Commit Graph

485 Commits

Author SHA1 Message Date
Campbell Barton
b4e4ccf92d BGE PyAPI can now import text (within the blend-file)
Previously this only worked with the Blender API.
- bpy_internal_import small C file that Blender scripting and the game engine use.
- Tested with blender, blenderplayer, loading files
- Needed to use a hack to override the Main struct since the game engine doesn't set G.main
- when the sandbox is set, only internal scripts can be imported.
2009-04-05 19:37:13 +00:00
Campbell Barton
3dacfbb231 BGE Python API
- action attribute wasnt checking for NULL (own fault)
- KX_Scene getCamera wasnt checking for NULL
- CListValue had asserts for not yet implimented functionality, this would close blender. Better to print an error if the user manages to run this functions (I managed to by CListValue.count([1,2,3]))
2009-04-05 14:55:50 +00:00
Campbell Barton
033a63f858 BGE Bugfixes (mostly in the py api)
KX_PolygonMaterial and KX_BlenderMaterial - Added a print function (would raise a python error on printing)

* Crashes *
KX_GameObject SetParent - Disallowed setting a parent to its self, caused a recursion crash.
KX_MeshProxy "materials" attribute was segfaulting because of my recent change - I was wrong, you do need to check material types (no idea why since they are both PyObject * at the base)
KX_VisibilityActuator - Wasn't initialized with PyType_Ready() making it crash on access (own fault) 

* Crashes because of missing NULL checks *
KX_PolygonMaterial's "gl_texture" attribute wasnt checking for a valid m_tface
KX_GameObject - added checks for GetPhysicsController()
KX_RayCast::RayTest - didnt check for a valid physics_environment
KX_SceneActuator's getCamera python function wasnt checking if there was a camera.
2009-04-05 14:01:49 +00:00
Campbell Barton
f8cc272575 added experimental KX_GameObject attributes "sensors", "controllers" and "actuators" 2009-04-05 08:48:51 +00:00
Campbell Barton
77da8461f3 Make materials use PyAttributeDef's 2009-04-05 07:41:03 +00:00
Campbell Barton
53e721305e BGE Python API
- made camera use PyAttributeDef's
- removed unneeded duplicate matrix type checks
- fixed own bug (added since 2.48a) that broke a converting 4x4 matrix to a PyObject
2009-04-05 06:08:41 +00:00
Campbell Barton
04ef5a492a Made KX_MeshProxy use PyAttributeDef. simplified getting the 'materials' attribute (no need to differentiate between types)
Added KX_GameObject 'meshes' attribute to replace getMesh(i)
2009-04-04 15:54:07 +00:00
Campbell Barton
a35a8f7a38 - should fix compiling with older python versions (<2.5)
- made the isA() function accept python types as well as strings.
- renamed _getattr_dict to py_getattr_dict
2009-04-04 08:20:52 +00:00
Campbell Barton
6be6921184 moved more attributes from getattr into PyAttributeDef's 2009-04-04 02:57:35 +00:00
Campbell Barton
e6985d31b5 Some users could not build with python 2.5, hopefully this fixes it. 2009-04-03 15:08:38 +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
b22705f169 BGE Python
- Bugfix for running dir() on all BGE python objects. was not getting the immediate methods and attributes for each class.
- Use attributes for KX_Scene (so they are included with dir())
- Override __dict__ attributes for KX_Scene and KX_GameObject so custom properties are included with a dir()
2009-04-03 02:16:56 +00:00
Campbell Barton
fcc23faa3a Added getitem/setitem access for KX_GameObject
ob.someProp = 10
can now be...
ob["someProp"] = 10

For simple get/set test with an objects 10 properties, this is ~30% faster.

Though I like the attribute access, its slower because it needs to lookup BGE attributes and methods (for parent classes as well as KX_GameObject class).

This could also be an advantage if there are collisions between new attributes added for 2.49 and existing properties a game uses.

