feat(prop): add prop functions

This commit is contained in:
fallenoak 2022-12-31 17:25:54 -06:00 committed by GitHub
parent 900aed5ee6
commit 5068af21cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 0 deletions

42
common/Prop.cpp Normal file
View file

@ -0,0 +1,42 @@
#include "common/Prop.hpp"
#include "common/Thread.hpp"
#include <storm/Memory.hpp>
namespace Prop {
uint32_t s_tlsIndex;
}
HPROPCONTEXT PropCreateContext() {
return SMemAlloc(sizeof(void*) * PROPERTIES, __FILE__, __LINE__, 0x8);
}
void* PropGet(PROPERTY id) {
auto properties = static_cast<void**>(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<void**>(OsTlsGetValue(Prop::s_tlsIndex));
if (properties) {
properties[id] = value;
}
}

18
common/Prop.hpp Normal file
View file

@ -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

12
common/prop/Types.hpp Normal file
View file

@ -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

9
test/Prop.cpp Normal file
View file

@ -0,0 +1,9 @@
#include "common/Prop.hpp"
#include "test/Test.hpp"
TEST_CASE("PropInitialize", "[prop]") {
SECTION("initializes prop") {
PropInitialize();
SUCCEED();
}
}