Fix some things

This commit is contained in:
blockmaster2000 2016-11-15 16:37:31 +01:00 committed by darkrose
parent a1ec501f26
commit b20fffb931
4 changed files with 25 additions and 16 deletions

View File

@ -34,7 +34,10 @@
#include "sound.h" #include "sound.h"
#ifndef SERVER #ifndef SERVER
float roundf(float x)
{
return (float)((x < 0) ? (ceil((x) - 0.5)) : (floor((x) + 0.5)));
}
static const v3s16 corners[8] = { static const v3s16 corners[8] = {
v3s16(-1, 1, 1), v3s16(-1, 1, 1),
v3s16( 1, 1, 1), v3s16( 1, 1, 1),
@ -2709,10 +2712,10 @@ void meshgen_liquid(MeshMakeData *data, v3s16 p, MapNode &n, SelectedNode &selec
if (top_is_same_liquid == false) { if (top_is_same_liquid == false) {
video::S3DVertex vertices[4] = { video::S3DVertex vertices[4] = {
video::S3DVertex(-0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y1()), video::S3DVertex(-0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y1()),
video::S3DVertex( 0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y1()), video::S3DVertex( 0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y1()),
video::S3DVertex( 0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y0()), video::S3DVertex( 0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y0()),
video::S3DVertex(-0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y0()) video::S3DVertex(-0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y0())
}; };
// To get backface culling right, the vertices need to go // To get backface culling right, the vertices need to go
@ -2730,15 +2733,15 @@ void meshgen_liquid(MeshMakeData *data, v3s16 p, MapNode &n, SelectedNode &selec
// -Z towards +Z, thus the direction is +Z. // -Z towards +Z, thus the direction is +Z.
// Rotate texture to make animation go in flow direction // Rotate texture to make animation go in flow direction
// Positive if liquid moves towards +Z // Positive if liquid moves towards +Z
int dz = (corner_levels[side_corners[2][0]] + int dz = (corner_levels[side_corners[3][0]] +
corner_levels[side_corners[2][1]] < corner_levels[side_corners[3][1]]) -
corner_levels[side_corners[3][0]] + (corner_levels[side_corners[2][0]] +
corner_levels[side_corners[3][1]]); corner_levels[side_corners[2][1]]);
// Positive if liquid moves towards +X // Positive if liquid moves towards +X
int dx = (corner_levels[side_corners[0][0]] + int dx = (corner_levels[side_corners[1][0]] +
corner_levels[side_corners[0][1]] < corner_levels[side_corners[1][1]]) -
corner_levels[side_corners[1][0]] + (corner_levels[side_corners[0][0]] +
corner_levels[side_corners[1][1]]); corner_levels[side_corners[0][1]]);
// -X // -X
if (-dx >= abs(dz)) { if (-dx >= abs(dz)) {
v2f t = vertices[0].TCoords; v2f t = vertices[0].TCoords;

View File

@ -480,6 +480,7 @@ void MapBlockMesh::animate(float time)
AnimationData temp_data = it->second; AnimationData temp_data = it->second;
const TileSpec &tile = temp_data.tile; const TileSpec &tile = temp_data.tile;
// Figure out current frame // Figure out current frame
int frame = (int)(time * 1000 / tile.animation_frame_length_ms) % tile.animation_frame_count; int frame = (int)(time * 1000 / tile.animation_frame_length_ms) % tile.animation_frame_count;
@ -500,7 +501,7 @@ void MapBlockMesh::animate(float time)
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(it->first); scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(it->first);
// Create new texture name from original // Create new texture name from original
if (g_texturesource && buf != 0) { if (g_texturesource && frame >= 0) {
std::ostringstream os(std::ios::binary); std::ostringstream os(std::ios::binary);
os << g_texturesource->getTextureName(tile.texture.id); os << g_texturesource->getTextureName(tile.texture.id);
os << "^[verticalframe:" << (int)tile.animation_frame_count << ":" << frame; os << "^[verticalframe:" << (int)tile.animation_frame_count << ":" << frame;
@ -725,12 +726,14 @@ void MapBlockMesh::generate(MeshMakeData *data, v3s16 camera_offset, JMutex *mut
m_meshdata.swap(data->m_meshdata); m_meshdata.swap(data->m_meshdata);
m_fardata.swap(data->m_fardata); m_fardata.swap(data->m_fardata);
refresh(data->m_daynight_ratio); refresh(data->m_daynight_ratio);
animate(0.0); // get first frame of animation
m_mesh->recalculateBoundingBox(); m_mesh->recalculateBoundingBox();
if (mutex != NULL) if (mutex != NULL)
mutex->Unlock(); mutex->Unlock();
// Get frist frame of animation AFTER the mutex is unlocked
animate(0.0);
END_DEBUG_EXCEPTION_HANDLER(errorstream) END_DEBUG_EXCEPTION_HANDLER(errorstream)
} }

View File

@ -262,7 +262,7 @@ void SelectionMesh::generate(MeshMakeData *data)
// it's a typedeffed CMeshBuffer<video::S3DVertex> // it's a typedeffed CMeshBuffer<video::S3DVertex>
scene::SMeshBuffer *buf = new scene::SMeshBuffer(); scene::SMeshBuffer *buf = new scene::SMeshBuffer();
// Set material // Set material
buf->Material = d.material; buf->Material = d.tile.getMaterial();
// Add to mesh // Add to mesh
mesh->addMeshBuffer(buf); mesh->addMeshBuffer(buf);
// Mesh grabbed it // Mesh grabbed it

View File

@ -292,8 +292,11 @@ struct TileSpec
animation_frame_count(0), animation_frame_count(0),
animation_frame_length_ms(0) animation_frame_length_ms(0)
{ {
#ifndef SERVER
// init material only on clients
video::SMaterial m; video::SMaterial m;
m_material = m; m_material = m;
#endif
} }
bool operator==(TileSpec &other) bool operator==(TileSpec &other)