From 6961986ad210603f04fbb0acff0ff3247a39ad4d Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 3 Nov 2026 14:15:50 +0100 Subject: [PATCH] primera faeneta --- .clang-format | 22 +++++++++++ .gitignore | 5 ++- CMakeLists.txt | 19 ++++++++++ source/core/main.cpp | 8 ++++ source/core/rendering/video.cpp | 65 +++++++++++++++++++++++++++++++++ source/core/rendering/video.hpp | 26 +++++++++++++ source/core/system/defaults.hpp | 8 ++++ source/core/system/director.cpp | 26 +++++++++++++ source/core/system/director.hpp | 16 ++++++++ 9 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 .clang-format create mode 100644 CMakeLists.txt create mode 100644 source/core/main.cpp create mode 100644 source/core/rendering/video.cpp create mode 100644 source/core/rendering/video.hpp create mode 100644 source/core/system/defaults.hpp create mode 100644 source/core/system/director.cpp create mode 100644 source/core/system/director.hpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..e148dad --- /dev/null +++ b/.clang-format @@ -0,0 +1,22 @@ +BasedOnStyle: Google +IndentWidth: 4 +NamespaceIndentation: All +IndentAccessModifiers: false +ColumnLimit: 0 # Sin límite de longitud de línea +BreakBeforeBraces: Attach # Llaves en la misma línea +AllowShortIfStatementsOnASingleLine: true +AllowShortBlocksOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AlignOperands: DontAlign +AlignAfterOpenBracket: DontAlign +BinPackArguments: false +BinPackParameters: false +ContinuationIndentWidth: 4 +ConstructorInitializerIndentWidth: 4 +IndentWrappedFunctionNames: false +Cpp11BracedListStyle: true +BreakConstructorInitializers: BeforeColon +AllowAllConstructorInitializersOnNextLine: false +PackConstructorInitializers: Never +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false diff --git a/.gitignore b/.gitignore index e07cb72..bf83327 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +build/ + # ---> C++ # Prerequisites *.d @@ -80,7 +82,8 @@ $RECYCLE.BIN/ .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..234d5a9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.16) + +project(spectrum LANGUAGES CXX) + +find_package(SDL3 REQUIRED CONFIG) + +add_executable(spectrum + source/core/main.cpp + source/core/rendering/video.cpp + source/core/system/director.cpp +) + +target_compile_features(spectrum PRIVATE cxx_std_20) + +target_include_directories(spectrum PRIVATE + source/core +) + +target_link_libraries(spectrum PRIVATE SDL3::SDL3) diff --git a/source/core/main.cpp b/source/core/main.cpp new file mode 100644 index 0000000..7e8e660 --- /dev/null +++ b/source/core/main.cpp @@ -0,0 +1,8 @@ +#include + +#include "system/director.hpp" + +auto main() -> int { + auto director = std::make_unique(); + return 0; +} diff --git a/source/core/rendering/video.cpp b/source/core/rendering/video.cpp new file mode 100644 index 0000000..09e8351 --- /dev/null +++ b/source/core/rendering/video.cpp @@ -0,0 +1,65 @@ +#include "rendering/video.hpp" + +#include + +Video::Video(Config config) + : config_(config) { + initSDL(); +} + +Video::~Video() { + cleanup(); +} + +void Video::cleanup() { + SDL_DestroyTexture(game_texture_); + game_texture_ = nullptr; + + SDL_DestroyRenderer(renderer_); + renderer_ = nullptr; + + SDL_DestroyWindow(window_); + window_ = nullptr; +} + +auto Video::initSDL() -> int { + if (!SDL_Init(SDL_INIT_VIDEO)) { + SDL_Log("No se pudo inicializar SDL: %s", SDL_GetError()); + return 1; + } + + window_ = SDL_CreateWindow("Mi ventana", config_.width, config_.height, 0); + if (window_ == nullptr) { + SDL_Log("No se pudo crear la ventana: %s", SDL_GetError()); + cleanup(); + SDL_Quit(); + return 1; + } + + renderer_ = SDL_CreateRenderer(window_, nullptr); + if (renderer_ == nullptr) { + SDL_Log("No se pudo crear el renderer: %s", SDL_GetError()); + cleanup(); + SDL_Quit(); + return 1; + } + + // SDL_SetRenderVSync(renderer_, config_.vsync ? 1 : 0); + // SDL_SetRenderLogicalPresentation(renderer_, GameCanvas::WIDTH, GameCanvas::HEIGHT, toSdlPresentation(config_.scaling_mode)); + + game_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, config_.width, config_.height); + if (game_texture_ == nullptr) { + SDL_Log("No se pudo crear la textura de juego: %s", SDL_GetError()); + cleanup(); + SDL_Quit(); + return 1; + } + //SDL_SetTextureScaleMode(game_texture_, toSdlScaleMode(config_.texture_filter)); + + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, + "Video subsystem initialized successfully"); + + SDL_Delay(1000); + + return 0; +} \ No newline at end of file diff --git a/source/core/rendering/video.hpp b/source/core/rendering/video.hpp new file mode 100644 index 0000000..8af90f9 --- /dev/null +++ b/source/core/rendering/video.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include + +class Video { + public: + struct Config { + bool fullscreen{false}; + float zoom{1.0F}; + float width{320.0F}; + float height{240.0F}; + }; + + Video(Config config); + ~Video(); + + private: + Config config_; + + SDL_Window* window_{nullptr}; + SDL_Renderer* renderer_{nullptr}; + SDL_Texture* game_texture_{nullptr}; + + auto initSDL() -> int; + void cleanup(); +}; \ No newline at end of file diff --git a/source/core/system/defaults.hpp b/source/core/system/defaults.hpp new file mode 100644 index 0000000..0f4b1b0 --- /dev/null +++ b/source/core/system/defaults.hpp @@ -0,0 +1,8 @@ +#pragma once + +namespace Defaults::Video { + constexpr int ZOOM = 3; + constexpr bool FULLSCREEN = false; + constexpr float WIDTH = 320.0F; + constexpr float HEIGHT = 240.0F; +} // namespace Defaults::Video \ No newline at end of file diff --git a/source/core/system/director.cpp b/source/core/system/director.cpp new file mode 100644 index 0000000..6a5a803 --- /dev/null +++ b/source/core/system/director.cpp @@ -0,0 +1,26 @@ +#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