1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-12-23 08:08:47 -05:00

commit before some more radical changes

This commit is contained in:
Perttu Ahola 2011-04-03 16:21:06 +03:00
parent 06eb0ad4d0
commit 01c2b003e1
12 changed files with 222 additions and 63 deletions

View File

@ -50,6 +50,7 @@ configure_file(
)
set(common_SRCS
nodemetadata.cpp
serverobject.cpp
noise.cpp
mineral.cpp

View File

@ -36,7 +36,7 @@ void * ClientUpdateThread::Thread()
while(getRun())
{
m_client->asyncStep();
//m_client->asyncStep();
//m_client->updateSomeExpiredMeshes();
@ -357,6 +357,7 @@ void Client::step(float dtime)
}*/
}
#if 0
float Client::asyncStep()
{
DSTACK(__FUNCTION_NAME);
@ -374,6 +375,7 @@ float Client::asyncStep()
return dtime;*/
return 0.0;
}
#endif
// Virtual methods from con::PeerHandler
void Client::peerAdded(con::Peer *peer)
@ -1182,8 +1184,6 @@ bool Client::AsyncProcessPacket()
// Ignore too small packet
if(datasize < 8)
return true;
/*if(datasize < 8 + MapBlock::serializedLength(ser_version))
goto getdata;*/
v3s16 p;
p.X = readS16(&data[2]);
@ -1238,35 +1238,6 @@ bool Client::AsyncProcessPacket()
block->deSerialize(istr, ser_version);
sector->insertBlock(block);
//block->setChangedFlag();
//DEBUG
/*NodeMod mod;
mod.type = NODEMOD_CHANGECONTENT;
mod.param = CONTENT_MESE;
block->setTempMod(v3s16(8,10,8), mod);
block->setTempMod(v3s16(8,9,8), mod);
block->setTempMod(v3s16(8,8,8), mod);
block->setTempMod(v3s16(8,7,8), mod);
block->setTempMod(v3s16(8,6,8), mod);*/
/*
Add some coulds
Well, this is a dumb way to do it, they should just
be drawn as separate objects.
*/
/*if(p.Y == 3)
{
NodeMod mod;
mod.type = NODEMOD_CHANGECONTENT;
mod.param = CONTENT_CLOUD;
v3s16 p2;
p2.Y = 8;
for(p2.X=3; p2.X<=13; p2.X++)
for(p2.Z=3; p2.Z<=13; p2.Z++)
{
block->setTempMod(p2, mod);
}
}*/
}
} //envlock
@ -1605,6 +1576,12 @@ MapNode Client::getNode(v3s16 p)
return m_env.getMap().getNode(p);
}
NodeMetadata* Client::getNodeMetadataClone(v3s16 p)
{
JMutexAutoLock envlock(m_env_mutex);
return m_env.getMap().getNodeMetadataClone(p);
}
v3f Client::getPlayerPosition()
{
JMutexAutoLock envlock(m_env_mutex);

View File

@ -138,7 +138,7 @@ public:
// Called from updater thread
// Returns dtime
float asyncStep();
//float asyncStep();
void ProcessData(u8 *data, u32 datasize, u16 sender_peer_id);
// Returns true if something was received
@ -166,6 +166,8 @@ public:
// Returns InvalidPositionException if not found
MapNode getNode(v3s16 p);
// Wrapper to Map
NodeMetadata* getNodeMetadataClone(v3s16 p);
v3f getPlayerPosition();

View File

@ -2701,6 +2701,55 @@ int main(int argc, char *argv[])
}
}
}
else if(n.d == CONTENT_SIGN_WALL)
{
v3s16 dir = unpackDir(n.dir);
v3f dir_f = v3f(dir.X, dir.Y, dir.Z);
dir_f *= BS/2 - BS/6 - BS/20;
v3f cpf = npf + dir_f;
f32 distance = (cpf - camera_position).getLength();
v3f vertices[4] =
{
v3f(BS*0.42,-BS*0.35,-BS*0.4),
v3f(BS*0.49, BS*0.35, BS*0.4),
};
for(s32 i=0; i<2; i++)
{
if(dir == v3s16(1,0,0))
vertices[i].rotateXZBy(0);
if(dir == v3s16(-1,0,0))
vertices[i].rotateXZBy(180);
if(dir == v3s16(0,0,1))
vertices[i].rotateXZBy(90);
if(dir == v3s16(0,0,-1))
vertices[i].rotateXZBy(-90);
if(dir == v3s16(0,-1,0))
vertices[i].rotateXYBy(-90);
if(dir == v3s16(0,1,0))
vertices[i].rotateXYBy(90);
vertices[i] += npf;
}
core::aabbox3d<f32> box;
box = core::aabbox3d<f32>(vertices[0]);
box.addInternalPoint(vertices[1]);
if(distance < mindistance)
{
if(box.intersectsWithLine(shootline))
{
nodefound = true;
nodepos = np;
neighbourpos = np;
mindistance = distance;
nodehilightbox = box;
}
}
}
/*
Regular blocks
*/
@ -2765,11 +2814,20 @@ int main(int argc, char *argv[])
static float dig_time = 0.0;
static u16 dig_index = 0;
// Visualize selection
/*
Visualize selection
*/
hilightboxes.push_back(nodehilightbox);
// Handle digging
/*
TODO:
Check information text of node
*/
/*
Handle digging
*/
if(g_input->getLeftReleased())
{

View File

@ -940,6 +940,15 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
n.setLight(bank, 0);
}
/*
If node lets sunlight through and is under sunlight, it has
sunlight too.
*/
if(node_under_sunlight && content_features(n.d).sunlight_propagates)
{
n.setLight(LIGHTBANK_DAY, LIGHT_SUN);
}
/*
Set the node on the map
*/
@ -947,13 +956,13 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
setNode(p, n);
/*
If node is under sunlight, take all sunlighted nodes under
it and clear light from them and from where the light has
been spread.
If node is under sunlight and doesn't let sunlight through,
take all sunlighted nodes under it and clear light from them
and from where the light has been spread.
TODO: This could be optimized by mass-unlighting instead
of looping
*/
if(node_under_sunlight)
if(node_under_sunlight && !content_features(n.d).sunlight_propagates)
{
s16 y = p.Y - 1;
for(;; y--){
@ -981,7 +990,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
break;
}
}
for(s32 i=0; i<2; i++)
{
enum LightBank bank = banks[i];
@ -1687,6 +1696,17 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
//dstream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
}
NodeMetadata* Map::getNodeMetadataClone(v3s16 p)
{
v3s16 blockpos = getNodeBlockPos(p);
v3s16 p_rel = p - blockpos*MAP_BLOCKSIZE;
MapBlock *block = getBlockNoCreateNoEx(blockpos);
if(block == NULL)
return NULL;
NodeMetadata *meta = block->m_node_metadata.getClone(p_rel);
return meta;
}
/*
ServerMap
*/