Made some other small optimizations,
- Getting and setting property can use const char* as well as STR_String (avoids making new STR_Strings just to do the lookup).
- CValue::SetPropertiesModified() and CValue::SetPropertiesModified(), were looping through all items in the std::map, advancing from the beginning each time.
2009-04-02 05:38:05 +00:00
Benoit Bolsee
48e4a48340 BGE API cleanup: ReplaceMeshActuator mesh attributes now returns a KX_MeshProxy. Fix a bug in KX_MeshProxy where the Python type was not set right. 2009-04-01 08:59:36 +00:00
Guillermo S. Romero
441f26a170 Clean up for the imminent migration from SVN to GIT. 2009-03-31 22:34:34 +00:00
Benoit Bolsee
f6f47a08eb BGE API cleanup: DynamicActuator, ReplaceMeshActuator, TrackToActuator. 2009-03-31 21:03:15 +00:00
Benoit Bolsee
8518f6e660 BGE API cleanup, patch from Moguri: RaySensor, NetworkMessageActuator, NetworkMessageSensor. 2009-03-31 19:02:01 +00:00
Erwin Coumans
b182778e71 Applied patch #18446, to do versions on damping
Re-enable vertex welding, only for soft bodies. They require it. Future versions could expose such vertexWeldingThreshold.
2009-03-29 19:54:05 +00:00
Erwin Coumans
30fa7a7286 Only apply advanced setting of angular/linear factor to rigid bodies (with angular rotation). The setting broke 'dynamic'-only objects. 2009-03-29 18:34:35 +00:00
Benoit Bolsee
d57811ada1 BGE API cleanup: CDActuator, ParentActuator, VisibilityActuator done. Thanks to Andre. 2009-03-29 15:17:55 +00:00
Benoit Bolsee
afec404962 BGE API Cleanup: GameActuator (patch from Andre) 2009-03-27 22:11:30 +00:00
Benoit Bolsee
059c2a10c4 BGE API cleanup: AddObject, DeleteObject and Scene actuator added. 2009-03-27 21:54:16 +00:00
Campbell Barton
bba2bdf41e Added attributes for Ipo Actuator settings (replacing all methods) 2009-03-26 01:42:01 +00:00
Campbell Barton
c78b460fce Use Benoits attributes in KX_GameObject.
Deprecated..
getPosition, setPosition, getOrientation, setOrientation, getState, setState, getParent, getVisible, getMass

* swapped set/get to get/set in KX_PYATTRIBUTE_RW_FUNCTION macro to match pythons getsetattrs.
* deprecation warnings in the api and notes in epydocs.
* added 'state' attribute
* gameob.mass = 10 # now works because its not checking only for float values.
* dir(gameob) # includes attributes now
2009-03-24 19:37:17 +00:00
Brecht Van Lommel
ce8badeb18 Fix for bug #18423: BGE lights in overlay scene also affected
other scenes, for texture face / multitexture materials.

Fix for bug #18428: BGE lights on hidden layers were still used,
for all material types, now they have no effect
2009-03-24 15:45:08 +00:00
Campbell Barton
4a07876562 Speedup for bullet physics mesh conversion
Was adding each face with a remove doubles option that made conversion increasingly slower for larger meshes, this would often hang blender when starting with the BGE with larger meshes.

Replace btTriangleMesh()->addTriangle() with btTriangleIndexVertexArray()

YoFrankie level_1_home.blend starts a third faster, level_nut about twice as fast.

- previous commit was also incorrect using the original meshes vert locations rather then the vert locations that came from the derived mesh.
- Softbody is relying on removing doubles at 0.01 to give stable results, this no longer works but seems a bit dodgy anyway. Maybe some post-processing filter could fix up a mesh for bullet softbody.
2009-03-23 06:00:21 +00:00
Erwin Coumans
06d455f428 Add support to lock individual axis during rigid body simulation, for translation and rotation. This makes it easier to do 1D or 2D physics (tetris, blockout)
todo: create some example/demo.blend.
2009-03-09 07:12:16 +00:00
Erwin Coumans
6e85d00055 Fix: The debug lines of Physics Debug Visualization were drawn incorrectly when using overlay scenes (it was using the wrong camera) 2009-03-09 05:01:16 +00:00
Benoit Bolsee
d4adc43fc1 BGE patch #18309 commited: Add an addObject() method to KX_Scene. 2009-02-28 22:25:23 +00:00
Benoit Bolsee
6c409ed541 BGE API cleanup: apply patch from Moguri: Near, Radar, Touch sensor updated. 2009-02-28 21:00:27 +00:00
Campbell Barton
8d3dcfb104 BGE Python API
* Scene's and GameObjects can now be printed (raised an exception)
* Added GameLogic.getSceneList()
2009-02-27 23:53:09 +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
936a6eeda8 small errors in touch sensor and gameObject 2009-02-26 05:17:54 +00:00
Campbell Barton
6bfb8ca6b0 - Attributes for the collision sensor: propertyName, materialCheck, pulseCollisions, objectHit and objectHitList.
Removed a check in Python API touch.setProperty() for the property name on the sensor owner before allowing the name to be set - it makes no sense and isnt checked when creating the sensor.
- SCA_DelaySensor.py indent error making epydoc fail.
2009-02-26 04:17:23 +00:00
Campbell Barton
a4ad52f1aa New Pulse option for the collision sensor (off by default wont change existing logic)
Previously only the first collision would trigger an event (no collisions a negative event ofcourse)

