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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PanelSession::PanelSession(const PanelDescriptor& descriptor)
}
}

void PanelSession::load_json(){
void PanelSession::load_json_from_global(){
JsonValue* node = PERSISTENT_SETTINGS().panels.get_value(m_descriptor.identifier());
if (node == nullptr){
return;
Expand Down
3 changes: 1 addition & 2 deletions SerialPrograms/Source/CommonFramework/Panels/PanelSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ class PanelSession : public UiState<PanelSession>{

public:
virtual void restore_defaults(){}

void load_json();
virtual JsonValue to_json() const;
virtual void load_json(const JsonValue& json);
void load_json_from_global();


protected:
Expand Down
9 changes: 5 additions & 4 deletions SerialPrograms/Source/CommonFramework/ProgramSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ProgramSession::ProgramSession(const ProgramDescriptor& descriptor)
, m_instance_id(ProgramTracker::instance().add_program(*this))
// , m_logger(global_logger_raw(), "Program:" + std::to_string(m_instance_id))
, m_logger(global_logger_raw(), "Program")
, m_timestamp(current_time())
, m_last_state_change(current_time())
, m_state(ProgramState::STOPPED)
{
load_historical_stats();
Expand Down Expand Up @@ -71,8 +71,8 @@ std::string ProgramSession::historical_stats() const{
}
return "";
}
WallClock ProgramSession::timestamp() const{
return m_timestamp.load(std::memory_order_relaxed);
WallClock ProgramSession::last_state_change() const{
return m_last_state_change.load(std::memory_order_relaxed);
}


Expand Down Expand Up @@ -190,7 +190,7 @@ std::string ProgramSession::start_program(){

// Now start the program.
m_logger.log("Starting program...");
m_timestamp.store(current_time(), std::memory_order_relaxed);
m_last_state_change.store(current_time(), std::memory_order_relaxed);
set_state(ProgramState::RUNNING);
m_program_thread = GlobalThreadPools::unlimited_realtime().dispatch_now_blocking(
[this]{
Expand Down Expand Up @@ -254,6 +254,7 @@ std::string ProgramSession::stop_program(){
}
}
internal_stop_program();
m_last_state_change.store(current_time(), std::memory_order_relaxed);
return "";
}

Expand Down
4 changes: 2 additions & 2 deletions SerialPrograms/Source/CommonFramework/ProgramSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ProgramSession : public TrackableProgram{
virtual ProgramState current_state() const override final{ return m_state.load(std::memory_order_relaxed); }
virtual std::string current_stats() const override final;
std::string historical_stats() const;
virtual WallClock timestamp() const final;
virtual WallClock last_state_change() const final;

// Temporary for migration.
StatsTracker* current_stats_tracker(){ return m_current_stats.get(); }
Expand Down Expand Up @@ -155,7 +155,7 @@ class ProgramSession : public TrackableProgram{

mutable Mutex m_lock;

std::atomic<WallClock> m_timestamp;
std::atomic<WallClock> m_last_state_change;
std::atomic<ProgramState> m_state;

// ProgramMissingResourceTracker m_missing_resource_tracker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void ComputerProgramSession::internal_run_program(){
identifier(),
m_descriptor.category(),
m_descriptor.display_name(),
timestamp()
last_state_change()
);
CancellableHolder<CancellableScope> scope;
ProgramEnvironment env(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ class ComputerProgramSession final


public:
virtual std::string check_validity() const override;
virtual void restore_defaults() override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;


private:
virtual std::string check_validity() const override;

virtual void internal_run_program() override;
virtual void internal_stop_program() override;

Expand Down
2 changes: 1 addition & 1 deletion SerialPrograms/Source/Controllers/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AbstractController{
// Static Information

virtual const char* name() = 0;
virtual ControllerClass controller_class() const = 0;
virtual ControllerClass controller_class() const noexcept = 0;

// Performance Metrics
virtual ControllerPerformanceClass performance_class() const = 0;
Expand Down
8 changes: 4 additions & 4 deletions SerialPrograms/Source/Controllers/ControllerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ class ControllerConnection : public CancellableScope{


public:
ControllerType current_controller() const{
ControllerType current_controller() const noexcept{
return m_current_controller.load(std::memory_order_acquire);
}
bool is_ready() const{ return status() == Status::READY; }
Status status() const{ return m_status.load(std::memory_order_acquire); }
bool is_ready() const noexcept{ return status() == Status::READY; }
Status status() const noexcept{ return m_status.load(std::memory_order_acquire); }
std::string status_text() const;

// It it not safe to call this until "is_ready()" is true.
const std::vector<ControllerType>& controller_list(){
const std::vector<ControllerType>& controller_list() noexcept{
return m_controller_list;
}

Expand Down
9 changes: 8 additions & 1 deletion SerialPrograms/Source/Controllers/ControllerSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ std::shared_ptr<ControllerDescriptor> ControllerSession::descriptor() const{
ReadSpinLock lg(m_state_lock);
return m_descriptor;
}
ControllerType ControllerSession::controller_type() const{
ControllerClass ControllerSession::controller_class() const noexcept{
ReadSpinLock lg(m_state_lock);
if (!m_controller){
return ControllerClass::None;
}
return m_controller->controller_class();
}
ControllerType ControllerSession::controller_type() const noexcept{
ReadSpinLock lg(m_state_lock);
if (!m_connection){
return ControllerType::None;
Expand Down
3 changes: 2 additions & 1 deletion SerialPrograms/Source/Controllers/ControllerSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class ControllerSession final
ControllerConnection::Status connection_status() const;

std::shared_ptr<ControllerDescriptor> descriptor() const;
ControllerType controller_type() const;
ControllerClass controller_class() const noexcept;
ControllerType controller_type() const noexcept;
std::string status_text() const;

std::optional<size_t> index() const{
Expand Down
2 changes: 1 addition & 1 deletion SerialPrograms/Source/Controllers/NullController.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class NullController final : public AbstractController{
virtual const char* name() override{
return NAME;
}
virtual ControllerClass controller_class() const override{
virtual ControllerClass controller_class() const noexcept override{
return ControllerClass::None;
}
virtual ControllerPerformanceClass performance_class() const override{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PABotBase2_Keyboard final :
// virtual ControllerType controller_type() const override{
// return ControllerType::HID_Keyboard;
// }
virtual ControllerClass controller_class() const override{
virtual ControllerClass controller_class() const noexcept override{
return ControllerClass::HID_Keyboard;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ std::string ConsoleSystemSession::status() const{
return m_status_text;
}


JsonValue ConsoleSystemSession::to_json() const{
std::lock_guard<Mutex> lg(m_lock);
return m_option.to_json();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,12 @@ class ConsoleSystemSession
VideoOverlaySession& overlay(){ return m_overlay; }
const StreamHistorySession& stream_history() const{ return m_history; }

size_t controllers() const{ return m_controllers.size(); }
ControllerSession& controller(size_t index){ return m_controllers[index].session; }


public:
virtual VideoFeed& video_feed() override{ return video(); }
virtual AudioFeed& audio_feed() override{ return audio(); }
virtual ControllerSession& controller() override{ return ConsoleSystemSession::controller(0); };
virtual VideoFeed& video_feed() noexcept override{ return video(); }
virtual AudioFeed& audio_feed() noexcept override{ return audio(); }
virtual size_t controllers() const noexcept override{ return m_controllers.size(); }
virtual ControllerSession& controller(size_t index) noexcept override{ return m_controllers[index].session; }

virtual JsonValue to_json() const;
virtual void load_json(const JsonValue& json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include "Integrations/ProgramTracker.h"
#include "DiscordSocial.h"

//#include <iostream>
//using std::cout;
//using std::endl;

using namespace discordpp;
namespace PokemonAutomation{
namespace Integration{
Expand Down Expand Up @@ -86,6 +90,7 @@ void DiscordSocial::thread_loop(){
}

void DiscordSocial::update_rich_presence(){
// cout << "DiscordSocial::update_rich_presence()" << endl;
try{
std::string details = m_activity.Details().value();
std::string state = m_activity.State().value();
Expand Down Expand Up @@ -120,7 +125,11 @@ void DiscordSocial::update_rich_presence(){
details = item.second.program_name;
}

m_timestamps.SetStart(std::chrono::duration_cast<std::chrono::seconds>(item.second.start_time.time_since_epoch()).count());
m_timestamps.SetStart(
std::chrono::duration_cast<std::chrono::seconds>(
item.second.last_state_change.time_since_epoch()
).count()
);
}

m_activity.SetTimestamps(m_timestamps);
Expand Down
Loading
Loading