View File

@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "constants.h"
#include "voxel.h"
#include "mapchunk.h"
#include "nodemetadata.h"
#define MAPTYPE_BASE 0
#define MAPTYPE_SERVER 1
@ -276,6 +277,13 @@ public:
void transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks);
/*
Node metadata
These are basically coordinate wrappers to MapBlock
*/
NodeMetadata* getNodeMetadataClone(v3s16 p);
/*
Variables
*/

View File

@ -799,6 +799,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
{
video::SColor c(255,255,255,255);
// Wall at X+ of node
video::S3DVertex vertices[4] =
{
video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c, 0,1),
@ -854,6 +855,61 @@ void MapBlock::updateMesh(u32 daynight_ratio)
// Add to mesh collector
collector.append(material, vertices, 4, indices, 6);
}
/*
Signs on walls
*/
if(n.d == CONTENT_SIGN_WALL)
{
u8 l = decode_light(n.getLightBlend(daynight_ratio));
video::SColor c(255,l,l,l);
float d = (float)BS/16;
// Wall at X+ of node
video::S3DVertex vertices[4] =
{
video::S3DVertex(BS/2-d,-BS/2,-BS/2, 0,0,0, c, 0,1),
video::S3DVertex(BS/2-d,-BS/2,BS/2, 0,0,0, c, 1,1),
video::S3DVertex(BS/2-d,BS/2,BS/2, 0,0,0, c, 1,0),
video::S3DVertex(BS/2-d,BS/2,-BS/2, 0,0,0, c, 0,0),
};
v3s16 dir = unpackDir(n.dir);
for(s32 i=0; i<4; i++)
{
if(dir == v3s16(1,0,0))
vertices[i].Pos.rotateXZBy(0);
if(dir == v3s16(-1,0,0))
vertices[i].Pos.rotateXZBy(180);
if(dir == v3s16(0,0,1))
vertices[i].Pos.rotateXZBy(90);
if(dir == v3s16(0,0,-1))
vertices[i].Pos.rotateXZBy(-90);
if(dir == v3s16(0,-1,0))
vertices[i].Pos.rotateXYBy(-90);
if(dir == v3s16(0,1,0))
vertices[i].Pos.rotateXYBy(90);
vertices[i].Pos += intToFloat(p + getPosRelative(), BS);
}
// Set material
video::SMaterial material;
material.setFlag(video::EMF_LIGHTING, false);
material.setFlag(video::EMF_BACK_FACE_CULLING, false);
material.setFlag(video::EMF_BILINEAR_FILTER, false);
material.setFlag(video::EMF_FOG_ENABLE, true);
//material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
material.MaterialType
= video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
material.setTexture(0,
g_texturesource->getTextureRaw("sign_wall.png"));
u16 indices[] = {0,1,2,2,3,0};
// Add to mesh collector
collector.append(material, vertices, 4, indices, 6);
}
/*
Add flowing water to mesh
*/

