Use pointers instead of indices in several places

git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/branches/SFML2@480 0420edf4-82e4-42fc-9478-35b55e6d67a3
master
pkeus 2013-11-27 17:11:54 +00:00
parent b0911a942b
commit df0203e807
22 changed files with 191 additions and 247 deletions

View File

@ -74,8 +74,15 @@ const TPolyhedron& CCourse::GetPoly (size_t type) const {
return PolyArr[ObjTypes[type].poly];
}
size_t CCourse::GetCourseIdx (const string& dir) const {
return CourseIndex.at(dir);
TCourse* CCourse::GetCourse(const string& dir) {
return &CourseList[CourseIndex.at(dir)];
}
size_t CCourse::GetCourseIdx(const TCourse* course) const {
size_t idx = (course - &CourseList[0]) / sizeof(TCourse);
if (idx >= CourseList.size())
return -1;
return idx;
}
void CCourse::CalcNormals () {
@ -387,24 +394,11 @@ void CCourse::LoadItemList () {
ObjTypes[type].texture = new TTexture();
ObjTypes[type].texture->Load(terrpath, false);
}
bool coll = ObjTypes[type].collidable;
if (coll == 1) {
CollArr.push_back(TCollidable());
CollArr.back().pt.x = xx;
CollArr.back().pt.z = zz;
CollArr.back().pt.y = FindYCoord (xx, zz);
CollArr.back().height = height;
CollArr.back().diam = diam;
CollArr.back().tree_type = type;
} else if (coll == 0) {
NocollArr.push_back(TItem(ObjTypes[type]));
NocollArr.back().pt.x = xx;
NocollArr.back().pt.z = zz;
NocollArr.back().pt.y = FindYCoord (xx, zz);
NocollArr.back().height = height;
NocollArr.back().diam = diam;
ObjTypes[type].num_items++;
}
if (ObjTypes[type].collidable)
CollArr.push_back(TCollidable(xx, FindYCoord(xx, zz), zz, height, diam, type));
else
NocollArr.push_back(TItem(xx, FindYCoord(xx, zz), zz, height, diam, ObjTypes[type]));
}
}
@ -502,24 +496,10 @@ bool CCourse::LoadAndConvertObjectMap () {
break;
}
bool coll = ObjTypes[type].collidable;
if (coll == 1) {
CollArr.push_back(TCollidable());
CollArr.back().pt.x = xx;
CollArr.back().pt.z = zz;
CollArr.back().pt.y = FindYCoord (xx, zz);
CollArr.back().height = height;
CollArr.back().diam = diam;
CollArr.back().tree_type = type;
} else if (coll == 0) {
NocollArr.push_back(TItem(ObjTypes[type]));
NocollArr.back().pt.x = xx;
NocollArr.back().pt.z = zz;
NocollArr.back().pt.y = FindYCoord (xx, zz);
NocollArr.back().height = height;
NocollArr.back().diam = diam;
ObjTypes[type].num_items++;
}
if (ObjTypes[type].collidable)
CollArr.push_back(TCollidable(xx, FindYCoord(xx, zz), zz, height, diam, type));
else
NocollArr.push_back(TItem(xx, FindYCoord(xx, zz), zz, height, diam, ObjTypes[type]));
string line = "*[name]";
line += ObjTypes[type].name;
@ -757,24 +737,18 @@ void CCourse::ResetCourse () {
mirrored = false;
}
bool CCourse::LoadCourse (size_t idx) {
if (idx >= CourseList.size()) {
Message ("wrong course index");
curr_course = NULL;
return false;
}
if (&CourseList[idx] != curr_course || g_game.force_treemap) {
bool CCourse::LoadCourse (TCourse* course) {
if (course != curr_course || g_game.force_treemap) {
ResetCourse ();
curr_course = &CourseList[idx];
curr_course = course;
CourseDir = param.common_course_dir + SEP + curr_course->dir;
start_pt.x = CourseList[idx].start.x;
start_pt.y = -CourseList[idx].start.y;
start_pt.x = course->start.x;
start_pt.y = -course->start.y;
base_height_value = 127;
g_game.use_keyframe = CourseList[idx].use_keyframe;
g_game.finish_brake = CourseList[idx].finish_brake;
g_game.use_keyframe = course->use_keyframe;
g_game.finish_brake = course->finish_brake;
if (!LoadElevMap ()) {
Message ("could not load course elev map");
@ -792,7 +766,7 @@ bool CCourse::LoadCourse (size_t idx) {
// ................................................................
string itemfile = CourseDir + SEP "items.lst";
bool itemsexists = FileExists (itemfile);
const CControl *ctrl = Players.GetCtrl (g_game.player_id);
const CControl *ctrl = g_game.player->ctrl;
if (itemsexists && !g_game.force_treemap)
LoadItemList ();
@ -810,9 +784,9 @@ bool CCourse::LoadCourse (size_t idx) {
param.course_detail_level);
}
if (g_game.mirror_id != mirrored) {
if (g_game.mirrorred != mirrored) {
MirrorCourse ();
mirrored = g_game.mirror_id;
mirrored = g_game.mirrorred;
}
return true;
}
@ -858,7 +832,7 @@ void CCourse::MirrorCourseData () {
ResetQuadtree ();
if (nx > 0 && ny > 0) {
const CControl *ctrl = Players.GetCtrl (g_game.player_id);
const CControl *ctrl = g_game.player->ctrl;
InitQuadtree (elevation, nx, ny, curr_course->size.x/(nx-1),
- curr_course->size.y/(ny-1), ctrl->viewpos, param.course_detail_level);
}

View File

@ -78,6 +78,9 @@ struct TCollidable {
double height;
double diam;
size_t tree_type;
TCollidable(double x, double y, double z, double height_, double diam_, size_t type)
: pt(x, y, z), height(height_), diam(diam_), tree_type(type)
{}
};
struct TItem {
@ -86,7 +89,9 @@ struct TItem {
double diam;
int collectable;
const TObjectType& type;
TItem(const TObjectType& type_) : type(type_), collectable(type_.collectable) {}
TItem(double x, double y, double z, double height_, double diam_, const TObjectType& type_)
: pt(x, y, z), height(height_), diam(diam_), collectable(type_.collectable), type(type_)
{}
};
struct TCourse {
@ -148,10 +153,11 @@ public:
GLubyte *vnc_array;
void ResetCourse ();
size_t GetCourseIdx (const string& dir) const;
TCourse* GetCourse (const string& dir);
size_t GetCourseIdx(const TCourse* course) const;
bool LoadCourseList ();
void FreeCourseList ();
bool LoadCourse (size_t idx);
bool LoadCourse(TCourse* course);
bool LoadTerrainTypes ();
bool LoadObjectTypes ();
void MakeStandardPolyhedrons ();

View File

@ -47,7 +47,7 @@ void RenderCourse () {
setup_course_tex_gen ();
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
set_material (colWhite, colBlack, 1.0);
const CControl *ctrl = Players.GetCtrl (g_game.player_id);
const CControl *ctrl = g_game.player->ctrl;
UpdateQuadtree (ctrl->viewpos, param.course_detail_level);
RenderQuadtree ();
}
@ -58,7 +58,7 @@ void RenderCourse () {
void DrawTrees() {
size_t tree_type = -1;
TObjectType* object_types = &Course.ObjTypes[0];
const CControl* ctrl = Players.GetCtrl (g_game.player_id);
const CControl* ctrl = g_game.player->ctrl;
ScopedRenderMode rm(TREES);
double fwd_clip_limit = param.forward_clip_distance;

View File

@ -52,7 +52,11 @@ enum TViewMode {
NUM_VIEW_MODES
};
struct TCup2;
struct TCup;
struct TPlayer;
struct TCourse;
struct TRace;
struct TCharacter;
struct TGameData {
TToolMode toolmode;
@ -67,22 +71,18 @@ struct TGameData {
double finish_brake;
// course and race params
size_t player_id;
TPlayer* player;
size_t start_player;
TCup2* cup;
size_t race_id;
bool mirror_id;
size_t char_id;
size_t course_id;
TCup* cup;
bool mirrorred;
TCharacter* character;
TCourse* course;
size_t location_id;
size_t light_id;
int snow_id;
int wind_id;
size_t theme_id;
// requirements
TVector3i herring_req; // 3 levels of needed herrings
TVector3d time_req; // 3 levels of allowed time
TRace* race; // Only valid if not in practice mode
// race results (better in player.ctrl ?)
double time; // reached time

View File

@ -41,7 +41,7 @@ CEvent Event;
// ready: 0 - racing 1 - ready with success 2 - ready with failure
static int ready = 0; // indicates if last race is done
static TWidget* curr_focus = 0;
static TCup2 *ecup = 0;
static TCup *ecup = 0;
static size_t curr_race = 0;
static size_t curr_bonus = 0;
static TWidget* textbuttons[3];
@ -54,14 +54,13 @@ void StartRace () {
State::manager.RequestEnterState (EventSelect);
return;
}
g_game.mirror_id = false;
g_game.course_id = ecup->races[curr_race]->course;
g_game.mirrorred = false;
g_game.course = ecup->races[curr_race]->course;
g_game.theme_id = ecup->races[curr_race]->music_theme;
g_game.light_id = ecup->races[curr_race]->light;
g_game.snow_id = ecup->races[curr_race]->snow;
g_game.wind_id = ecup->races[curr_race]->wind;
g_game.herring_req = ecup->races[curr_race]->herrings;
g_game.time_req = ecup->races[curr_race]->time;
g_game.race = ecup->races[curr_race];
g_game.game_type = CUPRACING;
State::manager.RequestEnterState (Loading);
}
@ -230,7 +229,7 @@ void CEvent::Loop (double timestep) {
FT.SetColor (colDYell);
else
FT.SetColor (colWhite);
FT.DrawString (area.left + 29, y, Course.CourseList[ecup->races[i]->course].name);
FT.DrawString (area.left + 29, y, ecup->races[i]->course->name);
checkbox.SetPosition(area.right - 50, y + 4);
checkbox.SetChecked(curr_race > i);
checkbox.Draw();

View File

@ -34,7 +34,7 @@ GNU General Public License for more details.
CEventSelect EventSelect;
static TEvent2 *EventList;
static TEvent *EventList;
static TUpDown* event;
static TUpDown* cup;
static TWidget* textbuttons[2];
@ -42,7 +42,6 @@ static TWidget* textbuttons[2];
void EnterEvent () {
g_game.game_type = CUPRACING;
g_game.cup = EventList[event->GetValue()].cups[cup->GetValue()];
g_game.race_id = 0;
State::manager.RequestEnterState(Event);
}
@ -121,7 +120,7 @@ void CEventSelect::Enter () {
selectedEvent = AddFramedText(area.left, frametop1, framewidth, frameheight, 3, colMBackgr, "", FT.GetSize(), true);
selectedCup = AddFramedText(area.left, frametop2, framewidth, frameheight, 3, colMBackgr, "", FT.GetSize(), true);
Events.MakeUnlockList (Players.GetCurrUnlocked());
Events.MakeUnlockList (g_game.player->funlocked);
Music.Play (param.menu_music, -1);
}

View File

@ -46,16 +46,14 @@ bool CEvents::LoadEventList () {
const string& line = list.Line(i);
int type = SPIntN (line, "struct", -1);
if (type == 0) {
RaceList.push_back(TRace2());
string item = SPStrN (line, "course");
RaceList.back().course = Course.GetCourseIdx (item);
item = SPStrN (line, "light");
RaceList.back().light = Env.GetLightIdx (item);
RaceList.back().snow = SPIntN (line, "snow", 0);
RaceList.back().wind = SPIntN (line, "wind", 0);
RaceList.back().time = SPVector3d(line, "time");
RaceList.back().herrings = SPVector3i(line, "herring");
RaceList.back().music_theme = Music.GetThemeIdx (SPStrN (line, "theme", "normal"));
RaceList.push_back(TRace(
Course.GetCourse(SPStrN(line, "course")),
Env.GetLightIdx(SPStrN(line, "light")),
SPIntN(line, "snow", 0),
SPIntN(line, "wind", 0),
SPVector3i(line, "herring"),
SPVector3d(line, "time"),
Music.GetThemeIdx(SPStrN(line, "theme", "normal"))));
}
}
list.MakeIndex (RaceIndex, "race");
@ -65,10 +63,10 @@ bool CEvents::LoadEventList () {
const string& line = list.Line(i);
int type = SPIntN (line, "struct", -1);
if (type == 1) {
CupList.push_back(TCup2());
CupList.back().cup = SPStrN (line, "cup", errorString);
CupList.back().name = SPStrN (line, "name", "unknown");
CupList.back().desc = SPStrN (line, "desc", "unknown");
CupList.push_back(TCup(
SPStrN(line, "cup", errorString),
SPStrN(line, "name", "unknown"),
SPStrN(line, "desc", "unknown")));
int num = SPIntN (line, "num", 0);
CupList.back().races.resize(num);
for (int ii=0; ii<num; ii++) {
@ -84,8 +82,7 @@ bool CEvents::LoadEventList () {
const string& line = list.Line(i);
int type = SPIntN (line, "struct", -1);
if (type == 2) {
EventList.push_back(TEvent2());
EventList.back().name = SPStrN (line, "name", "unknown");
EventList.push_back(TEvent(SPStrN(line, "name", "unknown")));
int num = SPIntN (line, "num", 0);
EventList.back().cups.resize(num);
for (int ii=0; ii<num; ii++) {
@ -162,35 +159,22 @@ CPlayers::~CPlayers() {
}
void CPlayers::AddPlayer (const string& name, const string& avatar) {
plyr.push_back(TPlayer());
plyr.back().name = name;
plyr.back().avatar = FindAvatar(avatar);
plyr.back().funlocked = "";
plyr.back().ctrl = NULL;
plyr.push_back(TPlayer(name, FindAvatar(avatar)));
}
void CPlayers::SetDefaultPlayers () {
plyr.resize(2);
plyr[0].funlocked = "";
plyr[0].name = "Racer";
plyr[0].avatar = FindAvatar("avatar01.png");
plyr[0].ctrl = NULL;
plyr[1].funlocked = "";
plyr[1].name = "Bunny";
plyr[1].avatar = FindAvatar("avatar02.png");
plyr[1].ctrl = NULL;
plyr.push_back(TPlayer("Racer", FindAvatar("avatar01.png")));
plyr.push_back(TPlayer("Bunny", FindAvatar("avatar02.png")));
}
bool CPlayers::LoadPlayers () {
CSPList list(MAX_PLAYERS);
if (FileExists (param.config_dir, "players") == false) {
SetDefaultPlayers ();
Message ("file 'players' does not exist, set default players");
return false;
}
CSPList list(MAX_PLAYERS);
if (list.Load (param.config_dir, "players") == false) {
SetDefaultPlayers ();
Message ("could not load players list, set default players");
@ -218,58 +202,35 @@ bool CPlayers::LoadPlayers () {
void CPlayers::SavePlayers () const {
string playerfile = param.config_dir + SEP "players";
CSPList list(MAX_PLAYERS);
string item = "";
CSPList list(plyr.size());
for (size_t i=0; i<plyr.size(); i++) {
item = "*[name]" + plyr[i].name;
string item = "*[name]" + plyr[i].name;
item +="[avatar]" + plyr[i].avatar->filename;
item += "[unlocked]" + plyr[i].funlocked;
if (i == g_game.player_id) item += "[active]1";
if (&plyr[i] == g_game.player) item += "[active]1";
else item += "[active]0";
list.Add (item);
}
list.Save (playerfile);
}
const TAvatar* CPlayers::FindAvatar(const string& name)
{
const TAvatar* CPlayers::FindAvatar(const string& name) {
for (size_t i = 0; i < avatars.size(); i++)
if (avatars[i].filename == name)
return &avatars[i];
return 0;
}
const string& CPlayers::GetCurrUnlocked () const {
return plyr[g_game.player_id].funlocked;
}
void CPlayers::AddPassedCup (const string& cup) {
if (SPIntN (plyr[g_game.player_id].funlocked, cup, -1) > 0) return;
plyr[g_game.player_id].funlocked += " ";
plyr[g_game.player_id].funlocked += cup;
}
CControl *CPlayers::GetCtrl (size_t player) {
if (player >= plyr.size()) return NULL;
return plyr[player].ctrl;
}
const CControl *CPlayers::GetCtrl (size_t player) const {
if (player >= plyr.size()) return NULL;
return plyr[player].ctrl;
}
const string& CPlayers::GetName (size_t player) const {
if (player >= plyr.size()) return emptyString;
return plyr[player].name;
if (SPIntN (g_game.player->funlocked, cup, -1) > 0) return;
g_game.player->funlocked += " ";
g_game.player->funlocked += cup;
}
void CPlayers::ResetControls () {
for (size_t i=0; i<plyr.size(); i++) {
if (plyr[i].ctrl != NULL) {
delete plyr[i].ctrl;
plyr[i].ctrl = NULL;
}
delete plyr[i].ctrl;
plyr[i].ctrl = NULL;
}
}
@ -315,6 +276,12 @@ const string& CPlayers::GetDirectAvatarName (size_t avatar) const {
// Character Administration
// ********************************************************************
CKeyframe* TCharacter::GetKeyframe(TFrameType type) {
if (type < 0 || type >= NUM_FRAME_TYPES) return NULL;
return &frames[type];
}
CCharacter Char;
static const string char_type_index = "[spheres]0[3d]1";
@ -379,19 +346,3 @@ void CCharacter::FreeCharacterPreviews() {
CharList[i].preview = 0;
}
}
void CCharacter::Draw (size_t idx) {
if (idx >= CharList.size()) return;
CharList[idx].shape->Draw ();
}
CCharShape *CCharacter::GetShape (size_t idx) {
if (idx >= CharList.size()) return NULL;
return CharList[idx].shape;
}
CKeyframe *CCharacter::GetKeyframe (size_t idx, TFrameType type) {
if (type < 0 || type >= NUM_FRAME_TYPES) return NULL;
if (idx >= CharList.size()) return NULL;
return &CharList[idx].frames[type];
}

View File

@ -19,6 +19,7 @@ GNU General Public License for more details.
#include "bh.h"
#include "keyframe.h"
#include "spx.h"
#include <map>
@ -33,27 +34,39 @@ enum TFrameType {
class TTexture;
struct TRace2 {
size_t course;
struct TRace {
TCourse* course;
size_t light;
int snow;
int wind;
TVector3i herrings;
TVector3d time;
size_t music_theme;
TRace(TCourse* course_, size_t light_, int snow_, int wind_, const TVector3i& herrings_, const TVector3d& time_, size_t music_theme_)
: course(course_), light(light_), snow(snow_), wind(wind_), herrings(herrings_), time(time_), music_theme(music_theme_)
{}
};
struct TCup2 {
struct TCup {
string cup;
string name;
string desc;
vector<TRace2*> races;
vector<TRace*> races;
bool Unlocked;
TCup(const string& cup_, const string& name_, const string& desc_)
: cup(cup_), name(name_), desc(desc_), Unlocked(false)
{}
};
struct TEvent2 {
struct TEvent {
string name;
vector<TCup2*> cups;
vector<TCup*> cups;
TEvent(const string& name_)
: name(name_)
{}
};
class CEvents {
@ -62,9 +75,9 @@ private:
map<string, size_t> CupIndex;
map<string, size_t> EventIndex;
public:
vector<TRace2> RaceList;
vector<TCup2> CupList;
vector<TEvent2> EventList;
vector<TRace> RaceList;
vector<TCup> CupList;
vector<TEvent> EventList;
bool LoadEventList ();
size_t GetRaceIdx (const string& race) const;
size_t GetCupIdx (const string& cup) const;
@ -89,7 +102,9 @@ struct TAvatar {
string filename;
TTexture* texture;
TAvatar(const string& filename_, TTexture* texture_) : filename(filename_), texture(texture_) {}
TAvatar(const string& filename_, TTexture* texture_)
: filename(filename_), texture(texture_)
{}
};
struct TPlayer {
@ -97,6 +112,10 @@ struct TPlayer {
CControl *ctrl;
string funlocked;
const TAvatar* avatar;
TPlayer(const string& name_ = emptyString, const TAvatar* avatar_ = NULL)
: name(name_), ctrl(NULL), avatar(avatar_)
{}
};
class CPlayers {
@ -109,14 +128,11 @@ private:
public:
~CPlayers();
const string& GetCurrUnlocked () const;
TPlayer* GetPlayer(size_t index) { return &plyr[index]; }
void AddPassedCup (const string& cup);
void AddPlayer (const string& name, const string& avatar);
bool LoadPlayers ();
void SavePlayers () const;
CControl *GetCtrl (size_t player);
const CControl *GetCtrl (size_t player) const;
const string& GetName (size_t player) const;
void ResetControls ();
void AllocControl (size_t player);
void LoadAvatars ();
@ -132,8 +148,6 @@ extern CPlayers Players;
// -------------------------------- characters ------------------------
#define MAX_CHARACTERS 16
class CCharShape;
struct TCharacter {
int type;
string name;
@ -142,6 +156,8 @@ struct TCharacter {
CCharShape *shape;
CKeyframe frames[NUM_FRAME_TYPES];
bool finishframesok;
CKeyframe* GetKeyframe(TFrameType type);
};
class CCharacter {
@ -150,12 +166,8 @@ public:
~CCharacter();
void Draw (size_t idx);
CCharShape *GetShape (size_t idx);
void LoadCharacterList ();
void FreeCharacterPreviews ();
CKeyframe *GetKeyframe (size_t idx, TFrameType type);
};
extern CCharacter Char;

View File

@ -38,6 +38,7 @@ GNU General Public License for more details.
#include "event.h"
#include "winsys.h"
#include "physics.h"
#include "tux.h"
CGameOver GameOver;
@ -96,7 +97,7 @@ void GameOverMessage (const CControl *ctrl) {
line = Int_StrN (g_game.herring);
if (g_game.game_type == CUPRACING) {
line += " (";
line += Int_StrN (g_game.herring_req.x);
line += Int_StrN (g_game.race->herrings.x);
line += ")";
}
FT.DrawString (leftframe+240, topframe+40, line);
@ -107,7 +108,7 @@ void GameOverMessage (const CControl *ctrl) {
line += " s";
if (g_game.game_type == CUPRACING) {
line += " (";
line += Float_StrN (g_game.time_req.x, 2);
line += Float_StrN (g_game.race->time.x, 2);
line += ")";
}
FT.DrawString (leftframe+240, topframe+65, line);
@ -177,13 +178,13 @@ void CGameOver::Enter() {
final_frame = NULL;
} else {
if (g_game.game_type == CUPRACING) {
if (g_game.race_result < 0) final_frame =
Char.GetKeyframe (g_game.char_id, LOSTRACE);
else final_frame = Char.GetKeyframe (g_game.char_id, WONRACE);
} else final_frame = Char.GetKeyframe (g_game.char_id, FINISH);
if (g_game.race_result < 0)
final_frame = g_game.character->GetKeyframe(LOSTRACE);
else final_frame = g_game.character->GetKeyframe(WONRACE);
} else final_frame = g_game.character->GetKeyframe( FINISH);
if (!g_game.raceaborted) {
const CControl *ctrl = Players.GetCtrl (g_game.player_id);
const CControl *ctrl = g_game.player->ctrl;
final_frame->Init (ctrl->cpos, -0.18);
}
}
@ -192,7 +193,7 @@ void CGameOver::Enter() {
void CGameOver::Loop(double time_step) {
CControl *ctrl = Players.GetCtrl (g_game.player_id);
CControl *ctrl = g_game.player->ctrl;
int width = Winsys.resolution.width;
int height = Winsys.resolution.height;
check_gl_error();
@ -217,7 +218,7 @@ void CGameOver::Loop(double time_step) {
UpdateSnow (time_step, ctrl);
DrawSnow (ctrl);
Char.Draw (g_game.char_id);
g_game.character->shape->Draw();
{
ScopedRenderMode rm(GUI);

View File

@ -33,6 +33,7 @@ GNU General Public License for more details.
#include "racing.h"
#include "winsys.h"
#include "physics.h"
#include "tux.h"
CIntro Intro;
static CKeyframe *startframe;
@ -48,18 +49,16 @@ void abort_intro (CControl *ctrl) {
// =================================================================
void CIntro::Enter() {
CControl *ctrl = Players.GetCtrl (g_game.player_id);
CControl *ctrl = g_game.player->ctrl;
const TVector2d& start_pt = Course.GetStartPoint ();
ctrl->orientation_initialized = false;
ctrl->view_init = false;
ctrl->cpos.x = start_pt.x;
ctrl->cpos.z = start_pt.y;
startframe = Char.GetKeyframe (g_game.char_id, START);
startframe = g_game.character->GetKeyframe(START);
if (startframe->loaded) {
// startframe->Init (ctrl->cpos, -0.05);
CCharShape *sh = Char.GetShape (g_game.char_id);
startframe->Init (ctrl->cpos, -0.05, sh);
startframe->Init(ctrl->cpos, -0.05, g_game.character->shape);
}
// reset of result values
@ -93,7 +92,7 @@ void CIntro::Enter() {
}
void CIntro::Loop (double time_step) {
CControl *ctrl = Players.GetCtrl (g_game.player_id);
CControl *ctrl = g_game.player->ctrl;
int width = Winsys.resolution.width;
int height = Winsys.resolution.height;
check_gl_error();
@ -120,7 +119,7 @@ void CIntro::Loop (double time_step) {
UpdateSnow (time_step, ctrl);
DrawSnow (ctrl);
Char.Draw (g_game.char_id);
g_game.character->shape->Draw();
DrawHud (ctrl);
Reshape (width, height);
@ -132,6 +131,6 @@ void CIntro::Loop (double time_step) {
void CIntro::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
if (release)
return;
CControl *ctrl = Players.GetCtrl (g_game.player_id);
CControl *ctrl = g_game.player->ctrl;
abort_intro (ctrl);
}

View File

@ -62,9 +62,8 @@ double CKeyframe::interp (double frac, double v1, double v2) {
void CKeyframe::Init (const TVector3d& ref_position, double height_correction) {
if (!loaded) return;
CCharShape *shape = Char.GetShape (g_game.char_id);
shape->ResetNode ("head");
shape->ResetNode ("neck");
g_game.character->shape->ResetNode("head");
g_game.character->shape->ResetNode("neck");
refpos = ref_position;
heightcorr = height_correction;
active = true;
@ -273,7 +272,7 @@ void CKeyframe::Update (double timestep) {
double frac;
TVector3d pos;
CCharShape *shape = Char.GetShape (g_game.char_id);
CCharShape *shape = g_game.character->shape;
if (fabs (frames[keyidx].val[0]) < 0.0001) frac = 1.0;
else frac = (frames[keyidx].val[0] - keytime) / frames[keyidx].val[0];
@ -286,7 +285,7 @@ void CKeyframe::Update (double timestep) {
shape->ResetRoot ();
shape->ResetJoints ();
Players.GetCtrl (g_game.player_id)->cpos = pos;
g_game.player->ctrl->cpos = pos;
double disp_y = pos.y + TUX_Y_CORR + heightcorr;
shape->ResetNode (0);
shape->TranslateNode (0, TVector3d(pos.x, disp_y, pos.z));

View File

@ -42,7 +42,7 @@ void CLoading::Enter() {
void CLoading::Loop(double time_step) {
TCourse *CourseList = &Course.CourseList[0];
string msg = Trans.Text(29) + " " + CourseList[g_game.course_id].name;
string msg = Trans.Text(29) + " " + g_game.course->name;
check_gl_error ();
ScopedRenderMode rm(GUI);
@ -67,7 +67,7 @@ void CLoading::Loop(double time_step) {
FT.DrawString (CENTER, AutoYPosN (70), Trans.Text (30));
Winsys.SwapBuffers ();
Course.LoadCourse (g_game.course_id);
Course.LoadCourse (g_game.course);
g_game.location_id = Course.GetEnv ();
Env.LoadEnvironment (g_game.location_id, g_game.light_id);
State::manager.RequestEnterState (Intro);

View File

@ -45,16 +45,15 @@ void InitGame (int argc, char **argv) {
if (group_arg == "9") g_game.argument = 9;
}
g_game.player_id = 0;
g_game.player = NULL;
g_game.start_player = 0;
g_game.course_id = 0;
g_game.mirror_id = false;
g_game.char_id = 0;
g_game.course = NULL;
g_game.mirrorred = false;
g_game.character = NULL;
g_game.location_id = 0;
g_game.light_id = 0;
g_game.snow_id = 0;
g_game.cup = 0;
g_game.race_id = 0;
g_game.theme_id = 0;
g_game.force_treemap = 0;
g_game.treesize = 3;

View File

@ -30,6 +30,7 @@ GNU General Public License for more details.
#include "particles.h"
#include "textures.h"
#include "game_ctrl.h"
#include "tux.h"
#include "racing.h"
#include "winsys.h"
#include "physics.h"
@ -71,7 +72,7 @@ void CPaused::Mouse (int button, int state, int x, int y) {
// ====================================================================
void CPaused::Loop (double time_step) {
CControl *ctrl = Players.GetCtrl (g_game.player_id);
CControl *ctrl = g_game.player->ctrl;
int width = Winsys.resolution.width;
int height = Winsys.resolution.height;
check_gl_error();
@ -91,7 +92,7 @@ void CPaused::Loop (double time_step) {
DrawSnow (ctrl);
if (param.perf_level > 2) draw_particles (ctrl);
Char.Draw (g_game.char_id);
g_game.character->shape->Draw();
DrawHud (ctrl);
Reshape (width, height);

View File

@ -116,7 +116,6 @@ bool CControl::CheckTreeCollisions (const TVector3d& pos, TVector3d *tree_loc, d
} else return false;
}
CCharShape *shape = Char.GetShape (g_game.char_id);
double diam = 0.0;
TVector3d loc(0, 0, 0);
bool hit = false;
@ -150,7 +149,7 @@ bool CControl::CheckTreeCollisions (const TVector3d& pos, TVector3d *tree_loc, d
mat.SetTranslationMatrix(loc.x, loc.y, loc.z);
TransPolyhedron (mat, ph2);
// hit = TuxCollision2 (pos, ph2);
hit = shape->Collision (pos, ph2);
hit = g_game.character->shape->Collision(pos, ph2);
if (hit == true) {
if (tree_loc != NULL) *tree_loc = loc;
@ -252,7 +251,7 @@ void CControl::AdjustPosition (const TPlane& surf_plane, double dist_from_surfac
}
void CControl::SetTuxPosition (double speed) {
CCharShape *shape = Char.GetShape (g_game.char_id);
CCharShape *shape = g_game.character->shape;
TVector2d playSize = Course.GetPlayDimensions();
TVector2d courseSize = Course.GetDimensions();
@ -623,7 +622,7 @@ void CControl::SolveOdeSystem (double timestep) {
// --------------------------------------------------------------------
void CControl::UpdatePlayerPos (double timestep) {
CCharShape *shape = Char.GetShape (g_game.char_id);
CCharShape *shape = g_game.character->shape;
double paddling_factor;
double flap_factor;
double dist_from_surface;

View File

@ -64,12 +64,12 @@ static void UpdateInfo() {
}
void SetRaceConditions() {
g_game.mirror_id = mirror->GetValue() != 0;
g_game.mirrorred = mirror->GetValue() != 0;
g_game.light_id = light->GetValue();
g_game.snow_id = snow->GetValue();
g_game.wind_id = wind->GetValue();
g_game.course_id = course->GetValue();
g_game.course = &Course.CourseList[course->GetValue()];
g_game.theme_id = CourseList[course->GetValue()].music_theme;
g_game.game_type = PRACTICING;
State::manager.RequestEnterState (Loading);
@ -163,12 +163,12 @@ void CRaceSelect::Enter() {
ResetGUI ();
course = AddUpDown(area.left + framewidth + 8, frametop, 0, (int)Course.CourseList.size() - 1, (int)g_game.course_id);
course = AddUpDown(area.left + framewidth + 8, frametop, 0, (int)Course.CourseList.size() - 1, g_game.course?(int)Course.GetCourseIdx(g_game.course):0);
light = AddIconButton (iconleft, icontop, Tex.GetSFTexture (LIGHT_BUTT), iconsize, 3, (int)g_game.light_id);
snow = AddIconButton(iconleft + iconspace, icontop, Tex.GetSFTexture(SNOW_BUTT), iconsize, 3, g_game.snow_id);
wind = AddIconButton(iconleft + iconspace * 2, icontop, Tex.GetSFTexture(WIND_BUTT), iconsize, 3, g_game.wind_id);
mirror = AddIconButton(iconleft + iconspace * 3, icontop, Tex.GetSFTexture(MIRROR_BUTT), iconsize, 1, (int) g_game.mirror_id);
mirror = AddIconButton(iconleft + iconspace * 3, icontop, Tex.GetSFTexture(MIRROR_BUTT), iconsize, 1, (int) g_game.mirrorred);
random_btn = AddIconButton(iconleft + iconspace * 4, icontop, Tex.GetSFTexture(RANDOM_BUTT), iconsize, 0, 0);
int siz = FT.AutoSizeN (5);
int len1 = FT.GetTextWidth (Trans.Text(13));

View File

@ -36,6 +36,7 @@ GNU General Public License for more details.
#include "reset.h"
#include "winsys.h"
#include "physics.h"
#include "tux.h"
#include <algorithm>
#define MAX_JUMP_AMT 1.0
@ -107,19 +108,19 @@ void CRacing::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, in
// view changing
case sf::Keyboard::Num1:
if (!release) {
set_view_mode (Players.GetCtrl (g_game.player_id), ABOVE);
set_view_mode (g_game.player->ctrl, ABOVE);
param.view_mode = ABOVE;
}
break;
case sf::Keyboard::Num2:
if (!release) {
set_view_mode (Players.GetCtrl (g_game.player_id), FOLLOW);
set_view_mode (g_game.player->ctrl, FOLLOW);
param.view_mode = FOLLOW;
}
break;
case sf::Keyboard::Num3:
if (!release) {
set_view_mode (Players.GetCtrl (g_game.player_id), BEHIND);
set_view_mode (g_game.player->ctrl, BEHIND);
param.view_mode = BEHIND;
}
break;
@ -166,7 +167,7 @@ void CRacing::Jbutt (int button, int state) {
}
void CalcJumpEnergy (double time_step) {
CControl *ctrl = Players.GetCtrl (g_game.player_id);
CControl *ctrl = g_game.player->ctrl;
if (ctrl->jump_charging) {
ctrl->jump_amt = min (MAX_JUMP_AMT, g_game.time - charge_start_time);
@ -195,7 +196,7 @@ void SetSoundVolumes () {
// ---------------------------- init ----------------------------------
void CRacing::Enter() {
CControl *ctrl = Players.GetCtrl (g_game.player_id);
CControl *ctrl = g_game.player->ctrl;
if (param.view_mode < 0 || param.view_mode >= NUM_VIEW_MODES) {
param.view_mode = ABOVE;
@ -338,7 +339,7 @@ void CalcTrickControls (CControl *ctrl, double time_step, bool airborne) {
// ====================================================================
void CRacing::Loop (double time_step) {
CControl *ctrl = Players.GetCtrl (g_game.player_id);
CControl *ctrl = g_game.player->ctrl;
double ycoord = Course.FindYCoord (ctrl->cpos.x, ctrl->cpos.z);
bool airborne = (bool) (ctrl->cpos.y > (ycoord + JUMP_MAX_START_HEIGHT));
@ -370,7 +371,7 @@ void CRacing::Loop (double time_step) {
update_particles (time_step);
draw_particles (ctrl);
}
Char.Draw (g_game.char_id);
g_game.character->shape->Draw();
UpdateWind (time_step);
UpdateSnow (time_step, ctrl);
DrawSnow (ctrl);

View File

@ -41,9 +41,9 @@ static TUpDown* character;
void QuitRegistration () {
Players.ResetControls ();
Players.AllocControl (player->GetValue());
g_game.player_id = player->GetValue();
g_game.player = Players.GetPlayer(player->GetValue());
g_game.char_id = character->GetValue();
g_game.character = &Char.CharList[character->GetValue()];
Char.FreeCharacterPreviews(); // From here on, character previews are no longer required
State::manager.RequestEnterState (GameTypeSelect);
}
@ -57,7 +57,7 @@ void CRegist::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, in
break;
case sf::Keyboard::Return:
if (focussed == textbuttons[1]) {
g_game.player_id = player->GetValue();
g_game.player = Players.GetPlayer(player->GetValue());
State::manager.RequestEnterState (NewPlayer);
} else QuitRegistration ();
break;
@ -70,7 +70,7 @@ void CRegist::Mouse (int button, int state, int x, int y) {
if (focussed == textbuttons[0])
QuitRegistration ();
else if (focussed == textbuttons[1]) {
g_game.player_id = player->GetValue();
g_game.player = Players.GetPlayer(player->GetValue());
State::manager.RequestEnterState (NewPlayer);
}
}
@ -133,7 +133,7 @@ void CRegist::Loop (double timestep) {
DrawGUIBackground(Winsys.scale);
sPlayerFrame->SetString(Players.GetName(player->GetValue()));
sPlayerFrame->SetString(Players.GetPlayer(player->GetValue())->name);
sPlayerFrame->Focussed(player->focussed());
Players.GetAvatarTexture(player->GetValue())->DrawFrame(
area.left + 60, AutoYPosN (40), texsize, texsize, 3, colWhite);

View File

@ -29,6 +29,7 @@ GNU General Public License for more details.
#include "course.h"
#include "track_marks.h"
#include "game_ctrl.h"
#include "tux.h"
#include "racing.h"
#include "winsys.h"
#include "physics.h"
@ -49,7 +50,7 @@ void CReset::Enter() {
}
void CReset::Loop(double time_step) {
CControl *ctrl = Players.GetCtrl (g_game.player_id);
CControl *ctrl = g_game.player->ctrl;
float elapsed_time = reset_timer.getElapsedTime().asSeconds();
static bool tux_visible = true;
static int tux_visible_count = 0;
@ -112,7 +113,7 @@ void CReset::Loop(double time_step) {
position_reset = true;
} // if elapsed time
if (tux_visible) Char.Draw (g_game.char_id);
if (tux_visible) g_game.character->shape->Draw();
if (++tux_visible_count > 3) {
tux_visible = (bool) !tux_visible;

View File

@ -34,7 +34,8 @@ GNU General Public License for more details.
CScore Score;
int CScore::AddScore (size_t list_idx, const TScore& score) {
int CScore::AddScore(const TCourse* course, const TScore& score) {
size_t list_idx = Course.GetCourseIdx(course);
if (list_idx >= Scorelist.size()) return 999;
if (score.points < 1) return 999;
@ -127,7 +128,7 @@ bool CScore::LoadHighScore () {
for (size_t i=0; i<list.Count(); i++) {
const string& line = list.Line(i);
string course = SPStrN (line, "course", "unknown");
size_t cidx = Course.GetCourseIdx (course);
TCourse* cidx = Course.GetCourse(course);
TScore score;
score.player = SPStrN (line, "plyr", "unknown");
@ -140,14 +141,16 @@ bool CScore::LoadHighScore () {
return true;
}
int CScore::CalcRaceResult () {
int CScore::CalcRaceResult() {
g_game.race_result = -1;
if (g_game.time <= g_game.time_req.x &&
g_game.herring >= g_game.herring_req.x) g_game.race_result = 0;
if (g_game.time <= g_game.time_req.y &&
g_game.herring >= g_game.herring_req.y) g_game.race_result = 1;
if (g_game.time <= g_game.time_req.z &&
g_game.herring >= g_game.herring_req.z) g_game.race_result = 2;
if (g_game.game_type == CUPRACING) {
if (g_game.time <= g_game.race->time.x &&
g_game.herring >= g_game.race->herrings.x) g_game.race_result = 0;
if (g_game.time <= g_game.race->time.y &&
g_game.herring >= g_game.race->herrings.y) g_game.race_result = 1;
if (g_game.time <= g_game.race->time.z &&
g_game.herring >= g_game.race->herrings.z) g_game.race_result = 2;
}
int herringpt = g_game.herring * 10;
double timept = Course.GetDimensions().y - (g_game.time * 10);
@ -158,9 +161,9 @@ int CScore::CalcRaceResult () {
TempScore.points = g_game.score;
TempScore.herrings = g_game.herring;
TempScore.time = g_game.time;
TempScore.player = Players.GetName (g_game.player_id);
TempScore.player = g_game.player->name;
return AddScore (g_game.course_id, TempScore);
return AddScore (g_game.course, TempScore);
}
// --------------------------------------------------------------------

View File

@ -46,7 +46,7 @@ private:
void Mouse(int button, int state, int x, int y);
void Motion(int x, int y);
public:
int AddScore (size_t list_idx, const TScore& score);
int AddScore(const TCourse* course, const TScore& score);
const TScoreList *GetScorelist (size_t list_idx) const;
void PrintScorelist (size_t list_idx) const;
bool SaveHighScore () const;

View File

@ -361,7 +361,7 @@ void ScreenshotN () {
string path = param.screenshot_dir;
path += SEP;
path += Course.CourseList[g_game.course_id].dir;
path += g_game.course->dir;
path += "_";
path += GetTimeString();
int type = SCREENSHOT_PROC;