move scene manager into App class
This commit is contained in:
parent
f12e61b1b5
commit
31adb6cbc9
@ -1,17 +1,59 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
#include "utils/Random.hpp"
|
#include "utils/Random.hpp"
|
||||||
|
|
||||||
|
struct Vector2;
|
||||||
|
struct Color;
|
||||||
|
struct Rectangle;
|
||||||
struct Texture;
|
struct Texture;
|
||||||
struct RenderTexture;
|
struct RenderTexture;
|
||||||
struct Color;
|
struct Camera2D;
|
||||||
struct Vector2;
|
|
||||||
struct Rectangle;
|
#ifdef PANDA_INCLUDE_TYPE
|
||||||
|
|
||||||
|
struct Vector2 {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Color {
|
||||||
|
unsigned char r;
|
||||||
|
unsigned char g;
|
||||||
|
unsigned char b;
|
||||||
|
unsigned char a;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Rectangle {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float width;
|
||||||
|
float height;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Texture {
|
||||||
|
unsigned int id;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int mipmaps;
|
||||||
|
int format;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct RenderTexture {
|
||||||
|
unsigned int id;
|
||||||
|
Texture texture;
|
||||||
|
Texture depth;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Camera2D {
|
||||||
|
Vector2 offset;
|
||||||
|
Vector2 target;
|
||||||
|
float rotation;
|
||||||
|
float zoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace panda
|
namespace panda
|
||||||
{
|
{
|
||||||
@ -29,7 +71,10 @@ namespace panda
|
|||||||
public:
|
public:
|
||||||
Scene() {}
|
Scene() {}
|
||||||
virtual ~Scene() {}
|
virtual ~Scene() {}
|
||||||
virtual void update() {}
|
virtual void Preload() {}
|
||||||
|
virtual void Update() {}
|
||||||
|
|
||||||
|
bool preloaded = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Sprite {
|
struct Sprite {
|
||||||
@ -73,15 +118,20 @@ namespace panda
|
|||||||
void concat(Matrix m);
|
void concat(Matrix m);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class App {
|
||||||
|
public:
|
||||||
|
void CreateWindow(int w, int h, const char *str);
|
||||||
|
|
||||||
|
void AppUpdate();
|
||||||
|
void SetScene(Scene* scene);
|
||||||
|
Scene* GetScene();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Scene* _scene_current = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
// ############################################################################################
|
// ############################################################################################
|
||||||
|
|
||||||
// Core
|
|
||||||
void CreateWindow(int w, int h, const char *str);
|
|
||||||
|
|
||||||
void AppUpdate();
|
|
||||||
void SetScene(Scene* scene);
|
|
||||||
Scene* GetScene();
|
|
||||||
|
|
||||||
// # Graphic
|
// # Graphic
|
||||||
|
|
||||||
// ### GUI
|
// ### GUI
|
||||||
|
51
src/core/App.cpp
Executable file
51
src/core/App.cpp
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#include "Panda.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef PANDA_BACKEND_RAYLIB
|
||||||
|
#include <raylib.h>
|
||||||
|
|
||||||
|
void panda::App::CreateWindow(int w, int h, const char *str)
|
||||||
|
{
|
||||||
|
SetConfigFlags(
|
||||||
|
FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
|
#if PLATFORM_ANDROID
|
||||||
|
InitWindow(0, 0, str);
|
||||||
|
#elif PLATFORM_DESKTOP
|
||||||
|
InitWindow(w, h, str);
|
||||||
|
SetWindowMinSize(w*0.8f, h*0.8f);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SetExitKey(-1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void panda::App::AppUpdate()
|
||||||
|
{
|
||||||
|
if (_scene_current != nullptr)
|
||||||
|
{
|
||||||
|
while (!_scene_current->preloaded)
|
||||||
|
{
|
||||||
|
_scene_current->preloaded = true;
|
||||||
|
_scene_current->Preload();
|
||||||
|
}
|
||||||
|
|
||||||
|
_scene_current->Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void panda::App::SetScene(Scene* scene)
|
||||||
|
{
|
||||||
|
if (_scene_current != nullptr)
|
||||||
|
{
|
||||||
|
delete _scene_current;
|
||||||
|
_scene_current = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
_scene_current = scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
panda::Scene* panda::App::GetScene()
|
||||||
|
{
|
||||||
|
return _scene_current;
|
||||||
|
}
|
@ -1,51 +0,0 @@
|
|||||||
#include <raylib.h>
|
|
||||||
|
|
||||||
#include "Panda.hpp"
|
|
||||||
|
|
||||||
static panda::Scene* currentScene = nullptr;
|
|
||||||
|
|
||||||
// CORE
|
|
||||||
void panda::CreateWindow(int w, int h, const char *str)
|
|
||||||
{
|
|
||||||
Random::getInstance().setSeedFromTime();
|
|
||||||
|
|
||||||
SetConfigFlags(
|
|
||||||
FLAG_MSAA_4X_HINT | FLAG_WINDOW_RESIZABLE);
|
|
||||||
|
|
||||||
#if PLATFORM_ANDROID
|
|
||||||
InitWindow(0, 0, str);
|
|
||||||
#elif PLATFORM_DESKTOP
|
|
||||||
InitWindow(w, h, str);
|
|
||||||
SetWindowMinSize(w*0.8f, h*0.8f);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SetExitKey(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void panda::AppUpdate()
|
|
||||||
{
|
|
||||||
if (currentScene != nullptr)
|
|
||||||
currentScene->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void panda::SetScene(Scene* scene)
|
|
||||||
{
|
|
||||||
if (currentScene != nullptr)
|
|
||||||
{
|
|
||||||
delete currentScene;
|
|
||||||
currentScene = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentScene = scene;
|
|
||||||
}
|
|
||||||
|
|
||||||
panda::Scene* panda::GetScene()
|
|
||||||
{
|
|
||||||
return currentScene;
|
|
||||||
}
|
|
||||||
|
|
||||||
// UTILS
|
|
||||||
panda::Random &panda::GetDefaultRandom()
|
|
||||||
{
|
|
||||||
return Random::getInstance();
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user