24 #include "kgamepropertyhandler.h"
25 #include "kgameproperty.h"
26 #include "kgamemessage.h"
29 #include <tqptrqueue.h>
31 #include <tdelocale.h>
34 #define KPLAYERHANDLER_LOAD_COOKIE 6239
37 class KGamePropertyHandlerPrivate
40 KGamePropertyHandlerPrivate()
44 TQMap<int, TQString> mNameMap;
45 TQIntDict<KGamePropertyBase> mIdDict;
49 bool mDefaultUserspace;
51 TQPtrQueue<KGamePropertyBase> mSignalQueue;
65 KGamePropertyHandler::~KGamePropertyHandler()
71 void KGamePropertyHandler::init()
73 kdDebug(11001) << k_funcinfo <<
": this=" <<
this << endl;
74 d =
new KGamePropertyHandlerPrivate;
76 d->mUniqueId=KGamePropertyBase::IdAutomatic;
77 d->mDefaultPolicy=KGamePropertyBase::PolicyLocal;
78 d->mDefaultUserspace=
true;
96 if (receiver && sendf) {
97 kdDebug(11001) <<
"Connecting TQT_SLOT " << sendf << endl;
98 connect(
this, TQT_SIGNAL(
signalSendMessage(
int, TQDataStream &,
bool*)), receiver, sendf);
100 if (receiver && emitf) {
101 kdDebug(11001) <<
"Connecting TQT_SLOT " << emitf << endl;
114 KGameMessage::extractPropertyHeader(stream, propertyId);
116 if (propertyId==KGamePropertyBase::IdCommand) {
118 KGameMessage::extractPropertyCommand(stream, propertyId, cmd);
120 p = d->mIdDict.find(propertyId);
122 if (!isSender || p->
policy()==KGamePropertyBase::PolicyClean) {
123 p->
command(stream, cmd, isSender);
126 kdError(11001) << k_funcinfo <<
": (cmd): property " << propertyId <<
" not found" << endl;
130 p = d->mIdDict.find(propertyId);
133 if (!isSender || p->
policy()==KGamePropertyBase::PolicyClean) {
137 kdError(11001) << k_funcinfo <<
": property " << propertyId <<
" not found" << endl;
147 d->mNameMap.erase(data->
id());
148 return d->mIdDict.remove(data->
id());
154 if (d->mIdDict.find(data->
id())) {
156 kdError(11001) <<
" -> cannot add property " << data->
id() << endl;
159 d->mIdDict.insert(data->
id(), data);
162 if (!name.isNull()) {
163 d->mNameMap[data->
id()] = name;
175 if (d->mIdDict.find(
id)) {
176 if (d->mNameMap.contains(
id)) {
177 s = i18n(
"%1 (%2)").arg(d->mNameMap[
id]).arg(
id);
179 s = i18n(
"Unnamed - ID: %1").arg(
id);
183 s = i18n(
"%1 unregistered").arg(
id);
194 kdDebug(11001) << k_funcinfo <<
": " << count <<
" KGameProperty objects " << endl;
195 for (i = 0; i < count; i++) {
200 if (cookie == KPLAYERHANDLER_LOAD_COOKIE) {
201 kdDebug(11001) <<
" KGamePropertyHandler loaded propertly"<<endl;
203 kdError(11001) <<
"KGamePropertyHandler loading error. probably format error"<<endl;
212 kdDebug(11001) << k_funcinfo <<
": " << d->mIdDict.count() <<
" KGameProperty objects " << endl;
213 stream << (uint)d->mIdDict.count();
214 TQIntDictIterator<KGamePropertyBase> it(d->mIdDict);
215 while (it.current()) {
218 KGameMessage::createPropertyHeader(stream, base->
id());
223 stream << (TQ_INT16)KPLAYERHANDLER_LOAD_COOKIE;
230 return d->mDefaultPolicy;
236 d->mDefaultUserspace=userspace;
237 TQIntDictIterator<KGamePropertyBase> it(d->mIdDict);
238 while (it.current()) {
239 if (!userspace || it.current()->id()>=KGamePropertyBase::IdUser) {
248 TQIntDictIterator<KGamePropertyBase> it(d->mIdDict);
249 while (it.current()) {
250 it.current()->unlock();
257 TQIntDictIterator<KGamePropertyBase> it(d->mIdDict);
258 while (it.current()) {
259 it.current()->lock();
266 return d->mUniqueId++;
271 TQIntDictIterator<KGamePropertyBase> it(d->mIdDict);
272 while (it.current()) {
273 if (it.current()->isDirty()) {
274 it.current()->sendProperty();
292 if (d->mIndirectEmit<=0)
295 while((prop=d->mSignalQueue.dequeue()) != 0)
310 if (d->mIndirectEmit>0)
313 d->mSignalQueue.enqueue(prop);
331 return d->mIdDict.find(
id);
336 kdDebug(11001) << k_funcinfo <<
id() << endl;
337 TQIntDictIterator<KGamePropertyBase> it(d->mIdDict);
338 while (it.toFirst()) {
341 if (d->mIdDict.find(p->
id())) {
357 return i18n(
"NULL pointer");
364 const type_info* t = prop->
typeinfo();
365 if (*t ==
typeid(
int)) {
367 }
else if (*t ==
typeid(
unsigned int)) {
369 }
else if (*t ==
typeid(
long int)) {
371 }
else if (*t ==
typeid(
unsigned long int)) {
373 }
else if (*t ==
typeid(TQString)) {
375 }
else if (*t ==
typeid(TQ_INT8)) {
381 if (value.isNull()) {
382 value = i18n(
"Unknown");
389 kdDebug(11001) <<
"-----------------------------------------------------------" << endl;
390 kdDebug(11001) <<
"KGamePropertyHandler:: Debug this=" <<
this << endl;
392 kdDebug(11001) <<
" Registered properties: (Policy,Lock,Emit,Optimized, Dirty)" << endl;
393 TQIntDictIterator<KGamePropertyBase> it(d->mIdDict);
394 while (it.current()) {
396 kdDebug(11001) <<
" "<< p->
id() <<
": p=" << p->
policy()
404 kdDebug(11001) <<
"-----------------------------------------------------------" << endl;
407 #include "kgamepropertyhandler.moc"