Commit Graph

78 Commits

Author SHA1 Message Date
Jorge Bernal
0c19a043e8 BGE Ketsji clean-up: double-promotion warnings 2015-12-16 01:53:48 +01:00
Porteries Tristan
720d4521cd BGE : Collision mask support in raycast + and raycast cleanup.
I have removed the m_pHitObject, m_xray and m_testPropName and replace them by a temporary struct "RayCastData" which contains these datas and a collision mask. Finally i add a collision mask argument in the python function "rayCast" :
```
rayCast(to, from, dist, prop, face, xray, poly, mask)
```

It can be useful to hit only object which are on the right colision layer. for example if you have hitbox for a charater or vehicle you don't want to hit it with raycast.

test file : {F237337}
left mouse click on two planes and see console messages.

Somewhat more elaborate test file by @sybren: {F237779}
Look around and click on the cubes. One cube lamp responds, the other doesn't, based on their collision groups.

Reviewers: moguri, hg1, agoose77, campbellbarton, sybren

Reviewed By: agoose77, campbellbarton, sybren

Subscribers: campbellbarton, sergey, blueprintrandom, sybren

Projects: #game_engine, #game_physics

Differential Revision: https://developer.blender.org/D1239
2015-10-07 22:14:43 +02:00
Porteries Tristan
9939c18900 BGE: Fix T35288 Touch/Ray/Mouse sensor and Constraint actuator with material check doesn't work.
Now we look at all materials instead of the first. So m_auxilary_info is useless and removed.
2015-07-25 09:43:06 +02:00
Campbell Barton
75a86d6a8e Fix for building without Python 2015-06-14 04:53:10 +10:00
Campbell Barton
46e2d5ee41 Cleanup: typo 2014-11-21 14:16:35 +01:00
Campbell Barton
d2c350b0a4 Quiet reorder warning 2014-08-08 14:45:38 +10:00
Mitchell Stokes
7307973063 BGE: Add property/material detection and X-Ray for mouse over any sensor
This patch adds a Property/Material detection and a X-Ray mode to the mouse over any sensor like on the ray sensor.

Proposal:
http://blenderartists.org/forum/showthread.php?261847-BGE-proposal-Mouse-Over-Any-sensor-with-Property-and-X-Ray&highlight=proposal

Reviewers: moguri

Reviewed By: moguri

