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) {
|
||||
int minimum = fin->getU32();
|
||||
int maximum = fin->getU32();
|
||||
m_phaseDurations.push_back(std::make_tuple(minimum, maximum));
|
||||
m_phaseDurations.emplace_back(minimum, maximum);
|
||||
}
|
||||
|
||||
m_phase = getStartPhase();
|
||||
|
@ -133,7 +133,7 @@ public:
|
||||
const std::vector<CreatureTypePtr>& getCreatures() { return m_creatures; }
|
||||
|
||||
protected:
|
||||
void internalLoadCreatureBuffer(TiXmlElement* elem, const CreatureTypePtr& m);
|
||||
void internalLoadCreatureBuffer(TiXmlElement* attrib, const CreatureTypePtr& m);
|
||||
|
||||
private:
|
||||
std::vector<CreatureTypePtr> m_creatures;
|
||||
|
@ -686,7 +686,7 @@ void Game::autoWalk(std::vector<Otc::Direction> dirs)
|
||||
return;
|
||||
}
|
||||
|
||||
if(dirs.size() == 0)
|
||||
if(dirs.empty())
|
||||
return;
|
||||
|
||||
// must cancel follow before any new walk
|
||||
@ -1715,10 +1715,10 @@ std::string Game::formatCreatureName(const std::string& name)
|
||||
std::string formatedName = name;
|
||||
if(getFeature(Otc::GameFormatCreatureName) && name.length() > 0) {
|
||||
bool upnext = true;
|
||||
for(uint i=0;i<formatedName.length();++i) {
|
||||
char ch = formatedName[i];
|
||||
for(char &i: formatedName) {
|
||||
char ch = i;
|
||||
if(upnext) {
|
||||
formatedName[i] = stdext::upchar(ch);
|
||||
i = stdext::upchar(ch);
|
||||
upnext = false;
|
||||
}
|
||||
if(ch == ' ')
|
||||
|
@ -70,7 +70,7 @@ private:
|
||||
void resetGameStates();
|
||||
|
||||
protected:
|
||||
void processConnectionError(const boost::system::error_code& error);
|
||||
void processConnectionError(const boost::system::error_code& ec);
|
||||
void processDisconnect();
|
||||
void processPing();
|
||||
void processPingBack();
|
||||
@ -178,7 +178,7 @@ public:
|
||||
void moveToParentContainer(const ThingPtr& thing, int count);
|
||||
void rotate(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 useInventoryItemWith(int itemId, const ThingPtr& toThing);
|
||||
ItemPtr findItemInContainers(uint itemId, int subType);
|
||||
@ -241,7 +241,7 @@ public:
|
||||
// pvp related
|
||||
void setUnjustifiedPoints(UnjustifiedPoints unjustifiedPoints);
|
||||
UnjustifiedPoints getUnjustifiedPoints() { return m_unjustifiedPoints; };
|
||||
void setOpenPvpSituations(int openPvpSitations);
|
||||
void setOpenPvpSituations(int openPvpSituations);
|
||||
int getOpenPvpSituations() { return m_openPvpSituations; }
|
||||
|
||||
// npc trade related
|
||||
@ -345,7 +345,7 @@ public:
|
||||
std::string getCharacterName() { return m_characterName; }
|
||||
std::string getWorldName() { return m_worldName; }
|
||||
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; }
|
||||
|
||||
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.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();
|
||||
if(prevSource.center == center && prevSource.color == color && prevSource.radius == radius)
|
||||
return;
|
||||
|
@ -192,7 +192,7 @@ public:
|
||||
// tile zone related
|
||||
void setShowZone(tileflags_t zone, 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; }
|
||||
|
||||
float getZoneOpacity() { return m_zoneOpacity; }
|
||||
|
@ -378,11 +378,11 @@ void MapView::updateVisibleTilesCache(int start)
|
||||
Rect(tpx, tpy + 1, 1, qs),
|
||||
};
|
||||
|
||||
for(int i=0;i<4;++i) {
|
||||
int sx = std::max<int>(lines[i].left(), area.left());
|
||||
int ex = std::min<int>(lines[i].right(), area.right());
|
||||
int sy = std::max<int>(lines[i].top(), area.top());
|
||||
int ey = std::min<int>(lines[i].bottom(), area.bottom());
|
||||
for(auto &line: lines) {
|
||||
int sx = std::max<int>(line.left(), area.left());
|
||||
int ex = std::min<int>(line.right(), area.right());
|
||||
int sy = std::max<int>(line.top(), area.top());
|
||||
int ey = std::min<int>(line.bottom(), area.bottom());
|
||||
for(int qx=sx;qx<=ex;++qx)
|
||||
for(int qy=sy;qy<=ey;++qy)
|
||||
m_spiral[count++] = Point(qx, qy);
|
||||
|
@ -55,12 +55,12 @@ public:
|
||||
void sendTurnSouth();
|
||||
void sendTurnWest();
|
||||
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 sendBuyItem(int itemId, int subType, int amount, bool ignoreCapacity, bool buyWithBackpack);
|
||||
void sendSellItem(int itemId, int subType, int amount, bool ignoreEquipped);
|
||||
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 sendAcceptTrade();
|
||||
void sendRejectTrade();
|
||||
@ -118,7 +118,7 @@ public:
|
||||
void sendRequestStoreOffers(const std::string& categoryName, int serviceType);
|
||||
void sendOpenStore(int serviceType, const std::string &category);
|
||||
void sendTransferCoins(const std::string& recipient, int amount);
|
||||
void sendOpenTransactionHistory(int entiresPerPage);
|
||||
void sendOpenTransactionHistory(int entriesPerPage);
|
||||
|
||||
// otclient only
|
||||
void sendChangeMapAwareRange(int xrange, int yrange);
|
||||
|
@ -1000,7 +1000,7 @@ void ProtocolGame::parseOpenNpcTrade(const InputMessagePtr& msg)
|
||||
int weight = msg->getU32();
|
||||
int buyPrice = 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);
|
||||
@ -1026,7 +1026,7 @@ void ProtocolGame::parsePlayerGoods(const InputMessagePtr& msg)
|
||||
else
|
||||
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);
|
||||
@ -1571,7 +1571,7 @@ void ProtocolGame::parseChannelList(const InputMessagePtr& msg)
|
||||
for(int i = 0; i < count; i++) {
|
||||
int id = msg->getU16();
|
||||
std::string name = msg->getString();
|
||||
channelList.push_back(std::make_tuple(id, name));
|
||||
channelList.emplace_back(id, name);
|
||||
}
|
||||
|
||||
g_game.processChannelList(channelList);
|
||||
@ -1785,7 +1785,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg)
|
||||
std::string outfitName = msg->getString();
|
||||
int outfitAddons = msg->getU8();
|
||||
|
||||
outfitList.push_back(std::make_tuple(outfitId, outfitName, outfitAddons));
|
||||
outfitList.emplace_back(outfitId, outfitName, outfitAddons);
|
||||
}
|
||||
} else {
|
||||
int outfitStart, outfitEnd;
|
||||
@ -1798,7 +1798,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg)
|
||||
}
|
||||
|
||||
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;
|
||||
@ -1808,7 +1808,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg)
|
||||
int mountId = msg->getU16(); // mount type
|
||||
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();
|
||||
std::string name = msg->getString();
|
||||
bool completed = msg->getU8();
|
||||
questList.push_back(std::make_tuple(id, name, completed));
|
||||
questList.emplace_back(id, name, completed);
|
||||
}
|
||||
|
||||
g_game.processQuestLog(questList);
|
||||
@ -1895,7 +1895,7 @@ void ProtocolGame::parseQuestLine(const InputMessagePtr& msg)
|
||||
for(int i = 0; i < missionCount; i++) {
|
||||
std::string missionName = 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);
|
||||
@ -1920,7 +1920,7 @@ void ProtocolGame::parseItemInfo(const InputMessagePtr& msg)
|
||||
item->setCountOrSubType(msg->getU8());
|
||||
|
||||
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);
|
||||
@ -1947,7 +1947,7 @@ void ProtocolGame::parseModalDialog(const InputMessagePtr& msg)
|
||||
for(int i = 0; i < sizeButtons; ++i) {
|
||||
std::string value = msg->getString();
|
||||
int id = msg->getU8();
|
||||
buttonList.push_back(std::make_tuple(id, value));
|
||||
buttonList.emplace_back(id, value);
|
||||
}
|
||||
|
||||
int sizeChoices = msg->getU8();
|
||||
@ -1955,7 +1955,7 @@ void ProtocolGame::parseModalDialog(const InputMessagePtr& msg)
|
||||
for(int i = 0; i < sizeChoices; ++i) {
|
||||
std::string value = msg->getString();
|
||||
int id = msg->getU8();
|
||||
choiceList.push_back(std::make_tuple(id, value));
|
||||
choiceList.emplace_back(id, value);
|
||||
}
|
||||
|
||||
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
|
||||
// first message
|
||||
if(m_messages.size() == 0) {
|
||||
if(m_messages.empty()) {
|
||||
m_name = name;
|
||||
m_mode = mode;
|
||||
}
|
||||
@ -82,7 +82,7 @@ bool StaticText::addMessage(const std::string& name, Otc::MessageMode mode, cons
|
||||
if(isYell())
|
||||
delay *= 2;
|
||||
|
||||
m_messages.push_back(std::make_pair(text, g_clock.millis() + delay));
|
||||
m_messages.emplace_back(text, g_clock.millis() + delay);
|
||||
compose();
|
||||
|
||||
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))
|
||||
fin->addU32(m_spritesIndex[i]);
|
||||
fin->addU32(i);
|
||||
else
|
||||
fin->addU16(m_spritesIndex[i]);
|
||||
fin->addU16(i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -328,7 +328,7 @@ void ThingType::exportImage(std::string fileName)
|
||||
if(m_null)
|
||||
stdext::throw_exception("cannot export null thingtype");
|
||||
|
||||
if(m_spritesIndex.size() == 0)
|
||||
if(m_spritesIndex.empty())
|
||||
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)));
|
||||
|
@ -48,15 +48,15 @@ void ThingTypeManager::init()
|
||||
m_datLoaded = false;
|
||||
m_xmlLoaded = false;
|
||||
m_otbLoaded = false;
|
||||
for(int i = 0; i < ThingLastCategory; ++i)
|
||||
m_thingTypes[i].resize(1, m_nullThingType);
|
||||
for(auto &m_thingType: m_thingTypes)
|
||||
m_thingType.resize(1, m_nullThingType);
|
||||
m_itemTypes.resize(1, m_nullItemType);
|
||||
}
|
||||
|
||||
void ThingTypeManager::terminate()
|
||||
{
|
||||
for(int i = 0; i < ThingLastCategory; ++i)
|
||||
m_thingTypes[i].clear();
|
||||
for(auto &m_thingType: m_thingTypes)
|
||||
m_thingType.clear();
|
||||
m_itemTypes.clear();
|
||||
m_reverseItemTypes.clear();
|
||||
m_nullThingType = nullptr;
|
||||
@ -77,8 +77,8 @@ void ThingTypeManager::saveDat(std::string fileName)
|
||||
|
||||
fin->addU32(m_datSignature);
|
||||
|
||||
for(int category = 0; category < ThingLastCategory; ++category)
|
||||
fin->addU16(m_thingTypes[category].size() - 1);
|
||||
for(auto &m_thingType: m_thingTypes)
|
||||
fin->addU16(m_thingType.size() - 1);
|
||||
|
||||
for(int category = 0; category < ThingLastCategory; ++category) {
|
||||
uint16 firstId = 1;
|
||||
@ -110,10 +110,10 @@ bool ThingTypeManager::loadDat(std::string file)
|
||||
m_datSignature = fin->getU32();
|
||||
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;
|
||||
m_thingTypes[category].clear();
|
||||
m_thingTypes[category].resize(count, m_nullThingType);
|
||||
m_thingType.clear();
|
||||
m_thingType.resize(count, m_nullThingType);
|
||||
}
|
||||
|
||||
for(int category = 0; category < ThingLastCategory; ++category) {
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
const ItemTypePtr& findItemTypeByClientId(uint16 id);
|
||||
const ItemTypePtr& findItemTypeByName(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 ItemTypePtr& getNullItemType() { return m_nullItemType; }
|
||||
|
@ -63,8 +63,7 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags, LightView *
|
||||
|
||||
bool restore = false;
|
||||
if(g_map.showZones() && thing->isGround()) {
|
||||
for(unsigned int i = 0; i < sizeof(flags) / sizeof(tileflags_t); ++i) {
|
||||
tileflags_t flag = flags[i];
|
||||
for(auto flag: flags) {
|
||||
if(hasFlag(flag) && g_map.showZone(flag)) {
|
||||
g_painter->setOpacity(g_map.getZoneOpacity());
|
||||
g_painter->setColor(g_map.getZoneColor(flag));
|
||||
@ -386,8 +385,7 @@ ThingPtr Tile::getTopLookThing()
|
||||
if(isEmpty())
|
||||
return nullptr;
|
||||
|
||||
for(uint i = 0; i < m_things.size(); ++i) {
|
||||
ThingPtr thing = m_things[i];
|
||||
for(auto thing: m_things) {
|
||||
if(!thing->isIgnoreLook() && (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()))
|
||||
return thing;
|
||||
}
|
||||
@ -400,14 +398,12 @@ ThingPtr Tile::getTopUseThing()
|
||||
if(isEmpty())
|
||||
return nullptr;
|
||||
|
||||
for(uint i = 0; i < m_things.size(); ++i) {
|
||||
ThingPtr thing = m_things[i];
|
||||
for(auto thing: m_things) {
|
||||
if (thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature() && !thing->isSplash()))
|
||||
return thing;
|
||||
}
|
||||
|
||||
for(uint i = 0; i < m_things.size(); ++i) {
|
||||
ThingPtr thing = m_things[i];
|
||||
for(auto thing: m_things) {
|
||||
if (!thing->isGround() && !thing->isGroundBorder() && !thing->isCreature() && !thing->isSplash())
|
||||
return thing;
|
||||
}
|
||||
@ -418,8 +414,7 @@ ThingPtr Tile::getTopUseThing()
|
||||
CreaturePtr Tile::getTopCreature()
|
||||
{
|
||||
CreaturePtr creature;
|
||||
for(uint i = 0; i < m_things.size(); ++i) {
|
||||
ThingPtr thing = m_things[i];
|
||||
for(auto thing: m_things) {
|
||||
if(thing->isLocalPlayer()) // return local player if there is no other creature
|
||||
creature = thing->static_self_cast<Creature>();
|
||||
else if(thing->isCreature() && !thing->isLocalPlayer())
|
||||
@ -480,8 +475,7 @@ ThingPtr Tile::getTopMultiUseThing()
|
||||
if(CreaturePtr topCreature = getTopCreature())
|
||||
return topCreature;
|
||||
|
||||
for(uint i = 0; i < m_things.size(); ++i) {
|
||||
ThingPtr thing = m_things[i];
|
||||
for(auto thing: m_things) {
|
||||
if(thing->isForceUse())
|
||||
return thing;
|
||||
}
|
||||
@ -495,8 +489,7 @@ ThingPtr Tile::getTopMultiUseThing()
|
||||
}
|
||||
}
|
||||
|
||||
for(uint i = 0; i < m_things.size(); ++i) {
|
||||
ThingPtr thing = m_things[i];
|
||||
for(auto thing: m_things) {
|
||||
if(!thing->isGround() && !thing->isOnTop())
|
||||
return thing;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ void AsyncDispatcher::terminate()
|
||||
void AsyncDispatcher::spawn_thread()
|
||||
{
|
||||
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()
|
||||
@ -55,7 +55,7 @@ void AsyncDispatcher::stop()
|
||||
void AsyncDispatcher::exec_loop() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
while(true) {
|
||||
while(m_tasks.size() == 0 && m_running)
|
||||
while(m_tasks.empty() && m_running)
|
||||
m_condition.wait(lock);
|
||||
|
||||
if(!m_running)
|
||||
|
@ -74,7 +74,7 @@ void Config::clear()
|
||||
|
||||
void Config::setValue(const std::string& key, const std::string& value)
|
||||
{
|
||||
if(value == "") {
|
||||
if(value.empty()) {
|
||||
remove(key);
|
||||
return;
|
||||
}
|
||||
@ -87,7 +87,7 @@ void Config::setList(const std::string& key, const std::vector<std::string>& lis
|
||||
{
|
||||
remove(key);
|
||||
|
||||
if(list.size() == 0)
|
||||
if(list.empty())
|
||||
return;
|
||||
|
||||
OTMLNodePtr child = OTMLNode::create(key, true);
|
||||
|
@ -320,7 +320,7 @@ std::string FileStream::getString()
|
||||
} else {
|
||||
if(m_pos+len > m_data.size()) {
|
||||
throwError("read failed");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
std::size_t now = std::time(NULL);
|
||||
m_logMessages.push_back(LogMessage(level, outmsg, now));
|
||||
std::size_t now = std::time(nullptr);
|
||||
m_logMessages.emplace_back(level, outmsg, now);
|
||||
if(m_logMessages.size() > MAX_LOG_HISTORY)
|
||||
m_logMessages.pop_front();
|
||||
|
||||
@ -133,7 +133,7 @@ void Logger::setLogFile(const std::string& file)
|
||||
{
|
||||
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()) {
|
||||
g_logger.error(stdext::format("Unable to save log to '%s'", file));
|
||||
return;
|
||||
|
@ -264,8 +264,8 @@ std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& di
|
||||
std::list<std::string> files;
|
||||
auto rc = PHYSFS_enumerateFiles(resolvePath(directoryPath).c_str());
|
||||
|
||||
for(int i = 0; rc[i] != NULL; i++)
|
||||
files.push_back(rc[i]);
|
||||
for(int i = 0; rc[i] != nullptr; i++)
|
||||
files.emplace_back(rc[i]);
|
||||
|
||||
PHYSFS_freeList(rc);
|
||||
return files;
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
|
||||
bool addSearchPath(const std::string& path, bool pushFront = false);
|
||||
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 directoryExists(const std::string& directoryName);
|
||||
|
@ -30,8 +30,8 @@ AnimatedTexture::AnimatedTexture(const Size& size, std::vector<ImagePtr> frames,
|
||||
if(!setupSize(size, buildMipmaps))
|
||||
return;
|
||||
|
||||
for(uint i=0;i<frames.size();++i) {
|
||||
m_frames.push_back(new Texture(frames[i], buildMipmaps, compress));
|
||||
for(const auto &frame: frames) {
|
||||
m_frames.push_back(new Texture(frame, buildMipmaps, compress));
|
||||
}
|
||||
|
||||
m_framesDelay = framesDelay;
|
||||
|
@ -23,14 +23,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <zlib.h>
|
||||
#include "apngloader.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1300
|
||||
#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 char * row = dst;
|
||||
unsigned char * prev_row = NULL;
|
||||
unsigned char * prev_row = nullptr;
|
||||
|
||||
zstream.next_out = dst;
|
||||
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);
|
||||
pImg1=pOut1;
|
||||
pImg2=pOut2;
|
||||
frames_delay = NULL;
|
||||
frames_delay = nullptr;
|
||||
|
||||
/* apng decoding - begin */
|
||||
memset(pOut1, 0, outimg1);
|
||||
@ -677,7 +679,7 @@ int load_apng(std::stringstream& file, struct apng_data *apng)
|
||||
frames = read32(file);
|
||||
if(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);
|
||||
/*crc = */read32(file);
|
||||
if (pOut1)
|
||||
@ -871,7 +873,7 @@ void write_chunk(std::ostream& f, const char* name, unsigned char* data, unsigne
|
||||
f.write(name, 4);
|
||||
crc = crc32(crc, (const Bytef*)name, 4);
|
||||
|
||||
if(data != NULL && length > 0) {
|
||||
if(data != nullptr && length > 0) {
|
||||
f.write((char*)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* 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;
|
||||
}
|
||||
|
||||
row_buf[0] = 0;
|
||||
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.avail_out = zbuf_size;
|
||||
|
||||
prev = NULL;
|
||||
prev = nullptr;
|
||||
row = pixels;
|
||||
|
||||
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);
|
||||
zstream2.data_type = Z_BINARY;
|
||||
|
||||
write_chunk(f, "IEND", 0, 0);
|
||||
write_chunk(f, "IEND", nullptr, 0);
|
||||
|
||||
deflateEnd(&zstream1);
|
||||
deflateEnd(&zstream2);
|
||||
|
@ -298,8 +298,7 @@ std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
|
||||
std::vector<std::string> wordsSplit = stdext::split(text);
|
||||
|
||||
// break huge words into small ones
|
||||
for(uint i=0;i<wordsSplit.size();++i) {
|
||||
const std::string& word = wordsSplit[i];
|
||||
for(const auto &word: wordsSplit) {
|
||||
int wordWidth = calculateTextRectSize(word).width();
|
||||
if(wordWidth > maxWidth) {
|
||||
std::string newWord;
|
||||
@ -324,8 +323,8 @@ std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
|
||||
}
|
||||
|
||||
// compose lines
|
||||
for(uint i=0;i<words.size();++i) {
|
||||
std::string candidate = line + words[i];
|
||||
for(const auto &word: words) {
|
||||
std::string candidate = line + word;
|
||||
int candidateWidth = calculateTextRectSize(candidate).width();
|
||||
|
||||
if(candidateWidth > maxWidth) {
|
||||
@ -334,7 +333,7 @@ std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
|
||||
line = "";
|
||||
}
|
||||
|
||||
line += words[i] + " ";
|
||||
line += word + " ";
|
||||
}
|
||||
|
||||
outText += line;
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
/// Calculate glyphs positions to use on render, also calculates textBoxSize if wanted
|
||||
const std::vector<Point>& calculateGlyphsPositions(const std::string& text,
|
||||
Fw::AlignmentFlag align = Fw::AlignTopLeft,
|
||||
Size* textBoxSize = NULL);
|
||||
Size* textBoxSize = nullptr);
|
||||
|
||||
/// Simulate render and calculate text size
|
||||
Size calculateTextRectSize(const std::string& text);
|
||||
|
@ -34,9 +34,7 @@ CoordsBuffer::CoordsBuffer()
|
||||
|
||||
CoordsBuffer::~CoordsBuffer()
|
||||
{
|
||||
if(m_hardwareVertexArray)
|
||||
delete m_hardwareVertexArray;
|
||||
if(m_hardwareTextureCoordArray)
|
||||
delete m_hardwareTextureCoordArray;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
void drawBoundingRect(const Rect& dest, int innerLineWidth);
|
||||
|
||||
void setMatrixMode(MatrixMode matrixMode);
|
||||
void setTransformMatrix(const Matrix3& projectionMatrix);
|
||||
void setTransformMatrix(const Matrix3& transformMatrix);
|
||||
void setProjectionMatrix(const Matrix3& projectionMatrix);
|
||||
void setTextureMatrix(const Matrix3& textureMatrix);
|
||||
void setColor(const Color& color);
|
||||
|
@ -165,7 +165,7 @@ void PainterShaderProgram::addMultiTexture(const std::string& file)
|
||||
|
||||
void PainterShaderProgram::bindMultiTextures()
|
||||
{
|
||||
if(m_multiTextures.size() == 0)
|
||||
if(m_multiTextures.empty())
|
||||
return;
|
||||
|
||||
int i=1;
|
||||
|
@ -54,8 +54,8 @@ void ParticleEffect::load(const ParticleEffectTypePtr& effectType)
|
||||
|
||||
void ParticleEffect::render()
|
||||
{
|
||||
for(auto it = m_systems.begin(), end = m_systems.end(); it != end; ++it)
|
||||
(*it)->render();
|
||||
for(auto &system: m_systems)
|
||||
system->render();
|
||||
}
|
||||
|
||||
void ParticleEffect::update()
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
ParticleEffect() {}
|
||||
|
||||
void load(const ParticleEffectTypePtr& effectType);
|
||||
bool hasFinished() { return m_systems.size() == 0; }
|
||||
bool hasFinished() { return m_systems.empty(); }
|
||||
void render();
|
||||
void update();
|
||||
|
||||
|
@ -61,8 +61,8 @@ void ParticleSystem::addParticle(const ParticlePtr& particle)
|
||||
|
||||
void ParticleSystem::render()
|
||||
{
|
||||
for(auto it = m_particles.begin(), end = m_particles.end(); it != end; ++it)
|
||||
(*it)->render();
|
||||
for(auto &particle: m_particles)
|
||||
particle->render();
|
||||
g_painter->resetCompositionMode();
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ void ParticleType::load(const OTMLNodePtr& node)
|
||||
}
|
||||
|
||||
if(pColors.empty())
|
||||
pColors.push_back(Color(255, 255, 255, 128));
|
||||
pColors.emplace_back(255, 255, 255, 128);
|
||||
if(pColorsStops.empty())
|
||||
pColorsStops.push_back(0);
|
||||
|
||||
|
@ -69,7 +69,7 @@ bool Shader::compileSourceCode(const std::string& sourceCode)
|
||||
std::string code = qualifierDefines;
|
||||
code.append(sourceCode);
|
||||
const char *c_source = code.c_str();
|
||||
glShaderSource(m_shaderId, 1, &c_source, NULL);
|
||||
glShaderSource(m_shaderId, 1, &c_source, nullptr);
|
||||
glCompileShader(m_shaderId);
|
||||
|
||||
int res = GL_FALSE;
|
||||
@ -95,7 +95,7 @@ std::string Shader::log()
|
||||
glGetShaderiv(m_shaderId, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
if(infoLogLength > 1) {
|
||||
std::vector<char> buf(infoLogLength);
|
||||
glGetShaderInfoLog(m_shaderId, infoLogLength-1, NULL, &buf[0]);
|
||||
glGetShaderInfoLog(m_shaderId, infoLogLength-1, nullptr, &buf[0]);
|
||||
infoLog = &buf[0];
|
||||
}
|
||||
return infoLog;
|
||||
|
@ -129,7 +129,7 @@ std::string ShaderProgram::log()
|
||||
glGetProgramiv(m_programId, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
if(infoLogLength > 1) {
|
||||
std::vector<char> buf(infoLogLength);
|
||||
glGetShaderInfoLog(m_programId, infoLogLength-1, NULL, &buf[0]);
|
||||
glGetShaderInfoLog(m_programId, infoLogLength-1, nullptr, &buf[0]);
|
||||
infoLog = &buf[0];
|
||||
}
|
||||
return infoLog;
|
||||
|
@ -75,7 +75,7 @@ bool Mouse::pushCursor(const std::string& name)
|
||||
|
||||
void Mouse::popCursor(const std::string& name)
|
||||
{
|
||||
if(m_cursorStack.size() == 0)
|
||||
if(m_cursorStack.empty())
|
||||
return;
|
||||
|
||||
if(name.empty() || m_cursors.find(name) == m_cursors.end())
|
||||
@ -93,7 +93,7 @@ void Mouse::popCursor(const std::string& name)
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_cursorStack.size() > 0)
|
||||
if(!m_cursorStack.empty())
|
||||
g_window.setMouseCursor(m_cursorStack.back());
|
||||
else
|
||||
g_window.restoreMouseCursor();
|
||||
@ -101,7 +101,7 @@ void Mouse::popCursor(const std::string& name)
|
||||
|
||||
bool Mouse::isCursorChanged()
|
||||
{
|
||||
return m_cursorStack.size() > 0;
|
||||
return !m_cursorStack.empty();
|
||||
}
|
||||
|
||||
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) /* { */
|
||||
/* the following definition assures proper modulo behavior */
|
||||
#if defined(LUA_NUMBER_DOUBLE)
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
|
||||
#define lua_number2unsigned(i,n) \
|
||||
((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
|
||||
@ -365,7 +365,7 @@ static const luaL_Reg bitlib[] = {
|
||||
{"replace", b_replace},
|
||||
{"rrotate", b_rrot},
|
||||
{"rshift", b_rshift},
|
||||
{NULL, NULL}
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
int luaopen_bit32 (lua_State *L) {
|
||||
|
@ -707,7 +707,7 @@ void LuaInterface::closeLuaState()
|
||||
if(L) {
|
||||
// close lua, it also collects
|
||||
lua_close(L);
|
||||
L = NULL;
|
||||
L = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -785,7 +785,7 @@ int LuaInterface::weakRef()
|
||||
|
||||
void LuaInterface::unref(int ref)
|
||||
{
|
||||
if(ref >= 0 && L != NULL)
|
||||
if(ref >= 0 && L != nullptr)
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, ref);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,9 @@
|
||||
|
||||
#include <framework/core/application.h>
|
||||
#include <framework/core/eventdispatcher.h>
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <memory>
|
||||
|
||||
asio::io_service g_ioService;
|
||||
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_outputStreams.pop_front();
|
||||
} else
|
||||
m_outputStream = std::shared_ptr<asio::streambuf>(new asio::streambuf);
|
||||
m_outputStream = std::make_shared<asio::streambuf>();
|
||||
|
||||
m_delayedWriteTimer.cancel();
|
||||
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,
|
||||
m_inputStream,
|
||||
what.c_str(),
|
||||
what,
|
||||
std::bind(&Connection::onRecv, asConnection(), std::placeholders::_1, std::placeholders::_2));
|
||||
|
||||
m_readTimer.cancel();
|
||||
|
@ -144,7 +144,7 @@ void Protocol::internalRecvData(uint8* buffer, uint16 size)
|
||||
|
||||
void Protocol::generateXteaKey()
|
||||
{
|
||||
std::mt19937 eng(std::time(NULL));
|
||||
std::mt19937 eng(std::time(nullptr));
|
||||
std::uniform_int_distribution<uint32> unif(0, 0xFFFFFFFF);
|
||||
m_xteaKey[0] = unif(eng);
|
||||
m_xteaKey[1] = unif(eng);
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
OTMLParser::OTMLParser(OTMLDocumentPtr doc, std::istream& in) :
|
||||
currentDepth(0), currentLine(0),
|
||||
doc(doc), currentParent(doc), previousNode(0),
|
||||
doc(doc), currentParent(doc), previousNode(nullptr),
|
||||
in(in)
|
||||
{
|
||||
}
|
||||
|
@ -150,8 +150,8 @@ void PlatformWindow::releaseAllKeys()
|
||||
|
||||
m_inputEvent.keyboardModifiers = 0;
|
||||
|
||||
for(int i=0;i<4;++i)
|
||||
m_mouseButtonStates[i] = false;
|
||||
for(auto &mouseButtonState: m_mouseButtonStates)
|
||||
mouseButtonState = false;
|
||||
}
|
||||
|
||||
void PlatformWindow::fireKeysPress()
|
||||
|
@ -30,9 +30,9 @@
|
||||
#define __USE_GNU
|
||||
#endif
|
||||
|
||||
#include <csignal>
|
||||
#include <execinfo.h>
|
||||
#include <ucontext.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define MAX_BACKTRACE_DEPTH 128
|
||||
#define DEMANGLE_BACKTRACE_SYMBOLS
|
||||
@ -129,10 +129,10 @@ void installCrashHandler()
|
||||
sigemptyset (&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||
|
||||
sigaction(SIGILL, &sa, NULL); // illegal instruction
|
||||
sigaction(SIGSEGV, &sa, NULL); // segmentation fault
|
||||
sigaction(SIGFPE, &sa, NULL); // floating-point exception
|
||||
sigaction(SIGABRT, &sa, NULL); // process aborted (asserts)
|
||||
sigaction(SIGILL, &sa, nullptr); // illegal instruction
|
||||
sigaction(SIGSEGV, &sa, nullptr); // segmentation fault
|
||||
sigaction(SIGFPE, &sa, nullptr); // floating-point exception
|
||||
sigaction(SIGABRT, &sa, nullptr); // process aborted (asserts)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -23,9 +23,9 @@
|
||||
#ifndef WIN32
|
||||
|
||||
#include "platform.h"
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <framework/stdext/stdext.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();
|
||||
for(uint i=1;i<=args.size();++i)
|
||||
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)
|
||||
_exit(EXIT_FAILURE);
|
||||
@ -84,7 +84,7 @@ std::string Platform::getCurrentDir()
|
||||
{
|
||||
std::string res;
|
||||
char cwd[2048];
|
||||
if(getcwd(cwd, sizeof(cwd)) != NULL) {
|
||||
if(getcwd(cwd, sizeof(cwd)) != nullptr) {
|
||||
res = cwd;
|
||||
res += "/";
|
||||
}
|
||||
|
@ -31,15 +31,15 @@
|
||||
|
||||
X11Window::X11Window()
|
||||
{
|
||||
m_display = 0;
|
||||
m_visual = 0;
|
||||
m_display = nullptr;
|
||||
m_visual = nullptr;
|
||||
m_window = 0;
|
||||
m_rootWindow = 0;
|
||||
m_colormap = 0;
|
||||
m_cursor = 0;
|
||||
m_hiddenCursor = 0;
|
||||
m_xim = 0;
|
||||
m_xic = 0;
|
||||
m_xim = nullptr;
|
||||
m_xic = nullptr;
|
||||
m_screen = 0;
|
||||
m_wmDelete = 0;
|
||||
m_minimumSize = Size(600,480);
|
||||
@ -51,8 +51,8 @@ X11Window::X11Window()
|
||||
m_eglDisplay = 0;
|
||||
m_eglSurface = 0;
|
||||
#else
|
||||
m_fbConfig = 0;
|
||||
m_glxContext = 0;
|
||||
m_fbConfig = nullptr;
|
||||
m_glxContext = nullptr;
|
||||
#endif
|
||||
|
||||
m_keyMap[XK_Escape] = Fw::KeyEscape;
|
||||
@ -247,22 +247,22 @@ void X11Window::terminate()
|
||||
|
||||
if(m_visual) {
|
||||
XFree(m_visual);
|
||||
m_visual = 0;
|
||||
m_visual = nullptr;
|
||||
}
|
||||
|
||||
if(m_xic) {
|
||||
XDestroyIC(m_xic);
|
||||
m_xic = 0;
|
||||
m_xic = nullptr;
|
||||
}
|
||||
|
||||
if(m_xim) {
|
||||
XCloseIM(m_xim);
|
||||
m_xim = 0;
|
||||
m_xim = nullptr;
|
||||
}
|
||||
|
||||
if(m_display) {
|
||||
XCloseDisplay(m_display);
|
||||
m_display = 0;
|
||||
m_display = nullptr;
|
||||
}
|
||||
|
||||
m_visible = false;
|
||||
@ -270,7 +270,7 @@ void X11Window::terminate()
|
||||
|
||||
void X11Window::internalOpenDisplay()
|
||||
{
|
||||
m_display = XOpenDisplay(NULL);
|
||||
m_display = XOpenDisplay(nullptr);
|
||||
if(!m_display)
|
||||
g_logger.fatal("Unable to open X11 display");
|
||||
m_screen = DefaultScreen(m_display);
|
||||
@ -343,7 +343,7 @@ bool X11Window::internalSetupWindowInput()
|
||||
}
|
||||
|
||||
XSetLocaleModifiers("");
|
||||
m_xim = XOpenIM(m_display, NULL, NULL, NULL);
|
||||
m_xim = XOpenIM(m_display, nullptr, nullptr, nullptr);
|
||||
if(!m_xim) {
|
||||
g_logger.error("XOpenIM failed");
|
||||
return false;
|
||||
@ -368,7 +368,7 @@ void X11Window::internalCheckGL()
|
||||
if(!eglInitialize(m_eglDisplay, NULL, NULL))
|
||||
g_logger.fatal("Unable to initialize EGL");
|
||||
#else
|
||||
if(!glXQueryExtension(m_display, NULL, NULL))
|
||||
if(!glXQueryExtension(m_display, nullptr, nullptr))
|
||||
g_logger.fatal("GLX not supported");
|
||||
#endif
|
||||
}
|
||||
@ -450,7 +450,7 @@ void X11Window::internalCreateGLContext()
|
||||
if(m_eglContext == EGL_NO_CONTEXT )
|
||||
g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError()));
|
||||
#else
|
||||
m_glxContext = glXCreateContext(m_display, m_visual, NULL, True);
|
||||
m_glxContext = glXCreateContext(m_display, m_visual, nullptr, True);
|
||||
|
||||
if(!m_glxContext)
|
||||
g_logger.fatal("Unable to create GLX context");
|
||||
@ -477,9 +477,9 @@ void X11Window::internalDestroyGLContext()
|
||||
}
|
||||
#else
|
||||
if(m_glxContext) {
|
||||
glXMakeCurrent(m_display, None, NULL);
|
||||
glXMakeCurrent(m_display, None, nullptr);
|
||||
glXDestroyContext(m_display, m_glxContext);
|
||||
m_glxContext = 0;
|
||||
m_glxContext = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -606,7 +606,7 @@ void X11Window::poll()
|
||||
// lookup keysym and translate it
|
||||
KeySym keysym;
|
||||
char buf[32];
|
||||
XLookupString(&xkey, buf, sizeof(buf), &keysym, 0);
|
||||
XLookupString(&xkey, buf, sizeof(buf), &keysym, nullptr);
|
||||
Fw::Key keyCode = Fw::KeyUnknown;
|
||||
|
||||
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 actualType;
|
||||
ulong i, numItems, bytesAfter;
|
||||
uchar *propertyValue = NULL;
|
||||
uchar *propertyValue = nullptr;
|
||||
int actualFormat;
|
||||
|
||||
if(XGetWindowProperty(m_display, m_window, wmState,
|
||||
@ -740,7 +740,7 @@ void X11Window::poll()
|
||||
Status 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
|
||||
static XComposeStatus compose = {NULL, 0};
|
||||
static XComposeStatus compose = {nullptr, 0};
|
||||
len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, &compose);
|
||||
}
|
||||
|
||||
@ -972,7 +972,7 @@ void X11Window::setVerticalSync(bool enable)
|
||||
//TODO
|
||||
#else
|
||||
typedef GLint (*glSwapIntervalProc)(GLint);
|
||||
glSwapIntervalProc glSwapInterval = NULL;
|
||||
glSwapIntervalProc glSwapInterval = nullptr;
|
||||
|
||||
if(isExtensionSupported("GLX_MESA_swap_control"))
|
||||
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalMESA");
|
||||
|
@ -35,7 +35,7 @@ OggSoundFile::~OggSoundFile()
|
||||
bool OggSoundFile::prepareOgg()
|
||||
{
|
||||
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);
|
||||
if(!vi) {
|
||||
|
@ -37,13 +37,13 @@ SoundManager g_sounds;
|
||||
|
||||
void SoundManager::init()
|
||||
{
|
||||
m_device = alcOpenDevice(NULL);
|
||||
m_device = alcOpenDevice(nullptr);
|
||||
if(!m_device) {
|
||||
g_logger.error("unable to open audio device");
|
||||
return;
|
||||
}
|
||||
|
||||
m_context = alcCreateContext(m_device, NULL);
|
||||
m_context = alcCreateContext(m_device, nullptr);
|
||||
if(!m_context) {
|
||||
g_logger.error(stdext::format("unable to create audio context: %s", alcGetString(m_device, alcGetError(m_device))));
|
||||
return;
|
||||
@ -59,8 +59,8 @@ void SoundManager::terminate()
|
||||
{
|
||||
ensureContext();
|
||||
|
||||
for(auto it = m_streamFiles.begin(); it != m_streamFiles.end();++it) {
|
||||
auto& future = it->second;
|
||||
for(auto &streamFile: m_streamFiles) {
|
||||
auto& future = streamFile.second;
|
||||
future.wait();
|
||||
}
|
||||
m_streamFiles.clear();
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
any() : content(nullptr) { }
|
||||
any(const any& other) : content(other.content ? other.content->clone() : nullptr) { }
|
||||
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; }
|
||||
|
||||
|
@ -44,20 +44,21 @@ namespace stdext {
|
||||
|
||||
const char* demangle_name(const char* name)
|
||||
{
|
||||
static const unsigned BufferSize = 1024;
|
||||
static char Buffer[1024] = {};
|
||||
|
||||
#ifdef _MSC_VER
|
||||
static char buffer[1024];
|
||||
UnDecorateSymbolName(name, buffer, sizeof(buffer), UNDNAME_COMPLETE);
|
||||
return buffer;
|
||||
UnDecorateSymbolName(name, Buffer, BufferSize, UNDNAME_COMPLETE);
|
||||
return Buffer;
|
||||
#else
|
||||
size_t len;
|
||||
int status;
|
||||
static char buffer[1024];
|
||||
char* demangled = abi::__cxa_demangle(name, 0, &len, &status);
|
||||
char* demangled = abi::__cxa_demangle(name, nullptr, &len, &status);
|
||||
if(demangled) {
|
||||
strcpy(buffer, demangled);
|
||||
strncpy(Buffer, demangled, BufferSize);
|
||||
free(demangled);
|
||||
}
|
||||
return buffer;
|
||||
return Buffer;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ class packed_storage {
|
||||
|
||||
public:
|
||||
packed_storage() : m_values(nullptr), m_size(0) { }
|
||||
~packed_storage() { if(m_values) delete[] m_values; }
|
||||
~packed_storage() { delete[] m_values; }
|
||||
|
||||
template<typename T>
|
||||
void set(Key id, const T& value) {
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
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(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; }
|
||||
|
||||
|
@ -23,22 +23,22 @@
|
||||
#ifndef STDEXT_H
|
||||
#define STDEXT_H
|
||||
|
||||
#include "compiler.h"
|
||||
#include "dumper.h"
|
||||
#include "types.h"
|
||||
#include "exception.h"
|
||||
#include "demangle.h"
|
||||
#include "any.h"
|
||||
#include "boolean.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 "packed_any.h"
|
||||
#include "packed_storage.h"
|
||||
#include "packed_vector.h"
|
||||
#include "shared_object.h"
|
||||
#include "string.h"
|
||||
#include "time.h"
|
||||
#include "boolean.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"
|
||||
#include "types.h"
|
||||
|
||||
#endif
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "string.h"
|
||||
#include "format.h"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <ctype.h>
|
||||
#include <cctype>
|
||||
#include <physfs.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "time.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <thread>
|
||||
@ -30,7 +31,7 @@ namespace stdext {
|
||||
const static auto startup_time = std::chrono::high_resolution_clock::now();
|
||||
|
||||
ticks_t time() {
|
||||
return std::time(NULL);
|
||||
return std::time(nullptr);
|
||||
}
|
||||
|
||||
ticks_t millis()
|
||||
|
@ -50,8 +50,8 @@ void UIParticles::drawSelf(Fw::DrawPane drawPane)
|
||||
else
|
||||
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)
|
||||
(*it)->render();
|
||||
for(auto &effect: m_effects)
|
||||
effect->render();
|
||||
g_painter->restoreSavedState();
|
||||
}
|
||||
}
|
||||
|
@ -397,9 +397,9 @@ void UITextEdit::appendText(std::string text)
|
||||
return;
|
||||
|
||||
// only ignore text append if it contains invalid characters
|
||||
if(m_validCharacters.size() > 0) {
|
||||
for(uint i = 0; i < text.size(); ++i) {
|
||||
if(m_validCharacters.find(text[i]) == std::string::npos)
|
||||
if(!m_validCharacters.empty()) {
|
||||
for(char i: text) {
|
||||
if(m_validCharacters.find(i) == std::string::npos)
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -424,7 +424,7 @@ void UITextEdit::appendCharacter(char c)
|
||||
if(m_maxLength > 0 && m_text.length() + 1 > m_maxLength)
|
||||
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;
|
||||
|
||||
std::string tmp;
|
||||
|
@ -103,7 +103,7 @@ protected:
|
||||
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
||||
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:
|
||||
void disableUpdates() { m_updatesEnabled = false; }
|
||||
|
@ -70,7 +70,7 @@ void UIWidget::draw(const Rect& visibleRect, Fw::DrawPane drawPane)
|
||||
|
||||
drawSelf(drawPane);
|
||||
|
||||
if(m_children.size() > 0) {
|
||||
if(!m_children.empty()) {
|
||||
if(m_clipping)
|
||||
g_painter->setClipRect(visibleRect.intersection(getPaddingRect()));
|
||||
|
||||
@ -488,7 +488,7 @@ void UIWidget::unlockChild(const UIWidgetPtr& child)
|
||||
|
||||
// find new child to lock
|
||||
UIWidgetPtr lockedChild;
|
||||
if(m_lockedChildren.size() > 0) {
|
||||
if(!m_lockedChildren.empty()) {
|
||||
lockedChild = m_lockedChildren.front();
|
||||
assert(hasChild(lockedChild));
|
||||
}
|
||||
@ -1043,8 +1043,8 @@ bool UIWidget::hasChild(const UIWidgetPtr& child)
|
||||
int UIWidget::getChildIndex(const UIWidgetPtr& child)
|
||||
{
|
||||
int index = 1;
|
||||
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
||||
if(*it == child)
|
||||
for(auto &it: m_children) {
|
||||
if(it == child)
|
||||
return 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)
|
||||
{
|
||||
if(containsPaddingPoint(mousePos)) {
|
||||
for(auto it = m_children.begin(); it != m_children.end(); ++it) {
|
||||
const UIWidgetPtr& child = *it;
|
||||
for(auto &child: m_children) {
|
||||
if(child->isExplicitlyVisible() && child->isExplicitlyEnabled() && child->containsPoint(mousePos))
|
||||
child->propagateOnMouseMove(mousePos, mouseMoved, widgetList);
|
||||
|
||||
|
@ -246,7 +246,7 @@ public:
|
||||
bool isClipping() { return m_clipping; }
|
||||
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 containsPaddingPoint(const Point& point) { return getPaddingRect().contains(point); }
|
||||
bool containsPoint(const Point& point) { return m_rect.contains(point); }
|
||||
|
@ -32,7 +32,6 @@ public:
|
||||
m_capacity(res),
|
||||
m_buffer(new T[m_capacity]) { }
|
||||
~DataBuffer() {
|
||||
if(m_buffer)
|
||||
delete[] m_buffer;
|
||||
}
|
||||
|
||||
@ -59,7 +58,7 @@ public:
|
||||
T *buffer = new T[n];
|
||||
for(uint i=0;i<m_size;++i)
|
||||
buffer[i] = m_buffer[i];
|
||||
if(m_buffer)
|
||||
|
||||
delete[] m_buffer;
|
||||
m_buffer = buffer;
|
||||
m_capacity = n;
|
||||
|
Loading…
x
Reference in New Issue
Block a user