mirror of
https://github.com/moparisthebest/minetest
synced 2024-11-15 13:55:11 -05:00
Scripting WIP
This commit is contained in:
parent
38944467d3
commit
75a0ca6bd6
@ -146,6 +146,8 @@ local TNT = {
|
|||||||
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
||||||
visual = "cube",
|
visual = "cube",
|
||||||
textures = {"tnt_top.png","tnt_bottom.png","tnt_side.png","tnt_side.png","tnt_side.png","tnt_side.png"},
|
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
|
-- Initial value for our timer
|
||||||
timer = 0,
|
timer = 0,
|
||||||
-- List names of state variables, for serializing object state
|
-- List names of state variables, for serializing object state
|
||||||
|
BIN
data/textures/tnt_bottom.png
Normal file
BIN
data/textures/tnt_bottom.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 161 B |
BIN
data/textures/tnt_side.png
Normal file
BIN
data/textures/tnt_side.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 186 B |
BIN
data/textures/tnt_top.png
Normal file
BIN
data/textures/tnt_top.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 264 B |
@ -1275,7 +1275,7 @@ LuaEntityCAO proto_LuaEntityCAO;
|
|||||||
|
|
||||||
LuaEntityCAO::LuaEntityCAO():
|
LuaEntityCAO::LuaEntityCAO():
|
||||||
ClientActiveObject(0),
|
ClientActiveObject(0),
|
||||||
m_selection_box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.),
|
m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.),
|
||||||
m_meshnode(NULL),
|
m_meshnode(NULL),
|
||||||
m_spritenode(NULL),
|
m_spritenode(NULL),
|
||||||
m_position(v3f(0,10*BS,0)),
|
m_position(v3f(0,10*BS,0)),
|
||||||
@ -1303,9 +1303,114 @@ void LuaEntityCAO::addToScene(scene::ISceneManager *smgr)
|
|||||||
//video::IVideoDriver* driver = smgr->getVideoDriver();
|
//video::IVideoDriver* driver = smgr->getVideoDriver();
|
||||||
|
|
||||||
if(m_prop->visual == "single_sprite"){
|
if(m_prop->visual == "single_sprite"){
|
||||||
|
infostream<<"LuaEntityCAO::addToScene(): single_sprite"<<std::endl;
|
||||||
|
m_spritenode = new scene::MyBillboardSceneNode(
|
||||||
|
smgr->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"){
|
} else if(m_prop->visual == "cube"){
|
||||||
|
infostream<<"LuaEntityCAO::addToScene(): cube"<<std::endl;
|
||||||
|
video::SColor c(255,255,255,255);
|
||||||
|
video::S3DVertex vertices[24] =
|
||||||
|
{
|
||||||
|
// Up
|
||||||
|
video::S3DVertex(-0.5,+0.5,-0.5, 0,1,0, c, 0,1),
|
||||||
|
video::S3DVertex(-0.5,+0.5,+0.5, 0,1,0, c, 0,0),
|
||||||
|
video::S3DVertex(+0.5,+0.5,+0.5, 0,1,0, c, 1,0),
|
||||||
|
video::S3DVertex(+0.5,+0.5,-0.5, 0,1,0, c, 1,1),
|
||||||
|
// Down
|
||||||
|
video::S3DVertex(-0.5,-0.5,-0.5, 0,-1,0, c, 0,0),
|
||||||
|
video::S3DVertex(+0.5,-0.5,-0.5, 0,-1,0, c, 1,0),
|
||||||
|
video::S3DVertex(+0.5,-0.5,+0.5, 0,-1,0, c, 1,1),
|
||||||
|
video::S3DVertex(-0.5,-0.5,+0.5, 0,-1,0, c, 0,1),
|
||||||
|
// Right
|
||||||
|
video::S3DVertex(+0.5,-0.5,-0.5, 1,0,0, c, 0,1),
|
||||||
|
video::S3DVertex(+0.5,+0.5,-0.5, 1,0,0, c, 0,0),
|
||||||
|
video::S3DVertex(+0.5,+0.5,+0.5, 1,0,0, c, 1,0),
|
||||||
|
video::S3DVertex(+0.5,-0.5,+0.5, 1,0,0, c, 1,1),
|
||||||
|
// Left
|
||||||
|
video::S3DVertex(-0.5,-0.5,-0.5, -1,0,0, c, 1,1),
|
||||||
|
video::S3DVertex(-0.5,-0.5,+0.5, -1,0,0, c, 0,1),
|
||||||
|
video::S3DVertex(-0.5,+0.5,+0.5, -1,0,0, c, 0,0),
|
||||||
|
video::S3DVertex(-0.5,+0.5,-0.5, -1,0,0, c, 1,0),
|
||||||
|
// Back
|
||||||
|
video::S3DVertex(-0.5,-0.5,+0.5, 0,0,1, c, 1,1),
|
||||||
|
video::S3DVertex(+0.5,-0.5,+0.5, 0,0,1, c, 0,1),
|
||||||
|
video::S3DVertex(+0.5,+0.5,+0.5, 0,0,1, c, 0,0),
|
||||||
|
video::S3DVertex(-0.5,+0.5,+0.5, 0,0,1, c, 1,0),
|
||||||
|
// Front
|
||||||
|
video::S3DVertex(-0.5,-0.5,-0.5, 0,0,-1, c, 0,1),
|
||||||
|
video::S3DVertex(-0.5,+0.5,-0.5, 0,0,-1, c, 0,0),
|
||||||
|
video::S3DVertex(+0.5,+0.5,-0.5, 0,0,-1, c, 1,0),
|
||||||
|
video::S3DVertex(+0.5,-0.5,-0.5, 0,0,-1, c, 1,1),
|
||||||
|
};
|
||||||
|
|
||||||
|
for(u32 i=0; i<24; ++i){
|
||||||
|
vertices[i].Pos *= BS;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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 {
|
} else {
|
||||||
|
infostream<<"LuaEntityCAO::addToScene(): \""<<m_prop->visual
|
||||||
|
<<"\" not supported"<<std::endl;
|
||||||
}
|
}
|
||||||
|
updateNodePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaEntityCAO::removeFromScene()
|
void LuaEntityCAO::removeFromScene()
|
||||||
@ -1326,9 +1431,11 @@ void LuaEntityCAO::updateLight(u8 light_at_pos)
|
|||||||
video::SColor color(255,li,li,li);
|
video::SColor color(255,li,li,li);
|
||||||
if(m_meshnode){
|
if(m_meshnode){
|
||||||
setMeshVerticesColor(m_meshnode->getMesh(), color);
|
setMeshVerticesColor(m_meshnode->getMesh(), color);
|
||||||
|
m_meshnode->setVisible(true);
|
||||||
}
|
}
|
||||||
if(m_spritenode){
|
if(m_spritenode){
|
||||||
m_spritenode->setColor(color);
|
m_spritenode->setColor(color);
|
||||||
|
m_spritenode->setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1350,6 +1457,7 @@ void LuaEntityCAO::updateNodePos()
|
|||||||
void LuaEntityCAO::step(float dtime, ClientEnvironment *env)
|
void LuaEntityCAO::step(float dtime, ClientEnvironment *env)
|
||||||
{
|
{
|
||||||
pos_translator.translate(dtime);
|
pos_translator.translate(dtime);
|
||||||
|
updateNodePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaEntityCAO::processMessage(const std::string &data)
|
void LuaEntityCAO::processMessage(const std::string &data)
|
||||||
@ -1399,6 +1507,10 @@ void LuaEntityCAO::initialize(const std::string &data)
|
|||||||
|
|
||||||
infostream<<"m_prop: "<<m_prop->dump()<<std::endl;
|
infostream<<"m_prop: "<<m_prop->dump()<<std::endl;
|
||||||
|
|
||||||
|
m_selection_box = m_prop->collisionbox;
|
||||||
|
m_selection_box.MinEdge *= BS;
|
||||||
|
m_selection_box.MaxEdge *= BS;
|
||||||
|
|
||||||
pos_translator.init(m_position);
|
pos_translator.init(m_position);
|
||||||
|
|
||||||
updateNodePos();
|
updateNodePos();
|
||||||
|
@ -1656,6 +1656,11 @@ void LuaEntitySAO::moveTo(v3f pos, bool continuous)
|
|||||||
sendPosition(true, true);
|
sendPosition(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float LuaEntitySAO::getMinimumSavedMovement()
|
||||||
|
{
|
||||||
|
return 0.1 * BS;
|
||||||
|
}
|
||||||
|
|
||||||
void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
|
void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
|
||||||
{
|
{
|
||||||
m_last_sent_move_precision = m_base_position.getDistanceFrom(
|
m_last_sent_move_precision = m_base_position.getDistanceFrom(
|
||||||
|
@ -52,6 +52,8 @@ public:
|
|||||||
InventoryItem* createInventoryItem();
|
InventoryItem* createInventoryItem();
|
||||||
InventoryItem* createPickedUpItem(){return createInventoryItem();}
|
InventoryItem* createPickedUpItem(){return createInventoryItem();}
|
||||||
void rightClick(Player *player);
|
void rightClick(Player *player);
|
||||||
|
|
||||||
|
float getMinimumSavedMovement(){ return 0.1*BS; }
|
||||||
private:
|
private:
|
||||||
std::string m_inventorystring;
|
std::string m_inventorystring;
|
||||||
v3f m_speed_f;
|
v3f m_speed_f;
|
||||||
@ -218,6 +220,7 @@ public:
|
|||||||
|
|
||||||
void setPos(v3f pos);
|
void setPos(v3f pos);
|
||||||
void moveTo(v3f pos, bool continuous);
|
void moveTo(v3f pos, bool continuous);
|
||||||
|
float getMinimumSavedMovement();
|
||||||
private:
|
private:
|
||||||
void sendPosition(bool do_interpolate, bool is_movement_end);
|
void sendPosition(bool do_interpolate, bool is_movement_end);
|
||||||
|
|
||||||
|
@ -1749,8 +1749,10 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||||||
if(n){
|
if(n){
|
||||||
StaticObject static_old = n->getValue();
|
StaticObject static_old = n->getValue();
|
||||||
|
|
||||||
|
float save_movem = obj->getMinimumSavedMovement();
|
||||||
|
|
||||||
if(static_old.data == staticdata_new &&
|
if(static_old.data == staticdata_new &&
|
||||||
(static_old.pos - objectpos).getLength() < 2*BS)
|
(static_old.pos - objectpos).getLength() < save_movem)
|
||||||
data_changed = false;
|
data_changed = false;
|
||||||
} else {
|
} else {
|
||||||
errorstream<<"ServerEnvironment::deactivateFarObjects(): "
|
errorstream<<"ServerEnvironment::deactivateFarObjects(): "
|
||||||
@ -1760,6 +1762,8 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool shall_be_written = (!stays_in_same_block || data_changed);
|
||||||
|
|
||||||
// Delete old static object
|
// Delete old static object
|
||||||
if(obj->m_static_exists)
|
if(obj->m_static_exists)
|
||||||
{
|
{
|
||||||
@ -1769,7 +1773,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||||||
block->m_static_objects.remove(id);
|
block->m_static_objects.remove(id);
|
||||||
obj->m_static_exists = false;
|
obj->m_static_exists = false;
|
||||||
// Only mark block as modified if data changed considerably
|
// 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);
|
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);
|
block->m_static_objects.insert(new_id, s_obj);
|
||||||
|
|
||||||
// Only mark block as modified if data changed considerably
|
// 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);
|
block->raiseModified(MOD_STATE_WRITE_NEEDED);
|
||||||
|
|
||||||
obj->m_static_exists = true;
|
obj->m_static_exists = true;
|
||||||
|
@ -135,6 +135,10 @@ ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f
|
|||||||
/*
|
/*
|
||||||
Create an ItemSAO
|
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
|
// Create object
|
||||||
ServerActiveObject *obj = new ItemSAO(env, pos, getItemString());
|
ServerActiveObject *obj = new ItemSAO(env, pos, getItemString());
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -40,9 +40,8 @@ std::string LuaEntityProperties::dump()
|
|||||||
os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
|
os<<", collisionbox="<<PP(collisionbox.MinEdge)<<","<<PP(collisionbox.MaxEdge);
|
||||||
os<<", visual="<<visual;
|
os<<", visual="<<visual;
|
||||||
os<<", textures=[";
|
os<<", textures=[";
|
||||||
for(core::list<std::string>::Iterator i = textures.begin();
|
for(u32 i=0; i<textures.size(); i++){
|
||||||
i != textures.end(); i++){
|
os<<"\""<<textures[i]<<"\" ";
|
||||||
os<<"\""<<(*i)<<"\" ";
|
|
||||||
}
|
}
|
||||||
os<<"]";
|
os<<"]";
|
||||||
return os.str();
|
return os.str();
|
||||||
@ -57,9 +56,8 @@ void LuaEntityProperties::serialize(std::ostream &os)
|
|||||||
writeV3F1000(os, collisionbox.MaxEdge);
|
writeV3F1000(os, collisionbox.MaxEdge);
|
||||||
os<<serializeString(visual);
|
os<<serializeString(visual);
|
||||||
writeU16(os, textures.size());
|
writeU16(os, textures.size());
|
||||||
for(core::list<std::string>::Iterator i = textures.begin();
|
for(u32 i=0; i<textures.size(); i++){
|
||||||
i != textures.end(); i++){
|
os<<serializeString(textures[i]);
|
||||||
os<<serializeString(*i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,8 +72,8 @@ void LuaEntityProperties::deSerialize(std::istream &is)
|
|||||||
collisionbox.MaxEdge = readV3F1000(is);
|
collisionbox.MaxEdge = readV3F1000(is);
|
||||||
visual = deSerializeString(is);
|
visual = deSerializeString(is);
|
||||||
textures.clear();
|
textures.clear();
|
||||||
int texture_count = readU16(is);
|
u32 texture_count = readU16(is);
|
||||||
for(int i=0; i<texture_count; i++){
|
for(u32 i=0; i<texture_count; i++){
|
||||||
textures.push_back(deSerializeString(is));
|
textures.push_back(deSerializeString(is));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
struct LuaEntityProperties
|
struct LuaEntityProperties
|
||||||
{
|
{
|
||||||
|
// Values are BS=1
|
||||||
bool physical;
|
bool physical;
|
||||||
float weight;
|
float weight;
|
||||||
core::aabbox3d<f32> collisionbox;
|
core::aabbox3d<f32> collisionbox;
|
||||||
std::string visual;
|
std::string visual;
|
||||||
core::list<std::string> textures;
|
core::array<std::string> textures;
|
||||||
|
|
||||||
LuaEntityProperties();
|
LuaEntityProperties();
|
||||||
std::string dump();
|
std::string dump();
|
||||||
|
@ -791,6 +791,7 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime)
|
void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime)
|
||||||
|
@ -2853,10 +2853,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
// Calculate a position for it
|
// Calculate a position for it
|
||||||
v3f pos = intToFloat(p_over, BS);
|
v3f pos = intToFloat(p_over, BS);
|
||||||
//pos.Y -= BS*0.45;
|
//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
|
// Randomize a bit
|
||||||
pos.X += BS*0.2*(float)myrand_range(-1000,1000)/1000.0;
|
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
|
Create the object
|
||||||
|
@ -76,6 +76,9 @@ public:
|
|||||||
// continuous: if true, object does not stop immediately at pos
|
// continuous: if true, object does not stop immediately at pos
|
||||||
virtual void moveTo(v3f pos, bool continuous)
|
virtual void moveTo(v3f pos, bool continuous)
|
||||||
{ setBasePosition(pos); }
|
{ 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.
|
Step object in time.
|
||||||
|
Loading…
Reference in New Issue
Block a user