Differential Revision: https://developer.blender.org/D653
2014-07-17 23:00:30 -07:00
Mitchell Stokes
b90de0331d BGE: Cleaning up the BGE's physics code and removing KX_IPhysicsController and KX_BulletPhysicsController. Instead, we just use PHY_IPhysicsController, which removes a lot of duplicate code.
This is a squashed commit of the following:
    BGE Physics Cleanup: Fix crashes with LibLoading and replication. Also fixing some memory leaks.
    BGE Physics Cleanup: Removing KX_IPhysicsController and KX_BulletPhysicsController.
    BGE Physics Cleanup: Moving the replication code outside of KX_BlenderBulletController and switching KX_ConvertPhysicsObjects to create a CcdPhysicsController instead of a KX_BlenderBulletController.
    BGE Physics Cleanup: Getting rid of an unsued KX_BulletPhysicsController.h include in KX_Scene.cpp.
    BGE Physics Cleanup: Removing unused KX_IPhysicsController and KX_BulletPhysicsController includes.
    BGE Physics Cleanup: Removing m_pPhysicsController1 and GetPhysicsController1() from KX_GameObject.
    BGE Physics Cleanup: Remove SetRigidBody() from KX_IPhysicsController and remove GetName() from CcdPhysicsController.
    BGE Physics Cleanup: Moving Add/RemoveCompoundChild() from KX_IPhysicsController to PHY_IPhysicsController.
    BGE Physics Cleanup: Removing GetLocalInertia() from KX_IPhysicsController.
    BGE Physics Cleanup: Making BlenderBulletCharacterController derive from PHY_ICharacter and removing CharacterWrapper from CcdPhysicsEnvironment.cpp. Also removing the character functions from KX_IPhysicsController.
    BGE Physics Cleanup: Removing GetOrientation(), SetOrientation(), SetPosition(), SetScaling(), and GetRadius() from KX_IPhysicsController.
    BGE Physics Cleanup: Removing GetReactionForce() since all implementations returned (0, 0, 0). The Python interface for KX_GameObject still has reaction force code, but it still also returns (0, 0, 0). This can probably be removed as well, but removing it can break scripts, so I'll leave it for now.
    BGE Physics Cleanup: Removing Get/SetLinVelocityMin() and Get/SetLinVelocityMax() from KX_IPhysicsController.
    BGE Physics Cleanup: Removing SetMargin(), RelativeTranslate(), and RelativeRotate() from KX_IPhysicsController.
    BGE Physics Cleanup: Using constant references for function arguments in PHY_IPhysicsController where appropriate.
    BGE Physics Cleanup: Removing ApplyImpulse() from KX_IPhysicsController.
    BGE Physics Cleanup: Removing ResolveCombinedVelocities() from KX_IPhysicsController.
    BGE Physics Cleanup: Accidently removed a return when cleaning up KX_GameObject::PyGetVelocity().
    BGE Physics Cleanup: Remove GetLinearVelocity(), GetAngularVelocity() and GetVelocity() from KX_IPhysicsController. The corresponding PHY_IPhysicsController functions now also take Moto types instead of scalars to match the KX_IPhysicsController interface.
    BGE Physics Cleanup: Moving SuspendDynamics, RestoreDynamics, SetMass, GetMass, and SetTransform from KX_IPhysicsController to PHY_IPhysicsController.
    BGE Physics Cleanup: PHY_IPhysicsEnvironment and derived classes now use the same naming scheme as PHY_IController.
    BGE Physics Cleanup: PHY_IMotionState and derived classes now use the same naming convention as PHY_IController.
    BGE Phsyics Cleanup: Making PHY_IController and its derived classes follow a consistent naming scheme for member functions. They now all start with capital letters (e.g., setWorldOrientation becomes SetWorldOrientation).
    BGE Physics Cleanup: Getting rid of KX_GameObject::SuspendDynamics() and KX_GameObject::RestoreDynamics(). Instead, use the functions from the physics controller.
    BGE: Some first steps in trying to cleanup the KX_IPhysicsController mess. KX_GameObject now has a GetPhysicsController() and a GetPhysicsController1(). The former returns a PHY_IPhysicsController* while the latter returns a KX_IPhysicsController. The goal is to get everything using GetPhysicsController() instead of GetPhysicsController1().
