|
1 | 1 | #include "ClassManager_Z.h" |
| 2 | +#include "Console_Z.h" |
| 3 | +#include "Program_Z.h" |
| 4 | + |
| 5 | +#ifdef __MWERKS__ // TODO: Should check for GC instead of metrowerks |
| 6 | +#define BIGFILE_EXTENSION ".DGC" |
| 7 | +#define BIGFILE_NAME_EXTENSION ".NGC" |
| 8 | +#define BIGFILE_PLATFORM_VERSION ".01" |
| 9 | +#else |
| 10 | +// $SABE: If this gets hit define a bigfile extension and version for the platform you're building on |
| 11 | +#define BIGFILE_EXTENSION ".DXX" |
| 12 | +#define BIGFILE_NAME_EXTENSION ".NXX" |
| 13 | +#define BIGFILE_PLATFORM_VERSION ".99" |
| 14 | +#endif |
| 15 | + |
| 16 | +#define BIGFILE_STREAM_EXTENSION ".STR" |
| 17 | + |
| 18 | +ClassManager_Z::ClassManager_Z() { |
| 19 | + m_UnkS32_0x16c = -1; |
| 20 | + REGISTERCOMMANDC("OpenBF", OpenBF, " [BigFileName] [StreamAgentInherit=Default StreamAgent_Z]"); |
| 21 | + REGISTERCOMMANDC("OpenBFS", OpenBFS, " [BigFileName]"); |
| 22 | + REGISTERCOMMAND("ForceBF", ForceBF); |
| 23 | + REGISTERCOMMAND("CloseBF", CloseBF); |
| 24 | + REGISTERCOMMANDC("CloneClass", CloneClass, " ClonedClassName ClassName"); |
| 25 | + m_BfPathWrite.Empty(); |
| 26 | + m_BfPathRead.Empty(); |
| 27 | + m_BfCreate = FALSE; |
| 28 | + m_BfRead = FALSE; |
| 29 | + m_BfOpened = FALSE; |
| 30 | + m_BfExtension.StrCpy(BIGFILE_EXTENSION); |
| 31 | + m_BfNameExtension.StrCpy(BIGFILE_NAME_EXTENSION); |
| 32 | + m_BfStreamExtension.StrCpy(BIGFILE_STREAM_EXTENSION); |
| 33 | + m_BfVersion.Sprintf(BIGFILE_VERSION_STRING, User_BFVersion, BIGFILE_PATCH_VERSION, BIGFILE_PLATFORM_VERSION); |
| 34 | + m_BfHeader.StrCpy(m_BfVersion); |
| 35 | + m_BfHeader.StrCat(BIGFILE_VERSION_COPYRIGHT); |
| 36 | +} |
| 37 | + |
| 38 | +void ClassManager_Z::RegisterClass(const Char* i_ClassName, const Char* i_ParentClassName, NewObjectProc i_NewObject) { |
| 39 | + Name_Z l_ClassName(i_ClassName); |
| 40 | + Name_Z l_ParentClassName(i_ParentClassName); |
| 41 | + S32 l_ClassId = m_ClassList.GetSize(); |
| 42 | + |
| 43 | + S32Hash_Z l_NameToId(l_ClassName.GetID(), l_ClassId); |
| 44 | + m_ClassNameToIndex.Insert(l_NameToId); |
| 45 | + |
| 46 | + ClassDesc_Z l_ClassDesc(l_ClassName, l_ParentClassName, i_NewObject, -1); |
| 47 | + m_ClassList.Add(l_ClassDesc); |
| 48 | +} |
| 49 | + |
| 50 | +void ClassManager_Z::RegisterClassType(const Char* i_ClassName, U8 i_AddFlag, U8 i_RemoveFlag) { |
| 51 | + Name_Z l_ClassName(i_ClassName); |
| 52 | + S32Hash_Z l_NameToId(l_ClassName.GetID()); |
| 53 | + const S32Hash_Z* l_Result = m_ClassNameToIndex.Search(l_NameToId); |
| 54 | + |
| 55 | + ASSERTLE_Z(l_Result, "", 151, "pResult"); |
| 56 | + |
| 57 | + m_ClassList[l_Result->m_Ref].m_Flag |= i_AddFlag; |
| 58 | + m_ClassList[l_Result->m_Ref].m_Flag &= ~i_RemoveFlag; |
| 59 | +} |
| 60 | + |
| 61 | +Bool ClassManager_Z::IsObjectInherit(const Name_Z& i_ClassName, const Name_Z& i_ParentClassName) { |
| 62 | + S32 l_ClassId = GetClassIndex(Name_Z(i_ClassName)); |
| 63 | + while (l_ClassId > 0) { |
| 64 | + if (m_ClassList[l_ClassId].m_ParentClassName == i_ParentClassName) { |
| 65 | + return TRUE; |
| 66 | + } |
| 67 | + l_ClassId = GetClassIndex(m_ClassList[l_ClassId].m_ParentClassName); |
| 68 | + } |
| 69 | + return FALSE; |
| 70 | +} |
| 71 | + |
| 72 | +const BaseObject_ZHdl& ClassManager_Z::NewObject(const Name_Z& i_ClassName, const Name_Z& i_Name) { |
| 73 | + S16 l_ClassId = GetClassIndex(i_ClassName); |
| 74 | + if (l_ClassId < 0) { |
| 75 | + return m_NullHandle; |
| 76 | + } |
| 77 | + return NewObject(l_ClassId, i_Name); |
| 78 | +} |
| 79 | + |
| 80 | +const BaseObject_ZHdl& ClassManager_Z::NewObject(const Name_Z& i_ClassName) { |
| 81 | + S16 l_ClassId = GetClassIndex(i_ClassName); |
| 82 | + if (l_ClassId < 0) { |
| 83 | + return m_NullHandle; |
| 84 | + } |
| 85 | + String_Z<ARRAY_CHAR_MAX> l_ObjectNameString; |
| 86 | + fsprintfID(l_ObjectNameString, l_ClassId, m_ClassList[l_ClassId].m_Id); |
| 87 | + Name_Z l_ObjectName(l_ObjectNameString); |
| 88 | + return NewObject(l_ClassId, l_ObjectName); |
| 89 | +} |
| 90 | + |
| 91 | +const BaseObject_ZHdl& ClassManager_Z::NewObject(const Char* i_ClassName) { |
| 92 | + S16 l_ClassId = GetClassIndex(i_ClassName); |
| 93 | + if (l_ClassId < 0) { |
| 94 | + return m_NullHandle; |
| 95 | + } |
| 96 | + String_Z<ARRAY_CHAR_MAX> l_ObjectNameString; |
| 97 | + fsprintfID(l_ObjectNameString, l_ClassId, m_ClassList[l_ClassId].m_Id); |
| 98 | + m_ClassList[l_ClassId].m_Id++; |
| 99 | + Name_Z l_ObjectName(l_ObjectNameString); |
| 100 | + return NewObject(l_ClassId, l_ObjectName); |
| 101 | +} |
| 102 | + |
| 103 | +const BaseObject_ZHdl& ClassManager_Z::NewObject(S16 i_ClassId, const Name_Z& i_Name) { |
| 104 | + m_ClassList[i_ClassId].m_Id++; |
| 105 | + return CreateNewHandle(m_ClassList[i_ClassId].m_NewObject(), i_Name, i_ClassId); |
| 106 | +} |
| 107 | + |
| 108 | +const BaseObject_ZHdl& ClassManager_Z::NewResource(const Name_Z& i_ClassName, const Name_Z& i_Name) { |
| 109 | + S16 l_ClassId = GetClassIndex(i_ClassName); |
| 110 | + return CreateNewHandle(m_ClassList[l_ClassId].m_NewObject(), i_Name, l_ClassId, HandleRec_Z::RSC); |
| 111 | +} |
0 commit comments