Skip to content

Commit

Permalink
Merge pull request #265 from Hoikas/pyStereizer
Browse files Browse the repository at this point in the history
Implement `pyStereizer` bindings for `plStereizer`.
  • Loading branch information
Hoikas authored Mar 5, 2023
2 parents f251fbb + c55e2e6 commit b56c71b
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ set(PRP_ANIM_SOURCES
PRP/Animation/pySimpleRotController.cpp
PRP/Animation/pySimpleScaleController.cpp
PRP/Animation/pySplineEaseCurve.cpp
PRP/Animation/pyStereizer.cpp
PRP/Animation/pyTMController.cpp
PRP/Animation/pyViewFaceModifier.cpp
)
Expand All @@ -96,6 +97,7 @@ set(PRP_ANIM_HEADERS
PRP/Animation/pyPosController.h
PRP/Animation/pyRotController.h
PRP/Animation/pyScaleController.h
PRP/Animation/pyStereizer.h
PRP/Animation/pyViewFaceModifier.h
)

Expand Down
2 changes: 2 additions & 0 deletions Python/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "PRP/Animation/pyPosController.h"
#include "PRP/Animation/pyRotController.h"
#include "PRP/Animation/pyScaleController.h"
#include "PRP/Animation/pyStereizer.h"
#include "PRP/Animation/pyViewFaceModifier.h"
#include "PRP/Avatar/pyAGAnim.h"
#include "PRP/Avatar/pyAGApplicator.h"
Expand Down Expand Up @@ -819,6 +820,7 @@ PyMODINIT_FUNC PyInit_PyHSPlasma()
PyModule_AddObject(module, "plActivePrintShape", Init_pyActivePrintShape_Type());
PyModule_AddObject(module, "plGrassShaderMod", Init_pyGrassShaderMod_Type());
PyModule_AddObject(module, "plPhysicalSndGroup", Init_pyPhysicalSndGroup_Type());
PyModule_AddObject(module, "plStereizer", Init_pyStereizer_Type());

PyModule_AddObject(module, "plSharedMesh", Init_pySharedMesh_Type());
PyModule_AddObject(module, "plSpaceTree", Init_pySpaceTree_Type());
Expand Down
88 changes: 88 additions & 0 deletions Python/PRP/Animation/pyStereizer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* This file is part of HSPlasma.
*
* HSPlasma is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HSPlasma is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HSPlasma. If not, see <http://www.gnu.org/licenses/>.
*/

#include "pyStereizer.h"

#include <PRP/Animation/plStereizer.h>
#include "Math/pyGeometry3.h"
#include "PRP/Modifier/pyModifier.h"

PY_PLASMA_NEW(Stereizer, plStereizer)

PY_PROPERTY(float, Stereizer, ambientDist, getAmbientDist, setAmbientDist)
PY_PROPERTY(float, Stereizer, transition, getTransition, setTransition)

PY_GETSET_GETTER_DECL(Stereizer, sepDist)
{
PyObject* sepDist = PyTuple_New(2);
PyTuple_SET_ITEM(sepDist, 0, pyPlasma_convert(self->fThis->getMinSepDist()));
PyTuple_SET_ITEM(sepDist, 1, pyPlasma_convert(self->fThis->getMaxSepDist()));
return sepDist;
}

PY_GETSET_SETTER_DECL(Stereizer, sepDist)
{
PY_PROPERTY_CHECK_NULL(sepDist);

pySequenceFastRef seq(value);
if (!seq.isSequence() || seq.size() != 2) {
PyErr_SetString(PyExc_TypeError, "sepDist should be a sequence of two floats");
return -1;
}

PyObject* minObj = seq.get(0);
PyObject* maxObj = seq.get(1);
if (!pyPlasma_check<float>(minObj) || !pyPlasma_check<float>(maxObj)) {
PyErr_SetString(PyExc_TypeError, "sepDist should be a sequence of two floats");
return -1;
}

self->fThis->setSepDist(pyPlasma_get<float>(minObj), pyPlasma_get<float>(maxObj));
return 0;
}

