Skip to content

Commit

Permalink
Fix clang build.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oberon00 committed Jul 23, 2013
1 parent c19fbc4 commit 0e702c5
Show file tree
Hide file tree
Showing 38 changed files with 515 additions and 451 deletions.
14 changes: 13 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
11 changes: 8 additions & 3 deletions src/Logfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<int>(level_);
auto level = static_cast<unsigned>(level_);

static auto const maxloglevel = static_cast<int>(loglevel::max);
static_assert(maxloglevel == 5, "Please correct levelnames below!");
Expand Down
5 changes: 3 additions & 2 deletions src/MapInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ MapInfo loadTilemap(jd::Tilemap& tm, std::string const& vfilename)
tm.setSize(jd::Vector3u(
map.get<unsigned>("<xmlattr>.width"),
map.get<unsigned>("<xmlattr>.height"),
rng::count_if(map, [](pt::ptree::value_type const& e) {
return e.first == "layer"; })));
static_cast<unsigned>(
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");

Expand Down
58 changes: 29 additions & 29 deletions src/Resources.rc
Original file line number Diff line number Diff line change
@@ -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
56 changes: 34 additions & 22 deletions src/Tilemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned>(m_columnCount),
static_cast<unsigned>(m_rowCount),
static_cast<unsigned>(m_map.size() / (m_columnCount * m_rowCount)));
}


Expand Down Expand Up @@ -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<float>(pos.x * m_tileset.size().x),
static_cast<float>(pos.y * m_tileset.size().y));
static_cast<float>(pos.x * static_cast<int>(m_tileset.size().x)),
static_cast<float>(pos.y * static_cast<int>(m_tileset.size().y)));
}

sf::Vector2f Tilemap::globalTilePos(sf::Vector2i pos) const
Expand Down Expand Up @@ -214,42 +214,50 @@ 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<int>(size.x));
lastTPos.y = std::min(lastTPos.y + 1, static_cast<int>(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<int>(size.x));
lastTPosI.y = std::min(lastTPosI.y + 1, static_cast<int>(size.y));
sf::Vector2i distanceI = lastTPosI - firstTPosI;
if (distanceI.x <= 0 || distanceI.y <= 0)
return;

auto distance = vec_cast<unsigned>(distanceI);

auto firstTPos = vec_cast<unsigned>(firstTPosI);
auto lastTPos = vec_cast<unsigned>(lastTPosI);

std::size_t const renderedTileCount = distance.x * distance.y * size.z;
static std::size_t const verticesPerTile = 4;
std::vector<sf::Vertex> 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<float>(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<unsigned>(firstTPos.x),
static_cast<unsigned>(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<std::size_t>(lastTPos.y); ++y){
for (std::size_t x = firstTPos.x; x < static_cast<std::size_t>(lastTPos.x); ++x) {
for (unsigned z = 0; z < size.z; ++z) {
for (unsigned y = firstTPos.y; y < static_cast<std::size_t>(lastTPos.y); ++y){
for (unsigned x = firstTPos.x; x < static_cast<std::size_t>(lastTPos.x); ++x) {
assert(index(Vector3u(x, y, z)) == iMap);
unsigned const tileId = m_map[iMap++];
if (tileId == 0) {
vertices.pop_back();
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<unsigned>(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);
Expand All @@ -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<unsigned>(vertices.size()),
sf::Quads,
states);
} // Tilemap::draw()

bool Tilemap::isValidPosition(sf::Vector3i pos) const
Expand Down
4 changes: 0 additions & 4 deletions src/WeakRef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ class EnableWeakRefFromThis {
m_connection(nullptr)
{ }

EnableWeakRefFromThis(EnableWeakRefFromThis const& rhs):
m_connection(nullptr) // reset connection
{ }

WeakRef<T> ref()
{
ensureConnection();
Expand Down
6 changes: 3 additions & 3 deletions src/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ std::vector<byte> decode(byte const* encoded, std::size_t byteCount)
charToByte);

std::array<byte, 3> 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<byte>(inBytes[0] << 2 | inBytes[1] >> 4);
outBytes[1] = static_cast<byte>(inBytes[1] << 4 | inBytes[2] >> 2);
outBytes[2] = static_cast<byte>(inBytes[2] << 6 | inBytes[3]);

if (i + 4 == byteCount) {
std::size_t discard = 0;
Expand Down
12 changes: 12 additions & 0 deletions src/clang_stdlib_config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <boost/config/stdlib/libstdcpp3.hpp>

// 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
2 changes: 1 addition & 1 deletion src/collision/Collisions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CollideableGroup: public EnableWeakRefFromThis<CollideableGroup> {
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;

Expand Down
34 changes: 19 additions & 15 deletions src/collision/TileCollideableGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(pos.x), static_cast<int>(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);
Expand All @@ -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();
Expand Down Expand Up @@ -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<sf::Vector2u>(
m_tilemap.tilePosFromGlobal(jd::topLeft(r)));
begin.x = std::max(begin.x, 0u);
begin.y = std::max(begin.y, 0u);
last = static_cast<sf::Vector2u>(
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<int>(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<unsigned>(begin);
last_out = jd::vec_cast<unsigned>(last);

return intersectingPerLayer * m_tilemap.size().z;
return static_cast<unsigned>(intersectingPerLayer) * m_tilemap.size().z;
}


Expand All @@ -256,8 +259,9 @@ std::vector<Collision> 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<std::ptrdiff_t>(i);
collisions.erase(collisions.begin() + off);
positions.erase(positions.begin() + off);
} else {
++i;
}
Expand Down
6 changes: 3 additions & 3 deletions src/collision/TileCollideableGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ class TileCollideableInfo: public EnableWeakRefFromThis<TileCollideableInfo> {
WeakRef<TileCollisionComponent> colliding(Vector3u pos);

// notify if e != nullptr
virtual std::vector<Collision> colliding(
std::vector<Collision> colliding(
sf::FloatRect const&,
Entity* e = nullptr,
std::vector<Vector3u>* positions = nullptr);

virtual std::vector<Collision> colliding(
std::vector<Collision> colliding(
sf::Vector2f lineStart,
sf::Vector2f lineEnd,
std::vector<Vector3u>* positions = nullptr);

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,
Expand Down
4 changes: 4 additions & 0 deletions src/compsys/Component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <boost/noncopyable.hpp>

#include <cassert>
#include <iosfwd>


class MetaComponent;
Expand Down Expand Up @@ -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
Loading

0 comments on commit 0e702c5

Please sign in to comment.