2013-12-12 11:58:14 +01:00
|
|
|
#ifndef _TESTGLOBABLS_HPP_
|
|
|
|
#define _TESTGLOBABLS_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>
|
2016-04-15 02:06:10 +02:00
|
|
|
#include <engine/GameState.hpp>
|
2015-03-30 03:45:58 +02:00
|
|
|
#include <core/Logger.hpp>
|
2014-05-29 10:10:08 +02:00
|
|
|
#include <glm/gtx/string_cast.hpp>
|
2016-06-22 12:29:39 +02:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include <GameWindow.hpp>
|
|
|
|
#include <GameConfig.hpp>
|
2013-12-12 11:58:14 +01:00
|
|
|
|
2014-05-29 10:10:08 +02:00
|
|
|
std::ostream& operator<<( std::ostream& stream, glm::vec3 const& v );
|
|
|
|
|
2016-05-19 22:09:08 +02:00
|
|
|
// 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
|
2014-05-29 10:10:08 +02:00
|
|
|
template<>
|
|
|
|
struct print_log_value<glm::vec3> {
|
|
|
|
void operator()( std::ostream& s , glm::vec3 const& v )
|
|
|
|
{
|
|
|
|
s << glm::to_string(v);
|
|
|
|
}
|
|
|
|
};
|
2016-05-19 22:09:08 +02:00
|
|
|
}} BOOST_NS_MAGIC_CLOSING
|
2014-05-29 10:10:08 +02:00
|
|
|
|
2016-05-19 22:09:08 +02:00
|
|
|
namespace boost { namespace test_tools { BOOST_NS_MAGIC
|
2014-05-29 12:12:40 +02:00
|
|
|
template<>
|
2014-08-11 18:58:43 +02:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
};
|
2016-05-19 22:09:08 +02:00
|
|
|
}} BOOST_NS_MAGIC_CLOSING
|
|
|
|
|
2016-08-16 01:53:27 +02:00
|
|
|
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
|
|
|
|
|
2016-05-19 22:09:08 +02:00
|
|
|
#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:
|
2016-06-22 12:29:39 +02:00
|
|
|
GameWindow window;
|
2016-06-16 22:11:55 +02:00
|
|
|
#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;
|
2016-04-15 02:06:10 +02:00
|
|
|
GameState* s;
|
2015-04-18 02:11:17 +02:00
|
|
|
Logger log;
|
2015-04-27 04:55:18 +02:00
|
|
|
WorkContext work;
|
2016-06-16 22:11:55 +02:00
|
|
|
#endif
|
|
|
|
|
2013-12-12 11:58:14 +01:00
|
|
|
Global() {
|
2016-06-22 12:29:39 +02:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
|
|
|
throw std::runtime_error("Failed to initialize SDL2!");
|
|
|
|
|
2016-07-03 00:00:11 +02:00
|
|
|
window.create("Tests", 800, 600, false);
|
2016-06-22 12:29:39 +02:00
|
|
|
window.hideCursor();
|
|
|
|
|
2016-06-16 22:11:55 +02:00
|
|
|
#if RW_TEST_WITH_DATA
|
2015-04-27 04:55:18 +02:00
|
|
|
d = new GameData(&log, &work, getGamePath());
|
2016-05-02 18:38:04 +02:00
|
|
|
|
|
|
|
d->loadIMG("/models/gta3");
|
|
|
|
d->loadIMG("/anim/cuts");
|
|
|
|
d->load();
|
|
|
|
|
2015-04-27 04:55:18 +02:00
|
|
|
e = new GameWorld(&log, &work, d);
|
2016-04-15 02:06:10 +02:00
|
|
|
s = new GameState;
|
|
|
|
e->state = s;
|
2014-02-28 12:23:51 +01:00
|
|
|
|
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();
|
2014-02-28 12:23:51 +01:00
|
|
|
++it) {
|
2015-04-24 19:09:21 +02:00
|
|
|
d->loadObjects(it->second);
|
2014-02-28 12:23:51 +01:00
|
|
|
}
|
2014-05-29 10:10:08 +02:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2016-06-16 22:11:55 +02:00
|
|
|
#endif
|
2013-12-12 11:58:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~Global() {
|
2016-06-22 12:29:39 +02:00
|
|
|
window.close();
|
2016-06-16 22:11:55 +02:00
|
|
|
#if RW_TEST_WITH_DATA
|
2014-02-28 12:23:51 +01:00
|
|
|
delete e;
|
2016-06-16 22:11:55 +02:00
|
|
|
#endif
|
2013-12-12 11:58:14 +01:00
|
|
|
}
|
2014-05-25 23:30:50 +02:00
|
|
|
|
2016-06-16 22:11:55 +02:00
|
|
|
#if RW_TEST_WITH_DATA
|
2014-05-25 23:30:50 +02:00
|
|
|
static std::string getGamePath()
|
|
|
|
{
|
2016-06-22 12:29:39 +02:00
|
|
|
return GameConfig("openrw.ini").getGameDataPath();
|
2014-05-25 23:30:50 +02:00
|
|
|
}
|
2016-06-16 22:11:55 +02:00
|
|
|
#endif
|
2016-06-22 12:29:39 +02:00
|
|
|
|
2013-12-12 11:58:14 +01:00
|
|
|
static Global& get()
|
|
|
|
{
|
|
|
|
static Global g;
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-22 12:29:39 +02:00
|
|
|
#endif
|