aboutsummaryrefslogtreecommitdiff
path: root/src/GameInitDispose.cpp
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-08-12 15:52:45 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-08-12 15:52:45 +0700
commit7cdccc2f37d1741572606ec74866da10aef98ecd (patch)
treec23a4d9986f6a72348b87d8d36773e7307870545 /src/GameInitDispose.cpp
parent43e50110f6c33ab6ef42c6175a66918d47087c89 (diff)
downloadblackshades-7cdccc2f37d1741572606ec74866da10aef98ecd.tar.gz
Extern C initGl and remove FULLSCREEN compile flag
Diffstat (limited to 'src/GameInitDispose.cpp')
-rw-r--r--src/GameInitDispose.cpp134
1 files changed, 47 insertions, 87 deletions
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);