add 'camera' library
This commit is contained in:
parent
24ecb94942
commit
ffb7aa1189
@ -252,9 +252,11 @@ function session.reset_entry(name)
|
|||||||
session.entries[name] = nil
|
session.entries[name] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function timeit(func, ...)
|
function timeit(iters, func, ...)
|
||||||
local tm = time.uptime()
|
local tm = time.uptime()
|
||||||
|
for i=1,iters do
|
||||||
func(...)
|
func(...)
|
||||||
|
end
|
||||||
print("[time mcs]", (time.uptime()-tm) * 1000000)
|
print("[time mcs]", (time.uptime()-tm) * 1000000)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,18 @@
|
|||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
|
/// Definitions can be found in local .cpp files
|
||||||
|
/// having same names as declarations
|
||||||
|
|
||||||
|
/// l_ prefix means that function is lua_CFunction:
|
||||||
|
/// int l_function_name(lua_State* L);
|
||||||
|
/// use following syntax:
|
||||||
|
/// int l_function_name(lua::State* L);
|
||||||
|
|
||||||
// Libraries
|
// Libraries
|
||||||
extern const luaL_Reg audiolib [];
|
extern const luaL_Reg audiolib [];
|
||||||
extern const luaL_Reg blocklib [];
|
extern const luaL_Reg blocklib [];
|
||||||
|
extern const luaL_Reg cameralib [];
|
||||||
extern const luaL_Reg consolelib [];
|
extern const luaL_Reg consolelib [];
|
||||||
extern const luaL_Reg corelib [];
|
extern const luaL_Reg corelib [];
|
||||||
extern const luaL_Reg entitylib [];
|
extern const luaL_Reg entitylib [];
|
||||||
@ -23,9 +32,9 @@ extern const luaL_Reg packlib [];
|
|||||||
extern const luaL_Reg playerlib [];
|
extern const luaL_Reg playerlib [];
|
||||||
extern const luaL_Reg timelib [];
|
extern const luaL_Reg timelib [];
|
||||||
extern const luaL_Reg tomllib [];
|
extern const luaL_Reg tomllib [];
|
||||||
extern const luaL_Reg vec2lib [];
|
extern const luaL_Reg vec2lib []; // vecn.cpp
|
||||||
extern const luaL_Reg vec3lib [];
|
extern const luaL_Reg vec3lib []; // vecn.cpp
|
||||||
extern const luaL_Reg vec4lib [];
|
extern const luaL_Reg vec4lib []; // vecn.cpp
|
||||||
extern const luaL_Reg worldlib [];
|
extern const luaL_Reg worldlib [];
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
#include "libentity.hpp"
|
#include "libentity.hpp"
|
||||||
|
|
||||||
static int l_transform_get_pos(lua::State* L) {
|
static int l_get_pos(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
return lua::pushvec3_arr(L, entity->getTransform().pos);
|
return lua::pushvec3_arr(L, entity->getTransform().pos);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_transform_set_pos(lua::State* L) {
|
static int l_set_pos(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
auto vec = lua::tovec3(L, 2);
|
auto vec = lua::tovec3(L, 2);
|
||||||
entity->getTransform().setPos(vec);
|
entity->getTransform().setPos(vec);
|
||||||
@ -16,28 +16,28 @@ static int l_transform_set_pos(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_transform_get_size(lua::State* L) {
|
static int l_get_size(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
return lua::pushvec3_arr(L, entity->getTransform().size);
|
return lua::pushvec3_arr(L, entity->getTransform().size);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_transform_set_size(lua::State* L) {
|
static int l_set_size(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
entity->getTransform().setSize(lua::tovec3(L, 2));
|
entity->getTransform().setSize(lua::tovec3(L, 2));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_transform_get_rot(lua::State* L) {
|
static int l_get_rot(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
return lua::pushmat4(L, entity->getTransform().rot);
|
return lua::pushmat4(L, entity->getTransform().rot);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_transform_set_rot(lua::State* L) {
|
static int l_set_rot(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
entity->getTransform().setRot(lua::tomat4(L, 2));
|
entity->getTransform().setRot(lua::tomat4(L, 2));
|
||||||
}
|
}
|
||||||
@ -45,11 +45,11 @@ static int l_transform_set_rot(lua::State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const luaL_Reg transformlib [] = {
|
const luaL_Reg transformlib [] = {
|
||||||
{"get_pos", lua::wrap<l_transform_get_pos>},
|
{"get_pos", lua::wrap<l_get_pos>},
|
||||||
{"set_pos", lua::wrap<l_transform_set_pos>},
|
{"set_pos", lua::wrap<l_set_pos>},
|
||||||
{"get_size", lua::wrap<l_transform_get_size>},
|
{"get_size", lua::wrap<l_get_size>},
|
||||||
{"set_size", lua::wrap<l_transform_set_size>},
|
{"set_size", lua::wrap<l_set_size>},
|
||||||
{"get_rot", lua::wrap<l_transform_get_rot>},
|
{"get_rot", lua::wrap<l_get_rot>},
|
||||||
{"set_rot", lua::wrap<l_transform_set_rot>},
|
{"set_rot", lua::wrap<l_set_rot>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
18
src/logic/scripting/lua/libcamera.cpp
Normal file
18
src/logic/scripting/lua/libcamera.cpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#include "api_lua.hpp"
|
||||||
|
|
||||||
|
#include "../../../content/Content.hpp"
|
||||||
|
#include "../../../world/Level.hpp"
|
||||||
|
|
||||||
|
using namespace scripting;
|
||||||
|
|
||||||
|
int l_index(lua::State* L) {
|
||||||
|
auto name = lua::require_string(L, 1);
|
||||||
|
auto& indices = content->getIndices(ResourceType::CAMERA);
|
||||||
|
std::cout << "index: " << name << std::endl;
|
||||||
|
return lua::pushinteger(L, indices.indexOf(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg cameralib [] = {
|
||||||
|
{"index", lua::wrap<l_index>},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
@ -8,11 +8,11 @@
|
|||||||
|
|
||||||
using namespace scripting;
|
using namespace scripting;
|
||||||
|
|
||||||
static int l_entity_exists(lua::State* L) {
|
static int l_exists(lua::State* L) {
|
||||||
return lua::pushboolean(L, get_entity(L, 1).has_value());
|
return lua::pushboolean(L, get_entity(L, 1).has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_entity_spawn(lua::State* L) {
|
static int l_spawn(lua::State* L) {
|
||||||
auto level = controller->getLevel();
|
auto level = controller->getLevel();
|
||||||
auto defname = lua::tostring(L, 1);
|
auto defname = lua::tostring(L, 1);
|
||||||
auto& def = content->entities.require(defname);
|
auto& def = content->entities.require(defname);
|
||||||
@ -25,14 +25,14 @@ static int l_entity_spawn(lua::State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_entity_despawn(lua::State* L) {
|
static int l_despawn(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
entity->destroy();
|
entity->destroy();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_entity_set_rig(lua::State* L) {
|
static int l_set_rig(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
std::string skeletonName = lua::require_string(L, 2);
|
std::string skeletonName = lua::require_string(L, 2);
|
||||||
auto rigConfig = content->getRig(skeletonName);
|
auto rigConfig = content->getRig(skeletonName);
|
||||||
@ -45,9 +45,9 @@ static int l_entity_set_rig(lua::State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const luaL_Reg entitylib [] = {
|
const luaL_Reg entitylib [] = {
|
||||||
{"exists", lua::wrap<l_entity_exists>},
|
{"exists", lua::wrap<l_exists>},
|
||||||
{"spawn", lua::wrap<l_entity_spawn>},
|
{"spawn", lua::wrap<l_spawn>},
|
||||||
{"despawn", lua::wrap<l_entity_despawn>},
|
{"despawn", lua::wrap<l_despawn>},
|
||||||
{"set_rig", lua::wrap<l_entity_set_rig>},
|
{"set_rig", lua::wrap<l_set_rig>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -48,6 +48,7 @@ static void create_libs(lua::State* L) {
|
|||||||
openlib(L, "world", worldlib);
|
openlib(L, "world", worldlib);
|
||||||
|
|
||||||
openlib(L, "entities", entitylib);
|
openlib(L, "entities", entitylib);
|
||||||
|
openlib(L, "cameras", cameralib);
|
||||||
|
|
||||||
// components
|
// components
|
||||||
openlib(L, "__skeleton", skeletonlib);
|
openlib(L, "__skeleton", skeletonlib);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user