]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameInitDispose.cpp
Building default player after PersonTypes are loaded to avoid segfault
[lugaru.git] / Source / GameInitDispose.cpp
index b082ef10676417feb07b91ddf202ac5a5ddd15d8..a1e96031da4ccf4d13245e7a971ca721384b8097 100644 (file)
@@ -1,6 +1,6 @@
 /*
 Copyright (C) 2003, 2010 - Wolfire Games
-Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
+Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
 
 This file is part of Lugaru.
 
@@ -40,8 +40,6 @@ extern float realtexdetail;
 extern float volume;
 extern int detail;
 extern bool cellophane;
-extern GLubyte bloodText[512 * 512 * 3];
-extern GLubyte wolfbloodText[512 * 512 * 3];
 extern bool ismotionblur;
 extern bool trilinear;
 extern bool musictoggle;
@@ -179,16 +177,19 @@ void Game::LoadingScreen()
     AbsoluteTime currTime = UpTime();
     double deltaTime = (float)AbsoluteDeltaToDuration(currTime, frametime);
 
-    if (0 > deltaTime) // if negative microseconds
+    if (0 > deltaTime) // if negative microseconds
         deltaTime /= -1000000.0;
-    else // else milliseconds
+    } else { // else milliseconds
         deltaTime /= 1000.0;
+    }
 
     multiplier = deltaTime;
-    if (multiplier < .001)
+    if (multiplier < .001) {
         multiplier = .001;
-    if (multiplier > 10)
+    }
+    if (multiplier > 10) {
         multiplier = 10;
+    }
     if (multiplier > .05) {
         frametime = currTime; // reset for next time interval
 
@@ -200,8 +201,9 @@ void Game::LoadingScreen()
         loadtime += multiplier * 4;
 
         loadprogress = loadtime;
-        if (loadprogress > 100)
+        if (loadprogress > 100) {
             loadprogress = 100;
+        }
 
         //Background
 
@@ -341,13 +343,16 @@ void Game::LoadingScreen()
         //Text
 
         if (flashamount > 0) {
-            if (flashamount > 1)
+            if (flashamount > 1) {
                 flashamount = 1;
-            if (flashdelay <= 0)
+            }
+            if (flashdelay <= 0) {
                 flashamount -= multiplier;
+            }
             flashdelay--;
-            if (flashamount < 0)
+            if (flashamount < 0) {
                 flashamount = 0;
+            }
             glDisable(GL_DEPTH_TEST);
             glDisable(GL_CULL_FACE);
             glDisable(GL_LIGHTING);
@@ -556,8 +561,9 @@ void Game::InitGame()
     OPENAL_SetSFXMasterVolume((int)(volume * 255));
     loadAllSounds();
 
-    if (musictoggle)
+    if (musictoggle) {
         emit_stream_np(stream_menutheme);
+    }
 
     cursortexture.load("Textures/Cursor.png", 0);
 
@@ -566,8 +572,9 @@ void Game::InitGame()
     Maparrowtexture.load("Textures/MapArrow.png", 0);
 
     temptexdetail = texdetail;
-    if (texdetail > 2)
+    if (texdetail > 2) {
         texdetail = 2;
+    }
     Mainmenuitems[0].load("Textures/Lugaru.png", 0);
     Mainmenuitems[1].load("Textures/NewGame.png", 0);
     Mainmenuitems[2].load("Textures/Options.png", 0);
@@ -593,14 +600,19 @@ void Game::InitGame()
     Menu::Load();
 
     Animation::loadAll();
+
+    PersonType::Load();
+
+    Person::players.emplace_back(new Person());
 }
 
 void Game::LoadScreenTexture()
 {
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
-    if (!Game::screentexture)
+    if (!Game::screentexture) {
         glGenTextures(1, &Game::screentexture);
+    }
     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 
     glEnable(GL_TEXTURE_2D);
@@ -728,8 +740,8 @@ void Game::LoadStuff()
     iris.Scale(.03, .03, .03);
     iris.CalculateNormals(0);
 
-    LoadSave("Textures/BloodFur.png", &bloodText[0]);
-    LoadSave("Textures/WolfBloodFur.png", &wolfbloodText[0]);
+    LoadSave("Textures/WolfBloodFur.png", &PersonType::types[wolftype].bloodText[0]);
+    LoadSave("Textures/BloodFur.png", &PersonType::types[rabbittype].bloodText[0]);
 
     oldenvironment = -4;