Skip to content

Commit

Permalink
[Switch] Delete power_manager singleton
Browse files Browse the repository at this point in the history
It served little to no purpose.
  • Loading branch information
halotroop2288 committed Jan 24, 2024
1 parent 1b815f9 commit 8b85723
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 136 deletions.
1 change: 0 additions & 1 deletion platform/switch/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Import("env")
files = [
"godot_switch.cpp",
"os_switch.cpp",
"power_switch.cpp",
"joypad_switch.cpp",
"context_gl_switch_egl.cpp",
]
Expand Down
38 changes: 32 additions & 6 deletions platform/switch/os_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ Error OS_Switch::initialize(const VideoMode &p_desired, int p_video_driver, int
}
joypad = memnew(JoypadSwitch(input));

power_manager = memnew(PowerSwitch);
if (R_SUCCEEDED(psmInitialize())) {
OS_Switch::psm_initialized = true;
}

AudioDriverManager::initialize(p_audio_driver);

Expand All @@ -195,8 +197,8 @@ void OS_Switch::finalize() {
memdelete(joypad);
visual_server->finish();
memdelete(visual_server);
memdelete(power_manager);
memdelete(gl_context);
psmExit();
}

void OS_Switch::finalize_core() {
Expand Down Expand Up @@ -505,15 +507,39 @@ void OS_Switch::hide_virtual_keyboard() {
}

OS::PowerState OS_Switch::get_power_state() {
return power_manager->get_power_state();
if (!OS_Switch::psm_initialized) {
return OS::POWERSTATE_UNKNOWN;
}

bool enough_power;
psmIsEnoughPowerSupplied(&enough_power);

if (!enough_power) {
return OS::PowerState::POWERSTATE_ON_BATTERY;
}

int percentage = OS_Switch::get_power_percent_left();

if (percentage == 100) {
return OS::PowerState::POWERSTATE_CHARGED;
}

return OS::PowerState::POWERSTATE_CHARGING;
}

int OS_Switch::get_power_seconds_left() {
return power_manager->get_power_seconds_left();
WARN_PRINT("power_seconds_left is not implemented on this platform, defaulting to -1");
return -1;
}

int OS_Switch::get_power_percent_left() {
return power_manager->get_power_percent_left();
if (!OS_Switch::psm_initialized) {
return -1;
}

u32 voltage_percentage;
psmGetBatteryChargePercentage(&voltage_percentage);
return (int)voltage_percentage;
}

String OS_Switch::get_executable_path() const {
Expand Down Expand Up @@ -554,8 +580,8 @@ OS_Switch::OS_Switch() {
main_loop = nullptr;
visual_server = nullptr;
input = nullptr;
power_manager = nullptr;
gl_context = nullptr;

AudioDriverManager::add_driver(&driver_audren);

swkbdInlineCreate(&inline_keyboard);
Expand Down
4 changes: 2 additions & 2 deletions platform/switch/os_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "drivers/audren/audio_driver_audren.h"
#include "joypad_switch.h"
#include "main/input_default.h"
#include "power_switch.h"
#include "servers/visual/visual_server_raster.h"

class OS_Switch : public OS {
Expand All @@ -43,14 +42,15 @@ class OS_Switch : public OS {
VideoMode current_videomode;
VisualServer *visual_server;
InputDefault *input;
PowerSwitch *power_manager;
ContextGLSwitchEGL *gl_context;
JoypadSwitch *joypad;
AudioDriverAudren driver_audren;
String switch_execpath;

SwkbdInline inline_keyboard;

bool psm_initialized = false;

protected:
virtual void initialize_core();
virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
Expand Down
75 changes: 0 additions & 75 deletions platform/switch/power_switch.cpp

This file was deleted.

52 changes: 0 additions & 52 deletions platform/switch/power_switch.h

This file was deleted.

0 comments on commit 8b85723

Please sign in to comment.