From: Côme Chilliet Date: Thu, 8 Dec 2016 02:49:40 +0000 (+0700) Subject: Replaced as much char* as possible by std::strings X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=f66f0e0b961dd138e4a60554373de9e64abd973b;p=lugaru.git Replaced as much char* as possible by std::strings --- diff --git a/Source/Account.cpp b/Source/Account.cpp index b93eff1..b3d42c7 100644 --- a/Source/Account.cpp +++ b/Source/Account.cpp @@ -75,7 +75,7 @@ Account* Account::destroy(Account* a) return NULL; } } - printf("Unexpected error : User %s not found\n", a->getName()); + printf("Unexpected error : User %s not found\n", a->getName().c_str()); return accounts.front(); } @@ -199,13 +199,12 @@ void Account::saveFile(string filename, Account* accountactive) tfile = fopen(filename.c_str(), "wb" ); if (tfile) { - printf("writing %d accounts :\n", getNbAccounts()); fpackf(tfile, "Bi", getNbAccounts()); fpackf(tfile, "Bi", indice(accountactive)); for (int i = 0; i < getNbAccounts(); i++) { Account* a = Account::get(i); - printf("writing account %d/%d (%s)\n", i + 1, getNbAccounts(), a->getName()); + printf("writing account %d/%d (%s)\n", i + 1, getNbAccounts(), a->getName().c_str()); fpackf(tfile, "Bi", a->difficulty); fpackf(tfile, "Bi", a->progress); fpackf(tfile, "Bi", a->campaignProgress.size()); diff --git a/Source/Account.h b/Source/Account.h index b9d2483..f5b91f1 100644 --- a/Source/Account.h +++ b/Source/Account.h @@ -60,8 +60,8 @@ public: void setDifficulty(int i) { difficulty = i; }; - const char* getName() { - return name.c_str(); + const std::string& getName() { + return name; }; float getCampaignScore() { return campaignProgress[currentCampaign].score; diff --git a/Source/Animation.cpp b/Source/Animation.cpp index f749ae6..b7e3995 100644 --- a/Source/Animation.cpp +++ b/Source/Animation.cpp @@ -21,7 +21,7 @@ along with Lugaru. If not, see . #include "Animation.h" struct animation_data_elt { - const char *filename; + const std::string& filename; int height; int attack; }; diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index fcd1798..c12904d 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -134,7 +134,7 @@ void Game::deleteGame() -void LoadSave(const char *fileName, GLuint *textureid, bool mipmap, GLubyte *array, int *skinsize) +void LoadSave(const std::string& fileName, GLuint *textureid, bool mipmap, GLubyte *array, int *skinsize) { LOGFUNC; @@ -702,14 +702,14 @@ void Game::LoadStuff() Weapon::lightbloodswordtextureptr.load("Textures/SwordBloodLight.jpg", 1); Weapon::stafftextureptr.load("Textures/Staff.jpg", 1); - Weapon::throwingknifemodel.load((char *)"Models/ThrowingKnife.solid", 1); + Weapon::throwingknifemodel.load("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 *)"Models/Sword.solid", 1); + Weapon::swordmodel.load("Models/Sword.solid", 1); Weapon::swordmodel.Scale(.001, .001, .001); Weapon::swordmodel.Rotate(90, 0, 0); Weapon::swordmodel.Rotate(0, 90, 0); @@ -717,7 +717,7 @@ void Game::LoadStuff() Weapon::swordmodel.flat = 1; Weapon::swordmodel.CalculateNormals(1); - Weapon::staffmodel.load((char *)"Models/Staff.solid", 1); + Weapon::staffmodel.load("Models/Staff.solid", 1); Weapon::staffmodel.Scale(.005, .005, .005); Weapon::staffmodel.Rotate(90, 0, 0); Weapon::staffmodel.Rotate(0, 90, 0); @@ -788,7 +788,7 @@ void Game::LoadStuff() viewer.x = terrain.size / 2 * terrain.scale; viewer.z = terrain.size / 2 * terrain.scale; - hawk.load((char *)"Models/Hawk.solid", 1); + hawk.load("Models/Hawk.solid", 1); hawk.Scale(.03, .03, .03); hawk.Rotate(90, 1, 1); hawk.CalculateNormals(0); @@ -797,15 +797,15 @@ void Game::LoadStuff() hawkcoords.z = terrain.size / 2 * terrain.scale - 5 - 7; hawkcoords.y = terrain.getHeight(hawkcoords.x, hawkcoords.z) + 25; - eye.load((char *)"Models/Eye.solid", 1); + eye.load("Models/Eye.solid", 1); eye.Scale(.03, .03, .03); eye.CalculateNormals(0); - cornea.load((char *)"Models/Cornea.solid", 1); + cornea.load("Models/Cornea.solid", 1); cornea.Scale(.03, .03, .03); cornea.CalculateNormals(0); - iris.load((char *)"Models/Iris.solid", 1); + iris.load("Models/Iris.solid", 1); iris.Scale(.03, .03, .03); iris.CalculateNormals(0); diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 5c63d3d..df0bc20 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -827,7 +827,7 @@ void Game::Loadlevel(const std::string& name) hostiletime = 0; won = 0; - animation[bounceidleanim].Load((char *)"Idle", middleheight, neutral); + animation[bounceidleanim].Load("Idle", middleheight, neutral); Dialog::dialogs.clear(); @@ -1159,7 +1159,7 @@ void Game::Loadlevel(const std::string& name) Person::players[i]->proportionlegs.z = 0; } - Person::players[i]->tempanimation.Load((char *)"Tempanim", 0, 0); + Person::players[i]->tempanimation.Load("Tempanim", 0, 0); if (i == 0) { Person::players[i]->headmorphness = 0; @@ -2238,7 +2238,7 @@ void doDebugKeys() Person::players.back()->proportionlegs.z = 0; } - Person::players.back()->tempanimation.Load((char *)"Tempanim", 0, 0); + Person::players.back()->tempanimation.Load("Tempanim", 0, 0); Person::players.back()->damagetolerance = 200; @@ -4644,7 +4644,7 @@ void updateSettingsMenu() void updateStereoConfigMenu() { char sbuf[256]; - sprintf(sbuf, "Stereo mode: %s", StereoModeName(newstereomode)); + sprintf(sbuf, "Stereo mode: %s", StereoModeName(newstereomode).c_str()); Menu::setText(0, sbuf); sprintf(sbuf, "Stereo separation: %.3f", stereoseparation); Menu::setText(1, sbuf); @@ -5152,7 +5152,7 @@ void MenuTick() if (selected == 0) { newstereomode = (StereoMode)(newstereomode + 1); while (!CanInitStereo(newstereomode)) { - printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode); + printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode).c_str(), newstereomode); newstereomode = (StereoMode)(newstereomode + 1); if (newstereomode >= stereoCount) newstereomode = stereoNone; diff --git a/Source/Models.cpp b/Source/Models.cpp index 4879ac2..2c30168 100644 --- a/Source/Models.cpp +++ b/Source/Models.cpp @@ -400,7 +400,7 @@ void Model::UpdateVertexArrayNoTexNoNorm() } } -bool Model::loadnotex(const char *filename ) +bool Model::loadnotex(const std::string& filename ) { FILE *tfile; long i; @@ -464,7 +464,7 @@ bool Model::loadnotex(const char *filename ) } -bool Model::load(const char *filename, bool texture ) +bool Model::load(const std::string& filename, bool texture ) { FILE *tfile; long i; @@ -538,7 +538,7 @@ bool Model::load(const char *filename, bool texture ) return true; } -bool Model::loaddecal(const char *filename, bool texture ) +bool Model::loaddecal(const std::string& filename, bool texture ) { FILE *tfile; long i, j; @@ -633,7 +633,7 @@ bool Model::loaddecal(const char *filename, bool texture ) return true; } -bool Model::loadraw(char *filename ) +bool Model::loadraw(const std::string& filename) { FILE *tfile; long i; diff --git a/Source/Models.h b/Source/Models.h index 8db72a2..3874e23 100644 --- a/Source/Models.h +++ b/Source/Models.h @@ -127,10 +127,10 @@ public: void UpdateVertexArray(); void UpdateVertexArrayNoTex(); void UpdateVertexArrayNoTexNoNorm(); - bool loadnotex(const char *filename); - bool loadraw(char *filename); - bool load(const char *filename, bool texture); - bool loaddecal(const char *filename, bool texture); + bool loadnotex(const std::string& filename); + bool loadraw(const std::string& filename); + bool load(const std::string& filename, bool texture); + bool loaddecal(const std::string& filename, bool texture); void Scale(float xscale, float yscale, float zscale); void FlipTexCoords(); void UniformTexCoords(); diff --git a/Source/Objects.cpp b/Source/Objects.cpp index efb2c00..dd4f4a7 100644 --- a/Source/Objects.cpp +++ b/Source/Objects.cpp @@ -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 *)"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) model[numobjects].loaddecal("Models/Box.solid", 0); + if (atype == cooltype) model[numobjects].loaddecal("Models/Cool.solid", 0); + if (atype == walltype) model[numobjects].loaddecal("Models/Wall.solid", 0); + if (atype == tunneltype) model[numobjects].loaddecal("Models/Tunnel.solid", 0); + if (atype == chimneytype) model[numobjects].loaddecal("Models/Chimney.solid", 0); + if (atype == spiketype) model[numobjects].load("Models/Spike.solid", 0); + if (atype == weirdtype) model[numobjects].loaddecal("Models/Weird.solid", 0); + if (atype == rocktype) model[numobjects].loaddecal("Models/Rock.solid", 0); + if (atype == treetrunktype) model[numobjects].load("Models/TreeTrunk.solid", 0); + if (atype == treeleavestype) model[numobjects].load("Models/Leaves.solid", 0); + if (atype == bushtype) model[numobjects].load("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 *)"Models/Platform.solid", 0); + model[numobjects].loaddecal("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 *)"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) model[numobjects].loaddecal("Models/Box.solid", 0); + if (atype == cooltype) model[numobjects].loaddecal("Models/Cool.solid", 0); + if (atype == walltype) model[numobjects].loaddecal("Models/Wall.solid", 0); + if (atype == tunneltype) model[numobjects].loaddecal("Models/Tunnel.solid", 0); + if (atype == chimneytype) model[numobjects].loaddecal("Models/Chimney.solid", 0); + if (atype == spiketype) model[numobjects].load("Models/Spike.solid", 0); + if (atype == weirdtype) model[numobjects].loaddecal("Models/Weird.solid", 0); + if (atype == rocktype) model[numobjects].loaddecal("Models/Rock.solid", 0); + if (atype == treetrunktype) model[numobjects].load("Models/TreeTrunk.solid", 0); + if (atype == treeleavestype) model[numobjects].load("Models/Leaves.solid", 0); + if (atype == bushtype) model[numobjects].load("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 *)"Models/Platform.solid", 0); + model[numobjects].loaddecal("Models/Platform.solid", 0); model[numobjects].Rotate(90, 0, 0); } diff --git a/Source/Person.cpp b/Source/Person.cpp index 0d3913e..3c9a123 100644 --- a/Source/Person.cpp +++ b/Source/Person.cpp @@ -6839,7 +6839,7 @@ void Person::addClothes() bool Person::addClothes(const int& clothesId) { LOGFUNC; - const char* fileName = clothes[clothesId]; + const std::string fileName = clothes[clothesId]; GLubyte* array = &skeleton.skinText[0]; diff --git a/Source/Skeleton.cpp b/Source/Skeleton.cpp index c74f07d..5a0e274 100644 --- a/Source/Skeleton.cpp +++ b/Source/Skeleton.cpp @@ -780,12 +780,12 @@ void Animation::Load(const std::string& filename, int aheight, int aattack) * load skeleton * takes filenames for three skeleton files and various models */ -void Skeleton::Load(const char *filename, const char *lowfilename, const char *clothesfilename, - const char *modelfilename, const char *model2filename, - const char *model3filename, const char *model4filename, - const char *model5filename, const char *model6filename, - const char *model7filename, const char *modellowfilename, - const char *modelclothesfilename, bool clothes) +void Skeleton::Load(const std::string& filename, const std::string& lowfilename, const std::string& clothesfilename, + const std::string& modelfilename, const std::string& model2filename, + const std::string& model3filename, const std::string& model4filename, + const std::string& model5filename, const std::string& model6filename, + const std::string& model7filename, const std::string& modellowfilename, + const std::string& modelclothesfilename, bool clothes) { GLfloat M[16]; int parentID; diff --git a/Source/Skeleton.h b/Source/Skeleton.h index 854355f..eb2afff 100644 --- a/Source/Skeleton.h +++ b/Source/Skeleton.h @@ -201,7 +201,7 @@ public: void FindRotationJoint(int which); void FindRotationJointSameTwist(int which); void FindRotationMuscle(int which, int animation); - void Load(const char *fileName, const char *lowfileName, const char *clothesfileName, const char *modelfileName, const char *model2fileName, const char *model3fileName, const char *model4fileName, const char *model5fileNamee, const char *model6fileName, const char *model7fileName, const char *modellowfileName, const char *modelclothesfileName, bool aclothes); + void Load(const std::string& fileName, const std::string& lowfileName, const std::string& clothesfileName, const std::string& modelfileName, const std::string& model2fileName, const std::string& model3fileName, const std::string& model4fileName, const std::string& model5fileNamee, const std::string& model6fileName, const std::string& model7fileName, const std::string& modellowfileName, const std::string& modelclothesfileName, bool aclothes); /* // unused diff --git a/Source/Skybox.cpp b/Source/Skybox.cpp index 7db0d2b..8fcc967 100644 --- a/Source/Skybox.cpp +++ b/Source/Skybox.cpp @@ -29,8 +29,8 @@ extern float skyboxr; extern float skyboxg; extern float skyboxb; -void SkyBox::load (const char *ffront, const char *fleft, const char *fback, - const char *fright, const char *fup, const char *fdown) +void SkyBox::load (const std::string& ffront, const std::string& fleft, const std::string& fback, + const std::string& fright, const std::string& fup, const std::string& fdown) { front.load(ffront, true); left.load(fleft, true); diff --git a/Source/Skybox.h b/Source/Skybox.h index fd542a4..5619a2a 100644 --- a/Source/Skybox.h +++ b/Source/Skybox.h @@ -32,8 +32,8 @@ class SkyBox public: Texture front, left, back, right, up, down; - void load(const char *ffront, const char *fleft, const char *fback, - const char *fright, const char *fup, const char *fdown); + void load(const std::string& ffront, const std::string& fleft, const std::string& fback, + const std::string& fright, const std::string& fup, const std::string& fdown); void draw(); SkyBox() {} diff --git a/Source/Stereo.cpp b/Source/Stereo.cpp index d288c61..8887a52 100644 --- a/Source/Stereo.cpp +++ b/Source/Stereo.cpp @@ -121,7 +121,7 @@ void InitStereo(StereoMode mode) } -const char* StereoModeName(StereoMode mode) +const std::string StereoModeName(StereoMode mode) { switch (mode) { case stereoNone: diff --git a/Source/Stereo.h b/Source/Stereo.h index 17271ea..8e70e5e 100644 --- a/Source/Stereo.h +++ b/Source/Stereo.h @@ -47,6 +47,6 @@ extern bool stereoreverse; bool CanInitStereo(StereoMode mode); void InitStereo(StereoMode mode); -const char* StereoModeName(StereoMode mode); +const std::string StereoModeName(StereoMode mode); #endif diff --git a/Source/Terrain.cpp b/Source/Terrain.cpp index 41a2181..34da00e 100644 --- a/Source/Terrain.cpp +++ b/Source/Terrain.cpp @@ -398,7 +398,7 @@ void Terrain::UpdateVertexArray(int whichx, int whichy) } -bool Terrain::load(const char *fileName) +bool Terrain::load(const std::string& fileName) { static long i, j; static long x, y; diff --git a/Source/Terrain.h b/Source/Terrain.h index 0a6b74b..c375687 100644 --- a/Source/Terrain.h +++ b/Source/Terrain.h @@ -117,7 +117,7 @@ public: void UpdateTransparency(int whichx, int whichy); void UpdateTransparencyother(int whichx, int whichy); void UpdateTransparencyotherother(int whichx, int whichy); - bool load(const char *fileName); + bool load(const std::string& fileName); void CalculateNormals(); void drawdecals(); void draw(int layer); diff --git a/Source/Text.cpp b/Source/Text.cpp index 5b90b6a..0a31c3e 100644 --- a/Source/Text.cpp +++ b/Source/Text.cpp @@ -22,7 +22,7 @@ along with Lugaru. If not, see . #include "Text.h" #include "Game.h" -void Text::LoadFontTexture(const char *fileName) +void Text::LoadFontTexture(const std::string& fileName) { LOGFUNC; diff --git a/Source/Text.h b/Source/Text.h index 281b75c..c2a2ccc 100644 --- a/Source/Text.h +++ b/Source/Text.h @@ -36,7 +36,7 @@ public: Texture FontTexture; GLuint base; - void LoadFontTexture(const char *fileName); + void LoadFontTexture(const std::string& fileName); void BuildFont(); void glPrint(float x, float y, const char *string, int set, float size, float width, float height); void glPrintOutline(float x, float y, const char *string, int set, float size, float width, float height);