diff --git a/README.md b/README.md index 2426fff1..695f5147 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,11 @@ This means RocketSim is accurate enough to: - *Train machine learning bots* - *Simulate different shots on the ball at different angles to find the best input combination* - *Simulate air control to find the optimal orientation input* +- *Simulate ground and floor pinches* However, RocketSim is NOT accurate enough to: - *Simulate entire games from inputs alone* -- *Accurately determine the outcome of powerful pinches* +- *Perfectly simulate long sequences of jumps and landings* ## Installation - Clone this repo and build it diff --git a/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index f7dc5cfe..80096a9a 100644 --- a/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -1208,5 +1208,7 @@ void btCollisionWorld::contactPairTest(btCollisionObject* colObjA, btCollisionOb bool btCollisionWorld::RayResultCallback::needsCollision(btBroadphaseProxy* proxy0) const { bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0 && (m_collisionFilterGroup & proxy0->m_collisionFilterMask); + if (proxy0->m_clientObject == m_ignoreObj) + return false; return collides; } \ No newline at end of file diff --git a/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionWorld.h b/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionWorld.h index 874a1792..5dbd76dd 100644 --- a/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionWorld.h +++ b/libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btCollisionWorld.h @@ -177,6 +177,7 @@ class btCollisionWorld { btScalar m_closestHitFraction; const btCollisionObject* m_collisionObject; + const btCollisionObject* m_ignoreObj; int m_collisionFilterGroup; int m_collisionFilterMask; //@BP Mod - Custom flags, currently used to enable backface culling on tri-meshes, see btRaycastCallback.h. Apply any of the EFlags defined there on m_flags here to invoke. @@ -195,6 +196,7 @@ class btCollisionWorld m_collisionObject(0), m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter), m_collisionFilterMask(btBroadphaseProxy::AllFilter), + m_ignoreObj(0), //@BP Mod m_flags(0) { @@ -208,10 +210,11 @@ class btCollisionWorld struct ClosestRayResultCallback : public RayResultCallback { - ClosestRayResultCallback(const btVector3& rayFromWorld, const btVector3& rayToWorld) + ClosestRayResultCallback(const btVector3& rayFromWorld, const btVector3& rayToWorld, const btCollisionObject* ignoreObj) : m_rayFromWorld(rayFromWorld), m_rayToWorld(rayToWorld) { + this->m_ignoreObj = ignoreObj; } btVector3 m_rayFromWorld; //used to calculate hitPointWorld from hitFraction diff --git a/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btDefaultVehicleRaycaster.cpp b/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btDefaultVehicleRaycaster.cpp index a96348be..006b3faf 100644 --- a/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btDefaultVehicleRaycaster.cpp +++ b/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btDefaultVehicleRaycaster.cpp @@ -29,11 +29,11 @@ btRigidBody& btActionInterface::getFixedBody() return s_fixed; } -void* btDefaultVehicleRaycaster::castRay(const btVector3& from, const btVector3& to, btVehicleRaycasterResult& result) +void* btDefaultVehicleRaycaster::castRay(const btVector3& from, const btVector3& to, const btCollisionObject* ignoreObj, btVehicleRaycasterResult& result) { // RayResultCallback& resultCallback; - btCollisionWorld::ClosestRayResultCallback rayCallback(from, to); + btCollisionWorld::ClosestRayResultCallback rayCallback(from, to, ignoreObj); rayCallback.m_collisionFilterGroup = btBroadphaseProxy::CharacterFilter; rayCallback.m_collisionFilterMask = btBroadphaseProxy::AllFilter; diff --git a/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btDefaultVehicleRaycaster.h b/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btDefaultVehicleRaycaster.h index f5996ce7..84dce283 100644 --- a/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btDefaultVehicleRaycaster.h +++ b/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btDefaultVehicleRaycaster.h @@ -31,7 +31,7 @@ class btDefaultVehicleRaycaster : public btVehicleRaycaster { } - virtual void* castRay(const btVector3& from, const btVector3& to, btVehicleRaycasterResult& result); + virtual void* castRay(const btVector3& from, const btVector3& to, const btCollisionObject* ignoreObj, btVehicleRaycasterResult& result); }; #endif //BT_RAYCASTVEHICLE_H diff --git a/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btVehicleRaycaster.h b/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btVehicleRaycaster.h index 218edb0a..4733d245 100644 --- a/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btVehicleRaycaster.h +++ b/libsrc/bullet3-3.24/BulletDynamics/Vehicle/btVehicleRaycaster.h @@ -27,7 +27,7 @@ struct btVehicleRaycaster btScalar m_distFraction; }; - virtual void* castRay(const btVector3& from, const btVector3& to, btVehicleRaycasterResult& result) = 0; + virtual void* castRay(const btVector3& from, const btVector3& to, const btCollisionObject* ignoreObj, btVehicleRaycasterResult& result) = 0; }; #endif //BT_VEHICLE_RAYCASTER_H diff --git a/libsrc/bullet3-3.24/LinearMath/btHashMap.h b/libsrc/bullet3-3.24/LinearMath/btHashMap.h index 1fca0fb7..57d68621 100644 --- a/libsrc/bullet3-3.24/LinearMath/btHashMap.h +++ b/libsrc/bullet3-3.24/LinearMath/btHashMap.h @@ -218,7 +218,7 @@ class btHashKey template class btHashMap { -protected: +public: btAlignedObjectArray m_hashTable; btAlignedObjectArray m_next; diff --git a/python-mtheall/Angle.cpp b/python-mtheall/Angle.cpp index 19d31465..a3950ddc 100644 --- a/python-mtheall/Angle.cpp +++ b/python-mtheall/Angle.cpp @@ -10,18 +10,18 @@ PyTypeObject *Angle::Type = nullptr; PyMemberDef Angle::Members[] = { {.name = "yaw", - .type = TypeHelper::type, - .offset = offsetof (Angle, angle) + offsetof (::Angle, yaw), + .type = TypeHelper::type, + .offset = offsetof (Angle, angle) + offsetof (RocketSim::Angle, yaw), .flags = 0, .doc = "Yaw component"}, {.name = "pitch", - .type = TypeHelper::type, - .offset = offsetof (Angle, angle) + offsetof (::Angle, pitch), + .type = TypeHelper::type, + .offset = offsetof (Angle, angle) + offsetof (RocketSim::Angle, pitch), .flags = 0, .doc = "Pitch component"}, {.name = "roll", - .type = TypeHelper::type, - .offset = offsetof (Angle, angle) + offsetof (::Angle, roll), + .type = TypeHelper::type, + .offset = offsetof (Angle, angle) + offsetof (RocketSim::Angle, roll), .flags = 0, .doc = "Roll component"}, {.name = nullptr, .type = 0, .offset = 0, .flags = 0, .doc = nullptr}, @@ -82,7 +82,7 @@ PyType_Spec Angle::Spec = { .slots = Angle::Slots, }; -PyRef Angle::NewFromAngle (::Angle const &angle_) noexcept +PyRef Angle::NewFromAngle (RocketSim::Angle const &angle_) noexcept { auto const self = PyRef::stealObject (Angle::New (Angle::Type, nullptr, nullptr)); if (!self || !InitFromAngle (self.borrow (), angle_)) @@ -91,13 +91,13 @@ PyRef Angle::NewFromAngle (::Angle const &angle_) noexcept return self; } -bool Angle::InitFromAngle (Angle *const self_, ::Angle const &angle_) noexcept +bool Angle::InitFromAngle (Angle *const self_, RocketSim::Angle const &angle_) noexcept { self_->angle = angle_; return true; } -::Angle Angle::ToAngle (Angle *self_) noexcept +RocketSim::Angle Angle::ToAngle (Angle *self_) noexcept { return self_->angle; } @@ -110,7 +110,7 @@ PyObject *Angle::New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) if (!self) return nullptr; - new (&self->angle)::Angle{}; + new (&self->angle) RocketSim::Angle{}; return self.giftObject (); } @@ -123,7 +123,7 @@ int Angle::Init (Angle *self_, PyObject *args_, PyObject *kwds_) noexcept static char *dict[] = {yawKwd, pitchKwd, rollKwd, nullptr}; - ::Angle angle{}; + RocketSim::Angle angle{}; if (!PyArg_ParseTupleAndKeywords (args_, kwds_, "|fff", dict, &angle.yaw, &angle.pitch, &angle.roll)) return -1; @@ -193,7 +193,7 @@ PyObject *Angle::Pickle (Angle *self_) noexcept if (!dict) return nullptr; - ::Angle const model{}; + RocketSim::Angle const model{}; auto const angle = ToAngle (self_); if (angle.yaw != model.yaw && !DictSetValue (dict.borrow (), "yaw", PyFloat_FromDouble (angle.yaw))) diff --git a/python-mtheall/Arena.cpp b/python-mtheall/Arena.cpp index f642a15f..67beef2d 100644 --- a/python-mtheall/Arena.cpp +++ b/python-mtheall/Arena.cpp @@ -126,7 +126,7 @@ std::unordered_map buildBoostMapping ( auto const soccarBoostMapping = buildBoostMapping (soccarIndexMapping); auto const hoopsBoostMapping = buildBoostMapping (hoopsIndexMapping); -int getBoostPadIndex (::BoostPad const *pad_, std::unordered_map const &map_) noexcept +int getBoostPadIndex (RocketSim::BoostPad const *pad_, std::unordered_map const &map_) noexcept { auto const it = map_.find (makeKey (pad_->pos.x, pad_->pos.y)); if (it == std::end (map_)) @@ -135,17 +135,17 @@ int getBoostPadIndex (::BoostPad const *pad_, std::unordered_mapsecond; } -std::pair getIndexMapping (::GameMode gameMode_) noexcept +std::pair getIndexMapping (RocketSim::GameMode gameMode_) noexcept { - if (gameMode_ == ::GameMode::HOOPS) + if (gameMode_ == RocketSim::GameMode::HOOPS) return {hoopsIndexMapping.data (), hoopsIndexMapping.size ()}; return {soccarIndexMapping.data (), soccarIndexMapping.size ()}; } -std::unordered_map const &getBoostMapping (::GameMode gameMode_) noexcept +std::unordered_map const &getBoostMapping (RocketSim::GameMode gameMode_) noexcept { - if (gameMode_ == ::GameMode::HOOPS) + if (gameMode_ == RocketSim::GameMode::HOOPS) return hoopsBoostMapping; return soccarBoostMapping; @@ -244,7 +244,7 @@ void assign (RocketSim::Python::PyArrayRef &array_, unsigned col_, btMatrix3x3 c void assign (RocketSim::Python::PyArrayRef &array_, unsigned col_, btRigidBody &rigidBody_, - CarState const *state_ = nullptr) noexcept + RocketSim::CarState const *state_ = nullptr) noexcept { if (state_) { @@ -348,7 +348,8 @@ class Arena::ThreadPool for (auto &arena : arenas_) { auto future = - std::async (std::launch::deferred, &::Arena::Step, arena->arena.get (), ticks_).share (); + std::async (std::launch::deferred, &RocketSim::Arena::Step, arena->arena.get (), ticks_) + .share (); m_jobs.emplace_back (future); futures.emplace_back (future); } @@ -677,10 +678,10 @@ PyObject *Arena::New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) if (!self) return nullptr; - new (&self->arena) std::shared_ptr<::Arena>{}; + new (&self->arena) std::shared_ptr{}; new (&self->threadPool) std::shared_ptr{}; self->cars = new (std::nothrow) std::map>{}; - self->boostPads = new (std::nothrow) std::unordered_map<::BoostPad *, PyRef>{}; + self->boostPads = new (std::nothrow) std::unordered_map>{}; self->boostPadsByIndex = nullptr; self->ballPrediction = nullptr; self->gameEvent = nullptr; @@ -724,8 +725,8 @@ PyObject *Arena::New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) int Arena::Init (Arena *self_, PyObject *args_, PyObject *kwds_) noexcept { - int gameMode = static_cast (::GameMode::SOCCAR); - int memoryWeightMode = static_cast (::ArenaMemWeightMode::HEAVY); + int gameMode = static_cast (RocketSim::GameMode::SOCCAR); + int memoryWeightMode = static_cast (RocketSim::ArenaMemWeightMode::HEAVY); float tickRate = 120.0f; static char gameModeKwd[] = "game_mode"; @@ -739,19 +740,19 @@ int Arena::Init (Arena *self_, PyObject *args_, PyObject *kwds_) noexcept try { - switch (static_cast<::GameMode> (gameMode)) + switch (static_cast (gameMode)) { - case ::GameMode::SOCCAR: - case ::GameMode::HOOPS: - case ::GameMode::SNOWDAY: - self_->gameEvent = new ::GameEventTracker{}; + case RocketSim::GameMode::SOCCAR: + case RocketSim::GameMode::HOOPS: + case RocketSim::GameMode::SNOWDAY: + self_->gameEvent = new RocketSim::GameEventTracker{}; self_->gameEvent->SetShotCallback (&Arena::HandleShotEventCallback, self_); self_->gameEvent->SetGoalCallback (&Arena::HandleGoalEventCallback, self_); self_->gameEvent->SetSaveCallback (&Arena::HandleSaveEventCallback, self_); break; - case ::GameMode::HEATSEEKER: - case ::GameMode::THE_VOID: + case RocketSim::GameMode::HEATSEEKER: + case RocketSim::GameMode::THE_VOID: break; default: @@ -784,14 +785,16 @@ int Arena::Init (Arena *self_, PyObject *args_, PyObject *kwds_) noexcept try { - auto arena = std::shared_ptr<::Arena> (::Arena::Create ( - static_cast<::GameMode> (gameMode), static_cast<::ArenaMemWeightMode> (memoryWeightMode), tickRate)); + auto arena = + std::shared_ptr (RocketSim::Arena::Create (static_cast (gameMode), + static_cast (memoryWeightMode), + tickRate)); if (!arena) throw -1; arena->SetCarBumpCallback (&Arena::HandleCarBumpCallback, self_); - if (arena->gameMode != ::GameMode::THE_VOID) + if (arena->gameMode != RocketSim::GameMode::THE_VOID) { arena->SetBoostPickupCallback (&Arena::HandleBoostPickupCallback, self_); arena->SetGoalScoreCallback (&Arena::HandleGoalScoreCallback, self_); @@ -801,7 +804,7 @@ int Arena::Init (Arena *self_, PyObject *args_, PyObject *kwds_) noexcept if (!ball) throw -1; - auto boostPads = std::unordered_map<::BoostPad *, PyRef>{}; + auto boostPads = std::unordered_map>{}; for (auto const &pad : arena->GetBoostPads ()) { auto ref = PyRef::steal (BoostPad::New ()); @@ -960,7 +963,7 @@ PyObject *Arena::Pickle (Arena *self_) noexcept return nullptr; } - if (self_->arena->gameMode != ::GameMode::SOCCAR && + if (self_->arena->gameMode != RocketSim::GameMode::SOCCAR && !DictSetValue (dict.borrow (), "game_mode", PyLong_FromLong (static_cast (self_->arena->gameMode)))) return nullptr; @@ -1159,8 +1162,8 @@ PyObject *Arena::Unpickle (Arena *self_, PyObject *dict_) noexcept float tickTime = 1.0f / 120.0f; unsigned blueScore = 0; unsigned orangeScore = 0; - int gameMode = static_cast (::GameMode::SOCCAR); - int memoryWeightMode = static_cast (::ArenaMemWeightMode::HEAVY); + int gameMode = static_cast (RocketSim::GameMode::SOCCAR); + int memoryWeightMode = static_cast (RocketSim::ArenaMemWeightMode::HEAVY); if (!PyArg_ParseTupleAndKeywords (dummy.borrow (), dict_, "|iikO!fKO!O!O!IIKKOOOOOOOOOOOOOO", @@ -1200,21 +1203,21 @@ PyObject *Arena::Unpickle (Arena *self_, PyObject *dict_) noexcept &saveEventCallbackUserData)) return nullptr; - switch (static_cast<::GameMode> (gameMode)) + switch (static_cast (gameMode)) { - case ::GameMode::SOCCAR: - case ::GameMode::HOOPS: - case ::GameMode::HEATSEEKER: - case ::GameMode::SNOWDAY: - case ::GameMode::THE_VOID: + case RocketSim::GameMode::SOCCAR: + case RocketSim::GameMode::HOOPS: + case RocketSim::GameMode::HEATSEEKER: + case RocketSim::GameMode::SNOWDAY: + case RocketSim::GameMode::THE_VOID: break; default: return PyErr_Format (PyExc_ValueError, "Invalid game mode '%d'", gameMode); } - if (static_cast<::ArenaMemWeightMode> (memoryWeightMode) != ::ArenaMemWeightMode::LIGHT && - static_cast<::ArenaMemWeightMode> (memoryWeightMode) != ::ArenaMemWeightMode::HEAVY) + if (static_cast (memoryWeightMode) != RocketSim::ArenaMemWeightMode::LIGHT && + static_cast (memoryWeightMode) != RocketSim::ArenaMemWeightMode::HEAVY) return PyErr_Format (PyExc_ValueError, "Invalid arena memory weight mode '%d'", memoryWeightMode); // make sure callback are None or callable @@ -1279,8 +1282,10 @@ PyObject *Arena::Unpickle (Arena *self_, PyObject *dict_) noexcept try { - auto arena = std::shared_ptr<::Arena> (::Arena::Create ( - static_cast<::GameMode> (gameMode), static_cast<::ArenaMemWeightMode> (memoryWeightMode), 1.0f / tickTime)); + auto arena = + std::shared_ptr (RocketSim::Arena::Create (static_cast (gameMode), + static_cast (memoryWeightMode), + 1.0f / tickTime)); if (!arena) return PyErr_NoMemory (); @@ -1311,7 +1316,7 @@ PyObject *Arena::Unpickle (Arena *self_, PyObject *dict_) noexcept carMap[car->car->id] = car; } - auto padMap = std::unordered_map<::BoostPad *, PyRef>{}; + auto padMap = std::unordered_map>{}; if (pads) { auto const &[indexMapping, indexMappingSize] = getIndexMapping (arena->gameMode); @@ -1415,7 +1420,7 @@ PyObject *Arena::Unpickle (Arena *self_, PyObject *dict_) noexcept self_->arena->SetCarBumpCallback (&Arena::HandleCarBumpCallback, self_); - if (self_->arena->gameMode != ::GameMode::THE_VOID) + if (self_->arena->gameMode != RocketSim::GameMode::THE_VOID) { self_->arena->SetBoostPickupCallback (&Arena::HandleBoostPickupCallback, self_); self_->arena->SetGoalScoreCallback (&Arena::HandleGoalScoreCallback, self_); @@ -1463,13 +1468,13 @@ PyObject *Arena::AddCar (Arena *self_, PyObject *args_, PyObject *kwds_) noexcep if (!PyArg_ParseTupleAndKeywords (args_, kwds_, "i|O", dict, &team, &config)) return nullptr; - if (team != static_cast (::Team::BLUE) && team != static_cast (::Team::ORANGE)) + if (team != static_cast (RocketSim::Team::BLUE) && team != static_cast (RocketSim::Team::ORANGE)) { PyErr_SetString (PyExc_RuntimeError, "Invalid team"); return nullptr; } - ::CarConfig carConfig = CAR_CONFIG_OCTANE; + RocketSim::CarConfig carConfig = CAR_CONFIG_OCTANE; if (config && Py_IS_TYPE (config, CarConfig::Type)) { carConfig = reinterpret_cast (config)->config; @@ -1488,11 +1493,11 @@ PyObject *Arena::AddCar (Arena *self_, PyObject *args_, PyObject *kwds_) noexcep if (!car) return nullptr; - ::Car *rsCar = nullptr; + RocketSim::Car *rsCar = nullptr; try { - rsCar = self_->arena->AddCar (static_cast<::Team> (team), carConfig); + rsCar = self_->arena->AddCar (static_cast (team), carConfig); auto &carRef = (*self_->cars)[rsCar->id]; if (carRef) // this probably shouldn't happen @@ -1530,7 +1535,7 @@ PyObject *Arena::Clone (Arena *self_, PyObject *args_, PyObject *kwds_) noexcept try { - auto arena = std::shared_ptr<::Arena> (self_->arena->Clone (false)); + auto arena = std::shared_ptr (self_->arena->Clone (false)); if (!arena) return PyErr_NoMemory (); @@ -1538,7 +1543,7 @@ PyObject *Arena::Clone (Arena *self_, PyObject *args_, PyObject *kwds_) noexcept if (!ball) return PyErr_NoMemory (); - auto boostPads = std::unordered_map<::BoostPad *, PyRef>{}; + auto boostPads = std::unordered_map>{}; for (auto const &pad : arena->GetBoostPads ()) { auto ref = PyRef::steal (BoostPad::New ()); @@ -1636,7 +1641,7 @@ PyObject *Arena::Clone (Arena *self_, PyObject *args_, PyObject *kwds_) noexcept clone->arena->SetCarBumpCallback (&Arena::HandleCarBumpCallback, clone.borrow ()); - if (clone->arena->gameMode != ::GameMode::THE_VOID) + if (clone->arena->gameMode != RocketSim::GameMode::THE_VOID) { clone->arena->SetBoostPickupCallback (&Arena::HandleBoostPickupCallback, clone.borrow ()); clone->arena->SetGoalScoreCallback (&Arena::HandleGoalScoreCallback, clone.borrow ()); @@ -1805,7 +1810,7 @@ PyObject *Arena::CloneInto (Arena *self_, PyObject *args_, PyObject *kwds_) noex target->arena->SetCarBumpCallback (&Arena::HandleCarBumpCallback, target); - if (target->arena->gameMode != ::GameMode::THE_VOID) + if (target->arena->gameMode != RocketSim::GameMode::THE_VOID) { target->arena->SetBoostPickupCallback (&Arena::HandleBoostPickupCallback, target); target->arena->SetGoalScoreCallback (&Arena::HandleGoalScoreCallback, target); @@ -1883,7 +1888,7 @@ PyObject *Arena::GetBallPrediction (Arena *self_, PyObject *args_, PyObject *kwd { try { - self_->ballPrediction = new (std::nothrow)::BallPredTracker (self_->arena.get (), numTicks); + self_->ballPrediction = new (std::nothrow) RocketSim::BallPredTracker (self_->arena.get (), numTicks); if (!self_->ballPrediction) { PyErr_NoMemory (); @@ -2206,7 +2211,7 @@ PyObject *Arena::SetBallTouchCallback (Arena *self_, PyObject *args_, PyObject * PyObject *Arena::SetBoostPickupCallback (Arena *self_, PyObject *args_, PyObject *kwds_) noexcept { - if (self_->arena->gameMode == ::GameMode::THE_VOID) + if (self_->arena->gameMode == RocketSim::GameMode::THE_VOID) { PyErr_SetString (PyExc_RuntimeError, "Cannot set a boost pickup callback when on THE_VOID gamemode!"); return nullptr; @@ -2326,7 +2331,7 @@ PyObject *Arena::SetCarDemoCallback (Arena *self_, PyObject *args_, PyObject *kw PyObject *Arena::SetGoalScoreCallback (Arena *self_, PyObject *args_, PyObject *kwds_) noexcept { - if (self_->arena->gameMode == ::GameMode::THE_VOID) + if (self_->arena->gameMode == RocketSim::GameMode::THE_VOID) { PyErr_SetString (PyExc_RuntimeError, "Cannot set a goal score callback when on THE_VOID gamemode!"); return nullptr; @@ -2597,7 +2602,7 @@ PyObject *Arena::MultiStep (PyObject *dummy_, PyObject *args_, PyObject *kwds_) return nullptr; } -void Arena::HandleBallTouchCallback (::Arena *arena_, ::Car *car_, void *userData_) noexcept +void Arena::HandleBallTouchCallback (RocketSim::Arena *arena_, RocketSim::Car *car_, void *userData_) noexcept { auto const self = reinterpret_cast (userData_); if (self->stepExceptionType) @@ -2646,7 +2651,10 @@ void Arena::HandleBallTouchCallback (::Arena *arena_, ::Car *car_, void *userDat } } -void Arena::HandleBoostPickupCallback (::Arena *arena_, ::Car *car_, ::BoostPad *boostPad_, void *userData_) noexcept +void Arena::HandleBoostPickupCallback (RocketSim::Arena *arena_, + RocketSim::Car *car_, + RocketSim::BoostPad *boostPad_, + void *userData_) noexcept { auto const self = reinterpret_cast (userData_); if (self->stepExceptionType) @@ -2721,9 +2729,9 @@ void Arena::HandleBoostPickupCallback (::Arena *arena_, ::Car *car_, ::BoostPad } } -void Arena::HandleCarBumpCallback (::Arena *arena_, - ::Car *bumper_, - ::Car *victim_, +void Arena::HandleCarBumpCallback (RocketSim::Arena *arena_, + RocketSim::Car *bumper_, + RocketSim::Car *victim_, bool isDemo_, void *userData_) noexcept { @@ -2840,7 +2848,7 @@ void Arena::HandleCarBumpCallback (::Arena *arena_, } } -void Arena::HandleGoalScoreCallback (::Arena *arena_, ::Team scoringTeam_, void *userData_) noexcept +void Arena::HandleGoalScoreCallback (RocketSim::Arena *arena_, RocketSim::Team scoringTeam_, void *userData_) noexcept { auto const self = reinterpret_cast (userData_); if (self->stepExceptionType) @@ -2849,7 +2857,7 @@ void Arena::HandleGoalScoreCallback (::Arena *arena_, ::Team scoringTeam_, void // avoid continuously counting goals until the ball exits goal zone if (self->lastGoalTick + 1 != self->arena->tickCount) { - if (scoringTeam_ == ::Team::BLUE) + if (scoringTeam_ == RocketSim::Team::BLUE) ++self->blueScore; else ++self->orangeScore; @@ -2886,7 +2894,10 @@ void Arena::HandleGoalScoreCallback (::Arena *arena_, ::Team scoringTeam_, void } } -void Arena::HandleShotEventCallback (::Arena *arena_, ::Car *shooter_, ::Car *passer_, void *userData_) noexcept +void Arena::HandleShotEventCallback (RocketSim::Arena *arena_, + RocketSim::Car *shooter_, + RocketSim::Car *passer_, + void *userData_) noexcept { auto const self = reinterpret_cast (userData_); if (self->stepExceptionType) @@ -2954,7 +2965,10 @@ void Arena::HandleShotEventCallback (::Arena *arena_, ::Car *shooter_, ::Car *pa } } -void Arena::HandleGoalEventCallback (::Arena *arena_, ::Car *shooter_, ::Car *passer_, void *userData_) noexcept +void Arena::HandleGoalEventCallback (RocketSim::Arena *arena_, + RocketSim::Car *shooter_, + RocketSim::Car *passer_, + void *userData_) noexcept { auto const self = reinterpret_cast (userData_); if (self->stepExceptionType) @@ -3023,7 +3037,7 @@ void Arena::HandleGoalEventCallback (::Arena *arena_, ::Car *shooter_, ::Car *pa } } -void Arena::HandleSaveEventCallback (::Arena *arena_, ::Car *saver_, void *userData_) noexcept +void Arena::HandleSaveEventCallback (RocketSim::Arena *arena_, RocketSim::Car *saver_, void *userData_) noexcept { auto const self = reinterpret_cast (userData_); if (self->stepExceptionType) diff --git a/python-mtheall/Ball.cpp b/python-mtheall/Ball.cpp index 90157a51..40797a16 100644 --- a/python-mtheall/Ball.cpp +++ b/python-mtheall/Ball.cpp @@ -53,7 +53,7 @@ Ball *Ball::New () noexcept if (!self) return nullptr; - new (&self->arena) std::shared_ptr<::Arena>{}; + new (&self->arena) std::shared_ptr{}; self->ball = nullptr; return self.gift (); diff --git a/python-mtheall/BallHitInfo.cpp b/python-mtheall/BallHitInfo.cpp index 2cd5aa06..238d8f4e 100644 --- a/python-mtheall/BallHitInfo.cpp +++ b/python-mtheall/BallHitInfo.cpp @@ -9,18 +9,18 @@ PyTypeObject *BallHitInfo::Type = nullptr; PyMemberDef BallHitInfo::Members[] = { {.name = "is_valid", - .type = TypeHelper::type, - .offset = offsetof (BallHitInfo, info) + offsetof (::BallHitInfo, isValid), + .type = TypeHelper::type, + .offset = offsetof (BallHitInfo, info) + offsetof (RocketSim::BallHitInfo, isValid), .flags = 0, .doc = "Is valid"}, {.name = "tick_count_when_hit", - .type = TypeHelper::type, - .offset = offsetof (BallHitInfo, info) + offsetof (::BallHitInfo, tickCountWhenHit), + .type = TypeHelper::type, + .offset = offsetof (BallHitInfo, info) + offsetof (RocketSim::BallHitInfo, tickCountWhenHit), .flags = 0, .doc = "Tick count when hit"}, {.name = "tick_count_when_extra_impulse_applied", - .type = TypeHelper::type, - .offset = offsetof (BallHitInfo, info) + offsetof (::BallHitInfo, tickCountWhenExtraImpulseApplied), + .type = TypeHelper::type, + .offset = offsetof (BallHitInfo, info) + offsetof (RocketSim::BallHitInfo, tickCountWhenExtraImpulseApplied), .flags = 0, .doc = "Tick count when extra impulse applied"}, {.name = nullptr, .type = 0, .offset = 0, .flags = 0, .doc = nullptr}, @@ -78,7 +78,7 @@ PyType_Spec BallHitInfo::Spec = { .slots = BallHitInfo::Slots, }; -PyRef BallHitInfo::NewFromBallHitInfo (::BallHitInfo const &info_) noexcept +PyRef BallHitInfo::NewFromBallHitInfo (RocketSim::BallHitInfo const &info_) noexcept { auto const self = PyRef::stealObject (BallHitInfo::New (BallHitInfo::Type, nullptr, nullptr)); if (!self || !InitFromBallHitInfo (self.borrow (), info_)) @@ -87,7 +87,7 @@ PyRef BallHitInfo::NewFromBallHitInfo (::BallHitInfo const &info_) return self; } -bool BallHitInfo::InitFromBallHitInfo (BallHitInfo *const self_, ::BallHitInfo const &info_) noexcept +bool BallHitInfo::InitFromBallHitInfo (BallHitInfo *const self_, RocketSim::BallHitInfo const &info_) noexcept { auto relativePosOnBall = Vec::NewFromVec (info_.relativePosOnBall); auto ballPos = Vec::NewFromVec (info_.ballPos); @@ -105,7 +105,7 @@ bool BallHitInfo::InitFromBallHitInfo (BallHitInfo *const self_, ::BallHitInfo c return true; } -::BallHitInfo BallHitInfo::ToBallHitInfo (BallHitInfo *self_) noexcept +RocketSim::BallHitInfo BallHitInfo::ToBallHitInfo (BallHitInfo *self_) noexcept { auto info = self_->info; @@ -124,7 +124,7 @@ PyObject *BallHitInfo::New (PyTypeObject *subtype_, PyObject *args_, PyObject *k if (!self) return nullptr; - new (&self->info)::BallHitInfo (); + new (&self->info) RocketSim::BallHitInfo (); self->relativePosOnBall = nullptr; self->ballPos = nullptr; @@ -150,7 +150,7 @@ int BallHitInfo::Init (BallHitInfo *self_, PyObject *args_, PyObject *kwds_) noe tickCountWhenExtraImpulseAppliedKwd, nullptr}; - ::BallHitInfo info{}; + RocketSim::BallHitInfo info{}; int isValid = info.isValid; PyObject *relativePosOnBall = nullptr; @@ -210,7 +210,7 @@ PyObject *BallHitInfo::Pickle (BallHitInfo *self_) noexcept if (!dict) return nullptr; - ::BallHitInfo const model{}; + RocketSim::BallHitInfo const model{}; auto const info = ToBallHitInfo (self_); if (info.isValid != model.isValid && !DictSetValue (dict.borrow (), "is_valid", PyBool_FromLong (info.isValid))) diff --git a/python-mtheall/BallState.cpp b/python-mtheall/BallState.cpp index 21548f88..e9f517d2 100644 --- a/python-mtheall/BallState.cpp +++ b/python-mtheall/BallState.cpp @@ -9,31 +9,31 @@ PyTypeObject *BallState::Type = nullptr; PyMemberDef BallState::Members[] = { {.name = "update_counter", - .type = TypeHelper::type, - .offset = offsetof (BallState, state) + offsetof (::BallState, updateCounter), + .type = TypeHelper::type, + .offset = offsetof (BallState, state) + offsetof (RocketSim::BallState, updateCounter), .flags = 0, .doc = "Update counter (ticks since last state set)"}, {.name = "last_hit_car_id", - .type = TypeHelper::type, - .offset = offsetof (BallState, state) + offsetof (::BallState, lastHitCarID), + .type = TypeHelper::type, + .offset = offsetof (BallState, state) + offsetof (RocketSim::BallState, lastHitCarID), .flags = 0, .doc = "Last hit car id"}, {.name = "heatseeker_target_dir", - .type = TypeHelper::type, - .offset = offsetof (BallState, state) + offsetof (::BallState, hsInfo) + - offsetof (::BallState::HeatseekerInfo, yTargetDir), + .type = TypeHelper::type, + .offset = offsetof (BallState, state) + offsetof (RocketSim::BallState, hsInfo) + + offsetof (RocketSim::BallState::HeatseekerInfo, yTargetDir), .flags = 0, .doc = "Heatseeker target direction"}, {.name = "heatseeker_target_speed", - .type = TypeHelper::type, - .offset = offsetof (BallState, state) + offsetof (::BallState, hsInfo) + - offsetof (::BallState::HeatseekerInfo, curTargetSpeed), + .type = TypeHelper::type, + .offset = offsetof (BallState, state) + offsetof (RocketSim::BallState, hsInfo) + + offsetof (RocketSim::BallState::HeatseekerInfo, curTargetSpeed), .flags = 0, .doc = "Heatseeker target speed"}, {.name = "heatseeker_time_since_hit", - .type = TypeHelper::type, - .offset = offsetof (BallState, state) + offsetof (::BallState, hsInfo) + - offsetof (::BallState::HeatseekerInfo, timeSinceHit), + .type = TypeHelper::type, + .offset = offsetof (BallState, state) + offsetof (RocketSim::BallState, hsInfo) + + offsetof (RocketSim::BallState::HeatseekerInfo, timeSinceHit), .flags = 0, .doc = "Heatseeker time since hit"}, {.name = nullptr, .type = 0, .offset = 0, .flags = 0, .doc = nullptr}, @@ -92,7 +92,7 @@ PyType_Spec BallState::Spec = { .slots = BallState::Slots, }; -PyRef BallState::NewFromBallState (::BallState const &state_) noexcept +PyRef BallState::NewFromBallState (RocketSim::BallState const &state_) noexcept { auto const self = PyRef::stealObject (BallState::New (BallState::Type, nullptr, nullptr)); if (!self || !InitFromBallState (self.borrow (), state_)) @@ -101,7 +101,7 @@ PyRef BallState::NewFromBallState (::BallState const &state_) noexcep return self; } -bool BallState::InitFromBallState (BallState *const self_, ::BallState const &state_) noexcept +bool BallState::InitFromBallState (BallState *const self_, RocketSim::BallState const &state_) noexcept { auto pos = Vec::NewFromVec (state_.pos); auto rotMat = RotMat::NewFromRotMat (state_.rotMat); @@ -121,7 +121,7 @@ bool BallState::InitFromBallState (BallState *const self_, ::BallState const &st return true; } -::BallState BallState::ToBallState (BallState *self_) noexcept +RocketSim::BallState BallState::ToBallState (BallState *self_) noexcept { auto state = self_->state; @@ -141,7 +141,7 @@ PyObject *BallState::New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwd if (!self) return nullptr; - new (&self->state)::BallState{}; + new (&self->state) RocketSim::BallState{}; self->pos = nullptr; self->rotMat = nullptr; @@ -174,7 +174,7 @@ int BallState::Init (BallState *self_, PyObject *args_, PyObject *kwds_) noexcep updateCounterKwd, nullptr}; - ::BallState state{}; + RocketSim::BallState state{}; PyObject *pos = nullptr; // borrowed references PyObject *rotMat = nullptr; // borrowed references @@ -240,7 +240,7 @@ PyObject *BallState::Pickle (BallState *self_) noexcept if (!dict) return nullptr; - ::BallState const model{}; + RocketSim::BallState const model{}; auto const state = ToBallState (self_); if (state.updateCounter != model.updateCounter && diff --git a/python-mtheall/BoostPad.cpp b/python-mtheall/BoostPad.cpp index e4cc1eac..96e01021 100644 --- a/python-mtheall/BoostPad.cpp +++ b/python-mtheall/BoostPad.cpp @@ -62,7 +62,7 @@ BoostPad *BoostPad::New () noexcept if (!self) return nullptr; - new (&self->arena) std::shared_ptr<::Arena>{}; + new (&self->arena) std::shared_ptr{}; self->pad = nullptr; return self.gift (); diff --git a/python-mtheall/BoostPadState.cpp b/python-mtheall/BoostPadState.cpp index 3d802852..e7a26880 100644 --- a/python-mtheall/BoostPadState.cpp +++ b/python-mtheall/BoostPadState.cpp @@ -9,18 +9,18 @@ PyTypeObject *BoostPadState::Type = nullptr; PyMemberDef BoostPadState::Members[] = { {.name = "is_active", - .type = TypeHelper::type, - .offset = offsetof (BoostPadState, state) + offsetof (::BoostPadState, isActive), + .type = TypeHelper::type, + .offset = offsetof (BoostPadState, state) + offsetof (RocketSim::BoostPadState, isActive), .flags = 0, .doc = "Is active"}, {.name = "cooldown", - .type = TypeHelper::type, - .offset = offsetof (BoostPadState, state) + offsetof (::BoostPadState, cooldown), + .type = TypeHelper::type, + .offset = offsetof (BoostPadState, state) + offsetof (RocketSim::BoostPadState, cooldown), .flags = 0, .doc = "Cooldown"}, {.name = "prev_locked_car_id", - .type = TypeHelper::type, - .offset = offsetof (BoostPadState, state) + offsetof (::BoostPadState, prevLockedCarID), + .type = TypeHelper::type, + .offset = offsetof (BoostPadState, state) + offsetof (RocketSim::BoostPadState, prevLockedCarID), .flags = 0, .doc = "Prev locked car id"}, {.name = nullptr, .type = 0, .offset = 0, .flags = 0, .doc = nullptr}, @@ -65,7 +65,7 @@ PyType_Spec BoostPadState::Spec = { .slots = BoostPadState::Slots, }; -PyRef BoostPadState::NewFromBoostPadState (::BoostPadState const &state_) noexcept +PyRef BoostPadState::NewFromBoostPadState (RocketSim::BoostPadState const &state_) noexcept { auto const self = PyRef::stealObject (BoostPadState::New (BoostPadState::Type, nullptr, nullptr)); if (!self || !InitFromBoostPadState (self.borrow (), state_)) @@ -74,13 +74,13 @@ PyRef BoostPadState::NewFromBoostPadState (::BoostPadState const return self; } -bool BoostPadState::InitFromBoostPadState (BoostPadState *self_, ::BoostPadState const &state_) noexcept +bool BoostPadState::InitFromBoostPadState (BoostPadState *self_, RocketSim::BoostPadState const &state_) noexcept { self_->state = state_; return true; } -::BoostPadState BoostPadState::ToBoostPadState (BoostPadState *self_) noexcept +RocketSim::BoostPadState BoostPadState::ToBoostPadState (BoostPadState *self_) noexcept { return self_->state; } @@ -93,7 +93,7 @@ PyObject *BoostPadState::New (PyTypeObject *subtype_, PyObject *args_, PyObject if (!self) return nullptr; - new (&self->state)::BoostPadState; + new (&self->state) RocketSim::BoostPadState; return self.giftObject (); } @@ -106,7 +106,7 @@ int BoostPadState::Init (BoostPadState *self_, PyObject *args_, PyObject *kwds_) static char *dict[] = {isActiveKwd, cooldownKwd, prevLockedCarIDKwd, nullptr}; - ::BoostPadState state{}; + RocketSim::BoostPadState state{}; int isActive = state.isActive; unsigned long prevLockedCarID = state.prevLockedCarID; @@ -136,7 +136,7 @@ PyObject *BoostPadState::Pickle (BoostPadState *self_) noexcept if (!dict) return nullptr; - ::BoostPadState model{}; + RocketSim::BoostPadState model{}; auto const state = ToBoostPadState (self_); if (state.isActive != model.isActive && diff --git a/python-mtheall/Car.cpp b/python-mtheall/Car.cpp index 405e87c0..909ee1f0 100644 --- a/python-mtheall/Car.cpp +++ b/python-mtheall/Car.cpp @@ -122,7 +122,7 @@ Car *Car::New () noexcept if (!self) return nullptr; - new (&self->arena) std::shared_ptr<::Arena>{}; + new (&self->arena) std::shared_ptr{}; self->car = nullptr; self->goals = 0; @@ -162,7 +162,7 @@ PyObject *Car::InternalPickle (Car *self_) noexcept dict.borrow (), "controls", CarControls::NewFromCarControls (self_->car->controls).giftObject ())) return nullptr; - if (self_->car->team != ::Team::BLUE && + if (self_->car->team != RocketSim::Team::BLUE && !DictSetValue (dict.borrow (), "team", PyLong_FromLong (static_cast (self_->car->team)))) return nullptr; @@ -188,7 +188,7 @@ PyObject *Car::InternalPickle (Car *self_) noexcept return dict.gift (); } -PyObject *Car::InternalUnpickle (std::shared_ptr<::Arena> arena_, Car *self_, PyObject *dict_) noexcept +PyObject *Car::InternalUnpickle (std::shared_ptr arena_, Car *self_, PyObject *dict_) noexcept { auto const dummy = PyObjectRef::steal (PyTuple_New (0)); if (!dummy) @@ -229,7 +229,7 @@ PyObject *Car::InternalUnpickle (std::shared_ptr<::Arena> arena_, Car *self_, Py unsigned shots = 0; unsigned saves = 0; unsigned assists = 0; - int team = static_cast (::Team::BLUE); + int team = static_cast (RocketSim::Team::BLUE); if (!PyArg_ParseTupleAndKeywords (dummy.borrow (), dict_, "|kiO!O!O!IIIIII", @@ -256,7 +256,8 @@ PyObject *Car::InternalUnpickle (std::shared_ptr<::Arena> arena_, Car *self_, Py if (arena_->_carIDMap.contains (id)) return PyErr_Format (PyExc_ValueError, "Car with id '%lu' already exists", id); - if (static_cast<::Team> (team) != ::Team::BLUE && static_cast<::Team> (team) != ::Team::ORANGE) + if (static_cast (team) != RocketSim::Team::BLUE && + static_cast (team) != RocketSim::Team::ORANGE) return PyErr_Format (PyExc_ValueError, "Invalid team '%d'", team); if (!state) @@ -279,7 +280,8 @@ PyObject *Car::InternalUnpickle (std::shared_ptr<::Arena> arena_, Car *self_, Py arena_->_lastCarID = id - 1; - self_->car = arena_->AddCar (static_cast<::Team> (team), CarConfig::ToCarConfig (PyCast (config))); + self_->car = + arena_->AddCar (static_cast (team), CarConfig::ToCarConfig (PyCast (config))); self_->arena = arena_; self_->goals = goals; diff --git a/python-mtheall/CarConfig.cpp b/python-mtheall/CarConfig.cpp index 4895509d..bdb76bc3 100644 --- a/python-mtheall/CarConfig.cpp +++ b/python-mtheall/CarConfig.cpp @@ -6,7 +6,7 @@ namespace { -unsigned templateDiff (::CarConfig const &config_, ::CarConfig const &model_) noexcept +unsigned templateDiff (RocketSim::CarConfig const &config_, RocketSim::CarConfig const &model_) noexcept { unsigned diff = 0; @@ -40,7 +40,7 @@ unsigned templateDiff (::CarConfig const &config_, ::CarConfig const &model_) no return diff; } -RocketSim::Python::CarConfig::Index bestTemplateConfig (::CarConfig const &config_) noexcept +RocketSim::Python::CarConfig::Index bestTemplateConfig (RocketSim::CarConfig const &config_) noexcept { using RocketSim::Python::CarConfig; @@ -49,12 +49,12 @@ RocketSim::Python::CarConfig::Index bestTemplateConfig (::CarConfig const &confi for (auto const &[index, model] : { // clang-format off - std::make_pair (CarConfig::Index::OCTANE, &CAR_CONFIG_OCTANE), - std::make_pair (CarConfig::Index::DOMINUS, &CAR_CONFIG_DOMINUS), - std::make_pair (CarConfig::Index::PLANK, &CAR_CONFIG_PLANK), - std::make_pair (CarConfig::Index::BREAKOUT, &CAR_CONFIG_BREAKOUT), - std::make_pair (CarConfig::Index::HYBRID, &CAR_CONFIG_HYBRID), - std::make_pair (CarConfig::Index::MERC, &CAR_CONFIG_MERC) + std::make_pair (CarConfig::Index::OCTANE, &RocketSim::CAR_CONFIG_OCTANE), + std::make_pair (CarConfig::Index::DOMINUS, &RocketSim::CAR_CONFIG_DOMINUS), + std::make_pair (CarConfig::Index::PLANK, &RocketSim::CAR_CONFIG_PLANK), + std::make_pair (CarConfig::Index::BREAKOUT, &RocketSim::CAR_CONFIG_BREAKOUT), + std::make_pair (CarConfig::Index::HYBRID, &RocketSim::CAR_CONFIG_HYBRID), + std::make_pair (CarConfig::Index::MERC, &RocketSim::CAR_CONFIG_MERC) // clang-format on }) { @@ -79,8 +79,8 @@ PyTypeObject *CarConfig::Type = nullptr; PyMemberDef CarConfig::Members[] = { {.name = "dodge_deadzone", - .type = TypeHelper::type, - .offset = offsetof (CarConfig, config) + offsetof (::CarConfig, dodgeDeadzone), + .type = TypeHelper::type, + .offset = offsetof (CarConfig, config) + offsetof (RocketSim::CarConfig, dodgeDeadzone), .flags = 0, .doc = "Dodge deadzone"}, {.name = nullptr, .type = 0, .offset = 0, .flags = 0, .doc = nullptr}, @@ -136,7 +136,7 @@ PyType_Spec CarConfig::Spec = { .slots = CarConfig::Slots, }; -bool CarConfig::FromIndex (Index index_, ::CarConfig &config_) noexcept +bool CarConfig::FromIndex (Index index_, RocketSim::CarConfig &config_) noexcept { switch (index_) { @@ -169,7 +169,7 @@ bool CarConfig::FromIndex (Index index_, ::CarConfig &config_) noexcept return false; } -PyRef CarConfig::NewFromCarConfig (::CarConfig const &config_) noexcept +PyRef CarConfig::NewFromCarConfig (RocketSim::CarConfig const &config_) noexcept { auto const self = PyRef::stealObject (CarConfig::New (CarConfig::Type, nullptr, nullptr)); if (!self || !InitFromCarConfig (self.borrow (), config_)) @@ -178,7 +178,7 @@ PyRef CarConfig::NewFromCarConfig (::CarConfig const &config_) noexce return self; } -bool CarConfig::InitFromCarConfig (CarConfig *const self_, ::CarConfig const &config_) noexcept +bool CarConfig::InitFromCarConfig (CarConfig *const self_, RocketSim::CarConfig const &config_) noexcept { auto hitboxSize = Vec::NewFromVec (config_.hitboxSize); auto hitboxPosOffset = Vec::NewFromVec (config_.hitboxPosOffset); @@ -198,7 +198,7 @@ bool CarConfig::InitFromCarConfig (CarConfig *const self_, ::CarConfig const &co return true; } -::CarConfig CarConfig::ToCarConfig (CarConfig *self_) noexcept +RocketSim::CarConfig CarConfig::ToCarConfig (CarConfig *self_) noexcept { auto config = self_->config; @@ -218,7 +218,7 @@ PyObject *CarConfig::New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwd if (!self) return nullptr; - new (&self->config)::CarConfig (); + new (&self->config) RocketSim::CarConfig (); self->hitboxSize = nullptr; self->hitboxPosOffset = nullptr; @@ -263,7 +263,7 @@ int CarConfig::Init (CarConfig *self_, PyObject *args_, PyObject *kwds_) noexcep return -1; // initialize with template - ::CarConfig config{}; + RocketSim::CarConfig config{}; if (!FromIndex (static_cast (templateId), config)) return -1; @@ -310,7 +310,7 @@ PyObject *CarConfig::Pickle (CarConfig *self_) noexcept if (!DictSetValue (dict.borrow (), "template", PyLong_FromLong (static_cast (index)))) return nullptr; - ::CarConfig model{}; + RocketSim::CarConfig model{}; if (!FromIndex (index, model)) return nullptr; diff --git a/python-mtheall/CarControls.cpp b/python-mtheall/CarControls.cpp index 5f6b8ac4..d6741414 100644 --- a/python-mtheall/CarControls.cpp +++ b/python-mtheall/CarControls.cpp @@ -6,43 +6,43 @@ PyTypeObject *CarControls::Type = nullptr; PyMemberDef CarControls::Members[] = { {.name = "throttle", - .type = TypeHelper::type, - .offset = offsetof (CarControls, controls) + offsetof (::CarControls, throttle), + .type = TypeHelper::type, + .offset = offsetof (CarControls, controls) + offsetof (RocketSim::CarControls, throttle), .flags = 0, .doc = "Throttle"}, {.name = "steer", - .type = TypeHelper::type, - .offset = offsetof (CarControls, controls) + offsetof (::CarControls, steer), + .type = TypeHelper::type, + .offset = offsetof (CarControls, controls) + offsetof (RocketSim::CarControls, steer), .flags = 0, .doc = "Steer"}, {.name = "pitch", - .type = TypeHelper::type, - .offset = offsetof (CarControls, controls) + offsetof (::CarControls, pitch), + .type = TypeHelper::type, + .offset = offsetof (CarControls, controls) + offsetof (RocketSim::CarControls, pitch), .flags = 0, .doc = "Pitch"}, {.name = "yaw", - .type = TypeHelper::type, - .offset = offsetof (CarControls, controls) + offsetof (::CarControls, yaw), + .type = TypeHelper::type, + .offset = offsetof (CarControls, controls) + offsetof (RocketSim::CarControls, yaw), .flags = 0, .doc = "Yaw"}, {.name = "roll", - .type = TypeHelper::type, - .offset = offsetof (CarControls, controls) + offsetof (::CarControls, roll), + .type = TypeHelper::type, + .offset = offsetof (CarControls, controls) + offsetof (RocketSim::CarControls, roll), .flags = 0, .doc = "Roll"}, {.name = "boost", - .type = TypeHelper::type, - .offset = offsetof (CarControls, controls) + offsetof (::CarControls, boost), + .type = TypeHelper::type, + .offset = offsetof (CarControls, controls) + offsetof (RocketSim::CarControls, boost), .flags = 0, .doc = "Boost"}, {.name = "jump", - .type = TypeHelper::type, - .offset = offsetof (CarControls, controls) + offsetof (::CarControls, jump), + .type = TypeHelper::type, + .offset = offsetof (CarControls, controls) + offsetof (RocketSim::CarControls, jump), .flags = 0, .doc = "Jump"}, {.name = "handbrake", - .type = TypeHelper::type, - .offset = offsetof (CarControls, controls) + offsetof (::CarControls, handbrake), + .type = TypeHelper::type, + .offset = offsetof (CarControls, controls) + offsetof (RocketSim::CarControls, handbrake), .flags = 0, .doc = "Handbrake"}, {.name = nullptr, .type = 0, .offset = 0, .flags = 0, .doc = nullptr}, @@ -88,7 +88,7 @@ PyType_Spec CarControls::Spec = { .slots = CarControls::Slots, }; -PyRef CarControls::NewFromCarControls (::CarControls const &controls_) noexcept +PyRef CarControls::NewFromCarControls (RocketSim::CarControls const &controls_) noexcept { auto const self = PyRef::stealObject (CarControls::New (CarControls::Type, nullptr, nullptr)); if (!self || !InitFromCarControls (self.borrow (), controls_)) @@ -97,13 +97,13 @@ PyRef CarControls::NewFromCarControls (::CarControls const &control return self; } -bool CarControls::InitFromCarControls (CarControls *const self_, ::CarControls const &controls_) noexcept +bool CarControls::InitFromCarControls (CarControls *const self_, RocketSim::CarControls const &controls_) noexcept { self_->controls = controls_; return true; } -::CarControls CarControls::ToCarControls (CarControls *self_) noexcept +RocketSim::CarControls CarControls::ToCarControls (CarControls *self_) noexcept { return self_->controls; } @@ -116,7 +116,7 @@ PyObject *CarControls::New (PyTypeObject *subtype_, PyObject *args_, PyObject *k if (!self) return nullptr; - new (&self->controls)::CarControls{}; + new (&self->controls) RocketSim::CarControls{}; return self.giftObject (); } @@ -136,7 +136,7 @@ int CarControls::Init (CarControls *self_, PyObject *args_, PyObject *kwds_) noe static char *dict[] = { throttleKwd, steerKwd, pitchKwd, yawKwd, rollKwd, boostKwd, jumpKwd, handbrakeKwd, useItemKwd, nullptr}; - ::CarControls controls{}; + RocketSim::CarControls controls{}; int boost = controls.boost; int jump = controls.jump; int handbrake = controls.handbrake; @@ -180,7 +180,7 @@ PyObject *CarControls::Pickle (CarControls *self_) noexcept if (!dict) return nullptr; - ::CarControls const model{}; + RocketSim::CarControls const model{}; auto const controls = ToCarControls (self_); if (controls.throttle != model.throttle && diff --git a/python-mtheall/CarState.cpp b/python-mtheall/CarState.cpp index 875d895f..22a89878 100644 --- a/python-mtheall/CarState.cpp +++ b/python-mtheall/CarState.cpp @@ -9,118 +9,118 @@ PyTypeObject *CarState::Type = nullptr; PyMemberDef CarState::Members[] = { {.name = "update_counter", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, updateCounter), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, updateCounter), .flags = 0, .doc = "Update counter (ticks since last state set)"}, {.name = "is_on_ground", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, isOnGround), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, isOnGround), .flags = 0, .doc = "Is on ground"}, {.name = "has_jumped", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, hasJumped), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, hasJumped), .flags = 0, .doc = "Has jumped"}, {.name = "has_double_jumped", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, hasDoubleJumped), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, hasDoubleJumped), .flags = 0, .doc = "Has double jumped"}, {.name = "has_flipped", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, hasFlipped), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, hasFlipped), .flags = 0, .doc = "Has flipped"}, {.name = "jump_time", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, jumpTime), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, jumpTime), .flags = 0, .doc = "Jump time"}, {.name = "flip_time", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, flipTime), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, flipTime), .flags = 0, .doc = "Flip time"}, {.name = "is_flipping", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, isFlipping), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, isFlipping), .flags = 0, .doc = "Is flipping"}, {.name = "is_jumping", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, isJumping), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, isJumping), .flags = 0, .doc = "Is jumping"}, {.name = "air_time_since_jump", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, airTimeSinceJump), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, airTimeSinceJump), .flags = 0, .doc = "Air time since jump"}, {.name = "boost", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, boost), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, boost), .flags = 0, .doc = "Boost"}, {.name = "time_spent_boosting", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, timeSpentBoosting), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, timeSpentBoosting), .flags = 0, .doc = "Time spent boosting"}, {.name = "is_supersonic", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, isSupersonic), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, isSupersonic), .flags = 0, .doc = "Is supersonic"}, {.name = "supersonic_time", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, supersonicTime), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, supersonicTime), .flags = 0, .doc = "Supersonic time"}, {.name = "handbrake_val", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, handbrakeVal), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, handbrakeVal), .flags = 0, .doc = "Handbrake val"}, {.name = "is_auto_flipping", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, isAutoFlipping), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, isAutoFlipping), .flags = 0, .doc = "Is auto flipping"}, {.name = "auto_flip_timer", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, autoFlipTimer), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, autoFlipTimer), .flags = 0, .doc = "Auto flip timer"}, {.name = "auto_flip_torque_scale", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, autoFlipTorqueScale), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, autoFlipTorqueScale), .flags = 0, .doc = "Auto flip torque scale"}, {.name = "has_world_contact", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, worldContact.hasContact), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, worldContact.hasContact), .flags = 0, .doc = "Has world contact"}, {.name = "car_contact_id", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, carContact.otherCarID), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, carContact.otherCarID), .flags = 0, .doc = "Car contact other car id"}, {.name = "car_contact_cooldown_timer", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, carContact.cooldownTimer), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, carContact.cooldownTimer), .flags = 0, .doc = "Car contact cooldown timer"}, {.name = "is_demoed", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, isDemoed), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, isDemoed), .flags = 0, .doc = "Is demoed"}, {.name = "demo_respawn_timer", - .type = TypeHelper::type, - .offset = offsetof (CarState, state) + offsetof (::CarState, demoRespawnTimer), + .type = TypeHelper::type, + .offset = offsetof (CarState, state) + offsetof (RocketSim::CarState, demoRespawnTimer), .flags = 0, .doc = "Demo respawn timer"}, {.name = nullptr, .type = 0, .offset = 0, .flags = 0, .doc = nullptr}, @@ -204,7 +204,7 @@ PyType_Spec CarState::Spec = { .slots = CarState::Slots, }; -PyRef CarState::NewFromCarState (::CarState const &state_) noexcept +PyRef CarState::NewFromCarState (RocketSim::CarState const &state_) noexcept { auto const self = PyRef::stealObject (CarState::New (CarState::Type, nullptr, nullptr)); if (!self || !InitFromCarState (self.borrow (), state_)) @@ -213,7 +213,7 @@ PyRef CarState::NewFromCarState (::CarState const &state_) noexcept return self; } -bool CarState::InitFromCarState (CarState *const self_, ::CarState const &state_) noexcept +bool CarState::InitFromCarState (CarState *const self_, RocketSim::CarState const &state_) noexcept { auto pos = Vec::NewFromVec (state_.pos); auto rotMat = RotMat::NewFromRotMat (state_.rotMat); @@ -242,7 +242,7 @@ bool CarState::InitFromCarState (CarState *const self_, ::CarState const &state_ return true; } -::CarState CarState::ToCarState (CarState *self_) noexcept +RocketSim::CarState CarState::ToCarState (CarState *self_) noexcept { auto state = self_->state; @@ -266,7 +266,7 @@ PyObject *CarState::New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds if (!self) return nullptr; - new (&self->state)::CarState (); + new (&self->state) RocketSim::CarState (); self->pos = nullptr; self->rotMat = nullptr; @@ -345,7 +345,7 @@ int CarState::Init (CarState *self_, PyObject *args_, PyObject *kwds_) noexcept updateCounterKwd, nullptr}; - ::CarState state{}; + RocketSim::CarState state{}; PyObject *pos = nullptr; // borrowed references PyObject *rotMat = nullptr; @@ -480,7 +480,7 @@ PyObject *CarState::Pickle (CarState *self_) noexcept if (!dict) return nullptr; - ::CarState const model{}; + RocketSim::CarState const model{}; auto const state = ToCarState (self_); if (state.updateCounter != model.updateCounter && diff --git a/python-mtheall/Module.cpp b/python-mtheall/Module.cpp index d22fef87..2dbd0efb 100644 --- a/python-mtheall/Module.cpp +++ b/python-mtheall/Module.cpp @@ -196,46 +196,46 @@ extern "C" Py_EXPORTED_SYMBOL PyObject *PyInit_RocketSim () noexcept // GameMode SET_TYPE_ATTR (RocketSim::Python::GameMode::Type, "SOCCAR", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (::GameMode::SOCCAR)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::GameMode::SOCCAR)))); SET_TYPE_ATTR (RocketSim::Python::GameMode::Type, "HOOPS", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (::GameMode::HOOPS)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::GameMode::HOOPS)))); SET_TYPE_ATTR (RocketSim::Python::GameMode::Type, "HEATSEEKER", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (::GameMode::HEATSEEKER)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::GameMode::HEATSEEKER)))); SET_TYPE_ATTR (RocketSim::Python::GameMode::Type, "SNOWDAY", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (::GameMode::SNOWDAY)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::GameMode::SNOWDAY)))); SET_TYPE_ATTR (RocketSim::Python::GameMode::Type, "THE_VOID", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (::GameMode::THE_VOID)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::GameMode::THE_VOID)))); // Team SET_TYPE_ATTR (RocketSim::Python::Team::Type, "BLUE", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (::Team::BLUE)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::Team::BLUE)))); SET_TYPE_ATTR (RocketSim::Python::Team::Type, "ORANGE", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (::Team::ORANGE)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::Team::ORANGE)))); // DemoMode SET_TYPE_ATTR (RocketSim::Python::DemoMode::Type, "NORMAL", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (::DemoMode::NORMAL)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::DemoMode::NORMAL)))); SET_TYPE_ATTR (RocketSim::Python::DemoMode::Type, "ON_CONTACT", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (::DemoMode::ON_CONTACT)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::DemoMode::ON_CONTACT)))); SET_TYPE_ATTR (RocketSim::Python::DemoMode::Type, "DISABLED", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (::DemoMode::DISABLED)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::DemoMode::DISABLED)))); // MemoryWeightMode SET_TYPE_ATTR (RocketSim::Python::MemoryWeightMode::Type, "HEAVY", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (ArenaMemWeightMode::HEAVY)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::ArenaMemWeightMode::HEAVY)))); SET_TYPE_ATTR (RocketSim::Python::MemoryWeightMode::Type, "LIGHT", - PyObjectRef::stealObject (PyLong_FromLong (static_cast (ArenaMemWeightMode::LIGHT)))); + PyObjectRef::stealObject (PyLong_FromLong (static_cast (RocketSim::ArenaMemWeightMode::LIGHT)))); // CarConfig SET_TYPE_ATTR (RocketSim::Python::CarConfig::Type, diff --git a/python-mtheall/Module.h b/python-mtheall/Module.h index 6e579d4d..d06182d6 100644 --- a/python-mtheall/Module.h +++ b/python-mtheall/Module.h @@ -152,7 +152,7 @@ struct Vec { PyObject_HEAD; - ::Vec vec; + RocketSim::Vec vec; static PyTypeObject *Type; static PyMemberDef Members[]; @@ -160,9 +160,9 @@ struct Vec static PyType_Slot Slots[]; static PyType_Spec Spec; - static PyRef NewFromVec (::Vec const &vec_ = {}) noexcept; - static bool InitFromVec (Vec *self_, ::Vec const &vec_ = {}) noexcept; - static ::Vec ToVec (Vec *self_) noexcept; + static PyRef NewFromVec (RocketSim::Vec const &vec_ = {}) noexcept; + static bool InitFromVec (Vec *self_, RocketSim::Vec const &vec_ = {}) noexcept; + static RocketSim::Vec ToVec (Vec *self_) noexcept; static PyObject *New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) noexcept; static int Init (Vec *self_, PyObject *args_, PyObject *kwds_) noexcept; @@ -194,9 +194,9 @@ struct RotMat static PyType_Slot Slots[]; static PyType_Spec Spec; - static PyRef NewFromRotMat (::RotMat const &mat_ = {}) noexcept; - static bool InitFromRotMat (RotMat *self_, ::RotMat const &mat_ = {}) noexcept; - static ::RotMat ToRotMat (RotMat *self_) noexcept; + static PyRef NewFromRotMat (RocketSim::RotMat const &mat_ = {}) noexcept; + static bool InitFromRotMat (RotMat *self_, RocketSim::RotMat const &mat_ = {}) noexcept; + static RocketSim::RotMat ToRotMat (RotMat *self_) noexcept; static PyObject *New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) noexcept; static int Init (RotMat *self_, PyObject *args_, PyObject *kwds_) noexcept; @@ -221,7 +221,7 @@ struct Angle { PyObject_HEAD; - ::Angle angle; + RocketSim::Angle angle; static PyTypeObject *Type; static PyMemberDef Members[]; @@ -229,9 +229,9 @@ struct Angle static PyType_Slot Slots[]; static PyType_Spec Spec; - static PyRef NewFromAngle (::Angle const &angle_ = {}) noexcept; - static bool InitFromAngle (Angle *self_, ::Angle const &angle_ = {}) noexcept; - static ::Angle ToAngle (Angle *self_) noexcept; + static PyRef NewFromAngle (RocketSim::Angle const &angle_ = {}) noexcept; + static bool InitFromAngle (Angle *self_, RocketSim::Angle const &angle_ = {}) noexcept; + static RocketSim::Angle ToAngle (Angle *self_) noexcept; static PyObject *New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) noexcept; static int Init (Angle *self_, PyObject *args_, PyObject *kwds_) noexcept; @@ -252,7 +252,7 @@ struct BallHitInfo { PyObject_HEAD; - ::BallHitInfo info; + RocketSim::BallHitInfo info; Vec *relativePosOnBall; Vec *ballPos; @@ -265,9 +265,9 @@ struct BallHitInfo static PyType_Slot Slots[]; static PyType_Spec Spec; - static PyRef NewFromBallHitInfo (::BallHitInfo const &info_ = {}) noexcept; - static bool InitFromBallHitInfo (BallHitInfo *self_, ::BallHitInfo const &info_ = {}) noexcept; - static ::BallHitInfo ToBallHitInfo (BallHitInfo *self_) noexcept; + static PyRef NewFromBallHitInfo (RocketSim::BallHitInfo const &info_ = {}) noexcept; + static bool InitFromBallHitInfo (BallHitInfo *self_, RocketSim::BallHitInfo const &info_ = {}) noexcept; + static RocketSim::BallHitInfo ToBallHitInfo (BallHitInfo *self_) noexcept; static PyObject *New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) noexcept; static int Init (BallHitInfo *self_, PyObject *args_, PyObject *kwds_) noexcept; @@ -286,7 +286,7 @@ struct BallState { PyObject_HEAD; - ::BallState state; + RocketSim::BallState state; Vec *pos; RotMat *rotMat; @@ -300,9 +300,9 @@ struct BallState static PyType_Slot Slots[]; static PyType_Spec Spec; - static PyRef NewFromBallState (::BallState const &state_ = {}) noexcept; - static bool InitFromBallState (BallState *self_, ::BallState const &state_ = {}) noexcept; - static ::BallState ToBallState (BallState *self_) noexcept; + static PyRef NewFromBallState (RocketSim::BallState const &state_ = {}) noexcept; + static bool InitFromBallState (BallState *self_, RocketSim::BallState const &state_ = {}) noexcept; + static RocketSim::BallState ToBallState (BallState *self_) noexcept; static PyObject *New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) noexcept; static int Init (BallState *self_, PyObject *args_, PyObject *kwds_) noexcept; @@ -322,8 +322,8 @@ struct Ball { PyObject_HEAD; - std::shared_ptr<::Arena> arena; - ::Ball *ball; + std::shared_ptr arena; + RocketSim::Ball *ball; static PyTypeObject *Type; static PyMethodDef Methods[]; @@ -344,7 +344,7 @@ struct BoostPadState { PyObject_HEAD; - ::BoostPadState state; + RocketSim::BoostPadState state; static PyTypeObject *Type; static PyMemberDef Members[]; @@ -352,9 +352,9 @@ struct BoostPadState static PyType_Slot Slots[]; static PyType_Spec Spec; - static PyRef NewFromBoostPadState (::BoostPadState const &state_ = {}) noexcept; - static bool InitFromBoostPadState (BoostPadState *self_, ::BoostPadState const &state_ = {}) noexcept; - static ::BoostPadState ToBoostPadState (BoostPadState *self_) noexcept; + static PyRef NewFromBoostPadState (RocketSim::BoostPadState const &state_ = {}) noexcept; + static bool InitFromBoostPadState (BoostPadState *self_, RocketSim::BoostPadState const &state_ = {}) noexcept; + static RocketSim::BoostPadState ToBoostPadState (BoostPadState *self_) noexcept; static PyObject *New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) noexcept; static int Init (BoostPadState *self_, PyObject *args_, PyObject *kwds_) noexcept; @@ -369,8 +369,8 @@ struct BoostPad { PyObject_HEAD; - std::shared_ptr<::Arena> arena; - ::BoostPad *pad; + std::shared_ptr arena; + RocketSim::BoostPad *pad; static PyTypeObject *Type; static PyMemberDef Members[]; @@ -395,7 +395,7 @@ struct WheelPairConfig { PyObject_HEAD; - ::WheelPairConfig config; + RocketSim::WheelPairConfig config; Vec *connectionPointOffset; static PyTypeObject *Type; @@ -405,9 +405,10 @@ struct WheelPairConfig static PyType_Slot Slots[]; static PyType_Spec Spec; - static PyRef NewFromWheelPairConfig (::WheelPairConfig const &config_ = {}) noexcept; - static bool InitFromWheelPairConfig (WheelPairConfig *self_, ::WheelPairConfig const &config_ = {}) noexcept; - static ::WheelPairConfig ToWheelPairConfig (WheelPairConfig *self_) noexcept; + static PyRef NewFromWheelPairConfig (RocketSim::WheelPairConfig const &config_ = {}) noexcept; + static bool InitFromWheelPairConfig (WheelPairConfig *self_, + RocketSim::WheelPairConfig const &config_ = {}) noexcept; + static RocketSim::WheelPairConfig ToWheelPairConfig (WheelPairConfig *self_) noexcept; static PyObject *New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) noexcept; static int Init (WheelPairConfig *self_, PyObject *args_, PyObject *kwds_) noexcept; @@ -434,7 +435,7 @@ struct CarConfig PyObject_HEAD; - ::CarConfig config; + RocketSim::CarConfig config; Vec *hitboxSize; Vec *hitboxPosOffset; @@ -448,10 +449,10 @@ struct CarConfig static PyType_Slot Slots[]; static PyType_Spec Spec; - static bool FromIndex (Index index_, ::CarConfig &config_) noexcept; - static PyRef NewFromCarConfig (::CarConfig const &config_ = {}) noexcept; - static bool InitFromCarConfig (CarConfig *self_, ::CarConfig const &config_ = {}) noexcept; - static ::CarConfig ToCarConfig (CarConfig *self_) noexcept; + static bool FromIndex (Index index_, RocketSim::CarConfig &config_) noexcept; + static PyRef NewFromCarConfig (RocketSim::CarConfig const &config_ = {}) noexcept; + static bool InitFromCarConfig (CarConfig *self_, RocketSim::CarConfig const &config_ = {}) noexcept; + static RocketSim::CarConfig ToCarConfig (CarConfig *self_) noexcept; static PyObject *New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) noexcept; static int Init (CarConfig *self_, PyObject *args_, PyObject *kwds_) noexcept; @@ -471,7 +472,7 @@ struct CarControls { PyObject_HEAD; - ::CarControls controls; + RocketSim::CarControls controls; static PyTypeObject *Type; static PyMemberDef Members[]; @@ -479,9 +480,9 @@ struct CarControls static PyType_Slot Slots[]; static PyType_Spec Spec; - static PyRef NewFromCarControls (::CarControls const &controls_ = {}) noexcept; - static bool InitFromCarControls (CarControls *self_, ::CarControls const &controls_ = {}) noexcept; - static ::CarControls ToCarControls (CarControls *self_) noexcept; + static PyRef NewFromCarControls (RocketSim::CarControls const &controls_ = {}) noexcept; + static bool InitFromCarControls (CarControls *self_, RocketSim::CarControls const &controls_ = {}) noexcept; + static RocketSim::CarControls ToCarControls (CarControls *self_) noexcept; static PyObject *New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) noexcept; static int Init (CarControls *self_, PyObject *args_, PyObject *kwds_) noexcept; @@ -498,7 +499,7 @@ struct CarState { PyObject_HEAD; - ::CarState state; + RocketSim::CarState state; Vec *pos; RotMat *rotMat; @@ -509,9 +510,9 @@ struct CarState Vec *worldContactNormal; BallHitInfo *ballHitInfo; - static PyRef NewFromCarState (::CarState const &state_ = {}) noexcept; - static bool InitFromCarState (CarState *self_, ::CarState const &state_ = {}) noexcept; - static ::CarState ToCarState (CarState *self_) noexcept; + static PyRef NewFromCarState (RocketSim::CarState const &state_ = {}) noexcept; + static bool InitFromCarState (CarState *self_, RocketSim::CarState const &state_ = {}) noexcept; + static RocketSim::CarState ToCarState (CarState *self_) noexcept; static PyTypeObject *Type; static PyMemberDef Members[]; @@ -542,10 +543,10 @@ struct Car { PyObject_HEAD; - ::CarState demoState; + RocketSim::CarState demoState; std::shared_ptr arena; - ::Car *car; + RocketSim::Car *car; unsigned goals; unsigned demos; unsigned boostPickups; @@ -564,7 +565,7 @@ struct Car static PyObject *NewStub (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) noexcept; static void Dealloc (Car *self_) noexcept; static PyObject *InternalPickle (Car *self_) noexcept; - static PyObject *InternalUnpickle (std::shared_ptr<::Arena> arena_, Car *self_, PyObject *dict_) noexcept; + static PyObject *InternalUnpickle (std::shared_ptr arena_, Car *self_, PyObject *dict_) noexcept; GETONLY_DECLARE (Car, id) GETONLY_DECLARE (Car, team) @@ -585,7 +586,7 @@ struct MutatorConfig { PyObject_HEAD; - ::MutatorConfig config; + RocketSim::MutatorConfig config; Vec *gravity; static PyTypeObject *Type; @@ -595,10 +596,11 @@ struct MutatorConfig static PyType_Slot Slots[]; static PyType_Spec Spec; - static PyRef NewFromMutatorConfig (::MutatorConfig const &config_ = {::GameMode::SOCCAR}) noexcept; + static PyRef NewFromMutatorConfig ( + RocketSim::MutatorConfig const &config_ = {RocketSim::GameMode::SOCCAR}) noexcept; static bool InitFromMutatorConfig (MutatorConfig *self_, - ::MutatorConfig const &config_ = {::GameMode::SOCCAR}) noexcept; - static ::MutatorConfig ToMutatorConfig (MutatorConfig *self_) noexcept; + RocketSim::MutatorConfig const &config_ = {RocketSim::GameMode::SOCCAR}) noexcept; + static RocketSim::MutatorConfig ToMutatorConfig (MutatorConfig *self_) noexcept; static PyObject *New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) noexcept; static int Init (MutatorConfig *self_, PyObject *args_, PyObject *kwds_) noexcept; @@ -617,13 +619,13 @@ struct Arena PyObject_HEAD; - std::shared_ptr<::Arena> arena; + std::shared_ptr arena; std::shared_ptr threadPool; std::map> *cars; - std::unordered_map<::BoostPad *, PyRef> *boostPads; + std::unordered_map> *boostPads; std::vector> *boostPadsByIndex; - ::BallPredTracker *ballPrediction; - ::GameEventTracker *gameEvent; + RocketSim::BallPredTracker *ballPrediction; + RocketSim::GameEventTracker *gameEvent; Ball *ball; PyObject *ballTouchCallback; @@ -696,16 +698,28 @@ struct Arena static PyObject *MultiStep (PyObject *dummy_, PyObject *args_, PyObject *kwds_) noexcept; - static void HandleBallTouchCallback (::Arena *arena_, ::Car *car_, void *userData_) noexcept; + static void HandleBallTouchCallback (RocketSim::Arena *arena_, RocketSim::Car *car_, void *userData_) noexcept; + static void HandleBoostPickupCallback (RocketSim::Arena *arena_, + RocketSim::Car *car_, + RocketSim::BoostPad *boostPad_, + void *userData_) noexcept; + static void HandleCarBumpCallback (RocketSim::Arena *arena_, + RocketSim::Car *bumper_, + RocketSim::Car *victim_, + bool isDemo_, + void *userData_) noexcept; static void - HandleBoostPickupCallback (::Arena *arena_, ::Car *car_, ::BoostPad *boostPad_, void *userData_) noexcept; - static void - HandleCarBumpCallback (::Arena *arena_, ::Car *bumper_, ::Car *victim_, bool isDemo_, void *userData_) noexcept; - static void HandleGoalScoreCallback (::Arena *arena_, ::Team scoringTeam_, void *userData_) noexcept; - - static void HandleShotEventCallback (::Arena *arena_, ::Car *shooter_, ::Car *passer_, void *userData_) noexcept; - static void HandleGoalEventCallback (::Arena *arena_, ::Car *shooter_, ::Car *passer_, void *userData_) noexcept; - static void HandleSaveEventCallback (::Arena *arena_, ::Car *saver_, void *userData_) noexcept; + HandleGoalScoreCallback (RocketSim::Arena *arena_, RocketSim::Team scoringTeam_, void *userData_) noexcept; + + static void HandleShotEventCallback (RocketSim::Arena *arena_, + RocketSim::Car *shooter_, + RocketSim::Car *passer_, + void *userData_) noexcept; + static void HandleGoalEventCallback (RocketSim::Arena *arena_, + RocketSim::Car *shooter_, + RocketSim::Car *passer_, + void *userData_) noexcept; + static void HandleSaveEventCallback (RocketSim::Arena *arena_, RocketSim::Car *saver_, void *userData_) noexcept; GETONLY_DECLARE (Arena, game_mode); GETONLY_DECLARE (Arena, tick_count); diff --git a/python-mtheall/MutatorConfig.cpp b/python-mtheall/MutatorConfig.cpp index fd936736..4a65d81f 100644 --- a/python-mtheall/MutatorConfig.cpp +++ b/python-mtheall/MutatorConfig.cpp @@ -11,133 +11,133 @@ PyTypeObject *MutatorConfig::Type = nullptr; PyMemberDef MutatorConfig::Members[] = { {.name = "ball_drag", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, ballDrag), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, ballDrag), .flags = 0, .doc = "Ball drag"}, {.name = "ball_hit_extra_force_scale", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, ballHitExtraForceScale), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, ballHitExtraForceScale), .flags = 0, .doc = "Ball hit extra force scale"}, {.name = "ball_mass", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, ballMass), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, ballMass), .flags = 0, .doc = "Ball mass"}, {.name = "ball_max_speed", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, ballMaxSpeed), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, ballMaxSpeed), .flags = 0, .doc = "Ball max speed"}, {.name = "ball_radius", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, ballRadius), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, ballRadius), .flags = 0, .doc = "Ball radius"}, {.name = "ball_world_friction", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, ballWorldFriction), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, ballWorldFriction), .flags = 0, .doc = "Ball world friction"}, {.name = "ball_world_restitution", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, ballWorldRestitution), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, ballWorldRestitution), .flags = 0, .doc = "Ball world restitution"}, {.name = "boost_accel", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, boostAccel), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, boostAccel), .flags = 0, .doc = "Boost accel"}, {.name = "boost_pad_cooldown_big", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, boostPadCooldown_Big), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, boostPadCooldown_Big), .flags = 0, .doc = "Boost pad cooldown big"}, {.name = "boost_pad_cooldown_small", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, boostPadCooldown_Small), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, boostPadCooldown_Small), .flags = 0, .doc = "Boost pad cooldown small"}, {.name = "boost_used_per_second", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, boostUsedPerSecond), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, boostUsedPerSecond), .flags = 0, .doc = "Boost used per second"}, {.name = "bump_cooldown_time", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, bumpCooldownTime), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, bumpCooldownTime), .flags = 0, .doc = "Bump cooldown time"}, {.name = "bump_force_scale", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, bumpForceScale), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, bumpForceScale), .flags = 0, .doc = "Bump force scale"}, {.name = "car_mass", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, carMass), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, carMass), .flags = 0, .doc = "Car mass"}, {.name = "car_spawn_boost_amount", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, carSpawnBoostAmount), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, carSpawnBoostAmount), .flags = 0, .doc = "Car spawn boost amount"}, {.name = "car_world_friction", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, carWorldFriction), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, carWorldFriction), .flags = 0, .doc = "Car world friction"}, {.name = "car_world_restitution", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, carWorldRestitution), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, carWorldRestitution), .flags = 0, .doc = "Car world restitution"}, {.name = "unlimited_flips", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, unlimitedFlips), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, unlimitedFlips), .flags = 0, .doc = "Enable unlimited flips"}, {.name = "unlimited_double_jumps", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, unlimitedDoubleJumps), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, unlimitedDoubleJumps), .flags = 0, .doc = "Enable unlimited double jumps"}, {.name = "demo_mode", - .type = TypeHelper>::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, demoMode), + .type = TypeHelper>::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, demoMode), .flags = 0, .doc = "Demo mode"}, {.name = "enable_team_demos", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, enableTeamDemos), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, enableTeamDemos), .flags = 0, .doc = "Enable team demos"}, {.name = "jump_accel", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, jumpAccel), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, jumpAccel), .flags = 0, .doc = "Jump acceleration"}, {.name = "jump_immediate_force", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, jumpImmediateForce), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, jumpImmediateForce), .flags = 0, .doc = "Jump immediate force"}, {.name = "respawn_delay", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, respawnDelay), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, respawnDelay), .flags = 0, .doc = "Respawn delay"}, {.name = "enable_car_car_collision", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, enableCarCarCollision), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, enableCarCarCollision), .flags = 0, .doc = "Enable car-car collision"}, {.name = "enable_car_ball_collision", - .type = TypeHelper::type, - .offset = offsetof (MutatorConfig, config) + offsetof (::MutatorConfig, enableCarBallCollision), + .type = TypeHelper::type, + .offset = offsetof (MutatorConfig, config) + offsetof (RocketSim::MutatorConfig, enableCarBallCollision), .flags = 0, .doc = "Enable car-ball collision"}, {.name = nullptr, .type = 0, .offset = 0, .flags = 0, .doc = nullptr}, @@ -218,7 +218,7 @@ PyType_Spec MutatorConfig::Spec = { .slots = MutatorConfig::Slots, }; -PyRef MutatorConfig::NewFromMutatorConfig (::MutatorConfig const &config_) noexcept +PyRef MutatorConfig::NewFromMutatorConfig (RocketSim::MutatorConfig const &config_) noexcept { auto const self = PyRef::stealObject (MutatorConfig::New (MutatorConfig::Type, nullptr, nullptr)); if (!self || !InitFromMutatorConfig (self.borrow (), config_)) @@ -227,7 +227,7 @@ PyRef MutatorConfig::NewFromMutatorConfig (::MutatorConfig const return self; } -bool MutatorConfig::InitFromMutatorConfig (MutatorConfig *const self_, ::MutatorConfig const &config_) noexcept +bool MutatorConfig::InitFromMutatorConfig (MutatorConfig *const self_, RocketSim::MutatorConfig const &config_) noexcept { auto const gravity = Vec::NewFromVec (config_.gravity); @@ -240,7 +240,7 @@ bool MutatorConfig::InitFromMutatorConfig (MutatorConfig *const self_, ::Mutator return true; } -::MutatorConfig MutatorConfig::ToMutatorConfig (MutatorConfig *self_) noexcept +RocketSim::MutatorConfig MutatorConfig::ToMutatorConfig (MutatorConfig *self_) noexcept { auto config = self_->config; @@ -257,7 +257,7 @@ PyObject *MutatorConfig::New (PyTypeObject *subtype_, PyObject *args_, PyObject if (!self) return nullptr; - new (&self->config)::MutatorConfig{::GameMode::SOCCAR}; + new (&self->config) RocketSim::MutatorConfig{RocketSim::GameMode::SOCCAR}; self->gravity = nullptr; return self.giftObject (); @@ -324,18 +324,18 @@ int MutatorConfig::Init (MutatorConfig *self_, PyObject *args_, PyObject *kwds_) enableCarBallCollisionKwd, nullptr}; - int gameMode = static_cast (::GameMode::SOCCAR); + int gameMode = static_cast (RocketSim::GameMode::SOCCAR); // first pass to get game mode, second pass to fill in if not for (int i = 0; i < 2; ++i) { - switch (static_cast<::GameMode> (gameMode)) + switch (static_cast (gameMode)) { - case ::GameMode::SOCCAR: - case ::GameMode::HOOPS: - case ::GameMode::HEATSEEKER: - case ::GameMode::SNOWDAY: - case ::GameMode::THE_VOID: + case RocketSim::GameMode::SOCCAR: + case RocketSim::GameMode::HOOPS: + case RocketSim::GameMode::HEATSEEKER: + case RocketSim::GameMode::SNOWDAY: + case RocketSim::GameMode::THE_VOID: break; default: @@ -343,7 +343,7 @@ int MutatorConfig::Init (MutatorConfig *self_, PyObject *args_, PyObject *kwds_) return -1; } - ::MutatorConfig config{static_cast<::GameMode> (gameMode)}; + RocketSim::MutatorConfig config{static_cast (gameMode)}; PyObject *gravity = nullptr; // borrowed reference int demoMode = static_cast (config.demoMode); @@ -390,16 +390,16 @@ int MutatorConfig::Init (MutatorConfig *self_, PyObject *args_, PyObject *kwds_) return -1; // try again with parsed game mode - if (i == 0 && static_cast<::GameMode> (gameMode) != ::GameMode::SOCCAR) + if (i == 0 && static_cast (gameMode) != RocketSim::GameMode::SOCCAR) continue; - config.demoMode = static_cast<::DemoMode> (demoMode); + config.demoMode = static_cast (demoMode); switch (config.demoMode) { - case ::DemoMode::NORMAL: - case ::DemoMode::ON_CONTACT: - case ::DemoMode::DISABLED: + case RocketSim::DemoMode::NORMAL: + case RocketSim::DemoMode::ON_CONTACT: + case RocketSim::DemoMode::DISABLED: break; default: @@ -447,7 +447,7 @@ PyObject *MutatorConfig::Pickle (MutatorConfig *self_) noexcept if (!dict) return nullptr; - ::MutatorConfig const model{::GameMode::SOCCAR}; + RocketSim::MutatorConfig const model{RocketSim::GameMode::SOCCAR}; auto const config = ToMutatorConfig (self_); if (config.gravity != model.gravity && !DictSetValue (dict.borrow (), "gravity", PyNewRef (self_->gravity))) diff --git a/python-mtheall/RotMat.cpp b/python-mtheall/RotMat.cpp index 099d815f..a7da9439 100644 --- a/python-mtheall/RotMat.cpp +++ b/python-mtheall/RotMat.cpp @@ -79,7 +79,7 @@ PyType_Spec RotMat::Spec = { .slots = RotMat::Slots, }; -PyRef RotMat::NewFromRotMat (::RotMat const &mat_) noexcept +PyRef RotMat::NewFromRotMat (RocketSim::RotMat const &mat_) noexcept { auto const self = PyRef::stealObject (RotMat::New (RotMat::Type, nullptr, nullptr)); if (!self || !InitFromRotMat (self.borrow (), mat_)) @@ -88,7 +88,7 @@ PyRef RotMat::NewFromRotMat (::RotMat const &mat_) noexcept return self; } -bool RotMat::InitFromRotMat (RotMat *const self_, ::RotMat const &mat_) noexcept +bool RotMat::InitFromRotMat (RotMat *const self_, RocketSim::RotMat const &mat_) noexcept { auto const forward = Vec::NewFromVec (mat_.forward); auto const right = Vec::NewFromVec (mat_.right); @@ -104,9 +104,9 @@ bool RotMat::InitFromRotMat (RotMat *const self_, ::RotMat const &mat_) noexcept return true; } -::RotMat RotMat::ToRotMat (RotMat *self_) noexcept +RocketSim::RotMat RotMat::ToRotMat (RotMat *self_) noexcept { - ::RotMat mat{}; + RocketSim::RotMat mat{}; mat.forward = Vec::ToVec (self_->forward); mat.right = Vec::ToVec (self_->right); @@ -132,7 +132,7 @@ PyObject *RotMat::New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) int RotMat::Init (RotMat *self_, PyObject *args_, PyObject *kwds_) noexcept { - ::RotMat mat = ::RotMat::GetIdentity (); + RocketSim::RotMat mat = RocketSim::RotMat::GetIdentity (); if (PyTuple_Size (args_) == 0 && !kwds_) { if (!InitFromRotMat (self_, mat)) @@ -372,7 +372,7 @@ PyObject *RotMat::AsTuple (RotMat *self_) noexcept PyObject *RotMat::AsAngle (RotMat *self_) noexcept { - return Angle::NewFromAngle (::Angle::FromRotMat (ToRotMat (self_))).giftObject (); + return Angle::NewFromAngle (RocketSim::Angle::FromRotMat (ToRotMat (self_))).giftObject (); } PyObject *RotMat::AsNumpy (RotMat *self_) noexcept diff --git a/python-mtheall/Vec.cpp b/python-mtheall/Vec.cpp index b0cdab21..9571ca32 100644 --- a/python-mtheall/Vec.cpp +++ b/python-mtheall/Vec.cpp @@ -13,18 +13,18 @@ PyTypeObject *Vec::Type = nullptr; PyMemberDef Vec::Members[] = { {.name = "x", - .type = TypeHelper::type, - .offset = offsetof (Vec, vec) + offsetof (::Vec, x), + .type = TypeHelper::type, + .offset = offsetof (Vec, vec) + offsetof (RocketSim::Vec, x), .flags = 0, .doc = "X component"}, {.name = "y", - .type = TypeHelper::type, - .offset = offsetof (Vec, vec) + offsetof (::Vec, y), + .type = TypeHelper::type, + .offset = offsetof (Vec, vec) + offsetof (RocketSim::Vec, y), .flags = 0, .doc = "Y component"}, {.name = "z", - .type = TypeHelper::type, - .offset = offsetof (Vec, vec) + offsetof (::Vec, z), + .type = TypeHelper::type, + .offset = offsetof (Vec, vec) + offsetof (RocketSim::Vec, z), .flags = 0, .doc = "Z component"}, {.name = nullptr, .type = 0, .offset = 0, .flags = 0, .doc = nullptr}, @@ -86,7 +86,7 @@ PyType_Spec Vec::Spec = { .slots = Vec::Slots, }; -PyRef Vec::NewFromVec (::Vec const &vec_) noexcept +PyRef Vec::NewFromVec (RocketSim::Vec const &vec_) noexcept { auto const self = PyRef::stealObject (Vec::New (Vec::Type, nullptr, nullptr)); if (!self || !InitFromVec (self.borrow (), vec_)) @@ -95,13 +95,13 @@ PyRef Vec::NewFromVec (::Vec const &vec_) noexcept return self; } -bool Vec::InitFromVec (Vec *const self_, ::Vec const &vec_) noexcept +bool Vec::InitFromVec (Vec *const self_, RocketSim::Vec const &vec_) noexcept { self_->vec = vec_; return true; } -::Vec Vec::ToVec (Vec *self_) noexcept +RocketSim::Vec Vec::ToVec (Vec *self_) noexcept { return self_->vec; } @@ -114,7 +114,7 @@ PyObject *Vec::New (PyTypeObject *subtype_, PyObject *args_, PyObject *kwds_) no if (!self) return nullptr; - new (&self->vec)::Vec{}; + new (&self->vec) RocketSim::Vec{}; return self.giftObject (); } @@ -126,7 +126,7 @@ int Vec::Init (Vec *self_, PyObject *args_, PyObject *kwds_) noexcept static char zKwd[] = "z"; static char *dict[] = {xKwd, yKwd, zKwd, nullptr}; - ::Vec vec{}; + RocketSim::Vec vec{}; if (!PyArg_ParseTupleAndKeywords (args_, kwds_, "|fff", dict, &vec.x, &vec.y, &vec.z)) return -1; @@ -213,7 +213,7 @@ PyObject *Vec::Pickle (Vec *self_) noexcept if (!dict) return nullptr; - ::Vec const model{}; + RocketSim::Vec const model{}; auto const vec = ToVec (self_); if (vec.x != model.x && !DictSetValue (dict.borrow (), "x", PyFloat_FromDouble (vec.x))) diff --git a/python-mtheall/WheelPairConfig.cpp b/python-mtheall/WheelPairConfig.cpp index ac7c7d4a..0aa4f276 100644 --- a/python-mtheall/WheelPairConfig.cpp +++ b/python-mtheall/WheelPairConfig.cpp @@ -9,13 +9,13 @@ PyTypeObject *WheelPairConfig::Type = nullptr; PyMemberDef WheelPairConfig::Members[] = { {.name = "wheel_radius", - .type = TypeHelper::type, - .offset = offsetof (WheelPairConfig, config) + offsetof (::WheelPairConfig, wheelRadius), + .type = TypeHelper::type, + .offset = offsetof (WheelPairConfig, config) + offsetof (RocketSim::WheelPairConfig, wheelRadius), .flags = 0, .doc = "Wheel radius"}, {.name = "suspension_rest_length", - .type = TypeHelper::type, - .offset = offsetof (WheelPairConfig, config) + offsetof (::WheelPairConfig, suspensionRestLength), + .type = TypeHelper::type, + .offset = offsetof (WheelPairConfig, config) + offsetof (RocketSim::WheelPairConfig, suspensionRestLength), .flags = 0, .doc = "Suspension rest length"}, {.name = nullptr, .type = 0, .offset = 0, .flags = 0, .doc = nullptr}, @@ -71,7 +71,7 @@ PyType_Spec WheelPairConfig::Spec = { .slots = WheelPairConfig::Slots, }; -PyRef WheelPairConfig::NewFromWheelPairConfig (::WheelPairConfig const &config_) noexcept +PyRef WheelPairConfig::NewFromWheelPairConfig (RocketSim::WheelPairConfig const &config_) noexcept { auto const self = PyRef::stealObject (WheelPairConfig::New (WheelPairConfig::Type, nullptr, nullptr)); @@ -81,7 +81,8 @@ PyRef WheelPairConfig::NewFromWheelPairConfig (::WheelPairConfi return self; } -bool WheelPairConfig::InitFromWheelPairConfig (WheelPairConfig *const self_, ::WheelPairConfig const &config_) noexcept +bool WheelPairConfig::InitFromWheelPairConfig (WheelPairConfig *const self_, + RocketSim::WheelPairConfig const &config_) noexcept { auto connectionPointOffset = Vec::NewFromVec (config_.connectionPointOffset); if (!connectionPointOffset) @@ -94,7 +95,7 @@ bool WheelPairConfig::InitFromWheelPairConfig (WheelPairConfig *const self_, ::W return true; } -::WheelPairConfig WheelPairConfig::ToWheelPairConfig (WheelPairConfig *self_) noexcept +RocketSim::WheelPairConfig WheelPairConfig::ToWheelPairConfig (WheelPairConfig *self_) noexcept { auto config = self_->config; @@ -111,7 +112,7 @@ PyObject *WheelPairConfig::New (PyTypeObject *subtype_, PyObject *args_, PyObjec if (!self) return nullptr; - new (&self->config)::WheelPairConfig (); + new (&self->config) RocketSim::WheelPairConfig (); self->connectionPointOffset = nullptr; @@ -126,7 +127,7 @@ int WheelPairConfig::Init (WheelPairConfig *self_, PyObject *args_, PyObject *kw static char *dict[] = {wheelRadiusKwd, suspensionRestLengthKwd, connectionPointOffsetKwd, nullptr}; - ::WheelPairConfig config{}; + RocketSim::WheelPairConfig config{}; PyObject *connectionPointOffset = nullptr; // borrowed if (!PyArg_ParseTupleAndKeywords (args_, diff --git a/src/CollisionMeshFile/CollisionMeshFile.cpp b/src/CollisionMeshFile/CollisionMeshFile.cpp index d9f2bbc3..7f177b44 100644 --- a/src/CollisionMeshFile/CollisionMeshFile.cpp +++ b/src/CollisionMeshFile/CollisionMeshFile.cpp @@ -6,6 +6,8 @@ #include "../../libsrc/bullet3-3.24/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" #include "../../libsrc/bullet3-3.24/BulletCollision/CollisionShapes/btTriangleMesh.h" +RS_NS_START + void CollisionMeshFile::ReadFromFile(std::string filePath) { constexpr char ERROR_PREFIX_STR[] = " > CollisionMeshFile::ReadFromFile(): "; @@ -95,3 +97,5 @@ void CollisionMeshFile::UpdateHash() { this->hash = hash; } + +RS_NS_END diff --git a/src/CollisionMeshFile/CollisionMeshFile.h b/src/CollisionMeshFile/CollisionMeshFile.h index e578c091..84f2e2de 100644 --- a/src/CollisionMeshFile/CollisionMeshFile.h +++ b/src/CollisionMeshFile/CollisionMeshFile.h @@ -7,6 +7,8 @@ class btTriangleMesh; +RS_NS_START + // Collision mesh file structure based off of the one in https://github.com/ZealanL/RLArenaCollisionDumper struct CollisionMeshFile { @@ -32,3 +34,5 @@ struct CollisionMeshFile { btTriangleMesh* MakeBulletMesh(); void UpdateHash(); }; + +RS_NS_END diff --git a/src/DataStream/DataStreamIn.h b/src/DataStream/DataStreamIn.h index dd20d509..cb90625d 100644 --- a/src/DataStream/DataStreamIn.h +++ b/src/DataStream/DataStreamIn.h @@ -5,6 +5,7 @@ #include +RS_NS_START // Basic struct for reading raw data from a file struct DataStreamIn { std::vector data; @@ -84,3 +85,5 @@ struct DataStreamIn { ReadMultipleFromList({ args... }); } }; + +RS_NS_END diff --git a/src/DataStream/DataStreamOut.h b/src/DataStream/DataStreamOut.h index f6cb32f6..9953572b 100644 --- a/src/DataStream/DataStreamOut.h +++ b/src/DataStream/DataStreamOut.h @@ -3,6 +3,8 @@ #include "SerializeObject.h" +RS_NS_START + // Basic struct for writing raw data to a file struct DataStreamOut { std::vector data; @@ -66,3 +68,5 @@ template <> inline void DataStreamOut::Write(const RotMat& val) { WriteMultiple(val.forward, val.right, val.up); } + +RS_NS_END diff --git a/src/DataStream/SerializeObject.h b/src/DataStream/SerializeObject.h index fa2dcc33..020ebdea 100644 --- a/src/DataStream/SerializeObject.h +++ b/src/DataStream/SerializeObject.h @@ -1,6 +1,8 @@ #pragma once #include "../Framework.h" +RS_NS_START + struct SerializeObject { void* ptr; size_t size = -1; @@ -17,4 +19,6 @@ struct SerializeObject { ptr = other.ptr; size = other.size; } -}; \ No newline at end of file +}; + +RS_NS_END \ No newline at end of file diff --git a/src/Framework.h b/src/Framework.h index cce8fde8..21f573a7 100644 --- a/src/Framework.h +++ b/src/Framework.h @@ -57,9 +57,14 @@ typedef uint8_t byte; // Returns sign of number (1 if positive, -1 if negative, and 0 if 0) #define RS_SGN(val) ((val > 0) - (val < 0)) -#define RS_WARN(s) RS_LOG("WARNING: " << s) +#define RS_WARN(s) RS_LOG("ROCKETSIM WARNING: " << s) -#define RS_ERR_CLOSE(s) { std::string _errorStr = RS_STR("FATAL ERROR: " << s); RS_LOG(_errorStr); throw std::runtime_error(_errorStr); exit(EXIT_FAILURE); } +#define RS_ERR_CLOSE(s) { \ + std::string _errorStr = RS_STR("ROCKETSIM FATAL ERROR: " << s); \ + RS_LOG(_errorStr); \ + throw std::runtime_error(_errorStr); \ + exit(EXIT_FAILURE); \ +} #if 0 // FOR FUTURE USE: Exports/imports setup #ifdef ROCKETSIM_EXPORTS @@ -73,6 +78,9 @@ typedef uint8_t byte; #define RS_ALIGN_16 alignas(16) +#define RS_NS_START namespace RocketSim { +#define RS_NS_END } + template size_t __RS_GET_ARGUMENT_COUNT(Args ...) { return sizeof...(Args); diff --git a/src/Math/Math.cpp b/src/Math/Math.cpp index 9390ce50..83d49f33 100644 --- a/src/Math/Math.cpp +++ b/src/Math/Math.cpp @@ -2,6 +2,8 @@ #include +RS_NS_START + float LinearPieceCurve::GetOutput(float input, float defaultOutput) const { float output = input; @@ -71,3 +73,5 @@ float Math::WrapNormalizeFloat(float val, float minmax) { result += minmax * 2; return result; } + +RS_NS_END diff --git a/src/Math/Math.h b/src/Math/Math.h index 574e7afe..13364815 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -1,6 +1,8 @@ #pragma once #include "../BaseInc.h" +RS_NS_START + struct LinearPieceCurve { std::map valueMappings; @@ -19,4 +21,6 @@ namespace Math { RSAPI std::default_random_engine& GetRandEngine(); RSAPI float WrapNormalizeFloat(float val, float minmax); -} \ No newline at end of file +} + +RS_NS_END \ No newline at end of file diff --git a/src/Math/MathTypes/MathTypes.cpp b/src/Math/MathTypes/MathTypes.cpp index 4fb92069..e47e2e2b 100644 --- a/src/Math/MathTypes/MathTypes.cpp +++ b/src/Math/MathTypes/MathTypes.cpp @@ -2,6 +2,8 @@ #include "../Math.h" +RS_NS_START + #define VEC_OP_VEC(op) \ Vec Vec::operator op(const Vec& other) const { return Vec(x op other.x, y op other.y, z op other.z, _w op other._w); } \ Vec& Vec::operator op##=(const Vec& other) { return *this = *this op other; } @@ -111,4 +113,6 @@ void Angle::NormalizeFix() { yaw = Math::WrapNormalizeFloat(yaw, M_PI); pitch = Math::WrapNormalizeFloat(pitch, M_PI / 2); roll = Math::WrapNormalizeFloat(roll, M_PI); -} \ No newline at end of file +} + +RS_NS_END \ No newline at end of file diff --git a/src/Math/MathTypes/MathTypes.h b/src/Math/MathTypes/MathTypes.h index f302c290..18ef293c 100644 --- a/src/Math/MathTypes/MathTypes.h +++ b/src/Math/MathTypes/MathTypes.h @@ -1,6 +1,8 @@ #pragma once #include "../../BaseInc.h" +RS_NS_START + // RocketSim 3D vector struct struct RS_ALIGN_16 Vec { float x = 0, y = 0, z = 0; @@ -38,9 +40,9 @@ struct RS_ALIGN_16 Vec { Vec Cross(const Vec& other) const { return Vec( - (y * other.z) - (z * other.y), - (z * other.x) - (x * other.z), - (x * other.y) - (y * other.x) + (y * other.z) - (z * other.y), + (z * other.x) - (x * other.z), + (x * other.y) - (y * other.x) ); } @@ -230,7 +232,7 @@ struct RS_ALIGN_16 RotMat { RotMat result; for (size_t i = 0; i < 3; i++) - for (size_t j = 0; j < 3; j++) + for (size_t j = 0; j < 3; j++) for (size_t k = 0; k < 3; k++) result[i][j] += (*this)[i][j] * other[k][j]; @@ -295,3 +297,5 @@ struct Angle { return stream; } }; + +RS_NS_END diff --git a/src/RLConst.h b/src/RLConst.h index 954f1b57..e152495e 100644 --- a/src/RLConst.h +++ b/src/RLConst.h @@ -2,6 +2,8 @@ #include "BaseInc.h" #include "Math/Math.h" +RS_NS_START + // Constant/default values from the game namespace RLConst { @@ -122,6 +124,7 @@ namespace RLConst { BALL_CAR_EXTRA_IMPULSE_Z_SCALE_HOOPS_GROUND = BALL_CAR_EXTRA_IMPULSE_Z_SCALE * 1.55f, BALL_CAR_EXTRA_IMPULSE_FORWARD_SCALE = 0.65f, BALL_CAR_EXTRA_IMPULSE_MAXDELTAVEL_UU = 4600.f, + BALL_CAR_EXTRA_IMPULSE_Z_SCALE_HOOPS_NORMAL_Z_THRESH = 0.1f, CAR_SPAWN_REST_Z = 17.f, CAR_RESPAWN_Z = 36.f, @@ -420,4 +423,6 @@ namespace RLConst { {2200.f, 417.f}, } }; -} \ No newline at end of file +} + +RS_NS_END \ No newline at end of file diff --git a/src/RocketSim.cpp b/src/RocketSim.cpp index 8f2f72e8..1728f5c1 100644 --- a/src/RocketSim.cpp +++ b/src/RocketSim.cpp @@ -1,14 +1,14 @@ #include "RocketSim.h" -#ifdef RS_PYBIND -// Make sure it gets compiled -#include "../python/src/PYB.h" -#endif - #include "../libsrc/bullet3-3.24/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" #include "../libsrc/bullet3-3.24/BulletCollision/CollisionShapes/btTriangleMesh.h" #include "../libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h" +using namespace RocketSim; + +std::filesystem::path RocketSim::_collisionMeshesFolder = {}; +std::mutex RocketSim::_beginInitMutex = {}; + struct MeshHashSet { std::unordered_map hashes; void AddAll(std::initializer_list hashesToAdd) { @@ -41,25 +41,24 @@ struct MeshHashSet { return hashes[hash]; } }; -static std::mutex beginInitMutex; static RocketSimStage stage = RocketSimStage::UNINITIALIZED; RocketSimStage RocketSim::GetStage() { return stage; } -std::vector& RocketSim::GetArenaCollisionShapes(GameMode gameMode) { +std::vector& RocketSim::GetArenaCollisionShapes(RocketSim::GameMode gameMode) { static std::vector arenaCollisionMeshes; static std::vector arenaCollisionMeshes_hoops; - return (gameMode == GameMode::HOOPS ? arenaCollisionMeshes_hoops : arenaCollisionMeshes); + return (gameMode == RocketSim::GameMode::HOOPS ? arenaCollisionMeshes_hoops : arenaCollisionMeshes); } #ifndef RS_NO_SUSPCOLGRID static SuspensionCollisionGrid suspColGrids_soccar[] = { {GameMode::SOCCAR, true}, {GameMode::SOCCAR, false} }, suspColGrids_hoops[] = { {GameMode::HOOPS, true}, {GameMode::HOOPS, false} }; -SuspensionCollisionGrid& RocketSim::GetDefaultSuspColGrid(GameMode gameMode, bool isLight) { + SuspensionCollisionGrid& RocketSim::GetDefaultSuspColGrid(GameMode gameMode, bool isLight) { if (gameMode == GameMode::HOOPS) { return suspColGrids_hoops[isLight]; } else { @@ -72,16 +71,17 @@ void RocketSim::Init(std::filesystem::path collisionMeshesFolder) { constexpr char MSG_PREFIX[] = "RocketSim::Init(): "; - beginInitMutex.lock(); + _beginInitMutex.lock(); { if (stage != RocketSimStage::UNINITIALIZED) { RS_WARN("RocketSim::Init() called again after already initialized, ignoring..."); - beginInitMutex.unlock(); + _beginInitMutex.unlock(); return; } RS_LOG("Initializing RocketSim version " RS_VERSION ", created by ZealanL..."); + _collisionMeshesFolder = collisionMeshesFolder; stage = RocketSimStage::INITIALIZING; uint64_t startMS = RS_CUR_MS(); @@ -162,11 +162,11 @@ void RocketSim::Init(std::filesystem::path collisionMeshesFolder) { stage = RocketSimStage::INITIALIZED; } - beginInitMutex.unlock(); + _beginInitMutex.unlock(); } void RocketSim::AssertInitialized(const char* errorMsgPrefix) { if (stage != RocketSimStage::INITIALIZED) { - RS_ERR_CLOSE(errorMsgPrefix << "RocketSim has not been initialized, call RocketSim::Init() first.") + RS_ERR_CLOSE(errorMsgPrefix << "RocketSim has not been initialized, call RocketSim::Init() first") } } diff --git a/src/RocketSim.h b/src/RocketSim.h index e7dac426..f3c59f66 100644 --- a/src/RocketSim.h +++ b/src/RocketSim.h @@ -12,13 +12,16 @@ class btBvhTriangleMeshShape; -enum class RocketSimStage : byte { - UNINITIALIZED, - INITIALIZING, - INITIALIZED -}; - namespace RocketSim { + enum class RocketSimStage : byte { + UNINITIALIZED, + INITIALIZING, + INITIALIZED + }; + + extern std::filesystem::path _collisionMeshesFolder; + extern std::mutex _beginInitMutex; + void Init(std::filesystem::path collisionMeshesFolder); void AssertInitialized(const char* errorMsgPrefix); diff --git a/src/Sim/Arena/Arena.cpp b/src/Sim/Arena/Arena.cpp index c468ed33..7fe94c07 100644 --- a/src/Sim/Arena/Arena.cpp +++ b/src/Sim/Arena/Arena.cpp @@ -1,5 +1,4 @@ #include "Arena.h" - #include "../../RocketSim.h" #include "../../../libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h" @@ -9,6 +8,7 @@ #include +RS_NS_START RSAPI void Arena::SetMutatorConfig(const MutatorConfig& mutatorConfig) { bool @@ -116,7 +116,7 @@ void Arena::SetBoostPickupCallback(BoostPickupEventFn callbackFunc, void* userIn void Arena::SetGoalScoreCallback(GoalScoreEventFn callbackFunc, void* userInfo) { if (gameMode == GameMode::THE_VOID) - RS_ERR_CLOSE("Cannot set a goal score callback when on THE_VOID gamemode!"); + RS_ERR_CLOSE("Cannot set a goal score callback when on THE_VOID gamemode"); _goalScoreCallback.func = callbackFunc; _goalScoreCallback.userInfo = userInfo; @@ -276,7 +276,8 @@ bool Arena::_BulletContactAddedCallback( arenaInst->ball->_OnWorldCollision(arenaInst->gameMode, contactPoint.m_normalWorldOnB, arenaInst->tickTime); // Set as special - contactPoint.m_isSpecial = true; + if (arenaInst->gameMode != GameMode::SNOWDAY) + contactPoint.m_isSpecial = true; } btAdjustInternalEdgeContacts( @@ -327,7 +328,11 @@ void Arena::_BtCallback_OnCarBallCollision(Car* car, Ball* ball, btManifoldPoint float relSpeed = RS_MIN(relVel.length(), BALL_CAR_EXTRA_IMPULSE_MAXDELTAVEL_UU); if (relSpeed > 0) { - float zScale = (gameMode == GameMode::HOOPS && car->_internalState.isOnGround) ? BALL_CAR_EXTRA_IMPULSE_Z_SCALE_HOOPS_GROUND : BALL_CAR_EXTRA_IMPULSE_Z_SCALE; + bool extraZScale = + gameMode == GameMode::HOOPS && + carState.isOnGround && + carState.rotMat.up.z > BALL_CAR_EXTRA_IMPULSE_Z_SCALE_HOOPS_NORMAL_Z_THRESH; + float zScale = extraZScale ? BALL_CAR_EXTRA_IMPULSE_Z_SCALE_HOOPS_GROUND : BALL_CAR_EXTRA_IMPULSE_Z_SCALE; btVector3 hitDir = (relPos * btVector3(1, 1, zScale)).safeNormalized(); btVector3 forwardDirAdjustment = carForward * hitDir.dot(carForward) * (1 - BALL_CAR_EXTRA_IMPULSE_FORWARD_SCALE); hitDir = (hitDir - forwardDirAdjustment).safeNormalized(); @@ -561,7 +566,7 @@ void Arena::Serialize(DataStreamOut& out) const { } } - if (gameMode == GameMode::SOCCAR) { // Serialize boost pads + if (_boostPads.size() > 0) { // Serialize boost pads out.Write(_boostPads.size()); for (auto pad : _boostPads) pad->GetState().Serialize(out); @@ -600,7 +605,7 @@ Arena* Arena::DeserializeNew(DataStreamIn& in) { #ifndef RS_MAX_SPEED if (newArena->_carIDMap.count(id)) - RS_ERR_CLOSE(ERROR_PREFIX << "Failed to load, got repeated car ID of " << id << "."); + RS_ERR_CLOSE(ERROR_PREFIX << "Failed to load, got repeated car ID of " << id); #endif Car* newCar = newArena->DeserializeNewCar(in, team); @@ -615,7 +620,7 @@ Arena* Arena::DeserializeNew(DataStreamIn& in) { } // Deserialize boost pads - if (gameMode == GameMode::SOCCAR) { + if (newArena->_boostPads.size() > 0) { uint32_t boostPadAmount = in.Read(); #ifndef RS_MAX_SPEED @@ -713,6 +718,9 @@ void Arena::Step(int ticksToSimulate) { #ifndef RS_NO_SUSPCOLGRID { // Add dynamic bodies to suspension grid for (Car* car : _cars) { + if (car->_internalState.isDemoed) + continue; + btVector3 min, max; car->_rigidBody.getAabb(min, max); _suspColGrid.UpdateDynamicCollisions(min, max, false); @@ -741,17 +749,7 @@ void Arena::Step(int ticksToSimulate) { if (hasArenaStuff) { #ifndef RS_NO_SUSPCOLGRID - { // Remove dynamic bodies from suspension grid - for (Car* car : _cars) { - btVector3 min, max; - car->_rigidBody.getAabb(min, max); - _suspColGrid.UpdateDynamicCollisions(min, max, true); - } - - btVector3 min, max; - ball->_rigidBody.getAabb(min, max); - _suspColGrid.UpdateDynamicCollisions(min, max, true); - } + _suspColGrid.ClearDynamicCollisions(); #endif } @@ -928,7 +926,7 @@ bool Arena::IsBallProbablyGoingIn(float maxTime, float extraMargin, Team* goalTe } } else { - RS_ERR_CLOSE("Arena::IsBallProbablyGoingIn() is not supported for: " << GAMEMODE_STRS[(int)gameMode]); + RS_ERR_CLOSE("Arena::IsBallProbablyGoingIn() is not supported for gamemode " << GAMEMODE_STRS[(int)gameMode]); return false; } } @@ -983,7 +981,7 @@ Arena::~Arena() { Ball::_DestroyBall(ball); } - if (gameMode == GameMode::SOCCAR) { + if (_boostPads.size() > 0) { if (ownsBoostPads) { // Remove all boost pads for (BoostPad* boostPad : _boostPads) @@ -1006,7 +1004,10 @@ void Arena::_SetupArenaCollisionShapes() { auto collisionMeshes = RocketSim::GetArenaCollisionShapes(gameMode); if (collisionMeshes.empty()) { - RS_ERR_CLOSE("Failed to setup arena collision meshes, no meshes found for game mode") + RS_ERR_CLOSE( + "No arena meshes found for gamemode " << GAMEMODE_STRS[(int)gameMode] << ", " << + "the mesh files should be in " << RocketSim::_collisionMeshesFolder + ) } _worldCollisionBvhShapes = new btBvhTriangleMeshShape[collisionMeshes.size()]; @@ -1126,3 +1127,5 @@ void Arena::SetCarBallCollision(bool enable) ball->_rigidBody.getBroadphaseHandle ()->m_collisionFilterMask = mask; } + +RS_NS_END diff --git a/src/Sim/Arena/Arena.h b/src/Sim/Arena/Arena.h index 007f276b..200e6bef 100644 --- a/src/Sim/Arena/Arena.h +++ b/src/Sim/Arena/Arena.h @@ -18,6 +18,8 @@ #include "../../../libsrc/bullet3-3.24/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h" #include "../../../libsrc/bullet3-3.24/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h" +RS_NS_START + // Mode of speed/memory optimization for the arena // Will affect whether high memory consumption is used to slightly increase speed or not enum class ArenaMemWeightMode : byte { @@ -219,3 +221,5 @@ class Arena { // Making this private because horrible memory overflows would happen if you changed it ArenaMemWeightMode _memWeightMode; }; + +RS_NS_END diff --git a/src/Sim/Ball/Ball.cpp b/src/Sim/Ball/Ball.cpp index 76edf8c5..5291054f 100644 --- a/src/Sim/Ball/Ball.cpp +++ b/src/Sim/Ball/Ball.cpp @@ -7,6 +7,8 @@ #include "../../../libsrc/bullet3-3.24/BulletCollision/CollisionShapes/btConvexHullShape.h" #include "../CollisionMasks.h" +RS_NS_START + bool BallState::Matches(const BallState& other, float marginPos, float marginVel, float marginAngVel) const { return pos.DistSq(other.pos) < (marginPos * marginPos) && @@ -221,3 +223,5 @@ void Ball::_OnWorldCollision(GameMode gameMode, Vec normal, float tickTime) { } } } + +RS_NS_END diff --git a/src/Sim/Ball/Ball.h b/src/Sim/Ball/Ball.h index 08c60eb3..816dc441 100644 --- a/src/Sim/Ball/Ball.h +++ b/src/Sim/Ball/Ball.h @@ -10,10 +10,14 @@ #include "../../../libsrc/bullet3-3.24/BulletDynamics/Dynamics/btRigidBody.h" #include "../../../libsrc/bullet3-3.24/BulletCollision/CollisionShapes/btSphereShape.h" +class btDynamicsWorld; + +RS_NS_START + struct BallState { // Incremented every update, reset when SetState() is called -// Used for telling if a stateset occured -// Not serialized + // Used for telling if a stateset occured + // Not serialized uint64_t updateCounter = 0; // Position in world space @@ -66,7 +70,7 @@ class Ball { // For removal by Arena static void _DestroyBall(Ball* ball) { delete ball; } - void _BulletSetup(GameMode gameMode, class btDynamicsWorld* bulletWorld, const MutatorConfig& mutatorConfig); + void _BulletSetup(GameMode gameMode, btDynamicsWorld* bulletWorld, const MutatorConfig& mutatorConfig); bool groundStickApplied = false; Vec _velocityImpulseCache = { 0,0,0 }; @@ -96,3 +100,5 @@ class Ball { private: Ball() {} }; + +RS_NS_END diff --git a/src/Sim/BallHitInfo/BallHitInfo.cpp b/src/Sim/BallHitInfo/BallHitInfo.cpp index dc18964f..7cab812a 100644 --- a/src/Sim/BallHitInfo/BallHitInfo.cpp +++ b/src/Sim/BallHitInfo/BallHitInfo.cpp @@ -1,5 +1,7 @@ #include "BallHitInfo.h" +RS_NS_START + void BallHitInfo::Serialize(DataStreamOut& out) const { out.Write(isValid); @@ -12,4 +14,6 @@ void BallHitInfo::Deserialize(DataStreamIn& in) { if (isValid) in.ReadMultiple(BALLHITINFO_SERIALIZATION_FIELDS); -} \ No newline at end of file +} + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/BallHitInfo/BallHitInfo.h b/src/Sim/BallHitInfo/BallHitInfo.h index c3026aa6..852e79e8 100644 --- a/src/Sim/BallHitInfo/BallHitInfo.h +++ b/src/Sim/BallHitInfo/BallHitInfo.h @@ -4,6 +4,8 @@ #include "../../DataStream/DataStreamIn.h" #include "../../DataStream/DataStreamOut.h" +RS_NS_START + struct BallHitInfo { // If false, all other fields within this struct should not be trusted bool isValid = false; @@ -26,3 +28,5 @@ struct BallHitInfo { // NOTE: Does not include isValid #define BALLHITINFO_SERIALIZATION_FIELDS \ relativePosOnBall, ballPos, extraHitVel, tickCountWhenHit, tickCountWhenExtraImpulseApplied + +RS_NS_END diff --git a/src/Sim/BallPredTracker/BallPredTracker.cpp b/src/Sim/BallPredTracker/BallPredTracker.cpp index a2f6fca8..90a43d60 100644 --- a/src/Sim/BallPredTracker/BallPredTracker.cpp +++ b/src/Sim/BallPredTracker/BallPredTracker.cpp @@ -1,5 +1,7 @@ #include "BallPredTracker.h" +RS_NS_START + BallPredTracker::BallPredTracker(Arena* arena, size_t numPredTicks) : numPredTicks(numPredTicks) { // Make ball pred arena this->ballPredArena = Arena::Create(arena->gameMode, ArenaMemWeightMode::LIGHT, arena->GetTickRate()); @@ -61,3 +63,5 @@ void BallPredTracker::ForceUpdateAllPred(Arena* arena) { BallState BallPredTracker::GetBallStateForTime(float predTime) const { return BallState(); } + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/BallPredTracker/BallPredTracker.h b/src/Sim/BallPredTracker/BallPredTracker.h index 315fff21..20e9d2ec 100644 --- a/src/Sim/BallPredTracker/BallPredTracker.h +++ b/src/Sim/BallPredTracker/BallPredTracker.h @@ -1,12 +1,16 @@ #pragma once #include "../Arena/Arena.h" +RS_NS_START + // An external tool struct that predicts the ball of a given arena struct BallPredTracker { Arena* ballPredArena; std::vector predData; size_t numPredTicks; + // arena: The arena you want to predict the ball for (BallPredTracker will make a copy of it without the cars) + // You do not need to make another arena for BallPredTracker, it does that itself BallPredTracker(Arena* arena, size_t numPredTicks); ~BallPredTracker(); @@ -22,4 +26,6 @@ struct BallPredTracker { // Get the predicted ball state at a given future time delta BallState GetBallStateForTime(float predTime) const; -}; \ No newline at end of file +}; + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/BoostPad/BoostPad.cpp b/src/Sim/BoostPad/BoostPad.cpp index 08149b92..bbeae819 100644 --- a/src/Sim/BoostPad/BoostPad.cpp +++ b/src/Sim/BoostPad/BoostPad.cpp @@ -4,6 +4,8 @@ #include "../../../libsrc/bullet3-3.24/BulletDynamics/Dynamics/btRigidBody.h" +RS_NS_START + BoostPad* BoostPad::_AllocBoostPad() { return new BoostPad(); } @@ -95,3 +97,5 @@ void BoostPadState::Deserialize(DataStreamIn& in) { BOOSTPAD_SERIALIZATION_FIELDS ); } + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/BoostPad/BoostPad.h b/src/Sim/BoostPad/BoostPad.h index 7eb488b8..652bfa68 100644 --- a/src/Sim/BoostPad/BoostPad.h +++ b/src/Sim/BoostPad/BoostPad.h @@ -8,6 +8,8 @@ #include "../MutatorConfig/MutatorConfig.h" +RS_NS_START + struct BoostPadState { bool isActive = true; float cooldown = 0; @@ -45,3 +47,5 @@ class BoostPad { private: BoostPad() {} }; + +RS_NS_END diff --git a/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.cpp b/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.cpp index ac879830..4a5ffe18 100644 --- a/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.cpp +++ b/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.cpp @@ -1,5 +1,7 @@ #include "BoostPadGrid.h" +RS_NS_START + void BoostPadGrid::CheckCollision(Car* car) { if (car->_internalState.isDemoed || car->_internalState.boost >= 100) return; @@ -37,3 +39,5 @@ void BoostPadGrid::Add(BoostPad* pad) { ptrInArray = pad; } } + +RS_NS_END diff --git a/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.h b/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.h index 469eebd6..583b08a2 100644 --- a/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.h +++ b/src/Sim/BoostPad/BoostPadGrid/BoostPadGrid.h @@ -4,6 +4,8 @@ #include "../BoostPad.h" +RS_NS_START + struct BoostPadGrid { constexpr static float EXTENT_X = 4096.f, @@ -24,3 +26,5 @@ struct BoostPadGrid { void CheckCollision(Car* car); void Add(BoostPad* pad); }; + +RS_NS_END diff --git a/src/Sim/Car/Car.cpp b/src/Sim/Car/Car.cpp index c9d8caa8..8189426c 100644 --- a/src/Sim/Car/Car.cpp +++ b/src/Sim/Car/Car.cpp @@ -4,6 +4,8 @@ #include "../../../libsrc/bullet3-3.24/BulletDynamics/Dynamics/btDynamicsWorld.h" +RS_NS_START + // Update our internal state from bullet and return it CarState Car::GetState() { if (!_internalState.isDemoed) { @@ -71,18 +73,12 @@ void Car::_PreTickUpdate(GameMode gameMode, float tickTime, const MutatorConfig& _internalState.demoRespawnTimer = RS_MAX(_internalState.demoRespawnTimer - tickTime, 0); if (_internalState.demoRespawnTimer == 0) Respawn(gameMode, -1, mutatorConfig.carSpawnBoostAmount); - } - if (_internalState.isDemoed) { // Disable rigidbody simulation _rigidBody.m_activationState1 = DISABLE_SIMULATION; _rigidBody.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE; - // Put car far away from anything going on in the arena - _rigidBody.m_worldTransform.m_origin = btVector3(0, 0, -1000); - // Don't bother updating anything - return; } else { // Prevent the car's RB from becoming inactive _rigidBody.m_activationState1 = ACTIVE_TAG; @@ -90,6 +86,9 @@ void Car::_PreTickUpdate(GameMode gameMode, float tickTime, const MutatorConfig& } } + if (_internalState.isDemoed) + return; // No other updates need to occur + // Do first part of the btVehicleRL update (update wheel transforms, do traces, calculate friction impulses) _bulletVehicle.updateVehicleFirst(tickTime, grid); @@ -564,7 +563,12 @@ void Car::_UpdateAirTorque(float tickTime, const MutatorConfig& mutatorConfig, b float pitchScale = 1; if (relDodgeTorque.y() != 0 && controls.pitch != 0) { if (RS_SGN(relDodgeTorque.y()) == RS_SGN(controls.pitch)) { - pitchScale = 0; + +#ifndef RS_MAX_SPEED + pitchScale = 1 - RS_MIN(abs(controls.pitch), 1); // Sanity clamp +#else + pitchScale = 1 - abs(controls.pitch); // No sanity check +#endif doAirControl = true; } } @@ -811,5 +815,7 @@ void Car::_UpdateAutoRoll(float tickTime, const MutatorConfig& mutatorConfig, in Vec torqueForward = torqueDirForward * forwardTorqueFactor; _rigidBody.applyCentralForce(groundDownDir * RLConst::CAR_AUTOROLL_FORCE * UU_TO_BT * CAR_MASS_BT); - _rigidBody.m_angularVelocity += (torqueForward + torqueRight) * RLConst::CAR_AUTOROLL_TORQUE * tickTime; + _rigidBody.applyTorque(_rigidBody.m_invInertiaTensorWorld.inverse() * (torqueForward + torqueRight) * RLConst::CAR_AUTOROLL_TORQUE); } + +RS_NS_END diff --git a/src/Sim/Car/Car.h b/src/Sim/Car/Car.h index 172a021f..536373d9 100644 --- a/src/Sim/Car/Car.h +++ b/src/Sim/Car/Car.h @@ -11,6 +11,8 @@ #include "../../../libsrc/bullet3-3.24/BulletCollision/CollisionShapes/btCompoundShape.h" #include "../../../src/Sim/btVehicleRL/btVehicleRL.h" +RS_NS_START + struct CarState { // Incremented every update, reset when SetState() is called @@ -177,4 +179,6 @@ class Car { void _UpdateAutoRoll(float tickTime, const MutatorConfig& mutatorConfig, int numWheelsInContact); Car() {} -}; \ No newline at end of file +}; + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/Car/CarConfig/CarConfig.cpp b/src/Sim/Car/CarConfig/CarConfig.cpp index af70b8a5..fba7ee22 100644 --- a/src/Sim/Car/CarConfig/CarConfig.cpp +++ b/src/Sim/Car/CarConfig/CarConfig.cpp @@ -1,5 +1,7 @@ #include "CarConfig.h" +RS_NS_START + // Default car-type config definitions // For those confused about the hitbox numbers, @@ -81,4 +83,6 @@ MAKE_CAR_CONFIG(DOMINUS, 1); MAKE_CAR_CONFIG(PLANK, 2); MAKE_CAR_CONFIG(BREAKOUT, 3); MAKE_CAR_CONFIG(HYBRID, 4); -MAKE_CAR_CONFIG(MERC, 5); \ No newline at end of file +MAKE_CAR_CONFIG(MERC, 5); + +RS_NS_END diff --git a/src/Sim/Car/CarConfig/CarConfig.h b/src/Sim/Car/CarConfig/CarConfig.h index b9785397..2cf23f77 100644 --- a/src/Sim/Car/CarConfig/CarConfig.h +++ b/src/Sim/Car/CarConfig/CarConfig.h @@ -1,6 +1,8 @@ #pragma once #include "../../../BaseInc.h" +RS_NS_START + struct WheelPairConfig { // Radius of both wheels float wheelRadius = 0.0f; @@ -39,3 +41,5 @@ WHEEL_PAIR_CONFIG_SERIALIZATION_FIELDS(name.backWheels) \ // NOTE: CAR_CONFIG_PLANK is the batmobile preset RSAPI const extern CarConfig CAR_CONFIG_OCTANE, CAR_CONFIG_DOMINUS, CAR_CONFIG_PLANK, CAR_CONFIG_BREAKOUT, CAR_CONFIG_HYBRID, CAR_CONFIG_MERC; + +RS_NS_END diff --git a/src/Sim/CarControls.h b/src/Sim/CarControls.h index ebd48bf7..c819a99e 100644 --- a/src/Sim/CarControls.h +++ b/src/Sim/CarControls.h @@ -3,6 +3,8 @@ #include +RS_NS_START + // Stores all control inputs to a car struct CarControls { // Driving control @@ -31,3 +33,5 @@ struct CarControls { name.throttle, name.steer, \ name.pitch, name.yaw, name.roll, \ name.boost, name.jump, name.handbrake + +RS_NS_END diff --git a/src/Sim/CollisionMasks.h b/src/Sim/CollisionMasks.h index a4d961ed..3badf9c0 100644 --- a/src/Sim/CollisionMasks.h +++ b/src/Sim/CollisionMasks.h @@ -1,8 +1,12 @@ #pragma once #include "../Framework.h" +RS_NS_START + // Collision masks for different types of objects // Used so that the net in hoops doesn't collide with the cars enum CollisionMasks : uint32_t { HOOPS_NET = (1 << 8) -}; \ No newline at end of file +}; + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/GameEventTracker/GameEventTracker.cpp b/src/Sim/GameEventTracker/GameEventTracker.cpp index 7f03e2e7..0dae55bc 100644 --- a/src/Sim/GameEventTracker/GameEventTracker.cpp +++ b/src/Sim/GameEventTracker/GameEventTracker.cpp @@ -1,5 +1,7 @@ #include "GameEventTracker.h" +RS_NS_START + bool GetShooterPasser(Arena* arena, Team team, Car*& shooterOut, bool findPasser, Car*& passerOut, uint64_t maxShooterTicks, uint64_t maxPasserTicks) { shooterOut = passerOut = NULL; // TODO: Instead of looping over cars to find who hit it last, use persistent info @@ -159,3 +161,5 @@ void GameEventTracker::ResetPersistentInfo() { // _ballShotGoalTeam doesn't need to be reset } + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/GameEventTracker/GameEventTracker.h b/src/Sim/GameEventTracker/GameEventTracker.h index 13a2cc1f..66f08eb1 100644 --- a/src/Sim/GameEventTracker/GameEventTracker.h +++ b/src/Sim/GameEventTracker/GameEventTracker.h @@ -1,6 +1,8 @@ #pragma once #include "../Arena/Arena.h" +RS_NS_START + typedef std::function ShotEventFn; typedef std::function GoalEventFn; typedef std::function SaveEventFn; @@ -95,4 +97,6 @@ struct GameEventTracker { // Automatically called from Update() when the ball's state has been set since last update // Call this whenever you set the arena to a new state if you want to be extra safe RSAPI void ResetPersistentInfo(); -}; \ No newline at end of file +}; + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/GameMode.h b/src/Sim/GameMode.h index 905d0fff..07166a27 100644 --- a/src/Sim/GameMode.h +++ b/src/Sim/GameMode.h @@ -1,6 +1,8 @@ #pragma once #include "../Framework.h" +RS_NS_START + enum class GameMode : byte { SOCCAR, HOOPS, @@ -20,3 +22,5 @@ constexpr const char* GAMEMODE_STRS[] = { "snowday", "the_void", }; + +RS_NS_END diff --git a/src/Sim/MutatorConfig/MutatorConfig.cpp b/src/Sim/MutatorConfig/MutatorConfig.cpp index 18876ca6..799435c2 100644 --- a/src/Sim/MutatorConfig/MutatorConfig.cpp +++ b/src/Sim/MutatorConfig/MutatorConfig.cpp @@ -1,5 +1,7 @@ #include "MutatorConfig.h" +RS_NS_START + MutatorConfig::MutatorConfig(GameMode gameMode) { using namespace RLConst; @@ -34,8 +36,10 @@ void MutatorConfig::Deserialize(DataStreamIn& in) { uint16_t argCount = in.Read(); if (argCount != RS_GET_ARGUMENT_COUNT(MUTATOR_CONFIG_SERIALIZATION_FIELDS)) { - RS_ERR_CLOSE(" MutatorConfig::Deserialize(): Mutator config is from a different version of RocketSim, fields don't match!"); + RS_ERR_CLOSE(" MutatorConfig::Deserialize(): Mutator config is from a different version of RocketSim, fields don't match"); } in.ReadMultiple(MUTATOR_CONFIG_SERIALIZATION_FIELDS); -} \ No newline at end of file +} + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/MutatorConfig/MutatorConfig.h b/src/Sim/MutatorConfig/MutatorConfig.h index d6f66ff6..b3a26dc2 100644 --- a/src/Sim/MutatorConfig/MutatorConfig.h +++ b/src/Sim/MutatorConfig/MutatorConfig.h @@ -5,6 +5,8 @@ #include "../../DataStream/DataStreamIn.h" #include "../../DataStream/DataStreamOut.h" +RS_NS_START + enum class DemoMode : byte { NORMAL, ON_CONTACT, @@ -78,3 +80,5 @@ jumpImmediateForce, boostAccel, boostUsedPerSecond, respawnDelay, \ carSpawnBoostAmount, bumpCooldownTime, boostPadCooldown_Big, boostPadCooldown_Small, \ ballHitExtraForceScale, bumpForceScale, ballRadius, unlimitedFlips, unlimitedDoubleJumps, \ demoMode, enableTeamDemos, enableCarCarCollision, enableCarBallCollision + +RS_NS_END diff --git a/src/Sim/SuspensionCollisionGrid/SuspensionCollisionGrid.cpp b/src/Sim/SuspensionCollisionGrid/SuspensionCollisionGrid.cpp index a27ab2a4..7ab627b2 100644 --- a/src/Sim/SuspensionCollisionGrid/SuspensionCollisionGrid.cpp +++ b/src/Sim/SuspensionCollisionGrid/SuspensionCollisionGrid.cpp @@ -3,6 +3,8 @@ #include "../../../libsrc/bullet3-3.24/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h" #include "../../../libsrc/bullet3-3.24/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" +RS_NS_START + // Quick virtual btTriangleCallback child class to simply check if any triangles are processed struct BoolHitTriangleCallback : public btTriangleCallback { @@ -120,11 +122,15 @@ void SuspensionCollisionGrid::SetupWorldCollision(const std::vector -btCollisionObject* _CastSuspensionRay(SuspensionCollisionGrid& grid, btVehicleRaycaster* raycaster, Vec start, Vec end, btVehicleRaycaster::btVehicleRaycasterResult& result) { +btCollisionObject* _CastSuspensionRay( + SuspensionCollisionGrid& grid, btVehicleRaycaster* raycaster, + Vec start, Vec end, const btCollisionObject* ignoreObj, btVehicleRaycaster::btVehicleRaycasterResult& result +) { SuspensionCollisionGrid::Cell& cell = grid.GetCellFromPos(start * BT_TO_UU); - if (cell.worldCollision || cell.dynamicObjects > 1) { - return (btCollisionObject*)raycaster->castRay(start, end, result); + if (cell.worldCollision || cell.dynamicCollision) { + // TODO: Do world-only or dynamic-only raycasts + return (btCollisionObject*)raycaster->castRay(start, end, ignoreObj, result); } else { Vec delta = end - start; float dist = delta.Length(); @@ -168,11 +174,11 @@ btCollisionObject* _CastSuspensionRay(SuspensionCollisionGrid& grid, btVehicleRa } } -btCollisionObject* SuspensionCollisionGrid::CastSuspensionRay(btVehicleRaycaster* raycaster, Vec start, Vec end, btVehicleRaycaster::btVehicleRaycasterResult& result) { +btCollisionObject* SuspensionCollisionGrid::CastSuspensionRay(btVehicleRaycaster* raycaster, Vec start, Vec end, const btCollisionObject* ignoreObj, btVehicleRaycaster::btVehicleRaycasterResult& result) { if (lightMem) { - return _CastSuspensionRay(*this, raycaster, start, end, result); + return _CastSuspensionRay(*this, raycaster, start, end, ignoreObj, result); } else { - return _CastSuspensionRay(*this, raycaster, start, end, result); + return _CastSuspensionRay(*this, raycaster, start, end, ignoreObj, result); } } @@ -189,7 +195,14 @@ void _UpdateDynamicCollisions(SuspensionCollisionGrid& grid, Vec minBT, Vec maxB for (int i = i1; i <= i2; i++) for (int j = j1; j <= j2; j++) for (int k = k1; k <= k2; k++) - grid.Get(i, j, k).dynamicObjects += deltaVal; + grid.Get(i, j, k).dynamicCollision = true; + + grid.dynamicCellRanges.push_back( + { + i1, j1, k1, + i2, j2, k2 + } + ); } void SuspensionCollisionGrid::UpdateDynamicCollisions(Vec minBT, Vec maxBT, bool remove) { @@ -198,4 +211,26 @@ void SuspensionCollisionGrid::UpdateDynamicCollisions(Vec minBT, Vec maxBT, bool } else { return _UpdateDynamicCollisions(*this, minBT, maxBT, remove); } -} \ No newline at end of file +} + +template +void _ClearDynamicCollisions(SuspensionCollisionGrid& grid) { + for (auto& range : grid.dynamicCellRanges) { + for (int i = range.minX; i <= range.maxX; i++) + for (int j = range.minY; j <= range.maxY; j++) + for (int k = range.minZ; k <= range.maxZ; k++) + grid.Get(i, j, k).dynamicCollision = false; + } + + grid.dynamicCellRanges.clear(); +} + +void SuspensionCollisionGrid::ClearDynamicCollisions() { + if (lightMem) { + return _ClearDynamicCollisions(*this); + } else { + return _ClearDynamicCollisions(*this); + } +} + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/SuspensionCollisionGrid/SuspensionCollisionGrid.h b/src/Sim/SuspensionCollisionGrid/SuspensionCollisionGrid.h index 1d5b9685..08868775 100644 --- a/src/Sim/SuspensionCollisionGrid/SuspensionCollisionGrid.h +++ b/src/Sim/SuspensionCollisionGrid/SuspensionCollisionGrid.h @@ -3,6 +3,8 @@ class btBvhTriangleMeshShape; +RS_NS_START + struct SuspensionCollisionGrid { GameMode gameMode; bool lightMem; @@ -27,9 +29,16 @@ struct SuspensionCollisionGrid { static_assert(RS_MIN(CELL_SIZE_X[0], RS_MIN(CELL_SIZE_Y[0], CELL_SIZE_Z[0])) > 60, "SuspensionCollisionGrid cells are too small"); struct Cell { - bool worldCollision = false; - int dynamicObjects = 0; + bool + worldCollision = false, + dynamicCollision = false; + }; + + struct CellRange { + int minX, minY, minZ; + int maxX, maxY, maxZ; }; + std::vector dynamicCellRanges; struct { float extentX_bt, extentY_bt, height_bt; @@ -91,8 +100,12 @@ struct SuspensionCollisionGrid { void SetupWorldCollision(const std::vector& triMeshShapes); - btCollisionObject* CastSuspensionRay(btVehicleRaycaster* raycaster, Vec start, Vec end, btVehicleRaycaster::btVehicleRaycasterResult& result); + btCollisionObject* CastSuspensionRay(btVehicleRaycaster* raycaster, Vec start, Vec end, const btCollisionObject* ignoreObj, btVehicleRaycaster::btVehicleRaycasterResult& result); + void UpdateDynamicCollisions(Vec minBT, Vec maxBT, bool remove); + void ClearDynamicCollisions(); btRigidBody* defaultWorldCollisionRB = NULL; }; + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/btVehicleRL/btVehicleRL.cpp b/src/Sim/btVehicleRL/btVehicleRL.cpp index 7141faba..7d690e23 100644 --- a/src/Sim/btVehicleRL/btVehicleRL.cpp +++ b/src/Sim/btVehicleRL/btVehicleRL.cpp @@ -7,6 +7,8 @@ #include "../../../libsrc/bullet3-3.24/BulletDynamics/Dynamics/btDynamicsWorld.h" #include "../../../libsrc/bullet3-3.24/BulletDynamics/ConstraintSolver/btContactConstraint.h" +RS_NS_START + btVehicleRL::btVehicleRL(const btVehicleTuning& tuning, btRigidBody* chassis, btVehicleRaycaster* raycaster, btDynamicsWorld* world) : m_vehicleRaycaster(raycaster), m_pitchControl(0), m_dynamicsWorld(world) { m_chassisBody = chassis; @@ -130,9 +132,9 @@ float btVehicleRL::rayCast(btWheelInfoRL& wheel, SuspensionCollisionGrid* grid) btCollisionObject* object; if (grid) { - object = grid->CastSuspensionRay(m_vehicleRaycaster, source, target, rayResults); + object = grid->CastSuspensionRay(m_vehicleRaycaster, source, target, m_chassisBody, rayResults); } else { - object = (btCollisionObject*)m_vehicleRaycaster->castRay(source, target, rayResults); + object = (btCollisionObject*)m_vehicleRaycaster->castRay(source, target, m_chassisBody, rayResults); } if (object) { @@ -411,4 +413,6 @@ btVector3 btVehicleRL::getUpwardsDirFromWheelContacts() { float btVehicleRL::getForwardSpeed() { return m_chassisBody->getLinearVelocity().dot(getForwardVector()); -} \ No newline at end of file +} + +RS_NS_END \ No newline at end of file diff --git a/src/Sim/btVehicleRL/btVehicleRL.h b/src/Sim/btVehicleRL/btVehicleRL.h index 6e5d9181..d743d5b0 100644 --- a/src/Sim/btVehicleRL/btVehicleRL.h +++ b/src/Sim/btVehicleRL/btVehicleRL.h @@ -3,6 +3,8 @@ #include "../../../libsrc/bullet3-3.24/BulletDynamics/Vehicle/btDefaultVehicleRaycaster.h" +RS_NS_START + // This is a modified version of btWheelInfo to more accurately follow Rocket League struct btWheelInfoRL : public btWheelInfo { bool m_isInContactWithWorld = false; @@ -206,4 +208,6 @@ class btVehicleRL : public btActionInterface { // Extra utility funcs btVector3 getUpwardsDirFromWheelContacts(); float getForwardSpeed(); -}; \ No newline at end of file +}; + +RS_NS_END \ No newline at end of file