2013-11-04 19:22:47 +00:00
Campbell Barton
64d161de87 style cleanup:
also rename mesh_getVertexCos() --> BKE_mesh_vertexCos_get() to match curve function.
2013-03-26 07:29:01 +00:00
Campbell Barton
ddc2dbc2a4 style cleanup 2012-10-22 08:15:51 +00:00
Campbell Barton
d599b643b7 style cleanup: bge, switch statements mostly.
also left bmesh decimator on in previous commit.
2012-10-21 07:58:38 +00:00
Campbell Barton
7deb8d8a26 code cleanup: spelling 2012-10-20 20:36:51 +00:00
Campbell Barton
4d4664d98f code cleanup: check for msvc directly when using warning pragma's. 2012-10-15 02:15:07 +00:00
Campbell Barton
2fb8292005 style cleanup 2012-09-16 04:58:18 +00:00
Campbell Barton
b8a71efeba style cleanup: follow style guide for/with/if spacing 2012-03-24 07:52:14 +00:00
Campbell Barton
89a963fb7f style cleanup: comment blocks 2012-03-09 18:28:30 +00:00
Campbell Barton
ea13ec1699 Spelling Cleanup 2012-03-01 12:20:18 +00:00
Campbell Barton
4a04f72069 remove $Id: tags after discussion on the mailign list: http://markmail.org/message/fp7ozcywxum3ar7n 2011-10-23 17:52:20 +00:00
Dalai Felinto
415f35d1dc bge bugfix: patch #28893 "Fix for #28753 and some other changes for BGE projection code" by Juha Mäki-Kanto (kanttori) 2011-10-20 06:38:45 +00:00
Campbell Barton
2365c64014 whitespace bge edits 2011-09-01 02:12:53 +00:00
Nathan Letwory
bb6e7faf72 doxygen: gameengine/Ketsji tagged. 2011-02-25 13:35:59 +00:00
Nathan Letwory
5b607701a7 doxygen: prevent GPL license block from being parsed as doxygen comment. 2011-02-23 10:52:22 +00:00
Campbell Barton
0876fce009 rename and negate DISABLE_PYTHON --> WITH_PYTHON 2010-10-31 04:11:39 +00:00
Campbell Barton
9b518710c6 update for MingW/CMake
- ignore MSVC warnings when FREE_WINDOWS is defined to quiet warnings.
- the CMake flags were not being set correctly making blender have weirdo colors (no -funsigned-char).
2010-09-15 16:13:32 +00:00
Campbell Barton
081c1205a3 correct fsf address 2010-02-12 13:34:04 +00:00
Benoit Bolsee
d765068fca BGE: add hitUV property to mouse focus sensor to return UV coordinates under mouse pointer. Useful for texture painting. More details in PyDoc. 2009-12-08 08:58:24 +00:00
Campbell Barton
98ee2a781d option to build the BGE without python, uses existing python check (cmake and scons)
when python is disabled videotextures are not built.
2009-09-29 21:42:40 +00:00
Campbell Barton
0a23895f95 remove all python api functions deprecated in 2.49 2009-08-25 22:51:18 +00:00
Campbell Barton
01d4748e5f svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22704:22717 2009-08-23 07:46:34 +00:00
Campbell Barton
4a4a3b4989 Option for MouseFocus sensor. only used when 'Mouse over any' type is set.
Previously the only way to detect if the mouse moved over a different object was to enable true-level-triggering and have a python script detect the change.

When the Pulse option is set, focusing on a different object pulses true.
Python attribute is focusSensor.usePulseFocus.

This is similar to the collision sensors pulse option where changes in the set of collision objects generates an event too.

Found this functionality missing when trying to make a logic demo that used mouse-over with overlapping objects.
2009-08-23 06:17:59 +00:00
Campbell Barton
7440fee85c remove python2.x support 2009-08-10 00:07:34 +00:00
Campbell Barton
9a7ea9664e BGE PyAPI support for subclassing any BGE game type from python, scripters define extra functions on gameObjects.
Adding a UI to set the type on startup can be added easily.

# ----
class myPlayer(GameTypes.KX_GameObject):
  def die(self):
    # ... do stuff ...
    self.endObject()

# make an instance
player = myPlayer(gameOb) # gameOb is made invalid now.
player.die()

# ----

One limitation (which could also be an advantage), is making the subclass instance will return that subclass everywhere, you cant have 2 different subclasses of the same BGE data at once.
2009-06-29 12:06:46 +00:00
Campbell Barton
6b9f3b5f5c BGE Python API
Remove the last of the odd C++/python wrapper code from http://www.python.org/doc/PyCPP.html (~1998)

* Use python subclasses rather then having fake subclassing through get/set attributes calling parent types.
* PyObject getset arrays are created while initializing the types, converted from our own attribute arrays. This way python deals with subclasses and we dont have to define getattro or setattro functions for each type.
* GameObjects and Scenes no longer have attribute access to properties. only dictionary style access - ob['prop']
* remove each class's get/set/dir functions.
* remove isA() methods, can use PyObject_TypeCheck() in C and issubclass() in python.
* remove Parents[] array for each C++ class, was only used for isA() and wasnt correct in quite a few cases.
* remove PyTypeObject that was being passed as the last argument to each class (the parent classes too).

TODO -
* Light and VertexProxy need to be converted to using attributes.
* memory for getset arrays is never freed, not that bad since its will only allocates once.
2009-06-28 11:22:26 +00:00
Brecht Van Lommel
c8b4cf9206 2.50:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r19820:HEAD

Notes:
* Game and sequencer RNA, and sequencer header are now out of date
  a bit after changes in trunk.
