// Scenesaver: copyright 2004 Sam Stafford. #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef WIN32 #include <direct.h> extern int Width, Height; #endif #include "globals.h" #define LTG_ABOUT "\ # Scenesaver - the best slideshow screensaver ever\n\ # from http://www.leadtogold.com\n\ # \n\ # \n\ # \n\ # Your Scenesaver directory is:\n\ " #define LTG_INSTR "\ # To specify the images that Scenesaver will use, create a file\n\ # called Scenes.txt in this directory, and list the images, one\n\ # file per line (no wildcards). The images will be used in the\n\ # order listed. It is recommended that all of the images be the\n\ # same dimensions; if they are not, the dimensions of the first\n\ # image will be used and all subsequent images will be clipped to\n\ # those dimensions.\n\ # \n\ # When screensaver is running, push 'c' to switch camera mode.\n\ # When in \"chase-cam\" mode, push 'v' to switch viewed creature.\n\ # Push 'b' to switch display buffer.\n\ # Push 'n' to switch to a new image.\n\ # Push 'x' to toggle creatures (in)visible.\n\ # Push 'z' to dump a screenshot of the image into this directory.\n\ # \n\ " void loadsettings(); void savesettings(); void loadsettings() { settings.save = true; settings.mutate = 9; settings.digest = 3000; settings.camera = 'w'; settings.opacity_i = 50; settings.opacity_f = 0.5; settings.radius = 15; settings.vision = 30; settings.maxspeed = 100; settings.fitness = 1000; settings.image = 5000; settings.diff = 80; settings.pop = 10; settings.autoscale = 'S'; settings.shuffle = false; settings.alternate = false; settings.gmo = false; settings.smudge = 0; settings.smudgedist = 50; FILE* f = fopen( "Scenesaver.cfg", "r" ); if ( !f ) { savesettings(); return; } char c[64]; while ( fgets( c, 64, f ) ) { if ( !memcmp( c, "savegenes=T", 11 ) ) settings.save = true; else if ( !memcmp( c, "savegenes=F", 11 ) ) settings.save = false; else if ( !memcmp( c, "setcamera=W", 11 ) ) settings.camera = 'w'; else if ( !memcmp( c, "setcamera=C", 11 ) ) settings.camera = 'c'; else if ( !memcmp( c, "autoscale=N", 11 ) ) settings.autoscale = 0; else if ( !memcmp( c, "autoscale=S", 11 ) ) settings.autoscale = 'S'; else if ( !memcmp( c, "autoscale=M", 11 ) ) settings.autoscale = 'M'; else if ( !memcmp( c, "autoscale=L", 11 ) ) settings.autoscale = 'L'; else if ( !memcmp( c, "randomize=T", 11 ) ) settings.shuffle = true; else if ( !memcmp( c, "randomize=F", 11 ) ) settings.shuffle = false; else if ( !memcmp( c, "alternate=T", 11 ) ) settings.alternate = true; else if ( !memcmp( c, "alternate=F", 11 ) ) settings.alternate = false; else if ( !memcmp( c, "allowgmos=T", 11 ) ) settings.gmo = true; else if ( !memcmp( c, "allowgmos=F", 11 ) ) settings.gmo = false; else if ( !memcmp( c, "mutations=", 10 ) ) settings.mutate = atoi( c+10 ); else if ( !memcmp( c, "digestion=", 10 ) ) settings.digest = 100 * atoi( c+10 ); else if ( !memcmp( c, "digestspd=", 10 ) ) settings.digest = atoi( c+10 ); else if ( !memcmp( c, "maxradius=", 10 ) ) settings.radius = atoi( c+10 ); else if ( !memcmp( c, "visionrng=", 10 ) ) settings.vision = atoi( c+10 ); else if ( !memcmp( c, "maxspeedp=", 10 ) ) settings.maxspeed = atoi( c+10 ); else if ( !memcmp( c, "t_fitness=", 10 ) ) settings.fitness = atoi( c+10 ); else if ( !memcmp( c, "t_nwimage=", 10 ) ) settings.image = atoi( c+10 ); else if ( !memcmp( c, "pctchange=", 10 ) ) settings.diff = atoi( c+10 ); else if ( !memcmp( c, "creatures=", 10 ) ) settings.pop = atoi( c+10 ); else if ( !memcmp( c, "pctsmudge=", 10 ) ) settings.smudge = atoi( c+10 ); else if ( !memcmp( c, "dstsmudge=", 10 ) ) settings.smudgedist = atoi( c+10 ); else if ( !memcmp( c, "pctopaque=", 10 ) ) settings.opacity_i = atoi( c+10 ); } fclose( f ); //Sanity checks if ( settings.mutate < 0 ) settings.mutate = 9; if ( settings.digest < 0 ) settings.digest = 30; if ( settings.radius < 0 ) settings.radius = 5; if ( settings.vision < 0 ) settings.vision = 30; if ( settings.maxspeed < 1 ) settings.maxspeed = 1; if ( settings.maxspeed > 200 ) settings.maxspeed = 200; if ( settings.fitness < 0 ) settings.fitness = 500; if ( settings.image < 0 ) settings.fitness = 5000; if ( settings.diff < 1 ) settings.diff = 1; if ( settings.diff > 100 ) settings.diff = 100; if ( settings.pop < 0 ) settings.pop = 10; if ( settings.smudge < 0 ) settings.smudge = 0; if ( settings.smudge > 100 ) settings.smudge = 100; if ( settings.smudgedist < 0 ) settings.smudgedist = 0; if ( settings.smudgedist > 200 ) settings.smudgedist = 200; if ( settings.opacity_i < 0 ) settings.opacity_i = 0; if ( settings.opacity_i > 100 ) settings.opacity_i = 100; settings.opacity_f = float( settings.opacity_i / 100.0 ); settings.digest_f = float( settings.digest / 100.0 ); } void savesettings() { FILE* f = fopen( "Scenesaver.cfg", "w" ); if ( !f ) return; char c; fprintf( f, LTG_ABOUT ); fprintf( f, "# %s\n#\n", getcwd( 0x0, 0 ) ); fprintf( f, LTG_INSTR ); fprintf( f, "#\n#\n# SETTINGS\n#\n" ); fprintf( f, "#\n# Simulation settings\n#\n" ); fprintf( f, "# Number of animals in the world?\n" ); fprintf( f, "creatures=%d\n", settings.pop ); fprintf( f, "# Initialize with engineered animals instead of random?\n" ); c = settings.gmo ? 'T' : 'F'; fprintf( f, "allowgmos=%c\n", c ); fprintf( f, "# Save genotypes on exit?\n" ); c = settings.save ? 'T' : 'F'; fprintf( f, "savegenes=%c\n", c ); fprintf( f, "# Number of timesteps per fitness cycle?\n" ); fprintf( f, "t_fitness=%d\n", settings.fitness ); fprintf( f, "# Number of mutations per fitness cycle?\n" ); fprintf( f, "mutations=%d\n", settings.mutate ); fprintf( f, "# Number of timesteps before automatic image swap?\n" ); fprintf( f, "t_nwimage=%d\n", settings.image ); fprintf( f, "# Percent of image changes before automatic image swap?\n" ); fprintf( f, "pctchange=%d\n", settings.diff ); fprintf( f, "# Randomized image order instead of sequential?\n" ); c = settings.shuffle ? 'T' : 'F'; fprintf( f, "randomize=%c\n", c ); fprintf( f, "# Use first image in sequence on every other rotation?\n" ); c = settings.alternate ? 'T' : 'F'; fprintf( f, "alternate=%c\n", c ); fprintf( f, "# Maximum radius, in pixels, of each animal?\n" ); fprintf( f, "maxradius=%d\n", settings.radius ); fprintf( f, "# Vision range, in pixels, for each animal?\n" ); fprintf( f, "visionrng=%d\n", settings.vision ); fprintf( f, "# Maximum speed, as percentage, of each animal?\n" ); fprintf( f, "maxspeedp=%d\n", settings.maxspeed ); fprintf( f, "# Amount of color each animal can change per step?\n" ); fprintf( f, "digestspd=%d\n", settings.digest ); fprintf( f, "# Smudge blend factor, as a percentage?\n" ); fprintf( f, "pctsmudge=%d\n", settings.smudge ); fprintf( f, "# Smudge distance factor, as a percentage?\n" ); fprintf( f, "dstsmudge=%d\n", settings.smudgedist ); fprintf( f, "#\n# View settings\n#\n" ); fprintf( f, "# Creature opacity in world view?\n" ); fprintf( f, "pctopaque=%d\n", int( settings.opacity_i ) ); fprintf( f, "# Auto-scale images if they don't match the first?\n" ); fprintf( f, "# N for no scaling, S for stretch to fit,\n" ); fprintf( f, "# L for letterbox, M for static pan 'n scan.\n" ); c = settings.autoscale ? settings.autoscale : 'N'; fprintf( f, "autoscale=%c\n", c ); fprintf( f, "# Default camera setting? W for world, C for chase\n" ); if ( settings.camera == 'c' || settings.camera == 'C' ) c = 'C'; else c = 'W'; fprintf( f, "setcamera=%c\n", c ); fclose( f ); } void loadimages( int* argc, char* ** argv ) { //initialize argc and argv to checkable error values *argc = 0; FILE* f = fopen( "Scenes.txt", "r" ); if ( !f ) { *argv = new char*; *argv[0] = 0; return; } char c[1024]; int lines = 0; while ( fgets( c, 1024, f ) ) { lines++; } *argc = lines; if ( !lines ) { *argv = new char*; *argv[0] = 0; return; } rewind( f ); *argv = new char*[lines]; int i = 0; while ( fgets( c, 1024, f ) ) { (*argv)[i] = new char[strlen(c)]; strncpy( (*argv)[i], c, strlen(c)-1 ); (*argv)[i][strlen(c)-1] = 0; i++; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#17 | 5890 | Sam Stafford |
Increased granularity of "digestion" setting so that lower values can be set. (This change is backwards-compatible with old settings files.) |
||
#16 | 5818 | Sam Stafford | Configurable painter opacity. | ||
#15 | 5691 | Sam Stafford |
Rebuilt Scenesaver with Qt 3.3.6. Added a new flag to the config file (not in the GUI since it's pretty esoteric) that uses the background image on every other rotation in shuffle mode. |
||
#14 | 5589 | Sam Stafford | Make painter speed configurable. | ||
#13 | 5293 | Sam Stafford |
Quick and dirty configuration dialog to edit SceneSaver.cfg. Slightly friendlier than the Notepad gizmo. Still need to write something to help people set up Scenes.txt... |
||
#12 | 4578 | Sam Stafford | Fix inconsequential memory leak and bad pun in loadimages(). | ||
#11 | 4577 | Sam Stafford | Add new "smudge distance" tunable. | ||
#10 | 4572 | Sam Stafford |
New "smudge" feature. REALLY COOL. Off by default (pctsmudge=0) since it's a CPU hog. |
||
#9 | 4561 | Sam Stafford | New smooth autoscaling, with configurable fit-to-screen behavior. | ||
#8 | 4465 | Sam Stafford |
Genetically engineered organisms - there's now an option to seed the initial population with these relentlessly efficient creatures rather than random mutants. Kinda neat-looking, but not as organic-looking as pure evolved creatures. |
||
#7 | 4462 | Sam Stafford | Image shuffle option. | ||
#6 | 4457 | Sam Stafford |
After the first round of user feedback: 1) Added option to autoscale images if they don't match in size (on by default) 2) Fixed crash bug if you tried to cycle the chasecam when it had never been initialized. |
||
#5 | 4454 | Sam Stafford |
Made "Scenesaver" the canonical capitalization throughout the output strings. Checking in a binary. |
||
#4 | 4453 | Sam Stafford |
Added screenshot feature, moved SceneSaver files to home directory rather than system directory, added code to handle invalid or missing images (loading a random color instead of crashing). I think this thing's good to go. |
||
#3 | 4452 | Sam Stafford | Fix a couple of small bugs. | ||
#2 | 4451 | Sam Stafford | All significant variables are now user-tweakable. | ||
#1 | 4448 | Sam Stafford | Turn this thing into a Windows screensaver. | ||
//guest/sam_stafford/genesaver/src/settings.cpp | |||||
#5 | 3356 | Sam Stafford |
Calculate display width/height ratio, if possible, and set default zoom level to prevent distortion. (Windows only, thus far.) |
||
#4 | 3353 | Sam Stafford |
Use Windows <scrnsave.h> and OpenGL functions instead of GLUT. This should fix all sorts of bugs involving the screensaver not terminating when it should, spawning new processes, et cetera. Code shuffling to follow, since right now it's a tangled mess. |
||
#3 | 3349 | Sam Stafford |
Add a simulation variable "crtrspeed" that regulates the speed of the creatures. This allows those with blazingly fast CPUs to slow the action down. (Those with crawlingly slow CPUs are out of luck, since above crtrspeed=400%, the creatures just teleport around the screen.) |
||
#2 | 3347 | Sam Stafford | Increase likelihood of color mutation. | ||
#1 | 3052 | Sam Stafford |
Add Genesaver to the Public Depot. It's not in any way Perforce-related, but it does share a bit of code with Jamgraph, and it feels strange to have an open-source project that's not in the PD. |