2022-04-20 06:06:18 +02:00
|
|
|
#include "dynos.cpp.h"
|
2022-04-23 12:05:16 +02:00
|
|
|
extern "C" {
|
|
|
|
#include "engine/graph_node.h"
|
|
|
|
}
|
2022-04-20 06:06:18 +02:00
|
|
|
|
|
|
|
static Array<PackData>& DynosPacks() {
|
|
|
|
static Array<PackData> sDynosPacks;
|
|
|
|
return sDynosPacks;
|
|
|
|
}
|
|
|
|
|
2022-05-08 03:20:53 +02:00
|
|
|
static void ScanPackBins(struct PackData* aPack) {
|
|
|
|
DIR *_PackDir = opendir(aPack->mPath.c_str());
|
|
|
|
if (!_PackDir) { return; }
|
|
|
|
|
|
|
|
struct dirent *_PackEnt = NULL;
|
|
|
|
while ((_PackEnt = readdir(_PackDir)) != NULL) {
|
|
|
|
// Skip . and ..
|
|
|
|
if (SysPath(_PackEnt->d_name) == ".") continue;
|
|
|
|
if (SysPath(_PackEnt->d_name) == "..") continue;
|
|
|
|
|
|
|
|
SysPath _FileName = fstring("%s/%s", aPack->mPath.c_str(), _PackEnt->d_name);
|
|
|
|
s32 length = strlen(_PackEnt->d_name);
|
|
|
|
|
|
|
|
// check for actors
|
|
|
|
if (length > 4 && !strncmp(&_PackEnt->d_name[length - 4], ".bin", 4)) {
|
|
|
|
String _ActorName = _PackEnt->d_name;
|
|
|
|
_ActorName[length - 4] = '\0';
|
2023-05-15 10:15:20 +02:00
|
|
|
DynOS_Actor_LoadFromBinary(aPack->mPath, _ActorName.begin(), _FileName, true);
|
2022-05-08 03:20:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// check for textures
|
|
|
|
if (length > 4 && !strncmp(&_PackEnt->d_name[length - 4], ".tex", 4)) {
|
|
|
|
String _TexName = _PackEnt->d_name;
|
|
|
|
_TexName[length - 4] = '\0';
|
|
|
|
DynOS_Tex_LoadFromBinary(aPack->mPath, _FileName, _TexName.begin(), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-20 06:06:18 +02:00
|
|
|
static void DynOS_Pack_ActivateActor(s32 aPackIndex, Pair<const char *, GfxData *>& pair) {
|
|
|
|
const char* aActorName = pair.first;
|
|
|
|
GfxData* aGfxData = pair.second;
|
2022-05-07 07:03:12 +02:00
|
|
|
|
2022-05-04 09:14:33 +02:00
|
|
|
auto& geoNode = *(aGfxData->mGeoLayouts.end() - 1);
|
2023-05-16 05:45:04 +02:00
|
|
|
u32 id = 0;
|
2023-05-19 06:29:57 +02:00
|
|
|
GraphNode* graphNode = DynOS_Model_LoadGeo(&id, MODEL_POOL_PERMANENT, geoNode->mData, true);
|
2022-04-20 06:06:18 +02:00
|
|
|
if (graphNode == NULL) { return; }
|
|
|
|
|
|
|
|
const void* georef = DynOS_Builtin_Actor_GetFromName(aActorName);
|
|
|
|
graphNode->georef = georef;
|
|
|
|
|
2022-04-24 00:54:39 +02:00
|
|
|
ActorGfx actorGfx;
|
|
|
|
actorGfx.mGfxData = aGfxData;
|
|
|
|
actorGfx.mGraphNode = graphNode;
|
|
|
|
actorGfx.mPackIndex = aPackIndex;
|
2022-04-20 06:06:18 +02:00
|
|
|
|
2022-05-04 09:14:33 +02:00
|
|
|
if (geoNode->mFlags & GRAPH_EXTRA_FORCE_3D) {
|
2022-04-23 12:05:16 +02:00
|
|
|
actorGfx.mGraphNode->extraFlags |= GRAPH_EXTRA_FORCE_3D;
|
2022-05-04 09:14:33 +02:00
|
|
|
}
|
2022-04-23 12:05:16 +02:00
|
|
|
|
2022-04-20 06:06:18 +02:00
|
|
|
DynOS_Actor_Valid(georef, actorGfx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DynOS_Pack_DeactivateActor(s32 aPackIndex, Pair<const char *, GfxData *>& pair) {
|
|
|
|
const char* aActorName = pair.first;
|
|
|
|
const void* georef = DynOS_Builtin_Actor_GetFromName(aActorName);
|
|
|
|
DynOS_Actor_Invalid(georef, aPackIndex);
|
|
|
|
|
|
|
|
// figure out which actor to replace it with
|
|
|
|
Pair<const char *, GfxData *>* _Replacement = NULL;
|
|
|
|
s32 _ReplacementPackIndex = 0;
|
|
|
|
for (auto& _Pack : DynosPacks()) {
|
|
|
|
if (!_Pack.mEnabled) { continue; }
|
|
|
|
auto _Tmp = DynOS_Pack_GetActor(&_Pack, aActorName);
|
|
|
|
if (_Tmp != NULL) {
|
|
|
|
_Replacement = _Tmp;
|
|
|
|
_ReplacementPackIndex = _Pack.mIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_Replacement != NULL) {
|
|
|
|
DynOS_Pack_ActivateActor(_ReplacementPackIndex, *_Replacement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 DynOS_Pack_GetCount() {
|
|
|
|
return DynosPacks().Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DynOS_Pack_SetEnabled(PackData* aPack, bool aEnabled) {
|
|
|
|
if (aPack == NULL) { return; }
|
|
|
|
aPack->mEnabled = aEnabled;
|
2022-04-23 12:23:30 +02:00
|
|
|
aPack->mEnabledSet = true;
|
2022-04-20 06:06:18 +02:00
|
|
|
|
2022-05-08 03:20:53 +02:00
|
|
|
if (aEnabled && !aPack->mLoaded) {
|
|
|
|
ScanPackBins(aPack);
|
|
|
|
aPack->mLoaded = true;
|
|
|
|
}
|
|
|
|
|
2022-04-20 06:06:18 +02:00
|
|
|
if (aEnabled) {
|
|
|
|
for (auto& pair : aPack->mGfxData) {
|
|
|
|
DynOS_Pack_ActivateActor(aPack->mIndex, pair);
|
|
|
|
}
|
2022-05-07 07:03:12 +02:00
|
|
|
for (auto& _Tex : aPack->mTextures) {
|
|
|
|
DynOS_Tex_Activate(_Tex, false);
|
|
|
|
}
|
2022-04-20 06:06:18 +02:00
|
|
|
} else {
|
|
|
|
for (auto& pair : aPack->mGfxData) {
|
|
|
|
DynOS_Pack_DeactivateActor(aPack->mIndex, pair);
|
|
|
|
}
|
2022-05-07 07:03:12 +02:00
|
|
|
for (auto& _Tex : aPack->mTextures) {
|
|
|
|
DynOS_Tex_Deactivate(_Tex);
|
|
|
|
}
|
2022-04-20 06:06:18 +02:00
|
|
|
}
|
|
|
|
DynOS_Actor_Override_All();
|
|
|
|
}
|
|
|
|
|
|
|
|
PackData* DynOS_Pack_GetFromIndex(s32 aIndex) {
|
|
|
|
auto& _DynosPacks = DynosPacks();
|
|
|
|
if (aIndex < 0 || aIndex >= _DynosPacks.Count()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return &_DynosPacks[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
PackData* DynOS_Pack_GetFromPath(const SysPath& aPath) {
|
|
|
|
for (auto& packData : DynosPacks()) {
|
|
|
|
if (packData.mPath == aPath) {
|
|
|
|
return &packData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:32:13 +02:00
|
|
|
PackData* DynOS_Pack_GetFromDisplayName(const char* aDisplayName) {
|
|
|
|
for (auto& packData : DynosPacks()) {
|
|
|
|
if (!strcmp(packData.mDisplayName.begin(), aDisplayName)) {
|
|
|
|
return &packData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-04-20 06:06:18 +02:00
|
|
|
PackData* DynOS_Pack_Add(const SysPath& aPath) {
|
|
|
|
PackData* existing = DynOS_Pack_GetFromPath(aPath);
|
|
|
|
if (existing != NULL) { return existing; }
|
|
|
|
|
2023-04-04 09:32:13 +02:00
|
|
|
// extract basename
|
|
|
|
const char* displayName = aPath.c_str();
|
|
|
|
const char* ctoken = displayName;
|
|
|
|
while (*ctoken != '\0') {
|
|
|
|
if (*ctoken == '/' || *ctoken == '\\') {
|
|
|
|
if (*(ctoken + 1) != '\0') {
|
|
|
|
displayName = (ctoken + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctoken++;
|
|
|
|
}
|
|
|
|
|
|
|
|
existing = DynOS_Pack_GetFromDisplayName(displayName);
|
|
|
|
if (existing != NULL) { return existing; }
|
|
|
|
|
|
|
|
|
2022-04-20 06:06:18 +02:00
|
|
|
auto& _DynosPacks = DynosPacks();
|
|
|
|
s32 index = _DynosPacks.Count();
|
2022-06-06 04:40:21 +02:00
|
|
|
const PackData packData = {
|
2022-04-20 06:06:18 +02:00
|
|
|
.mIndex = index,
|
2023-02-23 02:27:28 +01:00
|
|
|
.mEnabled = false,
|
|
|
|
.mEnabledSet = false,
|
2022-04-20 06:06:18 +02:00
|
|
|
.mPath = aPath,
|
2023-02-23 02:27:28 +01:00
|
|
|
.mDisplayName = "",
|
2022-04-20 06:06:18 +02:00
|
|
|
.mGfxData = {},
|
2022-05-08 03:20:53 +02:00
|
|
|
.mTextures = {},
|
|
|
|
.mLoaded = false,
|
2022-06-06 04:40:21 +02:00
|
|
|
};
|
|
|
|
_DynosPacks.Add(packData);
|
2022-04-20 06:06:18 +02:00
|
|
|
|
|
|
|
PackData* _Pack = &_DynosPacks[index];
|
|
|
|
|
2023-04-04 09:32:13 +02:00
|
|
|
_Pack->mDisplayName = displayName;
|
2022-04-20 06:06:18 +02:00
|
|
|
|
2022-04-23 12:23:30 +02:00
|
|
|
_Pack->mEnabled = true;
|
|
|
|
_Pack->mEnabledSet = false;
|
2022-04-20 06:06:18 +02:00
|
|
|
|
|
|
|
return _Pack;
|
|
|
|
}
|
|
|
|
|
2022-04-23 12:23:30 +02:00
|
|
|
void DynOS_Pack_Init() {
|
|
|
|
for (auto& pack : DynosPacks()) {
|
|
|
|
if (!pack.mEnabledSet) {
|
|
|
|
DynOS_Pack_SetEnabled(&pack, pack.mEnabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-20 06:06:18 +02:00
|
|
|
Pair<const char *, GfxData *>* DynOS_Pack_GetActor(PackData* aPackData, const char* aActorName) {
|
|
|
|
if (aPackData == NULL || aActorName == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (auto& pair : aPackData->mGfxData) {
|
|
|
|
if (!strcmp(pair.first, aActorName)) {
|
|
|
|
return &pair;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DynOS_Pack_AddActor(PackData* aPackData, const char* aActorName, GfxData* aGfxData) {
|
|
|
|
if (aPackData == NULL || aActorName == NULL || aGfxData == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 index = aPackData->mGfxData.Count();
|
2023-05-15 10:15:20 +02:00
|
|
|
aPackData->mGfxData.Add({ strdup(aActorName), aGfxData });
|
2022-04-20 06:06:18 +02:00
|
|
|
|
|
|
|
if (aPackData->mEnabled) {
|
|
|
|
DynOS_Pack_ActivateActor(aPackData->mIndex, aPackData->mGfxData[index]);
|
|
|
|
}
|
|
|
|
}
|
2022-05-07 07:03:12 +02:00
|
|
|
|
|
|
|
DataNode<TexData>* DynOS_Pack_GetTex(PackData* aPackData, const char* aTexName) {
|
|
|
|
if (aPackData == NULL || aTexName == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& _Tex : aPackData->mTextures) {
|
|
|
|
if (!strcmp(_Tex->mName.begin(), aTexName)) {
|
|
|
|
return _Tex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DynOS_Pack_AddTex(PackData* aPackData, DataNode<TexData>* aTexData) {
|
|
|
|
if (aPackData == NULL || aTexData == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aPackData->mTextures.Add(aTexData);
|
|
|
|
|
|
|
|
if (aPackData->mEnabled) {
|
|
|
|
DynOS_Tex_Activate(aTexData, false);
|
|
|
|
}
|
|
|
|
}
|