Skip to content
Merged
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
8 changes: 7 additions & 1 deletion Core/Libraries/Source/WWVegas/WW3D2/seglinerenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ SegLineRendererClass::SegLineRendererClass(void) :
NoiseAmplitude(0.0f),
MergeAbortFactor(1.5f),
TextureTileFactor(1.0f),
LastUsedSyncTime(WW3D::Get_Logic_Time_Milliseconds()),
CurrentUVOffset(0.0f,0.0f),
UVOffsetDeltaPerMS(0.0f, 0.0f),
Bits(DEFAULT_BITS),
Expand All @@ -97,6 +98,7 @@ SegLineRendererClass::SegLineRendererClass(const SegLineRendererClass & that) :
NoiseAmplitude(0.0f),
MergeAbortFactor(1.5f),
TextureTileFactor(1.0f),
LastUsedSyncTime(that.LastUsedSyncTime),
CurrentUVOffset(0.0f,0.0f),
UVOffsetDeltaPerMS(0.0f, 0.0f),
Bits(DEFAULT_BITS),
Expand All @@ -118,6 +120,7 @@ SegLineRendererClass & SegLineRendererClass::operator = (const SegLineRendererCl
NoiseAmplitude = that.NoiseAmplitude;
MergeAbortFactor = that.MergeAbortFactor;
TextureTileFactor = that.TextureTileFactor;
LastUsedSyncTime = that.LastUsedSyncTime;
CurrentUVOffset = that.CurrentUVOffset;
UVOffsetDeltaPerMS = that.UVOffsetDeltaPerMS;
Bits = that.Bits;
Expand Down Expand Up @@ -198,6 +201,7 @@ void SegLineRendererClass::Set_Texture_Tile_Factor(float factor)

void SegLineRendererClass::Reset_Line(void)
{
LastUsedSyncTime = WW3D::Get_Logic_Time_Milliseconds();
CurrentUVOffset.Set(0.0f,0.0f);
}

Expand All @@ -224,14 +228,16 @@ void SegLineRendererClass::Render
** Handle texture UV offset animation (done once for entire line).
*/
// TheSuperHackers @tweak The render update is now decoupled from the logic step.
Vector2 uv_offset = CurrentUVOffset + UVOffsetDeltaPerMS * WW3D::Get_Logic_Frame_Time_Milliseconds();
const unsigned int delta = WW3D::Get_Logic_Time_Milliseconds() - LastUsedSyncTime;
Vector2 uv_offset = CurrentUVOffset + UVOffsetDeltaPerMS * (float)delta;

// ensure offsets are in [0, 1] range:
uv_offset.X = uv_offset.X - floorf(uv_offset.X);
uv_offset.Y = uv_offset.Y - floorf(uv_offset.Y);

// Update state
CurrentUVOffset = uv_offset;
LastUsedSyncTime = WW3D::Get_Logic_Time_Milliseconds();

// Used later
TextureMapMode map_mode = Get_Texture_Mapping_Mode();
Expand Down
19 changes: 13 additions & 6 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/animobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Animatable3DObjClass::Animatable3DObjClass(const char * htree_name) :
ModeAnim.Motion=NULL;
ModeAnim.Frame=0.0f;
ModeAnim.PrevFrame=0.0f;
ModeAnim.LastSyncTime=WW3D::Get_Logic_Time_Milliseconds();
ModeAnim.frameRateMultiplier=1.0; // 020607 srj -- added
ModeAnim.animDirection=1.0; // 020607 srj -- added
ModeInterp.Motion0=NULL;
Expand Down Expand Up @@ -144,6 +145,7 @@ Animatable3DObjClass::Animatable3DObjClass(const Animatable3DObjClass & src) :
ModeAnim.Motion=NULL;
ModeAnim.Frame=0.0f;
ModeAnim.PrevFrame=0.0f;
ModeAnim.LastSyncTime=WW3D::Get_Logic_Time_Milliseconds();
ModeAnim.frameRateMultiplier=1.0; // 020607 srj -- added
ModeAnim.animDirection=1.0; // 020607 srj -- added
ModeInterp.Motion0=NULL;
Expand Down Expand Up @@ -203,6 +205,7 @@ Animatable3DObjClass & Animatable3DObjClass::operator = (const Animatable3DObjCl
ModeAnim.Motion = NULL;
ModeAnim.Frame = 0.0f;
ModeAnim.PrevFrame = 0.0f;
ModeAnim.LastSyncTime = WW3D::Get_Logic_Time_Milliseconds();
ModeAnim.frameRateMultiplier=1.0; // 020607 srj -- added
ModeAnim.animDirection=1.0; // 020607 srj -- added
ModeInterp.Motion0 = NULL;
Expand Down Expand Up @@ -471,6 +474,7 @@ void Animatable3DObjClass::Set_Animation(HAnimClass * motion, float frame, int m
ModeAnim.Motion = motion;
ModeAnim.PrevFrame = ModeAnim.Frame;
ModeAnim.Frame = frame;
ModeAnim.LastSyncTime = WW3D::Get_Logic_Time_Milliseconds();
ModeAnim.frameRateMultiplier=1.0; // 020607 srj -- added
ModeAnim.animDirection=1.0; // 020607 srj -- added

Expand Down Expand Up @@ -939,14 +943,16 @@ float Animatable3DObjClass::Compute_Current_Frame(float *newDirection) const
{
frame = ModeAnim.Frame;

//
// Compute the current frame based on elapsed time.
//
if (ModeAnim.AnimMode != ANIM_MODE_MANUAL) {
//
// Compute the current frame based on elapsed time.
// TheSuperHackers @info Is using elapsed time because frame computation is not guaranteed to be called every render frame!
//
// TheSuperHackers @tweak The animation render update is now decoupled from the logic step.
const float frametime = WW3D::Get_Logic_Frame_Time_Seconds();
const float delta = ModeAnim.Motion->Get_Frame_Rate() * ModeAnim.frameRateMultiplier * ModeAnim.animDirection * frametime;
frame += delta;
const float syncMilliseconds = WW3D::Get_Logic_Time_Milliseconds() - ModeAnim.LastSyncTime;
const float animMilliseconds = ModeAnim.Motion->Get_Frame_Rate() * ModeAnim.frameRateMultiplier * ModeAnim.animDirection * syncMilliseconds;
const float animSeconds = animMilliseconds * 0.001f;
frame += animSeconds;

//
// Wrap the frame
Expand Down Expand Up @@ -1042,6 +1048,7 @@ void Animatable3DObjClass::Single_Anim_Progress (void)
//
ModeAnim.PrevFrame = ModeAnim.Frame;
ModeAnim.Frame = Compute_Current_Frame(&ModeAnim.animDirection);
ModeAnim.LastSyncTime = WW3D::Get_Logic_Time_Milliseconds();
}


Expand Down
1 change: 1 addition & 0 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/animobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class Animatable3DObjClass : public CompositeRenderObjClass
float Frame;
float PrevFrame;
int AnimMode;
int LastSyncTime;
float animDirection;
float frameRateMultiplier; // 020607 srj -- added
} ModeAnim;
Expand Down
18 changes: 17 additions & 1 deletion Generals/Code/Libraries/Source/WWVegas/WW3D2/ww3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,28 @@ class WW3D
** will control things like animated uv-offset mappers and render object animations.
*/
static void Sync(bool step);

// Total sync time in milliseconds. Advances in full logic time steps only.
static unsigned int Get_Sync_Time(void) { return SyncTime; }

// Current sync frame time in milliseconds. Can be zero when the logic has not stepped forward in the current render update.
static unsigned int Get_Sync_Frame_Time(void) { return SyncTime - PreviousSyncTime; }
static unsigned int Get_Fractional_Sync_Milliseconds() { return FractionalSyncMs; }

// Fractional sync frame time. Accumulates for as long as the sync frame is not stepped forward.
static unsigned int Get_Fractional_Sync_Milliseconds() { return (unsigned int)FractionalSyncMs; }

// Total logic time in milliseconds. Can include fractions of a logic step. Is rounded to integer.
static unsigned int Get_Logic_Time_Milliseconds() { return SyncTime + (unsigned int)FractionalSyncMs; }

// Logic time step in milliseconds. Can be a fraction of a logic step.
static float Get_Logic_Frame_Time_Milliseconds() { return LogicFrameTimeMs; }

// Logic time step in seconds. Can be a fraction of a logic step.
static float Get_Logic_Frame_Time_Seconds() { return LogicFrameTimeMs * 0.001f; }

// Returns the render frame count.
static unsigned int Get_Frame_Count(void) { return FrameCount; }

static unsigned int Get_Last_Frame_Poly_Count(void);
static unsigned int Get_Last_Frame_Vertex_Count(void);

Expand Down
19 changes: 13 additions & 6 deletions GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/animobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Animatable3DObjClass::Animatable3DObjClass(const char * htree_name) :
ModeAnim.Motion=NULL;
ModeAnim.Frame=0.0f;
ModeAnim.PrevFrame=0.0f;
ModeAnim.LastSyncTime=WW3D::Get_Logic_Time_Milliseconds();
ModeAnim.frameRateMultiplier=1.0; // 020607 srj -- added
ModeAnim.animDirection=1.0; // 020607 srj -- added
ModeInterp.Motion0=NULL;
Expand Down Expand Up @@ -144,6 +145,7 @@ Animatable3DObjClass::Animatable3DObjClass(const Animatable3DObjClass & src) :
ModeAnim.Motion=NULL;
ModeAnim.Frame=0.0f;
ModeAnim.PrevFrame=0.0f;
ModeAnim.LastSyncTime=WW3D::Get_Logic_Time_Milliseconds();
ModeAnim.frameRateMultiplier=1.0; // 020607 srj -- added
ModeAnim.animDirection=1.0; // 020607 srj -- added
ModeInterp.Motion0=NULL;
Expand Down Expand Up @@ -203,6 +205,7 @@ Animatable3DObjClass & Animatable3DObjClass::operator = (const Animatable3DObjCl
ModeAnim.Motion = NULL;
ModeAnim.Frame = 0.0f;
ModeAnim.PrevFrame = 0.0f;
ModeAnim.LastSyncTime = WW3D::Get_Logic_Time_Milliseconds();
ModeAnim.frameRateMultiplier=1.0; // 020607 srj -- added
ModeAnim.animDirection=1.0; // 020607 srj -- added
ModeInterp.Motion0 = NULL;
Expand Down Expand Up @@ -471,6 +474,7 @@ void Animatable3DObjClass::Set_Animation(HAnimClass * motion, float frame, int m
ModeAnim.Motion = motion;
ModeAnim.PrevFrame = ModeAnim.Frame;
ModeAnim.Frame = frame;
ModeAnim.LastSyncTime = WW3D::Get_Logic_Time_Milliseconds();
ModeAnim.frameRateMultiplier=1.0; // 020607 srj -- added
ModeAnim.animDirection=1.0; // 020607 srj -- added

Expand Down Expand Up @@ -947,14 +951,16 @@ float Animatable3DObjClass::Compute_Current_Frame(float *newDirection) const
{
frame = ModeAnim.Frame;

//
// Compute the current frame based on elapsed time.
//
if (ModeAnim.AnimMode != ANIM_MODE_MANUAL) {
//
// Compute the current frame based on elapsed time.
// TheSuperHackers @info Is using elapsed time because frame computation is not guaranteed to be called every render frame!
//
// TheSuperHackers @tweak The animation render update is now decoupled from the logic step.
const float frametime = WW3D::Get_Logic_Frame_Time_Seconds();
const float delta = ModeAnim.Motion->Get_Frame_Rate() * ModeAnim.frameRateMultiplier * ModeAnim.animDirection * frametime;
frame += delta;
const float syncMilliseconds = WW3D::Get_Logic_Time_Milliseconds() - ModeAnim.LastSyncTime;
const float animMilliseconds = ModeAnim.Motion->Get_Frame_Rate() * ModeAnim.frameRateMultiplier * ModeAnim.animDirection * syncMilliseconds;
const float animSeconds = animMilliseconds * 0.001f;
frame += animSeconds;

//
// Wrap the frame
Expand Down Expand Up @@ -1050,6 +1056,7 @@ void Animatable3DObjClass::Single_Anim_Progress (void)
//
ModeAnim.PrevFrame = ModeAnim.Frame;
ModeAnim.Frame = Compute_Current_Frame(&ModeAnim.animDirection);
ModeAnim.LastSyncTime = WW3D::Get_Logic_Time_Milliseconds();
}


Expand Down
1 change: 1 addition & 0 deletions GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/animobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class Animatable3DObjClass : public CompositeRenderObjClass
float Frame;
float PrevFrame;
int AnimMode;
int LastSyncTime;
float animDirection;
float frameRateMultiplier; // 020607 srj -- added
} ModeAnim;
Expand Down
18 changes: 17 additions & 1 deletion GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ww3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,28 @@ class WW3D
** will control things like animated uv-offset mappers and render object animations.
*/
static void Sync(bool step);

// Total sync time in milliseconds. Advances in full logic time steps only.
static unsigned int Get_Sync_Time(void) { return SyncTime; }

// Current sync frame time in milliseconds. Can be zero when the logic has not stepped forward in the current render update.
static unsigned int Get_Sync_Frame_Time(void) { return SyncTime - PreviousSyncTime; }
static unsigned int Get_Fractional_Sync_Milliseconds() { return FractionalSyncMs; }

// Fractional sync frame time. Accumulates for as long as the sync frame is not stepped forward.
static unsigned int Get_Fractional_Sync_Milliseconds() { return (unsigned int)FractionalSyncMs; }

// Total logic time in milliseconds. Can include fractions of a logic step. Is rounded to integer.
static unsigned int Get_Logic_Time_Milliseconds() { return SyncTime + (unsigned int)FractionalSyncMs; }

// Logic time step in milliseconds. Can be a fraction of a logic step.
static float Get_Logic_Frame_Time_Milliseconds() { return LogicFrameTimeMs; }

// Logic time step in seconds. Can be a fraction of a logic step.
static float Get_Logic_Frame_Time_Seconds() { return LogicFrameTimeMs * 0.001f; }

// Returns the render frame count.
static unsigned int Get_Frame_Count(void) { return FrameCount; }

static unsigned int Get_Last_Frame_Poly_Count(void);
static unsigned int Get_Last_Frame_Vertex_Count(void);

Expand Down
Loading