From 571fb14f9480a0fd70d7cfeb0484c9513153c33a Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 13 Dec 2010 03:19:12 +0200 Subject: working nicely --- src/mapblock.cpp | 157 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 128 insertions(+), 29 deletions(-) (limited to 'src/mapblock.cpp') diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 0f2eba856..033c69cdb 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -111,7 +111,7 @@ FastFace * MapBlock::makeFastFace(u8 material, u8 light, v3f p, u8 alpha = 255; - if(material == MATERIAL_WATER || material == MATERIAL_OCEAN) + if(material == CONTENT_WATER || material == CONTENT_OCEAN) { alpha = 128; } @@ -152,7 +152,11 @@ u8 MapBlock::getFaceLight(v3s16 p, v3s16 face_dir) MapNode n = getNodeParent(p); MapNode n2 = getNodeParent(p + face_dir); u8 light; - if(n.solidness() < n2.solidness()) + /*if(n.solidness() < n2.solidness()) + light = n.getLight(); + else + light = n2.getLight();*/ + if(n.getLight() > n2.getLight()) light = n.getLight(); else light = n2.getLight(); @@ -173,18 +177,18 @@ u8 MapBlock::getFaceLight(v3s16 p, v3s16 face_dir) /* Gets node material from any place relative to block. - Returns MATERIAL_IGNORE if doesn't exist or should not be drawn. + Returns CONTENT_IGNORE if doesn't exist or should not be drawn. */ -u8 MapBlock::getNodeMaterial(v3s16 p) +u8 MapBlock::getNodeTile(v3s16 p) { try{ MapNode n = getNodeParent(p); - return content_cube_material(n.d); + return content_tile(n.d); } catch(InvalidPositionException &e) { - return MATERIAL_IGNORE; + return CONTENT_IGNORE; } } @@ -216,82 +220,82 @@ void MapBlock::updateFastFaceRow(v3s16 startpos, */ u8 light = getFaceLight(p, face_dir); - u16 continuous_materials_count = 0; + u16 continuous_tiles_count = 0; - u8 material0 = getNodeMaterial(p); - u8 material1 = getNodeMaterial(p + face_dir); + u8 tile0 = getNodeTile(p); + u8 tile1 = getNodeTile(p + face_dir); for(u16 j=0; jgetSize() > 0) { MeshCollector collector; @@ -467,8 +473,6 @@ void MapBlock::updateMesh() indices, 6); } - mesh_new = new scene::SMesh(); - collector.fillMesh(mesh_new); // Use VBO for mesh (this just would set this for ever buffer) @@ -495,13 +499,103 @@ void MapBlock::updateMesh() /* Add special graphics: - torches + + TODO: Optimize by using same meshbuffer for same textures */ + /*scene::ISceneManager *smgr = NULL; + video::IVideoDriver* driver = NULL; + if(g_device) + { + smgr = g_device->getSceneManager(); + driver = smgr->getVideoDriver(); + }*/ + for(s16 z=0; zappend(vertices, 4, indices, 6); + + // Set material + buf->getMaterial().setFlag(video::EMF_LIGHTING, false); + buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false); + buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false); + //buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + buf->getMaterial().MaterialType + = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; + if(dir == v3s16(0,-1,0)) + buf->getMaterial().setTexture(0, + g_texturecache.get("torch_on_floor")); + else if(dir == v3s16(0,1,0)) + buf->getMaterial().setTexture(0, + g_texturecache.get("torch_on_ceiling")); + // For backwards compatibility + else if(dir == v3s16(0,0,0)) + buf->getMaterial().setTexture(0, + g_texturecache.get("torch_on_floor")); + else + buf->getMaterial().setTexture(0, g_texturecache.get("torch")); + + // Add to mesh + mesh_new->addMeshBuffer(buf); + buf->drop(); + } + } + + /* + Do some stuff to the mesh + */ + + mesh_new->recalculateBoundingBox(); + + /* + Delete new mesh if it is empty + */ + + if(mesh_new->getMeshBufferCount() == 0) + { + mesh_new->drop(); + mesh_new = NULL; } /* @@ -681,6 +775,11 @@ void MapBlock::copyTo(VoxelManipulator &dst) getPosRelative(), data_size); } +/*void getPseudoObjects(v3f origin, f32 max_d, + core::array &dest) +{ +}*/ + /* Serialization */ -- cgit v1.2.3