initial components

This commit is contained in:
Josh Lyon
2025-08-12 23:14:42 -06:00
parent 4e3e4f9aab
commit f6de0ed9f3
9 changed files with 65 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)
project(sdl-test
LANGUAGES CXX)
LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 26)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@@ -10,7 +10,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
add_subdirectory(deps EXCLUDE_FROM_ALL)
set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
add_subdirectory(src)

18
include/GameObject.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include <memory>
#include "Graphics.h"
#include "components/GraphicsComponent.h"
class GameObject : std::enable_shared_from_this<GameObject> {
public:
GameObject(std::unique_ptr<GraphicsComponent> graphics)
: m_graphics(std::move(graphics)) {}
void update(Graphics &graphics) {
m_graphics->update(graphics);
}
private:
std::unique_ptr<GraphicsComponent> m_graphics;
};

8
include/Graphics.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
class Graphics {
public:
Graphics(){}
private:
};

View File

@@ -0,0 +1,13 @@
#pragma once
#include "Graphics.h"
class GraphicsComponent {
public:
virtual ~GraphicsComponent() {}
virtual void update(Graphics &graphics) = 0;
private:
};

View File

@@ -0,0 +1,11 @@
#pragma once
#include "Graphics.h"
#include "GraphicsComponent.h"
#include <print>
class PlayerGraphics : public GraphicsComponent {
void update(Graphics &graphics) {
std::print("Updating player graphics");
}
};

View File

@@ -1,6 +1,7 @@
add_executable(${PROJECT_NAME} main.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIR})
set(SOURCES
components/PlayerGraphics.cpp
components/GraphicsComponent.cpp)
add_executable(${PROJECT_NAME} main.cpp ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3)

View File

View File

View File

@@ -17,9 +17,18 @@
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <memory>
#include "components/PlayerGraphics.h"
#include "Graphics.h"
#include "GameObject.h"
static SDL_Window *window = nullptr;
static SDL_Renderer *renderer = nullptr;
GameObject player(std::make_unique<PlayerGraphics>());
Graphics graphics;
/* This function runs once at startup. */
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
{