* I didn't know how to port these bugfixes, most likely they are
  not needed anymore.
  * Fix "duplicate strip" always increase the user count for ipo.
  * IPO pinning on sequencer strips was lost during Undo.
2009-06-08 20:08:19 +00:00
Campbell Barton
9b088acc67 KX_MouseFocusSensor - bug reported by Micro27 on blenderartist
vertical bounds checking for multiple viewports was inverted.

quiet some compiler warnings and minor corrections
2009-06-03 20:06:40 +00:00
Benoit Bolsee
386122ada6 BGE performance, 4th round: logic
This commit extends the technique of dynamic linked list to the logic
system to eliminate as much as possible temporaries, map lookup or 
full scan. The logic engine is now free of memory allocation, which is
an important stability factor. 

The overhead of the logic system is reduced by a factor between 3 and 6
depending on the logic setup. This is the speed-up you can expect on 
a logic setup using simple bricks. Heavy bricks like python controllers
and ray sensors will still take about the same time to execute so the
speed up will be less important.

The core of the logic engine has been much reworked but the functionality
is still the same except for one thing: the priority system on the 
execution of controllers. The exact same remark applies to actuators but
I'll explain for controllers only:

Previously, it was possible, with the "executePriority" attribute to set
a controller to run before any other controllers in the game. Other than
that, the sequential execution of controllers, as defined in Blender was
guaranteed by default.

With the new system, the sequential execution of controllers is still 
guaranteed but only within the controllers of one object. the user can
no longer set a controller to run before any other controllers in the
game. The "executePriority" attribute controls the execution of controllers
within one object. The priority is a small number starting from 0 for the
first controller and incrementing for each controller.

If this missing feature is a must, a special method can be implemented
to set a controller to run before all other controllers.

Other improvements:
- Systematic use of reference in parameter passing to avoid unnecessary data copy
- Use pre increment in iterator instead of post increment to avoid temporary allocation
- Use const char* instead of STR_String whenever possible to avoid temporary allocation
- Fix reference counting bugs (memory leak)
- Fix a crash in certain cases of state switching and object deletion
- Minor speed up in property sensor
- Removal of objects during the game is a lot faster
2009-05-10 20:53:58 +00:00
Campbell Barton
94e9e954b1 [#18681] Mousesensor Over doesn't work in ortho mode of 3dview camera
bugfix, the clip near/far are scaled up for some reason, so use a range between 0 - clipfar for now.
2009-05-06 12:45:08 +00:00
Campbell Barton
81dfdf8374 ifdef's for future py3 support, after this adding py3 can mostly be done with defines or batch renaming funcs (with the exception of CListValue slicing)
.
No changes for py2.x.
2009-04-29 16:54:45 +00:00
Campbell Barton
217bbb7800 BGE Python API
Separate getting a normal attribute and getting __dict__, was having to do too a check for __dict__ on each class (multiple times per getattro call from python) when its not used that often.
2009-04-20 23:17:52 +00:00
Brecht Van Lommel
874c29cea8 2.50: svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r19323:HEAD
Notes:
* blenderbuttons and ICON_SNAP_PEEL_OBJECT were not merged.
2009-04-20 15:06:46 +00:00
Campbell Barton
6bc162e679 BGE Python API
removed redundant (PyObject *self) argument from python functions that are not exposed to python directly.
2009-04-19 17:29:07 +00:00
Campbell Barton
7dbc9dc719 BGE Python API cleanup - no functionality changes
- comments to PyObjectPlus.h
- remove unused/commented junk.
- renamed PyDestructor to py_base_dealloc for consistency
- all the PyTypeObject's were still using the sizeof() their class, can use sizeof(PyObjectPlus_Proxy) now which is smaller too.
2009-04-19 14:57:52 +00:00
Campbell Barton
8d2cb5bea4 BGE Python API
This changes how the BGE classes and Python work together, which hasnt changed since blender went opensource.
The main difference is PyObjectPlus - the base class for most game engine classes, no longer inherit from PyObject, and cannot be cast to a PyObject.

This has the advantage that the BGE does not have to keep 2 reference counts valid for C++ and Python.

Previously C++ classes would never be freed while python held a reference, however this reference could be problematic eg: a GameObject that isnt in a scene anymore should not be used by python, doing so could even crash blender in some cases.

Instead PyObjectPlus has a member "PyObject *m_proxy" which is lazily initialized when python needs it. m_proxy reference counts are managed by python, though it should never be freed while the C++ class exists since it holds a reference to avoid making and freeing it all the time.
When the C++ class is free'd it sets the m_proxy reference to NULL, If python accesses this variable it will raise a RuntimeError, (check the isValid attribute to see if its valid without raising an error).
- This replaces the m_zombie bool and IsZombie() tests added recently.

In python return values that used to be..
 return value->AddRef();
Are now
 return value->GetProxy();
or...
 return value->NewProxy(true); // true means python owns this C++ value which will be deleted when the PyObject is freed
2009-04-19 12:46:39 +00:00
Campbell Barton
514c78ba39 BGE MouseFocusSensor
- fix for multiple viewpors broke single viewport (both work now)
- python could get uninitialized values from m_prevTargetPoint and m_prevSourcePoint
- getting the RayDirection for python could crash blender trying to normalize a zero length vector.
- added python attributes
- removed unused canvas from the MouseFocusSensor class
2009-04-15 13:50:56 +00:00
Campbell Barton
1bc31fc7f9 BGE Bugfix
[#17678] "Mouse over" sensor broken when using viewports

Loop over all the scenes camera viewports and check the mouse is inside the viewport before casting a ray.
2009-04-14 03:08:09 +00:00
Campbell Barton
46a440c7a5 BGE Python API
- added a module for the BGE - GameTypes, only contains types.
- added KX_PYATTRIBUTE_DUMMY attributes for KX_Light, KX_PolyProxy, KX_VertexProxy, so all types should give correct results from a dir().
- added a script to check for missing methods in the epydocs - bge_api_validate_py.txt
2009-04-06 13:27:28 +00:00
Campbell Barton
fd2b115678 Python BGE API
- Initialize python types with PyType_Ready, which adds methods to the type dictionary.
- use Pythons get/setattro (uses a python string for the attribute rather then char*). Using basic C strings seems nice but internally python converts them to python strings and discards them for most functions that accept char arrays.
- Method lookups use the PyTypes dictionary (should be faster then Py_FindMethod)
- Renamed __getattr -> py_base_getattro, _getattr -> py_getattro, __repr -> py_base_repr, py_delattro, py_getattro_self etc.

From here is possible to put all the parent classes methods into each python types dictionary to avoid nested lookups (api has 4 levels of lookups in some places), tested this but its not ready yet.

Simple tests for getting a method within a loop show this to be between 0.5 and 3.2x faster then using Py_FindMethod()
2009-04-03 14:51:06 +00:00
Campbell Barton
d573e9c539 BGE Python api
Added the method into the PyType so python knows about the methods (its supposed to work this way).
This means in the future the api can use PyType_Ready() to store the methods in the types dictionary.
Python3 removes Py_FindMethod and we should not be using it anyway since its not that efficient.
2009-04-03 04:12:20 +00:00
Campbell Barton
c785532bec Py BGE API
Python dir(ob) for game types now includes attributes names,
* Use "__dict__" rather then "__methods__" attribute to be Python 3.0 compatible
* Added _getattr_dict() for getting the method and attribute names from a PyObject, rather then building it in the macro.
* Added place holder *::Attribute array, needed for the _getattr_up macro.
2009-02-26 09:04:06 +00:00
Campbell Barton
c77af31166 Minor speedups for the BGE
* Where possible use vec.setValue(x,y,z) to assign values to a vector instead of vec= MT_Vector3(x,y,z), for MT_Point and MT_Matrix types too.
* Comparing TexVerts was creating 10 MT_Vector types - instead compare as floats.
* Added SG_Spatial::SetWorldFromLocalTransform() since the local transform is use for world transform in some cases.
* removed some unneeded vars from UpdateChildCoordinates functions 
* Py API - Mouse, Ray, Radar sensors - use PyObjectFrom(vec) rather then filling the lists in each function. Use METH_NOARGS for get*() functions.
2009-02-25 06:43:03 +00:00