Refactorizations:

- Prefer std::unordered_map over std::map
- Sort CollArr by treetypes to avoid frequent texture rebinding

git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/trunk@703 0420edf4-82e4-42fc-9478-35b55e6d67a3
master
pkeus 2018-03-22 16:17:58 +00:00
parent c6d7d812f1
commit 5abb921456
15 changed files with 43 additions and 36 deletions

View File

@ -98,6 +98,7 @@
<DisableSpecificWarnings>4100;4512</DisableSpecificWarnings> <DisableSpecificWarnings>4100;4512</DisableSpecificWarnings>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules> <EnforceTypeConversionRules>true</EnforceTypeConversionRules>
<RuntimeTypeInfo>false</RuntimeTypeInfo> <RuntimeTypeInfo>false</RuntimeTypeInfo>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>sfml-system-d.lib;sfml-window-d.lib;sfml-graphics-d.lib;sfml-audio-d.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>sfml-system-d.lib;sfml-window-d.lib;sfml-graphics-d.lib;sfml-audio-d.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
@ -120,6 +121,7 @@
<DisableSpecificWarnings>4100;4512</DisableSpecificWarnings> <DisableSpecificWarnings>4100;4512</DisableSpecificWarnings>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules> <EnforceTypeConversionRules>true</EnforceTypeConversionRules>
<RuntimeTypeInfo>false</RuntimeTypeInfo> <RuntimeTypeInfo>false</RuntimeTypeInfo>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>sfml-system-d-64.lib;sfml-window-d-64.lib;sfml-graphics-d-64.lib;sfml-audio-d-64.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>sfml-system-d-64.lib;sfml-window-d-64.lib;sfml-graphics-d-64.lib;sfml-audio-d-64.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
@ -147,6 +149,7 @@
<DisableSpecificWarnings>4100;4512</DisableSpecificWarnings> <DisableSpecificWarnings>4100;4512</DisableSpecificWarnings>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules> <EnforceTypeConversionRules>true</EnforceTypeConversionRules>
<RuntimeTypeInfo>false</RuntimeTypeInfo> <RuntimeTypeInfo>false</RuntimeTypeInfo>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>sfml-system.lib;sfml-window.lib;sfml-graphics.lib;sfml-audio.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>sfml-system.lib;sfml-window.lib;sfml-graphics.lib;sfml-audio.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>
@ -178,6 +181,7 @@
<DisableSpecificWarnings>4100;4512</DisableSpecificWarnings> <DisableSpecificWarnings>4100;4512</DisableSpecificWarnings>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules> <EnforceTypeConversionRules>true</EnforceTypeConversionRules>
<RuntimeTypeInfo>false</RuntimeTypeInfo> <RuntimeTypeInfo>false</RuntimeTypeInfo>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>sfml-system-64.lib;sfml-window-64.lib;sfml-graphics-64.lib;sfml-audio-64.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>sfml-system-64.lib;sfml-window-64.lib;sfml-graphics-64.lib;sfml-audio-64.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies)</AdditionalDependencies>

View File

