diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Game.cc | 2 | ||||
-rw-r--r-- | src/Game.h | 2 | ||||
-rw-r--r-- | src/GameInitDispose.cpp | 134 | ||||
-rw-r--r-- | src/Support.cpp | 4 |
4 files changed, 49 insertions, 93 deletions
diff --git a/src/Game.cc b/src/Game.cc index be16a7a..34e2222 100644 --- a/src/Game.cc +++ b/src/Game.cc @@ -22,7 +22,7 @@ void run() { Game game {}; - game.InitGL(); + initGl(&game); game.InitGame(); game.EventLoop(); } diff --git a/src/Game.h b/src/Game.h index a1fc4ae..bc60a3c 100644 --- a/src/Game.h +++ b/src/Game.h @@ -190,7 +190,6 @@ public: // GL functions GLvoid ReSizeGLScene(float fov, float near); int DrawGLScene(); - int InitGL(); void LoadingScreen(float percent); // Game functions @@ -204,5 +203,6 @@ public: extern "C" { void run(); + int initGl(Game*); } #endif // BLACKSHADES_GAME_H diff --git a/src/GameInitDispose.cpp b/src/GameInitDispose.cpp index b9bdab7..35c6ba3 100644 --- a/src/GameInitDispose.cpp +++ b/src/GameInitDispose.cpp @@ -2018,118 +2018,98 @@ void Game::InitGame() losedelay=1; } -int Game::InitGL(void) +int initGl(Game* game) { - //Config - if(!initialized){ - //Default config in case config is not found - screenwidth = 640; - screenheight = 480; - usermousesensitivity=.7; - debug=0; - vblsync=1; - blood = 1; - blurness = 0; - mainmenuness=1; - customlevels=0; - musictoggle=1; - - //If no config, write one - ifstream ipstream("config.txt"); - if(!ipstream) { + // Config + if (!game->initialized) { + ifstream ipstream {"config.txt"}; + // If no config, write one + if (!ipstream) { ofstream opstream("config.txt"); opstream << "Screenwidth:\n"; - opstream << screenwidth; + opstream << (game->screenwidth = 640); opstream << "\nScreenheight:\n"; - opstream << screenheight; + opstream << (game->screenheight = 480); opstream << "\nMouse sensitivity:\n"; - opstream << usermousesensitivity; + opstream << (game->usermousesensitivity = 0.7f); opstream << "\nShow fps and other info:\n"; - opstream << debug; + opstream << (game->debug = false); opstream << "\nVBL sync:\n"; - opstream << vblsync; + opstream << (game->vblsync = true); opstream << "\nBlood:\n"; - opstream << blood; + opstream << (blood = true); opstream << "\nBlur:\n"; - opstream << blurness; + opstream << (game->blurness = false); opstream << "\nMain Menu:\n"; - opstream << mainmenuness; + opstream << (game->mainmenuness = true); opstream << "\nCustom levels:\n"; - opstream << customlevels; + opstream << (game->customlevels = false); opstream << "\nMusic:\n"; - opstream << musictoggle; + opstream << (game->musictoggle = true); opstream << "\azerty keyboard:\n"; - opstream << azertykeyboard; + opstream << (game->azertykeyboard = false) << endl; opstream.close(); - } - - //Read config - if(ipstream){ + } else { ipstream.ignore(256,'\n'); - ipstream >> screenwidth; + ipstream >> game->screenwidth; ipstream.ignore(256,'\n'); ipstream.ignore(256,'\n'); - ipstream >> screenheight; + ipstream >> game->screenheight; ipstream.ignore(256,'\n'); ipstream.ignore(256,'\n'); - ipstream >> usermousesensitivity; + ipstream >> game->usermousesensitivity; ipstream.ignore(256,'\n'); ipstream.ignore(256,'\n'); - ipstream >> debug; + ipstream >> game->debug; ipstream.ignore(256,'\n'); ipstream.ignore(256,'\n'); - ipstream >> vblsync; + ipstream >> game->vblsync; ipstream.ignore(256,'\n'); ipstream.ignore(256,'\n'); ipstream >> blood; ipstream.ignore(256,'\n'); ipstream.ignore(256,'\n'); - ipstream >> blurness; + ipstream >> game->blurness; ipstream.ignore(256,'\n'); ipstream.ignore(256,'\n'); - ipstream >> mainmenuness; + ipstream >> game->mainmenuness; ipstream.ignore(256,'\n'); ipstream.ignore(256,'\n'); - ipstream >> customlevels; + ipstream >> game->customlevels; ipstream.ignore(256,'\n'); ipstream.ignore(256,'\n'); - ipstream >> musictoggle; + ipstream >> game->musictoggle; ipstream.ignore(256,'\n'); ipstream.ignore(256,'\n'); - ipstream >> azertykeyboard; + ipstream >> game->azertykeyboard; ipstream.close(); } // TODO: Read high score - ifstream ipstream2("highscore.txt"); - if(!ipstream2) { - highscore = 0; - beatgame = 0; + ifstream ipstream2 {"highscore.txt"}; + if (!ipstream2) { ofstream opstream("highscore.txt"); - opstream << highscore; - opstream << "\n"; - opstream << beatgame; + opstream << (game->highscore = 0) << endl; + opstream << (game->beatgame = 0) << endl; opstream.close(); - } - if(ipstream2){ - ipstream2 >> highscore; + } else { + ipstream2 >> game->highscore; ipstream.ignore(256,'\n'); - ipstream2 >> beatgame; + ipstream2 >> game->beatgame; ipstream2.close(); } - sps=40; - maxfps=90; - disttest=1; - cubetest=1; + game->sps = 40; + game->maxfps = 90; + game->disttest = true; + game->cubetest = true; } - //Setup screen + // Setup screen if (SDL_Init(SDL_INIT_VIDEO) == -1) { fprintf(stderr, "SDL Init Video failed: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } - atexit(SDL_Quit); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); @@ -2138,37 +2118,17 @@ int Game::InitGL(void) SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if(screenwidth<640||screenheight<480) { -#ifdef FULLSCREEN - if (SDL_SetVideoMode(640, 480, 0, SDL_OPENGL | SDL_FULLSCREEN) == NULL) { -#else - if (SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL) { -#endif - fprintf(stderr, "(OpenGL) SDL SetVideoMode failed: %s\n", SDL_GetError()); - exit(EXIT_FAILURE); - } - } else { -#ifdef FULLSCREEN - if (SDL_SetVideoMode(screenwidth, screenheight, 0, SDL_OPENGL | SDL_FULLSCREEN) == NULL) { -#else - if (SDL_SetVideoMode(screenwidth, screenheight, 0, SDL_OPENGL) == NULL) { -#endif - fprintf(stderr, "(OpenGL) SDL SetVideoMode failed: %s\n", SDL_GetError()); - exit(EXIT_FAILURE); - } + if (SDL_SetVideoMode(game->screenwidth, game->screenheight, + 0, SDL_OPENGL) == NULL) { + fprintf(stderr, "(OpenGL) SDL SetVideoMode failed: %s\n", + SDL_GetError()); + exit(EXIT_FAILURE); } - SDL_WM_SetCaption("Black Shades", "Black Shades"); - SDL_EnableUNICODE(1); /* toggle it to ON */ -#ifdef FULLSCREEN - SDL_WM_GrabInput(SDL_GRAB_ON); - SDL_ShowCursor(0); -#endif - - text.LoadFontTexture(":Data:Textures:Font.png"); - text.BuildFont(); + game->text.LoadFontTexture(":Data:Textures:Font.png"); + game->text.BuildFont(); glAlphaFunc(GL_GREATER, 0.01); glDepthFunc(GL_LESS); glPolygonOffset(-8,0); diff --git a/src/Support.cpp b/src/Support.cpp index a068360..33794d9 100644 --- a/src/Support.cpp +++ b/src/Support.cpp @@ -58,10 +58,6 @@ int Button(void) void MoveMouse(int xcoord, int ycoord, Point *mouseloc) { /* TODO: mouse warp is annoying when we can just grab the mouse */ -#ifdef FULLSCREEN - SDL_WarpMouse(xcoord, ycoord); - SDL_PumpEvents(); -#endif GetMouse(mouseloc); } |