1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-18 16:32:32 +02:00
openrw/tests/test_globals.hpp

113 lines
2.2 KiB
C++
Raw Normal View History

2013-12-12 11:58:14 +01:00
#ifndef _TESTGLOBABLS_HPP_
#define _TESTGLOBABLS_HPP_
#include <SFML/Window.hpp>
2013-12-20 17:02:46 +01:00
#include <engine/GameWorld.hpp>
2015-04-18 02:11:17 +02:00
#include <engine/GameData.hpp>
#include <engine/GameState.hpp>
2015-03-30 03:45:58 +02:00
#include <core/Logger.hpp>
#include <glm/gtx/string_cast.hpp>
2013-12-12 11:58:14 +01:00
#if RW_TEST_WITH_DATA
2014-05-25 23:30:50 +02:00
#define ENV_GAME_PATH_NAME ("OPENRW_GAME_PATH")
#endif
2013-12-12 11:58:14 +01:00
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
2014-05-29 12:12:40 +02:00
template<>
struct print_log_value<std::nullptr_t> {
void operator()( std::ostream& s , std::nullptr_t )
2014-05-29 12:12:40 +02:00
{
s << "nullptr";
}
};
}} BOOST_NS_MAGIC_CLOSING
#undef BOOST_NS_MAGIC
#undef BOOST_NS_MAGIC_CLOSING
2014-05-29 12:12:40 +02:00
2013-12-12 11:58:14 +01:00
class Global
{
public:
sf::Window wnd;
#if RW_TEST_WITH_DATA
2015-04-18 02:11:17 +02:00
GameData* d;
2013-12-20 17:02:46 +01:00
GameWorld* e;
GameState* s;
2015-04-18 02:11:17 +02:00
Logger log;
WorkContext work;
#endif
2013-12-12 11:58:14 +01:00
Global() {
wnd.create(sf::VideoMode(640, 360), "Testing");
#if RW_TEST_WITH_DATA
d = new GameData(&log, &work, getGamePath());
d->loadIMG("/models/gta3");
d->loadIMG("/anim/cuts");
d->load();
e = new GameWorld(&log, &work, d);
s = new GameState;
e->state = s;
2015-04-18 02:11:17 +02:00
for(std::map<std::string, std::string>::iterator it = e->data->ideLocations.begin();
it != e->data->ideLocations.end();
++it) {
d->loadObjects(it->second);
}
e->dynamicsWorld->setGravity(btVector3(0.f, 0.f, 0.f));
2014-06-06 13:18:32 +02:00
while( ! e->_work->isEmpty() ) {
std::this_thread::yield();
}
#endif
2013-12-12 11:58:14 +01:00
}
~Global() {
wnd.close();
#if RW_TEST_WITH_DATA
delete e;
#endif
2013-12-12 11:58:14 +01:00
}
2014-05-25 23:30:50 +02:00
#if RW_TEST_WITH_DATA
2014-05-25 23:30:50 +02:00
static std::string getGamePath()
{
// TODO: Is this "the way to do it" on windows.
auto v = getenv(ENV_GAME_PATH_NAME);
return v ? v : "";
}
#endif
2013-12-12 11:58:14 +01:00
static Global& get()
{
static Global g;
return g;
}
};
#endif