With the Pulse option enabled, any change to the set of colliding objects will trigger an event.

Added this because there was no way to count how many sheep were on a platform in YoFrankie without running a script periodically.

Changes in collision are detected by comparing the number of objects colliding with the last event, as well as a hash made from the object pointers.

Also changed the touch sensors internal list of colliding objects to only contain objects that match the property or material.

- pulse isnt a great name, could change this.
2009-02-25 17:19:30 +00:00
Campbell Barton
7fffb0b630 Building the game engine with Solid/Sumo is now optional for scons using WITH_BF_SOLID.
Now Sumo is has been deprecated for a while we might want to remove it for 2.5.
2009-02-25 12:07:51 +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
Campbell Barton
2eb85c01f3 remove warnings for the BGE
- variables that shadow vers declared earlier
- Py_Fatal print an error to the stderr
- gcc was complaining about the order of initialized vars (for classes)
- const return values for ints and bools didnt do anything.
- braces for ambiguous if  statements
2009-02-25 03:26:02 +00:00
Campbell Barton
56e9c87309 building the game engine without SDL works again 2009-02-24 17:34:41 +00:00
Campbell Barton
adaa4b0fd0 Making KX_GameObject names read only.
This was committed in revision 2832 but never accounted for existing object name hashes which existed since revision 2.

Its possible to update the names elsewhere but unlikely anyone ever used this successfully so removing.
2009-02-24 12:38:56 +00:00
Campbell Barton
33aee345ed fix for segfault when the replace mesh actuator references a mesh that has no object in the current scene. 2009-02-24 09:49:28 +00:00
Campbell Barton
5488175d0b BGE Python API
* fixed segfaults in CListValue.index(val) and CListValue.count(val) when the pyTypes could not be converted into a CValue.
* added scene.objects to replace scene.getObjectList()
* added function names to PyArg_ParseTuple() so errors will include the function names 
* removed cases of PyArg_ParseTuple(args,"O",&pyobj) where METH_O ensures a single argument.
* Made PyObjectFrom use ugly python api rather then Py_BuildValue(), approx %40 speedup for functions that return Python vector and matrix types like ob.orientation.
2009-02-23 06:41:10 +00:00
Campbell Barton
9d5c2af1d1 * removed typedefs that were not used (from anonymous enums and structs)
* Missed some cases of using a 'char *' as an attribute
* replace BGE's Py_Return macro with Pythons Py_RETURN_NONE
* other minor warnings removed
2009-02-21 12:43:24 +00:00
Campbell Barton
cdec2b3d15 BGE Python API
Use 'const char *' rather then the C++ 'STR_String' type for the attribute identifier of python attributes.

Each attribute and method access from python was allocating and freeing the string.
A simple test with getting an attribute a loop shows this speeds up attribute lookups a bit over 2x.
2009-02-19 13:42:07 +00:00
Campbell Barton
c597863783 "object" and "objectLastCreated" attribute for actuators, deprecates getObject/setObject() & getLastCreatedObject()
also removed some warnings
2009-02-19 10:34:51 +00:00
Campbell Barton
92d4ef0939 Accept negative indices's for ListValues
scene.getObjectList()[-1] works like a python sequence.

removed some STR_String creation that was only used to do comparisons, in a simple expressions benchmark this made logic use 4% less overall.
2009-02-19 07:01:49 +00:00
Nathan Letwory
c3d74547be SCons:
* giving compileflags, cc_compileflags and cxx_compileflags to BlenderLib() now actually overrides any other setting (so there's no unclarity when ie. conflicting options are being specified in REL_CFLAGS et al). These are set after either release or debug flags, but before any *_WARN flags (so those stay maintained).
* add cxx_compileflags for GE parts on win32-vc to have better performance.
* NOTE: if platform maintainers (OSX and Linux) could check and do the same for their systems. Not vital, but probably very, very much welcomed by GE users.
2009-02-15 23:26:00 +00:00
Benoit Bolsee
915baae622 BGE bug #18137 fixed: When two actors collide in this blend file the blender crashes. 2009-02-15 19:07:27 +00:00
Benoit Bolsee
59e96a2831 BGE Py API cleanup: Camera Actuator. 2009-02-07 20:35:16 +00:00