Author: ArcRiley Date: 2007-07-08 20:19:35 -0400 (Sun, 08 Jul 2007) New Revision: 435
Added: trunk/pysoy/src/_datatypes/Datatype.pxi trunk/pysoy/src/_datatypes/MaterialList.pxi Modified: trunk/pysoy/src/_datatypes/FaceList.pxi trunk/pysoy/src/_datatypes/VertexList.pxi trunk/pysoy/src/_datatypes/soy._datatypes.pxd trunk/pysoy/src/_datatypes/soy._datatypes.pyx Log: some work on ticket #257, weird desync with soy._datatypes.pxd Copied: trunk/pysoy/src/_datatypes/Datatype.pxi (from rev 434, trunk/pysoy/src/_datatypes/VertexList.pxi) =================================================================== --- trunk/pysoy/src/_datatypes/Datatype.pxi (rev 0) +++ trunk/pysoy/src/_datatypes/Datatype.pxi 2007-07-09 00:19:35 UTC (rev 435) @@ -0,0 +1,38 @@ +# PySoy _datatypes.Datatype class +# +# Copyright (C) 2007 Team PySoy +# +# 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$ + +# The only purpose of this class is to provide functions to other datatypes + +cdef class Datatype : + '''PySoy Datatype + + This is not useful to you. It provides C functions to other datatypes. + ''' + cdef void *_alloc(self, int num, int* m, void* store, int size) : + if num == 0 : + m[0] = 0 + py.PyMem_Free(store) + return NULL + if m[0] == 0 : + m[0] = num + 15 + return py.PyMem_Malloc(m[0] * size) + if num > m[0] or num+120 < m[0] : + m[0] = num + 15 + return py.PyMem_Realloc(store, m[0] * size) + return store Modified: trunk/pysoy/src/_datatypes/FaceList.pxi =================================================================== --- trunk/pysoy/src/_datatypes/FaceList.pxi 2007-07-08 22:26:22 UTC (rev 434) +++ trunk/pysoy/src/_datatypes/FaceList.pxi 2007-07-09 00:19:35 UTC (rev 435) @@ -1,4 +1,4 @@ -# PySoy _internals.FaceList class +# PySoy _datatypes.FaceList class # # Copyright (C) 2007 Team PySoy # @@ -17,7 +17,7 @@ # # $Id$ -cdef class FaceList : +cdef class FaceList (Datatype) : '''PySoy FaceList This is a list-like container class for the faces of a soy.bodies.Mesh @@ -52,6 +52,11 @@ # _found = 0 self._children.lock() + if _index < 0 : + _index = self._arraySize + _index + if _index < 0 or _index >= self._arraySize : + self._children.unlock() + raise IndexError('face index out of range') for i from 0 <= i < self._children.current : if (<soy.atoms.Face> self._children.list[i])._index == _index : _face = <soy.atoms.Face> self._children.list[i] @@ -89,7 +94,9 @@ if _index - self._updateRange.offset > self._updateRange.length : self._updateRange.length = _index - self._updateRange.offset + cdef void _sendUpdated(self) : + gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._buffer) if self._updateRange.offset == -1 : return # If in the process of writing, wait until next cycle to send @@ -113,5 +120,5 @@ cdef void _allocArray(self, int num) : cdef soy.meshes.Mesh _mesh _mesh = <soy.meshes.Mesh> self._mesh - self._array = <Face *> _mesh._alloc(num, &self._arrayAlloc, - self._array, sizeof(Face)) + self._array = <Face *> self._alloc(num, &self._arrayAlloc, + self._array, sizeof(Face)) Copied: trunk/pysoy/src/_datatypes/MaterialList.pxi (from rev 434, trunk/pysoy/src/_datatypes/VertexList.pxi) =================================================================== --- trunk/pysoy/src/_datatypes/MaterialList.pxi (rev 0) +++ trunk/pysoy/src/_datatypes/MaterialList.pxi 2007-07-09 00:19:35 UTC (rev 435) @@ -0,0 +1,104 @@ +# PySoy _datatypes.MaterialList class +# +# Copyright (C) 2007 Team PySoy +# +# 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$ + +# This class is not intended to be stored or transfered on it's own but +# rather as part of it's parent Mesh. Parent must be in __new__ as +# it's parent holds the data this class works on. + +cdef class MaterialList (Datatype) : + '''PySoy MaterialList + + This is a list-like container class for materials used by a mesh + ''' + def __new__(self, mesh) : + if not isinstance(mesh, soy.meshes.Mesh) : + raise TypeError('argument must be of type soy.bodies.Mesh') + self._mesh = <void *> mesh + self._children = soy._internals.Children() + self._ranges = NULL + + + def __len__(self) : + return self._children.current + + + def __str__(self) : + cdef int i + cdef object l + cdef soy.meshes.Mesh _mesh + l = [] + self._children.lock() + for i from 0 <= i < self._children.current : + l.append(<soy.materials.Material> self._children.list[i]) + self._children.unlock() + return str(l) + + + def __repr__(self) : + return '<MaterialList with %d materials>' % self.__len__() + + + def __getitem__(self, _index) : + cdef soy.materials.Material _mat + self._children.lock() + if _index < 0 : + _index = self._children.current + _index + if _index < 0 or _index >= self._children.current : + self._children.unlock() + raise IndexError('material index out of range') + _mat = <soy.materials.Material> self._children.list[_index] + self._children.unlock() + return _mat + + + cdef void _renderArray(self) : + cdef int i + cdef soy.meshes.Mesh _mesh + _mesh = <soy.meshes.Mesh> self._mesh + _mesh._verts._renderArray() + self._children.lock() + for i from 0 <= i < self._children.current : + (<soy.materials.Material> self._children.list[i])._bind() + _mesh._faces._renderArray(self._ranges[i].offset, self._ranges[i].length) + (<soy.materials.Material> self._children.list[i])._unbind() + self._children.unlock() + + + cdef void _renderBuffer(self) : + cdef int i + cdef soy.meshes.Mesh _mesh + if self._children.current == 0 : + return + _mesh = <soy.meshes.Mesh> self._mesh + if _mesh._faces._buffer == 0 : + mesh._faces._createBuffer() + mesh._verts._createBuffer() + mesh._faces._sendUpdated() + mesh._verts._renderBuffer() + self._children.lock() + for i from 0 <= i < self._children.current : + (<soy.materials.Material> self._children.list[i])._bind() + _mesh._faces._renderBuffer(self._ranges[i].offset, self._ranges[i].length) + (<soy.materials.Material> self._children.list[i])._unbind() + self._children.unlock() + + + cdef void _allocRanges(self, int num) : + self._ranges = <Range *> self._alloc(num, &self._rangesAlloc, + self._ranges, sizeof(Range)) Modified: trunk/pysoy/src/_datatypes/VertexList.pxi =================================================================== --- trunk/pysoy/src/_datatypes/VertexList.pxi 2007-07-08 22:26:22 UTC (rev 434) +++ trunk/pysoy/src/_datatypes/VertexList.pxi 2007-07-09 00:19:35 UTC (rev 435) @@ -1,4 +1,4 @@ -# PySoy _internals.VertexList class +# PySoy _datatypes.VertexList class # # Copyright (C) 2007 Team PySoy # @@ -21,7 +21,7 @@ # rather as part of it's parent Mesh. Parent must be in __new__ as # it's parent holds the data this class works on. -cdef class VertexList : +cdef class VertexList (Datatype) : '''PySoy VertexList This is a list-like container class for shared vertices. @@ -72,6 +72,11 @@ # _found = 0 self._children.lock() + if _index < 0 : + _index = self._arraySize + _index + if _index < 0 or _index >= self._arraySize : + self._children.unlock() + raise IndexError('vertex index out of range') for i from 0 <= i < self._children.current : if (<soy.atoms.Vertex> self._children.list[i])._index == _index : _vert = <soy.atoms.Vertex> self._children.list[i] @@ -89,6 +94,7 @@ gl.glNormalPointer ( gl.GL_FLOAT, 36, &self._array[0].nx) gl.glTexCoordPointer(3, gl.GL_FLOAT, 36, &self._array[0].tx) + cdef void _renderBuffer(self) : gl.glBindBufferARB (gl.GL_ARRAY_BUFFER_ARB, self._buffer) self._sendUpdated() @@ -137,5 +143,5 @@ cdef void _allocArray(self, int num) : cdef soy.meshes.Mesh _mesh _mesh = <soy.meshes.Mesh> self._mesh - self._array = <Vert *> _mesh._alloc(num, &self._arrayAlloc, - self._array, sizeof(Vert)) + self._array = <Vert *> self._alloc(num, &self._arrayAlloc, + self._array, sizeof(Vert)) Modified: trunk/pysoy/src/_datatypes/soy._datatypes.pxd =================================================================== --- trunk/pysoy/src/_datatypes/soy._datatypes.pxd 2007-07-08 22:26:22 UTC (rev 434) +++ trunk/pysoy/src/_datatypes/soy._datatypes.pxd 2007-07-09 00:19:35 UTC (rev 435) @@ -52,18 +52,31 @@ cdef void _insert(self, char*, float) cdef float _lookup(self, char*) cdef int _has_key(self, char*) - cdef int _remove(self, char*) -cdef class FaceList : +cdef class Datatype : + cdef void *_alloc(self, int, int*, void*, int) + + +cdef class MaterialList (Datatype) : cdef void *_mesh - cdef soy._internals.Children _children # was cface - cdef Face *_array # was faces - cdef unsigned int _arraySize # was nface - cdef int _arrayAlloc # was mface - cdef gl.GLuint _buffer # was bface - cdef int _bufferAlloc # was aface - cdef Range _updateRange # was uface + cdef soy._internals.Children _children + cdef Range *_ranges + cdef int _rangesAlloc + cdef void _allocRanges (self, int) + cdef void _renderArray (self) + cdef void _renderBuffer (self) + + +cdef class FaceList (Datatype) : + cdef void *_mesh + cdef soy._internals.Children _children + cdef Face *_array + cdef unsigned int _arraySize + cdef int _arrayAlloc + cdef gl.GLuint _buffer + cdef int _bufferAlloc + cdef Range _updateRange cdef void _allocArray (self, int) cdef void _renderArray (self, int, int) cdef void _renderBuffer (self, int, int) @@ -72,15 +85,15 @@ cdef void _flagUpdated (self, int) -cdef class VertexList : +cdef class VertexList (Datatype) : cdef void *_mesh - cdef soy._internals.Children _children # was cvert - cdef Vert *_array # was verts - cdef unsigned short _arraySize # was nvert - cdef int _arrayAlloc # was mvert - cdef gl.GLuint _buffer # was bvert - cdef int _bufferAlloc # was avert - cdef Range _updateRange # was uvert + cdef soy._internals.Children _children + cdef Vert *_array + cdef unsigned short _arraySize + cdef int _arrayAlloc + cdef gl.GLuint _buffer + cdef int _bufferAlloc + cdef Range _updateRange cdef void _allocArray (self, int) cdef void _renderArray (self) cdef void _renderBuffer (self) Modified: trunk/pysoy/src/_datatypes/soy._datatypes.pyx =================================================================== --- trunk/pysoy/src/_datatypes/soy._datatypes.pyx 2007-07-08 22:26:22 UTC (rev 434) +++ trunk/pysoy/src/_datatypes/soy._datatypes.pyx 2007-07-09 00:19:35 UTC (rev 435) @@ -29,6 +29,8 @@ cimport soy.atoms cimport soy.meshes +include "Datatype.pxi" include "HashTable.pxi" +include "MaterialList.pxi" include "FaceList.pxi" include "VertexList.pxi" _______________________________________________ PySoy-SVN mailing list [email protected] http://www.pysoy.org/mailman/listinfo/pysoy-svn
