restore some game functionallity

* i'm gradually restoring game functionality with the new modules design, though still a lot to do
* you can reload all scripts and modules using Ctrl+R shortcut while playing (finally! this is the reason of all this rework)
* a bunch of fixes, but new regression too :P
* fix performance issue that could lead freezes in the client in older machines
* completely new game module with new design
* fix crashs in map render
* remove uigame.cpp (now every game input is via lua)
* enable DEBUG macro by default, with it you are able to view any possible lua leak while running
This commit is contained in:
Eduardo Bart
2012-03-18 10:34:39 -03:00
parent 26629cf77c
commit c0611bfe2a
99 changed files with 938 additions and 388 deletions

View File

@@ -50,15 +50,6 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -static-libgcc -static-libstdc++ -Wl,--as-needed")
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-DDEBUG)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug")
IF(CMAKE_BUILD_TYPE STREQUAL "Release")
# NDEBUG disable asserts
ADD_DEFINITIONS(-DNDEBUG)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Release")
MESSAGE(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
IF(USE_OPENGL_ES2)
MESSAGE(STATUS "Renderer: OpenGL ES 2.0")
@@ -66,6 +57,18 @@ ELSE(USE_OPENGL_ES2)
MESSAGE(STATUS "Renderer: OpenGL")
ENDIF(USE_OPENGL_ES2)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
ADD_DEFINITIONS(-DDEBUG)
MESSAGE(STATUS "Debug information: ON")
ELSE()
MESSAGE(STATUS "Debug information: OFF")
ENDIF()
IF(CMAKE_BUILD_TYPE STREQUAL "Release")
# NDEBUG disable asserts
ADD_DEFINITIONS(-DNDEBUG)
ENDIF(CMAKE_BUILD_TYPE STREQUAL "Release")
IF(CRASH_HANDLER)
ADD_DEFINITIONS(-DCRASH_HANDLER)
MESSAGE(STATUS "Crash handler: ON")

View File

@@ -219,10 +219,7 @@ void Application::poll()
void Application::close()
{
g_lua.getGlobalField("g_app", "onClose");
if(!g_lua.isNil())
g_lua.protectedCall();
else
if(!g_lua.callGlobalField<bool>("g_app", "onClose"))
exit();
}

View File

@@ -362,6 +362,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UILineEdit>("setTextHidden", &UILineEdit::setTextHidden);
g_lua.bindClassMemberFunction<UILineEdit>("setAlwaysActive", &UILineEdit::setAlwaysActive);
g_lua.bindClassMemberFunction<UILineEdit>("setValidCharacters", &UILineEdit::setValidCharacters);
g_lua.bindClassMemberFunction<UILineEdit>("setShiftNavigation", &UILineEdit::setShiftNavigation);
g_lua.bindClassMemberFunction<UILineEdit>("moveCursor", &UILineEdit::moveCursor);
g_lua.bindClassMemberFunction<UILineEdit>("appendText", &UILineEdit::appendText);
g_lua.bindClassMemberFunction<UILineEdit>("removeCharacter", &UILineEdit::removeCharacter);
@@ -372,6 +373,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UILineEdit>("isCursorEnabled", &UILineEdit::isCursorEnabled);
g_lua.bindClassMemberFunction<UILineEdit>("isAlwaysActive", &UILineEdit::isAlwaysActive);
g_lua.bindClassMemberFunction<UILineEdit>("isTextHidden", &UILineEdit::isTextHidden);
g_lua.bindClassMemberFunction<UILineEdit>("isShiftNavigation", &UILineEdit::isShiftNavigation);
// UIFrameCounter
g_lua.registerClass<UIFrameCounter, UIWidget>();

View File

@@ -35,6 +35,7 @@ UILineEdit::UILineEdit()
m_textHorizontalMargin = 0;
m_textHidden = false;
m_alwaysActive = false;
m_shiftNavigation = false;
blinkCursor();
}
@@ -407,8 +408,8 @@ void UILineEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& s
setTextHorizontalMargin(node->value<int>());
else if(node->tag() == "always-active")
setAlwaysActive(node->value<bool>());
//else if(node->tag() == "disable-arrow-navitation")
// setArrowNavigation(node->value<bool>());
else if(node->tag() == "shift-navigation")
setShiftNavigation(node->value<bool>());
}
}
@@ -434,28 +435,46 @@ bool UILineEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
if(UIWidget::onKeyPress(keyCode, keyboardModifiers, autoRepeatTicks))
return true;
if(keyCode == Fw::KeyDelete) // erase right character
removeCharacter(true);
else if(keyCode == Fw::KeyBackspace) // erase left character {
removeCharacter(false);
else if(keyCode == Fw::KeyRight) // move cursor right
moveCursor(true);
else if(keyCode == Fw::KeyLeft) // move cursor left
moveCursor(false);
else if(keyCode == Fw::KeyHome) // move cursor to first character
setCursorPos(0);
else if(keyCode == Fw::KeyEnd) // move cursor to last character
setCursorPos(m_text.length());
else if(keyCode == Fw::KeyV && keyboardModifiers == Fw::KeyboardCtrlModifier)
appendText(g_window.getClipboardText());
else if(keyCode == Fw::KeyTab) {
if(!m_alwaysActive) {
if(keyboardModifiers == Fw::KeyboardNoModifier) {
if(keyCode == Fw::KeyDelete) { // erase right character
removeCharacter(true);
return true;
} else if(keyCode == Fw::KeyBackspace) { // erase left character {
removeCharacter(false);
return true;
} else if(keyCode == Fw::KeyRight && !m_shiftNavigation) { // move cursor right
moveCursor(true);
return true;
} else if(keyCode == Fw::KeyLeft && !m_shiftNavigation) { // move cursor left
moveCursor(false);
return true;
} else if(keyCode == Fw::KeyHome) { // move cursor to first character
setCursorPos(0);
return true;
} else if(keyCode == Fw::KeyEnd) { // move cursor to last character
setCursorPos(m_text.length());
return true;
} else if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
if(UIWidgetPtr parent = getParent())
parent->focusNextChild(Fw::KeyboardFocusReason);
return true;
}
} else
return false;
return true;
} else if(keyboardModifiers == Fw::KeyboardCtrlModifier) {
if(keyCode == Fw::KeyV) {
appendText(g_window.getClipboardText());
return true;
}
} else if(keyboardModifiers == Fw::KeyboardShiftModifier) {
if(keyCode == Fw::KeyRight && m_shiftNavigation) { // move cursor right
moveCursor(true);
return true;
} else if(keyCode == Fw::KeyLeft && m_shiftNavigation) { // move cursor left
moveCursor(false);
return true;
}
}
return false;
}
bool UILineEdit::onKeyText(const std::string& keyText)

