summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-02-21 16:10:36 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-02-21 16:10:36 +0200
commit69dbc046eb5a82b38c6d5c3302e9b3b0b3c1bcf1 (patch)
treee892b50187ba7343cb75f359ccbb55bdde19afd5 /data
parentc57637b4c39319e0c0d5d80d0ae2884aec66d691 (diff)
downloadminetest-69dbc046eb5a82b38c6d5c3302e9b3b0b3c1bcf1.tar.gz
minetest-69dbc046eb5a82b38c6d5c3302e9b3b0b3c1bcf1.tar.bz2
minetest-69dbc046eb5a82b38c6d5c3302e9b3b0b3c1bcf1.zip
preliminary lua scripting framework for objects
Diffstat (limited to 'data')
-rw-r--r--data/grass2.pngbin493 -> 0 bytes
-rw-r--r--data/luaobjects/test/client.lua73
-rw-r--r--data/luaobjects/test/server.lua90
-rw-r--r--data/skybox1.pngbin19476 -> 0 bytes
-rw-r--r--data/skybox1_source.pngbin5477 -> 0 bytes
-rw-r--r--data/skybox2.pngbin2272 -> 0 bytes
-rw-r--r--data/skybox3.pngbin2272 -> 0 bytes
-rw-r--r--data/stone_with_arrow.pngbin856 -> 0 bytes
-rw-r--r--data/tf.jpgbin39989 -> 0 bytes
9 files changed, 163 insertions, 0 deletions
diff --git a/data/grass2.png b/data/grass2.png
deleted file mode 100644
index 66b3e58b5..000000000
--- a/data/grass2.png
+++ /dev/null
Binary files differ
diff --git a/data/luaobjects/test/client.lua b/data/luaobjects/test/client.lua
new file mode 100644
index 000000000..80f085190
--- /dev/null
+++ b/data/luaobjects/test/client.lua
@@ -0,0 +1,73 @@
+-- Client-side code of the test lua object
+
+--
+-- Some helper functions
+--
+
+function split(str, pat)
+ local t = {} -- NOTE: use {n = 0} in Lua-5.0
+ local fpat = "(.-)" .. pat
+ local last_end = 1
+ local s, e, cap = str:find(fpat, 1)
+ while s do
+ if s ~= 1 or cap ~= "" then
+ table.insert(t,cap)
+ end
+ last_end = e+1
+ s, e, cap = str:find(fpat, last_end)
+ end
+ if last_end <= #str then
+ cap = str:sub(last_end)
+ table.insert(t, cap)
+ end
+ return t
+end
+
+function dump(o)
+ if type(o) == 'table' then
+ local s = '{ '
+ for k,v in pairs(o) do
+ if type(k) ~= 'number' then k = '"'..k..'"' end
+ s = s .. '['..k..'] = ' .. dump(v) .. ','
+ end
+ return s .. '} '
+ else
+ return tostring(o)
+ end
+end
+
+--
+-- Actual code
+--
+
+function step(self, dtime)
+ -- Some smoother animation could be done here
+end
+
+function process_message(self, data)
+ --print("client got message: " .. data)
+
+ -- Receive our custom messages
+
+ sp = split(data, " ")
+ if sp[1] == "pos" then
+ object_set_position(self, sp[2], sp[3], sp[4])
+ end
+ if sp[1] == "rot" then
+ object_set_rotation(self, sp[2], sp[3], sp[4])
+ end
+end
+
+function initialize(self, data)
+ print("client object got initialization: " .. data)
+
+ corners = {
+ {-1/2,-1/4, 0},
+ { 1/2,-1/4, 0},
+ { 1/2, 1/4, 0},
+ {-1/2, 1/4, 0},
+ }
+ object_add_to_mesh(self, "rat.png", corners, false)
+
+end
+
diff --git a/data/luaobjects/test/server.lua b/data/luaobjects/test/server.lua
new file mode 100644
index 000000000..ac7b4800d
--- /dev/null
+++ b/data/luaobjects/test/server.lua
@@ -0,0 +1,90 @@
+-- Server-side code of the test lua object
+
+counter = 0
+counter2 = 0
+death_counter = 0
+position = {X=math.random(-2,2),Y=6,Z=math.random(-2,2)}
+rotation = {X=0, Y=math.random(0,360), Z=0}
+dir = 1
+
+function step(self, dtime)
+ --[[if position.Y > 9.5 then
+ position.Y = 6
+ end
+ if position.Y < 5.5 then
+ position.Y = 9
+
+ counter2 = counter2 - dtime
+ if counter2 < 0 then
+ counter2 = counter2 + 3
+ dir = -dir
+ end]]
+
+ -- Limit step to a sane value; it jumps a lot while the map generator
+ -- is in action
+ if dtime > 0.5 then
+ dtime = 0.5
+ end
+
+ -- Returned value has these fields:
+ -- * bool walkable
+ -- * int content
+ n = object_get_node(self, position.X,position.Y-0.35,position.Z)
+ if n.walkable then
+ dir = 1
+ else
+ dir = -1
+ end
+ -- Keep the object approximately at ground level
+ position.Y = position.Y + dtime * 1.0 * dir
+
+ -- Move the object around
+ position.X = position.X + math.cos(math.pi+rotation.Y/180*math.pi)
+ * dtime * 2.0
+ position.Z = position.Z + math.sin(math.pi+rotation.Y/180*math.pi)
+ * dtime * 2.0
+
+ -- This value has to be set; it determines to which player the
+ -- object is near to and such
+ object_set_base_position(self, position.X,position.Y,position.Z)
+
+ rotation.Y = rotation.Y + dtime * 180
+
+ -- Send some custom messages at a custom interval
+
+ counter = counter - dtime
+ if counter < 0 then
+ counter = counter + 0.175
+
+ message = "pos " .. position.X .. " " .. position.Y .. " " .. position.Z
+ object_add_message(self, message)
+
+ message = "rot " .. rotation.X .. " " .. rotation.Y .. " " .. rotation.Z
+ object_add_message(self, message)
+ end
+
+ -- Remove the object after some time
+ death_counter = death_counter + dtime
+ if death_counter > 30 then
+ object_remove(self)
+ end
+
+end
+
+-- This stuff is passed to a newly created client-side counterpart of this object
+function get_client_init_data(self)
+ return "result of get_client_init_data"
+end
+
+-- This should return some data that mostly saves the state of this object
+-- Not implemented yet
+function get_server_init_data(self)
+ return "result of get_server_init_data"
+end
+
+-- At reload time, the output of get_server_init_data is passed to this
+-- Not implemented yet
+function initialize(self, data)
+ print("server object got initialization: " .. data)
+end
+
diff --git a/data/skybox1.png b/data/skybox1.png
deleted file mode 100644
index 202e40eba..000000000
--- a/data/skybox1.png
+++ /dev/null
Binary files differ
diff --git a/data/skybox1_source.png b/data/skybox1_source.png
deleted file mode 100644
index 642e89ce4..000000000
--- a/data/skybox1_source.png
+++ /dev/null
Binary files differ
diff --git a/data/skybox2.png b/data/skybox2.png
deleted file mode 100644
index f09a8cbf1..000000000
--- a/data/skybox2.png
+++ /dev/null
Binary files differ
diff --git a/data/skybox3.png b/data/skybox3.png
deleted file mode 100644
index 9a37734c8..000000000
--- a/data/skybox3.png
+++ /dev/null
Binary files differ
diff --git a/data/stone_with_arrow.png b/data/stone_with_arrow.png
deleted file mode 100644
index d64470675..000000000
--- a/data/stone_with_arrow.png
+++ /dev/null
Binary files differ
diff --git a/data/tf.jpg b/data/tf.jpg
deleted file mode 100644
index d08b6c95e..000000000
--- a/data/tf.jpg
+++ /dev/null
Binary files differ