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
3 changes: 3 additions & 0 deletions Common/Cpp/EarlyShutdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void blocking_shutdown(
}


struct TryShutdownable{
virtual bool try_shutdown() noexcept = 0;
};


}
Expand Down
2 changes: 1 addition & 1 deletion SerialPrograms/Source/CommonFramework/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace PokemonAutomation{
#endif

#ifndef PA_VERSION_PATCH
#define PA_VERSION_PATCH 5
#define PA_VERSION_PATCH 6
#endif

const bool IS_BETA_VERSION = PA_IS_BETA;
Expand Down
5 changes: 5 additions & 0 deletions SerialPrograms/Source/CommonFramework/Panels/OptionsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
*
* From: https://github.com/PokemonAutomation/
*
* ConsolePanel is a panel with:
* - Has options.
* - Has no console.
* - Cannot be run.
*
*/

#ifndef PokemonAutomation_OptionsPanel_H
Expand Down
2 changes: 1 addition & 1 deletion SerialPrograms/Source/GameConsole/ConsolePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

#include "Common/Cpp/Json/JsonValue.h"
#include "Framework/ConsolePanelSession.h"
#include "ConsolePanel.h"
#include "ConsolePanelSession.h"

namespace PokemonAutomation{
namespace GameConsole{
Expand Down
5 changes: 4 additions & 1 deletion SerialPrograms/Source/GameConsole/ConsolePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
*
* From: https://github.com/PokemonAutomation/
*
* ConsolePanel is a panel with a console and options. It cannot be run.
* ConsolePanel is a panel with:
* - Has options.
* - Has a console.
* - Cannot be run.
*
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#define PokemonAutomation_GameConsole_ConsolePanelSession_H

#include "CommonFramework/Panels/PanelSession.h"
#include "GameConsole/ConsolePanel.h"
#include "ConsoleSystemSession.h"
#include "ConsolePanel.h"

namespace PokemonAutomation{
namespace GameConsole{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "Common/Cpp/Json/JsonArray.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "Common/Cpp/Containers/FixedLimitVector.tpp"
#include "GameConsole/ConsoleSystemOption.h"
#include "GameConsole/Framework/ConsoleSystemOption.h"

namespace PokemonAutomation{
namespace GameConsole{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
#ifndef PokemonAutomation_GameConsole_ConsoleSystemSession_H
#define PokemonAutomation_GameConsole_ConsoleSystemSession_H

#include "Common/Cpp/Logging/TaggedLogger.h"
#include "Common/Cpp/UiWrapper.h"
#include "Common/Cpp/EarlyShutdown.h"
#include "Common/Cpp/Logging/TaggedLogger.h"
#include "CommonFramework/AudioPipeline/AudioSession.h"
#include "CommonFramework/VideoPipeline/VideoSession.h"
#include "CommonFramework/VideoPipeline/VideoOverlaySession.h"
Expand All @@ -40,6 +41,7 @@ namespace GameConsole{

class ConsoleSystemSession
: public UiState<ConsoleSystemSession>
, public TryShutdownable
, public TrackableConsole
, private VideoDisplayHidListener
, private ControllerInputListener
Expand All @@ -60,8 +62,9 @@ class ConsoleSystemSession


public:
virtual bool try_shutdown() noexcept;
virtual bool try_shutdown() noexcept override;
virtual ~ConsoleSystemSession();

ConsoleSystemSession(
Logger& logger,
ConsoleSystemOption& option,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* Multi-Console Panel Session
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "Common/Cpp/EarlyShutdown.h"
#include "Common/Cpp/Logging/GlobalLogger.h"
#include "Common/Cpp/Json/JsonValue.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "CommonFramework/Logging/Logger.h"
#include "MultiConsolePanelSession.h"

namespace PokemonAutomation{
namespace GameConsole{



bool MultiConsolePanelSession::try_shutdown(){
return m_system.try_shutdown();
}
MultiConsolePanelSession::~MultiConsolePanelSession(){
blocking_shutdown(
global_logger_tagged(),
"ConsolePanelSession",
[this]{ return try_shutdown(); }
);
}
MultiConsolePanelSession::MultiConsolePanelSession(const MultiConsolePanelDescriptor& descriptor)
: UiState<MultiConsolePanelSession, PanelSession>(descriptor)
, m_descriptor(descriptor)
, m_system_option(
descriptor.min_consoles(),
descriptor.max_consoles(),
descriptor.default_consoles(),
descriptor.option_factory()
)
, m_system(m_system_option, descriptor.session_factory())
, m_instance(descriptor.make_instance(m_system))
{}

ConfigOption& MultiConsolePanelSession::options(){
return m_instance->m_options;
}


void MultiConsolePanelSession::restore_defaults(){
m_instance->restore_defaults();
}
JsonValue MultiConsolePanelSession::to_json() const{
JsonObject obj = std::move(*m_instance->to_json().to_object());
obj["ConsoleSetup"] = m_system_option.to_json();
return obj;
}
void MultiConsolePanelSession::load_json(const JsonValue& json){
const JsonObject* obj = json.to_object();
if (obj == nullptr){
return;
}
const JsonValue* value = obj->get_value("ConsoleSetup");
if (value){
m_system.load_json(*value);
}
m_instance->load_json(json);
}



}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Multi-Console Panel Session
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_GameConsole_MultiConsolePanelSession_H
#define PokemonAutomation_GameConsole_MultiConsolePanelSession_H

#include "CommonFramework/Panels/PanelSession.h"
#include "MultiConsoleSystemSession.h"
#include "GameConsole/MultiConsolePanel.h"

namespace PokemonAutomation{
namespace GameConsole{



class MultiConsolePanelSession final : public UiState<MultiConsolePanelSession, PanelSession>{
public:
bool try_shutdown();
~MultiConsolePanelSession();
MultiConsolePanelSession(const MultiConsolePanelDescriptor& descriptor);


public:
const MultiConsolePanelDescriptor& descriptor() const{ return m_descriptor; }

Logger& logger(){ return m_system.logger(); }
MultiConsoleSystemSession& system(){ return m_system; }
ConfigOption& options();


public:
// Serialization

void restore_defaults();
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;


private:
const MultiConsolePanelDescriptor& m_descriptor;

MultiConsoleSystemOption m_system_option;
MultiConsoleSystemSession m_system;

std::unique_ptr<MultiConsolePanelInstance> m_instance;
};





}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ MultiConsoleSystemOption::MultiConsoleSystemOption(
size_t min_consoles,
size_t max_consoles,
size_t consoles,
std::function<std::unique_ptr<ConsoleSystemOption>()> factory
const OptionFactory& option_factory
)
: m_min_consoles(std::max(min_consoles, (size_t)1))
, m_max_consoles(std::min(max_consoles, (size_t)MAX_CONSOLES))
, m_active_consoles(0)
, m_consoles(m_max_consoles)
{
for (size_t c = 0; c < m_max_consoles; c++){
m_consoles.emplace_back(factory());
m_consoles.emplace_back(option_factory(c));
}
consoles = std::max(consoles, m_min_consoles);
consoles = std::min(consoles, m_max_consoles);
Expand All @@ -40,9 +40,9 @@ MultiConsoleSystemOption::MultiConsoleSystemOption(
size_t min_consoles,
size_t max_consoles,
const JsonValue& json,
std::function<std::unique_ptr<ConsoleSystemOption>()> factory
const OptionFactory& option_factory
)
: MultiConsoleSystemOption(min_consoles, max_consoles, 0, std::move(factory))
: MultiConsoleSystemOption(min_consoles, max_consoles, 0, option_factory)
{
MultiConsoleSystemOption::load_json(json);
}
Expand Down Expand Up @@ -78,7 +78,6 @@ void MultiConsoleSystemOption::load_json(const JsonValue& json){
for (; c < stop; c++){
m_consoles[c]->load_json((*array)[c]);
}
m_active_consoles = c;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,29 @@ class MultiConsoleSystemOption{

public:
virtual ~MultiConsoleSystemOption();

using OptionFactory = std::function<
std::unique_ptr<ConsoleSystemOption>(
size_t console_index
)
>;

// Construct the multi-console option.
// By default it constructs the generic console. But you can inject your
// own factory for your own custom subclass.
MultiConsoleSystemOption(
size_t min_consoles,
size_t max_consoles,
size_t consoles,
std::function<std::unique_ptr<ConsoleSystemOption>()> factory = []{
const OptionFactory& option_factory = [](size_t console_index){
return std::make_unique<ConsoleSystemOption>(1);
}
);
MultiConsoleSystemOption(
size_t min_consoles,
size_t max_consoles,
const JsonValue& json,
std::function<std::unique_ptr<ConsoleSystemOption>()> factory = []{
const OptionFactory& option_factory = [](size_t console_index){
return std::make_unique<ConsoleSystemOption>(1);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void MultiConsoleSystemSession::remove_listener(Listener& listener){
m_listeners.remove(listener);
}

bool MultiConsoleSystemSession::try_shutdown(){
bool MultiConsoleSystemSession::try_shutdown() noexcept{
bool success = true;
for (std::unique_ptr<ConsoleSystemSession>& console : m_consoles){
success &= console->try_shutdown();
Expand All @@ -34,9 +34,9 @@ bool MultiConsoleSystemSession::try_shutdown(){
}
MultiConsoleSystemSession::~MultiConsoleSystemSession(){
blocking_shutdown(
global_logger_tagged(),
m_logger,
"MultiConsoleSystemSession",
[this]{ return try_shutdown(); }
[this]{ return MultiConsoleSystemSession::try_shutdown(); }
);
}

Expand All @@ -60,21 +60,18 @@ MultiConsoleSystemSession::MultiConsoleSystemSession(
{}
MultiConsoleSystemSession::MultiConsoleSystemSession(
MultiConsoleSystemOption& option,
std::function<
std::unique_ptr<ConsoleSystemSession>(
ConsoleSystemOption& option,
size_t console_index
)
> factory
SessionFactory session_factory
)
: m_option(option)
: m_logger(global_logger_tagged())
, m_option(option)
, m_consoles(option.active_consoles())
, m_factory(std::move(factory))
, m_session_factory(std::move(session_factory))
{
size_t count = option.active_consoles();
for (size_t c = 0; c < count; c++){
m_consoles.emplace_back(m_factory(option[c], c));
m_consoles.emplace_back(m_session_factory(option[c], c));
}
// cout << "MultiConsoleSystemSession(): count = " << count << endl;
}

void MultiConsoleSystemSession::lock_controllers(const std::string& reason){
Expand Down Expand Up @@ -130,7 +127,7 @@ void MultiConsoleSystemSession::set_active_consoles(size_t count){
m_consoles.reset(count);
m_option.resize(count);
for (size_t c = 0; c < count; c++){
m_consoles.emplace_back(m_factory(m_option[c], c));
m_consoles.emplace_back(m_session_factory(m_option[c], c));
}
}

Expand All @@ -144,11 +141,11 @@ JsonValue MultiConsoleSystemSession::to_json() const{
return m_option.to_json();
}
void MultiConsoleSystemSession::load_json(const JsonValue& json){
// cout << "MultiConsoleSystemSession::load_json()" << endl;
{
std::lock_guard<Mutex> lg(m_state_lock);
m_option.load_json(json);
}
// cout << "MultiConsoleSystemSession::load_json(): " << m_option.active_consoles() << endl;
set_active_consoles(m_option.active_consoles());
}

Expand Down
Loading