diff --git a/.gitignore b/.gitignore index 47b965b..f55728e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -build +/build* docs/html diff --git a/BUILDING b/BUILDING index 0fe4c36..09a2936 100644 --- a/BUILDING +++ b/BUILDING @@ -1,17 +1,44 @@ How to build cerritos 1. Install dependencies -cmake libsdl2 doxygen graphviz libsdl2-image-dev libsdl2-ttf-dev +Linux (package names may vary), in Terminal: +> {your packager} libsdl2 doxygen graphviz libsdl2-image-dev libsdl2-ttf-dev freealut-dev + +macOS: +Get XCode: https://developer.apple.com/support/xcode/ +Get Homebrew via https://brew.sh/; then, in Terminal: +> brew install sdl2 doxygen graphviz sdl2_image sdl2_ttf freealut + +Windows: +Install Visual Studio, for example the 2022 Community Edition: https://visualstudio.microsoft.com/de/vs/community/ +Only the C++ Desktop Development package should be required. +In cmd (all a bit more involved as Windows is lacking some basic tools): +> winget install Git.Git +> winget install cmake +> winget install python +optional: Visual Studio Code editor, not required for building: +> winget install code + +disable python alias via Settings -> Manage App Execution Aliases (use search) +DO NOT install Microsoft store version of python, its path settings seem broken + +In Git Bash (installed with git), install pip (https://pip.pypa.io/en/stable/installation/) +> py -m ensurepip --upgrade +then install conan over pip (https://docs.conan.io/en/2.0/installation.html): +> pip install conan --upgrade 2. Create build directory -mkdir build -cd build +> mkdir build +> cd build + +3: Get Dependencies via Conan (Optional on Linux and macOS if nothing went wrong in step 1, required on Windows): +> conan install .. --build=missing -3. Run cmake -cmake ../ +4. Run cmake +> cmake .. -4. Build! -make +5. Build! +> cmake --build . TODO: Make this document a lot more detailed. diff --git a/CMakeLists.txt b/CMakeLists.txt index 05a1254..4805b38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,17 +6,34 @@ cmake_minimum_required(VERSION 3.10) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# create .lib file on Windows (alternative: export specifically all desired symbols with dllexport, make that a NOP on Unix platforms) +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + # set the project name project(cerritos VERSION 0.1.0) set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) -include(sdl) -INCLUDE(FindPkgConfig) -#find_package(SDL_ttf REQUIRED) -#PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) -PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image) -PKG_SEARCH_MODULE(SDL2TTF REQUIRED SDL2_ttf) +# optionally include conan generated file +set(CONAN_FILE_TO_INCLUDE ${CMAKE_BINARY_DIR}/conan_paths.cmake) +if(EXISTS ${CONAN_FILE_TO_INCLUDE}) + include(${CONAN_FILE_TO_INCLUDE}) +endif() + +#include(sdl) +find_package(SDL2 REQUIRED) +find_package(SDL2_image REQUIRED) +find_package(SDL2_ttf REQUIRED) +find_package(OpenAL) + +if(OPENAL_FOUND) + find_path(ALUT_INCLUDE_DIR + NAMES AL/alut.h) + find_library(ALUT_LIBRARY + NAMES alut + HINTS lib lib64 + PATH /usr /usr/local /opt/local /sw) +endif(OPENAL_FOUND) # The actual cerritos sources add_subdirectory(src) diff --git a/cmake/sdl.cmake b/cmake/sdl.cmake index 18fb4e1..74275ec 100644 --- a/cmake/sdl.cmake +++ b/cmake/sdl.cmake @@ -1,4 +1,4 @@ find_package(SDL2 REQUIRED) -include_directories(${SDL2_INCLUDE_DIRS}) +include_directories(SYSTEM ${SDL2_INCLUDE_DIRS}) diff --git a/conanfile.txt b/conanfile.txt new file mode 100755 index 0000000..3e60ee8 --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,31 @@ +# standard conan instructions? +# make a new build directory, change into it +# install dependencies with +# conan install --build=missing + +[requires] +sdl/[^2.0,>=2.0.14] +sdl_ttf/[^2.0,>=2.0.15] +sdl_image/[^2.0,>=2.0.5] + +# conflict resolution +libpng/[^1.6] # odd that this is enough, but no complaining +[tool_requires] + +# the conan version of doxygen does not work the way we exect, so don't use it (for now) +#doxygen/[^1.9,<=1.9.2] +# 1.9.4 locks zlib to a higher version than one of its dependencies, causing irresolvable conflicts here + +# graphviz is not in Conan. Figures, it is a perl program. +# Hope it is optional or can be manually installed if needed. + +[generators] +cmake_find_package +cmake_paths +CMakeDeps +CMakeToolchain + +[imports] +# copy macOS and Windows dynamic libraries to where they can be found +bin, *.dll -> ./bin +lib, *.dylib* -> ./bin \ No newline at end of file diff --git a/examples/dadsteroids.cmake b/examples/dadsteroids.cmake index 074adb7..a516825 100644 --- a/examples/dadsteroids.cmake +++ b/examples/dadsteroids.cmake @@ -10,3 +10,10 @@ target_include_directories(dadsteroids PUBLIC target_link_libraries(dadsteroids cerritos ) + +# copy dll on windows into binary directory +if(WIN32) + add_custom_command(TARGET dadsteroids POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ $ + ) +endif(WIN32) diff --git a/examples/dasteroids.cpp b/examples/dasteroids.cpp index 8be9dfa..8ef1730 100644 --- a/examples/dasteroids.cpp +++ b/examples/dasteroids.cpp @@ -83,7 +83,7 @@ class Ship : public Sprite { void Fire() { m_Fired = true; m_Bullet = new Bullet(); - m_Bullet->setBackground(_PATH.getFilepath("share", "bullet.bmp")); + m_Bullet->setBackground(_PATH.getFilepath("share", "bullet.bmp").u8string()); m_Bullet->setPosition(this->getPosition()); m_Bullet->setHeading(this->getHeading()); m_Bullet->setSpeed(2.0); @@ -112,7 +112,7 @@ class ftApplication : public Application { m_Ship = new Ship(getMainWindow()->getWindow(), 200,200, 40, 40, 1 ); - m_Ship->setBackground(_PATH.getFilepath("share", "dadship.png")); + m_Ship->setBackground(_PATH.getFilepath("share", "dadship.png").u8string()); m_Ship->setPosition(200,200); diff --git a/examples/drumTest.cmake b/examples/drumTest.cmake index d3c9fe9..1687f13 100644 --- a/examples/drumTest.cmake +++ b/examples/drumTest.cmake @@ -10,3 +10,10 @@ target_include_directories(drumTest PUBLIC target_link_libraries(drumTest cerritos ) + +# copy dll on windows into binary directory +if(WIN32) + add_custom_command(TARGET drumTest POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ $ + ) +endif(WIN32) diff --git a/examples/eventTest.cmake b/examples/eventTest.cmake index ea856a2..9e378b5 100644 --- a/examples/eventTest.cmake +++ b/examples/eventTest.cmake @@ -10,3 +10,9 @@ target_link_libraries(eventTest cerritos ) +# copy dll on windows into binary directory +if(WIN32) + add_custom_command(TARGET eventTest POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ $ +) +endif(WIN32) diff --git a/examples/fontTest.cmake b/examples/fontTest.cmake index 4a3105d..5f14bc3 100644 --- a/examples/fontTest.cmake +++ b/examples/fontTest.cmake @@ -10,3 +10,10 @@ target_include_directories(fontTest PUBLIC target_link_libraries(fontTest cerritos ) + +# copy dll on windows into binary directory +if(WIN32) + add_custom_command(TARGET fontTest POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ $ + ) +endif(WIN32) diff --git a/examples/hello.cmake b/examples/hello.cmake index 7cd4d9c..acde522 100644 --- a/examples/hello.cmake +++ b/examples/hello.cmake @@ -11,3 +11,9 @@ target_link_libraries(hello cerritos ) +# copy dll on windows into binary directory +if(WIN32) + add_custom_command(TARGET hello POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ $ + ) +endif(WIN32) diff --git a/examples/pathTest.cmake b/examples/pathTest.cmake index 59f2ae5..a2b9323 100644 --- a/examples/pathTest.cmake +++ b/examples/pathTest.cmake @@ -10,3 +10,10 @@ target_include_directories(pathTest PUBLIC target_link_libraries(pathTest cerritos ) + +# copy dll on windows into binary directory +if(WIN32) + add_custom_command(TARGET pathTest POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ $ + ) +endif(WIN32) diff --git a/examples/spriteTest.cmake b/examples/spriteTest.cmake index 7f31ec5..4c674d4 100644 --- a/examples/spriteTest.cmake +++ b/examples/spriteTest.cmake @@ -11,3 +11,9 @@ target_link_libraries(spriteTest cerritos ) +# copy dll on windows into binary directory +if(WIN32) + add_custom_command(TARGET spriteTest POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $ $ + ) +endif(WIN32) diff --git a/examples/spriteTest.cpp b/examples/spriteTest.cpp index a8aa8aa..fb9c700 100644 --- a/examples/spriteTest.cpp +++ b/examples/spriteTest.cpp @@ -108,19 +108,19 @@ int main( int argc, char* args[] ) { theSprite = new Sprite(theWindow->getWindow(), 0, 0, 64, 64, 10); theOtherSprite = new Sprite(theWindow->getWindow(), 250, 250, 64, 64, 1); - List dancing = {_PATH.getFilepath("share", "boimlerdance00.bmp"), - _PATH.getFilepath("share", "boimlerdance01.bmp"), - _PATH.getFilepath("share", "boimlerdance02.bmp"), - _PATH.getFilepath("share", "boimlerdance01.bmp") }; + List dancing = {_PATH.getFilepath("share", "boimlerdance00.bmp").u8string(), + _PATH.getFilepath("share", "boimlerdance01.bmp").u8string(), + _PATH.getFilepath("share", "boimlerdance02.bmp").u8string(), + _PATH.getFilepath("share", "boimlerdance01.bmp").u8string() }; - List walking = {_PATH.getFilepath("share", "boimlerdance10.bmp"), - _PATH.getFilepath("share", "boimlerdance11.bmp"), - _PATH.getFilepath("share", "boimlerdance12.bmp"), - _PATH.getFilepath("share", "boimlerdance13.bmp"), - _PATH.getFilepath("share", "boimlerdance14.bmp"), - _PATH.getFilepath("share", "boimlerdance12.bmp") }; + List walking = {_PATH.getFilepath("share", "boimlerdance10.bmp").u8string(), + _PATH.getFilepath("share", "boimlerdance11.bmp").u8string(), + _PATH.getFilepath("share", "boimlerdance12.bmp").u8string(), + _PATH.getFilepath("share", "boimlerdance13.bmp").u8string(), + _PATH.getFilepath("share", "boimlerdance14.bmp").u8string(), + _PATH.getFilepath("share", "boimlerdance12.bmp").u8string() }; - List ship = {_PATH.getFilepath("share", "spaceship.bmp")}; + List ship = {_PATH.getFilepath("share", "spaceship.bmp").u8string()}; theSprite->addSpriteMode(0, dancing); theSprite->setDefaultMode(1); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24421d4..e0c9038 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -69,11 +69,7 @@ install(FILES DESTINATION include ) -target_include_directories(cerritos PUBLIC - ${SDL2_LIBRARIES} - ${SDL2IMAGE_INCLUDE_DIRS} - ${SDL2TTF_INCLUDE_DIRS} - ${OPENAL_INCLUDE_DIRS} +target_include_directories(cerritos BEFORE PUBLIC . backend core @@ -85,16 +81,36 @@ target_include_directories(cerritos PUBLIC widgets ) -target_link_libraries(cerritos - ${SDL2_LIBRARIES} - ${SDL2IMAGE_LIBRARIES} - ${SDL2TTF_LIBRARIES} - ${OPENAL_LIBRARIES} - alut - stdc++fs - stdc++ +target_include_directories(cerritos SYSTEM PUBLIC + ${SDL2_INCLUDE_DIRS} + ${SDL2IMAGE_INCLUDE_DIRS} + ${SDL2TTF_INCLUDE_DIRS} +) + +target_link_libraries(cerritos PUBLIC + SDL2::SDL2 + SDL2::SDL2main + SDL2_image::SDL2_image + SDL2_ttf::SDL2_ttf + $<$,$,9.1>>:stdc++fs> ) +if(OPENAL_FOUND) + # having this PUBLIC is probably bad style, but the ALUT definitions + # are required in a header right now... + target_compile_definitions(cerritos PUBLIC USING_OPENAL) + + target_include_directories(cerritos SYSTEM PUBLIC + ${OPENAL_INCLUDE_DIR} + ${ALUT_INCLUDE_DIR} + ) + + target_link_libraries(cerritos PUBLIC + ${OPENAL_LIBRARY} + ${ALUT_LIBRARY} + ) +endif(OPENAL_FOUND) + install(TARGETS cerritos EXPORT cerritos LIBRARY DESTINATION lib diff --git a/src/core/imagemanager.cpp b/src/core/imagemanager.cpp index 06f2080..9a9e821 100644 --- a/src/core/imagemanager.cpp +++ b/src/core/imagemanager.cpp @@ -54,7 +54,7 @@ Surface* ImageManager::loadFromFile(const char* filename) { } Surface* ImageManager::loadPath(String searchpath, String filename) { - return loadFromFile(_PATH.getFilepath(searchpath, filename) ); + return loadFromFile(_PATH.getFilepath(searchpath, filename).u8string() ); } Surface* ImageManager::loadFromFile(String filename) { diff --git a/src/core/path.cpp b/src/core/path.cpp index 4f8ece0..9e817b9 100644 --- a/src/core/path.cpp +++ b/src/core/path.cpp @@ -68,7 +68,7 @@ void Path::m_initialize(const char* programName, bool overwrite) { return; if(programName != NULL) { - p_name = Dirpath(programName).filename(); + p_name = Dirpath(programName).filename().u8string(); } else { p_name = getProgramNameFile(); } @@ -184,7 +184,7 @@ void Path::setAssetDir(String newAssetdir) { } String Path::getProgramNameFile() { - return String(m_ProgramName.filename() ); + return m_ProgramName.filename().u8string(); } void Path::setProgramName(String programName) { @@ -204,7 +204,7 @@ void Path::showPaths() { const Dirpath Path::getFilepath(String searchpath, String filename, bool useSysDirs) { if (m_AllPaths.has_key(searchpath)) { // Found the path - return String( (m_AllPaths[searchpath] / filename).c_str() ); + return (m_AllPaths[searchpath] / filename).u8string(); } return String(""); diff --git a/src/core/path.h b/src/core/path.h index 0f7ca3d..835e2a8 100644 --- a/src/core/path.h +++ b/src/core/path.h @@ -78,17 +78,17 @@ class Path { const Dirpath getFilepath(String searchpath, String filename, bool useSysDirs=false); /// Overloaded member for convenience. - String getFilepath(const char* searchpath, const char* filename, bool useSysDirs=false) { + Dirpath getFilepath(const char* searchpath, const char* filename, bool useSysDirs=false) { return getFilepath(String(searchpath), String(filename), useSysDirs); }; /// Overloaded member for convenience. - String getFilepath(String searchpath, const char* filename, bool useSysDirs=false) { + Dirpath getFilepath(String searchpath, const char* filename, bool useSysDirs=false) { return getFilepath(searchpath, String(filename), useSysDirs); }; /// Overloaded member for convenience. - String getFilepath(const char* searchpath, String filename, bool useSysDirs=false) { + Dirpath getFilepath(const char* searchpath, String filename, bool useSysDirs=false) { return getFilepath(String(searchpath), filename, useSysDirs ); }; @@ -108,7 +108,7 @@ class Path { String getAssetDir() { return m_AssetDir; }; - String getAppPath() { return m_AppPath; }; + String getAppPath() { return m_AppPath.u8string(); }; void setPrefix(const char* prefix) { setPrefix(String(prefix) ); diff --git a/src/core/sound.cpp b/src/core/sound.cpp index bb3dd52..a05cff5 100644 --- a/src/core/sound.cpp +++ b/src/core/sound.cpp @@ -4,8 +4,10 @@ using namespace cerritos; Sound::Sound(int numSources) { +#ifdef USING_OPENAL alutInit(NULL, NULL); - +#endif + for (int i = 0; i < numSources; i++) { ALuint buffer; m_Buffers.push_back(buffer); @@ -17,15 +19,21 @@ Sound::Sound(int numSources) { } } Sound::~Sound() { +#ifdef USING_OPENAL alutExit(); +#endif } void Sound::LoadSoundFromFile(const char *filename, int index) { +#ifdef USING_OPENAL m_Buffers[index] = alutCreateBufferFromFile(filename); alGenSources((ALuint)1, &m_Sources[index]); alSourcei(m_Sources[index], AL_BUFFER, m_Buffers[index]); +#endif } void Sound::PlaySound(int index) { +#ifdef USING_OPENAL alSourcePlay(m_Sources[index]); +#endif } diff --git a/src/core/sound.h b/src/core/sound.h index 64d83c8..dc3880c 100644 --- a/src/core/sound.h +++ b/src/core/sound.h @@ -1,4 +1,12 @@ +#ifdef USING_OPENAL #include +#else +// rudimentary type replacements +using ALvoid = void; +using ALuint = unsigned int; +// this probably needs competely different abstractions... good enough for just having sound disabled. +#endif + #include "types.h" namespace cerritos { diff --git a/src/core/types.h b/src/core/types.h index c1e5317..e51d256 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -94,11 +94,7 @@ typedef enum { * typedefs and defines that hopefully provide reasonable cross-platform * strings from the C++ standard library */ -#ifdef _WIN32 -typedef std::wstring String; -#else typedef std::string String; -#endif typedef std::filesystem::path Dirpath; diff --git a/src/thirdparty/binreloc/binreloc.c b/src/thirdparty/binreloc/binreloc.c index 84c22c4..a56b9dc 100644 --- a/src/thirdparty/binreloc/binreloc.c +++ b/src/thirdparty/binreloc/binreloc.c @@ -19,6 +19,8 @@ * 0. You just DO WHAT THE FUCK YOU WANT TO. */ +#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) + #include #include #include @@ -28,7 +30,11 @@ #include #include #include +#ifdef __APPLE__ +#include +#else #include +#endif #include "binreloc.h" @@ -752,3 +758,4 @@ br_dirname (const char *path) return result; } +#endif \ No newline at end of file diff --git a/src/widgets/mainwindow.cpp b/src/widgets/mainwindow.cpp index 504d996..35bfe91 100644 --- a/src/widgets/mainwindow.cpp +++ b/src/widgets/mainwindow.cpp @@ -67,6 +67,13 @@ void cMainWindow::Move() { #endif // USING_SDL } +cMainWindow::cMainWindow(CER_WindowFlags winFlags) : + cMainWindow("Cerritos Window", 800, 600, CER_WindowPos_Centered, CER_WindowPos_Centered, winFlags) { }; +cMainWindow::cMainWindow(String title, CER_WindowFlags winFlags) : + cMainWindow(title, 800, 600, CER_WindowPos_Centered, CER_WindowPos_Centered, winFlags) { }; +cMainWindow::cMainWindow(String title, int width, int height, CER_WindowFlags winFlags) : + cMainWindow(title, 800, 600, CER_WindowPos_Centered, CER_WindowPos_Centered, winFlags) { }; + cMainWindow::cMainWindow(String title, int width, int height, int posx, int posy, CER_WindowFlags winFlags) : cWidget(NULL), m_Title(title), m_Size(width, height), m_Position(posx, posy), diff --git a/src/widgets/mainwindow.h b/src/widgets/mainwindow.h index d694cc3..d08d014 100644 --- a/src/widgets/mainwindow.h +++ b/src/widgets/mainwindow.h @@ -64,12 +64,9 @@ class cMainWindow : public cerritos::cWidget { // Constructors //cMainWindow(); - cMainWindow(CER_WindowFlags winFlags=CER_Shown) : - cMainWindow("Cerritos Window", 800, 600, CER_WindowPos_Centered, CER_WindowPos_Centered, winFlags) { }; - cMainWindow(String title, CER_WindowFlags winFlags=CER_Shown) : - cMainWindow(title, 800, 600, CER_WindowPos_Centered, CER_WindowPos_Centered, winFlags) { }; - cMainWindow(String title, int width, int height, CER_WindowFlags winFlags=CER_Shown) : - cMainWindow(title, 800, 600, CER_WindowPos_Centered, CER_WindowPos_Centered, winFlags) { }; + cMainWindow(CER_WindowFlags winFlags=CER_Shown); + cMainWindow(String title, CER_WindowFlags winFlags=CER_Shown); + cMainWindow(String title, int width, int height, CER_WindowFlags winFlags=CER_Shown); cMainWindow(String title, int width, int height, int posx, int posy, CER_WindowFlags winFlags=CER_Shown); virtual ~cMainWindow();