Skip to content

Commit

Permalink
Issue #78 add sound/music to TTM playing
Browse files Browse the repository at this point in the history
  • Loading branch information
xavieran committed Jul 7, 2024
1 parent 413f08c commit 7f476da
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 34 deletions.
5 changes: 5 additions & 0 deletions audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ AudioManager& AudioManager::Get()

void AudioManager::ChangeMusicTrack(MusicIndex musicI)
{
if (!mMusicStack.empty())
{
mMusicStack.pop();
}

auto* music = GetMusic(musicI);
mMusicStack.push(music);
mLogger.Debug() << "Changing track to: " << musicI
Expand Down
71 changes: 37 additions & 34 deletions bak/ttmRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,40 +93,7 @@ bool TTMRenderer::AdvanceAction()
mRenderer.GetForegroundLayer());
},
[&](const BAK::Update& sr){
if (mScreen)
{
mRenderer.RenderSprite(
*mScreen,
mPaletteSlots.at(mCurrentPaletteSlot).mPaletteData,
glm::ivec2{0, 0}, false, mRenderer.GetBackgroundLayer());
}

mRenderer.RenderTexture(
mRenderer.GetSavedImagesLayerBG(),
glm::ivec2{0},
mRenderer.GetBackgroundLayer());

mRenderer.RenderTexture(
mRenderer.GetSavedImagesLayer0(),
glm::ivec2{0},
mRenderer.GetBackgroundLayer());

mRenderer.RenderTexture(
mRenderer.GetSavedImagesLayer1(),
glm::ivec2{0},
mRenderer.GetBackgroundLayer());

mRenderer.RenderTexture(
mRenderer.GetForegroundLayer(),
glm::ivec2{0, 0},
mRenderer.GetBackgroundLayer());

auto bg = mRenderer.GetBackgroundLayer();
bg.Invert();
mRenderedFrames.AddTexture(bg);

mRenderer.GetForegroundLayer() = Graphics::Texture{320, 200};
mRenderer.GetBackgroundLayer() = Graphics::Texture{320, 200};
RenderFrame();
},
[&](const BAK::SaveImage& si){
mRenderer.SaveImage(si.pos, si.dims, mImageSaveLayer);
Expand Down Expand Up @@ -183,5 +150,41 @@ bool TTMRenderer::AdvanceAction()

return false;
}
void TTMRenderer::RenderFrame()
{
if (mScreen)
{
mRenderer.RenderSprite(
*mScreen,
mPaletteSlots.at(mCurrentPaletteSlot).mPaletteData,
glm::ivec2{0, 0}, false, mRenderer.GetBackgroundLayer());
}

mRenderer.RenderTexture(
mRenderer.GetSavedImagesLayerBG(),
glm::ivec2{0},
mRenderer.GetBackgroundLayer());

mRenderer.RenderTexture(
mRenderer.GetSavedImagesLayer0(),
glm::ivec2{0},
mRenderer.GetBackgroundLayer());

mRenderer.RenderTexture(
mRenderer.GetSavedImagesLayer1(),
glm::ivec2{0},
mRenderer.GetBackgroundLayer());

mRenderer.RenderTexture(
mRenderer.GetForegroundLayer(),
glm::ivec2{0, 0},
mRenderer.GetBackgroundLayer());

auto bg = mRenderer.GetBackgroundLayer();
bg.Invert();
mRenderedFrames.AddTexture(bg);

mRenderer.GetForegroundLayer() = Graphics::Texture{320, 200};
mRenderer.GetBackgroundLayer() = Graphics::Texture{320, 200};
}
}
2 changes: 2 additions & 0 deletions bak/ttmRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class TTMRenderer
private:
bool AdvanceAction();

void RenderFrame();

TTMRunner mRunner;

struct PaletteSlot
Expand Down
13 changes: 13 additions & 0 deletions gui/dynamicTTM.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "gui/dynamicTTM.hpp"

#include "audio/audio.hpp"

#include "bak/dialogAction.hpp"
#include "gui/backgrounds.hpp"
#include "gui/colors.hpp"
#include "gui/callbackDelay.hpp"
Expand Down Expand Up @@ -156,6 +159,16 @@ bool DynamicTTM::AdvanceAction()
[&](const BAK::Purge&){
assert(false);
},
[&](const BAK::PlaySoundS& sound){
if (sound.mSoundIndex < 255)
{
AudioA::AudioManager::Get().PlaySound(AudioA::SoundIndex{sound.mSoundIndex});
}
else
{
AudioA::AudioManager::Get().ChangeMusicTrack(AudioA::MusicIndex{sound.mSoundIndex});
}
},
[&](const BAK::GotoTag& sa){
assert(false);
},
Expand Down

0 comments on commit 7f476da

Please sign in to comment.