Skip to content

Commit

Permalink
proper initialisation for gcc 3.4.2, compiles now
Browse files Browse the repository at this point in the history
proper mutex opening/closing during player xml loading
some minor debug description changes


git-svn-id: https://opentibia.svn.sourceforge.net/svnroot/opentibia/otserv/trunk@462 c77455bc-2124-0410-8220-ac9e7aafbb94
  • Loading branch information
snack committed May 10, 2005
1 parent 0197427 commit 5fa9ab2
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 40 deletions.
34 changes: 34 additions & 0 deletions game.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,38 @@ class Game {
friend class SpawnManager;
};

// from scheduler.h
// needed here for proper initialisation order forced by gcc 3.4.2+
template<class Functor, class Functor2, class Arg>
class TCallList : public SchedulerTask {
public:
TCallList(Functor f, Functor2 f2, std::list<Arg>& call_list, __int64 interval) : _f(f), _f2(f2), _list(call_list), _interval(interval) {
}

result_type operator()(const argument_type& arg) {
if(!_f2(arg)){
result_type ret = _f(arg, _list.front());
_list.pop_front();
if (!_list.empty()) {
SchedulerTask* newtask = new TCallList<Functor, Functor2, Arg>(_f, _f2, _list, _interval);
newtask->setTicks(_interval);
arg->addEvent(newtask);
}
return ret;
}
return result_type();
}
protected:
Functor _f;
Functor2 _f2;
std::list<Arg> _list;
__int64 _interval;
};

template<class Functor, class Functor2, class Arg>
SchedulerTask* makeTask(__int64 ticks, Functor f, std::list<Arg>& call_list, __int64 interval, Functor2 f2) {
TCallList<Functor, Functor2, Arg> *t = new TCallList<Functor, Functor2, Arg>(f, f2, call_list, interval);
t->setTicks(ticks);
return t;
}
#endif
2 changes: 1 addition & 1 deletion ioaccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class IOAccount {
static IOAccount* instance();
/** Get a textual description of what source is used
* \returns Name of the source*/
virtual char* getSourceDescription(){return "NULL";};
virtual char* getSourceDescription(){return "Account source: NULL";};
virtual Account loadAccount(unsigned long accno);

protected:
Expand Down
2 changes: 1 addition & 1 deletion ioaccountsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class IOAccountSQL : protected IOAccount {
public:
/** Get a textual description of what source is used
* \returns Name of the source*/
virtual char* getSourceDescription(){return "SQL";};
virtual char* getSourceDescription(){return "Account source: SQL";};
virtual Account loadAccount(unsigned long accno);
IOAccountSQL(){};
virtual ~IOAccountSQL(){};
Expand Down
1 change: 0 additions & 1 deletion ioaccountxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Account IOAccountXML::loadAccount(unsigned long accno){
std::transform(filename.begin(), filename.end(), filename.begin(), tolower);
xmlMutexLock(xmlmutex);
xmlDocPtr doc = xmlParseFile(filename.c_str());

if (doc)
{
xmlNodePtr root, p, tmp;
Expand Down
4 changes: 3 additions & 1 deletion ioplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ IOPlayer* IOPlayer::instance(){
_instance = (IOPlayer*)new IOPlayerXML;
#endif
}

#ifdef __DEBUG__
printf("%s \n", _instance->getSourceDescription());
#endif
return _instance;
}

Expand Down
2 changes: 1 addition & 1 deletion ioplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class IOPlayer {
static IOPlayer* instance();
/** Get a textual description of what source is used
* \returns Name of the source*/
virtual char* getSourceDescription(){return "NULL";};
virtual char* getSourceDescription(){return "Player source: NULL";};
/** Load a player
* \returns Wheter the player was successfully loaded
* \param player Player structure to load to
Expand Down
2 changes: 1 addition & 1 deletion ioplayersql.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class IOPlayerSQL : protected IOPlayer{
public:
/** Get a textual description of what source is used
* \returns Name of the source*/
char* getSourceDescription(){return "SQL";};
char* getSourceDescription(){return "Player source: SQL";};
bool loadPlayer(Player* player, std::string name);
/** Save a player
* \returns Wheter the player was successfully saved
Expand Down
4 changes: 4 additions & 0 deletions ioplayerxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ bool IOPlayerXML::loadPlayer(Player* player, std::string name){
p = root->children;

const char *account = (const char*)xmlGetProp(root, (const xmlChar *) "account");

//need to unlock and relock in order to load xml account
xmlMutexUnlock(xmlmutex);
Account a = IOAccount::instance()->loadAccount(atoi(account));
xmlMutexLock(xmlmutex);

player->password = a.password;
if (a.accnumber == 0 || a.accnumber != (unsigned long)atoi(account)) {
Expand Down
2 changes: 1 addition & 1 deletion ioplayerxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IOPlayerXML : protected IOPlayer{
public:
/** Get a textual description of what source is used
* \returns Name of the source*/
virtual char* getSourceDescription(){return "XML Player";};
virtual char* getSourceDescription(){return "Player source: XML";};
virtual bool loadPlayer(Player* player, std::string name);
/** Save a player
* \returns Wheter the player was successfully saved
Expand Down
33 changes: 0 additions & 33 deletions scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,37 +83,4 @@ class lessSchedTask : public std::binary_function<SchedulerTask*, SchedulerTask*
}
};

template<class Functor, class Functor2, class Arg>
class TCallList : public SchedulerTask {
public:
TCallList(Functor f, Functor2 f2, std::list<Arg>& call_list, __int64 interval) : _f(f), _f2(f2), _list(call_list), _interval(interval) {
}

result_type operator()(const argument_type& arg) {
if(!_f2(arg)){
result_type ret = _f(arg, _list.front());
_list.pop_front();
if (!_list.empty()) {
SchedulerTask* newtask = new TCallList<Functor, Functor2, Arg>(_f, _f2, _list, _interval);
newtask->setTicks(_interval);
arg->addEvent(newtask);
}
return ret;
}
return result_type();
}
protected:
Functor _f;
Functor2 _f2;
std::list<Arg> _list;
__int64 _interval;
};

template<class Functor, class Functor2, class Arg>
SchedulerTask* makeTask(__int64 ticks, Functor f, std::list<Arg>& call_list, __int64 interval, Functor2 f2) {
TCallList<Functor, Functor2, Arg> *t = new TCallList<Functor, Functor2, Arg>(f, f2, call_list, interval);
t->setTicks(ticks);
return t;
}

#endif

0 comments on commit 5fa9ab2

Please sign in to comment.