Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27923
Modified Files:
basechar.cpp basechar.h basics.cpp basics.h corpse.cpp
corpse.h guilds.cpp guilds.h items.cpp items.h multi.cpp
multi.h npc.cpp npc.h persistentobject.cpp persistentobject.h
player.cpp player.h server.cpp uobject.cpp uobject.h
wolfpack.vcproj world.cpp
Log Message:
Some very nice cleanups for the serialization code.
THIS IS EXPERIMENTAL
No release until fully tested.
Index: uobject.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/uobject.cpp,v
retrieving revision 1.172
retrieving revision 1.173
diff -C2 -d -r1.172 -r1.173
*** uobject.cpp 10 Aug 2004 03:15:57 -0000 1.172
--- uobject.cpp 15 Aug 2004 02:17:39 -0000 1.173
***************
*** 99,106 ****
}
- void cUObject::init()
- {
- }
-
void cUObject::moveTo( const Coord_cl& newpos, bool noRemove )
{
--- 99,102 ----
***************
*** 268,277 ****
Builds the SQL string needed to retrieve all objects of this type.
*/
! void cUObject::buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions )
{
// We are requiring fixed order by now, so this *is* possible
fields.push_back( "uobject.name,uobject.serial,uobject.multis,uobject.pos_x,uobject.pos_y,uobject.pos_z,uobject.pos_map,uobject.events,uobject.havetags" );
tables.push_back( "uobject" );
conditions.push_back( "uobjectmap.serial = uobject.serial" );
}
--- 264,275 ----
Builds the SQL string needed to retrieve all objects of this type.
*/
! void cUObject::buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions )
{
// We are requiring fixed order by now, so this *is* possible
fields.push_back( "uobject.name,uobject.serial,uobject.multis,uobject.pos_x,uobject.pos_y,uobject.pos_z,uobject.pos_map,uobject.events,uobject.havetags" );
tables.push_back( "uobject" );
+ tables.push_back( "uobjectmap" );
conditions.push_back( "uobjectmap.serial = uobject.serial" );
+ conditions.push_back( QString("uobjectmap.type = '%1'").arg(objectid) );
}
***************
*** 1063,1068 ****
}
! void cUObject::save( cBufferedWriter& writer )
! {
writer.setObjectCount( writer.objectCount() + 1 );
writer.writeByte( getClassid() );
--- 1061,1065 ----
}
! void cUObject::save(cBufferedWriter& writer) {
writer.setObjectCount( writer.objectCount() + 1 );
writer.writeByte( getClassid() );
Index: uobject.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/uobject.h,v
retrieving revision 1.102
retrieving revision 1.103
diff -C2 -d -r1.102 -r1.103
*** uobject.h 10 Aug 2004 03:15:57 -0000 1.102
--- uobject.h 15 Aug 2004 02:17:39 -0000 1.103
***************
*** 80,85 ****
// Things for building the SQL string
! static void buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions );
! void init();
enum eChanged
--- 80,84 ----
// Things for building the SQL string
! static void buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions );
enum eChanged
***************
*** 129,139 ****
// Wrapper
! virtual void load( cBufferedReader& reader ) = 0;
! virtual void save( cBufferedWriter& reader );
// "Real" ones
! virtual void load( cBufferedReader& reader, unsigned int version );
! virtual void save( cBufferedWriter& reader, unsigned int version );
! virtual void postload( unsigned int version ) = 0;
// Utility Methods
--- 128,138 ----
// Wrapper
! void load( cBufferedReader& reader ) = 0;
! void save( cBufferedWriter& reader );
// "Real" ones
! void load( cBufferedReader& reader, unsigned int version );
! void save( cBufferedWriter& reader, unsigned int version );
! void postload( unsigned int version ) = 0;
// Utility Methods
***************
*** 238,291 ****
#pragma pack()
- class cUObjectFactory : public Factory<cUObject, QString>
- {
- public:
- cUObjectFactory()
- {
- lastid = 0;
- }
-
- unsigned int registerSqlQuery( const QString& type, const QString& query )
- {
- sql_queries.insert( std::make_pair( type, query ) );
- sql_keys.push_back( type );
-
- if ( lastid + 1 < lastid )
- {
- throw wpException( "Only 256 types can be registered with the UObject factory." );
- }
-
- typemap.insert( lastid, type );
- return lastid++;
- }
-
- QString findSqlQuery( const QString& type ) const
- {
- std::map<QString, QString>::const_iterator iter = sql_queries.find( type );
-
- if ( iter == sql_queries.end() )
- return QString::null;
- else
- return iter->second;
- }
-
- QStringList objectTypes() const
- {
- return sql_keys;
- }
-
- const QMap<unsigned char, QString>& getTypemap()
- {
- return typemap;
- }
-
- private:
- std::map<QString, QString> sql_queries;
- QMap<unsigned char, QString> typemap;
- QStringList sql_keys;
- unsigned char lastid;
- };
-
- typedef SingletonHolder<cUObjectFactory> UObjectFactory;
-
#endif // __UOBJECT_H__
--- 237,239 ----
Index: basics.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basics.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** basics.cpp 10 Aug 2004 03:15:56 -0000 1.32
--- basics.cpp 15 Aug 2004 02:17:39 -0000 1.33
***************
*** 283,288 ****
// Start writing the object type list
! const QMap<unsigned char, QString> &typemap = UObjectFactory::instance()->getTypemap();
! QMap<unsigned char, QString>::const_iterator it;
d->skipmap.clear();
--- 283,288 ----
// Start writing the object type list
! const QMap<unsigned char, QCString> &typemap = BinaryTypemap::instance()->getTypemap();
! QMap<unsigned char, QCString>::const_iterator it;
d->skipmap.clear();
***************
*** 292,296 ****
writeByte( it.key() );
writeInt( 0 ); // SkipSize
! writeAscii( it.data().latin1() ); // Preinsert into the dictionary
d->skipmap.insert( it.key(), 0 );
d->typemap.insert( it.key(), it.data() );
--- 292,296 ----
writeByte( it.key() );
writeInt( 0 ); // SkipSize
! writeAscii( it.data() ); // Preinsert into the dictionary
d->skipmap.insert( it.key(), 0 );
d->typemap.insert( it.key(), it.data() );
Index: multi.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/multi.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** multi.cpp 12 Aug 2004 03:02:50 -0000 1.13
--- multi.cpp 15 Aug 2004 02:17:39 -0000 1.14
***************
*** 62,65 ****
--- 62,69 ----
}
+ void cMulti::buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions ) {
+ cItem::buildSqlString(objectid, fields, tables, conditions);
+ }
+
const char* cMulti::className() const
{
***************
*** 150,166 ****
}
! static cUObject* productCreator()
! {
! return new cMulti;
! }
!
! void cMulti::registerInFactory()
! {
! QStringList fields, tables, conditions;
! cItem::buildSqlString( fields, tables, conditions ); // Build our SQL string
! QString sqlString = QString( "SELECT %1 FROM uobjectmap,%2 WHERE uobjectmap.type = 'cMulti' AND %3" ).arg( fields.join( "," ) ).arg( tables.join( "," ) ).arg( conditions.join( " AND " ) );
! UObjectFactory::instance()->registerType( "cMulti", productCreator );
! classid = UObjectFactory::instance()->registerSqlQuery( "cMulti", sqlString );
! }
unsigned char cMulti::classid;
--- 154,158 ----
}
! static FactoryRegistration<cMulti> registration("cMulti");
unsigned char cMulti::classid;
Index: items.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/items.cpp,v
retrieving revision 1.433
retrieving revision 1.434
diff -C2 -d -r1.433 -r1.434
*** items.cpp 14 Aug 2004 09:27:45 -0000 1.433
--- items.cpp 15 Aug 2004 02:17:39 -0000 1.434
***************
*** 1433,1452 ****
}
- static cUObject* productCreator()
- {
- return new cItem;
- }
-
- void cItem::registerInFactory()
- {
- QStringList fields, tables, conditions;
- buildSqlString( fields, tables, conditions ); // Build our SQL string
- QString sqlString = QString( "SELECT %1 FROM uobjectmap,%2 WHERE uobjectmap.type = 'cItem' AND %3" ).arg( fields.join( "," ) ).arg( tables.join( "," ) ).arg( conditions.join( " AND " ) );
- UObjectFactory::instance()->registerType( "cItem", productCreator );
- classid = UObjectFactory::instance()->registerSqlQuery( "cItem", sqlString );
- }
-
unsigned char cItem::classid;
void cItem::load( char** result, UINT16& offset )
{
--- 1433,1440 ----
}
unsigned char cItem::classid;
+ static FactoryRegistration<cItem> registration("cItem");
+
void cItem::load( char** result, UINT16& offset )
{
***************
*** 1488,1494 ****
}
! void cItem::buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions )
{
! cUObject::buildSqlString( fields, tables, conditions );
fields.push_back( "items.id,items.color,items.cont,items.layer,items.amount,items.hp,items.maxhp,items.movable,items.owner,items.visible,items.priv,items.baseid" );
tables.push_back( "items" );
--- 1476,1482 ----
}
! void cItem::buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions )
{
! cUObject::buildSqlString( objectid, fields, tables, conditions );
fields.push_back( "items.id,items.color,items.cont,items.layer,items.amount,items.hp,items.maxhp,items.movable,items.owner,items.visible,items.priv,items.baseid" );
tables.push_back( "items" );
Index: corpse.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/corpse.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -C2 -d -r1.62 -r1.63
*** corpse.cpp 10 Aug 2004 03:15:56 -0000 1.62
--- corpse.cpp 15 Aug 2004 02:17:39 -0000 1.63
***************
*** 43,65 ****
using namespace std;
! static cUObject* productCreator()
! {
! return new cCorpse;
! }
!
! void cCorpse::registerInFactory()
! {
! QStringList fields, tables, conditions;
! buildSqlString( fields, tables, conditions ); // Build our SQL string
! QString sqlString = QString( "SELECT %1 FROM uobjectmap,%2 WHERE uobjectmap.type = 'cCorpse' AND %3" ).arg( fields.join( "," ) ).arg( tables.join( "," ) ).arg( conditions.join( " AND " ) );
! UObjectFactory::instance()->registerType( "cCorpse", productCreator );
! classid = UObjectFactory::instance()->registerSqlQuery( "cCorpse", sqlString );
! }
unsigned char cCorpse::classid;
! void cCorpse::buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions )
{
! cItem::buildSqlString( fields, tables, conditions );
fields.push_back( "corpses.bodyid,corpses.hairstyle,corpses.haircolor,corpses.beardstyle,corpses.beardcolor" );
fields.push_back( "corpses.direction,corpses.charbaseid,corpses.murderer,corpses.murdertime" );
--- 43,53 ----
using namespace std;
! static FactoryRegistration<cCorpse> registration("cCorpse");
unsigned char cCorpse::classid;
! void cCorpse::buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions )
{
! cItem::buildSqlString( objectid, fields, tables, conditions );
fields.push_back( "corpses.bodyid,corpses.hairstyle,corpses.haircolor,corpses.beardstyle,corpses.beardcolor" );
fields.push_back( "corpses.direction,corpses.charbaseid,corpses.murderer,corpses.murdertime" );
Index: items.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/items.h,v
retrieving revision 1.211
retrieving revision 1.212
diff -C2 -d -r1.211 -r1.212
*** items.h 14 Aug 2004 03:40:36 -0000 1.211
--- items.h 15 Aug 2004 02:17:39 -0000 1.212
***************
*** 183,186 ****
--- 183,189 ----
cItem( const cItem& src ); // Copy constructor
+ static void setClassid(unsigned char id) {
+ cItem::classid = id;
+ }
unsigned char getClassid()
***************
*** 545,557 ****
static P_ITEM createFromList( const QString& list );
static P_ITEM createFromId( unsigned short id );
! static void registerInFactory();
protected:
// Methods
- static void buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions );
virtual void processNode( const cElement* Tag );
void processModifierNode( const cElement* Tag );
- protected:
unsigned short id_; // Display id of the item
unsigned short color_ : 12; // Color of this item (Note: only colors up to 0xBFF available -> 12 bit)
--- 548,559 ----
static P_ITEM createFromList( const QString& list );
static P_ITEM createFromId( unsigned short id );
!
! static void buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions );
protected:
// Methods
virtual void processNode( const cElement* Tag );
void processModifierNode( const cElement* Tag );
unsigned short id_; // Display id of the item
unsigned short color_ : 12; // Color of this item (Note: only colors up to 0xBFF available -> 12 bit)
Index: basics.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basics.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** basics.h 10 Aug 2004 03:15:56 -0000 1.25
--- basics.h 15 Aug 2004 02:17:39 -0000 1.26
***************
*** 121,123 ****
#endif
-
--- 121,122 ----
Index: server.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/server.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** server.cpp 10 Aug 2004 03:15:57 -0000 1.16
--- server.cpp 15 Aug 2004 02:17:39 -0000 1.17
***************
*** 442,452 ****
void cServer::load()
{
- // Registers our Built-in types into factory.
- cPlayer::registerInFactory();
- cMulti::registerInFactory();
- cNPC::registerInFactory();
- cItem::registerInFactory();
- cCorpse::registerInFactory();
-
// NPC AI types
Monster_Aggressive_L0::registerInFactory();
--- 442,445 ----
Index: basechar.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basechar.h,v
retrieving revision 1.79
retrieving revision 1.80
diff -C2 -d -r1.79 -r1.80
*** basechar.h 13 Aug 2004 08:55:24 -0000 1.79
--- basechar.h 15 Aug 2004 02:17:39 -0000 1.80
***************
*** 631,635 ****
// other protected methods
! static void buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions );
virtual void processNode( const cElement* Tag );
--- 631,635 ----
// other protected methods
! static void buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions );
virtual void processNode( const cElement* Tag );
Index: corpse.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/corpse.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** corpse.h 10 Aug 2004 03:15:56 -0000 1.27
--- corpse.h 15 Aug 2004 02:17:39 -0000 1.28
***************
*** 43,47 ****
{
private:
- static void buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions );
bool changed_;
static unsigned char classid;
--- 43,46 ----
***************
*** 62,65 ****
--- 61,66 ----
// they're displayed as equipment
public:
+ static void buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions );
+
unsigned char getClassid()
{
***************
*** 67,70 ****
--- 68,75 ----
}
+ static void setClassid(unsigned char id) {
+ cCorpse::classid = id;
+ }
+
cCorpse( bool init = false );
void setBodyId( UINT16 data );
***************
*** 109,113 ****
// DB Serialization
- static void registerInFactory();
void load( char**, UINT16& );
void save();
--- 114,117 ----
Index: player.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/player.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** player.h 12 Aug 2004 03:02:51 -0000 1.54
--- player.h 15 Aug 2004 02:17:39 -0000 1.55
***************
*** 71,75 ****
// implementation of interfaces
- static void registerInFactory();
void load( char**, UINT16& );
void save();
--- 71,74 ----
***************
*** 201,204 ****
--- 200,207 ----
const char* className() const;
+ static void setClassid(unsigned char id) {
+ cPlayer::classid = id;
+ }
+
unsigned char getClassid()
{
***************
*** 206,209 ****
--- 209,214 ----
}
+ static void buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions );
+
private:
bool changed_;
***************
*** 212,216 ****
protected:
// interface implementation
- static void buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions );
// Reference to a guild this character is in
--- 217,220 ----
Index: persistentobject.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/persistentobject.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** persistentobject.cpp 2 Jun 2004 15:04:06 -0000 1.9
--- persistentobject.cpp 15 Aug 2004 02:17:39 -0000 1.10
***************
*** 50,51 ****
--- 50,57 ----
isPersistent = true;
}
+
+ void PersistentObject::postload( unsigned int version ) {
+ }
+
+ static void buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions ) {
+ }
Index: persistentobject.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/persistentobject.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** persistentobject.h 2 Jun 2004 15:04:06 -0000 1.12
--- persistentobject.h 15 Aug 2004 02:17:39 -0000 1.13
***************
*** 29,33 ****
--- 29,40 ----
#define __PERSISTENTOBJECT_H__
+ #include <typeinfo>
#include <qobject.h>
+ #include <qstringlist.h>
+ #include "singleton.h"
+ #include "factory.h"
+
+ class cBufferedReader;
+ class cBufferedWriter;
#pragma pack(1)
***************
*** 41,44 ****
--- 48,53 ----
{
}
+
+ static void buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions );
virtual bool del();
***************
*** 46,49 ****
--- 55,67 ----
virtual void save();
+ // Wrapper
+ virtual void load( cBufferedReader& reader ) = 0;
+ virtual void save( cBufferedWriter& reader ) = 0;
+
+ // "Real" ones
+ virtual void load( cBufferedReader& reader, unsigned int version ) = 0;
+ virtual void save( cBufferedWriter& reader, unsigned int version ) = 0;
+ virtual void postload( unsigned int version );
+
virtual const char* objectID() const
{
***************
*** 53,55 ****
--- 71,211 ----
#pragma pack()
+ /*
+ This class is used to assign 8-bit keys to all
+ classes that should be serialized by the binary
+ serialization system.
+ */
+ class cBinaryTypemap {
+ protected:
+ typedef QMap<unsigned char, QCString> Container;
+ typedef Container::iterator Iterator;
+
+ /*
+ The map storing the 8-bit to string mapping.
+ */
+ Container typemap;
+
+ public:
+ /*
+ Register a new type with this object and return
+ the 8-bit identifier assigned to this type.
+ */
+ unsigned int registerType(QCString type) {
+ // Find the largest typeid in use
+ int lastid = -1;
+ for (Iterator it = typemap.begin(); it != typemap.end(); ++it) {
+ if (it.key() > lastid) {
+ lastid = it.key();
+ }
+ }
+
+ // Increase the typeid and register the type
+ lastid += 1;
+ typemap.insert(lastid, type);
+
+ // Return the assigned type id.
+ return lastid;
+ }
+
+ /*
+ Get a type identified by its 8-bit key.
+ */
+ QString getType(unsigned char key) {
+ if (!typemap.contains(key)) {
+ return QString::null;
+ }
+
+ return typemap[key];
+ }
+
+ /*
+ Check if a given 8-bit key is known.
+ */
+ bool hasType(unsigned char key) {
+ return typemap.contains(key);
+ }
+
+ /*
+ Return the full typemap.
+ */
+ const QMap<unsigned char, QCString> &getTypemap() {
+ return typemap;
+ }
+ };
+
+ typedef SingletonHolder<cBinaryTypemap> BinaryTypemap;
+
+ /*
+ This factory creates objects from type ids used in the
+ binary and database serialization process.
+ */
+ class cPersistentFactory : public Factory<PersistentObject, QString> {
+ public:
+ /*
+ Register a SQL query to retrieve objects of a given type.
+ */
+ void registerSqlQuery( const QString& type, const QString& query ) {
+ sql_queries.insert(type, query);
+ sql_keys.push_back( type );
+ }
+
+ /*
+ Retrieve a SQL query to retrieve objects of a given type.
+ */
+ QString findSqlQuery(const QString& type) const {
+ QMap<QString, QString>::const_iterator iter = sql_queries.find( type );
+
+ if (iter == sql_queries.end())
+ return QString::null;
+ else
+ return iter.data();
+ }
+
+ /*
+ Retrieve the list of registered object types.
+ */
+ const QStringList &objectTypes() const {
+ return sql_keys;
+ }
+
+ private:
+ QMap<QString, QString> sql_queries;
+ QStringList sql_keys;
+ };
+
+ typedef SingletonHolder<cPersistentFactory> PersistentFactory;
+
+ /*
+ A static and local instance of this class allows an automatic
+ registration of a type in the factory at application startup.
+ The registration order isn't predictable though.
+ */
+ template <class C>
+ class FactoryRegistration {
+ public:
+ static PersistentObject *productCreator() {
+ return new C;
+ }
+
+ FactoryRegistration(const char *className) {
+ // Register the type for creation
+ PersistentFactory::instance()->registerType(className, productCreator);
+
+ // Build the SQL query for selecting all objects of this type
+ QStringList fields, tables, conditions;
+ C::buildSqlString(className, fields, tables, conditions);
+ QString sqlString = QString("SELECT %1 FROM %2").arg(fields.join(",")).arg(tables.join(","));
+ if (conditions.count() > 0) {
+ sqlString.append(" WHERE ");
+ sqlString.append(conditions.join(" AND "));
+ }
+
+ // Register the SQL query for this type in the factory
+ PersistentFactory::instance()->registerSqlQuery(className, sqlString);
+
+ // Register the type for the 8-bit binary mapping
+ C::setClassid(BinaryTypemap::instance()->registerType(className));
+ }
+ };
+
#endif // __PERSISTENTOBJECT_H__
Index: wolfpack.vcproj
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/wolfpack.vcproj,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** wolfpack.vcproj 9 Aug 2004 20:30:22 -0000 1.40
--- wolfpack.vcproj 15 Aug 2004 02:17:39 -0000 1.41
***************
*** 86,90 ****
OptimizeForProcessor="0"
OptimizeForWindowsApplication="TRUE"
! AdditionalIncludeDirectories="sqlite;"D:\coding\STLport-5.0-0125\stlport";D:\coding\msvcrt\include;qt;C:\MySQL\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;QT_THREAD_SUPPORT;QT_LITE_COMPONENT;QT_DLL;QT_NO_STL;QT_NO_COMPRESS;CRASHHANDLER;MYSQL_DRIVER"
StringPooling="TRUE"
--- 86,90 ----
OptimizeForProcessor="0"
OptimizeForWindowsApplication="TRUE"
! AdditionalIncludeDirectories="sqlite;qt;C:\MySQL\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;QT_THREAD_SUPPORT;QT_LITE_COMPONENT;QT_DLL;QT_NO_STL;QT_NO_COMPRESS;CRASHHANDLER;MYSQL_DRIVER"
StringPooling="TRUE"
***************
*** 165,169 ****
OptimizeForProcessor="0"
OptimizeForWindowsApplication="TRUE"
! AdditionalIncludeDirectories="sqlite;"D:\coding\STLport-5.0-0125\stlport";D:\coding\msvcrt\include;qt;C:\MySQL\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;QT_THREAD_SUPPORT;QT_LITE_COMPONENT;QT_DLL;QT_NO_STL;QT_NO_COMPRESS;CRASHHANDLER;MYSQL_DRIVER"
StringPooling="TRUE"
--- 165,169 ----
OptimizeForProcessor="0"
OptimizeForWindowsApplication="TRUE"
! AdditionalIncludeDirectories="sqlite;STLPort\stlport;msvcrt\include;qt;C:\MySQL\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;QT_THREAD_SUPPORT;QT_LITE_COMPONENT;QT_DLL;QT_NO_STL;QT_NO_COMPRESS;CRASHHANDLER;MYSQL_DRIVER"
StringPooling="TRUE"
***************
*** 190,194 ****
LinkIncremental="1"
SuppressStartupBanner="TRUE"
! AdditionalLibraryDirectories="D:\coding\msvcrt\lib;C:\MySQL\lib\opt"
IgnoreAllDefaultLibraries="TRUE"
GenerateDebugInformation="TRUE"
--- 190,194 ----
LinkIncremental="1"
SuppressStartupBanner="TRUE"
! AdditionalLibraryDirectories="msvcrt\lib;C:\MySQL\lib\opt"
IgnoreAllDefaultLibraries="TRUE"
GenerateDebugInformation="TRUE"
***************
*** 274,283 ****
</File>
<File
- RelativePath=".\serverconfig.cpp">
- </File>
- <File
- RelativePath=".\serverconfig.h">
- </File>
- <File
RelativePath=".\win\config_win.cpp">
</File>
--- 274,277 ----
***************
*** 487,490 ****
--- 481,490 ----
</File>
<File
+ RelativePath=".\serverconfig.cpp">
+ </File>
+ <File
+ RelativePath=".\serverconfig.h">
+ </File>
+ <File
RelativePath=".\singleton.h">
</File>
Index: basechar.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basechar.cpp,v
retrieving revision 1.129
retrieving revision 1.130
diff -C2 -d -r1.129 -r1.130
*** basechar.cpp 13 Aug 2004 08:55:24 -0000 1.129
--- basechar.cpp 15 Aug 2004 02:17:38 -0000 1.130
***************
*** 134,140 ****
}
! void cBaseChar::buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions )
{
! cUObject::buildSqlString( fields, tables, conditions );
fields.push_back( "characters.name,characters.title,characters.creationdate" );
fields.push_back( "characters.body,characters.orgbody,characters.skin" );
--- 134,140 ----
}
! void cBaseChar::buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions )
{
! cUObject::buildSqlString( objectid, fields, tables, conditions );
fields.push_back( "characters.name,characters.title,characters.creationdate" );
fields.push_back( "characters.body,characters.orgbody,characters.skin" );
Index: guilds.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/guilds.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** guilds.cpp 10 Aug 2004 03:15:57 -0000 1.18
--- guilds.cpp 15 Aug 2004 02:17:39 -0000 1.19
***************
*** 33,36 ****
--- 33,38 ----
#include "items.h"
+ unsigned char cGuild::classid;
+
cGuilds::~cGuilds()
{
***************
*** 59,68 ****
{
// Clear the tables first: guilds are not saved incremental.
! PersistentBroker::instance()->executeQuery( "DELETE FROM guilds;" );
! PersistentBroker::instance()->executeQuery( "DELETE FROM guilds_members;" );
! PersistentBroker::instance()->executeQuery( "DELETE FROM guilds_canidates;" );
! for ( iterator it = begin(); it != end(); ++it )
! {
it.data()->save();
}
--- 61,69 ----
{
// Clear the tables first: guilds are not saved incremental.
! PersistentBroker::instance()->executeQuery( "DELETE FROM guilds;" );
! PersistentBroker::instance()->executeQuery( "DELETE FROM guilds_members;" );
! PersistentBroker::instance()->executeQuery( "DELETE FROM guilds_canidates;" );
! for (iterator it = begin(); it != end(); ++it) {
it.data()->save();
}
***************
*** 78,82 ****
cGuild* guild = new cGuild( false );
guild->load( result );
- registerGuild( guild );
}
--- 79,82 ----
***************
*** 138,141 ****
--- 138,143 ----
leader_ = 0;
}
+
+ Guilds::instance()->registerGuild(this);
}
***************
*** 887,888 ****
--- 889,916 ----
return ( PyObject * ) returnVal;
}
+
+ void cGuild::registerInFactory() {
+ classid = BinaryTypemap::instance()->registerType("cGuild");
+ }
+
+ void cGuild::load( cBufferedReader& reader ) {
+ }
+
+ void cGuild::save( cBufferedWriter& reader ) {
+ }
+
+ void cGuild::load( cBufferedReader& reader, unsigned int version ) {
+ }
+
+ void cGuild::save( cBufferedWriter& reader, unsigned int version ) {
+ }
+
+ void cGuild::postload( unsigned int version ) {
+ }
+
+ void cGuild::buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions ) {
+ fields.append("serial,name,abbreviation,charta,website,alignment,leader,founded,guildstone");
+ tables.append("guilds");
+ }
+
+ static FactoryRegistration< cGuild > registration("cGuild");
Index: npc.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/npc.h,v
retrieving revision 1.55
retrieving revision 1.56
diff -C2 -d -r1.55 -r1.56
*** npc.h 13 Aug 2004 08:55:25 -0000 1.55
--- npc.h 15 Aug 2004 02:17:39 -0000 1.56
***************
*** 87,91 ****
// implementation of interfaces
- static void registerInFactory();
void load( char**, UINT16& );
void save();
--- 87,90 ----
***************
*** 197,200 ****
--- 196,203 ----
const char* className() const;
+ static void setClassid(unsigned char id) {
+ cNPC::classid = id;
+ }
+
unsigned char getClassid()
{
***************
*** 202,205 ****
--- 205,210 ----
}
+ static void buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions );
+
private:
bool changed_;
***************
*** 208,212 ****
protected:
// interface implementation
- static void buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions );
virtual void processNode( const cElement* Tag );
--- 213,216 ----
Index: player.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/player.cpp,v
retrieving revision 1.118
retrieving revision 1.119
diff -C2 -d -r1.118 -r1.119
*** player.cpp 12 Aug 2004 03:02:50 -0000 1.118
--- player.cpp 15 Aug 2004 02:17:39 -0000 1.119
***************
*** 85,107 ****
}
! static cUObject* productCreator()
! {
! return new cPlayer;
! }
!
! void cPlayer::registerInFactory()
! {
! QStringList fields, tables, conditions;
! buildSqlString( fields, tables, conditions ); // Build our SQL string
! QString sqlString = QString( "SELECT %1 FROM uobjectmap,%2 WHERE uobjectmap.type = 'cPlayer' AND %3" ).arg( fields.join( "," ) ).arg( tables.join( "," ) ).arg( conditions.join( " AND " ) );
! UObjectFactory::instance()->registerType( "cPlayer", productCreator );
! classid = UObjectFactory::instance()->registerSqlQuery( "cPlayer", sqlString );
! }
unsigned char cPlayer::classid;
! void cPlayer::buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions )
{
! cBaseChar::buildSqlString( fields, tables, conditions );
fields.push_back( "players.account,players.additionalflags,players.visualrange" );
fields.push_back( "players.profile,players.fixedlight" );
--- 85,95 ----
}
! static FactoryRegistration<cPlayer> registration("cPlayer");
unsigned char cPlayer::classid;
! void cPlayer::buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions )
{
! cBaseChar::buildSqlString( objectid, fields, tables, conditions );
fields.push_back( "players.account,players.additionalflags,players.visualrange" );
fields.push_back( "players.profile,players.fixedlight" );
Index: guilds.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/guilds.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** guilds.h 10 Aug 2004 03:15:57 -0000 1.8
--- guilds.h 15 Aug 2004 02:17:39 -0000 1.9
***************
*** 40,44 ****
\brief This class represents a guild and all associated information.
*/
! class cGuild : public cPythonScriptable
{
public:
--- 40,44 ----
\brief This class represents a guild and all associated information.
*/
! class cGuild : public cPythonScriptable, public PersistentObject
{
public:
***************
*** 130,134 ****
--- 130,150 ----
QPtrList<cPlayer> canidates_;
QMap<P_PLAYER, MemberInfo*> memberinfo_;
+
+ static unsigned char classid;
public:
+ static void registerInFactory();
+
+ static void setClassid(unsigned char id) {
+ cGuild::classid = id;
+ }
+
+ unsigned char getClassid() const {
+ return cGuild::classid;
+ }
+
+ const char* objectID() const {
+ return "cGuild";
+ }
+
/*!
\brief Creates a new guild.
***************
*** 155,158 ****
--- 171,179 ----
void load( const cDBResult& result );
+ /*
+ Build a sql string for loading all objects of this type from the database.
+ */
+ static void buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions );
+
/*!
\returns The guildstone for this guild. May be NULL.
***************
*** 355,358 ****
--- 376,386 ----
}
+ // Wrappers
+ void load( cBufferedReader& reader );
+ void save( cBufferedWriter& reader );
+ void load( cBufferedReader& reader, unsigned int version );
+ void save( cBufferedWriter& reader, unsigned int version );
+ void postload( unsigned int version );
+
// Methods inherited from cPythonScriptable
const char* className() const;
Index: world.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/world.cpp,v
retrieving revision 1.110
retrieving revision 1.111
diff -C2 -d -r1.110 -r1.111
*** world.cpp 14 Aug 2004 03:40:36 -0000 1.110
--- world.cpp 15 Aug 2004 02:17:39 -0000 1.111
***************
*** 427,431 ****
unsigned char type;
const QMap<unsigned char, QCString> &typemap = reader.typemap();
! const QMap<unsigned char, QString> &server_typemap = UObjectFactory::instance()->getTypemap();
unsigned int loaded = 0;
unsigned int count = reader.objectCount();
--- 427,431 ----
unsigned char type;
const QMap<unsigned char, QCString> &typemap = reader.typemap();
! const QMap<unsigned char, QCString> &server_typemap = BinaryTypemap::instance()->getTypemap();
unsigned int loaded = 0;
unsigned int count = reader.objectCount();
***************
*** 448,458 ****
else
{
! cUObject *object = UObjectFactory::instance()->createObject( typemap[type] );
! try
! {
! object->load( reader );
! }
! catch ( wpException e )
! {
}
}
--- 448,461 ----
else
{
! PersistentObject *object = PersistentFactory::instance()->createObject( typemap[type] );
!
! if (object) {
! try
! {
! object->load( reader );
! }
! catch ( wpException e )
! {
! }
}
}
***************
*** 523,527 ****
}
! QStringList types = UObjectFactory::instance()->objectTypes();
for ( uint j = 0; j < types.count(); ++j )
--- 526,530 ----
}
! QStringList types = PersistentFactory::instance()->objectTypes();
for ( uint j = 0; j < types.count(); ++j )
***************
*** 544,548 ****
Console::instance()->send( "\n" + tr( "Loading " ) + QString::number( count ) + tr( " objects of type " ) + type );
! res = PersistentBroker::instance()->query( UObjectFactory::instance()->findSqlQuery( type ) );
// Error Checking
--- 547,551 ----
Console::instance()->send( "\n" + tr( "Loading " ) + QString::number( count ) + tr( " objects of type " ) + type );
! res = PersistentBroker::instance()->query( PersistentFactory::instance()->findSqlQuery( type ) );
// Error Checking
***************
*** 551,555 ****
//UINT32 sTime = getNormalizedTime();
! cUObject* object;
progress_display progress( count );
--- 554,558 ----
//UINT32 sTime = getNormalizedTime();
! PersistentObject* object;
progress_display progress( count );
***************
*** 562,566 ****
// do something with data
! object = UObjectFactory::instance()->createObject( type );
object->load( row, offset );
--- 565,569 ----
// do something with data
! object = PersistentFactory::instance()->createObject( type );
object->load( row, offset );
***************
*** 796,800 ****
cBufferedWriter writer( "WOLFPACK", DATABASE_VERSION );
writer.open( "world.bin" );
! const QMap<unsigned char, QString> &typemap = UObjectFactory::instance()->getTypemap();
for ( item = itemIterator.first(); item; item = itemIterator.next() )
--- 799,803 ----
cBufferedWriter writer( "WOLFPACK", DATABASE_VERSION );
writer.open( "world.bin" );
! const QMap<unsigned char, QCString> &typemap = BinaryTypemap::instance()->getTypemap();
for ( item = itemIterator.first(); item; item = itemIterator.next() )
Index: multi.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/multi.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** multi.h 10 Aug 2004 03:15:57 -0000 1.8
--- multi.h 15 Aug 2004 02:17:39 -0000 1.9
***************
*** 46,49 ****
--- 46,53 ----
public:
+ static void setClassid(unsigned char id) {
+ cMulti::classid = id;
+ }
+
unsigned char getClassid()
{
***************
*** 59,63 ****
virtual ~cMulti();
! /*static void buildSqlString(QStringList &fields, QStringList &tables, QStringList &conditions);
void load( char **, UINT16& );
void save();
--- 63,69 ----
virtual ~cMulti();
!
! static void buildSqlString(const char *objectid, QStringList &fields, QStringList &tables, QStringList &conditions);
! /*
void load( char **, UINT16& );
void save();
***************
*** 68,74 ****
static cMulti* find( const Coord_cl& pos );
- // Register in load factory
- static void registerInFactory();
-
// Property Interface Methods
stError* setProperty( const QString& name, const cVariant& value );
--- 74,77 ----
Index: npc.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/npc.cpp,v
retrieving revision 1.105
retrieving revision 1.106
diff -C2 -d -r1.105 -r1.106
*** npc.cpp 13 Aug 2004 08:55:25 -0000 1.105
--- npc.cpp 15 Aug 2004 02:17:39 -0000 1.106
***************
*** 85,107 ****
}
! static cUObject* productCreator()
! {
! return new cNPC;
! }
!
! void cNPC::registerInFactory()
! {
! QStringList fields, tables, conditions;
! buildSqlString( fields, tables, conditions ); // Build our SQL string
! QString sqlString = QString( "SELECT %1 FROM uobjectmap,%2 WHERE uobjectmap.type = 'cNPC' AND %3" ).arg( fields.join( "," ) ).arg( tables.join( "," ) ).arg( conditions.join( " AND " ) );
! UObjectFactory::instance()->registerType( "cNPC", productCreator );
! classid = UObjectFactory::instance()->registerSqlQuery( "cNPC", sqlString );
! }
unsigned char cNPC::classid;
! void cNPC::buildSqlString( QStringList& fields, QStringList& tables, QStringList& conditions )
{
! cBaseChar::buildSqlString( fields, tables, conditions );
fields.push_back( "npcs.summontime,npcs.additionalflags,npcs.owner" );
fields.push_back( "npcs.stablemaster" );
--- 85,95 ----
}
! static FactoryRegistration<cNPC> registration("cNPC");
unsigned char cNPC::classid;
! void cNPC::buildSqlString( const char *objectid, QStringList& fields, QStringList& tables, QStringList& conditions )
{
! cBaseChar::buildSqlString( objectid, fields, tables, conditions );
fields.push_back( "npcs.summontime,npcs.additionalflags,npcs.owner" );
fields.push_back( "npcs.stablemaster" );
|