[Bf-blender-cvs] [ba5807c] master: BGE: added bge.logic.{get, set}AnimRecordFrame functions

Sybren A. Stüvel noreply at git.blender.org
Tue Aug 25 13:42:11 CEST 2015


Commit: ba5807c2710939cf8171fb19830f82cece48759f
Author: Sybren A. Stüvel
Date:   Tue Aug 25 13:42:09 2015 +0200
Branches: master
https://developer.blender.org/rBba5807c2710939cf8171fb19830f82cece48759f

BGE: added bge.logic.{get,set}AnimRecordFrame functions

By using getAnimRecordFrame(), game developers have access to the frame
number used by the "Record animation" feature. This enables them to
record additional information in Blender's F-Curves and ensuring perfect
synchronization with the information already recorded by Blender.

The setAnimRecordFrame() can be used to change the frame number at which
animations are recorded, for example to introduce delays the recording that
do not require delays in the actual game/simulation run.

The getter/setter functions in KX_KetsjiEngine are not directly named after
property they access (m_currentFrame). I found "current frame" to be too
vague for a public interface, hence chose a more descriptive name.

Reviewers: moguri, hg1, campbellbarton, panzergame, aligorith

Reviewed By: panzergame, aligorith

Differential Revision: https://developer.blender.org/D1449

===================================================================

M	doc/python_api/rst/bge.logic.rst
M	source/gameengine/Ketsji/KX_KetsjiEngine.cpp
M	source/gameengine/Ketsji/KX_KetsjiEngine.h
M	source/gameengine/Ketsji/KX_PythonInit.cpp

===================================================================

diff --git a/doc/python_api/rst/bge.logic.rst b/doc/python_api/rst/bge.logic.rst
index ab1f647..57d9f1a 100644
--- a/doc/python_api/rst/bge.logic.rst
+++ b/doc/python_api/rst/bge.logic.rst
@@ -337,6 +337,28 @@ General functions
 
    .. warning: Not implimented yet
 
+.. function:: getAnimRecordFrame()
+
+    Gets the current frame number used for recording animations. This
+    number is incremented automatically by Blender when the "Record
+    animation" feature is turned on.
+
+    :rtype: int
+
+.. function:: setAnimRecordFrame(framenr)
+
+    Sets the current frame number used for recording animations. This
+    number is automatically incremented by Blender when the "Record
+    animation" feature is turned on.
+
+    The frame number Must be non-negative, unless Blender has
+    :attr:`bpy.types.UserPreferencesEdit.use_negative_frames` enabled
+    in its user preferences. Only use non-negative numbers to be on
+    the safe side, unless you know what you are doing.
+
+    :arg framenr: The new frame number.
+    :type framenr: int
+
 .. function:: getExitKey()
 
    Gets the key used to exit the game engine
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
index c7cf556..72c5125 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
@@ -1750,6 +1750,16 @@ void	KX_KetsjiEngine::SetAnimRecordMode(bool animation_record, int startFrame)
 	m_currentFrame = startFrame;
 }
 
+int KX_KetsjiEngine::getAnimRecordFrame() const
+{
+	return m_currentFrame;
+}
+
+void KX_KetsjiEngine::setAnimRecordFrame(int framenr)
+{
+	m_currentFrame = framenr;
+}
+
 bool KX_KetsjiEngine::GetUseFixedTime(void) const
 {
 	return m_bFixedTime;
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h
index 6c9fed5..04e09c8 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.h
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h
@@ -225,6 +225,9 @@ public:
 	KX_ISceneConverter* GetSceneConverter() { return m_sceneconverter; }
 	void			SetAnimRecordMode(bool animation_record, int startFrame);
 
+	int getAnimRecordFrame() const;
+	void setAnimRecordFrame(int framenr);
+
 	RAS_IRasterizer*		GetRasterizer() { return m_rasterizer; }
 	RAS_ICanvas*		    GetCanvas() { return m_canvas; }
 	SCA_IInputDevice*		GetKeyboardDevice() { return m_keyboarddevice; }
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 4cb632e..2fef74c 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -526,6 +526,27 @@ static PyObject *gPyGetPhysicsTicRate(PyObject *)
 	return PyFloat_FromDouble(PHY_GetActiveEnvironment()->GetFixedTimeStep());
 }
 
+static PyObject *gPySetAnimRecordFrame(PyObject *, PyObject *args)
+{
+	int anim_record_frame;
+
+	if (!PyArg_ParseTuple(args, "i:setAnimRecordFrame", &anim_record_frame))
+		return NULL;
+
+	if (anim_record_frame < 0 && (U.flag & USER_NONEGFRAMES)) {
+		PyErr_Format(PyExc_ValueError, "Frame number must be non-negative (was %i).", anim_record_frame);
+		return NULL;
+	}
+
+	gp_KetsjiEngine->setAnimRecordFrame(anim_record_frame);
+	Py_RETURN_NONE;
+}
+
+static PyObject *gPyGetAnimRecordFrame(PyObject *)
+{
+	return PyLong_FromLong(gp_KetsjiEngine->getAnimRecordFrame());
+}
+
 static PyObject *gPyGetAverageFrameRate(PyObject *)
 {
 	return PyFloat_FromDouble(KX_KetsjiEngine::GetAverageFrameRate());
@@ -887,6 +908,8 @@ static struct PyMethodDef game_methods[] = {
 	{"setLogicTicRate", (PyCFunction) gPySetLogicTicRate, METH_VARARGS, (const char *)"Sets the logic tic rate"},
 	{"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_NOARGS, (const char *)"Gets the physics tic rate"},
 	{"setPhysicsTicRate", (PyCFunction) gPySetPhysicsTicRate, METH_VARARGS, (const char *)"Sets the physics tic rate"},
+	{"getAnimRecordFrame", (PyCFunction) gPyGetAnimRecordFrame, METH_NOARGS, (const char *)"Gets the current frame number used for animation recording"},
+	{"setAnimRecordFrame", (PyCFunction) gPySetAnimRecordFrame, METH_VARARGS, (const char *)"Sets the current frame number used for animation recording"},
 	{"getExitKey", (PyCFunction) gPyGetExitKey, METH_NOARGS, (const char *)"Gets the key used to exit the game engine"},
 	{"setExitKey", (PyCFunction) gPySetExitKey, METH_VARARGS, (const char *)"Sets the key used to exit the game engine"},
 	{"getAverageFrameRate", (PyCFunction) gPyGetAverageFrameRate, METH_NOARGS, (const char *)"Gets the estimated average frame rate"},




More information about the Bf-blender-cvs mailing list