[wpdev-commits] wolfpack/python tempeffect.h,1.8,1.9
Brought to you by:
rip,
thiagocorrea
|
From: <dar...@us...> - 2003-09-12 15:29:34
|
Update of /cvsroot/wpdev/wolfpack/python
In directory sc8-pr-cvs1:/tmp/cvs-serv11737/python
Modified Files:
tempeffect.h
Log Message:
Implemented serialization of effects to the database (experimental!).
Index: tempeffect.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/python/tempeffect.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** tempeffect.h 11 Sep 2003 16:19:51 -0000 1.8
--- tempeffect.h 12 Sep 2003 15:29:00 -0000 1.9
***************
*** 32,37 ****
--- 32,44 ----
#define __TEMPEFFECT_H__
+ #include "engine.h"
+ #include "utilities.h"
+
#include "../TmpEff.h"
+ #include "../persistentbroker.h"
+ #include "../globals.h"
+ #include "../dbdriver.h"
#include "../world.h"
+ #include "../console.h"
class cPythonEffect : public cTempEffect
***************
*** 149,215 ****
}
! void Serialize( ISerialization &archive )
{
! if( archive.isReading() )
{
! archive.read( "functionname", functionName );
! archive.read( "dispelfunc", dispelFunc_ );
! archive.read( "dispelid", dispelId_ );
! UINT32 pCount;
! QString type;
! archive.read( "pcount", pCount );
! args = PyTuple_New( pCount );
! for( UINT32 i = 0; i < pCount; ++i )
! {
! archive.read( QString( "pt%1" ).arg( i ), type );
! // Read an integer
! if( type == "i" )
! {
! INT32 data;
! archive.read( QString( "pv%1" ).arg( i ), data );
! PyObject *obj = PyInt_FromLong( data );
! PyTuple_SetItem( args, i, PyInt_FromLong( data ) );
! }
! // Read a string
! else if( type == "s" )
! {
! QString data;
! archive.read( QString( "pv%1" ).arg( i ), data );
! PyObject *obj = PyString_FromString( data.latin1() );
! PyTuple_SetItem( args, i, obj );
! }
! }
! }
! else if( archive.isWritting() )
{
! archive.write( "functionname", functionName );
! archive.write( "dispelfunc", dispelFunc_ );
! archive.write( "dispelid", dispelId_ );
! archive.write( "pcount", PyTuple_Size( args ) );
! // Serialize the py object
! for( UINT32 i = 0; i < PyTuple_Size( args ); ++i )
! {
! if( PyInt_Check( PyTuple_GetItem( args, i ) ) )
! {
! archive.write( QString( "pt%1" ).arg( i ), QString( "i" ) );
! archive.write( QString( "pv%1" ).arg( i ), (int)PyInt_AsLong( PyTuple_GetItem( args, i ) ) );
! }
! else if( PyString_Check( PyTuple_GetItem( args, i ) ) )
! {
! archive.write( QString( "pt%1" ).arg( i ), QString( "s" ) );
! archive.write( QString( "pv%1" ).arg( i ), PyString_AsString( PyTuple_GetItem( args, i ) ) );
! }
! // Something we can't save -> Py_None on load
! else
! archive.write( QString( "pt%1" ).arg( i ), QString( "n" ) );
! }
}
! cTempEffect::Serialize( archive );
}
};
--- 156,225 ----
}
! void save( unsigned int id )
{
! saveString( id, "functionname", functionName );
! saveString( id, "dispelfunc", dispelFunc_ );
! saveString( id, "dispelid", dispelId_ );
! saveInt( id, "pycount", PyTuple_Size( args ) );
!
! // Serialize the py object
! for( int i = 0; i < PyTuple_Size( args ); ++i )
{
! if( PyInt_Check( PyTuple_GetItem( args, i ) ) )
! {
! saveInt( id, "pyarg_" + QString::number( i ), (int)PyInt_AsLong( PyTuple_GetItem( args, i ) ) );
! }
! else if( PyString_Check( PyTuple_GetItem( args, i ) ) )
! {
! saveString( id, "pyarg_" + QString::number( i ), PyString_AsString( PyTuple_GetItem( args, i ) ) );
! }
! else if( PyFloat_Check( PyTuple_GetItem( args, i ) ) )
! {
! saveFloat( id, "pyarg_" + QString::number( i ), PyFloat_AsDouble( PyTuple_GetItem( args, i ) ) );
! }
! }
! cTempEffect::save( id );
! }
! void load( unsigned int id, const char **result )
! {
! // Load the Base Properties and then Select
! loadString( id, "functionname", functionName );
! loadString( id, "dispelfunc", dispelFunc_ );
! loadString( id, "dispelid", dispelId_ );
!
! int count;
! loadInt( id, "pycount", count );
! args = PyTuple_New( count );
!
! for( int i = 0; i < count; ++i )
! PyTuple_SetItem( args, i, Py_None );
!
! cDBResult res = persistentBroker->query( QString( "SELECT key,type,value FROM effects_properties WHERE id = %1 AND key LIKE 'pyarg_%'" ).arg( id ) );
!
! while( res.fetchrow() )
{
! QString key = res.getString( 0 );
! QString type = res.getString( 1 );
! QString value = res.getString( 2 );
! int id = key.right( key.length() - 3 ).toInt();
! if( id >= count )
! continue;
!
! if( type == "string" )
! PyTuple_SetItem( args, id, PyString_FromString( value.latin1() ) );
! else if( type == "int" )
! PyTuple_SetItem( args, id, PyInt_FromLong( value.toInt() ) );
! else if( type == "float" )
! PyTuple_SetItem( args, id, PyFloat_FromDouble( value.toFloat() ) );
}
! res.free();
!
! cTempEffect::load( id, result );
}
};
|