PY_PROPERTY_GETSET_DECL(Stereizer, sepDist)

PY_PROPERTY(float, Stereizer, tanAng, getTanAng, setTanAng)
PY_PROPERTY(hsVector3, Stereizer, initPos, getInitPos, setInitPos)

static PyGetSetDef pyStereizer_GetSet[] = {
pyStereizer_ambientDist_getset,
pyStereizer_transition_getset,
pyStereizer_sepDist_getset,
pyStereizer_tanAng_getset,
pyStereizer_initPos_getset,
PY_GETSET_TERMINATOR
};

PY_PLASMA_TYPE(Stereizer, plStereizer, "plStereizer wrapper")

PY_PLASMA_TYPE_INIT(Stereizer)
{
pyStereizer_Type.tp_new = pyStereizer_new;
pyStereizer_Type.tp_getset = pyStereizer_GetSet;
pyStereizer_Type.tp_base = &pySingleModifier_Type;
if (PyType_CheckAndReady(&pyStereizer_Type) < 0)
return nullptr;

PY_TYPE_ADD_CONST(Stereizer, "kLeftChannel", plStereizer::kLeftChannel);
PY_TYPE_ADD_CONST(Stereizer, "kHasMaster", plStereizer::kHasMaster);

Py_INCREF(&pyStereizer_Type);
return (PyObject*)&pyStereizer_Type;
}

PY_PLASMA_IFC_METHODS(Stereizer, plStereizer)
24 changes: 24 additions & 0 deletions Python/PRP/Animation/pyStereizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* This file is part of HSPlasma.
*
* HSPlasma is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HSPlasma is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HSPlasma. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _PYSTEREIZER_H
#define _PYSTEREIZER_H

#include "PyPlasma.h"

PY_WRAP_PLASMA(Stereizer, class plStereizer);

#endif
2 changes: 2 additions & 0 deletions Python/PRP/pyCreatableConvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
#include "PRP/Animation/pyPosController.h"
#include "PRP/Animation/pyRotController.h"
#include "PRP/Animation/pyScaleController.h"
#include "PRP/Animation/pyStereizer.h"
#include "PRP/Animation/pyViewFaceModifier.h"
#include "PRP/Avatar/pyAGAnim.h"
#include "PRP/Avatar/pyAGApplicator.h"
Expand Down Expand Up @@ -619,6 +620,7 @@ PyObject* ICreate(plCreatable* pCre)
case kGrassShaderMod: return pyGrassShaderMod_FromGrassShaderMod(plGrassShaderMod::Convert(pCre));
case kWarpMsg: return pyWarpMsg_FromWarpMsg(plWarpMsg::Convert(pCre));
case kPhysicalSndGroup: return pyPhysicalSndGroup_FromPhysicalSndGroup(plPhysicalSndGroup::Convert(pCre));
case kStereizer: return pyStereizer_FromStereizer(plStereizer::Convert(pCre));
default:
// many messages are not implemented, make sure they are at least a plMessage
if (pCre->ClassInstance(kMessage))
Expand Down
10 changes: 10 additions & 0 deletions Python/PyHSPlasma.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5299,6 +5299,16 @@ class plStateDescriptor:
def __len__(self) -> int: ...
def __setitem__(self, index: Union[int, str], object: plVarDescriptor) -> None: ...

class plStereizer:
kLeftChannel: int = ...
kHasMaster: int = ...

ambientDist: float = ...
transition: float = ...
sepDist: Tuple[float, float] = ...
tanAng: float = ...
initPos: hsVector3 = ...

class plSubWorldMsg(plSimulationMsg):
worldKey: Union[plKey, None] = ...

Expand Down

0 comments on commit b56c71b

Please sign in to comment.