From: <jo...@us...> - 2013-10-11 20:07:07
|
Revision: 8861 http://sourceforge.net/p/planeshift/code/8861 Author: joelyon Date: 2013-10-11 20:07:05 +0000 (Fri, 11 Oct 2013) Log Message: ----------- Revised Active Magic message handling to send a complete list of all active spells with each update. This should improve the reliability of the active magic bar. (before it accumulated items due to lost packets) Modified Paths: -------------- trunk/src/client/gui/pawsactivemagicwindow.cpp trunk/src/client/gui/pawsscrollmenu.cpp trunk/src/client/gui/pawsscrollmenu.h trunk/src/common/net/messages.cpp trunk/src/common/net/messages.h trunk/src/server/bulkobjects/activespell.cpp trunk/src/server/bulkobjects/activespell.h trunk/src/server/gem.cpp Modified: trunk/src/client/gui/pawsactivemagicwindow.cpp =================================================================== --- trunk/src/client/gui/pawsactivemagicwindow.cpp 2013-10-11 02:36:17 UTC (rev 8860) +++ trunk/src/client/gui/pawsactivemagicwindow.cpp 2013-10-11 20:07:05 UTC (rev 8861) @@ -167,112 +167,64 @@ if(!IsVisible() && psengine->loadstate == psEngine::LS_DONE && show) ShowBehind(); - if(incoming.duration==0 && showEffects==false) + size_t numSpells=incoming.name.GetSize(); + + buffList->Clear(); + + if( numSpells==0 ) { - return; + Hide(); } - - switch(incoming.command) + else { - case psGUIActiveMagicMessage::Add: + for( int i=0; i<numSpells; i++ ) { - rowEntry.PushBack(incoming.name); - - if(incoming.type == BUFF) + if(incoming.duration[i]==0 && showEffects==false) { - if(useImages) + continue; + } + rowEntry.PushBack(incoming.name[i]); + + if(useImages) + { + csRef<iPawsImage> image; + if(incoming.image[i].Length() >0) { - csRef<iPawsImage> image; - - if(incoming.image.Length() >0) - { - image = PawsManager::GetSingleton().GetTextureManager()->GetPawsImage(incoming.image); - } - else - { - image = NULL; - } - if(image) - { - buffList->LoadSingle(incoming.name, incoming.image, incoming.name, csString(""), 0, this, false); - } - else - { - buffList->LoadSingle(incoming.name, csString("/planeshift/materials/crystal_ball_icon.dds"), incoming.name, csString(""), 0, this, false); - } + image = PawsManager::GetSingleton().GetTextureManager()->GetPawsImage(incoming.image[i]); } else { - buffList->LoadSingle(incoming.name, csString(""), incoming.name, csString(""), 0, this, false); + image = NULL; } - buffList->SetEditLock(ScrollMenuOptionDISABLED); - if(autoResize) + if(image) { - AutoResize(); + buffList->LoadSingle(incoming.name[i], incoming.image[i], incoming.name[i], csString(""), 0, this, false); } else { - buffList->Resize(); - } - } - else // incoming.type == DEBUFF - { - if(useImages) - { - csRef<iPawsImage> image; - - if(incoming.image.Length() >0) + if( incoming.type[i]==BUFF ) { - image = PawsManager::GetSingleton().GetTextureManager()->GetPawsImage(incoming.image); + buffList->LoadSingle(incoming.name[i], csString("/planeshift/materials/crystal_ball_icon.dds"), incoming.name[i], csString(""), 0, this, false); } else { - image = NULL; + buffList->LoadSingle(incoming.name[i], csString("danger_01"), incoming.name[i], csString(""), -1, this, false); } - if(image) - { - buffList->LoadSingle(incoming.name, incoming.image, incoming.name, csString(""), -1, this, false); - } - else - { - buffList->LoadSingle(incoming.name, csString("danger_01"), incoming.name, csString(""), -1, this, false); - } } - else - { - buffList->LoadSingle(incoming.name, csString(""), incoming.name, csString(""), -1, this, false); - } - //buffList->SetEditLock( ScrollMenuOptionDISABLED ); - if(autoResize) - { - AutoResize(); - } - else - { - buffList->Resize(); - } } - - break; - } - case psGUIActiveMagicMessage::Remove: - { - buffList->RemoveByName(incoming.name); - if(autoResize) - { - AutoResize(); - } else { - buffList->Resize(); + buffList->LoadSingle(incoming.name[i], csString(""), incoming.name[i], csString(""), 0, this, false); } - - // If no active magic, hide the window. - if(buffList->GetSize() < 1) - Hide(); - - break; } + if(autoResize) + { + AutoResize(); + } + else + { + buffList->Resize(); + } } } Modified: trunk/src/client/gui/pawsscrollmenu.cpp =================================================================== --- trunk/src/client/gui/pawsscrollmenu.cpp 2013-10-11 02:36:17 UTC (rev 8860) +++ trunk/src/client/gui/pawsscrollmenu.cpp 2013-10-11 20:07:05 UTC (rev 8861) @@ -644,6 +644,19 @@ return true; } +bool pawsScrollMenu::Clear() +{ + for(size_t i=0; i<Buttons.GetSize(); i++) + { + pawsWidget* match = NULL; + + match=ButtonHolder->GetChild(i); + ButtonHolder->RemoveChild(match); + Buttons.DeleteIndex(i); + } + return true; +} + int pawsScrollMenu::GetSize() { return ButtonHolder->GetChildrenCount(); @@ -742,8 +755,7 @@ ScrollDown(); return true; } - parent->OnMouseDown(button, modifiers, GetScreenFrame().xmin + x, GetScreenFrame().ymin + y); - return true; + return parent->OnMouseDown(button, modifiers, GetScreenFrame().xmin + x, GetScreenFrame().ymin + y); } bool pawsScrollMenu::OnKeyDown(utf32_char keyCode, utf32_char key, int modifiers) Modified: trunk/src/client/gui/pawsscrollmenu.h =================================================================== --- trunk/src/client/gui/pawsscrollmenu.h 2013-10-11 02:36:17 UTC (rev 8860) +++ trunk/src/client/gui/pawsscrollmenu.h 2013-10-11 20:07:05 UTC (rev 8861) @@ -77,6 +77,7 @@ bool LoadSingle(csString name, csString icon, csString toolTip, csString action, int Index, pawsWidget* widget, bool IsEnabled); bool RemoveByName(csString name); + bool Clear(); int GetSize(); int GetButtonWidth(); int GetButtonHeight(); Modified: trunk/src/common/net/messages.cpp =================================================================== --- trunk/src/common/net/messages.cpp 2013-10-11 02:36:17 UTC (rev 8860) +++ trunk/src/common/net/messages.cpp 2013-10-11 20:07:05 UTC (rev 8861) @@ -5615,7 +5615,7 @@ else if(type == DEBUFF) msgtext.Append("debuff "); - msgtext.Append(name); + msgtext.Append(name[0]); return msgtext; } Modified: trunk/src/common/net/messages.h =================================================================== --- trunk/src/common/net/messages.h 2013-10-11 02:36:17 UTC (rev 8860) +++ trunk/src/common/net/messages.h 2013-10-11 20:07:05 UTC (rev 8861) @@ -34,6 +34,8 @@ #include "util/skillcache.h" #include <ivideo/graph3d.h> +#include "bulkobjects/activespell.h" + /** * \addtogroup messages * @{ */ @@ -3695,63 +3697,78 @@ class psGUIActiveMagicMessage : public psMessageCracker { public: - enum commandType { Add, Remove }; + long int msgIndex; //message number, used to ensure messages are processed in the correct order. increases by one for each message. + + enum commandType { Add, Remove, List }; - psGUIActiveMagicMessage(uint32_t clientNum, - commandType cmd, - SPELL_TYPE type, - csTicks duration, - const csString &name, - const csString &image) + psGUIActiveMagicMessage(uint32_t clientNum, csArray<ActiveSpell*> spells, uint32_t index ) { - // + duration + - size_t msgSize = sizeof(bool) + sizeof(uint8_t) + sizeof(uint32_t) + sizeof(int32_t); + // MSGTYPE_ACTIVEMAGIC + clientNum + valid + index + spellCount; + size_t msgSize = sizeof(uint8_t) + sizeof(uint32_t) + sizeof(bool) + sizeof(uint32_t) + sizeof(uint32_t); - if(name && name.Length()>0) - msgSize += name.Length() +1; - else - msgSize += sizeof(uint8_t); + size_t numSpells = spells.GetSize(); - if(image) + for( size_t i=0; i<numSpells; i++ ) { - if(image.Length()>0) + msgSize += sizeof(uint8_t); //SPELL_TYPE + msgSize += sizeof(uint32_t); //duration + msgSize += sizeof(uint32_t); //registrationTime + if(spells[i]->Name() && spells[i]->Name().Length()>0) + msgSize += (spells[i]->Name().Length()+1); + else + msgSize += sizeof(uint8_t); + + if(spells[i]->Image() && spells[i]->Image().Length()>0) { - msgSize += image.Length() +1; + msgSize += (spells[i]->Image().Length()+1); } + else + { + msgSize += sizeof(uint8_t); + } } - else - { - msgSize += sizeof(uint8_t); - } msg.AttachNew(new MsgEntry(msgSize)); msg->SetType(MSGTYPE_ACTIVEMAGIC); msg->clientnum = clientNum; - msg->Add((uint8_t)cmd); - msg->Add((uint8_t)type); - if(name && name.Length()>0) - msg->Add(name); - else - msg->Add((uint8_t)0); - - if(image && image.Length()>0) - msg->Add(image); - else - msg->Add((uint8_t)0); - - msg->Add((uint32_t)duration); - + msg->Add((uint32_t)index); + msg->Add((uint32_t)numSpells); + for( size_t i=0; i<numSpells; i++ ) + { + msg->Add((uint8_t)spells[i]->Type()); + msg->Add((uint32_t)spells[i]->Duration()); + msg->Add((uint32_t)spells[i]->RegistrationTime()); + if(spells[i]->Name() && spells[i]->Name().Length()>0) + msg->Add(spells[i]->Name().GetData()); + else + msg->Add((uint8_t)0); + + if(spells[i]->Image() && spells[i]->Image().Length()>0) + msg->Add(spells[i]->Image().GetData()); + else + msg->Add((uint8_t)0); + } valid = !(msg->overrun); } /// Crack this message off the network. psGUIActiveMagicMessage(MsgEntry* message) { - command = (commandType) message->GetUInt8(); - type = (SPELL_TYPE) message->GetUInt8(); - name = message->GetStr(); //if there was no name when the message was sent, this should read a null string - image = message->GetStr(); //if there was no name when the message was sent, this should read a null string - duration = message->GetUInt32(); + //what is the index number of this message? + long index = message->GetUInt32(); + + //how many spells are in the message? + size_t totalSpells = message->GetUInt32(); + + //read the spells + for( size_t i; i<totalSpells; i++ ) + { + type.Push( (SPELL_TYPE) message->GetUInt8() ); + duration.Push( message->GetUInt32()); + registrationTime.Push( message->GetUInt32()); + name.Push( message->GetStr()); //if there was no name when the message was sent, this should read a null string + image.Push( message->GetStr()); //if there was no name when the message was sent, this should read a null string + } valid = true; } @@ -3764,11 +3781,12 @@ */ virtual csString ToString(NetBase::AccessPointers* accessPointers); - commandType command; - SPELL_TYPE type; - uint32 duration; - csString name; - csString image; + csArray<commandType> command; + csArray<SPELL_TYPE> type; + csArray<uint32> duration; + csArray<uint32> registrationTime; + csArray<csString> name; + csArray<csString> image; }; //----------------------------------------------------------------------------- Modified: trunk/src/server/bulkobjects/activespell.cpp =================================================================== --- trunk/src/server/bulkobjects/activespell.cpp 2013-10-11 02:36:17 UTC (rev 8860) +++ trunk/src/server/bulkobjects/activespell.cpp 2013-10-11 20:07:05 UTC (rev 8861) @@ -53,6 +53,9 @@ //---------------------------------------------------------------------------- +ActiveSpell::ActiveSpell(const csString& name, SPELL_TYPE type, csTicks duration) : name(name), type(type), duration(duration), cancelOnDeath(true), damagesHP(false), target(NULL), registrationTime(0) +{ } + void ActiveSpell::Add(iSpellModifier& mod, const char* fmt, ...) { CS_ASSERT(registrationTime == 0); @@ -139,4 +142,7 @@ script.GetData()); return apply; } - +void ActiveSpell::SetImage( csString imageName ) +{ + image = imageName; +} Modified: trunk/src/server/bulkobjects/activespell.h =================================================================== --- trunk/src/server/bulkobjects/activespell.h 2013-10-11 02:36:17 UTC (rev 8860) +++ trunk/src/server/bulkobjects/activespell.h 2013-10-11 20:07:05 UTC (rev 8861) @@ -33,6 +33,7 @@ //============================================================================= #include "buffable.h" + struct iDocumentNode; class gemActor; @@ -67,7 +68,7 @@ class ActiveSpell : public CS::Utility::WeakReferenced { public: - ActiveSpell(const csString& name, SPELL_TYPE type, csTicks duration) : name(name), type(type), duration(duration), cancelOnDeath(true), damagesHP(false), target(NULL), registrationTime(0) { } + ActiveSpell(const csString& name, SPELL_TYPE type, csTicks duration); ~ActiveSpell() { } // These are only used by progression scripts, for loading/initializing it. @@ -84,8 +85,11 @@ bool DamagesHP() { return damagesHP; } const csString& Name() const { return name; } + const csString& Image() const { return image; } SPELL_TYPE Type() const { return type; } csTicks Duration() const { return duration; } + csTicks RegistrationTime() const { return registrationTime; } + void SetImage( csString imageName ); /** * If Cancel() returns true, you're responsible for freeing the ActiveSpell's memory. @@ -103,6 +107,7 @@ protected: csString name; ///< The name of the spell + csString image; ///< The icon representing the spell SPELL_TYPE type; ///< Spell type - buff, debuff, etc. csString script; ///< the contents of an \<apply\> node which recreates this effect csTicks duration; ///< How long this spell lasts Modified: trunk/src/server/gem.cpp =================================================================== --- trunk/src/server/gem.cpp 2013-10-11 02:36:17 UTC (rev 8860) +++ trunk/src/server/gem.cpp 2013-10-11 20:07:05 UTC (rev 8861) @@ -4410,29 +4410,24 @@ } activeSpells.Push(asp); - csString lname = asp->Name(); - csString imageName; - if(!lname) + psSpell* lspell = psserver->GetCacheManager()->GetSpellByName(asp->Name()); + csString image; + + if(!lspell) { + image = csString(); } - else if(lname) + else { - psSpell* lspell = psserver->GetCacheManager()->GetSpellByName(lname); - if(!lspell) + image = lspell->GetImage(); + if(!image) { - imageName = csString(); + image = csString(); } - else - { - imageName = lspell->GetImage(); - if(!imageName) - { - imageName = csString(); - } - } } + asp->SetImage( image ); - psGUIActiveMagicMessage outgoing(GetClientID(), psGUIActiveMagicMessage::Add, asp->Type(), asp->Duration(), lname, imageName); + psGUIActiveMagicMessage outgoing(GetClientID(), activeSpells, 0 ); // <---add message index tracking! outgoing.SendMessage(); } @@ -4440,7 +4435,7 @@ { if(activeSpells.Delete(asp)) { - psGUIActiveMagicMessage outgoing(GetClientID(), psGUIActiveMagicMessage::Remove, asp->Type(), asp->Duration(), asp->Name(), csString()); + psGUIActiveMagicMessage outgoing(GetClientID(), activeSpells, 0 ); // <---add message index tracking! outgoing.SendMessage(); return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |