Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit c877f73

Browse files
committed
Split part of MessageManager into non-static NotificationManager
+ Fixed movie recording/playback (for .mmo files)
1 parent 04310ed commit c877f73

36 files changed

+727
-590
lines changed

Core/AutomaticRomTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "PPU.h"
77
#include "VideoDecoder.h"
88
#include "StandardController.h"
9+
#include "NotificationManager.h"
910

1011
AutomaticRomTest::AutomaticRomTest()
1112
{
@@ -104,6 +105,7 @@ int32_t AutomaticRomTest::Run(string filename)
104105
{
105106
EmulationSettings::SetMasterVolume(0);
106107
_console.reset(new Console());
108+
_console->GetNotificationManager()->RegisterNotificationListener(shared_from_this());
107109
if(_console->Initialize(filename)) {
108110
_console->GetControlManager()->RegisterInputProvider(this);
109111

Core/AutomaticRomTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Console;
88

9-
class AutomaticRomTest : public INotificationListener, public IInputProvider
9+
class AutomaticRomTest : public INotificationListener, public IInputProvider, public std::enable_shared_from_this<AutomaticRomTest>
1010
{
1111
private:
1212
shared_ptr<Console> _console;

Core/CheatManager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "CheatManager.h"
44
#include "Console.h"
55
#include "MessageManager.h"
6+
#include "NotificationManager.h"
67

78
CheatManager::CheatManager(shared_ptr<Console> console)
89
{
@@ -97,7 +98,7 @@ void CheatManager::AddCode(CodeInfo &code)
9798
} else {
9899
_absoluteCheatCodes.push_back(code);
99100
}
100-
MessageManager::SendNotification(ConsoleNotificationType::CheatAdded);
101+
_console->GetNotificationManager()->SendNotification(ConsoleNotificationType::CheatAdded);
101102
}
102103

103104
void CheatManager::AddGameGenieCode(string code)
@@ -138,7 +139,7 @@ void CheatManager::ClearCodes()
138139
_absoluteCheatCodes.clear();
139140

140141
if(cheatRemoved) {
141-
MessageManager::SendNotification(ConsoleNotificationType::CheatRemoved);
142+
_console->GetNotificationManager()->SendNotification(ConsoleNotificationType::CheatRemoved);
142143
}
143144
}
144145

Core/Console.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "VideoDecoder.h"
4444
#include "VideoRenderer.h"
4545
#include "DebugHud.h"
46+
#include "NotificationManager.h"
4647

4748
Console::Console()
4849
{
@@ -57,6 +58,7 @@ Console::~Console()
5758

5859
void Console::Init()
5960
{
61+
_notificationManager.reset(new NotificationManager());
6062
_saveStateManager.reset(new SaveStateManager(shared_from_this()));
6163
_videoRenderer.reset(new VideoRenderer(shared_from_this()));
6264
_videoDecoder.reset(new VideoDecoder(shared_from_this()));
@@ -235,7 +237,7 @@ bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile)
235237
}
236238

237239
//Send notification only if a game was already running and we successfully loaded the new one
238-
MessageManager::SendNotification(ConsoleNotificationType::GameStopped, (void*)1);
240+
_notificationManager->SendNotification(ConsoleNotificationType::GameStopped, (void*)1);
239241
}
240242

241243
if(isDifferentGame) {
@@ -321,7 +323,7 @@ bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile)
321323
ResetComponents(false);
322324

323325
_rewindManager.reset(new RewindManager(shared_from_this()));
324-
MessageManager::RegisterNotificationListener(_rewindManager);
326+
_notificationManager->RegisterNotificationListener(_rewindManager);
325327

326328
_videoDecoder->StartThread();
327329

@@ -377,6 +379,11 @@ shared_ptr<SoundMixer> Console::GetSoundMixer()
377379
return _soundMixer;
378380
}
379381

