ja tenim algo de gamecontext. lo proxim va a ser fer algo per a la gestió del temps
This commit is contained in:
1 parent
9b168f02eb
commit
ffc2dee311
7 files changed
+52
-6
No files matched your search
@@ -64,4 +64,17 @@ auto Video::initSDL() -> int {
|
||||
SDL_Delay(1000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Video::clean(int color) {
|
||||
const Uint8 r = static_cast<Uint8>((color >> 16) & 0xFF);
|
||||
const Uint8 g = static_cast<Uint8>((color >> 8) & 0xFF);
|
||||
const Uint8 b = static_cast<Uint8>(color & 0xFF);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer_, r, g, b, 255);
|
||||
SDL_RenderClear(renderer_);
|
||||
}
|
||||
|
||||
void Video::present() {
|
||||
SDL_RenderPresent(renderer_);
|
||||
}
|
||||
@@ -16,6 +16,9 @@ class Video {
|
||||
Video(Config config);
|
||||
~Video();
|
||||
|
||||
void clean(int color);
|
||||
void present();
|
||||
|
||||
private:
|
||||
Config config_;
|
||||
|
||||
|
||||
@@ -11,13 +11,19 @@ Director::Director() {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Game start!");
|
||||
|
||||
video_ = std::make_shared<Video>(
|
||||
// Inicializa los subsistemas
|
||||
video_ = std::make_unique<Video>(
|
||||
Video::Config{
|
||||
Defaults::Video::FULLSCREEN,
|
||||
Defaults::Video::ZOOM,
|
||||
Defaults::Video::WIDTH,
|
||||
Defaults::Video::HEIGHT});
|
||||
scene_ = std::make_unique<Test>();
|
||||
|
||||
// Inicializa el contexto
|
||||
context_.video = video_.get();
|
||||
|
||||
// Establece la escena inicial
|
||||
scene_ = std::make_unique<Test>(context_);
|
||||
}
|
||||
|
||||
Director::~Director() {
|
||||
@@ -39,7 +45,7 @@ auto Director::iterate() -> int {
|
||||
case Scenes::GAME:
|
||||
break;
|
||||
case Scenes::TEST:
|
||||
scene_ = std::make_unique<Test>();
|
||||
scene_ = std::make_unique<Test>(context_);
|
||||
break;
|
||||
case Scenes::QUIT:
|
||||
scene_.reset();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "core/rendering/video.hpp"
|
||||
#include "game/scenes/scene.hpp"
|
||||
#include "gamecontext.hpp"
|
||||
|
||||
class Director {
|
||||
public:
|
||||
@@ -15,8 +16,10 @@ class Director {
|
||||
auto iterate() -> int;
|
||||
|
||||
private:
|
||||
GameContext context_;
|
||||
|
||||
// Core
|
||||
std::shared_ptr<Video> video_;
|
||||
std::unique_ptr<Video> video_;
|
||||
|
||||
// Game
|
||||
std::unique_ptr<Scene> scene_;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// GameContext.h
|
||||
|
||||
#pragma once
|
||||
|
||||
class Video;
|
||||
|
||||
struct GameContext {
|
||||
Video* video{nullptr};
|
||||
};
|
||||
@@ -1,16 +1,22 @@
|
||||
// test.cpp
|
||||
|
||||
#include "test.hpp"
|
||||
#include "core/rendering/video.hpp"
|
||||
#include "game/gamecontext.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Test::Test(GameContext& context)
|
||||
: context_(context) {}
|
||||
|
||||
auto Test::update() -> Scenes {
|
||||
static int count = 0;
|
||||
std::cout << count++ << "\n";
|
||||
if (count == 100) { return Scenes::QUIT; }
|
||||
if (count == 500) { return Scenes::QUIT; }
|
||||
return Scenes::CONTINUE;
|
||||
}
|
||||
|
||||
void Test::render() {
|
||||
context_.video->clean(0xAA0000);
|
||||
context_.video->present();
|
||||
}
|
||||
@@ -4,8 +4,14 @@
|
||||
|
||||
#include "scene.hpp"
|
||||
|
||||
struct GameContext;
|
||||
|
||||
class Test final : public Scene {
|
||||
public:
|
||||
explicit Test(GameContext& context);
|
||||
auto update() -> Scenes override;
|
||||
void render() override;
|
||||
|
||||
private:
|
||||
GameContext& context_;
|
||||
};
|
||||
Reference in new issue
Block a user