From e6df94dac0f6982232f0d2490938d6cf52dd18fc Mon Sep 17 00:00:00 2001 From: Madthijs Date: Sun, 11 Apr 2021 14:07:16 +0200 Subject: [PATCH] First compile, Logger works --- .gitignore | 1 + .vscode/settings.json | 66 +++++++++++++++++++++ AerofoilPortable/GpSystemServices_POSIX.cpp | 16 +++++ AerofoilX/GpFileSystem_X.cpp | 11 +++- AerofoilX/GpMain_SDL_X.cpp | 8 ++- AerofoilX/GpSystemServices_X.cpp | 6 ++ CMakeLists.txt | 20 +++++-- PortabilityLayer/BinarySearch.h | 3 + 8 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 4803db3..26cb720 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ SDL2-2.0.12/Makefile.rules SDL2-2.0.12/sdl2.pc SDL2-2.0.12/sdl2-config install_manifest.txt +AerofoilMac diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a184b52 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,66 @@ +{ + "files.associations": { + "iostream": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "complex": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "map": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "regex": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "ranges": "cpp", + "shared_mutex": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/AerofoilPortable/GpSystemServices_POSIX.cpp b/AerofoilPortable/GpSystemServices_POSIX.cpp index dbfac09..f14ea22 100644 --- a/AerofoilPortable/GpSystemServices_POSIX.cpp +++ b/AerofoilPortable/GpSystemServices_POSIX.cpp @@ -6,6 +6,10 @@ #include #include +#ifdef __MACOS__ +#include +#endif + GpSystemServices_POSIX::GpSystemServices_POSIX() { } @@ -44,7 +48,19 @@ IGpThreadEvent *GpSystemServices_POSIX::CreateThreadEvent(bool autoReset, bool s uint64_t GpSystemServices_POSIX::GetFreeMemoryCosmetic() const { + #ifdef __MACOS__ + { /* This works on *bsd and darwin. */ + unsigned int usermem; + size_t len = sizeof usermem; + static int mib[2] = { CTL_HW, HW_USERMEM }; + + if (sysctl (mib, 2, &usermem, &len, NULL, 0) == 0 + && len == sizeof (usermem)) + return (long) usermem; + } + #else long pages = sysconf(_SC_AVPHYS_PAGES); long pageSize = sysconf(_SC_PAGE_SIZE); return pages * pageSize; + #endif } diff --git a/AerofoilX/GpFileSystem_X.cpp b/AerofoilX/GpFileSystem_X.cpp index f076bd1..ada9d4e 100644 --- a/AerofoilX/GpFileSystem_X.cpp +++ b/AerofoilX/GpFileSystem_X.cpp @@ -9,8 +9,13 @@ #include "PLDrivers.h" +#ifdef __MACOS__ +#include +#include +#else #include "SDL2/SDL.h" #include "SDL2/SDL_rwops.h" +#endif #include #include @@ -22,7 +27,7 @@ #include "UTF8.h" -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MACOS__) typedef off_t off64_t; #define fstat64 fstat #define fseek64 fseek @@ -183,6 +188,9 @@ bool GpFileSystem_X::ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDir case PortabilityLayer::VirtualDirectories::kFontCache: prefsAppend = "FontCache"; break; + case PortabilityLayer::VirtualDirectories::kLogs: + prefsAppend = ".."; + break; default: return false; }; @@ -289,6 +297,7 @@ GpIOStream *GpFileSystem_X::OpenFileNested(PortabilityLayer::VirtualDirectory_t return nullptr; std::string resolvedPath; + if (!ResolvePath(virtualDirectory, subPaths, numSubPaths, resolvedPath)) return nullptr; diff --git a/AerofoilX/GpMain_SDL_X.cpp b/AerofoilX/GpMain_SDL_X.cpp index 3537207..7f76d72 100644 --- a/AerofoilX/GpMain_SDL_X.cpp +++ b/AerofoilX/GpMain_SDL_X.cpp @@ -26,15 +26,17 @@ IGpDisplayDriver *GpDriver_CreateDisplayDriver_SDL_GL2(const GpDisplayDriverProp IGpAudioDriver *GpDriver_CreateAudioDriver_SDL(const GpAudioDriverProperties &properties); IGpInputDriver *GpDriver_CreateInputDriver_SDL2_Gamepad(const GpInputDriverProperties &properties); - +#ifdef __MACOS__ +int main(int argc, char *argv[]) +#else SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]) +#endif { - GpLogDriver_X::Init(); - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) return -1; GpFileSystem_X::GetInstance()->Init(); + GpLogDriver_X::Init(); IGpLogDriver *logger = GpLogDriver_X::GetInstance(); GpDriverCollection *drivers = GpAppInterface_Get()->PL_GetDriverCollection(); diff --git a/AerofoilX/GpSystemServices_X.cpp b/AerofoilX/GpSystemServices_X.cpp index ed1401a..933c46d 100644 --- a/AerofoilX/GpSystemServices_X.cpp +++ b/AerofoilX/GpSystemServices_X.cpp @@ -2,7 +2,13 @@ #include "IGpClipboardContents.h" #include "IGpThreadEvent.h" + +#ifdef __MACOS__ +#include +#include +#else #include "SDL2/SDL.h" +#endif #include #include diff --git a/CMakeLists.txt b/CMakeLists.txt index 592cb6b..ed16c19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,23 @@ cmake_minimum_required(VERSION 3.10) - project (Aerofoil) +SET(PLATFORM "X" CACHE STRING "Defines the target platform") +SET(EXECNAME "AerofoilX" CACHE STRING "Defines the exec name") message(${CMAKE_BINARY_DIR}) find_package(SDL2 REQUIRED) +if(PLATFORM STREQUAL "MAC") + SET(EXECNAME "AerofoilMac" CACHE STRING "Defines the exec name" FORCE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + add_definitions(-D__MACOS__) +endif() + +message("Building ${EXECNAME} for: ${PLATFORM}") + add_definitions(-DGP_DEBUG_CONFIG=0) + add_library(stb STATIC stb/stb_image_write.c ) @@ -231,7 +241,7 @@ target_include_directories(GpApp PRIVATE target_link_libraries(GpApp PortabilityLayer) if(CMAKE_HOST_UNIX) - add_executable(AerofoilX + add_executable(${EXECNAME} AerofoilPortable/GpSystemServices_POSIX.cpp AerofoilPortable/GpThreadEvent_Cpp11.cpp AerofoilSDL/GpAudioDriver_SDL2.cpp @@ -248,7 +258,7 @@ if(CMAKE_HOST_UNIX) AerofoilX/GpFileSystem_X.cpp ) - target_include_directories(AerofoilX PRIVATE + target_include_directories(${EXECNAME} PRIVATE $ $ $ @@ -258,8 +268,8 @@ if(CMAKE_HOST_UNIX) ${SDL2_INCLUDE_DIRS} ) - target_link_libraries(AerofoilX ${SDL2_LIBRARIES} GpApp GpShell) + target_link_libraries(${EXECNAME} ${SDL2_LIBRARIES} GpApp GpShell) endif() -install (TARGETS AerofoilX) +install (TARGETS ${EXECNAME}) diff --git a/PortabilityLayer/BinarySearch.h b/PortabilityLayer/BinarySearch.h index ca52557..6f9f393 100644 --- a/PortabilityLayer/BinarySearch.h +++ b/PortabilityLayer/BinarySearch.h @@ -3,6 +3,9 @@ #define __PL_BINARY_SEARCH_H__ #include +#ifdef __MACOS__ +#include +#endif namespace PortabilityLayer {