382+
shared_ptr<NotificationManager> Console::GetNotificationManager()
383+
{
384+
return _notificationManager;
385+
}
386+
380387
BaseMapper* Console::GetMapper()
381388
{
382389
return _mapper.get();
@@ -473,7 +480,8 @@ void Console::ResetComponents(bool softReset)
473480

474481
KeyManager::UpdateDevices();
475482

476-
MessageManager::SendNotification(softReset ? ConsoleNotificationType::GameReset : ConsoleNotificationType::GameLoaded);
483+
//This notification MUST be sent before the UpdateInputState() below to allow MovieRecorder to grab the first frame's worth of inputs
484+
_notificationManager->SendNotification(softReset ? ConsoleNotificationType::GameReset : ConsoleNotificationType::GameLoaded);
477485

478486
if(softReset) {
479487
shared_ptr<Debugger> debugger = _debugger;
@@ -603,7 +611,7 @@ void Console::Run()
603611

604612
bool paused = EmulationSettings::IsPaused();
605613
if(paused && !_stop) {
606-
MessageManager::SendNotification(ConsoleNotificationType::GamePaused);
614+
_notificationManager->SendNotification(ConsoleNotificationType::GamePaused);
607615

608616
//Prevent audio from looping endlessly while game is paused
609617
_soundMixer->StopAudio();
@@ -625,7 +633,7 @@ void Console::Run()
625633

626634
PlatformUtilities::DisableScreensaver();
627635
_runLock.Acquire();
628-
MessageManager::SendNotification(ConsoleNotificationType::GameResumed);
636+
_notificationManager->SendNotification(ConsoleNotificationType::GameResumed);
629637
lastFrameTimer.Reset();
630638
}
631639

@@ -668,7 +676,7 @@ void Console::Run()
668676

669677
_running = false;
670678

671-
MessageManager::SendNotification(ConsoleNotificationType::BeforeEmulationStop);
679+
_notificationManager->SendNotification(ConsoleNotificationType::BeforeEmulationStop);
672680

673681
if(!crashed) {
674682
_saveStateManager->SaveRecentGame(GetMapperInfo().RomName, _romFilepath, _patchFilename);
@@ -703,8 +711,8 @@ void Console::Run()
703711

704712
_emulationThreadId = std::thread::id();
705713

706-
MessageManager::SendNotification(ConsoleNotificationType::GameStopped);
707-
MessageManager::SendNotification(ConsoleNotificationType::EmulationStopped);
714+
_notificationManager->SendNotification(ConsoleNotificationType::GameStopped);
715+
_notificationManager->SendNotification(ConsoleNotificationType::EmulationStopped);
708716
}
709717

710718
bool Console::IsRunning()
@@ -747,7 +755,7 @@ void Console::UpdateNesModel(bool sendNotification)
747755
_apu->SetNesModel(model);
748756

749757
if(configChanged && sendNotification) {
750-
MessageManager::SendNotification(ConsoleNotificationType::ConfigChanged);
758+
_notificationManager->SendNotification(ConsoleNotificationType::ConfigChanged);
751759
}
752760
}
753761

@@ -813,7 +821,7 @@ void Console::LoadState(istream &loadStream, uint32_t stateVersion)
813821
debugger->ResetCounters();
814822
}
815823

816-
MessageManager::SendNotification(ConsoleNotificationType::StateLoaded);
824+
_notificationManager->SendNotification(ConsoleNotificationType::StateLoaded);
817825
}
818826
}
819827

Core/Console.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class VideoDecoder;
2525
class VideoRenderer;
2626
class DebugHud;
2727
class SoundMixer;
28+
class NotificationManager;
2829

2930
struct HdPackData;
3031
enum class NesModel;
@@ -59,6 +60,7 @@ class Console : public std::enable_shared_from_this<Console>
5960
shared_ptr<CheatManager> _cheatManager;
6061
shared_ptr<DebugHud> _debugHud;
6162
shared_ptr<SoundMixer> _soundMixer;
63+
shared_ptr<NotificationManager> _notificationManager;
6264

6365
shared_ptr<HdPackBuilder> _hdPackBuilder;
6466
shared_ptr<HdPackData> _hdData;
@@ -96,6 +98,7 @@ class Console : public std::enable_shared_from_this<Console>
9698
shared_ptr<VideoRenderer> GetVideoRenderer();
9799
shared_ptr<DebugHud> GetDebugHud();
98100
shared_ptr<SoundMixer> GetSoundMixer();
101+
shared_ptr<NotificationManager> GetNotificationManager();
99102

100103
void ProcessCpuClock();
101104
CPU* GetCpu();

Core/Core.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@
546546
<ClInclude Include="MMC3_224.h" />
547547
<ClInclude Include="MovieRecorder.h" />
548548
<ClInclude Include="AsciiTurboFile.h" />
549+
<ClInclude Include="NotificationManager.h" />
549550
<ClInclude Include="OpenBusHandler.h" />
550551
<ClInclude Include="RawVideoFilter.h" />
551552
<ClInclude Include="Sachen9602.h" />
@@ -959,15 +960,20 @@
959960
<ClCompile Include="DebugHud.cpp" />
960961
<ClCompile Include="DrawRectangleCommand.h" />
961962
<ClCompile Include="FceuxMovie.cpp" />
963+
<ClCompile Include="FdsLoader.cpp" />
962964
<ClCompile Include="HdAudioDevice.cpp" />
963965
<ClCompile Include="HdNesPack.cpp" />
964966
<ClCompile Include="HdPackBuilder.cpp" />
965967
<ClCompile Include="HdPackLoader.cpp" />
968+
<ClCompile Include="HdPpu.cpp" />
966969
<ClCompile Include="KeyManager.cpp" />
967970
<ClCompile Include="LuaApi.cpp" />
968971
<ClCompile Include="LuaCallHelper.cpp" />
969972
<ClCompile Include="LuaScriptingContext.cpp" />
970973
<ClCompile Include="MovieRecorder.cpp" />
974+
<ClCompile Include="NotificationManager.cpp" />
975+
<ClCompile Include="NsfLoader.cpp" />
976+
<ClCompile Include="NsfPpu.cpp" />
971977
<ClCompile Include="OggMixer.cpp" />
972978
<ClCompile Include="OggReader.cpp" />
973979
<ClCompile Include="RawVideoFilter.cpp" />

