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);
|
SDL_Delay(1000);
|
||||||
|
|
||||||
return 0;
|
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(Config config);
|
||||||
~Video();
|
~Video();
|
||||||
|
|
||||||
|
void clean(int color);
|
||||||
|
void present();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Config config_;
|
Config config_;
|
||||||
|
|
||||||
|
|||||||
@@ -11,13 +11,19 @@ Director::Director() {
|
|||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Game start!");
|
"Game start!");
|
||||||
|
|
||||||
video_ = std::make_shared<Video>(
|
// Inicializa los subsistemas
|
||||||
|
video_ = std::make_unique<Video>(
|
||||||
Video::Config{
|
Video::Config{
|
||||||
Defaults::Video::FULLSCREEN,
|
Defaults::Video::FULLSCREEN,
|
||||||
Defaults::Video::ZOOM,
|
Defaults::Video::ZOOM,
|
||||||
Defaults::Video::WIDTH,
|
Defaults::Video::WIDTH,
|
||||||
Defaults::Video::HEIGHT});
|
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() {
|
Director::~Director() {
|
||||||
@@ -39,7 +45,7 @@ auto Director::iterate() -> int {
|
|||||||
case Scenes::GAME:
|
case Scenes::GAME:
|
||||||
break;
|
break;
|
||||||
case Scenes::TEST:
|
case Scenes::TEST:
|
||||||
scene_ = std::make_unique<Test>();
|
scene_ = std::make_unique<Test>(context_);
|
||||||
break;
|
break;
|
||||||
case Scenes::QUIT:
|
case Scenes::QUIT:
|
||||||
scene_.reset();
|
scene_.reset();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "core/rendering/video.hpp"
|
#include "core/rendering/video.hpp"
|
||||||
#include "game/scenes/scene.hpp"
|
#include "game/scenes/scene.hpp"
|
||||||
|
#include "gamecontext.hpp"
|
||||||
|
|
||||||
class Director {
|
class Director {
|
||||||
public:
|
public:
|
||||||
@@ -15,8 +16,10 @@ class Director {
|
|||||||
auto iterate() -> int;
|
auto iterate() -> int;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
GameContext context_;
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
std::shared_ptr<Video> video_;
|
std::unique_ptr<Video> video_;
|
||||||
|
|
||||||
// Game
|
// Game
|
||||||
std::unique_ptr<Scene> scene_;
|
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
|
// test.cpp
|
||||||
|
|
||||||
#include "test.hpp"
|
#include "test.hpp"
|
||||||
|
#include "core/rendering/video.hpp"
|
||||||
|
#include "game/gamecontext.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
Test::Test(GameContext& context)
|
||||||
|
: context_(context) {}
|
||||||
|
|
||||||
auto Test::update() -> Scenes {
|
auto Test::update() -> Scenes {
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
std::cout << count++ << "\n";
|
std::cout << count++ << "\n";
|
||||||
if (count == 100) { return Scenes::QUIT; }
|
if (count == 500) { return Scenes::QUIT; }
|
||||||
return Scenes::CONTINUE;
|
return Scenes::CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test::render() {
|
void Test::render() {
|
||||||
|
context_.video->clean(0xAA0000);
|
||||||
|
context_.video->present();
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,14 @@
|
|||||||
|
|
||||||
#include "scene.hpp"
|
#include "scene.hpp"
|
||||||
|
|
||||||
|
struct GameContext;
|
||||||
|
|
||||||
class Test final : public Scene {
|
class Test final : public Scene {
|
||||||
public:
|
public:
|
||||||
|
explicit Test(GameContext& context);
|
||||||
auto update() -> Scenes override;
|
auto update() -> Scenes override;
|
||||||
void render() override;
|
void render() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GameContext& context_;
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user