forked from oerkki/voxelands
non-smooth lighting now works, blocks aren't lost, yey
This commit is contained in:
parent
be139a26ba
commit
1801be4aea
141
src/client.cpp
141
src/client.cpp
|
@ -102,7 +102,7 @@ void MeshUpdateQueue::addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_se
|
|||
for (i=m_queue.begin(); i!=m_queue.end(); i++) {
|
||||
QueuedMeshUpdate *q = *i;
|
||||
if (q->p == p) {
|
||||
if (q->data && !q->data->m_refresh_only && data->m_refresh_only) {
|
||||
if (q->data && data->m_refresh_only) {
|
||||
q->data->m_daynight_ratio = data->m_daynight_ratio;
|
||||
delete data;
|
||||
}else{
|
||||
|
@ -165,17 +165,32 @@ void * MeshUpdateThread::Thread()
|
|||
|
||||
if (q->data && q->data->m_refresh_only) {
|
||||
MapBlock *block = m_env->getMap().getBlockNoCreateNoEx(q->p);
|
||||
if (block && block->mesh)
|
||||
block->mesh->refresh(q->data->m_daynight_ratio);
|
||||
if (block && block->mesh) {
|
||||
{
|
||||
JMutexAutoLock lock(block->mesh_mutex);
|
||||
block->mesh->refresh(q->data->m_daynight_ratio);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
MapBlockMesh *mesh_new = new MapBlockMesh(q->data, m_camera_offset);
|
||||
MapBlock *block = m_env->getMap().getBlockNoCreateNoEx(q->p);
|
||||
if (block && block->mesh) {
|
||||
block->mesh->generate(q->data, m_camera_offset, &block->mesh_mutex);
|
||||
if (q->ack_block_to_server) {
|
||||
MeshUpdateResult r;
|
||||
r.p = q->p;
|
||||
r.mesh = NULL;
|
||||
r.ack_block_to_server = q->ack_block_to_server;
|
||||
m_queue_out.push_back(r);
|
||||
}
|
||||
}else if (block) {
|
||||
MapBlockMesh *mesh_new = new MapBlockMesh(q->data, m_camera_offset);
|
||||
MeshUpdateResult r;
|
||||
r.p = q->p;
|
||||
r.mesh = mesh_new;
|
||||
r.ack_block_to_server = q->ack_block_to_server;
|
||||
|
||||
MeshUpdateResult r;
|
||||
r.p = q->p;
|
||||
r.mesh = mesh_new;
|
||||
r.ack_block_to_server = q->ack_block_to_server;
|
||||
|
||||
m_queue_out.push_back(r);
|
||||
m_queue_out.push_back(r);
|
||||
}
|
||||
}
|
||||
|
||||
delete q;
|
||||
|
@ -538,8 +553,16 @@ void Client::step(float dtime)
|
|||
while (m_mesh_update_thread.m_queue_out.size() > 0) {
|
||||
MeshUpdateResult r = m_mesh_update_thread.m_queue_out.pop_front();
|
||||
MapBlock *block = m_env.getMap().getBlockNoCreateNoEx(r.p);
|
||||
if (block)
|
||||
block->replaceMesh(r.mesh);
|
||||
if (block && r.mesh != NULL) {
|
||||
JMutexAutoLock lock(block->mesh_mutex);
|
||||
|
||||
MapBlockMesh *mesh_old = block->mesh;
|
||||
block->mesh = r.mesh;
|
||||
block->setMeshExpired(false);
|
||||
|
||||
if (mesh_old != NULL)
|
||||
delete mesh_old;
|
||||
}
|
||||
if (r.ack_block_to_server) {
|
||||
/*infostream<<"Client: ACK block ("<<r.p.X<<","<<r.p.Y
|
||||
<<","<<r.p.Z<<")"<<std::endl;*/
|
||||
|
@ -811,16 +834,13 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
// 0ms
|
||||
|
||||
block = sector->getBlockNoCreateNoEx(p.Y);
|
||||
if(block)
|
||||
{
|
||||
if (block) {
|
||||
/*
|
||||
Update an existing block
|
||||
*/
|
||||
//infostream<<"Updating"<<std::endl;
|
||||
block->deSerialize(istr, ser_version);
|
||||
}
|
||||
else
|
||||
{
|
||||
}else{
|
||||
/*
|
||||
Create a new block
|
||||
*/
|
||||
|
@ -831,37 +851,15 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
Acknowledge block
|
||||
*/
|
||||
/*
|
||||
[0] u16 command
|
||||
[2] u8 count
|
||||
[3] v3s16 pos_0
|
||||
[3+6] v3s16 pos_1
|
||||
...
|
||||
*/
|
||||
u32 replysize = 2+1+6;
|
||||
SharedBuffer<u8> reply(replysize);
|
||||
writeU16(&reply[0], TOSERVER_GOTBLOCKS);
|
||||
reply[2] = 1;
|
||||
writeV3S16(&reply[3], p);
|
||||
// Send as reliable
|
||||
m_con.Send(PEER_ID_SERVER, 1, reply, true);
|
||||
#endif
|
||||
|
||||
/*
|
||||
Update Mesh of this block and blocks at x-, y- and z-.
|
||||
Environment should not be locked as it interlocks with the
|
||||
main thread, from which is will want to retrieve textures.
|
||||
*/
|
||||
|
||||
//m_env.getClientMap().updateMeshes(block->getPos(), getDayNightRatio());
|
||||
/*
|
||||
Add it to mesh update queue and set it to be acknowledged after update.
|
||||
*/
|
||||
//infostream<<"Adding mesh update task for received block"<<std::endl;
|
||||
addUpdateMeshTaskWithEdge(p, true);
|
||||
}
|
||||
break;
|
||||
|
@ -1972,7 +1970,6 @@ void Client::removeNode(v3s16 p)
|
|||
i.atEnd() == false; i++)
|
||||
{
|
||||
v3s16 p = i.getNode()->getKey();
|
||||
//m_env.getClientMap().updateMeshes(p, m_env.getDayNightRatio());
|
||||
addUpdateMeshTaskWithEdge(p);
|
||||
}
|
||||
}
|
||||
|
@ -2001,7 +1998,6 @@ void Client::addNode(v3s16 p, MapNode n)
|
|||
i.atEnd() == false; i++)
|
||||
{
|
||||
v3s16 p = i.getNode()->getKey();
|
||||
//m_env.getClientMap().updateMeshes(p, m_env.getDayNightRatio());
|
||||
addUpdateMeshTaskWithEdge(p);
|
||||
}
|
||||
}
|
||||
|
@ -2225,14 +2221,11 @@ void Client::setTempMod(v3s16 p, NodeMod mod)
|
|||
assert(m_env.getMap().mapType() == MAPTYPE_CLIENT);
|
||||
|
||||
core::map<v3s16, MapBlock*> affected_blocks;
|
||||
((ClientMap&)m_env.getMap()).setTempMod(p, mod,
|
||||
&affected_blocks);
|
||||
((ClientMap&)m_env.getMap()).setTempMod(p, mod, &affected_blocks);
|
||||
|
||||
for(core::map<v3s16, MapBlock*>::Iterator
|
||||
i = affected_blocks.getIterator();
|
||||
i.atEnd() == false; i++)
|
||||
{
|
||||
i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio(), &m_env, m_mesh_update_thread.m_camera_offset);
|
||||
for(core::map<v3s16, MapBlock*>::Iterator i = affected_blocks.getIterator(); i.atEnd() == false; i++) {
|
||||
MapBlock *block = i.getNode()->getValue();
|
||||
addUpdateMeshTask(block->getPos());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2242,23 +2235,16 @@ void Client::clearTempMod(v3s16 p)
|
|||
assert(m_env.getMap().mapType() == MAPTYPE_CLIENT);
|
||||
|
||||
core::map<v3s16, MapBlock*> affected_blocks;
|
||||
((ClientMap&)m_env.getMap()).clearTempMod(p,
|
||||
&affected_blocks);
|
||||
((ClientMap&)m_env.getMap()).clearTempMod(p, &affected_blocks);
|
||||
|
||||
for(core::map<v3s16, MapBlock*>::Iterator
|
||||
i = affected_blocks.getIterator();
|
||||
i.atEnd() == false; i++)
|
||||
{
|
||||
i.getNode()->getValue()->updateMesh(m_env.getDayNightRatio(), &m_env, m_mesh_update_thread.m_camera_offset);
|
||||
for(core::map<v3s16, MapBlock*>::Iterator i = affected_blocks.getIterator(); i.atEnd() == false; i++) {
|
||||
MapBlock *block = i.getNode()->getValue();
|
||||
addUpdateMeshTask(block->getPos());
|
||||
}
|
||||
}
|
||||
|
||||
void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool refresh_only)
|
||||
{
|
||||
/*infostream<<"Client::addUpdateMeshTask(): "
|
||||
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
|
||||
<<std::endl;*/
|
||||
|
||||
MapBlock *b = m_env.getMap().getBlockNoCreateNoEx(p);
|
||||
if (b == NULL)
|
||||
return;
|
||||
|
@ -2275,27 +2261,17 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool refresh_only)
|
|||
data->m_refresh_only = true;
|
||||
}else{
|
||||
{
|
||||
//TimeTaker timer("data fill");
|
||||
// Release: ~0ms
|
||||
// Debug: 1-6ms, avg=2ms
|
||||
data->fill(getDayNightRatio(), b);
|
||||
}
|
||||
|
||||
data->m_sounds = &b->m_sounds;
|
||||
}
|
||||
|
||||
// Debug wait
|
||||
//while(m_mesh_update_thread.m_queue_in.size() > 0) sleep_ms(10);
|
||||
|
||||
// Add task to queue
|
||||
m_mesh_update_thread.m_queue_in.addBlock(p, data, ack_to_server);
|
||||
|
||||
/*infostream<<"Mesh update input queue size is "
|
||||
<<m_mesh_update_thread.m_queue_in.size()
|
||||
<<std::endl;*/
|
||||
|
||||
/*
|
||||
Mark mesh as non-expired at this point so that it can already
|
||||
Mark mesh as non-expired at this point so that it can
|
||||
be marked as expired again if the data changes
|
||||
*/
|
||||
b->setMeshExpired(false);
|
||||
|
@ -2303,16 +2279,8 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool refresh_only)
|
|||
|
||||
void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server)
|
||||
{
|
||||
/*{
|
||||
v3s16 p = blockpos;
|
||||
infostream<<"Client::addUpdateMeshTaskWithEdge(): "
|
||||
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
|
||||
<<std::endl;
|
||||
}*/
|
||||
|
||||
try{
|
||||
v3s16 p = blockpos + v3s16(0,0,0);
|
||||
//MapBlock *b = m_env.getMap().getBlockNoCreate(p);
|
||||
v3s16 p = blockpos;
|
||||
addUpdateMeshTask(p, ack_to_server);
|
||||
}
|
||||
catch(InvalidPositionException &e){}
|
||||
|
@ -2322,16 +2290,31 @@ void Client::addUpdateMeshTaskWithEdge(v3s16 blockpos, bool ack_to_server)
|
|||
addUpdateMeshTask(p);
|
||||
}
|
||||
catch(InvalidPositionException &e){}
|
||||
try{
|
||||
v3s16 p = blockpos + v3s16(1,0,0);
|
||||
addUpdateMeshTask(p);
|
||||
}
|
||||
catch(InvalidPositionException &e){}
|
||||
try{
|
||||
v3s16 p = blockpos + v3s16(0,-1,0);
|
||||
addUpdateMeshTask(p);
|
||||
}
|
||||
catch(InvalidPositionException &e){}
|
||||
try{
|
||||
v3s16 p = blockpos + v3s16(0,1,0);
|
||||
addUpdateMeshTask(p);
|
||||
}
|
||||
catch(InvalidPositionException &e){}
|
||||
try{
|
||||
v3s16 p = blockpos + v3s16(0,0,-1);
|
||||
addUpdateMeshTask(p);
|
||||
}
|
||||
catch(InvalidPositionException &e){}
|
||||
try{
|
||||
v3s16 p = blockpos + v3s16(0,0,1);
|
||||
addUpdateMeshTask(p);
|
||||
}
|
||||
catch(InvalidPositionException &e){}
|
||||
}
|
||||
|
||||
ClientEvent Client::getClientEvent()
|
||||
|
|
|
@ -222,50 +222,51 @@ static void getRoofLights(v3s16 pos, video::SColor *lights, MeshMakeData *data,
|
|||
}
|
||||
#endif
|
||||
|
||||
static void meshgen_fullbright_lights(std::vector<video::SColor> *colours, u8 alpha, u16 count)
|
||||
static u8 smooth_lights[8];
|
||||
|
||||
static void meshgen_fullbright_lights(std::vector<u32> &colours, u8 alpha, u16 count)
|
||||
{
|
||||
video::SColor c(alpha,255,255,255);
|
||||
u32 c = 0x0000000F;
|
||||
if (alpha != 255) {
|
||||
c |= 0x01<<24;
|
||||
c |= alpha<<8;
|
||||
}
|
||||
for (u16 i=0; i<count; i++) {
|
||||
for (u16 k=0; k<18; k++) {
|
||||
colours[k].push_back(c);
|
||||
}
|
||||
colours.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
static void meshgen_custom_lights(std::vector<video::SColor> *colours, u8 alpha, u8 red, u8 green, u8 blue, u16 count)
|
||||
static void meshgen_custom_lights(std::vector<u32> &colours, u8 alpha, u8 red, u8 green, u8 blue, u16 count)
|
||||
{
|
||||
video::SColor c(alpha,red,green,blue);
|
||||
if (alpha < 2)
|
||||
alpha = 3;
|
||||
u32 c = (alpha<<24)|(red<<16)|(green<<8)|blue;
|
||||
for (u16 i=0; i<count; i++) {
|
||||
for (u16 k=0; k<18; k++) {
|
||||
colours[k].push_back(c);
|
||||
}
|
||||
colours.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
static void meshgen_selected_lights(std::vector<video::SColor> *colours, u8 alpha, u16 count)
|
||||
static void meshgen_selected_lights(std::vector<u32> &colours, u8 alpha, u16 count)
|
||||
{
|
||||
video::SColor c(alpha,128,128,255);
|
||||
if (alpha < 2)
|
||||
alpha = 3;
|
||||
u32 c = (alpha<<24)|(128<<16)|(128<<8)|255;
|
||||
for (u16 i=0; i<count; i++) {
|
||||
for (u16 k=0; k<18; k++) {
|
||||
colours[k].push_back(c);
|
||||
}
|
||||
colours.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* what this should do:
|
||||
* get daynight_ratio from index
|
||||
* get all 4 corner vertex light values for the face
|
||||
* interpolate to the requested vertex position
|
||||
*/
|
||||
static void meshgen_lights_vertex(
|
||||
MeshMakeData *data,
|
||||
MapNode &n,
|
||||
v3s16 p,
|
||||
std::vector<video::SColor> *colours,
|
||||
std::vector<u32> &colours,
|
||||
u8 alpha,
|
||||
v3s16 face,
|
||||
u16 daynight_ratio_index,
|
||||
video::S3DVertex &vertex,
|
||||
u8 *lights
|
||||
)
|
||||
|
@ -275,64 +276,75 @@ static void meshgen_lights_vertex(
|
|||
|
||||
/*
|
||||
* what this should do:
|
||||
* get daynight_ratio from index
|
||||
* return face lighting (see also old roof lighting)
|
||||
*/
|
||||
static void meshgen_lights_face(
|
||||
MeshMakeData *data,
|
||||
MapNode &n,
|
||||
v3s16 p,
|
||||
std::vector<video::SColor> *colours,
|
||||
std::vector<u32> &colours,
|
||||
u8 alpha,
|
||||
v3s16 face,
|
||||
u16 daynight_ratio_index,
|
||||
u16 count,
|
||||
video::S3DVertex *vertexes
|
||||
)
|
||||
{
|
||||
u16 daynight_ratio = daynight_ratio_from_index(daynight_ratio_index);
|
||||
MapNode n1 = data->m_vmanip.getNodeRO(data->m_blockpos_nodes+p+face);
|
||||
u8 light = decode_light(getFaceLight(daynight_ratio, n, n1, face));
|
||||
u8 light = face_light(n, n1, face);
|
||||
if ((face.X && face.Y) || (face.X && face.Z) || (face.Y && face.Z)) {
|
||||
u32 l = light;
|
||||
u8 l;
|
||||
u32 dl = light&0x0F;
|
||||
u32 nl = (light&0xF0)>>4;
|
||||
u16 nc = 1;
|
||||
if (face.X) {
|
||||
n1 = data->m_vmanip.getNodeRO(data->m_blockpos_nodes+p+v3s16(face.X,0,0));
|
||||
l += decode_light(getFaceLight(daynight_ratio, n, n1, face));
|
||||
l = face_light(n, n1, face);
|
||||
dl += (l&0x0F);
|
||||
nl += (l>>4)&0x0F;
|
||||
nc++;
|
||||
}
|
||||
if (face.Y) {
|
||||
n1 = data->m_vmanip.getNodeRO(data->m_blockpos_nodes+p+v3s16(0,face.Y,0));
|
||||
l += decode_light(getFaceLight(daynight_ratio, n, n1, face));
|
||||
l = face_light(n, n1, face);
|
||||
dl += (l&0x0F);
|
||||
nl += (l>>4)&0x0F;
|
||||
nc++;
|
||||
}
|
||||
if (face.Z) {
|
||||
n1 = data->m_vmanip.getNodeRO(data->m_blockpos_nodes+p+v3s16(0,0,face.Z));
|
||||
l += decode_light(getFaceLight(daynight_ratio, n, n1, face));
|
||||
l = face_light(n, n1, face);
|
||||
dl += (l&0x0F);
|
||||
nl += (l>>4)&0x0F;
|
||||
nc++;
|
||||
}
|
||||
if (nc > 1)
|
||||
l /= nc;
|
||||
light = l;
|
||||
if (nc > 1) {
|
||||
dl /= nc;
|
||||
nl /= nc;
|
||||
}
|
||||
light = (nl<<4)|dl;
|
||||
}
|
||||
u32 c = light;
|
||||
if (alpha != 255) {
|
||||
c |= 0x01<<24;
|
||||
c |= alpha<<8;
|
||||
}
|
||||
video::SColor c = MapBlock_LightColor(alpha,light);
|
||||
for (u16 i=0; i<count; i++) {
|
||||
colours[daynight_ratio_index].push_back(c);
|
||||
colours.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* what this should do:
|
||||
* MeshMakeData has a m_smooth_lighting value in it, don't check config for every vertex!
|
||||
* get all 4 corner vertex light values for the face
|
||||
* for each vertex:
|
||||
* for each daynight_ratio value (18 of them):
|
||||
* call meshgen_lights_vertex
|
||||
* call meshgen_lights_vertex
|
||||
*/
|
||||
static void meshgen_lights(
|
||||
MeshMakeData *data,
|
||||
MapNode &n,
|
||||
v3s16 p,
|
||||
std::vector<video::SColor> *colours,
|
||||
std::vector<u32> &colours,
|
||||
u8 alpha,
|
||||
v3s16 face,
|
||||
u16 count,
|
||||
|
@ -340,57 +352,53 @@ static void meshgen_lights(
|
|||
)
|
||||
{
|
||||
if (data->m_smooth_lighting) {
|
||||
u8 lights[4];
|
||||
for (u16 k=0; k<18; k++) {
|
||||
//u32 l[4] = {0,0,0,0};
|
||||
//u8 nc = 0;
|
||||
//u16 daynight_ratio = daynight_ratio_from_index(k);
|
||||
//if (face.X) {
|
||||
//v3s16 f(face.X,0,0);
|
||||
//v3s16 vertex_dirs[4];
|
||||
//getNodeVertexDirs(f, vertex_dirs);
|
||||
//for (u16 i=0; i<4; i++) {
|
||||
//l[i] += getSmoothLight(data->m_blockpos_nodes + p, vertex_dirs[i], data->m_vmanip, daynight_ratio);
|
||||
//}
|
||||
//nc++;
|
||||
u8 lights[4] = {0,0,0,0};
|
||||
//u32 l[4] = {0,0,0,0};
|
||||
//u8 nc = 0;
|
||||
//u16 daynight_ratio = daynight_ratio_from_index(k);
|
||||
//if (face.X) {
|
||||
//v3s16 f(face.X,0,0);
|
||||
//v3s16 vertex_dirs[4];
|
||||
//getNodeVertexDirs(f, vertex_dirs);
|
||||
//for (u16 i=0; i<4; i++) {
|
||||
//l[i] += getSmoothLight(data->m_blockpos_nodes + p, vertex_dirs[i], data->m_vmanip, daynight_ratio);
|
||||
//}
|
||||
//if (face.Y) {
|
||||
//v3s16 f(0,face.Y,0);
|
||||
//v3s16 vertex_dirs[4];
|
||||
//getNodeVertexDirs(f, vertex_dirs);
|
||||
//for (u16 i=0; i<4; i++) {
|
||||
//l[i] += getSmoothLight(data->m_blockpos_nodes + p, vertex_dirs[i], data->m_vmanip, daynight_ratio);
|
||||
//}
|
||||
//nc++;
|
||||
//nc++;
|
||||
//}
|
||||
//if (face.Y) {
|
||||
//v3s16 f(0,face.Y,0);
|
||||
//v3s16 vertex_dirs[4];
|
||||
//getNodeVertexDirs(f, vertex_dirs);
|
||||
//for (u16 i=0; i<4; i++) {
|
||||
//l[i] += getSmoothLight(data->m_blockpos_nodes + p, vertex_dirs[i], data->m_vmanip, daynight_ratio);
|
||||
//}
|
||||
//if (face.Z) {
|
||||
//v3s16 f(0,0,face.Z);
|
||||
//v3s16 vertex_dirs[4];
|
||||
//getNodeVertexDirs(f, vertex_dirs);
|
||||
//for (u16 i=0; i<4; i++) {
|
||||
//l[i] += getSmoothLight(data->m_blockpos_nodes + p, vertex_dirs[i], data->m_vmanip, daynight_ratio);
|
||||
//}
|
||||
//nc++;
|
||||
//nc++;
|
||||
//}
|
||||
//if (face.Z) {
|
||||
//v3s16 f(0,0,face.Z);
|
||||
//v3s16 vertex_dirs[4];
|
||||
//getNodeVertexDirs(f, vertex_dirs);
|
||||
//for (u16 i=0; i<4; i++) {
|
||||
//l[i] += getSmoothLight(data->m_blockpos_nodes + p, vertex_dirs[i], data->m_vmanip, daynight_ratio);
|
||||
//}
|
||||
//if (nc > 1) {
|
||||
//lights[0] = l[0]/nc;
|
||||
//lights[1] = l[1]/nc;
|
||||
//lights[2] = l[2]/nc;
|
||||
//lights[3] = l[3]/nc;
|
||||
//}else {
|
||||
//lights[0] = l[0];
|
||||
//lights[1] = l[1];
|
||||
//lights[2] = l[2];
|
||||
//lights[3] = l[3];
|
||||
//}
|
||||
for (u16 i=0; i<count; i++) {
|
||||
meshgen_lights_vertex(data,n,p,colours,alpha,face,k,vertexes[i],lights);
|
||||
}
|
||||
//nc++;
|
||||
//}
|
||||
//if (nc > 1) {
|
||||
//lights[0] = l[0]/nc;
|
||||
//lights[1] = l[1]/nc;
|
||||
//lights[2] = l[2]/nc;
|
||||
//lights[3] = l[3]/nc;
|
||||
//}else {
|
||||
//lights[0] = l[0];
|
||||
//lights[1] = l[1];
|
||||
//lights[2] = l[2];
|
||||
//lights[3] = l[3];
|
||||
//}
|
||||
for (u16 i=0; i<count; i++) {
|
||||
meshgen_lights_vertex(data,n,p,colours,alpha,face,vertexes[i],lights);
|
||||
}
|
||||
}else{
|
||||
for (u16 k=0; k<18; k++) {
|
||||
meshgen_lights_face(data,n,p,colours,alpha,face,k,count,vertexes);
|
||||
}
|
||||
meshgen_lights_face(data,n,p,colours,alpha,face,count,vertexes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -587,7 +595,7 @@ static void meshgen_cuboid(
|
|||
vertices[i][j].TCoords *= tiles[tileindex].texture.size;
|
||||
vertices[i][j].TCoords += tiles[tileindex].texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (cols) {
|
||||
meshgen_custom_lights(colours,cols[0],cols[1],cols[2],cols[3],4);
|
||||
}else if (selected) {
|
||||
|
@ -635,7 +643,7 @@ static void meshgen_build_nodebox(MeshMakeData *data, v3s16 p, MapNode &n, bool
|
|||
}
|
||||
|
||||
/* TODO: calculate faces better, or pass faces as argument */
|
||||
void meshgen_rooftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners[3], v3f pos, TileSpec &tile, bool selected, s16 rot, v3s16 face)
|
||||
static void meshgen_rooftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners[3], v3f pos, TileSpec &tile, bool selected, s16 rot, v3s16 face)
|
||||
{
|
||||
// vertices for top and bottom tri
|
||||
v3f top_v[3];
|
||||
|
@ -678,7 +686,7 @@ void meshgen_rooftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners[3], v3
|
|||
video::S3DVertex(btm_v[2].X, btm_v[2].Y, btm_v[2].Z, 0,0,0, video::SColor(255,255,255,255), btm_t[2].X, btm_t[2].Y),
|
||||
};
|
||||
u16 indices[] = {0,1,2};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,3);
|
||||
}else{
|
||||
|
@ -696,7 +704,7 @@ void meshgen_rooftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners[3], v3
|
|||
video::S3DVertex(top_v[2].X, top_v[2].Y, top_v[2].Z, 0,0,0, video::SColor(255,255,255,255), top_t[2].X, top_t[2].Y),
|
||||
};
|
||||
u16 indices[] = {0,1,2};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,3);
|
||||
}else{
|
||||
|
@ -710,7 +718,7 @@ void meshgen_rooftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners[3], v3
|
|||
}
|
||||
|
||||
/* TODO: calculate faces better, or pass faces as argument */
|
||||
void meshgen_leaftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners[3], v3f pos, TileSpec &tile, bool selected, s16 rot)
|
||||
static void meshgen_leaftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners[3], v3f pos, TileSpec &tile, bool selected, s16 rot)
|
||||
{
|
||||
// vertices
|
||||
v3f v[3];
|
||||
|
@ -735,7 +743,7 @@ void meshgen_leaftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners[3], v3
|
|||
video::S3DVertex(v[2].X, v[2].Y, v[2].Z, 0,0,0, video::SColor(255,255,255,255), t[2].X, t[2].Y),
|
||||
};
|
||||
u16 indices[] = {0,1,2};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,3);
|
||||
}else{
|
||||
|
@ -748,6 +756,13 @@ void meshgen_leaftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners[3], v3
|
|||
}
|
||||
}
|
||||
|
||||
void meshgen_preset_smooth_lights(MeshMakeData *data, v3s16 p)
|
||||
{
|
||||
for (u16 i=0; i<8; i++) {
|
||||
smooth_lights[i] = 0x0F;
|
||||
}
|
||||
}
|
||||
|
||||
void meshgen_cubelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
||||
{
|
||||
v3f pos = intToFloat(p, BS);
|
||||
|
@ -761,7 +776,7 @@ void meshgen_cubelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
};
|
||||
|
||||
u16 indices[6] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -784,7 +799,7 @@ void meshgen_cubelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
};
|
||||
|
||||
u16 indices[6] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -807,7 +822,7 @@ void meshgen_cubelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
};
|
||||
|
||||
u16 indices[6] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -830,7 +845,7 @@ void meshgen_cubelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
};
|
||||
|
||||
u16 indices[6] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -853,7 +868,7 @@ void meshgen_cubelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
};
|
||||
|
||||
u16 indices[6] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -876,7 +891,7 @@ void meshgen_cubelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
};
|
||||
|
||||
u16 indices[6] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -1342,7 +1357,7 @@ void meshgen_plantlike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
}
|
||||
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -1562,7 +1577,7 @@ void meshgen_liquid(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
}
|
||||
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,f->vertex_alpha,4);
|
||||
}else{
|
||||
|
@ -1597,7 +1612,7 @@ void meshgen_liquid(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
}
|
||||
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,f->vertex_alpha,4);
|
||||
}else{
|
||||
|
@ -1773,7 +1788,7 @@ void meshgen_liquid_source(MeshMakeData *data, v3s16 p, MapNode &n, bool selecte
|
|||
}
|
||||
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,f->vertex_alpha,4);
|
||||
}else{
|
||||
|
@ -1889,7 +1904,7 @@ void meshgen_glasslike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
}
|
||||
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -2014,7 +2029,7 @@ void meshgen_torchlike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v3f pos = intToFloat(p,BS);
|
||||
// Add to mesh collector
|
||||
for (s32 j=0; j<6; j++) {
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -2244,7 +2259,7 @@ void meshgen_firelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
continue;
|
||||
}
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -3651,7 +3666,7 @@ void meshgen_wirelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, bo
|
|||
vertices[i].Pos += intToFloat(p, BS);
|
||||
}
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
meshgen_custom_lights(colours,cols[0],cols[1],cols[2],cols[3],4);
|
||||
data->append(tiles[0].getMaterial(), vertices, 4, indices, 6, colours);
|
||||
}
|
||||
|
@ -3666,7 +3681,7 @@ void meshgen_wirelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, bo
|
|||
vertices[i].Pos += intToFloat(p, BS);
|
||||
}
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
meshgen_custom_lights(colours,cols[0],cols[1],cols[2],cols[3],4);
|
||||
data->append(tiles[0].getMaterial(), vertices, 4, indices, 6, colours);
|
||||
}
|
||||
|
@ -3682,7 +3697,7 @@ void meshgen_wirelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, bo
|
|||
vertices[i].Pos += intToFloat(p, BS);
|
||||
}
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
meshgen_custom_lights(colours,cols[0],cols[1],cols[2],cols[3],4);
|
||||
data->append(tiles[0].getMaterial(), vertices, 4, indices, 6, colours);
|
||||
}
|
||||
|
@ -3697,7 +3712,7 @@ void meshgen_wirelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, bo
|
|||
vertices[i].Pos += intToFloat(p, BS);
|
||||
}
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
meshgen_custom_lights(colours,cols[0],cols[1],cols[2],cols[3],4);
|
||||
data->append(tiles[0].getMaterial(), vertices, 4, indices, 6, colours);
|
||||
}
|
||||
|
@ -3712,7 +3727,7 @@ void meshgen_wirelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, bo
|
|||
vertices[i].Pos += intToFloat(p, BS);
|
||||
}
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
meshgen_custom_lights(colours,cols[0],cols[1],cols[2],cols[3],4);
|
||||
data->append(tiles[0].getMaterial(), vertices, 4, indices, 6, colours);
|
||||
}
|
||||
|
@ -3727,7 +3742,7 @@ void meshgen_wirelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, bo
|
|||
vertices[i].Pos += intToFloat(p, BS);
|
||||
}
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
meshgen_custom_lights(colours,cols[0],cols[1],cols[2],cols[3],4);
|
||||
data->append(tiles[0].getMaterial(), vertices, 4, indices, 6, colours);
|
||||
}
|
||||
|
@ -3742,7 +3757,7 @@ void meshgen_wirelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, bo
|
|||
vertices[i].Pos += intToFloat(p, BS);
|
||||
}
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
meshgen_custom_lights(colours,cols[0],cols[1],cols[2],cols[3],4);
|
||||
data->append(tiles[0].getMaterial(), vertices, 4, indices, 6, colours);
|
||||
}
|
||||
|
@ -3757,7 +3772,7 @@ void meshgen_wirelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, bo
|
|||
vertices[i].Pos += intToFloat(p, BS);
|
||||
}
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
meshgen_custom_lights(colours,cols[0],cols[1],cols[2],cols[3],4);
|
||||
data->append(tiles[0].getMaterial(), vertices, 4, indices, 6, colours);
|
||||
}
|
||||
|
@ -3772,7 +3787,7 @@ void meshgen_wirelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, bo
|
|||
vertices[i].Pos += intToFloat(p, BS);
|
||||
}
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
meshgen_custom_lights(colours,cols[0],cols[1],cols[2],cols[3],4);
|
||||
data->append(tiles[0].getMaterial(), vertices, 4, indices, 6, colours);
|
||||
}
|
||||
|
@ -3787,7 +3802,7 @@ void meshgen_wirelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected, bo
|
|||
vertices[i].Pos += intToFloat(p, BS);
|
||||
}
|
||||
u16 indices[] = {0,1,2,2,3,0};
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
meshgen_custom_lights(colours,cols[0],cols[1],cols[2],cols[3],4);
|
||||
data->append(tiles[0].getMaterial(), vertices, 4, indices, 6, colours);
|
||||
}
|
||||
|
@ -4108,7 +4123,7 @@ void meshgen_stairlike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
vertices[i][j].TCoords *= tiles[i].texture.size;
|
||||
vertices[i][j].TCoords += tiles[i].texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,vcounts[i]);
|
||||
}else{
|
||||
|
@ -4132,7 +4147,7 @@ void meshgen_stairlike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
vertices[i][j].TCoords *= tiles[i].texture.size;
|
||||
vertices[i][j].TCoords += tiles[i].texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,vcounts[i]);
|
||||
}else{
|
||||
|
@ -4157,7 +4172,7 @@ void meshgen_stairlike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
vertices[i][j].TCoords *= tiles[i].texture.size;
|
||||
vertices[i][j].TCoords += tiles[i].texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,vcounts[i]);
|
||||
}else{
|
||||
|
@ -4178,7 +4193,7 @@ void meshgen_stairlike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
vertices[i][j].TCoords *= tiles[i].texture.size;
|
||||
vertices[i][j].TCoords += tiles[i].texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,vcounts[i]);
|
||||
}else{
|
||||
|
@ -4308,7 +4323,7 @@ void meshgen_slablike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
vertices[i][j].TCoords *= tiles[i].texture.size;
|
||||
vertices[i][j].TCoords += tiles[i].texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -4329,7 +4344,7 @@ void meshgen_slablike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
vertices[i][j].TCoords *= tiles[i].texture.size;
|
||||
vertices[i][j].TCoords += tiles[i].texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,4);
|
||||
}else{
|
||||
|
@ -4464,9 +4479,9 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
u16 end_indices[12] = {5,1,0,5,2,1,5,3,2,5,4,3};
|
||||
u16 rots[4] = {0,90,180,270};
|
||||
v3s16 faces[3] = {
|
||||
v3s16( 0, 0,-1),
|
||||
v3s16(-1, 0,-1),
|
||||
v3s16(-1, 0, 0)
|
||||
v3s16(0,0,1),
|
||||
v3s16(1,0,1),
|
||||
v3s16(1,0,0)
|
||||
};
|
||||
|
||||
v3f pos = intToFloat(p,BS);
|
||||
|
@ -4480,7 +4495,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= tile.texture.size;
|
||||
v[i].TCoords += tile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,10);
|
||||
}else{
|
||||
|
@ -4512,7 +4527,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= endtile.texture.size;
|
||||
v[i].TCoords += endtile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,6);
|
||||
}else{
|
||||
|
@ -4536,7 +4551,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= endtile.texture.size;
|
||||
v[i].TCoords += endtile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,6);
|
||||
}else{
|
||||
|
@ -4561,7 +4576,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= tile.texture.size;
|
||||
v[i].TCoords += tile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,10);
|
||||
}else{
|
||||
|
@ -4596,7 +4611,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= tile.texture.size;
|
||||
v[i].TCoords += tile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,10);
|
||||
}else{
|
||||
|
@ -4631,7 +4646,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= tile.texture.size;
|
||||
v[i].TCoords += tile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,10);
|
||||
}else{
|
||||
|
@ -4667,7 +4682,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= tile.texture.size;
|
||||
v[i].TCoords += tile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,10);
|
||||
}else{
|
||||
|
@ -4703,7 +4718,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= tile.texture.size;
|
||||
v[i].TCoords += tile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,10);
|
||||
}else{
|
||||
|
@ -4711,7 +4726,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
for (u16 i=0; i<3; i++) {
|
||||
f[i] = faces[i];
|
||||
f[i].rotateXYBy(90);
|
||||
f[i].rotateYZBy(180+rots[j]);
|
||||
f[i].rotateYZBy(rots[j]);
|
||||
}
|
||||
meshgen_lights(data,n,p,colours,255,f[0],2,v);
|
||||
meshgen_lights(data,n,p,colours,255,f[1],1,&v[2]);
|
||||
|
@ -4737,7 +4752,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= endtile.texture.size;
|
||||
v[i].TCoords += endtile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,6);
|
||||
}else{
|
||||
|
@ -4761,7 +4776,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= endtile.texture.size;
|
||||
v[i].TCoords += endtile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,6);
|
||||
}else{
|
||||
|
@ -4785,7 +4800,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= tile.texture.size;
|
||||
v[i].TCoords += tile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,10);
|
||||
}else{
|
||||
|
@ -4793,7 +4808,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
for (u16 i=0; i<3; i++) {
|
||||
f[i] = faces[i];
|
||||
f[i].rotateYZBy(90);
|
||||
f[i].rotateXYBy(180+rots[j]);
|
||||
f[i].rotateXYBy(rots[j]);
|
||||
}
|
||||
meshgen_lights(data,n,p,colours,255,f[0],2,v);
|
||||
meshgen_lights(data,n,p,colours,255,f[1],1,&v[2]);
|
||||
|
@ -4821,7 +4836,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= tile.texture.size;
|
||||
v[i].TCoords += tile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,10);
|
||||
}else{
|
||||
|
@ -4829,7 +4844,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
for (u16 i=0; i<3; i++) {
|
||||
f[i] = faces[i];
|
||||
f[i].rotateYZBy(90);
|
||||
f[i].rotateXYBy(180+rots[j]);
|
||||
f[i].rotateXYBy(rots[j]);
|
||||
}
|
||||
meshgen_lights(data,n,p,colours,255,f[0],2,v);
|
||||
meshgen_lights(data,n,p,colours,255,f[1],1,&v[2]);
|
||||
|
@ -4856,7 +4871,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= tile.texture.size;
|
||||
v[i].TCoords += tile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,10);
|
||||
}else{
|
||||
|
@ -4864,7 +4879,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
for (u16 i=0; i<3; i++) {
|
||||
f[i] = faces[i];
|
||||
f[i].rotateYZBy(90);
|
||||
f[i].rotateXYBy(180+rots[j]);
|
||||
f[i].rotateXYBy(rots[j]);
|
||||
}
|
||||
meshgen_lights(data,n,p,colours,255,f[0],2,v);
|
||||
meshgen_lights(data,n,p,colours,255,f[1],1,&v[2]);
|
||||
|
@ -4890,7 +4905,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= endtile.texture.size;
|
||||
v[i].TCoords += endtile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,6);
|
||||
}else{
|
||||
|
@ -4914,7 +4929,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= endtile.texture.size;
|
||||
v[i].TCoords += endtile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,6);
|
||||
}else{
|
||||
|
@ -4939,7 +4954,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= tile.texture.size;
|
||||
v[i].TCoords += tile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,10);
|
||||
}else{
|
||||
|
@ -4947,7 +4962,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
for (u16 i=0; i<3; i++) {
|
||||
f[i] = faces[i];
|
||||
f[i].rotateXYBy(90);
|
||||
f[i].rotateYZBy(180+rots[j]);
|
||||
f[i].rotateYZBy(rots[j]);
|
||||
}
|
||||
meshgen_lights(data,n,p,colours,255,f[0],2,v);
|
||||
meshgen_lights(data,n,p,colours,255,f[1],1,&v[2]);
|
||||
|
@ -4974,7 +4989,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
v[i].TCoords *= tile.texture.size;
|
||||
v[i].TCoords += tile.texture.pos;
|
||||
}
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
if (selected) {
|
||||
meshgen_selected_lights(colours,255,10);
|
||||
}else{
|
||||
|
@ -4982,7 +4997,7 @@ void meshgen_trunklike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected)
|
|||
for (u16 i=0; i<3; i++) {
|
||||
f[i] = faces[i];
|
||||
f[i].rotateXYBy(90);
|
||||
f[i].rotateYZBy(180+rots[j]);
|
||||
f[i].rotateYZBy(rots[j]);
|
||||
}
|
||||
meshgen_lights(data,n,p,colours,255,f[0],2,v);
|
||||
meshgen_lights(data,n,p,colours,255,f[1],1,&v[2]);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "mapblock_mesh.h"
|
||||
#include "utility.h"
|
||||
|
||||
void meshgen_preset_smooth_lights(MeshMakeData *data, v3s16 p);
|
||||
void meshgen_cubelike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected);
|
||||
void meshgen_raillike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected);
|
||||
void meshgen_plantlike(MeshMakeData *data, v3s16 p, MapNode &n, bool selected);
|
||||
|
|
|
@ -3891,11 +3891,6 @@ void ClientEnvironment::step(float dtime)
|
|||
}
|
||||
}
|
||||
|
||||
void ClientEnvironment::updateMeshes(v3s16 blockpos, v3s16 camera_offset)
|
||||
{
|
||||
m_map->updateMeshes(blockpos, getDayNightRatio(), camera_offset);
|
||||
}
|
||||
|
||||
void ClientEnvironment::expireMeshes(bool only_daynight_diffed)
|
||||
{
|
||||
m_map->expireMeshes(only_daynight_diffed);
|
||||
|
|
|
@ -446,7 +446,6 @@ public:
|
|||
virtual void addPlayer(Player *player);
|
||||
LocalPlayer * getLocalPlayer();
|
||||
|
||||
void updateMeshes(v3s16 blockpos, v3s16 camera_offset);
|
||||
void expireMeshes(bool only_daynight_diffed);
|
||||
|
||||
void setTimeOfDay(u32 time)
|
||||
|
|
107
src/map.cpp
107
src/map.cpp
|
@ -3068,13 +3068,6 @@ ClientMap::ClientMap(
|
|||
|
||||
ClientMap::~ClientMap()
|
||||
{
|
||||
/*JMutexAutoLock lock(mesh_mutex);
|
||||
|
||||
if(mesh != NULL)
|
||||
{
|
||||
mesh->drop();
|
||||
mesh = NULL;
|
||||
}*/
|
||||
}
|
||||
|
||||
MapSector * ClientMap::emergeSector(v2s16 p2d)
|
||||
|
@ -3336,29 +3329,31 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||
}
|
||||
}
|
||||
|
||||
f32 faraway = BS*50;
|
||||
f32 faraway = BS*100;
|
||||
//f32 faraway = m_control.wanted_range * BS;
|
||||
|
||||
/*
|
||||
This has to be done with the mesh_mutex unlocked
|
||||
*/
|
||||
// Pretty random but this should work somewhat nicely
|
||||
if(mesh_expired && (
|
||||
(mesh_update_count < 3
|
||||
&& (d < faraway || mesh_update_count < 2)
|
||||
)
|
||||
||
|
||||
(m_control.range_all && mesh_update_count < 20)
|
||||
if (
|
||||
mesh_expired
|
||||
&& (
|
||||
d < faraway
|
||||
|| mesh_update_count < 20
|
||||
|| (m_control.range_all && mesh_update_count < 100)
|
||||
)
|
||||
)
|
||||
/*if(mesh_expired && mesh_update_count < 6
|
||||
&& (d < faraway || mesh_update_count < 3))*/
|
||||
{
|
||||
) {
|
||||
mesh_update_count++;
|
||||
|
||||
// Mesh has been expired: generate new mesh
|
||||
//block->updateMesh(daynight_ratio);
|
||||
m_client->addUpdateMeshTask(block->getPos(),false,true);
|
||||
if (block->mesh) {
|
||||
JMutexAutoLock lock(block->mesh_mutex);
|
||||
block->mesh->refresh(m_client->getDayNightRatio());
|
||||
block->setMeshExpired(false);
|
||||
}else{
|
||||
m_client->addUpdateMeshTask(block->getPos(),false,true);
|
||||
}
|
||||
|
||||
mesh_expired = false;
|
||||
}
|
||||
|
@ -3688,78 +3683,6 @@ void ClientMap::expireMeshes(bool only_daynight_diffed)
|
|||
}
|
||||
}
|
||||
|
||||
void ClientMap::updateMeshes(v3s16 blockpos, u32 daynight_ratio, v3s16 camera_offset)
|
||||
{
|
||||
assert(mapType() == MAPTYPE_CLIENT);
|
||||
|
||||
try{
|
||||
v3s16 p = blockpos + v3s16(0,0,0);
|
||||
MapBlock *b = getBlockNoCreate(p);
|
||||
b->updateMesh(daynight_ratio, &m_client->getEnv(), camera_offset);
|
||||
//b->setMeshExpired(true);
|
||||
}
|
||||
catch(InvalidPositionException &e){}
|
||||
// Leading edge
|
||||
try{
|
||||
v3s16 p = blockpos + v3s16(-1,0,0);
|
||||
MapBlock *b = getBlockNoCreate(p);
|
||||
b->updateMesh(daynight_ratio, &m_client->getEnv(), camera_offset);
|
||||
//b->setMeshExpired(true);
|
||||
}
|
||||
catch(InvalidPositionException &e){}
|
||||
try{
|
||||
v3s16 p = blockpos + v3s16(0,-1,0);
|
||||
MapBlock *b = getBlockNoCreate(p);
|
||||
b->updateMesh(daynight_ratio, &m_client->getEnv(), camera_offset);
|
||||
//b->setMeshExpired(true);
|
||||
}
|
||||
catch(InvalidPositionException &e){}
|
||||
try{
|
||||
v3s16 p = blockpos + v3s16(0,0,-1);
|
||||
MapBlock *b = getBlockNoCreate(p);
|
||||
b->updateMesh(daynight_ratio, &m_client->getEnv(), camera_offset);
|
||||
//b->setMeshExpired(true);
|
||||
}
|
||||
catch(InvalidPositionException &e){}
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
Update mesh of block in which the node is, and if the node is at the
|
||||
leading edge, update the appropriate leading blocks too.
|
||||
*/
|
||||
void ClientMap::updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio)
|
||||
{
|
||||
v3s16 dirs[4] = {
|
||||
v3s16(0,0,0),
|
||||
v3s16(-1,0,0),
|
||||
v3s16(0,-1,0),
|
||||
v3s16(0,0,-1),
|
||||
};
|
||||
v3s16 blockposes[4];
|
||||
for(u32 i=0; i<4; i++)
|
||||
{
|
||||
v3s16 np = nodepos + dirs[i];
|
||||
blockposes[i] = getNodeBlockPos(np);
|
||||
// Don't update mesh of block if it has been done already
|
||||
bool already_updated = false;
|
||||
for(u32 j=0; j<i; j++)
|
||||
{
|
||||
if(blockposes[j] == blockposes[i])
|
||||
{
|
||||
already_updated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(already_updated)
|
||||
continue;
|
||||
// Update mesh
|
||||
MapBlock *b = getBlockNoCreate(blockposes[i]);
|
||||
b->updateMesh(daynight_ratio);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void ClientMap::PrintInfo(std::ostream &out)
|
||||
{
|
||||
out<<"ClientMap: ";
|
||||
|
|
|
@ -568,15 +568,6 @@ public:
|
|||
|
||||
void expireMeshes(bool only_daynight_diffed);
|
||||
|
||||
/*
|
||||
Update the faces of the given block and blocks on the
|
||||
leading edge.
|
||||
*/
|
||||
void updateMeshes(v3s16 blockpos, u32 daynight_ratio, v3s16 camera_offset);
|
||||
|
||||
// Update meshes that touch the node
|
||||
//void updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio);
|
||||
|
||||
// For debug printing
|
||||
virtual void PrintInfo(std::ostream &out);
|
||||
|
||||
|
|
|
@ -114,82 +114,6 @@ void MapBlock::setNodeParent(v3s16 p, MapNode & n)
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef SERVER
|
||||
|
||||
#if 1
|
||||
void MapBlock::updateMesh(u32 daynight_ratio, Environment *env, v3s16 camera_offset)
|
||||
{
|
||||
#if 0
|
||||
/*
|
||||
DEBUG: If mesh has been generated, don't generate it again
|
||||
*/
|
||||
{
|
||||
JMutexAutoLock meshlock(mesh_mutex);
|
||||
if(mesh != NULL)
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
MeshMakeData data;
|
||||
data.m_env = env;
|
||||
data.fill(daynight_ratio, this);
|
||||
data.m_sounds = &m_sounds;
|
||||
|
||||
MapBlockMesh *mesh_new = new MapBlockMesh(&data, camera_offset);
|
||||
|
||||
//scene::SMesh *mesh_new = makeMapBlockMesh(&data);
|
||||
|
||||
/*
|
||||
Replace the mesh
|
||||
*/
|
||||
|
||||
replaceMesh(mesh_new);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
void MapBlock::replaceMesh(MapBlockMesh *mesh_new)
|
||||
{
|
||||
mesh_mutex.Lock();
|
||||
|
||||
//scene::SMesh *mesh_old = mesh[daynight_i];
|
||||
//mesh[daynight_i] = mesh_new;
|
||||
|
||||
MapBlockMesh *mesh_old = mesh;
|
||||
mesh = mesh_new;
|
||||
setMeshExpired(false);
|
||||
|
||||
if(mesh_old != NULL)
|
||||
{
|
||||
// Remove hardware buffers of meshbuffers of mesh
|
||||
// NOTE: No way, this runs in a different thread and everything
|
||||
/*u32 c = mesh_old->getMeshBufferCount();
|
||||
for(u32 i=0; i<c; i++)
|
||||
{
|
||||
IMeshBuffer *buf = mesh_old->getMeshBuffer(i);
|
||||
}*/
|
||||
|
||||
/*dstream<<"mesh_old->getReferenceCount()="
|
||||
<<mesh_old->getReferenceCount()<<std::endl;
|
||||
u32 c = mesh_old->getMeshBufferCount();
|
||||
for(u32 i=0; i<c; i++)
|
||||
{
|
||||
scene::IMeshBuffer *buf = mesh_old->getMeshBuffer(i);
|
||||
dstream<<"buf->getReferenceCount()="
|
||||
<<buf->getReferenceCount()<<std::endl;
|
||||
}*/
|
||||
|
||||
// Drop the mesh
|
||||
//mesh_old->drop();
|
||||
|
||||
delete mesh_old;
|
||||
}
|
||||
|
||||
mesh_mutex.Unlock();
|
||||
}
|
||||
|
||||
#endif // !SERVER
|
||||
|
||||
/*
|
||||
Propagates sunlight down through the block.
|
||||
Doesn't modify nodes that are not affected by sunlight.
|
||||
|
|
|
@ -410,20 +410,6 @@ public:
|
|||
face_dir);
|
||||
}
|
||||
|
||||
#ifndef SERVER // Only on client
|
||||
|
||||
#if 1
|
||||
/*
|
||||
Thread-safely updates the whole mesh of the mapblock.
|
||||
NOTE: Prefer generating the mesh separately and then using
|
||||
replaceMesh().
|
||||
*/
|
||||
void updateMesh(u32 daynight_ratio, Environment *env, v3s16 camera_offset);
|
||||
#endif
|
||||
// Replace the mesh with a new one
|
||||
void replaceMesh(MapBlockMesh *mesh_new);
|
||||
#endif
|
||||
|
||||
// See comments in mapblock.cpp
|
||||
bool propagateSunlight(core::map<v3s16, bool> & light_sources,
|
||||
bool remove_light=false, bool *black_air_left=NULL);
|
||||
|
|
|
@ -165,6 +165,42 @@ video::SColor MapBlock_LightColor(u8 alpha, u8 light)
|
|||
return video::SColor(alpha,r,g,b);
|
||||
}
|
||||
|
||||
video::SColor blend_light(u32 data, u32 daylight_factor)
|
||||
{
|
||||
u8 type = (data>>24)&0xFF;
|
||||
u8 a = 255;
|
||||
u8 r = 0;
|
||||
u8 g = 0;
|
||||
u8 b = 0;
|
||||
|
||||
if (type < 2) {
|
||||
u8 light = data&0xFF;
|
||||
if (type == 1)
|
||||
a = (data>>8)&0xFF;
|
||||
u8 d = light&0x0F;
|
||||
u8 n = (light>>4)&0x0F;
|
||||
u8 l = ((daylight_factor * d + (1000-daylight_factor) * n) )/1000;
|
||||
u8 max = LIGHT_MAX;
|
||||
if (d == LIGHT_SUN)
|
||||
max = LIGHT_SUN;
|
||||
if (l > max)
|
||||
l = max;
|
||||
l = decode_light(l);
|
||||
r = l;
|
||||
g = l;
|
||||
b = l;
|
||||
if (l <= 80)
|
||||
b = MYMAX(0, pow((float)l/80.0, 0.8)*80.0);
|
||||
}else{
|
||||
a = type;
|
||||
r = (data>>16)&0xFF;
|
||||
g = (data>>8)&0xFF;
|
||||
b = data&0xFF;
|
||||
}
|
||||
|
||||
return video::SColor(a,r,g,b);
|
||||
}
|
||||
|
||||
/*
|
||||
Gets node tile from any place relative to block.
|
||||
Returns TILE_NODE if doesn't exist or should not be drawn.
|
||||
|
@ -401,7 +437,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
|
|||
m_mesh(NULL),
|
||||
m_camera_offset(camera_offset)
|
||||
{
|
||||
generate(data,camera_offset);
|
||||
generate(data,camera_offset,NULL);
|
||||
}
|
||||
|
||||
MapBlockMesh::~MapBlockMesh()
|
||||
|
@ -410,11 +446,12 @@ MapBlockMesh::~MapBlockMesh()
|
|||
m_mesh = NULL;
|
||||
}
|
||||
|
||||
void MapBlockMesh::generate(MeshMakeData *data, v3s16 camera_offset)
|
||||
void MapBlockMesh::generate(MeshMakeData *data, v3s16 camera_offset, JMutex *mutex)
|
||||
{
|
||||
data->m_blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
|
||||
data->m_smooth_lighting = g_settings->getBool("smooth_lighting");
|
||||
bool selected = false;
|
||||
m_pos = data->m_blockpos;
|
||||
|
||||
for(s16 z=0; z<MAP_BLOCKSIZE; z++)
|
||||
for(s16 y=0; y<MAP_BLOCKSIZE; y++)
|
||||
|
@ -475,6 +512,8 @@ void MapBlockMesh::generate(MeshMakeData *data, v3s16 camera_offset)
|
|||
data->m_sounds->erase(i);
|
||||
}
|
||||
}
|
||||
if (data->m_smooth_lighting && !selected)
|
||||
meshgen_preset_smooth_lights(data,p);
|
||||
switch (content_features(n).draw_type) {
|
||||
case CDT_AIRLIKE:
|
||||
break;
|
||||
|
@ -540,52 +579,56 @@ void MapBlockMesh::generate(MeshMakeData *data, v3s16 camera_offset)
|
|||
case CDT_TRUNKLIKE:
|
||||
meshgen_trunklike(data,p,n,selected);
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_mesh) {
|
||||
scene::SMesh *m = m_mesh;
|
||||
m_mesh = NULL;
|
||||
m->drop();
|
||||
scene::SMesh *mesh = new scene::SMesh();
|
||||
for (u32 i=0; i<data->m_meshdata.size(); i++) {
|
||||
MeshData &d = data->m_meshdata[i];
|
||||
// Create meshbuffer
|
||||
// This is a "Standard MeshBuffer",
|
||||
// it's a typedeffed CMeshBuffer<video::S3DVertex>
|
||||
scene::SMeshBuffer *buf = new scene::SMeshBuffer();
|
||||
// Set material
|
||||
buf->Material = d.material;
|
||||
// Add to mesh
|
||||
mesh->addMeshBuffer(buf);
|
||||
// Mesh grabbed it
|
||||
buf->drop();
|
||||
|
||||
buf->append(d.vertices.data(), d.vertices.size(), d.indices.data(), d.indices.size());
|
||||
}
|
||||
|
||||
translateMesh(mesh, intToFloat(data->m_blockpos * MAP_BLOCKSIZE - camera_offset, BS));
|
||||
|
||||
if (mutex != NULL)
|
||||
mutex->Lock();
|
||||
|
||||
if (m_mesh)
|
||||
m_mesh->drop();
|
||||
m_mesh = mesh;
|
||||
m_meshdata.swap(data->m_meshdata);
|
||||
refresh(data->m_daynight_ratio);
|
||||
m_mesh->recalculateBoundingBox();
|
||||
|
||||
translateMesh(m_mesh, intToFloat(data->m_blockpos * MAP_BLOCKSIZE - camera_offset, BS));
|
||||
if (mutex != NULL)
|
||||
mutex->Unlock();
|
||||
}
|
||||
|
||||
void MapBlockMesh::refresh(u32 daynight_ratio)
|
||||
{
|
||||
if (m_mesh == NULL) {
|
||||
m_mesh = new scene::SMesh();
|
||||
for (u32 i=0; i<m_meshdata.size(); i++) {
|
||||
MeshData &d = m_meshdata[i];
|
||||
// Create meshbuffer
|
||||
// This is a "Standard MeshBuffer",
|
||||
// it's a typedeffed CMeshBuffer<video::S3DVertex>
|
||||
scene::SMeshBuffer *buf = new scene::SMeshBuffer();
|
||||
// Set material
|
||||
buf->Material = d.material;
|
||||
// Add to mesh
|
||||
m_mesh->addMeshBuffer(buf);
|
||||
// Mesh grabbed it
|
||||
buf->drop();
|
||||
|
||||
buf->append(d.vertices.data(), d.vertices.size(), d.indices.data(), d.indices.size());
|
||||
}
|
||||
}
|
||||
|
||||
u16 ci = daynight_ratio_index(daynight_ratio);
|
||||
if (m_mesh == NULL)
|
||||
return;
|
||||
|
||||
u16 mc = m_mesh->getMeshBufferCount();
|
||||
for (u16 j=0; j<mc; j++) {
|
||||
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(j);
|
||||
video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
|
||||
u16 vc = buf->getVertexCount();
|
||||
video::SColor *c = m_meshdata[j].colours[ci].data();
|
||||
u32 *c = m_meshdata[j].colours.data();
|
||||
for (u16 i=0; i<vc; i++) {
|
||||
vertices[i].Color = c[i];
|
||||
vertices[i].Color = blend_light(c[i],daynight_ratio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ struct MeshData
|
|||
video::SMaterial material;
|
||||
std::vector<u16> indices;
|
||||
std::vector<video::S3DVertex> vertices;
|
||||
std::vector<video::SColor> colours[18];
|
||||
std::vector<u32> colours;
|
||||
std::vector<MeshData*> siblings;
|
||||
MeshData* parent;
|
||||
};
|
||||
|
@ -111,7 +111,7 @@ struct MeshMakeData
|
|||
u32 v_count,
|
||||
const u16* const indices,
|
||||
u32 i_count,
|
||||
std::vector<video::SColor> colours[18]
|
||||
std::vector<u32> colours
|
||||
)
|
||||
{
|
||||
MeshData *d = NULL;
|
||||
|
@ -159,10 +159,8 @@ struct MeshMakeData
|
|||
}
|
||||
}
|
||||
|
||||
for (u32 i=0; i<18; i++) {
|
||||
for (u32 k=0; k<colours[i].size(); k++) {
|
||||
d->colours[i].push_back(colours[i][k]);
|
||||
}
|
||||
for (u32 k=0; k<colours.size(); k++) {
|
||||
d->colours.push_back(colours[k]);
|
||||
}
|
||||
|
||||
u32 vertex_count = d->vertices.size();
|
||||
|
@ -187,12 +185,13 @@ public:
|
|||
return m_mesh;
|
||||
}
|
||||
|
||||
void generate(MeshMakeData *data, v3s16 camera_offset);
|
||||
void generate(MeshMakeData *data, v3s16 camera_offset, JMutex *mutex);
|
||||
void refresh(u32 daynight_ratio);
|
||||
|
||||
void updateCameraOffset(v3s16 camera_offset);
|
||||
|
||||
private:
|
||||
v3s16 m_pos;
|
||||
scene::SMesh *m_mesh;
|
||||
v3s16 m_camera_offset;
|
||||
std::vector<MeshData> m_meshdata;
|
||||
|
|
|
@ -694,4 +694,36 @@ u8 getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
|
|||
}
|
||||
}
|
||||
|
||||
u8 face_light(MapNode n, MapNode n2, v3s16 face_dir)
|
||||
{
|
||||
u8 ld = n.getLight(LIGHTBANK_DAY);
|
||||
u8 ld2 = n2.getLight(LIGHTBANK_DAY);
|
||||
u8 ln = n.getLight(LIGHTBANK_NIGHT);
|
||||
u8 ln2 = n2.getLight(LIGHTBANK_NIGHT);
|
||||
|
||||
if (n2.getContent() == CONTENT_IGNORE) {
|
||||
if (ld > 0) {
|
||||
ld2 = ld;
|
||||
}else{
|
||||
ld2 = LIGHT_MAX;
|
||||
}
|
||||
ln2 = ln;
|
||||
}
|
||||
|
||||
if (ld2 > ld)
|
||||
ld = ld2;
|
||||
if (ln2 > ln)
|
||||
ln = ln2;
|
||||
|
||||
if (face_dir.X == 1 || face_dir.X == -1 || face_dir.Y == -1) {
|
||||
ld = MYMAX(0,ld-2);
|
||||
ln = MYMAX(0,ln-2);
|
||||
}else if(face_dir.Z == 1 || face_dir.Z == -1) {
|
||||
ld = MYMAX(0,ld-1);
|
||||
ln = MYMAX(0,ln-1);
|
||||
}
|
||||
|
||||
return (ln<<4)|ld;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -963,8 +963,8 @@ struct MapNode
|
|||
|
||||
returns encoded light value.
|
||||
*/
|
||||
u8 getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
|
||||
v3s16 face_dir);
|
||||
u8 getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2, v3s16 face_dir);
|
||||
u8 face_light(MapNode n, MapNode n2, v3s16 face_dir);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -412,7 +412,6 @@ public:
|
|||
n = m_defaults.find(name);
|
||||
if(n == NULL)
|
||||
{
|
||||
printf("Not Found: %s\n",name.c_str());
|
||||
infostream<<"Settings: Setting not found: \""
|
||||
<<name<<"\""<<std::endl;
|
||||
throw SettingNotFoundException("Setting not found");
|
||||
|
|
|
@ -1634,33 +1634,15 @@ inline u32 time_to_daynight_ratio(u32 time_of_day)
|
|||
for (u32 i=0; i<18; i++) {
|
||||
if (values[i][0] <= t)
|
||||
continue;
|
||||
//if (i == 0)
|
||||
if (i == 0)
|
||||
return values[i][1];
|
||||
//float td0 = values[i][0] - values[i-1][0];
|
||||
//float f = (t - values[i-1][0]) / td0;
|
||||
//return f * values[i][1] + (1.0 - f) * values[i-1][1];
|
||||
float td0 = values[i][0] - values[i-1][0];
|
||||
float f = (t - values[i-1][0]) / td0;
|
||||
return f * values[i][1] + (1.0 - f) * values[i-1][1];
|
||||
}
|
||||
return 1000;
|
||||
}
|
||||
|
||||
inline u16 daynight_ratio_index(u32 daynight_ratio)
|
||||
{
|
||||
u32 values[18] = {150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000};
|
||||
for (u16 i=0; i<18; i++) {
|
||||
if (values[i] == daynight_ratio)
|
||||
return i;
|
||||
}
|
||||
return 17;
|
||||
}
|
||||
|
||||
inline u32 daynight_ratio_from_index(u16 i)
|
||||
{
|
||||
u32 values[18] = {150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000};
|
||||
if (i > 17)
|
||||
return values[17];
|
||||
return values[i];
|
||||
}
|
||||
|
||||
// Random helper. Usually d=BS
|
||||
inline core::aabbox3d<f32> getNodeBox(v3s16 p, float d)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue