Author: ArcRiley
Date: 2008-03-19 00:58:42 -0400 (Wed, 19 Mar 2008)
New Revision: 1175

Modified:
   trunk/pysoy/src/_internals/Loadable.pxi
   trunk/pysoy/src/_internals/soy._internals.pxd
   trunk/pysoy/src/textures/Image.pxi
   trunk/pysoy/src/textures/Texture.pxi
   trunk/pysoy/src/textures/Video.pxi
   trunk/pysoy/src/textures/soy.textures.pxd
   trunk/pysoy/src/transports/Transport.pxi
   trunk/pysoy/src/transports/soy.transports.pxd
Log:
No Ticket :
  * cleanup and comments in textures, transports, and _internals/Loadable
  * signifigant cleanup and renaming in TransportLoop


Modified: trunk/pysoy/src/_internals/Loadable.pxi
===================================================================
--- trunk/pysoy/src/_internals/Loadable.pxi     2008-03-19 00:10:23 UTC (rev 
1174)
+++ trunk/pysoy/src/_internals/Loadable.pxi     2008-03-19 04:58:42 UTC (rev 
1175)
@@ -20,17 +20,17 @@
 cimport py
 
 cdef class Loadable :
-  '''PySoy Loadable
+  '''soy._internals.Loadable
 
     This should be inherited by any PySoy class which can be loaded or saved.
   '''
   def __cinit__(self, source=None, *args, **keywords) :
     self._source = source
 
-  cdef int _coreLoad(self, void *_data, int _size) :
+  cdef int _load(self, void* _data, int _size) :
     return 0
 
-  cdef int _save(self, void *_data, int _size) :
+  cdef int _save(self, void* _data, int _size) :
     return 0
 
   cdef int _ready(self) :

Modified: trunk/pysoy/src/_internals/soy._internals.pxd
===================================================================
--- trunk/pysoy/src/_internals/soy._internals.pxd       2008-03-19 00:10:23 UTC 
(rev 1174)
+++ trunk/pysoy/src/_internals/soy._internals.pxd       2008-03-19 04:58:42 UTC 
(rev 1175)
@@ -54,7 +54,7 @@
 cdef class Loadable :
   cdef object            _source
   cdef int               _state
-  cdef int               _coreLoad     ( self, void*, int )
+  cdef int               _load         ( self, void*, int )
   cdef int               _save         ( self, void*, int )
   cdef int               _ready        ( self )
 

Modified: trunk/pysoy/src/textures/Image.pxi
===================================================================
--- trunk/pysoy/src/textures/Image.pxi  2008-03-19 00:10:23 UTC (rev 1174)
+++ trunk/pysoy/src/textures/Image.pxi  2008-03-19 04:58:42 UTC (rev 1175)
@@ -18,7 +18,7 @@
 # $Id$
 
 cdef class Image (Texture) :
-  '''PySoy textures.Image Class
+  '''soy.textures.Image
 
     This class loads an image (from PIL) as a 1D or 2D texture.
 

Modified: trunk/pysoy/src/textures/Texture.pxi
===================================================================
--- trunk/pysoy/src/textures/Texture.pxi        2008-03-19 00:10:23 UTC (rev 
1174)
+++ trunk/pysoy/src/textures/Texture.pxi        2008-03-19 04:58:42 UTC (rev 
1175)
@@ -1,4 +1,4 @@
-# PySoy's Texture class
+# PySoy's textures.Texture class
 #
 # Copyright (C) 2006,2007,2008 PySoy Group
 #
@@ -18,7 +18,7 @@
 # $Id$
 
 cdef class Texture (soy._internals.Loadable) :
-  '''PySoy Texture
+  '''soy.textures.Texture
 
     The base texture class which all others inherit
   '''
@@ -29,7 +29,12 @@
   #
 
   def __cinit__(self, *args, **keywords) :
+    #
+    # Alloc the texture _mutex lock
+    # this is used to prevent resizing/etc while rendering a texture
     self._mutex = py.PyThread_allocate_lock()
+    #
+    # These are OpenGL format mapping based on number of channels
     self._iFormats[1] = gl.GL_LUMINANCE8
     self._iFormats[2] = gl.GL_LUMINANCE8_ALPHA8
     self._iFormats[3] = gl.GL_RGB8
