Compare commits

...

12 Commits

Author SHA1 Message Date
veclavtalica
2286cdefeb ignore docgen artifact in lua template 2025-02-02 23:11:11 +03:00
veclavtalica
00ada15dbc remove unneeded cmake file from lua template 2025-02-02 23:10:47 +03:00
veclavtalica
96b6b7e70b /bin/twnbuild: python based build solution 2025-02-02 23:08:02 +03:00
veclavtalica
ccfdfd8a35 half pi. 2025-02-02 05:39:47 +03:00
veclavtalica
7284bb726a make yaw = 0 result in (0, 0, 1) target vector 2025-02-02 05:32:18 +03:00
veclavtalica
87b33c2e0c /apps/twnlua: replace dots to forward slashes in module lookup 2025-02-02 05:00:54 +03:00
veclavtalica
732a3579b0 /apps/templates/lua: add .gitignore 2025-02-02 04:27:44 +03:00
veclavtalica
2f629433aa catch null font, report it as unimplemented 2025-02-02 04:12:56 +03:00
veclavtalica
6d58e964bc use ccalloc in input bindings 2025-02-02 03:15:05 +03:00
veclavtalica
0014458dbb actuall no spam. i swear. 2025-02-02 03:13:58 +03:00
veclavtalica
9112630330 don't report useless opengl messages 2025-02-02 02:17:37 +03:00
veclavtalica
108810d68a /apps/twnlua: propagate errors in physfs_loader() 2025-02-02 02:10:05 +03:00
12 changed files with 74 additions and 33 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
*
!*.*
!*/
!bin/*
!Makefile
**/*.exe

12
apps/templates/lua/.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
# ignore executables
*
!*.*
!*/
*.so
*.dll
*.exe
*.trace
data/scripts/twnapi.lua
build/

View File

@ -1,8 +0,0 @@
cmake_minimum_required(VERSION 3.21)
project(twngame LANGUAGES C)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
add_subdirectory($ENV{TWNROOT}/apps/twnlua ${CMAKE_CURRENT_BINARY_DIR}/twnlua)

View File

@ -14,6 +14,7 @@ dev_id = "you"
# Game runtime details
[game]
resolution = [ 640, 480 ]
interpreter = "$TWNROOT/apps/twnlua"
#debug = true
# Engine tweaks. You probably don't need to change these

View File

@ -14,10 +14,19 @@ void bindgen_upload_context(lua_State *L);
/* require will go through physicsfs exclusively so that scripts can be in the data dir */
/* TODO: allow for bytecode files */
/* TODO: support .lua suffixes files? */
static int physfs_loader(lua_State *L) {
const char *name = luaL_checkstring(L, 1);
/* replace dots with path slashes */
char *path_copy = SDL_strdup(name);
char *ch = NULL;
while ((ch = SDL_strchr(path_copy, '.')))
*ch = '/';
char *final_path = NULL;
SDL_asprintf(&final_path, "/scripts/%s.lua", name);
SDL_asprintf(&final_path, "/scripts/%s.lua", path_copy);
SDL_free(path_copy);
if (!file_exists(final_path)) {
char *error_message = NULL;
@ -34,10 +43,10 @@ static int physfs_loader(lua_State *L) {
free(final_path);
/* TODO: use reader interface for streaming instead */
luaL_loadbuffer(L, (char *)buf, buf_size, name);
int const result = luaL_loadbuffer(L, (char *)buf, buf_size, name) == LUA_OK;
free(buf);
return 1;
return result;
}

View File

@ -1,19 +0,0 @@
#!/bin/env sh
set +e
# check whether ninja is around (you better start running)
if [ -x "$(command -v ninja)" ]; then
generator="-G Ninja"
fi
# check whether clang is around (it's just better)
if [ -x "$(command -v clang)" ]; then
cc="-DCMAKE_C_COMPILER=clang"
fi
if [ "$1" = "web" ]; then
emcmake cmake $generator $cc -B build-web "${@:2}" && cmake --build build-web --parallel
else
cmake $generator $cc -B build "$@" && cmake --build build --parallel
fi

View File

@ -8,7 +8,7 @@ toolpath="$(dirname -- "${BASH_SOURCE[0]}")"
export TWNROOT=$(realpath "$toolpath"/../)
case "$1" in
build ) "$toolpath"/build.sh "${@:2}"
build ) "$toolpath"/twnbuild "${@:2}"
;;
run ) $0 build && ./$exe "${@:2}"

36
bin/twnbuild Executable file
View File

@ -0,0 +1,36 @@
#!/bin/env python3
from subprocess import getoutput, run
from os.path import expandvars
from pathlib import Path
from sys import argv
import tomllib
has_ninja = getoutput("command -v ninja") != ""
has_clang = getoutput("command -v clang") != ""
#TODO: support for default pack override
cmake = ["cmake"]
# check whether clang is around (it's just better)
if has_clang:
cmake += ["-DCMAKE_C_COMPILER=clang"]
# check whether ninja is around (you better start running)
if has_ninja:
cmake += ["-G", "Ninja"]
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"]
# pass arbitrary arguments over
if "--" in argv:
cmake += argv[argv.find("--"):]
# if no root cmake file is present, infer it from `twn.toml:game.interpreter`
if not Path("CMakeLists.txt").is_file():
with open("data/twn.toml", "rb") as f:
config = tomllib.load(f)
cmake += ["-S", expandvars(config["game"]["interpreter"])]
run(cmake, check=True)
run(["cmake", "--build", "build", "--parallel"], check=True)

View File

@ -454,8 +454,9 @@ DrawCameraFromPrincipalAxesResult draw_camera_from_principal_axes(Vec3 position,
(void)roll;
/* rotate so that yaw = 0 results in (0, 0, 1) target vector */
float yawc, yaws, pitchc, pitchs;
sincosf(yaw, &yaws, &yawc);
sincosf(yaw + (float)M_PI_2, &yaws, &yawc);
sincosf(pitch, &pitchs, &pitchc);
Camera const camera = {

View File

@ -27,6 +27,9 @@ static void APIENTRY opengl_log(GLenum source,
(void)severity;
(void)userParam;
if (severity == GL_DEBUG_SEVERITY_NOTIFICATION || severity == GL_DEBUG_SEVERITY_LOW)
return;
log_info("OpenGL: %.*s\n", length, message);
}

View File

@ -289,6 +289,11 @@ void text_cache_reset_arena(TextCache *cache) {
void draw_text(const char *string, Vec2 position, float height, Color color, const char *font) {
if (!font) {
log_warn("Default font isn't yet implemented");
return;
}
ensure_font_cache(font, (int)height);
/* the original string might not be around by the time it's used, so copy it */

View File

@ -74,7 +74,7 @@ static ActionHashItem *input_add_action(char const *action_name) {
SDL_assert(action_name);
Action new_action = { 0 };
new_action.bindings = SDL_calloc(ctx.keybind_slots, sizeof *new_action.bindings);
new_action.bindings = ccalloc(ctx.keybind_slots, sizeof *new_action.bindings);
shput(ctx.input.action_hash, action_name, new_action);
return shgetp(ctx.input.action_hash, action_name);
}