Compare commits
12 Commits
2c94efb796
...
2286cdefeb
Author | SHA1 | Date | |
---|---|---|---|
|
2286cdefeb | ||
|
00ada15dbc | ||
|
96b6b7e70b | ||
|
ccfdfd8a35 | ||
|
7284bb726a | ||
|
87b33c2e0c | ||
|
732a3579b0 | ||
|
2f629433aa | ||
|
6d58e964bc | ||
|
0014458dbb | ||
|
9112630330 | ||
|
108810d68a |
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
||||
*
|
||||
!*.*
|
||||
!*/
|
||||
!bin/*
|
||||
!Makefile
|
||||
|
||||
**/*.exe
|
||||
|
12
apps/templates/lua/.gitignore
vendored
Normal file
12
apps/templates/lua/.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
# ignore executables
|
||||
*
|
||||
!*.*
|
||||
!*/
|
||||
|
||||
*.so
|
||||
*.dll
|
||||
*.exe
|
||||
*.trace
|
||||
|
||||
data/scripts/twnapi.lua
|
||||
build/
|
@ -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)
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
19
bin/build.sh
19
bin/build.sh
@ -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
|
2
bin/twn
2
bin/twn
@ -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
36
bin/twnbuild
Executable 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)
|
@ -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 = {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user