Skip to content

Commit

Permalink
Implements MiddleFrame for AnimTypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Nov 25, 2022
1 parent 0412ac9 commit a2a564e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/extensions/animtype/animtypeext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ AnimTypeClassExtension::AnimTypeClassExtension(const AnimTypeClass *this_ptr) :
EndAnims(),
EndAnimsCount(),
EndAnimsMinimum(),
EndAnimsMaximum()
EndAnimsMaximum(),
BiggestFrameWidth(0),
BiggestFrameHeight(0)
{
//if (this_ptr) EXT_DEBUG_TRACE("AnimTypeClassExtension::AnimTypeClassExtension - Name: %s (0x%08X)\n", Name(), (uintptr_t)(This()));

Expand Down Expand Up @@ -331,6 +333,40 @@ bool AnimTypeClassExtension::Read_INI(CCINIClass &ini)
ASSERT_FATAL(EndAnims.Count() == EndAnimsMinimum.Count());
ASSERT_FATAL(EndAnims.Count() == EndAnimsMaximum.Count());
}

/**
* #issue-883
*
* The "biggest" frame of a animation is frame which should hide all cosmetic
* changes to the underlaying ground (e.g. craters) that the animation causes,
* so these effects are delayed until this frame is reached. TibSun calculates
* this by scanning the entire shape file to find the largest visible frame, but
* in some cases, this might not be ideal (e.g. the shape has consistent frame
* dimensions). This new value allows the frame in which these effects are
* spawned be set.
*
* A special value of "-1" will set the biggest frame to the actual middle frame
* of the shape file. This behavior was observed in Red Alert 2.
*/
if (This()->Image != nullptr && This()->Image->Get_Frame_Count() > 0) {
ShapeFileStruct *image = const_cast<ShapeFileStruct *>(This()->Image);

int biggest = ini.Get_Int_Clamp(ini_name, "MiddleFrame", -1, image->Get_Frame_Count()-1, This()->Biggest);
ASSERT(biggest != 0);

if (biggest == -1 && image->Get_Frame_Count() >= 2) {

This()->Biggest = image->Get_Frame_Count() / 2;
BiggestFrameWidth = image->Get_Frame_Data(This()->Biggest)->FrameWidth;
BiggestFrameHeight = image->Get_Frame_Data(This()->Biggest)->FrameHeight;

} else if (biggest != This()->Biggest) {

This()->Biggest = biggest;
BiggestFrameWidth = image->Get_Frame_Data(This()->Biggest)->FrameWidth;
BiggestFrameHeight = image->Get_Frame_Data(This()->Biggest)->FrameHeight;
}
}

return true;
}
6 changes: 6 additions & 0 deletions src/extensions/animtype/animtypeext.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@ AnimTypeClassExtension final : public ObjectTypeClassExtension
TypeList<int> EndAnimsCount;
TypeList<int> EndAnimsMinimum;
TypeList<int> EndAnimsMaximum;

/**
* The width and height of the biggest frame, if set by the user.
*/
unsigned BiggestFrameWidth;
unsigned BiggestFrameHeight;
};

0 comments on commit a2a564e

Please sign in to comment.