Uniformized paranthese padding with AStyle, use AStyle 2.04
git-svn-id: https://svn.code.sf.net/p/extremetuxracer/code/branches/SFML2@491 0420edf4-82e4-42fc-9478-35b55e6d67a3master
parent
d351e0124c
commit
ee38139d2a
|
@ -4,4 +4,5 @@
|
|||
--indent=tab
|
||||
--indent-switches
|
||||
--pad-header
|
||||
--unpad-paren
|
||||
--keep-one-line-blocks
|
|
@ -52,7 +52,7 @@ CSound::~CSound() {
|
|||
FreeSounds();
|
||||
}
|
||||
|
||||
bool CSound::LoadChunk (const std::string& name, const std::string& filename) {
|
||||
bool CSound::LoadChunk(const std::string& name, const std::string& filename) {
|
||||
sounds.push_back(new TSound(param.sound_volume));
|
||||
if (!sounds.back()->data.loadFromFile(filename)) // Try loading sound buffer
|
||||
return false;
|
||||
|
@ -62,20 +62,20 @@ bool CSound::LoadChunk (const std::string& name, const std::string& filename) {
|
|||
}
|
||||
|
||||
// Load all soundfiles listed in "/sounds/sounds.lst"
|
||||
void CSound::LoadSoundList () {
|
||||
void CSound::LoadSoundList() {
|
||||
CSPList list(200);
|
||||
if (list.Load (param.sounds_dir, "sounds.lst")) {
|
||||
if (list.Load(param.sounds_dir, "sounds.lst")) {
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
string name = SPStrN (line, "name");
|
||||
string soundfile = SPStrN (line, "file");
|
||||
string path = MakePathStr (param.sounds_dir, soundfile);
|
||||
LoadChunk (name, path);
|
||||
string name = SPStrN(line, "name");
|
||||
string soundfile = SPStrN(line, "file");
|
||||
string path = MakePathStr(param.sounds_dir, soundfile);
|
||||
LoadChunk(name, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSound::FreeSounds () {
|
||||
void CSound::FreeSounds() {
|
||||
HaltAll();
|
||||
for (size_t i = 0; i < sounds.size(); i++)
|
||||
delete sounds[i];
|
||||
|
@ -83,7 +83,7 @@ void CSound::FreeSounds () {
|
|||
SoundIndex.clear();
|
||||
}
|
||||
|
||||
size_t CSound::GetSoundIdx (const string& name) const {
|
||||
size_t CSound::GetSoundIdx(const string& name) const {
|
||||
try {
|
||||
return SoundIndex.at(name);
|
||||
} catch (...) {
|
||||
|
@ -91,15 +91,15 @@ size_t CSound::GetSoundIdx (const string& name) const {
|
|||
}
|
||||
}
|
||||
|
||||
void CSound::SetVolume (size_t soundid, int volume) {
|
||||
void CSound::SetVolume(size_t soundid, int volume) {
|
||||
if (soundid >= sounds.size()) return;
|
||||
|
||||
volume = clamp(0, volume, MIX_MAX_VOLUME);
|
||||
sounds[soundid]->setVolume(volume);
|
||||
}
|
||||
|
||||
void CSound::SetVolume (const string& name, int volume) {
|
||||
SetVolume (GetSoundIdx (name), volume);
|
||||
void CSound::SetVolume(const string& name, int volume) {
|
||||
SetVolume(GetSoundIdx(name), volume);
|
||||
}
|
||||
|
||||
// ------------------- play -------------------------------------------
|
||||
|
@ -111,7 +111,7 @@ void CSound::Play(size_t soundid, bool loop) {
|
|||
}
|
||||
|
||||
void CSound::Play(const string& name, bool loop) {
|
||||
Play (GetSoundIdx (name), loop);
|
||||
Play(GetSoundIdx(name), loop);
|
||||
}
|
||||
|
||||
void CSound::Play(size_t soundid, bool loop, int volume) {
|
||||
|
@ -123,10 +123,10 @@ void CSound::Play(size_t soundid, bool loop, int volume) {
|
|||
}
|
||||
|
||||
void CSound::Play(const string& name, bool loop, int volume) {
|
||||
Play (GetSoundIdx (name), loop, volume);
|
||||
Play(GetSoundIdx(name), loop, volume);
|
||||
}
|
||||
|
||||
void CSound::Halt (size_t soundid) {
|
||||
void CSound::Halt(size_t soundid) {
|
||||
if (soundid >= sounds.size()) return;
|
||||
|
||||
// loop_count must be -1 (endless loop) for halt
|
||||
|
@ -134,11 +134,11 @@ void CSound::Halt (size_t soundid) {
|
|||
sounds[soundid]->player.stop();
|
||||
}
|
||||
|
||||
void CSound::Halt (const string& name) {
|
||||
Halt (GetSoundIdx (name));
|
||||
void CSound::Halt(const string& name) {
|
||||
Halt(GetSoundIdx(name));
|
||||
}
|
||||
|
||||
void CSound::HaltAll () {
|
||||
void CSound::HaltAll() {
|
||||
for (size_t i = 0; i < sounds.size(); i++) {
|
||||
sounds[i]->player.stop();
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ CMusic::~CMusic() {
|
|||
bool CMusic::LoadPiece(const string& name, const string& filename) {
|
||||
sf::Music* m = new sf::Music();
|
||||
if (!m->openFromFile(filename)) {
|
||||
Message ("could not load music", filename);
|
||||
Message("could not load music", filename);
|
||||
return false;
|
||||
}
|
||||
MusicIndex[name] = musics.size();
|
||||
|
@ -167,43 +167,43 @@ bool CMusic::LoadPiece(const string& name, const string& filename) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void CMusic::LoadMusicList () {
|
||||
void CMusic::LoadMusicList() {
|
||||
// --- music ---
|
||||
CSPList list(200);
|
||||
if (list.Load (param.music_dir, "music.lst")) {
|
||||
if (list.Load(param.music_dir, "music.lst")) {
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
string name = SPStrN (line, "name");
|
||||
string musicfile = SPStrN (line, "file");
|
||||
string path = MakePathStr (param.music_dir, musicfile);
|
||||
LoadPiece (name, path);
|
||||
string name = SPStrN(line, "name");
|
||||
string musicfile = SPStrN(line, "file");
|
||||
string path = MakePathStr(param.music_dir, musicfile);
|
||||
LoadPiece(name, path);
|
||||
}
|
||||
} else {
|
||||
Message ("could not load music.lst");
|
||||
Message("could not load music.lst");
|
||||
return;
|
||||
}
|
||||
|
||||
// --- racing themes ---
|
||||
list.Clear();
|
||||
ThemesIndex.clear();
|
||||
if (list.Load (param.music_dir, "racing_themes.lst")) {
|
||||
if (list.Load(param.music_dir, "racing_themes.lst")) {
|
||||
themes.resize(list.Count());
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
string name = SPStrN (line, "name");
|
||||
string name = SPStrN(line, "name");
|
||||
ThemesIndex[name] = i;
|
||||
string item = SPStrN (line, "race", "race_1");
|
||||
string item = SPStrN(line, "race", "race_1");
|
||||
themes[i].situation[0] = musics[MusicIndex[item]];
|
||||
item = SPStrN (line, "wonrace", "wonrace_1");
|
||||
item = SPStrN(line, "wonrace", "wonrace_1");
|
||||
themes[i].situation[1] = musics[MusicIndex[item]];
|
||||
item = SPStrN (line, "lostrace", "lostrace_1");
|
||||
item = SPStrN(line, "lostrace", "lostrace_1");
|
||||
themes[i].situation[2] = musics[MusicIndex[item]];
|
||||
}
|
||||
} else Message ("could not load racing_themes.lst");
|
||||
} else Message("could not load racing_themes.lst");
|
||||
}
|
||||
|
||||
void CMusic::FreeMusics () {
|
||||
Halt ();
|
||||
void CMusic::FreeMusics() {
|
||||
Halt();
|
||||
for (size_t i = 0; i < musics.size(); i++)
|
||||
delete musics[i];
|
||||
musics.clear();
|
||||
|
@ -215,7 +215,7 @@ void CMusic::FreeMusics () {
|
|||
curr_music = NULL;
|
||||
}
|
||||
|
||||
size_t CMusic::GetMusicIdx (const string& name) const {
|
||||
size_t CMusic::GetMusicIdx(const string& name) const {
|
||||
try {
|
||||
return MusicIndex.at(name);
|
||||
} catch (...) {
|
||||
|
@ -223,7 +223,7 @@ size_t CMusic::GetMusicIdx (const string& name) const {
|
|||
}
|
||||
}
|
||||
|
||||
size_t CMusic::GetThemeIdx (const string& theme) const {
|
||||
size_t CMusic::GetThemeIdx(const string& theme) const {
|
||||
try {
|
||||
return ThemesIndex.at(theme);
|
||||
} catch (...) {
|
||||
|
@ -231,14 +231,14 @@ size_t CMusic::GetThemeIdx (const string& theme) const {
|
|||
}
|
||||
}
|
||||
|
||||
void CMusic::SetVolume (int volume) {
|
||||
void CMusic::SetVolume(int volume) {
|
||||
int vol = clamp(0, volume, MIX_MAX_VOLUME);
|
||||
if (curr_music)
|
||||
curr_music->setVolume(volume);
|
||||
curr_volume = vol;
|
||||
}
|
||||
|
||||
bool CMusic::Play (sf::Music* music, bool loop, int volume) {
|
||||
bool CMusic::Play(sf::Music* music, bool loop, int volume) {
|
||||
if (!music)
|
||||
return false;
|
||||
|
||||
|
@ -261,7 +261,7 @@ bool CMusic::Play(size_t musid, bool loop) {
|
|||
}
|
||||
|
||||
bool CMusic::Play(const string& name, bool loop) {
|
||||
return Play (GetMusicIdx(name), loop);
|
||||
return Play(GetMusicIdx(name), loop);
|
||||
}
|
||||
|
||||
bool CMusic::Play(size_t musid, bool loop, int volume) {
|
||||
|
@ -271,17 +271,17 @@ bool CMusic::Play(size_t musid, bool loop, int volume) {
|
|||
}
|
||||
|
||||
bool CMusic::Play(const string& name, bool loop, int volume) {
|
||||
return Play (GetMusicIdx (name), loop, volume);
|
||||
return Play(GetMusicIdx(name), loop, volume);
|
||||
}
|
||||
|
||||
bool CMusic::PlayTheme (size_t theme, ESituation situation) {
|
||||
bool CMusic::PlayTheme(size_t theme, ESituation situation) {
|
||||
if (theme >= themes.size()) return false;
|
||||
if (situation >= SITUATION_COUNT) return false;
|
||||
sf::Music* music = themes[theme].situation[situation];
|
||||
return Play (music, -1, curr_volume);
|
||||
return Play(music, -1, curr_volume);
|
||||
}
|
||||
|
||||
void CMusic::Halt () {
|
||||
void CMusic::Halt() {
|
||||
if (curr_music) {
|
||||
curr_music->stop();
|
||||
curr_music = NULL;
|
||||
|
|
32
src/audio.h
32
src/audio.h
|
@ -34,23 +34,23 @@ private:
|
|||
map<string, size_t> SoundIndex;
|
||||
public:
|
||||
~CSound();
|
||||
bool LoadChunk (const std::string& name, const std::string& filename);
|
||||
void LoadSoundList ();
|
||||
size_t GetSoundIdx (const string& name) const;
|
||||
bool LoadChunk(const std::string& name, const std::string& filename);
|
||||
void LoadSoundList();
|
||||
size_t GetSoundIdx(const string& name) const;
|
||||
|
||||
void SetVolume (size_t soundid, int volume);
|
||||
void SetVolume (const string& name, int volume);
|
||||
void SetVolume(size_t soundid, int volume);
|
||||
void SetVolume(const string& name, int volume);
|
||||
|
||||
void Play(size_t soundid, bool loop);
|
||||
void Play(const string& name, bool loop);
|
||||
void Play(size_t soundid, bool loop, int volume);
|
||||
void Play(const string& name, bool loop, int volume);
|
||||
|
||||
void Halt (size_t soundid);
|
||||
void Halt (const string& name);
|
||||
void HaltAll ();
|
||||
void Halt(size_t soundid);
|
||||
void Halt(const string& name);
|
||||
void HaltAll();
|
||||
|
||||
void FreeSounds ();
|
||||
void FreeSounds();
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -86,18 +86,18 @@ public:
|
|||
~CMusic();
|
||||
|
||||
bool LoadPiece(const string& name, const string& filename);
|
||||
void LoadMusicList ();
|
||||
size_t GetMusicIdx (const string& name) const;
|
||||
size_t GetThemeIdx (const string& theme) const;
|
||||
void LoadMusicList();
|
||||
size_t GetMusicIdx(const string& name) const;
|
||||
size_t GetThemeIdx(const string& theme) const;
|
||||
|
||||
void SetVolume (int volume);
|
||||
void SetVolume(int volume);
|
||||
bool Play(size_t musid, bool loop);
|
||||
bool Play(const string& name, bool loop);
|
||||
bool Play(size_t musid, bool loop, int volume);
|
||||
bool Play(const string& name, bool loop, int volume);
|
||||
bool PlayTheme (size_t theme, ESituation situation);
|
||||
void Halt ();
|
||||
void FreeMusics ();
|
||||
bool PlayTheme(size_t theme, ESituation situation);
|
||||
void Halt();
|
||||
void FreeMusics();
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
|
|
@ -55,49 +55,49 @@ const sf::Color colSky = TColor(0.82, 0.86, 0.88, 1.0);
|
|||
// print utils
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void PrintInt (const int val) {
|
||||
void PrintInt(const int val) {
|
||||
cout << "Integer: " << val << '\n';
|
||||
}
|
||||
|
||||
void PrintInt (const string& s, const int val) {
|
||||
void PrintInt(const string& s, const int val) {
|
||||
cout << s << val << endl;
|
||||
}
|
||||
|
||||
void PrintStr (const char *val) {
|
||||
void PrintStr(const char *val) {
|
||||
cout << val << '\n';
|
||||
}
|
||||
|
||||
void PrintString (const string& s) {
|
||||
void PrintString(const string& s) {
|
||||
cout << s << endl;
|
||||
}
|
||||
|
||||
void PrintDouble (const double val) {
|
||||
void PrintDouble(const double val) {
|
||||
cout.precision(4);
|
||||
cout << val << '\n';
|
||||
}
|
||||
|
||||
void PrintVector4 (const TVector4d& v) {
|
||||
void PrintVector4(const TVector4d& v) {
|
||||
cout.precision(3);
|
||||
cout << v.x << " " << v.y << " " << v.z << " " << v.w << '\n';
|
||||
}
|
||||
|
||||
void PrintColor (const sf::Color& v) {
|
||||
void PrintColor(const sf::Color& v) {
|
||||
cout.precision(3);
|
||||
cout << v.r << " " << v.g << " " << v.b << '\n';
|
||||
}
|
||||
|
||||
void PrintVector2 (const TVector2d& v) {
|
||||
void PrintVector2(const TVector2d& v) {
|
||||
cout.precision(3);
|
||||
cout << v.x << " " << v.y << '\n';
|
||||
}
|
||||
|
||||
void PrintVector (const TVector3d& v) {
|
||||
void PrintVector(const TVector3d& v) {
|
||||
cout.precision(5);
|
||||
cout << v.x << " " << v.y << " " << v.z << '\n';
|
||||
}
|
||||
|
||||
template<int x, int y>
|
||||
void PrintMatrix (const TMatrix<x, y>& mat) {
|
||||
void PrintMatrix(const TMatrix<x, y>& mat) {
|
||||
cout << '\n';
|
||||
cout.precision(3);
|
||||
for (int i=0; i<x; i++) {
|
||||
|
@ -112,7 +112,7 @@ void PrintMatrix (const TMatrix<x, y>& mat) {
|
|||
template void PrintMatrix<4, 4>(const TMatrix<4, 4>& mat);
|
||||
template void PrintMatrix<3, 3>(const TMatrix<3, 3>& mat);
|
||||
|
||||
void PrintQuaternion (const TQuaternion& q) {
|
||||
void PrintQuaternion(const TQuaternion& q) {
|
||||
cout.precision(5);
|
||||
cout << "Quaternion: " << q.x << " " << q.y << " " << q.z << " " << q.w << '\n';
|
||||
}
|
||||
|
@ -121,13 +121,13 @@ void PrintQuaternion (const TQuaternion& q) {
|
|||
// message utils
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
static CSPList msg_list (100);
|
||||
static CSPList msg_list(100);
|
||||
|
||||
void SaveMessages () {
|
||||
msg_list.Save (param.config_dir, "messages");
|
||||
void SaveMessages() {
|
||||
msg_list.Save(param.config_dir, "messages");
|
||||
}
|
||||
|
||||
void Message (const char *msg, const char *desc) {
|
||||
void Message(const char *msg, const char *desc) {
|
||||
if (*msg == 0 && *desc == 0) {
|
||||
cout << '\n';
|
||||
return;
|
||||
|
@ -136,23 +136,23 @@ void Message (const char *msg, const char *desc) {
|
|||
string aa = msg;
|
||||
string bb = desc;
|
||||
cout << aa << " " << bb << '\n';
|
||||
msg_list.Add (aa + bb);
|
||||
msg_list.Add(aa + bb);
|
||||
}
|
||||
|
||||
void Message (const char *msg) {
|
||||
void Message(const char *msg) {
|
||||
cout << msg << '\n';
|
||||
if (*msg != 0)
|
||||
msg_list.Add (msg);
|
||||
msg_list.Add(msg);
|
||||
}
|
||||
|
||||
void Message (const string& a, const string& b) {
|
||||
void Message(const string& a, const string& b) {
|
||||
cout << a << ' ' << b << endl;
|
||||
msg_list.Add (a + b);
|
||||
msg_list.Add(a + b);
|
||||
}
|
||||
|
||||
void Message (const string& msg) {
|
||||
void Message(const string& msg) {
|
||||
cout << msg << endl;
|
||||
msg_list.Add (msg);
|
||||
msg_list.Add(msg);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -161,26 +161,26 @@ void Message (const string& msg) {
|
|||
|
||||
bool FileExists(const string& filename) {
|
||||
struct stat stat_info;
|
||||
if (stat (filename.c_str(), &stat_info) != 0) {
|
||||
if (errno != ENOENT) Message ("couldn't stat ", filename);
|
||||
if (stat(filename.c_str(), &stat_info) != 0) {
|
||||
if (errno != ENOENT) Message("couldn't stat ", filename);
|
||||
return false;
|
||||
} else return true;
|
||||
}
|
||||
|
||||
bool FileExists (const string& dir, const string& filename) {
|
||||
return FileExists (dir + SEP + filename);
|
||||
bool FileExists(const string& dir, const string& filename) {
|
||||
return FileExists(dir + SEP + filename);
|
||||
}
|
||||
|
||||
#ifndef OS_WIN32_MSC
|
||||
bool DirExists (const char *dirname) {
|
||||
bool DirExists(const char *dirname) {
|
||||
DIR *xdir;
|
||||
if ((xdir = opendir (dirname)) == 0)
|
||||
if ((xdir = opendir(dirname)) == 0)
|
||||
return ((errno != ENOENT) && (errno != ENOTDIR));
|
||||
if (closedir (xdir) != 0) Message ("Couldn't close directory", dirname);
|
||||
if (closedir(xdir) != 0) Message("Couldn't close directory", dirname);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool DirExists (const char *dirname) {
|
||||
bool DirExists(const char *dirname) {
|
||||
DWORD typ = GetFileAttributesA(dirname);
|
||||
if (typ == INVALID_FILE_ATTRIBUTES)
|
||||
return false; // Doesn't exist
|
||||
|
@ -193,21 +193,21 @@ bool DirExists (const char *dirname) {
|
|||
// date and time
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void GetTimeComponents (double time, int *min, int *sec, int *hundr) {
|
||||
*min = (int) (time / 60);
|
||||
void GetTimeComponents(double time, int *min, int *sec, int *hundr) {
|
||||
*min = (int)(time / 60);
|
||||
*sec = ((int) time) % 60;
|
||||
*hundr = ((int) (time * 100 + 0.5) ) % 100;
|
||||
*hundr = ((int)(time * 100 + 0.5)) % 100;
|
||||
}
|
||||
|
||||
string GetTimeString () {
|
||||
string GetTimeString() {
|
||||
time_t rawtime;
|
||||
time (&rawtime);
|
||||
struct tm* timeinfo = localtime (&rawtime);
|
||||
time(&rawtime);
|
||||
struct tm* timeinfo = localtime(&rawtime);
|
||||
|
||||
string line = Int_StrN(timeinfo->tm_mon + 1);
|
||||
line += '_' + Int_StrN(timeinfo->tm_mday);
|
||||
line += '_' + Int_StrN(timeinfo->tm_hour);
|
||||
line += Int_StrN (timeinfo->tm_min);
|
||||
line += Int_StrN (timeinfo->tm_sec);
|
||||
line += Int_StrN(timeinfo->tm_min);
|
||||
line += Int_StrN(timeinfo->tm_sec);
|
||||
return line;
|
||||
}
|
||||
|
|
40
src/common.h
40
src/common.h
|
@ -79,44 +79,44 @@ extern const sf::Color colSky;
|
|||
// --------------------------------------------------------------------
|
||||
// some simple functions to print out values on the
|
||||
// terminal. Only used for development.
|
||||
void PrintInt (const int val);
|
||||
void PrintInt (const string& s, const int val);
|
||||
void PrintStr (const char *val);
|
||||
void PrintString (const string& s);
|
||||
void PrintDouble (const double val);
|
||||
void PrintVector (const TVector3d& v);
|
||||
void PrintVector4 (const TVector4d& v);
|
||||
void PrintInt(const int val);
|
||||
void PrintInt(const string& s, const int val);
|
||||
void PrintStr(const char *val);
|
||||
void PrintString(const string& s);
|
||||
void PrintDouble(const double val);
|
||||
void PrintVector(const TVector3d& v);
|
||||
void PrintVector4(const TVector4d& v);
|
||||
void PrintColor(const sf::Color& c);
|
||||
void PrintVector2 (const TVector2d& v);
|
||||
void PrintVector2(const TVector2d& v);
|
||||
|
||||
template<int x, int y>
|
||||
void PrintMatrix (const TMatrix<x, y>& mat);
|
||||
void PrintQuaternion (const TQuaternion& q);
|
||||
void PrintMatrix(const TMatrix<x, y>& mat);
|
||||
void PrintQuaternion(const TQuaternion& q);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// file utils
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
bool FileExists (const string& filename);
|
||||
bool FileExists (const string& dir, const string& filename);
|
||||
bool DirExists (const char *dirname);
|
||||
bool FileExists(const string& filename);
|
||||
bool FileExists(const string& dir, const string& filename);
|
||||
bool DirExists(const char *dirname);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// message utils
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void Message (const char *msg, const char *desc);
|
||||
void Message (const char *msg);
|
||||
void Message (const string& a, const string& b);
|
||||
void Message (const string& a);
|
||||
void SaveMessages ();
|
||||
void Message(const char *msg, const char *desc);
|
||||
void Message(const char *msg);
|
||||
void Message(const string& a, const string& b);
|
||||
void Message(const string& a);
|
||||
void SaveMessages();
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// date and time
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void GetTimeComponents (double time, int *min, int *sec, int *hundr);
|
||||
string GetTimeString ();
|
||||
void GetTimeComponents(double time, int *min, int *sec, int *hundr);
|
||||
string GetTimeString();
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -61,7 +61,7 @@ static TUpDown* detail_level;
|
|||
static TWidget* textbuttons[2];
|
||||
static TLabel* descriptions[5];
|
||||
|
||||
void SetConfig () {
|
||||
void SetConfig() {
|
||||
if (mus_vol->GetValue() != param.music_volume ||
|
||||
sound_vol->GetValue() != param.sound_volume ||
|
||||
language->GetValue() != param.language ||
|
||||
|
@ -80,20 +80,20 @@ void SetConfig () {
|
|||
// the followind config params don't require a new VideoMode
|
||||
// they only must stored in the param structure (and saved)
|
||||
param.music_volume = mus_vol->GetValue();
|
||||
Music.SetVolume (param.music_volume);
|
||||
Music.SetVolume(param.music_volume);
|
||||
param.sound_volume = sound_vol->GetValue();
|
||||
param.perf_level = detail_level->GetValue();
|
||||
FT.SetFontFromSettings();
|
||||
if (param.language != language->GetValue()) {
|
||||
param.language = language->GetValue();
|
||||
Trans.LoadTranslations (param.language);
|
||||
Trans.LoadTranslations(param.language);
|
||||
}
|
||||
SaveConfigFile ();
|
||||
SaveConfigFile();
|
||||
}
|
||||
State::manager.RequestEnterState(*State::manager.PreviousState());
|
||||
}
|
||||
|
||||
void CGameConfig::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CGameConfig::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
|
||||
switch (key) {
|
||||
|
@ -101,13 +101,13 @@ void CGameConfig::Keyb (sf::Keyboard::Key key, bool special, bool release, int x
|
|||
param.ui_snow = !param.ui_snow;
|
||||
break;
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestEnterState (*State::manager.PreviousState());
|
||||
State::manager.RequestEnterState(*State::manager.PreviousState());
|
||||
break;
|
||||
case sf::Keyboard::Return:
|
||||
if (textbuttons[0]->focussed())
|
||||
State::manager.RequestEnterState (*State::manager.PreviousState());
|
||||
State::manager.RequestEnterState(*State::manager.PreviousState());
|
||||
else if (textbuttons[1]->focussed())
|
||||
SetConfig ();
|
||||
SetConfig();
|
||||
break;
|
||||
default:
|
||||
KeyGUI(key, 0, release);
|
||||
|
@ -115,21 +115,21 @@ void CGameConfig::Keyb (sf::Keyboard::Key key, bool special, bool release, int x
|
|||
}
|
||||
}
|
||||
|
||||
void CGameConfig::Mouse (int button, int state, int x, int y) {
|
||||
void CGameConfig::Mouse(int button, int state, int x, int y) {
|
||||
if (state == 1) {
|
||||
TWidget* focussed = ClickGUI(x, y);
|
||||
|
||||
if (focussed == textbuttons[0])
|
||||
State::manager.RequestEnterState (*State::manager.PreviousState());
|
||||
State::manager.RequestEnterState(*State::manager.PreviousState());
|
||||
else if (focussed == textbuttons[1])
|
||||
SetConfig ();
|
||||
SetConfig();
|
||||
}
|
||||
}
|
||||
|
||||
void CGameConfig::Motion (int x, int y) {
|
||||
void CGameConfig::Motion(int x, int y) {
|
||||
MouseMoveGUI(x, y);
|
||||
|
||||
if (param.ui_snow) push_ui_snow (cursor_pos);
|
||||
if (param.ui_snow) push_ui_snow(cursor_pos);
|
||||
}
|
||||
|
||||
// ------------------ Init --------------------------------------------
|
||||
|
@ -138,21 +138,21 @@ static TArea area;
|
|||
static int dd;
|
||||
|
||||
void CGameConfig::Enter() {
|
||||
Winsys.ShowCursor (!param.ice_cursor);
|
||||
Winsys.KeyRepeat (true);
|
||||
Winsys.ShowCursor(!param.ice_cursor);
|
||||
Winsys.KeyRepeat(true);
|
||||
|
||||
for (int i=0; i<NUM_RESOLUTIONS; i++) res_names[i] = Winsys.GetResName (i);
|
||||
for (int i=0; i<NUM_RESOLUTIONS; i++) res_names[i] = Winsys.GetResName(i);
|
||||
|
||||
int framewidth = 550 * Winsys.scale;
|
||||
area = AutoAreaN (30, 80, framewidth);
|
||||
FT.AutoSizeN (4);
|
||||
dd = FT.AutoDistanceN (3);
|
||||
area = AutoAreaN(30, 80, framewidth);
|
||||
FT.AutoSizeN(4);
|
||||
dd = FT.AutoDistanceN(3);
|
||||
if (dd < 36) dd = 36;
|
||||
int rightpos = area.right -48;
|
||||
|
||||
ResetGUI();
|
||||
int siz = FT.AutoSizeN(5);
|
||||
fullscreen = AddCheckbox (area.left, area.top, framewidth-16, Trans.Text(31));
|
||||
fullscreen = AddCheckbox(area.left, area.top, framewidth-16, Trans.Text(31));
|
||||
fullscreen->checked = param.fullscreen;
|
||||
|
||||
resolution = AddUpDown(rightpos, area.top+dd*1, 0, NUM_RESOLUTIONS-1, (int)param.res_type);
|
||||
|
@ -161,9 +161,9 @@ void CGameConfig::Enter() {
|
|||
language = AddUpDown(rightpos, area.top+dd*4, 0, (int)Trans.languages.size() - 1, (int)param.language);
|
||||
detail_level = AddUpDown(rightpos, area.top+dd*5, 1, 4, param.perf_level);
|
||||
|
||||
textbuttons[0] = AddTextButton (Trans.Text(28), area.left+50, AutoYPosN (80), siz);
|
||||
double len = FT.GetTextWidth (Trans.Text(8));
|
||||
textbuttons[1] = AddTextButton (Trans.Text(15), area.right-len-50, AutoYPosN (80), siz);
|
||||
textbuttons[0] = AddTextButton(Trans.Text(28), area.left+50, AutoYPosN(80), siz);
|
||||
double len = FT.GetTextWidth(Trans.Text(8));
|
||||
textbuttons[1] = AddTextButton(Trans.Text(15), area.right-len-50, AutoYPosN(80), siz);
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
descriptions[i] = AddLabel(Trans.Text(32 + i), area.left, area.top + dd*(i + 1), colWhite);
|
||||
|
@ -171,12 +171,12 @@ void CGameConfig::Enter() {
|
|||
Music.Play(param.config_music, true);
|
||||
}
|
||||
|
||||
void CGameConfig::Loop (double time_step) {
|
||||
void CGameConfig::Loop(double time_step) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow (time_step);
|
||||
update_ui_snow(time_step);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ void CGameConfig::Loop (double time_step) {
|
|||
// DrawFrameX (area.left, area.top, area.right-area.left, area.bottom - area.top,
|
||||
// 0, colMBackgr, colBlack, 0.2);
|
||||
|
||||
FT.AutoSizeN (4);
|
||||
FT.AutoSizeN(4);
|
||||
|
||||
descriptions[0]->Focussed(resolution->focussed());
|
||||
descriptions[1]->Focussed(mus_vol->focussed());
|
||||
|
@ -193,23 +193,23 @@ void CGameConfig::Loop (double time_step) {
|
|||
descriptions[3]->Focussed(language->focussed());
|
||||
descriptions[4]->Focussed(detail_level->focussed());
|
||||
|
||||
FT.SetColor (colWhite);
|
||||
FT.DrawString (area.left+240, area.top + dd + 3, res_names[resolution->GetValue()]);
|
||||
FT.DrawString (area.left+240, area.top + dd*2 + 3, Int_StrN (mus_vol->GetValue()));
|
||||
FT.DrawString (area.left+240, area.top + dd*3 + 3, Int_StrN (sound_vol->GetValue()));
|
||||
FT.DrawString (area.left+240, area.top + dd*4 + 3, Trans.languages[language->GetValue()].language);
|
||||
FT.DrawString (area.left+240, area.top + dd*5 + 3, Int_StrN (detail_level->GetValue()));
|
||||
FT.SetColor(colWhite);
|
||||
FT.DrawString(area.left+240, area.top + dd + 3, res_names[resolution->GetValue()]);
|
||||
FT.DrawString(area.left+240, area.top + dd*2 + 3, Int_StrN(mus_vol->GetValue()));
|
||||
FT.DrawString(area.left+240, area.top + dd*3 + 3, Int_StrN(sound_vol->GetValue()));
|
||||
FT.DrawString(area.left+240, area.top + dd*4 + 3, Trans.languages[language->GetValue()].language);
|
||||
FT.DrawString(area.left+240, area.top + dd*5 + 3, Int_StrN(detail_level->GetValue()));
|
||||
|
||||
FT.SetColor (colLGrey);
|
||||
FT.AutoSizeN (3);
|
||||
FT.DrawString (CENTER, AutoYPosN (68), Trans.Text(41));
|
||||
FT.DrawString (CENTER, AutoYPosN (72), Trans.Text(42));
|
||||
FT.SetColor(colLGrey);
|
||||
FT.AutoSizeN(3);
|
||||
FT.DrawString(CENTER, AutoYPosN(68), Trans.Text(41));
|
||||
FT.DrawString(CENTER, AutoYPosN(72), Trans.Text(42));
|
||||
|
||||
DrawGUI();
|
||||
|
||||
Winsys.SwapBuffers ();
|
||||
Winsys.SwapBuffers();
|
||||
}
|
||||
|
||||
void CGameConfig::Exit() {
|
||||
Winsys.KeyRepeat (false);
|
||||
Winsys.KeyRepeat(false);
|
||||
}
|
||||
|
|
358
src/course.cpp
358
src/course.cpp
|
@ -37,7 +37,7 @@ GNU General Public License for more details.
|
|||
|
||||
CCourse Course;
|
||||
|
||||
CCourse::CCourse () {
|
||||
CCourse::CCourse() {
|
||||
terrain = NULL;
|
||||
elevation = NULL;
|
||||
nmls = NULL;
|
||||
|
@ -48,12 +48,12 @@ CCourse::CCourse () {
|
|||
}
|
||||
|
||||
CCourse::~CCourse() {
|
||||
FreeCourseList ();
|
||||
ResetCourse ();
|
||||
FreeCourseList();
|
||||
ResetCourse();
|
||||
}
|
||||
|
||||
double CCourse::GetBaseHeight (double distance) const {
|
||||
double slope = tan (ANGLES_TO_RADIANS (curr_course->angle));
|
||||
double CCourse::GetBaseHeight(double distance) const {
|
||||
double slope = tan(ANGLES_TO_RADIANS(curr_course->angle));
|
||||
double base_height;
|
||||
|
||||
base_height = -slope * distance -
|
||||
|
@ -61,16 +61,16 @@ double CCourse::GetBaseHeight (double distance) const {
|
|||
return base_height;
|
||||
}
|
||||
|
||||
double CCourse::GetMaxHeight (double distance) const {
|
||||
return GetBaseHeight (distance) + curr_course->scale;
|
||||
double CCourse::GetMaxHeight(double distance) const {
|
||||
return GetBaseHeight(distance) + curr_course->scale;
|
||||
}
|
||||
|
||||
void CCourse::GetDivisions (int *x, int *y) const {
|
||||
void CCourse::GetDivisions(int *x, int *y) const {
|
||||
*x = nx;
|
||||
*y = ny;
|
||||
}
|
||||
|
||||
const TPolyhedron& CCourse::GetPoly (size_t type) const {
|
||||
const TPolyhedron& CCourse::GetPoly(size_t type) const {
|
||||
return PolyArr[ObjTypes[type].poly];
|
||||
}
|
||||
|
||||
|
@ -85,11 +85,11 @@ size_t CCourse::GetCourseIdx(const TCourse* course) const {
|
|||
return idx;
|
||||
}
|
||||
|
||||
void CCourse::CalcNormals () {
|
||||
void CCourse::CalcNormals() {
|
||||
for (int y=0; y<ny; y++) {
|
||||
for (int x=0; x<nx; x++) {
|
||||
TVector3d nml(0.0, 0.0, 0.0);
|
||||
TVector3d p0 (XCD(x), ELEV(x,y), ZCD(y));
|
||||
TVector3d p0(XCD(x), ELEV(x,y), ZCD(y));
|
||||
|
||||
if ((x + y) % 2 == 0) {
|
||||
if (x > 0 && y > 0) {
|
||||
|
@ -97,16 +97,16 @@ void CCourse::CalcNormals () {
|
|||
TVector3d p2 = NMLPOINT(x-1,y-1);
|
||||
TVector3d v1 = p1 - p0;
|
||||
TVector3d v2 = p2 - p0;
|
||||
TVector3d n = CrossProduct (v2, v1);
|
||||
TVector3d n = CrossProduct(v2, v1);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
||||
p1 = NMLPOINT (x-1, y-1);
|
||||
p2 = NMLPOINT (x-1, y);
|
||||
p1 = NMLPOINT(x-1, y-1);
|
||||
p2 = NMLPOINT(x-1, y);
|
||||
v1 = p1 - p0;
|
||||
v2 = p2 - p0;
|
||||
n = CrossProduct (v2, v1);
|
||||
n = CrossProduct(v2, v1);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
@ -116,7 +116,7 @@ void CCourse::CalcNormals () {
|
|||
TVector3d p2 = NMLPOINT(x-1,y+1);
|
||||
TVector3d v1 = p1 - p0;
|
||||
TVector3d v2 = p2 - p0;
|
||||
TVector3d n = CrossProduct (v2, v1);
|
||||
TVector3d n = CrossProduct(v2, v1);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
@ -125,7 +125,7 @@ void CCourse::CalcNormals () {
|
|||
p2 = NMLPOINT(x ,y+1);
|
||||
v1 = p1 - p0;
|
||||
v2 = p2 - p0;
|
||||
n = CrossProduct (v2, v1);
|
||||
n = CrossProduct(v2, v1);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
@ -135,7 +135,7 @@ void CCourse::CalcNormals () {
|
|||
TVector3d p2 = NMLPOINT(x+1,y-1);
|
||||
TVector3d v1 = p1 - p0;
|
||||
TVector3d v2 = p2 - p0;
|
||||
TVector3d n = CrossProduct (v2, v1);
|
||||
TVector3d n = CrossProduct(v2, v1);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
@ -144,7 +144,7 @@ void CCourse::CalcNormals () {
|
|||
p2 = NMLPOINT(x ,y-1);
|
||||
v1 = p1 - p0;
|
||||
v2 = p2 - p0;
|
||||
n = CrossProduct (v2, v1);
|
||||
n = CrossProduct(v2, v1);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
@ -154,7 +154,7 @@ void CCourse::CalcNormals () {
|
|||
TVector3d p2 = NMLPOINT(x+1,y+1);
|
||||
TVector3d v1 = p1 - p0;
|
||||
TVector3d v2 = p2 - p0;
|
||||
TVector3d n = CrossProduct (v1, v2);
|
||||
TVector3d n = CrossProduct(v1, v2);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
@ -163,7 +163,7 @@ void CCourse::CalcNormals () {
|
|||
p2 = NMLPOINT(x ,y+1);
|
||||
v1 = p1 - p0;
|
||||
v2 = p2 - p0;
|
||||
n = CrossProduct (v1, v2);
|
||||
n = CrossProduct(v1, v2);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
@ -174,7 +174,7 @@ void CCourse::CalcNormals () {
|
|||
TVector3d p2 = NMLPOINT(x-1,y);
|
||||
TVector3d v1 = p1 - p0;
|
||||
TVector3d v2 = p2 - p0;
|
||||
TVector3d n = CrossProduct (v2, v1);
|
||||
TVector3d n = CrossProduct(v2, v1);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
@ -184,7 +184,7 @@ void CCourse::CalcNormals () {
|
|||
TVector3d p2 = NMLPOINT(x ,y+1);
|
||||
TVector3d v1 = p1 - p0;
|
||||
TVector3d v2 = p2 - p0;
|
||||
TVector3d n = CrossProduct (v2, v1);
|
||||
TVector3d n = CrossProduct(v2, v1);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
@ -194,7 +194,7 @@ void CCourse::CalcNormals () {
|
|||
TVector3d p2 = NMLPOINT(x ,y-1);
|
||||
TVector3d v1 = p1 - p0;
|
||||
TVector3d v2 = p2 - p0;
|
||||
TVector3d n = CrossProduct (v2, v1);
|
||||
TVector3d n = CrossProduct(v2, v1);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
@ -204,7 +204,7 @@ void CCourse::CalcNormals () {
|
|||
TVector3d p2 = NMLPOINT(x ,y+1);
|
||||
TVector3d v1 = p1 - p0;
|
||||
TVector3d v2 = p2 - p0;
|
||||
TVector3d n = CrossProduct (v1, v2);
|
||||
TVector3d n = CrossProduct(v1, v2);
|
||||
|
||||
n.Norm();
|
||||
nml += n;
|
||||
|
@ -218,15 +218,15 @@ void CCourse::CalcNormals () {
|
|||
}
|
||||
}
|
||||
|
||||
void CCourse::MakeCourseNormals () {
|
||||
void CCourse::MakeCourseNormals() {
|
||||
if (nmls != NULL) delete[] nmls;
|
||||
try {
|
||||
nmls = new TVector3d[nx * ny];
|
||||
} catch (...) {
|
||||
nmls = NULL;
|
||||
Message ("Allocation failed in MakeCourseNormals");
|
||||
Message("Allocation failed in MakeCourseNormals");
|
||||
}
|
||||
CalcNormals ();
|
||||
CalcNormals();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -261,7 +261,7 @@ void CCourse::FillGlArrays() {
|
|||
}
|
||||
}
|
||||
|
||||
void CCourse::MakeStandardPolyhedrons () {
|
||||
void CCourse::MakeStandardPolyhedrons() {
|
||||
PolyArr.resize(2);
|
||||
|
||||
// polyhedron "none"
|
||||
|
@ -312,14 +312,14 @@ void CCourse::MakeStandardPolyhedrons () {
|
|||
PolyArr[1].polygons[7].vertices[2] = 3;
|
||||
}
|
||||
|
||||
void CCourse::FreeTerrainTextures () {
|
||||
void CCourse::FreeTerrainTextures() {
|
||||
for (size_t i=0; i<TerrList.size(); i++) {
|
||||
delete TerrList[i].texture;
|
||||
TerrList[i].texture = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void CCourse::FreeObjectTextures () {
|
||||
void CCourse::FreeObjectTextures() {
|
||||
for (size_t i=0; i<ObjTypes.size(); i++) {
|
||||
delete ObjTypes[i].texture;
|
||||
ObjTypes[i].texture = NULL;
|
||||
|
@ -330,11 +330,11 @@ void CCourse::FreeObjectTextures () {
|
|||
// LoadElevMap
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
bool CCourse::LoadElevMap () {
|
||||
bool CCourse::LoadElevMap() {
|
||||
sf::Image img;
|
||||
|
||||
if (!img.loadFromFile(CourseDir + SEP "elev.png")) {
|
||||
Message ("unable to open elev.png");
|
||||
Message("unable to open elev.png");
|
||||
return false;
|
||||
}
|
||||
img.flipVertically();
|
||||
|
@ -344,11 +344,11 @@ bool CCourse::LoadElevMap () {
|
|||
try {
|
||||
elevation = new double[nx * ny];
|
||||
} catch (...) {
|
||||
Message ("Allocation failed in LoadElevMap");
|
||||
Message("Allocation failed in LoadElevMap");
|
||||
return false;
|
||||
}
|
||||
|
||||
double slope = tan (ANGLES_TO_RADIANS (curr_course->angle));
|
||||
double slope = tan(ANGLES_TO_RADIANS(curr_course->angle));
|
||||
int pad = 0;
|
||||
int depth = 4;
|
||||
const uint8_t* data = img.getPixelsPtr();
|
||||
|
@ -368,11 +368,11 @@ bool CCourse::LoadElevMap () {
|
|||
// LoadItemList
|
||||
// ====================================================================
|
||||
|
||||
void CCourse::LoadItemList () {
|
||||
CSPList list (16000);
|
||||
void CCourse::LoadItemList() {
|
||||
CSPList list(16000);
|
||||
|
||||
if (!list.Load (CourseDir, "items.lst")) {
|
||||
Message ("could not load items list");
|
||||
if (!list.Load(CourseDir, "items.lst")) {
|
||||
Message("could not load items list");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -380,14 +380,14 @@ void CCourse::LoadItemList () {
|
|||
NocollArr.clear();
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
int x = SPIntN (line, "x", 0);
|
||||
int z = SPIntN (line, "z", 0);
|
||||
double height = SPFloatN (line, "height", 1);
|
||||
double diam = SPFloatN (line, "diam", 1);
|
||||
int x = SPIntN(line, "x", 0);
|
||||
int z = SPIntN(line, "z", 0);
|
||||
double height = SPFloatN(line, "height", 1);
|
||||
double diam = SPFloatN(line, "diam", 1);
|
||||
double xx = (nx - x) / (double)(nx - 1.0) * curr_course->size.x;
|
||||
double zz = -(ny - z) / (double)(ny - 1.0) * curr_course->size.y;
|
||||
|
||||
string name = SPStrN (line, "name");
|
||||
string name = SPStrN(line, "name");
|
||||
size_t type = ObjectIndex[name];
|
||||
if (ObjTypes[type].texture == NULL && ObjTypes[type].drawable) {
|
||||
string terrpath = param.obj_dir + SEP + ObjTypes[type].textureFile;
|
||||
|
@ -405,7 +405,7 @@ void CCourse::LoadItemList () {
|
|||
// -------------------- LoadObjectMap ---------------------------------
|
||||
|
||||
|
||||
static int GetObject (const unsigned char* pixel) {
|
||||
static int GetObject(const unsigned char* pixel) {
|
||||
int r = pixel[0];
|
||||
int g = pixel[1];
|
||||
int b = pixel[2];
|
||||
|
@ -432,19 +432,19 @@ const double sizefact[6] = {0.5, 0.5, 0.7, 1.0, 1.4, 2.0};
|
|||
const double varfact[6] = {1.0, 1.0, 1.22, 1.41, 1.73, 2.0};
|
||||
const double diamfact = 1.4;
|
||||
|
||||
static void CalcRandomTrees (double baseheight, double basediam, double &height, double &diam) {
|
||||
static void CalcRandomTrees(double baseheight, double basediam, double &height, double &diam) {
|
||||
double hhh = baseheight * sizefact[g_game.treesize];
|
||||
double minsiz = hhh / varfact[g_game.treevar];
|
||||
double maxsiz = hhh * varfact[g_game.treevar];
|
||||
height = XRandom (minsiz, maxsiz);
|
||||
diam = XRandom (height/diamfact, height);
|
||||
height = XRandom(minsiz, maxsiz);
|
||||
diam = XRandom(height/diamfact, height);
|
||||
}
|
||||
|
||||
bool CCourse::LoadAndConvertObjectMap () {
|
||||
bool CCourse::LoadAndConvertObjectMap() {
|
||||
sf::Image treeImg;
|
||||
|
||||
if (!treeImg.loadFromFile (CourseDir + SEP "trees.png")) {
|
||||
Message ("unable to open trees.png");
|
||||
if (!treeImg.loadFromFile(CourseDir + SEP "trees.png")) {
|
||||
Message("unable to open trees.png");
|
||||
return false;
|
||||
}
|
||||
treeImg.flipVertically();
|
||||
|
@ -454,14 +454,14 @@ bool CCourse::LoadAndConvertObjectMap () {
|
|||
int depth = 4;
|
||||
const unsigned char* data = (unsigned char*)treeImg.getPixelsPtr();
|
||||
double height, diam;
|
||||
CSPList savelist (10000);
|
||||
CSPList savelist(10000);
|
||||
|
||||
CollArr.clear();
|
||||
NocollArr.clear();
|
||||
for (int y=0; y<ny; y++) {
|
||||
for (int x=0; x<nx; x++) {
|
||||
int imgidx = (x + nx * y) * depth + pad;
|
||||
int type = GetObject (&data[imgidx]);
|
||||
int type = GetObject(&data[imgidx]);
|
||||
if (type >= 0) {
|
||||
cnt++;
|
||||
double xx = (nx - x) / (double)(nx - 1.0) * curr_course->size.x;
|
||||
|
@ -475,13 +475,13 @@ bool CCourse::LoadAndConvertObjectMap () {
|
|||
// set random height and diam - see constants above
|
||||
switch (type) {
|
||||
case 5:
|
||||
CalcRandomTrees (2.5, 2.5, height, diam);
|
||||
CalcRandomTrees(2.5, 2.5, height, diam);
|
||||
break;
|
||||
case 6:
|
||||
CalcRandomTrees (3, 3, height, diam);
|
||||
CalcRandomTrees(3, 3, height, diam);
|
||||
break;
|
||||
case 7:
|
||||
CalcRandomTrees (1.2, 1.2, height, diam);
|
||||
CalcRandomTrees(1.2, 1.2, height, diam);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
@ -503,17 +503,17 @@ bool CCourse::LoadAndConvertObjectMap () {
|
|||
|
||||
string line = "*[name]";
|
||||
line += ObjTypes[type].name;
|
||||
SPSetIntN (line, "x", x);
|
||||
SPSetIntN (line, "z", y);
|
||||
SPSetFloatN (line, "height", height, 1);
|
||||
SPSetFloatN (line, "diam", diam, 1);
|
||||
savelist.Add (line);
|
||||
SPSetIntN(line, "x", x);
|
||||
SPSetIntN(line, "z", y);
|
||||
SPSetFloatN(line, "height", height, 1);
|
||||
SPSetFloatN(line, "diam", diam, 1);
|
||||
savelist.Add(line);
|
||||
}
|
||||
}
|
||||
pad += (nx * depth) % 4;
|
||||
}
|
||||
string itemfile = CourseDir + SEP "items.lst";
|
||||
savelist.Save (itemfile); // Convert trees.png to items.lst
|
||||
savelist.Save(itemfile); // Convert trees.png to items.lst
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -521,11 +521,11 @@ bool CCourse::LoadAndConvertObjectMap () {
|
|||
// LoadObjectTypes
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
bool CCourse::LoadObjectTypes () {
|
||||
CSPList list (MAX_OBJECT_TYPES+10);
|
||||
bool CCourse::LoadObjectTypes() {
|
||||
CSPList list(MAX_OBJECT_TYPES+10);
|
||||
|
||||
if (!list.Load (param.obj_dir, "object_types.lst")) {
|
||||
Message ("could not load object types");
|
||||
if (!list.Load(param.obj_dir, "object_types.lst")) {
|
||||
Message("could not load object types");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -533,22 +533,22 @@ bool CCourse::LoadObjectTypes () {
|
|||
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
ObjTypes[i].name = SPStrN (line, "name");
|
||||
ObjTypes[i].name = SPStrN(line, "name");
|
||||
ObjTypes[i].textureFile = ObjTypes[i].name;
|
||||
ObjTypes[i].texture = NULL;
|
||||
|
||||
ObjTypes[i].drawable = SPBoolN (line, "draw", true);
|
||||
ObjTypes[i].drawable = SPBoolN(line, "draw", true);
|
||||
if (ObjTypes[i].drawable) {
|
||||
ObjTypes[i].textureFile = SPStrN (line, "texture");
|
||||
ObjTypes[i].textureFile = SPStrN(line, "texture");
|
||||
}
|
||||
ObjTypes[i].collectable = SPBoolN (line, "snap", -1) != 0;
|
||||
ObjTypes[i].collectable = SPBoolN(line, "snap", -1) != 0;
|
||||
if (ObjTypes[i].collectable == 0) {
|
||||
ObjTypes[i].collectable = -1;
|
||||
}
|
||||
|
||||
ObjTypes[i].collidable = SPBoolN (line, "coll", false);
|
||||
ObjTypes[i].reset_point = SPBoolN (line, "reset", false);
|
||||
ObjTypes[i].use_normal = SPBoolN (line, "usenorm", false);
|
||||
ObjTypes[i].collidable = SPBoolN(line, "coll", false);
|
||||
ObjTypes[i].reset_point = SPBoolN(line, "reset", false);
|
||||
ObjTypes[i].use_normal = SPBoolN(line, "usenorm", false);
|
||||
|
||||
if (ObjTypes[i].use_normal) {
|
||||
ObjTypes[i].normal = SPVector3(line, "norm", TVector3d(0, 1, 0));
|
||||
|
@ -556,7 +556,7 @@ bool CCourse::LoadObjectTypes () {
|
|||
}
|
||||
ObjTypes[i].poly = 1;
|
||||
}
|
||||
list.MakeIndex (ObjectIndex, "name");
|
||||
list.MakeIndex(ObjectIndex, "name");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -564,7 +564,7 @@ bool CCourse::LoadObjectTypes () {
|
|||
// Terrain
|
||||
// ====================================================================
|
||||
|
||||
int CCourse::GetTerrain (const unsigned char* pixel) const {
|
||||
int CCourse::GetTerrain(const unsigned char* pixel) const {
|
||||
for (size_t i=0; i<TerrList.size(); i++) {
|
||||
if (abs(pixel[0]-TerrList[i].col.r) < 30
|
||||
&& abs(pixel[1]-TerrList[i].col.g) < 30
|
||||
|
@ -579,30 +579,30 @@ int CCourse::GetTerrain (const unsigned char* pixel) const {
|
|||
// LoadTerrainTypes
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
bool CCourse::LoadTerrainTypes () {
|
||||
bool CCourse::LoadTerrainTypes() {
|
||||
CSPList list(MAX_TERR_TYPES +10);
|
||||
|
||||
if (!list.Load (param.terr_dir, "terrains.lst")) {
|
||||
Message ("could not load terrain types");
|
||||
if (!list.Load(param.terr_dir, "terrains.lst")) {
|
||||
Message("could not load terrain types");
|
||||
return false;
|
||||
}
|
||||
|
||||
TerrList.resize(list.Count());
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
TerrList[i].textureFile = SPStrN (line, "texture");
|
||||
TerrList[i].sound = Sound.GetSoundIdx (SPStrN (line, "sound"));
|
||||
TerrList[i].starttex = SPIntN (line, "starttex", -1);
|
||||
TerrList[i].tracktex = SPIntN (line, "tracktex", -1);
|
||||
TerrList[i].stoptex = SPIntN (line, "stoptex", -1);
|
||||
TerrList[i].col = SPColor3N (line, "col", TColor3(255, 255, 255));
|
||||
TerrList[i].friction = SPFloatN (line, "friction", 0.5);
|
||||
TerrList[i].depth = SPFloatN (line, "depth", 0.01);
|
||||
TerrList[i].particles = SPBoolN (line, "part", false);
|
||||
TerrList[i].trackmarks = SPBoolN (line, "trackmarks", false);
|
||||
TerrList[i].textureFile = SPStrN(line, "texture");
|
||||
TerrList[i].sound = Sound.GetSoundIdx(SPStrN(line, "sound"));
|
||||
TerrList[i].starttex = SPIntN(line, "starttex", -1);
|
||||
TerrList[i].tracktex = SPIntN(line, "tracktex", -1);
|
||||
TerrList[i].stoptex = SPIntN(line, "stoptex", -1);
|
||||
TerrList[i].col = SPColor3N(line, "col", TColor3(255, 255, 255));
|
||||
TerrList[i].friction = SPFloatN(line, "friction", 0.5);
|
||||
TerrList[i].depth = SPFloatN(line, "depth", 0.01);
|
||||
TerrList[i].particles = SPBoolN(line, "part", false);
|
||||
TerrList[i].trackmarks = SPBoolN(line, "trackmarks", false);
|
||||
TerrList[i].texture = NULL;
|
||||
TerrList[i].shiny = SPBoolN(line, "shiny", false);
|
||||
TerrList[i].vol_type = SPIntN (line, "vol_type", 1);
|
||||
TerrList[i].vol_type = SPIntN(line, "vol_type", 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -611,22 +611,22 @@ bool CCourse::LoadTerrainTypes () {
|
|||
// LoadTerrainMap
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
bool CCourse::LoadTerrainMap () {
|
||||
bool CCourse::LoadTerrainMap() {
|
||||
sf::Image terrImage;
|
||||
|
||||
if (!terrImage.loadFromFile (CourseDir + SEP "terrain.png")) {
|
||||
Message ("unable to open terrain.png");
|
||||
if (!terrImage.loadFromFile(CourseDir + SEP "terrain.png")) {
|
||||
Message("unable to open terrain.png");
|
||||
return false;
|
||||
}
|
||||
terrImage.flipVertically();
|
||||
if (nx != terrImage.getSize().x || ny != terrImage.getSize().y) {
|
||||
Message ("wrong terrain size");
|
||||
Message("wrong terrain size");
|
||||
}
|
||||
|
||||
try {
|
||||
terrain = new char[nx * ny];
|
||||
} catch (...) {
|
||||
Message ("Allocation failed in LoadTerrainMap");
|
||||
Message("Allocation failed in LoadTerrainMap");
|
||||
}
|
||||
int depth = 4;
|
||||
const unsigned char* data = (const unsigned char*) terrImage.getPixelsPtr();
|
||||
|
@ -635,7 +635,7 @@ bool CCourse::LoadTerrainMap () {
|
|||
for (int x=0; x<nx; x++) {
|
||||
int imgidx = (x+nx*y) * depth + pad;
|
||||
int arridx = (nx-1-x) + nx * (ny-1-y);
|
||||
int terr = GetTerrain (&data[imgidx]);
|
||||
int terr = GetTerrain(&data[imgidx]);
|
||||
terrain[arridx] = terr;
|
||||
if (TerrList[terr].texture == NULL) {
|
||||
TerrList[terr].texture = new TTexture();
|
||||
|
@ -651,25 +651,25 @@ bool CCourse::LoadTerrainMap () {
|
|||
// LoadCourseList
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
bool CCourse::LoadCourseList () {
|
||||
CSPList list (128);
|
||||
bool CCourse::LoadCourseList() {
|
||||
CSPList list(128);
|
||||
|
||||
if (!list.Load (param.common_course_dir, "courses.lst")) {
|
||||
Message ("could not load courses.lst");
|
||||
if (!list.Load(param.common_course_dir, "courses.lst")) {
|
||||
Message("could not load courses.lst");
|
||||
return false;
|
||||
}
|
||||
|
||||
CSPList paramlist (48);
|
||||
CSPList paramlist(48);
|
||||
|
||||
CourseList.resize(list.Count());
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line1 = list.Line(i);
|
||||
CourseList[i].name = SPStrN (line1, "name", "noname");
|
||||
CourseList[i].dir = SPStrN (line1, "dir", "nodir");
|
||||
CourseList[i].name = SPStrN(line1, "name", "noname");
|
||||
CourseList[i].dir = SPStrN(line1, "dir", "nodir");
|
||||
|
||||
string desc = SPStrN (line1, "desc");
|
||||
FT.AutoSizeN (2);
|
||||
vector<string> desclist = FT.MakeLineList (desc.c_str(), 335 * Winsys.scale - 16.0);
|
||||
string desc = SPStrN(line1, "desc");
|
||||
FT.AutoSizeN(2);
|
||||
vector<string> desclist = FT.MakeLineList(desc.c_str(), 335 * Winsys.scale - 16.0);
|
||||
size_t cnt = min<size_t>(desclist.size(), MAX_DESCRIPTION_LINES);
|
||||
CourseList[i].num_lines = cnt;
|
||||
for (size_t ll=0; ll<cnt; ll++) {
|
||||
|
@ -677,43 +677,43 @@ bool CCourse::LoadCourseList () {
|
|||
}
|
||||
|
||||
string coursepath = param.common_course_dir + SEP + CourseList[i].dir;
|
||||
if (DirExists (coursepath.c_str())) {
|
||||
if (DirExists(coursepath.c_str())) {
|
||||
// preview
|
||||
string previewfile = coursepath + SEP "preview.png";
|
||||
CourseList[i].preview = new TTexture();
|
||||
if (!CourseList[i].preview->Load(previewfile, false)) {
|
||||
Message ("couldn't load previewfile");
|
||||
Message("couldn't load previewfile");
|
||||
// texid = Tex.TexID (NO_PREVIEW);
|
||||
}
|
||||
|
||||
// params
|
||||
string paramfile = coursepath + SEP "course.dim";
|
||||
if (!paramlist.Load (paramfile)) {
|
||||
Message ("could not load course.dim");
|
||||
if (!paramlist.Load(paramfile)) {
|
||||
Message("could not load course.dim");
|
||||
}
|
||||
|
||||
const string& line2 = paramlist.Line (0);
|
||||
CourseList[i].author = SPStrN (line2, "author", "unknown");
|
||||
CourseList[i].size.x = SPFloatN (line2, "width", 100);
|
||||
CourseList[i].size.y = SPFloatN (line2, "length", 1000);
|
||||
CourseList[i].play_size.x = SPFloatN (line2, "play_width", 90);
|
||||
CourseList[i].play_size.y = SPFloatN (line2, "play_length", 900);
|
||||
CourseList[i].angle = SPFloatN (line2, "angle", 10);
|
||||
CourseList[i].scale = SPFloatN (line2, "scale", 10);
|
||||
CourseList[i].start.x = SPFloatN (line2, "startx", 50);
|
||||
CourseList[i].start.y = SPFloatN (line2, "starty", 5);
|
||||
CourseList[i].env = Env.GetEnvIdx (SPStrN (line2, "env", "etr"));
|
||||
CourseList[i].music_theme = Music.GetThemeIdx (SPStrN (line2, "theme", "normal"));
|
||||
CourseList[i].use_keyframe = SPBoolN (line2, "use_keyframe", false);
|
||||
CourseList[i].finish_brake = SPFloatN (line2, "finish_brake", 20);
|
||||
paramlist.Clear (); // the list is used several times
|
||||
const string& line2 = paramlist.Line(0);
|
||||
CourseList[i].author = SPStrN(line2, "author", "unknown");
|
||||
CourseList[i].size.x = SPFloatN(line2, "width", 100);
|
||||
CourseList[i].size.y = SPFloatN(line2, "length", 1000);
|
||||
CourseList[i].play_size.x = SPFloatN(line2, "play_width", 90);
|
||||
CourseList[i].play_size.y = SPFloatN(line2, "play_length", 900);
|
||||
CourseList[i].angle = SPFloatN(line2, "angle", 10);
|
||||
CourseList[i].scale = SPFloatN(line2, "scale", 10);
|
||||
CourseList[i].start.x = SPFloatN(line2, "startx", 50);
|
||||
CourseList[i].start.y = SPFloatN(line2, "starty", 5);
|
||||
CourseList[i].env = Env.GetEnvIdx(SPStrN(line2, "env", "etr"));
|
||||
CourseList[i].music_theme = Music.GetThemeIdx(SPStrN(line2, "theme", "normal"));
|
||||
CourseList[i].use_keyframe = SPBoolN(line2, "use_keyframe", false);
|
||||
CourseList[i].finish_brake = SPFloatN(line2, "finish_brake", 20);
|
||||
paramlist.Clear(); // the list is used several times
|
||||
}
|
||||
}
|
||||
list.MakeIndex (CourseIndex, "dir");
|
||||
list.MakeIndex(CourseIndex, "dir");
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCourse::FreeCourseList () {
|
||||
void CCourse::FreeCourseList() {
|
||||
for (size_t i=0; i<CourseList.size(); i++) {
|
||||
delete CourseList[i].preview;
|
||||
}
|
||||
|
@ -724,22 +724,22 @@ void CCourse::FreeCourseList () {
|
|||
// LoadCourse
|
||||
// ===================================================================
|
||||
|
||||
void CCourse::ResetCourse () {
|
||||
void CCourse::ResetCourse() {
|
||||
if (nmls != NULL) {delete[] nmls; nmls = NULL;}
|
||||
if (vnc_array != NULL) {delete[] vnc_array; vnc_array = NULL;}
|
||||
if (elevation != NULL) {delete[] elevation; elevation = NULL;}
|
||||
if (terrain != NULL) {delete[] terrain; terrain = NULL;}
|
||||
|
||||
FreeTerrainTextures ();
|
||||
FreeObjectTextures ();
|
||||
ResetQuadtree ();
|
||||
FreeTerrainTextures();
|
||||
FreeObjectTextures();
|
||||
ResetQuadtree();
|
||||
curr_course = NULL;
|
||||
mirrored = false;
|
||||
}
|
||||
|
||||
bool CCourse::LoadCourse (TCourse* course) {
|
||||
bool CCourse::LoadCourse(TCourse* course) {
|
||||
if (course != curr_course || g_game.force_treemap) {
|
||||
ResetCourse ();
|
||||
ResetCourse();
|
||||
curr_course = course;
|
||||
CourseDir = param.common_course_dir + SEP + curr_course->dir;
|
||||
|
||||
|
@ -750,33 +750,33 @@ bool CCourse::LoadCourse (TCourse* course) {
|
|||
g_game.use_keyframe = course->use_keyframe;
|
||||
g_game.finish_brake = course->finish_brake;
|
||||
|
||||
if (!LoadElevMap ()) {
|
||||
Message ("could not load course elev map");
|
||||
if (!LoadElevMap()) {
|
||||
Message("could not load course elev map");
|
||||
return false;
|
||||
}
|
||||
|
||||
MakeCourseNormals ();
|
||||
FillGlArrays ();
|
||||
MakeCourseNormals();
|
||||
FillGlArrays();
|
||||
|
||||
if (!LoadTerrainMap ()) {
|
||||
Message ("could not load course terrain map");
|
||||
if (!LoadTerrainMap()) {
|
||||
Message("could not load course terrain map");
|
||||
return false;
|
||||
}
|
||||
|
||||
// ................................................................
|
||||
string itemfile = CourseDir + SEP "items.lst";
|
||||
bool itemsexists = FileExists (itemfile);
|
||||
bool itemsexists = FileExists(itemfile);
|
||||
const CControl *ctrl = g_game.player->ctrl;
|
||||
|
||||
if (itemsexists && !g_game.force_treemap)
|
||||
LoadItemList ();
|
||||
LoadItemList();
|
||||
else
|
||||
LoadAndConvertObjectMap ();
|
||||
LoadAndConvertObjectMap();
|
||||
g_game.force_treemap = false;
|
||||
// ................................................................
|
||||
|
||||
init_track_marks ();
|
||||
InitQuadtree (
|
||||
init_track_marks();
|
||||
InitQuadtree(
|
||||
elevation, nx, ny,
|
||||
curr_course->size.x / (nx - 1.0),
|
||||
-curr_course->size.y / (ny - 1.0),
|
||||
|
@ -785,13 +785,13 @@ bool CCourse::LoadCourse (TCourse* course) {
|
|||
}
|
||||
|
||||
if (g_game.mirrorred != mirrored) {
|
||||
MirrorCourse ();
|
||||
MirrorCourse();
|
||||
mirrored = g_game.mirrorred;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t CCourse::GetEnv () const {
|
||||
size_t CCourse::GetEnv() const {
|
||||
return curr_course->env;
|
||||
}
|
||||
|
||||
|
@ -799,7 +799,7 @@ size_t CCourse::GetEnv () const {
|
|||
// mirror course
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void CCourse::MirrorCourseData () {
|
||||
void CCourse::MirrorCourseData() {
|
||||
for (int y=0; y<ny; y++) {
|
||||
for (int x=0; x<nx/2; x++) {
|
||||
double tmp = ELEV(x,y);
|
||||
|
@ -820,29 +820,29 @@ void CCourse::MirrorCourseData () {
|
|||
|
||||
for (size_t i=0; i<CollArr.size(); i++) {
|
||||
CollArr[i].pt.x = curr_course->size.x - CollArr[i].pt.x;
|
||||
CollArr[i].pt.y = FindYCoord (CollArr[i].pt.x, CollArr[i].pt.z);
|
||||
CollArr[i].pt.y = FindYCoord(CollArr[i].pt.x, CollArr[i].pt.z);
|
||||
}
|
||||
|
||||
for (size_t i=0; i<NocollArr.size(); i++) {
|
||||
NocollArr[i].pt.x = curr_course->size.x - NocollArr[i].pt.x;
|
||||
NocollArr[i].pt.y = FindYCoord (NocollArr[i].pt.x, NocollArr[i].pt.z);
|
||||
NocollArr[i].pt.y = FindYCoord(NocollArr[i].pt.x, NocollArr[i].pt.z);
|
||||
}
|
||||
|
||||
FillGlArrays();
|
||||
|
||||
ResetQuadtree ();
|
||||
ResetQuadtree();
|
||||
if (nx > 0 && ny > 0) {
|
||||
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);
|
||||
InitQuadtree(elevation, nx, ny, curr_course->size.x/(nx-1),
|
||||
- curr_course->size.y/(ny-1), ctrl->viewpos, param.course_detail_level);
|
||||
}
|
||||
|
||||
start_pt.x = curr_course->size.x - start_pt.x;
|
||||
}
|
||||
|
||||
void CCourse::MirrorCourse () {
|
||||
MirrorCourseData ();
|
||||
init_track_marks ();
|
||||
void CCourse::MirrorCourse() {
|
||||
MirrorCourseData();
|
||||
init_track_marks();
|
||||
}
|
||||
|
||||
// ********************************************************************
|
||||
|
@ -852,7 +852,7 @@ void CCourse::MirrorCourse () {
|
|||
void CCourse::GetIndicesForPoint(double x, double z, int *x0, int *y0, int *x1, int *y1) const {
|
||||
|
||||
double xidx = x / curr_course->size.x * ((double) nx - 1.);
|
||||
double yidx = -z / curr_course->size.y * ((double) ny - 1.);
|
||||
double yidx = -z / curr_course->size.y * ((double) ny - 1.);
|
||||
|
||||
if (xidx < 0) xidx = 0;
|
||||
else if (xidx > nx-1) xidx = nx-1;
|
||||
|
@ -866,12 +866,12 @@ void CCourse::GetIndicesForPoint(double x, double z, int *x0, int *y0, int *x1,
|
|||
*y1 = (int)(yidx + 0.9999); // ceil(yidx)
|
||||
|
||||
if (*x0 == *x1) {
|
||||
if (*x1 < nx - 1) (*x1)++;
|
||||
if (*x1 < nx - 1)(*x1)++;
|
||||
else (*x0)--;
|
||||
}
|
||||
|
||||
if (*y0 == *y1) {
|
||||
if (*y1 < ny - 1) (*y1)++;
|
||||
if (*y1 < ny - 1)(*y1)++;
|
||||
else (*y0)--;
|
||||
}
|
||||
}
|
||||
|
@ -882,7 +882,7 @@ void CCourse::FindBarycentricCoords(double x, double z, TVector2i *idx0,
|
|||
int x0, x1, y0, y1;
|
||||
double dx, ex, dz, ez, qx, qz, invdet;
|
||||
|
||||
GetIndicesForPoint (x, z, &x0, &y0, &x1, &y1);
|
||||
GetIndicesForPoint(x, z, &x0, &y0, &x1, &y1);
|
||||
xidx = x / curr_course->size.x * ((double) nx - 1.);
|
||||
yidx = -z / curr_course->size.y * ((double) ny - 1.);
|
||||
|
||||
|
@ -923,23 +923,23 @@ void CCourse::FindBarycentricCoords(double x, double z, TVector2i *idx0,
|
|||
#define COURSE_VERTX(_x, _y) TVector3d ( (double)(_x)/(nx-1.)*curr_course->size.x, \
|
||||
ELEV((_x),(_y)), -(double)(_y)/(ny-1.)*curr_course->size.y )
|
||||
|
||||
TVector3d CCourse::FindCourseNormal (double x, double z) const {
|
||||
TVector3d CCourse::FindCourseNormal(double x, double z) const {
|
||||
|
||||
double *elevation = Course.elevation;
|
||||
int x0, x1, y0, y1;
|
||||
GetIndicesForPoint (x, z, &x0, &y0, &x1, &y1);
|
||||
GetIndicesForPoint(x, z, &x0, &y0, &x1, &y1);
|
||||
|
||||
TVector2i idx0, idx1, idx2;
|
||||
double u, v;
|
||||
FindBarycentricCoords (x, z, &idx0, &idx1, &idx2, &u, &v);
|
||||
FindBarycentricCoords(x, z, &idx0, &idx1, &idx2, &u, &v);
|
||||
|
||||
const TVector3d& n0 = Course.nmls[ idx0.x + nx * idx0.y ];
|
||||
const TVector3d& n1 = Course.nmls[ idx1.x + nx * idx1.y ];
|
||||
const TVector3d& n2 = Course.nmls[ idx2.x + nx * idx2.y ];
|
||||
|
||||
TVector3d p0 = COURSE_VERTX (idx0.x, idx0.y);
|
||||
TVector3d p1 = COURSE_VERTX (idx1.x, idx1.y);
|
||||
TVector3d p2 = COURSE_VERTX (idx2.x, idx2.y);
|
||||
TVector3d p0 = COURSE_VERTX(idx0.x, idx0.y);
|
||||
TVector3d p1 = COURSE_VERTX(idx1.x, idx1.y);
|
||||
TVector3d p2 = COURSE_VERTX(idx2.x, idx2.y);
|
||||
|
||||
TVector3d smooth_nml = u * n0 +
|
||||
v * n1 +
|
||||
|
@ -948,8 +948,8 @@ TVector3d CCourse::FindCourseNormal (double x, double z) const {
|
|||
TVector3d tri_nml = CrossProduct(p1 - p0, p2 - p0);
|
||||
tri_nml.Norm();
|
||||
|
||||
double min_bary = min (u, min (v, 1. - u - v));
|
||||
double interp_factor = min (min_bary / NORM_INTERPOL, 1.0);
|
||||
double min_bary = min(u, min(v, 1. - u - v));
|
||||
double interp_factor = min(min_bary / NORM_INTERPOL, 1.0);
|
||||
|
||||
TVector3d interp_nml = interp_factor * tri_nml + (1.-interp_factor) * smooth_nml;
|
||||
interp_nml.Norm();
|
||||
|
@ -957,7 +957,7 @@ TVector3d CCourse::FindCourseNormal (double x, double z) const {
|
|||
return interp_nml;
|
||||
}
|
||||
|
||||
double CCourse::FindYCoord (double x, double z) const {
|
||||
double CCourse::FindYCoord(double x, double z) const {
|
||||
static double last_x, last_z, last_y;
|
||||
static bool cache_full = false;
|
||||
|
||||
|
@ -966,13 +966,13 @@ double CCourse::FindYCoord (double x, double z) const {
|
|||
|
||||
TVector2i idx0, idx1, idx2;
|
||||
double u, v;
|
||||
FindBarycentricCoords (x, z, &idx0, &idx1, &idx2, &u, &v);
|
||||
FindBarycentricCoords(x, z, &idx0, &idx1, &idx2, &u, &v);
|
||||
|
||||
TVector3d p0 = COURSE_VERTX (idx0.x, idx0.y);
|
||||
TVector3d p1 = COURSE_VERTX (idx1.x, idx1.y);
|
||||
TVector3d p2 = COURSE_VERTX (idx2.x, idx2.y);
|
||||
TVector3d p0 = COURSE_VERTX(idx0.x, idx0.y);
|
||||
TVector3d p1 = COURSE_VERTX(idx1.x, idx1.y);
|
||||
TVector3d p2 = COURSE_VERTX(idx2.x, idx2.y);
|
||||
|
||||
double ycoord = u * p0.y + v * p1.y + (1. - u - v) * p2.y;
|
||||
double ycoord = u * p0.y + v * p1.y + (1. - u - v) * p2.y;
|
||||
|
||||
last_x = x;
|
||||
last_z = z;
|
||||
|
@ -982,10 +982,10 @@ double CCourse::FindYCoord (double x, double z) const {
|
|||
return ycoord;
|
||||
}
|
||||
|
||||
void CCourse::GetSurfaceType (double x, double z, double weights[]) const {
|
||||
void CCourse::GetSurfaceType(double x, double z, double weights[]) const {
|
||||
TVector2i idx0, idx1, idx2;
|
||||
double u, v;
|
||||
FindBarycentricCoords (x, z, &idx0, &idx1, &idx2, &u, &v);
|
||||
FindBarycentricCoords(x, z, &idx0, &idx1, &idx2, &u, &v);
|
||||
|
||||
char *terrain = Course.terrain;
|
||||
for (size_t i=0; i<Course.TerrList.size(); i++) {
|
||||
|
@ -996,10 +996,10 @@ void CCourse::GetSurfaceType (double x, double z, double weights[]) const {
|
|||
}
|
||||
}
|
||||
|
||||
int CCourse::GetTerrainIdx (double x, double z, double level) const {
|
||||
int CCourse::GetTerrainIdx(double x, double z, double level) const {
|
||||
TVector2i idx0, idx1, idx2;
|
||||
double u, v;
|
||||
FindBarycentricCoords (x, z, &idx0, &idx1, &idx2, &u, &v);
|
||||
FindBarycentricCoords(x, z, &idx0, &idx1, &idx2, &u, &v);
|
||||
char *terrain = Course.terrain;
|
||||
|
||||
for (size_t i=0; i<Course.TerrList.size(); i++) {
|
||||
|
@ -1012,10 +1012,10 @@ int CCourse::GetTerrainIdx (double x, double z, double level) const {
|
|||
return -1;
|
||||
}
|
||||
|
||||
TPlane CCourse::GetLocalCoursePlane (TVector3d pt) const {
|
||||
TPlane CCourse::GetLocalCoursePlane(TVector3d pt) const {
|
||||
TPlane plane;
|
||||
pt.y = FindYCoord (pt.x, pt.z);
|
||||
plane.nml = FindCourseNormal (pt.x, pt.z);
|
||||
pt.y = FindYCoord(pt.x, pt.z);
|
||||
plane.nml = FindCourseNormal(pt.x, pt.z);
|
||||
plane.d = -DotProduct(plane.nml, pt);
|
||||
return plane;
|
||||
}
|
||||
|
|
68
src/course.h
68
src/course.h
|
@ -128,19 +128,19 @@ private:
|
|||
int base_height_value;
|
||||
bool mirrored;
|
||||
|
||||
void FreeTerrainTextures ();
|
||||
void FreeObjectTextures ();
|
||||
void CalcNormals ();
|
||||
void MakeCourseNormals ();
|
||||
bool LoadElevMap ();
|
||||
void LoadItemList ();
|
||||
bool LoadAndConvertObjectMap ();
|
||||
bool LoadTerrainMap ();
|
||||
int GetTerrain (const unsigned char* pixel) const;
|
||||
void FreeTerrainTextures();
|
||||
void FreeObjectTextures();
|
||||
void CalcNormals();
|
||||
void MakeCourseNormals();
|
||||
bool LoadElevMap();
|
||||
void LoadItemList();
|
||||
bool LoadAndConvertObjectMap();
|
||||
bool LoadTerrainMap();
|
||||
int GetTerrain(const unsigned char* pixel) const;
|
||||
|
||||
void MirrorCourseData ();
|
||||
void MirrorCourseData();
|
||||
public:
|
||||
CCourse ();
|
||||
CCourse();
|
||||
~CCourse();
|
||||
|
||||
vector<TCourse> CourseList;
|
||||
|
@ -155,37 +155,37 @@ public:
|
|||
TVector3d *nmls;
|
||||
GLubyte *vnc_array;
|
||||
|
||||
void ResetCourse ();
|
||||
TCourse* GetCourse (const string& dir);
|
||||
void ResetCourse();
|
||||
TCourse* GetCourse(const string& dir);
|
||||
size_t GetCourseIdx(const TCourse* course) const;
|
||||
bool LoadCourseList ();
|
||||
void FreeCourseList ();
|
||||
bool LoadCourseList();
|
||||
void FreeCourseList();
|
||||
bool LoadCourse(TCourse* course);
|
||||
bool LoadTerrainTypes ();
|
||||
bool LoadObjectTypes ();
|
||||
void MakeStandardPolyhedrons ();
|
||||
bool LoadTerrainTypes();
|
||||
bool LoadObjectTypes();
|
||||
void MakeStandardPolyhedrons();
|
||||
GLubyte* GetGLArrays() const { return vnc_array; }
|
||||
void FillGlArrays();
|
||||
|
||||
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;
|
||||
size_t GetEnv () const;
|
||||
const TVector2d& GetStartPoint () const { return start_pt; }
|
||||
const TPolyhedron& GetPoly (size_t type) const;
|
||||
void MirrorCourse ();
|
||||
void GetDivisions(int *nx, int *ny) const;
|
||||
double GetCourseAngle() const { return curr_course->angle; }
|
||||
double GetBaseHeight(double distance) const;
|
||||
double GetMaxHeight(double distance) const;
|
||||
size_t GetEnv() const;
|
||||
const TVector2d& GetStartPoint() const { return start_pt; }
|
||||
const TPolyhedron& GetPoly(size_t type) const;
|
||||
void MirrorCourse();
|
||||
|
||||
void GetIndicesForPoint (double x, double z, int *x0, int *y0, int *x1, int *y1) const;
|
||||
void FindBarycentricCoords (double x, double z,
|
||||
TVector2i *idx0, TVector2i *idx1, TVector2i *idx2, double *u, double *v) const;
|
||||
TVector3d FindCourseNormal (double x, double z) const;
|
||||
double FindYCoord (double x, double z) const;
|
||||
void GetSurfaceType (double x, double z, double weights[]) const;
|
||||
int GetTerrainIdx (double x, double z, double level) const;
|
||||
TPlane GetLocalCoursePlane (TVector3d pt) const;
|
||||
void GetIndicesForPoint(double x, double z, int *x0, int *y0, int *x1, int *y1) const;
|
||||
void FindBarycentricCoords(double x, double z,
|
||||
TVector2i *idx0, TVector2i *idx1, TVector2i *idx2, double *u, double *v) const;
|
||||
TVector3d FindCourseNormal(double x, double z) const;
|
||||
double FindYCoord(double x, double z) const;
|
||||
void GetSurfaceType(double x, double z, double weights[]) const;
|
||||
int GetTerrainIdx(double x, double z, double level) const;
|
||||
TPlane GetLocalCoursePlane(TVector3d pt) const;
|
||||
};
|
||||
|
||||
extern CCourse Course;
|
||||
|
|
|
@ -32,24 +32,24 @@ GNU General Public License for more details.
|
|||
#define TEX_SCALE 6
|
||||
static const bool clip_course = true;
|
||||
|
||||
void setup_course_tex_gen () {
|
||||
void setup_course_tex_gen() {
|
||||
static const GLfloat xplane[4] = {1.0 / TEX_SCALE, 0.0, 0.0, 0.0 };
|
||||
static const GLfloat zplane[4] = {0.0, 0.0, 1.0 / TEX_SCALE, 0.0 };
|
||||
glTexGenfv (GL_S, GL_OBJECT_PLANE, xplane);
|
||||
glTexGenfv (GL_T, GL_OBJECT_PLANE, zplane);
|
||||
glTexGenfv(GL_S, GL_OBJECT_PLANE, xplane);
|
||||
glTexGenfv(GL_T, GL_OBJECT_PLANE, zplane);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// render course
|
||||
// --------------------------------------------------------------------
|
||||
void RenderCourse () {
|
||||
void RenderCourse() {
|
||||
ScopedRenderMode rm(COURSE);
|
||||
setup_course_tex_gen ();
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
set_material (colWhite, colBlack, 1.0);
|
||||
setup_course_tex_gen();
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
set_material(colWhite, colBlack, 1.0);
|
||||
const CControl *ctrl = g_game.player->ctrl;
|
||||
UpdateQuadtree (ctrl->viewpos, param.course_detail_level);
|
||||
RenderQuadtree ();
|
||||
UpdateQuadtree(ctrl->viewpos, param.course_detail_level);
|
||||
RenderQuadtree();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -64,8 +64,8 @@ void DrawTrees() {
|
|||
double fwd_clip_limit = param.forward_clip_distance;
|
||||
double bwd_clip_limit = param.backward_clip_distance;
|
||||
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
set_material (colWhite, colBlack, 1.0);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
set_material(colWhite, colBlack, 1.0);
|
||||
|
||||
|
||||
// -------------- trees ------------------------
|
||||
|
@ -82,7 +82,7 @@ void DrawTrees() {
|
|||
|
||||
glPushMatrix();
|
||||
glTranslate(Course.CollArr[i].pt);
|
||||
if (param.perf_level > 1) glRotatef (1, 0, 1, 0);
|
||||
if (param.perf_level > 1) glRotatef(1, 0, 1, 0);
|
||||
|
||||
float treeRadius = Course.CollArr[i].diam / 2.0;
|
||||
float treeHeight = Course.CollArr[i].height;
|
||||
|
|
|
@ -20,9 +20,9 @@ GNU General Public License for more details.
|
|||
|
||||
#include "bh.h"
|
||||
|
||||
void setup_course_tex_gen ();
|
||||
void setup_course_tex_gen();
|
||||
|
||||
void RenderCourse ();
|
||||
void DrawTrees ();
|
||||
void RenderCourse();
|
||||
void DrawTrees();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,30 +42,30 @@ sf::RenderTexture* RT = 0;
|
|||
sf::VertexArray arr(sf::Quads, 12);
|
||||
sf::RenderStates states(sf::BlendAlpha);
|
||||
|
||||
void CCredits::LoadCreditList () {
|
||||
void CCredits::LoadCreditList() {
|
||||
CSPList list(MAX_CREDITS);
|
||||
|
||||
if (!list.Load (param.data_dir, "credits.lst")) {
|
||||
Message ("could not load credits list");
|
||||
if (!list.Load(param.data_dir, "credits.lst")) {
|
||||
Message("could not load credits list");
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
TCredits credit;
|
||||
credit.text = SPStrN (line, "text");
|
||||
credit.text = SPStrN(line, "text");
|
||||
|
||||
double offset = SPFloatN (line, "offs", 0) * OFFS_SCALE_FACTOR * Winsys.scale;
|
||||
double offset = SPFloatN(line, "offs", 0) * OFFS_SCALE_FACTOR * Winsys.scale;
|
||||
if (i>0) credit.offs = CreditList.back().offs + (int)offset;
|
||||
else credit.offs = offset;
|
||||
|
||||
credit.col = SPIntN (line, "col", 0);
|
||||
credit.size = SPFloatN (line, "size", 1.0);
|
||||
credit.col = SPIntN(line, "col", 0);
|
||||
credit.size = SPFloatN(line, "size", 1.0);
|
||||
CreditList.push_back(credit);
|
||||
}
|
||||
}
|
||||
|
||||
void CCredits::DrawCreditsText (double time_step) {
|
||||
void CCredits::DrawCreditsText(double time_step) {
|
||||
int h = Winsys.resolution.height;
|
||||
double offs = 0.0;
|
||||
if (moving) y_offset += time_step * 30;
|
||||
|
@ -94,7 +94,7 @@ void CCredits::DrawCreditsText (double time_step) {
|
|||
if (offs < TOP_Y) y_offset = 0;
|
||||
}
|
||||
|
||||
void CCredits::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CCredits::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case sf::Keyboard::M:
|
||||
|
@ -108,12 +108,12 @@ void CCredits::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, i
|
|||
}
|
||||
}
|
||||
|
||||
void CCredits::Mouse (int button, int state, int x, int y) {
|
||||
void CCredits::Mouse(int button, int state, int x, int y) {
|
||||
if (state == 1) State::manager.RequestEnterState(*State::manager.PreviousState());
|
||||
}
|
||||
|
||||
void CCredits::Motion(int x, int y) {
|
||||
if (param.ui_snow) push_ui_snow (cursor_pos);
|
||||
if (param.ui_snow) push_ui_snow(cursor_pos);
|
||||
}
|
||||
|
||||
void CCredits::Enter() {
|
||||
|
@ -156,9 +156,9 @@ void CCredits::Loop(double time_step) {
|
|||
ClearRenderContext();
|
||||
Winsys.clear();
|
||||
|
||||
DrawCreditsText (time_step);
|
||||
DrawCreditsText(time_step);
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow (time_step);
|
||||
update_ui_snow(time_step);
|
||||
draw_ui_snow();
|
||||
}
|
||||
DrawGUIBackground(Winsys.scale);
|
||||
|
|
146
src/env.cpp
146
src/env.cpp
|
@ -47,7 +47,7 @@ void TLight::Enable(GLenum num) const {
|
|||
|
||||
CEnvironment Env;
|
||||
|
||||
CEnvironment::CEnvironment () {
|
||||
CEnvironment::CEnvironment() {
|
||||
EnvID = -1;
|
||||
lightcond[0] = "sunny";
|
||||
lightcond[1] = "cloudy";
|
||||
|
@ -75,12 +75,12 @@ CEnvironment::CEnvironment () {
|
|||
default_fog.part_color = def_partcol;
|
||||
}
|
||||
|
||||
void CEnvironment::ResetSkybox () {
|
||||
void CEnvironment::ResetSkybox() {
|
||||
delete[] Skybox;
|
||||
Skybox = NULL;
|
||||
}
|
||||
|
||||
void CEnvironment::SetupLight () {
|
||||
void CEnvironment::SetupLight() {
|
||||
lights[0].Enable(GL_LIGHT0);
|
||||
if (lights[1].is_on)
|
||||
lights[1].Enable(GL_LIGHT1);
|
||||
|
@ -92,43 +92,43 @@ void CEnvironment::SetupLight () {
|
|||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
void CEnvironment::SetupFog () {
|
||||
glEnable (GL_FOG);
|
||||
glFogi (GL_FOG_MODE, fog.mode);
|
||||
glFogf (GL_FOG_START, fog.start);
|
||||
glFogf (GL_FOG_END, fog.end);
|
||||
glFogfv (GL_FOG_COLOR, fog.color);
|
||||
void CEnvironment::SetupFog() {
|
||||
glEnable(GL_FOG);
|
||||
glFogi(GL_FOG_MODE, fog.mode);
|
||||
glFogf(GL_FOG_START, fog.start);
|
||||
glFogf(GL_FOG_END, fog.end);
|
||||
glFogfv(GL_FOG_COLOR, fog.color);
|
||||
|
||||
if (param.perf_level > 1) {
|
||||
glHint (GL_FOG_HINT, GL_NICEST);
|
||||
glHint(GL_FOG_HINT, GL_NICEST);
|
||||
} else {
|
||||
glHint (GL_FOG_HINT, GL_FASTEST);
|
||||
glHint(GL_FOG_HINT, GL_FASTEST);
|
||||
}
|
||||
}
|
||||
|
||||
void CEnvironment::ResetLight () {
|
||||
void CEnvironment::ResetLight() {
|
||||
lights[0] = default_light;
|
||||
for (int i=1; i<4; i++) lights[i].is_on = false;
|
||||
glDisable (GL_LIGHT1);
|
||||
glDisable (GL_LIGHT2);
|
||||
glDisable (GL_LIGHT3);
|
||||
glDisable(GL_LIGHT1);
|
||||
glDisable(GL_LIGHT2);
|
||||
glDisable(GL_LIGHT3);
|
||||
}
|
||||
|
||||
void CEnvironment::ResetFog () {
|
||||
void CEnvironment::ResetFog() {
|
||||
fog = default_fog;
|
||||
}
|
||||
|
||||
void CEnvironment::Reset () {
|
||||
void CEnvironment::Reset() {
|
||||
EnvID = -1;
|
||||
ResetSkybox ();
|
||||
ResetLight ();
|
||||
ResetFog ();
|
||||
ResetSkybox();
|
||||
ResetLight();
|
||||
ResetFog();
|
||||
}
|
||||
|
||||
bool CEnvironment::LoadEnvironmentList () {
|
||||
CSPList list (32, true);
|
||||
if (!list.Load (param.env_dir2, "environment.lst")) {
|
||||
Message ("could not load environment.lst");
|
||||
bool CEnvironment::LoadEnvironmentList() {
|
||||
CSPList list(32, true);
|
||||
if (!list.Load(param.env_dir2, "environment.lst")) {
|
||||
Message("could not load environment.lst");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -138,11 +138,11 @@ bool CEnvironment::LoadEnvironmentList () {
|
|||
locs[i].name = SPStrN(line, "location");
|
||||
locs[i].high_res = SPBoolN(line, "high_res", false);
|
||||
}
|
||||
list.MakeIndex (EnvIndex, "location");
|
||||
list.MakeIndex(EnvIndex, "location");
|
||||
return true;
|
||||
}
|
||||
|
||||
string CEnvironment::GetDir (size_t location, size_t light) const {
|
||||
string CEnvironment::GetDir(size_t location, size_t light) const {
|
||||
if (location >= locs.size()) return "";
|
||||
if (light >= 4) return "";
|
||||
string res =
|
||||
|
@ -160,7 +160,7 @@ void CEnvironment::LoadSkyboxSide(size_t index, const string& EnvDir, const stri
|
|||
Skybox[index].Load(EnvDir, name + ".png");
|
||||
}
|
||||
|
||||
void CEnvironment::LoadSkybox (const string& EnvDir, bool high_res) {
|
||||
void CEnvironment::LoadSkybox(const string& EnvDir, bool high_res) {
|
||||
Skybox = new TTexture[param.full_skybox ? 6 : 3];
|
||||
LoadSkyboxSide(0, EnvDir, "front", high_res);
|
||||
LoadSkyboxSide(1, EnvDir, "left", high_res);
|
||||
|
@ -172,37 +172,37 @@ void CEnvironment::LoadSkybox (const string& EnvDir, bool high_res) {
|
|||
}
|
||||
}
|
||||
|
||||
void CEnvironment::LoadLight (const string& EnvDir) {
|
||||
void CEnvironment::LoadLight(const string& EnvDir) {
|
||||
static const string idxstr = "[fog]-1[0]0[1]1[2]2[3]3[4]4[5]5[6]6";
|
||||
|
||||
CSPList list(24);
|
||||
if (!list.Load (EnvDir, "light.lst")) {
|
||||
Message ("could not load light file");
|
||||
if (!list.Load(EnvDir, "light.lst")) {
|
||||
Message("could not load light file");
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
string item = SPStrN (line, "light", "none");
|
||||
int idx = SPIntN (idxstr, item, -1);
|
||||
string item = SPStrN(line, "light", "none");
|
||||
int idx = SPIntN(idxstr, item, -1);
|
||||
if (idx < 0) {
|
||||
fog.is_on = SPBoolN (line, "fog", true);
|
||||
fog.start = SPFloatN (line, "fogstart", 20);
|
||||
fog.end = SPFloatN (line, "fogend", param.forward_clip_distance);
|
||||
fog.height = SPFloatN (line, "fogheight", 0);
|
||||
SPArrN (line, "fogcol", fog.color, 4, 1);
|
||||
fog.part_color = SPColorN (line, "partcol", def_partcol);
|
||||
fog.is_on = SPBoolN(line, "fog", true);
|
||||
fog.start = SPFloatN(line, "fogstart", 20);
|
||||
fog.end = SPFloatN(line, "fogend", param.forward_clip_distance);
|
||||
fog.height = SPFloatN(line, "fogheight", 0);
|
||||
SPArrN(line, "fogcol", fog.color, 4, 1);
|
||||
fog.part_color = SPColorN(line, "partcol", def_partcol);
|
||||
} else if (idx < 4) {
|
||||
lights[idx].is_on = true;
|
||||
SPArrN (line, "amb", lights[idx].ambient, 4, 1);
|
||||
SPArrN (line, "diff", lights[idx].diffuse, 4, 1);
|
||||
SPArrN (line, "spec", lights[idx].specular, 4, 1);
|
||||
SPArrN (line, "pos", lights[idx].position, 4, 1);
|
||||
SPArrN(line, "amb", lights[idx].ambient, 4, 1);
|
||||
SPArrN(line, "diff", lights[idx].diffuse, 4, 1);
|
||||
SPArrN(line, "spec", lights[idx].specular, 4, 1);
|
||||
SPArrN(line, "pos", lights[idx].position, 4, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CEnvironment::DrawSkybox (const TVector3d& pos) {
|
||||
void CEnvironment::DrawSkybox(const TVector3d& pos) {
|
||||
ScopedRenderMode rm(SKY);
|
||||
|
||||
#if defined (OS_LINUX)
|
||||
|
@ -213,8 +213,8 @@ void CEnvironment::DrawSkybox (const TVector3d& pos) {
|
|||
static const float bb = 0.995f;
|
||||
#endif
|
||||
|
||||
glColor4f (1.0, 1.0, 1.0, 1.0);
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
||||
glPushMatrix();
|
||||
glTranslate(pos);
|
||||
|
||||
|
@ -303,7 +303,7 @@ void CEnvironment::DrawSkybox (const TVector3d& pos) {
|
|||
glPopMatrix();
|
||||
}
|
||||
|
||||
void CEnvironment::DrawFog () {
|
||||
void CEnvironment::DrawFog() {
|
||||
if (!fog.is_on)
|
||||
return;
|
||||
|
||||
|
@ -313,32 +313,32 @@ void CEnvironment::DrawFog () {
|
|||
TVector3d bottomleft, bottomright;
|
||||
|
||||
// the clipping planes are calculated by view frustum (view.cpp)
|
||||
const TPlane& leftclip = get_left_clip_plane ();
|
||||
const TPlane& rightclip = get_right_clip_plane ();
|
||||
const TPlane& farclip = get_far_clip_plane ();
|
||||
const TPlane& bottomclip = get_bottom_clip_plane ();
|
||||
const TPlane& leftclip = get_left_clip_plane();
|
||||
const TPlane& rightclip = get_right_clip_plane();
|
||||
const TPlane& farclip = get_far_clip_plane();
|
||||
const TPlane& bottomclip = get_bottom_clip_plane();
|
||||
|
||||
// --------------- calculate the planes ---------------------------
|
||||
|
||||
double slope = tan (ANGLES_TO_RADIANS (Course.GetCourseAngle()));
|
||||
double slope = tan(ANGLES_TO_RADIANS(Course.GetCourseAngle()));
|
||||
// TPlane left_edge_plane = MakePlane (1.0, 0.0, 0.0, 0.0);
|
||||
// TPlane right_edge_plane = MakePlane (-1.0, 0.0, 0.0, Course.width);
|
||||
|
||||
bottom_plane.nml = TVector3d(0.0, 1, -slope);
|
||||
float height = Course.GetBaseHeight (0);
|
||||
float height = Course.GetBaseHeight(0);
|
||||
bottom_plane.d = -height * bottom_plane.nml.y;
|
||||
|
||||
top_plane.nml = bottom_plane.nml;
|
||||
height = Course.GetMaxHeight (0) + fog.height;
|
||||
height = Course.GetMaxHeight(0) + fog.height;
|
||||
top_plane.d = -height * top_plane.nml.y;
|
||||
|
||||
|
||||
if (!IntersectPlanes (bottom_plane, farclip, leftclip, &left)) return;
|
||||
if (!IntersectPlanes (bottom_plane, farclip, rightclip, &right)) return;
|
||||
if (!IntersectPlanes (top_plane, farclip, leftclip, &topleft)) return;
|
||||
if (!IntersectPlanes (top_plane, farclip, rightclip, &topright)) return;
|
||||
if (!IntersectPlanes (bottomclip, farclip, leftclip, &bottomleft)) return;
|
||||
if (!IntersectPlanes (bottomclip, farclip, rightclip, &bottomright)) return;
|
||||
if (!IntersectPlanes(bottom_plane, farclip, leftclip, &left)) return;
|
||||
if (!IntersectPlanes(bottom_plane, farclip, rightclip, &right)) return;
|
||||
if (!IntersectPlanes(top_plane, farclip, leftclip, &topleft)) return;
|
||||
if (!IntersectPlanes(top_plane, farclip, rightclip, &topright)) return;
|
||||
if (!IntersectPlanes(bottomclip, farclip, leftclip, &bottomleft)) return;
|
||||
if (!IntersectPlanes(bottomclip, farclip, rightclip, &bottomright)) return;
|
||||
|
||||
TVector3d leftvec = topleft - left;
|
||||
TVector3d rightvec = topright - right;
|
||||
|
@ -346,7 +346,7 @@ void CEnvironment::DrawFog () {
|
|||
// --------------- draw the fog plane -----------------------------
|
||||
|
||||
ScopedRenderMode rm(FOG_PLANE);
|
||||
glEnable (GL_FOG);
|
||||
glEnable(GL_FOG);
|
||||
|
||||
// only the alpha channel is used
|
||||
static const GLfloat bottom_dens[4] = {0, 0, 0, 1.0};
|
||||
|
@ -354,24 +354,24 @@ void CEnvironment::DrawFog () {
|
|||
static const GLfloat leftright_dens[4] = { 0, 0, 0, 0.3 };
|
||||
static const GLfloat top_bottom_dens[4] = { 0, 0, 0, 0.0 };
|
||||
|
||||
glBegin (GL_QUAD_STRIP);
|
||||
glColor4fv (bottom_dens);
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
glColor4fv(bottom_dens);
|
||||
glVertex3(bottomleft);
|
||||
glVertex3(bottomright);
|
||||
glVertex3(left);
|
||||
glVertex3(right);
|
||||
|
||||
glColor4fv (top_dens);
|
||||
glColor4fv(top_dens);
|
||||
glVertex3(topleft);
|
||||
glVertex3(topright);
|
||||
|
||||
glColor4fv (leftright_dens);
|
||||
glColor4fv(leftright_dens);
|
||||
vpoint = topleft + leftvec;
|
||||
glVertex3(vpoint);
|
||||
vpoint = topright + rightvec;
|
||||
glVertex3(vpoint);
|
||||
|
||||
glColor4fv (top_bottom_dens);
|
||||
glColor4fv(top_bottom_dens);
|
||||
vpoint = topleft + 3.0 * leftvec;
|
||||
glVertex3(vpoint);
|
||||
vpoint = topright + 3.0 * rightvec;
|
||||
|
@ -380,7 +380,7 @@ void CEnvironment::DrawFog () {
|
|||
}
|
||||
|
||||
|
||||
void CEnvironment::LoadEnvironment (size_t loc, size_t light) {
|
||||
void CEnvironment::LoadEnvironment(size_t loc, size_t light) {
|
||||
if (loc >= locs.size()) loc = 0;
|
||||
if (light >= 4) light = 0;
|
||||
// remember: with (example) 3 locations and 4 lights there
|
||||
|
@ -392,24 +392,24 @@ void CEnvironment::LoadEnvironment (size_t loc, size_t light) {
|
|||
EnvID = env_id;
|
||||
|
||||
// Set directory. The dir is used several times.
|
||||
string EnvDir = GetDir (loc, light);
|
||||
string EnvDir = GetDir(loc, light);
|
||||
|
||||
// Load skybox. If the sky can't be loaded for any reason, the
|
||||
// texture id's are set to 0 and the sky will not be drawn.
|
||||
// There is no error handling, you see the result on the screen.
|
||||
ResetSkybox ();
|
||||
ResetSkybox();
|
||||
LoadSkybox(EnvDir, locs[loc].high_res);
|
||||
|
||||
// Load light conditions.
|
||||
ResetFog ();
|
||||
ResetLight ();
|
||||
LoadLight (EnvDir);
|
||||
ResetFog();
|
||||
ResetLight();
|
||||
LoadLight(EnvDir);
|
||||
}
|
||||
|
||||
size_t CEnvironment::GetEnvIdx (const string& tag) const {
|
||||
size_t CEnvironment::GetEnvIdx(const string& tag) const {
|
||||
return EnvIndex.at(tag);
|
||||
}
|
||||
|
||||
size_t CEnvironment::GetLightIdx (const string& tag) const {
|
||||
size_t CEnvironment::GetLightIdx(const string& tag) const {
|
||||
return LightIndex.at(tag);
|
||||
}
|
||||
|
|
30
src/env.h
30
src/env.h
|
@ -64,25 +64,25 @@ private:
|
|||
map<string, size_t> EnvIndex;
|
||||
map<string, size_t> LightIndex;
|
||||
|
||||
void ResetSkybox ();
|
||||
void ResetSkybox();
|
||||
void LoadSkybox(const string& EnvDir, bool high_res);
|
||||
void LoadSkyboxSide(size_t index, const string& EnvDir, const string& name, bool high_res);
|
||||
void ResetLight ();
|
||||
void LoadLight (const string& EnvDir);
|
||||
void ResetFog ();
|
||||
void Reset ();
|
||||
string GetDir (size_t location, size_t light) const;
|
||||
void ResetLight();
|
||||
void LoadLight(const string& EnvDir);
|
||||
void ResetFog();
|
||||
void Reset();
|
||||
string GetDir(size_t location, size_t light) const;
|
||||
public:
|
||||
CEnvironment ();
|
||||
bool LoadEnvironmentList ();
|
||||
void LoadEnvironment (size_t loc, size_t light);
|
||||
void DrawSkybox (const TVector3d& pos);
|
||||
void SetupLight ();
|
||||
void SetupFog ();
|
||||
void DrawFog ();
|
||||
CEnvironment();
|
||||
bool LoadEnvironmentList();
|
||||
void LoadEnvironment(size_t loc, size_t light);
|
||||
void DrawSkybox(const TVector3d& pos);
|
||||
void SetupLight();
|
||||
void SetupFog();
|
||||
void DrawFog();
|
||||
const sf::Color& ParticleColor() const { return fog.part_color; }
|
||||
size_t GetEnvIdx (const string& tag) const;
|
||||
size_t GetLightIdx (const string& tag) const;
|
||||
size_t GetEnvIdx(const string& tag) const;
|
||||
size_t GetLightIdx(const string& tag) const;
|
||||
};
|
||||
|
||||
extern CEnvironment Env;
|
||||
|
|
106
src/event.cpp
106
src/event.cpp
|
@ -48,9 +48,9 @@ static TLabel* headline;
|
|||
static TLabel* info1;
|
||||
static TLabel* info2;
|
||||
|
||||
void StartRace () {
|
||||
void StartRace() {
|
||||
if (ready > 0) {
|
||||
State::manager.RequestEnterState (EventSelect);
|
||||
State::manager.RequestEnterState(EventSelect);
|
||||
return;
|
||||
}
|
||||
g_game.mirrorred = false;
|
||||
|
@ -61,18 +61,18 @@ void StartRace () {
|
|||
g_game.wind_id = ecup->races[curr_race]->wind;
|
||||
g_game.race = ecup->races[curr_race];
|
||||
g_game.game_type = CUPRACING;
|
||||
State::manager.RequestEnterState (Loading);
|
||||
State::manager.RequestEnterState(Loading);
|
||||
}
|
||||
|
||||
void CEvent::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CEvent::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case sf::Keyboard::Return:
|
||||
if (textbuttons[0]->focussed() && ready < 1) StartRace ();
|
||||
else State::manager.RequestEnterState (EventSelect);
|
||||
if (textbuttons[0]->focussed() && ready < 1) StartRace();
|
||||
else State::manager.RequestEnterState(EventSelect);
|
||||
break;
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestEnterState (EventSelect);
|
||||
State::manager.RequestEnterState(EventSelect);
|
||||
break;
|
||||
case sf::Keyboard::U:
|
||||
param.ui_snow = !param.ui_snow;
|
||||
|
@ -82,31 +82,31 @@ void CEvent::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int
|
|||
}
|
||||
}
|
||||
|
||||
void CEvent::Mouse (int button, int state, int x, int y) {
|
||||
void CEvent::Mouse(int button, int state, int x, int y) {
|
||||
if (state != 1) return;
|
||||
|
||||
TWidget* clicked = ClickGUI(x, y);
|
||||
if (clicked == textbuttons[0]) {
|
||||
if (ready < 1)
|
||||
StartRace ();
|
||||
StartRace();
|
||||
} else if (clicked == textbuttons[1] || clicked == textbuttons[2])
|
||||
State::manager.RequestEnterState (EventSelect);
|
||||
State::manager.RequestEnterState(EventSelect);
|
||||
}
|
||||
|
||||
void CEvent::Motion (int x, int y) {
|
||||
void CEvent::Motion(int x, int y) {
|
||||
MouseMoveGUI(x, y);
|
||||
|
||||
if (param.ui_snow) push_ui_snow (cursor_pos);
|
||||
if (param.ui_snow) push_ui_snow(cursor_pos);
|
||||
}
|
||||
|
||||
void InitCupRacing () {
|
||||
void InitCupRacing() {
|
||||
ecup = g_game.cup;
|
||||
curr_race = 0;
|
||||
curr_bonus = ecup->races.size();
|
||||
ready = 0;
|
||||
}
|
||||
|
||||
void UpdateCupRacing () {
|
||||
void UpdateCupRacing() {
|
||||
size_t lastrace = ecup->races.size() - 1;
|
||||
curr_bonus += g_game.race_result;
|
||||
if (g_game.race_result >= 0) {
|
||||
|
@ -116,8 +116,8 @@ void UpdateCupRacing () {
|
|||
if (curr_bonus == 0) ready = 2;
|
||||
}
|
||||
if (ready == 1) {
|
||||
Players.AddPassedCup (ecup->cup);
|
||||
Players.SavePlayers ();
|
||||
Players.AddPassedCup(ecup->cup);
|
||||
Players.SavePlayers();
|
||||
}
|
||||
|
||||
headline->SetVisible(ready == 0);
|
||||
|
@ -132,29 +132,29 @@ static int messtop, messtop2;
|
|||
static int bonustop, framewidth, frametop;
|
||||
static int dist, texsize;
|
||||
|
||||
void CEvent::Enter () {
|
||||
Winsys.ShowCursor (!param.ice_cursor);
|
||||
void CEvent::Enter() {
|
||||
Winsys.ShowCursor(!param.ice_cursor);
|
||||
|
||||
if (State::manager.PreviousState() == &GameOver) UpdateCupRacing ();
|
||||
else InitCupRacing ();
|
||||
if (State::manager.PreviousState() == &GameOver) UpdateCupRacing();
|
||||
else InitCupRacing();
|
||||
|
||||
framewidth = 500;
|
||||
frametop = AutoYPosN (45);
|
||||
area = AutoAreaN (30, 80, framewidth);
|
||||
messtop = AutoYPosN (50);
|
||||
messtop2 = AutoYPosN (60);
|
||||
bonustop = AutoYPosN (35);
|
||||
frametop = AutoYPosN(45);
|
||||
area = AutoAreaN(30, 80, framewidth);
|
||||
messtop = AutoYPosN(50);
|
||||
messtop2 = AutoYPosN(60);
|
||||
bonustop = AutoYPosN(35);
|
||||
texsize = 32 * Winsys.scale;
|
||||
if (texsize < 32) texsize = 32;
|
||||
dist = texsize + 2 * 4;
|
||||
int framebottom = frametop + (int) ecup->races.size() * dist + 10;
|
||||
|
||||
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));
|
||||
textbuttons[0] = AddTextButton (Trans.Text(13), area.right -len - 100, AutoYPosN (80), siz);
|
||||
textbuttons[2] = AddTextButton (Trans.Text(15), CENTER, AutoYPosN (80), siz);
|
||||
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));
|
||||
textbuttons[0] = AddTextButton(Trans.Text(13), area.right -len - 100, AutoYPosN(80), siz);
|
||||
textbuttons[2] = AddTextButton(Trans.Text(15), CENTER, AutoYPosN(80), siz);
|
||||
|
||||
FT.AutoSizeN(6);
|
||||
headline = AddLabel(ecup->name, CENTER, AutoYPosN(25), colWhite);
|
||||
|
@ -177,19 +177,19 @@ void CEvent::Enter () {
|
|||
Music.Play(param.menu_music, true);
|
||||
}
|
||||
|
||||
int resultlevel (size_t num, size_t numraces) {
|
||||
int resultlevel(size_t num, size_t numraces) {
|
||||
if (num < 1) return 0;
|
||||
int q = (int)((num - 0.01) / numraces);
|
||||
return q + 1;
|
||||
}
|
||||
|
||||
void CEvent::Loop (double timestep) {
|
||||
void CEvent::Loop(double timestep) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow (timestep);
|
||||
draw_ui_snow ();
|
||||
update_ui_snow(timestep);
|
||||
draw_ui_snow();
|
||||
}
|
||||
DrawGUIBackground(Winsys.scale);
|
||||
|
||||
|
@ -197,38 +197,38 @@ void CEvent::Loop (double timestep) {
|
|||
// 0, colMBackgr, colBlack, 0.2);
|
||||
|
||||
if (ready == 0) { // cup not finished
|
||||
DrawBonusExt (bonustop, (int)ecup->races.size(), curr_bonus);
|
||||
DrawBonusExt(bonustop, (int)ecup->races.size(), curr_bonus);
|
||||
|
||||
DrawFrameX (area.left, frametop, framewidth,
|
||||
(int)ecup->races.size() * dist + 20, 3, colBackgr, colWhite, 1);
|
||||
DrawFrameX(area.left, frametop, framewidth,
|
||||
(int)ecup->races.size() * dist + 20, 3, colBackgr, colWhite, 1);
|
||||
|
||||
TCheckbox checkbox(area.right - 50, frametop, texsize, "");
|
||||
for (size_t i=0; i<ecup->races.size(); i++) {
|
||||
FT.AutoSizeN (3);
|
||||
FT.AutoSizeN(3);
|
||||
|
||||
int y = frametop + 10 + (int)i * dist;
|
||||
if (i == curr_race)
|
||||
FT.SetColor (colDYell);
|
||||
FT.SetColor(colDYell);
|
||||
else
|
||||
FT.SetColor (colWhite);
|
||||
FT.DrawString (area.left + 29, y, ecup->races[i]->course->name);
|
||||
FT.SetColor(colWhite);
|
||||
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();
|
||||
}
|
||||
} else if (ready == 1) { // cup successfully finished
|
||||
FT.AutoSizeN (5);
|
||||
FT.SetColor (colWhite);
|
||||
FT.DrawString (CENTER, messtop, Trans.Text(16));
|
||||
DrawBonusExt (bonustop, (int)ecup->races.size(), curr_bonus);
|
||||
FT.AutoSizeN(5);
|
||||
FT.SetColor(colWhite);
|
||||
FT.DrawString(CENTER, messtop, Trans.Text(16));
|
||||
DrawBonusExt(bonustop, (int)ecup->races.size(), curr_bonus);
|
||||
int res = resultlevel(curr_bonus, ecup->races.size());
|
||||
FT.DrawString (CENTER, messtop2, Trans.Text(17) + " " + Int_StrN (res));
|
||||
FT.DrawString(CENTER, messtop2, Trans.Text(17) + " " + Int_StrN(res));
|
||||
} else if (ready == 2) { // cup finished but failed
|
||||
FT.AutoSizeN (5);
|
||||
FT.SetColor (colLRed);
|
||||
FT.DrawString (CENTER, messtop, Trans.Text(18));
|
||||
DrawBonusExt (bonustop, ecup->races.size(), curr_bonus);
|
||||
FT.DrawString (CENTER, messtop2, Trans.Text(19));
|
||||
FT.AutoSizeN(5);
|
||||
FT.SetColor(colLRed);
|
||||
FT.DrawString(CENTER, messtop, Trans.Text(18));
|
||||
DrawBonusExt(bonustop, ecup->races.size(), curr_bonus);
|
||||
FT.DrawString(CENTER, messtop2, Trans.Text(19));
|
||||
}
|
||||
|
||||
textbuttons[0]->SetVisible(ready < 1);
|
||||
|
@ -238,6 +238,6 @@ void CEvent::Loop (double timestep) {
|
|||
textbuttons[1]->SetActive(ready < 1);
|
||||
textbuttons[2]->SetActive(!(ready < 1));
|
||||
|
||||
DrawGUI ();
|
||||
DrawGUI();
|
||||
Winsys.SwapBuffers();
|
||||
}
|
||||
|
|
|
@ -43,24 +43,24 @@ static TFramedText* selectedEvent;
|
|||
static TFramedText* selectedCup;
|
||||
static TLabel* cupLocked;
|
||||
|
||||
void EnterEvent () {
|
||||
void EnterEvent() {
|
||||
g_game.game_type = CUPRACING;
|
||||
g_game.cup = Events.EventList[event->GetValue()].cups[cup->GetValue()];
|
||||
State::manager.RequestEnterState(Event);
|
||||
}
|
||||
|
||||
void CEventSelect::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CEventSelect::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
State::manager.RequestEnterState(GameTypeSelect);
|
||||
break;
|
||||
case sf::Keyboard::Q:
|
||||
State::manager.RequestQuit();
|
||||
break;
|
||||
case sf::Keyboard::Return:
|
||||
if (textbuttons[1]->focussed()) State::manager.RequestEnterState (GameTypeSelect);
|
||||
else if (Events.IsUnlocked (event->GetValue(), cup->GetValue())) EnterEvent();
|
||||
if (textbuttons[1]->focussed()) State::manager.RequestEnterState(GameTypeSelect);
|
||||
else if (Events.IsUnlocked(event->GetValue(), cup->GetValue())) EnterEvent();
|
||||
break;
|
||||
case sf::Keyboard::U:
|
||||
param.ui_snow = !param.ui_snow;
|
||||
|
@ -70,25 +70,25 @@ void CEventSelect::Keyb (sf::Keyboard::Key key, bool special, bool release, int
|
|||
}
|
||||
}
|
||||
|
||||
void CEventSelect::Mouse (int button, int state, int x, int y) {
|
||||
void CEventSelect::Mouse(int button, int state, int x, int y) {
|
||||
if (state == 1) {
|
||||
TWidget* clicked = ClickGUI(x, y);
|
||||
if (textbuttons[0] == clicked) {
|
||||
if (Events.IsUnlocked (event->GetValue(), cup->GetValue()))
|
||||
if (Events.IsUnlocked(event->GetValue(), cup->GetValue()))
|
||||
EnterEvent();
|
||||
} else if (textbuttons[1] == clicked)
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
State::manager.RequestEnterState(GameTypeSelect);
|
||||
}
|
||||
}
|
||||
|
||||
void CEventSelect::Motion (int x, int y) {
|
||||
void CEventSelect::Motion(int x, int y) {
|
||||
MouseMoveGUI(x, y);
|
||||
|
||||
if (param.ui_snow) push_ui_snow (cursor_pos);
|
||||
if (param.ui_snow) push_ui_snow(cursor_pos);
|
||||
}
|
||||
|
||||
void CEventSelect::Enter () {
|
||||
Winsys.ShowCursor (!param.ice_cursor);
|
||||
void CEventSelect::Enter() {
|
||||
Winsys.ShowCursor(!param.ice_cursor);
|
||||
|
||||
int framewidth = 500 * Winsys.scale;
|
||||
int frameheight = 50 * Winsys.scale;
|
||||
|
@ -100,11 +100,11 @@ void CEventSelect::Enter () {
|
|||
event = AddUpDown(area.right+8, frametop1, 0, (int)Events.EventList.size() - 1, 0);
|
||||
cup = AddUpDown(area.right + 8, frametop2, 0, (int)Events.EventList[0].cups.size() - 1, 0);
|
||||
|
||||
int siz = FT.AutoSizeN (5);
|
||||
int siz = FT.AutoSizeN(5);
|
||||
|
||||
double 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);
|
||||
double 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]);
|
||||
|
||||
FT.AutoSizeN(3);
|
||||
|
@ -116,17 +116,17 @@ 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 (g_game.player->funlocked);
|
||||
Events.MakeUnlockList(g_game.player->funlocked);
|
||||
Music.Play(param.menu_music, true);
|
||||
}
|
||||
|
||||
void CEventSelect::Loop (double timestep) {
|
||||
void CEventSelect::Loop(double timestep) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow (timestep);
|
||||
draw_ui_snow ();
|
||||
update_ui_snow(timestep);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
DrawGUIBackground(Winsys.scale);
|
||||
|
@ -140,7 +140,7 @@ void CEventSelect::Loop (double timestep) {
|
|||
selectedCup->Focussed(cup->focussed());
|
||||
selectedCup->SetString(Events.GetCupTrivialName(event->GetValue(), cup->GetValue()));
|
||||
|
||||
textbuttons[0]->SetActive(Events.IsUnlocked (event->GetValue(), cup->GetValue()));
|
||||
textbuttons[0]->SetActive(Events.IsUnlocked(event->GetValue(), cup->GetValue()));
|
||||
DrawGUI();
|
||||
|
||||
Winsys.SwapBuffers();
|
||||
|
|
50
src/font.cpp
50
src/font.cpp
|
@ -33,7 +33,7 @@ GNU General Public License for more details.
|
|||
// CFont::MakeLineList. This bundle of functions generates
|
||||
// a vector<string> from a textstring and adapts the lines to the textbox
|
||||
|
||||
static void MakeWordList (vector<string>& wordlist, const char *s) {
|
||||
static void MakeWordList(vector<string>& wordlist, const char *s) {
|
||||
size_t start = 0;
|
||||
for (size_t i = 0; s[i] != '\0'; i++) {
|
||||
if (s[i] == ' ') {
|
||||
|
@ -48,7 +48,7 @@ static void MakeWordList (vector<string>& wordlist, const char *s) {
|
|||
wordlist.push_back(string(s+start));
|
||||
}
|
||||
|
||||
static size_t MakeLine (size_t first, const vector<string>& wordlist, vector<string>& linelist, float width) {
|
||||
static size_t MakeLine(size_t first, const vector<string>& wordlist, vector<string>& linelist, float width) {
|
||||
if (first >= wordlist.size()) return wordlist.size()-1;
|
||||
|
||||
size_t last = first;
|
||||
|
@ -82,7 +82,7 @@ static size_t MakeLine (size_t first, const vector<string>& wordlist, vector<str
|
|||
|
||||
CFont FT;
|
||||
|
||||
CFont::CFont () {
|
||||
CFont::CFont() {
|
||||
forientation = OR_TOP;
|
||||
|
||||
// setting default values
|
||||
|
@ -99,7 +99,7 @@ CFont::~CFont() {
|
|||
Clear();
|
||||
}
|
||||
|
||||
void CFont::Clear () {
|
||||
void CFont::Clear() {
|
||||
for (size_t i = 0; i < fonts.size(); i++)
|
||||
delete fonts[i];
|
||||
fonts.clear();
|
||||
|
@ -110,10 +110,10 @@ void CFont::Clear () {
|
|||
// public
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
int CFont::LoadFont (const string& name, const string& path) {
|
||||
int CFont::LoadFont(const string& name, const string& path) {
|
||||
fonts.push_back(new sf::Font());
|
||||
if (!fonts.back()->loadFromFile(path)) {
|
||||
Message ("Failed to open font");
|
||||
Message("Failed to open font");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -125,26 +125,26 @@ int CFont::LoadFont(const string& name, const string& dir, const string& filenam
|
|||
string path = dir;
|
||||
path += SEP;
|
||||
path += filename;
|
||||
return LoadFont (name, path);
|
||||
return LoadFont(name, path);
|
||||
}
|
||||
|
||||
bool CFont::LoadFontlist () {
|
||||
bool CFont::LoadFontlist() {
|
||||
CSPList list(MAX_FONTS);
|
||||
if (!list.Load ( param.font_dir, "fonts.lst")) return false;
|
||||
if (!list.Load(param.font_dir, "fonts.lst")) return false;
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
string fontfile = SPStrN (line, "file");
|
||||
string name = SPStrN (line, "name");
|
||||
string fontfile = SPStrN(line, "file");
|
||||
string name = SPStrN(line, "name");
|
||||
|
||||
int ftidx = LoadFont (name, param.font_dir, fontfile);
|
||||
int ftidx = LoadFont(name, param.font_dir, fontfile);
|
||||
if (ftidx < 0) {
|
||||
Message ("couldn't load font", name);
|
||||
Message("couldn't load font", name);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t CFont::GetFontIdx (const string &name) const {
|
||||
size_t CFont::GetFontIdx(const string &name) const {
|
||||
return fontindex.at(name);
|
||||
}
|
||||
|
||||
|
@ -153,12 +153,12 @@ void CFont::SetProps(const string &fontname, float size, const sf::Color& col) {
|
|||
curr_col = col;
|
||||
}
|
||||
|
||||
void CFont::SetProps (const string &fontname, float size) {
|
||||
curr_font = (int)GetFontIdx (fontname);
|
||||
void CFont::SetProps(const string &fontname, float size) {
|
||||
curr_font = (int)GetFontIdx(fontname);
|
||||
curr_size = size;
|
||||
}
|
||||
|
||||
void CFont::SetFont (const string& fontname) {
|
||||
void CFont::SetFont(const string& fontname) {
|
||||
try {
|
||||
curr_font = (int)fontindex[fontname];
|
||||
} catch (...) {
|
||||
|
@ -178,15 +178,15 @@ void CFont::SetFontFromSettings() {
|
|||
|
||||
// -------------------- auto ------------------------------------------
|
||||
|
||||
int CFont::AutoSizeN (int rel_val) {
|
||||
int CFont::AutoSizeN(int rel_val) {
|
||||
float size = (rel_val + 2) * 4;
|
||||
size *= curr_fact;
|
||||
size *= Winsys.scale;
|
||||
SetSize (size);
|
||||
SetSize(size);
|
||||
return (int)size;
|
||||
}
|
||||
|
||||
int CFont::AutoDistanceN (int rel_val) {
|
||||
int CFont::AutoDistanceN(int rel_val) {
|
||||
float fact = (rel_val + 5) * 0.2;
|
||||
float dist = curr_size * fact;
|
||||
return (int) dist;
|
||||
|
@ -238,18 +238,18 @@ float CFont::GetTextWidth(const sf::String& text) const {
|
|||
return x;
|
||||
}
|
||||
|
||||
float CFont::GetTextWidth (const sf::String& text, const string &fontname, float size) const {
|
||||
size_t temp_font = GetFontIdx (fontname);
|
||||
float CFont::GetTextWidth(const sf::String& text, const string &fontname, float size) const {
|
||||
size_t temp_font = GetFontIdx(fontname);
|
||||
float x, y;
|
||||
GetTextSize(text, x, y, temp_font, size);
|
||||
return x;
|
||||
}
|
||||
|
||||
float CFont::CenterX (const char *text) const {
|
||||
return (Winsys.resolution.width - GetTextWidth (text)) / 2.0;
|
||||
float CFont::CenterX(const char *text) const {
|
||||
return (Winsys.resolution.width - GetTextWidth(text)) / 2.0;
|
||||
}
|
||||
|
||||
vector<string> CFont::MakeLineList (const char *source, float width) {
|
||||
vector<string> CFont::MakeLineList(const char *source, float width) {
|
||||
vector<string> wordlist;
|
||||
MakeWordList(wordlist, source);
|
||||
vector<string> linelist;
|
||||
|
|
24
src/font.h
24
src/font.h
|
@ -44,28 +44,28 @@ private:
|
|||
void DrawText(float x, float y, const sf::String& text, size_t font, float size) const;
|
||||
void GetTextSize(const sf::String& text, float &x, float &y, size_t font, float size) const;
|
||||
public:
|
||||
CFont ();
|
||||
~CFont ();
|
||||
CFont();
|
||||
~CFont();
|
||||
|
||||
void Clear ();
|
||||
void Clear();
|
||||
int LoadFont(const string& name, const string& dir, const string& filename);
|
||||
int LoadFont(const string& name, const string& path);
|
||||
bool LoadFontlist ();
|
||||
size_t GetFontIdx (const string &name) const;
|
||||
bool LoadFontlist();
|
||||
size_t GetFontIdx(const string &name) const;
|
||||
const sf::Font& getCurrentFont() const { return *fonts[curr_font]; }
|
||||
float GetSize() const { return curr_size; }
|
||||
|
||||
// properties
|
||||
void SetProps(const string &fontname, float size, const sf::Color& col);
|
||||
void SetProps (const string &fontname, float size);
|
||||
void SetProps(const string &fontname, float size);
|
||||
void SetColor(const sf::Color& col) { curr_col = col; }
|
||||
void SetSize (float size) { curr_size = size; }
|
||||
void SetSize(float size) { curr_size = size; }
|
||||
void SetFont(const string& fontname);
|
||||
void SetFontFromSettings();
|
||||
|
||||
// auto
|
||||
int AutoSizeN (int rel_val); // rel_val = relative size, return: autosize
|
||||
int AutoDistanceN (int rel_val); // rel_val = relative dist
|
||||
int AutoSizeN(int rel_val); // rel_val = relative size, return: autosize
|
||||
int AutoDistanceN(int rel_val); // rel_val = relative dist
|
||||
|
||||
// draw
|
||||
void DrawString(float x, float y, const sf::String &s) const; // sf::String class
|
||||
|
@ -77,10 +77,10 @@ public:
|
|||
float GetTextWidth(const sf::String& text) const;
|
||||
float GetTextWidth(const sf::String& text, const string &fontname, float size) const;
|
||||
|
||||
float CenterX (const char *text) const;
|
||||
void SetOrientation (Orientation orientation) { forientation = orientation; }
|
||||
float CenterX(const char *text) const;
|
||||
void SetOrientation(Orientation orientation) { forientation = orientation; }
|
||||
|
||||
vector<string> MakeLineList (const char *source, float width);
|
||||
vector<string> MakeLineList(const char *source, float width);
|
||||
};
|
||||
|
||||
extern CFont FT;
|
||||
|
|
|
@ -47,46 +47,46 @@ Then edit the below functions:
|
|||
TParam param;
|
||||
|
||||
|
||||
void LoadConfigFile () {
|
||||
void LoadConfigFile() {
|
||||
CSPList list(4);
|
||||
if (!list.Load (param.configfile)) {
|
||||
Message ("Could not load 'options'");
|
||||
if (!list.Load(param.configfile)) {
|
||||
Message("Could not load 'options'");
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
|
||||
param.fullscreen = SPBoolN (line, "fullscreen", false);
|
||||
param.res_type = SPIntN (line, "res_type", 0);
|
||||
param.perf_level = SPIntN (line, "detail_level", 3);
|
||||
param.fullscreen = SPBoolN(line, "fullscreen", false);
|
||||
param.res_type = SPIntN(line, "res_type", 0);
|
||||
param.perf_level = SPIntN(line, "detail_level", 3);
|
||||
param.language = Trans.GetLangIdx(SPStrN(line, "language", "EN_en"));
|
||||
param.sound_volume = SPIntN (line, "sound_volume", 90);
|
||||
param.music_volume = SPIntN (line, "music_volume", 20);
|
||||
param.sound_volume = SPIntN(line, "sound_volume", 90);
|
||||
param.music_volume = SPIntN(line, "music_volume", 20);
|
||||
|
||||
param.framerate = SPIntN (line, "framerate", 60);
|
||||
param.framerate = SPIntN(line, "framerate", 60);
|
||||
|
||||
param.forward_clip_distance = SPIntN (line, "forward_clip_distance", 75);
|
||||
param.backward_clip_distance = SPIntN (line, "backward_clip_distance", 20);
|
||||
param.fov = SPIntN (line, "fov", 60);
|
||||
param.bpp_mode = SPIntN (line, "bpp_mode", 0);
|
||||
param.tree_detail_distance = SPIntN (line, "tree_detail_distance", 20);
|
||||
param.tux_sphere_divisions = SPIntN (line, "tux_sphere_divisions", 10);
|
||||
param.tux_shadow_sphere_divisions = SPIntN (line, "tux_shadow_sphere_div", 3);
|
||||
param.course_detail_level = SPIntN (line, "course_detail_level", 75);
|
||||
param.forward_clip_distance = SPIntN(line, "forward_clip_distance", 75);
|
||||
param.backward_clip_distance = SPIntN(line, "backward_clip_distance", 20);
|
||||
param.fov = SPIntN(line, "fov", 60);
|
||||
param.bpp_mode = SPIntN(line, "bpp_mode", 0);
|
||||
param.tree_detail_distance = SPIntN(line, "tree_detail_distance", 20);
|
||||
param.tux_sphere_divisions = SPIntN(line, "tux_sphere_divisions", 10);
|
||||
param.tux_shadow_sphere_divisions = SPIntN(line, "tux_shadow_sphere_div", 3);
|
||||
param.course_detail_level = SPIntN(line, "course_detail_level", 75);
|
||||
|
||||
param.use_papercut_font = SPIntN (line, "use_papercut_font", 1);
|
||||
param.ice_cursor = SPIntN (line, "ice_cursor", 1) != 0;
|
||||
param.full_skybox = SPBoolN (line, "full_skybox", false);
|
||||
param.use_quad_scale = SPBoolN (line, "use_quad_scale", false);
|
||||
param.use_papercut_font = SPIntN(line, "use_papercut_font", 1);
|
||||
param.ice_cursor = SPIntN(line, "ice_cursor", 1) != 0;
|
||||
param.full_skybox = SPBoolN(line, "full_skybox", false);
|
||||
param.use_quad_scale = SPBoolN(line, "use_quad_scale", false);
|
||||
|
||||
param.menu_music = SPStrN (line, "menu_music", "start_1");
|
||||
param.credits_music = SPStrN (line, "credits_music", "credits_1");
|
||||
param.config_music = SPStrN (line, "config_music", "options_1");
|
||||
param.menu_music = SPStrN(line, "menu_music", "start_1");
|
||||
param.credits_music = SPStrN(line, "credits_music", "credits_1");
|
||||
param.config_music = SPStrN(line, "config_music", "options_1");
|
||||
}
|
||||
}
|
||||
|
||||
void SetConfigDefaults () {
|
||||
void SetConfigDefaults() {
|
||||
param.fullscreen = true;
|
||||
param.res_type = 0; // 0=auto / 1=800x600 / 2=1024x768 ...
|
||||
param.perf_level = 3; // detail level
|
||||
|
@ -122,56 +122,56 @@ template<typename T>
|
|||
void AddItem(CSPList &list, const string& tag, T content) {
|
||||
ostringstream os;
|
||||
os << " [" << tag << "] " << content;
|
||||
list.Add (os.str());
|
||||
list.Add(os.str());
|
||||
}
|
||||
|
||||
void AddComment (CSPList &list, const string& comment) {
|
||||
void AddComment(CSPList &list, const string& comment) {
|
||||
string line = "# " + comment;
|
||||
list.Add (line);
|
||||
list.Add(line);
|
||||
}
|
||||
|
||||
void SaveConfigFile () {
|
||||
CSPList liste (512);
|
||||
void SaveConfigFile() {
|
||||
CSPList liste(512);
|
||||
|
||||
liste.Add ("# ------------------------------------------------------------------");
|
||||
liste.Add ("# The first group of params can be adjusted ");
|
||||
liste.Add ("# on the configuration screen, too");
|
||||
liste.Add ("# ------------------------------------------------------------------");
|
||||
liste.Add("# ------------------------------------------------------------------");
|
||||
liste.Add("# The first group of params can be adjusted ");
|
||||
liste.Add("# on the configuration screen, too");
|
||||
liste.Add("# ------------------------------------------------------------------");
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Full-screen mode [0...1]");
|
||||
AddComment(liste, "Full-screen mode [0...1]");
|
||||
AddItem(liste, "fullscreen", param.fullscreen);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Screen resolution [0...9]");
|
||||
AddComment (liste, "0 = auto, 1 = 800x600, 2 = 1024x768");
|
||||
AddComment (liste, "3 = 1152x864, 4 = 1280x960, 5 = 1280x1024");
|
||||
AddComment (liste, "6 = 1360x768, 7 = 1400x1050, 8 = 1440x900, 9=1680x1050");
|
||||
AddComment(liste, "Screen resolution [0...9]");
|
||||
AddComment(liste, "0 = auto, 1 = 800x600, 2 = 1024x768");
|
||||
AddComment(liste, "3 = 1152x864, 4 = 1280x960, 5 = 1280x1024");
|
||||
AddComment(liste, "6 = 1360x768, 7 = 1400x1050, 8 = 1440x900, 9=1680x1050");
|
||||
AddItem(liste, "res_type", param.res_type);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Level of details [1...3]");
|
||||
AddComment (liste, "1 = best performance, 3 = best appearance");
|
||||
AddComment(liste, "Level of details [1...3]");
|
||||
AddComment(liste, "1 = best performance, 3 = best appearance");
|
||||
AddItem(liste, "detail_level", param.perf_level);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Language code");
|
||||
AddComment (liste, "en_GB = English etc.");
|
||||
AddComment(liste, "Language code");
|
||||
AddComment(liste, "en_GB = English etc.");
|
||||
AddItem(liste, "language", Trans.languages[param.language].lang);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Sound volume [0...100]");
|
||||
AddComment (liste, "Sounds are the terrain effects or the pickup noise.");
|
||||
AddComment(liste, "Sound volume [0...100]");
|
||||
AddComment(liste, "Sounds are the terrain effects or the pickup noise.");
|
||||
AddItem(liste, "sound_volume", param.sound_volume);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Volume of the background music [0...100]");
|
||||
AddComment(liste, "Volume of the background music [0...100]");
|
||||
AddItem(liste, "music_volume", param.music_volume);
|
||||
liste.AddLine();
|
||||
|
||||
liste.Add ("# ------------------------------------------------------------------");
|
||||
liste.Add ("# The second group of params must be adjusted in this file.");
|
||||
liste.Add ("# ------------------------------------------------------------------");
|
||||
liste.Add("# ------------------------------------------------------------------");
|
||||
liste.Add("# The second group of params must be adjusted in this file.");
|
||||
liste.Add("# ------------------------------------------------------------------");
|
||||
liste.AddLine();
|
||||
|
||||
AddComment(liste, "Framerate limit");
|
||||
|
@ -179,92 +179,92 @@ void SaveConfigFile () {
|
|||
AddItem(liste, "framerate", param.framerate);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Forward clipping distance");
|
||||
AddComment (liste, "Controls how far ahead of the camera the course");
|
||||
AddComment (liste, "is rendered. Larger values mean that more of the course is");
|
||||
AddComment (liste, "rendered, resulting in slower performance. Decreasing this ");
|
||||
AddComment (liste, "value is an effective way to improve framerates.");
|
||||
AddComment(liste, "Forward clipping distance");
|
||||
AddComment(liste, "Controls how far ahead of the camera the course");
|
||||
AddComment(liste, "is rendered. Larger values mean that more of the course is");
|
||||
AddComment(liste, "rendered, resulting in slower performance. Decreasing this ");
|
||||
AddComment(liste, "value is an effective way to improve framerates.");
|
||||
AddItem(liste, "forward_clip_distance", param.forward_clip_distance);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Backward clipping distance");
|
||||
AddComment (liste, "Some objects aren't yet clipped to the view frustum, ");
|
||||
AddComment (liste, "so this value is used to control how far up the course these ");
|
||||
AddComment (liste, "objects are drawn.");
|
||||
AddComment(liste, "Backward clipping distance");
|
||||
AddComment(liste, "Some objects aren't yet clipped to the view frustum, ");
|
||||
AddComment(liste, "so this value is used to control how far up the course these ");
|
||||
AddComment(liste, "objects are drawn.");
|
||||
AddItem(liste, "backward_clip_distance", param.backward_clip_distance);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Field of View of the camera");
|
||||
AddComment(liste, "Field of View of the camera");
|
||||
AddItem(liste, "fov", param.fov);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Bpp mode - bits per pixel");
|
||||
AddComment (liste, "Controls the color depth of the OpenGL window");
|
||||
AddComment (liste, "16 = 16 bpp, 32 = 32 bpp,");
|
||||
AddComment (liste, "0 (or any other) = use current bpp setting of operating system,");
|
||||
AddComment(liste, "Bpp mode - bits per pixel");
|
||||
AddComment(liste, "Controls the color depth of the OpenGL window");
|
||||
AddComment(liste, "16 = 16 bpp, 32 = 32 bpp,");
|
||||
AddComment(liste, "0 (or any other) = use current bpp setting of operating system,");
|
||||
AddItem(liste, "bpp_mode", param.bpp_mode);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Tree detail distance");
|
||||
AddComment (liste, "Controls how far up the course the trees are drawn crosswise.");
|
||||
AddComment(liste, "Tree detail distance");
|
||||
AddComment(liste, "Controls how far up the course the trees are drawn crosswise.");
|
||||
AddItem(liste, "tree_detail_distance", param.tree_detail_distance);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Tux sphere divisions");
|
||||
AddComment (liste, "Controls how detailled the character is drawn");
|
||||
AddComment(liste, "Tux sphere divisions");
|
||||
AddComment(liste, "Controls how detailled the character is drawn");
|
||||
AddItem(liste, "tux_sphere_divisions", param.tux_sphere_divisions);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Tux shadow sphere divisions");
|
||||
AddComment (liste, "The same but for the shadow of the character");
|
||||
AddComment(liste, "Tux shadow sphere divisions");
|
||||
AddComment(liste, "The same but for the shadow of the character");
|
||||
AddItem(liste, "tux_shadow_sphere_div", param.tux_shadow_sphere_divisions);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Detail level of the course");
|
||||
AddComment (liste, "This param is used for the quadtree and controls the");
|
||||
AddComment (liste, "LOD of the algorithm. ");
|
||||
AddComment(liste, "Detail level of the course");
|
||||
AddComment(liste, "This param is used for the quadtree and controls the");
|
||||
AddComment(liste, "LOD of the algorithm. ");
|
||||
AddItem(liste, "course_detail_level", param.course_detail_level);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Font type [0...2]");
|
||||
AddComment (liste, "0 = always arial-like font,");
|
||||
AddComment (liste, "1 = papercut font on the menu screens");
|
||||
AddComment (liste, "2 = papercut font for the hud display, too");
|
||||
AddComment(liste, "Font type [0...2]");
|
||||
AddComment(liste, "0 = always arial-like font,");
|
||||
AddComment(liste, "1 = papercut font on the menu screens");
|
||||
AddComment(liste, "2 = papercut font for the hud display, too");
|
||||
AddItem(liste, "use_papercut_font", param.use_papercut_font);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Cursor type [0...1]");
|
||||
AddComment (liste, "0 = normal cursor (arrow), 1 = icicle");
|
||||
AddComment(liste, "Cursor type [0...1]");
|
||||
AddComment(liste, "0 = normal cursor (arrow), 1 = icicle");
|
||||
AddItem(liste, "ice_cursor", (int)param.ice_cursor);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Draw full skybox [0...1]");
|
||||
AddComment (liste, "A normal skybox consists of 6 textures. In Tuxracer");
|
||||
AddComment (liste, "3 textures are invisible (top, bottom and back).");
|
||||
AddComment (liste, "These textures needn't be drawn.");
|
||||
AddComment(liste, "Draw full skybox [0...1]");
|
||||
AddComment(liste, "A normal skybox consists of 6 textures. In Tuxracer");
|
||||
AddComment(liste, "3 textures are invisible (top, bottom and back).");
|
||||
AddComment(liste, "These textures needn't be drawn.");
|
||||
AddItem(liste, "full_skybox", param.full_skybox);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Select the music:");
|
||||
AddComment (liste, "(the racing music is defined by a music theme)");
|
||||
AddItem (liste, "menu_music", param.menu_music);
|
||||
AddItem (liste, "credits_music", param.credits_music);
|
||||
AddItem (liste, "config_music", param.config_music);
|
||||
AddComment(liste, "Select the music:");
|
||||
AddComment(liste, "(the racing music is defined by a music theme)");
|
||||
AddItem(liste, "menu_music", param.menu_music);
|
||||
AddItem(liste, "credits_music", param.credits_music);
|
||||
AddItem(liste, "config_music", param.config_music);
|
||||
liste.AddLine();
|
||||
|
||||
AddComment (liste, "Use sqare root of scale factors for menu screens [0...1]");
|
||||
AddComment (liste, "Exprimental: these factors reduce the effect of screen scaling.");
|
||||
AddComment (liste, "The widgets are closer to their default sizes.");
|
||||
AddComment(liste, "Use sqare root of scale factors for menu screens [0...1]");
|
||||
AddComment(liste, "Exprimental: these factors reduce the effect of screen scaling.");
|
||||
AddComment(liste, "The widgets are closer to their default sizes.");
|
||||
AddItem(liste, "use_quad_scale", param.use_quad_scale);
|
||||
liste.AddLine();
|
||||
|
||||
// ---------------------------------------
|
||||
liste.Save (param.configfile);
|
||||
liste.Save(param.configfile);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void InitConfig () {
|
||||
void InitConfig() {
|
||||
#if defined (OS_WIN32_MINGW) || defined (OS_WIN32_MSC)
|
||||
// the progdir is always the current dir
|
||||
param.config_dir = "config";
|
||||
|
@ -275,12 +275,12 @@ void InitConfig () {
|
|||
#if 0
|
||||
char buff[256];
|
||||
|
||||
if (strcmp (arg0, "./etr") == 0) { // start from work directory
|
||||
char *s = getcwd (buff, 256);
|
||||
if (strcmp(arg0, "./etr") == 0) { // start from work directory
|
||||
char *s = getcwd(buff, 256);
|
||||
if (s==NULL) {};
|
||||
} else { // start with full path
|
||||
strcpy (buff, arg0);
|
||||
if (strlen (buff) > 5) {
|
||||
strcpy(buff, arg0);
|
||||
if (strlen(buff) > 5) {
|
||||
buff[strlen(buff)-3] = 0;
|
||||
}
|
||||
}
|
||||
|
@ -288,13 +288,13 @@ void InitConfig () {
|
|||
param.prog_dir = buff;
|
||||
#endif
|
||||
|
||||
struct passwd *pwent = getpwuid (getuid ());
|
||||
struct passwd *pwent = getpwuid(getuid());
|
||||
param.config_dir = pwent->pw_dir;
|
||||
param.config_dir += SEP;
|
||||
param.config_dir += ".etr";
|
||||
// or: param.config_dir = param.prog_dir + SEP "config";
|
||||
if (!DirExists (param.config_dir.c_str()))
|
||||
mkdir (param.config_dir.c_str(), 0775);
|
||||
if (!DirExists(param.config_dir.c_str()))
|
||||
mkdir(param.config_dir.c_str(), 0775);
|
||||
param.data_dir = ETR_DATA_DIR;
|
||||
param.data_dir += SEP;
|
||||
param.data_dir += "etr";
|
||||
|
@ -322,10 +322,10 @@ void InitConfig () {
|
|||
|
||||
Trans.LoadLanguages();
|
||||
|
||||
if (FileExists (param.configfile)) {
|
||||
LoadConfigFile ();
|
||||
if (FileExists(param.configfile)) {
|
||||
LoadConfigFile();
|
||||
} else {
|
||||
SetConfigDefaults ();
|
||||
SaveConfigFile ();
|
||||
SetConfigDefaults();
|
||||
SaveConfigFile();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,8 +73,8 @@ struct TParam {
|
|||
TViewMode view_mode;
|
||||
};
|
||||
|
||||
void InitConfig ();
|
||||
void SaveConfigFile ();
|
||||
void InitConfig();
|
||||
void SaveConfigFile();
|
||||
|
||||
extern TParam param;
|
||||
|
||||
|
|
|
@ -33,18 +33,18 @@ GNU General Public License for more details.
|
|||
|
||||
CEvents Events;
|
||||
|
||||
bool CEvents::LoadEventList () {
|
||||
bool CEvents::LoadEventList() {
|
||||
CSPList list(256);
|
||||
|
||||
if (!list.Load (param.common_course_dir, "events.lst")) {
|
||||
Message ("could not load events.lst");
|
||||
if (!list.Load(param.common_course_dir, "events.lst")) {
|
||||
Message("could not load events.lst");
|
||||
return false;
|
||||
}
|
||||
|
||||
// pass 1: races
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
int type = SPIntN (line, "struct", -1);
|
||||
int type = SPIntN(line, "struct", -1);
|
||||
if (type == 0) {
|
||||
RaceList.push_back(TRace(
|
||||
Course.GetCourse(SPStrN(line, "course")),
|
||||
|
@ -56,71 +56,71 @@ bool CEvents::LoadEventList () {
|
|||
Music.GetThemeIdx(SPStrN(line, "theme", "normal"))));
|
||||
}
|
||||
}
|
||||
list.MakeIndex (RaceIndex, "race");
|
||||
list.MakeIndex(RaceIndex, "race");
|
||||
|
||||
// pass 2: cups
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
int type = SPIntN (line, "struct", -1);
|
||||
int type = SPIntN(line, "struct", -1);
|
||||
if (type == 1) {
|
||||
CupList.push_back(TCup(
|
||||
SPStrN(line, "cup", errorString),
|
||||
SPStrN(line, "name", "unknown"),
|
||||
SPStrN(line, "desc", "unknown")));
|
||||
int num = SPIntN (line, "num", 0);
|
||||
int num = SPIntN(line, "num", 0);
|
||||
CupList.back().races.resize(num);
|
||||
for (int ii=0; ii<num; ii++) {
|
||||
string race = SPStrN (line, Int_StrN (ii+1));
|
||||
string race = SPStrN(line, Int_StrN(ii+1));
|
||||
CupList.back().races[ii] = &RaceList[GetRaceIdx(race)];
|
||||
}
|
||||
}
|
||||
}
|
||||
list.MakeIndex (CupIndex, "cup");
|
||||
list.MakeIndex(CupIndex, "cup");
|
||||
|
||||
// pass 3: events
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
int type = SPIntN (line, "struct", -1);
|
||||
int type = SPIntN(line, "struct", -1);
|
||||
if (type == 2) {
|
||||
EventList.push_back(TEvent(SPStrN(line, "name", "unknown")));
|
||||
int num = SPIntN (line, "num", 0);
|
||||
int num = SPIntN(line, "num", 0);
|
||||
EventList.back().cups.resize(num);
|
||||
for (int ii=0; ii<num; ii++) {
|
||||
string cup = SPStrN (line, Int_StrN (ii+1));
|
||||
string cup = SPStrN(line, Int_StrN(ii+1));
|
||||
EventList.back().cups[ii] = &CupList[GetCupIdx(cup)];
|
||||
}
|
||||
}
|
||||
}
|
||||
list.MakeIndex (EventIndex, "event");
|
||||
list.MakeIndex(EventIndex, "event");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t CEvents::GetRaceIdx (const string& race) const {
|
||||
size_t CEvents::GetRaceIdx(const string& race) const {
|
||||
return RaceIndex.at(race);
|
||||
}
|
||||
|
||||
size_t CEvents::GetCupIdx (const string& cup) const {
|
||||
size_t CEvents::GetCupIdx(const string& cup) const {
|
||||
return CupIndex.at(cup);
|
||||
}
|
||||
|
||||
size_t CEvents::GetEventIdx (const string& event) const {
|
||||
size_t CEvents::GetEventIdx(const string& event) const {
|
||||
return EventIndex.at(event);
|
||||
}
|
||||
|
||||
const string& CEvents::GetCup (size_t event, size_t cup) const {
|
||||
const string& CEvents::GetCup(size_t event, size_t cup) const {
|
||||
if (event >= EventList.size()) return errorString;
|
||||
if (cup >= EventList[event].cups.size()) return errorString;
|
||||
return EventList[event].cups[cup]->cup;
|
||||
}
|
||||
|
||||
const string& CEvents::GetCupTrivialName (size_t event, size_t cup) const {
|
||||
const string& CEvents::GetCupTrivialName(size_t event, size_t cup) const {
|
||||
if (event >= EventList.size()) return errorString;
|
||||
if (cup >= EventList[event].cups.size()) return errorString;
|
||||
return EventList[event].cups[cup]->name;
|
||||
}
|
||||
|
||||
void CEvents::MakeUnlockList (const string& unlockstr) {
|
||||
void CEvents::MakeUnlockList(const string& unlockstr) {
|
||||
for (size_t event=0; event<EventList.size(); event++) {
|
||||
for (size_t cup=0; cup<EventList[event].cups.size(); cup++) {
|
||||
EventList[event].cups[cup]->Unlocked = false;
|
||||
|
@ -128,8 +128,8 @@ void CEvents::MakeUnlockList (const string& unlockstr) {
|
|||
}
|
||||
for (size_t event=0; event<EventList.size(); event++) {
|
||||
for (size_t cup=0; cup<EventList[event].cups.size(); cup++) {
|
||||
const string& cp = GetCup (event, cup);
|
||||
bool passed = SPosN (unlockstr, cp) != string::npos;
|
||||
const string& cp = GetCup(event, cup);
|
||||
bool passed = SPosN(unlockstr, cp) != string::npos;
|
||||
if (cup < 1) EventList[event].cups[0]->Unlocked = true;
|
||||
if (passed) {
|
||||
EventList[event].cups[cup]->Unlocked = true;
|
||||
|
@ -140,7 +140,7 @@ void CEvents::MakeUnlockList (const string& unlockstr) {
|
|||
}
|
||||
}
|
||||
|
||||
bool CEvents::IsUnlocked (size_t event, size_t cup) const {
|
||||
bool CEvents::IsUnlocked(size_t event, size_t cup) const {
|
||||
if (event >= EventList.size()) return false;
|
||||
if (cup >= EventList[event].cups.size()) return false;
|
||||
return EventList[event].cups[cup]->Unlocked;
|
||||
|
@ -158,26 +158,26 @@ CPlayers::~CPlayers() {
|
|||
delete avatars[i].texture;
|
||||
}
|
||||
|
||||
void CPlayers::AddPlayer (const string& name, const string& avatar) {
|
||||
void CPlayers::AddPlayer(const string& name, const string& avatar) {
|
||||
plyr.push_back(TPlayer(name, FindAvatar(avatar)));
|
||||
}
|
||||
|
||||
void CPlayers::SetDefaultPlayers () {
|
||||
void CPlayers::SetDefaultPlayers() {
|
||||
plyr.push_back(TPlayer("Racer", FindAvatar("avatar01.png")));
|
||||
plyr.push_back(TPlayer("Bunny", FindAvatar("avatar02.png")));
|
||||
}
|
||||
|
||||
bool CPlayers::LoadPlayers () {
|
||||
if (FileExists (param.config_dir, "players") == false) {
|
||||
SetDefaultPlayers ();
|
||||
Message ("file 'players' does not exist, set default players");
|
||||
bool CPlayers::LoadPlayers() {
|
||||
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");
|
||||
if (list.Load(param.config_dir, "players") == false) {
|
||||
SetDefaultPlayers();
|
||||
Message("could not load players list, set default players");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -185,22 +185,22 @@ bool CPlayers::LoadPlayers () {
|
|||
plyr.resize(list.Count());
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
plyr[i].name = SPStrN (line, "name", "unknown");
|
||||
plyr[i].funlocked = SPStrN (line, "unlocked");
|
||||
plyr[i].name = SPStrN(line, "name", "unknown");
|
||||
plyr[i].funlocked = SPStrN(line, "unlocked");
|
||||
plyr[i].avatar = FindAvatar(SPStrN(line, "avatar"));
|
||||
plyr[i].ctrl = NULL;
|
||||
int active = SPIntN (line, "active", 0);
|
||||
int active = SPIntN(line, "active", 0);
|
||||
if (active > 0) g_game.start_player = plyr.size()-1;
|
||||
}
|
||||
if (plyr.empty()) {
|
||||
SetDefaultPlayers ();
|
||||
Message ("player file doesn't contain a player, set default players");
|
||||
SetDefaultPlayers();
|
||||
Message("player file doesn't contain a player, set default players");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPlayers::SavePlayers () const {
|
||||
void CPlayers::SavePlayers() const {
|
||||
string playerfile = param.config_dir + SEP "players";
|
||||
CSPList list(plyr.size());
|
||||
for (size_t i=0; i<plyr.size(); i++) {
|
||||
|
@ -209,9 +209,9 @@ void CPlayers::SavePlayers () const {
|
|||
item += "[unlocked]" + plyr[i].funlocked;
|
||||
if (&plyr[i] == g_game.player) item += "[active]1";
|
||||
else item += "[active]0";
|
||||
list.Add (item);
|
||||
list.Add(item);
|
||||
}
|
||||
list.Save (playerfile);
|
||||
list.Save(playerfile);
|
||||
}
|
||||
|
||||
const TAvatar* CPlayers::FindAvatar(const string& name) {
|
||||
|
@ -221,13 +221,13 @@ const TAvatar* CPlayers::FindAvatar(const string& name) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void CPlayers::AddPassedCup (const string& cup) {
|
||||
if (SPIntN (g_game.player->funlocked, cup, -1) > 0) return;
|
||||
void CPlayers::AddPassedCup(const string& cup) {
|
||||
if (SPIntN(g_game.player->funlocked, cup, -1) > 0) return;
|
||||
g_game.player->funlocked += ' ';
|
||||
g_game.player->funlocked += cup;
|
||||
}
|
||||
|
||||
void CPlayers::ResetControls () {
|
||||
void CPlayers::ResetControls() {
|
||||
for (size_t i=0; i<plyr.size(); i++) {
|
||||
delete plyr[i].ctrl;
|
||||
plyr[i].ctrl = NULL;
|
||||
|
@ -235,7 +235,7 @@ void CPlayers::ResetControls () {
|
|||
}
|
||||
|
||||
// called in module regist.cpp:
|
||||
void CPlayers::AllocControl (size_t player) {
|
||||
void CPlayers::AllocControl(size_t player) {
|
||||
if (player >= plyr.size()) return;
|
||||
if (plyr[player].ctrl != NULL) return;
|
||||
plyr[player].ctrl = new CControl;
|
||||
|
@ -243,17 +243,17 @@ void CPlayers::AllocControl (size_t player) {
|
|||
|
||||
// ----------------------- avatars ------------------------------------
|
||||
|
||||
void CPlayers::LoadAvatars () {
|
||||
CSPList list (MAX_AVATARS);
|
||||
void CPlayers::LoadAvatars() {
|
||||
CSPList list(MAX_AVATARS);
|
||||
|
||||
if (!list.Load (param.player_dir, "avatars.lst")) {
|
||||
Message ("could not load avators.lst");
|
||||
if (!list.Load(param.player_dir, "avatars.lst")) {
|
||||
Message("could not load avators.lst");
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
string filename = SPStrN (line, "file", "unknown");
|
||||
string filename = SPStrN(line, "file", "unknown");
|
||||
TTexture* texture = new TTexture();
|
||||
if (texture && texture->Load(param.player_dir, filename)) {
|
||||
avatars.push_back(TAvatar(filename, texture));
|
||||
|
@ -262,12 +262,12 @@ void CPlayers::LoadAvatars () {
|
|||
}
|
||||
}
|
||||
|
||||
TTexture* CPlayers::GetAvatarTexture (size_t avatar) const {
|
||||
TTexture* CPlayers::GetAvatarTexture(size_t avatar) const {
|
||||
if (avatar >= avatars.size()) return 0;
|
||||
return avatars[avatar].texture;
|
||||
}
|
||||
|
||||
const string& CPlayers::GetDirectAvatarName (size_t avatar) const {
|
||||
const string& CPlayers::GetDirectAvatarName(size_t avatar) const {
|
||||
if (avatar >= avatars.size()) return emptyString;
|
||||
return avatars[avatar].filename;
|
||||
}
|
||||
|
@ -293,48 +293,48 @@ CCharacter::~CCharacter() {
|
|||
}
|
||||
}
|
||||
|
||||
void CCharacter::LoadCharacterList () {
|
||||
CSPList list (MAX_CHARACTERS);
|
||||
void CCharacter::LoadCharacterList() {
|
||||
CSPList list(MAX_CHARACTERS);
|
||||
|
||||
if (!list.Load (param.char_dir, "characters.lst")) {
|
||||
Message ("could not load characters.lst");
|
||||
if (!list.Load(param.char_dir, "characters.lst")) {
|
||||
Message("could not load characters.lst");
|
||||
return;
|
||||
}
|
||||
|
||||
CharList.resize(list.Count());
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
CharList[i].name = SPStrN (line, "name");
|
||||
CharList[i].dir = SPStrN (line, "dir");
|
||||
string typestr = SPStrN (line, "type", "unknown");
|
||||
CharList[i].type = SPIntN (char_type_index, typestr, -1);
|
||||
CharList[i].name = SPStrN(line, "name");
|
||||
CharList[i].dir = SPStrN(line, "dir");
|
||||
string typestr = SPStrN(line, "type", "unknown");
|
||||
CharList[i].type = SPIntN(char_type_index, typestr, -1);
|
||||
|
||||
string charpath = param.char_dir + SEP + CharList[i].dir;
|
||||
if (DirExists (charpath.c_str())) {
|
||||
if (DirExists(charpath.c_str())) {
|
||||
string previewfile = charpath + SEP "preview.png";
|
||||
|
||||
TCharacter* ch = &CharList[i];
|
||||
ch->preview = new TTexture();
|
||||
if (!ch->preview->Load(previewfile, false)) {
|
||||
Message ("could not load previewfile of character");
|
||||
Message("could not load previewfile of character");
|
||||
// texid = Tex.TexID (NO_PREVIEW);
|
||||
}
|
||||
|
||||
|
||||
ch->shape = new CCharShape;
|
||||
if (ch->shape->Load (charpath, "shape.lst", false) == false) {
|
||||
if (ch->shape->Load(charpath, "shape.lst", false) == false) {
|
||||
delete ch->shape;
|
||||
ch->shape = NULL;
|
||||
Message ("could not load character shape");
|
||||
Message("could not load character shape");
|
||||
}
|
||||
|
||||
ch->frames[0].Load (charpath, "start.lst");
|
||||
ch->frames[0].Load(charpath, "start.lst");
|
||||
ch->finishframesok = true;
|
||||
ch->frames[1].Load (charpath, "finish.lst");
|
||||
ch->frames[1].Load(charpath, "finish.lst");
|
||||
if (ch->frames[1].loaded == false) ch->finishframesok = false;
|
||||
ch->frames[2].Load (charpath, "wonrace.lst");
|
||||
ch->frames[2].Load(charpath, "wonrace.lst");
|
||||
if (ch->frames[2].loaded == false) ch->finishframesok = false;
|
||||
ch->frames[3].Load (charpath, "lostrace.lst");
|
||||
ch->frames[3].Load(charpath, "lostrace.lst");
|
||||
if (ch->frames[3].loaded == false) ch->finishframesok = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,15 +78,15 @@ public:
|
|||
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;
|
||||
size_t GetEventIdx (const string& event) const;
|
||||
const string& GetCup (size_t event, size_t cup) const;
|
||||
const string& GetCupTrivialName (size_t event, size_t cup) const;
|
||||
bool LoadEventList();
|
||||
size_t GetRaceIdx(const string& race) const;
|
||||
size_t GetCupIdx(const string& cup) const;
|
||||
size_t GetEventIdx(const string& event) const;
|
||||
const string& GetCup(size_t event, size_t cup) const;
|
||||
const string& GetCupTrivialName(size_t event, size_t cup) const;
|
||||
|
||||
void MakeUnlockList (const string& unlockstr);
|
||||
bool IsUnlocked (size_t event, size_t cup) const;
|
||||
void MakeUnlockList(const string& unlockstr);
|
||||
bool IsUnlocked(size_t event, size_t cup) const;
|
||||
};
|
||||
|
||||
extern CEvents Events;
|
||||
|
@ -121,7 +121,7 @@ struct TPlayer {
|
|||
class CPlayers {
|
||||
private:
|
||||
vector<TPlayer> plyr;
|
||||
void SetDefaultPlayers ();
|
||||
void SetDefaultPlayers();
|
||||
vector<TAvatar> avatars;
|
||||
|
||||
const TAvatar* FindAvatar(const string& name);
|
||||
|
@ -129,17 +129,17 @@ public:
|
|||
~CPlayers();
|
||||
|
||||
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;
|
||||
void ResetControls ();
|
||||
void AllocControl (size_t player);
|
||||
void LoadAvatars ();
|
||||
void AddPassedCup(const string& cup);
|
||||
void AddPlayer(const string& name, const string& avatar);
|
||||
bool LoadPlayers();
|
||||
void SavePlayers() const;
|
||||
void ResetControls();
|
||||
void AllocControl(size_t player);
|
||||
void LoadAvatars();
|
||||
size_t numAvatars() const { return avatars.size(); }
|
||||
size_t numPlayers() const { return plyr.size(); }
|
||||
|
||||
TTexture* GetAvatarTexture (size_t avatar) const;
|
||||
TTexture* GetAvatarTexture(size_t avatar) const;
|
||||
const string& GetDirectAvatarName(size_t avatar) const;
|
||||
};
|
||||
|
||||
|
@ -166,8 +166,8 @@ public:
|
|||
|
||||
~CCharacter();
|
||||
|
||||
void LoadCharacterList ();
|
||||
void FreeCharacterPreviews ();
|
||||
void LoadCharacterList();
|
||||
void FreeCharacterPreviews();
|
||||
};
|
||||
|
||||
extern CCharacter Char;
|
||||
|
|
|
@ -45,25 +45,25 @@ CGameOver GameOver;
|
|||
static CKeyframe *final_frame;
|
||||
static int highscore_pos = MAX_SCORES;
|
||||
|
||||
void QuitGameOver () {
|
||||
void QuitGameOver() {
|
||||
if (g_game.game_type == PRACTICING) {
|
||||
State::manager.RequestEnterState (RaceSelect);
|
||||
State::manager.RequestEnterState(RaceSelect);
|
||||
} else {
|
||||
State::manager.RequestEnterState (Event);
|
||||
State::manager.RequestEnterState(Event);
|
||||
}
|
||||
}
|
||||
|
||||
void CGameOver::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CGameOver::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
if (key == 13 || key == sf::Keyboard::Escape) QuitGameOver ();
|
||||
if (key == 13 || key == sf::Keyboard::Escape) QuitGameOver();
|
||||
}
|
||||
|
||||
void CGameOver::Mouse (int button, int state, int x, int y) {
|
||||
QuitGameOver ();
|
||||
void CGameOver::Mouse(int button, int state, int x, int y) {
|
||||
QuitGameOver();
|
||||
}
|
||||
|
||||
|
||||
void GameOverMessage (const CControl *ctrl) {
|
||||
void GameOverMessage(const CControl *ctrl) {
|
||||
int fwidth = 500;
|
||||
|
||||
int leftframe = (Winsys.resolution.width - fwidth) / 2;
|
||||
|
@ -72,71 +72,71 @@ void GameOverMessage (const CControl *ctrl) {
|
|||
const sf::Color& backcol = colWhite;
|
||||
static const sf::Color framecol(0.7*255, 0.7*255, 1*255);
|
||||
|
||||
if (param.use_papercut_font > 0) FT.SetSize (28);
|
||||
else FT.SetSize (22);
|
||||
if (param.use_papercut_font > 0) FT.SetSize(28);
|
||||
else FT.SetSize(22);
|
||||
if (g_game.raceaborted) {
|
||||
DrawFrameX (leftframe, topframe, fwidth, 100, 4, backcol, framecol, 0.5);
|
||||
FT.SetColor (colDBlue);
|
||||
FT.DrawString (CENTER, topframe+30, Trans.Text(25));
|
||||
DrawFrameX(leftframe, topframe, fwidth, 100, 4, backcol, framecol, 0.5);
|
||||
FT.SetColor(colDBlue);
|
||||
FT.DrawString(CENTER, topframe+30, Trans.Text(25));
|
||||
} else {
|
||||
int firstMarker = leftframe + 60;
|
||||
int secondMarker = leftframe + 310;
|
||||
DrawFrameX(leftframe, topframe, fwidth, 210, 4, backcol, framecol, 0.5);
|
||||
|
||||
if (param.use_papercut_font > 0) FT.SetSize (20);
|
||||
else FT.SetSize (14);
|
||||
if (g_game.race_result >= 0 || g_game.game_type != CUPRACING) FT.SetColor (colDBlue);
|
||||
else FT.SetColor (colDRed);
|
||||
if (param.use_papercut_font > 0) FT.SetSize(20);
|
||||
else FT.SetSize(14);
|
||||
if (g_game.race_result >= 0 || g_game.game_type != CUPRACING) FT.SetColor(colDBlue);
|
||||
else FT.SetColor(colDRed);
|
||||
|
||||
string line = Trans.Text(84) + ": ";
|
||||
FT.DrawString(firstMarker, topframe + 15, line);
|
||||
line = Int_StrN (g_game.score);
|
||||
line = Int_StrN(g_game.score);
|
||||
line += " pts";
|
||||
FT.DrawString(secondMarker, topframe + 15, line);
|
||||
|
||||
line = Trans.Text(85) + ": ";
|
||||
FT.DrawString(firstMarker, topframe + 40, line);
|
||||
line = Int_StrN (g_game.herring);
|
||||
line = Int_StrN(g_game.herring);
|
||||
if (g_game.game_type == CUPRACING) {
|
||||
line += " (";
|
||||
line += Int_StrN (g_game.race->herrings.x);
|
||||
line += Int_StrN(g_game.race->herrings.x);
|
||||
line += ')';
|
||||
}
|
||||
FT.DrawString(secondMarker, topframe + 40, line);
|
||||
|
||||
line = Trans.Text(86) + ": ";
|
||||
FT.DrawString(firstMarker, topframe + 65, line);
|
||||
line = Float_StrN (g_game.time, 2);
|
||||
line = Float_StrN(g_game.time, 2);
|
||||
line += " s";
|
||||
if (g_game.game_type == CUPRACING) {
|
||||
line += " (";
|
||||
line += Float_StrN (g_game.race->time.x, 2);
|
||||
line += Float_StrN(g_game.race->time.x, 2);
|
||||
line += ')';
|
||||
}
|
||||
FT.DrawString(secondMarker, topframe + 65, line);
|
||||
|
||||
line = Trans.Text(87) + ": ";
|
||||
FT.DrawString(firstMarker, topframe + 90, line);
|
||||
line = Float_StrN (ctrl->way, 2);
|
||||
line = Float_StrN(ctrl->way, 2);
|
||||
line += " m";
|
||||
FT.DrawString(secondMarker, topframe + 90, line);
|
||||
|
||||
line = Trans.Text(88) + ": ";
|
||||
FT.DrawString(firstMarker, topframe + 115, line);
|
||||
line = Float_StrN (ctrl->way / g_game.time * 3.6, 2);
|
||||
line = Float_StrN(ctrl->way / g_game.time * 3.6, 2);
|
||||
line += " km/h";
|
||||
FT.DrawString(secondMarker, topframe + 115, line);
|
||||
|
||||
if (param.use_papercut_font > 0) FT.SetSize (28);
|
||||
else FT.SetSize (22);
|
||||
if (param.use_papercut_font > 0) FT.SetSize(28);
|
||||
else FT.SetSize(22);
|
||||
if (g_game.game_type == CUPRACING) {
|
||||
FT.DrawString(CENTER, topframe + 150, Trans.Text(22 + g_game.race_result)); // Text IDs 21 - 24; race_results is in [-1; 2]
|
||||
} else {
|
||||
if (highscore_pos < MAX_SCORES) {
|
||||
line = Trans.Text(89) + ' ';
|
||||
line += Int_StrN (highscore_pos + 1);
|
||||
line += Int_StrN(highscore_pos + 1);
|
||||
line += ' ' + Trans.Text(90);
|
||||
FT.DrawString (CENTER, topframe+150, line);
|
||||
FT.DrawString(CENTER, topframe+150, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,19 +144,19 @@ void GameOverMessage (const CControl *ctrl) {
|
|||
|
||||
// =========================================================================
|
||||
void CGameOver::Enter() {
|
||||
if (!g_game.raceaborted) highscore_pos = Score.CalcRaceResult ();
|
||||
if (!g_game.raceaborted) highscore_pos = Score.CalcRaceResult();
|
||||
|
||||
if (g_game.game_type == CUPRACING) {
|
||||
if (g_game.race_result >= 0) {
|
||||
Music.PlayTheme (g_game.theme_id, MUS_WONRACE);
|
||||
Music.PlayTheme(g_game.theme_id, MUS_WONRACE);
|
||||
} else {
|
||||
Music.PlayTheme (g_game.theme_id, MUS_LOSTRACE);
|
||||
Music.PlayTheme(g_game.theme_id, MUS_LOSTRACE);
|
||||
}
|
||||
} else {
|
||||
if (g_game.raceaborted) {
|
||||
Music.PlayTheme (g_game.theme_id, MUS_LOSTRACE);
|
||||
Music.PlayTheme(g_game.theme_id, MUS_LOSTRACE);
|
||||
} else {
|
||||
Music.PlayTheme (g_game.theme_id, MUS_WONRACE);
|
||||
Music.PlayTheme(g_game.theme_id, MUS_WONRACE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,10 +172,10 @@ void CGameOver::Enter() {
|
|||
|
||||
if (!g_game.raceaborted) {
|
||||
const CControl *ctrl = g_game.player->ctrl;
|
||||
final_frame->Init (ctrl->cpos, -0.18);
|
||||
final_frame->Init(ctrl->cpos, -0.18);
|
||||
}
|
||||
}
|
||||
SetStationaryCamera (true);
|
||||
SetStationaryCamera(true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -184,25 +184,25 @@ void CGameOver::Loop(double time_step) {
|
|||
int width = Winsys.resolution.width;
|
||||
int height = Winsys.resolution.height;
|
||||
|
||||
ClearRenderContext ();
|
||||
Env.SetupFog ();
|
||||
ClearRenderContext();
|
||||
Env.SetupFog();
|
||||
|
||||
update_view (ctrl, 0);
|
||||
update_view(ctrl, 0);
|
||||
|
||||
if (final_frame != NULL) final_frame->Update (time_step);
|
||||
if (final_frame != NULL) final_frame->Update(time_step);
|
||||
|
||||
SetupViewFrustum (ctrl);
|
||||
Env.DrawSkybox (ctrl->viewpos);
|
||||
Env.DrawFog ();
|
||||
Env.SetupLight ();
|
||||
SetupViewFrustum(ctrl);
|
||||
Env.DrawSkybox(ctrl->viewpos);
|
||||
Env.DrawFog();
|
||||
Env.SetupLight();
|
||||
|
||||
RenderCourse ();
|
||||
DrawTrackmarks ();
|
||||
DrawTrees ();
|
||||
RenderCourse();
|
||||
DrawTrackmarks();
|
||||
DrawTrees();
|
||||
|
||||
UpdateWind (time_step);
|
||||
UpdateSnow (time_step, ctrl);
|
||||
DrawSnow (ctrl);
|
||||
UpdateWind(time_step);
|
||||
UpdateSnow(time_step, ctrl);
|
||||
DrawSnow(ctrl);
|
||||
|
||||
g_game.character->shape->Draw();
|
||||
|
||||
|
@ -212,7 +212,7 @@ void CGameOver::Loop(double time_step) {
|
|||
if (!final_frame->active) GameOverMessage(ctrl);
|
||||
} else GameOverMessage(ctrl);
|
||||
}
|
||||
DrawHud (ctrl);
|
||||
Reshape (width, height);
|
||||
Winsys.SwapBuffers ();
|
||||
DrawHud(ctrl);
|
||||
Reshape(width, height);
|
||||
Winsys.SwapBuffers();
|
||||
}
|
||||
|
|
|
@ -40,36 +40,36 @@ CGameTypeSelect GameTypeSelect;
|
|||
static TTextButton* textbuttons[7];
|
||||
static sf::Sprite logo;
|
||||
|
||||
void EnterPractice () {
|
||||
void EnterPractice() {
|
||||
g_game.game_type = PRACTICING;
|
||||
State::manager.RequestEnterState (RaceSelect);
|
||||
State::manager.RequestEnterState(RaceSelect);
|
||||
}
|
||||
|
||||
void QuitGameType () {
|
||||
void QuitGameType() {
|
||||
if (textbuttons[0]->focussed())
|
||||
State::manager.RequestEnterState (EventSelect);
|
||||
State::manager.RequestEnterState(EventSelect);
|
||||
if (textbuttons[1]->focussed())
|
||||
EnterPractice ();
|
||||
EnterPractice();
|
||||
if (textbuttons[2]->focussed())
|
||||
State::manager.RequestEnterState (GameConfig);
|
||||
State::manager.RequestEnterState(GameConfig);
|
||||
if (textbuttons[3]->focussed())
|
||||
State::manager.RequestEnterState (Score);
|
||||
State::manager.RequestEnterState(Score);
|
||||
if (textbuttons[4]->focussed())
|
||||
State::manager.RequestEnterState (Help);
|
||||
State::manager.RequestEnterState(Help);
|
||||
if (textbuttons[5]->focussed())
|
||||
State::manager.RequestEnterState (Credits);
|
||||
State::manager.RequestEnterState(Credits);
|
||||
if (textbuttons[6]->focussed())
|
||||
State::manager.RequestQuit();
|
||||
}
|
||||
|
||||
void CGameTypeSelect::Mouse (int button, int state, int x, int y) {
|
||||
void CGameTypeSelect::Mouse(int button, int state, int x, int y) {
|
||||
if (state == 1) {
|
||||
ClickGUI(x, y);
|
||||
QuitGameType();
|
||||
}
|
||||
}
|
||||
|
||||
void CGameTypeSelect::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CGameTypeSelect::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
|
||||
KeyGUI(key, 0, release);
|
||||
|
@ -92,27 +92,27 @@ void CGameTypeSelect::Keyb (sf::Keyboard::Key key, bool special, bool release, i
|
|||
}
|
||||
}
|
||||
|
||||
void CGameTypeSelect::Motion (int x, int y) {
|
||||
void CGameTypeSelect::Motion(int x, int y) {
|
||||
MouseMoveGUI(x, y);
|
||||
|
||||
if (param.ui_snow) push_ui_snow (cursor_pos);
|
||||
if (param.ui_snow) push_ui_snow(cursor_pos);
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
void CGameTypeSelect::Enter () {
|
||||
Winsys.ShowCursor (!param.ice_cursor);
|
||||
void CGameTypeSelect::Enter() {
|
||||
Winsys.ShowCursor(!param.ice_cursor);
|
||||
|
||||
ResetGUI ();
|
||||
int top = AutoYPosN (40);
|
||||
int siz = FT.AutoSizeN (6);
|
||||
int dist = FT.AutoDistanceN (2);
|
||||
textbuttons[0] = AddTextButton (Trans.Text(1), CENTER, top, siz);
|
||||
textbuttons[1] = AddTextButton (Trans.Text(2), CENTER, top + dist, siz);
|
||||
textbuttons[2] = AddTextButton (Trans.Text(3), CENTER, top + dist * 2, siz);
|
||||
textbuttons[3] = AddTextButton (Trans.Text(62), CENTER, top + dist * 3, siz);
|
||||
textbuttons[4] = AddTextButton (Trans.Text(43), CENTER, top + dist * 4, siz);
|
||||
textbuttons[5] = AddTextButton (Trans.Text(4), CENTER, top + dist * 5, siz);
|
||||
ResetGUI();
|
||||
int top = AutoYPosN(40);
|
||||
int siz = FT.AutoSizeN(6);
|
||||
int dist = FT.AutoDistanceN(2);
|
||||
textbuttons[0] = AddTextButton(Trans.Text(1), CENTER, top, siz);
|
||||
textbuttons[1] = AddTextButton(Trans.Text(2), CENTER, top + dist, siz);
|
||||
textbuttons[2] = AddTextButton(Trans.Text(3), CENTER, top + dist * 2, siz);
|
||||
textbuttons[3] = AddTextButton(Trans.Text(62), CENTER, top + dist * 3, siz);
|
||||
textbuttons[4] = AddTextButton(Trans.Text(43), CENTER, top + dist * 4, siz);
|
||||
textbuttons[5] = AddTextButton(Trans.Text(4), CENTER, top + dist * 5, siz);
|
||||
textbuttons[6] = AddTextButton(Trans.Text(5), CENTER, top + dist * 6, siz);
|
||||
logo.setTexture(Tex.GetSFTexture(T_TITLE));
|
||||
logo.setScale(Winsys.scale, Winsys.scale);
|
||||
|
@ -121,12 +121,12 @@ void CGameTypeSelect::Enter () {
|
|||
Music.Play(param.menu_music, true);
|
||||
}
|
||||
|
||||
void CGameTypeSelect::Loop (double time_step) {
|
||||
void CGameTypeSelect::Loop(double time_step) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow (time_step);
|
||||
update_ui_snow(time_step);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
|
@ -134,5 +134,5 @@ void CGameTypeSelect::Loop (double time_step) {
|
|||
DrawGUIFrame();
|
||||
DrawGUI();
|
||||
|
||||
Winsys.SwapBuffers ();
|
||||
Winsys.SwapBuffers();
|
||||
}
|
||||
|
|
39
src/gui.cpp
39
src/gui.cpp
|
@ -45,7 +45,7 @@ static TWidget* AddWidget(TWidget* widget) {
|
|||
return widget;
|
||||
}
|
||||
|
||||
static bool Inside (int x, int y, const TRect& Rect) {
|
||||
static bool Inside(int x, int y, const TRect& Rect) {
|
||||
return (x >= Rect.left
|
||||
&& x <= Rect.left + Rect.width
|
||||
&& y >= Rect.top
|
||||
|
@ -182,8 +182,8 @@ TTextButton* AddTextButton(const sf::String& text, int x, int y, float ftsize) {
|
|||
}
|
||||
|
||||
TTextButton* AddTextButtonN(const sf::String& text, int x, int y, int rel_ftsize) {
|
||||
double siz = FT.AutoSizeN (rel_ftsize);
|
||||
return AddTextButton (text, x, y, siz);
|
||||
double siz = FT.AutoSizeN(rel_ftsize);
|
||||
return AddTextButton(text, x, y, siz);
|
||||
}
|
||||
|
||||
|
||||
|
@ -200,10 +200,10 @@ TTextField::TTextField(int x, int y, int width, int height, const sf::String& te
|
|||
|
||||
void TTextField::Draw() const {
|
||||
const sf::Color& col = focus ? colDYell : colWhite;
|
||||
FT.SetColor (col);
|
||||
DrawFrameX (mouseRect.left, mouseRect.top, mouseRect.width, mouseRect.height, 3, colMBackgr, col, 1.0);
|
||||
FT.AutoSizeN (5);
|
||||
FT.DrawString (mouseRect.left+20, mouseRect.top, text);
|
||||
FT.SetColor(col);
|
||||
DrawFrameX(mouseRect.left, mouseRect.top, mouseRect.width, mouseRect.height, 3, colMBackgr, col, 1.0);
|
||||
FT.AutoSizeN(5);
|
||||
FT.DrawString(mouseRect.left+20, mouseRect.top, text);
|
||||
|
||||
if (cursor && focus) {
|
||||
Winsys.draw(cursorShape);
|
||||
|
@ -234,7 +234,7 @@ void TTextField::SetCursorPos(size_t new_pos) {
|
|||
void TTextField::Key(sf::Keyboard::Key key, unsigned int mod, bool released) {
|
||||
switch (key) {
|
||||
case sf::Keyboard::Delete:
|
||||
if (cursorPos < text.getSize()) text.erase (cursorPos, 1);
|
||||
if (cursorPos < text.getSize()) text.erase(cursorPos, 1);
|
||||
break;
|
||||
case sf::Keyboard::BackSpace:
|
||||
if (cursorPos > 0) { text.erase(cursorPos - 1, 1); SetCursorPos(cursorPos - 1); }
|
||||
|
@ -330,7 +330,7 @@ TIconButton::TIconButton(int x, int y, const sf::Texture& texture, double size_,
|
|||
SetValue(value_);
|
||||
}
|
||||
|
||||
void TIconButton::SetValue (int _value) {
|
||||
void TIconButton::SetValue(int _value) {
|
||||
value = _value;
|
||||
if (value > maximum)
|
||||
value = 0;
|
||||
|
@ -354,15 +354,15 @@ void TIconButton::SetValue (int _value) {
|
|||
}
|
||||
}
|
||||
|
||||
void TIconButton::Draw () const {
|
||||
void TIconButton::Draw() const {
|
||||
sf::Color framecol = colWhite;
|
||||
if (focus) framecol = colDYell;
|
||||
|
||||
int line = 3;
|
||||
int framesize = size + 2 * line;
|
||||
|
||||
DrawFrameX (position.x-line, position.y-line,
|
||||
framesize, framesize, line, colBlack, framecol, 1.0);
|
||||
DrawFrameX(position.x-line, position.y-line,
|
||||
framesize, framesize, line, colBlack, framecol, 1.0);
|
||||
|
||||
Winsys.draw(sprite);
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ void DrawFrameX(int x, int y, int w, int h, int line, const sf::Color& backcol,
|
|||
Winsys.draw(shape);
|
||||
}
|
||||
|
||||
void DrawBonusExt (int y, size_t numraces, size_t num) {
|
||||
void DrawBonusExt(int y, size_t numraces, size_t num) {
|
||||
size_t maxtux = numraces * 3;
|
||||
if (num > maxtux) return;
|
||||
|
||||
|
@ -705,8 +705,7 @@ void SetFocus(TWidget* widget) {
|
|||
Widgets[i]->Focussed();
|
||||
focussed = i;
|
||||
break;
|
||||
}
|
||||
else if (Widgets[i]->focus) {
|
||||
} else if (Widgets[i]->focus) {
|
||||
Widgets[i]->focus = false;
|
||||
Widgets[i]->Focussed();
|
||||
}
|
||||
|
@ -768,7 +767,7 @@ void DecreaseFocus() {
|
|||
lock_focussed = focussed;
|
||||
}
|
||||
|
||||
void ResetGUI () {
|
||||
void ResetGUI() {
|
||||
for (size_t i = 0; i < Widgets.size(); i++)
|
||||
delete Widgets[i];
|
||||
Widgets.clear();
|
||||
|
@ -779,16 +778,16 @@ void ResetGUI () {
|
|||
|
||||
// ------------------ new ---------------------------------------------
|
||||
|
||||
int AutoYPosN (double percent) {
|
||||
int AutoYPosN(double percent) {
|
||||
double hh = (double)Winsys.resolution.height;
|
||||
double po = hh * percent / 100;
|
||||
return (int)(po);
|
||||
}
|
||||
|
||||
TArea AutoAreaN (double top_perc, double bott_perc, int w) {
|
||||
TArea AutoAreaN(double top_perc, double bott_perc, int w) {
|
||||
TArea res;
|
||||
res.top = AutoYPosN (top_perc);
|
||||
res.bottom = AutoYPosN (bott_perc);
|
||||
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;
|
||||
|
|
12
src/gui.h
12
src/gui.h
|
@ -101,7 +101,7 @@ TTextButton* AddTextButton(const sf::String& text, int x, int y, float ftsize);
|
|||
TTextButton* AddTextButtonN(const sf::String& text, int x, int y, int rel_ftsize);
|
||||
|
||||
class TTextField : public TWidget {
|
||||
sf::String text;
|
||||
sf::String text;
|
||||
sf::RectangleShape cursorShape;
|
||||
size_t cursorPos;
|
||||
size_t maxLng;
|
||||
|
@ -195,16 +195,16 @@ void ResetGUI();
|
|||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void DrawFrameX (int x, int y, int w, int h, int line,
|
||||
const sf::Color& backcol, const sf::Color& framecol, double transp);
|
||||
void DrawBonusExt (int y, size_t numraces, size_t num);
|
||||
void DrawFrameX(int x, int y, int w, int h, int line,
|
||||
const sf::Color& backcol, const sf::Color& framecol, double transp);
|
||||
void DrawBonusExt(int y, size_t numraces, size_t num);
|
||||
void DrawGUIBackground(float scale);
|
||||
void DrawGUIFrame();
|
||||
void DrawCursor();
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
int AutoYPosN (double percent);
|
||||
TArea AutoAreaN (double top_perc, double bott_perc, int w);
|
||||
int AutoYPosN(double percent);
|
||||
TArea AutoAreaN(double top_perc, double bott_perc, int w);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -44,12 +44,12 @@ void CHelp::Mouse(int button, int state, int x, int y) {
|
|||
}
|
||||
|
||||
void CHelp::Motion(int x, int y) {
|
||||
if (param.ui_snow) push_ui_snow (cursor_pos);
|
||||
if (param.ui_snow) push_ui_snow(cursor_pos);
|
||||
}
|
||||
|
||||
void CHelp::Enter() {
|
||||
ResetGUI();
|
||||
Winsys.ShowCursor (false);
|
||||
Winsys.ShowCursor(false);
|
||||
Music.Play(param.credits_music, true);
|
||||
|
||||
int ytop = AutoYPosN(15);
|
||||
|
@ -72,7 +72,7 @@ void CHelp::Loop(double timestep) {
|
|||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow (timestep);
|
||||
update_ui_snow(timestep);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
|
|
138
src/hud.cpp
138
src/hud.cpp
|
@ -53,27 +53,27 @@ static const GLfloat speedbar_background_color[] = { 0.2, 0.2, 0.2, 0.0 };
|
|||
static const GLfloat hud_white[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||
|
||||
static void draw_time() {
|
||||
Tex.Draw (T_TIME, 10, 10, 1);
|
||||
Tex.Draw(T_TIME, 10, 10, 1);
|
||||
|
||||
int min, sec, hundr;
|
||||
GetTimeComponents (g_game.time, &min, &sec, &hundr);
|
||||
string timestr = Int_StrN (min, 2);
|
||||
string secstr = Int_StrN (sec, 2);
|
||||
string hundrstr = Int_StrN (hundr, 2);
|
||||
GetTimeComponents(g_game.time, &min, &sec, &hundr);
|
||||
string timestr = Int_StrN(min, 2);
|
||||
string secstr = Int_StrN(sec, 2);
|
||||
string hundrstr = Int_StrN(hundr, 2);
|
||||
|
||||
timestr += ':';
|
||||
timestr += secstr;
|
||||
|
||||
if (param.use_papercut_font < 2) {
|
||||
Tex.DrawNumStr(timestr, 50, 12, 1, colWhite);
|
||||
Tex.DrawNumStr (hundrstr, 170, 12, 0.7, colWhite);
|
||||
Tex.DrawNumStr(hundrstr, 170, 12, 0.7, colWhite);
|
||||
} else {
|
||||
Winsys.beginSFML();
|
||||
FT.SetColor (colDYell);
|
||||
FT.SetSize (30);
|
||||
FT.DrawString (138, 3, hundrstr);
|
||||
FT.SetSize (42);
|
||||
FT.DrawString (53, 3, timestr);
|
||||
FT.SetColor(colDYell);
|
||||
FT.SetSize(30);
|
||||
FT.DrawString(138, 3, hundrstr);
|
||||
FT.SetSize(42);
|
||||
FT.DrawString(53, 3, timestr);
|
||||
Winsys.endSFML();
|
||||
}
|
||||
}
|
||||
|
@ -81,25 +81,25 @@ static void draw_time() {
|
|||
static void draw_herring_count(int herring_count) {
|
||||
Tex.Draw(HERRING_ICON, Winsys.resolution.width - 59, 12, 1);
|
||||
|
||||
string hcountstr = Int_StrN (herring_count, 3);
|
||||
string hcountstr = Int_StrN(herring_count, 3);
|
||||
if (param.use_papercut_font < 2) {
|
||||
Tex.DrawNumStr(hcountstr, Winsys.resolution.width - 130, 12, 1, colWhite);
|
||||
} else {
|
||||
Winsys.beginSFML();
|
||||
FT.SetColor (colDYell);
|
||||
FT.SetColor(colDYell);
|
||||
FT.DrawString(Winsys.resolution.width - 125, 3, hcountstr);
|
||||
Winsys.endSFML();
|
||||
}
|
||||
}
|
||||
|
||||
TVector2d calc_new_fan_pt (double angle) {
|
||||
TVector2d calc_new_fan_pt(double angle) {
|
||||
TVector2d pt;
|
||||
pt.x = ENERGY_GAUGE_CENTER_X + cos (ANGLES_TO_RADIANS (angle)) * SPEEDBAR_OUTER_RADIUS;
|
||||
pt.y = ENERGY_GAUGE_CENTER_Y + sin (ANGLES_TO_RADIANS (angle)) * SPEEDBAR_OUTER_RADIUS;
|
||||
pt.x = ENERGY_GAUGE_CENTER_X + cos(ANGLES_TO_RADIANS(angle)) * SPEEDBAR_OUTER_RADIUS;
|
||||
pt.y = ENERGY_GAUGE_CENTER_Y + sin(ANGLES_TO_RADIANS(angle)) * SPEEDBAR_OUTER_RADIUS;
|
||||
return pt;
|
||||
}
|
||||
|
||||
void draw_partial_tri_fan (double fraction) {
|
||||
void draw_partial_tri_fan(double fraction) {
|
||||
double angle = SPEEDBAR_BASE_ANGLE +
|
||||
(SPEEDBAR_MAX_ANGLE - SPEEDBAR_BASE_ANGLE) * fraction;
|
||||
|
||||
|
@ -112,37 +112,37 @@ void draw_partial_tri_fan (double fraction) {
|
|||
ENERGY_GAUGE_CENTER_Y);
|
||||
|
||||
for (int i=0; i<divs; i++) {
|
||||
TVector2d pt = calc_new_fan_pt (cur_angle);
|
||||
glVertex2f (pt.x, pt.y);
|
||||
TVector2d pt = calc_new_fan_pt(cur_angle);
|
||||
glVertex2f(pt.x, pt.y);
|
||||
cur_angle -= angle_incr;
|
||||
}
|
||||
|
||||
if (cur_angle+angle_incr > angle + EPS) {
|
||||
cur_angle = angle;
|
||||
TVector2d pt = calc_new_fan_pt (cur_angle);
|
||||
glVertex2f (pt.x, pt.y);
|
||||
TVector2d pt = calc_new_fan_pt(cur_angle);
|
||||
glVertex2f(pt.x, pt.y);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void draw_gauge (double speed, double energy) {
|
||||
void draw_gauge(double speed, double energy) {
|
||||
static const GLfloat xplane[4] = {1.0 / GAUGE_IMG_SIZE, 0.0, 0.0, 0.0 };
|
||||
static const GLfloat yplane[4] = {0.0, 1.0 / GAUGE_IMG_SIZE, 0.0, 0.0 };
|
||||
|
||||
ScopedRenderMode rm(GAUGE_BARS);
|
||||
|
||||
if (Tex.GetTexture (GAUGE_ENERGY) == NULL) return;
|
||||
if (Tex.GetTexture (GAUGE_SPEED) == NULL) return;
|
||||
if (Tex.GetTexture (GAUGE_OUTLINE) == NULL) return;
|
||||
if (Tex.GetTexture(GAUGE_ENERGY) == NULL) return;
|
||||
if (Tex.GetTexture(GAUGE_SPEED) == NULL) return;
|
||||
if (Tex.GetTexture(GAUGE_OUTLINE) == NULL) return;
|
||||
|
||||
Tex.BindTex (GAUGE_ENERGY);
|
||||
glTexGenfv (GL_S, GL_OBJECT_PLANE, xplane);
|
||||
glTexGenfv (GL_T, GL_OBJECT_PLANE, yplane);
|
||||
Tex.BindTex(GAUGE_ENERGY);
|
||||
glTexGenfv(GL_S, GL_OBJECT_PLANE, xplane);
|
||||
glTexGenfv(GL_T, GL_OBJECT_PLANE, yplane);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef (Winsys.resolution.width - GAUGE_WIDTH, 0, 0);
|
||||
Tex.BindTex (GAUGE_ENERGY);
|
||||
glTranslatef(Winsys.resolution.width - GAUGE_WIDTH, 0, 0);
|
||||
Tex.BindTex(GAUGE_ENERGY);
|
||||
double y = ENERGY_GAUGE_BOTTOM + energy * ENERGY_GAUGE_HEIGHT;
|
||||
|
||||
const GLfloat vtx1 [] = {
|
||||
|
@ -190,13 +190,13 @@ void draw_gauge (double speed, double energy) {
|
|||
speedbar_frac += speed/SPEEDBAR_GREEN_MAX_SPEED * SPEEDBAR_GREEN_FRACTION;
|
||||
}
|
||||
|
||||
glColor4fv (speedbar_background_color);
|
||||
Tex.BindTex (GAUGE_SPEED);
|
||||
draw_partial_tri_fan (1.0);
|
||||
glColor4fv (hud_white);
|
||||
draw_partial_tri_fan (min (1.0, speedbar_frac));
|
||||
glColor4fv(speedbar_background_color);
|
||||
Tex.BindTex(GAUGE_SPEED);
|
||||
draw_partial_tri_fan(1.0);
|
||||
glColor4fv(hud_white);
|
||||
draw_partial_tri_fan(min(1.0, speedbar_frac));
|
||||
|
||||
glColor4fv (hud_white);
|
||||
glColor4fv(hud_white);
|
||||
Tex.BindTex(GAUGE_OUTLINE);
|
||||
static const GLshort vtx3 [] = {
|
||||
0, 0,
|
||||
|
@ -213,14 +213,14 @@ void draw_gauge (double speed, double energy) {
|
|||
glPopMatrix();
|
||||
}
|
||||
|
||||
void DrawSpeed (double speed) {
|
||||
string speedstr = Int_StrN ((int)speed, 3);
|
||||
void DrawSpeed(double speed) {
|
||||
string speedstr = Int_StrN((int)speed, 3);
|
||||
if (param.use_papercut_font < 2) {
|
||||
Tex.DrawNumStr (speedstr,
|
||||
Winsys.resolution.width - 87, Winsys.resolution.height-73, 1, colWhite);
|
||||
Tex.DrawNumStr(speedstr,
|
||||
Winsys.resolution.width - 87, Winsys.resolution.height-73, 1, colWhite);
|
||||
} else {
|
||||
Winsys.beginSFML();
|
||||
FT.SetColor (colDDYell);
|
||||
FT.SetColor(colDDYell);
|
||||
FT.DrawString(Winsys.resolution.width - 82, Winsys.resolution.height - 80, speedstr);
|
||||
Winsys.endSFML();
|
||||
}
|
||||
|
@ -232,8 +232,8 @@ void DrawWind(float dir, float speed, const CControl *ctrl) {
|
|||
static const int texHeight = Tex.GetSFTexture(SPEEDMETER).getSize().y;
|
||||
static const int texWidth = Tex.GetSFTexture(SPEEDMETER).getSize().x;
|
||||
|
||||
Tex.Draw (SPEEDMETER, 5, Winsys.resolution.height-5-texHeight, 1.0);
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
Tex.Draw(SPEEDMETER, 5, Winsys.resolution.height-5-texHeight, 1.0);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
|
||||
float alpha, red, blue;
|
||||
|
@ -246,8 +246,8 @@ void DrawWind(float dir, float speed, const CControl *ctrl) {
|
|||
}
|
||||
blue = 1.0 - red;
|
||||
|
||||
glPushMatrix ();
|
||||
glColor4f (red, 0, blue, alpha);
|
||||
glPushMatrix();
|
||||
glColor4f(red, 0, blue, alpha);
|
||||
glTranslatef(5 + texWidth / 2, 5 + texHeight / 2, 0);
|
||||
glRotatef(dir, 0, 0, 1);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
@ -264,8 +264,8 @@ void DrawWind(float dir, float speed, const CControl *ctrl) {
|
|||
// direction indicator
|
||||
float dir_angle = RADIANS_TO_ANGLES(atan2(ctrl->cvel.x, ctrl->cvel.z));
|
||||
|
||||
glColor4f (0, 0.5, 0, 1.0);
|
||||
glRotatef (dir_angle - dir, 0, 0, 1);
|
||||
glColor4f(0, 0.5, 0, 1.0);
|
||||
glRotatef(dir_angle - dir, 0, 0, 1);
|
||||
static const GLshort vtx2 [] = {
|
||||
-2, 0,
|
||||
2, 0,
|
||||
|
@ -275,12 +275,12 @@ void DrawWind(float dir, float speed, const CControl *ctrl) {
|
|||
glVertexPointer(2, GL_SHORT, 0, vtx2);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glPopMatrix ();
|
||||
glPopMatrix();
|
||||
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
Tex.Draw(SPEED_KNOB, 5 + texWidth / 2 - 8, Winsys.resolution.height - 5 - texWidth / 2 - 8, 1.0);
|
||||
string windstr = Int_StrN ((int)speed, 3);
|
||||
string windstr = Int_StrN((int)speed, 3);
|
||||
if (param.use_papercut_font < 2) {
|
||||
Tex.DrawNumStr(windstr, 120, Winsys.resolution.height - 45, 1, colWhite);
|
||||
} else {
|
||||
|
@ -312,21 +312,21 @@ void DrawFps() {
|
|||
|
||||
string fpsstr = Int_StrN((int)averagefps);
|
||||
if (param.use_papercut_font < 2) {
|
||||
Tex.DrawNumStr (fpsstr, (Winsys.resolution.width - 60) / 2, 10, 1, colWhite);
|
||||
Tex.DrawNumStr(fpsstr, (Winsys.resolution.width - 60) / 2, 10, 1, colWhite);
|
||||
} else {
|
||||
Winsys.beginSFML();
|
||||
if (averagefps >= 35)
|
||||
FT.SetColor (colWhite);
|
||||
FT.SetColor(colWhite);
|
||||
else
|
||||
FT.SetColor (colRed);
|
||||
FT.DrawString (-1, 3, fpsstr);
|
||||
FT.SetColor(colRed);
|
||||
FT.DrawString(-1, 3, fpsstr);
|
||||
Winsys.endSFML();
|
||||
}
|
||||
}
|
||||
|
||||
void DrawPercentBar (float fact, float x, float y) {
|
||||
Tex.BindTex (T_ENERGY_MASK);
|
||||
glColor4f (1.0, 1.0, 1.0, 1.0);
|
||||
void DrawPercentBar(float fact, float x, float y) {
|
||||
Tex.BindTex(T_ENERGY_MASK);
|
||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
const GLfloat tex[] = {
|
||||
0, 1,
|
||||
|
@ -352,28 +352,28 @@ void DrawPercentBar (float fact, float x, float y) {
|
|||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
void DrawCoursePosition (const CControl *ctrl) {
|
||||
void DrawCoursePosition(const CControl *ctrl) {
|
||||
double fact = ctrl->cpos.z / Course.GetPlayDimensions().y;
|
||||
if (fact > 1.0) fact = 1.0;
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
DrawPercentBar (-fact, Winsys.resolution.width - 48, 280-128);
|
||||
Tex.Draw (T_MASK_OUTLINE, Winsys.resolution.width - 48, Winsys.resolution.height - 280, 1.0);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
DrawPercentBar(-fact, Winsys.resolution.width - 48, 280-128);
|
||||
Tex.Draw(T_MASK_OUTLINE, Winsys.resolution.width - 48, Winsys.resolution.height - 280, 1.0);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------
|
||||
void DrawHud (const CControl *ctrl) {
|
||||
void DrawHud(const CControl *ctrl) {
|
||||
if (!param.show_hud)
|
||||
return;
|
||||
|
||||
double speed = ctrl->cvel.Length();
|
||||
Setup2dScene ();
|
||||
Setup2dScene();
|
||||
|
||||
draw_gauge (speed * 3.6, ctrl->jump_amt);
|
||||
draw_gauge(speed * 3.6, ctrl->jump_amt);
|
||||
ScopedRenderMode rm(TEXFONT);
|
||||
draw_time();
|
||||
draw_herring_count (g_game.herring);
|
||||
DrawSpeed (speed * 3.6);
|
||||
DrawFps ();
|
||||
DrawCoursePosition (ctrl);
|
||||
DrawWind (Wind.Angle (), Wind.Speed (), ctrl);
|
||||
draw_herring_count(g_game.herring);
|
||||
DrawSpeed(speed * 3.6);
|
||||
DrawFps();
|
||||
DrawCoursePosition(ctrl);
|
||||
DrawWind(Wind.Angle(), Wind.Speed(), ctrl);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,6 @@ GNU General Public License for more details.
|
|||
|
||||
#include "bh.h"
|
||||
|
||||
void DrawHud (const CControl *ctrl);
|
||||
void DrawHud(const CControl *ctrl);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -52,7 +52,7 @@ void abort_intro() {
|
|||
// =================================================================
|
||||
void CIntro::Enter() {
|
||||
CControl *ctrl = g_game.player->ctrl;
|
||||
const TVector2d& start_pt = Course.GetStartPoint ();
|
||||
const TVector2d& start_pt = Course.GetStartPoint();
|
||||
ctrl->orientation_initialized = false;
|
||||
ctrl->view_init = false;
|
||||
ctrl->cpos.x = start_pt.x;
|
||||
|
@ -70,14 +70,14 @@ void CIntro::Enter() {
|
|||
g_game.race_result = -1;
|
||||
g_game.raceaborted = false;
|
||||
|
||||
ctrl->Init ();
|
||||
ctrl->Init();
|
||||
|
||||
ctrl->cvel = TVector3d(0, 0, 0);
|
||||
clear_particles();
|
||||
set_view_mode (ctrl, ABOVE);
|
||||
SetCameraDistance (4.0);
|
||||
SetStationaryCamera (false);
|
||||
update_view (ctrl, EPS);
|
||||
set_view_mode(ctrl, ABOVE);
|
||||
SetCameraDistance(4.0);
|
||||
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++) {
|
||||
|
@ -86,52 +86,52 @@ void CIntro::Enter() {
|
|||
}
|
||||
}
|
||||
|
||||
InitSnow (ctrl);
|
||||
InitWind ();
|
||||
InitSnow(ctrl);
|
||||
InitWind();
|
||||
|
||||
Music.PlayTheme (g_game.theme_id, MUS_RACING);
|
||||
Music.PlayTheme(g_game.theme_id, MUS_RACING);
|
||||
param.show_hud = true;
|
||||
}
|
||||
|
||||
void CIntro::Loop (double time_step) {
|
||||
void CIntro::Loop(double time_step) {
|
||||
CControl *ctrl = g_game.player->ctrl;
|
||||
int width = Winsys.resolution.width;
|
||||
int height = Winsys.resolution.height;
|
||||
|
||||
if (startframe->active) {
|
||||
startframe->Update (time_step);
|
||||
} else State::manager.RequestEnterState (Racing);
|
||||
startframe->Update(time_step);
|
||||
} else State::manager.RequestEnterState(Racing);
|
||||
|
||||
ClearRenderContext ();
|
||||
Env.SetupFog ();
|
||||
ClearRenderContext();
|
||||
Env.SetupFog();
|
||||
|
||||
update_view (ctrl, time_step);
|
||||
SetupViewFrustum (ctrl);
|
||||
update_view(ctrl, time_step);
|
||||
SetupViewFrustum(ctrl);
|
||||
|
||||
Env.DrawSkybox (ctrl->viewpos);
|
||||
Env.DrawSkybox(ctrl->viewpos);
|
||||
|
||||
Env.DrawFog ();
|
||||
Env.SetupLight ();
|
||||
RenderCourse ();
|
||||
DrawTrackmarks ();
|
||||
DrawTrees ();
|
||||
Env.DrawFog();
|
||||
Env.SetupLight();
|
||||
RenderCourse();
|
||||
DrawTrackmarks();
|
||||
DrawTrees();
|
||||
|
||||
UpdateWind (time_step);
|
||||
UpdateSnow (time_step, ctrl);
|
||||
DrawSnow (ctrl);
|
||||
UpdateWind(time_step);
|
||||
UpdateSnow(time_step, ctrl);
|
||||
DrawSnow(ctrl);
|
||||
|
||||
g_game.character->shape->Draw();
|
||||
DrawHud (ctrl);
|
||||
DrawHud(ctrl);
|
||||
|
||||
Reshape (width, height);
|
||||
Winsys.SwapBuffers ();
|
||||
Reshape(width, height);
|
||||
Winsys.SwapBuffers();
|
||||
|
||||
}
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
void CIntro::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CIntro::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release)
|
||||
return;
|
||||
|
||||
abort_intro ();
|
||||
abort_intro();
|
||||
}
|
||||
|
|
230
src/keyframe.cpp
230
src/keyframe.cpp
|
@ -48,7 +48,7 @@ static const string highlightnames[numJoints] = {
|
|||
|
||||
CKeyframe TestFrame;
|
||||
|
||||
CKeyframe::CKeyframe () {
|
||||
CKeyframe::CKeyframe() {
|
||||
keytime = 0;
|
||||
active = false;
|
||||
loaded = false;
|
||||
|
@ -56,11 +56,11 @@ CKeyframe::CKeyframe () {
|
|||
keyidx = 0;
|
||||
}
|
||||
|
||||
double CKeyframe::interp (double frac, double v1, double v2) {
|
||||
double CKeyframe::interp(double frac, double v1, double v2) {
|
||||
return frac * v1 + (1.0 - frac) * v2;
|
||||
}
|
||||
|
||||
void CKeyframe::Init (const TVector3d& ref_position, double height_correction) {
|
||||
void CKeyframe::Init(const TVector3d& ref_position, double height_correction) {
|
||||
if (!loaded) return;
|
||||
g_game.character->shape->ResetNode("head");
|
||||
g_game.character->shape->ResetNode("neck");
|
||||
|
@ -71,10 +71,10 @@ void CKeyframe::Init (const TVector3d& ref_position, double height_correction) {
|
|||
keytime = 0;
|
||||
}
|
||||
|
||||
void CKeyframe::Init (const TVector3d& ref_position, double height_correction, CCharShape *shape) {
|
||||
void CKeyframe::Init(const TVector3d& ref_position, double height_correction, CCharShape *shape) {
|
||||
if (!loaded) return;
|
||||
shape->ResetNode ("head");
|
||||
shape->ResetNode ("neck");
|
||||
shape->ResetNode("head");
|
||||
shape->ResetNode("neck");
|
||||
refpos = ref_position;
|
||||
heightcorr = height_correction;
|
||||
active = true;
|
||||
|
@ -83,10 +83,10 @@ void CKeyframe::Init (const TVector3d& ref_position, double height_correction, C
|
|||
|
||||
}
|
||||
|
||||
void CKeyframe::InitTest (const TVector3d& ref_position, CCharShape *shape) {
|
||||
void CKeyframe::InitTest(const TVector3d& ref_position, CCharShape *shape) {
|
||||
if (!loaded) return;
|
||||
shape->ResetNode ("head");
|
||||
shape->ResetNode ("neck");
|
||||
shape->ResetNode("head");
|
||||
shape->ResetNode("neck");
|
||||
refpos = ref_position;
|
||||
heightcorr = 0.0;
|
||||
active = true;
|
||||
|
@ -94,7 +94,7 @@ void CKeyframe::InitTest (const TVector3d& ref_position, CCharShape *shape) {
|
|||
keytime = 0;
|
||||
}
|
||||
|
||||
void CKeyframe::Reset () {
|
||||
void CKeyframe::Reset() {
|
||||
loaded = false;
|
||||
active = false;
|
||||
loadedfile = "";
|
||||
|
@ -102,24 +102,24 @@ void CKeyframe::Reset () {
|
|||
frames.clear();
|
||||
}
|
||||
|
||||
bool CKeyframe::Load (const string& dir, const string& filename) {
|
||||
bool CKeyframe::Load(const string& dir, const string& filename) {
|
||||
if (loaded && loadedfile == filename) return true;
|
||||
CSPList list (1000);
|
||||
CSPList list(1000);
|
||||
|
||||
if (list.Load (dir, filename)) {
|
||||
if (list.Load(dir, filename)) {
|
||||
frames.resize(list.Count());
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
frames[i].val[0] = SPFloatN (line, "time", 0);
|
||||
frames[i].val[0] = SPFloatN(line, "time", 0);
|
||||
TVector3d posit = SPVector3d(line, "pos");
|
||||
frames[i].val[1] = posit.x;
|
||||
frames[i].val[2] = posit.y;
|
||||
frames[i].val[3] = posit.z;
|
||||
frames[i].val[4] = SPFloatN (line, "yaw", 0);
|
||||
frames[i].val[5] = SPFloatN (line, "pitch", 0);
|
||||
frames[i].val[6] = SPFloatN (line, "roll", 0);
|
||||
frames[i].val[7] = SPFloatN (line, "neck", 0);
|
||||
frames[i].val[8] = SPFloatN (line, "head", 0);
|
||||
frames[i].val[4] = SPFloatN(line, "yaw", 0);
|
||||
frames[i].val[5] = SPFloatN(line, "pitch", 0);
|
||||
frames[i].val[6] = SPFloatN(line, "roll", 0);
|
||||
frames[i].val[7] = SPFloatN(line, "neck", 0);
|
||||
frames[i].val[8] = SPFloatN(line, "head", 0);
|
||||
TVector2d pp = SPVector2d(line, "sh");
|
||||
frames[i].val[9] = pp.x;
|
||||
frames[i].val[10] = pp.y;
|
||||
|
@ -140,7 +140,7 @@ bool CKeyframe::Load (const string& dir, const string& filename) {
|
|||
loadedfile = filename;
|
||||
return true;
|
||||
} else {
|
||||
Message ("keyframe not found:", filename);
|
||||
Message("keyframe not found:", filename);
|
||||
loaded = false;
|
||||
return false;
|
||||
}
|
||||
|
@ -149,55 +149,55 @@ bool CKeyframe::Load (const string& dir, const string& filename) {
|
|||
// there are more possibilities for rotating the parts of the body,
|
||||
// that will be implemented later
|
||||
|
||||
void CKeyframe::InterpolateKeyframe (size_t idx, double frac, CCharShape *shape) {
|
||||
void CKeyframe::InterpolateKeyframe(size_t idx, double frac, CCharShape *shape) {
|
||||
double vv;
|
||||
vv = interp (frac, frames[idx].val[4], frames[idx+1].val[4]);
|
||||
shape->RotateNode ("root", 2, vv);
|
||||
vv = interp(frac, frames[idx].val[4], frames[idx+1].val[4]);
|
||||
shape->RotateNode("root", 2, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[5], frames[idx+1].val[5]);
|
||||
shape->RotateNode ("root", 1, vv);
|
||||
vv = interp(frac, frames[idx].val[5], frames[idx+1].val[5]);
|
||||
shape->RotateNode("root", 1, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[6], frames[idx+1].val[6]);
|
||||
shape->RotateNode ("root", 3, vv);
|
||||
vv = interp(frac, frames[idx].val[6], frames[idx+1].val[6]);
|
||||
shape->RotateNode("root", 3, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[7], frames[idx+1].val[7]);
|
||||
shape->RotateNode ("neck", 3, vv);
|
||||
vv = interp(frac, frames[idx].val[7], frames[idx+1].val[7]);
|
||||
shape->RotateNode("neck", 3, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[8], frames[idx+1].val[8]);
|
||||
shape->RotateNode ("head", 2, vv);
|
||||
vv = interp(frac, frames[idx].val[8], frames[idx+1].val[8]);
|
||||
shape->RotateNode("head", 2, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[9], frames[idx+1].val[9]);
|
||||
shape->RotateNode ("left_shldr", 3, vv);
|
||||
vv = interp(frac, frames[idx].val[9], frames[idx+1].val[9]);
|
||||
shape->RotateNode("left_shldr", 3, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[10], frames[idx+1].val[10]);
|
||||
shape->RotateNode ("right_shldr", 3, vv);
|
||||
vv = interp(frac, frames[idx].val[10], frames[idx+1].val[10]);
|
||||
shape->RotateNode("right_shldr", 3, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[11], frames[idx+1].val[11]);
|
||||
shape->RotateNode ("left_shldr", 2, vv);
|
||||
vv = interp(frac, frames[idx].val[11], frames[idx+1].val[11]);
|
||||
shape->RotateNode("left_shldr", 2, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[12], frames[idx+1].val[12]);
|
||||
shape->RotateNode ("right_shldr", 2, vv);
|
||||
vv = interp(frac, frames[idx].val[12], frames[idx+1].val[12]);
|
||||
shape->RotateNode("right_shldr", 2, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[13], frames[idx+1].val[13]);
|
||||
shape->RotateNode ("left_hip", 3, vv);
|
||||
vv = interp(frac, frames[idx].val[13], frames[idx+1].val[13]);
|
||||
shape->RotateNode("left_hip", 3, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[14], frames[idx+1].val[14]);
|
||||
shape->RotateNode ("right_hip", 3, vv);
|
||||
vv = interp(frac, frames[idx].val[14], frames[idx+1].val[14]);
|
||||
shape->RotateNode("right_hip", 3, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[15], frames[idx+1].val[15]);
|
||||
shape->RotateNode ("left_knee", 3, vv);
|
||||
vv = interp(frac, frames[idx].val[15], frames[idx+1].val[15]);
|
||||
shape->RotateNode("left_knee", 3, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[16], frames[idx+1].val[16]);
|
||||
shape->RotateNode ("right_knee", 3, vv);
|
||||
vv = interp(frac, frames[idx].val[16], frames[idx+1].val[16]);
|
||||
shape->RotateNode("right_knee", 3, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[17], frames[idx+1].val[17]);
|
||||
shape->RotateNode ("left_ankle", 3, vv);
|
||||
vv = interp(frac, frames[idx].val[17], frames[idx+1].val[17]);
|
||||
shape->RotateNode("left_ankle", 3, vv);
|
||||
|
||||
vv = interp (frac, frames[idx].val[18], frames[idx+1].val[18]);
|
||||
shape->RotateNode ("right_ankle", 3, vv);
|
||||
vv = interp(frac, frames[idx].val[18], frames[idx+1].val[18]);
|
||||
shape->RotateNode("right_ankle", 3, vv);
|
||||
}
|
||||
|
||||
void CKeyframe::CalcKeyframe (size_t idx, CCharShape *shape, const TVector3d& refpos) {
|
||||
void CKeyframe::CalcKeyframe(size_t idx, CCharShape *shape, const TVector3d& refpos) {
|
||||
double vv;
|
||||
TVector3d pos;
|
||||
|
||||
|
@ -205,57 +205,57 @@ void CKeyframe::CalcKeyframe (size_t idx, CCharShape *shape, const TVector3d& re
|
|||
pos.z = frames[idx].val[3] + refpos.z;
|
||||
pos.y = refpos.y;
|
||||
|
||||
shape->ResetRoot ();
|
||||
shape->ResetJoints ();
|
||||
shape->TranslateNode (0, pos);
|
||||
shape->ResetRoot();
|
||||
shape->ResetJoints();
|
||||
shape->TranslateNode(0, pos);
|
||||
|
||||
vv = frames[idx].val[4];
|
||||
shape->RotateNode ("root", 2, vv);
|
||||
shape->RotateNode("root", 2, vv);
|
||||
|
||||
vv = frames[idx].val[5];
|
||||
shape->RotateNode ("root", 1, vv);
|
||||
shape->RotateNode("root", 1, vv);
|
||||
|
||||
vv = frames[idx].val[6];
|
||||
shape->RotateNode ("root", 3, vv);
|
||||
shape->RotateNode("root", 3, vv);
|
||||
|
||||
vv = frames[idx].val[7];
|
||||
shape->RotateNode ("neck", 3, vv);
|
||||
shape->RotateNode("neck", 3, vv);
|
||||
|
||||
vv = frames[idx].val[8];
|
||||
shape->RotateNode ("head", 2, vv);
|
||||
shape->RotateNode("head", 2, vv);
|
||||
|
||||
vv = frames[idx].val[9];
|
||||
shape->RotateNode ("left_shldr", 3, vv);
|
||||
shape->RotateNode("left_shldr", 3, vv);
|
||||
|
||||
vv = frames[idx].val[10];
|
||||
shape->RotateNode ("right_shldr", 3, vv);
|
||||
shape->RotateNode("right_shldr", 3, vv);
|
||||
|
||||
vv = frames[idx].val[11];
|
||||
shape->RotateNode ("left_shldr", 2, vv);
|
||||
shape->RotateNode("left_shldr", 2, vv);
|
||||
|
||||
vv = frames[idx].val[12];
|
||||
shape->RotateNode ("right_shldr", 2, vv);
|
||||
shape->RotateNode("right_shldr", 2, vv);
|
||||
|
||||
vv = frames[idx].val[13];
|
||||
shape->RotateNode ("left_hip", 3, vv);
|
||||
shape->RotateNode("left_hip", 3, vv);
|
||||
|
||||
vv = frames[idx].val[14];
|
||||
shape->RotateNode ("right_hip", 3, vv);
|
||||
shape->RotateNode("right_hip", 3, vv);
|
||||
|
||||
vv = frames[idx].val[15];
|
||||
shape->RotateNode ("left_knee", 3, vv);
|
||||
shape->RotateNode("left_knee", 3, vv);
|
||||
|
||||
vv = frames[idx].val[16];
|
||||
shape->RotateNode ("right_knee", 3, vv);
|
||||
shape->RotateNode("right_knee", 3, vv);
|
||||
|
||||
vv = frames[idx].val[17];
|
||||
shape->RotateNode ("left_ankle", 3, vv);
|
||||
shape->RotateNode("left_ankle", 3, vv);
|
||||
|
||||
vv = frames[idx].val[18];
|
||||
shape->RotateNode ("right_ankle", 3, vv);
|
||||
shape->RotateNode("right_ankle", 3, vv);
|
||||
}
|
||||
|
||||
void CKeyframe::Update (double timestep) {
|
||||
void CKeyframe::Update(double timestep) {
|
||||
if (!loaded) return;
|
||||
if (!active) return;
|
||||
|
||||
|
@ -274,25 +274,25 @@ void CKeyframe::Update (double timestep) {
|
|||
TVector3d pos;
|
||||
CCharShape *shape = g_game.character->shape;
|
||||
|
||||
if (fabs (frames[keyidx].val[0]) < 0.0001) frac = 1.0;
|
||||
if (fabs(frames[keyidx].val[0]) < 0.0001) frac = 1.0;
|
||||
else frac = (frames[keyidx].val[0] - keytime) / frames[keyidx].val[0];
|
||||
|
||||
pos.x = interp (frac, frames[keyidx].val[1], frames[keyidx+1].val[1]) + refpos.x;
|
||||
pos.z = interp (frac, frames[keyidx].val[3], frames[keyidx+1].val[3]) + refpos.z;
|
||||
pos.y = interp (frac, frames[keyidx].val[2], frames[keyidx+1].val[2]);
|
||||
pos.y += Course.FindYCoord (pos.x, pos.z);
|
||||
pos.x = interp(frac, frames[keyidx].val[1], frames[keyidx+1].val[1]) + refpos.x;
|
||||
pos.z = interp(frac, frames[keyidx].val[3], frames[keyidx+1].val[3]) + refpos.z;
|
||||
pos.y = interp(frac, frames[keyidx].val[2], frames[keyidx+1].val[2]);
|
||||
pos.y += Course.FindYCoord(pos.x, pos.z);
|
||||
|
||||
shape->ResetRoot ();
|
||||
shape->ResetJoints ();
|
||||
shape->ResetRoot();
|
||||
shape->ResetJoints();
|
||||
|
||||
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));
|
||||
InterpolateKeyframe (keyidx, frac, shape);
|
||||
shape->ResetNode(0);
|
||||
shape->TranslateNode(0, TVector3d(pos.x, disp_y, pos.z));
|
||||
InterpolateKeyframe(keyidx, frac, shape);
|
||||
}
|
||||
|
||||
void CKeyframe::UpdateTest (double timestep, CCharShape *shape) {
|
||||
void CKeyframe::UpdateTest(double timestep, CCharShape *shape) {
|
||||
if (!active) return;
|
||||
|
||||
keytime += timestep;
|
||||
|
@ -309,52 +309,52 @@ void CKeyframe::UpdateTest (double timestep, CCharShape *shape) {
|
|||
double frac;
|
||||
TVector3d pos;
|
||||
|
||||
if (fabs (frames[keyidx].val[0]) < 0.0001) frac = 1.0;
|
||||
if (fabs(frames[keyidx].val[0]) < 0.0001) frac = 1.0;
|
||||
else frac = (frames[keyidx].val[0] - keytime) / frames[keyidx].val[0];
|
||||
|
||||
pos.x = interp (frac, frames[keyidx].val[1], frames[keyidx+1].val[1]) + refpos.x;
|
||||
pos.z = interp (frac, frames[keyidx].val[3], frames[keyidx+1].val[3]) + refpos.z;
|
||||
pos.y = interp (frac, frames[keyidx].val[2], frames[keyidx+1].val[2]);
|
||||
pos.x = interp(frac, frames[keyidx].val[1], frames[keyidx+1].val[1]) + refpos.x;
|
||||
pos.z = interp(frac, frames[keyidx].val[3], frames[keyidx+1].val[3]) + refpos.z;
|
||||
pos.y = interp(frac, frames[keyidx].val[2], frames[keyidx+1].val[2]);
|
||||
|
||||
shape->ResetRoot ();
|
||||
shape->ResetJoints ();
|
||||
shape->TranslateNode (0, pos);
|
||||
InterpolateKeyframe (keyidx, frac, shape);
|
||||
shape->ResetRoot();
|
||||
shape->ResetJoints();
|
||||
shape->TranslateNode(0, pos);
|
||||
InterpolateKeyframe(keyidx, frac, shape);
|
||||
}
|
||||
|
||||
void CKeyframe::ResetFrame2 (TKeyframe *frame) {
|
||||
void CKeyframe::ResetFrame2(TKeyframe *frame) {
|
||||
for (int i=1; i<32; i++) frame->val[i] = 0.0;
|
||||
frame->val[0] = 0.5; // time
|
||||
}
|
||||
|
||||
TKeyframe *CKeyframe::GetFrame (size_t idx) {
|
||||
TKeyframe *CKeyframe::GetFrame(size_t idx) {
|
||||
if (idx >= frames.size()) return NULL;
|
||||
return &frames[idx];
|
||||
}
|
||||
|
||||
const string& CKeyframe::GetJointName (size_t idx) {
|
||||
const string& CKeyframe::GetJointName(size_t idx) {
|
||||
if (idx >= numJoints) return emptyString;
|
||||
return jointnames[idx];
|
||||
}
|
||||
|
||||
const string& CKeyframe::GetHighlightName (size_t idx) {
|
||||
const string& CKeyframe::GetHighlightName(size_t idx) {
|
||||
if (idx >= numJoints) return emptyString;
|
||||
return highlightnames[idx];
|
||||
}
|
||||
|
||||
int CKeyframe::GetNumJoints () {
|
||||
int CKeyframe::GetNumJoints() {
|
||||
return numJoints;
|
||||
}
|
||||
|
||||
void CKeyframe::SaveTest (const string& dir, const string& filename) {
|
||||
CSPList list (100);
|
||||
void CKeyframe::SaveTest(const string& dir, const string& filename) {
|
||||
CSPList list(100);
|
||||
|
||||
for (size_t i=0; i<frames.size(); i++) {
|
||||
TKeyframe* frame = &frames[i];
|
||||
string line = "*[time] " + Float_StrN (frame->val[0], 1);
|
||||
line += " [pos] " + Float_StrN (frame->val[1], 2);
|
||||
line += " " + Float_StrN (frame->val[2], 2);
|
||||
line += " " + Float_StrN (frame->val[3], 2);
|
||||
string line = "*[time] " + Float_StrN(frame->val[0], 1);
|
||||
line += " [pos] " + Float_StrN(frame->val[1], 2);
|
||||
line += " " + Float_StrN(frame->val[2], 2);
|
||||
line += " " + Float_StrN(frame->val[3], 2);
|
||||
if (frame->val[4] != 0) line += " [yaw] " + Int_StrN((int)frame->val[4]);
|
||||
if (frame->val[5] != 0) line += " [pitch] " + Int_StrN((int)frame->val[5]);
|
||||
if (frame->val[6] != 0) line += " [roll] " + Int_StrN((int)frame->val[6]);
|
||||
|
@ -386,23 +386,23 @@ void CKeyframe::SaveTest (const string& dir, const string& filename) {
|
|||
if (ll != 0 || rr != 0)
|
||||
line += " [ankle] " + Int_StrN((int)ll) + ' ' + Int_StrN((int)rr);
|
||||
|
||||
list.Add (line);
|
||||
list.Add(line);
|
||||
}
|
||||
list.Save (dir, filename);
|
||||
list.Save(dir, filename);
|
||||
}
|
||||
|
||||
void CKeyframe::CopyFrame (size_t prim_idx, size_t sec_idx) {
|
||||
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));
|
||||
}
|
||||
|
||||
void CKeyframe::AddFrame () {
|
||||
void CKeyframe::AddFrame() {
|
||||
frames.push_back(TKeyframe());
|
||||
ResetFrame2 (&frames.back());
|
||||
ResetFrame2(&frames.back());
|
||||
}
|
||||
|
||||
size_t CKeyframe::DeleteFrame (size_t idx) {
|
||||
size_t CKeyframe::DeleteFrame(size_t idx) {
|
||||
if (frames.size() < 2) return idx;
|
||||
size_t lastframe = frames.size()-1;
|
||||
if (idx > lastframe) return 0;
|
||||
|
@ -412,33 +412,33 @@ size_t CKeyframe::DeleteFrame (size_t idx) {
|
|||
return frames.size()-1;
|
||||
|
||||
} else {
|
||||
for (size_t i=idx; i<lastframe-1; i++) CopyFrame (i+1, i);
|
||||
for (size_t i=idx; i<lastframe-1; i++) CopyFrame(i+1, i);
|
||||
frames.pop_back();
|
||||
return idx;
|
||||
}
|
||||
}
|
||||
|
||||
void CKeyframe::InsertFrame (size_t idx) {
|
||||
void CKeyframe::InsertFrame(size_t idx) {
|
||||
size_t lastframe = frames.size()-1;
|
||||
if (idx > lastframe) return;
|
||||
|
||||
frames.push_back(TKeyframe());
|
||||
|
||||
for (size_t i=frames.size()-1; i>idx; i--) CopyFrame (i-1, i);
|
||||
ResetFrame2 (&frames[idx]);
|
||||
for (size_t i=frames.size()-1; i>idx; i--) CopyFrame(i-1, i);
|
||||
ResetFrame2(&frames[idx]);
|
||||
}
|
||||
|
||||
void CKeyframe::CopyToClipboard (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));
|
||||
}
|
||||
|
||||
void CKeyframe::PasteFromClipboard (size_t idx) {
|
||||
void CKeyframe::PasteFromClipboard(size_t idx) {
|
||||
if (idx >= frames.size()) return;
|
||||
memcpy(frames[idx].val, clipboard.val, MAX_FRAME_VALUES*sizeof(*frames[idx].val));
|
||||
}
|
||||
|
||||
void CKeyframe::ClearFrame (size_t idx) {
|
||||
void CKeyframe::ClearFrame(size_t idx) {
|
||||
if (idx >= frames.size()) return;
|
||||
ResetFrame2 (&frames[idx]);
|
||||
ResetFrame2(&frames[idx]);
|
||||
}
|
||||
|
|
|
@ -39,38 +39,38 @@ private:
|
|||
double heightcorr;
|
||||
size_t keyidx;
|
||||
|
||||
double interp (double frac, double v1, double v2);
|
||||
void InterpolateKeyframe (size_t idx, double frac, CCharShape *shape);
|
||||
double interp(double frac, double v1, double v2);
|
||||
void InterpolateKeyframe(size_t idx, double frac, CCharShape *shape);
|
||||
|
||||
// test and editing
|
||||
void ResetFrame2 (TKeyframe *frame);
|
||||
void ResetFrame2(TKeyframe *frame);
|
||||
public:
|
||||
CKeyframe ();
|
||||
CKeyframe();
|
||||
bool loaded;
|
||||
bool active;
|
||||
|
||||
void Init (const TVector3d& ref_position, double height_correction);
|
||||
void Init (const TVector3d& ref_position, double height_correction, CCharShape *shape);
|
||||
void InitTest (const TVector3d& ref_position, CCharShape *shape);
|
||||
void Reset ();
|
||||
void Update (double timestep);
|
||||
void UpdateTest (double timestep, CCharShape *shape);
|
||||
bool Load (const string& dir, const string& filename);
|
||||
void CalcKeyframe (size_t idx, CCharShape *shape, const TVector3d& refpos);
|
||||
void Init(const TVector3d& ref_position, double height_correction);
|
||||
void Init(const TVector3d& ref_position, double height_correction, CCharShape *shape);
|
||||
void InitTest(const TVector3d& ref_position, CCharShape *shape);
|
||||
void Reset();
|
||||
void Update(double timestep);
|
||||
void UpdateTest(double timestep, CCharShape *shape);
|
||||
bool Load(const string& dir, const string& filename);
|
||||
void CalcKeyframe(size_t idx, CCharShape *shape, const TVector3d& refpos);
|
||||
|
||||
// test and editing
|
||||
TKeyframe *GetFrame (size_t idx);
|
||||
static const string& GetHighlightName (size_t idx);
|
||||
static const string& GetJointName (size_t idx);
|
||||
static int GetNumJoints ();
|
||||
void SaveTest (const string& dir, const string& filename);
|
||||
void CopyFrame (size_t prim_idx, size_t sec_idx);
|
||||
void AddFrame ();
|
||||
size_t DeleteFrame (size_t idx);
|
||||
void InsertFrame (size_t idx);
|
||||
void CopyToClipboard (size_t idx);
|
||||
void PasteFromClipboard (size_t idx);
|
||||
void ClearFrame (size_t idx);
|
||||
TKeyframe *GetFrame(size_t idx);
|
||||
static const string& GetHighlightName(size_t idx);
|
||||
static const string& GetJointName(size_t idx);
|
||||
static int GetNumJoints();
|
||||
void SaveTest(const string& dir, const string& filename);
|
||||
void CopyFrame(size_t prim_idx, size_t sec_idx);
|
||||
void AddFrame();
|
||||
size_t DeleteFrame(size_t idx);
|
||||
void InsertFrame(size_t idx);
|
||||
void CopyToClipboard(size_t idx);
|
||||
void PasteFromClipboard(size_t idx);
|
||||
void ClearFrame(size_t idx);
|
||||
size_t numFrames() const { return frames.size(); }
|
||||
};
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ CLoading Loading;
|
|||
|
||||
// ====================================================================
|
||||
void CLoading::Enter() {
|
||||
Winsys.ShowCursor (false);
|
||||
Music.Play ("loading", true);
|
||||
Winsys.ShowCursor(false);
|
||||
Music.Play("loading", true);
|
||||
}
|
||||
|
||||
void CLoading::Loop(double time_step) {
|
||||
|
@ -45,8 +45,8 @@ void CLoading::Loop(double time_step) {
|
|||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow (time_step);
|
||||
draw_ui_snow ();
|
||||
update_ui_snow(time_step);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
sf::Sprite logo(Tex.GetSFTexture(TEXLOGO));
|
||||
|
@ -55,15 +55,15 @@ void CLoading::Loop(double time_step) {
|
|||
Winsys.draw(logo);
|
||||
DrawGUIFrame();
|
||||
|
||||
FT.SetColor (colDYell);
|
||||
FT.SetColor(colDYell);
|
||||
FT.AutoSizeN(5);
|
||||
FT.DrawString(CENTER, AutoYPosN(60), Trans.Text(29) + " '" + g_game.course->name + '\'');
|
||||
FT.SetColor (colWhite);
|
||||
FT.DrawString (CENTER, AutoYPosN (70), Trans.Text (30));
|
||||
Winsys.SwapBuffers ();
|
||||
FT.SetColor(colWhite);
|
||||
FT.DrawString(CENTER, AutoYPosN(70), Trans.Text(30));
|
||||
Winsys.SwapBuffers();
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
|
16
src/main.cpp
16
src/main.cpp
|
@ -33,7 +33,7 @@ GNU General Public License for more details.
|
|||
|
||||
TGameData g_game;
|
||||
|
||||
void InitGame (int argc, char **argv) {
|
||||
void InitGame(int argc, char **argv) {
|
||||
g_game.toolmode = NONE;
|
||||
g_game.argument = 0;
|
||||
if (argc == 4) {
|
||||
|
@ -69,22 +69,22 @@ int main(int argc, char **argv) {
|
|||
cout << "\n----------- Extreme Tux Racer " ETR_VERSION_STRING " ----------------";
|
||||
cout << "\n----------- (C) 2010-2013 Extreme Tuxracer Team --------\n\n";
|
||||
|
||||
srand (time (NULL));
|
||||
srand(time(NULL));
|
||||
InitConfig();
|
||||
InitGame(argc, argv);
|
||||
Winsys.Init ();
|
||||
InitOpenglExtensions ();
|
||||
Winsys.Init();
|
||||
InitOpenglExtensions();
|
||||
// for checking the joystick and the OpgenGL version (the info is
|
||||
// written on the console):
|
||||
// Winsys.PrintJoystickInfo ();
|
||||
// PrintGLInfo ();
|
||||
|
||||
// theses resources must or should be loaded before splashscreen starts
|
||||
Tex.LoadTextureList ();
|
||||
FT.LoadFontlist ();
|
||||
Tex.LoadTextureList();
|
||||
FT.LoadFontlist();
|
||||
FT.SetFontFromSettings();
|
||||
Music.LoadMusicList ();
|
||||
Music.SetVolume (param.music_volume);
|
||||
Music.LoadMusicList();
|
||||
Music.SetVolume(param.music_volume);
|
||||
|
||||
switch (g_game.argument) {
|
||||
case 0:
|
||||
|
|
150
src/mathlib.cpp
150
src/mathlib.cpp
|
@ -25,8 +25,8 @@ GNU General Public License for more details.
|
|||
#include <algorithm>
|
||||
|
||||
|
||||
TVector3d ProjectToPlane (const TVector3d& nml, const TVector3d& v) {
|
||||
double dotProd = DotProduct (nml, v);
|
||||
TVector3d ProjectToPlane(const TVector3d& nml, const TVector3d& v) {
|
||||
double dotProd = DotProduct(nml, v);
|
||||
TVector3d nmlComp = dotProd * nml;
|
||||
|
||||
return v - nmlComp;
|
||||
|
@ -35,16 +35,16 @@ TVector3d ProjectToPlane (const TVector3d& nml, const TVector3d& v) {
|
|||
|
||||
TVector3d TransformVector(const TMatrix<4, 4>& mat, const TVector3d& v) {
|
||||
return TVector3d(
|
||||
v.x * mat[0][0] + v.y * mat[1][0] + v.z * mat[2][0],
|
||||
v.x * mat[0][1] + v.y * mat[1][1] + v.z * mat[2][1],
|
||||
v.x * mat[0][2] + v.y * mat[1][2] + v.z * mat[2][2]);
|
||||
v.x * mat[0][0] + v.y * mat[1][0] + v.z * mat[2][0],
|
||||
v.x * mat[0][1] + v.y * mat[1][1] + v.z * mat[2][1],
|
||||
v.x * mat[0][2] + v.y * mat[1][2] + v.z * mat[2][2]);
|
||||
}
|
||||
|
||||
TVector3d TransformNormal(const TVector3d& n, const TMatrix<4, 4>& mat) {
|
||||
return TVector3d(
|
||||
n.x * mat[0][0] + n.y * mat[0][1] + n.z * mat[0][2],
|
||||
n.x * mat[1][0] + n.y * mat[1][1] + n.z * mat[1][2],
|
||||
n.x * mat[2][0] + n.y * mat[2][1] + n.z * mat[2][2]);
|
||||
n.x * mat[0][0] + n.y * mat[0][1] + n.z * mat[0][2],
|
||||
n.x * mat[1][0] + n.y * mat[1][1] + n.z * mat[1][2],
|
||||
n.x * mat[2][0] + n.y * mat[2][1] + n.z * mat[2][2]);
|
||||
}
|
||||
|
||||
TVector3d TransformPoint(const TMatrix<4, 4>& mat, const TVector3d& p) {
|
||||
|
@ -58,7 +58,7 @@ TVector3d TransformPoint(const TMatrix<4, 4>& mat, const TVector3d& p) {
|
|||
return r;
|
||||
}
|
||||
|
||||
bool IntersectPlanes (const TPlane& s1, const TPlane& s2, const TPlane& s3, TVector3d *p) {
|
||||
bool IntersectPlanes(const TPlane& s1, const TPlane& s2, const TPlane& s3, TVector3d *p) {
|
||||
double A[3][4];
|
||||
double x[3];
|
||||
double retval;
|
||||
|
@ -78,7 +78,7 @@ bool IntersectPlanes (const TPlane& s1, const TPlane& s2, const TPlane& s3, TVec
|
|||
A[2][2] = s3.nml.z;
|
||||
A[2][3] = -s3.d;
|
||||
|
||||
retval = Gauss ((double*) A, 3, x);
|
||||
retval = Gauss((double*) A, 3, x);
|
||||
|
||||
if (retval != 0) {
|
||||
return false;
|
||||
|
@ -90,7 +90,7 @@ bool IntersectPlanes (const TPlane& s1, const TPlane& s2, const TPlane& s3, TVec
|
|||
}
|
||||
}
|
||||
|
||||
double DistanceToPlane (const TPlane& plane, const TVector3d& pt) {
|
||||
double DistanceToPlane(const TPlane& plane, const TVector3d& pt) {
|
||||
return
|
||||
DotProduct(plane.nml, pt) +
|
||||
plane.d;
|
||||
|
@ -105,7 +105,7 @@ TMatrix<4, 4> RotateAboutVectorMatrix(const TVector3d& u, double angle) {
|
|||
double b = u.y;
|
||||
double c = u.z;
|
||||
|
||||
double d = sqrt (b*b + c*c);
|
||||
double d = sqrt(b*b + c*c);
|
||||
|
||||
if (d < EPS) {
|
||||
if (a < 0)
|
||||
|
@ -149,15 +149,15 @@ TMatrix<4, 4> RotateAboutVectorMatrix(const TVector3d& u, double angle) {
|
|||
return mat;
|
||||
}
|
||||
|
||||
TQuaternion MultiplyQuaternions (const TQuaternion& q, const TQuaternion& r) {
|
||||
TQuaternion MultiplyQuaternions(const TQuaternion& q, const TQuaternion& r) {
|
||||
return TQuaternion(
|
||||
q.y * r.z - q.z * r.y + r.w * q.x + q.w * r.x,
|
||||
q.z * r.x - q.x * r.z + r.w * q.y + q.w * r.y,
|
||||
q.x * r.y - q.y * r.x + r.w * q.z + q.w * r.z,
|
||||
q.w * r.w - q.x * r.x - q.y * r.y - q.z * r.z);
|
||||
q.y * r.z - q.z * r.y + r.w * q.x + q.w * r.x,
|
||||
q.z * r.x - q.x * r.z + r.w * q.y + q.w * r.y,
|
||||
q.x * r.y - q.y * r.x + r.w * q.z + q.w * r.z,
|
||||
q.w * r.w - q.x * r.x - q.y * r.y - q.z * r.z);
|
||||
}
|
||||
|
||||
TQuaternion ConjugateQuaternion (const TQuaternion& q) {
|
||||
TQuaternion ConjugateQuaternion(const TQuaternion& q) {
|
||||
TQuaternion res(
|
||||
-1 * q.x,
|
||||
-1 * q.y,
|
||||
|
@ -169,17 +169,17 @@ TQuaternion ConjugateQuaternion (const TQuaternion& q) {
|
|||
|
||||
TMatrix<4, 4> MakeMatrixFromQuaternion(const TQuaternion& q) {
|
||||
TMatrix<4, 4> mat;
|
||||
mat[0][0] = 1.0 - 2.0 * (q.y * q.y + q.z * q.z);
|
||||
mat[1][0] = 2.0 * (q.x * q.y - q.w * q.z);
|
||||
mat[2][0] = 2.0 * (q.x * q.z + q.w * q.y);
|
||||
mat[0][0] = 1.0 - 2.0 * (q.y * q.y + q.z * q.z);
|
||||
mat[1][0] = 2.0 * (q.x * q.y - q.w * q.z);
|
||||
mat[2][0] = 2.0 * (q.x * q.z + q.w * q.y);
|
||||
|
||||
mat[0][1] = 2.0 * (q.x * q.y + q.w * q.z);
|
||||
mat[1][1] = 1.0 - 2.0 * (q.x * q.x + q.z * q.z);
|
||||
mat[2][1] = 2.0 * (q.y * q.z - q.w * q.x);
|
||||
mat[0][1] = 2.0 * (q.x * q.y + q.w * q.z);
|
||||
mat[1][1] = 1.0 - 2.0 * (q.x * q.x + q.z * q.z);
|
||||
mat[2][1] = 2.0 * (q.y * q.z - q.w * q.x);
|
||||
|
||||
mat[0][2] = 2.0 * (q.x * q.z - q.w * q.y);
|
||||
mat[1][2] = 2.0 * (q.y * q.z + q.w * q.x);
|
||||
mat[2][2] = 1.0 - 2.0 * (q.x * q.x + q.y * q.y);
|
||||
mat[0][2] = 2.0 * (q.x * q.z - q.w * q.y);
|
||||
mat[1][2] = 2.0 * (q.y * q.z + q.w * q.x);
|
||||
mat[2][2] = 1.0 - 2.0 * (q.x * q.x + q.y * q.y);
|
||||
|
||||
mat[3][0] = mat[3][1] = mat[3][2] = 0.0;
|
||||
mat[0][3] = mat[1][3] = mat[2][3] = 0.0;
|
||||
|
@ -196,7 +196,7 @@ TQuaternion MakeQuaternionFromMatrix(const TMatrix<4, 4>& m) {
|
|||
tr = m[0][0] + m[1][1] + m[2][2];
|
||||
|
||||
if (tr > 0.0) {
|
||||
s = sqrt (tr + 1.0);
|
||||
s = sqrt(tr + 1.0);
|
||||
res.w = 0.5 * s;
|
||||
s = 0.5 / s;
|
||||
res.x = (m[1][2] - m[2][1]) * s;
|
||||
|
@ -209,7 +209,7 @@ TQuaternion MakeQuaternionFromMatrix(const TMatrix<4, 4>& m) {
|
|||
int j = nxt[i];
|
||||
int k = nxt[j];
|
||||
|
||||
s = sqrt (m[i][i] - m[j][j] - m[k][k] + 1.0);
|
||||
s = sqrt(m[i][i] - m[j][j] - m[k][k] + 1.0);
|
||||
|
||||
q[i] = s * 0.5;
|
||||
|
||||
|
@ -228,17 +228,17 @@ TQuaternion MakeQuaternionFromMatrix(const TMatrix<4, 4>& m) {
|
|||
return res;
|
||||
}
|
||||
|
||||
TQuaternion MakeRotationQuaternion (const TVector3d& s, const TVector3d& t) {
|
||||
TVector3d u = CrossProduct (s, t);
|
||||
TQuaternion MakeRotationQuaternion(const TVector3d& s, const TVector3d& t) {
|
||||
TVector3d u = CrossProduct(s, t);
|
||||
double sin2phi = u.Norm();
|
||||
|
||||
if (sin2phi < EPS) {
|
||||
return TQuaternion (0., 0., 0., 1.);
|
||||
return TQuaternion(0., 0., 0., 1.);
|
||||
} else {
|
||||
double cos2phi = DotProduct (s, t);
|
||||
double cos2phi = DotProduct(s, t);
|
||||
|
||||
double sinphi = sqrt ( (1 - cos2phi) / 2.0);
|
||||
double cosphi = sqrt ( (1 + cos2phi) / 2.0);
|
||||
double sinphi = sqrt((1 - cos2phi) / 2.0);
|
||||
double cosphi = sqrt((1 + cos2phi) / 2.0);
|
||||
|
||||
return TQuaternion(
|
||||
sinphi * u.x,
|
||||
|
@ -248,7 +248,7 @@ TQuaternion MakeRotationQuaternion (const TVector3d& s, const TVector3d& t) {
|
|||
}
|
||||
}
|
||||
|
||||
TQuaternion InterpolateQuaternions (const TQuaternion& q, TQuaternion r, double t) {
|
||||
TQuaternion InterpolateQuaternions(const TQuaternion& q, TQuaternion r, double t) {
|
||||
double cosphi = q.x * r.x + q.y * r.y + q.z * r.z + q.w * r.w;
|
||||
|
||||
if (cosphi < 0.0) {
|
||||
|
@ -261,10 +261,10 @@ TQuaternion InterpolateQuaternions (const TQuaternion& q, TQuaternion r, double
|
|||
|
||||
double scale0, scale1;
|
||||
if (1.0 - cosphi > EPS) {
|
||||
double phi = acos (cosphi);
|
||||
double sinphi = sin (phi);
|
||||
scale0 = sin (phi * (1.0 - t)) / sinphi;
|
||||
scale1 = sin (phi * t) / sinphi;
|
||||
double phi = acos(cosphi);
|
||||
double sinphi = sin(phi);
|
||||
scale0 = sin(phi * (1.0 - t)) / sinphi;
|
||||
scale1 = sin(phi * t) / sinphi;
|
||||
} else {
|
||||
scale0 = 1.0 - t;
|
||||
scale1 = t;
|
||||
|
@ -273,12 +273,12 @@ TQuaternion InterpolateQuaternions (const TQuaternion& q, TQuaternion r, double
|
|||
return scale0 * q + scale1 * r;
|
||||
}
|
||||
|
||||
TVector3d RotateVector (const TQuaternion& q, const TVector3d& v) {
|
||||
TVector3d RotateVector(const TQuaternion& q, const TVector3d& v) {
|
||||
TQuaternion p(v.x, v.y, v.z, 1.0);
|
||||
|
||||
TQuaternion qs(-q.x, -q.y, -q.z, q.w);
|
||||
|
||||
TQuaternion res_q = MultiplyQuaternions (q, MultiplyQuaternions (p, qs));
|
||||
TQuaternion res_q = MultiplyQuaternions(q, MultiplyQuaternions(p, qs));
|
||||
|
||||
return res_q;
|
||||
}
|
||||
|
@ -287,9 +287,9 @@ TVector3d RotateVector (const TQuaternion& q, const TVector3d& v) {
|
|||
// Gauss
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
bool order (double *matrix, int n, int pivot);
|
||||
void elim (double *matrix, int n, int pivot);
|
||||
void backsb (double *matrix, int n, double *soln);
|
||||
bool order(double *matrix, int n, int pivot);
|
||||
void elim(double *matrix, int n, int pivot);
|
||||
void backsb(double *matrix, int n, double *soln);
|
||||
|
||||
int Gauss(double *matrix, int n, double *soln) {
|
||||
int pivot = 0;
|
||||
|
@ -309,7 +309,7 @@ int Gauss(double *matrix, int n, double *soln) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool order (double *matrix, int n, int pivot) {
|
||||
bool order(double *matrix, int n, int pivot) {
|
||||
bool error = false;
|
||||
|
||||
int rmax = pivot;
|
||||
|
@ -331,7 +331,7 @@ bool order (double *matrix, int n, int pivot) {
|
|||
return error;
|
||||
}
|
||||
|
||||
void elim (double *matrix, int n, int pivot) {
|
||||
void elim(double *matrix, int n, int pivot) {
|
||||
for (int row = pivot+1; row < n; row++) {
|
||||
double factor = (*(matrix+row*(n+1)+pivot))/(*(matrix+pivot*(n+1)+pivot));
|
||||
*(matrix+row*(n+1)+pivot)=0.0;
|
||||
|
@ -343,7 +343,7 @@ void elim (double *matrix, int n, int pivot) {
|
|||
}
|
||||
|
||||
|
||||
void backsb (double *matrix, int n, double *soln) {
|
||||
void backsb(double *matrix, int n, double *soln) {
|
||||
for (int row = n-1; row >=0; row--) {
|
||||
for (int col = n-1; col >= row+1; col--) {
|
||||
*(matrix+row*(n+1)+(n)) = *(matrix+row*(n+1)+n) -
|
||||
|
@ -361,17 +361,17 @@ bool IntersectPolygon(const TPolygon& p, vector<TVector3d>& v) {
|
|||
double d, s, nuDotProd;
|
||||
double distsq;
|
||||
|
||||
TVector3d nml = MakeNormal (p, &v[0]);
|
||||
TVector3d nml = MakeNormal(p, &v[0]);
|
||||
ray.pt = TVector3d(0., 0., 0.);
|
||||
ray.vec = nml;
|
||||
|
||||
nuDotProd = DotProduct (nml, ray.vec);
|
||||
nuDotProd = DotProduct(nml, ray.vec);
|
||||
if (fabs(nuDotProd) < EPS)
|
||||
return false;
|
||||
|
||||
d = - DotProduct(nml, v[p.vertices[0]]);
|
||||
|
||||
if (fabs (d) > 1) return false;
|
||||
if (fabs(d) > 1) return false;
|
||||
|
||||
for (size_t i=0; i < p.vertices.size(); i++) {
|
||||
TVector3d *v0, *v1;
|
||||
|
@ -382,28 +382,28 @@ bool IntersectPolygon(const TPolygon& p, vector<TVector3d>& v) {
|
|||
TVector3d edge_vec = *v1 - *v0;
|
||||
double edge_len = edge_vec.Norm();
|
||||
|
||||
double t = - DotProduct (*v0, edge_vec);
|
||||
double t = - DotProduct(*v0, edge_vec);
|
||||
|
||||
if (t < 0) {
|
||||
distsq = MAG_SQD (*v0);
|
||||
distsq = MAG_SQD(*v0);
|
||||
} else if (t > edge_len) {
|
||||
distsq = MAG_SQD (*v1);
|
||||
distsq = MAG_SQD(*v1);
|
||||
} else {
|
||||
*v0 += t * edge_vec;
|
||||
distsq = MAG_SQD (*v0);
|
||||
distsq = MAG_SQD(*v0);
|
||||
}
|
||||
|
||||
if (distsq <= 1) return true;
|
||||
}
|
||||
|
||||
s = - (d + DotProduct (nml, ray.pt)) / nuDotProd;
|
||||
s = - (d + DotProduct(nml, ray.pt)) / nuDotProd;
|
||||
TVector3d pt = ray.pt + s * ray.vec;
|
||||
|
||||
for (size_t i = 0; i < p.vertices.size(); i++) {
|
||||
TVector3d edge_nml = CrossProduct (nml,
|
||||
v[p.vertices[(i + 1) % p.vertices.size()]] - v[p.vertices[i]]);
|
||||
TVector3d edge_nml = CrossProduct(nml,
|
||||
v[p.vertices[(i + 1) % p.vertices.size()]] - v[p.vertices[i]]);
|
||||
|
||||
double wec = DotProduct (pt - v[p.vertices[i]], edge_nml);
|
||||
double wec = DotProduct(pt - v[p.vertices[i]], edge_nml);
|
||||
if (wec < 0) return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -412,25 +412,25 @@ bool IntersectPolygon(const TPolygon& p, vector<TVector3d>& v) {
|
|||
bool IntersectPolyhedron(TPolyhedron& p) {
|
||||
bool hit = false;
|
||||
for (size_t i = 0; i < p.polygons.size(); i++) {
|
||||
hit = IntersectPolygon (p.polygons[i], p.vertices);
|
||||
hit = IntersectPolygon(p.polygons[i], p.vertices);
|
||||
if (hit == true) break;
|
||||
}
|
||||
return hit;
|
||||
}
|
||||
|
||||
TVector3d MakeNormal (const TPolygon& p, const TVector3d *v) {
|
||||
TVector3d MakeNormal(const TPolygon& p, const TVector3d *v) {
|
||||
TVector3d v1 = v[p.vertices[1]] - v[p.vertices[0]];
|
||||
TVector3d v2 = v[p.vertices[p.vertices.size() - 1]] - v[p.vertices[0]];
|
||||
TVector3d normal = CrossProduct (v1, v2);
|
||||
TVector3d normal = CrossProduct(v1, v2);
|
||||
|
||||
normal.Norm();
|
||||
return normal;
|
||||
}
|
||||
|
||||
|
||||
void TransPolyhedron (const TMatrix<4, 4>& mat, TPolyhedron& ph) {
|
||||
void TransPolyhedron(const TMatrix<4, 4>& mat, TPolyhedron& ph) {
|
||||
for (size_t i = 0; i < ph.vertices.size(); i++)
|
||||
ph.vertices[i] = TransformPoint (mat, ph.vertices[i]);
|
||||
ph.vertices[i] = TransformPoint(mat, ph.vertices[i]);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -450,7 +450,7 @@ const double ode23_time_step_exp = 1./3.;
|
|||
|
||||
int ode23_NumEstimates() {return 4; }
|
||||
|
||||
void ode23_InitOdeData (TOdeData *data, double init_val, double h) {
|
||||
void ode23_InitOdeData(TOdeData *data, double init_val, double h) {
|
||||
data->init_val = init_val;
|
||||
data->h = h;
|
||||
}
|
||||
|
@ -459,7 +459,7 @@ double ode23_NextTime(TOdeData *data, int step) {
|
|||
return ode23_time_step_mat[step] * data->h;
|
||||
}
|
||||
|
||||
double ode23_NextValue (TOdeData *data, int step) {
|
||||
double ode23_NextValue(TOdeData *data, int step) {
|
||||
double val = data->init_val;
|
||||
|
||||
for (int i=0; i<step; i++)
|
||||
|
@ -502,7 +502,7 @@ TOdeSolver::TOdeSolver() {
|
|||
TimestepExponent = ode23_TimestepExponent;
|
||||
}
|
||||
|
||||
double LinearInterp (const double x[], const double y[], double val, int n) {
|
||||
double LinearInterp(const double x[], const double y[], double val, int n) {
|
||||
int i;
|
||||
double m, b;
|
||||
|
||||
|
@ -516,22 +516,22 @@ double LinearInterp (const double x[], const double y[], double val, int n) {
|
|||
return m * val + b;
|
||||
}
|
||||
|
||||
double XRandom (float min, float max) {
|
||||
return (double)rand () / RAND_MAX * (max - min) + min;
|
||||
double XRandom(float min, float max) {
|
||||
return (double)rand() / RAND_MAX * (max - min) + min;
|
||||
}
|
||||
|
||||
double FRandom () {
|
||||
return (double)rand () / RAND_MAX;
|
||||
double FRandom() {
|
||||
return (double)rand() / RAND_MAX;
|
||||
}
|
||||
|
||||
int IRandom (int min, int max) {
|
||||
int IRandom(int min, int max) {
|
||||
return min + rand()%(max-min+1);
|
||||
}
|
||||
|
||||
int ITrunc (int val, int base) {
|
||||
int ITrunc(int val, int base) {
|
||||
return (int)(val / base);
|
||||
}
|
||||
|
||||
int IFrac (int val, int base) {
|
||||
return val - ITrunc (val, base) * base;
|
||||
int IFrac(int val, int base) {
|
||||
return val - ITrunc(val, base) * base;
|
||||
}
|
||||
|
|
|
@ -49,22 +49,22 @@ TVector3d ProjectToPlane(const TVector3d& nml, const TVector3d& v);
|
|||
TVector3d TransformVector(const TMatrix<4, 4>& mat, const TVector3d& v);
|
||||
TVector3d TransformNormal(const TVector3d& n, const TMatrix<4, 4>& mat); // not used ?
|
||||
TVector3d TransformPoint(const TMatrix<4, 4>& mat, const TVector3d& p);
|
||||
bool IntersectPlanes (const TPlane& s1, const TPlane& s2, const TPlane& s3, TVector3d *p);
|
||||
double DistanceToPlane (const TPlane& plane, const TVector3d& pt);
|
||||
bool IntersectPlanes(const TPlane& s1, const TPlane& s2, const TPlane& s3, TVector3d *p);
|
||||
double DistanceToPlane(const TPlane& plane, const TVector3d& pt);
|
||||
|
||||
TMatrix<4, 4> RotateAboutVectorMatrix(const TVector3d& u, double angle);
|
||||
|
||||
TQuaternion MultiplyQuaternions (const TQuaternion& q, const TQuaternion& r);
|
||||
TQuaternion ConjugateQuaternion (const TQuaternion& q);
|
||||
TQuaternion MultiplyQuaternions(const TQuaternion& q, const TQuaternion& r);
|
||||
TQuaternion ConjugateQuaternion(const TQuaternion& q);
|
||||
TMatrix<4, 4> MakeMatrixFromQuaternion(const TQuaternion& q);
|
||||
TQuaternion MakeQuaternionFromMatrix(const TMatrix<4, 4>& mat);
|
||||
TQuaternion MakeRotationQuaternion (const TVector3d& s, const TVector3d& t);
|
||||
TQuaternion InterpolateQuaternions (const TQuaternion& q, TQuaternion r, double t);
|
||||
TVector3d RotateVector (const TQuaternion& q, const TVector3d& v);
|
||||
TQuaternion MakeRotationQuaternion(const TVector3d& s, const TVector3d& t);
|
||||
TQuaternion InterpolateQuaternions(const TQuaternion& q, TQuaternion r, double t);
|
||||
TVector3d RotateVector(const TQuaternion& q, const TVector3d& v);
|
||||
|
||||
bool IntersectPolygon (const TPolygon& p, vector<TVector3d>& v);
|
||||
bool IntersectPolyhedron (TPolyhedron& p);
|
||||
TVector3d MakeNormal (const TPolygon& p, const TVector3d *v);
|
||||
bool IntersectPolygon(const TPolygon& p, vector<TVector3d>& v);
|
||||
bool IntersectPolyhedron(TPolyhedron& p);
|
||||
TVector3d MakeNormal(const TPolygon& p, const TVector3d *v);
|
||||
void TransPolyhedron(const TMatrix<4, 4>& mat, TPolyhedron& ph);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -77,14 +77,14 @@ struct TOdeData {
|
|||
double h;
|
||||
};
|
||||
|
||||
typedef int (*PNumEstimates) ();
|
||||
typedef void (*PInitOdeData) (TOdeData *, double init_val, double h);
|
||||
typedef double (*PNextTime) (TOdeData *, int step);
|
||||
typedef double (*PNextValue) (TOdeData *, int step);
|
||||
typedef void (*PUpdateEstimate) (TOdeData *, int step, double val);
|
||||
typedef double (*PFinalEstimate) (TOdeData *);
|
||||
typedef double (*PEstimateError) (TOdeData *);
|
||||
typedef double (*PTimestepExponent) ();
|
||||
typedef int (*PNumEstimates)();
|
||||
typedef void (*PInitOdeData)(TOdeData *, double init_val, double h);
|
||||
typedef double(*PNextTime)(TOdeData *, int step);
|
||||
typedef double(*PNextValue)(TOdeData *, int step);
|
||||
typedef void (*PUpdateEstimate)(TOdeData *, int step, double val);
|
||||
typedef double(*PFinalEstimate)(TOdeData *);
|
||||
typedef double(*PEstimateError)(TOdeData *);
|
||||
typedef double(*PTimestepExponent)();
|
||||
|
||||
struct TOdeSolver {
|
||||
PNumEstimates NumEstimates;
|
||||
|
@ -102,13 +102,13 @@ struct TOdeSolver {
|
|||
// special
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
int Gauss (double *matrix, int n, double *soln);
|
||||
double LinearInterp (const double x[], const double y[], double val, int n);
|
||||
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 FRandom ();
|
||||
int IRandom (int min, int max);
|
||||
int ITrunc (int val, int base);
|
||||
int IFrac (int val, int base);
|
||||
double XRandom(float min, float max);
|
||||
double FRandom();
|
||||
int IRandom(int min, int max);
|
||||
int ITrunc(int val, int base);
|
||||
int IFrac(int val, int base);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -39,10 +39,10 @@ static TUpDown* avatar;
|
|||
static TWidget* textbuttons[2];
|
||||
static TTextField* textfield;
|
||||
|
||||
void QuitAndAddPlayer () {
|
||||
void QuitAndAddPlayer() {
|
||||
if (textfield->Text().getSize() > 0)
|
||||
Players.AddPlayer (textfield->Text(), Players.GetDirectAvatarName(avatar->GetValue()));
|
||||
State::manager.RequestEnterState (Regist);
|
||||
Players.AddPlayer(textfield->Text(), Players.GetDirectAvatarName(avatar->GetValue()));
|
||||
State::manager.RequestEnterState(Regist);
|
||||
}
|
||||
|
||||
void CNewPlayer::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
|
@ -66,46 +66,46 @@ void CNewPlayer::TextEntered(char text) {
|
|||
TextEnterGUI(text);
|
||||
}
|
||||
|
||||
void CNewPlayer::Mouse (int button, int state, int x, int y) {
|
||||
void CNewPlayer::Mouse(int button, int state, int x, int y) {
|
||||
if (state == 1) {
|
||||
TWidget* clicked = ClickGUI(x, y);
|
||||
|
||||
if (clicked == textbuttons[0])
|
||||
State::manager.RequestEnterState (Regist);
|
||||
State::manager.RequestEnterState(Regist);
|
||||
else if (clicked == textbuttons[1])
|
||||
QuitAndAddPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
void CNewPlayer::Motion (int x, int y) {
|
||||
void CNewPlayer::Motion(int x, int y) {
|
||||
MouseMoveGUI(x, y);
|
||||
|
||||
if (param.ui_snow) push_ui_snow (cursor_pos);
|
||||
if (param.ui_snow) push_ui_snow(cursor_pos);
|
||||
}
|
||||
|
||||
static int prevleft, prevtop, prevwidth;
|
||||
|
||||
void CNewPlayer::Enter() {
|
||||
Winsys.KeyRepeat (true);
|
||||
Winsys.ShowCursor (!param.ice_cursor);
|
||||
Winsys.KeyRepeat(true);
|
||||
Winsys.ShowCursor(!param.ice_cursor);
|
||||
Music.Play(param.menu_music, true);
|
||||
|
||||
int framewidth = 400 * Winsys.scale;
|
||||
int frameheight = 50 * Winsys.scale;
|
||||
int frametop = AutoYPosN (38);
|
||||
int frametop = AutoYPosN(38);
|
||||
TArea area = AutoAreaN(30, 80, framewidth);
|
||||
int prevoffs = 80;
|
||||
prevleft = area.left + prevoffs;
|
||||
prevtop = AutoYPosN (52);
|
||||
prevtop = AutoYPosN(52);
|
||||
prevwidth = 75 * Winsys.scale;
|
||||
|
||||
ResetGUI();
|
||||
|
||||
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));
|
||||
textbuttons[1] = AddTextButton (Trans.Text(15), area.right-len-50, AutoYPosN (70), siz);
|
||||
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));
|
||||
textbuttons[1] = AddTextButton(Trans.Text(15), area.right-len-50, AutoYPosN(70), siz);
|
||||
|
||||
textfield = AddTextField(emptyString, area.left, frametop, framewidth, frameheight);
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ void CNewPlayer::Loop(double timestep) {
|
|||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow (timestep);
|
||||
update_ui_snow(timestep);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
|
@ -128,9 +128,9 @@ void CNewPlayer::Loop(double timestep) {
|
|||
|
||||
DrawGUIBackground(Winsys.scale);
|
||||
|
||||
FT.SetColor (colWhite);
|
||||
FT.AutoSizeN (4);
|
||||
FT.DrawString (CENTER, AutoYPosN (30), Trans.Text(66));
|
||||
FT.SetColor(colWhite);
|
||||
FT.AutoSizeN(4);
|
||||
FT.DrawString(CENTER, AutoYPosN(30), Trans.Text(66));
|
||||
|
||||
if (avatar->focussed()) col = colDYell;
|
||||
else col = colWhite;
|
||||
|
|
396
src/ogl.cpp
396
src/ogl.cpp
|
@ -47,7 +47,7 @@ void check_gl_error() {
|
|||
GLenum error = glGetError();
|
||||
if (error != GL_NO_ERROR) {
|
||||
const char* errstr = (const char*)gluErrorString(error);
|
||||
Message ("OpenGL Error: ", errstr ? errstr : "");
|
||||
Message("OpenGL Error: ", errstr ? errstr : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ PFNGLUNLOCKARRAYSEXTPROC glUnlockArraysEXT_p = NULL;
|
|||
|
||||
|
||||
typedef void (*(*get_gl_proc_fptr_t)(const GLubyte *))();
|
||||
void InitOpenglExtensions () {
|
||||
void InitOpenglExtensions() {
|
||||
get_gl_proc_fptr_t get_gl_proc;
|
||||
#ifdef OS_WIN32_MSC
|
||||
get_gl_proc = (get_gl_proc_fptr_t)wglGetProcAddress;
|
||||
|
@ -72,24 +72,24 @@ void InitOpenglExtensions () {
|
|||
if (glLockArraysEXT_p != NULL && glUnlockArraysEXT_p != NULL) {
|
||||
|
||||
} else {
|
||||
Message ("GL_EXT_compiled_vertex_array extension NOT supported");
|
||||
Message("GL_EXT_compiled_vertex_array extension NOT supported");
|
||||
glLockArraysEXT_p = NULL;
|
||||
glUnlockArraysEXT_p = NULL;
|
||||
}
|
||||
} else {
|
||||
Message ("No function available for obtaining GL proc addresses");
|
||||
Message("No function available for obtaining GL proc addresses");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PrintGLInfo () {
|
||||
Message ("Gl vendor: ", (char*)glGetString (GL_VENDOR));
|
||||
Message ("Gl renderer: ", (char*)glGetString (GL_RENDERER));
|
||||
Message ("Gl version: ", (char*)glGetString (GL_VERSION));
|
||||
string extensions = (char*)glGetString (GL_EXTENSIONS);
|
||||
Message ("");
|
||||
Message ("Gl extensions:");
|
||||
Message ("");
|
||||
void PrintGLInfo() {
|
||||
Message("Gl vendor: ", (char*)glGetString(GL_VENDOR));
|
||||
Message("Gl renderer: ", (char*)glGetString(GL_RENDERER));
|
||||
Message("Gl version: ", (char*)glGetString(GL_VERSION));
|
||||
string extensions = (char*)glGetString(GL_EXTENSIONS);
|
||||
Message("");
|
||||
Message("Gl extensions:");
|
||||
Message("");
|
||||
|
||||
size_t oldpos = 0;
|
||||
size_t pos;
|
||||
|
@ -100,32 +100,32 @@ void PrintGLInfo () {
|
|||
}
|
||||
Message(extensions.substr(oldpos));
|
||||
|
||||
Message ("");
|
||||
Message("");
|
||||
for (int i=0; i<(int)(sizeof(gl_values)/sizeof(gl_values[0])); i++) {
|
||||
switch (gl_values[i].type) {
|
||||
case GL_INT: {
|
||||
GLint int_val;
|
||||
glGetIntegerv (gl_values[i].value, &int_val);
|
||||
string ss = Int_StrN (int_val);
|
||||
Message (gl_values[i].name, ss);
|
||||
glGetIntegerv(gl_values[i].value, &int_val);
|
||||
string ss = Int_StrN(int_val);
|
||||
Message(gl_values[i].name, ss);
|
||||
break;
|
||||
}
|
||||
case GL_FLOAT: {
|
||||
GLfloat float_val;
|
||||
glGetFloatv (gl_values[i].value, &float_val);
|
||||
string ss = Float_StrN (float_val, 2);
|
||||
Message (gl_values[i].name, ss);
|
||||
glGetFloatv(gl_values[i].value, &float_val);
|
||||
string ss = Float_StrN(float_val, 2);
|
||||
Message(gl_values[i].name, ss);
|
||||
break;
|
||||
}
|
||||
case GL_UNSIGNED_BYTE: {
|
||||
GLboolean boolean_val;
|
||||
glGetBooleanv (gl_values[i].value, &boolean_val);
|
||||
string ss = Int_StrN (boolean_val);
|
||||
Message (gl_values[i].name, ss);
|
||||
glGetBooleanv(gl_values[i].value, &boolean_val);
|
||||
string ss = Int_StrN(boolean_val);
|
||||
Message(gl_values[i].name, ss);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Message ("");
|
||||
Message("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ void set_material(const sf::Color& diffuse_colour, const sf::Color& specular_col
|
|||
static_cast<GLfloat>(diffuse_colour.b) / 255.f,
|
||||
static_cast<GLfloat>(diffuse_colour.a) / 255.f
|
||||
};
|
||||
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff);
|
||||
|
||||
GLfloat mat_specular[4] = {
|
||||
static_cast<GLfloat>(specular_colour.r) / 255.f,
|
||||
|
@ -145,45 +145,45 @@ void set_material(const sf::Color& diffuse_colour, const sf::Color& specular_col
|
|||
static_cast<GLfloat>(specular_colour.b) / 255.f,
|
||||
static_cast<GLfloat>(specular_colour.a) / 255.f
|
||||
};
|
||||
glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
|
||||
|
||||
glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, specular_exp);
|
||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, specular_exp);
|
||||
|
||||
glColor(diffuse_colour);
|
||||
}
|
||||
void ClearRenderContext () {
|
||||
glDepthMask (GL_TRUE);
|
||||
void ClearRenderContext() {
|
||||
glDepthMask(GL_TRUE);
|
||||
glClearColor(colBackgr.r / 255.f, colBackgr.g / 255.f, colBackgr.b / 255.f, colBackgr.a / 255.f);
|
||||
glClearStencil (0);
|
||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glClearStencil(0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void ClearRenderContext(const sf::Color& col) {
|
||||
glDepthMask (GL_TRUE);
|
||||
glDepthMask(GL_TRUE);
|
||||
glClearColor(col.r / 255.f, col.g / 255.f, col.b / 255.f, col.a / 255.f);
|
||||
glClearStencil (0);
|
||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glClearStencil(0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void Setup2dScene () {
|
||||
void Setup2dScene() {
|
||||
static const float offset = 0.f;
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity ();
|
||||
glOrtho (0, Winsys.resolution.width, 0, Winsys.resolution.height, -1.0, 1.0);
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glLoadIdentity ();
|
||||
glTranslatef (offset, offset, -1.0);
|
||||
glColor4f (1.0, 1.0, 1.0, 1.0);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, Winsys.resolution.width, 0, Winsys.resolution.height, -1.0, 1.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(offset, offset, -1.0);
|
||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
void Reshape (int w, int h) {
|
||||
glViewport (0, 0, (GLint) w, (GLint) h );
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity ();
|
||||
void Reshape(int w, int h) {
|
||||
glViewport(0, 0, (GLint) w, (GLint) h);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
double far_clip_dist = param.forward_clip_distance + FAR_CLIP_FUDGE_AMOUNT;
|
||||
gluPerspective (param.fov, (double)w/h, NEAR_CLIP_DIST, far_clip_dist );
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
gluPerspective(param.fov, (double)w/h, NEAR_CLIP_DIST, far_clip_dist);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
// ====================================================================
|
||||
// GL options
|
||||
|
@ -198,7 +198,7 @@ void ResetRenderMode() {
|
|||
currentMode = RM_UNINITIALIZED;
|
||||
}
|
||||
|
||||
void set_gl_options (TRenderMode mode) {
|
||||
void set_gl_options(TRenderMode mode) {
|
||||
if (currentMode == GUI)
|
||||
Winsys.endSFML();
|
||||
|
||||
|
@ -209,194 +209,194 @@ void set_gl_options (TRenderMode mode) {
|
|||
break;
|
||||
|
||||
case GAUGE_BARS:
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glDisable (GL_LIGHTING);
|
||||
glDisable (GL_NORMALIZE);
|
||||
glDisable (GL_ALPHA_TEST);
|
||||
glEnable (GL_BLEND);
|
||||
glDisable (GL_STENCIL_TEST);
|
||||
glEnable (GL_TEXTURE_GEN_S);
|
||||
glEnable (GL_TEXTURE_GEN_T);
|
||||
glDisable (GL_COLOR_MATERIAL);
|
||||
glDepthMask (GL_TRUE);
|
||||
glShadeModel (GL_SMOOTH);
|
||||
glDepthFunc (GL_LESS);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_NORMALIZE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
glDepthMask(GL_TRUE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
break;
|
||||
|
||||
case TEXFONT:
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glDisable (GL_LIGHTING);
|
||||
glDisable (GL_NORMALIZE);
|
||||
glDisable (GL_ALPHA_TEST);
|
||||
glEnable (GL_BLEND);
|
||||
glDisable (GL_STENCIL_TEST);
|
||||
glDisable (GL_TEXTURE_GEN_S);
|
||||
glDisable (GL_TEXTURE_GEN_T);
|
||||
glDisable (GL_COLOR_MATERIAL);
|
||||
glDepthMask (GL_TRUE);
|
||||
glShadeModel (GL_SMOOTH);
|
||||
glDepthFunc (GL_LESS);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_NORMALIZE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
glDepthMask(GL_TRUE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDepthFunc(GL_LESS);
|
||||
break;
|
||||
|
||||
case COURSE:
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glEnable (GL_CULL_FACE);
|
||||
glEnable (GL_LIGHTING);
|
||||
glDisable (GL_NORMALIZE);
|
||||
glDisable (GL_ALPHA_TEST);
|
||||
glEnable (GL_BLEND);
|
||||
glDisable (GL_STENCIL_TEST);
|
||||
glEnable (GL_TEXTURE_GEN_S);
|
||||
glEnable (GL_TEXTURE_GEN_T);
|
||||
glEnable (GL_COLOR_MATERIAL);
|
||||
glDepthMask (GL_TRUE);
|
||||
glShadeModel (GL_SMOOTH);
|
||||
glDepthFunc (GL_LEQUAL);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glDisable(GL_NORMALIZE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glDepthMask(GL_TRUE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
|
||||
break;
|
||||
|
||||
case TREES:
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glEnable (GL_LIGHTING);
|
||||
glDisable (GL_NORMALIZE);
|
||||
glEnable (GL_ALPHA_TEST);
|
||||
glEnable (GL_BLEND);
|
||||
glDisable (GL_STENCIL_TEST);
|
||||
glDisable (GL_TEXTURE_GEN_S);
|
||||
glDisable (GL_TEXTURE_GEN_T);
|
||||
glDisable (GL_COLOR_MATERIAL);
|
||||
glDepthMask (GL_TRUE);
|
||||
glShadeModel (GL_SMOOTH);
|
||||
glDepthFunc (GL_LESS);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glDisable(GL_NORMALIZE);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
glDepthMask(GL_TRUE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
glAlphaFunc (GL_GEQUAL, 0.5);
|
||||
glAlphaFunc(GL_GEQUAL, 0.5);
|
||||
break;
|
||||
|
||||
case PARTICLES:
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glDisable (GL_LIGHTING);
|
||||
glDisable (GL_NORMALIZE);
|
||||
glEnable (GL_ALPHA_TEST);
|
||||
glEnable (GL_BLEND);
|
||||
glDisable (GL_STENCIL_TEST);
|
||||
glDisable (GL_TEXTURE_GEN_S);
|
||||
glDisable (GL_TEXTURE_GEN_T);
|
||||
glDisable (GL_COLOR_MATERIAL);
|
||||
glDepthMask (GL_TRUE);
|
||||
glShadeModel (GL_SMOOTH);
|
||||
glDepthFunc (GL_LESS);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_NORMALIZE);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
glDepthMask(GL_TRUE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
glAlphaFunc (GL_GEQUAL, 0.5);
|
||||
glAlphaFunc(GL_GEQUAL, 0.5);
|
||||
break;
|
||||
|
||||
case SKY:
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glDisable (GL_LIGHTING);
|
||||
glDisable (GL_NORMALIZE);
|
||||
glDisable (GL_ALPHA_TEST);
|
||||
glEnable (GL_BLEND);
|
||||
glDisable (GL_STENCIL_TEST);
|
||||
glDisable (GL_TEXTURE_GEN_S);
|
||||
glDisable (GL_TEXTURE_GEN_T);
|
||||
glDisable (GL_COLOR_MATERIAL);
|
||||
glDepthMask (GL_FALSE);
|
||||
glShadeModel (GL_SMOOTH);
|
||||
glDepthFunc (GL_LESS);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_NORMALIZE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
glDepthMask(GL_FALSE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDepthFunc(GL_LESS);
|
||||
break;
|
||||
|
||||
case FOG_PLANE:
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glDisable (GL_LIGHTING);
|
||||
glDisable (GL_NORMALIZE);
|
||||
glDisable (GL_ALPHA_TEST);
|
||||
glEnable (GL_BLEND);
|
||||
glDisable (GL_STENCIL_TEST);
|
||||
glDisable (GL_TEXTURE_GEN_S);
|
||||
glDisable (GL_TEXTURE_GEN_T);
|
||||
glDisable (GL_COLOR_MATERIAL);
|
||||
glDepthMask (GL_TRUE);
|
||||
glShadeModel (GL_SMOOTH);
|
||||
glDepthFunc (GL_LESS);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_NORMALIZE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
glDepthMask(GL_TRUE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDepthFunc(GL_LESS);
|
||||
break;
|
||||
|
||||
case TUX:
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glEnable (GL_CULL_FACE);
|
||||
glEnable (GL_LIGHTING);
|
||||
glEnable (GL_NORMALIZE);
|
||||
glDisable (GL_ALPHA_TEST);
|
||||
glEnable (GL_BLEND);
|
||||
glDisable (GL_STENCIL_TEST);
|
||||
glDisable (GL_TEXTURE_GEN_S);
|
||||
glDisable (GL_TEXTURE_GEN_T);
|
||||
glDisable (GL_COLOR_MATERIAL);
|
||||
glDepthMask (GL_TRUE);
|
||||
glShadeModel (GL_SMOOTH);
|
||||
glDepthFunc (GL_LESS);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_NORMALIZE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
glDepthMask(GL_TRUE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDepthFunc(GL_LESS);
|
||||
break;
|
||||
|
||||
case TUX_SHADOW:
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDisable (GL_LIGHTING);
|
||||
glDisable (GL_NORMALIZE);
|
||||
glDisable (GL_ALPHA_TEST);
|
||||
glEnable (GL_BLEND);
|
||||
glDisable (GL_COLOR_MATERIAL);
|
||||
glShadeModel (GL_SMOOTH);
|
||||
glDepthFunc (GL_LESS);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_NORMALIZE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDepthFunc(GL_LESS);
|
||||
#ifdef USE_STENCIL_BUFFER
|
||||
glDisable (GL_CULL_FACE);
|
||||
glEnable (GL_STENCIL_TEST);
|
||||
glDepthMask (GL_FALSE);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
glStencilFunc (GL_EQUAL, 0, ~0);
|
||||
glStencilOp (GL_KEEP, GL_KEEP, GL_INCR);
|
||||
glStencilFunc(GL_EQUAL, 0, ~0);
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
|
||||
#else
|
||||
glEnable (GL_CULL_FACE);
|
||||
glDisable (GL_STENCIL_TEST);
|
||||
glDepthMask (GL_TRUE);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case TRACK_MARKS:
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glEnable (GL_LIGHTING);
|
||||
glDisable (GL_NORMALIZE);
|
||||
glDisable (GL_ALPHA_TEST);
|
||||
glEnable (GL_BLEND);
|
||||
glDisable (GL_STENCIL_TEST);
|
||||
glDisable (GL_COLOR_MATERIAL);
|
||||
glDisable (GL_TEXTURE_GEN_S);
|
||||
glDisable (GL_TEXTURE_GEN_T);
|
||||
glDepthMask (GL_FALSE);
|
||||
glShadeModel (GL_SMOOTH);
|
||||
glDepthFunc (GL_LEQUAL);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glDisable(GL_NORMALIZE);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
glDepthMask(GL_FALSE);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
break;
|
||||
|
||||
default:
|
||||
Message ("not a valid render mode");
|
||||
Message("not a valid render mode");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ struct ScopedRenderMode {
|
|||
void ClearRenderContext();
|
||||
void ClearRenderContext(const sf::Color& col);
|
||||
void Setup2dScene();
|
||||
void Reshape (int w, int h);
|
||||
void Reshape(int w, int h);
|
||||
|
||||
void glColor(const sf::Color& col);
|
||||
void glColor(const sf::Color& col, uint8_t alpha);
|
||||
|
|
|
@ -37,7 +37,7 @@ static const TLight light = {
|
|||
};
|
||||
|
||||
|
||||
void SetTestLight () {
|
||||
void SetTestLight() {
|
||||
light.Enable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
@ -53,17 +53,17 @@ void COglTest::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, in
|
|||
}
|
||||
|
||||
void COglTest::Enter() {
|
||||
Winsys.KeyRepeat (true);
|
||||
Winsys.KeyRepeat(true);
|
||||
}
|
||||
|
||||
void COglTest::Loop(double timestep) {
|
||||
// ------------- 3d scenery ---------------------------------------
|
||||
ScopedRenderMode rm(TUX);
|
||||
ClearRenderContext (colDDBackgr);
|
||||
ClearRenderContext(colDDBackgr);
|
||||
|
||||
glLoadIdentity ();
|
||||
glPushMatrix ();
|
||||
SetTestLight ();
|
||||
glLoadIdentity();
|
||||
glPushMatrix();
|
||||
SetTestLight();
|
||||
|
||||
/*
|
||||
glTranslatef (xposition, yposition, zposition);
|
||||
|
@ -71,13 +71,13 @@ void COglTest::Loop(double timestep) {
|
|||
glRotatef (yrotation, 0, 1, 0);
|
||||
glRotatef (zrotation, 0, 0, 1);
|
||||
*/
|
||||
glPopMatrix ();
|
||||
glPopMatrix();
|
||||
|
||||
// --------------- 2d screen --------------------------------------
|
||||
Setup2dScene ();
|
||||
Setup2dScene();
|
||||
ScopedRenderMode rm2(TEXFONT);
|
||||
FT.SetProps("bold", 24, colWhite);
|
||||
FT.DrawString (CENTER, 10, "Test screen");
|
||||
Reshape (Winsys.resolution.width, Winsys.resolution.height);
|
||||
Winsys.SwapBuffers ();
|
||||
FT.DrawString(CENTER, 10, "Test screen");
|
||||
Reshape(Winsys.resolution.width, Winsys.resolution.height);
|
||||
Winsys.SwapBuffers();
|
||||
}
|
||||
|
|
|
@ -110,19 +110,19 @@ void TGuiParticle::Update(float time_step, float push_timestep, const TVector2d&
|
|||
if (push_timestep > 0) {
|
||||
f.x = PUSH_FACTOR * push_vector.x / push_timestep;
|
||||
f.y = PUSH_FACTOR * push_vector.y / push_timestep;
|
||||
f.x = clamp (-MAX_PUSH_FORCE, f.x, MAX_PUSH_FORCE);
|
||||
f.y = clamp (-MAX_PUSH_FORCE, f.y, MAX_PUSH_FORCE);
|
||||
f.x = clamp(-MAX_PUSH_FORCE, f.x, MAX_PUSH_FORCE);
|
||||
f.y = clamp(-MAX_PUSH_FORCE, f.y, MAX_PUSH_FORCE);
|
||||
f.x *= 1.0/(PUSH_DIST_DECAY*dist_from_push + 1) *
|
||||
size/ PARTICLE_SIZE_RANGE;
|
||||
f.y *= 1.0/(PUSH_DIST_DECAY*dist_from_push + 1) *
|
||||
size / PARTICLE_SIZE_RANGE;
|
||||
}
|
||||
|
||||
vel.x += (f.x - vel.x * AIR_DRAG) * time_step;
|
||||
vel.y += (f.y + GRAVITY_FACTOR - vel.y * AIR_DRAG) * time_step;
|
||||
vel.x += (f.x - vel.x * AIR_DRAG) * time_step;
|
||||
vel.y += (f.y + GRAVITY_FACTOR - vel.y * AIR_DRAG) * time_step;
|
||||
|
||||
x += vel.x * time_step * (size / PARTICLE_SIZE_RANGE);
|
||||
y += vel.y * time_step * (size / PARTICLE_SIZE_RANGE);
|
||||
x += vel.x * time_step * (size / PARTICLE_SIZE_RANGE);
|
||||
y += vel.y * time_step * (size / PARTICLE_SIZE_RANGE);
|
||||
|
||||
x = clamp(-0.05, x, 1);
|
||||
sprite.setPosition(x*Winsys.resolution.width, y*Winsys.resolution.height);
|
||||
|
@ -189,7 +189,7 @@ void draw_ui_snow() {
|
|||
}
|
||||
}
|
||||
|
||||
void push_ui_snow (const TVector2i& pos) {
|
||||
void push_ui_snow(const TVector2i& pos) {
|
||||
push_position = TVector2d((pos.x) / static_cast<float>(Winsys.resolution.width), (pos.y) / static_cast<float>(Winsys.resolution.height));
|
||||
if (!push_position_initialized) last_push_position = push_position;
|
||||
push_position_initialized = true;
|
||||
|
@ -262,13 +262,13 @@ void Particle::Draw(const CControl* ctrl) const {
|
|||
}
|
||||
};
|
||||
|
||||
const sf::Color& particle_colour = Env.ParticleColor ();
|
||||
const sf::Color& particle_colour = Env.ParticleColor();
|
||||
glColor(particle_colour, particle_colour.a * alpha);
|
||||
|
||||
draw_billboard(ctrl, cur_size, cur_size, false, tex_coords[type]);
|
||||
}
|
||||
|
||||
void Particle::draw_billboard (const CControl *ctrl, double width, double height, bool use_world_y_axis, const GLfloat* tex) const {
|
||||
void Particle::draw_billboard(const CControl *ctrl, double width, double height, bool use_world_y_axis, const GLfloat* tex) const {
|
||||
TVector3d x_vec;
|
||||
TVector3d y_vec;
|
||||
TVector3d z_vec;
|
||||
|
@ -279,9 +279,9 @@ void Particle::draw_billboard (const CControl *ctrl, double width, double height
|
|||
|
||||
if (use_world_y_axis) {
|
||||
y_vec = TVector3d(0, 1, 0);
|
||||
x_vec = ProjectToPlane (y_vec, x_vec);
|
||||
x_vec = ProjectToPlane(y_vec, x_vec);
|
||||
x_vec.Norm();
|
||||
z_vec = CrossProduct (x_vec, y_vec);
|
||||
z_vec = CrossProduct(x_vec, y_vec);
|
||||
} else {
|
||||
y_vec.x = ctrl->view_mat[1][0];
|
||||
y_vec.y = ctrl->view_mat[1][1];
|
||||
|
@ -314,11 +314,11 @@ void Particle::draw_billboard (const CControl *ctrl, double width, double height
|
|||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
void create_new_particles (const TVector3d& loc, const TVector3d& vel, int num) {
|
||||
void create_new_particles(const TVector3d& loc, const TVector3d& vel, int num) {
|
||||
double speed = vel.Length();
|
||||
|
||||
if (particles.size() + num > MAX_PARTICLES) {
|
||||
Message ("maximum number of particles exceeded");
|
||||
Message("maximum number of particles exceeded");
|
||||
}
|
||||
for (int i=0; i<num; i++) {
|
||||
particles.push_back(Particle());
|
||||
|
@ -337,7 +337,7 @@ void create_new_particles (const TVector3d& loc, const TVector3d& vel, int num)
|
|||
VARIANCE_FACTOR * (FRandom() - 0.5) * speed);
|
||||
}
|
||||
}
|
||||
void update_particles (double time_step) {
|
||||
void update_particles(double time_step) {
|
||||
for (list<Particle>::iterator p = particles.begin(); p != particles.end();) {
|
||||
p->age += time_step;
|
||||
if (p->age < 0) {
|
||||
|
@ -346,7 +346,7 @@ void update_particles (double time_step) {
|
|||
}
|
||||
|
||||
p->pt += time_step * p->vel;
|
||||
double ycoord = Course.FindYCoord (p->pt.x, p->pt.z);
|
||||
double ycoord = Course.FindYCoord(p->pt.x, p->pt.z);
|
||||
if (p->pt.y < ycoord - 3) {p->age = p->death + 1;}
|
||||
if (p->age >= p->death) {
|
||||
p = particles.erase(p);
|
||||
|
@ -359,10 +359,10 @@ void update_particles (double time_step) {
|
|||
++p;
|
||||
}
|
||||
}
|
||||
void draw_particles (const CControl *ctrl) {
|
||||
void draw_particles(const CControl *ctrl) {
|
||||
ScopedRenderMode rm(PARTICLES);
|
||||
Tex.BindTex (SNOW_PART);
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
Tex.BindTex(SNOW_PART);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glColor4f(1.f, 1.f, 1.f, 0.8f);
|
||||
|
||||
for (list<Particle>::const_iterator p = particles.begin(); p != particles.end(); ++p) {
|
||||
|
@ -374,21 +374,21 @@ void clear_particles() {
|
|||
particles.clear();
|
||||
}
|
||||
|
||||
double adjust_particle_count (double particles) {
|
||||
double adjust_particle_count(double particles) {
|
||||
if (particles < 1) {
|
||||
if (((double) rand()) / RAND_MAX < particles) return 1.0;
|
||||
else return 0.0;
|
||||
} else return particles;
|
||||
}
|
||||
|
||||
void generate_particles (const CControl *ctrl, double dtime, const TVector3d& pos, double speed) {
|
||||
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);
|
||||
double surf_y = Course.FindYCoord(pos.x, pos.z);
|
||||
|
||||
int id = Course.GetTerrainIdx (pos.x, pos.z, 0.5);
|
||||
int id = Course.GetTerrainIdx(pos.x, pos.z, 0.5);
|
||||
if (id >= 0 && TerrList[id].particles && pos.y < surf_y) {
|
||||
TVector3d xvec = CrossProduct (ctrl->cdirection, ctrl->plane_nml);
|
||||
TVector3d xvec = CrossProduct(ctrl->cdirection, ctrl->plane_nml);
|
||||
|
||||
TVector3d right_part_pt = pos + TUX_WIDTH/2.0 * xvec;
|
||||
|
||||
|
@ -397,45 +397,45 @@ void generate_particles (const CControl *ctrl, double dtime, const TVector3d& po
|
|||
right_part_pt.y = left_part_pt.y = surf_y;
|
||||
|
||||
double brake_particles = dtime *
|
||||
BRAKE_PARTICLES * (ctrl->is_braking ? 1.0 : 0.0)
|
||||
* min (speed / PARTICLE_SPEED_FACTOR, 1.0);
|
||||
BRAKE_PARTICLES * (ctrl->is_braking ? 1.0 : 0.0)
|
||||
* min(speed / PARTICLE_SPEED_FACTOR, 1.0);
|
||||
double turn_particles = dtime * MAX_TURN_PARTICLES
|
||||
* min (speed / PARTICLE_SPEED_FACTOR, 1.0);
|
||||
* min(speed / PARTICLE_SPEED_FACTOR, 1.0);
|
||||
double roll_particles = dtime * MAX_ROLL_PARTICLES
|
||||
* min (speed / PARTICLE_SPEED_FACTOR, 1.0);
|
||||
* min(speed / PARTICLE_SPEED_FACTOR, 1.0);
|
||||
|
||||
double left_particles = turn_particles *
|
||||
fabs (min(ctrl->turn_fact, 0.)) +
|
||||
fabs(min(ctrl->turn_fact, 0.)) +
|
||||
brake_particles +
|
||||
roll_particles * fabs (min(ctrl->turn_animation, 0.));
|
||||
roll_particles * fabs(min(ctrl->turn_animation, 0.));
|
||||
|
||||
double right_particles = turn_particles *
|
||||
fabs (max(ctrl->turn_fact, 0.)) +
|
||||
fabs(max(ctrl->turn_fact, 0.)) +
|
||||
brake_particles +
|
||||
roll_particles * fabs (max(ctrl->turn_animation, 0.));
|
||||
roll_particles * fabs(max(ctrl->turn_animation, 0.));
|
||||
|
||||
left_particles = adjust_particle_count (left_particles);
|
||||
right_particles = adjust_particle_count (right_particles);
|
||||
left_particles = adjust_particle_count(left_particles);
|
||||
right_particles = adjust_particle_count(right_particles);
|
||||
|
||||
TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix(
|
||||
ctrl->cdirection,
|
||||
max (-MAX_PARTICLE_ANGLE,
|
||||
-MAX_PARTICLE_ANGLE * speed / MAX_PARTICLE_ANGLE_SPEED));
|
||||
TVector3d left_part_vel = TransformVector (rot_mat, ctrl->plane_nml);
|
||||
max(-MAX_PARTICLE_ANGLE,
|
||||
-MAX_PARTICLE_ANGLE * speed / MAX_PARTICLE_ANGLE_SPEED));
|
||||
TVector3d left_part_vel = TransformVector(rot_mat, ctrl->plane_nml);
|
||||
left_part_vel *= min(MAX_PARTICLE_SPEED, speed * PARTICLE_SPEED_MULTIPLIER);
|
||||
|
||||
rot_mat = RotateAboutVectorMatrix(
|
||||
ctrl->cdirection,
|
||||
min (MAX_PARTICLE_ANGLE,
|
||||
MAX_PARTICLE_ANGLE * speed / MAX_PARTICLE_ANGLE_SPEED));
|
||||
TVector3d right_part_vel = TransformVector (rot_mat, ctrl->plane_nml);
|
||||
min(MAX_PARTICLE_ANGLE,
|
||||
MAX_PARTICLE_ANGLE * speed / MAX_PARTICLE_ANGLE_SPEED));
|
||||
TVector3d right_part_vel = TransformVector(rot_mat, ctrl->plane_nml);
|
||||
right_part_vel *= min(MAX_PARTICLE_SPEED, speed * PARTICLE_SPEED_MULTIPLIER);
|
||||
|
||||
|
||||
create_new_particles (left_part_pt, left_part_vel,
|
||||
(int)left_particles);
|
||||
create_new_particles (right_part_pt, right_part_vel,
|
||||
(int)right_particles);
|
||||
create_new_particles(left_part_pt, left_part_vel,
|
||||
(int)left_particles);
|
||||
create_new_particles(right_part_pt, right_part_vel,
|
||||
(int)right_particles);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -449,10 +449,10 @@ static CFlakes Flakes;
|
|||
|
||||
|
||||
void TFlake::Draw(const TPlane& lp, const TPlane& rp, bool rotate_flake, float dir_angle) const {
|
||||
if ((DistanceToPlane (lp, pt) < 0) && (DistanceToPlane (rp, pt) < 0)) {
|
||||
if ((DistanceToPlane(lp, pt) < 0) && (DistanceToPlane(rp, pt) < 0)) {
|
||||
glPushMatrix();
|
||||
glTranslate(pt);
|
||||
if (rotate_flake) glRotatef (dir_angle, 0, 1, 0);
|
||||
if (rotate_flake) glRotatef(dir_angle, 0, 1, 0);
|
||||
|
||||
const GLfloat vtx[] = {
|
||||
0, 0, 0,
|
||||
|
@ -469,7 +469,7 @@ void TFlake::Draw(const TPlane& lp, const TPlane& rp, bool rotate_flake, float d
|
|||
}
|
||||
|
||||
|
||||
TFlakeArea::TFlakeArea (
|
||||
TFlakeArea::TFlakeArea(
|
||||
int num_flakes,
|
||||
float _xrange,
|
||||
float _ytop,
|
||||
|
@ -493,15 +493,15 @@ TFlakeArea::TFlakeArea (
|
|||
flakes.resize(num_flakes);
|
||||
}
|
||||
|
||||
void TFlakeArea::Draw (const CControl *ctrl) const {
|
||||
void TFlakeArea::Draw(const CControl *ctrl) const {
|
||||
if (g_game.snow_id < 1) return;
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
ScopedRenderMode rm(PARTICLES);
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
Tex.BindTex(SNOW_PART);
|
||||
const sf::Color& particle_colour = Env.ParticleColor();
|
||||
glColor(particle_colour);
|
||||
|
@ -537,16 +537,16 @@ void TFlakeArea::Update(float timestep, float xcoeff, float ycoeff, float zcoeff
|
|||
}
|
||||
}
|
||||
|
||||
void CFlakes::Reset () {
|
||||
void CFlakes::Reset() {
|
||||
areas.clear();
|
||||
}
|
||||
|
||||
void CFlakes::MakeSnowFlake (size_t ar, size_t i) {
|
||||
areas[ar].flakes[i].pt.x = XRandom (areas[ar].left, areas[ar].right);
|
||||
areas[ar].flakes[i].pt.y = -XRandom (areas[ar].top, areas[ar].bottom);
|
||||
areas[ar].flakes[i].pt.z = areas[ar].back - FRandom () * (areas[ar].back - areas[ar].front);
|
||||
void CFlakes::MakeSnowFlake(size_t ar, size_t i) {
|
||||
areas[ar].flakes[i].pt.x = XRandom(areas[ar].left, areas[ar].right);
|
||||
areas[ar].flakes[i].pt.y = -XRandom(areas[ar].top, areas[ar].bottom);
|
||||
areas[ar].flakes[i].pt.z = areas[ar].back - FRandom() * (areas[ar].back - areas[ar].front);
|
||||
|
||||
areas[ar].flakes[i].size = XRandom (areas[ar].minSize, areas[ar].maxSize);
|
||||
areas[ar].flakes[i].size = XRandom(areas[ar].minSize, areas[ar].maxSize);
|
||||
areas[ar].flakes[i].vel.x = 0;
|
||||
areas[ar].flakes[i].vel.z = 0;
|
||||
areas[ar].flakes[i].vel.y = -areas[ar].flakes[i].size * areas[ar].speed;
|
||||
|
@ -580,15 +580,15 @@ void CFlakes::MakeSnowFlake (size_t ar, size_t i) {
|
|||
areas[ar].flakes[i].tex = tex_coords[type];
|
||||
}
|
||||
|
||||
void CFlakes::GenerateSnowFlakes (const CControl *ctrl) {
|
||||
void CFlakes::GenerateSnowFlakes(const CControl *ctrl) {
|
||||
if (g_game.snow_id < 1) return;
|
||||
snow_lastpos = ctrl->cpos;
|
||||
for (size_t ar=0; ar<areas.size(); ar++) {
|
||||
for (size_t i=0; i<areas[ar].flakes.size(); i++) MakeSnowFlake (ar, i);
|
||||
for (size_t i=0; i<areas[ar].flakes.size(); i++) MakeSnowFlake(ar, i);
|
||||
}
|
||||
}
|
||||
|
||||
void CFlakes::UpdateAreas (const CControl *ctrl) {
|
||||
void CFlakes::UpdateAreas(const CControl *ctrl) {
|
||||
for (size_t ar=0; ar<areas.size(); ar++) {
|
||||
areas[ar].left = ctrl->cpos.x - areas[ar].xrange / 2;
|
||||
areas[ar].right = areas[ar].left + areas[ar].xrange;
|
||||
|
@ -602,8 +602,8 @@ void CFlakes::UpdateAreas (const CControl *ctrl) {
|
|||
#define YDRIFT 0.8
|
||||
#define ZDRIFT 0.6
|
||||
|
||||
void CFlakes::Init (int grade, const CControl *ctrl) {
|
||||
Reset ();
|
||||
void CFlakes::Init(int grade, const CControl *ctrl) {
|
||||
Reset();
|
||||
switch (grade) {
|
||||
case 1:
|
||||
// areas.push_back(TFlakeArea(400, 5, 4, 4, -2, 4, 0.01, 0.02, 5, true));
|
||||
|
@ -642,15 +642,15 @@ void CFlakes::Init (int grade, const CControl *ctrl) {
|
|||
break;
|
||||
}
|
||||
|
||||
UpdateAreas (ctrl);
|
||||
GenerateSnowFlakes (ctrl);
|
||||
UpdateAreas(ctrl);
|
||||
GenerateSnowFlakes(ctrl);
|
||||
}
|
||||
|
||||
void CFlakes::Update (double timestep, const CControl *ctrl) {
|
||||
void CFlakes::Update(double timestep, const CControl *ctrl) {
|
||||
if (g_game.snow_id < 1)
|
||||
return;
|
||||
|
||||
UpdateAreas (ctrl);
|
||||
UpdateAreas(ctrl);
|
||||
|
||||
float zdiff = ctrl->cpos.z - snow_lastpos.z;
|
||||
float ydiff = 0.f;
|
||||
|
@ -658,7 +658,7 @@ void CFlakes::Update (double timestep, const CControl *ctrl) {
|
|||
ydiff = ctrl->cpos.y - snow_lastpos.y;
|
||||
}
|
||||
|
||||
TVector3d winddrift = SNOW_WIND_DRIFT * Wind.WindDrift ();
|
||||
TVector3d winddrift = SNOW_WIND_DRIFT * Wind.WindDrift();
|
||||
float xcoeff = winddrift.x * timestep;
|
||||
float ycoeff = (ydiff * YDRIFT) + (winddrift.z * timestep);
|
||||
float zcoeff = (zdiff * ZDRIFT) + (winddrift.z * timestep);
|
||||
|
@ -669,7 +669,7 @@ void CFlakes::Update (double timestep, const CControl *ctrl) {
|
|||
snow_lastpos = ctrl->cpos;
|
||||
}
|
||||
|
||||
void CFlakes::Draw (const CControl *ctrl) const {
|
||||
void CFlakes::Draw(const CControl *ctrl) const {
|
||||
for (size_t ar=0; ar<areas.size(); ar++)
|
||||
areas[ar].Draw(ctrl);
|
||||
}
|
||||
|
@ -693,17 +693,17 @@ struct TChange {
|
|||
|
||||
TChange changes[NUM_CHANGES];
|
||||
|
||||
void InitChanges () {
|
||||
void InitChanges() {
|
||||
for (int i=0; i<NUM_CHANGES; i++) {
|
||||
changes[i].min = XRandom (-0.15, -0.05);
|
||||
changes[i].max = XRandom (0.05, 0.15);
|
||||
changes[i].min = XRandom(-0.15, -0.05);
|
||||
changes[i].max = XRandom(0.05, 0.15);
|
||||
changes[i].curr = (changes[i].min + changes[i].max) / 2;
|
||||
changes[i].step = CHANGE_SPEED;
|
||||
changes[i].forward = true;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateChanges (double timestep) {
|
||||
void UpdateChanges(double timestep) {
|
||||
for (int i=0; i<NUM_CHANGES; i++) {
|
||||
TChange* ch = &changes[i];
|
||||
if (ch->forward) {
|
||||
|
@ -716,8 +716,8 @@ void UpdateChanges (double timestep) {
|
|||
}
|
||||
}
|
||||
|
||||
TCurtain::TCurtain (int num_rows, float z_dist, float tex_size,
|
||||
float base_speed, float start_angle, float min_height, int dense) {
|
||||
TCurtain::TCurtain(int num_rows, float z_dist, float tex_size,
|
||||
float base_speed, float start_angle, float min_height, int dense) {
|
||||
numRows = num_rows;
|
||||
zdist = z_dist;
|
||||
size = tex_size;
|
||||
|
@ -736,13 +736,13 @@ 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 / 3.14159;
|
||||
numCols = (unsigned int)(-2 * startangle / angledist) + 1;
|
||||
if (numCols > MAX_CURTAIN_COLS) numCols = MAX_CURTAIN_COLS;
|
||||
lastangle = startangle + (numCols-1) * angledist;
|
||||
|
||||
for (unsigned int i=0; i<numRows; i++)
|
||||
chg[i] = IRandom (0, 5);
|
||||
chg[i] = IRandom(0, 5);
|
||||
}
|
||||
|
||||
void TCurtain::SetStartParams(const CControl* ctrl) {
|
||||
|
@ -752,7 +752,7 @@ void TCurtain::SetStartParams(const CControl* ctrl) {
|
|||
curt->height = minheight + row * size;
|
||||
float x, z;
|
||||
curt->angle = co * angledist + startangle;
|
||||
CurtainVec (curt->angle, zdist, x, z);
|
||||
CurtainVec(curt->angle, zdist, x, z);
|
||||
curt->pt.x = ctrl->cpos.x + x;
|
||||
curt->pt.z = ctrl->cpos.z + z;
|
||||
curt->pt.y = ctrl->cpos.y + curt->height;
|
||||
|
@ -761,7 +761,7 @@ void TCurtain::SetStartParams(const CControl* ctrl) {
|
|||
}
|
||||
|
||||
void TCurtain::Draw() const {
|
||||
Tex.BindTex (texture);
|
||||
Tex.BindTex(texture);
|
||||
float halfsize = size / 2.f;
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
@ -770,7 +770,7 @@ void TCurtain::Draw() const {
|
|||
const TVector3d& pt = curtains[co][row].pt;
|
||||
glPushMatrix();
|
||||
glTranslate(pt);
|
||||
glRotatef (-curtains[co][row].angle, 0, 1, 0);
|
||||
glRotatef(-curtains[co][row].angle, 0, 1, 0);
|
||||
|
||||
static const GLshort tex[] = {
|
||||
0, 1,
|
||||
|
@ -806,7 +806,7 @@ void TCurtain::Update(float timestep, const TVector3d& drift, const CControl* ct
|
|||
if (curt->angle > lastangle + angledist) curt->angle = startangle;
|
||||
if (curt->angle < startangle - angledist) curt->angle = lastangle;
|
||||
float x, z;
|
||||
CurtainVec (curt->angle, zdist, x, z);
|
||||
CurtainVec(curt->angle, zdist, x, z);
|
||||
curt->pt.x = ctrl->cpos.x + x;
|
||||
curt->pt.z = ctrl->cpos.z + z;
|
||||
curt->pt.y = ctrl->cpos.y + curt->height;
|
||||
|
@ -817,17 +817,17 @@ 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);
|
||||
if (angle > 90 || angle < -90) z = sqrt (zdist * zdist - x * x);
|
||||
else z = -sqrt (zdist * zdist - x * x);
|
||||
void TCurtain::CurtainVec(float angle, float zdist, float &x, float &z) {
|
||||
x = zdist * sin(angle * 3.14159 / 180);
|
||||
if (angle > 90 || angle < -90) z = sqrt(zdist * zdist - x * x);
|
||||
else z = -sqrt(zdist * zdist - x * x);
|
||||
}
|
||||
|
||||
void CCurtain::Draw () {
|
||||
void CCurtain::Draw() {
|
||||
if (g_game.snow_id < 1) return;
|
||||
|
||||
ScopedRenderMode rm(PARTICLES);
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
const sf::Color& particle_colour = Env.ParticleColor();
|
||||
glColor(particle_colour, 255);
|
||||
|
||||
|
@ -837,30 +837,30 @@ void CCurtain::Draw () {
|
|||
}
|
||||
}
|
||||
|
||||
void CCurtain::Update (float timestep, const CControl *ctrl) {
|
||||
void CCurtain::Update(float timestep, const CControl *ctrl) {
|
||||
if (g_game.snow_id < 1) return;
|
||||
const TVector3d& drift = Wind.WindDrift ();
|
||||
const TVector3d& drift = Wind.WindDrift();
|
||||
|
||||
UpdateChanges (timestep);
|
||||
UpdateChanges(timestep);
|
||||
for (size_t i=0; i<curtains.size(); i++) {
|
||||
curtains[i].Update(timestep, drift, ctrl);
|
||||
}
|
||||
Draw ();
|
||||
Draw();
|
||||
}
|
||||
|
||||
void CCurtain::Reset () {
|
||||
void CCurtain::Reset() {
|
||||
curtains.clear();
|
||||
}
|
||||
|
||||
void CCurtain::SetStartParams (const CControl *ctrl) {
|
||||
void CCurtain::SetStartParams(const CControl *ctrl) {
|
||||
for (size_t i=0; i<curtains.size(); i++) {
|
||||
curtains[i].SetStartParams(ctrl);
|
||||
}
|
||||
}
|
||||
|
||||
void CCurtain::Init (const CControl *ctrl) {
|
||||
Reset ();
|
||||
InitChanges ();
|
||||
void CCurtain::Init(const CControl *ctrl) {
|
||||
Reset();
|
||||
InitChanges();
|
||||
switch (g_game.snow_id) {
|
||||
case 1:
|
||||
// curtains.push_back(TCurtain(3, 60, 10, 3, -100, -10, 1));
|
||||
|
@ -898,7 +898,7 @@ void CCurtain::Init (const CControl *ctrl) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
SetStartParams (ctrl);
|
||||
SetStartParams(ctrl);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -909,7 +909,7 @@ void CCurtain::Init (const CControl *ctrl) {
|
|||
|
||||
CWind Wind;
|
||||
|
||||
CWind::CWind ()
|
||||
CWind::CWind()
|
||||
: WVector(0, 0, 0) {
|
||||
windy = false;
|
||||
CurrTime = 0.0;
|
||||
|
@ -924,7 +924,7 @@ CWind::CWind ()
|
|||
AngleChange = 0;
|
||||
}
|
||||
|
||||
void CWind::SetParams (int grade) {
|
||||
void CWind::SetParams(int grade) {
|
||||
float min_base_speed = 0;
|
||||
float max_base_speed = 0;
|
||||
float min_speed_var = 0;
|
||||
|
@ -996,46 +996,46 @@ void CWind::SetParams (int grade) {
|
|||
|
||||
float speed, var, angle;
|
||||
|
||||
speed = XRandom (min_base_speed, max_base_speed);
|
||||
var = XRandom (min_speed_var, max_speed_var) / 2;
|
||||
speed = XRandom(min_base_speed, max_base_speed);
|
||||
var = XRandom(min_speed_var, max_speed_var) / 2;
|
||||
params.minSpeed = speed - var;
|
||||
params.maxSpeed = speed + var;
|
||||
if (params.minSpeed < 0) params.minSpeed = 0;
|
||||
if (params.maxSpeed > 100) params.maxSpeed = 100;
|
||||
|
||||
angle = XRandom (min_base_angle, max_base_angle);
|
||||
if (XRandom (0, 100) > 50) angle = angle + alt_angle;
|
||||
var = XRandom (min_angle_var, max_angle_var) / 2;
|
||||
angle = XRandom(min_base_angle, max_base_angle);
|
||||
if (XRandom(0, 100) > 50) angle = angle + alt_angle;
|
||||
var = XRandom(min_angle_var, max_angle_var) / 2;
|
||||
params.minAngle = angle - var;
|
||||
params.maxAngle = angle + var;
|
||||
}
|
||||
|
||||
void CWind::CalcDestSpeed () {
|
||||
float rand = XRandom (0, 100);
|
||||
void CWind::CalcDestSpeed() {
|
||||
float rand = XRandom(0, 100);
|
||||
if (rand > (100 - params.topProbability)) {
|
||||
DestSpeed = XRandom (params.maxSpeed, params.topSpeed);
|
||||
DestSpeed = XRandom(params.maxSpeed, params.topSpeed);
|
||||
WindChange = params.maxChange;
|
||||
} else if (rand < params.nullProbability) {
|
||||
DestSpeed = 0.0;
|
||||
WindChange = XRandom (params.minChange, params.maxChange);
|
||||
WindChange = XRandom(params.minChange, params.maxChange);
|
||||
} else {
|
||||
DestSpeed = XRandom (params.minSpeed, params.maxSpeed);
|
||||
WindChange = XRandom (params.minChange, params.maxChange);
|
||||
DestSpeed = XRandom(params.minSpeed, params.maxSpeed);
|
||||
WindChange = XRandom(params.minChange, params.maxChange);
|
||||
}
|
||||
|
||||
if (DestSpeed > WSpeed) SpeedMode = 1;
|
||||
else SpeedMode = 0;
|
||||
}
|
||||
|
||||
void CWind::CalcDestAngle () {
|
||||
DestAngle = XRandom (params.minAngle, params.maxAngle);
|
||||
AngleChange = XRandom (params.minAngleChange, params.maxAngleChange);
|
||||
void CWind::CalcDestAngle() {
|
||||
DestAngle = XRandom(params.minAngle, params.maxAngle);
|
||||
AngleChange = XRandom(params.minAngleChange, params.maxAngleChange);
|
||||
|
||||
if (DestAngle > WAngle) AngleMode = 1;
|
||||
else AngleMode = 0;
|
||||
}
|
||||
|
||||
void CWind::Update (float timestep) {
|
||||
void CWind::Update(float timestep) {
|
||||
if (!windy) return;
|
||||
|
||||
// the wind needn't be updated in each frame
|
||||
|
@ -1046,11 +1046,11 @@ void CWind::Update (float timestep) {
|
|||
if (SpeedMode == 1) { // current speed lesser than destination speed
|
||||
if (WSpeed < DestSpeed) {
|
||||
WSpeed = WSpeed + WindChange;
|
||||
} else CalcDestSpeed ();
|
||||
} else CalcDestSpeed();
|
||||
} else {
|
||||
if (WSpeed > DestSpeed) {
|
||||
WSpeed = WSpeed - WindChange;
|
||||
} else CalcDestSpeed ();
|
||||
} else CalcDestSpeed();
|
||||
}
|
||||
if (WSpeed > params.topSpeed) WSpeed = params.topSpeed;
|
||||
if (WSpeed < 0) WSpeed = 0;
|
||||
|
@ -1059,17 +1059,17 @@ void CWind::Update (float timestep) {
|
|||
if (AngleMode == 1) {
|
||||
if (WAngle < DestAngle) {
|
||||
WAngle = WAngle + AngleChange;
|
||||
} else CalcDestAngle ();
|
||||
} else CalcDestAngle();
|
||||
} else {
|
||||
if (WAngle > DestAngle) {
|
||||
WAngle = WAngle - AngleChange;
|
||||
} else CalcDestAngle ();
|
||||
} else CalcDestAngle();
|
||||
}
|
||||
if (WAngle > params.maxAngle) WAngle = params.maxAngle;
|
||||
if (WAngle < params.minAngle) WAngle = params.minAngle;
|
||||
|
||||
float xx = sin (WAngle * 3.14159 / 180);
|
||||
float zz = sqrt (1 - xx * xx);
|
||||
float xx = sin(WAngle * 3.14159 / 180);
|
||||
float zz = sqrt(1 - xx * xx);
|
||||
if ((WAngle > 90 && WAngle < 270) || (WAngle > 450 && WAngle < 630)) {
|
||||
zz = -zz;
|
||||
}
|
||||
|
@ -1079,48 +1079,48 @@ void CWind::Update (float timestep) {
|
|||
}
|
||||
}
|
||||
|
||||
void CWind::Init (int wind_id) {
|
||||
void CWind::Init(int wind_id) {
|
||||
if (wind_id < 1 || wind_id > 3) {
|
||||
windy = false;
|
||||
WVector = TVector3d (0, 0, 0);
|
||||
WVector = TVector3d(0, 0, 0);
|
||||
WAngle = 0;
|
||||
WSpeed = 0;
|
||||
return;
|
||||
}
|
||||
windy = true;;
|
||||
SetParams (wind_id -1);
|
||||
WSpeed = XRandom (params.minSpeed, (params.minSpeed + params.maxSpeed) / 2);
|
||||
WAngle = XRandom (params.minAngle, params.maxAngle);
|
||||
CalcDestSpeed ();
|
||||
CalcDestAngle ();
|
||||
SetParams(wind_id -1);
|
||||
WSpeed = XRandom(params.minSpeed, (params.minSpeed + params.maxSpeed) / 2);
|
||||
WAngle = XRandom(params.minAngle, params.maxAngle);
|
||||
CalcDestSpeed();
|
||||
CalcDestAngle();
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
// access functions
|
||||
// ====================================================================
|
||||
|
||||
void InitSnow (const CControl *ctrl) {
|
||||
void InitSnow(const CControl *ctrl) {
|
||||
if (g_game.snow_id < 1 || g_game.snow_id > 3) return;
|
||||
Flakes.Init (g_game.snow_id, ctrl);
|
||||
Curtain.Init (ctrl);
|
||||
Flakes.Init(g_game.snow_id, ctrl);
|
||||
Curtain.Init(ctrl);
|
||||
}
|
||||
|
||||
void UpdateSnow (double timestep, const CControl *ctrl) {
|
||||
void UpdateSnow(double timestep, const CControl *ctrl) {
|
||||
if (g_game.snow_id < 1 || g_game.snow_id > 3) return;
|
||||
Flakes.Update (timestep, ctrl);
|
||||
Curtain.Update (timestep, ctrl);
|
||||
Flakes.Update(timestep, ctrl);
|
||||
Curtain.Update(timestep, ctrl);
|
||||
}
|
||||
|
||||
void DrawSnow (const CControl *ctrl) {
|
||||
void DrawSnow(const CControl *ctrl) {
|
||||
if (g_game.snow_id < 1 || g_game.snow_id > 3) return;
|
||||
Flakes.Draw (ctrl);
|
||||
Curtain.Draw ();
|
||||
Flakes.Draw(ctrl);
|
||||
Curtain.Draw();
|
||||
}
|
||||
|
||||
void InitWind () {
|
||||
Wind.Init (g_game.wind_id);
|
||||
void InitWind() {
|
||||
Wind.Init(g_game.wind_id);
|
||||
}
|
||||
|
||||
void UpdateWind (double timestep) {
|
||||
Wind.Update (timestep);
|
||||
void UpdateWind(double timestep) {
|
||||
Wind.Update(timestep);
|
||||
}
|
||||
|
|
|
@ -26,20 +26,20 @@ GNU General Public License for more details.
|
|||
// snow for menu screens
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void init_ui_snow ();
|
||||
void update_ui_snow (double time_step);
|
||||
void push_ui_snow (const TVector2i& pos);
|
||||
void draw_ui_snow ();
|
||||
void init_ui_snow();
|
||||
void update_ui_snow(double time_step);
|
||||
void push_ui_snow(const TVector2i& pos);
|
||||
void draw_ui_snow();
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// snow particles during race
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void create_new_particles (const TVector3d& loc, const TVector3d& vel, int num);
|
||||
void update_particles (double time_step);
|
||||
void clear_particles ();
|
||||
void draw_particles (const CControl *ctrl);
|
||||
void generate_particles (const CControl *ctrl, double dtime, const TVector3d& pos, double speed);
|
||||
void create_new_particles(const TVector3d& loc, const TVector3d& vel, int num);
|
||||
void update_particles(double time_step);
|
||||
void clear_particles();
|
||||
void draw_particles(const CControl *ctrl);
|
||||
void generate_particles(const CControl *ctrl, double dtime, const TVector3d& pos, double speed);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// snow flakes for short distances
|
||||
|
@ -93,14 +93,14 @@ class CFlakes {
|
|||
private:
|
||||
TVector3d snow_lastpos;
|
||||
vector<TFlakeArea> areas;
|
||||
void MakeSnowFlake (size_t ar, size_t i);
|
||||
void GenerateSnowFlakes (const CControl *ctrl);
|
||||
void UpdateAreas (const CControl *ctrl);
|
||||
void MakeSnowFlake(size_t ar, size_t i);
|
||||
void GenerateSnowFlakes(const CControl *ctrl);
|
||||
void UpdateAreas(const CControl *ctrl);
|
||||
public:
|
||||
void Init (int grade, const CControl *ctrl);
|
||||
void Reset ();
|
||||
void Update (double timestep, const CControl *ctrl);
|
||||
void Draw (const CControl *ctrl) const;
|
||||
void Init(int grade, const CControl *ctrl);
|
||||
void Reset();
|
||||
void Update(double timestep, const CControl *ctrl);
|
||||
void Draw(const CControl *ctrl) const;
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -150,19 +150,19 @@ struct TCurtain {
|
|||
void Update(float timestep, const TVector3d& drift, const CControl* ctrl);
|
||||
|
||||
private:
|
||||
static void CurtainVec (float angle, float zdist, float &x, float &z);
|
||||
static void CurtainVec(float angle, float zdist, float &x, float &z);
|
||||
};
|
||||
|
||||
class CCurtain {
|
||||
private:
|
||||
vector<TCurtain> curtains;
|
||||
|
||||
void SetStartParams (const CControl *ctrl);
|
||||
void SetStartParams(const CControl *ctrl);
|
||||
public:
|
||||
void Init (const CControl *ctrl);
|
||||
void Update (float timestep, const CControl *ctrl);
|
||||
void Draw ();
|
||||
void Reset ();
|
||||
void Init(const CControl *ctrl);
|
||||
void Update(float timestep, const CControl *ctrl);
|
||||
void Draw();
|
||||
void Reset();
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -203,18 +203,18 @@ private:
|
|||
float WindChange;
|
||||
float AngleChange;
|
||||
|
||||
void SetParams (int grade);
|
||||
void CalcDestSpeed ();
|
||||
void CalcDestAngle ();
|
||||
void SetParams(int grade);
|
||||
void CalcDestSpeed();
|
||||
void CalcDestAngle();
|
||||
public:
|
||||
CWind ();
|
||||
CWind();
|
||||
|
||||
void Update (float timestep);
|
||||
void Init (int wind_id);
|
||||
bool Windy () const { return windy; }
|
||||
float Angle () const { return WAngle; }
|
||||
float Speed () const { return WSpeed; }
|
||||
const TVector3d& WindDrift () const { return WVector; }
|
||||
void Update(float timestep);
|
||||
void Init(int wind_id);
|
||||
bool Windy() const { return windy; }
|
||||
float Angle() const { return WAngle; }
|
||||
float Speed() const { return WSpeed; }
|
||||
const TVector3d& WindDrift() const { return WVector; }
|
||||
};
|
||||
|
||||
extern CWind Wind;
|
||||
|
@ -223,10 +223,10 @@ extern CWind Wind;
|
|||
// Acess functions
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void InitSnow (const CControl *ctrl);
|
||||
void UpdateSnow (double timestep, const CControl *ctrl);
|
||||
void DrawSnow (const CControl *ctrl);
|
||||
void InitWind ();
|
||||
void UpdateWind (double timestep);
|
||||
void InitSnow(const CControl *ctrl);
|
||||
void UpdateSnow(double timestep, const CControl *ctrl);
|
||||
void DrawSnow(const CControl *ctrl);
|
||||
void InitWind();
|
||||
void UpdateWind(double timestep);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,11 +42,11 @@ static bool fog = true;
|
|||
static bool terr = true;
|
||||
static bool trees = true;
|
||||
|
||||
void CPaused::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CPaused::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case sf::Keyboard::S:
|
||||
ScreenshotN ();
|
||||
ScreenshotN();
|
||||
break;
|
||||
case sf::Keyboard::F5:
|
||||
sky = !sky;
|
||||
|
@ -61,39 +61,39 @@ void CPaused::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, in
|
|||
trees = !trees;
|
||||
break;
|
||||
default:
|
||||
State::manager.RequestEnterState (Racing);
|
||||
State::manager.RequestEnterState(Racing);
|
||||
}
|
||||
}
|
||||
|
||||
void CPaused::Mouse (int button, int state, int x, int y) {
|
||||
State::manager.RequestEnterState (Racing);
|
||||
void CPaused::Mouse(int button, int state, int x, int y) {
|
||||
State::manager.RequestEnterState(Racing);
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
void CPaused::Loop (double time_step) {
|
||||
void CPaused::Loop(double time_step) {
|
||||
CControl *ctrl = g_game.player->ctrl;
|
||||
int width = Winsys.resolution.width;
|
||||
int height = Winsys.resolution.height;
|
||||
|
||||
ClearRenderContext ();
|
||||
Env.SetupFog ();
|
||||
update_view (ctrl, 0);
|
||||
SetupViewFrustum (ctrl);
|
||||
ClearRenderContext();
|
||||
Env.SetupFog();
|
||||
update_view(ctrl, 0);
|
||||
SetupViewFrustum(ctrl);
|
||||
|
||||
if (sky) Env.DrawSkybox (ctrl->viewpos);
|
||||
if (fog) Env.DrawFog ();
|
||||
Env.SetupLight ();
|
||||
if (sky) Env.DrawSkybox(ctrl->viewpos);
|
||||
if (fog) Env.DrawFog();
|
||||
Env.SetupLight();
|
||||
if (terr) RenderCourse();
|
||||
DrawTrackmarks ();
|
||||
DrawTrackmarks();
|
||||
if (trees) DrawTrees();
|
||||
|
||||
DrawSnow (ctrl);
|
||||
DrawSnow(ctrl);
|
||||
|
||||
if (param.perf_level > 2) draw_particles (ctrl);
|
||||
if (param.perf_level > 2) draw_particles(ctrl);
|
||||
g_game.character->shape->Draw();
|
||||
|
||||
DrawHud (ctrl);
|
||||
Reshape (width, height);
|
||||
Winsys.SwapBuffers ();
|
||||
DrawHud(ctrl);
|
||||
Reshape(width, height);
|
||||
Winsys.SwapBuffers();
|
||||
}
|
||||
|
|
266
src/physics.cpp
266
src/physics.cpp
|
@ -28,7 +28,7 @@ GNU General Public License for more details.
|
|||
#include "game_over.h"
|
||||
#include <algorithm>
|
||||
|
||||
CControl::CControl () :
|
||||
CControl::CControl() :
|
||||
cnet_force(0, 0, 0) {
|
||||
minSpeed = 0;
|
||||
minFrictspeed = 0;
|
||||
|
@ -62,11 +62,11 @@ CControl::CControl () :
|
|||
// init
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void CControl::Init () {
|
||||
TVector3d nml = Course.FindCourseNormal (cpos.x, cpos.z);
|
||||
void CControl::Init() {
|
||||
TVector3d nml = Course.FindCourseNormal(cpos.x, cpos.z);
|
||||
TMatrix<4, 4> rotMat;
|
||||
rotMat.SetRotationMatrix(-90.0, 'x');
|
||||
TVector3d init_vel = TransformVector (rotMat, nml);
|
||||
TVector3d init_vel = TransformVector(rotMat, nml);
|
||||
init_vel *= INIT_TUX_SPEED;
|
||||
|
||||
turn_fact = 0;
|
||||
|
@ -76,10 +76,10 @@ void CControl::Init () {
|
|||
is_paddling = false;
|
||||
jumping = false;
|
||||
jump_charging = false;
|
||||
cpos.y = Course.FindYCoord (cpos.x, cpos.z);
|
||||
cpos.y = Course.FindYCoord(cpos.x, cpos.z);
|
||||
cvel = init_vel;
|
||||
last_pos = cpos;
|
||||
cnet_force = TVector3d (0, 0, 0);
|
||||
cnet_force = TVector3d(0, 0, 0);
|
||||
orientation_initialized = false;
|
||||
plane_nml = nml;
|
||||
cdirection = init_vel;
|
||||
|
@ -100,14 +100,14 @@ void CControl::Init () {
|
|||
// collision
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
bool CControl::CheckTreeCollisions (const TVector3d& pos, TVector3d *tree_loc) {
|
||||
bool CControl::CheckTreeCollisions(const TVector3d& pos, TVector3d *tree_loc) {
|
||||
// These variables are used to cache collision detection results
|
||||
static bool last_collision = false;
|
||||
static TVector3d last_collision_tree_loc(-999, -999, -999);
|
||||
static TVector3d last_collision_pos(-999, -999, -999);
|
||||
|
||||
TVector3d dist_vec = pos - last_collision_pos;
|
||||
if (MAG_SQD (dist_vec) < COLL_TOLERANCE) {
|
||||
if (MAG_SQD(dist_vec) < COLL_TOLERANCE) {
|
||||
if (last_collision && !cairborne) {
|
||||
if (tree_loc != NULL) *tree_loc = last_collision_tree_loc;
|
||||
return true;
|
||||
|
@ -131,14 +131,14 @@ bool CControl::CheckTreeCollisions (const TVector3d& pos, TVector3d *tree_loc) {
|
|||
|
||||
TPolyhedron ph2 = Course.GetPoly(Course.CollArr[i].tree_type);
|
||||
mat.SetScalingMatrix(diam, height, diam);
|
||||
TransPolyhedron (mat, ph2);
|
||||
TransPolyhedron(mat, ph2);
|
||||
mat.SetTranslationMatrix(loc.x, loc.y, loc.z);
|
||||
TransPolyhedron (mat, ph2);
|
||||
TransPolyhedron(mat, ph2);
|
||||
|
||||
hit = g_game.character->shape->Collision(pos, ph2);
|
||||
if (hit == true) {
|
||||
if (tree_loc != NULL) *tree_loc = loc;
|
||||
Sound.Play ("tree_hit", 0);
|
||||
Sound.Play("tree_hit", 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -150,10 +150,10 @@ bool CControl::CheckTreeCollisions (const TVector3d& pos, TVector3d *tree_loc) {
|
|||
return hit;
|
||||
}
|
||||
|
||||
void CControl::AdjustTreeCollision (const TVector3d& pos, TVector3d *vel) {
|
||||
void CControl::AdjustTreeCollision(const TVector3d& pos, TVector3d *vel) {
|
||||
TVector3d treeLoc;
|
||||
|
||||
if (CheckTreeCollisions (pos, &treeLoc)) {
|
||||
if (CheckTreeCollisions(pos, &treeLoc)) {
|
||||
TVector3d treeNml(
|
||||
pos.x - treeLoc.x,
|
||||
0,
|
||||
|
@ -163,7 +163,7 @@ void CControl::AdjustTreeCollision (const TVector3d& pos, TVector3d *vel) {
|
|||
double speed = vel->Norm();
|
||||
speed *= 0.8; // original 0.7
|
||||
|
||||
double costheta = DotProduct (*vel, treeNml);
|
||||
double costheta = DotProduct(*vel, treeNml);
|
||||
if (costheta < 0) {
|
||||
double factor;
|
||||
if (cairborne) factor = 0.5;
|
||||
|
@ -171,12 +171,12 @@ void CControl::AdjustTreeCollision (const TVector3d& pos, TVector3d *vel) {
|
|||
*vel += (-factor * costheta) * treeNml;
|
||||
vel->Norm();
|
||||
}
|
||||
speed = max (speed, minSpeed);
|
||||
speed = max(speed, minSpeed);
|
||||
*vel *= speed;
|
||||
}
|
||||
}
|
||||
|
||||
void CControl::CheckItemCollection (const TVector3d& pos) {
|
||||
void CControl::CheckItemCollection(const TVector3d& pos) {
|
||||
TItem *items = &Course.NocollArr[0];
|
||||
size_t num_items = Course.NocollArr.size();
|
||||
|
||||
|
@ -190,7 +190,7 @@ void CControl::CheckItemCollection (const TVector3d& pos) {
|
|||
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
|
||||
if (MAG_SQD(distvec) <= squared_dist) { // Check collision using a bounding sphere
|
||||
items[i].collectable = 0;
|
||||
g_game.herring += 1;
|
||||
Sound.Play("pickup1", 0);
|
||||
|
@ -203,26 +203,26 @@ void CControl::CheckItemCollection (const TVector3d& pos) {
|
|||
// position and velocity ***
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void CControl::AdjustVelocity () {
|
||||
void CControl::AdjustVelocity() {
|
||||
double speed = cvel.Norm();
|
||||
speed = max (minSpeed, speed);
|
||||
speed = max(minSpeed, speed);
|
||||
cvel *= speed;
|
||||
|
||||
if (g_game.finish == true) {
|
||||
/// --------------- finish ------------------------------------
|
||||
if (speed < 3) State::manager.RequestEnterState (GameOver);
|
||||
if (speed < 3) State::manager.RequestEnterState(GameOver);
|
||||
/// -----------------------------------------------------------
|
||||
}
|
||||
}
|
||||
|
||||
void CControl::AdjustPosition (const TPlane& surf_plane, double dist_from_surface) {
|
||||
void CControl::AdjustPosition(const TPlane& surf_plane, double dist_from_surface) {
|
||||
if (dist_from_surface < -MAX_SURF_PEN) {
|
||||
double displace = -MAX_SURF_PEN - dist_from_surface;
|
||||
cpos += displace * surf_plane.nml;
|
||||
}
|
||||
}
|
||||
|
||||
void CControl::SetTuxPosition (double speed) {
|
||||
void CControl::SetTuxPosition(double speed) {
|
||||
CCharShape *shape = g_game.character->shape;
|
||||
|
||||
TVector2d playSize = Course.GetPlayDimensions();
|
||||
|
@ -239,69 +239,69 @@ void CControl::SetTuxPosition (double speed) {
|
|||
g_game.finish = true;
|
||||
finish_speed = speed;
|
||||
// SetStationaryCamera (true);
|
||||
} else State::manager.RequestEnterState (GameOver);
|
||||
} else State::manager.RequestEnterState(GameOver);
|
||||
}
|
||||
/// -----------------------------------------------------------
|
||||
}
|
||||
double disp_y = cpos.y + TUX_Y_CORR;
|
||||
shape->ResetNode (0);
|
||||
shape->TranslateNode (0, TVector3d (cpos.x, disp_y, cpos.z));
|
||||
shape->ResetNode(0);
|
||||
shape->TranslateNode(0, TVector3d(cpos.x, disp_y, cpos.z));
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
// forces ***
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
TVector3d CControl::CalcRollNormal (double speed) {
|
||||
TVector3d vel = ProjectToPlane (ff.surfnml, ff.vel);
|
||||
TVector3d CControl::CalcRollNormal(double speed) {
|
||||
TVector3d vel = ProjectToPlane(ff.surfnml, ff.vel);
|
||||
vel.Norm();
|
||||
|
||||
double roll_angle = MAX_ROLL_ANGLE;
|
||||
if (is_braking) roll_angle = BRAKING_ROLL_ANGLE;
|
||||
|
||||
double angle = turn_fact * roll_angle *
|
||||
min (1.0, max (0.0, ff.frict_coeff) / IDEAL_ROLL_FRIC) *
|
||||
min (1.0, max (0.0, speed - minSpeed) / (IDEAL_ROLL_SPEED - minSpeed));
|
||||
min(1.0, max(0.0, ff.frict_coeff) / IDEAL_ROLL_FRIC) *
|
||||
min(1.0, max(0.0, speed - minSpeed) / (IDEAL_ROLL_SPEED - minSpeed));
|
||||
|
||||
TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix(vel, angle);
|
||||
return TransformVector (rot_mat, ff.surfnml);
|
||||
return TransformVector(rot_mat, ff.surfnml);
|
||||
}
|
||||
|
||||
const double airlog[] = {-1, 0, 1, 2, 3, 4, 5, 6};
|
||||
const double airdrag[] = {2.25, 1.35, 0.6, 0, -0.35, -0.45, -0.33, -0.9};
|
||||
|
||||
TVector3d CControl::CalcAirForce () {
|
||||
TVector3d CControl::CalcAirForce() {
|
||||
TVector3d windvec = -1.0 * ff.vel;
|
||||
if (g_game.wind_id > 0)
|
||||
windvec += WIND_FACTOR * Wind.WindDrift();
|
||||
|
||||
double windspeed = windvec.Length();
|
||||
double re = 34600 * windspeed;
|
||||
int tablesize = sizeof (airdrag) / sizeof (airdrag[0]);
|
||||
double interpol = LinearInterp (airlog, airdrag, log10 (re), tablesize);
|
||||
double dragcoeff = pow (10.0, interpol);
|
||||
int tablesize = sizeof(airdrag) / sizeof(airdrag[0]);
|
||||
double interpol = LinearInterp(airlog, airdrag, log10(re), tablesize);
|
||||
double dragcoeff = pow(10.0, interpol);
|
||||
double airfact = 0.104 * dragcoeff * windspeed;
|
||||
return airfact * windvec;
|
||||
}
|
||||
|
||||
TVector3d CControl::CalcSpringForce () {
|
||||
double springvel = DotProduct (ff.vel, ff.rollnml);
|
||||
double springfact = min (ff.compression, 0.05) * 1500;
|
||||
springfact += clamp (0, ff.compression - 0.05, 0.12) * 3000;
|
||||
springfact += max (0, ff.compression - 0.12 - 0.05) * 10000;
|
||||
TVector3d CControl::CalcSpringForce() {
|
||||
double springvel = DotProduct(ff.vel, ff.rollnml);
|
||||
double springfact = min(ff.compression, 0.05) * 1500;
|
||||
springfact += clamp(0, ff.compression - 0.05, 0.12) * 3000;
|
||||
springfact += max(0, ff.compression - 0.12 - 0.05) * 10000;
|
||||
springfact -= springvel * (ff.compression <= 0.05 ? 1500 : 500);
|
||||
springfact = clamp (0.0, springfact, 3000.0);
|
||||
springfact = clamp(0.0, springfact, 3000.0);
|
||||
return springfact * ff.rollnml;
|
||||
}
|
||||
|
||||
TVector3d CControl::CalcNormalForce () {
|
||||
TVector3d CControl::CalcNormalForce() {
|
||||
if (ff.surfdistance <= -ff.comp_depth) {
|
||||
ff.compression = -ff.surfdistance - ff.comp_depth;
|
||||
return CalcSpringForce ();
|
||||
return CalcSpringForce();
|
||||
}
|
||||
return TVector3d(0, 0, 0);
|
||||
}
|
||||
|
||||
TVector3d CControl::CalcJumpForce () {
|
||||
TVector3d CControl::CalcJumpForce() {
|
||||
TVector3d jumpforce;
|
||||
if (begin_jump == true) {
|
||||
begin_jump = false;
|
||||
|
@ -320,26 +320,26 @@ TVector3d CControl::CalcJumpForce () {
|
|||
return jumpforce; // normally scaled with 1.0
|
||||
}
|
||||
|
||||
TVector3d CControl::CalcFrictionForce (double speed, const TVector3d& nmlforce) {
|
||||
TVector3d CControl::CalcFrictionForce(double speed, const TVector3d& nmlforce) {
|
||||
if ((cairborne == false && speed > minFrictspeed) || g_game.finish) {
|
||||
double fric_f_mag = nmlforce.Length() * ff.frict_coeff;
|
||||
fric_f_mag = min (MAX_FRICT_FORCE, fric_f_mag);
|
||||
fric_f_mag = min(MAX_FRICT_FORCE, fric_f_mag);
|
||||
TVector3d frictforce = fric_f_mag * ff.frictdir;
|
||||
|
||||
double steer_angle = turn_fact * MAX_TURN_ANGLE;
|
||||
|
||||
if (fabs (fric_f_mag * sin (steer_angle * M_PI / 180)) > MAX_TURN_PERP) {
|
||||
steer_angle = RADIANS_TO_ANGLES (asin (MAX_TURN_PERP / fric_f_mag)) *
|
||||
turn_fact / fabs (turn_fact);
|
||||
if (fabs(fric_f_mag * sin(steer_angle * M_PI / 180)) > MAX_TURN_PERP) {
|
||||
steer_angle = RADIANS_TO_ANGLES(asin(MAX_TURN_PERP / fric_f_mag)) *
|
||||
turn_fact / fabs(turn_fact);
|
||||
}
|
||||
TMatrix<4, 4> fric_rot_mat = RotateAboutVectorMatrix(ff.surfnml, steer_angle);
|
||||
frictforce = TransformVector (fric_rot_mat, frictforce);
|
||||
frictforce = TransformVector(fric_rot_mat, frictforce);
|
||||
return (1.0 + MAX_TURN_PEN) * frictforce;
|
||||
}
|
||||
return TVector3d (0, 0, 0);
|
||||
return TVector3d(0, 0, 0);
|
||||
}
|
||||
|
||||
TVector3d CControl::CalcBrakeForce (double speed) {
|
||||
TVector3d CControl::CalcBrakeForce(double speed) {
|
||||
if (g_game.finish == false) {
|
||||
if (cairborne == false && speed > minFrictspeed) {
|
||||
if (speed > minSpeed && is_braking) {
|
||||
|
@ -360,7 +360,7 @@ TVector3d CControl::CalcBrakeForce (double speed) {
|
|||
return TVector3d(0, 0, 0);
|
||||
}
|
||||
|
||||
TVector3d CControl::CalcPaddleForce (double speed) {
|
||||
TVector3d CControl::CalcPaddleForce(double speed) {
|
||||
TVector3d paddleforce(0, 0, 0);
|
||||
if (is_paddling)
|
||||
if (g_game.time - paddle_time >= PADDLING_DURATION) is_paddling = false;
|
||||
|
@ -368,7 +368,7 @@ TVector3d CControl::CalcPaddleForce (double speed) {
|
|||
if (is_paddling) {
|
||||
if (cairborne) {
|
||||
paddleforce.z = -TUX_MASS * EARTH_GRAV / 4.0;
|
||||
paddleforce = RotateVector (corientation, paddleforce);
|
||||
paddleforce = RotateVector(corientation, paddleforce);
|
||||
} else {
|
||||
double factor = -1 * min(MAX_PADD_FORCE, MAX_PADD_FORCE
|
||||
* (MAX_PADDLING_SPEED - speed) / MAX_PADDLING_SPEED
|
||||
|
@ -379,18 +379,18 @@ TVector3d CControl::CalcPaddleForce (double speed) {
|
|||
return PADDLE_FACT * paddleforce;
|
||||
}
|
||||
|
||||
TVector3d CControl::CalcGravitationForce () {
|
||||
TVector3d CControl::CalcGravitationForce() {
|
||||
if (g_game.finish == false) {
|
||||
return TVector3d (0, -EARTH_GRAV * TUX_MASS, 0);
|
||||
return TVector3d(0, -EARTH_GRAV * TUX_MASS, 0);
|
||||
} else {
|
||||
/// ---------------- finish -----------------------------------
|
||||
if (cairborne) return TVector3d (0, -FIN_AIR_GRAV, 0);
|
||||
else return TVector3d (0, -FIN_GRAV, 0);
|
||||
if (cairborne) return TVector3d(0, -FIN_AIR_GRAV, 0);
|
||||
else return TVector3d(0, -FIN_GRAV, 0);
|
||||
/// -----------------------------------------------------------
|
||||
}
|
||||
}
|
||||
|
||||
TVector3d CControl::CalcNetForce (const TVector3d& pos, const TVector3d& vel) {
|
||||
TVector3d CControl::CalcNetForce(const TVector3d& pos, const TVector3d& vel) {
|
||||
// pos and vel are temporary, see ODE solver
|
||||
|
||||
ff.pos = pos;
|
||||
|
@ -403,7 +403,7 @@ TVector3d CControl::CalcNetForce (const TVector3d& pos, const TVector3d& vel) {
|
|||
static vector<double> surfweights;
|
||||
if (surfweights.size() != Course.TerrList.size())
|
||||
surfweights.resize(Course.TerrList.size());
|
||||
Course.GetSurfaceType (ff.pos.x, ff.pos.z, &surfweights[0]);
|
||||
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++) {
|
||||
|
@ -411,20 +411,20 @@ TVector3d CControl::CalcNetForce (const TVector3d& pos, const TVector3d& vel) {
|
|||
ff.comp_depth += surfweights[i] * TerrList[i].depth;
|
||||
}
|
||||
|
||||
TPlane surfplane = Course.GetLocalCoursePlane (ff.pos);
|
||||
TPlane surfplane = Course.GetLocalCoursePlane(ff.pos);
|
||||
ff.surfnml = surfplane.nml;
|
||||
ff.rollnml = CalcRollNormal (speed);
|
||||
ff.surfdistance = DistanceToPlane (surfplane, ff.pos);
|
||||
ff.rollnml = CalcRollNormal(speed);
|
||||
ff.surfdistance = DistanceToPlane(surfplane, ff.pos);
|
||||
cairborne = (bool)(ff.surfdistance > 0);
|
||||
|
||||
// don't change this order:
|
||||
TVector3d gravforce = CalcGravitationForce ();
|
||||
TVector3d nmlforce = CalcNormalForce ();
|
||||
TVector3d jumpforce = CalcJumpForce ();
|
||||
TVector3d frictforce = CalcFrictionForce (speed, nmlforce);
|
||||
TVector3d brakeforce = CalcBrakeForce (speed);
|
||||
TVector3d airforce = CalcAirForce ();
|
||||
TVector3d paddleforce = CalcPaddleForce (speed);
|
||||
TVector3d gravforce = CalcGravitationForce();
|
||||
TVector3d nmlforce = CalcNormalForce();
|
||||
TVector3d jumpforce = CalcJumpForce();
|
||||
TVector3d frictforce = CalcFrictionForce(speed, nmlforce);
|
||||
TVector3d brakeforce = CalcBrakeForce(speed);
|
||||
TVector3d airforce = CalcAirForce();
|
||||
TVector3d paddleforce = CalcPaddleForce(speed);
|
||||
|
||||
return jumpforce + gravforce + nmlforce + frictforce + airforce + brakeforce + paddleforce;
|
||||
}
|
||||
|
@ -433,21 +433,21 @@ TVector3d CControl::CalcNetForce (const TVector3d& pos, const TVector3d& vel) {
|
|||
// ODE solver
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
double CControl::AdjustTimeStep (double h, const TVector3d& vel) {
|
||||
double CControl::AdjustTimeStep(double h, const TVector3d& vel) {
|
||||
double speed = vel.Length();
|
||||
h = clamp (MIN_TIME_STEP, h, MAX_STEP_DIST / speed);
|
||||
h = min (h, MAX_TIME_STEP);
|
||||
h = clamp(MIN_TIME_STEP, h, MAX_STEP_DIST / speed);
|
||||
h = min(h, MAX_TIME_STEP);
|
||||
return h;
|
||||
}
|
||||
|
||||
void CControl::SolveOdeSystem (double timestep) {
|
||||
void CControl::SolveOdeSystem(double timestep) {
|
||||
double pos_err[3], vel_err[3], tot_pos_err, tot_vel_err;
|
||||
double err=0, tol=0;
|
||||
|
||||
static const TOdeSolver solver;
|
||||
double h = ode_time_step;
|
||||
if (h < 0 || solver.EstimateError == NULL)
|
||||
h = AdjustTimeStep (timestep, cvel);
|
||||
h = AdjustTimeStep(timestep, cvel);
|
||||
double t = 0;
|
||||
double tfinal = timestep;
|
||||
|
||||
|
@ -465,7 +465,7 @@ void CControl::SolveOdeSystem (double timestep) {
|
|||
bool done = false;
|
||||
while (!done) {
|
||||
if (t >= tfinal) {
|
||||
Message ("t >= tfinal in ode_system()");
|
||||
Message("t >= tfinal in ode_system()");
|
||||
break;
|
||||
}
|
||||
if (1.1 * h > tfinal - t) {
|
||||
|
@ -478,55 +478,55 @@ void CControl::SolveOdeSystem (double timestep) {
|
|||
|
||||
bool failed = false;
|
||||
for (;;) {
|
||||
solver.InitOdeData (&x, new_pos.x, h);
|
||||
solver.InitOdeData (&y, new_pos.y, h);
|
||||
solver.InitOdeData (&z, new_pos.z, h);
|
||||
solver.InitOdeData (&vx, new_vel.x, h);
|
||||
solver.InitOdeData (&vy, new_vel.y, h);
|
||||
solver.InitOdeData (&vz, new_vel.z, h);
|
||||
solver.InitOdeData(&x, new_pos.x, h);
|
||||
solver.InitOdeData(&y, new_pos.y, h);
|
||||
solver.InitOdeData(&z, new_pos.z, h);
|
||||
solver.InitOdeData(&vx, new_vel.x, h);
|
||||
solver.InitOdeData(&vy, new_vel.y, h);
|
||||
solver.InitOdeData(&vz, new_vel.z, h);
|
||||
|
||||
solver.UpdateEstimate (&x, 0, new_vel.x);
|
||||
solver.UpdateEstimate (&y, 0, new_vel.y);
|
||||
solver.UpdateEstimate (&z, 0, new_vel.z);
|
||||
solver.UpdateEstimate (&vx, 0, new_f.x / TUX_MASS);
|
||||
solver.UpdateEstimate (&vy, 0, new_f.y / TUX_MASS);
|
||||
solver.UpdateEstimate (&vz, 0, new_f.z / TUX_MASS);
|
||||
solver.UpdateEstimate(&x, 0, new_vel.x);
|
||||
solver.UpdateEstimate(&y, 0, new_vel.y);
|
||||
solver.UpdateEstimate(&z, 0, new_vel.z);
|
||||
solver.UpdateEstimate(&vx, 0, new_f.x / TUX_MASS);
|
||||
solver.UpdateEstimate(&vy, 0, new_f.y / TUX_MASS);
|
||||
solver.UpdateEstimate(&vz, 0, new_f.z / TUX_MASS);
|
||||
|
||||
for (int i=1; i < solver.NumEstimates(); i++) {
|
||||
new_pos.x = solver.NextValue (&x, i);
|
||||
new_pos.y = solver.NextValue (&y, i);
|
||||
new_pos.z = solver.NextValue (&z, i);
|
||||
new_vel.x = solver.NextValue (&vx, i);
|
||||
new_vel.y = solver.NextValue (&vy, i);
|
||||
new_vel.z = solver.NextValue (&vz, i);
|
||||
new_pos.x = solver.NextValue(&x, i);
|
||||
new_pos.y = solver.NextValue(&y, i);
|
||||
new_pos.z = solver.NextValue(&z, i);
|
||||
new_vel.x = solver.NextValue(&vx, i);
|
||||
new_vel.y = solver.NextValue(&vy, i);
|
||||
new_vel.z = solver.NextValue(&vz, i);
|
||||
|
||||
solver.UpdateEstimate (&x, i, new_vel.x);
|
||||
solver.UpdateEstimate (&y, i, new_vel.y);
|
||||
solver.UpdateEstimate (&z, i, new_vel.z);
|
||||
solver.UpdateEstimate(&x, i, new_vel.x);
|
||||
solver.UpdateEstimate(&y, i, new_vel.y);
|
||||
solver.UpdateEstimate(&z, i, new_vel.z);
|
||||
|
||||
new_f = CalcNetForce (new_pos, new_vel);
|
||||
new_f = CalcNetForce(new_pos, new_vel);
|
||||
|
||||
solver.UpdateEstimate (&vx, i, new_f.x / TUX_MASS);
|
||||
solver.UpdateEstimate (&vy, i, new_f.y / TUX_MASS);
|
||||
solver.UpdateEstimate (&vz, i, new_f.z / TUX_MASS);
|
||||
solver.UpdateEstimate(&vx, i, new_f.x / TUX_MASS);
|
||||
solver.UpdateEstimate(&vy, i, new_f.y / TUX_MASS);
|
||||
solver.UpdateEstimate(&vz, i, new_f.z / TUX_MASS);
|
||||
}
|
||||
|
||||
new_pos.x = solver.FinalEstimate (&x);
|
||||
new_pos.y = solver.FinalEstimate (&y);
|
||||
new_pos.z = solver.FinalEstimate (&z);
|
||||
new_pos.x = solver.FinalEstimate(&x);
|
||||
new_pos.y = solver.FinalEstimate(&y);
|
||||
new_pos.z = solver.FinalEstimate(&z);
|
||||
|
||||
new_vel.x = solver.FinalEstimate (&vx);
|
||||
new_vel.y = solver.FinalEstimate (&vy);
|
||||
new_vel.z = solver.FinalEstimate (&vz);
|
||||
new_vel.x = solver.FinalEstimate(&vx);
|
||||
new_vel.y = solver.FinalEstimate(&vy);
|
||||
new_vel.z = solver.FinalEstimate(&vz);
|
||||
|
||||
if (solver.EstimateError != NULL) {
|
||||
pos_err[0] = solver.EstimateError (&x);
|
||||
pos_err[1] = solver.EstimateError (&y);
|
||||
pos_err[2] = solver.EstimateError (&z);
|
||||
pos_err[0] = solver.EstimateError(&x);
|
||||
pos_err[1] = solver.EstimateError(&y);
|
||||
pos_err[2] = solver.EstimateError(&z);
|
||||
|
||||
vel_err[0] = solver.EstimateError (&vx);
|
||||
vel_err[1] = solver.EstimateError (&vy);
|
||||
vel_err[2] = solver.EstimateError (&vz);
|
||||
vel_err[0] = solver.EstimateError(&vx);
|
||||
vel_err[1] = solver.EstimateError(&vy);
|
||||
vel_err[2] = solver.EstimateError(&vz);
|
||||
|
||||
tot_pos_err = 0.;
|
||||
tot_vel_err = 0.;
|
||||
|
@ -537,8 +537,8 @@ void CControl::SolveOdeSystem (double timestep) {
|
|||
vel_err[i] *= vel_err[i];
|
||||
tot_vel_err += vel_err[i];
|
||||
}
|
||||
tot_pos_err = sqrt (tot_pos_err);
|
||||
tot_vel_err = sqrt (tot_vel_err);
|
||||
tot_pos_err = sqrt(tot_pos_err);
|
||||
tot_vel_err = sqrt(tot_vel_err);
|
||||
if (tot_pos_err / MAX_POS_ERR > tot_vel_err / MAX_VEL_ERR) {
|
||||
err = tot_pos_err;
|
||||
tol = MAX_POS_ERR;
|
||||
|
@ -551,10 +551,10 @@ void CControl::SolveOdeSystem (double timestep) {
|
|||
done = false;
|
||||
if (!failed) {
|
||||
failed = true;
|
||||
h *= max (0.5, 0.8 * pow (tol/err, solver.TimestepExponent()));
|
||||
h *= max(0.5, 0.8 * pow(tol/err, solver.TimestepExponent()));
|
||||
} else h *= 0.5;
|
||||
|
||||
h = AdjustTimeStep (h, saved_vel);
|
||||
h = AdjustTimeStep(h, saved_vel);
|
||||
new_pos = saved_pos;
|
||||
new_vel = saved_vel;
|
||||
new_f = saved_f;
|
||||
|
@ -564,19 +564,19 @@ void CControl::SolveOdeSystem (double timestep) {
|
|||
|
||||
t = t + h;
|
||||
double speed = new_vel.Length();
|
||||
if (param.perf_level > 2) generate_particles (this, h, new_pos, speed);
|
||||
if (param.perf_level > 2) generate_particles(this, h, new_pos, speed);
|
||||
|
||||
new_f = CalcNetForce (new_pos, new_vel);
|
||||
new_f = CalcNetForce(new_pos, new_vel);
|
||||
|
||||
if (!failed && solver.EstimateError != NULL) {
|
||||
double temp = 1.25 * pow (err / tol, solver.TimestepExponent());
|
||||
double temp = 1.25 * pow(err / tol, solver.TimestepExponent());
|
||||
if (temp > 0.2) h = h / temp;
|
||||
else h = 5.0 * h;
|
||||
}
|
||||
h = AdjustTimeStep (h, new_vel);
|
||||
AdjustTreeCollision (new_pos, &new_vel);
|
||||
h = AdjustTimeStep(h, new_vel);
|
||||
AdjustTreeCollision(new_pos, &new_vel);
|
||||
// if (g_game.finish) new_vel = ScaleVector (0.99,new_vel);
|
||||
CheckItemCollection (new_pos);
|
||||
CheckItemCollection(new_pos);
|
||||
}
|
||||
ode_time_step = h;
|
||||
cnet_force = new_f;
|
||||
|
@ -593,7 +593,7 @@ void CControl::SolveOdeSystem (double timestep) {
|
|||
// update tux position
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void CControl::UpdatePlayerPos (double timestep) {
|
||||
void CControl::UpdatePlayerPos(double timestep) {
|
||||
CCharShape *shape = g_game.character->shape;
|
||||
double paddling_factor;
|
||||
double flap_factor;
|
||||
|
@ -609,17 +609,17 @@ void CControl::UpdatePlayerPos (double timestep) {
|
|||
minFrictspeed = MIN_FRICT_SPEED;
|
||||
}
|
||||
|
||||
if (timestep > 2 * EPS) SolveOdeSystem (timestep);
|
||||
if (timestep > 2 * EPS) SolveOdeSystem(timestep);
|
||||
|
||||
TPlane surf_plane = Course.GetLocalCoursePlane (cpos);
|
||||
TPlane surf_plane = Course.GetLocalCoursePlane(cpos);
|
||||
TVector3d surf_nml = surf_plane.nml; // normal vector of terrain
|
||||
dist_from_surface = DistanceToPlane (surf_plane, cpos);
|
||||
dist_from_surface = DistanceToPlane(surf_plane, cpos);
|
||||
|
||||
double speed = cvel.Length();
|
||||
AdjustVelocity ();
|
||||
AdjustPosition (surf_plane, dist_from_surface);
|
||||
SetTuxPosition (speed); // speed only to set finish_speed
|
||||
shape->AdjustOrientation (this, timestep, dist_from_surface, surf_nml);
|
||||
AdjustVelocity();
|
||||
AdjustPosition(surf_plane, dist_from_surface);
|
||||
SetTuxPosition(speed); // speed only to set finish_speed
|
||||
shape->AdjustOrientation(this, timestep, dist_from_surface, surf_nml);
|
||||
|
||||
flap_factor = 0;
|
||||
if (is_paddling) {
|
||||
|
@ -637,11 +637,11 @@ void CControl::UpdatePlayerPos (double timestep) {
|
|||
}
|
||||
|
||||
TVector3d local_force = RotateVector
|
||||
(ConjugateQuaternion (corientation), cnet_force);
|
||||
(ConjugateQuaternion(corientation), cnet_force);
|
||||
|
||||
if (jumping)
|
||||
flap_factor = (g_game.time - jump_start_time) / JUMP_FORCE_DURATION;
|
||||
|
||||
shape->AdjustJoints (turn_animation, is_braking, paddling_factor, speed,
|
||||
local_force, flap_factor);
|
||||
shape->AdjustJoints(turn_animation, is_braking, paddling_factor, speed,
|
||||
local_force, flap_factor);
|
||||
}
|
||||
|
|
|
@ -81,29 +81,29 @@ private:
|
|||
double ode_time_step;
|
||||
double finish_speed;
|
||||
|
||||
bool CheckTreeCollisions (const TVector3d& pos, TVector3d *tree_loc);
|
||||
void AdjustTreeCollision (const TVector3d& pos, TVector3d *vel);
|
||||
void CheckItemCollection (const TVector3d& pos);
|
||||
bool CheckTreeCollisions(const TVector3d& pos, TVector3d *tree_loc);
|
||||
void AdjustTreeCollision(const TVector3d& pos, TVector3d *vel);
|
||||
void CheckItemCollection(const TVector3d& pos);
|
||||
|
||||
TVector3d CalcRollNormal (double speed);
|
||||
TVector3d CalcAirForce ();
|
||||
TVector3d CalcSpringForce ();
|
||||
TVector3d CalcNormalForce ();
|
||||
TVector3d CalcJumpForce ();
|
||||
TVector3d CalcFrictionForce (double speed, const TVector3d& nmlforce);
|
||||
TVector3d CalcPaddleForce (double speed);
|
||||
TVector3d CalcBrakeForce (double speed);
|
||||
TVector3d CalcGravitationForce ();
|
||||
TVector3d CalcNetForce (const TVector3d& pos, const TVector3d& vel);
|
||||
TVector3d CalcFinishForce (const TVector3d& pos, const TVector3d& vel);
|
||||
TVector3d CalcRollNormal(double speed);
|
||||
TVector3d CalcAirForce();
|
||||
TVector3d CalcSpringForce();
|
||||
TVector3d CalcNormalForce();
|
||||
TVector3d CalcJumpForce();
|
||||
TVector3d CalcFrictionForce(double speed, const TVector3d& nmlforce);
|
||||
TVector3d CalcPaddleForce(double speed);
|
||||
TVector3d CalcBrakeForce(double speed);
|
||||
TVector3d CalcGravitationForce();
|
||||
TVector3d CalcNetForce(const TVector3d& pos, const TVector3d& vel);
|
||||
TVector3d CalcFinishForce(const TVector3d& pos, const TVector3d& vel);
|
||||
|
||||
void AdjustVelocity ();
|
||||
void AdjustPosition (const TPlane& surf_plane, double dist_from_surface);
|
||||
void SetTuxPosition (double speed);
|
||||
double AdjustTimeStep (double h, const TVector3d& vel);
|
||||
void SolveOdeSystem (double timestep);
|
||||
void AdjustVelocity();
|
||||
void AdjustPosition(const TPlane& surf_plane, double dist_from_surface);
|
||||
void SetTuxPosition(double speed);
|
||||
double AdjustTimeStep(double h, const TVector3d& vel);
|
||||
void SolveOdeSystem(double timestep);
|
||||
public:
|
||||
CControl ();
|
||||
CControl();
|
||||
|
||||
// view:
|
||||
TViewMode viewmode;
|
||||
|
@ -147,8 +147,8 @@ public:
|
|||
double minSpeed;
|
||||
double minFrictspeed;
|
||||
|
||||
void Init ();
|
||||
void UpdatePlayerPos (double timestep);
|
||||
void Init();
|
||||
void UpdatePlayerPos(double timestep);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
140
src/quadtree.cpp
140
src/quadtree.cpp
|
@ -61,7 +61,7 @@ GLuint quadsquare::VertexArrayCounter;
|
|||
GLuint quadsquare::VertexArrayMinIdx;
|
||||
GLuint quadsquare::VertexArrayMaxIdx;
|
||||
|
||||
quadsquare::quadsquare (quadcornerdata* pcd) {
|
||||
quadsquare::quadsquare(quadcornerdata* pcd) {
|
||||
pcd->Square = this;
|
||||
Static = false;
|
||||
ForceEastVert = false;
|
||||
|
@ -103,7 +103,7 @@ quadsquare::~quadsquare() {
|
|||
}
|
||||
}
|
||||
|
||||
void quadsquare::SetStatic (const quadcornerdata &cd) {
|
||||
void quadsquare::SetStatic(const quadcornerdata &cd) {
|
||||
if (Static == false) {
|
||||
Static = true;
|
||||
if (cd.Parent && cd.Parent->Square) {
|
||||
|
@ -356,7 +356,7 @@ float quadsquare::RecomputeError(const quadcornerdata& cd) {
|
|||
if (total > 0) {
|
||||
terrain_error = (1.0 - max_count / total);
|
||||
if (numTerr > 1) {
|
||||
terrain_error *= numTerr / (numTerr - 1.0);
|
||||
terrain_error *= numTerr / (numTerr - 1.0);
|
||||
}
|
||||
} else terrain_error = 0;
|
||||
terrain_error *= whole * whole;
|
||||
|
@ -567,10 +567,10 @@ static float DetailThreshold = 100;
|
|||
|
||||
bool quadsquare::VertexTest(int x, float y, int z, float error,
|
||||
const float Viewer[3], int level, vertex_loc_t vertex_loc) {
|
||||
float dx = fabs(x - Viewer[0]) * fabs (ScaleX);
|
||||
float dx = fabs(x - Viewer[0]) * fabs(ScaleX);
|
||||
float dy = fabs(y - Viewer[1]);
|
||||
float dz = fabs(z - Viewer[2]) * fabs (ScaleZ);
|
||||
float d = max (dx, max (dy, dz) );
|
||||
float dz = fabs(z - Viewer[2]) * fabs(ScaleZ);
|
||||
float d = max(dx, max(dy, dz));
|
||||
|
||||
if (vertex_loc == South && ForceSouthVert && d < VERTEX_FORCE_THRESHOLD) {
|
||||
return true;
|
||||
|
@ -587,10 +587,10 @@ bool quadsquare::VertexTest(int x, float y, int z, float error,
|
|||
|
||||
bool quadsquare::BoxTest(int x, int z, float size, float miny, float maxy, float error, const float Viewer[3]) {
|
||||
float half = size * 0.5;
|
||||
float dx = (fabs(x + half - Viewer[0]) - half ) * fabs(ScaleX);
|
||||
float dx = (fabs(x + half - Viewer[0]) - half) * fabs(ScaleX);
|
||||
float dy = fabs((miny + maxy) * 0.5 - Viewer[1]) - (maxy - miny) * 0.5;
|
||||
float dz = (fabs(z + half - Viewer[2]) - half ) * fabs(ScaleZ);
|
||||
float d = max (dx, max (dy , dz) );
|
||||
float dz = (fabs(z + half - Viewer[2]) - half) * fabs(ScaleZ);
|
||||
float d = max(dx, max(dy , dz));
|
||||
|
||||
if (d < ERROR_MAGNIFICATION_THRESHOLD) {
|
||||
error *= ERROR_MAGNIFICATION_AMOUNT;
|
||||
|
@ -599,15 +599,15 @@ bool quadsquare::BoxTest(int x, int z, float size, float miny, float maxy, float
|
|||
if (error * DetailThreshold > d) {
|
||||
return true;
|
||||
}
|
||||
if ( (x < RowSize-1 && x+size >= RowSize) ||
|
||||
(z < NumRows-1 && z+size >= NumRows) ) {
|
||||
if ((x < RowSize-1 && x+size >= RowSize) ||
|
||||
(z < NumRows-1 && z+size >= NumRows)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void quadsquare::Update (const quadcornerdata& cd, const TVector3d& ViewerLocation, float Detail) {
|
||||
void quadsquare::Update(const quadcornerdata& cd, const TVector3d& ViewerLocation, float Detail) {
|
||||
float Viewer[3];
|
||||
|
||||
DetailThreshold = Detail;
|
||||
|
@ -618,10 +618,10 @@ void quadsquare::Update (const quadcornerdata& cd, const TVector3d& ViewerLocati
|
|||
}
|
||||
|
||||
|
||||
void quadsquare::UpdateAux (const quadcornerdata& cd,
|
||||
const float ViewerLocation[3], float CenterError, clip_result_t vis) {
|
||||
void quadsquare::UpdateAux(const quadcornerdata& cd,
|
||||
const float ViewerLocation[3], float CenterError, clip_result_t vis) {
|
||||
if (vis != NoClip) {
|
||||
vis = ClipSquare (cd);
|
||||
vis = ClipSquare(cd);
|
||||
|
||||
if (vis == NotVisible) {
|
||||
return;
|
||||
|
@ -635,13 +635,13 @@ void quadsquare::UpdateAux (const quadcornerdata& cd,
|
|||
int whole = half << 1;
|
||||
if ((EnabledFlags & 1) == 0 &&
|
||||
VertexTest(cd.xorg + whole, Vertex[1].Y, cd.zorg + half,
|
||||
Error[0], ViewerLocation, cd.Level, East) == true ) {
|
||||
Error[0], ViewerLocation, cd.Level, East) == true) {
|
||||
EnableEdgeVertex(0, false, cd);
|
||||
}
|
||||
|
||||
if ((EnabledFlags & 8) == 0 &&
|
||||
VertexTest(cd.xorg + half, Vertex[4].Y, cd.zorg + whole,
|
||||
Error[1], ViewerLocation, cd.Level, South) == true ) {
|
||||
Error[1], ViewerLocation, cd.Level, South) == true) {
|
||||
EnableEdgeVertex(3, false, cd);
|
||||
}
|
||||
|
||||
|
@ -728,11 +728,11 @@ void quadsquare::DrawTris() {
|
|||
|
||||
if (glLockArraysEXT_p) {
|
||||
if (tmp_min_idx == 0) tmp_min_idx = 1;
|
||||
glLockArraysEXT_p (tmp_min_idx, VertexArrayMaxIdx - tmp_min_idx + 1);
|
||||
glLockArraysEXT_p(tmp_min_idx, VertexArrayMaxIdx - tmp_min_idx + 1);
|
||||
}
|
||||
|
||||
glDrawElements (GL_TRIANGLES, VertexArrayCounter,
|
||||
GL_UNSIGNED_INT, VertexArrayIndices);
|
||||
glDrawElements(GL_TRIANGLES, VertexArrayCounter,
|
||||
GL_UNSIGNED_INT, VertexArrayIndices);
|
||||
if (glUnlockArraysEXT_p) glUnlockArraysEXT_p();
|
||||
}
|
||||
|
||||
|
@ -742,11 +742,11 @@ void quadsquare::InitArrayCounters() {
|
|||
VertexArrayMaxIdx = 0;
|
||||
}
|
||||
|
||||
void quadsquare::Render (const quadcornerdata& cd, GLubyte *vnc_array) {
|
||||
void quadsquare::Render(const quadcornerdata& cd, GLubyte *vnc_array) {
|
||||
VNCArray = vnc_array;
|
||||
bool fog_on;
|
||||
int nx, ny;
|
||||
Course.GetDivisions (&nx, &ny);
|
||||
Course.GetDivisions(&nx, &ny);
|
||||
const TTerrType *TerrList = &Course.TerrList[0];
|
||||
|
||||
size_t numTerrains = Course.TerrList.size();
|
||||
|
@ -755,34 +755,34 @@ void quadsquare::Render (const quadcornerdata& cd, GLubyte *vnc_array) {
|
|||
for (size_t j=0; j<numTerrains; j++) {
|
||||
if (TerrList[j].texture != NULL) {
|
||||
InitArrayCounters();
|
||||
RenderAux (cd, SomeClip, (int)j);
|
||||
RenderAux(cd, SomeClip, (int)j);
|
||||
if (VertexArrayCounter == 0) continue;
|
||||
|
||||
Course.TerrList[j].texture->Bind();
|
||||
DrawTris ();
|
||||
DrawTris();
|
||||
}
|
||||
}
|
||||
|
||||
if (param.perf_level > 1) {
|
||||
InitArrayCounters();
|
||||
RenderAux (cd, SomeClip, -1);
|
||||
RenderAux(cd, SomeClip, -1);
|
||||
|
||||
if (VertexArrayCounter != 0) {
|
||||
glDisable (GL_FOG);
|
||||
glDisable(GL_FOG);
|
||||
for (GLuint i=0; i<VertexArrayCounter; i++) {
|
||||
colorval (VertexArrayIndices[i], 0) = 0;
|
||||
colorval (VertexArrayIndices[i], 1) = 0;
|
||||
colorval (VertexArrayIndices[i], 2) = 0;
|
||||
colorval (VertexArrayIndices[i], 3) = 255;
|
||||
colorval(VertexArrayIndices[i], 0) = 0;
|
||||
colorval(VertexArrayIndices[i], 1) = 0;
|
||||
colorval(VertexArrayIndices[i], 2) = 0;
|
||||
colorval(VertexArrayIndices[i], 3) = 255;
|
||||
}
|
||||
Course.TerrList[0].texture->Bind();
|
||||
DrawTris();
|
||||
if (fog_on) glEnable (GL_FOG);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE);
|
||||
if (fog_on) glEnable(GL_FOG);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
for (GLuint i=0; i<VertexArrayCounter; i++) {
|
||||
colorval (VertexArrayIndices[i], 0) = 255;
|
||||
colorval (VertexArrayIndices[i], 1) = 255;
|
||||
colorval (VertexArrayIndices[i], 2) = 255;
|
||||
colorval(VertexArrayIndices[i], 0) = 255;
|
||||
colorval(VertexArrayIndices[i], 1) = 255;
|
||||
colorval(VertexArrayIndices[i], 2) = 255;
|
||||
}
|
||||
|
||||
for (size_t j=0; j<numTerrains; j++) {
|
||||
|
@ -790,18 +790,18 @@ void quadsquare::Render (const quadcornerdata& cd, GLubyte *vnc_array) {
|
|||
Course.TerrList[j].texture->Bind();
|
||||
|
||||
for (GLuint i=0; i<VertexArrayCounter; i++) {
|
||||
colorval (VertexArrayIndices[i], 3) =
|
||||
(Terrain[VertexArrayIndices[i]] == (char)j ) ? 255 : 0;
|
||||
colorval(VertexArrayIndices[i], 3) =
|
||||
(Terrain[VertexArrayIndices[i]] == (char)j) ? 255 : 0;
|
||||
}
|
||||
DrawTris();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
clip_result_t quadsquare::ClipSquare (const quadcornerdata& cd) {
|
||||
clip_result_t quadsquare::ClipSquare(const quadcornerdata& cd) {
|
||||
if (cd.xorg >= RowSize-1) {
|
||||
return NotVisible;
|
||||
}
|
||||
|
@ -847,52 +847,52 @@ clip_result_t quadsquare::ClipSquare (const quadcornerdata& cd) {
|
|||
}
|
||||
|
||||
|
||||
inline void quadsquare::MakeTri (int a, int b, int c, int terrain) {
|
||||
if ( (VertexTerrains[a] == terrain ||
|
||||
inline void quadsquare::MakeTri(int a, int b, int c, int terrain) {
|
||||
if ((VertexTerrains[a] == terrain ||
|
||||
VertexTerrains[b] == terrain ||
|
||||
VertexTerrains[c] == terrain) ) {
|
||||
VertexTerrains[c] == terrain)) {
|
||||
VertexArrayIndices[VertexArrayCounter++] = VertexIndices[a];
|
||||
setalphaval(a);
|
||||
update_min_max (VertexIndices[a]);
|
||||
update_min_max(VertexIndices[a]);
|
||||
VertexArrayIndices[VertexArrayCounter++] = VertexIndices[b];
|
||||
setalphaval(b);
|
||||
update_min_max (VertexIndices[b]);
|
||||
update_min_max(VertexIndices[b]);
|
||||
VertexArrayIndices[VertexArrayCounter++] = VertexIndices[c];
|
||||
setalphaval(c);
|
||||
update_min_max (VertexIndices[c]);
|
||||
update_min_max(VertexIndices[c]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void quadsquare::MakeSpecialTri (int a, int b, int c, int terrain) {
|
||||
inline void quadsquare::MakeSpecialTri(int a, int b, int c, int terrain) {
|
||||
if (VertexTerrains[a] != VertexTerrains[b] &&
|
||||
VertexTerrains[a] != VertexTerrains[c] &&
|
||||
VertexTerrains[b] != VertexTerrains[c]) {
|
||||
VertexArrayIndices[VertexArrayCounter++] = VertexIndices[a];
|
||||
update_min_max (VertexIndices[a]);
|
||||
update_min_max(VertexIndices[a]);
|
||||
VertexArrayIndices[VertexArrayCounter++] = VertexIndices[b];
|
||||
update_min_max (VertexIndices[b]);
|
||||
update_min_max(VertexIndices[b]);
|
||||
VertexArrayIndices[VertexArrayCounter++] = VertexIndices[c];
|
||||
update_min_max (VertexIndices[c]);
|
||||
update_min_max(VertexIndices[c]);
|
||||
}
|
||||
}
|
||||
|
||||
inline void quadsquare::MakeNoBlendTri (int a, int b, int c, int terrain) {
|
||||
if ( (VertexTerrains[a] == terrain ||
|
||||
inline void quadsquare::MakeNoBlendTri(int a, int b, int c, int terrain) {
|
||||
if ((VertexTerrains[a] == terrain ||
|
||||
VertexTerrains[b] == terrain ||
|
||||
VertexTerrains[c] == terrain) &&
|
||||
(VertexTerrains[a] >= terrain &&
|
||||
VertexTerrains[b] >= terrain &&
|
||||
VertexTerrains[c] >= terrain) ) {
|
||||
VertexTerrains[c] >= terrain)) {
|
||||
VertexArrayIndices[VertexArrayCounter++] = VertexIndices[a];
|
||||
setalphaval(a);
|
||||
update_min_max (VertexIndices[a]);
|
||||
update_min_max(VertexIndices[a]);
|
||||
VertexArrayIndices[VertexArrayCounter++] = VertexIndices[b];
|
||||
setalphaval(b);
|
||||
update_min_max (VertexIndices[b]);
|
||||
update_min_max(VertexIndices[b]);
|
||||
VertexArrayIndices[VertexArrayCounter++] = VertexIndices[c];
|
||||
setalphaval(c);
|
||||
update_min_max (VertexIndices[c]);
|
||||
update_min_max(VertexIndices[c]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -900,7 +900,7 @@ void quadsquare::RenderAux(const quadcornerdata& cd, clip_result_t vis, int terr
|
|||
int half = 1 << cd.Level;
|
||||
int whole = 2 << cd.Level;
|
||||
if (vis != NoClip) {
|
||||
vis = ClipSquare (cd);
|
||||
vis = ClipSquare(cd);
|
||||
if (vis == NotVisible) return;
|
||||
}
|
||||
|
||||
|
@ -1058,7 +1058,7 @@ void quadsquare::SetScale(double x, double z) {
|
|||
}
|
||||
|
||||
char* quadsquare::Terrain;
|
||||
void quadsquare::SetTerrain (char *t) {
|
||||
void quadsquare::SetTerrain(char *t) {
|
||||
Terrain = t;
|
||||
}
|
||||
|
||||
|
@ -1088,16 +1088,16 @@ void ResetQuadtree() {
|
|||
}
|
||||
}
|
||||
|
||||
static int get_root_level (int nx, int nz) {
|
||||
int xlev = (int) (log(static_cast<double>(nx)) / log (2.0));
|
||||
int zlev = (int) (log(static_cast<double>(nz)) / log (2.0));
|
||||
static int get_root_level(int nx, int nz) {
|
||||
int xlev = (int)(log(static_cast<double>(nx)) / log(2.0));
|
||||
int zlev = (int)(log(static_cast<double>(nz)) / log(2.0));
|
||||
|
||||
return max (xlev, zlev);
|
||||
return max(xlev, zlev);
|
||||
}
|
||||
|
||||
|
||||
void InitQuadtree (double *elevation, int nx, int nz,
|
||||
double scalex, double scalez, const TVector3d& view_pos, double detail) {
|
||||
void InitQuadtree(double *elevation, int nx, int nz,
|
||||
double scalex, double scalez, const TVector3d& view_pos, double detail) {
|
||||
HeightMapInfo hm;
|
||||
|
||||
hm.Data = elevation;
|
||||
|
@ -1110,7 +1110,7 @@ void InitQuadtree (double *elevation, int nx, int nz,
|
|||
|
||||
root_corner_data.Square = (quadsquare*)NULL;
|
||||
root_corner_data.ChildIndex = 0;
|
||||
root_corner_data.Level = get_root_level (nx, nz);
|
||||
root_corner_data.Level = get_root_level(nx, nz);
|
||||
root_corner_data.xorg = 0;
|
||||
root_corner_data.zorg = 0;
|
||||
|
||||
|
@ -1119,19 +1119,19 @@ void InitQuadtree (double *elevation, int nx, int nz,
|
|||
root_corner_data.Verts[i].Y = 0;
|
||||
}
|
||||
|
||||
root = new quadsquare (&root_corner_data);
|
||||
root->AddHeightMap (root_corner_data, hm);
|
||||
root->SetScale (scalex, scalez);
|
||||
root->SetTerrain (Course.terrain);
|
||||
root = new quadsquare(&root_corner_data);
|
||||
root->AddHeightMap(root_corner_data, hm);
|
||||
root->SetScale(scalex, scalez);
|
||||
root->SetTerrain(Course.terrain);
|
||||
|
||||
root->StaticCullData (root_corner_data, CULL_DETAIL_FACTOR);
|
||||
root->StaticCullData(root_corner_data, CULL_DETAIL_FACTOR);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
root->Update(root_corner_data, view_pos, detail);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateQuadtree (const TVector3d& view_pos, float detail) {
|
||||
void UpdateQuadtree(const TVector3d& view_pos, float detail) {
|
||||
root->Update(root_corner_data, view_pos, detail);
|
||||
}
|
||||
|
||||
|
|
|
@ -77,14 +77,14 @@ struct quadsquare {
|
|||
static GLuint VertexArrayMinIdx;
|
||||
static GLuint VertexArrayMaxIdx;
|
||||
|
||||
static void MakeTri( int a, int b, int c, int terrain );
|
||||
static void MakeSpecialTri( int a, int b, int c, int terrain );
|
||||
static void MakeNoBlendTri( int a, int b, int c, int terrain );
|
||||
static void MakeTri(int a, int b, int c, int terrain);
|
||||
static void MakeSpecialTri(int a, int b, int c, int terrain);
|
||||
static void MakeNoBlendTri(int a, int b, int c, int terrain);
|
||||
|
||||
static void DrawTris();
|
||||
static void InitArrayCounters();
|
||||
|
||||
quadsquare (quadcornerdata* pcd);
|
||||
quadsquare(quadcornerdata* pcd);
|
||||
~quadsquare();
|
||||
|
||||
void AddHeightMap(const quadcornerdata& cd, const HeightMapInfo& hm);
|
||||
|
@ -95,29 +95,29 @@ struct quadsquare {
|
|||
void Render(const quadcornerdata& cd, GLubyte *vnc_array);
|
||||
float GetHeight(const quadcornerdata& cd, float x, float z);
|
||||
void SetScale(double x, double z);
|
||||
void SetTerrain (char *terrain);
|
||||
void SetTerrain(char *terrain);
|
||||
|
||||
private:
|
||||
quadsquare* EnableDescendant(int count, int stack[],
|
||||
const quadcornerdata& cd);
|
||||
quadsquare* GetNeighbor(int dir, const quadcornerdata &cd);
|
||||
clip_result_t ClipSquare( const quadcornerdata &cd );
|
||||
clip_result_t ClipSquare(const quadcornerdata &cd);
|
||||
|
||||
void EnableEdgeVertex(int index, bool IncrementCount,
|
||||
const quadcornerdata &cd);
|
||||
void EnableChild(int index, const quadcornerdata &cd);
|
||||
void NotifyChildDisable(const quadcornerdata& cd, int index);
|
||||
void ResetTree();
|
||||
void StaticCullAux (const quadcornerdata &cd, float ThresholdDetail,
|
||||
int TargetLevel);
|
||||
void StaticCullAux(const quadcornerdata &cd, float ThresholdDetail,
|
||||
int TargetLevel);
|
||||
void CreateChild(int index, const quadcornerdata &cd);
|
||||
void SetupCornerData (quadcornerdata *q, const quadcornerdata &pd,
|
||||
int ChildIndex);
|
||||
void SetupCornerData(quadcornerdata *q, const quadcornerdata &pd,
|
||||
int ChildIndex);
|
||||
void UpdateAux(const quadcornerdata &cd, const float ViewerLocation[3],
|
||||
float CenterError, clip_result_t vis);
|
||||
void RenderAux(const quadcornerdata &cd, clip_result_t vis,
|
||||
int terrain);
|
||||
void SetStatic (const quadcornerdata &cd);
|
||||
void SetStatic(const quadcornerdata &cd);
|
||||
void InitVert(int i, int x, int z);
|
||||
bool VertexTest(int x, float y, int z, float error, const float Viewer[3],
|
||||
int level, vertex_loc_t vertex_loc);
|
||||
|
@ -130,11 +130,11 @@ private:
|
|||
// --------------------------------------------------------------------
|
||||
|
||||
void ResetQuadtree();
|
||||
void InitQuadtree (double *elevation, int nx, int nz,
|
||||
double scalex, double scalez,
|
||||
const TVector3d& view_pos, double detail);
|
||||
void InitQuadtree(double *elevation, int nx, int nz,
|
||||
double scalex, double scalez,
|
||||
const TVector3d& view_pos, double detail);
|
||||
|
||||
void UpdateQuadtree (const TVector3d& view_pos, float detail);
|
||||
void UpdateQuadtree(const TVector3d& view_pos, float detail);
|
||||
void RenderQuadtree();
|
||||
|
||||
|
||||
|
|
|
@ -72,34 +72,34 @@ void SetRaceConditions() {
|
|||
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);
|
||||
State::manager.RequestEnterState(Loading);
|
||||
}
|
||||
|
||||
void CRaceSelect::Motion (int x, int y) {
|
||||
void CRaceSelect::Motion(int x, int y) {
|
||||
MouseMoveGUI(x, y);
|
||||
|
||||
if (param.ui_snow) push_ui_snow (cursor_pos);
|
||||
if (param.ui_snow) push_ui_snow(cursor_pos);
|
||||
|
||||
UpdateInfo ();
|
||||
UpdateInfo();
|
||||
}
|
||||
|
||||
void CRaceSelect::Mouse (int button, int state, int x, int y) {
|
||||
void CRaceSelect::Mouse(int button, int state, int x, int y) {
|
||||
if (state == 1) {
|
||||
ClickGUI(x, y);
|
||||
|
||||
if (textbuttons[0]->focussed())
|
||||
SetRaceConditions ();
|
||||
SetRaceConditions();
|
||||
else if (textbuttons[1]->focussed())
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
State::manager.RequestEnterState(GameTypeSelect);
|
||||
|
||||
if (random_btn->focussed()) {
|
||||
mirror->SetValue(IRandom (0, 1));
|
||||
light->SetValue(IRandom (0, 3));
|
||||
snow->SetValue(IRandom (0, 3));
|
||||
wind->SetValue(IRandom (0, 3));
|
||||
mirror->SetValue(IRandom(0, 1));
|
||||
light->SetValue(IRandom(0, 3));
|
||||
snow->SetValue(IRandom(0, 3));
|
||||
wind->SetValue(IRandom(0, 3));
|
||||
}
|
||||
|
||||
UpdateInfo ();
|
||||
UpdateInfo();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ void CRaceSelect::Keyb(sf::Keyboard::Key key, bool special, bool release, int x,
|
|||
KeyGUI(key, 0, release);
|
||||
switch (key) {
|
||||
case sf::Keyboard::Escape:
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
State::manager.RequestEnterState(GameTypeSelect);
|
||||
break;
|
||||
case sf::Keyboard::U:
|
||||
param.ui_snow = !param.ui_snow;
|
||||
|
@ -126,9 +126,9 @@ void CRaceSelect::Keyb(sf::Keyboard::Key key, bool special, bool release, int x,
|
|||
break;
|
||||
case sf::Keyboard::Return:
|
||||
if (textbuttons[1]->focussed())
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
State::manager.RequestEnterState(GameTypeSelect);
|
||||
else
|
||||
SetRaceConditions ();
|
||||
SetRaceConditions();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -140,39 +140,39 @@ static int prevtop, prevwidth, prevheight;
|
|||
static int boxleft, boxwidth;
|
||||
|
||||
void CRaceSelect::Enter() {
|
||||
Winsys.ShowCursor (!param.ice_cursor);
|
||||
Winsys.ShowCursor(!param.ice_cursor);
|
||||
Music.Play(param.menu_music, true);
|
||||
|
||||
CourseList = &Course.CourseList[0];
|
||||
|
||||
framewidth = 550 * Winsys.scale;
|
||||
frameheight = 50 * Winsys.scale;
|
||||
frametop = AutoYPosN (30);
|
||||
frametop = AutoYPosN(30);
|
||||
|
||||
area = AutoAreaN (30, 80, framewidth);
|
||||
prevtop = AutoYPosN (50);
|
||||
area = AutoAreaN(30, 80, framewidth);
|
||||
prevtop = AutoYPosN(50);
|
||||
prevheight = 144 * Winsys.scale;
|
||||
prevwidth = 192 * Winsys.scale;
|
||||
boxwidth = framewidth - prevwidth - 20;
|
||||
boxleft = area.right - boxwidth;
|
||||
int icontop = AutoYPosN(40);
|
||||
int iconsize = 32 * Winsys.scale;
|
||||
int iconspace = (int) ((iconsize + 6) * 1.5);
|
||||
int iconspace = (int)((iconsize + 6) * 1.5);
|
||||
int iconsumwidth = iconspace * 4 + iconsize;
|
||||
int iconleft = (Winsys.resolution.width - iconsumwidth) / 2;
|
||||
|
||||
ResetGUI ();
|
||||
ResetGUI();
|
||||
|
||||
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);
|
||||
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.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));
|
||||
textbuttons[0] = AddTextButton (Trans.Text(13), area.right-len1-50, AutoYPosN (80), siz);
|
||||
int siz = FT.AutoSizeN(5);
|
||||
int len1 = FT.GetTextWidth(Trans.Text(13));
|
||||
textbuttons[0] = AddTextButton(Trans.Text(13), area.right-len1-50, AutoYPosN(80), siz);
|
||||
textbuttons[1] = AddTextButton(Trans.Text(8), area.left + 50, AutoYPosN(80), siz);
|
||||
FT.AutoSizeN(4);
|
||||
name = AddFramedText(area.left, frametop, framewidth, frameheight, 3, colMBackgr, "", FT.GetSize(), true);
|
||||
|
@ -183,8 +183,8 @@ void CRaceSelect::Loop(double timestep) {
|
|||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow (timestep);
|
||||
draw_ui_snow ();
|
||||
update_ui_snow(timestep);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
DrawGUIBackground(1.0);
|
||||
|
@ -196,28 +196,28 @@ void CRaceSelect::Loop(double timestep) {
|
|||
if (CourseList[course->GetValue()].preview)
|
||||
CourseList[course->GetValue()].preview->DrawFrame(area.left + 3, prevtop, prevwidth, prevheight, 3, colWhite);
|
||||
|
||||
DrawFrameX (area.right-boxwidth, prevtop-3, boxwidth, prevheight+6, 3, colBackgr, colWhite, 1.0);
|
||||
FT.AutoSizeN (2);
|
||||
FT.SetColor (colWhite);
|
||||
int dist = FT.AutoDistanceN (0);
|
||||
DrawFrameX(area.right-boxwidth, prevtop-3, boxwidth, prevheight+6, 3, colBackgr, colWhite, 1.0);
|
||||
FT.AutoSizeN(2);
|
||||
FT.SetColor(colWhite);
|
||||
int dist = FT.AutoDistanceN(0);
|
||||
for (size_t i=0; i<CourseList[course->GetValue()].num_lines; i++) {
|
||||
FT.DrawString (boxleft+8, prevtop+i*dist, CourseList[course->GetValue()].desc[i]);
|
||||
FT.DrawString(boxleft+8, prevtop+i*dist, CourseList[course->GetValue()].desc[i]);
|
||||
}
|
||||
|
||||
FT.DrawString (CENTER, prevtop + prevheight + 10, "Author: " + CourseList[course->GetValue()].author);
|
||||
FT.DrawString(CENTER, prevtop + prevheight + 10, "Author: " + CourseList[course->GetValue()].author);
|
||||
|
||||
FT.DrawString (CENTER, AutoYPosN (45), info);
|
||||
FT.DrawString(CENTER, AutoYPosN(45), info);
|
||||
|
||||
if (g_game.force_treemap) {
|
||||
FT.AutoSizeN (4);
|
||||
FT.AutoSizeN(4);
|
||||
static const string forcetrees = "Load trees.png";
|
||||
string sizevar = "Size: ";
|
||||
sizevar += Int_StrN (g_game.treesize);
|
||||
sizevar += Int_StrN(g_game.treesize);
|
||||
sizevar += " Variation: ";
|
||||
sizevar += Int_StrN (g_game.treevar);
|
||||
FT.SetColor (colYellow);
|
||||
FT.DrawString (CENTER, AutoYPosN (85), forcetrees);
|
||||
FT.DrawString (CENTER, AutoYPosN (90), sizevar);
|
||||
sizevar += Int_StrN(g_game.treevar);
|
||||
FT.SetColor(colYellow);
|
||||
FT.DrawString(CENTER, AutoYPosN(85), forcetrees);
|
||||
FT.DrawString(CENTER, AutoYPosN(90), sizevar);
|
||||
}
|
||||
|
||||
DrawGUI();
|
||||
|
|
142
src/racing.cpp
142
src/racing.cpp
|
@ -66,7 +66,7 @@ static bool trees = true;
|
|||
static int newsound = -1;
|
||||
static int lastsound = -1;
|
||||
|
||||
void CRacing::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CRacing::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
switch (key) {
|
||||
// steering flipflops
|
||||
case sf::Keyboard::Up:
|
||||
|
@ -92,35 +92,35 @@ void CRacing::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, in
|
|||
if (!release) {
|
||||
g_game.raceaborted = true;
|
||||
g_game.race_result = -1;
|
||||
State::manager.RequestEnterState (GameOver);
|
||||
State::manager.RequestEnterState(GameOver);
|
||||
}
|
||||
break;
|
||||
case sf::Keyboard::P:
|
||||
if (!release) State::manager.RequestEnterState (Paused);
|
||||
if (!release) State::manager.RequestEnterState(Paused);
|
||||
break;
|
||||
case sf::Keyboard::R:
|
||||
if (!release) State::manager.RequestEnterState (Reset);
|
||||
if (!release) State::manager.RequestEnterState(Reset);
|
||||
break;
|
||||
case sf::Keyboard::S:
|
||||
if (!release) ScreenshotN ();
|
||||
if (!release) ScreenshotN();
|
||||
break;
|
||||
|
||||
// view changing
|
||||
case sf::Keyboard::Num1:
|
||||
if (!release) {
|
||||
set_view_mode (g_game.player->ctrl, ABOVE);
|
||||
set_view_mode(g_game.player->ctrl, ABOVE);
|
||||
param.view_mode = ABOVE;
|
||||
}
|
||||
break;
|
||||
case sf::Keyboard::Num2:
|
||||
if (!release) {
|
||||
set_view_mode (g_game.player->ctrl, FOLLOW);
|
||||
set_view_mode(g_game.player->ctrl, FOLLOW);
|
||||
param.view_mode = FOLLOW;
|
||||
}
|
||||
break;
|
||||
case sf::Keyboard::Num3:
|
||||
if (!release) {
|
||||
set_view_mode (g_game.player->ctrl, BEHIND);
|
||||
set_view_mode(g_game.player->ctrl, BEHIND);
|
||||
param.view_mode = BEHIND;
|
||||
}
|
||||
break;
|
||||
|
@ -147,7 +147,7 @@ void CRacing::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, in
|
|||
}
|
||||
}
|
||||
|
||||
void CRacing::Jaxis (int axis, float value) {
|
||||
void CRacing::Jaxis(int axis, float value) {
|
||||
if (axis == 0) { // left and right
|
||||
stick_turn = ((value < -0.2) || (value > 0.2));
|
||||
if (stick_turn) stick_turnfact = value;
|
||||
|
@ -158,7 +158,7 @@ void CRacing::Jaxis (int axis, float value) {
|
|||
}
|
||||
}
|
||||
|
||||
void CRacing::Jbutt (int button, int state) {
|
||||
void CRacing::Jbutt(int button, int state) {
|
||||
if (button == 0) {
|
||||
key_charging = state != 0;
|
||||
} else if (button == 1) {
|
||||
|
@ -166,32 +166,32 @@ void CRacing::Jbutt (int button, int state) {
|
|||
}
|
||||
}
|
||||
|
||||
void CalcJumpEnergy (double time_step) {
|
||||
void CalcJumpEnergy(double time_step) {
|
||||
CControl *ctrl = g_game.player->ctrl;
|
||||
|
||||
if (ctrl->jump_charging) {
|
||||
ctrl->jump_amt = min (MAX_JUMP_AMT, g_game.time - charge_start_time);
|
||||
ctrl->jump_amt = min(MAX_JUMP_AMT, g_game.time - charge_start_time);
|
||||
} else if (ctrl->jumping) {
|
||||
ctrl->jump_amt *= (1.0 - (g_game.time - ctrl->jump_start_time) /
|
||||
JUMP_FORCE_DURATION);
|
||||
ctrl->jump_amt *= (1.0 - (g_game.time - ctrl->jump_start_time) /
|
||||
JUMP_FORCE_DURATION);
|
||||
} else {
|
||||
ctrl->jump_amt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int CalcSoundVol (float fact) {
|
||||
int CalcSoundVol(float fact) {
|
||||
float vv = (float) param.sound_volume * fact;
|
||||
if (vv > 100) vv = 100;
|
||||
return (int) vv;
|
||||
}
|
||||
|
||||
void SetSoundVolumes () {
|
||||
Sound.SetVolume ("pickup1", CalcSoundVol (1.0));
|
||||
Sound.SetVolume ("pickup2", CalcSoundVol (0.8));
|
||||
Sound.SetVolume ("pickup3", CalcSoundVol (0.8));
|
||||
Sound.SetVolume ("snow_sound", CalcSoundVol (1.5));
|
||||
Sound.SetVolume ("ice_sound", CalcSoundVol (0.6));
|
||||
Sound.SetVolume ("rock_sound", CalcSoundVol (1.1));
|
||||
void SetSoundVolumes() {
|
||||
Sound.SetVolume("pickup1", CalcSoundVol(1.0));
|
||||
Sound.SetVolume("pickup2", CalcSoundVol(0.8));
|
||||
Sound.SetVolume("pickup3", CalcSoundVol(0.8));
|
||||
Sound.SetVolume("snow_sound", CalcSoundVol(1.5));
|
||||
Sound.SetVolume("ice_sound", CalcSoundVol(0.6));
|
||||
Sound.SetVolume("rock_sound", CalcSoundVol(1.1));
|
||||
}
|
||||
|
||||
// ---------------------------- init ----------------------------------
|
||||
|
@ -201,7 +201,7 @@ void CRacing::Enter() {
|
|||
if (param.view_mode < 0 || param.view_mode >= NUM_VIEW_MODES) {
|
||||
param.view_mode = ABOVE;
|
||||
}
|
||||
set_view_mode (ctrl, param.view_mode);
|
||||
set_view_mode(ctrl, param.view_mode);
|
||||
left_turn = right_turn = trick_modifier = false;
|
||||
|
||||
ctrl->turn_fact = 0.0;
|
||||
|
@ -214,11 +214,11 @@ void CRacing::Enter() {
|
|||
lastsound = -1;
|
||||
newsound = -1;
|
||||
|
||||
if (State::manager.PreviousState() != &Paused) ctrl->Init ();
|
||||
if (State::manager.PreviousState() != &Paused) ctrl->Init();
|
||||
g_game.raceaborted = false;
|
||||
|
||||
SetSoundVolumes ();
|
||||
Music.PlayTheme (g_game.theme_id, MUS_RACING);
|
||||
SetSoundVolumes();
|
||||
Music.PlayTheme(g_game.theme_id, MUS_RACING);
|
||||
|
||||
g_game.finish = false;
|
||||
}
|
||||
|
@ -226,40 +226,40 @@ void CRacing::Enter() {
|
|||
// -------------------- sound -----------------------------------------
|
||||
|
||||
// this function is not used yet.
|
||||
int SlideVolume (CControl *ctrl, double speed, int typ) {
|
||||
int SlideVolume(CControl *ctrl, double speed, int typ) {
|
||||
if (typ == 1) { // only at paddling or braking
|
||||
return (int)(min ((((pow(ctrl->turn_fact, 2) * 128)) +
|
||||
(ctrl->is_braking ? 128:0) +
|
||||
(ctrl->jumping ? 128:0) + 20) * (speed / 10), 128));
|
||||
return (int)(min((((pow(ctrl->turn_fact, 2) * 128)) +
|
||||
(ctrl->is_braking ? 128:0) +
|
||||
(ctrl->jumping ? 128:0) + 20) * (speed / 10), 128));
|
||||
} else { // always
|
||||
return (int)(128 * pow((speed/2),2));
|
||||
}
|
||||
}
|
||||
|
||||
void PlayTerrainSound (CControl *ctrl, bool airborne) {
|
||||
void PlayTerrainSound(CControl *ctrl, bool airborne) {
|
||||
if (airborne == false) {
|
||||
int terridx = Course.GetTerrainIdx (ctrl->cpos.x, ctrl->cpos.z, 0.5);
|
||||
int terridx = Course.GetTerrainIdx(ctrl->cpos.x, ctrl->cpos.z, 0.5);
|
||||
if (terridx >= 0) {
|
||||
newsound = (int)Course.TerrList[terridx].sound;
|
||||
} else newsound = -1;
|
||||
} else newsound = -1;
|
||||
if ((newsound != lastsound) && (lastsound >= 0)) Sound.Halt (lastsound);
|
||||
if (newsound >= 0) Sound.Play (newsound, -1);
|
||||
if ((newsound != lastsound) && (lastsound >= 0)) Sound.Halt(lastsound);
|
||||
if (newsound >= 0) Sound.Play(newsound, -1);
|
||||
|
||||
lastsound = newsound;
|
||||
}
|
||||
|
||||
// ----------------------- controls -----------------------------------
|
||||
void CalcSteeringControls (CControl *ctrl, double time_step) {
|
||||
void CalcSteeringControls(CControl *ctrl, double time_step) {
|
||||
if (stick_turn) {
|
||||
ctrl->turn_fact = stick_turnfact;
|
||||
ctrl->turn_animation += ctrl->turn_fact * 2 * time_step;
|
||||
ctrl->turn_animation = clamp (-1.0, ctrl->turn_animation, 1.0);
|
||||
ctrl->turn_animation = clamp(-1.0, ctrl->turn_animation, 1.0);
|
||||
} else if (left_turn ^ right_turn) {
|
||||
if (left_turn) ctrl->turn_fact = -1.0;
|
||||
else ctrl->turn_fact = 1.0;
|
||||
ctrl->turn_animation += ctrl->turn_fact * 2 * time_step;
|
||||
ctrl->turn_animation = clamp (-1.0, ctrl->turn_animation, 1.0);
|
||||
ctrl->turn_animation = clamp(-1.0, ctrl->turn_animation, 1.0);
|
||||
} else {
|
||||
ctrl->turn_fact = 0.0;
|
||||
if (time_step < ROLL_DECAY) {
|
||||
|
@ -280,7 +280,7 @@ void CalcSteeringControls (CControl *ctrl, double time_step) {
|
|||
|
||||
bool charge = key_charging || stick_charging;
|
||||
bool invcharge = !key_charging && !stick_charging;
|
||||
CalcJumpEnergy (time_step);
|
||||
CalcJumpEnergy(time_step);
|
||||
if ((charge) && !ctrl->jump_charging && !ctrl->jumping) {
|
||||
ctrl->jump_charging = true;
|
||||
charge_start_time = g_game.time;
|
||||
|
@ -291,11 +291,11 @@ void CalcSteeringControls (CControl *ctrl, double time_step) {
|
|||
}
|
||||
}
|
||||
|
||||
void CalcFinishControls (CControl *ctrl, double timestep, bool airborne) {
|
||||
void CalcFinishControls(CControl *ctrl, double timestep, bool airborne) {
|
||||
double speed = ctrl->cvel.Length();
|
||||
double dir_angle = RADIANS_TO_ANGLES(atan(ctrl->cvel.x / ctrl->cvel.z));
|
||||
|
||||
if (fabs (dir_angle) > 5 && speed > 5) {
|
||||
if (fabs(dir_angle) > 5 && speed > 5) {
|
||||
ctrl->turn_fact = dir_angle / 20;
|
||||
if (ctrl->turn_fact < -1) ctrl->turn_fact = -1;
|
||||
if (ctrl->turn_fact > 1) ctrl->turn_fact = 1;
|
||||
|
@ -310,7 +310,7 @@ void CalcFinishControls (CControl *ctrl, double timestep, bool airborne) {
|
|||
|
||||
// ----------------------- trick --------------------------------------
|
||||
|
||||
void CalcTrickControls (CControl *ctrl, double time_step, bool airborne) {
|
||||
void CalcTrickControls(CControl *ctrl, double time_step, bool airborne) {
|
||||
if (airborne && trick_modifier) {
|
||||
if (left_turn) ctrl->roll_left = true;
|
||||
if (right_turn) ctrl->roll_right = true;
|
||||
|
@ -338,50 +338,50 @@ void CalcTrickControls (CControl *ctrl, double time_step, bool airborne) {
|
|||
// loop
|
||||
// ====================================================================
|
||||
|
||||
void CRacing::Loop (double time_step) {
|
||||
void CRacing::Loop(double time_step) {
|
||||
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));
|
||||
double ycoord = Course.FindYCoord(ctrl->cpos.x, ctrl->cpos.z);
|
||||
bool airborne = (bool)(ctrl->cpos.y > (ycoord + JUMP_MAX_START_HEIGHT));
|
||||
|
||||
ClearRenderContext ();
|
||||
Env.SetupFog ();
|
||||
CalcTrickControls (ctrl, time_step, airborne);
|
||||
ClearRenderContext();
|
||||
Env.SetupFog();
|
||||
CalcTrickControls(ctrl, time_step, airborne);
|
||||
|
||||
if (!g_game.finish) CalcSteeringControls (ctrl, time_step);
|
||||
else CalcFinishControls (ctrl, time_step, airborne);
|
||||
PlayTerrainSound (ctrl, airborne);
|
||||
if (!g_game.finish) CalcSteeringControls(ctrl, time_step);
|
||||
else CalcFinishControls(ctrl, time_step, airborne);
|
||||
PlayTerrainSound(ctrl, airborne);
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
ctrl->UpdatePlayerPos (time_step);
|
||||
ctrl->UpdatePlayerPos(time_step);
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
if (g_game.finish) IncCameraDistance (time_step);
|
||||
update_view (ctrl, time_step);
|
||||
UpdateTrackmarks (ctrl);
|
||||
if (g_game.finish) IncCameraDistance(time_step);
|
||||
update_view(ctrl, time_step);
|
||||
UpdateTrackmarks(ctrl);
|
||||
|
||||
SetupViewFrustum (ctrl);
|
||||
if (sky) Env.DrawSkybox (ctrl->viewpos);
|
||||
if (fog) Env.DrawFog ();
|
||||
void SetupLight ();
|
||||
if (terr) RenderCourse ();
|
||||
DrawTrackmarks ();
|
||||
if (trees) DrawTrees ();
|
||||
SetupViewFrustum(ctrl);
|
||||
if (sky) Env.DrawSkybox(ctrl->viewpos);
|
||||
if (fog) Env.DrawFog();
|
||||
void SetupLight();
|
||||
if (terr) RenderCourse();
|
||||
DrawTrackmarks();
|
||||
if (trees) DrawTrees();
|
||||
if (param.perf_level > 2) {
|
||||
update_particles (time_step);
|
||||
draw_particles (ctrl);
|
||||
update_particles(time_step);
|
||||
draw_particles(ctrl);
|
||||
}
|
||||
g_game.character->shape->Draw();
|
||||
UpdateWind (time_step);
|
||||
UpdateSnow (time_step, ctrl);
|
||||
DrawSnow (ctrl);
|
||||
DrawHud (ctrl);
|
||||
UpdateWind(time_step);
|
||||
UpdateSnow(time_step, ctrl);
|
||||
DrawSnow(ctrl);
|
||||
DrawHud(ctrl);
|
||||
|
||||
Reshape (Winsys.resolution.width, Winsys.resolution.height);
|
||||
Winsys.SwapBuffers ();
|
||||
Reshape(Winsys.resolution.width, Winsys.resolution.height);
|
||||
Winsys.SwapBuffers();
|
||||
if (g_game.finish == false) g_game.time += time_step;
|
||||
}
|
||||
// ---------------------------------- term ------------------
|
||||
void CRacing::Exit() {
|
||||
Sound.HaltAll ();
|
||||
break_track_marks ();
|
||||
Sound.HaltAll();
|
||||
break_track_marks();
|
||||
}
|
||||
|
|
|
@ -38,17 +38,17 @@ static TWidget* textbuttons[2];
|
|||
static TUpDown* player;
|
||||
static TUpDown* character;
|
||||
|
||||
void QuitRegistration () {
|
||||
Players.ResetControls ();
|
||||
Players.AllocControl (player->GetValue());
|
||||
void QuitRegistration() {
|
||||
Players.ResetControls();
|
||||
Players.AllocControl(player->GetValue());
|
||||
g_game.player = Players.GetPlayer(player->GetValue());
|
||||
|
||||
g_game.character = &Char.CharList[character->GetValue()];
|
||||
Char.FreeCharacterPreviews(); // From here on, character previews are no longer required
|
||||
State::manager.RequestEnterState (GameTypeSelect);
|
||||
State::manager.RequestEnterState(GameTypeSelect);
|
||||
}
|
||||
|
||||
void CRegist::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CRegist::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
TWidget* focussed = KeyGUI(key, 0, release);
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
|
@ -58,28 +58,28 @@ void CRegist::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, in
|
|||
case sf::Keyboard::Return:
|
||||
if (focussed == textbuttons[1]) {
|
||||
g_game.player = Players.GetPlayer(player->GetValue());
|
||||
State::manager.RequestEnterState (NewPlayer);
|
||||
} else QuitRegistration ();
|
||||
State::manager.RequestEnterState(NewPlayer);
|
||||
} else QuitRegistration();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CRegist::Mouse (int button, int state, int x, int y) {
|
||||
void CRegist::Mouse(int button, int state, int x, int y) {
|
||||
if (state == 1) {
|
||||
TWidget* focussed = ClickGUI(x, y);
|
||||
if (focussed == textbuttons[0])
|
||||
QuitRegistration ();
|
||||
QuitRegistration();
|
||||
else if (focussed == textbuttons[1]) {
|
||||
g_game.player = Players.GetPlayer(player->GetValue());
|
||||
State::manager.RequestEnterState (NewPlayer);
|
||||
State::manager.RequestEnterState(NewPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CRegist::Motion (int x, int y) {
|
||||
void CRegist::Motion(int x, int y) {
|
||||
MouseMoveGUI(x, y);
|
||||
|
||||
if (param.ui_snow) push_ui_snow (cursor_pos);
|
||||
if (param.ui_snow) push_ui_snow(cursor_pos);
|
||||
}
|
||||
|
||||
static int framewidth, frameheight, arrowwidth;
|
||||
|
@ -91,22 +91,22 @@ static TFramedText* sPlayerFrame;
|
|||
static TFramedText* sCharFrame;
|
||||
|
||||
void CRegist::Enter() {
|
||||
Winsys.ShowCursor (!param.ice_cursor);
|
||||
Winsys.ShowCursor(!param.ice_cursor);
|
||||
Music.Play(param.menu_music, true);
|
||||
|
||||
framewidth = (int) (Winsys.scale * 280);
|
||||
frameheight = (int) (Winsys.scale * 50);
|
||||
framewidth = (int)(Winsys.scale * 280);
|
||||
frameheight = (int)(Winsys.scale * 50);
|
||||
arrowwidth = 50;
|
||||
int sumwidth = framewidth * 2 + arrowwidth * 2;
|
||||
area = AutoAreaN (30, 80, sumwidth);
|
||||
area = AutoAreaN(30, 80, sumwidth);
|
||||
texsize = 128 * Winsys.scale;
|
||||
|
||||
ResetGUI ();
|
||||
ResetGUI();
|
||||
player = AddUpDown(area.left + framewidth + 8, area.top, 0, (int)Players.numPlayers() - 1, (int)g_game.start_player);
|
||||
character = AddUpDown(area.left + framewidth * 2 + arrowwidth + 8, area.top, 0, (int)Char.CharList.size() - 1, 0);
|
||||
int siz = FT.AutoSizeN (5);
|
||||
textbuttons[0] = AddTextButton (Trans.Text(60), CENTER, AutoYPosN (62), siz);
|
||||
textbuttons[1] = AddTextButton (Trans.Text(61), CENTER, AutoYPosN (70), siz);
|
||||
int siz = FT.AutoSizeN(5);
|
||||
textbuttons[0] = AddTextButton(Trans.Text(60), CENTER, AutoYPosN(62), siz);
|
||||
textbuttons[1] = AddTextButton(Trans.Text(61), CENTER, AutoYPosN(70), siz);
|
||||
|
||||
FT.AutoSizeN(3);
|
||||
int top = AutoYPosN(24);
|
||||
|
@ -121,12 +121,12 @@ void CRegist::Enter() {
|
|||
Winsys.Terminate(); // Characters are necessary - ETR is unusable otherwise
|
||||
}
|
||||
|
||||
void CRegist::Loop (double timestep) {
|
||||
void CRegist::Loop(double timestep) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow (timestep);
|
||||
update_ui_snow(timestep);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
|
@ -135,14 +135,14 @@ void CRegist::Loop (double timestep) {
|
|||
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);
|
||||
area.left + 60, AutoYPosN(40), texsize, texsize, 3, colWhite);
|
||||
|
||||
sCharFrame->SetString(Char.CharList[character->GetValue()].name);
|
||||
sCharFrame->Focussed(character->focussed());
|
||||
if (Char.CharList[character->GetValue()].preview != NULL)
|
||||
Char.CharList[character->GetValue()].preview->DrawFrame(
|
||||
area.right - texsize - 60 - arrowwidth,
|
||||
AutoYPosN (40), texsize, texsize, 3, colWhite);
|
||||
AutoYPosN(40), texsize, texsize, 3, colWhite);
|
||||
|
||||
DrawGUI();
|
||||
|
||||
|
|
|
@ -55,17 +55,17 @@ void CReset::Loop(double time_step) {
|
|||
static bool tux_visible = true;
|
||||
static int tux_visible_count = 0;
|
||||
|
||||
ClearRenderContext ();
|
||||
Env.SetupFog ();
|
||||
ctrl->UpdatePlayerPos (EPS);
|
||||
update_view (ctrl, EPS);
|
||||
SetupViewFrustum (ctrl);
|
||||
Env.DrawSkybox (ctrl->viewpos);
|
||||
Env.DrawFog ();
|
||||
Env.SetupLight (); // and fog
|
||||
ClearRenderContext();
|
||||
Env.SetupFog();
|
||||
ctrl->UpdatePlayerPos(EPS);
|
||||
update_view(ctrl, EPS);
|
||||
SetupViewFrustum(ctrl);
|
||||
Env.DrawSkybox(ctrl->viewpos);
|
||||
Env.DrawFog();
|
||||
Env.SetupLight(); // and fog
|
||||
RenderCourse();
|
||||
DrawTrackmarks ();
|
||||
DrawTrees ();
|
||||
DrawTrackmarks();
|
||||
DrawTrees();
|
||||
|
||||
if ((elapsed_time > BLINK_IN_PLACE_TIME) && (!position_reset)) {
|
||||
TObjectType* object_types = &Course.ObjTypes[0];
|
||||
|
@ -97,10 +97,10 @@ void CReset::Loop(double time_step) {
|
|||
|
||||
if (best_loc == -1) {
|
||||
ctrl->cpos.x = Course.GetDimensions().x/2.0;
|
||||
ctrl->cpos.z = min (ctrl->cpos.z + 10, -1.0);
|
||||
ctrl->cpos.z = min(ctrl->cpos.z + 10, -1.0);
|
||||
} else if (item_locs[best_loc].pt.z <= ctrl->cpos.z) {
|
||||
ctrl->cpos.x = Course.GetDimensions().x/2.0;
|
||||
ctrl->cpos.z = min (ctrl->cpos.z + 10, -1.0);
|
||||
ctrl->cpos.z = min(ctrl->cpos.z + 10, -1.0);
|
||||
} else {
|
||||
ctrl->cpos.x = item_locs[best_loc].pt.x;
|
||||
ctrl->cpos.z = item_locs[best_loc].pt.z;
|
||||
|
@ -108,7 +108,7 @@ void CReset::Loop(double time_step) {
|
|||
}
|
||||
|
||||
ctrl->view_init = false;
|
||||
ctrl->Init ();
|
||||
ctrl->Init();
|
||||
position_reset = true;
|
||||
} // if elapsed time
|
||||
|
||||
|
@ -119,12 +119,12 @@ void CReset::Loop(double time_step) {
|
|||
tux_visible_count = 0;
|
||||
}
|
||||
|
||||
DrawHud (ctrl);
|
||||
Reshape (Winsys.resolution.width, Winsys.resolution.height);
|
||||
Winsys.SwapBuffers ();
|
||||
DrawHud(ctrl);
|
||||
Reshape(Winsys.resolution.width, Winsys.resolution.height);
|
||||
Winsys.SwapBuffers();
|
||||
g_game.time += time_step;
|
||||
|
||||
if (elapsed_time > TOTAL_RESET_TIME) {
|
||||
State::manager.RequestEnterState (Racing);
|
||||
State::manager.RequestEnterState(Racing);
|
||||
}
|
||||
}
|
||||
|
|
110
src/score.cpp
110
src/score.cpp
|
@ -64,30 +64,30 @@ int CScore::AddScore(const TCourse* course, const TScore& score) {
|
|||
}
|
||||
|
||||
// for testing:
|
||||
void CScore::PrintScorelist (size_t list_idx) const {
|
||||
void CScore::PrintScorelist(size_t list_idx) const {
|
||||
if (list_idx >= Scorelist.size()) return;
|
||||
const TScoreList *list = &Scorelist[list_idx];
|
||||
|
||||
if (list->numScores < 1) {
|
||||
PrintStr ("no entries in this score list");
|
||||
PrintStr("no entries in this score list");
|
||||
} else {
|
||||
for (int i=0; i<list->numScores; i++) {
|
||||
string line = "player: " + list->scores[i].player;
|
||||
line += " points: " + Int_StrN (list->scores[i].points);
|
||||
line += " herrings: " + Int_StrN (list->scores[i].herrings);
|
||||
line += " time: " + Float_StrN (list->scores[i].time, 2);
|
||||
PrintString (line);
|
||||
line += " points: " + Int_StrN(list->scores[i].points);
|
||||
line += " herrings: " + Int_StrN(list->scores[i].herrings);
|
||||
line += " time: " + Float_StrN(list->scores[i].time, 2);
|
||||
PrintString(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const TScoreList *CScore::GetScorelist (size_t list_idx) const {
|
||||
const TScoreList *CScore::GetScorelist(size_t list_idx) const {
|
||||
if (list_idx >= Scorelist.size()) return NULL;
|
||||
return &Scorelist[list_idx];
|
||||
}
|
||||
|
||||
bool CScore::SaveHighScore () const {
|
||||
CSPList splist ((int)Scorelist.size()*MAX_SCORES);
|
||||
bool CScore::SaveHighScore() const {
|
||||
CSPList splist((int)Scorelist.size()*MAX_SCORES);
|
||||
|
||||
for (size_t li=0; li<Scorelist.size(); li++) {
|
||||
const TScoreList* lst = &Scorelist[li];
|
||||
|
@ -98,43 +98,43 @@ bool CScore::SaveHighScore () const {
|
|||
const TScore& score = lst->scores[sc];
|
||||
string line = "*[course] " + Course.CourseList[li].dir;
|
||||
line += " [plyr] " + score.player;
|
||||
line += " [pts] " + Int_StrN (score.points);
|
||||
line += " [herr] " + Int_StrN (score.herrings);
|
||||
line += " [time] " + Float_StrN (score.time, 1);
|
||||
splist.Add (line);
|
||||
line += " [pts] " + Int_StrN(score.points);
|
||||
line += " [herr] " + Int_StrN(score.herrings);
|
||||
line += " [time] " + Float_StrN(score.time, 1);
|
||||
splist.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!splist.Save (param.config_dir, "highscore")) {
|
||||
Message ("could not save highscore list");
|
||||
if (!splist.Save(param.config_dir, "highscore")) {
|
||||
Message("could not save highscore list");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CScore::LoadHighScore () {
|
||||
CSPList list (520);
|
||||
bool CScore::LoadHighScore() {
|
||||
CSPList list(520);
|
||||
|
||||
Scorelist.resize(Course.CourseList.size());
|
||||
|
||||
if (!list.Load (param.config_dir, "highscore")) {
|
||||
Message ("could not load highscore list");
|
||||
if (!list.Load(param.config_dir, "highscore")) {
|
||||
Message("could not load highscore list");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
string course = SPStrN (line, "course", "unknown");
|
||||
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);
|
||||
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, score);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ int CScore::CalcRaceResult() {
|
|||
TempScore.time = g_game.time;
|
||||
TempScore.player = g_game.player->name;
|
||||
|
||||
return AddScore (g_game.course, TempScore);
|
||||
return AddScore(g_game.course, TempScore);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -174,7 +174,7 @@ static TWidget* textbutton;
|
|||
static TFramedText* courseName;
|
||||
static TLabel* headline;
|
||||
|
||||
void CScore::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CScore::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
KeyGUI(key, 0, release);
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
|
@ -185,10 +185,10 @@ void CScore::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int
|
|||
State::manager.RequestQuit();
|
||||
break;
|
||||
case sf::Keyboard::S:
|
||||
Score.SaveHighScore ();
|
||||
Score.SaveHighScore();
|
||||
break;
|
||||
case sf::Keyboard::L:
|
||||
Score.LoadHighScore ();
|
||||
Score.LoadHighScore();
|
||||
break;
|
||||
case sf::Keyboard::Return:
|
||||
State::manager.RequestEnterState(*State::manager.PreviousState());
|
||||
|
@ -196,7 +196,7 @@ void CScore::Keyb (sf::Keyboard::Key key, bool special, bool release, int x, int
|
|||
}
|
||||
}
|
||||
|
||||
void CScore::Mouse (int button, int state, int x, int y) {
|
||||
void CScore::Mouse(int button, int state, int x, int y) {
|
||||
if (state == 1) {
|
||||
TWidget* clicked = ClickGUI(x, y);
|
||||
if (clicked == textbutton)
|
||||
|
@ -204,10 +204,10 @@ void CScore::Mouse (int button, int state, int x, int y) {
|
|||
}
|
||||
}
|
||||
|
||||
void CScore::Motion (int x, int y) {
|
||||
void CScore::Motion(int x, int y) {
|
||||
MouseMoveGUI(x, y);
|
||||
|
||||
if (param.ui_snow) push_ui_snow (cursor_pos);
|
||||
if (param.ui_snow) push_ui_snow(cursor_pos);
|
||||
}
|
||||
|
||||
static TArea area;
|
||||
|
@ -215,17 +215,17 @@ static int linedist, listtop;
|
|||
static int dd1, dd2, dd3, dd4;
|
||||
|
||||
void CScore::Enter() {
|
||||
Winsys.ShowCursor (!param.ice_cursor);
|
||||
Winsys.KeyRepeat (true);
|
||||
Winsys.ShowCursor(!param.ice_cursor);
|
||||
Winsys.KeyRepeat(true);
|
||||
Music.Play(param.menu_music, true);
|
||||
|
||||
int framewidth = 550 * Winsys.scale;
|
||||
int frameheight = 50 * Winsys.scale;
|
||||
int frametop = AutoYPosN(32);
|
||||
area = AutoAreaN (30, 80, framewidth);
|
||||
FT.AutoSizeN (3);
|
||||
linedist = FT.AutoDistanceN (1);
|
||||
listtop = AutoYPosN (44);
|
||||
area = AutoAreaN(30, 80, framewidth);
|
||||
FT.AutoSizeN(3);
|
||||
linedist = FT.AutoDistanceN(1);
|
||||
listtop = AutoYPosN(44);
|
||||
dd1 = 50 * Winsys.scale;
|
||||
dd2 = 115 * Winsys.scale;
|
||||
dd3 = 250 * Winsys.scale;
|
||||
|
@ -233,10 +233,10 @@ void CScore::Enter() {
|
|||
|
||||
CourseList = &Course.CourseList[0];
|
||||
|
||||
ResetGUI ();
|
||||
ResetGUI();
|
||||
course = AddUpDown(area.right + 8, frametop, 0, (int)Course.CourseList.size()-1, 0);
|
||||
int siz = FT.AutoSizeN (5);
|
||||
textbutton = AddTextButton (Trans.Text(64), CENTER, AutoYPosN (80), siz);
|
||||
int siz = FT.AutoSizeN(5);
|
||||
textbutton = AddTextButton(Trans.Text(64), CENTER, AutoYPosN(80), siz);
|
||||
|
||||
FT.AutoSizeN(7);
|
||||
headline = AddLabel(Trans.Text(62), CENTER, AutoYPosN(22), colWhite);
|
||||
|
@ -248,12 +248,12 @@ void CScore::Enter() {
|
|||
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) {
|
||||
void CScore::Loop(double timestep) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
|
||||
if (param.ui_snow) {
|
||||
update_ui_snow (timestep);
|
||||
update_ui_snow(timestep);
|
||||
draw_ui_snow();
|
||||
}
|
||||
|
||||
|
@ -262,26 +262,26 @@ void CScore::Loop (double timestep) {
|
|||
courseName->Focussed(course->focussed());
|
||||
courseName->SetString(CourseList[course->GetValue()].name);
|
||||
|
||||
const TScoreList *list = Score.GetScorelist (course->GetValue());
|
||||
const TScoreList *list = Score.GetScorelist(course->GetValue());
|
||||
|
||||
FT.SetColor (colWhite);
|
||||
FT.SetColor(colWhite);
|
||||
if (list != NULL) {
|
||||
FT.AutoSizeN (3);
|
||||
FT.AutoSizeN(3);
|
||||
if (list->numScores < 1) {
|
||||
FT.DrawString (CENTER, area.top + 140, Trans.Text(63));
|
||||
FT.DrawString(CENTER, area.top + 140, Trans.Text(63));
|
||||
} else {
|
||||
for (int i=0; i<min(MAX_SCORES, list->numScores); i++) {
|
||||
int y = listtop + i*linedist;
|
||||
FT.DrawString (area.left, y, ordinals[i]);
|
||||
FT.DrawString (area.left + dd1, y, Int_StrN (list->scores[i].points));
|
||||
FT.DrawString (area.left + dd2, y, list->scores[i].player);
|
||||
FT.DrawString (area.left + dd3, y,
|
||||
Int_StrN (list->scores[i].herrings) + " herrings");
|
||||
FT.DrawString (area.left + dd4, y,
|
||||
Float_StrN (list->scores[i].time, 1) + " sec");
|
||||
FT.DrawString(area.left, y, ordinals[i]);
|
||||
FT.DrawString(area.left + dd1, y, Int_StrN(list->scores[i].points));
|
||||
FT.DrawString(area.left + dd2, y, list->scores[i].player);
|
||||
FT.DrawString(area.left + dd3, y,
|
||||
Int_StrN(list->scores[i].herrings) + " herrings");
|
||||
FT.DrawString(area.left + dd4, y,
|
||||
Float_StrN(list->scores[i].time, 1) + " sec");
|
||||
}
|
||||
}
|
||||
} else Message ("score list out of range");
|
||||
} else Message("score list out of range");
|
||||
|
||||
DrawGUI();
|
||||
|
||||
|
|
10
src/score.h
10
src/score.h
|
@ -47,11 +47,11 @@ private:
|
|||
void Motion(int x, int y);
|
||||
public:
|
||||
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;
|
||||
bool LoadHighScore ();
|
||||
int CalcRaceResult ();
|
||||
const TScoreList *GetScorelist(size_t list_idx) const;
|
||||
void PrintScorelist(size_t list_idx) const;
|
||||
bool SaveHighScore() const;
|
||||
bool LoadHighScore();
|
||||
int CalcRaceResult();
|
||||
};
|
||||
|
||||
extern CScore Score;
|
||||
|
|
|
@ -38,14 +38,14 @@ CSplashScreen SplashScreen;
|
|||
|
||||
|
||||
void CSplashScreen::Enter() {
|
||||
Winsys.ShowCursor (!param.ice_cursor);
|
||||
Winsys.ShowCursor(!param.ice_cursor);
|
||||
Music.Play(param.menu_music, true);
|
||||
}
|
||||
|
||||
void CSplashScreen::Loop(double timestep) {
|
||||
ScopedRenderMode rm(GUI);
|
||||
Winsys.clear();
|
||||
Trans.LoadTranslations (param.language); // Before first texts are being displayed
|
||||
Trans.LoadTranslations(param.language); // Before first texts are being displayed
|
||||
|
||||
sf::Sprite logo(Tex.GetSFTexture(TEXLOGO));
|
||||
logo.setScale(Winsys.scale/2, Winsys.scale/2);
|
||||
|
@ -56,7 +56,7 @@ void CSplashScreen::Loop(double timestep) {
|
|||
int top = AutoYPosN(60);
|
||||
t1.setPosition((Winsys.resolution.width - t1.getLocalBounds().width) / 2, top);
|
||||
sf::Text t2(Trans.Text(68), FT.getCurrentFont(), FT.GetSize());
|
||||
int dist = FT.AutoDistanceN (3);
|
||||
int dist = FT.AutoDistanceN(3);
|
||||
t2.setPosition((Winsys.resolution.width - t2.getLocalBounds().width) / 2, top + dist);
|
||||
|
||||
Winsys.draw(logo);
|
||||
|
@ -66,17 +66,17 @@ void CSplashScreen::Loop(double timestep) {
|
|||
|
||||
init_ui_snow();
|
||||
|
||||
Course.MakeStandardPolyhedrons ();
|
||||
Sound.LoadSoundList ();
|
||||
Char.LoadCharacterList ();
|
||||
Course.LoadObjectTypes ();
|
||||
Course.LoadTerrainTypes ();
|
||||
Env.LoadEnvironmentList ();
|
||||
Course.LoadCourseList ();
|
||||
Score.LoadHighScore (); // after LoadCourseList !!!
|
||||
Events.LoadEventList ();
|
||||
Players.LoadAvatars (); // before LoadPlayers !!!
|
||||
Players.LoadPlayers ();
|
||||
Course.MakeStandardPolyhedrons();
|
||||
Sound.LoadSoundList();
|
||||
Char.LoadCharacterList();
|
||||
Course.LoadObjectTypes();
|
||||
Course.LoadTerrainTypes();
|
||||
Env.LoadEnvironmentList();
|
||||
Course.LoadCourseList();
|
||||
Score.LoadHighScore(); // after LoadCourseList !!!
|
||||
Events.LoadEventList();
|
||||
Players.LoadAvatars(); // before LoadPlayers !!!
|
||||
Players.LoadPlayers();
|
||||
|
||||
State::manager.RequestEnterState (Regist);
|
||||
State::manager.RequestEnterState(Regist);
|
||||
}
|
||||
|
|
208
src/spx.cpp
208
src/spx.cpp
|
@ -32,70 +32,70 @@ const string errorString = "error";
|
|||
// elementary string functions
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
string MakePathStr (const string& src, const string& add) {
|
||||
string MakePathStr(const string& src, const string& add) {
|
||||
string res = src;
|
||||
res += SEP;
|
||||
res += add;
|
||||
return res;
|
||||
}
|
||||
|
||||
void SInsertN (string &s, size_t pos, const string& ins) {
|
||||
void SInsertN(string &s, size_t pos, const string& ins) {
|
||||
if (pos > s.size()) pos = s.size();
|
||||
s.insert (pos, ins);
|
||||
s.insert(pos, ins);
|
||||
}
|
||||
|
||||
void SDeleteN (string &s, size_t pos, size_t count) {
|
||||
void SDeleteN(string &s, size_t pos, size_t count) {
|
||||
if (pos > s.size()) pos = s.size();
|
||||
s.erase (pos, count);
|
||||
s.erase(pos, count);
|
||||
}
|
||||
|
||||
size_t SPosN (const string &s, const string& find) {
|
||||
return s.find (find);
|
||||
size_t SPosN(const string &s, const string& find) {
|
||||
return s.find(find);
|
||||
}
|
||||
|
||||
void STrimLeftN (string &s) {
|
||||
void STrimLeftN(string &s) {
|
||||
size_t i = s.find_first_not_of(" \t");
|
||||
if (i > 0)
|
||||
SDeleteN (s, 0, i);
|
||||
SDeleteN(s, 0, i);
|
||||
}
|
||||
|
||||
void STrimRightN (string &s) {
|
||||
void STrimRightN(string &s) {
|
||||
size_t i = s.find_last_not_of(" \t");
|
||||
if (i != s.size()-1)
|
||||
s.erase (i+1);
|
||||
s.erase(i+1);
|
||||
}
|
||||
|
||||
void STrimN (string &s) {
|
||||
STrimLeftN (s);
|
||||
STrimRightN (s);
|
||||
void STrimN(string &s) {
|
||||
STrimLeftN(s);
|
||||
STrimRightN(s);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// conversion functions
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
string Int_StrN (const int val) {
|
||||
string Int_StrN(const int val) {
|
||||
ostringstream os;
|
||||
os << val;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string Int_StrN (const int val, const streamsize count) {
|
||||
string Int_StrN(const int val, const streamsize count) {
|
||||
ostringstream os;
|
||||
os << setw(count) << setfill('0') << val;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string Float_StrN (const float val, const streamsize count) {
|
||||
string Float_StrN(const float val, const streamsize count) {
|
||||
ostringstream os;
|
||||
os << setprecision(count) << fixed << val;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
string Vector_StrN (const TVector3d& v, const streamsize count) {
|
||||
string res = Float_StrN (v.x, count);
|
||||
res += ' ' + Float_StrN (v.y, count);
|
||||
res += ' ' + Float_StrN (v.z, count);
|
||||
string Vector_StrN(const TVector3d& v, const streamsize count) {
|
||||
string res = Float_StrN(v.x, count);
|
||||
res += ' ' + Float_StrN(v.y, count);
|
||||
res += ' ' + Float_StrN(v.z, count);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ string Bool_StrN(const bool val) {
|
|||
else return "false";
|
||||
}
|
||||
|
||||
int Str_IntN (const string &s, const int def) {
|
||||
int Str_IntN(const string &s, const int def) {
|
||||
int val;
|
||||
istringstream is(s);
|
||||
is >> val;
|
||||
|
@ -112,7 +112,7 @@ int Str_IntN (const string &s, const int def) {
|
|||
else return val;
|
||||
}
|
||||
|
||||
bool Str_BoolN (const string &s, const bool def) {
|
||||
bool Str_BoolN(const string &s, const bool def) {
|
||||
if (s == "0" || s == "false")
|
||||
return false;
|
||||
if (s == "1" || s == "true")
|
||||
|
@ -120,7 +120,7 @@ bool Str_BoolN (const string &s, const bool def) {
|
|||
return Str_IntN(s, (int)def) != 0; // Try to parse as int
|
||||
}
|
||||
|
||||
float Str_FloatN (const string &s, const float def) {
|
||||
float Str_FloatN(const string &s, const float def) {
|
||||
float val;
|
||||
istringstream is(s);
|
||||
is >> val;
|
||||
|
@ -170,7 +170,7 @@ sf::Color Str_ColorN(const string &s, const sf::Color &def) {
|
|||
else return sf::Color(r * 255, g * 255, b * 255, a * 255);
|
||||
}
|
||||
|
||||
TColor3 Str_Color3N (const string &s, const TColor3 &def) {
|
||||
TColor3 Str_Color3N(const string &s, const TColor3 &def) {
|
||||
float r, g, b;
|
||||
istringstream is(s);
|
||||
is >> r >> g >> b;
|
||||
|
@ -178,7 +178,7 @@ TColor3 Str_Color3N (const string &s, const TColor3 &def) {
|
|||
else return TColor3(r, g, b);
|
||||
}
|
||||
|
||||
void Str_ArrN (const string &s, float *arr, size_t count, float def) {
|
||||
void Str_ArrN(const string &s, float *arr, size_t count, float def) {
|
||||
istringstream is(s);
|
||||
for (size_t i = 0; i < count; i++)
|
||||
is >> arr[i];
|
||||
|
@ -190,11 +190,11 @@ void Str_ArrN (const string &s, float *arr, size_t count, float def) {
|
|||
// SP functions for parsing lines
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
string SPItemN (const string &s, const string &tag) {
|
||||
string SPItemN(const string &s, const string &tag) {
|
||||
if (s.empty() || tag.empty()) return "";
|
||||
|
||||
string tg = '[' + tag + ']';
|
||||
size_t i = SPosN (s, tg);
|
||||
size_t i = SPosN(s, tg);
|
||||
if (i == string::npos) return "";
|
||||
size_t ii = i + tg.size();
|
||||
string item;
|
||||
|
@ -205,30 +205,30 @@ string SPItemN (const string &s, const string &tag) {
|
|||
return item;
|
||||
}
|
||||
|
||||
string SPStrN (const string &s, const string &tag, const string& def) {
|
||||
string item = SPItemN (s, tag);
|
||||
string SPStrN(const string &s, const string &tag, const string& def) {
|
||||
string item = SPItemN(s, tag);
|
||||
if (item.empty()) return def;
|
||||
STrimN (item);
|
||||
STrimN(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
int SPIntN (const string &s, const string &tag, const int def) {
|
||||
return (Str_IntN (SPItemN (s, tag), def));
|
||||
int SPIntN(const string &s, const string &tag, const int def) {
|
||||
return (Str_IntN(SPItemN(s, tag), def));
|
||||
}
|
||||
|
||||
bool SPBoolN (const string &s, const string &tag, const bool def) {
|
||||
string item = SPItemN (s, tag);
|
||||
STrimN (item);
|
||||
return Str_BoolN (item, def);
|
||||
bool SPBoolN(const string &s, const string &tag, const bool def) {
|
||||
string item = SPItemN(s, tag);
|
||||
STrimN(item);
|
||||
return Str_BoolN(item, def);
|
||||
}
|
||||
|
||||
float SPFloatN (const string &s, const string &tag, const float def) {
|
||||
return (Str_FloatN (SPItemN (s, tag), def));
|
||||
float SPFloatN(const string &s, const string &tag, const float def) {
|
||||
return (Str_FloatN(SPItemN(s, tag), def));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
TVector2<T> SPVector2 (const string &s, const string &tag, const TVector2<T>& def) {
|
||||
return (Str_Vector2(SPItemN (s, tag), def));
|
||||
TVector2<T> SPVector2(const string &s, const string &tag, const TVector2<T>& def) {
|
||||
return (Str_Vector2(SPItemN(s, tag), def));
|
||||
}
|
||||
template TVector2<int> SPVector2(const string &s, const string &tag, const TVector2<int>& def);
|
||||
template TVector2<double> SPVector2(const string &s, const string &tag, const TVector2<double>& def);
|
||||
|
@ -248,68 +248,68 @@ template TVector4<int> SPVector4(const string &s, const string &tag, const TVect
|
|||
template TVector4<double> SPVector4(const string &s, const string &tag, const TVector4<double>& def);
|
||||
|
||||
sf::Color SPColorN(const string &s, const string &tag, const sf::Color& def) {
|
||||
return (Str_ColorN (SPItemN (s, tag), def));
|
||||
return (Str_ColorN(SPItemN(s, tag), def));
|
||||
}
|
||||
|
||||
TColor3 SPColor3N (const string &s, const string &tag, const TColor3& def) {
|
||||
return (Str_Color3N (SPItemN (s, tag), def));
|
||||
TColor3 SPColor3N(const string &s, const string &tag, const TColor3& def) {
|
||||
return (Str_Color3N(SPItemN(s, tag), def));
|
||||
}
|
||||
|
||||
void SPArrN (const string &s, const string &tag, float *arr, size_t count, float def) {
|
||||
Str_ArrN (SPItemN (s, tag), arr, count, def);
|
||||
void SPArrN(const string &s, const string &tag, float *arr, size_t count, float def) {
|
||||
Str_ArrN(SPItemN(s, tag), arr, count, def);
|
||||
}
|
||||
|
||||
size_t SPPosN (const string &s, const string &tag) {
|
||||
size_t SPPosN(const string &s, const string &tag) {
|
||||
string tg = '[' + tag + ']';
|
||||
return SPosN (s, tg);
|
||||
return SPosN(s, tg);
|
||||
}
|
||||
|
||||
// ------------------ add ---------------------------------------------
|
||||
|
||||
void SPAddIntN (string &s, const string &tag, const int val) {
|
||||
void SPAddIntN(string &s, const string &tag, const int val) {
|
||||
s += '[';
|
||||
s += tag;
|
||||
s += ']';
|
||||
s += Int_StrN (val);
|
||||
s += Int_StrN(val);
|
||||
}
|
||||
|
||||
void SPAddFloatN (string &s, const string &tag, const float val, size_t count) {
|
||||
void SPAddFloatN(string &s, const string &tag, const float val, size_t count) {
|
||||
s += '[';
|
||||
s += tag;
|
||||
s += ']';
|
||||
s += Float_StrN (val, count);
|
||||
s += Float_StrN(val, count);
|
||||
}
|
||||
|
||||
void SPAddStrN (string &s, const string &tag, const string &val) {
|
||||
void SPAddStrN(string &s, const string &tag, const string &val) {
|
||||
s += '[';
|
||||
s += tag;
|
||||
s += ']';
|
||||
s += val;
|
||||
}
|
||||
|
||||
void SPAddVec2N (string &s, const string &tag, const TVector2d &val, size_t count) {
|
||||
void SPAddVec2N(string &s, const string &tag, const TVector2d &val, size_t count) {
|
||||
s += '[';
|
||||
s += tag;
|
||||
s += ']';
|
||||
s += ' ';
|
||||
s += Float_StrN (val.x, count);
|
||||
s += Float_StrN(val.x, count);
|
||||
s += ' ';
|
||||
s += Float_StrN (val.y, count);
|
||||
s += Float_StrN(val.y, count);
|
||||
}
|
||||
|
||||
void SPAddVec3N (string &s, const string &tag, const TVector3d &val, size_t count) {
|
||||
void SPAddVec3N(string &s, const string &tag, const TVector3d &val, size_t count) {
|
||||
s += '[';
|
||||
s += tag;
|
||||
s += ']';
|
||||
s += ' ';
|
||||
s += Float_StrN (val.x, count);
|
||||
s += Float_StrN(val.x, count);
|
||||
s += ' ';
|
||||
s += Float_StrN (val.y, count);
|
||||
s += Float_StrN(val.y, count);
|
||||
s += ' ';
|
||||
s += Float_StrN (val.z, count);
|
||||
s += Float_StrN(val.z, count);
|
||||
}
|
||||
|
||||
void SPAddBoolN (string &s, const string &tag, const bool val) {
|
||||
void SPAddBoolN(string &s, const string &tag, const bool val) {
|
||||
s += '[';
|
||||
s += tag;
|
||||
s += ']';
|
||||
|
@ -319,34 +319,34 @@ void SPAddBoolN (string &s, const string &tag, const bool val) {
|
|||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void SPSetIntN (string &s, const string &tag, const int val) {
|
||||
size_t pos = SPPosN (s, tag);
|
||||
void SPSetIntN(string &s, const string &tag, const int val) {
|
||||
size_t pos = SPPosN(s, tag);
|
||||
if (pos != string::npos) {
|
||||
size_t ipos = pos + tag.size() + 2;
|
||||
string item = SPItemN (s, tag);
|
||||
if (item.size() != string::npos) SDeleteN (s, ipos, item.size());
|
||||
SInsertN (s, ipos, Int_StrN (val));
|
||||
} else SPAddIntN (s, tag, val);
|
||||
string item = SPItemN(s, tag);
|
||||
if (item.size() != string::npos) SDeleteN(s, ipos, item.size());
|
||||
SInsertN(s, ipos, Int_StrN(val));
|
||||
} else SPAddIntN(s, tag, val);
|
||||
}
|
||||
|
||||
void SPSetFloatN (string &s, const string &tag, const float val, size_t count) {
|
||||
size_t pos = SPPosN (s, tag);
|
||||
void SPSetFloatN(string &s, const string &tag, const float val, size_t count) {
|
||||
size_t pos = SPPosN(s, tag);
|
||||
if (pos != string::npos) {
|
||||
size_t ipos = pos + tag.size() + 2;
|
||||
string item = SPItemN (s, tag);
|
||||
if (item.size() != string::npos) SDeleteN (s, ipos, item.size());
|
||||
SInsertN (s, ipos, Float_StrN (val, count));
|
||||
} else SPAddFloatN (s, tag, val, count);
|
||||
string item = SPItemN(s, tag);
|
||||
if (item.size() != string::npos) SDeleteN(s, ipos, item.size());
|
||||
SInsertN(s, ipos, Float_StrN(val, count));
|
||||
} else SPAddFloatN(s, tag, val, count);
|
||||
}
|
||||
|
||||
void SPSetStrN (string &s, const string &tag, const string &val) {
|
||||
size_t pos = SPPosN (s, tag);
|
||||
void SPSetStrN(string &s, const string &tag, const string &val) {
|
||||
size_t pos = SPPosN(s, tag);
|
||||
if (pos != string::npos) {
|
||||
size_t ipos = pos + tag.size() + 2;
|
||||
string item = SPItemN (s, tag);
|
||||
if (item.size() != string::npos) SDeleteN (s, ipos, item.size());
|
||||
SInsertN (s, ipos, val);
|
||||
} else SPAddStrN (s, tag, val);
|
||||
string item = SPItemN(s, tag);
|
||||
if (item.size() != string::npos) SDeleteN(s, ipos, item.size());
|
||||
SInsertN(s, ipos, val);
|
||||
} else SPAddStrN(s, tag, val);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -354,52 +354,52 @@ void SPSetStrN (string &s, const string &tag, const string &val) {
|
|||
// --------------------------------------------------------------------
|
||||
|
||||
|
||||
CSPList::CSPList (size_t maxlines, bool newlineflag) {
|
||||
CSPList::CSPList(size_t maxlines, bool newlineflag) {
|
||||
fmax = maxlines;
|
||||
fnewlineflag = newlineflag;
|
||||
}
|
||||
|
||||
const string& CSPList::Line (size_t idx) const {
|
||||
const string& CSPList::Line(size_t idx) const {
|
||||
if (idx >= flines.size()) return emptyString;
|
||||
return flines[idx];
|
||||
}
|
||||
|
||||
void CSPList::Add (const string& line) {
|
||||
void CSPList::Add(const string& line) {
|
||||
if (flines.size() < fmax) {
|
||||
flines.push_back(line);
|
||||
}
|
||||
}
|
||||
|
||||
void CSPList::AddLine () {
|
||||
void CSPList::AddLine() {
|
||||
if (flines.size() < fmax) {
|
||||
flines.push_back(emptyString);
|
||||
}
|
||||
}
|
||||
|
||||
void CSPList::Append (const string& line, size_t idx) {
|
||||
void CSPList::Append(const string& line, size_t idx) {
|
||||
if (idx >= flines.size()) return;
|
||||
flines[idx] += line;
|
||||
}
|
||||
|
||||
void CSPList::Print () const {
|
||||
void CSPList::Print() const {
|
||||
for (size_t i = 0; i < flines.size(); i++)
|
||||
cout << flines[i] << endl;
|
||||
}
|
||||
|
||||
bool CSPList::Load (const string &filepath) {
|
||||
bool CSPList::Load(const string &filepath) {
|
||||
std::ifstream tempfile(filepath.c_str());
|
||||
string line;
|
||||
|
||||
if (!tempfile) {
|
||||
Message ("CSPList::Load - unable to open " + filepath);
|
||||
Message("CSPList::Load - unable to open " + filepath);
|
||||
return false;
|
||||
} else {
|
||||
bool backflag = false;
|
||||
while (getline(tempfile, line)) {
|
||||
|
||||
// delete new line char if in string
|
||||
size_t npos = line.rfind ('\n');
|
||||
if (npos != string::npos) SDeleteN (line, npos, 1);
|
||||
size_t npos = line.rfind('\n');
|
||||
if (npos != string::npos) SDeleteN(line, npos, 1);
|
||||
|
||||
bool valid = true;
|
||||
if (line.empty()) valid = false; // empty line
|
||||
|
@ -408,24 +408,24 @@ bool CSPList::Load (const string &filepath) {
|
|||
if (valid) {
|
||||
if (flines.size() < fmax) {
|
||||
if (!fnewlineflag) {
|
||||
if (line[0] == '*' || flines.empty()) Add (line);
|
||||
else Append (line, flines.size()-1);
|
||||
if (line[0] == '*' || flines.empty()) Add(line);
|
||||
else Append(line, flines.size()-1);
|
||||
} else {
|
||||
bool fwdflag;
|
||||
if (line[line.length()-1] == '\\') {
|
||||
SDeleteN (line, line.length()-1, 1);
|
||||
SDeleteN(line, line.length()-1, 1);
|
||||
fwdflag = true;
|
||||
} else {
|
||||
fwdflag = false;
|
||||
}
|
||||
|
||||
if (backflag == false) Add (line);
|
||||
else Append (line, flines.size()-1);
|
||||
if (backflag == false) Add(line);
|
||||
else Append(line, flines.size()-1);
|
||||
|
||||
backflag = fwdflag;
|
||||
}
|
||||
} else {
|
||||
Message ("CSPList::Load - not enough lines");
|
||||
Message("CSPList::Load - not enough lines");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -434,14 +434,14 @@ bool CSPList::Load (const string &filepath) {
|
|||
}
|
||||
}
|
||||
|
||||
bool CSPList::Load (const string& dir, const string& filename) {
|
||||
return Load (dir + SEP + filename);
|
||||
bool CSPList::Load(const string& dir, const string& filename) {
|
||||
return Load(dir + SEP + filename);
|
||||
}
|
||||
|
||||
bool CSPList::Save (const string &filepath) const {
|
||||
bool CSPList::Save(const string &filepath) const {
|
||||
std::ofstream tempfile(filepath.c_str());
|
||||
if (!tempfile) {
|
||||
Message ("CSPList::Save - unable to open " + filepath);
|
||||
Message("CSPList::Save - unable to open " + filepath);
|
||||
return false;
|
||||
} else {
|
||||
for (size_t i=0; i<flines.size(); i++) {
|
||||
|
@ -451,17 +451,17 @@ bool CSPList::Save (const string &filepath) const {
|
|||
}
|
||||
}
|
||||
|
||||
bool CSPList::Save (const string& dir, const string& filename) const {
|
||||
return Save (dir + SEP + filename);
|
||||
bool CSPList::Save(const string& dir, const string& filename) const {
|
||||
return Save(dir + SEP + filename);
|
||||
}
|
||||
|
||||
void CSPList::MakeIndex (map<string, size_t>& index, const string &tag) {
|
||||
void CSPList::MakeIndex(map<string, size_t>& index, const string &tag) {
|
||||
index.clear();
|
||||
size_t idx = 0;
|
||||
|
||||
for (size_t i=0; i<flines.size(); i++) {
|
||||
string item = SPItemN (flines[i], tag);
|
||||
STrimN (item);
|
||||
string item = SPItemN(flines[i], tag);
|
||||
STrimN(item);
|
||||
if (!item.empty()) {
|
||||
index[item] = idx;
|
||||
idx++;
|
||||
|
|
88
src/spx.h
88
src/spx.h
|
@ -26,22 +26,22 @@ extern const string emptyString;
|
|||
extern const string errorString;
|
||||
|
||||
// ----- elementary string functions ----------------------------------
|
||||
string MakePathStr (const string& src, const string& add);
|
||||
void SInsertN (string &s, size_t pos, const string& ins);
|
||||
void SDeleteN (string &s, size_t pos, size_t count);
|
||||
size_t SPosN (const string &s, const string& find);
|
||||
void STrimLeftN (string &s);
|
||||
void STrimRightN (string &s);
|
||||
void STrimN (string &s);
|
||||
string MakePathStr(const string& src, const string& add);
|
||||
void SInsertN(string &s, size_t pos, const string& ins);
|
||||
void SDeleteN(string &s, size_t pos, size_t count);
|
||||
size_t SPosN(const string &s, const string& find);
|
||||
void STrimLeftN(string &s);
|
||||
void STrimRightN(string &s);
|
||||
void STrimN(string &s);
|
||||
|
||||
// ----- conversion functions -----------------------------------------
|
||||
string Int_StrN (const int val);
|
||||
string Int_StrN (const int val, const streamsize count);
|
||||
string Float_StrN (const float val, const streamsize count);
|
||||
string Bool_StrN (const bool val);
|
||||
string Vector_StrN (const TVector3d& v, const streamsize count);
|
||||
int Str_IntN (const string &s, const int def);
|
||||
bool Str_BoolN (const string &s, const bool def);
|
||||
string Int_StrN(const int val);
|
||||
string Int_StrN(const int val, const streamsize count);
|
||||
string Float_StrN(const float val, const streamsize count);
|
||||
string Bool_StrN(const bool val);
|
||||
string Vector_StrN(const TVector3d& v, const streamsize count);
|
||||
int Str_IntN(const string &s, const int def);
|
||||
bool Str_BoolN(const string &s, const bool def);
|
||||
float Str_FloatN(const string &s, const float def);
|
||||
template<typename T>
|
||||
TVector2<T> Str_Vector2(const string &s, const TVector2<T>& def);
|
||||
|
@ -50,16 +50,16 @@ TVector3<T> Str_Vector3(const string &s, const TVector3<T>& def);
|
|||
template<typename T>
|
||||
TVector4<T> Str_Vector4(const string &s, const TVector4<T>& def);
|
||||
sf::Color Str_ColorN(const string &s, const sf::Color& def);
|
||||
TColor3 Str_Color3N (const string &s, const TColor3& def);
|
||||
void Str_ArrN (const string &s, float *arr, size_t count, float def);
|
||||
TColor3 Str_Color3N(const string &s, const TColor3& def);
|
||||
void Str_ArrN(const string &s, float *arr, size_t count, float def);
|
||||
|
||||
// ----- SP functions for parsing lines --------------------------------
|
||||
size_t SPPosN (const string &s, const string &tag);
|
||||
size_t SPPosN(const string &s, const string &tag);
|
||||
|
||||
string SPStrN (const string &s, const string &tag, const string& def = emptyString);
|
||||
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);
|
||||
string SPStrN(const string &s, const string &tag, const string& def = emptyString);
|
||||
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);
|
||||
template<typename T>
|
||||
TVector2<T> SPVector2(const string &s, const string &tag, const TVector2<T>& def);
|
||||
static inline TVector2d SPVector2d(const string &s, const string &tag) { return SPVector2(s, tag, NullVec2); }
|
||||
|
@ -73,21 +73,21 @@ TVector4<T> SPVector4(const string &s, const string &tag, const TVector4<T>& def
|
|||
static inline TVector4d SPVector4d(const string &s, const string &tag) { return SPVector4(s, tag, NullVec4); }
|
||||
static inline TVector4i SPVector4i(const string &s, const string &tag) { return SPVector4(s, tag, NullVec4i); }
|
||||
sf::Color SPColorN(const string &s, const string &tag, const sf::Color& def);
|
||||
TColor3 SPColor3N (const string &s, const string &tag, const TColor3& def);
|
||||
void SPArrN (const string &s, const string &tag, float *arr, size_t count, float def);
|
||||
TColor3 SPColor3N(const string &s, const string &tag, const TColor3& def);
|
||||
void SPArrN(const string &s, const string &tag, float *arr, size_t count, float def);
|
||||
|
||||
// ----- making SP strings --------------------------------------------
|
||||
void SPAddIntN (string &s, const string &tag, const int val);
|
||||
void SPAddFloatN (string &s, const string &tag, const float val, size_t count);
|
||||
void SPAddStrN (string &s, const string &tag, const string &val);
|
||||
void SPAddVec2N (string &s, const string &tag, const TVector2d& val, size_t count);
|
||||
void SPAddVec3N (string &s, const string &tag, const TVector3d& val, size_t count);
|
||||
void SPAddBoolN (string &s, const string &tag, const bool val);
|
||||
void SPAddIntN(string &s, const string &tag, const int val);
|
||||
void SPAddFloatN(string &s, const string &tag, const float val, size_t count);
|
||||
void SPAddStrN(string &s, const string &tag, const string &val);
|
||||
void SPAddVec2N(string &s, const string &tag, const TVector2d& val, size_t count);
|
||||
void SPAddVec3N(string &s, const string &tag, const TVector3d& val, size_t count);
|
||||
void SPAddBoolN(string &s, const string &tag, const bool val);
|
||||
|
||||
// ----- manipulating SP strings --------------------------------------
|
||||
void SPSetIntN (string &s, const string &tag, const int val);
|
||||
void SPSetFloatN (string &s, const string &tag, const float val, size_t count);
|
||||
void SPSetStrN (string &s, const string &tag, const string &val);
|
||||
void SPSetIntN(string &s, const string &tag, const int val);
|
||||
void SPSetFloatN(string &s, const string &tag, const float val, size_t count);
|
||||
void SPSetStrN(string &s, const string &tag, const string &val);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// string list
|
||||
|
@ -99,21 +99,21 @@ private:
|
|||
size_t fmax;
|
||||
bool fnewlineflag;
|
||||
public:
|
||||
CSPList (size_t maxlines, bool newlineflag = false);
|
||||
CSPList(size_t maxlines, bool newlineflag = false);
|
||||
|
||||
const string& Line (size_t idx) const;
|
||||
size_t Count () const { return flines.size(); }
|
||||
void Clear () { flines.clear(); }
|
||||
void Add (const string& line);
|
||||
const string& Line(size_t idx) const;
|
||||
size_t Count() const { return flines.size(); }
|
||||
void Clear() { flines.clear(); }
|
||||
void Add(const string& line);
|
||||
void AddLine();
|
||||
void Append (const string& line, size_t idx);
|
||||
void Print () const;
|
||||
bool Load (const string &filepath);
|
||||
bool Load (const string& dir, const string& filename);
|
||||
bool Save (const string &filepath) const;
|
||||
bool Save (const string& dir, const string& filename) const;
|
||||
void Append(const string& line, size_t idx);
|
||||
void Print() const;
|
||||
bool Load(const string &filepath);
|
||||
bool Load(const string& dir, const string& filename);
|
||||
bool Save(const string &filepath) const;
|
||||
bool Save(const string& dir, const string& filename) const;
|
||||
|
||||
void MakeIndex (map<string, size_t>& index, const string &tag);
|
||||
void MakeIndex(map<string, size_t>& index, const string &tag);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -103,7 +103,7 @@ void State::Manager::PollEvent() {
|
|||
if (Winsys.resolution.width != event.size.width || Winsys.resolution.height != event.size.height) {
|
||||
Winsys.resolution.width = event.size.width;
|
||||
Winsys.resolution.height = event.size.height;
|
||||
Winsys.SetupVideoMode (param.res_type);
|
||||
Winsys.SetupVideoMode(param.res_type);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -57,12 +57,12 @@ void TTexture::Bind() {
|
|||
void TTexture::Draw() {
|
||||
GLint w, h;
|
||||
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
Bind();
|
||||
|
||||
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||
|
||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||
const GLshort vtx[] = {
|
||||
|
@ -86,12 +86,12 @@ void TTexture::Draw(int x, int y, float size, Orientation orientation) {
|
|||
GLint w, h;
|
||||
GLfloat width, height, top, bott, left, right;
|
||||
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
Bind();
|
||||
|
||||
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||
glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
||||
|
||||
width = w * size;
|
||||
height = h * size;
|
||||
|
@ -129,8 +129,8 @@ void TTexture::Draw(int x, int y, float size, Orientation orientation) {
|
|||
void TTexture::Draw(int x, int y, float width, float height, Orientation orientation) {
|
||||
GLfloat top, bott, left, right;
|
||||
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
Bind();
|
||||
|
||||
if (orientation == OR_TOP) {
|
||||
|
@ -181,41 +181,41 @@ void TTexture::DrawFrame(int x, int y, int w, int h, int frame, const sf::Color&
|
|||
|
||||
CTexture Tex;
|
||||
|
||||
CTexture::CTexture () {
|
||||
CTexture::CTexture() {
|
||||
forientation = OR_TOP;
|
||||
}
|
||||
|
||||
CTexture::~CTexture () {
|
||||
CTexture::~CTexture() {
|
||||
FreeTextureList();
|
||||
}
|
||||
|
||||
void CTexture::LoadTextureList () {
|
||||
void CTexture::LoadTextureList() {
|
||||
FreeTextureList();
|
||||
CSPList list (200);
|
||||
if (list.Load (param.tex_dir, "textures.lst")) {
|
||||
CSPList list(200);
|
||||
if (list.Load(param.tex_dir, "textures.lst")) {
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
string name = SPStrN (line, "name");
|
||||
int id = SPIntN (line, "id", -1);
|
||||
string name = SPStrN(line, "name");
|
||||
int id = SPIntN(line, "id", -1);
|
||||
CommonTex.resize(max(CommonTex.size(), (size_t)id+1));
|
||||
string texfile = SPStrN (line, "file");
|
||||
bool rep = SPBoolN (line, "repeat", false);
|
||||
string texfile = SPStrN(line, "file");
|
||||
bool rep = SPBoolN(line, "repeat", false);
|
||||
if (id >= 0) {
|
||||
CommonTex[id] = new TTexture();
|
||||
CommonTex[id]->Load(param.tex_dir, texfile, rep);
|
||||
} else Message ("wrong texture id in textures.lst");
|
||||
} else Message("wrong texture id in textures.lst");
|
||||
}
|
||||
} else Message ("failed to load common textures");
|
||||
} else Message("failed to load common textures");
|
||||
}
|
||||
|
||||
void CTexture::FreeTextureList () {
|
||||
void CTexture::FreeTextureList() {
|
||||
for (size_t i=0; i<CommonTex.size(); i++) {
|
||||
delete CommonTex[i];
|
||||
}
|
||||
CommonTex.clear();
|
||||
}
|
||||
|
||||
TTexture* CTexture::GetTexture (size_t idx) const {
|
||||
TTexture* CTexture::GetTexture(size_t idx) const {
|
||||
if (idx >= CommonTex.size()) return NULL;
|
||||
return CommonTex[idx];
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ const sf::Texture& CTexture::GetSFTexture(size_t idx) const {
|
|||
return CommonTex[idx]->texture;
|
||||
}
|
||||
|
||||
bool CTexture::BindTex (size_t idx) {
|
||||
bool CTexture::BindTex(size_t idx) {
|
||||
if (idx >= CommonTex.size()) return false;
|
||||
CommonTex[idx]->Bind();
|
||||
return true;
|
||||
|
@ -232,27 +232,27 @@ bool CTexture::BindTex (size_t idx) {
|
|||
|
||||
// ---------------------------- Draw ----------------------------------
|
||||
|
||||
void CTexture::Draw (size_t idx) {
|
||||
void CTexture::Draw(size_t idx) {
|
||||
if (CommonTex.size() > idx)
|
||||
CommonTex[idx]->Draw();
|
||||
}
|
||||
|
||||
void CTexture::Draw (size_t idx, int x, int y, float size) {
|
||||
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 (size_t idx, int x, int y, int width, int height) {
|
||||
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);
|
||||
CommonTex[idx]->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);
|
||||
CommonTex[idx]->DrawFrame(x, y, w, h, frame, col);
|
||||
}
|
||||
|
||||
void CTexture::SetOrientation (Orientation orientation) {
|
||||
void CTexture::SetOrientation(Orientation orientation) {
|
||||
forientation = orientation;
|
||||
}
|
||||
|
||||
|
@ -295,11 +295,11 @@ 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(NUMERIC_FONT)) {
|
||||
Message ("DrawNumStr: missing texture");
|
||||
Message("DrawNumStr: missing texture");
|
||||
return;
|
||||
}
|
||||
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
int qw = (int)(22 * size);
|
||||
int qh = (int)(32 * size);
|
||||
|
||||
|
@ -307,7 +307,7 @@ void CTexture::DrawNumStr(const string& s, int x, int y, float size, const sf::C
|
|||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
for (size_t i=0; i < s.size(); i++) {
|
||||
DrawNumChr (s[i], x + (int)i*qw, y, qw, qh);
|
||||
DrawNumChr(s[i], x + (int)i*qw, y, qw, qh);
|
||||
}
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
@ -321,7 +321,7 @@ void CTexture::DrawNumStr(const string& s, int x, int y, float size, const sf::C
|
|||
// 0 ppm, 1 tga, 2 bmp
|
||||
#define SCREENSHOT_PROC 2
|
||||
|
||||
void ScreenshotN () {
|
||||
void ScreenshotN() {
|
||||
sf::Texture tex;
|
||||
tex.update(Winsys.getWindow());
|
||||
sf::Image img = tex.copyToImage();
|
||||
|
|
|
@ -90,28 +90,28 @@ private:
|
|||
|
||||
void DrawNumChr(char c, int x, int y, int w, int h);
|
||||
public:
|
||||
CTexture ();
|
||||
~CTexture ();
|
||||
void LoadTextureList ();
|
||||
void FreeTextureList ();
|
||||
CTexture();
|
||||
~CTexture();
|
||||
void LoadTextureList();
|
||||
void FreeTextureList();
|
||||
|
||||
TTexture* GetTexture(size_t idx) const;
|
||||
const sf::Texture& GetSFTexture(size_t idx) const;
|
||||
bool BindTex (size_t idx);
|
||||
bool BindTex(size_t idx);
|
||||
|
||||
void Draw (size_t idx);
|
||||
void Draw (size_t idx, int x, int y, float size);
|
||||
void Draw (size_t idx, int x, int y, int width, int height);
|
||||
void Draw(size_t idx);
|
||||
void Draw(size_t idx, int x, int y, float size);
|
||||
void Draw(size_t idx, 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 SetOrientation (Orientation orientation);
|
||||
void SetOrientation(Orientation orientation);
|
||||
void DrawNumStr(const string& s, int x, int y, float size, const sf::Color& col);
|
||||
};
|
||||
|
||||
extern CTexture Tex;
|
||||
|
||||
void ScreenshotN ();
|
||||
void ScreenshotN();
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -56,32 +56,32 @@ static bool rotactive = false;
|
|||
static bool moveactive = false;
|
||||
static int comp = 0;
|
||||
|
||||
void InitCharTools () {
|
||||
void InitCharTools() {
|
||||
charbase = (int)((Winsys.resolution.height - 200) / 18);
|
||||
firstnode = 1;
|
||||
lastnode = TestChar.GetNumNodes () -1;
|
||||
lastnode = TestChar.GetNumNodes() -1;
|
||||
curr_node = firstnode;
|
||||
curr_act = firstact;
|
||||
lastact = TestChar.GetNumActs (curr_node) -1;
|
||||
action = TestChar.GetAction (curr_node);
|
||||
StoreAction (action);
|
||||
lastact = TestChar.GetNumActs(curr_node) -1;
|
||||
action = TestChar.GetAction(curr_node);
|
||||
StoreAction(action);
|
||||
}
|
||||
|
||||
void StoreAction (TCharAction *act) {
|
||||
void StoreAction(TCharAction *act) {
|
||||
for (size_t i=0; i<=act->num; i++) {
|
||||
Undo.vec[i] = act->vec[i];
|
||||
Undo.dval[i] = act->dval[i];
|
||||
}
|
||||
}
|
||||
|
||||
void RecallAction (TCharAction *act) {
|
||||
void RecallAction(TCharAction *act) {
|
||||
for (size_t i=0; i<=act->num; i++) {
|
||||
act->vec[i] = Undo.vec[i];
|
||||
act->dval[i] = Undo.dval[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeValue (int type, double fact) {
|
||||
void ChangeValue(int type, double fact) {
|
||||
if (type == 0 || type == 4) {
|
||||
if (comp == 0) {
|
||||
action->vec[curr_act].x += 0.02 * fact;
|
||||
|
@ -95,38 +95,38 @@ void ChangeValue (int type, double fact) {
|
|||
} else if (type == 5) {
|
||||
action->dval[curr_act] += 1 * fact;
|
||||
}
|
||||
TestChar.RefreshNode (curr_node);
|
||||
SetCharChanged (true);
|
||||
TestChar.RefreshNode(curr_node);
|
||||
SetCharChanged(true);
|
||||
}
|
||||
|
||||
void ChangeNode (int steps) {
|
||||
void ChangeNode(int steps) {
|
||||
bool ch;
|
||||
if (steps > 0) ch = (curr_node + steps <= lastnode);
|
||||
else ch = (curr_node + steps >= firstnode);
|
||||
if (ch) {
|
||||
curr_node += steps;
|
||||
curr_act = firstact;
|
||||
lastact = TestChar.GetNumActs (curr_node) -1;
|
||||
action = TestChar.GetAction (curr_node);
|
||||
lastact = TestChar.GetNumActs(curr_node) -1;
|
||||
action = TestChar.GetAction(curr_node);
|
||||
if (action->num > 0 && action->type[0] == 4) comp = 0;
|
||||
else comp = 1;
|
||||
StoreAction (action);
|
||||
StoreAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
void SetRotation (double x, double y, double z) {
|
||||
void SetRotation(double x, double y, double z) {
|
||||
xrotation = x;
|
||||
yrotation = y;
|
||||
zrotation = z;
|
||||
}
|
||||
|
||||
void CharKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void CharKeys(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
must_render = true;
|
||||
|
||||
if (ToolsFinalStage ()) {
|
||||
if (ToolsFinalStage()) {
|
||||
if (key == sf::Keyboard::Y || key == sf::Keyboard::J) {
|
||||
SaveToolCharacter ();
|
||||
SaveToolFrame ();
|
||||
SaveToolCharacter();
|
||||
SaveToolFrame();
|
||||
State::manager.RequestQuit();
|
||||
} else if (key == sf::Keyboard::N) State::manager.RequestQuit();
|
||||
return;
|
||||
|
@ -141,20 +141,20 @@ void CharKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y)
|
|||
int type = action->type[curr_act];
|
||||
switch (key) {
|
||||
case sf::Keyboard::Tab:
|
||||
SetToolMode (1);
|
||||
SetToolMode(1);
|
||||
break;
|
||||
case sf::Keyboard::Escape:
|
||||
case sf::Keyboard::Q:
|
||||
QuitTool ();
|
||||
QuitTool();
|
||||
break;
|
||||
case sf::Keyboard::F10:
|
||||
ScreenshotN ();
|
||||
ScreenshotN();
|
||||
break;
|
||||
case sf::Keyboard::S:
|
||||
SaveToolCharacter ();
|
||||
SaveToolCharacter();
|
||||
break;
|
||||
case sf::Keyboard::C:
|
||||
ScreenshotN ();
|
||||
ScreenshotN();
|
||||
break;
|
||||
case sf::Keyboard::M:
|
||||
TestChar.useMaterials = !TestChar.useMaterials;
|
||||
|
@ -163,14 +163,14 @@ void CharKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y)
|
|||
TestChar.useHighlighting = !TestChar.useHighlighting;
|
||||
break;
|
||||
case sf::Keyboard::R:
|
||||
TestChar.Reset ();
|
||||
ReloadToolCharacter ();
|
||||
Tools.Enter ();
|
||||
TestChar.Reset();
|
||||
ReloadToolCharacter();
|
||||
Tools.Enter();
|
||||
break;
|
||||
case sf::Keyboard::U:
|
||||
if (action != NULL) {
|
||||
RecallAction (action);
|
||||
TestChar.RefreshNode (curr_node);
|
||||
RecallAction(action);
|
||||
TestChar.RefreshNode(curr_node);
|
||||
}
|
||||
break;
|
||||
case sf::Keyboard::Add:
|
||||
|
@ -185,30 +185,30 @@ void CharKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y)
|
|||
|
||||
// set rotations for view
|
||||
case sf::Keyboard::Num1:
|
||||
SetRotation (0, 0, 0);
|
||||
SetRotation(0, 0, 0);
|
||||
break;
|
||||
case sf::Keyboard::Num2:
|
||||
SetRotation (-50, 180, 15);
|
||||
SetRotation(-50, 180, 15);
|
||||
break;
|
||||
case sf::Keyboard::Num3:
|
||||
SetRotation (0, 180, 0);
|
||||
SetRotation(0, 180, 0);
|
||||
break;
|
||||
case sf::Keyboard::Num4:
|
||||
SetRotation (0, -80, 0);
|
||||
SetRotation(0, -80, 0);
|
||||
break;
|
||||
|
||||
// select node
|
||||
case sf::Keyboard::PageUp:
|
||||
ChangeNode (-1);
|
||||
ChangeNode(-1);
|
||||
break;
|
||||
case sf::Keyboard::PageDown:
|
||||
ChangeNode (1);
|
||||
ChangeNode(1);
|
||||
break;
|
||||
case sf::Keyboard::End:
|
||||
ChangeNode (charbase);
|
||||
ChangeNode(charbase);
|
||||
break;
|
||||
case sf::Keyboard::Home:
|
||||
ChangeNode (-charbase);
|
||||
ChangeNode(-charbase);
|
||||
break;
|
||||
|
||||
// select action
|
||||
|
@ -223,10 +223,10 @@ void CharKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y)
|
|||
else comp = 1;
|
||||
break;
|
||||
case sf::Keyboard::Left:
|
||||
ChangeValue (type, -1);
|
||||
ChangeValue(type, -1);
|
||||
break;
|
||||
case sf::Keyboard::Right:
|
||||
ChangeValue (type, 1);
|
||||
ChangeValue(type, 1);
|
||||
break;
|
||||
|
||||
// select value
|
||||
|
@ -242,9 +242,9 @@ void CharKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y)
|
|||
}
|
||||
}
|
||||
|
||||
void CharMouse (int button, int state, int x, int y) {
|
||||
void CharMouse(int button, int state, int x, int y) {
|
||||
must_render = true;
|
||||
if (ToolsFinalStage ()) return;
|
||||
if (ToolsFinalStage()) return;
|
||||
|
||||
if (state<1) {
|
||||
rotactive = false;
|
||||
|
@ -272,7 +272,7 @@ void CharMouse (int button, int state, int x, int y) {
|
|||
}
|
||||
}
|
||||
|
||||
void CharMotion (int x, int y) {
|
||||
void CharMotion(int x, int y) {
|
||||
must_render = true;
|
||||
if (rotactive) {
|
||||
int diffx = cursor_pos.x - startx;
|
||||
|
@ -282,92 +282,92 @@ void CharMotion (int x, int y) {
|
|||
}
|
||||
if (moveactive) {
|
||||
float diffposx = (float)(cursor_pos.x - startx) / 200;
|
||||
float diffposy = (float) (cursor_pos.y - starty) / 200;
|
||||
float diffposy = (float)(cursor_pos.y - starty) / 200;
|
||||
yposition = startposy - diffposy;
|
||||
xposition = startposx + diffposx;
|
||||
}
|
||||
}
|
||||
|
||||
void DrawActionVec (size_t nr, const string& s, int y, const TVector3d& v) {
|
||||
FT.SetColor (colLGrey);
|
||||
FT.DrawString (20, y, s);
|
||||
void DrawActionVec(size_t nr, const string& s, int y, const TVector3d& v) {
|
||||
FT.SetColor(colLGrey);
|
||||
FT.DrawString(20, y, s);
|
||||
if (nr == curr_act) {
|
||||
if (comp == 0) {
|
||||
FT.SetColor (colYellow);
|
||||
FT.DrawString (100, y, Float_StrN (v.x, 2));
|
||||
FT.DrawString (150, y, Float_StrN (v.y, 2));
|
||||
FT.DrawString (200, y, Float_StrN (v.z, 2));
|
||||
FT.SetColor(colYellow);
|
||||
FT.DrawString(100, y, Float_StrN(v.x, 2));
|
||||
FT.DrawString(150, y, Float_StrN(v.y, 2));
|
||||
FT.DrawString(200, y, Float_StrN(v.z, 2));
|
||||
} else {
|
||||
if (comp == 1) FT.SetColor (colYellow);
|
||||
else FT.SetColor (colLGrey);
|
||||
FT.DrawString (100, y, Float_StrN (v.x, 2));
|
||||
if (comp == 2) FT.SetColor (colYellow);
|
||||
else FT.SetColor (colLGrey);
|
||||
FT.DrawString (150, y, Float_StrN (v.y, 2));
|
||||
if (comp == 3) FT.SetColor (colYellow);
|
||||
else FT.SetColor (colLGrey);
|
||||
FT.DrawString (200, y, Float_StrN (v.z, 2));
|
||||
if (comp == 1) FT.SetColor(colYellow);
|
||||
else FT.SetColor(colLGrey);
|
||||
FT.DrawString(100, y, Float_StrN(v.x, 2));
|
||||
if (comp == 2) FT.SetColor(colYellow);
|
||||
else FT.SetColor(colLGrey);
|
||||
FT.DrawString(150, y, Float_StrN(v.y, 2));
|
||||
if (comp == 3) FT.SetColor(colYellow);
|
||||
else FT.SetColor(colLGrey);
|
||||
FT.DrawString(200, y, Float_StrN(v.z, 2));
|
||||
}
|
||||
} else {
|
||||
FT.DrawString (100, y, Float_StrN (v.x, 2));
|
||||
FT.DrawString (150, y, Float_StrN (v.y, 2));
|
||||
FT.DrawString (200, y, Float_StrN (v.z, 2));
|
||||
FT.DrawString(100, y, Float_StrN(v.x, 2));
|
||||
FT.DrawString(150, y, Float_StrN(v.y, 2));
|
||||
FT.DrawString(200, y, Float_StrN(v.z, 2));
|
||||
}
|
||||
}
|
||||
|
||||
void DrawActionFloat (size_t nr, const string& s, int y, float f) {
|
||||
FT.SetColor (colLGrey);
|
||||
FT.DrawString (20, y, s);
|
||||
if (nr == curr_act) FT.SetColor (colYellow);
|
||||
else FT.SetColor (colLGrey);
|
||||
FT.DrawString (100, y, Float_StrN (f, 2));
|
||||
void DrawActionFloat(size_t nr, const string& s, int y, float f) {
|
||||
FT.SetColor(colLGrey);
|
||||
FT.DrawString(20, y, s);
|
||||
if (nr == curr_act) FT.SetColor(colYellow);
|
||||
else FT.SetColor(colLGrey);
|
||||
FT.DrawString(100, y, Float_StrN(f, 2));
|
||||
}
|
||||
|
||||
void RenderChar (double timestep) {
|
||||
void RenderChar(double timestep) {
|
||||
if (!must_render) return;
|
||||
bool is_visible = false;
|
||||
|
||||
// ------------- 3d scenery ---------------------------------------
|
||||
ScopedRenderMode rm1(TUX);
|
||||
ClearRenderContext (colDDBackgr);
|
||||
TestChar.highlight_node = TestChar.GetNodeName (curr_node);
|
||||
ClearRenderContext(colDDBackgr);
|
||||
TestChar.highlight_node = TestChar.GetNodeName(curr_node);
|
||||
|
||||
glLoadIdentity ();
|
||||
glPushMatrix ();
|
||||
SetToolLight ();
|
||||
glLoadIdentity();
|
||||
glPushMatrix();
|
||||
SetToolLight();
|
||||
|
||||
TestChar.ResetRoot ();
|
||||
TestChar.ResetJoints ();
|
||||
glTranslatef (xposition, yposition, zposition);
|
||||
glRotatef (xrotation, 1, 0, 0);
|
||||
glRotatef (yrotation, 0, 1, 0);
|
||||
glRotatef (zrotation, 0, 0, 1);
|
||||
TestChar.ResetRoot();
|
||||
TestChar.ResetJoints();
|
||||
glTranslatef(xposition, yposition, zposition);
|
||||
glRotatef(xrotation, 1, 0, 0);
|
||||
glRotatef(yrotation, 0, 1, 0);
|
||||
glRotatef(zrotation, 0, 0, 1);
|
||||
|
||||
if (drawcount > 0) TestChar.Draw ();
|
||||
glPopMatrix ();
|
||||
if (drawcount > 0) TestChar.Draw();
|
||||
glPopMatrix();
|
||||
drawcount++;
|
||||
|
||||
// --------------- 2d screen --------------------------------------
|
||||
Setup2dScene ();
|
||||
Setup2dScene();
|
||||
ScopedRenderMode rm2(TEXFONT);
|
||||
|
||||
FT.SetProps("bold", 20, colYellow);
|
||||
FT.DrawString (-1, 10, "Edit mode");
|
||||
FT.DrawString(-1, 10, "Edit mode");
|
||||
|
||||
if (CharHasChanged ()) DrawChanged ();
|
||||
if (CharHasChanged()) DrawChanged();
|
||||
|
||||
FT.SetSize (16);
|
||||
FT.SetSize(16);
|
||||
for (size_t i=0; i<=lastnode; i++) {
|
||||
if (i != curr_node) {
|
||||
FT.SetColor (colLGrey);
|
||||
FT.SetFont ("normal");
|
||||
FT.SetColor(colLGrey);
|
||||
FT.SetFont("normal");
|
||||
} else {
|
||||
FT.SetColor (colYellow);
|
||||
FT.SetFont ("bold");
|
||||
FT.SetColor(colYellow);
|
||||
FT.SetFont("bold");
|
||||
}
|
||||
int xl = ITrunc ((int)i, charbase) * 100 + 20;
|
||||
int yt = IFrac ((int)i, charbase) * 18 + 60;
|
||||
FT.DrawString (xl, yt, TestChar.GetNodeJoint (i));
|
||||
int xl = ITrunc((int)i, charbase) * 100 + 20;
|
||||
int yt = IFrac((int)i, charbase) * 18 + 60;
|
||||
FT.DrawString(xl, yt, TestChar.GetNodeJoint(i));
|
||||
}
|
||||
|
||||
size_t num = action->num;
|
||||
|
@ -379,22 +379,22 @@ void RenderChar (double timestep) {
|
|||
int yt = Winsys.resolution.height - 120 + (int)i * 18;
|
||||
switch (type) {
|
||||
case 0:
|
||||
DrawActionVec (i, "trans", yt, action->vec[i]);
|
||||
DrawActionVec(i, "trans", yt, action->vec[i]);
|
||||
break;
|
||||
case 1:
|
||||
DrawActionFloat (i, "x-rot", yt, action->dval[i]);
|
||||
DrawActionFloat(i, "x-rot", yt, action->dval[i]);
|
||||
break;
|
||||
case 2:
|
||||
DrawActionFloat (i, "y-rot", yt, action->dval[i]);
|
||||
DrawActionFloat(i, "y-rot", yt, action->dval[i]);
|
||||
break;
|
||||
case 3:
|
||||
DrawActionFloat (i, "z-rot", yt, action->dval[i]);
|
||||
DrawActionFloat(i, "z-rot", yt, action->dval[i]);
|
||||
break;
|
||||
case 4:
|
||||
DrawActionVec (i, "scale", yt, action->vec[i]);
|
||||
DrawActionVec(i, "scale", yt, action->vec[i]);
|
||||
break;
|
||||
case 5:
|
||||
DrawActionFloat (i, "vis", yt, action->dval[i]);
|
||||
DrawActionFloat(i, "vis", yt, action->dval[i]);
|
||||
is_visible = true;
|
||||
break;
|
||||
default:
|
||||
|
@ -404,17 +404,17 @@ void RenderChar (double timestep) {
|
|||
}
|
||||
|
||||
FT.SetFont("normal");
|
||||
if (is_visible) FT.SetColor (colYellow);
|
||||
else FT.SetColor (colLGrey);
|
||||
FT.DrawString (20, 20, action->name);
|
||||
if (is_visible) FT.SetColor(colYellow);
|
||||
else FT.SetColor(colLGrey);
|
||||
FT.DrawString(20, 20, action->name);
|
||||
|
||||
if (ToolsFinalStage ()) {
|
||||
FT.SetSize (20);
|
||||
FT.SetColor (colYellow);
|
||||
FT.DrawString (-1, Winsys.resolution.height - 50, "Quit program. Save character list (y/n)");
|
||||
if (ToolsFinalStage()) {
|
||||
FT.SetSize(20);
|
||||
FT.SetColor(colYellow);
|
||||
FT.DrawString(-1, Winsys.resolution.height - 50, "Quit program. Save character list (y/n)");
|
||||
}
|
||||
|
||||
Reshape (Winsys.resolution.width, Winsys.resolution.height);
|
||||
Winsys.SwapBuffers ();
|
||||
Reshape(Winsys.resolution.width, Winsys.resolution.height);
|
||||
Winsys.SwapBuffers();
|
||||
if (drawcount > 3) must_render = false;
|
||||
}
|
||||
|
|
|
@ -22,12 +22,12 @@ GNU General Public License for more details.
|
|||
|
||||
struct TCharAction;
|
||||
|
||||
void InitCharTools ();
|
||||
void CharKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void CharMouse (int button, int state, int x, int y);
|
||||
void CharMotion (int x, int y);
|
||||
void RenderChar (double timestep);
|
||||
void StoreAction (TCharAction *act);
|
||||
void InitCharTools();
|
||||
void CharKeys(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void CharMouse(int button, int state, int x, int y);
|
||||
void CharMotion(int x, int y);
|
||||
void RenderChar(double timestep);
|
||||
void StoreAction(TCharAction *act);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -42,19 +42,19 @@ static bool alt = false;
|
|||
static bool lastframe = 0;
|
||||
static bool keyrun = false;
|
||||
|
||||
void InitFrameTools () {
|
||||
void InitFrameTools() {
|
||||
framebase = (int)((Winsys.resolution.height - 350) / 18);
|
||||
if (TestFrame.numFrames() < 1) TestFrame.AddFrame ();
|
||||
if (TestFrame.numFrames() < 1) TestFrame.AddFrame();
|
||||
curr_joint = 0;
|
||||
last_joint = TestFrame.GetNumJoints () -1;
|
||||
last_joint = TestFrame.GetNumJoints() -1;
|
||||
}
|
||||
|
||||
void SingleFrameKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void SingleFrameKeys(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
//PrintInt (key);
|
||||
must_render = true;
|
||||
int keyfact;
|
||||
lastframe = TestFrame.numFrames() != 1;
|
||||
TKeyframe *frame = TestFrame.GetFrame (curr_frame);
|
||||
TKeyframe *frame = TestFrame.GetFrame(curr_frame);
|
||||
|
||||
// setting the camera change state
|
||||
if (key == sf::Keyboard::F1) {GluCamera.turnright = !release; return;}
|
||||
|
@ -74,38 +74,38 @@ void SingleFrameKeys (sf::Keyboard::Key key, bool special, bool release, int x,
|
|||
switch (key) {
|
||||
case sf::Keyboard::Y:
|
||||
case sf::Keyboard::J:
|
||||
if (ToolsFinalStage ()) {
|
||||
SaveToolCharacter ();
|
||||
SaveToolFrame ();
|
||||
if (ToolsFinalStage()) {
|
||||
SaveToolCharacter();
|
||||
SaveToolFrame();
|
||||
State::manager.RequestQuit();
|
||||
}
|
||||
break;
|
||||
case sf::Keyboard::N:
|
||||
if (ToolsFinalStage ()) State::manager.RequestQuit();
|
||||
if (ToolsFinalStage()) State::manager.RequestQuit();
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Escape:
|
||||
case sf::Keyboard::Q:
|
||||
QuitTool ();
|
||||
QuitTool();
|
||||
break;
|
||||
case sf::Keyboard::S:
|
||||
SaveToolFrame ();
|
||||
SaveToolFrame();
|
||||
break;
|
||||
case sf::Keyboard::Tab:
|
||||
SetToolMode (0);
|
||||
SetToolMode(0);
|
||||
break;
|
||||
|
||||
case sf::Keyboard::A:
|
||||
TestFrame.AddFrame ();
|
||||
SetFrameChanged (true);
|
||||
TestFrame.AddFrame();
|
||||
SetFrameChanged(true);
|
||||
break;
|
||||
case sf::Keyboard::Insert:
|
||||
TestFrame.InsertFrame (curr_frame);
|
||||
SetFrameChanged (true);
|
||||
TestFrame.InsertFrame(curr_frame);
|
||||
SetFrameChanged(true);
|
||||
break;
|
||||
case sf::Keyboard::Delete:
|
||||
curr_frame = TestFrame.DeleteFrame (curr_frame);
|
||||
SetFrameChanged (true);
|
||||
curr_frame = TestFrame.DeleteFrame(curr_frame);
|
||||
SetFrameChanged(true);
|
||||
break;
|
||||
case sf::Keyboard::PageDown:
|
||||
if (curr_frame < TestFrame.numFrames()-1) curr_frame++;
|
||||
|
@ -122,26 +122,26 @@ void SingleFrameKeys (sf::Keyboard::Key key, bool special, bool release, int x,
|
|||
case sf::Keyboard::Right:
|
||||
if (curr_joint < 4) frame->val[curr_joint] += 0.05;
|
||||
else frame->val[curr_joint] += 1;
|
||||
SetFrameChanged (true);
|
||||
SetFrameChanged(true);
|
||||
break;
|
||||
case sf::Keyboard::Left:
|
||||
if (curr_joint < 4) frame->val[curr_joint] -= 0.05;
|
||||
else frame->val[curr_joint] -= 1;
|
||||
SetFrameChanged (true);
|
||||
SetFrameChanged(true);
|
||||
break;
|
||||
case sf::Keyboard::Num0:
|
||||
frame->val[curr_joint] = 0.0;
|
||||
SetFrameChanged (true);
|
||||
SetFrameChanged(true);
|
||||
break;
|
||||
case sf::Keyboard::Space:
|
||||
if (curr_joint < 4) frame->val[curr_joint] += 0.05 * keyfact;
|
||||
else frame->val[curr_joint] += 1 * keyfact;
|
||||
SetFrameChanged (true);
|
||||
SetFrameChanged(true);
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Return:
|
||||
TestFrame.InitTest (ref_position, &TestChar);
|
||||
SetToolMode (2);
|
||||
TestFrame.InitTest(ref_position, &TestChar);
|
||||
SetToolMode(2);
|
||||
must_render = true;
|
||||
break;
|
||||
|
||||
|
@ -152,20 +152,20 @@ void SingleFrameKeys (sf::Keyboard::Key key, bool special, bool release, int x,
|
|||
TestChar.useHighlighting = !TestChar.useHighlighting;
|
||||
break;
|
||||
case sf::Keyboard::C:
|
||||
if (control) TestFrame.CopyToClipboard (curr_frame);
|
||||
else TestFrame.ClearFrame (curr_frame);
|
||||
SetFrameChanged (true);
|
||||
if (control) TestFrame.CopyToClipboard(curr_frame);
|
||||
else TestFrame.ClearFrame(curr_frame);
|
||||
SetFrameChanged(true);
|
||||
break;
|
||||
case sf::Keyboard::V:
|
||||
if (control) TestFrame.PasteFromClipboard (curr_frame);
|
||||
SetFrameChanged (true);
|
||||
if (control) TestFrame.PasteFromClipboard(curr_frame);
|
||||
SetFrameChanged(true);
|
||||
break;
|
||||
case sf::Keyboard::P:
|
||||
if (curr_frame>0)
|
||||
TestFrame.CopyFrame (curr_frame-1, curr_frame);
|
||||
TestFrame.CopyFrame(curr_frame-1, curr_frame);
|
||||
break;
|
||||
case sf::Keyboard::F10:
|
||||
ScreenshotN ();
|
||||
ScreenshotN();
|
||||
break;
|
||||
|
||||
case sf::Keyboard::Num1:
|
||||
|
@ -195,9 +195,9 @@ void SingleFrameKeys (sf::Keyboard::Key key, bool special, bool release, int x,
|
|||
}
|
||||
}
|
||||
|
||||
void SingleFrameMouse (int button, int state, int x, int y) {
|
||||
void SingleFrameMouse(int button, int state, int x, int y) {
|
||||
must_render = true;
|
||||
if (ToolsFinalStage ()) return;
|
||||
if (ToolsFinalStage()) return;
|
||||
|
||||
if (button == 4) {
|
||||
GluCamera.distance += 0.1;
|
||||
|
@ -206,77 +206,77 @@ void SingleFrameMouse (int button, int state, int x, int y) {
|
|||
}
|
||||
}
|
||||
|
||||
void SingleFrameMotion (int x, int y) {
|
||||
void SingleFrameMotion(int x, int y) {
|
||||
}
|
||||
|
||||
void PrintFrameParams (int ytop, TKeyframe *frame) {
|
||||
void PrintFrameParams(int ytop, TKeyframe *frame) {
|
||||
int offs = 18;
|
||||
|
||||
for (int i=0; i<=last_joint; i++) {
|
||||
if (i == curr_joint) FT.SetColor (colYellow);
|
||||
else FT.SetColor (colLGrey);
|
||||
if (i == curr_joint) FT.SetColor(colYellow);
|
||||
else FT.SetColor(colLGrey);
|
||||
|
||||
int x = ITrunc (i, jointbase) * 140 + 20;
|
||||
int y = IFrac (i, jointbase) * offs + ytop;
|
||||
int x = ITrunc(i, jointbase) * 140 + 20;
|
||||
int y = IFrac(i, jointbase) * offs + ytop;
|
||||
|
||||
FT.DrawString (x, y, TestFrame.GetJointName(i));
|
||||
if (i < 4) FT.DrawString (x+80, y, Float_StrN (frame->val[i], 2));
|
||||
else FT.DrawString (x+80, y, Float_StrN (frame->val[i], 0));
|
||||
FT.DrawString(x, y, TestFrame.GetJointName(i));
|
||||
if (i < 4) FT.DrawString(x+80, y, Float_StrN(frame->val[i], 2));
|
||||
else FT.DrawString(x+80, y, Float_StrN(frame->val[i], 0));
|
||||
}
|
||||
}
|
||||
|
||||
void RenderSingleFrame (double timestep) {
|
||||
void RenderSingleFrame(double timestep) {
|
||||
if (!must_render) return;
|
||||
|
||||
// ------------------ 3d scenery ----------------------------------
|
||||
ScopedRenderMode rm1(TUX);
|
||||
ClearRenderContext (colDDBackgr);
|
||||
ClearRenderContext(colDDBackgr);
|
||||
|
||||
const string& hlname = TestFrame.GetHighlightName (curr_joint);
|
||||
TestChar.highlight_node = TestChar.GetNodeName (hlname);
|
||||
const string& hlname = TestFrame.GetHighlightName(curr_joint);
|
||||
TestChar.highlight_node = TestChar.GetNodeName(hlname);
|
||||
|
||||
glPushMatrix ();
|
||||
SetToolLight ();
|
||||
GluCamera.Update (timestep);
|
||||
glPushMatrix();
|
||||
SetToolLight();
|
||||
GluCamera.Update(timestep);
|
||||
|
||||
TestFrame.CalcKeyframe (curr_frame, &TestChar, ref_position);
|
||||
TestChar.Draw ();
|
||||
glPopMatrix ();
|
||||
TestFrame.CalcKeyframe(curr_frame, &TestChar, ref_position);
|
||||
TestChar.Draw();
|
||||
glPopMatrix();
|
||||
|
||||
// ----------------- 2d screen ------------------------------------
|
||||
Setup2dScene ();
|
||||
Setup2dScene();
|
||||
ScopedRenderMode rm2(TEXFONT);
|
||||
|
||||
if (FrameHasChanged ()) DrawChanged ();
|
||||
if (FrameHasChanged()) DrawChanged();
|
||||
|
||||
FT.SetProps("bold", 20, colYellow);
|
||||
FT.DrawString (-1, 10, "Keyframe mode");
|
||||
FT.DrawString(-1, 10, "Keyframe mode");
|
||||
|
||||
FT.SetProps("normal", 16);
|
||||
for (size_t i=0; i<TestFrame.numFrames(); i++) {
|
||||
if (i != curr_frame) {
|
||||
FT.SetColor (colLGrey);
|
||||
FT.SetFont ("normal");
|
||||
FT.SetColor(colLGrey);
|
||||
FT.SetFont("normal");
|
||||
} else {
|
||||
FT.SetColor (colYellow);
|
||||
FT.SetFont ("bold");
|
||||
FT.SetColor(colYellow);
|
||||
FT.SetFont("bold");
|
||||
}
|
||||
int xl = ITrunc ((int)i, framebase) * 100 + 20;
|
||||
int yt = IFrac ((int)i, framebase) * 18 + 20;
|
||||
FT.DrawString (xl, yt, Int_StrN ((int)i));
|
||||
int xl = ITrunc((int)i, framebase) * 100 + 20;
|
||||
int yt = IFrac((int)i, framebase) * 18 + 20;
|
||||
FT.DrawString(xl, yt, Int_StrN((int)i));
|
||||
}
|
||||
|
||||
FT.SetFont ("normal");
|
||||
FT.SetColor (colLGrey);
|
||||
PrintFrameParams (Winsys.resolution.height - 330, TestFrame.GetFrame (curr_frame));
|
||||
FT.SetFont("normal");
|
||||
FT.SetColor(colLGrey);
|
||||
PrintFrameParams(Winsys.resolution.height - 330, TestFrame.GetFrame(curr_frame));
|
||||
|
||||
if (ToolsFinalStage ()) {
|
||||
FT.SetSize (20);
|
||||
FT.SetColor (colYellow);
|
||||
FT.DrawString (-1, Winsys.resolution.height - 50, "Quit program. Save character list (y/n)");
|
||||
if (ToolsFinalStage()) {
|
||||
FT.SetSize(20);
|
||||
FT.SetColor(colYellow);
|
||||
FT.DrawString(-1, Winsys.resolution.height - 50, "Quit program. Save character list (y/n)");
|
||||
}
|
||||
|
||||
Reshape (Winsys.resolution.width, Winsys.resolution.height);
|
||||
Reshape(Winsys.resolution.width, Winsys.resolution.height);
|
||||
Winsys.SwapBuffers();
|
||||
must_render = false;
|
||||
}
|
||||
|
@ -286,7 +286,7 @@ void RenderSingleFrame (double timestep) {
|
|||
// frame sequence
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void SequenceKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
void SequenceKeys(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
if (release) return;
|
||||
switch (key) {
|
||||
case sf::Keyboard::Return:
|
||||
|
@ -294,32 +294,32 @@ void SequenceKeys (sf::Keyboard::Key key, bool special, bool release, int x, int
|
|||
break;
|
||||
case sf::Keyboard::Escape:
|
||||
case sf::Keyboard::Tab:
|
||||
SetToolMode (1);
|
||||
SetToolMode(1);
|
||||
break;
|
||||
case sf::Keyboard::Q:
|
||||
QuitTool ();
|
||||
QuitTool();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SequenceMouse (int button, int state, int x, int y) {}
|
||||
void SequenceMotion (int x, int y) {}
|
||||
void SequenceMouse(int button, int state, int x, int y) {}
|
||||
void SequenceMotion(int x, int y) {}
|
||||
|
||||
void RenderSequence (double timestep) {
|
||||
void RenderSequence(double timestep) {
|
||||
ScopedRenderMode rm(TUX);
|
||||
ClearRenderContext (colDDBackgr);
|
||||
ClearRenderContext(colDDBackgr);
|
||||
|
||||
GluCamera.Update (timestep);
|
||||
if (TestFrame.active) TestFrame.UpdateTest (timestep, &TestChar);
|
||||
GluCamera.Update(timestep);
|
||||
if (TestFrame.active) TestFrame.UpdateTest(timestep, &TestChar);
|
||||
else if (keyrun) {
|
||||
TestFrame.InitTest (NullVec3, &TestChar);
|
||||
TestFrame.InitTest(NullVec3, &TestChar);
|
||||
keyrun = false;
|
||||
}
|
||||
|
||||
glPushMatrix ();
|
||||
TestChar.Draw ();
|
||||
glPopMatrix ();
|
||||
glPushMatrix();
|
||||
TestChar.Draw();
|
||||
glPopMatrix();
|
||||
|
||||
Reshape (Winsys.resolution.width, Winsys.resolution.height);
|
||||
Reshape(Winsys.resolution.width, Winsys.resolution.height);
|
||||
Winsys.SwapBuffers();
|
||||
}
|
||||
|
|
|
@ -20,20 +20,20 @@ GNU General Public License for more details.
|
|||
|
||||
#include "bh.h"
|
||||
|
||||
void InitFrameTools ();
|
||||
void SingleFrameKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void SingleFrameMouse (int button, int state, int x, int y);
|
||||
void SingleFrameMotion (int x, int y);
|
||||
void RenderSingleFrame (double timestep);
|
||||
void InitFrameTools();
|
||||
void SingleFrameKeys(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void SingleFrameMouse(int button, int state, int x, int y);
|
||||
void SingleFrameMotion(int x, int y);
|
||||
void RenderSingleFrame(double timestep);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// frame sequence
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void SequenceKeys (sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void SequenceMouse (int button, int state, int x, int y);
|
||||
void SequenceMotion (int x, int y);
|
||||
void RenderSequence (double timestep);
|
||||
void SequenceKeys(sf::Keyboard::Key key, bool special, bool release, int x, int y);
|
||||
void SequenceMouse(int button, int state, int x, int y);
|
||||
void SequenceMotion(int x, int y);
|
||||
void RenderSequence(double timestep);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
134
src/tools.cpp
134
src/tools.cpp
|
@ -33,7 +33,7 @@ GNU General Public License for more details.
|
|||
|
||||
CGluCamera GluCamera;
|
||||
|
||||
CCamera::CCamera () {
|
||||
CCamera::CCamera() {
|
||||
xview = 0;
|
||||
yview = 0;
|
||||
zview = 4;
|
||||
|
@ -52,48 +52,48 @@ CCamera::CCamera () {
|
|||
pitchdown = false;
|
||||
}
|
||||
|
||||
void CCamera::XMove (GLfloat step) {
|
||||
void CCamera::XMove(GLfloat step) {
|
||||
zview += (float)sin(-vhead * 3.14 / 180) * step;
|
||||
xview += (float)cos(-vhead * 3.14 / 180) * step;
|
||||
}
|
||||
|
||||
void CCamera::YMove (GLfloat step) {
|
||||
void CCamera::YMove(GLfloat step) {
|
||||
yview += step;
|
||||
}
|
||||
|
||||
void CCamera::ZMove (GLfloat step) {
|
||||
xview += (float)sin (vhead * 3.14 / 180) * step;
|
||||
zview += (float)cos (vhead * 3.14 / 180) * step;
|
||||
void CCamera::ZMove(GLfloat step) {
|
||||
xview += (float)sin(vhead * 3.14 / 180) * step;
|
||||
zview += (float)cos(vhead * 3.14 / 180) * step;
|
||||
}
|
||||
|
||||
void CCamera::RotateHead (GLfloat step) {
|
||||
void CCamera::RotateHead(GLfloat step) {
|
||||
vhead += step;
|
||||
}
|
||||
|
||||
void CCamera::RotatePitch (GLfloat step) {
|
||||
void CCamera::RotatePitch(GLfloat step) {
|
||||
vpitch += step;
|
||||
}
|
||||
|
||||
void CCamera::Update (float timestep) {
|
||||
if (fore) ZMove (-2 * timestep);
|
||||
if (back) ZMove (2 * timestep);
|
||||
if (left) XMove (-1 * timestep);
|
||||
if (right) XMove (1 * timestep);
|
||||
if (up) YMove (1 * timestep);
|
||||
if (down) YMove (-1 * timestep);
|
||||
if (headleft) RotateHead (5 * timestep);
|
||||
if (headright) RotateHead (-5 * timestep);
|
||||
if (pitchup) RotatePitch (-2 * timestep);
|
||||
if (pitchdown) RotatePitch (2 * timestep);
|
||||
void CCamera::Update(float timestep) {
|
||||
if (fore) ZMove(-2 * timestep);
|
||||
if (back) ZMove(2 * timestep);
|
||||
if (left) XMove(-1 * timestep);
|
||||
if (right) XMove(1 * timestep);
|
||||
if (up) YMove(1 * timestep);
|
||||
if (down) YMove(-1 * timestep);
|
||||
if (headleft) RotateHead(5 * timestep);
|
||||
if (headright) RotateHead(-5 * timestep);
|
||||
if (pitchup) RotatePitch(-2 * timestep);
|
||||
if (pitchdown) RotatePitch(2 * timestep);
|
||||
|
||||
glLoadIdentity ();
|
||||
glRotatef (-vpitch, 1.0, 0.0 , 0.0);
|
||||
glRotatef (-vhead, 0.0, 1.0 , 0.0);
|
||||
glTranslatef (-xview, -yview, -zview);
|
||||
glLoadIdentity();
|
||||
glRotatef(-vpitch, 1.0, 0.0 , 0.0);
|
||||
glRotatef(-vhead, 0.0, 1.0 , 0.0);
|
||||
glTranslatef(-xview, -yview, -zview);
|
||||
}
|
||||
|
||||
|
||||
CGluCamera::CGluCamera () {
|
||||
CGluCamera::CGluCamera() {
|
||||
angle = 0.0;
|
||||
distance = 3.0;
|
||||
turnright = false;
|
||||
|
@ -102,15 +102,15 @@ CGluCamera::CGluCamera () {
|
|||
farther = false;
|
||||
}
|
||||
|
||||
void CGluCamera::Update (double timestep) {
|
||||
void CGluCamera::Update(double timestep) {
|
||||
if (turnright) angle += timestep * 2000;
|
||||
if (turnleft) angle -= timestep * 2000;
|
||||
if (nearer) distance -= timestep * 100;
|
||||
if (farther) distance += timestep * 100;
|
||||
double xx = distance * sin (angle * M_PI / 180);
|
||||
double zz = distance * sin ((90 - angle) * M_PI / 180);
|
||||
glLoadIdentity ();
|
||||
gluLookAt (xx, 0, zz, 0, 0, 0, 0, 1, 0);
|
||||
double xx = distance * sin(angle * M_PI / 180);
|
||||
double zz = distance * sin((90 - angle) * M_PI / 180);
|
||||
glLoadIdentity();
|
||||
gluLookAt(xx, 0, zz, 0, 0, 0, 0, 1, 0);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -136,7 +136,7 @@ static const TLight toollight = {
|
|||
static int tool_mode = 0;
|
||||
|
||||
void DrawQuad(float x, float y, float w, float h, float scrheight, const sf::Color& col, int frame) {
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor(col);
|
||||
const GLfloat vtx[] = {
|
||||
x - frame, scrheight - y - h - frame,
|
||||
|
@ -150,26 +150,26 @@ void DrawQuad(float x, float y, float w, float h, float scrheight, const sf::Col
|
|||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void DrawChanged () {
|
||||
DrawQuad (Winsys.resolution.width - 120, 10, 100, 22, Winsys.resolution.height, colRed, 0);
|
||||
void DrawChanged() {
|
||||
DrawQuad(Winsys.resolution.width - 120, 10, 100, 22, Winsys.resolution.height, colRed, 0);
|
||||
FT.SetProps("normal", 18, colBlack);
|
||||
FT.DrawString (Winsys.resolution.width - 110, 8, "changed");
|
||||
FT.DrawString(Winsys.resolution.width - 110, 8, "changed");
|
||||
}
|
||||
|
||||
void SetToolLight () {
|
||||
void SetToolLight() {
|
||||
toollight.Enable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
void QuitTool () {
|
||||
void QuitTool() {
|
||||
if (!charchanged && !framechanged) State::manager.RequestQuit();
|
||||
else finalstage = true;
|
||||
}
|
||||
|
||||
void SetToolMode (int newmode) {
|
||||
void SetToolMode(int newmode) {
|
||||
if (newmode == tool_mode) return;
|
||||
if (newmode > 2) tool_mode = 0;
|
||||
else tool_mode = newmode;
|
||||
|
@ -183,35 +183,35 @@ void SetToolMode (int newmode) {
|
|||
}
|
||||
}
|
||||
|
||||
bool CharHasChanged () {return charchanged;}
|
||||
bool FrameHasChanged () {return framechanged;}
|
||||
bool CharHasChanged() {return charchanged;}
|
||||
bool FrameHasChanged() {return framechanged;}
|
||||
|
||||
bool ToolsFinalStage () {
|
||||
bool ToolsFinalStage() {
|
||||
return finalstage;
|
||||
}
|
||||
|
||||
void SetCharChanged (bool val) {
|
||||
void SetCharChanged(bool val) {
|
||||
charchanged = val;
|
||||
}
|
||||
|
||||
void SetFrameChanged (bool val) {
|
||||
void SetFrameChanged(bool val) {
|
||||
framechanged = val;
|
||||
}
|
||||
|
||||
void SaveToolCharacter () {
|
||||
void SaveToolCharacter() {
|
||||
if (!charchanged) return;
|
||||
TestChar.SaveCharNodes (char_dir, char_file);
|
||||
TestChar.SaveCharNodes(char_dir, char_file);
|
||||
charchanged = false;
|
||||
}
|
||||
|
||||
void ReloadToolCharacter () {
|
||||
TestChar.Load (char_dir, char_file, true);
|
||||
void ReloadToolCharacter() {
|
||||
TestChar.Load(char_dir, char_file, true);
|
||||
charchanged = false;
|
||||
}
|
||||
|
||||
void SaveToolFrame () {
|
||||
void SaveToolFrame() {
|
||||
if (!framechanged) return;
|
||||
TestFrame.SaveTest (char_dir, frame_file);
|
||||
TestFrame.SaveTest(char_dir, frame_file);
|
||||
framechanged = false;
|
||||
}
|
||||
|
||||
|
@ -222,33 +222,33 @@ void CTools::SetParameter(const string& dir, const string& file) {
|
|||
}
|
||||
|
||||
void CTools::Enter() {
|
||||
if (TestChar.Load (char_dir, char_file, true) == false) {
|
||||
Message ("could not load 'shape.lst'");
|
||||
if (TestChar.Load(char_dir, char_file, true) == false) {
|
||||
Message("could not load 'shape.lst'");
|
||||
Winsys.Terminate();
|
||||
}
|
||||
if (TestFrame.Load (char_dir, frame_file) == false) {
|
||||
Message ("could not load 'frame.lst'");
|
||||
if (TestFrame.Load(char_dir, frame_file) == false) {
|
||||
Message("could not load 'frame.lst'");
|
||||
Winsys.Terminate();
|
||||
}
|
||||
charchanged = false;
|
||||
framechanged = false;
|
||||
|
||||
InitCharTools ();
|
||||
InitFrameTools ();
|
||||
InitCharTools();
|
||||
InitFrameTools();
|
||||
|
||||
Winsys.KeyRepeat (true);
|
||||
Winsys.KeyRepeat(true);
|
||||
}
|
||||
|
||||
void CTools::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int y) {
|
||||
switch (tool_mode) {
|
||||
case 0:
|
||||
CharKeys (key, special, release, x, y);
|
||||
CharKeys(key, special, release, x, y);
|
||||
break;
|
||||
case 1:
|
||||
SingleFrameKeys (key, special, release, x, y);
|
||||
SingleFrameKeys(key, special, release, x, y);
|
||||
break;
|
||||
case 2:
|
||||
SequenceKeys (key, special, release, x, y);
|
||||
SequenceKeys(key, special, release, x, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -256,13 +256,13 @@ void CTools::Keyb(sf::Keyboard::Key key, bool special, bool release, int x, int
|
|||
void CTools::Mouse(int button, int state, int x, int y) {
|
||||
switch (tool_mode) {
|
||||
case 0:
|
||||
CharMouse (button, state, x, y);
|
||||
CharMouse(button, state, x, y);
|
||||
break;
|
||||
case 1:
|
||||
SingleFrameMouse (button, state, x, y);
|
||||
SingleFrameMouse(button, state, x, y);
|
||||
break;
|
||||
case 2:
|
||||
SequenceMouse (button, state, x, y);
|
||||
SequenceMouse(button, state, x, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -270,13 +270,13 @@ void CTools::Mouse(int button, int state, int x, int y) {
|
|||
void CTools::Motion(int x, int y) {
|
||||
switch (tool_mode) {
|
||||
case 0:
|
||||
CharMotion (x, y);
|
||||
CharMotion(x, y);
|
||||
break;
|
||||
case 1:
|
||||
SingleFrameMotion (x, y);
|
||||
SingleFrameMotion(x, y);
|
||||
break;
|
||||
case 2:
|
||||
SequenceMotion (x, y);
|
||||
SequenceMotion(x, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -284,13 +284,13 @@ void CTools::Motion(int x, int y) {
|
|||
void CTools::Loop(double timestep) {
|
||||
switch (tool_mode) {
|
||||
case 0:
|
||||
RenderChar (timestep);
|
||||
RenderChar(timestep);
|
||||
break;
|
||||
case 1:
|
||||
RenderSingleFrame (timestep);
|
||||
RenderSingleFrame(timestep);
|
||||
break;
|
||||
case 2:
|
||||
RenderSequence (timestep);
|
||||
RenderSequence(timestep);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
42
src/tools.h
42
src/tools.h
|
@ -29,13 +29,13 @@ private:
|
|||
GLfloat vhead; // heading - Rundumsicht
|
||||
GLfloat vpitch; // pitch - Drehung nach oben/unten
|
||||
|
||||
void XMove (GLfloat step);
|
||||
void YMove (GLfloat step);
|
||||
void ZMove (GLfloat step);
|
||||
void RotateHead (GLfloat step);
|
||||
void RotatePitch (GLfloat step);
|
||||
void XMove(GLfloat step);
|
||||
void YMove(GLfloat step);
|
||||
void ZMove(GLfloat step);
|
||||
void RotateHead(GLfloat step);
|
||||
void RotatePitch(GLfloat step);
|
||||
public:
|
||||
CCamera ();
|
||||
CCamera();
|
||||
|
||||
bool fore;
|
||||
bool back;
|
||||
|
@ -47,7 +47,7 @@ public:
|
|||
bool headright;
|
||||
bool pitchup;
|
||||
bool pitchdown;
|
||||
void Update (float timestep);
|
||||
void Update(float timestep);
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
@ -57,10 +57,10 @@ public:
|
|||
class CGluCamera {
|
||||
private:
|
||||
public:
|
||||
CGluCamera ();
|
||||
CGluCamera();
|
||||
double distance;
|
||||
double angle;
|
||||
void Update (double timestep);
|
||||
void Update(double timestep);
|
||||
|
||||
bool turnright;
|
||||
bool turnleft;
|
||||
|
@ -72,18 +72,18 @@ extern CGluCamera GluCamera;
|
|||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void SetToolLight ();
|
||||
void QuitTool ();
|
||||
void SetToolMode (int newmode);
|
||||
bool ToolsFinalStage ();
|
||||
void SetCharChanged (bool val);
|
||||
void SetFrameChanged (bool val);
|
||||
bool CharHasChanged ();
|
||||
bool FrameHasChanged ();
|
||||
void SaveToolCharacter ();
|
||||
void SaveToolFrame ();
|
||||
void ReloadToolCharacter ();
|
||||
void DrawChanged ();
|
||||
void SetToolLight();
|
||||
void QuitTool();
|
||||
void SetToolMode(int newmode);
|
||||
bool ToolsFinalStage();
|
||||
void SetCharChanged(bool val);
|
||||
void SetFrameChanged(bool val);
|
||||
bool CharHasChanged();
|
||||
bool FrameHasChanged();
|
||||
void SaveToolCharacter();
|
||||
void SaveToolFrame();
|
||||
void ReloadToolCharacter();
|
||||
void DrawChanged();
|
||||
|
||||
|
||||
class CTools : public State {
|
||||
|
|
|
@ -105,15 +105,15 @@ void DrawTrackmarks() {
|
|||
sf::Color track_colour = colWhite;
|
||||
ScopedRenderMode rm(TRACK_MARKS);
|
||||
|
||||
textures[TRACK_HEAD] = Tex.GetTexture (trackid1);
|
||||
textures[TRACK_MARK] = Tex.GetTexture (trackid2);
|
||||
textures[TRACK_TAIL] = Tex.GetTexture (trackid3);
|
||||
textures[TRACK_HEAD] = Tex.GetTexture(trackid1);
|
||||
textures[TRACK_MARK] = Tex.GetTexture(trackid2);
|
||||
textures[TRACK_TAIL] = Tex.GetTexture(trackid3);
|
||||
|
||||
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
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);
|
||||
set_material(track_colour, colBlack, 1.0);
|
||||
textures[q->track_type]->Bind();
|
||||
|
||||
if ((q->track_type == TRACK_HEAD) || (q->track_type == TRACK_TAIL)) {
|
||||
|
@ -160,7 +160,7 @@ void DrawTrackmarks() {
|
|||
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);
|
||||
set_material(track_colour, colBlack, 1.0);
|
||||
|
||||
glNormal3(q->n4);
|
||||
glTexCoord2(q->t4);
|
||||
|
@ -203,7 +203,7 @@ void add_track_mark(const CControl *ctrl, int *id) {
|
|||
|
||||
TTerrType *TerrList = &Course.TerrList[0];
|
||||
|
||||
*id = Course.GetTerrainIdx (ctrl->cpos.x, ctrl->cpos.z, 0.5);
|
||||
*id = Course.GetTerrainIdx(ctrl->cpos.x, ctrl->cpos.z, 0.5);
|
||||
if (*id < 1) {
|
||||
break_track_marks();
|
||||
return;
|
||||
|
@ -220,7 +220,7 @@ void add_track_mark(const CControl *ctrl, int *id) {
|
|||
return;
|
||||
}
|
||||
|
||||
TVector3d width_vector = CrossProduct (ctrl->cdirection, TVector3d (0, 1, 0));
|
||||
TVector3d width_vector = CrossProduct(ctrl->cdirection, TVector3d(0, 1, 0));
|
||||
double magnitude = width_vector.Norm();
|
||||
if (magnitude == 0) {
|
||||
break_track_marks();
|
||||
|
@ -231,16 +231,16 @@ void add_track_mark(const CControl *ctrl, int *id) {
|
|||
TVector3d right_vector = -TRACK_WIDTH/2.0 * width_vector;
|
||||
TVector3d left_wing = ctrl->cpos - left_vector;
|
||||
TVector3d right_wing = ctrl->cpos - right_vector;
|
||||
double left_y = Course.FindYCoord (left_wing.x, left_wing.z);
|
||||
double right_y = Course.FindYCoord (right_wing.x, right_wing.z);
|
||||
double left_y = Course.FindYCoord(left_wing.x, left_wing.z);
|
||||
double right_y = Course.FindYCoord(right_wing.x, right_wing.z);
|
||||
|
||||
if (fabs(left_y-right_y) > MAX_TRACK_DEPTH) {
|
||||
break_track_marks();
|
||||
return;
|
||||
}
|
||||
|
||||
TPlane surf_plane = Course.GetLocalCoursePlane (ctrl->cpos);
|
||||
double dist_from_surface = DistanceToPlane (surf_plane, ctrl->cpos);
|
||||
TPlane surf_plane = Course.GetLocalCoursePlane(ctrl->cpos);
|
||||
double dist_from_surface = DistanceToPlane(surf_plane, ctrl->cpos);
|
||||
// comp_depth = get_compression_depth(Snow);
|
||||
double comp_depth = 0.1;
|
||||
if (dist_from_surface >= (2 * comp_depth)) {
|
||||
|
@ -259,12 +259,12 @@ void add_track_mark(const CControl *ctrl, int *id) {
|
|||
|
||||
if (!continuing_track) {
|
||||
q->track_type = TRACK_HEAD;
|
||||
q->v1 = TVector3d (left_wing.x, left_y + TRACK_HEIGHT, left_wing.z);
|
||||
q->v2 = TVector3d (right_wing.x, right_y + TRACK_HEIGHT, right_wing.z);
|
||||
q->v3 = TVector3d (left_wing.x, left_y + TRACK_HEIGHT, left_wing.z);
|
||||
q->v4 = TVector3d (right_wing.x, right_y + TRACK_HEIGHT, right_wing.z);
|
||||
q->n1 = Course.FindCourseNormal (q->v1.x, q->v1.z);
|
||||
q->n2 = Course.FindCourseNormal (q->v2.x, q->v2.z);
|
||||
q->v1 = TVector3d(left_wing.x, left_y + TRACK_HEIGHT, left_wing.z);
|
||||
q->v2 = TVector3d(right_wing.x, right_y + TRACK_HEIGHT, right_wing.z);
|
||||
q->v3 = TVector3d(left_wing.x, left_y + TRACK_HEIGHT, left_wing.z);
|
||||
q->v4 = TVector3d(right_wing.x, right_y + TRACK_HEIGHT, right_wing.z);
|
||||
q->n1 = Course.FindCourseNormal(q->v1.x, q->v1.z);
|
||||
q->n2 = Course.FindCourseNormal(q->v2.x, q->v2.z);
|
||||
q->t1 = TVector2d(0.0, 0.0);
|
||||
q->t2 = TVector2d(1.0, 0.0);
|
||||
} else {
|
||||
|
@ -278,20 +278,20 @@ void add_track_mark(const CControl *ctrl, int *id) {
|
|||
q->t2 = qprev->t4;
|
||||
if (qprev->track_type == TRACK_TAIL) qprev->track_type = TRACK_MARK;
|
||||
}
|
||||
q->v3 = TVector3d (left_wing.x, left_y + TRACK_HEIGHT, left_wing.z);
|
||||
q->v4 = TVector3d (right_wing.x, right_y + TRACK_HEIGHT, right_wing.z);
|
||||
q->n3 = Course.FindCourseNormal (q->v3.x, q->v3.z);
|
||||
q->n4 = Course.FindCourseNormal (q->v4.x, q->v4.z);
|
||||
q->v3 = TVector3d(left_wing.x, left_y + TRACK_HEIGHT, left_wing.z);
|
||||
q->v4 = TVector3d(right_wing.x, right_y + TRACK_HEIGHT, right_wing.z);
|
||||
q->n3 = Course.FindCourseNormal(q->v3.x, q->v3.z);
|
||||
q->n4 = Course.FindCourseNormal(q->v4.x, q->v4.z);
|
||||
double tex_end = speed*g_game.time_step/TRACK_WIDTH;
|
||||
if (q->track_type == TRACK_HEAD) {
|
||||
q->t3= TVector2d (0.0, 1.0);
|
||||
q->t4= TVector2d (1.0, 1.0);
|
||||
q->t3= TVector2d(0.0, 1.0);
|
||||
q->t4= TVector2d(1.0, 1.0);
|
||||
} else {
|
||||
q->t3 = TVector2d (0.0, q->t1.y + tex_end);
|
||||
q->t4 = TVector2d (1.0, q->t2.y + tex_end);
|
||||
q->t3 = TVector2d(0.0, q->t1.y + tex_end);
|
||||
q->t4 = TVector2d(1.0, q->t2.y + tex_end);
|
||||
}
|
||||
}
|
||||
q->alpha = min ((2*comp_depth-dist_from_surface)/(4*comp_depth)*255, 255);
|
||||
q->alpha = min((2*comp_depth-dist_from_surface)/(4*comp_depth)*255, 255);
|
||||
continuing_track = true;
|
||||
}
|
||||
|
||||
|
@ -302,10 +302,10 @@ void UpdateTrackmarks(const CControl *ctrl) {
|
|||
int trackid;
|
||||
TTerrType *TerrList = &Course.TerrList[0];
|
||||
|
||||
add_track_mark (ctrl, &trackid);
|
||||
add_track_mark(ctrl, &trackid);
|
||||
if (trackid >= 0 && TerrList[trackid].trackmarks) {
|
||||
SetTrackIDs (TerrList[trackid].starttex,
|
||||
TerrList[trackid].tracktex,
|
||||
TerrList[trackid].stoptex);
|
||||
SetTrackIDs(TerrList[trackid].starttex,
|
||||
TerrList[trackid].tracktex,
|
||||
TerrList[trackid].stoptex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ CTranslation Trans;
|
|||
|
||||
// if anything is wrong with an translation, the program will fall back
|
||||
// to these defaults (only the wrong items)
|
||||
void CTranslation::SetDefaultTranslations () {
|
||||
void CTranslation::SetDefaultTranslations() {
|
||||
texts[0] = "Press any key to start";
|
||||
texts[1] = "Enter an event";
|
||||
texts[2] = "Practice";
|
||||
|
@ -148,28 +148,28 @@ static wstring UnicodeStr(const char *s) {
|
|||
for (size_t i = 0, j = 0; i < len; ++i, ++j) {
|
||||
wchar_t ch = ((const unsigned char *) s)[i];
|
||||
if (ch >= 0xF0) {
|
||||
ch = (wchar_t) (s[i] & 0x07) << 18;
|
||||
ch |= (wchar_t) (s[++i] & 0x3F) << 12;
|
||||
ch |= (wchar_t) (s[++i] & 0x3F) << 6;
|
||||
ch |= (wchar_t) (s[++i] & 0x3F);
|
||||
ch = (wchar_t)(s[i] & 0x07) << 18;
|
||||
ch |= (wchar_t)(s[++i] & 0x3F) << 12;
|
||||
ch |= (wchar_t)(s[++i] & 0x3F) << 6;
|
||||
ch |= (wchar_t)(s[++i] & 0x3F);
|
||||
} else if (ch >= 0xE0) {
|
||||
ch = (wchar_t) (s[i] & 0x0F) << 12;
|
||||
ch |= (wchar_t) (s[++i] & 0x3F) << 6;
|
||||
ch |= (wchar_t) (s[++i] & 0x3F);
|
||||
ch = (wchar_t)(s[i] & 0x0F) << 12;
|
||||
ch |= (wchar_t)(s[++i] & 0x3F) << 6;
|
||||
ch |= (wchar_t)(s[++i] & 0x3F);
|
||||
} else if (ch >= 0xC0) {
|
||||
ch = (wchar_t) (s[i] & 0x1F) << 6;
|
||||
ch |= (wchar_t) (s[++i] & 0x3F);
|
||||
ch = (wchar_t)(s[i] & 0x1F) << 6;
|
||||
ch |= (wchar_t)(s[++i] & 0x3F);
|
||||
}
|
||||
res[j] = ch;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void CTranslation::LoadLanguages () {
|
||||
CSPList list (MAX_LANGUAGES);
|
||||
void CTranslation::LoadLanguages() {
|
||||
CSPList list(MAX_LANGUAGES);
|
||||
|
||||
if (!list.Load (param.trans_dir, "languages.lst")) {
|
||||
Message ("could not load language list");
|
||||
if (!list.Load(param.trans_dir, "languages.lst")) {
|
||||
Message("could not load language list");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ void CTranslation::LoadLanguages () {
|
|||
languages[0].language = "English";
|
||||
for (size_t i=1; i<list.Count()+1; i++) {
|
||||
const string& line = list.Line(i-1);
|
||||
languages[i].lang = SPStrN (line, "lang", "en_GB");
|
||||
languages[i].lang = SPStrN(line, "lang", "en_GB");
|
||||
languages[i].language = UnicodeStr(SPStrN(line, "language", "English").c_str());
|
||||
}
|
||||
|
||||
|
@ -186,26 +186,26 @@ void CTranslation::LoadLanguages () {
|
|||
param.language = GetSystemDefaultLangIdx();
|
||||
}
|
||||
|
||||
const sf::String& CTranslation::GetLanguage (size_t idx) const {
|
||||
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;
|
||||
}
|
||||
|
||||
void CTranslation::LoadTranslations (size_t langidx) {
|
||||
SetDefaultTranslations ();
|
||||
void CTranslation::LoadTranslations(size_t langidx) {
|
||||
SetDefaultTranslations();
|
||||
if (langidx == 0 || langidx >= languages.size()) return;
|
||||
|
||||
CSPList list(MAX_COMMON_TEXT_LINES);
|
||||
string filename = languages[langidx].lang + ".lst";
|
||||
if (!list.Load (param.trans_dir, filename)) {
|
||||
Message ("could not load translations list:", filename);
|
||||
if (!list.Load(param.trans_dir, filename)) {
|
||||
Message("could not load translations list:", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
int idx = SPIntN (line, "idx", -1);
|
||||
int idx = SPIntN(line, "idx", -1);
|
||||
if (idx >= 0 && idx < NUM_COMMON_TEXTS) {
|
||||
texts[idx] = UnicodeStr(SPStrN(line, "trans", texts[idx]).c_str());
|
||||
}
|
||||
|
|
|
@ -42,11 +42,11 @@ private:
|
|||
public:
|
||||
vector<TLang> languages;
|
||||
|
||||
void LoadLanguages ();
|
||||
void LoadLanguages();
|
||||
const sf::String& GetLanguage(size_t idx) const;
|
||||
void SetDefaultTranslations ();
|
||||
void SetDefaultTranslations();
|
||||
const sf::String& Text(size_t idx) const;
|
||||
void LoadTranslations (size_t langidx);
|
||||
void LoadTranslations(size_t langidx);
|
||||
static string GetSystemDefaultLang();
|
||||
size_t GetSystemDefaultLangIdx() const;
|
||||
size_t GetLangIdx(const string& lang) const;
|
||||
|
|
404
src/tux.cpp
404
src/tux.cpp
|
@ -52,7 +52,7 @@ static const TCharMaterial TuxDefMat = { sf::Color(0.5 * 255, 0.5 * 255, 0.5 * 2
|
|||
static const TCharMaterial Highlight = { sf::Color(0.8 * 255, 0.15 * 255, 0.15 * 255), colBlack, 0.0 };
|
||||
CCharShape TestChar;
|
||||
|
||||
CCharShape::CCharShape () {
|
||||
CCharShape::CCharShape() {
|
||||
for (int i=0; i<MAX_CHAR_NODES; i++) {
|
||||
Nodes[i] = NULL;
|
||||
Index[i] = -1;
|
||||
|
@ -80,18 +80,18 @@ CCharShape::~CCharShape() {
|
|||
// nodes
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
size_t CCharShape::GetNodeIdx (size_t node_name) const {
|
||||
size_t CCharShape::GetNodeIdx(size_t node_name) const {
|
||||
if (node_name >= MAX_CHAR_NODES) return -1;
|
||||
return Index[node_name];
|
||||
}
|
||||
|
||||
TCharNode *CCharShape::GetNode (size_t node_name) {
|
||||
size_t idx = GetNodeIdx (node_name);
|
||||
TCharNode *CCharShape::GetNode(size_t node_name) {
|
||||
size_t idx = GetNodeIdx(node_name);
|
||||
if (idx >= numNodes) return NULL;
|
||||
return Nodes[idx];
|
||||
}
|
||||
|
||||
void CCharShape::CreateRootNode () {
|
||||
void CCharShape::CreateRootNode() {
|
||||
TCharNode *node = new TCharNode;
|
||||
node->node_name = 0;
|
||||
node->parent = NULL;
|
||||
|
@ -116,9 +116,9 @@ void CCharShape::CreateRootNode () {
|
|||
}
|
||||
|
||||
bool CCharShape::CreateCharNode(int parent_name, size_t node_name, const string& joint, const string& name, const string& order, bool shadow) {
|
||||
TCharNode *parent = GetNode (parent_name);
|
||||
TCharNode *parent = GetNode(parent_name);
|
||||
if (parent == NULL) {
|
||||
Message ("wrong parent node");
|
||||
Message("wrong parent node");
|
||||
return false;
|
||||
}
|
||||
TCharNode *node = new TCharNode;
|
||||
|
@ -167,8 +167,8 @@ bool CCharShape::CreateCharNode(int parent_name, size_t node_name, const string&
|
|||
return true;
|
||||
}
|
||||
|
||||
void CCharShape::AddAction (size_t node_name, int type, const TVector3d& vec, double val) {
|
||||
size_t idx = GetNodeIdx (node_name);
|
||||
void CCharShape::AddAction(size_t node_name, int type, const TVector3d& vec, double val) {
|
||||
size_t idx = GetNodeIdx(node_name);
|
||||
TCharAction *act = Nodes[idx]->action;
|
||||
act->type[act->num] = type;
|
||||
act->vec[act->num] = vec;
|
||||
|
@ -176,8 +176,8 @@ void CCharShape::AddAction (size_t node_name, int type, const TVector3d& vec, do
|
|||
act->num++;
|
||||
}
|
||||
|
||||
bool CCharShape::TranslateNode (size_t node_name, const TVector3d& vec) {
|
||||
TCharNode *node = GetNode (node_name);
|
||||
bool CCharShape::TranslateNode(size_t node_name, const TVector3d& vec) {
|
||||
TCharNode *node = GetNode(node_name);
|
||||
if (node == NULL) return false;
|
||||
|
||||
TMatrix<4, 4> TransMatrix;
|
||||
|
@ -187,12 +187,12 @@ bool CCharShape::TranslateNode (size_t node_name, const TVector3d& vec) {
|
|||
TransMatrix.SetTranslationMatrix(-vec.x, -vec.y, -vec.z);
|
||||
node->invtrans = TransMatrix * node->invtrans;
|
||||
|
||||
if (newActions && useActions) AddAction (node_name, 0, vec, 0);
|
||||
if (newActions && useActions) AddAction(node_name, 0, vec, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCharShape::RotateNode (size_t node_name, int axis, double angle) {
|
||||
TCharNode *node = GetNode (node_name);
|
||||
bool CCharShape::RotateNode(size_t node_name, int axis, double angle) {
|
||||
TCharNode *node = GetNode(node_name);
|
||||
if (node == NULL) return false;
|
||||
|
||||
if (axis > 3) return false;
|
||||
|
@ -216,17 +216,17 @@ bool CCharShape::RotateNode (size_t node_name, int axis, double angle) {
|
|||
rotMatrix.SetRotationMatrix(-angle, caxis);
|
||||
node->invtrans = rotMatrix * node->invtrans;
|
||||
|
||||
if (newActions && useActions) AddAction (node_name, axis, NullVec3, angle);
|
||||
if (newActions && useActions) AddAction(node_name, axis, NullVec3, angle);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCharShape::RotateNode (const string& node_trivialname, int axis, double angle) {
|
||||
bool CCharShape::RotateNode(const string& node_trivialname, int axis, double angle) {
|
||||
map<string, size_t>::const_iterator i = NodeIndex.find(node_trivialname);
|
||||
if (i == NodeIndex.end()) return false;
|
||||
return RotateNode (i->second, axis, angle);
|
||||
return RotateNode(i->second, axis, angle);
|
||||
}
|
||||
|
||||
void CCharShape::ScaleNode (size_t node_name, const TVector3d& vec) {
|
||||
void CCharShape::ScaleNode(size_t node_name, const TVector3d& vec) {
|
||||
TCharNode *node = GetNode(node_name);
|
||||
if (node == NULL) return;
|
||||
|
||||
|
@ -237,10 +237,10 @@ void CCharShape::ScaleNode (size_t node_name, const TVector3d& vec) {
|
|||
matrix.SetScalingMatrix(1.0 / vec.x, 1.0 / vec.y, 1.0 / vec.z);
|
||||
node->invtrans = matrix * node->invtrans;
|
||||
|
||||
if (newActions && useActions) AddAction (node_name, 4, vec, 0);
|
||||
if (newActions && useActions) AddAction(node_name, 4, vec, 0);
|
||||
}
|
||||
|
||||
bool CCharShape::VisibleNode (size_t node_name, float level) {
|
||||
bool CCharShape::VisibleNode(size_t node_name, float level) {
|
||||
TCharNode *node = GetNode(node_name);
|
||||
if (node == NULL) return false;
|
||||
|
||||
|
@ -248,14 +248,14 @@ bool CCharShape::VisibleNode (size_t node_name, float level) {
|
|||
|
||||
if (node->visible) {
|
||||
node->divisions =
|
||||
clamp (MIN_SPHERE_DIV, ROUND_TO_NEAREST (param.tux_sphere_divisions * level / 10), MAX_SPHERE_DIV);
|
||||
clamp(MIN_SPHERE_DIV, ROUND_TO_NEAREST(param.tux_sphere_divisions * level / 10), MAX_SPHERE_DIV);
|
||||
node->radius = 1.0;
|
||||
}
|
||||
if (newActions && useActions) AddAction (node_name, 5, NullVec3, level);
|
||||
if (newActions && useActions) AddAction(node_name, 5, NullVec3, level);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCharShape::MaterialNode (size_t node_name, const string& mat_name) {
|
||||
bool CCharShape::MaterialNode(size_t node_name, const string& mat_name) {
|
||||
TCharNode *node = GetNode(node_name);
|
||||
if (node == NULL) return false;
|
||||
TCharMaterial *mat = GetMaterial(mat_name);
|
||||
|
@ -265,7 +265,7 @@ bool CCharShape::MaterialNode (size_t node_name, const string& mat_name) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CCharShape::ResetNode (size_t node_name) {
|
||||
bool CCharShape::ResetNode(size_t node_name) {
|
||||
TCharNode *node = GetNode(node_name);
|
||||
if (node == NULL) return false;
|
||||
|
||||
|
@ -274,10 +274,10 @@ bool CCharShape::ResetNode (size_t node_name) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CCharShape::ResetNode (const string& node_trivialname) {
|
||||
bool CCharShape::ResetNode(const string& node_trivialname) {
|
||||
map<string, size_t>::const_iterator i = NodeIndex.find(node_trivialname);
|
||||
if (i == NodeIndex.end()) return false;
|
||||
return ResetNode (i->second);
|
||||
return ResetNode(i->second);
|
||||
}
|
||||
|
||||
bool CCharShape::TransformNode(size_t node_name, const TMatrix<4, 4>& mat, const TMatrix<4, 4>& invmat) {
|
||||
|
@ -289,21 +289,21 @@ bool CCharShape::TransformNode(size_t node_name, const TMatrix<4, 4>& mat, const
|
|||
return true;
|
||||
}
|
||||
|
||||
void CCharShape::ResetJoints () {
|
||||
ResetNode ("left_shldr");
|
||||
ResetNode ("right_shldr");
|
||||
ResetNode ("left_hip");
|
||||
ResetNode ("right_hip");
|
||||
ResetNode ("left_knee");
|
||||
ResetNode ("right_knee");
|
||||
ResetNode ("left_ankle");
|
||||
ResetNode ("right_ankle");
|
||||
ResetNode ("tail");
|
||||
ResetNode ("neck");
|
||||
ResetNode ("head");
|
||||
void CCharShape::ResetJoints() {
|
||||
ResetNode("left_shldr");
|
||||
ResetNode("right_shldr");
|
||||
ResetNode("left_hip");
|
||||
ResetNode("right_hip");
|
||||
ResetNode("left_knee");
|
||||
ResetNode("right_knee");
|
||||
ResetNode("left_ankle");
|
||||
ResetNode("right_ankle");
|
||||
ResetNode("tail");
|
||||
ResetNode("neck");
|
||||
ResetNode("head");
|
||||
}
|
||||
|
||||
void CCharShape::Reset () {
|
||||
void CCharShape::Reset() {
|
||||
for (int i=0; i<MAX_CHAR_NODES; i++) {
|
||||
if (Nodes[i] != NULL) {
|
||||
delete Nodes[i]->action;
|
||||
|
@ -329,7 +329,7 @@ void CCharShape::Reset () {
|
|||
// materials
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
TCharMaterial* CCharShape::GetMaterial (const string& mat_name) {
|
||||
TCharMaterial* CCharShape::GetMaterial(const string& mat_name) {
|
||||
map<string, size_t>::const_iterator i = MaterialIndex.find(mat_name);
|
||||
if (i != MaterialIndex.end() && i->second < Materials.size()) {
|
||||
return &Materials[i->second];
|
||||
|
@ -337,10 +337,10 @@ TCharMaterial* CCharShape::GetMaterial (const string& mat_name) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void CCharShape::CreateMaterial (const string& line) {
|
||||
void CCharShape::CreateMaterial(const string& line) {
|
||||
TVector3d diff = SPVector3d(line, "diff");
|
||||
TVector3d spec = SPVector3d(line, "spec");
|
||||
float exp = SPFloatN (line, "exp", 50);
|
||||
float exp = SPFloatN(line, "exp", 50);
|
||||
std::string mat = SPStrN(line, "mat");
|
||||
|
||||
Materials.push_back(TCharMaterial());
|
||||
|
@ -363,16 +363,16 @@ void CCharShape::CreateMaterial (const string& line) {
|
|||
// drawing
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void CCharShape::DrawCharSphere (int num_divisions) {
|
||||
void CCharShape::DrawCharSphere(int num_divisions) {
|
||||
GLUquadricObj *qobj = gluNewQuadric();
|
||||
gluQuadricDrawStyle (qobj, GLU_FILL);
|
||||
gluQuadricOrientation (qobj, GLU_OUTSIDE);
|
||||
gluQuadricNormals (qobj, GLU_SMOOTH);
|
||||
gluSphere (qobj, 1.0, (GLint)2.0 * num_divisions, num_divisions);
|
||||
gluDeleteQuadric (qobj);
|
||||
gluQuadricDrawStyle(qobj, GLU_FILL);
|
||||
gluQuadricOrientation(qobj, GLU_OUTSIDE);
|
||||
gluQuadricNormals(qobj, GLU_SMOOTH);
|
||||
gluSphere(qobj, 1.0, (GLint)2.0 * num_divisions, num_divisions);
|
||||
gluDeleteQuadric(qobj);
|
||||
}
|
||||
|
||||
void CCharShape::DrawNodes (const TCharNode *node) {
|
||||
void CCharShape::DrawNodes(const TCharNode *node) {
|
||||
glPushMatrix();
|
||||
glMultMatrix(node->trans);
|
||||
|
||||
|
@ -386,14 +386,14 @@ void CCharShape::DrawNodes (const TCharNode *node) {
|
|||
}
|
||||
|
||||
if (node->visible == true) {
|
||||
set_material (mat->diffuse, mat->specular, mat->exp);
|
||||
set_material(mat->diffuse, mat->specular, mat->exp);
|
||||
|
||||
DrawCharSphere (node->divisions);
|
||||
DrawCharSphere(node->divisions);
|
||||
}
|
||||
// -------------- recursive loop -------------------------------------
|
||||
TCharNode *child = node->child;
|
||||
while (child != NULL) {
|
||||
DrawNodes (child);
|
||||
DrawNodes(child);
|
||||
if (child->node_name == highlight_node) highlighted = false;
|
||||
child = child->next;
|
||||
}
|
||||
|
@ -401,80 +401,80 @@ void CCharShape::DrawNodes (const TCharNode *node) {
|
|||
glPopMatrix();
|
||||
}
|
||||
|
||||
void CCharShape::Draw () {
|
||||
void CCharShape::Draw() {
|
||||
static const float dummy_color[] = {0.0, 0.0, 0.0, 1.0};
|
||||
|
||||
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dummy_color);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, dummy_color);
|
||||
ScopedRenderMode rm(TUX);
|
||||
glEnable (GL_NORMALIZE);
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
TCharNode *node = GetNode(0);
|
||||
if (node == NULL) return;
|
||||
|
||||
DrawNodes (node);
|
||||
glDisable (GL_NORMALIZE);
|
||||
if (param.perf_level > 2 && g_game.argument == 0) DrawShadow ();
|
||||
DrawNodes(node);
|
||||
glDisable(GL_NORMALIZE);
|
||||
if (param.perf_level > 2 && g_game.argument == 0) DrawShadow();
|
||||
highlighted = false;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
bool CCharShape::Load (const string& dir, const string& filename, bool with_actions) {
|
||||
CSPList list (500);
|
||||
bool CCharShape::Load(const string& dir, const string& filename, bool with_actions) {
|
||||
CSPList list(500);
|
||||
|
||||
useActions = with_actions;
|
||||
CreateRootNode ();
|
||||
CreateRootNode();
|
||||
newActions = true;
|
||||
|
||||
if (!list.Load (dir, filename)) {
|
||||
Message ("could not load character", filename);
|
||||
if (!list.Load(dir, filename)) {
|
||||
Message("could not load character", filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i=0; i<list.Count(); i++) {
|
||||
const string& line = list.Line(i);
|
||||
int node_name = SPIntN (line, "node", -1);
|
||||
int parent_name = SPIntN (line, "par", -1);
|
||||
string mat_name = SPStrN (line, "mat");
|
||||
string name = SPStrN (line, "joint");
|
||||
string fullname = SPStrN (line, "name");
|
||||
int node_name = SPIntN(line, "node", -1);
|
||||
int parent_name = SPIntN(line, "par", -1);
|
||||
string mat_name = SPStrN(line, "mat");
|
||||
string name = SPStrN(line, "joint");
|
||||
string fullname = SPStrN(line, "name");
|
||||
|
||||
if (SPIntN (line, "material", 0) > 0) {
|
||||
CreateMaterial (line);
|
||||
if (SPIntN(line, "material", 0) > 0) {
|
||||
CreateMaterial(line);
|
||||
} else {
|
||||
float visible = SPFloatN (line, "vis", -1.0);
|
||||
bool shadow = SPBoolN (line, "shad", false);
|
||||
string order = SPStrN (line, "order");
|
||||
CreateCharNode (parent_name, node_name, name, fullname, order, shadow);
|
||||
float visible = SPFloatN(line, "vis", -1.0);
|
||||
bool shadow = SPBoolN(line, "shad", false);
|
||||
string order = SPStrN(line, "order");
|
||||
CreateCharNode(parent_name, node_name, name, fullname, order, shadow);
|
||||
TVector3d rot = SPVector3d(line, "rot");
|
||||
MaterialNode (node_name, mat_name);
|
||||
MaterialNode(node_name, mat_name);
|
||||
for (size_t ii = 0; ii < order.size(); ii++) {
|
||||
int act = order[ii]-48;
|
||||
switch (act) {
|
||||
case 0: {
|
||||
TVector3d trans = SPVector3d(line, "trans");
|
||||
TranslateNode (node_name, trans);
|
||||
TranslateNode(node_name, trans);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
RotateNode (node_name, 1, rot.x);
|
||||
RotateNode(node_name, 1, rot.x);
|
||||
break;
|
||||
case 2:
|
||||
RotateNode (node_name, 2, rot.y);
|
||||
RotateNode(node_name, 2, rot.y);
|
||||
break;
|
||||
case 3:
|
||||
RotateNode (node_name, 3, rot.z);
|
||||
RotateNode(node_name, 3, rot.z);
|
||||
break;
|
||||
case 4: {
|
||||
TVector3d scale = SPVector3(line, "scale", TVector3d(1, 1, 1));
|
||||
ScaleNode (node_name, scale);
|
||||
ScaleNode(node_name, scale);
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
VisibleNode (node_name, visible);
|
||||
VisibleNode(node_name, visible);
|
||||
break;
|
||||
case 9:
|
||||
RotateNode (node_name, 2, rot.z);
|
||||
RotateNode(node_name, 2, rot.z);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -486,20 +486,20 @@ bool CCharShape::Load (const string& dir, const string& filename, bool with_acti
|
|||
return true;
|
||||
}
|
||||
|
||||
TVector3d CCharShape::AdjustRollvector (const CControl *ctrl, const TVector3d& vel_, const TVector3d& zvec) {
|
||||
TVector3d CCharShape::AdjustRollvector(const CControl *ctrl, const TVector3d& vel_, const TVector3d& zvec) {
|
||||
TMatrix<4, 4> rot_mat;
|
||||
TVector3d vel = ProjectToPlane(zvec, vel_);
|
||||
vel.Norm();
|
||||
if (ctrl->is_braking) {
|
||||
rot_mat = RotateAboutVectorMatrix (vel, ctrl->turn_fact * BRAKING_ROLL_ANGLE);
|
||||
rot_mat = RotateAboutVectorMatrix(vel, ctrl->turn_fact * BRAKING_ROLL_ANGLE);
|
||||
} else {
|
||||
rot_mat = RotateAboutVectorMatrix (vel, ctrl->turn_fact * MAX_ROLL_ANGLE);
|
||||
rot_mat = RotateAboutVectorMatrix(vel, ctrl->turn_fact * MAX_ROLL_ANGLE);
|
||||
}
|
||||
return TransformVector (rot_mat, zvec);
|
||||
return TransformVector(rot_mat, zvec);
|
||||
}
|
||||
|
||||
void CCharShape::AdjustOrientation (CControl *ctrl, double dtime,
|
||||
double dist_from_surface, const TVector3d& surf_nml) {
|
||||
void CCharShape::AdjustOrientation(CControl *ctrl, double dtime,
|
||||
double dist_from_surface, const TVector3d& surf_nml) {
|
||||
TVector3d new_y, new_z;
|
||||
static const TVector3d minus_z_vec(0, 0, -1);
|
||||
static const TVector3d y_vec(0, 1, 0);
|
||||
|
@ -507,19 +507,19 @@ void CCharShape::AdjustOrientation (CControl *ctrl, double dtime,
|
|||
if (dist_from_surface > 0) {
|
||||
new_y = ctrl->cvel;
|
||||
new_y.Norm();
|
||||
new_z = ProjectToPlane (new_y, TVector3d(0, -1, 0));
|
||||
new_z = ProjectToPlane(new_y, TVector3d(0, -1, 0));
|
||||
new_z.Norm();
|
||||
new_z = AdjustRollvector (ctrl, ctrl->cvel, new_z);
|
||||
new_z = AdjustRollvector(ctrl, ctrl->cvel, new_z);
|
||||
} else {
|
||||
new_z = -1.0 * surf_nml;
|
||||
new_z = AdjustRollvector (ctrl, ctrl->cvel, new_z);
|
||||
new_y = ProjectToPlane (surf_nml, ctrl->cvel);
|
||||
new_z = AdjustRollvector(ctrl, ctrl->cvel, new_z);
|
||||
new_y = ProjectToPlane(surf_nml, ctrl->cvel);
|
||||
new_y.Norm();
|
||||
}
|
||||
|
||||
TVector3d new_x = CrossProduct (new_y, new_z);
|
||||
TVector3d new_x = CrossProduct(new_y, new_z);
|
||||
TMatrix<4, 4> cob_mat(new_x, new_y, new_z);
|
||||
TQuaternion new_orient = MakeQuaternionFromMatrix (cob_mat);
|
||||
TQuaternion new_orient = MakeQuaternionFromMatrix(cob_mat);
|
||||
|
||||
if (!ctrl->orientation_initialized) {
|
||||
ctrl->orientation_initialized = true;
|
||||
|
@ -528,28 +528,28 @@ void CCharShape::AdjustOrientation (CControl *ctrl, double dtime,
|
|||
|
||||
double time_constant = dist_from_surface > 0 ? TO_AIR_TIME : TO_TIME;
|
||||
|
||||
ctrl->corientation = InterpolateQuaternions (
|
||||
ctrl->corientation = InterpolateQuaternions(
|
||||
ctrl->corientation, new_orient,
|
||||
min (dtime / time_constant, 1.0));
|
||||
min(dtime / time_constant, 1.0));
|
||||
|
||||
ctrl->plane_nml = RotateVector (ctrl->corientation, minus_z_vec);
|
||||
ctrl->cdirection = RotateVector (ctrl->corientation, y_vec);
|
||||
ctrl->plane_nml = RotateVector(ctrl->corientation, minus_z_vec);
|
||||
ctrl->cdirection = RotateVector(ctrl->corientation, y_vec);
|
||||
cob_mat = MakeMatrixFromQuaternion(ctrl->corientation);
|
||||
|
||||
// Trick rotations
|
||||
new_y = TVector3d (cob_mat[1][0], cob_mat[1][1], cob_mat[1][2]);
|
||||
new_y = TVector3d(cob_mat[1][0], cob_mat[1][1], cob_mat[1][2]);
|
||||
TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix(new_y, (ctrl->roll_factor * 360));
|
||||
cob_mat = rot_mat * cob_mat;
|
||||
new_x = TVector3d (cob_mat[0][0], cob_mat[0][1], cob_mat[0][2]);
|
||||
rot_mat = RotateAboutVectorMatrix (new_x, ctrl->flip_factor * 360);
|
||||
new_x = TVector3d(cob_mat[0][0], cob_mat[0][1], cob_mat[0][2]);
|
||||
rot_mat = RotateAboutVectorMatrix(new_x, ctrl->flip_factor * 360);
|
||||
cob_mat = rot_mat * cob_mat;
|
||||
|
||||
TransformNode (0, cob_mat, cob_mat.GetTransposed());
|
||||
TransformNode(0, cob_mat, cob_mat.GetTransposed());
|
||||
}
|
||||
|
||||
void CCharShape::AdjustJoints (double turnFact, bool isBraking,
|
||||
double paddling_factor, double speed,
|
||||
const TVector3d& net_force, double flap_factor) {
|
||||
void CCharShape::AdjustJoints(double turnFact, bool isBraking,
|
||||
double paddling_factor, double speed,
|
||||
const TVector3d& net_force, double flap_factor) {
|
||||
double turning_angle[2];
|
||||
double paddling_angle = 0;
|
||||
double ext_paddling_angle = 0;
|
||||
|
@ -567,33 +567,33 @@ void CCharShape::AdjustJoints (double turnFact, bool isBraking,
|
|||
|
||||
turning_angle[0] = max(-turnFact,0.0) * MAX_ARM_ANGLE2;
|
||||
turning_angle[1] = max(turnFact,0.0) * MAX_ARM_ANGLE2;
|
||||
flap_angle = MAX_ARM_ANGLE2 * (0.5 + 0.5 * sin (M_PI * flap_factor * 6 - M_PI / 2));
|
||||
force_angle = clamp (-20.0, -net_force.z / 300.0, 20.0);
|
||||
flap_angle = MAX_ARM_ANGLE2 * (0.5 + 0.5 * sin(M_PI * flap_factor * 6 - M_PI / 2));
|
||||
force_angle = clamp(-20.0, -net_force.z / 300.0, 20.0);
|
||||
turn_leg_angle = turnFact * 10;
|
||||
|
||||
ResetJoints ();
|
||||
ResetJoints();
|
||||
|
||||
RotateNode ("left_shldr", 3,
|
||||
min (braking_angle + paddling_angle + turning_angle[0], MAX_ARM_ANGLE2) + flap_angle);
|
||||
RotateNode ("right_shldr", 3,
|
||||
min (braking_angle + paddling_angle + turning_angle[1], MAX_ARM_ANGLE2) + flap_angle);
|
||||
RotateNode("left_shldr", 3,
|
||||
min(braking_angle + paddling_angle + turning_angle[0], MAX_ARM_ANGLE2) + flap_angle);
|
||||
RotateNode("right_shldr", 3,
|
||||
min(braking_angle + paddling_angle + turning_angle[1], MAX_ARM_ANGLE2) + flap_angle);
|
||||
|
||||
RotateNode ("left_shldr", 2, -ext_paddling_angle);
|
||||
RotateNode ("right_shldr", 2, ext_paddling_angle);
|
||||
RotateNode ("left_hip", 3, -20 + turn_leg_angle + force_angle);
|
||||
RotateNode ("right_hip", 3, -20 - turn_leg_angle + force_angle);
|
||||
RotateNode("left_shldr", 2, -ext_paddling_angle);
|
||||
RotateNode("right_shldr", 2, ext_paddling_angle);
|
||||
RotateNode("left_hip", 3, -20 + turn_leg_angle + force_angle);
|
||||
RotateNode("right_hip", 3, -20 - turn_leg_angle + force_angle);
|
||||
|
||||
RotateNode ("left_knee", 3,
|
||||
-10 + turn_leg_angle - min (35, speed) + kick_paddling_angle + force_angle);
|
||||
RotateNode ("right_knee", 3,
|
||||
-10 - turn_leg_angle - min (35, speed) - kick_paddling_angle + force_angle);
|
||||
RotateNode("left_knee", 3,
|
||||
-10 + turn_leg_angle - min(35, speed) + kick_paddling_angle + force_angle);
|
||||
RotateNode("right_knee", 3,
|
||||
-10 - turn_leg_angle - min(35, speed) - kick_paddling_angle + force_angle);
|
||||
|
||||
RotateNode ("left_ankle", 3, -20 + min (50, speed));
|
||||
RotateNode ("right_ankle", 3, -20 + min (50, speed));
|
||||
RotateNode ("tail", 3, turnFact * 20);
|
||||
RotateNode ("neck", 3, -50);
|
||||
RotateNode ("head", 3, -30);
|
||||
RotateNode ("head", 2, -turnFact * 70);
|
||||
RotateNode("left_ankle", 3, -20 + min(50, speed));
|
||||
RotateNode("right_ankle", 3, -20 + min(50, speed));
|
||||
RotateNode("tail", 3, turnFact * 20);
|
||||
RotateNode("neck", 3, -50);
|
||||
RotateNode("head", 3, -30);
|
||||
RotateNode("head", 2, -turnFact * 70);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -609,31 +609,31 @@ bool CCharShape::CheckPolyhedronCollision(const TCharNode *node, const TMatrix<4
|
|||
|
||||
if (node->visible) {
|
||||
TPolyhedron newph = ph;
|
||||
TransPolyhedron (newInvModelMatrix, newph);
|
||||
hit = IntersectPolyhedron (newph);
|
||||
TransPolyhedron(newInvModelMatrix, newph);
|
||||
hit = IntersectPolyhedron(newph);
|
||||
}
|
||||
|
||||
if (hit == true) return hit;
|
||||
const TCharNode *child = node->child;
|
||||
while (child != NULL) {
|
||||
hit = CheckPolyhedronCollision (child, newModelMatrix, newInvModelMatrix, ph);
|
||||
hit = CheckPolyhedronCollision(child, newModelMatrix, newInvModelMatrix, ph);
|
||||
if (hit == true) return hit;
|
||||
child = child->next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CCharShape::CheckCollision (const TPolyhedron& ph) {
|
||||
bool CCharShape::CheckCollision(const TPolyhedron& ph) {
|
||||
TCharNode *node = GetNode(0);
|
||||
if (node == NULL) return false;
|
||||
const TMatrix<4, 4>& identity = TMatrix<4, 4>::getIdentity();
|
||||
return CheckPolyhedronCollision(node, identity, identity, ph);
|
||||
}
|
||||
|
||||
bool CCharShape::Collision (const TVector3d& pos, const TPolyhedron& ph) {
|
||||
ResetNode (0);
|
||||
TranslateNode (0, TVector3d (pos.x, pos.y, pos.z));
|
||||
return CheckCollision (ph);
|
||||
bool CCharShape::Collision(const TVector3d& pos, const TPolyhedron& ph) {
|
||||
ResetNode(0);
|
||||
TranslateNode(0, TVector3d(pos.x, pos.y, pos.z));
|
||||
return CheckCollision(ph);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@ -642,10 +642,10 @@ bool CCharShape::Collision (const TVector3d& pos, const TPolyhedron& ph) {
|
|||
|
||||
void CCharShape::DrawShadowVertex(double x, double y, double z, const TMatrix<4, 4>& mat) {
|
||||
TVector3d pt(x, y, z);
|
||||
pt = TransformPoint (mat, pt);
|
||||
pt = TransformPoint(mat, pt);
|
||||
double old_y = pt.y;
|
||||
TVector3d nml = Course.FindCourseNormal (pt.x, pt.z);
|
||||
pt.y = Course.FindYCoord (pt.x, pt.z) + SHADOW_HEIGHT;
|
||||
TVector3d nml = Course.FindCourseNormal(pt.x, pt.z);
|
||||
pt.y = Course.FindYCoord(pt.x, pt.z) + SHADOW_HEIGHT;
|
||||
if (pt.y > old_y) pt.y = old_y;
|
||||
glNormal3(nml);
|
||||
glVertex3(pt);
|
||||
|
@ -665,68 +665,68 @@ void CCharShape::DrawShadowSphere(const TMatrix<4, 4>& mat) {
|
|||
double sin_phi, cos_phi;
|
||||
double sin_phi_d_phi, cos_phi_d_phi;
|
||||
|
||||
sin_phi = sin (phi);
|
||||
cos_phi = cos (phi);
|
||||
sin_phi_d_phi = sin (phi + d_phi);
|
||||
cos_phi_d_phi = cos (phi + d_phi);
|
||||
sin_phi = sin(phi);
|
||||
cos_phi = cos(phi);
|
||||
sin_phi_d_phi = sin(phi + d_phi);
|
||||
cos_phi_d_phi = cos(phi + d_phi);
|
||||
|
||||
if (phi <= eps) {
|
||||
glBegin (GL_TRIANGLE_FAN);
|
||||
DrawShadowVertex (0., 0., 1., mat);
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
DrawShadowVertex(0., 0., 1., mat);
|
||||
|
||||
for (theta = 0.0; theta + eps < twopi; theta += d_theta) {
|
||||
sin_theta = sin (theta);
|
||||
cos_theta = cos (theta);
|
||||
sin_theta = sin(theta);
|
||||
cos_theta = cos(theta);
|
||||
|
||||
x = cos_theta * sin_phi_d_phi;
|
||||
y = sin_theta * sin_phi_d_phi;
|
||||
z = cos_phi_d_phi;
|
||||
DrawShadowVertex (x, y, z, mat);
|
||||
DrawShadowVertex(x, y, z, mat);
|
||||
}
|
||||
x = sin_phi_d_phi;
|
||||
y = 0.0;
|
||||
z = cos_phi_d_phi;
|
||||
DrawShadowVertex (x, y, z, mat);
|
||||
DrawShadowVertex(x, y, z, mat);
|
||||
glEnd();
|
||||
} else if (phi + d_phi + eps >= M_PI) {
|
||||
glBegin (GL_TRIANGLE_FAN);
|
||||
DrawShadowVertex (0., 0., -1., mat);
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
DrawShadowVertex(0., 0., -1., mat);
|
||||
for (theta = twopi; theta - eps > 0; theta -= d_theta) {
|
||||
sin_theta = sin (theta);
|
||||
cos_theta = cos (theta);
|
||||
sin_theta = sin(theta);
|
||||
cos_theta = cos(theta);
|
||||
x = cos_theta * sin_phi;
|
||||
y = sin_theta * sin_phi;
|
||||
z = cos_phi;
|
||||
DrawShadowVertex (x, y, z, mat);
|
||||
DrawShadowVertex(x, y, z, mat);
|
||||
}
|
||||
x = sin_phi;
|
||||
y = 0.0;
|
||||
z = cos_phi;
|
||||
DrawShadowVertex (x, y, z, mat);
|
||||
DrawShadowVertex(x, y, z, mat);
|
||||
glEnd();
|
||||
} else {
|
||||
glBegin (GL_TRIANGLE_STRIP);
|
||||
glBegin(GL_TRIANGLE_STRIP);
|
||||
for (theta = 0.0; theta + eps < twopi; theta += d_theta) {
|
||||
sin_theta = sin (theta);
|
||||
cos_theta = cos (theta);
|
||||
sin_theta = sin(theta);
|
||||
cos_theta = cos(theta);
|
||||
x = cos_theta * sin_phi;
|
||||
y = sin_theta * sin_phi;
|
||||
z = cos_phi;
|
||||
DrawShadowVertex (x, y, z, mat);
|
||||
DrawShadowVertex(x, y, z, mat);
|
||||
|
||||
x = cos_theta * sin_phi_d_phi;
|
||||
y = sin_theta * sin_phi_d_phi;
|
||||
z = cos_phi_d_phi;
|
||||
DrawShadowVertex (x, y, z, mat);
|
||||
DrawShadowVertex(x, y, z, mat);
|
||||
}
|
||||
x = sin_phi;
|
||||
y = 0.0;
|
||||
z = cos_phi;
|
||||
DrawShadowVertex (x, y, z, mat);
|
||||
DrawShadowVertex(x, y, z, mat);
|
||||
x = sin_phi_d_phi;
|
||||
y = 0.0;
|
||||
z = cos_phi_d_phi;
|
||||
DrawShadowVertex (x, y, z, mat);
|
||||
DrawShadowVertex(x, y, z, mat);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
@ -735,16 +735,16 @@ void CCharShape::DrawShadowSphere(const TMatrix<4, 4>& mat) {
|
|||
void CCharShape::TraverseDagForShadow(const TCharNode *node, const TMatrix<4, 4>& mat) {
|
||||
TMatrix<4, 4> new_matrix = mat * node->trans;
|
||||
if (node->visible && node->render_shadow)
|
||||
DrawShadowSphere (new_matrix);
|
||||
DrawShadowSphere(new_matrix);
|
||||
|
||||
TCharNode* child = node->child;
|
||||
while (child != NULL) {
|
||||
TraverseDagForShadow (child, new_matrix);
|
||||
TraverseDagForShadow(child, new_matrix);
|
||||
child = child->next;
|
||||
}
|
||||
}
|
||||
|
||||
void CCharShape::DrawShadow () {
|
||||
void CCharShape::DrawShadow() {
|
||||
if (g_game.light_id == 1 || g_game.light_id == 3) return;
|
||||
|
||||
ScopedRenderMode rm(TUX_SHADOW);
|
||||
|
@ -752,7 +752,7 @@ void CCharShape::DrawShadow () {
|
|||
|
||||
TCharNode *node = GetNode(0);
|
||||
if (node == NULL) {
|
||||
Message ("couldn't find tux's root node");
|
||||
Message("couldn't find tux's root node");
|
||||
return;
|
||||
}
|
||||
TraverseDagForShadow(node, TMatrix<4, 4>::getIdentity());
|
||||
|
@ -762,25 +762,25 @@ void CCharShape::DrawShadow () {
|
|||
// testing and tools
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
string CCharShape::GetNodeJoint (size_t idx) const {
|
||||
string CCharShape::GetNodeJoint(size_t idx) const {
|
||||
if (idx >= numNodes) return "";
|
||||
TCharNode *node = Nodes[idx];
|
||||
if (node == NULL) return "";
|
||||
if (!node->joint.empty()) return node->joint;
|
||||
else return Int_StrN ((int)node->node_name);
|
||||
else return Int_StrN((int)node->node_name);
|
||||
}
|
||||
|
||||
size_t CCharShape::GetNodeName (size_t idx) const {
|
||||
size_t CCharShape::GetNodeName(size_t idx) const {
|
||||
if (idx >= numNodes) return -1;
|
||||
return Nodes[idx]->node_name;
|
||||
}
|
||||
|
||||
size_t CCharShape::GetNodeName (const string& node_trivialname) const {
|
||||
size_t CCharShape::GetNodeName(const string& node_trivialname) const {
|
||||
return NodeIndex.at(node_trivialname);
|
||||
}
|
||||
|
||||
|
||||
void CCharShape::RefreshNode (size_t idx) {
|
||||
void CCharShape::RefreshNode(size_t idx) {
|
||||
if (idx >= numNodes) return;
|
||||
TMatrix<4, 4> TempMatrix;
|
||||
char caxis;
|
||||
|
@ -837,7 +837,7 @@ void CCharShape::RefreshNode (size_t idx) {
|
|||
node->invtrans = TempMatrix * node->invtrans;
|
||||
break;
|
||||
case 5:
|
||||
VisibleNode (node->node_name, dval);
|
||||
VisibleNode(node->node_name, dval);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -845,60 +845,60 @@ void CCharShape::RefreshNode (size_t idx) {
|
|||
}
|
||||
}
|
||||
|
||||
const string& CCharShape::GetNodeFullname (size_t idx) const {
|
||||
const string& CCharShape::GetNodeFullname(size_t idx) const {
|
||||
if (idx >= numNodes) return emptyString;
|
||||
return Nodes[idx]->action->name;
|
||||
}
|
||||
|
||||
size_t CCharShape::GetNumActs (size_t idx) const {
|
||||
size_t CCharShape::GetNumActs(size_t idx) const {
|
||||
if (idx >= numNodes) return -1;
|
||||
return Nodes[idx]->action->num;
|
||||
}
|
||||
|
||||
TCharAction *CCharShape::GetAction (size_t idx) const {
|
||||
TCharAction *CCharShape::GetAction(size_t idx) const {
|
||||
if (idx >= numNodes) return NULL;
|
||||
return Nodes[idx]->action;
|
||||
}
|
||||
|
||||
void CCharShape::PrintAction (size_t idx) const {
|
||||
void CCharShape::PrintAction(size_t idx) const {
|
||||
if (idx >= numNodes) return;
|
||||
TCharAction *act = Nodes[idx]->action;
|
||||
PrintInt ((int)act->num);
|
||||
PrintInt((int)act->num);
|
||||
for (size_t i=0; i<act->num; i++) {
|
||||
PrintInt (act->type[i]);
|
||||
PrintDouble (act->dval[i]);
|
||||
PrintVector (act->vec[i]);
|
||||
PrintInt(act->type[i]);
|
||||
PrintDouble(act->dval[i]);
|
||||
PrintVector(act->vec[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void CCharShape::PrintNode (size_t idx) const {
|
||||
void CCharShape::PrintNode(size_t idx) const {
|
||||
TCharNode *node = Nodes[idx];
|
||||
PrintInt ("node: ", (int)node->node_name);
|
||||
PrintInt ("parent: ", (int)node->parent_name);
|
||||
PrintInt ("child: ", (int)node->child_name);
|
||||
PrintInt ("next: ", (int)node->next_name);
|
||||
PrintInt("node: ", (int)node->node_name);
|
||||
PrintInt("parent: ", (int)node->parent_name);
|
||||
PrintInt("child: ", (int)node->child_name);
|
||||
PrintInt("next: ", (int)node->next_name);
|
||||
}
|
||||
|
||||
void CCharShape::SaveCharNodes (const string& dir, const string& filename) {
|
||||
CSPList list (MAX_CHAR_NODES + 10);
|
||||
void CCharShape::SaveCharNodes(const string& dir, const string& filename) {
|
||||
CSPList list(MAX_CHAR_NODES + 10);
|
||||
|
||||
list.Add ("# Generated by Tuxracer tools");
|
||||
list.AddLine ();
|
||||
list.Add("# Generated by Tuxracer tools");
|
||||
list.AddLine();
|
||||
if (!Materials.empty()) {
|
||||
list.Add ("# Materials:");
|
||||
list.Add("# Materials:");
|
||||
for (size_t i=0; i<Materials.size(); i++)
|
||||
if (!Materials[i].matline.empty())
|
||||
list.Add (Materials[i].matline);
|
||||
list.AddLine ();
|
||||
list.Add(Materials[i].matline);
|
||||
list.AddLine();
|
||||
}
|
||||
|
||||
list.Add ("# Nodes:");
|
||||
list.Add("# Nodes:");
|
||||
for (size_t i=1; i<numNodes; i++) {
|
||||
TCharNode* node = Nodes[i];
|
||||
TCharAction* act = node->action;
|
||||
if (node->parent_name >= node->node_name) Message ("wrong parent index");
|
||||
string line = "*[node] " + Int_StrN ((int)node->node_name);
|
||||
line += " [par] " + Int_StrN ((int)node->parent_name);
|
||||
if (node->parent_name >= node->node_name) Message("wrong parent index");
|
||||
string line = "*[node] " + Int_StrN((int)node->node_name);
|
||||
line += " [par] " + Int_StrN((int)node->parent_name);
|
||||
|
||||
if (!act->order.empty()) {
|
||||
bool rotflag = false;
|
||||
|
@ -908,10 +908,10 @@ void CCharShape::SaveCharNodes (const string& dir, const string& filename) {
|
|||
int aa = act->order[ii]-48;
|
||||
switch (aa) {
|
||||
case 0:
|
||||
line += " [trans] " + Vector_StrN (act->vec[ii], 2);
|
||||
line += " [trans] " + Vector_StrN(act->vec[ii], 2);
|
||||
break;
|
||||
case 4:
|
||||
line += " [scale] " + Vector_StrN (act->vec[ii], 2);
|
||||
line += " [scale] " + Vector_StrN(act->vec[ii], 2);
|
||||
break;
|
||||
case 1:
|
||||
rotation.x = act->dval[ii];
|
||||
|
@ -926,7 +926,7 @@ void CCharShape::SaveCharNodes (const string& dir, const string& filename) {
|
|||
rotflag = true;
|
||||
break;
|
||||
case 5:
|
||||
line += " [vis] " + Float_StrN (act->dval[ii], 0);
|
||||
line += " [vis] " + Float_StrN(act->dval[ii], 0);
|
||||
break;
|
||||
case 9:
|
||||
rotation.z = act->dval[ii];
|
||||
|
@ -934,19 +934,19 @@ void CCharShape::SaveCharNodes (const string& dir, const string& filename) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (rotflag) line += " [rot] " + Vector_StrN (rotation, 2);
|
||||
if (rotflag) line += " [rot] " + Vector_StrN(rotation, 2);
|
||||
}
|
||||
if (!act->mat.empty()) line += " [mat] " + act->mat;
|
||||
if (!node->joint.empty()) line += " [joint] " + node->joint;
|
||||
if (!act->name.empty()) line += " [name] " + act->name;
|
||||
if (node->render_shadow) line += " [shad] 1";
|
||||
|
||||
list.Add (line);
|
||||
list.Add(line);
|
||||
if (i<numNodes-3) {
|
||||
if (node->visible && !Nodes[i+1]->visible) list.AddLine ();
|
||||
if (node->visible && !Nodes[i+1]->visible) list.AddLine();
|
||||
const string& joint = Nodes[i+2]->joint;
|
||||
if (joint.empty()) list.Add ("# " + joint);
|
||||
if (joint.empty()) list.Add("# " + joint);
|
||||
}
|
||||
}
|
||||
list.Save (dir, filename);
|
||||
list.Save(dir, filename);
|
||||
}
|
||||
|
|
84
src/tux.h
84
src/tux.h
|
@ -81,29 +81,29 @@ private:
|
|||
map<string, size_t> MaterialIndex;
|
||||
|
||||
// nodes
|
||||
size_t GetNodeIdx (size_t node_name) const;
|
||||
TCharNode *GetNode (size_t node_name);
|
||||
void CreateRootNode ();
|
||||
size_t GetNodeIdx(size_t node_name) const;
|
||||
TCharNode *GetNode(size_t node_name);
|
||||
void CreateRootNode();
|
||||
bool CreateCharNode
|
||||
(int parent_name, size_t node_name, const string& joint,
|
||||
const string& name, const string& order, bool shadow);
|
||||
bool VisibleNode (size_t node_name, float level);
|
||||
bool MaterialNode (size_t node_name, const string& mat_name);
|
||||
bool VisibleNode(size_t node_name, float level);
|
||||
bool MaterialNode(size_t node_name, const string& mat_name);
|
||||
bool TransformNode(size_t node_name, const TMatrix<4, 4>& mat, const TMatrix<4, 4>& invmat);
|
||||
|
||||
// material
|
||||
TCharMaterial* GetMaterial (const string& mat_name);
|
||||
void CreateMaterial (const string& line);
|
||||
TCharMaterial* GetMaterial(const string& mat_name);
|
||||
void CreateMaterial(const string& line);
|
||||
|
||||
// drawing
|
||||
void DrawCharSphere (int num_divisions);
|
||||
void DrawNodes (const TCharNode *node);
|
||||
TVector3d AdjustRollvector (const CControl *ctrl, const TVector3d& vel, const TVector3d& zvec);
|
||||
void DrawCharSphere(int num_divisions);
|
||||
void DrawNodes(const TCharNode *node);
|
||||
TVector3d AdjustRollvector(const CControl *ctrl, const TVector3d& vel, const TVector3d& zvec);
|
||||
|
||||
// collision
|
||||
bool CheckPolyhedronCollision(const TCharNode *node, const TMatrix<4, 4>& modelMatrix,
|
||||
const TMatrix<4, 4>& invModelMatrix, const TPolyhedron& ph);
|
||||
bool CheckCollision (const TPolyhedron& ph);
|
||||
bool CheckCollision(const TPolyhedron& ph);
|
||||
|
||||
// shadow
|
||||
void DrawShadowVertex(double x, double y, double z, const TMatrix<4, 4>& mat);
|
||||
|
@ -111,52 +111,52 @@ private:
|
|||
void TraverseDagForShadow(const TCharNode *node, const TMatrix<4, 4>& mat);
|
||||
|
||||
// testing and developing
|
||||
void AddAction (size_t node_name, int type, const TVector3d& vec, double val);
|
||||
void AddAction(size_t node_name, int type, const TVector3d& vec, double val);
|
||||
public:
|
||||
CCharShape ();
|
||||
CCharShape();
|
||||
~CCharShape();
|
||||
bool useMaterials;
|
||||
bool useHighlighting;
|
||||
map<string, size_t> NodeIndex;
|
||||
|
||||
// nodes
|
||||
bool ResetNode (size_t node_name);
|
||||
bool ResetNode (const string& node_trivialname);
|
||||
bool TranslateNode (size_t node_name, const TVector3d& vec);
|
||||
bool RotateNode (size_t node_name, int axis, double angle);
|
||||
bool RotateNode (const string& node_trivialname, int axis, double angle);
|
||||
void ScaleNode (size_t node_name, const TVector3d& vec);
|
||||
void ResetRoot () { ResetNode (0); }
|
||||
void ResetJoints ();
|
||||
bool ResetNode(size_t node_name);
|
||||
bool ResetNode(const string& node_trivialname);
|
||||
bool TranslateNode(size_t node_name, const TVector3d& vec);
|
||||
bool RotateNode(size_t node_name, int axis, double angle);
|
||||
bool RotateNode(const string& node_trivialname, int axis, double angle);
|
||||
void ScaleNode(size_t node_name, const TVector3d& vec);
|
||||
void ResetRoot() { ResetNode(0); }
|
||||
void ResetJoints();
|
||||
|
||||
// global functions
|
||||
void Reset ();
|
||||
void Draw ();
|
||||
void DrawShadow ();
|
||||
bool Load (const string& dir, const string& filename, bool with_actions);
|
||||
void Reset();
|
||||
void Draw();
|
||||
void DrawShadow();
|
||||
bool Load(const string& dir, const string& filename, bool with_actions);
|
||||
|
||||
void AdjustOrientation (CControl *ctrl, double dtime,
|
||||
double dist_from_surface, const TVector3d& surf_nml);
|
||||
void AdjustJoints (double turnFact, bool isBraking,
|
||||
double paddling_factor, double speed,
|
||||
const TVector3d& net_force, double flap_factor);
|
||||
bool Collision (const TVector3d& pos, const TPolyhedron& ph);
|
||||
void AdjustOrientation(CControl *ctrl, double dtime,
|
||||
double dist_from_surface, const TVector3d& surf_nml);
|
||||
void AdjustJoints(double turnFact, bool isBraking,
|
||||
double paddling_factor, double speed,
|
||||
const TVector3d& net_force, double flap_factor);
|
||||
bool Collision(const TVector3d& pos, const TPolyhedron& ph);
|
||||
|
||||
// testing and tools
|
||||
bool highlighted;
|
||||
size_t highlight_node;
|
||||
|
||||
size_t GetNodeName (size_t idx) const;
|
||||
size_t GetNodeName (const string& node_trivialname) const;
|
||||
string GetNodeJoint (size_t idx) const;
|
||||
size_t GetNumNodes () const { return numNodes; }
|
||||
const string& GetNodeFullname (size_t idx) const;
|
||||
size_t GetNumActs (size_t idx) const;
|
||||
TCharAction *GetAction (size_t idx) const;
|
||||
void PrintAction (size_t idx) const;
|
||||
void PrintNode (size_t idx) const;
|
||||
void RefreshNode (size_t idx);
|
||||
void SaveCharNodes (const string& dir, const string& filename);
|
||||
size_t GetNodeName(size_t idx) const;
|
||||
size_t GetNodeName(const string& node_trivialname) const;
|
||||
string GetNodeJoint(size_t idx) const;
|
||||
size_t GetNumNodes() const { return numNodes; }
|
||||
const string& GetNodeFullname(size_t idx) const;
|
||||
size_t GetNumActs(size_t idx) const;
|
||||
TCharAction *GetAction(size_t idx) const;
|
||||
void PrintAction(size_t idx) const;
|
||||
void PrintNode(size_t idx) const;
|
||||
void RefreshNode(size_t idx);
|
||||
void SaveCharNodes(const string& dir, const string& filename);
|
||||
};
|
||||
|
||||
// only for char tools, the characters for playing are in
|
||||
|
|
166
src/view.cpp
166
src/view.cpp
|
@ -43,7 +43,7 @@ static TMatrix<4, 4> stationary_matrix;
|
|||
static bool is_stationary = false;
|
||||
static bool shall_stationary = false;
|
||||
|
||||
void SetStationaryCamera (bool stat) {
|
||||
void SetStationaryCamera(bool stat) {
|
||||
if (stat == false) {
|
||||
is_stationary = false;
|
||||
shall_stationary = false;
|
||||
|
@ -53,20 +53,20 @@ void SetStationaryCamera (bool stat) {
|
|||
}
|
||||
|
||||
static double camera_distance = 4.0;
|
||||
void IncCameraDistance (double timestep) {
|
||||
void IncCameraDistance(double timestep) {
|
||||
camera_distance += timestep * CAMERA_DISTANCE_INCREMENT;
|
||||
}
|
||||
|
||||
void SetCameraDistance (double val) {camera_distance = val;}
|
||||
void SetCameraDistance(double val) {camera_distance = val;}
|
||||
|
||||
|
||||
void set_view_mode (CControl *ctrl, TViewMode mode) {ctrl->viewmode = mode;}
|
||||
void set_view_mode(CControl *ctrl, TViewMode mode) {ctrl->viewmode = mode;}
|
||||
|
||||
TVector3d interpolate_view_pos (const TVector3d& ctrl_pos1, const TVector3d& ctrl_pos2,
|
||||
double max_vec_angle,
|
||||
const TVector3d& pos1, const TVector3d& pos2,
|
||||
double dist, double dt,
|
||||
double time_constant) {
|
||||
TVector3d interpolate_view_pos(const TVector3d& ctrl_pos1, const TVector3d& ctrl_pos2,
|
||||
double max_vec_angle,
|
||||
const TVector3d& pos1, const TVector3d& pos2,
|
||||
double dist, double dt,
|
||||
double time_constant) {
|
||||
static TVector3d y_vec(0.0, 1.0, 0.0);
|
||||
|
||||
TVector3d vec1 = pos1 - ctrl_pos1;
|
||||
|
@ -75,43 +75,43 @@ TVector3d interpolate_view_pos (const TVector3d& ctrl_pos1, const TVector3d& ctr
|
|||
vec1.Norm();
|
||||
vec2.Norm();
|
||||
|
||||
TQuaternion q1 = MakeRotationQuaternion (y_vec, vec1);
|
||||
TQuaternion q2 = MakeRotationQuaternion (y_vec, vec2);
|
||||
double alpha = min (MAX_INTERPOLATION_VALUE, 1.0 - exp (-dt / time_constant));
|
||||
q2 = InterpolateQuaternions (q1, q2, alpha);
|
||||
TQuaternion q1 = MakeRotationQuaternion(y_vec, vec1);
|
||||
TQuaternion q2 = MakeRotationQuaternion(y_vec, vec2);
|
||||
double alpha = min(MAX_INTERPOLATION_VALUE, 1.0 - exp(-dt / time_constant));
|
||||
q2 = InterpolateQuaternions(q1, q2, alpha);
|
||||
|
||||
vec2 = RotateVector (q2, y_vec);
|
||||
double theta = RADIANS_TO_ANGLES (M_PI/2 - acos (DotProduct (vec2, y_vec)));
|
||||
vec2 = RotateVector(q2, y_vec);
|
||||
double theta = RADIANS_TO_ANGLES(M_PI/2 - acos(DotProduct(vec2, y_vec)));
|
||||
if (theta > max_vec_angle) {
|
||||
TVector3d axis = CrossProduct (y_vec, vec2);
|
||||
TVector3d axis = CrossProduct(y_vec, vec2);
|
||||
axis.Norm();
|
||||
TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix(axis, theta - max_vec_angle);
|
||||
vec2 = TransformVector (rot_mat, vec2);
|
||||
vec2 = TransformVector(rot_mat, vec2);
|
||||
}
|
||||
return ctrl_pos2 + dist * vec2;
|
||||
}
|
||||
|
||||
void interpolate_view_frame (const TVector3d& up1, const TVector3d& dir1,
|
||||
TVector3d *p_up2, TVector3d *p_dir2,
|
||||
double dt, double time_constant) {
|
||||
void interpolate_view_frame(const TVector3d& up1, const TVector3d& dir1,
|
||||
TVector3d *p_up2, TVector3d *p_dir2,
|
||||
double dt, double time_constant) {
|
||||
TVector3d z1 = -1.0 * dir1;
|
||||
z1.Norm();
|
||||
TVector3d y1 = ProjectToPlane (z1, up1);
|
||||
TVector3d y1 = ProjectToPlane(z1, up1);
|
||||
y1.Norm();
|
||||
TVector3d x1 = CrossProduct (y1, z1);
|
||||
TVector3d x1 = CrossProduct(y1, z1);
|
||||
TMatrix<4, 4> cob_mat1(x1, y1, z1);
|
||||
TQuaternion q1 = MakeQuaternionFromMatrix (cob_mat1);
|
||||
TQuaternion q1 = MakeQuaternionFromMatrix(cob_mat1);
|
||||
|
||||
TVector3d z2 = -1.0 * *p_dir2;
|
||||
z2.Norm();
|
||||
TVector3d y2 = ProjectToPlane (z2, *p_up2);
|
||||
TVector3d y2 = ProjectToPlane(z2, *p_up2);
|
||||
y2.Norm();
|
||||
TVector3d x2 = CrossProduct (y2, z2);
|
||||
TVector3d x2 = CrossProduct(y2, z2);
|
||||
TMatrix<4, 4> cob_mat2(x2, y2, z2);
|
||||
TQuaternion q2 = MakeQuaternionFromMatrix (cob_mat2);
|
||||
TQuaternion q2 = MakeQuaternionFromMatrix(cob_mat2);
|
||||
|
||||
double alpha = min (MAX_INTERPOLATION_VALUE, 1.0 - exp (-dt / time_constant));
|
||||
q2 = InterpolateQuaternions (q1, q2, alpha);
|
||||
double alpha = min(MAX_INTERPOLATION_VALUE, 1.0 - exp(-dt / time_constant));
|
||||
q2 = InterpolateQuaternions(q1, q2, alpha);
|
||||
cob_mat2 = MakeMatrixFromQuaternion(q2);
|
||||
|
||||
p_up2->x = cob_mat2[1][0];
|
||||
|
@ -123,10 +123,10 @@ void interpolate_view_frame (const TVector3d& up1, const TVector3d& dir1,
|
|||
p_dir2->z = -cob_mat2[2][2];
|
||||
}
|
||||
|
||||
void setup_view_matrix (CControl *ctrl, bool save_mat) {
|
||||
void setup_view_matrix(CControl *ctrl, bool save_mat) {
|
||||
TVector3d view_z = -1.0 * ctrl->viewdir;
|
||||
TVector3d view_x = CrossProduct (ctrl->viewup, view_z);
|
||||
TVector3d view_y = CrossProduct (view_z, view_x);
|
||||
TVector3d view_x = CrossProduct(ctrl->viewup, view_z);
|
||||
TVector3d view_y = CrossProduct(view_z, view_x);
|
||||
view_z.Norm();
|
||||
view_x.Norm();
|
||||
view_y.Norm();
|
||||
|
@ -143,7 +143,7 @@ void setup_view_matrix (CControl *ctrl, bool save_mat) {
|
|||
view_mat[1][3] = 0;
|
||||
view_mat[2][3] = 0;
|
||||
|
||||
TVector3d viewpt_in_view_frame = TransformPoint (view_mat, ctrl->viewpos);
|
||||
TVector3d viewpt_in_view_frame = TransformPoint(view_mat, ctrl->viewpos);
|
||||
|
||||
view_mat[3][0] = -viewpt_in_view_frame.x;
|
||||
view_mat[3][1] = -viewpt_in_view_frame.y;
|
||||
|
@ -155,9 +155,9 @@ void setup_view_matrix (CControl *ctrl, bool save_mat) {
|
|||
glLoadMatrix(view_mat);
|
||||
}
|
||||
|
||||
TVector3d MakeViewVector () {
|
||||
TVector3d MakeViewVector() {
|
||||
double course_angle = Course.GetCourseAngle();
|
||||
double rad = ANGLES_TO_RADIANS (
|
||||
double rad = ANGLES_TO_RADIANS(
|
||||
course_angle -
|
||||
CAMERA_ANGLE_ABOVE_SLOPE +
|
||||
PLAYER_ANGLE_IN_CAMERA);
|
||||
|
@ -165,7 +165,7 @@ TVector3d MakeViewVector () {
|
|||
return camera_distance * res;
|
||||
}
|
||||
|
||||
void update_view (CControl *ctrl, double dt) {
|
||||
void update_view(CControl *ctrl, double dt) {
|
||||
if (is_stationary) {
|
||||
glLoadMatrix(stationary_matrix);
|
||||
return;
|
||||
|
@ -179,9 +179,9 @@ void update_view (CControl *ctrl, double dt) {
|
|||
|
||||
double speed = ctrl->cvel.Length();
|
||||
double time_constant_mult = 1.0 /
|
||||
clamp (0.0,
|
||||
(speed - NO_INTERPOLATION_SPEED) / (BASELINE_INTERPOLATION_SPEED - NO_INTERPOLATION_SPEED),
|
||||
1.0);
|
||||
clamp(0.0,
|
||||
(speed - NO_INTERPOLATION_SPEED) / (BASELINE_INTERPOLATION_SPEED - NO_INTERPOLATION_SPEED),
|
||||
1.0);
|
||||
|
||||
TVector3d vel_dir = ctrl->cvel;
|
||||
vel_dir.Norm();
|
||||
|
@ -190,12 +190,12 @@ void update_view (CControl *ctrl, double dt) {
|
|||
|
||||
switch (ctrl->viewmode) {
|
||||
case BEHIND: {
|
||||
TVector3d vel_proj = ProjectToPlane (y_vec, vel_dir);
|
||||
TVector3d vel_proj = ProjectToPlane(y_vec, vel_dir);
|
||||
vel_proj.Norm();
|
||||
TQuaternion rot_quat = MakeRotationQuaternion (mz_vec, vel_proj);
|
||||
view_vec = RotateVector (rot_quat, view_vec);
|
||||
TQuaternion rot_quat = MakeRotationQuaternion(mz_vec, vel_proj);
|
||||
view_vec = RotateVector(rot_quat, view_vec);
|
||||
view_pt = ctrl->cpos + view_vec;
|
||||
double ycoord = Course.FindYCoord (view_pt.x, view_pt.z);
|
||||
double ycoord = Course.FindYCoord(view_pt.x, view_pt.z);
|
||||
|
||||
if (view_pt.y < ycoord + MIN_CAMERA_HEIGHT) {
|
||||
view_pt.y = ycoord + MIN_CAMERA_HEIGHT;
|
||||
|
@ -203,73 +203,73 @@ void update_view (CControl *ctrl, double dt) {
|
|||
|
||||
if (ctrl->view_init) {
|
||||
for (int i=0; i<2; i++) {
|
||||
view_pt = interpolate_view_pos (ctrl->cpos, ctrl->cpos,
|
||||
MAX_CAMERA_PITCH, ctrl->viewpos,
|
||||
view_pt, camera_distance, dt,
|
||||
BEHIND_ORBIT_TIME_CONSTANT *
|
||||
time_constant_mult);
|
||||
view_pt = interpolate_view_pos(ctrl->cpos, ctrl->cpos,
|
||||
MAX_CAMERA_PITCH, ctrl->viewpos,
|
||||
view_pt, camera_distance, dt,
|
||||
BEHIND_ORBIT_TIME_CONSTANT *
|
||||
time_constant_mult);
|
||||
}
|
||||
}
|
||||
|
||||
ycoord = Course.FindYCoord (view_pt.x, view_pt.z);
|
||||
ycoord = Course.FindYCoord(view_pt.x, view_pt.z);
|
||||
if (view_pt.y < ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT) {
|
||||
view_pt.y = ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT;
|
||||
}
|
||||
|
||||
view_vec = view_pt - ctrl->cpos;
|
||||
TVector3d axis = CrossProduct (y_vec, view_vec);
|
||||
TVector3d axis = CrossProduct(y_vec, view_vec);
|
||||
axis.Norm();
|
||||
TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix(axis, PLAYER_ANGLE_IN_CAMERA);
|
||||
view_dir = -1.0 * TransformVector (rot_mat, view_vec);
|
||||
view_dir = -1.0 * TransformVector(rot_mat, view_vec);
|
||||
|
||||
if (ctrl->view_init) {
|
||||
for (int i=0; i<2; i++) {
|
||||
TVector3d up_dir(0, 1, 0);
|
||||
interpolate_view_frame (ctrl->viewup, ctrl->viewdir,
|
||||
&up_dir, &view_dir, dt,
|
||||
BEHIND_ORIENT_TIME_CONSTANT);
|
||||
interpolate_view_frame(ctrl->viewup, ctrl->viewdir,
|
||||
&up_dir, &view_dir, dt,
|
||||
BEHIND_ORIENT_TIME_CONSTANT);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case FOLLOW: { // normale Einstellung
|
||||
TVector3d vel_proj = ProjectToPlane (y_vec, vel_dir);
|
||||
TVector3d vel_proj = ProjectToPlane(y_vec, vel_dir);
|
||||
vel_proj.Norm();
|
||||
TQuaternion rot_quat = MakeRotationQuaternion (mz_vec, vel_proj);
|
||||
view_vec = RotateVector (rot_quat, view_vec);
|
||||
TQuaternion rot_quat = MakeRotationQuaternion(mz_vec, vel_proj);
|
||||
view_vec = RotateVector(rot_quat, view_vec);
|
||||
view_pt = ctrl->cpos + view_vec;
|
||||
double ycoord = Course.FindYCoord (view_pt.x, view_pt.z);
|
||||
double ycoord = Course.FindYCoord(view_pt.x, view_pt.z);
|
||||
if (view_pt.y < ycoord + MIN_CAMERA_HEIGHT) {
|
||||
view_pt.y = ycoord + MIN_CAMERA_HEIGHT;
|
||||
}
|
||||
|
||||
if (ctrl->view_init) {
|
||||
for (int i=0; i<2; i++) {
|
||||
view_pt = interpolate_view_pos (ctrl->plyr_pos, ctrl->cpos,
|
||||
MAX_CAMERA_PITCH, ctrl->viewpos,
|
||||
view_pt, camera_distance, dt,
|
||||
FOLLOW_ORBIT_TIME_CONSTANT *
|
||||
time_constant_mult);
|
||||
view_pt = interpolate_view_pos(ctrl->plyr_pos, ctrl->cpos,
|
||||
MAX_CAMERA_PITCH, ctrl->viewpos,
|
||||
view_pt, camera_distance, dt,
|
||||
FOLLOW_ORBIT_TIME_CONSTANT *
|
||||
time_constant_mult);
|
||||
}
|
||||
}
|
||||
ycoord = Course.FindYCoord (view_pt.x, view_pt.z);
|
||||
ycoord = Course.FindYCoord(view_pt.x, view_pt.z);
|
||||
if (view_pt.y < ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT) {
|
||||
view_pt.y = ycoord + ABSOLUTE_MIN_CAMERA_HEIGHT;
|
||||
}
|
||||
|
||||
view_vec = view_pt - ctrl->cpos;
|
||||
TVector3d axis = CrossProduct (y_vec, view_vec);
|
||||
TVector3d axis = CrossProduct(y_vec, view_vec);
|
||||
axis.Norm();
|
||||
TMatrix<4, 4> rot_mat = RotateAboutVectorMatrix(axis, PLAYER_ANGLE_IN_CAMERA);
|
||||
view_dir = -1.0 * TransformVector (rot_mat, view_vec);
|
||||
view_dir = -1.0 * TransformVector(rot_mat, view_vec);
|
||||
|
||||
if (ctrl->view_init) {
|
||||
for (int i=0; i<2; i++) {
|
||||
TVector3d up_dir(0, 1, 0);
|
||||
interpolate_view_frame (ctrl->viewup, ctrl->viewdir,
|
||||
&up_dir, &view_dir, dt,
|
||||
FOLLOW_ORIENT_TIME_CONSTANT);
|
||||
interpolate_view_frame(ctrl->viewup, ctrl->viewdir,
|
||||
&up_dir, &view_dir, dt,
|
||||
FOLLOW_ORIENT_TIME_CONSTANT);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -277,7 +277,7 @@ void update_view (CControl *ctrl, double dt) {
|
|||
|
||||
case ABOVE: {
|
||||
view_pt = ctrl->cpos + view_vec;
|
||||
double ycoord = Course.FindYCoord (view_pt.x, view_pt.z);
|
||||
double ycoord = Course.FindYCoord(view_pt.x, view_pt.z);
|
||||
if (view_pt.y < ycoord + MIN_CAMERA_HEIGHT) {
|
||||
view_pt.y = ycoord + MIN_CAMERA_HEIGHT;
|
||||
}
|
||||
|
@ -285,12 +285,12 @@ void update_view (CControl *ctrl, double dt) {
|
|||
view_vec = view_pt - ctrl->cpos;
|
||||
TMatrix<4, 4> rot_mat;
|
||||
rot_mat.SetRotationMatrix(PLAYER_ANGLE_IN_CAMERA, 'x');
|
||||
view_dir = -1.0 * TransformVector (rot_mat, view_vec);
|
||||
view_dir = -1.0 * TransformVector(rot_mat, view_vec);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
Message ("code not reached");
|
||||
Message("code not reached");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -302,10 +302,10 @@ void update_view (CControl *ctrl, double dt) {
|
|||
ctrl->view_init = true;
|
||||
|
||||
if (shall_stationary) {
|
||||
setup_view_matrix (ctrl, true);
|
||||
setup_view_matrix(ctrl, true);
|
||||
is_stationary = true;
|
||||
} else {
|
||||
setup_view_matrix (ctrl, false);
|
||||
setup_view_matrix(ctrl, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -318,14 +318,14 @@ static TPlane frustum_planes[6];
|
|||
static char p_vertex_code[6];
|
||||
|
||||
|
||||
void SetupViewFrustum (const CControl *ctrl) {
|
||||
void SetupViewFrustum(const CControl *ctrl) {
|
||||
double aspect = (double) Winsys.resolution.width /Winsys.resolution.height;
|
||||
|
||||
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);
|
||||
double half_fov = ANGLES_TO_RADIANS(param.fov * 0.5);
|
||||
double half_fov_horiz = atan(tan(half_fov) * aspect);
|
||||
|
||||
frustum_planes[0] = TPlane(0, 0, 1, near_dist);
|
||||
frustum_planes[1] = TPlane(0, 0, -1, -far_dist);
|
||||
|
@ -339,13 +339,13 @@ void SetupViewFrustum (const CControl *ctrl) {
|
|||
= TPlane(0, -cos(half_fov), sin(half_fov), 0);
|
||||
|
||||
for (int i=0; i<6; i++) {
|
||||
TVector3d pt = TransformPoint (ctrl->view_mat,
|
||||
origin + -frustum_planes[i].d * frustum_planes[i].nml);
|
||||
TVector3d pt = TransformPoint(ctrl->view_mat,
|
||||
origin + -frustum_planes[i].d * frustum_planes[i].nml);
|
||||
|
||||
frustum_planes[i].nml = TransformVector (
|
||||
frustum_planes[i].nml = TransformVector(
|
||||
ctrl->view_mat, frustum_planes[i].nml);
|
||||
|
||||
frustum_planes[i].d = -DotProduct (
|
||||
frustum_planes[i].d = -DotProduct(
|
||||
frustum_planes[i].nml,
|
||||
pt - origin);
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ void SetupViewFrustum (const CControl *ctrl) {
|
|||
}
|
||||
}
|
||||
|
||||
clip_result_t clip_aabb_to_view_frustum (const TVector3d& min, const TVector3d& max) {
|
||||
clip_result_t clip_aabb_to_view_frustum(const TVector3d& min, const TVector3d& max) {
|
||||
bool intersect = false;
|
||||
|
||||
for (int i=0; i<6; i++) {
|
||||
|
@ -381,11 +381,11 @@ clip_result_t clip_aabb_to_view_frustum (const TVector3d& min, const TVector3d&
|
|||
n.z = min.z;
|
||||
}
|
||||
|
||||
if (DotProduct (n, frustum_planes[i].nml) + frustum_planes[i].d > 0) {
|
||||
if (DotProduct(n, frustum_planes[i].nml) + frustum_planes[i].d > 0) {
|
||||
return NotVisible;
|
||||
}
|
||||
|
||||
if (DotProduct (p, frustum_planes[i].nml) + frustum_planes[i].d > 0) {
|
||||
if (DotProduct(p, frustum_planes[i].nml) + frustum_planes[i].d > 0) {
|
||||
intersect = true;
|
||||
}
|
||||
}
|
||||
|
|
14
src/view.h
14
src/view.h
|
@ -21,12 +21,12 @@ GNU General Public License for more details.
|
|||
#include "bh.h"
|
||||
#include "mathlib.h"
|
||||
|
||||
void set_view_mode (CControl *ctrl, TViewMode mode);
|
||||
void update_view (CControl *ctrl, double dt);
|
||||
void set_view_mode(CControl *ctrl, TViewMode mode);
|
||||
void update_view(CControl *ctrl, double dt);
|
||||
|
||||
void SetStationaryCamera (bool stat); // 0 follow, 1 stationary
|
||||
void IncCameraDistance (double timestep);
|
||||
void SetCameraDistance (double val);
|
||||
void SetStationaryCamera(bool stat); // 0 follow, 1 stationary
|
||||
void IncCameraDistance(double timestep);
|
||||
void SetCameraDistance(double val);
|
||||
|
||||
// ------------- viewfrustum ------------------------------------------
|
||||
|
||||
|
@ -36,8 +36,8 @@ enum clip_result_t {
|
|||
NotVisible
|
||||
};
|
||||
|
||||
void SetupViewFrustum (const CControl *ctrl);
|
||||
clip_result_t clip_aabb_to_view_frustum (const TVector3d& min, const TVector3d& max);
|
||||
void SetupViewFrustum(const CControl *ctrl);
|
||||
clip_result_t clip_aabb_to_view_frustum(const TVector3d& min, const TVector3d& max);
|
||||
|
||||
const TPlane& get_far_clip_plane();
|
||||
const TPlane& get_left_clip_plane();
|
||||
|
|
|
@ -31,7 +31,7 @@ TVector2i cursor_pos(0, 0);
|
|||
|
||||
CWinsys Winsys;
|
||||
|
||||
CWinsys::CWinsys ()
|
||||
CWinsys::CWinsys()
|
||||
: sfmlRenders(false)
|
||||
, auto_resolution(800, 600) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
|
@ -54,26 +54,26 @@ CWinsys::CWinsys ()
|
|||
resolutions[9] = TScreenRes(1680, 1050);
|
||||
}
|
||||
|
||||
const TScreenRes& CWinsys::GetResolution (size_t idx) const {
|
||||
const TScreenRes& CWinsys::GetResolution(size_t idx) const {
|
||||
if (idx >= NUM_RESOLUTIONS || (idx == 0 && !param.fullscreen)) return auto_resolution;
|
||||
return resolutions[idx];
|
||||
}
|
||||
|
||||
string CWinsys::GetResName (size_t idx) const {
|
||||
string CWinsys::GetResName(size_t idx) const {
|
||||
if (idx >= NUM_RESOLUTIONS) return "800 x 600";
|
||||
if (idx == 0) return ("auto");
|
||||
string line = Int_StrN (resolutions[idx].width);
|
||||
line += " x " + Int_StrN (resolutions[idx].height);
|
||||
string line = Int_StrN(resolutions[idx].width);
|
||||
line += " x " + Int_StrN(resolutions[idx].height);
|
||||
return line;
|
||||
}
|
||||
|
||||
double CWinsys::CalcScreenScale () const {
|
||||
double CWinsys::CalcScreenScale() const {
|
||||
if (resolution.height < 768) return 0.78;
|
||||
else if (resolution.height == 768) return 1.0;
|
||||
else return (resolution.height / 768);
|
||||
}
|
||||
|
||||
void CWinsys::SetupVideoMode (const TScreenRes& resolution_) {
|
||||
void CWinsys::SetupVideoMode(const TScreenRes& resolution_) {
|
||||
int bpp = 32;
|
||||
switch (param.bpp_mode) {
|
||||
case 16:
|
||||
|
@ -103,41 +103,41 @@ void CWinsys::SetupVideoMode (const TScreenRes& resolution_) {
|
|||
if (param.framerate)
|
||||
window.setFramerateLimit(param.framerate);
|
||||
|
||||
scale = CalcScreenScale ();
|
||||
if (param.use_quad_scale) scale = sqrt (scale);
|
||||
scale = CalcScreenScale();
|
||||
if (param.use_quad_scale) scale = sqrt(scale);
|
||||
}
|
||||
|
||||
void CWinsys::SetupVideoMode (size_t idx) {
|
||||
SetupVideoMode (GetResolution(idx));
|
||||
void CWinsys::SetupVideoMode(size_t idx) {
|
||||
SetupVideoMode(GetResolution(idx));
|
||||
}
|
||||
|
||||
void CWinsys::SetupVideoMode (int width, int height) {
|
||||
SetupVideoMode (TScreenRes(width, height));
|
||||
void CWinsys::SetupVideoMode(int width, int height) {
|
||||
SetupVideoMode(TScreenRes(width, height));
|
||||
}
|
||||
|
||||
void CWinsys::Init () {
|
||||
void CWinsys::Init() {
|
||||
SetupVideoMode(GetResolution(param.res_type));
|
||||
|
||||
KeyRepeat (false);
|
||||
KeyRepeat(false);
|
||||
}
|
||||
|
||||
void CWinsys::KeyRepeat (bool repeat) {
|
||||
void CWinsys::KeyRepeat(bool repeat) {
|
||||
window.setKeyRepeatEnabled(repeat);
|
||||
}
|
||||
|
||||
void CWinsys::Quit () {
|
||||
Score.SaveHighScore ();
|
||||
SaveMessages ();
|
||||
if (g_game.argument < 1) Players.SavePlayers ();
|
||||
void CWinsys::Quit() {
|
||||
Score.SaveHighScore();
|
||||
SaveMessages();
|
||||
if (g_game.argument < 1) Players.SavePlayers();
|
||||
window.close();
|
||||
}
|
||||
|
||||
void CWinsys::Terminate () {
|
||||
void CWinsys::Terminate() {
|
||||
Quit();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void CWinsys::PrintJoystickInfo () const {
|
||||
void CWinsys::PrintJoystickInfo() const {
|
||||
if (numJoysticks == 0) {
|
||||
cout << "No joystick found\n";
|
||||
return;
|
||||
|
|
22
src/winsys.h
22
src/winsys.h
|
@ -44,21 +44,21 @@ public:
|
|||
TScreenRes resolution;
|
||||
double scale; // scale factor for screen, see 'use_quad_scale'
|
||||
|
||||
CWinsys ();
|
||||
CWinsys();
|
||||
|
||||
// sdl window
|
||||
const TScreenRes& GetResolution (size_t idx) const;
|
||||
string GetResName (size_t idx) const;
|
||||
void Init ();
|
||||
void SetupVideoMode (const TScreenRes& resolution);
|
||||
void SetupVideoMode (size_t idx);
|
||||
void SetupVideoMode (int width, int height);
|
||||
void KeyRepeat (bool repeat);
|
||||
void PrintJoystickInfo () const;
|
||||
const TScreenRes& GetResolution(size_t idx) const;
|
||||
string GetResName(size_t idx) const;
|
||||
void Init();
|
||||
void SetupVideoMode(const TScreenRes& resolution);
|
||||
void SetupVideoMode(size_t idx);
|
||||
void SetupVideoMode(int width, int height);
|
||||
void KeyRepeat(bool repeat);
|
||||
void PrintJoystickInfo() const;
|
||||
void ShowCursor(bool visible) { window.setMouseCursorVisible(visible); }
|
||||
void SwapBuffers() { window.display(); }
|
||||
void Quit ();
|
||||
void Terminate ();
|
||||
void Quit();
|
||||
void Terminate();
|
||||
bool joystick_isActive() const { return joystick_active; }
|
||||
void draw(const sf::Drawable& drawable, const sf::RenderStates& states = sf::RenderStates::Default) { window.draw(drawable, states); }
|
||||
void clear() { window.clear(colBackgr); }
|
||||
|
|
Loading…
Reference in New Issue