From 5068af21cdc867389707b678e5c67dc3dfa099cc Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 31 Dec 2022 17:25:54 -0600 Subject: [PATCH] feat(prop): add prop functions --- common/Prop.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ common/Prop.hpp | 18 ++++++++++++++++++ common/prop/Types.hpp | 12 ++++++++++++ test/Prop.cpp | 9 +++++++++ 4 files changed, 81 insertions(+) create mode 100644 common/Prop.cpp create mode 100644 common/Prop.hpp create mode 100644 common/prop/Types.hpp create mode 100644 test/Prop.cpp diff --git a/common/Prop.cpp b/common/Prop.cpp new file mode 100644 index 0000000..99fe2d8 --- /dev/null +++ b/common/Prop.cpp @@ -0,0 +1,42 @@ +#include "common/Prop.hpp" +#include "common/Thread.hpp" +#include + +namespace Prop { +uint32_t s_tlsIndex; +} + +HPROPCONTEXT PropCreateContext() { + return SMemAlloc(sizeof(void*) * PROPERTIES, __FILE__, __LINE__, 0x8); +} + +void* PropGet(PROPERTY id) { + auto properties = static_cast(OsTlsGetValue(Prop::s_tlsIndex)); + + if (properties) { + return properties[id]; + } else { + return nullptr; + } +} + +HPROPCONTEXT PropGetSelectedContext() { + return OsTlsGetValue(Prop::s_tlsIndex); +} + +void PropInitialize() { + Prop::s_tlsIndex = OsTlsAlloc(); + OsTlsSetValue(Prop::s_tlsIndex, nullptr); +} + +void PropSelectContext(HPROPCONTEXT context) { + OsTlsSetValue(Prop::s_tlsIndex, context); +} + +void PropSet(PROPERTY id, void* value) { + auto properties = static_cast(OsTlsGetValue(Prop::s_tlsIndex)); + + if (properties) { + properties[id] = value; + } +} diff --git a/common/Prop.hpp b/common/Prop.hpp new file mode 100644 index 0000000..8c3d367 --- /dev/null +++ b/common/Prop.hpp @@ -0,0 +1,18 @@ +#ifndef COMMON_PROP_HPP +#define COMMON_PROP_HPP + +#include "common/prop/Types.hpp" + +HPROPCONTEXT PropCreateContext(); + +void* PropGet(PROPERTY id); + +HPROPCONTEXT PropGetSelectedContext(); + +void PropInitialize(); + +void PropSelectContext(HPROPCONTEXT context); + +void PropSet(PROPERTY id, void* value); + +#endif diff --git a/common/prop/Types.hpp b/common/prop/Types.hpp new file mode 100644 index 0000000..baedff2 --- /dev/null +++ b/common/prop/Types.hpp @@ -0,0 +1,12 @@ +#ifndef COMMON_PROP_TYPES_HPP +#define COMMON_PROP_TYPES_HPP + +enum PROPERTY { + PROP_EVENTCONTEXT = 0, + // TODO + PROPERTIES, +}; + +typedef void* HPROPCONTEXT; + +#endif diff --git a/test/Prop.cpp b/test/Prop.cpp new file mode 100644 index 0000000..67be300 --- /dev/null +++ b/test/Prop.cpp @@ -0,0 +1,9 @@ +#include "common/Prop.hpp" +#include "test/Test.hpp" + +TEST_CASE("PropInitialize", "[prop]") { + SECTION("initializes prop") { + PropInitialize(); + SUCCEED(); + } +}