memory: move to libtrx

This commit is contained in:
Marcin Kurczewski 2024-04-28 11:58:41 +02:00
parent 710be8b89b
commit 52fa9bc09c
48 changed files with 52 additions and 127 deletions

View file

@ -24,6 +24,8 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
submodules: 'true'
- name: Build Docker image (${{ matrix.platform }}) - name: Build Docker image (${{ matrix.platform }})
run: | run: |

View file

@ -44,6 +44,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
submodules: 'true'
fetch-depth: 0 fetch-depth: 0
- name: Extend PATH for MacPorts - name: Extend PATH for MacPorts

View file

@ -12,6 +12,7 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
submodules: 'true'
fetch-depth: 0 fetch-depth: 0
- name: Check JSON files validity - name: Check JSON files validity

View file

@ -81,6 +81,7 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
submodules: 'true'
fetch-depth: 0 fetch-depth: 0
- name: Package asset (${{ matrix.platform }}) - name: Package asset (${{ matrix.platform }})
@ -119,6 +120,7 @@ jobs:
- name: "Checkout code" - name: "Checkout code"
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
submodules: 'true'
fetch-depth: 0 fetch-depth: 0
- name: "Download built game assets" - name: "Download built game assets"

3
.gitmodules vendored
View file

@ -0,0 +1,3 @@
[submodule "libtrx"]
path = subprojects/libtrx
url = git@github.com:LostArtefacts/libtrx.git

View file

