2022-04-08 17:18:06 +02:00
|
|
|
#include "dynos.cpp.h"
|
|
|
|
|
|
|
|
static Array<Pair<const char*, DataNode<Collision>*>> sDynosCollisions;
|
|
|
|
|
2022-04-16 22:05:10 +02:00
|
|
|
void DynOS_Col_Activate(const SysPath &aFilename, const char *aCollisionName) {
|
2022-04-08 17:18:06 +02:00
|
|
|
// check for duplicates
|
|
|
|
for (s32 i = 0; i < sDynosCollisions.Count(); ++i) {
|
|
|
|
if (!strcmp(sDynosCollisions[i].first, aCollisionName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate name
|
|
|
|
u16 collisionLen = strlen(aCollisionName);
|
|
|
|
char* collisionName = (char*)calloc(1, sizeof(char) * (collisionLen + 1));
|
|
|
|
strcpy(collisionName, aCollisionName);
|
|
|
|
|
|
|
|
// Load
|
2022-04-16 22:05:10 +02:00
|
|
|
DataNode<Collision>* _Node = DynOS_Col_LoadFromBinary(aFilename, collisionName);
|
2022-04-08 17:18:06 +02:00
|
|
|
if (!_Node) {
|
|
|
|
free(collisionName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add to collisions
|
|
|
|
sDynosCollisions.Add({ collisionName, _Node });
|
|
|
|
}
|
|
|
|
|
|
|
|
Collision* DynOS_Col_Get(const char* collisionName) {
|
|
|
|
// check levels
|
|
|
|
auto& levelsArray = DynOS_Lvl_GetArray();
|
|
|
|
for (auto& lvl : levelsArray) {
|
|
|
|
for (auto& col : lvl.second->mCollisions) {
|
|
|
|
if (col->mName == collisionName) {
|
|
|
|
return col->mData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-09 04:17:57 +02:00
|
|
|
// check mod actor collisions
|
2022-04-08 17:18:06 +02:00
|
|
|
for (s32 i = 0; i < sDynosCollisions.Count(); ++i) {
|
|
|
|
if (!strcmp(sDynosCollisions[i].first, collisionName)) {
|
|
|
|
return sDynosCollisions[i].second->mData;
|
|
|
|
}
|
|
|
|
}
|
2022-04-09 04:17:57 +02:00
|
|
|
|
|
|
|
// check builtin collisions
|
|
|
|
return (Collision*)DynOS_Builtin_LvlCol_GetFromName(collisionName);
|
2022-04-08 17:18:06 +02:00
|
|
|
}
|