- 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).
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.
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.
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.
- 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.
Use each types dictionary to store attributes PyAttributeDef's so it uses pythons hash lookup (which it was already doing for methods) rather then doing a string lookup on the array each time.
This also means attributes can be found in the type without having to do a dir() on the instance.
- 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()
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.
- 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
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.
* Value clamping to min/max is now supported as an option for integer, float
and string attribute (for string clamping=trim to max length)
* Post check function now take PyAttributeDef parameter so that more
generic function can be written.
* Definition of SCA_ILogicBrick::CheckProperty() function to check that
a string attribute contains a valid property name of the parent game object.
* Definition of enum attribute vi KX_PYATTRIBUTE_ENUM... macros.
Enum are handled just like integer but to be totally paranoid, the sizeof()
of the enum member is check at run time to match integer size.
* More bricks updated to use the framework.
The principle is to replace most get/set methods of logic bricks by direct property access.
To make porting of game code easier, the properties have usually the same type and use than
the return values/parameters of the get/set methods.
More details on http://wiki.blender.org/index.php/GameEngineDev/Python_API_Clean_Up
Old methods are still available but will produce deprecation warnings on the console:
"<method> is deprecated, use the <property> property instead"
You can avoid these messages by turning on the "Ignore deprecation warnings" option in Game menu.
PyDoc is updated to include the new properties and display a deprecation warning
for the get/set methods that are being deprecated.
Introduction of a new Delay sensor that can be used to
generate positive and negative triggers at precise time,
expressed in number of frames.
The delay parameter defines the length of the initial
OFF period. A positive trigger is generated at the end
of this period. The duration parameter defines the
length of the ON period following the OFF period.
A negative trigger is generated at the end of the ON period.
If duration is 0, the sensor stays ON and there is no
negative trigger.
The sensor runs the OFF-ON cycle once unless the repeat
option is set: the OFF-ON cycle repeats indefinately
(or the OFF cycle if duration is 0).
The new generic SCA_ISensor::reset() Python function
can be used at any time to restart the sensor: the
current cycle is interrupted and no trigger is generated.