diff --git a/CMakeLists.txt b/CMakeLists.txt index 88d9cad..9935cf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,8 +26,9 @@ set(TWN_TARGET townengine CACHE INTERNAL "") set(TWN_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") # feature configuration, set them with -DFEATURE=ON/OFF in cli -option(TWN_FEATURE_DYNLIB_GAME "Enable dynamic library loading support" ON) -option(TWN_USE_AMALGAM "Enable use of twn_amalgam.c as a single compilation unit" ON) +option(TWN_USE_AMALGAM "Enable use of twn_amalgam.c as a single compilation unit" ON) +option(TWN_FEATURE_DYNLIB_GAME "Enable dynamic library loading support" ON) +set(TWN_OUT_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Artifact destination") # todo: figure out how to compile for dynamic linking instead if(EMSCRIPTEN) @@ -270,7 +271,9 @@ function(link_deps target) endfunction() -function(use_townengine target sources output_directory) +function(use_townengine sources output_directory) + cmake_path(GET TWN_OUT_DIR STEM LAST_ONLY target) + if(TWN_FEATURE_DYNLIB_GAME) # game shared library, for reloading add_library(${target}_game SHARED ${sources}) diff --git a/apps/demos/bunnymark/CMakeLists.txt b/apps/demos/bunnymark/CMakeLists.txt index 44fe767..ab6057a 100644 --- a/apps/demos/bunnymark/CMakeLists.txt +++ b/apps/demos/bunnymark/CMakeLists.txt @@ -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}) diff --git a/apps/demos/bunnymark/game.c b/apps/demos/bunnymark/game.c index 2241ebf..bf9a0ed 100644 --- a/apps/demos/bunnymark/game.c +++ b/apps/demos/bunnymark/game.c @@ -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; diff --git a/apps/demos/platformer/CMakeLists.txt b/apps/demos/platformer/CMakeLists.txt index 79bbb90..2d7593f 100644 --- a/apps/demos/platformer/CMakeLists.txt +++ b/apps/demos/platformer/CMakeLists.txt @@ -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}) diff --git a/apps/demos/platformer/game.c b/apps/demos/platformer/game.c index 4e203a1..a09f7a0 100644 --- a/apps/demos/platformer/game.c +++ b/apps/demos/platformer/game.c @@ -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; diff --git a/apps/demos/platformer/scenes/ingame.c b/apps/demos/platformer/scenes/ingame.c index 1498c1e..d4086dc 100644 --- a/apps/demos/platformer/scenes/ingame.c +++ b/apps/demos/platformer/scenes/ingame.c @@ -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); diff --git a/apps/demos/platformer/scenes/title.c b/apps/demos/platformer/scenes/title.c index 37ccbf5..dc2b6f5 100644 --- a/apps/demos/platformer/scenes/title.c +++ b/apps/demos/platformer/scenes/title.c @@ -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); diff --git a/apps/demos/scenery/CMakeLists.txt b/apps/demos/scenery/CMakeLists.txt index e399176..1c85cfe 100644 --- a/apps/demos/scenery/CMakeLists.txt +++ b/apps/demos/scenery/CMakeLists.txt @@ -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}) diff --git a/apps/demos/scenery/game.c b/apps/demos/scenery/game.c index 520db4a..1cd5709 100644 --- a/apps/demos/scenery/game.c +++ b/apps/demos/scenery/game.c @@ -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; diff --git a/apps/demos/scenery/scenes/ingame.c b/apps/demos/scenery/scenes/ingame.c index 23dabac..bd8cddd 100644 --- a/apps/demos/scenery/scenes/ingame.c +++ b/apps/demos/scenery/scenes/ingame.c @@ -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 */ diff --git a/apps/demos/scenery/scenes/title.c b/apps/demos/scenery/scenes/title.c index 4ef7264..4722c06 100644 --- a/apps/demos/scenery/scenes/title.c +++ b/apps/demos/scenery/scenes/title.c @@ -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); diff --git a/apps/examples/circle-raster/game.c b/apps/examples/circle-raster/game.c index 1e81ee6..3d89d9d 100644 --- a/apps/examples/circle-raster/game.c +++ b/apps/examples/circle-raster/game.c @@ -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; diff --git a/apps/twnlua/CMakeLists.txt b/apps/twnlua/CMakeLists.txt index 2bd46d7..6dcca8a 100644 --- a/apps/twnlua/CMakeLists.txt +++ b/apps/twnlua/CMakeLists.txt @@ -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}) diff --git a/apps/twnlua/bindgen.py b/apps/twnlua/bindgen.py index 018c616..6817345 100755 --- a/apps/twnlua/bindgen.py +++ b/apps/twnlua/bindgen.py @@ -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] diff --git a/apps/twnlua/docgen.py b/apps/twnlua/docgen.py index f7ef860..fb70af3 100755 --- a/apps/twnlua/docgen.py +++ b/apps/twnlua/docgen.py @@ -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] = {} diff --git a/bin/twnbuild b/bin/twnbuild index b2898cf..209db73 100755 --- a/bin/twnbuild +++ b/bin/twnbuild @@ -1,6 +1,7 @@ #!/bin/env python3 from subprocess import getoutput, run +from os import getcwd from os.path import expandvars from pathlib import Path from sys import argv @@ -22,6 +23,7 @@ cmake += ["-B", "build"] # TODO: have it --fast instead, where separate --no-debug would mean stripping the debug info if "--release" in argv: cmake += ["-DCMAKE_BUILD_TYPE=Release"] +cmake += [f"-DTWN_OUT_DIR={getcwd()}"] # pass arbitrary arguments over if "--" in argv: cmake += argv[argv.index("--")+1:] diff --git a/docs/wiki/.gitignore b/docs/wiki/.gitignore new file mode 100644 index 0000000..7e0caf8 --- /dev/null +++ b/docs/wiki/.gitignore @@ -0,0 +1 @@ +!*.html diff --git a/docs/wiki/about-townengine.html b/docs/wiki/about-townengine.html index 43b71af..7fd7603 100644 --- a/docs/wiki/about-townengine.html +++ b/docs/wiki/about-townengine.html @@ -5,9 +5,9 @@
--Townengine, {twn}, is an opinionated game development framework designed around ideas of simplicity, managed state, care for old devices, portability, language agnosticism, use-case orientation, iterability and low latency. @@ -34,7 +34,7 @@
Low latency. Care is given to various incarnations of feared latency. Engine is fast to build, allowing for low commitment patches. Startup time is profiled and optimized. Streaming is used as much as possible for asset load.
Purpose of this wiki is to collect information on various usages of {twn} across the genres, FAQ style. You're welcomed to contribute to it. It's written in HTML so basic you can edit it by hand. diff --git a/docs/wiki/index.html b/docs/wiki/index.html index 54ab8d3..7539030 100644 --- a/docs/wiki/index.html +++ b/docs/wiki/index.html @@ -5,20 +5,27 @@
-Townengine Wiki
--
+- 1. About Townengnine -2. Making 2.5D Shooters +Townengine Wiki
+ Awesomeness ++
- -- T1. About Townengnine +G1. Making 2.5D Shooters -1.1 Introduction
-1.2 Wiki
++ T2. Input System +T1. About Townengine
++- -T1.1 Introduction
+T1.2 Wiki
+T2. Input System
+++ +T2.1 Design
+T2.2 API
+