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>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<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>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<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>
@ -147,6 +149,7 @@
<DisableSpecificWarnings>4100;4512</DisableSpecificWarnings>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<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>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<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 <vector>
#include <map>
#include <unordered_map>
// --------------------------------------------------------------------
// class CSound
@ -31,7 +31,7 @@ struct TSound;
class CSound {
private:
std::vector<TSound*> sounds;
std::map<std::string, std::size_t> SoundIndex;
std::unordered_map<std::string, std::size_t> SoundIndex;
public:
~CSound();
bool LoadChunk(const std::string& name, const std::string& filename);
@ -71,11 +71,11 @@ class Music;
class CMusic {
private:
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]; };
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
int curr_volume;

View File

@ -72,7 +72,7 @@ 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();
ResetCourse();
}
@ -385,6 +385,9 @@ void CCourse::LoadItemList() {
else
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 ---------------------------------
@ -692,7 +695,7 @@ void CCourseList::Free() {
}
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();
}
@ -714,7 +717,7 @@ bool CCourse::LoadCourseList() {
}
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);
return &i->second;
}

View File

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

View File

@ -20,7 +20,7 @@ GNU General Public License for more details.
#include "bh.h"
#include <vector>
#include <map>
#include <unordered_map>
class TTexture;
@ -61,8 +61,8 @@ private:
TFog fog;
TFog default_fog;
std::map<std::string, std::size_t> EnvIndex;
std::map<std::string, std::size_t> LightIndex;
std::unordered_map<std::string, std::size_t> EnvIndex;
std::unordered_map<std::string, std::size_t> LightIndex;
void ResetSkybox();
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 <vector>
#include <map>
#include <unordered_map>
// --------------------------------------------------------------------
// CFont
@ -31,7 +31,7 @@ GNU General Public License for more details.
class CFont {
private:
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;
sf::Color curr_col;

View File

@ -20,7 +20,7 @@ GNU General Public License for more details.
#include "bh.h"
#include "keyframe.h"
#include "spx.h"
#include <map>
#include <unordered_map>
enum TFrameType {
@ -71,9 +71,9 @@ struct TEvent {
class CEvents {
private:
std::map<std::string, std::size_t> RaceIndex;
std::map<std::string, std::size_t> CupIndex;
std::map<std::string, std::size_t> EventIndex;
std::unordered_map<std::string, std::size_t> RaceIndex;
std::unordered_map<std::string, std::size_t> CupIndex;
std::unordered_map<std::string, std::size_t> EventIndex;
public:
std::vector<TRace> RaceList;
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 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 d = std::max(dx, std::max(dy , dz));
float d = std::max(dx, std::max(dy, dz));
if (d < ERROR_MAGNIFICATION_THRESHOLD) {
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 {
CSPList splist;
for (std::map<std::string, std::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, std::unordered_map<std::string, TScoreList>>::const_iterator i = Scorelist.cbegin(); i != Scorelist.cend(); ++i) {
for (std::unordered_map<std::string, TScoreList>::const_iterator j = i->second.cbegin(); j != i->second.cend(); ++j) {
const TScoreList *list = &j->second;
int num = list->numScores;

View File

@ -20,7 +20,7 @@ GNU General Public License for more details.
#include "bh.h"
#include "states.h"
#include "spx.h"
#include <map>
#include <unordered_map>
#define MAX_SCORES 8
@ -43,7 +43,7 @@ struct TScoreList {
class CScore : public State {
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 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);
}
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();
std::size_t idx = 0;

View File

@ -20,7 +20,7 @@ GNU General Public License for more details.
#include "bh.h"
#include <string>
#include <list>
#include <map>
#include <unordered_map>
extern const std::string emptyString;
extern const std::string errorString;
@ -108,7 +108,7 @@ public:
bool Save(const std::string &filepath) 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

View File

@ -87,8 +87,8 @@ void CCamera::Update(float timestep) {
if (pitchdown) RotatePitch(2 * timestep);
glLoadIdentity();
glRotatef(-vpitch, 1.0, 0.0 , 0.0);
glRotatef(-vhead, 0.0, 1.0 , 0.0);
glRotatef(-vpitch, 1.0, 0.0, 0.0);
glRotatef(-vhead, 0.0, 1.0, 0.0);
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) {
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;
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) {
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;
return ResetNode(i->second);
}
@ -330,7 +330,7 @@ void CCharShape::Reset() {
// --------------------------------------------------------------------
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()) {
return &Materials[i->second];
}

View File

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