@ -1,10 +1,11 @@
project('TR1X', ['c'], project('TR1X', 'c',
default_options: [ default_options: [
'c_std=c11', 'c_std=c11',
'warning_level=2', 'warning_level=2',
], ],
) )
dep_trx = subproject('libtrx')
c_compiler = meson.get_compiler('c') c_compiler = meson.get_compiler('c')
build_opts = [ build_opts = [
@ -272,7 +273,6 @@ sources = [
'src/math/math.c', 'src/math/math.c',
'src/math/math_misc.c', 'src/math/math_misc.c',
'src/math/matrix.c', 'src/math/matrix.c',
'src/memory.c',
'src/specific/s_audio.c', 'src/specific/s_audio.c',
'src/specific/s_audio_sample.c', 'src/specific/s_audio_sample.c',
'src/specific/s_audio_stream.c', 'src/specific/s_audio_stream.c',
@ -328,6 +328,7 @@ executable(
sources, sources,
include_directories: ['src/'], include_directories: ['src/'],
dependencies: dependencies, dependencies: dependencies,
link_with: dep_trx.get_variable('libtrx'),
link_args: link_args, link_args: link_args,
gui_app: true, gui_app: true,
install: true, install: true,

View file

@ -12,7 +12,7 @@
#include "json/json_parse.h" #include "json/json_parse.h"
#include "json/json_write.h" #include "json/json_write.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include "util.h" #include "util.h"
#include <stdio.h> #include <stdio.h>

View file

@ -1,7 +1,7 @@
#include "filesystem.h" #include "filesystem.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include "specific/s_filesystem.h" #include "specific/s_filesystem.h"
#include <stdio.h> #include <stdio.h>

View file

@ -22,7 +22,7 @@
#include "global/types.h" #include "global/types.h"
#include "global/vars.h" #include "global/vars.h"
#include "math/math.h" #include "math/math.h"
#include "memory.h" #include "shared/memory.h"
#include "strings.h" #include "strings.h"
#include "util.h" #include "util.h"

View file

@ -3,7 +3,7 @@
#include "filesystem.h" #include "filesystem.h"
#include "game/music.h" #include "game/music.h"
#include "game/sound.h" #include "game/sound.h"
#include "memory.h" #include "shared/memory.h"
#include "specific/s_fmv.h" #include "specific/s_fmv.h"
#include <stddef.h> #include <stddef.h>

View file

@ -1,5 +1,5 @@
#include "game_string.h" #include "game_string.h"
#include "memory.h" #include "shared/memory.h"
#include "util.h" #include "util.h"
#include <assert.h> #include <assert.h>

View file

@ -1,7 +1,7 @@
#include "game/gamebuf.h" #include "game/gamebuf.h"
#include "game/shell.h" #include "game/shell.h"
#include "memory.h" #include "shared/memory.h"
#include <stddef.h> #include <stddef.h>

View file

@ -19,7 +19,7 @@
#include "json/json_base.h" #include "json/json_base.h"
#include "json/json_parse.h" #include "json/json_parse.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include <string.h> #include <string.h>

View file

@ -9,7 +9,7 @@
#include "global/vars.h" #include "global/vars.h"
#include "items.h" #include "items.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include "util.h" #include "util.h"
#include <assert.h> #include <assert.h>

View file

@ -25,7 +25,7 @@
#include "global/types.h" #include "global/types.h"
#include "global/vars.h" #include "global/vars.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>

View file

@ -6,7 +6,7 @@
#include "game/sound.h" #include "game/sound.h"
#include "global/vars.h" #include "global/vars.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include "specific/s_audio.h" #include "specific/s_audio.h"
#include <stdio.h> #include <stdio.h>

View file

@ -3,7 +3,7 @@
#include "game/inventory.h" #include "game/inventory.h"
#include "game/inventory/inventory_vars.h" #include "game/inventory/inventory_vars.h"
#include "game/objects/common.h" #include "game/objects/common.h"
#include "memory.h" #include "shared/memory.h"
#include "strings.h" #include "strings.h"
#include <string.h> #include <string.h>

View file

@ -12,7 +12,7 @@
#include "game/text.h" #include "game/text.h"
#include "global/const.h" #include "global/const.h"
#include "global/vars.h" #include "global/vars.h"
#include "memory.h" #include "shared/memory.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>

View file

@ -14,7 +14,7 @@
#include "math/math.h" #include "math/math.h"
#include "math/math_misc.h" #include "math/math_misc.h"
#include "math/matrix.h" #include "math/matrix.h"
#include "memory.h" #include "shared/memory.h"
#include "specific/s_output.h" #include "specific/s_output.h"
#include "specific/s_shell.h" #include "specific/s_shell.h"
#include "util.h" #include "util.h"

View file

@ -4,7 +4,7 @@
#include "global/types.h" #include "global/types.h"
#include "global/vars.h" #include "global/vars.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include "util.h" #include "util.h"
#include <stddef.h> #include <stddef.h>

View file

@ -1,7 +1,7 @@
#include "game/picture.h" #include "game/picture.h"
#include "filesystem.h" #include "filesystem.h"
#include "memory.h" #include "shared/memory.h"
#include "specific/s_picture.h" #include "specific/s_picture.h"
#include <assert.h> #include <assert.h>

View file

@ -20,7 +20,7 @@
#include "global/const.h" #include "global/const.h"
#include "global/types.h" #include "global/types.h"
#include "global/vars.h" #include "global/vars.h"
#include "memory.h" #include "shared/memory.h"
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>

View file

@ -17,7 +17,7 @@
#include "json/bson_write.h" #include "json/bson_write.h"
#include "json/json_base.h" #include "json/json_base.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include "util.h" #include "util.h"
#include <assert.h> #include <assert.h>

View file

@ -13,7 +13,7 @@
#include "global/const.h" #include "global/const.h"
#include "global/vars.h" #include "global/vars.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include "util.h" #include "util.h"
#include <assert.h> #include <assert.h>

View file

@ -23,7 +23,7 @@
#include "global/types.h" #include "global/types.h"
#include "global/vars.h" #include "global/vars.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include "specific/s_shell.h" #include "specific/s_shell.h"
#include <stdarg.h> #include <stdarg.h>

View file

@ -3,7 +3,7 @@
#include "gfx/blitter.h" #include "gfx/blitter.h"
#include "gfx/context.h" #include "gfx/context.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include <string.h> #include <string.h>

View file

@ -3,7 +3,7 @@
#include "gfx/gl/gl_core_3_3.h" #include "gfx/gl/gl_core_3_3.h"
#include "gfx/gl/utils.h" #include "gfx/gl/utils.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
static const GLenum GL_PRIM_MODES[] = { static const GLenum GL_PRIM_MODES[] = {
GL_LINES, // GFX_3D_PRIM_LINE GL_LINES, // GFX_3D_PRIM_LINE

View file

@ -5,7 +5,7 @@
#include "gfx/gl/utils.h" #include "gfx/gl/utils.h"
#include "gfx/screenshot.h" #include "gfx/screenshot.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include <SDL2/SDL_video.h> #include <SDL2/SDL_video.h>
#include <string.h> #include <string.h>

View file

@ -4,7 +4,7 @@
#include "game/shell.h" #include "game/shell.h"
#include "gfx/gl/utils.h" #include "gfx/gl/utils.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>

View file

@ -1,7 +1,7 @@
#include "gfx/gl/texture.h" #include "gfx/gl/texture.h"
#include "gfx/gl/utils.h" #include "gfx/gl/utils.h"
#include "memory.h" #include "shared/memory.h"
#include <assert.h> #include <assert.h>

View file

@ -2,7 +2,7 @@
#include "game/picture.h" #include "game/picture.h"
#include "global/types.h" #include "global/types.h"
#include "memory.h" #include "shared/memory.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>

View file

@ -2,7 +2,7 @@
#include "json/json_base.h" #include "json/json_base.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>

View file

@ -2,7 +2,7 @@
#include "json/json_base.h" #include "json/json_base.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include <assert.h> #include <assert.h>
#include <float.h> #include <float.h>

View file

@ -1,6 +1,6 @@
#include "json/json_base.h" #include "json/json_base.h"
#include "memory.h" #include "shared/memory.h"
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>

View file

@ -1,7 +1,7 @@
#include "json/json_parse.h" #include "json/json_parse.h"
#include "json/json_base.h" #include "json/json_base.h"
#include "memory.h" #include "shared/memory.h"
struct json_parse_state_s { struct json_parse_state_s {
const char *src; const char *src;

View file

@ -1,7 +1,7 @@
#include "json/json_write.h" #include "json/json_write.h"
#include "json/json_base.h" #include "json/json_base.h"
#include "memory.h" #include "shared/memory.h"
static int json_write_minified_get_value_size( static int json_write_minified_get_value_size(
const struct json_value_s *value, size_t *size); const struct json_value_s *value, size_t *size);

View file

@ -1,7 +1,7 @@
#include "log.h" #include "log.h"
#include "filesystem.h" #include "filesystem.h"
#include "memory.h" #include "shared/memory.h"
#include "specific/s_log.h" #include "specific/s_log.h"
#include <stdarg.h> #include <stdarg.h>

View file

@ -1,50 +0,0 @@
#include "memory.h"
#include "game/shell.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
void *Memory_Alloc(size_t size)
{
void *result = malloc(size);
if (!result) {
Shell_ExitSystem("ERROR: Could not allocate enough memory");
}
memset(result, 0, size);
return result;
}
void *Memory_Realloc(void *memory, size_t size)
{
void *result = realloc(memory, size);
if (!result) {
Shell_ExitSystem("ERROR: Could not allocate enough memory");
}
return result;
}
void Memory_Free(void *memory)
{
if (memory) {
free(memory);
}
}
void Memory_FreePointer(void *arg)
{
assert(arg);
void *memory;
memcpy(&memory, arg, sizeof(void *));
memcpy(arg, &(void *) { NULL }, sizeof(void *));
Memory_Free(memory);
}
char *Memory_DupStr(const char *string)
{
assert(string);
char *memory = Memory_Alloc(strlen(string) + 1);
strcpy(memory, string);
return memory;
}

View file

@ -1,37 +0,0 @@
#pragma once
// Basic memory utilities that exit the game in case the system runs out of
// memory.
#include <stddef.h>
// Allocate n bytes. In case the memory allocation fails, shows an error to the
// user and exits the application. The allocated memory is filled with zeros.
void *Memory_Alloc(size_t size);
// Reallocate existing memory to n bytes, returning an address to the
// reallocated memory. In case the memory allocation fails, shows an error to
// the user and exits the application. All pointers to the old memory address
// become invalid. Preserves the previous memory contents. If the memory is
// NULL, the function acts like Memory_Alloc.
void *Memory_Realloc(void *memory, size_t size);
// Frees the memory associated with a given address. If the memory is NULL, the
// function is a no-op.
void Memory_Free(void *memory);
// Frees the memory associated with a given pointer and sets it to NULL. The
// user is expected to pass a pointer of their variable like so:
//
// char *mem = Memory_Alloc(10);
// Memory_FreePointer(&mem);
// (mem is now NULL)
//
// Giving a NULL to this function is a fatal error. Passing mem directly is
// also an error.
void Memory_FreePointer(void *memory);
// Duplicates a string. In case the memory allocation fails, shows an error to
// the user and exits the application. The string must be NULL-terminated.
// Giving a NULL to this function is a fatal error.
char *Memory_DupStr(const char *string);

1
src/shared Symbolic link
View file

@ -0,0 +1 @@
../subprojects/libtrx/src/

View file

@ -2,7 +2,7 @@
#include "specific/s_audio.h" #include "specific/s_audio.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <SDL2/SDL_error.h> #include <SDL2/SDL_error.h>

View file

@ -3,7 +3,7 @@
#include "game/shell.h" #include "game/shell.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include <SDL2/SDL_audio.h> #include <SDL2/SDL_audio.h>
#include <errno.h> #include <errno.h>

View file

@ -3,7 +3,7 @@
#include "filesystem.h" #include "filesystem.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include <SDL2/SDL_audio.h> #include <SDL2/SDL_audio.h>
#include <SDL2/SDL_error.h> #include <SDL2/SDL_error.h>

View file

@ -1,7 +1,7 @@
#include "specific/s_filesystem.h" #include "specific/s_filesystem.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include "strings.h" #include "strings.h"
#include <SDL2/SDL_filesystem.h> #include <SDL2/SDL_filesystem.h>

View file

@ -33,7 +33,7 @@
#include "gfx/context.h" #include "gfx/context.h"
#include "global/types.h" #include "global/types.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include "specific/s_audio.h" #include "specific/s_audio.h"
#include "specific/s_output.h" #include "specific/s_output.h"
#include "specific/s_shell.h" #include "specific/s_shell.h"

View file

@ -3,7 +3,7 @@
#include "filesystem.h" #include "filesystem.h"
#include "game/picture.h" #include "game/picture.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>

View file

@ -9,7 +9,7 @@
#include "game/shell.h" #include "game/shell.h"
#include "game/sound.h" #include "game/sound.h"
#include "log.h" #include "log.h"
#include "memory.h" #include "shared/memory.h"
#define SDL_MAIN_HANDLED #define SDL_MAIN_HANDLED

1
subprojects/libtrx Submodule

@ -0,0 +1 @@
Subproject commit b271b45a5575da9d45478b6ed71aa1208fd350d0