Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp2
-rw-r--r--source/gameengine/BlenderRoutines/CMakeLists.txt4
-rw-r--r--source/gameengine/BlenderRoutines/Makefile3
-rw-r--r--source/gameengine/BlenderRoutines/SConscript16
-rw-r--r--source/gameengine/Converter/BL_BlenderDataConversion.cpp107
-rw-r--r--source/gameengine/Converter/BL_MeshDeformer.cpp4
-rw-r--r--source/gameengine/Converter/KX_BlenderSceneConverter.cpp2
-rw-r--r--source/gameengine/Converter/KX_ConvertControllers.cpp7
-rw-r--r--source/gameengine/Converter/KX_ConvertSensors.cpp8
-rw-r--r--source/gameengine/Converter/KX_IpoConvert.cpp50
-rw-r--r--source/gameengine/Converter/SConscript13
-rw-r--r--source/gameengine/Expressions/FloatValue.cpp6
-rw-r--r--source/gameengine/Expressions/InputParser.cpp7
-rw-r--r--source/gameengine/Expressions/InputParser.h1
-rw-r--r--source/gameengine/Expressions/IntValue.cpp6
-rw-r--r--source/gameengine/Expressions/ListValue.cpp4
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.cpp32
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.h39
-rw-r--r--source/gameengine/Expressions/Value.cpp13
-rw-r--r--source/gameengine/Expressions/Value.h1
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp8
-rw-r--r--source/gameengine/GameLogic/SCA_2DFilterActuator.cpp3
-rw-r--r--source/gameengine/GameLogic/SCA_ANDController.cpp4
-rw-r--r--source/gameengine/GameLogic/SCA_AlwaysSensor.cpp4
-rw-r--r--source/gameengine/GameLogic/SCA_DelaySensor.cpp6
-rw-r--r--source/gameengine/GameLogic/SCA_ExpressionController.cpp35
-rw-r--r--source/gameengine/GameLogic/SCA_ExpressionController.h6
-rw-r--r--source/gameengine/GameLogic/SCA_IActuator.cpp4
-rw-r--r--source/gameengine/GameLogic/SCA_IActuator.h2
-rw-r--r--source/gameengine/GameLogic/SCA_IController.cpp4
-rw-r--r--source/gameengine/GameLogic/SCA_ILogicBrick.h1
-rw-r--r--source/gameengine/GameLogic/SCA_IObject.cpp9
-rw-r--r--source/gameengine/GameLogic/SCA_ISensor.h5
-rw-r--r--source/gameengine/GameLogic/SCA_MouseSensor.cpp4
-rw-r--r--source/gameengine/GameLogic/SCA_NANDController.cpp4
-rw-r--r--source/gameengine/GameLogic/SCA_NORController.cpp4
-rw-r--r--source/gameengine/GameLogic/SCA_ORController.cpp5
-rw-r--r--source/gameengine/GameLogic/SCA_PropertySensor.h4
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.cpp163
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.h5
-rw-r--r--source/gameengine/GameLogic/SCA_XNORController.cpp4
-rw-r--r--source/gameengine/GameLogic/SCA_XORController.cpp4
-rw-r--r--source/gameengine/GamePlayer/common/SConscript10
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_ghost.cpp73
-rw-r--r--source/gameengine/GamePlayer/ghost/SConscript7
-rw-r--r--source/gameengine/Ketsji/BL_Shader.cpp7
-rw-r--r--source/gameengine/Ketsji/BL_Shader.h2
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp4
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_BlenderMaterial.cpp3
-rw-r--r--source/gameengine/Ketsji/KX_BulletPhysicsController.cpp6
-rw-r--r--source/gameengine/Ketsji/KX_CDActuator.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_Camera.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_ClientObjectInfo.h16
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintActuator.cpp8
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintWrapper.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_ConvertPhysicsObject.h10
-rw-r--r--source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp20
-rw-r--r--source/gameengine/Ketsji/KX_GameActuator.cpp6
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp54
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.h3
-rw-r--r--source/gameengine/Ketsji/KX_IPO_SGController.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_IpoActuator.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.cpp10
-rw-r--r--source/gameengine/Ketsji/KX_Light.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_MeshProxy.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_MouseFocusSensor.cpp93
-rw-r--r--source/gameengine/Ketsji/KX_MouseFocusSensor.h12
-rw-r--r--source/gameengine/Ketsji/KX_NearSensor.cpp48
-rw-r--r--source/gameengine/Ketsji/KX_NearSensor.h27
-rw-r--r--source/gameengine/Ketsji/KX_ObjectActuator.cpp10
-rw-r--r--source/gameengine/Ketsji/KX_ParentActuator.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_PolyProxy.cpp8
-rw-r--r--source/gameengine/Ketsji/KX_PolygonMaterial.cpp3
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp45
-rw-r--r--source/gameengine/Ketsji/KX_RadarSensor.cpp134
-rw-r--r--source/gameengine/Ketsji/KX_RadarSensor.h28
-rw-r--r--source/gameengine/Ketsji/KX_RaySensor.cpp68
-rw-r--r--source/gameengine/Ketsji/KX_RaySensor.h8
-rw-r--r--source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp3
-rw-r--r--source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp3
-rw-r--r--source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp3
-rw-r--r--source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp19
-rw-r--r--source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp80
-rw-r--r--source/gameengine/Ketsji/KX_Scene.cpp49
-rw-r--r--source/gameengine/Ketsji/KX_Scene.h3
-rw-r--r--source/gameengine/Ketsji/KX_SceneActuator.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_SoundActuator.cpp6
-rw-r--r--source/gameengine/Ketsji/KX_StateActuator.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_TouchSensor.cpp170
-rw-r--r--source/gameengine/Ketsji/KX_TouchSensor.h33
-rw-r--r--source/gameengine/Ketsji/KX_TrackToActuator.cpp9
-rw-r--r--source/gameengine/Ketsji/KX_VehicleWrapper.cpp3
-rw-r--r--source/gameengine/Ketsji/KX_VertexProxy.cpp4
-rw-r--r--source/gameengine/Ketsji/KX_VisibilityActuator.cpp4
-rw-r--r--source/gameengine/Ketsji/SConscript17
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.cpp29
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.h2
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp24
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h2
-rw-r--r--source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h2
-rw-r--r--source/gameengine/PyDoc/GameLogic.py10
-rw-r--r--source/gameengine/PyDoc/KX_GameObject.py2
-rw-r--r--source/gameengine/PyDoc/KX_NearSensor.py5
-rw-r--r--source/gameengine/PyDoc/KX_RadarSensor.py18
-rw-r--r--source/gameengine/PyDoc/KX_Scene.py15
-rw-r--r--source/gameengine/PyDoc/KX_TouchSensor.py37
-rw-r--r--source/gameengine/PyDoc/SCA_DelaySensor.py7
-rw-r--r--source/gameengine/PyDoc/SCA_PythonController.py12
-rw-r--r--source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp2
-rw-r--r--source/gameengine/Rasterizer/RAS_IPolygonMaterial.h2
-rw-r--r--source/gameengine/Rasterizer/RAS_IRasterizer.h2
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp16
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h2
-rw-r--r--source/gameengine/Rasterizer/RAS_TexVert.cpp26
-rw-r--r--source/gameengine/Rasterizer/RAS_TexVert.h3
-rw-r--r--source/gameengine/SConscript4
-rw-r--r--source/gameengine/SceneGraph/SG_BBox.cpp4
-rw-r--r--source/gameengine/SceneGraph/SG_Spatial.cpp19
-rw-r--r--source/gameengine/SceneGraph/SG_Spatial.h2
-rw-r--r--source/gameengine/VideoTexture/CMakeLists.txt2
-rw-r--r--source/gameengine/VideoTexture/FilterBase.cpp2
-rw-r--r--source/gameengine/VideoTexture/FilterSource.h8
-rw-r--r--source/gameengine/VideoTexture/Makefile3
-rw-r--r--source/gameengine/VideoTexture/SConscript2
-rw-r--r--source/gameengine/VideoTexture/VideoFFmpeg.cpp538
-rw-r--r--source/gameengine/VideoTexture/VideoFFmpeg.h46
128 files changed, 1778 insertions, 858 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
index 67bec97ea32..d89d2d80ab4 100644
--- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
+++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
@@ -563,10 +563,12 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
// get some preferences
SYS_SystemHandle syshandle = SYS_GetSystem();
+ /*
bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
bool usefixed = (SYS_GetCommandLineInt(syshandle, "fixedtime", 0) != 0);
bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
+ */
bool game2ipo = true;//(SYS_GetCommandLineInt(syshandle, "game2ipo", 0) != 0);
bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0);
bool usemat = false;
diff --git a/source/gameengine/BlenderRoutines/CMakeLists.txt b/source/gameengine/BlenderRoutines/CMakeLists.txt
index 340a1ae310b..d65e6a012df 100644
--- a/source/gameengine/BlenderRoutines/CMakeLists.txt
+++ b/source/gameengine/BlenderRoutines/CMakeLists.txt
@@ -38,5 +38,9 @@ SET(INC
${PYTHON_INC}
)
+IF(WITH_FFMPEG)
+ ADD_DEFINITIONS(-DWITH_FFMPEG)
+ENDIF(WITH_FFMPEG)
+
BLENDERLIB(bf_blroutines "${SRC}" "${INC}")
#env.BlenderLib ( 'bf_bloutines', sources, Split(incs), [], libtype=['game', 'game2', 'player'], priority=[0, 0, 55] , compileflags=cxxflags)
diff --git a/source/gameengine/BlenderRoutines/Makefile b/source/gameengine/BlenderRoutines/Makefile
index c2f19ae1d8a..e77d8e8380e 100644
--- a/source/gameengine/BlenderRoutines/Makefile
+++ b/source/gameengine/BlenderRoutines/Makefile
@@ -76,3 +76,6 @@ endif
CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
+ifeq ($(WITH_FFMPEG), true)
+ CPPFLAGS += -DWITH_FFMPEG
+endif
diff --git a/source/gameengine/BlenderRoutines/SConscript b/source/gameengine/BlenderRoutines/SConscript
index 7a1bf4d9ad6..4a9c0e1286b 100644
--- a/source/gameengine/BlenderRoutines/SConscript
+++ b/source/gameengine/BlenderRoutines/SConscript
@@ -2,6 +2,7 @@
Import ('env')
sources = env.Glob('*.cpp')
+defs = []
incs = '. #source/kernel/gen_system #intern/string #intern/guardedalloc'
incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer #intern/bmfont'
@@ -12,13 +13,20 @@ incs += ' #source/blender/blenkernel #source/blender #source/blender/include'
incs += ' #source/blender/makesdna #source/gameengine/Rasterizer #source/gameengine/GameLogic'
incs += ' #source/gameengine/Expressions #source/gameengine/Network'
incs += ' #source/gameengine/SceneGraph #source/gameengine/Physics/common'
-incs += ' #source/gameengine/Physics/Bullet #source/gameengine/Physics/Sumo'
-incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork'
+incs += ' #source/gameengine/Physics/Bullet'
+incs += ' #source/gameengine/Network/LoopBackNetwork'
incs += ' #intern/SoundSystem #source/blender/misc #source/blender/blenloader'
incs += ' #extern/glew/include #source/blender/gpu'
+if env['WITH_BF_SOLID']:
+ incs += ' #source/gameengine/Physics/Sumo #source/gameengine/Physics/Sumo/Fuzzics/include'
+ incs += ' ' + env['BF_SOLID_INC']
+ defs.append('USE_SUMO_SOLID')
+
+if env['WITH_BF_FFMPEG']:
+ defs.append('WITH_FFMPEG')
+
incs += ' ' + env['BF_PYTHON_INC']
-incs += ' ' + env['BF_SOLID_INC']
incs += ' ' + env['BF_BULLET_INC']
incs += ' ' + env['BF_OPENGL_INC']
@@ -27,4 +35,4 @@ if env['OURPLATFORM']=='win32-vc':
cxxflags.append ('/GR')
cxxflags.append ('/O2')
-env.BlenderLib ( 'bf_bloutines', sources, Split(incs), [], libtype=['game', 'game2', 'player'], priority=[0, 0, 55] , cxx_compileflags=cxxflags)
+env.BlenderLib ( 'bf_bloutines', sources, Split(incs), defs, libtype=['game', 'game2', 'player'], priority=[0, 0, 55] , cxx_compileflags=cxxflags)
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
index 2fa3e192179..d74243b0eb0 100644
--- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp
+++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
@@ -593,7 +593,7 @@ BL_Material* ConvertMaterial(
MT_Point2 uv2[4];
const char *uvName = "", *uv2Name = "";
- uv[0]= uv[1]= uv[2]= uv[3]= MT_Point2(0.0f, 0.0f);
+
uv2[0]= uv2[1]= uv2[2]= uv2[3]= MT_Point2(0.0f, 0.0f);
if( validface ) {
@@ -607,12 +607,12 @@ BL_Material* ConvertMaterial(
material->tile = tface->tile;
material->mode = tface->mode;
- uv[0] = MT_Point2(tface->uv[0]);
- uv[1] = MT_Point2(tface->uv[1]);
- uv[2] = MT_Point2(tface->uv[2]);
+ uv[0].setValue(tface->uv[0]);
+ uv[1].setValue(tface->uv[1]);
+ uv[2].setValue(tface->uv[2]);
if (mface->v4)
- uv[3] = MT_Point2(tface->uv[3]);
+ uv[3].setValue(tface->uv[3]);
uvName = tfaceName;
}
@@ -622,6 +622,8 @@ BL_Material* ConvertMaterial(
material->mode = default_face_mode;
material->transp = TF_SOLID;
material->tile = 0;
+
+ uv[0]= uv[1]= uv[2]= uv[3]= MT_Point2(0.0f, 0.0f);
}
// with ztransp enabled, enforce alpha blending mode
@@ -665,14 +667,14 @@ BL_Material* ConvertMaterial(
{
MT_Point2 uvSet[4];
- uvSet[0] = MT_Point2(layer.face->uv[0]);
- uvSet[1] = MT_Point2(layer.face->uv[1]);
- uvSet[2] = MT_Point2(layer.face->uv[2]);
+ uvSet[0].setValue(layer.face->uv[0]);
+ uvSet[1].setValue(layer.face->uv[1]);
+ uvSet[2].setValue(layer.face->uv[2]);
if (mface->v4)
- uvSet[3] = MT_Point2(layer.face->uv[3]);
+ uvSet[3].setValue(layer.face->uv[3]);
else
- uvSet[3] = MT_Point2(0.0f, 0.0f);
+ uvSet[3].setValue(0.0f, 0.0f);
if (isFirstSet)
{
@@ -790,10 +792,10 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
MT_Vector4 tan0(0,0,0,0), tan1(0,0,0,0), tan2(0,0,0,0), tan3(0,0,0,0);
/* get coordinates, normals and tangents */
- pt0 = MT_Point3(mvert[mface->v1].co);
- pt1 = MT_Point3(mvert[mface->v2].co);
- pt2 = MT_Point3(mvert[mface->v3].co);
- pt3 = (mface->v4)? MT_Point3(mvert[mface->v4].co): MT_Point3(0.0, 0.0, 0.0);
+ pt0.setValue(mvert[mface->v1].co);
+ pt1.setValue(mvert[mface->v2].co);
+ pt2.setValue(mvert[mface->v3].co);
+ if (mface->v4) pt3.setValue(mvert[mface->v4].co);
if(mface->flag & ME_SMOOTH) {
float n0[3], n1[3], n2[3], n3[3];
@@ -894,12 +896,12 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
visible = !((mface->flag & ME_HIDE)||(tface->mode & TF_INVISIBLE));
- uv0 = MT_Point2(tface->uv[0]);
- uv1 = MT_Point2(tface->uv[1]);
- uv2 = MT_Point2(tface->uv[2]);
+ uv0.setValue(tface->uv[0]);
+ uv1.setValue(tface->uv[1]);
+ uv2.setValue(tface->uv[2]);
if (mface->v4)
- uv3 = MT_Point2(tface->uv[3]);
+ uv3.setValue(tface->uv[3]);
}
else {
/* no texfaces, set COLLSION true and everything else FALSE */
@@ -960,7 +962,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
polymat->m_diffuse = MT_Vector3(ma->r, ma->g, ma->b)*(ma->emit + ma->ref);
}
else {
- polymat->m_specular = MT_Vector3(0.0f,0.0f,0.0f);
+ polymat->m_specular.setValue(0.0f,0.0f,0.0f);
polymat->m_shininess = 35.0;
}
}
@@ -1313,6 +1315,12 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
CreateMaterialFromBlenderObject(blenderobject, kxscene);
KX_ObjectProperties objprop;
+ objprop.m_lockXaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_X_AXIS) !=0;
+ objprop.m_lockYaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Y_AXIS) !=0;
+ objprop.m_lockZaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_AXIS) !=0;
+ objprop.m_lockXRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_X_ROT_AXIS) !=0;
+ objprop.m_lockYRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Y_ROT_AXIS) !=0;
+ objprop.m_lockZRotaxis = (blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_ROT_AXIS) !=0;
objprop.m_isCompoundChild = isCompoundChild;
objprop.m_hasCompoundChildren = (blenderobject->gameflag & OB_CHILD) != 0;
@@ -1911,21 +1919,14 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
MT_Matrix3x3 angor;
if (converter->addInitFromFrame) blenderscene->r.cfra=blenderscene->r.sfra;
- MT_Point3 pos = MT_Point3(
+ MT_Point3 pos;
+ pos.setValue(
blenderobject->loc[0]+blenderobject->dloc[0],
blenderobject->loc[1]+blenderobject->dloc[1],
blenderobject->loc[2]+blenderobject->dloc[2]
);
- MT_Vector3 eulxyz = MT_Vector3(
- blenderobject->rot[0],
- blenderobject->rot[1],
- blenderobject->rot[2]
- );
- MT_Vector3 scale = MT_Vector3(
- blenderobject->size[0],
- blenderobject->size[1],
- blenderobject->size[2]
- );
+ MT_Vector3 eulxyz(blenderobject->rot);
+ MT_Vector3 scale(blenderobject->size);
if (converter->addInitFromFrame){//rcruiz
float eulxyzPrev[3];
blenderscene->r.cfra=blenderscene->r.sfra-1;
@@ -1997,18 +1998,18 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
MT_Vector3 x(ori.getColumn(0));
MT_Vector3 y(ori.getColumn(1));
MT_Vector3 z(ori.getColumn(2));
- MT_Vector3 scale(x.length(), y.length(), z.length());
- if (!MT_fuzzyZero(scale[0]))
- x /= scale[0];
- if (!MT_fuzzyZero(scale[1]))
- y /= scale[1];
- if (!MT_fuzzyZero(scale[2]))
- z /= scale[2];
+ MT_Vector3 parscale(x.length(), y.length(), z.length());
+ if (!MT_fuzzyZero(parscale[0]))
+ x /= parscale[0];
+ if (!MT_fuzzyZero(parscale[1]))
+ y /= parscale[1];
+ if (!MT_fuzzyZero(parscale[2]))
+ z /= parscale[2];
ori.setColumn(0, x);
ori.setColumn(1, y);
ori.setColumn(2, z);
parentinversenode->SetLocalOrientation(ori);
- parentinversenode->SetLocalScale(scale);
+ parentinversenode->SetLocalScale(parscale);
parentinversenode->AddChild(gameobj->GetSGNode());
}
@@ -2113,21 +2114,13 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
if (converter->addInitFromFrame)
blenderscene->r.cfra=blenderscene->r.sfra;
- MT_Point3 pos = MT_Point3(
+ MT_Point3 pos(
blenderobject->loc[0]+blenderobject->dloc[0],
blenderobject->loc[1]+blenderobject->dloc[1],
blenderobject->loc[2]+blenderobject->dloc[2]
);
- MT_Vector3 eulxyz = MT_Vector3(
- blenderobject->rot[0],
- blenderobject->rot[1],
- blenderobject->rot[2]
- );
- MT_Vector3 scale = MT_Vector3(
- blenderobject->size[0],
- blenderobject->size[1],
- blenderobject->size[2]
- );
+ MT_Vector3 eulxyz(blenderobject->rot);
+ MT_Vector3 scale(blenderobject->size);
if (converter->addInitFromFrame){//rcruiz
float eulxyzPrev[3];
blenderscene->r.cfra=blenderscene->r.sfra-1;
@@ -2194,18 +2187,18 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
MT_Vector3 x(ori.getColumn(0));
MT_Vector3 y(ori.getColumn(1));
MT_Vector3 z(ori.getColumn(2));
- MT_Vector3 scale(x.length(), y.length(), z.length());
- if (!MT_fuzzyZero(scale[0]))
- x /= scale[0];
- if (!MT_fuzzyZero(scale[1]))
- y /= scale[1];
- if (!MT_fuzzyZero(scale[2]))
- z /= scale[2];
+ MT_Vector3 localscale(x.length(), y.length(), z.length());
+ if (!MT_fuzzyZero(localscale[0]))
+ x /= localscale[0];
+ if (!MT_fuzzyZero(localscale[1]))
+ y /= localscale[1];
+ if (!MT_fuzzyZero(localscale[2]))
+ z /= localscale[2];
ori.setColumn(0, x);
ori.setColumn(1, y);
ori.setColumn(2, z);
parentinversenode->SetLocalOrientation(ori);
- parentinversenode->SetLocalScale(scale);
+ parentinversenode->SetLocalScale(localscale);
parentinversenode->AddChild(gameobj->GetSGNode());
}
diff --git a/source/gameengine/Converter/BL_MeshDeformer.cpp b/source/gameengine/Converter/BL_MeshDeformer.cpp
index fa3b8185fe2..80112346c72 100644
--- a/source/gameengine/Converter/BL_MeshDeformer.cpp
+++ b/source/gameengine/Converter/BL_MeshDeformer.cpp
@@ -51,7 +51,6 @@
bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*)
{
size_t i;
- float *co;
// only apply once per frame if the mesh is actually modified
if(m_pMeshObject->MeshModified() &&
@@ -70,8 +69,7 @@ bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*)
// For each vertex
for(i=it.startvertex; i<it.endvertex; i++) {
RAS_TexVert& v = it.vertex[i];
- co = m_bmesh->mvert[v.getOrigIndex()].co;
- v.SetXYZ(MT_Point3(co));
+ v.SetXYZ(m_bmesh->mvert[v.getOrigIndex()].co);
}
}
}
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
index 7eec93dc402..97a0819147c 100644
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
+++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
@@ -321,7 +321,7 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename,
SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/
int visualizePhysics = SYS_GetCommandLineInt(syshandle,"show_physics",0);
if (visualizePhysics)
- ccdPhysEnv->setDebugMode(btIDebugDraw::DBG_DrawWireframe|btIDebugDraw::DBG_DrawAabb|btIDebugDraw::DBG_DrawContactPoints|btIDebugDraw::DBG_DrawText);
+ ccdPhysEnv->setDebugMode(btIDebugDraw::DBG_DrawWireframe|btIDebugDraw::DBG_DrawAabb|btIDebugDraw::DBG_DrawContactPoints|btIDebugDraw::DBG_DrawText|btIDebugDraw::DBG_DrawConstraintLimits|btIDebugDraw::DBG_DrawConstraints);
//todo: get a button in blender ?
//disable / enable debug drawing (contact points, aabb's etc)
diff --git a/source/gameengine/Converter/KX_ConvertControllers.cpp b/source/gameengine/Converter/KX_ConvertControllers.cpp
index da490b4ee85..fb100b0a68b 100644
--- a/source/gameengine/Converter/KX_ConvertControllers.cpp
+++ b/source/gameengine/Converter/KX_ConvertControllers.cpp
@@ -200,6 +200,13 @@ void BL_ConvertControllers(
gameobj->AddController(gamecontroller);
converter->RegisterGameController(gamecontroller, bcontr);
+
+ if (bcontr->type==CONT_PYTHON) {
+ /* not strictly needed but gives syntax errors early on and
+ * gives more pradictable performance for larger scripts */
+ (static_cast<SCA_PythonController*>(gamecontroller))->Compile();
+ }
+
//done with gamecontroller
gamecontroller->Release();
}
diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp
index 13b7f43195d..c9b51807767 100644
--- a/source/gameengine/Converter/KX_ConvertSensors.cpp
+++ b/source/gameengine/Converter/KX_ConvertSensors.cpp
@@ -306,12 +306,12 @@ void BL_ConvertSensors(struct Object* blenderobject,
{
// collision sensor can sense both materials and properties.
- bool bFindMaterial = false;
+ bool bFindMaterial = false, bTouchPulse = false;
bCollisionSensor* blendertouchsensor = (bCollisionSensor*)sens->data;
- bFindMaterial = (blendertouchsensor->mode
- & SENS_COLLISION_MATERIAL);
+ bFindMaterial = (blendertouchsensor->mode & SENS_COLLISION_MATERIAL);
+ bTouchPulse = (blendertouchsensor->mode & SENS_COLLISION_PULSE);
STR_String touchPropOrMatName = ( bFindMaterial ?
@@ -324,6 +324,7 @@ void BL_ConvertSensors(struct Object* blenderobject,
gamesensor = new KX_TouchSensor(eventmgr,
gameobj,
bFindMaterial,
+ bTouchPulse,
touchPropOrMatName);
}
@@ -349,6 +350,7 @@ void BL_ConvertSensors(struct Object* blenderobject,
gamesensor = new KX_TouchSensor(eventmgr,
gameobj,
bFindMaterial,
+ false,
touchpropertyname);
}
}
diff --git a/source/gameengine/Converter/KX_IpoConvert.cpp b/source/gameengine/Converter/KX_IpoConvert.cpp
index ce004fa0504..f19390db8a9 100644
--- a/source/gameengine/Converter/KX_IpoConvert.cpp
+++ b/source/gameengine/Converter/KX_IpoConvert.cpp
@@ -311,67 +311,67 @@ void BL_ConvertIpos(struct Object* blenderobject,KX_GameObject* gameobj,KX_Blend
}
{
- KX_ObColorIpoSGController* ipocontr=NULL;
+ KX_ObColorIpoSGController* ipocontr_obcol=NULL;
ipo = ipoList->GetScalarInterpolator(OB_COL_R);
if (ipo)
{
- if (!ipocontr)
+ if (!ipocontr_obcol)
{
- ipocontr = new KX_ObColorIpoSGController();
- gameobj->GetSGNode()->AddSGController(ipocontr);
- ipocontr->SetObject(gameobj->GetSGNode());
+ ipocontr_obcol = new KX_ObColorIpoSGController();
+ gameobj->GetSGNode()->AddSGController(ipocontr_obcol);
+ ipocontr_obcol->SetObject(gameobj->GetSGNode());
}
KX_IInterpolator *interpolator =
new KX_ScalarInterpolator(
- &ipocontr->m_rgba[0],
+ &ipocontr_obcol->m_rgba[0],
ipo);
- ipocontr->AddInterpolator(interpolator);
+ ipocontr_obcol->AddInterpolator(interpolator);
}
ipo = ipoList->GetScalarInterpolator(OB_COL_G);
if (ipo)
{
- if (!ipocontr)
+ if (!ipocontr_obcol)
{
- ipocontr = new KX_ObColorIpoSGController();
- gameobj->GetSGNode()->AddSGController(ipocontr);
- ipocontr->SetObject(gameobj->GetSGNode());
+ ipocontr_obcol = new KX_ObColorIpoSGController();
+ gameobj->GetSGNode()->AddSGController(ipocontr_obcol);
+ ipocontr_obcol->SetObject(gameobj->GetSGNode());
}
KX_IInterpolator *interpolator =
new KX_ScalarInterpolator(
- &ipocontr->m_rgba[1],
+ &ipocontr_obcol->m_rgba[1],
ipo);
- ipocontr->AddInterpolator(interpolator);
+ ipocontr_obcol->AddInterpolator(interpolator);
}
ipo = ipoList->GetScalarInterpolator(OB_COL_B);
if (ipo)
{
- if (!ipocontr)
+ if (!ipocontr_obcol)
{
- ipocontr = new KX_ObColorIpoSGController();
- gameobj->GetSGNode()->AddSGController(ipocontr);
- ipocontr->SetObject(gameobj->GetSGNode());
+ ipocontr_obcol = new KX_ObColorIpoSGController();
+ gameobj->GetSGNode()->AddSGController(ipocontr_obcol);
+ ipocontr_obcol->SetObject(gameobj->GetSGNode());
}
KX_IInterpolator *interpolator =
new KX_ScalarInterpolator(
- &ipocontr->m_rgba[2],
+ &ipocontr_obcol->m_rgba[2],
ipo);
- ipocontr->AddInterpolator(interpolator);
+ ipocontr_obcol->AddInterpolator(interpolator);
}
ipo = ipoList->GetScalarInterpolator(OB_COL_A);
if (ipo)
{
- if (!ipocontr)
+ if (!ipocontr_obcol)
{
- ipocontr = new KX_ObColorIpoSGController();
- gameobj->GetSGNode()->AddSGController(ipocontr);
- ipocontr->SetObject(gameobj->GetSGNode());
+ ipocontr_obcol = new KX_ObColorIpoSGController();
+ gameobj->GetSGNode()->AddSGController(ipocontr_obcol);
+ ipocontr_obcol->SetObject(gameobj->GetSGNode());
}
KX_IInterpolator *interpolator =
new KX_ScalarInterpolator(
- &ipocontr->m_rgba[3],
+ &ipocontr_obcol->m_rgba[3],
ipo);
- ipocontr->AddInterpolator(interpolator);
+ ipocontr_obcol->AddInterpolator(interpolator);
}
}
diff --git a/source/gameengine/Converter/SConscript b/source/gameengine/Converter/SConscript
index 3be352c568b..361dca58005 100644
--- a/source/gameengine/Converter/SConscript
+++ b/source/gameengine/Converter/SConscript
@@ -2,6 +2,7 @@
Import ('env')
sources = env.Glob('*.cpp')
+defs = []
incs = '. #source/kernel/gen_system #intern/string #intern/guardedalloc'
incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer #intern/bmfont'
@@ -14,12 +15,16 @@ incs += ' #source/blender/include #source/blender/makesdna #source/gameengine/Ra
incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer #source/gameengine/GameLogic'
incs += ' #source/gameengine/Expressions #source/gameengine/Network #source/gameengine/SceneGraph'
incs += ' #source/gameengine/Physics/common #source/gameengine/Physics/Bullet #source/gameengine/Physics/BlOde'
-incs += ' #source/gameengine/Physics/Dummy #source/gameengine/Physics/Sumo'
-incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork'
+incs += ' #source/gameengine/Physics/Dummy'
+incs += ' #source/gameengine/Network/LoopBackNetwork'
incs += ' #source/blender/misc #source/blender/blenloader #source/blender/gpu'
+if env['WITH_BF_SOLID']:
+ incs += ' #source/gameengine/Physics/Sumo #source/gameengine/Physics/Sumo/Fuzzics/include'
+ incs += ' ' + env['BF_SOLID_INC']
+ defs.append('USE_SUMO_SOLID')
+
incs += ' ' + env['BF_PYTHON_INC']
-incs += ' ' + env['BF_SOLID_INC']
incs += ' ' + env['BF_BULLET_INC']
-env.BlenderLib ( 'bf_converter', sources, Split(incs), [], libtype=['game','player'], priority=[5,70] )
+env.BlenderLib ( 'bf_converter', sources, Split(incs), defs, libtype=['game','player'], priority=[5,70] )
diff --git a/source/gameengine/Expressions/FloatValue.cpp b/source/gameengine/Expressions/FloatValue.cpp
index 93f102d04a6..460eaa73f35 100644
--- a/source/gameengine/Expressions/FloatValue.cpp
+++ b/source/gameengine/Expressions/FloatValue.cpp
@@ -127,6 +127,9 @@ ret: a new object containing the result of applying operator op to val and
{
switch (op)
{
+ case VALUE_MOD_OPERATOR:
+ ret = new CFloatValue(fmod(((CIntValue *) val)->GetInt(), m_float));
+ break;
case VALUE_ADD_OPERATOR:
ret = new CFloatValue(((CIntValue *) val)->GetInt() + m_float);
break;
@@ -171,6 +174,9 @@ ret: a new object containing the result of applying operator op to val and
{
switch (op)
{
+ case VALUE_MOD_OPERATOR:
+ ret = new CFloatValue(fmod(((CFloatValue *) val)->GetFloat(), m_float));
+ break;
case VALUE_ADD_OPERATOR:
ret = new CFloatValue(((CFloatValue *) val)->GetFloat() + m_float);
break;
diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/InputParser.cpp
index a60e1ee59dc..94663c4a365 100644
--- a/source/gameengine/Expressions/InputParser.cpp
+++ b/source/gameengine/Expressions/InputParser.cpp
@@ -175,6 +175,9 @@ void CParser::NextSym()
case ',':
sym = commasym; NextCh();
break;
+ case '%' :
+ sym = opsym; opkind = OPmodulus; NextCh();
+ break;
case '+' :
sym = opsym; opkind = OPplus; NextCh();
break;
@@ -274,7 +277,7 @@ void CParser::NextSym()
} else if (((ch >= 'a') && (ch <= 'z'))
|| ((ch >= 'A') && (ch <= 'Z')))
{ // reserved word?
- int start;
+
start = chcount;
CharRep();
GrabString(start);
@@ -370,6 +373,7 @@ int CParser::Priority(int optorkind) {
case OPunequal: return 3;
case OPplus:
case OPminus: return 4;
+ case OPmodulus:
case OPtimes:
case OPdivide: return 5;
}
@@ -390,6 +394,7 @@ CExpression *CParser::Ex(int i) {
NextSym();
e2 = Ex(i + 1);
switch(opkind2) {
+ case OPmodulus: e1 = new COperator2Expr(VALUE_MOD_OPERATOR,e1, e2); break;
case OPplus: e1 = new COperator2Expr(VALUE_ADD_OPERATOR,e1, e2); break;
case OPminus: e1 = new COperator2Expr(VALUE_SUB_OPERATOR,e1, e2); break;
case OPtimes: e1 = new COperator2Expr(VALUE_MUL_OPERATOR,e1, e2); break;
diff --git a/source/gameengine/Expressions/InputParser.h b/source/gameengine/Expressions/InputParser.h
index 4caa47cbb0c..f51c473ba18 100644
--- a/source/gameengine/Expressions/InputParser.h
+++ b/source/gameengine/Expressions/InputParser.h
@@ -49,6 +49,7 @@ private:
}; // all kinds of symbols
enum optype {
+ OPmodulus,
OPplus,
OPminus,
OPtimes,
diff --git a/source/gameengine/Expressions/IntValue.cpp b/source/gameengine/Expressions/IntValue.cpp
index fbf4f4f59e0..fb586cb4979 100644
--- a/source/gameengine/Expressions/IntValue.cpp
+++ b/source/gameengine/Expressions/IntValue.cpp
@@ -125,6 +125,9 @@ this object
case VALUE_INT_TYPE:
{
switch (op) {
+ case VALUE_MOD_OPERATOR:
+ ret = new CIntValue (((CIntValue *) val)->GetInt() % m_int);
+ break;
case VALUE_ADD_OPERATOR:
ret = new CIntValue (((CIntValue *) val)->GetInt() + m_int);
break;
@@ -181,6 +184,9 @@ this object
case VALUE_FLOAT_TYPE:
{
switch (op) {
+ case VALUE_MOD_OPERATOR:
+ ret = new CFloatValue(fmod(((CFloatValue *) val)->GetFloat(), m_int));
+ break;
case VALUE_ADD_OPERATOR:
ret = new CFloatValue (((CFloatValue *) val)->GetFloat() + m_int);
break;
diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp
index 9acc6ad2cde..90a939af236 100644
--- a/source/gameengine/Expressions/ListValue.cpp
+++ b/source/gameengine/Expressions/ListValue.cpp
@@ -232,7 +232,9 @@ PyMethodDef CListValue::Methods[] = {
{NULL,NULL} //Sentinel
};
-
+PyAttributeDef CListValue::Attributes[] = {
+ { NULL } //Sentinel
+};
PyObject* CListValue::_getattr(const char *attr) {
_getattr_up(CValue);
diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp
index 2c4fbd5a867..1bead0a7664 100644
--- a/source/gameengine/Expressions/PyObjectPlus.cpp
+++ b/source/gameengine/Expressions/PyObjectPlus.cpp
@@ -147,7 +147,7 @@ PyObject *PyObjectPlus::_getattr_self(const PyAttributeDef attrlist[], void *sel
if (attrdef->m_length > 1)
{
PyObject* resultlist = PyList_New(attrdef->m_length);
- for (int i=0; i<attrdef->m_length; i++)
+ for (unsigned int i=0; i<attrdef->m_length; i++)
{
switch (attrdef->m_type) {
case KX_PYATTRIBUTE_TYPE_BOOL:
@@ -707,5 +707,35 @@ PyObject *PyObjectPlus::Py_isA(PyObject *value) // Python wrapper for isA
Py_RETURN_FALSE;
}
+/* Utility function called by the macro _getattr_up()
+ * for getting ob.__dict__() values from our PyObject
+ * this is used by python for doing dir() on an object, so its good
+ * if we return a list of attributes and methods.
+ *
+ * Other then making dir() useful the value returned from __dict__() is not useful
+ * since every value is a Py_None
+ * */
+PyObject *_getattr_dict(PyObject *pydict, PyMethodDef *meth, PyAttributeDef *attrdef)
+{
+ if(pydict==NULL) { /* incase calling __dict__ on the parent of this object raised an error */
+ PyErr_Clear();
+ pydict = PyDict_New();
+ }
+
+ if(meth) {
+ for (; meth->ml_name != NULL; meth++) {
+ PyDict_SetItemString(pydict, meth->ml_name, Py_None);
+ }
+ }
+
+ if(attrdef) {
+ for (; attrdef->m_name != NULL; attrdef++) {
+ PyDict_SetItemString(pydict, attrdef->m_name, Py_None);
+ }
+ }
+
+ return pydict;
+}
+
#endif //NO_EXP_PYTHON_EMBEDDING
diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h
index 0fae175e3cf..1a5f50a3d23 100644
--- a/source/gameengine/Expressions/PyObjectPlus.h
+++ b/source/gameengine/Expressions/PyObjectPlus.h
@@ -73,7 +73,7 @@ typedef int Py_ssize_t;
#endif
static inline void Py_Fatal(const char *M) {
- //cout << M << endl;
+ fprintf(stderr, "%s\n", M);
exit(-1);
};
@@ -89,35 +89,22 @@ static inline void Py_Fatal(const char *M) {
virtual PyParentObject *GetParents(void) {return Parents;}
+
// This defines the _getattr_up macro
// which allows attribute and method calls
// to be properly passed up the hierarchy.
#define _getattr_up(Parent) \
- PyObject *rvalue = NULL; \
- if (!strcmp(attr, "__methods__")) { \
- PyObject *_attr_string = NULL; \
- PyMethodDef *meth = Methods; \
- rvalue = Parent::_getattr(attr); \
- if (rvalue==NULL) { \
- PyErr_Clear(); \
- rvalue = PyList_New(0); \
- } \
- if (meth) { \
- for (; meth->ml_name != NULL; meth++) { \
- _attr_string = PyString_FromString(meth->ml_name); \
- PyList_Append(rvalue, _attr_string); \
- Py_DECREF(_attr_string); \
- } \
+ PyObject *rvalue = Py_FindMethod(Methods, this, attr); \
+ \
+ if (rvalue == NULL) { \
+ PyErr_Clear(); \
+ rvalue = Parent::_getattr(attr); \
} \
- } else { \
- rvalue = Py_FindMethod(Methods, this, attr); \
- if (rvalue == NULL) { \
- PyErr_Clear(); \
- rvalue = Parent::_getattr(attr); \
- } \
- } \
- return rvalue; \
-
+ if ((rvalue == NULL) && !strcmp(attr, "__dict__")) {\
+ PyErr_Clear(); \
+ rvalue = _getattr_dict(Parent::_getattr(attr), Methods, Attributes); \
+ } \
+ return rvalue; \
/**
* These macros are helpfull when embedding Python routines. The second
@@ -398,6 +385,8 @@ public:
}
};
+PyObject *_getattr_dict(PyObject *pydict, PyMethodDef *meth, PyAttributeDef *attrdef);
+
#endif // _adr_py_lib_h_
#endif //NO_EXP_PYTHON_EMBEDDING
diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp
index 9b26cda01b3..ebb12636ac2 100644
--- a/source/gameengine/Expressions/Value.cpp
+++ b/source/gameengine/Expressions/Value.cpp
@@ -52,6 +52,10 @@ PyObject* cvalue_div(PyObject*v, PyObject*w)
{
return ((CValue*)v)->Calc(VALUE_DIV_OPERATOR,(CValue*)w);
}
+PyObject* cvalue_mod(PyObject*v, PyObject*w)
+{
+ return ((CValue*)v)->Calc(VALUE_MOD_OPERATOR,(CValue*)w);
+}
PyObject* cvalue_neg(PyObject*v)
{
return ((CValue*)v)->Calc(VALUE_NEG_OPERATOR,(CValue*)v);
@@ -112,7 +116,7 @@ static PyNumberMethods cvalue_as_number = {
(binaryfunc)cvalue_sub, /*nb_subtract*/
(binaryfunc)cvalue_mul, /*nb_multiply*/
(binaryfunc)cvalue_div, /*nb_divide*/
- 0,//(binaryfunc)cvalue_remainder, /*nb_remainder*/
+ (binaryfunc)cvalue_mod, /*nb_remainder*/
0,//(binaryfunc)cvalue_divmod, /*nb_divmod*/
0,//0,//0,//0,//(ternaryfunc)cvalue_pow, /*nb_power*/
(unaryfunc)cvalue_neg, /*nb_negative*/
@@ -257,6 +261,9 @@ STR_String CValue::op2str (VALUE_OPERATOR op)
STR_String opmsg;
switch (op) {
+ case VALUE_MOD_OPERATOR:
+ opmsg = " % ";
+ break;
case VALUE_ADD_OPERATOR:
opmsg = " + ";
break;
@@ -673,6 +680,10 @@ static PyMethodDef CValueMethods[] =
{ NULL,NULL} // Sentinel
};
+PyAttributeDef CValue::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* CValue::_getattr(const char *attr)
{
diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h
index 854334b892b..caf1064dc32 100644
--- a/source/gameengine/Expressions/Value.h
+++ b/source/gameengine/Expressions/Value.h
@@ -75,6 +75,7 @@
enum VALUE_OPERATOR {
+ VALUE_MOD_OPERATOR, // %
VALUE_ADD_OPERATOR, // +
VALUE_SUB_OPERATOR, // -
VALUE_MUL_OPERATOR, // *
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
index e8e29fb2769..c21e5db1410 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
+++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
@@ -42,14 +42,14 @@ SCA_Joystick::SCA_Joystick(short int index)
m_axis21(0),
m_prec(3200),
m_buttonnum(-2),
+ m_axismax(-1),
m_hatdir(-2),
+ m_buttonmax(-1),
+ m_hatmax(-1),
m_isinit(0),
m_istrig_axis(0),
m_istrig_button(0),
- m_istrig_hat(0),
- m_axismax(-1),
- m_buttonmax(-1),
- m_hatmax(-1)
+ m_istrig_hat(0)
{
#ifndef DISABLE_SDL
m_private = new PrivateData();
diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
index 6fcb1be654c..7bf051f2b5c 100644
--- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
+++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
@@ -113,6 +113,9 @@ PyMethodDef SCA_2DFilterActuator::Methods[] = {
{NULL,NULL}
};
+PyAttributeDef SCA_2DFilterActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
PyObject* SCA_2DFilterActuator::_getattr(const char *attr) {
_getattr_up(SCA_IActuator);
diff --git a/source/gameengine/GameLogic/SCA_ANDController.cpp b/source/gameengine/GameLogic/SCA_ANDController.cpp
index 98a3c2e96cd..b67ef7dabaf 100644
--- a/source/gameengine/GameLogic/SCA_ANDController.cpp
+++ b/source/gameengine/GameLogic/SCA_ANDController.cpp
@@ -137,6 +137,10 @@ PyMethodDef SCA_ANDController::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef SCA_ANDController::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* SCA_ANDController::_getattr(const char *attr) {
_getattr_up(SCA_IController);
}
diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
index 76aa328aa48..154f0ad8cef 100644
--- a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
@@ -135,6 +135,10 @@ PyMethodDef SCA_AlwaysSensor::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef SCA_AlwaysSensor::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* SCA_AlwaysSensor::_getattr(const char *attr) {
_getattr_up(SCA_ISensor);
}
diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp
index 25c9888cadd..31a620b939d 100644
--- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp
+++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp
@@ -53,10 +53,10 @@ SCA_DelaySensor::SCA_DelaySensor(class SCA_EventManager* eventmgr,
int duration,
bool repeat,
PyTypeObject* T)
- : SCA_ISensor(gameobj,eventmgr, T),
+ : SCA_ISensor(gameobj,eventmgr, T),
+ m_repeat(repeat),
m_delay(delay),
- m_duration(duration),
- m_repeat(repeat)
+ m_duration(duration)
{
Init();
}
diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.cpp b/source/gameengine/GameLogic/SCA_ExpressionController.cpp
index e9a543c9f31..8ed46beb7f3 100644
--- a/source/gameengine/GameLogic/SCA_ExpressionController.cpp
+++ b/source/gameengine/GameLogic/SCA_ExpressionController.cpp
@@ -49,7 +49,8 @@ SCA_ExpressionController::SCA_ExpressionController(SCA_IObject* gameobj,
const STR_String& exprtext,
PyTypeObject* T)
:SCA_IController(gameobj,T),
- m_exprText(exprtext)
+ m_exprText(exprtext),
+ m_exprCache(NULL)
{
}
@@ -57,6 +58,8 @@ SCA_ExpressionController::SCA_ExpressionController(SCA_IObject* gameobj,
SCA_ExpressionController::~SCA_ExpressionController()
{
+ if (m_exprCache)
+ m_exprCache->Release();
}
@@ -65,6 +68,7 @@ CValue* SCA_ExpressionController::GetReplica()
{
SCA_ExpressionController* replica = new SCA_ExpressionController(*this);
replica->m_exprText = m_exprText;
+ replica->m_exprCache = NULL;
// this will copy properties and so on...
CValue::AddDataToReplica(replica);
@@ -72,18 +76,32 @@ CValue* SCA_ExpressionController::GetReplica()
}
+// Forced deletion of precalculated expression to break reference loop
+// Use this function when you know that you won't use the sensor anymore
+void SCA_ExpressionController::Delete()
+{
+ if (m_exprCache)
+ {
+ m_exprCache->Release();
+ m_exprCache = NULL;
+ }
+ Release();
+}
+
void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr)
{
bool expressionresult = false;
-
- CParser parser;
- parser.SetContext(this->AddRef());
- CExpression* expr = parser.ProcessText(m_exprText);
- if (expr)
+ if (!m_exprCache)
+ {
+ CParser parser;
+ parser.SetContext(this->AddRef());
+ m_exprCache = parser.ProcessText(m_exprText);
+ }
+ if (m_exprCache)
{
- CValue* value = expr->Calculate();
+ CValue* value = m_exprCache->Calculate();
if (value)
{
if (value->IsError())
@@ -97,7 +115,8 @@ void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr)
value->Release();
}
- expr->Release();
+ //m_exprCache->Release();
+ //m_exprCache = NULL;
}
/*
diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.h b/source/gameengine/GameLogic/SCA_ExpressionController.h
index 20e1eb77771..79c26eea1e7 100644
--- a/source/gameengine/GameLogic/SCA_ExpressionController.h
+++ b/source/gameengine/GameLogic/SCA_ExpressionController.h
@@ -38,6 +38,7 @@ class SCA_ExpressionController : public SCA_IController
{
// Py_Header;
STR_String m_exprText;
+ CExpression* m_exprCache;
public:
SCA_ExpressionController(SCA_IObject* gameobj,
@@ -48,6 +49,11 @@ public:
virtual CValue* GetReplica();
virtual void Trigger(SCA_LogicManager* logicmgr);
virtual CValue* FindIdentifier(const STR_String& identifiername);
+ /**
+ * used to release the expression cache
+ * so that self references are removed before the controller itself is released
+ */
+ virtual void Delete();
/* --------------------------------------------------------------------- */
/* Python interface ---------------------------------------------------- */
diff --git a/source/gameengine/GameLogic/SCA_IActuator.cpp b/source/gameengine/GameLogic/SCA_IActuator.cpp
index eeca2d7b44c..309f3108418 100644
--- a/source/gameengine/GameLogic/SCA_IActuator.cpp
+++ b/source/gameengine/GameLogic/SCA_IActuator.cpp
@@ -36,8 +36,8 @@ using namespace std;
SCA_IActuator::SCA_IActuator(SCA_IObject* gameobj,
PyTypeObject* T) :
- m_links(0),
- SCA_ILogicBrick(gameobj,T)
+ SCA_ILogicBrick(gameobj,T),
+ m_links(0)
{
// nothing to do
}
diff --git a/source/gameengine/GameLogic/SCA_IActuator.h b/source/gameengine/GameLogic/SCA_IActuator.h
index 7ffb21b5490..51bd6454d92 100644
--- a/source/gameengine/GameLogic/SCA_IActuator.h
+++ b/source/gameengine/GameLogic/SCA_IActuator.h
@@ -36,9 +36,9 @@ class SCA_IActuator : public SCA_ILogicBrick
{
friend class SCA_LogicManager;
protected:
- std::vector<CValue*> m_events;
int m_links; // number of active links to controllers
// when 0, the actuator is automatically stopped
+ std::vector<CValue*> m_events;
void RemoveAllEvents();
public:
diff --git a/source/gameengine/GameLogic/SCA_IController.cpp b/source/gameengine/GameLogic/SCA_IController.cpp
index 0bd20117f31..f9c192cae5c 100644
--- a/source/gameengine/GameLogic/SCA_IController.cpp
+++ b/source/gameengine/GameLogic/SCA_IController.cpp
@@ -38,8 +38,8 @@
SCA_IController::SCA_IController(SCA_IObject* gameobj,
PyTypeObject* T)
:
- m_statemask(0),
- SCA_ILogicBrick(gameobj,T)
+ SCA_ILogicBrick(gameobj,T),
+ m_statemask(0)
{
}
diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h
index cde1353275b..70d49941613 100644
--- a/source/gameengine/GameLogic/SCA_ILogicBrick.h
+++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h
@@ -62,6 +62,7 @@ public:
SCA_IObject* GetParent();
virtual void ReParent(SCA_IObject* parent);
virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map);
+ virtual void Delete() { Release(); }
// act as a BoolValue (with value IsPositiveTrigger)
virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp
index 3afc48b719c..debd62d44e6 100644
--- a/source/gameengine/GameLogic/SCA_IObject.cpp
+++ b/source/gameengine/GameLogic/SCA_IObject.cpp
@@ -40,7 +40,7 @@
MT_Point3 SCA_IObject::m_sDummy=MT_Point3(0,0,0);
-SCA_IObject::SCA_IObject(PyTypeObject* T): m_initState(0), m_state(0), CValue(T)
+SCA_IObject::SCA_IObject(PyTypeObject* T): CValue(T), m_initState(0), m_state(0)
{
m_suspended = false;
}
@@ -59,7 +59,9 @@ SCA_IObject::~SCA_IObject()
SCA_ControllerList::iterator itc;
for (itc = m_controllers.begin(); !(itc == m_controllers.end()); ++itc)
{
- ((CValue*)(*itc))->Release();
+ //Use Delete for controller to ensure proper cleaning (expression controller)
+ (*itc)->Delete();
+ //((CValue*)(*itc))->Release();
}
SCA_ActuatorList::iterator ita;
for (ita = m_registeredActuators.begin(); !(ita==m_registeredActuators.end()); ++ita)
@@ -407,6 +409,9 @@ PyMethodDef SCA_IObject::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef SCA_IObject::Attributes[] = {
+ { NULL } //Sentinel
+};
PyObject* SCA_IObject::_getattr(const char *attr) {
diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h
index 5ae7ced2a2a..23f2c76c19f 100644
--- a/source/gameengine/GameLogic/SCA_ISensor.h
+++ b/source/gameengine/GameLogic/SCA_ISensor.h
@@ -105,11 +105,6 @@ public:
bool negmode,
int freq);
- /** Release sensor
- * For property sensor, it is used to release the pre-calculated expression
- * so that self references are removed before the sensor itself is released
- */
- virtual void Delete() { Release(); }
/** Set inversion of pulses on or off. */
void SetInvert(bool inv);
/** set the level detection on or off */
diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp
index 4f4d62f13b9..36e4a5f2c30 100644
--- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp
@@ -158,8 +158,8 @@ bool SCA_MouseSensor::Evaluate(CValue* event)
case KX_MOUSESENSORMODE_WHEELUP:
case KX_MOUSESENSORMODE_WHEELDOWN:
{
- const SCA_InputEvent& event = mousedev->GetEventValue(m_hotkey);
- switch (event.m_status){
+ const SCA_InputEvent& mevent = mousedev->GetEventValue(m_hotkey);
+ switch (mevent.m_status){
case SCA_InputEvent::KX_JUSTACTIVATED:
m_val = 1;
result = true;
diff --git a/source/gameengine/GameLogic/SCA_NANDController.cpp b/source/gameengine/GameLogic/SCA_NANDController.cpp
index 0efa8da153a..18426d75582 100644
--- a/source/gameengine/GameLogic/SCA_NANDController.cpp
+++ b/source/gameengine/GameLogic/SCA_NANDController.cpp
@@ -137,6 +137,10 @@ PyMethodDef SCA_NANDController::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef SCA_NANDController::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* SCA_NANDController::_getattr(const char *attr) {
_getattr_up(SCA_IController);
}
diff --git a/source/gameengine/GameLogic/SCA_NORController.cpp b/source/gameengine/GameLogic/SCA_NORController.cpp
index fa24be9ebce..1de6a641c3d 100644
--- a/source/gameengine/GameLogic/SCA_NORController.cpp
+++ b/source/gameengine/GameLogic/SCA_NORController.cpp
@@ -137,6 +137,10 @@ PyMethodDef SCA_NORController::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef SCA_NORController::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* SCA_NORController::_getattr(const char *attr) {
_getattr_up(SCA_IController);
}
diff --git a/source/gameengine/GameLogic/SCA_ORController.cpp b/source/gameengine/GameLogic/SCA_ORController.cpp
index 42a29e1959b..61fbc889d90 100644
--- a/source/gameengine/GameLogic/SCA_ORController.cpp
+++ b/source/gameengine/GameLogic/SCA_ORController.cpp
@@ -129,6 +129,11 @@ PyMethodDef SCA_ORController::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef SCA_ORController::Attributes[] = {
+ { NULL } //Sentinel
+};
+
+
PyObject* SCA_ORController::_getattr(const char *attr) {
_getattr_up(SCA_IController);
}
diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h
index 933de49de18..2594e3fca9d 100644
--- a/source/gameengine/GameLogic/SCA_PropertySensor.h
+++ b/source/gameengine/GameLogic/SCA_PropertySensor.h
@@ -70,6 +70,10 @@ public:
KX_PROPSENSOR_TYPE checktype,
PyTypeObject* T=&Type );
+ /**
+ * For property sensor, it is used to release the pre-calculated expression
+ * so that self references are removed before the sensor itself is released
+ */
virtual void Delete();
virtual ~SCA_PropertySensor();
virtual CValue* GetReplica();
diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp
index 2fff21f22fb..c75e36acab2 100644
--- a/source/gameengine/GameLogic/SCA_PythonController.cpp
+++ b/source/gameengine/GameLogic/SCA_PythonController.cpp
@@ -157,8 +157,40 @@ static const char* sPyGetCurrentController__doc__;
PyObject* SCA_PythonController::sPyGetCurrentController(PyObject* self)
{
- m_sCurrentController->AddRef();
- return m_sCurrentController;
+ return m_sCurrentController->AddRef();
+}
+
+SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
+{
+ // for safety, todo: only allow for registered actuators (pointertable)
+ // we don't want to crash gameengine/blender by python scripts
+ std::vector<SCA_IActuator*> lacts = m_sCurrentController->GetLinkedActuators();
+ std::vector<SCA_IActuator*>::iterator it;
+
+ if (PyString_Check(value)) {
+ /* get the actuator from the name */
+ char *name= PyString_AsString(value);
+ for(it = lacts.begin(); it!= lacts.end(); it++) {
+ if( name == (*it)->GetName() ) {
+ return *it;
+ }
+ }
+ }
+ else {
+ /* Expecting an actuator type */
+ for(it = lacts.begin(); it!= lacts.end(); it++) {
+ if( static_cast<SCA_IActuator*>(value) == (*it) ) {
+ return *it;
+ }
+ }
+ }
+
+ /* set the exception */
+ PyObject *value_str = PyObject_Repr(value); /* new ref */
+ PyErr_Format(PyExc_ValueError, "'%s' not in this controllers actuator list", PyString_AsString(value_str));
+ Py_DECREF(value_str);
+
+ return false;
}
#if 0
@@ -175,26 +207,14 @@ PyObject* SCA_PythonController::sPyAddActiveActuator(
int activate;
if (!PyArg_ParseTuple(args, "Oi", &ob1,&activate))
return NULL;
-
- // for safety, todo: only allow for registered actuators (pointertable)
- // we don't want to crash gameengine/blender by python scripts
- std::vector<SCA_IActuator*> lacts = m_sCurrentController->GetLinkedActuators();
- std::vector<SCA_IActuator*>::iterator it;
- bool found = false;
- CValue* act = (CValue*)ob1;
-
- for(it = lacts.begin(); it!= lacts.end(); it++) {
- if( static_cast<SCA_IActuator*>(act) == (*it) ) {
- found=true;
- break;
- }
- }
- if(found){
- CValue* boolval = new CBoolValue(activate!=0);
- m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)act,boolval);
- boolval->Release();
- }
+ SCA_IActuator* actu = LinkedActuatorFromPy(ob1);
+ if(actu==NULL)
+ return NULL;
+
+ CValue* boolval = new CBoolValue(activate!=0);
+ m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu,boolval);
+ boolval->Release();
Py_RETURN_NONE;
}
@@ -229,6 +249,9 @@ PyParentObject SCA_PythonController::Parents[] = {
NULL
};
PyMethodDef SCA_PythonController::Methods[] = {
+ {"activate", (PyCFunction) SCA_PythonController::sPyActivate, METH_O},
+ {"deactivate", (PyCFunction) SCA_PythonController::sPyDeActivate, METH_O},
+
{"getActuators", (PyCFunction) SCA_PythonController::sPyGetActuators, METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::GetActuators_doc},
{"getActuator", (PyCFunction) SCA_PythonController::sPyGetActuator, METH_O, (PY_METHODCHAR)SCA_PythonController::GetActuator_doc},
{"getSensors", (PyCFunction) SCA_PythonController::sPyGetSensors, METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::GetSensors_doc},
@@ -241,6 +264,46 @@ PyMethodDef SCA_PythonController::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef SCA_PythonController::Attributes[] = {
+ { NULL } //Sentinel
+};
+
+bool SCA_PythonController::Compile()
+{
+ //printf("py script modified '%s'\n", m_scriptName.Ptr());
+
+ // if a script already exists, decref it before replace the pointer to a new script
+ if (m_bytecode)
+ {
+ Py_DECREF(m_bytecode);
+ m_bytecode=NULL;
+ }
+ // recompile the scripttext into bytecode
+ m_bytecode = Py_CompileString(m_scriptText.Ptr(), m_scriptName.Ptr(), Py_file_input);
+ m_bModified=false;
+
+ if (m_bytecode)
+ {
+
+ return true;
+ }
+ else {
+ // didn't compile, so instead of compile, complain
+ // something is wrong, tell the user what went wrong
+ printf("Python compile error from controller \"%s\": \n", GetName().Ptr());
+ //PyRun_SimpleString(m_scriptText.Ptr());
+ PyErr_Print();
+
+ /* Added in 2.48a, the last_traceback can reference Objects for example, increasing
+ * their user count. Not to mention holding references to wrapped data.
+ * This is especially bad when the PyObject for the wrapped data is free'd, after blender
+ * has alredy dealocated the pointer */
+ PySys_SetObject( (char *)"last_traceback", Py_None);
+ PyErr_Clear(); /* just to be sure */
+
+ return false;
+ }
+}
void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
{
@@ -249,33 +312,13 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
if (m_bModified)
{
- // if a script already exists, decref it before replace the pointer to a new script
- if (m_bytecode)
- {
- Py_DECREF(m_bytecode);
- m_bytecode=NULL;
- }
- // recompile the scripttext into bytecode
- m_bytecode = Py_CompileString(m_scriptText.Ptr(), m_scriptName.Ptr(), Py_file_input);
- if (!m_bytecode)
- {
- // didn't compile, so instead of compile, complain
- // something is wrong, tell the user what went wrong
- printf("Python compile error from controller \"%s\": \n", GetName().Ptr());
- //PyRun_SimpleString(m_scriptText.Ptr());
- PyErr_Print();
-
- /* Added in 2.48a, the last_traceback can reference Objects for example, increasing
- * their user count. Not to mention holding references to wrapped data.
- * This is especially bad when the PyObject for the wrapped data is free'd, after blender
- * has alredy dealocated the pointer */
- PySys_SetObject( "last_traceback", Py_None);
- PyErr_Clear(); /* just to be sure */
-
+ if (Compile()==false) // sets m_bModified to false
return;
- }
- m_bModified=false;
}
+ if (!m_bytecode) {
+ return;
+ }
+
/*
* This part here with excdict is a temporary patch
@@ -313,7 +356,7 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
* their user count. Not to mention holding references to wrapped data.
* This is especially bad when the PyObject for the wrapped data is free'd, after blender
* has alredy dealocated the pointer */
- PySys_SetObject( "last_traceback", Py_None);
+ PySys_SetObject( (char *)"last_traceback", Py_None);
PyErr_Clear(); /* just to be sure */
//PyRun_SimpleString(m_scriptText.Ptr());
@@ -363,6 +406,29 @@ int SCA_PythonController::_setattr(const char *attr, PyObject *value)
return SCA_IController::_setattr(attr, value);
}
+PyObject* SCA_PythonController::PyActivate(PyObject* self, PyObject *value)
+{
+ SCA_IActuator* actu = LinkedActuatorFromPy(value);
+ if(actu==NULL)
+ return NULL;
+
+ CValue* boolval = new CBoolValue(true);
+ m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, boolval);
+ boolval->Release();
+ Py_RETURN_NONE;
+}
+
+PyObject* SCA_PythonController::PyDeActivate(PyObject* self, PyObject *value)
+{
+ SCA_IActuator* actu = LinkedActuatorFromPy(value);
+ if(actu==NULL)
+ return NULL;
+
+ CValue* boolval = new CBoolValue(false);
+ m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, boolval);
+ boolval->Release();
+ Py_RETURN_NONE;
+}
PyObject* SCA_PythonController::PyGetActuators(PyObject* self)
{
@@ -420,8 +486,7 @@ SCA_PythonController::PyGetActuator(PyObject* self, PyObject* value)
for (unsigned int index=0;index<m_linkedactuators.size();index++)
{
SCA_IActuator* actua = m_linkedactuators[index];
- STR_String realname = actua->GetName();
- if (realname == scriptArg)
+ if (actua->GetName() == scriptArg)
{
return actua->AddRef();
}
diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h
index 00c30d7f3d5..4ec18f32c23 100644
--- a/source/gameengine/GameLogic/SCA_PythonController.h
+++ b/source/gameengine/GameLogic/SCA_PythonController.h
@@ -70,15 +70,20 @@ class SCA_PythonController : public SCA_IController
void AddTriggeredSensor(class SCA_ISensor* sensor)
{ m_triggeredSensors.push_back(sensor); }
int IsTriggered(class SCA_ISensor* sensor);
+ bool Compile();
static const char* sPyGetCurrentController__doc__;
static PyObject* sPyGetCurrentController(PyObject* self);
static const char* sPyAddActiveActuator__doc__;
static PyObject* sPyAddActiveActuator(PyObject* self,
PyObject* args);
+ static SCA_IActuator* LinkedActuatorFromPy(PyObject *value);
virtual PyObject* _getattr(const char *attr);
virtual int _setattr(const char *attr, PyObject *value);
+
+ KX_PYMETHOD_O(SCA_PythonController,Activate);
+ KX_PYMETHOD_O(SCA_PythonController,DeActivate);
KX_PYMETHOD_DOC_NOARGS(SCA_PythonController,GetSensors);
KX_PYMETHOD_DOC_NOARGS(SCA_PythonController,GetActuators);
KX_PYMETHOD_DOC_O(SCA_PythonController,GetSensor);
diff --git a/source/gameengine/GameLogic/SCA_XNORController.cpp b/source/gameengine/GameLogic/SCA_XNORController.cpp
index b019aedc93d..b2734dd1b33 100644
--- a/source/gameengine/GameLogic/SCA_XNORController.cpp
+++ b/source/gameengine/GameLogic/SCA_XNORController.cpp
@@ -141,6 +141,10 @@ PyMethodDef SCA_XNORController::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef SCA_XNORController::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* SCA_XNORController::_getattr(const char *attr) {
_getattr_up(SCA_IController);
}
diff --git a/source/gameengine/GameLogic/SCA_XORController.cpp b/source/gameengine/GameLogic/SCA_XORController.cpp
index 11ffa19b8f1..662ef523d56 100644
--- a/source/gameengine/GameLogic/SCA_XORController.cpp
+++ b/source/gameengine/GameLogic/SCA_XORController.cpp
@@ -141,6 +141,10 @@ PyMethodDef SCA_XORController::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef SCA_XORController::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* SCA_XORController::_getattr(const char *attr) {
_getattr_up(SCA_IController);
}
diff --git a/source/gameengine/GamePlayer/common/SConscript b/source/gameengine/GamePlayer/common/SConscript
index c9bda78d905..23ad413350b 100644
--- a/source/gameengine/GamePlayer/common/SConscript
+++ b/source/gameengine/GamePlayer/common/SConscript
@@ -39,15 +39,13 @@ incs = ['.',
'#source/gameengine/Network',
'#source/gameengine/SceneGraph',
'#source/gameengine/Physics/common',
- '#source/gameengine/Physics/Sumo',
- '#source/gameengine/Physics/Sumo/Fuzzics/include',
'#source/gameengine/Network/LoopBackNetwork',
'#source/gameengine/GamePlayer/ghost',
'#source/blender/misc',
'#source/blender/blenloader',
'#source/blender/gpu',
'#extern/glew/include']
-
+
#This is all plugin stuff!
#if sys.platform=='win32':
# source_files += ['windows/GPW_Canvas.cpp',
@@ -62,8 +60,12 @@ incs = ['.',
# 'unix/GPU_System.cpp']
# gp_common_env.Append ( CPPPATH = ['unix'])
+if env['WITH_BF_SOLID']:
+ incs.append('#source/gameengine/Physics/Sumo')
+ incs.append('#source/gameengine/Physics/Sumo/Fuzzics/include')
+ incs += Split(env['BF_SOLID_INC'])
+
incs += Split(env['BF_PYTHON_INC'])
-incs += Split(env['BF_SOLID_INC'])
incs += Split(env['BF_PNG_INC'])
incs += Split(env['BF_ZLIB_INC'])
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index 70272d57357..afee60c3192 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -162,33 +162,39 @@ void usage(const char* program)
consoleoption = "";
#endif
- printf("usage: %s [-w l t w h] %s[-g gamengineoptions] "
+ printf("usage: %s [-w [w h l t]] [-f [fw fh fb ff]] %s[-g gamengineoptions] "
"[-s stereomode] filename.blend\n", program, consoleoption);
- printf(" -h: Prints this command summary\n");
+ printf(" -h: Prints this command summary\n\n");
printf(" -w: display in a window\n");
+ printf(" --Optional parameters--\n");
+ printf(" w = window width\n");
+ printf(" h = window height\n\n");
printf(" l = window left coordinate\n");
printf(" t = window top coordinate\n");
- printf(" w = window width\n");
- printf(" h = window height\n");
+ printf(" Note: If w or h is defined, both must be defined.\n");
+ printf(" Also, if l or t is defined, all options must be used.\n\n");
printf(" -f: start game in full screen mode\n");
+ printf(" --Optional parameters--\n");
printf(" fw = full screen mode pixel width\n");
- printf(" fh = full screen mode pixel height\n");
+ printf(" fh = full screen mode pixel height\n\n");
printf(" fb = full screen mode bits per pixel\n");
printf(" ff = full screen mode frequency\n");
+ printf(" Note: If fw or fh is defined, both must be defined.\n");
+ printf(" Also, if fb is used, fw and fh must be used. ff requires all options.\n\n");
printf(" -s: start player in stereo\n");
printf(" stereomode: hwpageflip (Quad buffered shutter glasses)\n");
printf(" syncdoubling (Above Below)\n");
printf(" sidebyside (Left Right)\n");
printf(" anaglyph (Red-Blue glasses)\n");
printf(" vinterlace (Vertical interlace for autostereo display)\n");
- printf(" depending on the type of stereo you want\n");
+ printf(" depending on the type of stereo you want\n\n");
#ifndef _WIN32
- printf(" -i: parent windows ID \n");
+ printf(" -i: parent windows ID \n\n");
#endif
#ifdef _WIN32
- printf(" -c: keep console window open\n");
+ printf(" -c: keep console window open\n\n");
#endif
- printf(" -d: turn debugging on\n");
+ printf(" -d: turn debugging on\n\n");
printf(" -g: game engine options:\n\n");
printf(" Name Default Description\n");
printf(" ------------------------------------------------------------------------\n");
@@ -200,7 +206,7 @@ void usage(const char* program)
printf(" blender_material 0 Enable material settings\n");
printf(" ignore_deprecation_warnings 0 Ignore deprecation warnings\n");
printf("\n");
- printf("example: %s -w 10 10 320 200 -g noaudio c:\\loadtest.blend\n", program);
+ printf("example: %s -w 320 200 10 10 -g noaudio c:\\loadtest.blend\n", program);
printf("example: %s -g show_framerate = 0 c:\\loadtest.blend\n", program);
}
@@ -431,54 +437,41 @@ int main(int argc, char** argv)
G.f |= G_DEBUG; /* std output printf's */
MEM_set_memory_debug();
break;
-
- case 'p':
- // Parse window position and size options
- if (argv[i][2] == 0) {
- i++;
- if ((i + 4) < argc)
- {
- windowLeft = atoi(argv[i++]);
- windowTop = atoi(argv[i++]);
- windowWidth = atoi(argv[i++]);
- windowHeight = atoi(argv[i++]);
- windowParFound = true;
- }
- else
- {
- error = true;
- printf("error: too few options for window argument.\n");
- }
- } else { /* mac specific */
-
- if (strncmp(argv[i], "-psn_", 5)==0)
- i++; /* skip process serial number */
- }
- break;
+
case 'f':
i++;
fullScreen = true;
fullScreenParFound = true;
- if ((i + 2) < argc && argv[i][0] != '-' && argv[i+1][0] != '-')
+ if ((i + 2) <= argc && argv[i][0] != '-' && argv[i+1][0] != '-')
{
fullScreenWidth = atoi(argv[i++]);
fullScreenHeight = atoi(argv[i++]);
- if ((i + 1) < argc && argv[i][0] != '-')
+ if ((i + 1) <= argc && argv[i][0] != '-')
{
fullScreenBpp = atoi(argv[i++]);
- if ((i + 1) < argc && argv[i][0] != '-')
+ if ((i + 1) <= argc && argv[i][0] != '-')
fullScreenFrequency = atoi(argv[i++]);
}
}
break;
case 'w':
// Parse window position and size options
+ i++;
+ fullScreen = false;
+ windowParFound = true;
+
+ if ((i + 2) <= argc && argv[i][0] != '-' && argv[i+1][0] != '-')
{
- fullScreen = false;
- fullScreenParFound = true;
- i++;
+ windowWidth = atoi(argv[i++]);
+ windowHeight = atoi(argv[i++]);
+ if ((i +2) <= argc && argv[i][0] != '-' && argv[i+1][0] != '-')
+ {
+ windowLeft = atoi(argv[i++]);
+ windowTop = atoi(argv[i++]);
+ }
}
break;
+
case 'h':
usage(argv[0]);
return 0;
diff --git a/source/gameengine/GamePlayer/ghost/SConscript b/source/gameengine/GamePlayer/ghost/SConscript
index 0785ce4bd0d..dd8761e0a45 100644
--- a/source/gameengine/GamePlayer/ghost/SConscript
+++ b/source/gameengine/GamePlayer/ghost/SConscript
@@ -34,8 +34,6 @@ incs = ['.',
'#source/gameengine/Network',
'#source/gameengine/SceneGraph',
'#source/gameengine/Physics/common',
- '#source/gameengine/Physics/Sumo',
- '#source/gameengine/Physics/Sumo/Fuzzics/include',
'#source/gameengine/Network/LoopBackNetwork',
'#source/gameengine/GamePlayer/common',
'#source/blender/misc',
@@ -43,8 +41,11 @@ incs = ['.',
'#source/blender/gpu',
'#extern/glew/include']
+if env['WITH_BF_SOLID']:
+ incs.append(['#source/gameengine/Physics/Sumo', '#source/gameengine/Physics/Sumo/Fuzzics/include'])
+ incs += Split(env['BF_SOLID_INC'])
+
incs += Split(env['BF_PYTHON_INC'])
-incs += Split(env['BF_SOLID_INC'])
cxxflags = []
if env['OURPLATFORM']=='win32-vc':
diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp
index 2a4a74d5b90..60cb288436a 100644
--- a/source/gameengine/Ketsji/BL_Shader.cpp
+++ b/source/gameengine/Ketsji/BL_Shader.cpp
@@ -18,7 +18,7 @@
#define spit(x) std::cout << x << std::endl;
#define SORT_UNIFORMS 1
-#define UNIFORM_MAX_LEN sizeof(float)*16
+#define UNIFORM_MAX_LEN (int)sizeof(float)*16
#define MAX_LOG_LEN 262144 // bounds
BL_Uniform::BL_Uniform(int data_size)
@@ -108,7 +108,7 @@ void BL_Uniform::SetData(int location, int type,bool transpose)
#endif
}
-const bool BL_Shader::Ok()const
+bool BL_Shader::Ok()const
{
return (mShader !=0 && mOk && mUse);
}
@@ -767,6 +767,9 @@ PyMethodDef BL_Shader::Methods[] =
{NULL,NULL} //Sentinel
};
+PyAttributeDef BL_Shader::Attributes[] = {
+ { NULL } //Sentinel
+};
PyTypeObject BL_Shader::Type = {
PyObject_HEAD_INIT(&PyType_Type)
diff --git a/source/gameengine/Ketsji/BL_Shader.h b/source/gameengine/Ketsji/BL_Shader.h
index 52cbd0cda51..76acd5513ef 100644
--- a/source/gameengine/Ketsji/BL_Shader.h
+++ b/source/gameengine/Ketsji/BL_Shader.h
@@ -166,7 +166,7 @@ public:
//const BL_Sampler* GetSampler(int i);
void SetSampler(int loc, int unit);
- const bool Ok()const;
+ bool Ok()const;
unsigned int GetProg();
void SetProg(bool enable);
int GetAttribute(){return mAttr;};
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp
index 31f1d2dd3ee..4e5f27df2da 100644
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp
+++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp
@@ -143,6 +143,10 @@ PyMethodDef KX_NetworkMessageActuator::Methods[] = {
{NULL,NULL} // Sentinel
};
+PyAttributeDef KX_NetworkMessageActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* KX_NetworkMessageActuator::_getattr(const char *attr) {
_getattr_up(SCA_IActuator);
}
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
index cb9956d4616..ac89d8b0716 100644
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
+++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
@@ -213,6 +213,10 @@ PyMethodDef KX_NetworkMessageSensor::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_NetworkMessageSensor::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* KX_NetworkMessageSensor::_getattr(const char *attr) {
_getattr_up(SCA_ISensor); // implicit return!
}
diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
index 5fa19924267..b9bd7647f89 100644
--- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
+++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
@@ -748,6 +748,9 @@ PyMethodDef KX_BlenderMaterial::Methods[] =
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_BlenderMaterial::Attributes[] = {
+ { NULL } //Sentinel
+};
PyTypeObject KX_BlenderMaterial::Type = {
PyObject_HEAD_INIT(&PyType_Type)
diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
index 534c48661b7..062e9f7df50 100644
--- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
+++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
@@ -384,10 +384,10 @@ SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode)
childit!= destnode->GetSGChildren().end();
++childit
) {
- KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
- if (clientgameobj)
+ KX_GameObject *clientgameobj_child = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
+ if (clientgameobj_child)
{
- parentKxCtrl = (KX_BulletPhysicsController*)clientgameobj->GetPhysicsController();
+ parentKxCtrl = (KX_BulletPhysicsController*)clientgameobj_child->GetPhysicsController();
parentctrl = parentKxCtrl;
ccdParent = parentKxCtrl;
}
diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp
index 7d238e28add..ef7883910fd 100644
--- a/source/gameengine/Ketsji/KX_CDActuator.cpp
+++ b/source/gameengine/Ketsji/KX_CDActuator.cpp
@@ -197,7 +197,9 @@ PyMethodDef KX_CDActuator::Methods[] = {
{NULL,NULL,NULL,NULL} //Sentinel
};
-
+PyAttributeDef KX_CDActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
PyObject* KX_CDActuator::_getattr(const char *attr)
{
diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp
index 99e2d3b7c06..5caac2fc670 100644
--- a/source/gameengine/Ketsji/KX_Camera.cpp
+++ b/source/gameengine/Ketsji/KX_Camera.cpp
@@ -483,6 +483,10 @@ PyMethodDef KX_Camera::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_Camera::Attributes[] = {
+ { NULL } //Sentinel
+};
+
char KX_Camera::doc[] = "Module KX_Camera\n\n"
"Constants:\n"
"\tINSIDE\n"
diff --git a/source/gameengine/Ketsji/KX_ClientObjectInfo.h b/source/gameengine/Ketsji/KX_ClientObjectInfo.h
index 5e8af0f040c..7345edb054b 100644
--- a/source/gameengine/Ketsji/KX_ClientObjectInfo.h
+++ b/source/gameengine/Ketsji/KX_ClientObjectInfo.h
@@ -29,7 +29,10 @@
#ifndef __KX_CLIENTOBJECT_INFO_H
#define __KX_CLIENTOBJECT_INFO_H
+/* Note, the way this works with/without sumo is a bit odd */
+#ifdef USE_SUMO_SOLID
#include <SM_Object.h>
+#endif //USE_SUMO_SOLID
#include <list>
@@ -38,7 +41,10 @@ class KX_GameObject;
/**
* Client Type and Additional Info. This structure can be use instead of a bare void* pointer, for safeness, and additional info for callbacks
*/
-struct KX_ClientObjectInfo : public SM_ClientObject
+struct KX_ClientObjectInfo
+#ifdef USE_SUMO_SOLID
+ : public SM_ClientObject
+#endif
{
enum clienttype {
STATIC,
@@ -52,14 +58,18 @@ struct KX_ClientObjectInfo : public SM_ClientObject
std::list<SCA_ISensor*> m_sensors;
public:
KX_ClientObjectInfo(KX_GameObject *gameobject, clienttype type = STATIC, void *auxilary_info = NULL) :
+#ifdef USE_SUMO_SOLID
SM_ClientObject(),
+#endif
m_type(type),
m_gameobject(gameobject),
m_auxilary_info(auxilary_info)
{}
- KX_ClientObjectInfo(const KX_ClientObjectInfo &copy)
- : SM_ClientObject(copy),
+ KX_ClientObjectInfo(const KX_ClientObjectInfo &copy) :
+#ifdef USE_SUMO_SOLID
+ SM_ClientObject(copy),
+#endif
m_type(copy.m_type),
m_gameobject(copy.m_gameobject),
m_auxilary_info(copy.m_auxilary_info)
diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
index c0d802a9cf9..fba9544d702 100644
--- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
+++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
@@ -56,9 +56,9 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj,
int option,
char *property,
PyTypeObject* T) :
+ SCA_IActuator(gameobj, T),
m_refDirection(refDir),
- m_currentTime(0),
- SCA_IActuator(gameobj, T)
+ m_currentTime(0)
{
m_posDampTime = posDampTime;
m_rotDampTime = rotDampTime;
@@ -612,6 +612,10 @@ PyMethodDef KX_ConstraintActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_ConstraintActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* KX_ConstraintActuator::_getattr(const char *attr) {
_getattr_up(SCA_IActuator);
}
diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
index 9ceb4a05b06..f014c1896fe 100644
--- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
+++ b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
@@ -130,3 +130,7 @@ PyMethodDef KX_ConstraintWrapper::Methods[] = {
{"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_VARARGS},
{NULL,NULL} //Sentinel
};
+
+PyAttributeDef KX_ConstraintWrapper::Attributes[] = {
+ { NULL } //Sentinel
+};
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
index 53486cecf73..3534500e619 100644
--- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
+++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
@@ -32,7 +32,7 @@
/* These are defined by the build system... */
//but the build system is broken, because it doesn't allow for 2 or more defines at once.
//Please leave Sumo _AND_ Bullet enabled
-#define USE_SUMO_SOLID
+//#define USE_SUMO_SOLID // scons defines this
#define USE_BULLET
//#define USE_ODE
@@ -127,6 +127,14 @@ struct KX_ObjectProperties
/////////////////////////
+ bool m_lockXaxis;
+ bool m_lockYaxis;
+ bool m_lockZaxis;
+ bool m_lockXRotaxis;
+ bool m_lockYRotaxis;
+ bool m_lockZRotaxis;
+
+ /////////////////////////
double m_margin;
KX_BoundBoxClass m_boundclass;
union {
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
index 46e46b014b5..602486e0017 100644
--- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
+++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
@@ -1101,8 +1101,24 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
{
btRigidBody* rbody = physicscontroller->GetRigidBody();
- if (rbody && objprop->m_disableSleeping)
- rbody->setActivationState(DISABLE_DEACTIVATION);
+ if (rbody)
+ {
+ btVector3 linearFactor(
+ objprop->m_lockXaxis? 0 : 1,
+ objprop->m_lockYaxis? 0 : 1,
+ objprop->m_lockZaxis? 0 : 1);
+ btVector3 angularFactor(
+ objprop->m_lockXRotaxis? 0 : 1,
+ objprop->m_lockYRotaxis? 0 : 1,
+ objprop->m_lockZRotaxis? 0 : 1);
+ rbody->setLinearFactor(linearFactor);
+ rbody->setAngularFactor(angularFactor);
+
+ if (rbody && objprop->m_disableSleeping)
+ {
+ rbody->setActivationState(DISABLE_DEACTIVATION);
+ }
+ }
}
CcdPhysicsController* parentCtrl = objprop->m_dynamic_parent ? (KX_BulletPhysicsController*)objprop->m_dynamic_parent->GetPhysicsController() : 0;
diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp
index 2387dcdef3a..3c0695b5952 100644
--- a/source/gameengine/Ketsji/KX_GameActuator.cpp
+++ b/source/gameengine/Ketsji/KX_GameActuator.cpp
@@ -132,7 +132,7 @@ bool KX_GameActuator::Update()
{
char mashal_path[512];
char *marshal_buffer = NULL;
- int marshal_length;
+ unsigned int marshal_length;
FILE *fp = NULL;
pathGamePythonConfig(mashal_path);
@@ -246,6 +246,10 @@ PyMethodDef KX_GameActuator::Methods[] =
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_GameActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
+
/* getFile */
const char KX_GameActuator::GetFile_doc[] =
"getFile()\n"
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index 82b5fff534c..95df9d51a26 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -690,9 +690,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac)
switch (axis)
{
case 0: //x axis
- ori = MT_Vector3(orimat[0][2], orimat[1][2], orimat[2][2]); //pivot axis
+ ori.setValue(orimat[0][2], orimat[1][2], orimat[2][2]); //pivot axis
if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON) //is the vector paralell to the pivot?
- ori = MT_Vector3(orimat[0][1], orimat[1][1], orimat[2][1]); //change the pivot!
+ ori.setValue(orimat[0][1], orimat[1][1], orimat[2][1]); //change the pivot!
if (fac == 1.0) {
x = vect;
} else {
@@ -705,9 +705,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac)
z = x.cross(y);
break;
case 1: //y axis
- ori = MT_Vector3(orimat[0][0], orimat[1][0], orimat[2][0]);
+ ori.setValue(orimat[0][0], orimat[1][0], orimat[2][0]);
if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON)
- ori = MT_Vector3(orimat[0][2], orimat[1][2], orimat[2][2]);
+ ori.setValue(orimat[0][2], orimat[1][2], orimat[2][2]);
if (fac == 1.0) {
y = vect;
} else {
@@ -720,9 +720,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac)
x = y.cross(z);
break;
case 2: //z axis
- ori = MT_Vector3(orimat[0][1], orimat[1][1], orimat[2][1]);
+ ori.setValue(orimat[0][1], orimat[1][1], orimat[2][1]);
if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON)
- ori = MT_Vector3(orimat[0][0], orimat[1][0], orimat[2][0]);
+ ori.setValue(orimat[0][0], orimat[1][0], orimat[2][0]);
if (fac == 1.0) {
z = vect;
} else {
@@ -741,9 +741,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac)
x.normalize(); //normalize the vectors
y.normalize();
z.normalize();
- orimat = MT_Matrix3x3( x[0],y[0],z[0],
- x[1],y[1],z[1],
- x[2],y[2],z[2]);
+ orimat.setValue( x[0],y[0],z[0],
+ x[1],y[1],z[1],
+ x[2],y[2],z[2]);
if (GetSGNode()->GetSGParent() != NULL)
{
// the object is a child, adapt its local orientation so that
@@ -945,13 +945,11 @@ const MT_Vector3& KX_GameObject::NodeGetWorldScaling() const
const MT_Point3& KX_GameObject::NodeGetWorldPosition() const
{
- static MT_Point3 defaultPosition = MT_Point3(0.0, 0.0, 0.0);
-
// check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return defaultPosition;
-
- return GetSGNode()->GetWorldPosition();
+ if (GetSGNode())
+ return GetSGNode()->GetWorldPosition();
+ else
+ return MT_Point3(0.0, 0.0, 0.0);
}
/* Suspend/ resume: for the dynamic behaviour, there is a simple
@@ -1035,6 +1033,9 @@ PyMethodDef KX_GameObject::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_GameObject::Attributes[] = {
+ { NULL } //Sentinel
+};
/*
@@ -1172,7 +1173,7 @@ int KX_GameObject::_setattr(const char *attr, PyObject *value) // _setattr metho
{
if (!strcmp(attr, "parent")) {
- PyErr_SetString(PyExc_AttributeError, "attribute \"mass\" is read only\nUse setParent()");
+ PyErr_SetString(PyExc_AttributeError, "attribute \"parent\" is read only\nUse setParent()");
return 1;
}
@@ -1279,8 +1280,14 @@ int KX_GameObject::_setattr(const char *attr, PyObject *value) // _setattr metho
{
if (!strcmp(attr, "name"))
{
+#if 0 // was added in revision 2832, but never took into account Object name mappings from revision 2
+ // unlikely anyone ever used this successfully , removing.
m_name = PyString_AsString(value);
return 0;
+#else
+ PyErr_SetString(PyExc_AttributeError, "object name readonly");
+ return 1;
+#endif
}
}
@@ -1456,11 +1463,9 @@ PyObject* KX_GameObject::PySetState(PyObject* self, PyObject* value)
PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args)
{
// only can get the velocity if we have a physics object connected to us...
- MT_Vector3 velocity(0.0,0.0,0.0);
MT_Point3 point(0.0,0.0,0.0);
-
-
PyObject* pypos = NULL;
+
if (PyArg_ParseTuple(args, "|O:getVelocity", &pypos))
{
if (pypos)
@@ -1472,10 +1477,11 @@ PyObject* KX_GameObject::PyGetVelocity(PyObject* self, PyObject* args)
if (m_pPhysicsController1)
{
- velocity = m_pPhysicsController1->GetVelocity(point);
+ return PyObjectFrom(m_pPhysicsController1->GetVelocity(point));
+ }
+ else {
+ return PyObjectFrom(MT_Vector3(0.0,0.0,0.0));
}
-
- return PyObjectFrom(velocity);
}
@@ -2039,8 +2045,8 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
if (callback.m_hitMesh)
{
// if this field is set, then we can trust that m_hitPolygon is a valid polygon
- RAS_Polygon* poly = callback.m_hitMesh->GetPolygon(callback.m_hitPolygon);
- KX_PolyProxy* polyproxy = new KX_PolyProxy(callback.m_hitMesh, poly);
+ RAS_Polygon* polygon = callback.m_hitMesh->GetPolygon(callback.m_hitPolygon);
+ KX_PolyProxy* polyproxy = new KX_PolyProxy(callback.m_hitMesh, polygon);
PyTuple_SET_ITEM(returnValue, 3, polyproxy);
}
else
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h
index d95e3751d33..211c9b7ca7d 100644
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ b/source/gameengine/Ketsji/KX_GameObject.h
@@ -758,7 +758,8 @@ public:
virtual PyObject* _getattr(const char *attr);
virtual int _setattr(const char *attr, PyObject *value); // _setattr method
-
+ virtual PyObject* _repr(void) { return PyString_FromString(GetName().ReadPtr()); }
+
KX_PYMETHOD_NOARGS(KX_GameObject,GetPosition);
KX_PYMETHOD_O(KX_GameObject,SetPosition);
KX_PYMETHOD_O(KX_GameObject,SetWorldPosition);
diff --git a/source/gameengine/Ketsji/KX_IPO_SGController.cpp b/source/gameengine/Ketsji/KX_IPO_SGController.cpp
index 67d54cf0b0b..55a7e2ade60 100644
--- a/source/gameengine/Ketsji/KX_IPO_SGController.cpp
+++ b/source/gameengine/Ketsji/KX_IPO_SGController.cpp
@@ -58,8 +58,8 @@ KX_IpoSGController::KX_IpoSGController()
m_ipo_add(false),
m_ipo_local(false),
m_modified(true),
- m_ipo_start_initialized(false),
m_ipotime(1.0),
+ m_ipo_start_initialized(false),
m_ipo_start_euler(0.0,0.0,0.0),
m_ipo_euler_initialized(false)
{
diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp
index ca8419666b5..623a939bf62 100644
--- a/source/gameengine/Ketsji/KX_IpoActuator.cpp
+++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp
@@ -457,6 +457,10 @@ PyMethodDef KX_IpoActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_IpoActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* KX_IpoActuator::_getattr(const char *attr) {
_getattr_up(SCA_IActuator);
}
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
index 1271474802c..97b4213b8bd 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
@@ -59,7 +59,10 @@
#include "KX_PythonInit.h"
#include "KX_PyConstraintBinding.h"
#include "PHY_IPhysicsEnvironment.h"
+
+#ifdef USE_SUMO_SOLID
#include "SumoPhysicsEnvironment.h"
+#endif
#include "SND_Scene.h"
#include "SND_IAudioDevice.h"
@@ -713,7 +716,7 @@ void KX_KetsjiEngine::Render()
if (!BeginFrame())
return;
- KX_SceneList::iterator sceneit;
+
for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++)
// for each scene, call the proceed functions
{
@@ -1109,6 +1112,11 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam)
scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools);
+ if (scene->GetPhysicsEnvironment())
+ scene->GetPhysicsEnvironment()->debugDrawWorld();
+
+ m_rasterizer->FlushDebugLines();
+
PostRenderFrame();
}
diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp
index 36700265260..a2e93ecdd36 100644
--- a/source/gameengine/Ketsji/KX_Light.cpp
+++ b/source/gameengine/Ketsji/KX_Light.cpp
@@ -301,6 +301,10 @@ PyMethodDef KX_LightObject::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_LightObject::Attributes[] = {
+ { NULL } //Sentinel
+};
+
char KX_LightObject::doc[] = "Module KX_LightObject\n\n"
"Constants:\n"
"\tSPOT\n"
diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp
index 4b949903c88..a0c0a496c06 100644
--- a/source/gameengine/Ketsji/KX_MeshProxy.cpp
+++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp
@@ -86,6 +86,10 @@ KX_PYMETHODTABLE(KX_MeshProxy, reinstancePhysicsMesh),
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_MeshProxy::Attributes[] = {
+ { NULL } //Sentinel
+};
+
void KX_MeshProxy::SetMeshModified(bool v)
{
m_meshobj->SetMeshModified(v);
diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
index bd15d3cffbe..384034485e7 100644
--- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
+++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
@@ -42,6 +42,7 @@
#include "KX_Scene.h"
#include "KX_Camera.h"
#include "KX_MouseFocusSensor.h"
+#include "KX_PyMath.h"
#include "KX_RayCast.h"
#include "KX_IPhysicsController.h"
@@ -320,17 +321,21 @@ PyParentObject KX_MouseFocusSensor::Parents[] = {
};
PyMethodDef KX_MouseFocusSensor::Methods[] = {
- {"getRayTarget", (PyCFunction) KX_MouseFocusSensor::sPyGetRayTarget, METH_VARARGS, (PY_METHODCHAR)GetRayTarget_doc},
- {"getRaySource", (PyCFunction) KX_MouseFocusSensor::sPyGetRaySource, METH_VARARGS, (PY_METHODCHAR)GetRaySource_doc},
- {"getHitObject",(PyCFunction) KX_MouseFocusSensor::sPyGetHitObject,METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc},
- {"getHitPosition",(PyCFunction) KX_MouseFocusSensor::sPyGetHitPosition,METH_VARARGS, (PY_METHODCHAR)GetHitPosition_doc},
- {"getHitNormal",(PyCFunction) KX_MouseFocusSensor::sPyGetHitNormal,METH_VARARGS, (PY_METHODCHAR)GetHitNormal_doc},
- {"getRayDirection",(PyCFunction) KX_MouseFocusSensor::sPyGetRayDirection,METH_VARARGS, (PY_METHODCHAR)GetRayDirection_doc},
+ {"getRayTarget", (PyCFunction) KX_MouseFocusSensor::sPyGetRayTarget, METH_NOARGS, (PY_METHODCHAR)GetRayTarget_doc},
+ {"getRaySource", (PyCFunction) KX_MouseFocusSensor::sPyGetRaySource, METH_NOARGS, (PY_METHODCHAR)GetRaySource_doc},
+ {"getHitObject",(PyCFunction) KX_MouseFocusSensor::sPyGetHitObject,METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc},
+ {"getHitPosition",(PyCFunction) KX_MouseFocusSensor::sPyGetHitPosition,METH_NOARGS, (PY_METHODCHAR)GetHitPosition_doc},
+ {"getHitNormal",(PyCFunction) KX_MouseFocusSensor::sPyGetHitNormal,METH_NOARGS, (PY_METHODCHAR)GetHitNormal_doc},
+ {"getRayDirection",(PyCFunction) KX_MouseFocusSensor::sPyGetRayDirection,METH_NOARGS, (PY_METHODCHAR)GetRayDirection_doc},
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_MouseFocusSensor::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* KX_MouseFocusSensor::_getattr(const char *attr) {
_getattr_up(SCA_MouseSensor);
}
@@ -339,14 +344,11 @@ PyObject* KX_MouseFocusSensor::_getattr(const char *attr) {
const char KX_MouseFocusSensor::GetHitObject_doc[] =
"getHitObject()\n"
"\tReturns the name of the object that was hit by this ray.\n";
-PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self)
{
if (m_hitObject)
- {
return m_hitObject->AddRef();
- }
+
Py_RETURN_NONE;
}
@@ -354,61 +356,28 @@ PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self,
const char KX_MouseFocusSensor::GetHitPosition_doc[] =
"getHitPosition()\n"
"\tReturns the position (in worldcoordinates) where the object was hit by this ray.\n";
-PyObject* KX_MouseFocusSensor::PyGetHitPosition(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* KX_MouseFocusSensor::PyGetHitPosition(PyObject* self)
{
-
- MT_Point3 pos = m_hitPosition;
-
- PyObject* resultlist = PyList_New(3);
- int index;
- for (index=0;index<3;index++)
- {
- PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index]));
- }
- return resultlist;
-
+ return PyObjectFrom(m_hitPosition);
}
const char KX_MouseFocusSensor::GetRayDirection_doc[] =
"getRayDirection()\n"
"\tReturns the direction from the ray (in worldcoordinates) .\n";
-PyObject* KX_MouseFocusSensor::PyGetRayDirection(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* KX_MouseFocusSensor::PyGetRayDirection(PyObject* self)
{
MT_Vector3 dir = m_prevTargetPoint - m_prevSourcePoint;
dir.normalize();
-
- PyObject* resultlist = PyList_New(3);
- int index;
- for (index=0;index<3;index++)
- {
- PyList_SetItem(resultlist,index,PyFloat_FromDouble(dir[index]));
- }
- return resultlist;
-
+ return PyObjectFrom(dir);
}
const char KX_MouseFocusSensor::GetHitNormal_doc[] =
"getHitNormal()\n"
"\tReturns the normal (in worldcoordinates) of the object at the location where the object was hit by this ray.\n";
-PyObject* KX_MouseFocusSensor::PyGetHitNormal(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* KX_MouseFocusSensor::PyGetHitNormal(PyObject* self)
{
- MT_Vector3 pos = m_hitNormal;
-
- PyObject* resultlist = PyList_New(3);
- int index;
- for (index=0;index<3;index++)
- {
- PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index]));
- }
- return resultlist;
-
+ return PyObjectFrom(m_hitNormal);
}
@@ -417,16 +386,8 @@ const char KX_MouseFocusSensor::GetRayTarget_doc[] =
"getRayTarget()\n"
"\tReturns the target of the ray that seeks the focus object,\n"
"\tin worldcoordinates.";
-PyObject* KX_MouseFocusSensor::PyGetRayTarget(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
- PyObject *retVal = PyList_New(3);
-
- PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_prevTargetPoint[0]));
- PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_prevTargetPoint[1]));
- PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_prevTargetPoint[2]));
-
- return retVal;
+PyObject* KX_MouseFocusSensor::PyGetRayTarget(PyObject* self) {
+ return PyObjectFrom(m_prevTargetPoint);
}
/* getRayTarget */
@@ -434,16 +395,8 @@ const char KX_MouseFocusSensor::GetRaySource_doc[] =
"getRaySource()\n"
"\tReturns the source of the ray that seeks the focus object,\n"
"\tin worldcoordinates.";
-PyObject* KX_MouseFocusSensor::PyGetRaySource(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
- PyObject *retVal = PyList_New(3);
-
- PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_prevSourcePoint[0]));
- PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_prevSourcePoint[1]));
- PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_prevSourcePoint[2]));
-
- return retVal;
+PyObject* KX_MouseFocusSensor::PyGetRaySource(PyObject* self) {
+ return PyObjectFrom(m_prevSourcePoint);
}
/* eof */
diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.h b/source/gameengine/Ketsji/KX_MouseFocusSensor.h
index 704198ce5a3..4979783032c 100644
--- a/source/gameengine/Ketsji/KX_MouseFocusSensor.h
+++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.h
@@ -89,13 +89,13 @@ class KX_MouseFocusSensor : public SCA_MouseSensor
/* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr);
- KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetRayTarget);
- KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetRaySource);
+ KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRayTarget);
+ KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRaySource);
- KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetHitObject);
- KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetHitPosition);
- KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetHitNormal);
- KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetRayDirection);
+ KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetHitObject);
+ KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetHitPosition);
+ KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetHitNormal);
+ KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRayDirection);
/* --------------------------------------------------------------------- */
SCA_IObject* m_hitObject;
diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp
index 7ef544618f8..993a6b3d86c 100644
--- a/source/gameengine/Ketsji/KX_NearSensor.cpp
+++ b/source/gameengine/Ketsji/KX_NearSensor.cpp
@@ -37,14 +37,13 @@
#include "PHY_IPhysicsEnvironment.h"
#include "PHY_IPhysicsController.h"
-
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr,
KX_GameObject* gameobj,
- double margin,
- double resetmargin,
+ float margin,
+ float resetmargin,
bool bFindMaterial,
const STR_String& touchedpropname,
class KX_Scene* scene,
@@ -53,6 +52,7 @@ KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr,
:KX_TouchSensor(eventmgr,
gameobj,
bFindMaterial,
+ false,
touchedpropname,
/* scene, */
T),
@@ -240,7 +240,7 @@ bool KX_NearSensor::BroadPhaseFilterCollision(void*obj1,void*obj2)
bool KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData * coll_data)
{
// KX_TouchEventManager* toucheventmgr = static_cast<KX_TouchEventManager*>(m_eventmgr);
- KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
+// KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
// need the mapping from PHY_IPhysicsController to gameobjects now
@@ -272,12 +272,20 @@ bool KX_NearSensor::NewHandleCollision(void* obj1,void* obj2,const PHY_CollData
//}
}
- return DT_CONTINUE;
+ return false; // was DT_CONTINUE; but this was defined in Sumo as false
}
+/* ------------------------------------------------------------------------- */
+/* Python Functions */
+/* ------------------------------------------------------------------------- */
+
+//No methods
+
+/* ------------------------------------------------------------------------- */
+/* Python Integration Hooks */
+/* ------------------------------------------------------------------------- */
-// python embedding
PyTypeObject KX_NearSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
@@ -311,17 +319,31 @@ PyParentObject KX_NearSensor::Parents[] = {
PyMethodDef KX_NearSensor::Methods[] = {
- {"setProperty", (PyCFunction) KX_NearSensor::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc},
- {"getProperty", (PyCFunction) KX_NearSensor::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc},
- {"getHitObject",(PyCFunction) KX_NearSensor::sPyGetHitObject, METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc},
- {"getHitObjectList", (PyCFunction) KX_NearSensor::sPyGetHitObjectList, METH_VARARGS, (PY_METHODCHAR)GetHitObjectList_doc},
+ //No methods
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_NearSensor::Attributes[] = {
+ KX_PYATTRIBUTE_FLOAT_RW_CHECK("distance", 0, 100, KX_NearSensor, m_Margin, CheckResetDistance),
+ KX_PYATTRIBUTE_FLOAT_RW_CHECK("resetDistance", 0, 100, KX_NearSensor, m_ResetMargin, CheckResetDistance),
+ {NULL} //Sentinel
+};
-PyObject*
-KX_NearSensor::_getattr(const char *attr)
+
+PyObject* KX_NearSensor::_getattr(const char *attr)
{
- _getattr_up(KX_TouchSensor);
+ PyObject* object = _getattr_self(Attributes, this, attr);
+ if (object != NULL)
+ return object;
+
+ _getattr_up(KX_TouchSensor);
}
+int KX_NearSensor::_setattr(const char *attr, PyObject* value)
+{
+ int ret = _setattr_self(Attributes, this, attr, value);
+ if (ret >= 0)
+ return ret;
+
+ return KX_TouchSensor::_setattr(attr, value);
+}
diff --git a/source/gameengine/Ketsji/KX_NearSensor.h b/source/gameengine/Ketsji/KX_NearSensor.h
index 58c7cc7da91..ee03992e734 100644
--- a/source/gameengine/Ketsji/KX_NearSensor.h
+++ b/source/gameengine/Ketsji/KX_NearSensor.h
@@ -42,15 +42,15 @@ class KX_NearSensor : public KX_TouchSensor
{
Py_Header;
protected:
- double m_Margin;
- double m_ResetMargin;
+ float m_Margin;
+ float m_ResetMargin;
KX_Scene* m_scene;
KX_ClientObjectInfo* m_client_info;
public:
KX_NearSensor(class SCA_EventManager* eventmgr,
class KX_GameObject* gameobj,
- double margin,
- double resetmargin,
+ float margin,
+ float resetmargin,
bool bFindMaterial,
const STR_String& touchedpropname,
class KX_Scene* scene,
@@ -78,8 +78,25 @@ public:
virtual bool BroadPhaseFilterCollision(void*obj1,void*obj2);
virtual void RegisterSumo(KX_TouchEventManager *touchman);
virtual void UnregisterSumo(KX_TouchEventManager* touchman);
-
+
+ /* --------------------------------------------------------------------- */
+ /* Python interface ---------------------------------------------------- */
+ /* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr);
+ virtual int _setattr(const char *attr, PyObject* value);
+
+ //No methods
+
+ //This method is used to make sure the distance does not exceed the reset distance
+ static int CheckResetDistance(void *self, const PyAttributeDef*)
+ {
+ KX_NearSensor* sensor = reinterpret_cast<KX_NearSensor*>(self);
+
+ if (sensor->m_Margin > sensor->m_ResetMargin)
+ sensor->m_ResetMargin = sensor->m_Margin;
+
+ return 0;
+ }
};
diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp
index 9a620998538..0666261b470 100644
--- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp
+++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp
@@ -65,12 +65,12 @@ KX_ObjectActuator(
m_current_linear_factor(0.0),
m_current_angular_factor(0.0),
m_damping(damping),
+ m_previous_error(0.0,0.0,0.0),
+ m_error_accumulator(0.0,0.0,0.0),
m_bitLocalFlag (flag),
m_active_combined_velocity (false),
m_linear_damping_active(false),
- m_angular_damping_active(false),
- m_error_accumulator(0.0,0.0,0.0),
- m_previous_error(0.0,0.0,0.0)
+ m_angular_damping_active(false)
{
if (m_bitLocalFlag.ServoControl)
{
@@ -332,6 +332,10 @@ PyMethodDef KX_ObjectActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_ObjectActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* KX_ObjectActuator::_getattr(const char *attr) {
_getattr_up(SCA_IActuator);
};
diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp
index 5a908186235..84d7ccb9c05 100644
--- a/source/gameengine/Ketsji/KX_ParentActuator.cpp
+++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp
@@ -172,6 +172,10 @@ PyMethodDef KX_ParentActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_ParentActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* KX_ParentActuator::_getattr(const char *attr) {
if (!strcmp(attr, "object")) {
diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp
index 1c9e2a49c11..b4bdd77fb66 100644
--- a/source/gameengine/Ketsji/KX_PolyProxy.cpp
+++ b/source/gameengine/Ketsji/KX_PolyProxy.cpp
@@ -77,6 +77,10 @@ PyMethodDef KX_PolyProxy::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_PolyProxy::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* KX_PolyProxy::_getattr(const char *attr)
{
if (!strcmp(attr, "matname"))
@@ -146,8 +150,8 @@ PyObject* KX_PolyProxy::_getattr(const char *attr)
}
KX_PolyProxy::KX_PolyProxy(const RAS_MeshObject*mesh, RAS_Polygon* polygon)
-: m_mesh((RAS_MeshObject*)mesh),
- m_polygon(polygon)
+: m_polygon(polygon),
+ m_mesh((RAS_MeshObject*)mesh)
{
}
diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
index 52c5b013e65..bbaf697b168 100644
--- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
+++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
@@ -180,6 +180,9 @@ PyMethodDef KX_PolygonMaterial::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_PolygonMaterial::Attributes[] = {
+ { NULL } //Sentinel
+};
PyTypeObject KX_PolygonMaterial::Type = {
PyObject_HEAD_INIT(&PyType_Type)
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index c3ae3d0ec52..d974d67bf33 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -47,6 +47,7 @@
#include "KX_PyConstraintBinding.h"
#include "KX_KetsjiEngine.h"
+#include "KX_RadarSensor.h"
#include "SCA_IInputDevice.h"
#include "SCA_PropertySensor.h"
@@ -196,7 +197,7 @@ static PyObject* gPyGetSpectrum(PyObject*)
}
-
+#if 0 // unused
static PyObject* gPyStartDSP(PyObject*, PyObject* args)
{
SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance();
@@ -213,7 +214,7 @@ static PyObject* gPyStartDSP(PyObject*, PyObject* args)
Py_RETURN_NONE;
}
-
+#endif
static PyObject* gPyStopDSP(PyObject*, PyObject* args)
@@ -257,7 +258,7 @@ static PyObject* gPySetPhysicsTicRate(PyObject*, PyObject* args)
PHY_GetActiveEnvironment()->setFixedTimeStep(true,ticrate);
Py_RETURN_NONE;
}
-
+#if 0 // unused
static PyObject* gPySetPhysicsDebug(PyObject*, PyObject* args)
{
int debugMode;
@@ -267,7 +268,7 @@ static PyObject* gPySetPhysicsDebug(PyObject*, PyObject* args)
PHY_GetActiveEnvironment()->setDebugMode(debugMode);
Py_RETURN_NONE;
}
-
+#endif
static PyObject* gPyGetPhysicsTicRate(PyObject*)
@@ -329,6 +330,32 @@ static PyObject* gPyGetCurrentScene(PyObject* self)
return (PyObject*) gp_KetsjiScene;
}
+static STR_String gPyGetSceneList_doc =
+"getSceneList()\n"
+"Return a list of converted scenes.\n";
+static PyObject* gPyGetSceneList(PyObject* self)
+{
+ KX_KetsjiEngine* m_engine = KX_GetActiveEngine();
+ //CListValue* list = new CListValue();
+ PyObject* list;
+ KX_SceneList* scenes = m_engine->CurrentScenes();
+ int numScenes = scenes->size();
+ int i;
+
+ list = PyList_New(numScenes);
+
+ for (i=0;i<numScenes;i++)
+ {
+ KX_Scene* scene = scenes->at(i);
+ //list->Add(scene);
+ PyList_SET_ITEM(list, i, scene);
+ Py_INCREF(scene);
+
+ }
+
+ return (PyObject*)list;
+}
+
static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
{
#define pprint(x) std::cout << x << std::endl;
@@ -408,6 +435,8 @@ static struct PyMethodDef game_methods[] = {
METH_NOARGS, (PY_METHODCHAR)SCA_PythonController::sPyGetCurrentController__doc__},
{"getCurrentScene", (PyCFunction) gPyGetCurrentScene,
METH_NOARGS, (PY_METHODCHAR)gPyGetCurrentScene_doc.Ptr()},
+ {"getSceneList", (PyCFunction) gPyGetSceneList,
+ METH_NOARGS, (PY_METHODCHAR)gPyGetSceneList_doc.Ptr()},
{"addActiveActuator",(PyCFunction) SCA_PythonController::sPyAddActiveActuator,
METH_VARARGS, (PY_METHODCHAR)SCA_PythonController::sPyAddActiveActuator__doc__},
{"getRandomFloat",(PyCFunction) gPyGetRandomFloat,
@@ -1032,6 +1061,14 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack
KX_MACRO_addTypesToDict(d, KX_STATE29, (1<<28));
KX_MACRO_addTypesToDict(d, KX_STATE30, (1<<29));
+ /* Radar Sensor */
+ KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_X, KX_RadarSensor::KX_RADAR_AXIS_POS_X);
+ KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_Y, KX_RadarSensor::KX_RADAR_AXIS_POS_Y);
+ KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_Z, KX_RadarSensor::KX_RADAR_AXIS_POS_Z);
+ KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_X, KX_RadarSensor::KX_RADAR_AXIS_NEG_Y);
+ KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_Y, KX_RadarSensor::KX_RADAR_AXIS_NEG_X);
+ KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_Z, KX_RadarSensor::KX_RADAR_AXIS_NEG_Z);
+
// Check for errors
if (PyErr_Occurred())
{
diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp
index 1321b862463..fa8998cd81d 100644
--- a/source/gameengine/Ketsji/KX_RadarSensor.cpp
+++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp
@@ -28,6 +28,7 @@
#include "KX_RadarSensor.h"
#include "KX_GameObject.h"
+#include "KX_PyMath.h"
#include "PHY_IPhysicsController.h"
#ifdef HAVE_CONFIG_H
@@ -170,8 +171,18 @@ void KX_RadarSensor::SynchronizeTransform()
{
}
}
- m_cone_origin = trans.getOrigin();
- m_cone_target = trans(MT_Point3(0, -m_coneheight/2.0 ,0));
+
+ //Using a temp variable to translate MT_Point3 to float[3].
+ //float[3] works better for the Python interface.
+ MT_Point3 temp = trans.getOrigin();
+ m_cone_origin[0] = temp[0];
+ m_cone_origin[1] = temp[1];
+ m_cone_origin[2] = temp[2];
+
+ temp = trans(MT_Point3(0, -m_coneheight/2.0 ,0));
+ m_cone_target[0] = temp[0];
+ m_cone_target[1] = temp[1];
+ m_cone_target[2] = temp[2];
if (m_physCtrl)
@@ -186,10 +197,58 @@ void KX_RadarSensor::SynchronizeTransform()
}
/* ------------------------------------------------------------------------- */
-/* Python functions */
+/* Python Functions */
/* ------------------------------------------------------------------------- */
-/* Integration hooks ------------------------------------------------------- */
+//Deprecated ----->
+/* getConeOrigin */
+const char KX_RadarSensor::GetConeOrigin_doc[] =
+"getConeOrigin()\n"
+"\tReturns the origin of the cone with which to test. The origin\n"
+"\tis in the middle of the cone.";
+PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self) {
+ ShowDeprecationWarning("getConeOrigin()", "the coneOrigin property");
+
+ PyObject *retVal = PyList_New(3);
+
+ PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_origin[0]));
+ PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_origin[1]));
+ PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_origin[2]));
+
+ return retVal;
+}
+
+/* getConeOrigin */
+const char KX_RadarSensor::GetConeTarget_doc[] =
+"getConeTarget()\n"
+"\tReturns the center of the bottom face of the cone with which to test.\n";
+PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self) {
+ ShowDeprecationWarning("getConeTarget()", "the coneTarget property");
+
+ PyObject *retVal = PyList_New(3);
+
+ PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_target[0]));
+ PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_target[1]));
+ PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_target[2]));
+
+ return retVal;
+}
+
+/* getConeHeight */
+const char KX_RadarSensor::GetConeHeight_doc[] =
+"getConeHeight()\n"
+"\tReturns the height of the cone with which to test.\n";
+PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self) {
+
+ ShowDeprecationWarning("getConeHeight()", "the distance property");
+
+ return PyFloat_FromDouble(m_coneheight);
+}
+//<----- Deprecated
+
+/* ------------------------------------------------------------------------- */
+/* Python Integration Hooks */
+/* ------------------------------------------------------------------------- */
PyTypeObject KX_RadarSensor::Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
@@ -220,60 +279,39 @@ PyParentObject KX_RadarSensor::Parents[] = {
};
PyMethodDef KX_RadarSensor::Methods[] = {
+ //Deprecated ----->
{"getConeOrigin", (PyCFunction) KX_RadarSensor::sPyGetConeOrigin,
METH_VARARGS, (PY_METHODCHAR)GetConeOrigin_doc},
{"getConeTarget", (PyCFunction) KX_RadarSensor::sPyGetConeTarget,
METH_VARARGS, (PY_METHODCHAR)GetConeTarget_doc},
{"getConeHeight", (PyCFunction) KX_RadarSensor::sPyGetConeHeight,
METH_VARARGS, (PY_METHODCHAR)GetConeHeight_doc},
- {NULL,NULL,NULL,NULL} //Sentinel
+ //<-----
+ {NULL} //Sentinel
};
-PyObject* KX_RadarSensor::_getattr(const char *attr) {
- _getattr_up(KX_TouchSensor);
-}
-
-/* getConeOrigin */
-const char KX_RadarSensor::GetConeOrigin_doc[] =
-"getConeOrigin()\n"
-"\tReturns the origin of the cone with which to test. The origin\n"
-"\tis in the middle of the cone.";
-PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
- PyObject *retVal = PyList_New(3);
-
- PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_origin[0]));
- PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_origin[1]));
- PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_origin[2]));
-
- return retVal;
-}
+PyAttributeDef KX_RadarSensor::Attributes[] = {
+ KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneOrigin", KX_RadarSensor, m_cone_origin, 3),
+ KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneTarget", KX_RadarSensor, m_cone_target, 3),
+ KX_PYATTRIBUTE_FLOAT_RW("angle", 0, 360, KX_RadarSensor, m_coneradius),
+ KX_PYATTRIBUTE_INT_RW("axis", 0, 5, true, KX_RadarSensor, m_axis),
+ {NULL} //Sentinel
+};
-/* getConeOrigin */
-const char KX_RadarSensor::GetConeTarget_doc[] =
-"getConeTarget()\n"
-"\tReturns the center of the bottom face of the cone with which to test.\n";
-PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
- PyObject *retVal = PyList_New(3);
-
- PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_target[0]));
- PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_target[1]));
- PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_target[2]));
-
- return retVal;
-}
+PyObject* KX_RadarSensor::_getattr(const char *attr)
+{
+ PyObject* object = _getattr_self(Attributes, this, attr);
+ if (object != NULL)
+ return object;
-/* getConeOrigin */
-const char KX_RadarSensor::GetConeHeight_doc[] =
-"getConeHeight()\n"
-"\tReturns the height of the cone with which to test.\n";
-PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
- return PyFloat_FromDouble(m_coneheight);
+ _getattr_up(KX_NearSensor);
}
+int KX_RadarSensor::_setattr(const char *attr, PyObject* value)
+{
+ int ret = _setattr_self(Attributes, this, attr, value);
+ if (ret >= 0)
+ return ret;
+ return KX_NearSensor::_setattr(attr, value);
+}
diff --git a/source/gameengine/Ketsji/KX_RadarSensor.h b/source/gameengine/Ketsji/KX_RadarSensor.h
index f8f80725145..6dfe0c42f5d 100644
--- a/source/gameengine/Ketsji/KX_RadarSensor.h
+++ b/source/gameengine/Ketsji/KX_RadarSensor.h
@@ -40,23 +40,23 @@ class KX_RadarSensor : public KX_NearSensor
protected:
Py_Header;
- MT_Scalar m_coneradius;
+ float m_coneradius;
/**
* Height of the cone.
*/
- MT_Scalar m_coneheight;
+ float m_coneheight;
int m_axis;
/**
* The previous position of the origin of the cone.
*/
- MT_Point3 m_cone_origin;
+ float m_cone_origin[3];
/**
* The previous direction of the cone (origin to bottom plane).
*/
- MT_Point3 m_cone_target;
+ float m_cone_target[3];
public:
@@ -80,13 +80,23 @@ public:
/* --------------------------------------------------------------------- */
/* Python interface ---------------------------------------------------- */
/* --------------------------------------------------------------------- */
-
- virtual PyObject* _getattr(const char *attr);
+ enum RadarAxis {
+ KX_RADAR_AXIS_POS_X = 0,
+ KX_RADAR_AXIS_POS_Y,
+ KX_RADAR_AXIS_POS_Z,
+ KX_RADAR_AXIS_NEG_X,
+ KX_RADAR_AXIS_NEG_Y,
+ KX_RADAR_AXIS_NEG_Z
+ };
- KX_PYMETHOD_DOC(KX_RadarSensor,GetConeOrigin);
- KX_PYMETHOD_DOC(KX_RadarSensor,GetConeTarget);
- KX_PYMETHOD_DOC(KX_RadarSensor,GetConeHeight);
+ virtual PyObject* _getattr(const char *attr);
+ virtual int _setattr(const char *attr, PyObject* value);
+ //Deprecated ----->
+ KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeOrigin);
+ KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeTarget);
+ KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeHeight);
+ //<-----
};
#endif //__KX_RADAR_SENSOR_H
diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp
index b8ebce28814..ce12b983147 100644
--- a/source/gameengine/Ketsji/KX_RaySensor.cpp
+++ b/source/gameengine/Ketsji/KX_RaySensor.cpp
@@ -38,6 +38,7 @@
#include "KX_GameObject.h"
#include "KX_Scene.h"
#include "KX_RayCast.h"
+#include "KX_PyMath.h"
#include "PHY_IPhysicsEnvironment.h"
#include "KX_IPhysicsController.h"
#include "PHY_IPhysicsController.h"
@@ -179,8 +180,8 @@ bool KX_RaySensor::Evaluate(CValue* event)
bool reset = m_reset && m_level;
m_rayHit = false;
m_hitObject = NULL;
- m_hitPosition = MT_Vector3(0,0,0);
- m_hitNormal = MT_Vector3(1,0,0);
+ m_hitPosition.setValue(0,0,0);
+ m_hitNormal.setValue(1,0,0);
KX_GameObject* obj = (KX_GameObject*)GetParent();
MT_Point3 frompoint = obj->NodeGetWorldPosition();
@@ -335,19 +336,21 @@ PyParentObject KX_RaySensor::Parents[] = {
};
PyMethodDef KX_RaySensor::Methods[] = {
- {"getHitObject",(PyCFunction) KX_RaySensor::sPyGetHitObject,METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc},
- {"getHitPosition",(PyCFunction) KX_RaySensor::sPyGetHitPosition,METH_VARARGS, (PY_METHODCHAR)GetHitPosition_doc},
- {"getHitNormal",(PyCFunction) KX_RaySensor::sPyGetHitNormal,METH_VARARGS, (PY_METHODCHAR)GetHitNormal_doc},
- {"getRayDirection",(PyCFunction) KX_RaySensor::sPyGetRayDirection,METH_VARARGS, (PY_METHODCHAR)GetRayDirection_doc},
+ {"getHitObject",(PyCFunction) KX_RaySensor::sPyGetHitObject,METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc},
+ {"getHitPosition",(PyCFunction) KX_RaySensor::sPyGetHitPosition,METH_NOARGS, (PY_METHODCHAR)GetHitPosition_doc},
+ {"getHitNormal",(PyCFunction) KX_RaySensor::sPyGetHitNormal,METH_NOARGS, (PY_METHODCHAR)GetHitNormal_doc},
+ {"getRayDirection",(PyCFunction) KX_RaySensor::sPyGetRayDirection,METH_NOARGS, (PY_METHODCHAR)GetRayDirection_doc},
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_RaySensor::Attributes[] = {
+ { NULL } //Sentinel
+};
+
const char KX_RaySensor::GetHitObject_doc[] =
"getHitObject()\n"
"\tReturns the name of the object that was hit by this ray.\n";
-PyObject* KX_RaySensor::PyGetHitObject(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* KX_RaySensor::PyGetHitObject(PyObject* self)
{
if (m_hitObject)
{
@@ -360,60 +363,25 @@ PyObject* KX_RaySensor::PyGetHitObject(PyObject* self,
const char KX_RaySensor::GetHitPosition_doc[] =
"getHitPosition()\n"
"\tReturns the position (in worldcoordinates) where the object was hit by this ray.\n";
-PyObject* KX_RaySensor::PyGetHitPosition(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* KX_RaySensor::PyGetHitPosition(PyObject* self)
{
-
- MT_Point3 pos = m_hitPosition;
-
- PyObject* resultlist = PyList_New(3);
- int index;
- for (index=0;index<3;index++)
- {
- PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index]));
- }
- return resultlist;
-
+ return PyObjectFrom(m_hitPosition);
}
const char KX_RaySensor::GetRayDirection_doc[] =
"getRayDirection()\n"
"\tReturns the direction from the ray (in worldcoordinates) .\n";
-PyObject* KX_RaySensor::PyGetRayDirection(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* KX_RaySensor::PyGetRayDirection(PyObject* self)
{
-
- MT_Vector3 dir = m_rayDirection;
-
- PyObject* resultlist = PyList_New(3);
- int index;
- for (index=0;index<3;index++)
- {
- PyList_SetItem(resultlist,index,PyFloat_FromDouble(dir[index]));
- }
- return resultlist;
-
+ return PyObjectFrom(m_rayDirection);
}
const char KX_RaySensor::GetHitNormal_doc[] =
"getHitNormal()\n"
"\tReturns the normal (in worldcoordinates) of the object at the location where the object was hit by this ray.\n";
-PyObject* KX_RaySensor::PyGetHitNormal(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* KX_RaySensor::PyGetHitNormal(PyObject* self)
{
- MT_Vector3 pos = m_hitNormal;
-
- PyObject* resultlist = PyList_New(3);
- int index;
- for (index=0;index<3;index++)
- {
- PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index]));
- }
- return resultlist;
-
+ return PyObjectFrom(m_hitNormal);
}
diff --git a/source/gameengine/Ketsji/KX_RaySensor.h b/source/gameengine/Ketsji/KX_RaySensor.h
index 2baec12f74e..09d8bc1369a 100644
--- a/source/gameengine/Ketsji/KX_RaySensor.h
+++ b/source/gameengine/Ketsji/KX_RaySensor.h
@@ -74,10 +74,10 @@ public:
bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data);
bool NeedRayCast(KX_ClientObjectInfo* client);
- KX_PYMETHOD_DOC(KX_RaySensor,GetHitObject);
- KX_PYMETHOD_DOC(KX_RaySensor,GetHitPosition);
- KX_PYMETHOD_DOC(KX_RaySensor,GetHitNormal);
- KX_PYMETHOD_DOC(KX_RaySensor,GetRayDirection);
+ KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetHitObject);
+ KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetHitPosition);
+ KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetHitNormal);
+ KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetRayDirection);
virtual PyObject* _getattr(const char *attr);
diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
index 017ab5d6c97..68b704f4889 100644
--- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
@@ -204,6 +204,9 @@ PyMethodDef KX_SCA_AddObjectActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_SCA_AddObjectActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
PyObject* KX_SCA_AddObjectActuator::_getattr(const char *attr)
{
diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp
index 1aba05c1d83..394bb667728 100644
--- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp
@@ -85,6 +85,9 @@ PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
PyObject* KX_SCA_DynamicActuator::_getattr(const char *attr)
diff --git a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp
index 443921d22b0..9268a1df5f0 100644
--- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp
@@ -127,6 +127,9 @@ PyMethodDef KX_SCA_EndObjectActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_SCA_EndObjectActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
PyObject* KX_SCA_EndObjectActuator::_getattr(const char *attr)
{
diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
index ccc3b8fdb18..502990b2b27 100644
--- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
@@ -89,7 +89,9 @@ PyMethodDef KX_SCA_ReplaceMeshActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
-
+PyAttributeDef KX_SCA_ReplaceMeshActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
PyObject* KX_SCA_ReplaceMeshActuator::_getattr(const char *attr)
{
diff --git a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
index d651373869a..151270cbd68 100644
--- a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
+++ b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
@@ -97,11 +97,11 @@ UpdateChildCoordinates(
child_transform = parent_matrix * child_transform;
// Recompute the child transform components from the transform.
- child_w_scale = MT_Vector3(
+ child_w_scale.setValue(
MT_Vector3(child_transform[0][0], child_transform[0][1], child_transform[0][2]).length(),
MT_Vector3(child_transform[1][0], child_transform[1][1], child_transform[1][2]).length(),
MT_Vector3(child_transform[2][0], child_transform[2][1], child_transform[2][2]).length());
- child_w_rotation = MT_Matrix3x3(child_transform[0][0], child_transform[0][1], child_transform[0][2],
+ child_w_rotation.setValue(child_transform[0][0], child_transform[0][1], child_transform[0][2],
child_transform[1][0], child_transform[1][1], child_transform[1][2],
child_transform[2][0], child_transform[2][1], child_transform[2][2]);
child_w_rotation.scale(1.0/child_w_scale[0], 1.0/child_w_scale[1], 1.0/child_w_scale[2]);
@@ -113,16 +113,15 @@ UpdateChildCoordinates(
}
}
- if (!valid_parent_transform)
+ if (valid_parent_transform)
{
- child_w_scale = child_scale;
- child_w_pos = child_pos;
- child_w_rotation = child_rotation;
+ child->SetWorldScale(child_w_scale);
+ child->SetWorldPosition(child_w_pos);
+ child->SetWorldOrientation(child_w_rotation);
+ }
+ else {
+ child->SetWorldFromLocalTransform();
}
-
- child->SetWorldScale(child_w_scale);
- child->SetWorldPosition(child_w_pos);
- child->SetWorldOrientation(child_w_rotation);
return valid_parent_transform;
}
diff --git a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
index 0c8e7e28771..0729ec8a902 100644
--- a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
+++ b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
@@ -55,43 +55,21 @@ UpdateChildCoordinates(
){
MT_assert(child != NULL);
- // This way of accessing child coordinates is a bit cumbersome
- // be nice to have non constant reference access to these values.
-
- const MT_Vector3 & child_scale = child->GetLocalScale();
- const MT_Point3 & child_pos = child->GetLocalPosition();
- const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation();
-
- // the childs world locations which we will update.
-
- MT_Vector3 child_w_scale;
- MT_Point3 child_w_pos;
- MT_Matrix3x3 child_w_rotation;
-
- if (parent) {
-
+ if (parent==NULL) { /* Simple case */
+ child->SetWorldFromLocalTransform();
+ return false;
+ }
+ else {
+ // the childs world locations which we will update.
const MT_Vector3 & p_world_scale = parent->GetWorldScaling();
const MT_Point3 & p_world_pos = parent->GetWorldPosition();
const MT_Matrix3x3 & p_world_rotation = parent->GetWorldOrientation();
- child_w_scale = p_world_scale * child_scale;
- child_w_rotation = p_world_rotation * child_rotation;
-
- child_w_pos = p_world_pos + p_world_scale *
- (p_world_rotation * child_pos);
-
- } else {
-
- child_w_scale = child_scale;
- child_w_pos = child_pos;
- child_w_rotation = child_rotation;
+ child->SetWorldScale(p_world_scale * child->GetLocalScale());
+ child->SetWorldOrientation(p_world_rotation * child->GetLocalOrientation());
+ child->SetWorldPosition(p_world_pos + p_world_scale * (p_world_rotation * child->GetLocalPosition()));
+ return true;
}
-
- child->SetWorldScale(child_w_scale);
- child->SetWorldPosition(child_w_pos);
- child->SetWorldOrientation(child_w_rotation);
-
- return parent != NULL;
}
SG_ParentRelation *
@@ -138,40 +116,14 @@ UpdateChildCoordinates(
){
MT_assert(child != NULL);
-
- const MT_Vector3 & child_scale = child->GetLocalScale();
- const MT_Point3 & child_pos = child->GetLocalPosition();
- const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation();
-
- // the childs world locations which we will update.
+ child->SetWorldScale(child->GetLocalScale());
- MT_Vector3 child_w_scale;
- MT_Point3 child_w_pos;
- MT_Matrix3x3 child_w_rotation;
-
- if (parent) {
-
- // This is a vertex parent so we do not inherit orientation
- // information.
-
- // const MT_Vector3 & p_world_scale = parent->GetWorldScaling(); /*unused*/
- const MT_Point3 & p_world_pos = parent->GetWorldPosition();
- // const MT_Matrix3x3 & p_world_rotation = parent->GetWorldOrientation(); /*unused*/
-
- child_w_scale = child_scale;
- child_w_rotation = child_rotation;
- child_w_pos = p_world_pos + child_pos;
- } else {
-
- child_w_scale = child_scale;
- child_w_pos = child_pos;
- child_w_rotation = child_rotation;
- }
-
- child->SetWorldScale(child_w_scale);
- child->SetWorldPosition(child_w_pos);
- child->SetWorldOrientation(child_w_rotation);
+ if (parent)
+ child->SetWorldPosition(child->GetLocalPosition()+parent->GetWorldPosition());
+ else
+ child->SetWorldPosition(child->GetLocalPosition());
+ child->SetWorldOrientation(child->GetLocalOrientation());
return parent != NULL;
}
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp
index 7fcbf5b54bb..0fded15f1a1 100644
--- a/source/gameengine/Ketsji/KX_Scene.cpp
+++ b/source/gameengine/Ketsji/KX_Scene.cpp
@@ -1014,6 +1014,12 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj)
blendmesh->dvert!=NULL; // mesh has vertex group
bool releaseParent = true;
+
+ if (oldblendobj==NULL) {
+ std::cout << "warning: ReplaceMesh() new mesh is not used in an object from the current scene, you will get incorrect behavior" << std::endl;
+ bHasShapeKey= bHasDvert= bHasArmature= false;
+ }
+
if (bHasShapeKey)
{
BL_ShapeDeformer* shapeDeformer;
@@ -1511,14 +1517,6 @@ double KX_Scene::getSuspendedDelta()
//----------------------------------------------------------------------------
//Python
-PyMethodDef KX_Scene::Methods[] = {
- KX_PYMETHODTABLE_NOARGS(KX_Scene, getLightList),
- KX_PYMETHODTABLE_NOARGS(KX_Scene, getObjectList),
- KX_PYMETHODTABLE_NOARGS(KX_Scene, getName),
-
- {NULL,NULL} //Sentinel
-};
-
PyTypeObject KX_Scene::Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
@@ -1544,6 +1542,19 @@ PyParentObject KX_Scene::Parents[] = {
NULL
};
+PyMethodDef KX_Scene::Methods[] = {
+ KX_PYMETHODTABLE(KX_Scene, getLightList),
+ KX_PYMETHODTABLE(KX_Scene, getObjectList),
+ KX_PYMETHODTABLE(KX_Scene, getName),
+ KX_PYMETHODTABLE(KX_Scene, addObject),
+
+ {NULL,NULL} //Sentinel
+};
+
+PyAttributeDef KX_Scene::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* KX_Scene::_getattr(const char *attr)
{
if (!strcmp(attr, "name"))
@@ -1612,3 +1623,25 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_Scene, getName,
{
return PyString_FromString(GetName());
}
+
+KX_PYMETHODDEF_DOC(KX_Scene, addObject,
+"addObject(object, other, time=0)\n"
+"Returns the added object.\n")
+{
+ PyObject *pyob, *pyother;
+ KX_GameObject *ob, *other;
+
+ int time = 0;
+
+ if (!PyArg_ParseTuple(args, "OO|i", &pyob, &pyother, &time))
+ return NULL;
+
+ if (!ConvertPythonToGameObject(pyob, &ob, false)
+ || !ConvertPythonToGameObject(pyother, &other, false))
+ return NULL;
+
+
+ SCA_IObject* replica = AddReplicaObject((SCA_IObject*)ob, other, time);
+ replica->AddRef();
+ return replica;
+} \ No newline at end of file
diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h
index e4d4b6fe2cd..962db1a9b96 100644
--- a/source/gameengine/Ketsji/KX_Scene.h
+++ b/source/gameengine/Ketsji/KX_Scene.h
@@ -550,6 +550,7 @@ public:
KX_PYMETHOD_DOC_NOARGS(KX_Scene, getLightList);
KX_PYMETHOD_DOC_NOARGS(KX_Scene, getObjectList);
KX_PYMETHOD_DOC_NOARGS(KX_Scene, getName);
+ KX_PYMETHOD_DOC(KX_Scene, addObject);
/*
KX_PYMETHOD_DOC(KX_Scene, getActiveCamera);
KX_PYMETHOD_DOC(KX_Scene, getActiveCamera);
@@ -567,7 +568,9 @@ public:
virtual PyObject* _getattr(const char *attr); /* name, active_camera, gravity, suspended, viewport, framing, activity_culling, activity_culling_radius */
virtual int _setattr(const char *attr, PyObject *pyvalue);
virtual int _delattr(const char *attr);
+ virtual PyObject* _repr(void) { return PyString_FromString(GetName().ReadPtr()); }
+
/**
* Sets the time the scene was suspended
*/
diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp
index 8e33177cf3a..1cad4e21352 100644
--- a/source/gameengine/Ketsji/KX_SceneActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp
@@ -268,7 +268,9 @@ PyMethodDef KX_SceneActuator::Methods[] =
{NULL,NULL} //Sentinel
};
-
+PyAttributeDef KX_SceneActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
PyObject* KX_SceneActuator::_getattr(const char *attr)
{
diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp
index 37604518486..6de1d67bfdb 100644
--- a/source/gameengine/Ketsji/KX_SoundActuator.cpp
+++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp
@@ -285,7 +285,9 @@ PyMethodDef KX_SoundActuator::Methods[] = {
{NULL,NULL,NULL,NULL} //Sentinel
};
-
+PyAttributeDef KX_SoundActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
PyObject* KX_SoundActuator::_getattr(const char *attr)
{
@@ -444,7 +446,7 @@ PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObjec
PyObject* KX_SoundActuator::PyGetLooping(PyObject* self, PyObject* args, PyObject* kwds)
{
- int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : SND_LOOP_OFF;
+ int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF;
PyObject* result = PyInt_FromLong(looping);
return result;
diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp
index cd5c5d29ab1..0de4da79bd8 100644
--- a/source/gameengine/Ketsji/KX_StateActuator.cpp
+++ b/source/gameengine/Ketsji/KX_StateActuator.cpp
@@ -146,6 +146,10 @@ KX_StateActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_StateActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* KX_StateActuator::_getattr(const char *attr)
{
_getattr_up(SCA_IActuator);
diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp
index 117adb44742..705b54edd37 100644
--- a/source/gameengine/Ketsji/KX_TouchSensor.cpp
+++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp
@@ -34,7 +34,9 @@
#include "SCA_LogicManager.h"
#include "KX_GameObject.h"
#include "KX_TouchEventManager.h"
-#include "KX_SumoPhysicsController.h"
+
+#include "PHY_IPhysicsController.h"
+
#include <iostream>
#include "PHY_IPhysicsEnvironment.h"
@@ -57,6 +59,7 @@ void KX_TouchSensor::EndFrame() {
m_colliders->ReleaseAndRemoveAll();
m_hitObject = NULL;
m_bTriggered = false;
+ m_bColliderHash = 0;
}
void KX_TouchSensor::UnregisterToManager()
@@ -70,7 +73,6 @@ bool KX_TouchSensor::Evaluate(CValue* event)
{
bool result = false;
bool reset = m_reset && m_level;
-
m_reset = false;
if (m_bTriggered != m_bLastTriggered)
{
@@ -82,13 +84,24 @@ bool KX_TouchSensor::Evaluate(CValue* event)
if (reset)
// force an event
result = true;
+
+ if (m_bTouchPulse) { /* pulse on changes to the colliders */
+ int count = m_colliders->GetCount();
+
+ if (m_bLastCount!=count || m_bColliderHash!=m_bLastColliderHash) {
+ m_bLastCount = count;
+ m_bLastColliderHash= m_bColliderHash;
+ result = true;
+ }
+ }
return result;
}
-KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj,bool bFindMaterial,const STR_String& touchedpropname,PyTypeObject* T)
+KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj,bool bFindMaterial,bool bTouchPulse,const STR_String& touchedpropname,PyTypeObject* T)
:SCA_ISensor(gameobj,eventmgr,T),
m_touchedpropname(touchedpropname),
m_bFindMaterial(bFindMaterial),
+m_bTouchPulse(bTouchPulse),
m_eventmgr(eventmgr)
/*m_sumoObj(sumoObj),*/
{
@@ -114,6 +127,8 @@ void KX_TouchSensor::Init()
m_bCollision = false;
m_bTriggered = false;
m_bLastTriggered = (m_invert)?true:false;
+ m_bLastCount = 0;
+ m_bColliderHash = m_bLastColliderHash = 0;
m_hitObject = NULL;
m_reset = true;
}
@@ -189,8 +204,6 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll
if (m_links && !m_suspended &&
gameobj && (gameobj != parent) && client_info->isActor())
{
- if (!m_colliders->SearchValue(gameobj))
- m_colliders->Add(gameobj->AddRef());
bool found = m_touchedpropname.IsEmpty();
if (!found)
@@ -208,13 +221,19 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll
}
if (found)
{
+ if (!m_colliders->SearchValue(gameobj)) {
+ m_colliders->Add(gameobj->AddRef());
+
+ if (m_bTouchPulse)
+ m_bColliderHash += (uint_ptr)(static_cast<void *>(&gameobj));
+ }
m_bTriggered = true;
m_hitObject = gameobj;
//printf("KX_TouchSensor::HandleCollision\n");
}
}
- return DT_CONTINUE;
+ return false; // was DT_CONTINUE but this was defined in sumo as false.
}
@@ -250,21 +269,53 @@ PyParentObject KX_TouchSensor::Parents[] = {
};
PyMethodDef KX_TouchSensor::Methods[] = {
+ //Deprecated ----->
{"setProperty",
- (PyCFunction) KX_TouchSensor::sPySetProperty, METH_VARARGS, (PY_METHODCHAR)SetProperty_doc},
+ (PyCFunction) KX_TouchSensor::sPySetProperty, METH_O, (PY_METHODCHAR)SetProperty_doc},
{"getProperty",
- (PyCFunction) KX_TouchSensor::sPyGetProperty, METH_VARARGS, (PY_METHODCHAR)GetProperty_doc},
+ (PyCFunction) KX_TouchSensor::sPyGetProperty, METH_NOARGS, (PY_METHODCHAR)GetProperty_doc},
{"getHitObject",
- (PyCFunction) KX_TouchSensor::sPyGetHitObject, METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc},
+ (PyCFunction) KX_TouchSensor::sPyGetHitObject, METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc},
{"getHitObjectList",
- (PyCFunction) KX_TouchSensor::sPyGetHitObjectList, METH_VARARGS, (PY_METHODCHAR)GetHitObjectList_doc},
+ (PyCFunction) KX_TouchSensor::sPyGetHitObjectList, METH_NOARGS, (PY_METHODCHAR)GetHitObjectList_doc},
+ //<-----
{NULL,NULL} //Sentinel
};
-PyObject* KX_TouchSensor::_getattr(const char *attr) {
+PyAttributeDef KX_TouchSensor::Attributes[] = {
+ KX_PYATTRIBUTE_STRING_RW("property",0,100,false,KX_TouchSensor,m_touchedpropname),
+ KX_PYATTRIBUTE_BOOL_RW("useMaterial",KX_TouchSensor,m_bFindMaterial),
+ KX_PYATTRIBUTE_BOOL_RW("pulseCollisions",KX_TouchSensor,m_bTouchPulse),
+ KX_PYATTRIBUTE_DUMMY("objectHit"),
+ KX_PYATTRIBUTE_DUMMY("objectHitList"),
+ { NULL } //Sentinel
+};
+
+PyObject* KX_TouchSensor::_getattr(const char *attr)
+{
+ if (!strcmp(attr, "objectHit")) {
+ if (m_hitObject) return m_hitObject->AddRef();
+ else Py_RETURN_NONE;
+ }
+ if (!strcmp(attr, "objectHitList")) {
+ return m_colliders->AddRef();
+ }
+
+ PyObject* object= _getattr_self(Attributes, this, attr);
+ if (object != NULL)
+ return object;
_getattr_up(SCA_ISensor);
}
+int KX_TouchSensor::_setattr(const char *attr, PyObject *value)
+{
+ int ret = _setattr_self(Attributes, this, attr, value);
+ if (ret >= 0)
+ return ret;
+
+ return SCA_ISensor::_setattr(attr, value);
+}
+
/* Python API */
/* 1. setProperty */
@@ -274,23 +325,16 @@ const char KX_TouchSensor::SetProperty_doc[] =
"\tSet the property or material to collide with. Use\n"
"\tsetTouchMaterial() to switch between properties and\n"
"\tmaterials.";
-PyObject* KX_TouchSensor::PySetProperty(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
- char *nameArg;
- if (!PyArg_ParseTuple(args, "s", &nameArg)) {
+PyObject* KX_TouchSensor::PySetProperty(PyObject* self, PyObject* value)
+{
+ ShowDeprecationWarning("setProperty()", "the propertyName property");
+ char *nameArg= PyString_AsString(value);
+ if (nameArg==NULL) {
+ PyErr_SetString(PyExc_ValueError, "expected a ");
return NULL;
}
-
- CValue* prop = GetParent()->FindIdentifier(nameArg);
-
- if (!prop->IsError()) {
- m_touchedpropname = nameArg;
- } else {
- ; /* not found ... */
- }
- prop->Release();
+ m_touchedpropname = nameArg;
Py_RETURN_NONE;
}
/* 2. getProperty */
@@ -299,19 +343,16 @@ const char KX_TouchSensor::GetProperty_doc[] =
"\tReturns the property or material to collide with. Use\n"
"\tgetTouchMaterial() to find out whether this sensor\n"
"\tlooks for properties or materials.";
-PyObject* KX_TouchSensor::PyGetProperty(PyObject* self,
- PyObject* args,
- PyObject* kwds) {
+PyObject* KX_TouchSensor::PyGetProperty(PyObject* self) {
return PyString_FromString(m_touchedpropname);
}
const char KX_TouchSensor::GetHitObject_doc[] =
"getHitObject()\n"
;
-PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* KX_TouchSensor::PyGetHitObject(PyObject* self)
{
+ ShowDeprecationWarning("getHitObject()", "the objectHit property");
/* to do: do Py_IncRef if the object is already known in Python */
/* otherwise, this leaks memory */
if (m_hitObject)
@@ -325,78 +366,41 @@ const char KX_TouchSensor::GetHitObjectList_doc[] =
"getHitObjectList()\n"
"\tReturn a list of the objects this object collided with,\n"
"\tbut only those matching the property/material condition.\n";
-PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* KX_TouchSensor::PyGetHitObjectList(PyObject* self)
{
-
+ ShowDeprecationWarning("getHitObjectList()", "the objectHitList property");
/* to do: do Py_IncRef if the object is already known in Python */
- /* otherwise, this leaks memory */
-
- if ( m_touchedpropname.IsEmpty() ) {
- return m_colliders->AddRef();
- } else {
- CListValue* newList = new CListValue();
- int i = 0;
- while (i < m_colliders->GetCount()) {
- if (m_bFindMaterial) {
- /* need to associate the CValues from the list to material
- * names. The collider list _should_ contains only
- * KX_GameObjects. I am loathe to cast them, though... The
- * material name must be retrieved from Sumo. To a Sumo
- * object, a client-info block is attached. This block
- * contains the material name.
- * - this also doesn't work (obviously) for multi-materials...
- */
- KX_GameObject* gameob = (KX_GameObject*) m_colliders->GetValue(i);
- PHY_IPhysicsController* spc = dynamic_cast<PHY_IPhysicsController*>(gameob->GetPhysicsController());
-
- if (spc) {
- KX_ClientObjectInfo* cl_inf = static_cast<KX_ClientObjectInfo*>(spc->getNewClientInfo());
-
- if (NULL != cl_inf->m_auxilary_info && m_touchedpropname == ((char*)cl_inf->m_auxilary_info)) {
- newList->Add(m_colliders->GetValue(i)->AddRef());
- }
- }
-
- } else {
- CValue* val = m_colliders->GetValue(i)->FindIdentifier(m_touchedpropname);
- if (!val->IsError()) {
- newList->Add(m_colliders->GetValue(i)->AddRef());
- }
- val->Release();
- }
-
- i++;
- }
- return newList->AddRef();
- }
-
+ /* otherwise, this leaks memory */ /* Edit, this seems ok and not to leak memory - Campbell */
+ return m_colliders->AddRef();
}
+/*getTouchMaterial and setTouchMaterial were never added to the api,
+they can probably be removed with out anyone noticing*/
+
/* 5. getTouchMaterial */
const char KX_TouchSensor::GetTouchMaterial_doc[] =
"getTouchMaterial()\n"
"\tReturns KX_TRUE if this sensor looks for a specific material,\n"
"\tKX_FALSE if it looks for a specific property.\n" ;
-PyObject* KX_TouchSensor::PyGetTouchMaterial(PyObject* self,
- PyObject* args,
- PyObject* kwds)
+PyObject* KX_TouchSensor::PyGetTouchMaterial(PyObject* self)
{
+ ShowDeprecationWarning("getTouchMaterial()", "the materialCheck property");
return PyInt_FromLong(m_bFindMaterial);
}
/* 6. setTouchMaterial */
+#if 0
const char KX_TouchSensor::SetTouchMaterial_doc[] =
"setTouchMaterial(flag)\n"
"\t- flag: KX_TRUE or KX_FALSE.\n"
"\tSet flag to KX_TRUE to switch on positive pulse mode,\n"
"\tKX_FALSE to switch off positive pulse mode.\n" ;
-PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject* args, PyObject* kwds)
+PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject *value)
{
- int pulseArg = 0;
+ int pulseArg = PyInt_AsLong(value);
- if(!PyArg_ParseTuple(args, "i", &pulseArg)) {
+ if(pulseArg ==-1 && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ValueError, "expected a bool");
return NULL;
}
@@ -404,6 +408,6 @@ PyObject* KX_TouchSensor::PySetTouchMaterial(PyObject* self, PyObject* args, PyO
Py_RETURN_NONE;
}
-
+#endif
/* eof */
diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h
index e07f89f0a31..18ce9406a9b 100644
--- a/source/gameengine/Ketsji/KX_TouchSensor.h
+++ b/source/gameengine/Ketsji/KX_TouchSensor.h
@@ -39,6 +39,12 @@ struct PHY_CollData;
#include "KX_ClientObjectInfo.h"
+#if defined(_WIN64)
+typedef unsigned __int64 uint_ptr;
+#else
+typedef unsigned long uint_ptr;
+#endif
+
class KX_TouchEventManager;
class KX_TouchSensor : public SCA_ISensor
@@ -51,6 +57,7 @@ protected:
*/
STR_String m_touchedpropname;
bool m_bFindMaterial;
+ bool m_bTouchPulse; /* changes in the colliding objects trigger pulses */
class SCA_EventManager* m_eventmgr;
class PHY_IPhysicsController* m_physCtrl;
@@ -58,13 +65,20 @@ protected:
bool m_bCollision;
bool m_bTriggered;
bool m_bLastTriggered;
+
+ // Use with m_bTouchPulse to detect changes
+ int m_bLastCount; /* size of m_colliders last tick */
+ uint_ptr m_bColliderHash; /* hash collision objects pointers to trigger incase one object collides and another takes its place */
+ uint_ptr m_bLastColliderHash;
+
SCA_IObject* m_hitObject;
class CListValue* m_colliders;
public:
KX_TouchSensor(class SCA_EventManager* eventmgr,
class KX_GameObject* gameobj,
- bool fFindMaterial,
+ bool bFindMaterial,
+ bool bTouchPulse,
const STR_String& touchedpropname,
PyTypeObject* T=&Type) ;
virtual ~KX_TouchSensor();
@@ -107,19 +121,24 @@ public:
/* --------------------------------------------------------------------- */
virtual PyObject* _getattr(const char *attr);
+ virtual int _setattr(const char *attr, PyObject *value);
+ //Deprecated ----->
/* 1. setProperty */
- KX_PYMETHOD_DOC(KX_TouchSensor,SetProperty);
+ KX_PYMETHOD_DOC_O(KX_TouchSensor,SetProperty);
/* 2. getProperty */
- KX_PYMETHOD_DOC(KX_TouchSensor,GetProperty);
+ KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetProperty);
/* 3. getHitObject */
- KX_PYMETHOD_DOC(KX_TouchSensor,GetHitObject);
+ KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetHitObject);
/* 4. getHitObject */
- KX_PYMETHOD_DOC(KX_TouchSensor,GetHitObjectList);
+ KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetHitObjectList);
/* 5. getTouchMaterial */
- KX_PYMETHOD_DOC(KX_TouchSensor,GetTouchMaterial);
+ KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetTouchMaterial);
+#if 0
/* 6. setTouchMaterial */
- KX_PYMETHOD_DOC(KX_TouchSensor,SetTouchMaterial);
+ KX_PYMETHOD_DOC_O(KX_TouchSensor,SetTouchMaterial);
+#endif
+ //<-----
};
diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp
index 89dfc8e57ad..8637bc92d39 100644
--- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp
+++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp
@@ -258,18 +258,18 @@ bool KX_TrackToActuator::Update(double curtime, bool frame)
{
case 0:
{
- up = MT_Vector3(1.0,0,0);
+ up.setValue(1.0,0,0);
break;
}
case 1:
{
- up = MT_Vector3(0,1.0,0);
+ up.setValue(0,1.0,0);
break;
}
case 2:
default:
{
- up = MT_Vector3(0,0,1.0);
+ up.setValue(0,0,1.0);
}
}
#endif
@@ -468,6 +468,9 @@ PyMethodDef KX_TrackToActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_TrackToActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
PyObject* KX_TrackToActuator::_getattr(const char *attr)
diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
index 057e10f195a..8d5af1b9216 100644
--- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
+++ b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
@@ -382,3 +382,6 @@ PyMethodDef KX_VehicleWrapper::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_VehicleWrapper::Attributes[] = {
+ { NULL } //Sentinel
+};
diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp
index 1c427768b66..da0e3dbdd8d 100644
--- a/source/gameengine/Ketsji/KX_VertexProxy.cpp
+++ b/source/gameengine/Ketsji/KX_VertexProxy.cpp
@@ -78,6 +78,10 @@ PyMethodDef KX_VertexProxy::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_VertexProxy::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject*
KX_VertexProxy::_getattr(const char *attr)
{
diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp
index ca89a63de62..0ec280080bd 100644
--- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp
+++ b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp
@@ -126,6 +126,10 @@ KX_VisibilityActuator::Methods[] = {
{NULL,NULL} //Sentinel
};
+PyAttributeDef KX_VisibilityActuator::Attributes[] = {
+ { NULL } //Sentinel
+};
+
PyObject* KX_VisibilityActuator::_getattr(const char *attr)
{
_getattr_up(SCA_IActuator);
diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript
index e9e68f14df8..5989d9d8b52 100644
--- a/source/gameengine/Ketsji/SConscript
+++ b/source/gameengine/Ketsji/SConscript
@@ -4,6 +4,7 @@ import sys
Import ('env')
sources = env.Glob('*.cpp')
+defs = ''
# Mathutils C files.
sources.extend([\
@@ -30,21 +31,27 @@ incs += ' #source/blender/makesdna #source/blender/python #source/gameengine/Ras
incs += ' #source/gameengine/GameLogic #source/gameengine/Expressions #source/gameengine/Network'
incs += ' #source/gameengine/SceneGraph #source/gameengine/Physics/common #source/gameengine/Physics/Bullet'
incs += ' #source/gameengine/Physics/BlOde #source/gameengine/Physics/Dummy'
-incs += ' #source/gameengine/Physics/Sumo #source/gameengine/Physics/Sumo/include'
-incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork'
incs += ' #source/blender/misc #source/blender/blenloader #extern/glew/include #source/blender/gpu'
-incs += ' ' + env['BF_SOLID_INC']
+if env['WITH_BF_SOLID']:
+ incs += ' #source/gameengine/Physics/Sumo #source/gameengine/Physics/Sumo/include'
+ incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork'
+ incs += ' ' + env['BF_SOLID_INC']
+ defs += ' USE_SUMO_SOLID'
+
+
incs += ' ' + env['BF_PYTHON_INC']
incs += ' ' + env['BF_BULLET_INC']
incs += ' ' + env['BF_OPENGL_INC']
if env['WITH_BF_SDL']:
incs += ' ' + env['BF_SDL_INC']
-
+else:
+ defs += ' DISABLE_SDL'
+
cxxflags = []
if env['OURPLATFORM']=='win32-vc':
cxxflags.append ('/GR')
cxxflags.append ('/O2')
-env.BlenderLib ( 'bf_ketsji', sources, Split(incs), [], libtype=['game','player'], priority=[25, 72], cxx_compileflags = cxxflags )
+env.BlenderLib ( 'bf_ketsji', sources, Split(incs), Split(defs), libtype=['game','player'], priority=[25, 72], cxx_compileflags = cxxflags )
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
index d09ad58fe3b..eecdea55349 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
@@ -1240,7 +1240,7 @@ void DefaultMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,flo
void DefaultMotionState::setWorldPosition(float posX,float posY,float posZ)
{
- btPoint3 pos(posX,posY,posZ);
+ btVector3 pos(posX,posY,posZ);
m_worldTransform.setOrigin( pos );
}
@@ -1328,7 +1328,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
for (int i=0;i<poly->VertexCount();i++)
{
const float* vtx = poly->GetVertex(i)->getXYZ();
- btPoint3 point(vtx[0],vtx[1],vtx[2]);
+ btVector3 point(vtx[0],vtx[1],vtx[2]);
//avoid duplicates (could better directly use vertex offsets, rather than a vertex compare)
bool found = false;
for (int j=0;j<m_vertexArray.size();j++)
@@ -1348,13 +1348,13 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
{
{
const float* vtx = poly->GetVertex(2)->getXYZ();
- btPoint3 vertex0(vtx[0],vtx[1],vtx[2]);
+ btVector3 vertex0(vtx[0],vtx[1],vtx[2]);
vtx = poly->GetVertex(1)->getXYZ();
- btPoint3 vertex1(vtx[0],vtx[1],vtx[2]);
+ btVector3 vertex1(vtx[0],vtx[1],vtx[2]);
vtx = poly->GetVertex(0)->getXYZ();
- btPoint3 vertex2(vtx[0],vtx[1],vtx[2]);
+ btVector3 vertex2(vtx[0],vtx[1],vtx[2]);
m_vertexArray.push_back(vertex0);
m_vertexArray.push_back(vertex1);
@@ -1365,13 +1365,13 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
if (poly->VertexCount() == 4)
{
const float* vtx = poly->GetVertex(3)->getXYZ();
- btPoint3 vertex0(vtx[0],vtx[1],vtx[2]);
+ btVector3 vertex0(vtx[0],vtx[1],vtx[2]);
vtx = poly->GetVertex(2)->getXYZ();
- btPoint3 vertex1(vtx[0],vtx[1],vtx[2]);
+ btVector3 vertex1(vtx[0],vtx[1],vtx[2]);
vtx = poly->GetVertex(0)->getXYZ();
- btPoint3 vertex2(vtx[0],vtx[1],vtx[2]);
+ btVector3 vertex2(vtx[0],vtx[1],vtx[2]);
m_vertexArray.push_back(vertex0);
m_vertexArray.push_back(vertex1);
@@ -1442,7 +1442,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
break;
case PHY_SHAPE_POLYTOPE:
- collisionShape = new btConvexHullShape(&m_vertexArray.begin()->getX(), m_vertexArray.size());
+ collisionShape = new btConvexHullShape(&m_vertexArray[0].getX(), m_vertexArray.size());
break;
case PHY_SHAPE_MESH:
@@ -1457,12 +1457,14 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
{
collisionMeshData = new btTriangleMesh();
+ bool removeDuplicateVertices=true;
// m_vertexArray is necessarily a multiple of 3
- for (std::vector<btPoint3>::iterator it=m_vertexArray.begin(); it != m_vertexArray.end(); )
+ for (int i=0;i<m_vertexArray.size(); i+=3 )
{
- collisionMeshData->addTriangle(*it++,*it++,*it++);
+ collisionMeshData->addTriangle(m_vertexArray[i+2],m_vertexArray[i+1],m_vertexArray[i],removeDuplicateVertices);
}
+
btGImpactMeshShape* gimpactShape = new btGImpactMeshShape(collisionMeshData);
collisionShape = gimpactShape;
@@ -1475,10 +1477,11 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
collisionMeshData = new btTriangleMesh(true,false);
collisionMeshData->m_weldingThreshold = m_weldingThreshold;
+ bool removeDuplicateVertices=true;
// m_vertexArray is necessarily a multiple of 3
- for (std::vector<btPoint3>::iterator it=m_vertexArray.begin(); it != m_vertexArray.end(); )
+ for (int i=0;i<m_vertexArray.size(); i+=3 )
{
- collisionMeshData->addTriangle(*it++,*it++,*it++);
+ collisionMeshData->addTriangle(m_vertexArray[i+2],m_vertexArray[i+1],m_vertexArray[i],removeDuplicateVertices);
}
// this shape will be shared and not deleted until shapeInfo is deleted
m_unscaledShape = new btBvhTriangleMeshShape( collisionMeshData, true );
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
index c771aa2624b..deb3c0880e9 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
@@ -161,7 +161,7 @@ public:
btTransform m_childTrans;
btVector3 m_childScale;
void* m_userData;
- std::vector<btPoint3> m_vertexArray; // Contains both vertex array for polytope shape and
+ btAlignedObjectArray<btVector3> m_vertexArray; // Contains both vertex array for polytope shape and
// triangle array for concave mesh shape.
// In this case a triangle is made of 3 consecutive points
std::vector<int> m_polygonIndexArray; // Contains the array of polygon index in the
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
index d2274c1e8d6..dd21e58bd68 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
@@ -317,8 +317,8 @@ static void DrawAabb(btIDebugDraw* debugDrawer,const btVector3& from,const btVec
CcdPhysicsEnvironment::CcdPhysicsEnvironment(btDispatcher* dispatcher,btOverlappingPairCache* pairCache)
-:m_scalingPropagated(false),
-m_numIterations(10),
+:m_numIterations(10),
+m_scalingPropagated(false),
m_numTimeSubSteps(1),
m_ccdMode(0),
m_solverType(-1),
@@ -326,8 +326,8 @@ m_profileTimings(0),
m_enableSatCollisionDetection(false),
m_solver(NULL),
m_ownPairCache(NULL),
-m_ownDispatcher(NULL),
-m_filterCallback(NULL)
+m_filterCallback(NULL),
+m_ownDispatcher(NULL)
{
for (int i=0;i<PHY_NUM_RESPONSE;i++)
@@ -337,6 +337,7 @@ m_filterCallback(NULL)
// m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
+ //m_collisionConfiguration->setConvexConvexMultipointIterations();
if (!dispatcher)
{
@@ -356,6 +357,8 @@ m_filterCallback(NULL)
setSolverType(1);//issues with quickstep and memory allocations
// m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
m_dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
+ //m_dynamicsWorld->getSolverInfo().m_linearSlop = 0.01f;
+ //m_dynamicsWorld->getSolverInfo().m_solverMode= SOLVER_USE_WARMSTARTING + SOLVER_USE_2_FRICTION_DIRECTIONS + SOLVER_RANDMIZE_ORDER + SOLVER_USE_FRICTION_WARMSTARTING;
m_debugDrawer = 0;
m_gravity = btVector3(0.f,-10.f,0.f);
@@ -414,7 +417,7 @@ void CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl)
const btTransform& t = ctrl->GetCollisionObject()->getWorldTransform();
- btPoint3 minAabb,maxAabb;
+ btVector3 minAabb,maxAabb;
shapeinterface->getAabb(t,minAabb,maxAabb);
@@ -560,6 +563,11 @@ void CcdPhysicsEnvironment::beginFrame()
}
+void CcdPhysicsEnvironment::debugDrawWorld()
+{
+ if (m_dynamicsWorld->getDebugDrawer() && m_dynamicsWorld->getDebugDrawer()->getDebugMode() >0)
+ m_dynamicsWorld->debugDrawWorld();
+}
bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
{
@@ -596,9 +604,6 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
veh->SyncWheels();
}
- if (m_dynamicsWorld->getDebugDrawer() && m_dynamicsWorld->getDebugDrawer()->getDebugMode() >0)
- m_dynamicsWorld->debugDrawWorld();
-
CallbackTriggers();
@@ -845,7 +850,8 @@ void CcdPhysicsEnvironment::setSolverType(int solverType)
{
m_solver = new btSequentialImpulseConstraintSolver();
-// ((btSequentialImpulseConstraintSolver*)m_solver)->setSolverMode(btSequentialImpulseConstraintSolver::SOLVER_USE_WARMSTARTING | btSequentialImpulseConstraintSolver::SOLVER_RANDMIZE_ORDER);
+
+
break;
}
}
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
index 4b28d3fddfc..2f1f0bb254b 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
@@ -110,6 +110,8 @@ protected:
virtual void endFrame() {};
/// Perform an integration step of duration 'timeStep'.
virtual bool proceedDeltaTime(double curTime,float timeStep);
+
+ virtual void debugDrawWorld();
// virtual bool proceedDeltaTimeOneStep(float timeStep);
virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep){};
diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
index 0e9c571924c..226ba3a7e74 100644
--- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
+++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
@@ -90,6 +90,8 @@ class PHY_IPhysicsEnvironment
virtual void endFrame() = 0;
/// Perform an integration step of duration 'timeStep'.
virtual bool proceedDeltaTime(double curTime,float timeStep)=0;
+ ///draw debug lines (make sure to call this during the render phase, otherwise lines are not drawn properly)
+ virtual void debugDrawWorld(){}
virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)=0;
//returns 0.f if no fixed timestep is used
virtual float getFixedTimeStep()=0;
diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py
index 9dab7db6081..0524a9df355 100644
--- a/source/gameengine/PyDoc/GameLogic.py
+++ b/source/gameengine/PyDoc/GameLogic.py
@@ -140,6 +140,14 @@ Documentation for the GameLogic Module.
@var KX_SOUNDACT_LOOPEND: See L{KX_SoundActuator}
@var KX_SOUNDACT_LOOPBIDIRECTIONAL: See L{KX_SoundActuator}
@var KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: See L{KX_SoundActuator}
+
+@group Radar Sensor: KX_RADAR_AXIS_POS_X, KX_RADAR_AXIS_POS_Y, KX_RADAR_AXIS_POS_Z, KX_RADAR_AXIS_NEG_X, KX_RADAR_AXIS_NEG_Y, KX_RADAR_AXIS_NEG_Z
+@var KX_RADAR_AXIS_POS_X: See L{KX_RadarSensor}
+@var KX_RADAR_AXIS_POS_Y: See L{KX_RadarSensor}
+@var KX_RADAR_AXIS_POS_Z: See L{KX_RadarSensor}
+@var KX_RADAR_AXIS_NEG_X: See L{KX_RadarSensor}
+@var KX_RADAR_AXIS_NEG_Y: See L{KX_RadarSensor}
+@var KX_RADAR_AXIS_NEG_Z: See L{KX_RadarSensor}
"""
@@ -159,7 +167,7 @@ def addActiveActuator(actuator, activate):
"""
Activates the given actuator.
- @type actuator: L{SCA_IActuator}
+ @type actuator: L{SCA_IActuator} or the actuator name as a string.
@type activate: boolean
@param activate: whether to activate or deactivate the given actuator.
"""
diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py
index efeffab2eed..4f389a1ae4f 100644
--- a/source/gameengine/PyDoc/KX_GameObject.py
+++ b/source/gameengine/PyDoc/KX_GameObject.py
@@ -7,7 +7,7 @@ class KX_GameObject:
Properties assigned to game objects are accessible as attributes of this class.
- @ivar name: The object's name.
+ @ivar name: The object's name. (Read only)
@type name: string.
@ivar mass: The object's mass (provided the object has a physics controller). Read only.
@type mass: float
diff --git a/source/gameengine/PyDoc/KX_NearSensor.py b/source/gameengine/PyDoc/KX_NearSensor.py
index fef2e4b2acc..a8c408827fe 100644
--- a/source/gameengine/PyDoc/KX_NearSensor.py
+++ b/source/gameengine/PyDoc/KX_NearSensor.py
@@ -5,5 +5,10 @@ from KX_TouchSensor import *
class KX_NearSensor(KX_TouchSensor):
"""
A near sensor is a specialised form of touch sensor.
+
+ @ivar distance: The near sensor activates when an object is within this distance.
+ @type distance: float
+ @ivar resetDistance: The near sensor deactivates when the object exceeds this distance.
+ @type resetDistance: float
"""
diff --git a/source/gameengine/PyDoc/KX_RadarSensor.py b/source/gameengine/PyDoc/KX_RadarSensor.py
index 64be858371a..b68bf4ea0f3 100644
--- a/source/gameengine/PyDoc/KX_RadarSensor.py
+++ b/source/gameengine/PyDoc/KX_RadarSensor.py
@@ -5,8 +5,26 @@ from KX_NearSensor import *
class KX_RadarSensor(KX_NearSensor):
"""
Radar sensor is a near sensor with a conical sensor object.
+
+ @ivar coneOrigin: The origin of the cone with which to test. The origin
+ is in the middle of the cone.
+ (Read only)
+ @type coneOrigin: list of floats [x, y, z]
+ @ivar coneTarget: The center of the bottom face of the cone with which to test.
+ (Read only)
+ @type coneTarget: list of floats [x, y, z]
+ @ivar distance: The height of the cone with which to test.
+ @type distance: float
+ @ivar angle: The angle of the cone (in degrees) with which to test.
+ @type angle: float from 0 to 360
+ @ivar axis: The axis on which the radar cone is cast
+ @type axis: int from 0 to 5
+ KX_RADAR_AXIS_POS_X, KX_RADAR_AXIS_POS_Y, KX_RADAR_AXIS_POS_Z,
+ KX_RADAR_AXIS_NEG_X, KX_RADAR_AXIS_NEG_Y, KX_RADAR_AXIS_NEG_Z
"""
+
+ #--The following methods are deprecated, please use properties instead.
def getConeOrigin():
"""
Returns the origin of the cone with which to test. The origin
diff --git a/source/gameengine/PyDoc/KX_Scene.py b/source/gameengine/PyDoc/KX_Scene.py
index 4a0a7a9556d..5e357e6eefc 100644
--- a/source/gameengine/PyDoc/KX_Scene.py
+++ b/source/gameengine/PyDoc/KX_Scene.py
@@ -39,6 +39,8 @@ class KX_Scene:
@ivar name: The scene's name
@type name: string
+ @type objects: A list of objects in the scene.
+ @type objects: list [L{KX_GameObject}]
@ivar active_camera: The current active camera
@type active_camera: L{KX_Camera}
@ivar suspended: True if the scene is suspended.
@@ -68,3 +70,16 @@ class KX_Scene:
@rtype: string
"""
+ def addObject(object, other, time=0)
+ """
+ Adds an object to the scene like the Add Object Actuator would, and returns the created object.
+
+ @param object: The object to add
+ @type object: L{KX_GameObject} or string
+ @param other: The object's center to use when adding the object
+ @type other: L{KX_GameObject} or string
+ @param time: The lifetime of the added object, in frames. A time of 0 means the object will last forever.
+ @type time: int
+
+ @rtype: L{KX_GameObject}
+ """
diff --git a/source/gameengine/PyDoc/KX_TouchSensor.py b/source/gameengine/PyDoc/KX_TouchSensor.py
index f2cc101af10..d7277be4c2a 100644
--- a/source/gameengine/PyDoc/KX_TouchSensor.py
+++ b/source/gameengine/PyDoc/KX_TouchSensor.py
@@ -1,36 +1,55 @@
# $Id$
# Documentation for KX_TouchSensor
from SCA_ISensor import *
+from KX_GameObject import *
class KX_TouchSensor(SCA_ISensor):
"""
Touch sensor detects collisions between objects.
+
+ @ivar property: The property or material to collide with.
+ @type property: string
+ @ivar useMaterial: Determines if the sensor is looking for a property or material.
+ KX_True = Find material; KX_False = Find property
+ @type useMaterial: boolean
+ @ivar pulseCollisions: The last collided object.
+ @type pulseCollisions: bool
+ @ivar objectHit: The last collided object. (Read Only)
+ @type objectHit: L{KX_GameObject} or None
+ @ivar objectHitList: A list of colliding objects. (Read Only)
+ @type objectHitList: list
"""
+
+ #--The following methods are deprecated, please use properties instead.
def setProperty(name):
"""
+ DEPRECATED: use the property property
Set the property or material to collide with. Use
setTouchMaterial() to switch between properties and
materials.
@type name: string
"""
+
def getProperty():
"""
+ DEPRECATED: use the property property
Returns the property or material to collide with. Use
getTouchMaterial() to find out whether this sensor
- looks for properties or materials.
+ looks for properties or materials. (B{deprecated})
@rtype: string
"""
-
def getHitObject():
"""
- Returns the last object hit by this touch sensor.
+ DEPRECATED: use the objectHit property
+ Returns the last object hit by this touch sensor. (B{deprecated})
@rtype: L{KX_GameObject}
"""
def getHitObjectList():
"""
- Returns a list of all objects hit in the last frame.
+ DEPRECATED: use the objectHitList property
+ Returns a list of all objects hit in the last frame. (B{deprecated})
Only objects that have the requisite material/property are listed.
@@ -38,13 +57,7 @@ class KX_TouchSensor(SCA_ISensor):
"""
def getTouchMaterial():
"""
+ DEPRECATED: use the useMaterial property
Returns KX_TRUE if this sensor looks for a specific material,
- KX_FALSE if it looks for a specific property.
- """
- def setTouchMaterial(flag):
- """
- Set flag to KX_TRUE to switch on positive pulse mode,
- KX_FALSE to switch off positive pulse mode.
-
- @type flag: KX_TRUE or KX_FALSE.
+ KX_FALSE if it looks for a specific property. (B{deprecated})
"""
diff --git a/source/gameengine/PyDoc/SCA_DelaySensor.py b/source/gameengine/PyDoc/SCA_DelaySensor.py
index b99ed08bed5..6560df6573e 100644
--- a/source/gameengine/PyDoc/SCA_DelaySensor.py
+++ b/source/gameengine/PyDoc/SCA_DelaySensor.py
@@ -20,10 +20,9 @@ class SCA_DelaySensor(SCA_ISensor):
@type delay: integer.
@ivar duration: length of the ON period in number of frame after the initial OFF period.
If duration is greater than 0, a negative trigger is sent at the end of the ON pulse.
- @type duration: integer
- @ivar repeat: 1 if the OFF-ON cycle should be repeated indefinately, 0 if it should run once.
- @type repeat: integer
-
+ @type duration: integer
+ @ivar repeat: 1 if the OFF-ON cycle should be repeated indefinately, 0 if it should run once.
+ @type repeat: integer
"""
def setDelay(delay):
"""
diff --git a/source/gameengine/PyDoc/SCA_PythonController.py b/source/gameengine/PyDoc/SCA_PythonController.py
index 06f2b7e9d1d..9684b41d481 100644
--- a/source/gameengine/PyDoc/SCA_PythonController.py
+++ b/source/gameengine/PyDoc/SCA_PythonController.py
@@ -15,7 +15,17 @@ class SCA_PythonController(SCA_IController):
This can be used with the GameObject's state to test if the controller is active.
@type state: integer
"""
-
+ def activate(actuator):
+ """
+ Activates an actuator attached to this controller.
+ @type actuator: actuator or the actuator name as a string
+ """
+ def deactivate(actuator):
+ """
+ Deactivates an actuator attached to this controller.
+ @type actuator: actuator or the actuator name as a string
+ """
+
def getSensors():
"""
Gets a list of all sensors attached to this controller.
diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
index fb3607f89f4..cd88112007b 100644
--- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
+++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
@@ -143,7 +143,7 @@ const STR_String& RAS_IPolyMaterial::GetTextureName() const
return m_texturename;
}
-const unsigned int RAS_IPolyMaterial::GetFlag() const
+unsigned int RAS_IPolyMaterial::GetFlag() const
{
return m_flag;
}
diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
index 218dd91cb30..e5b24070c4b 100644
--- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
+++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
@@ -138,7 +138,7 @@ public:
const STR_String& GetMaterialName() const;
dword GetMaterialNameHash() const;
const STR_String& GetTextureName() const;
- const unsigned int GetFlag() const;
+ unsigned int GetFlag() const;
virtual bool UsesLighting(RAS_IRasterizer *rasty) const;
virtual bool UsesObjectColor() const;
diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h
index d529ca8973a..83adcfd8321 100644
--- a/source/gameengine/Rasterizer/RAS_IRasterizer.h
+++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h
@@ -361,6 +361,8 @@ public:
virtual void SetPolygonOffset(float mult, float add) = 0;
virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)=0;
+ virtual void FlushDebugLines()=0;
+
virtual void SetTexCoordNum(int num) = 0;
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
index 08c600e7682..d4d1b73c772 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
@@ -327,13 +327,12 @@ void RAS_OpenGLRasterizer::ClearCachingInfo(void)
m_materialCachingInfo = 0;
}
-
-void RAS_OpenGLRasterizer::EndFrame()
+void RAS_OpenGLRasterizer::FlushDebugLines()
{
+//DrawDebugLines
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
- //DrawDebugLines
glBegin(GL_LINES);
for (unsigned int i=0;i<m_debugLines.size();i++)
{
@@ -348,8 +347,19 @@ void RAS_OpenGLRasterizer::EndFrame()
}
glEnd();
+ glEnable(GL_LIGHTING);
+ glEnable(GL_TEXTURE_2D);
+
m_debugLines.clear();
+}
+
+void RAS_OpenGLRasterizer::EndFrame()
+{
+
+
+ FlushDebugLines();
+
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
m_2DCanvas->EndFrame();
}
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
index c72d4880437..83a9f759a8b 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
@@ -240,6 +240,8 @@ public:
virtual void SetPolygonOffset(float mult, float add);
+ virtual void FlushDebugLines();
+
virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
{
OglDebugLine line;
diff --git a/source/gameengine/Rasterizer/RAS_TexVert.cpp b/source/gameengine/Rasterizer/RAS_TexVert.cpp
index b92965ed1cc..210addfb927 100644
--- a/source/gameengine/Rasterizer/RAS_TexVert.cpp
+++ b/source/gameengine/Rasterizer/RAS_TexVert.cpp
@@ -59,10 +59,10 @@ const MT_Point3& RAS_TexVert::xyz()
void RAS_TexVert::SetRGBA(const MT_Vector4& rgba)
{
unsigned char *colp = (unsigned char*) &m_rgba;
- colp[0] = (unsigned char) (rgba[0]*255.0);
- colp[1] = (unsigned char) (rgba[1]*255.0);
- colp[2] = (unsigned char) (rgba[2]*255.0);
- colp[3] = (unsigned char) (rgba[3]*255.0);
+ colp[0] = (unsigned char) (rgba[0]*255.0f);
+ colp[1] = (unsigned char) (rgba[1]*255.0f);
+ colp[2] = (unsigned char) (rgba[2]*255.0f);
+ colp[3] = (unsigned char) (rgba[3]*255.0f);
}
@@ -71,7 +71,10 @@ void RAS_TexVert::SetXYZ(const MT_Point3& xyz)
xyz.getValue(m_localxyz);
}
-
+void RAS_TexVert::SetXYZ(const float *xyz)
+{
+ m_localxyz[0]= xyz[0]; m_localxyz[1]= xyz[1]; m_localxyz[2]= xyz[2];
+}
void RAS_TexVert::SetUV(const MT_Point2& uv)
{
@@ -111,15 +114,18 @@ void RAS_TexVert::SetTangent(const MT_Vector3& tangent)
}
// compare two vertices, and return TRUE if both are almost identical (they can be shared)
+#define _VEC_EQUAL3(_v1, _v2) (_v1[0]==_v2[0] && _v1[1]==_v2[1] && _v1[2]==_v2[2])
+#define _VEC_EQUAL2(_v1, _v2) (_v1[0]==_v2[0] && _v1[1]==_v2[1])
bool RAS_TexVert::closeTo(const RAS_TexVert* other)
{
return (m_flag == other->m_flag &&
m_rgba == other->m_rgba &&
- MT_fuzzyEqual(MT_Vector3(m_normal), MT_Vector3(other->m_normal)) &&
- MT_fuzzyEqual(MT_Vector3(m_tangent), MT_Vector3(other->m_tangent)) &&
- MT_fuzzyEqual(MT_Vector2(m_uv1), MT_Vector2(other->m_uv1)) &&
- MT_fuzzyEqual(MT_Vector2(m_uv2), MT_Vector2(other->m_uv2)) && // p --
- MT_fuzzyEqual(MT_Vector3(m_localxyz), MT_Vector3(other->m_localxyz))) ;
+ _VEC_EQUAL3(m_normal, other->m_normal) &&
+ _VEC_EQUAL3(m_tangent, other->m_tangent) &&
+ _VEC_EQUAL2(m_uv1, other->m_uv1) &&
+ _VEC_EQUAL2(m_uv2, other->m_uv2) // p --
+ /* we know the verts must be shared so dont need to check this */
+ /*&& FAST_MT_fuzzyEqual3(m_localxyz, other->m_localxyz)*/) ;
}
short RAS_TexVert::getFlag() const
diff --git a/source/gameengine/Rasterizer/RAS_TexVert.h b/source/gameengine/Rasterizer/RAS_TexVert.h
index 54da109cbf1..811867f3579 100644
--- a/source/gameengine/Rasterizer/RAS_TexVert.h
+++ b/source/gameengine/Rasterizer/RAS_TexVert.h
@@ -110,11 +110,12 @@ public:
return (unsigned char *) &m_rgba;
}
- const unsigned int getOrigIndex() const {
+ unsigned int getOrigIndex() const {
return m_origindex;
}
void SetXYZ(const MT_Point3& xyz);
+ void SetXYZ(const float *xyz);
void SetUV(const MT_Point2& uv);
void SetUV2(const MT_Point2& uv);
diff --git a/source/gameengine/SConscript b/source/gameengine/SConscript
index e841f206eee..51a05e70a07 100644
--- a/source/gameengine/SConscript
+++ b/source/gameengine/SConscript
@@ -15,10 +15,12 @@ SConscript(['BlenderRoutines/SConscript',
'Rasterizer/RAS_OpenGLRasterizer/SConscript',
'SceneGraph/SConscript',
'Physics/Bullet/SConscript',
- 'Physics/Sumo/SConscript',
'VideoTexture/SConscript'
])
+if env['WITH_BF_SOLID']:
+ SConscript(['Physics/Sumo/SConscript'])
+
if env['WITH_BF_PLAYER']:
SConscript(['GamePlayer/SConscript'])
diff --git a/source/gameengine/SceneGraph/SG_BBox.cpp b/source/gameengine/SceneGraph/SG_BBox.cpp
index 4bd2805978e..a44262d04f7 100644
--- a/source/gameengine/SceneGraph/SG_BBox.cpp
+++ b/source/gameengine/SceneGraph/SG_BBox.cpp
@@ -34,8 +34,8 @@
#include "SG_Node.h"
SG_BBox::SG_BBox() :
- m_min(MT_Point3(0., 0., 0.)),
- m_max(MT_Point3(0., 0., 0.))
+ m_min(0., 0., 0.),
+ m_max(0., 0., 0.)
{
}
diff --git a/source/gameengine/SceneGraph/SG_Spatial.cpp b/source/gameengine/SceneGraph/SG_Spatial.cpp
index 5ba116e59db..99aeb3e72ee 100644
--- a/source/gameengine/SceneGraph/SG_Spatial.cpp
+++ b/source/gameengine/SceneGraph/SG_Spatial.cpp
@@ -44,13 +44,13 @@ SG_Spatial(
):
SG_IObject(clientobj,clientinfo,callbacks),
- m_localPosition(MT_Point3(0.0,0.0,0.0)),
- m_localRotation(MT_Matrix3x3(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0)),
- m_localScaling(MT_Vector3(1.f,1.f,1.f)),
+ m_localPosition(0.0,0.0,0.0),
+ m_localRotation(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),
+ m_localScaling(1.f,1.f,1.f),
- m_worldPosition(MT_Point3(0.0,0.0,0.0)),
- m_worldRotation(MT_Matrix3x3(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0)),
- m_worldScaling(MT_Vector3(1.f,1.f,1.f)),
+ m_worldPosition(0.0,0.0,0.0),
+ m_worldRotation(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),
+ m_worldScaling(1.f,1.f,1.f),
m_parent_relation (NULL),
@@ -297,6 +297,13 @@ GetWorldScaling(
return m_worldScaling;
}
+void SG_Spatial::SetWorldFromLocalTransform()
+{
+ m_worldPosition= m_localPosition;
+ m_worldScaling= m_localScaling;
+ m_worldRotation= m_localRotation;
+}
+
SG_BBox& SG_Spatial::BBox()
{
return m_bbox;
diff --git a/source/gameengine/SceneGraph/SG_Spatial.h b/source/gameengine/SceneGraph/SG_Spatial.h
index 28848b0f933..6ccec2aa9c1 100644
--- a/source/gameengine/SceneGraph/SG_Spatial.h
+++ b/source/gameengine/SceneGraph/SG_Spatial.h
@@ -176,6 +176,8 @@ public:
GetWorldScaling(
) const ;
+ void SetWorldFromLocalTransform();
+
MT_Transform GetWorldTransform() const;
bool ComputeWorldTransforms( const SG_Spatial *parent);
diff --git a/source/gameengine/VideoTexture/CMakeLists.txt b/source/gameengine/VideoTexture/CMakeLists.txt
index 1674602edd7..1fca5374991 100644
--- a/source/gameengine/VideoTexture/CMakeLists.txt
+++ b/source/gameengine/VideoTexture/CMakeLists.txt
@@ -52,7 +52,7 @@ SET(INC
)
IF(WITH_FFMPEG)
- SET(INC ${INC} ${FFMPEG_INC})
+ SET(INC ${INC} ${FFMPEG_INC} ${PTHREADS_INC})
ADD_DEFINITIONS(-DWITH_FFMPEG)
ADD_DEFINITIONS(-D__STDC_CONSTANT_MACROS)
ENDIF(WITH_FFMPEG)
diff --git a/source/gameengine/VideoTexture/FilterBase.cpp b/source/gameengine/VideoTexture/FilterBase.cpp
index b0112cd355b..b2abd4354fd 100644
--- a/source/gameengine/VideoTexture/FilterBase.cpp
+++ b/source/gameengine/VideoTexture/FilterBase.cpp
@@ -69,7 +69,7 @@ FilterBase * FilterBase::findFirst (void)
{
// find first filter in chain
FilterBase * frst;
- for (frst = this; frst->m_previous != NULL; frst = frst->m_previous->m_filter);
+ for (frst = this; frst->m_previous != NULL; frst = frst->m_previous->m_filter) {};
// set first filter
return frst;
}
diff --git a/source/gameengine/VideoTexture/FilterSource.h b/source/gameengine/VideoTexture/FilterSource.h
index 7e90747d252..6385ed5108f 100644
--- a/source/gameengine/VideoTexture/FilterSource.h
+++ b/source/gameengine/VideoTexture/FilterSource.h
@@ -189,9 +189,10 @@ protected:
int d = m_buffU[offset] - 128;
int e = m_buffV[offset] - 128;
// if horizontal interpolation is needed
- if ((x & 1) == 1)
+ if ((x & 1) == 1) {
// if vertical interpolation is needed too
if ((y & 1) == 1)
+ {
// if this pixel is on the edge
if (isEdge(x, y, size))
{
@@ -206,7 +207,8 @@ protected:
e = interpolVH(m_buffV + offset) - 128;
}
// otherwise use horizontal interpolation only
- else
+ }
+ else {
// if this pixel is on the edge
if (isEdge(x, y, size))
{
@@ -221,6 +223,8 @@ protected:
e = interpolH(m_buffV + offset) - 128;
}
// otherwise if only vertical interpolation is needed
+ }
+ }
else if ((y & 1) == 1)
// if this pixel is on the edge
if (isEdge(x, y, size))
diff --git a/source/gameengine/VideoTexture/Makefile b/source/gameengine/VideoTexture/Makefile
index bead176808b..a4611937a65 100644
--- a/source/gameengine/VideoTexture/Makefile
+++ b/source/gameengine/VideoTexture/Makefile
@@ -60,6 +60,9 @@ CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
ifeq ($(WITH_FFMPEG),true)
CPPFLAGS += -DWITH_FFMPEG
CPPFLAGS += $(NAN_FFMPEGCFLAGS)
+ ifdef NAN_PTHREADS
+ CPPFLAGS += -I$(NAN_PTHREADS)/include
+ endif
endif
diff --git a/source/gameengine/VideoTexture/SConscript b/source/gameengine/VideoTexture/SConscript
index 28737ed06e5..edd44f98783 100644
--- a/source/gameengine/VideoTexture/SConscript
+++ b/source/gameengine/VideoTexture/SConscript
@@ -27,7 +27,7 @@ incs += ' ' + env['BF_PYTHON_INC']
if env['WITH_BF_FFMPEG']:
defs += ' WITH_FFMPEG'
- incs += ' ' + env['BF_FFMPEG_INC']
+ incs += ' ' + env['BF_FFMPEG_INC'] + ' ' + env['BF_PTHREADS_INC']
defs += ' __STDC_CONSTANT_MACROS'
env.BlenderLib ( 'bf_videotex', sources, Split(incs), Split(defs), libtype=['game','player'], priority=[25, 72], cxx_compileflags = cxxflags )
diff --git a/source/gameengine/VideoTexture/VideoFFmpeg.cpp b/source/gameengine/VideoTexture/VideoFFmpeg.cpp
index 02798c7e596..5265b0ecb93 100644
--- a/source/gameengine/VideoTexture/VideoFFmpeg.cpp
+++ b/source/gameengine/VideoTexture/VideoFFmpeg.cpp
@@ -55,7 +55,8 @@ m_codec(NULL), m_formatCtx(NULL), m_codecCtx(NULL),
m_frame(NULL), m_frameDeinterlaced(NULL), m_frameRGB(NULL), m_imgConvertCtx(NULL),
m_deinterlace(false), m_preseek(0), m_videoStream(-1), m_baseFrameRate(25.0),
m_lastFrame(-1), m_eof(false), m_curPosition(-1), m_startTime(0),
-m_captWidth(0), m_captHeight(0), m_captRate(0.f), m_isImage(false)
+m_captWidth(0), m_captHeight(0), m_captRate(0.f), m_isImage(false),
+m_isThreaded(false), m_stopThread(false), m_cacheStarted(false)
{
// set video format
m_format = RGB24;
@@ -63,6 +64,12 @@ m_captWidth(0), m_captHeight(0), m_captRate(0.f), m_isImage(false)
setFlip(true);
// construction is OK
*hRslt = S_OK;
+ m_thread.first = m_thread.last = NULL;
+ pthread_mutex_init(&m_cacheMutex, NULL);
+ m_frameCacheFree.first = m_frameCacheFree.last = NULL;
+ m_frameCacheBase.first = m_frameCacheBase.last = NULL;
+ m_packetCacheFree.first = m_packetCacheFree.last = NULL;
+ m_packetCacheBase.first = m_packetCacheBase.last = NULL;
}
// destructor
@@ -75,6 +82,7 @@ VideoFFmpeg::~VideoFFmpeg ()
bool VideoFFmpeg::release()
{
// release
+ stopCache();
if (m_codecCtx)
{
avcodec_close(m_codecCtx);
@@ -112,6 +120,29 @@ bool VideoFFmpeg::release()
return true;
}
+AVFrame *VideoFFmpeg::allocFrameRGB()
+{
+ AVFrame *frame;
+ frame = avcodec_alloc_frame();
+ if (m_format == RGBA32)
+ {
+ avpicture_fill((AVPicture*)frame,
+ (uint8_t*)MEM_callocN(avpicture_get_size(
+ PIX_FMT_RGBA,
+ m_codecCtx->width, m_codecCtx->height),
+ "ffmpeg rgba"),
+ PIX_FMT_RGBA, m_codecCtx->width, m_codecCtx->height);
+ } else
+ {
+ avpicture_fill((AVPicture*)frame,
+ (uint8_t*)MEM_callocN(avpicture_get_size(
+ PIX_FMT_RGB24,
+ m_codecCtx->width, m_codecCtx->height),
+ "ffmpeg rgb"),
+ PIX_FMT_RGB24, m_codecCtx->width, m_codecCtx->height);
+ }
+ return frame;
+}
// set initial parameters
void VideoFFmpeg::initParams (short width, short height, float rate, bool image)
@@ -122,6 +153,7 @@ void VideoFFmpeg::initParams (short width, short height, float rate, bool image)
m_isImage = image;
}
+
int VideoFFmpeg::openStream(const char *filename, AVInputFormat *inputFormat, AVFormatParameters *formatParams)
{
AVFormatContext *formatCtx;
@@ -189,7 +221,6 @@ int VideoFFmpeg::openStream(const char *filename, AVInputFormat *inputFormat, AV
m_videoStream = videoStream;
m_frame = avcodec_alloc_frame();
m_frameDeinterlaced = avcodec_alloc_frame();
- m_frameRGB = avcodec_alloc_frame();
// allocate buffer if deinterlacing is required
avpicture_fill((AVPicture*)m_frameDeinterlaced,
@@ -207,12 +238,6 @@ int VideoFFmpeg::openStream(const char *filename, AVInputFormat *inputFormat, AV
{
// allocate buffer to store final decoded frame
m_format = RGBA32;
- avpicture_fill((AVPicture*)m_frameRGB,
- (uint8_t*)MEM_callocN(avpicture_get_size(
- PIX_FMT_RGBA,
- m_codecCtx->width, m_codecCtx->height),
- "ffmpeg rgba"),
- PIX_FMT_RGBA, m_codecCtx->width, m_codecCtx->height);
// allocate sws context
m_imgConvertCtx = sws_getContext(
m_codecCtx->width,
@@ -227,12 +252,6 @@ int VideoFFmpeg::openStream(const char *filename, AVInputFormat *inputFormat, AV
{
// allocate buffer to store final decoded frame
m_format = RGB24;
- avpicture_fill((AVPicture*)m_frameRGB,
- (uint8_t*)MEM_callocN(avpicture_get_size(
- PIX_FMT_RGB24,
- m_codecCtx->width, m_codecCtx->height),
- "ffmpeg rgb"),
- PIX_FMT_RGB24, m_codecCtx->width, m_codecCtx->height);
// allocate sws context
m_imgConvertCtx = sws_getContext(
m_codecCtx->width,
@@ -244,19 +263,247 @@ int VideoFFmpeg::openStream(const char *filename, AVInputFormat *inputFormat, AV
SWS_FAST_BILINEAR,
NULL, NULL, NULL);
}
+ m_frameRGB = allocFrameRGB();
+
if (!m_imgConvertCtx) {
avcodec_close(m_codecCtx);
+ m_codecCtx = NULL;
av_close_input_file(m_formatCtx);
+ m_formatCtx = NULL;
av_free(m_frame);
+ m_frame = NULL;
MEM_freeN(m_frameDeinterlaced->data[0]);
av_free(m_frameDeinterlaced);
+ m_frameDeinterlaced = NULL;
MEM_freeN(m_frameRGB->data[0]);
av_free(m_frameRGB);
+ m_frameRGB = NULL;
return -1;
}
return 0;
}
+/*
+ * This thread is used to load video frame asynchronously.
+ * It provides a frame caching service.
+ * The main thread is responsible for positionning the frame pointer in the
+ * file correctly before calling startCache() which starts this thread.
+ * The cache is organized in two layers: 1) a cache of 20-30 undecoded packets to keep
+ * memory and CPU low 2) a cache of 5 decoded frames.
+ * If the main thread does not find the frame in the cache (because the video has restarted
+ * or because the GE is lagging), it stops the cache with StopCache() (this is a synchronous
+ * function: it sends a signal to stop the cache thread and wait for confirmation), then
+ * change the position in the stream and restarts the cache thread.
+ */
+void *VideoFFmpeg::cacheThread(void *data)
+{
+ VideoFFmpeg* video = (VideoFFmpeg*)data;
+ // holds the frame that is being decoded
+ CacheFrame *currentFrame = NULL;
+ CachePacket *cachePacket;
+ bool endOfFile = false;
+ int frameFinished = 0;
+
+ while (!video->m_stopThread)
+ {
+ // packet cache is used solely by this thread, no need to lock
+ // In case the stream/file contains other stream than the one we are looking for,
+ // allow a bit of cycling to get rid quickly of those frames
+ frameFinished = 0;
+ while ( !endOfFile
+ && (cachePacket = (CachePacket *)video->m_packetCacheFree.first) != NULL
+ && frameFinished < 25)
+ {
+ // free packet => packet cache is not full yet, just read more
+ if (av_read_frame(video->m_formatCtx, &cachePacket->packet)>=0)
+ {
+ if (cachePacket->packet.stream_index == video->m_videoStream)
+ {
+ // make sure fresh memory is allocated for the packet and move it to queue
+ av_dup_packet(&cachePacket->packet);
+ BLI_remlink(&video->m_packetCacheFree, cachePacket);
+ BLI_addtail(&video->m_packetCacheBase, cachePacket);
+ break;
+ } else {
+ // this is not a good packet for us, just leave it on free queue
+ // Note: here we could handle sound packet
+ av_free_packet(&cachePacket->packet);
+ frameFinished++;
+ }
+
+ } else {
+ if (video->m_isFile)
+ // this mark the end of the file
+ endOfFile = true;
+ // if we cannot read a packet, no need to continue
+ break;
+ }
+ }
+ // frame cache is also used by main thread, lock
+ if (currentFrame == NULL)
+ {
+ // no current frame being decoded, take free one
+ pthread_mutex_lock(&video->m_cacheMutex);
+ if ((currentFrame = (CacheFrame *)video->m_frameCacheFree.first) != NULL)
+ BLI_remlink(&video->m_frameCacheFree, currentFrame);
+ pthread_mutex_unlock(&video->m_cacheMutex);
+ }
+ if (currentFrame != NULL)
+ {
+ // this frame is out of free and busy queue, we can manipulate it without locking
+ frameFinished = 0;
+ while (!frameFinished && (cachePacket = (CachePacket *)video->m_packetCacheBase.first) != NULL)
+ {
+ BLI_remlink(&video->m_packetCacheBase, cachePacket);
+ // use m_frame because when caching, it is not used in main thread
+ // we can't use currentFrame directly because we need to convert to RGB first
+ avcodec_decode_video(video->m_codecCtx,
+ video->m_frame, &frameFinished,
+ cachePacket->packet.data, cachePacket->packet.size);
+ if(frameFinished)
+ {
+ AVFrame * input = video->m_frame;
+
+ /* This means the data wasnt read properly, this check stops crashing */
+ if ( input->data[0]!=0 || input->data[1]!=0
+ || input->data[2]!=0 || input->data[3]!=0)
+ {
+ if (video->m_deinterlace)
+ {
+ if (avpicture_deinterlace(
+ (AVPicture*) video->m_frameDeinterlaced,
+ (const AVPicture*) video->m_frame,
+ video->m_codecCtx->pix_fmt,
+ video->m_codecCtx->width,
+ video->m_codecCtx->height) >= 0)
+ {
+ input = video->m_frameDeinterlaced;
+ }
+ }
+ // convert to RGB24
+ sws_scale(video->m_imgConvertCtx,
+ input->data,
+ input->linesize,
+ 0,
+ video->m_codecCtx->height,
+ currentFrame->frame->data,
+ currentFrame->frame->linesize);
+ // move frame to queue, this frame is necessarily the next one
+ currentFrame->framePosition = ++video->m_curPosition;
+ pthread_mutex_lock(&video->m_cacheMutex);
+ BLI_addtail(&video->m_frameCacheBase, currentFrame);
+ pthread_mutex_unlock(&video->m_cacheMutex);
+ currentFrame = NULL;
+ }
+ }
+ av_free_packet(&cachePacket->packet);
+ BLI_addtail(&video->m_packetCacheFree, cachePacket);
+ }
+ if (currentFrame && endOfFile)
+ {
+ // no more packet and end of file => put a special frame that indicates that
+ currentFrame->framePosition = -1;
+ pthread_mutex_lock(&video->m_cacheMutex);
+ BLI_addtail(&video->m_frameCacheBase, currentFrame);
+ pthread_mutex_unlock(&video->m_cacheMutex);
+ currentFrame = NULL;
+ // no need to stay any longer in this thread
+ break;
+ }
+ }
+ // small sleep to avoid unnecessary looping
+ PIL_sleep_ms(10);
+ }
+ // before quitting, put back the current frame to queue to allow freeing
+ if (currentFrame)
+ {
+ pthread_mutex_lock(&video->m_cacheMutex);
+ BLI_addtail(&video->m_frameCacheFree, currentFrame);
+ pthread_mutex_unlock(&video->m_cacheMutex);
+ }
+ return 0;
+}
+
+// start thread to cache video frame from file/capture/stream
+// this function should be called only when the position in the stream is set for the
+// first frame to cache
+bool VideoFFmpeg::startCache()
+{
+ if (!m_cacheStarted && m_isThreaded)
+ {
+ m_stopThread = false;
+ for (int i=0; i<CACHE_FRAME_SIZE; i++)
+ {
+ CacheFrame *frame = new CacheFrame();
+ frame->frame = allocFrameRGB();
+ BLI_addtail(&m_frameCacheFree, frame);
+ }
+ for (int i=0; i<CACHE_PACKET_SIZE; i++)
+ {
+ CachePacket *packet = new CachePacket();
+ BLI_addtail(&m_packetCacheFree, packet);
+ }
+ BLI_init_threads(&m_thread, cacheThread, 1);
+ BLI_insert_thread(&m_thread, this);
+ m_cacheStarted = true;
+ }
+ return m_cacheStarted;
+}
+
+void VideoFFmpeg::stopCache()
+{
+ if (m_cacheStarted)
+ {
+ m_stopThread = true;
+ BLI_end_threads(&m_thread);
+ // now delete the cache
+ CacheFrame *frame;
+ CachePacket *packet;
+ while ((frame = (CacheFrame *)m_frameCacheBase.first) != NULL)
+ {
+ BLI_remlink(&m_frameCacheBase, frame);
+ MEM_freeN(frame->frame->data[0]);
+ av_free(frame->frame);
+ delete frame;
+ }
+ while ((frame = (CacheFrame *)m_frameCacheFree.first) != NULL)
+ {
+ BLI_remlink(&m_frameCacheFree, frame);
+ MEM_freeN(frame->frame->data[0]);
+ av_free(frame->frame);
+ delete frame;
+ }
+ while((packet = (CachePacket *)m_packetCacheBase.first) != NULL)
+ {
+ BLI_remlink(&m_packetCacheBase, packet);
+ av_free_packet(&packet->packet);
+ delete packet;
+ }
+ while((packet = (CachePacket *)m_packetCacheFree.first) != NULL)
+ {
+ BLI_remlink(&m_packetCacheFree, packet);
+ delete packet;
+ }
+ m_cacheStarted = false;
+ }
+}
+
+void VideoFFmpeg::releaseFrame(AVFrame* frame)
+{
+ if (frame == m_frameRGB)
+ {
+ // this is not a frame from the cache, ignore
+ return;
+ }
+ // this frame MUST be the first one of the queue
+ pthread_mutex_lock(&m_cacheMutex);
+ CacheFrame *cacheFrame = (CacheFrame *)m_frameCacheBase.first;
+ assert (cacheFrame != NULL && cacheFrame->frame == frame);
+ BLI_remlink(&m_frameCacheBase, cacheFrame);
+ BLI_addtail(&m_frameCacheFree, cacheFrame);
+ pthread_mutex_unlock(&m_cacheMutex);
+}
+
// open video file
void VideoFFmpeg::openFile (char * filename)
{
@@ -280,8 +527,12 @@ void VideoFFmpeg::openFile (char * filename)
VideoBase::openFile(filename);
if (
+ // ffmpeg reports that http source are actually non stream
+ // but it is really not desirable to seek on http file, so force streaming.
+ // It would be good to find this information from the context but there are no simple indication
+ !strncmp(filename, "http://", 7) ||
#ifdef FFMPEG_PB_IS_POINTER
- m_formatCtx->pb && m_formatCtx->pb->is_streamed
+ (m_formatCtx->pb && m_formatCtx->pb->is_streamed)
#else
m_formatCtx->pb.is_streamed
#endif
@@ -304,7 +555,13 @@ void VideoFFmpeg::openFile (char * filename)
m_avail = false;
play();
}
-
+ // check if we should do multi-threading?
+ if (!m_isImage && BLI_system_thread_count() > 1)
+ {
+ // never thread image: there are no frame to read ahead
+ // no need to thread if the system has a single core
+ m_isThreaded = true;
+ }
}
@@ -385,6 +642,12 @@ void VideoFFmpeg::openCam (char * file, short camIdx)
m_formatCtx->flags |= AVFMT_FLAG_NONBLOCK;
// open base class
VideoBase::openCam(file, camIdx);
+ // check if we should do multi-threading?
+ if (BLI_system_thread_count() > 1)
+ {
+ // no need to thread if the system has a single core
+ m_isThreaded = true;
+ }
}
// play video
@@ -427,9 +690,12 @@ void VideoFFmpeg::setRange (double start, double stop)
try
{
// set range
- VideoBase::setRange(start, stop);
- // set range for video
- setPositions();
+ if (m_isFile)
+ {
+ VideoBase::setRange(start, stop);
+ // set range for video
+ setPositions();
+ }
}
CATCH_EXCP;
}
@@ -451,43 +717,61 @@ void VideoFFmpeg::calcImage (unsigned int texId)
// load frame from video
void VideoFFmpeg::loadFrame (void)
{
- // get actual time
- double actTime = PIL_check_seconds_timer() - m_startTime;
- // if video has ended
- if (m_isFile && actTime * m_frameRate >= m_range[1])
- {
- // if repeats are set, decrease them
- if (m_repeat > 0)
- --m_repeat;
- // if video has to be replayed
- if (m_repeat != 0)
- {
- // reset its position
- actTime -= (m_range[1] - m_range[0]) / m_frameRate;
- m_startTime += (m_range[1] - m_range[0]) / m_frameRate;
- }
- // if video has to be stopped, stop it
- else
- m_status = SourceStopped;
- }
- // if video is playing
if (m_status == SourcePlaying)
{
+ // get actual time
+ double startTime = PIL_check_seconds_timer();
+ double actTime = startTime - m_startTime;
+ // if video has ended
+ if (m_isFile && actTime * m_frameRate >= m_range[1])
+ {
+ // in any case, this resets the cache
+ stopCache();
+ // if repeats are set, decrease them
+ if (m_repeat > 0)
+ --m_repeat;
+ // if video has to be replayed
+ if (m_repeat != 0)
+ {
+ // reset its position
+ actTime -= (m_range[1] - m_range[0]) / m_frameRate;
+ m_startTime += (m_range[1] - m_range[0]) / m_frameRate;
+ }
+ // if video has to be stopped, stop it
+ else
+ {
+ m_status = SourceStopped;
+ return;
+ }
+ }
// actual frame
- long actFrame = m_isFile ? long(actTime * actFrameRate()) : m_lastFrame + 1;
+ long actFrame = (m_isImage) ? m_lastFrame+1 : long(actTime * actFrameRate());
// if actual frame differs from last frame
if (actFrame != m_lastFrame)
{
+ AVFrame* frame;
// get image
- if(grabFrame(actFrame))
+ if((frame = grabFrame(actFrame)) != NULL)
{
- AVFrame* frame = getFrame();
+ if (!m_isFile && !m_cacheStarted)
+ {
+ // streaming without cache: detect synchronization problem
+ double execTime = PIL_check_seconds_timer() - startTime;
+ if (execTime > 0.005)
+ {
+ // exec time is too long, it means that the function was blocking
+ // resynchronize the stream from this time
+ m_startTime += execTime;
+ }
+ }
// save actual frame
m_lastFrame = actFrame;
// init image, if needed
init(short(m_codecCtx->width), short(m_codecCtx->height));
// process image
process((BYTE*)(frame->data[0]));
+ // finished with the frame, release it so that cache can reuse it
+ releaseFrame(frame);
// in case it is an image, automatically stop reading it
if (m_isImage)
{
@@ -495,6 +779,12 @@ void VideoFFmpeg::loadFrame (void)
// close the file as we don't need it anymore
release();
}
+ } else if (!m_isFile)
+ {
+ // we didn't get a frame and we are streaming, this may be due to
+ // a delay in the network or because we are getting the frame too fast.
+ // In the later case, shift time by a small amount to compensate for a drift
+ m_startTime += 0.01;
}
}
}
@@ -507,77 +797,135 @@ void VideoFFmpeg::setPositions (void)
// set video start time
m_startTime = PIL_check_seconds_timer();
// if file is played and actual position is before end position
- if (m_isFile && !m_eof && m_lastFrame >= 0 && m_lastFrame < m_range[1] * actFrameRate())
+ if (!m_eof && m_lastFrame >= 0 && (!m_isFile || m_lastFrame < m_range[1] * actFrameRate()))
// continue from actual position
m_startTime -= double(m_lastFrame) / actFrameRate();
- else
+ else {
m_startTime -= m_range[0];
+ // start from begining, stop cache just in case
+ stopCache();
+ }
}
// position pointer in file, position in second
-bool VideoFFmpeg::grabFrame(long position)
+AVFrame *VideoFFmpeg::grabFrame(long position)
{
AVPacket packet;
int frameFinished;
int posFound = 1;
bool frameLoaded = false;
long long targetTs = 0;
+ CacheFrame *frame;
- // first check if the position that we are looking for is in the preseek range
- // if so, just read the frame until we get there
- if (position > m_curPosition + 1
- && m_preseek
- && position - (m_curPosition + 1) < m_preseek)
+ if (m_cacheStarted)
{
- while(av_read_frame(m_formatCtx, &packet)>=0)
+ // when cache is active, we must not read the file directly
+ do {
+ pthread_mutex_lock(&m_cacheMutex);
+ frame = (CacheFrame *)m_frameCacheBase.first;
+ pthread_mutex_unlock(&m_cacheMutex);
+ // no need to remove the frame from the queue: the cache thread does not touch the head, only the tail
+ if (frame == NULL)
+ {
+ // no frame in cache, in case of file it is an abnormal situation
+ if (m_isFile)
+ {
+ // go back to no threaded reading
+ stopCache();
+ break;
+ }
+ return NULL;
+ }
+ if (frame->framePosition == -1)
+ {
+ // this frame mark the end of the file (only used for file)
+ // leave in cache to make sure we don't miss it
+ m_eof = true;
+ return NULL;
+ }
+ // for streaming, always return the next frame,
+ // that's what grabFrame does in non cache mode anyway.
+ if (!m_isFile || frame->framePosition == position)
+ {
+ return frame->frame;
+ }
+ // this frame is not useful, release it
+ pthread_mutex_lock(&m_cacheMutex);
+ BLI_remlink(&m_frameCacheBase, frame);
+ BLI_addtail(&m_frameCacheFree, frame);
+ pthread_mutex_unlock(&m_cacheMutex);
+ } while (true);
+ }
+ // come here when there is no cache or cache has been stopped
+ // locate the frame, by seeking if necessary (seeking is only possible for files)
+ if (m_isFile)
+ {
+ // first check if the position that we are looking for is in the preseek range
+ // if so, just read the frame until we get there
+ if (position > m_curPosition + 1
+ && m_preseek
+ && position - (m_curPosition + 1) < m_preseek)
{
- if (packet.stream_index == m_videoStream)
+ while(av_read_frame(m_formatCtx, &packet)>=0)
{
- avcodec_decode_video(
- m_codecCtx,
- m_frame, &frameFinished,
- packet.data, packet.size);
- if (frameFinished)
- m_curPosition++;
+ if (packet.stream_index == m_videoStream)
+ {
+ avcodec_decode_video(
+ m_codecCtx,
+ m_frame, &frameFinished,
+ packet.data, packet.size);
+ if (frameFinished)
+ m_curPosition++;
+ }
+ av_free_packet(&packet);
+ if (position == m_curPosition+1)
+ break;
}
- av_free_packet(&packet);
- if (position == m_curPosition+1)
- break;
}
- }
- // if the position is not in preseek, do a direct jump
- if (position != m_curPosition + 1)
- {
- double timeBase = av_q2d(m_formatCtx->streams[m_videoStream]->time_base);
- long long pos = (long long)
- ((long long) (position - m_preseek) * AV_TIME_BASE / m_baseFrameRate);
- long long startTs = m_formatCtx->streams[m_videoStream]->start_time;
+ // if the position is not in preseek, do a direct jump
+ if (position != m_curPosition + 1)
+ {
+ double timeBase = av_q2d(m_formatCtx->streams[m_videoStream]->time_base);
+ long long pos = (long long)
+ ((long long) (position - m_preseek) * AV_TIME_BASE / m_baseFrameRate);
+ long long startTs = m_formatCtx->streams[m_videoStream]->start_time;
- if (pos < 0)
- pos = 0;
+ if (pos < 0)
+ pos = 0;
- if (startTs != AV_NOPTS_VALUE)
- pos += (long long)(startTs * AV_TIME_BASE * timeBase);
+ if (startTs != AV_NOPTS_VALUE)
+ pos += (long long)(startTs * AV_TIME_BASE * timeBase);
- if (position <= m_curPosition || !m_eof)
- {
- // no need to seek past the end of the file
- if (av_seek_frame(m_formatCtx, -1, pos, AVSEEK_FLAG_BACKWARD) >= 0)
+ if (position <= m_curPosition || !m_eof)
{
- // current position is now lost, guess a value.
- // It's not important because it will be set at this end of this function
- m_curPosition = position - m_preseek - 1;
+ // no need to seek past the end of the file
+ if (av_seek_frame(m_formatCtx, -1, pos, AVSEEK_FLAG_BACKWARD) >= 0)
+ {
+ // current position is now lost, guess a value.
+ // It's not important because it will be set at this end of this function
+ m_curPosition = position - m_preseek - 1;
+ }
}
- }
- // this is the timestamp of the frame we're looking for
- targetTs = (long long)(((double) position) / m_baseFrameRate / timeBase);
- if (startTs != AV_NOPTS_VALUE)
- targetTs += startTs;
+ // this is the timestamp of the frame we're looking for
+ targetTs = (long long)(((double) position) / m_baseFrameRate / timeBase);
+ if (startTs != AV_NOPTS_VALUE)
+ targetTs += startTs;
- posFound = 0;
- avcodec_flush_buffers(m_codecCtx);
+ posFound = 0;
+ avcodec_flush_buffers(m_codecCtx);
+ }
+ } else if (m_isThreaded)
+ {
+ // cache is not started but threading is possible
+ // better not read the stream => make take some time, better start caching
+ if (startCache())
+ return NULL;
+ // Abnormal!!! could not start cache, fall back on direct read
+ m_isThreaded = false;
}
+ // find the correct frame, in case of streaming and no cache, it means just
+ // return the next frame. This is not quite correct, may need more work
while(av_read_frame(m_formatCtx, &packet)>=0)
{
if(packet.stream_index == m_videoStream)
@@ -632,10 +980,22 @@ bool VideoFFmpeg::grabFrame(long position)
}
av_free_packet(&packet);
}
- m_eof = !frameLoaded;
+ m_eof = m_isFile && !frameLoaded;
if (frameLoaded)
+ {
m_curPosition = position;
- return frameLoaded;
+ if (m_isThreaded)
+ {
+ // normal case for file: first locate, then start cache
+ if (!startCache())
+ {
+ // Abnormal!! could not start cache, return to non-cache mode
+ m_isThreaded = false;
+ }
+ }
+ return m_frameRGB;
+ }
+ return NULL;
}
diff --git a/source/gameengine/VideoTexture/VideoFFmpeg.h b/source/gameengine/VideoTexture/VideoFFmpeg.h
index e60f1727aab..51ce2c4eebe 100644
--- a/source/gameengine/VideoTexture/VideoFFmpeg.h
+++ b/source/gameengine/VideoTexture/VideoFFmpeg.h
@@ -24,12 +24,17 @@ http://www.gnu.org/copyleft/lesser.txt.
#ifdef WITH_FFMPEG
extern "C" {
+#include <pthread.h>
#include <ffmpeg/avformat.h>
#include <ffmpeg/avcodec.h>
#include <ffmpeg/rational.h>
#include <ffmpeg/swscale.h>
+#include "DNA_listBase.h"
+#include "BLI_threads.h"
+#include "BLI_blenlib.h"
}
+
#if LIBAVFORMAT_VERSION_INT < (49 << 16)
#define FFMPEG_OLD_FRAME_RATE 1
#else
@@ -54,6 +59,8 @@ static inline AVCodecContext* get_codec_from_stream(AVStream* stream)
#include "VideoBase.h"
+#define CACHE_FRAME_SIZE 5
+#define CACHE_PACKET_SIZE 30
// type VideoFFmpeg declaration
class VideoFFmpeg : public VideoBase
@@ -91,7 +98,6 @@ public:
char *getImageName(void) { return (m_isImage) ? m_imageName.Ptr() : NULL; }
protected:
-
// format and codec information
AVCodec *m_codec;
AVFormatContext *m_formatCtx;
@@ -138,6 +144,9 @@ protected:
/// is file an image?
bool m_isImage;
+ /// is image loading done in a separate thread?
+ bool m_isThreaded;
+
/// keep last image name
STR_String m_imageName;
@@ -157,10 +166,37 @@ protected:
int openStream(const char *filename, AVInputFormat *inputFormat, AVFormatParameters *formatParams);
/// check if a frame is available and load it in pFrame, return true if a frame could be retrieved
- bool grabFrame(long frame);
-
- /// return the frame in RGB24 format, the image data is found in AVFrame.data[0]
- AVFrame* getFrame(void) { return m_frameRGB; }
+ AVFrame* grabFrame(long frame);
+
+ /// in case of caching, put the frame back in free queue
+ void releaseFrame(AVFrame* frame);
+
+ /// start thread to load the video file/capture/stream
+ bool startCache();
+ void stopCache();
+
+private:
+ typedef struct {
+ Link link;
+ long framePosition;
+ AVFrame *frame;
+ } CacheFrame;
+ typedef struct {
+ Link link;
+ AVPacket packet;
+ } CachePacket;
+
+ bool m_stopThread;
+ bool m_cacheStarted;
+ ListBase m_thread;
+ ListBase m_frameCacheBase; // list of frames that are ready
+ ListBase m_frameCacheFree; // list of frames that are unused
+ ListBase m_packetCacheBase; // list of packets that are ready for decoding
+ ListBase m_packetCacheFree; // list of packets that are unused
+ pthread_mutex_t m_cacheMutex;
+
+ AVFrame *allocFrameRGB();
+ static void *cacheThread(void *);
};
inline VideoFFmpeg * getFFmpeg (PyImage * self)