Skip to content

Commit

Permalink
Static sprite sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
cvet committed Feb 18, 2025
1 parent d5d643c commit 386db6b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
11 changes: 8 additions & 3 deletions Source/Client/CritterHexView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ void CritterHexView::Action(CritterAction action, int action_data, Entity* conte
#endif
{
const auto* anim = GetCurAnim();
_resetTime = _engine->GameTime.GameplayTime() + std::chrono::milliseconds {anim != nullptr && anim->AnimFrames != nullptr ? anim->AnimFrames->WholeTicks : 1000};
const auto duration = std::chrono::milliseconds {anim != nullptr && anim->AnimFrames != nullptr && anim->AnimFrames->WholeTicks != 0 ? anim->AnimFrames->WholeTicks : 1000};
_resetTime = _engine->GameTime.GameplayTime() + duration;
_needReset = true;
}
} break;
Expand Down Expand Up @@ -259,6 +260,7 @@ void CritterHexView::Animate(CritterStateAnim state_anim, CritterActionAnim acti
STACK_TRACE_ENTRY();

const auto dir = GetDir();

if (state_anim == CritterStateAnim::None) {
state_anim = GetStateAnim();
}
Expand All @@ -282,6 +284,7 @@ void CritterHexView::Animate(CritterStateAnim state_anim, CritterActionAnim acti
if (_model != nullptr) {
if (_model->ResolveAnimation(state_anim, action_anim)) {
_animSequence.push_back(CritterAnim {nullptr, time_duration {}, 0, 0, state_anim, action_anim, fixed_context_item});

if (_animSequence.size() == 1) {
NextAnim(false);
}
Expand All @@ -298,7 +301,9 @@ void CritterHexView::Animate(CritterStateAnim state_anim, CritterActionAnim acti
const auto* frames = _engine->ResMngr.GetCritterAnimFrames(GetModelName(), state_anim, action_anim, dir);

if (frames != nullptr) {
_animSequence.push_back(CritterAnim {frames, std::chrono::milliseconds {frames->WholeTicks}, 0, frames->CntFrm - 1, frames->StateAnim, frames->ActionAnim, fixed_context_item});
const auto duration = std::chrono::milliseconds {frames->WholeTicks != 0 ? frames->WholeTicks : 100};
_animSequence.push_back(CritterAnim {frames, duration, 0, frames->CntFrm - 1, frames->StateAnim, frames->ActionAnim, fixed_context_item});

if (_animSequence.size() == 1) {
NextAnim(false);
}
Expand Down Expand Up @@ -373,7 +378,7 @@ void CritterHexView::AnimateStay()
_engine->OnCritterAnimationProcess.Fire(true, this, state_anim, action_anim, nullptr);

_stayAnim.AnimFrames = frames;
_stayAnim.AnimDuration = std::chrono::milliseconds {frames->WholeTicks};
_stayAnim.AnimDuration = std::chrono::milliseconds {frames->WholeTicks != 0 ? frames->WholeTicks : 100};
_stayAnim.BeginFrm = 0;
_stayAnim.EndFrm = frames->CntFrm - 1;

Expand Down
6 changes: 5 additions & 1 deletion Source/Client/DefaultSprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ SpriteSheet::SpriteSheet(SpriteManager& spr_mngr, uint frames, uint ticks, uint
Spr.resize(frames);
SprOffset.resize(frames);
CntFrm = frames;
WholeTicks = ticks != 0 ? ticks : frames * 100;
WholeTicks = ticks;

DirCount = dirs;

Expand Down Expand Up @@ -265,6 +265,10 @@ void SpriteSheet::Play(hstring anim_name, bool looped, bool reversed)

UNUSED_VARIABLE(anim_name);

if (CntFrm == 1 || WholeTicks == 0) {
return;
}

_playing = true;
_looped = looped;
_reversed = reversed;
Expand Down
38 changes: 10 additions & 28 deletions Source/Tools/ImageBaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,9 @@ auto ImageBaker::LoadFofrm(string_view fname, string_view opt, File& file) -> Fr
// Load ini parser
ConfigFile fofrm(file.GetPath(), file.GetStr());

int frm_fps = fofrm.GetInt("", "fps", 0);

if (frm_fps <= 0) {
frm_fps = 10;
}

int frm_count = fofrm.GetInt("", "count", 0);

if (frm_count <= 0) {
frm_count = 1;
}
int frm_fps = fofrm.GetInt("", "fps", 10);
int frm_count = fofrm.GetInt("", "count", 1);
RUNTIME_ASSERT(frm_count > 0);

int ox = fofrm.GetInt("", "offs_x", 0);
int oy = fofrm.GetInt("", "offs_y", 0);
Expand Down Expand Up @@ -390,7 +382,7 @@ auto ImageBaker::LoadFofrm(string_view fname, string_view opt, File& file) -> Fr
// Allocate animation storage
if (dir == 0) {
collection.SequenceSize = static_cast<uint16>(frames);
collection.AnimTicks = static_cast<uint16>(1000 * frm_count / frm_fps);
collection.AnimTicks = static_cast<uint16>(frm_fps != 0 ? 1000 * frm_count / frm_fps : 0);
}
else {
collection.HaveDirs = true;
Expand Down Expand Up @@ -435,16 +427,13 @@ auto ImageBaker::LoadFrm(string_view fname, string_view opt, File& file) -> Fram
file.SetCurPos(0x4);
auto frm_fps = file.GetBEUShort();

if (frm_fps == 0) {
frm_fps = 10;
}

file.SetCurPos(0x8);
auto frm_count = file.GetBEUShort();
RUNTIME_ASSERT(frm_count > 0);

FrameCollection collection;
collection.SequenceSize = frm_count;
collection.AnimTicks = 1000 / frm_fps * frm_count;
collection.AnimTicks = frm_fps != 0 ? 1000 / frm_fps * frm_count : 0;

// Animate pixels
// 0x00 - None
Expand Down Expand Up @@ -696,16 +685,13 @@ auto ImageBaker::LoadFrX(string_view fname, string_view opt, File& file) -> Fram
file.SetCurPos(0x4);
auto frm_fps = file.GetBEUShort();

if (frm_fps == 0) {
frm_fps = 10;
}

file.SetCurPos(0x8);
auto frm_count = file.GetBEUShort();
RUNTIME_ASSERT(frm_count > 0);

FrameCollection collection;
collection.SequenceSize = frm_count;
collection.AnimTicks = 1000 / frm_fps * frm_count;
collection.AnimTicks = frm_fps != 0 ? 1000 / frm_fps * frm_count : 0;
collection.NewExtension = "frm";

// Animate pixels
Expand Down Expand Up @@ -1114,12 +1100,8 @@ auto ImageBaker::LoadArt(string_view fname, string_view opt, File& file) -> Fram
}

auto frm_fps = header.FrameRate;

if (frm_fps == 0) {
frm_fps = 10;
}

auto frm_count = header.FrameCount;
RUNTIME_ASSERT(frm_count > 0);

if (frm_from >= frm_count) {
frm_from = frm_count - 1;
Expand All @@ -1133,7 +1115,7 @@ auto ImageBaker::LoadArt(string_view fname, string_view opt, File& file) -> Fram
// Create animation
FrameCollection collection;
collection.SequenceSize = static_cast<uint16>(frm_count_target);
collection.AnimTicks = static_cast<uint16>(1000 / frm_fps * frm_count_target);
collection.AnimTicks = static_cast<uint16>(frm_fps != 0 ? 1000 / frm_fps * frm_count_target : 0);
collection.HaveDirs = header.RotationCount == 8;

for (const auto dir : xrange(GameSettings::MAP_DIR_COUNT)) {
Expand Down

0 comments on commit 386db6b

Please sign in to comment.