View File

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "constants.h"
#include "mapblockobject.h"
#include "voxel.h"
#include "nodemetadata.h"
// Named by looking towards z+
enum{
@ -619,6 +620,8 @@ public:
JMutex mesh_mutex;
#endif
NodeMetadataList m_node_metadata;
private:
/*
Private member variables
@ -665,27 +668,11 @@ private:
// Whether day and night lighting differs
bool m_day_night_differs;
/*
Whether everything that is mainly located on this block has
been added to the world.
While this is false, a block can still be changed a bit when
stuff is added to the neighboring blocks that extends to this
one.
When this is false on every one of a 3x3x3 chunk of blocks, the
central one will not be changed by the map generator in the
future.
TODO: Save in file
*/
//bool m_not_fully_generated;
MapBlockObjectList m_objects;
// Object spawning stuff
float m_spawn_timer;
#ifndef SERVER // Only on client
/*
Set to true if the mesh has been ordered to be updated

View File

@ -201,6 +201,7 @@ void init_mapnode()
}
f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
// Deprecated
i = CONTENT_COALSTONE;
f = &g_content_features[i];
//f->translate_to = new MapNode(CONTENT_STONE, MINERAL_COAL);
@ -287,6 +288,25 @@ void init_mapnode()
f->wall_mounted = true;
f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
i = CONTENT_FURNACE;
f = &g_content_features[i];
f->setAllTextures("furnace_side.png");
f->setTexture(2, "furnace_front.png");
f->setInventoryTexture("furnace_front.png");
f->param_type = CPT_NONE;
f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
i = CONTENT_SIGN_WALL;
f = &g_content_features[i];
f->setInventoryTexture("sign_wall.png");
f->param_type = CPT_LIGHT;
f->light_propagates = true;
f->sunlight_propagates = true;
f->solidness = 0; // drawn separately, makes no faces
f->walkable = false;
f->wall_mounted = true;
f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
}
TileSpec MapNode::getTile(v3s16 dir)

View File

@ -94,12 +94,8 @@ void init_content_inventory_texture_paths();
#define CONTENT_COALSTONE 11
#define CONTENT_WOOD 12
#define CONTENT_SAND 13
/*
This is used by all kinds of things to allocate memory for all
contents except CONTENT_AIR and CONTENT_IGNORE
*/
#define USEFUL_CONTENT_COUNT 14
#define CONTENT_FURNACE 14
#define CONTENT_SIGN_WALL 15
/*
Content feature list

View File

@ -60,6 +60,8 @@ void initializeMaterialProperties()
g_material_properties[CONTENT_SAND].setDiggingProperties("",
DiggingProperties(true, 0.4, 0));
setStoneLikeDiggingProperties(CONTENT_FURNACE, 1.0);
/*
Add MesePick to everything
*/

View File

@ -3327,6 +3327,36 @@ void setCreativeInventory(Player *player)
/*
Give materials
*/
// CONTENT_IGNORE-terminated list
u8 material_items[] = {
CONTENT_TORCH,
CONTENT_MUD,
CONTENT_STONE,
CONTENT_SAND,
CONTENT_TREE,
CONTENT_LEAVES,
CONTENT_MESE,
CONTENT_WATERSOURCE,
CONTENT_CLOUD,
CONTENT_FURNACE,
CONTENT_SIGN_WALL,
CONTENT_IGNORE
};
u8 *mip = material_items;
for(u16 i=0; i<PLAYER_INVENTORY_SIZE; i++)
{
if(*mip == CONTENT_IGNORE)
break;
InventoryItem *item = new MaterialItem(*mip, 1);
player->inventory.addItem("main", item);
mip++;
}
#if 0
assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
// add torch first
@ -3344,6 +3374,8 @@ void setCreativeInventory(Player *player)
InventoryItem *item = new MaterialItem(i, 1);
player->inventory.addItem("main", item);
}
#endif
// Sign
{
InventoryItem *item = new MapBlockObjectItem("Sign Example text");