Skip to content

Commit 3dc3cb1

Browse files
committed
Code refactor: stage 3
1 parent 2c1a20e commit 3dc3cb1

40 files changed

+704
-718
lines changed

.github/workflows/win32-build.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Windows x64 Build & Package
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
runs-on: windows-latest
12+
13+
env:
14+
BUILD_TYPE: Release
15+
OUTPUT_DIR: Build
16+
ARCH: x64
17+
BUILD_DIR: build-x64 # per-arch build directory
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Show toolchain versions
26+
shell: pwsh
27+
run: |
28+
cmake --version
29+
ninja --version || echo "Ninja not used (VS generator expected)"
30+
31+
# Ensure a clean build dir to avoid generator/platform mismatch
32+
- name: Clean build dir (if exists)
33+
shell: pwsh
34+
run: |
35+
if (Test-Path $env:BUILD_DIR) { Remove-Item -Recurse -Force $env:BUILD_DIR }
36+
37+
# Cache only the per-arch _deps to avoid re-downloading SFML/tinyxml2
38+
- name: Cache CMake deps
39+
uses: actions/cache@v4
40+
with:
41+
path: |
42+
${{ env.BUILD_DIR }}/_deps
43+
key: ${{ runner.os }}-${{ env.ARCH }}-${{ env.BUILD_TYPE }}-cmake-deps-${{ hashFiles('cmake/**', '**/CMakeLists.txt') }}
44+
45+
- name: Configure (CMake, x64)
46+
shell: pwsh
47+
run: >
48+
cmake -S . -B $env:BUILD_DIR
49+
-A $env:ARCH
50+
-DCMAKE_BUILD_TYPE=$env:BUILD_TYPE
51+
52+
- name: Build
53+
shell: pwsh
54+
run: cmake --build $env:BUILD_DIR --config $env:BUILD_TYPE --parallel
55+
56+
# Validate outputs: only the exe and res/ are required
57+
- name: Verify outputs
58+
shell: pwsh
59+
run: |
60+
$binDir = Join-Path $PWD $env:OUTPUT_DIR
61+
$exe = Join-Path $binDir "SuperMario.exe"
62+
$res = Join-Path $binDir "res"
63+
if (-not (Test-Path $exe)) { throw "SuperMario.exe not found at $exe" }
64+
if (-not (Test-Path $res)) { throw "res folder not found at $res" }
65+
Write-Host "Artifacts OK: $exe and $res"
66+
67+
- name: Package zip (exe + res/)
68+
shell: pwsh
69+
run: |
70+
$binDir = Join-Path $PWD $env:OUTPUT_DIR
71+
$exe = Join-Path $binDir "SuperMario.exe"
72+
$res = Join-Path $binDir "res"
73+
$zipName = "SuperMario-x64-${{ env.BUILD_TYPE }}.zip"
74+
if (Test-Path $zipName) { Remove-Item $zipName -Force }
75+
Compress-Archive -Path $exe, $res -DestinationPath $zipName
76+
Write-Host "Created $zipName"
77+
78+
- name: Upload artifact
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: SuperMario-x64-${{ env.BUILD_TYPE }}
82+
path: SuperMario-x64-${{ env.BUILD_TYPE }}.zip
83+
if-no-files-found: error
84+
85+
- name: Upload to GitHub Release (on tag)
86+
if: startsWith(github.ref, 'refs/tags/v')
87+
uses: softprops/action-gh-release@v2
88+
with:
89+
files: SuperMario-x64-${{ env.BUILD_TYPE }}.zip
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitmodules

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
[submodule "ext/SFML"]
2-
path = ext/SFML
3-
url = git://github.com/SFML/SFML.git
4-
[submodule "ext/tinyxml2"]
5-
path = ext/tinyxml2
6-
url = git://github.com/leethomason/tinyxml2.git

CMakeLists.txt

Lines changed: 24 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,24 @@
1-
cmake_minimum_required(VERSION 3.8)
1+
cmake_minimum_required(VERSION 3.21)
22

33
project(SuperMario VERSION 0.99 LANGUAGES C CXX)
44

55
set(CMAKE_CXX_STANDARD 20)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
78

8-
if(NOT CMAKE_BUILD_TYPE)
9-
set(CMAKE_BUILD_TYPE "Release")
9+
if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
10+
set(CMAKE_BUILD_TYPE Release)
1011
endif()
1112

