Working lua integration.
This commit is contained in:
parent
7a9dc006d1
commit
96fbb318c0
|
|
@ -9,6 +9,9 @@ ASSETS := \
|
|||
maps/dungeon_entry.map \
|
||||
maps/dungeon_room_1.map
|
||||
|
||||
LUA_SOURCES := \
|
||||
enemy_system.lua
|
||||
|
||||
OBJECTS := $(ASSETS:%=$(BUILD_DIR)/$(notdir $(ASSETS_DIR))/%.o)
|
||||
|
||||
ifeq ($(TOTAL_BUILD_FILES),)
|
||||
|
|
|
|||
|
|
@ -6,10 +6,12 @@
|
|||
COMPONENT(TRANSFORM_COMPONENT, transform_component, DRAW)
|
||||
COMPONENT(HITBOX_COMPONENT, hitbox_component, DRAW)
|
||||
COMPONENT(INTERACT_COMPONENT, interact_component, DRAW)
|
||||
COMPONENT(LUA_COMPONENT, lua_component, DRAW)
|
||||
#else
|
||||
COMPONENT(TRANSFORM_COMPONENT, transform_component, NO_DRAW)
|
||||
COMPONENT(HITBOX_COMPONENT, hitbox_component, NO_DRAW)
|
||||
COMPONENT(INTERACT_COMPONENT, interact_component, NO_DRAW)
|
||||
COMPONENT(LUA_COMPONENT, lua_component, NO_DRAW)
|
||||
#endif // DEBUG >= 2
|
||||
|
||||
COMPONENT(PHYSICS_SYSTEM, physics_system, NO_DRAW)
|
||||
|
|
@ -18,7 +20,6 @@ COMPONENT(ANIMATION_SYSTEM, animation_system, NO_DRAW)
|
|||
COMPONENT(PLAYER_SYSTEM, player_system, NO_DRAW)
|
||||
COMPONENT(LEVER_COMPONENT, lever_component, NO_DRAW)
|
||||
COMPONENT(DOOR_COMPONENT, door_component, NO_DRAW)
|
||||
// COMPONENT(LUA_COMPONENT, lua_component, NO_DRAW)
|
||||
// Add new components definition here
|
||||
|
||||
#undef COMPONENT
|
||||
|
|
|
|||
|
|
@ -1,6 +1,51 @@
|
|||
#ifndef LUA_COMPONENT_H
|
||||
#define LUA_COMPONENT_H
|
||||
#include "lua_component.h"
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
#include "game.h"
|
||||
#include "ecs.h"
|
||||
#include "memory_alloc.h"
|
||||
#include "errors.h"
|
||||
|
||||
inline int lua_component_init(component_t *component)
|
||||
{
|
||||
lua_component_data_t *component_data = component->data;
|
||||
|
||||
#endif // LUA_COMPONENT_H
|
||||
component_data->lua_state = luaL_newstate();
|
||||
|
||||
luaL_openlibs(component_data->lua_state);
|
||||
|
||||
luaL_dostring(component_data->lua_state, "function f (a) print(a) end");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
inline int lua_component_update(component_t *component __attribute__((unused)))
|
||||
{
|
||||
lua_component_data_t *component_data = component->data;
|
||||
|
||||
luaL_dostring(component_data->lua_state, "f(\"prout\")");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#if DEBUG >= 2
|
||||
#include "display.h"
|
||||
|
||||
inline int lua_component_draw(const component_t *component)
|
||||
{
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif // DEBUG >= 2
|
||||
|
||||
inline int lua_component_destroy(component_t *component)
|
||||
{
|
||||
lua_component_data_t *component_data = component->data;
|
||||
|
||||
lua_close(component_data->lua_state);
|
||||
|
||||
free(component_data);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef LUA_COMPONENT_H
|
||||
#define LUA_COMPONENT_H
|
||||
|
||||
#include "ecs.h"
|
||||
#include "lua.h"
|
||||
#include "errors.h"
|
||||
|
||||
typedef struct lua_component_data_t {
|
||||
lua_State *lua_state;
|
||||
} lua_component_data_t;
|
||||
|
||||
int lua_component_init(component_t *component);
|
||||
int lua_component_update(component_t *component);
|
||||
#if DEBUG >= 2
|
||||
int lua_component_draw(const component_t *component);
|
||||
#endif // DEBUG >= 2
|
||||
int lua_component_destroy(component_t *component);
|
||||
|
||||
#endif // LUA_COMPONENT_H
|
||||
10
src/game.c
10
src/game.c
|
|
@ -21,7 +21,7 @@ int game_init(void)
|
|||
entity_manager_init();
|
||||
if(asset_manager_init()) return_failure_int;
|
||||
|
||||
asset_t *map_asset = asset_manager_load_asset("dungeon_room_1", ASSET_MAP);
|
||||
asset_t *map_asset = asset_manager_load_asset("dungeon_entry", ASSET_MAP);
|
||||
if(!map_asset) return_failure_int;
|
||||
|
||||
game.map = map_asset->data;
|
||||
|
|
@ -119,6 +119,14 @@ int game_init(void)
|
|||
if(!entity_new_component(player_entity, PLAYER_SYSTEM)) return_failure_int;
|
||||
}
|
||||
|
||||
/* ======== Enemy ======== */
|
||||
{
|
||||
entity_t *enemy_entity = entity_manager_new_entity(1);
|
||||
if(!enemy_entity) return_failure_int;
|
||||
|
||||
if(!entity_new_component(enemy_entity, LUA_COMPONENT)) return_failure_int;
|
||||
}
|
||||
|
||||
game.is_running = true;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
Loading…
Reference in New Issue