From 652dcd6c2f823b01332673e0febef1c91f5c9bd9 Mon Sep 17 00:00:00 2001 From: Alfred Burgess <alfred.burgess95@gmail.com> Date: Mon, 4 Dec 2023 21:45:00 +0800 Subject: [PATCH] Got SDL2 working with makefile --- .gitignore | 4 ++++ include/main.h | 3 +++ makefile | 11 +++++++++-- src/main.cpp | 17 +++++++++++++++-- src/save-manager.cpp | 2 +- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index dd654e5..99b9f78 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,9 @@ game bin/ +# Libraries +libs/ + # Build directory build/ @@ -32,6 +35,7 @@ build/ # Visual Studio Code specific files .vscode/ + # CMake files CMakeFiles/ CMakeCache.txt diff --git a/include/main.h b/include/main.h index efab701..d402445 100644 --- a/include/main.h +++ b/include/main.h @@ -4,6 +4,9 @@ #include <iostream> #include <cstdint> +#define SDL_MAIN_HANDLED +#include <SDL.h> + enum GenerationMethod { Random diff --git a/makefile b/makefile index 0a14e43..aef12b9 100644 --- a/makefile +++ b/makefile @@ -21,6 +21,12 @@ TEST_DIR = test # Executable directory BIN_DIR = bin +# SDL Inclusions +SDL_INCLUDE = -IC:/dev/SDL2/x86_64-w64-mingw32/include/SDL2 +SDL_LIBRARY = -LC:/dev/SDL2/x86_64-w64-mingw32/lib +SDL_OPTIONS = -lSDL2main -lSDL2 +# SDL_OPTIONS = -lmingw32 -lSDL2main -lSDL2 + # Source files SRC_FILES = $(wildcard $(SRC_DIR)/**/*.cpp $(SRC_DIR)/*.cpp ) SRC_FILES_ = $(wildcard $(SRC_DIR)/*.cpp) @@ -37,11 +43,12 @@ TARGET = $(BIN_DIR)/game all: $(TARGET) $(TARGET): $(OBJ_FILES) - $(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJ_FILES) + $(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJ_FILES) $(SDL_LIBRARY) $(SDL_OPTIONS) $(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp @mkdir -p $(@D) - $(CXX) $(CXXFLAGS) -I$(INC_DIR) -c -o $@ $< + $(CXX) $(CXXFLAGS) ${SDL_INCLUDE} -I$(INC_DIR) -c -o $@ $< +# $(CXX) $(CXXFLAGS) -I$(INC_DIR) -c -o $@ $< clean: rm -rf $(BIN_DIR)/* $(BUILD_DIR)/* test_runnr diff --git a/src/main.cpp b/src/main.cpp index 8dd269c..573b2b1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,9 @@ #include "main.h" -int main() { +int main( int argc, char* argv[] ) { + const uint16_t SCREEN_HEIGHT = 600; + const uint16_t SCREEN_WIDTH = 800; GameState state = Uninitialised; @@ -12,7 +14,17 @@ int main() { state = Initialise; // Seed the random number generator srand(static_cast<unsigned int>(time(nullptr))); - + + SDL_Window* window = NULL; + SDL_Surface* screenSurface = NULL; + + //Initialize SDL + //if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) + //{ + //// printf( "SDL could not initialize! SDL_Error: \n%s\n", SDL_GetError() ); + //} + window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); + // Genrate a Random chunk WorldHex2D map( 5 ); //Chunk* chunk = new Chunk( 0, 0, 0); @@ -51,3 +63,4 @@ int main() { logger.info( "Process Ending" ); return 0; } +// int /*WINAPI*/ WinMain(/*HINSTANCE hInstance, HINSTANCE, LPSTR, int*/) { main(); return 0; } diff --git a/src/save-manager.cpp b/src/save-manager.cpp index 3b280d0..19baa07 100644 --- a/src/save-manager.cpp +++ b/src/save-manager.cpp @@ -48,7 +48,7 @@ void SaveManager::findSaves() for( const auto& entry : std::filesystem::directory_iterator( SAVE_LOCATION ) ) { - saves.push_back( SaveItem(entry.path().filename() ) ); + // saves.push_back( SaveItem(entry.path().filename() ) ); } this->saves = saves; } -- GitLab