@@ -39,10 +44,18 @@
     self._oFormats[3] = gl.GL_RGB
     self._oFormats[4] = gl.GL_RGBA
 
+
   def __dealloc__(self) :
+    #
+    # Delete the GL texture if it's been created
+    # !!! This needs a rendering lock to be safe !!!
     if self._textureID != 0 :
       gl.glDeleteTextures(1, &self._textureID)
+    #
+    # Resizing to (0,0,0,0) frees the memory
     self._resize(0,0,0,0)
+    #
+    # Free the memory used for our mutex lock
     py.PyThread_free_lock(self._mutex)
 
 
@@ -69,38 +82,30 @@
 
 
   property channels :
+    '''Number of texture channels
+
+    1 = L     (Greyscale)
+    2 = LA    (Greyscale + Alpha)
+    3 = RGB   (Color)
+    4 = RGBA  (Color + Alpha)
+    '''
     def __get__(self) :
       return self._chans
 
 
-  property width :
-    def __get__(self) :
-      return self._width
-
-
-  property height :
-    def __get__(self) :
-      return self._height
-
-
-  property depth :
-    def __get__(self) :
-      return self._depth
-
-
   property size :
-    '''Texture's size
-
-    Size of the image file
+    '''Size of the texture
+ 
+    This will always be three dimensional, unused dimensions will be size 1.
     '''
     def __get__(self) :
       return (self._width, self._height, self._depth)
 
 
-  property pixels :
-    '''Texture.pixels
+  property texels :
+    '''Uncompressed, raw texel data
 
-    Uncompressed pixel data
+    Texel data size should equal width * height * depth * channels
     '''
     def __get__(self) :
       return <char*> self._texels
@@ -111,35 +116,52 @@
   # General C Functions
   #
 
-  cdef void _resize(self, int c, int x, int y, int z) :
+  cdef void _resize(self, int _c, int _x, int _y, int _z) :
+    #
+    # This function is called to allocate or free self._texels
+    # It will also set self._chans self._width self._height and self._depth
+    #
     cdef long int _size
-    _size = c*x*y*z
+    _size = _c * _x * _y * _z
+    #
     if _size == 0 :
+      #
+      # This is a request to free self._texels
       self._textureTarget = 0
       if self._width != 0 :
         py.PyMem_Free(self._texels)
-    elif z == 1 :
-      if y == 1 :
-        self._textureTarget = gl.GL_TEXTURE_1D
+    else :
+      #
+      # Determine the _textureTarget (number of dimensions)
+      if _z == 1 :
+        if _y == 1 :
+          self._textureTarget = gl.GL_TEXTURE_1D
+        else :
+          self._textureTarget = gl.GL_TEXTURE_2D
       else :
-        self._textureTarget = gl.GL_TEXTURE_2D
-    else :
-      self._textureTarget = gl.GL_TEXTURE_3D
-    if _size :
+        self._textureTarget = gl.GL_TEXTURE_3D
+      #
+      # Have we already alloc'ed?
       if self._width :
-        if self._chans*self._width*self._height*self._depth != _size :
+        # Yes - realloc if we're resizing to a different size as before
+        if self._chans * self._width * self._height * self._depth != _size :
           self._texels = <gl.GLubyte*> py.PyMem_Realloc(self._texels, _size)
       else :
+        # No, allocate a fresh buffer
         self._texels = <gl.GLubyte*> py.PyMem_Malloc(_size)
-    self._chans  = c
-    self._width  = x
-    self._height = y
-    self._depth  = z
+    #
+    # We're all done, set the object's new channels and size
+    self._chans  = _c
+    self._width  = _x
+    self._height = _y
+    self._depth  = _z
 
 
   cdef int _squareup(self, int _v) :
+    # 
     # This handy hack courtesy Sean Anderson, see:
     # http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
+    # 
     _v = _v - 1
     _v = _v | _v >> 1
     _v = _v | _v >> 2
@@ -155,7 +177,11 @@
   #
 
   cdef void _enable(self) :
+    #
+    # Lock to prevent resizing while we render
     py.PyThread_acquire_lock(self._mutex, 1)
+    #
+    # Enable our texture target
     if self._textureTarget == gl.GL_TEXTURE_1D :
       gl.glEnable(gl.GL_TEXTURE_1D)
     elif self._textureTarget == gl.GL_TEXTURE_2D :
