Compare commits
No commits in common. "2286cdefeb53a7cc4d751983a19ba0dd61d00465" and "2c94efb79689e8b2d3f55921bdf175c52c90c07d" have entirely different histories.
2286cdefeb
...
2c94efb796
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,7 +2,6 @@
|
|||||||
*
|
*
|
||||||
!*.*
|
!*.*
|
||||||
!*/
|
!*/
|
||||||
!bin/*
|
|
||||||
!Makefile
|
!Makefile
|
||||||
|
|
||||||
**/*.exe
|
**/*.exe
|
||||||
|
12
apps/templates/lua/.gitignore
vendored
12
apps/templates/lua/.gitignore
vendored
@ -1,12 +0,0 @@
|
|||||||
# ignore executables
|
|
||||||
*
|
|
||||||
!*.*
|
|
||||||
!*/
|
|
||||||
|
|
||||||
*.so
|
|
||||||
*.dll
|
|
||||||
*.exe
|
|
||||||
*.trace
|
|
||||||
|
|
||||||
data/scripts/twnapi.lua
|
|
||||||
build/
|
|
8
apps/templates/lua/CMakeLists.txt
Normal file
8
apps/templates/lua/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
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,7 +14,6 @@ dev_id = "you"
|
|||||||
# Game runtime details
|
# Game runtime details
|
||||||
[game]
|
[game]
|
||||||
resolution = [ 640, 480 ]
|
resolution = [ 640, 480 ]
|
||||||
interpreter = "$TWNROOT/apps/twnlua"
|
|
||||||
#debug = true
|
#debug = true
|
||||||
|
|
||||||
# Engine tweaks. You probably don't need to change these
|
# Engine tweaks. You probably don't need to change these
|
||||||
|
@ -14,19 +14,10 @@ void bindgen_upload_context(lua_State *L);
|
|||||||
|
|
||||||
/* require will go through physicsfs exclusively so that scripts can be in the data dir */
|
/* require will go through physicsfs exclusively so that scripts can be in the data dir */
|
||||||
/* TODO: allow for bytecode files */
|
/* TODO: allow for bytecode files */
|
||||||
/* TODO: support .lua suffixes files? */
|
|
||||||
static int physfs_loader(lua_State *L) {
|
static int physfs_loader(lua_State *L) {
|
||||||
const char *name = luaL_checkstring(L, 1);
|
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;
|
char *final_path = NULL;
|
||||||
SDL_asprintf(&final_path, "/scripts/%s.lua", path_copy);
|
SDL_asprintf(&final_path, "/scripts/%s.lua", name);
|
||||||
SDL_free(path_copy);
|
|
||||||
|
|
||||||
if (!file_exists(final_path)) {
|
if (!file_exists(final_path)) {
|
||||||
char *error_message = NULL;
|
char *error_message = NULL;
|
||||||
@ -43,10 +34,10 @@ static int physfs_loader(lua_State *L) {
|
|||||||
free(final_path);
|
free(final_path);
|
||||||
|
|
||||||
/* TODO: use reader interface for streaming instead */
|
/* TODO: use reader interface for streaming instead */
|
||||||
int const result = luaL_loadbuffer(L, (char *)buf, buf_size, name) == LUA_OK;
|
luaL_loadbuffer(L, (char *)buf, buf_size, name);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
return result;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
19
bin/build.sh
Executable file
19
bin/build.sh
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/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"/../)
|
export TWNROOT=$(realpath "$toolpath"/../)
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
build ) "$toolpath"/twnbuild "${@:2}"
|
build ) "$toolpath"/build.sh "${@:2}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
run ) $0 build && ./$exe "${@:2}"
|
run ) $0 build && ./$exe "${@:2}"
|
||||||
|
36
bin/twnbuild
36
bin/twnbuild
@ -1,36 +0,0 @@
|
|||||||
#!/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,9 +454,8 @@ DrawCameraFromPrincipalAxesResult draw_camera_from_principal_axes(Vec3 position,
|
|||||||
|
|
||||||
(void)roll;
|
(void)roll;
|
||||||
|
|
||||||
/* rotate so that yaw = 0 results in (0, 0, 1) target vector */
|
|
||||||
float yawc, yaws, pitchc, pitchs;
|
float yawc, yaws, pitchc, pitchs;
|
||||||
sincosf(yaw + (float)M_PI_2, &yaws, &yawc);
|
sincosf(yaw, &yaws, &yawc);
|
||||||
sincosf(pitch, &pitchs, &pitchc);
|
sincosf(pitch, &pitchs, &pitchc);
|
||||||
|
|
||||||
Camera const camera = {
|
Camera const camera = {
|
||||||
|
@ -27,9 +27,6 @@ static void APIENTRY opengl_log(GLenum source,
|
|||||||
(void)severity;
|
(void)severity;
|
||||||
(void)userParam;
|
(void)userParam;
|
||||||
|
|
||||||
if (severity == GL_DEBUG_SEVERITY_NOTIFICATION || severity == GL_DEBUG_SEVERITY_LOW)
|
|
||||||
return;
|
|
||||||
|
|
||||||
log_info("OpenGL: %.*s\n", length, message);
|
log_info("OpenGL: %.*s\n", length, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,11 +289,6 @@ void text_cache_reset_arena(TextCache *cache) {
|
|||||||
|
|
||||||
|
|
||||||
void draw_text(const char *string, Vec2 position, float height, Color color, const char *font) {
|
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);
|
ensure_font_cache(font, (int)height);
|
||||||
|
|
||||||
/* the original string might not be around by the time it's used, so copy it */
|
/* 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);
|
SDL_assert(action_name);
|
||||||
|
|
||||||
Action new_action = { 0 };
|
Action new_action = { 0 };
|
||||||
new_action.bindings = ccalloc(ctx.keybind_slots, sizeof *new_action.bindings);
|
new_action.bindings = SDL_calloc(ctx.keybind_slots, sizeof *new_action.bindings);
|
||||||
shput(ctx.input.action_hash, action_name, new_action);
|
shput(ctx.input.action_hash, action_name, new_action);
|
||||||
return shgetp(ctx.input.action_hash, action_name);
|
return shgetp(ctx.input.action_hash, action_name);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user