本文整理汇总了C++中VoxelManipulator类的典型用法代码示例。如果您正苦于以下问题:C++ VoxelManipulator类的具体用法?C++ VoxelManipulator怎么用?C++ VoxelManipulator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VoxelManipulator类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: clearLightAndCollectSources
void clearLightAndCollectSources(VoxelManipulator &v, VoxelArea a,
enum LightBank bank, INodeDefManager *ndef,
std::set<v3s16> & light_sources,
std::map<v3s16, u8> & unlight_from)
{
// The full area we shall touch
VoxelArea required_a = a;
required_a.pad(v3s16(0,0,0));
// Make sure we have access to it
v.emerge(a);
for(s32 x=a.MinEdge.X; x<=a.MaxEdge.X; x++)
for(s32 z=a.MinEdge.Z; z<=a.MaxEdge.Z; z++)
for(s32 y=a.MinEdge.Y; y<=a.MaxEdge.Y; y++)
{
v3s16 p(x,y,z);
MapNode &n = v.getNodeRefUnsafe(p);
u8 oldlight = n.getLight(bank, ndef);
n.setLight(bank, 0, ndef);
// If node sources light, add to list
u8 source = ndef->get(n).light_source;
if(source != 0)
light_sources.insert(p);
// Collect borders for unlighting
if((x==a.MinEdge.X || x == a.MaxEdge.X
|| y==a.MinEdge.Y || y == a.MaxEdge.Y
|| z==a.MinEdge.Z || z == a.MaxEdge.Z)
&& oldlight != 0)
{
unlight_from[p] = oldlight;
}
}
}
开发者ID:GottfriedSp,项目名称:minetest,代码行数:35,代码来源:voxelalgorithms.cpp
示例2: testClearLightAndCollectSources
void TestVoxelAlgorithms::testClearLightAndCollectSources(INodeDefManager *ndef)
{
VoxelManipulator v;
for (u16 z = 0; z < 3; z++)
for (u16 y = 0; y < 3; y++)
for (u16 x = 0; x < 3; x++) {
v3s16 p(x,y,z);
v.setNode(p, MapNode(CONTENT_AIR));
}
VoxelArea a(v3s16(0,0,0), v3s16(2,2,2));
v.setNodeNoRef(v3s16(0,0,0), MapNode(t_CONTENT_STONE));
v.setNodeNoRef(v3s16(1,1,1), MapNode(t_CONTENT_TORCH));
{
MapNode n(CONTENT_AIR);
n.setLight(LIGHTBANK_DAY, 1, ndef);
v.setNode(v3s16(1,1,2), n);
}
{
std::set<v3s16> light_sources;
std::map<v3s16, u8> unlight_from;
voxalgo::clearLightAndCollectSources(v, a, LIGHTBANK_DAY,
ndef, light_sources, unlight_from);
//v.print(dstream, ndef, VOXELPRINT_LIGHT_DAY);
UASSERT(v.getNode(v3s16(0,1,1)).getLight(LIGHTBANK_DAY, ndef) == 0);
UASSERT(light_sources.find(v3s16(1,1,1)) != light_sources.end());
UASSERT(light_sources.size() == 1);
UASSERT(unlight_from.find(v3s16(1,1,2)) != unlight_from.end());
UASSERT(unlight_from.size() == 1);
}
}
开发者ID:MultiCraftProject,项目名称:MultiCraft,代码行数:34,代码来源:test_voxelalgorithms.cpp
示例3: getSmoothLight
// Calculate lighting at the XYZ- corner of p
u8 getSmoothLight(v3s16 p, VoxelManipulator &vmanip, u32 daynight_ratio)
{
u16 ambient_occlusion = 0;
u16 light = 0;
u16 light_count = 0;
for(u32 i=0; i<8; i++)
{
MapNode n = vmanip.getNodeNoEx(p - dirs8[i]);
if(content_features(n.d).param_type == CPT_LIGHT
// Fast-style leaves look better this way
&& content_features(n.d).solidness != 2)
{
light += decode_light(n.getLightBlend(daynight_ratio));
light_count++;
}
else
{
if(n.d != CONTENT_IGNORE)
ambient_occlusion++;
}
}
if(light_count == 0)
return 255;
light /= light_count;
if(ambient_occlusion > 4)
{
ambient_occlusion -= 4;
light = (float)light / ((float)ambient_occlusion * 0.5 + 1.0);
}
return light;
}
开发者ID:asiekierka,项目名称:minetest-delta,代码行数:36,代码来源:mapblock_mesh.cpp
示例4: data_size
void MapBlock::copyFrom(VoxelManipulator &dst)
{
v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
VoxelArea data_area(v3s16(0,0,0), data_size - v3s16(1,1,1));
// Copy from VoxelManipulator to data
dst.copyTo(data, data_area, v3s16(0,0,0),
getPosRelative(), data_size);
}
开发者ID:wowiamdiamonds,项目名称:minetest,代码行数:9,代码来源:mapblock.cpp
示例5: lock_shared_rec
void MapBlock::copyTo(VoxelManipulator &dst)
{
auto lock = lock_shared_rec();
v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
VoxelArea data_area(v3s16(0,0,0), data_size - v3s16(1,1,1));
// Copy from data to VoxelManipulator
dst.copyFrom(data, data_area, v3s16(0,0,0),
getPosRelative(), data_size);
}
开发者ID:daniel-santos,项目名称:freeminer,代码行数:10,代码来源:mapblock.cpp
示例6: setLight
void setLight(VoxelManipulator &v, VoxelArea a, u8 light,
INodeDefManager *ndef)
{
for(s32 x=a.MinEdge.X; x<=a.MaxEdge.X; x++)
for(s32 z=a.MinEdge.Z; z<=a.MaxEdge.Z; z++)
for(s32 y=a.MinEdge.Y; y<=a.MaxEdge.Y; y++)
{
v3s16 p(x,y,z);
MapNode &n = v.getNodeRefUnsafe(p);
n.setLight(LIGHTBANK_DAY, light, ndef);
n.setLight(LIGHTBANK_NIGHT, light, ndef);
}
}
开发者ID:GottfriedSp,项目名称:minetest,代码行数:13,代码来源:voxelalgorithms.cpp
示例7: voxel_area
void Map::copy_27_blocks_to_vm(MapBlock * block, VoxelManipulator & vmanip) {
v3POS blockpos = block->getPos();
v3POS blockpos_nodes = blockpos * MAP_BLOCKSIZE;
// Allocate this block + neighbors
vmanip.clear();
VoxelArea voxel_area(blockpos_nodes - v3POS(1, 1, 1) * MAP_BLOCKSIZE,
blockpos_nodes + v3POS(1, 1, 1) * MAP_BLOCKSIZE * 2 - v3POS(1, 1, 1));
vmanip.addArea(voxel_area);
block->copyTo(vmanip);
auto * map = block->getParent();
for(u16 i = 0; i < 26; i++) {
v3POS bp = blockpos + g_26dirs[i];
MapBlock *b = map->getBlockNoCreateNoEx(bp);
if(b)
b->copyTo(vmanip);
}
}
开发者ID:hellotanm,项目名称:freeminer,代码行数:23,代码来源:fm_map.cpp
示例8: testVoxelManipulator
void TestVoxelManipulator::testVoxelManipulator(INodeDefManager *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)));
}
开发者ID:00c,项目名称:minetest,代码行数:26,代码来源:test_voxelmanipulator.cpp
示例9: getTileInfo
void getTileInfo(
// Input:
v3s16 blockpos_nodes,
v3s16 p,
v3s16 face_dir,
u32 daynight_ratio,
VoxelManipulator &vmanip,
NodeModMap &temp_mods,
bool smooth_lighting,
// Output:
bool &makes_face,
v3s16 &p_corrected,
v3s16 &face_dir_corrected,
u8 *lights,
TileSpec &tile
)
{
MapNode n0 = vmanip.getNodeNoEx(blockpos_nodes + p);
MapNode n1 = vmanip.getNodeNoEx(blockpos_nodes + p + face_dir);
TileSpec tile0 = getNodeTile(n0, p, face_dir, temp_mods);
TileSpec tile1 = getNodeTile(n1, p + face_dir, -face_dir, temp_mods);
// This is hackish
u8 content0 = getNodeContent(p, n0, temp_mods);
u8 content1 = getNodeContent(p + face_dir, n1, temp_mods);
u8 mf = face_contents(content0, content1);
if(mf == 0)
{
makes_face = false;
return;
}
makes_face = true;
if(mf == 1)
{
tile = tile0;
p_corrected = p;
face_dir_corrected = face_dir;
}
else
{
tile = tile1;
p_corrected = p + face_dir;
face_dir_corrected = -face_dir;
}
if(smooth_lighting == false)
{
lights[0] = lights[1] = lights[2] = lights[3] =
decode_light(getFaceLight(daynight_ratio, n0, n1, face_dir));
}
else
{
v3s16 vertex_dirs[4];
getNodeVertexDirs(face_dir_corrected, vertex_dirs);
for(u16 i=0; i<4; i++)
{
lights[i] = getSmoothLight(blockpos_nodes + p_corrected,
vertex_dirs[i], vmanip, daynight_ratio);
}
}
return;
}
开发者ID:asiekierka,项目名称:minetest-delta,代码行数:66,代码来源:mapblock_mesh.cpp
示例10: propagateSunlight
SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
bool inexistent_top_provides_sunlight,
std::set<v3s16> & light_sources,
INodeDefManager *ndef)
{
// Return values
bool bottom_sunlight_valid = true;
// The full area we shall touch extends one extra at top and bottom
VoxelArea required_a = a;
required_a.pad(v3s16(0,1,0));
// Make sure we have access to it
v.emerge(a);
s16 max_y = a.MaxEdge.Y;
s16 min_y = a.MinEdge.Y;
for(s32 x=a.MinEdge.X; x<=a.MaxEdge.X; x++)
for(s32 z=a.MinEdge.Z; z<=a.MaxEdge.Z; z++)
{
v3s16 p_overtop(x, max_y+1, z);
bool overtop_has_sunlight = false;
// If overtop node does not exist, trust heuristics
if(!v.exists(p_overtop))
overtop_has_sunlight = inexistent_top_provides_sunlight;
else if(v.getNodeRefUnsafe(p_overtop).getContent() == CONTENT_IGNORE)
overtop_has_sunlight = inexistent_top_provides_sunlight;
// Otherwise refer to it's light value
else
overtop_has_sunlight = (v.getNodeRefUnsafe(p_overtop).getLight(
LIGHTBANK_DAY, ndef) == LIGHT_SUN);
// Copy overtop's sunlight all over the place
u8 incoming_light = overtop_has_sunlight ? LIGHT_SUN : 0;
for(s32 y=max_y; y>=min_y; y--)
{
v3s16 p(x,y,z);
MapNode &n = v.getNodeRefUnsafe(p);
if(incoming_light == 0) {
// Do nothing
} else if(incoming_light == LIGHT_SUN &&
ndef->get(n).sunlight_propagates) {
// Do nothing
} else if(ndef->get(n).sunlight_propagates == false) {
incoming_light = 0;
} else {
incoming_light = diminish_light(incoming_light);
}
u8 old_light = n.getLight(LIGHTBANK_DAY, ndef);
if(incoming_light > old_light)
n.setLight(LIGHTBANK_DAY, incoming_light, ndef);
if(diminish_light(incoming_light) != 0)
light_sources.insert(p);
}
// Check validity of sunlight at top of block below if it
// hasn't already been proven invalid
if(bottom_sunlight_valid)
{
bool sunlight_should_continue_down = (incoming_light == LIGHT_SUN);
v3s16 p_overbottom(x, min_y-1, z);
if(!v.exists(p_overbottom) ||
v.getNodeRefUnsafe(p_overbottom
).getContent() == CONTENT_IGNORE) {
// Is not known, cannot compare
} else {
bool overbottom_has_sunlight = (v.getNodeRefUnsafe(p_overbottom
).getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN);
if(sunlight_should_continue_down != overbottom_has_sunlight) {
bottom_sunlight_valid = false;
}
}
}
}
return SunlightPropagateResult(bottom_sunlight_valid);
}
开发者ID:GottfriedSp,项目名称:minetest,代码行数:79,代码来源:voxelalgorithms.cpp
示例11: testPropogateSunlight
void TestVoxelAlgorithms::testPropogateSunlight(INodeDefManager *ndef)
{
VoxelManipulator v;
for (u16 z = 0; z < 3; z++)
for (u16 y = 0; y < 3; y++)
for (u16 x = 0; x < 3; x++) {
v3s16 p(x,y,z);
v.setNodeNoRef(p, MapNode(CONTENT_AIR));
}
VoxelArea a(v3s16(0,0,0), v3s16(2,2,2));
{
std::set<v3s16> light_sources;
voxalgo::setLight(v, a, 0, ndef);
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
v, a, true, light_sources, ndef);
//v.print(dstream, ndef, VOXELPRINT_LIGHT_DAY);
UASSERT(res.bottom_sunlight_valid == true);
UASSERT(v.getNode(v3s16(1,1,1)).getLight(LIGHTBANK_DAY, ndef)
== LIGHT_SUN);
}
v.setNodeNoRef(v3s16(0,0,0), MapNode(t_CONTENT_STONE));
{
std::set<v3s16> light_sources;
voxalgo::setLight(v, a, 0, ndef);
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
v, a, true, light_sources, ndef);
UASSERT(res.bottom_sunlight_valid == true);
UASSERT(v.getNode(v3s16(1,1,1)).getLight(LIGHTBANK_DAY, ndef)
== LIGHT_SUN);
}
{
std::set<v3s16> light_sources;
voxalgo::setLight(v, a, 0, ndef);
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
v, a, false, light_sources, ndef);
UASSERT(res.bottom_sunlight_valid == true);
UASSERT(v.getNode(v3s16(2,0,2)).getLight(LIGHTBANK_DAY, ndef)
== 0);
}
v.setNodeNoRef(v3s16(1,3,2), MapNode(t_CONTENT_STONE));
{
std::set<v3s16> light_sources;
voxalgo::setLight(v, a, 0, ndef);
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
v, a, true, light_sources, ndef);
UASSERT(res.bottom_sunlight_valid == true);
UASSERT(v.getNode(v3s16(1,1,2)).getLight(LIGHTBANK_DAY, ndef)
== 0);
}
{
std::set<v3s16> light_sources;
voxalgo::setLight(v, a, 0, ndef);
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
v, a, false, light_sources, ndef);
UASSERT(res.bottom_sunlight_valid == true);
UASSERT(v.getNode(v3s16(1,0,2)).getLight(LIGHTBANK_DAY, ndef)
== 0);
}
{
MapNode n(CONTENT_AIR);
n.setLight(LIGHTBANK_DAY, 10, ndef);
v.setNodeNoRef(v3s16(1,-1,2), n);
}
{
std::set<v3s16> light_sources;
voxalgo::setLight(v, a, 0, ndef);
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
v, a, true, light_sources, ndef);
UASSERT(res.bottom_sunlight_valid == true);
}
{
std::set<v3s16> light_sources;
voxalgo::setLight(v, a, 0, ndef);
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
v, a, false, light_sources, ndef);
UASSERT(res.bottom_sunlight_valid == true);
}
{
MapNode n(CONTENT_AIR);
n.setLight(LIGHTBANK_DAY, LIGHT_SUN, ndef);
v.setNodeNoRef(v3s16(1,-1,2), n);
}
{
std::set<v3s16> light_sources;
voxalgo::setLight(v, a, 0, ndef);
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
//.........这里部分代码省略.........
开发者ID:MultiCraftProject,项目名称:MultiCraft,代码行数:101,代码来源:test_voxelalgorithms.cpp
示例12: Run
void Run()
{
/*
VoxelArea
*/
VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1));
assert(a.index(0,0,0) == 1*3*3 + 1*3 + 1);
assert(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));
core::list<VoxelArea> aa;
d.diff(c, aa);
// Correct results
core::array<VoxelArea> results;
results.push_back(VoxelArea(v3s16(-2,-2,-3),v3s16(3,2,-3)));
results.push_back(VoxelArea(v3s16(3,-2,-2),v3s16(3,2,2)));
assert(aa.size() == results.size());
infostream<<"Result of diff:"<<std::endl;
for(core::list<VoxelArea>::Iterator
i = aa.begin(); i != aa.end(); i++)
{
i->print(infostream);
infostream<<std::endl;
s32 j = results.linear_search(*i);
assert(j != -1);
results.erase(j, 1);
}
/*
VoxelManipulator
*/
VoxelManipulator v;
v.print(infostream);
infostream<<"*** Setting (-1,0,-1)=2 ***"<<std::endl;
v.setNodeNoRef(v3s16(-1,0,-1), MapNode(2));
v.print(infostream);
assert(v.getNode(v3s16(-1,0,-1)).getContent() == 2);
infostream<<"*** Reading from inexistent (0,0,-1) ***"<<std::endl;
EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1)));
v.print(infostream);
infostream<<"*** Adding area ***"<<std::endl;
v.addArea(a);
v.print(infostream);
assert(v.getNode(v3s16(-1,0,-1)).getContent() == 2);
EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));
#if 0
/*
Water stuff
*/
v.clear();
const char *content =
"#...###### "
"#...##..## "
"#........ .."
"############"
"#...###### "
"#...##..## "
"#........# "
"############"
;
v3s16 size(12, 4, 2);
VoxelArea area(v3s16(0,0,0), size-v3s16(1,1,1));
const char *p = content;
for(s16 z=0; z<size.Z; z++)
for(s16 y=size.Y-1; y>=0; y--)
for(s16 x=0; x<size.X; x++)
{
MapNode n;
//n.pressure = size.Y - y;
if(*p == '#')
n.setContent(CONTENT_STONE);
else if(*p == '.')
//.........这里部分代码省略.........
开发者ID:MarkTraceur,项目名称:minetest,代码行数:101,代码来源:test.cpp
注:本文中的VoxelManipulator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论