add entity library
This commit is contained in:
@@ -8,19 +8,43 @@
|
||||
#include "../../../window/Camera.hpp"
|
||||
#include "../../../frontend/hud.hpp"
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace scripting {
|
||||
extern Hud* hud;
|
||||
}
|
||||
using namespace scripting;
|
||||
|
||||
static std::optional<Entity> get_entity(lua::State* L, int idx) {
|
||||
auto id = lua::tointeger(L, idx);
|
||||
auto level = controller->getLevel();
|
||||
return level->entities->get(id);
|
||||
}
|
||||
|
||||
static int l_test(lua::State* L) {
|
||||
auto level = controller->getLevel();
|
||||
auto player = hud->getPlayer();
|
||||
level->entities->drop(player->camera->position, player->camera->front*8.0f+glm::vec3(0, 2, 0)+player->hitbox->velocity);
|
||||
return 0;
|
||||
auto id = level->entities->drop(player->camera->position);
|
||||
return lua::pushinteger(L, id);
|
||||
}
|
||||
|
||||
static int l_get_vel(lua::State* L) {
|
||||
if (auto entity = get_entity(L, 1)) {
|
||||
return lua::pushvec3_arr(L, entity->getHitbox().velocity);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_set_vel(lua::State* L) {
|
||||
if (auto entity = get_entity(L, 1)) {
|
||||
entity->getHitbox().velocity = lua::tovec3(L, 2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg entitylib [] = {
|
||||
{"test", lua::wrap<l_test>},
|
||||
{"get_vel", lua::wrap<l_get_vel>},
|
||||
{"set_vel", lua::wrap<l_set_vel>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -379,6 +379,16 @@ namespace lua {
|
||||
pop(L);
|
||||
return glm::vec4(x, y, z, w);
|
||||
}
|
||||
inline glm::vec3 tovec3_stack(lua::State* L, int idx) {
|
||||
return glm::vec3(
|
||||
tonumber(L, idx), tonumber(L, idx+1), tonumber(L, idx+2)
|
||||
);
|
||||
}
|
||||
inline glm::vec4 tovec4_stack(lua::State* L, int idx) {
|
||||
return glm::vec4(
|
||||
tonumber(L, idx), tonumber(L, idx+1), tonumber(L, idx+2), tonumber(L, idx+3)
|
||||
);
|
||||
}
|
||||
inline glm::mat4 tomat4(lua::State* L, int idx) {
|
||||
pushvalue(L, idx);
|
||||
if (!istable(L, idx) || objlen(L, idx) < 16) {
|
||||
|
||||
Reference in New Issue
Block a user