aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-11-12 17:46:06 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-11-29 19:13:40 +0200
commit73bb3bc5958989db21eefb826e277dada248ceca (patch)
tree1d87277d92ff54fdc32cfd735934b11ec182a69a /src
parent1320d07068f25ff23ea27e120983c006f75bec24 (diff)
downloadminetest-73bb3bc5958989db21eefb826e277dada248ceca.tar.gz
minetest-73bb3bc5958989db21eefb826e277dada248ceca.tar.bz2
minetest-73bb3bc5958989db21eefb826e277dada248ceca.zip
Scripting WIP: Add global environment step function on_step
Diffstat (limited to 'src')
-rw-r--r--src/environment.cpp5
-rw-r--r--src/scriptapi.cpp23
-rw-r--r--src/scriptapi.h4
3 files changed, 31 insertions, 1 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index d3e8fa12c..29432bc5e 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -1142,6 +1142,11 @@ void ServerEnvironment::step(float dtime)
}
/*
+ Step script environment (run global on_step())
+ */
+ scriptapi_environment_step(m_lua, dtime);
+
+ /*
Step active objects
*/
{
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index 530c1719e..381664489 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -40,7 +40,9 @@ extern "C" {
TODO:
- Global environment step function
- Random node triggers
-- Object network and client-side stuff
+- Object visual client-side stuff
+ - Blink effect
+ - Spritesheets and animation
- Named node types and dynamic id allocation
- LuaNodeMetadata
blockdef.has_metadata = true/false
@@ -670,6 +672,25 @@ void scriptapi_rm_object_reference(lua_State *L, ServerActiveObject *cobj)
}
/*
+ environment
+*/
+
+void scriptapi_environment_step(lua_State *L, float dtime)
+{
+ realitycheck(L);
+ assert(lua_checkstack(L, 20));
+ //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl;
+ StackUnroller stack_unroller(L);
+
+ lua_getglobal(L, "on_step");
+ if(lua_type(L, -1) != LUA_TFUNCTION)
+ return; // If no on_step function exist, do nothing
+ lua_pushnumber(L, dtime);
+ if(lua_pcall(L, 1, 0, 0))
+ script_error(L, "error: %s\n", lua_tostring(L, -1));
+}
+
+/*
luaentity
*/
diff --git a/src/scriptapi.h b/src/scriptapi.h
index 458f90acb..c63977fc6 100644
--- a/src/scriptapi.h
+++ b/src/scriptapi.h
@@ -35,6 +35,10 @@ void scriptapi_add_environment(lua_State *L, ServerEnvironment *env);
void scriptapi_add_object_reference(lua_State *L, ServerActiveObject *cobj);
void scriptapi_rm_object_reference(lua_State *L, ServerActiveObject *cobj);
+/* environment */
+void scriptapi_environment_step(lua_State *L, float dtime);
+
+/* luaentity */
void scriptapi_luaentity_add(lua_State *L, u16 id, const char *name,
const char *init_state);
void scriptapi_luaentity_rm(lua_State *L, u16 id);