Commit Graph

697 Commits

Author SHA1 Message Date
Benoit Bolsee
7f5acd6875 BGE remove parent: unparented object keeps the linear and angular velocity it had while being parented. 2009-05-21 19:38:49 +00:00
Benoit Bolsee
036ebc5523 BGE: GUI control over frame rate, logic rate, physics rate and physics subrate.
Four new buttons in World settings to control frame rate:
fps:  Nominal frame rate in frame per second.
      Also sets the physics timestep = 1/fps
phys: Maximum number of physics timestep per game frame in case
      the actual fps is less than nominal. This allows the 
      physics to keep up with real time even if the graphics slows
      down the game.
sub:  Fixed number of simulation substeps per physic timestep.
      Improves the precision of the physics simulation. Useful for
      fast moving objects for example.
log:  Maximum number of logic steps per game frame in case the 
      actual fps is less than nominal. This allows the logic
      system to follow the physics simulation. 
      Upper bound = phys 
      (setting the value higher than phys has no effect).
      On games with heavy logic system, it is useful to set this
      value to 1, to keep logic time under control.

All these values were already accessible from Python except phys:

GameLogic.getMaxPhysicsFrame():
	Gets the maximum number of physics frame per render frame.

GameLogic.setMaxPhysicsFrame(phys):
	Sets the maximum number of physics timestep that are executed per render frame.
	Higher value allows physics to keep up with realtime even if graphics slows down the game.
	Physics timestep is fixed and equal to 1/tickrate (see setLogicTicRate)
	maxphysics/ticrate is the maximum delay of the renderer that physics can compensate.
      phys: integer
2009-05-21 18:10:19 +00:00
Benoit Bolsee
06a7155b68 BGE: user control to compound shape and setParent.
Compound shape control
======================
1) GUI control
It is now possible to control which child shape is added to 
a parent compound shape in the Physics buttons. The "Compound"
shape button becomes "Add to parent" on child objects and
determines whether the child shape is to be added to the top
parent compound shape when the game is stated.

Notes: * "Compound" is only available to top parent objects
         (objects without parent).
       * Nesting of compound shape is not possible: a child
         object with "Add to parent" button set will be added
         to the top parent compound shape, regardless of its
         position in the parent-child hierarchy and even if its
         immediate parent doesn't have the "Add to parent" button set.

2) runtime control
It is now possible to control the compound shape at runtime:
The SetParent actuator has a new "Compound" button that indicates
whether the object shape should be added to the compound shape
of the parent object, provided the parent has a compound shape
of course. If not, the object retain it's individual state
while parented.
Similarly, the KX_GameObject.setParent() python function has
a new compound parameter.

Notes: * When an object is dynamically added to a compound 
         shape, it looses temporarily all its physics capability
         to the benefit of the parent: it cannot register collisions
         and the characteristics of its shape are lost (ghost, sensor,
         dynamic, etc.). 
       * Nested compound shape is not supported: if the object
         being parented is already a compound shape, it is not
         added to the compound parent (as if the Compound option 
         was not set in the actuator or the setParent function).
       * To ensure compatibility with old blend files, the Blender
         subversion is changed to 2.48.5 and the old blend files
         are automatically converted to match the old behavior: 
         all children of a Compound object will have the "Add to
         parent" button set automatically.

Child ghost control
===================
It is now possible to control if an object should becomes ghost
or solid when parented. This is only applicable if the object
is not added to the parent compound shape (see above).
A new "Ghost" button is available on the SetParent actuator to 
that effect. Similarly the KX_GameObject.setParent() python function
has a new compound parameter.

Notes: * This option is not applicable to sensor objects: they stay
         ghost all the time.
       * Make sure the child object does not enter in collision with
         the parent shape when the Ghost option if off and the parent is
         dynamic: the collision creates a reaction force but the parent
         cannot escape the child, so the force builds up and produces
         eratic movements.
       * The collision capability of an ordinary object (dynamic or static)
         is limited when it is parented: it becomes automatically static
         and can only detect dynamic and sensor objects.
       * A sensor object retain its full collision capability when parented:
         it can detect static and dynamic object.

Python control
==============
KX_GameObject.setParent(parent,compound,ghost):
	Sets this object's parent. 
	Control the shape status with the optional compound and ghost parameters:
	compound=1: the object shape should be added to the parent compound shape (default)
	compound=0: the object should keep its individual shape. 
	In that case you can control if it should be ghost or not:
	ghost=1 if the object should be made ghost while parented (default)
	ghost=0 if the object should be solid while parented 
	Note: if the object type is sensor, it stays ghost regardless of ghost parameter
		
	parent: KX_GameObject reference or string (object name w/o OB prefix)
2009-05-21 13:32:15 +00:00
Benoit Bolsee
c0844b7938 BGE logic patch: fix another incompatibility with YF.
Previous patch was not sorting the state actuators. This was causing 
some problems with YoFrankie that relies on the order of actuators
when multiple state actuators are activated at once.

Active state actuators will now be sorted per object. This doesn't
change the fact that state actuators are executed before all other
actuators as before.

Incidently, made the logic loop faster.
2009-05-20 08:45:42 +00:00
Dalai Felinto
dc6ae673b1 Moving ScreenSpace methods from Rasterizer to KX_Camera (getScreenPos, getScreenVect, getScreenRay)
The modules were moved in order to access the camera internal matrixes. It will make then compatible with multiple viewports in a near future.
So far the problem I found was:
1) KX_Camera doesn't store the canvas viewport
2) RAS_ICanvas methods: GetDisplayArea and GetWindowArea are affected by multiple viewports (and they shouldn't).

Test file is here: http://www.pasteall.org/blend/68
2009-05-20 05:33:39 +00:00
Campbell Barton
1a16fb1953 BGE Py API
use PY_SET_ATTR_FAIL and PY_SET_ATTR_SUCCESS return values so the fake subclassing can know if a value failed to be set or if it was missing from the type. (with PY_SET_ATTR_MISSING)

Also noticed some other mistakes.
- KX_LightObject, setting the type didnt check for an int.
- KX_SoundActuator, didnt return an error when assigning an invalid orientation value
- KX_GameObject, worldOrientation didnt return an error value.
2009-05-19 07:16:40 +00:00
Campbell Barton
cb96dc40e8 Sensor objects were initialized as invisible, which conflicted with initializing the invisible setting from the outliner render object (which it seems nobody knew about).
Added an 'Invisible' button to make this more clear, it seems like a display option but its also related to logic because the actuators can toggle this after the game starts.

Without this its annoying to add UV's only to set the invisible flag.

Sensor objects were not clearing the softbody gameflag
2009-05-18 10:27:09 +00:00
Benoit Bolsee
07fc2aa526 BGE #18665: Servo control and relative motion
Servo control motion actuator did not work as expected when the object
is moving on a moving platform. 

This patch introduces a new Ref field in the servo motion actuator
to set a reference object for the velocity calculation.
You can set the object during the game using the actuator "reference"
attribute; use an object name or an object reference.

The servo controller takes into account the angular velocity of the
reference object to compute the relative local velocity.
2009-05-18 08:22:51 +00:00
Benoit Bolsee
9a40f4d2a6 BGE: bookmark option on controller to make them run before all other controllers.
A new bookmark button is available on the controller UI. 
When set, the controller is guaranteed to execute before all
other non-bookmarked controllers, provided it is scheduled 
for execution. 

This is useful for initialization scripts that run once at startup or
scripts that must set some prerequisite for the other controllers at
the start of each logic frame.

This feature is also available at python level with the "bookmark"
attribute. It can be changed during the game.

Note that if several script are bookmarked, their relative order of 
execution is not guaranteed. Make sure they don't depend on each other.
2009-05-17 21:50:31 +00:00
Dalai Felinto
9ce8a67690 BGE Dome: removing of size option and adding tilt option.
- Size adjustments can be accomplished with warp mesh data now. So we get a free spot in the GUI for a tilt option.

- Tilt option to tilt the camera (for planetarium domes).
Angle is in degree from -180 to +180. It's needed for planetarium domes (as this one http://domejunky.blogspot.com/2009/05/dome-corrected-bge.html ).

- This is the last commit regarding dome code I expected to 2.49. I consider this feature full implemented now. (working on docs now)
2009-05-17 20:37:13 +00:00
Campbell Barton
41acd3b81c While testing YoFrankie with the new API attributes found some issues...
- corrections to docs
- disallow calling controller.activate(actuator) when the controller is not active. (Raise a SystemError)
- Added 2 new attributes, CValue.name - deprecates CValue.getName(), KX_GameObject.children deprecated KX_GameObject.getChildren(), (same for getChildrenRecursive()).
2009-05-17 16:30:18 +00:00
Benoit Bolsee
3ea1c1b4b6 BGE: new sensor object to generalize Near and Radar sensor, static-static collision capbility.
A new type of "Sensor" physics object is available in the GE for advanced
collision management. It's called Sensor for its similarities with the
physics objects that underlie the Near and Radar sensors.
Like the Near and Radar object it is:
- static and ghost
- invisible by default
- always active to ensure correct collision detection
- capable of detecting both static and dynamic objects
- ignoring collision with their parent
- capable of broadphase filtering based on:
  * Actor option: the collisioning object must have the Actor flag set to be detected
  * property/material: as specified in the collision sensors attached to it
  Broadphase filtering is important for performance reason: the collision points
  will be computed only for the objects that pass the broahphase filter.
- automatically removed from the simulation when no collision sensor is active on it

Unlike the Near and Radar object it can:
- take any shape, including triangle mesh
- be made visible for debugging (just use the Visible actuator)
- have multiple collision sensors using it

Other than that, the sensor objects are ordinary objects. You can move them
freely or parent them. When parented to a dynamic object, they can provide
advanced collision control to this object.

The type of collision capability depends on the shape:
- box, sphere, cylinder, cone, convex hull provide volume detection.
- triangle mesh provides surface detection but you can give some volume
  to the suface by increasing the margin in the Advanced Settings panel.
  The margin applies on both sides of the surface.

Performance tip:
- Sensor objects perform better than Near and Radar: they do less synchronizations
  because of the Scenegraph optimizations and they can have multiple collision sensors
  on them (with different property filtering for example).
- Always prefer simple shape (box, sphere) to complex shape whenever possible.
- Always use broadphase filtering (avoid collision sensor with empty propery/material)
- Use collision sensor only when you need them. When no collision sensor is active
  on the sensor object, it is removed from the simulation and consume no CPU.

Known limitations:
- When running Blender in debug mode, you will see one warning line of the console:
  "warning btCollisionDispatcher::needsCollision: static-static collision!"
  In release mode this message is not printed.
- Collision margin has no effect on sphere, cone and cylinder shape.

Other performance improvements:
- Remove unnecessary interpolation for Near and Radar objects and by extension
  sensor objects.
- Use direct matrix copy instead of quaternion to synchronize orientation.

Other bug fix:
- Fix Near/Radar position error on newly activated objects. This was causing
  several detection problems in YoFrankie
- Fix margin not passed correctly to gImpact shape.
- Disable force/velocity actions on static objects
2009-05-17 12:51:51 +00:00
Campbell Barton
10ed9a4f64 setting up the BGE Python sys.path for importing modules wasnt working for library paths. 2009-05-16 13:19:23 +00:00
Campbell Barton
b063d2f621 replace Py_BuildValue("OOO", Py_None, Py_None, Py_None) with a function that makes and fills the tuple,
since some scripts call rayCast many times in a single logic tick,
contrived benchmark shows this to be about 20% faster.
2009-05-16 06:57:38 +00:00
Campbell Barton
006ad4aaac BGE Py API Bugfixes
KX_GameObject.getVelocity() would set an error but nor return an error value when an non vector argument was given.
KX_PythonSeq_Type was not initialized with PyType_Ready which could crash blender when inspecting the type.
2009-05-16 00:49:28 +00:00
Benoit Bolsee
ef8f92ffe6 BGE: fix a compatibility problem since logic patch with YoFrankie (and other games I guess). State actuators will now execute before any other actuators to make sure that the actuators link count are up to date when they execute. 2009-05-15 20:51:32 +00:00
Campbell Barton
b8657fd648 Name attributes added since 2.48a more consistently.
BL_ActionActuator::blendin -> blendIn
BL_ActionActuator::end -> frameEnd
BL_ActionActuator::property -> propName
BL_ActionActuator::start -> frameStart
BL_ActionActuator::type -> mode
BL_ShapeActionActuator::blendin -> blendIn
BL_ShapeActionActuator::end -> frameEnd
BL_ShapeActionActuator::frameProperty -> framePropName
BL_ShapeActionActuator::property -> propName
BL_ShapeActionActuator::start -> frameStart
BL_ShapeActionActuator::type -> mode
KX_CameraActuator::xy -> useXY
KX_ConstraintActuator::property -> propName
KX_GameActuator::file -> fileName
KX_GameObject::localScaling -> localScaling
KX_GameObject::worldScaling -> worldScaling
KX_IpoActuator::endFrame -> frameEnd
KX_IpoActuator::startFrame -> frameStart
KX_IpoActuator::type -> mode
KX_RaySensor::property -> propName
KX_SCA_DynamicActuator::operation -> mode
KX_Scene::objects_inactive -> objectsInactive
KX_SoundActuator::filename -> fileName
KX_SoundActuator::type -> mode
KX_TouchSensor::objectHit -> hitObject
KX_TouchSensor::objectHitList -> hitObjectList
KX_TouchSensor::property -> propName
KX_TouchSensor::pulseCollisions -> usePulseCollision
KX_VisibilityActuator::occlusion -> useOcclusion
KX_VisibilityActuator::recursion -> useRecursion
SCA_2DFilterActuator::passNb -> passNumber
SCA_PropertyActuator::property -> propName
SCA_PropertyActuator::type -> mode
SCA_PropertySensor::property -> propName
SCA_PropertySensor::type -> mode
SCA_RandomActuator::property -> propName
2009-05-15 03:26:53 +00:00
Campbell Barton
0e423e5bb6 BGE PyAPI
[#18701] Issues with camera.pointInsideFrustum method
- note in docs that the projection matrix is not correct for first logic tick.

Renamed...
KX_Camera.isViewport -> KX_Camera.useViewport
KX_Lamp.quat_attenuation -> KX_Lamp.quad_attenuation

Deprecated KX_Camera.getProjectionMatrix(), KX_Camera.setProjectionMatrix() for projection_matrix attr

Added most missing docs reported by the doc-checker script
2009-05-14 23:06:05 +00:00
Benoit Bolsee
d95a109990 BGE modifier: generate correct physic shape, share static derived mesh, share display list.
This commit completes the support for modifiers in the BGE.
- The physic shape is generated according to the derived mesh. 
  This is true for all types of shapes and all types of 
  objects except soft body.
- Optimization for static derived mesh (mesh with modifiers
  but no armature and no shape keys). Replicas will share
  the derived mesh and the display list: less memory and
  faster rendering. With this optimization, the static 
  derived mesh will render as fast as if the modifiers were
  applied.

Known Limits:
- Sharing of mesh and display list is only possible between
  in-game replicas or dupligroup. If you want to instantiate
  multiple objects with modifiers, use dupligroup to ensure
  best memory and GPU utilization.
- rayCast() will interact with the derived mesh as follow:
  Hit position and hit normal are the real values according
  to the derived mesh but the KX_PolyProxy object refers to
  the original mesh. You should use it only to retrieve the
  material.
- Dynamic derived mesh have very poor performance:
  They use direct openGL calls for rendering (no support
  for display list and vertex array) and they dont't share
  the derived mesh memory. Always apply modifiers on dynamic
  mesh for best performance.
- Time dependent modifiers are not supported.
- Modifiers are not supported for Bullet soft body.
2009-05-14 13:47:08 +00:00
Campbell Barton
d257586fe6 BGE Py API
scene.active_camera can now be set so you can more easily set the current camera from python scripts without using an actuator.
ConvertPythonToCamera utility function to get a camera from a python string or KX_Camera type.
2009-05-14 07:59:44 +00:00
Benoit Bolsee
f5bacc6c8a BGE API cleanup: motion actuator. Apply patch from Moguri. 2009-05-13 16:48:33 +00:00
Benoit Bolsee
82b4975ccf BGE #18732: Python Light options don't work with GLSL materials. Commited patch from dfelinto and moguri, thanks for the good work. 2009-05-13 06:42:15 +00:00
Benoit Bolsee
5a0de728b0 BGE performance: allow to create display list on meshes with modifiers but without armature and shape keys. These modified meshes are static and can be put safely in a display list. As the rendering of modifiers is done in direct openGL call, it results is a bit performance boost. 2009-05-12 19:48:18 +00:00
Benoit Bolsee
732c3ee66f BGE bug #18596: No ipo dynamics is 2.49rc1. 2009-05-11 23:05:13 +00:00
Diego Borghetti
0c6ec76a4c Fix Makefiles for gameengine. 2009-05-11 15:34:46 +00:00
Benoit Bolsee
ee1c29028d BGE: Add MT_Vector3 support for Py attribute macro system. See KX_PYATTRIBUTE_VECTOR_... 2009-05-11 12:41:48 +00:00
Campbell Barton
9cc61dd9c8 use the same sequence mapping types as CListValue, hopefully this means it will build on different python versions 2009-05-10 22:33:21 +00:00
Benoit Bolsee
a417334026 Linux compilation problem 2009-05-10 22:06:11 +00:00
Campbell Barton
a6721e549d changes to get benoits logic updates building on scons with gcc 2009-05-10 21:22:25 +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
6f5ef6044d remove unneeded vars and wasn't returning on some errors 2009-05-10 15:23:18 +00:00
Campbell Barton
136d4c34ba deprecate controller.getActuator(name) and controller.getSensor(name) for
controller.actuators[name] and controller.sensors[name]

Made a read-only sequence type for logic brick sensors and actuators which can access single items or be used like a list or dictionary.
We could use a python dictionary or CValueList but that would be slower to create.

So you can do...
 for s in controller.sensors: print s

 print controller.sensors["Sensor"]

 print controller.sensors[0]

 sensors = list(controller.sensors)

This sequence type keeps a reference to the proxy it came from and will raise an error on access if the proxy has been removed.
2009-05-10 01:48:14 +00:00
Dalai Felinto
f155da0039 BGE Dome: Reducing FBO size to warped meshes.
Commit 20099 started using a FBO way too big.
According to Paul Bourke this is how it's done in other Engines:

Projectors HD:
1920x1050 - buffersize = 1024; FBO size = 2048
1400x1050 - buffersize = 1024; FBO size = 2048

Projectors XGA:
1024x768 - buffersize = 512; FBO size = 1024

Now in Blender Game Engine we are using:

Projectors HD:
1920x1050 - buffersize = 1050; FBO size = 2048
1400x1050 - buffersize = 1050; FBO size = 2048

Projectors XGA:
1024x768 - buffersize = 768; FBO size = 1024

(I guess I should be committing code to the ge_dome branch instead of the trunk. I feel bad doing all those adjustments in a hurry to 2.49 final release in the trunk. That is ok, right?)
2009-05-09 21:54:22 +00:00
Dalai Felinto
4a2341fe9a BGE Dome: Allowing FOV different from 180º for Truncated Domes
*) a small note:

In the end it turned out that we have upright and downright domes out there.
So I may rearrange the order of the gui later:
(1 = fisheye, 2 = truncated up, 3 = truncated down, 4 = envmap, 5 = spherical panoramic)

I don't plan to do a doVersion() for that, so if you are using it already keep in mind that the modes may change before 249 final release.
2009-05-09 21:04:03 +00:00
Campbell Barton
df01af5a1f Methods didn't check for zombies which could crash in the case where a method for an object is kept.
func = ob.getMass
 ...remove ob...
 func() # crash

2 More refcount fixes spotted by Benoit too
2009-05-09 18:18:04 +00:00
Campbell Barton
355b585447 More refcount errors spotted by Benoit, one with python getting a list item so scene.objects["OBfoo"] would always mess up refcounts. 2009-05-09 17:24:21 +00:00
Campbell Barton
5d6b249c9b refcounting bugfix, gameOb.getParent() and gameOb.parent both added a reference when they should not have. 2009-05-09 16:29:00 +00:00
Dalai Felinto
1d11df1708 BGE Dome: Truncated Dome are back (Upright and Downright) + GLEW_EXT_framebuffer_object check before generating FBO
After last commit (20099) warping meshes got slower (more quality == less performance). Since we don't need an extra warping for truncated domes, It's better to handle them directly in openGL without the need of warping it.

I'll talk with some Dome owners to see if we need both Upright and Downright modes. I may remove one of them by 2.49 them.

*) also: a proper GLEW_EXT_framebuffer_object check before generating FBO (for warping meshes).

**) next in line (maybe after RC2): tilt option to tilt the camera up to 90º upward.
2009-05-08 18:59:08 +00:00
Dalai Felinto
e1c958c364 BGE Dome: Implementation of FBO to handle warp mesh rendering.
We are using an image twice as big to render the fisheye before warping.
It'll slow down warping meshes a little, but we get way more resolution.

Therefore I will bring Truncated Dome mode back in order to avoid using warping mesh for that.
2009-05-07 20:00:09 +00:00
Campbell Barton
f590ffdadc [#18645] Texture painting smudge brush darkens images - 2.49RC1
not fixed but the problem is now less bad when projection painting, bilinear interpolation was rounding down.
- added gameOb.attrDict to get the internal gameObject dict.
- mesh.getVertex wasnt setting an exception.
2009-05-07 14:53:40 +00:00
Benoit Bolsee
42557f90bd BGE performance, 3rd round: culling and rasterizer.
This commit extend the technique of dynamic linked list to the mesh
slots so as to eliminate dumb scan or map lookup. It provides massive 
performance improvement in the culling and in the rasterizer when 
the majority of objects are static.

Other improvements:
- Compute the opengl matrix only for objects that are visible.
- Simplify hash function for GEN_HasedPtr
- Scan light list instead of general object list to render shadows
- Remove redundant opengl calls to set specularity, shinyness and diffuse
  between each mesh slots.
- Cache GPU material to avoid frequent call to GPU_material_from_blender
- Only set once the fixed elements of mesh slot
- Use more inline function

The following table shows the performance increase between 2.48, 1st round
and this round of improvement. The test was done with a scene containing 
40000 objects, of which 1000 are in the view frustrum approximately. The
object are simple textured cube to make sure the GPU is not the bottleneck.
As some of the rasterizer processing time has moved under culling, I present
the sum of scenegraph(includes culling)+rasterizer time

Scenegraph+rasterizer(ms)       2.48      1st round       3rd round

All objects static,            323.0           86.0             7.2
all visible, 1000 in 
the view frustrum

All objects static,            219.0           49.7             N/A(*)
all invisible.

All objects moving,            323.0          105.6            34.7
all visible, 1000 in 
the view frustrum

Scene destruction              40min          40min              4s

(*) : this time is not representative because the frame rate was at 60fps.
      In that case, the GPU holds down the GE by frame sync. By design, the
      overhead of the rasterizer is 0 when the the objects are invisible. 

This table shows a global speed up between 9x and 45x compared to 2.48a
for scenegraph, culling and rasterizer overhead. The speed up goes much
higher when objects are invisible.

An additional 2-4x speed up is possible in the scenegraph by upgrading
the Moto library to use Eigen2 BLAS library instead of C++ classes but
the scenegraph is already so fast that it is not a priority right now.

Next speed up in logic: many things to do there...
2009-05-07 09:13:01 +00:00
Campbell Barton
779bf435ef python3 compatibility for the BGE api, this only works with scons when WITH_BF_NOBLENDER is enabled.
Mathutils, Geometry and BGL modules are currently disabled with python3
2009-05-07 05:23:15 +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
c1e1091f02 moved py controller functions from SCA_PythonController to SCA_IController - the base controller class so python can get the sensors & actuators from any controller (not just SCA_PythonController types)
also deprecated getActuators() and getSensors() for 'sensors' and 'actuators' attributes.

an example of getting every sensor connected to an object.
 all_sensors = [s for c in ob.controllers for s in c.sensors]
2009-05-06 09:12:08 +00:00
Diego Borghetti
405cf80eb8 Big, big commit!!
1) Remove WITH_FREETYPE2 from code, so now blender always need freetype2
2) Remove the old bmfont
3) Remove ftfont and bFTGL library
4) Implement a new BLF_draw_default function for place that still need/use
   the old BMF api.

