Commit Graph

79 Commits

Author SHA1 Message Date
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
2fb8292005 style cleanup 2012-09-16 04:58:18 +00:00
Campbell Barton
8b865c01cd style cleanup: comments 2012-06-30 22:49:33 +00:00
Campbell Barton
a744fed46c style cleanup 2012-06-20 16:43:48 +00:00
Campbell Barton
9dd981a440 style cleanup: block comments 2012-05-16 23:37:23 +00:00
Campbell Barton
b8a71efeba style cleanup: follow style guide for/with/if spacing 2012-03-24 07:52:14 +00:00
Campbell Barton
4f19c1a995 spelling cleanup 2012-03-18 07:38:51 +00:00
Campbell Barton
4f7bdc59d3 style cleanup: spelling.
also remove large, duplicate comments from sunsky.h
2012-03-09 00:41:09 +00:00
Campbell Barton
4c17f8e5de PyUnicode_From_STR_String utility function which passes STR_String to PyUnicode_FromStringAndSize (saves a call to strlen).
Also made CValue::ConvertKeysToPython use faster list creation and improved some of the macro formatting.
2011-11-06 01:39:36 +00:00
Campbell Barton
665f602f15 python string conversion
- use _PyUnicode_AsStringAndSize where possible
- use %R for PyErr_Format(...) rather then running repr on the object explicitly 
- use const char
2011-11-03 14:09: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
Campbell Barton
11014aa34b access pythons code object directly rather than attribute access. 2011-05-29 11:05:52 +00:00
Campbell Barton
cfd9d6d190 Drop support for python 3.1.
for building py3.2 on *nix see:
  http://wiki.blender.org/index.php?title=Dev:2.5/Doc/Building_Blender/Linux/Troubleshooting#Python

