Skip to content

Commit

Permalink
Fix previous value tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilliamson committed May 29, 2022
1 parent 42181ef commit f2ad0d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/Remotery.c
Original file line number Diff line number Diff line change
Expand Up @@ -9949,28 +9949,30 @@ static void PropertyFrameReset(Remotery* rmt, rmtProperty* first_property)
break;

case RMT_PropertyType_rmtBool:
changed = property->prevValue.Bool != property->value.Bool;
changed = property->lastFrameValue.Bool != property->value.Bool;
break;

case RMT_PropertyType_rmtS32:
case RMT_PropertyType_rmtU32:
case RMT_PropertyType_rmtF32:
changed = property->prevValue.U32 != property->value.U32;
changed = property->lastFrameValue.U32 != property->value.U32;
break;

case RMT_PropertyType_rmtS64:
case RMT_PropertyType_rmtU64:
case RMT_PropertyType_rmtF64:
changed = property->prevValue.U64 != property->value.U64;
changed = property->lastFrameValue.U64 != property->value.U64;
break;
}

if (changed)
{
property->prevValue = property->value;
property->prevValue = property->lastFrameValue;
property->prevValueFrame = rmt->propertyFrame;
}

property->lastFrameValue = property->value;

if ((property->flags & RMT_PropertyFlags_FrameReset) != 0)
{
property->value = property->defaultValue;
Expand Down
5 changes: 4 additions & 1 deletion lib/Remotery.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ typedef struct rmtProperty

// Current value
rmtPropertyValue value;

// Last frame value to see if previous value needs to be updated
rmtPropertyValue lastFrameValue;

// Previous value only if it's different from the current value, and when it changed
rmtPropertyValue prevValue;
Expand Down Expand Up @@ -738,7 +741,7 @@ typedef struct rmtProperty

// Used to define properties from typed macro callers
#define _rmt_PropertyDefine(type, name, default_value, flags, desc, ...) \
rmtProperty name = { RMT_FALSE, RMT_PropertyType_##type, flags, default_value, default_value, 0, #name, desc, default_value, __VA_ARGS__ };
rmtProperty name = { RMT_FALSE, RMT_PropertyType_##type, flags, default_value, default_value, default_value, 0, #name, desc, default_value, __VA_ARGS__ };

// C++ doesn't support designated initialisers until C++20
// Worth checking for C++ designated initialisers to remove the function call in debug builds
Expand Down

0 comments on commit f2ad0d8

Please sign in to comment.