View File

@@ -42,6 +42,7 @@ public:
void setTextHidden(bool hidden);
void setAlwaysActive(bool enable);
void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; }
void setShiftNavigation(bool enable) { m_shiftNavigation = enable; }
void moveCursor(bool right);
void appendText(std::string text);
@@ -55,6 +56,7 @@ public:
bool isCursorEnabled() { return m_cursorPos != -1; }
bool isAlwaysActive() { return m_alwaysActive; }
bool isTextHidden() { return m_textHidden; }
bool isShiftNavigation() { return m_shiftNavigation; }
protected:
virtual void onTextChange(const std::string& text, const std::string& oldText);
@@ -77,6 +79,7 @@ private:
int m_textHorizontalMargin;
bool m_textHidden;
bool m_alwaysActive;
bool m_shiftNavigation;
std::string m_validCharacters;
std::vector<Rect> m_glyphsCoords;

View File

@@ -319,7 +319,12 @@ UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent
return nullptr;
}
}
/*
UIWidgetPtr UIManager::loadWidgetFromStyle()
{
}
*/
UIWidgetPtr UIManager::loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent)
{
OTMLNodePtr originalStyleNode = getStyle(widgetNode->tag());

View File

@@ -206,7 +206,7 @@ void UIWidget::removeChild(UIWidgetPtr child)
g_ui.onWidgetDisappear(child);
} else
logError("Attempt to remove an unknown child from a UIWidget");
logError("attempt to remove an unknown child from a UIWidget");
}
@@ -637,11 +637,12 @@ void UIWidget::destroy()
// remove itself from parent
if(UIWidgetPtr parent = getParent()) {
if(parent->hasChild(asUIWidget()))
parent->removeChild(asUIWidget());
assert(parent->hasChild(asUIWidget()));
parent->removeChild(asUIWidget());
}
destroyChildren();
m_focusedChild = nullptr;
callLuaField("onDestroy");
@@ -649,12 +650,13 @@ void UIWidget::destroy()
#ifdef DEBUG
auto self = asUIWidget();
g_lua.collectGarbage();
if(self != g_ui.getRootWidget()) {
g_eventDispatcher.scheduleEvent([self] {
g_lua.collectGarbage();
if(self->getUseCount() != 1)
logWarning("widget '", self->getId(), "' destroyed but still have ", self->getUseCount()-1, " reference(s) left");
}, 100);
}, 500);
}
#endif
}

View File

@@ -51,6 +51,9 @@ void UIWidget::drawText(const Rect& screenCoords)
if(m_text.length() == 0 || m_color.a() == 0)
return;
#if 0
//TODO: creating framebuffers on the fly was slowing down the render
// we should use vertex arrys instead of this method
Size boxSize = screenCoords.size();
if(boxSize != m_textCachedBoxSize || m_textMustRecache) {
if(!m_textFramebuffer)
@@ -73,6 +76,11 @@ void UIWidget::drawText(const Rect& screenCoords)
g_painter.setColor(m_color);
m_textFramebuffer->draw(screenCoords);
#else
Rect textRect = screenCoords;
textRect.translate(m_textOffset);
m_font->renderText(m_text, textRect, m_textAlign, m_color);
#endif
}
void UIWidget::onTextChange(const std::string& text, const std::string& oldText)