LuaPlus extenssion
This commit is contained in:
16
data/scripts/actors/actor_base.lua
Normal file
16
data/scripts/actors/actor_base.lua
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
-- базовый класс актора
|
||||||
|
actor_base = inherit_table(game_object)
|
||||||
|
|
||||||
|
-- инициализация FSM
|
||||||
|
|
||||||
|
function actor_base:on_init()
|
||||||
|
game_object.on_init(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function actor_base:on_shutdown()
|
||||||
|
game_object.on_shutdown(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function actor_base:on_update(dt)
|
||||||
|
game_object.on_update(self, dt)
|
||||||
|
end
|
||||||
@@ -1,21 +1,3 @@
|
|||||||
-- базовый класс актора
|
|
||||||
actor_base = inherit_table(game_object)
|
|
||||||
|
|
||||||
-- инициализация FSM
|
|
||||||
|
|
||||||
|
|
||||||
function actor_base:on_init()
|
|
||||||
game_object.on_init(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function actor_base:on_shutdown()
|
|
||||||
game_object.on_shutdown(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
function actor_base:on_update(dt)
|
|
||||||
game_object.on_update(self, dt)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- игрок
|
-- игрок
|
||||||
actor_player = inherit_table(actor_base)
|
actor_player = inherit_table(actor_base)
|
||||||
|
|
||||||
@@ -40,5 +22,5 @@ function actor_player:on_update(dt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function actor_player:on_collide(other)
|
function actor_player:on_collide(other)
|
||||||
--console.print(string.format("actor_player:on_collide: %s", other:get_classname()))
|
console.print(string.format("actor_player:on_collide: %s", other:get_classname()))
|
||||||
end
|
end
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
-- Game initialization script
|
-- Game initialization script
|
||||||
|
|
||||||
|
console.print("--- Game initialization ---")
|
||||||
|
|
||||||
-- загружаем скрипты
|
-- загружаем скрипты
|
||||||
load_script("game_utils.lua")
|
load_script("game_utils.lua")
|
||||||
load_script("game_object.lua")
|
load_script("game_object.lua")
|
||||||
load_script("test_object.lua")
|
load_script("test_object.lua")
|
||||||
|
|
||||||
|
load_script("weapons/weapon_base.lua")
|
||||||
|
load_script("actors/actor_base.lua")
|
||||||
|
|
||||||
load_script("actors/actor_player.lua")
|
load_script("actors/actor_player.lua")
|
||||||
|
|
||||||
-- глобальная таблица сущностей
|
-- глобальная таблица сущностей
|
||||||
|
|||||||
109
data/scripts/weapons/weapon_base.lua
Normal file
109
data/scripts/weapons/weapon_base.lua
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
-----------------------------------------------------------
|
||||||
|
-- weapon_base.lua, Базоавый скрипт оружия
|
||||||
|
-- Автор: Кирилл
|
||||||
|
-- Изменяли:
|
||||||
|
-- Дата: 05.03.2026
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
-- индификаторы состояний FSM
|
||||||
|
WEAPON_FSM_STATE_IDLE = 1
|
||||||
|
WEAPON_FSM_STATE_ATTACK = 2
|
||||||
|
WEAPON_FSM_STATE_ATTACK2 = 3
|
||||||
|
WEAPON_FSM_STATE_RELOAD = 4
|
||||||
|
|
||||||
|
-- базовый класс оружия
|
||||||
|
weapon_base = inherit_table(game_object)
|
||||||
|
|
||||||
|
-- инициализация FSM
|
||||||
|
weapon_base.m_fsm = {}
|
||||||
|
|
||||||
|
-- покой
|
||||||
|
weapon_base.m_fsm[WEAPON_FSM_STATE_IDLE] = {
|
||||||
|
anim = "idle", -- имя анимации
|
||||||
|
anim_playback = ANIM_PLAYBACK_REPEAT, -- бесконечно играть
|
||||||
|
anim_speed = 1.0 -- обычная скорость анимации
|
||||||
|
}
|
||||||
|
|
||||||
|
-- атака
|
||||||
|
weapon_base.m_fsm[WEAPON_FSM_STATE_ATTACK] = {
|
||||||
|
anim = "attack", -- имя анимации
|
||||||
|
anim_playback = ANIM_PLAYBACK_NONE,
|
||||||
|
anim_speed = 1.0 -- обычная скорость анимации
|
||||||
|
}
|
||||||
|
|
||||||
|
-- перезарядка
|
||||||
|
weapon_base.m_fsm[WEAPON_FSM_STATE_RELOAD] = {
|
||||||
|
anim = "reload", -- имя анимации
|
||||||
|
anim_playback = ANIM_PLAYBACK_NONE,
|
||||||
|
anim_speed = 1.0 -- обычная скорость анимации
|
||||||
|
}
|
||||||
|
|
||||||
|
function weapon_base:on_init()
|
||||||
|
game_object.on_init(self)
|
||||||
|
|
||||||
|
-- начальное состояние FSM
|
||||||
|
self.m_state = WEAPON_FSM_STATE_IDLE
|
||||||
|
self.m_next_state = WEAPON_FSM_STATE_IDLE
|
||||||
|
self.m_state_time = 0.0
|
||||||
|
self.m_end_state_time = 0.0
|
||||||
|
self.m_damage = 25
|
||||||
|
end
|
||||||
|
|
||||||
|
function weapon_base:on_shutdown()
|
||||||
|
game_object.on_shutdown(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function weapon_base:on_update(dt)
|
||||||
|
game_object.on_update(self, dt)
|
||||||
|
|
||||||
|
self:on_fsm_state_update(dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
function weapon_base:on_fsm_state_update(dt)
|
||||||
|
-- обновления времени
|
||||||
|
self.m_state_time = self.m_state_time + dt
|
||||||
|
|
||||||
|
-- проверка на стрельбу
|
||||||
|
if (self.m_state == WEAPON_STATE_ATTACK or
|
||||||
|
self.m_state == WEAPON_STATE_ATTACK2) and
|
||||||
|
self.m_state_time >= self.m_end_state_time then
|
||||||
|
|
||||||
|
-- переходим в ожидание
|
||||||
|
self:set_state(WEAPON_STATE_IDLE)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- костыль, нету анимаций бесконечных
|
||||||
|
if self.m_state == WEAPON_STATE_IDLE and self.m_state_time >= self.m_end_state_time then
|
||||||
|
-- переходим в ожидание
|
||||||
|
self:set_state(WEAPON_STATE_IDLE)
|
||||||
|
end
|
||||||
|
|
||||||
|
self:fsm_update(dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
function weapon_base:set_state(next_state)
|
||||||
|
self.m_next_state = next_state
|
||||||
|
end
|
||||||
|
|
||||||
|
function weapon_base:fsm_update(dt)
|
||||||
|
-- надо ли менять состояние
|
||||||
|
if self.m_next_state ~= self.m_state then
|
||||||
|
|
||||||
|
if self.m_next_state == WEAPON_STATE_ATTACK then
|
||||||
|
self:set_anim("attack1")
|
||||||
|
elseif self.m_next_state == WEAPON_STATE_ATTACK2 then
|
||||||
|
self:set_anim("attack1")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- сброс времени и установка его на таймер анимации
|
||||||
|
self.m_state_time = 0.0
|
||||||
|
self.m_end_state_time = render.get_anim_time(self:get_anim())
|
||||||
|
|
||||||
|
-- запускаем атаку
|
||||||
|
if self.m_next_state == WEAPON_STATE_ATTACK or self.m_next_state == WEAPON_STATE_ATTACK2 then
|
||||||
|
self:attack()
|
||||||
|
end
|
||||||
|
|
||||||
|
self.m_state = self.m_next_state
|
||||||
|
end
|
||||||
|
end
|
||||||
1
data/scripts/weapons/weapon_key.lua
Normal file
1
data/scripts/weapons/weapon_key.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
weapon_key = inherit_table(weapon_base)
|
||||||
@@ -58,6 +58,11 @@ void registerEngine()
|
|||||||
|
|
||||||
LuaObject consoleTable = GetLuaState().GetGlobals().CreateTable("console");
|
LuaObject consoleTable = GetLuaState().GetGlobals().CreateTable("console");
|
||||||
consoleTable.RegisterDirect("print", &consoleMsg);
|
consoleTable.RegisterDirect("print", &consoleMsg);
|
||||||
|
|
||||||
|
// animations globals
|
||||||
|
GetLuaState().DoString("ANIM_PLAYBACK_NONE = 0");
|
||||||
|
GetLuaState().DoString("ANIM_PLAYBACK_REPEAT = 1");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerClasses()
|
void registerClasses()
|
||||||
|
|||||||
@@ -89,3 +89,13 @@ glm::mat4 getMatrixFromLua(LuaPlus::LuaObject& matrix)
|
|||||||
glm::mat4 return_matrix = glm::identity<glm::mat4>();
|
glm::mat4 return_matrix = glm::identity<glm::mat4>();
|
||||||
return return_matrix;
|
return return_matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuaPlusErrorFunction(const char* errorMsg)
|
||||||
|
{
|
||||||
|
Core::Error(errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace LuaPlus
|
||||||
|
{
|
||||||
|
void (*g_errorFunction)(const char*) = LuaPlusErrorFunction;
|
||||||
|
}
|
||||||
@@ -131,7 +131,7 @@ void Entity::OnCollide(IEntityBase* other)
|
|||||||
LuaPlus::LuaObject otherTable = lookup.GetByIndex(other->GetID());
|
LuaPlus::LuaObject otherTable = lookup.GetByIndex(other->GetID());
|
||||||
if (!otherTable.IsNil())
|
if (!otherTable.IsNil())
|
||||||
{
|
{
|
||||||
LuaPlus:: LuaFunctionVoid function = m_onCollideFunction;
|
LuaPlus::LuaFunctionVoid function = m_onCollideFunction;
|
||||||
function(m_luaObject, otherTable);
|
function(m_luaObject, otherTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
60
thirdparty/luaplus/Src/LuaPlus/LuaFunction.h
vendored
60
thirdparty/luaplus/Src/LuaPlus/LuaFunction.h
vendored
@@ -35,8 +35,8 @@ public:
|
|||||||
functionObj.Push(L);
|
functionObj.Push(L);
|
||||||
|
|
||||||
if (lua_pcall(L, 0, 1, 0)) {
|
if (lua_pcall(L, 0, 1, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
return LPCD::Type<RT>::Get(L, -1);
|
return LPCD::Type<RT>::Get(L, -1);
|
||||||
}
|
}
|
||||||
@@ -50,8 +50,8 @@ public:
|
|||||||
LPCD::Type<P1>::Push(L, p1);
|
LPCD::Type<P1>::Push(L, p1);
|
||||||
|
|
||||||
if (lua_pcall(L, 1, 1, 0)) {
|
if (lua_pcall(L, 1, 1, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
return LPCD::Type<RT>::Get(L, -1);
|
return LPCD::Type<RT>::Get(L, -1);
|
||||||
}
|
}
|
||||||
@@ -66,8 +66,8 @@ public:
|
|||||||
LPCD::Type<P2>::Push(L, p2);
|
LPCD::Type<P2>::Push(L, p2);
|
||||||
|
|
||||||
if (lua_pcall(L, 2, 1, 0)) {
|
if (lua_pcall(L, 2, 1, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
return LPCD::Type<RT>::Get(L, -1);
|
return LPCD::Type<RT>::Get(L, -1);
|
||||||
}
|
}
|
||||||
@@ -83,8 +83,8 @@ public:
|
|||||||
LPCD::Type<P3>::Push(L, p3);
|
LPCD::Type<P3>::Push(L, p3);
|
||||||
|
|
||||||
if (lua_pcall(L, 3, 1, 0)) {
|
if (lua_pcall(L, 3, 1, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
return LPCD::Type<RT>::Get(L, -1);
|
return LPCD::Type<RT>::Get(L, -1);
|
||||||
}
|
}
|
||||||
@@ -101,8 +101,8 @@ public:
|
|||||||
LPCD::Type<P4>::Push(L, p4);
|
LPCD::Type<P4>::Push(L, p4);
|
||||||
|
|
||||||
if (lua_pcall(L, 4, 1, 0)) {
|
if (lua_pcall(L, 4, 1, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
return LPCD::Type<RT>::Get(L, -1);
|
return LPCD::Type<RT>::Get(L, -1);
|
||||||
}
|
}
|
||||||
@@ -120,8 +120,8 @@ public:
|
|||||||
LPCD::Type<P5>::Push(L, p5);
|
LPCD::Type<P5>::Push(L, p5);
|
||||||
|
|
||||||
if (lua_pcall(L, 5, 1, 0)) {
|
if (lua_pcall(L, 5, 1, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
return LPCD::Type<RT>::Get(L, -1);
|
return LPCD::Type<RT>::Get(L, -1);
|
||||||
}
|
}
|
||||||
@@ -140,8 +140,8 @@ public:
|
|||||||
LPCD::Type<P6>::Push(L, p6);
|
LPCD::Type<P6>::Push(L, p6);
|
||||||
|
|
||||||
if (lua_pcall(L, 6, 1, 0)) {
|
if (lua_pcall(L, 6, 1, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
return LPCD::Type<RT>::Get(L, -1);
|
return LPCD::Type<RT>::Get(L, -1);
|
||||||
}
|
}
|
||||||
@@ -161,8 +161,8 @@ public:
|
|||||||
LPCD::Type<P7>::Push(L, p7);
|
LPCD::Type<P7>::Push(L, p7);
|
||||||
|
|
||||||
if (lua_pcall(L, 7, 1, 0)) {
|
if (lua_pcall(L, 7, 1, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
return LPCD::Type<RT>::Get(L, -1);
|
return LPCD::Type<RT>::Get(L, -1);
|
||||||
}
|
}
|
||||||
@@ -191,8 +191,8 @@ public:
|
|||||||
functionObj.Push(L);
|
functionObj.Push(L);
|
||||||
|
|
||||||
if (lua_pcall(L, 0, 0, 0)) {
|
if (lua_pcall(L, 0, 0, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,8 +205,8 @@ public:
|
|||||||
LPCD::Type<P1>::Push(L, p1);
|
LPCD::Type<P1>::Push(L, p1);
|
||||||
|
|
||||||
if (lua_pcall(L, 1, 0, 0)) {
|
if (lua_pcall(L, 1, 0, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,8 +220,8 @@ public:
|
|||||||
LPCD::Type<P2>::Push(L, p2);
|
LPCD::Type<P2>::Push(L, p2);
|
||||||
|
|
||||||
if (lua_pcall(L, 2, 0, 0)) {
|
if (lua_pcall(L, 2, 0, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,8 +236,8 @@ public:
|
|||||||
LPCD::Type<P3>::Push(L, p3);
|
LPCD::Type<P3>::Push(L, p3);
|
||||||
|
|
||||||
if (lua_pcall(L, 3, 0, 0)) {
|
if (lua_pcall(L, 3, 0, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,8 +253,8 @@ public:
|
|||||||
LPCD::Type<P4>::Push(L, p4);
|
LPCD::Type<P4>::Push(L, p4);
|
||||||
|
|
||||||
if (lua_pcall(L, 4, 0, 0)) {
|
if (lua_pcall(L, 4, 0, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,8 +271,8 @@ public:
|
|||||||
LPCD::Type<P5>::Push(L, p5);
|
LPCD::Type<P5>::Push(L, p5);
|
||||||
|
|
||||||
if (lua_pcall(L, 5, 0, 0)) {
|
if (lua_pcall(L, 5, 0, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,8 +290,8 @@ public:
|
|||||||
LPCD::Type<P6>::Push(L, p6);
|
LPCD::Type<P6>::Push(L, p6);
|
||||||
|
|
||||||
if (lua_pcall(L, 6, 0, 0)) {
|
if (lua_pcall(L, 6, 0, 0)) {
|
||||||
const char* errorString = lua_tostring(L, -1); (void)errorString;
|
const char* errorString = lua_tostring(L, -1);
|
||||||
luaplus_assert(0);
|
g_errorFunction(errorString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,4 +94,8 @@ struct LuaArgNil {};
|
|||||||
#define LuaState_to_lua_State(state) ((lua_State*)(state))
|
#define LuaState_to_lua_State(state) ((lua_State*)(state))
|
||||||
#define lua_State_to_LuaState(L) ((LuaPlus::LuaState*)L)
|
#define lua_State_to_LuaState(L) ((LuaPlus::LuaState*)L)
|
||||||
|
|
||||||
|
namespace LuaPlus {
|
||||||
|
extern void (*g_errorFunction)(const char* errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // LUAPLUS__LUAPLUSINTERNAL_H
|
#endif // LUAPLUS__LUAPLUSINTERNAL_H
|
||||||
|
|||||||
Reference in New Issue
Block a user