Build TMS as a unity build too

The C portion of TMS is its own unity build chunk while the portions of TMS in C++ are lumped into the main chunk
This commit is contained in:
ROllerozxa 2026-06-07 21:13:52 +02:00
commit 4c395f09af
5 changed files with 68 additions and 25 deletions

View file

@ -105,11 +105,6 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}) ${CMAKE_CURRENT_BINARY_DIR})
file(GLOB SRCS file(GLOB SRCS
src/tms/core/*.c
src/tms/math/*.c
src/tms/cpp.cc
src/tms/modules/3ds.c
src/*.c src/*.c
lib/GLAD/src/gl.c lib/GLAD/src/gl.c
@ -119,6 +114,7 @@ file(GLOB SRCS
if(UNITY_BUILD) if(UNITY_BUILD)
list(APPEND SRCS list(APPEND SRCS
src/tms/_unity_chunk.c
src/_unity_chunk.cc src/_unity_chunk.cc
src/game.cc src/game.cc
src/game-gearbox-edit.cc src/game-gearbox-edit.cc
@ -131,6 +127,11 @@ if(UNITY_BUILD)
lib/Box2D/_unity_chunk.cc) lib/Box2D/_unity_chunk.cc)
else() else()
file(GLOB MAIN_SRCS file(GLOB MAIN_SRCS
src/tms/core/*.c
src/tms/math/*.c
src/tms/cpp.cc
src/tms/modules/3ds.c
src/*.cc src/*.cc
src/luascript/*.cc src/luascript/*.cc
@ -193,17 +194,17 @@ if(USE_LUASOCKET)
list(APPEND SRCS ${LUASOCKET_SRCS}) list(APPEND SRCS ${LUASOCKET_SRCS})
endif() endif()
if(NOT UNITY_BUILD)
if(SCREENSHOT_BUILD)
set(BACKEND_SRC main_screenshotter.cc)
else()
set(BACKEND_SRC main.cc)
list(APPEND SRCS src/tms/backend/pipe.cc)
endif()
if(SCREENSHOT_BUILD) list(APPEND SRCS src/tms/backend/${BACKEND_SRC})
set(BACKEND_SRC main_screenshotter.cc)
else()
set(BACKEND_SRC main.cc)
list(APPEND SRCS src/tms/backend/pipe.cc)
endif() endif()
list(APPEND SRCS src/tms/backend/${BACKEND_SRC})
if(WIN32) if(WIN32)
list(APPEND SRCS packaging/principia.rc) list(APPEND SRCS packaging/principia.rc)
endif() endif()

View file

@ -232,4 +232,13 @@
#include "luascript/lua_world.cc" #include "luascript/lua_world.cc"
#include "luascript/lua.cc" #include "luascript/lua.cc"
#if SCREENSHOT_BUILD
#include "tms/backend/main_screenshotter.cc"
#else
#include "tms/backend/main.cc"
#include "tms/backend/pipe.cc"
#endif
#include "tms/cpp.cc"
#endif #endif

View file

@ -1076,7 +1076,7 @@ escript::solve_electronics()
return 0; return 0;
} }
static unsigned char keys[5] = {0x41, 0xf3, 0x1a, 0x44, 0x14}; static unsigned char encryption_keys[5] = {0x41, 0xf3, 0x1a, 0x44, 0x14};
#define IS_ENCRYPTED(ver) \ #define IS_ENCRYPTED(ver) \
ver >= LEVEL_VERSION_1_5 \ ver >= LEVEL_VERSION_1_5 \
@ -1126,7 +1126,7 @@ escript::on_load(bool created, bool has_state)
// For old level versions above 1.5+, LuaScript code is encrypted // For old level versions above 1.5+, LuaScript code is encrypted
if (IS_ENCRYPTED(W->level.version)) { if (IS_ENCRYPTED(W->level.version)) {
for (uint32_t x=0; x<this->properties[0].v.s.len; ++x) { for (uint32_t x=0; x<this->properties[0].v.s.len; ++x) {
this->properties[0].v.s.buf[x] ^= keys[x%5]; this->properties[0].v.s.buf[x] ^= encryption_keys[x%5];
} }
} }
} }
@ -1140,7 +1140,7 @@ escript::pre_write()
// For old level versions above 1.5+, LuaScript code is encrypted // For old level versions above 1.5+, LuaScript code is encrypted
if (IS_ENCRYPTED(W->level.version)) { if (IS_ENCRYPTED(W->level.version)) {
for (uint32_t x=0; x<this->properties[0].v.s.len; ++x) { for (uint32_t x=0; x<this->properties[0].v.s.len; ++x) {
this->properties[0].v.s.buf[x] ^= keys[x%5]; this->properties[0].v.s.buf[x] ^= encryption_keys[x%5];
} }
} }
} }
@ -1153,7 +1153,7 @@ escript::post_write()
// For old level versions above 1.5+, LuaScript code is encrypted // For old level versions above 1.5+, LuaScript code is encrypted
if (IS_ENCRYPTED(W->level.version)) { if (IS_ENCRYPTED(W->level.version)) {
for (uint32_t x=0; x<this->properties[0].v.s.len; ++x) { for (uint32_t x=0; x<this->properties[0].v.s.len; ++x) {
this->properties[0].v.s.buf[x] ^= keys[x%5]; this->properties[0].v.s.buf[x] ^= encryption_keys[x%5];
} }
} }
} }

33
src/tms/_unity_chunk.c Normal file
View file

@ -0,0 +1,33 @@
#ifdef UNITY_BUILD
#include "core/atlas.c"
#include "core/camera.c"
#include "core/ddraw.c"
#include "core/entity.c"
#include "core/event.c"
#include "core/framebuffer.c"
#include "core/gbuffer.c"
#include "core/graph.c"
#include "core/hash.c"
#include "core/material.c"
#include "core/mesh.c"
#include "core/meshfactory.c"
#include "core/model.c"
#include "core/pipeline.c"
#include "core/program.c"
#include "core/scene.c"
#include "core/screen.c"
#include "core/shader.c"
#include "core/storage.c"
#include "core/surface.c"
#include "core/texture.c"
#include "core/tms.c"
#include "core/varray.c"
#include "core/wdg.c"
#include "math/intersect.c"
#include "math/math.c"
#include "modules/3ds.c"
#endif

View file

@ -3,7 +3,7 @@
#define OBJ_NAME_MAX 32 #define OBJ_NAME_MAX 32
struct vertex { struct mdl_vert {
tvec3 pos; tvec3 pos;
tvec3 nor; tvec3 nor;
tvec2 uv; tvec2 uv;
@ -18,7 +18,7 @@ load_3ds_model(struct tms_model *model,
uint16_t num_items; uint16_t num_items;
char object_name[OBJ_NAME_MAX]; char object_name[OBJ_NAME_MAX];
struct vertex *vertex_buf = 0; struct mdl_vert *vertex_buf = 0;
uint16_t *index_buf = 0; uint16_t *index_buf = 0;
uint16_t base_index; uint16_t base_index;
@ -68,14 +68,14 @@ load_3ds_model(struct tms_model *model,
sz = model->vertices->size; sz = model->vertices->size;
base_index = sz / sizeof(struct vertex); base_index = sz / sizeof(struct mdl_vert);
if (base_index > 0x7fff) { if (base_index > 0x7fff) {
//tms_infof("WARNING TOO MANY INDICES ----------------------------------------h"); //tms_infof("WARNING TOO MANY INDICES ----------------------------------------h");
} }
//tms_infof("base index:%d", base_index); //tms_infof("base index:%d", base_index);
tms_gbuffer_realloc(model->vertices, sz + num_items * sizeof(struct vertex)); tms_gbuffer_realloc(model->vertices, sz + num_items * sizeof(struct mdl_vert));
vertex_buf = (struct vertex *)(model->vertices->buf+sz); vertex_buf = (struct mdl_vert *)(model->vertices->buf+sz);
for (int x=0; x<num_items; x++) { for (int x=0; x<num_items; x++) {
SDL_RWread(fp, &vertex_buf[x].pos, 4, 3); SDL_RWread(fp, &vertex_buf[x].pos, 4, 3);
@ -121,7 +121,7 @@ load_3ds_model(struct tms_model *model,
// tms_debugf("found uv mapping chunk, num items: %d", num_items); // tms_debugf("found uv mapping chunk, num items: %d", num_items);
tms_assertf(num_vertices != 0, "oops! texture coordinates specified before vertices list, unsupported at this time"); tms_assertf(num_vertices != 0, "oops! texture coordinates specified before vertices list, unsupported at this time");
//tms_assertf(num_items*sizeof(struct vertex) == vertices->size, "number texture coordinates does not match number of vertices"); //tms_assertf(num_items*sizeof(struct mdl_vert) == vertices->size, "number texture coordinates does not match number of vertices");
for (int x=0; x<num_items; x++) for (int x=0; x<num_items; x++)
SDL_RWread(fp, &vertex_buf[x].uv, 4, 2); SDL_RWread(fp, &vertex_buf[x].uv, 4, 2);
@ -143,8 +143,8 @@ load_3ds_model(struct tms_model *model,
struct tms_mesh *mesh = tms_model_create_mesh(model); struct tms_mesh *mesh = tms_model_create_mesh(model);
mesh->i_start = ((char*)index_buf - model->indices->buf) / 2;// / sizeof(struct vertex); mesh->i_start = ((char*)index_buf - model->indices->buf) / 2;// / sizeof(struct mdl_vert);
mesh->i_count = num_indices;// / sizeof(struct vertex); mesh->i_count = num_indices;// / sizeof(struct mdl_vert);
mesh->v_start = ((char*)vertex_buf - model->vertices->buf); mesh->v_start = ((char*)vertex_buf - model->vertices->buf);
mesh->v_count = num_vertices; mesh->v_count = num_vertices;