]> git.jsancho.org Git - lugaru.git/commitdiff
Switched all data access to the new methods
authorCôme Chilliet <come@chilliet.eu>
Thu, 1 Dec 2016 17:40:13 +0000 (00:40 +0700)
committerCôme Chilliet <come@chilliet.eu>
Thu, 1 Dec 2016 17:40:13 +0000 (00:40 +0700)
Removed the ugly define on fopen
Still missing:
- Creating the folders we want to write in
- Finding the path of the binary and use it as base on Linux, with locateCorrectFile

20 files changed:
Source/Account.cpp
Source/ConsoleCmds.cpp
Source/Dialog.cpp
Source/Game.h
Source/GameInitDispose.cpp
Source/GameTick.cpp
Source/ImageIO.cpp
Source/MacCompatibility.cpp
Source/MacCompatibility.h
Source/Models.cpp
Source/Objects.cpp
Source/Settings.cpp
Source/Skeleton.cpp
Source/Skeleton.h
Source/Sounds.cpp
Source/Terrain.cpp
Source/Texture.cpp
Source/WinDefs.cpp
Source/WinDefs.h
Source/openal_wrapper.cpp

index 11483f89c2eb39ec7a40bd2a503d3cdfe66c786f..f650330a0f87bcbb3d9c456eb03488bf3fca5d88 100644 (file)
@@ -23,6 +23,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include <fstream>
 #include "MacCompatibility.h"
 #include "string.h"
+#include <iostream>
 
 using namespace std;
 
@@ -115,7 +116,7 @@ Account* Account::loadFile(string filename)
     int numaccounts;
     int accountactive;
 
-    tfile = fopen(ConvertFileName(filename.c_str()), "rb" );
+    tfile = fopen(filename.c_str(), "rb" );
 
     if (tfile) {
         funpackf(tfile, "Bi", &numaccounts);
@@ -185,7 +186,7 @@ Account* Account::loadFile(string filename)
         fclose(tfile);
         return get(accountactive);
     } else {
-        printf("filenotfound\n");
+        perror(("Couldn't load users from " + filename).c_str());
         return NULL;
     }
 }
@@ -194,7 +195,7 @@ void Account::saveFile(string filename, Account* accountactive)
 {
     FILE *tfile;
 
-    tfile = fopen(ConvertFileName(filename.c_str(), "wb"), "wb" );
+    tfile = fopen(filename.c_str(), "wb" );
     if (tfile) {
         printf("writing %d accounts :\n", getNbAccounts());
         fpackf(tfile, "Bi", getNbAccounts());
@@ -243,6 +244,8 @@ void Account::saveFile(string filename, Account* accountactive)
         }
 
         fclose(tfile);
+    } else {
+        perror(("Couldn't save users in " + filename).c_str());
     }
 }
 
index a4cbfb52865cf050d5eb482ede321075fee7b721..8fc1da892982abcb2889c44d0089e512c86949c6 100644 (file)
@@ -21,6 +21,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include "ConsoleCmds.h"
 #include "Game.h"
 #include "Dialog.h"
