From 75a0ca6bd67aa9ca87668bc27d36399b5028c2b1 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 12 Nov 2011 15:14:24 +0200 Subject: [PATCH] Scripting WIP --- data/scripts/default.lua | 2 + data/textures/tnt_bottom.png | Bin 0 -> 161 bytes data/textures/tnt_side.png | Bin 0 -> 186 bytes data/textures/tnt_top.png | Bin 0 -> 264 bytes src/content_cao.cpp | 114 ++++++++++++++++++++++++++++++++++- src/content_sao.cpp | 5 ++ src/content_sao.h | 3 + src/environment.cpp | 10 ++- src/inventory.cpp | 4 ++ src/luaentity_common.cpp | 14 ++--- src/luaentity_common.h | 3 +- src/scriptapi.cpp | 1 + src/server.cpp | 4 +- src/serverobject.h | 3 + 14 files changed, 148 insertions(+), 15 deletions(-) create mode 100644 data/textures/tnt_bottom.png create mode 100644 data/textures/tnt_side.png create mode 100644 data/textures/tnt_top.png diff --git a/data/scripts/default.lua b/data/scripts/default.lua index 7d3242837..46d9fbf6c 100644 --- a/data/scripts/default.lua +++ b/data/scripts/default.lua @@ -146,6 +146,8 @@ local TNT = { collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, visual = "cube", textures = {"tnt_top.png","tnt_bottom.png","tnt_side.png","tnt_side.png","tnt_side.png","tnt_side.png"}, + --visual = "single_sprite", + --textures = {"mese.png^[forcesingle"}, -- Initial value for our timer timer = 0, -- List names of state variables, for serializing object state diff --git a/data/textures/tnt_bottom.png b/data/textures/tnt_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..8ba2fca0be5b58ab656f61743204358e8d8152f8 GIT binary patch literal 161 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ z@ErkR#;MwT(m+9HPZ!4!i{9jz#S1^qXXN6$yW?QO@`VQ-xaM~@0)b@=2s7$Ag7{7c uW*k58Vg3fAI}NQN_Wf-KGbDH}8vxDda%<*zA(RC)j=|H_&t;ucLK6U;Lohf1 literal 0 HcmV?d00001 diff --git a/data/textures/tnt_side.png b/data/textures/tnt_side.png new file mode 100644 index 0000000000000000000000000000000000000000..d9a2bc4ebee1e8046f98d7fd48deb545b7aa4896 GIT binary patch literal 186 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ z@ErkR#;MwT(m=r&PZ!4!i{9jz#S1_FKh-PE0|M_QBqZLLm`Hd$G&T(2XlrEb`40sC zqT&WdMu!Z0`gPiUdAk@5+7+xhA{F&aD-J&ZN=vjo_`+o8{DHBHd19f7W^f(@gTf`7 V-v-t5ZGrYMc)I$ztaD0e0ssynH*^31 literal 0 HcmV?d00001 diff --git a/data/textures/tnt_top.png b/data/textures/tnt_top.png new file mode 100644 index 0000000000000000000000000000000000000000..a84ffc9af486b0869b64c649700eafb6aab959e9 GIT binary patch literal 264 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf4nJ z@ErkR#;MwT(m=sgo-U3d7QJUDALMOO5OAHptF>YY*SR=fpEpfnJ-QL>o#E%BS?}(c zp4c3j_+;CACj0pYXP#WHNcL+f=ZHvNaZ%U7{Ci39f77gz?n5F>kE>Gt9y>U*w2`-9 zlUvND`b=A3jvUcZ!Db1c~6CPz3 zO$fU){o!$TRrZfBe;cK24mjg@#-THb???Ck1q=VN_VO>g7J2ZgetVideoDriver(); if(m_prop->visual == "single_sprite"){ + infostream<<"LuaEntityCAO::addToScene(): single_sprite"<getRootSceneNode(), smgr, -1, v3f(0,0,0), v2f(1,1)); + std::string texturestring = "unknown_block.png"; + if(m_prop->textures.size() >= 1) + texturestring = m_prop->textures[0]; + m_spritenode->setMaterialTexture(0, + g_texturesource->getTextureRaw(texturestring)); + m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false); + m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false); + m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF); + m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true); + m_spritenode->setColor(video::SColor(255,0,0,0)); + m_spritenode->setVisible(false); /* Set visible when brightness is known */ + m_spritenode->setSize(v2f(1,1)*1.0*BS); + { + 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)); + } } else if(m_prop->visual == "cube"){ + infostream<<"LuaEntityCAO::addToScene(): cube"<append(vertices + 4 * i, 4, indices, 6); + buf->recalculateBoundingBox(); + mesh->addMeshBuffer(buf); + buf->drop(); + } + mesh->recalculateBoundingBox(); + + m_meshnode = smgr->addMeshSceneNode(mesh, NULL); + + m_meshnode->setMesh(mesh); + m_meshnode->setScale(v3f(1)); + for (u32 i = 0; i < 6; ++i) + { + std::string texturestring = "unknown_block.png"; + if(m_prop->textures.size() > i) + texturestring = m_prop->textures[i]; + AtlasPointer ap = g_texturesource->getTexture(texturestring); + + // Get the tile texture and atlas transformation + video::ITexture* atlas = ap.atlas; + v2f pos = ap.pos; + v2f size = ap.size; + + // Set material flags and texture + video::SMaterial& material = m_meshnode->getMaterial(i); + material.setFlag(video::EMF_LIGHTING, false); + material.setFlag(video::EMF_BILINEAR_FILTER, false); + material.setTexture(0, atlas); + material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y); + material.getTextureMatrix(0).setTextureScale(size.X, size.Y); + } + // Will be shown when we know the brightness + m_meshnode->setVisible(false); } else { + infostream<<"LuaEntityCAO::addToScene(): \""<visual + <<"\" not supported"<getMesh(), color); + m_meshnode->setVisible(true); } if(m_spritenode){ m_spritenode->setColor(color); + m_spritenode->setVisible(true); } } @@ -1350,6 +1457,7 @@ void LuaEntityCAO::updateNodePos() void LuaEntityCAO::step(float dtime, ClientEnvironment *env) { pos_translator.translate(dtime); + updateNodePos(); } void LuaEntityCAO::processMessage(const std::string &data) @@ -1398,6 +1506,10 @@ void LuaEntityCAO::initialize(const std::string &data) m_prop->deSerialize(prop_is); infostream<<"m_prop: "<dump()<collisionbox; + m_selection_box.MinEdge *= BS; + m_selection_box.MaxEdge *= BS; pos_translator.init(m_position); diff --git a/src/content_sao.cpp b/src/content_sao.cpp index b053274f1..0abeb0ef0 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -1656,6 +1656,11 @@ void LuaEntitySAO::moveTo(v3f pos, bool continuous) sendPosition(true, true); } +float LuaEntitySAO::getMinimumSavedMovement() +{ + return 0.1 * BS; +} + void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end) { m_last_sent_move_precision = m_base_position.getDistanceFrom( diff --git a/src/content_sao.h b/src/content_sao.h index 103b4cc8e..1d7239232 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -52,6 +52,8 @@ public: InventoryItem* createInventoryItem(); InventoryItem* createPickedUpItem(){return createInventoryItem();} void rightClick(Player *player); + + float getMinimumSavedMovement(){ return 0.1*BS; } private: std::string m_inventorystring; v3f m_speed_f; @@ -218,6 +220,7 @@ public: void setPos(v3f pos); void moveTo(v3f pos, bool continuous); + float getMinimumSavedMovement(); private: void sendPosition(bool do_interpolate, bool is_movement_end); diff --git a/src/environment.cpp b/src/environment.cpp index e75e967c2..d3e8fa12c 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -1749,8 +1749,10 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) if(n){ StaticObject static_old = n->getValue(); + float save_movem = obj->getMinimumSavedMovement(); + if(static_old.data == staticdata_new && - (static_old.pos - objectpos).getLength() < 2*BS) + (static_old.pos - objectpos).getLength() < save_movem) data_changed = false; } else { errorstream<<"ServerEnvironment::deactivateFarObjects(): " @@ -1759,6 +1761,8 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) <m_static_block)<m_static_exists) @@ -1769,7 +1773,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) block->m_static_objects.remove(id); obj->m_static_exists = false; // Only mark block as modified if data changed considerably - if(!stays_in_same_block || data_changed) + if(shall_be_written) block->raiseModified(MOD_STATE_WRITE_NEEDED); } } @@ -1794,7 +1798,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) block->m_static_objects.insert(new_id, s_obj); // Only mark block as modified if data changed considerably - if(!stays_in_same_block || data_changed) + if(shall_be_written) block->raiseModified(MOD_STATE_WRITE_NEEDED); obj->m_static_exists = true; diff --git a/src/inventory.cpp b/src/inventory.cpp index 5d4a6e408..45646a69a 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -135,6 +135,10 @@ ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f /* Create an ItemSAO */ + pos.Y -= BS*0.25; // let it drop a bit + // Randomize a bit + pos.X += BS*0.2*(float)myrand_range(-1000,1000)/1000.0; + pos.Z += BS*0.2*(float)myrand_range(-1000,1000)/1000.0; // Create object ServerActiveObject *obj = new ItemSAO(env, pos, getItemString()); return obj; diff --git a/src/luaentity_common.cpp b/src/luaentity_common.cpp index 6ce201236..26cfce1c2 100644 --- a/src/luaentity_common.cpp +++ b/src/luaentity_common.cpp @@ -40,9 +40,8 @@ std::string LuaEntityProperties::dump() os<<", collisionbox="<::Iterator i = textures.begin(); - i != textures.end(); i++){ - os<<"\""<<(*i)<<"\" "; + for(u32 i=0; i::Iterator i = textures.begin(); - i != textures.end(); i++){ - os< collisionbox; std::string visual; - core::list textures; + core::array textures; LuaEntityProperties(); std::string dump(); diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 428810117..f8875c0e3 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -791,6 +791,7 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id, } } lua_pop(L, 1); + } void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime) diff --git a/src/server.cpp b/src/server.cpp index 88ac6fd70..fd9703bd5 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2853,10 +2853,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) // Calculate a position for it v3f pos = intToFloat(p_over, BS); //pos.Y -= BS*0.45; - pos.Y -= BS*0.25; // let it drop a bit + /*pos.Y -= BS*0.25; // let it drop a bit // Randomize a bit pos.X += BS*0.2*(float)myrand_range(-1000,1000)/1000.0; - pos.Z += BS*0.2*(float)myrand_range(-1000,1000)/1000.0; + pos.Z += BS*0.2*(float)myrand_range(-1000,1000)/1000.0;*/ /* Create the object diff --git a/src/serverobject.h b/src/serverobject.h index cd98ba0aa..6d616c75e 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -76,6 +76,9 @@ public: // continuous: if true, object does not stop immediately at pos virtual void moveTo(v3f pos, bool continuous) { setBasePosition(pos); } + // If object has moved less than this and data has not changed, + // saving to disk may be omitted + virtual float getMinimumSavedMovement(){ return 2.0*BS; } /* Step object in time. -- 2.25.1