@ -19,7 +19,7 @@ GNU General Public License for more details.
#include "bh.h" #include "bh.h"
#include <vector> #include <vector>
#include <map> #include <unordered_map>
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// class CSound // class CSound
@ -31,7 +31,7 @@ struct TSound;
class CSound { class CSound {
private: private:
std::vector<TSound*> sounds; std::vector<TSound*> sounds;
std::map<std::string, std::size_t> SoundIndex; std::unordered_map<std::string, std::size_t> SoundIndex;
public: public:
~CSound(); ~CSound();
bool LoadChunk(const std::string& name, const std::string& filename); bool LoadChunk(const std::string& name, const std::string& filename);
@ -71,11 +71,11 @@ class Music;
class CMusic { class CMusic {
private: private:
std::vector<sf::Music*> musics; std::vector<sf::Music*> musics;
std::map<std::string, std::size_t> MusicIndex; std::unordered_map<std::string, std::size_t> MusicIndex;
struct Situation { sf::Music* situation[SITUATION_COUNT]; }; struct Situation { sf::Music* situation[SITUATION_COUNT]; };
std::vector<Situation> themes; std::vector<Situation> themes;
std::map<std::string, std::size_t> ThemesIndex; std::unordered_map<std::string, std::size_t> ThemesIndex;
sf::Music* curr_music; // current music piece sf::Music* curr_music; // current music piece
int curr_volume; int curr_volume;

View File

@ -72,7 +72,7 @@ CCourse::CCourse()
} }
CCourse::~CCourse() { CCourse::~CCourse() {
for (std::map<std::string, CCourseList>::iterator i = CourseLists.begin(); i != CourseLists.end(); ++i) for (std::unordered_map<std::string, CCourseList>::iterator i = CourseLists.begin(); i != CourseLists.end(); ++i)
i->second.Free(); i->second.Free();
ResetCourse(); ResetCourse();
} }
@ -385,6 +385,9 @@ void CCourse::LoadItemList() {
else else
NocollArr.emplace_back(xx, FindYCoord(xx, zz), zz, height, diam, ObjTypes[type]); NocollArr.emplace_back(xx, FindYCoord(xx, zz), zz, height, diam, ObjTypes[type]);
} }
std::sort(CollArr.begin(), CollArr.end(), [](const TCollidable& l, const TCollidable& r) -> bool {
return l.tree_type < r.tree_type;
});
} }
// -------------------- LoadObjectMap --------------------------------- // -------------------- LoadObjectMap ---------------------------------
@ -692,7 +695,7 @@ void CCourseList::Free() {
} }
void CCourse::FreeCourseList() { void CCourse::FreeCourseList() {
for (std::map<std::string, CCourseList>::iterator i = CourseLists.begin(); i != CourseLists.end(); ++i) for (std::unordered_map<std::string, CCourseList>::iterator i = CourseLists.begin(); i != CourseLists.end(); ++i)
i->second.Free(); i->second.Free();
} }
@ -714,7 +717,7 @@ bool CCourse::LoadCourseList() {
} }
CCourseList* CCourse::getGroup(std::size_t index) { CCourseList* CCourse::getGroup(std::size_t index) {
std::map<std::string, CCourseList>::iterator i = CourseLists.begin(); std::unordered_map<std::string, CCourseList>::iterator i = CourseLists.begin();
std::advance(i, index); std::advance(i, index);
return &i->second; return &i->second;
} }

View File

