mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
rewrite and reoganize tools functions
* create stdext namespace which contains additional C++ algorithms * organize stdext in string, math, cast and exception utilities
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
void Font::load(const OTMLNodePtr& fontNode)
|
||||
{
|
||||
OTMLNodePtr textureNode = fontNode->at("texture");
|
||||
std::string textureFile = Fw::resolvePath(textureNode->value(), textureNode->source());
|
||||
std::string textureFile = stdext::resolve_path(textureNode->value(), textureNode->source());
|
||||
Size glyphSize = fontNode->valueAt<Size>("glyph-size");
|
||||
m_glyphHeight = fontNode->valueAt<int>("height");
|
||||
m_yOffset = fontNode->valueAt("y-offset", 0);
|
||||
@@ -53,7 +53,7 @@ void Font::load(const OTMLNodePtr& fontNode)
|
||||
// read custom widths
|
||||
if(OTMLNodePtr node = fontNode->get("glyph-widths")) {
|
||||
for(const OTMLNodePtr& child : node->children())
|
||||
m_glyphsSize[Fw::safeCast<int>(child->tag())].setWidth(child->value<int>());
|
||||
m_glyphsSize[stdext::safe_cast<int>(child->tag())].setWidth(child->value<int>());
|
||||
}
|
||||
|
||||
// calculate glyphs texture coords
|
||||
@@ -285,7 +285,7 @@ std::string Font::wrapText(const std::string& text, int maxWidth)
|
||||
std::string outText;
|
||||
std::string line;
|
||||
std::vector<std::string> words;
|
||||
std::vector<std::string> wordsSplit = Fw::split(text);
|
||||
std::vector<std::string> wordsSplit = stdext::split(text);
|
||||
|
||||
// break huge words into small ones
|
||||
for(uint i=0;i<wordsSplit.size();++i) {
|
||||
|
@@ -49,7 +49,7 @@ bool FontManager::importFont(std::string fontFile)
|
||||
|
||||
std::string name = fontNode->valueAt("name");
|
||||
//if(fontExists(name))
|
||||
// Fw::throwException("font '", name, "' already exists, cannot have duplicate font names");
|
||||
// stdext::throw_exception("font '", name, "' already exists, cannot have duplicate font names");
|
||||
|
||||
// remove any font with the same name
|
||||
for(auto it = m_fonts.begin(); it != m_fonts.end(); ++it) {
|
||||
@@ -68,7 +68,7 @@ bool FontManager::importFont(std::string fontFile)
|
||||
m_defaultFont = font;
|
||||
|
||||
return true;
|
||||
} catch(Exception& e) {
|
||||
} catch(stdext::exception& e) {
|
||||
logError("Unable to load font from file '", fontFile, "': ", e.what());
|
||||
return false;
|
||||
}
|
||||
|
@@ -41,11 +41,11 @@ ImagePtr Image::load(const std::string& file)
|
||||
try {
|
||||
// currently only png images are supported
|
||||
if(!boost::ends_with(file, ".png"))
|
||||
Fw::throwException("image file format no supported");
|
||||
stdext::throw_exception("image file format no supported");
|
||||
|
||||
// load image file data
|
||||
image = loadPNG(file);
|
||||
} catch(Exception& e) {
|
||||
} catch(stdext::exception& e) {
|
||||
logError("unable to load image '", file, "': ", e.what());
|
||||
}
|
||||
return image;
|
||||
|
@@ -71,8 +71,8 @@ bool ParticleAffector::load(const OTMLNodePtr& node)
|
||||
maxDuration = childNode->value<float>();
|
||||
}
|
||||
|
||||
m_delay = Fw::randomRange(minDelay, maxDelay);
|
||||
m_duration = Fw::randomRange(minDuration, maxDuration);
|
||||
m_delay = stdext::random_range(minDelay, maxDelay);
|
||||
m_duration = stdext::random_range(minDuration, maxDuration);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -25,7 +25,6 @@
|
||||
#include "particlesystem.h"
|
||||
#include <framework/core/clock.h>
|
||||
#include <framework/graphics/texturemanager.h>
|
||||
#include <framework/util/tools.h>
|
||||
|
||||
ParticleEmitter::ParticleEmitter(const ParticleSystemPtr& parent)
|
||||
{
|
||||
@@ -152,9 +151,9 @@ bool ParticleEmitter::load(const OTMLNodePtr& node)
|
||||
m_pFinalSize = childNode->value<Size>();
|
||||
|
||||
else if(childNode->tag() == "particle-colors")
|
||||
m_pColors = Fw::split<Color>(childNode->value());
|
||||
m_pColors = stdext::split<Color>(childNode->value());
|
||||
else if(childNode->tag() == "particle-colors-stops")
|
||||
m_pColorsStops = Fw::split<float>(childNode->value());
|
||||
m_pColorsStops = stdext::split<float>(childNode->value());
|
||||
else if(childNode->tag() == "particle-texture")
|
||||
m_pTexture = g_textures.getTexture(childNode->value());
|
||||
else if(childNode->tag() == "particle-composition-mode") {
|
||||
@@ -196,23 +195,23 @@ void ParticleEmitter::update(float elapsedTime)
|
||||
for(int b = m_currentBurst; b < currentBurst; ++b) {
|
||||
|
||||
// every burst created at same position.
|
||||
float pRadius = Fw::randomRange(m_pMinPositionRadius, m_pMaxPositionRadius);
|
||||
float pAngle = Fw::randomRange(m_pMinPositionAngle, m_pMaxPositionAngle);
|
||||
float pRadius = stdext::random_range(m_pMinPositionRadius, m_pMaxPositionRadius);
|
||||
float pAngle = stdext::random_range(m_pMinPositionAngle, m_pMaxPositionAngle);
|
||||
|
||||
Point pPosition = m_position + Point(pRadius * cos(pAngle), pRadius * sin(pAngle));
|
||||
|
||||
for(int p = 0; p < m_burstCount; ++p) {
|
||||
|
||||
float pDuration = Fw::randomRange(m_pMinDuration, m_pMaxDuration);
|
||||
float pDuration = stdext::random_range(m_pMinDuration, m_pMaxDuration);
|
||||
|
||||
// particles initial velocity
|
||||
float pVelocityAbs = Fw::randomRange(m_pMinVelocity, m_pMaxVelocity);
|
||||
float pVelocityAngle = Fw::randomRange(m_pMinVelocityAngle, m_pMaxVelocityAngle);
|
||||
float pVelocityAbs = stdext::random_range(m_pMinVelocity, m_pMaxVelocity);
|
||||
float pVelocityAngle = stdext::random_range(m_pMinVelocityAngle, m_pMaxVelocityAngle);
|
||||
PointF pVelocity(pVelocityAbs * cos(pVelocityAngle), pVelocityAbs * sin(pVelocityAngle));
|
||||
|
||||
// particles initial acceleration
|
||||
float pAccelerationAbs = Fw::randomRange(m_pMinAcceleration, m_pMaxAcceleration);
|
||||
float pAccelerationAngle = Fw::randomRange(m_pMinAccelerationAngle, m_pMaxAccelerationAngle);
|
||||
float pAccelerationAbs = stdext::random_range(m_pMinAcceleration, m_pMaxAcceleration);
|
||||
float pAccelerationAngle = stdext::random_range(m_pMinAccelerationAngle, m_pMaxAccelerationAngle);
|
||||
PointF pAcceleration(pAccelerationAbs * cos(pAccelerationAngle), pAccelerationAbs * sin(pAccelerationAngle));
|
||||
|
||||
ParticleSystemPtr particleSystem = m_parent.lock();
|
||||
|
@@ -38,7 +38,7 @@ bool ParticleManager::load(const std::string& filename)
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch(Exception& e) {
|
||||
} catch(stdext::exception& e) {
|
||||
logError("could not load particles: ", e.what());
|
||||
return false;
|
||||
}
|
||||
|
@@ -50,13 +50,13 @@ TexturePtr TextureManager::getTexture(const std::string& fileName)
|
||||
try {
|
||||
// currently only png textures are supported
|
||||
if(!boost::ends_with(filePath, ".png"))
|
||||
Fw::throwException("texture file format no supported");
|
||||
stdext::throw_exception("texture file format no supported");
|
||||
|
||||
// load texture file data
|
||||
std::stringstream fin;
|
||||
g_resources.loadFile(filePath, fin);
|
||||
texture = loadPNG(fin);
|
||||
} catch(Exception& e) {
|
||||
} catch(stdext::exception& e) {
|
||||
logError("unable to load texture '", fileName, "': ", e.what());
|
||||
texture = g_graphics.getEmptyTexture();
|
||||
}
|
||||
|
Reference in New Issue
Block a user