@@ -169,17 +195,27 @@
     #else :
     #  gl.glEnable(gl.GL_BLEND)
     #  gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
+    #
     if self._textureID == 0 :
+      #
+      # If we haven't generated this texture yet
       gl.glGenTextures(1, &self._textureID)
       gl.glBindTexture(self._textureTarget, self._textureID)
       gl.glTexParameteri(self._textureTarget, gl.GL_TEXTURE_MAG_FILTER, 
                          gl.GL_LINEAR)
       gl.glTexParameteri(self._textureTarget, gl.GL_TEXTURE_MIN_FILTER, 
                          gl.GL_LINEAR)
+      #
+      # flag the texture for updating here so it'll be processed below
       self._update = 1
     else :
+      #
+      # Texture is already generated, bind it
       gl.glBindTexture(self._textureTarget, self._textureID)
+    #
     if self._update :
+      #
+      # If the texture needs updating
       if self._textureTarget == gl.GL_TEXTURE_1D :
         gl.glTexImage1D(gl.GL_TEXTURE_1D, 0, self._iFormats[self._chans],
                         self._width, 0, 
@@ -195,8 +231,14 @@
                         self._width, self._height, self._depth, 0, 
                         self._oFormats[self._chans], gl.GL_UNSIGNED_BYTE, 
                         self._texels)
+      #
+      # Update complete, clear the flag
       self._update = 0
+    #
+    # Do we need to scale the texture?
     if self._scaleX :
+      #
+      # Activate the texcoord matrix then scale them by the given amount
       gl.glMatrixMode(gl.GL_TEXTURE)
       gl.glScalef(self._scaleX, self._scaleY, self._scaleZ)
 
@@ -214,6 +256,8 @@
     elif self._textureTarget == gl.GL_TEXTURE_3D :
       gl.glDisable(gl.GL_TEXTURE_3D)
     if self._scaleX :
+      #
+      # Reset texture scaling
       gl.glMatrixMode(gl.GL_TEXTURE)
       gl.glLoadIdentity()
     py.PyThread_release_lock(self._mutex)
@@ -224,31 +268,38 @@
   # TransportLoop Functions
   #
 
-  cdef int _coreLoad(self, void *_data, int _size) :
+  cdef int _load(self, void* _vdata, int _size) :
+    #
+    # This function is called by a soy.transports.Transport for each .soy
+    # packet that's loaded.  We store the next packet number in self._state
+    # which is set to -1 if there's an error or we're finished.
+    #
+    # _i = iterator
+    #
+    cdef int _i
+    cdef unsigned char* _data
+    _data = <unsigned char*> _vdata
+    #
+    # Process this packet
     if self._state == 0 :
-      self._state = self._coreLoadPacket0(<unsigned char*> _data, _size)
+      #
+      # Load Packet 0 :
+      #
+      #   char _chans
+      #   char _width   \
+      #   char _height   } These are in values of 2^
+      #   char _depth   /
+      if _data[0] > 0 and _data[0] < 5 :
+        self._resize(_data[0], 1 << _data[1], 1 << _data[2], 1 << _data[3])
+        self._state = 1
+      else :
+        self._state -1
+      #
     elif self._state == 1 :
-      self._state = self._coreLoadPacket1(<unsigned char*> _data, _size)
-
-  cdef int _coreLoadPacket0(self, unsigned char *_data, int _size) :
-    '''
-    char _chans
-    char _width   \
-    char _height   } These are in values of 2^
-    char _depth   /
-    '''
-    if _data[0] > 0 and _data[0] < 5 :
-      self._resize(_data[0], 1 << _data[1], 1 << _data[2], 1 << _data[3])
-      return 1
-    else :
-      return -1
-
-
-  cdef int _coreLoadPacket1(self, unsigned char *_data, int _size) :
-    '''
-    Currently craptacularly common code crying for completion
-    '''
-    cdef int i
-    for i from 0 <= i < _size :
-      self._texels[i] = _data[i]
-    return -1
+      #
+      # Load Packet 1 :
+      #   Currently craptacularly common code crying for completion
+      # 
+      for _i from 0 <= _i < _size :
+        self._texels[_i] = _data[_i]
+      self._state = -1

