Author: ArcRiley Date: 2008-02-06 05:20:00 -0500 (Wed, 06 Feb 2008) New Revision: 815
Added: trunk/pysoy/src/scenes/ trunk/pysoy/src/scenes/Scene.pxi trunk/pysoy/src/scenes/soy.scenes.pxd trunk/pysoy/src/scenes/soy.scenes.pyx Removed: trunk/pysoy/src/_core-common/Scene.pxi Log: Starting work on #903 Deleted: trunk/pysoy/src/_core-common/Scene.pxi =================================================================== --- trunk/pysoy/src/_core-common/Scene.pxi 2008-02-06 07:34:43 UTC (rev 814) +++ trunk/pysoy/src/_core-common/Scene.pxi 2008-02-06 10:20:00 UTC (rev 815) @@ -1,161 +0,0 @@ -# PySoy Scene Class -# -# Copyright (C) 2006,2007,2008 PySoy Group -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see http://www.gnu.org/licenses -# -# $Id$ - -cimport soy.bodies.lights - -cdef soy._internals.Children _scenes -_scenes = soy._internals.Children() - -cdef class Scene : - '''PySoy Scene - - Scenes are containers in physics space for bodies, joints, and shapes. - Objects in different worlds cannot interact, for example, bodies in two - different worlds cannot collide. Worlds also apply gravity to bodies. - ''' - - def __cinit__(self, *args, **kw) : - global _scenes - self._bodies = soy._internals.Children() - self._joints = soy._internals.Children() - self._lights = soy._internals.Children() - self._worldID = ode.dWorldCreate() - self._spaceID = ode.dSimpleSpaceCreate(NULL) - self._stepSize = 0.01 - self._prevTime = _time() - self._ambient = soy.colors.Gray() - _scenes.lock() - _scenes.append(<void *>self) - _scenes.unlock() - - - def __dealloc__(self) : - global _scenes - _scenes.lock() - _scenes.remove(<void *>self) - _scenes.unlock() - if self._worldID != NULL : - ode.dWorldDestroy(self._worldID) - if self._spaceID != NULL : - ode.dSpaceDestroy(self._spaceID) - - - def __repr__(self) : - report = [] - if self._bodies.current == 1 : - report.append('1 body') - elif self._bodies.current > 1 : - report.append('%d bodies' % self._bodies.current) - - if self._lights.current == 1 : - report.append('1 light') - elif self._bodies.current > 1 : - report.append('%d lights' % self._lights.current) - - if report == [] : return '<Empty Scene>' - else : return '<Scene with %s>' % ', '.join(report) - - - cdef void _render(self) : - cdef int i - cdef float _ambientLight[4] - - gl.glEnable(gl.GL_LIGHTING) - (<soy.colors.Color> self._ambient)._getRGBA(_ambientLight) - gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, _ambientLight) - self._lights.lock() - for i from 0 <= i < self._lights.current : - # This is a quick hack (gl.GL_LIGHT0+i) - (<soy.bodies.lights.Light> self._lights.list[i])._on(gl.GL_LIGHT0+i) - self._lights.unlock() - self._bodies.lock() - for i from 0 <= i < self._bodies.current : - (<soy.bodies._bodies.Body> self._bodies.list[i])._render() - self._bodies.unlock() - self._lights.lock() - for i from 0 <= i < self._lights.current : - # This is a quick hack (gl.GL_LIGHT0+i) - (<soy.bodies.lights.Light> self._lights.list[i])._off(gl.GL_LIGHT0+i) - self._lights.unlock() - gl.glDisable(gl.GL_LIGHTING) - - - cdef void _updateTime(self) : - self._time = _time() - - - cdef int _steps(self) : - cdef int _step - cdef double _lapsTime - _lapsTime = _time() - self._prevTime - if _lapsTime < ode.dEpsilon : - _lapsTime = ode.dEpsilon - _step = lround(_lapsTime / self._stepSize) - if _step > 12 : - _step = 12 - self._prevTime = self._prevTime + (_step * self._stepSize) - return _step - - - property gravity : - '''Scene gravity - - This is a scene-wide pseudo-force drawing all bodies in a single - direction. This should not be confused with a monopole force or other - forces which are often used for gravity in larger scenes. - - Takes a (x,y,z) tuple of numbers, defaults to (0.0, 0.0, 0.0) - ''' - def __get__(self) : - cdef ode.dVector3 grav - ode.dWorldGetGravity(self._worldID, grav) - return (grav[0], grav[1], grav[2]) - def __set__(self, value) : - ode.dWorldSetGravity(self._worldID, value[0], value[1], value[2]) - - - property stepsize : - '''Step Size - - This is the fraction of time each "step" calculates for. Larger steps - trade accuracy for speed. - - Takes a float, defaults to .01 - ''' - def __get__(self) : - return self._stepSize - def __set__(self, value) : - global _scenes - _scenes.lock() - self._stepSize = value - _scenes.unlock() - - - property ambient : - '''Scene's ambient light - - This is the ambient light for the scene. When no light is used this is - the only light available in the scene - use it well. - - Defaults to soy.colors.Gray(). - ''' - def __get__(self) : - return self._ambient - def __set__(self, soy.colors.Color value) : - self._ambient = value Copied: trunk/pysoy/src/scenes/Scene.pxi (from rev 814, trunk/pysoy/src/_core-common/Scene.pxi) =================================================================== --- trunk/pysoy/src/scenes/Scene.pxi (rev 0) +++ trunk/pysoy/src/scenes/Scene.pxi 2008-02-06 10:20:00 UTC (rev 815) @@ -0,0 +1,161 @@ +# PySoy Scene Class +# +# Copyright (C) 2006,2007,2008 PySoy Group +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cimport soy.bodies.lights + +cdef soy._internals.Children _scenes +_scenes = soy._internals.Children() + +cdef class Scene : + '''PySoy Scene + + Scenes are containers in physics space for bodies, joints, and shapes. + Objects in different worlds cannot interact, for example, bodies in two + different worlds cannot collide. Worlds also apply gravity to bodies. + ''' + + def __cinit__(self, *args, **kw) : + global _scenes + self._bodies = soy._internals.Children() + self._joints = soy._internals.Children() + self._lights = soy._internals.Children() + self._worldID = ode.dWorldCreate() + self._spaceID = ode.dSimpleSpaceCreate(NULL) + self._stepSize = 0.01 + self._prevTime = _time() + self._ambient = soy.colors.Gray() + _scenes.lock() + _scenes.append(<void *>self) + _scenes.unlock() + + + def __dealloc__(self) : + global _scenes + _scenes.lock() + _scenes.remove(<void *>self) + _scenes.unlock() + if self._worldID != NULL : + ode.dWorldDestroy(self._worldID) + if self._spaceID != NULL : + ode.dSpaceDestroy(self._spaceID) + + + def __repr__(self) : + report = [] + if self._bodies.current == 1 : + report.append('1 body') + elif self._bodies.current > 1 : + report.append('%d bodies' % self._bodies.current) + + if self._lights.current == 1 : + report.append('1 light') + elif self._bodies.current > 1 : + report.append('%d lights' % self._lights.current) + + if report == [] : return '<Empty Scene>' + else : return '<Scene with %s>' % ', '.join(report) + + + cdef void _render(self) : + cdef int i + cdef float _ambientLight[4] + + gl.glEnable(gl.GL_LIGHTING) + (<soy.colors.Color> self._ambient)._getRGBA(_ambientLight) + gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, _ambientLight) + self._lights.lock() + for i from 0 <= i < self._lights.current : + # This is a quick hack (gl.GL_LIGHT0+i) + (<soy.bodies.lights.Light> self._lights.list[i])._on(gl.GL_LIGHT0+i) + self._lights.unlock() + self._bodies.lock() + for i from 0 <= i < self._bodies.current : + (<soy.bodies._bodies.Body> self._bodies.list[i])._render() + self._bodies.unlock() + self._lights.lock() + for i from 0 <= i < self._lights.current : + # This is a quick hack (gl.GL_LIGHT0+i) + (<soy.bodies.lights.Light> self._lights.list[i])._off(gl.GL_LIGHT0+i) + self._lights.unlock() + gl.glDisable(gl.GL_LIGHTING) + + + cdef void _updateTime(self) : + self._time = _time() + + + cdef int _steps(self) : + cdef int _step + cdef double _lapsTime + _lapsTime = _time() - self._prevTime + if _lapsTime < ode.dEpsilon : + _lapsTime = ode.dEpsilon + _step = lround(_lapsTime / self._stepSize) + if _step > 12 : + _step = 12 + self._prevTime = self._prevTime + (_step * self._stepSize) + return _step + + + property gravity : + '''Scene gravity + + This is a scene-wide pseudo-force drawing all bodies in a single + direction. This should not be confused with a monopole force or other + forces which are often used for gravity in larger scenes. + + Takes a (x,y,z) tuple of numbers, defaults to (0.0, 0.0, 0.0) + ''' + def __get__(self) : + cdef ode.dVector3 grav + ode.dWorldGetGravity(self._worldID, grav) + return (grav[0], grav[1], grav[2]) + def __set__(self, value) : + ode.dWorldSetGravity(self._worldID, value[0], value[1], value[2]) + + + property stepsize : + '''Step Size + + This is the fraction of time each "step" calculates for. Larger steps + trade accuracy for speed. + + Takes a float, defaults to .01 + ''' + def __get__(self) : + return self._stepSize + def __set__(self, value) : + global _scenes + _scenes.lock() + self._stepSize = value + _scenes.unlock() + + + property ambient : + '''Scene's ambient light + + This is the ambient light for the scene. When no light is used this is + the only light available in the scene - use it well. + + Defaults to soy.colors.Gray(). + ''' + def __get__(self) : + return self._ambient + def __set__(self, soy.colors.Color value) : + self._ambient = value Copied: trunk/pysoy/src/scenes/soy.scenes.pxd (from rev 814, trunk/pysoy/src/_core-x11/soy._core.pxd) =================================================================== --- trunk/pysoy/src/scenes/soy.scenes.pxd (rev 0) +++ trunk/pysoy/src/scenes/soy.scenes.pxd 2008-02-06 10:20:00 UTC (rev 815) @@ -0,0 +1,110 @@ +# PySoy Core Declarations (for X11-based systems) +# +# Copyright (C) 2006,2007,2008 PySoy Group +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cimport gl +cimport glx +cimport glib +cimport ode +cimport ogg +cimport py +cimport stdio +cimport soy._datatypes +cimport soy._internals +cimport soy.colors +cimport soy.textures + +cdef void _sleep ( unsigned int ) +cdef double _time ( ) + +cdef soy._datatypes.AsyncQueue _get_queue ( ) + +cdef class Scene : + cdef ode.dWorldID _worldID + cdef ode.dSpaceID _spaceID + cdef soy._internals.Children _bodies + cdef soy._internals.Children _joints + cdef soy._internals.Children _lights + cdef soy.colors.Color _ambient + cdef ode.dReal _stepSize + cdef double _prevTime + cdef double _time + # _coreloop methods + cdef void _render(self) + cdef int _steps(self) + cdef void _updateTime(self) + + +cdef class Screen : + cdef glx.Screen *_screen + cdef int _screenID + cdef glx.Atom _wmDelWin + cdef glx.XF86VidModeModeInfo _deskMode + cdef glx.XVisualInfo *_xVisualInfo + cdef object _fullScreen + # OpenGL Support + cdef int _glVersion + cdef void _glewInit(self) + cdef void _events(self) + +cdef class Window : + cdef soy._internals.Children _controllers + cdef soy._internals.Children _widgets + cdef Screen _screen + cdef glx.Window _windowID + cdef object _title + cdef soy.textures.Texture _icon + cdef glx.Pixmap _iconID + cdef soy.colors.Color _background + cdef int _width + cdef int _height + cdef int _savedWidth + cdef int _savedHeight + cdef int _opened + cdef int _splash + # _coreloop methods + cdef void _create(self, int, int, int, int) + cdef void _destroy(self) + cdef void _render(self) + cdef void _resize(self, int _width, int _height) + cdef void _setProperties( self ) + cdef void _eventKeyDown ( self, glx.Time, + glx.KeyCode, glx.KeySym ) + cdef void _eventKeyUp ( self, glx.Time, + glx.KeyCode, glx.KeySym ) + cdef void _eventButtonDown( self, glx.Time, + unsigned int, int, int ) + cdef void _eventButtonUp ( self, glx.Time, + unsigned int, int, int ) + cdef void _eventMotion ( self, glx.Time, int, int ) + cdef void _eventWinClose ( self ) + + +cdef extern from "sys/time.h" : + cdef struct timeval : + long int tv_sec + long int tv_usec + int gettimeofday (timeval *tv, void *tz ) + +cdef extern from "math.h" : + long int lround (double x) + long int lroundf (float x) + float fabsf (float number) + +cdef extern from "unistd.h" : + void usleep(unsigned long usec) Copied: trunk/pysoy/src/scenes/soy.scenes.pyx (from rev 814, trunk/pysoy/src/_core-x11/soy._core.pyx) =================================================================== --- trunk/pysoy/src/scenes/soy.scenes.pyx (rev 0) +++ trunk/pysoy/src/scenes/soy.scenes.pyx 2008-02-06 10:20:00 UTC (rev 815) @@ -0,0 +1,48 @@ +'''3d Game Engine + +Description, description + +See http://www.pysoy.org/ for more information. +''' +__credits__ = '''Copyright (C) 2006,2007,2008 PySoy Group + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see http://www.gnu.org/licenses +''' +__author__ = '''Maintained by ArcRiley''' +__date__ = 'Last change on '+ \ + '$Date$'[7:-20]+ \ + 'by '+'$Author$'[9:-2] +__version__ = 'Trunk (r'+'$Rev$'[6:-2]+')' + +cimport soy.joints +cimport soy.bodies.fields +cimport soy.bodies._bodies +cimport soy.widgets +import soy.colors + +include "../_core-common/_Transports.pxi" +include "../_core-common/Scene.pxi" +include "_sleep.pxi" +include "_time.pxi" +include "Screen.pxi" +include "Window.pxi" + +# These must be last and in this order +include "../_core-common/_eventLoop.pxi" +include "../_core-common/quit.pxi" +include "../_core-common/_callback.pxi" +include "../_core-common/_coreLoop.pxi" +include "../_core-common/_runField.pxi" +include "../_core-common/_prerunField.pxi" +include "../_core-common/_init.pxi" _______________________________________________ PySoy-SVN mailing list [email protected] http://www.pysoy.org/mailman/listinfo/pysoy-svn