12-
# BUILD EXTERNAL LIBRARIES
13-
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
14-
ExternalProject_Add(SFML
15-
#GIT_REPOSITORY https://github.com/SFML/SFML.git GIT_TAG 2.5.1
16-
SOURCE_DIR ${CMAKE_SOURCE_DIR}/ext/SFML
17-
CMAKE_ARGS
18-
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
19-
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
20-
ExternalProject_Get_Property(SFML INSTALL_DIR)
21-
set(SFML_LIB ${INSTALL_DIR})
22-
23-
ExternalProject_Add(TinyXml2
24-
#GIT_REPOSITORY https://github.com/leethomason/tinyxml2.git
25-
SOURCE_DIR ${CMAKE_SOURCE_DIR}/ext/tinyxml2
26-
CMAKE_ARGS
27-
-DBUILD_TESTS=OFF
28-
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
29-
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>)
30-
ExternalProject_Get_Property(TinyXml2 INSTALL_DIR)
31-
set(TINY_XML_LIB ${INSTALL_DIR})
32-
33-
link_directories(${SFML_LIB}/lib ${TINY_XML_LIB}/lib)
13+
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
14+
3415

3516
set(MARIO_SOURCE_DIR ${CMAKE_SOURCE_DIR}/source)
3617

18+
19+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/source/game_framework)
20+
3721
set(SOURCE
38-
${MARIO_SOURCE_DIR}/game_framework/Collisions.cpp
39-
${MARIO_SOURCE_DIR}/game_framework/InputManager.cpp
40-
${MARIO_SOURCE_DIR}/game_framework/TimerManager.cpp
41-
${MARIO_SOURCE_DIR}/game_framework/GameObject.cpp
42-
${MARIO_SOURCE_DIR}/game_framework/Property.cpp
43-
${MARIO_SOURCE_DIR}/game_framework/StateMachine.cpp
44-
${MARIO_SOURCE_DIR}/game_framework/Logger.cpp
45-
${MARIO_SOURCE_DIR}/game_framework/Rect.cpp
46-
${MARIO_SOURCE_DIR}/game_framework/Vector.cpp
47-
${MARIO_SOURCE_DIR}/utils/Format.cpp
4822
${MARIO_SOURCE_DIR}/Blocks.cpp
4923
${MARIO_SOURCE_DIR}/GameEngine.cpp
5024
${MARIO_SOURCE_DIR}/Items.cpp
@@ -71,18 +45,6 @@ set(SOURCE
7145
)
7246

7347
set(HEADERS
74-
${MARIO_SOURCE_DIR}/game_framework/Collisions.hpp
75-
${MARIO_SOURCE_DIR}/game_framework/InputManager.hpp
76-
${MARIO_SOURCE_DIR}/game_framework/TimerManager.hpp
77-
${MARIO_SOURCE_DIR}/game_framework/GameObject.hpp
78-
${MARIO_SOURCE_DIR}/game_framework/Logger.hpp
79-
${MARIO_SOURCE_DIR}/game_framework/Property.hpp
80-
${MARIO_SOURCE_DIR}/game_framework/Rect.hpp
81-
${MARIO_SOURCE_DIR}/game_framework/StateMachine.hpp
82-
${MARIO_SOURCE_DIR}/game_framework/ResourceManager.hpp
83-
${MARIO_SOURCE_DIR}/game_framework/Vector.hpp
84-
${MARIO_SOURCE_DIR}/utils/Format.hpp
85-
${MARIO_SOURCE_DIR}/utils/RTIIX.hpp
8648
${MARIO_SOURCE_DIR}/Character.hpp
8749
${MARIO_SOURCE_DIR}/TileMap.hpp
8850
${MARIO_SOURCE_DIR}/Blocks.hpp
@@ -112,7 +74,13 @@ set(HEADERS
11274
)
11375

11476
# Target
115-
add_executable(SuperMario ${SOURCE} ${HEADERS})
77+
add_executable(SuperMario)
78+
79+
target_sources(SuperMario
80+
PRIVATE
81+
${SOURCE}
82+
${HEADERS}
83+
)
11684

11785
# Include directories
11886
target_include_directories(SuperMario
@@ -121,10 +89,6 @@ target_include_directories(SuperMario
12189
${MARIO_SOURCE_DIR}/enemies
12290
${MARIO_SOURCE_DIR}/game_framework
12391
${MARIO_SOURCE_DIR}/pickups
124-
${MARIO_SOURCE_DIR}/utils
125-
${CMAKE_SOURCE_DIR}/include
126-
${SFML_LIB}/include
127-
${TINY_XML_LIB}/include
12892
)
12993

13094
if (MSVC)
@@ -133,43 +97,21 @@ if (MSVC)
13397
set_target_properties( SuperMario PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/Build")
13498
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
13599

136-
file(GLOB_RECURSE GAME_FILES CONFIGURE_DEPENDS
137-
"${CMAKE_SOURCE_DIR}/source/*.cpp"
138-
"${CMAKE_SOURCE_DIR}/source/*.c"
139-
"${CMAKE_SOURCE_DIR}/source/*.hpp"
140-
"${CMAKE_SOURCE_DIR}/source/*.h"
141-
)
142-
143-
source_group(TREE "${CMAKE_SOURCE_DIR}/source" FILES ${GAME_FILES})
144-
100+
source_group(TREE "${MARIO_SOURCE_DIR}" FILES ${SOURCE} ${HEADERS})
145101

146102
endif(MSVC)
147103

148-
# ADD DEPENDISIES FOR EXECUTABLE
149-
add_dependencies(SuperMario SFML TinyXml2)
150-
151-
#find_library(MYLIB1 NAMES mylibrary1 PATHS /path/to/libraries REQUIRED)
152-
153104
target_link_libraries(SuperMario
154-
optimized sfml-system debug sfml-system-d
155-
optimized sfml-window debug sfml-window-d
156-
optimized sfml-graphics debug sfml-graphics-d
157-
optimized sfml-audio debug sfml-audio-d
158-
optimized tinyxml2 debug tinyxml2d
105+
PRIVATE
106+
game-framework
159107
)
160108

161109
if (UNIX AND NOT APPLE)
162110
target_link_libraries(SuperMario stdc++ m pthread)
163111
endif()
164112

165-
# POST BUILD SCRIPTS
166-
set(POST_LIB_DIR "lib")
167-
if (WIN32)
168-
set(POST_LIB_DIR "bin")
169-
endif()
170-
171-
ADD_CUSTOM_COMMAND(TARGET SuperMario POST_BUILD
172-
COMMAND ${CMAKE_COMMAND} -E copy_directory "${SFML_LIB}/${POST_LIB_DIR}" "${CMAKE_CURRENT_BINARY_DIR}"
173-
COMMAND ${CMAKE_COMMAND} -E copy_directory "${TINY_XML_LIB}/${POST_LIB_DIR}" "${CMAKE_CURRENT_BINARY_DIR}"
174-
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/res" "${CMAKE_CURRENT_BINARY_DIR}/res")
175-
113+
add_custom_command(TARGET SuperMario POST_BUILD
114+
COMMAND "${CMAKE_COMMAND}" -E copy_directory
115+
"${CMAKE_SOURCE_DIR}/res"
116+
"$<TARGET_FILE_DIR:SuperMario>/res"
117+
)

cmake/SFML3.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Simple FetchContent for SFML 3.x
2+
include(FetchContent)
3+
4+
set(SFML2_TAG "3.0.1" CACHE STRING "SFML 2.x tag to fetch")
5+
6+
set(SFML_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
7+
set(SFML_BUILD_DOC OFF CACHE BOOL "" FORCE)
8+
# set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
9+
10+
FetchContent_Declare(
11+
sfml3
12+
GIT_REPOSITORY https://github.com/SFML/SFML.git
13+
GIT_TAG ${SFML2_TAG}
14+
)
15+
16+
# Download and build
17+
FetchContent_MakeAvailable(sfml3)
18+
19+
add_library(SFML3::all INTERFACE IMPORTED)
20+
target_link_libraries(SFML3::all INTERFACE
21+
sfml-graphics
22+
sfml-audio
23+
# sfml-network
24+
)
25+

cmake/TinyXML2.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Simple FetchContent for tinyxml2
2+
include(FetchContent)
3+
4+
set(TINYXML2_TAG "10.0.0" CACHE STRING "tinyxml2 tag to fetch")
5+
6+
set(BUILD_TESTS OFF CACHE BOOL "" FORCE)
7+
8+
FetchContent_Declare(
9+
tinyxml2
10+
GIT_REPOSITORY https://github.com/leethomason/tinyxml2.git
11+
GIT_TAG ${TINYXML2_TAG}
12+
)
13+
14+
# Download and build
15+
FetchContent_MakeAvailable(tinyxml2)
16+
17+
add_library(TinyXML2::TinyXML2 ALIAS tinyxml2)

ext/SFML

Lines changed: 0 additions & 1 deletion
This file was deleted.

ext/tinyxml2

Lines changed: 0 additions & 1 deletion
This file was deleted.

readme.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# SuperMarioHD
1+
# SuperMarioHD
2+
![Build](https://github.com/andriy-parfenyuk/supermariohd/actions/workflows/win-build.yml/badge.svg)
23
![MARIO logo](https://github.com/PfAndrey/supermariohd/blob/master/res/Screen.jpg?raw=true)
34
Cross-platform HD remake of Super Mario Bros. (NES, 1985).
45
Project was created for learning purposes only.
@@ -14,12 +15,9 @@ Visual Studio Community: https://visualstudio.microsoft.com/downloads/ or MinGW
1415
**3. Install CMake:**
1516
https://cmake.org/download
1617

17-
**4. Install OpenAL:**
18-
https://www.openal.org/downloads
19-
20-
**5. Open git-bash and type:**
18+
**4. Open git-bash and type:**
2119
```console
22-
git clone https://github.com/PfAndrey/supermariohd.git --recursive
20+
git clone https://github.com/PfAndrey/supermariohd.git
2321
cd supermariohd
2422
mkdir build && cd build
2523
cmake ..
@@ -40,7 +38,7 @@ sudo apt-get -y install libx11-dev libudev-dev xorg-dev freeglut3-dev libalut-de
4038

4139
**3. download mario repo**
4240
```console
43-
git clone https://github.com/PfAndrey/supermariohd.git --recursive
41+
git clone https://github.com/PfAndrey/supermariohd.git
4442
```
4543

4644
**4. build project**

0 commit comments

Comments
 (0)