projects
/
oweals
/
minetest.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
1cc1b93
)
Add dtime_s to entity activation
author
Perttu Ahola
<celeron55@gmail.com>
Sun, 9 Sep 2012 14:12:29 +0000
(17:12 +0300)
committer
Perttu Ahola
<celeron55@gmail.com>
Sun, 9 Sep 2012 14:12:29 +0000
(17:12 +0300)
doc/lua_api.txt
patch
|
blob
|
history
src/content_sao.cpp
patch
|
blob
|
history
src/content_sao.h
patch
|
blob
|
history
src/environment.cpp
patch
|
blob
|
history
src/environment.h
patch
|
blob
|
history
src/scriptapi.cpp
patch
|
blob
|
history
src/scriptapi.h
patch
|
blob
|
history
src/serverobject.h
patch
|
blob
|
history
diff --git
a/doc/lua_api.txt
b/doc/lua_api.txt
index 782378c1f00fe31095d0b6747f97d04e89a2db1b..8c6fedc1e3f54a311d568c974dcc7bc57683bb22 100644
(file)
--- a/
doc/lua_api.txt
+++ b/
doc/lua_api.txt
@@
-1237,7
+1237,7
@@
Entity definition (register_entity)
initial_properties = <initial object properties>,
initial_properties = <initial object properties>,
- on_activate = function(self, staticdata),
+ on_activate = function(self, staticdata
, dtime_s
),
on_step = function(self, dtime),
on_punch = function(self, hitter),
on_rightclick = function(self, clicker),
on_step = function(self, dtime),
on_punch = function(self, hitter),
on_rightclick = function(self, clicker),
diff --git
a/src/content_sao.cpp
b/src/content_sao.cpp
index 843ab29f76b38841dec43e0f9547fec37a710f94..7526e03533bc1829bea4f9f9c5111f6ec99dce37 100644
(file)
--- a/
src/content_sao.cpp
+++ b/
src/content_sao.cpp
@@
-376,9
+376,9
@@
LuaEntitySAO::~LuaEntitySAO()
}
}
}
}
-void LuaEntitySAO::addedToEnvironment()
+void LuaEntitySAO::addedToEnvironment(
u32 dtime_s
)
{
{
- ServerActiveObject::addedToEnvironment();
+ ServerActiveObject::addedToEnvironment(
dtime_s
);
// Create entity from name
lua_State *L = m_env->getLua();
// Create entity from name
lua_State *L = m_env->getLua();
@@
-390,7
+390,7
@@
void LuaEntitySAO::addedToEnvironment()
// Initialize HP from properties
m_hp = m_prop.hp_max;
// Activate entity, supplying serialized state
// Initialize HP from properties
m_hp = m_prop.hp_max;
// Activate entity, supplying serialized state
- scriptapi_luaentity_activate(L, m_id, m_init_state.c_str());
+ scriptapi_luaentity_activate(L, m_id, m_init_state.c_str()
, dtime_s
);
}
}
}
}
@@
-805,9
+805,9
@@
std::string PlayerSAO::getDescription()
}
// Called after id has been set and has been inserted in environment
}
// Called after id has been set and has been inserted in environment
-void PlayerSAO::addedToEnvironment()
+void PlayerSAO::addedToEnvironment(
u32 dtime_s
)
{
{
- ServerActiveObject::addedToEnvironment();
+ ServerActiveObject::addedToEnvironment(
dtime_s
);
ServerActiveObject::setBasePosition(m_player->getPosition());
m_player->setPlayerSAO(this);
m_player->peer_id = m_peer_id;
ServerActiveObject::setBasePosition(m_player->getPosition());
m_player->setPlayerSAO(this);
m_player->peer_id = m_peer_id;
diff --git
a/src/content_sao.h
b/src/content_sao.h
index ff427bac63c5d0b64c51bd3a68c18baaf7002ba2..05c77e2cb92e861b5be28437cca61255aeb281d8 100644
(file)
--- a/
src/content_sao.h
+++ b/
src/content_sao.h
@@
-43,7
+43,7
@@
public:
{ return ACTIVEOBJECT_TYPE_LUAENTITY; }
u8 getSendType() const
{ return ACTIVEOBJECT_TYPE_GENERIC; }
{ return ACTIVEOBJECT_TYPE_LUAENTITY; }
u8 getSendType() const
{ return ACTIVEOBJECT_TYPE_GENERIC; }
- virtual void addedToEnvironment();
+ virtual void addedToEnvironment(
u32 dtime_s
);
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
const std::string &data);
void step(float dtime, bool send_recommended);
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
const std::string &data);
void step(float dtime, bool send_recommended);
@@
-118,7
+118,7
@@
public:
Active object <-> environment interface
*/
Active object <-> environment interface
*/
- void addedToEnvironment();
+ void addedToEnvironment(
u32 dtime_s
);
void removingFromEnvironment();
bool isStaticAllowed() const;
bool unlimitedTransferDistance() const;
void removingFromEnvironment();
bool isStaticAllowed() const;
bool unlimitedTransferDistance() const;
diff --git
a/src/environment.cpp
b/src/environment.cpp
index 10ebd412729a394d6e651c238a2327fb4ae89f2b..4abba63599f4f3a1157a99677d2dca56260e53f4 100644
(file)
--- a/
src/environment.cpp
+++ b/
src/environment.cpp
@@
-790,7
+790,7
@@
void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
<<dtime_s<<" seconds old."<<std::endl;*/
// Activate stored objects
<<dtime_s<<" seconds old."<<std::endl;*/
// Activate stored objects
- activateObjects(block);
+ activateObjects(block
, dtime_s
);
// Run node timers
std::map<v3s16, NodeTimer> elapsed_timers =
// Run node timers
std::map<v3s16, NodeTimer> elapsed_timers =
@@
-1249,7
+1249,7
@@
u16 getFreeServerActiveObjectId(
u16 ServerEnvironment::addActiveObject(ServerActiveObject *object)
{
assert(object);
u16 ServerEnvironment::addActiveObject(ServerActiveObject *object)
{
assert(object);
- u16 id = addActiveObjectRaw(object, true);
+ u16 id = addActiveObjectRaw(object, true
, 0
);
return id;
}
return id;
}
@@
-1408,7
+1408,7
@@
ActiveObjectMessage ServerEnvironment::getActiveObjectMessage()
*/
u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
*/
u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
- bool set_changed)
+ bool set_changed
, u32 dtime_s
)
{
assert(object);
if(object->getId() == 0){
{
assert(object);
if(object->getId() == 0){
@@
-1448,7
+1448,7
@@
u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
// Register reference in scripting api (must be done before post-init)
scriptapi_add_object_reference(m_lua, object);
// Post-initialize object
// Register reference in scripting api (must be done before post-init)
scriptapi_add_object_reference(m_lua, object);
// Post-initialize object
- object->addedToEnvironment();
+ object->addedToEnvironment(
dtime_s
);
// Add static data to block
if(object->isStaticAllowed())
// Add static data to block
if(object->isStaticAllowed())
@@
-1585,7
+1585,7
@@
static void print_hexdump(std::ostream &o, const std::string &data)
/*
Convert stored objects from blocks near the players to active.
*/
/*
Convert stored objects from blocks near the players to active.
*/
-void ServerEnvironment::activateObjects(MapBlock *block)
+void ServerEnvironment::activateObjects(MapBlock *block
, u32 dtime_s
)
{
if(block==NULL)
return;
{
if(block==NULL)
return;
@@
-1609,7
+1609,7
@@
void ServerEnvironment::activateObjects(MapBlock *block)
"large amount of objects");
return;
}
"large amount of objects");
return;
}
- // A list for objects that couldn't be converted to
static
for some
+ // A list for objects that couldn't be converted to
active
for some
// reason. They will be stored back.
core::list<StaticObject> new_stored;
// Loop through stored static objects
// reason. They will be stored back.
core::list<StaticObject> new_stored;
// Loop through stored static objects
@@
-1639,7
+1639,7
@@
void ServerEnvironment::activateObjects(MapBlock *block)
<<"activated static object pos="<<PP(s_obj.pos/BS)
<<" type="<<(int)s_obj.type<<std::endl;
// This will also add the object to the active static list
<<"activated static object pos="<<PP(s_obj.pos/BS)
<<" type="<<(int)s_obj.type<<std::endl;
// This will also add the object to the active static list
- addActiveObjectRaw(obj, false);
+ addActiveObjectRaw(obj, false
, dtime_s
);
}
// Clear stored list
block->m_static_objects.m_stored.clear();
}
// Clear stored list
block->m_static_objects.m_stored.clear();
diff --git
a/src/environment.h
b/src/environment.h
index bb1da2461e7baa2c55b28dbe2cce78efd5b24b0e..0422290388b1f19859fd77320bf56d4611237987 100644
(file)
--- a/
src/environment.h
+++ b/
src/environment.h
@@
-312,7
+312,7
@@
private:
Returns the id of the object.
Returns 0 if not added and thus deleted.
*/
Returns the id of the object.
Returns 0 if not added and thus deleted.
*/
- u16 addActiveObjectRaw(ServerActiveObject *object, bool set_changed);
+ u16 addActiveObjectRaw(ServerActiveObject *object, bool set_changed
, u32 dtime_s
);
/*
Remove all objects that satisfy (m_removed && m_known_by_count==0)
/*
Remove all objects that satisfy (m_removed && m_known_by_count==0)
@@
-322,7
+322,7
@@
private:
/*
Convert stored objects from block to active
*/
/*
Convert stored objects from block to active
*/
- void activateObjects(MapBlock *block);
+ void activateObjects(MapBlock *block
, u32 dtime_s
);
/*
Convert objects that are not in active blocks to static.
/*
Convert objects that are not in active blocks to static.
diff --git
a/src/scriptapi.cpp
b/src/scriptapi.cpp
index 39e2a46e4f520b3c3aac23078ecfe359b40af6b4..9fa927ff34e486d6b1e0e662b8665f2d54b8167b 100644
(file)
--- a/
src/scriptapi.cpp
+++ b/
src/scriptapi.cpp
@@
-6483,7
+6483,7
@@
bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name)
}
void scriptapi_luaentity_activate(lua_State *L, u16 id,
}
void scriptapi_luaentity_activate(lua_State *L, u16 id,
- const std::string &staticdata)
+ const std::string &staticdata
, u32 dtime_s
)
{
realitycheck(L);
assert(lua_checkstack(L, 20));
{
realitycheck(L);
assert(lua_checkstack(L, 20));
@@
-6501,8
+6501,9
@@
void scriptapi_luaentity_activate(lua_State *L, u16 id,
luaL_checktype(L, -1, LUA_TFUNCTION);
lua_pushvalue(L, object); // self
lua_pushlstring(L, staticdata.c_str(), staticdata.size());
luaL_checktype(L, -1, LUA_TFUNCTION);
lua_pushvalue(L, object); // self
lua_pushlstring(L, staticdata.c_str(), staticdata.size());
- // Call with 2 arguments, 0 results
- if(lua_pcall(L, 2, 0, 0))
+ lua_pushinteger(L, dtime_s);
+ // Call with 3 arguments, 0 results
+ if(lua_pcall(L, 3, 0, 0))
script_error(L, "error running function on_activate: %s\n",
lua_tostring(L, -1));
}
script_error(L, "error running function on_activate: %s\n",
lua_tostring(L, -1));
}
diff --git
a/src/scriptapi.h
b/src/scriptapi.h
index 0ae3591122530c57d53c2a4630d510e6b108345c..144cb3bc6d556c59b08ec5f38871fc62ed0d5ea1 100644
(file)
--- a/
src/scriptapi.h
+++ b/
src/scriptapi.h
@@
-167,7
+167,7
@@
void scriptapi_detached_inventory_on_take(lua_State *L,
// Returns true if succesfully added into Lua; false otherwise.
bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name);
void scriptapi_luaentity_activate(lua_State *L, u16 id,
// Returns true if succesfully added into Lua; false otherwise.
bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name);
void scriptapi_luaentity_activate(lua_State *L, u16 id,
- const std::string &staticdata);
+ const std::string &staticdata
, u32 dtime_s
);
void scriptapi_luaentity_rm(lua_State *L, u16 id);
std::string scriptapi_luaentity_get_staticdata(lua_State *L, u16 id);
void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
void scriptapi_luaentity_rm(lua_State *L, u16 id);
std::string scriptapi_luaentity_get_staticdata(lua_State *L, u16 id);
void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
diff --git
a/src/serverobject.h
b/src/serverobject.h
index 6acd0dfeea9c753176efe0c9027df38a577ae6b6..ece53fd98f278e1255c20d2c053ad575a5de7130 100644
(file)
--- a/
src/serverobject.h
+++ b/
src/serverobject.h
@@
-62,7
+62,7
@@
public:
{ return getType(); }
// Called after id has been set and has been inserted in environment
{ return getType(); }
// Called after id has been set and has been inserted in environment
- virtual void addedToEnvironment(){};
+ virtual void addedToEnvironment(
u32 dtime_s
){};
// Called before removing from environment
virtual void removingFromEnvironment(){};
// Returns true if object's deletion is the job of the
// Called before removing from environment
virtual void removingFromEnvironment(){};
// Returns true if object's deletion is the job of the