2016-12-14 17:05:34 +01:00
|
|
|
/** @file
|
|
|
|
|
*
|
|
|
|
|
* @par History
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "testenv.h"
|
|
|
|
|
|
2016-12-18 12:48:35 +01:00
|
|
|
#include "pol_global_config.h"
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_BENCHMARK
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../module/uomod.h"
|
|
|
|
|
#include "../scrsched.h"
|
|
|
|
|
#include "../uoexec.h"
|
|
|
|
|
#include "../uoscrobj.h"
|
2016-12-18 12:48:35 +01:00
|
|
|
#include <benchmark/benchmark.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-12-14 17:05:34 +01:00
|
|
|
#include "../../clib/logfacility.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
#include "../../clib/rawtypes.h"
|
2016-12-14 17:05:34 +01:00
|
|
|
#include "../globals/uvars.h"
|
|
|
|
|
#include "../item/item.h"
|
|
|
|
|
#include "../los.h"
|
|
|
|
|
#include "../mobile/npc.h"
|
|
|
|
|
#include "../realms/realm.h"
|
|
|
|
|
#include "../uobject.h"
|
2018-01-29 21:55:48 +01:00
|
|
|
|
2016-12-14 17:05:34 +01:00
|
|
|
namespace Pol
|
|
|
|
|
{
|
|
|
|
|
namespace Testing
|
|
|
|
|
{
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
void test_los( Core::UObject* src, Core::UObject* target, bool should_have_los )
|
|
|
|
|
{
|
2016-12-18 12:48:35 +01:00
|
|
|
#ifndef ENABLE_BENCHMARK
|
2016-12-14 17:05:34 +01:00
|
|
|
INFO_PRINT << "LOS test: " << src->name() << " to " << target->name() << "(" << should_have_los
|
|
|
|
|
<< "):";
|
2016-12-18 12:48:35 +01:00
|
|
|
#endif
|
|
|
|
|
|
2016-12-14 17:05:34 +01:00
|
|
|
bool res = Core::gamestate.main_realm->has_los( *src, *target );
|
2016-12-18 12:48:35 +01:00
|
|
|
#ifdef ENABLE_BENCHMARK
|
|
|
|
|
return;
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-12-14 17:05:34 +01:00
|
|
|
INFO_PRINT << res << " ";
|
|
|
|
|
if ( should_have_los == res )
|
|
|
|
|
{
|
|
|
|
|
INFO_PRINT << "Ok!\n";
|
|
|
|
|
inc_successes();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
INFO_PRINT << "Failure!\n";
|
|
|
|
|
inc_failures();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void test_los( u16 x1, u16 y1, s8 z1, u16 x2, u16 y2, s8 z2, bool should_have_los )
|
|
|
|
|
{
|
2016-12-18 12:48:35 +01:00
|
|
|
#ifndef ENABLE_BENCHMARK
|
2016-12-14 17:05:34 +01:00
|
|
|
INFO_PRINT << "LOS test: (" << x1 << "," << y1 << "," << int( z1 ) << ")"
|
|
|
|
|
<< " - (" << x2 << "," << y2 << "," << int( z2 ) << ")"
|
|
|
|
|
<< " (" << should_have_los << "):";
|
2016-12-18 12:48:35 +01:00
|
|
|
#endif
|
2016-12-14 17:05:34 +01:00
|
|
|
auto main_realm = Core::gamestate.main_realm;
|
|
|
|
|
bool res = main_realm->has_los( Core::LosObj( x1, y1, z1, main_realm ),
|
2016-12-18 12:48:35 +01:00
|
|
|
Core::LosObj( x2, y2, z2, main_realm ) );
|
|
|
|
|
#ifdef ENABLE_BENCHMARK
|
|
|
|
|
return;
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-12-14 17:05:34 +01:00
|
|
|
INFO_PRINT << res << " ";
|
|
|
|
|
if ( should_have_los == res )
|
|
|
|
|
{
|
|
|
|
|
INFO_PRINT << "Ok!\n";
|
|
|
|
|
inc_successes();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
INFO_PRINT << "Failure!\n";
|
|
|
|
|
inc_failures();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-18 12:48:35 +01:00
|
|
|
void test_los( u16 x1, u16 y1, s8 z1, u8 h1, u16 x2, u16 y2, s8 z2, u8 h2, bool should_have_los )
|
2016-12-14 17:05:34 +01:00
|
|
|
{
|
2016-12-18 12:48:35 +01:00
|
|
|
#ifndef ENABLE_BENCHMARK
|
2016-12-14 17:05:34 +01:00
|
|
|
INFO_PRINT << "LOS test: (" << x1 << "," << y1 << "," << int( z1 ) << ",ht=" << int( h1 ) << ")"
|
|
|
|
|
<< " - (" << x2 << "," << y2 << "," << int( z2 ) << ",ht=" << int( h2 ) << ")"
|
|
|
|
|
<< " (" << should_have_los << "):";
|
2016-12-18 12:48:35 +01:00
|
|
|
#endif
|
2016-12-14 17:05:34 +01:00
|
|
|
auto main_realm = Core::gamestate.main_realm;
|
|
|
|
|
bool res = main_realm->has_los( Core::LosObj( x1, y1, z1, main_realm ),
|
2016-12-18 12:48:35 +01:00
|
|
|
Core::LosObj( x2, y2, z2, main_realm ) );
|
|
|
|
|
#ifdef ENABLE_BENCHMARK
|
|
|
|
|
return;
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-12-14 17:05:34 +01:00
|
|
|
INFO_PRINT << res << " ";
|
|
|
|
|
if ( should_have_los == res )
|
|
|
|
|
{
|
|
|
|
|
INFO_PRINT << "Ok!\n";
|
|
|
|
|
inc_successes();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
INFO_PRINT << "Failure!\n";
|
|
|
|
|
inc_failures();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-18 12:48:35 +01:00
|
|
|
} // namespace
|
2016-12-14 17:05:34 +01:00
|
|
|
|
|
|
|
|
void los_test()
|
|
|
|
|
{
|
2016-12-18 12:48:35 +01:00
|
|
|
#ifndef ENABLE_BENCHMARK
|
2016-12-14 17:05:34 +01:00
|
|
|
INFO_PRINT << "POL datafile LOS tests:\n";
|
2016-12-18 12:48:35 +01:00
|
|
|
#endif
|
2016-12-14 17:05:34 +01:00
|
|
|
test_los( 5421, 78, 10, 5422, 89, 20, false );
|
|
|
|
|
test_los( 1403, 1624, 28, 1402, 1625, 28, true );
|
|
|
|
|
|
|
|
|
|
test_los( 1374, 1625, 59, 1379, 1625, 30, true );
|
|
|
|
|
test_los( 1373, 1625, 59, 1379, 1625, 30, true );
|
|
|
|
|
test_los( 1372, 1625, 59, 1379, 1625, 30, false );
|
|
|
|
|
test_los( 1372, 1625, 59, 1381, 1625, 30, true );
|
|
|
|
|
|
|
|
|
|
// from you standing in the house in GA to a backpack outside
|
|
|
|
|
test_los( 5987, 1999, 7 + 9, 5991, 2001, 1, false );
|
|
|
|
|
test_los( 5987, 1999, 7 + 9, 5993, 1997, 1, false );
|
|
|
|
|
|
|
|
|
|
// test looking through "black space" in a cave
|
|
|
|
|
test_los( 5583, 226, 0, 5590, 223, 0, false );
|
|
|
|
|
|
|
|
|
|
test_los( test_banker2, test_chest1, true );
|
|
|
|
|
test_los( test_banker2, test_chest2, true );
|
|
|
|
|
|
|
|
|
|
// standing aboveground in buc's den, and below
|
|
|
|
|
|
|
|
|
|
test_los( test_orclord, test_banker3, false );
|
|
|
|
|
|
|
|
|
|
test_los( 579, 2106, 0, 1, 563, 2107, 0, 1, false );
|
|
|
|
|
test_los( 862, 1691, 0, 1, 843, 1689, 0, 1, true );
|
|
|
|
|
test_los( 1618, 3351, 3, 1, 1618, 3340, 4, 1, true );
|
|
|
|
|
}
|
2016-12-18 12:48:35 +01:00
|
|
|
|
|
|
|
|
#ifdef ENABLE_BENCHMARK
|
|
|
|
|
|
|
|
|
|
static void BM_los( benchmark::State& state )
|
|
|
|
|
{
|
|
|
|
|
while ( state.KeepRunning() )
|
|
|
|
|
{
|
|
|
|
|
los_test();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-29 21:55:48 +01:00
|
|
|
// BENCHMARK( BM_los );
|
2016-12-18 12:48:35 +01:00
|
|
|
|
2016-12-18 17:03:27 +01:00
|
|
|
static void BM_los100inside100outside( benchmark::State& state )
|
|
|
|
|
{
|
|
|
|
|
while ( state.KeepRunning() )
|
|
|
|
|
{
|
|
|
|
|
test_los( 1373, 1625, 59, 1379, 1625, 30, true );
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-29 21:55:48 +01:00
|
|
|
// BENCHMARK( BM_los100inside100outside );
|
2016-12-18 17:03:27 +01:00
|
|
|
|
2017-12-20 16:52:39 +01:00
|
|
|
static void BM_method( benchmark::State& state )
|
|
|
|
|
{
|
|
|
|
|
std::unique_ptr<Core::UOExecutor> ex( Core::create_script_executor() );
|
2018-01-29 21:55:48 +01:00
|
|
|
auto uoemod = new Module::UOExecutorModule( *ex );
|
|
|
|
|
ex->addModule( uoemod );
|
2017-12-20 16:52:39 +01:00
|
|
|
Items::Item* item = Items::Item::create( 0xffa1 );
|
2018-01-29 21:55:48 +01:00
|
|
|
auto ref = new Module::EItemRefObjImp( item );
|
|
|
|
|
|
2017-12-20 16:52:39 +01:00
|
|
|
while ( state.KeepRunning() )
|
|
|
|
|
{
|
2018-01-29 21:55:48 +01:00
|
|
|
ref->call_method( "test", *( ex.get() ) );
|
|
|
|
|
// for (int i=0;i<Bscript::n_objmembers;++i)
|
|
|
|
|
// ref->get_member(Bscript::object_members[i].code);
|
|
|
|
|
// ref->get_member("x");
|
2017-12-20 16:52:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BENCHMARK( BM_method );
|
|
|
|
|
static void BM_member_id( benchmark::State& state )
|
|
|
|
|
{
|
|
|
|
|
Items::Item* item = Items::Item::create( 0xffa1 );
|
2018-01-29 21:55:48 +01:00
|
|
|
auto ref = new Module::EItemRefObjImp( item );
|
|
|
|
|
|
2017-12-20 16:52:39 +01:00
|
|
|
while ( state.KeepRunning() )
|
|
|
|
|
{
|
2018-01-29 21:55:48 +01:00
|
|
|
ref->get_member_id( 1 );
|
|
|
|
|
// for (int i=0;i<Bscript::n_objmembers;++i)
|
|
|
|
|
// ref->get_member(Bscript::object_members[i].code);
|
|
|
|
|
// ref->get_member("x");
|
2017-12-20 16:52:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BENCHMARK( BM_member_id );
|
2016-12-18 12:48:35 +01:00
|
|
|
#endif
|
|
|
|
|
} // namespace Testing
|
|
|
|
|
} // namespace Pol
|