Changeset 680
- Timestamp:
- Feb 21, 2011, 6:11:36 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/configure.ac
r674 r680 126 126 AC_MSG_ERROR([[One of SDL, SDL_Image or SDL_Mixer not found]]) 127 127 else 128 AC_DEFINE(USE_SDL, 1, Define to 1 to use SDL _image)128 AC_DEFINE(USE_SDL, 1, Define to 1 to use SDL) 129 129 fi 130 130 AM_CONDITIONAL(USE_SDL, test "${ac_cv_my_have_sdl}" = "yes") -
trunk/deushax/deushax.cpp
r622 r680 8 8 #endif 9 9 10 #include <cstdio>11 #include <cmath>12 10 #if defined _WIN32 13 11 # include <direct.h> 14 12 #endif 15 13 16 #include <SDL.h>14 #include "core.h" 17 15 18 #include "core.h"19 16 #include "game.h" 17 #include "sdlapp.h" 20 18 #include "sdlinput.h" 21 19 #include "debugfps.h" … … 26 24 27 25 #if defined _WIN32 28 # undef main 26 # undef main /* FIXME: still needed? */ 29 27 #endif 30 31 static float const FPS = 30.0f;32 28 33 29 int main(int argc, char **argv) 34 30 { 35 /* Initialise SDL */ 36 if (SDL_Init(SDL_INIT_VIDEO) < 0) 37 { 38 fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError()); 39 return EXIT_FAILURE; 40 } 31 SdlApp app("Map Test (SDL)", vec2i(640, 480), 30.0f); 41 32 42 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);43 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);44 SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);45 if (!video)46 {47 fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());48 SDL_Quit();49 return EXIT_FAILURE;50 }51 52 SDL_WM_SetCaption("Map Test (SDL)", NULL);53 SDL_ShowCursor(0);54 //SDL_WM_GrabInput(SDL_GRAB_ON);55 56 Ticker::Setup(FPS);57 58 /* Initialise OpenGL */59 Video::Setup(video->w, video->h);60 61 /* Create a game */62 33 #if defined _WIN32 63 34 _chdir(".."); /* Temporary Win32 hack */ … … 74 45 new DebugStats("stats.txt"); 75 46 76 while (!Ticker::Finished()) 77 { 78 /* Tick the game */ 79 Ticker::TickGame(); 80 81 /* Tick the renderer, show the frame and clamp to desired framerate. */ 82 Ticker::TickDraw(); 83 SDL_GL_SwapBuffers(); 84 Ticker::ClampFps(); 85 } 86 87 SDL_Quit(); 47 app.Run(); 88 48 89 49 return EXIT_SUCCESS; -
trunk/monsterz/monsterz.cpp
r622 r680 13 13 #endif 14 14 15 #include <cstdio>16 #include <cmath>17 15 #if defined _WIN32 18 16 # include <direct.h> 19 17 #endif 20 18 21 #include <SDL.h>19 #include "core.h" 22 20 23 #include " core.h"21 #include "sdlapp.h" 24 22 #include "sdlinput.h" 25 23 #include "interface.h" … … 29 27 30 28 #if defined _WIN32 31 # undef main 29 # undef main /* FIXME: still needed? */ 32 30 #endif 33 34 static float const FPS = 60.0f;35 31 36 32 int main(int argc, char **argv) 37 33 { 38 /* Initialise SDL */ 39 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) 40 { 41 fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError()); 42 return EXIT_FAILURE; 43 } 34 SdlApp app("Monsterz", vec2i(640, 480), 60.0f); 44 35 45 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);46 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);47 SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);48 if (!video)49 {50 fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());51 SDL_Quit();52 return EXIT_FAILURE;53 }54 55 SDL_WM_SetCaption("Monsterz", NULL);56 SDL_ShowCursor(0);57 58 /* Initialise everything */59 Ticker::Setup(FPS);60 Video::Setup(video->w, video->h);61 Audio::Setup(2);62 63 /* Create a game */64 36 #if defined _WIN32 65 37 _chdir(".."); /* Temporary Win32 hack */ … … 72 44 //new DebugRecord("monsterz.ogm", FPS); 73 45 74 while (!Ticker::Finished()) 75 { 76 /* Tick the game */ 77 Ticker::TickGame(); 78 79 /* Tick the renderer, show the frame and clamp to desired framerate. */ 80 Ticker::TickDraw(); 81 SDL_GL_SwapBuffers(); 82 Ticker::ClampFps(); 83 } 84 85 SDL_Quit(); 46 app.Run(); 86 47 87 48 return EXIT_SUCCESS; -
trunk/src/Makefile.am
r673 r680 12 12 worldentity.cpp worldentity.h shader.cpp shader.h \ 13 13 \ 14 sdl input.cpp sdlinput.h \14 sdlapp.cpp sdlapp.h sdlinput.cpp sdlinput.h \ 15 15 \ 16 16 debugfps.cpp debugfps.h debugsphere.cpp debugsphere.h \ -
trunk/src/audio.cpp
r254 r680 15 15 #include <cmath> 16 16 17 #include <SDL_mixer.h> 17 #if defined USE_SDL 18 # include <SDL.h> 19 # include <SDL_mixer.h> 20 #endif 18 21 19 22 #include "core.h" … … 25 28 void Audio::Setup(int channels) 26 29 { 30 #if defined USE_SDL 27 31 Mix_OpenAudio(22050, AUDIO_S16, channels, 1024); 32 #endif 28 33 } 29 34 -
trunk/src/input.cpp
r664 r680 13 13 #endif 14 14 15 #include <SDL.h>16 17 15 #include <cstdio> 18 16 #include <cstdlib> 19 17 #include <cmath> 18 19 #if defined USE_SDL 20 # include <SDL.h> 21 #endif 20 22 21 23 #include "core.h" … … 57 59 { 58 60 float invsqrt2 = sqrtf(0.5f); 59 vec2 f;61 vec2 ret; 60 62 63 #if defined USE_SDL 61 64 /* Simulate a joystick using the keyboard. This SDL call is free. */ 62 65 Uint8 *keystate = SDL_GetKeyState(NULL); 63 66 int left = keystate[SDLK_d] - (keystate[SDLK_a] | keystate[SDLK_q]); 64 67 int up = (keystate[SDLK_w] | keystate[SDLK_z]) - keystate[SDLK_s] ; 65 f.x += left;66 f.y += up;68 ret.x += left; 69 ret.y += up; 67 70 if (left && up) 68 f = f * invsqrt2; 71 ret = ret * invsqrt2; 72 #else 73 ret = 0; 74 #endif 69 75 70 return f;76 return ret; 71 77 } 72 78 -
trunk/src/lolgl.h
r674 r680 18 18 19 19 #define GL_GLEXT_PROTOTYPES 20 21 /* Defines for exotic platforms (until they get their config.h) */ 22 #ifdef ANDROID_NDK 23 # define HAVE_GLES_1X 24 #endif 20 25 21 26 /* Only define one GL platform */ -
trunk/src/sample.cpp
r658 r680 14 14 15 15 #include <cstdlib> 16 #include <cstdio> 16 17 #include <cmath> 17 18 18 #include <SDL.h> 19 #include <SDL_mixer.h> 19 #if defined USE_SDL 20 # include <SDL.h> 21 # include <SDL_mixer.h> 22 #endif 20 23 21 24 #include "core.h" … … 31 34 private: 32 35 char *name, *path; 36 #if defined USE_SDL 33 37 Mix_Chunk *chunk; 38 #endif 34 39 }; 35 40 … … 45 50 sprintf(data->name, "<sample> %s", path); 46 51 52 #if defined USE_SDL 47 53 data->chunk = Mix_LoadWAV(path); 48 54 if (!data->chunk) … … 54 60 exit(1); 55 61 } 62 #endif 56 63 } 57 64 58 65 Sample::~Sample() 59 66 { 67 #if defined USE_SDL 60 68 Mix_FreeChunk(data->chunk); 69 #endif 61 70 free(data->name); 62 71 delete data; … … 75 84 void Sample::Play() 76 85 { 86 #if defined USE_SDL 77 87 Mix_PlayChannel(-1, data->chunk, 0); 88 #endif 78 89 } 79 90 -
trunk/src/sdlapp.cpp
r675 r680 1 1 // 2 // Monsterz2 // Lol Engine 3 3 // 4 // Copyright: (c) 20 05-2011 Sam Hocevar <sam@hocevar.net>4 // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> 5 5 // This program is free software; you can redistribute it and/or 6 6 // modify it under the terms of the Do What The Fuck You Want To … … 13 13 #endif 14 14 15 #include <cstdio> 16 #include <cmath> 17 #if defined _WIN32 18 # include <direct.h> 15 #if defined USE_SDL 16 # include <SDL.h> 19 17 #endif 20 18 21 #include <SDL.h> 19 #include "core.h" 20 #include "sdlapp.h" 22 21 23 #include "core.h" 24 #include "sdlinput.h" 25 #include "interface.h" 22 /* 23 * SDL App implementation class 24 */ 26 25 27 #include "debugfps.h" 28 #include "debugrecord.h" 26 class SdlAppData 27 { 28 friend class SdlApp; 29 29 30 #if defined _WIN32 31 # undef main 32 #endif 30 private: 31 int unused; 32 }; 33 33 34 static float const FPS = 60.0f; 34 /* 35 * Public SdlApp class 36 */ 35 37 36 int main(int argc, char **argv) 38 SdlApp::SdlApp(char const *title, vec2i res, float fps) : 39 data(new SdlAppData()) 37 40 { 41 #if defined USE_SDL 38 42 /* Initialise SDL */ 39 43 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) 40 44 { 41 45 fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError()); 42 return EXIT_FAILURE;46 exit(EXIT_FAILURE); 43 47 } 44 48 45 49 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 46 50 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); 47 SDL_Surface *video = SDL_SetVideoMode( 640, 480, 0, SDL_OPENGL);51 SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 0, SDL_OPENGL); 48 52 if (!video) 49 53 { 50 54 fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError()); 51 55 SDL_Quit(); 52 return EXIT_FAILURE;56 exit(EXIT_FAILURE); 53 57 } 54 58 55 SDL_WM_SetCaption( "Monsterz", NULL);59 SDL_WM_SetCaption(title, NULL); 56 60 SDL_ShowCursor(0); 57 61 58 62 /* Initialise everything */ 59 Ticker::Setup( FPS);63 Ticker::Setup(fps); 60 64 Video::Setup(video->w, video->h); 61 65 Audio::Setup(2); 66 #endif 67 } 62 68 63 /* Create a game */ 64 #if defined _WIN32 65 _chdir(".."); /* Temporary Win32 hack */ 66 #endif 67 68 /* Register an input driver and some debug stuff */ 69 new SdlInput(); 70 new Interface(); 71 new DebugFps(20, 20); 72 //new DebugRecord("monsterz.ogm", FPS); 73 69 void SdlApp::Run() 70 { 74 71 while (!Ticker::Finished()) 75 72 { … … 79 76 /* Tick the renderer, show the frame and clamp to desired framerate. */ 80 77 Ticker::TickDraw(); 78 #if defined USE_SDL 81 79 SDL_GL_SwapBuffers(); 80 #endif 82 81 Ticker::ClampFps(); 83 82 } 84 85 SDL_Quit();86 87 return EXIT_SUCCESS;88 83 } 89 84 85 SdlApp::~SdlApp() 86 { 87 #if defined USE_SDL 88 SDL_Quit(); 89 #endif 90 free(data); 91 } 92 -
trunk/src/sdlapp.h
r675 r680 9 9 // 10 10 11 #if defined HAVE_CONFIG_H 12 # include "config.h" 13 #endif 11 // 12 // The SdlApp class 13 // ---------------- 14 // 14 15 15 #include <cmath> 16 #if !defined __DH_SDLAPP_H__ 17 #define __DH_SDLAPP_H__ 16 18 17 #include <SDL_mixer.h>19 #include "matrix.h" 18 20 19 #include "core.h" 21 class SdlAppData; 20 22 21 /* 22 * Public Audio class 23 */ 23 class SdlApp 24 { 25 public: 26 SdlApp(char const *title, vec2i res, float fps); 27 virtual ~SdlApp(); 24 28 25 void Audio::Setup(int channels) 26 { 27 Mix_OpenAudio(22050, AUDIO_S16, channels, 1024); 28 } 29 void Run(); 29 30 31 private: 32 SdlAppData *data; 33 }; 34 35 #endif // __DH_SDLAPP_H__ 36 -
trunk/src/tileset.cpp
r673 r680 14 14 15 15 #include <cstdlib> 16 #include <cstdio> 16 17 #include <cmath> 17 18 … … 21 22 #endif 22 23 23 #include <SDL.h> 24 #include <SDL_image.h> 24 #if defined USE_SDL 25 # include <SDL.h> 26 # include <SDL_image.h> 27 #endif 25 28 26 29 #include "core.h" … … 41 44 float dilate, tx, ty; 42 45 46 #if defined USE_SDL 43 47 SDL_Surface *img; 48 #endif 44 49 GLuint texture; 45 50 }; … … 57 62 58 63 data->tiles = NULL; 64 #if defined USE_SDL 59 65 data->img = NULL; 66 #endif 60 67 data->texture = 0; 61 68 69 #if defined USE_SDL 62 70 for (char const *name = path; *name; name++) 63 71 if ((data->img = IMG_Load(name))) … … 87 95 } 88 96 97 data->tx = (float)data->size.x / PotUp(data->img->w); 98 data->ty = (float)data->size.y / PotUp(data->img->h); 99 #endif 100 89 101 data->dilate = dilate; 90 102 data->ntiles = data->count.i * data->count.j; 91 data->tx = (float)data->size.x / PotUp(data->img->w);92 data->ty = (float)data->size.y / PotUp(data->img->h);93 103 94 104 drawgroup = DRAWGROUP_BEFORE; … … 106 116 Entity::TickDraw(deltams); 107 117 118 #if defined USE_SDL 108 119 if (IsDestroying()) 109 120 { … … 146 157 data->img = NULL; 147 158 } 159 #endif 148 160 } 149 161 … … 165 177 void TileSet::Bind() 166 178 { 179 #if defined USE_SDL 167 180 if (!data->img) 168 181 glBindTexture(GL_TEXTURE_2D, data->texture); 182 #endif 169 183 } 170 184 … … 180 194 int dz = o ? data->size.y : 0; 181 195 196 #if defined USE_SDL 182 197 if (!data->img) 183 198 { … … 221 236 } 222 237 else 238 #endif 223 239 { 224 240 memset(vertex, 0, 3 * sizeof(float)); -
trunk/win32/deushax.vcxproj
r673 r680 37 37 <ClInclude Include="..\src\sampler.h" /> 38 38 <ClInclude Include="..\src\scene.h" /> 39 <ClInclude Include="..\src\sdlapp.h" /> 39 40 <ClInclude Include="..\src\sdlinput.h" /> 40 41 <ClInclude Include="..\src\shader.h" /> … … 71 72 <ClCompile Include="..\src\sampler.cpp" /> 72 73 <ClCompile Include="..\src\scene.cpp" /> 74 <ClCompile Include="..\src\sdlapp.cpp" /> 73 75 <ClCompile Include="..\src\sdlinput.cpp" /> 74 76 <ClCompile Include="..\src\shader.cpp" /> -
trunk/win32/deushax.vcxproj.filters
r673 r680 67 67 <Filter>lolengine</Filter> 68 68 </ClInclude> 69 <ClInclude Include="..\src\sdlapp.h"> 70 <Filter>lolengine</Filter> 71 </ClInclude> 69 72 <ClInclude Include="..\src\sdlinput.h"> 70 73 <Filter>lolengine</Filter> … … 156 159 </ClCompile> 157 160 <ClCompile Include="..\src\scene.cpp"> 161 <Filter>lolengine</Filter> 162 </ClCompile> 163 <ClCompile Include="..\src\sdlapp.cpp"> 158 164 <Filter>lolengine</Filter> 159 165 </ClCompile> -
trunk/win32/editor.vcxproj
r673 r680 37 37 <ClInclude Include="..\src\sampler.h" /> 38 38 <ClInclude Include="..\src\scene.h" /> 39 <ClInclude Include="..\src\sdlapp.h" /> 39 40 <ClInclude Include="..\src\sdlinput.h" /> 40 41 <ClInclude Include="..\src\shader.h" /> … … 71 72 <ClCompile Include="..\src\sampler.cpp" /> 72 73 <ClCompile Include="..\src\scene.cpp" /> 74 <ClCompile Include="..\src\sdlapp.cpp" /> 73 75 <ClCompile Include="..\src\sdlinput.cpp" /> 74 76 <ClCompile Include="..\src\shader.cpp" /> -
trunk/win32/editor.vcxproj.filters
r673 r680 67 67 <Filter>lolengine</Filter> 68 68 </ClInclude> 69 <ClInclude Include="..\src\sdlapp.h"> 70 <Filter>lolengine</Filter> 71 </ClInclude> 69 72 <ClInclude Include="..\src\sdlinput.h"> 70 73 <Filter>lolengine</Filter> … … 158 161 <Filter>lolengine</Filter> 159 162 </ClCompile> 163 <ClCompile Include="..\src\sdlapp.cpp"> 164 <Filter>lolengine</Filter> 165 </ClCompile> 160 166 <ClCompile Include="..\src\sdlinput.cpp"> 161 167 <Filter>lolengine</Filter> -
trunk/win32/monsterz.vcxproj
r673 r680 42 42 <ClInclude Include="..\src\sampler.h" /> 43 43 <ClInclude Include="..\src\scene.h" /> 44 <ClInclude Include="..\src\sdlapp.h" /> 44 45 <ClInclude Include="..\src\sdlinput.h" /> 45 46 <ClInclude Include="..\src\shader.h" /> … … 80 81 <ClCompile Include="..\src\sampler.cpp" /> 81 82 <ClCompile Include="..\src\scene.cpp" /> 83 <ClCompile Include="..\src\sdlapp.cpp" /> 82 84 <ClCompile Include="..\src\sdlinput.cpp" /> 83 85 <ClCompile Include="..\src\shader.cpp" /> -
trunk/win32/monsterz.vcxproj.filters
r673 r680 67 67 <Filter>lolengine</Filter> 68 68 </ClInclude> 69 <ClInclude Include="..\src\sdlapp.h"> 70 <Filter>lolengine</Filter> 71 </ClInclude> 69 72 <ClInclude Include="..\src\sdlinput.h"> 70 73 <Filter>lolengine</Filter> … … 161 164 </ClCompile> 162 165 <ClCompile Include="..\src\scene.cpp"> 166 <Filter>lolengine</Filter> 167 </ClCompile> 168 <ClCompile Include="..\src\sdlapp.cpp"> 163 169 <Filter>lolengine</Filter> 164 170 </ClCompile>
Note: See TracChangeset
for help on using the changeset viewer.