From ff67a5cf4e002d9321fe2d3c18b07f7ef8f33c40 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Thu, 9 Feb 2012 21:14:32 +0000 Subject: [PATCH] Removed the usage of friend declaration. CheckStructure dependencies are now not read in CheckStructure anymore, instead they are set by the CheckManager depending on the direction of the track. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/reverse_mode@10832 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/tracks/check_manager.cpp | 53 +++++++++++++++++----------------- src/tracks/check_manager.hpp | 1 - src/tracks/check_structure.cpp | 14 ++++----- src/tracks/check_structure.hpp | 12 ++++++-- src/tracks/track.cpp | 3 -- 5 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/tracks/check_manager.cpp b/src/tracks/check_manager.cpp index 0f14ed30a..c69876fea 100644 --- a/src/tracks/check_manager.cpp +++ b/src/tracks/check_manager.cpp @@ -52,6 +52,32 @@ CheckManager::CheckManager(const XMLNode &node, Track *track) else printf("Unknown check structure '%s' - ignored.\n", type.c_str()); } // for i check_structures_to_change_state; + + check_node->get("other-ids", &check_structures_to_change_state); + // Backwards compatibility to tracks exported with older versions of + // the track exporter + if(check_structures_to_change_state.size()==0) + check_node->get("other-id", &check_structures_to_change_state); + std::vector::iterator it; + for(it=check_structures_to_change_state.begin(); + it != check_structures_to_change_state.end(); it++) + { + if(QuadGraph::get()->isReverse()) + m_all_checks[*it]->addSuccessor(i); + else + m_all_checks[i]->addSuccessor(*it); + } + + } } // CheckManager // ---------------------------------------------------------------------------- @@ -65,33 +91,6 @@ CheckManager::~CheckManager() // ---------------------------------------------------------------------------- -/** Reverse checks order. */ -void CheckManager::reverse() -{ - std::map > structures_to_change_state; - std::vector::iterator it; - for(unsigned int i=0;i::const_iterator it = m_all_checks[i]->m_check_structures_to_change_state.begin(); - it != m_all_checks[i]->m_check_structures_to_change_state.end(); ++it) - { - if(*it>=0) - { - structures_to_change_state[*it].push_back(i); - } - } - } - for(unsigned int i=0;im_check_structures_to_change_state.clear(); - m_all_checks[i]->m_check_structures_to_change_state.resize(structures_to_change_state[i].size()); - copy(structures_to_change_state[i].begin(),structures_to_change_state[i].end(), - m_all_checks[i]->m_check_structures_to_change_state.begin()); - } -} // reverse - -// ---------------------------------------------------------------------------- - /** Resets all checks. */ void CheckManager::reset(const Track &track) { diff --git a/src/tracks/check_manager.hpp b/src/tracks/check_manager.hpp index fba3c9894..0f9a9c45e 100644 --- a/src/tracks/check_manager.hpp +++ b/src/tracks/check_manager.hpp @@ -39,7 +39,6 @@ public: ~CheckManager(); void update(float dt); void reset(const Track &track); - void reverse(); int getCheckStructureCount() const { return m_all_checks.size(); } diff --git a/src/tracks/check_structure.cpp b/src/tracks/check_structure.cpp index c8caf4d57..98e88940b 100644 --- a/src/tracks/check_structure.cpp +++ b/src/tracks/check_structure.cpp @@ -33,6 +33,13 @@ CheckStructure::CheckStructure(CheckManager *check_manager, { m_index = index; m_check_manager = check_manager; + m_check_type = CT_NEW_LAP; + + // This structure is actually filled by the check manager (necessary + // in order to support track reversing). + m_check_structures_to_change_state.clear(); + m_same_group.clear(); + std::string kind; node.get("kind", &kind); if(kind=="lap") @@ -47,14 +54,7 @@ CheckStructure::CheckStructure(CheckManager *check_manager, { printf("Unknown check structure '%s' - ignored.\n", kind.c_str()); } - m_check_structures_to_change_state.clear(); - node.get("other-ids", &m_check_structures_to_change_state); - // Backwards compatibility to tracks exported with older versions of - // the track exporter - if(m_check_structures_to_change_state.size()==0) - node.get("other-id", &m_check_structures_to_change_state); - m_same_group.clear(); node.get("same-group", &m_same_group); // Make sure that the index of this check structure is included in // the same_group list. While this should be guaranteed by the diff --git a/src/tracks/check_structure.hpp b/src/tracks/check_structure.hpp index 3a13e77a3..99ae2f5b8 100644 --- a/src/tracks/check_structure.hpp +++ b/src/tracks/check_structure.hpp @@ -47,7 +47,6 @@ class CheckManager; */ class CheckStructure { -friend class CheckManager; public: /** Different types of check structures: * ACTIVATE: Activates another check structure (independent of @@ -113,13 +112,20 @@ public: * \param indx Index of the kart, can be used to store kart specific * additional data. */ - virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx)=0; + virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, + int indx)=0; virtual void trigger(unsigned int kart_index); virtual void reset(const Track &track); + // ------------------------------------------------------------------------ /** Returns the type of this check structure. */ CheckType getType() const { return m_check_type; } - + // ------------------------------------------------------------------------ + /** Adds the index of a successor check structure which will get triggered + * by this check structure. */ + void addSuccessor(unsigned int i) { + m_check_structures_to_change_state.push_back(i); + } // addSuccessor }; // CheckStructure #endif diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 254396666..dcdd38fc3 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -1316,9 +1316,6 @@ void Track::loadTrackModel(World* parent, bool reverse_track, else if(name=="checks") { m_check_manager = new CheckManager(*node, this); - if(reverse_track) { - m_check_manager->reverse(); - } } else if (name=="particle-emitter") {