Modified: trunk/pysoy/src/textures/Video.pxi
===================================================================
--- trunk/pysoy/src/textures/Video.pxi  2008-03-19 00:10:23 UTC (rev 1174)
+++ trunk/pysoy/src/textures/Video.pxi  2008-03-19 04:58:42 UTC (rev 1175)
@@ -23,10 +23,11 @@
 
     Renders an Ogg Theora stream to a texture
   '''
-  cdef int _coreLoad(self, void *_data, int _size) :
+
+  cdef int _load(self, void* _data, int _size) :
     cdef int x, y, _cx, _cy, _tx, _ty, _yl, _yc
     cdef int _py, _pu, _pv, _pr, _pg, _pb
-    cdef ogg.ogg_page   *_page
+    cdef ogg.ogg_page*   _page
     cdef ogg.yuv_buffer  _yuv
     cdef ogg.ogg_packet  _packet
     cdef double          _start  # for benchmarking

Modified: trunk/pysoy/src/textures/soy.textures.pxd
===================================================================
--- trunk/pysoy/src/textures/soy.textures.pxd   2008-03-19 00:10:23 UTC (rev 
1174)
+++ trunk/pysoy/src/textures/soy.textures.pxd   2008-03-19 04:58:42 UTC (rev 
1175)
@@ -1,4 +1,4 @@
-# PySoy textures declarations
+# PySoy's textures declarations
 #
 # Copyright (C) 2006,2007,2008 PySoy Group
 #
@@ -48,9 +48,6 @@
   # WindowLoop functions
   cdef void         _enable(self)
   cdef void         _disable(self)
-  # TransportLoop functions
-  cdef int          _coreLoadPacket0(self, unsigned char*, int) 
-  cdef int          _coreLoadPacket1(self, unsigned char*, int) 
 
 
 cdef class Print (Texture) :

Modified: trunk/pysoy/src/transports/Transport.pxi
===================================================================
--- trunk/pysoy/src/transports/Transport.pxi    2008-03-19 00:10:23 UTC (rev 
1174)
+++ trunk/pysoy/src/transports/Transport.pxi    2008-03-19 04:58:42 UTC (rev 
1175)
@@ -1,4 +1,4 @@
-# PySoy transports.Transport Class
+# PySoy's transports.Transport Class
 #
 # Copyright (C) 2006,2007,2008 PySoy Group
 #
@@ -18,30 +18,42 @@
 # $Id$
 
 cdef class Transport (soy._internals.Loopable) :
-  '''PySoy Transport
+  '''soy.transports.Transport
 
     This class provides the basic data stream parsing for all transports.
   '''
+
+  ############################################################################
+  #
+  # Python functions
+  #
+
   def __init__(self, path, loop=1, *args, **keywords) :
     cdef char _magic[4]
     self._objs = <Stored*> py.PyMem_Malloc(sizeof(Stored) * 4)
     self._mobj = 4
     self._dict = {}
-    if self._open(path) : 
-      if self._read(_magic,4) == 0 :
-        self._vers = -1
+    #
+    # If this file doesn't exist yet or is less than 4 characters long, return
+    if (not self._open(path)) or self._read(_magic,4) == 0 :
+      self._vers = -1
+      _transports._append(<void*> self)
+      return
+    #
+    # if "OggS" is the first four bytes, it's an Ogg file
+    if _magic[:4] == 'OggS' :
+      self._oggLoop = loop
+      self._oggHead()
+    #
+    # if "Soy" is the first three bytes, it's a Soy file
+    elif _magic[:3] == 'Soy' :
+      if _magic[3] == 0 :
+        self._soyHead()
       else :
-        if _magic[:3] == 'Soy' :
-          if _magic[3] == 0 :
-            self._headSoy()
-          else :
-            raise TypeError('unsupported soy version %d' % _magic[3])
-        elif _magic[:4] == 'OggS' :
-          self._oggLoop = loop
-          self._headOgg()
-        else :
-          self._vers = -10
-          raise TypeError('unsupported file type')
+        raise TypeError('unsupported soy version %d' % _magic[3])
+    else :
+      self._vers = -10
+      raise TypeError('unsupported file type')
     _transports._append(<void*> self)
 
 
@@ -49,15 +61,39 @@
     _transports._remove(<void*> self)
     py.PyMem_Free(self._objs)
 
+  def __getitem__(self, key) :
+    return self._dict[key]
 
