diff --git a/OpenJPOG/Source/main.cpp b/OpenJPOG/Source/main.cpp index 2ca0825..3dcec4f 100644 --- a/OpenJPOG/Source/main.cpp +++ b/OpenJPOG/Source/main.cpp @@ -1,5 +1,22 @@ +#include "TApplication/TApplication.h" +#include "TMemory.h" + +class AApplication : public Toshi::TApplication +{ + virtual TBOOL OnCreate(TINT argc, TPCHAR* const argv) override + { + return TTRUE; + } +}; + +static AApplication g_oTheApp; int main(int argc, char** argv) { - return 1; + if (g_oTheApp.Create("Jurassic Park: Operation Genesis - (c) Blue Tongue Software", argc, argv)) { + Toshi::TMemory::DebugPrintHALMemInfo(TNULL); + g_oTheApp.Execute(); + } + g_oTheApp.Destroy(); + return 0; } \ No newline at end of file diff --git a/Tools/UnitTests/Source/TKernel/TUser_Tests.cpp b/Tools/UnitTests/Source/TKernel/TUser_Tests.cpp new file mode 100644 index 0000000..6e93dfa --- /dev/null +++ b/Tools/UnitTests/Source/TKernel/TUser_Tests.cpp @@ -0,0 +1,12 @@ +#include "TKernel/TUser.h" +#include + +TOSHI_NAMESPACE_USING + +TEST_CASE("Register User", "[TUser]") +{ + TUser user("AdventureT"); + TSHORT iUserID = user.Register(); + REQUIRE(iUserID != -1); + REQUIRE(user.IsRegistered()); +} \ No newline at end of file diff --git a/Toshi/Include/TKernel/TFreeList.h b/Toshi/Include/TKernel/TFreeList.h new file mode 100644 index 0000000..78e76e6 --- /dev/null +++ b/Toshi/Include/TKernel/TFreeList.h @@ -0,0 +1,31 @@ +#pragma once + +#include "TMemory.h" + +TOSHI_NAMESPACE_BEGIN + +class TOSHI_EXPORT TFreeList +{ +public: + + struct Node + { + Node* pNext = TNULL; + }; + + TFreeList(); + + TINT GetCapacity() const { return m_iCapacity; } + TINT GetGrowSize() const { return m_iGrowSize; } + TINT GetFreeCount() { return m_iFreeCount; } +private: + TFreeList* m_pPrevList; + TINT m_iFreeCount; // 0x0 + TUINT m_uiItemSize; + Node m_LastNode; + TINT m_iCapacity; // 0xC + Node m_RootNode; + TINT m_iGrowSize; // 0x1C +}; + +TOSHI_NAMESPACE_END \ No newline at end of file diff --git a/Toshi/Include/TKernel/TSystemTools.h b/Toshi/Include/TKernel/TSystemTools.h index 92bd629..c18203b 100644 --- a/Toshi/Include/TKernel/TSystemTools.h +++ b/Toshi/Include/TKernel/TSystemTools.h @@ -11,6 +11,7 @@ class TOSHI_EXPORT TSystem static TINT __stdcall StringCompareNoCase(TPCCHAR a_String1, TPCCHAR a_String2, TINT a_uiSize); static TCHAR const* __stdcall StringCopy(TPCHAR a_DestinationString, TCHAR const* a_SourceString, TINT a_iCount); static TPVOID __stdcall MemCopy(TPVOID a_dest, TPCVOID a_src, TUINT a_iSize); + static TPVOID __stdcall MemSet(TPVOID a_dest, TINT a_iValue, TINT m_iSize); static TPBYTE GetScratchMem() { return ms_aScratchMem; } private: diff --git a/Toshi/Include/TKernel/TUser.h b/Toshi/Include/TKernel/TUser.h new file mode 100644 index 0000000..4eb9be6 --- /dev/null +++ b/Toshi/Include/TKernel/TUser.h @@ -0,0 +1,50 @@ +#pragma once + +#include "TDebug.h" + +#define MAX_USERS 50 + +TOSHI_NAMESPACE_BEGIN + +class TOSHI_EXPORT TUser +{ + friend class TUserHandler; +public: + TUser(TCHAR const* a_sName); + + TBOOL IsRegistered() { return m_iUserID != -1; } + TSHORT Register(); + void Deregister(); + + TSHORT GetUserID() { return m_iUserID; } + TSHORT GetNameLength() { return m_iNameLen; } + TCHAR const* GetName() { return m_sName; } + +private: + TCHAR const* m_sName; // 0x0 + TSHORT m_iNameLen; // 0x4 + TSHORT m_iUserID; // 0x6 +}; + +class TOSHI_EXPORT TUserHandler +{ +protected: + TUserHandler(); + ~TUserHandler() = default; +public: + TSHORT RegisterUser(TUser &a_rUser); + void DeregisterUser(TUser &a_rUser); + TUser* FindUser(TCHAR const* a_sName); + + TINT GetUserCount() { return m_iUserCount; } + TUser* GetUser(TINT a_iUserID) { return m_pUsers[a_iUserID]; } + static TUserHandler& __stdcall GetSingleton(); + +private: + static TUserHandler ms_oSingleton; + + TINT m_iUserCount; // 0x0 + TUser* m_pUsers[MAX_USERS]; // 0x4 +}; + +TOSHI_NAMESPACE_END \ No newline at end of file diff --git a/Toshi/Source/TKernel/TFreeList.cpp b/Toshi/Source/TKernel/TFreeList.cpp new file mode 100644 index 0000000..da17fae --- /dev/null +++ b/Toshi/Source/TKernel/TFreeList.cpp @@ -0,0 +1,8 @@ +#include "TFreeList.h" + +TOSHI_NAMESPACE_USING + +TFreeList::TFreeList() +{ + TASSERT(m_iGrowSize >= 0); +} diff --git a/Toshi/Source/TKernel/TSystemTools.cpp b/Toshi/Source/TKernel/TSystemTools.cpp index 7dd81e9..3886360 100644 --- a/Toshi/Source/TKernel/TSystemTools.cpp +++ b/Toshi/Source/TKernel/TSystemTools.cpp @@ -40,3 +40,11 @@ TPVOID __stdcall TSystem::MemCopy(TPVOID a_dest, TPCVOID a_src, TUINT a_iSize) *d++ = *s++; return a_dest; } + +TPVOID __stdcall TSystem::MemSet(TPVOID a_dest, TINT a_iValue, TINT m_iSize) +{ + TPCHAR dest = (TPCHAR)a_dest; + while (m_iSize--) + *dest++ = (TCHAR)a_iValue; + return a_dest; +} diff --git a/Toshi/Source/TKernel/TUser.cpp b/Toshi/Source/TKernel/TUser.cpp new file mode 100644 index 0000000..7f068d2 --- /dev/null +++ b/Toshi/Source/TKernel/TUser.cpp @@ -0,0 +1,70 @@ +#include "TUser.h" +#include "TSystemTools.h" + +TOSHI_NAMESPACE_USING + +TUserHandler TUserHandler::ms_oSingleton = TUserHandler(); + +TUser::TUser(TCHAR const* a_sName) +{ + m_sName = a_sName; + m_iUserID = -1; + TVALIDADDRESS(m_sName); + m_iNameLen = TSystem::StringLength(m_sName); +} + +TUserHandler::TUserHandler() +{ + m_iUserCount = 0; + TSystem::MemSet(m_pUsers, 0, sizeof(m_pUsers)); +} + +TSHORT TUserHandler::RegisterUser(TUser& a_rUser) +{ + TASSERT(TFALSE==a_rUser.IsRegistered()); + TINT curUserCount = GetUserCount(); + if (curUserCount < MAX_USERS) { + m_iUserCount++; + a_rUser.m_iUserID = curUserCount; + m_pUsers[curUserCount] = &a_rUser; + return a_rUser.GetUserID(); + } + a_rUser.m_iUserID = -1; + return -1; +} + +void TUserHandler::DeregisterUser(TUser& a_rUser) +{ + if (a_rUser.GetUserID() != -1) { + m_pUsers[a_rUser.GetUserID()] = TNULL; + } + a_rUser.m_iUserID = -1; +} + +TUser* TUserHandler::FindUser(TCHAR const* a_sName) +{ + TINT iNameLength = TSystem::StringLength(a_sName); + for (TINT i = 0; i < MAX_USERS; i++) { + if (m_pUsers[i] && + m_pUsers[i]->GetNameLength() == iNameLength && + TSystem::StringCompareNoCase(m_pUsers[i]->GetName(), a_sName, -1) == 0) { + return m_pUsers[i]; + } + } + return TNULL; +} + +TUserHandler& TUserHandler::GetSingleton() +{ + return ms_oSingleton; +} + +TSHORT TUser::Register() +{ + return TUserHandler::GetSingleton().RegisterUser(*this); +} + +void TUser::Deregister() +{ + TUserHandler::GetSingleton().DeregisterUser(*this); +}