+#include "Utils/Folders.h"
 
 const char *cmd_names[cmd_count] = {
 #define DECLARE_COMMAND(cmd) #cmd,
@@ -142,7 +143,7 @@ static void set_noclothes(int pnum, const char *args)
 static void set_clothes(int pnum, const char *args)
 {
     char buf[64];
-    snprintf(buf, 63, ":Data:Textures:%s.png", args);
+    snprintf(buf, 63, "Textures/%s.png", args);
 
     int id = Person::players[pnum]->numclothes;
     strcpy(Person::players[pnum]->clothes[id], buf);
@@ -173,13 +174,12 @@ void ch_map(const char *args)
 
 void ch_save(const char *args)
 {
-    char buf[64];
-    snprintf(buf, 63, ":Data:Maps:%s", args);
+    std::string map_path = Folders::getUserDataPath() + "/Maps/" + args;
 
     int mapvers = 12;
 
     FILE *tfile;
-    tfile = fopen( ConvertFileName(buf), "wb" );
+    tfile = fopen( map_path.c_str(), "wb" );
     fpackf(tfile, "Bi", mapvers);
     fpackf(tfile, "Bi", maptype);
     fpackf(tfile, "Bi", hostile);
@@ -300,7 +300,7 @@ void ch_save(const char *args)
 
 void ch_cellar(const char *args)
 {
-    Person::players[0]->skeleton.drawmodel.textureptr.load(":Data:Textures:Furdarko.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
+    Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Furdarko.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
 }
 
 void ch_tint(const char *args)
@@ -443,13 +443,13 @@ void ch_cellophane(const char *args)
 void ch_funnybunny(const char *args)
 {
     Person::players[0]->skeleton.id = 0;
-    Person::players[0]->skeleton.Load(":Data:Skeleton:Basic Figure", ":Data:Skeleton:Basic Figurelow",
-                            ":Data:Skeleton:Rabbitbelt", ":Data:Models:Body.solid",
-                            ":Data:Models:Body2.solid", ":Data:Models:Body3.solid",
-                            ":Data:Models:Body4.solid", ":Data:Models:Body5.solid",
-                            ":Data:Models:Body6.solid", ":Data:Models:Body7.solid",
-                            ":Data:Models:Bodylow.solid", ":Data:Models:Belt.solid", 1);
-    Person::players[0]->skeleton.drawmodel.textureptr.load(":Data:Textures:fur3.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
+    Person::players[0]->skeleton.Load("Skeleton/Basic Figure", "Skeleton/Basic Figurelow",
+                            "Skeleton/Rabbitbelt", "Models/Body.solid",
+                            "Models/Body2.solid", "Models/Body3.solid",
+                            "Models/Body4.solid", "Models/Body5.solid",
+                            "Models/Body6.solid", "Models/Body7.solid",
+                            "Models/Bodylow.solid", "Models/Belt.solid", 1);
+    Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/fur3.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
     Person::players[0]->creature = rabbittype;
     Person::players[0]->scale = .2;
     Person::players[0]->headless = 0;
@@ -460,13 +460,13 @@ void ch_funnybunny(const char *args)
 void ch_wolfie(const char *args)
 {
     Person::players[0]->skeleton.id = 0;
-    Person::players[0]->skeleton.Load(":Data:Skeleton:Basic Figure Wolf", ":Data:Skeleton:Basic Figure Wolf Low",
-                            ":Data:Skeleton:Rabbitbelt", ":Data:Models:Wolf.solid",
-                            ":Data:Models:Wolf2.solid", ":Data:Models:Wolf3.solid",
-                            ":Data:Models:Wolf4.solid", ":Data:Models:Wolf5.solid",
-                            ":Data:Models:Wolf6.solid", ":Data:Models:Wolf7.solid",
-                            ":Data:Models:Wolflow.solid", ":Data:Models:Belt.solid", 0);
-    Person::players[0]->skeleton.drawmodel.textureptr.load(":Data:Textures:Wolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
+    Person::players[0]->skeleton.Load("Skeleton/Basic Figure Wolf", "Skeleton/Basic Figure Wolf Low",
+                            "Skeleton/Rabbitbelt", "Models/Wolf.solid",
+                            "Models/Wolf2.solid", "Models/Wolf3.solid",
+                            "Models/Wolf4.solid", "Models/Wolf5.solid",
+                            "Models/Wolf6.solid", "Models/Wolf7.solid",
+                            "Models/Wolflow.solid", "Models/Belt.solid", 0);
+    Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Wolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
     Person::players[0]->creature = wolftype;
     Person::players[0]->damagetolerance = 300;
     set_proportion(0, "1 1 1 1");
@@ -479,37 +479,37 @@ void ch_wolfieisgod(const char *args)
 
 void ch_wolf(const char *args)
 {
-    Person::players[0]->skeleton.drawmodel.textureptr.load(":Data:Textures:Wolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
+    Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Wolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
 }
 
 void ch_snowwolf(const char *args)
 {
-    Person::players[0]->skeleton.drawmodel.textureptr.load(":Data:Textures:SnowWolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
+    Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/SnowWolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
 }
 
 void ch_darkwolf(const char *args)
 {
-    Person::players[0]->skeleton.drawmodel.textureptr.load(":Data:Textures:DarkWolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
+    Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/DarkWolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
 }
 
 void ch_lizardwolf(const char *args)
 {
-    Person::players[0]->skeleton.drawmodel.textureptr.load(":Data:Textures:Lizardwolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
+    Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/Lizardwolf.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
 }
 
 void ch_white(const char *args)
 {
-    Person::players[0]->skeleton.drawmodel.textureptr.load(":Data:Textures:fur.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
+    Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/fur.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
 }
 
 void ch_brown(const char *args)
 {
-    Person::players[0]->skeleton.drawmodel.textureptr.load(":Data:Textures:fur3.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
+    Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/fur3.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
 }
 
 void ch_black(const char *args)
 {
-    Person::players[0]->skeleton.drawmodel.textureptr.load(":Data:Textures:fur2.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
+    Person::players[0]->skeleton.drawmodel.textureptr.load("Textures/fur2.jpg", 1, &Person::players[0]->skeleton.skinText[0], &Person::players[0]->skeleton.skinsize);
 }
 
 void ch_sizemin(const char *args)
@@ -569,10 +569,10 @@ void ch_hs(const char *args)
 void ch_dialogue(const char *args)
 {
     int type;
-    char buf1[32], filename[64];
+    char buf1[32];
 
     sscanf(args, "%d %31s", &type, buf1);
-    snprintf(filename, 63, ":Data:Dialogues:%s.txt", buf1);
+    std::string filename = std::string("Dialogues/") + buf1 + ".txt";
 
     Dialog::dialogs.push_back(Dialog(type, filename));
 
@@ -583,11 +583,11 @@ void ch_dialogue(const char *args)
 
 void ch_fixdialogue(const char *args)
 {
-    char buf1[32], filename[64];
+    char buf1[32];
     int whichdi;
 
     sscanf(args, "%d %31s", &whichdi, buf1);
-    snprintf(filename, 63, ":Data:Dialogues:%s.txt", buf1);
+    std::string filename = std::string("Dialogues/") + buf1 + ".txt";
 
     Dialog::dialogs[whichdi] = Dialog(Dialog::dialogs[whichdi].type, filename);
 }
index 5987c8f498ce225485ce6694692951d8c0110045..1f3adc58a0997364172d9d9ae8841cbca6e12dc5 100644 (file)
@@ -23,6 +23,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include "Input.h"
 #include "Game.h"
 #include "binio.h"
+#include "Utils/Folders.h"
 
 extern int hostile;
 
@@ -109,7 +110,7 @@ DialogScene::DialogScene(FILE* tfile)
 /* Load dialog from txt file, used by console */
 Dialog::Dialog(int type, std::string filename) : type(type)
 {
-    ifstream ipstream(ConvertFileName(filename.c_str()));
+    ifstream ipstream(Folders::getResourcePath(filename));
     ipstream.ignore(256, ':');
     int numscenes;
     ipstream >> numscenes;
index 7ccc49f875b3a7866607e5e7c35a19d806b88174..4f7a2aaa1422b797386d41347a9bf31250a20d57 100644 (file)
@@ -151,7 +151,7 @@ void LoadMenu();
 void playdialoguescenesound();
 int findClosestPlayer();
 void Loadlevel(int which);
-void Loadlevel(const char *name);
+void Loadlevel(const std::string& name);
 void Tick();
 void TickOnce();
 void TickOnceAfter();
index 3cbed4a5040d083116aeebfc32fdd003e9b30d29..754faf61524823131df6578e459456cb083701d5 100644 (file)
@@ -22,6 +22,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include "openal_wrapper.h"
 #include "Animation.h"
 #include "Texture.h"
+#include "Utils/Folders.h"
 
 extern float screenwidth, screenheight;
 extern float viewdistance;
@@ -81,7 +82,7 @@ void Dispose()
         Game::endgame = 0;
     }
 
-    Account::saveFile(":Data:Users", Game::accountactive);
+    Account::saveFile(Folders::getUserDataPath()+"/users", Game::accountactive);
 
     //textures.clear();
 
@@ -145,7 +146,7 @@ void LoadSave(const char *fileName, GLuint *textureid, bool mipmap, GLubyte *arr
 
     //Load Image
     ImageRec texture;
-    load_image(ConvertFileName(fileName), texture);
+    load_image(Folders::getResourcePath(fileName).c_str(), texture);
     texdetail = temptexdetail;
 
     int bytesPerPixel = texture.bpp / 8;
@@ -453,7 +454,7 @@ void Game::InitGame()
 
     numchallengelevels = 14;
 
-    accountactive = Account::loadFile(":Data:Users");
+    accountactive = Account::loadFile(Folders::getUserDataPath()+"/users");
 
     whichjointstartarray[0] = righthip;
     whichjointendarray[0] = rightfoot;
@@ -539,7 +540,7 @@ void Game::InitGame()
 
     int temptexdetail = texdetail;
     texdetail = 1;
-    text->LoadFontTexture(":Data:Textures:Font.png");
+    text->LoadFontTexture("Textures/Font.png");
     text->BuildFont();
     texdetail = temptexdetail;
 
@@ -591,22 +592,22 @@ void Game::InitGame()
     if (musictoggle)
         emit_stream_np(stream_menutheme);
 
-    cursortexture.load(":Data:Textures:Cursor.png", 0);
+    cursortexture.load("Textures/Cursor.png", 0);
 
-    Mapcircletexture.load(":Data:Textures:MapCircle.png", 0);
-    Mapboxtexture.load(":Data:Textures:MapBox.png", 0);
-    Maparrowtexture.load(":Data:Textures:MapArrow.png", 0);
+    Mapcircletexture.load("Textures/MapCircle.png", 0);
+    Mapboxtexture.load("Textures/MapBox.png", 0);
+    Maparrowtexture.load("Textures/MapArrow.png", 0);
 
     temptexdetail = texdetail;
     if (texdetail > 2)
         texdetail = 2;
-    Mainmenuitems[0].load(":Data:Textures:Lugaru.png", 0);
-    Mainmenuitems[1].load(":Data:Textures:Newgame.png", 0);
-    Mainmenuitems[2].load(":Data:Textures:Options.png", 0);
-    Mainmenuitems[3].load(":Data:Textures:Quit.png", 0);
-    Mainmenuitems[4].load(":Data:Textures:Eyelid.png", 0);
-    Mainmenuitems[5].load(":Data:Textures:Resume.png", 0);
-    Mainmenuitems[6].load(":Data:Textures:Endgame.png", 0);
+    Mainmenuitems[0].load("Textures/Lugaru.png", 0);
+    Mainmenuitems[1].load("Textures/Newgame.png", 0);
+    Mainmenuitems[2].load("Textures/Options.png", 0);
+    Mainmenuitems[3].load("Textures/Quit.png", 0);
+    Mainmenuitems[4].load("Textures/Eyelid.png", 0);
+    Mainmenuitems[5].load("Textures/Resume.png", 0);
+    Mainmenuitems[6].load("Textures/Endgame.png", 0);
 
     texdetail = temptexdetail;
 
@@ -664,12 +665,12 @@ void Game::LoadStuff()
 
     i = abs(Random() % 4);
     visibleloading = 0; //don't use loadscreentexture yet
-    loadscreentexture.load(":Data:Textures:fire.jpg", 1);
+    loadscreentexture.load("Textures/fire.jpg", 1);
     visibleloading = 1;
 
     temptexdetail = texdetail;
     texdetail = 1;
-    text->LoadFontTexture(":Data:Textures:Font.png");
+    text->LoadFontTexture("Textures/Font.png");
     text->BuildFont();
     texdetail = temptexdetail;
 
@@ -690,22 +691,22 @@ void Game::LoadStuff()
 
     LOG("Loading weapon data...");
 
-    Weapon::knifetextureptr.load(":Data:Textures:knife.png", 0);
-    Weapon::bloodknifetextureptr.load(":Data:Textures:bloodknife.png", 0);
-    Weapon::lightbloodknifetextureptr.load(":Data:Textures:lightbloodknife.png", 0);
-    Weapon::swordtextureptr.load(":Data:Textures:sword.jpg", 1);
-    Weapon::bloodswordtextureptr.load(":Data:Textures:Swordblood.jpg", 1);
-    Weapon::lightbloodswordtextureptr.load(":Data:Textures:Swordbloodlight.jpg", 1);
-    Weapon::stafftextureptr.load(":Data:Textures:Staff.jpg", 1);
+    Weapon::knifetextureptr.load("Textures/knife.png", 0);
+    Weapon::bloodknifetextureptr.load("Textures/bloodknife.png", 0);
+    Weapon::lightbloodknifetextureptr.load("Textures/lightbloodknife.png", 0);
+    Weapon::swordtextureptr.load("Textures/sword.jpg", 1);
+    Weapon::bloodswordtextureptr.load("Textures/Swordblood.jpg", 1);
+    Weapon::lightbloodswordtextureptr.load("Textures/Swordbloodlight.jpg", 1);
+    Weapon::stafftextureptr.load("Textures/Staff.jpg", 1);
 
-    Weapon::throwingknifemodel.load((char *)":Data:Models:throwingknife.solid", 1);
+    Weapon::throwingknifemodel.load((char *)"Models/throwingknife.solid", 1);
     Weapon::throwingknifemodel.Scale(.001, .001, .001);
     Weapon::throwingknifemodel.Rotate(90, 0, 0);
     Weapon::throwingknifemodel.Rotate(0, 90, 0);
     Weapon::throwingknifemodel.flat = 0;
     Weapon::throwingknifemodel.CalculateNormals(1);
 
-    Weapon::swordmodel.load((char *)":Data:Models:sword.solid", 1);
+    Weapon::swordmodel.load((char *)"Models/sword.solid", 1);
     Weapon::swordmodel.Scale(.001, .001, .001);
     Weapon::swordmodel.Rotate(90, 0, 0);
     Weapon::swordmodel.Rotate(0, 90, 0);
@@ -713,7 +714,7 @@ void Game::LoadStuff()
     Weapon::swordmodel.flat = 1;
     Weapon::swordmodel.CalculateNormals(1);
 
-    Weapon::staffmodel.load((char *)":Data:Models:staff.solid", 1);
+    Weapon::staffmodel.load((char *)"Models/staff.solid", 1);
     Weapon::staffmodel.Scale(.005, .005, .005);
     Weapon::staffmodel.Rotate(90, 0, 0);
     Weapon::staffmodel.Rotate(0, 90, 0);
@@ -721,28 +722,28 @@ void Game::LoadStuff()
     Weapon::staffmodel.flat = 1;
     Weapon::staffmodel.CalculateNormals(1);
 
-    terrain.shadowtexture.load(":Data:Textures:shadow.png", 0);
-    terrain.bloodtexture.load(":Data:Textures:blood.png", 0);
-    terrain.breaktexture.load(":Data:Textures:break.png", 0);
-    terrain.bloodtexture2.load(":Data:Textures:blood.png", 0);
+    terrain.shadowtexture.load("Textures/shadow.png", 0);
+    terrain.bloodtexture.load("Textures/blood.png", 0);
+    terrain.breaktexture.load("Textures/break.png", 0);
+    terrain.bloodtexture2.load("Textures/blood.png", 0);
 
 
-    terrain.footprinttexture.load(":Data:Textures:footprint.png", 0);
-    terrain.bodyprinttexture.load(":Data:Textures:bodyprint.png", 0);
-    hawktexture.load(":Data:Textures:hawk.png", 0);
+    terrain.footprinttexture.load("Textures/footprint.png", 0);
+    terrain.bodyprinttexture.load("Textures/bodyprint.png", 0);
+    hawktexture.load("Textures/hawk.png", 0);
 
 
-    Sprite::cloudtexture.load(":Data:Textures:cloud.png", 1);
-    Sprite::cloudimpacttexture.load(":Data:Textures:cloudimpact.png", 1);
-    Sprite::bloodtexture.load(":Data:Textures:bloodparticle.png", 1);
-    Sprite::snowflaketexture.load(":Data:Textures:snowflake.png", 1);
-    Sprite::flametexture.load(":Data:Textures:flame.png", 1);
-    Sprite::bloodflametexture.load(":Data:Textures:bloodflame.png", 1);
-    Sprite::smoketexture.load(":Data:Textures:smoke.png", 1);
-    Sprite::shinetexture.load(":Data:Textures:shine.png", 1);
-    Sprite::splintertexture.load(":Data:Textures:splinter.png", 1);
-    Sprite::leaftexture.load(":Data:Textures:leaf.png", 1);
-    Sprite::toothtexture.load(":Data:Textures:tooth.png", 1);
+    Sprite::cloudtexture.load("Textures/cloud.png", 1);
+    Sprite::cloudimpacttexture.load("Textures/cloudimpact.png", 1);
+    Sprite::bloodtexture.load("Textures/bloodparticle.png", 1);
+    Sprite::snowflaketexture.load("Textures/snowflake.png", 1);
+    Sprite::flametexture.load("Textures/flame.png", 1);
+    Sprite::bloodflametexture.load("Textures/bloodflame.png", 1);
+    Sprite::smoketexture.load("Textures/smoke.png", 1);
+    Sprite::shinetexture.load("Textures/shine.png", 1);
+    Sprite::splintertexture.load("Textures/splinter.png", 1);
+    Sprite::leaftexture.load("Textures/leaf.png", 1);
+    Sprite::toothtexture.load("Textures/tooth.png", 1);
 
     yaw = 0;
     pitch = 0;
@@ -784,7 +785,7 @@ void Game::LoadStuff()
     viewer.x = terrain.size / 2 * terrain.scale;
     viewer.z = terrain.size / 2 * terrain.scale;
 
-    hawk.load((char *)":Data:Models:hawk.solid", 1);
+    hawk.load((char *)"Models/hawk.solid", 1);
     hawk.Scale(.03, .03, .03);
     hawk.Rotate(90, 1, 1);
     hawk.CalculateNormals(0);
@@ -793,20 +794,20 @@ void Game::LoadStuff()
     hawkcoords.z = terrain.size / 2 * terrain.scale - 5 - 7;
     hawkcoords.y = terrain.getHeight(hawkcoords.x, hawkcoords.z) + 25;
 
-    eye.load((char *)":Data:Models:eye.solid", 1);
+    eye.load((char *)"Models/eye.solid", 1);
     eye.Scale(.03, .03, .03);
     eye.CalculateNormals(0);
 
-    cornea.load((char *)":Data:Models:cornea.solid", 1);
+    cornea.load((char *)"Models/cornea.solid", 1);
     cornea.Scale(.03, .03, .03);
     cornea.CalculateNormals(0);
 
-    iris.load((char *)":Data:Models:iris.solid", 1);
+    iris.load((char *)"Models/iris.solid", 1);
     iris.Scale(.03, .03, .03);
     iris.CalculateNormals(0);
 
-    LoadSave(":Data:Textures:Bloodfur.png", 0, 1, &bloodText[0], 0);
-    LoadSave(":Data:Textures:Wolfbloodfur.png", 0, 1, &wolfbloodText[0], 0);
+    LoadSave("Textures/Bloodfur.png", 0, 1, &bloodText[0], 0);
+    LoadSave("Textures/Wolfbloodfur.png", 0, 1, &wolfbloodText[0], 0);
 
     oldenvironment = -4;
 
index 19d043df2a54fadbf640bfba47d68b22dd13994b..8646111176e950a827c514798411ad1fa4c6ae86 100644 (file)
@@ -43,6 +43,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include "Menu.h"
 #include "ConsoleCmds.h"
 #include "Dialog.h"
+#include "Utils/Folders.h"
 
 #include <algorithm>
 #include <set>
@@ -239,22 +240,22 @@ float oldmusicvolume[4] = {};
 int musicselected = 0;
 
 const char *rabbitskin[] = {
-    ":Data:Textures:Fur3.jpg",
-    ":Data:Textures:Fur.jpg",
-    ":Data:Textures:Fur2.jpg",
-    ":Data:Textures:Lynx.jpg",
-    ":Data:Textures:Otter.jpg",
-    ":Data:Textures:Opal.jpg",
-    ":Data:Textures:Sable.jpg",
-    ":Data:Textures:Chocolate.jpg",
-    ":Data:Textures:BW2.jpg",
-    ":Data:Textures:WB2.jpg"
+    "Textures/Fur3.jpg",
+    "Textures/Fur.jpg",
+    "Textures/Fur2.jpg",
+    "Textures/Lynx.jpg",
+    "Textures/Otter.jpg",
+    "Textures/Opal.jpg",
+    "Textures/Sable.jpg",
+    "Textures/Chocolate.jpg",
+    "Textures/BW2.jpg",
+    "Textures/WB2.jpg"
 };
 
 const char *wolfskin[] = {
-    ":Data:Textures:Wolf.jpg",
-    ":Data:Textures:Darkwolf.jpg",
-    ":Data:Textures:Snowwolf.jpg"
+    "Textures/Wolf.jpg",
+    "Textures/Darkwolf.jpg",
+    "Textures/Snowwolf.jpg"
 };
 
 const char **creatureskin[] = {rabbitskin, wolfskin};
@@ -601,29 +602,29 @@ void Setenvironment(int which)
         if (ambientsound)
             emit_stream_np(stream_wind);
 
-        objects.treetextureptr.load(":Data:Textures:snowtree.png", 0);
-        objects.bushtextureptr.load(":Data:Textures:bushsnow.png", 0);
-        objects.rocktextureptr.load(":Data:Textures:bouldersnow.jpg", 1);
-        objects.boxtextureptr.load(":Data:Textures:snowbox.jpg", 1);
+        objects.treetextureptr.load("Textures/snowtree.png", 0);
+        objects.bushtextureptr.load("Textures/bushsnow.png", 0);
+        objects.rocktextureptr.load("Textures/bouldersnow.jpg", 1);
+        objects.boxtextureptr.load("Textures/snowbox.jpg", 1);
 
         footstepsound = footstepsn1;
         footstepsound2 = footstepsn2;
         footstepsound3 = footstepst1;
         footstepsound4 = footstepst2;
 
-        terraintexture.load(":Data:Textures:snow.jpg", 1);
-        terraintexture2.load(":Data:Textures:rock.jpg", 1);
+        terraintexture.load("Textures/snow.jpg", 1);
+        terraintexture2.load("Textures/rock.jpg", 1);
 
 
         temptexdetail = texdetail;
         if (texdetail > 1)
             texdetail = 4;
-        skybox->load(   ":Data:Textures:Skybox(snow):Front.jpg",
-                        ":Data:Textures:Skybox(snow):Left.jpg",
-                        ":Data:Textures:Skybox(snow):Back.jpg",
-                        ":Data:Textures:Skybox(snow):Right.jpg",
-                        ":Data:Textures:Skybox(snow):Up.jpg",
-                        ":Data:Textures:Skybox(snow):Down.jpg");
+        skybox->load(   "Textures/Skybox(snow):Front.jpg",
+                        "Textures/Skybox(snow):Left.jpg",
+                        "Textures/Skybox(snow):Back.jpg",
+                        "Textures/Skybox(snow):Right.jpg",
+                        "Textures/Skybox(snow):Up.jpg",
+                        "Textures/Skybox(snow):Down.jpg");
 
 
 
@@ -632,10 +633,10 @@ void Setenvironment(int which)
     } else if (environment == desertenvironment) {
         windvector = 0;
         windvector.z = 2;
-        objects.treetextureptr.load(":Data:Textures:deserttree.png", 0);
-        objects.bushtextureptr.load(":Data:Textures:bushdesert.png", 0);
-        objects.rocktextureptr.load(":Data:Textures:boulderdesert.jpg", 1);
-        objects.boxtextureptr.load(":Data:Textures:desertbox.jpg", 1);
+        objects.treetextureptr.load("Textures/deserttree.png", 0);
+        objects.bushtextureptr.load("Textures/bushdesert.png", 0);
+        objects.rocktextureptr.load("Textures/boulderdesert.jpg", 1);
+        objects.boxtextureptr.load("Textures/desertbox.jpg", 1);
 
 
         if (ambientsound)
@@ -646,19 +647,19 @@ void Setenvironment(int which)
         footstepsound3 = footstepsn1;
         footstepsound4 = footstepsn2;
 
-        terraintexture.load(":Data:Textures:sand.jpg", 1);
-        terraintexture2.load(":Data:Textures:sandslope.jpg", 1);
+        terraintexture.load("Textures/sand.jpg", 1);
+        terraintexture2.load("Textures/sandslope.jpg", 1);
 
 
         temptexdetail = texdetail;
         if (texdetail > 1)
             texdetail = 4;
-        skybox->load(   ":Data:Textures:Skybox(sand):Front.jpg",
-                        ":Data:Textures:Skybox(sand):Left.jpg",
-                        ":Data:Textures:Skybox(sand):Back.jpg",
-                        ":Data:Textures:Skybox(sand):Right.jpg",
-                        ":Data:Textures:Skybox(sand):Up.jpg",
-                        ":Data:Textures:Skybox(sand):Down.jpg");
+        skybox->load(   "Textures/Skybox(sand):Front.jpg",
+                        "Textures/Skybox(sand):Left.jpg",
+                        "Textures/Skybox(sand):Back.jpg",
+                        "Textures/Skybox(sand):Right.jpg",
+                        "Textures/Skybox(sand):Up.jpg",
+                        "Textures/Skybox(sand):Down.jpg");
 
 
 
@@ -667,10 +668,10 @@ void Setenvironment(int which)
     } else if (environment == grassyenvironment) {
         windvector = 0;
         windvector.z = 2;
-        objects.treetextureptr.load(":Data:Textures:tree.png", 0);
-        objects.bushtextureptr.load(":Data:Textures:bush.png", 0);
-        objects.rocktextureptr.load(":Data:Textures:boulder.jpg", 1);
-        objects.boxtextureptr.load(":Data:Textures:grassbox.jpg", 1);
+        objects.treetextureptr.load("Textures/tree.png", 0);
+        objects.bushtextureptr.load("Textures/bush.png", 0);
+        objects.rocktextureptr.load("Textures/boulder.jpg", 1);
+        objects.boxtextureptr.load("Textures/grassbox.jpg", 1);
 
         if (ambientsound)
             emit_stream_np(stream_wind, 100.);
@@ -680,19 +681,19 @@ void Setenvironment(int which)
         footstepsound3 = footstepst1;
         footstepsound4 = footstepst2;
 
-        terraintexture.load(":Data:Textures:grassdirt.jpg", 1);
-        terraintexture2.load(":Data:Textures:mossrock.jpg", 1);
+        terraintexture.load("Textures/grassdirt.jpg", 1);
+        terraintexture2.load("Textures/mossrock.jpg", 1);
 
 
         temptexdetail = texdetail;
         if (texdetail > 1)
             texdetail = 4;
-        skybox->load(   ":Data:Textures:Skybox(grass):Front.jpg",
-                        ":Data:Textures:Skybox(grass):Left.jpg",
-                        ":Data:Textures:Skybox(grass):Back.jpg",
-                        ":Data:Textures:Skybox(grass):Right.jpg",
-                        ":Data:Textures:Skybox(grass):Up.jpg",
-                        ":Data:Textures:Skybox(grass):Down.jpg");
+        skybox->load(   "Textures/Skybox(grass):Front.jpg",
+                        "Textures/Skybox(grass):Left.jpg",
+                        "Textures/Skybox(grass):Back.jpg",
+                        "Textures/Skybox(grass):Right.jpg",
+                        "Textures/Skybox(grass):Up.jpg",
+                        "Textures/Skybox(grass):Down.jpg");
 
 
 
@@ -700,7 +701,7 @@ void Setenvironment(int which)
     }
     temptexdetail = texdetail;
     texdetail = 1;
-    terrain.load(":Data:Textures:heightmap.png");
+    terrain.load("Textures/heightmap.png");
 
     texdetail = temptexdetail;
 }
@@ -709,7 +710,7 @@ void LoadCampaign()
 {
     if (!accountactive)
         return;
-    ifstream ipstream(ConvertFileName((":Data:Campaigns:" + accountactive->getCurrentCampaign() + ".txt").c_str()));
+    ifstream ipstream(Folders::getResourcePath("Campaigns/" + accountactive->getCurrentCampaign() + ".txt"));
     if (!ipstream.good()) {
         if (accountactive->getCurrentCampaign() == "main") {
             cerr << "Could not found main campaign!" << endl;
@@ -730,11 +731,11 @@ void LoadCampaign()
     }
     ipstream.close();
 
-    ifstream test(ConvertFileName((":Data:Textures:" + accountactive->getCurrentCampaign() + ":World.png").c_str()));
+    ifstream test(Folders::getResourcePath("Textures/" + accountactive->getCurrentCampaign() + ":World.png"));
     if (test.good()) {
-        Mainmenuitems[7].load((":Data:Textures:" + accountactive->getCurrentCampaign() + ":World.png").c_str(), 0);
+        Mainmenuitems[7].load("Textures/" + accountactive->getCurrentCampaign() + ":World.png", 0);
     } else {
-        Mainmenuitems[7].load(":Data:Textures:World.png", 0);
+        Mainmenuitems[7].load("Textures/World.png", 0);
     }
 
     if (accountactive->getCampaignChoicesMade() == 0) {
@@ -745,11 +746,11 @@ void LoadCampaign()
 
 vector<string> ListCampaigns()
 {
-    DIR *campaigns = opendir(ConvertFileName(":Data:Campaigns"));
+    DIR *campaigns = opendir(Folders::getResourcePath("Campaigns").c_str());
     struct dirent *campaign = NULL;
     if (!campaigns) {
         perror("Problem while loading campaigns");
-        cerr << "campaign folder was : " << ConvertFileName(":Data:Campaigns") << endl;
+        cerr << "campaign folder was : " << Folders::getResourcePath("Campaigns") << endl;
         exit(EXIT_FAILURE);
     }
     vector<string> campaignNames;
@@ -781,13 +782,11 @@ void Game::Loadlevel(int which)
         Loadlevel("mapsave");
 }
 
-void Game::Loadlevel(const char *name)
+void Game::Loadlevel(const std::string& name)
 {
     int indemo; // FIXME this should be removed
     int templength;
     float lamefloat;
-    static const char *pfx = ":Data:Maps:";
-    char *buf;
 
     LOGFUNC;
 
@@ -817,14 +816,9 @@ void Game::Loadlevel(const char *name)
     pause_sound(whooshsound);
     pause_sound(stream_firesound);
 
-    // Change the map filename into something that is os specific
-    buf = (char*) alloca(strlen(pfx) + strlen(name) + 1);
-    sprintf(buf, "%s%s", pfx, name);
-    const char *FixedFN = ConvertFileName(buf);
-
     int mapvers;
     FILE *tfile;
-    tfile = fopen( FixedFN, "rb" );
+    tfile = fopen( Folders::getResourcePath("Maps/"+name).c_str(), "rb" );
     if (tfile) {
         pause_sound(stream_firesound);
         scoreadded = 0;
@@ -1109,49 +1103,49 @@ void Game::Loadlevel(const char *name)
                 Person::players[i]->creature = rabbittype;
             if (Person::players[i]->creature != wolftype) {
                 Person::players[i]->skeleton.Load(
-                    (char *)":Data:Skeleton:Basic Figure",
-                    (char *)":Data:Skeleton:Basic Figurelow",
-                    (char *)":Data:Skeleton:Rabbitbelt",
-                    (char *)":Data:Models:Body.solid",
-                    (char *)":Data:Models:Body2.solid",
-                    (char *)":Data:Models:Body3.solid",
-                    (char *)":Data:Models:Body4.solid",
-                    (char *)":Data:Models:Body5.solid",
-                    (char *)":Data:Models:Body6.solid",
-                    (char *)":Data:Models:Body7.solid",
-                    (char *)":Data:Models:Bodylow.solid",
-                    (char *)":Data:Models:Belt.solid", 0);
+                    (char *)"Skeleton/Basic Figure",
+                    (char *)"Skeleton/Basic Figurelow",
+                    (char *)"Skeleton/Rabbitbelt",
+                    (char *)"Models/Body.solid",
+                    (char *)"Models/Body2.solid",
+                    (char *)"Models/Body3.solid",
+                    (char *)"Models/Body4.solid",
+                    (char *)"Models/Body5.solid",
+                    (char *)"Models/Body6.solid",
+                    (char *)"Models/Body7.solid",
+                    (char *)"Models/Bodylow.solid",
+                    (char *)"Models/Belt.solid", 0);
             } else {
                 if (Person::players[i]->creature != wolftype) {
                     Person::players[i]->skeleton.Load(
-                        (char *)":Data:Skeleton:Basic Figure",
-                        (char *)":Data:Skeleton:Basic Figurelow",
-                        (char *)":Data:Skeleton:Rabbitbelt",
-                        (char *)":Data:Models:Body.solid",
-                        (char *)":Data:Models:Body2.solid",
-                        (char *)":Data:Models:Body3.solid",
-                        (char *)":Data:Models:Body4.solid",
-                        (char *)":Data:Models:Body5.solid",
-                        (char *)":Data:Models:Body6.solid",
-                        (char *)":Data:Models:Body7.solid",
-                        (char *)":Data:Models:Bodylow.solid",
-                        (char *)":Data:Models:Belt.solid", 1);
-                    Person::players[i]->skeleton.drawmodelclothes.textureptr.load(":Data:Textures:Belt.png", 1);
+                        (char *)"Skeleton/Basic Figure",
+                        (char *)"Skeleton/Basic Figurelow",
+                        (char *)"Skeleton/Rabbitbelt",
+                        (char *)"Models/Body.solid",
+                        (char *)"Models/Body2.solid",
+                        (char *)"Models/Body3.solid",
+                        (char *)"Models/Body4.solid",
+                        (char *)"Models/Body5.solid",
+                        (char *)"Models/Body6.solid",
+                        (char *)"Models/Body7.solid",
+                        (char *)"Models/Bodylow.solid",
+                        (char *)"Models/Belt.solid", 1);
+                    Person::players[i]->skeleton.drawmodelclothes.textureptr.load("Textures/Belt.png", 1);
                 }
                 if (Person::players[i]->creature == wolftype) {
                     Person::players[i]->skeleton.Load(
-                        (char *)":Data:Skeleton:Basic Figure Wolf",
-                        (char *)":Data:Skeleton:Basic Figure Wolf Low",
-                        (char *)":Data:Skeleton:Rabbitbelt",
-                        (char *)":Data:Models:Wolf.solid",
-                        (char *)":Data:Models:Wolf2.solid",
-                        (char *)":Data:Models:Wolf3.solid",
-                        (char *)":Data:Models:Wolf4.solid",
-                        (char *)":Data:Models:Wolf5.solid",
-                        (char *)":Data:Models:Wolf6.solid",
-                        (char *)":Data:Models:Wolf7.solid",
-                        (char *)":Data:Models:Wolflow.solid",
-                        (char *)":Data:Models:Belt.solid", 0);
+                        (char *)"Skeleton/Basic Figure Wolf",
+                        (char *)"Skeleton/Basic Figure Wolf Low",
+                        (char *)"Skeleton/Rabbitbelt",
+                        (char *)"Models/Wolf.solid",
+                        (char *)"Models/Wolf2.solid",
+                        (char *)"Models/Wolf3.solid",
+                        (char *)"Models/Wolf4.solid",
+                        (char *)"Models/Wolf5.solid",
+                        (char *)"Models/Wolf6.solid",
+                        (char *)"Models/Wolf7.solid",
+                        (char *)"Models/Wolflow.solid",
+                        (char *)"Models/Belt.solid", 0);
                 }
             }
 
@@ -1926,8 +1920,8 @@ void doDebugKeys()
 
                 if (Person::players[closest]->creature == rabbittype) {
                     Person::players[closest]->skeleton.id = closest;
-                    Person::players[closest]->skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf", (char *)":Data:Skeleton:Basic Figure Wolf Low", (char *)":Data:Skeleton:Rabbitbelt", (char *)":Data:Models:Wolf.solid", (char *)":Data:Models:Wolf2.solid", (char *)":Data:Models:Wolf3.solid", (char *)":Data:Models:Wolf4.solid", (char *)":Data:Models:Wolf5.solid", (char *)":Data:Models:Wolf6.solid", (char *)":Data:Models:Wolf7.solid", (char *)":Data:Models:Wolflow.solid", (char *)":Data:Models:Belt.solid", 0);
-                    Person::players[closest]->skeleton.drawmodel.textureptr.load(":Data:Textures:Wolf.jpg", 1, &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize);
+                    Person::players[closest]->skeleton.Load((char *)"Skeleton/Basic Figure Wolf", (char *)"Skeleton/Basic Figure Wolf Low", (char *)"Skeleton/Rabbitbelt", (char *)"Models/Wolf.solid", (char *)"Models/Wolf2.solid", (char *)"Models/Wolf3.solid", (char *)"Models/Wolf4.solid", (char *)"Models/Wolf5.solid", (char *)"Models/Wolf6.solid", (char *)"Models/Wolf7.solid", (char *)"Models/Wolflow.solid", (char *)"Models/Belt.solid", 0);
+                    Person::players[closest]->skeleton.drawmodel.textureptr.load("Textures/Wolf.jpg", 1, &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize);
                     Person::players[closest]->whichskin = 0;
                     Person::players[closest]->creature = wolftype;
 
@@ -1941,8 +1935,8 @@ void doDebugKeys()
                     Person::players[closest]->damagetolerance = 300;
                 } else {
                     Person::players[closest]->skeleton.id = closest;
-                    Person::players[closest]->skeleton.Load((char *)":Data:Skeleton:Basic Figure", (char *)":Data:Skeleton:Basic Figurelow", (char *)":Data:Skeleton:Rabbitbelt", (char *)":Data:Models:Body.solid", (char *)":Data:Models:Body2.solid", (char *)":Data:Models:Body3.solid", (char *)":Data:Models:Body4.solid", (char *)":Data:Models:Body5.solid", (char *)":Data:Models:Body6.solid", (char *)":Data:Models:Body7.solid", (char *)":Data:Models:Bodylow.solid", (char *)":Data:Models:Belt.solid", 1);
-                    Person::players[closest]->skeleton.drawmodel.textureptr.load(":Data:Textures:Fur3.jpg", 1, &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize);
+                    Person::players[closest]->skeleton.Load((char *)"Skeleton/Basic Figure", (char *)"Skeleton/Basic Figurelow", (char *)"Skeleton/Rabbitbelt", (char *)"Models/Body.solid", (char *)"Models/Body2.solid", (char *)"Models/Body3.solid", (char *)"Models/Body4.solid", (char *)"Models/Body5.solid", (char *)"Models/Body6.solid", (char *)"Models/Body7.solid", (char *)"Models/Bodylow.solid", (char *)"Models/Belt.solid", 1);
+                    Person::players[closest]->skeleton.drawmodel.textureptr.load("Textures/Fur3.jpg", 1, &Person::players[closest]->skeleton.skinText[0], &Person::players[closest]->skeleton.skinsize);
                     Person::players[closest]->whichskin = 0;
                     Person::players[closest]->creature = rabbittype;
 
@@ -2234,21 +2228,21 @@ void doDebugKeys()
                 Person::players.back()->creature = rabbittype;
                 Person::players.back()->howactive = editoractive;
                 Person::players.back()->skeleton.id = Person::players.size()-1;
-                Person::players.back()->skeleton.Load((char *)":Data:Skeleton:Basic Figure", (char *)":Data:Skeleton:Basic Figurelow", (char *)":Data:Skeleton:Rabbitbelt", (char *)":Data:Models:Body.solid", (char *)":Data:Models:Body2.solid", (char *)":Data:Models:Body3.solid", (char *)":Data:Models:Body4.solid", (char *)":Data:Models:Body5.solid", (char *)":Data:Models:Body6.solid", (char *)":Data:Models:Body7.solid", (char *)":Data:Models:Bodylow.solid", (char *)":Data:Models:Belt.solid", 1);
+                Person::players.back()->skeleton.Load((char *)"Skeleton/Basic Figure", (char *)"Skeleton/Basic Figurelow", (char *)"Skeleton/Rabbitbelt", (char *)"Models/Body.solid", (char *)"Models/Body2.solid", (char *)"Models/Body3.solid", (char *)"Models/Body4.solid", (char *)"Models/Body5.solid", (char *)"Models/Body6.solid", (char *)"Models/Body7.solid", (char *)"Models/Bodylow.solid", (char *)"Models/Belt.solid", 1);
 
                 int k = abs(Random() % 2) + 1;
                 if (k == 0) {
-                    Person::players.back()->skeleton.drawmodel.textureptr.load(":Data:Textures:Fur3.jpg", 1, &Person::players.back()->skeleton.skinText[0], &Person::players.back()->skeleton.skinsize);
+                    Person::players.back()->skeleton.drawmodel.textureptr.load("Textures/Fur3.jpg", 1, &Person::players.back()->skeleton.skinText[0], &Person::players.back()->skeleton.skinsize);
                     Person::players.back()->whichskin = 0;
                 } else if (k == 1) {
-                    Person::players.back()->skeleton.drawmodel.textureptr.load(":Data:Textures:Fur.jpg", 1, &Person::players.back()->skeleton.skinText[0], &Person::players.back()->skeleton.skinsize);
+                    Person::players.back()->skeleton.drawmodel.textureptr.load("Textures/Fur.jpg", 1, &Person::players.back()->skeleton.skinText[0], &Person::players.back()->skeleton.skinsize);
                     Person::players.back()->whichskin = 1;
                 } else {
-                    Person::players.back()->skeleton.drawmodel.textureptr.load(":Data:Textures:Fur2.jpg", 1, &Person::players.back()->skeleton.skinText[0], &Person::players.back()->skeleton.skinsize);
+                    Person::players.back()->skeleton.drawmodel.textureptr.load("Textures/Fur2.jpg", 1, &Person::players.back()->skeleton.skinText[0], &Person::players.back()->skeleton.skinsize);
                     Person::players.back()->whichskin = 2;
                 }
 
-                Person::players.back()->skeleton.drawmodelclothes.textureptr.load(":Data:Textures:Belt.png", 1);
+                Person::players.back()->skeleton.drawmodelclothes.textureptr.load("Textures/Belt.png", 1);
                 Person::players.back()->power = 1;
                 Person::players.back()->speedmult = 1;
                 Person::players.back()->animCurrent = bounceidleanim;
index 3e9f15501eb70a65898476d1be80705c83f16a85..3e6a72e825fc2caf89411e692e27a6b02618f9c8 100644 (file)
@@ -27,6 +27,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "Game.h"
 #include "ImageIO.h"
+#include "Utils/Folders.h"
 
 extern bool visibleloading;
 
@@ -74,7 +75,7 @@ bool save_screenshot(const char *file_name)
     const char *ptr = strrchr((char *)file_name, '.');
     if (ptr) {
         if (strcasecmp(ptr + 1, "png") == 0)
-            return save_screenshot_png(file_name);
+            return save_screenshot_png((Folders::getScreenshotDir() + '/' + file_name).c_str());
     }
 
     STUBBED("Unsupported image type");
@@ -291,6 +292,6 @@ save_png_done:
     if (fp)
         fclose(fp);
     if (!retval)
-        unlink(ConvertFileName(file_name));
+        unlink(file_name);
     return retval;
 }
index ea8ba749c12d655499360cb2f7401d376d5d9d7a..1777791269b6c84a174e369cbbc5b881bb57844d 100644 (file)
@@ -239,30 +239,3 @@ static int locateCorrectFile(char *buf, const char *mode)
     return(rc);
 } /* locateCorrectFile */
 #endif
-
-
-static char g_filename[4096];
-char* ConvertFileName( const char* orgfilename, const char *mode)
-{
-    if (orgfilename == g_filename) // recursion?
-        return g_filename;
-
-    // translate filename into proper path name
-    if (orgfilename[ 0] == ':')
-        orgfilename++;
-    strcpy( g_filename, orgfilename);
-
-    for (int n = 0; g_filename[ n]; n++) {
-        if (g_filename[ n] == ':')
-            g_filename[ n] = '/';
-
-        else if (g_filename[ n] == '\\')
-            g_filename[ n] = '/';
-    }
-
-#if PLATFORM_UNIX
-    locateCorrectFile(g_filename, mode);
-#endif
-
-    return g_filename;
-}
index 21681671116479d77757d8e88f7ee90d74484b88..5d6f9550aa694d07784fa51ada4dad751217a5a1 100644 (file)
@@ -92,12 +92,6 @@ inline bool isnormal( double x)
 #include <stdint.h>
 #endif
 
-
-// fix file names to use '/' instead of ':'
-char* ConvertFileName( const char* orgfilename, const char *mode = "rb" );
-
-#define fopen( a, b) fopen(ConvertFileName(a, b), b)
-
 #endif
 
 
index d0a991b8217a5b6eed602b44b613913ce6664dd9..16f92badf78552f5d1667896e0485184ba7276b1 100644 (file)
@@ -20,6 +20,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 
 #include "Game.h"
 #include "Models.h"
+#include "Utils/Folders.h"
 
 extern float multiplier;
 extern float viewdistance;
@@ -407,7 +408,7 @@ bool Model::loadnotex(const char *filename )
     type = notextype;
     color = 0;
 
-    tfile = fopen( ConvertFileName(filename), "rb" );
+    tfile = fopen( Folders::getResourcePath(filename).c_str(), "rb" );
     // read model settings
 
     fseek(tfile, 0, SEEK_SET);
@@ -477,7 +478,7 @@ bool Model::load(const char *filename, bool texture )
     type = normaltype;
     color = 0;
 
-    tfile = fopen( ConvertFileName(filename), "rb" );
+    tfile = fopen( Folders::getResourcePath(filename).c_str(), "rb" );
     // read model settings
 
 
@@ -543,16 +544,13 @@ bool Model::loaddecal(const char *filename, bool texture )
 
     LOGFUNC;
 
-    // Changing the filename so that its more os specific
-    char * FixedFN = ConvertFileName(filename);
-
-    LOG(std::string("Loading decal...") + FixedFN);
+    LOG(std::string("Loading decal...") + Folders::getResourcePath(filename));
 
     type = decalstype;
     numdecals = 0;
     color = 0;
 
-    tfile = fopen( FixedFN, "rb" );
+    tfile = fopen( Folders::getResourcePath(filename).c_str(), "rb" );
     // read model settings
 
 
@@ -646,7 +644,7 @@ bool Model::loadraw(char *filename )
     type = rawtype;
     color = 0;
 
-    tfile = fopen( ConvertFileName(filename), "rb" );
+    tfile = fopen( Folders::getResourcePath(filename).c_str(), "rb" );
     // read model settings
 
 
index 6f98ead6d536f158581f024dd1d652e439708c07..3ae0afba3d5c69fb5615bd574eae8aaf623bb27e 100644 (file)
@@ -546,17 +546,17 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float ascale)
         rotx[numobjects] = 0;
         roty[numobjects] = 0;
 
-        if (atype == boxtype)           model[numobjects].loaddecal((char *)":Data:Models:Box.solid", 0);
-        if (atype == cooltype)          model[numobjects].loaddecal((char *)":Data:Models:Cool.solid", 0);
-        if (atype == walltype)          model[numobjects].loaddecal((char *)":Data:Models:Wall.solid", 0);
-        if (atype == tunneltype)        model[numobjects].loaddecal((char *)":Data:Models:Tunnel.solid", 0);
-        if (atype == chimneytype)       model[numobjects].loaddecal((char *)":Data:Models:Chimney.solid", 0);
-        if (atype == spiketype)         model[numobjects].load((char *)":Data:Models:Spike.solid", 0);
-        if (atype == weirdtype)         model[numobjects].loaddecal((char *)":Data:Models:Weird.solid", 0);
-        if (atype == rocktype)          model[numobjects].loaddecal((char *)":Data:Models:Rock.solid", 0);
-        if (atype == treetrunktype)     model[numobjects].load((char *)":Data:Models:Treetrunk.solid", 0);
-        if (atype == treeleavestype)    model[numobjects].load((char *)":Data:Models:Leaves.solid", 0);
-        if (atype == bushtype)          model[numobjects].load((char *)":Data:Models:Bush.solid", 0);
+        if (atype == boxtype)           model[numobjects].loaddecal((char *)"Models/Box.solid", 0);
+        if (atype == cooltype)          model[numobjects].loaddecal((char *)"Models/Cool.solid", 0);
+        if (atype == walltype)          model[numobjects].loaddecal((char *)"Models/Wall.solid", 0);
+        if (atype == tunneltype)        model[numobjects].loaddecal((char *)"Models/Tunnel.solid", 0);
+        if (atype == chimneytype)       model[numobjects].loaddecal((char *)"Models/Chimney.solid", 0);
+        if (atype == spiketype)         model[numobjects].load((char *)"Models/Spike.solid", 0);
+        if (atype == weirdtype)         model[numobjects].loaddecal((char *)"Models/Weird.solid", 0);
+        if (atype == rocktype)          model[numobjects].loaddecal((char *)"Models/Rock.solid", 0);
+        if (atype == treetrunktype)     model[numobjects].load((char *)"Models/Treetrunk.solid", 0);
+        if (atype == treeleavestype)    model[numobjects].load((char *)"Models/Leaves.solid", 0);
+        if (atype == bushtype)          model[numobjects].load((char *)"Models/Bush.solid", 0);
 
         if (atype == boxtype)           friction[numobjects] = 1.5;
         if (atype == cooltype)          friction[numobjects] = 1.5;
@@ -572,7 +572,7 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float ascale)
         if (atype == treeleavestype)    friction[numobjects] = 0;
 
         if (atype == platformtype) {
-            model[numobjects].loaddecal((char *)":Data:Models:Platform.solid", 0);
+            model[numobjects].loaddecal((char *)"Models/Platform.solid", 0);
             model[numobjects].Rotate(90, 0, 0);
         }
 
@@ -636,17 +636,17 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float apitch, float a
         rotx[numobjects] = 0;
         roty[numobjects] = 0;
 
-        if (atype == boxtype)           model[numobjects].loaddecal((char *)":Data:Models:Box.solid", 0);
-        if (atype == cooltype)          model[numobjects].loaddecal((char *)":Data:Models:Cool.solid", 0);
-        if (atype == walltype)          model[numobjects].loaddecal((char *)":Data:Models:Wall.solid", 0);
-        if (atype == tunneltype)        model[numobjects].loaddecal((char *)":Data:Models:Tunnel.solid", 0);
-        if (atype == chimneytype)       model[numobjects].loaddecal((char *)":Data:Models:Chimney.solid", 0);
-        if (atype == spiketype)         model[numobjects].load((char *)":Data:Models:Spike.solid", 0);
-        if (atype == weirdtype)         model[numobjects].loaddecal((char *)":Data:Models:Weird.solid", 0);
-        if (atype == rocktype)          model[numobjects].loaddecal((char *)":Data:Models:Rock.solid", 0);
-        if (atype == treetrunktype)     model[numobjects].load((char *)":Data:Models:Treetrunk.solid", 0);
-        if (atype == treeleavestype)    model[numobjects].load((char *)":Data:Models:Leaves.solid", 0);
-        if (atype == bushtype)          model[numobjects].load((char *)":Data:Models:Bush.solid", 0);
+        if (atype == boxtype)           model[numobjects].loaddecal((char *)"Models/Box.solid", 0);
+        if (atype == cooltype)          model[numobjects].loaddecal((char *)"Models/Cool.solid", 0);
+        if (atype == walltype)          model[numobjects].loaddecal((char *)"Models/Wall.solid", 0);
+        if (atype == tunneltype)        model[numobjects].loaddecal((char *)"Models/Tunnel.solid", 0);
+        if (atype == chimneytype)       model[numobjects].loaddecal((char *)"Models/Chimney.solid", 0);
+        if (atype == spiketype)         model[numobjects].load((char *)"Models/Spike.solid", 0);
+        if (atype == weirdtype)         model[numobjects].loaddecal((char *)"Models/Weird.solid", 0);
+        if (atype == rocktype)          model[numobjects].loaddecal((char *)"Models/Rock.solid", 0);
+        if (atype == treetrunktype)     model[numobjects].load((char *)"Models/Treetrunk.solid", 0);
+        if (atype == treeleavestype)    model[numobjects].load((char *)"Models/Leaves.solid", 0);
+        if (atype == bushtype)          model[numobjects].load((char *)"Models/Bush.solid", 0);
 
         if (atype == boxtype)           friction[numobjects] = 1.5;
         if (atype == cooltype)          friction[numobjects] = 1.5;
@@ -665,7 +665,7 @@ void Objects::MakeObject(int atype, XYZ where, float ayaw, float apitch, float a
             friction[numobjects] = .5;
 
         if (atype == platformtype) {
-            model[numobjects].loaddecal((char *)":Data:Models:Platform.solid", 0);
+            model[numobjects].loaddecal((char *)"Models/Platform.solid", 0);
             model[numobjects].Rotate(90, 0, 0);
         }
 
index 609b9fdd8b0b0233bc1cf15adaca31577e446ff6..2ebfbfff3498633b73a23aa70bd0e1b1a5f57e95 100644 (file)
@@ -81,6 +81,10 @@ void SaveSettings()
     if (newscreenheight < 0)
         newscreenheight = screenheight;
     ofstream opstream(Folders::getConfigFilePath());
+    if (opstream.fail()) {
+        perror(("Couldn't save config file " + Folders::getConfigFilePath()).c_str());
+        return;
+    }
     opstream << "Screenwidth:\n";
     opstream << newscreenwidth;
     opstream << "\nScreenheight:\n";
@@ -169,8 +173,8 @@ void SaveSettings()
 bool LoadSettings()
 {
     ifstream ipstream(Folders::getConfigFilePath(), std::ios::in);
-    if ( !ipstream || ipstream.fail() ) {
-        printf("Config file not found\n");
+    if ( ipstream.fail() ) {
+        perror(("Couldn't read config file " + Folders::getConfigFilePath()).c_str());
         return false;
     }
     char setting[256];
index af343d6b3261b3a405f876f877e665a7a6813c85..a9f63e258ee438861871746d1baf78a47e7faddf 100644 (file)
@@ -23,6 +23,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include "Skeleton.h"
 #include "openal_wrapper.h"
 #include "Animation.h"
+#include "Utils/Folders.h"
 
 extern float multiplier;
 extern float gravity;
@@ -668,27 +669,18 @@ void Skeleton::FindRotationMuscle(int which, int animation)
 /* EFFECT
  * load an animation from file
  */
-void Animation::Load(const char *filename, int aheight, int aattack)
+void Animation::Load(const std::string& filename, int aheight, int aattack)
 {
     FILE *tfile;
     int i, j;
     XYZ endoffset;
 
-    // path to dir
-    const char *anim_prefix = ":Data:Animations:";
-
-
     LOGFUNC;
 
-    // concatenate anim_prefix + filename
-    int len = strlen(anim_prefix) + strlen(filename);
-    char *buf = new char[len + 1];
-    snprintf(buf, len + 1, "%s%s", anim_prefix, filename);
     // Changing the filename into something the OS can understand
-    char *fixedFN = ConvertFileName(buf);
-    delete[] buf;
+    std::string filepath = Folders::getResourcePath("Animations/"+filename);
 
-    LOG(std::string("Loading animation...") + fixedFN);
+    LOG(std::string("Loading animation...") + filepath);
 
     // clear existing data
     deallocate();
@@ -700,7 +692,7 @@ void Animation::Load(const char *filename, int aheight, int aattack)
         Game::LoadingScreen();
 
     // read file in binary mode
-    tfile = fopen( fixedFN, "rb" );
+    tfile = fopen( filepath.c_str(), "rb" );
     if (tfile) {
         // read numframes, joints to know how much memory to allocate
         funpackf(tfile, "Bi Bi", &numframes, &joints);
@@ -867,7 +859,7 @@ void Skeleton::Load(const char *filename,       const char *lowfilename, const c
 
     // load skeleton
 
-    tfile = fopen( ConvertFileName(filename), "rb" );
+    tfile = fopen( Folders::getResourcePath(filename).c_str(), "rb" );
 
     if (1) { // FIXME: should this be if(tfile) ?
         // read num_joints
@@ -977,7 +969,7 @@ void Skeleton::Load(const char *filename,       const char *lowfilename, const c
 
     // load ???
 
-    tfile = fopen( ConvertFileName(lowfilename), "rb" );
+    tfile = fopen( Folders::getResourcePath(lowfilename).c_str(), "rb" );
 
     if (1) { // FIXME: should this be if(tfile) ?
         // skip joints section
@@ -1075,7 +1067,7 @@ void Skeleton::Load(const char *filename,       const char *lowfilename, const c
     // load clothes
 
     if (clothes) {
-        tfile = fopen( ConvertFileName(clothesfilename), "rb" ); // FIXME: where's the check for valid load
+        tfile = fopen( Folders::getResourcePath(clothesfilename).c_str(), "rb" ); // FIXME: where's the check for valid load
 
         // skip num_joints
         lSize = sizeof(num_joints);
index 8bc7b74752c724b9b566a6d1a2be1a2b64e7256f..854355f38af564855c2968d9709f133102884049 100644 (file)
@@ -135,7 +135,7 @@ public:
     ~Animation();
     Animation & operator = (const Animation & ani);
 
-    void Load(const char *fileName, int aheight, int aattack);
+    void Load(const std::string& fileName, int aheight, int aattack);
 
 protected:
     void deallocate();
index c2d4eb714863b86e334d5a86aa51e0b94318f843..735d93975fc58780c86bb929177a9378158a9a48 100644 (file)
@@ -20,6 +20,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include "Quaternions.h"
 #include "Sounds.h"
 #include "openal_wrapper.h"
+#include "Utils/Folders.h"
 
 struct OPENAL_SAMPLE *samp[sounds_count];
 
@@ -57,10 +58,9 @@ static int snd_mode(int snd)
 void loadAllSounds()
 {
     for (int i = 0; i < sounds_count; i++) {
-        char buf[64];
-        snprintf(buf, 64, ":Data:Sounds:%s", sound_data[i]);
+        std::string buf = std::string("Sounds/") + sound_data[i];
         samp[i] = OPENAL_Sample_Load(OPENAL_FREE,
-                                     ConvertFileName(buf),
+                                     Folders::getResourcePath(buf).c_str(),
                                      snd_mode(i),
                                      0, 0);
     }
index 9061f37559694f06f3bcb8ab4f8834f9da0367b7..c395ebf0b03113e54324005b566ca3b7139ac08e 100644 (file)
@@ -21,6 +21,8 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include "Game.h"
 #include "Terrain.h"
 #include "Objects.h"
+#include "Utils/Folders.h"
+
 extern XYZ viewer;
 extern float viewdistance;
 extern float fadestart;
@@ -407,7 +409,7 @@ bool Terrain::load(const char *fileName)
     ImageRec texture;
 
     //Load Image
-    load_image(ConvertFileName(fileName), texture);
+    load_image(Folders::getResourcePath(fileName).c_str(), texture);
 
     //Is it valid?
     if (texture.bpp > 24) {
index dd2d1cc63ff0e0b7760bcfa4bb7324c3ba8a35b0..7fb4b94609740f7ba55e8ad4ac2119ea7f981f54 100644 (file)
@@ -21,6 +21,7 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include "gamegl.h"
 #include "Texture.h"
 #include "ImageIO.h"
+#include "Utils/Folders.h"
 
 using namespace std;
 
@@ -33,7 +34,7 @@ void TextureRes::load()
     ImageRec texture;
 
     //load image into 'texture'
-    load_image(ConvertFileName(filename.c_str()), texture);
+    load_image(filename.c_str(), texture);
 
     skinsize = texture.sizeX;
     GLuint type = GL_RGBA;
@@ -107,13 +108,13 @@ TextureRes::~TextureRes()
 void Texture::load(const string& filename, bool hasMipmap)
 {
     destroy();
-    tex = new TextureRes(filename, hasMipmap);
+    tex = new TextureRes(Folders::getResourcePath(filename), hasMipmap);
 }
 
 void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep)
 {
     destroy();
-    tex = new TextureRes(filename, hasMipmap, array, skinsizep);
+    tex = new TextureRes(Folders::getResourcePath(filename), hasMipmap, array, skinsizep);
 }
 
 void Texture::destroy()
index 3bca88542ffc81d26394b2790c0d55e894229407..b032f5e241e7a219fcda8882d59e36d8239d9a67 100644 (file)
@@ -86,25 +86,3 @@ Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b)
 
     return time;
 }
-
-
-static char g_filename[ 256];
-char* ConvertFileName( const char* orgfilename)
-{
-    // translate filename into proper path name
-    if (orgfilename[ 0] == ':')
-        orgfilename++;
-    strcpy( g_filename, orgfilename);
-
-    for (int n = 0; g_filename[ n]; n++) {
-        if (g_filename[ n] == ':')
-            g_filename[ n] = '/';
-    }
-
-    return g_filename;
-}
-
-char* ConvertFileName( const char* orgfilename, const char* junk)
-{
-    return ConvertFileName(orgfilename);
-}
index 05fe6a4530bcfff1ba804325d34c9e764cb76ab7..32c7945f8068104280683648ec8324f55ef1fba3 100644 (file)
@@ -73,13 +73,6 @@ enum {
 
 Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b);
 
-// fix file names to use '/' instead of ':'
-char* ConvertFileName( const char* orgfilename);
-char* ConvertFileName( const char* orgfilename, const char* junk);
-
-
-#define fopen(a, b) fopen(ConvertFileName(a), b);
-
 #ifndef __MINGW32__
 inline float abs(float f)
 {
index 4331c69f33ff075d450336a0dadefc2e5d966959..ecac525b61f9312217755e0c4ffd7c5bc4d2752e 100644 (file)
@@ -293,7 +293,6 @@ static void *decode_to_pcm(const char *_fname, ALenum &format, ALsizei &size, AL
     strcat(fname, ".ogg");
 
     // just in case...
-#undef fopen
     FILE *io = fopen(fname, "rb");
     if (io == NULL)
         return NULL;