From 3e012122d1607a6269af4e4522305d8b5efcd9d4 Mon Sep 17 00:00:00 2001 From: Kahrl Date: Wed, 21 Sep 2011 18:37:29 +0200 Subject: [PATCH] Simplistic wielded tool lighting, added setMeshVerticesColor to utility.h and refactored some other code into calls of that --- src/camera.cpp | 13 +++++++++ src/camera.h | 3 ++ src/content_cao.cpp | 68 +++----------------------------------------- src/environment.cpp | 21 +++++++------- src/mapblockobject.h | 60 +++----------------------------------- src/player.h | 24 ++++++---------- src/utility.cpp | 19 +++++++++++++ src/utility.h | 3 ++ 8 files changed, 66 insertions(+), 145 deletions(-) diff --git a/src/camera.cpp b/src/camera.cpp index c14d0e8bf..a61532143 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -249,6 +249,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize) } m_wieldnode->setPosition(wield_position); m_wieldnode->setRotation(wield_rotation); + m_wieldnode->updateLight(player->light); // Render distance feedback loop updateViewingRange(frametime); @@ -472,6 +473,7 @@ ExtrudedSpriteSceneNode::ExtrudedSpriteSceneNode( m_thickness = 0.1; m_cubemesh = NULL; m_is_cube = false; + m_light = LIGHT_MAX; } ExtrudedSpriteSceneNode::~ExtrudedSpriteSceneNode() @@ -519,6 +521,7 @@ void ExtrudedSpriteSceneNode::setSprite(video::ITexture* texture) m_meshnode->getMaterial(0).MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; m_meshnode->setVisible(true); m_is_cube = false; + updateLight(m_light); } void ExtrudedSpriteSceneNode::setCube(const TileSpec tiles[6]) @@ -546,6 +549,16 @@ void ExtrudedSpriteSceneNode::setCube(const TileSpec tiles[6]) } m_meshnode->setVisible(true); m_is_cube = true; + updateLight(m_light); +} + +void ExtrudedSpriteSceneNode::updateLight(u8 light) +{ + m_light = light; + + u8 li = decode_light(light); + video::SColor color(255,li,li,li); + setMeshVerticesColor(m_meshnode->getMesh(), color); } void ExtrudedSpriteSceneNode::removeSpriteFromCache(video::ITexture* texture) diff --git a/src/camera.h b/src/camera.h index fbee4a378..66825e372 100644 --- a/src/camera.h +++ b/src/camera.h @@ -205,6 +205,8 @@ public: f32 getSpriteThickness() const { return m_thickness; } void setSpriteThickness(f32 thickness); + void updateLight(u8 light); + void removeSpriteFromCache(video::ITexture* texture); virtual const core::aabbox3d& getBoundingBox() const; @@ -216,6 +218,7 @@ private: f32 m_thickness; scene::IMesh* m_cubemesh; bool m_is_cube; + u8 m_light; // internal extrusion helper methods io::path getExtrudedName(video::ITexture* texture); diff --git a/src/content_cao.cpp b/src/content_cao.cpp index dfeaea85a..b6543061a 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -224,22 +224,7 @@ void ItemCAO::updateLight(u8 light_at_pos) u8 li = decode_light(light_at_pos); video::SColor color(255,li,li,li); - - scene::IMesh *mesh = m_node->getMesh(); - if(mesh == NULL) - return; - - u16 mc = mesh->getMeshBufferCount(); - for(u16 j=0; jgetMeshBuffer(j); - video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices(); - u16 vc = buf->getVertexCount(); - for(u16 i=0; igetMesh(), color); } v3s16 ItemCAO::getLightPosition() @@ -430,22 +415,7 @@ void RatCAO::updateLight(u8 light_at_pos) u8 li = decode_light(light_at_pos); video::SColor color(255,li,li,li); - - scene::IMesh *mesh = m_node->getMesh(); - if(mesh == NULL) - return; - - u16 mc = mesh->getMeshBufferCount(); - for(u16 j=0; jgetMeshBuffer(j); - video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices(); - u16 vc = buf->getVertexCount(); - for(u16 i=0; igetMesh(), color); } v3s16 RatCAO::getLightPosition() @@ -601,22 +571,7 @@ void Oerkki1CAO::updateLight(u8 light_at_pos) u8 li = decode_light(light_at_pos); video::SColor color(255,li,li,li); - - scene::IMesh *mesh = m_node->getMesh(); - if(mesh == NULL) - return; - - u16 mc = mesh->getMeshBufferCount(); - for(u16 j=0; jgetMeshBuffer(j); - video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices(); - u16 vc = buf->getVertexCount(); - for(u16 i=0; igetMesh(), color); } v3s16 Oerkki1CAO::getLightPosition() @@ -833,22 +788,7 @@ void FireflyCAO::updateLight(u8 light_at_pos) u8 li = 255; video::SColor color(255,li,li,li); - - scene::IMesh *mesh = m_node->getMesh(); - if(mesh == NULL) - return; - - u16 mc = mesh->getMeshBufferCount(); - for(u16 j=0; jgetMeshBuffer(j); - video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices(); - u16 vc = buf->getVertexCount(); - for(u16 i=0; igetMesh(), color); } v3s16 FireflyCAO::getLightPosition() diff --git a/src/environment.cpp b/src/environment.cpp index 80f41f9fd..ea33274df 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1686,18 +1686,19 @@ void ClientEnvironment::step(float dtime) // Move player->move(dtime, *m_map, 100*BS); - // Update lighting on remote players on client - u8 light = LIGHT_MAX; - try{ - // Get node at head - v3s16 p = player->getLightPosition(); - MapNode n = m_map->getNode(p); - light = n.getLightBlend(getDayNightRatio()); - } - catch(InvalidPositionException &e) {} - player->updateLight(light); } + // Update lighting on all players on client + u8 light = LIGHT_MAX; + try{ + // Get node at head + v3s16 p = player->getLightPosition(); + MapNode n = m_map->getNode(p); + light = n.getLightBlend(getDayNightRatio()); + } + catch(InvalidPositionException &e) {} + player->updateLight(light); + /* Add footsteps to grass */ diff --git a/src/mapblockobject.h b/src/mapblockobject.h index 804494715..b852812e2 100644 --- a/src/mapblockobject.h +++ b/src/mapblockobject.h @@ -484,20 +484,7 @@ public: u8 li = decode_light(light_at_pos); video::SColor color(255,li,li,li); - - scene::IMesh *mesh = m_node->getMesh(); - - u16 mc = mesh->getMeshBufferCount(); - for(u16 j=0; jgetMeshBuffer(j); - video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices(); - u16 vc = buf->getVertexCount(); - for(u16 i=0; igetMesh(), color); } #endif @@ -676,20 +663,7 @@ public: u8 li = decode_light(light_at_pos); video::SColor color(255,li,li,li); - - scene::IMesh *mesh = m_node->getMesh(); - - u16 mc = mesh->getMeshBufferCount(); - for(u16 j=0; jgetMeshBuffer(j); - video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices(); - u16 vc = buf->getVertexCount(); - for(u16 i=0; igetMesh(), color); } #endif @@ -836,20 +810,7 @@ public: u8 li = decode_light(light_at_pos); video::SColor color(255,li,li,li); - - scene::IMesh *mesh = m_node->getMesh(); - - u16 mc = mesh->getMeshBufferCount(); - for(u16 j=0; jgetMeshBuffer(j); - video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices(); - u16 vc = buf->getVertexCount(); - for(u16 i=0; igetMesh(), color); } #endif @@ -982,20 +943,7 @@ public: u8 li = decode_light(light_at_pos); video::SColor color(255,li,li,li); - - scene::IMesh *mesh = m_node->getMesh(); - - u16 mc = mesh->getMeshBufferCount(); - for(u16 j=0; jgetMeshBuffer(j); - video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices(); - u16 vc = buf->getVertexCount(); - for(u16 i=0; igetMesh(), color); } #endif diff --git a/src/player.h b/src/player.h index 350b85e1b..ce1001992 100644 --- a/src/player.h +++ b/src/player.h @@ -126,7 +126,10 @@ public: virtual bool isLocal() const = 0; - virtual void updateLight(u8 light_at_pos) {}; + virtual void updateLight(u8 light_at_pos) + { + light = light_at_pos; + } // NOTE: Use peer_id == 0 for disconnected /*virtual bool isClientConnected() { return false; } @@ -149,6 +152,8 @@ public: bool swimming_up; bool is_frozen; + u8 light; + Inventory inventory; // Actual inventory is backed up here when creative mode is used Inventory *inventory_backup; @@ -266,25 +271,14 @@ public: virtual void updateLight(u8 light_at_pos) { + Player::updateLight(light_at_pos); + if(m_node == NULL) return; u8 li = decode_light(light_at_pos); video::SColor color(255,li,li,li); - - scene::IMesh *mesh = m_node->getMesh(); - - u16 mc = mesh->getMeshBufferCount(); - for(u16 j=0; jgetMeshBuffer(j); - video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices(); - u16 vc = buf->getVertexCount(); - for(u16 i=0; igetMesh(), color); } void move(f32 dtime, Map &map, f32 pos_max_d); diff --git a/src/utility.cpp b/src/utility.cpp index 9c1edc8a9..3c6c2f286 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -156,6 +156,25 @@ void mysrand(unsigned seed) next = seed; } +// Sets the color of all vertices in the mesh +void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color) +{ + if(mesh == NULL) + return; + + u16 mc = mesh->getMeshBufferCount(); + for(u16 j=0; jgetMeshBuffer(j); + video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices(); + u16 vc = buf->getVertexCount(); + for(u16 i=0; i &list, u16 d) {