mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
bunch of optimizations
This commit is contained in:
@@ -100,7 +100,7 @@ void CoordsBuffer::cacheVertexArrays()
|
||||
m_vertices.clear();
|
||||
m_textureCoords.clear();
|
||||
|
||||
for(int i=0;i<numDestRects;++i) {
|
||||
for(register int i=0;i<numDestRects;++i) {
|
||||
m_vertices.addRect(m_destRects[i]);
|
||||
if(numSrcRects == numDestRects)
|
||||
m_textureCoords.addRect(m_srcRects[i]);
|
||||
|
@@ -38,13 +38,13 @@ public:
|
||||
/// Simple text render starting at startPos
|
||||
void renderText(const std::string& text,
|
||||
const Point& startPos,
|
||||
const Color& color = Fw::white);
|
||||
const Color& color = Color::white);
|
||||
|
||||
/// Advanced text render delimited by a screen region and alignment
|
||||
void renderText(const std::string& text,
|
||||
const Rect& screenCoords,
|
||||
Fw::AlignmentFlag align = Fw::AlignTopLeft,
|
||||
const Color& color = Fw::white);
|
||||
const Color& color = Color::white);
|
||||
|
||||
/// Calculate glyphs positions to use on render, also calculates textBoxSize if wanted
|
||||
const std::vector<Point>& calculateGlyphsPositions(const std::string& text,
|
||||
|
@@ -28,7 +28,7 @@ uint FrameBuffer::boundFbo = 0;
|
||||
|
||||
FrameBuffer::FrameBuffer()
|
||||
{
|
||||
m_clearColor = Fw::alpha;
|
||||
m_clearColor = Color::alpha;
|
||||
|
||||
glGenFramebuffers(1, &m_fbo);
|
||||
if(!m_fbo)
|
||||
@@ -37,7 +37,7 @@ FrameBuffer::FrameBuffer()
|
||||
|
||||
FrameBuffer::FrameBuffer(const Size& size)
|
||||
{
|
||||
m_clearColor = Fw::alpha;
|
||||
m_clearColor = Color::alpha;
|
||||
|
||||
glGenFramebuffers(1, &m_fbo);
|
||||
if(!m_fbo)
|
||||
|
@@ -32,7 +32,7 @@ Painter g_painter;
|
||||
|
||||
void Painter::init()
|
||||
{
|
||||
setColor(Fw::white);
|
||||
setColor(Color::white);
|
||||
setOpacity(1.0f);
|
||||
setCompositionMode(CompositionMode_Normal);
|
||||
|
||||
@@ -67,16 +67,11 @@ void Painter::drawProgram(const PainterShaderProgramPtr& program, CoordsBuffer&
|
||||
|
||||
void Painter::drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture)
|
||||
{
|
||||
PainterShaderProgramPtr program = m_customProgram ? m_customProgram : m_drawTexturedProgram;
|
||||
PainterShaderProgramPtr& program = m_customProgram ? m_customProgram : m_drawTexturedProgram;
|
||||
program->setTexture(texture);
|
||||
drawProgram(program, coordsBuffer);
|
||||
}
|
||||
|
||||
void Painter::drawTexturedRect(const Rect& dest, const TexturePtr& texture)
|
||||
{
|
||||
drawTexturedRect(dest, texture, Rect(Point(0,0), texture->getSize()));
|
||||
}
|
||||
|
||||
void Painter::drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src)
|
||||
{
|
||||
if(dest.isEmpty() || src.isEmpty() || !texture->getId())
|
||||
@@ -153,7 +148,7 @@ void Painter::saveAndResetState()
|
||||
m_oldCompostionMode = m_compostionMode;
|
||||
|
||||
releaseCustomProgram();
|
||||
setColor(Fw::white);
|
||||
setColor(Color::white);
|
||||
setOpacity(1);
|
||||
setCompositionMode(CompositionMode_Normal);
|
||||
}
|
||||
@@ -166,7 +161,7 @@ void Painter::restoreSavedState()
|
||||
setCompositionMode(m_oldCompostionMode);
|
||||
|
||||
m_oldCustomProgram = nullptr;
|
||||
m_oldColor = Fw::white;
|
||||
m_oldColor = Color::white;
|
||||
m_oldOpacity = 1;
|
||||
m_oldCompostionMode = CompositionMode_Normal;
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include <framework/util/databuffer.h>
|
||||
#include "coordsbuffer.h"
|
||||
#include "paintershaderprogram.h"
|
||||
#include "texture.h"
|
||||
|
||||
class Painter
|
||||
{
|
||||
@@ -44,8 +45,8 @@ public:
|
||||
|
||||
void drawProgram(const PainterShaderProgramPtr& program, CoordsBuffer& coordsBuffer, PainterShaderProgram::DrawMode drawMode = PainterShaderProgram::Triangles);
|
||||
void drawTextureCoords(CoordsBuffer& coordsBuffer, const TexturePtr& texture);
|
||||
void drawTexturedRect(const Rect& dest, const TexturePtr& texture);
|
||||
void drawTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
||||
void drawTexturedRect(const Rect& dest, const TexturePtr& texture) { drawTexturedRect(dest, texture, Rect(Point(0,0), texture->getSize())); }
|
||||
void drawRepeatedTexturedRect(const Rect& dest, const TexturePtr& texture, const Rect& src);
|
||||
void drawFilledRect(const Rect& dest);
|
||||
void drawBoundingRect(const Rect& dest, int innerLineWidth = 1);
|
||||
|
@@ -29,6 +29,7 @@
|
||||
PainterShaderProgram::PainterShaderProgram()
|
||||
{
|
||||
m_textures.fill(std::make_tuple(-1, 0));
|
||||
m_startTime = g_clock.time();
|
||||
}
|
||||
|
||||
bool PainterShaderProgram::link()
|
||||
@@ -44,7 +45,7 @@ bool PainterShaderProgram::link()
|
||||
bindUniformLocation(TIME_UNIFORM, "time");
|
||||
return true;
|
||||
}
|
||||
m_startTimer.restart();
|
||||
m_startTime = g_clock.time();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -94,7 +95,7 @@ void PainterShaderProgram::draw(const CoordsBuffer& coordsBuffer, DrawMode drawM
|
||||
{
|
||||
bind();
|
||||
|
||||
setUniformValue(TIME_UNIFORM, (float)m_startTimer.timeElapsed());
|
||||
setUniformValue(TIME_UNIFORM, g_clock.timeElapsed(m_startTime));
|
||||
|
||||
int numVertices = coordsBuffer.getVertexCount();
|
||||
if(numVertices == 0)
|
||||
|
@@ -58,7 +58,7 @@ public:
|
||||
|
||||
private:
|
||||
DrawMode m_drawMode;
|
||||
Timer m_startTimer;
|
||||
float m_startTime;
|
||||
std::array<std::tuple<int, int>, 4> m_textures;
|
||||
};
|
||||
|
||||
|
@@ -56,7 +56,7 @@ void Particle::render()
|
||||
}
|
||||
}
|
||||
|
||||
void Particle::update(double elapsedTime)
|
||||
void Particle::update(float elapsedTime)
|
||||
{
|
||||
// check if finished
|
||||
if(m_duration >= 0 && m_elapsedTime >= m_duration) {
|
||||
@@ -71,7 +71,7 @@ void Particle::update(double elapsedTime)
|
||||
m_elapsedTime += elapsedTime;
|
||||
}
|
||||
|
||||
void Particle::updatePosition(double elapsedTime)
|
||||
void Particle::updatePosition(float elapsedTime)
|
||||
{
|
||||
if(m_ignorePhysicsAfter < 0 || m_elapsedTime < m_ignorePhysicsAfter ) {
|
||||
// update position
|
||||
|
@@ -32,7 +32,7 @@ public:
|
||||
Particle(const Point& pos, const Size& startSize, const Size& finalSize, const PointF& velocity, const PointF& acceleration, float duration, float ignorePhysicsAfter, const std::vector<Color>& colors, const std::vector<float>& colorsStops, Painter::CompositionMode compositionMode = Painter::CompositionMode_Normal, TexturePtr texture = nullptr);
|
||||
|
||||
void render();
|
||||
void update(double elapsedTime);
|
||||
void update(float elapsedTime);
|
||||
|
||||
bool hasFinished() { return m_finished; }
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
private:
|
||||
void updateColor();
|
||||
void updatePosition(double elapsedTime);
|
||||
void updatePosition(float elapsedTime);
|
||||
void updateSize();
|
||||
|
||||
Color m_color;
|
||||
@@ -58,7 +58,7 @@ private:
|
||||
Rect m_rect;
|
||||
Painter::CompositionMode m_compositionMode;
|
||||
float m_duration, m_ignorePhysicsAfter;
|
||||
double m_elapsedTime;
|
||||
float m_elapsedTime;
|
||||
bool m_finished;
|
||||
};
|
||||
|
||||
|
@@ -33,7 +33,7 @@ ParticleAffector::ParticleAffector()
|
||||
m_elapsedTime = 0;
|
||||
}
|
||||
|
||||
void ParticleAffector::update(double elapsedTime)
|
||||
void ParticleAffector::update(float elapsedTime)
|
||||
{
|
||||
if(m_duration >= 0 && m_elapsedTime >= m_duration + m_delay) {
|
||||
m_finished = true;
|
||||
@@ -94,7 +94,7 @@ bool GravityAffector::load(const OTMLNodePtr& node)
|
||||
return true;
|
||||
}
|
||||
|
||||
void GravityAffector::updateParticle(const ParticlePtr& particle, double elapsedTime)
|
||||
void GravityAffector::updateParticle(const ParticlePtr& particle, float elapsedTime)
|
||||
{
|
||||
if(!m_active)
|
||||
return;
|
||||
@@ -126,7 +126,7 @@ bool AttractionAffector::load(const OTMLNodePtr& node)
|
||||
return true;
|
||||
}
|
||||
|
||||
void AttractionAffector::updateParticle(const ParticlePtr& particle, double elapsedTime)
|
||||
void AttractionAffector::updateParticle(const ParticlePtr& particle, float elapsedTime)
|
||||
{
|
||||
if(!m_active)
|
||||
return;
|
||||
|
@@ -30,22 +30,22 @@ class ParticleAffector {
|
||||
public:
|
||||
ParticleAffector();
|
||||
|
||||
void update(double elapsedTime);
|
||||
void update(float elapsedTime);
|
||||
virtual bool load(const OTMLNodePtr& node);
|
||||
virtual void updateParticle(const ParticlePtr&, double) {}
|
||||
virtual void updateParticle(const ParticlePtr&, float) {}
|
||||
|
||||
bool hasFinished() { return m_finished; }
|
||||
|
||||
protected:
|
||||
bool m_finished, m_active;
|
||||
float m_delay, m_duration;
|
||||
double m_elapsedTime;
|
||||
float m_elapsedTime;
|
||||
};
|
||||
|
||||
class GravityAffector : public ParticleAffector {
|
||||
public:
|
||||
bool load(const OTMLNodePtr& node);
|
||||
void updateParticle(const ParticlePtr& particle, double elapsedTime);
|
||||
void updateParticle(const ParticlePtr& particle, float elapsedTime);
|
||||
|
||||
private:
|
||||
float m_angle, m_gravity;
|
||||
@@ -54,7 +54,7 @@ private:
|
||||
class AttractionAffector : public ParticleAffector {
|
||||
public:
|
||||
bool load(const OTMLNodePtr& node);
|
||||
void updateParticle(const ParticlePtr& particle, double elapsedTime);
|
||||
void updateParticle(const ParticlePtr& particle, float elapsedTime);
|
||||
|
||||
private:
|
||||
Point m_position;
|
||||
|
@@ -180,7 +180,7 @@ bool ParticleEmitter::load(const OTMLNodePtr& node)
|
||||
return true;
|
||||
}
|
||||
|
||||
void ParticleEmitter::update(double elapsedTime)
|
||||
void ParticleEmitter::update(float elapsedTime)
|
||||
{
|
||||
// check if finished
|
||||
if(m_duration >= 0 && m_elapsedTime >= m_duration + m_delay) {
|
||||
|
@@ -36,7 +36,7 @@ public:
|
||||
|
||||
bool load(const OTMLNodePtr& node);
|
||||
|
||||
void update(double elapsedTime);
|
||||
void update(float elapsedTime);
|
||||
|
||||
bool hasFinished() { return m_finished; }
|
||||
|
||||
@@ -46,7 +46,7 @@ private:
|
||||
// self related
|
||||
Point m_position;
|
||||
float m_duration, m_delay;
|
||||
double m_elapsedTime;
|
||||
float m_elapsedTime;
|
||||
bool m_finished, m_active;
|
||||
float m_burstRate;
|
||||
int m_currentBurst, m_burstCount;
|
||||
|
@@ -70,7 +70,7 @@ void ParticleSystem::render()
|
||||
|
||||
void ParticleSystem::update()
|
||||
{
|
||||
static const double delay = 0.0166; // 60 updates/s
|
||||
static const float delay = 0.0166; // 60 updates/s
|
||||
|
||||
// check if finished
|
||||
if(m_particles.empty() && m_emitters.empty()) {
|
||||
@@ -79,7 +79,7 @@ void ParticleSystem::update()
|
||||
}
|
||||
|
||||
// check time
|
||||
double elapsedTime = g_clock.timeElapsed(m_lastUpdateTime);
|
||||
float elapsedTime = g_clock.timeElapsed(m_lastUpdateTime);
|
||||
if(elapsedTime < delay)
|
||||
return;
|
||||
m_lastUpdateTime = g_clock.time() - std::fmod(elapsedTime, delay);
|
||||
|
@@ -42,7 +42,7 @@ public:
|
||||
|
||||
private:
|
||||
bool m_finished;
|
||||
double m_lastUpdateTime;
|
||||
float m_lastUpdateTime;
|
||||
std::list<ParticlePtr> m_particles;
|
||||
std::list<ParticleEmitterPtr> m_emitters;
|
||||
std::list<ParticleAffectorPtr> m_affectors;
|
||||
|
Reference in New Issue
Block a user