diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2011-09-07 19:34:04 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2011-09-07 19:34:04 +0400 |
commit | dbd6658d737b1592a633ddf6397be14e50e434d9 (patch) | |
tree | 57081721d70622a3c3141909b258f9bce8a5b1e3 /source/gameengine/Ketsji | |
parent | b5bd86e5907c3fa98546dabeda9703dfb15862f4 (diff) | |
parent | 884fc84793be1c5fdd6643ad267331381f8e1c6b (diff) |
svn merge -r 37306:39975 https://svn.blender.org/svnroot/bf-blender/trunk/blender
Diffstat (limited to 'source/gameengine/Ketsji')
42 files changed, 1789 insertions, 511 deletions
diff --git a/source/gameengine/Ketsji/BL_Action.cpp b/source/gameengine/Ketsji/BL_Action.cpp new file mode 100644 index 00000000000..08794042e37 --- /dev/null +++ b/source/gameengine/Ketsji/BL_Action.cpp @@ -0,0 +1,453 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Mitchell Stokes. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file BL_Action.cpp + * \ingroup ketsji + */ + +#include <cstdlib> + +#include "BL_Action.h" +#include "BL_ArmatureObject.h" +#include "BL_DeformableGameObject.h" +#include "BL_ShapeDeformer.h" +#include "KX_IpoConvert.h" +#include "KX_GameObject.h" + +// These three are for getting the action from the logic manager +#include "KX_Scene.h" +#include "KX_PythonInit.h" +#include "SCA_LogicManager.h" + +extern "C" { +#include "BKE_animsys.h" +#include "BKE_action.h" +#include "RNA_access.h" +#include "RNA_define.h" +} + +BL_Action::BL_Action(class KX_GameObject* gameobj) +: + m_action(NULL), + m_pose(NULL), + m_blendpose(NULL), + m_blendinpose(NULL), + m_ptrrna(NULL), + m_obj(gameobj), + m_startframe(0.f), + m_endframe(0.f), + m_endtime(0.f), + m_localtime(0.f), + m_blendin(0.f), + m_blendframe(0.f), + m_blendstart(0.f), + m_speed(0.f), + m_priority(0), + m_playmode(0), + m_ipo_flags(0), + m_done(true), + m_calc_localtime(true) +{ + if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) + { + BL_ArmatureObject *obj = (BL_ArmatureObject*)m_obj; + + m_ptrrna = new PointerRNA(); + RNA_id_pointer_create(&obj->GetArmatureObject()->id, m_ptrrna); + } + else + { + BL_DeformableGameObject *obj = (BL_DeformableGameObject*)m_obj; + BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); + + if (shape_deformer) + { + m_ptrrna = new PointerRNA(); + RNA_id_pointer_create(&shape_deformer->GetKey()->id, m_ptrrna); + } + } +} + +BL_Action::~BL_Action() +{ + if (m_pose) + game_free_pose(m_pose); + if (m_blendpose) + game_free_pose(m_blendpose); + if (m_blendinpose) + game_free_pose(m_blendinpose); + if (m_ptrrna) + delete m_ptrrna; + ClearControllerList(); +} + +void BL_Action::ClearControllerList() +{ + // Clear out the controller list + std::vector<SG_Controller*>::iterator it; + for (it = m_sg_contr_list.begin(); it != m_sg_contr_list.end(); it++) + { + m_obj->GetSGNode()->RemoveSGController((*it)); + delete *it; + } + + m_sg_contr_list.clear(); +} + +bool BL_Action::Play(const char* name, + float start, + float end, + short priority, + float blendin, + short play_mode, + float layer_weight, + short ipo_flags, + float playback_speed) +{ + + // Only start playing a new action if we're done, or if + // the new action has a higher priority + if (priority != 0 && !IsDone() && priority >= m_priority) + return false; + m_priority = priority; + bAction* prev_action = m_action; + + // First try to load the action + m_action = (bAction*)KX_GetActiveScene()->GetLogicManager()->GetActionByName(name); + if (!m_action) + { + printf("Failed to load action: %s\n", name); + m_done = true; + return false; + } + + if (prev_action != m_action) + { + // First get rid of any old controllers + ClearControllerList(); + + // Create an SG_Controller + SG_Controller *sg_contr = BL_CreateIPO(m_action, m_obj, KX_GetActiveScene()->GetSceneConverter()); + m_sg_contr_list.push_back(sg_contr); + m_obj->GetSGNode()->AddSGController(sg_contr); + sg_contr->SetObject(m_obj->GetSGNode()); + + // Extra controllers + if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_LIGHT) + { + sg_contr = BL_CreateLampIPO(m_action, m_obj, KX_GetActiveScene()->GetSceneConverter()); + m_sg_contr_list.push_back(sg_contr); + m_obj->GetSGNode()->AddSGController(sg_contr); + sg_contr->SetObject(m_obj->GetSGNode()); + } + else if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_CAMERA) + { + sg_contr = BL_CreateCameraIPO(m_action, m_obj, KX_GetActiveScene()->GetSceneConverter()); + m_sg_contr_list.push_back(sg_contr); + m_obj->GetSGNode()->AddSGController(sg_contr); + sg_contr->SetObject(m_obj->GetSGNode()); + } + } + + m_ipo_flags = ipo_flags; + InitIPO(); + + // Setup blendin shapes/poses + if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) + { + BL_ArmatureObject *obj = (BL_ArmatureObject*)m_obj; + obj->GetMRDPose(&m_blendinpose); + } + else + { + BL_DeformableGameObject *obj = (BL_DeformableGameObject*)m_obj; + BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); + + if (shape_deformer && shape_deformer->GetKey()) + { + obj->GetShape(m_blendinshape); + + // Now that we have the previous blend shape saved, we can clear out the key to avoid any + // further interference. + KeyBlock *kb; + for (kb=(KeyBlock*)shape_deformer->GetKey()->block.first; kb; kb=(KeyBlock*)kb->next) + kb->curval = 0.f; + } + } + + // Now that we have an action, we have something we can play + m_starttime = KX_GetActiveEngine()->GetFrameTime(); + m_startframe = m_localtime = start; + m_endframe = end; + m_blendin = blendin; + m_playmode = play_mode; + m_endtime = 0.f; + m_blendframe = 0.f; + m_blendstart = 0.f; + m_speed = playback_speed; + m_layer_weight = layer_weight; + + m_done = false; + + return true; +} + +void BL_Action::Stop() +{ + m_done = true; +} + +bool BL_Action::IsDone() +{ + return m_done; +} + +void BL_Action::InitIPO() +{ + // Initialize the IPOs + std::vector<SG_Controller*>::iterator it; + for (it = m_sg_contr_list.begin(); it != m_sg_contr_list.end(); it++) + { + (*it)->SetOption(SG_Controller::SG_CONTR_IPO_RESET, true); + (*it)->SetOption(SG_Controller::SG_CONTR_IPO_IPO_AS_FORCE, m_ipo_flags & ACT_IPOFLAG_FORCE); + (*it)->SetOption(SG_Controller::SG_CONTR_IPO_IPO_ADD, m_ipo_flags & ACT_IPOFLAG_ADD); + (*it)->SetOption(SG_Controller::SG_CONTR_IPO_LOCAL, m_ipo_flags & ACT_IPOFLAG_LOCAL); + } +} + +bAction *BL_Action::GetAction() +{ + return (IsDone()) ? NULL : m_action; +} + +float BL_Action::GetFrame() +{ + return m_localtime; +} + +void BL_Action::SetFrame(float frame) +{ + // Clamp the frame to the start and end frame + if (frame < min(m_startframe, m_endframe)) + frame = min(m_startframe, m_endframe); + else if (frame > max(m_startframe, m_endframe)) + frame = max(m_startframe, m_endframe); + + m_localtime = frame; + m_calc_localtime = false; +} + +void BL_Action::SetPlayMode(short play_mode) +{ + m_playmode = play_mode; +} + +void BL_Action::SetTimes(float start, float end) +{ + m_startframe = start; + m_endframe = end; +} + +void BL_Action::SetLocalTime(float curtime) +{ + float dt = (curtime-m_starttime)*KX_KetsjiEngine::GetAnimFrameRate()*m_speed; + + if (m_endframe < m_startframe) + dt = -dt; + + m_localtime = m_startframe + dt; +} + +void BL_Action::ResetStartTime(float curtime) +{ + float dt = m_localtime - m_startframe; + + m_starttime = curtime - dt / (KX_KetsjiEngine::GetAnimFrameRate()*m_speed); + SetLocalTime(curtime); +} + +void BL_Action::IncrementBlending(float curtime) +{ + // Setup m_blendstart if we need to + if (m_blendstart == 0.f) + m_blendstart = curtime; + + // Bump the blend frame + m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate(); + + // Clamp + if (m_blendframe>m_blendin) + m_blendframe = m_blendin; +} + + +void BL_Action::BlendShape(Key* key, float srcweight, std::vector<float>& blendshape) +{ + vector<float>::const_iterator it; + float dstweight; + KeyBlock *kb; + + dstweight = 1.0F - srcweight; + //printf("Dst: %f\tSrc: %f\n", srcweight, dstweight); + for (it=blendshape.begin(), kb = (KeyBlock*)key->block.first; + kb && it != blendshape.end(); + kb = (KeyBlock*)kb->next, it++) { + //printf("OirgKeys: %f\t%f\n", kb->curval, (*it)); + kb->curval = kb->curval * dstweight + (*it) * srcweight; + //printf("NewKey: %f\n", kb->curval); + } + //printf("\n"); +} + +void BL_Action::Update(float curtime) +{ + // Don't bother if we're done with the animation + if (m_done) + return; + + curtime -= KX_KetsjiEngine::GetSuspendedDelta(); + + if (m_calc_localtime) + SetLocalTime(curtime); + else + { + ResetStartTime(curtime); + m_calc_localtime = true; + } + + // Handle wrap around + if (m_localtime < min(m_startframe, m_endframe) || m_localtime > max(m_startframe, m_endframe)) + { + switch(m_playmode) + { + case ACT_MODE_PLAY: + // Clamp + m_localtime = m_endframe; + m_done = true; + break; + case ACT_MODE_LOOP: + // Put the time back to the beginning + m_localtime = m_startframe; + m_starttime = curtime; + break; + case ACT_MODE_PING_PONG: + // Swap the start and end frames + float temp = m_startframe; + m_startframe = m_endframe; + m_endframe = temp; + + m_starttime = curtime; + + break; + } + + if (!m_done) + InitIPO(); + } + + if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) + { + BL_ArmatureObject *obj = (BL_ArmatureObject*)m_obj; + obj->GetPose(&m_pose); + + // Extract the pose from the action + { + Object *arm = obj->GetArmatureObject(); + bPose *temp = arm->pose; + + arm->pose = m_pose; + animsys_evaluate_action(m_ptrrna, m_action, NULL, m_localtime); + + arm->pose = temp; + } + + // Handle blending between armature actions + if (m_blendin && m_blendframe<m_blendin) + { + IncrementBlending(curtime); + + // Calculate weight + float weight = 1.f - (m_blendframe/m_blendin); + + // Blend the poses + game_blend_poses(m_pose, m_blendinpose, weight); + } + + + // Handle layer blending + if (m_layer_weight >= 0) + { + obj->GetMRDPose(&m_blendpose); + game_blend_poses(m_pose, m_blendpose, m_layer_weight); + } + + obj->SetPose(m_pose); + + obj->SetActiveAction(NULL, 0, curtime); + } + else + { + BL_DeformableGameObject *obj = (BL_DeformableGameObject*)m_obj; + BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer()); + + // Handle shape actions if we have any + if (shape_deformer && shape_deformer->GetKey()) + { + Key *key = shape_deformer->GetKey(); + + + animsys_evaluate_action(m_ptrrna, m_action, NULL, m_localtime); + + // Handle blending between shape actions + if (m_blendin && m_blendframe < m_blendin) + { + IncrementBlending(curtime); + + float weight = 1.f - (m_blendframe/m_blendin); + + // We go through and clear out the keyblocks so there isn't any interference + // from other shape actions + KeyBlock *kb; + for (kb=(KeyBlock*)key->block.first; kb; kb=(KeyBlock*)kb->next) + kb->curval = 0.f; + + // Now blend the shape + BlendShape(key, weight, m_blendinshape); + } + + // Handle layer blending + if (m_layer_weight >= 0) + { + obj->GetShape(m_blendshape); + BlendShape(key, m_layer_weight, m_blendshape); + } + + obj->SetActiveAction(NULL, 0, curtime); + } + + + InitIPO(); + m_obj->UpdateIPO(m_localtime, m_ipo_flags & ACT_IPOFLAG_CHILD); + } +} diff --git a/source/gameengine/Ketsji/BL_Action.h b/source/gameengine/Ketsji/BL_Action.h new file mode 100644 index 00000000000..92fbe95fd54 --- /dev/null +++ b/source/gameengine/Ketsji/BL_Action.h @@ -0,0 +1,144 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Mitchell Stokes. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file BL_Action.h + * \ingroup ketsji + */ + +#ifndef __BL_ACTION +#define __BL_ACTION + + +#include <vector> + +#ifdef WITH_CXX_GUARDEDALLOC +#include "MEM_guardedalloc.h" +#endif + + +class BL_Action +{ +private: + struct bAction* m_action; + struct bPose* m_pose; + struct bPose* m_blendpose; + struct bPose* m_blendinpose; + struct PointerRNA *m_ptrrna; + std::vector<class SG_Controller*> m_sg_contr_list; + class KX_GameObject* m_obj; + std::vector<float> m_blendshape; + std::vector<float> m_blendinshape; + + float m_startframe; + float m_endframe; + float m_starttime; + float m_endtime; + float m_localtime; + + float m_blendin; + float m_blendframe; + float m_blendstart; + + float m_layer_weight; + + float m_speed; + + short m_priority; + + short m_playmode; + + short m_ipo_flags; + + bool m_done; + bool m_calc_localtime; + + void ClearControllerList(); + void InitIPO(); + void SetLocalTime(float curtime); + void ResetStartTime(float curtime); + void IncrementBlending(float curtime); + void BlendShape(struct Key* key, float srcweight, std::vector<float>& blendshape); +public: + BL_Action(class KX_GameObject* gameobj); + ~BL_Action(); + + /** + * Play an action + */ + bool Play(const char* name, + float start, + float end, + short priority, + float blendin, + short play_mode, + float layer_weight, + short ipo_flags, + float playback_speed); + /** + * Stop playing the action + */ + void Stop(); + /** + * Whether or not the action is still playing + */ + bool IsDone(); + /** + * Update the action's frame, etc. + */ + void Update(float curtime); + + // Accessors + float GetFrame(); + struct bAction *GetAction(); + + // Mutators + void SetFrame(float frame); + void SetPlayMode(short play_mode); + void SetTimes(float start, float end); + + enum + { + ACT_MODE_PLAY = 0, + ACT_MODE_LOOP, + ACT_MODE_PING_PONG, + ACT_MODE_MAX, + }; + + enum + { + ACT_IPOFLAG_FORCE = 1, + ACT_IPOFLAG_LOCAL = 2, + ACT_IPOFLAG_ADD = 4, + ACT_IPOFLAG_CHILD = 8, + }; + +#ifdef WITH_CXX_GUARDEDALLOC +public: + void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:BL_Action"); } + void operator delete( void *mem ) { MEM_freeN(mem); } +#endif +}; + +#endif //BL_ACTION + diff --git a/source/gameengine/Ketsji/BL_ActionManager.cpp b/source/gameengine/Ketsji/BL_ActionManager.cpp new file mode 100644 index 00000000000..4e4d3bc539e --- /dev/null +++ b/source/gameengine/Ketsji/BL_ActionManager.cpp @@ -0,0 +1,110 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Mitchell Stokes. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file BL_ActionManager.cpp + * \ingroup ketsji + */ + +#include "BL_ActionManager.h" + +BL_ActionManager::BL_ActionManager(class KX_GameObject *obj) +{ + for (int i=0; i<MAX_ACTION_LAYERS; ++i) + m_layers[i] = new BL_Action(obj); +} + +BL_ActionManager::~BL_ActionManager() +{ + for (int i=0; i<MAX_ACTION_LAYERS; ++i) + delete m_layers[i]; +} + +float BL_ActionManager::GetActionFrame(short layer) +{ + return m_layers[layer]->GetFrame(); + + return 0.f; +} + +void BL_ActionManager::SetActionFrame(short layer, float frame) +{ + m_layers[layer]->SetFrame(frame); +} + +struct bAction *BL_ActionManager::GetCurrentAction(short layer) +{ + return m_layers[layer]->GetAction(); + + return 0; +} + +void BL_ActionManager::SetPlayMode(short layer, short mode) +{ + m_layers[layer]->SetPlayMode(mode); +} + +void BL_ActionManager::SetTimes(short layer, float start, float end) +{ + m_layers[layer]->SetTimes(start, end); +} + +bool BL_ActionManager::PlayAction(const char* name, + float start, + float end, + short layer, + short priority, + float blendin, + short play_mode, + float layer_weight, + short ipo_flags, + float playback_speed) +{ + // Disable layer blending on the first layer + if (layer == 0) layer_weight = -1.f; + + return m_layers[layer]->Play(name, start, end, priority, blendin, play_mode, layer_weight, ipo_flags, playback_speed); +} + +void BL_ActionManager::StopAction(short layer) +{ + m_layers[layer]->Stop(); +} + +bool BL_ActionManager::IsActionDone(short layer) +{ + return m_layers[layer]->IsDone(); + + return true; +} + +void BL_ActionManager::Update(float curtime) +{ + for (int i=0; i<MAX_ACTION_LAYERS; ++i) + { + if (!m_layers[i]->IsDone()) + { + m_layers[i]->Update(curtime); + } + } +} diff --git a/source/gameengine/Ketsji/BL_ActionManager.h b/source/gameengine/Ketsji/BL_ActionManager.h new file mode 100644 index 00000000000..a3c8379981e --- /dev/null +++ b/source/gameengine/Ketsji/BL_ActionManager.h @@ -0,0 +1,106 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Mitchell Stokes. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file BL_ActionManager.cpp + * \ingroup ketsji + */ + +#ifndef __BL_ACTIONMANAGER +#define __BL_ACTIONMANAGER + +#include "BL_Action.h" + +#define MAX_ACTION_LAYERS 8 + +/** + * BL_ActionManager is responsible for handling a KX_GameObject's actions. + */ +class BL_ActionManager +{ +private: + BL_Action* m_layers[MAX_ACTION_LAYERS]; + +public: + BL_ActionManager(class KX_GameObject* obj); + ~BL_ActionManager(); + + bool PlayAction(const char* name, + float start, + float end, + short layer=0, + short priority=0, + float blendin=0.f, + short play_mode=0, + float layer_weight=0.f, + short ipo_flags=0, + float playback_speed=1.f); + /** + * Gets the current frame of an action + */ + float GetActionFrame(short layer); + + /** + * Sets the current frame of an action + */ + void SetActionFrame(short layer, float frame); + + /** + * Gets the currently running action on the given layer + */ + struct bAction *GetCurrentAction(short layer); + + /** + * Sets play mode of the action on the given layer + */ + void SetPlayMode(short layer, short mode); + + /** + * Sets the start and end times of the action on the given layer + */ + void SetTimes(short layer, float start, float end); + + /** + * Stop playing the action on the given layer + */ + void StopAction(short layer); + + /** + * Check if an action has finished playing + */ + bool IsActionDone(short layer); + + /** + * Update any running actions + */ + void Update(float); + +#ifdef WITH_CXX_GUARDEDALLOC +public: + void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:BL_ActionManager"); } + void operator delete( void *mem ) { MEM_freeN(mem); } +#endif +}; + +#endif //BL_ACTIONMANAGER + diff --git a/source/gameengine/Ketsji/BL_BlenderShader.cpp b/source/gameengine/Ketsji/BL_BlenderShader.cpp index 91982a424c7..4ae937cdcd6 100644 --- a/source/gameengine/Ketsji/BL_BlenderShader.cpp +++ b/source/gameengine/Ketsji/BL_BlenderShader.cpp @@ -63,7 +63,7 @@ int BL_BlenderShader::GetAttribNum() GPU_material_vertex_attributes(mGPUMat, &attribs); - for(i = 0; i < attribs.totlayer; i++) + for(i = 0; i < attribs.totlayer; i++) if(attribs.layer[i].glindex+1 > enabled) enabled= attribs.layer[i].glindex+1; diff --git a/source/gameengine/Ketsji/BL_Material.h b/source/gameengine/Ketsji/BL_Material.h index ef25c9218a3..c0440e66501 100644 --- a/source/gameengine/Ketsji/BL_Material.h +++ b/source/gameengine/Ketsji/BL_Material.h @@ -157,7 +157,8 @@ enum BL_ras_mode ALPHA=8, // TRIANGLE=16, USE_LIGHT=32, - WIRE=64 + WIRE=64, + CAST_SHADOW=128 }; // ------------------------------------- diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp index 621cabfe0cf..aea33246a3f 100644 --- a/source/gameengine/Ketsji/BL_Shader.cpp +++ b/source/gameengine/Ketsji/BL_Shader.cpp @@ -690,7 +690,7 @@ void BL_Shader::SetUniform(int uniform, const MT_Matrix3x3& vec, bool transpose) float value[9]; value[0] = (float)vec[0][0]; value[1] = (float)vec[1][0]; value[2] = (float)vec[2][0]; value[3] = (float)vec[0][1]; value[4] = (float)vec[1][1]; value[5] = (float)vec[2][1]; - value[6] = (float)vec[0][2]; value[7] = (float)vec[1][2]; value[7] = (float)vec[2][2]; + value[6] = (float)vec[0][2]; value[7] = (float)vec[1][2]; value[8] = (float)vec[2][2]; glUniformMatrix3fvARB(uniform, 1, transpose?GL_TRUE:GL_FALSE, value); } } diff --git a/source/gameengine/Ketsji/BL_Texture.cpp b/source/gameengine/Ketsji/BL_Texture.cpp index d2438a66367..a306e059442 100644 --- a/source/gameengine/Ketsji/BL_Texture.cpp +++ b/source/gameengine/Ketsji/BL_Texture.cpp @@ -28,6 +28,7 @@ #define spit(x) std::cout << x << std::endl; #include "MEM_guardedalloc.h" +#include "GPU_draw.h" extern "C" { // envmaps @@ -175,6 +176,8 @@ void BL_Texture::InitGLTex(unsigned int *pix,int x,int y,bool mipmap) glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, pix ); } + if (GLEW_EXT_texture_filter_anisotropic) + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic()); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } @@ -199,6 +202,9 @@ void BL_Texture::InitNonPow2Tex(unsigned int *pix,int x,int y,bool mipmap) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, nx, ny, 0, GL_RGBA, GL_UNSIGNED_BYTE, newPixels ); } + + if (GLEW_EXT_texture_filter_anisotropic) + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic()); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); free(newPixels); } diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index b32fd9e7a44..6846da5b019 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -26,33 +26,33 @@ set(INC . - ../../../intern/string - ../../../intern/guardedalloc + KXNetwork + ../BlenderRoutines + ../Converter + ../Expressions + ../GameLogic + ../Network + ../Network/LoopBackNetwork + ../Physics/common + ../Rasterizer + ../Rasterizer/RAS_OpenGLRasterizer + ../SceneGraph + ../../blender + ../../blender/blenfont + ../../blender/blenkernel + ../../blender/blenlib + ../../blender/blenloader + ../../blender/gpu + ../../blender/imbuf + ../../blender/makesdna + ../../blender/makesrna + ../../blender/python + ../../blender/python/generic + ../../blender/python/mathutils ../../../intern/container - ../../../source/gameengine/Rasterizer/RAS_OpenGLRasterizer - ../../../source/gameengine/Converter - ../../../source/gameengine/BlenderRoutines - ../../../source/blender/imbuf + ../../../intern/guardedalloc ../../../intern/moto/include - ../../../source/gameengine/Ketsji - ../../../source/blender/blenlib - ../../../source/blender/blenfont - ../../../source/blender/blenkernel - ../../../source/blender/python - ../../../source/blender/python/generic - ../../../source/blender - ../../../source/blender/makesdna - ../../../source/gameengine/Rasterizer - ../../../source/gameengine/GameLogic - ../../../source/gameengine/Expressions - ../../../source/gameengine/Ketsji/KXNetwork - ../../../source/gameengine/Network - ../../../source/gameengine/SceneGraph - ../../../source/gameengine/Physics/common - ../../../source/gameengine/Network/LoopBackNetwork - ../../../intern/audaspace/intern - ../../../source/blender/blenloader - ../../../source/blender/gpu + ../../../intern/string ) set(INC_SYS @@ -63,6 +63,8 @@ set(INC_SYS ) set(SRC + BL_Action.cpp + BL_ActionManager.cpp BL_BlenderShader.cpp BL_Material.cpp BL_Shader.cpp @@ -135,6 +137,12 @@ set(SRC KX_WorldInfo.cpp KX_WorldIpoController.cpp + BL_Action.h + BL_ActionManager.h + BL_BlenderShader.h + BL_Material.h + BL_Shader.h + BL_Texture.h KX_ArmatureSensor.h KX_BlenderMaterial.h KX_BulletPhysicsController.h @@ -210,16 +218,14 @@ set(SRC KX_VisibilityActuator.h KX_WorldInfo.h KX_WorldIpoController.h - BL_BlenderShader.h - BL_Material.h - BL_Shader.h - BL_Texture.h ) add_definitions(-DGLEW_STATIC) if(WITH_SDL) - list(APPEND INC_SYS ${SDL_INCLUDE_DIR}) + list(APPEND INC_SYS + ${SDL_INCLUDE_DIR} + ) else() add_definitions(-DDISABLE_SDL) endif() @@ -228,10 +234,18 @@ if(WITH_CODEC_FFMPEG) add_definitions(-DWITH_FFMPEG) endif() +if(WITH_AUDASPACE) + list(APPEND INC + ../../../intern/audaspace/intern + ../../../intern/audaspace/FX + ) + add_definitions(-DWITH_AUDASPACE) +endif() + if(WITH_BULLET) list(APPEND INC ../../../extern/bullet2/src - ../../../source/gameengine/Physics/Bullet + ../Physics/Bullet ) add_definitions(-DUSE_BULLET) endif() diff --git a/source/gameengine/Ketsji/KXNetwork/CMakeLists.txt b/source/gameengine/Ketsji/KXNetwork/CMakeLists.txt index b8149566801..1ebf1153150 100644 --- a/source/gameengine/Ketsji/KXNetwork/CMakeLists.txt +++ b/source/gameengine/Ketsji/KXNetwork/CMakeLists.txt @@ -26,14 +26,14 @@ set(INC . - ../../../../intern/string + .. + ../../Expressions + ../../GameLogic + ../../Network + ../../SceneGraph ../../../../intern/container ../../../../intern/moto/include - ../../../../source/gameengine/Ketsji - ../../../../source/gameengine/GameLogic - ../../../../source/gameengine/Expressions - ../../../../source/gameengine/SceneGraph - ../../../../source/gameengine/Network + ../../../../intern/string ) set(INC_SYS diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp index e8e65371d3a..72f1cee8855 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp @@ -66,8 +66,8 @@ void KX_NetworkEventManager::NextFrame() for (it.begin();!it.end();++it) { // printf("KX_NetworkEventManager::proceed sensor %.2f\n", curtime); - // process queue - (*it)->Activate(m_logicmgr); + // process queue + (*it)->Activate(m_logicmgr); } // now a list of triggerer sensors has been built diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h index ff9131f464e..405e2d52989 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h @@ -43,7 +43,7 @@ class KX_NetworkEventManager : public SCA_EventManager public: KX_NetworkEventManager(class SCA_LogicManager* logicmgr, - class NG_NetworkDeviceInterface *ndi); + class NG_NetworkDeviceInterface *ndi); virtual ~KX_NetworkEventManager (); virtual void NextFrame(); @@ -51,7 +51,7 @@ public: SCA_LogicManager* GetLogicManager() { return m_logicmgr; } class NG_NetworkDeviceInterface* GetNetworkDevice() { - return m_ndi; } + return m_ndi; } }; #endif //KX_NETWORK_EVENTMANAGER_H diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp index 2e0abc0290c..9fd09506c0d 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp @@ -91,8 +91,7 @@ bool KX_NetworkMessageActuator::Update() CValue* KX_NetworkMessageActuator::GetReplica() { - KX_NetworkMessageActuator* replica = - new KX_NetworkMessageActuator(*this); + KX_NetworkMessageActuator* replica = new KX_NetworkMessageActuator(*this); replica->ProcessReplica(); return replica; diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp index 6dcf50fa18f..a795a4eddc6 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp @@ -50,11 +50,11 @@ #endif KX_NetworkMessageSensor::KX_NetworkMessageSensor( - class KX_NetworkEventManager* eventmgr, // our eventmanager - class NG_NetworkScene *NetworkScene, // our scene - SCA_IObject* gameobj, // the sensor controlling object - const STR_String &subject -) : + class KX_NetworkEventManager* eventmgr, // our eventmanager + class NG_NetworkScene *NetworkScene, // our scene + SCA_IObject* gameobj, // the sensor controlling object + const STR_String &subject + ) : SCA_ISensor(gameobj,eventmgr), m_NetworkScene(NetworkScene), m_subject(subject), @@ -67,7 +67,7 @@ KX_NetworkMessageSensor::KX_NetworkMessageSensor( void KX_NetworkMessageSensor::Init() { - m_IsUp = false; + m_IsUp = false; } KX_NetworkMessageSensor::~KX_NetworkMessageSensor() diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 9ff32ba57c5..33da17cc505 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -56,21 +56,21 @@ KX_BlenderMaterial::KX_BlenderMaterial() } void KX_BlenderMaterial::Initialize( - KX_Scene *scene, - BL_Material *data) + KX_Scene *scene, + BL_Material *data) { RAS_IPolyMaterial::Initialize( - data->texname[0], - data->matname, - data->materialindex, - data->tile, - data->tilexrep[0], - data->tileyrep[0], - data->mode, - data->transp, - ((data->ras_mode &ALPHA)!=0), - ((data->ras_mode &ZSORT)!=0) - ); + data->texname[0], + data->matname, + data->materialindex, + data->tile, + data->tilexrep[0], + data->tileyrep[0], + data->mode, + data->transp, + ((data->ras_mode &ALPHA)!=0), + ((data->ras_mode &ZSORT)!=0) + ); mMaterial = data; mShader = 0; mBlenderShader = 0; @@ -80,11 +80,12 @@ void KX_BlenderMaterial::Initialize( mConstructed = false; mPass = 0; // -------------------------------- - // RAS_IPolyMaterial variables... + // RAS_IPolyMaterial variables... m_flag |= RAS_BLENDERMAT; m_flag |= (mMaterial->IdMode>=ONETEX)? RAS_MULTITEX: 0; m_flag |= ((mMaterial->ras_mode & USE_LIGHT)!=0)? RAS_MULTILIGHT: 0; m_flag |= (mMaterial->glslmat)? RAS_BLENDERGLSL: 0; + m_flag |= ((mMaterial->ras_mode & CAST_SHADOW)!=0)? RAS_CASTSHADOW: 0; // figure max int enabled = mMaterial->num_enabled; @@ -92,14 +93,11 @@ void KX_BlenderMaterial::Initialize( mMaterial->num_enabled = enabled>=max?max:enabled; // test the sum of the various modes for equality - // so we can ether accept or reject this material - // as being equal, this is rather important to + // so we can ether accept or reject this material + // as being equal, this is rather important to // prevent material bleeding for(int i=0; i<mMaterial->num_enabled; i++) { - m_multimode += - ( mMaterial->flag[i] + - mMaterial->blend_mode[i] - ); + m_multimode += (mMaterial->flag[i] + mMaterial->blend_mode[i]); } m_multimode += mMaterial->IdMode+ (mMaterial->ras_mode & ~(COLLIDER|USE_LIGHT)); } diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp index fde01961fd5..6e5513991f9 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -213,16 +213,16 @@ MT_Scalar KX_BulletPhysicsController::GetMass() MT_Vector3 KX_BulletPhysicsController::GetLocalInertia() { - MT_Vector3 inertia(0.f, 0.f, 0.f); - btVector3 inv_inertia; - if (GetRigidBody()) { - inv_inertia = GetRigidBody()->getInvInertiaDiagLocal(); - if (!btFuzzyZero(inv_inertia.getX()) && - !btFuzzyZero(inv_inertia.getY()) && - !btFuzzyZero(inv_inertia.getZ())) + MT_Vector3 inertia(0.f, 0.f, 0.f); + btVector3 inv_inertia; + if (GetRigidBody()) { + inv_inertia = GetRigidBody()->getInvInertiaDiagLocal(); + if (!btFuzzyZero(inv_inertia.getX()) && + !btFuzzyZero(inv_inertia.getY()) && + !btFuzzyZero(inv_inertia.getZ())) inertia = MT_Vector3(1.f/inv_inertia.getX(), 1.f/inv_inertia.getY(), 1.f/inv_inertia.getZ()); - } - return inertia; + } + return inertia; } MT_Vector3 KX_BulletPhysicsController::getReactionForce() diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index 98ea25c135a..a488d646792 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -271,18 +271,18 @@ void KX_Camera::ExtractFrustumSphere() if (m_set_frustum_center) return; - // compute sphere for the general case and not only symmetric frustum: - // the mirror code in ImageRender can use very asymmetric frustum. - // We will put the sphere center on the line that goes from origin to the center of the far clipping plane - // This is the optimal position if the frustum is symmetric or very asymmetric and probably close - // to optimal for the general case. The sphere center position is computed so that the distance to - // the near and far extreme frustum points are equal. - - // get the transformation matrix from device coordinate to camera coordinate + // compute sphere for the general case and not only symmetric frustum: + // the mirror code in ImageRender can use very asymmetric frustum. + // We will put the sphere center on the line that goes from origin to the center of the far clipping plane + // This is the optimal position if the frustum is symmetric or very asymmetric and probably close + // to optimal for the general case. The sphere center position is computed so that the distance to + // the near and far extreme frustum points are equal. + + // get the transformation matrix from device coordinate to camera coordinate MT_Matrix4x4 clip_camcs_matrix = m_projection_matrix; clip_camcs_matrix.invert(); - if (m_projection_matrix[3][3] == MT_Scalar(0.0)) + if (m_projection_matrix[3][3] == MT_Scalar(0.0)) { // frustrum projection // detect which of the corner of the far clipping plane is the farthest to the origin @@ -302,7 +302,7 @@ void KX_Camera::ExtractFrustumSphere() MT_Scalar len; for (int i=0; i<4; i++) { - hpoint = clip_camcs_matrix*npoint; + hpoint = clip_camcs_matrix*npoint; point.setValue(hpoint[0]/hpoint[3], hpoint[1]/hpoint[3], hpoint[2]/hpoint[3]); len = point.dot(point); if (len > F) @@ -321,7 +321,7 @@ void KX_Camera::ExtractFrustumSphere() farcenter *= 0.25; // the extreme near point is the opposite point on the near clipping plane nfar.setValue(-nfar[0], -nfar[1], -1., 1.); - nfar = clip_camcs_matrix*nfar; + nfar = clip_camcs_matrix*nfar; nearpoint.setValue(nfar[0]/nfar[3], nfar[1]/nfar[3], nfar[2]/nfar[3]); // this is a frustrum projection N = nearpoint.dot(nearpoint); @@ -340,7 +340,7 @@ void KX_Camera::ExtractFrustumSphere() z = (F-N)/(2.0*(e-s+c*(f-n))); m_frustum_center = MT_Point3(farcenter[0]*z/e, farcenter[1]*z/e, z); m_frustum_radius = m_frustum_center.distance(farpoint); - } + } else { // orthographic projection @@ -923,6 +923,8 @@ KX_PYMETHODDEF_DOC_O(KX_Camera, getScreenPosition, if (!PyVecTo(value, vect)) { + PyErr_Clear(); + if(ConvertPythonToGameObject(value, &obj, true, "")) { PyErr_Clear(); @@ -1020,10 +1022,8 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, getScreenRay, return NULL; PyObject* argValue = PyTuple_New(2); - if (argValue) { - PyTuple_SET_ITEM(argValue, 0, PyFloat_FromDouble(x)); - PyTuple_SET_ITEM(argValue, 1, PyFloat_FromDouble(y)); - } + PyTuple_SET_ITEM(argValue, 0, PyFloat_FromDouble(x)); + PyTuple_SET_ITEM(argValue, 1, PyFloat_FromDouble(y)); if(!PyVecTo(PygetScreenVect(argValue), vect)) { diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index d68cb453fe8..ebb291b2284 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -54,14 +54,16 @@ KX_CameraActuator::KX_CameraActuator( float hght, float minhght, float maxhght, - bool xytog + bool xytog, + float damping ): SCA_IActuator(gameobj, KX_ACT_CAMERA), m_ob (obj), m_height (hght), m_minHeight (minhght), m_maxHeight (maxhght), - m_x (xytog) + m_x (xytog), + m_damping (damping) { if (m_ob) m_ob->RegisterActuator(this); @@ -283,7 +285,7 @@ bool KX_CameraActuator::Update(double curtime, bool frame) } inp= fp1[0]*fp2[0] + fp1[1]*fp2[1] + fp1[2]*fp2[2]; - fac= (-1.0 + inp)/32.0; + fac= (-1.0 + inp) * m_damping; from[0]+= fac*fp1[0]; from[1]+= fac*fp1[1]; @@ -390,6 +392,7 @@ PyAttributeDef KX_CameraActuator::Attributes[] = { KX_PYATTRIBUTE_FLOAT_RW("height",-FLT_MAX,FLT_MAX,KX_CameraActuator,m_height), KX_PYATTRIBUTE_BOOL_RW("useXY",KX_CameraActuator,m_x), KX_PYATTRIBUTE_RW_FUNCTION("object", KX_CameraActuator, pyattr_get_object, pyattr_set_object), + KX_PYATTRIBUTE_FLOAT_RW("damping",0.f,10.f,KX_CameraActuator,m_damping), {NULL} }; diff --git a/source/gameengine/Ketsji/KX_CameraActuator.h b/source/gameengine/Ketsji/KX_CameraActuator.h index d59fcff9370..f844f6418b8 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.h +++ b/source/gameengine/Ketsji/KX_CameraActuator.h @@ -73,6 +73,9 @@ private : /** xy toggle (pick one): true == x, false == y */ bool m_x; + + /** damping (float), */ + float m_damping; /* get the KX_IGameObject with this name */ CValue *findObject(char *obName); @@ -95,7 +98,8 @@ private : float hght, float minhght, float maxhght, - bool xytog + bool xytog, + float damping ); diff --git a/source/gameengine/Ketsji/KX_Dome.cpp b/source/gameengine/Ketsji/KX_Dome.cpp index 2e1fb933ad0..00c5e5803a8 100644 --- a/source/gameengine/Ketsji/KX_Dome.cpp +++ b/source/gameengine/Ketsji/KX_Dome.cpp @@ -42,34 +42,34 @@ Developed as part of a Research and Development project for SAT - La Société d // constructor KX_Dome::KX_Dome ( - RAS_ICanvas* canvas, - /// rasterizer - RAS_IRasterizer* rasterizer, - /// render tools - RAS_IRenderTools* rendertools, - /// engine - KX_KetsjiEngine* engine, - - short res, //resolution of the mesh - short mode, //mode - fisheye, truncated, warped, panoramic, ... - short angle, - float resbuf, //size adjustment of the buffer - short tilt, - struct Text* warptext - -): - dlistSupported(false), - canvaswidth(-1), canvasheight(-1), - m_drawingmode(engine->GetDrawType()), - m_resolution(res), - m_mode(mode), - m_angle(angle), - m_resbuffer(resbuf), - m_tilt(tilt), - m_canvas(canvas), - m_rasterizer(rasterizer), - m_rendertools(rendertools), - m_engine(engine) + RAS_ICanvas* canvas, + /// rasterizer + RAS_IRasterizer* rasterizer, + /// render tools + RAS_IRenderTools* rendertools, + /// engine + KX_KetsjiEngine* engine, + + short res, //resolution of the mesh + short mode, //mode - fisheye, truncated, warped, panoramic, ... + short angle, + float resbuf, //size adjustment of the buffer + short tilt, + struct Text* warptext + + ): + dlistSupported(false), + canvaswidth(-1), canvasheight(-1), + m_drawingmode(engine->GetDrawType()), + m_resolution(res), + m_mode(mode), + m_angle(angle), + m_resbuffer(resbuf), + m_tilt(tilt), + m_canvas(canvas), + m_rasterizer(rasterizer), + m_rendertools(rendertools), + m_engine(engine) { warp.usemesh = false; fboSupported = false; @@ -1984,9 +1984,9 @@ void KX_Dome::DrawDomeWarped(void) int can_width = m_viewport.GetRight(); int can_height = m_viewport.GetTop(); - double screen_ratio = can_width/ (double) can_height; + double screen_ratio = can_width/ (double) can_height; - glOrtho(-screen_ratio,screen_ratio,-1.0,1.0,-20.0,10.0); + glOrtho(-screen_ratio,screen_ratio,-1.0,1.0,-20.0,10.0); glMatrixMode(GL_TEXTURE); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index d4ef462fb27..ae8d7094015 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -75,6 +75,8 @@ typedef unsigned long uint_ptr; #include "NG_NetworkScene.h" //Needed for sendMessage() #include "KX_ObstacleSimulation.h" +#include "BL_ActionManager.h" + #include "PyObjectPlus.h" /* python stuff */ // This file defines relationships between parents and children @@ -86,32 +88,33 @@ typedef unsigned long uint_ptr; static MT_Point3 dummy_point= MT_Point3(0.0, 0.0, 0.0); static MT_Vector3 dummy_scaling = MT_Vector3(1.0, 1.0, 1.0); -static MT_Matrix3x3 dummy_orientation = MT_Matrix3x3( 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0); +static MT_Matrix3x3 dummy_orientation = MT_Matrix3x3(1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 0.0, 0.0, 1.0); KX_GameObject::KX_GameObject( - void* sgReplicationInfo, - SG_Callbacks callbacks) - : SCA_IObject(), - m_bDyna(false), - m_layer(0), - m_pBlenderObject(NULL), - m_pBlenderGroupObject(NULL), - m_bSuspendDynamics(false), - m_bUseObjectColor(false), - m_bIsNegativeScaling(false), - m_bVisible(true), - m_bCulled(true), - m_bOccluder(false), - m_pPhysicsController1(NULL), - m_pGraphicController(NULL), - m_xray(false), - m_pHitObject(NULL), - m_isDeformable(false), - m_pObstacleSimulation(NULL) + void* sgReplicationInfo, + SG_Callbacks callbacks) + : SCA_IObject(), + m_bDyna(false), + m_layer(0), + m_pBlenderObject(NULL), + m_pBlenderGroupObject(NULL), + m_bSuspendDynamics(false), + m_bUseObjectColor(false), + m_bIsNegativeScaling(false), + m_bVisible(true), + m_bCulled(true), + m_bOccluder(false), + m_pPhysicsController1(NULL), + m_pGraphicController(NULL), + m_xray(false), + m_pHitObject(NULL), + m_actionManager(NULL), + m_isDeformable(false), + m_pObstacleSimulation(NULL) #ifdef WITH_PYTHON - , m_attr_dict(NULL) + , m_attr_dict(NULL) #endif { m_ignore_activity_culling = false; @@ -162,6 +165,11 @@ KX_GameObject::~KX_GameObject() m_pObstacleSimulation->DestroyObstacleForObj(this); } + if (m_actionManager) + { + KX_GetActiveScene()->RemoveAnimatedObject(this); + delete m_actionManager; + } #ifdef WITH_PYTHON if (m_attr_dict) { PyDict_Clear(m_attr_dict); /* incase of circular refs or other weird cases */ @@ -335,7 +343,7 @@ void KX_GameObject::RemoveParent(KX_Scene *scene) rootobj->m_pPhysicsController1->RemoveCompoundChild(m_pPhysicsController1); } m_pPhysicsController1->RestoreDynamics(); - if (m_pPhysicsController1->IsDyna() && rootobj->m_pPhysicsController1) + if (m_pPhysicsController1->IsDyna() && (rootobj != NULL && rootobj->m_pPhysicsController1)) { // dynamic object should remember the velocity they had while being parented MT_Point3 childPoint = GetSGNode()->GetWorldPosition(); @@ -352,6 +360,69 @@ void KX_GameObject::RemoveParent(KX_Scene *scene) } } +BL_ActionManager* KX_GameObject::GetActionManager() +{ + // We only want to create an action manager if we need it + if (!m_actionManager) + { KX_GetActiveScene()->AddAnimatedObject(this); m_actionManager = new BL_ActionManager(this); + } + return m_actionManager; +} + +bool KX_GameObject::PlayAction(const char* name, + float start, + float end, + short layer, + short priority, + float blendin, + short play_mode, + float layer_weight, + short ipo_flags, + float playback_speed) +{ + return GetActionManager()->PlayAction(name, start, end, layer, priority, blendin, play_mode, layer_weight, ipo_flags, playback_speed); +} + +void KX_GameObject::StopAction(short layer) +{ + GetActionManager()->StopAction(layer); +} + +bool KX_GameObject::IsActionDone(short layer) +{ + return GetActionManager()->IsActionDone(layer); +} + +void KX_GameObject::UpdateActionManager(float curtime) +{ + GetActionManager()->Update(curtime); +} + +float KX_GameObject::GetActionFrame(short layer) +{ + return GetActionManager()->GetActionFrame(layer); +} + +void KX_GameObject::SetActionFrame(short layer, float frame) +{ + GetActionManager()->SetActionFrame(layer, frame); +} + +bAction *KX_GameObject::GetCurrentAction(short layer) +{ + return GetActionManager()->GetCurrentAction(layer); +} + +void KX_GameObject::SetPlayMode(short layer, short mode) +{ + GetActionManager()->SetPlayMode(layer, mode); +} + +void KX_GameObject::SetTimes(short layer, float start, float end) +{ + GetActionManager()->SetTimes(layer, start, end); +} + void KX_GameObject::ProcessReplica() { SCA_IObject::ProcessReplica(); @@ -361,6 +432,8 @@ void KX_GameObject::ProcessReplica() m_pSGNode = NULL; m_pClient_info = new KX_ClientObjectInfo(*m_pClient_info); m_pClient_info->m_gameobject = this; + if (m_actionManager) + m_actionManager = new BL_ActionManager(this); m_state = 0; KX_Scene* scene = KX_GetActiveScene(); @@ -1513,6 +1586,12 @@ PyMethodDef KX_GameObject::Methods[] = { KX_PYMETHODTABLE_O(KX_GameObject, getDistanceTo), KX_PYMETHODTABLE_O(KX_GameObject, getVectTo), KX_PYMETHODTABLE(KX_GameObject, sendMessage), + + KX_PYMETHODTABLE_KEYWORDS(KX_GameObject, playAction), + KX_PYMETHODTABLE(KX_GameObject, stopAction), + KX_PYMETHODTABLE(KX_GameObject, getActionFrame), + KX_PYMETHODTABLE(KX_GameObject, setActionFrame), + KX_PYMETHODTABLE(KX_GameObject, isPlayingAction), // dict style access for props {"get",(PyCFunction) KX_GameObject::sPyget, METH_VARARGS}, @@ -1855,7 +1934,7 @@ PyObject* KX_GameObject::pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBU { KX_GameObject* self= static_cast<KX_GameObject*>(self_v); KX_IPhysicsController *spc = self->GetPhysicsController(); - return PyFloat_FromDouble(spc ? spc->GetLinVelocityMax() : 0.0f); + return PyFloat_FromDouble(spc ? spc->GetLinVelocityMin() : 0.0f); } int KX_GameObject::pyattr_set_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) @@ -2991,6 +3070,112 @@ KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage, Py_RETURN_NONE; } +static void layer_check(short &layer, const char *method_name) +{ + if (layer < 0 || layer >= MAX_ACTION_LAYERS) + { + printf("KX_GameObject.%s(): given layer (%d) is out of range (0 - %d), setting to 0.\n", method_name, layer, MAX_ACTION_LAYERS-1); + layer = 0; + } +} + +KX_PYMETHODDEF_DOC(KX_GameObject, playAction, + "playAction(name, start_frame, end_frame, layer=0, priority=0 blendin=0, play_mode=ACT_MODE_PLAY, layer_weight=0.0, ipo_flags=0, speed=1.0)\n" + "Plays an action\n") +{ + const char* name; + float start, end, blendin=0.f, speed=1.f, layer_weight=0.f; + short layer=0, priority=0; + short ipo_flags=0; + short play_mode=0; + + static const char *kwlist[] = {"name", "start_frame", "end_frame", "layer", "priority", "blendin", "play_mode", "layer_weight", "ipo_flags", "speed", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "sff|hhfhfhf:playAction", const_cast<char**>(kwlist), + &name, &start, &end, &layer, &priority, &blendin, &play_mode, &layer_weight, &ipo_flags, &speed)) + return NULL; + + layer_check(layer, "playAction"); + + if (play_mode < 0 || play_mode > BL_Action::ACT_MODE_MAX) + { + printf("KX_GameObject.playAction(): given play_mode (%d) is out of range (0 - %d), setting to ACT_MODE_PLAY", play_mode, BL_Action::ACT_MODE_MAX-1); + play_mode = BL_Action::ACT_MODE_MAX; + } + + if (layer_weight < 0.f || layer_weight > 1.f) + { + printf("KX_GameObject.playAction(): given layer_weight (%f) is out of range (0.0 - 1.0), setting to 0.0", layer_weight); + layer_weight = 0.f; + } + + PlayAction(name, start, end, layer, priority, blendin, play_mode, layer_weight, ipo_flags, speed); + + Py_RETURN_NONE; +} + +KX_PYMETHODDEF_DOC(KX_GameObject, stopAction, + "stopAction(layer=0)\n" + "Stop playing the action on the given layer\n") +{ + short layer=0; + + if (!PyArg_ParseTuple(args, "|h:stopAction", &layer)) + return NULL; + + layer_check(layer, "stopAction"); + + StopAction(layer); + + Py_RETURN_NONE; +} + +KX_PYMETHODDEF_DOC(KX_GameObject, getActionFrame, + "getActionFrame(layer=0)\n" + "Gets the current frame of the action playing in the supplied layer\n") +{ + short layer=0; + + if (!PyArg_ParseTuple(args, "|h:getActionFrame", &layer)) + return NULL; + + layer_check(layer, "getActionFrame"); + + return PyFloat_FromDouble(GetActionFrame(layer)); +} + +KX_PYMETHODDEF_DOC(KX_GameObject, setActionFrame, + "setActionFrame(frame, layer=0)\n" + "Set the current frame of the action playing in the supplied layer\n") +{ + short layer=0; + float frame; + + if (!PyArg_ParseTuple(args, "f|h:setActionFrame", &frame, &layer)) + return NULL; + + layer_check(layer, "setActionFrame"); + + SetActionFrame(layer, frame); + + Py_RETURN_NONE; +} + +KX_PYMETHODDEF_DOC(KX_GameObject, isPlayingAction, + "isPlayingAction(layer=0)\n" + "Checks to see if there is an action playing in the given layer\n") +{ + short layer=0; + + if (!PyArg_ParseTuple(args, "|h:isPlayingAction", &layer)) + return NULL; + + layer_check(layer, "isPlayingAction"); + + return PyBool_FromLong(!IsActionDone(layer)); +} + + /* dict style access */ diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 2ea6e9552a2..655bc9ff080 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -63,8 +63,10 @@ class RAS_MeshObject; class KX_IPhysicsController; class PHY_IGraphicController; class PHY_IPhysicsEnvironment; +class BL_ActionManager; struct Object; class KX_ObstacleSimulation; +struct bAction; #ifdef WITH_PYTHON /* utility conversion function */ @@ -116,6 +118,12 @@ protected: KX_ObstacleSimulation* m_pObstacleSimulation; + + // The action manager is used to play/stop/update actions + BL_ActionManager* m_actionManager; + + BL_ActionManager* GetActionManager(); + public: bool m_isDeformable; @@ -201,6 +209,68 @@ public: */ void RemoveParent(KX_Scene *scene); + /********************************* + * Animation API + *********************************/ + + /** + * Adds an action to the object's action manager + */ + bool PlayAction(const char* name, + float start, + float end, + short layer=0, + short priority=0, + float blendin=0.f, + short play_mode=0, + float layer_weight=0.f, + short ipo_flags=0, + float playback_speed=1.f); + + /** + * Gets the current frame of an action + */ + float GetActionFrame(short layer); + + /** + * Sets the current frame of an action + */ + void SetActionFrame(short layer, float frame); + + /** + * Gets the currently running action on the given layer + */ + bAction *GetCurrentAction(short layer); + + /** + * Sets play mode of the action on the given layer + */ + void SetPlayMode(short layer, short mode); + + /** + * Sets the start and end times of the action on the given layer + */ + void SetTimes(short layer, float start, float end); + + /** + * Stop playing the action on the given layer + */ + void StopAction(short layer); + + /** + * Check if an action has finished playing + */ + bool IsActionDone(short layer); + + /** + * Kick the object's action manager + */ + void UpdateActionManager(float curtime); + + /********************************* + * End Animation API + *********************************/ + /** * Construct a game object. This class also inherits the * default constructors - use those with care! @@ -866,6 +936,12 @@ public: KX_PYMETHOD_DOC_O(KX_GameObject,getVectTo); KX_PYMETHOD_DOC_VARARGS(KX_GameObject, sendMessage); KX_PYMETHOD_VARARGS(KX_GameObject, ReinstancePhysicsMesh); + + KX_PYMETHOD_DOC(KX_GameObject, playAction); + KX_PYMETHOD_DOC(KX_GameObject, stopAction); + KX_PYMETHOD_DOC(KX_GameObject, getActionFrame); + KX_PYMETHOD_DOC(KX_GameObject, setActionFrame); + KX_PYMETHOD_DOC(KX_GameObject, isPlayingAction); /* Dict access */ KX_PYMETHOD_VARARGS(KX_GameObject,get); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index eef543e629c..db919b7bc5a 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -68,7 +68,10 @@ #include "KX_PyConstraintBinding.h" #include "PHY_IPhysicsEnvironment.h" -#include "AUD_C-API.h" +#ifdef WITH_AUDASPACE +# include "AUD_C-API.h" +# include "AUD_I3DDevice.h" +#endif #include "NG_NetworkScene.h" #include "NG_NetworkDeviceInterface.h" @@ -91,10 +94,10 @@ const char KX_KetsjiEngine::m_profileLabels[tc_numCategories][15] = { "Physics:", // tc_physics - "Logic", // tc_logic + "Logic:", // tc_logic + "Animations:", // tc_animations "Network:", // tc_network "Scenegraph:", // tc_scenegraph - "Sound:", // tc_sound "Rasterizer:", // tc_rasterizer "Services:", // tc_services "Overhead:", // tc_overhead @@ -108,13 +111,14 @@ double KX_KetsjiEngine::m_anim_framerate = 25.0; double KX_KetsjiEngine::m_suspendedtime = 0.0; double KX_KetsjiEngine::m_suspendeddelta = 0.0; double KX_KetsjiEngine::m_average_framerate = 0.0; +bool KX_KetsjiEngine::m_restrict_anim_fps = false; /** * Constructor of the Ketsji Engine */ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system) - : m_canvas(NULL), + : m_canvas(NULL), m_rasterizer(NULL), m_kxsystem(system), m_rendertools(NULL), @@ -137,6 +141,7 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system) m_frameTime(0.f), m_clockTime(0.f), m_previousClockTime(0.f), + m_previousAnimTime(0.f), m_exitcode(KX_EXIT_REQUEST_NO_REQUEST), @@ -578,7 +583,7 @@ else framestep = (frames*timestep)/m_maxLogicFrame; frames = m_maxLogicFrame; } - + while (frames) { @@ -657,7 +662,14 @@ else m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_ACTUATOR_UPDATE); scene->UpdateParents(m_frameTime); - + + if (!GetRestrictAnimationFPS()) + { + m_logger->StartLog(tc_animations, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_ANIMATION_UPDATE); + scene->UpdateAnimations(m_frameTime); + } + m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_PHYSICS2); scene->GetPhysicsEnvironment()->beginFrame(); @@ -681,8 +693,6 @@ else else if(scene->getSuspendedTime()==0.0) scene->setSuspendedTime(m_clockTime); - - DoSound(scene); m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true); } @@ -758,14 +768,30 @@ else if(scene->getSuspendedTime()==0.0) scene->setSuspendedTime(m_clockTime); - DoSound(scene); - m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true); } } + + // Handle the animations independently of the logic time step + if (GetRestrictAnimationFPS()) + { + m_logger->StartLog(tc_animations, m_kxsystem->GetTimeInSeconds(), true); + SG_SetActiveStage(SG_STAGE_ANIMATION_UPDATE); - m_previousClockTime = m_clockTime; + double anim_timestep = 1.0/KX_GetActiveScene()->GetAnimationFPS(); + if (m_clockTime - m_previousAnimTime > anim_timestep) + { + // Sanity/debug print to make sure we're actually going at the fps we want (should be close to anim_timestep) + // printf("Anim fps: %f\n", 1.0/(m_clockTime - m_previousAnimTime)); + m_previousAnimTime = m_clockTime; + for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit) + { + (*sceneit)->UpdateAnimations(m_frameTime); + } + } + m_previousClockTime = m_clockTime; + } // Start logging time spend outside main loop m_logger->StartLog(tc_outside, m_kxsystem->GetTimeInSeconds(), true); @@ -974,29 +1000,6 @@ const STR_String& KX_KetsjiEngine::GetExitString() } - -void KX_KetsjiEngine::DoSound(KX_Scene* scene) -{ - m_logger->StartLog(tc_sound, m_kxsystem->GetTimeInSeconds(), true); - - KX_Camera* cam = scene->GetActiveCamera(); - if (!cam) - return; - - float f[4]; - - cam->NodeGetWorldPosition().getValue(f); - AUD_setListenerLocation(f); - - cam->GetLinearVelocity().getValue(f); - AUD_setListenerVelocity(f); - - cam->NodeGetWorldOrientation().getRotation().getValue(f); - AUD_setListenerOrientation(f); -} - - - void KX_KetsjiEngine::SetBackGround(KX_WorldInfo* wi) { if (wi->hasWorld()) @@ -1220,7 +1223,7 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam) projmat.setValue(m_overrideCamProjMat.getPointer()); cam->SetProjectionMatrix(projmat); } - } else if (cam->hasValidProjectionMatrix() && !cam->GetViewport() ) + } else if (cam->hasValidProjectionMatrix()) { m_rasterizer->SetProjectionMatrix(cam->GetProjectionMatrix()); } else @@ -1334,6 +1337,9 @@ To run once per scene */ void KX_KetsjiEngine::PostRenderScene(KX_Scene* scene) { + // We need to first make sure our viewport is correct (enabling multiple viewports can mess this up) + m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight()); + m_rendertools->MotionBlur(m_rasterizer); scene->Render2DFilters(m_canvas); #ifdef WITH_PYTHON @@ -1799,6 +1805,16 @@ void KX_KetsjiEngine::SetMaxPhysicsFrame(int frame) m_maxPhysicsFrame = frame; } +bool KX_KetsjiEngine::GetRestrictAnimationFPS() +{ + return m_restrict_anim_fps; +} + +void KX_KetsjiEngine::SetRestrictAnimationFPS(bool bRestrictAnimFPS) +{ + m_restrict_anim_fps = bRestrictAnimFPS; +} + double KX_KetsjiEngine::GetAnimFrameRate() { return m_anim_framerate; diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index 8cd6fdb8f5f..b1009c7d8f0 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -108,6 +108,7 @@ private: double m_frameTime;//discrete timestamp of the 'game logic frame' double m_clockTime;//current time double m_previousClockTime;//previous clock time + double m_previousAnimTime; //the last time animations were updated double m_remainingTime; static int m_maxLogicFrame; /* maximum number of consecutive logic frame */ @@ -115,6 +116,8 @@ private: static double m_ticrate; static double m_anim_framerate; /* for animation playback only - ipo and action */ + static bool m_restrict_anim_fps; + static double m_suspendedtime; static double m_suspendeddelta; @@ -147,9 +150,9 @@ private: tc_first = 0, tc_physics = 0, tc_logic, + tc_animations, tc_network, tc_scenegraph, - tc_sound, tc_rasterizer, tc_services, // time spend in miscelaneous activities tc_overhead, // profile info drawing overhead @@ -195,7 +198,6 @@ private: void RenderDebugProperties(); void RenderShadowBuffers(KX_Scene *scene); void SetBackGround(KX_WorldInfo* worldinfo); - void DoSound(KX_Scene* scene); void RenderFonts(KX_Scene* scene); public: @@ -321,6 +323,16 @@ public: static void SetMaxPhysicsFrame(int frame); /** + * Gets whether or not to lock animation updates to the animframerate + */ + static bool GetRestrictAnimationFPS(); + + /** + * Sets whether or not to lock animation updates to the animframerate + */ + static void SetRestrictAnimationFPS(bool bRestrictAnimFPS); + + /** * Gets the framerate for playing animations. (actions and ipos) */ static double GetAnimFrameRate(); diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index 49f00e39110..2f2c45cd5cc 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -254,8 +254,12 @@ void KX_LightObject::BindShadowBuffer(RAS_IRasterizer *ras, KX_Camera *cam, MT_T cam->NodeUpdateGS(0); /* setup rasterizer transformations */ + /* SetViewMatrix may use stereomode which we temporarily disable here */ + RAS_IRasterizer::StereoMode stereomode = ras->GetStereoMode(); + ras->SetStereoMode(RAS_IRasterizer::RAS_STEREO_NOSTEREO); ras->SetProjectionMatrix(projectionmat); ras->SetViewMatrix(modelviewmat, cam->NodeGetWorldOrientation(), cam->NodeGetWorldPosition(), cam->GetCameraData()->m_perspective); + ras->SetStereoMode(stereomode); } void KX_LightObject::UnbindShadowBuffer(RAS_IRasterizer *ras) @@ -351,11 +355,11 @@ PyObject* KX_LightObject::pyattr_get_typeconst(void *self_v, const KX_PYATTRIBUT } else if (!strcmp(type, "NORMAL")) { retvalue = PyLong_FromSsize_t(RAS_LightObject::LIGHT_NORMAL); } - else { - /* should never happen */ - PyErr_SetString(PyExc_TypeError, "light.type: internal error, invalid light type"); - retvalue = NULL; - } + else { + /* should never happen */ + PyErr_SetString(PyExc_TypeError, "light.type: internal error, invalid light type"); + retvalue = NULL; + } return retvalue; } diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index ba41dc355f7..9ad09f9793b 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -119,7 +119,7 @@ CValue* KX_MeshProxy::GetReplica() { return NULL;} PyObject* KX_MeshProxy::PyGetMaterialName(PyObject* args, PyObject* kwds) { - int matid= 1; + int matid= 1; STR_String matname; if (PyArg_ParseTuple(args,"i:getMaterialName",&matid)) @@ -131,13 +131,13 @@ PyObject* KX_MeshProxy::PyGetMaterialName(PyObject* args, PyObject* kwds) } return PyUnicode_FromString(matname.Ptr()); - + } - + PyObject* KX_MeshProxy::PyGetTextureName(PyObject* args, PyObject* kwds) { - int matid= 1; + int matid= 1; STR_String matname; if (PyArg_ParseTuple(args,"i:getTextureName",&matid)) @@ -154,7 +154,7 @@ PyObject* KX_MeshProxy::PyGetTextureName(PyObject* args, PyObject* kwds) PyObject* KX_MeshProxy::PyGetVertexArrayLength(PyObject* args, PyObject* kwds) { - int matid= 0; + int matid= 0; int length = 0; @@ -177,7 +177,7 @@ PyObject* KX_MeshProxy::PyGetVertexArrayLength(PyObject* args, PyObject* kwds) PyObject* KX_MeshProxy::PyGetVertex(PyObject* args, PyObject* kwds) { - int vertexindex; + int vertexindex; int matindex; if (!PyArg_ParseTuple(args,"ii:getVertex",&matindex,&vertexindex)) @@ -195,7 +195,7 @@ PyObject* KX_MeshProxy::PyGetVertex(PyObject* args, PyObject* kwds) PyObject* KX_MeshProxy::PyGetPolygon(PyObject* args, PyObject* kwds) { - int polyindex= 1; + int polyindex= 1; PyObject* polyob = NULL; if (!PyArg_ParseTuple(args,"i:getPolygon",&polyindex)) diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index 6cb80028858..34f5c26415d 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -121,14 +121,14 @@ bool KX_MouseFocusSensor::Evaluate() } } if (reset) { - // force an event + // force an event result = true; } } else { /* No focus behaviour required: revert to the basic mode. This - * mode is never used, because the converter never makes this - * sensor for a mouse-key event. It is here for - * completeness. */ + * mode is never used, because the converter never makes this + * sensor for a mouse-key event. It is here for + * completeness. */ result = SCA_MouseSensor::Evaluate(); m_positive_event = (m_val!=0); } diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index 7289ffc6e29..cb59ef42699 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -237,9 +237,9 @@ bool KX_ObjectActuator::Update() if (m_current_linear_factor > 1.0) m_current_linear_factor = 1.0; linV = m_current_linear_factor * m_linear_velocity; - parent->setLinearVelocity(linV,(m_bitLocalFlag.LinearVelocity) != 0); + parent->setLinearVelocity(linV,(m_bitLocalFlag.LinearVelocity) != 0); } else { - parent->setLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0); + parent->setLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0); } } } @@ -260,7 +260,7 @@ bool KX_ObjectActuator::Update() if (m_current_angular_factor > 1.0) m_current_angular_factor = 1.0; angV = m_current_angular_factor * m_angular_velocity; - parent->setAngularVelocity(angV,(m_bitLocalFlag.AngularVelocity) != 0); + parent->setAngularVelocity(angV,(m_bitLocalFlag.AngularVelocity) != 0); } else { parent->setAngularVelocity(m_angular_velocity,(m_bitLocalFlag.AngularVelocity) != 0); } diff --git a/source/gameengine/Ketsji/KX_OrientationInterpolator.cpp b/source/gameengine/Ketsji/KX_OrientationInterpolator.cpp index d9483083aa1..bd743159950 100644 --- a/source/gameengine/Ketsji/KX_OrientationInterpolator.cpp +++ b/source/gameengine/Ketsji/KX_OrientationInterpolator.cpp @@ -51,6 +51,6 @@ void KX_OrientationInterpolator::Execute(float currentTime) const { MT_Scalar ss = si*sh; m_target.setValue(cj*ch, sj*sc-cs, sj*cc+ss, - cj*sh, sj*ss+cc, sj*cs-sc, - -sj, cj*si, cj*ci); + cj*sh, sj*ss+cc, sj*cs-sc, + -sj, cj*si, cj*ci); } diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index 9d0597051ad..d32f267f0e0 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -187,7 +187,7 @@ void KX_PolygonMaterial::DefaultActivate(RAS_IRasterizer* rasty, TCachingInfo& c rasty->SetCullFace(true); if ((m_drawingmode & RAS_IRasterizer::KX_LINES) || - (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME)) + (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME)) rasty->SetLines(true); else rasty->SetLines(false); diff --git a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp index 12024657149..fde127b7ef5 100644 --- a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp +++ b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp @@ -38,12 +38,20 @@ #include "KX_PhysicsObjectWrapper.h" #include "PHY_IPhysicsController.h" #include "PHY_IVehicle.h" +#include "PHY_DynamicTypes.h" #include "MT_Matrix3x3.h" #include "PyObjectPlus.h" +#ifdef USE_BULLET +# include "LinearMath/btIDebugDraw.h" +#endif + #ifdef WITH_PYTHON +// macro copied from KX_PythonInit.cpp +#define KX_MACRO_addTypesToDict(dict, name, name2) PyDict_SetItemString(dict, #name, item=PyLong_FromSsize_t(name2)); Py_DECREF(item) + // nasty glob variable to connect scripting language // if there is a better way (without global), please do so! static PHY_IPhysicsEnvironment* g_CurrentActivePhysicsEnvironment = NULL; @@ -84,8 +92,8 @@ static char gPyGetAppliedImpulse__doc__[] = "getAppliedImpulse(int constraintId) static PyObject* gPySetGravity(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { float x,y,z; if (PyArg_ParseTuple(args,"fff",&x,&y,&z)) @@ -101,8 +109,8 @@ static PyObject* gPySetGravity(PyObject* self, } static PyObject* gPySetDebugMode(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { int mode; if (PyArg_ParseTuple(args,"i",&mode)) @@ -124,8 +132,8 @@ static PyObject* gPySetDebugMode(PyObject* self, static PyObject* gPySetNumTimeSubSteps(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { int substep; if (PyArg_ParseTuple(args,"i",&substep)) @@ -143,8 +151,8 @@ static PyObject* gPySetNumTimeSubSteps(PyObject* self, static PyObject* gPySetNumIterations(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { int iter; if (PyArg_ParseTuple(args,"i",&iter)) @@ -161,10 +169,9 @@ static PyObject* gPySetNumIterations(PyObject* self, } - static PyObject* gPySetDeactivationTime(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { float deactive_time; if (PyArg_ParseTuple(args,"f",&deactive_time)) @@ -182,8 +189,8 @@ static PyObject* gPySetDeactivationTime(PyObject* self, static PyObject* gPySetDeactivationLinearTreshold(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { float linearDeactivationTreshold; if (PyArg_ParseTuple(args,"f",&linearDeactivationTreshold)) @@ -201,8 +208,8 @@ static PyObject* gPySetDeactivationLinearTreshold(PyObject* self, static PyObject* gPySetDeactivationAngularTreshold(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { float angularDeactivationTreshold; if (PyArg_ParseTuple(args,"f",&angularDeactivationTreshold)) @@ -219,8 +226,8 @@ static PyObject* gPySetDeactivationAngularTreshold(PyObject* self, } static PyObject* gPySetContactBreakingTreshold(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { float contactBreakingTreshold; if (PyArg_ParseTuple(args,"f",&contactBreakingTreshold)) @@ -238,8 +245,8 @@ static PyObject* gPySetContactBreakingTreshold(PyObject* self, static PyObject* gPySetCcdMode(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { float ccdMode; if (PyArg_ParseTuple(args,"f",&ccdMode)) @@ -256,8 +263,8 @@ static PyObject* gPySetCcdMode(PyObject* self, } static PyObject* gPySetSorConstant(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { float sor; if (PyArg_ParseTuple(args,"f",&sor)) @@ -274,8 +281,8 @@ static PyObject* gPySetSorConstant(PyObject* self, } static PyObject* gPySetSolverTau(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { float tau; if (PyArg_ParseTuple(args,"f",&tau)) @@ -293,8 +300,8 @@ static PyObject* gPySetSolverTau(PyObject* self, static PyObject* gPySetSolverDamping(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { float damping; if (PyArg_ParseTuple(args,"f",&damping)) @@ -311,8 +318,8 @@ static PyObject* gPySetSolverDamping(PyObject* self, } static PyObject* gPySetLinearAirDamping(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { float damping; if (PyArg_ParseTuple(args,"f",&damping)) @@ -330,8 +337,8 @@ static PyObject* gPySetLinearAirDamping(PyObject* self, static PyObject* gPySetUseEpa(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { int epa; if (PyArg_ParseTuple(args,"i",&epa)) @@ -347,8 +354,8 @@ static PyObject* gPySetUseEpa(PyObject* self, Py_RETURN_NONE; } static PyObject* gPySetSolverType(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { int solverType; if (PyArg_ParseTuple(args,"i",&solverType)) @@ -367,8 +374,8 @@ static PyObject* gPySetSolverType(PyObject* self, static PyObject* gPyGetVehicleConstraint(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { #if defined(_WIN64) __int64 constraintid; @@ -398,9 +405,6 @@ static PyObject* gPyGetVehicleConstraint(PyObject* self, } - - - static PyObject* gPyCreateConstraint(PyObject* self, PyObject* args, PyObject* kwds) @@ -425,39 +429,39 @@ static PyObject* gPyCreateConstraint(PyObject* self, success = PyArg_ParseTuple(args,"lli",&physicsid,&physicsid2,&constrainttype); #endif } - else - if (len ==6) + else if (len == 6) { #if defined(_WIN64) success = PyArg_ParseTuple(args,"LLifff",&physicsid,&physicsid2,&constrainttype, - &pivotX,&pivotY,&pivotZ); + &pivotX,&pivotY,&pivotZ); #else success = PyArg_ParseTuple(args,"llifff",&physicsid,&physicsid2,&constrainttype, - &pivotX,&pivotY,&pivotZ); + &pivotX,&pivotY,&pivotZ); #endif } else if (len == 9) { #if defined(_WIN64) success = PyArg_ParseTuple(args,"LLiffffff",&physicsid,&physicsid2,&constrainttype, - &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ); + &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ); #else success = PyArg_ParseTuple(args,"lliffffff",&physicsid,&physicsid2,&constrainttype, - &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ); + &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ); #endif - } else if (len == 10) { #if defined(_WIN64) success = PyArg_ParseTuple(args,"LLiffffffi",&physicsid,&physicsid2,&constrainttype, - &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ,&flag); + &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ,&flag); #else success = PyArg_ParseTuple(args,"lliffffffi",&physicsid,&physicsid2,&constrainttype, - &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ,&flag); + &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ,&flag); #endif } - else if (len==4) + + /* XXX extrainfo seems to be nothing implemented. right now it works as a pivot with [X,0,0] */ + else if (len == 4) { #if defined(_WIN64) success = PyArg_ParseTuple(args,"LLii",&physicsid,&physicsid2,&constrainttype,&extrainfo); @@ -466,7 +470,7 @@ static PyObject* gPyCreateConstraint(PyObject* self, #endif pivotX=extrainfo; } - + if (success) { if (PHY_GetActiveEnvironment()) @@ -490,20 +494,18 @@ static PyObject* gPyCreateConstraint(PyObject* self, MT_Vector3 axis0 = localCFrame.getColumn(0); MT_Vector3 axis1 = localCFrame.getColumn(1); MT_Vector3 axis2 = localCFrame.getColumn(2); - - constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype, - pivotX,pivotY,pivotZ, - (float)axis0.x(),(float)axis0.y(),(float)axis0.z(), - (float)axis1.x(),(float)axis1.y(),(float)axis1.z(), - (float)axis2.x(),(float)axis2.y(),(float)axis2.z(),flag); - } else - { + constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype, + pivotX,pivotY,pivotZ, + (float)axis0.x(),(float)axis0.y(),(float)axis0.z(), + (float)axis1.x(),(float)axis1.y(),(float)axis1.z(), + (float)axis2.x(),(float)axis2.y(),(float)axis2.z(),flag); + } + else { constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,pivotX,pivotY,pivotZ,axisX,axisY,axisZ,0); } KX_ConstraintWrapper* wrap = new KX_ConstraintWrapper((enum PHY_ConstraintType)constrainttype,constraintid,PHY_GetActiveEnvironment()); - return wrap->NewProxy(true); } @@ -522,8 +524,8 @@ static PyObject* gPyCreateConstraint(PyObject* self, static PyObject* gPyGetAppliedImpulse(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { float appliedImpulse = 0.f; @@ -549,8 +551,8 @@ static PyObject* gPyGetAppliedImpulse(PyObject* self, static PyObject* gPyRemoveConstraint(PyObject* self, - PyObject* args, - PyObject* kwds) + PyObject* args, + PyObject* kwds) { #if defined(_WIN64) __int64 constraintid; @@ -577,7 +579,7 @@ static PyObject* gPyExportBulletFile(PyObject*, PyObject* args) char* filename; if (!PyArg_ParseTuple(args,"s:exportBulletFile",&filename)) return NULL; - + if (PHY_GetActiveEnvironment()) { PHY_GetActiveEnvironment()->exportFile(filename); @@ -586,62 +588,61 @@ static PyObject* gPyExportBulletFile(PyObject*, PyObject* args) } static struct PyMethodDef physicsconstraints_methods[] = { - {"setGravity",(PyCFunction) gPySetGravity, - METH_VARARGS, (const char *)gPySetGravity__doc__}, - {"setDebugMode",(PyCFunction) gPySetDebugMode, - METH_VARARGS, (const char *)gPySetDebugMode__doc__}, - - /// settings that influence quality of the rigidbody dynamics - {"setNumIterations",(PyCFunction) gPySetNumIterations, - METH_VARARGS, (const char *)gPySetNumIterations__doc__}, - - {"setNumTimeSubSteps",(PyCFunction) gPySetNumTimeSubSteps, - METH_VARARGS, (const char *)gPySetNumTimeSubSteps__doc__}, - - {"setDeactivationTime",(PyCFunction) gPySetDeactivationTime, - METH_VARARGS, (const char *)gPySetDeactivationTime__doc__}, - - {"setDeactivationLinearTreshold",(PyCFunction) gPySetDeactivationLinearTreshold, - METH_VARARGS, (const char *)gPySetDeactivationLinearTreshold__doc__}, - {"setDeactivationAngularTreshold",(PyCFunction) gPySetDeactivationAngularTreshold, - METH_VARARGS, (const char *)gPySetDeactivationAngularTreshold__doc__}, - - {"setContactBreakingTreshold",(PyCFunction) gPySetContactBreakingTreshold, - METH_VARARGS, (const char *)gPySetContactBreakingTreshold__doc__}, - {"setCcdMode",(PyCFunction) gPySetCcdMode, - METH_VARARGS, (const char *)gPySetCcdMode__doc__}, - {"setSorConstant",(PyCFunction) gPySetSorConstant, - METH_VARARGS, (const char *)gPySetSorConstant__doc__}, - {"setSolverTau",(PyCFunction) gPySetSolverTau, - METH_VARARGS, (const char *)gPySetSolverTau__doc__}, - {"setSolverDamping",(PyCFunction) gPySetSolverDamping, - METH_VARARGS, (const char *)gPySetSolverDamping__doc__}, - - {"setLinearAirDamping",(PyCFunction) gPySetLinearAirDamping, - METH_VARARGS, (const char *)gPySetLinearAirDamping__doc__}, - - {"setUseEpa",(PyCFunction) gPySetUseEpa, - METH_VARARGS, (const char *)gPySetUseEpa__doc__}, + {"setGravity",(PyCFunction) gPySetGravity, + METH_VARARGS, (const char*)gPySetGravity__doc__}, + {"setDebugMode",(PyCFunction) gPySetDebugMode, + METH_VARARGS, (const char *)gPySetDebugMode__doc__}, + + /// settings that influence quality of the rigidbody dynamics + {"setNumIterations",(PyCFunction) gPySetNumIterations, + METH_VARARGS, (const char *)gPySetNumIterations__doc__}, + + {"setNumTimeSubSteps",(PyCFunction) gPySetNumTimeSubSteps, + METH_VARARGS, (const char *)gPySetNumTimeSubSteps__doc__}, + + {"setDeactivationTime",(PyCFunction) gPySetDeactivationTime, + METH_VARARGS, (const char *)gPySetDeactivationTime__doc__}, + + {"setDeactivationLinearTreshold",(PyCFunction) gPySetDeactivationLinearTreshold, + METH_VARARGS, (const char *)gPySetDeactivationLinearTreshold__doc__}, + {"setDeactivationAngularTreshold",(PyCFunction) gPySetDeactivationAngularTreshold, + METH_VARARGS, (const char *)gPySetDeactivationAngularTreshold__doc__}, + + {"setContactBreakingTreshold",(PyCFunction) gPySetContactBreakingTreshold, + METH_VARARGS, (const char *)gPySetContactBreakingTreshold__doc__}, + {"setCcdMode",(PyCFunction) gPySetCcdMode, + METH_VARARGS, (const char *)gPySetCcdMode__doc__}, + {"setSorConstant",(PyCFunction) gPySetSorConstant, + METH_VARARGS, (const char *)gPySetSorConstant__doc__}, + {"setSolverTau",(PyCFunction) gPySetSolverTau, + METH_VARARGS, (const char *)gPySetSolverTau__doc__}, + {"setSolverDamping",(PyCFunction) gPySetSolverDamping, + METH_VARARGS, (const char *)gPySetSolverDamping__doc__}, + + {"setLinearAirDamping",(PyCFunction) gPySetLinearAirDamping, + METH_VARARGS, (const char *)gPySetLinearAirDamping__doc__}, + + {"setUseEpa",(PyCFunction) gPySetUseEpa, + METH_VARARGS, (const char *)gPySetUseEpa__doc__}, {"setSolverType",(PyCFunction) gPySetSolverType, - METH_VARARGS, (const char *)gPySetSolverType__doc__}, + METH_VARARGS, (const char *)gPySetSolverType__doc__}, - {"createConstraint",(PyCFunction) gPyCreateConstraint, - METH_VARARGS, (const char *)gPyCreateConstraint__doc__}, - {"getVehicleConstraint",(PyCFunction) gPyGetVehicleConstraint, - METH_VARARGS, (const char *)gPyGetVehicleConstraint__doc__}, + {"createConstraint",(PyCFunction) gPyCreateConstraint, + METH_VARARGS, (const char *)gPyCreateConstraint__doc__}, + {"getVehicleConstraint",(PyCFunction) gPyGetVehicleConstraint, + METH_VARARGS, (const char *)gPyGetVehicleConstraint__doc__}, - {"removeConstraint",(PyCFunction) gPyRemoveConstraint, - METH_VARARGS, (const char *)gPyRemoveConstraint__doc__}, + {"removeConstraint",(PyCFunction) gPyRemoveConstraint, + METH_VARARGS, (const char *)gPyRemoveConstraint__doc__}, {"getAppliedImpulse",(PyCFunction) gPyGetAppliedImpulse, - METH_VARARGS, (const char *)gPyGetAppliedImpulse__doc__}, + METH_VARARGS, (const char *)gPyGetAppliedImpulse__doc__}, - {"exportBulletFile",(PyCFunction)gPyExportBulletFile, - METH_VARARGS, "export a .bullet file"}, + {"exportBulletFile",(PyCFunction)gPyExportBulletFile, + METH_VARARGS, "export a .bullet file"}, - - //sentinel - { NULL, (PyCFunction) NULL, 0, NULL } + //sentinel + { NULL, (PyCFunction) NULL, 0, NULL } }; static struct PyModuleDef PhysicsConstraints_module_def = { @@ -656,12 +657,13 @@ static struct PyModuleDef PhysicsConstraints_module_def = { 0, /* m_free */ }; -PyObject* initPythonConstraintBinding() +PyObject* initPythonConstraintBinding() { - PyObject* ErrorObject; - PyObject* m; - PyObject* d; + PyObject* ErrorObject; + PyObject* m; + PyObject* d; + PyObject* item; /* Use existing module where possible * be careful not to init any runtime vars after this */ @@ -677,21 +679,43 @@ PyObject* initPythonConstraintBinding() PyDict_SetItemString(PySys_GetObject("modules"), PhysicsConstraints_module_def.m_name, m); } - // Add some symbolic constants to the module - d = PyModule_GetDict(m); - ErrorObject = PyUnicode_FromString("PhysicsConstraints.error"); - PyDict_SetItemString(d, "error", ErrorObject); - Py_DECREF(ErrorObject); - - // XXXX Add constants here - - // Check for errors - if (PyErr_Occurred()) - { - Py_FatalError("can't initialize module PhysicsConstraints"); - } - - return d; + // Add some symbolic constants to the module + d = PyModule_GetDict(m); + ErrorObject = PyUnicode_FromString("PhysicsConstraints.error"); + PyDict_SetItemString(d, "error", ErrorObject); + Py_DECREF(ErrorObject); + +#ifdef USE_BULLET + //Debug Modes constants to be used with setDebugMode() python function + KX_MACRO_addTypesToDict(d, DBG_NODEBUG, btIDebugDraw::DBG_NoDebug); + KX_MACRO_addTypesToDict(d, DBG_DRAWWIREFRAME, btIDebugDraw::DBG_DrawWireframe); + KX_MACRO_addTypesToDict(d, DBG_DRAWAABB, btIDebugDraw::DBG_DrawAabb); + KX_MACRO_addTypesToDict(d, DBG_DRAWFREATURESTEXT, btIDebugDraw::DBG_DrawFeaturesText); + KX_MACRO_addTypesToDict(d, DBG_DRAWCONTACTPOINTS, btIDebugDraw::DBG_DrawContactPoints); + KX_MACRO_addTypesToDict(d, DBG_NOHELPTEXT, btIDebugDraw::DBG_NoHelpText); + KX_MACRO_addTypesToDict(d, DBG_DRAWTEXT, btIDebugDraw::DBG_DrawText); + KX_MACRO_addTypesToDict(d, DBG_PROFILETIMINGS, btIDebugDraw::DBG_ProfileTimings); + KX_MACRO_addTypesToDict(d, DBG_ENABLESATCOMPARISION, btIDebugDraw::DBG_EnableSatComparison); + KX_MACRO_addTypesToDict(d, DBG_DISABLEBULLETLCP, btIDebugDraw::DBG_DisableBulletLCP); + KX_MACRO_addTypesToDict(d, DBG_ENABLECDD, btIDebugDraw::DBG_EnableCCD); + KX_MACRO_addTypesToDict(d, DBG_DRAWCONSTRAINTS, btIDebugDraw::DBG_DrawConstraints); + KX_MACRO_addTypesToDict(d, DBG_DRAWCONSTRAINTLIMITS, btIDebugDraw::DBG_DrawConstraintLimits); + KX_MACRO_addTypesToDict(d, DBG_FASTWIREFRAME, btIDebugDraw::DBG_FastWireframe); +#endif // USE_BULLET + + //Constraint types to be used with createConstraint() python function + KX_MACRO_addTypesToDict(d, POINTTOPOINT_CONSTRAINT, PHY_POINT2POINT_CONSTRAINT); + KX_MACRO_addTypesToDict(d, LINEHINGE_CONSTRAINT, PHY_LINEHINGE_CONSTRAINT); + KX_MACRO_addTypesToDict(d, ANGULAR_CONSTRAINT, PHY_ANGULAR_CONSTRAINT); + KX_MACRO_addTypesToDict(d, CONETWIST_CONSTRAINT, PHY_CONE_TWIST_CONSTRAINT); + KX_MACRO_addTypesToDict(d, VEHICLE_CONSTRAINT, PHY_VEHICLE_CONSTRAINT); + + // Check for errors + if (PyErr_Occurred()) { + Py_FatalError("can't initialize module PhysicsConstraints"); + } + + return d; } @@ -709,7 +733,4 @@ PHY_IPhysicsEnvironment* PHY_GetActiveEnvironment() return g_CurrentActivePhysicsEnvironment; } - - #endif // WITH_PYTHON - diff --git a/source/gameengine/Ketsji/KX_PyMath.h b/source/gameengine/Ketsji/KX_PyMath.h index 9b198f85664..4864482c33b 100644 --- a/source/gameengine/Ketsji/KX_PyMath.h +++ b/source/gameengine/Ketsji/KX_PyMath.h @@ -49,7 +49,7 @@ #ifdef WITH_PYTHON #ifdef USE_MATHUTILS extern "C" { -#include "../../blender/python/generic/mathutils.h" /* so we can have mathutils callbacks */ +#include "../../blender/python/mathutils/mathutils.h" /* so we can have mathutils callbacks */ } #endif diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index f984538fa5b..fb39e944559 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -54,7 +54,7 @@ extern "C" { #include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */ #include "py_capi_utils.h" - #include "mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use. + #include "mathutils.h" // 'mathutils' module copied here so the blenderlayer can use. #include "bgl.h" #include "blf_py_api.h" @@ -115,6 +115,7 @@ extern "C" { #include "NG_NetworkScene.h" //Needed for sendMessage() #include "BL_Shader.h" +#include "BL_Action.h" #include "KX_PyMath.h" @@ -336,7 +337,7 @@ static PyObject* gPyLoadGlobalDict(PyObject*) { char marshal_path[512]; char *marshal_buffer = NULL; - unsigned int marshal_length; + size_t marshal_length; FILE *fp = NULL; int result; @@ -347,7 +348,7 @@ static PyObject* gPyLoadGlobalDict(PyObject*) if (fp) { // obtain file size: fseek (fp, 0, SEEK_END); - marshal_length = ftell(fp); + marshal_length = (size_t)ftell(fp); rewind(fp); marshal_buffer = (char*)malloc (sizeof(char)*marshal_length); @@ -397,10 +398,10 @@ static PyObject* gPyGetSpectrum(PyObject*) { PyObject* resultlist = PyList_New(512); - for (int index = 0; index < 512; index++) - { - PyList_SET_ITEM(resultlist, index, PyFloat_FromDouble(0.0)); - } + for (int index = 0; index < 512; index++) + { + PyList_SET_ITEM(resultlist, index, PyFloat_FromDouble(0.0)); + } return resultlist; } @@ -487,13 +488,13 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args) char cpath[sizeof(gp_GamePythonPath)]; char *searchpath = NULL; PyObject* list, *value; - - DIR *dp; - struct dirent *dirp; - + + DIR *dp; + struct dirent *dirp; + if (!PyArg_ParseTuple(args, "|s:getBlendFileList", &searchpath)) return NULL; - + list = PyList_New(0); if (searchpath) { @@ -503,23 +504,23 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args) /* Get the dir only */ BLI_split_dirfile(gp_GamePythonPath, cpath, NULL); } - - if((dp = opendir(cpath)) == NULL) { + + if((dp = opendir(cpath)) == NULL) { /* todo, show the errno, this shouldnt happen anyway if the blendfile is readable */ fprintf(stderr, "Could not read directoty (%s) failed, code %d (%s)\n", cpath, errno, strerror(errno)); return list; - } + } - while ((dirp = readdir(dp)) != NULL) { + while ((dirp = readdir(dp)) != NULL) { if (BLI_testextensie(dirp->d_name, ".blend")) { value= PyUnicode_DecodeFSDefault(dirp->d_name); PyList_Append(list, value); Py_DECREF(value); } - } + } - closedir(dp); - return list; + closedir(dp); + return list; } static char gPyAddScene_doc[] = @@ -1216,6 +1217,28 @@ static PyObject* gPyGetMaterialType(PyObject*) return PyLong_FromSsize_t(flag); } +static PyObject* gPySetAnisotropicFiltering(PyObject*, PyObject* args) +{ + short level; + + if (!PyArg_ParseTuple(args, "h:setAnisotropicFiltering", &level)) + return NULL; + + if (level != 1 && level != 2 && level != 4 && level != 8 && level != 16) { + PyErr_SetString(PyExc_ValueError, "Rasterizer.setAnisotropicFiltering(level): Expected value of 1, 2, 4, 8, or 16 for value"); + return NULL; + } + + gp_Rasterizer->SetAnisotropicFiltering(level); + + Py_RETURN_NONE; +} + +static PyObject* gPyGetAnisotropicFiltering(PyObject*, PyObject* args) +{ + return PyLong_FromLong(gp_Rasterizer->GetAnisotropicFiltering()); +} + static PyObject* gPyDrawLine(PyObject*, PyObject* args) { PyObject* ob_from; @@ -1280,6 +1303,10 @@ static struct PyMethodDef rasterizer_methods[] = { METH_VARARGS, "set the state of a GLSL material setting"}, {"getGLSLMaterialSetting",(PyCFunction) gPyGetGLSLMaterialSetting, METH_VARARGS, "get the state of a GLSL material setting"}, + {"setAnisotropicFiltering", (PyCFunction) gPySetAnisotropicFiltering, + METH_VARARGS, "set the anisotropic filtering level (must be one of 1, 2, 4, 8, 16)"}, + {"getAnisotropicFiltering", (PyCFunction) gPyGetAnisotropicFiltering, + METH_VARARGS, "get the anisotropic filtering level"}, {"drawLine", (PyCFunction) gPyDrawLine, METH_VARARGS, "draw a line on the screen"}, { NULL, (PyCFunction) NULL, 0, NULL } @@ -1647,11 +1674,16 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack KX_MACRO_addTypesToDict(d, RM_POLYS, KX_NavMeshObject::RM_POLYS); KX_MACRO_addTypesToDict(d, RM_TRIS, KX_NavMeshObject::RM_TRIS); + /* BL_Action play modes */ + KX_MACRO_addTypesToDict(d, KX_ACTION_MODE_PLAY, BL_Action::ACT_MODE_PLAY); + KX_MACRO_addTypesToDict(d, KX_ACTION_MODE_LOOP, BL_Action::ACT_MODE_LOOP); + KX_MACRO_addTypesToDict(d, KX_ACTION_MODE_PING_PONG, BL_Action::ACT_MODE_PING_PONG); + // Check for errors if (PyErr_Occurred()) - { + { Py_FatalError("can't initialize module bge.logic"); - } + } return m; } @@ -1768,7 +1800,7 @@ static void restorePySysObjects(void) // Copied from bpy_interface.c static struct _inittab bge_internal_modules[]= { - {(char *)"mathutils", BPyInit_mathutils}, + {(char *)"mathutils", PyInit_mathutils}, {(char *)"bgl", BPyInit_bgl}, {(char *)"blf", BPyInit_blf}, {(char *)"aud", AUD_initPython}, @@ -1941,12 +1973,12 @@ PyObject* initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas) gp_Rasterizer = rasty; - PyObject* m; - PyObject* d; - PyObject* item; + PyObject* m; + PyObject* d; + PyObject* item; /* Use existing module where possible - * be careful not to init any runtime vars after this */ + * be careful not to init any runtime vars after this */ m = PyImport_ImportModule( "Rasterizer" ); if(m) { Py_DECREF(m); @@ -1954,32 +1986,32 @@ PyObject* initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas) } else { PyErr_Clear(); - + // Create the module and add the functions m = PyModule_Create(&Rasterizer_module_def); PyDict_SetItemString(PySys_GetObject("modules"), Rasterizer_module_def.m_name, m); } - // Add some symbolic constants to the module - d = PyModule_GetDict(m); - ErrorObject = PyUnicode_FromString("Rasterizer.error"); - PyDict_SetItemString(d, "error", ErrorObject); - Py_DECREF(ErrorObject); + // Add some symbolic constants to the module + d = PyModule_GetDict(m); + ErrorObject = PyUnicode_FromString("Rasterizer.error"); + PyDict_SetItemString(d, "error", ErrorObject); + Py_DECREF(ErrorObject); - /* needed for get/setMaterialType */ - KX_MACRO_addTypesToDict(d, KX_TEXFACE_MATERIAL, KX_TEXFACE_MATERIAL); - KX_MACRO_addTypesToDict(d, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL); - KX_MACRO_addTypesToDict(d, KX_BLENDER_GLSL_MATERIAL, KX_BLENDER_GLSL_MATERIAL); + /* needed for get/setMaterialType */ + KX_MACRO_addTypesToDict(d, KX_TEXFACE_MATERIAL, KX_TEXFACE_MATERIAL); + KX_MACRO_addTypesToDict(d, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL); + KX_MACRO_addTypesToDict(d, KX_BLENDER_GLSL_MATERIAL, KX_BLENDER_GLSL_MATERIAL); - // XXXX Add constants here + // XXXX Add constants here - // Check for errors - if (PyErr_Occurred()) - { - Py_FatalError("can't initialize module Rasterizer"); - } + // Check for errors + if (PyErr_Occurred()) + { + Py_FatalError("can't initialize module Rasterizer"); + } - return d; + return d; } @@ -2218,9 +2250,9 @@ PyObject* initGameKeys() // Check for errors if (PyErr_Occurred()) - { + { Py_FatalError("can't initialize module GameKeys"); - } + } return d; } diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index a683c9857aa..aecf2ab3598 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -83,7 +83,7 @@ void KX_RaySensor::Init() KX_RaySensor::~KX_RaySensor() { - /* Nothing to be done here. */ + /* Nothing to be done here. */ } @@ -279,7 +279,7 @@ bool KX_RaySensor::Evaluate() /* now pass this result to some controller */ - if (m_rayHit) + if (m_rayHit) { if (!m_bTriggered) { @@ -288,14 +288,14 @@ bool KX_RaySensor::Evaluate() m_bTriggered = true; } else - { + { // notify logicsystem that ray is STILL hitting ... result = false; - - } + + } } - else - { + else + { if (m_bTriggered) { m_bTriggered = false; @@ -306,9 +306,9 @@ bool KX_RaySensor::Evaluate() { result = false; } - - } - if (reset) + + } + if (reset) // force an event result = true; diff --git a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp index 076669e325a..c5f3fefd4d3 100644 --- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp @@ -44,11 +44,11 @@ #include "SCA_IScene.h" KX_SCA_EndObjectActuator::KX_SCA_EndObjectActuator(SCA_IObject *gameobj, - SCA_IScene* scene): - SCA_IActuator(gameobj, KX_ACT_END_OBJECT), - m_scene(scene) + SCA_IScene* scene): + SCA_IActuator(gameobj, KX_ACT_END_OBJECT), + m_scene(scene) { - // intentionally empty + // intentionally empty } /* End of constructor */ diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 5e0e46026df..00638478349 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -169,6 +169,7 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_lightlist= new CListValue(); m_inactivelist = new CListValue(); m_euthanasyobjects = new CListValue(); + m_animatedlist = new CListValue(); m_logicmgr = new SCA_LogicManager(); @@ -270,6 +271,9 @@ KX_Scene::~KX_Scene() if (m_euthanasyobjects) m_euthanasyobjects->Release(); + if (m_animatedlist) + m_animatedlist->Release(); + if (m_logicmgr) delete m_logicmgr; @@ -1519,7 +1523,22 @@ void KX_Scene::LogicBeginFrame(double curtime) m_logicmgr->BeginFrame(curtime, 1.0/KX_KetsjiEngine::GetTicRate()); } +void KX_Scene::AddAnimatedObject(CValue* gameobj) +{ + m_animatedlist->Add(gameobj); +} +void KX_Scene::RemoveAnimatedObject(CValue* gameobj) +{ + m_animatedlist->RemoveValue(gameobj); +} + +void KX_Scene::UpdateAnimations(double curtime) +{ + // Update any animations + for (int i=0; i<m_animatedlist->GetCount(); ++i) + ((KX_GameObject*)GetObjectList()->GetValue(i))->UpdateActionManager(curtime); +} void KX_Scene::LogicUpdateFrame(double curtime, bool frame) { @@ -1689,6 +1708,11 @@ double KX_Scene::getSuspendedDelta() return m_suspendeddelta; } +short KX_Scene::GetAnimationFPS() +{ + return m_blenderScene->r.frs_sec; +} + #ifdef USE_BULLET #include "KX_BulletPhysicsController.h" #endif diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 26dec2d612b..5954d5465ba 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -131,6 +131,7 @@ protected: CListValue* m_parentlist; // all 'root' parents CListValue* m_lightlist; CListValue* m_inactivelist; // all objects that are not in the active layer + CListValue* m_animatedlist; // all animated objects SG_QList m_sghead; // list of nodes that needs scenegraph update // the Dlist is not object that must be updated @@ -338,12 +339,17 @@ public: int NewRemoveObject(CValue* gameobj); void ReplaceMesh(CValue* gameobj, void* meshob, bool use_gfx, bool use_phys); + + void AddAnimatedObject(CValue* gameobj); + void RemoveAnimatedObject(CValue* gameobj); + /** * @section Logic stuff * Initiate an update of the logic system. */ void LogicBeginFrame(double curtime); void LogicUpdateFrame(double curtime, bool frame); + void UpdateAnimations(double curtime); void LogicEndFrame( @@ -569,6 +575,8 @@ public: void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* physEnv); void SetGravity(const MT_Vector3& gravity); + + short GetAnimationFPS(); /** * Sets the node tree for this scene. diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index 45ba827a1b8..6c7b515c095 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -36,16 +36,25 @@ #include "KX_SoundActuator.h" -#include "AUD_C-API.h" + +#ifdef WITH_AUDASPACE +# include "AUD_C-API.h" +# include "AUD_PingPongFactory.h" +# include "AUD_IDevice.h" +# include "AUD_I3DHandle.h" +#endif + #include "KX_GameObject.h" #include "KX_PyMath.h" // needed for PyObjectFrom() +#include "KX_PythonInit.h" +#include "KX_Camera.h" #include <iostream> /* ------------------------------------------------------------------------- */ /* Native functions */ /* ------------------------------------------------------------------------- */ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj, - AUD_Sound* sound, + AUD_Reference<AUD_IFactory> sound, float volume, float pitch, bool is3d, @@ -58,7 +67,6 @@ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj, m_pitch = pitch; m_is3d = is3d; m_3d = settings; - m_handle = NULL; m_type = type; m_isplaying = false; } @@ -67,22 +75,20 @@ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj, KX_SoundActuator::~KX_SoundActuator() { - if(m_handle) - AUD_stop(m_handle); + if(!m_handle.isNull()) + m_handle->stop(); } void KX_SoundActuator::play() { - if(m_handle) - AUD_stop(m_handle); + if(!m_handle.isNull()) + m_handle->stop(); - if(!m_sound) + if(m_sound.isNull()) return; // this is the sound that will be played and not deleted afterwards - AUD_Sound* sound = m_sound; - // this sound is for temporary stacked sounds, will be deleted if not NULL - AUD_Sound* sound2 = NULL; + AUD_Reference<AUD_IFactory> sound = m_sound; bool loop = false; @@ -90,7 +96,7 @@ void KX_SoundActuator::play() { case KX_SOUNDACT_LOOPBIDIRECTIONAL: case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: - sound = sound2 = AUD_pingpongSound(sound); + sound = new AUD_PingPongFactory(sound); // fall through case KX_SOUNDACT_LOOPEND: case KX_SOUNDACT_LOOPSTOP: @@ -102,32 +108,28 @@ void KX_SoundActuator::play() break; } - if(m_is3d) + m_handle = AUD_getDevice()->play(sound, 0); + + AUD_Reference<AUD_I3DHandle> handle3d = AUD_Reference<AUD_I3DHandle>(m_handle); + + if(m_is3d && !handle3d.isNull()) { - // sound shall be played 3D - m_handle = AUD_play(sound, 0); - - AUD_setRelative(m_handle, false); - AUD_setVolumeMaximum(m_handle, m_3d.max_gain); - AUD_setVolumeMinimum(m_handle, m_3d.min_gain); - AUD_setDistanceReference(m_handle, m_3d.reference_distance); - AUD_setDistanceMaximum(m_handle, m_3d.max_distance); - AUD_setAttenuation(m_handle, m_3d.rolloff_factor); - AUD_setConeAngleInner(m_handle, m_3d.cone_inner_angle); - AUD_setConeAngleOuter(m_handle, m_3d.cone_outer_angle); - AUD_setConeVolumeOuter(m_handle, m_3d.cone_outer_gain); + handle3d->setRelative(true); + handle3d->setVolumeMaximum(m_3d.max_gain); + handle3d->setVolumeMinimum(m_3d.min_gain); + handle3d->setDistanceReference(m_3d.reference_distance); + handle3d->setDistanceMaximum(m_3d.max_distance); + handle3d->setAttenuation(m_3d.rolloff_factor); + handle3d->setConeAngleInner(m_3d.cone_inner_angle); + handle3d->setConeAngleOuter(m_3d.cone_outer_angle); + handle3d->setConeVolumeOuter(m_3d.cone_outer_gain); } - else - m_handle = AUD_play(sound, 0); if(loop) - AUD_setLoop(m_handle, -1); - AUD_setSoundPitch(m_handle, m_pitch); - AUD_setSoundVolume(m_handle, m_volume); + m_handle->setLoopCount(-1); + m_handle->setPitch(m_pitch); + m_handle->setVolume(m_volume); m_isplaying = true; - - if(sound2) - AUD_unload(sound2); } CValue* KX_SoundActuator::GetReplica() @@ -140,7 +142,7 @@ CValue* KX_SoundActuator::GetReplica() void KX_SoundActuator::ProcessReplica() { SCA_IActuator::ProcessReplica(); - m_handle = 0; + m_handle = AUD_Reference<AUD_IHandle>(); } bool KX_SoundActuator::Update(double curtime, bool frame) @@ -155,11 +157,11 @@ bool KX_SoundActuator::Update(double curtime, bool frame) RemoveAllEvents(); - if(!m_sound) + if(m_sound.isNull()) return false; // actual audio device playing state - bool isplaying = AUD_getStatus(m_handle) == AUD_STATUS_PLAYING; + bool isplaying = m_handle.isNull() ? false : (m_handle->getStatus() == AUD_STATUS_PLAYING); if (bNegativeEvent) { @@ -173,7 +175,9 @@ bool KX_SoundActuator::Update(double curtime, bool frame) case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: { // stop immediately - AUD_stop(m_handle); + if(!m_handle.isNull()) + m_handle->stop(); + m_handle = AUD_Reference<AUD_IHandle>(); break; } case KX_SOUNDACT_PLAYEND: @@ -185,7 +189,8 @@ bool KX_SoundActuator::Update(double curtime, bool frame) case KX_SOUNDACT_LOOPBIDIRECTIONAL: { // stop the looping so that the sound stops when it finished - AUD_setLoop(m_handle, 0); + if(!m_handle.isNull()) + m_handle->setLoopCount(0); break; } default: @@ -211,21 +216,35 @@ bool KX_SoundActuator::Update(double curtime, bool frame) play(); } // verify that the sound is still playing - isplaying = AUD_getStatus(m_handle) == AUD_STATUS_PLAYING ? true : false; + isplaying = m_handle.isNull() ? false : (m_handle->getStatus() == AUD_STATUS_PLAYING); if (isplaying) { - if(m_is3d) + AUD_Reference<AUD_I3DHandle> handle3d = AUD_Reference<AUD_I3DHandle>(m_handle); + + if(m_is3d && !handle3d.isNull()) { - KX_GameObject* obj = (KX_GameObject*)this->GetParent(); - float f[4]; - - obj->NodeGetWorldPosition().getValue(f); - AUD_setSourceLocation(m_handle, f); - obj->GetLinearVelocity().getValue(f); - AUD_setSourceVelocity(m_handle, f); - obj->NodeGetWorldOrientation().getRotation().getValue(f); - AUD_setSourceOrientation(m_handle, f); + KX_Camera* cam = KX_GetActiveScene()->GetActiveCamera(); + if (cam) + { + KX_GameObject* obj = (KX_GameObject*)this->GetParent(); + MT_Point3 p; + MT_Matrix3x3 Mo; + AUD_Vector3 v; + float q[4]; + + Mo = cam->NodeGetWorldOrientation().inverse(); + p = (obj->NodeGetWorldPosition() - cam->NodeGetWorldPosition()); + p = Mo * p; + p.getValue(v.get()); + handle3d->setSourceLocation(v); + p = (obj->GetLinearVelocity() - cam->GetLinearVelocity()); + p = Mo * p; + p.getValue(v.get()); + handle3d->setSourceVelocity(v); + (Mo * obj->NodeGetWorldOrientation()).getRotation().getValue(q); + handle3d->setSourceOrientation(AUD_Quaternion(q[3], q[0], q[1], q[2])); + } } result = true; } @@ -237,7 +256,6 @@ bool KX_SoundActuator::Update(double curtime, bool frame) return result; } - #ifdef WITH_PYTHON /* ------------------------------------------------------------------------- */ @@ -286,6 +304,7 @@ PyAttributeDef KX_SoundActuator::Attributes[] = { KX_PYATTRIBUTE_RW_FUNCTION("cone_angle_inner", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), KX_PYATTRIBUTE_RW_FUNCTION("cone_angle_outer", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), KX_PYATTRIBUTE_RW_FUNCTION("cone_volume_outer", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), + KX_PYATTRIBUTE_RW_FUNCTION("sound", KX_SoundActuator, pyattr_get_sound, pyattr_set_sound), KX_PYATTRIBUTE_RW_FUNCTION("time", KX_SoundActuator, pyattr_get_audposition, pyattr_set_audposition), KX_PYATTRIBUTE_RW_FUNCTION("volume", KX_SoundActuator, pyattr_get_gain, pyattr_set_gain), @@ -299,15 +318,18 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound, "startSound()\n" "\tStarts the sound.\n") { - switch(AUD_getStatus(m_handle)) + if(!m_handle.isNull()) { - case AUD_STATUS_PLAYING: - break; - case AUD_STATUS_PAUSED: - AUD_resume(m_handle); - break; - default: - play(); + switch(m_handle->getStatus()) + { + case AUD_STATUS_PLAYING: + break; + case AUD_STATUS_PAUSED: + m_handle->resume(); + break; + default: + play(); + } } Py_RETURN_NONE; } @@ -316,7 +338,8 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, pauseSound, "pauseSound()\n" "\tPauses the sound.\n") { - AUD_pause(m_handle); + if(!m_handle.isNull()) + m_handle->pause(); Py_RETURN_NONE; } @@ -324,7 +347,9 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound, "stopSound()\n" "\tStops the sound.\n") { - AUD_stop(m_handle); + if(!m_handle.isNull()) + m_handle->stop(); + m_handle = AUD_Reference<AUD_IHandle>(); Py_RETURN_NONE; } @@ -372,8 +397,8 @@ PyObject* KX_SoundActuator::pyattr_get_audposition(void *self, const struct KX_P KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); float position = 0.0; - if(actuator->m_handle) - position = AUD_getPosition(actuator->m_handle); + if(!actuator->m_handle.isNull()) + position = actuator->m_handle->getPosition(); PyObject* result = PyFloat_FromDouble(position); @@ -400,6 +425,15 @@ PyObject* KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRI return result; } +PyObject* KX_SoundActuator::pyattr_get_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); + if(!actuator->m_sound.isNull()) + return AUD_getPythonFactory(&actuator->m_sound); + else + Py_RETURN_NONE; +} + int KX_SoundActuator::pyattr_set_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); @@ -409,49 +443,50 @@ int KX_SoundActuator::pyattr_set_3d_property(void *self, const struct KX_PYATTRI if (!PyArg_Parse(value, "f", &prop_value)) return PY_SET_ATTR_FAIL; + AUD_Reference<AUD_I3DHandle> handle3d = AUD_Reference<AUD_I3DHandle>(actuator->m_handle); // if sound is working and 3D, set the new setting if(!actuator->m_is3d) return PY_SET_ATTR_FAIL; if(!strcmp(prop, "volume_maximum")) { actuator->m_3d.max_gain = prop_value; - if(actuator->m_handle) - AUD_setVolumeMaximum(actuator->m_handle, prop_value); + if(!handle3d.isNull()) + handle3d->setVolumeMaximum(prop_value); } else if (!strcmp(prop, "volume_minimum")) { actuator->m_3d.min_gain = prop_value; - if(actuator->m_handle) - AUD_setVolumeMinimum(actuator->m_handle, prop_value); + if(!handle3d.isNull()) + handle3d->setVolumeMinimum(prop_value); } else if (!strcmp(prop, "distance_reference")) { actuator->m_3d.reference_distance = prop_value; - if(actuator->m_handle) - AUD_setDistanceReference(actuator->m_handle, prop_value); + if(!handle3d.isNull()) + handle3d->setDistanceReference(prop_value); } else if (!strcmp(prop, "distance_maximum")) { actuator->m_3d.max_distance = prop_value; - if(actuator->m_handle) - AUD_setDistanceMaximum(actuator->m_handle, prop_value); + if(!handle3d.isNull()) + handle3d->setDistanceMaximum(prop_value); } else if (!strcmp(prop, "attenuation")) { actuator->m_3d.rolloff_factor = prop_value; - if(actuator->m_handle) - AUD_setAttenuation(actuator->m_handle, prop_value); + if(!handle3d.isNull()) + handle3d->setAttenuation(prop_value); } else if (!!strcmp(prop, "cone_angle_inner")) { actuator->m_3d.cone_inner_angle = prop_value; - if(actuator->m_handle) - AUD_setConeAngleInner(actuator->m_handle, prop_value); + if(!handle3d.isNull()) + handle3d->setConeAngleInner(prop_value); } else if (!strcmp(prop, "cone_angle_outer")) { actuator->m_3d.cone_outer_angle = prop_value; - if(actuator->m_handle) - AUD_setConeAngleOuter(actuator->m_handle, prop_value); + if(!handle3d.isNull()) + handle3d->setConeAngleOuter(prop_value); } else if (!strcmp(prop, "cone_volume_outer")) { actuator->m_3d.cone_outer_gain = prop_value; - if(actuator->m_handle) - AUD_setConeVolumeOuter(actuator->m_handle, prop_value); + if(!handle3d.isNull()) + handle3d->setConeVolumeOuter(prop_value); } else { return PY_SET_ATTR_FAIL; @@ -468,8 +503,8 @@ int KX_SoundActuator::pyattr_set_audposition(void *self, const struct KX_PYATTRI if (!PyArg_Parse(value, "f", &position)) return PY_SET_ATTR_FAIL; - if(actuator->m_handle) - AUD_seek(actuator->m_handle, position); + if(!actuator->m_handle.isNull()) + actuator->m_handle->seek(position); return PY_SET_ATTR_SUCCESS; } @@ -481,8 +516,8 @@ int KX_SoundActuator::pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DE return PY_SET_ATTR_FAIL; actuator->m_volume = gain; - if(actuator->m_handle) - AUD_setSoundVolume(actuator->m_handle, gain); + if(!actuator->m_handle.isNull()) + actuator->m_handle->setVolume(gain); return PY_SET_ATTR_SUCCESS; } @@ -495,10 +530,28 @@ int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_D return PY_SET_ATTR_FAIL; actuator->m_pitch = pitch; - if(actuator->m_handle) - AUD_setSoundPitch(actuator->m_handle, pitch); + if(!actuator->m_handle.isNull()) + actuator->m_handle->setPitch(pitch); return PY_SET_ATTR_SUCCESS; } +int KX_SoundActuator::pyattr_set_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + PyObject* sound = NULL; + KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); + if (!PyArg_Parse(value, "O", &sound)) + return PY_SET_ATTR_FAIL; + + AUD_Reference<AUD_IFactory>* snd = reinterpret_cast<AUD_Reference<AUD_IFactory>*>(AUD_getPythonSound(sound)); + if(snd) + { + actuator->m_sound = *snd; + delete snd; + return PY_SET_ATTR_SUCCESS; + } + + return PY_SET_ATTR_FAIL; +} + #endif // WITH_PYTHON diff --git a/source/gameengine/Ketsji/KX_SoundActuator.h b/source/gameengine/Ketsji/KX_SoundActuator.h index e7257245a80..b1161e0cad2 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.h +++ b/source/gameengine/Ketsji/KX_SoundActuator.h @@ -36,7 +36,13 @@ #include "SCA_IActuator.h" -#include "AUD_C-API.h" +#ifdef WITH_AUDASPACE +# include "AUD_C-API.h" +# include "AUD_Reference.h" +# include "AUD_IFactory.h" +# include "AUD_IHandle.h" +#endif + #include "BKE_sound.h" typedef struct KX_3DSoundSettings @@ -53,14 +59,14 @@ typedef struct KX_3DSoundSettings class KX_SoundActuator : public SCA_IActuator { - Py_Header; - bool m_isplaying; - AUD_Sound* m_sound; + Py_Header; + bool m_isplaying; + AUD_Reference<AUD_IFactory> m_sound; float m_volume; float m_pitch; bool m_is3d; KX_3DSoundSettings m_3d; - AUD_Channel* m_handle; + AUD_Reference<AUD_IHandle> m_handle; void play(); @@ -81,7 +87,7 @@ public: KX_SOUNDACT_TYPE m_type; KX_SoundActuator(SCA_IObject* gameobj, - AUD_Sound* sound, + AUD_Reference<AUD_IFactory> sound, float volume, float pitch, bool is3d, @@ -110,12 +116,14 @@ public: static int pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int pyattr_set_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static PyObject* pyattr_get_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); #endif // WITH_PYTHON diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index edcba969811..f13f152c5d5 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -54,16 +54,16 @@ KX_TrackToActuator::KX_TrackToActuator(SCA_IObject *gameobj, - SCA_IObject *ob, - int time, - bool allow3D, - int trackflag, - int upflag) - : SCA_IActuator(gameobj, KX_ACT_TRACKTO) + SCA_IObject *ob, + int time, + bool allow3D, + int trackflag, + int upflag) + : SCA_IActuator(gameobj, KX_ACT_TRACKTO) { - m_time = time; - m_allow3D = allow3D; - m_object = ob; + m_time = time; + m_allow3D = allow3D; + m_object = ob; m_trackflag = trackflag; m_upflag = upflag; m_parentobj = 0; diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h index c5e96bd7454..bbf0134a859 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.h +++ b/source/gameengine/Ketsji/KX_TrackToActuator.h @@ -57,7 +57,7 @@ class KX_TrackToActuator : public SCA_IActuator public: KX_TrackToActuator(SCA_IObject* gameobj, SCA_IObject *ob, int time, - bool threedee,int trackflag,int upflag); + bool threedee,int trackflag,int upflag); virtual ~KX_TrackToActuator(); virtual CValue* GetReplica() { KX_TrackToActuator* replica = new KX_TrackToActuator(*this); diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index 11dd0e5a4bf..7c9785c24e7 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -6,15 +6,16 @@ Import ('env') sources = env.Glob('*.cpp') defs = [ 'GLEW_STATIC' ] -incs = '. #source/blender/python/generic' # Only for Mathutils! and bpy_internal_import.h, be very careful +incs = '. #source/blender/python/generic' # Only for bpy_internal_import.h, be very careful +incs += ' #source/blender/python/mathutils' # Only for mathutils, be very careful incs += ' #intern/string #intern/guardedalloc #intern/container' incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer' -incs += ' #intern/audaspace/intern #source/gameengine/Converter' +incs += ' #intern/audaspace/intern #intern/audaspace/FX #source/gameengine/Converter' incs += ' #source/gameengine/BlenderRoutines #source/blender/imbuf #intern/moto/include' incs += ' #source/gameengine/Ketsji #source/gameengine/Ketsji/KXNetwork #source/blender/blenlib #source/blender/blenfont' incs += ' #source/blender/blenkernel #source/blender #source/blender/editors/include' -incs += ' #source/blender/makesdna #source/blender/python #source/gameengine/Rasterizer' +incs += ' #source/blender/makesdna #source/blender/makesrna #source/blender/python #source/gameengine/Rasterizer' incs += ' #source/gameengine/GameLogic #source/gameengine/Expressions #source/gameengine/Network' incs += ' #source/gameengine/SceneGraph #source/gameengine/Physics/common' incs += ' #source/gameengine/Physics/Dummy' @@ -36,7 +37,7 @@ if env['WITH_BF_PYTHON']: if env['WITH_BF_FFMPEG']: defs.append('WITH_FFMPEG') - + if env['OURPLATFORM'] in ('win32-vc', 'win64-vc', 'win32-mingw'): if env['BF_DEBUG']: defs.append('_DEBUG') # for Python |