Merge all she::instance() implementations

Only she::create_system() must be provided by the platform impl.
This commit is contained in:
David Capello 2016-11-18 09:38:25 -03:00
parent 2f987ac3c3
commit 08bb51e358
6 changed files with 32 additions and 25 deletions

View File

@ -66,7 +66,7 @@ int app_main(int argc, char* argv[])
MemLeak memleak;
base::SystemConsole systemConsole;
app::AppOptions options(argc, const_cast<const char**>(argv));
she::ScopedHandle<she::System> system(she::create_system());
she::ScopedHandle<she::System> system(she::instance());
app::App app;
// Change the name of the memory dump file

View File

@ -2,7 +2,8 @@
# Copyright (C) 2012-2016 David Capello
set(SHE_SOURCES
common/freetype_font.cpp)
common/freetype_font.cpp
system.cpp)
######################################################################
# Allegro 4 backend

View File

@ -63,8 +63,6 @@
#include "she/alleg4/mouse_poller.h"
#endif
static she::System* g_instance = nullptr;
namespace she {
class Alleg4EventQueue : public EventQueue {
@ -129,15 +127,11 @@ public:
#ifdef USE_MOUSE_POLLER
mouse_poller_init();
#endif
g_instance = this;
}
~Alleg4System() {
remove_timer();
allegro_exit();
g_instance = nullptr;
}
void dispose() override {
@ -216,15 +210,11 @@ System* create_system() {
return new Alleg4System();
}
System* instance()
{
return g_instance;
}
void error_message(const char* msg)
{
if (g_instance && g_instance->logger())
g_instance->logger()->logError(msg);
System* sys = instance();
if (sys && sys->logger())
sys->logger()->logError(msg);
#ifdef _WIN32
std::wstring wmsg = base::from_utf8(msg);

View File

@ -24,15 +24,8 @@
namespace she {
static System* g_instance;
System* create_system() {
return g_instance = new SkiaSystem();
}
System* instance()
{
return g_instance;
return new SkiaSystem();
}
void error_message(const char* msg)

23
src/she/system.cpp Normal file
View File

@ -0,0 +1,23 @@
// SHE library
// Copyright (C) 2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "she/system.h"
namespace she {
System* instance()
{
static System* sys = nullptr;
if (!sys)
sys = create_system();
return sys;
}
} // namespace she

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -38,7 +38,7 @@ int main(int argc, char* argv[])
#ifdef TEST_GUI
{
// Do not create a she::System, as we don't need it for testing purposes.
//she::ScopedHandle<she::System> system(she::create_system());
//she::ScopedHandle<she::System> system(she::instance());
ui::UISystem uiSystem;
ui::Manager uiManager;
#endif