X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fflurry.c;h=e6d1b22699b2eaf28ac3efbf18565c9fadf84007;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hp=0014cd818e7589535dc5f1abb3fa0a59083cd3bd;hpb=4cecfc89e5e889c7232693897c06168fb378bd5c;p=xscreensaver diff --git a/hacks/glx/flurry.c b/hacks/glx/flurry.c index 0014cd81..e6d1b226 100644 --- a/hacks/glx/flurry.c +++ b/hacks/glx/flurry.c @@ -37,38 +37,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* flurry */ -#if !defined( lint ) && !defined( SABER ) +#if 0 static const char sccsid[] = "@(#)flurry.c 4.07 97/11/24 xlockmore"; - #endif -/*- - * due to a Bug/feature in VMS X11/Intrinsic.h has to be placed before xlock. - * otherwise caddr_t is not defined correctly - */ - -#define DEF_PRESET "classic" +#define DEF_PRESET "random" #define DEF_BRIGHTNESS "8" -#include - -# define PROGCLASS "Flurry" -# define HACK_INIT init_flurry -# define HACK_DRAW draw_flurry -# define HACK_RESHAPE reshape_flurry -# define HACK_HANDLE_EVENT flurry_handle_event -# define EVENT_MASK PointerMotionMask -# define flurry_opts xlockmore_opts -# define DEFAULTS "*showFPS: False \n" \ - "*preset: " DEF_PRESET " \n" +# define DEFAULTS "*delay: 10000 \n" \ + "*showFPS: False \n" +# define refresh_flurry 0 +# define release_flurry 0 +# define flurry_handle_event 0 # include "xlockmore.h" /* from the xscreensaver distribution */ #ifdef USE_GL -#include "rotator.h" -#include "gltrackball.h" - static char *preset_str; static XrmOptionDescRec opts[] = { @@ -76,19 +61,19 @@ static XrmOptionDescRec opts[] = { }; static argtype vars[] = { - {(caddr_t *) &preset_str, "preset", "Preset", DEF_PRESET, t_String}, + {&preset_str, "preset", "Preset", DEF_PRESET, t_String}, }; #define countof(x) (sizeof((x))/sizeof((*x))) -ModeSpecOpt flurry_opts = {countof(opts), opts, countof(vars), vars, NULL}; +ENTRYPOINT ModeSpecOpt flurry_opts = {countof(opts), opts, countof(vars), vars, NULL}; #ifdef USE_MODULES ModStruct flurry_description = { "flurry", "init_flurry", "draw_flurry", - "release_flurry", + NULL, "draw_flurry", "init_flurry", NULL, @@ -102,40 +87,38 @@ ModStruct flurry_description = { #endif -#include -#include - #include "flurry.h" global_info_t *flurry_info = NULL; -static double gTimeCounter = 0.0; - +static double currentTime(void) { struct timeval tv; - - gettimeofday(&tv, NULL); +# ifdef GETTIMEOFDAY_TWO_ARGS + struct timezone tzp; + gettimeofday(&tv, &tzp); +# else + gettimeofday(&tv); +# endif return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0; } -void OTSetup (void) { - if (gTimeCounter == 0.0) { - gTimeCounter = currentTime(); - } -} - -double TimeInSecondsSinceStart (void) { - return currentTime() - gTimeCounter; +double TimeInSecondsSinceStart (const global_info_t *global) { + return currentTime() - global->gTimeCounter; } +#if 0 #ifdef __ppc__ static int IsAltiVecAvailable(void) { return 0; } #endif +#endif + +static void delete_flurry_info(flurry_info_t *flurry) { int i; @@ -146,9 +129,10 @@ void delete_flurry_info(flurry_info_t *flurry) { free(flurry->spark[i]); } - free(flurry); + /* free(flurry); */ } +static flurry_info_t *new_flurry_info(global_info_t *global, int streams, ColorModes colour, float thickness, float speed, double bf) { int i,k; @@ -158,7 +142,10 @@ flurry_info_t *new_flurry_info(global_info_t *global, int streams, ColorModes co flurry->flurryRandomSeed = RandFlt(0.0, 300.0); - flurry->fOldTime = TimeInSecondsSinceStart() + flurry->flurryRandomSeed; + flurry->fOldTime = 0; + flurry->dframe = 0; + flurry->fTime = TimeInSecondsSinceStart(global) + flurry->flurryRandomSeed; + flurry->fDeltaTime = flurry->fTime - flurry->fOldTime; flurry->numStreams = streams; flurry->streamExpansion = thickness; @@ -191,6 +178,7 @@ flurry_info_t *new_flurry_info(global_info_t *global, int streams, ColorModes co return flurry; } +static void GLSetupRC(global_info_t *global) { /* setup the defaults for OpenGL */ @@ -205,17 +193,17 @@ void GLSetupRC(global_info_t *global) glViewport(0,0,(int) global->sys_glWidth,(int) global->sys_glHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluOrtho2D(0,global->sys_glWidth,0,global->sys_glHeight); + glOrtho(0,global->sys_glWidth,0,global->sys_glHeight,-1,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glClearColor(0.0,0.0,0.0,1.0); glClear(GL_COLOR_BUFFER_BIT); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); +#if 0 #ifdef __ppc__ global->optMode = OPT_MODE_SCALAR_FRSQRTE; @@ -226,8 +214,10 @@ void GLSetupRC(global_info_t *global) #else global->optMode = OPT_MODE_SCALAR_BASE; #endif +#endif /* 0 */ } +static void GLRenderScene(global_info_t *global, flurry_info_t *flurry, double b) { int i; @@ -235,7 +225,7 @@ void GLRenderScene(global_info_t *global, flurry_info_t *flurry, double b) flurry->dframe++; flurry->fOldTime = flurry->fTime; - flurry->fTime = TimeInSecondsSinceStart() + flurry->flurryRandomSeed; + flurry->fTime = TimeInSecondsSinceStart(global) + flurry->flurryRandomSeed; flurry->fDeltaTime = flurry->fTime - flurry->fOldTime; flurry->drag = (float) pow(0.9965,flurry->fDeltaTime*85.0); @@ -263,6 +253,7 @@ void GLRenderScene(global_info_t *global, flurry_info_t *flurry, double b) case OPT_MODE_SCALAR_BASE: UpdateSmoke_ScalarBase(global, flurry, flurry->s); break; +#if 0 #ifdef __ppc__ case OPT_MODE_SCALAR_FRSQRTE: UpdateSmoke_ScalarFrsqrte(global, flurry, flurry->s); @@ -276,6 +267,8 @@ void GLRenderScene(global_info_t *global, flurry_info_t *flurry, double b) UpdateSmoke_VectorUnrolled(global, flurry, flurry->s); break; #endif +#endif /* 0 */ + default: break; } @@ -287,17 +280,21 @@ void GLRenderScene(global_info_t *global, flurry_info_t *flurry, double b) switch(global->optMode) { case OPT_MODE_SCALAR_BASE: +#if 0 #ifdef __ppc__ case OPT_MODE_SCALAR_FRSQRTE: #endif +#endif /* 0 */ DrawSmoke_Scalar(global, flurry, flurry->s, b); break; +#if 0 #ifdef __VEC__ case OPT_MODE_VECTOR_SIMPLE: case OPT_MODE_VECTOR_UNROLLED: DrawSmoke_Vector(global, flurry, flurry->s, b); break; #endif +#endif /* 0 */ default: break; } @@ -305,6 +302,7 @@ void GLRenderScene(global_info_t *global, flurry_info_t *flurry, double b) glDisable(GL_TEXTURE_2D); } +static void GLResize(global_info_t *global, float w, float h) { global->sys_glWidth = w; @@ -312,7 +310,7 @@ void GLResize(global_info_t *global, float w, float h) } /* new window size or exposure */ -void reshape_flurry(ModeInfo *mi, int width, int height) +ENTRYPOINT void reshape_flurry(ModeInfo *mi, int width, int height) { global_info_t *global = flurry_info + MI_SCREEN(mi); @@ -321,44 +319,16 @@ void reshape_flurry(ModeInfo *mi, int width, int height) glViewport(0.0, 0.0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluOrtho2D(0, width, 0, height); + glOrtho(0, width, 0, height,-1,1); glMatrixMode(GL_MODELVIEW); - - glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); - glFlush(); - GLResize(global, (float)width, (float)height); } -Bool -flurry_handle_event (ModeInfo *mi, XEvent *event) -{ - global_info_t *global = flurry_info + MI_SCREEN(mi); - - if (event->xany.type == ButtonPress && event->xbutton.button & Button1) { - global->button_down_p = True; - gltrackball_start (global->trackball, - event->xbutton.x, event->xbutton.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } - else if (event->xany.type == ButtonRelease && event->xbutton.button & Button1) { - global->button_down_p = False; - return True; - } - else if (event->xany.type == MotionNotify && global->button_down_p) { - gltrackball_track (global->trackball, - event->xmotion.x, event->xmotion.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } - - return False; -} +static void free_flurry(ModeInfo * mi); -void +ENTRYPOINT void init_flurry(ModeInfo * mi) { int screen = MI_SCREEN(mi); @@ -375,19 +345,13 @@ init_flurry(ModeInfo * mi) PRESET_MAX } preset_num; - if (flurry_info == NULL) { - OTSetup(); - if ((flurry_info = (global_info_t *) calloc(MI_NUM_SCREENS(mi), - sizeof (global_info_t))) == NULL) - return; - } + MI_INIT (mi, flurry_info, free_flurry); global = &flurry_info[screen]; - global->window = MI_WINDOW(mi); + global->gTimeCounter = currentTime(); - global->rot = make_rotator(1, 1, 1, 1, 0, True); - global->trackball = gltrackball_init(); + global->window = MI_WINDOW(mi); global->flurry = NULL; @@ -427,7 +391,7 @@ init_flurry(ModeInfo * mi) case PRESET_FIRE: { flurry_info_t *flurry; - flurry = new_flurry_info(global, 12, slowCyclicColorMode, 10000.0, 0.0, 1.0); + flurry = new_flurry_info(global, 12, slowCyclicColorMode, 10000.0, 0.2, 1.0); flurry->next = global->flurry; global->flurry = flurry; break; @@ -497,13 +461,14 @@ init_flurry(ModeInfo * mi) } else { MI_CLEARWINDOW(mi); } + + global->first = 1; + global->oldFrameTime = -1; } -void +ENTRYPOINT void draw_flurry(ModeInfo * mi) { - static int first = 1; - static double oldFrameTime = -1; double newFrameTime; double deltaFrameTime = 0; double brite; @@ -515,7 +480,7 @@ draw_flurry(ModeInfo * mi) Window window = MI_WINDOW(mi); newFrameTime = currentTime(); - if (oldFrameTime == -1) { + if (global->oldFrameTime == -1) { /* special case the first frame -- clear to black */ alpha = 1.0; } else { @@ -528,24 +493,24 @@ draw_flurry(ModeInfo * mi) * than that and the blending causes the display to * saturate, which looks really ugly. */ - if (newFrameTime - oldFrameTime < 1/60.0) { - usleep(MAX_(1,(int)(20000 * (newFrameTime - oldFrameTime)))); + if (newFrameTime - global->oldFrameTime < 1/60.0) { + usleep(MAX_(1,(int)(20000 * (newFrameTime - global->oldFrameTime)))); return; } - deltaFrameTime = newFrameTime - oldFrameTime; + deltaFrameTime = newFrameTime - global->oldFrameTime; alpha = 5.0 * deltaFrameTime; } - oldFrameTime = newFrameTime; + global->oldFrameTime = newFrameTime; if (alpha > 0.2) alpha = 0.2; if (!global->glx_context) return; - if (first) { + if (global->first) { MakeTexture(); - first = 0; + global->first = 0; } glDrawBuffer(GL_BACK); glXMakeCurrent(display, window, *(global->glx_context)); @@ -567,28 +532,21 @@ draw_flurry(ModeInfo * mi) glXSwapBuffers(display, window); } -void -release_flurry(ModeInfo * mi) +static void +free_flurry(ModeInfo * mi) { - if (flurry_info != NULL) { - int screen; - - for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) { - global_info_t *global = &flurry_info[screen]; - flurry_info_t *flurry; + global_info_t *global = &flurry_info[MI_SCREEN(mi)]; + flurry_info_t *flurry; - if (global->glx_context) { - glXMakeCurrent(MI_DISPLAY(mi), global->window, *(global->glx_context)); - } + if (global->glx_context) { + glXMakeCurrent(MI_DISPLAY(mi), global->window, *(global->glx_context)); + } - for (flurry = global->flurry; flurry; flurry=flurry->next) { - delete_flurry_info(flurry); - } - } - (void) free((void *) flurry_info); - flurry_info = NULL; + for (flurry = global->flurry; flurry; flurry=flurry->next) { + delete_flurry_info(flurry); } - FreeAllGL(mi); } +XSCREENSAVER_MODULE ("Flurry", flurry) + #endif