Refactorizations:

- Check for gl_error automatically (in states)
- Cleaned up some unnecessary includes
- Removed some index maps that offer no performance gain
- Load credit text on demand and unload it when leaving credits menu
- Replaced loadIdentity+multMatrix by loadMatrix

git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/branches/SFML2@487 0420edf4-82e4-42fc-9478-35b55e6d67a3
master
pkeus 2013-11-30 18:02:01 +00:00
parent e2b58a7b9b
commit ff90183305
34 changed files with 34 additions and 122 deletions

View File

@ -46,11 +46,7 @@ Then edit the below functions:
#include "audio.h"
#include "ogl.h"
#include "gui.h"
#include "textures.h"
#include "font.h"
#include "translation.h"
#include "course.h"
#include "game_ctrl.h"
#include "winsys.h"
CGameConfig GameConfig;
@ -92,7 +88,7 @@ void SetConfig () {
Music.SetVolume (param.music_volume);
param.sound_volume = sound_vol->GetValue();
param.perf_level = detail_level->GetValue();
Winsys.SetFonttype ();
FT.SetFontFromSettings();
if (param.language != language->GetValue()) {
param.language = language->GetValue();
Trans.LoadTranslations (param.language);
@ -186,7 +182,6 @@ void CGameConfig::Enter() {
}
void CGameConfig::Loop (double time_step) {
check_gl_error();
ScopedRenderMode rm(GUI);
Winsys.clear();

View File

@ -118,6 +118,8 @@ void CCredits::Motion(int x, int y) {
}
void CCredits::Enter() {
LoadCreditList();
Music.Play (param.credits_music, -1);
y_offset = 0;
moving = true;
@ -147,6 +149,7 @@ void CCredits::Enter() {
void CCredits::Exit() {
delete RT;
RT = NULL;
CreditList.clear();
}
void CCredits::Loop(double time_step) {

View File

@ -201,7 +201,6 @@ int resultlevel (size_t num, size_t numraces) {
}
void CEvent::Loop (double timestep) {
check_gl_error();
ScopedRenderMode rm(GUI);
Winsys.clear();

View File

@ -125,9 +125,6 @@ void CEventSelect::Enter () {
}
void CEventSelect::Loop (double timestep) {
sf::Color col;
check_gl_error();
ScopedRenderMode rm(GUI);
Winsys.clear();

View File

@ -169,6 +169,13 @@ void CFont::SetFont (const string& fontname) {
else curr_fact = 1.0;
}
void CFont::SetFontFromSettings() {
if (param.use_papercut_font > 0)
SetFont("pc20");
else
SetFont("bold");
}
// -------------------- auto ------------------------------------------
int CFont::AutoSizeN (int rel_val) {

View File

@ -60,7 +60,8 @@ public:
void SetProps (const string &fontname, float size);
void SetColor(const sf::Color& col) { curr_col = col; }
void SetSize (float size) { curr_size = size; }
void SetFont (const string& fontname);
void SetFont(const string& fontname);
void SetFontFromSettings();
// auto
int AutoSizeN (int rel_val); // rel_val = relative size, return: autosize

View File

@ -183,7 +183,6 @@ void CGameOver::Loop(double time_step) {
CControl *ctrl = g_game.player->ctrl;
int width = Winsys.resolution.width;
int height = Winsys.resolution.height;
check_gl_error();
ClearRenderContext ();
Env.SetupFog ();

View File

@ -125,7 +125,6 @@ void CGameTypeSelect::Enter () {
}
void CGameTypeSelect::Loop (double time_step) {
check_gl_error();
ScopedRenderMode rm(GUI);
Winsys.clear();

View File

@ -69,7 +69,6 @@ void CHelp::Enter() {
}
void CHelp::Loop(double timestep) {
check_gl_error();
ScopedRenderMode rm(GUI);
Winsys.clear();

View File

@ -66,7 +66,7 @@ static void draw_time() {
if (param.use_papercut_font < 2) {
Tex.DrawNumStr(timestr, 50, 12, 1, colWhite);
Tex.DrawNumStr (hundrstr, 176, 12, 0.7, colWhite);
Tex.DrawNumStr (hundrstr, 170, 12, 0.7, colWhite);
} else {
Winsys.beginSFML();
FT.SetColor (colDYell);

View File

@ -95,7 +95,6 @@ void CIntro::Loop (double time_step) {
CControl *ctrl = g_game.player->ctrl;
int width = Winsys.resolution.width;
int height = Winsys.resolution.height;
check_gl_error();
if (startframe->active) {
startframe->Update (time_step);

View File

@ -44,7 +44,6 @@ void CLoading::Loop(double time_step) {
TCourse *CourseList = &Course.CourseList[0];
string msg = Trans.Text(29) + ' ' + g_game.course->name;
check_gl_error ();
ScopedRenderMode rm(GUI);
Winsys.clear();

View File

@ -82,7 +82,7 @@ int main(int argc, char **argv) {
// theses resources must or should be loaded before splashscreen starts
Tex.LoadTextureList ();
FT.LoadFontlist ();
Winsys.SetFonttype ();
FT.SetFontFromSettings();
Music.LoadMusicList ();
Music.SetVolume (param.music_volume);

View File

@ -113,7 +113,6 @@ void CNewPlayer::Enter() {
void CNewPlayer::Loop(double timestep) {
sf::Color col;
check_gl_error();
ScopedRenderMode rm(GUI);
Winsys.clear();

View File

@ -431,6 +431,10 @@ void glTexCoord2(const TVector2d& vec) {
glTexCoord2d(vec.x, vec.y);
}
void glMultMatrix(const TMatrix<4, 4>& mat) {
glMultMatrixd((const double*)mat.data());
void glLoadMatrix(const TMatrix<4, 4>& mat) {
glLoadMatrixd((const double*) mat.data());
}
void glMultMatrix(const TMatrix<4, 4>& mat) {
glMultMatrixd((const double*) mat.data());
}

View File

@ -79,6 +79,7 @@ void glNormal3(const TVector3d& vec);
void glVertex3(const TVector3d& vec);
void glTexCoord2(const TVector2d& vec);
void glLoadMatrix(const TMatrix<4, 4>& mat);
void glMultMatrix(const TMatrix<4, 4>& mat);

View File

@ -57,8 +57,6 @@ void COglTest::Enter() {
}
void COglTest::Loop(double timestep) {
check_gl_error();
// ------------- 3d scenery ---------------------------------------
ScopedRenderMode rm(TUX);
ClearRenderContext (colDDBackgr);

View File

@ -75,7 +75,6 @@ void CPaused::Loop (double time_step) {
CControl *ctrl = g_game.player->ctrl;
int width = Winsys.resolution.width;
int height = Winsys.resolution.height;
check_gl_error();
ClearRenderContext ();
Env.SetupFog ();

View File

@ -179,7 +179,6 @@ void CRaceSelect::Enter() {
}
void CRaceSelect::Loop(double timestep) {
check_gl_error();
ScopedRenderMode rm(GUI);
Winsys.clear();

View File

@ -343,7 +343,6 @@ void CRacing::Loop (double time_step) {
double ycoord = Course.FindYCoord (ctrl->cpos.x, ctrl->cpos.z);
bool airborne = (bool) (ctrl->cpos.y > (ycoord + JUMP_MAX_START_HEIGHT));
check_gl_error();
ClearRenderContext ();
Env.SetupFog ();
CalcTrickControls (ctrl, time_step, airborne);

View File

@ -122,7 +122,6 @@ void CRegist::Enter() {
}
void CRegist::Loop (double timestep) {
check_gl_error();
ScopedRenderMode rm(GUI);
Winsys.clear();

View File

@ -55,7 +55,6 @@ void CReset::Loop(double time_step) {
static bool tux_visible = true;
static int tux_visible_count = 0;
check_gl_error();
ClearRenderContext ();
Env.SetupFog ();
ctrl->UpdatePlayerPos (EPS);

View File

@ -20,7 +20,6 @@ GNU General Public License for more details.
#include "score.h"
#include "ogl.h"
#include "textures.h"
#include "audio.h"
#include "gui.h"
#include "particles.h"
@ -251,7 +250,6 @@ const string ordinals[10] =
{"1:st", "2:nd", "3:rd", "4:th", "5:th", "6:th", "7:th", "8:th", "9:th", "10:th"};
void CScore::Loop (double timestep) {
check_gl_error();
ScopedRenderMode rm(GUI);
Winsys.clear();

View File

@ -25,10 +25,8 @@ GNU General Public License for more details.
#include "audio.h"
#include "gui.h"
#include "course.h"
#include "tux.h"
#include "env.h"
#include "particles.h"
#include "credits.h"
#include "font.h"
#include "game_ctrl.h"
#include "translation.h"
@ -53,12 +51,10 @@ void CSplashScreen::Keyb(sf::Keyboard::Key key, bool special, bool release, int
void CSplashScreen::Enter() {
Winsys.ShowCursor (!param.ice_cursor);
init_ui_snow ();
Music.Play (param.menu_music, -1);
}
void CSplashScreen::Loop(double timestep) {
check_gl_error();
ScopedRenderMode rm(GUI);
Winsys.clear();
Trans.LoadLanguages ();
@ -81,9 +77,10 @@ void CSplashScreen::Loop(double timestep) {
Winsys.draw(t2);
Winsys.SwapBuffers();
init_ui_snow();
Course.MakeStandardPolyhedrons ();
Sound.LoadSoundList ();
Credits.LoadCreditList ();
Char.LoadCharacterList ();
Course.LoadObjectTypes ();
Course.LoadTerrainTypes ();

View File

@ -22,7 +22,6 @@ GNU General Public License for more details.
#include "states.h"
#include "ogl.h"
#include "winsys.h"
#include <SFML/Window.hpp>
State::Manager State::manager(Winsys);
@ -118,6 +117,8 @@ void State::Manager::PollEvent() {
}
void State::Manager::CallLoopFunction() {
check_gl_error();
g_game.time_step = max(0.0001, timer.getElapsedTime().asSeconds());
timer.restart();
current->Loop(g_game.time_step);

View File

@ -25,7 +25,6 @@ GNU General Public License for more details.
#include "winsys.h"
#include "ogl.h"
#include "gui.h"
#include <SFML/Graphics.hpp>
#include <cctype>
@ -204,8 +203,6 @@ void CTexture::LoadTextureList () {
if (id >= 0) {
CommonTex[id] = new TTexture();
CommonTex[id]->Load(param.tex_dir, texfile, rep);
Index[name] = CommonTex[id];
} else Message ("wrong texture id in textures.lst");
}
} else Message ("failed to load common textures");
@ -216,7 +213,6 @@ void CTexture::FreeTextureList () {
delete CommonTex[i];
}
CommonTex.clear();
Index.clear();
}
TTexture* CTexture::GetTexture (size_t idx) const {
@ -228,25 +224,12 @@ const sf::Texture& CTexture::GetSFTexture(size_t idx) const {
return CommonTex[idx]->texture;
}
TTexture* CTexture::GetTexture (const string& name) const {
return Index.at(name);
}
bool CTexture::BindTex (size_t idx) {
if (idx >= CommonTex.size()) return false;
CommonTex[idx]->Bind();
return true;
}
bool CTexture::BindTex (const string& name) {
try {
Index.at(name)->Bind();
} catch (...) {
return false;
}
return true;
}
// ---------------------------- Draw ----------------------------------
void CTexture::Draw (size_t idx) {
@ -254,37 +237,21 @@ void CTexture::Draw (size_t idx) {
CommonTex[idx]->Draw();
}
void CTexture::Draw (const string& name) {
Index[name]->Draw();
}
void CTexture::Draw (size_t idx, int x, int y, float size) {
if (CommonTex.size() > idx)
CommonTex[idx]->Draw(x, y, size, forientation);
}
void CTexture::Draw (const string& name, int x, int y, float size) {
Index[name]->Draw(x, y, size, forientation);
}
void CTexture::Draw (size_t idx, int x, int y, int width, int height) {
if (CommonTex.size() > idx)
CommonTex[idx]->Draw (x, y, width, height, forientation);
}
void CTexture::Draw (const string& name, int x, int y, int width, int height) {
Index[name]->Draw (x, y, width, height, forientation);
}
void CTexture::DrawFrame(size_t idx, int x, int y, double w, double h, int frame, const sf::Color& col) {
if (CommonTex.size() > idx)
CommonTex[idx]->DrawFrame (x, y, w, h, frame, col);
}
void CTexture::DrawFrame(const string& name, int x, int y, double w, double h, int frame, const sf::Color& col) {
Index[name]->DrawFrame (x, y, w, h, frame, col);
}
void CTexture::SetOrientation (Orientation orientation) {
forientation = orientation;
}
@ -327,7 +294,7 @@ void CTexture::DrawNumChr(char c, int x, int y, int w, int h) {
}
void CTexture::DrawNumStr(const string& s, int x, int y, float size, const sf::Color& col) {
if (!BindTex ("ziff032")) {
if (!BindTex(NUMERIC_FONT)) {
Message ("DrawNumStr: missing texture");
return;
}

View File

@ -20,7 +20,6 @@ GNU General Public License for more details.
#include "bh.h"
#include <vector>
#include <map>
#define TEXLOGO 0
#define SNOW_START 1
@ -87,7 +86,6 @@ public:
class CTexture {
private:
vector<TTexture*> CommonTex;
map<string, TTexture*> Index;
Orientation forientation;
void DrawNumChr(char c, int x, int y, int w, int h);
@ -99,21 +97,13 @@ public:
TTexture* GetTexture(size_t idx) const;
const sf::Texture& GetSFTexture(size_t idx) const;
TTexture* GetTexture (const string& name) const;
bool BindTex (size_t idx);
bool BindTex (const string& name);
void Draw (size_t idx);
void Draw (const string& name);
void Draw (size_t idx, int x, int y, float size);
void Draw (const string& name, int x, int y, float size);
void Draw (size_t idx, int x, int y, int width, int height);
void Draw (const string& name, int x, int y, int width, int height);
void DrawFrame(size_t idx, int x, int y, double w, double h, int frame, const sf::Color& col);
void DrawFrame(const string& name, int x, int y, double w, double h, int frame, const sf::Color& col);
void SetOrientation (Orientation orientation);
void DrawNumStr(const string& s, int x, int y, float size, const sf::Color& col);

View File

@ -326,7 +326,6 @@ void DrawActionFloat (size_t nr, const string& s, int y, float f) {
void RenderChar (double timestep) {
if (!must_render) return;
bool is_visible = false;
check_gl_error();
// ------------- 3d scenery ---------------------------------------
ScopedRenderMode rm1(TUX);

View File

@ -227,7 +227,6 @@ void PrintFrameParams (int ytop, TKeyframe *frame) {
void RenderSingleFrame (double timestep) {
if (!must_render) return;
check_gl_error ();
// ------------------ 3d scenery ----------------------------------
ScopedRenderMode rm1(TUX);
@ -307,7 +306,6 @@ void SequenceMouse (int button, int state, int x, int y) {}
void SequenceMotion (int x, int y) {}
void RenderSequence (double timestep) {
check_gl_error();
ScopedRenderMode rm(TUX);
ClearRenderContext (colDDBackgr);

View File

@ -175,27 +175,18 @@ void CTranslation::LoadLanguages () {
const string& line = list.Line(i-1);
languages[i].lang = SPStrN (line, "lang", "en_GB");
languages[i].language = UnicodeStr(SPStrN(line, "language", "English").c_str());
LangIndex[languages[i].lang] = i;
}
if (param.language == string::npos)
param.language = GetSystemDefaultLangIdx();
}
size_t CTranslation::GetLangIdx (const string& lang) const {
return LangIndex.at(lang);
}
const sf::String& CTranslation::GetLanguage (size_t idx) const {
static const sf::String error = "error";
if (idx >= languages.size()) return error;
return languages[idx].language;
}
const sf::String& CTranslation::GetLanguage(const string& lang) const {
return GetLanguage (GetLangIdx (lang));
}
void CTranslation::LoadTranslations (size_t langidx) {
SetDefaultTranslations ();
if (langidx == 0 || langidx >= languages.size()) return;
@ -232,9 +223,9 @@ string CTranslation::GetSystemDefaultLang() {
}
size_t CTranslation::GetSystemDefaultLangIdx() const {
try {
return GetLangIdx(GetSystemDefaultLang());
} catch (...) {
return 0;
}
std::string name = GetSystemDefaultLang();
for (size_t i = 0; i < languages.size(); i++)
if (languages[i].lang == name)
return i;
return 0;
}

View File

@ -24,7 +24,6 @@ An name convention:
#define TRANSLATION_H
#include "bh.h"
#include <map>
#include <vector>
#define MAX_LANGUAGES 32
@ -40,14 +39,11 @@ struct TLang {
class CTranslation {
private:
sf::String texts[NUM_COMMON_TEXTS];
map<string, size_t> LangIndex;
public:
vector<TLang> languages;
void LoadLanguages ();
size_t GetLangIdx (const string& lang) const;
const sf::String& GetLanguage(size_t idx) const;
const sf::String& GetLanguage(const string& lang) const;
void SetDefaultTranslations ();
const sf::String& Text(size_t idx) const;
void LoadTranslations (size_t langidx);

View File

@ -152,8 +152,7 @@ void setup_view_matrix (CControl *ctrl, bool save_mat) {
if (save_mat) {
stationary_matrix = view_mat;
}
glLoadIdentity();
glMultMatrix(view_mat);
glLoadMatrix(view_mat);
}
TVector3d MakeViewVector () {
@ -168,8 +167,7 @@ TVector3d MakeViewVector () {
void update_view (CControl *ctrl, double dt) {
if (is_stationary) {
glLoadIdentity();
glMultMatrix(stationary_matrix);
glLoadMatrix(stationary_matrix);
return;
}

View File

@ -20,15 +20,8 @@ GNU General Public License for more details.
#endif
#include "winsys.h"
#include "ogl.h"
#include "audio.h"
#include "game_ctrl.h"
#include "font.h"
#include "score.h"
#include "textures.h"
#include "spx.h"
#include "course.h"
#include <SFML/Window.hpp>
#include <iostream>
#define USE_JOYSTICK true
@ -129,18 +122,9 @@ void CWinsys::KeyRepeat (bool repeat) {
window.setKeyRepeatEnabled(repeat);
}
void CWinsys::SetFonttype () {
if (param.use_papercut_font > 0) {
FT.SetFont ("pc20");
} else {
FT.SetFont ("bold");
}
}
void CWinsys::Quit () {
Score.SaveHighScore ();
SaveMessages ();
FT.Clear ();
if (g_game.argument < 1) Players.SavePlayers ();
window.close();
}

View File

@ -54,7 +54,6 @@ public:
void SetupVideoMode (size_t idx);
void SetupVideoMode (int width, int height);
void KeyRepeat (bool repeat);
void SetFonttype ();
void PrintJoystickInfo () const;
void ShowCursor(bool visible) { window.setMouseCursorVisible(visible); }
void SwapBuffers() { window.display(); }