mirror of
https://github.com/encounter/cpp3ds.git
synced 2026-03-30 11:04:22 -07:00
Add basic console, remove console method from Game
This commit is contained in:
@@ -23,26 +23,14 @@ class Console : public Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// The constructor creates and activates the context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Console();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
/// The destructor deactivates and destroys the context
|
||||
/// The destructor deactivates and destroys the console
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Console();
|
||||
|
||||
public:
|
||||
|
||||
void create(Screen screen = BottomScreen);
|
||||
|
||||
void update(float delta);
|
||||
|
||||
void write(String text);
|
||||
@@ -51,10 +39,14 @@ public:
|
||||
|
||||
void setVisible(bool visible);
|
||||
|
||||
static void initialize();
|
||||
static Console& getInstance();
|
||||
|
||||
static void enable(Screen screen, Color color = Color::White);
|
||||
static void enableBasic(Screen screen);
|
||||
static bool isEnabled();
|
||||
static bool isEnabledBasic();
|
||||
|
||||
void setScreen(Screen screen);
|
||||
|
||||
Screen getScreen();
|
||||
|
||||
void setColor(const Color& color);
|
||||
@@ -62,6 +54,14 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// The constructor creates and activates the context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Console();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Draw the console to a render target
|
||||
///
|
||||
@@ -79,7 +79,8 @@ private:
|
||||
std::vector<Text> m_lines;
|
||||
Text m_memoryText;
|
||||
unsigned int m_limit;
|
||||
static bool m_initialized;
|
||||
static bool m_enabled;
|
||||
static bool m_enabledBasic;
|
||||
bool m_visible;
|
||||
Screen m_screen;
|
||||
};
|
||||
|
||||
@@ -21,8 +21,6 @@ public:
|
||||
virtual void processEvent(Event& event) = 0;
|
||||
virtual void renderTopScreen(Window& window) = 0;
|
||||
virtual void renderBottomScreen(Window& window) = 0;
|
||||
void console(Screen screen = BottomScreen, Color color = Color::White);
|
||||
void consoleBasic(Screen screen = BottomScreen);
|
||||
void render();
|
||||
void run();
|
||||
void exit();
|
||||
@@ -31,11 +29,7 @@ public:
|
||||
protected:
|
||||
Window windowTop, windowBottom;
|
||||
private:
|
||||
bool m_consoleEnabled;
|
||||
bool m_consoleBasicEnabled;
|
||||
bool m_triggerExit;
|
||||
Console m_console;
|
||||
Screen m_consoleScreen;
|
||||
#ifdef EMULATION
|
||||
sf::RenderTexture m_frameTextureTop, m_frameTextureBottom;
|
||||
sf::Sprite m_frameSpriteTop, m_frameSpriteBottom;
|
||||
|
||||
@@ -43,52 +43,86 @@ static const devoptab_t dotab_stdout = {
|
||||
namespace cpp3ds
|
||||
{
|
||||
|
||||
bool Console::m_initialized = false;
|
||||
bool Console::m_enabled = false;
|
||||
bool Console::m_enabledBasic = false;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Console::Console()
|
||||
: m_visible(true)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Console::~Console()
|
||||
{
|
||||
if (m_initialized)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Console& Console::getInstance()
|
||||
{
|
||||
static Console console;
|
||||
return console;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Console::enable(Screen screen, Color color)
|
||||
{
|
||||
if (m_enabledBasic)
|
||||
return;
|
||||
if (!m_enabled) {
|
||||
m_enabled = true;
|
||||
#ifndef EMULATION
|
||||
gfxInitDefault();
|
||||
devoptab_list[STD_OUT] = &dotab_stdout;
|
||||
devoptab_list[STD_ERR] = &dotab_stdout;
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
setvbuf(stderr, NULL, _IONBF, 0);
|
||||
#endif
|
||||
Console& console = getInstance();
|
||||
priv::ResourceInfo font = priv::core_resources["opensans.ttf"];
|
||||
console.m_font.loadFromMemory(font.data, font.size);
|
||||
|
||||
console.m_memoryText.setFont(console.m_font);
|
||||
console.m_memoryText.setCharacterSize(12);
|
||||
|
||||
console.m_screen = screen;
|
||||
console.m_color = color;
|
||||
console.m_limit = 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Console::initialize()
|
||||
void Console::enableBasic(Screen screen)
|
||||
{
|
||||
if (!m_initialized) {
|
||||
m_initialized = true;
|
||||
if (m_enabled)
|
||||
return;
|
||||
if (!m_enabledBasic) {
|
||||
m_enabledBasic = true;
|
||||
Console& console = getInstance();
|
||||
console.m_screen = screen;
|
||||
#ifndef EMULATION
|
||||
devoptab_list[STD_OUT] = &dotab_stdout;
|
||||
devoptab_list[STD_ERR] = &dotab_stdout;
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
setvbuf(stderr, NULL, _IONBF, 0);
|
||||
gfxInitDefault();
|
||||
consoleInit(screen == TopScreen ? GFX_TOP : GFX_BOTTOM, nullptr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void Console::create(Screen screen)
|
||||
bool Console::isEnabled()
|
||||
{
|
||||
initialize();
|
||||
priv::ResourceInfo font = priv::core_resources["opensans.ttf"];
|
||||
m_font.loadFromMemory(font.data, font.size);
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
m_memoryText.setFont(m_font);
|
||||
m_memoryText.setCharacterSize(12);
|
||||
|
||||
m_screen = screen;
|
||||
m_limit = 1000;
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Console::isEnabledBasic()
|
||||
{
|
||||
return m_enabledBasic;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,12 +136,12 @@ void Console::update(float delta)
|
||||
if (m_lines.size() > m_limit)
|
||||
m_lines.erase(m_lines.begin(), m_lines.end() - m_limit);
|
||||
|
||||
#ifndef EMULATION
|
||||
#ifndef EMULATION
|
||||
std::ostringstream ss;
|
||||
ss << (__linear_heap_size - linearSpaceFree()) / 1024 << "kb / " << __linear_heap_size / 1024 << "kb";
|
||||
m_memoryText.setString(ss.str());
|
||||
m_memoryText.setPosition((m_screen == TopScreen ? 395 : 315) - m_memoryText.getGlobalBounds().width, 5);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int h = 240;
|
||||
int i = m_lines.size();
|
||||
|
||||
+17
-36
@@ -23,10 +23,8 @@ static void apt_clock_hook(APT_HookType hook, void* param)
|
||||
|
||||
Game::Game()
|
||||
: m_triggerExit(false)
|
||||
, m_consoleEnabled(false)
|
||||
, m_consoleBasicEnabled(false)
|
||||
{
|
||||
if (!Console::isInitialized())
|
||||
if (!Console::isEnabled() && !Console::isEnabledBasic())
|
||||
gfxInitDefault();
|
||||
CitroInit();
|
||||
Service::enable(RomFS);
|
||||
@@ -51,49 +49,30 @@ Game::~Game()
|
||||
}
|
||||
|
||||
|
||||
void Game::console(Screen screen, Color color)
|
||||
{
|
||||
if (m_consoleEnabled || m_consoleBasicEnabled)
|
||||
return;
|
||||
Console::initialize();
|
||||
m_consoleScreen = screen;
|
||||
m_consoleEnabled = true;
|
||||
m_console.setVisible(true);
|
||||
m_console.create(screen);
|
||||
m_console.setColor(color);
|
||||
}
|
||||
|
||||
|
||||
void Game::consoleBasic(Screen screen)
|
||||
{
|
||||
if (m_consoleEnabled || m_consoleBasicEnabled)
|
||||
return;
|
||||
Console::initializeBasic(screen);
|
||||
m_consoleScreen = screen;
|
||||
m_consoleBasicEnabled = true;
|
||||
}
|
||||
|
||||
|
||||
void Game::render()
|
||||
{
|
||||
if (!m_consoleBasicEnabled || m_consoleScreen != TopScreen) {
|
||||
Console& console = Console::getInstance();
|
||||
|
||||
if (!console.isEnabledBasic() || console.getScreen() != TopScreen) {
|
||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||
C3D_FrameDrawOn(windowTop.getCitroTarget());
|
||||
windowTop.setView(windowTop.getDefaultView());
|
||||
renderTopScreen(windowTop);
|
||||
if (m_consoleEnabled && m_consoleScreen == TopScreen) {
|
||||
if (console.isEnabled() && console.getScreen() == TopScreen) {
|
||||
windowTop.setView(windowTop.getDefaultView());
|
||||
windowTop.draw(m_console);
|
||||
windowTop.draw(Console::getInstance());
|
||||
}
|
||||
C3D_FrameEnd(0);
|
||||
}
|
||||
|
||||
if (!m_consoleBasicEnabled || m_consoleScreen != BottomScreen) {
|
||||
if (!console.isEnabledBasic() || console.getScreen() != BottomScreen) {
|
||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||
C3D_FrameDrawOn(windowBottom.getCitroTarget());
|
||||
windowBottom.setView(windowBottom.getDefaultView());
|
||||
renderBottomScreen(windowBottom);
|
||||
if (m_consoleEnabled && m_consoleScreen == BottomScreen) {
|
||||
if (console.isEnabled() && console.getScreen() == BottomScreen) {
|
||||
windowBottom.setView(windowBottom.getDefaultView());
|
||||
windowBottom.draw(m_console);
|
||||
windowBottom.draw(Console::getInstance());
|
||||
}
|
||||
C3D_FrameEnd(0);
|
||||
}
|
||||
@@ -113,6 +92,8 @@ void Game::run()
|
||||
Clock clock;
|
||||
Time deltaTime;
|
||||
|
||||
Console& console = Console::getInstance();
|
||||
|
||||
// Hook for clock
|
||||
aptHook(&apt_hook_cookie, apt_clock_hook, &clock);
|
||||
|
||||
@@ -122,8 +103,8 @@ void Game::run()
|
||||
Sensor::update();
|
||||
|
||||
while (eventmanager.pollEvent(event)) {
|
||||
if (m_consoleEnabled) {
|
||||
if (!m_console.processEvent(event))
|
||||
if (console.isEnabled()) {
|
||||
if (!console.processEvent(event))
|
||||
continue;
|
||||
}
|
||||
processEvent(event);
|
||||
@@ -133,8 +114,8 @@ void Game::run()
|
||||
if (m_triggerExit)
|
||||
break;
|
||||
|
||||
if (m_consoleEnabled)
|
||||
m_console.update(deltaTime.asSeconds());
|
||||
if (console.isEnabled())
|
||||
console.update(deltaTime.asSeconds());
|
||||
|
||||
update(deltaTime.asSeconds());
|
||||
render();
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace cpp3ds {
|
||||
|
||||
Game::Game()
|
||||
: m_triggerExit(false)
|
||||
, m_consoleEnabled(false)
|
||||
{
|
||||
priv::ensureExtensionsInit();
|
||||
|
||||
@@ -32,12 +31,6 @@ Game::~Game()
|
||||
}
|
||||
|
||||
|
||||
void Game::console(Screen screen, Color color)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
void Game::exit()
|
||||
{
|
||||
m_triggerExit = true;
|
||||
|
||||
Reference in New Issue
Block a user