diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8834f79..65cb98f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -195,7 +195,19 @@ else () message(FATAL_ERROR "${PROJECT_NAME} requires g++ 4.7 or greater.") endif () elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") + add_definitions("-Weverything" + "-Wno-shadow" "-Wno-undef" + "-Wno-global-constructors" "-Wno-weak-vtables" + "-Wno-padded" "-Wno-exit-time-destructors" + "-Wno-mismatched-tags" # struct vs. class for std::hash + # Demands double curly braces at std::array initialization: + "-Wno-missing-braces" + "-Wno-covered-switch-default" "-Wno-float-equal" + "-Wno-c++98-compat" "-Wno-c++98-compat-pedantic") + list(APPEND JD_HEADERS "clang_stdlib_config.hpp") + set(stdlibcfg "${CMAKE_CURRENT_SOURCE_DIR}/clang_stdlib_config.hpp") + add_definitions("-DBOOST_STDLIB_CONFIG=\"${stdlibcfg}\"" + "-D_GLIBCXX_USE_WCHAR_T") else () message(FATAL_ERROR "Your C++ compiler does not support C++11.") endif () diff --git a/src/Logfile.cpp b/src/Logfile.cpp index 27aaa41..cdaea85 100644 --- a/src/Logfile.cpp +++ b/src/Logfile.cpp @@ -35,9 +35,14 @@ class Logfile::LineNotifier :public boost::iostreams::line_filter static const std::string full_time() { std::time_t tms = std::time(nullptr); -#pragma warning (disable:4996) +#ifdef BOOST_MSVC +# pragma warning (push) +# pragma warning (disable:4996) +#endif return ctime(&tms); -#pragma warning (default:4996) +#ifdef BOOST_MSVC +# pragma warning (pop) +#endif } const std::string Logfile::printable_time() const @@ -149,7 +154,7 @@ void Logfile::write(std::string const& msg, loglevel level_, char const* locatio if (level_ < m_min_level) return; - auto level = static_cast(level_); + auto level = static_cast(level_); static auto const maxloglevel = static_cast(loglevel::max); static_assert(maxloglevel == 5, "Please correct levelnames below!"); diff --git a/src/MapInfo.cpp b/src/MapInfo.cpp index 9b7e0bf..5ca0743 100644 --- a/src/MapInfo.cpp +++ b/src/MapInfo.cpp @@ -197,8 +197,9 @@ MapInfo loadTilemap(jd::Tilemap& tm, std::string const& vfilename) tm.setSize(jd::Vector3u( map.get(".width"), map.get(".height"), - rng::count_if(map, [](pt::ptree::value_type const& e) { - return e.first == "layer"; }))); + static_cast( + rng::count_if(map, [](pt::ptree::value_type const& e) { + return e.first == "layer"; })))); if (tm.size().x * tm.size().y * tm.size().z == 0) throw jd::ResourceLoadError("map is empty"); diff --git a/src/Resources.rc b/src/Resources.rc index bc0d250..ab129f4 100644 --- a/src/Resources.rc +++ b/src/Resources.rc @@ -1,29 +1,29 @@ -#define APPN "Jade Engine" -#define VERSION_ 0,12,1,0 -#define VERSION_STR "Beta 0.12.1" - -0 ICON DISCARDABLE jd.ico - -1 VERSIONINFO - FILEVERSION VERSION_ - PRODUCTVERSION VERSION_ -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000704b0" - BEGIN - VALUE "CompanyName", "Christian Neumüller" - VALUE "FileDescription", "Jade Game Engine" - VALUE "FileVersion", VERSION_STR - VALUE "InternalName", APPN - VALUE "LegalCopyright", "Copyright © 2013" - VALUE "OriginalFilename", "jd.exe" - VALUE "ProductName", APPN - VALUE "ProductVersion", VERSION_STR - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x7, 1200 - END -END +#define APPN "Jade Engine" +#define VERSION_ 0,12,1,0 +#define VERSION_STR "Beta 0.12.1" + +0 ICON DISCARDABLE jd.ico + +1 VERSIONINFO + FILEVERSION VERSION_ + PRODUCTVERSION VERSION_ +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000704b0" + BEGIN + VALUE "CompanyName", "Christian Neumüller" + VALUE "FileDescription", "Jade Game Engine" + VALUE "FileVersion", VERSION_STR + VALUE "InternalName", APPN + VALUE "LegalCopyright", "Copyright © 2013" + VALUE "OriginalFilename", "jd.exe" + VALUE "ProductName", APPN + VALUE "ProductVersion", VERSION_STR + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x7, 1200 + END +END diff --git a/src/Tilemap.cpp b/src/Tilemap.cpp index 2eac667..3d9da44 100644 --- a/src/Tilemap.cpp +++ b/src/Tilemap.cpp @@ -93,9 +93,9 @@ void Tilemap::setSize(Vector3u const& size) Vector3u Tilemap::size() const { return Vector3u( - m_columnCount, - m_rowCount, - m_map.size() / (m_columnCount * m_rowCount)); + static_cast(m_columnCount), + static_cast(m_rowCount), + static_cast(m_map.size() / (m_columnCount * m_rowCount))); } @@ -136,8 +136,8 @@ std::size_t Tilemap::index(Vector3u pos) const sf::Vector2f Tilemap::localTilePos(sf::Vector2i pos) const { return sf::Vector2f( - static_cast(pos.x * m_tileset.size().x), - static_cast(pos.y * m_tileset.size().y)); + static_cast(pos.x * static_cast(m_tileset.size().x)), + static_cast(pos.y * static_cast(m_tileset.size().y))); } sf::Vector2f Tilemap::globalTilePos(sf::Vector2i pos) const @@ -214,34 +214,40 @@ void Tilemap::draw(sf::RenderTarget& target, sf::RenderStates states) const sf::FloatRect const viewRect(jd::viewRect(target.getView())); Vector3u size = this->size(); - sf::Vector2i firstTPos(tilePosFromGlobal(topLeft(viewRect))); - firstTPos.x = std::max(firstTPos.x, 0); - firstTPos.y = std::max(firstTPos.y, 0); - sf::Vector2i lastTPos(tilePosFromGlobal(bottomRight(viewRect))); - lastTPos.x = std::min(lastTPos.x + 1, static_cast(size.x)); - lastTPos.y = std::min(lastTPos.y + 1, static_cast(size.y)); - sf::Vector2i distance(lastTPos - firstTPos); - if (distance.x <= 0 || distance.y <= 0) + sf::Vector2i firstTPosI(tilePosFromGlobal(topLeft(viewRect))); + firstTPosI.x = std::max(firstTPosI.x, 0); + firstTPosI.y = std::max(firstTPosI.y, 0); + sf::Vector2i lastTPosI(tilePosFromGlobal(bottomRight(viewRect))); + lastTPosI.x = std::min(lastTPosI.x + 1, static_cast(size.x)); + lastTPosI.y = std::min(lastTPosI.y + 1, static_cast(size.y)); + sf::Vector2i distanceI = lastTPosI - firstTPosI; + if (distanceI.x <= 0 || distanceI.y <= 0) return; + + auto distance = vec_cast(distanceI); + + auto firstTPos = vec_cast(firstTPosI); + auto lastTPos = vec_cast(lastTPosI); + std::size_t const renderedTileCount = distance.x * distance.y * size.z; static std::size_t const verticesPerTile = 4; std::vector vertices(renderedTileCount * verticesPerTile); - sf::Vector2f const firstPos(localTilePos(firstTPos)); + sf::Vector2f const firstPos(localTilePos(firstTPosI)); std::size_t iVertices = 0; - sf::Vector2f const tileSize(m_tileset.size()); + auto const tileSize = vec_cast(m_tileset.size()); std::size_t const mapSkipY = size.x - distance.x; std::size_t const mapSkipZ = size.x * size.y - distance.x * distance.y - mapSkipY * distance.y; std::size_t iMap = index(Vector3u( - firstTPos.x, - firstTPos.y, + static_cast(firstTPos.x), + static_cast(firstTPos.y), 0)); sf::Vector2f iPos(firstPos); - for (std::size_t z = 0; z < size.z; ++z) { - for (std::size_t y = firstTPos.y; y < static_cast(lastTPos.y); ++y){ - for (std::size_t x = firstTPos.x; x < static_cast(lastTPos.x); ++x) { + for (unsigned z = 0; z < size.z; ++z) { + for (unsigned y = firstTPos.y; y < static_cast(lastTPos.y); ++y){ + for (unsigned x = firstTPos.x; x < static_cast(lastTPos.x); ++x) { assert(index(Vector3u(x, y, z)) == iMap); unsigned const tileId = m_map[iMap++]; if (tileId == 0) { @@ -249,7 +255,9 @@ void Tilemap::draw(sf::RenderTarget& target, sf::RenderStates states) const iPos.x += tileSize.x; continue; } - sf::Vector2f texPos(m_tileset.position(maybeAnimated(tileId, Vector3u(x, y, z)) - 1)); + sf::Vector2f texPos(m_tileset.position( + static_cast(maybeAnimated( + tileId, Vector3u(x, y, z)) - 1))); vertices[iVertices].texCoords = texPos; vertices[iVertices++].position = iPos; vertices[iVertices].texCoords = sf::Vector2f(texPos.x, texPos.y + tileSize.y); @@ -271,7 +279,11 @@ void Tilemap::draw(sf::RenderTarget& target, sf::RenderStates states) const return; states.transform *= getTransform(); states.texture = m_tileset.texture().get(); - target.draw(&vertices[0], vertices.size(), sf::Quads, states); + target.draw( + &vertices[0], + static_cast(vertices.size()), + sf::Quads, + states); } // Tilemap::draw() bool Tilemap::isValidPosition(sf::Vector3i pos) const diff --git a/src/WeakRef.hpp b/src/WeakRef.hpp index 9cd846e..280c1d2 100644 --- a/src/WeakRef.hpp +++ b/src/WeakRef.hpp @@ -131,10 +131,6 @@ class EnableWeakRefFromThis { m_connection(nullptr) { } - EnableWeakRefFromThis(EnableWeakRefFromThis const& rhs): - m_connection(nullptr) // reset connection - { } - WeakRef ref() { ensureConnection(); diff --git a/src/base64.cpp b/src/base64.cpp index 3171e2d..260e6d3 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -72,9 +72,9 @@ std::vector decode(byte const* encoded, std::size_t byteCount) charToByte); std::array outBytes; - outBytes[0] = inBytes[0] << '\2' | inBytes[1] >> '\4'; - outBytes[1] = inBytes[1] << '\4' | inBytes[2] >> '\2'; - outBytes[2] = inBytes[2] << '\6' | inBytes[3]; + outBytes[0] = static_cast(inBytes[0] << 2 | inBytes[1] >> 4); + outBytes[1] = static_cast(inBytes[1] << 4 | inBytes[2] >> 2); + outBytes[2] = static_cast(inBytes[2] << 6 | inBytes[3]); if (i + 4 == byteCount) { std::size_t discard = 0; diff --git a/src/clang_stdlib_config.hpp b/src/clang_stdlib_config.hpp new file mode 100644 index 0000000..f213a27 --- /dev/null +++ b/src/clang_stdlib_config.hpp @@ -0,0 +1,12 @@ +#include + +// Let's hope for the best: +#undef BOOST_NO_CXX11_HDR_CONDITION_VARIABLE +#undef BOOST_NO_CXX11_HDR_FORWARD_LIST +#undef BOOST_NO_CXX11_HDR_INITIALIZER_LIST +#undef BOOST_NO_CXX11_HDR_MUTEX +#undef BOOST_NO_CXX11_HDR_RATIO +#undef BOOST_NO_CXX11_HDR_SYSTEM_ERROR +#undef BOOST_NO_CXX11_SMART_PTR + +#undef BOOST_NO_CXX11_HDR_TYPE_TRAITS // HACK diff --git a/src/collision/Collisions.hpp b/src/collision/Collisions.hpp index f03fda6..e0c3478 100644 --- a/src/collision/Collisions.hpp +++ b/src/collision/Collisions.hpp @@ -41,7 +41,7 @@ class CollideableGroup: public EnableWeakRefFromThis { CollideableGroup& other, DelegateState delegated = DelegateState::notDelegated) { other.collideWith(*this, nextDelegateState(delegated)); } - virtual void collide() { }; // Check for internal collisions + virtual void collide() { } // Check for internal collisions virtual void clear() = 0; diff --git a/src/collision/TileCollideableGroup.cpp b/src/collision/TileCollideableGroup.cpp index 3478ed9..4ef44f7 100644 --- a/src/collision/TileCollideableGroup.cpp +++ b/src/collision/TileCollideableGroup.cpp @@ -78,12 +78,13 @@ Collision TileCollideableInfo::makeCollision( Vector3u pos, Entity* e, sf::FloatRect const& r) { auto const iEntity = m_entities.find(pos); + sf::Vector2i const ipos2(static_cast(pos.x), static_cast(pos.y)); if (iEntity != m_entities.end()) { if (e) iEntity->second->notifyCollision(pos, *e, r); return Collision( iEntity->second->parent(), - m_tilemap.globalTileRect(sf::Vector2i(pos.x, pos.y))); + m_tilemap.globalTileRect(ipos2)); } else { unsigned const tileId = m_tilemap[pos]; auto const iProxy = m_proxyEntities.find(tileId); @@ -92,7 +93,7 @@ Collision TileCollideableInfo::makeCollision( iProxy->second->notifyCollision(pos, *e, r); return Collision( iProxy->second->parent(), - m_tilemap.globalTileRect(sf::Vector2i(pos.x, pos.y))); + m_tilemap.globalTileRect(ipos2)); } } // if no entity at pos registered return Collision(); @@ -226,24 +227,26 @@ sf::Vector2u TileCollideableInfo::findNext( std::size_t TileCollideableInfo::mapCorners( sf::FloatRect const& r, - sf::Vector2u& begin, - sf::Vector2u& last) + sf::Vector2u& begin_out, + sf::Vector2u& last_out) { - begin = static_cast( - m_tilemap.tilePosFromGlobal(jd::topLeft(r))); - begin.x = std::max(begin.x, 0u); - begin.y = std::max(begin.y, 0u); - last = static_cast( - m_tilemap.tilePosFromGlobal(jd::bottomRightIn(r))); - last.x = std::min(last.x, m_tilemap.size().x - 1); - last.y = std::min(last.y, m_tilemap.size().y - 1); + auto begin = m_tilemap.tilePosFromGlobal(jd::topLeft(r)); + begin.x = std::max(begin.x, 0); + begin.y = std::max(begin.y, 0); + auto last = m_tilemap.tilePosFromGlobal(jd::bottomRightIn(r)); + auto isize = jd::vec_cast(m_tilemap.size()); + last.x = std::min(last.x, isize.x - 1); + last.y = std::min(last.y, isize.y - 1); int intersectingPerLayer = (last.x - begin.x + 1) * (last.y - begin.y + 1); if (intersectingPerLayer <= 0) { return 0; } + + begin_out = jd::vec_cast(begin); + last_out = jd::vec_cast(last); - return intersectingPerLayer * m_tilemap.size().z; + return static_cast(intersectingPerLayer) * m_tilemap.size().z; } @@ -256,8 +259,9 @@ std::vector filter( std::size_t i = 0; while (i < collisions.size()) { if (!pred(positions[i].z)) { - collisions.erase(collisions.begin() + i); - positions.erase(positions.begin() + i); + auto off = static_cast(i); + collisions.erase(collisions.begin() + off); + positions.erase(positions.begin() + off); } else { ++i; } diff --git a/src/collision/TileCollideableGroup.hpp b/src/collision/TileCollideableGroup.hpp index 896073c..dd3ee28 100644 --- a/src/collision/TileCollideableGroup.hpp +++ b/src/collision/TileCollideableGroup.hpp @@ -28,12 +28,12 @@ class TileCollideableInfo: public EnableWeakRefFromThis { WeakRef colliding(Vector3u pos); // notify if e != nullptr - virtual std::vector colliding( + std::vector colliding( sf::FloatRect const&, Entity* e = nullptr, std::vector* positions = nullptr); - virtual std::vector colliding( + std::vector colliding( sf::Vector2f lineStart, sf::Vector2f lineEnd, std::vector* positions = nullptr); @@ -41,7 +41,7 @@ class TileCollideableInfo: public EnableWeakRefFromThis { jd::Tilemap& tilemap() { return m_tilemap; } Vector3u mapsize() const; - virtual void clear() { m_entities.clear(); m_proxyEntities.clear(); } + void clear() { m_entities.clear(); m_proxyEntities.clear(); } Collision makeCollision( Vector3u pos, diff --git a/src/compsys/Component.hpp b/src/compsys/Component.hpp index 75b317d..20bb958 100644 --- a/src/compsys/Component.hpp +++ b/src/compsys/Component.hpp @@ -10,6 +10,7 @@ #include #include +#include class MetaComponent; @@ -57,4 +58,7 @@ inline T* component_cast(Component* c) // safe & a bit slower virtual class MetaComponent const& metaComponent() const { return staticMetaComponent; } \ private: + +std::ostream& operator<< (std::ostream& os, Component const& c); + #endif diff --git a/src/compsys/MetaComponent.cpp b/src/compsys/MetaComponent.cpp index 07497b4..f4847c7 100644 --- a/src/compsys/MetaComponent.cpp +++ b/src/compsys/MetaComponent.cpp @@ -24,6 +24,10 @@ static char const libname[] = "ComponentSystem"; #include "luaexport/ExportThis.hpp" +std::ostream& operator<< (std::ostream& os, Component const& c) +{ + return os << "jd.Component (" << c.metaComponent().name() << " @" << &c << ')'; +} namespace { @@ -38,7 +42,7 @@ static std::string const& Component_componentName(Component const& c) return c.metaComponent().name(); } -luabind::object Component_parent(Component const& c, lua_State* L) +static luabind::object Component_parent(Component const& c, lua_State* L) { if (c.parent()) return luabind::object(L, c.parent()->ref()); @@ -46,11 +50,6 @@ luabind::object Component_parent(Component const& c, lua_State* L) return luabind::object(); } -static std::ostream& operator<< (std::ostream& os, Component const& c) -{ - return os << "jd.Component (" << c.metaComponent().name() << " @" << &c << ')'; -} - static ssig::ConnectionBase* connectEvent( lua_State* L, Component& sender, @@ -186,7 +185,6 @@ bool operator< (MetaComponent const& lhs, MetaComponent const& rhs) /////////////////////////////////////////////////////// LuaMetaComponent::LuaMetaComponent(lua_State* L, std::string const& name): - m_L(L), m_name(name) { ComponentRegistry::get(L).registerComponent(this); @@ -204,11 +202,11 @@ void LuaMetaComponent::castDown(lua_State* L, Component* c) const o.push(L); } -ssig::ConnectionBase* LuaMetaComponent::connectEvent(Component* c, std::string const& name) const +ssig::ConnectionBase* LuaMetaComponent::connectEvent(lua_State* L, Component* c, std::string const& name) const { using namespace luabind; - object receiver(from_stack(m_L, -1)); - object callback = globals(m_L)[jd::moduleName]["callback_connectLuaEvent"]; + object receiver(from_stack(L, -1)); + object callback = globals(L)[jd::moduleName]["callback_connectLuaEvent"]; if (type(callback) != LUA_TFUNCTION) throw std::runtime_error("no callback for event connection defined (must be a plain function)"); return object_cast(callback(c, name, receiver)[adopt(result)]); diff --git a/src/compsys/MetaComponent.hpp b/src/compsys/MetaComponent.hpp index 515a12d..f119cf1 100644 --- a/src/compsys/MetaComponent.hpp +++ b/src/compsys/MetaComponent.hpp @@ -31,7 +31,7 @@ class InvalidMetaComponentName: public std::runtime_error { // places result on top of stack. virtual void castDown(lua_State*, Component*) const { - assert(!"not scriptable!"); + assert("not scriptable!" && false); throw std::runtime_error("castDown() is not implemented."); } @@ -54,14 +54,14 @@ bool operator< (MetaComponent const& lhs, MetaComponent const& rhs); class LuaMetaComponent: public MetaComponent { public: - LuaMetaComponent(lua_State* L, std::string const& name); - virtual std::string const& name() const; + explicit LuaMetaComponent(lua_State* L, std::string const& name); + std::string const& name() const override; - virtual void castDown(lua_State* L, Component* c) const override; - virtual ssig::ConnectionBase* connectEvent(Component* c, std::string const& name) const; + void castDown(lua_State* L, Component* c) const override; + ssig::ConnectionBase* connectEvent( + lua_State* L, Component* c, std::string const& name) const override; private: - lua_State* m_L; std::string const m_name; }; diff --git a/src/createComponent.py b/src/createComponent.py index 6ccd46f..c4a691c 100644 --- a/src/createComponent.py +++ b/src/createComponent.py @@ -1,104 +1,104 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Part of the Jade Engine -- Copyright (c) Christian Neumüller 2012--2013 -# This file is subject to the terms of the BSD 2-Clause License. -# See LICENSE.txt or http://opensource.org/licenses/BSD-2-Clause - -import string -import sys -from os.path import exists - -HEADER_TEMPLATE = string.Template( -"""#ifndef $includeGuard -#define $includeGuard $includeGuard - -#include "compsys/Component.hpp" -#include - -class $compName: public Component { - JD_COMPONENT - -public: - $compName(); - ~$compName(); - -private: - -}; - -#endif - -""") - -IMPLEMENTATION_TEMPLATE = string.Template( -"""#include "$compName.hpp" - -$compName::$compName() -{ -} - -$compName::~$compName() -{ -} - -""") - -META_TEMPLATE = string.Template( -"""#include "$headerPath" -#include "compsys/BasicMetaComponent.hpp" - -static char const libname[] = "$compName"; -#include "ExportThis.hpp" - -JD_SINGLETON_COMPONENT_IMPL($compName) - -static void init(LuaVm& vm) -{ - vm.initLib("ComponentSystem"); - LHMODULE [ -# define LHCURCLASS $compName - class_("$compName") - -# undef LHCURCLASS - ]; -} - -""") - - -def createComponent(name, pathPrefix = "comp/"): - - headerPath = pathPrefix + name + ".hpp" - implPath = pathPrefix + name + ".cpp" - metaPath = "luaexport/" + name + "Meta.cpp" - - print "COMP_HEADERS +=", headerPath - print "COMP_SOURCES +=", implPath - print "LUAEXPORT_SOURCES +=", metaPath - - if (exists(headerPath) or exists(implPath) or exists(metaPath)): - print "One or more files already exist. Aborting." - sys.exit(1) - - tmplArgs = { - "headerPath": headerPath, - "compName": name, - "includeGuard": name.upper() + "_HPP_INCLUDED" - } - - def writeout(fname, tmpl): - with open(fname, "w") as f: - f.write(tmpl.substitute(tmplArgs)) - - writeout(headerPath, HEADER_TEMPLATE) - writeout(implPath, IMPLEMENTATION_TEMPLATE) - writeout(metaPath, META_TEMPLATE) - - -if __name__ == "__main__": - compPath = (sys.argv[2] if len(sys.argv) > 2 else "comp") + "/" - - createComponent( - sys.argv[1], - compPath) +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Part of the Jade Engine -- Copyright (c) Christian Neumüller 2012--2013 +# This file is subject to the terms of the BSD 2-Clause License. +# See LICENSE.txt or http://opensource.org/licenses/BSD-2-Clause + +import string +import sys +from os.path import exists + +HEADER_TEMPLATE = string.Template( +"""#ifndef $includeGuard +#define $includeGuard $includeGuard + +#include "compsys/Component.hpp" +#include + +class $compName: public Component { + JD_COMPONENT + +public: + $compName(); + ~$compName(); + +private: + +}; + +#endif + +""") + +IMPLEMENTATION_TEMPLATE = string.Template( +"""#include "$compName.hpp" + +$compName::$compName() +{ +} + +$compName::~$compName() +{ +} + +""") + +META_TEMPLATE = string.Template( +"""#include "$headerPath" +#include "compsys/BasicMetaComponent.hpp" + +static char const libname[] = "$compName"; +#include "ExportThis.hpp" + +JD_SINGLETON_COMPONENT_IMPL($compName) + +static void init(LuaVm& vm) +{ + vm.initLib("ComponentSystem"); + LHMODULE [ +# define LHCURCLASS $compName + class_("$compName") + +# undef LHCURCLASS + ]; +} + +""") + + +def createComponent(name, pathPrefix = "comp/"): + + headerPath = pathPrefix + name + ".hpp" + implPath = pathPrefix + name + ".cpp" + metaPath = "luaexport/" + name + "Meta.cpp" + + print "COMP_HEADERS +=", headerPath + print "COMP_SOURCES +=", implPath + print "LUAEXPORT_SOURCES +=", metaPath + + if (exists(headerPath) or exists(implPath) or exists(metaPath)): + print "One or more files already exist. Aborting." + sys.exit(1) + + tmplArgs = { + "headerPath": headerPath, + "compName": name, + "includeGuard": name.upper() + "_HPP_INCLUDED" + } + + def writeout(fname, tmpl): + with open(fname, "w") as f: + f.write(tmpl.substitute(tmplArgs)) + + writeout(headerPath, HEADER_TEMPLATE) + writeout(implPath, IMPLEMENTATION_TEMPLATE) + writeout(metaPath, META_TEMPLATE) + + +if __name__ == "__main__": + compPath = (sys.argv[2] if len(sys.argv) > 2 else "comp") + "/" + + createComponent( + sys.argv[1], + compPath) diff --git a/src/luaUtils.cpp b/src/luaUtils.cpp index efdfa98..87888e2 100644 --- a/src/luaUtils.cpp +++ b/src/luaUtils.cpp @@ -155,7 +155,9 @@ static const char* loader(lua_State*, void* ud, std::size_t* sz) assert(ud); assert(sz); LoadInfo& loadinfo = *static_cast(ud); - sf::Int64 r = loadinfo.f.read(&loadinfo.buf[0], loadinfo.buf.size()); + sf::Int64 r = loadinfo.f.read( + &loadinfo.buf[0], + static_cast(loadinfo.buf.size())); if (r >= 0) { *sz = static_cast(r); return &loadinfo.buf[0]; @@ -169,7 +171,8 @@ static int dumper(lua_State*, const void* p, std::size_t sz, void* ud) assert(p); assert(ud); VFile& f = *static_cast(ud); - return f.write(p, sz) == sz ? 0 : -1; + auto isz = static_cast(sz); + return f.write(p, isz) == isz ? 0 : -1; } @@ -250,12 +253,12 @@ StackBalance::~StackBalance() if (m_action & pop) lua_settop(m_L, m_desiredTop); else if (m_action & debug) - assert(!"unbalanced stack: too much elements"); + assert("unbalanced stack: too much elements" && false); } else if (top < m_desiredTop) { if (m_action & pushNil) lua_settop(m_L, m_desiredTop); else if (m_action & debug) - assert(!"unbalanced stack: too less elements"); + assert("unbalanced stack: too less elements" && false); } } diff --git a/src/luaexport/Geometry.cpp b/src/luaexport/Geometry.cpp index a36da69..31c84e3 100644 --- a/src/luaexport/Geometry.cpp +++ b/src/luaexport/Geometry.cpp @@ -196,7 +196,7 @@ static int geo_index(lua_State* L) return 1; } -bool geo_setattrib(lua_State* L, char const* n, LuaVec2* v) +static bool geo_setattrib(lua_State* L, char const* n, LuaVec2* v) { if (n[0] != 0 && n[1] == 0) switch (n[0]) { case 'x': v->x = luaL_checknumber(L, 3); return true; @@ -205,7 +205,7 @@ bool geo_setattrib(lua_State* L, char const* n, LuaVec2* v) return false; } -bool geo_setattrib(lua_State* L, char const* n, LuaVec3* v) +static bool geo_setattrib(lua_State* L, char const* n, LuaVec3* v) { if (n[0] != 0 && n[1] == 0) switch (n[0]) { case 'x': v->x = luaL_checknumber(L, 3); return true; @@ -272,7 +272,7 @@ template static int geo_create(lua_State* L); template <> -int geo_create(lua_State* L) +inline int geo_create(lua_State* L) { if (lua_istable(L, 1)) lua_remove(L, 1); // remove table which is called @@ -291,7 +291,7 @@ int geo_create(lua_State* L) } template <> -int geo_create(lua_State* L) +inline int geo_create(lua_State* L) { if (lua_istable(L, 1)) lua_remove(L, 1); // remove table which is called @@ -307,7 +307,7 @@ int geo_create(lua_State* L) } template <> -int geo_create(lua_State* L) +inline int geo_create(lua_State* L) { if (lua_istable(L, 1)) lua_remove(L, 1); // remove table which is called @@ -475,7 +475,7 @@ void Vec_export(lua_State* L) lua_pop(L, 1); } -void Rect_export(lua_State* L) +static void Rect_export(lua_State* L) { int const success = luaL_newmetatable(L, lgeo::Traits::mtName); assert(success); @@ -516,7 +516,7 @@ void Rect_export(lua_State* L) } -void init(LuaVm& vm) +static void init(LuaVm& vm) { lua_State* L = vm.L(); diff --git a/src/luaexport/LuaPackage.cpp b/src/luaexport/LuaPackage.cpp index 607d913..7b8cd33 100644 --- a/src/luaexport/LuaPackage.cpp +++ b/src/luaexport/LuaPackage.cpp @@ -25,7 +25,8 @@ static std::string const searchPath( replace_all(path, "?", name); std::vector> pelems; - split(pelems, path, [](char c) { return c == ';'; }); + static bool(*splitter)(char) = [](char c) { return c == ';'; }; + split(pelems, path, splitter); // hack: The C++ standard does not guarantee that std::string is zero // terminated, only the return value of c_str() is. But even after calling diff --git a/src/luaexport/SfGraphics.cpp b/src/luaexport/SfGraphics.cpp index 19bc2e4..27f6be1 100644 --- a/src/luaexport/SfGraphics.cpp +++ b/src/luaexport/SfGraphics.cpp @@ -7,17 +7,18 @@ #include "ressys/AutoTexture.hpp" #include "ressys/ResourceManager.hpp" #include "ressys/VFileFont.hpp" -#include "sharedPtrConverter.hpp" #include "SfBaseTypes.hpp" #include "sfUtil.hpp" #include "TransformGroup.hpp" #include -#include #include #include +static std::ostream& operator<< (std::ostream& o, sf::Color c); +#include + static char const libname[] = "SfGraphics"; #include "ExportThis.hpp" @@ -47,7 +48,7 @@ static void addTextureProp(luabind::class_& c) } -std::ostream& operator<< (std::ostream& o, sf::Color c) +static std::ostream& operator<< (std::ostream& o, sf::Color c) { return o << "jd.Color(" << static_cast(c.r) << ',' @@ -98,7 +99,7 @@ static void Image_transparentMask(sf::Image& img, sf::Color const& c) static void Text_set##name(sf::Text& text, bool on) \ { \ text.setStyle(on ? text.getStyle() | sf::Text::name \ - : text.getStyle() & ~sf::Text::name); \ + : text.getStyle() & ~static_cast(sf::Text::name)); \ } TEXT_STYLE_PROP(Bold) diff --git a/src/luaexport/SfSystem.cpp b/src/luaexport/SfSystem.cpp index b36a0ab..7d9f3aa 100644 --- a/src/luaexport/SfSystem.cpp +++ b/src/luaexport/SfSystem.cpp @@ -2,10 +2,13 @@ // This file is subject to the terms of the BSD 2-Clause License. // See LICENSE.txt or http://opensource.org/licenses/BSD-2-Clause + #include "luaexport/SfBaseTypes.hpp" -#include #include +#include +static std::ostream& operator<< (std::ostream& os, sf::Time const& v); +#include static char const libname[] = "SfSystem"; #include "ExportThis.hpp" diff --git a/src/luaexport/SfWindow.cpp b/src/luaexport/SfWindow.cpp index 7211f32..e19ffa9 100644 --- a/src/luaexport/SfWindow.cpp +++ b/src/luaexport/SfWindow.cpp @@ -7,10 +7,13 @@ #include "luaUtils.hpp" #include -#include #include #include // for Window_setIcon +#include +static std::ostream& operator<< (std::ostream& os, sf::VideoMode const& v); +#include + char const libname[] = "SfWindow"; #include "ExportThis.hpp" @@ -202,18 +205,16 @@ static void init(LuaVm& vm) .property("position", &MouseEvent_position), # undef LHCURCLASS -# define LHCURCLASS Keyboard namespace_("kb") [ LHFN(keyName) ] -# undef LHCURCLASS ]; lua_State* L = vm.L(); lua_getglobal(L, "jd"); lua_getfield(L, -1, "kb"); static luaU::ExportedEnumValue const keys[] = { -# define E(n, v) {n, Keyboard::v}, +# define KEY(n, v) {n, Keyboard::v}, # include "sfKeyCodes.hpp" {nullptr, 0} }; diff --git a/src/luaexport/container.hpp b/src/luaexport/container.hpp index 81bba19..360b011 100644 --- a/src/luaexport/container.hpp +++ b/src/luaexport/container.hpp @@ -60,8 +60,9 @@ void RandomAccessContainer_set(C& c, typename C::size_type i, luabind::argument --i; if (luabind::type(value) == LUA_TNIL) { + typedef typename C::difference_type offset_t; if (c.size() > i) - c.erase(c.begin() + i); + c.erase(c.begin() + static_cast(i)); else throw std::out_of_range("attempt to set invalid index to nil"); } else { diff --git a/src/luaexport/luaIo.cpp b/src/luaexport/luaIo.cpp index fa86efa..020f11f 100644 --- a/src/luaexport/luaIo.cpp +++ b/src/luaexport/luaIo.cpp @@ -36,7 +36,7 @@ static int writeString(lua_State* L) char const* data = luaL_checklstring(L, 2, &len); try { VFile f(filename, VFile::openW); - f.write(data, len); + f.write(data, static_cast(len)); f.throwError(); f.close(); return 0; @@ -54,7 +54,7 @@ static int readString(lua_State* L) f.throwError(); assert(sz >= 0); std::vector buf(static_cast(sz)); - f.read(&buf[0], buf.size()); + f.read(&buf[0], static_cast(buf.size())); f.throwError(); f.close(); @@ -99,7 +99,8 @@ static int compressString(lua_State* L) static_cast(srcLen * 1.001 + 12 + 1), static_cast(1)) + sizeof(uncompressed_len_t)); - *reinterpret_cast(&buf[0]) = srcLen; + *reinterpret_cast(&buf[0]) = + static_cast(srcLen); uLongf dstLen = buf.size() - sizeof(uncompressed_len_t); throwZErr(compress( reinterpret_cast(&buf[sizeof(uncompressed_len_t)]), &dstLen, diff --git a/src/luaexport/resources.hpp b/src/luaexport/resources.hpp index 85245b8..aaa1f1f 100644 --- a/src/luaexport/resources.hpp +++ b/src/luaexport/resources.hpp @@ -6,7 +6,7 @@ #define RESOURCES_HPP_INCLUDED RESOURCES_HPP_INCLUDED #include "ressys/ResourceManager.hpp" - +#include "sharedPtrConverter.hpp" #include diff --git a/src/luaexport/sharedPtrConverter.hpp b/src/luaexport/sharedPtrConverter.hpp index 8db001c..117c8f5 100644 --- a/src/luaexport/sharedPtrConverter.hpp +++ b/src/luaexport/sharedPtrConverter.hpp @@ -9,6 +9,7 @@ #if BOOST_VERSION >= 105300 #include +#include namespace luabind { namespace detail { namespace has_get_pointer_ { diff --git a/src/ressys/AutoResource.hpp b/src/ressys/AutoResource.hpp index 34205c5..780278b 100644 --- a/src/ressys/AutoResource.hpp +++ b/src/ressys/AutoResource.hpp @@ -23,8 +23,8 @@ class AutoResource: public mediaT typedef typename ResourceTraits::ConstPtr ConstPtr; explicit AutoResource(Ptr resource); - AutoResource(){}; - virtual ~AutoResource(){}; + AutoResource(){} + virtual ~AutoResource(){} ConstPtr resource() const; Ptr resource(); void setResource(Ptr resource); diff --git a/src/ressys/ResourceManager.inl b/src/ressys/ResourceManager.inl index f1a2c9b..dee5dd4 100644 --- a/src/ressys/ResourceManager.inl +++ b/src/ressys/ResourceManager.inl @@ -1,159 +1,159 @@ -// Part of the Jade Engine -- Copyright (c) Christian Neumüller 2012--2013 -// This file is subject to the terms of the BSD 2-Clause License. -// See LICENSE.txt or http://opensource.org/licenses/BSD-2-Clause - -/// \file ResourceManager.inl Implementation file for ResourceManager.hpp - -template -ResourceManager::ResourceManager(): - m_keepAll(false) -{ -} - -template -ResourceManager::~ResourceManager() -{ - if (!m_keepAll) { - for (auto it = m_kept.cbegin(); it != m_kept.cend(); ++it) - LOG_W("Resource \"" + it->first + "\" has not been released!"); - } -} - -template -typename ResourceManager::Ptr ResourceManager::request( - std::string const& name) -{ - if (!m_callback) - return get(name); - - WeakPtr& oldRes = m_resMap[name]; - if (oldRes.expired()) { - LOG_D("Loading resource[" + - std::string(typeid(ResT).name()) + "] \"" + name + "\"..."); - Ptr newRes(std::make_shared()); - try { - m_callback(*newRes, name); - LOG_D("Finished loading resource \"" + name + "\"."); - } catch (std::exception const& ex) { - LOG_EX(ex); - LOG_E("Failed loading resource \"" + name + "\"."); - throw; - } - if (m_keepAll) - m_kept.insert(std::make_pair(name, newRes)); - oldRes = newRes; - return newRes; - } - else - return oldRes.lock(); -} - -template -void ResourceManager::tidy() -{ - for (auto it = m_resMap.begin(); it != m_resMap.end();) { - if (it->second.expired()) - it = m_resMap.erase(it); - else ++it; - } -} - -template -void ResourceManager::purge() -{ - releaseAll(); - tidy(); -} - -template -typename ResourceManager::Ptr ResourceManager::keepLoaded( - std::string const& name) -{ - // insert and return inserted pointer - Ptr result = request(name); - m_kept.insert(std::make_pair(name, result)); - return result; -} - -template -void ResourceManager::keepAllLoaded(bool const enable) -{ - m_keepAll = enable; - if (enable) - m_kept.insert(m_resMap.begin(), m_resMap.end()); -} - - - -template -void ResourceManager::release(std::string const& name) -{ - m_kept.erase(name); -} - -template -void ResourceManager::releaseAll() -{ - m_kept.clear(); -} - -template -typename ResourceManager::Ptr ResourceManager::tryGet( - std::string const& name) -{ - auto const& p = m_resMap[name]; - if (p.expired()) - return nullptr; - else - return p.lock(); -} - - -template -typename ResourceManager::Ptr ResourceManager::get( - std::string const& name) -{ - auto result = tryGet(name); - if (!result) - LOG_THROW(jd::ResourceError("resource \"" + name + "\" is not loaded")); - return result; -} - -template -void ResourceManager::insert( - std::string const& name, Ptr res) -{ - if (!res) - LOG_THROW(jd::ResourceError("attempt to insert null pointer in ResourceManager")); - m_resMap[name] = res; - if (m_keepAll) - m_kept[name] = res; -} - -template -typename ResourceManager::ResourceNotFoundCallback -ResourceManager::setResourceNotFoundCallback( - ResourceNotFoundCallback const& callback) -{ - ResourceNotFoundCallback old(std::move(m_callback)); - m_callback = callback; - return old; -} - -template -void ResourceManager::useDefaultCallback() -{ - setResourceNotFoundCallback(&loadResource); -} - - -//// FREE FUNCTIONS //// -template -void loadResource(ResT& resource, std::string const& name) -{ - if (!resource.loadFromFile(name)) { - throw jd::ResourceLoadError( - "failed loading resource (type: " + std::string(typeid(ResT).name()) + - ") from file \"" + name + "\"."); - } -} +// Part of the Jade Engine -- Copyright (c) Christian Neumüller 2012--2013 +// This file is subject to the terms of the BSD 2-Clause License. +// See LICENSE.txt or http://opensource.org/licenses/BSD-2-Clause + +/// \file ResourceManager.inl Implementation file for ResourceManager.hpp + +template +ResourceManager::ResourceManager(): + m_keepAll(false) +{ +} + +template +ResourceManager::~ResourceManager() +{ + if (!m_keepAll) { + for (auto it = m_kept.cbegin(); it != m_kept.cend(); ++it) + LOG_W("Resource \"" + it->first + "\" has not been released!"); + } +} + +template +typename ResourceManager::Ptr ResourceManager::request( + std::string const& name) +{ + if (!m_callback) + return get(name); + + WeakPtr& oldRes = m_resMap[name]; + if (oldRes.expired()) { + LOG_D("Loading resource[" + + std::string(typeid(ResT).name()) + "] \"" + name + "\"..."); + Ptr newRes(std::make_shared()); + try { + m_callback(*newRes, name); + LOG_D("Finished loading resource \"" + name + "\"."); + } catch (std::exception const& ex) { + LOG_EX(ex); + LOG_E("Failed loading resource \"" + name + "\"."); + throw; + } + if (m_keepAll) + m_kept.insert(std::make_pair(name, newRes)); + oldRes = newRes; + return newRes; + } + else + return oldRes.lock(); +} + +template +void ResourceManager::tidy() +{ + for (auto it = m_resMap.begin(); it != m_resMap.end();) { + if (it->second.expired()) + it = m_resMap.erase(it); + else ++it; + } +} + +template +void ResourceManager::purge() +{ + releaseAll(); + tidy(); +} + +template +typename ResourceManager::Ptr ResourceManager::keepLoaded( + std::string const& name) +{ + // insert and return inserted pointer + Ptr result = request(name); + m_kept.insert(std::make_pair(name, result)); + return result; +} + +template +void ResourceManager::keepAllLoaded(bool const enable) +{ + m_keepAll = enable; + if (enable) + m_kept.insert(m_resMap.begin(), m_resMap.end()); +} + + + +template +void ResourceManager::release(std::string const& name) +{ + m_kept.erase(name); +} + +template +void ResourceManager::releaseAll() +{ + m_kept.clear(); +} + +template +typename ResourceManager::Ptr ResourceManager::tryGet( + std::string const& name) +{ + auto const& p = m_resMap[name]; + if (p.expired()) + return nullptr; + else + return p.lock(); +} + + +template +typename ResourceManager::Ptr ResourceManager::get( + std::string const& name) +{ + auto result = tryGet(name); + if (!result) + LOG_THROW(jd::ResourceError("resource \"" + name + "\" is not loaded")); + return result; +} + +template +void ResourceManager::insert( + std::string const& name, Ptr res) +{ + if (!res) + LOG_THROW(jd::ResourceError("attempt to insert null pointer in ResourceManager")); + m_resMap[name] = res; + if (m_keepAll) + m_kept[name] = res; +} + +template +typename ResourceManager::ResourceNotFoundCallback +ResourceManager::setResourceNotFoundCallback( + ResourceNotFoundCallback const& callback) +{ + ResourceNotFoundCallback old(std::move(m_callback)); + m_callback = callback; + return old; +} + +template +void ResourceManager::useDefaultCallback() +{ + setResourceNotFoundCallback(&loadResource); +} + + +//// FREE FUNCTIONS //// +template +void loadResource(ResT& resource, std::string const& name) +{ + if (!resource.loadFromFile(name)) { + throw jd::ResourceLoadError( + "failed loading resource (type: " + std::string(typeid(ResT).name()) + + ") from file \"" + name + "\"."); + } +} diff --git a/src/ressys/VFileFont.hpp b/src/ressys/VFileFont.hpp index 273ee57..6801a6c 100644 --- a/src/ressys/VFileFont.hpp +++ b/src/ressys/VFileFont.hpp @@ -9,7 +9,7 @@ #include -static void loadFontResource(struct VFileFont&, std::string const&); +inline void loadFontResource(struct VFileFont& fnt, std::string const& name); struct VFileFont: public sf::Font { diff --git a/src/ressys/resourceLoaders.cpp b/src/ressys/resourceLoaders.cpp index e929d83..1221358 100644 --- a/src/ressys/resourceLoaders.cpp +++ b/src/ressys/resourceLoaders.cpp @@ -35,7 +35,11 @@ std::string const findResource( std::string result(path + ".???"); for (std::size_t i = 0; i < nExts; ++i) { - result.replace(result.begin() + path.size(), result.end(), exts[i]); + typedef std::string::difference_type offset_t; + result.replace( + result.begin() + static_cast(path.size()), + result.end(), + exts[i]); if (PHYSFS_exists(result.c_str())) return result; } @@ -66,7 +70,7 @@ static void loadTextureResource(sf::Texture& tx, std::string const& name) } } -static void loadFontResource(VFileFont& fnt, std::string const& name) +inline void loadFontResource(VFileFont& fnt, std::string const& name) { std::string const filename = findResource( name, diff --git a/src/sfKeyCodes.hpp b/src/sfKeyCodes.hpp index d9d7109..80c0620 100644 --- a/src/sfKeyCodes.hpp +++ b/src/sfKeyCodes.hpp @@ -6,51 +6,51 @@ // // #define E(name, value) to something meaningful -#ifndef E -# error You have to provide a definiton for the macro E(name, value) +#ifndef KEY +# error You have to provide a definiton for the macro KEY(name, value) #endif -#define E1(n) E(#n, n) - E1(A) E1(B) E1(C) E1(D) E1(E) E1(F) E1(G) E1(H) E1(I) E1(J) E1(K) - E1(L) E1(M) E1(N) E1(O) E1(P) E1(Q) E1(R) E1(S) E1(T) E1(U) E1(V) - E1(W) E1(X) E1(Y) E1(Z) - E1(F1) E1(F2) E1(F3) E1(F4) E1(F5) E1(F6) E1(F7) E1(F8) E1(F9) E1(F10) - E1(F11) E1(F12) E1(F13) E1(F14) E1(F15) -#undef E1 +#define K1(n) KEY(#n, n) + K1(A) K1(B) K1(C) K1(D) K1(E) K1(F) K1(G) K1(H) K1(I) K1(J) K1(K) + K1(L) K1(M) K1(N) K1(O) K1(P) K1(Q) K1(R) K1(S) K1(T) K1(U) K1(V) + K1(W) K1(X) K1(Y) K1(Z) + K1(F1) K1(F2) K1(F3) K1(F4) K1(F5) K1(F6) K1(F7) K1(F8) K1(F9) K1(F10) + K1(F11) K1(F12) K1(F13) K1(F14) K1(F15) +#undef K1 - E("UNKNOWN", Unknown) - E("NUM0", Num0) - E("NUM1", Num1) E("NUM2", Num2) E("NUM3", Num3) - E("NUM4", Num4) E("NUM5", Num5) E("NUM6", Num6) - E("NUM7", Num7) E("NUM8", Num8) E("NUM9", Num9) - E("ESCAPE", Escape) - E("LCONTROL", LControl) E("LSHIFT", LShift) - E("LALT", LAlt) E("LSYSTEM", LSystem) - E("RCONTROL", RControl) E("RSHIFT", RShift) - E("RALT", RAlt) E("RSYSTEM", RSystem) - E("MENU", Menu) - E("LBRACKET", LBracket) - E("RBRACKET", RBracket) - E("SEMICOLON", SemiColon) E("COMMA", Comma) E("PERIOD", Period) - E("QUOTE", Quote) - E("SLASH", Slash) E("BACKSLASH", BackSlash) - E("TILDE", Tilde) - E("EQUAL", Equal) - E("DASH", Dash) - E("SPACE", Space) - E("RETURN", Return) - E("BACKSPACE", BackSpace) - E("TAB", Tab) - E("PAGEUP", PageUp) E("PAGEDOWN", PageDown) - E("END", End) E("HOME", Home) - E("INSERT", Insert) E("DELETE", Delete) - E("ADD", Add) E("SUBTRACT", Subtract) - E("MULTIPLY", Multiply) E("DIVIDE", Divide) - E("LEFT", Left) E("RIGHT", Right) E("UP", Up) E("DOWN", Down) - E("NUMPAD0", Numpad0) - E("NUMPAD1", Numpad1) E("NUMPAD2", Numpad2) E("NUMPAD3", Numpad3) - E("NUMPAD4", Numpad4) E("NUMPAD5", Numpad5) E("NUMPAD6", Numpad6) - E("NUMPAD7", Numpad7) E("NUMPAD8", Numpad8) E("NUMPAD9", Numpad9) - E("PAUSE", Pause) + KEY("UNKEYNOWN", Unknown) + KEY("NUM0", Num0) + KEY("NUM1", Num1) KEY("NUM2", Num2) KEY("NUM3", Num3) + KEY("NUM4", Num4) KEY("NUM5", Num5) KEY("NUM6", Num6) + KEY("NUM7", Num7) KEY("NUM8", Num8) KEY("NUM9", Num9) + KEY("ESCAPE", Escape) + KEY("LCONTROL", LControl) KEY("LSHIFT", LShift) + KEY("LALT", LAlt) KEY("LSYSTEM", LSystem) + KEY("RCONTROL", RControl) KEY("RSHIFT", RShift) + KEY("RALT", RAlt) KEY("RSYSTEM", RSystem) + KEY("MENU", Menu) + KEY("LBRACKEYET", LBracket) + KEY("RBRACKEYET", RBracket) + KEY("SEMICOLON", SemiColon) KEY("COMMA", Comma) KEY("PERIOD", Period) + KEY("QUOTE", Quote) + KEY("SLASH", Slash) KEY("BACKEYSLASH", BackSlash) + KEY("TILDE", Tilde) + KEY("EQUAL", Equal) + KEY("DASH", Dash) + KEY("SPACE", Space) + KEY("RETURN", Return) + KEY("BACKEYSPACE", BackSpace) + KEY("TAB", Tab) + KEY("PAGEUP", PageUp) KEY("PAGEDOWN", PageDown) + KEY("END", End) KEY("HOME", Home) + KEY("INSERT", Insert) KEY("DELETE", Delete) + KEY("ADD", Add) KEY("SUBTRACT", Subtract) + KEY("MULTIPLY", Multiply) KEY("DIVIDE", Divide) + KEY("LEFT", Left) KEY("RIGHT", Right) KEY("UP", Up) KEY("DOWN", Down) + KEY("NUMPAD0", Numpad0) + KEY("NUMPAD1", Numpad1) KEY("NUMPAD2", Numpad2) KEY("NUMPAD3", Numpad3) + KEY("NUMPAD4", Numpad4) KEY("NUMPAD5", Numpad5) KEY("NUMPAD6", Numpad6) + KEY("NUMPAD7", Numpad7) KEY("NUMPAD8", Numpad8) KEY("NUMPAD9", Numpad9) + KEY("PAUSE", Pause) -#undef E +#undef KEY diff --git a/src/sfUtil.cpp b/src/sfUtil.cpp index 26a27c0..59fd712 100644 --- a/src/sfUtil.cpp +++ b/src/sfUtil.cpp @@ -17,7 +17,7 @@ namespace jd { std::string const keyName(int keyCode) { switch(keyCode) { -# define E(n, v) case sf::Keyboard::v: return n; +# define KEY(n, v) case sf::Keyboard::v: return n; # include "sfKeyCodes.hpp" } return "key #" + boost::lexical_cast(keyCode); @@ -45,7 +45,7 @@ void breakTextLines(sf::Text& t, float maxX) { sf::String s = t.getString(); std::size_t lastBreakCharIdx = s.getSize(); - static sf::String const breakBeforeChars("([{\"'`´"); + static sf::String const breakBeforeChars("([{\"'`'"); static auto const isBreakBeforeChar = [] (sf::Uint32 c) { return breakBeforeChars.find(c) != sf::String::InvalidPos; }; diff --git a/src/sfUtil.hpp b/src/sfUtil.hpp index 4118e08..fc3871b 100644 --- a/src/sfUtil.hpp +++ b/src/sfUtil.hpp @@ -11,6 +11,7 @@ #include // std::hash #include +#include namespace sf { class Text; class String; class View; } diff --git a/src/svc/Configuration.cpp b/src/svc/Configuration.cpp index bae6c3e..37cf772 100644 --- a/src/svc/Configuration.cpp +++ b/src/svc/Configuration.cpp @@ -60,7 +60,7 @@ void Configuration::save() std::string s = "return "; s += luaU::serialize(L, -1); VFile f(m_confPath, VFile::openW); - f.write(s.data(), s.size()); + f.write(s.data(), static_cast(s.size())); f.close(); // Close manually to avoid swallowing errors. } @@ -81,15 +81,17 @@ luabind::object Configuration::getObject(std::string const& p) throw Error(p, "Configuration has not been loaded yet."); std::vector> pelems; - boost::split(pelems, p, [](char c) {return c == '.'; }); + bool (*splitter)(char) = [](char c) {return c == '.'; }; + boost::split(pelems, p, splitter); lua_State* L = m_conf.interpreter(); - if (!lua_checkstack(L, pelems.size() + 2)) + if (!lua_checkstack(L, static_cast(pelems.size() + 2))) throw Error(p, "Cannot reserve lua stack size. Path to long?"); lua_pushcfunction(L, &getTable); m_conf.push(L); for (auto const& elem: boost::adaptors::reverse(pelems)) - lua_pushlstring(L, &*elem.begin(), elem.size()); - try { luaU::pcall(L, pelems.size() + 1, 1); } + lua_pushlstring(L, &*elem.begin(), + static_cast(elem.size())); + try { luaU::pcall(L, static_cast(pelems.size() + 1), 1); } catch (luaU::Error const& e) { throw Error(p, e.what()); } diff --git a/src/svc/EventDispatcher.cpp b/src/svc/EventDispatcher.cpp index 109d68f..fd2a3ec 100644 --- a/src/svc/EventDispatcher.cpp +++ b/src/svc/EventDispatcher.cpp @@ -35,9 +35,8 @@ void EventDispatcher::dispatch() void EventDispatcher::dispatchEvent(sf::Event& ev) { m_sig_sfEvent(ev); + using sf::Event; switch (ev.type) { - using sf::Event; - // Misc case Event::Closed: m_sig_closed(); break; case Event::Resized: m_sig_resized(ev.size); break; @@ -66,6 +65,7 @@ void EventDispatcher::dispatchEvent(sf::Event& ev) case Event::JoystickMoved: break; + case sf::Event::Count: default: LOG_W("unknown sf::Event::type: " + boost::lexical_cast(ev.type)); break; diff --git a/src/svc/FileSystem.cpp b/src/svc/FileSystem.cpp index ebdde20..78e5a61 100644 --- a/src/svc/FileSystem.cpp +++ b/src/svc/FileSystem.cpp @@ -108,7 +108,8 @@ sf::Int64 VFile::write(void const* data, sf::Int64 size) sf::Int64 VFile::seek(sf::Int64 position) { - if (!m_f || !check(PHYSFS_seek(m_f, position), 1, "seek")) + auto ipos = static_cast(position); + if (!m_f || !check(PHYSFS_seek(m_f, ipos), 1, "seek")) return -1; return tell(); } @@ -272,7 +273,7 @@ bool FileSystem::mountFirstWorking( std::string const& mountPoint, int flags) { - int const mflags = flags & ~logWarnings | mountOptional; + int const mflags = (flags & ~logWarnings) | mountOptional; std::string message = "Failed mounting all of the following:"; for (auto const& path: paths) { if (mount(path, mountPoint, mflags)) diff --git a/src/svc/LuaVm.cpp b/src/svc/LuaVm.cpp index 1d4acbd..7729ece 100644 --- a/src/svc/LuaVm.cpp +++ b/src/svc/LuaVm.cpp @@ -26,7 +26,7 @@ static int pcallf(lua_State* L) static lua_CFunction oldpanicf = nullptr; -int panicf(lua_State* L) +static int panicf(lua_State* L) { pcallf(L); LOG_F(luaU::Error(L, "Lua panic").what()); diff --git a/src/svc/Timer.cpp b/src/svc/Timer.cpp index d3e0c52..b0e8787 100644 --- a/src/svc/Timer.cpp +++ b/src/svc/Timer.cpp @@ -83,7 +83,7 @@ void Timer::endFrame() } -float const Timer::factor() const +float Timer::factor() const { return m_factor; } diff --git a/src/svc/Timer.hpp b/src/svc/Timer.hpp index 41a6da4..9f95428 100644 --- a/src/svc/Timer.hpp +++ b/src/svc/Timer.hpp @@ -54,7 +54,7 @@ class Timer: public Component { void processCallbacks(); void endFrame(); - float const factor() const; + float factor() const; void setFactor(float factor); private: