From f325a0fa1452f2060a551bb108fb1fad442b0d01 Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 24 Feb 2020 10:58:17 +0800 Subject: [PATCH] Add code for copying check structures --- src/tracks/check_cannon.cpp | 18 ++++++++++++++++-- src/tracks/check_cannon.hpp | 4 +++- src/tracks/check_cylinder.hpp | 9 +++++++++ src/tracks/check_goal.hpp | 5 ++++- src/tracks/check_lap.hpp | 4 +++- src/tracks/check_line.hpp | 9 ++++++++- src/tracks/check_sphere.hpp | 2 ++ src/tracks/check_structure.hpp | 3 +++ src/tracks/check_trigger.hpp | 14 ++++++++++++-- 9 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/tracks/check_cannon.cpp b/src/tracks/check_cannon.cpp index 2d13679ae..fcc3205c1 100644 --- a/src/tracks/check_cannon.cpp +++ b/src/tracks/check_cannon.cpp @@ -57,6 +57,7 @@ CheckCannon::CheckCannon(const XMLNode &node, unsigned int index) /*reverse*/race_manager->getReverseTrack()); #if defined(DEBUG) && !defined(SERVER_ONLY) + m_show_curve = NULL; if(UserConfigParams::m_track_debug) { m_show_curve = new ShowCurve(0.5f, 0.5f); @@ -98,8 +99,7 @@ CheckCannon::~CheckCannon() { delete m_curve; #if defined(DEBUG) && !defined(SERVER_ONLY) - if(UserConfigParams::m_track_debug) - delete m_show_curve; + delete m_show_curve; if (m_debug_target_dy_dc) m_debug_target_dy_dc->removeFromSP(); #endif @@ -173,3 +173,17 @@ void CheckCannon::update(float dt) flyable->setAnimation(animation); } // for i in all flyables } // update + +// ---------------------------------------------------------------------------- +CheckStructure* CheckCannon::clone() +{ + CheckCannon* cc = new CheckCannon(*this); +#if defined(DEBUG) && !defined(SERVER_ONLY) + // Remove unsupported stuff when cloning + cc->m_show_curve = NULL; + cc->m_debug_target_dy_dc = nullptr; +#endif + // IPO curve needs to be copied manually + cc->m_curve = m_curve->clone(); + return cc; +} // clone diff --git a/src/tracks/check_cannon.hpp b/src/tracks/check_cannon.hpp index 2af759bcd..ec441067e 100644 --- a/src/tracks/check_cannon.hpp +++ b/src/tracks/check_cannon.hpp @@ -52,7 +52,7 @@ private: /** Stores the cannon curve data. */ Ipo *m_curve; -#ifdef DEBUG +#if defined(DEBUG) && !defined(SERVER_ONLY) /** If track debugging is enabled, this will show the the curve of * the cannon in the race. */ ShowCurve* m_show_curve; @@ -90,6 +90,8 @@ public: const Vec3& getTargetRight() const { return m_target_right; } // ------------------------------------------------------------------------ Ipo* getIpo() const { return m_curve; } + // ------------------------------------------------------------------------ + virtual CheckStructure* clone() OVERRIDE; }; // CheckCannon #endif diff --git a/src/tracks/check_cylinder.hpp b/src/tracks/check_cylinder.hpp index 1d47d386d..aa3d3b0e6 100644 --- a/src/tracks/check_cylinder.hpp +++ b/src/tracks/check_cylinder.hpp @@ -65,6 +65,15 @@ public: // ------------------------------------------------------------------------- /** Returns the square of the radius of this sphere. */ float getRadius2() const { return m_radius2; } + // ------------------------------------------------------------------------ + virtual CheckStructure* clone() + { + CheckCylinder* cc = new CheckCylinder(*this); + // Drop unneeded stuff ( trigger function is not supported in server, + // no scripting atm) + cc->m_triggering_function = nullptr; + return cc; + } }; // CheckCylinder #endif diff --git a/src/tracks/check_goal.hpp b/src/tracks/check_goal.hpp index a310ca60c..3718491fb 100644 --- a/src/tracks/check_goal.hpp +++ b/src/tracks/check_goal.hpp @@ -69,13 +69,16 @@ public: virtual void reset(const Track &track) OVERRIDE; // ------------------------------------------------------------------------ - bool getTeam() const { return m_first_goal; } + bool getTeam() const { return m_first_goal; } // ------------------------------------------------------------------------ const Vec3& getPoint(PointLocation point) const { return (point == POINT_LAST ? m_p3 : (point == POINT_CENTER ? m_p2 : m_p1)); } + // ------------------------------------------------------------------------ + virtual CheckStructure* clone() OVERRIDE + { return new CheckGoal(*this); } }; // CheckGoal #endif diff --git a/src/tracks/check_lap.hpp b/src/tracks/check_lap.hpp index 5f932a9a7..fd96e60e3 100644 --- a/src/tracks/check_lap.hpp +++ b/src/tracks/check_lap.hpp @@ -44,7 +44,9 @@ public: int indx) OVERRIDE; virtual void reset(const Track &track) OVERRIDE; virtual bool triggeringCheckline() const OVERRIDE { return true; } -}; // CheckLine + // ------------------------------------------------------------------------ + virtual CheckStructure* clone() OVERRIDE { return new CheckLap(*this); } +}; // CheckLap #endif diff --git a/src/tracks/check_line.hpp b/src/tracks/check_line.hpp index 01d3bcc8a..0c78aac45 100644 --- a/src/tracks/check_line.hpp +++ b/src/tracks/check_line.hpp @@ -109,7 +109,14 @@ public: const Vec3 &getLeftPoint() const { return m_left_point; } // ------------------------------------------------------------------------ const Vec3 &getRightPoint() const { return m_right_point; } - + // ------------------------------------------------------------------------ + virtual CheckStructure* clone() OVERRIDE + { + CheckLine* cl = new CheckLine(*this); + // Drop unneeded stuff + cl->m_debug_dy_dc = nullptr; + return cl; + } }; // CheckLine #endif diff --git a/src/tracks/check_sphere.hpp b/src/tracks/check_sphere.hpp index b11e05fd9..99814305f 100644 --- a/src/tracks/check_sphere.hpp +++ b/src/tracks/check_sphere.hpp @@ -59,6 +59,8 @@ public: // ------------------------------------------------------------------------- /** Returns the square of the radius of this sphere. */ float getRadius2() const { return m_radius2; } + // ------------------------------------------------------------------------ + virtual CheckStructure* clone() { return new CheckSphere(*this); } }; // CheckSphere #endif diff --git a/src/tracks/check_structure.hpp b/src/tracks/check_structure.hpp index 31fd2b19a..ceba9cd24 100644 --- a/src/tracks/check_structure.hpp +++ b/src/tracks/check_structure.hpp @@ -146,6 +146,9 @@ public: void restoreIsActive(int kart_id, const BareNetworkString& b); // ------------------------------------------------------------------------ int getIndex() const { return m_index; } + // ------------------------------------------------------------------------ + /** Clone to child process for server usage (atm no sound or scripting). */ + virtual CheckStructure* clone() = 0; }; // CheckStructure #endif diff --git a/src/tracks/check_trigger.hpp b/src/tracks/check_trigger.hpp index b1dedb424..2802908a4 100644 --- a/src/tracks/check_trigger.hpp +++ b/src/tracks/check_trigger.hpp @@ -38,7 +38,7 @@ private: const float m_distance2; /** Function to call when triggered. */ - const std::function m_triggering_function; + std::function m_triggering_function; /** Time since last trigger, if any triggering between 2 seconds ignored * (like items). */ @@ -55,10 +55,20 @@ public: // ------------------------------------------------------------------------ virtual void trigger(unsigned int kart_index) OVERRIDE { + if (!m_triggering_function) return; m_triggering_function(kart_index); CheckStructure::trigger(kart_index); } -}; // CheckSphere + // ------------------------------------------------------------------------ + virtual CheckStructure* clone() OVERRIDE + { + CheckTrigger* ct = new CheckTrigger(*this); + // Drop unneeded stuff ( trigger function is not supported in server, + // no scripting atm) + ct->m_triggering_function = nullptr; + return ct; + } +}; // CheckTrigger #endif