这篇教程C++ v3s16函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中v3s16函数的典型用法代码示例。如果您正苦于以下问题:C++ v3s16函数的具体用法?C++ v3s16怎么用?C++ v3s16使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了v3s16函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: getIndexElementbool Pathfinder::updateAllCosts(v3s16 ipos, v3s16 srcdir, int current_cost, int level){ PathGridnode &g_pos = getIndexElement(ipos); g_pos.totalcost = current_cost; g_pos.sourcedir = srcdir; level ++; //check if target has been found if (g_pos.target) { m_min_target_distance = current_cost; DEBUG_OUT(LVL " Pathfinder: target found!" << std::endl); return true; } bool retval = false; std::vector<v3s16> directions; directions.push_back(v3s16( 1,0, 0)); directions.push_back(v3s16(-1,0, 0)); directions.push_back(v3s16( 0,0, 1)); directions.push_back(v3s16( 0,0,-1)); for (unsigned int i=0; i < directions.size(); i++) { if (directions[i] != srcdir) { PathCost cost = g_pos.getCost(directions[i]); if (cost.valid) { directions[i].Y = cost.direction; v3s16 ipos2 = ipos + directions[i]; if (!isValidIndex(ipos2)) { DEBUG_OUT(LVL " Pathfinder: " << PP(ipos2) << " out of range, max=" << PP(m_limits.MaxEdge) << std::endl); continue; } PathGridnode &g_pos2 = getIndexElement(ipos2); if (!g_pos2.valid) { VERBOSE_TARGET << LVL "Pathfinder: no data for new position: " << PP(ipos2) << std::endl; continue; } assert(cost.value > 0); int new_cost = current_cost + cost.value; // check if there already is a smaller path if ((m_min_target_distance > 0) && (m_min_target_distance < new_cost)) { return false; } if ((g_pos2.totalcost < 0) || (g_pos2.totalcost > new_cost)) { DEBUG_OUT(LVL "Pathfinder: updating path at: "<< PP(ipos2) << " from: " << g_pos2.totalcost << " to "<< new_cost << std::endl); if (updateAllCosts(ipos2, invert(directions[i]), new_cost, level)) { retval = true; } } else { DEBUG_OUT(LVL "Pathfinder:" " already found shorter path to: " << PP(ipos2) << std::endl); } } else { DEBUG_OUT(LVL "Pathfinder:" " not moving to invalid direction: " << PP(directions[i]) << std::endl); } } } return retval;}
开发者ID:minetest,项目名称:minetest,代码行数:85,
示例2: mapblock_mesh_generate_specialvoid mapblock_mesh_generate_special(MeshMakeData *data, MeshCollector &collector, IGameDef *gamedef){ INodeDefManager *nodedef = gamedef->ndef(); // 0ms //TimeTaker timer("mapblock_mesh_generate_special()"); /* Some settings */ bool new_style_water = g_settings->getBool("new_style_water"); float node_liquid_level = 1.0; if(new_style_water) node_liquid_level = 0.85; v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE; /*// General ground material for special output // Texture is modified just before usage video::SMaterial material_general; material_general.setFlag(video::EMF_LIGHTING, false); material_general.setFlag(video::EMF_BILINEAR_FILTER, false); material_general.setFlag(video::EMF_FOG_ENABLE, true); material_general.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;*/ for(s16 z=0; z<MAP_BLOCKSIZE; z++) for(s16 y=0; y<MAP_BLOCKSIZE; y++) for(s16 x=0; x<MAP_BLOCKSIZE; x++) { v3s16 p(x,y,z); MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes+p); const ContentFeatures &f = nodedef->get(n); // Only solidness=0 stuff is drawn here if(f.solidness != 0) continue; switch(f.drawtype){ default: infostream<<"Got "<<f.drawtype<<std::endl; assert(0); break; case NDT_AIRLIKE: break; case NDT_LIQUID: { /* Add water sources to mesh if using new style */ assert(nodedef->get(n).special_materials[0]); //assert(nodedef->get(n).special_materials[1]); assert(nodedef->get(n).special_aps[0]); video::SMaterial &liquid_material = *nodedef->get(n).special_materials[0]; /*video::SMaterial &liquid_material_bfculled = *nodedef->get(n).special_materials[1];*/ AtlasPointer &pa_liquid1 = *nodedef->get(n).special_aps[0]; bool top_is_air = false; MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z)); if(n.getContent() == CONTENT_AIR) top_is_air = true; if(top_is_air == false) continue; u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio, nodedef)); video::SColor c = MapBlock_LightColor( nodedef->get(n).alpha, l); video::S3DVertex vertices[4] = { video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, pa_liquid1.x0(), pa_liquid1.y1()), video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, pa_liquid1.x1(), pa_liquid1.y1()), video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, pa_liquid1.x1(), pa_liquid1.y0()), video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c, pa_liquid1.x0(), pa_liquid1.y0()), }; for(s32 i=0; i<4; i++) { vertices[i].Pos.Y += (-0.5+node_liquid_level)*BS; vertices[i].Pos += intToFloat(p + blockpos_nodes, BS); } u16 indices[] = {0,1,2,2,3,0}; // Add to mesh collector collector.append(liquid_material, vertices, 4, indices, 6); break;} case NDT_FLOWINGLIQUID: { /*//.........这里部分代码省略.........
开发者ID:bcmpinc,项目名称:minetest,代码行数:101,
示例3: assertvoid Schematic::placeOnMap(Map *map, v3s16 p, u32 flags, Rotation rot, bool force_place){ concurrent_map<v3POS, MapBlock *> lighting_modified_blocks; /* std::map<v3s16, MapBlock *> lighting_modified_blocks; */ std::map<v3s16, MapBlock *> modified_blocks; std::map<v3s16, MapBlock *>::iterator it; if(!map || !schemdata || !m_ndef) return; /* assert(map != NULL); assert(schemdata != NULL); sanity_check(m_ndef != NULL); */ //// Determine effective rotation and effective schematic dimensions if (rot == ROTATE_RAND) rot = (Rotation)myrand_range(ROTATE_0, ROTATE_270); v3s16 s = (rot == ROTATE_90 || rot == ROTATE_270) ? v3s16(size.Z, size.Y, size.X) : size; //// Adjust placement position if necessary if (flags & DECO_PLACE_CENTER_X) p.X -= (s.X + 1) / 2; if (flags & DECO_PLACE_CENTER_Y) p.Y -= (s.Y + 1) / 2; if (flags & DECO_PLACE_CENTER_Z) p.Z -= (s.Z + 1) / 2; //// Create VManip for effected area, emerge our area, modify area //// inside VManip, then blit back. v3s16 bp1 = getNodeBlockPos(p); v3s16 bp2 = getNodeBlockPos(p + s - v3s16(1,1,1)); MMVManip vm(map); vm.initialEmerge(bp1, bp2); blitToVManip(&vm, p, rot, force_place); vm.blitBackAll(&modified_blocks); //// Carry out post-map-modification actions //// Update lighting // TODO: Optimize this by using Mapgen::calcLighting() instead lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end()); map->updateLighting(lighting_modified_blocks, modified_blocks); //// Create & dispatch map modification events to observers MapEditEvent event; event.type = MEET_OTHER; /* for (it = modified_blocks.begin(); it != modified_blocks.end(); ++it) event.modified_blocks.insert(it->first); */ map->dispatchEvent(&event);}
开发者ID:ChunHungLiu,项目名称:freeminer,代码行数:63,
示例4: grassrandomvoid MapgenV6::placeTreesAndJungleGrass(){ //TimeTaker t("placeTrees"); PseudoRandom grassrandom(blockseed + 53); content_t c_sand = ndef->getId("mapgen_sand"); content_t c_junglegrass = ndef->getId("mapgen_junglegrass"); // if we don't have junglegrass, don't place cignore... that's bad if (c_junglegrass == CONTENT_IGNORE) c_junglegrass = CONTENT_AIR; MapNode n_junglegrass(c_junglegrass); v3s16 em = vm->m_area.getExtent(); // Divide area into parts s16 div = 8; s16 sidelen = central_area_size.X / div; double area = sidelen * sidelen; // N.B. We must add jungle grass first, since tree leaves will // obstruct the ground, giving us a false ground level for (s16 z0 = 0; z0 < div; z0++) for (s16 x0 = 0; x0 < div; x0++) { // Center position of part of division v2s16 p2d_center( node_min.X + sidelen / 2 + sidelen * x0, node_min.Z + sidelen / 2 + sidelen * z0 ); // Minimum edge of part of division v2s16 p2d_min( node_min.X + sidelen * x0, node_min.Z + sidelen * z0 ); // Maximum edge of part of division v2s16 p2d_max( node_min.X + sidelen + sidelen * x0 - 1, node_min.Z + sidelen + sidelen * z0 - 1 ); // Get biome at center position of part of division BiomeV6Type bt = getBiome(v3POS(p2d_center.X, node_min.Y, p2d_center.Y)); // Amount of trees float humidity = getHumidity(v3POS(p2d_center.X, node_max.Y, p2d_center.Y)); s32 tree_count; if (bt == BT_JUNGLE || bt == BT_TAIGA || bt == BT_NORMAL) { tree_count = area * getTreeAmount(p2d_center) * ((humidity + 1)/2.0); if (bt == BT_JUNGLE) tree_count *= 4; } else { tree_count = 0; } if (node_max.Y < water_level) tree_count /= 2; // Add jungle grass if (bt == BT_JUNGLE) { u32 grass_count = 5 * humidity * tree_count; for (u32 i = 0; i < grass_count; i++) { s16 x = grassrandom.range(p2d_min.X, p2d_max.X); s16 z = grassrandom.range(p2d_min.Y, p2d_max.Y);/* wtf int mapindex = central_area_size.X * (z - node_min.Z) + (x - node_min.X); s16 y = heightmap[mapindex];*/ s16 y = findGroundLevelFull(v2s16(x, z)); if (y < water_level) continue; u32 vi = vm->m_area.index(x, y, z); // place on dirt_with_grass, since we know it is exposed to sunlight if (vm->m_data[vi].getContent() == c_dirt_with_grass) { vm->m_area.add_y(em, vi, 1); vm->m_data[vi] = n_junglegrass; } } } // Put trees in random places on part of division for (s32 i = 0; i < tree_count; i++) { s16 x = myrand_range(p2d_min.X, p2d_max.X); s16 z = myrand_range(p2d_min.Y, p2d_max.Y);/* wtf int mapindex = central_area_size.X * (z - node_min.Z) + (x - node_min.X); s16 y = heightmap[mapindex];*/ s16 y = findGroundLevelFull(v2s16(x, z)); // Don't make a tree under water level // Don't make a tree so high that it doesn't fit if (y > node_max.Y - 6) continue; v3s16 p(x, y, z); // Trees grow only on mud and grass and snowblock {//.........这里部分代码省略.........
开发者ID:alexxvk,项目名称:freeminer,代码行数:101,
示例5: getNodeVertexDirs/* vertex_dirs: v3s16[4]*/static void getNodeVertexDirs(v3s16 dir, v3s16 *vertex_dirs){ /* If looked from outside the node towards the face, the corners are: 0: bottom-right 1: bottom-left 2: top-left 3: top-right */ if(dir == v3s16(0,0,1)) { // If looking towards z+, this is the face that is behind // the center point, facing towards z+. vertex_dirs[0] = v3s16(-1,-1, 1); vertex_dirs[1] = v3s16( 1,-1, 1); vertex_dirs[2] = v3s16( 1, 1, 1); vertex_dirs[3] = v3s16(-1, 1, 1); } else if(dir == v3s16(0,0,-1)) { // faces towards Z- vertex_dirs[0] = v3s16( 1,-1,-1); vertex_dirs[1] = v3s16(-1,-1,-1); vertex_dirs[2] = v3s16(-1, 1,-1); vertex_dirs[3] = v3s16( 1, 1,-1); } else if(dir == v3s16(1,0,0)) { // faces towards X+ vertex_dirs[0] = v3s16( 1,-1, 1); vertex_dirs[1] = v3s16( 1,-1,-1); vertex_dirs[2] = v3s16( 1, 1,-1); vertex_dirs[3] = v3s16( 1, 1, 1); } else if(dir == v3s16(-1,0,0)) { // faces towards X- vertex_dirs[0] = v3s16(-1,-1,-1); vertex_dirs[1] = v3s16(-1,-1, 1); vertex_dirs[2] = v3s16(-1, 1, 1); vertex_dirs[3] = v3s16(-1, 1,-1); } else if(dir == v3s16(0,1,0)) { // faces towards Y+ (assume Z- as "down" in texture) vertex_dirs[0] = v3s16( 1, 1,-1); vertex_dirs[1] = v3s16(-1, 1,-1); vertex_dirs[2] = v3s16(-1, 1, 1); vertex_dirs[3] = v3s16( 1, 1, 1); } else if(dir == v3s16(0,-1,0)) { // faces towards Y- (assume Z+ as "down" in texture) vertex_dirs[0] = v3s16( 1,-1, 1); vertex_dirs[1] = v3s16(-1,-1, 1); vertex_dirs[2] = v3s16(-1,-1,-1); vertex_dirs[3] = v3s16( 1,-1,-1); }}
开发者ID:4aiman,项目名称:MultiCraft,代码行数:62,
示例6: collisionMoveSimplecollisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, f32 pos_max_d, const aabb3f &box_0, f32 stepheight, f32 dtime, v3f *pos_f, v3f *speed_f, v3f accel_f, ActiveObject *self, bool collideWithObjects){ static bool time_notification_done = false; Map *map = &env->getMap(); //TimeTaker tt("collisionMoveSimple"); ScopeProfiler sp(g_profiler, "collisionMoveSimple avg", SPT_AVG); collisionMoveResult result; /* Calculate new velocity */ if (dtime > 0.5) { if (!time_notification_done) { time_notification_done = true; infostream << "collisionMoveSimple: maximum step interval exceeded," " lost movement details!"<<std::endl; } dtime = 0.5; } else { time_notification_done = false; } *speed_f += accel_f * dtime; // If there is no speed, there are no collisions if (speed_f->getLength() == 0) return result; // Limit speed for avoiding hangs speed_f->Y = rangelim(speed_f->Y, -5000, 5000); speed_f->X = rangelim(speed_f->X, -5000, 5000); speed_f->Z = rangelim(speed_f->Z, -5000, 5000); /* Collect node boxes in movement range */ std::vector<aabb3f> cboxes; std::vector<bool> is_unloaded; std::vector<bool> is_step_up; std::vector<bool> is_object; std::vector<int> bouncy_values; std::vector<v3s16> node_positions; { //TimeTaker tt2("collisionMoveSimple collect boxes"); ScopeProfiler sp(g_profiler, "collisionMoveSimple collect boxes avg", SPT_AVG); v3s16 oldpos_i = floatToInt(*pos_f, BS); v3s16 newpos_i = floatToInt(*pos_f + *speed_f * dtime, BS); s16 min_x = MYMIN(oldpos_i.X, newpos_i.X) + (box_0.MinEdge.X / BS) - 1; s16 min_y = MYMIN(oldpos_i.Y, newpos_i.Y) + (box_0.MinEdge.Y / BS) - 1; s16 min_z = MYMIN(oldpos_i.Z, newpos_i.Z) + (box_0.MinEdge.Z / BS) - 1; s16 max_x = MYMAX(oldpos_i.X, newpos_i.X) + (box_0.MaxEdge.X / BS) + 1; s16 max_y = MYMAX(oldpos_i.Y, newpos_i.Y) + (box_0.MaxEdge.Y / BS) + 1; s16 max_z = MYMAX(oldpos_i.Z, newpos_i.Z) + (box_0.MaxEdge.Z / BS) + 1; bool any_position_valid = false; for(s16 x = min_x; x <= max_x; x++) for(s16 y = min_y; y <= max_y; y++) for(s16 z = min_z; z <= max_z; z++) { v3s16 p(x,y,z); bool is_position_valid; MapNode n = map->getNodeNoEx(p, &is_position_valid); if (is_position_valid) { // Object collides into walkable nodes any_position_valid = true; const ContentFeatures &f = gamedef->getNodeDefManager()->get(n); if(f.walkable == false) continue; int n_bouncy_value = itemgroup_get(f.groups, "bouncy"); std::vector<aabb3f> nodeboxes = n.getCollisionBoxes(gamedef->ndef()); for(std::vector<aabb3f>::iterator i = nodeboxes.begin(); i != nodeboxes.end(); ++i) { aabb3f box = *i; box.MinEdge += v3f(x, y, z)*BS; box.MaxEdge += v3f(x, y, z)*BS; cboxes.push_back(box); is_unloaded.push_back(false); is_step_up.push_back(false); bouncy_values.push_back(n_bouncy_value); node_positions.push_back(p); is_object.push_back(false); } } else { // Collide with unloaded nodes aabb3f box = getNodeBox(p, BS); cboxes.push_back(box);//.........这里部分代码省略.........
开发者ID:grigoriis,项目名称:MultiCraft,代码行数:101,
示例7: assertvoid MapgenV6::makeChunk(BlockMakeData *data){ // Pre-conditions assert(data->vmanip); assert(data->nodedef); assert(data->blockpos_requested.X >= data->blockpos_min.X && data->blockpos_requested.Y >= data->blockpos_min.Y && data->blockpos_requested.Z >= data->blockpos_min.Z); assert(data->blockpos_requested.X <= data->blockpos_max.X && data->blockpos_requested.Y <= data->blockpos_max.Y && data->blockpos_requested.Z <= data->blockpos_max.Z); this->generating = true; this->vm = data->vmanip; this->ndef = data->nodedef; // Hack: use minimum block coords for old code that assumes a single block v3s16 blockpos_min = data->blockpos_min; v3s16 blockpos_max = data->blockpos_max; // Area of central chunk node_min = blockpos_min * MAP_BLOCKSIZE; node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); // Full allocated area full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1); central_area_size = node_max - node_min + v3s16(1, 1, 1); assert(central_area_size.X == central_area_size.Z); int volume_blocks = (blockpos_max.X - blockpos_min.X + 1) * (blockpos_max.Y - blockpos_min.Y + 1) * (blockpos_max.Z - blockpos_max.Z + 1); volume_nodes = volume_blocks * MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE; // Create a block-specific seed blockseed = get_blockseed(data->seed, full_node_min); // Make some noise calculateNoise(); // Maximum height of the stone surface and obstacles. // This is used to guide the cave generation s16 stone_surface_max_y; // Generate general ground level to full area stone_surface_max_y = generateGround(); generateExperimental(); // Create initial heightmap to limit caves updateHeightmap(node_min, node_max); const s16 max_spread_amount = MAP_BLOCKSIZE; // Limit dirt flow area by 1 because mud is flown into neighbors. s16 mudflow_minpos = -max_spread_amount + 1; s16 mudflow_maxpos = central_area_size.X + max_spread_amount - 2; // Loop this part, it will make stuff look older and newer nicely const u32 age_loops = 2; for (u32 i_age = 0; i_age < age_loops; i_age++) { // Aging loop // Make caves (this code is relatively horrible) if (flags & MG_CAVES) generateCaves(stone_surface_max_y); // Add mud to the central chunk addMud(); // Flow mud away from steep edges if (spflags & MGV6_MUDFLOW) flowMud(mudflow_minpos, mudflow_maxpos); } // Update heightmap after mudflow updateHeightmap(node_min, node_max); // Add dungeons if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) { DungeonParams dp; dp.seed = seed; dp.c_water = c_water_source; dp.c_river_water = c_water_source; dp.rooms_min = 2; dp.rooms_max = 16; dp.y_min = -MAX_MAP_GENERATION_LIMIT; dp.y_max = MAX_MAP_GENERATION_LIMIT; dp.np_density = NoiseParams(0.9, 0.5, v3f(500.0, 500.0, 500.0), 0, 2, 0.8, 2.0); dp.np_alt_wall = NoiseParams(-0.4, 1.0, v3f(40.0, 40.0, 40.0), 32474, 6, 1.1, 2.0); if (getBiome(0, node_min) == BT_DESERT) { dp.c_wall = c_desert_stone; dp.c_alt_wall = CONTENT_IGNORE; dp.c_stair = c_desert_stone; dp.diagonal_dirs = true;//.........这里部分代码省略.........
开发者ID:alexxvk,项目名称:freeminer,代码行数:101,
示例8: v3s16/* Lights neighbors of from_nodes, collects all them and then goes on recursively.*/void VoxelManipulator::spreadLight(enum LightBank bank, core::map<v3s16, bool> & from_nodes, INodeDefManager *nodemgr){ const v3s16 dirs[6] = { v3s16(0,0,1), // back v3s16(0,1,0), // top v3s16(1,0,0), // right v3s16(0,0,-1), // front v3s16(0,-1,0), // bottom v3s16(-1,0,0), // left }; if(from_nodes.size() == 0) return; core::map<v3s16, bool> lighted_nodes; core::map<v3s16, bool>::Iterator j; j = from_nodes.getIterator(); for(; j.atEnd() == false; j++) { v3s16 pos = j.getNode()->getKey(); emerge(VoxelArea(pos - v3s16(1,1,1), pos + v3s16(1,1,1))); u32 i = m_area.index(pos); if(m_flags[i] & VOXELFLAG_INEXISTENT) continue; MapNode &n = m_data[i]; u8 oldlight = n.getLight(bank, nodemgr); u8 newlight = diminish_light(oldlight); // Loop through 6 neighbors for(u16 i=0; i<6; i++) { // Get the position of the neighbor node v3s16 n2pos = pos + dirs[i]; try { u32 n2i = m_area.index(n2pos); if(m_flags[n2i] & VOXELFLAG_INEXISTENT) continue; MapNode &n2 = m_data[n2i]; u8 light2 = n2.getLight(bank, nodemgr); /* If the neighbor is brighter than the current node, add to list (it will light up this node on its turn) */ if(light2 > undiminish_light(oldlight)) { lighted_nodes.insert(n2pos, true); } /* If the neighbor is dimmer than how much light this node would spread on it, add to list */ if(light2 < newlight) { if(nodemgr->get(n2).light_propagates) { n2.setLight(bank, newlight, nodemgr); lighted_nodes.insert(n2pos, true); } } } catch(InvalidPositionException &e) { continue; } } } /*dstream<<"spreadLight(): Changed block " <<blockchangecount<<" times" <<" for "<<from_nodes.size()<<" nodes" <<std::endl;*/ if(lighted_nodes.size() > 0) spreadLight(bank, lighted_nodes, nodemgr);}
开发者ID:Anchakor,项目名称:minetest,代码行数:92,
示例9: getPosRelative/* Propagates sunlight down through the block. Doesn't modify nodes that are not affected by sunlight. Returns false if sunlight at bottom block is invalid. Returns true if sunlight at bottom block is valid. Returns true if bottom block doesn't exist. If there is a block above, continues from it. If there is no block above, assumes there is sunlight, unless is_underground is set or highest node is water. All sunlighted nodes are added to light_sources. if remove_light==true, sets non-sunlighted nodes black. if black_air_left!=NULL, it is set to true if non-sunlighted air is left in block.*/bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources, bool remove_light, bool *black_air_left){ INodeDefManager *nodemgr = m_gamedef->ndef(); // Whether the sunlight at the top of the bottom block is valid bool block_below_is_valid = true; v3s16 pos_relative = getPosRelative(); for(s16 x=0; x<MAP_BLOCKSIZE; x++) { for(s16 z=0; z<MAP_BLOCKSIZE; z++) {#if 1 bool no_sunlight = false; //bool no_top_block = false; // Check if node above block has sunlight bool is_valid_position; MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z), &is_valid_position); if (is_valid_position) { if(n.getContent() == CONTENT_IGNORE) { // Trust heuristics no_sunlight = is_underground; } else if(n.getLight(LIGHTBANK_DAY, m_gamedef->ndef()) != LIGHT_SUN) { no_sunlight = true; } } else { //no_top_block = true; // NOTE: This makes over-ground roofed places sunlighted // Assume sunlight, unless is_underground==true if(is_underground) { no_sunlight = true; } else { MapNode n = getNodeNoEx(v3s16(x, MAP_BLOCKSIZE-1, z)); if(m_gamedef->ndef()->get(n).sunlight_propagates == false) { no_sunlight = true; } } // NOTE: As of now, this just would make everything dark. // No sunlight here //no_sunlight = true; }#endif#if 0 // Doesn't work; nothing gets light. bool no_sunlight = true; bool no_top_block = false; // Check if node above block has sunlight try { MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z)); if(n.getLight(LIGHTBANK_DAY) == LIGHT_SUN) { no_sunlight = false; } } catch(InvalidPositionException &e) { no_top_block = true; }#endif /*std::cout<<"("<<x<<","<<z<<"): " <<"no_top_block="<<no_top_block <<", is_underground="<<is_underground <<", no_sunlight="<<no_sunlight <<std::endl;*///.........这里部分代码省略.........
开发者ID:TriBlade9,项目名称:minetest,代码行数:101,
示例10: was/* Goes recursively through the neighbours of the node. Alters only transparent nodes. If the lighting of the neighbour is lower than the lighting of the node was (before changing it to 0 at the step before), the lighting of the neighbour is set to 0 and then the same stuff repeats for the neighbour. The ending nodes of the routine are stored in light_sources. This is useful when a light is removed. In such case, this routine can be called for the light node and then again for light_sources to re-light the area without the removed light. values of from_nodes are lighting values.*/void VoxelManipulator::unspreadLight(enum LightBank bank, core::map<v3s16, u8> & from_nodes, core::map<v3s16, bool> & light_sources){ v3s16 dirs[6] = { v3s16(0,0,1), // back v3s16(0,1,0), // top v3s16(1,0,0), // right v3s16(0,0,-1), // front v3s16(0,-1,0), // bottom v3s16(-1,0,0), // left }; if(from_nodes.size() == 0) return; core::map<v3s16, u8> unlighted_nodes; core::map<v3s16, u8>::Iterator j; j = from_nodes.getIterator(); for(; j.atEnd() == false; j++) { v3s16 pos = j.getNode()->getKey(); emerge(VoxelArea(pos - v3s16(1,1,1), pos + v3s16(1,1,1))); //MapNode &n = m_data[m_area.index(pos)]; u8 oldlight = j.getNode()->getValue(); // Loop through 6 neighbors for(u16 i=0; i<6; i++) { // Get the position of the neighbor node v3s16 n2pos = pos + dirs[i]; u32 n2i = m_area.index(n2pos); if(m_flags[n2i] & VOXELFLAG_INEXISTENT) continue; MapNode &n2 = m_data[n2i]; /* If the neighbor is dimmer than what was specified as oldlight (the light of the previous node) */ if(n2.getLight(bank, nodemgr) < oldlight) { /* And the neighbor is transparent and it has some light */ if(nodemgr->get(n2).light_propagates && n2.getLight(bank, nodemgr) != 0) { /* Set light to 0 and add to queue */ u8 current_light = n2.getLight(bank, nodemgr); n2.setLight(bank, 0); unlighted_nodes.insert(n2pos, current_light); /* Remove from light_sources if it is there NOTE: This doesn't happen nearly at all */ /*if(light_sources.find(n2pos)) { std::cout<<"Removed from light_sources"<<std::endl; light_sources.remove(n2pos); }*/ } } else{ light_sources.insert(n2pos, true); } } } /*dstream<<"unspreadLight(): Changed block " <<blockchangecount<<" times" <<" for "<<from_nodes.size()<<" nodes"//.........这里部分代码省略.........
开发者ID:Anchakor,项目名称:minetest,代码行数:101,
示例11: timervoid VoxelManipulator::addArea(VoxelArea area){ // Cancel if requested area has zero volume if(area.getExtent() == v3s16(0,0,0)) return; // Cancel if m_area already contains the requested area if(m_area.contains(area)) return; TimeTaker timer("addArea", &addarea_time); // Calculate new area VoxelArea new_area; // New area is the requested area if m_area has zero volume if(m_area.getExtent() == v3s16(0,0,0)) { new_area = area; } // Else add requested area to m_area else { new_area = m_area; new_area.addArea(area); } s32 new_size = new_area.getVolume(); /*dstream<<"adding area "; area.print(dstream); dstream<<", old area "; m_area.print(dstream); dstream<<", new area "; new_area.print(dstream); dstream<<", new_size="<<new_size; dstream<<std::endl;*/ // Allocate and clear new data MapNode *new_data = new MapNode[new_size]; u8 *new_flags = new u8[new_size]; for(s32 i=0; i<new_size; i++) { new_flags[i] = VOXELFLAG_NOT_LOADED; } // Copy old data for(s32 z=m_area.MinEdge.Z; z<=m_area.MaxEdge.Z; z++) for(s32 y=m_area.MinEdge.Y; y<=m_area.MaxEdge.Y; y++) for(s32 x=m_area.MinEdge.X; x<=m_area.MaxEdge.X; x++) { // If loaded, copy data and flags if((m_flags[m_area.index(x,y,z)] & VOXELFLAG_NOT_LOADED) == false) { new_data[new_area.index(x,y,z)] = m_data[m_area.index(x,y,z)]; new_flags[new_area.index(x,y,z)] = m_flags[m_area.index(x,y,z)]; } } // Replace area, data and flags m_area = new_area; MapNode *old_data = m_data; u8 *old_flags = m_flags; /*dstream<<"old_data="<<(int)old_data<<", new_data="<<(int)new_data <<", old_flags="<<(int)m_flags<<", new_flags="<<(int)new_flags<<std::endl;*/ m_data = new_data; m_flags = new_flags; if(old_data) delete[] old_data; if(old_flags) delete[] old_flags; //dstream<<"addArea done"<<std::endl;}
开发者ID:Anchakor,项目名称:minetest,代码行数:79,
示例12: assertvoid MapgenV6::makeChunk(BlockMakeData *data) { assert(data->vmanip); assert(data->nodedef); assert(data->blockpos_requested.X >= data->blockpos_min.X && data->blockpos_requested.Y >= data->blockpos_min.Y && data->blockpos_requested.Z >= data->blockpos_min.Z); assert(data->blockpos_requested.X <= data->blockpos_max.X && data->blockpos_requested.Y <= data->blockpos_max.Y && data->blockpos_requested.Z <= data->blockpos_max.Z); this->generating = true; this->vm = data->vmanip; this->ndef = data->nodedef; // Hack: use minimum block coords for old code that assumes a single block v3s16 blockpos = data->blockpos_requested; v3s16 blockpos_min = data->blockpos_min; v3s16 blockpos_max = data->blockpos_max; // Area of central chunk node_min = blockpos_min*MAP_BLOCKSIZE; node_max = (blockpos_max+v3s16(1,1,1))*MAP_BLOCKSIZE-v3s16(1,1,1); // Full allocated area full_node_min = (blockpos_min-1)*MAP_BLOCKSIZE; full_node_max = (blockpos_max+2)*MAP_BLOCKSIZE-v3s16(1,1,1); central_area_size = node_max - node_min + v3s16(1,1,1); assert(central_area_size.X == central_area_size.Z); int volume_blocks = (blockpos_max.X - blockpos_min.X + 1) * (blockpos_max.Y - blockpos_min.Y + 1) * (blockpos_max.Z - blockpos_max.Z + 1); volume_nodes = volume_blocks * MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE; // Create a block-specific seed blockseed = get_blockseed(data->seed, full_node_min); // Make some noise calculateNoise(); c_stone = ndef->getId("mapgen_stone"); c_dirt = ndef->getId("mapgen_dirt"); c_dirt_with_grass = ndef->getId("mapgen_dirt_with_grass"); c_sand = ndef->getId("mapgen_sand"); c_water_source = ndef->getId("mapgen_water_source"); c_lava_source = ndef->getId("mapgen_lava_source"); c_gravel = ndef->getId("mapgen_gravel"); c_cobble = ndef->getId("mapgen_cobble"); c_desert_sand = ndef->getId("mapgen_desert_sand"); c_desert_stone = ndef->getId("mapgen_desert_stone"); c_mossycobble = ndef->getId("mapgen_mossycobble"); c_sandbrick = ndef->getId("mapgen_sandstonebrick"); c_stair_cobble = ndef->getId("mapgen_stair_cobble"); c_stair_sandstone = ndef->getId("mapgen_stair_sandstone"); if (c_desert_sand == CONTENT_IGNORE) c_desert_sand = c_sand; if (c_desert_stone == CONTENT_IGNORE) c_desert_stone = c_stone; if (c_mossycobble == CONTENT_IGNORE) c_mossycobble = c_cobble; if (c_sandbrick == CONTENT_IGNORE) c_sandbrick = c_desert_stone; if (c_stair_cobble == CONTENT_IGNORE) c_stair_cobble = c_cobble; if (c_stair_sandstone == CONTENT_IGNORE) c_stair_sandstone = c_sandbrick; // Maximum height of the stone surface and obstacles. // This is used to guide the cave generation s16 stone_surface_max_y; // Generate general ground level to full area stone_surface_max_y = generateGround(); generateExperimental(); const s16 max_spread_amount = MAP_BLOCKSIZE; // Limit dirt flow area by 1 because mud is flown into neighbors. s16 mudflow_minpos = -max_spread_amount + 1; s16 mudflow_maxpos = central_area_size.X + max_spread_amount - 2; // Loop this part, it will make stuff look older and newer nicely const u32 age_loops = 2; for (u32 i_age = 0; i_age < age_loops; i_age++) { // Aging loop // Make caves (this code is relatively horrible) if (flags & MG_CAVES) generateCaves(stone_surface_max_y); // Add mud to the central chunk addMud(); // Add blobs of dirt and gravel underground addDirtGravelBlobs(); // Flow mud away from steep edges flowMud(mudflow_minpos, mudflow_maxpos);//.........这里部分代码省略.........
开发者ID:0151n,项目名称:minetest,代码行数:101,
示例13: intbool PathFinder::findPathHeuristic(v3s16 pos, std::vector <v3s16>& directions, unsigned int (*heuristicFunction)(v3s16, v3s16)){ std::multiset <OpenElement> q; used.clear(); q.insert(OpenElement(heuristicFunction(pos, m_destination), 0, pos, v3s16(0, 0, 0))); while(!q.empty()) { v3s16 current_pos = q.begin()->pos; v3s16 prev_pos = q.begin()->prev_pos; unsigned int current_cost = q.begin()->start_cost; q.erase(q.begin()); for(unsigned int i = 0; i < directions.size(); ++i) { v3s16 next_pos = current_pos + directions[i]; unsigned int next_cost = current_cost + getDirectionCost(i); // Check limits or already processed if((next_pos.X < m_limits.X.min) || (next_pos.X >= m_limits.X.max) || (next_pos.Z < m_limits.Z.min) || (next_pos.Z >= m_limits.Z.max)) { continue; } MapNode node_at_next_pos = m_env->getMap().getNodeNoEx(next_pos); if(node_at_next_pos.param0 == CONTENT_IGNORE) { continue; } if(node_at_next_pos.param0 == CONTENT_AIR) { MapNode node_below_next_pos = m_env->getMap().getNodeNoEx(next_pos + v3s16(0, -1, 0)); if(node_below_next_pos.param0 == CONTENT_IGNORE) { continue; } if(node_below_next_pos.param0 == CONTENT_AIR) { // Try jump down v3s16 test_pos = next_pos - v3s16(0, -1, 0); MapNode node_at_test_pos = m_env->getMap().getNodeNoEx(test_pos); while((node_at_test_pos.param0 == CONTENT_AIR) && (test_pos.Y > m_limits.Y.min)) { --test_pos.Y; node_at_test_pos = m_env->getMap().getNodeNoEx(test_pos); } ++test_pos.Y; if((test_pos.Y >= m_limits.Y.min) && (node_at_test_pos.param0 != CONTENT_IGNORE) && (node_at_test_pos.param0 != CONTENT_AIR) && ((next_pos.Y - test_pos.Y) <= m_maxdrop)) { next_pos.Y = test_pos.Y; next_cost = current_cost + getDirectionCost(i) * 2; } else { continue; } } } else { // Try jump up v3s16 test_pos = next_pos; MapNode node_at_test_pos = m_env->getMap().getNodeNoEx(test_pos); while((node_at_test_pos.param0 != CONTENT_IGNORE) && (node_at_test_pos.param0 != CONTENT_AIR) && (test_pos.Y < m_limits.Y.max)) { ++test_pos.Y; node_at_test_pos = m_env->getMap().getNodeNoEx(test_pos); } // Did we find surface? if((test_pos.Y <= m_limits.Y.max) && (node_at_test_pos.param0 == CONTENT_AIR) && (test_pos.Y - next_pos.Y <= m_maxjump)) { next_pos.Y = test_pos.Y; next_cost = current_cost + getDirectionCost(i) * 2; } else { continue; } } if((used.find(next_pos) == used.end()) || (used[next_pos].second > next_cost)) { used[next_pos].first = current_pos; used[next_pos].second = next_cost; q.insert(OpenElement(next_cost + heuristicFunction(next_pos, m_destination), next_cost, next_pos, current_pos)); } } if(current_pos == m_destination) { return true; } } return (used.find(m_destination) != used.end());}
开发者ID:Nate-Devv,项目名称:freeminer,代码行数:97,
示例14: getSmoothLight/* Calculate smooth lighting at the XYZ- corner of p. Single light bank.*/static u8 getSmoothLight(enum LightBank bank, v3s16 p, MeshMakeData *data){ static v3s16 dirs8[8] = { v3s16(0,0,0), v3s16(0,0,1), v3s16(0,1,0), v3s16(0,1,1), v3s16(1,0,0), v3s16(1,1,0), v3s16(1,0,1), v3s16(1,1,1), }; INodeDefManager *ndef = data->m_gamedef->ndef(); u16 ambient_occlusion = 0; u16 light = 0; u16 light_count = 0; u8 light_source_max = 0; for(u32 i=0; i<8; i++) { MapNode n = data->m_vmanip.getNodeNoEx(p - dirs8[i]); if (n.getContent() == CONTENT_IGNORE) { ambient_occlusion++; continue; } const ContentFeatures &f = ndef->get(n); if(f.light_source > light_source_max) light_source_max = f.light_source; // Check f.solidness because fast-style leaves look // better this way if(f.param_type == CPT_LIGHT && f.solidness != 2) { light += decode_light(n.getLight(bank, ndef)); light_count++; } } if(light_count == 0) return 255; light /= light_count; // Boost brightness around light sources if(decode_light(light_source_max) >= light) //return decode_light(undiminish_light(light_source_max)); return decode_light(light_source_max); if(ambient_occlusion > 4) { //ambient_occlusion -= 4; //light = (float)light / ((float)ambient_occlusion * 0.5 + 1.0); float light_amount = (8 - ambient_occlusion) / 4.0; float light_f = (float)light / 255.0; light_f = pow(light_f, 2.2f); // gamma -> linear space light_f = light_f * light_amount; light_f = pow(light_f, 1.0f/2.2f); // linear -> gamma space if(light_f > 1.0) light_f = 1.0; light = 255.0 * light_f + 0.5; } return light;}
开发者ID:iamnerotic,项目名称:minetest,代码行数:70,
示例15: getPositionvoid LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, std::vector<CollisionInfo> *collision_info){ Map *map = &env->getMap(); INodeDefManager *nodemgr = m_gamedef->ndef(); v3f position = getPosition(); // Copy parent position if local player is attached if(isAttached) { setPosition(overridePosition); m_sneak_node_exists = false; return; } // Skip collision detection if noclip mode is used bool fly_allowed = m_gamedef->checkLocalPrivilege("fly"); bool noclip = m_gamedef->checkLocalPrivilege("noclip") && g_settings->getBool("noclip"); bool free_move = noclip && fly_allowed && g_settings->getBool("free_move"); if (free_move) { position += m_speed * dtime; setPosition(position); m_sneak_node_exists = false; return; } /* Collision detection */ bool is_valid_position; MapNode node; v3s16 pp; /* Check if player is in liquid (the oscillating value) */ // If in liquid, the threshold of coming out is at higher y if (in_liquid) { pp = floatToInt(position + v3f(0,BS*0.1,0), BS); node = map->getNodeNoEx(pp, &is_valid_position); if (is_valid_position) { in_liquid = nodemgr->get(node.getContent()).isLiquid(); liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity; } else { in_liquid = false; } } // If not in liquid, the threshold of going in is at lower y else { pp = floatToInt(position + v3f(0,BS*0.5,0), BS); node = map->getNodeNoEx(pp, &is_valid_position); if (is_valid_position) { in_liquid = nodemgr->get(node.getContent()).isLiquid(); liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity; } else { in_liquid = false; } } /* Check if player is in liquid (the stable value) */ pp = floatToInt(position + v3f(0,0,0), BS); node = map->getNodeNoEx(pp, &is_valid_position); if (is_valid_position) { in_liquid_stable = nodemgr->get(node.getContent()).isLiquid(); } else { in_liquid_stable = false; } /* Check if player is climbing */ pp = floatToInt(position + v3f(0,0.5*BS,0), BS); v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS); node = map->getNodeNoEx(pp, &is_valid_position); bool is_valid_position2; MapNode node2 = map->getNodeNoEx(pp2, &is_valid_position2); if (!(is_valid_position && is_valid_position2)) { is_climbing = false; } else { is_climbing = (nodemgr->get(node.getContent()).climbable || nodemgr->get(node2.getContent()).climbable) && !free_move; } /* Collision uncertainty radius Make it a bit larger than the maximum distance of movement *///.........这里部分代码省略.........
开发者ID:Calinou,项目名称:minetest,代码行数:101,
示例16: setExtrudedvoid WieldMeshSceneNode::setItem(const ItemStack &item, IGameDef *gamedef){ ITextureSource *tsrc = gamedef->getTextureSource(); IItemDefManager *idef = gamedef->getItemDefManager(); //IShaderSource *shdrsrc = gamedef->getShaderSource(); INodeDefManager *ndef = gamedef->getNodeDefManager(); const ItemDefinition &def = item.getDefinition(idef); const ContentFeatures &f = ndef->get(def.name); content_t id = ndef->getId(def.name);#if 0//// TODO(RealBadAngel): Reactivate when shader is added for wield items if (m_enable_shaders) { u32 shader_id = shdrsrc->getShader("nodes_shader", TILE_MATERIAL_BASIC, NDT_NORMAL); m_material_type = shdrsrc->getShaderInfo(shader_id).material; }#endif // If wield_image is defined, it overrides everything else if (def.wield_image != "") { setExtruded(def.wield_image, def.wield_scale, tsrc, 1); return; } // Handle nodes // See also CItemDefManager::createClientCached() else if (def.type == ITEM_NODE) { if (f.mesh_ptr[0]) { // e.g. mesh nodes and nodeboxes changeToMesh(f.mesh_ptr[0]); // mesh_ptr[0] is pre-scaled by BS * f->visual_scale m_meshnode->setScale( def.wield_scale * WIELD_SCALE_FACTOR / (BS * f.visual_scale)); } else if (f.drawtype == NDT_AIRLIKE) { changeToMesh(NULL); } else if (f.drawtype == NDT_PLANTLIKE) { setExtruded(tsrc->getTextureName(f.tiles[0].texture_id), def.wield_scale, tsrc, f.tiles[0].animation_frame_count); } else if (f.drawtype == NDT_NORMAL || f.drawtype == NDT_ALLFACES) { setCube(f.tiles, def.wield_scale, tsrc); } else { //// TODO: Change false in the following constructor args to //// appropriate value when shader is added for wield items (if applicable) MeshMakeData mesh_make_data(gamedef, false); MapNode mesh_make_node(id, 255, 0); mesh_make_data.fillSingleNode(&mesh_make_node); MapBlockMesh mapblock_mesh(&mesh_make_data, v3s16(0, 0, 0)); changeToMesh(mapblock_mesh.getMesh()); translateMesh(m_meshnode->getMesh(), v3f(-BS, -BS, -BS)); m_meshnode->setScale( def.wield_scale * WIELD_SCALE_FACTOR / (BS * f.visual_scale)); } u32 material_count = m_meshnode->getMaterialCount(); if (material_count > 6) { errorstream << "WieldMeshSceneNode::setItem: Invalid material " "count " << material_count << ", truncating to 6" << std::endl; material_count = 6; } for (u32 i = 0; i < material_count; ++i) { video::SMaterial &material = m_meshnode->getMaterial(i); material.setFlag(video::EMF_BACK_FACE_CULLING, true); material.setFlag(video::EMF_BILINEAR_FILTER, m_bilinear_filter); material.setFlag(video::EMF_TRILINEAR_FILTER, m_trilinear_filter); bool animated = (f.tiles[i].animation_frame_count > 1); if (animated) { FrameSpec animation_frame = f.tiles[i].frames[0]; material.setTexture(0, animation_frame.texture); } else { material.setTexture(0, f.tiles[i].texture); } material.MaterialType = m_material_type;#if 0//// TODO(RealBadAngel): Reactivate when shader is added for wield items if (m_enable_shaders) { if (f.tiles[i].normal_texture) { if (animated) { FrameSpec animation_frame = f.tiles[i].frames[0]; material.setTexture(1, animation_frame.normal_texture); } else { material.setTexture(1, f.tiles[i].normal_texture); } material.setTexture(2, tsrc->getTexture("enable_img.png")); } else { material.setTexture(2, tsrc->getTexture("disable_img.png")); } }#endif } return; } else if (def.inventory_image != "") { setExtruded(def.inventory_image, def.wield_scale, tsrc, 1); return; } // no wield mesh found changeToMesh(NULL);}
开发者ID:DaErHuo,项目名称:minetest,代码行数:98,
示例17: assertvoid MapgenValleys::makeChunk(BlockMakeData *data){ // Pre-conditions assert(data->vmanip); assert(data->nodedef); assert(data->blockpos_requested.X >= data->blockpos_min.X && data->blockpos_requested.Y >= data->blockpos_min.Y && data->blockpos_requested.Z >= data->blockpos_min.Z); assert(data->blockpos_requested.X <= data->blockpos_max.X && data->blockpos_requested.Y <= data->blockpos_max.Y && data->blockpos_requested.Z <= data->blockpos_max.Z); this->generating = true; this->vm = data->vmanip; this->ndef = data->nodedef; //TimeTaker t("makeChunk"); v3s16 blockpos_min = data->blockpos_min; v3s16 blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); // Generate noise maps and base terrain height. calculateNoise(); // Generate base terrain with initial heightmaps s16 stone_surface_max_y = generateTerrain(); // Create biomemap at heightmap surface bmgr->calcBiomes(csize.X, csize.Z, heatmap, humidmap, heightmap, biomemap); // Actually place the biome-specific nodes MgStoneType stone_type = generateBiomes(heatmap, humidmap); // Cave creation. if (flags & MG_CAVES) generateCaves(stone_surface_max_y); // Dungeon creation if ((flags & MG_DUNGEONS) && node_max.Y < 50 && (stone_surface_max_y >= node_min.Y)) { DungeonParams dp; dp.np_rarity = nparams_dungeon_rarity; dp.np_density = nparams_dungeon_density; dp.np_wetness = nparams_dungeon_wetness; dp.c_water = c_water_source; if (stone_type == STONE) { dp.c_cobble = c_cobble; dp.c_moss = c_mossycobble; dp.c_stair = c_stair_cobble; dp.diagonal_dirs = false; dp.mossratio = 3.f; dp.holesize = v3s16(1, 2, 1); dp.roomsize = v3s16(0, 0, 0); dp.notifytype = GENNOTIFY_DUNGEON; } else if (stone_type == DESERT_STONE) { dp.c_cobble = c_desert_stone; dp.c_moss = c_desert_stone; dp.c_stair = c_desert_stone; dp.diagonal_dirs = true; dp.mossratio = 0.f; dp.holesize = v3s16(2, 3, 2); dp.roomsize = v3s16(2, 5, 2); dp.notifytype = GENNOTIFY_TEMPLE; } else if (stone_type == SANDSTONE) { dp.c_cobble = c_sandstonebrick; dp.c_moss = c_sandstonebrick; dp.c_stair = c_sandstonebrick; dp.diagonal_dirs = false; dp.mossratio = 0.f; dp.holesize = v3s16(2, 2, 2); dp.roomsize = v3s16(2, 0, 2); dp.notifytype = GENNOTIFY_DUNGEON; } DungeonGen dgen(this, &dp); dgen.generate(blockseed, full_node_min, full_node_max); } // Generate the registered decorations if (flags & MG_DECORATIONS) m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max); // Generate the registered ores m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max); // Sprinkle some dust on top after everything else was generated dustTopNodes(); //TimeTaker tll("liquid_lighting"); updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);//.........这里部分代码省略.........
开发者ID:OverloadedWolf,项目名称:minetest,代码行数:101,
示例18: farscalevoid DungeonGen::makeDungeon(v3s16 start_padding){ v3s16 areasize = vm->m_area.getExtent(); v3s16 roomsize; v3s16 roomplace; float far_multi = farscale(5, vm->m_area.MinEdge.X, vm->m_area.MinEdge.Y, vm->m_area.MinEdge.Z); /* Find place for first room */ bool fits = false; for (u32 i = 0; i < 100 && !fits; i++) { bool is_large_room = ((random.next() & 3) == 1); roomsize = is_large_room ? v3s16(random.range(8, 16 * far_multi), random.range(8, 16 * far_multi), random.range(8, 16 * far_multi)) : v3s16(random.range(4, 8 * far_multi), random.range(4, 6 * far_multi), random.range(4, 8 * far_multi)); roomsize += dp.roomsize; // start_padding is used to disallow starting the generation of // a dungeon in a neighboring generation chunk roomplace = vm->m_area.MinEdge + start_padding + v3s16( random.range(0, areasize.X - roomsize.X - start_padding.X), random.range(0, areasize.Y - roomsize.Y - start_padding.Y), random.range(0, areasize.Z - roomsize.Z - start_padding.Z)); /* Check that we're not putting the room to an unknown place, otherwise it might end up floating in the air */ fits = true; for (s16 z = 0; z < roomsize.Z; z++) for (s16 y = 0; y < roomsize.Y; y++) for (s16 x = 0; x < roomsize.X; x++) { v3s16 p = roomplace + v3s16(x, y, z); u32 vi = vm->m_area.index(p); if ((vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) || vm->m_data[vi].getContent() == CONTENT_IGNORE) { fits = false; break; } } } // No place found if (fits == false) return; /* Stores the center position of the last room made, so that a new corridor can be started from the last room instead of the new room, if chosen so. */ v3s16 last_room_center = roomplace + v3s16(roomsize.X / 2, 1, roomsize.Z / 2); u32 room_count = random.range(2, random.range(8, 16 * far_multi)); for (u32 i = 0; i < room_count; i++) { // Make a room to the determined place makeRoom(roomsize, roomplace); v3s16 room_center = roomplace + v3s16(roomsize.X / 2, 1, roomsize.Z / 2); mg->gennotify.addEvent(dp.notifytype, room_center);#ifdef DGEN_USE_TORCHES // Place torch at room center (for testing) vm->m_data[vm->m_area.index(room_center)] = MapNode(c_torch);#endif // Quit if last room if (i == room_count - 1) break; // Determine walker start position bool start_in_last_room = (random.range(0, 2) != 0); v3s16 walker_start_place; if (start_in_last_room) { walker_start_place = last_room_center; } else { walker_start_place = room_center; // Store center of current room as the last one last_room_center = room_center; } // Create walker and find a place for a door v3s16 doorplace; v3s16 doordir; m_pos = walker_start_place; if (!findPlaceForDoor(doorplace, doordir)) return; if (random.range(0, 1) == 0) // Make the door makeDoor(doorplace, doordir); else // Don't actually make a door doorplace -= doordir;//.........这里部分代码省略.........
开发者ID:Mab879,项目名称:freeminer,代码行数:101,
示例19: v2s16void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos){ // 340ms @cs=8 //TimeTaker timer1("flow mud"); // Iterate a few times for (s16 k = 0; k < 3; k++) { for (s16 z = mudflow_minpos; z <= mudflow_maxpos; z++) for (s16 x = mudflow_minpos; x <= mudflow_maxpos; x++) { // Invert coordinates every 2nd iteration if (k % 2 == 0) { x = mudflow_maxpos - (x - mudflow_minpos); z = mudflow_maxpos - (z - mudflow_minpos); } // Node position in 2d v2s16 p2d = v2s16(node_min.X, node_min.Z) + v2s16(x, z); v3s16 em = vm->m_area.getExtent(); u32 i = vm->m_area.index(p2d.X, node_max.Y, p2d.Y); s16 y = node_max.Y; while (y >= node_min.Y) { for (;; y--) { MapNode *n = NULL; // Find mud for (; y >= node_min.Y; y--) { n = &vm->m_data[i]; if (n->getContent() == c_dirt || n->getContent() == c_dirt_with_grass || n->getContent() == c_gravel) break; vm->m_area.add_y(em, i, -1); } // Stop if out of area //if(vmanip.m_area.contains(i) == false) if (y < node_min.Y) break; if (n->getContent() == c_dirt || n->getContent() == c_dirt_with_grass) { // Make it exactly mud n->setContent(c_dirt); // Don't flow it if the stuff under it is not mud { u32 i2 = i; vm->m_area.add_y(em, i2, -1); // Cancel if out of area if (vm->m_area.contains(i2) == false) continue; MapNode *n2 = &vm->m_data[i2]; if (n2->getContent() != c_dirt && n2->getContent() != c_dirt_with_grass) continue; } } v3s16 dirs4[4] = { v3s16(0, 0, 1), // back v3s16(1, 0, 0), // right v3s16(0, 0, -1), // front v3s16(-1, 0, 0), // left }; // Check that upper is air or doesn't exist. // Cancel dropping if upper keeps it in place u32 i3 = i; vm->m_area.add_y(em, i3, 1); if (vm->m_area.contains(i3) == true && ndef->get(vm->m_data[i3]).walkable) continue; // Drop mud on side for (u32 di = 0; di < 4; di++) { v3s16 dirp = dirs4[di]; u32 i2 = i; // Move to side vm->m_area.add_p(em, i2, dirp); // Fail if out of area if (vm->m_area.contains(i2) == false) continue; // Check that side is air MapNode *n2 = &vm->m_data[i2]; if (ndef->get(*n2).walkable) continue; // Check that under side is air vm->m_area.add_y(em, i2, -1); if (vm->m_area.contains(i2) == false) continue; n2 = &vm->m_data[i2]; if (ndef->get(*n2).walkable) continue; // Loop further down until not air bool dropped_to_unknown = false; do { vm->m_area.add_y(em, i2, -1);//.........这里部分代码省略.........
开发者ID:alexxvk,项目名称:freeminer,代码行数:101,
示例20: n_cobblevoid DungeonGen::makeRoom(v3s16 roomsize, v3s16 roomplace){ MapNode n_cobble(dp.c_cobble); MapNode n_air(CONTENT_AIR); // Make +-X walls for (s16 z = 0; z < roomsize.Z; z++) for (s16 y = 0; y < roomsize.Y; y++) { { v3s16 p = roomplace + v3s16(0, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_cobble; } { v3s16 p = roomplace + v3s16(roomsize.X - 1, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_cobble; } } // Make +-Z walls for (s16 x = 0; x < roomsize.X; x++) for (s16 y = 0; y < roomsize.Y; y++) { { v3s16 p = roomplace + v3s16(x, y, 0); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_cobble; } { v3s16 p = roomplace + v3s16(x, y, roomsize.Z - 1); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_cobble; } } // Make +-Y walls (floor and ceiling) for (s16 z = 0; z < roomsize.Z; z++) for (s16 x = 0; x < roomsize.X; x++) { { v3s16 p = roomplace + v3s16(x, 0, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_cobble; } { v3s16 p = roomplace + v3s16(x,roomsize. Y - 1, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); if (vm->m_flags[vi] & VMANIP_FLAG_DUNGEON_UNTOUCHABLE) continue; vm->m_data[vi] = n_cobble; } } // Fill with air for (s16 z = 1; z < roomsize.Z - 1; z++) for (s16 y = 1; y < roomsize.Y - 1; y++) for (s16 x = 1; x < roomsize.X - 1; x++) { v3s16 p = roomplace + v3s16(x, y, z); if (!vm->m_area.contains(p)) continue; u32 vi = vm->m_area.index(p); vm->m_flags[vi] |= VMANIP_FLAG_DUNGEON_UNTOUCHABLE; vm->m_data[vi] = n_air; }}
开发者ID:Mab879,项目名称:freeminer,代码行数:86,
示例21: getSmoothLightCombined/* Calculate smooth lighting at the XYZ- corner of p. Both light banks*/static u16 getSmoothLightCombined(v3s16 p, MeshMakeData *data){ static const v3s16 dirs8[8] = { v3s16(0,0,0), v3s16(0,0,1), v3s16(0,1,0), v3s16(0,1,1), v3s16(1,0,0), v3s16(1,1,0), v3s16(1,0,1), v3s16(1,1,1), }; INodeDefManager *ndef = data->m_gamedef->ndef(); u16 ambient_occlusion = 0; u16 light_count = 0; u8 light_source_max = 0; u16 light_day = 0; u16 light_night = 0; for (u32 i = 0; i < 8; i++) { const MapNode &n = data->m_vmanip.getNodeRefUnsafeCheckFlags(p - dirs8[i]); // if it's CONTENT_IGNORE we can't do any light calculations if (n.getContent() == CONTENT_IGNORE) { continue; } const ContentFeatures &f = ndef->get(n); if (f.light_source > light_source_max) light_source_max = f.light_source; // Check f.solidness because fast-style leaves look better this way if (f.param_type == CPT_LIGHT && f.solidness != 2) { light_day += decode_light(n.getLightNoChecks(LIGHTBANK_DAY, &f)); light_night += decode_light(n.getLightNoChecks(LIGHTBANK_NIGHT, &f)); light_count++; } else { ambient_occlusion++; } } if(light_count == 0) return 0xffff; light_day /= light_count; light_night /= light_count; // Boost brightness around light sources bool skip_ambient_occlusion_day = false; if(decode_light(light_source_max) >= light_day) { light_day = decode_light(light_source_max); skip_ambient_occlusion_day = true; } bool skip_ambient_occlusion_night = false; if(decode_light(light_source_max) >= light_night) { light_night = decode_light(light_source_max); skip_ambient_occlusion_night = true; } if (ambient_occlusion > 4) { static const float ao_gamma = rangelim( g_settings->getFloat("ambient_occlusion_gamma"), 0.25, 4.0); // Table of gamma space multiply factors. static const float light_amount[3] = { powf(0.75, 1.0 / ao_gamma), powf(0.5, 1.0 / ao_gamma), powf(0.25, 1.0 / ao_gamma) }; //calculate table index for gamma space multiplier ambient_occlusion -= 5; if (!skip_ambient_occlusion_day) light_day = rangelim(core::round32(light_day*light_amount[ambient_occlusion]), 0, 255); if (!skip_ambient_occlusion_night) light_night = rangelim(core::round32(light_night*light_amount[ambient_occlusion]), 0, 255); } return light_day | (light_night << 8);}
开发者ID:4aiman,项目名称:MultiCraft,代码行数:89,
示例22: makeHolevoid DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, v3s16 &result_place, v3s16 &result_dir){ makeHole(doorplace); v3s16 p0 = doorplace; v3s16 dir = doordir; u32 length; /*if (random.next() % 2) length = random.range(1, 13); else length = random.range(1, 6);*/ length = random.range(1, 13); u32 partlength = random.range(1, 13); u32 partcount = 0; s16 make_stairs = 0; if (random.next() % 2 == 0 && partlength >= 3) make_stairs = random.next() % 2 ? 1 : -1; for (u32 i = 0; i < length; i++) { v3s16 p = p0 + dir; if (partcount != 0) p.Y += make_stairs; if (vm->m_area.contains(p) && vm->m_area.contains(p + v3s16(0, 1, 0)) && vm->m_area.contains(v3s16(p.X - dir.X, p.Y - 1, p.Z - dir.Z))) { if (make_stairs) { makeFill(p + v3s16(-1, -1, -1), dp.holesize + v3s16(2, 3, 2), VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(dp.c_cobble), 0); makeHole(p); makeHole(p - dir); // TODO: fix stairs code so it works 100% // (quite difficult) // exclude stairs from the bottom step // exclude stairs from diagonal steps if (((dir.X ^ dir.Z) & 1) && (((make_stairs == 1) && i != 0) || ((make_stairs == -1) && i != length - 1))) { // rotate face 180 deg if // making stairs backwards int facedir = dir_to_facedir(dir * make_stairs); u32 vi = vm->m_area.index(p.X - dir.X, p.Y - 1, p.Z - dir.Z); if (vm->m_data[vi].getContent() == dp.c_cobble) vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); vi = vm->m_area.index(p.X, p.Y, p.Z); if (vm->m_data[vi].getContent() == dp.c_cobble) vm->m_data[vi] = MapNode(dp.c_stair, 0, facedir); } } else { makeFill(p + v3s16(-1, -1, -1), dp.holesize + v3s16(2, 2, 2), VMANIP_FLAG_DUNGEON_UNTOUCHABLE, MapNode(dp.c_cobble), 0); makeHole(p); } p0 = p; } else { // Can't go here, turn away dir = turn_xz(dir, random.range(0, 1)); make_stairs = -make_stairs; partcount = 0; partlength = random.range(1, length); continue; } partcount++; if (partcount >= partlength) { partcount = 0; dir = random_turn(random, dir); partlength = random.range(1, length); make_stairs = 0; if (random.next() % 2 == 0 && partlength >= 3) make_stairs = random.next() % 2 ? 1 : -1; } } result_place = p0; result_dir = dir;}
开发者ID:Mab879,项目名称:freeminer,代码行数:90,
示例23: assertvoid MapgenValleys::makeChunk(BlockMakeData *data){ // Pre-conditions assert(data->vmanip); assert(data->nodedef); assert(data->blockpos_requested.X >= data->blockpos_min.X && data->blockpos_requested.Y >= data->blockpos_min.Y && data->blockpos_requested.Z >= data->blockpos_min.Z); assert(data->blockpos_requested.X <= data->blockpos_max.X && data->blockpos_requested.Y <= data->blockpos_max.Y && data->blockpos_requested.Z <= data->blockpos_max.Z); this->generating = true; this->vm = data->vmanip; this->ndef = data->nodedef; //TimeTaker t("makeChunk"); v3s16 blockpos_min = data->blockpos_min; v3s16 blockpos_max = data->blockpos_max; node_min = blockpos_min * MAP_BLOCKSIZE; node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE; full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1); blockseed = getBlockSeed2(full_node_min, seed); // Generate noise maps and base terrain height. calculateNoise(); // Generate biome noises. Note this must be executed strictly before // generateTerrain, because generateTerrain depends on intermediate // biome-related noises. m_bgen->calcBiomeNoise(node_min); // Generate base terrain with initial heightmaps s16 stone_surface_max_y = generateTerrain(); // Build biomemap m_bgen->getBiomes(heightmap); // Place biome-specific nodes MgStoneType stone_type = generateBiomes(); // Cave creation. if (flags & MG_CAVES) generateCaves(stone_surface_max_y, large_cave_depth); // Dungeon creation if ((flags & MG_DUNGEONS) && node_max.Y < 50) generateDungeons(stone_surface_max_y, stone_type); // Generate the registered decorations if (flags & MG_DECORATIONS) m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max); // Generate the registered ores m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max); // Sprinkle some dust on top after everything else was generated dustTopNodes(); //TimeTaker tll("liquid_lighting"); updateLiquid(&data->transforming_liquid, full_node_min, full_node_max); if (flags & MG_LIGHT) calcLighting( node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0), full_node_min, full_node_max); //mapgen_profiler->avg("liquid_lighting", tll.stop() / 1000.f); //mapgen_profiler->avg("makeChunk", t.stop() / 1000.f); this->generating = false;}
开发者ID:IAmRasputin,项目名称:minetest,代码行数:78,
示例24: findPlaceForDoorbool DungeonGen::findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace, v3s16 &result_doordir, v3s16 &result_roomplace){ for (s16 trycount = 0; trycount < 30; trycount++) { v3s16 doorplace; v3s16 doordir; bool r = findPlaceForDoor(doorplace, doordir); if (r == false) continue; v3s16 roomplace; // X east, Z north, Y up#if 1 if (doordir == v3s16(1, 0, 0)) // X+ roomplace = doorplace + v3s16(0, -1, random.range(-roomsize.Z + 2, -2)); if (doordir == v3s16(-1, 0, 0)) // X- roomplace = doorplace + v3s16(-roomsize.X + 1, -1, random.range(-roomsize.Z + 2, -2)); if (doordir == v3s16(0, 0, 1)) // Z+ roomplace = doorplace + v3s16(random.range(-roomsize.X + 2, -2), -1, 0); if (doordir == v3s16(0, 0, -1)) // Z- roomplace = doorplace + v3s16(random.range(-roomsize.X + 2, -2), -1, -roomsize.Z + 1);#endif#if 0 if (doordir == v3s16(1, 0, 0)) // X+ roomplace = doorplace + v3s16(0, -1, -roomsize.Z / 2); if (doordir == v3s16(-1, 0, 0)) // X- roomplace = doorplace + v3s16(-roomsize.X+1,-1,-roomsize.Z / 2); if (doordir == v3s16(0, 0, 1)) // Z+ roomplace = doorplace + v3s16(-roomsize.X / 2, -1, 0); if (doordir == v3s16(0, 0, -1)) // Z- roomplace = doorplace + v3s16(-roomsize.X / 2, -1, -roomsize.Z + 1);#endif // Check fit bool fits = true; for (s16 z = 1; z < roomsize.Z - 1; z++) for (s16 y = 1; y < roomsize.Y - 1; y++) for (s16 x = 1; x < roomsize.X - 1; x++) { v3s16 p = roomplace + v3s16(x, y, z); if (!vm->m_area.contains(p)) { fits = false; break; } if (vm->m_flags[vm->m_area.index(p)] & VMANIP_FLAG_DUNGEON_INSIDE) { fits = false; break; } } if (fits == false) { // Find new place continue; } result_doorplace = doorplace; result_doordir = doordir; result_roomplace = roomplace; return true; } return false;}
开发者ID:Mab879,项目名称:freeminer,代码行数:62,
示例25: m_searchdistancePathFinder::PathFinder() : m_searchdistance(0), m_maxdrop(0), m_maxjump(0), m_start(0,0,0), m_destination(0,0,0), m_limits(), m_env(0){ m_adjacency_4.push_back(v3s16(-1, 0, 0)); m_adjacency_4.push_back(v3s16(1, 0, 0)); m_adjacency_4.push_back(v3s16(0, 0, 1)); m_adjacency_4.push_back(v3s16(0, 0, -1)); m_adjacency_4_cost.push_back(1); m_adjacency_4_cost.push_back(1); m_adjacency_4_cost.push_back(1); m_adjacency_4_cost.push_back(1); m_adjacency_8.push_back(v3s16(-1, 0, 0)); m_adjacency_8.push_back(v3s16(1, 0, 0)); m_adjacency_8.push_back(v3s16(0, 0, 1)); m_adjacency_8.push_back(v3s16(0, 0, -1)); m_adjacency_8.push_back(v3s16(-1, 0, -1)); m_adjacency_8.push_back(v3s16(1, 0, -1)); m_adjacency_8.push_back(v3s16(-1, 0, 1)); m_adjacency_8.push_back(v3s16(1, 0, 1)); m_adjacency_8_cost.push_back(1); m_adjacency_8_cost.push_back(1); m_adjacency_8_cost.push_back(1); m_adjacency_8_cost.push_back(1); m_adjacency_8_cost.push_back(1); m_adjacency_8_cost.push_back(1); m_adjacency_8_cost.push_back(1); m_adjacency_8_cost.push_back(1);}
开发者ID:Nate-Devv,项目名称:freeminer,代码行数:37,
示例26: collisionMoveSimplecollisionMoveResult collisionMoveSimple(Map *map, IGameDef *gamedef, f32 pos_max_d, const core::aabbox3d<f32> &box_0, f32 dtime, v3f &pos_f, v3f &speed_f){ collisionMoveResult result; v3f oldpos_f = pos_f; v3s16 oldpos_i = floatToInt(oldpos_f, BS); /* Calculate new position */ pos_f += speed_f * dtime; /* Collision detection */ // position in nodes v3s16 pos_i = floatToInt(pos_f, BS); /* Collision uncertainty radius Make it a bit larger than the maximum distance of movement */ f32 d = pos_max_d * 1.1; // A fairly large value in here makes moving smoother //f32 d = 0.15*BS; // This should always apply, otherwise there are glitches assert(d > pos_max_d); /* Calculate collision box */ core::aabbox3d<f32> box = box_0; box.MaxEdge += pos_f; box.MinEdge += pos_f; core::aabbox3d<f32> oldbox = box_0; oldbox.MaxEdge += oldpos_f; oldbox.MinEdge += oldpos_f; /* If the object lies on a walkable node, this is set to true. */ result.touching_ground = false; /* Go through every node around the object */ s16 min_x = (box_0.MinEdge.X / BS) - 2; s16 min_y = (box_0.MinEdge.Y / BS) - 2; s16 min_z = (box_0.MinEdge.Z / BS) - 2; s16 max_x = (box_0.MaxEdge.X / BS) + 1; s16 max_y = (box_0.MaxEdge.Y / BS) + 1; s16 max_z = (box_0.MaxEdge.Z / BS) + 1; for(s16 y = oldpos_i.Y + min_y; y <= oldpos_i.Y + max_y; y++) for(s16 z = oldpos_i.Z + min_z; z <= oldpos_i.Z + max_z; z++) for(s16 x = oldpos_i.X + min_x; x <= oldpos_i.X + max_x; x++) { try{ // Object collides into walkable nodes MapNode n = map->getNode(v3s16(x,y,z)); if(gamedef->getNodeDefManager()->get(n).walkable == false) continue; } catch(InvalidPositionException &e) { // Doing nothing here will block the object from // walking over map borders } core::aabbox3d<f32> nodebox = getNodeBox(v3s16(x,y,z), BS); /* See if the object is touching ground. Object touches ground if object's minimum Y is near node's maximum Y and object's X-Z-area overlaps with the node's X-Z-area. Use 0.15*BS so that it is easier to get on a node. */ if( //fabs(nodebox.MaxEdge.Y-box.MinEdge.Y) < d fabs(nodebox.MaxEdge.Y-box.MinEdge.Y) < 0.15*BS && nodebox.MaxEdge.X-d > box.MinEdge.X && nodebox.MinEdge.X+d < box.MaxEdge.X && nodebox.MaxEdge.Z-d > box.MinEdge.Z && nodebox.MinEdge.Z+d < box.MaxEdge.Z ){ result.touching_ground = true; } // If object doesn't intersect with node, ignore node. if(box.intersectsWithBox(nodebox) == false) continue; /* Go through every axis//.........这里部分代码省略.........
开发者ID:Anchakor,项目名称:minetest,代码行数:101,
示例27: inline PathGridnode &Pathfinder::getIdxElem(s16 x, s16 y, s16 z){ return m_nodes_container->access(v3s16(x,y,z));}
开发者ID:minetest,项目名称:minetest,代码行数:4,
注:本文中的v3s16函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ v4l2_close函数代码示例 C++ v3f函数代码示例 |