I try to update both, scons and cmake, but I only can test with make, so
hope all work fine.

MSVC is broken, but I don't have Windows, things to search and fix are
any reference to WITH_FREETYPE2, FTGL and BMFONT (take in care that
blenkernel also have a BKE_bmfont.h, this don't have anything to do with bmfont).
        Always have to link/include the freetype2 library
        Remove any reference to libbmfont
        Remove any reference to libftfont
        Remove any reference to libbftgl (or libbFTGL)
2009-05-05 23:10:32 +00:00
Campbell Barton
2f7cd19ff5 print BGE Py api warnings only once to avoid flooding the terminal and slowing the game down too much, resets on loading scenes/blendfiles and restarting the game engine. 2009-05-04 08:55:54 +00:00
Benoit Bolsee
3abb8e8e68 BGE performance: second round of scenegraph improvement.
Use dynamic linked list to handle scenegraph rather than dumb scan
of the whole tree. The performance improvement depends on the fraction
of moving objects. If most objects are static, the speed up is 
considerable. The following table compares the time spent on 
scenegraph before and after this commit on a scene with 10000 objects
in various configuratons:

Scenegraph time (ms)              Before         After
(includes culling)

All objects static,               8.8            1.7  
all visible but small fraction          
in the view frustrum

All objects static,               7,5            0.01
all invisible.

All objects moving,               14.1           8.4
all visible but small fraction
in the view frustrum

This tables shows that static and invisible objects take no CPU at all
for scenegraph and culling. In the general case, this commit will 
speed up the scenegraph between 2x and 5x. Compared to 2.48a, it should
be between 4x and 10x faster. Further speed up is possible by making
the scenegraph cache-friendly.

Next round of performance improvement will be on the rasterizer: use
the same dynamic linked list technique for the mesh slots.
2009-05-03 22:29:00 +00:00
Benoit Bolsee
2aa3c932d0 BGE performance: use inline function as much as possible in scenegraph and logic to avoid function call. 2009-05-03 21:51:57 +00:00
Campbell Barton
f67ffd137d fix for a problem with setUV2 reported by cthames on blenderartist
http://blenderartists.org/forum/showpost.php?p=1369757&postcount=35
there was an undocumented second arg but may as well allow a single vector arg like setUV()
2009-05-03 20:47:29 +00:00
Campbell Barton
d85bbb8070 on second thought its less trouble to make a python script that makes all the getset's in the array, apologies to Alex for suggesting this be dynamic :/
included python script to print out getsets as a comment
2009-05-03 19:47:13 +00:00
Campbell Barton
8a83aff9f5 [#18678] Swizzle properties for Mathutils.Vector
patch from Alex Fraser (z0r)

eg.
  - vec.xyz = vec.zyx
  - vec.xy = vec.zw
  - vec.xxy = vec.wzz
  - vec.yzyz = vec.yxyx

See http://en.wikipedia.org/wiki/Swizzling_(computer_graphics)

made some minor modifications to this patch.

tested access times and adding 336 attributes to vectors doesn't make a noticeable differences to speed of existing axis attributes (x,y,z,w) - thanks to python dict lookups.
2009-05-03 17:52:03 +00:00
Campbell Barton
22b501c791 fixes for bugs submitted by BGE users, fixes by myself and Mitchell Stokes
- when the attribute check function failed it didnt set an error raising a SystemError instead
- Rasterizer.getMaterialMode would never return KX_BLENDER_MULTITEX_MATERIAL
- PropertySensor value attribute checking function was always returning a fail.
- Vertex Self Shadow python script didnt update for meshes with modifiers.
2009-05-03 09:21:58 +00:00
Campbell Barton
41f42099ac BGE Py API patch from Mitchell Stokes, add distance attribute to the radar sensor, dont use 'continue' because its a python keyword.
removed (ssizeobjargproc) it breaks py2.3
2009-05-02 04:53:01 +00:00
Campbell Barton
ef20036b84 BGE Py API patch from Mitchell Stokes, adds extra attributes and docs 2009-05-02 02:40:11 +00:00
Benoit Bolsee
07abb9dee2 BGE performance:
- Vast performance increase when removing scene containing large number of 
  objects: the sensor/controller map was updated for each deleted object, 
  causing massive slow down when the number of objects was large (O(n^2)).
- Use reference when scanning the sensor map => avoid useless copy.
- Remove dynamically the object bounding box from the DBVT when the object
  is invisible => faster culling.
2009-05-01 20:34:23 +00:00
Benoit Bolsee
e13a089d91 BGE: work around a problem with DBVT culling when graphic objects are rescaled. This happens when objects with very diverse scale are instantiated with dupligroup. The problem remains when the objects are rescaled during the game. The effect of the problem is an inefficient culling: objects can have a bounding box larger than needed. Patch to fix the problem is filed at Bullet forum. 2009-05-01 19:02:23 +00:00
Benoit Bolsee
672492f563 BGE: New function GameLogic.setMaxLogicFrame() to allow better control over the time spent on logic.
This function sets the maximum number of logic frame executed per render frame.
Valid values: 1..5

This function is useful to control the amount of processing consumed by logic.
By default, up to 5 logic frames can be executed per render frame. This is fine
as long as the time spent on logic is negligible compared to the render time. 
If it's not the case, the default value will drag the performance of the game
down by executing unnecessary logic frames that take up most of the CPU time. 

You can avoid that by lowering the value with this function. 
The drawback is less precision in the logic system to physics and I/O activity.
	
Note that it does not affect the physics system: physics will still run 
at full frame rate (actually up to 5 times the ticrate).
You can further control the render frame rate with GameLogic.setLogicTicRate().
2009-05-01 16:35:06 +00:00
Campbell Barton
bb3fa18a95 add blendfile dirs to the sys.path without the scripts subdir 2009-05-01 04:55:40 +00:00
Benoit Bolsee
2ec50d7bb2 BGE bug #18091: Hitbox of object X doesn't move along when object X is parented to object Y. 2009-04-30 19:00:17 +00:00
Dalai Felinto
8570071e40 supporting warp data files with tabs instead of spaces. 2009-04-30 15:27:38 +00:00
Campbell Barton
fdf6ea916d added Geometry as a BGE module, removed its dependency on gen_utils.c 2009-04-30 12:45:13 +00:00
Campbell Barton
b5b24ee521 BGE Python sys.path for the blenderplayer and blender
sys.path is the search path for python modules. This is useful so people making games can put all their scripts in a folder and be sure they will always load into the BGE.

for each blend file a scripts directory is added to the path
 /home/me/foo.blend
will look for modules in...
 /home/me/scripts/*.py 

It could also default to look for modules in the same directory as the blend file but I think this is messy.
Added a note in the tooltip about //scripts so its not such a hidden feature.

This works by storing the original sys.path, then adding the paths for the blendfile and all its libs,
when a new blendfile is loaded, the original sys.path is restored before adding the blendfiles paths again so the sys.path wont get junk in it.

One problem with this - when using linked libs the module names must be unique else it will load the wrong module for one of the controllers.

also fixed 2 bugs
- sys.path in the blenderplayer was growing by 1 for every file load in blenderplayer
- the relative path (gp_GamePythonPath), wasnt being set when loading files in the blenderlayer (as I wrongly said in the last commit).
2009-04-30 08:01:31 +00:00
Dalai Felinto
939290b59c BGE 2dFilters: Revert of part of own commit [rev. 19687]
Therefore we still need to find a better way to solve this problem:
[#18154] 2dFilter and motion blur should run only once to all the scenes:
http://projects.blender.org/tracker/?func=detail&aid=18154&group_id=9&atid=127
2009-04-30 03:46:31 +00:00
Dalai Felinto
5908e2aa77 BGE Dome update. Spurious black seams (finally) fixed.
The solution is a hack. It's a workaround for another bug (#18655).
Now it's working in all modes: fullscreen, maximized screen and gameplayer.

* small change to always set the perspective mode as true during dome mode.
2009-04-30 02:41:07 +00:00
Campbell Barton
1e7df58519 python modules in the game engine could point to builtin modules like GameLogic that was cleared.
I added module clearing before there was checks for invalid python objects, so now its not needed for BGE Builtin types at least.

also made the builtin modules get re-used if they already exist and clear all user modules when the game engine finishes so with Module-Py-Controllers the referenced modules are at least up to date when pressing Pkey.
2009-04-29 23:39:27 +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
3bc02088e8 remove uneeded checks and testMethod from KX_ConstraintWrapper, typo in import_obj 2009-04-29 10:24:12 +00:00
Benoit Bolsee
f004c36e41 BGE: speed up mesh conversion by avoiding allocation/deallocation of material object on each face. The speed up is minor on optimized builds but considerable on less optimized builds, good for debugging large scene. 2009-04-29 10:06:38 +00:00
Benoit Bolsee
e4abebfa91 BGE: reenable object activation for static object, otherwise their physic shape is not updated when they move due to parent relation. 2009-04-28 18:56:48 +00:00
Campbell Barton
94c6cadfe2 BGE PyAPI
- renamed generic attribute "isValid" to "invalid" since BL_Shader already uses isValid.
- Moved deprecation warnings from CValue 
- removed unused KX_Scene::SetProjectionMatrix and KX_Scene::GetViewMatrix
- Added KX_Scene attributes "lights", "cameras", "objects_inactive", to allow access to objects in unseen layers (before the AddObject actuator adds them)
- KX_Camera deprecated cam.enableViewport(bool) for cam.isViewport which can be read as well.
2009-04-28 13:11:56 +00:00
Benoit Bolsee
352eaccd5d BGE: Add soft body welding parameter to the Advanced Settings panel. The values are very small so I chose to use logarithmic scale. Should be fine, it's an advanced setting after all. 2009-04-27 16:44:02 +00:00
Benoit Bolsee
c56ee09c48 BGE bug #18624: Collision detection fails on parented objects. Partial fix, parented shape now moves with the parent but still the parent near detector detects the child only in the zone where it was parented. 2009-04-27 16:40:26 +00:00
Erwin Coumans
5d1d6ad4d1 Don't always activate a Bullet rigid body
If you want to keep a rigid body awake, please use the GUI 'No Sleeping' option for Rigid bodies.
2009-04-27 05:06:24 +00:00
Erwin Coumans
d2ff190dfb Lower the vertex welding threshold, for removing duplicate/nearby vertices for soft bodies (this broke susanne softbody regression test) 2009-04-27 04:21:05 +00:00
Benoit Bolsee
ba563216e9 BGE: Fix Orthographic mode and viewport scaling
- the BGE now uses correct glOrtho projection whe camera is in orthographic mode
-
2009-04-26 12:23:30 +00:00
Benoit Bolsee
b991b32458 BGE mesh modifiers: fix view frustrum culling for mesh with modifiers. Update the bounding box based on mesh extent after applying the modifiers. 2009-04-25 12:20:59 +00:00
Campbell Barton
3038fb1a01 [#18606] Writing to KX_GameObject.orientation causes crash
Own bug, conversion function to get an orientation from python - PyOrientationTo() ignored user input completely :| (breaking the orientation attribute)

Also made KX_GameObject worldOrientation writable and minor doc fixes.
2009-04-25 07:17:36 +00:00
Campbell Barton
0c482f7607 BGE API - small changes
- print CListValue errors only once.
- bge_api_validate_py.txt now validates modules as well as types.
- added missing functions and consts for epydoc modules. some of these in GameLogic.py still need sorting.
2009-04-24 20:27:04 +00:00
Brecht Van Lommel
70f1b45430 Fix for part of bug #18496: issue with light state switching
when using Dome.
2009-04-23 13:30:34 +00:00
Dalai Felinto
073abf7047 BGE Dome update:
* Enviroment Map implemented (replacing truncated mode 2).
 - Now it's possible to pre-bake animated (or static) EnvMaps to use with Cube Map textures.

* Enabling 2DFilter in Dome mode
 - no GL_DEPTH_BUFFER supported though.

* Tweaking GameSettings menu (centralizing buttons)
2009-04-23 02:27:11 +00:00
Dalai Felinto
7ac233be8a BGE Rasterizer methods to handle Screen Space - (getScreenPosition, getScreenVect, getScreenRay)
getScreenPosition(obj):
 - Gets the position of an object projected on screen space.

getScreenVect(x, y):
 - Gets the vector from the camera position in the screen coordinate direction.

getScreenRay(x, y, dist, property):
 - Look towards a screen coordinate (x,y) and find first object hit within dist that matches prop.
- The ray is a call to KX_GameObject->rayCastTo from the KX_Camera object.

Patch [#18589] test files can be found there. Patch reviewed by Campbell
2009-04-23 00:49:38 +00:00
Campbell Barton
e8f5c75005 patch from Mitchell Stokes, comments only - KX_PYATTRIBUTE_TODO for missing attributes 2009-04-23 00:47:45 +00:00
Campbell Barton
6a270ecb94 BGE Python API
CListValue fixes
- Disable changing CValueLists that the BGE uses internally (scene.objects.append(1) would crash when drawing)
- val=clist+list would modify clist in place, now return a new value.
- clist.append([....]), was working like extend.
- clist.append(val) didnt work for most CValue types like KX_GameObjects.

Other changes
- "isValid" was always returning True.
- Set all errors for invalid proxy access to PyExc_SystemError (was using a mix of error types)
- Added PyObjectPlus::InvalidateProxy() to manually invalidate, though if python ever gains access again, it will make a new valid proxy. This is so removing an object from a scene can invalidate the object even if its stored elsewhere in a CValueList for eg.
2009-04-23 00:32:33 +00:00
Benoit Bolsee
90508ed125 BGE bug #17670: Python controlled mist doesnt work in textured mode. 2009-04-22 22:12:36 +00:00
Campbell Barton
fd108f1019 [#18586] [bug] Ray sensor doesn't return a hit object
Supporting len(GameOb) to see how many properties it has backfired since it can then evaluate as false.
2009-04-22 20:43:41 +00:00
Benoit Bolsee
48f483d14f BGE: some more cleanup, implement proper GetReplica/ProcessReplica workflow for touch/near/radar sensor. Remove duplicated code. 2009-04-22 18:20:41 +00:00
Benoit Bolsee
f6d27e73ee BGE: some more cleanup, remove useless ReplicaSetName(), move code to ProcessReplica. 2009-04-22 16:58:04 +00:00
Benoit Bolsee
076d1910f5 BGE: some more cleanup in GetReplica/ProcessReplica of deformers: make them consistent with the other classes. 2009-04-22 16:26:22 +00:00
Campbell Barton
5553d2c014 BGE C++ API
PyObjectPlus::ProcessReplica() is now called when any of its subclasses are replicated.

This is important because PyObjectPlus::ProcessReplica() NULL's the 'm_proxy' python pointer I added recently.
Without this a replicated subclass of PyObjectPlus could have an invalid pointer (crashing the BGE).

This change also means CValue::AddDataToReplica() can be moved into CValue::ProcessReplica() since ProcessReplica is always called.
2009-04-22 14:42:00 +00:00
Campbell Barton
a8592d09d0 BGE C++ API
Some functions used
	ProcessReplica(replica);
others
	replica->ProcessReplica()

Use the second method everywhere so the PyObjectPlus's ProcessReplica() can be called from its subclasses.

Note that PyObjectPlus's ProcessReplica isnt used yet.
2009-04-22 12:16:41 +00:00
Campbell Barton
785b784e09 BGE Python API
improved how attribute errors are set so each classes py_getattro function dosnt need to set an error if the attribute doesn't exist.
Now py_base_getattro sets an error on a NULL return value when no errors are set to avoid setting errors at multiple levels.
2009-04-22 09:47:57 +00:00
Nathan Letwory
88c58d6b2d BGE
* the ternary form refused to compile properly with msvc, rewrite a bit.
2009-04-22 06:30:32 +00:00
Campbell Barton
0145a93f24 Patch from Mitchell Stokes for KX_Light to use attrdef's
Added type access to the SCA_PropertyActuator, added missing function in library docs.
2009-04-21 23:15:18 +00:00
Benoit Bolsee
221f589f51 BGE bug #18521 fixed: Dupligroups + Bullet Softbodies are broken. 2009-04-21 21:33:03 +00:00
Benoit Bolsee
d11a5bbef2 BGE: Support mesh modifiers in the game engine.
Realtime modifiers applied on mesh objects will be supported in 
the game engine with the following limitations:

- Only real time modifiers are supported (basically all of them!)
- Virtual modifiers resulting from parenting are not supported: 
  armature, curve, lattice. You can still use these modifiers 
  (armature is really not recommended) but in non parent mode. 
  The BGE has it's own parenting capability for armature.
- Modifiers are computed on the host (using blender modifier
  stack).
- Modifiers are statically evaluated: any possible time dependency
  in the modifiers is not supported (don't know enough about
  modifiers to be more specific).
- Modifiers are reevaluated if the underlying mesh is deformed
  due to shape action or armature action. Beware that this is 
  very CPU intensive; modifiers should really be used for static
  objects only.
- Physics is still based on the original mesh: if you have a 
  mirror modifier, the physic shape will be limited to one half
  of the resulting object. Therefore, the modifiers should 
  preferably be used on graphic objects.
- Scripts have no access to the modified mesh. 
- Modifiers that are based on objects interaction (boolean,..)
  will not be dependent on the objects position in the GE.
  What you see in the 3D view is what you get in the GE regardless
  on the object position, velocity, etc.

Besides that, the feature is compatible with all the BGE features
that affect meshes: armature action, shape action, relace mesh, 
VideoTexture, add object, dupligroup.

Known problems:
- This feature is a bit hacky: the BGE uses the derived mesh draw 
  functions to display the object. This drawing method is a
  bit slow and is not 100% compatible with the BGE. There may
  be some problems in multi-texture mode: the multi-texture
  coordinates are not sent to the GPU. 
  Texface and GLSL on the other hand should be fully supported.
- Culling is still based on the extend of the original mesh. 
  If you have a modifer that extends the size of the mesh, 
  the object may disappear while still in the view frustrum.
- Derived mesh is not shared between replicas.
  The derived mesh is allocated and computed for each object
  with modifiers, regardless if they are static replicas.
- Display list are not created on objects with modifiers.
  
I should be able to fix the above problems before release.
However, the feature is already useful for game development.
Once you are ready to release the game, you can apply the modifiers
to get back display list support and mesh sharing capability.

MSVC, scons, Cmake, makefile updated.

Enjoy
/benoit
2009-04-21 11:01:09 +00:00
Campbell Barton
3e7cbd5388 Blender Python API
- Removed the gen_utils.c dependency from Mathutils (since gen_utils wont go into 2.5 but mathutils will), repalced with python functions.
- removed Blender.Mathutils.Point, since it was not documented, the C api never used it, none of our scripts used it (and I never saw a script that used it).
2009-04-21 09:44:29 +00:00
Benoit Bolsee
106b5a435c BGE: show profile in millisecond in addition to percentage. 2009-04-21 09:20:47 +00:00
Campbell Barton
720f7a8b69 use PyList_SET_ITEM instead of PyList_SetItem,
PyList_SetItem does error checking and decref's existing values, PyList_SET_ITEM is a macro for direct assignment, only for use on new lists.
2009-04-20 23:27:53 +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