mirror of
https://github.com/edubart/otclient.git
synced 2025-04-30 01:29:21 +02:00
Tidy up the source code
* Replaced push_back calls with emplace_back where applicable. * Replaced size() == 0 and size() != 0 with empty() and !empty(). * Replaced C style loops for range for loops where applicable. * Fixed mismatching arg names between function declarations and definitions. * Replaced NULL and 0 (in the context of pointers) with nullptr. * Remove unnecessary calls to string::c_str() where applicable. * Replaced deprecated C headers with proper C++ headers. * Removed unnecessary null pointer checks when deleting pointers (deleting a null pointer has no effect). * Fixed a potential memory leak in apngloader.cpp file. * Replaced unsafe strcpy with strncpy in the demangle_name function.
This commit is contained in:
parent
caae18dbce
commit
869de6886f
@ -50,7 +50,7 @@ void Animator::unserialize(int animationPhases, const FileStreamPtr& fin)
|
|||||||
for(int i = 0; i < m_animationPhases; ++i) {
|
for(int i = 0; i < m_animationPhases; ++i) {
|
||||||
int minimum = fin->getU32();
|
int minimum = fin->getU32();
|
||||||
int maximum = fin->getU32();
|
int maximum = fin->getU32();
|
||||||
m_phaseDurations.push_back(std::make_tuple(minimum, maximum));
|
m_phaseDurations.emplace_back(minimum, maximum);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_phase = getStartPhase();
|
m_phase = getStartPhase();
|
||||||
|
@ -133,7 +133,7 @@ public:
|
|||||||
const std::vector<CreatureTypePtr>& getCreatures() { return m_creatures; }
|
const std::vector<CreatureTypePtr>& getCreatures() { return m_creatures; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void internalLoadCreatureBuffer(TiXmlElement* elem, const CreatureTypePtr& m);
|
void internalLoadCreatureBuffer(TiXmlElement* attrib, const CreatureTypePtr& m);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<CreatureTypePtr> m_creatures;
|
std::vector<CreatureTypePtr> m_creatures;
|
||||||
|
@ -686,7 +686,7 @@ void Game::autoWalk(std::vector<Otc::Direction> dirs)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dirs.size() == 0)
|
if(dirs.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// must cancel follow before any new walk
|
// must cancel follow before any new walk
|
||||||
@ -1715,10 +1715,10 @@ std::string Game::formatCreatureName(const std::string& name)
|
|||||||
std::string formatedName = name;
|
std::string formatedName = name;
|
||||||
if(getFeature(Otc::GameFormatCreatureName) && name.length() > 0) {
|
if(getFeature(Otc::GameFormatCreatureName) && name.length() > 0) {
|
||||||
bool upnext = true;
|
bool upnext = true;
|
||||||
for(uint i=0;i<formatedName.length();++i) {
|
for(char &i: formatedName) {
|
||||||
char ch = formatedName[i];
|
char ch = i;
|
||||||
if(upnext) {
|
if(upnext) {
|
||||||
formatedName[i] = stdext::upchar(ch);
|
i = stdext::upchar(ch);
|
||||||
upnext = false;
|
upnext = false;
|
||||||
}
|
}
|
||||||
if(ch == ' ')
|
if(ch == ' ')
|
||||||
|
@ -70,7 +70,7 @@ private:
|
|||||||
void resetGameStates();
|
void resetGameStates();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void processConnectionError(const boost::system::error_code& error);
|
void processConnectionError(const boost::system::error_code& ec);
|
||||||
void processDisconnect();
|
void processDisconnect();
|
||||||
void processPing();
|
void processPing();
|
||||||
void processPingBack();
|
void processPingBack();
|
||||||
@ -178,7 +178,7 @@ public:
|
|||||||
void moveToParentContainer(const ThingPtr& thing, int count);
|
void moveToParentContainer(const ThingPtr& thing, int count);
|
||||||
void rotate(const ThingPtr& thing);
|
void rotate(const ThingPtr& thing);
|
||||||
void use(const ThingPtr& thing);
|
void use(const ThingPtr& thing);
|
||||||
void useWith(const ItemPtr& fromThing, const ThingPtr& toThing);
|
void useWith(const ItemPtr& item, const ThingPtr& toThing);
|
||||||
void useInventoryItem(int itemId);
|
void useInventoryItem(int itemId);
|
||||||
void useInventoryItemWith(int itemId, const ThingPtr& toThing);
|
void useInventoryItemWith(int itemId, const ThingPtr& toThing);
|
||||||
ItemPtr findItemInContainers(uint itemId, int subType);
|
ItemPtr findItemInContainers(uint itemId, int subType);
|
||||||
@ -241,7 +241,7 @@ public:
|
|||||||
// pvp related
|
// pvp related
|
||||||
void setUnjustifiedPoints(UnjustifiedPoints unjustifiedPoints);
|
void setUnjustifiedPoints(UnjustifiedPoints unjustifiedPoints);
|
||||||
UnjustifiedPoints getUnjustifiedPoints() { return m_unjustifiedPoints; };
|
UnjustifiedPoints getUnjustifiedPoints() { return m_unjustifiedPoints; };
|
||||||
void setOpenPvpSituations(int openPvpSitations);
|
void setOpenPvpSituations(int openPvpSituations);
|
||||||
int getOpenPvpSituations() { return m_openPvpSituations; }
|
int getOpenPvpSituations() { return m_openPvpSituations; }
|
||||||
|
|
||||||
// npc trade related
|
// npc trade related
|
||||||
@ -345,7 +345,7 @@ public:
|
|||||||
std::string getCharacterName() { return m_characterName; }
|
std::string getCharacterName() { return m_characterName; }
|
||||||
std::string getWorldName() { return m_worldName; }
|
std::string getWorldName() { return m_worldName; }
|
||||||
std::vector<uint8> getGMActions() { return m_gmActions; }
|
std::vector<uint8> getGMActions() { return m_gmActions; }
|
||||||
bool isGM() { return m_gmActions.size() > 0; }
|
bool isGM() { return !m_gmActions.empty(); }
|
||||||
Otc::Direction getLastWalkDir() { return m_lastWalkDir; }
|
Otc::Direction getLastWalkDir() { return m_lastWalkDir; }
|
||||||
|
|
||||||
std::string formatCreatureName(const std::string &name);
|
std::string formatCreatureName(const std::string &name);
|
||||||
|
@ -88,7 +88,7 @@ void LightView::addLightSource(const Point& center, float scaleFactor, const Lig
|
|||||||
color.setGreen(color.gF() * brightness);
|
color.setGreen(color.gF() * brightness);
|
||||||
color.setBlue(color.bF() * brightness);
|
color.setBlue(color.bF() * brightness);
|
||||||
|
|
||||||
if(m_blendEquation == Painter::BlendEquation_Add && m_lightMap.size() > 0) {
|
if(m_blendEquation == Painter::BlendEquation_Add && !m_lightMap.empty()) {
|
||||||
LightSource prevSource = m_lightMap.back();
|
LightSource prevSource = m_lightMap.back();
|
||||||
if(prevSource.center == center && prevSource.color == color && prevSource.radius == radius)
|
if(prevSource.center == center && prevSource.color == color && prevSource.radius == radius)
|
||||||
return;
|
return;
|
||||||
|
@ -192,7 +192,7 @@ public:
|
|||||||
// tile zone related
|
// tile zone related
|
||||||
void setShowZone(tileflags_t zone, bool show);
|
void setShowZone(tileflags_t zone, bool show);
|
||||||
void setShowZones(bool show);
|
void setShowZones(bool show);
|
||||||
void setZoneColor(tileflags_t flag, const Color& color);
|
void setZoneColor(tileflags_t zone, const Color& color);
|
||||||
void setZoneOpacity(float opacity) { m_zoneOpacity = opacity; }
|
void setZoneOpacity(float opacity) { m_zoneOpacity = opacity; }
|
||||||
|
|
||||||
float getZoneOpacity() { return m_zoneOpacity; }
|
float getZoneOpacity() { return m_zoneOpacity; }
|
||||||
|
@ -378,11 +378,11 @@ void MapView::updateVisibleTilesCache(int start)
|
|||||||
Rect(tpx, tpy + 1, 1, qs),
|
Rect(tpx, tpy + 1, 1, qs),
|
||||||
};
|
};
|
||||||
|
|
||||||
for(int i=0;i<4;++i) {
|
for(auto &line: lines) {
|
||||||
int sx = std::max<int>(lines[i].left(), area.left());
|
int sx = std::max<int>(line.left(), area.left());
|
||||||
int ex = std::min<int>(lines[i].right(), area.right());
|
int ex = std::min<int>(line.right(), area.right());
|
||||||
int sy = std::max<int>(lines[i].top(), area.top());
|
int sy = std::max<int>(line.top(), area.top());
|
||||||
int ey = std::min<int>(lines[i].bottom(), area.bottom());
|
int ey = std::min<int>(line.bottom(), area.bottom());
|
||||||
for(int qx=sx;qx<=ex;++qx)
|
for(int qx=sx;qx<=ex;++qx)
|
||||||
for(int qy=sy;qy<=ey;++qy)
|
for(int qy=sy;qy<=ey;++qy)
|
||||||
m_spiral[count++] = Point(qx, qy);
|
m_spiral[count++] = Point(qx, qy);
|
||||||
|
@ -55,12 +55,12 @@ public:
|
|||||||
void sendTurnSouth();
|
void sendTurnSouth();
|
||||||
void sendTurnWest();
|
void sendTurnWest();
|
||||||
void sendEquipItem(int itemId, int countOrSubType);
|
void sendEquipItem(int itemId, int countOrSubType);
|
||||||
void sendMove(const Position& fromPos, int itemId, int stackpos, const Position& toPos, int count);
|
void sendMove(const Position& fromPos, int thingId, int stackpos, const Position& toPos, int count);
|
||||||
void sendInspectNpcTrade(int itemId, int count);
|
void sendInspectNpcTrade(int itemId, int count);
|
||||||
void sendBuyItem(int itemId, int subType, int amount, bool ignoreCapacity, bool buyWithBackpack);
|
void sendBuyItem(int itemId, int subType, int amount, bool ignoreCapacity, bool buyWithBackpack);
|
||||||
void sendSellItem(int itemId, int subType, int amount, bool ignoreEquipped);
|
void sendSellItem(int itemId, int subType, int amount, bool ignoreEquipped);
|
||||||
void sendCloseNpcTrade();
|
void sendCloseNpcTrade();
|
||||||
void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint playerId);
|
void sendRequestTrade(const Position& pos, int thingId, int stackpos, uint creatureId);
|
||||||
void sendInspectTrade(bool counterOffer, int index);
|
void sendInspectTrade(bool counterOffer, int index);
|
||||||
void sendAcceptTrade();
|
void sendAcceptTrade();
|
||||||
void sendRejectTrade();
|
void sendRejectTrade();
|
||||||
@ -118,7 +118,7 @@ public:
|
|||||||
void sendRequestStoreOffers(const std::string& categoryName, int serviceType);
|
void sendRequestStoreOffers(const std::string& categoryName, int serviceType);
|
||||||
void sendOpenStore(int serviceType, const std::string &category);
|
void sendOpenStore(int serviceType, const std::string &category);
|
||||||
void sendTransferCoins(const std::string& recipient, int amount);
|
void sendTransferCoins(const std::string& recipient, int amount);
|
||||||
void sendOpenTransactionHistory(int entiresPerPage);
|
void sendOpenTransactionHistory(int entriesPerPage);
|
||||||
|
|
||||||
// otclient only
|
// otclient only
|
||||||
void sendChangeMapAwareRange(int xrange, int yrange);
|
void sendChangeMapAwareRange(int xrange, int yrange);
|
||||||
|
@ -1000,7 +1000,7 @@ void ProtocolGame::parseOpenNpcTrade(const InputMessagePtr& msg)
|
|||||||
int weight = msg->getU32();
|
int weight = msg->getU32();
|
||||||
int buyPrice = msg->getU32();
|
int buyPrice = msg->getU32();
|
||||||
int sellPrice = msg->getU32();
|
int sellPrice = msg->getU32();
|
||||||
items.push_back(std::make_tuple(item, name, weight, buyPrice, sellPrice));
|
items.emplace_back(item, name, weight, buyPrice, sellPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_game.processOpenNpcTrade(items);
|
g_game.processOpenNpcTrade(items);
|
||||||
@ -1026,7 +1026,7 @@ void ProtocolGame::parsePlayerGoods(const InputMessagePtr& msg)
|
|||||||
else
|
else
|
||||||
amount = msg->getU8();
|
amount = msg->getU8();
|
||||||
|
|
||||||
goods.push_back(std::make_tuple(Item::create(itemId), amount));
|
goods.emplace_back(Item::create(itemId), amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_game.processPlayerGoods(money, goods);
|
g_game.processPlayerGoods(money, goods);
|
||||||
@ -1571,7 +1571,7 @@ void ProtocolGame::parseChannelList(const InputMessagePtr& msg)
|
|||||||
for(int i = 0; i < count; i++) {
|
for(int i = 0; i < count; i++) {
|
||||||
int id = msg->getU16();
|
int id = msg->getU16();
|
||||||
std::string name = msg->getString();
|
std::string name = msg->getString();
|
||||||
channelList.push_back(std::make_tuple(id, name));
|
channelList.emplace_back(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_game.processChannelList(channelList);
|
g_game.processChannelList(channelList);
|
||||||
@ -1785,7 +1785,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg)
|
|||||||
std::string outfitName = msg->getString();
|
std::string outfitName = msg->getString();
|
||||||
int outfitAddons = msg->getU8();
|
int outfitAddons = msg->getU8();
|
||||||
|
|
||||||
outfitList.push_back(std::make_tuple(outfitId, outfitName, outfitAddons));
|
outfitList.emplace_back(outfitId, outfitName, outfitAddons);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int outfitStart, outfitEnd;
|
int outfitStart, outfitEnd;
|
||||||
@ -1798,7 +1798,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(int i = outfitStart; i <= outfitEnd; i++)
|
for(int i = outfitStart; i <= outfitEnd; i++)
|
||||||
outfitList.push_back(std::make_tuple(i, "", 0));
|
outfitList.emplace_back(i, "", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::tuple<int, std::string> > mountList;
|
std::vector<std::tuple<int, std::string> > mountList;
|
||||||
@ -1808,7 +1808,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg)
|
|||||||
int mountId = msg->getU16(); // mount type
|
int mountId = msg->getU16(); // mount type
|
||||||
std::string mountName = msg->getString(); // mount name
|
std::string mountName = msg->getString(); // mount name
|
||||||
|
|
||||||
mountList.push_back(std::make_tuple(mountId, mountName));
|
mountList.emplace_back(mountId, mountName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1881,7 +1881,7 @@ void ProtocolGame::parseQuestLog(const InputMessagePtr& msg)
|
|||||||
int id = msg->getU16();
|
int id = msg->getU16();
|
||||||
std::string name = msg->getString();
|
std::string name = msg->getString();
|
||||||
bool completed = msg->getU8();
|
bool completed = msg->getU8();
|
||||||
questList.push_back(std::make_tuple(id, name, completed));
|
questList.emplace_back(id, name, completed);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_game.processQuestLog(questList);
|
g_game.processQuestLog(questList);
|
||||||
@ -1895,7 +1895,7 @@ void ProtocolGame::parseQuestLine(const InputMessagePtr& msg)
|
|||||||
for(int i = 0; i < missionCount; i++) {
|
for(int i = 0; i < missionCount; i++) {
|
||||||
std::string missionName = msg->getString();
|
std::string missionName = msg->getString();
|
||||||
std::string missionDescrition = msg->getString();
|
std::string missionDescrition = msg->getString();
|
||||||
questMissions.push_back(std::make_tuple(missionName, missionDescrition));
|
questMissions.emplace_back(missionName, missionDescrition);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_game.processQuestLine(questId, questMissions);
|
g_game.processQuestLine(questId, questMissions);
|
||||||
@ -1920,7 +1920,7 @@ void ProtocolGame::parseItemInfo(const InputMessagePtr& msg)
|
|||||||
item->setCountOrSubType(msg->getU8());
|
item->setCountOrSubType(msg->getU8());
|
||||||
|
|
||||||
std::string desc = msg->getString();
|
std::string desc = msg->getString();
|
||||||
list.push_back(std::make_tuple(item, desc));
|
list.emplace_back(item, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_lua.callGlobalField("g_game", "onItemInfo", list);
|
g_lua.callGlobalField("g_game", "onItemInfo", list);
|
||||||
@ -1947,7 +1947,7 @@ void ProtocolGame::parseModalDialog(const InputMessagePtr& msg)
|
|||||||
for(int i = 0; i < sizeButtons; ++i) {
|
for(int i = 0; i < sizeButtons; ++i) {
|
||||||
std::string value = msg->getString();
|
std::string value = msg->getString();
|
||||||
int id = msg->getU8();
|
int id = msg->getU8();
|
||||||
buttonList.push_back(std::make_tuple(id, value));
|
buttonList.emplace_back(id, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sizeChoices = msg->getU8();
|
int sizeChoices = msg->getU8();
|
||||||
@ -1955,7 +1955,7 @@ void ProtocolGame::parseModalDialog(const InputMessagePtr& msg)
|
|||||||
for(int i = 0; i < sizeChoices; ++i) {
|
for(int i = 0; i < sizeChoices; ++i) {
|
||||||
std::string value = msg->getString();
|
std::string value = msg->getString();
|
||||||
int id = msg->getU8();
|
int id = msg->getU8();
|
||||||
choiceList.push_back(std::make_tuple(id, value));
|
choiceList.emplace_back(id, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int enterButton, escapeButton;
|
int enterButton, escapeButton;
|
||||||
|
@ -63,7 +63,7 @@ bool StaticText::addMessage(const std::string& name, Otc::MessageMode mode, cons
|
|||||||
{
|
{
|
||||||
//TODO: this could be moved to lua
|
//TODO: this could be moved to lua
|
||||||
// first message
|
// first message
|
||||||
if(m_messages.size() == 0) {
|
if(m_messages.empty()) {
|
||||||
m_name = name;
|
m_name = name;
|
||||||
m_mode = mode;
|
m_mode = mode;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ bool StaticText::addMessage(const std::string& name, Otc::MessageMode mode, cons
|
|||||||
if(isYell())
|
if(isYell())
|
||||||
delay *= 2;
|
delay *= 2;
|
||||||
|
|
||||||
m_messages.push_back(std::make_pair(text, g_clock.millis() + delay));
|
m_messages.emplace_back(text, g_clock.millis() + delay);
|
||||||
compose();
|
compose();
|
||||||
|
|
||||||
if(!m_updateEvent)
|
if(!m_updateEvent)
|
||||||
|
@ -123,11 +123,11 @@ void ThingType::serialize(const FileStreamPtr& fin)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint i = 0; i < m_spritesIndex.size(); i++) {
|
for(int i: m_spritesIndex) {
|
||||||
if(g_game.getFeature(Otc::GameSpritesU32))
|
if(g_game.getFeature(Otc::GameSpritesU32))
|
||||||
fin->addU32(m_spritesIndex[i]);
|
fin->addU32(i);
|
||||||
else
|
else
|
||||||
fin->addU16(m_spritesIndex[i]);
|
fin->addU16(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +328,7 @@ void ThingType::exportImage(std::string fileName)
|
|||||||
if(m_null)
|
if(m_null)
|
||||||
stdext::throw_exception("cannot export null thingtype");
|
stdext::throw_exception("cannot export null thingtype");
|
||||||
|
|
||||||
if(m_spritesIndex.size() == 0)
|
if(m_spritesIndex.empty())
|
||||||
stdext::throw_exception("cannot export thingtype without sprites");
|
stdext::throw_exception("cannot export thingtype without sprites");
|
||||||
|
|
||||||
ImagePtr image(new Image(Size(32 * m_size.width() * m_layers * m_numPatternX, 32 * m_size.height() * m_animationPhases * m_numPatternY * m_numPatternZ)));
|
ImagePtr image(new Image(Size(32 * m_size.width() * m_layers * m_numPatternX, 32 * m_size.height() * m_animationPhases * m_numPatternY * m_numPatternZ)));
|
||||||
@ -571,4 +571,4 @@ void ThingType::setPathable(bool var)
|
|||||||
m_attribs.remove(ThingAttrNotPathable);
|
m_attribs.remove(ThingAttrNotPathable);
|
||||||
else
|
else
|
||||||
m_attribs.set(ThingAttrNotPathable, true);
|
m_attribs.set(ThingAttrNotPathable, true);
|
||||||
}
|
}
|
||||||
|
@ -48,15 +48,15 @@ void ThingTypeManager::init()
|
|||||||
m_datLoaded = false;
|
m_datLoaded = false;
|
||||||
m_xmlLoaded = false;
|
m_xmlLoaded = false;
|
||||||
m_otbLoaded = false;
|
m_otbLoaded = false;
|
||||||
for(int i = 0; i < ThingLastCategory; ++i)
|
for(auto &m_thingType: m_thingTypes)
|
||||||
m_thingTypes[i].resize(1, m_nullThingType);
|
m_thingType.resize(1, m_nullThingType);
|
||||||
m_itemTypes.resize(1, m_nullItemType);
|
m_itemTypes.resize(1, m_nullItemType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThingTypeManager::terminate()
|
void ThingTypeManager::terminate()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < ThingLastCategory; ++i)
|
for(auto &m_thingType: m_thingTypes)
|
||||||
m_thingTypes[i].clear();
|
m_thingType.clear();
|
||||||
m_itemTypes.clear();
|
m_itemTypes.clear();
|
||||||
m_reverseItemTypes.clear();
|
m_reverseItemTypes.clear();
|
||||||
m_nullThingType = nullptr;
|
m_nullThingType = nullptr;
|
||||||
@ -77,8 +77,8 @@ void ThingTypeManager::saveDat(std::string fileName)
|
|||||||
|
|
||||||
fin->addU32(m_datSignature);
|
fin->addU32(m_datSignature);
|
||||||
|
|
||||||
for(int category = 0; category < ThingLastCategory; ++category)
|
for(auto &m_thingType: m_thingTypes)
|
||||||
fin->addU16(m_thingTypes[category].size() - 1);
|
fin->addU16(m_thingType.size() - 1);
|
||||||
|
|
||||||
for(int category = 0; category < ThingLastCategory; ++category) {
|
for(int category = 0; category < ThingLastCategory; ++category) {
|
||||||
uint16 firstId = 1;
|
uint16 firstId = 1;
|
||||||
@ -110,10 +110,10 @@ bool ThingTypeManager::loadDat(std::string file)
|
|||||||
m_datSignature = fin->getU32();
|
m_datSignature = fin->getU32();
|
||||||
m_contentRevision = static_cast<uint16_t>(m_datSignature);
|
m_contentRevision = static_cast<uint16_t>(m_datSignature);
|
||||||
|
|
||||||
for(int category = 0; category < ThingLastCategory; ++category) {
|
for(auto &m_thingType: m_thingTypes) {
|
||||||
int count = fin->getU16() + 1;
|
int count = fin->getU16() + 1;
|
||||||
m_thingTypes[category].clear();
|
m_thingType.clear();
|
||||||
m_thingTypes[category].resize(count, m_nullThingType);
|
m_thingType.resize(count, m_nullThingType);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int category = 0; category < ThingLastCategory; ++category) {
|
for(int category = 0; category < ThingLastCategory; ++category) {
|
||||||
|
@ -47,7 +47,7 @@ public:
|
|||||||
const ItemTypePtr& findItemTypeByClientId(uint16 id);
|
const ItemTypePtr& findItemTypeByClientId(uint16 id);
|
||||||
const ItemTypePtr& findItemTypeByName(std::string name);
|
const ItemTypePtr& findItemTypeByName(std::string name);
|
||||||
ItemTypeList findItemTypesByName(std::string name);
|
ItemTypeList findItemTypesByName(std::string name);
|
||||||
ItemTypeList findItemTypesByString(std::string str);
|
ItemTypeList findItemTypesByString(std::string name);
|
||||||
|
|
||||||
const ThingTypePtr& getNullThingType() { return m_nullThingType; }
|
const ThingTypePtr& getNullThingType() { return m_nullThingType; }
|
||||||
const ItemTypePtr& getNullItemType() { return m_nullItemType; }
|
const ItemTypePtr& getNullItemType() { return m_nullItemType; }
|
||||||
|
@ -63,8 +63,7 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags, LightView *
|
|||||||
|
|
||||||
bool restore = false;
|
bool restore = false;
|
||||||
if(g_map.showZones() && thing->isGround()) {
|
if(g_map.showZones() && thing->isGround()) {
|
||||||
for(unsigned int i = 0; i < sizeof(flags) / sizeof(tileflags_t); ++i) {
|
for(auto flag: flags) {
|
||||||
tileflags_t flag = flags[i];
|
|
||||||
if(hasFlag(flag) && g_map.showZone(flag)) {
|
if(hasFlag(flag) && g_map.showZone(flag)) {
|
||||||
g_painter->setOpacity(g_map.getZoneOpacity());
|
g_painter->setOpacity(g_map.getZoneOpacity());
|
||||||
g_painter->setColor(g_map.getZoneColor(flag));
|
g_painter->setColor(g_map.getZoneColor(flag));
|
||||||
@ -386,8 +385,7 @@ ThingPtr Tile::getTopLookThing()
|
|||||||
if(isEmpty())
|
if(isEmpty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
for(uint i = 0; i < m_things.size(); ++i) {
|
for(auto thing: m_things) {
|
||||||
ThingPtr thing = m_things[i];
|
|
||||||
if(!thing->isIgnoreLook() && (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()))
|
if(!thing->isIgnoreLook() && (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()))
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
@ -400,14 +398,12 @@ ThingPtr Tile::getTopUseThing()
|
|||||||
if(isEmpty())
|
if(isEmpty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
for(uint i = 0; i < m_things.size(); ++i) {
|
for(auto thing: m_things) {
|
||||||
ThingPtr thing = m_things[i];
|
|
||||||
if (thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature() && !thing->isSplash()))
|
if (thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature() && !thing->isSplash()))
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint i = 0; i < m_things.size(); ++i) {
|
for(auto thing: m_things) {
|
||||||
ThingPtr thing = m_things[i];
|
|
||||||
if (!thing->isGround() && !thing->isGroundBorder() && !thing->isCreature() && !thing->isSplash())
|
if (!thing->isGround() && !thing->isGroundBorder() && !thing->isCreature() && !thing->isSplash())
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
@ -418,8 +414,7 @@ ThingPtr Tile::getTopUseThing()
|
|||||||
CreaturePtr Tile::getTopCreature()
|
CreaturePtr Tile::getTopCreature()
|
||||||
{
|
{
|
||||||
CreaturePtr creature;
|
CreaturePtr creature;
|
||||||
for(uint i = 0; i < m_things.size(); ++i) {
|
for(auto thing: m_things) {
|
||||||
ThingPtr thing = m_things[i];
|
|
||||||
if(thing->isLocalPlayer()) // return local player if there is no other creature
|
if(thing->isLocalPlayer()) // return local player if there is no other creature
|
||||||
creature = thing->static_self_cast<Creature>();
|
creature = thing->static_self_cast<Creature>();
|
||||||
else if(thing->isCreature() && !thing->isLocalPlayer())
|
else if(thing->isCreature() && !thing->isLocalPlayer())
|
||||||
@ -480,8 +475,7 @@ ThingPtr Tile::getTopMultiUseThing()
|
|||||||
if(CreaturePtr topCreature = getTopCreature())
|
if(CreaturePtr topCreature = getTopCreature())
|
||||||
return topCreature;
|
return topCreature;
|
||||||
|
|
||||||
for(uint i = 0; i < m_things.size(); ++i) {
|
for(auto thing: m_things) {
|
||||||
ThingPtr thing = m_things[i];
|
|
||||||
if(thing->isForceUse())
|
if(thing->isForceUse())
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
@ -495,8 +489,7 @@ ThingPtr Tile::getTopMultiUseThing()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint i = 0; i < m_things.size(); ++i) {
|
for(auto thing: m_things) {
|
||||||
ThingPtr thing = m_things[i];
|
|
||||||
if(!thing->isGround() && !thing->isOnTop())
|
if(!thing->isGround() && !thing->isOnTop())
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ void AsyncDispatcher::terminate()
|
|||||||
void AsyncDispatcher::spawn_thread()
|
void AsyncDispatcher::spawn_thread()
|
||||||
{
|
{
|
||||||
m_running = true;
|
m_running = true;
|
||||||
m_threads.push_back(std::thread(std::bind(&AsyncDispatcher::exec_loop, this)));
|
m_threads.emplace_back(std::bind(&AsyncDispatcher::exec_loop, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncDispatcher::stop()
|
void AsyncDispatcher::stop()
|
||||||
@ -55,7 +55,7 @@ void AsyncDispatcher::stop()
|
|||||||
void AsyncDispatcher::exec_loop() {
|
void AsyncDispatcher::exec_loop() {
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
while(true) {
|
while(true) {
|
||||||
while(m_tasks.size() == 0 && m_running)
|
while(m_tasks.empty() && m_running)
|
||||||
m_condition.wait(lock);
|
m_condition.wait(lock);
|
||||||
|
|
||||||
if(!m_running)
|
if(!m_running)
|
||||||
|
@ -74,7 +74,7 @@ void Config::clear()
|
|||||||
|
|
||||||
void Config::setValue(const std::string& key, const std::string& value)
|
void Config::setValue(const std::string& key, const std::string& value)
|
||||||
{
|
{
|
||||||
if(value == "") {
|
if(value.empty()) {
|
||||||
remove(key);
|
remove(key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ void Config::setList(const std::string& key, const std::vector<std::string>& lis
|
|||||||
{
|
{
|
||||||
remove(key);
|
remove(key);
|
||||||
|
|
||||||
if(list.size() == 0)
|
if(list.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OTMLNodePtr child = OTMLNode::create(key, true);
|
OTMLNodePtr child = OTMLNode::create(key, true);
|
||||||
|
@ -320,7 +320,7 @@ std::string FileStream::getString()
|
|||||||
} else {
|
} else {
|
||||||
if(m_pos+len > m_data.size()) {
|
if(m_pos+len > m_data.size()) {
|
||||||
throwError("read failed");
|
throwError("read failed");
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = std::string((char*)&m_data[m_pos], len);
|
str = std::string((char*)&m_data[m_pos], len);
|
||||||
|
@ -74,8 +74,8 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
|
|||||||
m_outFile.flush();
|
m_outFile.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t now = std::time(NULL);
|
std::size_t now = std::time(nullptr);
|
||||||
m_logMessages.push_back(LogMessage(level, outmsg, now));
|
m_logMessages.emplace_back(level, outmsg, now);
|
||||||
if(m_logMessages.size() > MAX_LOG_HISTORY)
|
if(m_logMessages.size() > MAX_LOG_HISTORY)
|
||||||
m_logMessages.pop_front();
|
m_logMessages.pop_front();
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ void Logger::setLogFile(const std::string& file)
|
|||||||
{
|
{
|
||||||
std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
||||||
|
|
||||||
m_outFile.open(stdext::utf8_to_latin1(file.c_str()).c_str(), std::ios::out | std::ios::app);
|
m_outFile.open(stdext::utf8_to_latin1(file).c_str(), std::ios::out | std::ios::app);
|
||||||
if(!m_outFile.is_open() || !m_outFile.good()) {
|
if(!m_outFile.is_open() || !m_outFile.good()) {
|
||||||
g_logger.error(stdext::format("Unable to save log to '%s'", file));
|
g_logger.error(stdext::format("Unable to save log to '%s'", file));
|
||||||
return;
|
return;
|
||||||
|
@ -264,8 +264,8 @@ std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& di
|
|||||||
std::list<std::string> files;
|
std::list<std::string> files;
|
||||||
auto rc = PHYSFS_enumerateFiles(resolvePath(directoryPath).c_str());
|
auto rc = PHYSFS_enumerateFiles(resolvePath(directoryPath).c_str());
|
||||||
|
|
||||||
for(int i = 0; rc[i] != NULL; i++)
|
for(int i = 0; rc[i] != nullptr; i++)
|
||||||
files.push_back(rc[i]);
|
files.emplace_back(rc[i]);
|
||||||
|
|
||||||
PHYSFS_freeList(rc);
|
PHYSFS_freeList(rc);
|
||||||
return files;
|
return files;
|
||||||
|
@ -44,7 +44,7 @@ public:
|
|||||||
|
|
||||||
bool addSearchPath(const std::string& path, bool pushFront = false);
|
bool addSearchPath(const std::string& path, bool pushFront = false);
|
||||||
bool removeSearchPath(const std::string& path);
|
bool removeSearchPath(const std::string& path);
|
||||||
void searchAndAddPackages(const std::string& packagesDir, const std::string& packagesExt);
|
void searchAndAddPackages(const std::string& packagesDir, const std::string& packageExt);
|
||||||
|
|
||||||
bool fileExists(const std::string& fileName);
|
bool fileExists(const std::string& fileName);
|
||||||
bool directoryExists(const std::string& directoryName);
|
bool directoryExists(const std::string& directoryName);
|
||||||
|
@ -30,8 +30,8 @@ AnimatedTexture::AnimatedTexture(const Size& size, std::vector<ImagePtr> frames,
|
|||||||
if(!setupSize(size, buildMipmaps))
|
if(!setupSize(size, buildMipmaps))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(uint i=0;i<frames.size();++i) {
|
for(const auto &frame: frames) {
|
||||||
m_frames.push_back(new Texture(frames[i], buildMipmaps, compress));
|
m_frames.push_back(new Texture(frame, buildMipmaps, compress));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_framesDelay = framesDelay;
|
m_framesDelay = framesDelay;
|
||||||
|
@ -23,14 +23,16 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <memory.h>
|
|
||||||
#include <zlib.h>
|
|
||||||
#include "apngloader.h"
|
#include "apngloader.h"
|
||||||
#include <iostream>
|
#include <cstdio>
|
||||||
#include <sstream>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1300
|
#if defined(_MSC_VER) && _MSC_VER >= 1300
|
||||||
#define swap16(data) _byteswap_ushort(data)
|
#define swap16(data) _byteswap_ushort(data)
|
||||||
@ -169,7 +171,7 @@ void unpack(z_stream& zstream, unsigned char * dst, unsigned int dst_size, unsig
|
|||||||
{
|
{
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
unsigned char * row = dst;
|
unsigned char * row = dst;
|
||||||
unsigned char * prev_row = NULL;
|
unsigned char * prev_row = nullptr;
|
||||||
|
|
||||||
zstream.next_out = dst;
|
zstream.next_out = dst;
|
||||||
zstream.avail_out = dst_size;
|
zstream.avail_out = dst_size;
|
||||||
@ -609,7 +611,7 @@ int load_apng(std::stringstream& file, struct apng_data *apng)
|
|||||||
pData=(unsigned char *)malloc(zbuf_size);
|
pData=(unsigned char *)malloc(zbuf_size);
|
||||||
pImg1=pOut1;
|
pImg1=pOut1;
|
||||||
pImg2=pOut2;
|
pImg2=pOut2;
|
||||||
frames_delay = NULL;
|
frames_delay = nullptr;
|
||||||
|
|
||||||
/* apng decoding - begin */
|
/* apng decoding - begin */
|
||||||
memset(pOut1, 0, outimg1);
|
memset(pOut1, 0, outimg1);
|
||||||
@ -677,7 +679,7 @@ int load_apng(std::stringstream& file, struct apng_data *apng)
|
|||||||
frames = read32(file);
|
frames = read32(file);
|
||||||
if(frames_delay)
|
if(frames_delay)
|
||||||
free(frames_delay);
|
free(frames_delay);
|
||||||
frames_delay = (unsigned short*)malloc(frames*sizeof(int));
|
frames_delay = (unsigned short*)malloc(frames*sizeof(unsigned short));
|
||||||
loops = read32(file);
|
loops = read32(file);
|
||||||
/*crc = */read32(file);
|
/*crc = */read32(file);
|
||||||
if (pOut1)
|
if (pOut1)
|
||||||
@ -871,7 +873,7 @@ void write_chunk(std::ostream& f, const char* name, unsigned char* data, unsigne
|
|||||||
f.write(name, 4);
|
f.write(name, 4);
|
||||||
crc = crc32(crc, (const Bytef*)name, 4);
|
crc = crc32(crc, (const Bytef*)name, 4);
|
||||||
|
|
||||||
if(data != NULL && length > 0) {
|
if(data != nullptr && length > 0) {
|
||||||
f.write((char*)data, length);
|
f.write((char*)data, length);
|
||||||
crc = crc32(crc, data, length);
|
crc = crc32(crc, data, length);
|
||||||
}
|
}
|
||||||
@ -955,8 +957,17 @@ void save_png(std::stringstream& f, unsigned int width, unsigned int height, int
|
|||||||
unsigned char* zbuf1 = (unsigned char*)malloc(zbuf_size);
|
unsigned char* zbuf1 = (unsigned char*)malloc(zbuf_size);
|
||||||
unsigned char* zbuf2 = (unsigned char*)malloc(zbuf_size);
|
unsigned char* zbuf2 = (unsigned char*)malloc(zbuf_size);
|
||||||
|
|
||||||
if(!row_buf || !sub_row || !up_row || !avg_row || !paeth_row || !zbuf1 || !zbuf2)
|
if(!row_buf || !sub_row || !up_row || !avg_row || !paeth_row || !zbuf1 || !zbuf2) {
|
||||||
|
free(row_buf);
|
||||||
|
free(sub_row);
|
||||||
|
free(up_row);
|
||||||
|
free(avg_row);
|
||||||
|
free(paeth_row);
|
||||||
|
free(zbuf1);
|
||||||
|
free(zbuf2);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
row_buf[0] = 0;
|
row_buf[0] = 0;
|
||||||
sub_row[0] = 1;
|
sub_row[0] = 1;
|
||||||
@ -994,7 +1005,7 @@ void save_png(std::stringstream& f, unsigned int width, unsigned int height, int
|
|||||||
zstream2.next_out = zbuf2;
|
zstream2.next_out = zbuf2;
|
||||||
zstream2.avail_out = zbuf_size;
|
zstream2.avail_out = zbuf_size;
|
||||||
|
|
||||||
prev = NULL;
|
prev = nullptr;
|
||||||
row = pixels;
|
row = pixels;
|
||||||
|
|
||||||
for(j = 0; j < (unsigned int)height; j++) {
|
for(j = 0; j < (unsigned int)height; j++) {
|
||||||
@ -1122,7 +1133,7 @@ void save_png(std::stringstream& f, unsigned int width, unsigned int height, int
|
|||||||
deflateReset(&zstream2);
|
deflateReset(&zstream2);
|
||||||
zstream2.data_type = Z_BINARY;
|
zstream2.data_type = Z_BINARY;
|
||||||
|
|
||||||
write_chunk(f, "IEND", 0, 0);
|
write_chunk(f, "IEND", nullptr, 0);
|
||||||
|
|
||||||
deflateEnd(&zstream1);
|
deflateEnd(&zstream1);
|
||||||
deflateEnd(&zstream2);
|
deflateEnd(&zstream2);
|
||||||
|
@ -298,8 +298,7 @@ std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
|
|||||||
std::vector<std::string> wordsSplit = stdext::split(text);
|
std::vector<std::string> wordsSplit = stdext::split(text);
|
||||||
|
|
||||||
// break huge words into small ones
|
// break huge words into small ones
|
||||||
for(uint i=0;i<wordsSplit.size();++i) {
|
for(const auto &word: wordsSplit) {
|
||||||
const std::string& word = wordsSplit[i];
|
|
||||||
int wordWidth = calculateTextRectSize(word).width();
|
int wordWidth = calculateTextRectSize(word).width();
|
||||||
if(wordWidth > maxWidth) {
|
if(wordWidth > maxWidth) {
|
||||||
std::string newWord;
|
std::string newWord;
|
||||||
@ -324,8 +323,8 @@ std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// compose lines
|
// compose lines
|
||||||
for(uint i=0;i<words.size();++i) {
|
for(const auto &word: words) {
|
||||||
std::string candidate = line + words[i];
|
std::string candidate = line + word;
|
||||||
int candidateWidth = calculateTextRectSize(candidate).width();
|
int candidateWidth = calculateTextRectSize(candidate).width();
|
||||||
|
|
||||||
if(candidateWidth > maxWidth) {
|
if(candidateWidth > maxWidth) {
|
||||||
@ -334,7 +333,7 @@ std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
|
|||||||
line = "";
|
line = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
line += words[i] + " ";
|
line += word + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
outText += line;
|
outText += line;
|
||||||
|
@ -48,7 +48,7 @@ public:
|
|||||||
/// Calculate glyphs positions to use on render, also calculates textBoxSize if wanted
|
/// Calculate glyphs positions to use on render, also calculates textBoxSize if wanted
|
||||||
const std::vector<Point>& calculateGlyphsPositions(const std::string& text,
|
const std::vector<Point>& calculateGlyphsPositions(const std::string& text,
|
||||||
Fw::AlignmentFlag align = Fw::AlignTopLeft,
|
Fw::AlignmentFlag align = Fw::AlignTopLeft,
|
||||||
Size* textBoxSize = NULL);
|
Size* textBoxSize = nullptr);
|
||||||
|
|
||||||
/// Simulate render and calculate text size
|
/// Simulate render and calculate text size
|
||||||
Size calculateTextRectSize(const std::string& text);
|
Size calculateTextRectSize(const std::string& text);
|
||||||
|
@ -34,10 +34,8 @@ CoordsBuffer::CoordsBuffer()
|
|||||||
|
|
||||||
CoordsBuffer::~CoordsBuffer()
|
CoordsBuffer::~CoordsBuffer()
|
||||||
{
|
{
|
||||||
if(m_hardwareVertexArray)
|
delete m_hardwareVertexArray;
|
||||||
delete m_hardwareVertexArray;
|
delete m_hardwareTextureCoordArray;
|
||||||
if(m_hardwareTextureCoordArray)
|
|
||||||
delete m_hardwareTextureCoordArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoordsBuffer::addBoudingRect(const Rect& dest, int innerLineWidth)
|
void CoordsBuffer::addBoudingRect(const Rect& dest, int innerLineWidth)
|
||||||
|
@ -60,7 +60,7 @@ public:
|
|||||||
void drawBoundingRect(const Rect& dest, int innerLineWidth);
|
void drawBoundingRect(const Rect& dest, int innerLineWidth);
|
||||||
|
|
||||||
void setMatrixMode(MatrixMode matrixMode);
|
void setMatrixMode(MatrixMode matrixMode);
|
||||||
void setTransformMatrix(const Matrix3& projectionMatrix);
|
void setTransformMatrix(const Matrix3& transformMatrix);
|
||||||
void setProjectionMatrix(const Matrix3& projectionMatrix);
|
void setProjectionMatrix(const Matrix3& projectionMatrix);
|
||||||
void setTextureMatrix(const Matrix3& textureMatrix);
|
void setTextureMatrix(const Matrix3& textureMatrix);
|
||||||
void setColor(const Color& color);
|
void setColor(const Color& color);
|
||||||
|
@ -165,7 +165,7 @@ void PainterShaderProgram::addMultiTexture(const std::string& file)
|
|||||||
|
|
||||||
void PainterShaderProgram::bindMultiTextures()
|
void PainterShaderProgram::bindMultiTextures()
|
||||||
{
|
{
|
||||||
if(m_multiTextures.size() == 0)
|
if(m_multiTextures.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int i=1;
|
int i=1;
|
||||||
|
@ -54,8 +54,8 @@ void ParticleEffect::load(const ParticleEffectTypePtr& effectType)
|
|||||||
|
|
||||||
void ParticleEffect::render()
|
void ParticleEffect::render()
|
||||||
{
|
{
|
||||||
for(auto it = m_systems.begin(), end = m_systems.end(); it != end; ++it)
|
for(auto &system: m_systems)
|
||||||
(*it)->render();
|
system->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticleEffect::update()
|
void ParticleEffect::update()
|
||||||
|
@ -51,7 +51,7 @@ public:
|
|||||||
ParticleEffect() {}
|
ParticleEffect() {}
|
||||||
|
|
||||||
void load(const ParticleEffectTypePtr& effectType);
|
void load(const ParticleEffectTypePtr& effectType);
|
||||||
bool hasFinished() { return m_systems.size() == 0; }
|
bool hasFinished() { return m_systems.empty(); }
|
||||||
void render();
|
void render();
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ void ParticleSystem::addParticle(const ParticlePtr& particle)
|
|||||||
|
|
||||||
void ParticleSystem::render()
|
void ParticleSystem::render()
|
||||||
{
|
{
|
||||||
for(auto it = m_particles.begin(), end = m_particles.end(); it != end; ++it)
|
for(auto &particle: m_particles)
|
||||||
(*it)->render();
|
particle->render();
|
||||||
g_painter->resetCompositionMode();
|
g_painter->resetCompositionMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ void ParticleType::load(const OTMLNodePtr& node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(pColors.empty())
|
if(pColors.empty())
|
||||||
pColors.push_back(Color(255, 255, 255, 128));
|
pColors.emplace_back(255, 255, 255, 128);
|
||||||
if(pColorsStops.empty())
|
if(pColorsStops.empty())
|
||||||
pColorsStops.push_back(0);
|
pColorsStops.push_back(0);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ bool Shader::compileSourceCode(const std::string& sourceCode)
|
|||||||
std::string code = qualifierDefines;
|
std::string code = qualifierDefines;
|
||||||
code.append(sourceCode);
|
code.append(sourceCode);
|
||||||
const char *c_source = code.c_str();
|
const char *c_source = code.c_str();
|
||||||
glShaderSource(m_shaderId, 1, &c_source, NULL);
|
glShaderSource(m_shaderId, 1, &c_source, nullptr);
|
||||||
glCompileShader(m_shaderId);
|
glCompileShader(m_shaderId);
|
||||||
|
|
||||||
int res = GL_FALSE;
|
int res = GL_FALSE;
|
||||||
@ -95,7 +95,7 @@ std::string Shader::log()
|
|||||||
glGetShaderiv(m_shaderId, GL_INFO_LOG_LENGTH, &infoLogLength);
|
glGetShaderiv(m_shaderId, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||||
if(infoLogLength > 1) {
|
if(infoLogLength > 1) {
|
||||||
std::vector<char> buf(infoLogLength);
|
std::vector<char> buf(infoLogLength);
|
||||||
glGetShaderInfoLog(m_shaderId, infoLogLength-1, NULL, &buf[0]);
|
glGetShaderInfoLog(m_shaderId, infoLogLength-1, nullptr, &buf[0]);
|
||||||
infoLog = &buf[0];
|
infoLog = &buf[0];
|
||||||
}
|
}
|
||||||
return infoLog;
|
return infoLog;
|
||||||
|
@ -129,7 +129,7 @@ std::string ShaderProgram::log()
|
|||||||
glGetProgramiv(m_programId, GL_INFO_LOG_LENGTH, &infoLogLength);
|
glGetProgramiv(m_programId, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||||
if(infoLogLength > 1) {
|
if(infoLogLength > 1) {
|
||||||
std::vector<char> buf(infoLogLength);
|
std::vector<char> buf(infoLogLength);
|
||||||
glGetShaderInfoLog(m_programId, infoLogLength-1, NULL, &buf[0]);
|
glGetShaderInfoLog(m_programId, infoLogLength-1, nullptr, &buf[0]);
|
||||||
infoLog = &buf[0];
|
infoLog = &buf[0];
|
||||||
}
|
}
|
||||||
return infoLog;
|
return infoLog;
|
||||||
|
@ -75,7 +75,7 @@ bool Mouse::pushCursor(const std::string& name)
|
|||||||
|
|
||||||
void Mouse::popCursor(const std::string& name)
|
void Mouse::popCursor(const std::string& name)
|
||||||
{
|
{
|
||||||
if(m_cursorStack.size() == 0)
|
if(m_cursorStack.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(name.empty() || m_cursors.find(name) == m_cursors.end())
|
if(name.empty() || m_cursors.find(name) == m_cursors.end())
|
||||||
@ -93,7 +93,7 @@ void Mouse::popCursor(const std::string& name)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_cursorStack.size() > 0)
|
if(!m_cursorStack.empty())
|
||||||
g_window.setMouseCursor(m_cursorStack.back());
|
g_window.setMouseCursor(m_cursorStack.back());
|
||||||
else
|
else
|
||||||
g_window.restoreMouseCursor();
|
g_window.restoreMouseCursor();
|
||||||
@ -101,7 +101,7 @@ void Mouse::popCursor(const std::string& name)
|
|||||||
|
|
||||||
bool Mouse::isCursorChanged()
|
bool Mouse::isCursorChanged()
|
||||||
{
|
{
|
||||||
return m_cursorStack.size() > 0;
|
return !m_cursorStack.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Mouse::isPressed(Fw::MouseButton mouseButton)
|
bool Mouse::isPressed(Fw::MouseButton mouseButton)
|
||||||
|
@ -122,7 +122,7 @@ union luai_Cast2 { double l_d; LUAI_INT32 l_p[2]; };
|
|||||||
#if !defined(lua_number2unsigned) /* { */
|
#if !defined(lua_number2unsigned) /* { */
|
||||||
/* the following definition assures proper modulo behavior */
|
/* the following definition assures proper modulo behavior */
|
||||||
#if defined(LUA_NUMBER_DOUBLE)
|
#if defined(LUA_NUMBER_DOUBLE)
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
|
#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
|
||||||
#define lua_number2unsigned(i,n) \
|
#define lua_number2unsigned(i,n) \
|
||||||
((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
|
((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
|
||||||
@ -365,7 +365,7 @@ static const luaL_Reg bitlib[] = {
|
|||||||
{"replace", b_replace},
|
{"replace", b_replace},
|
||||||
{"rrotate", b_rrot},
|
{"rrotate", b_rrot},
|
||||||
{"rshift", b_rshift},
|
{"rshift", b_rshift},
|
||||||
{NULL, NULL}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
int luaopen_bit32 (lua_State *L) {
|
int luaopen_bit32 (lua_State *L) {
|
||||||
|
@ -707,7 +707,7 @@ void LuaInterface::closeLuaState()
|
|||||||
if(L) {
|
if(L) {
|
||||||
// close lua, it also collects
|
// close lua, it also collects
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
L = NULL;
|
L = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -785,7 +785,7 @@ int LuaInterface::weakRef()
|
|||||||
|
|
||||||
void LuaInterface::unref(int ref)
|
void LuaInterface::unref(int ref)
|
||||||
{
|
{
|
||||||
if(ref >= 0 && L != NULL)
|
if(ref >= 0 && L != nullptr)
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, ref);
|
luaL_unref(L, LUA_REGISTRYINDEX, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,9 @@
|
|||||||
|
|
||||||
#include <framework/core/application.h>
|
#include <framework/core/application.h>
|
||||||
#include <framework/core/eventdispatcher.h>
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
asio::io_service g_ioService;
|
asio::io_service g_ioService;
|
||||||
std::list<std::shared_ptr<asio::streambuf>> Connection::m_outputStreams;
|
std::list<std::shared_ptr<asio::streambuf>> Connection::m_outputStreams;
|
||||||
@ -123,7 +125,7 @@ void Connection::write(uint8* buffer, size_t size)
|
|||||||
m_outputStream = m_outputStreams.front();
|
m_outputStream = m_outputStreams.front();
|
||||||
m_outputStreams.pop_front();
|
m_outputStreams.pop_front();
|
||||||
} else
|
} else
|
||||||
m_outputStream = std::shared_ptr<asio::streambuf>(new asio::streambuf);
|
m_outputStream = std::make_shared<asio::streambuf>();
|
||||||
|
|
||||||
m_delayedWriteTimer.cancel();
|
m_delayedWriteTimer.cancel();
|
||||||
m_delayedWriteTimer.expires_from_now(boost::posix_time::milliseconds(0));
|
m_delayedWriteTimer.expires_from_now(boost::posix_time::milliseconds(0));
|
||||||
@ -177,7 +179,7 @@ void Connection::read_until(const std::string& what, const RecvCallback& callbac
|
|||||||
|
|
||||||
asio::async_read_until(m_socket,
|
asio::async_read_until(m_socket,
|
||||||
m_inputStream,
|
m_inputStream,
|
||||||
what.c_str(),
|
what,
|
||||||
std::bind(&Connection::onRecv, asConnection(), std::placeholders::_1, std::placeholders::_2));
|
std::bind(&Connection::onRecv, asConnection(), std::placeholders::_1, std::placeholders::_2));
|
||||||
|
|
||||||
m_readTimer.cancel();
|
m_readTimer.cancel();
|
||||||
|
@ -144,7 +144,7 @@ void Protocol::internalRecvData(uint8* buffer, uint16 size)
|
|||||||
|
|
||||||
void Protocol::generateXteaKey()
|
void Protocol::generateXteaKey()
|
||||||
{
|
{
|
||||||
std::mt19937 eng(std::time(NULL));
|
std::mt19937 eng(std::time(nullptr));
|
||||||
std::uniform_int_distribution<uint32> unif(0, 0xFFFFFFFF);
|
std::uniform_int_distribution<uint32> unif(0, 0xFFFFFFFF);
|
||||||
m_xteaKey[0] = unif(eng);
|
m_xteaKey[0] = unif(eng);
|
||||||
m_xteaKey[1] = unif(eng);
|
m_xteaKey[1] = unif(eng);
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
OTMLParser::OTMLParser(OTMLDocumentPtr doc, std::istream& in) :
|
OTMLParser::OTMLParser(OTMLDocumentPtr doc, std::istream& in) :
|
||||||
currentDepth(0), currentLine(0),
|
currentDepth(0), currentLine(0),
|
||||||
doc(doc), currentParent(doc), previousNode(0),
|
doc(doc), currentParent(doc), previousNode(nullptr),
|
||||||
in(in)
|
in(in)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -150,8 +150,8 @@ void PlatformWindow::releaseAllKeys()
|
|||||||
|
|
||||||
m_inputEvent.keyboardModifiers = 0;
|
m_inputEvent.keyboardModifiers = 0;
|
||||||
|
|
||||||
for(int i=0;i<4;++i)
|
for(auto &mouseButtonState: m_mouseButtonStates)
|
||||||
m_mouseButtonStates[i] = false;
|
mouseButtonState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformWindow::fireKeysPress()
|
void PlatformWindow::fireKeysPress()
|
||||||
|
@ -30,9 +30,9 @@
|
|||||||
#define __USE_GNU
|
#define __USE_GNU
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <csignal>
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#include <ucontext.h>
|
#include <ucontext.h>
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#define MAX_BACKTRACE_DEPTH 128
|
#define MAX_BACKTRACE_DEPTH 128
|
||||||
#define DEMANGLE_BACKTRACE_SYMBOLS
|
#define DEMANGLE_BACKTRACE_SYMBOLS
|
||||||
@ -129,10 +129,10 @@ void installCrashHandler()
|
|||||||
sigemptyset (&sa.sa_mask);
|
sigemptyset (&sa.sa_mask);
|
||||||
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||||
|
|
||||||
sigaction(SIGILL, &sa, NULL); // illegal instruction
|
sigaction(SIGILL, &sa, nullptr); // illegal instruction
|
||||||
sigaction(SIGSEGV, &sa, NULL); // segmentation fault
|
sigaction(SIGSEGV, &sa, nullptr); // segmentation fault
|
||||||
sigaction(SIGFPE, &sa, NULL); // floating-point exception
|
sigaction(SIGFPE, &sa, nullptr); // floating-point exception
|
||||||
sigaction(SIGABRT, &sa, NULL); // process aborted (asserts)
|
sigaction(SIGABRT, &sa, nullptr); // process aborted (asserts)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -23,9 +23,9 @@
|
|||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
|
||||||
#include <framework/stdext/stdext.h>
|
#include <framework/stdext/stdext.h>
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -51,7 +51,7 @@ bool Platform::spawnProcess(std::string process, const std::vector<std::string>&
|
|||||||
cargs[0] = (char*)process.c_str();
|
cargs[0] = (char*)process.c_str();
|
||||||
for(uint i=1;i<=args.size();++i)
|
for(uint i=1;i<=args.size();++i)
|
||||||
cargs[i] = (char*)args[i-1].c_str();
|
cargs[i] = (char*)args[i-1].c_str();
|
||||||
cargs[args.size()+1] = 0;
|
cargs[args.size()+1] = nullptr;
|
||||||
|
|
||||||
if(execv(process.c_str(), cargs) == -1)
|
if(execv(process.c_str(), cargs) == -1)
|
||||||
_exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
@ -84,7 +84,7 @@ std::string Platform::getCurrentDir()
|
|||||||
{
|
{
|
||||||
std::string res;
|
std::string res;
|
||||||
char cwd[2048];
|
char cwd[2048];
|
||||||
if(getcwd(cwd, sizeof(cwd)) != NULL) {
|
if(getcwd(cwd, sizeof(cwd)) != nullptr) {
|
||||||
res = cwd;
|
res = cwd;
|
||||||
res += "/";
|
res += "/";
|
||||||
}
|
}
|
||||||
|
@ -31,15 +31,15 @@
|
|||||||
|
|
||||||
X11Window::X11Window()
|
X11Window::X11Window()
|
||||||
{
|
{
|
||||||
m_display = 0;
|
m_display = nullptr;
|
||||||
m_visual = 0;
|
m_visual = nullptr;
|
||||||
m_window = 0;
|
m_window = 0;
|
||||||
m_rootWindow = 0;
|
m_rootWindow = 0;
|
||||||
m_colormap = 0;
|
m_colormap = 0;
|
||||||
m_cursor = 0;
|
m_cursor = 0;
|
||||||
m_hiddenCursor = 0;
|
m_hiddenCursor = 0;
|
||||||
m_xim = 0;
|
m_xim = nullptr;
|
||||||
m_xic = 0;
|
m_xic = nullptr;
|
||||||
m_screen = 0;
|
m_screen = 0;
|
||||||
m_wmDelete = 0;
|
m_wmDelete = 0;
|
||||||
m_minimumSize = Size(600,480);
|
m_minimumSize = Size(600,480);
|
||||||
@ -51,8 +51,8 @@ X11Window::X11Window()
|
|||||||
m_eglDisplay = 0;
|
m_eglDisplay = 0;
|
||||||
m_eglSurface = 0;
|
m_eglSurface = 0;
|
||||||
#else
|
#else
|
||||||
m_fbConfig = 0;
|
m_fbConfig = nullptr;
|
||||||
m_glxContext = 0;
|
m_glxContext = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_keyMap[XK_Escape] = Fw::KeyEscape;
|
m_keyMap[XK_Escape] = Fw::KeyEscape;
|
||||||
@ -247,22 +247,22 @@ void X11Window::terminate()
|
|||||||
|
|
||||||
if(m_visual) {
|
if(m_visual) {
|
||||||
XFree(m_visual);
|
XFree(m_visual);
|
||||||
m_visual = 0;
|
m_visual = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_xic) {
|
if(m_xic) {
|
||||||
XDestroyIC(m_xic);
|
XDestroyIC(m_xic);
|
||||||
m_xic = 0;
|
m_xic = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_xim) {
|
if(m_xim) {
|
||||||
XCloseIM(m_xim);
|
XCloseIM(m_xim);
|
||||||
m_xim = 0;
|
m_xim = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_display) {
|
if(m_display) {
|
||||||
XCloseDisplay(m_display);
|
XCloseDisplay(m_display);
|
||||||
m_display = 0;
|
m_display = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_visible = false;
|
m_visible = false;
|
||||||
@ -270,7 +270,7 @@ void X11Window::terminate()
|
|||||||
|
|
||||||
void X11Window::internalOpenDisplay()
|
void X11Window::internalOpenDisplay()
|
||||||
{
|
{
|
||||||
m_display = XOpenDisplay(NULL);
|
m_display = XOpenDisplay(nullptr);
|
||||||
if(!m_display)
|
if(!m_display)
|
||||||
g_logger.fatal("Unable to open X11 display");
|
g_logger.fatal("Unable to open X11 display");
|
||||||
m_screen = DefaultScreen(m_display);
|
m_screen = DefaultScreen(m_display);
|
||||||
@ -343,7 +343,7 @@ bool X11Window::internalSetupWindowInput()
|
|||||||
}
|
}
|
||||||
|
|
||||||
XSetLocaleModifiers("");
|
XSetLocaleModifiers("");
|
||||||
m_xim = XOpenIM(m_display, NULL, NULL, NULL);
|
m_xim = XOpenIM(m_display, nullptr, nullptr, nullptr);
|
||||||
if(!m_xim) {
|
if(!m_xim) {
|
||||||
g_logger.error("XOpenIM failed");
|
g_logger.error("XOpenIM failed");
|
||||||
return false;
|
return false;
|
||||||
@ -368,7 +368,7 @@ void X11Window::internalCheckGL()
|
|||||||
if(!eglInitialize(m_eglDisplay, NULL, NULL))
|
if(!eglInitialize(m_eglDisplay, NULL, NULL))
|
||||||
g_logger.fatal("Unable to initialize EGL");
|
g_logger.fatal("Unable to initialize EGL");
|
||||||
#else
|
#else
|
||||||
if(!glXQueryExtension(m_display, NULL, NULL))
|
if(!glXQueryExtension(m_display, nullptr, nullptr))
|
||||||
g_logger.fatal("GLX not supported");
|
g_logger.fatal("GLX not supported");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -450,7 +450,7 @@ void X11Window::internalCreateGLContext()
|
|||||||
if(m_eglContext == EGL_NO_CONTEXT )
|
if(m_eglContext == EGL_NO_CONTEXT )
|
||||||
g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError()));
|
g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError()));
|
||||||
#else
|
#else
|
||||||
m_glxContext = glXCreateContext(m_display, m_visual, NULL, True);
|
m_glxContext = glXCreateContext(m_display, m_visual, nullptr, True);
|
||||||
|
|
||||||
if(!m_glxContext)
|
if(!m_glxContext)
|
||||||
g_logger.fatal("Unable to create GLX context");
|
g_logger.fatal("Unable to create GLX context");
|
||||||
@ -477,9 +477,9 @@ void X11Window::internalDestroyGLContext()
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if(m_glxContext) {
|
if(m_glxContext) {
|
||||||
glXMakeCurrent(m_display, None, NULL);
|
glXMakeCurrent(m_display, None, nullptr);
|
||||||
glXDestroyContext(m_display, m_glxContext);
|
glXDestroyContext(m_display, m_glxContext);
|
||||||
m_glxContext = 0;
|
m_glxContext = nullptr;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -606,7 +606,7 @@ void X11Window::poll()
|
|||||||
// lookup keysym and translate it
|
// lookup keysym and translate it
|
||||||
KeySym keysym;
|
KeySym keysym;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
XLookupString(&xkey, buf, sizeof(buf), &keysym, 0);
|
XLookupString(&xkey, buf, sizeof(buf), &keysym, nullptr);
|
||||||
Fw::Key keyCode = Fw::KeyUnknown;
|
Fw::Key keyCode = Fw::KeyUnknown;
|
||||||
|
|
||||||
if(m_keyMap.find(keysym) != m_keyMap.end())
|
if(m_keyMap.find(keysym) != m_keyMap.end())
|
||||||
@ -651,7 +651,7 @@ void X11Window::poll()
|
|||||||
Atom wmStateMaximizedHorz = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
|
Atom wmStateMaximizedHorz = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
|
||||||
Atom actualType;
|
Atom actualType;
|
||||||
ulong i, numItems, bytesAfter;
|
ulong i, numItems, bytesAfter;
|
||||||
uchar *propertyValue = NULL;
|
uchar *propertyValue = nullptr;
|
||||||
int actualFormat;
|
int actualFormat;
|
||||||
|
|
||||||
if(XGetWindowProperty(m_display, m_window, wmState,
|
if(XGetWindowProperty(m_display, m_window, wmState,
|
||||||
@ -740,7 +740,7 @@ void X11Window::poll()
|
|||||||
Status status;
|
Status status;
|
||||||
len = XmbLookupString(m_xic, &event.xkey, buf, sizeof(buf), &keysym, &status);
|
len = XmbLookupString(m_xic, &event.xkey, buf, sizeof(buf), &keysym, &status);
|
||||||
} else { // otherwise use XLookupString, but often it doesn't work right with dead keys
|
} else { // otherwise use XLookupString, but often it doesn't work right with dead keys
|
||||||
static XComposeStatus compose = {NULL, 0};
|
static XComposeStatus compose = {nullptr, 0};
|
||||||
len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, &compose);
|
len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, &compose);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -972,7 +972,7 @@ void X11Window::setVerticalSync(bool enable)
|
|||||||
//TODO
|
//TODO
|
||||||
#else
|
#else
|
||||||
typedef GLint (*glSwapIntervalProc)(GLint);
|
typedef GLint (*glSwapIntervalProc)(GLint);
|
||||||
glSwapIntervalProc glSwapInterval = NULL;
|
glSwapIntervalProc glSwapInterval = nullptr;
|
||||||
|
|
||||||
if(isExtensionSupported("GLX_MESA_swap_control"))
|
if(isExtensionSupported("GLX_MESA_swap_control"))
|
||||||
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalMESA");
|
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalMESA");
|
||||||
|
@ -35,7 +35,7 @@ OggSoundFile::~OggSoundFile()
|
|||||||
bool OggSoundFile::prepareOgg()
|
bool OggSoundFile::prepareOgg()
|
||||||
{
|
{
|
||||||
ov_callbacks callbacks = { cb_read, cb_seek, cb_close, cb_tell };
|
ov_callbacks callbacks = { cb_read, cb_seek, cb_close, cb_tell };
|
||||||
ov_open_callbacks(m_file.get(), &m_vorbisFile, 0, 0, callbacks);
|
ov_open_callbacks(m_file.get(), &m_vorbisFile, nullptr, 0, callbacks);
|
||||||
|
|
||||||
vorbis_info* vi = ov_info(&m_vorbisFile, -1);
|
vorbis_info* vi = ov_info(&m_vorbisFile, -1);
|
||||||
if(!vi) {
|
if(!vi) {
|
||||||
|
@ -37,13 +37,13 @@ SoundManager g_sounds;
|
|||||||
|
|
||||||
void SoundManager::init()
|
void SoundManager::init()
|
||||||
{
|
{
|
||||||
m_device = alcOpenDevice(NULL);
|
m_device = alcOpenDevice(nullptr);
|
||||||
if(!m_device) {
|
if(!m_device) {
|
||||||
g_logger.error("unable to open audio device");
|
g_logger.error("unable to open audio device");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_context = alcCreateContext(m_device, NULL);
|
m_context = alcCreateContext(m_device, nullptr);
|
||||||
if(!m_context) {
|
if(!m_context) {
|
||||||
g_logger.error(stdext::format("unable to create audio context: %s", alcGetString(m_device, alcGetError(m_device))));
|
g_logger.error(stdext::format("unable to create audio context: %s", alcGetString(m_device, alcGetError(m_device))));
|
||||||
return;
|
return;
|
||||||
@ -59,8 +59,8 @@ void SoundManager::terminate()
|
|||||||
{
|
{
|
||||||
ensureContext();
|
ensureContext();
|
||||||
|
|
||||||
for(auto it = m_streamFiles.begin(); it != m_streamFiles.end();++it) {
|
for(auto &streamFile: m_streamFiles) {
|
||||||
auto& future = it->second;
|
auto& future = streamFile.second;
|
||||||
future.wait();
|
future.wait();
|
||||||
}
|
}
|
||||||
m_streamFiles.clear();
|
m_streamFiles.clear();
|
||||||
|
@ -52,7 +52,7 @@ public:
|
|||||||
any() : content(nullptr) { }
|
any() : content(nullptr) { }
|
||||||
any(const any& other) : content(other.content ? other.content->clone() : nullptr) { }
|
any(const any& other) : content(other.content ? other.content->clone() : nullptr) { }
|
||||||
template<typename T> any(const T& value) : content(new holder<T>(value)) { }
|
template<typename T> any(const T& value) : content(new holder<T>(value)) { }
|
||||||
~any() { if(content) delete content; }
|
~any() { delete content; }
|
||||||
|
|
||||||
any& swap(any& rhs) { std::swap(content, rhs.content); return *this; }
|
any& swap(any& rhs) { std::swap(content, rhs.content); return *this; }
|
||||||
|
|
||||||
|
@ -44,20 +44,21 @@ namespace stdext {
|
|||||||
|
|
||||||
const char* demangle_name(const char* name)
|
const char* demangle_name(const char* name)
|
||||||
{
|
{
|
||||||
|
static const unsigned BufferSize = 1024;
|
||||||
|
static char Buffer[1024] = {};
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
static char buffer[1024];
|
UnDecorateSymbolName(name, Buffer, BufferSize, UNDNAME_COMPLETE);
|
||||||
UnDecorateSymbolName(name, buffer, sizeof(buffer), UNDNAME_COMPLETE);
|
return Buffer;
|
||||||
return buffer;
|
|
||||||
#else
|
#else
|
||||||
size_t len;
|
size_t len;
|
||||||
int status;
|
int status;
|
||||||
static char buffer[1024];
|
char* demangled = abi::__cxa_demangle(name, nullptr, &len, &status);
|
||||||
char* demangled = abi::__cxa_demangle(name, 0, &len, &status);
|
|
||||||
if(demangled) {
|
if(demangled) {
|
||||||
strcpy(buffer, demangled);
|
strncpy(Buffer, demangled, BufferSize);
|
||||||
free(demangled);
|
free(demangled);
|
||||||
}
|
}
|
||||||
return buffer;
|
return Buffer;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,4 +66,4 @@ double round(double r)
|
|||||||
return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
|
return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class packed_storage {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
packed_storage() : m_values(nullptr), m_size(0) { }
|
packed_storage() : m_values(nullptr), m_size(0) { }
|
||||||
~packed_storage() { if(m_values) delete[] m_values; }
|
~packed_storage() { delete[] m_values; }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void set(Key id, const T& value) {
|
void set(Key id, const T& value) {
|
||||||
|
@ -46,7 +46,7 @@ public:
|
|||||||
template <class InputIterator>
|
template <class InputIterator>
|
||||||
packed_vector(InputIterator first, InputIterator last) : m_size(last - first), m_data(new T[m_size]) { std::copy(first, last, m_data); }
|
packed_vector(InputIterator first, InputIterator last) : m_size(last - first), m_data(new T[m_size]) { std::copy(first, last, m_data); }
|
||||||
packed_vector(const packed_vector<T>& other) : m_size(other.m_size), m_data(new T[other.m_size]) { std::copy(other.begin(), other.end(), m_data); }
|
packed_vector(const packed_vector<T>& other) : m_size(other.m_size), m_data(new T[other.m_size]) { std::copy(other.begin(), other.end(), m_data); }
|
||||||
~packed_vector() { if(m_data) delete[] m_data; }
|
~packed_vector() { delete[] m_data; }
|
||||||
|
|
||||||
packed_vector<T,U>& operator=(packed_vector<T,U> other) { other.swap(*this); return *this; }
|
packed_vector<T,U>& operator=(packed_vector<T,U> other) { other.swap(*this); return *this; }
|
||||||
|
|
||||||
|
@ -23,22 +23,22 @@
|
|||||||
#ifndef STDEXT_H
|
#ifndef STDEXT_H
|
||||||
#define STDEXT_H
|
#define STDEXT_H
|
||||||
|
|
||||||
#include "compiler.h"
|
#include "any.h"
|
||||||
#include "dumper.h"
|
#include "boolean.h"
|
||||||
#include "types.h"
|
|
||||||
#include "exception.h"
|
|
||||||
#include "demangle.h"
|
|
||||||
#include "cast.h"
|
#include "cast.h"
|
||||||
|
#include "compiler.h"
|
||||||
|
#include "demangle.h"
|
||||||
|
#include "dumper.h"
|
||||||
|
#include "dynamic_storage.h"
|
||||||
|
#include "exception.h"
|
||||||
|
#include "format.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
#include "packed_any.h"
|
||||||
|
#include "packed_storage.h"
|
||||||
|
#include "packed_vector.h"
|
||||||
|
#include "shared_object.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include "boolean.h"
|
#include "types.h"
|
||||||
#include "shared_object.h"
|
|
||||||
#include "any.h"
|
|
||||||
#include "packed_any.h"
|
|
||||||
#include "dynamic_storage.h"
|
|
||||||
#include "packed_storage.h"
|
|
||||||
#include "format.h"
|
|
||||||
#include "packed_vector.h"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "format.h"
|
#include "format.h"
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <ctype.h>
|
#include <cctype>
|
||||||
#include <physfs.h>
|
#include <physfs.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@ -30,7 +31,7 @@ namespace stdext {
|
|||||||
const static auto startup_time = std::chrono::high_resolution_clock::now();
|
const static auto startup_time = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
ticks_t time() {
|
ticks_t time() {
|
||||||
return std::time(NULL);
|
return std::time(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ticks_t millis()
|
ticks_t millis()
|
||||||
|
@ -50,8 +50,8 @@ void UIParticles::drawSelf(Fw::DrawPane drawPane)
|
|||||||
else
|
else
|
||||||
g_painter->translate(m_rect.x() + m_referencePos.x * m_rect.width(), m_rect.y() + m_referencePos.y * m_rect.height());
|
g_painter->translate(m_rect.x() + m_referencePos.x * m_rect.width(), m_rect.y() + m_referencePos.y * m_rect.height());
|
||||||
|
|
||||||
for(auto it = m_effects.begin(), end = m_effects.end(); it != end; ++it)
|
for(auto &effect: m_effects)
|
||||||
(*it)->render();
|
effect->render();
|
||||||
g_painter->restoreSavedState();
|
g_painter->restoreSavedState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -397,9 +397,9 @@ void UITextEdit::appendText(std::string text)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// only ignore text append if it contains invalid characters
|
// only ignore text append if it contains invalid characters
|
||||||
if(m_validCharacters.size() > 0) {
|
if(!m_validCharacters.empty()) {
|
||||||
for(uint i = 0; i < text.size(); ++i) {
|
for(char i: text) {
|
||||||
if(m_validCharacters.find(text[i]) == std::string::npos)
|
if(m_validCharacters.find(i) == std::string::npos)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -424,7 +424,7 @@ void UITextEdit::appendCharacter(char c)
|
|||||||
if(m_maxLength > 0 && m_text.length() + 1 > m_maxLength)
|
if(m_maxLength > 0 && m_text.length() + 1 > m_maxLength)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(m_validCharacters.size() > 0 && m_validCharacters.find(c) == std::string::npos)
|
if(!m_validCharacters.empty() && m_validCharacters.find(c) == std::string::npos)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
|
@ -103,7 +103,7 @@ protected:
|
|||||||
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||||
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
||||||
virtual bool onDoubleClick(const Point& mousePos);
|
virtual bool onDoubleClick(const Point& mousePos);
|
||||||
virtual void onTextAreaUpdate(const Point& vitualOffset, const Size& virtualSize, const Size& totalSize);
|
virtual void onTextAreaUpdate(const Point& vitualOffset, const Size& visibleSize, const Size& totalSize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void disableUpdates() { m_updatesEnabled = false; }
|
void disableUpdates() { m_updatesEnabled = false; }
|
||||||
|
@ -70,7 +70,7 @@ void UIWidget::draw(const Rect& visibleRect, Fw::DrawPane drawPane)
|
|||||||
|
|
||||||
drawSelf(drawPane);
|
drawSelf(drawPane);
|
||||||
|
|
||||||
if(m_children.size() > 0) {
|
if(!m_children.empty()) {
|
||||||
if(m_clipping)
|
if(m_clipping)
|
||||||
g_painter->setClipRect(visibleRect.intersection(getPaddingRect()));
|
g_painter->setClipRect(visibleRect.intersection(getPaddingRect()));
|
||||||
|
|
||||||
@ -488,7 +488,7 @@ void UIWidget::unlockChild(const UIWidgetPtr& child)
|
|||||||
|
|
||||||
// find new child to lock
|
// find new child to lock
|
||||||
UIWidgetPtr lockedChild;
|
UIWidgetPtr lockedChild;
|
||||||
if(m_lockedChildren.size() > 0) {
|
if(!m_lockedChildren.empty()) {
|
||||||
lockedChild = m_lockedChildren.front();
|
lockedChild = m_lockedChildren.front();
|
||||||
assert(hasChild(lockedChild));
|
assert(hasChild(lockedChild));
|
||||||
}
|
}
|
||||||
@ -1043,8 +1043,8 @@ bool UIWidget::hasChild(const UIWidgetPtr& child)
|
|||||||
int UIWidget::getChildIndex(const UIWidgetPtr& child)
|
int UIWidget::getChildIndex(const UIWidgetPtr& child)
|
||||||
{
|
{
|
||||||
int index = 1;
|
int index = 1;
|
||||||
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
for(auto &it: m_children) {
|
||||||
if(*it == child)
|
if(it == child)
|
||||||
return index;
|
return index;
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
@ -1713,8 +1713,7 @@ bool UIWidget::propagateOnMouseEvent(const Point& mousePos, UIWidgetList& widget
|
|||||||
bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved, UIWidgetList& widgetList)
|
bool UIWidget::propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved, UIWidgetList& widgetList)
|
||||||
{
|
{
|
||||||
if(containsPaddingPoint(mousePos)) {
|
if(containsPaddingPoint(mousePos)) {
|
||||||
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
for(auto &child: m_children) {
|
||||||
const UIWidgetPtr& child = *it;
|
|
||||||
if(child->isExplicitlyVisible() && child->isExplicitlyEnabled() && child->containsPoint(mousePos))
|
if(child->isExplicitlyVisible() && child->isExplicitlyEnabled() && child->containsPoint(mousePos))
|
||||||
child->propagateOnMouseMove(mousePos, mouseMoved, widgetList);
|
child->propagateOnMouseMove(mousePos, mouseMoved, widgetList);
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ public:
|
|||||||
bool isClipping() { return m_clipping; }
|
bool isClipping() { return m_clipping; }
|
||||||
bool isDestroyed() { return m_destroyed; }
|
bool isDestroyed() { return m_destroyed; }
|
||||||
|
|
||||||
bool hasChildren() { return m_children.size() > 0; }
|
bool hasChildren() { return !m_children.empty(); }
|
||||||
bool containsMarginPoint(const Point& point) { return getMarginRect().contains(point); }
|
bool containsMarginPoint(const Point& point) { return getMarginRect().contains(point); }
|
||||||
bool containsPaddingPoint(const Point& point) { return getPaddingRect().contains(point); }
|
bool containsPaddingPoint(const Point& point) { return getPaddingRect().contains(point); }
|
||||||
bool containsPoint(const Point& point) { return m_rect.contains(point); }
|
bool containsPoint(const Point& point) { return m_rect.contains(point); }
|
||||||
|
@ -32,8 +32,7 @@ public:
|
|||||||
m_capacity(res),
|
m_capacity(res),
|
||||||
m_buffer(new T[m_capacity]) { }
|
m_buffer(new T[m_capacity]) { }
|
||||||
~DataBuffer() {
|
~DataBuffer() {
|
||||||
if(m_buffer)
|
delete[] m_buffer;
|
||||||
delete[] m_buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void reset() { m_size = 0; }
|
inline void reset() { m_size = 0; }
|
||||||
@ -59,8 +58,8 @@ public:
|
|||||||
T *buffer = new T[n];
|
T *buffer = new T[n];
|
||||||
for(uint i=0;i<m_size;++i)
|
for(uint i=0;i<m_size;++i)
|
||||||
buffer[i] = m_buffer[i];
|
buffer[i] = m_buffer[i];
|
||||||
if(m_buffer)
|
|
||||||
delete[] m_buffer;
|
delete[] m_buffer;
|
||||||
m_buffer = buffer;
|
m_buffer = buffer;
|
||||||
m_capacity = n;
|
m_capacity = n;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user