Skip to content

Commit

Permalink
added Timer module to py bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor committed Jun 12, 2024
1 parent 1758ab2 commit b4849ea
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/core/scripting/VRPyMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ PyObject* VRPyLine::intersect(VRPyLine* self, PyObject *args) {

// expression bindings

simpleVRPyType(Timer, New_ptr);
simplePyType(Expression, New_named_ptr);
simplePyType(MathExpression, New_named_ptr);
simplePyType(TSDF, VRPyTSDF::New );
Expand Down Expand Up @@ -758,6 +759,13 @@ PyMethodDef VRPyDatarow::methods[] = {
{NULL} /* Sentinel */
};

PyMethodDef VRPyTimer::methods[] = {
{"start", PyWrap( Timer, start, "start timer", void ) },
{"stop", PyWrap( Timer, stop, "stop timer", double ) },
{"reset", PyWrap( Timer, reset, "reset timer", void ) },
{NULL} /* Sentinel */
};

PyMethodDef VRPyExpression::methods[] = {
{"set", PyWrap2( Expression, set, "Set expression", void, string ) },
{"segment", PyWrap2( Expression, segment, "Build tree structure", void ) },
Expand Down
5 changes: 5 additions & 0 deletions src/core/scripting/VRPyMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "core/math/OSGMathFwd.h"
#include "core/utils/xml.h"
#include "core/utils/VRSpreadsheet.h"
#include "core/utils/VRTimer.h"
#include <OpenSG/OSGMatrix.h>
#include <OpenSG/OSGLine.h>

Expand Down Expand Up @@ -113,6 +114,10 @@ struct VRPyLine : VRPyBaseT<OSG::Line> {
static PyObject* pos(VRPyLine* self);
static PyObject* dir(VRPyLine* self);
};

struct VRPyTimer : VRPyBaseT<OSG::VRTimer> {
static PyMethodDef methods[];
};

struct VRPyExpression : VRPyBaseT<OSG::Expression> {
static PyMethodDef methods[];
Expand Down
5 changes: 5 additions & 0 deletions src/core/scripting/VRSceneGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ PyMethodDef VRSceneGlobals::methods[] = {
{"getSky", (PyCFunction)VRSceneGlobals::getSky, METH_NOARGS, "Get sky module" },
{"getSoundManager", (PyCFunction)VRSceneGlobals::getSoundManager, METH_NOARGS, "Get sound manager module" },
{"getFrame", (PyCFunction)VRSceneGlobals::getFrame, METH_NOARGS, "Get current frame number" },
{"getFPS", (PyCFunction)VRSceneGlobals::getFPS, METH_NOARGS, "Get current fps" },
{"getScript", (PyCFunction)VRSceneGlobals::getScript, METH_VARARGS, "Get python script by name" },
{"importScene", (PyCFunction)VRSceneGlobals::importScene, METH_VARARGS, "Import scene" },
{"getActiveCamera", (PyCFunction)VRSceneGlobals::getActiveCamera, METH_NOARGS, "Get active camera" },
Expand Down Expand Up @@ -124,6 +125,10 @@ PyObject* VRSceneGlobals::getFrame(VRSceneGlobals* self) {
return PyInt_FromLong(VRGlobals::CURRENT_FRAME);
}

PyObject* VRSceneGlobals::getFPS(VRSceneGlobals* self) {
return PyFloat_FromDouble(VRGlobals::FRAME_RATE.fps);
}

PyObject* VRSceneGlobals::getActiveCamera(VRSceneGlobals* self) {
return VRPyTypeCaster::cast( VRScene::getCurrent()->getActiveCamera() );
}
Expand Down
1 change: 1 addition & 0 deletions src/core/scripting/VRSceneGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class VRSceneGlobals: public VRPyBase {
static PyObject* getSky(VRSceneGlobals* self);
static PyObject* getSoundManager(VRSceneGlobals* self);
static PyObject* getFrame(VRSceneGlobals* self);
static PyObject* getFPS(VRSceneGlobals* self);
static PyObject* getScript(VRSceneGlobals* self, PyObject *args);
static PyObject* importScene(VRSceneGlobals* self, PyObject *args);
static PyObject* getActiveCamera(VRSceneGlobals* self);
Expand Down
1 change: 1 addition & 0 deletions src/core/scripting/VRSceneModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ void VRSceneModules::setup(VRScriptManager* sm, PyObject* pModVR) {
#ifndef WITHOUT_LAPACKE_BLAS
sm->registerModule<VRPyPCA>("PCA", pModVR, 0, "Math");
#endif
sm->registerModule<VRPyTimer>("Timer", pModVR, 0, "Math");
sm->registerModule<VRPyPID>("PID", pModVR, 0, "Math");
sm->registerModule<VRPyPatch>("Patch", pModVR, 0, "Math");

Expand Down
1 change: 1 addition & 0 deletions src/core/utils/VRTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#endif

using namespace std;
using namespace OSG;

VRTimer::VRTimer() { start(); }
VRTimerPtr VRTimer::create() { return VRTimerPtr(new VRTimer()); }
Expand Down
4 changes: 4 additions & 0 deletions src/core/utils/VRTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <string>
#include "core/utils/VRUtilsFwd.h"

namespace OSG {

class VRTimer {
private:
struct timer {
Expand Down Expand Up @@ -32,4 +34,6 @@ class VRTimer {
static double getBeacon(std::string);
};

}

#endif // VRTIMER_H_INCLUDED
3 changes: 1 addition & 2 deletions src/core/utils/VRUtilsFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
ptrTemplateFwd(VRCallbackWrapper, VRCallbackStrWrapper, std::string);
ptrTemplateFwd(VRCallbackWrapper, VRCallbackPyWrapper, PyObject*);

ptrFwd(VRTimer);

namespace OSG {
ptrFwd(VRTimer);
ptrFwd(VRVisualLayer);
ptrFwd(VRProgress);
ptrFwd(VREncryption);
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/system/VRSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ void doFrameSleep(double tFrame, double fps) {
// efficient sleep
double precisionBuffer = 0;//1.5;
if (sT-precisionBuffer > 0) {
VRTimer timer;
OSG::VRTimer timer;
timer.start();
duration<double> T((sT-precisionBuffer)*1000);
std::this_thread::sleep_for(T);
Expand Down

0 comments on commit b4849ea

Please sign in to comment.