Various small Optimizations:
- Use final specifier - Use STL reserve() function more often - Replace forward_list by vector for storing credits entries git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/trunk@731 0420edf4-82e4-42fc-9478-35b55e6d67a3master
parent
44017fd910
commit
68f971fccc
|
@ -66,6 +66,8 @@ bool CSound::LoadChunk(const std::string& name, const std::string& filename) {
|
|||
void CSound::LoadSoundList() {
|
||||
CSPList list;
|
||||
if (list.Load(param.sounds_dir, "sounds.lst")) {
|
||||
sounds.reserve(list.size());
|
||||
SoundIndex.reserve(list.size());
|
||||
for (CSPList::const_iterator line = list.cbegin(); line != list.cend(); ++line) {
|
||||
std::string name = SPStrN(*line, "name");
|
||||
std::string soundfile = SPStrN(*line, "file");
|
||||
|
@ -172,6 +174,7 @@ void CMusic::LoadMusicList() {
|
|||
CSPList list;
|
||||
if (list.Load(param.music_dir, "music.lst")) {
|
||||
musics.reserve(list.size());
|
||||
MusicIndex.reserve(list.size());
|
||||
for (CSPList::const_iterator line = list.cbegin(); line != list.cend(); ++line) {
|
||||
std::string name = SPStrN(*line, "name");
|
||||
std::string musicfile = SPStrN(*line, "file");
|
||||
|
@ -188,6 +191,7 @@ void CMusic::LoadMusicList() {
|
|||
ThemesIndex.clear();
|
||||
if (list.Load(param.music_dir, "racing_themes.lst")) {
|
||||
themes.resize(list.size());
|
||||
ThemesIndex.reserve(list.size());
|
||||
std::size_t i = 0;
|
||||
for (CSPList::const_iterator line = list.cbegin(); line != list.cend(); ++line, i++) {
|
||||
std::string name = SPStrN(*line, "name");
|
||||
|
|
|
@ -20,7 +20,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CGameConfig : public State {
|
||||
class CGameConfig final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
|
|
|
@ -50,12 +50,12 @@ void CCredits::LoadCreditList() {
|
|||
return;
|
||||
}
|
||||
|
||||
std::forward_list<TCredits>::iterator last = CreditList.before_begin();
|
||||
int old_offs = 0;
|
||||
CreditList.reserve(list.size());
|
||||
for (CSPList::const_iterator line = list.cbegin(); line != list.cend(); ++line) {
|
||||
int old_offs = (last != CreditList.before_begin()) ? last->offs : 0;
|
||||
last = CreditList.emplace_after(last);
|
||||
TCredits& credit = *last;
|
||||
credit.text = SPStrN(*line, "text");
|
||||
TCredits& credit = CreditList.emplace_back();
|
||||
std::string temp = SPStrN(*line, "text");
|
||||
credit.text = sf::String::fromUtf8(temp.cbegin(), temp.cend());
|
||||
|
||||
int offset = SPFloatN(*line, "offs", 0) * OFFS_SCALE_FACTOR * Winsys.scale;
|
||||
if (line != list.cbegin()) credit.offs = old_offs + offset;
|
||||
|
@ -63,6 +63,8 @@ void CCredits::LoadCreditList() {
|
|||
|
||||
credit.col = SPIntN(*line, "col", 0);
|
||||
credit.size = SPFloatN(*line, "size", 1.f);
|
||||
|
||||
old_offs = credit.offs;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +76,7 @@ void CCredits::DrawCreditsText(float time_step) {
|
|||
sf::Text text;
|
||||
text.setFont(FT.getCurrentFont());
|
||||
RT->clear(colTBackr);
|
||||
for (std::forward_list<TCredits>::const_iterator i = CreditList.begin(); i != CreditList.end(); ++i) {
|
||||
for (std::vector<TCredits>::const_iterator i = CreditList.begin(); i != CreditList.end(); ++i) {
|
||||
offs = h - TOP_Y - y_offset + i->offs;
|
||||
if (offs > h || offs < -100.f) // Draw only visible lines
|
||||
continue;
|
||||
|
|
|
@ -19,18 +19,18 @@ GNU General Public License for more details.
|
|||
|
||||
#include "bh.h"
|
||||
#include "states.h"
|
||||
#include <forward_list>
|
||||
#include <vector>
|
||||
|
||||
struct TCredits {
|
||||
std::string text;
|
||||
sf::String text;
|
||||
float size;
|
||||
int offs;
|
||||
int font;
|
||||
int col;
|
||||
};
|
||||
|
||||
class CCredits : public State {
|
||||
std::forward_list<TCredits> CreditList;
|
||||
class CCredits final : public State {
|
||||
std::vector<TCredits> CreditList;
|
||||
|
||||
void DrawCreditsText(float time_step);
|
||||
void Enter();
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CEvent : public State {
|
||||
class CEvent final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CEventSelect : public State {
|
||||
class CEventSelect final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
|
|
|
@ -131,6 +131,7 @@ bool CFont::LoadFontlist() {
|
|||
}
|
||||
|
||||
fonts.reserve(list.size());
|
||||
fontindex.reserve(list.size());
|
||||
for (CSPList::const_iterator line = list.cbegin(); line != list.cend(); ++line) {
|
||||
std::string fontfile = SPStrN(*line, "file");
|
||||
std::string name = SPStrN(*line, "name");
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CGameOver : public State {
|
||||
class CGameOver final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CGameTypeSelect : public State {
|
||||
class CGameTypeSelect final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
|
|
16
src/gui.h
16
src/gui.h
|
@ -69,7 +69,7 @@ public:
|
|||
bool GetInteractive() const { return interactive; }
|
||||
};
|
||||
|
||||
class TLabel : public TWidget {
|
||||
class TLabel final : public TWidget {
|
||||
sf::Text text;
|
||||
public:
|
||||
TLabel(const sf::String& string, int x, int y, const sf::Color& color);
|
||||
|
@ -79,7 +79,7 @@ public:
|
|||
};
|
||||
TLabel* AddLabel(const sf::String& string, int x, int y, const sf::Color& color);
|
||||
|
||||
class TFramedText : public TWidget {
|
||||
class TFramedText final : public TWidget {
|
||||
sf::RectangleShape frame;
|
||||
sf::Text text;
|
||||
bool borderFocus;
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
};
|
||||
TFramedText* AddFramedText(int x, int y, int width, int height, int line, const sf::Color& backcol, const sf::String& text, unsigned int ftsize, bool borderFocus = false);
|
||||
|
||||
class TTextButton : public TWidget {
|
||||
class TTextButton final : public TWidget {
|
||||
sf::Text text;
|
||||
public:
|
||||
TTextButton(int x, int y, const sf::String& text_, int ftsize);
|
||||
|
@ -102,7 +102,7 @@ public:
|
|||
TTextButton* AddTextButton(const sf::String& text, int x, int y, int ftsize);
|
||||
TTextButton* AddTextButtonN(const sf::String& text, int x, int y, int rel_ftsize);
|
||||
|
||||
class TTextField : public TWidget {
|
||||
class TTextField final : public TWidget {
|
||||
sf::Text text;
|
||||
sf::RectangleShape frame;
|
||||
sf::RectangleShape cursorShape;
|
||||
|
@ -124,7 +124,7 @@ public:
|
|||
};
|
||||
TTextField* AddTextField(const sf::String& text, int x, int y, int width, int height);
|
||||
|
||||
class TCheckbox : public TWidget {
|
||||
class TCheckbox final : public TWidget {
|
||||
sf::Text text;
|
||||
sf::Sprite back, checkmark;
|
||||
public:
|
||||
|
@ -140,7 +140,7 @@ public:
|
|||
};
|
||||
TCheckbox* AddCheckbox(int x, int y, int width, const sf::String& tag);
|
||||
|
||||
class TIconButton : public TWidget {
|
||||
class TIconButton final : public TWidget {
|
||||
sf::Sprite sprite;
|
||||
sf::RectangleShape frame;
|
||||
float size;
|
||||
|
@ -157,7 +157,7 @@ public:
|
|||
};
|
||||
TIconButton* AddIconButton(int x, int y, const sf::Texture& texture, float size, int maximum, int value);
|
||||
|
||||
class TArrow : public TWidget {
|
||||
class TArrow final : public TWidget {
|
||||
sf::Sprite sprite;
|
||||
bool down;
|
||||
void SetTexture();
|
||||
|
@ -169,7 +169,7 @@ public:
|
|||
};
|
||||
TArrow* AddArrow(int x, int y, bool down);
|
||||
|
||||
class TUpDown : public TWidget {
|
||||
class TUpDown final : public TWidget {
|
||||
TArrow up;
|
||||
TArrow down;
|
||||
TArrow& higher;
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CHelp : public State {
|
||||
class CHelp final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CIntro : public State {
|
||||
class CIntro final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#ifndef LOADING_H
|
||||
#define LOADING_H
|
||||
|
||||
class CLoading : public State {
|
||||
class CLoading final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
public:
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CNewPlayer : public State {
|
||||
class CNewPlayer final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class COglTest : public State {
|
||||
class COglTest final : public State {
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
public:
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CPaused : public State {
|
||||
class CPaused final : public State {
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CRaceSelect : public State {
|
||||
class CRaceSelect final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CRacing : public State {
|
||||
class CRacing final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CRegist : public State {
|
||||
class CRegist final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CReset : public State {
|
||||
class CReset final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
public:
|
||||
|
|
|
@ -41,7 +41,7 @@ struct TScoreList {
|
|||
TScoreList() : numScores(0) {}
|
||||
};
|
||||
|
||||
class CScore : public State {
|
||||
class CScore final : public State {
|
||||
private:
|
||||
std::unordered_map<std::string, std::unordered_map<std::string, TScoreList>> Scorelist;
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "states.h"
|
||||
|
||||
class CSplashScreen : public State {
|
||||
class CSplashScreen final : public State {
|
||||
void Enter();
|
||||
void Loop(float time_step);
|
||||
public:
|
||||
|
|
|
@ -444,6 +444,7 @@ bool CSPList::Save(const std::string& dir, const std::string& filename) const {
|
|||
|
||||
void CSPList::MakeIndex(std::unordered_map<std::string, std::size_t>& index, const std::string &tag) {
|
||||
index.clear();
|
||||
index.reserve(size());
|
||||
std::size_t idx = 0;
|
||||
|
||||
for (const_iterator line = cbegin(); line != cend(); ++line) {
|
||||
|
|
|
@ -86,7 +86,7 @@ void ReloadToolCharacter();
|
|||
void DrawChanged();
|
||||
|
||||
|
||||
class CTools : public State {
|
||||
class CTools final : public State {
|
||||
void Loop(float time_step);
|
||||
void Keyb(sf::Keyboard::Key key, bool release, int x, int y);
|
||||
void Mouse(int button, int state, int x, int y);
|
||||
|
|
Loading…
Reference in New Issue