aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_node.cpp
Commit message (Expand)AuthorAge
* Add new ContentParamType2 "CPT2_DEGROTATE"est312015-10-04
* Push error handler afresh each time lua_pcall is usedKahrl2015-08-27
* Improve Script CPP API diagnosticskwolekr2015-08-05
* Replace instances of std::map<std::string, std::string> with StringMapkwolekr2015-05-19
* Add meshnode drawtype.RealBadAngel2014-10-18
* Fix object reference pushing functions when called from coroutinesShadowNinja2014-10-07
* Add optional framed glasslike drawtypeBlockMen2014-10-02
* Add firelike drawtypeTriBlade92014-09-21
* Only push the Lua error handler onceShadowNinja2014-04-27
* Pass pointed_thing to on_punch and minetest.register_on_punchnode callbacksShadowNinja2014-01-23
* Pass a errfunc to lua_pcall to get a tracebackShadowNinja2013-11-15
* Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenuKahrl2013-08-14
* Weather supportproller2013-07-27
* Leveled nodeboxproller2013-07-13
* Move scriptapi to separate folder (by sapier)sapier2013-05-25
e <algorithm> #include "gamedef.h" #include "log.h" #include "voxel.h" class TestVoxelManipulator : public TestBase { public: TestVoxelManipulator() { TestManager::registerTestModule(this); } const char *getName() { return "TestVoxelManipulator"; } void runTests(IGameDef *gamedef); void testVoxelArea(); void testVoxelManipulator(const NodeDefManager *nodedef); }; static TestVoxelManipulator g_test_instance; void TestVoxelManipulator::runTests(IGameDef *gamedef) { TEST(testVoxelArea); TEST(testVoxelManipulator, gamedef->getNodeDefManager()); } //////////////////////////////////////////////////////////////////////////////// void TestVoxelManipulator::testVoxelArea() { VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1)); UASSERT(a.index(0,0,0) == 1*3*3 + 1*3 + 1); UASSERT(a.index(-1,-1,-1) == 0); VoxelArea c(v3s16(-2,-2,-2), v3s16(2,2,2)); // An area that is 1 bigger in x+ and z- VoxelArea d(v3s16(-2,-2,-3), v3s16(3,2,2)); std::list<VoxelArea> aa; d.diff(c, aa); // Correct results std::vector<VoxelArea> results; results.emplace_back(v3s16(-2,-2,-3), v3s16(3,2,-3)); results.emplace_back(v3s16(3,-2,-2), v3s16(3,2,2)); UASSERT(aa.size() == results.size()); infostream<<"Result of diff:"<<std::endl; for (std::list<VoxelArea>::const_iterator it = aa.begin(); it != aa.end(); ++it) { it->print(infostream); infostream << std::endl; std::vector<VoxelArea>::iterator j; j = std::find(results.begin(), results.end(), *it); UASSERT(j != results.end()); results.erase(j); } } void TestVoxelManipulator::testVoxelManipulator(const NodeDefManager *nodedef) { VoxelManipulator v; v.print(infostream, nodedef); infostream << "*** Setting (-1,0,-1)=2 ***" << std::endl; v.setNodeNoRef(v3s16(-1,0,-1), MapNode(t_CONTENT_GRASS)); v.print(infostream, nodedef); UASSERT(v.getNode(v3s16(-1,0,-1)).getContent() == t_CONTENT_GRASS); infostream << "*** Reading from inexistent (0,0,-1) ***" << std::endl; EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1))); v.print(infostream, nodedef); infostream << "*** Adding area ***" << std::endl; VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1)); v.addArea(a); v.print(infostream, nodedef); UASSERT(v.getNode(v3s16(-1,0,-1)).getContent() == t_CONTENT_GRASS); EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1))); }