some optimizations
This commit is contained in:
parent
4c143f4a33
commit
1c5b906b5b
1
TODO
1
TODO
|
@ -48,6 +48,7 @@ clean sprites cache periodically
|
||||||
handle corrupt errors in dat/spr
|
handle corrupt errors in dat/spr
|
||||||
throw exceptions when fail to read a file
|
throw exceptions when fail to read a file
|
||||||
fix C++ exceptions messages inside onExtendedOpcode
|
fix C++ exceptions messages inside onExtendedOpcode
|
||||||
|
rework outfit masks drawing
|
||||||
|
|
||||||
* framework
|
* framework
|
||||||
rework Settings/g_configs
|
rework Settings/g_configs
|
||||||
|
|
|
@ -167,7 +167,6 @@ void Application::run()
|
||||||
if(!m_initialized)
|
if(!m_initialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//ticks_t lastPollTicks = g_clock.updateTicks();
|
|
||||||
m_stopping = false;
|
m_stopping = false;
|
||||||
m_running = true;
|
m_running = true;
|
||||||
|
|
||||||
|
@ -176,10 +175,10 @@ void Application::run()
|
||||||
|
|
||||||
g_lua.callGlobalField("g_app", "onRun");
|
g_lua.callGlobalField("g_app", "onRun");
|
||||||
|
|
||||||
while(!m_stopping) {
|
// first clock update
|
||||||
// only update the current time once per frame to gain performance
|
g_clock.update();
|
||||||
g_clock.updateTicks();
|
|
||||||
|
|
||||||
|
while(!m_stopping) {
|
||||||
// poll all events before rendering
|
// poll all events before rendering
|
||||||
poll();
|
poll();
|
||||||
|
|
||||||
|
@ -215,20 +214,16 @@ void Application::run()
|
||||||
m_foreground->copyFromScreen(viewportRect);
|
m_foreground->copyFromScreen(viewportRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//glClearColor(0,0,0,0);
|
||||||
|
//glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
// draw background (animated stuff)
|
// draw background (animated stuff)
|
||||||
m_backgroundFrameCounter.processNextFrame();
|
m_backgroundFrameCounter.processNextFrame();
|
||||||
g_ui.render(false);
|
g_ui.render(false);
|
||||||
|
|
||||||
// transform projection matrix to render upside down
|
|
||||||
Matrix3 projectionMatrix = g_painter->getProjectionMatrix();
|
|
||||||
projectionMatrix(2,2) *= -1.0f;
|
|
||||||
projectionMatrix(3,2) *= -1.0f;
|
|
||||||
|
|
||||||
// draw the foreground (steady stuff)
|
// draw the foreground (steady stuff)
|
||||||
g_painter->saveAndResetState();
|
g_painter->setColor(Color::white);
|
||||||
g_painter->setProjectionMatrix(projectionMatrix);
|
|
||||||
g_painter->drawTexturedRect(viewportRect, m_foreground, viewportRect);
|
g_painter->drawTexturedRect(viewportRect, m_foreground, viewportRect);
|
||||||
g_painter->restoreSavedState();
|
|
||||||
|
|
||||||
g_graphics.endRender();
|
g_graphics.endRender();
|
||||||
|
|
||||||
|
@ -236,6 +231,9 @@ void Application::run()
|
||||||
g_window.swapBuffers();
|
g_window.swapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only update the current time once per frame to gain performance
|
||||||
|
g_clock.update();
|
||||||
|
|
||||||
m_backgroundFrameCounter.update();
|
m_backgroundFrameCounter.update();
|
||||||
m_foregroundFrameCounter.update();
|
m_foregroundFrameCounter.update();
|
||||||
|
|
||||||
|
@ -246,7 +244,8 @@ void Application::run()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// sleeps until next poll to avoid massive cpu usage
|
// sleeps until next poll to avoid massive cpu usage
|
||||||
g_clock.sleep(POLL_CYCLE_DELAY+1);
|
stdext::millisleep(POLL_CYCLE_DELAY+1);
|
||||||
|
g_clock.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,6 +287,7 @@ void Application::resize(const Size& size)
|
||||||
m_onInputEvent = false;
|
m_onInputEvent = false;
|
||||||
|
|
||||||
m_foreground = TexturePtr(new Texture(size.width(), size.height()));
|
m_foreground = TexturePtr(new Texture(size.width(), size.height()));
|
||||||
|
m_foreground->setUpsideDown(true);
|
||||||
m_mustRepaint = true;
|
m_mustRepaint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "adaptativeframecounter.h"
|
#include "adaptativeframecounter.h"
|
||||||
|
#include "clock.h"
|
||||||
|
|
||||||
AdaptativeFrameCounter::AdaptativeFrameCounter()
|
AdaptativeFrameCounter::AdaptativeFrameCounter()
|
||||||
{
|
{
|
||||||
|
@ -35,8 +36,8 @@ AdaptativeFrameCounter::AdaptativeFrameCounter()
|
||||||
m_maxFps = 0;
|
m_maxFps = 0;
|
||||||
m_sleepMicros = 0;
|
m_sleepMicros = 0;
|
||||||
m_mediumFrameDelay = 0;
|
m_mediumFrameDelay = 0;
|
||||||
m_lastFpsUpdate = stdext::micros();
|
m_lastFpsUpdate = g_clock.micros();
|
||||||
m_lastPartialFpsUpdate = stdext::micros();
|
m_lastPartialFpsUpdate = g_clock.micros();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdaptativeFrameCounter::shouldProcessNextFrame()
|
bool AdaptativeFrameCounter::shouldProcessNextFrame()
|
||||||
|
@ -44,7 +45,7 @@ bool AdaptativeFrameCounter::shouldProcessNextFrame()
|
||||||
if(m_maxFps == 0)
|
if(m_maxFps == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ticks_t now = stdext::micros();
|
ticks_t now = g_clock.micros();
|
||||||
if(now - m_lastFrame < m_bestFrameDelay)
|
if(now - m_lastFrame < m_bestFrameDelay)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
@ -52,7 +53,7 @@ bool AdaptativeFrameCounter::shouldProcessNextFrame()
|
||||||
|
|
||||||
void AdaptativeFrameCounter::processNextFrame()
|
void AdaptativeFrameCounter::processNextFrame()
|
||||||
{
|
{
|
||||||
ticks_t now = stdext::micros();
|
ticks_t now = g_clock.micros();
|
||||||
m_frames++;
|
m_frames++;
|
||||||
m_partialFrames++;
|
m_partialFrames++;
|
||||||
m_frameDelaySum += now - m_lastFrame;
|
m_frameDelaySum += now - m_lastFrame;
|
||||||
|
@ -61,7 +62,7 @@ void AdaptativeFrameCounter::processNextFrame()
|
||||||
|
|
||||||
void AdaptativeFrameCounter::update()
|
void AdaptativeFrameCounter::update()
|
||||||
{
|
{
|
||||||
ticks_t now = stdext::micros();
|
ticks_t now = g_clock.micros();
|
||||||
ticks_t delta = now - m_lastPartialFpsUpdate;
|
ticks_t delta = now - m_lastPartialFpsUpdate;
|
||||||
if(delta > 41000 && m_partialFrames > 0) {
|
if(delta > 41000 && m_partialFrames > 0) {
|
||||||
m_partialFps = m_partialFrames / (delta / 1000000.0f);
|
m_partialFps = m_partialFrames / (delta / 1000000.0f);
|
||||||
|
@ -101,7 +102,7 @@ int AdaptativeFrameCounter::getMaximumSleepMicros()
|
||||||
{
|
{
|
||||||
if(m_maxFps == 0)
|
if(m_maxFps == 0)
|
||||||
return 0;
|
return 0;
|
||||||
return m_lastFrame + m_bestFrameDelay - stdext::micros();
|
return m_lastFrame + m_bestFrameDelay - g_clock.micros();
|
||||||
}
|
}
|
||||||
|
|
||||||
float AdaptativeFrameCounter::getFrameDelayHit()
|
float AdaptativeFrameCounter::getFrameDelayHit()
|
||||||
|
|
|
@ -22,30 +22,18 @@
|
||||||
|
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
|
|
||||||
// for usleep
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
Clock g_clock;
|
Clock g_clock;
|
||||||
|
|
||||||
Clock::Clock()
|
Clock::Clock()
|
||||||
{
|
{
|
||||||
m_startupTime = std::chrono::high_resolution_clock::now();
|
m_currentMicros = 0;
|
||||||
m_currentTicks = 0;
|
m_currentMillis = 0;
|
||||||
}
|
m_currentSeconds = 0;
|
||||||
ticks_t Clock::updateTicks()
|
|
||||||
{
|
|
||||||
m_currentTicks = asyncTicks();
|
|
||||||
m_currentTime = m_currentTicks/1000.0f;
|
|
||||||
return m_currentTicks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ticks_t Clock::asyncTicks()
|
void Clock::update()
|
||||||
{
|
{
|
||||||
auto timeNow = std::chrono::high_resolution_clock::now();
|
m_currentMicros = stdext::micros();
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(timeNow - m_startupTime).count();
|
m_currentMillis = m_currentMicros / 1000;
|
||||||
}
|
m_currentSeconds = m_currentMicros / 1000000.0f;
|
||||||
|
|
||||||
void Clock::sleep(int ms)
|
|
||||||
{
|
|
||||||
usleep(ms * 1000);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,23 +30,16 @@ class Clock
|
||||||
public:
|
public:
|
||||||
Clock();
|
Clock();
|
||||||
|
|
||||||
ticks_t updateTicks();
|
void update();
|
||||||
void sleep(int ms);
|
|
||||||
|
|
||||||
ticks_t asyncTicks();
|
ticks_t micros() { return m_currentMicros; }
|
||||||
ticks_t ticks() { return m_currentTicks; }
|
ticks_t millis() { return m_currentMillis; }
|
||||||
ticks_t ticksElapsed(ticks_t prevTicks) { return m_currentTicks - prevTicks; }
|
float seconds() { return m_currentSeconds; }
|
||||||
ticks_t ticksFor(int delay) { return m_currentTicks + delay; }
|
|
||||||
|
|
||||||
float asyncTime() { return asyncTicks()/1000.0f; }
|
|
||||||
float time() { return m_currentTime; }
|
|
||||||
float timeElapsed(float prevTime) { return m_currentTime - prevTime; }
|
|
||||||
float timeFor(float delay) { return m_currentTime + delay; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ticks_t m_currentTicks;
|
ticks_t m_currentMicros;
|
||||||
float m_currentTime;
|
ticks_t m_currentMillis;
|
||||||
std::chrono::system_clock::time_point m_startupTime;
|
float m_currentSeconds;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Clock g_clock;
|
extern Clock g_clock;
|
||||||
|
|
|
@ -53,11 +53,11 @@ class ScheduledEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScheduledEvent(const std::function<void()>& callback, int delay) : Event(callback) {
|
ScheduledEvent(const std::function<void()>& callback, int delay) : Event(callback) {
|
||||||
m_ticks = g_clock.ticksFor(delay);
|
m_ticks = g_clock.millis() + delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ticks() const { return m_ticks; }
|
int ticks() const { return m_ticks; }
|
||||||
int reamaningTicks() const { return m_ticks - g_clock.ticks(); }
|
int reamaningTicks() const { return m_ticks - g_clock.millis(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ticks_t m_ticks;
|
ticks_t m_ticks;
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
|
|
||||||
void Timer::restart()
|
void Timer::restart()
|
||||||
{
|
{
|
||||||
m_startTicks = g_clock.ticks();
|
m_startTicks = g_clock.millis();
|
||||||
m_stopped = false;
|
m_stopped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ticks_t Timer::ticksElapsed()
|
ticks_t Timer::ticksElapsed()
|
||||||
{
|
{
|
||||||
return g_clock.ticks() - m_startTicks;
|
return g_clock.millis() - m_startTicks;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ void FrameBuffer::resize(const Size& size)
|
||||||
|
|
||||||
m_texture = TexturePtr(new Texture(size.width(), size.height(), 4));
|
m_texture = TexturePtr(new Texture(size.width(), size.height(), 4));
|
||||||
m_texture->setSmooth(true);
|
m_texture->setSmooth(true);
|
||||||
|
m_texture->setUpsideDown(true);
|
||||||
|
|
||||||
if(m_fbo) {
|
if(m_fbo) {
|
||||||
internalBind();
|
internalBind();
|
||||||
|
@ -97,8 +98,8 @@ void FrameBuffer::bind()
|
||||||
internalBind();
|
internalBind();
|
||||||
|
|
||||||
Matrix3 projectionMatrix = { 2.0f/m_texture->getWidth(), 0.0f, 0.0f,
|
Matrix3 projectionMatrix = { 2.0f/m_texture->getWidth(), 0.0f, 0.0f,
|
||||||
0.0f, 2.0f/m_texture->getHeight(), 0.0f,
|
0.0f, -2.0f/m_texture->getHeight(), 0.0f,
|
||||||
-1.0f, -1.0f, 1.0f };
|
-1.0f, 1.0f, 1.0f };
|
||||||
g_painter->saveAndResetState();
|
g_painter->saveAndResetState();
|
||||||
g_painter->setProjectionMatrix(projectionMatrix);
|
g_painter->setProjectionMatrix(projectionMatrix);
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,13 @@ void Graphics::init()
|
||||||
// blending is always enabled
|
// blending is always enabled
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
|
||||||
|
// face culling may improve performance
|
||||||
|
/*
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glFrontFace(GL_CW);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
*/
|
||||||
|
|
||||||
// determine max texture size
|
// determine max texture size
|
||||||
static GLint maxTextureSize = -1;
|
static GLint maxTextureSize = -1;
|
||||||
if(maxTextureSize == -1)
|
if(maxTextureSize == -1)
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
|
|
||||||
struct PainterState {
|
struct PainterState {
|
||||||
Matrix3 projectionMatrix;
|
Matrix3 projectionMatrix;
|
||||||
Matrix2 textureMatrix;
|
Matrix3 textureMatrix;
|
||||||
Color color;
|
Color color;
|
||||||
float opacity;
|
float opacity;
|
||||||
Painter::CompositionMode compositionMode;
|
Painter::CompositionMode compositionMode;
|
||||||
|
@ -75,7 +75,7 @@ public:
|
||||||
virtual void drawBoundingRect(const Rect& dest, int innerLineWidth = 1) = 0;
|
virtual void drawBoundingRect(const Rect& dest, int innerLineWidth = 1) = 0;
|
||||||
|
|
||||||
virtual void setProjectionMatrix(const Matrix3& projectionMatrix) { m_projectionMatrix = projectionMatrix; }
|
virtual void setProjectionMatrix(const Matrix3& projectionMatrix) { m_projectionMatrix = projectionMatrix; }
|
||||||
virtual void setTextureMatrix(const Matrix2& textureMatrix) { m_textureMatrix = textureMatrix; }
|
virtual void setTextureMatrix(const Matrix3& textureMatrix) { m_textureMatrix = textureMatrix; }
|
||||||
virtual void setColor(const Color& color) { m_color = color; }
|
virtual void setColor(const Color& color) { m_color = color; }
|
||||||
virtual void setOpacity(float opacity) { m_opacity = opacity; }
|
virtual void setOpacity(float opacity) { m_opacity = opacity; }
|
||||||
virtual void setCompositionMode(CompositionMode compositionMode);
|
virtual void setCompositionMode(CompositionMode compositionMode);
|
||||||
|
@ -87,7 +87,7 @@ public:
|
||||||
void setTexture(const TexturePtr& texture) { setTexture(texture.get()); }
|
void setTexture(const TexturePtr& texture) { setTexture(texture.get()); }
|
||||||
|
|
||||||
Matrix3 getProjectionMatrix() { return m_projectionMatrix; }
|
Matrix3 getProjectionMatrix() { return m_projectionMatrix; }
|
||||||
Matrix2 getTextureMatrix() { return m_textureMatrix; }
|
Matrix3 getTextureMatrix() { return m_textureMatrix; }
|
||||||
Color getColor() { return m_color; }
|
Color getColor() { return m_color; }
|
||||||
float getOpacity() { return m_opacity; }
|
float getOpacity() { return m_opacity; }
|
||||||
CompositionMode getCompositionMode() { return m_compositionMode; }
|
CompositionMode getCompositionMode() { return m_compositionMode; }
|
||||||
|
@ -109,7 +109,7 @@ protected:
|
||||||
CoordsBuffer m_coordsBuffer;
|
CoordsBuffer m_coordsBuffer;
|
||||||
|
|
||||||
Matrix3 m_projectionMatrix;
|
Matrix3 m_projectionMatrix;
|
||||||
Matrix2 m_textureMatrix;
|
Matrix3 m_textureMatrix;
|
||||||
Color m_color;
|
Color m_color;
|
||||||
float m_opacity;
|
float m_opacity;
|
||||||
CompositionMode m_compositionMode;
|
CompositionMode m_compositionMode;
|
||||||
|
|
|
@ -195,7 +195,7 @@ void PainterOGL1::setProjectionMatrix(const Matrix3& projectionMatrix)
|
||||||
updateGlProjectionMatrix();
|
updateGlProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterOGL1::setTextureMatrix(const Matrix2& textureMatrix)
|
void PainterOGL1::setTextureMatrix(const Matrix3& textureMatrix)
|
||||||
{
|
{
|
||||||
// avoid re-updating texture matrix
|
// avoid re-updating texture matrix
|
||||||
if(m_textureMatrix == textureMatrix)
|
if(m_textureMatrix == textureMatrix)
|
||||||
|
@ -249,7 +249,7 @@ void PainterOGL1::updateGlTextureMatrix()
|
||||||
m_textureMatrix(1,1), m_textureMatrix(1,2), 0.0f, 0.0f,
|
m_textureMatrix(1,1), m_textureMatrix(1,2), 0.0f, 0.0f,
|
||||||
m_textureMatrix(2,1), m_textureMatrix(2,2), 0.0f, 0.0f,
|
m_textureMatrix(2,1), m_textureMatrix(2,2), 0.0f, 0.0f,
|
||||||
0.0f, 0.0f, 1.0f, 0.0f,
|
0.0f, 0.0f, 1.0f, 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 1.0f,
|
m_textureMatrix(3,1), m_textureMatrix(3,2), 0.0f, m_textureMatrix(3,3),
|
||||||
};
|
};
|
||||||
|
|
||||||
setMatrixMode(MatrixTexture);
|
setMatrixMode(MatrixTexture);
|
||||||
|
|
|
@ -57,7 +57,7 @@ public:
|
||||||
|
|
||||||
void setMatrixMode(MatrixMode matrixMode);
|
void setMatrixMode(MatrixMode matrixMode);
|
||||||
void setProjectionMatrix(const Matrix3& projectionMatrix);
|
void setProjectionMatrix(const Matrix3& projectionMatrix);
|
||||||
void setTextureMatrix(const Matrix2& textureMatrix);
|
void setTextureMatrix(const Matrix3& textureMatrix);
|
||||||
void setColor(const Color& color);
|
void setColor(const Color& color);
|
||||||
void setOpacity(float opacity);
|
void setOpacity(float opacity);
|
||||||
|
|
||||||
|
|
|
@ -28,13 +28,13 @@ static const std::string glslMainVertexShader = "\n\
|
||||||
|
|
||||||
static const std::string glslMainWithTexCoordsVertexShader = "\n\
|
static const std::string glslMainWithTexCoordsVertexShader = "\n\
|
||||||
attribute highp vec2 a_texCoord;\n\
|
attribute highp vec2 a_texCoord;\n\
|
||||||
uniform highp mat2 textureMatrix;\n\
|
uniform highp mat3 textureMatrix;\n\
|
||||||
varying highp vec2 texCoord;\n\
|
varying highp vec2 texCoord;\n\
|
||||||
highp vec4 calculatePosition();\n\
|
highp vec4 calculatePosition();\n\
|
||||||
void main()\n\
|
void main()\n\
|
||||||
{\n\
|
{\n\
|
||||||
gl_Position = calculatePosition();\n\
|
gl_Position = calculatePosition();\n\
|
||||||
texCoord = textureMatrix * a_texCoord;\n\
|
texCoord = textureMatrix * vec3(a_texCoord,1);\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
|
||||||
static std::string glslPositionOnlyVertexShader = "\n\
|
static std::string glslPositionOnlyVertexShader = "\n\
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
PainterShaderProgram::PainterShaderProgram()
|
PainterShaderProgram::PainterShaderProgram()
|
||||||
{
|
{
|
||||||
m_startTime = g_clock.time();
|
m_startTime = g_clock.seconds();
|
||||||
m_opacity = 1;
|
m_opacity = 1;
|
||||||
m_color = Color::white;
|
m_color = Color::white;
|
||||||
m_time = 0;
|
m_time = 0;
|
||||||
|
@ -36,7 +36,7 @@ PainterShaderProgram::PainterShaderProgram()
|
||||||
|
|
||||||
bool PainterShaderProgram::link()
|
bool PainterShaderProgram::link()
|
||||||
{
|
{
|
||||||
m_startTime = g_clock.time();
|
m_startTime = g_clock.seconds();
|
||||||
bindAttributeLocation(VERTEX_ATTR, "a_vertex");
|
bindAttributeLocation(VERTEX_ATTR, "a_vertex");
|
||||||
bindAttributeLocation(TEXCOORD_ATTR, "a_texCoord");
|
bindAttributeLocation(TEXCOORD_ATTR, "a_texCoord");
|
||||||
if(ShaderProgram::link()) {
|
if(ShaderProgram::link()) {
|
||||||
|
@ -72,7 +72,7 @@ void PainterShaderProgram::setProjectionMatrix(const Matrix3& projectionMatrix)
|
||||||
m_projectionMatrix = projectionMatrix;
|
m_projectionMatrix = projectionMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterShaderProgram::setTextureMatrix(const Matrix2& textureMatrix)
|
void PainterShaderProgram::setTextureMatrix(const Matrix3& textureMatrix)
|
||||||
{
|
{
|
||||||
if(textureMatrix == m_textureMatrix)
|
if(textureMatrix == m_textureMatrix)
|
||||||
return;
|
return;
|
||||||
|
@ -104,7 +104,7 @@ void PainterShaderProgram::setOpacity(float opacity)
|
||||||
|
|
||||||
void PainterShaderProgram::updateTime()
|
void PainterShaderProgram::updateTime()
|
||||||
{
|
{
|
||||||
float time = g_clock.timeElapsed(m_startTime);
|
float time = g_clock.seconds() - m_startTime;
|
||||||
if(m_time == time)
|
if(m_time == time)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
bool link();
|
bool link();
|
||||||
|
|
||||||
void setProjectionMatrix(const Matrix3& projectionMatrix);
|
void setProjectionMatrix(const Matrix3& projectionMatrix);
|
||||||
void setTextureMatrix(const Matrix2& textureMatrix);
|
void setTextureMatrix(const Matrix3& textureMatrix);
|
||||||
void setColor(const Color& color);
|
void setColor(const Color& color);
|
||||||
void setOpacity(float opacity);
|
void setOpacity(float opacity);
|
||||||
void updateTime();
|
void updateTime();
|
||||||
|
@ -63,7 +63,7 @@ private:
|
||||||
Color m_color;
|
Color m_color;
|
||||||
float m_opacity;
|
float m_opacity;
|
||||||
Matrix3 m_projectionMatrix;
|
Matrix3 m_projectionMatrix;
|
||||||
Matrix2 m_textureMatrix;
|
Matrix3 m_textureMatrix;
|
||||||
float m_time;
|
float m_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
ParticleSystem::ParticleSystem()
|
ParticleSystem::ParticleSystem()
|
||||||
{
|
{
|
||||||
m_finished = false;
|
m_finished = false;
|
||||||
m_lastUpdateTime = g_clock.time();
|
m_lastUpdateTime = g_clock.seconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParticleSystem::load(const OTMLNodePtr& node)
|
bool ParticleSystem::load(const OTMLNodePtr& node)
|
||||||
|
@ -79,10 +79,10 @@ void ParticleSystem::update()
|
||||||
}
|
}
|
||||||
|
|
||||||
// check time
|
// check time
|
||||||
float elapsedTime = g_clock.timeElapsed(m_lastUpdateTime);
|
float elapsedTime = g_clock.seconds() - m_lastUpdateTime;
|
||||||
if(elapsedTime < delay)
|
if(elapsedTime < delay)
|
||||||
return;
|
return;
|
||||||
m_lastUpdateTime = g_clock.time() - std::fmod(elapsedTime, delay);
|
m_lastUpdateTime = g_clock.seconds() - std::fmod(elapsedTime, delay);
|
||||||
|
|
||||||
for(int i = 0; i < elapsedTime / delay; ++i) {
|
for(int i = 0; i < elapsedTime / delay; ++i) {
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int
|
||||||
m_size.resize(width, height);
|
m_size.resize(width, height);
|
||||||
|
|
||||||
// convert texture pixel data to power of two size, only required for OpenGL 1.5 or older
|
// convert texture pixel data to power of two size, only required for OpenGL 1.5 or older
|
||||||
Size glSize;
|
|
||||||
std::vector<uint8> tmp;
|
std::vector<uint8> tmp;
|
||||||
if(!g_graphics.canUseNonPowerOfTwoTextures()) {
|
if(!g_graphics.canUseNonPowerOfTwoTextures()) {
|
||||||
int glWidth = 1;
|
int glWidth = 1;
|
||||||
|
@ -64,7 +63,7 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int
|
||||||
while(glHeight < height)
|
while(glHeight < height)
|
||||||
glHeight = glHeight << 1;
|
glHeight = glHeight << 1;
|
||||||
|
|
||||||
if(m_size != glSize && pixels) {
|
if(m_size != m_glSize && pixels) {
|
||||||
tmp.resize(glHeight*glWidth*channels, 0);
|
tmp.resize(glHeight*glWidth*channels, 0);
|
||||||
for(int y=0; y<height; ++y)
|
for(int y=0; y<height; ++y)
|
||||||
for(int x=0; x<width; ++x)
|
for(int x=0; x<width; ++x)
|
||||||
|
@ -73,15 +72,14 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int
|
||||||
pixels = &tmp[0];
|
pixels = &tmp[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
glSize.resize(glWidth, glHeight);
|
m_glSize.resize(glWidth, glHeight);
|
||||||
} else
|
} else
|
||||||
glSize = m_size;
|
m_glSize = m_size;
|
||||||
|
|
||||||
m_transformMatrix = { 1.0f/glSize.width(), 0.0f,
|
setupTranformMatrix();
|
||||||
0.0f, 1.0f/glSize.height() };
|
|
||||||
|
|
||||||
// checks texture max size
|
// checks texture max size
|
||||||
if(std::max(glSize.width(), glSize.height()) > g_graphics.getMaxTextureSize()) {
|
if(std::max(m_glSize.width(), m_glSize.height()) > g_graphics.getMaxTextureSize()) {
|
||||||
g_logger.error(stdext::format("loading texture with size %dx%d failed, "
|
g_logger.error(stdext::format("loading texture with size %dx%d failed, "
|
||||||
"the maximum size allowed by the graphics card is %dx%d,"
|
"the maximum size allowed by the graphics card is %dx%d,"
|
||||||
"to prevent crashes the texture will be displayed as a blank texture",
|
"to prevent crashes the texture will be displayed as a blank texture",
|
||||||
|
@ -115,7 +113,7 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int
|
||||||
}
|
}
|
||||||
|
|
||||||
// load pixels into gl memory
|
// load pixels into gl memory
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, glSize.width(), glSize.height(), 0, format, GL_UNSIGNED_BYTE, pixels);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_glSize.width(), m_glSize.height(), 0, format, GL_UNSIGNED_BYTE, pixels);
|
||||||
|
|
||||||
GLint texParam = GL_REPEAT;
|
GLint texParam = GL_REPEAT;
|
||||||
if(g_graphics.canUseClampToEdge())
|
if(g_graphics.canUseClampToEdge())
|
||||||
|
@ -182,6 +180,14 @@ void Texture::setSmooth(bool smooth)
|
||||||
setupFilters();
|
setupFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Texture::setUpsideDown(bool upsideDown)
|
||||||
|
{
|
||||||
|
if(m_upsideDown == upsideDown)
|
||||||
|
return;
|
||||||
|
m_upsideDown = upsideDown;
|
||||||
|
setupTranformMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
void Texture::generateSoftwareMipmaps(std::vector<uint8> inPixels)
|
void Texture::generateSoftwareMipmaps(std::vector<uint8> inPixels)
|
||||||
{
|
{
|
||||||
bind();
|
bind();
|
||||||
|
@ -261,3 +267,16 @@ void Texture::setupFilters()
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Texture::setupTranformMatrix()
|
||||||
|
{
|
||||||
|
if(m_upsideDown) {
|
||||||
|
m_transformMatrix = { 1.0f/m_glSize.width(), 0.0f, 0.0f,
|
||||||
|
0.0f, -1.0f/m_glSize.height(), 0.0f,
|
||||||
|
0.0f, 1.0f, 1.0f };
|
||||||
|
} else {
|
||||||
|
m_transformMatrix = { 1.0f/m_glSize.width(), 0.0f, 0.0f,
|
||||||
|
0.0f, 1.0f/m_glSize.height(), 0.0f,
|
||||||
|
0.0f, 0.0f, 1.0f };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -46,26 +46,30 @@ public:
|
||||||
|
|
||||||
/// Activate texture anti-aliasing giving a better look when they are resized
|
/// Activate texture anti-aliasing giving a better look when they are resized
|
||||||
void setSmooth(bool smooth);
|
void setSmooth(bool smooth);
|
||||||
|
void setUpsideDown(bool upsideDown);
|
||||||
|
|
||||||
GLuint getId() { return m_textureId; }
|
GLuint getId() { return m_textureId; }
|
||||||
|
|
||||||
int getWidth() { return m_size.width(); }
|
int getWidth() { return m_size.width(); }
|
||||||
int getHeight() { return m_size.height(); }
|
int getHeight() { return m_size.height(); }
|
||||||
const Size& getSize() { return m_size; }
|
const Size& getSize() { return m_size; }
|
||||||
const Matrix2& getTransformMatrix() { return m_transformMatrix; }
|
const Matrix3& getTransformMatrix() { return m_transformMatrix; }
|
||||||
|
|
||||||
bool isEmpty() { return m_textureId == 0; }
|
bool isEmpty() { return m_textureId == 0; }
|
||||||
bool hasMipmaps() { return m_hasMipmaps; }
|
bool hasMipmaps() { return m_hasMipmaps; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setupFilters();
|
void setupFilters();
|
||||||
|
void setupTranformMatrix();
|
||||||
GLuint internalLoadGLTexture(uchar* pixels, int channels, int w, int h);
|
GLuint internalLoadGLTexture(uchar* pixels, int channels, int w, int h);
|
||||||
|
|
||||||
GLuint m_textureId;
|
GLuint m_textureId;
|
||||||
Size m_size;
|
Size m_size;
|
||||||
Matrix2 m_transformMatrix;
|
Size m_glSize;
|
||||||
|
Matrix3 m_transformMatrix;
|
||||||
Boolean<false> m_hasMipmaps;
|
Boolean<false> m_hasMipmaps;
|
||||||
Boolean<false> m_smooth;
|
Boolean<false> m_smooth;
|
||||||
|
Boolean<false> m_upsideDown;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -74,8 +74,8 @@ void PlatformWindow::processKeyDown(Fw::Key keyCode)
|
||||||
|
|
||||||
m_inputEvent.reset(Fw::KeyPressInputEvent);
|
m_inputEvent.reset(Fw::KeyPressInputEvent);
|
||||||
m_inputEvent.keyCode = keyCode;
|
m_inputEvent.keyCode = keyCode;
|
||||||
m_lastKeysPress[keyCode] = g_clock.ticks();
|
m_lastKeysPress[keyCode] = g_clock.millis();
|
||||||
m_firstKeysPress[keyCode] = g_clock.ticks();
|
m_firstKeysPress[keyCode] = g_clock.millis();
|
||||||
m_onInputEvent(m_inputEvent);
|
m_onInputEvent(m_inputEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,14 +141,14 @@ void PlatformWindow::fireKeysPress()
|
||||||
|
|
||||||
ticks_t lastPressTicks = m_lastKeysPress[keyCode];
|
ticks_t lastPressTicks = m_lastKeysPress[keyCode];
|
||||||
ticks_t firstKeyPress = m_firstKeysPress[keyCode];
|
ticks_t firstKeyPress = m_firstKeysPress[keyCode];
|
||||||
if(g_clock.ticksElapsed(lastPressTicks) >= KEY_PRESS_REPEAT_INTERVAL) {
|
if(g_clock.millis() - lastPressTicks >= KEY_PRESS_REPEAT_INTERVAL) {
|
||||||
if(m_onInputEvent) {
|
if(m_onInputEvent) {
|
||||||
m_inputEvent.reset(Fw::KeyPressInputEvent);
|
m_inputEvent.reset(Fw::KeyPressInputEvent);
|
||||||
m_inputEvent.keyCode = keyCode;
|
m_inputEvent.keyCode = keyCode;
|
||||||
m_inputEvent.autoRepeatTicks = g_clock.ticksElapsed(firstKeyPress);
|
m_inputEvent.autoRepeatTicks = g_clock.millis() - firstKeyPress;
|
||||||
m_onInputEvent(m_inputEvent);
|
m_onInputEvent(m_inputEvent);
|
||||||
}
|
}
|
||||||
m_lastKeysPress[keyCode] = g_clock.ticks();
|
m_lastKeysPress[keyCode] = g_clock.millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ void SoundManager::terminate()
|
||||||
void SoundManager::poll()
|
void SoundManager::poll()
|
||||||
{
|
{
|
||||||
static ticks_t lastUpdate = 0;
|
static ticks_t lastUpdate = 0;
|
||||||
ticks_t now = g_clock.ticks();
|
ticks_t now = g_clock.millis();
|
||||||
|
|
||||||
if(now - lastUpdate < POLL_DELAY)
|
if(now - lastUpdate < POLL_DELAY)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -114,7 +114,7 @@ void SoundSource::setVelocity(const Point& velocity)
|
||||||
|
|
||||||
void SoundSource::setFading(FadeState state, float fadeTime)
|
void SoundSource::setFading(FadeState state, float fadeTime)
|
||||||
{
|
{
|
||||||
float now = g_clock.time();
|
float now = g_clock.seconds();
|
||||||
if(m_fadeState != NoFading) {
|
if(m_fadeState != NoFading) {
|
||||||
float elapsed = now - m_fadeStartTime;
|
float elapsed = now - m_fadeStartTime;
|
||||||
float add;
|
float add;
|
||||||
|
@ -132,7 +132,7 @@ void SoundSource::setFading(FadeState state, float fadeTime)
|
||||||
|
|
||||||
void SoundSource::update()
|
void SoundSource::update()
|
||||||
{
|
{
|
||||||
float now = g_clock.time();
|
float now = g_clock.seconds();
|
||||||
if(m_fadeState == FadingOn) {
|
if(m_fadeState == FadingOn) {
|
||||||
float elapsed = now - m_fadeStartTime;
|
float elapsed = now - m_fadeStartTime;
|
||||||
if(elapsed >= m_fadeTime) {
|
if(elapsed >= m_fadeTime) {
|
||||||
|
|
|
@ -64,7 +64,8 @@ void UITextEdit::drawSelf(bool foregroundPane)
|
||||||
assert(m_cursorPos <= textLength);
|
assert(m_cursorPos <= textLength);
|
||||||
// draw every 333ms
|
// draw every 333ms
|
||||||
const int delay = 333;
|
const int delay = 333;
|
||||||
if(g_clock.ticksElapsed(m_cursorTicks) <= delay) {
|
int elapsed = g_clock.millis() - m_cursorTicks;
|
||||||
|
if(elapsed <= delay) {
|
||||||
Rect cursorRect;
|
Rect cursorRect;
|
||||||
// when cursor is at 0 or is the first visible element
|
// when cursor is at 0 or is the first visible element
|
||||||
if(m_cursorPos == 0 || m_cursorPos == m_startRenderPos)
|
if(m_cursorPos == 0 || m_cursorPos == m_startRenderPos)
|
||||||
|
@ -72,8 +73,8 @@ void UITextEdit::drawSelf(bool foregroundPane)
|
||||||
else
|
else
|
||||||
cursorRect = Rect(m_glyphsCoords[m_cursorPos-1].right(), m_glyphsCoords[m_cursorPos-1].top(), 1, m_font->getGlyphHeight());
|
cursorRect = Rect(m_glyphsCoords[m_cursorPos-1].right(), m_glyphsCoords[m_cursorPos-1].top(), 1, m_font->getGlyphHeight());
|
||||||
g_painter->drawFilledRect(cursorRect);
|
g_painter->drawFilledRect(cursorRect);
|
||||||
} else if(g_clock.ticksElapsed(m_cursorTicks) >= 2*delay) {
|
} else if(elapsed >= 2*delay) {
|
||||||
m_cursorTicks = g_clock.ticks();
|
m_cursorTicks = g_clock.millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -512,5 +513,5 @@ bool UITextEdit::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
||||||
|
|
||||||
void UITextEdit::blinkCursor()
|
void UITextEdit::blinkCursor()
|
||||||
{
|
{
|
||||||
m_cursorTicks = g_clock.ticks();
|
m_cursorTicks = g_clock.millis();
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool ani
|
||||||
|
|
||||||
if(isAnimateAlways() && animateIdle) {
|
if(isAnimateAlways() && animateIdle) {
|
||||||
int ticksPerFrame = 1000 / getAnimationPhases();
|
int ticksPerFrame = 1000 / getAnimationPhases();
|
||||||
animationPhase = (g_clock.ticks() % (ticksPerFrame * getAnimationPhases())) / ticksPerFrame;
|
animationPhase = (g_clock.millis() % (ticksPerFrame * getAnimationPhases())) / ticksPerFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
// xPattern => creature direction
|
// xPattern => creature direction
|
||||||
|
@ -182,7 +182,7 @@ void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool ani
|
||||||
|
|
||||||
if(animationPhases > 1) {
|
if(animationPhases > 1) {
|
||||||
if(animateIdle)
|
if(animateIdle)
|
||||||
animationPhase = (g_clock.ticks() % (animateTicks * animationPhases)) / animateTicks;
|
animationPhase = (g_clock.millis() % (animateTicks * animationPhases)) / animateTicks;
|
||||||
else
|
else
|
||||||
animationPhase = animationPhases-1;
|
animationPhase = animationPhases-1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate)
|
||||||
int animationPhase = 0;
|
int animationPhase = 0;
|
||||||
if(getAnimationPhases() > 1) {
|
if(getAnimationPhases() > 1) {
|
||||||
if(animate)
|
if(animate)
|
||||||
animationPhase = (g_clock.ticks() % (Otc::ITEM_TICKS_PER_FRAME * getAnimationPhases())) / Otc::ITEM_TICKS_PER_FRAME;
|
animationPhase = (g_clock.millis() % (Otc::ITEM_TICKS_PER_FRAME * getAnimationPhases())) / Otc::ITEM_TICKS_PER_FRAME;
|
||||||
else
|
else
|
||||||
animationPhase = getAnimationPhases()-1;
|
animationPhase = getAnimationPhases()-1;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate)
|
||||||
m_type->draw(dest, scaleFactor, 0, xPattern, yPattern, zPattern, animationPhase);
|
m_type->draw(dest, scaleFactor, 0, xPattern, yPattern, zPattern, animationPhase);
|
||||||
|
|
||||||
// release draw shader
|
// release draw shader
|
||||||
g_painter->resetShaderProgram();
|
//g_painter->resetShaderProgram();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::setId(uint32 id)
|
void Item::setId(uint32 id)
|
||||||
|
|
Loading…
Reference in New Issue