Added a new Platform class.

This commit is contained in:
Relintai 2021-11-09 17:47:51 +01:00
parent d637c2132c
commit 0bca7735e1
6 changed files with 91 additions and 2 deletions

22
core/os/platform.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "platform.h"
#include "core/error_macros.h"
void Platform::arg_setup(int argc, char **argv, char **envp) {
arg_parser.setup(argc, argv, envp);
}
Platform *Platform::get_singleton() {
return _self;
}
Platform::Platform() {
_self = this;
}
Platform::~Platform() {
if (_self == this) {
_self = nullptr;
}
}
Platform *Platform::_self = nullptr;

21
core/os/platform.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef PLATFORM_H
#define PLATFORM_H
#include "arg_parser.h"
class Platform {
public:
virtual void arg_setup(int argc, char **argv, char **envp);
static Platform *get_singleton();
Platform();
virtual ~Platform();
ArgParser arg_parser;
protected:
static Platform *_self;
};
#endif

View File

@ -0,0 +1,8 @@
#include "platform_linux.h"
#include "core/error_macros.h"
PlatformLinux::PlatformLinux() : Platform() {
}
PlatformLinux::~PlatformLinux() {
}

View File

@ -0,0 +1,14 @@
#ifndef PLATFORM_LINUX_H
#define PLATFORM_LINUX_H
#include "core/os/platform.h"
class PlatformLinux : public Platform {
public:
PlatformLinux();
virtual ~PlatformLinux();
protected:
};
#endif

View File

@ -4,8 +4,24 @@
#if PLATFORM_LINUX
#include "linux/crash_handler_linux.h"
#include "linux/platform_linux.h"
#endif
void PlatformInitializer::allocate_platform() {
ERR_FAIL_COND(_platform);
#if PLATFORM_LINUX
_platform = new PlatformLinux();
#endif
}
void PlatformInitializer::free_platform() {
if (_platform) {
delete _platform;
_platform = nullptr;
}
}
void PlatformInitializer::allocate_crash_handler() {
ERR_FAIL_COND(_crash_handler);
@ -23,11 +39,14 @@ void PlatformInitializer::free_crash_handler() {
}
void PlatformInitializer::allocate_all() {
allocate_platform();
allocate_crash_handler();
}
void PlatformInitializer::free_all() {
free_platform();
free_crash_handler();
}
Platform *PlatformInitializer::_platform = nullptr;
CrashHandler *PlatformInitializer::_crash_handler = nullptr;

View File

@ -1,11 +1,15 @@
#ifndef PLATFORM_INITIALIZER_H
#define PLATFORM_INITIALIZER_H
#include "core/os/platform.h"
#include "core/os/crash_handler.h"
class PlatformInitializer {
public:
static void allocate_platform();
static void free_platform();
static void allocate_crash_handler();
static void free_crash_handler();
@ -14,6 +18,7 @@ public:
protected:
static CrashHandler *_crash_handler;
static Platform *_platform;
};
#endif