From 1c5b906b5b8b457245f4e8d81d7c13adbcff80a5 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sat, 2 Jun 2012 11:43:27 -0300 Subject: [PATCH] some optimizations --- TODO | 1 + src/framework/application.cpp | 26 +++++++------- src/framework/core/adaptativeframecounter.cpp | 13 +++---- src/framework/core/clock.cpp | 26 ++++---------- src/framework/core/clock.h | 21 ++++------- src/framework/core/eventdispatcher.h | 4 +-- src/framework/core/timer.cpp | 4 +-- src/framework/graphics/framebuffer.cpp | 5 +-- src/framework/graphics/graphics.cpp | 7 ++++ src/framework/graphics/painter.h | 8 ++--- src/framework/graphics/painterogl1.cpp | 10 +++--- src/framework/graphics/painterogl1.h | 2 +- .../graphics/painterogl2_shadersources.h | 4 +-- .../graphics/paintershaderprogram.cpp | 8 ++--- src/framework/graphics/paintershaderprogram.h | 4 +-- src/framework/graphics/particlesystem.cpp | 6 ++-- src/framework/graphics/texture.cpp | 35 ++++++++++++++----- src/framework/graphics/texture.h | 8 +++-- src/framework/platform/platformwindow.cpp | 10 +++--- src/framework/sound/soundmanager.cpp | 2 +- src/framework/sound/soundsource.cpp | 4 +-- src/framework/ui/uitextedit.cpp | 9 ++--- src/otclient/core/creature.cpp | 4 +-- src/otclient/core/item.cpp | 4 +-- 24 files changed, 120 insertions(+), 105 deletions(-) diff --git a/TODO b/TODO index 86adebb6..c04b2b89 100644 --- a/TODO +++ b/TODO @@ -48,6 +48,7 @@ clean sprites cache periodically handle corrupt errors in dat/spr throw exceptions when fail to read a file fix C++ exceptions messages inside onExtendedOpcode +rework outfit masks drawing * framework rework Settings/g_configs diff --git a/src/framework/application.cpp b/src/framework/application.cpp index ebe69c37..7a067ffe 100644 --- a/src/framework/application.cpp +++ b/src/framework/application.cpp @@ -167,7 +167,6 @@ void Application::run() if(!m_initialized) return; - //ticks_t lastPollTicks = g_clock.updateTicks(); m_stopping = false; m_running = true; @@ -176,10 +175,10 @@ void Application::run() g_lua.callGlobalField("g_app", "onRun"); - while(!m_stopping) { - // only update the current time once per frame to gain performance - g_clock.updateTicks(); + // first clock update + g_clock.update(); + while(!m_stopping) { // poll all events before rendering poll(); @@ -215,20 +214,16 @@ void Application::run() m_foreground->copyFromScreen(viewportRect); } + //glClearColor(0,0,0,0); + //glClear(GL_COLOR_BUFFER_BIT); + // draw background (animated stuff) m_backgroundFrameCounter.processNextFrame(); 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) - g_painter->saveAndResetState(); - g_painter->setProjectionMatrix(projectionMatrix); + g_painter->setColor(Color::white); g_painter->drawTexturedRect(viewportRect, m_foreground, viewportRect); - g_painter->restoreSavedState(); g_graphics.endRender(); @@ -236,6 +231,9 @@ void Application::run() g_window.swapBuffers(); } + // only update the current time once per frame to gain performance + g_clock.update(); + m_backgroundFrameCounter.update(); m_foregroundFrameCounter.update(); @@ -246,7 +244,8 @@ void Application::run() } else { // 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_foreground = TexturePtr(new Texture(size.width(), size.height())); + m_foreground->setUpsideDown(true); m_mustRepaint = true; } diff --git a/src/framework/core/adaptativeframecounter.cpp b/src/framework/core/adaptativeframecounter.cpp index 649daebe..2e1b1cfe 100644 --- a/src/framework/core/adaptativeframecounter.cpp +++ b/src/framework/core/adaptativeframecounter.cpp @@ -21,6 +21,7 @@ */ #include "adaptativeframecounter.h" +#include "clock.h" AdaptativeFrameCounter::AdaptativeFrameCounter() { @@ -35,8 +36,8 @@ AdaptativeFrameCounter::AdaptativeFrameCounter() m_maxFps = 0; m_sleepMicros = 0; m_mediumFrameDelay = 0; - m_lastFpsUpdate = stdext::micros(); - m_lastPartialFpsUpdate = stdext::micros(); + m_lastFpsUpdate = g_clock.micros(); + m_lastPartialFpsUpdate = g_clock.micros(); } bool AdaptativeFrameCounter::shouldProcessNextFrame() @@ -44,7 +45,7 @@ bool AdaptativeFrameCounter::shouldProcessNextFrame() if(m_maxFps == 0) return true; - ticks_t now = stdext::micros(); + ticks_t now = g_clock.micros(); if(now - m_lastFrame < m_bestFrameDelay) return false; return true; @@ -52,7 +53,7 @@ bool AdaptativeFrameCounter::shouldProcessNextFrame() void AdaptativeFrameCounter::processNextFrame() { - ticks_t now = stdext::micros(); + ticks_t now = g_clock.micros(); m_frames++; m_partialFrames++; m_frameDelaySum += now - m_lastFrame; @@ -61,7 +62,7 @@ void AdaptativeFrameCounter::processNextFrame() void AdaptativeFrameCounter::update() { - ticks_t now = stdext::micros(); + ticks_t now = g_clock.micros(); ticks_t delta = now - m_lastPartialFpsUpdate; if(delta > 41000 && m_partialFrames > 0) { m_partialFps = m_partialFrames / (delta / 1000000.0f); @@ -101,7 +102,7 @@ int AdaptativeFrameCounter::getMaximumSleepMicros() { if(m_maxFps == 0) return 0; - return m_lastFrame + m_bestFrameDelay - stdext::micros(); + return m_lastFrame + m_bestFrameDelay - g_clock.micros(); } float AdaptativeFrameCounter::getFrameDelayHit() diff --git a/src/framework/core/clock.cpp b/src/framework/core/clock.cpp index 849b3eae..04ddda0c 100644 --- a/src/framework/core/clock.cpp +++ b/src/framework/core/clock.cpp @@ -22,30 +22,18 @@ #include "clock.h" -// for usleep -#include - Clock g_clock; Clock::Clock() { - m_startupTime = std::chrono::high_resolution_clock::now(); - m_currentTicks = 0; -} -ticks_t Clock::updateTicks() -{ - m_currentTicks = asyncTicks(); - m_currentTime = m_currentTicks/1000.0f; - return m_currentTicks; -} - -ticks_t Clock::asyncTicks() -{ - auto timeNow = std::chrono::high_resolution_clock::now(); - return std::chrono::duration_cast(timeNow - m_startupTime).count(); + m_currentMicros = 0; + m_currentMillis = 0; + m_currentSeconds = 0; } -void Clock::sleep(int ms) +void Clock::update() { - usleep(ms * 1000); + m_currentMicros = stdext::micros(); + m_currentMillis = m_currentMicros / 1000; + m_currentSeconds = m_currentMicros / 1000000.0f; } diff --git a/src/framework/core/clock.h b/src/framework/core/clock.h index e7cda832..c78df9a1 100644 --- a/src/framework/core/clock.h +++ b/src/framework/core/clock.h @@ -30,23 +30,16 @@ class Clock public: Clock(); - ticks_t updateTicks(); - void sleep(int ms); + void update(); - ticks_t asyncTicks(); - ticks_t ticks() { return m_currentTicks; } - ticks_t ticksElapsed(ticks_t prevTicks) { return m_currentTicks - prevTicks; } - 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; } + ticks_t micros() { return m_currentMicros; } + ticks_t millis() { return m_currentMillis; } + float seconds() { return m_currentSeconds; } private: - ticks_t m_currentTicks; - float m_currentTime; - std::chrono::system_clock::time_point m_startupTime; + ticks_t m_currentMicros; + ticks_t m_currentMillis; + float m_currentSeconds; }; extern Clock g_clock; diff --git a/src/framework/core/eventdispatcher.h b/src/framework/core/eventdispatcher.h index caa8d504..c803c9d5 100644 --- a/src/framework/core/eventdispatcher.h +++ b/src/framework/core/eventdispatcher.h @@ -53,11 +53,11 @@ class ScheduledEvent : public Event { public: ScheduledEvent(const std::function& callback, int delay) : Event(callback) { - m_ticks = g_clock.ticksFor(delay); + m_ticks = g_clock.millis() + delay; } 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: ticks_t m_ticks; diff --git a/src/framework/core/timer.cpp b/src/framework/core/timer.cpp index ee05f7a9..5da192ea 100644 --- a/src/framework/core/timer.cpp +++ b/src/framework/core/timer.cpp @@ -26,11 +26,11 @@ void Timer::restart() { - m_startTicks = g_clock.ticks(); + m_startTicks = g_clock.millis(); m_stopped = false; } ticks_t Timer::ticksElapsed() { - return g_clock.ticks() - m_startTicks; + return g_clock.millis() - m_startTicks; } diff --git a/src/framework/graphics/framebuffer.cpp b/src/framework/graphics/framebuffer.cpp index 0c8364b7..5cf7d4cb 100644 --- a/src/framework/graphics/framebuffer.cpp +++ b/src/framework/graphics/framebuffer.cpp @@ -65,6 +65,7 @@ void FrameBuffer::resize(const Size& size) m_texture = TexturePtr(new Texture(size.width(), size.height(), 4)); m_texture->setSmooth(true); + m_texture->setUpsideDown(true); if(m_fbo) { internalBind(); @@ -97,8 +98,8 @@ void FrameBuffer::bind() internalBind(); Matrix3 projectionMatrix = { 2.0f/m_texture->getWidth(), 0.0f, 0.0f, - 0.0f, 2.0f/m_texture->getHeight(), 0.0f, - -1.0f, -1.0f, 1.0f }; + 0.0f, -2.0f/m_texture->getHeight(), 0.0f, + -1.0f, 1.0f, 1.0f }; g_painter->saveAndResetState(); g_painter->setProjectionMatrix(projectionMatrix); diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index 9702641f..c4903f1f 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -79,6 +79,13 @@ void Graphics::init() // blending is always enabled glEnable(GL_BLEND); + // face culling may improve performance + /* + glCullFace(GL_BACK); + glFrontFace(GL_CW); + glEnable(GL_CULL_FACE); + */ + // determine max texture size static GLint maxTextureSize = -1; if(maxTextureSize == -1) diff --git a/src/framework/graphics/painter.h b/src/framework/graphics/painter.h index ea4d00cf..61c0016b 100644 --- a/src/framework/graphics/painter.h +++ b/src/framework/graphics/painter.h @@ -45,7 +45,7 @@ public: struct PainterState { Matrix3 projectionMatrix; - Matrix2 textureMatrix; + Matrix3 textureMatrix; Color color; float opacity; Painter::CompositionMode compositionMode; @@ -75,7 +75,7 @@ public: virtual void drawBoundingRect(const Rect& dest, int innerLineWidth = 1) = 0; 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 setOpacity(float opacity) { m_opacity = opacity; } virtual void setCompositionMode(CompositionMode compositionMode); @@ -87,7 +87,7 @@ public: void setTexture(const TexturePtr& texture) { setTexture(texture.get()); } Matrix3 getProjectionMatrix() { return m_projectionMatrix; } - Matrix2 getTextureMatrix() { return m_textureMatrix; } + Matrix3 getTextureMatrix() { return m_textureMatrix; } Color getColor() { return m_color; } float getOpacity() { return m_opacity; } CompositionMode getCompositionMode() { return m_compositionMode; } @@ -109,7 +109,7 @@ protected: CoordsBuffer m_coordsBuffer; Matrix3 m_projectionMatrix; - Matrix2 m_textureMatrix; + Matrix3 m_textureMatrix; Color m_color; float m_opacity; CompositionMode m_compositionMode; diff --git a/src/framework/graphics/painterogl1.cpp b/src/framework/graphics/painterogl1.cpp index ba58def6..023223d7 100644 --- a/src/framework/graphics/painterogl1.cpp +++ b/src/framework/graphics/painterogl1.cpp @@ -195,7 +195,7 @@ void PainterOGL1::setProjectionMatrix(const Matrix3& projectionMatrix) updateGlProjectionMatrix(); } -void PainterOGL1::setTextureMatrix(const Matrix2& textureMatrix) +void PainterOGL1::setTextureMatrix(const Matrix3& textureMatrix) { // avoid re-updating texture matrix if(m_textureMatrix == textureMatrix) @@ -246,10 +246,10 @@ void PainterOGL1::updateGlProjectionMatrix() void PainterOGL1::updateGlTextureMatrix() { float glTextureMatrix[] = { - m_textureMatrix(1,1), m_textureMatrix(1,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, 0.0f, 1.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, + 0.0f, 0.0f, 1.0f, 0.0f, + m_textureMatrix(3,1), m_textureMatrix(3,2), 0.0f, m_textureMatrix(3,3), }; setMatrixMode(MatrixTexture); diff --git a/src/framework/graphics/painterogl1.h b/src/framework/graphics/painterogl1.h index 1fa8a9a2..f062943a 100644 --- a/src/framework/graphics/painterogl1.h +++ b/src/framework/graphics/painterogl1.h @@ -57,7 +57,7 @@ public: void setMatrixMode(MatrixMode matrixMode); void setProjectionMatrix(const Matrix3& projectionMatrix); - void setTextureMatrix(const Matrix2& textureMatrix); + void setTextureMatrix(const Matrix3& textureMatrix); void setColor(const Color& color); void setOpacity(float opacity); diff --git a/src/framework/graphics/painterogl2_shadersources.h b/src/framework/graphics/painterogl2_shadersources.h index c9102ce3..84e0999b 100644 --- a/src/framework/graphics/painterogl2_shadersources.h +++ b/src/framework/graphics/painterogl2_shadersources.h @@ -28,13 +28,13 @@ static const std::string glslMainVertexShader = "\n\ static const std::string glslMainWithTexCoordsVertexShader = "\n\ attribute highp vec2 a_texCoord;\n\ - uniform highp mat2 textureMatrix;\n\ + uniform highp mat3 textureMatrix;\n\ varying highp vec2 texCoord;\n\ highp vec4 calculatePosition();\n\ void main()\n\ {\n\ gl_Position = calculatePosition();\n\ - texCoord = textureMatrix * a_texCoord;\n\ + texCoord = textureMatrix * vec3(a_texCoord,1);\n\ }\n"; static std::string glslPositionOnlyVertexShader = "\n\ diff --git a/src/framework/graphics/paintershaderprogram.cpp b/src/framework/graphics/paintershaderprogram.cpp index dd5bd135..7d18dc03 100644 --- a/src/framework/graphics/paintershaderprogram.cpp +++ b/src/framework/graphics/paintershaderprogram.cpp @@ -28,7 +28,7 @@ PainterShaderProgram::PainterShaderProgram() { - m_startTime = g_clock.time(); + m_startTime = g_clock.seconds(); m_opacity = 1; m_color = Color::white; m_time = 0; @@ -36,7 +36,7 @@ PainterShaderProgram::PainterShaderProgram() bool PainterShaderProgram::link() { - m_startTime = g_clock.time(); + m_startTime = g_clock.seconds(); bindAttributeLocation(VERTEX_ATTR, "a_vertex"); bindAttributeLocation(TEXCOORD_ATTR, "a_texCoord"); if(ShaderProgram::link()) { @@ -72,7 +72,7 @@ void PainterShaderProgram::setProjectionMatrix(const Matrix3& projectionMatrix) m_projectionMatrix = projectionMatrix; } -void PainterShaderProgram::setTextureMatrix(const Matrix2& textureMatrix) +void PainterShaderProgram::setTextureMatrix(const Matrix3& textureMatrix) { if(textureMatrix == m_textureMatrix) return; @@ -104,7 +104,7 @@ void PainterShaderProgram::setOpacity(float opacity) void PainterShaderProgram::updateTime() { - float time = g_clock.timeElapsed(m_startTime); + float time = g_clock.seconds() - m_startTime; if(m_time == time) return; diff --git a/src/framework/graphics/paintershaderprogram.h b/src/framework/graphics/paintershaderprogram.h index ccf2d3fd..547753c7 100644 --- a/src/framework/graphics/paintershaderprogram.h +++ b/src/framework/graphics/paintershaderprogram.h @@ -52,7 +52,7 @@ public: bool link(); void setProjectionMatrix(const Matrix3& projectionMatrix); - void setTextureMatrix(const Matrix2& textureMatrix); + void setTextureMatrix(const Matrix3& textureMatrix); void setColor(const Color& color); void setOpacity(float opacity); void updateTime(); @@ -63,7 +63,7 @@ private: Color m_color; float m_opacity; Matrix3 m_projectionMatrix; - Matrix2 m_textureMatrix; + Matrix3 m_textureMatrix; float m_time; }; diff --git a/src/framework/graphics/particlesystem.cpp b/src/framework/graphics/particlesystem.cpp index 9ea6ec8d..f8a21123 100644 --- a/src/framework/graphics/particlesystem.cpp +++ b/src/framework/graphics/particlesystem.cpp @@ -27,7 +27,7 @@ ParticleSystem::ParticleSystem() { m_finished = false; - m_lastUpdateTime = g_clock.time(); + m_lastUpdateTime = g_clock.seconds(); } bool ParticleSystem::load(const OTMLNodePtr& node) @@ -79,10 +79,10 @@ void ParticleSystem::update() } // check time - float elapsedTime = g_clock.timeElapsed(m_lastUpdateTime); + float elapsedTime = g_clock.seconds() - m_lastUpdateTime; if(elapsedTime < delay) 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) { diff --git a/src/framework/graphics/texture.cpp b/src/framework/graphics/texture.cpp index 2992bc24..a42cce2d 100644 --- a/src/framework/graphics/texture.cpp +++ b/src/framework/graphics/texture.cpp @@ -53,7 +53,6 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int m_size.resize(width, height); // convert texture pixel data to power of two size, only required for OpenGL 1.5 or older - Size glSize; std::vector tmp; if(!g_graphics.canUseNonPowerOfTwoTextures()) { int glWidth = 1; @@ -64,7 +63,7 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int while(glHeight < height) glHeight = glHeight << 1; - if(m_size != glSize && pixels) { + if(m_size != m_glSize && pixels) { tmp.resize(glHeight*glWidth*channels, 0); for(int y=0; y 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, " "the maximum size allowed by the graphics card is %dx%d," "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 - 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; if(g_graphics.canUseClampToEdge()) @@ -182,6 +180,14 @@ void Texture::setSmooth(bool smooth) setupFilters(); } +void Texture::setUpsideDown(bool upsideDown) +{ + if(m_upsideDown == upsideDown) + return; + m_upsideDown = upsideDown; + setupTranformMatrix(); +} + void Texture::generateSoftwareMipmaps(std::vector inPixels) { bind(); @@ -261,3 +267,16 @@ void Texture::setupFilters() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); 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 }; + } +} diff --git a/src/framework/graphics/texture.h b/src/framework/graphics/texture.h index 38838826..d49a09ed 100644 --- a/src/framework/graphics/texture.h +++ b/src/framework/graphics/texture.h @@ -46,26 +46,30 @@ public: /// Activate texture anti-aliasing giving a better look when they are resized void setSmooth(bool smooth); + void setUpsideDown(bool upsideDown); GLuint getId() { return m_textureId; } int getWidth() { return m_size.width(); } int getHeight() { return m_size.height(); } 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 hasMipmaps() { return m_hasMipmaps; } protected: void setupFilters(); + void setupTranformMatrix(); GLuint internalLoadGLTexture(uchar* pixels, int channels, int w, int h); GLuint m_textureId; Size m_size; - Matrix2 m_transformMatrix; + Size m_glSize; + Matrix3 m_transformMatrix; Boolean m_hasMipmaps; Boolean m_smooth; + Boolean m_upsideDown; }; #endif diff --git a/src/framework/platform/platformwindow.cpp b/src/framework/platform/platformwindow.cpp index ddaca9cb..8be6d6b7 100644 --- a/src/framework/platform/platformwindow.cpp +++ b/src/framework/platform/platformwindow.cpp @@ -74,8 +74,8 @@ void PlatformWindow::processKeyDown(Fw::Key keyCode) m_inputEvent.reset(Fw::KeyPressInputEvent); m_inputEvent.keyCode = keyCode; - m_lastKeysPress[keyCode] = g_clock.ticks(); - m_firstKeysPress[keyCode] = g_clock.ticks(); + m_lastKeysPress[keyCode] = g_clock.millis(); + m_firstKeysPress[keyCode] = g_clock.millis(); m_onInputEvent(m_inputEvent); } } @@ -141,14 +141,14 @@ void PlatformWindow::fireKeysPress() ticks_t lastPressTicks = m_lastKeysPress[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) { m_inputEvent.reset(Fw::KeyPressInputEvent); m_inputEvent.keyCode = keyCode; - m_inputEvent.autoRepeatTicks = g_clock.ticksElapsed(firstKeyPress); + m_inputEvent.autoRepeatTicks = g_clock.millis() - firstKeyPress; m_onInputEvent(m_inputEvent); } - m_lastKeysPress[keyCode] = g_clock.ticks(); + m_lastKeysPress[keyCode] = g_clock.millis(); } } } diff --git a/src/framework/sound/soundmanager.cpp b/src/framework/sound/soundmanager.cpp index dd15f444..fd4b5c6f 100644 --- a/src/framework/sound/soundmanager.cpp +++ b/src/framework/sound/soundmanager.cpp @@ -77,7 +77,7 @@ void SoundManager::terminate() void SoundManager::poll() { static ticks_t lastUpdate = 0; - ticks_t now = g_clock.ticks(); + ticks_t now = g_clock.millis(); if(now - lastUpdate < POLL_DELAY) return; diff --git a/src/framework/sound/soundsource.cpp b/src/framework/sound/soundsource.cpp index c03156da..7bd0ed1a 100644 --- a/src/framework/sound/soundsource.cpp +++ b/src/framework/sound/soundsource.cpp @@ -114,7 +114,7 @@ void SoundSource::setVelocity(const Point& velocity) void SoundSource::setFading(FadeState state, float fadeTime) { - float now = g_clock.time(); + float now = g_clock.seconds(); if(m_fadeState != NoFading) { float elapsed = now - m_fadeStartTime; float add; @@ -132,7 +132,7 @@ void SoundSource::setFading(FadeState state, float fadeTime) void SoundSource::update() { - float now = g_clock.time(); + float now = g_clock.seconds(); if(m_fadeState == FadingOn) { float elapsed = now - m_fadeStartTime; if(elapsed >= m_fadeTime) { diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index f8ff901a..fbb26828 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -64,7 +64,8 @@ void UITextEdit::drawSelf(bool foregroundPane) assert(m_cursorPos <= textLength); // draw every 333ms const int delay = 333; - if(g_clock.ticksElapsed(m_cursorTicks) <= delay) { + int elapsed = g_clock.millis() - m_cursorTicks; + if(elapsed <= delay) { Rect cursorRect; // when cursor is at 0 or is the first visible element if(m_cursorPos == 0 || m_cursorPos == m_startRenderPos) @@ -72,8 +73,8 @@ void UITextEdit::drawSelf(bool foregroundPane) else cursorRect = Rect(m_glyphsCoords[m_cursorPos-1].right(), m_glyphsCoords[m_cursorPos-1].top(), 1, m_font->getGlyphHeight()); g_painter->drawFilledRect(cursorRect); - } else if(g_clock.ticksElapsed(m_cursorTicks) >= 2*delay) { - m_cursorTicks = g_clock.ticks(); + } else if(elapsed >= 2*delay) { + m_cursorTicks = g_clock.millis(); } } } @@ -512,5 +513,5 @@ bool UITextEdit::onMousePress(const Point& mousePos, Fw::MouseButton button) void UITextEdit::blinkCursor() { - m_cursorTicks = g_clock.ticks(); + m_cursorTicks = g_clock.millis(); } diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 5953f6cb..a9f02626 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -105,7 +105,7 @@ void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool ani if(isAnimateAlways() && animateIdle) { int ticksPerFrame = 1000 / getAnimationPhases(); - animationPhase = (g_clock.ticks() % (ticksPerFrame * getAnimationPhases())) / ticksPerFrame; + animationPhase = (g_clock.millis() % (ticksPerFrame * getAnimationPhases())) / ticksPerFrame; } // xPattern => creature direction @@ -182,7 +182,7 @@ void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool ani if(animationPhases > 1) { if(animateIdle) - animationPhase = (g_clock.ticks() % (animateTicks * animationPhases)) / animateTicks; + animationPhase = (g_clock.millis() % (animateTicks * animationPhases)) / animateTicks; else animationPhase = animationPhases-1; } diff --git a/src/otclient/core/item.cpp b/src/otclient/core/item.cpp index bcc7a45c..49e7fdf4 100644 --- a/src/otclient/core/item.cpp +++ b/src/otclient/core/item.cpp @@ -61,7 +61,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate) int animationPhase = 0; if(getAnimationPhases() > 1) { 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 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); // release draw shader - g_painter->resetShaderProgram(); + //g_painter->resetShaderProgram(); } void Item::setId(uint32 id)