From: Kahrl Date: Sun, 4 Dec 2011 02:28:30 +0000 (+0100) Subject: Use plain IBillboardSceneNode instead of MyBillboardSceneNode (improves X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=ceaf8edaded4c9e8f2e6fa285d9765e7095df332;p=zefram%2Fminetest%2Fminetest_engine.git Use plain IBillboardSceneNode instead of MyBillboardSceneNode (improves Irrlicht 1.8 compat); also find dungeon master's fireball texture again; add /spawnentity command --- diff --git a/data/mods/default/init.lua b/data/mods/default/init.lua index a843063e..7f0614e2 100644 --- a/data/mods/default/init.lua +++ b/data/mods/default/init.lua @@ -1472,6 +1472,28 @@ minetest.register_on_chat_message(function(name, message) end return true -- Handled chat message end + local cmd = "/spawnentity" + if message:sub(0, #cmd) == cmd then + if not minetest.get_player_privs(name)["give"] then + minetest.chat_send_player(name, "you don't have permission to spawn (give)") + return true -- Handled chat message + end + local entityname = string.match(message, cmd.." (.*)") + if entityname == nil then + minetest.chat_send_player(name, 'usage: '..cmd..' entityname') + return true -- Handled chat message + end + print(cmd..' invoked, entityname="'..entityname..'"') + local player = minetest.env:get_player_by_name(name) + if player == nil then + print("Unable to spawn entity, player is nil") + return true -- Handled chat message + end + minetest.env:add_luaentity(player:getpos(), entityname) + minetest.chat_send_player(name, '"'..entityname + ..'" spawned.'); + return true -- Handled chat message + end end) -- diff --git a/data/mods/default/textures/default_fireball.png b/data/mods/default/textures/default_fireball.png deleted file mode 100644 index 52314285..00000000 Binary files a/data/mods/default/textures/default_fireball.png and /dev/null differ diff --git a/data/mods/legacy/textures/fireball.png b/data/mods/legacy/textures/fireball.png new file mode 100644 index 00000000..52314285 Binary files /dev/null and b/data/mods/legacy/textures/fireball.png differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 61a0b1be..2088c8b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -158,7 +158,6 @@ endif() # Client sources set(minetest_SRCS ${common_SRCS} - MyBillboardSceneNode.cpp content_mapblock.cpp content_cao.cpp mesh.cpp diff --git a/src/MyBillboardSceneNode.cpp b/src/MyBillboardSceneNode.cpp deleted file mode 100644 index 0dfa59be..00000000 --- a/src/MyBillboardSceneNode.cpp +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright (C) 2002-2010 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#include "MyBillboardSceneNode.h" -#include "IVideoDriver.h" -#include "ISceneManager.h" -#include "ICameraSceneNode.h" - -namespace irr -{ -namespace scene -{ - -//! constructor -MyBillboardSceneNode::MyBillboardSceneNode(ISceneNode* parent, - ISceneManager* mgr, s32 id, - const core::vector3df& position, const core::dimension2d& size) - : IBillboardSceneNode(parent, mgr, id, position) -{ - #ifdef _DEBUG - setDebugName("MyBillboardSceneNode"); - #endif - - setSize(size); - - indices[0] = 0; - indices[1] = 2; - indices[2] = 1; - indices[3] = 0; - indices[4] = 3; - indices[5] = 2; - - video::SColor colorTop = video::SColor(0xFFFFFFFF); - video::SColor colorBottom = video::SColor(0xFFFFFFFF); - - vertices[0].TCoords.set(1.0f, 1.0f); - vertices[0].Color = colorBottom; - - vertices[1].TCoords.set(1.0f, 0.0f); - vertices[1].Color = colorTop; - - vertices[2].TCoords.set(0.0f, 0.0f); - vertices[2].Color = colorTop; - - vertices[3].TCoords.set(0.0f, 1.0f); - vertices[3].Color = colorBottom; -} - - -//! pre render event -void MyBillboardSceneNode::OnRegisterSceneNode() -{ - if (IsVisible) - SceneManager->registerNodeForRendering(this); - - ISceneNode::OnRegisterSceneNode(); -} - - -//! render -void MyBillboardSceneNode::render() -{ - video::IVideoDriver* driver = SceneManager->getVideoDriver(); - ICameraSceneNode* camera = SceneManager->getActiveCamera(); - - if (!camera || !driver) - return; - - // make billboard look to camera - - core::vector3df pos = getAbsolutePosition(); - - core::vector3df campos = camera->getAbsolutePosition(); - core::vector3df target = camera->getTarget(); - core::vector3df up = camera->getUpVector(); - core::vector3df view = target - campos; - view.normalize(); - - core::vector3df horizontal = up.crossProduct(view); - if ( horizontal.getLength() == 0 ) - { - horizontal.set(up.Y,up.X,up.Z); - } - horizontal.normalize(); - horizontal *= 0.5f * Size.Width; - - core::vector3df vertical = horizontal.crossProduct(view); - vertical.normalize(); - vertical *= 0.5f * Size.Height; - - view *= -1.0f; - - for (s32 i=0; i<4; ++i) - vertices[i].Normal = view; - - vertices[0].Pos = pos + horizontal + vertical; - vertices[1].Pos = pos + horizontal - vertical; - vertices[2].Pos = pos - horizontal - vertical; - vertices[3].Pos = pos - horizontal + vertical; - - // draw - - if ( DebugDataVisible & scene::EDS_BBOX ) - { - driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); - video::SMaterial m; - m.Lighting = false; - driver->setMaterial(m); - driver->draw3DBox(BBox, video::SColor(0,208,195,152)); - } - - driver->setTransform(video::ETS_WORLD, core::IdentityMatrix); - - driver->setMaterial(Material); - - driver->drawIndexedTriangleList(vertices, 4, indices, 2); -} - - -//! returns the axis aligned bounding box of this node -const core::aabbox3d& MyBillboardSceneNode::getBoundingBox() const -{ - return BBox; -} - - -//! sets the size of the billboard -void MyBillboardSceneNode::setSize(const core::dimension2d& size) -{ - Size = size; - - if (Size.Width == 0.0f) - Size.Width = 1.0f; - - if (Size.Height == 0.0f ) - Size.Height = 1.0f; - - f32 avg = (size.Width + size.Height)/6; - BBox.MinEdge.set(-avg,-avg,-avg); - BBox.MaxEdge.set(avg,avg,avg); -} - - -video::SMaterial& MyBillboardSceneNode::getMaterial(u32 i) -{ - return Material; -} - - -//! returns amount of materials used by this scene node. -u32 MyBillboardSceneNode::getMaterialCount() const -{ - return 1; -} - - -//! gets the size of the billboard -const core::dimension2d& MyBillboardSceneNode::getSize() const -{ - return Size; -} - - -//! Set the color of all vertices of the billboard -//! \param overallColor: the color to set -void MyBillboardSceneNode::setColor(const video::SColor & overallColor) -{ - for(u32 vertex = 0; vertex < 4; ++vertex) - vertices[vertex].Color = overallColor; -} - - -//! Set the color of the top and bottom vertices of the billboard -//! \param topColor: the color to set the top vertices -//! \param bottomColor: the color to set the bottom vertices -void MyBillboardSceneNode::setColor(const video::SColor & topColor, const video::SColor & bottomColor) -{ - vertices[0].Color = bottomColor; - vertices[1].Color = topColor; - vertices[2].Color = topColor; - vertices[3].Color = bottomColor; -} - - -//! Gets the color of the top and bottom vertices of the billboard -//! \param[out] topColor: stores the color of the top vertices -//! \param[out] bottomColor: stores the color of the bottom vertices -void MyBillboardSceneNode::getColor(video::SColor & topColor, video::SColor & bottomColor) const -{ - bottomColor = vertices[0].Color; - topColor = vertices[1].Color; -} - -void MyBillboardSceneNode::setTCoords(u32 i, core::vector2d c) -{ - vertices[i].TCoords = c; -} - -} // end namespace scene -} // end namespace irr - diff --git a/src/MyBillboardSceneNode.h b/src/MyBillboardSceneNode.h deleted file mode 100644 index 935993d8..00000000 --- a/src/MyBillboardSceneNode.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2002-2010 Nikolaus Gebhardt -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __C_BILLBOARD_SCENE_NODE_H_INCLUDED__ -#define __C_BILLBOARD_SCENE_NODE_H_INCLUDED__ - -#include "IBillboardSceneNode.h" -#include "S3DVertex.h" - -namespace irr -{ -namespace scene -{ - -//! Scene node which is a billboard. A billboard is like a 3d sprite: A 2d element, -//! which always looks to the camera. -class MyBillboardSceneNode : virtual public IBillboardSceneNode -{ -public: - - //! constructor - MyBillboardSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id, - const core::vector3df& position, const core::dimension2d& size); - - //! pre render event - virtual void OnRegisterSceneNode(); - - //! render - virtual void render(); - - //! returns the axis aligned bounding box of this node - virtual const core::aabbox3d& getBoundingBox() const; - - //! sets the size of the billboard - virtual void setSize(const core::dimension2d& size); - - //! gets the size of the billboard - virtual const core::dimension2d& getSize() const; - - virtual video::SMaterial& getMaterial(u32 i); - - //! returns amount of materials used by this scene node. - virtual u32 getMaterialCount() const; - - //! Set the color of all vertices of the billboard - //! \param overallColor: the color to set - virtual void setColor(const video::SColor & overallColor); - - //! Set the color of the top and bottom vertices of the billboard - //! \param topColor: the color to set the top vertices - //! \param bottomColor: the color to set the bottom vertices - virtual void setColor(const video::SColor & topColor, const video::SColor & bottomColor); - - //! Gets the color of the top and bottom vertices of the billboard - //! \param[out] topColor: stores the color of the top vertices - //! \param[out] bottomColor: stores the color of the bottom vertices - virtual void getColor(video::SColor& topColor, video::SColor& bottomColor) const; - - virtual void setTCoords(u32 i, core::vector2d c); - -private: - - core::dimension2d Size; - core::aabbox3d BBox; - video::SMaterial Material; - - video::S3DVertex vertices[4]; - u16 indices[6]; -}; - - -} // end namespace scene -} // end namespace irr - -#endif - diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 7563cfcc..d581b35d 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "settings.h" #include #include +#include #include "serialization.h" // For decompressZlib #include "gamedef.h" #include "clientobject.h" @@ -30,7 +31,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mesh.h" #include "utility.h" // For IntervalLimiter class Settings; -#include "MyBillboardSceneNode.h" core::map ClientActiveObject::m_types; @@ -332,6 +332,15 @@ private: SmoothTranslator pos_translator; }; +static void setBillboardTextureMatrix(scene::IBillboardSceneNode *bill, + float txs, float tys, int col, int row) +{ + video::SMaterial& material = bill->getMaterial(0); + core::matrix4& matrix = material.getTextureMatrix(0); + matrix.setTextureTranslate(txs*col, tys*row); + matrix.setTextureScale(txs, tys); +} + /* MobV2CAO */ @@ -377,7 +386,7 @@ private: IntervalLimiter m_attack_interval; core::aabbox3d m_selection_box; - scene::MyBillboardSceneNode *m_node; + scene::IBillboardSceneNode *m_node; v3f m_position; std::string m_texture_name; float m_yaw; @@ -1305,8 +1314,8 @@ void MobV2CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc, std::string texture_string = m_texture_name + "^[makealpha:128,0,0^[makealpha:128,128,0"; - scene::MyBillboardSceneNode *bill = new scene::MyBillboardSceneNode( - smgr->getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1)); + scene::IBillboardSceneNode *bill = smgr->addBillboardSceneNode( + NULL, v2f(1, 1), v3f(0,0,0), -1); bill->setMaterialTexture(0, tsrc->getTextureRaw(texture_string)); bill->setMaterialFlag(video::EMF_LIGHTING, false); bill->setMaterialFlag(video::EMF_BILINEAR_FILTER, false); @@ -1320,17 +1329,11 @@ void MobV2CAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc, const float txs = txp*32; const float typ = 1./240; const float tys = typ*48; - bill->setTCoords(0, v2f(txs*1, tys*1)); - bill->setTCoords(1, v2f(txs*1, tys*0)); - bill->setTCoords(2, v2f(txs*0, tys*0)); - bill->setTCoords(3, v2f(txs*0, tys*1)); + setBillboardTextureMatrix(bill, txs, tys, 0, 0); } else if(m_sprite_type == "simple"){ const float txs = 1.0; const float tys = 1.0 / m_simple_anim_frames; - bill->setTCoords(0, v2f(txs*1, tys*1)); - bill->setTCoords(1, v2f(txs*1, tys*0)); - bill->setTCoords(2, v2f(txs*0, tys*0)); - bill->setTCoords(3, v2f(txs*0, tys*1)); + setBillboardTextureMatrix(bill, txs, tys, 0, 0); } else { infostream<<"MobV2CAO: Unknown sprite type \""<drop(); m_node->remove(); m_node = NULL; } @@ -1394,7 +1396,7 @@ void MobV2CAO::updateNodePos() void MobV2CAO::step(float dtime, ClientEnvironment *env) { - scene::MyBillboardSceneNode *bill = m_node; + scene::IBillboardSceneNode *bill = m_node; if(!bill) return; @@ -1447,10 +1449,7 @@ void MobV2CAO::step(float dtime, ClientEnvironment *env) const float txs = txp*32; const float typ = 1./240; const float tys = typ*48; - bill->setTCoords(0, v2f(txs*(1+col), tys*(1+row))); - bill->setTCoords(1, v2f(txs*(1+col), tys*(0+row))); - bill->setTCoords(2, v2f(txs*(0+col), tys*(0+row))); - bill->setTCoords(3, v2f(txs*(0+col), tys*(1+row))); + setBillboardTextureMatrix(bill, txs, tys, col, row); } else if(m_sprite_type == "simple"){ m_walk_timer += dtime; if(m_walk_timer >= m_simple_anim_frametime){ @@ -1461,10 +1460,7 @@ void MobV2CAO::step(float dtime, ClientEnvironment *env) int row = m_walk_frame; const float txs = 1.0; const float tys = 1.0 / m_simple_anim_frames; - bill->setTCoords(0, v2f(txs*(1+col), tys*(1+row))); - bill->setTCoords(1, v2f(txs*(1+col), tys*(0+row))); - bill->setTCoords(2, v2f(txs*(0+col), tys*(0+row))); - bill->setTCoords(3, v2f(txs*(0+col), tys*(1+row))); + setBillboardTextureMatrix(bill, txs, tys, col, row); } else { infostream<<"MobV2CAO::step(): Unknown sprite type \"" < m_selection_box; scene::IMeshSceneNode *m_meshnode; - scene::MyBillboardSceneNode *m_spritenode; + scene::IBillboardSceneNode *m_spritenode; v3f m_position; v3f m_velocity; v3f m_acceleration; @@ -1783,8 +1779,8 @@ public: if(m_prop->visual == "sprite"){ infostream<<"LuaEntityCAO::addToScene(): single_sprite"<getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1)); + m_spritenode = smgr->addBillboardSceneNode( + NULL, v2f(1, 1), v3f(0,0,0), -1); m_spritenode->setMaterialTexture(0, tsrc->getTextureRaw("unknown_block.png")); m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false); @@ -1797,71 +1793,15 @@ public: { const float txs = 1.0 / 1; const float tys = 1.0 / 1; - m_spritenode->setTCoords(0, v2f(txs*1, tys*1)); - m_spritenode->setTCoords(1, v2f(txs*1, tys*0)); - m_spritenode->setTCoords(2, v2f(txs*0, tys*0)); - m_spritenode->setTCoords(3, v2f(txs*0, tys*1)); + setBillboardTextureMatrix(m_spritenode, + txs, tys, 0, 0); } } else if(m_prop->visual == "cube"){ infostream<<"LuaEntityCAO::addToScene(): cube"<visual_size.Y; - vertices[i].Pos.X *= m_prop->visual_size.X; - vertices[i].Pos.Z *= m_prop->visual_size.X; - } - - u16 indices[6] = {0,1,2,2,3,0}; - - scene::SMesh* mesh = new scene::SMesh(); - for (u32 i=0; i<6; ++i) - { - scene::IMeshBuffer* buf = new scene::SMeshBuffer(); - buf->append(vertices + 4 * i, 4, indices, 6); - buf->recalculateBoundingBox(); - mesh->addMeshBuffer(buf); - buf->drop(); - } - mesh->recalculateBoundingBox(); - + scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS)); m_meshnode = smgr->addMeshSceneNode(mesh, NULL); + mesh->drop(); - m_meshnode->setMesh(mesh); m_meshnode->setScale(v3f(1)); // Will be shown when we know the brightness m_meshnode->setVisible(false); @@ -1999,10 +1939,8 @@ public: float txs = m_tx_size.X; float tys = m_tx_size.Y; - m_spritenode->setTCoords(0, v2f(txs*(1+col), tys*(1+row))); - m_spritenode->setTCoords(1, v2f(txs*(1+col), tys*(0+row))); - m_spritenode->setTCoords(2, v2f(txs*(0+col), tys*(0+row))); - m_spritenode->setTCoords(3, v2f(txs*(0+col), tys*(1+row))); + setBillboardTextureMatrix(m_spritenode, + txs, tys, col, row); } }