Allow lua mods to override models, have DynOS generate bins

This commit is contained in:
MysterD 2022-03-16 21:26:29 -07:00
parent a13a784782
commit 2804a48e4e
7 changed files with 48 additions and 3 deletions

View File

@ -639,6 +639,7 @@ Array<ActorGfx> &DynOS_Gfx_GetActorList();
Array<PackData *> &DynOS_Gfx_GetPacks();
#ifdef COOP
Array<bool> &DynOS_Gfx_GetPacksEnabled();
void DynOS_Gfx_GeneratePacks(const char* directory);
#endif
Array<String> DynOS_Gfx_Init();
void DynOS_Gfx_Update();

View File

@ -13,6 +13,8 @@ const char* dynos_packs_get(s32 index);
bool dynos_packs_get_enabled(s32 index);
void dynos_packs_set_enabled(s32 index, bool value);
void dynos_generate_packs(const char* directory);
void dynos_add_actor_custom(const char *modPath, const char* geoName);
const void* dynos_geolayout_get(const char *name);

View File

@ -53,6 +53,10 @@ void dynos_packs_set_enabled(s32 index, bool value) {
DynOS_Gfx_GetPacksEnabled()[index] = value;
}
void dynos_generate_packs(const char* directory) {
DynOS_Gfx_GeneratePacks(directory);
}
void dynos_add_actor_custom(const char *modPath, const char* geoName) {
DynOS_Geo_AddActorCustom(modPath, geoName);
}

View File

@ -15,6 +15,26 @@ Array<bool> &DynOS_Gfx_GetPacksEnabled() {
static Array<bool> sPacksEnabled;
return sPacksEnabled;
}
void DynOS_Gfx_GeneratePacks(const char* directory) {
DIR *modsDir = opendir(directory);
if (!modsDir) { return; }
struct dirent *dir = NULL;
while ((dir = readdir(modsDir)) != NULL) {
// Skip . and ..
if (SysPath(dir->d_name) == ".") continue;
if (SysPath(dir->d_name) == "..") continue;
// If pack folder exists, generate bins
SysPath _PackFolder = fstring("%s/%s/actors", directory, dir->d_name);
if (fs_sys_dir_exists(_PackFolder.c_str())) {
DynOS_Gfx_GeneratePack(_PackFolder);
}
}
closedir(modsDir);
}
#endif
Array<String> DynOS_Gfx_Init() {

View File

@ -106,6 +106,9 @@ void DynOS_Gfx_Update() {
#ifdef COOP
Array<bool> &_Enabled = DynOS_Gfx_GetPacksEnabled();
const Array<PackData *> &pDynosPacks = DynOS_Gfx_GetPacks();
while (_Enabled.Count() < pDynosPacks.Count()) {
_Enabled.Add(true);
}
#else
Array<bool> _Enabled;
const Array<PackData *> &pDynosPacks = DynOS_Gfx_GetPacks();

View File

@ -342,9 +342,13 @@ static Array<Pair<const char*, void *>> sDynosCustomActors;
void DynOS_Geo_AddActorCustom(const SysPath &aPackFolder, const char *aActorName) {
// check for duplicates
bool isUnique = true;
s32 foundIndex = -1;
for (s32 i = 0; i < DynOS_Geo_GetActorCount(); ++i) {
if (!strcmp(DynOS_Geo_GetActorName(i), aActorName)) {
return;
isUnique = false;
foundIndex = i;
break;
}
}
@ -354,24 +358,31 @@ void DynOS_Geo_AddActorCustom(const SysPath &aPackFolder, const char *aActorName
GfxData *_GfxData = DynOS_Gfx_LoadFromBinary(aPackFolder, actorName);
if (!_GfxData) {
free(actorName);
return;
}
void* geoLayout = (*(_GfxData->mGeoLayouts.end() - 1))->mData;
if (!geoLayout) {
free(actorName);
return;
}
// Add to custom actors
s32 index = DynOS_Geo_GetActorCount();
sDynosCustomActors.Add({ actorName, geoLayout });
if (isUnique) {
sDynosCustomActors.Add({ actorName, geoLayout });
} else {
index = foundIndex;
free(actorName);
}
// Alloc and init the actors gfx list
Array<ActorGfx> &pActorGfxList = DynOS_Gfx_GetActorList();
pActorGfxList.Resize(DynOS_Geo_GetActorCount());
pActorGfxList[index].mPackIndex = -1;
pActorGfxList[index].mGfxData = _GfxData;
pActorGfxList[index].mGraphNode = (GraphNode *) DynOS_Geo_GetGraphNode(DynOS_Geo_GetActorLayout(index), true);
pActorGfxList[index].mGraphNode = (GraphNode *) DynOS_Geo_GetGraphNode(geoLayout, true);
}
s32 DynOS_Geo_GetActorCount() {

View File

@ -1,6 +1,7 @@
#include <unistd.h>
#include "mods.h"
#include "mods_utils.h"
#include "data/dynos_coop.c.h"
#include "pc/debuglog.h"
#define MOD_DIRECTORY "mods"
@ -91,6 +92,9 @@ void mods_activate(struct Mods* mods) {
}
static void mods_load(struct Mods* mods, char* modsBasePath) {
// generate bins
dynos_generate_packs(modsBasePath);
// sanity check
if (modsBasePath == NULL) {
LOG_ERROR("Trying to load from NULL path!");