Core/Core.vcxproj.filters

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,9 @@
14531453
<ClInclude Include="Bmc60311C.h">
14541454
<Filter>Nes\Mappers\Unif</Filter>
14551455
</ClInclude>
1456+
<ClInclude Include="NotificationManager.h">
1457+
<Filter>Misc</Filter>
1458+
</ClInclude>
14561459
</ItemGroup>
14571460
<ItemGroup>
14581461
<ClCompile Include="stdafx.cpp">
@@ -1722,5 +1725,20 @@
17221725
<ClCompile Include="BaseExpansionAudio.cpp">
17231726
<Filter>Misc</Filter>
17241727
</ClCompile>
1728+
<ClCompile Include="NotificationManager.cpp">
1729+
<Filter>Misc</Filter>
1730+
</ClCompile>
1731+
<ClCompile Include="NsfPpu.cpp">
1732+
<Filter>Nes</Filter>
1733+
</ClCompile>
1734+
<ClCompile Include="HdPpu.cpp">
1735+
<Filter>HdPacks</Filter>
1736+
</ClCompile>
1737+
<ClCompile Include="NsfLoader.cpp">
1738+
<Filter>Nes\RomLoader</Filter>
1739+
</ClCompile>
1740+
<ClCompile Include="FdsLoader.cpp">
1741+
<Filter>Nes\RomLoader</Filter>
1742+
</ClCompile>
17251743
</ItemGroup>
17261744
</Project>

Core/Debugger.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "TraceLogger.h"
2828
#include "Breakpoint.h"
2929
#include "CodeDataLogger.h"
30+
#include "NotificationManager.h"
3031

3132
#ifndef UINT32_MAX
3233
#define UINT32_MAX ((uint32_t)-1)
@@ -445,7 +446,7 @@ void Debugger::ProcessPpuCycle()
445446
int32_t currentCycle = (_ppu->GetCurrentCycle() << 9) + _ppu->GetCurrentScanline();
446447
for(auto updateCycle : _ppuViewerUpdateCycle) {
447448
if(updateCycle.second == currentCycle) {
448-
MessageManager::SendNotification(ConsoleNotificationType::PpuViewerDisplayFrame, (void*)(uint64_t)updateCycle.first);
449+
_console->GetNotificationManager()->SendNotification(ConsoleNotificationType::PpuViewerDisplayFrame, (void*)(uint64_t)updateCycle.first);
449450
}
450451
}
451452

@@ -691,7 +692,7 @@ bool Debugger::SleepUntilResume(BreakSource source)
691692

692693
if(_preventResume == 0) {
693694
_console->GetSoundMixer()->StopAudio();
694-
MessageManager::SendNotification(ConsoleNotificationType::CodeBreak, (void*)(uint64_t)source);
695+
_console->GetNotificationManager()->SendNotification(ConsoleNotificationType::CodeBreak, (void*)(uint64_t)source);
695696
ProcessEvent(EventType::CodeBreak);
696697
_stepOverAddr = -1;
697698
if(CheckFlag(DebuggerFlags::PpuPartialDraw)) {
@@ -1340,7 +1341,7 @@ void Debugger::ProcessEvent(EventType type)
13401341
_memoryDumper->GatherChrPaletteInfo();
13411342
} else if(type == EventType::StartFrame) {
13421343
//Update the event viewer
1343-
MessageManager::SendNotification(ConsoleNotificationType::EventViewerDisplayFrame);
1344+
_console->GetNotificationManager()->SendNotification(ConsoleNotificationType::EventViewerDisplayFrame);
13441345

13451346
//Clear the current frame/event log
13461347
if(CheckFlag(DebuggerFlags::PpuPartialDraw)) {

Core/EmulationSettings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,8 @@ class EmulationSettings
10391039

10401040
UpdateEffectiveOverclockRate();
10411041

1042-
MessageManager::SendNotification(ConsoleNotificationType::ConfigChanged);
1042+
//TODOCONSOLE
1043+
//MessageManager::SendNotification(ConsoleNotificationType::ConfigChanged);
10431044

10441045
MessageManager::DisplayMessage("ClockRate", std::to_string((uint32_t)EmulationSettings::GetOverclockRate()) + "%");
10451046
}

0 commit comments

Comments
 (0)