// Genesaver: copyright 2003 Sam Stafford. #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef WIN32 #include <direct.h> #endif #include "globals.h" #define LTG_ABOUT "\ # Genesaver - a living screensaver\n\ # from http://www.leadtogold.com\n\ # \n\ # Thanks to:\n\ # Matt: feedback and testing\n\ # Adrian: OpenGL help\n\ # Nora and Mandi: biology lesson\n\ " #define LTG_INSTR "\ # \n\ # When screensaver is running, push 'c' to switch camera mode.\n\ # When in \"chase-cam\" mode, push 'v' to switch viewed creature.\n\ # \n\ " void loadsettings(); void savesettings(); int config() { loadsettings(); savesettings(); #ifdef WIN32 return system( "notepad Genesaver.cfg" ); #else return system( "vi Genesaver.cfg" ); #endif }; void loadsettings() { settings.AA = false; settings.AAline = false; settings.shade = true; settings.save = true; settings.mutate = 7; settings.plants = 200; settings.cscale = 100; settings.camera = C_WORLD; settings.gticks = 20000; settings.gwidth = 200; settings.wake = false; settings.drawvis = true; settings.lizard = false; settings.zoom = 100; settings.alpha = 1.0; FILE* f = fopen( "Genesaver.cfg", "r" ); if ( !f ) { savesettings(); return; } char c[64]; while ( fgets( c, 64, f ) ) { if ( !memcmp( c, "antialias=T", 11 ) ) settings.AA = true; else if ( !memcmp( c, "antialias=F", 11 ) ) settings.AA = false; else if ( !memcmp( c, "aalinetoo=T", 11 ) ) settings.AAline = true; else if ( !memcmp( c, "aalinetoo=F", 11 ) ) settings.AAline = false; else if ( !memcmp( c, "doshading=T", 11 ) ) settings.shade = true; else if ( !memcmp( c, "doshading=F", 11 ) ) settings.shade = false; else 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 = C_WORLD; else if ( !memcmp( c, "setcamera=C", 11 ) ) settings.camera = C_CHASE; else if ( !memcmp( c, "setcamera=G", 11 ) ) settings.camera = C_GRAPH; else if ( !memcmp( c, "speedline=T", 11 ) ) settings.wake = true; else if ( !memcmp( c, "speedline=F", 11 ) ) settings.wake = false; else if ( !memcmp( c, "drawvisbl=T", 11 ) ) settings.drawvis = true; else if ( !memcmp( c, "drawvisbl=F", 11 ) ) settings.drawvis = false; else if ( !memcmp( c, "weirdness=T", 11 ) ) settings.lizard = true; else if ( !memcmp( c, "weirdness=F", 11 ) ) settings.lizard = false; else if ( !memcmp( c, "mutations=", 10 ) ) settings.mutate = atoi( c+10 ); else if ( !memcmp( c, "plantgrow=", 10 ) ) settings.plants = atoi( c+10 ); else if ( !memcmp( c, "graphtime=", 10 ) ) settings.gticks = atoi( c+10 ); else if ( !memcmp( c, "graphpnts=", 10 ) ) settings.gwidth = atoi( c+10 ); else if ( !memcmp( c, "zoomprcnt=", 10 ) ) settings.zoom = atoi( c+10 ); else if ( !memcmp( c, "crtrscale=", 10 ) ) settings.cscale = atoi( c+10 ); } fclose( f ); //Sanity checks if ( settings.mutate < 0 ) settings.mutate = 7; if ( settings.plants < 0 ) settings.plants = 200; if ( settings.gwidth < 1 ) settings.gwidth = 200; if ( settings.gticks < settings.gwidth ) settings.gticks = settings.gwidth ; if ( settings.zoom < 50 || settings.zoom > 10000 ) settings.zoom = 100; if ( settings.cscale < 1 || settings.cscale > 1000 ) settings.cscale = 100; //Pre-process settings as needed fsettings.gtime = float( settings.gticks ) / float( settings.gwidth ); fsettings.gstep = float( 2.0 / settings.gwidth ); fsettings.ps = float( settings.plants / 1000.0 ); fsettings.pr = float( settings.cscale * 0.005 / 100.0 ); fsettings.ar = float( settings.cscale * 0.01 / 100.0 ); fsettings.am = float( 25.0 * 100.0 / settings.cscale ); fsettings.as = float( settings.cscale * 0.0075 / 100.0 ); fsettings.av = float( settings.cscale * 0.2 / 100.0 ); } void savesettings() { FILE* f = fopen( "Genesaver.cfg", "w" ); if ( !f ) return; char c; fprintf( f, LTG_ABOUT ); fprintf( f, LTG_INSTR ); fprintf( f, "#\n#\n# SETTINGS\n#\n" ); fprintf( f, "#\n# Simulation settings\n#\n" ); fprintf( f, "# Save genotypes on exit?\n" ); c = settings.save ? 'T' : 'F'; fprintf( f, "savegenes=%c\n", c ); fprintf( f, "# Number of mutations per birth?\n" ); fprintf( f, "mutations=%d\n", settings.mutate ); fprintf( f, "# Number of plants to grow per 1000 steps?\n" ); fprintf( f, "plantgrow=%d\n", settings.plants ); fprintf( f, "# Creature size (percent of normal)?\n" ); fprintf( f, "crtrscale=%d\n", settings.cscale ); fprintf( f, "# Use weird alternate ecosystem?\n" ); c = settings.lizard ? 'T' : 'F'; fprintf( f, "weirdness=%c\n", c ); fprintf( f, "#\n# Graphics settings\n#\n" ); fprintf( f, "# Enable antialiasing and alpha blending?\n" ); c = settings.AA ? 'T' : 'F' ; fprintf( f, "antialias=%c\n", c ); fprintf( f, "# Antialias lines as well as polygons?\n" ); c = settings.AAline ? 'T' : 'F'; fprintf( f, "aalinetoo=%c\n", c ); fprintf( f, "# Enable smooth shading?\n" ); c = settings.shade ? 'T' : 'F'; fprintf( f, "doshading=%c\n", c ); fprintf( f, "#\n# View settings\n#\n" ); fprintf( f, "# Default camera setting? W for world, C for chase, G for graph\n" ); if ( settings.camera == C_CHASE ) c = 'C'; else if ( settings.camera == C_GRAPH ) c = 'G'; else c = 'W'; fprintf( f, "setcamera=%c\n", c ); fprintf( f, "# Zoom percent in world view?\n" ); fprintf( f, "zoomprcnt=%d\n", settings.zoom ); fprintf( f, "# Draw speed lines behind viewed creature?\n" ); c = settings.wake ? 'T' : 'F' ; fprintf( f, "speedline=%c\n", c ); fprintf( f, "# Limit chase-cam drawing to visual range?\n" ); c = settings.drawvis ? 'T' : 'F' ; fprintf( f, "drawvisbl=%c\n", c ); fprintf( f, "# Number of timesteps to cover per graph screen?\n" ); fprintf( f, "graphtime=%d\n", settings.gticks ); fprintf( f, "# Number of points to plot per graph screen?\n" ); fprintf( f, "graphpnts=%d\n", settings.gwidth ); fclose( f ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#12 | 8469 | Sam Stafford |
Bind to source control with P4VS. So far so good. Make zoom better -- zoom automatically adjusts to a minimum "pretty" value for the current resolution (regardless of what's in settings), and zoom adjustment in screensaver mode scales with current zoom level. |
||
#11 | 8466 | Sam Stafford | Fix default settings to work better in our modern widescreen world. | ||
#10 | 5634 | Sam Stafford | Make vision configurable. | ||
#9 | 5384 | Sam Stafford |
Increase maximum allowable creature speed, fix a couple of bugs (some of them balance-related) with the alternate ecology ruleset. |
||
#8 | 5366 | Sam Stafford |
A bit of infrastructure tidying and a minor performance enhancement - the genome is now not saved when running in "demo mode" in Windows, which eliminates that little pause when you close the Windows display dialog after modifying Genesaver settings. |
||
#7 | 5337 | Sam Stafford | Blur trails. | ||
#6 | 5090 | Sam Stafford | Option to draw a grid on the background (they appear in both world and chase view), set by the "gridlines" option in the settings file. | ||
#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. |