Compile with clang and add cotire

* Add cotire cmake module to speedup compilation https://github.com/sakra/cotire
* Fix clang error and warnings
* Rename Font to BitmapFont to fix conflict with Xlib.g Font typedef
* Remove legacy PCH support
* Improve Position hash
master
Eduardo Bart 12 years ago
parent 4813b7eb4b
commit 10b33c6124

@ -28,8 +28,8 @@ ADD_EXECUTABLE(otclient ${framework_SOURCES} ${otclient_SOURCES} ${executable_SO
TARGET_LINK_LIBRARIES(otclient ${framework_LIBRARIES})
IF(PCH)
FIND_PACKAGE(PCHSupport REQUIRED)
ADD_PRECOMPILED_HEADER(otclient ${CMAKE_CURRENT_SOURCE_DIR}/src/framework/pch.h)
include(cotire)
cotire(otclient)
MESSAGE(STATUS "Use precompiled header: ON")
ELSE()
MESSAGE(STATUS "Use precompiled header: OFF")

@ -207,8 +207,8 @@ SET(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/graphics/coordsbuffer.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/coordsbuffer.h
${CMAKE_CURRENT_LIST_DIR}/graphics/declarations.h
${CMAKE_CURRENT_LIST_DIR}/graphics/font.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/font.h
${CMAKE_CURRENT_LIST_DIR}/graphics/bitmapfont.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/bitmapfont.h
${CMAKE_CURRENT_LIST_DIR}/graphics/fontmanager.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/fontmanager.h
${CMAKE_CURRENT_LIST_DIR}/graphics/framebuffer.cpp

@ -1,315 +0,0 @@
# - Try to find precompiled headers support for GCC 3.4 and 4.x (and MSVC)
# Once done this will define:
#
# Variable:
# PCHSupport_FOUND
#
# Macro:
# ADD_PRECOMPILED_HEADER _targetName _input _dowarn
# ADD_PRECOMPILED_HEADER_TO_TARGET _targetName _input _pch_output_to_use _dowarn
# ADD_NATIVE_PRECOMPILED_HEADER _targetName _input _dowarn
# GET_NATIVE_PRECOMPILED_HEADER _targetName _input
IF(CMAKE_COMPILER_IS_GNUCXX)
EXEC_PROGRAM(
${CMAKE_CXX_COMPILER}
ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
OUTPUT_VARIABLE gcc_compiler_version
)
#MESSAGE("GCC Version: ${gcc_compiler_version}")
IF(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]")
SET(PCHSupport_FOUND TRUE)
ELSE(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]")
IF(gcc_compiler_version MATCHES "3\\.4\\.[0-9]")
SET(PCHSupport_FOUND TRUE)
ENDIF(gcc_compiler_version MATCHES "3\\.4\\.[0-9]")
ENDIF(gcc_compiler_version MATCHES "4\\.[0-9]\\.[0-9]")
SET(_PCH_include_prefix "-I")
ELSE(CMAKE_COMPILER_IS_GNUCXX)
IF(WIN32)
SET(PCHSupport_FOUND TRUE) # for experimental msvc support
SET(_PCH_include_prefix "/I")
ELSE(WIN32)
SET(PCHSupport_FOUND FALSE)
ENDIF(WIN32)
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags)
STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name)
SET(${_out_compile_flags} ${${_flags_var_name}} )
IF(CMAKE_COMPILER_IS_GNUCXX)
GET_TARGET_PROPERTY(_targetType ${_PCH_current_target} TYPE)
IF(${_targetType} STREQUAL SHARED_LIBRARY AND NOT WIN32)
LIST(APPEND ${_out_compile_flags} -fPIC)
ENDIF()
ELSE(CMAKE_COMPILER_IS_GNUCXX)
## TODO ... ? or does it work out of the box
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES )
FOREACH(item ${DIRINC})
LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}${item}")
ENDFOREACH(item)
GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
GET_DIRECTORY_PROPERTY(_global_definitions DIRECTORY ${CMAKE_SOURCE_DIR} DEFINITIONS)
#MESSAGE("_directory_flags ${_directory_flags} ${_global_definitions}" )
LIST(APPEND ${_out_compile_flags} ${_directory_flags})
LIST(APPEND ${_out_compile_flags} ${_global_definitions})
LIST(APPEND ${_out_compile_flags} ${CMAKE_CXX_FLAGS} )
SEPARATE_ARGUMENTS(${_out_compile_flags})
ENDMACRO(_PCH_GET_COMPILE_FLAGS)
MACRO(_PCH_WRITE_PCHDEP_CXX _targetName _include_file _dephelp)
SET(${_dephelp} ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch_dephelp.cxx)
FILE(WRITE ${${_dephelp}}
"#include \"${_include_file}\"
int testfunction()
{
return 0;
}
"
)
ENDMACRO(_PCH_WRITE_PCHDEP_CXX )
MACRO(_PCH_GET_COMPILE_COMMAND out_command _input _output)
FILE(TO_NATIVE_PATH ${_input} _native_input)
FILE(TO_NATIVE_PATH ${_output} _native_output)
IF(CMAKE_COMPILER_IS_GNUCXX)
IF(CMAKE_CXX_COMPILER_ARG1)
# remove leading space in compiler argument
STRING(REGEX REPLACE "^ +" "" pchsupport_compiler_cxx_arg1 ${CMAKE_CXX_COMPILER_ARG1})
SET(${out_command}
${CMAKE_CXX_COMPILER} ${pchsupport_compiler_cxx_arg1} ${_compile_FLAGS} -x c++-header -o ${_output} ${_input}
)
ELSE(CMAKE_CXX_COMPILER_ARG1)
SET(${out_command}
${CMAKE_CXX_COMPILER} ${_compile_FLAGS} -x c++-header -o ${_output} ${_input}
)
ENDIF(CMAKE_CXX_COMPILER_ARG1)
ELSE(CMAKE_COMPILER_IS_GNUCXX)
SET(_dummy_str "#include <${_input}>")
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pch_dummy.cpp ${_dummy_str})
SET(${out_command}
${CMAKE_CXX_COMPILER} ${_compile_FLAGS} /c /Fp${_native_output} /Yc${_native_input} pch_dummy.cpp
)
#/out:${_output}
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
ENDMACRO(_PCH_GET_COMPILE_COMMAND )
MACRO(_PCH_GET_TARGET_COMPILE_FLAGS _cflags _header_name _pch_path _dowarn )
FILE(TO_NATIVE_PATH ${_pch_path} _native_pch_path)
IF(CMAKE_COMPILER_IS_GNUCXX)
# for use with distcc and gcc >4.0.1 if preprocessed files are accessible
# on all remote machines set
# PCH_ADDITIONAL_COMPILER_FLAGS to -fpch-preprocess
# if you want warnings for invalid header files (which is very inconvenient
# if you have different versions of the headers for different build types
# you may set _pch_dowarn
IF (_dowarn)
SET(${_cflags} "${PCH_ADDITIONAL_COMPILER_FLAGS} -include ${CMAKE_CURRENT_BINARY_DIR}/${_header_name} -Winvalid-pch " )
ELSE (_dowarn)
SET(${_cflags} "${PCH_ADDITIONAL_COMPILER_FLAGS} -include ${CMAKE_CURRENT_BINARY_DIR}/${_header_name} " )
ENDIF (_dowarn)
ELSE(CMAKE_COMPILER_IS_GNUCXX)
set(${_cflags} "/Fp${_native_pch_path} /Yu${_header_name}" )
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
ENDMACRO(_PCH_GET_TARGET_COMPILE_FLAGS )
MACRO(GET_PRECOMPILED_HEADER_OUTPUT _targetName _input _output)
GET_FILENAME_COMPONENT(_name ${_input} NAME)
GET_FILENAME_COMPONENT(_path ${_input} PATH)
SET(_output "${CMAKE_CURRENT_BINARY_DIR}/${_name}.gch/${_targetName}_${CMAKE_BUILD_TYPE}.gch")
ENDMACRO(GET_PRECOMPILED_HEADER_OUTPUT _targetName _input)
MACRO(ADD_PRECOMPILED_HEADER_TO_TARGET _targetName _input _pch_output_to_use )
# to do: test whether compiler flags match between target _targetName
# and _pch_output_to_use
GET_FILENAME_COMPONENT(_name ${_input} NAME)
IF( "${ARGN}" STREQUAL "0")
SET(_dowarn 0)
ELSE( "${ARGN}" STREQUAL "0")
SET(_dowarn 1)
ENDIF("${ARGN}" STREQUAL "0")
_PCH_GET_TARGET_COMPILE_FLAGS(_target_cflags ${_name} ${_pch_output_to_use} ${_dowarn})
# MESSAGE("Add flags ${_target_cflags} to ${_targetName} " )
SET_TARGET_PROPERTIES(${_targetName}
PROPERTIES
COMPILE_FLAGS ${_target_cflags}
)
ADD_CUSTOM_TARGET(pch_Generate_${_targetName}
DEPENDS ${_pch_output_to_use}
)
ADD_DEPENDENCIES(${_targetName} pch_Generate_${_targetName} )
ENDMACRO(ADD_PRECOMPILED_HEADER_TO_TARGET)
MACRO(ADD_PRECOMPILED_HEADER _targetName _input)
SET(_PCH_current_target ${_targetName})
IF(NOT CMAKE_BUILD_TYPE)
MESSAGE(FATAL_ERROR
"This is the ADD_PRECOMPILED_HEADER macro. "
"You must set CMAKE_BUILD_TYPE!"
)
ENDIF(NOT CMAKE_BUILD_TYPE)
IF( "${ARGN}" STREQUAL "0")
SET(_dowarn 0)
ELSE( "${ARGN}" STREQUAL "0")
SET(_dowarn 1)
ENDIF("${ARGN}" STREQUAL "0")
GET_FILENAME_COMPONENT(_name ${_input} NAME)
GET_FILENAME_COMPONENT(_path ${_input} PATH)
GET_PRECOMPILED_HEADER_OUTPUT( ${_targetName} ${_input} _output)
GET_FILENAME_COMPONENT(_outdir ${_output} PATH )
GET_TARGET_PROPERTY(_targetType ${_PCH_current_target} TYPE)
_PCH_WRITE_PCHDEP_CXX(${_targetName} ${_input} _pch_dephelp_cxx)
IF(${_targetType} STREQUAL SHARED_LIBRARY)
ADD_LIBRARY(${_targetName}_pch_dephelp STATIC ${_pch_dephelp_cxx} )
ELSE(${_targetType} STREQUAL SHARED_LIBRARY)
ADD_LIBRARY(${_targetName}_pch_dephelp STATIC ${_pch_dephelp_cxx})
ENDIF(${_targetType} STREQUAL SHARED_LIBRARY)
FILE(MAKE_DIRECTORY ${_outdir})
_PCH_GET_COMPILE_FLAGS(_compile_FLAGS)
#MESSAGE("_compile_FLAGS: ${_compile_FLAGS}")
#message("COMMAND ${CMAKE_CXX_COMPILER} ${_compile_FLAGS} -x c++-header -o ${_output} ${_input}")
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/${_name} PROPERTIES GENERATED 1)
ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}
COMMAND ${CMAKE_COMMAND} -E copy ${_input} ${CMAKE_CURRENT_BINARY_DIR}/${_name} # ensure same directory! Required by gcc
DEPENDS ${_input}
)
#message("_command ${_input} ${_output}")
_PCH_GET_COMPILE_COMMAND(_command ${CMAKE_CURRENT_BINARY_DIR}/${_name} ${_output} )
#message(${_input} )
#message("_output ${_output}")
ADD_CUSTOM_COMMAND(
OUTPUT ${_output}
COMMAND ${_command}
DEPENDS ${_input} ${CMAKE_CURRENT_BINARY_DIR}/${_name} ${_targetName}_pch_dephelp
)
ADD_PRECOMPILED_HEADER_TO_TARGET(${_targetName} ${_input} ${_output} ${_dowarn})
ENDMACRO(ADD_PRECOMPILED_HEADER)
# Generates the use of precompiled in a target,
# without using depency targets (2 extra for each target)
# Using Visual, must also add ${_targetName}_pch to sources
# Not needed by Xcode
MACRO(GET_NATIVE_PRECOMPILED_HEADER _targetName _input)
if(CMAKE_GENERATOR MATCHES Visual*)
SET(_dummy_str "#include \"${_input}\"\n"
"// This is required to suppress LNK4221. Very annoying.\n"
"void *g_${_targetName}Dummy = 0\;\n")
# Use of cxx extension for generated files (as Qt does)
SET(${_targetName}_pch ${CMAKE_CURRENT_BINARY_DIR}/${_targetName}_pch.cxx)
if(EXISTS ${${_targetName}_pch})
# Check if contents is the same, if not rewrite
# todo
else(EXISTS ${${_targetName}_pch})
FILE(WRITE ${${_targetName}_pch} ${_dummy_str})
endif(EXISTS ${${_targetName}_pch})
endif(CMAKE_GENERATOR MATCHES Visual*)
ENDMACRO(GET_NATIVE_PRECOMPILED_HEADER)
MACRO(ADD_NATIVE_PRECOMPILED_HEADER _targetName _input)
IF( "${ARGN}" STREQUAL "0")
SET(_dowarn 0)
ELSE( "${ARGN}" STREQUAL "0")
SET(_dowarn 1)
ENDIF("${ARGN}" STREQUAL "0")
if(CMAKE_GENERATOR MATCHES Visual*)
# Auto include the precompile (useful for moc processing, since the use of
# precompiled is specified at the target level
# and I don't want to specifiy /F- for each moc/res/ui generated files (using Qt)
GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS)
if (${oldProps} MATCHES NOTFOUND)
SET(oldProps "")
endif(${oldProps} MATCHES NOTFOUND)
SET(newProperties "${oldProps} /Yu\"${_input}.h\" /FI\"${_input}.h\"")
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES COMPILE_FLAGS "${newProperties}")
#also inlude ${oldProps} to have the same compile options
SET_SOURCE_FILES_PROPERTIES(${_input}.cpp PROPERTIES COMPILE_FLAGS "${oldProps} /Yc\"${_input}.h\"")
else(CMAKE_GENERATOR MATCHES Visual*)
if (CMAKE_GENERATOR MATCHES Xcode)
# For Xcode, cmake needs my patch to process
# GCC_PREFIX_HEADER and GCC_PRECOMPILE_PREFIX_HEADER as target properties
GET_TARGET_PROPERTY(oldProps ${_targetName} COMPILE_FLAGS)
if (${oldProps} MATCHES NOTFOUND)
SET(oldProps "")
endif(${oldProps} MATCHES NOTFOUND)
# When buiding out of the tree, precompiled may not be located
# Use full path instead.
GET_FILENAME_COMPONENT(fullPath ${_input} ABSOLUTE)
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${fullPath}")
SET_TARGET_PROPERTIES(${_targetName} PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES")
else (CMAKE_GENERATOR MATCHES Xcode)
#Fallback to the "old" precompiled suppport
#ADD_PRECOMPILED_HEADER(${_targetName} ${_input} ${_dowarn})
endif(CMAKE_GENERATOR MATCHES Xcode)
endif(CMAKE_GENERATOR MATCHES Visual*)
ENDMACRO(ADD_NATIVE_PRECOMPILED_HEADER)

File diff suppressed because it is too large Load Diff

@ -20,14 +20,14 @@
* THE SOFTWARE.
*/
#include "font.h"
#include "bitmapfont.h"
#include "texturemanager.h"
#include "graphics.h"
#include "image.h"
#include <framework/otml/otml.h>
void Font::load(const OTMLNodePtr& fontNode)
void BitmapFont::load(const OTMLNodePtr& fontNode)
{
OTMLNodePtr textureNode = fontNode->at("texture");
std::string textureFile = stdext::resolve_path(textureNode->value(), textureNode->source());
@ -66,14 +66,14 @@ void Font::load(const OTMLNodePtr& fontNode)
}
}
void Font::drawText(const std::string& text, const Point& startPos)
void BitmapFont::drawText(const std::string& text, const Point& startPos)
{
Size boxSize = g_painter->getResolution() - startPos.toSize();
Rect screenCoords(startPos, boxSize);
drawText(text, screenCoords, Fw::AlignTopLeft);
}
void Font::drawText(const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align)
void BitmapFont::drawText(const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align)
{
static CoordsBuffer coordsBuffer;
coordsBuffer.clear();
@ -82,7 +82,7 @@ void Font::drawText(const std::string& text, const Rect& screenCoords, Fw::Align
g_painter->drawTextureCoords(coordsBuffer, m_texture);
}
void Font::calculateDrawTextCoords(CoordsBuffer& coordsBuffer, const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align)
void BitmapFont::calculateDrawTextCoords(CoordsBuffer& coordsBuffer, const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align)
{
// prevent glitches from invalid rects
if(!screenCoords.isValid() || !m_texture)
@ -158,7 +158,7 @@ void Font::calculateDrawTextCoords(CoordsBuffer& coordsBuffer, const std::string
}
}
const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text,
const std::vector<Point>& BitmapFont::calculateGlyphsPositions(const std::string& text,
Fw::AlignmentFlag align,
Size *textBoxSize) const
{
@ -242,14 +242,14 @@ const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text
return glyphsPositions;
}
Size Font::calculateTextRectSize(const std::string& text)
Size BitmapFont::calculateTextRectSize(const std::string& text)
{
Size size;
calculateGlyphsPositions(text, Fw::AlignTopLeft, &size);
return size;
}
void Font::calculateGlyphsWidthsAutomatically(const ImagePtr& image, const Size& glyphSize)
void BitmapFont::calculateGlyphsWidthsAutomatically(const ImagePtr& image, const Size& glyphSize)
{
int numHorizontalGlyphs = image->getSize().width() / glyphSize.width();
auto texturePixels = image->getPixels();
@ -280,7 +280,7 @@ void Font::calculateGlyphsWidthsAutomatically(const ImagePtr& image, const Size&
}
}
std::string Font::wrapText(const std::string& text, int maxWidth)
std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
{
std::string outText;
std::string line;

@ -20,18 +20,18 @@
* THE SOFTWARE.
*/
#ifndef FONT_H
#define FONT_H
#ifndef BITMAPFONT_H
#define BITMAPFONT_H
#include "declarations.h"
#include <framework/otml/declarations.h>
#include <framework/graphics/coordsbuffer.h>
class Font
class BitmapFont
{
public:
Font(const std::string& name) : m_name(name) { }
BitmapFont(const std::string& name) : m_name(name) { }
/// Load font from otml node
void load(const OTMLNodePtr& fontNode);

@ -23,7 +23,7 @@
#include "cachedtext.h"
#include "painter.h"
#include "fontmanager.h"
#include "font.h"
#include "bitmapfont.h"
CachedText::CachedText()
{

@ -34,13 +34,13 @@ public:
void draw(const Rect& rect);
void wrapText(int maxWidth);
void setFont(const FontPtr& font) { m_font = font; update(); }
void setFont(const BitmapFontPtr& font) { m_font = font; update(); }
void setText(const std::string& text) { m_text = text; update(); }
void setAlign(Fw::AlignmentFlag align) { m_align = align; update(); }
Size getTextSize() { return m_textSize; }
std::string getText() { return m_text; }
FontPtr getFont() { return m_font; }
BitmapFontPtr getFont() { return m_font; }
Fw::AlignmentFlag getAlign() { return m_align; }
private:
@ -51,7 +51,7 @@ private:
Boolean<true> m_textMustRecache;
CoordsBuffer m_textCoordsBuffer;
Rect m_textCachedScreenCoords;
FontPtr m_font;
BitmapFontPtr m_font;
Fw::AlignmentFlag m_align;
};

@ -29,7 +29,7 @@
class Texture;
class Image;
class AnimatedTexture;
class Font;
class BitmapFont;
class CachedText;
class FrameBuffer;
class Shader;
@ -46,7 +46,7 @@ typedef std::weak_ptr<ParticleSystem> ParticleSystemWeakPtr;
typedef std::shared_ptr<Image> ImagePtr;
typedef std::shared_ptr<Texture> TexturePtr;
typedef std::shared_ptr<AnimatedTexture> AnimatedTexturePtr;
typedef std::shared_ptr<Font> FontPtr;
typedef std::shared_ptr<BitmapFont> BitmapFontPtr;
typedef std::shared_ptr<CachedText> CachedTextPtr;
typedef std::shared_ptr<FrameBuffer> FrameBufferPtr;
typedef std::shared_ptr<Shader> ShaderPtr;

@ -29,7 +29,7 @@ FontManager g_fonts;
FontManager::FontManager()
{
m_defaultFont = FontPtr(new Font("emptyfont"));
m_defaultFont = BitmapFontPtr(new BitmapFont("emptyfont"));
}
void FontManager::releaseFonts()
@ -57,7 +57,7 @@ bool FontManager::importFont(std::string fontFile)
}
}
FontPtr font(new Font(name));
BitmapFontPtr font(new BitmapFont(name));
font->load(fontNode);
m_fonts.push_back(font);
@ -74,17 +74,17 @@ bool FontManager::importFont(std::string fontFile)
bool FontManager::fontExists(const std::string& fontName)
{
for(const FontPtr& font : m_fonts) {
for(const BitmapFontPtr& font : m_fonts) {
if(font->getName() == fontName)
return true;
}
return false;
}
FontPtr FontManager::getFont(const std::string& fontName)
BitmapFontPtr FontManager::getFont(const std::string& fontName)
{
// find font by name
for(const FontPtr& font : m_fonts) {
for(const BitmapFontPtr& font : m_fonts) {
if(font->getName() == fontName)
return font;
}

@ -23,7 +23,7 @@
#ifndef FONTMANAGER_H
#define FONTMANAGER_H
#include "font.h"
#include "bitmapfont.h"
class FontManager
{
@ -37,14 +37,14 @@ public:
bool importFont(std::string fontFile);
bool fontExists(const std::string& fontName);
FontPtr getFont(const std::string& fontName);
FontPtr getDefaultFont() { return m_defaultFont; }
BitmapFontPtr getFont(const std::string& fontName);
BitmapFontPtr getDefaultFont() { return m_defaultFont; }
void setDefaultFont(const std::string& fontName) { m_defaultFont = getFont(fontName); }
private:
std::vector<FontPtr> m_fonts;
FontPtr m_defaultFont;
std::vector<BitmapFontPtr> m_fonts;
BitmapFontPtr m_defaultFont;
};
extern FontManager g_fonts;

@ -20,6 +20,9 @@
* THE SOFTWARE.
*/
#ifndef PAINTEROGL2_SHADERSOURCES_H
#define PAINTEROGL2_SHADERSOURCES_H
static const std::string glslMainVertexShader = "\n\
highp vec4 calculatePosition();\n\
void main() {\n\
@ -66,3 +69,5 @@ static const std::string glslSolidColorFragmentShader = "\n\
lowp vec4 calculatePixel() {\n\
return u_Color;\n\
}\n";
#endif

@ -78,6 +78,7 @@ bool Shader::compileSourceFile(const std::string& sourceFile)
} catch(stdext::exception& e) {
g_logger.error(stdext::format("unable to load shader source form file: %s", sourceFile));
}
return false;
}
std::string Shader::log()

@ -95,7 +95,7 @@ namespace luabinder
template<typename Ret, typename F, typename Tuple>
LuaCppFunction bind_fun_specializer(const F& f) {
enum { N = std::tuple_size<Tuple>::value };
return [=](LuaInterface* lua) {
return [=](LuaInterface* lua) -> int {
if(lua->stackSize() != N)
throw LuaBadNumberOfArgumentsException(N, lua->stackSize());
Tuple tuple;
@ -248,7 +248,7 @@ namespace luabinder
template<typename C>
LuaCppFunction bind_mem_fun(int (C::*f)(LuaInterface*)) {
auto mf = std::mem_fn(f);
return [=](LuaInterface* lua) {
return [=](LuaInterface* lua) -> int {
auto obj = lua->castValue<std::shared_ptr<C>>(1);
lua->remove(1);
return mf(obj, lua);

@ -53,7 +53,7 @@ void LuaInterface::init()
bindClassMemberFunction<LuaObject>("getUseCount", &LuaObject::getUseCount);
bindClassMemberFunction<LuaObject>("getClassName", &LuaObject::getClassName);
registerClassMemberFunction<LuaObject>("getFieldsTable", (LuaCppFunction) ([](LuaInterface* lua) {
registerClassMemberFunction<LuaObject>("getFieldsTable", (LuaCppFunction) ([](LuaInterface* lua) -> int {
LuaObjectPtr obj = g_lua.popObject();
obj->luaGetFieldsTable();
return 1;

@ -23,6 +23,11 @@
#ifndef STDEXT_CAST_H
#define STDEXT_CAST_H
namespace stdext {
template<typename R, typename T> R safe_cast(const T& t);
template<typename R, typename T> R unsafe_cast(const T& t, R def = R());
}
#include "string.h"
#include "exception.h"
#include "demangle.h"
@ -107,7 +112,7 @@ R safe_cast(const T& t) {
// cast a type to another type, cast errors are ignored
template<typename R, typename T>
R unsafe_cast(const T& t, R def = R()) {
R unsafe_cast(const T& t, R def) {
try {
return safe_cast<R,T>(t);
} catch(cast_exception& e) {

@ -23,12 +23,19 @@
#ifndef STDEXT_COMPILER_H
#define STDEXT_COMPILER_H
#if !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#error "sorry, you need gcc 4.6 or greater to compile"
#ifdef __clang__
// clang is supported
#undef _GLIBCXX_USE_FLOAT128
#elif defined(__GNUC__)
#if !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#error "Sorry, you need gcc 4.6 or greater to compile."
#endif
#else
#error "Compiler not supported."
#endif
#if !defined(__GXX_EXPERIMENTAL_CXX0X__)
#error "sorry, you must enable C++0x to compile"
#error "Sorry, you must enable C++0x to compile."
#endif
// hack to enable std::thread on mingw32 4.6

@ -37,10 +37,6 @@
namespace stdext {
// casts declaration, definition will be included at the end of the file
template<typename R, typename T> R safe_cast(const T& t);
template<typename R, typename T> R unsafe_cast(const T& t, R def = R());
/// Convert any type to std::string
template<typename T>
std::string to_string(const T& t) { return unsafe_cast<std::string, T>(t); }

@ -375,3 +375,5 @@ int luaopen_bit32 (lua_State *L) {
return 1;
}
#undef trim

@ -335,16 +335,15 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode)
styleNode->writeAt("__unique", true);
}
// TODO: styles must be searched by widget scopes, in that way this warning could be fixed
// this warning is disabled because many ppl was complening about it
/*
auto it = m_styles.find(name);
if(it != m_styles.end())
g_logger.warning("style '%s' is being redefined", name);
*/
// Warn about redefined styles
if(!g_app->isRunning() && !unique) {
auto it = m_styles.find(name);
if(it != m_styles.end())
g_logger.warning(stdext::format("style '%s' is being redefined", name));
}
OTMLNodePtr oldStyle = m_styles[name];
if(!oldStyle || oldStyle->valueAt("__unique", false) || unique) {
if(!oldStyle || !oldStyle->valueAt("__unique", false) || unique) {
OTMLNodePtr originalStyle = getStyle(base);
if(!originalStyle)
stdext::throw_exception(stdext::format("base style '%s', is not defined", base));

@ -21,7 +21,7 @@
*/
#include "uitextedit.h"
#include <framework/graphics/font.h>
#include <framework/graphics/bitmapfont.h>
#include <framework/graphics/graphics.h>
#include <framework/platform/platformwindow.h>
#include <framework/core/clock.h>

@ -1208,7 +1208,7 @@ void UIWidget::updateState(Fw::WidgetState state)
newStatus = false;
break;
}
} while(widget = parent);
} while((widget = parent));
updateChildren = newStatus != oldStatus;
break;
@ -1237,7 +1237,7 @@ void UIWidget::updateState(Fw::WidgetState state)
enabled = false;
break;
}
} while(widget = widget->getParent());
} while((widget = widget->getParent()));
newStatus = !enabled;
updateChildren = newStatus != oldStatus;
break;

@ -27,7 +27,7 @@
#include <framework/luascript/luaobject.h>
#include <framework/graphics/declarations.h>
#include <framework/otml/otmlnode.h>
#include <framework/graphics/font.h>
#include <framework/graphics/bitmapfont.h>
#include <framework/graphics/coordsbuffer.h>
#include <framework/core/timer.h>
@ -465,7 +465,7 @@ protected:
Point m_textOffset;
Boolean<false> m_textWrap;
Boolean<false> m_textAutoResize;
FontPtr m_font;
BitmapFontPtr m_font;
public:
void resizeToText() { setSize(getTextSize()); }

@ -214,7 +214,7 @@ public:
struct PositionHasher : std::unary_function<Position, std::size_t> {
std::size_t operator()(const Position& pos) const {
return ((((pos.x * 65536) + pos.y) * 15) + pos.z) % 1000000;
return ((((pos.x * 32768) + pos.y) * 16) + pos.z) % 1000000;
}
};

Loading…
Cancel
Save