input system rework
This commit is contained in:
@ -13,4 +13,4 @@ set(SOURCE_FILES
|
||||
state.h
|
||||
)
|
||||
|
||||
use_townengine(${PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
use_townengine("${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
@ -69,8 +69,8 @@ void game_tick(void)
|
||||
ctx.udata = calloc(1, sizeof(State));
|
||||
}
|
||||
|
||||
input_action("add_a_bit", CONTROL_LEFT_MOUSE);
|
||||
input_action("add_a_lot", CONTROL_RIGHT_MOUSE);
|
||||
input_action("add_a_bit", "LCLICK");
|
||||
input_action("add_a_lot", "RCLICK");
|
||||
|
||||
State *state = ctx.udata;
|
||||
|
||||
|
@ -20,4 +20,4 @@ set(SOURCE_FILES
|
||||
scenes/ingame.c scenes/ingame.h
|
||||
)
|
||||
|
||||
use_townengine(${PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
use_townengine("${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
@ -22,8 +22,8 @@ void game_tick(void) {
|
||||
|
||||
State *state = ctx.udata;
|
||||
|
||||
input_action("debug_toggle", CONTROL_BACKSPACE);
|
||||
input_action("debug_dump_atlases", CONTROL_HOME);
|
||||
input_action("debug_toggle", "BACKSPACE");
|
||||
input_action("debug_dump_atlases", "HOME");
|
||||
|
||||
if (input_action_just_pressed("debug_toggle")) {
|
||||
ctx.debug = !ctx.debug;
|
||||
|
@ -11,12 +11,12 @@
|
||||
static void ingame_tick(State *state) {
|
||||
SceneIngame *scn = (SceneIngame *)state->scene;
|
||||
|
||||
input_action("player_left", CONTROL_A);
|
||||
input_action("player_right", CONTROL_D);
|
||||
input_action("player_forward", CONTROL_W);
|
||||
input_action("player_backward", CONTROL_S);
|
||||
input_action("player_jump", CONTROL_SPACE);
|
||||
input_action("player_run", CONTROL_LSHIFT);
|
||||
input_action("player_left", "A");
|
||||
input_action("player_right", "D");
|
||||
input_action("player_forward", "W");
|
||||
input_action("player_backward", "S");
|
||||
input_action("player_jump", "SPACE");
|
||||
input_action("player_run", "LSHIFT");
|
||||
|
||||
world_drawdef(scn->world);
|
||||
player_calc(scn->player);
|
||||
|
@ -13,7 +13,7 @@ static void title_tick(State *state) {
|
||||
SceneTitle *scn = (SceneTitle *)state->scene;
|
||||
(void)scn;
|
||||
|
||||
input_action("ui_accept", CONTROL_RETURN);
|
||||
input_action("ui_accept", "ENTER");
|
||||
|
||||
if (input_action_just_pressed("ui_accept")) {
|
||||
switch_to(state, ingame_scene);
|
||||
|
@ -17,4 +17,4 @@ set(SOURCE_FILES
|
||||
scenes/ingame.c scenes/ingame.h
|
||||
)
|
||||
|
||||
use_townengine(${PROJECT_NAME} "${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
use_townengine("${SOURCE_FILES}" ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
@ -24,8 +24,8 @@ void game_tick(void) {
|
||||
|
||||
State *state = ctx.udata;
|
||||
|
||||
input_action("debug_toggle", CONTROL_BACKSPACE);
|
||||
input_action("debug_dump_atlases", CONTROL_HOME);
|
||||
input_action("debug_toggle", "BACKSPACE");
|
||||
input_action("debug_dump_atlases", "HOME");
|
||||
|
||||
if (input_action_just_pressed("debug_toggle")) {
|
||||
ctx.debug = !ctx.debug;
|
||||
|
@ -188,14 +188,14 @@ static void draw_terrain(SceneIngame *scn) {
|
||||
static void ingame_tick(State *state) {
|
||||
SceneIngame *scn = (SceneIngame *)state->scene;
|
||||
|
||||
input_action("player_left", CONTROL_A);
|
||||
input_action("player_right", CONTROL_D);
|
||||
input_action("player_forward", CONTROL_W);
|
||||
input_action("player_backward", CONTROL_S);
|
||||
input_action("player_jump", CONTROL_SPACE);
|
||||
input_action("player_run", CONTROL_LSHIFT);
|
||||
input_action("mouse_capture_toggle", CONTROL_ESCAPE);
|
||||
input_action("toggle_camera_mode", CONTROL_C);
|
||||
input_action("player_left", "A");
|
||||
input_action("player_right", "D");
|
||||
input_action("player_forward", "W");
|
||||
input_action("player_backward", "S");
|
||||
input_action("player_jump", "SPACE");
|
||||
input_action("player_run", "LSHIFT");
|
||||
input_action("mouse_capture_toggle", "ESCAPE");
|
||||
input_action("toggle_camera_mode", "C");
|
||||
|
||||
if (scn->mouse_captured) {
|
||||
const float sensitivity = 0.4f * (float)DEG2RAD; /* TODO: put this in a better place */
|
||||
|
@ -11,7 +11,7 @@ static void title_tick(State *state) {
|
||||
SceneTitle *scn = (SceneTitle *)state->scene;
|
||||
(void)scn;
|
||||
|
||||
input_action("ui_accept", CONTROL_RETURN);
|
||||
input_action("ui_accept", "RETURN");
|
||||
|
||||
if (input_action_just_pressed("ui_accept")) {
|
||||
switch_to(state, ingame_scene);
|
||||
|
@ -113,8 +113,8 @@ void game_tick(void) {
|
||||
|
||||
Vec2 const mouse_snap = {floorf(ctx.mouse_position.x / 8) * 8, floorf(ctx.mouse_position.y / 8) * 8};
|
||||
|
||||
input_action("up", CONTROL_LEFT_MOUSE);
|
||||
input_action("down", CONTROL_RIGHT_MOUSE);
|
||||
input_action("up", "LCLICK");
|
||||
input_action("down", "RCLICK");
|
||||
|
||||
if (input_action_just_pressed("up"))
|
||||
state->r += 1;
|
||||
|
@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.21)
|
||||
cmake_policy(SET CMP0171 NEW)
|
||||
project(twnlua LANGUAGES C)
|
||||
|
||||
option(TWN_OUT_DIR "Artifact destination" ${CMAKE_SOURCE_DIR})
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
endif()
|
||||
@ -41,5 +39,4 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/luabind.c
|
||||
)
|
||||
|
||||
cmake_path(GET TWN_OUT_DIR STEM LAST_ONLY GAME_PROJECT_NAME)
|
||||
use_townengine(${GAME_PROJECT_NAME} "${SOURCE_FILES}" ${TWN_OUT_DIR})
|
||||
use_townengine("${SOURCE_FILES}" ${TWN_OUT_DIR})
|
||||
|
@ -116,7 +116,6 @@ for procedure, procedure_desc in api["procedures"].items():
|
||||
elif procedure_desc["return"] == "char *":
|
||||
binding += " lua_pushstring(L, %s(%s));\n" % (procedure, ", ".join(param["name"] for param in procedure_desc["params"]))
|
||||
elif type(procedure_desc["return"]) is dict or procedure_desc["return"] in api["types"]:
|
||||
# TODO: handle enums
|
||||
type_desc = procedure_desc["return"] if type(procedure_desc["return"]) is dict else api["types"][procedure_desc["return"]]
|
||||
binding += " %s result = %s(%s);\n" % (type_desc["c_type"], procedure, ", ".join(param["name"] for param in procedure_desc["params"]))
|
||||
binding += to_table(type_desc, "result", 4)
|
||||
@ -150,21 +149,6 @@ for typename, typedesc in used_converters.items():
|
||||
raise BaseException("Unhandled converter field type '%s'" % (field["type"]))
|
||||
converter += " lua_pop(L, %i);\n" % len(typedesc["fields"]);
|
||||
|
||||
# TODO: wild idea: use compile time built hash table
|
||||
elif "enums" in typedesc:
|
||||
storages += ["struct %sHashItem { char *key; %s value; };\nstatic struct %sHashItem *%s_map = NULL;\n" % (typename, typename, typename, typename.lower())]
|
||||
|
||||
# TODO: use arena
|
||||
for enum in typedesc["enums"]:
|
||||
initializer = " shput(%s_map, \"%s\", %s);" % (typename.lower(), enum, typedesc["enums"][enum])
|
||||
initializers += [initializer]
|
||||
|
||||
deinitializers += [" shfree(%s_map);" % typename.lower()]
|
||||
|
||||
converter += " char const *value = lua_tostring(L, -1);\n";
|
||||
converter += " %s = shget(%s_map, value);\n" % (typename.lower(), typename.lower())
|
||||
converter += " lua_pop(L, 1);\n";
|
||||
|
||||
converter += " return %s;\n}\n" % (typename.lower())
|
||||
converters += [converter]
|
||||
|
||||
|
@ -33,7 +33,7 @@ def to_lua_type_annot(typedesc):
|
||||
|
||||
print("error(\"townengine lua api file is not supposed to be imported!\")")
|
||||
|
||||
type_annotations, enum_annotations = {}, {}
|
||||
type_annotations = {}
|
||||
type_annotations["ctx"] = r"{ %s, udata: table }" % \
|
||||
', '.join("%s: %s" % (f["name"], to_lua_type_annot(f["type"])) for f in api["types"]["Context"]["fields"])
|
||||
|
||||
@ -41,12 +41,6 @@ for annot in type_annotations:
|
||||
print("---@type " + type_annotations[annot])
|
||||
print(r"%s = nil" % annot)
|
||||
|
||||
enum_annotations["Control"] = \
|
||||
'|'.join('\'"%s"\'' % e for e in api["types"]["Control"]["enums"])
|
||||
|
||||
for annot in enum_annotations:
|
||||
print("---@alias %s %s" % (annot, enum_annotations[annot]))
|
||||
|
||||
procedure_annotations = {}
|
||||
for procedure, procedure_desc in api["procedures"].items():
|
||||
procedure_annotations[procedure] = {}
|
||||
|
Reference in New Issue
Block a user