Revision: 38930
http://brlcad.svn.sourceforge.net/brlcad/?rev=38930&view=rev
Author: erikgreenwald
Date: 2010-04-30 20:39:10 +0000 (Fri, 30 Apr 2010)
Log Message:
-----------
break event loop into seperate file
Modified Paths:
--------------
isst/trunk/sdl/Makefile.am
isst/trunk/sdl/main.c
Added Paths:
-----------
isst/trunk/sdl/event.c
isst/trunk/sdl/isst.h
Modified: isst/trunk/sdl/Makefile.am
===================================================================
--- isst/trunk/sdl/Makefile.am 2010-04-30 20:29:11 UTC (rev 38929)
+++ isst/trunk/sdl/Makefile.am 2010-04-30 20:39:10 UTC (rev 38930)
@@ -1,5 +1,7 @@
bin_PROGRAMS=isst_sdl
-isst_sdl_SOURCES=main.c
+isst_sdl_SOURCES=main.c event.c
AM_CFLAGS=${SDL_CFLAGS} @TIE_CFLAGS@
AM_LDFLAGS=${SDL_LIBS} @TIE_LIBS@
+
+noinst_HEADERS = isst.h
Added: isst/trunk/sdl/event.c
===================================================================
--- isst/trunk/sdl/event.c (rev 0)
+++ isst/trunk/sdl/event.c 2010-04-30 20:39:10 UTC (rev 38930)
@@ -0,0 +1,117 @@
+/*
+ * ISST
+ *
+ * Copyright (c) 2005-2010 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file main.c
+ *
+ * top level for SDL version of ISST
+ *
+ */
+
+#include <stdio.h>
+#include <sys/time.h>
+
+#include <SDL.h>
+
+#include <tie/tie.h>
+#include <tie/adrt.h>
+#include <tie/adrt_struct.h>
+#include <tie/camera.h>
+
+#include "isst.h"
+
+
+int
+do_loop(struct isst_s *isst)
+{
+ SDL_Event e;
+ struct timeval ts[2];
+ int fc = 0;
+
+ gettimeofday(ts, NULL);
+
+ while (1)
+ {
+ int i;
+
+ isst->buffer_image.ind = 0;
+ if(isst->ogl)
+ paint_ogl(isst);
+ else
+ paint_sw(isst);
+
+ /* some FPS stuff */
+ fc++;
+ if(fc == 10) {
+ gettimeofday(ts+1, NULL);
+ printf(" \r%g FPS",
(double)fc/(((double)ts[1].tv_sec+(double)ts[1].tv_usec/(double)1e6) -
((double)ts[0].tv_sec+(double)ts[0].tv_usec/(double)1e6)));
+ fflush(stdout);
+ fc=0;
+ gettimeofday(ts, NULL);
+ }
+
+ while(SDL_PollEvent (&e))
+ switch (e.type)
+ {
+ case SDL_VIDEORESIZE:
+ isst->w = e.resize.w;
+ isst->h = e.resize.h;
+ resize_isst(isst);
+ break;
+ case SDL_KEYDOWN:
+ switch (tolower (e.key.keysym.sym))
+ {
+ case 'f':
+ if(isst->sflags&SDL_FULLSCREEN)
+ isst->sflags &= ~SDL_FULLSCREEN;
+ else
+ isst->sflags |= SDL_FULLSCREEN;
+ resize_isst(isst);
+ break;
+ case 'x':
+ case 'q':
+ case SDLK_ESCAPE:
+ SDL_Quit ();
+ printf("\n");
+ return EXIT_SUCCESS;
+ break;
+ /* TODO: more keys for nifty things like changing
mode or pulling up gui bits or something */
+ }
+ case SDL_MOUSEMOTION:
+ switch(e.motion.state) {
+ case 1:
+ /* rotate xrel/yrel */
+ break;
+ case 4:
+ /* zoom in/out yrel */
+ break;
+ }
+
+ }
+ }
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: isst/trunk/sdl/event.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: isst/trunk/sdl/isst.h
===================================================================
--- isst/trunk/sdl/isst.h (rev 0)
+++ isst/trunk/sdl/isst.h 2010-04-30 20:39:10 UTC (rev 38930)
@@ -0,0 +1,57 @@
+/*
+ * ISST
+ *
+ * Copyright (c) 2005-2010 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file isst.h
+ *
+ *
+ */
+
+
+struct isst_s {
+ struct tie_s *tie;
+ struct render_camera_s camera;
+ struct camera_tile_s tile;
+ struct adrt_mesh_s *meshes;
+ tienet_buffer_t buffer_image;
+ struct SDL_Rect r;
+ struct SDL_Surface *screen;
+ int ogl, sflags, w, h;
+};
+
+void resize_isst(struct isst_s *isst);
+
+struct isst_s * prep_isst(int argc, const char **argv);
+
+void paint_ogl(struct isst_s *isst);
+
+void paint_sw(struct isst_s *isst);
+
+int do_loop(struct isst_s *isst);
+
+
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: isst/trunk/sdl/isst.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: isst/trunk/sdl/main.c
===================================================================
--- isst/trunk/sdl/main.c 2010-04-30 20:29:11 UTC (rev 38929)
+++ isst/trunk/sdl/main.c 2010-04-30 20:39:10 UTC (rev 38930)
@@ -53,7 +53,6 @@
isst->r.x = isst->r.y = isst->tile.orig_x = isst->tile.orig_y = 0;
isst->tile.format = RENDER_CAMERA_BIT_DEPTH_24;
TIENET_BUFFER_SIZE(isst->buffer_image, 3 * isst->w * isst->h);
- printf("%dx%d 24 %x\n", isst->w, isst->h, isst->sflags);
isst->screen = SDL_SetVideoMode (isst->w, isst->h, 24, isst->sflags);
if(isst->screen == NULL) {
printf("Failed to generate display context\n");
@@ -81,12 +80,16 @@
void
paint_ogl(struct isst_s *isst)
{
+ render_camera_prep(&isst->camera);
+ render_camera_render(&isst->camera, isst->tie, &isst->tile,
&isst->buffer_image);
}
void
paint_sw(struct isst_s *isst)
{
int i;
+ render_camera_prep(&isst->camera);
+ render_camera_render(&isst->camera, isst->tie, &isst->tile,
&isst->buffer_image);
for(i=0;i<isst->h;i++)
memcpy(isst->screen->pixels + i * isst->screen->pitch,
isst->buffer_image.data + i * isst->w * 3,
@@ -95,70 +98,6 @@
}
int
-do_loop(struct isst_s *isst)
-{
- SDL_Event e;
- struct timeval ts[2];
- int fc = 0;
-
- gettimeofday(ts, NULL);
-
- while (1)
- {
- int i;
-
- isst->buffer_image.ind = 0;
- render_camera_prep(&isst->camera);
- render_camera_render(&isst->camera, isst->tie, &isst->tile,
&isst->buffer_image);
- if(isst->ogl)
- paint_ogl(isst);
- else
- paint_sw(isst);
-
- /* some FPS stuff */
- fc++;
- if(fc == 10) {
- gettimeofday(ts+1, NULL);
- printf(" \r%g FPS",
(double)fc/(((double)ts[1].tv_sec+(double)ts[1].tv_usec/(double)1e6) -
((double)ts[0].tv_sec+(double)ts[0].tv_usec/(double)1e6)));
- fflush(stdout);
- fc=0;
- gettimeofday(ts, NULL);
- }
-
- while(SDL_PollEvent (&e))
- switch (e.type)
- {
- case SDL_VIDEORESIZE:
- isst->w = e.resize.w;
- isst->h = e.resize.h;
- resize_isst(isst);
- break;
- case SDL_KEYDOWN:
- switch (tolower (e.key.keysym.sym))
- {
- case 'f':
- if(isst->sflags&SDL_FULLSCREEN)
- isst->sflags &= ~SDL_FULLSCREEN;
- else
- isst->sflags |= SDL_FULLSCREEN;
- resize_isst(isst);
- break;
- case 'x':
- case 'q':
- case SDLK_ESCAPE:
- SDL_Quit ();
- printf("\n");
- return EXIT_SUCCESS;
- break;
- /* TODO: more keys for nifty things like changing
mode or pulling up gui bits or something */
- }
- /* TODO: look for mouse events */
- }
- }
-}
-
-
-int
main(int argc, char **argv)
{
struct isst_s *isst;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits