Merged revision(s) 515 from branches/SFML2:

Refactorizations:
- Reduced time spend in set_material(), reduced calls in track_marks.cpp
- Uniformized some more double/float usage
- Prefer copy_n over memcpy, fill_n over memset
........

Merged revision(s) 518 from branches/SFML2:
Bugfixes:
- Slightly improved error handling (not fully merged from branches/SFML2)
- Fixed Credits GUI broken in r492
- Updated some copyright dates to 2014

Refactorizations:
- Fixed some warnings
- Avoid copying TScore objects
- Small simplifications
........

Fixed mistake in previous merge commit.

git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/trunk@520 0420edf4-82e4-42fc-9478-35b55e6d67a3
master
pkeus 2014-07-13 15:48:20 +00:00
parent 6d5872cb2b
commit 2cb8155816
37 changed files with 256 additions and 255 deletions

View File

@ -42,7 +42,7 @@
*[offs] 30 [text] Translators up to version 0.6.0 unknown [font] 0 [size] 3 [col] 0
*[offs] 50 [text] Copyright © 1999 - 2000 Jasmin F. Patry[font] 0 [size] 3 [col] 0
*[offs] 25 [text] Copyright © 2011-2013 The Extreme Tux Racer Team[font] 0 [size] 3 [col] 0
*[offs] 25 [text] Copyright © 2011-2014 The Extreme Tux Racer Team[font] 0 [size] 3 [col] 0
*[offs] 40 [text] on the web at: http://extremetuxracer.sourceforge.net [font] 0 [size] 3 [col] 0
*[offs] 30 [text] Use of the name "Extreme Tux Racer" is granted to any forks or continuations. [font] 0 [size] 2 [col] 0
*[offs] 50 [text] ----------------------- [font] 0 [size] 3 [col] 0

View File

@ -171,7 +171,7 @@ void CGameConfig::Enter() {
int siz = FT.AutoSizeN(5);
textbuttons[0] = AddTextButton(Trans.Text(28), area.left+50, AutoYPosN(80), siz);
double len = FT.GetTextWidth(Trans.Text(8));
float len = FT.GetTextWidth(Trans.Text(8));
textbuttons[1] = AddTextButton(Trans.Text(15), area.right-len-50, AutoYPosN(80), siz);
Music.Play(param.config_music, -1);

View File

@ -54,22 +54,15 @@ CCourse::~CCourse() {
double CCourse::GetBaseHeight(double distance) const {
double slope = tan(ANGLES_TO_RADIANS(curr_course->angle));
double base_height;
base_height = -slope * distance -
base_height_value / 255.0 * curr_course->scale;
return base_height;
return -slope * distance -
base_height_value / 255.0 * curr_course->scale;
}
double CCourse::GetMaxHeight(double distance) const {
return GetBaseHeight(distance) + curr_course->scale;
}
void CCourse::GetDivisions(int *x, int *y) const {
*x = nx;
*y = ny;
}
const TPolyhedron& CCourse::GetPoly(size_t type) const {
return PolyArr[ObjTypes[type].poly];
}
@ -338,6 +331,7 @@ bool CCourse::LoadElevMap() {
return false;
}
// Get size of course from elevation map
nx = img.nx;
ny = img.ny;
try {
@ -366,6 +360,11 @@ bool CCourse::LoadElevMap() {
// ====================================================================
void CCourse::LoadItemList() {
if (ObjTypes.empty()) {
Message("No object types loaded.");
return;
}
CSPList list(16000);
if (!list.Load(CourseDir, "items.lst")) {
@ -588,8 +587,8 @@ bool CCourse::LoadTerrainTypes() {
TerrList[i].tracktex = SPIntN(*line, "tracktex", -1);
TerrList[i].stoptex = SPIntN(*line, "stoptex", -1);
TerrList[i].col = SPColor3N(*line, "col", TColor3(1, 1, 1));
TerrList[i].friction = SPFloatN(*line, "friction", 0.5);
TerrList[i].depth = SPFloatN(*line, "depth", 0.01);
TerrList[i].friction = SPFloatN(*line, "friction", 0.5f);
TerrList[i].depth = SPFloatN(*line, "depth", 0.01f);
TerrList[i].particles = SPBoolN(*line, "part", false);
TerrList[i].trackmarks = SPBoolN(*line, "trackmarks", false);
TerrList[i].texture = NULL;
@ -913,8 +912,6 @@ void CCourse::FindBarycentricCoords(double x, double z, TVector2i *idx0,
ELEV((_x),(_y)), -(double)(_y)/(ny-1.)*curr_course->size.y )
TVector3d CCourse::FindCourseNormal(double x, double z) const {
double *elevation = Course.elevation;
int x0, x1, y0, y1;
GetIndicesForPoint(x, z, &x0, &y0, &x1, &y1);
@ -951,7 +948,6 @@ double CCourse::FindYCoord(double x, double z) const {
static bool cache_full = false;
if (cache_full && last_x == x && last_z == z) return last_y;
double *elevation = Course.elevation;
TVector2i idx0, idx1, idx2;
double u, v;

View File

@ -169,7 +169,6 @@ public:
const TVector2d& GetDimensions() const { return curr_course->size; }
const TVector2d& GetPlayDimensions() const { return curr_course->play_size; }
void GetDivisions(int *nx, int *ny) const;
double GetCourseAngle() const { return curr_course->angle; }
double GetBaseHeight(double distance) const;
double GetMaxHeight(double distance) const;

View File

@ -57,7 +57,6 @@ void RenderCourse() {
// --------------------------------------------------------------------
void DrawTrees() {
size_t tree_type = -1;
TObjectType* object_types = &Course.ObjTypes[0];
const CControl* ctrl = g_game.player->ctrl;
ScopedRenderMode rm(TREES);
@ -77,7 +76,7 @@ void DrawTrees() {
if (Course.CollArr[i].tree_type != tree_type) {
tree_type = Course.CollArr[i].tree_type;
object_types[tree_type].texture->Bind();
Course.ObjTypes[tree_type].texture->Bind();
}
glPushMatrix();

View File

@ -31,12 +31,12 @@ GNU General Public License for more details.
#define TOP_Y 160
#define BOTT_Y 64
#define OFFS_SCALE_FACTOR 1.2
#define OFFS_SCALE_FACTOR 1.2f
CCredits Credits;
static double y_offset = 0;
static float y_offset = 0;
static bool moving = true;
void CCredits::LoadCreditList() {
@ -48,29 +48,30 @@ void CCredits::LoadCreditList() {
}
for (CSPList::const_iterator line = list.cbegin(); line != list.cend(); ++line) {
int old_offs = CreditList.back().offs;
CreditList.emplace_back();
TCredits& credit = CreditList.back();
credit.text = SPStrN(*line, "text");
double offset = SPFloatN(*line, "offs", 0) * OFFS_SCALE_FACTOR * Winsys.scale;
if (line != list.cbegin()) credit.offs = CreditList.back().offs + (int)offset;
float offset = SPFloatN(*line, "offs", 0) * OFFS_SCALE_FACTOR * Winsys.scale;
if (line != list.cbegin()) credit.offs = old_offs + (int)offset;
else credit.offs = offset;
credit.col = SPIntN(*line, "col", 0);
credit.size = SPFloatN(*line, "size", 1.0);
credit.size = SPFloatN(*line, "size", 1.f);
}
}
void CCredits::DrawCreditsText(double time_step) {
int w = Winsys.resolution.width;
int h = Winsys.resolution.height;
double offs = 0.0;
float offs = 0.f;
if (moving) y_offset += time_step * 30;
for (list<TCredits>::const_iterator i = CreditList.begin(); i != CreditList.end(); ++i) {
offs = h - 100 - y_offset + i->offs;
if (offs > h || offs < 0.0) // Draw only visible lines
offs = h - TOP_Y - y_offset + i->offs;
if (offs > h || offs < -100.f) // Draw only visible lines
continue;
if (i->col == 0)

View File

@ -27,7 +27,7 @@ struct TCredits {
string text;
int offs;
int font;
double size;
float size;
int col;
};

View File

@ -160,7 +160,7 @@ void CEvent::Enter() {
ResetGUI();
int siz = FT.AutoSizeN(5);
textbuttons[1] = AddTextButton(Trans.Text(8), area.left + 100, AutoYPosN(80), siz);
double len = FT.GetTextWidth(Trans.Text(13));
float len = FT.GetTextWidth(Trans.Text(13));
textbuttons[0] = AddTextButton(Trans.Text(13), area.right -len - 100, AutoYPosN(80), siz);
textbuttons[2] = AddTextButton(Trans.Text(15), CENTER, AutoYPosN(80), siz);

View File

@ -103,7 +103,7 @@ void CEventSelect::Enter() {
int siz = FT.AutoSizeN(5);
double len = FT.GetTextWidth(Trans.Text(9));
float len = FT.GetTextWidth(Trans.Text(9));
textbuttons[0] = AddTextButton(Trans.Text(9), area.right-len-50, AutoYPosN(70), siz);
textbuttons[1] = AddTextButton(Trans.Text(8), area.left+50, AutoYPosN(70), siz);
SetFocus(textbuttons[1]);

View File

@ -362,7 +362,7 @@ float CFont::GetTextWidth(const wchar_t *text, const string &fontname, float siz
}
float CFont::CenterX(const char *text) const {
return (Winsys.resolution.width - GetTextWidth(text)) / 2.0;
return (Winsys.resolution.width - GetTextWidth(text)) / 2.f;
}
vector<string> CFont::MakeLineList(const char *source, float width) {

View File

@ -161,8 +161,8 @@ void SaveConfigFile() {
AddIntItem(liste, "framerate", (int)param.framerate);
liste.Add();
AddComment(liste, "Level of details [1...3]");
AddComment(liste, "1 = best performance, 3 = best appearance");
AddComment(liste, "Level of details [1...4]");
AddComment(liste, "1 = best performance, 4 = best appearance");
AddIntItem(liste, "detail_level", param.perf_level);
liste.Add();
@ -336,12 +336,11 @@ void InitConfig() {
param.display_fps = false;
param.show_hud = true;
Trans.LoadLanguages();
if (FileExists(param.configfile)) {
Trans.LoadLanguages();
LoadConfigFile();
} else {
SetConfigDefaults();
SaveConfigFile();
Trans.LoadLanguages();
}
}

View File

@ -238,12 +238,12 @@ void CPlayers::AllocControl(size_t player) {
// ----------------------- avatars ------------------------------------
void CPlayers::LoadAvatars() {
bool CPlayers::LoadAvatars() {
CSPList list(MAX_AVATARS);
if (!list.Load(param.player_dir, "avatars.lst")) {
Message("could not load avators.lst");
return;
return false;
}
for (CSPList::const_iterator line = list.cbegin(); line != list.cend(); ++line) {
@ -254,6 +254,7 @@ void CPlayers::LoadAvatars() {
} else
delete texture;
}
return true;
}
TTexture* CPlayers::GetAvatarTexture(size_t avatar) const {
@ -287,12 +288,12 @@ CCharacter::~CCharacter() {
}
}
void CCharacter::LoadCharacterList() {
bool CCharacter::LoadCharacterList() {
CSPList list(MAX_CHARACTERS);
if (!list.Load(param.char_dir, "characters.lst")) {
Message("could not load characters.lst");
return;
return false;
}
CharList.resize(list.size());
@ -314,7 +315,6 @@ void CCharacter::LoadCharacterList() {
// texid = Tex.TexID (NO_PREVIEW);
}
ch->shape = new CCharShape;
if (ch->shape->Load(charpath, "shape.lst", false) == false) {
delete ch->shape;
@ -332,6 +332,7 @@ void CCharacter::LoadCharacterList() {
if (ch->frames[3].loaded == false) ch->finishframesok = false;
}
}
return !CharList.empty();
}
void CCharacter::FreeCharacterPreviews() {

View File

@ -135,7 +135,7 @@ public:
void SavePlayers() const;
void ResetControls();
void AllocControl(size_t player);
void LoadAvatars();
bool LoadAvatars();
size_t numAvatars() const { return avatars.size(); }
size_t numPlayers() const { return plyr.size(); }
@ -166,7 +166,7 @@ public:
~CCharacter();
void LoadCharacterList();
bool LoadCharacterList();
void FreeCharacterPreviews();
};

View File

@ -617,71 +617,72 @@ void SetFocus(TWidget* widget) {
break;
}
}
}
void IncreaseFocus() {
if (focussed >= 0)
Widgets[focussed]->focus = false;
void IncreaseFocus() {
if (focussed >= 0)
Widgets[focussed]->focus = false;
focussed++;
if (focussed >= (int)Widgets.size())
focussed = 0;
int end = focussed;
// Select only active widgets
do {
if (Widgets[focussed]->GetActive())
break;
focussed++;
if (focussed >= (int)Widgets.size())
focussed = 0;
int end = focussed;
// Select only active widgets
do {
if (Widgets[focussed]->GetActive())
break;
} while (end != focussed);
focussed++;
if (focussed >= (int)Widgets.size())
focussed = 0;
} while (end != focussed);
if (focussed >= 0)
Widgets[focussed]->focus = true;
}
void DecreaseFocus() {
if (focussed >= 0)
Widgets[focussed]->focus = false;
if (focussed >= 0)
Widgets[focussed]->focus = true;
}
void DecreaseFocus() {
if (focussed >= 0)
Widgets[focussed]->focus = false;
if (focussed > 0)
focussed--;
else
focussed = (int)Widgets.size()-1;
int end = focussed;
// Select only active widgets
do {
if (Widgets[focussed]->GetActive())
break;
if (focussed > 0)
focussed--;
else
focussed = (int)Widgets.size()-1;
int end = focussed;
// Select only active widgets
do {
if (Widgets[focussed]->GetActive())
break;
} while (end != focussed);
if (focussed > 0)
focussed--;
else
focussed = (int)Widgets.size()-1;
} while (end != focussed);
if (focussed >= 0)
Widgets[focussed]->focus = true;
}
if (focussed >= 0)
Widgets[focussed]->focus = true;
}
void ResetGUI() {
for (size_t i = 0; i < Widgets.size(); i++)
delete Widgets[i];
Widgets.clear();
focussed = 0;
}
void ResetGUI() {
for (size_t i = 0; i < Widgets.size(); i++)
delete Widgets[i];
Widgets.clear();
focussed = 0;
}
// ------------------ new ---------------------------------------------
int AutoYPosN(double percent) {
return Winsys.resolution.height * percent / 100.0;
}
int AutoYPosN(double percent) {
return Winsys.resolution.height * percent / 100.0;
}
TArea AutoAreaN(double top_perc, double bott_perc, int w) {
TArea res;
res.top = AutoYPosN(top_perc);
res.bottom = AutoYPosN(bott_perc);
if (w > Winsys.resolution.width) w = Winsys.resolution.width;
res.left = (Winsys.resolution.width - w) / 2;
res.right = Winsys.resolution.width - res.left;
return res;
}
TArea AutoAreaN(double top_perc, double bott_perc, int w) {
TArea res;
res.top = AutoYPosN(top_perc);
res.bottom = AutoYPosN(bott_perc);
if (w > Winsys.resolution.width) w = Winsys.resolution.width;
res.left = (Winsys.resolution.width - w) / 2;
res.right = Winsys.resolution.width - res.left;
return res;
}

View File

@ -77,10 +77,9 @@ void CIntro::Enter() {
SetStationaryCamera(false);
update_view(ctrl, EPS);
size_t num_items = Course.NocollArr.size();
TItem* item_locs = &Course.NocollArr[0];
for (size_t i = 0; i < num_items; i++) {
if (item_locs[i].collectable != -1) {
item_locs[i].collectable = 1;
if (Course.NocollArr[i].collectable != -1) {
Course.NocollArr[i].collectable = 1;
}
}

View File

@ -29,6 +29,7 @@ GNU General Public License for more details.
#include "tux.h"
#include "game_ctrl.h"
#include "physics.h"
#include <algorithm>
#include <iterator>
static const int numJoints = 19;
@ -328,7 +329,7 @@ void CKeyframe::UpdateTest(double timestep, CCharShape *shape) {
}
void CKeyframe::ResetFrame2(TKeyframe *frame) {
for (int i = 1; i<32; i++) frame->val[i] = 0.0;
std::fill_n(frame->val + 1, MAX_FRAME_VALUES - 1, 0.0);
frame->val[0] = 0.5; // time
}
@ -399,7 +400,7 @@ void CKeyframe::SaveTest(const string& dir, const string& filename) {
void CKeyframe::CopyFrame(size_t prim_idx, size_t sec_idx) {
TKeyframe *ppp = &frames[prim_idx];
TKeyframe *sss = &frames[sec_idx];
memcpy(sss->val, ppp->val, MAX_FRAME_VALUES*sizeof(*sss->val));
std::copy_n(ppp->val, MAX_FRAME_VALUES, sss->val);
}
void CKeyframe::AddFrame() {
@ -426,12 +427,12 @@ void CKeyframe::InsertFrame(size_t idx) {
void CKeyframe::CopyToClipboard(size_t idx) {
if (idx >= frames.size()) return;
memcpy(clipboard.val, frames[idx].val, MAX_FRAME_VALUES*sizeof(*frames[idx].val));
std::copy_n(frames[idx].val, MAX_FRAME_VALUES, clipboard.val);
}
void CKeyframe::PasteFromClipboard(size_t idx) {
if (idx >= frames.size()) return;
memcpy(frames[idx].val, clipboard.val, MAX_FRAME_VALUES*sizeof(*frames[idx].val));
std::copy_n(clipboard.val, MAX_FRAME_VALUES, frames[idx].val);
}
void CKeyframe::ClearFrame(size_t idx) {

View File

@ -71,7 +71,7 @@ void InitGame(int argc, char **argv) {
int main(int argc, char **argv) {
// ****************************************************************
cout << "\n----------- Extreme Tux Racer " ETR_VERSION_STRING " ----------------";
cout << "\n----------- (C) 2010-2013 Extreme Tuxracer Team --------\n\n";
cout << "\n----------- (C) 2010-2014 Extreme Tuxracer Team --------\n\n";
srand(time(NULL));
InitConfig();
@ -84,7 +84,10 @@ int main(int argc, char **argv) {
// PrintGLInfo ();
// theses resources must or should be loaded before splashscreen starts
Tex.LoadTextureList();
if (!Tex.LoadTextureList()) {
Winsys.Quit();
return -1;
}
FT.LoadFontlist();
FT.SetFontFromSettings();
Audio.Open();

View File

@ -365,7 +365,7 @@ bool IntersectPolygon(const TPolygon& p, vector<TVector3d>& v) {
double distsq;
TVector3d nml = MakeNormal(p, &v[0]);
ray.pt = TVector3d(0., 0., 0.);
ray.pt = TVector3d();
ray.vec = nml;
nuDotProd = DotProduct(nml, ray.vec);
@ -519,7 +519,7 @@ double LinearInterp(const double x[], const double y[], double val, int n) {
return m * val + b;
}
double XRandom(float min, float max) {
double XRandom(double min, double max) {
return (double)rand() / RAND_MAX * (max - min) + min;
}

View File

@ -106,7 +106,7 @@ struct TOdeSolver {
int Gauss(double *matrix, int n, double *soln);
double LinearInterp(const double x[], const double y[], double val, int n);
double XRandom(float min, float max);
double XRandom(double min, double max);
double FRandom();
int IRandom(int min, int max);
int ITrunc(int val, int base);

View File

@ -99,7 +99,7 @@ void CNewPlayer::Enter() {
avatar = AddUpDown(area.left + prevwidth + prevoffs + 8, prevtop, 0, (int)Players.numAvatars() - 1, 0, prevwidth - 34);
int siz = FT.AutoSizeN(5);
textbuttons[0] = AddTextButton(Trans.Text(8), area.left+50, AutoYPosN(70), siz);
double len = FT.GetTextWidth(Trans.Text(15));
float len = FT.GetTextWidth(Trans.Text(15));
textbuttons[1] = AddTextButton(Trans.Text(15), area.right-len-50, AutoYPosN(70), siz);
textfield = AddTextField(emptyString, area.left, frametop, framewidth, frameheight);

View File

@ -127,27 +127,30 @@ void PrintGLInfo() {
}
}
void set_material(const TColor& diffuse_colour, const TColor& specular_colour, float specular_exp) {
GLfloat mat_amb_diff[4] = {
static_cast<GLfloat>(diffuse_colour.r),
static_cast<GLfloat>(diffuse_colour.g),
static_cast<GLfloat>(diffuse_colour.b),
static_cast<GLfloat>(diffuse_colour.a)
void set_material_diffuse(const TColor& diffuse_colour) {
GLint mat_amb_diff[4] = {
static_cast<GLint>(diffuse_colour.r * INT_MAX),
static_cast<GLint>(diffuse_colour.g * INT_MAX),
static_cast<GLint>(diffuse_colour.b * INT_MAX),
static_cast<GLint>(diffuse_colour.a * INT_MAX)
};
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff);
GLfloat mat_specular[4] = {
static_cast<GLfloat>(specular_colour.r),
static_cast<GLfloat>(specular_colour.g),
static_cast<GLfloat>(specular_colour.b),
static_cast<GLfloat>(specular_colour.a)
};
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, specular_exp);
glColor(diffuse_colour);
glMaterialiv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff);
}
void set_material(const TColor& diffuse_colour, const TColor& specular_colour, float specular_exp) {
set_material_diffuse(diffuse_colour);
GLint mat_specular[4] = {
static_cast<GLint>(specular_colour.r * INT_MAX),
static_cast<GLint>(specular_colour.g * INT_MAX),
static_cast<GLint>(specular_colour.b * INT_MAX),
static_cast<GLint>(specular_colour.a * INT_MAX)
};
glMaterialiv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, specular_exp);
}
void ClearRenderContext() {
glDepthMask(GL_TRUE);
glClearColor(colBackgr.r, colBackgr.g, colBackgr.b, colBackgr.a);

View File

@ -48,6 +48,7 @@ void check_gl_error();
void InitOpenglExtensions();
void PrintGLInfo();
void set_material_diffuse(const TColor& specular_colour);
void set_material(const TColor& diffuse_colour,
const TColor& specular_colour,
float specular_exp);

View File

@ -148,7 +148,7 @@ void TGuiParticle::Update(double time_step, double push_timestep, const TVector2
void init_ui_snow() {
particles_2d.clear();
for (int i = 0; i < BASE_snowparticles * Winsys.resolution.width; i++)
particles_2d.emplace_back(FRandom(), FRandom());
particles_2d.emplace_back(static_cast<float>(FRandom()), static_cast<float>(FRandom()));
push_position = TVector2d(0.0, 0.0);
}
@ -170,8 +170,8 @@ void update_ui_snow(double time_step) {
p->Update(time_step, push_timestep, push_vector);
}
if (FRandom() < time_step*20.0*(MAX_num_snowparticles - particles_2d.size()) / 1000.0) {
particles_2d.emplace_back(FRandom(), 1);
if (FRandom() < time_step*20.f*(MAX_num_snowparticles - particles_2d.size()) / 1000.f) {
particles_2d.emplace_back(static_cast<float>(FRandom()), 1.f);
}
for (list<TGuiParticle>::iterator p = particles_2d.begin(); p != particles_2d.end();) {
@ -182,7 +182,7 @@ void update_ui_snow(double time_step) {
p->pt.x = FRandom();
p->pt.y = 1 + FRandom()*BASE_VELOCITY;
double p_dist = FRandom();
p->size = PARTICLE_MIN_SIZE + (1.0 - p_dist) * PARTICLE_SIZE_RANGE;
p->size = PARTICLE_MIN_SIZE + (1.f - p_dist) * PARTICLE_SIZE_RANGE;
p->vel.x = 0;
p->vel.y = -BASE_VELOCITY-p_dist*VELOCITY_RANGE;
++p;
@ -409,12 +409,10 @@ double adjust_particle_count(double particles) {
}
void generate_particles(const CControl *ctrl, double dtime, const TVector3d& pos, double speed) {
TTerrType *TerrList = &Course.TerrList[0];
double surf_y = Course.FindYCoord(pos.x, pos.z);
int id = Course.GetTerrainIdx(pos.x, pos.z, 0.5);
if (id >= 0 && TerrList[id].particles && pos.y < surf_y) {
if (id >= 0 && Course.TerrList[id].particles && pos.y < surf_y) {
TVector3d xvec = CrossProduct(ctrl->cdirection, ctrl->plane_nml);
TVector3d right_part_pt = pos + TUX_WIDTH/2.0 * xvec;
@ -497,7 +495,7 @@ void TFlake::Draw(const TPlane& lp, const TPlane& rp, bool rotate_flake, float d
TFlakeArea::TFlakeArea(
int num_flakes,
size_t num_flakes,
float _xrange,
float _ytop,
float _yrange,
@ -525,7 +523,7 @@ void TFlakeArea::Draw(const CControl *ctrl) const {
const TPlane& lp = get_left_clip_plane();
const TPlane& rp = get_right_clip_plane();
float dir_angle(atan(ctrl->viewdir.x / ctrl->viewdir.z) * 180 / 3.14159);
float dir_angle(atan(ctrl->viewdir.x / ctrl->viewdir.z) * 180 / M_PI);
ScopedRenderMode rm(PARTICLES);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
@ -626,8 +624,8 @@ void CFlakes::UpdateAreas(const CControl *ctrl) {
}
}
#define YDRIFT 0.8
#define ZDRIFT 0.6
#define YDRIFT 0.8f
#define ZDRIFT 0.6f
void CFlakes::Init(int grade, const CControl *ctrl) {
Reset();
@ -636,9 +634,9 @@ void CFlakes::Init(int grade, const CControl *ctrl) {
// areas.emplace_back(400, 5, 4, 4, -2, 4, 0.01, 0.02, 5, true);
// areas.emplace_back(400, 12, 5, 8, 2, 8, 0.03, 0.045, 5, false);
// areas.emplace_back(400, 30, 6, 15, 10, 15, 0.06, 0.12, 5, false);
areas.emplace_back(400, 5, 4, 4, -2, 4, 0.015, 0.03, 5, true);
areas.emplace_back(400, 12, 5, 8, 2, 8, 0.045, 0.07, 5, false);
areas.emplace_back(400, 30, 6, 15, 10, 15, 0.09, 0.18, 5, false);
areas.emplace_back(400, 5.f, 4.f, 4.f, -2.f, 4.f, 0.015f, 0.03f, 5.f, true);
areas.emplace_back(400, 12.f, 5.f, 8.f, 2.f, 8.f, 0.045f, 0.07f, 5.f, false);
areas.emplace_back(400, 30.f, 6.f, 15.f, 10.f, 15.f, 0.09f, 0.18f, 5.f, false);
// areas.emplace_back(400, 5, 4, 4, -2, 4, 0.02, 0.04, 5, true);
// areas.emplace_back(400, 12, 5, 8, 2, 8, 0.06, 0.09, 5, false);
// areas.emplace_back(400, 30, 6, 15, 10, 15, 0.15, 0.25, 5, false);
@ -647,9 +645,9 @@ void CFlakes::Init(int grade, const CControl *ctrl) {
// areas.emplace_back(500, 5, 4, 4, -2, 4, 0.02, 0.03, 5, true);
// areas.emplace_back(500, 12, 5, 8, 2, 8, 0.045, 0.07, 5, false);
// areas.emplace_back(500, 30, 6, 15, 10, 15, 0.1, 0.15, 5, false);
areas.emplace_back(500, 5, 4, 4, -2, 4, 0.03, 0.045, 5, true);
areas.emplace_back(500, 12, 5, 8, 2, 8, 0.07, 0.1, 5, false);
areas.emplace_back(500, 30, 6, 15, 10, 15, 0.15, 0.22, 5, false);
areas.emplace_back(500, 5.f, 4.f, 4.f, -2.f, 4.f, 0.03f, 0.045f, 5.f, true);
areas.emplace_back(500, 12.f, 5.f, 8.f, 2.f, 8.f, 0.07f, 0.1f, 5.f, false);
areas.emplace_back(500, 30.f, 6.f, 15.f, 10.f, 15.f, 0.15f, 0.22f, 5.f, false);
// areas.emplace_back(500, 5, 4, 4, -2, 4, 0.04, 0.06, 5, true);
// areas.emplace_back(500, 12, 5, 8, 2, 8, 0.09, 0.15, 5, false);
// areas.emplace_back(500, 30, 6, 15, 10, 15, 0.2, 0.32, 5, false);
@ -658,9 +656,9 @@ void CFlakes::Init(int grade, const CControl *ctrl) {
// areas.emplace_back(1000, 5, 4, 4, -2, 4, 0.025, 0.04, 5, true);
// areas.emplace_back(1000, 12, 5, 9, 2, 8, 0.06, 0.10, 5, false);
// areas.emplace_back(1000, 30, 6, 15, 10, 15, 0.12, 0.2, 5, false);
areas.emplace_back(1000, 5, 4, 4, -2, 4, 0.037, 0.05, 5, true);
areas.emplace_back(1000, 12, 5, 9, 2, 8, 0.09, 0.15, 5, false);
areas.emplace_back(1000, 30, 6, 15, 10, 15, 0.18, 0.35, 5, false);
areas.emplace_back(1000, 5.f, 4.f, 4.f, -2.f, 4.f, 0.037f, 0.05f, 5.f, true);
areas.emplace_back(1000, 12.f, 5.f, 9.f, 2.f, 8.f, 0.09f, 0.15f, 5.f, false);
areas.emplace_back(1000, 30.f, 6.f, 15.f, 10.f, 15.f, 0.18f, 0.35f, 5.f, false);
// areas.emplace_back(800, 5, 4, 4, -2, 4, 0.05, 0.08, 5, true);
// areas.emplace_back(800, 12, 5, 9, 2, 8, 0.12, 0.20, 5, false);
// areas.emplace_back(800, 30, 6, 15, 10, 15, 0.25, 0.5, 5, false);
@ -707,8 +705,8 @@ void CFlakes::Draw(const CControl *ctrl) const {
#define NUM_CHANGES 6
#define CHANGE_DRIFT 15
#define CHANGE_SPEED 0.05
#define CURTAIN_WINDDRIFT 0.35
#define CHANGE_SPEED 0.05f
#define CURTAIN_WINDDRIFT 0.35f
struct TChange {
float min;
@ -763,7 +761,7 @@ TCurtain::TCurtain(int num_rows, float z_dist, float tex_size,
break;
}
angledist = atan(size / 2 / zdist) * 360 / 3.14159;
angledist = atan(size / 2 / zdist) * 360 / M_PI;
numCols = (unsigned int)(-2 * startangle / angledist) + 1;
if (numCols > MAX_CURTAIN_COLS) numCols = MAX_CURTAIN_COLS;
lastangle = startangle + (numCols-1) * angledist;
@ -845,7 +843,7 @@ void TCurtain::Update(float timestep, const TVector3d& drift, const CControl* ct
static CCurtain Curtain;
void TCurtain::CurtainVec(float angle, float zdist, float &x, float &z) {
x = zdist * sin(angle * 3.14159 / 180);
x = zdist * sin(angle * M_PI / 180);
if (angle > 90 || angle < -90) z = sqrt(zdist * zdist - x * x);
else z = -sqrt(zdist * zdist - x * x);
}
@ -893,9 +891,9 @@ void CCurtain::Init(const CControl *ctrl) {
// curtains.emplace_back(3, 60, 10, 3, -100, -10, 1);
// curtains.emplace_back(3, 50, 13, 3, -100, -10, 1);
// curtains.emplace_back(3, 40, 16, 3, -100, -10, 1);
curtains.emplace_back(3, 60, 15, 3, -100, -10, 1);
curtains.emplace_back(3, 50, 19, 3, -100, -10, 1);
curtains.emplace_back(3, 40, 23, 3, -100, -10, 1);
curtains.emplace_back(3, 60.f, 15.f, 3.f, -100.f, -10.f, 1);
curtains.emplace_back(3, 50.f, 19.f, 3.f, -100.f, -10.f, 1);
curtains.emplace_back(3, 40.f, 23.f, 3.f, -100.f, -10.f, 1);
// curtains.emplace_back(3, 60, 20, 3, -100, -10, 1);
// curtains.emplace_back(3, 50, 25, 3, -100, -10, 1);
// curtains.emplace_back(3, 40, 30, 3, -100, -10, 1);
@ -904,9 +902,9 @@ void CCurtain::Init(const CControl *ctrl) {
// curtains.emplace_back(3, 60, 15, 3, -100, -10, 2);
// curtains.emplace_back(3, 50, 17, 3, -100, -10, 2);
// curtains.emplace_back(3, 40, 20, 3, -100, -10, 2);
curtains.emplace_back(3, 60, 22, 3, -100, -10, 2);
curtains.emplace_back(3, 50, 25, 3, -100, -10, 2);
curtains.emplace_back(3, 40, 30, 3, -100, -10, 2);
curtains.emplace_back(3, 60.f, 22.f, 3.f, -100.f, -10.f, 2);
curtains.emplace_back(3, 50.f, 25.f, 3.f, -100.f, -10.f, 2);
curtains.emplace_back(3, 40.f, 30.f, 3.f, -100.f, -10.f, 2);
// curtains.emplace_back(3, 60, 30, 3, -100, -10, 2);
// curtains.emplace_back(3, 50, 35, 3, -100, -10, 2);
// curtains.emplace_back(3, 40, 40, 3, -100, -10, 2);
@ -915,9 +913,9 @@ void CCurtain::Init(const CControl *ctrl) {
// curtains.emplace_back(3, 60, 20, 3, -100, -10, 3);
// curtains.emplace_back(3, 50, 25, 3, -100, -10, 2);
// curtains.emplace_back(3, 40, 30, 3, -100, -10, 2);
curtains.emplace_back(3, 60, 22, 3, -100, -10, 3);
curtains.emplace_back(3, 50, 27, 3, -100, -10, 2);
curtains.emplace_back(3, 40, 32, 3, -100, -10, 2);
curtains.emplace_back(3, 60.f, 22.f, 3.f, -100.f, -10.f, 3);
curtains.emplace_back(3, 50.f, 27.f, 3.f, -100.f, -10.f, 2);
curtains.emplace_back(3, 40.f, 32.f, 3.f, -100.f, -10.f, 2);
// curtains.emplace_back(3, 60, 25, 3, -100, -10, 3);
// curtains.emplace_back(3, 50, 30, 3, -100, -10, 2);
// curtains.emplace_back(3, 40, 35, 3, -100, -10, 2);
@ -932,7 +930,7 @@ void CCurtain::Init(const CControl *ctrl) {
// wind
// --------------------------------------------------------------------
#define UPDATE_TIME 0.04
#define UPDATE_TIME 0.04f
CWind Wind;
@ -1068,7 +1066,7 @@ void CWind::Update(float timestep) {
// the wind needn't be updated in each frame
CurrTime = CurrTime + timestep;
if (CurrTime > UPDATE_TIME) {
CurrTime = 0.0;
CurrTime = 0.f;
if (SpeedMode == 1) { // current speed lesser than destination speed
if (WSpeed < DestSpeed) {
@ -1095,7 +1093,7 @@ void CWind::Update(float timestep) {
if (WAngle > params.maxAngle) WAngle = params.maxAngle;
if (WAngle < params.minAngle) WAngle = params.minAngle;
float xx = sin(WAngle * 3.14159 / 180);
float xx = sin(WAngle * M_PI / 180.f);
float zz = sqrt(1 - xx * xx);
if ((WAngle > 90 && WAngle < 270) || (WAngle > 450 && WAngle < 630)) {
zz = -zz;

View File

@ -75,7 +75,7 @@ struct TFlakeArea {
vector<TFlake> flakes;
TFlakeArea(
int num_flakes,
size_t num_flakes,
float xrange,
float ytop,
float yrange,

View File

@ -177,20 +177,19 @@ void CControl::AdjustTreeCollision(const TVector3d& pos, TVector3d *vel) {
}
void CControl::CheckItemCollection(const TVector3d& pos) {
TItem *items = &Course.NocollArr[0];
size_t num_items = Course.NocollArr.size();
for (size_t i=0; i<num_items; i++) {
if (items[i].collectable != 1) continue;
if (Course.NocollArr[i].collectable != 1) continue;
double diam = items[i].diam;
const TVector3d& loc = items[i].pt;
double diam = Course.NocollArr[i].diam;
const TVector3d& loc = Course.NocollArr[i].pt;
TVector3d distvec(loc.x - pos.x, loc.y - pos.y, loc.z - pos.z);
double squared_dist = (diam / 2. + 0.7);
squared_dist *= squared_dist;
if (MAG_SQD(distvec) <= squared_dist) { // Check collision using a bounding sphere
items[i].collectable = 0;
Course.NocollArr[i].collectable = 0;
g_game.herring += 1;
Sound.Play("pickup1", 0);
Sound.Play("pickup2", 0);
@ -403,11 +402,10 @@ TVector3d CControl::CalcNetForce(const TVector3d& pos, const TVector3d& vel) {
if (surfweights.size() != Course.TerrList.size())
surfweights.resize(Course.TerrList.size());
Course.GetSurfaceType(ff.pos.x, ff.pos.z, &surfweights[0]);
TTerrType *TerrList = &Course.TerrList[0];
ff.frict_coeff = ff.comp_depth = 0;
for (size_t i=0; i<Course.TerrList.size(); i++) {
ff.frict_coeff += surfweights[i] * TerrList[i].friction;
ff.comp_depth += surfweights[i] * TerrList[i].depth;
ff.frict_coeff += surfweights[i] * Course.TerrList[i].friction;
ff.comp_depth += surfweights[i] * Course.TerrList[i].depth;
}
TPlane surfplane = Course.GetLocalCoursePlane(ff.pos);

View File

@ -14,7 +14,7 @@
#include <climits>
#define TERRAIN_ERROR_SCALE 0.1
#define TERRAIN_ERROR_SCALE 0.1f
#define VERTEX_FORCE_THRESHOLD 100
#define ERROR_MAGNIFICATION_THRESHOLD 20
#define ERROR_MAGNIFICATION_AMOUNT 3
@ -80,17 +80,17 @@ quadsquare::quadsquare(quadcornerdata* pcd) {
for (int i = 0; i < 2; i++) SubEnabledCount[i] = 0;
Vertex[0].Y = 0.25 * (pcd->Verts[0].Y
+ pcd->Verts[1].Y + pcd->Verts[2].Y + pcd->Verts[3].Y);
Vertex[1].Y = 0.5 * (pcd->Verts[3].Y + pcd->Verts[0].Y);
Vertex[2].Y = 0.5 * (pcd->Verts[0].Y + pcd->Verts[1].Y);
Vertex[3].Y = 0.5 * (pcd->Verts[1].Y + pcd->Verts[2].Y);
Vertex[4].Y = 0.5 * (pcd->Verts[2].Y + pcd->Verts[3].Y);
Vertex[0].Y = 0.25f * (pcd->Verts[0].Y
+ pcd->Verts[1].Y + pcd->Verts[2].Y + pcd->Verts[3].Y);
Vertex[1].Y = 0.5f * (pcd->Verts[3].Y + pcd->Verts[0].Y);
Vertex[2].Y = 0.5f * (pcd->Verts[0].Y + pcd->Verts[1].Y);
Vertex[3].Y = 0.5f * (pcd->Verts[1].Y + pcd->Verts[2].Y);
Vertex[4].Y = 0.5f * (pcd->Verts[2].Y + pcd->Verts[3].Y);
for (int i = 0; i < 2; i++) Error[i] = 0;
for (int i = 0; i < 4; i++) {
Error[i+2] = fabs((Vertex[0].Y + pcd->Verts[i].Y)
- (Vertex[i+1].Y + Vertex[((i+1)&3) + 1].Y)) * 0.25;
- (Vertex[i+1].Y + Vertex[((i+1)&3) + 1].Y)) * 0.25f;
}
MinY = MaxY = pcd->Verts[0].Y;
@ -153,7 +153,7 @@ float quadsquare::GetHeight(const quadcornerdata &cd, float x, float z) {
if (lx < 0) lz = 0;
if (lz > 1) lz = 1;
float s00, s01, s10, s11;
float s00, s01, s10, s11;
switch (index) {
default:
case 0:
@ -316,8 +316,8 @@ float quadsquare::RecomputeError(const quadcornerdata& cd) {
}
for (int i = 0; i < 4; i++) {
quadcornerdata q;
if (Child[i]) {
quadcornerdata q;
SetupCornerData(&q, cd, i);
Error[i+2] = Child[i]->RecomputeError(q);
@ -330,7 +330,7 @@ float quadsquare::RecomputeError(const quadcornerdata& cd) {
if (Error[i+2] > maxerror) maxerror = Error[i+2];
}
int *terrain_count = new int[numTerr];
size_t *terrain_count = new size_t[numTerr];
memset(terrain_count, 0, sizeof(*terrain_count)*numTerr);
for (int i=cd.xorg; i<=cd.xorg+whole; i++) {
@ -346,8 +346,8 @@ float quadsquare::RecomputeError(const quadcornerdata& cd) {
}
}
int max_count = 0;
int total = 0;
size_t max_count = 0;
size_t total = 0;
for (size_t t=0; t<numTerr; t++) {
if (terrain_count[t] > max_count) {
max_count = terrain_count[t];
@ -358,13 +358,13 @@ float quadsquare::RecomputeError(const quadcornerdata& cd) {
delete [] terrain_count;
if (total > 0) {
terrain_error = (1.0 - max_count / total);
terrain_error = (1.f - ((float)max_count / (float)total));
if (numTerr > 1) {
terrain_error *= numTerr / (numTerr - 1.0);
terrain_error *= numTerr / (numTerr - 1.f);
}
terrain_error *= whole * whole;
terrain_error *= TERRAIN_ERROR_SCALE;
} else terrain_error = 0;
terrain_error *= whole * whole;
terrain_error *= TERRAIN_ERROR_SCALE;
if (terrain_error > maxerror) maxerror = terrain_error;
if (terrain_error > Error[0]) Error[0] = terrain_error;
@ -422,7 +422,7 @@ void quadsquare::StaticCullAux(const quadcornerdata& cd, float ThresholdDetail,
quadsquare* s = GetNeighbor(0, cd);
if (s == NULL || (s->Child[1] == NULL && s->Child[2] == NULL)) {
float y = (cd.Verts[0].Y + cd.Verts[3].Y) * 0.5;
float y = (cd.Verts[0].Y + cd.Verts[3].Y) * 0.5f;
Vertex[1].Y = y;
Error[0] = 0;
if (s) s->Vertex[3].Y = y;
@ -434,7 +434,7 @@ void quadsquare::StaticCullAux(const quadcornerdata& cd, float ThresholdDetail,
if (Child[2] == NULL && Child[3] == NULL && Error[1] * ThresholdDetail < size) {
quadsquare* s = GetNeighbor(3, cd);
if (s == NULL || (s->Child[0] == NULL && s->Child[1] == NULL)) {
float y = (cd.Verts[2].Y + cd.Verts[3].Y) * 0.5;
float y = (cd.Verts[2].Y + cd.Verts[3].Y) * 0.5f;
Vertex[4].Y = y;
Error[1] = 0;
@ -455,14 +455,14 @@ void quadsquare::StaticCullAux(const quadcornerdata& cd, float ThresholdDetail,
bool NecessaryEdges = false;
for (int i = 0; i < 4; i++) {
float diff = fabs(Vertex[i+1].Y - (cd.Verts[i].Y
+ cd.Verts[(i+3)&3].Y) * 0.5);
if (diff > 0.00001) {
+ cd.Verts[(i+3)&3].Y) * 0.5f);
if (diff > 0.00001f) {
NecessaryEdges = true;
}
}
if (!NecessaryEdges) {
size *= 1.414213562;
size *= 1.414213562f;
if (cd.Parent->Square->Error[2 + cd.ChildIndex] * ThresholdDetail < size) {
delete cd.Parent->Square->Child[cd.ChildIndex];
cd.Parent->Square->Child[cd.ChildIndex] = 0;
@ -748,16 +748,12 @@ void quadsquare::InitArrayCounters() {
void quadsquare::Render(const quadcornerdata& cd, GLubyte *vnc_array) {
VNCArray = vnc_array;
bool fog_on;
int nx, ny;
Course.GetDivisions(&nx, &ny);
const TTerrType *TerrList = &Course.TerrList[0];
size_t numTerrains = Course.TerrList.size();
// fog_on = is_fog_on ();
fog_on = true;
bool fog_on = true;
for (size_t j=0; j<numTerrains; j++) {
if (TerrList[j].texture != NULL) {
if (Course.TerrList[j].texture != NULL) {
InitArrayCounters();
RenderAux(cd, SomeClip, (int)j);
if (VertexArrayCounter == 0) continue;
@ -790,7 +786,7 @@ void quadsquare::Render(const quadcornerdata& cd, GLubyte *vnc_array) {
}
for (size_t j=0; j<numTerrains; j++) {
if (TerrList[j].texture > 0) {
if (Course.TerrList[j].texture > 0) {
Course.TerrList[j].texture->Bind();
for (GLuint i=0; i<VertexArrayCounter; i++) {
@ -815,26 +811,22 @@ clip_result_t quadsquare::ClipSquare(const quadcornerdata& cd) {
}
int whole = 2 << cd.Level;
TVector3d min, max;
min.x = cd.xorg * ScaleX;
min.y = MinY;
min.z = cd.zorg * ScaleZ;
max.x = (cd.xorg + whole) * ScaleX;
max.y = MaxY;
max.z = (cd.zorg + whole) * ScaleZ;
if (min.x > max.x) {
double tmp = min.x;
min.x = max.x;
max.x = tmp;
}
TVector3d minimum(
cd.xorg * ScaleX,
MinY,
cd.zorg * ScaleZ);
TVector3d maximum(
(cd.xorg + whole) * ScaleX,
MaxY,
(cd.zorg + whole) * ScaleZ);
if (min.z > max.z) {
double tmp = min.z;
min.z = max.z;
max.z = tmp;
}
if (minimum.x > maximum.x)
std::swap(minimum.x, maximum.x);
clip_result_t clip_result = clip_aabb_to_view_frustum(min, max);
if (minimum.z > maximum.z)
std::swap(minimum.z, maximum.z);
clip_result_t clip_result = clip_aabb_to_view_frustum(minimum, maximum);
if (clip_result == NotVisible || clip_result == SomeClip) {
return clip_result;
@ -1112,7 +1104,7 @@ void InitQuadtree(double *elevation, int nx, int nz,
hm.RowWidth = hm.XSize;
hm.Scale = 0;
root_corner_data.Square = (quadsquare*)NULL;
root_corner_data.Square = nullptr;
root_corner_data.ChildIndex = 0;
root_corner_data.Level = get_root_level(nx, nz);
root_corner_data.xorg = 0;

View File

@ -34,7 +34,7 @@ GNU General Public License for more details.
CScore Score;
int CScore::AddScore(const TCourse* course, const TScore& score) {
int CScore::AddScore(const TCourse* course, TScore&& score) {
size_t list_idx = Course.GetCourseIdx(course);
if (list_idx >= Scorelist.size()) return 999;
if (score.points < 1) return 999;
@ -129,13 +129,11 @@ bool CScore::LoadHighScore() {
string course = SPStrN(*line, "course", "unknown");
TCourse* cidx = Course.GetCourse(course);
TScore score;
score.player = SPStrN(*line, "plyr", "unknown");
score.points = SPIntN(*line, "pts", 0);
score.herrings = SPIntN(*line, "herr", 0);
score.time = SPFloatN(*line, "time", 0);
AddScore(cidx, score);
AddScore(cidx, TScore(
SPStrN(*line, "plyr", "unknown"),
SPIntN(*line, "pts", 0),
SPIntN(*line, "herr", 0),
SPFloatN(*line, "time", 0)));
}
return true;
}
@ -156,13 +154,7 @@ int CScore::CalcRaceResult() {
g_game.score = (int)(herringpt + timept);
if (g_game.score < 0) g_game.score = 0;
TScore TempScore;
TempScore.points = g_game.score;
TempScore.herrings = g_game.herring;
TempScore.time = g_game.time;
TempScore.player = g_game.player->name;
return AddScore(g_game.course, TempScore);
return AddScore(g_game.course, TScore(g_game.player->name, g_game.score, g_game.herring, g_game.time));
}
// --------------------------------------------------------------------

View File

@ -19,6 +19,7 @@ GNU General Public License for more details.
#include "bh.h"
#include "states.h"
#include "spx.h"
#include <vector>
#define MAX_SCORES 8
@ -27,7 +28,11 @@ struct TScore {
string player;
int points;
int herrings;
double time;
float time;
TScore(const string& player_ = emptyString, int points_ = 0, int herrings_ = 0, double time_ = 0)
: player(player_), points(points_), herrings(herrings_), time(time_)
{}
};
struct TScoreList {
@ -46,7 +51,7 @@ private:
void Mouse(int button, int state, int x, int y);
void Motion(int x, int y);
public:
int AddScore(const TCourse* course, const TScore& score);
int AddScore(const TCourse* course, TScore&& score);
const TScoreList *GetScorelist(size_t list_idx) const;
void PrintScorelist(size_t list_idx) const;
bool SaveHighScore() const;

View File

@ -212,6 +212,13 @@ string SPStrN(const string &s, const string &tag, const string& def) {
return item;
}
string SPStrN(const string &s, const char* tag, const char* def) {
string item = SPItemN(s, tag);
if (item.empty()) return def;
STrimN(item);
return item;
}
int SPIntN(const string &s, const string &tag, const int def) {
return (Str_IntN(SPItemN(s, tag), def));
}

View File

@ -59,6 +59,7 @@ void Str_ArrN(const string &s, float *arr, size_t count, float def);
size_t SPPosN(const string &s, const string &tag);
string SPStrN(const string &s, const string &tag, const string& def = emptyString);
string SPStrN(const string &s, const char* tag, const char* def);
int SPIntN(const string &s, const string &tag, const int def);
bool SPBoolN(const string &s, const string &tag, const bool def);
float SPFloatN(const string &s, const string &tag, const float def);

View File

@ -534,7 +534,7 @@ CTexture::~CTexture() {
FreeTextureList();
}
void CTexture::LoadTextureList() {
bool CTexture::LoadTextureList() {
FreeTextureList();
CSPList list(200);
if (list.Load(param.tex_dir, "textures.lst")) {
@ -551,7 +551,11 @@ void CTexture::LoadTextureList() {
CommonTex[id]->Load(param.tex_dir, texfile);
} else Message("wrong texture id in textures.lst");
}
} else Message("failed to load common textures");
} else {
Message("failed to load common textures");
return false;
}
return true;
}
void CTexture::FreeTextureList() {

View File

@ -129,7 +129,7 @@ private:
public:
CTexture();
~CTexture();
void LoadTextureList();
bool LoadTextureList();
void FreeTextureList();
TTexture* GetTexture(size_t idx) const;

View File

@ -103,6 +103,7 @@ void DrawTrackmarks() {
TTexture* textures[NUM_TRACK_TYPES];
TColor track_colour = colWhite;
set_material(track_colour, colBlack, 1.f);
ScopedRenderMode rm(TRACK_MARKS);
textures[TRACK_HEAD] = Tex.GetTexture(trackid1);
@ -112,8 +113,10 @@ void DrawTrackmarks() {
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
for (list<track_quad_t>::const_iterator q = track_marks.quads.begin(); q != track_marks.quads.end(); ++q) {
track_colour.a = q->alpha;
set_material(track_colour, colBlack, 1.0);
if (q->alpha != track_colour.a) {
track_colour.a = q->alpha;
set_material_diffuse(track_colour);
}
textures[q->track_type]->Bind();
if ((q->track_type == TRACK_HEAD) || (q->track_type == TRACK_TAIL)) {
@ -159,8 +162,10 @@ void DrawTrackmarks() {
++qnext;
while (qnext != track_marks.quads.end() && qnext->track_type != TRACK_TAIL) {
q = qnext;
track_colour.a = q->alpha;
set_material(track_colour, colBlack, 1.0);
if (q->alpha != track_colour.a) {
track_colour.a = q->alpha;
set_material_diffuse(track_colour);
}
glNormal3(q->n4);
glTexCoord2(q->t4);
@ -201,15 +206,13 @@ void add_track_mark(const CControl *ctrl, int *id) {
if (param.perf_level < 3)
return;
TTerrType *TerrList = &Course.TerrList[0];
*id = Course.GetTerrainIdx(ctrl->cpos.x, ctrl->cpos.z, 0.5);
if (*id < 1) {
break_track_marks();
return;
}
if (!TerrList[*id].trackmarks) {
if (!Course.TerrList[*id].trackmarks) {
break_track_marks();
return;
}

View File

@ -441,7 +441,7 @@ bool CCharShape::Load(const string& dir, const string& filename, bool with_actio
if (SPIntN(*line, "material", 0) > 0) {
CreateMaterial(*line);
} else {
float visible = SPFloatN(*line, "vis", -1.0);
float visible = SPFloatN(*line, "vis", -1.f);
bool shadow = SPBoolN(*line, "shad", false);
string order = SPStrN(*line, "order");
CreateCharNode(parent_name, node_name, name, fullname, order, shadow);

View File

@ -323,7 +323,6 @@ void SetupViewFrustum(const CControl *ctrl) {
double near_dist = NEAR_CLIP_DIST;
double far_dist = param.forward_clip_distance;
TVector3d origin(0., 0., 0.);
double half_fov = ANGLES_TO_RADIANS(param.fov * 0.5);
double half_fov_horiz = atan(tan(half_fov) * aspect);
@ -340,14 +339,14 @@ void SetupViewFrustum(const CControl *ctrl) {
for (int i=0; i<6; i++) {
TVector3d pt = TransformPoint(ctrl->view_mat,
origin + -frustum_planes[i].d * frustum_planes[i].nml);
-frustum_planes[i].d * frustum_planes[i].nml);
frustum_planes[i].nml = TransformVector(
ctrl->view_mat, frustum_planes[i].nml);
frustum_planes[i].d = -DotProduct(
frustum_planes[i].nml,
pt - origin);
pt);
}
for (int i=0; i<6; i++) {

View File

@ -70,10 +70,9 @@ string CWinsys::GetResName(size_t idx) const {
return line;
}
double CWinsys::CalcScreenScale() const {
if (resolution.height < 768) return 0.78;
else if (resolution.height == 768) return 1.0;
else return (resolution.height / 768);
float CWinsys::CalcScreenScale() const {
if (resolution.height < 768) return 0.78f;
else return (resolution.height / 768.f);
}
void CWinsys::SetupVideoMode(const TScreenRes& resolution_) {

View File

@ -41,10 +41,10 @@ private:
TScreenRes resolutions[NUM_RESOLUTIONS];
TScreenRes auto_resolution;
SDL_Surface *screen;
double CalcScreenScale() const;
float CalcScreenScale() const;
public:
TScreenRes resolution;
double scale; // scale factor for screen, see 'use_quad_scale'
float scale; // scale factor for screen, see 'use_quad_scale'
CWinsys();