diff --git a/src/explosion.cpp b/src/explosion.cpp index 60b098dd0..420771bac 100644 --- a/src/explosion.cpp +++ b/src/explosion.cpp @@ -56,7 +56,7 @@ void Explosion::init(const Vec3& coord) c.hpr[0]=0; c.hpr[1]=0; c.hpr[2]=0; setTransform(&c); m_step = -1; - scene->add(this); + stk_scene->add(this); m_has_ended = false; } @@ -70,7 +70,7 @@ void Explosion::update(float dt) if(m_explode_sound->getStatus() != SFXManager::SFX_PLAYING) { //fprintf(stderr, "Sound finished. Removing.\n"); - scene->remove((ssgTransform*)this); + stk_scene->remove((ssgTransform*)this); projectile_manager->FinishedExplosion(); m_has_ended = true; return; diff --git a/src/graphics/particle_system.cpp b/src/graphics/particle_system.cpp index 9eeee8a56..aecacac87 100644 --- a/src/graphics/particle_system.cpp +++ b/src/graphics/particle_system.cpp @@ -69,7 +69,7 @@ ParticleSystem::ParticleSystem ( int num, float create_rate, int ttf, float sz) } m_num_active = 0 ; - scene->add(this); + stk_scene->add(this); } // ParticleSystem //----------------------------------------------------------------------------- diff --git a/src/graphics/scene.cpp b/src/graphics/scene.cpp index b5235842b..f76757da7 100644 --- a/src/graphics/scene.cpp +++ b/src/graphics/scene.cpp @@ -36,7 +36,7 @@ #include "scene.hpp" -Scene *scene = 0; +Scene *stk_scene = 0; Scene::Scene() : m_scenegraph(new ssgRoot) { diff --git a/src/graphics/scene.hpp b/src/graphics/scene.hpp index 8e5ce8c02..47cc145f7 100644 --- a/src/graphics/scene.hpp +++ b/src/graphics/scene.hpp @@ -16,8 +16,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HEADER_SCENE_H -#define HEADER_SCENE_H +#ifndef HEADER_SCENE_HPP +#define HEADER_SCENE_HPP //FIXME: make the camera a pointer to vector so it can be forward declared. #include @@ -48,6 +48,6 @@ public: Camera *createCamera(int playerId, const Kart* kart); }; -extern Scene *scene; +extern Scene *stk_scene; #endif diff --git a/src/graphics/skid_marks.cpp b/src/graphics/skid_marks.cpp index 1007c21e4..d32550781 100644 --- a/src/graphics/skid_marks.cpp +++ b/src/graphics/skid_marks.cpp @@ -55,8 +55,8 @@ void SkidMarks::reset() { for(unsigned int i=0; iremove(m_left[i]); - scene->remove(m_right[i]); + stk_scene->remove(m_left[i]); + stk_scene->remove(m_right[i]); } m_left.clear(); m_right.clear(); @@ -152,7 +152,7 @@ void SkidMarks::update(float dt) SkidMarkQuads *smq_left = new SkidMarkQuads(raycast_left.m_contactPointWS, raycast_left.m_contactPointWS + delta, m_skid_state, m_avoid_z_fighting); - scene->add(smq_left); + stk_scene->add(smq_left); m_avoid_z_fighting += 0.001f; if(m_avoid_z_fighting>0.01f) m_avoid_z_fighting = 0.0f; @@ -161,7 +161,7 @@ void SkidMarks::update(float dt) raycast_right.m_contactPointWS, m_skid_state, m_avoid_z_fighting); - scene->add(smq_right); + stk_scene->add(smq_right); m_current++; if(m_current>=stk_config->m_max_skidmarks) m_current = 0; @@ -172,8 +172,8 @@ void SkidMarks::update(float dt) } else { - scene->remove(m_left [m_current]); - scene->remove(m_right[m_current]); + stk_scene->remove(m_left [m_current]); + stk_scene->remove(m_right[m_current]); m_left [m_current] = smq_left; m_right[m_current] = smq_right; } diff --git a/src/gui/grand_prix_ending.cpp b/src/gui/grand_prix_ending.cpp index 60ab8d8ed..2a03b47bc 100644 --- a/src/gui/grand_prix_ending.cpp +++ b/src/gui/grand_prix_ending.cpp @@ -151,7 +151,7 @@ GrandPrixEnd::GrandPrixEnd() //FIXME: this is taken from RaceMode::exit_race, //this should be organized better. - scene->clear(); + stk_scene->clear(); RaceManager::setWorld(NULL); race_manager->m_active_race = false; diff --git a/src/gui/race_options.cpp b/src/gui/race_options.cpp index 8e631ba61..0ea42b13c 100644 --- a/src/gui/race_options.cpp +++ b/src/gui/race_options.cpp @@ -17,6 +17,8 @@ #include "gui/race_options.hpp" +#include + #include "race_manager.hpp" #include "user_config.hpp" #include "material_manager.hpp" @@ -24,10 +26,6 @@ #include "gui/widget_manager.hpp" #include "utils/translation.hpp" -#if defined(WIN32) && !defined(__CYGWIN__) -# define snprintf _snprintf -#endif - enum WidgetTokens { WTOK_TITLE, @@ -102,9 +100,9 @@ RaceOptions::RaceOptions() widget_manager->setWgtTextSize(WTOK_KARTS_TITLE, WGT_FNT_LRG); widget_manager->addTextButtonWgt( WTOK_KARTS_DOWN, 3, 7, " < " ); - char string_num_karts[MAX_MESSAGE_LENGTH]; - snprintf(string_num_karts, MAX_MESSAGE_LENGTH, "%d", m_num_karts); - widget_manager->addTextWgt( WTOK_KARTS, ITEM_WIDTH, 7, string_num_karts ); + std::ostringstream string_num_karts; + string_num_karts << m_num_karts; + widget_manager->addTextWgt( WTOK_KARTS, ITEM_WIDTH, 7, string_num_karts.str() ); widget_manager->setWgtBorderPercentage( WTOK_KARTS, 10 ); widget_manager->showWgtBorder( WTOK_KARTS ); widget_manager->hideWgtRect( WTOK_KARTS ); @@ -124,9 +122,9 @@ RaceOptions::RaceOptions() widget_manager->setWgtTextSize(WTOK_LAPS_TITLE, WGT_FNT_LRG); widget_manager->addTextButtonWgt( WTOK_LAPS_DOWN, 3, 7, " < " ); - char string_num_laps[MAX_MESSAGE_LENGTH]; - snprintf(string_num_laps, MAX_MESSAGE_LENGTH, "%d", m_num_laps); - widget_manager->addTextWgt( WTOK_LAPS, ITEM_WIDTH, 7, string_num_laps ); + std::ostringstream string_num_laps; + string_num_laps << m_num_laps; + widget_manager->addTextWgt( WTOK_LAPS, ITEM_WIDTH, 7, string_num_laps.str() ); widget_manager->setWgtBorderPercentage( WTOK_LAPS, 10 ); widget_manager->showWgtBorder( WTOK_LAPS ); widget_manager->hideWgtRect( WTOK_LAPS ); @@ -191,7 +189,7 @@ void RaceOptions::select() { m_difficulty = RaceManager::RD_MEDIUM; } - widget_manager->setWgtText( WTOK_DIFFICULTY, getDifficultyString(m_difficulty) ); + widget_manager->setWgtText(WTOK_DIFFICULTY, getDifficultyString(m_difficulty) ); break; case WTOK_DIFFICULTY_DOWN: @@ -207,20 +205,19 @@ void RaceOptions::select() { m_difficulty = RaceManager::RD_HARD; } - widget_manager->setWgtText( WTOK_DIFFICULTY, - getDifficultyString(m_difficulty) ); + widget_manager->setWgtText(WTOK_DIFFICULTY, + getDifficultyString(m_difficulty) ); break; case WTOK_KARTS_UP: { - m_num_karts = m_num_karts==stk_config->m_max_karts + m_num_karts = m_num_karts==stk_config->m_max_karts ? m_min_karts : m_num_karts + 1; - char label[ MAX_MESSAGE_LENGTH ]; - snprintf( label, MAX_MESSAGE_LENGTH, "%d", m_num_karts ); - - widget_manager->setWgtText( WTOK_KARTS, label ); + std::ostringstream label; + label << m_num_karts; + widget_manager->setWgtText(WTOK_KARTS, label.str() ); } break; @@ -228,10 +225,9 @@ void RaceOptions::select() { m_num_karts = m_num_karts==m_min_karts ? stk_config->m_max_karts : m_num_karts-1; - char label[ MAX_MESSAGE_LENGTH ]; - snprintf( label, MAX_MESSAGE_LENGTH, "%d", m_num_karts ); - - widget_manager->setWgtText( WTOK_KARTS, label ); + std::ostringstream label; + label << m_num_karts; + widget_manager->setWgtText(WTOK_KARTS, label.str() ); } break; @@ -240,10 +236,9 @@ void RaceOptions::select() m_num_laps++; if(m_num_laps>10) m_num_laps=1; - char label[ MAX_MESSAGE_LENGTH ]; - snprintf( label, MAX_MESSAGE_LENGTH, "%d", m_num_laps ); - - widget_manager->setWgtText( WTOK_LAPS, label); + std::ostringstream label; + label << m_num_laps; + widget_manager->setWgtText(WTOK_LAPS, label.str()); } break; @@ -252,10 +247,9 @@ void RaceOptions::select() m_num_laps--; if(m_num_laps<1) m_num_laps=10; - char label[ MAX_MESSAGE_LENGTH ]; - snprintf( label, MAX_MESSAGE_LENGTH, "%d", m_num_laps ); - - widget_manager->setWgtText( WTOK_LAPS, label); + std::ostringstream label; + label << m_num_laps; + widget_manager->setWgtText(WTOK_LAPS, label.str()); } break; diff --git a/src/highscore_manager.cpp b/src/highscore_manager.cpp index 8111868e3..bd3987e26 100644 --- a/src/highscore_manager.cpp +++ b/src/highscore_manager.cpp @@ -20,9 +20,7 @@ #include "highscore_manager.hpp" #include -#if defined(WIN32) && !defined(__CYGWIN__) -# define snprintf _snprintf -#endif +#include #include "race_manager.hpp" #include "file_manager.hpp" @@ -98,9 +96,7 @@ void HighscoreManager::Load() const lisp::Lisp* const node = root->getLisp("highscores"); if(!node) { - char msg[MAX_ERROR_MESSAGE_LENGTH]; - snprintf(msg, sizeof(msg), "No 'highscore' node found."); - throw std::runtime_error(msg); + throw std::runtime_error("No 'highscore' node found."); } // check file version @@ -121,23 +117,21 @@ void HighscoreManager::Load() int n; if (!node->get("number-entries",n)) { - char msg[MAX_ERROR_MESSAGE_LENGTH]; - snprintf(msg, sizeof(msg), "No 'number-entries' node found."); - throw std::runtime_error(msg); + throw std::runtime_error("No 'number-entries' node found."); } // read all entries one by one and store them in 'm_allScores' for(int i=0; igetLisp(record_name); + std::ostringstream record_name; + record_name << "record-" << i; + const lisp::Lisp* const node_record=node->getLisp(record_name.str()); if(!node_record) { - char msg[MAX_ERROR_MESSAGE_LENGTH]; - snprintf(msg, sizeof(msg),"Can't find record '%d' in '%s'", - i,m_filename.c_str()); - throw std::runtime_error(msg); + std::ostringstream msg; + msg << "Can't find record '" << i << "' in '" + << m_filename << "'"; + throw std::runtime_error(msg.str()); } HighscoreEntry *highscores = new HighscoreEntry(node_record); m_allScores.push_back(highscores); @@ -174,12 +168,12 @@ void HighscoreManager::Save() for(type_all_scores::iterator i = m_allScores.begin(); i != m_allScores.end(); i++) { - char record_name[255]; - snprintf(record_name, sizeof(record_name),"record-%d\t",record_number); + std::ostringstream record_name; + record_name << "record-" << record_number << "\t"; record_number++; - writer.beginList(record_name); + writer.beginList(record_name.str()); (*i)->Write(&writer); - writer.endList(record_name); + writer.endList(record_name.str()); } // next score writer.endList("highscores"); m_can_write=true; diff --git a/src/highscores.cpp b/src/highscores.cpp index c725ff58c..3369fb95b 100644 --- a/src/highscores.cpp +++ b/src/highscores.cpp @@ -17,13 +17,12 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include #include "highscores.hpp" -#include "race_manager.hpp" -#if defined(WIN32) && !defined(__CYGWIN__) -# define snprintf _snprintf -#endif +#include +#include + +#include "race_manager.hpp" // ----------------------------------------------------------------------------- HighscoreEntry::HighscoreEntry(const HighscoreEntry::HighscoreType highscore_type, @@ -74,13 +73,13 @@ void HighscoreEntry::Read(const lisp::Lisp* const node) for(int i=0; iget(s,m_time[i] ); - snprintf(s, sizeof(s), "name-%d", i); - node->get(s,m_name[i] ); - snprintf(s, sizeof(s), "kartname-%d", i); - node->get(s, m_kart_name[i] ); + std::ostringstream s; + s << "time-" << i; + node->get(s.str(),m_time[i] ); + s << "name-" << i; + node->get(s.str(),m_name[i] ); + s << "kartname-" << i; + node->get(s.str(), m_kart_name[i] ); } } // Read @@ -90,17 +89,17 @@ void HighscoreEntry::Write(lisp::Writer *writer) writer->write("track-name\t", m_track ); writer->write("number-karts\t", m_number_of_karts ); writer->write("difficulty\t\t", m_difficulty ); - writer->write("hscore-type\t\t", m_highscore_type ); + writer->write("hscore-type\t\t", m_highscore_type ); writer->write("number-of-laps\t", m_number_of_laps ); for(int j=0; jwrite(s, m_time[j] ); - snprintf(s, sizeof(s), "name-%d\t\t", j); - writer->write(s, m_name[j] ); - snprintf(s, sizeof(s), "kartname-%d\t\t", j); - writer->write(s, m_kart_name[j] ); + std::ostringstream s; + s << "time-" << j << "\t\t"; + writer->write(s.str(), m_time[j] ); + s << "name-" << j << "\t\t"; + writer->write(s.str(), m_name[j] ); + s << "kartname-" << j << "\t\t"; + writer->write(s.str(), m_kart_name[j] ); } // for j } // Write diff --git a/src/ide/vc9/supertuxkart.sln b/src/ide/vc9/supertuxkart.sln index 07ebcf94e..05d8da827 100644 --- a/src/ide/vc9/supertuxkart.sln +++ b/src/ide/vc9/supertuxkart.sln @@ -13,48 +13,29 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "enet", "enet.vcproj", "{B0E EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - BulletDebug|Win32 = BulletDebug|Win32 - BulletRelease|Win32 = BulletRelease|Win32 Debug|Win32 = Debug|Win32 + irrlicht-debug|Win32 = irrlicht-debug|Win32 Release|Win32 = Release|Win32 - ReplayDebug|Win32 = ReplayDebug|Win32 - ReplayRelease|Win32 = ReplayRelease|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B1BC2764-1A43-4800-A654-788B0D05EDA2}.BulletDebug|Win32.ActiveCfg = BulletDebug|Win32 - {B1BC2764-1A43-4800-A654-788B0D05EDA2}.BulletDebug|Win32.Build.0 = BulletDebug|Win32 - {B1BC2764-1A43-4800-A654-788B0D05EDA2}.BulletRelease|Win32.ActiveCfg = BulletRelease|Win32 - {B1BC2764-1A43-4800-A654-788B0D05EDA2}.BulletRelease|Win32.Build.0 = BulletRelease|Win32 - {B1BC2764-1A43-4800-A654-788B0D05EDA2}.Debug|Win32.ActiveCfg = Debug|Win32 - {B1BC2764-1A43-4800-A654-788B0D05EDA2}.Debug|Win32.Build.0 = Debug|Win32 + {B1BC2764-1A43-4800-A654-788B0D05EDA2}.Debug|Win32.ActiveCfg = Release|Win32 + {B1BC2764-1A43-4800-A654-788B0D05EDA2}.Debug|Win32.Build.0 = Release|Win32 + {B1BC2764-1A43-4800-A654-788B0D05EDA2}.irrlicht-debug|Win32.ActiveCfg = irrlicht-debug|Win32 + {B1BC2764-1A43-4800-A654-788B0D05EDA2}.irrlicht-debug|Win32.Build.0 = irrlicht-debug|Win32 {B1BC2764-1A43-4800-A654-788B0D05EDA2}.Release|Win32.ActiveCfg = Release|Win32 {B1BC2764-1A43-4800-A654-788B0D05EDA2}.Release|Win32.Build.0 = Release|Win32 - {B1BC2764-1A43-4800-A654-788B0D05EDA2}.ReplayDebug|Win32.ActiveCfg = ReplayDebug|Win32 - {B1BC2764-1A43-4800-A654-788B0D05EDA2}.ReplayDebug|Win32.Build.0 = ReplayDebug|Win32 - {B1BC2764-1A43-4800-A654-788B0D05EDA2}.ReplayRelease|Win32.ActiveCfg = ReplayRelease|Win32 - {B1BC2764-1A43-4800-A654-788B0D05EDA2}.ReplayRelease|Win32.Build.0 = ReplayRelease|Win32 - {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.BulletDebug|Win32.ActiveCfg = Debug|Win32 - {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.BulletDebug|Win32.Build.0 = Debug|Win32 - {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.BulletRelease|Win32.ActiveCfg = Release|Win32 - {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.BulletRelease|Win32.Build.0 = Release|Win32 {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.Debug|Win32.ActiveCfg = Debug|Win32 {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.Debug|Win32.Build.0 = Debug|Win32 + {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.irrlicht-debug|Win32.ActiveCfg = Release|Win32 + {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.irrlicht-debug|Win32.Build.0 = Release|Win32 {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.Release|Win32.ActiveCfg = Release|Win32 {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.Release|Win32.Build.0 = Release|Win32 - {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.ReplayDebug|Win32.ActiveCfg = Debug|Win32 - {54AA44B9-B07B-49DA-8B1A-05BBFE8AD5D4}.ReplayRelease|Win32.ActiveCfg = Release|Win32 - {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.BulletDebug|Win32.ActiveCfg = Release|Win32 - {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.BulletDebug|Win32.Build.0 = Release|Win32 - {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.BulletRelease|Win32.ActiveCfg = Release|Win32 - {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.BulletRelease|Win32.Build.0 = Release|Win32 - {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.Debug|Win32.ActiveCfg = Debug|Win32 - {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.Debug|Win32.Build.0 = Debug|Win32 + {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.Debug|Win32.ActiveCfg = Release|Win32 + {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.Debug|Win32.Build.0 = Release|Win32 + {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.irrlicht-debug|Win32.ActiveCfg = Release|Win32 + {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.irrlicht-debug|Win32.Build.0 = Release|Win32 {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.Release|Win32.ActiveCfg = Release|Win32 {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.Release|Win32.Build.0 = Release|Win32 - {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.ReplayDebug|Win32.ActiveCfg = Debug|Win32 - {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.ReplayDebug|Win32.Build.0 = Debug|Win32 - {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.ReplayRelease|Win32.ActiveCfg = Release|Win32 - {B0E92B97-089A-4D5B-BF17-77F1BC5DAEEF}.ReplayRelease|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/ide/vc9/supertuxkart.vcproj b/src/ide/vc9/supertuxkart.vcproj index 00f45bd93..7aec0be46 100644 --- a/src/ide/vc9/supertuxkart.vcproj +++ b/src/ide/vc9/supertuxkart.vcproj @@ -16,6 +16,94 @@ + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - addKid(m_st_model[type]); - scene->add(m); + stk_scene->add(m); } // Flyable // ---------------------------------------------------------------------------- void Flyable::createPhysics(float y_offset, const btVector3 &velocity, @@ -259,7 +259,7 @@ void Flyable::hit(Kart *kart_hit, MovingPhysics* moving_physics) // Now remove this projectile from the graph: ssgTransform *m = getModelTransform(); m->removeAllKids(); - scene->remove(m); + stk_scene->remove(m); // The explosion is a bit higher in the air Vec3 pos_explosion=getXYZ(); diff --git a/src/items/item.cpp b/src/items/item.cpp index 119eefd5c..ab248cf49 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -41,13 +41,13 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal, m_root->ref(); m_root->setTransform(const_cast(&m_coord.toSgCoord())); m_root->addKid(model); - scene->add(m_root); + stk_scene->add(m_root); } // Item //----------------------------------------------------------------------------- Item::~Item() { - scene->remove(m_root); + stk_scene->remove(m_root); ssgDeRefDelete(m_root); } // ~Item diff --git a/src/items/plunger.cpp b/src/items/plunger.cpp index 37ea6e044..19012eb08 100644 --- a/src/items/plunger.cpp +++ b/src/items/plunger.cpp @@ -124,7 +124,7 @@ void Plunger::update(float dt) projectile_manager->notifyRemove(); ssgTransform *m = getModelTransform(); m->removeAllKids(); - scene->remove(m); + stk_scene->remove(m); } if(m_rubber_band != NULL) m_rubber_band->update(dt); return; diff --git a/src/items/projectile_manager.cpp b/src/items/projectile_manager.cpp index f5d48101c..56436d301 100644 --- a/src/items/projectile_manager.cpp +++ b/src/items/projectile_manager.cpp @@ -73,7 +73,7 @@ void ProjectileManager::cleanup() for(Explosions::iterator i = m_active_explosions.begin(); i != m_active_explosions.end(); ++i) { - scene->remove((ssgTransform*)*i); + stk_scene->remove((ssgTransform*)*i); ssgDeRefDelete(*i); } m_active_explosions.clear(); diff --git a/src/items/rubber_band.cpp b/src/items/rubber_band.cpp index f5b396f7b..45c8556a6 100755 --- a/src/items/rubber_band.cpp +++ b/src/items/rubber_band.cpp @@ -67,7 +67,7 @@ RubberBand::RubberBand(Plunger *plunger, const Kart &kart) setState(m_state); //setState(material_manager->getMaterial("chrome.rgb")->getState()); - scene->add(this); + stk_scene->add(this); } // RubberBand // ---------------------------------------------------------------------------- @@ -76,7 +76,7 @@ RubberBand::RubberBand(Plunger *plunger, const Kart &kart) */ void RubberBand::removeFromScene() { - scene->remove(this); + stk_scene->remove(this); } // removeFromScene // ---------------------------------------------------------------------------- diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index c6c86b21f..49659b394 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -26,6 +26,7 @@ #include "file_manager.hpp" #include "stk_config.hpp" #include "user_config.hpp" +#include "callback_manager.hpp" #include "challenges/unlock_manager.hpp" #include "karts/kart_properties.hpp" #include "utils/string_utils.hpp" diff --git a/src/karts/player_kart.cpp b/src/karts/player_kart.cpp index c74a6db45..f02cdbcf5 100644 --- a/src/karts/player_kart.cpp +++ b/src/karts/player_kart.cpp @@ -40,7 +40,7 @@ PlayerKart::PlayerKart(const std::string& kart_name, int position, Player *playe { m_player = player; m_penalty_time = 0.0f; - m_camera = scene->createCamera(player_index, this); + m_camera = stk_scene->createCamera(player_index, this); m_camera->setMode(Camera::CM_NORMAL); m_bzzt_sound = sfx_manager->newSFX(SFXManager::SOUND_BZZT ); diff --git a/src/lisp/lisp.hpp b/src/lisp/lisp.hpp index 3109fa478..b1d51f391 100644 --- a/src/lisp/lisp.hpp +++ b/src/lisp/lisp.hpp @@ -103,6 +103,12 @@ namespace lisp return false; return lisp->get(val); } + template + bool get(std::string &name, T& val) const + { + return get(name.c_str(), val); + } + bool get(const char* name, sgVec4& val) const { const Lisp* lisp = getLisp(name); diff --git a/src/main.cpp b/src/main.cpp index fff0b67b6..682b6b895 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -504,7 +504,7 @@ void CleanTuxKart() if(loader) delete loader; if(translations) delete translations; if(file_manager) delete file_manager; - if(scene) delete scene; + if(stk_scene) delete stk_scene; } //============================================================================= @@ -555,7 +555,7 @@ int main(int argc, char *argv[] ) powerup_manager -> loadPowerups (); item_manager -> loadDefaultItems(); attachment_manager -> loadModels (); - scene = new Scene(); + stk_scene = new Scene(); //For some reason, calling this before the material loading screws //the background picture. diff --git a/src/main_loop.cpp b/src/main_loop.cpp index 9849468c9..b295430b9 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -124,7 +124,7 @@ void MainLoop::run() if(user_config->m_profile) dt=1.0f/60.0f; // In the first call dt might be large (includes loading time), // which can cause the camera to significantly tilt - scene->draw(RaceManager::getWorld()->getPhase()==SETUP_PHASE ? 0.0f : dt); + stk_scene->draw(RaceManager::getWorld()->getPhase()==SETUP_PHASE ? 0.0f : dt); // Again, only receive updates if the race isn't over - once the // race results are displayed (i.e. game is in finish phase) diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 9684513a2..142479dce 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -49,10 +49,7 @@ #include "tracks/track_manager.hpp" #include "utils/constants.hpp" #include "utils/translation.hpp" - -#if defined(WIN32) && !defined(__CYGWIN__) -# define snprintf _snprintf -#endif +#include "utils/string_utils.hpp" //----------------------------------------------------------------------------- World::World() : TimedRace() @@ -114,7 +111,7 @@ void World::init() // karts can be seen. if(i==race_manager->getNumKarts()-1) { - scene->createCamera(local_player_id, newkart); + stk_scene->createCamera(local_player_id, newkart); m_local_player_karts[0] = static_cast(newkart); } } @@ -147,7 +144,7 @@ void World::init() newkart -> getModelTransform() -> clrTraversalMaskBits(SSGTRAV_ISECT|SSGTRAV_HOT); - scene->add ( newkart -> getModelTransform() ) ; + stk_scene->add ( newkart -> getModelTransform() ) ; m_kart.push_back(newkart); newkart->setWorldKartId(m_kart.size()-1); } // for i @@ -413,10 +410,9 @@ void World::removeKart(int kart_number) } else { - char s[MAX_MESSAGE_LENGTH]; - snprintf(s, MAX_MESSAGE_LENGTH,_("'%s' has\nbeen eliminated."), - kart->getName().c_str()); - m->addMessage( s, *i, 2.0f, 60); + std::string s = _("'%s' has\nbeen eliminated."); + m->addMessage( StringUtils::insert_string(s, kart->getName()), + *i, 2.0f, 60); } } // for i in kart } // if raceMenu exist @@ -514,7 +510,7 @@ void World::restartRace() callback_manager->reset(); // Resets the cameras in case that they are pointing too steep up or down - scene->reset(); + stk_scene->reset(); } // restartRace //----------------------------------------------------------------------------- diff --git a/src/physics/moving_physics.cpp b/src/physics/moving_physics.cpp index 8911358a3..47366916d 100644 --- a/src/physics/moving_physics.cpp +++ b/src/physics/moving_physics.cpp @@ -86,7 +86,7 @@ MovingPhysics::~MovingPhysics() delete m_body; delete m_motion_state; delete m_shape; - scene->remove(this); + stk_scene->remove(this); } // ~MovingPhysics // ----------------------------------------------------------------------------- @@ -112,7 +112,7 @@ void MovingPhysics::init() } ssgBranch *parent = getParent(0); - scene->add(this); + stk_scene->add(this); parent->removeKid(this); // 2. Determine the original position of the object diff --git a/src/race_manager.cpp b/src/race_manager.cpp index 255692d33..573cff857 100644 --- a/src/race_manager.cpp +++ b/src/race_manager.cpp @@ -275,7 +275,7 @@ void RaceManager::next() network_manager->beginReadySetGoBarrier(); else network_manager->setState(NetworkManager::NS_WAIT_FOR_RACE_DATA); - scene->clear(); + stk_scene->clear(); startNextRace(); } else @@ -370,7 +370,7 @@ void RaceManager::exit_race() { menu_manager->switchToMainMenu(); } - scene->clear(); + stk_scene->clear(); delete world; world = 0; m_track_number = 0; diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 2d38fe75c..1b659db85 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -526,7 +526,7 @@ void Track::addDebugToScene(int type) const colour[2] = 0; } sphere->setColour(colour); - scene->add(sphere); + stk_scene->add(sphere); } // for i } /// type ==1 // 2: drivelines, 4: driveline with tolerance @@ -561,7 +561,7 @@ void Track::addDebugToScene(int type) const (ssgNormalArray*)NULL, (ssgTexCoordArray*)NULL, c_array); - scene->add(l); + stk_scene->add(l); } } // addDebugToScene @@ -1196,7 +1196,7 @@ void Track::loadTrackModel() // Start building the scene graph m_model = new ssgBranch ; - scene->add(m_model); + stk_scene->add(m_model); char s [ 1024 ] ; diff --git a/src/user_config.cpp b/src/user_config.cpp index 66bf5ae0f..fc5d143bc 100644 --- a/src/user_config.cpp +++ b/src/user_config.cpp @@ -352,9 +352,7 @@ void UserConfig::loadConfig(const std::string& filename) const lisp::Lisp* lisp = root->getLisp("tuxkart-config"); if(!lisp) { - char msg[MAX_ERROR_MESSAGE_LENGTH]; - snprintf(msg, sizeof(msg), "No tuxkart-config node"); - throw std::runtime_error(msg); + throw std::runtime_error("No tuxkart-config node"); } int configFileVersion = 0; lisp->get("configFileVersion", configFileVersion); @@ -457,9 +455,9 @@ void UserConfig::loadConfig(const std::string& filename) const lisp::Lisp* reader = lisp->getLisp(temp); if(!reader) { - char msg[MAX_ERROR_MESSAGE_LENGTH]; - snprintf(msg, sizeof(msg), "No '%s' node", temp.c_str()); - throw std::runtime_error(msg); + std::ostringstream msg; + msg << "No '" << temp << "' node"; + throw std::runtime_error(msg.str()); } std::string name; reader->get("name", name); @@ -467,12 +465,12 @@ void UserConfig::loadConfig(const std::string& filename) { // For older config files, replace the default player // names "Player %d" with the user name - char sDefaultName[10]; - snprintf(sDefaultName, sizeof(sDefaultName), - "Player %d",i+1); + std::ostringstream sDefaultName; + + sDefaultName << "Player " << i+1; // If the config file does not contain a name or the old // default name, set the default username as player name. - if(name.size()==0 || name==sDefaultName) name=m_username; + if(name.size()==0 || name==sDefaultName.str()) name=m_username; } m_player[i].setName(name); @@ -921,41 +919,43 @@ void UserConfig::writeInput(lisp::Writer *writer, const Input &input) std::string UserConfig::getInputAsString(const Input &input) { char msg[MAX_MESSAGE_LENGTH]; - std::ostringstream stm; + std::string s; switch (input.type) { case Input::IT_NONE: - snprintf(msg, sizeof(msg), _("not set")); + s = _("not set"); break; case Input::IT_KEYBOARD: - snprintf(msg, sizeof(msg), "%s", SDL_GetKeyName((SDLKey) input.id0)); + s = SDL_GetKeyName((SDLKey) input.id0); break; case Input::IT_STICKMOTION: snprintf(msg, sizeof(msg), _("joy %d axis %d %c"), input.id0, input.id1, (input.id2 == Input::AD_NEGATIVE) ? '-' : '+'); + s = msg; break; case Input::IT_STICKBUTTON: snprintf(msg, sizeof(msg), _("joy %d btn %d"), input.id0, input.id1); + s = msg; break; case Input::IT_STICKHAT: snprintf(msg, sizeof(msg), _("joy %d hat %d"), input.id0, input.id1); + s = msg; break; case Input::IT_MOUSEBUTTON: snprintf(msg, sizeof(msg), _("mouse btn %d"), input.id0); + s = msg; break; case Input::IT_MOUSEMOTION: snprintf(msg, sizeof(msg), _("mouse axis %d %c"), input.id0, ((input.id1 == Input::AD_NEGATIVE) ? '-' : '+')); break; default: - snprintf(msg, sizeof(msg), _("Invalid")); + s = _("Invalid"); } - stm << msg; - - return stm.str(); + return s; } // GetKeyAsString // ----------------------------------------------------------------------------- diff --git a/src/utils/string_utils.cpp b/src/utils/string_utils.cpp index a4e2e8256..34f19bfb1 100644 --- a/src/utils/string_utils.cpp +++ b/src/utils/string_utils.cpp @@ -127,7 +127,6 @@ namespace StringUtils } return result; } - } // namespace StringUtils /* EOF */ diff --git a/src/utils/string_utils.hpp b/src/utils/string_utils.hpp index 36933a8b4..c822aa439 100644 --- a/src/utils/string_utils.hpp +++ b/src/utils/string_utils.hpp @@ -18,8 +18,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HEADER_STRING_UTILS_H -#define HEADER_STRING_UTILS_H +#ifndef HEADER_STRING_UTILS_HPP +#define HEADER_STRING_UTILS_HPP #include #include @@ -72,6 +72,29 @@ namespace StringUtils std::string upcase (const std::string&); std::string downcase (const std::string&); std::vector split(const std::string& s, char c); + // ------------------------------------------------------------------------ + /** Replaces all '%s' or '%d' in the first string with the 2nd string. So + * this is basically a simplified s(n)printf replacement, which doesn't + * rely on s(n)printf (which is not that portable). + * \param s String in which all %s or %dare replaced. + * \param a Value to replace all %s or %d with. + */ + template + std::string insert_string(const std::string &s, const T &a) + { + std::vector sv = StringUtils::split(s, '%'); + std::string new_string=""; + for(unsigned int i=0; i