mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 10:22:52 +01:00
7a86c199b0
This reduces compile time from 1m19s to 9s when touching GameConfig.hpp. (Executed from rwgame/build/tests) before: $ make >/dev/null $ touch ../../rwgame/GameConfig.hpp $ time make>/dev/null real 1m18.643s user 1m13.069s sys 0m5.266s after: $ make >/dev/null $ touch ../../rwgame/GameConfig.hpp $ time make>/dev/null real 0m9.247s user 0m8.374s sys 0m0.836s
117 lines
2.2 KiB
C++
117 lines
2.2 KiB
C++
#ifndef _TESTGLOBABLS_HPP_
|
|
#define _TESTGLOBABLS_HPP_
|
|
|
|
#include <SDL2/SDL.h>
|
|
#include <GameWindow.hpp>
|
|
#include <boost/test/unit_test.hpp>
|
|
#include <core/Logger.hpp>
|
|
#include <engine/GameData.hpp>
|
|
#include <engine/GameState.hpp>
|
|
#include <engine/GameWorld.hpp>
|
|
#include <glm/gtx/string_cast.hpp>
|
|
|
|
std::ostream& operator<<(std::ostream& stream, glm::vec3 const& v);
|
|
|
|
// Boost moved the print_log_value struct in version 1.59
|
|
// TODO: use another testing library
|
|
#if BOOST_VERSION >= 105900
|
|
#define BOOST_NS_MAGIC namespace tt_detail {
|
|
#define BOOST_NS_MAGIC_CLOSING }
|
|
#else
|
|
#define BOOST_NS_MAGIC
|
|
#define BOOST_NS_MAGIC_CLOSING
|
|
#endif
|
|
|
|
namespace boost {
|
|
namespace test_tools {
|
|
BOOST_NS_MAGIC
|
|
template <>
|
|
struct print_log_value<glm::vec3> {
|
|
void operator()(std::ostream& s, glm::vec3 const& v) {
|
|
s << glm::to_string(v);
|
|
}
|
|
};
|
|
}
|
|
}
|
|
BOOST_NS_MAGIC_CLOSING
|
|
|
|
namespace boost {
|
|
namespace test_tools {
|
|
BOOST_NS_MAGIC
|
|
template <>
|
|
struct print_log_value<std::nullptr_t> {
|
|
void operator()(std::ostream& s, std::nullptr_t) {
|
|
s << "nullptr";
|
|
}
|
|
};
|
|
}
|
|
}
|
|
BOOST_NS_MAGIC_CLOSING
|
|
|
|
namespace boost {
|
|
namespace test_tools {
|
|
BOOST_NS_MAGIC
|
|
template <>
|
|
struct print_log_value<GameString> {
|
|
void operator()(std::ostream& s, GameString const& v) {
|
|
for (GameString::size_type i = 0u; i < v.size(); ++i) {
|
|
s << (char)v[i];
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|
|
BOOST_NS_MAGIC_CLOSING
|
|
|
|
#undef BOOST_NS_MAGIC
|
|
#undef BOOST_NS_MAGIC_CLOSING
|
|
|
|
class Global {
|
|
public:
|
|
GameWindow window;
|
|
#if RW_TEST_WITH_DATA
|
|
GameData* d;
|
|
GameWorld* e;
|
|
GameState* s;
|
|
Logger log;
|
|
#endif
|
|
|
|
Global() {
|
|
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
|
throw std::runtime_error("Failed to initialize SDL2!");
|
|
|
|
window.create("Tests", 800, 600, false);
|
|
window.hideCursor();
|
|
|
|
#if RW_TEST_WITH_DATA
|
|
d = new GameData(&log, getGamePath());
|
|
|
|
d->load();
|
|
|
|
e = new GameWorld(&log, d);
|
|
s = new GameState;
|
|
e->state = s;
|
|
|
|
e->dynamicsWorld->setGravity(btVector3(0.f, 0.f, 0.f));
|
|
#endif
|
|
}
|
|
|
|
~Global() {
|
|
window.close();
|
|
#if RW_TEST_WITH_DATA
|
|
delete e;
|
|
#endif
|
|
}
|
|
|
|
#if RW_TEST_WITH_DATA
|
|
static std::string getGamePath();
|
|
#endif
|
|
|
|
static Global& get() {
|
|
static Global g;
|
|
return g;
|
|
}
|
|
};
|
|
|
|
#endif
|