Skip to content

Commit

Permalink
Add last_rel_dodge_torque for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mtheall committed May 5, 2024
1 parent e0b9141 commit 759f994
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
35 changes: 33 additions & 2 deletions python-mtheall/CarState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@
#include <algorithm>
#include <cstddef>
#include <cstring>
#include <mutex>

namespace RocketSim::Python
{
constexpr unsigned NUM_WHEELS = std::extent_v<decltype (RocketSim::CarState::wheelsWithContact)>;

std::once_flag lastRelDodgeTorqueWarnOnce;

void warnLastRelDodgeTorque ()
{
std::call_once (lastRelDodgeTorqueWarnOnce,
&std::fprintf,
stderr,
"last_rel_dodge_torque is a deprecated alias of flip_rel_torque\n");
}

PyTypeObject *CarState::Type = nullptr;

PyMemberDef CarState::Members[] = {
Expand Down Expand Up @@ -167,6 +178,7 @@ PyGetSetDef CarState::GetSet[] = {
GETSET_ENTRY (CarState, rot_mat, "Rotation matrix"),
GETSET_ENTRY (CarState, vel, "Velocity"),
GETSET_ENTRY (CarState, ang_vel, "Angular velocity"),
GETSET_ENTRY (CarState, last_rel_dodge_torque, "Deprecated alias of flip_rel_torque"),
GETSET_ENTRY (CarState, flip_rel_torque, "Flip relative torque"),
GETSET_ENTRY (CarState, last_controls, "Last controls"),
GETSET_ENTRY (CarState, world_contact_normal, "World contact normal"),
Expand Down Expand Up @@ -336,6 +348,7 @@ int CarState::Init (CarState *self_, PyObject *args_, PyObject *kwds_) noexcept
static char ballHitInfoKwd[] = "ball_hit_info";
static char lastControlsKwd[] = "last_controls";
static char updateCounterKwd[] = "update_counter";
static char lastRelDodgeTorqueKwd[] = "last_rel_dodge_torque";

static char *dict[] = {posKwd,
rotMatKwd,
Expand Down Expand Up @@ -369,6 +382,7 @@ int CarState::Init (CarState *self_, PyObject *args_, PyObject *kwds_) noexcept
ballHitInfoKwd,
lastControlsKwd,
updateCounterKwd,
lastRelDodgeTorqueKwd,
nullptr};

RocketSim::CarState state{};
Expand All @@ -382,6 +396,7 @@ int CarState::Init (CarState *self_, PyObject *args_, PyObject *kwds_) noexcept
PyObject *lastControls = nullptr;
PyObject *worldContactNormal = nullptr;
PyObject *ballHitInfo = nullptr;
PyObject *lastRelDodgeTorque = nullptr;

int isOnGround = state.isOnGround;
int hasJumped = state.hasJumped;
Expand All @@ -398,7 +413,7 @@ int CarState::Init (CarState *self_, PyObject *args_, PyObject *kwds_) noexcept
unsigned long long updateCounter = state.updateCounter;
if (!PyArg_ParseTupleAndKeywords (args_,
kwds_,
"|O!O!O!O!pOpppO!ffppffffpffpfpO!kfpfO!O!K",
"|O!O!O!O!pOpppO!ffppffffpffpfpO!kfpfO!O!K$O!",
dict,
Vec::Type,
&pos,
Expand Down Expand Up @@ -439,7 +454,9 @@ int CarState::Init (CarState *self_, PyObject *args_, PyObject *kwds_) noexcept
&ballHitInfo,
CarControls::Type,
&lastControls,
&updateCounter))
&updateCounter,
Vec::Type,
&lastRelDodgeTorque))
return -1;

if (pos)
Expand All @@ -465,6 +482,8 @@ int CarState::Init (CarState *self_, PyObject *args_, PyObject *kwds_) noexcept

if (flipRelTorque)
state.flipRelTorque = Vec::ToVec (PyCast<Vec> (flipRelTorque));
else if (lastRelDodgeTorque)
state.flipRelTorque = Vec::ToVec (PyCast<Vec> (lastRelDodgeTorque));

if (worldContactNormal)
state.worldContact.contactNormal = Vec::ToVec (PyCast<Vec> (worldContactNormal));
Expand Down Expand Up @@ -848,6 +867,18 @@ int CarState::Setang_vel (CarState *self_, PyObject *value_, void *) noexcept
return 0;
}

PyObject *CarState::Getlast_rel_dodge_torque (CarState *self_, void *closure_) noexcept
{
warnLastRelDodgeTorque ();
return Getflip_rel_torque (self_, closure_);
}

int CarState::Setlast_rel_dodge_torque (CarState *self_, PyObject *value_, void *closure_) noexcept
{
warnLastRelDodgeTorque ();
return Setflip_rel_torque (self_, value_, closure_);
}

PyObject *CarState::Getflip_rel_torque (CarState *self_, void *) noexcept
{
return PyRef<Vec>::incRef (self_->flipRelTorque).giftObject ();
Expand Down
2 changes: 1 addition & 1 deletion python-mtheall/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ wheel: build
$(PYTHON) ../setup.py bdist_wheel --py-limited-api=cp34

install: wheel
$(PYTHON) -m pip install --force-reinstall --user ./dist/RocketSim-2.1.0a5-cp34-abi3-linux_x86_64.whl
$(PYTHON) -m pip install --force-reinstall --user ./dist/RocketSim-2.1.0a6-cp34-abi3-linux_x86_64.whl

clean:
$(RM) -r build/ dist/ RocketSim.egg-info/
1 change: 1 addition & 0 deletions python-mtheall/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ struct CarState
GETSET_DECLARE (CarState, rot_mat)
GETSET_DECLARE (CarState, vel)
GETSET_DECLARE (CarState, ang_vel)
GETSET_DECLARE (CarState, last_rel_dodge_torque)
GETSET_DECLARE (CarState, flip_rel_torque)
GETSET_DECLARE (CarState, last_controls)
GETSET_DECLARE (CarState, world_contact_normal)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def build_extension(self, ext):

setup(
name = "RocketSim",
version = "2.1.0a5",
version = "2.1.0a6",
description = "This is Rocket League!",
cmdclass = {"build_ext": build_ext_ex},
ext_modules = [RocketSim],
Expand Down

0 comments on commit 759f994

Please sign in to comment.