commit 0546212bf5c3ad82f1319d654df528d1580a0347
parent e2657a53c59f09ffdddd72bf01caf6a9d080fc56
Author: MikoĊaj Lenczewski <mblenczewski@gmail.com>
Date: Sun, 12 Feb 2023 16:45:30 +0000
Introduced type definitions and function stubs for WAD types
Diffstat:
5 files changed, 101 insertions(+), 0 deletions(-)
diff --git a/libriot/include/libriot/wad.h b/libriot/include/libriot/wad.h
@@ -10,6 +10,50 @@
extern "C" {
#endif /* __cplusplus */
+enum riot_wad_compression {
+ RIOT_WAD_COMPRESSION_NONE = 0,
+ RIOT_WAD_COMPRESSION_GZIP = 1,
+ RIOT_WAD_COMPRESSION_SATELLITE = 2,
+ RIOT_WAD_COMPRESSION_ZSTD = 3,
+ RIOT_WAD_COMPRESSION_ZSTD_CHUNK = 4,
+};
+
+struct riot_wad_chunk {
+ xxh64_u64 path_hash;
+ u32 data_offset, compressed_size, decompressed_size;
+ enum riot_wad_compression compression;
+ b8 duplicated;
+ u16 sub_chunk_count, sub_chunk_start;
+ u64 checksum;
+ struct riot_intrusive_list_node list;
+};
+
+struct riot_wad {
+ u8 major, minor;
+ riot_offptr_t root_chunk;
+};
+
+#define RIOT_WAD_CTX_CHUNK_POOL_SZ 4 * KiB
+
+struct riot_wad_ctx {
+ struct mem_pool chunk_pool;
+};
+
+extern b32
+riot_wad_ctx_init(struct riot_wad_ctx *self);
+
+extern void
+riot_wad_ctx_free(struct riot_wad_ctx *self);
+
+extern b32
+riot_wad_ctx_pushn_chunk(struct riot_wad_ctx *self, u32 count, riot_offptr_t *out);
+
+extern b32
+riot_wad_read(struct riot_wad_ctx *ctx, struct mem_stream stream);
+
+extern b32
+riot_wad_write(struct riot_wad_ctx *ctx, struct mem_stream stream);
+
#ifdef __cplusplus
};
#endif /* __cplusplus */
diff --git a/libriot/makefile.mk b/libriot/makefile.mk
@@ -19,6 +19,9 @@ LIBRIOT_FLAGS := \
$(LDFLAGS)
LIBRIOT_SOURCES := libriot/src/libriot.c \
+ libriot/src/wad.c \
+ libriot/src/wad_reader.c \
+ libriot/src/wad_writer.c \
libriot/src/inibin.c \
libriot/src/inibin_reader.c \
libriot/src/inibin_writer.c
diff --git a/libriot/src/wad.c b/libriot/src/wad.c
@@ -0,0 +1,34 @@
+#include "libriot/wad.h"
+
+b32
+riot_wad_ctx_init(struct riot_wad_ctx *self) {
+ assert(self);
+
+ if (!MEM_POOL_INIT(&self->chunk_pool, struct riot_wad_chunk, RIOT_WAD_CTX_CHUNK_POOL_SZ))
+ goto chunk_pool_alloc_failure;
+
+ return true;
+
+chunk_pool_alloc_failure:
+ return false;
+}
+
+void
+riot_wad_ctx_free(struct riot_wad_ctx *self) {
+ assert(self);
+
+ mem_pool_free(&self->chunk_pool);
+}
+
+b32
+riot_wad_ctx_pushn_chunk(struct riot_wad_ctx *self, u32 count, riot_offptr_t *out) {
+ assert(self);
+ assert(out);
+
+ void *absptr = MEM_POOL_ALLOC(&self->chunk_pool, struct riot_wad_chunk, count);
+ if (!absptr) return false;
+
+ *out = (struct riot_wad_chunk *)absptr - (struct riot_wad_chunk *)self->chunk_pool.ptr;
+
+ return true;
+}
diff --git a/libriot/src/wad_reader.c b/libriot/src/wad_reader.c
@@ -0,0 +1,10 @@
+#include "libriot/wad.h"
+
+b32
+riot_wad_read(struct riot_wad_ctx *ctx, struct mem_stream stream) {
+ assert(ctx);
+
+ (void) stream;
+
+ return false;
+}
diff --git a/libriot/src/wad_writer.c b/libriot/src/wad_writer.c
@@ -0,0 +1,10 @@
+#include "libriot/wad.h"
+
+b32
+riot_wad_write(struct riot_wad_ctx *ctx, struct mem_stream stream) {
+ assert(ctx);
+
+ (void) stream;
+
+ return false;
+}