2014-09-26 16:03:38 +03:00
|
|
|
-- Buildat: client/api.lua
|
|
|
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
-- Copyright 2014 Perttu Ahola <celeron55@gmail.com>
|
|
|
|
local log = buildat.Logger("__client/api")
|
|
|
|
|
2014-09-27 07:44:54 +03:00
|
|
|
buildat.connect_server = __buildat_connect_server
|
|
|
|
buildat.extension_path = __buildat_extension_path
|
2014-10-14 09:45:16 +03:00
|
|
|
buildat.get_time_us = __buildat_get_time_us
|
2014-09-26 16:03:38 +03:00
|
|
|
|
2014-09-27 09:54:53 +03:00
|
|
|
buildat.safe.disconnect = __buildat_disconnect
|
2014-10-14 09:45:16 +03:00
|
|
|
buildat.safe.get_time_us = __buildat_get_time_us
|
2014-09-27 09:54:53 +03:00
|
|
|
|
2014-10-12 13:28:24 +03:00
|
|
|
function buildat.safe.set_simple_voxel_model(safe_node, w, h, d, safe_buffer)
|
2014-10-05 19:49:12 +03:00
|
|
|
if not getmetatable(safe_node) or
|
|
|
|
getmetatable(safe_node).type_name ~= "Node" then
|
2014-10-12 13:28:24 +03:00
|
|
|
error("node is not a sandboxed Node instance")
|
|
|
|
end
|
2014-10-05 19:49:12 +03:00
|
|
|
node = getmetatable(safe_node).unsafe
|
2014-10-12 13:53:07 +03:00
|
|
|
|
|
|
|
buffer = nil
|
|
|
|
if type(safe_buffer) == 'string' then
|
|
|
|
buffer = safe_buffer
|
|
|
|
else
|
|
|
|
if not getmetatable(safe_buffer) or
|
|
|
|
getmetatable(safe_buffer).type_name ~= "VectorBuffer" then
|
|
|
|
error("safe_buffer is not a sandboxed VectorBuffer instance")
|
|
|
|
end
|
|
|
|
buffer = getmetatable(safe_buffer).unsafe
|
|
|
|
end
|
|
|
|
|
2014-10-12 13:28:24 +03:00
|
|
|
__buildat_set_simple_voxel_model(node, w, h, d, buffer)
|
2014-10-05 19:49:12 +03:00
|
|
|
end
|
|
|
|
|
2014-10-12 13:28:24 +03:00
|
|
|
function buildat.safe.set_8bit_voxel_geometry(safe_node, w, h, d, safe_buffer)
|
2014-10-08 16:51:16 +03:00
|
|
|
if not getmetatable(safe_node) or
|
|
|
|
getmetatable(safe_node).type_name ~= "Node" then
|
2014-10-12 13:28:24 +03:00
|
|
|
error("node is not a sandboxed Node instance")
|
|
|
|
end
|
2014-10-08 16:51:16 +03:00
|
|
|
node = getmetatable(safe_node).unsafe
|
2014-10-12 13:53:07 +03:00
|
|
|
|
|
|
|
buffer = nil
|
|
|
|
if type(safe_buffer) == 'string' then
|
|
|
|
buffer = safe_buffer
|
|
|
|
else
|
|
|
|
if not getmetatable(safe_buffer) or
|
|
|
|
getmetatable(safe_buffer).type_name ~= "VectorBuffer" then
|
|
|
|
error("safe_buffer is not a sandboxed VectorBuffer instance")
|
|
|
|
end
|
|
|
|
buffer = getmetatable(safe_buffer).unsafe
|
|
|
|
end
|
2014-10-12 13:28:24 +03:00
|
|
|
__buildat_set_8bit_voxel_geometry(node, w, h, d, buffer)
|
2014-10-08 16:51:16 +03:00
|
|
|
end
|
|
|
|
|
2014-10-12 14:49:11 +03:00
|
|
|
function buildat.safe.set_voxel_geometry(safe_node, safe_buffer)
|
|
|
|
if not getmetatable(safe_node) or
|
|
|
|
getmetatable(safe_node).type_name ~= "Node" then
|
|
|
|
error("node is not a sandboxed Node instance")
|
|
|
|
end
|
|
|
|
node = getmetatable(safe_node).unsafe
|
|
|
|
|
|
|
|
buffer = nil
|
|
|
|
if type(safe_buffer) == 'string' then
|
|
|
|
buffer = safe_buffer
|
|
|
|
else
|
|
|
|
if not getmetatable(safe_buffer) or
|
|
|
|
getmetatable(safe_buffer).type_name ~= "VectorBuffer" then
|
|
|
|
error("safe_buffer is not a sandboxed VectorBuffer instance")
|
|
|
|
end
|
|
|
|
buffer = getmetatable(safe_buffer).unsafe
|
|
|
|
end
|
|
|
|
__buildat_set_voxel_geometry(node, buffer)
|
|
|
|
end
|
|
|
|
|
2014-10-13 18:56:28 +03:00
|
|
|
function buildat.safe.set_voxel_physics_boxes(safe_node, safe_buffer)
|
|
|
|
if not getmetatable(safe_node) or
|
|
|
|
getmetatable(safe_node).type_name ~= "Node" then
|
|
|
|
error("node is not a sandboxed Node instance")
|
|
|
|
end
|
|
|
|
node = getmetatable(safe_node).unsafe
|
|
|
|
|
|
|
|
buffer = nil
|
|
|
|
if type(safe_buffer) == 'string' then
|
|
|
|
buffer = safe_buffer
|
|
|
|
else
|
|
|
|
if not getmetatable(safe_buffer) or
|
|
|
|
getmetatable(safe_buffer).type_name ~= "VectorBuffer" then
|
|
|
|
error("safe_buffer is not a sandboxed VectorBuffer instance")
|
|
|
|
end
|
|
|
|
buffer = getmetatable(safe_buffer).unsafe
|
|
|
|
end
|
|
|
|
__buildat_set_voxel_physics_boxes(node, buffer)
|
|
|
|
end
|
|
|
|
|
2014-10-12 11:26:29 +03:00
|
|
|
local IntVector3_prototype = {
|
|
|
|
x = 0,
|
|
|
|
y = 0,
|
|
|
|
z = 0,
|
|
|
|
mul_components = function(a, b)
|
|
|
|
return buildat.safe.IntVector3(
|
|
|
|
a.x * b.x, a.y * b.y, a.z * b.z)
|
|
|
|
end,
|
|
|
|
div_components = function(a, b)
|
|
|
|
return buildat.safe.IntVector3(
|
|
|
|
a.x / b.x, a.y / b.y, a.z / b.z)
|
|
|
|
end,
|
|
|
|
floor = function(a)
|
|
|
|
return buildat.safe.IntVector3(
|
|
|
|
math.floor(a.x), math.floor(a.y), math.floor(a.z))
|
|
|
|
end,
|
|
|
|
add = function(a, b)
|
|
|
|
return buildat.safe.IntVector3(
|
|
|
|
a.x + b.x, a.y + b.y, a.z + b.z)
|
|
|
|
end,
|
|
|
|
sub = function(a, b)
|
|
|
|
return buildat.safe.IntVector3(
|
|
|
|
a.x - b.x, a.y - b.y, a.z - b.z)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
function buildat.safe.IntVector3(x, y, z)
|
|
|
|
local self = {}
|
|
|
|
if x ~= nil and y == nil and z == nil then
|
|
|
|
self.x = x.x
|
|
|
|
self.y = x.y
|
|
|
|
self.z = x.z
|
|
|
|
else
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
self.z = z
|
|
|
|
end
|
|
|
|
setmetatable(self, {
|
|
|
|
__index = IntVector3_prototype,
|
|
|
|
__add = IntVector3_prototype.add,
|
|
|
|
__sub = IntVector3_prototype.sub,
|
|
|
|
})
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
2014-09-26 16:03:38 +03:00
|
|
|
-- vim: set noet ts=4 sw=4:
|