many changes

* Fixes in WIN32 platform
* Remove unused files
* Make StaticText work more like tibia
* Fix WIN32 compilation
* Fix regression in framebuffers that caused battle to disappear
* Shader fixes for DX9
* Add two new shaders: noise and heat
This commit is contained in:
Eduardo Bart
2012-06-15 19:18:30 -03:00
parent 10b60a3871
commit 4813b7eb4b
19 changed files with 203 additions and 177 deletions

View File

@@ -22,8 +22,7 @@ ELSE()
SET(ARCH_FLAGS "-m32 -march=i686 -mtune=generic")
ENDIF()
SET(WARNS_FLAGS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable")
SET(SECURE_FLAGS "-fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_WARNS} ${SECURE_FLAGS} ${ARCH_FLAGS} -std=gnu++0x -pipe")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_WARNS} ${ARCH_FLAGS} -std=gnu++0x -pipe")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -ggdb")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -ggdb -fno-omit-frame-pointer")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")

View File

@@ -60,6 +60,7 @@ void Painter::refreshState()
void Painter::saveState()
{
assert(m_oldStateIndex<10);
m_olderStates[m_oldStateIndex].resolution = m_resolution;
m_olderStates[m_oldStateIndex].projectionMatrix = m_projectionMatrix;
m_olderStates[m_oldStateIndex].textureMatrix = m_textureMatrix;
m_olderStates[m_oldStateIndex].color = m_color;
@@ -69,7 +70,6 @@ void Painter::saveState()
m_olderStates[m_oldStateIndex].shaderProgram = m_shaderProgram;
m_olderStates[m_oldStateIndex].texture = m_texture;
m_olderStates[m_oldStateIndex].alphaWriting = m_alphaWriting;
m_olderStates[m_oldStateIndex].resolution = m_resolution;
m_oldStateIndex++;
}
@@ -82,6 +82,7 @@ void Painter::saveAndResetState()
void Painter::restoreSavedState()
{
m_oldStateIndex--;
setResolution(m_olderStates[m_oldStateIndex].resolution);
setProjectionMatrix(m_olderStates[m_oldStateIndex].projectionMatrix);
setTextureMatrix(m_olderStates[m_oldStateIndex].textureMatrix);
setColor(m_olderStates[m_oldStateIndex].color);
@@ -90,7 +91,7 @@ void Painter::restoreSavedState()
setClipRect(m_olderStates[m_oldStateIndex].clipRect);
setShaderProgram(m_olderStates[m_oldStateIndex].shaderProgram);
setTexture(m_olderStates[m_oldStateIndex].texture);
setResolution(m_olderStates[m_oldStateIndex].resolution);
setAlphaWriting(m_olderStates[m_oldStateIndex].alphaWriting);
}
void Painter::clear(const Color& color)

View File

@@ -44,6 +44,7 @@ public:
};
struct PainterState {
Size resolution;
Matrix3 projectionMatrix;
Matrix3 textureMatrix;
Color color;
@@ -53,7 +54,6 @@ public:
Texture *texture;
PainterShaderProgram *shaderProgram;
bool alphaWriting;
Size resolution;
};
Painter();

View File

@@ -1,48 +0,0 @@
/*
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef PAINTERSHADERMANAGER_H
#define PAINTERSHADERMANAGER_H
#include "paintershaderprogram.h"
class PainterShaderManager
{
public:
void init();
void terminate();
PainterShaderProgramPtr createShader();
PainterShaderProgramPtr createTexturedFragmentShader(const std::string& shaderFile);
const PainterShaderProgramPtr& getDrawTexturedProgram() { return m_drawTexturedProgram; }
const PainterShaderProgramPtr& getDrawSolidColorProgram() { return m_drawSolidColorProgram; }
private:
PainterShaderProgramPtr m_drawTexturedProgram;
PainterShaderProgramPtr m_drawSolidColorProgram;
};
extern PainterShaderManager g_shaders;
#endif

View File

@@ -205,6 +205,7 @@ void WIN32Window::init()
internalCreateWindow();
internalCreateGLContext();
internalRestoreGLContext();
}
void WIN32Window::terminate()
@@ -253,7 +254,7 @@ void WIN32Window::internalCreateWindow()
wc.hInstance = m_instance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = m_defaultCursor;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_app->getName().c_str();
@@ -344,8 +345,6 @@ void WIN32Window::internalCreateGLContext()
if(m_eglContext == EGL_NO_CONTEXT )
g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError()));
if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext))
g_logger.fatal("Unable to make current EGL context");
#else
uint pixelFormat;
static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),
@@ -374,9 +373,6 @@ void WIN32Window::internalCreateGLContext()
if(!(m_wglContext = wglCreateContext(m_deviceContext)))
g_logger.fatal("Unable to create GL context");
if(!wglMakeCurrent(m_deviceContext, m_wglContext))
g_logger.fatal("Unable to set GLX context on WIN32 window");
#endif
}
@@ -406,6 +402,17 @@ void WIN32Window::internalDestroyGLContext()
#endif
}
void WIN32Window::internalRestoreGLContext()
{
#ifdef OPENGL_ES
if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext))
g_logger.fatal("Unable to make current EGL context");
#else
if(!wglMakeCurrent(m_deviceContext, m_wglContext))
g_logger.fatal("Unable to make current WGL context");
#endif
}
bool WIN32Window::isExtensionSupported(const char *ext)
{
#ifdef OPENGL_ES
@@ -707,6 +714,9 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
break;
}
if(m_visible && m_deviceContext)
internalRestoreGLContext();
Size size;
size.setWidth(std::max(std::min((int)LOWORD(lParam), 7680), m_minimumSize.width()));
size.setHeight(std::max(std::min((int)HIWORD(lParam), 4320), m_minimumSize.height()));

View File

@@ -38,6 +38,7 @@ class WIN32Window : public PlatformWindow
void internalCreateWindow();
void internalCreateGLContext();
void internalDestroyGLContext();
void internalRestoreGLContext();
void *getExtensionProcAddress(const char *ext);
bool isExtensionSupported(const char *ext);

View File

@@ -50,7 +50,7 @@ namespace Otc
INVISIBLE_TICKS_PER_FRAME = 500,
ITEM_TICKS_PER_FRAME = 500,
ANIMATED_TEXT_DURATION = 1000,
STATIC_DURATION_PER_CHARACTER = 75,
STATIC_DURATION_PER_CHARACTER = 60,
MIN_STATIC_TEXT_DURATION = 3000,
MAX_STATIC_TEXT_WIDTH = 200,
};

View File

@@ -170,8 +170,8 @@ void MapView::draw(const Rect& rect)
Position pos = staticText->getPosition();
// ony draw static texts from current camera floor, unless yells
if(pos.z != cameraPosition.z && !staticText->isYell())
continue;
//if(pos.z != cameraPosition.z && !staticText->isYell())
// continue;
Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset;
p.x = p.x * horizontalStretchFactor;

View File

@@ -49,7 +49,7 @@ void ShaderManager::terminate()
PainterShaderProgramPtr ShaderManager::createShader(const std::string& name)
{
if(!g_graphics.canUseShaders()) {
g_logger.error(stdext::format("unable to create shader, shaders are not supported"));
g_logger.error(stdext::format("unable to create shader '%s', shaders are not supported", name));
return nullptr;
}

View File

@@ -40,50 +40,63 @@ void StaticText::draw(const Point& dest, const Rect& parentRect)
boundRect.bind(parentRect);
// draw only if the real center is not too far from the parent center, or its a yell
if((boundRect.center() - rect.center()).length() < parentRect.width() / 15 || isYell()) {
//if(g_map.isAwareOfPosition(m_position) || isYell()) {
g_painter->setColor(m_color);
m_cachedText.draw(boundRect);
}
//}
}
bool StaticText::addMessage(const std::string& name, Otc::SpeakType type, const std::string& message)
{
//TODO: this could be moved to lua
// First message
// first message
if(m_messages.size() == 0) {
m_name = name;
m_messageType = type;
}
else if(m_messages.size() > 20) {
// to many messages, ignore to avoid lag
// check if we can really own the message
else if(m_name != name || m_messageType != type) {
return false;
} else {
// we can only add another message if it follows these conditions
if(m_name != name || m_messageType != type)
return false;
}
// too many messages
else if(m_messages.size() > 10) {
m_messages.pop_front();
m_updateEvent->cancel();
m_updateEvent = nullptr;
}
m_messages.push_back(message);
compose();
auto self = asStaticText();
g_eventDispatcher.scheduleEvent([self]() {
self->removeMessage();
}, std::max<int>(Otc::STATIC_DURATION_PER_CHARACTER * message.length(), Otc::MIN_STATIC_TEXT_DURATION));
if(!m_updateEvent)
scheduleUpdate();
return true;
}
void StaticText::removeMessage()
void StaticText::update()
{
m_messages.pop_front();
if(m_messages.empty()) {
// schedule removal
auto self = asStaticText();
g_eventDispatcher.addEvent([self]() { g_map.removeThing(self); });
} else
} else {
compose();
scheduleUpdate();
}
}
void StaticText::scheduleUpdate()
{
int len = m_messages.front().length();
int delay = std::max(Otc::STATIC_DURATION_PER_CHARACTER * len, (int)Otc::MIN_STATIC_TEXT_DURATION);
auto self = asStaticText();
m_updateEvent = g_eventDispatcher.scheduleEvent([self]() {
self->m_updateEvent = nullptr;
self->update();
}, delay);
}
void StaticText::compose()
@@ -121,5 +134,5 @@ void StaticText::compose()
}
m_cachedText.setText(text);
m_cachedText.wrapText(Otc::MAX_STATIC_TEXT_WIDTH);
m_cachedText.wrapText(275);
}

View File

@@ -26,6 +26,7 @@
#include "thing.h"
#include <framework/graphics/cachedtext.h>
#include <framework/graphics/fontmanager.h>
#include <framework/core/timer.h>
class StaticText : public Thing
{
@@ -41,12 +42,13 @@ public:
bool isYell() { return m_messageType == Otc::SpeakYell || m_messageType == Otc::SpeakMonsterYell; }
bool addMessage(const std::string& name, Otc::SpeakType type, const std::string& message);
void removeMessage();
StaticTextPtr asStaticText() { return std::static_pointer_cast<StaticText>(shared_from_this()); }
bool isStaticText() { return true; }
private:
void update();
void scheduleUpdate();
void compose();
Boolean<false> m_yell;
@@ -55,6 +57,7 @@ private:
Otc::SpeakType m_messageType;
Color m_color;
CachedText m_cachedText;
ScheduledEventPtr m_updateEvent;
};
#endif