Add horrible tracking template; for each structure you'll want to create a

separate tracker type by #defining __TRACKER_NAME and __TRACKER_GLOBAL_OFFSET.

eg.:

Then if you have a tracked value and a value of the same type at the given offset:

Tracker_1<int32_t> trackedInt;
int32_t trackedIntDirty = 0; // 4 bytes after

trackedIntDirty will become 1 everytime trackedInt changes.

git-svn-id: https://svn.eduke32.com/eduke32@3119 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
Plagman 2012-11-05 04:34:23 +00:00
parent 10c7206d1c
commit 548f939df5
3 changed files with 78 additions and 0 deletions

View file

@ -0,0 +1,39 @@
template<typename TrackedType>
class __TRACKER_NAME
{
TrackedType TrackedValue;
public:
TrackedType operator = (TrackedType);
TrackedType operator = (__TRACKER_NAME<TrackedType>);
TrackedType operator += (TrackedType);
TrackedType operator += (__TRACKER_NAME<TrackedType>);
operator TrackedType();
};
enum {
__TRACKER_NOOP_RIGHTHAND_EQUAL = 0,
__TRACKER_NOOP_RIGHTHAND_ZERO,
__TRACKER_NEVER,
};
#define __TRACKER_RIGHTHAND_TYPE __TRACKER_NAME<TrackedType> rightHand
#define __TRACKER_RIGHTHAND rightHand.TrackedValue
#include "tracker_operators.hpp"
#undef __TRACKER_RIGHTHAND_TYPE
#undef __TRACKER_RIGHTHAND
#define __TRACKER_RIGHTHAND_TYPE TrackedType rightHand
#define __TRACKER_RIGHTHAND rightHand
#include "tracker_operators.hpp"
#undef __TRACKER_RIGHTHAND_TYPE
#undef __TRACKER_RIGHTHAND
template<typename TrackedType>
__TRACKER_NAME<TrackedType>::operator TrackedType()
{
return this->TrackedValue;
}

View file

@ -0,0 +1,28 @@
template<typename TrackedType>
TrackedType __TRACKER_NAME<TrackedType>::operator __TRACKER_OPERATOR (__TRACKER_RIGHTHAND_TYPE)
{
bool isNoop;
switch (__TRACKER_NOOP) {
case __TRACKER_NOOP_RIGHTHAND_EQUAL:
isNoop = this->TrackedValue == __TRACKER_RIGHTHAND;
break;
case __TRACKER_NOOP_RIGHTHAND_ZERO:
isNoop = __TRACKER_RIGHTHAND == 0;
break;
default:
case __TRACKER_NEVER:
isNoop = false;
break;
}
if (!isNoop) {
// hook here
int TrackedAddress = (int)&this->TrackedValue;
TrackedAddress += __TRACKER_GLOBAL_OFFSET;
*((TrackedType*)TrackedAddress) = 1;
return (this->TrackedValue __TRACKER_OPERATOR __TRACKER_RIGHTHAND);
}
}

View file

@ -0,0 +1,11 @@
#define __TRACKER_OPERATOR =
#define __TRACKER_NOOP __TRACKER_NOOP_RIGHTHAND_EQUAL
#include "tracker_operator.hpp"
#undef __TRACKER_OPERATOR
#undef __TRACKER_NOOP
#define __TRACKER_OPERATOR +=
#define __TRACKER_NOOP __TRACKER_NOOP_RIGHTHAND_ZERO
#include "tracker_operator.hpp"
#undef __TRACKER_OPERATOR
#undef __TRACKER_NOOP