also fixed possible buffer overrun with getting the fake filepath for a blender textblock.
2011-03-07 11:53:40 +00:00
Campbell Barton
3a590b4ec7 patch [#26366] More detailed Python error reporting for the BGE
from Alex Fraser (z0r)

    Now object name is shown with python error.
2011-03-05 11:08:22 +00:00
Nathan Letwory
344caea0b3 doxygen: gameengine/GameLogic tagged. 2011-02-25 13:32:11 +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
6a2e5ad599 [#25815] Patch gcc 4.6
with minor edits, made sure it works in CMake too.
2011-01-27 00:02:25 +00:00
Campbell Barton
3b0c2accc6 support building with python3.2 2011-01-18 21:39:50 +00:00
Campbell Barton
0876fce009 rename and negate DISABLE_PYTHON --> WITH_PYTHON 2010-10-31 04:11:39 +00:00
Campbell Barton
f49fc58df6 enable building the game engine without bullet for scons & cmake 2010-10-10 07:01:56 +00:00
Joerg Mueller
0be08725ad Py API (GSoC): Second merging commit
Rough summary of fixes/changes:
- Blender Py API: GameLogic -> bge.logic
- Blender Py API: Implemented missing KX_PYATTRIBUTE_TODOs and -DUMMYs.
- Fix for [#22924] KX_PolygonMaterial.diffuse does not return expected list[r,g,b]
- Py API: Renaming _owner attribute of mathutils classes to owner.
- Fix some minor errors in mathutils and blf.
- Enabling game engine autoplay again based on a patch by Dalai:
  * The biggest 3D view in the open scene is used, if there is none, blender opens the file normally and raises an error.
  * The 3D view are is made fullscreen.
  * Quad view, header, properties and toolbox panel are all hidden to get the maximum view.
  * If the game engine full screen setting is set, the game starts in fullscreen.
- Fix for ipo conversion on file transition in the game engine.
2010-08-16 12:14:09 +00:00
Campbell Barton
a0cece42c6 bugfix [#23148] "ImportError: __import__ not found" on changing Render FPS
The BGE was getting the namespace dict directly from __main__ which conflicts
with my recent fix to get the pickle module working which to overwrote the __main__ module on script execution.

Simple fix is to have the BGE and Blender use the same method of getting namespaces.
Renamed CreateGlobalDictionary() to bpy_namespace_dict_new() and moved into bpy_internal_import.c

pickle still wont work in the BGE since we make a copy of __main__ namespace but for speed would rather not have to replace the __main__ module many times per second.
2010-08-05 03:25:45 +00:00
Campbell Barton
f7b046c108 Hopefully fix building with MSVC 2008 from rev 30746.
SCA_PythonController.cpp(303) : error C2133: 'mod_path' : unknown size
2010-07-26 17:46:10 +00:00
Campbell Barton
ed5d0bb62f patch from Mitchell Stokes with some changes.
BGE Py Controllers were effectively doing this...
 "a.b.c" --> "__import__('a').b.c()"

This was annoying because it meant module 'a' would need to import 'b' explicitly.

Now use import like this.
 "a.b.c" --> "__import__("a.b").c()"

Note that this has the slight disadvantage that these need to be modules, where as before they could be collections of functions in a class instance for eg. So its possible this breaks existing files but dont think anyone used this since its a fairly obscure use case.
2010-07-26 08:49:16 +00:00
Campbell Barton
fd31436897 spelling correction: alredy --> already 2010-07-17 18:08:14 +00:00
Campbell Barton
8f1500da00 remove config.h references, was added for automake build system rev around 124-126 but isnt used by any build systems now. 2010-04-18 10:28:37 +00:00
Campbell Barton
081c1205a3 correct fsf address 2010-02-12 13:34:04 +00:00
Campbell Barton
c36f78dd41 [#19258] [patch] Adding drawing capabilities to BGE Python
patch from Mitchell Stokes (moguri)

simple use case
 scene.post_draw = [pyOpenGLFunc]

this only needs to be set once, then the funcion runs each redraw.

note, this patch also changes how python scripts run (not modules): Dont clear the namespace after running a script, since functions still use the namespace, BGE API is now better when dealing with stale data.

made some changes to this patch.
- assigning a list didnt decrement the existing list.
- initialize as NULL rather then a blank list
- dont use string comparisons for the callbacks, pass the python list to use instead.
- dont check the list items are callable. python will display an error if they are not.
- use python list macros that dont do any type checking sine blender does this when assigning the list

---- from tracker, edited since an updated patch changes some things.
Here is a patch to be able to draw to the screen with BGE Python. This will be very handy for GUI stuff. This patch
works by having the user register a callback in the scene. Two options are available KX_Scene.pre_draw
and KX_Scene.post_draw. The difference between these is when Python draws to the screen (before or after the BGE).
Each can take a list of functions. Here is an example that draws a blue semi-transparent
2009-11-22 14:42:22 +00:00
Campbell Barton
8b6f5c171d - rather then passing the python namespace dictionary to the controller function get the namespace from the converter.
- renamed SetPythonDictionary() to SetPyNamespace()
- remove IsLight(), GetGameObjectType() existed before this but wasnt used for lights.
2009-09-29 22:49:33 +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
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
c50bbe5ae7 BGE Py API using python3 c/api calls. include bpy_compat.h to support py2.x 2009-06-29 02:25:54 +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
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
f5fc4ebdd8 BGE Python API
- More verbose error messages.
- BL_Shader wasnt setting error messages on some errors
- FilterNormal depth attribute was checking for float which is bad because scripts often expect ints assigned to float attributes.
- Added a check to PyVecTo for a tuple rather then always using a generic python sequence. On my system this is over 2x faster with an optmized build.
2009-04-19 21:01:12 +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
efb7dd86ff Fix for own recent reference count error.
- The armature weakref list was  being incref'd twice then decrefed twice (incref and decref were used incorrectly), now only once. My 'fix' broke this.
- In bpy_pydriver_create_dict the 2 refs added from running PyDict_SetItemString twice were undone when clearing the dictionary (added comment)
- changed Py_XDECREF to Py_DECREF int BPY_pyconstraint_update and BPY_pyconstraint_target, Py_XDECREF checs for NULL value which would have crashed blender before it got to Py_XDECREF anyway.
- after every error is reported (PyErr_Print), remove sys.last_traceback and clear the error, I found this fixed certain crashes (usually when starting the game engine or exiting blender), so best do this all the time.

- header_text.c, CcdPhysicsEnvironment.cpp, KX_CameraActuator.cpp - remove some warnings.
2009-04-15 04:34:27 +00:00
Andre Susano Pinto
2fff90bbb4 Added function name to many of the PyArg_ParseTuple calls in gameengine
This way python raises more useful messages.
2009-04-10 16:45:19 +00:00
Campbell Barton
5d64dd019e BGE Python API
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.
2009-04-07 11:06:35 +00:00
Campbell Barton
6be6921184 moved more attributes from getattr into PyAttributeDef's 2009-04-04 02:57:35 +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
6c7c38a4e4 BGE Py API
* Made GameLogic.addActiveActuator(actu, bool) to raise an error if the actuator is not in the list. Before it would allow any value as the actuator and fail silently (makes debugging scripts more difficult).

* Allow the actuator to be a string which is convenient if you dont want to change the settings of the actuator.
* Added activate/deactivate functions to the controller, this is more logical since the GameLogic.addActiveActuator() function is running through the controller anyway.

GameLogic.addActiveActuator(controller.getActuator("SomeAct"), True)
...can be replaced with...
controller.activate("SomeAct")
2009-02-24 05:50:45 +00:00