Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/core/StructTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
#include "ViewportRenderState.h"

MACRO_STRUCT_RESOLVER(ViewportRenderState, false, 0x100) ViewportRenderState_Struct;

// in this case, it will just instantiate the struct, calling the constructor, but only if implemented
MACRO_STRUCT_INSTANCE(ViewportRenderState, 0x100);
12 changes: 0 additions & 12 deletions src/core/ViewportRenderState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@

#include "windowslib.h"

// could also be placed in own file against the clutter
// PROBLEM: Needs definition of address twice, could however be helped if addresses are moved into own struct/file
MACRO_STRUCT_INSTANCE(ViewportRenderState, 0x100)
{
// needs direct create return to properly work
// interestingly, "ViewportRenderState" here would be so big,
// a stack overflow would occur if it was not optimized to be no copy
// works with variables
// might work good together with the copy prevention
return ViewportRenderState();
}

ViewportRenderState::ViewportRenderState() { MACRO_CALL_MEMBER(ViewportRenderState_Func::_constructor_, this)(); }

// FUNCTION: STRONGHOLDCRUSADER 0x004e1fa0
Expand Down
16 changes: 8 additions & 8 deletions src/precomp/StructResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@

struct StructResolver {
private:
template <typename T, int gameAddress> static T instance();
template <typename T, int gameAddress, typename = void> struct Instance;

template <typename T, bool implemented, int gameAddress> struct InternalResolver;
template <typename T, int gameAddress> struct InternalResolver<T, true, gameAddress> {
private:
static T instance;

public:
static T* const ptr;
};
template <typename T, int gameAddress> struct InternalResolver<T, false, gameAddress> {
Expand Down Expand Up @@ -44,9 +40,10 @@ struct StructResolver {

template <typename T, int gameAddress>
T* const StructResolver::InternalResolver<T, false, gameAddress>::ptr = reinterpret_cast<T*>(gameAddress);

template <typename T, int gameAddress>
T StructResolver::InternalResolver<T, true, gameAddress>::instance = StructResolver::instance<T, gameAddress>();
template <typename T, int gameAddress> T* const StructResolver::InternalResolver<T, true, gameAddress>::ptr = &instance;
T* const StructResolver::InternalResolver<T, true, gameAddress>::ptr
= &StructResolver::Instance<T, gameAddress>::instance;

template <int address> bool StructResolver::AddressUsageKeeper<address>::initialized = false;

Expand All @@ -65,6 +62,9 @@ StructResolver::Resolver<T, implemented, gameAddress>::Initializer::Initializer(
typedef StructResolver::Resolver<STRUCT_TYPE, IMPLEMENTED, GAME_ADDRESS>::Ptr

#define MACRO_STRUCT_INSTANCE(STRUCT_TYPE, GAME_ADDRESS) \
template <> STRUCT_TYPE StructResolver::instance<STRUCT_TYPE, GAME_ADDRESS>()
template <typename _> struct StructResolver::Instance<STRUCT_TYPE, GAME_ADDRESS, _> { \
static STRUCT_TYPE instance; \
}; \
template <typename _> STRUCT_TYPE StructResolver::Instance<STRUCT_TYPE, GAME_ADDRESS, _>::instance

#endif // STRUCT_RESOLVER