Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/tests/test_LOSTexture.h
Show All 15 Lines | |||||
*/ | */ | ||||
#include "lib/self_test.h" | #include "lib/self_test.h" | ||||
#include "graphics/LOSTexture.h" | #include "graphics/LOSTexture.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/helpers/ArrayData.h" | |||||
class TestLOSTexture : public CxxTest::TestSuite | class TestLOSTexture : public CxxTest::TestSuite | ||||
{ | { | ||||
public: | public: | ||||
void test_basic() | void test_basic() | ||||
{ | { | ||||
CSimulation2 sim(NULL, g_ScriptRuntime, NULL); | CSimulation2 sim(NULL, g_ScriptRuntime, NULL); | ||||
CLOSTexture tex(sim); | CLOSTexture tex(sim); | ||||
const ssize_t size = 8; | const ssize_t size = 8; | ||||
u32 inputData[size*size] = { | PlayersData2b o(0); o.set(0, 0); // zero | ||||
2, 2, 2, 0, 0, 0, 0, 0, | PlayersData2b x(0); x.set(0, 2); // two | ||||
2, 2, 2, 0, 0, 0, 0, 0, | |||||
2, 2, 2, 0, 0, 0, 0, 0, | PlayersData2b inputData[size*size] = { | ||||
0, 0, 0, 0, 0, 0, 0, 0, | x, x, x, o, o, o, o, o, | ||||
0, 0, 0, 0, 0, 0, 0, 0, | x, x, x, o, o, o, o, o, | ||||
0, 0, 0, 0, 0, 0, 0, 0, | x, x, x, o, o, o, o, o, | ||||
0, 0, 0, 0, 0, 0, 0, 0, | o, o, o, o, o, o, o, o, | ||||
0, 0, 0, 0, 0, 0, 0, 2 | o, o, o, o, o, o, o, o, | ||||
o, o, o, o, o, o, o, o, | |||||
o, o, o, o, o, o, o, o, | |||||
o, o, o, o, o, o, o, x | |||||
Silier: also `0, 0` same below | |||||
}; | }; | ||||
std::vector<u32> inputDataVec(inputData, inputData+size*size); | std::vector<PlayersData2b> inputDataVec(inputData, inputData+size*size); | ||||
// LOS_MASK should be cmpRanageManager->GetSharedLosMask(1), | // LOS_MASK should be cmpRanageManager->GetSharedLosMask(1), | ||||
// but that would mean adding a huge mock component for this and it | // but that would mean adding a huge mock component for this and it | ||||
// should always be LOS_MASK for player 1 (as the other players are bit-shifted). | // should always be LOS_MASK for player 1 (as the other players are bit-shifted). | ||||
ICmpRangeManager::CLosQuerier los(ICmpRangeManager::LOS_MASK, inputDataVec, size); | PlayersData2b player1(0); player1.set(0, ICmpRangeManager::LOS_MASK); | ||||
ICmpRangeManager::CLosQuerier los(player1, inputDataVec, size); | |||||
std::vector<u8> losData; | std::vector<u8> losData; | ||||
size_t pitch; | size_t pitch; | ||||
losData.resize(tex.GetBitmapSize(size, size, &pitch)); | losData.resize(tex.GetBitmapSize(size, size, &pitch)); | ||||
tex.GenerateBitmap(los, &losData[0], size, size, pitch); | tex.GenerateBitmap(los, &losData[0], size, size, pitch); | ||||
// for (size_t i = 0; i < losData.size(); ++i) | // for (size_t i = 0; i < losData.size(); ++i) | ||||
// printf("%s %3d", i % (size_t)sqrt(losData.size()) ? "" : "\n", losData[i]); | // printf("%s %3d", i % (size_t)sqrt(losData.size()) ? "" : "\n", losData[i]); | ||||
TS_ASSERT_EQUALS(losData[0], 104); | TS_ASSERT_EQUALS(losData[0], 104); | ||||
} | } | ||||
void test_perf_DISABLED() | void test_perf_DISABLED() | ||||
{ | { | ||||
CSimulation2 sim(NULL, g_ScriptRuntime, NULL); | CSimulation2 sim(NULL, g_ScriptRuntime, NULL); | ||||
CLOSTexture tex(sim); | CLOSTexture tex(sim); | ||||
const ssize_t size = 257; | const ssize_t size = 257; | ||||
std::vector<u32> inputDataVec; | std::vector<PlayersData2b> inputDataVec; | ||||
inputDataVec.resize(size*size); | inputDataVec.resize(size*size); | ||||
// LOS_MASK should be cmpRanageManager->GetSharedLosMask(1), | // LOS_MASK should be cmpRanageManager->GetSharedLosMask(1), | ||||
// but that would mean adding a huge mock component for this and it | // but that would mean adding a huge mock component for this and it | ||||
// should always be LOS_MASK for player 1 (as the other players are bit-shifted). | // should always be LOS_MASK for player 1 (as the other players are bit-shifted). | ||||
ICmpRangeManager::CLosQuerier los(ICmpRangeManager::LOS_MASK, inputDataVec, size); | PlayersData2b player1(0); player1.set(0, ICmpRangeManager::LOS_MASK); | ||||
ICmpRangeManager::CLosQuerier los(player1, inputDataVec, size); | |||||
size_t reps = 128; | size_t reps = 128; | ||||
double t = timer_Time(); | double t = timer_Time(); | ||||
for (size_t i = 0; i < reps; ++i) | for (size_t i = 0; i < reps; ++i) | ||||
{ | { | ||||
std::vector<u8> losData; | std::vector<u8> losData; | ||||
size_t pitch; | size_t pitch; | ||||
losData.resize(tex.GetBitmapSize(size, size, &pitch)); | losData.resize(tex.GetBitmapSize(size, size, &pitch)); | ||||
tex.GenerateBitmap(los, &losData[0], size, size, pitch); | tex.GenerateBitmap(los, &losData[0], size, size, pitch); | ||||
} | } | ||||
double dt = timer_Time() - t; | double dt = timer_Time() - t; | ||||
printf("\n# %f secs\n", dt/reps); | printf("\n# %f secs\n", dt/reps); | ||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator
also 0, 0 same below