Pol  Revision:4b29d2b
testlos.cpp
Go to the documentation of this file.
1 
7 #include "testenv.h"
8 
9 #include "pol_global_config.h"
10 
11 #ifdef ENABLE_BENCHMARK
12 #include "../module/uomod.h"
13 #include "../scrsched.h"
14 #include "../uoexec.h"
15 #include "../uoscrobj.h"
16 #include <benchmark/benchmark.h>
17 #endif
18 
19 #include "../../clib/logfacility.h"
20 #include "../../clib/rawtypes.h"
21 #include "../globals/uvars.h"
22 #include "../item/item.h"
23 #include "../los.h"
24 #include "../mobile/npc.h"
25 #include "../realms/realm.h"
26 #include "../uobject.h"
27 
28 namespace Pol
29 {
30 namespace Testing
31 {
32 namespace
33 {
34 void test_los( Core::UObject* src, Core::UObject* target, bool should_have_los )
35 {
36 #ifndef ENABLE_BENCHMARK
37  INFO_PRINT << "LOS test: " << src->name() << " to " << target->name() << "(" << should_have_los
38  << "):";
39 #endif
40 
41  bool res = Core::gamestate.main_realm->has_los( *src, *target );
42 #ifdef ENABLE_BENCHMARK
43  return;
44 #endif
45 
46  INFO_PRINT << res << " ";
47  if ( should_have_los == res )
48  {
49  INFO_PRINT << "Ok!\n";
50  inc_successes();
51  }
52  else
53  {
54  INFO_PRINT << "Failure!\n";
55  inc_failures();
56  }
57 }
58 
59 void test_los( u16 x1, u16 y1, s8 z1, u16 x2, u16 y2, s8 z2, bool should_have_los )
60 {
61 #ifndef ENABLE_BENCHMARK
62  INFO_PRINT << "LOS test: (" << x1 << "," << y1 << "," << int( z1 ) << ")"
63  << " - (" << x2 << "," << y2 << "," << int( z2 ) << ")"
64  << " (" << should_have_los << "):";
65 #endif
66  auto main_realm = Core::gamestate.main_realm;
67  bool res = main_realm->has_los( Core::LosObj( x1, y1, z1, main_realm ),
68  Core::LosObj( x2, y2, z2, main_realm ) );
69 #ifdef ENABLE_BENCHMARK
70  return;
71 #endif
72 
73  INFO_PRINT << res << " ";
74  if ( should_have_los == res )
75  {
76  INFO_PRINT << "Ok!\n";
77  inc_successes();
78  }
79  else
80  {
81  INFO_PRINT << "Failure!\n";
82  inc_failures();
83  }
84 }
85 
86 void test_los( u16 x1, u16 y1, s8 z1, u8 h1, u16 x2, u16 y2, s8 z2, u8 h2, bool should_have_los )
87 {
88 #ifndef ENABLE_BENCHMARK
89  INFO_PRINT << "LOS test: (" << x1 << "," << y1 << "," << int( z1 ) << ",ht=" << int( h1 ) << ")"
90  << " - (" << x2 << "," << y2 << "," << int( z2 ) << ",ht=" << int( h2 ) << ")"
91  << " (" << should_have_los << "):";
92 #endif
93  auto main_realm = Core::gamestate.main_realm;
94  bool res = main_realm->has_los( Core::LosObj( x1, y1, z1, main_realm ),
95  Core::LosObj( x2, y2, z2, main_realm ) );
96 #ifdef ENABLE_BENCHMARK
97  return;
98 #endif
99 
100  INFO_PRINT << res << " ";
101  if ( should_have_los == res )
102  {
103  INFO_PRINT << "Ok!\n";
104  inc_successes();
105  }
106  else
107  {
108  INFO_PRINT << "Failure!\n";
109  inc_failures();
110  }
111 }
112 } // namespace
113 
114 void los_test()
115 {
116 #ifndef ENABLE_BENCHMARK
117  INFO_PRINT << "POL datafile LOS tests:\n";
118 #endif
119  test_los( 5421, 78, 10, 5422, 89, 20, false );
120  test_los( 1403, 1624, 28, 1402, 1625, 28, true );
121 
122  test_los( 1374, 1625, 59, 1379, 1625, 30, true );
123  test_los( 1373, 1625, 59, 1379, 1625, 30, true );
124  test_los( 1372, 1625, 59, 1379, 1625, 30, false );
125  test_los( 1372, 1625, 59, 1381, 1625, 30, true );
126 
127  // from you standing in the house in GA to a backpack outside
128  test_los( 5987, 1999, 7 + 9, 5991, 2001, 1, false );
129  test_los( 5987, 1999, 7 + 9, 5993, 1997, 1, false );
130 
131  // test looking through "black space" in a cave
132  test_los( 5583, 226, 0, 5590, 223, 0, false );
133 
134  test_los( test_banker2, test_chest1, true );
135  test_los( test_banker2, test_chest2, true );
136 
137  // standing aboveground in buc's den, and below
138 
139  test_los( test_orclord, test_banker3, false );
140 
141  test_los( 579, 2106, 0, 1, 563, 2107, 0, 1, false );
142  test_los( 862, 1691, 0, 1, 843, 1689, 0, 1, true );
143  test_los( 1618, 3351, 3, 1, 1618, 3340, 4, 1, true );
144 }
145 
146 #ifdef ENABLE_BENCHMARK
147 
148 static void BM_los( benchmark::State& state )
149 {
150  while ( state.KeepRunning() )
151  {
152  los_test();
153  }
154 }
155 // BENCHMARK( BM_los );
156 
157 static void BM_los100inside100outside( benchmark::State& state )
158 {
159  while ( state.KeepRunning() )
160  {
161  test_los( 1373, 1625, 59, 1379, 1625, 30, true );
162  }
163 }
164 // BENCHMARK( BM_los100inside100outside );
165 
166 static void BM_method( benchmark::State& state )
167 {
168  std::unique_ptr<Core::UOExecutor> ex( Core::create_script_executor() );
169  auto uoemod = new Module::UOExecutorModule( *ex );
170  ex->addModule( uoemod );
171  Items::Item* item = Items::Item::create( 0xffa1 );
172  auto ref = new Module::EItemRefObjImp( item );
173 
174  while ( state.KeepRunning() )
175  {
176  ref->call_method( "test", *( ex.get() ) );
177  // for (int i=0;i<Bscript::n_objmembers;++i)
178  // ref->get_member(Bscript::object_members[i].code);
179  // ref->get_member("x");
180  }
181 }
182 BENCHMARK( BM_method );
183 static void BM_member_id( benchmark::State& state )
184 {
185  Items::Item* item = Items::Item::create( 0xffa1 );
186  auto ref = new Module::EItemRefObjImp( item );
187 
188  while ( state.KeepRunning() )
189  {
190  ref->get_member_id( 1 );
191  // for (int i=0;i<Bscript::n_objmembers;++i)
192  // ref->get_member(Bscript::object_members[i].code);
193  // ref->get_member("x");
194  }
195 }
196 BENCHMARK( BM_member_id );
197 #endif
198 } // namespace Testing
199 } // namespace Pol
unsigned char u8
Definition: rawtypes.h:25
static Item * create(u32 objtype, u32 serial=0)
Definition: itemcr.cpp:53
void los_test()
Definition: testlos.cpp:114
Item * test_chest1
Definition: testenv.cpp:58
void inc_failures()
Definition: testenv.cpp:33
Mobile::NPC * test_banker2
Definition: testenv.cpp:53
unsigned short u16
Definition: rawtypes.h:26
UOExecutor * create_script_executor()
Definition: scrsched.cpp:644
bool has_los(const Core::ULWObject &att, const Core::ULWObject &tgt) const
Definition: realmlos.cpp:146
signed char s8
Definition: rawtypes.h:29
GameState gamestate
Definition: uvars.cpp:74
Mobile::NPC * test_orclord
Definition: testenv.cpp:60
Mobile::NPC * test_banker3
Definition: testenv.cpp:54
void inc_successes()
Definition: testenv.cpp:38
#define INFO_PRINT
Definition: logfacility.h:223
Realms::Realm * main_realm
Definition: uvars.h:162
Definition: berror.cpp:12
Item * test_chest2
Definition: testenv.cpp:59