arreglos en la estructura
afegida una escena de test
This commit is contained in:
1 parent
6961986ad2
commit
9b168f02eb
13 files changed
+142
-49
No files matched your search
+4
-3
@@ -5,15 +5,16 @@ project(spectrum LANGUAGES CXX)
|
|||||||
find_package(SDL3 REQUIRED CONFIG)
|
find_package(SDL3 REQUIRED CONFIG)
|
||||||
|
|
||||||
add_executable(spectrum
|
add_executable(spectrum
|
||||||
source/core/main.cpp
|
source/main.cpp
|
||||||
source/core/rendering/video.cpp
|
source/core/rendering/video.cpp
|
||||||
source/core/system/director.cpp
|
source/game/director.cpp
|
||||||
|
source/game/scenes/test.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_features(spectrum PRIVATE cxx_std_20)
|
target_compile_features(spectrum PRIVATE cxx_std_20)
|
||||||
|
|
||||||
target_include_directories(spectrum PRIVATE
|
target_include_directories(spectrum PRIVATE
|
||||||
source/core
|
source
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(spectrum PRIVATE SDL3::SDL3)
|
target_link_libraries(spectrum PRIVATE SDL3::SDL3)
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "rendering/video.hpp"
|
// video.cpp
|
||||||
|
|
||||||
|
#include "video.hpp"
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
@@ -54,7 +56,7 @@ auto Video::initSDL() -> int {
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
//SDL_SetTextureScaleMode(game_texture_, toSdlScaleMode(config_.texture_filter));
|
// SDL_SetTextureScaleMode(game_texture_, toSdlScaleMode(config_.texture_filter));
|
||||||
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Video subsystem initialized successfully");
|
"Video subsystem initialized successfully");
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// video.hpp
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
#include "system/director.hpp"
|
|
||||||
|
|
||||||
#include "rendering/video.hpp"
|
|
||||||
#include "system/defaults.hpp"
|
|
||||||
|
|
||||||
Director::Director() {
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"Game start!");
|
|
||||||
|
|
||||||
video = std::make_shared<Video>(
|
|
||||||
Video::Config{
|
|
||||||
Defaults::Video::FULLSCREEN,
|
|
||||||
Defaults::Video::ZOOM,
|
|
||||||
Defaults::Video::WIDTH,
|
|
||||||
Defaults::Video::HEIGHT});
|
|
||||||
}
|
|
||||||
|
|
||||||
Director::~Director() {
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"Bye!");
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto Director::iterate() -> int {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "rendering/video.hpp"
|
|
||||||
|
|
||||||
class Director {
|
|
||||||
public:
|
|
||||||
Director();
|
|
||||||
~Director();
|
|
||||||
|
|
||||||
auto iterate() -> int;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::shared_ptr<Video> video;
|
|
||||||
};
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// defaults.hpp
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace Defaults::Video {
|
namespace Defaults::Video {
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
// director.cpp
|
||||||
|
|
||||||
|
#include "director.hpp"
|
||||||
|
|
||||||
|
#include "core/rendering/video.hpp"
|
||||||
|
#include "defaults.hpp"
|
||||||
|
#include "game/scenes/scenes.hpp"
|
||||||
|
#include "game/scenes/test.hpp"
|
||||||
|
|
||||||
|
Director::Director() {
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"Game start!");
|
||||||
|
|
||||||
|
video_ = std::make_shared<Video>(
|
||||||
|
Video::Config{
|
||||||
|
Defaults::Video::FULLSCREEN,
|
||||||
|
Defaults::Video::ZOOM,
|
||||||
|
Defaults::Video::WIDTH,
|
||||||
|
Defaults::Video::HEIGHT});
|
||||||
|
scene_ = std::make_unique<Test>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Director::~Director() {
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"Bye!");
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Director::iterate() -> int {
|
||||||
|
while (scene_) {
|
||||||
|
scene_->render();
|
||||||
|
switch (scene_->update()) {
|
||||||
|
case Scenes::CONTINUE:
|
||||||
|
break;
|
||||||
|
case Scenes::LOGO:
|
||||||
|
break;
|
||||||
|
case Scenes::INTRO:
|
||||||
|
break;
|
||||||
|
case Scenes::GAME:
|
||||||
|
break;
|
||||||
|
case Scenes::TEST:
|
||||||
|
scene_ = std::make_unique<Test>();
|
||||||
|
break;
|
||||||
|
case Scenes::QUIT:
|
||||||
|
scene_.reset();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// director.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "core/rendering/video.hpp"
|
||||||
|
#include "game/scenes/scene.hpp"
|
||||||
|
|
||||||
|
class Director {
|
||||||
|
public:
|
||||||
|
Director();
|
||||||
|
~Director();
|
||||||
|
|
||||||
|
auto iterate() -> int;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Core
|
||||||
|
std::shared_ptr<Video> video_;
|
||||||
|
|
||||||
|
// Game
|
||||||
|
std::unique_ptr<Scene> scene_;
|
||||||
|
};
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// scene.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "scenes.hpp"
|
||||||
|
|
||||||
|
class Scene {
|
||||||
|
public:
|
||||||
|
virtual ~Scene() = default;
|
||||||
|
|
||||||
|
virtual auto update() -> Scenes = 0;
|
||||||
|
virtual void render() = 0;
|
||||||
|
};
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// scenes.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum class Scenes {
|
||||||
|
INTRO,
|
||||||
|
LOGO,
|
||||||
|
GAME,
|
||||||
|
TEST,
|
||||||
|
CONTINUE,
|
||||||
|
QUIT
|
||||||
|
};
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// test.cpp
|
||||||
|
|
||||||
|
#include "test.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
auto Test::update() -> Scenes {
|
||||||
|
static int count = 0;
|
||||||
|
std::cout << count++ << "\n";
|
||||||
|
if (count == 100) { return Scenes::QUIT; }
|
||||||
|
return Scenes::CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Test::render() {
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// test.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "scene.hpp"
|
||||||
|
|
||||||
|
class Test final : public Scene {
|
||||||
|
public:
|
||||||
|
auto update() -> Scenes override;
|
||||||
|
void render() override;
|
||||||
|
};
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
|
// main.cpp
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "system/director.hpp"
|
#include "game/director.hpp"
|
||||||
|
|
||||||
auto main() -> int {
|
auto main() -> int {
|
||||||
auto director = std::make_unique<Director>();
|
auto director = std::make_unique<Director>();
|
||||||
return 0;
|
return director->iterate();
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user