@ -21,7 +21,7 @@ GNU General Public License for more details.
#include "bh.h" #include "bh.h"
#include "mathlib.h" #include "mathlib.h"
#include <vector> #include <vector>
#include <map> #include <unordered_map>
#define FLOATVAL(i) (*(GLfloat*)(vnc_array+idx+(i)*sizeof(GLfloat))) #define FLOATVAL(i) (*(GLfloat*)(vnc_array+idx+(i)*sizeof(GLfloat)))
#define BYTEVAL(i) (*(GLubyte*)(vnc_array+idx+8*sizeof(GLfloat) + i*sizeof(GLubyte))) #define BYTEVAL(i) (*(GLubyte*)(vnc_array+idx+8*sizeof(GLfloat) + i*sizeof(GLubyte)))
@ -121,7 +121,7 @@ struct CourseFields {
class CCourseList { class CCourseList {
std::vector<TCourse> courses; std::vector<TCourse> courses;
std::map<std::string, std::size_t> index; std::unordered_map<std::string, std::size_t> index;
public: public:
std::string name; std::string name;
@ -137,7 +137,7 @@ public:
class CCourse { class CCourse {
private: private:
const TCourse* curr_course; const TCourse* curr_course;
std::map<std::string, std::size_t> ObjectIndex; std::unordered_map<std::string, std::size_t> ObjectIndex;
std::string CourseDir; std::string CourseDir;
unsigned int nx; unsigned int nx;
@ -161,7 +161,7 @@ public:
CCourse(); CCourse();
~CCourse(); ~CCourse();
std::map<std::string, CCourseList> CourseLists; std::unordered_map<std::string, CCourseList> CourseLists;
CCourseList* currentCourseList; CCourseList* currentCourseList;
std::vector<TTerrType> TerrList; std::vector<TTerrType> TerrList;
std::vector<TObjectType> ObjTypes; std::vector<TObjectType> ObjTypes;

View File

@ -20,7 +20,7 @@ GNU General Public License for more details.
#include "bh.h" #include "bh.h"
#include <vector> #include <vector>
#include <map> #include <unordered_map>
class TTexture; class TTexture;
@ -61,8 +61,8 @@ private:
TFog fog; TFog fog;
TFog default_fog; TFog default_fog;
std::map<std::string, std::size_t> EnvIndex; std::unordered_map<std::string, std::size_t> EnvIndex;
std::map<std::string, std::size_t> LightIndex; std::unordered_map<std::string, std::size_t> LightIndex;
void ResetSkybox(); void ResetSkybox();
void LoadSkybox(const std::string& EnvDir, bool high_res); void LoadSkybox(const std::string& EnvDir, bool high_res);

View File

@ -21,7 +21,7 @@ GNU General Public License for more details.
#include "bh.h" #include "bh.h"
#include <vector> #include <vector>
#include <map> #include <unordered_map>
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// CFont // CFont
@ -31,7 +31,7 @@ GNU General Public License for more details.
class CFont { class CFont {
private: private:
std::vector<sf::Font*> fonts; std::vector<sf::Font*> fonts;
std::map<std::string, std::size_t> fontindex; std::unordered_map<std::string, std::size_t> fontindex;
int curr_font; int curr_font;
sf::Color curr_col; sf::Color curr_col;

View File

@ -20,7 +20,7 @@ GNU General Public License for more details.
#include "bh.h" #include "bh.h"
#include "keyframe.h" #include "keyframe.h"
#include "spx.h" #include "spx.h"
#include <map> #include <unordered_map>
enum TFrameType { enum TFrameType {
@ -71,9 +71,9 @@ struct TEvent {
class CEvents { class CEvents {
private: private:
std::map<std::string, std::size_t> RaceIndex; std::unordered_map<std::string, std::size_t> RaceIndex;
std::map<std::string, std::size_t> CupIndex; std::unordered_map<std::string, std::size_t> CupIndex;
std::map<std::string, std::size_t> EventIndex; std::unordered_map<std::string, std::size_t> EventIndex;
public: public:
std::vector<TRace> RaceList; std::vector<TRace> RaceList;
std::vector<TCup> CupList; std::vector<TCup> CupList;

View File

@ -591,7 +591,7 @@ bool quadsquare::BoxTest(int x, int z, float size, float miny, float maxy, float
float dx = (std::fabs(x + half - Viewer[0]) - half) * std::fabs(ScaleX); float dx = (std::fabs(x + half - Viewer[0]) - half) * std::fabs(ScaleX);
float dy = std::fabs((miny + maxy) * 0.5f - Viewer[1]) - (maxy - miny) * 0.5f; float dy = std::fabs((miny + maxy) * 0.5f - Viewer[1]) - (maxy - miny) * 0.5f;
float dz = (std::fabs(z + half - Viewer[2]) - half) * std::fabs(ScaleZ); float dz = (std::fabs(z + half - Viewer[2]) - half) * std::fabs(ScaleZ);
float d = std::max(dx, std::max(dy , dz)); float d = std::max(dx, std::max(dy, dz));
if (d < ERROR_MAGNIFICATION_THRESHOLD) { if (d < ERROR_MAGNIFICATION_THRESHOLD) {
error *= ERROR_MAGNIFICATION_AMOUNT; error *= ERROR_MAGNIFICATION_AMOUNT;

View File

@ -89,8 +89,8 @@ const TScoreList* CScore::GetScorelist(const std::string& group, const std::stri
bool CScore::SaveHighScore() const { bool CScore::SaveHighScore() const {
CSPList splist; CSPList splist;
for (std::map<std::string, std::map<std::string, TScoreList>>::const_iterator i = Scorelist.cbegin(); i != Scorelist.cend(); ++i) { for (std::unordered_map<std::string, std::unordered_map<std::string, TScoreList>>::const_iterator i = Scorelist.cbegin(); i != Scorelist.cend(); ++i) {
for (std::map<std::string, TScoreList>::const_iterator j = i->second.cbegin(); j != i->second.cend(); ++j) { for (std::unordered_map<std::string, TScoreList>::const_iterator j = i->second.cbegin(); j != i->second.cend(); ++j) {
const TScoreList *list = &j->second; const TScoreList *list = &j->second;
int num = list->numScores; int num = list->numScores;

View File

@ -20,7 +20,7 @@ GNU General Public License for more details.
#include "bh.h" #include "bh.h"
#include "states.h" #include "states.h"
#include "spx.h" #include "spx.h"
#include <map> #include <unordered_map>
#define MAX_SCORES 8 #define MAX_SCORES 8
@ -43,7 +43,7 @@ struct TScoreList {
class CScore : public State { class CScore : public State {
private: private:
std::map<std::string, std::map<std::string, TScoreList>> Scorelist; std::unordered_map<std::string, std::unordered_map<std::string, TScoreList>> Scorelist;
void Enter(); void Enter();
void Loop(float time_step); void Loop(float time_step);

View File

@ -438,7 +438,7 @@ bool CSPList::Save(const std::string& dir, const std::string& filename) const {
return Save(dir + SEP + filename); return Save(dir + SEP + filename);
} }
void CSPList::MakeIndex(std::map<std::string, std::size_t>& index, const std::string &tag) { void CSPList::MakeIndex(std::unordered_map<std::string, std::size_t>& index, const std::string &tag) {
index.clear(); index.clear();
std::size_t idx = 0; std::size_t idx = 0;

View File

@ -20,7 +20,7 @@ GNU General Public License for more details.
#include "bh.h" #include "bh.h"
#include <string> #include <string>
#include <list> #include <list>
#include <map> #include <unordered_map>
extern const std::string emptyString; extern const std::string emptyString;
extern const std::string errorString; extern const std::string errorString;
@ -108,7 +108,7 @@ public:
bool Save(const std::string &filepath) const; bool Save(const std::string &filepath) const;
bool Save(const std::string& dir, const std::string& filename) const; bool Save(const std::string& dir, const std::string& filename) const;
void MakeIndex(std::map<std::string, std::size_t>& index, const std::string &tag); void MakeIndex(std::unordered_map<std::string, std::size_t>& index, const std::string &tag);
}; };
#endif #endif

View File

@ -87,8 +87,8 @@ void CCamera::Update(float timestep) {
if (pitchdown) RotatePitch(2 * timestep); if (pitchdown) RotatePitch(2 * timestep);
glLoadIdentity(); glLoadIdentity();
glRotatef(-vpitch, 1.0, 0.0 , 0.0); glRotatef(-vpitch, 1.0, 0.0, 0.0);
glRotatef(-vhead, 0.0, 1.0 , 0.0); glRotatef(-vhead, 0.0, 1.0, 0.0);
glTranslatef(-xview, -yview, -zview); glTranslatef(-xview, -yview, -zview);
} }

View File

@ -221,7 +221,7 @@ bool CCharShape::RotateNode(std::size_t node_name, int axis, double angle) {
} }
bool CCharShape::RotateNode(const std::string& node_trivialname, int axis, double angle) { bool CCharShape::RotateNode(const std::string& node_trivialname, int axis, double angle) {
std::map<std::string, std::size_t>::const_iterator i = NodeIndex.find(node_trivialname); std::unordered_map<std::string, std::size_t>::const_iterator i = NodeIndex.find(node_trivialname);
if (i == NodeIndex.end()) return false; if (i == NodeIndex.end()) return false;
return RotateNode(i->second, axis, angle); return RotateNode(i->second, axis, angle);
} }
@ -275,7 +275,7 @@ bool CCharShape::ResetNode(std::size_t node_name) {
} }
bool CCharShape::ResetNode(const std::string& node_trivialname) { bool CCharShape::ResetNode(const std::string& node_trivialname) {
std::map<std::string, std::size_t>::const_iterator i = NodeIndex.find(node_trivialname); std::unordered_map<std::string, std::size_t>::const_iterator i = NodeIndex.find(node_trivialname);
if (i == NodeIndex.end()) return false; if (i == NodeIndex.end()) return false;
return ResetNode(i->second); return ResetNode(i->second);
} }
@ -330,7 +330,7 @@ void CCharShape::Reset() {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
TCharMaterial* CCharShape::GetMaterial(const std::string& mat_name) { TCharMaterial* CCharShape::GetMaterial(const std::string& mat_name) {
std::map<std::string, std::size_t>::const_iterator i = MaterialIndex.find(mat_name); std::unordered_map<std::string, std::size_t>::const_iterator i = MaterialIndex.find(mat_name);
if (i != MaterialIndex.end() && i->second < Materials.size()) { if (i != MaterialIndex.end() && i->second < Materials.size()) {
return &Materials[i->second]; return &Materials[i->second];
} }

View File

@ -20,7 +20,7 @@ GNU General Public License for more details.
#include "bh.h" #include "bh.h"
#include "mathlib.h" #include "mathlib.h"
#include <map> #include <unordered_map>
#include <vector> #include <vector>
#define MAX_ACTIONS 8 #define MAX_ACTIONS 8
@ -75,7 +75,7 @@ private:
std::size_t Index[MAX_CHAR_NODES]; std::size_t Index[MAX_CHAR_NODES];
std::size_t numNodes; std::size_t numNodes;
std::vector<TCharMaterial> Materials; std::vector<TCharMaterial> Materials;
std::map<std::string, std::size_t> MaterialIndex; std::unordered_map<std::string, std::size_t> MaterialIndex;
bool useActions; bool useActions;
bool newActions; bool newActions;
@ -117,7 +117,7 @@ public:
bool useHighlighting; bool useHighlighting;
bool highlighted; bool highlighted;
std::size_t highlight_node; std::size_t highlight_node;
std::map<std::string, std::size_t> NodeIndex; std::unordered_map<std::string, std::size_t> NodeIndex;
// nodes // nodes
bool ResetNode(std::size_t node_name); bool ResetNode(std::size_t node_name);