+
+  def __repr__(self) :
+    return self._dict.__repr__()
+
+
+  def __str__(self) :
+    return self._dict.__str__()
+
+
+  def __len__(self) :
+    return self._dict.__len__()
+
+
+  ############################################################################
+  #
+  # TransportLoop functions
+  #
+  
   cdef int _loop(self) :
+    #
+    # If idle, just return now
     if self._mode == 0 :
-      return 10
-    elif self._mode == 1 :
+      return 1000
+    #
+    # Handle loading
+    if self._mode == 1 :
       if self._vers == 0 :
-        self._coreLoadSoy()
+        self._oggLoad()
       elif self._vers == 1 :
-        self._coreLoadOgg()
+        self._soyLoad()
     # If finished loading/saving, decref just before returning
       #py.Py_DECREF(self)
     return 1
@@ -78,26 +114,34 @@
     self._nobj = self._nobj + 1
     return self._nobj-1
 
-  cdef int _findName(self, char *_name, unsigned char _namelen) :
-    cdef int i
-    for i from 0 <= i < self._nobj :
-      if _namelen == self._objs[i].namelen and \
-         _name[:_namelen] == self._objs[i].name[:_namelen] :
-        return i
+  cdef int _indexName(self, char *_name, unsigned char _namelen) :
+    #
+    # this returns the index of a given object name in self._objs array
+    #
+    cdef int _i
+    for _i from 0 <= _i < self._nobj :
+      if _namelen == self._objs[_i].namelen and \
+         _name[:_namelen] == self._objs[_i].name[:_namelen] :
+        return _i
     return -1
 
 
-  cdef int _findSrno(self, int _serialno) :
-    cdef int i
-    for i from 0 <= i < self._nobj :
-      if _serialno == self._objs[i].serialno :
-        return i
+  cdef int _indexSerial(self, int _serialno) :
+    #
+    # this returns the index for a given serialno in the self._objs array
+    #
+    cdef int _i
+    for _i from 0 <= _i < self._nobj :
+      if _serialno == self._objs[_i].serialno :
+        return _i
     return -1
 
 
   ############################################################################
+  # 
   # Transport-specific functions
   #
+
   cdef int _open(self, path) :
     return 0
 
@@ -131,57 +175,12 @@
 
 
   ############################################################################
-  # Soy functions
   #
-  cdef void _headSoy(self) :
-    cdef unsigned int _i, _nobj
-    cdef unsigned char _l
-    cdef unsigned char _key[256], _cls[256]
-    cdef object _keystr, _clsstr
-    # We're assuming little endian here
-    self._read(<char*> (&_nobj), 4)
-    for _i from 0 <= _i < _nobj :
-      self._read(<char*> (&_l), 1)
-      self._read(<char*> _key, _l)
-      _keystr = py.PyString_FromStringAndSize(<char*> _key, _l) 
-      self._read(<char*> (&_l), 1)
-      self._read(<char*> _cls, _l)
-      _clsstr = py.PyString_FromStringAndSize(<char*> _cls, _l) 
-      if _clsstr == 'soy.textures.Texture' :
-        self._initObjt(_i, _keystr, soy.textures.Texture(source=self))
-    self._vers = 0 # Soy
-    self._mode = 1 # Loading
-
-  cdef void _coreLoadSoy(self) :
-    cdef unsigned char *_data
-    cdef unsigned int _serial, _length
-    self._readSoy(<char*> (&_serial), 4)
-    self._readSoy(<char*> (&_length), 4)
-    if self._mode == 0 :
-      return
-    _data = <unsigned char*> py.PyMem_Malloc(_length)
-    self._read(<char*> (_data), _length)
-    if self._mode == 0 :
-      py.PyMem_Free(_data)
-      return
-    (<soy._internals.Loadable> 
self._objs[_serial].object)._coreLoad(_data,_length)
-    py.PyMem_Free(_data)
-
-  cdef void _readSoy(self, char *_buffer, int _len) :
-    cdef int _bytes
-    if self._mode == 0 :
-      return
-    _bytes = self._read(_buffer, _len)
-    if _bytes != _len :
-      self._mode = 0
-
-
-  ############################################################################
   # Ogg functions
   #
-  cdef void _headOgg(self) :
-    cdef int i, _sn
-    cdef unsigned int m
+  cdef void _oggHead(self) :
+    cdef int _i, _sn
+    cdef unsigned int _m
     cdef char *_magic
     cdef ogg.ogg_page         _page
     cdef ogg.ogg_packet       _packet
@@ -194,48 +193,49 @@
     _magic[2] = 103
     _magic[3] = 83
     ogg.ogg_sync_wrote(&self._sync, 4)
-    while self._readOggPage(&_page) :
+    while self._oggReadPage(&_page) :
       if not ogg.ogg_page_bos(&_page) :
-        i = self._findSrno(ogg.ogg_page_serialno(&_page))
-        if i >= 0 :
-          (<soy._internals.Loadable> self._objs[i].object)._coreLoad(&_page, 0)
+        _i = self._indexSerial(ogg.ogg_page_serialno(&_page))
+        if _i >= 0 :
+          (<soy._internals.Loadable> self._objs[_i].object)._load(&_page, 0)
         break
       _sn = ogg.ogg_page_serialno(&_page)
       ogg.ogg_stream_init(&_testStream, _sn)
       ogg.ogg_stream_pagein(&_testStream, &_page)
       ogg.ogg_stream_packetout(&_testStream, &_packet)
       ogg.oggpackB_readinit(&_buffer, _packet.packet, _packet.bytes)
-      m = ogg.oggpackB_read(&_buffer, 32)
-      if m == 2155112549L :
-        i = self._initObjt(_sn, 'video', soy.textures.Video())
-        (<soy._internals.Loadable> self._objs[i].object)._coreLoad(&_page, 0)
+      _m = ogg.oggpackB_read(&_buffer, 32)
+      if _m == 2155112549L :
+        _i = self._initObjt(_sn, 'video', soy.textures.Video())
+        (<soy._internals.Loadable> self._objs[_i].object)._load(&_page, 0)
       # 24538994 = vorbis
       # 7828073 = writ
       # 1399874917L = speex
       # 2135313473L = flac
       ogg.ogg_stream_clear(&_testStream)
+    #
     # Grab the rest of the headers so codec instances can fully init
     while ogg.ogg_page_granulepos(&_page) == 0 :
-      if not self._readOggPage(&_page) :
+      if not self._oggReadPage(&_page) :
         break
       _sn = ogg.ogg_page_serialno(&_page)
-      i = self._findSrno(_sn)
-      if i >= 0 :
-        (<soy._internals.Loadable> self._objs[i].object)._coreLoad(&_page, 0)
-    self._vers = 1 # Ogg
+      _i = self._indexSerial(_sn)
+      if _i >= 0 :
+        (<soy._internals.Loadable> self._objs[_i].object)._load(&_page, 0)
+    self._vers = 0 # Ogg
     self._mode = 1 # Loading
 
 
-  cdef void _coreLoadOgg(self) :
+  cdef void _oggLoad(self) :
     cdef int i, _sn
     cdef ogg.ogg_page _page
     if not (<soy._internals.Loadable> self._objs[0].object)._ready() :
       return
-    if self._readOggPage(&_page) :
+    if self._oggReadPage(&_page) :
       _sn = ogg.ogg_page_serialno(&_page)
-      i = self._findSrno(_sn)
+      i = self._indexSerial(_sn)
       if i >= 0 :
-        (<soy._internals.Loadable> self._objs[i].object)._coreLoad(&_page, 0)
+        (<soy._internals.Loadable> self._objs[i].object)._load(&_page, 0)
     else :
       if self._oggLoop :
         self._rewind()
@@ -243,7 +243,7 @@
         self._mode = 0
     
 
-  cdef int _readOggPage(self, ogg.ogg_page *_oggPage) :
+  cdef int _oggReadPage(self, ogg.ogg_page *_oggPage) :
     cdef char *_buffer
     cdef int   _bytes
     while ogg.ogg_sync_pageout(&self._sync, _oggPage) == 0 :
@@ -257,19 +257,47 @@
 
 
   ############################################################################
-  # Python methods
   #
