initial components
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.15)
|
cmake_minimum_required(VERSION 3.15)
|
||||||
project(sdl-test
|
project(sdl-test
|
||||||
LANGUAGES CXX)
|
LANGUAGES C CXX)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 26)
|
set(CMAKE_CXX_STANDARD 26)
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
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)
|
add_subdirectory(deps EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
|||||||
18
include/GameObject.h
Normal file
18
include/GameObject.h
Normal 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
8
include/Graphics.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Graphics {
|
||||||
|
public:
|
||||||
|
Graphics(){}
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
13
include/components/GraphicsComponent.h
Normal file
13
include/components/GraphicsComponent.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Graphics.h"
|
||||||
|
|
||||||
|
class GraphicsComponent {
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~GraphicsComponent() {}
|
||||||
|
virtual void update(Graphics &graphics) = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
11
include/components/PlayerGraphics.h
Normal file
11
include/components/PlayerGraphics.h
Normal 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");
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
add_executable(${PROJECT_NAME} main.cpp)
|
set(SOURCES
|
||||||
|
components/PlayerGraphics.cpp
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIR})
|
components/GraphicsComponent.cpp)
|
||||||
|
add_executable(${PROJECT_NAME} main.cpp ${SOURCES})
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3)
|
target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3)
|
||||||
|
|
||||||
|
|||||||
0
src/components/GraphicsComponent.cpp
Normal file
0
src/components/GraphicsComponent.cpp
Normal file
0
src/components/PlayerGraphics.cpp
Normal file
0
src/components/PlayerGraphics.cpp
Normal file
@@ -17,9 +17,18 @@
|
|||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3/SDL_main.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_Window *window = nullptr;
|
||||||
static SDL_Renderer *renderer = nullptr;
|
static SDL_Renderer *renderer = nullptr;
|
||||||
|
|
||||||
|
GameObject player(std::make_unique<PlayerGraphics>());
|
||||||
|
Graphics graphics;
|
||||||
|
|
||||||
/* This function runs once at startup. */
|
/* This function runs once at startup. */
|
||||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user