diff --git a/ion/src/simulator/android/Makefile b/ion/src/simulator/android/Makefile index 952012eff..b3634670d 100644 --- a/ion/src/simulator/android/Makefile +++ b/ion/src/simulator/android/Makefile @@ -1,6 +1,6 @@ ion_src += $(addprefix ion/src/simulator/android/src/cpp/, \ - images.cpp \ haptics_enabled.cpp \ + platform_images.cpp \ ) ion_src += $(addprefix ion/src/simulator/shared/, \ diff --git a/ion/src/simulator/android/src/cpp/images.cpp b/ion/src/simulator/android/src/cpp/platform_images.cpp similarity index 91% rename from ion/src/simulator/android/src/cpp/images.cpp rename to ion/src/simulator/android/src/cpp/platform_images.cpp index 75855a3a0..2b7f92f29 100644 --- a/ion/src/simulator/android/src/cpp/images.cpp +++ b/ion/src/simulator/android/src/cpp/platform_images.cpp @@ -4,7 +4,11 @@ #include #include -SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) { +namespace Ion { +namespace Simulator { +namespace Platform { + +SDL_Texture * loadImage(SDL_Renderer * renderer, const char * identifier) { JNIEnv * env = static_cast(SDL_AndroidGetJNIEnv()); jobject activity = static_cast(SDL_AndroidGetActivity()); @@ -54,3 +58,7 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi env->DeleteLocalRef(activity); return texture; } + +} +} +} diff --git a/ion/src/simulator/ios/Makefile b/ion/src/simulator/ios/Makefile index 35f24e812..6a51f63d3 100644 --- a/ion/src/simulator/ios/Makefile +++ b/ion/src/simulator/ios/Makefile @@ -1,9 +1,9 @@ ion_src += $(addprefix ion/src/simulator/ios/, \ - images.m \ + platform_images.mm \ ) ion_src += $(addprefix ion/src/simulator/shared/, \ - apple/language.m \ + apple/platform_language.mm \ dummy/haptics_enabled.cpp \ dummy/journal.cpp \ dummy/keyboard_callback.cpp \ diff --git a/ion/src/simulator/ios/images.m b/ion/src/simulator/ios/platform_images.mm similarity index 89% rename from ion/src/simulator/ios/images.m rename to ion/src/simulator/ios/platform_images.mm index 6a68fe2c4..3d3bb70b2 100644 --- a/ion/src/simulator/ios/images.m +++ b/ion/src/simulator/ios/platform_images.mm @@ -1,9 +1,12 @@ #include "../shared/platform.h" - #include #include -SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) { +namespace Ion { +namespace Simulator { +namespace Platform { + +SDL_Texture * loadImage(SDL_Renderer * renderer, const char * identifier) { CGImageRef cgImage = [[UIImage imageNamed:[NSString stringWithUTF8String:identifier]] CGImage]; if (cgImage == NULL) { return NULL; @@ -53,3 +56,7 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi return texture; } + +} +} +} diff --git a/ion/src/simulator/linux/Makefile b/ion/src/simulator/linux/Makefile index f1585a6e8..5425edddd 100644 --- a/ion/src/simulator/linux/Makefile +++ b/ion/src/simulator/linux/Makefile @@ -8,9 +8,9 @@ SFLAGS += -DUSING_GENERATED_CONFIG_H SFLAGS += -Iion/src/simulator/linux/include ion_src += $(addprefix ion/src/simulator/linux/, \ - images.cpp \ - language.cpp \ assets.s \ + platform_images.cpp \ + platform_language.cpp \ ) ion_src += $(addprefix ion/src/simulator/shared/, \ @@ -32,13 +32,13 @@ LDFLAGS += -ljpeg $(eval $(call rule_for, \ INCBIN, \ - ion/src/simulator/linux/assets.s ion/src/simulator/linux/images.h, \ + ion/src/simulator/linux/assets.s ion/src/simulator/linux/platform_images.h, \ $(ion_simulator_assets_paths), \ $$(PYTHON) ion/src/simulator/linux/incbin.py $(ion_simulator_assets) -o $$@, \ global \ )) -$(call object_for,ion/src/simulator/linux/images.cpp): $(BUILD_DIR)/ion/src/simulator/linux/images.h +$(call object_for,ion/src/simulator/linux/platform_images.cpp): $(BUILD_DIR)/ion/src/simulator/linux/platform_images.h -# The header is refered to as so make sure it's findable this way +# The header is refered to as so make sure it's findable this way SFLAGS += -I$(BUILD_DIR) diff --git a/ion/src/simulator/linux/images.cpp b/ion/src/simulator/linux/platform_images.cpp similarity index 95% rename from ion/src/simulator/linux/images.cpp rename to ion/src/simulator/linux/platform_images.cpp index dbe94b123..a3ec43760 100644 --- a/ion/src/simulator/linux/images.cpp +++ b/ion/src/simulator/linux/platform_images.cpp @@ -5,7 +5,11 @@ #include #include -#include +#include + +namespace Ion { +namespace Simulator { +namespace Platform { enum class AssetFormat { JPG, @@ -95,7 +99,7 @@ bool readJPG(const unsigned char * start, size_t size, unsigned char ** bitmapDa return true; } -SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) { +SDL_Texture * loadImage(SDL_Renderer * renderer, const char * identifier) { static constexpr const char * jpgExtension = ".jpg"; static constexpr const char * pngExtension = ".png"; @@ -161,3 +165,7 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi return texture; } + +} +} +} diff --git a/ion/src/simulator/linux/language.cpp b/ion/src/simulator/linux/platform_language.cpp similarity index 72% rename from ion/src/simulator/linux/language.cpp rename to ion/src/simulator/linux/platform_language.cpp index dd146e143..81a370de3 100644 --- a/ion/src/simulator/linux/language.cpp +++ b/ion/src/simulator/linux/platform_language.cpp @@ -1,8 +1,11 @@ #include "../shared/platform.h" - #include -char * IonSimulatorGetLanguageCode() { +namespace Ion { +namespace Simulator { +namespace Platform { + +const char * languageCode() { static char buffer[3] = {0}; char * locale = setlocale(LC_ALL, ""); if (locale[2] == '_') { @@ -12,3 +15,7 @@ char * IonSimulatorGetLanguageCode() { } return nullptr; } + +} +} +} diff --git a/ion/src/simulator/macos/Makefile b/ion/src/simulator/macos/Makefile index d35c71b73..238da5daf 100644 --- a/ion/src/simulator/macos/Makefile +++ b/ion/src/simulator/macos/Makefile @@ -1,9 +1,9 @@ ion_src += $(addprefix ion/src/simulator/macos/, \ - images.m \ + platform_images.mm \ ) ion_src += $(addprefix ion/src/simulator/shared/, \ - apple/language.m \ + apple/platform_language.mm \ dummy/haptics_enabled.cpp \ dummy/keyboard_callback.cpp \ dummy/window_callback.cpp \ diff --git a/ion/src/simulator/macos/images.m b/ion/src/simulator/macos/platform_images.mm similarity index 90% rename from ion/src/simulator/macos/images.m rename to ion/src/simulator/macos/platform_images.mm index 03c82ab51..1cf9f61a9 100644 --- a/ion/src/simulator/macos/images.m +++ b/ion/src/simulator/macos/platform_images.mm @@ -3,7 +3,11 @@ #include #include -SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) { +namespace Ion { +namespace Simulator { +namespace Platform { + +SDL_Texture * loadImage(SDL_Renderer * renderer, const char * identifier) { NSImage * nsImage = [NSImage imageNamed:[NSString stringWithUTF8String:identifier]]; CGImageRef cgImage = [nsImage CGImageForProposedRect:NULL context:NULL @@ -55,3 +59,7 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi return texture; } + +} +} +} diff --git a/ion/src/simulator/shared/apple/language.m b/ion/src/simulator/shared/apple/platform_language.mm similarity index 83% rename from ion/src/simulator/shared/apple/language.m rename to ion/src/simulator/shared/apple/platform_language.mm index 1fcefe08b..e765a8af9 100644 --- a/ion/src/simulator/shared/apple/language.m +++ b/ion/src/simulator/shared/apple/platform_language.mm @@ -2,7 +2,11 @@ #include -char * IonSimulatorGetLanguageCode() { +namespace Ion { +namespace Simulator { +namespace Platform { + +const char * languageCode() { static char buffer[4] = {0}; if (buffer[0] == 0) { NSString * preferredLanguage = [[NSLocale preferredLanguages] firstObject]; @@ -15,3 +19,7 @@ char * IonSimulatorGetLanguageCode() { } return buffer; } + +} +} +} diff --git a/ion/src/simulator/shared/layout.cpp b/ion/src/simulator/shared/layout.cpp index df4c7ab88..f3dffd900 100644 --- a/ion/src/simulator/shared/layout.cpp +++ b/ion/src/simulator/shared/layout.cpp @@ -202,9 +202,9 @@ static SDL_Texture * sBackgroundTexture = nullptr; static SDL_Texture * sKeyLayoutTextures[KeyLayout::NumberOfShapes]; void init(SDL_Renderer * renderer) { - sBackgroundTexture = IonSimulatorLoadImage(renderer, "background.jpg"); + sBackgroundTexture = Platform::loadImage(renderer, "background.jpg"); for (size_t i = 0; i < KeyLayout::NumberOfShapes; i++) { - sKeyLayoutTextures[i] = IonSimulatorLoadImage(renderer, KeyLayout::assetName[i]); + sKeyLayoutTextures[i] = Platform::loadImage(renderer, KeyLayout::assetName[i]); } } diff --git a/ion/src/simulator/shared/main.cpp b/ion/src/simulator/shared/main.cpp index 2bf0bd553..c05ac937c 100644 --- a/ion/src/simulator/shared/main.cpp +++ b/ion/src/simulator/shared/main.cpp @@ -4,6 +4,7 @@ #include "random.h" #include "telemetry.h" #include "window.h" +#include #include #include #ifndef __WIN32__ @@ -68,11 +69,13 @@ std::vector::const_iterator Args::find(const char * name) const { ); } +using namespace Ion::Simulator; + int main(int argc, char * argv[]) { Args args(argc, argv); if (!args.has("--language")) { - args.push("--language", IonSimulatorGetLanguageCode()); + args.push("--language", Platform::languageCode()); } #ifndef __WIN32__ @@ -88,7 +91,6 @@ int main(int argc, char * argv[]) { bool headless = args.popFlag("--headless"); - using namespace Ion::Simulator; Random::init(); if (!headless) { Journal::init(); diff --git a/ion/src/simulator/shared/platform.h b/ion/src/simulator/shared/platform.h index e6e13d5e0..ccdff6806 100644 --- a/ion/src/simulator/shared/platform.h +++ b/ion/src/simulator/shared/platform.h @@ -2,20 +2,16 @@ #define ION_SIMULATOR_PLATFORM_H #include -#include -#ifdef __cplusplus -extern "C" { -#endif +namespace Ion { +namespace Simulator { +namespace Platform { -/* Those functions should be implemented per-platform. - * They are defined as C function for easier interop. */ +SDL_Texture * loadImage(SDL_Renderer * renderer, const char * identifier); +const char * languageCode(); -SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier); -char * IonSimulatorGetLanguageCode(); - -#ifdef __cplusplus } -#endif +} +} #endif diff --git a/ion/src/simulator/windows/Makefile b/ion/src/simulator/windows/Makefile index 8456e7c20..563a6fc61 100644 --- a/ion/src/simulator/windows/Makefile +++ b/ion/src/simulator/windows/Makefile @@ -1,6 +1,6 @@ ion_src += $(addprefix ion/src/simulator/windows/, \ - images.cpp \ - language.cpp \ + platform_images.cpp \ + platform_language.cpp \ resources.rc \ ) @@ -36,6 +36,6 @@ $(eval $(call rule_for, \ global \ )) -$(call object_for,ion/src/simulator/windows/images.cpp): $(BUILD_DIR)/ion/src/simulator/windows/images.h +$(call object_for,ion/src/simulator/windows/platform_images.cpp): $(BUILD_DIR)/ion/src/simulator/windows/images.h $(call object_for,ion/src/simulator/windows/resources.rc): $(BUILD_DIR)/ion/src/simulator/windows/resources_gen.rc diff --git a/ion/src/simulator/windows/images.cpp b/ion/src/simulator/windows/platform_images.cpp similarity index 91% rename from ion/src/simulator/windows/images.cpp rename to ion/src/simulator/windows/platform_images.cpp index 1bae507fa..648ddbe35 100644 --- a/ion/src/simulator/windows/images.cpp +++ b/ion/src/simulator/windows/platform_images.cpp @@ -12,7 +12,7 @@ * Note that this adds an extra runtime dependency (as compared to just SDL), * but this should not be an issue. */ -HRESULT CreateStreamOnResource(const char * name, LPSTREAM * stream) { +static inline HRESULT CreateStreamOnResource(const char * name, LPSTREAM * stream) { HINSTANCE hInstance = GetModuleHandle(0); *stream = nullptr; HRSRC hC = FindResource(hInstance, name, RT_RCDATA); @@ -36,7 +36,11 @@ HRESULT CreateStreamOnResource(const char * name, LPSTREAM * stream) { return hr; } -SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) { +namespace Ion { +namespace Simulator { +namespace Platform { + +SDL_Texture * loadImage(SDL_Renderer * renderer, const char * identifier) { Gdiplus::GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr); @@ -87,3 +91,7 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi return texture; } + +} +} +} diff --git a/ion/src/simulator/windows/language.cpp b/ion/src/simulator/windows/platform_language.cpp similarity index 84% rename from ion/src/simulator/windows/language.cpp rename to ion/src/simulator/windows/platform_language.cpp index 22d7909f8..5cc652a48 100644 --- a/ion/src/simulator/windows/language.cpp +++ b/ion/src/simulator/windows/platform_language.cpp @@ -1,8 +1,11 @@ #include "../shared/platform.h" - #include -char * IonSimulatorGetLanguageCode() { +namespace Ion { +namespace Simulator { +namespace Platform { + +const char * languageCode() { /* Per documentation, the maximum number of characters allowed for the * language string is nine, including a terminating null character. */ static char buffer[9] = {0}; @@ -19,3 +22,7 @@ char * IonSimulatorGetLanguageCode() { } return buffer; } + +} +} +}