-  def __getitem__(self, key) :
-    return self._dict[key]
+  # Soy functions
+  #
+  cdef void _soyHead(self) :
+    cdef unsigned int _i, _nobj
+    cdef unsigned char _l
+    cdef unsigned char _key[256], _cls[256]
+    cdef object _keystr, _clsstr
+    # We're assuming little endian here
+    self._read(<char*> (&_nobj), 4)
+    for _i from 0 <= _i < _nobj :
+      self._read(<char*> (&_l), 1)
+      self._read(<char*> _key, _l)
+      _keystr = py.PyString_FromStringAndSize(<char*> _key, _l) 
+      self._read(<char*> (&_l), 1)
+      self._read(<char*> _cls, _l)
+      _clsstr = py.PyString_FromStringAndSize(<char*> _cls, _l) 
+      if _clsstr == 'soy.textures.Texture' :
+        self._initObjt(_i, _keystr, soy.textures.Texture(source=self))
+    self._vers = 1 # Soy
+    self._mode = 1 # Loading
 
+  cdef void _soyLoad(self) :
+    cdef unsigned char *_data
+    cdef unsigned int _serial, _length
+    self._readSoy(<char*> (&_serial), 4)
+    self._readSoy(<char*> (&_length), 4)
+    if self._mode == 0 :
+      return
+    _data = <unsigned char*> py.PyMem_Malloc(_length)
+    self._read(<char*> (_data), _length)
+    if self._mode == 0 :
+      py.PyMem_Free(_data)
+      return
+    (<soy._internals.Loadable> self._objs[_serial].object)._load(_data,_length)
+    py.PyMem_Free(_data)
 
-  def __repr__(self) :
-    return self._dict.__repr__()
-
-
-  def __str__(self) :
-    return self._dict.__str__()
-
-
-  def __len__(self) :
-    return self._dict.__len__()
+  cdef void _soyRead(self, char *_buffer, int _len) :
+    cdef int _bytes
+    if self._mode == 0 :
+      return
+    _bytes = self._read(_buffer, _len)
+    if _bytes != _len :
+      self._mode = 0

Modified: trunk/pysoy/src/transports/soy.transports.pxd
===================================================================
--- trunk/pysoy/src/transports/soy.transports.pxd       2008-03-19 00:10:23 UTC 
(rev 1174)
+++ trunk/pysoy/src/transports/soy.transports.pxd       2008-03-19 04:58:42 UTC 
(rev 1175)
@@ -31,7 +31,7 @@
 
 
 cdef class Transport (soy._internals.Loopable) :
-  cdef Stored                 *_objs
+  cdef Stored*                 _objs
   cdef object                  _dict
   cdef int                     _mobj
   cdef int                     _nobj
@@ -42,30 +42,30 @@
   cdef ogg.ogg_sync_state      _sync
   #
   # General Functions
-  cdef int   _initObjt(self, int, object, object)
-  cdef int   _findName(self, char*, unsigned char)
-  cdef int   _findSrno(self, int)
+  cdef int                     _initObjt       ( self, int, object, object )
+  cdef int                     _indexName      ( self, char*, unsigned char )
+  cdef int                     _indexSerial    ( self, int )
   #
   # Transport-specific functions
-  cdef int   _open  (self, path)
-  cdef int   _read  (self, char*, int)
-  cdef int   _write (self, char*, int)
-  cdef int   _goto  (self, long)
-  cdef int   _seek  (self, long)
-  cdef long  _tell  (self)
-  cdef void  _rewind(self)
-  cdef void  _close (self)
+  cdef int                     _open           ( self, object )
+  cdef int                     _read           ( self, char*, int )
+  cdef int                     _write          ( self, char*, int )
+  cdef int                     _goto           ( self, long )
+  cdef int                     _seek           ( self, long )
+  cdef long                    _tell           ( self )
+  cdef void                    _rewind         ( self )
+  cdef void                    _close          ( self )
   #
   # Soy functions
-  cdef void  _headSoy(self)
-  cdef void  _coreLoadSoy(self)
-  cdef void  _readSoy(self, char*, int)
+  cdef void                    _soyHead        ( self )
+  cdef void                    _soyLoad        ( self )
+  cdef void                    _soyRead        ( self, char*, int )
   #
   # Ogg functions
-  cdef void  _headOgg(self)
-  cdef void  _coreLoadOgg(self)
-  cdef int   _readOggPage(self, ogg.ogg_page *_oggPage)
-    
+  cdef void                    _oggHead        ( self )
+  cdef void                    _oggLoad        ( self )
+  cdef int                     _oggReadPage    ( self, ogg.ogg_page* )
 
+
 cdef class File (Transport) :
-  cdef void *_file
+  cdef void*                   _file

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to