From 76572492872e0f27e64cf861545fe81d7d020726 Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 16 Mar 2026 11:55:10 +0100 Subject: [PATCH] first commit sfml template --- .gitignore | 45 ++++++++ .vscode/c_cpp_properties.json | 30 +++++ .vscode/launch.json | 47 ++++++++ .vscode/settings.json | 25 ++++ .vscode/tasks.json | 102 +++++++++++++++++ CMakeLists.txt | 58 ++++++++++ README.md | 208 ++++++++++++++++++++++++++++++++++ src/main.cpp | 30 +++++ 8 files changed, 545 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc43b26 --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +# Build directories +build/ +cmake-build-*/ +*.exe +*.o +*.obj + +# CMake +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +Makefile +*.cmake +!CMakeLists.txt + +# VSCodium / VSCode +*.code-workspace +.vscode/.history + +# OS specific +.DS_Store +Thumbs.db + +# Compiler outputs +*.dll +*.so +*.dylib +*.a + +# Debug files +*.pdb +*.ilk + +# IDE specific +.idea/ +*.suo +*.user +*.userosscache +*.sln.docstates + +# Temporary files +*.tmp +*.log +*.swp +*~ diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..621c2ce --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,30 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**", + "C:/msys64/mingw64/include" + ], + "defines": [], + "compilerPath": "C:/msys64/mingw64/bin/g++.exe", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "gcc-x64" + }, + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**", + "/usr/include", + "/usr/local/include" + ], + "defines": [], + "compilerPath": "/usr/bin/g++", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "gcc-x64" + } + ], + "version": 4 +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..96873fc --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,47 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug (Windows)", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/bin/StrategyGame.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "C:/msys64/mingw64/bin/gdb.exe", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "CMake: Build" + }, + { + "name": "Debug (Linux)", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/bin/StrategyGame", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "CMake: Build" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8369830 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,25 @@ +{ + "terminal.integrated.profiles.windows": { + "MSYS2 MinGW64": { + "path": "C:\\msys64\\usr\\bin\\bash.exe", + "args": [ + "--login", + "-i" + ], + "env": { + "MSYSTEM": "MINGW64", + "CHERE_INVOKING": "1", + "MSYS2_PATH_TYPE": "inherit" + } + }, + "PowerShell": { + "path": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", + "args": ["-NoLogo"] + } + }, + "terminal.integrated.defaultProfile.windows": "MSYS2 MinGW64", + "files.associations": { + "*.hpp": "cpp", + "*.cpp": "cpp" + } +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..c4b5206 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,102 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "CMake: Configure", + "type": "shell", + "command": "cmake", + "args": [ + "-B", + "build", + "-S", + ".", + "-G", + "Unix Makefiles" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "label": "CMake: Build", + "type": "shell", + "command": "cmake", + "args": [ + "--build", + "build", + "--config", + "Debug" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "group": { + "kind": "build", + "isDefault": true + }, + "dependsOn": ["CMake: Configure"], + "problemMatcher": ["$gcc"] + }, + { + "label": "CMake: Clean", + "type": "shell", + "command": "cmake", + "args": [ + "--build", + "build", + "--target", + "clean" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "label": "Run Game", + "type": "shell", + "windows": { + "command": "${workspaceFolder}/build/bin/StrategyGame.exe" + }, + "linux": { + "command": "${workspaceFolder}/build/bin/StrategyGame" + }, + "options": { + "cwd": "${workspaceFolder}" + }, + "dependsOn": ["CMake: Build"], + "group": { + "kind": "test", + "isDefault": true + }, + "problemMatcher": [] + }, + { + "label": "Clean Build Directory", + "type": "shell", + "windows": { + "command": "Remove-Item", + "args": [ + "-Path", + "build", + "-Recurse", + "-Force", + "-ErrorAction", + "SilentlyContinue" + ] + }, + "linux": { + "command": "rm", + "args": [ + "-rf", + "build" + ] + }, + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + } + ] +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1fe9d5b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 3.16) +project(StrategyGame LANGUAGES CXX) + +# C++ Standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Build type +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Debug) +endif() + +# Output directory +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +# Find SFML +find_package(SFML 3 COMPONENTS Graphics Window System Network REQUIRED) + +# Source files +set(SOURCES + src/main.cpp +) + +# Create executable +add_executable(${PROJECT_NAME} ${SOURCES}) + +# Link SFML +target_link_libraries(${PROJECT_NAME} PRIVATE + SFML::Graphics + SFML::Window + SFML::System + SFML::Network +) + +# Windows specific: Copy DLLs to output directory +if(WIN32) + # Copy SFML DLLs after build + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + $ + $ + $ + ) +endif() + +# Enable more warnings +if(MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W4) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic) +endif() + +# Print build info +message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") +message(STATUS "C++ standard: ${CMAKE_CXX_STANDARD}") +message(STATUS "SFML version: ${SFML_VERSION}") \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..14ced1c --- /dev/null +++ b/README.md @@ -0,0 +1,208 @@ +# SFML Strategy Game - CMake Setup + +Dieses Projekt nutzt **CMake** für plattformunabhängiges Bauen mit SFML 3.x. + +## Voraussetzungen + +### Windows + +1. **MSYS2 installieren** + - Download: https://www.msys2.org/ + - Installiere nach `C:\msys64` (Standard) + - Nach Installation: MSYS2 MINGW64 Terminal öffnen + +2. **Pakete installieren** + ```bash + pacman -Syu + pacman -S mingw-w64-x86_64-gcc + pacman -S mingw-w64-x86_64-sfml + pacman -S mingw-w64-x86_64-cmake + pacman -S mingw-w64-x86_64-gdb + pacman -S make + ``` + +3. **VSCodium / VS Code** + - Installiere VSCodium oder VS Code + - Installiere Extensions: + - `C/C++` (Microsoft) + - `CMake Tools` (optional, aber empfohlen) + - `cppdbg` (für Debugging) + +### Linux (Ubuntu/Debian) + +1. **Pakete installieren** + ```bash + sudo apt update + sudo apt install build-essential + sudo apt install cmake + sudo apt install libsfml-dev + sudo apt install gdb + ``` + +2. **VSCodium / VS Code** + - Installiere VSCodium oder VS Code + - Installiere Extensions: + - `C/C++` (Microsoft) + - `CMake Tools` (optional) + - `cppdbg` (für Debugging) + +## Projekt Setup + +### Mit VSCodium (empfohlen) + +1. **Projekt öffnen** in VSCodium + +2. **Bauen:** + - Drücke `Ctrl+Shift+B` → Wähle "CMake: Build" + - Oder einfach `Ctrl+Shift+B` (Standard Build-Task) + +3. **Ausführen:** + - `Ctrl+Shift+P` → "Tasks: Run Test Task" + - Oder `F5` zum Debuggen + +### Manuell (Terminal) + +**Konfigurieren:** +```bash +cmake -B build -S . +``` + +**Bauen:** +```bash +cmake --build build +``` + +**Ausführen:** + +Windows (MSYS2): +```bash +./build/bin/StrategyGame.exe +``` + +Linux: +```bash +./build/bin/StrategyGame +``` + +## Projekt-Struktur + +``` +projekt/ +├── CMakeLists.txt # CMake Konfiguration +├── .vscode/ +│ ├── tasks.json # Build-Tasks +│ ├── launch.json # Debug-Konfiguration +│ ├── c_cpp_properties.json +│ └── settings.json # Terminal-Einstellungen +├── src/ +│ └── main.cpp # Haupt-Spielcode +├── build/ # Generierter Build-Ordner +│ └── bin/ # Kompilierte Executable +└── README.md +``` + +## Debugging + +### Breakpoints setzen +- Klicke links neben die Zeilennummer (roter Punkt) + +### Debugging starten +- `F5` - Start Debugging +- `F10` - Step Over +- `F11` - Step Into +- `Shift+F11` - Step Out +- `Shift+F5` - Stop + +## Build-Typen + +**Debug (Standard):** +```bash +cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug +cmake --build build +``` + +**Release (optimiert):** +```bash +cmake -B build -S . -DCMAKE_BUILD_TYPE=Release +cmake --build build +``` + +## DLL-Verwaltung (Windows) + +CMake kopiert **automatisch** alle benötigten SFML-DLLs in den `build/bin/` Ordner! + +Kein manuelles Kopieren nötig. 🎉 + +## Distribution / Release + +### Windows + +**Release bauen:** +```bash +cmake -B build -S . -DCMAKE_BUILD_TYPE=Release +cmake --build build --config Release +``` + +Der `build/bin/` Ordner enthält dann: +- `StrategyGame.exe` +- Alle benötigten `.dll` Dateien + +→ Diesen Ordner verteilen! + +### Linux + +```bash +cmake -B build -S . -DCMAKE_BUILD_TYPE=Release +cmake --build build +``` + +Die Executable ist in `build/bin/StrategyGame`. + +## Troubleshooting + +### Windows: CMake not found +```bash +# In MSYS2 MINGW64: +pacman -S mingw-w64-x86_64-cmake +``` + +### Linux: SFML not found +```bash +sudo apt install libsfml-dev +``` + +### "No such file or directory" beim Build +- Stelle sicher, dass du im Projekt-Root-Verzeichnis bist +- `CMakeLists.txt` muss im aktuellen Verzeichnis sein + +### Build-Ordner aufräumen +```bash +rm -rf build +cmake -B build -S . +cmake --build build +``` + +## Nützliche CMake-Befehle + +```bash +# Neukonfigurieren +cmake -B build -S . + +# Bauen (verbose) +cmake --build build --verbose + +# Nur bestimmtes Target bauen +cmake --build build --target StrategyGame + +# Clean +cmake --build build --target clean + +# Kompletter Rebuild +rm -rf build && cmake -B build -S . && cmake --build build +``` + +## Nützliche Links + +- CMake Dokumentation: https://cmake.org/documentation/ +- SFML Dokumentation: https://www.sfml-dev.org/documentation/3.0.0/ +- SFML mit CMake: https://www.sfml-dev.org/tutorials/3.0/compile-with-cmake.php diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..263ec92 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,30 @@ +#include +#include + +int main() { + // Create window with SFML 3.x syntax + sf::RenderWindow window(sf::VideoMode({800, 600}), "SFML Game"); + window.setFramerateLimit(60); + + // Simple green circle for testing + sf::CircleShape shape(50.f); + shape.setFillColor(sf::Color::Green); + shape.setPosition({350.f, 200.f}); + + // Main game loop + while (window.isOpen()) { + // Event handling (SFML 3.x style) + while (auto event = window.pollEvent()) { + if (event->is()) { + window.close(); + } + } + + // Clear, draw, display + window.clear(sf::Color::Black); + window.draw(shape); + window.display(); + } + + return 0; +}