mirror of
https://github.com/edubart/otclient.git
synced 2025-10-16 04:24:54 +02:00
Refactor for documentation
This commit is contained in:
@@ -47,7 +47,7 @@ void exitSignalHandler(int sig)
|
||||
case SIGINT:
|
||||
if(!signaled) {
|
||||
signaled = true;
|
||||
g_eventDispatcher.addEvent(std::bind(&Application::close, &g_app));
|
||||
g_dispatcher.addEvent(std::bind(&Application::close, &g_app));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ void Application::terminate()
|
||||
g_lua.terminate();
|
||||
|
||||
// flush remaining dispatcher events
|
||||
g_eventDispatcher.flush();
|
||||
g_dispatcher.flush();
|
||||
|
||||
// terminate graphics
|
||||
m_foreground = nullptr;
|
||||
@@ -182,7 +182,7 @@ void Application::run()
|
||||
g_clock.update();
|
||||
|
||||
// show the application only after we draw some frames
|
||||
g_eventDispatcher.scheduleEvent([] { g_window.show(); }, 10);
|
||||
g_dispatcher.scheduleEvent([] { g_window.show(); }, 10);
|
||||
|
||||
|
||||
while(!m_stopping) {
|
||||
@@ -281,7 +281,7 @@ void Application::poll()
|
||||
//g_particleManager.update();
|
||||
|
||||
Connection::poll();
|
||||
g_eventDispatcher.poll();
|
||||
g_dispatcher.poll();
|
||||
}
|
||||
|
||||
void Application::close()
|
||||
|
@@ -25,7 +25,7 @@
|
||||
#include <framework/core/clock.h>
|
||||
#include "timer.h"
|
||||
|
||||
EventDispatcher g_eventDispatcher;
|
||||
EventDispatcher g_dispatcher;
|
||||
|
||||
|
||||
void EventDispatcher::flush()
|
||||
|
@@ -26,7 +26,7 @@
|
||||
#include "clock.h"
|
||||
#include "scheduledevent.h"
|
||||
|
||||
// @bindsingleton g_eventDispatcher
|
||||
// @bindsingleton g_dispatcher
|
||||
class EventDispatcher
|
||||
{
|
||||
public:
|
||||
@@ -44,6 +44,6 @@ private:
|
||||
std::priority_queue<ScheduledEventPtr, std::vector<ScheduledEventPtr>, lessScheduledEvent> m_scheduledEventList;
|
||||
};
|
||||
|
||||
extern EventDispatcher g_eventDispatcher;
|
||||
extern EventDispatcher g_dispatcher;
|
||||
|
||||
#endif
|
||||
|
@@ -54,7 +54,7 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
|
||||
|
||||
if(m_onLog) {
|
||||
// schedule log callback, because this callback can run lua code that may affect the current state
|
||||
g_eventDispatcher.addEvent([=] {
|
||||
g_dispatcher.addEvent([=] {
|
||||
if(m_onLog)
|
||||
m_onLog(level, outmsg, now);
|
||||
});
|
||||
|
@@ -42,7 +42,7 @@ AnimatedTexture::AnimatedTexture(int width, int height, int channels, int numFra
|
||||
m_framesDelay[i] = framesDelay[i];
|
||||
}
|
||||
m_currentFrame = -1;
|
||||
g_eventDispatcher.scheduleEvent(std::bind(&AnimatedTexture::processAnimation, this), 0);
|
||||
g_dispatcher.scheduleEvent(std::bind(&AnimatedTexture::processAnimation, this), 0);
|
||||
}
|
||||
|
||||
AnimatedTexture::~AnimatedTexture()
|
||||
@@ -71,6 +71,6 @@ void AnimatedTexture::processAnimation()
|
||||
|
||||
// continue to animate only if something still referencing this texture
|
||||
if(self.use_count() > 1)
|
||||
g_eventDispatcher.scheduleEvent(std::bind(&AnimatedTexture::processAnimation, self), m_framesDelay[m_currentFrame]);
|
||||
g_dispatcher.scheduleEvent(std::bind(&AnimatedTexture::processAnimation, self), m_framesDelay[m_currentFrame]);
|
||||
}
|
||||
*/
|
@@ -594,7 +594,8 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindSingletonFunction("g_ui", "getStyle", &UIManager::getStyle, &g_ui);
|
||||
g_lua.bindSingletonFunction("g_ui", "getStyleClass", &UIManager::getStyleClass, &g_ui);
|
||||
g_lua.bindSingletonFunction("g_ui", "loadUI", &UIManager::loadUI, &g_ui);
|
||||
g_lua.bindSingletonFunction("g_ui", "createWidgetFromStyle", &UIManager::createWidgetFromStyle, &g_ui);
|
||||
g_lua.bindSingletonFunction("g_ui", "displayUI", &UIManager::displayUI, &g_ui);
|
||||
g_lua.bindSingletonFunction("g_ui", "createWidget", &UIManager::createWidget, &g_ui);
|
||||
g_lua.bindSingletonFunction("g_ui", "createWidgetFromOTML", &UIManager::createWidgetFromOTML, &g_ui);
|
||||
g_lua.bindSingletonFunction("g_ui", "getRootWidget", &UIManager::getRootWidget, &g_ui);
|
||||
g_lua.bindSingletonFunction("g_ui", "getDraggingWidget", &UIManager::getDraggingWidget, &g_ui);
|
||||
@@ -634,10 +635,10 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindSingletonFunction("g_sounds", "getCurrentMusic", &SoundManager::getCurrentMusic, &g_sounds);
|
||||
|
||||
// EventDispatcher
|
||||
g_lua.registerSingletonClass("g_eventDispatcher");
|
||||
g_lua.bindSingletonFunction("g_eventDispatcher", "addEvent", &EventDispatcher::addEvent, &g_eventDispatcher);
|
||||
g_lua.bindSingletonFunction("g_eventDispatcher", "scheduleEvent", &EventDispatcher::scheduleEvent, &g_eventDispatcher);
|
||||
g_lua.bindSingletonFunction("g_eventDispatcher", "cycleEvent", &EventDispatcher::cycleEvent, &g_eventDispatcher);
|
||||
g_lua.registerSingletonClass("g_dispatcher");
|
||||
g_lua.bindSingletonFunction("g_dispatcher", "addEvent", &EventDispatcher::addEvent, &g_dispatcher);
|
||||
g_lua.bindSingletonFunction("g_dispatcher", "scheduleEvent", &EventDispatcher::scheduleEvent, &g_dispatcher);
|
||||
g_lua.bindSingletonFunction("g_dispatcher", "cycleEvent", &EventDispatcher::cycleEvent, &g_dispatcher);
|
||||
|
||||
// ResourceManager
|
||||
g_lua.registerSingletonClass("g_resources");
|
||||
|
@@ -96,8 +96,12 @@ namespace luabinder
|
||||
LuaCppFunction bind_fun_specializer(const F& f) {
|
||||
enum { N = std::tuple_size<Tuple>::value };
|
||||
return [=](LuaInterface* lua) -> int {
|
||||
if(lua->stackSize() != N)
|
||||
throw LuaBadNumberOfArgumentsException(N, lua->stackSize());
|
||||
while(lua->stackSize() != N) {
|
||||
if(lua->stackSize() < N)
|
||||
g_lua.pushNil();
|
||||
else
|
||||
g_lua.pop();
|
||||
}
|
||||
Tuple tuple;
|
||||
pack_values_into_tuple<N>::call(tuple, lua);
|
||||
return expand_fun_arguments<N,Ret>::call(tuple, f, lua);
|
||||
|
@@ -127,7 +127,7 @@ void Connection::write(uint8* buffer, uint16 size)
|
||||
auto weakSelf = ConnectionWeakPtr(shared_from_this());
|
||||
|
||||
// wait 1 ms to do the real send
|
||||
m_sendEvent = g_eventDispatcher.scheduleEvent([=] {
|
||||
m_sendEvent = g_dispatcher.scheduleEvent([=] {
|
||||
if(!weakSelf.lock())
|
||||
return;
|
||||
//m_writeTimer.cancel();
|
||||
|
@@ -119,7 +119,7 @@ bool UIGridLayout::internalUpdate()
|
||||
|
||||
if(m_fitChildren && preferredHeight != parentWidget->getHeight()) {
|
||||
// must set the preferred height later
|
||||
g_eventDispatcher.addEvent([=] {
|
||||
g_dispatcher.addEvent([=] {
|
||||
parentWidget->setHeight(preferredHeight);
|
||||
});
|
||||
}
|
||||
|
@@ -85,7 +85,7 @@ bool UIHorizontalLayout::internalUpdate()
|
||||
|
||||
if(m_fitChildren && preferredWidth != parentWidget->getWidth()) {
|
||||
// must set the preferred width later
|
||||
g_eventDispatcher.addEvent([=] {
|
||||
g_dispatcher.addEvent([=] {
|
||||
parentWidget->setWidth(preferredWidth);
|
||||
});
|
||||
}
|
||||
|
@@ -65,7 +65,7 @@ void UILayout::updateLater()
|
||||
return;
|
||||
|
||||
auto self = asUILayout();
|
||||
g_eventDispatcher.addEvent([self] {
|
||||
g_dispatcher.addEvent([self] {
|
||||
self->m_updateScheduled = false;
|
||||
self->update();
|
||||
});
|
||||
|
@@ -214,7 +214,7 @@ void UIManager::updateHoveredWidget()
|
||||
if(m_hoverUpdateScheduled)
|
||||
return;
|
||||
|
||||
g_eventDispatcher.addEvent([this] {
|
||||
g_dispatcher.addEvent([this] {
|
||||
if(!m_rootWidget)
|
||||
return;
|
||||
|
||||
@@ -278,11 +278,11 @@ void UIManager::onWidgetDestroy(const UIWidgetPtr& widget)
|
||||
if(m_checkEvent && !m_checkEvent->isExecuted())
|
||||
return;
|
||||
|
||||
m_checkEvent = g_eventDispatcher.scheduleEvent([this] {
|
||||
m_checkEvent = g_dispatcher.scheduleEvent([this] {
|
||||
g_lua.collectGarbage();
|
||||
UIWidgetList backupList = m_destroyedWidgets;
|
||||
m_destroyedWidgets.clear();
|
||||
g_eventDispatcher.scheduleEvent([backupList] {
|
||||
g_dispatcher.scheduleEvent([backupList] {
|
||||
g_lua.collectGarbage();
|
||||
for(const UIWidgetPtr& widget : backupList) {
|
||||
if(widget->getUseCount() != 1)
|
||||
@@ -404,7 +404,7 @@ UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent
|
||||
}
|
||||
}
|
||||
|
||||
UIWidgetPtr UIManager::createWidgetFromStyle(const std::string& styleName, const UIWidgetPtr& parent)
|
||||
UIWidgetPtr UIManager::createWidget(const std::string& styleName, const UIWidgetPtr& parent)
|
||||
{
|
||||
OTMLNodePtr node = OTMLNode::create(styleName);
|
||||
try {
|
||||
|
@@ -49,7 +49,8 @@ public:
|
||||
std::string getStyleClass(const std::string& styleName);
|
||||
|
||||
UIWidgetPtr loadUI(const std::string& file, const UIWidgetPtr& parent);
|
||||
UIWidgetPtr createWidgetFromStyle(const std::string& styleName, const UIWidgetPtr& parent);
|
||||
UIWidgetPtr displayUI(const std::string& file) { return loadUI(file, m_rootWidget); }
|
||||
UIWidgetPtr createWidget(const std::string& styleName, const UIWidgetPtr& parent);
|
||||
UIWidgetPtr createWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent);
|
||||
|
||||
void setMouseReceiver(const UIWidgetPtr& widget) { m_mouseReceiver = widget; }
|
||||
|
@@ -86,7 +86,7 @@ bool UIVerticalLayout::internalUpdate()
|
||||
|
||||
if(m_fitChildren && preferredHeight != parentWidget->getHeight()) {
|
||||
// must set the preferred width later
|
||||
g_eventDispatcher.addEvent([=] {
|
||||
g_dispatcher.addEvent([=] {
|
||||
parentWidget->setHeight(preferredHeight);
|
||||
});
|
||||
}
|
||||
|
@@ -505,7 +505,7 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
|
||||
|
||||
if(m_firstOnStyle) {
|
||||
auto self = asUIWidget();
|
||||
g_eventDispatcher.addEvent([self] {
|
||||
g_dispatcher.addEvent([self] {
|
||||
self->callLuaField("onSetup");
|
||||
});
|
||||
// always focus new child
|
||||
@@ -832,7 +832,7 @@ bool UIWidget::setRect(const Rect& rect)
|
||||
// avoid massive update events
|
||||
if(!m_updateEventScheduled) {
|
||||
UIWidgetPtr self = asUIWidget();
|
||||
g_eventDispatcher.addEvent([self, oldRect]() {
|
||||
g_dispatcher.addEvent([self, oldRect]() {
|
||||
self->m_updateEventScheduled = false;
|
||||
if(oldRect != self->getRect())
|
||||
self->onGeometryChange(oldRect, self->getRect());
|
||||
@@ -1318,7 +1318,7 @@ void UIWidget::updateStyle()
|
||||
|
||||
if(m_loadingStyle && !m_updateStyleScheduled) {
|
||||
UIWidgetPtr self = asUIWidget();
|
||||
g_eventDispatcher.addEvent([self] {
|
||||
g_dispatcher.addEvent([self] {
|
||||
self->m_updateStyleScheduled = false;
|
||||
self->updateStyle();
|
||||
});
|
||||
|
@@ -53,7 +53,7 @@ void AnimatedText::startAnimation()
|
||||
|
||||
// schedule removal
|
||||
auto self = asAnimatedText();
|
||||
g_eventDispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, Otc::ANIMATED_TEXT_DURATION);
|
||||
g_dispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, Otc::ANIMATED_TEXT_DURATION);
|
||||
}
|
||||
|
||||
void AnimatedText::setColor(int color)
|
||||
|
@@ -368,7 +368,7 @@ void Creature::nextWalkUpdate()
|
||||
// schedules next update
|
||||
if(m_walking) {
|
||||
auto self = asCreature();
|
||||
m_walkUpdateEvent = g_eventDispatcher.scheduleEvent([self] {
|
||||
m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] {
|
||||
self->m_walkUpdateEvent = nullptr;
|
||||
self->nextWalkUpdate();
|
||||
}, m_walkAnimationInterval / 32);
|
||||
@@ -492,7 +492,7 @@ void Creature::setShieldTexture(const std::string& filename, bool blink)
|
||||
|
||||
if(blink && !m_shieldBlink) {
|
||||
auto self = asCreature();
|
||||
g_eventDispatcher.scheduleEvent([self]() {
|
||||
g_dispatcher.scheduleEvent([self]() {
|
||||
self->updateShield();
|
||||
}, SHIELD_BLINK_TICKS);
|
||||
}
|
||||
@@ -512,7 +512,7 @@ void Creature::addTimedSquare(uint8 color)
|
||||
|
||||
// schedule removal
|
||||
auto self = asCreature();
|
||||
g_eventDispatcher.scheduleEvent([self]() {
|
||||
g_dispatcher.scheduleEvent([self]() {
|
||||
self->removeTimedSquare();
|
||||
}, VOLATILE_SQUARE_DURATION);
|
||||
}
|
||||
@@ -523,7 +523,7 @@ void Creature::updateShield()
|
||||
|
||||
if(m_shield != Otc::ShieldNone && m_shieldBlink) {
|
||||
auto self = asCreature();
|
||||
g_eventDispatcher.scheduleEvent([self]() {
|
||||
g_dispatcher.scheduleEvent([self]() {
|
||||
self->updateShield();
|
||||
}, SHIELD_BLINK_TICKS);
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ void Effect::startAnimation()
|
||||
|
||||
// schedule removal
|
||||
auto self = asEffect();
|
||||
g_eventDispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, Otc::EFFECT_TICKS_PER_FRAME * getAnimationPhases());
|
||||
g_dispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, Otc::EFFECT_TICKS_PER_FRAME * getAnimationPhases());
|
||||
}
|
||||
|
||||
void Effect::setId(uint32 id)
|
||||
|
@@ -1,238 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "itemloader.h"
|
||||
#include <framework/core/resourcemanager.h>
|
||||
#include <framework/core/filestream.h>
|
||||
#define TIXML_USE_STL // use STL strings instead.
|
||||
#include <framework/thirdparty/tinyxml.h>
|
||||
|
||||
ItemLoader g_itemLoader;
|
||||
|
||||
ItemLoader::~ItemLoader()
|
||||
{
|
||||
m_items.clear();
|
||||
}
|
||||
|
||||
ItemDataPtr ItemLoader::getType(uint16 id) const
|
||||
{
|
||||
for (const ItemDataPtr &it : m_items) {
|
||||
if (it->id == id)
|
||||
return it;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ItemLoader::addType(uint16 id, ItemDataPtr type)
|
||||
{
|
||||
if (getType(id))
|
||||
return;
|
||||
|
||||
m_items.push_back(type);
|
||||
}
|
||||
|
||||
bool ItemLoader::loadOtb(const std::string &name)
|
||||
{
|
||||
FileStreamPtr fin = g_resources.openFile(name);
|
||||
if (!fin) {
|
||||
g_logger.error(stdext::format("failed to open file '%s'", name));
|
||||
return false;
|
||||
}
|
||||
|
||||
fin->getU32(); // skip version
|
||||
|
||||
uint32 type;
|
||||
uint8 node = fin->readNode(node, type);
|
||||
|
||||
fin->getU32(); // skip flags...
|
||||
if (fin->getU8() == 0x01) { // version
|
||||
fin->getU8(); // skip length.
|
||||
dwMajorVersion = fin->getU32();
|
||||
dwMinorVersion = fin->getU32();
|
||||
dwBuildNumber = fin->getU32();
|
||||
}
|
||||
|
||||
uint16 lastId = 99;
|
||||
ItemDataPtr newItem;
|
||||
|
||||
while ((node = fin->readNode(node, type))) {
|
||||
if (!(newItem = ItemDataPtr(new ItemData))) {
|
||||
g_logger.error("failed to read new item from OTB");
|
||||
return false;
|
||||
}
|
||||
|
||||
newItem->group = (ItemGroup)type;
|
||||
fin->getU32(); // skip flags
|
||||
|
||||
ItemAttrib attr;
|
||||
while ((attr = (ItemAttrib)fin->getU8())) {
|
||||
uint16 dsize = fin->getU16();
|
||||
switch (attr) {
|
||||
case ServerId: {
|
||||
if (dsize != sizeof(uint16)) {
|
||||
g_logger.error("Invalid data size");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16 serverId = fin->getU16();
|
||||
if (serverId > 20000 && serverId < 20100) {
|
||||
serverId -= 20000;
|
||||
} else if (lastId > 99 && lastId != serverId - 1) {
|
||||
static ItemDataPtr dummyItemType(new ItemData);
|
||||
while (lastId != serverId - 1) {
|
||||
dummyItemType->id = ++lastId;
|
||||
addType(lastId, dummyItemType);
|
||||
}
|
||||
}
|
||||
|
||||
newItem->id = serverId;
|
||||
lastId = serverId;
|
||||
break;
|
||||
} case ClientId: {
|
||||
newItem->clientId = fin->getU16();
|
||||
break;
|
||||
} case Speed: {
|
||||
fin->getU16(); // skip speed
|
||||
break;
|
||||
} case Light2: {
|
||||
if (!fin->seek(dsize)) {
|
||||
g_logger.error(stdext::format("fail to skip light block with size %d", dsize));
|
||||
return false;
|
||||
}
|
||||
} default: {
|
||||
if (!fin->seek(dsize)) {
|
||||
g_logger.error(stdext::format("fail to skip unknown data with size %d", dsize));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addType(newItem->id, newItem);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ItemLoader::loadXML(const std::string &name)
|
||||
{
|
||||
TiXmlDocument doc(name.c_str());
|
||||
if (!doc.LoadFile()) {
|
||||
g_logger.error(stdext::format("failed to load xml '%s'", name));
|
||||
return false;
|
||||
}
|
||||
|
||||
TiXmlElement* root = doc.FirstChildElement();
|
||||
if (!root) {
|
||||
g_logger.error("invalid xml root");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (root->ValueTStr() != "items") {
|
||||
g_logger.error("invalid xml tag name, should be 'items'");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (TiXmlElement *element = root->FirstChildElement(); element; element = element->NextSiblingElement()) {
|
||||
if (element->ValueTStr() != "item")
|
||||
continue;
|
||||
|
||||
std::string name = element->Attribute("id");
|
||||
if (name.empty())
|
||||
continue;
|
||||
|
||||
uint16 id = stdext::unsafe_cast<uint16>(element->Attribute("id"));
|
||||
uint16 idEx = 0;
|
||||
if (!id) {
|
||||
bool found = false;
|
||||
// fallback into reading fromid and toid
|
||||
uint16 fromid = stdext::unsafe_cast<uint16>(element->Attribute("fromid"));
|
||||
uint16 toid = stdext::unsafe_cast<uint16>(element->Attribute("toid"));
|
||||
ItemDataPtr iType;
|
||||
for (int __id = fromid; __id < toid; ++__id) {
|
||||
if (!(iType = getType(__id)))
|
||||
continue;
|
||||
|
||||
iType->name = name;
|
||||
idEx = iType->id == fromid ? fromid : toid;
|
||||
found = true;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemDataPtr iType = getType(id);
|
||||
if (!iType) {
|
||||
iType = ItemDataPtr(new ItemData);
|
||||
iType->id = idEx ? idEx : id;
|
||||
iType->name = name;
|
||||
addType(iType->id, iType);
|
||||
}
|
||||
|
||||
iType->name = name;
|
||||
|
||||
for (TiXmlElement *attr = element->FirstChildElement(); attr; attr = attr->NextSiblingElement()) {
|
||||
if (attr->ValueTStr() != "attribute")
|
||||
continue;
|
||||
|
||||
std::string key = attr->Attribute("key");
|
||||
std::string value = attr->Attribute("value");
|
||||
if (key == "type") {
|
||||
if (value == "magicfield")
|
||||
iType->group = IsMagicField;
|
||||
else if (value == "key")
|
||||
iType->group = IsKey;
|
||||
else if (value == "depot")
|
||||
iType->isDepot = true;
|
||||
else if (value == "teleport")
|
||||
iType->group = IsTeleport;
|
||||
else if (value == "bed")
|
||||
iType->isBed = true;
|
||||
else if (value == "door")
|
||||
iType->group = IsDoor;
|
||||
} else if (key == "name") {
|
||||
iType->name = value;
|
||||
} else if (key == "description") {
|
||||
iType->description = value;
|
||||
} else if (key == "weight") {
|
||||
iType->weight = stdext::unsafe_cast<double>(stdext::unsafe_cast<double>(value) / 100.f);
|
||||
} else if (key == "containerSize") {
|
||||
int containerSize = stdext::unsafe_cast<int>(value);
|
||||
if (containerSize)
|
||||
iType->containerSize = containerSize;
|
||||
iType->group = IsContainer;
|
||||
} else if (key == "writeable") {
|
||||
if (!value.empty())
|
||||
iType->group = IsWritable;
|
||||
} else if (key == "maxTextLen") {
|
||||
iType->maxTextLength = stdext::unsafe_cast<int>(value);
|
||||
} else if (key == "charges") {
|
||||
iType->charges = stdext::unsafe_cast<int>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
doc.Clear();
|
||||
return true;
|
||||
}
|
@@ -185,7 +185,7 @@ void LocalPlayer::terminateWalk()
|
||||
if(m_autoWalking) {
|
||||
if(m_autoWalkEndEvent)
|
||||
m_autoWalkEndEvent->cancel();
|
||||
m_autoWalkEndEvent = g_eventDispatcher.scheduleEvent([self] {
|
||||
m_autoWalkEndEvent = g_dispatcher.scheduleEvent([self] {
|
||||
self->m_autoWalking = false;
|
||||
}, 100);
|
||||
}
|
||||
|
@@ -286,6 +286,9 @@ bool Map::loadOtcm(const std::string& fileName)
|
||||
{
|
||||
try {
|
||||
FileStreamPtr fin = g_resources.openFile(fileName);
|
||||
if(!fin)
|
||||
stdext::throw_exception("unable to open file");
|
||||
|
||||
fin->cache();
|
||||
|
||||
uint32 signature = fin->getU32();
|
||||
@@ -617,7 +620,7 @@ void Map::setCentralPosition(const Position& centralPosition)
|
||||
// this fixes local player position when the local player is removed from the map,
|
||||
// the local player is removed from the map when there are too many creatures on his tile,
|
||||
// so there is no enough stackpos to the server send him
|
||||
g_eventDispatcher.addEvent([this] {
|
||||
g_dispatcher.addEvent([this] {
|
||||
LocalPlayerPtr localPlayer = g_game.getLocalPlayer();
|
||||
if(!localPlayer || localPlayer->getPosition() == m_centralPosition)
|
||||
return;
|
||||
|
@@ -394,7 +394,7 @@ void MapView::updateVisibleTilesCache(int start)
|
||||
|
||||
if(stop) {
|
||||
// schedule next update continuation to avoid freezes
|
||||
m_updateTilesCacheEvent = g_eventDispatcher.scheduleEvent(std::bind(&MapView::updateVisibleTilesCache, asMapView(), count), 1);
|
||||
m_updateTilesCacheEvent = g_dispatcher.scheduleEvent(std::bind(&MapView::updateVisibleTilesCache, asMapView(), count), 1);
|
||||
}
|
||||
|
||||
if(start == 0 && m_drawTexts && m_viewMode <= NEAR_VIEW)
|
||||
|
25
src/otclient/core/minimap.cpp
Normal file
25
src/otclient/core/minimap.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "minimap.h"
|
||||
|
66
src/otclient/core/minimap.h
Normal file
66
src/otclient/core/minimap.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MINIMAP_H
|
||||
#define MINIMAP_H
|
||||
|
||||
#include <otclient/global.h>
|
||||
#include <framework/graphics/image.h>
|
||||
/*
|
||||
enum {
|
||||
MINIMAP_AREA_SIZE = 32
|
||||
};
|
||||
|
||||
struct MinimapArea
|
||||
{
|
||||
ImagePtr img;
|
||||
TexturePtr tex;
|
||||
uint8 colors[MINIMAP_AREA_SIZE][MINIMAP_AREA_SIZE];
|
||||
Boolean<true> mustUpdate;
|
||||
};
|
||||
|
||||
class Minimap
|
||||
{
|
||||
|
||||
public:
|
||||
void init();
|
||||
void terminate();
|
||||
|
||||
void loadOtmm();
|
||||
void saveOtmm();
|
||||
|
||||
void updateTile(const Position& pos, uint8 color);
|
||||
|
||||
private:
|
||||
|
||||
struct MinimaAreaHasher : std::unary_function<Position, std::size_t> {
|
||||
std::size_t operator()(const Position& pos) const {
|
||||
return ((pos.x/MINIMAP_AREA_SIZE) * 0x8000 + (pos.y/MINIMAP_AREA_SIZE)) * 16 + pos.z;
|
||||
}
|
||||
};
|
||||
std::unordered_map<Position, ImagePtr, MinimaAreaHasher> m_areas;
|
||||
};
|
||||
|
||||
extern Minimap g_minimap;
|
||||
*/
|
||||
#endif
|
@@ -78,7 +78,7 @@ void Missile::setPath(const Position& fromPosition, const Position& toPosition)
|
||||
|
||||
// schedule removal
|
||||
auto self = asMissile();
|
||||
g_eventDispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, m_duration);
|
||||
g_dispatcher.scheduleEvent([self]() { g_map.removeThing(self); }, m_duration);
|
||||
}
|
||||
|
||||
void Missile::setId(uint32 id)
|
||||
|
@@ -81,7 +81,7 @@ void StaticText::update()
|
||||
if(m_messages.empty()) {
|
||||
// schedule removal
|
||||
auto self = asStaticText();
|
||||
g_eventDispatcher.addEvent([self]() { g_map.removeThing(self); });
|
||||
g_dispatcher.addEvent([self]() { g_map.removeThing(self); });
|
||||
} else {
|
||||
compose();
|
||||
scheduleUpdate();
|
||||
@@ -94,7 +94,7 @@ void StaticText::scheduleUpdate()
|
||||
int delay = std::max(Otc::STATIC_DURATION_PER_CHARACTER * len, (int)Otc::MIN_STATIC_TEXT_DURATION);
|
||||
|
||||
auto self = asStaticText();
|
||||
m_updateEvent = g_eventDispatcher.scheduleEvent([self]() {
|
||||
m_updateEvent = g_dispatcher.scheduleEvent([self]() {
|
||||
self->m_updateEvent = nullptr;
|
||||
self->update();
|
||||
}, delay);
|
||||
|
@@ -94,6 +94,8 @@ bool ThingTypeManager::loadOtb(const std::string& file)
|
||||
{
|
||||
try {
|
||||
FileStreamPtr fin = g_resources.openFile(file);
|
||||
if(!fin)
|
||||
stdext::throw_exception("unable to open file");
|
||||
|
||||
uint signature = fin->getU32();
|
||||
if(signature != 0)
|
||||
|
Reference in New Issue
Block a user