#ifdef WIN32 #include <direct.h> #include <windows.h> #endif #define _USE_MATH_DEFINES #include <math.h> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <gl/gl.h> #include "globals.h" #include "util.h" #include "DNA.h" #include "World.h" extern Settings settings; //Globals. Settings settings; //General utility functions. char* LoadGenes() { FILE* f = fopen( "SceneGenes.txt", "r" ); if ( !f ) { //Try to stat the file; if it's there, don't attempt to overwrite //it on exit. struct stat temp; if ( stat( "SceneGenes.txt", &temp ) == 0 ) settings.save = false; return NULL; } fseek( f, 0, SEEK_END ); int size = ftell( f ); fseek( f, 0, SEEK_SET ); if ( !size ) return NULL; char* dfile = new char[size]; for ( int a = 0 ; a < size ; a++ ) dfile[a] = fgetc( f ); fclose( f ); return dfile; } float RandFloat() { return rand() / ( 1.0f * RAND_MAX ); } int RandInt( int foo ) { return rand() % ( foo + 1 ); } void SetColor( Color c ) { switch ( c ) { case Black: glColor3f( 0.0, 0.0, 0.0 ); break; case Blue: glColor3f( 0.0, 0.0, 1.0 ); break; case Cyan: glColor3f( 0.0, 1.0, 1.0 ); break; case Green: glColor3f( 0.0, 1.0, 0.0 ); break; case Grey: glColor3f( 0.5, 0.5, 0.5 ); break; case Magenta: glColor3f( 1.0, 0.0, 1.0 ); break; case Red: glColor3f( 1.0, 0.0, 0.0 ); break; case Yellow: glColor3f( 1.0, 1.0, 0.0 ); break; } } float Angle( float dx, float dy ) { double pa; if ( dx == 0 && dy > 0 ) { if ( dy > 0 ) pa = M_PI / 2; else if ( dy < 0 ) pa = -M_PI / 2; else pa = 0; } else if ( dy == 0 ) { if ( dx > 0 ) pa = 0; else pa = M_PI; } else if ( dx > 0 ) { pa = atan( dy / dx ); } else if ( dx < 0 ) { if ( dy > 0 ) pa = atan( dy / dx ) + M_PI; else pa = atan( dy / dx ) - M_PI; } return float( pa ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 5099 | Sam Stafford |
Try to avoid clearing out the genome file if it exists but wasn't readable on startup (seems like I've gotten this to happen by hitting "Preview" in the Windows dialog while it's still loading up the mini-preview). |
||
#5 | 4449 | Sam Stafford | Speed lines, toggle creatures on and off. | ||
#4 | 4448 | Sam Stafford | Turn this thing into a Windows screensaver. | ||
#3 | 4440 | Sam Stafford | Bug fixes, new features, the usual. | ||
#2 | 4433 | Sam Stafford |
More work on this little project. The AI is still nonexistent. |
||
#1 | 4430 | Sam Stafford |
Start importing alife/AI code from Genesaver. Much tweaking will need to be done. |
||
//guest/sam_stafford/genesaver/src/util.cpp | |||||
#1 | 3354 | Sam Stafford |
Code refactoring - split "main" functions into main.cpp (non-Windows) and winmain.cpp (Windows), with all shared code going in util.cpp. No functional changes. |