author | andyq <andyq> | 2003-01-21 20:37:00 (UTC) |
---|---|---|
committer | andyq <andyq> | 2003-01-21 20:37:00 (UTC) |
commit | 0a6563fcc2f49857c581d9def24407a3a4ef526c (patch) (unidiff) | |
tree | f1b82a4bd7582ef2cb722cffb87eecff1e1f96e6 | |
parent | 50b5915b48fc5cbacf23e4d2b75d7a266f141a4a (diff) | |
download | opie-0a6563fcc2f49857c581d9def24407a3a4ef526c.zip opie-0a6563fcc2f49857c581d9def24407a3a4ef526c.tar.gz opie-0a6563fcc2f49857c581d9def24407a3a4ef526c.tar.bz2 |
Clean up of code - fixed memory leaks (most of them) and added new custom config menu
25 files changed, 791 insertions, 409 deletions
diff --git a/noncore/games/sfcave-sdl/animatedimage.cpp b/noncore/games/sfcave-sdl/animatedimage.cpp index d9d6ff6..441c647 100644 --- a/noncore/games/sfcave-sdl/animatedimage.cpp +++ b/noncore/games/sfcave-sdl/animatedimage.cpp | |||
@@ -6,3 +6,3 @@ | |||
6 | 6 | ||
7 | AnimatedImage :: AnimatedImage( QString file, int nFrames ) | 7 | AnimatedImage :: AnimatedImage( string file, int nFrames ) |
8 | { | 8 | { |
@@ -21,5 +21,2 @@ AnimatedImage :: AnimatedImage( QString file, int nFrames ) | |||
21 | SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB( image->format, 0, 0, 0 ) ); | 21 | SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB( image->format, 0, 0, 0 ) ); |
22 | //image = SDL_DisplayFormat( tmp ); | ||
23 | |||
24 | //SDL_FreeSurface( tmp ); | ||
25 | frameWidth = image->w/nrFrames; | 22 | frameWidth = image->w/nrFrames; |
@@ -49,2 +46,5 @@ void AnimatedImage :: draw( SDL_Surface *screen, int x, int y ) | |||
49 | { | 46 | { |
47 | if ( !image ) | ||
48 | return; | ||
49 | |||
50 | SDL_Rect dst; | 50 | SDL_Rect dst; |
diff --git a/noncore/games/sfcave-sdl/animatedimage.h b/noncore/games/sfcave-sdl/animatedimage.h index 1b38e6d..3c03f52 100644 --- a/noncore/games/sfcave-sdl/animatedimage.h +++ b/noncore/games/sfcave-sdl/animatedimage.h | |||
@@ -8,3 +8,3 @@ class AnimatedImage | |||
8 | public: | 8 | public: |
9 | AnimatedImage( QString file, int nFrames ); | 9 | AnimatedImage( string file, int nFrames ); |
10 | ~AnimatedImage(); | 10 | ~AnimatedImage(); |
diff --git a/noncore/games/sfcave-sdl/bfont.cpp b/noncore/games/sfcave-sdl/bfont.cpp index 0f29104..7dec8f5 100644 --- a/noncore/games/sfcave-sdl/bfont.cpp +++ b/noncore/games/sfcave-sdl/bfont.cpp | |||
@@ -75,6 +75,2 @@ void BFont::LoadFont (const char *filename) | |||
75 | } | 75 | } |
76 | else | ||
77 | { | ||
78 | cerr << "Error! The font has not been loaded!" << endl; | ||
79 | } | ||
80 | } | 76 | } |
@@ -115,3 +111,2 @@ BFont * BFont :: SetFontColor(Uint8 r, Uint8 g, Uint8 b) | |||
115 | 111 | ||
116 | printf("looking...\n"); | ||
117 | for( x=0; x < Surface->w; x++) { | 112 | for( x=0; x < Surface->w; x++) { |
@@ -133,3 +128,3 @@ BFont * BFont :: SetFontColor(Uint8 r, Uint8 g, Uint8 b) | |||
133 | } | 128 | } |
134 | printf("unlooking...\n"); | 129 | |
135 | if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); | 130 | if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); |
diff --git a/noncore/games/sfcave-sdl/constants.h b/noncore/games/sfcave-sdl/constants.h index 8fadae4..f10764e 100644 --- a/noncore/games/sfcave-sdl/constants.h +++ b/noncore/games/sfcave-sdl/constants.h | |||
@@ -5,3 +5,2 @@ | |||
5 | using namespace std; | 5 | using namespace std; |
6 | #define QString string | ||
7 | 6 | ||
@@ -57,7 +56,17 @@ using namespace std; | |||
57 | #define MENU_DIFFICULTY_HARD18 | 56 | #define MENU_DIFFICULTY_HARD18 |
58 | #define MENU_SOUNDS 19 | 57 | #define MENU_DIFFICULTY_HARD18 |
59 | #define MENU_SOUND_ON 20 | 58 | #define MENU_DIFFICULTY_CUSTOM19 |
60 | #define MENU_SOUND_OFF 21 | 59 | #define MENU_SOUNDS 20 |
61 | #define MENU_MUSIC_ON 22 | 60 | #define MENU_SOUND_ON 21 |
62 | #define MENU_MUSIC_OFF 23 | 61 | #define MENU_SOUND_OFF 22 |
62 | #define MENU_MUSIC_ON 23 | ||
63 | #define MENU_MUSIC_OFF 24 | ||
64 | #define MENU_CUSTOM_THRUST 25 | ||
65 | #define MENU_CUSTOM_GRAVITY 26 | ||
66 | #define MENU_CUSTOM_MAXSPEEDUP 27 | ||
67 | #define MENU_CUSTOM_MAXSPEEDDOWN 28 | ||
68 | #define MENU_CUSTOM_INCREASE 29 | ||
69 | #define MENU_CUSTOM_DECREASE 30 | ||
70 | #define MENU_CUSTOM_SAVE 31 | ||
71 | #define MENU_CUSTOM_CANCEL 32 | ||
63 | 72 | ||
@@ -66,2 +75,10 @@ using namespace std; | |||
66 | #define SND_THRUST 1 | 75 | #define SND_THRUST 1 |
76 | #define INGAME_MUSIC SOUND_PATH "ingame.mod" | ||
77 | |||
78 | // Constants for player values | ||
79 | #define PLAYER_THRUST 0 | ||
80 | #define PLAYER_GRAVITY 1 | ||
81 | #define PLAYER_MAX_SPEED_UP 2 | ||
82 | #define PLAYER_MAX_SPEED_DOWN 3 | ||
83 | |||
67 | #endif | 84 | #endif |
diff --git a/noncore/games/sfcave-sdl/fly_game.cpp b/noncore/games/sfcave-sdl/fly_game.cpp index f5ab401..7605c3f 100644 --- a/noncore/games/sfcave-sdl/fly_game.cpp +++ b/noncore/games/sfcave-sdl/fly_game.cpp | |||
@@ -19,2 +19,3 @@ FlyGame :: ~FlyGame() | |||
19 | { | 19 | { |
20 | // terrain and player get deleted by parent class | ||
20 | } | 21 | } |
@@ -36,2 +37,11 @@ void FlyGame :: init() | |||
36 | break; | 37 | break; |
38 | case MENU_DIFFICULTY_CUSTOM: | ||
39 | { | ||
40 | double thrust = parent->loadDoubleSetting( "Fly_custom_player_thrust", 0.3 ); | ||
41 | double gravity = parent->loadDoubleSetting( "Fly_custom_player_gravity", 0.2 ); | ||
42 | double maxUp = parent->loadDoubleSetting( "Fly_custom_player_maxupspeed", 1.5 ); | ||
43 | double maxDown = parent->loadDoubleSetting( "Fly_custom_player_maxdownspeed", 1.5 ); | ||
44 | player->setMovementInfo( thrust, gravity, maxUp, maxDown ); | ||
45 | break; | ||
46 | } | ||
37 | } | 47 | } |
@@ -52,3 +62,3 @@ void FlyGame :: update( int state ) | |||
52 | int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff ); | 62 | int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff ); |
53 | // printf( "diff - %d score - %d\n", diff, tmpScore ); | 63 | |
54 | if ( !startScoring ) | 64 | if ( !startScoring ) |
@@ -71,3 +81,2 @@ void FlyGame :: update( int state ) | |||
71 | { | 81 | { |
72 | // printf( "Crashed!\n" ); | ||
73 | parent->changeState( STATE_CRASHING ); | 82 | parent->changeState( STATE_CRASHING ); |
diff --git a/noncore/games/sfcave-sdl/font.cpp b/noncore/games/sfcave-sdl/font.cpp index 2976d48..1988252 100644 --- a/noncore/games/sfcave-sdl/font.cpp +++ b/noncore/games/sfcave-sdl/font.cpp | |||
@@ -10,3 +10,3 @@ BFont *FontHandler :: helpFont; | |||
10 | 10 | ||
11 | void FontHandler :: init() | 11 | bool FontHandler :: init() |
12 | { | 12 | { |
@@ -19,2 +19,11 @@ void FontHandler :: init() | |||
19 | colouredFont = 0; | 19 | colouredFont = 0; |
20 | |||
21 | // Check if we are installed correctly (we need fonts to function) | ||
22 | if ( menuSelFont == 0 || menuUnSelFont == 0 || whiteFont == 0 || helpFont == 0 ) | ||
23 | { | ||
24 | printf( "One or more fonts are not installed correctly\n" ); | ||
25 | return false; | ||
26 | } | ||
27 | |||
28 | return true; | ||
20 | } | 29 | } |
@@ -23,7 +32,10 @@ void FontHandler :: cleanUp() | |||
23 | { | 32 | { |
24 | delete menuSelFont; | 33 | if ( menuSelFont ) |
25 | delete menuUnSelFont; | 34 | delete menuSelFont; |
26 | delete whiteFont; | 35 | if ( menuUnSelFont ) |
27 | delete helpFont; | 36 | delete menuUnSelFont; |
28 | 37 | if ( whiteFont ) | |
38 | delete whiteFont; | ||
39 | if ( helpFont ) | ||
40 | delete helpFont; | ||
29 | if ( colouredFont ) | 41 | if ( colouredFont ) |
diff --git a/noncore/games/sfcave-sdl/font.h b/noncore/games/sfcave-sdl/font.h index e5bb707..5f0674a 100644 --- a/noncore/games/sfcave-sdl/font.h +++ b/noncore/games/sfcave-sdl/font.h | |||
@@ -15,3 +15,3 @@ class FontHandler | |||
15 | public: | 15 | public: |
16 | static void init(); | 16 | static bool init(); |
17 | static void cleanUp(); | 17 | static void cleanUp(); |
diff --git a/noncore/games/sfcave-sdl/game.cpp b/noncore/games/sfcave-sdl/game.cpp index a644696..e41e510 100644 --- a/noncore/games/sfcave-sdl/game.cpp +++ b/noncore/games/sfcave-sdl/game.cpp | |||
@@ -56,3 +56,3 @@ void Game :: init() | |||
56 | } | 56 | } |
57 | 57 | ||
58 | score = 0; | 58 | score = 0; |
@@ -78,5 +78,2 @@ void Game :: handleKeys( SDL_KeyboardEvent &key ) | |||
78 | press = true; | 78 | press = true; |
79 | |||
80 | // if ( thrustChannel == -1 && parent->getState() == STATE_PLAYING ) | ||
81 | // thrustChannel = SoundHandler :: playSound( SND_THRUST, -1, -1, false ); | ||
82 | } | 79 | } |
@@ -88,7 +85,2 @@ void Game :: handleKeys( SDL_KeyboardEvent &key ) | |||
88 | 85 | ||
89 | if ( thrustChannel != -1 ) | ||
90 | { | ||
91 | // SoundHandler :: stopSound( thrustChannel, true, 300 ); | ||
92 | // thrustChannel = -1; | ||
93 | } | ||
94 | } | 86 | } |
@@ -99,5 +91,5 @@ void Game :: handleKeys( SDL_KeyboardEvent &key ) | |||
99 | 91 | ||
100 | QString Game :: getGameDifficultyText() | 92 | string Game :: getGameDifficultyText() |
101 | { | 93 | { |
102 | QString ret; | 94 | string ret; |
103 | 95 | ||
@@ -109,2 +101,4 @@ QString Game :: getGameDifficultyText() | |||
109 | ret = "Hard"; | 101 | ret = "Hard"; |
102 | else if ( difficulty == MENU_DIFFICULTY_CUSTOM ) | ||
103 | ret = "Custom"; | ||
110 | 104 | ||
@@ -121,2 +115,12 @@ void Game :: setDifficulty( string diff ) | |||
121 | difficulty = MENU_DIFFICULTY_HARD; | 115 | difficulty = MENU_DIFFICULTY_HARD; |
116 | else if ( diff == "Custom" ) | ||
117 | difficulty = MENU_DIFFICULTY_CUSTOM; | ||
118 | |||
119 | init(); | ||
120 | } | ||
121 | |||
122 | void Game :: setDifficulty( int diff ) | ||
123 | { | ||
124 | difficulty = diff; | ||
125 | init(); | ||
122 | } | 126 | } |
@@ -133,3 +137,3 @@ void Game :: update( int state ) | |||
133 | { | 137 | { |
134 | if ( replay ) | 138 | if ( replay ) |
135 | { | 139 | { |
@@ -168,5 +172,4 @@ void Game :: draw( SDL_Surface *screen ) | |||
168 | char tmp[100]; | 172 | char tmp[100]; |
169 | QString scoreText; | 173 | string scoreText; |
170 | sprintf( tmp, "Score: %06ld High Score: %06ld", score, highScore ); | 174 | sprintf( tmp, "Score: %06ld High Score: %06ld", score, highScore ); |
171 | //printf( "%s\n", (const char *)scoreText ); | ||
172 | FontHandler::draw( screen, FONT_WHITE_TEXT, tmp, 3, 10 ); | 175 | FontHandler::draw( screen, FONT_WHITE_TEXT, tmp, 3, 10 ); |
@@ -175,3 +178,3 @@ void Game :: draw( SDL_Surface *screen ) | |||
175 | { | 178 | { |
176 | QString crashText; | 179 | string crashText; |
177 | crashText = "Game Over"; | 180 | crashText = "Game Over"; |
@@ -225,3 +228,3 @@ void Game :: setSeed( int seed ) | |||
225 | 228 | ||
226 | void Game :: saveReplay( QString file ) | 229 | void Game :: saveReplay( string file ) |
227 | { | 230 | { |
@@ -238,3 +241,3 @@ void Game :: saveReplay( QString file ) | |||
238 | // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... | 241 | // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... |
239 | QString val; | 242 | string val; |
240 | char tmp[20]; | 243 | char tmp[20]; |
@@ -253,3 +256,3 @@ void Game :: saveReplay( QString file ) | |||
253 | 256 | ||
254 | QString line; | 257 | string line; |
255 | sprintf( tmp, "%d\n", val.length() ); | 258 | sprintf( tmp, "%d\n", val.length() ); |
@@ -261,8 +264,5 @@ void Game :: saveReplay( QString file ) | |||
261 | fclose( out ); | 264 | fclose( out ); |
262 | |||
263 | printf( "Replay saved to %s\n", (const char *)file.c_str() ); | ||
264 | |||
265 | } | 265 | } |
266 | 266 | ||
267 | void Game :: loadReplay( QString file ) | 267 | void Game :: loadReplay( string file ) |
268 | { | 268 | { |
@@ -287,5 +287,4 @@ void Game :: loadReplay( QString file ) | |||
287 | fread( data, 1, length, in ); | 287 | fread( data, 1, length, in ); |
288 | // printf( "data - %s", data ); | ||
289 | 288 | ||
290 | QString sep = " "; | 289 | string sep = " "; |
291 | 290 | ||
@@ -310,5 +309,2 @@ void Game :: loadReplay( QString file ) | |||
310 | fclose( in ); | 309 | fclose( in ); |
311 | |||
312 | printf( "Replay loaded from %s\n", (const char *)file.c_str() ); | ||
313 | |||
314 | } | 310 | } |
diff --git a/noncore/games/sfcave-sdl/game.h b/noncore/games/sfcave-sdl/game.h index 56fa6a1..087f848 100644 --- a/noncore/games/sfcave-sdl/game.h +++ b/noncore/games/sfcave-sdl/game.h | |||
@@ -27,6 +27,6 @@ public: | |||
27 | void handleKeys( SDL_KeyboardEvent &key ); | 27 | void handleKeys( SDL_KeyboardEvent &key ); |
28 | QString getGameName() { return gameName; } | 28 | string getGameName() { return gameName; } |
29 | int getDifficulty() { return difficulty; } | 29 | int getDifficulty() { return difficulty; } |
30 | QString getGameDifficultyText(); | 30 | string getGameDifficultyText(); |
31 | void setDifficulty( int diff ) { difficulty = diff; } | 31 | void setDifficulty( int diff ); |
32 | void setDifficulty( string diff ); | 32 | void setDifficulty( string diff ); |
@@ -41,6 +41,7 @@ public: | |||
41 | Terrain *getTerrain() { return terrain; } | 41 | Terrain *getTerrain() { return terrain; } |
42 | Player *getPlayer() { return player; } | ||
42 | 43 | ||
43 | void setSeed( int seed ); | 44 | void setSeed( int seed ); |
44 | void loadReplay( QString file ); | 45 | void loadReplay( string file ); |
45 | void saveReplay( QString file ); | 46 | void saveReplay( string file ); |
46 | 47 | ||
@@ -49,3 +50,3 @@ public: | |||
49 | protected: | 50 | protected: |
50 | QString gameName; | 51 | string gameName; |
51 | 52 | ||
@@ -71,8 +72,6 @@ protected: | |||
71 | 72 | ||
72 | // QListIterator<int> *replayIt; | ||
73 | list<int> replayList; | 73 | list<int> replayList; |
74 | list<int>::iterator replayIt; | 74 | list<int>::iterator replayIt; |
75 | //QList<int> replayList; | ||
76 | bool replay; | 75 | bool replay; |
77 | QString replayFile; | 76 | string replayFile; |
78 | 77 | ||
diff --git a/noncore/games/sfcave-sdl/gates_game.cpp b/noncore/games/sfcave-sdl/gates_game.cpp index 1a9bc89..762801d 100644 --- a/noncore/games/sfcave-sdl/gates_game.cpp +++ b/noncore/games/sfcave-sdl/gates_game.cpp | |||
@@ -20,2 +20,3 @@ GatesGame :: ~GatesGame() | |||
20 | { | 20 | { |
21 | // terrain and player get deleted by parent class | ||
21 | } | 22 | } |
@@ -48,2 +49,15 @@ void GatesGame :: init() | |||
48 | break; | 49 | break; |
50 | case MENU_DIFFICULTY_CUSTOM: | ||
51 | { | ||
52 | // Read custom difficulty settings for this game | ||
53 | gapHeight = parent->loadIntSetting( "Gates_custom_gapHeight", 75 ); | ||
54 | |||
55 | double thrust = parent->loadDoubleSetting( "Gates_custom_player_thrust", 0.4 ); | ||
56 | double gravity = parent->loadDoubleSetting( "Gates_custom_player_gravity", 0.6 ); | ||
57 | double maxUp = parent->loadDoubleSetting( "Gates_custom_player_maxupspeed", 4.0 ); | ||
58 | double maxDown = parent->loadDoubleSetting( "Gates_custom_player_maxdownspeed", 5.0 ); | ||
59 | player->setMovementInfo( thrust, gravity, maxUp, maxDown ); | ||
60 | |||
61 | break; | ||
62 | } | ||
49 | } | 63 | } |
@@ -79,3 +93,2 @@ void GatesGame :: update( int state ) | |||
79 | { | 93 | { |
80 | // printf( "Crashed!\n" ); | ||
81 | parent->changeState( STATE_CRASHING ); | 94 | parent->changeState( STATE_CRASHING ); |
diff --git a/noncore/games/sfcave-sdl/help.cpp b/noncore/games/sfcave-sdl/help.cpp index 91c62da..f1728f6 100644 --- a/noncore/games/sfcave-sdl/help.cpp +++ b/noncore/games/sfcave-sdl/help.cpp | |||
@@ -37,3 +37,3 @@ void Help :: handleKeys( SDL_KeyboardEvent &key ) | |||
37 | } | 37 | } |
38 | 38 | ||
39 | } | 39 | } |
@@ -50,3 +50,3 @@ void Help :: init() | |||
50 | textSpeed = 1; | 50 | textSpeed = 1; |
51 | 51 | ||
52 | // Create our coloured font | 52 | // Create our coloured font |
@@ -59,3 +59,2 @@ void Help :: draw( SDL_Surface *screen ) | |||
59 | 59 | ||
60 | |||
61 | list<string>::iterator it = textList.begin(); | 60 | list<string>::iterator it = textList.begin(); |
@@ -77,3 +76,3 @@ void Help :: draw( SDL_Surface *screen ) | |||
77 | } | 76 | } |
78 | 77 | ||
79 | } | 78 | } |
@@ -83,3 +82,3 @@ void Help :: update() | |||
83 | stars->move(); | 82 | stars->move(); |
84 | 83 | ||
85 | startPos -= textSpeed; | 84 | startPos -= textSpeed; |
diff --git a/noncore/games/sfcave-sdl/menu.cpp b/noncore/games/sfcave-sdl/menu.cpp index 0a7366f..a4a4216 100644 --- a/noncore/games/sfcave-sdl/menu.cpp +++ b/noncore/games/sfcave-sdl/menu.cpp | |||
@@ -10,3 +10,3 @@ | |||
10 | 10 | ||
11 | MenuOption :: MenuOption( QString text, int id ) | 11 | MenuOption :: MenuOption( string text, int id ) |
12 | { | 12 | { |
@@ -117,2 +117,3 @@ Menu :: Menu( SFCave *p ) | |||
117 | // Game Difficulty menu | 117 | // Game Difficulty menu |
118 | MenuOption *customMenu = 0; | ||
118 | Menu *gameDifficulty = new Menu( options ); | 119 | Menu *gameDifficulty = new Menu( options ); |
@@ -124,2 +125,3 @@ Menu :: Menu( SFCave *p ) | |||
124 | item->setNextMenu( options, false ); | 125 | item->setNextMenu( options, false ); |
126 | customMenu = gameDifficulty->addMenuOption( "Custom", MENU_DIFFICULTY_CUSTOM ); | ||
125 | item = gameDifficulty->addMenuOption( "Back", MENU_BACK ); | 127 | item = gameDifficulty->addMenuOption( "Back", MENU_BACK ); |
@@ -137,2 +139,25 @@ Menu :: Menu( SFCave *p ) | |||
137 | soundsMenu->setNextMenu( sounds ); | 139 | soundsMenu->setNextMenu( sounds ); |
140 | |||
141 | // Custom Menu | ||
142 | Menu *custom = new Menu( gameDifficulty ); | ||
143 | Menu *updown = new Menu( custom ); | ||
144 | item = custom->addMenuOption( "Thrust", MENU_CUSTOM_THRUST ); | ||
145 | item->setNextMenu( updown ); | ||
146 | item = custom->addMenuOption( "Gravity", MENU_CUSTOM_GRAVITY ); | ||
147 | item->setNextMenu( updown ); | ||
148 | item = custom->addMenuOption( "Max Speed Up", MENU_CUSTOM_MAXSPEEDUP ); | ||
149 | item->setNextMenu( updown ); | ||
150 | item = custom->addMenuOption( "Max Speed Down", MENU_CUSTOM_MAXSPEEDDOWN ); | ||
151 | item->setNextMenu( updown ); | ||
152 | item = custom->addMenuOption( "Back", MENU_BACK ); | ||
153 | item->setNextMenu( gameDifficulty, false ); | ||
154 | customMenu->setNextMenu( custom ); | ||
155 | |||
156 | // Up down menu | ||
157 | item = updown->addMenuOption( "Increase", MENU_CUSTOM_INCREASE ); | ||
158 | item = updown->addMenuOption( "Decrease", MENU_CUSTOM_DECREASE ); | ||
159 | item = updown->addMenuOption( "Save", MENU_CUSTOM_SAVE ); | ||
160 | item->setNextMenu( custom, false ); | ||
161 | item = updown->addMenuOption( "Cancel", MENU_CUSTOM_CANCEL ); | ||
162 | item->setNextMenu( custom, false ); | ||
138 | 163 | ||
@@ -217,3 +242,2 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
217 | 242 | ||
218 | statusText = ""; | ||
219 | switch( key.keysym.sym ) | 243 | switch( key.keysym.sym ) |
@@ -278,4 +302,4 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
278 | { | 302 | { |
303 | statusText = ""; | ||
279 | currentMenu = currentMenu->parentMenu; | 304 | currentMenu = currentMenu->parentMenu; |
280 | printf( "HERE\n" ); | ||
281 | 305 | ||
@@ -288,5 +312,7 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
288 | { | 312 | { |
313 | statusText = ""; | ||
289 | // select menu item | 314 | // select menu item |
290 | int id = currentMenu->currentMenuOption->getMenuId(); | 315 | int id = currentMenu->currentMenuOption->getMenuId(); |
291 | // // if the current item has a child menu then move to that menu | 316 | |
317 | // if the current item has a child menu then move to that menu | ||
292 | Menu *next = currentMenu->currentMenuOption->getNextMenu(); | 318 | Menu *next = currentMenu->currentMenuOption->getNextMenu(); |
@@ -298,9 +324,6 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
298 | initCurrentMenu(); | 324 | initCurrentMenu(); |
299 | // return -1; | ||
300 | } | ||
301 | // else | ||
302 | { | ||
303 | return id; | ||
304 | } | 325 | } |
305 | 326 | ||
327 | return id; | ||
328 | |||
306 | break; | 329 | break; |
@@ -315,3 +338,3 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
315 | 338 | ||
316 | MenuOption *Menu :: addMenuOption( QString text, int id ) | 339 | MenuOption *Menu :: addMenuOption( string text, int id ) |
317 | { | 340 | { |
diff --git a/noncore/games/sfcave-sdl/menu.h b/noncore/games/sfcave-sdl/menu.h index 08f7528..6a5ef40 100644 --- a/noncore/games/sfcave-sdl/menu.h +++ b/noncore/games/sfcave-sdl/menu.h | |||
@@ -15,3 +15,3 @@ class MenuOption | |||
15 | public: | 15 | public: |
16 | MenuOption( QString text, int id ); | 16 | MenuOption( string text, int id ); |
17 | ~MenuOption(); | 17 | ~MenuOption(); |
@@ -27,3 +27,3 @@ private: | |||
27 | int menuId; | 27 | int menuId; |
28 | QString menuText; | 28 | string menuText; |
29 | bool highlighted; | 29 | bool highlighted; |
@@ -42,3 +42,3 @@ public: | |||
42 | int handleKeys( SDL_KeyboardEvent & ); | 42 | int handleKeys( SDL_KeyboardEvent & ); |
43 | MenuOption *addMenuOption( QString text, int id ); | 43 | MenuOption *addMenuOption( string text, int id ); |
44 | void resetToTopMenu(); | 44 | void resetToTopMenu(); |
@@ -46,3 +46,3 @@ public: | |||
46 | 46 | ||
47 | void setStatusText( QString text ) { statusText = text; } | 47 | void setStatusText( string text ) { statusText = text; } |
48 | 48 | ||
@@ -60,3 +60,3 @@ private: | |||
60 | 60 | ||
61 | QString statusText; | 61 | string statusText; |
62 | 62 | ||
diff --git a/noncore/games/sfcave-sdl/player.cpp b/noncore/games/sfcave-sdl/player.cpp index 830ee78..2d52ae2 100644 --- a/noncore/games/sfcave-sdl/player.cpp +++ b/noncore/games/sfcave-sdl/player.cpp | |||
@@ -13,4 +13,4 @@ Player :: Player( int w, int h ) | |||
13 | 13 | ||
14 | thrustUp = 0.4; | 14 | thrust = 0.4; |
15 | thrustDown = 0.6; | 15 | gravity = 0.6; |
16 | maxUpSpeed = 4.0; | 16 | maxUpSpeed = 4.0; |
@@ -82,6 +82,3 @@ void Player :: drawTrails( SDL_Surface *screen ) | |||
82 | { | 82 | { |
83 | // int r = (int) ((255.0/pos.x()) * (trail[i].x)); | ||
84 | // int g = (int) ((150.0/pos.x()) * (trail[i].x)); | ||
85 | int c = (int)((150.0/50) * (50.0 - (pos.x() - trail[i].x() ) )); | 83 | int c = (int)((150.0/50) * (50.0 - (pos.x() - trail[i].x() ) )); |
86 | // SDL_FillRect( screen, &trail[i], SDL_MapRGBA( screen->format, r, g, 0, 0 ) ); //(int)(1.5*c), 0, 255 ) ); | ||
87 | boxRGBA( screen, trail[i].x(), trail[i].y(), trail[i].x() + 2, trail[i].y() + 2, 255, (int)(1.5*c), 0, c ); | 84 | boxRGBA( screen, trail[i].x(), trail[i].y(), trail[i].x() + 2, trail[i].y() + 2, 255, (int)(1.5*c), 0, c ); |
@@ -97,12 +94,12 @@ void Player :: move( bool up ) | |||
97 | if ( up ) | 94 | if ( up ) |
98 | thrust -= thrustUp; | 95 | currentThrust -= thrust; |
99 | else | 96 | else |
100 | thrust += thrustDown; | 97 | currentThrust += gravity; |
101 | 98 | ||
102 | if ( thrust > maxDownSpeed ) | 99 | if ( currentThrust > maxDownSpeed ) |
103 | thrust = maxDownSpeed; | 100 | currentThrust = maxDownSpeed; |
104 | else if ( thrust < -maxUpSpeed ) | 101 | else if ( currentThrust < -maxUpSpeed ) |
105 | thrust = -maxUpSpeed; | 102 | currentThrust = -maxUpSpeed; |
106 | 103 | ||
107 | pos.moveBy( 0, (int)(thrust) ); | 104 | pos.moveBy( 0, (int)(currentThrust) ); |
108 | } | 105 | } |
@@ -154,6 +151,6 @@ bool Player :: updateCrashing() | |||
154 | 151 | ||
155 | void Player :: setMovementInfo( double up, double down, double maxUp, double maxDown ) | 152 | void Player :: setMovementInfo( double up, double grav, double maxUp, double maxDown ) |
156 | { | 153 | { |
157 | thrustUp = up; | 154 | thrust = up; |
158 | thrustDown = down; | 155 | gravity = grav; |
159 | maxUpSpeed = maxUp; | 156 | maxUpSpeed = maxUp; |
@@ -162 +159,126 @@ void Player :: setMovementInfo( double up, double down, double maxUp, double max | |||
162 | 159 | ||
160 | |||
161 | void Player :: incValue( int valueType ) | ||
162 | { | ||
163 | switch( valueType ) | ||
164 | { | ||
165 | case PLAYER_THRUST: | ||
166 | thrust += 0.1; | ||
167 | break; | ||
168 | case PLAYER_GRAVITY: | ||
169 | gravity += 0.1; | ||
170 | break; | ||
171 | case PLAYER_MAX_SPEED_UP: | ||
172 | maxUpSpeed += 0.1; | ||
173 | break; | ||
174 | case PLAYER_MAX_SPEED_DOWN: | ||
175 | maxDownSpeed += 0.1; | ||
176 | break; | ||
177 | } | ||
178 | } | ||
179 | |||
180 | void Player :: decValue( int valueType ) | ||
181 | { | ||
182 | switch( valueType ) | ||
183 | { | ||
184 | case PLAYER_THRUST: | ||
185 | thrust -= 0.1; | ||
186 | break; | ||
187 | case PLAYER_GRAVITY: | ||
188 | gravity -= 0.1; | ||
189 | break; | ||
190 | case PLAYER_MAX_SPEED_UP: | ||
191 | maxUpSpeed -= 0.1; | ||
192 | break; | ||
193 | case PLAYER_MAX_SPEED_DOWN: | ||
194 | maxDownSpeed -= 0.1; | ||
195 | break; | ||
196 | } | ||
197 | } | ||
198 | |||
199 | void Player :: setValue( int valueType, double val ) | ||
200 | { | ||
201 | switch( valueType ) | ||
202 | { | ||
203 | case PLAYER_THRUST: | ||
204 | thrust = val; | ||
205 | break; | ||
206 | case PLAYER_GRAVITY: | ||
207 | gravity = val; | ||
208 | break; | ||
209 | case PLAYER_MAX_SPEED_UP: | ||
210 | maxUpSpeed = val; | ||
211 | break; | ||
212 | case PLAYER_MAX_SPEED_DOWN: | ||
213 | maxDownSpeed = val; | ||
214 | break; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | double Player :: getValue( int valueType ) | ||
219 | { | ||
220 | double val; | ||
221 | switch( valueType ) | ||
222 | { | ||
223 | case PLAYER_THRUST: | ||
224 | val = thrust; | ||
225 | break; | ||
226 | case PLAYER_GRAVITY: | ||
227 | val = gravity; | ||
228 | break; | ||
229 | case PLAYER_MAX_SPEED_UP: | ||
230 | val = maxUpSpeed; | ||
231 | break; | ||
232 | case PLAYER_MAX_SPEED_DOWN: | ||
233 | val = maxDownSpeed; | ||
234 | break; | ||
235 | } | ||
236 | |||
237 | return val; | ||
238 | } | ||
239 | |||
240 | string Player :: getValueTypeString( int valueType ) | ||
241 | { | ||
242 | string val; | ||
243 | switch( valueType ) | ||
244 | { | ||
245 | case PLAYER_THRUST: | ||
246 | val = "thrust"; | ||
247 | break; | ||
248 | case PLAYER_GRAVITY: | ||
249 | val = "gravity"; | ||
250 | break; | ||
251 | case PLAYER_MAX_SPEED_UP: | ||
252 | val = "maxupspeed"; | ||
253 | break; | ||
254 | case PLAYER_MAX_SPEED_DOWN: | ||
255 | val = "maxdownspeed"; | ||
256 | break; | ||
257 | } | ||
258 | |||
259 | return val; | ||
260 | } | ||
261 | |||
262 | string Player :: getValueString( int valueType ) | ||
263 | { | ||
264 | char val[50]; | ||
265 | switch( valueType ) | ||
266 | { | ||
267 | case PLAYER_THRUST: | ||
268 | sprintf( val, "Thrust - %lf", thrust ); | ||
269 | break; | ||
270 | case PLAYER_GRAVITY: | ||
271 | sprintf( val, "Gravity - %lf", gravity ); | ||
272 | break; | ||
273 | case PLAYER_MAX_SPEED_UP: | ||
274 | sprintf( val, "Max Speed Up - %lf", maxUpSpeed ); | ||
275 | break; | ||
276 | case PLAYER_MAX_SPEED_DOWN: | ||
277 | sprintf( val, "Max Speed Down - %lf", maxDownSpeed ); | ||
278 | break; | ||
279 | } | ||
280 | |||
281 | string ret = val; | ||
282 | return ret; | ||
283 | } | ||
284 | |||
diff --git a/noncore/games/sfcave-sdl/player.h b/noncore/games/sfcave-sdl/player.h index e4c904a..595c25b 100644 --- a/noncore/games/sfcave-sdl/player.h +++ b/noncore/games/sfcave-sdl/player.h | |||
@@ -24,3 +24,9 @@ public: | |||
24 | bool updateCrashing(); | 24 | bool updateCrashing(); |
25 | void setMovementInfo( double up, double down, double maxUp, double maxDown ); | 25 | void setMovementInfo( double up, double grav, double maxUp, double maxDown ); |
26 | void incValue( int valType ); | ||
27 | void decValue( int valType ); | ||
28 | double getValue( int valueType ); | ||
29 | string getValueString( int valueType ); | ||
30 | string getValueTypeString( int valueType ); | ||
31 | void setValue( int valueType, double val ); | ||
26 | 32 | ||
@@ -38,6 +44,6 @@ private: | |||
38 | Rect pos; | 44 | Rect pos; |
39 | double thrust; | 45 | double currentThrust; |
40 | 46 | ||
41 | double thrustUp; | 47 | double thrust; |
42 | double thrustDown; | 48 | double gravity; |
43 | double maxUpSpeed; | 49 | double maxUpSpeed; |
diff --git a/noncore/games/sfcave-sdl/settings.cpp b/noncore/games/sfcave-sdl/settings.cpp index 914c4ec..20cce4f 100644 --- a/noncore/games/sfcave-sdl/settings.cpp +++ b/noncore/games/sfcave-sdl/settings.cpp | |||
@@ -7,2 +7,4 @@ | |||
7 | 7 | ||
8 | // Defined in util.h | ||
9 | string getHomeDir(); | ||
8 | 10 | ||
@@ -18,11 +20,4 @@ Settings::Settings( char * env_file, char * env_dir ) | |||
18 | { | 20 | { |
19 | char * homeDir = getenv( "HOME" );; | 21 | envFile = getHomeDir(); |
20 | 22 | envFile.append("/"); | |
21 | if ( homeDir ) | ||
22 | { | ||
23 | envFile.append(homeDir); | ||
24 | envFile.append("/"); | ||
25 | } | ||
26 | else | ||
27 | printf( "Environment var HOME not set!\n" ); | ||
28 | 23 | ||
@@ -44,11 +39,4 @@ Settings::Settings() | |||
44 | { | 39 | { |
45 | char * homeDir = getenv("HOME"); | 40 | envFile = getHomeDir(); |
46 | 41 | envFile.append("/"); | |
47 | if ( homeDir) | ||
48 | { | ||
49 | envFile.append(homeDir); | ||
50 | envFile.append("/"); | ||
51 | } | ||
52 | else | ||
53 | printf( "Environment var HOME not set!\n" ); | ||
54 | 42 | ||
@@ -112,2 +100,14 @@ bool Settings::readSetting(const string key_str,unsigned long& result) | |||
112 | 100 | ||
101 | bool Settings::readSetting(const string key_str,double& result) | ||
102 | { | ||
103 | string Buffer; | ||
104 | if (readSetting(key_str,Buffer)) | ||
105 | { | ||
106 | result = atof( Buffer.c_str() ); | ||
107 | return true; | ||
108 | } | ||
109 | else | ||
110 | return false; | ||
111 | } | ||
112 | |||
113 | bool Settings::readSetting(const string key_str,bool& result) | 113 | bool Settings::readSetting(const string key_str,bool& result) |
@@ -161,2 +161,10 @@ void Settings::writeSetting(const string key_str,const bool value) | |||
161 | 161 | ||
162 | void Settings::writeSetting(const string key_str,const double value) | ||
163 | { | ||
164 | char Buffer[30]; | ||
165 | |||
166 | sprintf(Buffer,"%lf",value); | ||
167 | writeSetting(key_str,string(Buffer)); | ||
168 | } | ||
169 | |||
162 | void Settings::writeSetting(const string key_str,const int value) | 170 | void Settings::writeSetting(const string key_str,const int value) |
@@ -197,37 +205,30 @@ void Settings::writeSetting(const string key_str,const string value) | |||
197 | // already exists then it will be overwritten. | 205 | // already exists then it will be overwritten. |
198 | |||
199 | std::vector<string> FileEntries; | ||
200 | FILE *fd=NULL,*ftemp=NULL; | 206 | FILE *fd=NULL,*ftemp=NULL; |
201 | char * dir_str; | ||
202 | char * dir_ptr; | ||
203 | char buf[MAX_LINE_SIZE]; | 207 | char buf[MAX_LINE_SIZE]; |
204 | char tempname[12]; | ||
205 | 208 | ||
206 | dir_str = strdup(envFile.c_str()); | 209 | string tmp = getHomeDir() + "/tmpsfcave.dat"; |
207 | printf( "dir = %s, file - %s\n", dir_str, envFile.c_str() ); | 210 | |
208 | if (dir_str) | 211 | // if file exists we need to save contents |
212 | fd = fopen( envFile.c_str(), "r" ); | ||
213 | ftemp = fopen( tmp.c_str(), "w" ); | ||
214 | if ( fd != NULL && ftemp != NULL ) | ||
209 | { | 215 | { |
210 | // remove file from the directory string | 216 | while (fgets(buf, MAX_LINE_SIZE-1, fd)) |
211 | dir_ptr = strrchr(dir_str, (int)'/'); | ||
212 | if (dir_ptr) | ||
213 | { | 217 | { |
214 | *dir_ptr = 0; | 218 | if ( strncmp( buf, key_str.c_str(), key_str.size() ) != 0 ) |
215 | 219 | fprintf( ftemp, "%s", buf ); | |
216 | // make the directory path if it does not exist | 220 | } |
217 | // mkdir(dir_str, 777 ); | 221 | fclose(fd); |
222 | } | ||
218 | 223 | ||
219 | // if file exists we need to save contents | 224 | if ( ftemp != NULL ) |
220 | if ((fd = fopen(envFile.c_str(), "r")) != NULL) | 225 | { |
221 | { | 226 | fprintf(ftemp, "%s\t%s\n", key_str.c_str(),value.c_str()); |
222 | while (fgets(buf, MAX_LINE_SIZE-1, fd)) | 227 | fclose( ftemp ); |
223 | FileEntries.push_back(string(buf)); | ||
224 | fclose(fd); | ||
225 | } | ||
226 | 228 | ||
227 | char *home = getenv( "HOME" ); | 229 | remove(envFile.c_str()); |
228 | string tmp; | 230 | rename( tmp.c_str(), envFile.c_str() ); |
229 | if ( home ) | 231 | } |
230 | tmp = home + string( "/" ) + "tmpsfcave.dat"; | 232 | /* |
231 | else | 233 | string tmp = getHomeDir() + "/tmpsfcave.dat"; |
232 | tmp = "./tmpsfcave.dat"; | ||
233 | strcpy(tempname,tmp.c_str() ); | 234 | strcpy(tempname,tmp.c_str() ); |
@@ -256,6 +257,2 @@ void Settings::writeSetting(const string key_str,const string value) | |||
256 | fclose(ftemp); | 257 | fclose(ftemp); |
257 | |||
258 | remove(envFile.c_str()); | ||
259 | |||
260 | rename( tempname, envFile.c_str() ); | ||
261 | } | 258 | } |
@@ -267,2 +264,3 @@ void Settings::writeSetting(const string key_str,const string value) | |||
267 | } | 264 | } |
265 | */ | ||
268 | } | 266 | } |
diff --git a/noncore/games/sfcave-sdl/settings.h b/noncore/games/sfcave-sdl/settings.h index 5e828ed..a3af999 100644 --- a/noncore/games/sfcave-sdl/settings.h +++ b/noncore/games/sfcave-sdl/settings.h | |||
@@ -34,2 +34,3 @@ public: | |||
34 | bool readSetting(const string key_str,unsigned long& result); | 34 | bool readSetting(const string key_str,unsigned long& result); |
35 | bool readSetting(const string key_str,double & result); | ||
35 | bool readSetting(const string key_str,bool& result); | 36 | bool readSetting(const string key_str,bool& result); |
@@ -41,2 +42,3 @@ public: | |||
41 | void writeSetting(const string key_str,const unsigned long result); | 42 | void writeSetting(const string key_str,const unsigned long result); |
43 | void writeSetting(const string key_str,const double value); | ||
42 | void writeSetting(const string key_str,const bool value); | 44 | void writeSetting(const string key_str,const bool value); |
@@ -44,3 +46,3 @@ public: | |||
44 | void deleteFile(void); | 46 | void deleteFile(void); |
45 | 47 | ||
46 | private: | 48 | private: |
diff --git a/noncore/games/sfcave-sdl/sfcave.cpp b/noncore/games/sfcave-sdl/sfcave.cpp index 8d376a1..dbd788c 100644 --- a/noncore/games/sfcave-sdl/sfcave.cpp +++ b/noncore/games/sfcave-sdl/sfcave.cpp | |||
@@ -28,5 +28,5 @@ void start( int argc, char *argv[] ) | |||
28 | { | 28 | { |
29 | FontHandler::init(); | 29 | SFCave *app = new SFCave( argc, argv ); |
30 | SFCave app( argc, argv ); | 30 | app->mainEventLoop(); |
31 | FontHandler::cleanUp(); | 31 | delete app; |
32 | } | 32 | } |
@@ -45,2 +45,5 @@ SFCave :: SFCave( int argc, char *argv[] ) | |||
45 | { | 45 | { |
46 | setupOK = false; | ||
47 | |||
48 | // Load settings | ||
46 | string diff = loadSetting( "GameDifficulty", "Easy" ); | 49 | string diff = loadSetting( "GameDifficulty", "Easy" ); |
@@ -48,6 +51,8 @@ SFCave :: SFCave( int argc, char *argv[] ) | |||
48 | musicPath = loadSetting( "MusicPath", SOUND_PATH ); | 51 | musicPath = loadSetting( "MusicPath", SOUND_PATH ); |
49 | printf( "musicPath %s\n", musicPath.c_str() ); | ||
50 | musicType = loadSetting( "MusicType", "mod,ogg" ); | 52 | musicType = loadSetting( "MusicType", "mod,ogg" ); |
53 | bool soundOn = loadBoolSetting( "SoundOn", true ); | ||
54 | bool musicOn = loadBoolSetting( "MusicOn", true ); | ||
51 | if ( musicPath[musicPath.size()-1] != '/' ) | 55 | if ( musicPath[musicPath.size()-1] != '/' ) |
52 | musicPath += "/"; | 56 | musicPath += "/"; |
57 | printf( "musicPath %s\n", musicPath.c_str() ); | ||
53 | 58 | ||
@@ -56,2 +61,9 @@ SFCave :: SFCave( int argc, char *argv[] ) | |||
56 | 61 | ||
62 | // Init font handler | ||
63 | if ( !FontHandler::init() ) | ||
64 | { | ||
65 | printf( "Unable to initialise fonts!\n" ); | ||
66 | return; | ||
67 | } | ||
68 | |||
57 | // Init SoundHandler | 69 | // Init SoundHandler |
@@ -60,2 +72,5 @@ SFCave :: SFCave( int argc, char *argv[] ) | |||
60 | 72 | ||
73 | SoundHandler :: setSoundsOn( soundOn ); | ||
74 | SoundHandler :: setMusicOn( musicOn ); | ||
75 | |||
61 | currentGame = Game::createGame( this, WIDTH, HEIGHT, game, diff ); | 76 | currentGame = Game::createGame( this, WIDTH, HEIGHT, game, diff ); |
@@ -64,4 +79,7 @@ SFCave :: SFCave( int argc, char *argv[] ) | |||
64 | currentGame->setSeed(-1); | 79 | currentGame->setSeed(-1); |
80 | |||
81 | // Create menu | ||
65 | menu = new Menu( this ); | 82 | menu = new Menu( this ); |
66 | 83 | ||
84 | // Create help screen | ||
67 | help = new Help( this ); | 85 | help = new Help( this ); |
@@ -70,6 +88,4 @@ SFCave :: SFCave( int argc, char *argv[] ) | |||
70 | showFps = false; | 88 | showFps = false; |
71 | mainEventLoop(); | 89 | |
72 | 90 | setupOK = true; | |
73 | SoundHandler :: cleanUp(); | ||
74 | SDL_Quit(); | ||
75 | } | 91 | } |
@@ -84,12 +100,13 @@ SFCave :: ~SFCave() | |||
84 | 100 | ||
85 | SDL_FreeSurface( screen ); | 101 | if ( help ) |
86 | } | 102 | delete help; |
87 | |||
88 | 103 | ||
89 | void SFCave :: drawGameScreen( ) | 104 | SDL_FreeSurface( screen ); |
90 | { | 105 | FontHandler::cleanUp(); |
91 | //ClearScreen(screen, "Titletext"); | 106 | SoundHandler :: cleanUp(); |
92 | 107 | ||
108 | SDL_Quit(); | ||
93 | } | 109 | } |
94 | 110 | ||
111 | |||
95 | void SFCave :: initSDL( int argc, char *argv[] ) | 112 | void SFCave :: initSDL( int argc, char *argv[] ) |
@@ -100,5 +117,3 @@ void SFCave :: initSDL( int argc, char *argv[] ) | |||
100 | 117 | ||
101 | 118 | // Initialize SDL | |
102 | |||
103 | /* Initialize SDL */ | ||
104 | if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) { | 119 | if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) { |
@@ -107,26 +122,31 @@ void SFCave :: initSDL( int argc, char *argv[] ) | |||
107 | } | 122 | } |
108 | atexit(SDL_Quit); | ||
109 | 123 | ||
110 | /* Alpha blending doesn't work well at 8-bit color */ | ||
111 | video_bpp = 16; | 124 | video_bpp = 16; |
112 | 125 | ||
113 | if ( !SDL_VideoModeOK(WIDTH, HEIGHT, 16, SDL_DOUBLEBUF) ) | 126 | if ( !SDL_VideoModeOK(WIDTH, HEIGHT, video_bpp, SDL_DOUBLEBUF) ) |
114 | printf( "No double buffering\n" ); | 127 | printf( "No double buffering\n" ); |
115 | 128 | ||
116 | videoflags = SDL_HWSURFACE | SDL_SRCALPHA;//|| SDL_DOUBLEBUF;// | SDL_SRCALPHA | SDL_RESIZABLE; | 129 | videoflags = SDL_HWSURFACE | SDL_SRCALPHA; |
117 | while ( argc > 1 ) { | 130 | while ( argc > 1 ) |
131 | { | ||
118 | --argc; | 132 | --argc; |
119 | if ( strcmp(argv[argc-1], "-bpp") == 0 ) { | 133 | if ( strcmp(argv[argc-1], "-bpp") == 0 ) |
134 | { | ||
120 | video_bpp = atoi(argv[argc]); | 135 | video_bpp = atoi(argv[argc]); |
121 | --argc; | 136 | --argc; |
122 | } else | 137 | } |
123 | if ( strcmp(argv[argc], "-hw") == 0 ) { | 138 | else if ( strcmp(argv[argc], "-hw") == 0 ) |
139 | { | ||
124 | videoflags |= SDL_HWSURFACE; | 140 | videoflags |= SDL_HWSURFACE; |
125 | } else | 141 | } |
126 | if ( strcmp(argv[argc], "-warp") == 0 ) { | 142 | else if ( strcmp(argv[argc], "-warp") == 0 ) |
143 | { | ||
127 | videoflags |= SDL_HWPALETTE; | 144 | videoflags |= SDL_HWPALETTE; |
128 | } else | 145 | } |
129 | if ( strcmp(argv[argc], "-fullscreen") == 0 ) { | 146 | else if ( strcmp(argv[argc], "-fullscreen") == 0 ) |
147 | { | ||
130 | videoflags |= SDL_FULLSCREEN; | 148 | videoflags |= SDL_FULLSCREEN; |
131 | } else { | 149 | } |
150 | else if ( strcmp(argv[argc], "-h") == 0 ) | ||
151 | { | ||
132 | fprintf(stderr, | 152 | fprintf(stderr, |
@@ -138,5 +158,6 @@ void SFCave :: initSDL( int argc, char *argv[] ) | |||
138 | 158 | ||
139 | /* Set 240x320 video mode */ | 159 | // Set 240x320 video mode |
140 | if ( (screen=SDL_SetVideoMode(WIDTH,HEIGHT,video_bpp,videoflags)) == NULL ) { | 160 | if ( (screen = SDL_SetVideoMode( WIDTH,HEIGHT,video_bpp,videoflags )) == NULL ) |
141 | fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError()); | 161 | { |
162 | printf( "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError() ); | ||
142 | exit(2); | 163 | exit(2); |
@@ -144,6 +165,6 @@ void SFCave :: initSDL( int argc, char *argv[] ) | |||
144 | 165 | ||
145 | /* Use alpha blending */ | 166 | // Use alpha blending |
146 | SDL_SetAlpha(screen, SDL_RLEACCEL, 0); | 167 | //SDL_SetAlpha(screen, SDL_RLEACCEL, 0); |
147 | 168 | ||
148 | /* Set title for window */ | 169 | // Set title for window |
149 | SDL_WM_SetCaption("SFCave","SFCave"); | 170 | SDL_WM_SetCaption("SFCave","SFCave"); |
@@ -153,7 +174,7 @@ void SFCave :: mainEventLoop() | |||
153 | { | 174 | { |
154 | SDL_Event event; | 175 | if ( !setupOK ) |
155 | int done; | 176 | return; |
156 | 177 | ||
157 | /* Wait for a keystroke */ | 178 | // Wait for a keystroke |
158 | done = 0; | 179 | finish = false; |
159 | state = 0; | 180 | state = 0; |
@@ -162,93 +183,20 @@ void SFCave :: mainEventLoop() | |||
162 | 183 | ||
163 | int FPS = 0; | 184 | FPS = 0; |
164 | bool limitFPS = true; | ||
165 | actualFPS = 0; | 185 | actualFPS = 0; |
166 | long time1 = 0; | 186 | time1 = 0; |
167 | long start; | 187 | |
168 | long end; | 188 | limitFPS = true; |
169 | //long nrTimes = 0; | 189 | while ( !finish ) |
170 | struct timeb tp; | ||
171 | while ( !done ) | ||
172 | { | 190 | { |
173 | // calc FPS | 191 | // calc FPS |
174 | ftime( &tp ); | 192 | calcFPS(); |
175 | start =(tp.time%10000)*10000 + tp.millitm; | ||
176 | // printf( "start = %ld, time1 - %d, st-tm - %d, tp.time - %ld\n", start, time1, start-time1, (tp.time%1000)*1000 ); | ||
177 | if ( start - time1 >= 1000 ) | ||
178 | { | ||
179 | actualFPS = FPS; | ||
180 | // printf( "%d FPS = %d\n", nrTimes++, actualFPS ); | ||
181 | FPS = 0; | ||
182 | time1 = start; | ||
183 | } | ||
184 | else | ||
185 | FPS ++; | ||
186 | 193 | ||
187 | SDL_FillRect( screen, 0, 0 ); | 194 | SDL_FillRect( screen, 0, 0 ); |
188 | switch( state ) | ||
189 | { | ||
190 | case STATE_MENU: | ||
191 | SDL_FillRect( screen, 0, 0 ); | ||
192 | menu->draw( screen ); | ||
193 | break; | ||
194 | case STATE_HELP: | ||
195 | SDL_FillRect( screen, 0, 0 ); | ||
196 | help->update(); | ||
197 | help->draw( screen ); | ||
198 | break; | ||
199 | case STATE_NEWGAME: | ||
200 | printf( "STATE_NEWGAME\n" ); | ||
201 | currentGame->setReplay( false ); | ||
202 | currentGame->init(); | ||
203 | changeState( STATE_PLAYING ); | ||
204 | break; | ||
205 | 195 | ||
206 | case STATE_REPLAY: | 196 | handleGameState( ); |
207 | printf( "STATE_NEWGAME\n" ); | ||
208 | currentGame->setReplay( true ); | ||
209 | currentGame->init(); | ||
210 | changeState( STATE_PLAYING ); | ||
211 | break; | ||
212 | 197 | ||
213 | case STATE_PLAYING: | 198 | SDL_Flip( screen ); |
214 | case STATE_CRASHING: | ||
215 | currentGame->update( state ); | ||
216 | currentGame->draw( screen ); | ||
217 | break; | ||
218 | |||
219 | case STATE_CRASHED: | ||
220 | currentGame->update( state ); | ||
221 | currentGame->draw( screen ); | ||
222 | |||
223 | // Display Game Over message | ||
224 | break; | ||
225 | |||
226 | case STATE_QUIT: | ||
227 | done = 1; | ||
228 | break; | ||
229 | } | ||
230 | |||
231 | /* Show */ | ||
232 | // if ( state != STATE_CRASHED ) | ||
233 | SDL_Flip( screen ); | ||
234 | // SDL_UpdateRect(screen, 0, 0, 0, 0); | ||
235 | 199 | ||
236 | if ( limitFPS ) | 200 | if ( limitFPS ) |
237 | { | 201 | FPSDelay(); |
238 | /* Slow down polling - limit to x FPS*/ | ||
239 | ftime( &tp ); | ||
240 | end = abs((tp.time%10000)*10000 + tp.millitm); | ||
241 | if ( end-start < (1000/maxFPS) ) | ||
242 | { | ||
243 | // printf( "end - %ld, timetaken for frame = %ld, sleeping for %ld %d\n", end, end-start, (1000/maxFPS)-(end-start), actualFPS ); | ||
244 | if ( (1000/maxFPS)-(end-start) > 500 ) | ||
245 | { | ||
246 | // Should never happen but in case it does sleep for 5 seconds | ||
247 | printf( "WARNING WILL ROBINSON! delay = %ld - start %ld, end %ld\n", (1000/maxFPS)-(end-start), start, end ); | ||
248 | SDL_Delay( 5 ); | ||
249 | } | ||
250 | else | ||
251 | SDL_Delay((1000/maxFPS)-(end-start) ); | ||
252 | } | ||
253 | } | ||
254 | else | 202 | else |
@@ -256,97 +204,124 @@ void SFCave :: mainEventLoop() | |||
256 | 204 | ||
257 | /* Check for events */ | 205 | handleEvents(); |
258 | while ( SDL_PollEvent(&event) ) | 206 | } |
207 | } | ||
208 | |||
209 | |||
210 | void SFCave :: handleGameState() | ||
211 | { | ||
212 | switch( state ) | ||
213 | { | ||
214 | case STATE_MENU: | ||
215 | SDL_FillRect( screen, 0, 0 ); | ||
216 | menu->draw( screen ); | ||
217 | break; | ||
218 | case STATE_HELP: | ||
219 | SDL_FillRect( screen, 0, 0 ); | ||
220 | help->update(); | ||
221 | help->draw( screen ); | ||
222 | break; | ||
223 | case STATE_NEWGAME: | ||
224 | currentGame->setReplay( false ); | ||
225 | currentGame->init(); | ||
226 | changeState( STATE_PLAYING ); | ||
227 | break; | ||
228 | |||
229 | case STATE_REPLAY: | ||
230 | currentGame->setReplay( true ); | ||
231 | currentGame->init(); | ||
232 | changeState( STATE_PLAYING ); | ||
233 | break; | ||
234 | |||
235 | case STATE_PLAYING: | ||
236 | case STATE_CRASHING: | ||
237 | case STATE_CRASHED: | ||
238 | currentGame->update( state ); | ||
239 | currentGame->draw( screen ); | ||
240 | break; | ||
241 | |||
242 | case STATE_QUIT: | ||
243 | finish = true; | ||
244 | break; | ||
245 | } | ||
246 | } | ||
247 | |||
248 | void SFCave :: handleEvents() | ||
249 | { | ||
250 | SDL_Event event; | ||
251 | |||
252 | // Check for events | ||
253 | while ( SDL_PollEvent(&event) ) | ||
254 | { | ||
255 | switch (event.type) | ||
259 | { | 256 | { |
260 | switch (event.type) | 257 | case SDL_KEYDOWN: |
258 | case SDL_KEYUP: | ||
261 | { | 259 | { |
262 | case SDL_KEYDOWN: | 260 | // Escape keypress quits the app |
263 | case SDL_KEYUP: | 261 | if ( event.key.keysym.sym == SDLK_ESCAPE ) |
264 | // Escape keypress quits the app | 262 | { |
265 | if ( event.key.keysym.sym != SDLK_ESCAPE ) | 263 | finish = true; |
264 | break; | ||
265 | } | ||
266 | |||
267 | if ( state == STATE_MENU ) | ||
268 | { | ||
269 | int rc = menu->handleKeys( event.key ); | ||
270 | if ( rc != -1 ) | ||
271 | handleMenuSelect( rc ); | ||
272 | } | ||
273 | else if ( state == STATE_HELP ) | ||
274 | { | ||
275 | help->handleKeys( event.key ); | ||
276 | } | ||
277 | else if ( state == STATE_CRASHED ) | ||
278 | { | ||
279 | if ( event.type == SDL_KEYDOWN ) | ||
266 | { | 280 | { |
267 | // printf( "Key Pressed was %d %s\n", event.key.keysym.sym, SDL_GetKeyName( event.key.keysym.sym ) ); | 281 | if ( event.key.keysym.sym == SDLK_UP || |
268 | 282 | event.key.keysym.sym == SDLK_DOWN || | |
269 | if ( state == STATE_MENU ) | 283 | event.key.keysym.sym == SDLK_SPACE ) |
284 | changeState( STATE_NEWGAME ); | ||
285 | else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == 0 ) | ||
270 | { | 286 | { |
271 | int rc = menu->handleKeys( event.key ); | 287 | changeState( STATE_MENU ); |
272 | if ( rc != -1 ) | 288 | menu->resetToTopMenu(); |
273 | handleMenuSelect( rc ); | ||
274 | } | 289 | } |
275 | else if ( state == STATE_HELP ) | 290 | else if ( event.key.keysym.sym == SDLK_r ) |
276 | { | 291 | { |
277 | help->handleKeys( event.key ); | 292 | changeState( STATE_REPLAY ); |
278 | } | 293 | } |
279 | else if ( state == STATE_CRASHED ) | 294 | else if ( event.key.keysym.sym == SDLK_s ) |
280 | { | 295 | { |
281 | if ( event.type == SDL_KEYDOWN ) | 296 | SoundHandler :: playSound( SND_EXPLOSION ); |
282 | { | ||
283 | if ( event.key.keysym.sym == SDLK_UP || | ||
284 | event.key.keysym.sym == SDLK_DOWN || | ||
285 | event.key.keysym.sym == SDLK_SPACE ) | ||
286 | changeState( STATE_NEWGAME ); | ||
287 | else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == 0 ) | ||
288 | { | ||
289 | changeState( STATE_MENU ); | ||
290 | menu->resetToTopMenu(); | ||
291 | } | ||
292 | else if ( event.key.keysym.sym == SDLK_r ) | ||
293 | { | ||
294 | changeState( STATE_REPLAY ); | ||
295 | } | ||
296 | else if ( event.key.keysym.sym == SDLK_s ) | ||
297 | { | ||
298 | SoundHandler :: playSound( SND_EXPLOSION ); | ||
299 | } | ||
300 | } | ||
301 | } | 297 | } |
302 | else | ||
303 | { | ||
304 | switch ( event.key.keysym.sym ) | ||
305 | { | ||
306 | case SDLK_f: | ||
307 | printf( "showFPS - %d\n", showFps ); | ||
308 | if ( event.type == SDL_KEYDOWN ) | ||
309 | showFps = !showFps; | ||
310 | break; | ||
311 | case SDLK_l: | ||
312 | if ( event.type == SDL_KEYDOWN ) | ||
313 | limitFPS = !limitFPS; | ||
314 | break; | ||
315 | |||
316 | case SDLK_p: | ||
317 | if ( event.type == SDL_KEYDOWN ) | ||
318 | { | ||
319 | maxFPS ++; | ||
320 | printf( "maxFPS - %d\n", maxFPS ); | ||
321 | } | ||
322 | break; | ||
323 | |||
324 | case SDLK_o: | ||
325 | if ( event.type == SDL_KEYDOWN ) | ||
326 | { | ||
327 | maxFPS --; | ||
328 | printf( "maxFPS - %d\n", maxFPS ); | ||
329 | } | ||
330 | break; | ||
331 | |||
332 | case SDLK_n: | ||
333 | currentGame->getTerrain()->offset++; | ||
334 | break; | ||
335 | |||
336 | default: | ||
337 | currentGame->handleKeys( event.key ); | ||
338 | break; | ||
339 | } | ||
340 | } | ||
341 | |||
342 | break; | ||
343 | } | 298 | } |
299 | } | ||
300 | else | ||
301 | { | ||
302 | switch ( event.key.keysym.sym ) | ||
303 | { | ||
304 | case SDLK_f: | ||
305 | if ( event.type == SDL_KEYDOWN ) | ||
306 | showFps = !showFps; | ||
307 | break; | ||
308 | case SDLK_l: | ||
309 | if ( event.type == SDL_KEYDOWN ) | ||
310 | limitFPS = !limitFPS; | ||
311 | break; | ||
344 | 312 | ||
313 | default: | ||
314 | currentGame->handleKeys( event.key ); | ||
315 | break; | ||
316 | } | ||
317 | } | ||
345 | 318 | ||
346 | case SDL_QUIT: | 319 | break; |
347 | done = 1; | ||
348 | break; | ||
349 | default: | ||
350 | break; | ||
351 | } | 320 | } |
321 | |||
322 | case SDL_QUIT: | ||
323 | finish = true; | ||
324 | break; | ||
325 | default: | ||
326 | break; | ||
352 | } | 327 | } |
@@ -367,3 +342,2 @@ void SFCave :: changeState( int s ) | |||
367 | string musicFile = chooseRandomFile( musicPath, musicType ); | 342 | string musicFile = chooseRandomFile( musicPath, musicType ); |
368 | printf("playing music %s\n", musicFile.c_str() ); | ||
369 | SoundHandler :: setMusicVolume( 128 ); | 343 | SoundHandler :: setMusicVolume( 128 ); |
@@ -376,3 +350,3 @@ void SFCave :: changeState( int s ) | |||
376 | // Start the in game music | 350 | // Start the in game music |
377 | string musicFile = SOUND_PATH "ingame.mod"; | 351 | string musicFile = INGAME_MUSIC; |
378 | SoundHandler :: playMusic( musicFile ); | 352 | SoundHandler :: playMusic( musicFile ); |
@@ -410,8 +384,3 @@ void SFCave :: handleMenuSelect( int menuId ) | |||
410 | { | 384 | { |
411 | #ifdef QWS | 385 | string replayFile = getHomeDir() + "/" + currentGame->getGameName() + ".replay"; |
412 | QString replayFile = getenv( "HOME" ); | ||
413 | #else | ||
414 | QString replayFile = "."; | ||
415 | #endif | ||
416 | replayFile += string( "/" ) + currentGame->getGameName() + ".replay"; | ||
417 | 386 | ||
@@ -427,8 +396,3 @@ void SFCave :: handleMenuSelect( int menuId ) | |||
427 | { | 396 | { |
428 | #ifdef QWS | 397 | string replayFile = getHomeDir() + "/" + currentGame->getGameName() + ".replay"; |
429 | QString replayFile = getenv( "HOME" ); | ||
430 | #else | ||
431 | QString replayFile = "."; | ||
432 | #endif | ||
433 | replayFile += string( "/" ) + currentGame->getGameName() + ".replay"; | ||
434 | 398 | ||
@@ -496,4 +460,10 @@ void SFCave :: handleMenuSelect( int menuId ) | |||
496 | 460 | ||
461 | case MENU_DIFFICULTY_CUSTOM: | ||
462 | currentGame->setDifficulty( MENU_DIFFICULTY_CUSTOM ); | ||
463 | saveSetting( "GameDifficulty", "Custom" ); | ||
464 | break; | ||
465 | |||
497 | case MENU_SOUND_ON: | 466 | case MENU_SOUND_ON: |
498 | SoundHandler :: setSoundsOn( true ); | 467 | SoundHandler :: setSoundsOn( true ); |
468 | saveSetting( "SoundOn", "true" ); | ||
499 | break; | 469 | break; |
@@ -502,2 +472,3 @@ void SFCave :: handleMenuSelect( int menuId ) | |||
502 | SoundHandler :: setSoundsOn( false ); | 472 | SoundHandler :: setSoundsOn( false ); |
473 | saveSetting( "SoundOn", "false" ); | ||
503 | break; | 474 | break; |
@@ -506,2 +477,3 @@ void SFCave :: handleMenuSelect( int menuId ) | |||
506 | SoundHandler :: setMusicOn( true ); | 477 | SoundHandler :: setMusicOn( true ); |
478 | saveSetting( "MusicOn", "true" ); | ||
507 | break; | 479 | break; |
@@ -510,4 +482,45 @@ void SFCave :: handleMenuSelect( int menuId ) | |||
510 | SoundHandler :: setMusicOn( false ); | 482 | SoundHandler :: setMusicOn( false ); |
483 | saveSetting( "MusicOn", "false" ); | ||
511 | break; | 484 | break; |
512 | 485 | ||
486 | case MENU_CUSTOM_THRUST: | ||
487 | customPlayerMenuVal = PLAYER_THRUST; | ||
488 | origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); | ||
489 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
490 | break; | ||
491 | case MENU_CUSTOM_GRAVITY: | ||
492 | customPlayerMenuVal = PLAYER_GRAVITY; | ||
493 | origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); | ||
494 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
495 | break; | ||
496 | case MENU_CUSTOM_MAXSPEEDUP: | ||
497 | customPlayerMenuVal = PLAYER_MAX_SPEED_UP; | ||
498 | origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); | ||
499 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
500 | break; | ||
501 | case MENU_CUSTOM_MAXSPEEDDOWN: | ||
502 | customPlayerMenuVal = PLAYER_MAX_SPEED_DOWN; | ||
503 | origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); | ||
504 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
505 | break; | ||
506 | case MENU_CUSTOM_INCREASE: | ||
507 | currentGame->getPlayer()->incValue( customPlayerMenuVal ); | ||
508 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
509 | break; | ||
510 | case MENU_CUSTOM_DECREASE: | ||
511 | currentGame->getPlayer()->decValue( customPlayerMenuVal ); | ||
512 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
513 | break; | ||
514 | case MENU_CUSTOM_SAVE: | ||
515 | { | ||
516 | // save settings | ||
517 | string key = currentGame->getGameName() + "_custom_player_" + currentGame->getPlayer()->getValueTypeString( customPlayerMenuVal ); | ||
518 | saveSetting( key, currentGame->getPlayer()->getValue( customPlayerMenuVal ) ); | ||
519 | |||
520 | break; | ||
521 | } | ||
522 | case MENU_CUSTOM_CANCEL: | ||
523 | currentGame->getPlayer()->setValue( customPlayerMenuVal, origValue ); | ||
524 | break; | ||
525 | |||
513 | default: | 526 | default: |
@@ -535,2 +548,14 @@ void SFCave :: saveSetting( string key, int val ) | |||
535 | 548 | ||
549 | void SFCave :: saveSetting( string key, long val ) | ||
550 | { | ||
551 | Settings cfg( "sfcave-sdl" ); | ||
552 | cfg.writeSetting( key, val ); | ||
553 | } | ||
554 | |||
555 | void SFCave :: saveSetting( string key, double val ) | ||
556 | { | ||
557 | Settings cfg( "sfcave-sdl" ); | ||
558 | cfg.writeSetting( key, val ); | ||
559 | } | ||
560 | |||
536 | string SFCave :: loadSetting( string key, string defaultVal ) | 561 | string SFCave :: loadSetting( string key, string defaultVal ) |
@@ -546 +571,63 @@ string SFCave :: loadSetting( string key, string defaultVal ) | |||
546 | } | 571 | } |
572 | |||
573 | bool SFCave :: loadBoolSetting( string key, bool defaultVal ) | ||
574 | { | ||
575 | bool val = defaultVal; | ||
576 | Settings cfg( "sfcave-sdl" ); | ||
577 | cfg.readSetting( key, val ); | ||
578 | |||
579 | return val; | ||
580 | } | ||
581 | |||
582 | int SFCave :: loadIntSetting( string key, int defaultVal ) | ||
583 | { | ||
584 | int val = defaultVal; | ||
585 | Settings cfg( "sfcave-sdl" ); | ||
586 | cfg.readSetting( key, val ); | ||
587 | |||
588 | return val; | ||
589 | } | ||
590 | |||
591 | double SFCave :: loadDoubleSetting( string key, double defaultVal ) | ||
592 | { | ||
593 | double val = defaultVal; | ||
594 | Settings cfg( "sfcave-sdl" ); | ||
595 | cfg.readSetting( key, val ); | ||
596 | |||
597 | return val; | ||
598 | } | ||
599 | |||
600 | |||
601 | void SFCave :: calcFPS() | ||
602 | { | ||
603 | struct timeb tp; | ||
604 | ftime( &tp ); | ||
605 | start =(tp.time%10000)*10000 + tp.millitm; | ||
606 | if ( start - time1 >= 1000 ) | ||
607 | { | ||
608 | actualFPS = FPS; | ||
609 | FPS = 0; | ||
610 | time1 = start; | ||
611 | } | ||
612 | else | ||
613 | FPS ++; | ||
614 | } | ||
615 | |||
616 | void SFCave :: FPSDelay() | ||
617 | { | ||
618 | struct timeb tp; | ||
619 | // Slow down polling - limit to x FPS | ||
620 | ftime( &tp ); | ||
621 | end = abs((tp.time%10000)*10000 + tp.millitm); | ||
622 | if ( end-start < (1000/maxFPS) ) | ||
623 | { | ||
624 | if ( (1000/maxFPS)-(end-start) > 500 ) | ||
625 | { | ||
626 | // Should never happen but in case it does sleep for 5 seconds | ||
627 | printf( "WARNING WILL ROBINSON! delay = %ld - start %ld, end %ld\n", (1000/maxFPS)-(end-start), start, end ); | ||
628 | SDL_Delay( 5 ); | ||
629 | } | ||
630 | else | ||
631 | SDL_Delay((1000/maxFPS)-(end-start) ); | ||
632 | } | ||
633 | } | ||
diff --git a/noncore/games/sfcave-sdl/sfcave.h b/noncore/games/sfcave-sdl/sfcave.h index 96c2334..c707919 100644 --- a/noncore/games/sfcave-sdl/sfcave.h +++ b/noncore/games/sfcave-sdl/sfcave.h | |||
@@ -17,3 +17,2 @@ public: | |||
17 | 17 | ||
18 | void drawGameScreen(); | ||
19 | void initSDL( int argc, char *argv[] ); | 18 | void initSDL( int argc, char *argv[] ); |
@@ -32,5 +31,12 @@ public: | |||
32 | void saveSetting( string key, int val ); | 31 | void saveSetting( string key, int val ); |
32 | void saveSetting( string key, long val ); | ||
33 | void saveSetting( string key, double val ); | ||
33 | string loadSetting( string key, string defaultVal = "" ); | 34 | string loadSetting( string key, string defaultVal = "" ); |
35 | bool loadBoolSetting( string key, bool defaultVal); | ||
36 | int loadIntSetting( string key, int defaultVal ); | ||
37 | double loadDoubleSetting( string key, double defaultVal ); | ||
38 | |||
34 | private: | 39 | private: |
35 | SDL_Surface *screen; | 40 | SDL_Surface *screen; |
41 | bool setupOK; | ||
36 | 42 | ||
@@ -40,4 +46,2 @@ private: | |||
40 | int state; | 46 | int state; |
41 | int maxFPS; | ||
42 | int actualFPS; | ||
43 | bool showFps; | 47 | bool showFps; |
@@ -45,4 +49,22 @@ private: | |||
45 | string musicType; | 49 | string musicType; |
50 | bool finish; | ||
51 | |||
52 | bool limitFPS; | ||
53 | int maxFPS; | ||
54 | int actualFPS; | ||
55 | int FPS; | ||
56 | long time1; | ||
57 | long start; | ||
58 | long end; | ||
59 | |||
60 | // This is used when the user is setting the custom | ||
61 | // values in the menu | ||
62 | int customPlayerMenuVal; | ||
63 | double origValue; | ||
46 | 64 | ||
47 | void handleMenuSelect( int menuId ); | 65 | void handleMenuSelect( int menuId ); |
66 | void handleGameState(); | ||
67 | void handleEvents(); | ||
68 | void calcFPS(); | ||
69 | void FPSDelay(); | ||
48 | }; | 70 | }; |
diff --git a/noncore/games/sfcave-sdl/sfcave_game.cpp b/noncore/games/sfcave-sdl/sfcave_game.cpp index 72c5ce3..1b00e14 100644 --- a/noncore/games/sfcave-sdl/sfcave_game.cpp +++ b/noncore/games/sfcave-sdl/sfcave_game.cpp | |||
@@ -41,2 +41,15 @@ void SFCaveGame :: init() | |||
41 | break; | 41 | break; |
42 | case MENU_DIFFICULTY_CUSTOM: | ||
43 | { | ||
44 | // Read custom difficulty settings for this game | ||
45 | blockDistance = parent->loadIntSetting( "SFCave_custom_blockdistance", 50 ); | ||
46 | |||
47 | double thrust = parent->loadDoubleSetting( "SFCave_custom_player_thrust", 0.4 ); | ||
48 | double gravity = parent->loadDoubleSetting( "SFCave_custom_player_gravity", 0.6 ); | ||
49 | double maxUp = parent->loadDoubleSetting( "SFCave_custom_player_maxupspeed", 4.0 ); | ||
50 | double maxDown = parent->loadDoubleSetting( "SFCave_custom_player_maxdownspeed", 5.0 ); | ||
51 | player->setMovementInfo( thrust, gravity, maxUp, maxDown ); | ||
52 | |||
53 | break; | ||
54 | } | ||
42 | } | 55 | } |
@@ -70,3 +83,2 @@ void SFCaveGame :: update( int state ) | |||
70 | { | 83 | { |
71 | // printf( "Crashed!\n" ); | ||
72 | parent->changeState( STATE_CRASHING ); | 84 | parent->changeState( STATE_CRASHING ); |
diff --git a/noncore/games/sfcave-sdl/sound.cpp b/noncore/games/sfcave-sdl/sound.cpp index 5fda859..855f2e6 100644 --- a/noncore/games/sfcave-sdl/sound.cpp +++ b/noncore/games/sfcave-sdl/sound.cpp | |||
@@ -33,2 +33,3 @@ bool SoundHandler :: init( ) | |||
33 | soundOn = true; | 33 | soundOn = true; |
34 | musicOn = true; | ||
34 | 35 | ||
@@ -40,4 +41,6 @@ void SoundHandler :: cleanUp() | |||
40 | // Free audio sounds | 41 | // Free audio sounds |
41 | Mix_FreeChunk( sounds[SND_EXPLOSION] ); | 42 | if ( sounds[SND_EXPLOSION] ) |
42 | Mix_FreeChunk( sounds[SND_THRUST] ); | 43 | Mix_FreeChunk( sounds[SND_EXPLOSION] ); |
44 | if ( sounds[SND_THRUST] ) | ||
45 | Mix_FreeChunk( sounds[SND_THRUST] ); | ||
43 | 46 | ||
@@ -54,3 +57,3 @@ int SoundHandler :: playSound( int soundNr, int channel, int nrLoops, int playBe | |||
54 | 57 | ||
55 | if ( soundNr >= NR_SOUNDS ) | 58 | if ( soundNr >= NR_SOUNDS || !sounds[soundNr] ) |
56 | return -1; | 59 | return -1; |
@@ -103,3 +106,3 @@ void SoundHandler :: playMusic( bool fade ) | |||
103 | { | 106 | { |
104 | if ( !soundOn ) | 107 | if ( !musicOn ) |
105 | return; | 108 | return; |
@@ -110,3 +113,3 @@ void SoundHandler :: playMusic( bool fade ) | |||
110 | Mix_RewindMusic(); | 113 | Mix_RewindMusic(); |
111 | 114 | ||
112 | if ( fade ) | 115 | if ( fade ) |
@@ -148,3 +151,3 @@ void SoundHandler :: setMusicOn( bool val ) | |||
148 | musicOn = val; | 151 | musicOn = val; |
149 | 152 | ||
150 | if ( !musicOn ) | 153 | if ( !musicOn ) |
diff --git a/noncore/games/sfcave-sdl/starfield.cpp b/noncore/games/sfcave-sdl/starfield.cpp index c1f2d73..82edfc1 100644 --- a/noncore/games/sfcave-sdl/starfield.cpp +++ b/noncore/games/sfcave-sdl/starfield.cpp | |||
@@ -163,3 +163,3 @@ void StarField :: move( ) | |||
163 | pos_y[i] += vel_y[i]; | 163 | pos_y[i] += vel_y[i]; |
164 | 164 | ||
165 | if (pos_x[i] < 0) | 165 | if (pos_x[i] < 0) |
@@ -223 +223,73 @@ void StarField :: draw( SDL_Surface *screen, int w, int h ) | |||
223 | } | 223 | } |
224 | |||
225 | |||
226 | |||
227 | // Test | ||
228 | #ifdef DEBUG_STARS | ||
229 | SDL_Surface *screen; | ||
230 | StarField *stars; | ||
231 | |||
232 | void go() | ||
233 | { | ||
234 | /* Initialize SDL */ | ||
235 | if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) | ||
236 | { | ||
237 | fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | ||
238 | exit(1); | ||
239 | } | ||
240 | atexit(SDL_Quit); | ||
241 | |||
242 | int videoflags = SDL_SWSURFACE ; | ||
243 | |||
244 | if ( (screen=SDL_SetVideoMode(240, 320,32,videoflags)) == NULL ) | ||
245 | { | ||
246 | fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",240,320,SDL_GetError()); | ||
247 | exit(2); | ||
248 | } | ||
249 | |||
250 | stars = new StarField( false, 200 ); | ||
251 | |||
252 | bool done = false; | ||
253 | while ( !done ) | ||
254 | { | ||
255 | SDL_FillRect( screen, 0, 0 ); | ||
256 | stars->draw( screen ); | ||
257 | stars->move( ); | ||
258 | |||
259 | SDL_Flip( screen ); | ||
260 | |||
261 | SDL_Delay( 10 ); | ||
262 | |||
263 | SDL_Event event; | ||
264 | while ( SDL_PollEvent(&event) ) | ||
265 | { | ||
266 | switch (event.type) | ||
267 | { | ||
268 | case SDL_KEYDOWN: | ||
269 | // Escape keypress quits the app | ||
270 | if ( event.key.keysym.sym != SDLK_ESCAPE ) | ||
271 | { | ||
272 | break; | ||
273 | } | ||
274 | case SDL_QUIT: | ||
275 | done = 1; | ||
276 | break; | ||
277 | default: | ||
278 | break; | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | } | ||
283 | |||
284 | |||
285 | |||
286 | |||
287 | #ifdef __cplusplus | ||
288 | extern "C" | ||
289 | #endif | ||
290 | int main( int argc, char *argv[] ) | ||
291 | { | ||
292 | go(); | ||
293 | } | ||
294 | |||
295 | #endif | ||
diff --git a/noncore/games/sfcave-sdl/terrain.cpp b/noncore/games/sfcave-sdl/terrain.cpp index c001a56..b243f45 100644 --- a/noncore/games/sfcave-sdl/terrain.cpp +++ b/noncore/games/sfcave-sdl/terrain.cpp | |||
@@ -49,2 +49,3 @@ void Terrain :: initTerrain() | |||
49 | SDL_FillRect( terrainSurface, 0, 0 ); | 49 | SDL_FillRect( terrainSurface, 0, 0 ); |
50 | |||
50 | // Draw Terrain into surface | 51 | // Draw Terrain into surface |
@@ -93,3 +94,2 @@ void Terrain :: moveTerrain( int amountToMove ) | |||
93 | 94 | ||
94 | //printf( "offset - %d, speed - %d\n", offset, speed ); | ||
95 | if ( offset >= segSize ) | 95 | if ( offset >= segSize ) |
@@ -197,3 +197,2 @@ void Terrain :: drawTerrain( SDL_Surface *screen ) | |||
197 | dst.h = sHeight; | 197 | dst.h = sHeight; |
198 | //dst.h = maxHeight; | ||
199 | 198 | ||
@@ -206,18 +205,2 @@ void Terrain :: drawTerrain( SDL_Surface *screen ) | |||
206 | stars->draw( screen ); | 205 | stars->draw( screen ); |
207 | |||
208 | //dst.y = sHeight - maxHeight; | ||
209 | //dst2.y = sHeight - maxHeight; | ||
210 | //SDL_BlitSurface(terrainSurface, &dst, screen, &dst2 ); | ||
211 | |||
212 | /* | ||
213 | for ( int i = 0 ; i < MAPSIZE ; ++i ) | ||
214 | { | ||
215 | int x1 = (i*segSize) - (offset*speed); | ||
216 | int x2 = ((i+1)*segSize)-(offset*speed); | ||
217 | if ( x2 >= sWidth ) | ||
218 | x2 = sWidth-1; | ||
219 | aalineRGBA( screen, x1, mapTop[i], x2, mapTop[i+1], 0, 220, 0, 255 ); | ||
220 | aalineRGBA( screen, x1, mapBottom[i], x2, mapBottom[i+1], 0, 220, 0, 255 ); | ||
221 | } | ||
222 | */ | ||
223 | } | 206 | } |
@@ -228,2 +211,3 @@ bool Terrain :: checkCollision( int x, int y, int h ) | |||
228 | return true; | 211 | return true; |
212 | |||
229 | // First get segment that matches x | 213 | // First get segment that matches x |
@@ -249,3 +233,3 @@ void go() | |||
249 | { | 233 | { |
250 | /* Initialize SDL */ | 234 | // Initialize SDL |
251 | if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) | 235 | if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) |
diff --git a/noncore/games/sfcave-sdl/util.cpp b/noncore/games/sfcave-sdl/util.cpp index 86738ad..f73e256 100644 --- a/noncore/games/sfcave-sdl/util.cpp +++ b/noncore/games/sfcave-sdl/util.cpp | |||
@@ -37,3 +37,3 @@ Uint32 getpixel(SDL_Surface *surface, int x, int y) | |||
37 | 37 | ||
38 | const char *chooseRandomFile( string path, string fileType ) | 38 | string chooseRandomFile( string path, string fileType ) |
39 | { | 39 | { |
@@ -52,6 +52,4 @@ const char *chooseRandomFile( string path, string fileType ) | |||
52 | string tmp = file.substr( pos ); | 52 | string tmp = file.substr( pos ); |
53 | printf( "pos = %d, tmp =%s\n", pos, tmp.c_str() ); | ||
54 | if ( tmp.size() > 0 && fileType.find( tmp ) != -1 ) | 53 | if ( tmp.size() > 0 && fileType.find( tmp ) != -1 ) |
55 | { | 54 | { |
56 | printf( "Matching <%s> - %s with <%s>\n", file.substr( pos ).c_str(), file.c_str(), fileType.c_str() ); | ||
57 | files.push_back( file ); | 55 | files.push_back( file ); |
@@ -62,3 +60,16 @@ const char *chooseRandomFile( string path, string fileType ) | |||
62 | closedir( d ); | 60 | closedir( d ); |
63 | return files[nextInt( files.size() )].c_str(); | 61 | return files[nextInt( files.size() )]; |
62 | } | ||
63 | |||
64 | |||
65 | string getHomeDir() | ||
66 | { | ||
67 | string home; | ||
68 | #ifdef QWS | ||
69 | home = getenv( "HOME" ); | ||
70 | #else | ||
71 | home = "."; | ||
72 | #endif | ||
73 | |||
74 | return home; | ||
64 | } | 75 | } |
diff --git a/noncore/games/sfcave-sdl/util.h b/noncore/games/sfcave-sdl/util.h index fe3e9c0..e3aa31a 100644 --- a/noncore/games/sfcave-sdl/util.h +++ b/noncore/games/sfcave-sdl/util.h | |||
@@ -7,4 +7,4 @@ using namespace std; | |||
7 | Uint32 getpixel(SDL_Surface *surface, int x, int y); | 7 | Uint32 getpixel(SDL_Surface *surface, int x, int y); |
8 | const char *chooseRandomFile( string path, string fileType ); | 8 | string chooseRandomFile( string path, string fileType ); |
9 | 9 | string getHomeDir(); | |
10 | #endif | 10 | #endif |