diff --git a/src/openrct2-ui/input/Input.h b/src/openrct2-ui/input/Input.h index 0340d3a9b2..bf5d2090b5 100644 --- a/src/openrct2-ui/input/Input.h +++ b/src/openrct2-ui/input/Input.h @@ -16,11 +16,5 @@ #pragma once -#ifdef __cplusplus -extern "C" -{ -#endif - void input_handle_keyboard(bool isTitle); -#ifdef __cplusplus -} -#endif +void input_handle_keyboard(bool isTitle); + diff --git a/src/openrct2-ui/input/KeyboardShortcuts.cpp b/src/openrct2-ui/input/KeyboardShortcuts.cpp index 96464fa957..724ea04413 100644 --- a/src/openrct2-ui/input/KeyboardShortcuts.cpp +++ b/src/openrct2-ui/input/KeyboardShortcuts.cpp @@ -200,45 +200,43 @@ void KeyboardShortcuts::GetKeyboardMapScroll(const uint8 * keysState, sint32 * x } } -extern "C" +void keyboard_shortcuts_reset() { - void keyboard_shortcuts_reset() - { - _instance->Reset(); - } - - bool keyboard_shortcuts_load() - { - return _instance->Load(); - } - - bool keyboard_shortcuts_save() - { - return _instance->Save(); - } - - void keyboard_shortcuts_set(sint32 key) - { - return _instance->Set(key); - } - - sint32 keyboard_shortcuts_get_from_key(sint32 key) - { - return _instance->GetFromKey(key); - } - - void keyboard_shortcuts_format_string(char * buffer, size_t bufferSize, sint32 shortcut) - { - auto str = _instance->GetShortcutString(shortcut); - String::Set(buffer, bufferSize, str.c_str()); - } - - void get_keyboard_map_scroll(const uint8 * keysState, sint32 * x, sint32 * y) - { - _instance->GetKeyboardMapScroll(keysState, x, y); - } + _instance->Reset(); } +bool keyboard_shortcuts_load() +{ + return _instance->Load(); +} + +bool keyboard_shortcuts_save() +{ + return _instance->Save(); +} + +void keyboard_shortcuts_set(sint32 key) +{ + return _instance->Set(key); +} + +sint32 keyboard_shortcuts_get_from_key(sint32 key) +{ + return _instance->GetFromKey(key); +} + +void keyboard_shortcuts_format_string(char * buffer, size_t bufferSize, sint32 shortcut) +{ + auto str = _instance->GetShortcutString(shortcut); + String::Set(buffer, bufferSize, str.c_str()); +} + +void get_keyboard_map_scroll(const uint8 * keysState, sint32 * x, sint32 * y) +{ + _instance->GetKeyboardMapScroll(keysState, x, y); +} + + // Default keyboard shortcuts const uint16 KeyboardShortcuts::DefaultKeys[SHORTCUT_COUNT] = { diff --git a/src/openrct2-ui/input/KeyboardShortcuts.h b/src/openrct2-ui/input/KeyboardShortcuts.h index 171169c136..6c2200e832 100644 --- a/src/openrct2-ui/input/KeyboardShortcuts.h +++ b/src/openrct2-ui/input/KeyboardShortcuts.h @@ -140,28 +140,22 @@ namespace OpenRCT2 #endif -#ifdef __cplusplus -extern "C" -{ -#endif - typedef struct rct_window rct_window; +typedef struct rct_window rct_window; - /** The current shortcut being changed. */ - extern uint8 gKeyboardShortcutChangeId; - extern const rct_string_id ShortcutStringIds[SHORTCUT_COUNT]; +/** The current shortcut being changed. */ +extern uint8 gKeyboardShortcutChangeId; +extern const rct_string_id ShortcutStringIds[SHORTCUT_COUNT]; - void keyboard_shortcuts_reset(); - bool keyboard_shortcuts_load(); - bool keyboard_shortcuts_save(); - void keyboard_shortcuts_set(sint32 key); - sint32 keyboard_shortcuts_get_from_key(sint32 key); - void keyboard_shortcuts_format_string(char * buffer, size_t bufferSize, sint32 shortcut); +void keyboard_shortcuts_reset(); +bool keyboard_shortcuts_load(); +bool keyboard_shortcuts_save(); +void keyboard_shortcuts_set(sint32 key); +sint32 keyboard_shortcuts_get_from_key(sint32 key); +void keyboard_shortcuts_format_string(char * buffer, size_t bufferSize, sint32 shortcut); - void keyboard_shortcut_handle(sint32 key); - void keyboard_shortcut_handle_command(sint32 shortcutIndex); - void keyboard_shortcut_format_string(char *buffer, size_t size, uint16 shortcutKey); +void keyboard_shortcut_handle(sint32 key); +void keyboard_shortcut_handle_command(sint32 shortcutIndex); +void keyboard_shortcut_format_string(char *buffer, size_t size, uint16 shortcutKey); + +void get_keyboard_map_scroll(const uint8 * keysState, sint32 * x, sint32 * y); - void get_keyboard_map_scroll(const uint8 * keysState, sint32 * x, sint32 * y); -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2-ui/windows/ShortcutKeys.cpp b/src/openrct2-ui/windows/ShortcutKeys.cpp index 21530c0e4c..7c7d8493aa 100644 --- a/src/openrct2-ui/windows/ShortcutKeys.cpp +++ b/src/openrct2-ui/windows/ShortcutKeys.cpp @@ -86,8 +86,6 @@ static rct_window_event_list window_shortcut_events = { window_shortcut_scrollpaint }; -extern "C" -{ const rct_string_id ShortcutStringIds[SHORTCUT_COUNT] = { STR_SHORTCUT_CLOSE_TOP_MOST_WINDOW, STR_SHORTCUT_CLOSE_ALL_FLOATING_WINDOWS, @@ -155,7 +153,7 @@ const rct_string_id ShortcutStringIds[SHORTCUT_COUNT] = { STR_SHORTCUT_CLEAR_SCENERY, STR_SHORTCUT_GRIDLINES_DISPLAY_TOGGLE, }; -} + /** * diff --git a/src/openrct2/Cheats.h b/src/openrct2/Cheats.h index f2e31caa46..4367772b3f 100644 --- a/src/openrct2/Cheats.h +++ b/src/openrct2/Cheats.h @@ -19,10 +19,6 @@ #include "common.h" -#ifdef __cplusplus -extern "C" { -#endif - extern bool gCheatsSandboxMode; extern bool gCheatsDisableClearanceChecks; extern bool gCheatsDisableSupportLimits; @@ -132,8 +128,4 @@ void cheats_reset(); const char* cheats_get_cheat_string(int cheat, int edx, int edi); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/CmdlineSprite.h b/src/openrct2/CmdlineSprite.h index 47c774d0df..d5f124216c 100644 --- a/src/openrct2/CmdlineSprite.h +++ b/src/openrct2/CmdlineSprite.h @@ -19,16 +19,7 @@ #include "common.h" -#ifdef __cplusplus -extern "C" -{ -#endif - sint32 cmdline_for_sprite(const char **argv, sint32 argc); extern sint32 gSpriteMode; -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 7a7c0fcf18..fb703aff28 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -891,294 +891,292 @@ namespace OpenRCT2 } } -extern "C" +void context_init() { - void context_init() - { - GetContext()->GetUiContext()->GetWindowManager()->Init(); - } + GetContext()->GetUiContext()->GetWindowManager()->Init(); +} - bool context_load_park_from_file(const utf8 * path) - { - return GetContext()->LoadParkFromFile(path); - } +bool context_load_park_from_file(const utf8 * path) +{ + return GetContext()->LoadParkFromFile(path); +} - bool context_load_park_from_stream(void * stream) - { - return GetContext()->LoadParkFromStream((IStream*)stream, ""); - } +bool context_load_park_from_stream(void * stream) +{ + return GetContext()->LoadParkFromStream((IStream*)stream, ""); +} - void openrct2_write_full_version_info(utf8 * buffer, size_t bufferSize) - { - String::Set(buffer, bufferSize, gVersionInfoFull); - } +void openrct2_write_full_version_info(utf8 * buffer, size_t bufferSize) +{ + String::Set(buffer, bufferSize, gVersionInfoFull); +} - void openrct2_finish() - { - GetContext()->Finish(); - } +void openrct2_finish() +{ + GetContext()->Finish(); +} - void context_setcurrentcursor(sint32 cursor) - { - GetContext()->GetUiContext()->SetCursor((CURSOR_ID)cursor); - } +void context_setcurrentcursor(sint32 cursor) +{ + GetContext()->GetUiContext()->SetCursor((CURSOR_ID)cursor); +} - void context_update_cursor_scale() - { - GetContext()->GetUiContext()->SetCursorScale(static_cast(round(gConfigGeneral.window_scale))); - } +void context_update_cursor_scale() +{ + GetContext()->GetUiContext()->SetCursorScale(static_cast(round(gConfigGeneral.window_scale))); +} - void context_hide_cursor() - { - GetContext()->GetUiContext()->SetCursorVisible(false); - } +void context_hide_cursor() +{ + GetContext()->GetUiContext()->SetCursorVisible(false); +} - void context_show_cursor() - { - GetContext()->GetUiContext()->SetCursorVisible(true); - } +void context_show_cursor() +{ + GetContext()->GetUiContext()->SetCursorVisible(true); +} - void context_get_cursor_position(sint32 * x, sint32 * y) - { - GetContext()->GetUiContext()->GetCursorPosition(x, y); - } +void context_get_cursor_position(sint32 * x, sint32 * y) +{ + GetContext()->GetUiContext()->GetCursorPosition(x, y); +} - void context_get_cursor_position_scaled(sint32 * x, sint32 * y) - { - context_get_cursor_position(x, y); +void context_get_cursor_position_scaled(sint32 * x, sint32 * y) +{ + context_get_cursor_position(x, y); - // Compensate for window scaling. - *x = (sint32)ceilf(*x / gConfigGeneral.window_scale); - *y = (sint32)ceilf(*y / gConfigGeneral.window_scale); - } + // Compensate for window scaling. + *x = (sint32)ceilf(*x / gConfigGeneral.window_scale); + *y = (sint32)ceilf(*y / gConfigGeneral.window_scale); +} - void context_set_cursor_position(sint32 x, sint32 y) - { - GetContext()->GetUiContext()->SetCursorPosition(x, y); - } +void context_set_cursor_position(sint32 x, sint32 y) +{ + GetContext()->GetUiContext()->SetCursorPosition(x, y); +} - const CursorState * context_get_cursor_state() - { - return GetContext()->GetUiContext()->GetCursorState(); - } +const CursorState * context_get_cursor_state() +{ + return GetContext()->GetUiContext()->GetCursorState(); +} - const uint8 * context_get_keys_state() - { - return GetContext()->GetUiContext()->GetKeysState(); - } +const uint8 * context_get_keys_state() +{ + return GetContext()->GetUiContext()->GetKeysState(); +} - const uint8 * context_get_keys_pressed() - { - return GetContext()->GetUiContext()->GetKeysPressed(); - } +const uint8 * context_get_keys_pressed() +{ + return GetContext()->GetUiContext()->GetKeysPressed(); +} - TextInputSession * context_start_text_input(utf8 * buffer, size_t maxLength) - { - return GetContext()->GetUiContext()->StartTextInput(buffer, maxLength); - } +TextInputSession * context_start_text_input(utf8 * buffer, size_t maxLength) +{ + return GetContext()->GetUiContext()->StartTextInput(buffer, maxLength); +} - void context_stop_text_input() - { - GetContext()->GetUiContext()->StopTextInput(); - } +void context_stop_text_input() +{ + GetContext()->GetUiContext()->StopTextInput(); +} - bool context_is_input_active() - { - return GetContext()->GetUiContext()->IsTextInputActive(); - } +bool context_is_input_active() +{ + return GetContext()->GetUiContext()->IsTextInputActive(); +} - void context_trigger_resize() - { - return GetContext()->GetUiContext()->TriggerResize(); - } +void context_trigger_resize() +{ + return GetContext()->GetUiContext()->TriggerResize(); +} - void context_set_fullscreen_mode(sint32 mode) - { - return GetContext()->GetUiContext()->SetFullscreenMode((FULLSCREEN_MODE)mode); - } +void context_set_fullscreen_mode(sint32 mode) +{ + return GetContext()->GetUiContext()->SetFullscreenMode((FULLSCREEN_MODE)mode); +} - void context_recreate_window() - { - GetContext()->GetUiContext()->RecreateWindow(); - } +void context_recreate_window() +{ + GetContext()->GetUiContext()->RecreateWindow(); +} - sint32 context_get_resolutions(Resolution * * outResolutions) - { - auto resolutions = GetContext()->GetUiContext()->GetFullscreenResolutions(); - sint32 count = (sint32)resolutions.size(); - *outResolutions = Memory::AllocateArray(count); - std::copy_n(resolutions.begin(), count, *outResolutions); - return count; - } +sint32 context_get_resolutions(Resolution * * outResolutions) +{ +auto resolutions = GetContext()->GetUiContext()->GetFullscreenResolutions(); +sint32 count = (sint32)resolutions.size(); +*outResolutions = Memory::AllocateArray(count); +std::copy_n(resolutions.begin(), count, *outResolutions); +return count; +} - sint32 context_get_width() - { - return GetContext()->GetUiContext()->GetWidth(); - } +sint32 context_get_width() +{ + return GetContext()->GetUiContext()->GetWidth(); +} - sint32 context_get_height() - { - return GetContext()->GetUiContext()->GetHeight(); - } +sint32 context_get_height() +{ + return GetContext()->GetUiContext()->GetHeight(); +} - bool context_has_focus() - { - return GetContext()->GetUiContext()->HasFocus(); - } +bool context_has_focus() +{ + return GetContext()->GetUiContext()->HasFocus(); +} - void context_set_cursor_trap(bool value) - { - GetContext()->GetUiContext()->SetCursorTrap(value); - } +void context_set_cursor_trap(bool value) +{ + GetContext()->GetUiContext()->SetCursorTrap(value); +} - rct_window * context_open_window(rct_windowclass wc) - { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); - return windowManager->OpenWindow(wc); - } +rct_window * context_open_window(rct_windowclass wc) +{ + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + return windowManager->OpenWindow(wc); +} - rct_window * context_open_window_view(rct_windowclass wc) - { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); - return windowManager->OpenView(wc); - } +rct_window * context_open_window_view(rct_windowclass wc) +{ + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + return windowManager->OpenView(wc); +} - rct_window * context_open_detail_window(uint8 type, sint32 id) - { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); - return windowManager->OpenDetails(type, id); - } +rct_window * context_open_detail_window(uint8 type, sint32 id) +{ + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + return windowManager->OpenDetails(type, id); +} - rct_window * context_open_intent(Intent * intent) - { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); - return windowManager->OpenIntent(intent); - } +rct_window * context_open_intent(Intent * intent) +{ + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + return windowManager->OpenIntent(intent); +} - void context_broadcast_intent(Intent * intent) - { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); - windowManager->BroadcastIntent(*intent); - } +void context_broadcast_intent(Intent * intent) +{ + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + windowManager->BroadcastIntent(*intent); +} - void context_force_close_window_by_class(rct_windowclass windowClass) - { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); - windowManager->ForceClose(windowClass); - } +void context_force_close_window_by_class(rct_windowclass windowClass) +{ + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + windowManager->ForceClose(windowClass); +} - rct_window * context_show_error(rct_string_id title, rct_string_id message) - { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); - return windowManager->ShowError(title, message); - } +rct_window * context_show_error(rct_string_id title, rct_string_id message) +{ + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + return windowManager->ShowError(title, message); +} - void context_update_map_tooltip() - { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); - windowManager->UpdateMapTooltip(); - } +void context_update_map_tooltip() +{ + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + windowManager->UpdateMapTooltip(); +} - void context_handle_input() - { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); - windowManager->HandleInput(); - } +void context_handle_input() +{ + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + windowManager->HandleInput(); +} - void context_input_handle_keyboard(bool isTitle) - { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); - windowManager->HandleKeyboard(isTitle); - } +void context_input_handle_keyboard(bool isTitle) +{ + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + windowManager->HandleKeyboard(isTitle); +} - bool context_read_bmp(void * * outPixels, uint32 * outWidth, uint32 * outHeight, const utf8 * path) - { - return GetContext()->GetUiContext()->ReadBMP(outPixels, outWidth, outHeight, std::string(path)); - } +bool context_read_bmp(void * * outPixels, uint32 * outWidth, uint32 * outHeight, const utf8 * path) +{ + return GetContext()->GetUiContext()->ReadBMP(outPixels, outWidth, outHeight, std::string(path)); +} - void context_quit() - { - GetContext()->Quit(); - } +void context_quit() +{ + GetContext()->Quit(); +} - const utf8 * context_get_path_legacy(sint32 pathId) - { - static utf8 result[MAX_PATH]; - auto path = GetContext()->GetPathLegacy(pathId); - String::Set(result, sizeof(result), path.c_str()); - return result; - } +const utf8 * context_get_path_legacy(sint32 pathId) +{ + static utf8 result[MAX_PATH]; + auto path = GetContext()->GetPathLegacy(pathId); + String::Set(result, sizeof(result), path.c_str()); + return result; +} - bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize) +bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize) +{ + try { - try + FileDialogDesc desc2; + desc2.Type = (FILE_DIALOG_TYPE)desc->type; + desc2.Title = String::ToStd(desc->title); + desc2.InitialDirectory = String::ToStd(desc->initial_directory); + desc2.DefaultFilename = String::ToStd(desc->default_filename); + for (const auto &filter : desc->filters) { - FileDialogDesc desc2; - desc2.Type = (FILE_DIALOG_TYPE)desc->type; - desc2.Title = String::ToStd(desc->title); - desc2.InitialDirectory = String::ToStd(desc->initial_directory); - desc2.DefaultFilename = String::ToStd(desc->default_filename); - for (const auto &filter : desc->filters) + if (filter.name != nullptr) { - if (filter.name != nullptr) - { - desc2.Filters.push_back({ String::ToStd(filter.name), String::ToStd(filter.pattern) }); - } + desc2.Filters.push_back({ String::ToStd(filter.name), String::ToStd(filter.pattern) }); } - std::string result = GetContext()->GetUiContext()->ShowFileDialog(desc2); - String::Set(outFilename, outSize, result.c_str()); - return !result.empty(); - } - catch (const std::exception &ex) - { - log_error(ex.what()); - outFilename[0] = '\0'; - return false; } + std::string result = GetContext()->GetUiContext()->ShowFileDialog(desc2); + String::Set(outFilename, outSize, result.c_str()); + return !result.empty(); } - - utf8 * platform_open_directory_browser(const utf8 * title) + catch (const std::exception &ex) { - try - { - std::string result = GetContext()->GetUiContext()->ShowDirectoryDialog(title); - return String::Duplicate(result.c_str()); - } - catch (const std::exception &ex) - { - log_error(ex.what()); - return nullptr; - } - } - - bool platform_place_string_on_clipboard(utf8* target) - { - return GetContext()->GetUiContext()->SetClipboardText(target); - } - - /** - * This function is deprecated. - * Use IPlatformEnvironment instad. - */ - void platform_get_user_directory(utf8 * outPath, const utf8 * subDirectory, size_t outSize) - { - auto env = GetContext()->GetPlatformEnvironment(); - auto path = env->GetDirectoryPath(DIRBASE::USER); - if (!String::IsNullOrEmpty(subDirectory)) - { - path = Path::Combine(path, subDirectory); - } - String::Set(outPath, outSize, path.c_str()); - } - - /** - * This function is deprecated. - * Use IPlatformEnvironment instad. - */ - void platform_get_openrct_data_path(utf8 * outPath, size_t outSize) - { - auto env = GetContext()->GetPlatformEnvironment(); - auto path = env->GetDirectoryPath(DIRBASE::OPENRCT2); - String::Set(outPath, outSize, path.c_str()); + log_error(ex.what()); + outFilename[0] = '\0'; + return false; } } + +utf8 * platform_open_directory_browser(const utf8 * title) +{ + try + { + std::string result = GetContext()->GetUiContext()->ShowDirectoryDialog(title); + return String::Duplicate(result.c_str()); + } + catch (const std::exception &ex) + { + log_error(ex.what()); + return nullptr; + } +} + +bool platform_place_string_on_clipboard(utf8* target) +{ + return GetContext()->GetUiContext()->SetClipboardText(target); +} + +/** + * This function is deprecated. + * Use IPlatformEnvironment instad. + */ +void platform_get_user_directory(utf8 * outPath, const utf8 * subDirectory, size_t outSize) +{ + auto env = GetContext()->GetPlatformEnvironment(); + auto path = env->GetDirectoryPath(DIRBASE::USER); + if (!String::IsNullOrEmpty(subDirectory)) + { + path = Path::Combine(path, subDirectory); + } +} + +/** + * This function is deprecated. + * Use IPlatformEnvironment instad. + */ +void platform_get_openrct_data_path(utf8 * outPath, size_t outSize) +{ + auto env = GetContext()->GetPlatformEnvironment(); + auto path = env->GetDirectoryPath(DIRBASE::OPENRCT2); + String::Set(outPath, outSize, path.c_str()); +} + + diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index e1ae676abd..e4b8564341 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -189,47 +189,41 @@ enum PATH_ID_END, }; -#ifdef __cplusplus -extern "C" -{ -#endif - void context_init(); - void context_setcurrentcursor(sint32 cursor); - void context_update_cursor_scale(); - void context_hide_cursor(); - void context_show_cursor(); - void context_get_cursor_position(sint32 * x, sint32 * y); - void context_get_cursor_position_scaled(sint32 * x, sint32 * y); - void context_set_cursor_position(sint32 x, sint32 y); - const CursorState * context_get_cursor_state(); - const uint8 * context_get_keys_state(); - const uint8 * context_get_keys_pressed(); - TextInputSession * context_start_text_input(utf8 * buffer, size_t maxLength); - void context_stop_text_input(); - bool context_is_input_active(); - void context_trigger_resize(); - void context_set_fullscreen_mode(sint32 mode); - void context_recreate_window(); - sint32 context_get_resolutions(struct Resolution * * outResolutions); - sint32 context_get_width(); - sint32 context_get_height(); - bool context_has_focus(); - void context_set_cursor_trap(bool value); - rct_window * context_open_window(rct_windowclass wc); - rct_window * context_open_detail_window(uint8 type, sint32 id); - rct_window * context_open_window_view(uint8 view); - rct_window * context_show_error(rct_string_id title, rct_string_id message); - rct_window * context_open_intent(Intent * intent); - void context_broadcast_intent(Intent * intent); - void context_force_close_window_by_class(rct_windowclass wc); - void context_update_map_tooltip(); - void context_handle_input(); - void context_input_handle_keyboard(bool isTitle); - bool context_read_bmp(void * * outPixels, uint32 * outWidth, uint32 * outHeight, const utf8 * path); - void context_quit(); - const utf8 * context_get_path_legacy(sint32 pathId); - bool context_load_park_from_file(const utf8 * path); - bool context_load_park_from_stream(void * stream); -#ifdef __cplusplus -} -#endif +void context_init(); +void context_setcurrentcursor(sint32 cursor); +void context_update_cursor_scale(); +void context_hide_cursor(); +void context_show_cursor(); +void context_get_cursor_position(sint32 * x, sint32 * y); +void context_get_cursor_position_scaled(sint32 * x, sint32 * y); +void context_set_cursor_position(sint32 x, sint32 y); +const CursorState * context_get_cursor_state(); +const uint8 * context_get_keys_state(); +const uint8 * context_get_keys_pressed(); +TextInputSession * context_start_text_input(utf8 * buffer, size_t maxLength); +void context_stop_text_input(); +bool context_is_input_active(); +void context_trigger_resize(); +void context_set_fullscreen_mode(sint32 mode); +void context_recreate_window(); +sint32 context_get_resolutions(struct Resolution * * outResolutions); +sint32 context_get_width(); +sint32 context_get_height(); +bool context_has_focus(); +void context_set_cursor_trap(bool value); +rct_window * context_open_window(rct_windowclass wc); +rct_window * context_open_detail_window(uint8 type, sint32 id); +rct_window * context_open_window_view(uint8 view); +rct_window * context_show_error(rct_string_id title, rct_string_id message); +rct_window * context_open_intent(Intent * intent); +void context_broadcast_intent(Intent * intent); +void context_force_close_window_by_class(rct_windowclass wc); +void context_update_map_tooltip(); +void context_handle_input(); +void context_input_handle_keyboard(bool isTitle); +bool context_read_bmp(void * * outPixels, uint32 * outWidth, uint32 * outHeight, const utf8 * path); +void context_quit(); +const utf8 * context_get_path_legacy(sint32 pathId); +bool context_load_park_from_file(const utf8 * path); +bool context_load_park_from_stream(void * stream); + diff --git a/src/openrct2/Diagnostic.h b/src/openrct2/Diagnostic.h index f8f0d2d5c4..268b5fc3e7 100644 --- a/src/openrct2/Diagnostic.h +++ b/src/openrct2/Diagnostic.h @@ -75,19 +75,11 @@ typedef enum { #define DEBUG_LEVEL_1 0 #endif // defined(DEBUG) -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - extern bool _log_levels[DIAGNOSTIC_LEVEL_COUNT]; void diagnostic_log(DiagnosticLevel diagnosticLevel, const char *format, ...); void diagnostic_log_with_location(DiagnosticLevel diagnosticLevel, const char *file, const char *function, sint32 line, const char *format, ...); -#ifdef __cplusplus -} -#endif // __cplusplus - #ifdef _MSC_VER #define diagnostic_log_macro(level, format, ...) diagnostic_log_with_location(level, __FILE__, __FUNCTION__, __LINE__, format, ## __VA_ARGS__) #else diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 4c84024017..ddc9875cf3 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -808,15 +808,13 @@ namespace Editor } } -extern "C" +void editor_open_windows_for_current_step() { - void editor_open_windows_for_current_step() - { - Editor::OpenWindowsForCurrentStep(); - } - - void game_command_edit_scenario_options(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp) - { - Editor::GameCommandEditScenarioOptions(eax, ebx, ecx, edx, esi, edi, ebp); - } + Editor::OpenWindowsForCurrentStep(); } + +void game_command_edit_scenario_options(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp) +{ + Editor::GameCommandEditScenarioOptions(eax, ebx, ecx, edx, esi, edi, ebp); +} + diff --git a/src/openrct2/Editor.h b/src/openrct2/Editor.h index d3c8c9c940..8cefe57662 100644 --- a/src/openrct2/Editor.h +++ b/src/openrct2/Editor.h @@ -40,52 +40,47 @@ namespace Editor void GameCommandEditScenarioOptions(sint32*, sint32*, sint32*, sint32*, sint32*, sint32*, sint32*); } -extern "C" - { -#endif +typedef enum +{ + EDITOR_STEP_OBJECT_SELECTION, // 0 + EDITOR_STEP_LANDSCAPE_EDITOR, // 1 + EDITOR_STEP_INVENTIONS_LIST_SET_UP, // 2 + EDITOR_STEP_OPTIONS_SELECTION, // 3 + EDITOR_STEP_OBJECTIVE_SELECTION, // 4 + EDITOR_STEP_SAVE_SCENARIO, // 5 + EDITOR_STEP_ROLLERCOASTER_DESIGNER, // 6 + EDITOR_STEP_TRACK_DESIGNS_MANAGER // 7 +} RCT2_EDITOR_STEP; - typedef enum - { - EDITOR_STEP_OBJECT_SELECTION, // 0 - EDITOR_STEP_LANDSCAPE_EDITOR, // 1 - EDITOR_STEP_INVENTIONS_LIST_SET_UP, // 2 - EDITOR_STEP_OPTIONS_SELECTION, // 3 - EDITOR_STEP_OBJECTIVE_SELECTION, // 4 - EDITOR_STEP_SAVE_SCENARIO, // 5 - EDITOR_STEP_ROLLERCOASTER_DESIGNER, // 6 - EDITOR_STEP_TRACK_DESIGNS_MANAGER // 7 - } RCT2_EDITOR_STEP; +enum +{ + EDIT_SCENARIOOPTIONS_SETNOMONEY, + EDIT_SCENARIOOPTIONS_SETINITIALCASH, + EDIT_SCENARIOOPTIONS_SETINITIALLOAN, + EDIT_SCENARIOOPTIONS_SETMAXIMUMLOANSIZE, + EDIT_SCENARIOOPTIONS_SETANNUALINTERESTRATE, + EDIT_SCENARIOOPTIONS_SETFORBIDMARKETINGCAMPAIGNS, + EDIT_SCENARIOOPTIONS_SETAVERAGECASHPERGUEST, + EDIT_SCENARIOOPTIONS_SETGUESTINITIALHAPPINESS, + EDIT_SCENARIOOPTIONS_SETGUESTINITIALHUNGER, + EDIT_SCENARIOOPTIONS_SETGUESTINITIALTHIRST, + EDIT_SCENARIOOPTIONS_SETGUESTSPREFERLESSINTENSERIDES, + EDIT_SCENARIOOPTIONS_SETGUESTSPREFERMOREINTENSERIDES, + EDIT_SCENARIOOPTIONS_SETCOSTTOBUYLAND, + EDIT_SCENARIOOPTIONS_SETCOSTTOBUYCONSTRUCTIONRIGHTS, + EDIT_SCENARIOOPTIONS_SETPARKCHARGEMETHOD, + EDIT_SCENARIOOPTIONS_SETPARKCHARGEENTRYFEE, + EDIT_SCENARIOOPTIONS_SETFORBIDTREEREMOVAL, + EDIT_SCENARIOOPTIONS_SETFORBIDLANDSCAPECHANGES, + EDIT_SCENARIOOPTIONS_SETFORBIDHIGHCONSTRUCTION, + EDIT_SCENARIOOPTIONS_SETPARKRATINGHIGHERDIFFICULTLEVEL, + EDIT_SCENARIOOPTIONS_SETGUESTGENERATIONHIGHERDIFFICULTLEVEL, +}; - enum - { - EDIT_SCENARIOOPTIONS_SETNOMONEY, - EDIT_SCENARIOOPTIONS_SETINITIALCASH, - EDIT_SCENARIOOPTIONS_SETINITIALLOAN, - EDIT_SCENARIOOPTIONS_SETMAXIMUMLOANSIZE, - EDIT_SCENARIOOPTIONS_SETANNUALINTERESTRATE, - EDIT_SCENARIOOPTIONS_SETFORBIDMARKETINGCAMPAIGNS, - EDIT_SCENARIOOPTIONS_SETAVERAGECASHPERGUEST, - EDIT_SCENARIOOPTIONS_SETGUESTINITIALHAPPINESS, - EDIT_SCENARIOOPTIONS_SETGUESTINITIALHUNGER, - EDIT_SCENARIOOPTIONS_SETGUESTINITIALTHIRST, - EDIT_SCENARIOOPTIONS_SETGUESTSPREFERLESSINTENSERIDES, - EDIT_SCENARIOOPTIONS_SETGUESTSPREFERMOREINTENSERIDES, - EDIT_SCENARIOOPTIONS_SETCOSTTOBUYLAND, - EDIT_SCENARIOOPTIONS_SETCOSTTOBUYCONSTRUCTIONRIGHTS, - EDIT_SCENARIOOPTIONS_SETPARKCHARGEMETHOD, - EDIT_SCENARIOOPTIONS_SETPARKCHARGEENTRYFEE, - EDIT_SCENARIOOPTIONS_SETFORBIDTREEREMOVAL, - EDIT_SCENARIOOPTIONS_SETFORBIDLANDSCAPECHANGES, - EDIT_SCENARIOOPTIONS_SETFORBIDHIGHCONSTRUCTION, - EDIT_SCENARIOOPTIONS_SETPARKRATINGHIGHERDIFFICULTLEVEL, - EDIT_SCENARIOOPTIONS_SETGUESTGENERATIONHIGHERDIFFICULTLEVEL, - }; +void editor_open_windows_for_current_step(); - void editor_open_windows_for_current_step(); - - void game_command_edit_scenario_options(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); -#ifdef __cplusplus -} -#endif +void game_command_edit_scenario_options(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); #endif + +#endif \ No newline at end of file diff --git a/src/openrct2/EditorObjectSelectionSession.h b/src/openrct2/EditorObjectSelectionSession.h index 929e75890b..d83e77af75 100644 --- a/src/openrct2/EditorObjectSelectionSession.h +++ b/src/openrct2/EditorObjectSelectionSession.h @@ -32,17 +32,9 @@ void reset_selected_object_count_and_size(); sint32 window_editor_object_selection_select_object(uint8 bh, sint32 flags, const rct_object_entry *entry); #endif -#ifdef __cplusplus -extern "C" -{ -#endif +/** +* Removes all unused objects from the object selection. +* @return The number of removed objects. +*/ +sint32 editor_remove_unused_objects(); - /** - * Removes all unused objects from the object selection. - * @return The number of removed objects. - */ - sint32 editor_remove_unused_objects(); - -#ifdef __cplusplus -} -#endif // __cplusplus diff --git a/src/openrct2/FileClassifier.cpp b/src/openrct2/FileClassifier.cpp index 7231889b58..c5ef5e5496 100644 --- a/src/openrct2/FileClassifier.cpp +++ b/src/openrct2/FileClassifier.cpp @@ -166,18 +166,16 @@ static bool TryClassifyAsTD4_TD6(IStream * stream, ClassifiedFileInfo * result) return success; } -extern "C" +uint32 get_file_extension_type(const utf8 * path) { - uint32 get_file_extension_type(const utf8 * path) - { - auto extension = Path::GetExtension(path); - if (String::Equals(extension, ".dat", true)) return FILE_EXTENSION_DAT; - if (String::Equals(extension, ".sc4", true)) return FILE_EXTENSION_SC4; - if (String::Equals(extension, ".sv4", true)) return FILE_EXTENSION_SV4; - if (String::Equals(extension, ".td4", true)) return FILE_EXTENSION_TD4; - if (String::Equals(extension, ".sc6", true)) return FILE_EXTENSION_SC6; - if (String::Equals(extension, ".sv6", true)) return FILE_EXTENSION_SV6; - if (String::Equals(extension, ".td6", true)) return FILE_EXTENSION_TD6; - return FILE_EXTENSION_UNKNOWN; - } + auto extension = Path::GetExtension(path); + if (String::Equals(extension, ".dat", true)) return FILE_EXTENSION_DAT; + if (String::Equals(extension, ".sc4", true)) return FILE_EXTENSION_SC4; + if (String::Equals(extension, ".sv4", true)) return FILE_EXTENSION_SV4; + if (String::Equals(extension, ".td4", true)) return FILE_EXTENSION_TD4; + if (String::Equals(extension, ".sc6", true)) return FILE_EXTENSION_SC6; + if (String::Equals(extension, ".sv6", true)) return FILE_EXTENSION_SV6; + if (String::Equals(extension, ".td6", true)) return FILE_EXTENSION_TD6; + return FILE_EXTENSION_UNKNOWN; } + diff --git a/src/openrct2/FileClassifier.h b/src/openrct2/FileClassifier.h index 837f7ad48d..c7fcf34cfb 100644 --- a/src/openrct2/FileClassifier.h +++ b/src/openrct2/FileClassifier.h @@ -57,12 +57,4 @@ bool TryClassifyFile(IStream * stream, ClassifiedFileInfo * result); #endif // __cplusplus - -#ifdef __cplusplus -extern "C" -{ -#endif - uint32 get_file_extension_type(const utf8 * path); -#ifdef __cplusplus -} -#endif +uint32 get_file_extension_type(const utf8 * path); diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index 7025e4d67a..d6566019ce 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -126,10 +126,6 @@ typedef void (GAME_COMMAND_POINTER)(sint32 * eax, sint32 * ebx, sint32 * ecx, si typedef void (GAME_COMMAND_CALLBACK_POINTER)(sint32 eax, sint32 ebx, sint32 ecx, sint32 edx, sint32 esi, sint32 edi, sint32 ebp); -#ifdef __cplusplus -extern "C" { -#endif - extern GAME_COMMAND_CALLBACK_POINTER * game_command_callback; sint32 game_command_callback_get_index(GAME_COMMAND_CALLBACK_POINTER * callback); GAME_COMMAND_CALLBACK_POINTER * game_command_callback_get_callback(uint32 index); @@ -191,7 +187,3 @@ void game_convert_news_items_to_utf8(); void game_convert_strings_to_rct2(rct_s6_data * s6); void game_fix_save_vars(); void game_init_all(sint32 mapSize); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/Imaging.cpp b/src/openrct2/Imaging.cpp index 077f41f8d1..02c2287814 100644 --- a/src/openrct2/Imaging.cpp +++ b/src/openrct2/Imaging.cpp @@ -300,20 +300,18 @@ namespace Imaging } } -extern "C" +bool image_io_png_read(uint8 * * pixels, uint32 * width, uint32 * height, bool expand, const utf8 * path, sint32 * bitDepth) { - bool image_io_png_read(uint8 * * pixels, uint32 * width, uint32 * height, bool expand, const utf8 * path, sint32 * bitDepth) - { - return Imaging::PngRead(pixels, width, height, expand, path, bitDepth); - } - - bool image_io_png_write(const rct_drawpixelinfo * dpi, const rct_palette * palette, const utf8 * path) - { - return Imaging::PngWrite(dpi, palette, path); - } - - bool image_io_png_write_32bpp(sint32 width, sint32 height, const void * pixels, const utf8 * path) - { - return Imaging::PngWrite32bpp(width, height, pixels, path); - } + return Imaging::PngRead(pixels, width, height, expand, path, bitDepth); } + +bool image_io_png_write(const rct_drawpixelinfo * dpi, const rct_palette * palette, const utf8 * path) +{ + return Imaging::PngWrite(dpi, palette, path); +} + +bool image_io_png_write_32bpp(sint32 width, sint32 height, const void * pixels, const utf8 * path) +{ + return Imaging::PngWrite32bpp(width, height, pixels, path); +} + diff --git a/src/openrct2/Imaging.h b/src/openrct2/Imaging.h index 41cdbd90d0..142f2ec99c 100644 --- a/src/openrct2/Imaging.h +++ b/src/openrct2/Imaging.h @@ -31,13 +31,7 @@ namespace Imaging #endif // __cplusplus -#ifdef __cplusplus -extern "C" -{ -#endif - bool image_io_png_read(uint8 * * pixels, uint32 * width, uint32 * height, bool expand, const utf8 * path, sint32 * bitDepth); - bool image_io_png_write(const rct_drawpixelinfo * dpi, const rct_palette * palette, const utf8 * path); - bool image_io_png_write_32bpp(sint32 width, sint32 height, const void * pixels, const utf8 * path); -#ifdef __cplusplus -} -#endif +bool image_io_png_read(uint8 * * pixels, uint32 * width, uint32 * height, bool expand, const utf8 * path, sint32 * bitDepth); +bool image_io_png_write(const rct_drawpixelinfo * dpi, const rct_palette * palette, const utf8 * path); +bool image_io_png_write_32bpp(sint32 width, sint32 height, const void * pixels, const utf8 * path); + diff --git a/src/openrct2/Input.h b/src/openrct2/Input.h index c8bcfcb743..44fbd74663 100644 --- a/src/openrct2/Input.h +++ b/src/openrct2/Input.h @@ -76,10 +76,6 @@ typedef struct widget_ref { rct_widgetindex widget_index; } widget_ref; -#ifdef __cplusplus -extern "C" { -#endif - extern uint8 gInputPlaceObjectModifier; extern sint32 gInputDragLastX; @@ -126,8 +122,4 @@ void input_reset_place_obj_modifier(); void input_scroll_viewport(sint32 scrollX, sint32 scrollY); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/Intro.h b/src/openrct2/Intro.h index a324882a5a..4e22a7fddf 100644 --- a/src/openrct2/Intro.h +++ b/src/openrct2/Intro.h @@ -34,17 +34,9 @@ enum INTRO_STATE { INTRO_STATE_FINISH = 255, }; -#ifdef __cplusplus -extern "C" { -#endif - extern uint8 gIntroState; void intro_update(); void intro_draw(rct_drawpixelinfo *dpi); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/OpenRCT2.cpp b/src/openrct2/OpenRCT2.cpp index f347864fc9..1a10a24f47 100644 --- a/src/openrct2/OpenRCT2.cpp +++ b/src/openrct2/OpenRCT2.cpp @@ -22,30 +22,28 @@ #include "audio/audio.h" #include "platform/platform.h" -extern "C" -{ - sint32 gExitCode; - sint32 gOpenRCT2StartupAction = STARTUP_ACTION_TITLE; - utf8 gOpenRCT2StartupActionPath[512] = { 0 }; - utf8 gExePath[MAX_PATH]; - utf8 gCustomUserDataPath[MAX_PATH] = { 0 }; - utf8 gCustomOpenrctDataPath[MAX_PATH] = { 0 }; - utf8 gCustomRCT2DataPath[MAX_PATH] = { 0 }; - utf8 gCustomPassword[MAX_PATH] = { 0 }; +sint32 gExitCode; +sint32 gOpenRCT2StartupAction = STARTUP_ACTION_TITLE; +utf8 gOpenRCT2StartupActionPath[512] = { 0 }; +utf8 gExePath[MAX_PATH]; +utf8 gCustomUserDataPath[MAX_PATH] = { 0 }; +utf8 gCustomOpenrctDataPath[MAX_PATH] = { 0 }; +utf8 gCustomRCT2DataPath[MAX_PATH] = { 0 }; +utf8 gCustomPassword[MAX_PATH] = { 0 }; - bool gOpenRCT2Headless = false; - bool gOpenRCT2NoGraphics = false; +bool gOpenRCT2Headless = false; +bool gOpenRCT2NoGraphics = false; - bool gOpenRCT2ShowChangelog; - bool gOpenRCT2SilentBreakpad; +bool gOpenRCT2ShowChangelog; +bool gOpenRCT2SilentBreakpad; #ifndef DISABLE_NETWORK - // OpenSSL's message digest context used for calculating sprite checksums - EVP_MD_CTX * gHashCTX = nullptr; +// OpenSSL's message digest context used for calculating sprite checksums +EVP_MD_CTX * gHashCTX = nullptr; #endif // DISABLE_NETWORK - uint32 gCurrentDrawCount = 0; - uint8 gScreenFlags; - uint32 gScreenAge; - uint8 gSavePromptMode; -} +uint32 gCurrentDrawCount = 0; +uint8 gScreenFlags; +uint32 gScreenAge; +uint8 gSavePromptMode; + diff --git a/src/openrct2/OpenRCT2.h b/src/openrct2/OpenRCT2.h index a00a4e324a..e437a5b658 100644 --- a/src/openrct2/OpenRCT2.h +++ b/src/openrct2/OpenRCT2.h @@ -44,47 +44,39 @@ enum SCREEN_FLAGS_EDITOR = (SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER), }; -#ifdef __cplusplus -extern "C" -{ -#endif +/** The exit code for OpenRCT2 when it exits. */ +extern sint32 gExitCode; - /** The exit code for OpenRCT2 when it exits. */ - extern sint32 gExitCode; - - extern sint32 gOpenRCT2StartupAction; - extern utf8 gOpenRCT2StartupActionPath[512]; - extern utf8 gExePath[MAX_PATH]; - extern utf8 gCustomUserDataPath[MAX_PATH]; - extern utf8 gCustomOpenrctDataPath[MAX_PATH]; - extern utf8 gCustomRCT2DataPath[MAX_PATH]; - extern utf8 gCustomPassword[MAX_PATH]; - extern bool gOpenRCT2Headless; - extern bool gOpenRCT2NoGraphics; - extern bool gOpenRCT2ShowChangelog; - extern bool gOpenRCT2SilentBreakpad; +extern sint32 gOpenRCT2StartupAction; +extern utf8 gOpenRCT2StartupActionPath[512]; +extern utf8 gExePath[MAX_PATH]; +extern utf8 gCustomUserDataPath[MAX_PATH]; +extern utf8 gCustomOpenrctDataPath[MAX_PATH]; +extern utf8 gCustomRCT2DataPath[MAX_PATH]; +extern utf8 gCustomPassword[MAX_PATH]; +extern bool gOpenRCT2Headless; +extern bool gOpenRCT2NoGraphics; +extern bool gOpenRCT2ShowChangelog; +extern bool gOpenRCT2SilentBreakpad; #ifndef DISABLE_NETWORK - extern EVP_MD_CTX * gHashCTX; +extern EVP_MD_CTX * gHashCTX; #endif // DISABLE_NETWORK #ifndef DISABLE_NETWORK - extern sint32 gNetworkStart; - extern char gNetworkStartHost[128]; - extern sint32 gNetworkStartPort; - extern char* gNetworkStartAddress; +extern sint32 gNetworkStart; +extern char gNetworkStartHost[128]; +extern sint32 gNetworkStartPort; +extern char* gNetworkStartAddress; #endif - extern uint32 gCurrentDrawCount; - extern uint8 gScreenFlags; - extern uint32 gScreenAge; - extern uint8 gSavePromptMode; +extern uint32 gCurrentDrawCount; +extern uint8 gScreenFlags; +extern uint32 gScreenAge; +extern uint8 gSavePromptMode; - void openrct2_write_full_version_info(utf8 * buffer, size_t bufferSize); - void openrct2_finish(); +void openrct2_write_full_version_info(utf8 * buffer, size_t bufferSize); +void openrct2_finish(); - sint32 cmdline_run(const char * * argv, sint32 argc); +sint32 cmdline_run(const char * * argv, sint32 argc); -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/ParkImporter.cpp b/src/openrct2/ParkImporter.cpp index 13b3b8d62f..f6d1d4b3d9 100644 --- a/src/openrct2/ParkImporter.cpp +++ b/src/openrct2/ParkImporter.cpp @@ -65,39 +65,37 @@ ParkLoadResult ParkLoadResult::CreateUnsupportedRCTCflag(uint8 classic_flag) return ParkLoadResult(PARK_LOAD_ERROR::PARK_LOAD_ERROR_UNSUPPORTED_RCTC_FLAG, classic_flag); } -extern "C" +PARK_LOAD_ERROR ParkLoadResult_GetError(const ParkLoadResult * t) { - PARK_LOAD_ERROR ParkLoadResult_GetError(const ParkLoadResult * t) - { - return t->Error; - } - - size_t ParkLoadResult_GetMissingObjectsCount(const ParkLoadResult * t) - { - return t->MissingObjects.size(); - } - - uint8 ParkLoadResult_GetFlag(const ParkLoadResult * t) - { - return t->Flag; - } - - const rct_object_entry * ParkLoadResult_GetMissingObjects(const ParkLoadResult * t) - { - return t->MissingObjects.data(); - } - - void ParkLoadResult_Delete(ParkLoadResult * t) - { - delete t; - } - - ParkLoadResult * ParkLoadResult_CreateInvalidExtension() - { - return new ParkLoadResult(ParkLoadResult::CreateInvalidExtension()); - } + return t->Error; } +size_t ParkLoadResult_GetMissingObjectsCount(const ParkLoadResult * t) +{ + return t->MissingObjects.size(); +} + +uint8 ParkLoadResult_GetFlag(const ParkLoadResult * t) +{ + return t->Flag; +} + +const rct_object_entry * ParkLoadResult_GetMissingObjects(const ParkLoadResult * t) +{ + return t->MissingObjects.data(); +} + +void ParkLoadResult_Delete(ParkLoadResult * t) +{ + delete t; +} + +ParkLoadResult * ParkLoadResult_CreateInvalidExtension() +{ + return new ParkLoadResult(ParkLoadResult::CreateInvalidExtension()); +} + + namespace ParkImporter { IParkImporter * Create(const std::string &hintPath) @@ -136,22 +134,20 @@ namespace ParkImporter } } -extern "C" +void park_importer_load_from_stream(void * stream_c, const utf8 * hintPath_c) { - void park_importer_load_from_stream(void * stream_c, const utf8 * hintPath_c) - { - IStream * stream = (IStream *)stream_c; - std::string hintPath = String::ToStd(hintPath_c); + IStream * stream = (IStream *)stream_c; + std::string hintPath = String::ToStd(hintPath_c); - bool isScenario = ParkImporter::ExtensionIsScenario(hintPath); + bool isScenario = ParkImporter::ExtensionIsScenario(hintPath); - auto parkImporter = std::unique_ptr(ParkImporter::Create(hintPath)); - parkImporter->LoadFromStream((IStream *)stream, isScenario); - parkImporter->Import(); - } - - bool park_importer_extension_is_scenario(const utf8 * extension) - { - return ParkImporter::ExtensionIsScenario(String::ToStd(extension)); - } + auto parkImporter = std::unique_ptr(ParkImporter::Create(hintPath)); + parkImporter->LoadFromStream((IStream *)stream, isScenario); + parkImporter->Import(); } + +bool park_importer_extension_is_scenario(const utf8 * extension) +{ + return ParkImporter::ExtensionIsScenario(String::ToStd(extension)); +} + diff --git a/src/openrct2/ParkImporter.h b/src/openrct2/ParkImporter.h index 73e0a0bf47..6665c7f816 100644 --- a/src/openrct2/ParkImporter.h +++ b/src/openrct2/ParkImporter.h @@ -95,19 +95,13 @@ typedef struct ParkLoadResult ParkLoadResult; #endif -#ifdef __cplusplus -extern "C" -{ -#endif - void park_importer_load_from_stream(void * stream, const utf8 * hintPath); - bool park_importer_extension_is_scenario(const utf8 * extension); +void park_importer_load_from_stream(void * stream, const utf8 * hintPath); +bool park_importer_extension_is_scenario(const utf8 * extension); + +PARK_LOAD_ERROR ParkLoadResult_GetError(const ParkLoadResult * t); +size_t ParkLoadResult_GetMissingObjectsCount(const ParkLoadResult * t); +const rct_object_entry * ParkLoadResult_GetMissingObjects(const ParkLoadResult * t); +uint8 ParkLoadResult_GetFlag(const ParkLoadResult * t); +void ParkLoadResult_Delete(ParkLoadResult * t); +ParkLoadResult * ParkLoadResult_CreateInvalidExtension(); - PARK_LOAD_ERROR ParkLoadResult_GetError(const ParkLoadResult * t); - size_t ParkLoadResult_GetMissingObjectsCount(const ParkLoadResult * t); - const rct_object_entry * ParkLoadResult_GetMissingObjects(const ParkLoadResult * t); - uint8 ParkLoadResult_GetFlag(const ParkLoadResult * t); - void ParkLoadResult_Delete(ParkLoadResult * t); - ParkLoadResult * ParkLoadResult_CreateInvalidExtension(); -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/Version.cpp b/src/openrct2/Version.cpp index 55eda44ac5..e40b40dbbc 100644 --- a/src/openrct2/Version.cpp +++ b/src/openrct2/Version.cpp @@ -22,7 +22,6 @@ #include OPENRCT2_BUILD_INFO_HEADER #endif -extern "C" { const char gVersionInfoFull[] = OPENRCT2_NAME ", v" OPENRCT2_VERSION #ifdef OPENRCT2_BRANCH @@ -38,4 +37,3 @@ const char gVersionInfoFull[] = " (DEBUG)" #endif ; -} diff --git a/src/openrct2/Version.h b/src/openrct2/Version.h index 914062aa5e..aaeb797ab5 100644 --- a/src/openrct2/Version.h +++ b/src/openrct2/Version.h @@ -78,11 +78,4 @@ #define OPENRCT2_CUSTOM_INFO "" #endif -#ifdef __cplusplus -extern "C" -{ -#endif - extern const char gVersionInfoFull[]; -#ifdef __cplusplus -} -#endif +extern const char gVersionInfoFull[]; diff --git a/src/openrct2/actions/GameActionCompat.cpp b/src/openrct2/actions/GameActionCompat.cpp index 40eee2ce08..6b51871629 100644 --- a/src/openrct2/actions/GameActionCompat.cpp +++ b/src/openrct2/actions/GameActionCompat.cpp @@ -24,8 +24,6 @@ #include "RideSetName.hpp" #include "RideDemolishAction.hpp" -extern "C" -{ #pragma region PlaceParkEntranceAction money32 place_park_entrance(sint16 x, sint16 y, sint16 z, uint8 direction) { @@ -236,5 +234,3 @@ extern "C" } #pragma endregion - -} diff --git a/src/openrct2/audio/AudioMixer.h b/src/openrct2/audio/AudioMixer.h index f3cf76a018..5dbfd603d0 100644 --- a/src/openrct2/audio/AudioMixer.h +++ b/src/openrct2/audio/AudioMixer.h @@ -16,13 +16,7 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif - #include "../common.h" -#ifdef __cplusplus -} -#endif +#include "../common.h" #define MIXER_VOLUME_MAX 128 #define MIXER_LOOP_NONE 0 @@ -65,33 +59,27 @@ namespace OpenRCT2 { namespace Audio #endif -#ifdef __cplusplus -extern "C" -{ +#ifndef DSBPAN_LEFT +#define DSBPAN_LEFT -10000 #endif - #ifndef DSBPAN_LEFT - #define DSBPAN_LEFT -10000 - #endif - #ifndef DSBPAN_RIGHT - #define DSBPAN_RIGHT 10000 - #endif - - void Mixer_Init(const char * device); - void* Mixer_Play_Effect(size_t id, sint32 loop, sint32 volume, float pan, double rate, sint32 deleteondone); - void Mixer_Stop_Channel(void* channel); - void Mixer_Channel_Volume(void* channel, sint32 volume); - void Mixer_Channel_Pan(void* channel, float pan); - void Mixer_Channel_Rate(void* channel, double rate); - sint32 Mixer_Channel_IsPlaying(void* channel); - uint64 Mixer_Channel_GetOffset(void* channel); - sint32 Mixer_Channel_SetOffset(void* channel, uint64 offset); - void Mixer_Channel_SetGroup(void* channel, sint32 group); - void* Mixer_Play_Music(sint32 pathId, sint32 loop, sint32 streaming); - void Mixer_SetVolume(float volume); - - sint32 DStoMixerVolume(sint32 volume); - float DStoMixerPan(sint32 pan); - double DStoMixerRate(sint32 frequency); -#ifdef __cplusplus -} +#ifndef DSBPAN_RIGHT +#define DSBPAN_RIGHT 10000 #endif + +void Mixer_Init(const char * device); +void* Mixer_Play_Effect(size_t id, sint32 loop, sint32 volume, float pan, double rate, sint32 deleteondone); +void Mixer_Stop_Channel(void* channel); +void Mixer_Channel_Volume(void* channel, sint32 volume); +void Mixer_Channel_Pan(void* channel, float pan); +void Mixer_Channel_Rate(void* channel, double rate); +sint32 Mixer_Channel_IsPlaying(void* channel); +uint64 Mixer_Channel_GetOffset(void* channel); +sint32 Mixer_Channel_SetOffset(void* channel, uint64 offset); +void Mixer_Channel_SetGroup(void* channel, sint32 group); +void* Mixer_Play_Music(sint32 pathId, sint32 loop, sint32 streaming); +void Mixer_SetVolume(float volume); + +sint32 DStoMixerVolume(sint32 volume); +float DStoMixerPan(sint32 pan); +double DStoMixerRate(sint32 frequency); + diff --git a/src/openrct2/audio/audio.h b/src/openrct2/audio/audio.h index 6f99ac0f78..cb61b26abb 100644 --- a/src/openrct2/audio/audio.h +++ b/src/openrct2/audio/audio.h @@ -18,11 +18,6 @@ #include "../common.h" -#ifdef __cplusplus -extern "C" -{ -#endif - #define AUDIO_DEVICE_NAME_SIZE 256 #define AUDIO_MAX_RIDE_MUSIC 2 #define AUDIO_MAX_VEHICLE_SOUNDS 14 @@ -258,7 +253,3 @@ void audio_toggle_all_sounds(); void audio_unpause_sounds(); void audio_stop_all_music_and_sounds(); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/cmdline/CommandLine.cpp b/src/openrct2/cmdline/CommandLine.cpp index 52d0737837..56b8410c22 100644 --- a/src/openrct2/cmdline/CommandLine.cpp +++ b/src/openrct2/cmdline/CommandLine.cpp @@ -555,38 +555,36 @@ namespace CommandLine } } -extern "C" +sint32 cmdline_run(const char * * argv, sint32 argc) { - sint32 cmdline_run(const char * * argv, sint32 argc) + auto argEnumerator = CommandLineArgEnumerator(argv, argc); + + // Pop process path + argEnumerator.TryPop(); + + const CommandLineCommand * command = CommandLine::FindCommandFor(CommandLine::RootCommands, &argEnumerator); + + if (command == nullptr) { - auto argEnumerator = CommandLineArgEnumerator(argv, argc); + return EXITCODE_FAIL; + } - // Pop process path - argEnumerator.TryPop(); - - const CommandLineCommand * command = CommandLine::FindCommandFor(CommandLine::RootCommands, &argEnumerator); - - if (command == nullptr) + if (command->Options != nullptr) + { + auto argEnumeratorForOptions = CommandLineArgEnumerator(argEnumerator); + if (!CommandLine::ParseOptions(command->Options, &argEnumeratorForOptions)) { return EXITCODE_FAIL; } + } - if (command->Options != nullptr) - { - auto argEnumeratorForOptions = CommandLineArgEnumerator(argEnumerator); - if (!CommandLine::ParseOptions(command->Options, &argEnumeratorForOptions)) - { - return EXITCODE_FAIL; - } - } - - if (command == CommandLine::RootCommands && command->Func == nullptr) - { - return CommandLine::HandleCommandDefault(); - } - else - { - return command->Func(&argEnumerator); - } + if (command == CommandLine::RootCommands && command->Func == nullptr) + { + return CommandLine::HandleCommandDefault(); + } + else + { + return command->Func(&argEnumerator); } } + diff --git a/src/openrct2/cmdline/SpriteCommands.cpp b/src/openrct2/cmdline/SpriteCommands.cpp index e23b70ad78..775a526828 100644 --- a/src/openrct2/cmdline/SpriteCommands.cpp +++ b/src/openrct2/cmdline/SpriteCommands.cpp @@ -23,10 +23,7 @@ #define SZ_CLOSEST "closest" #define SZ_DITHERING "dithering" -extern "C" -{ sint32 gSpriteMode = 0; -} static const char * _mode; diff --git a/src/openrct2/common.h b/src/openrct2/common.h index 94a767164e..df8f1fac70 100644 --- a/src/openrct2/common.h +++ b/src/openrct2/common.h @@ -141,13 +141,7 @@ typedef uint8 colour_t; #endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) #if !((defined (_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700)) -#ifdef __cplusplus -extern "C" { -#endif char *strndup(const char *src, size_t size); -#ifdef __cplusplus -} -#endif #endif // !(POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700) // BSD and macOS have MAP_ANON instead of MAP_ANONYMOUS diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index e632f67192..77d54e3732 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -642,130 +642,128 @@ namespace Config } } -extern "C" -{ - GeneralConfiguration gConfigGeneral; - InterfaceConfiguration gConfigInterface; - SoundConfiguration gConfigSound; - TwitchConfiguration gConfigTwitch; - NetworkConfiguration gConfigNetwork; - NotificationConfiguration gConfigNotifications; - FontConfiguration gConfigFonts; +GeneralConfiguration gConfigGeneral; +InterfaceConfiguration gConfigInterface; +SoundConfiguration gConfigSound; +TwitchConfiguration gConfigTwitch; +NetworkConfiguration gConfigNetwork; +NotificationConfiguration gConfigNotifications; +FontConfiguration gConfigFonts; - void config_set_defaults() +void config_set_defaults() +{ + config_release(); + Config::SetDefaults(); +} + +bool config_open(const utf8 * path) +{ + if (!File::Exists(path)) { - config_release(); - Config::SetDefaults(); + return false; } - bool config_open(const utf8 * path) + config_release(); + auto result = Config::ReadFile(path); + if (result) { - if (!File::Exists(path)) + currency_load_custom_currency_config(); + } + return result; +} + +bool config_save(const utf8 * path) +{ + return Config::WriteFile(path); +} + +void config_release() +{ + SafeFree(gConfigGeneral.rct1_path); + SafeFree(gConfigGeneral.rct2_path); + SafeFree(gConfigGeneral.custom_currency_symbol); + SafeFree(gConfigGeneral.last_save_game_directory); + SafeFree(gConfigGeneral.last_save_landscape_directory); + SafeFree(gConfigGeneral.last_save_scenario_directory); + SafeFree(gConfigGeneral.last_save_track_directory); + SafeFree(gConfigGeneral.last_run_version); + SafeFree(gConfigInterface.current_theme_preset); + SafeFree(gConfigInterface.current_title_sequence_preset); + SafeFree(gConfigSound.device); + SafeFree(gConfigTwitch.channel); + SafeFree(gConfigNetwork.player_name); + SafeFree(gConfigNetwork.listen_address); + SafeFree(gConfigNetwork.default_password); + SafeFree(gConfigNetwork.server_name); + SafeFree(gConfigNetwork.server_description); + SafeFree(gConfigNetwork.server_greeting); + SafeFree(gConfigNetwork.master_server_url); + SafeFree(gConfigNetwork.provider_name); + SafeFree(gConfigNetwork.provider_email); + SafeFree(gConfigNetwork.provider_website); + SafeFree(gConfigFonts.file_name); + SafeFree(gConfigFonts.font_name); +} + +void config_get_default_path(utf8 * outPath, size_t size) +{ + platform_get_user_directory(outPath, nullptr, size); + Path::Append(outPath, size, "config.ini"); +} + +bool config_save_default() +{ + utf8 path[MAX_PATH]; + config_get_default_path(path, sizeof(path)); + return config_save(path); +} + +bool config_find_or_browse_install_directory() +{ + std::string path = Config::FindRCT2Path(); + if (!path.empty()) + { + Memory::Free(gConfigGeneral.rct2_path); + gConfigGeneral.rct2_path = String::Duplicate(path.c_str()); + } + else + { + if (gOpenRCT2Headless) { return false; } - config_release(); - auto result = Config::ReadFile(path); - if (result) + try { - currency_load_custom_currency_config(); - } - return result; - } - - bool config_save(const utf8 * path) - { - return Config::WriteFile(path); - } - - void config_release() - { - SafeFree(gConfigGeneral.rct1_path); - SafeFree(gConfigGeneral.rct2_path); - SafeFree(gConfigGeneral.custom_currency_symbol); - SafeFree(gConfigGeneral.last_save_game_directory); - SafeFree(gConfigGeneral.last_save_landscape_directory); - SafeFree(gConfigGeneral.last_save_scenario_directory); - SafeFree(gConfigGeneral.last_save_track_directory); - SafeFree(gConfigGeneral.last_run_version); - SafeFree(gConfigInterface.current_theme_preset); - SafeFree(gConfigInterface.current_title_sequence_preset); - SafeFree(gConfigSound.device); - SafeFree(gConfigTwitch.channel); - SafeFree(gConfigNetwork.player_name); - SafeFree(gConfigNetwork.listen_address); - SafeFree(gConfigNetwork.default_password); - SafeFree(gConfigNetwork.server_name); - SafeFree(gConfigNetwork.server_description); - SafeFree(gConfigNetwork.server_greeting); - SafeFree(gConfigNetwork.master_server_url); - SafeFree(gConfigNetwork.provider_name); - SafeFree(gConfigNetwork.provider_email); - SafeFree(gConfigNetwork.provider_website); - SafeFree(gConfigFonts.file_name); - SafeFree(gConfigFonts.font_name); - } - - void config_get_default_path(utf8 * outPath, size_t size) - { - platform_get_user_directory(outPath, nullptr, size); - Path::Append(outPath, size, "config.ini"); - } - - bool config_save_default() - { - utf8 path[MAX_PATH]; - config_get_default_path(path, sizeof(path)); - return config_save(path); - } - - bool config_find_or_browse_install_directory() - { - std::string path = Config::FindRCT2Path(); - if (!path.empty()) - { - Memory::Free(gConfigGeneral.rct2_path); - gConfigGeneral.rct2_path = String::Duplicate(path.c_str()); - } - else - { - if (gOpenRCT2Headless) + while (true) { - return false; - } + IUiContext * uiContext = GetContext()->GetUiContext(); + uiContext->ShowMessageBox("OpenRCT2 needs files from the original RollerCoaster Tycoon 2 in order to work. \nPlease select the directory where you installed RollerCoaster Tycoon 2."); - try - { - while (true) + std::string installPath = uiContext->ShowDirectoryDialog("Please select your RCT2 directory"); + if (installPath.empty()) { - IUiContext * uiContext = GetContext()->GetUiContext(); - uiContext->ShowMessageBox("OpenRCT2 needs files from the original RollerCoaster Tycoon 2 in order to work. \nPlease select the directory where you installed RollerCoaster Tycoon 2."); - - std::string installPath = uiContext->ShowDirectoryDialog("Please select your RCT2 directory"); - if (installPath.empty()) - { - return false; - } - - Memory::Free(gConfigGeneral.rct2_path); - gConfigGeneral.rct2_path = String::Duplicate(installPath.c_str()); - - if (platform_original_game_data_exists(installPath.c_str())) - { - return true; - } - - std::string message = String::StdFormat("Could not find %s" PATH_SEPARATOR "Data" PATH_SEPARATOR "g1.dat at this path", installPath.c_str()); - uiContext->ShowMessageBox(message); + return false; } - } - catch (const std::exception &ex) - { - Console::Error::WriteLine(ex.what()); - return false; + + Memory::Free(gConfigGeneral.rct2_path); + gConfigGeneral.rct2_path = String::Duplicate(installPath.c_str()); + + if (platform_original_game_data_exists(installPath.c_str())) + { + return true; + } + + std::string message = String::StdFormat("Could not find %s" PATH_SEPARATOR "Data" PATH_SEPARATOR "g1.dat at this path", installPath.c_str()); + uiContext->ShowMessageBox(message); } } - return true; + catch (const std::exception &ex) + { + Console::Error::WriteLine(ex.what()); + return false; + } } + return true; } + diff --git a/src/openrct2/config/Config.h b/src/openrct2/config/Config.h index b166f84924..28f3888d79 100644 --- a/src/openrct2/config/Config.h +++ b/src/openrct2/config/Config.h @@ -234,25 +234,18 @@ enum }; #endif -#ifdef __cplusplus -extern "C" -{ -#endif - extern GeneralConfiguration gConfigGeneral; - extern InterfaceConfiguration gConfigInterface; - extern SoundConfiguration gConfigSound; - extern TwitchConfiguration gConfigTwitch; - extern NetworkConfiguration gConfigNetwork; - extern NotificationConfiguration gConfigNotifications; - extern FontConfiguration gConfigFonts; +extern GeneralConfiguration gConfigGeneral; +extern InterfaceConfiguration gConfigInterface; +extern SoundConfiguration gConfigSound; +extern TwitchConfiguration gConfigTwitch; +extern NetworkConfiguration gConfigNetwork; +extern NotificationConfiguration gConfigNotifications; +extern FontConfiguration gConfigFonts; - bool config_open(const utf8 * path); - bool config_save(const utf8 * path); - void config_get_default_path(utf8 *outPath, size_t size); - void config_set_defaults(); - void config_release(); - bool config_save_default(); - bool config_find_or_browse_install_directory(); -#ifdef __cplusplus -} -#endif +bool config_open(const utf8 * path); +bool config_save(const utf8 * path); +void config_get_default_path(utf8 *outPath, size_t size); +void config_set_defaults(); +void config_release(); +bool config_save_default(); +bool config_find_or_browse_install_directory(); diff --git a/src/openrct2/core/Console.hpp b/src/openrct2/core/Console.hpp index bb7d69468c..7a397f6739 100644 --- a/src/openrct2/core/Console.hpp +++ b/src/openrct2/core/Console.hpp @@ -16,10 +16,7 @@ #pragma once -extern "C" -{ - #include "../common.h" -} +#include "../common.h" #include diff --git a/src/openrct2/core/File.cpp b/src/openrct2/core/File.cpp index aea292af82..9cd38c2a70 100644 --- a/src/openrct2/core/File.cpp +++ b/src/openrct2/core/File.cpp @@ -134,31 +134,29 @@ namespace File } } -extern "C" +bool readentirefile(const utf8 * path, void * * outBuffer, size_t * outLength) { - bool readentirefile(const utf8 * path, void * * outBuffer, size_t * outLength) + try { - try - { - *outBuffer = File::ReadAllBytes(String::ToStd(path), outLength); - return true; - } - catch (const std::exception &) - { - return false; - } + *outBuffer = File::ReadAllBytes(String::ToStd(path), outLength); + return true; } - - bool writeentirefile(const utf8 * path, const void * buffer, size_t length) + catch (const std::exception &) { - try - { - File::WriteAllBytes(String::ToStd(path), buffer, length); - return true; - } - catch (const std::exception &) - { - return false; - } + return false; } } + +bool writeentirefile(const utf8 * path, const void * buffer, size_t length) +{ + try + { + File::WriteAllBytes(String::ToStd(path), buffer, length); + return true; + } + catch (const std::exception &) + { + return false; + } +} + diff --git a/src/openrct2/core/Guard.cpp b/src/openrct2/core/Guard.cpp index 833e51f7ec..127c2962c1 100644 --- a/src/openrct2/core/Guard.cpp +++ b/src/openrct2/core/Guard.cpp @@ -31,17 +31,15 @@ #include "Guard.hpp" #include "String.hpp" -extern "C" +void openrct2_assert_fwd(bool expression, const char * message, ...) { - void openrct2_assert_fwd(bool expression, const char * message, ...) - { - va_list va; - va_start(va, message); - Guard::Assert_VA(expression, message, va); - va_end(va); - } + va_list va; + va_start(va, message); + Guard::Assert_VA(expression, message, va); + va_end(va); } + namespace Guard { constexpr const utf8 * ASSERTION_MESSAGE = "An assertion failed, please report this to the OpenRCT2 developers."; diff --git a/src/openrct2/core/Guard.hpp b/src/openrct2/core/Guard.hpp index 01469f0c73..24a3465fa4 100644 --- a/src/openrct2/core/Guard.hpp +++ b/src/openrct2/core/Guard.hpp @@ -19,17 +19,10 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - void openrct2_assert_fwd(bool expression, const char * message, ...); #define openrct2_assert(expr, msg, ...) if(!(expr)) { openrct2_assert_fwd((expr), msg, ##__VA_ARGS__); } -#ifdef __cplusplus -} - enum class ASSERT_BEHAVIOUR { ABORT, @@ -70,5 +63,3 @@ namespace Guard } #define GUARD_LINE "Location: %s:%d", __func__, __LINE__ - -#endif // __cplusplus diff --git a/src/openrct2/core/ZipAndroid.cpp b/src/openrct2/core/ZipAndroid.cpp index 59bd4c43b1..55c69e9b48 100644 --- a/src/openrct2/core/ZipAndroid.cpp +++ b/src/openrct2/core/ZipAndroid.cpp @@ -154,13 +154,9 @@ namespace Zip { } } -extern "C" { - JNIEXPORT jlong JNICALL Java_website_openrct2_ZipArchive_allocBytes(JNIEnv *env, jclass, jbyteArray input, jint numBytes); -} - JNIEXPORT jlong JNICALL Java_website_openrct2_ZipArchive_allocBytes(JNIEnv *env, jclass, jbyteArray input, diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index b06c3b892c..4c2e0d3c04 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -26,9 +26,6 @@ #include "../world/Water.h" #include "Drawing.h" -extern "C" -{ - // HACK These were originally passed back through registers sint32 gLastDrawStringX; sint32 gLastDrawStringY; @@ -660,4 +657,3 @@ void gfx_draw_pickedup_peep(rct_drawpixelinfo *dpi) } } -} diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index 234f0dc930..4551eff1b0 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -243,10 +243,6 @@ typedef struct rct_size16 #define MAX_SCROLLING_TEXT_MODES 38 -#ifdef __cplusplus -extern "C" { -#endif - extern sint16 gCurrentFontSpriteBase; extern uint16 gCurrentFontFlags; @@ -371,10 +367,6 @@ void mask_init(); extern void (*mask_fn)(sint32 width, sint32 height, const uint8 * RESTRICT maskSrc, const uint8 * RESTRICT colourSrc, uint8 * RESTRICT dst, sint32 maskWrap, sint32 colourWrap, sint32 dstWrap); -#ifdef __cplusplus -} -#endif - #include "NewDrawing.h" #endif diff --git a/src/openrct2/drawing/DrawingFast.cpp b/src/openrct2/drawing/DrawingFast.cpp index fc66358ac9..f0f5dd4787 100644 --- a/src/openrct2/drawing/DrawingFast.cpp +++ b/src/openrct2/drawing/DrawingFast.cpp @@ -173,41 +173,39 @@ static void FASTCALL DrawRLESprite1(const uint8* source_bits_pointer, #define DrawRLESpriteHelper1(image_type) \ DrawRLESprite1(source_bits_pointer, dest_bits_pointer, palette_pointer, dpi, source_y_start, height, source_x_start, width) -extern "C" +/** + * Transfers readied images onto buffers + * This function copies the sprite data onto the screen + * rct2: 0x0067AA18 + */ +void FASTCALL gfx_rle_sprite_to_buffer(const uint8* RESTRICT source_bits_pointer, + uint8* RESTRICT dest_bits_pointer, + const uint8* RESTRICT palette_pointer, + const rct_drawpixelinfo * RESTRICT dpi, + sint32 image_type, + sint32 source_y_start, + sint32 height, + sint32 source_x_start, + sint32 width) { - /** - * Transfers readied images onto buffers - * This function copies the sprite data onto the screen - * rct2: 0x0067AA18 - */ - void FASTCALL gfx_rle_sprite_to_buffer(const uint8* RESTRICT source_bits_pointer, - uint8* RESTRICT dest_bits_pointer, - const uint8* RESTRICT palette_pointer, - const rct_drawpixelinfo * RESTRICT dpi, - sint32 image_type, - sint32 source_y_start, - sint32 height, - sint32 source_x_start, - sint32 width) + if (image_type & IMAGE_TYPE_REMAP) { - if (image_type & IMAGE_TYPE_REMAP) + if (image_type & IMAGE_TYPE_TRANSPARENT) { - if (image_type & IMAGE_TYPE_TRANSPARENT) - { - DrawRLESpriteHelper1(IMAGE_TYPE_REMAP | IMAGE_TYPE_TRANSPARENT); - } - else - { - DrawRLESpriteHelper1(IMAGE_TYPE_REMAP); - } - } - else if (image_type & IMAGE_TYPE_TRANSPARENT) - { - DrawRLESpriteHelper1(IMAGE_TYPE_TRANSPARENT); + DrawRLESpriteHelper1(IMAGE_TYPE_REMAP | IMAGE_TYPE_TRANSPARENT); } else { - DrawRLESpriteHelper1(IMAGE_TYPE_DEFAULT); + DrawRLESpriteHelper1(IMAGE_TYPE_REMAP); } } + else if (image_type & IMAGE_TYPE_TRANSPARENT) + { + DrawRLESpriteHelper1(IMAGE_TYPE_TRANSPARENT); + } + else + { + DrawRLESpriteHelper1(IMAGE_TYPE_DEFAULT); + } } + diff --git a/src/openrct2/drawing/Font.cpp b/src/openrct2/drawing/Font.cpp index 9aebdd34cf..b2ef18a576 100644 --- a/src/openrct2/drawing/Font.cpp +++ b/src/openrct2/drawing/Font.cpp @@ -27,9 +27,6 @@ static constexpr const sint32 SpriteFontLineHeight[] = { 6, 10, 10, 18 }; static uint8 _spriteFontCharacterWidths[896]; -extern "C" -{ - #ifndef NO_TTF TTFFontSetDescriptor *gCurrentTTFFontSet; #endif // NO_TTF @@ -275,5 +272,3 @@ bool font_supports_string(const utf8 *text, sint32 fontSize) return font_supports_string_sprite(text); } } - -} diff --git a/src/openrct2/drawing/Font.h b/src/openrct2/drawing/Font.h index 58240685da..c7f7e219bb 100644 --- a/src/openrct2/drawing/Font.h +++ b/src/openrct2/drawing/Font.h @@ -56,20 +56,10 @@ typedef struct TTFFontSetDescriptor { TTFFontDescriptor size[FONT_SIZE_COUNT]; } TTFFontSetDescriptor; -#ifdef __cplusplus -extern "C" { -#endif extern TTFFontSetDescriptor *gCurrentTTFFontSet; -#ifdef __cplusplus -} -#endif #endif // NO_TTF -#ifdef __cplusplus -extern "C" { -#endif - void font_sprite_initialise_characters(); sint32 font_sprite_get_codepoint_offset(sint32 codepoint); sint32 font_sprite_get_codepoint_width(uint16 fontSpriteBase, sint32 codepoint); @@ -81,8 +71,4 @@ bool font_supports_string_sprite(const utf8 *text); bool font_supports_string_ttf(const utf8 *text, sint32 fontSize); bool font_supports_string(const utf8 *text, sint32 fontSize); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/drawing/Image.cpp b/src/openrct2/drawing/Image.cpp index f6e6971e2a..8441f0c94b 100644 --- a/src/openrct2/drawing/Image.cpp +++ b/src/openrct2/drawing/Image.cpp @@ -201,60 +201,58 @@ static void FreeImageList(uint32 baseImageId, uint32 count) _freeLists.push_back({ baseImageId, count }); } -extern "C" +uint32 gfx_object_allocate_images(const rct_g1_element * images, uint32 count) { - uint32 gfx_object_allocate_images(const rct_g1_element * images, uint32 count) + if (count == 0 || gOpenRCT2NoGraphics) { - if (count == 0 || gOpenRCT2NoGraphics) - { - return INVALID_IMAGE_ID; - } + return INVALID_IMAGE_ID; + } - uint32 baseImageId = AllocateImageList(count); - if (baseImageId == INVALID_IMAGE_ID) - { - log_error("Reached maximum image limit."); - return INVALID_IMAGE_ID; - } + uint32 baseImageId = AllocateImageList(count); + if (baseImageId == INVALID_IMAGE_ID) + { + log_error("Reached maximum image limit."); + return INVALID_IMAGE_ID; + } - uint32 imageId = baseImageId; + uint32 imageId = baseImageId; + for (uint32 i = 0; i < count; i++) + { + gfx_set_g1_element(imageId, &images[i]); + drawing_engine_invalidate_image(imageId); + imageId++; + } + + return baseImageId; +} + +void gfx_object_free_images(uint32 baseImageId, uint32 count) +{ + if (baseImageId != 0 && baseImageId != INVALID_IMAGE_ID) + { + // Zero the G1 elements so we don't have invalid pointers + // and data lying about for (uint32 i = 0; i < count; i++) { - gfx_set_g1_element(imageId, &images[i]); + uint32 imageId = baseImageId + i; + rct_g1_element g1 = { nullptr }; + gfx_set_g1_element(imageId, &g1); drawing_engine_invalidate_image(imageId); - imageId++; } - return baseImageId; - } - - void gfx_object_free_images(uint32 baseImageId, uint32 count) - { - if (baseImageId != 0 && baseImageId != INVALID_IMAGE_ID) - { - // Zero the G1 elements so we don't have invalid pointers - // and data lying about - for (uint32 i = 0; i < count; i++) - { - uint32 imageId = baseImageId + i; - rct_g1_element g1 = { nullptr }; - gfx_set_g1_element(imageId, &g1); - drawing_engine_invalidate_image(imageId); - } - - FreeImageList(baseImageId, count); - } - } - - void gfx_object_check_all_images_freed() - { - if (_allocatedImageCount != 0) - { -#ifdef DEBUG - Guard::Assert(_allocatedImageCount == 0, "%u images were not freed", _allocatedImageCount); -#else - Console::Error::WriteLine("%u images were not freed", _allocatedImageCount); -#endif - } + FreeImageList(baseImageId, count); } } + +void gfx_object_check_all_images_freed() +{ + if (_allocatedImageCount != 0) + { +#ifdef DEBUG + Guard::Assert(_allocatedImageCount == 0, "%u images were not freed", _allocatedImageCount); +#else + Console::Error::WriteLine("%u images were not freed", _allocatedImageCount); +#endif + } +} + diff --git a/src/openrct2/drawing/LightFX.cpp b/src/openrct2/drawing/LightFX.cpp index 64f39b8902..865ae954c0 100644 --- a/src/openrct2/drawing/LightFX.cpp +++ b/src/openrct2/drawing/LightFX.cpp @@ -29,9 +29,6 @@ #include "Drawing.h" #include "LightFX.h" -extern "C" -{ - static uint8 _bakedLightTexture_lantern_0[32*32]; static uint8 _bakedLightTexture_lantern_1[64*64]; static uint8 _bakedLightTexture_lantern_2[128*128]; @@ -1018,6 +1015,4 @@ void lightfx_render_to_texture( } } -} - #endif // __ENABLE_LIGHTFX__ diff --git a/src/openrct2/drawing/LightFX.h b/src/openrct2/drawing/LightFX.h index d854bbe340..278b9e36ec 100644 --- a/src/openrct2/drawing/LightFX.h +++ b/src/openrct2/drawing/LightFX.h @@ -45,10 +45,6 @@ enum LIGHTFX_LIGHT_QUALIFIER { LIGHTFX_LIGHT_QUALIFIER_MAP = 0x2 }; -#ifdef __cplusplus -extern "C" { -#endif - void lightfx_set_available(bool available); bool lightfx_is_available(); @@ -82,10 +78,6 @@ void lightfx_render_to_texture( const uint32 * palette, const uint32 * lightPalette); -#ifdef __cplusplus -} -#endif - #endif // __ENABLE_LIGHTFX__ #endif diff --git a/src/openrct2/drawing/Line.cpp b/src/openrct2/drawing/Line.cpp index ea080192b8..30add7d39e 100644 --- a/src/openrct2/drawing/Line.cpp +++ b/src/openrct2/drawing/Line.cpp @@ -16,9 +16,6 @@ #include "Drawing.h" -extern "C" -{ - /** * Draws a horizontal line of specified colour to a buffer. * rct2: 0x0068474C @@ -145,5 +142,3 @@ void gfx_draw_line_software(rct_drawpixelinfo *dpi, sint32 x1, sint32 y1, sint32 } } } - -} diff --git a/src/openrct2/drawing/NewDrawing.cpp b/src/openrct2/drawing/NewDrawing.cpp index bd7cfef1e5..9f02d6ebaa 100644 --- a/src/openrct2/drawing/NewDrawing.cpp +++ b/src/openrct2/drawing/NewDrawing.cpp @@ -38,59 +38,87 @@ static IDrawingEngine * _drawingEngine = nullptr; // TODO move this to Context static Painter * _painter = nullptr; -extern "C" +rct_string_id DrawingEngineStringIds[] = { - rct_string_id DrawingEngineStringIds[] = - { - STR_DRAWING_ENGINE_SOFTWARE, - STR_DRAWING_ENGINE_SOFTWARE_WITH_HARDWARE_DISPLAY, - STR_DRAWING_ENGINE_OPENGL, - }; + STR_DRAWING_ENGINE_SOFTWARE, + STR_DRAWING_ENGINE_SOFTWARE_WITH_HARDWARE_DISPLAY, + STR_DRAWING_ENGINE_OPENGL, +}; + +sint32 drawing_engine_get_type() +{ + return _drawingEngineType; } -extern "C" +bool drawing_engine_requires_new_window(sint32 srcEngine, sint32 dstEngine) { - sint32 drawing_engine_get_type() - { - return _drawingEngineType; - } - - bool drawing_engine_requires_new_window(sint32 srcEngine, sint32 dstEngine) - { #ifdef _WIN32 - if (srcEngine != DRAWING_ENGINE_OPENGL && dstEngine != DRAWING_ENGINE_OPENGL) - { - // Windows is apparently able to switch to hardware rendering on the fly although - // using the same window in an unaccelerated and accelerated context is unsupported by SDL2 - return false; - } + if (srcEngine != DRAWING_ENGINE_OPENGL && dstEngine != DRAWING_ENGINE_OPENGL) + { + // Windows is apparently able to switch to hardware rendering on the fly although + // using the same window in an unaccelerated and accelerated context is unsupported by SDL2 + return false; + } #endif - return true; - } + return true; +} - void drawing_engine_init() +void drawing_engine_init() +{ + assert(_drawingEngine == nullptr); + assert(_painter == nullptr); + + _drawingEngineType = gConfigGeneral.drawing_engine; + + auto context = GetContext(); + auto uiContext = context->GetUiContext(); + auto drawingEngine = uiContext->CreateDrawingEngine((DRAWING_ENGINE_TYPE)_drawingEngineType); + + if (drawingEngine == nullptr) { - assert(_drawingEngine == nullptr); - assert(_painter == nullptr); - - _drawingEngineType = gConfigGeneral.drawing_engine; - - auto context = GetContext(); - auto uiContext = context->GetUiContext(); - auto drawingEngine = uiContext->CreateDrawingEngine((DRAWING_ENGINE_TYPE)_drawingEngineType); - - if (drawingEngine == nullptr) + if (_drawingEngineType == DRAWING_ENGINE_SOFTWARE) { + _drawingEngineType = DRAWING_ENGINE_NONE; + log_fatal("Unable to create a drawing engine."); + exit(-1); + } + else + { + log_error("Unable to create drawing engine. Falling back to software."); + + // Fallback to software + gConfigGeneral.drawing_engine = DRAWING_ENGINE_SOFTWARE; + config_save_default(); + drawing_engine_init(); + } + } + else + { + _painter = new Painter(uiContext); + try + { + drawingEngine->Initialise(); + drawingEngine->SetVSync(gConfigGeneral.use_vsync); + _drawingEngine = drawingEngine; + } + catch (const std::exception &ex) + { + delete _painter; + _painter = nullptr; + delete drawingEngine; + drawingEngine = nullptr; if (_drawingEngineType == DRAWING_ENGINE_SOFTWARE) { _drawingEngineType = DRAWING_ENGINE_NONE; - log_fatal("Unable to create a drawing engine."); + log_error(ex.what()); + log_fatal("Unable to initialise a drawing engine."); exit(-1); } else { - log_error("Unable to create drawing engine. Falling back to software."); + log_error(ex.what()); + log_error("Unable to initialise drawing engine. Falling back to software."); // Fallback to software gConfigGeneral.drawing_engine = DRAWING_ENGINE_SOFTWARE; @@ -98,207 +126,174 @@ extern "C" drawing_engine_init(); } } - else - { - _painter = new Painter(uiContext); - try - { - drawingEngine->Initialise(); - drawingEngine->SetVSync(gConfigGeneral.use_vsync); - _drawingEngine = drawingEngine; - } - catch (const std::exception &ex) - { - delete _painter; - _painter = nullptr; - delete drawingEngine; - drawingEngine = nullptr; - if (_drawingEngineType == DRAWING_ENGINE_SOFTWARE) - { - _drawingEngineType = DRAWING_ENGINE_NONE; - log_error(ex.what()); - log_fatal("Unable to initialise a drawing engine."); - exit(-1); - } - else - { - log_error(ex.what()); - log_error("Unable to initialise drawing engine. Falling back to software."); - - // Fallback to software - gConfigGeneral.drawing_engine = DRAWING_ENGINE_SOFTWARE; - config_save_default(); - drawing_engine_init(); - } - } - } - } - - void drawing_engine_resize() - { - if (_drawingEngine != nullptr) - { - IUiContext * uiContext = GetContext()->GetUiContext(); - _drawingEngine->Resize(uiContext->GetWidth(), uiContext->GetHeight()); - } - } - - void drawing_engine_set_palette(const rct_palette_entry * colours) - { - if (_drawingEngine != nullptr) - { - _drawingEngine->SetPalette(colours); - } - } - - void drawing_engine_draw() - { - if (_drawingEngine != nullptr && _painter != nullptr) - { - _drawingEngine->BeginDraw(); - _painter->Paint(_drawingEngine); - _drawingEngine->EndDraw(); - } - } - - void drawing_engine_copy_rect(sint32 x, sint32 y, sint32 width, sint32 height, sint32 dx, sint32 dy) - { - if (_drawingEngine != nullptr) - { - _drawingEngine->CopyRect(x, y, width, height, dx, dy); - } - } - - void drawing_engine_dispose() - { - delete _drawingEngine; - delete _painter; - _drawingEngine = nullptr; - _painter = nullptr; - } - - rct_drawpixelinfo * drawing_engine_get_dpi() - { - assert(_drawingEngine != nullptr); - return _drawingEngine->GetDrawingPixelInfo(); - } - - bool drawing_engine_has_dirty_optimisations() - { - bool result = false; - if (_drawingEngine != nullptr) - { - result = (_drawingEngine->GetFlags() & DEF_DIRTY_OPTIMISATIONS); - } - return result; - } - - void drawing_engine_invalidate_image(uint32 image) - { - if (_drawingEngine != nullptr) - { - _drawingEngine->InvalidateImage(image); - } - } - - void drawing_engine_set_vsync(bool vsync) - { - if (_drawingEngine != nullptr) - { - _drawingEngine->SetVSync(vsync); - } - } - - void gfx_set_dirty_blocks(sint16 left, sint16 top, sint16 right, sint16 bottom) - { - if (_drawingEngine != nullptr) - { - _drawingEngine->Invalidate(left, top, right, bottom); - } - } - - void gfx_draw_all_dirty_blocks() - { - } - - void gfx_clear(rct_drawpixelinfo * dpi, uint8 paletteIndex) - { - if (_drawingEngine != nullptr) - { - IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); - dc->Clear(paletteIndex); - } - } - - void gfx_fill_rect(rct_drawpixelinfo * dpi, sint32 left, sint32 top, sint32 right, sint32 bottom, sint32 colour) - { - if (_drawingEngine != nullptr) - { - IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); - dc->FillRect(colour, left, top, right, bottom); - } - } - - void gfx_filter_rect(rct_drawpixelinfo * dpi, sint32 left, sint32 top, sint32 right, sint32 bottom, FILTER_PALETTE_ID palette) - { - if (_drawingEngine != nullptr) - { - IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); - dc->FilterRect(palette, left, top, right, bottom); - } - } - - void gfx_draw_line(rct_drawpixelinfo *dpi, sint32 x1, sint32 y1, sint32 x2, sint32 y2, sint32 colour) - { - if (_drawingEngine != nullptr) - { - IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); - dc->DrawLine(colour, x1, y1, x2, y2); - } - } - - void FASTCALL gfx_draw_sprite(rct_drawpixelinfo * dpi, sint32 image, sint32 x, sint32 y, uint32 tertiary_colour) - { - if (_drawingEngine != nullptr) - { - IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); - dc->DrawSprite(image, x, y, tertiary_colour); - } - } - - void FASTCALL gfx_draw_glpyh(rct_drawpixelinfo * dpi, sint32 image, sint32 x, sint32 y, uint8 * palette) - { - if (_drawingEngine != nullptr) - { - IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); - dc->DrawGlyph(image, x, y, palette); - } - } - - void FASTCALL gfx_draw_sprite_raw_masked(rct_drawpixelinfo * dpi, sint32 x, sint32 y, sint32 maskImage, sint32 colourImage) - { - if (_drawingEngine != nullptr) - { - IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); - dc->DrawSpriteRawMasked(x, y, maskImage, colourImage); - } - } - - void FASTCALL gfx_draw_sprite_solid(rct_drawpixelinfo * dpi, sint32 image, sint32 x, sint32 y, uint8 colour) - { - if (_drawingEngine != nullptr) - { - IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); - dc->DrawSpriteSolid(image, x, y, colour); - } - } - - sint32 screenshot_dump() - { - if (_drawingEngine != nullptr) - { - return _drawingEngine->Screenshot(); - } - return false; } } + +void drawing_engine_resize() +{ + if (_drawingEngine != nullptr) + { + IUiContext * uiContext = GetContext()->GetUiContext(); + _drawingEngine->Resize(uiContext->GetWidth(), uiContext->GetHeight()); + } +} + +void drawing_engine_set_palette(const rct_palette_entry * colours) +{ + if (_drawingEngine != nullptr) + { + _drawingEngine->SetPalette(colours); + } +} + +void drawing_engine_draw() +{ + if (_drawingEngine != nullptr && _painter != nullptr) + { + _drawingEngine->BeginDraw(); + _painter->Paint(_drawingEngine); + _drawingEngine->EndDraw(); + } +} + +void drawing_engine_copy_rect(sint32 x, sint32 y, sint32 width, sint32 height, sint32 dx, sint32 dy) +{ + if (_drawingEngine != nullptr) + { + _drawingEngine->CopyRect(x, y, width, height, dx, dy); + } +} + +void drawing_engine_dispose() +{ + delete _drawingEngine; + delete _painter; + _drawingEngine = nullptr; + _painter = nullptr; +} + +rct_drawpixelinfo * drawing_engine_get_dpi() +{ + assert(_drawingEngine != nullptr); + return _drawingEngine->GetDrawingPixelInfo(); +} + +bool drawing_engine_has_dirty_optimisations() +{ + bool result = false; + if (_drawingEngine != nullptr) + { + result = (_drawingEngine->GetFlags() & DEF_DIRTY_OPTIMISATIONS); + } + return result; +} + +void drawing_engine_invalidate_image(uint32 image) +{ + if (_drawingEngine != nullptr) + { + _drawingEngine->InvalidateImage(image); + } +} + +void drawing_engine_set_vsync(bool vsync) +{ + if (_drawingEngine != nullptr) + { + _drawingEngine->SetVSync(vsync); + } +} + +void gfx_set_dirty_blocks(sint16 left, sint16 top, sint16 right, sint16 bottom) +{ + if (_drawingEngine != nullptr) + { + _drawingEngine->Invalidate(left, top, right, bottom); + } +} + +void gfx_draw_all_dirty_blocks() +{ +} + +void gfx_clear(rct_drawpixelinfo * dpi, uint8 paletteIndex) +{ + if (_drawingEngine != nullptr) + { + IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); + dc->Clear(paletteIndex); + } +} + +void gfx_fill_rect(rct_drawpixelinfo * dpi, sint32 left, sint32 top, sint32 right, sint32 bottom, sint32 colour) +{ + if (_drawingEngine != nullptr) + { + IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); + dc->FillRect(colour, left, top, right, bottom); + } +} + +void gfx_filter_rect(rct_drawpixelinfo * dpi, sint32 left, sint32 top, sint32 right, sint32 bottom, FILTER_PALETTE_ID palette) +{ + if (_drawingEngine != nullptr) + { + IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); + dc->FilterRect(palette, left, top, right, bottom); + } +} + +void gfx_draw_line(rct_drawpixelinfo *dpi, sint32 x1, sint32 y1, sint32 x2, sint32 y2, sint32 colour) +{ + if (_drawingEngine != nullptr) + { + IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); + dc->DrawLine(colour, x1, y1, x2, y2); + } +} + +void FASTCALL gfx_draw_sprite(rct_drawpixelinfo * dpi, sint32 image, sint32 x, sint32 y, uint32 tertiary_colour) +{ + if (_drawingEngine != nullptr) + { + IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); + dc->DrawSprite(image, x, y, tertiary_colour); + } +} + +void FASTCALL gfx_draw_glpyh(rct_drawpixelinfo * dpi, sint32 image, sint32 x, sint32 y, uint8 * palette) +{ + if (_drawingEngine != nullptr) + { + IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); + dc->DrawGlyph(image, x, y, palette); + } +} + +void FASTCALL gfx_draw_sprite_raw_masked(rct_drawpixelinfo * dpi, sint32 x, sint32 y, sint32 maskImage, sint32 colourImage) +{ + if (_drawingEngine != nullptr) + { + IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); + dc->DrawSpriteRawMasked(x, y, maskImage, colourImage); + } +} + +void FASTCALL gfx_draw_sprite_solid(rct_drawpixelinfo * dpi, sint32 image, sint32 x, sint32 y, uint8 colour) +{ + if (_drawingEngine != nullptr) + { + IDrawingContext * dc = _drawingEngine->GetDrawingContext(dpi); + dc->DrawSpriteSolid(image, x, y, colour); + } +} + +sint32 screenshot_dump() +{ + if (_drawingEngine != nullptr) + { + return _drawingEngine->Screenshot(); + } + return false; +} + diff --git a/src/openrct2/drawing/NewDrawing.h b/src/openrct2/drawing/NewDrawing.h index c9003c098a..66ed1d6ca6 100644 --- a/src/openrct2/drawing/NewDrawing.h +++ b/src/openrct2/drawing/NewDrawing.h @@ -20,10 +20,6 @@ typedef struct rct_drawpixelinfo rct_drawpixelinfo; -#ifdef __cplusplus -extern "C" -{ -#endif extern rct_string_id DrawingEngineStringIds[3]; sint32 drawing_engine_get_type(); @@ -39,7 +35,3 @@ rct_drawpixelinfo * drawing_engine_get_dpi(); bool drawing_engine_has_dirty_optimisations(); void drawing_engine_invalidate_image(uint32 image); void drawing_engine_set_vsync(bool vsync); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/drawing/Rect.cpp b/src/openrct2/drawing/Rect.cpp index c94c90e513..be351d07dd 100644 --- a/src/openrct2/drawing/Rect.cpp +++ b/src/openrct2/drawing/Rect.cpp @@ -19,9 +19,6 @@ #include "../platform/platform.h" #include "Drawing.h" -extern "C" -{ - /** * Draw a rectangle, with optional border or fill * @@ -117,5 +114,3 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, sint16 left, sint16 top, sint16 } } } - -} diff --git a/src/openrct2/drawing/ScrollingText.cpp b/src/openrct2/drawing/ScrollingText.cpp index efbf26f0e7..8dfc2430fa 100644 --- a/src/openrct2/drawing/ScrollingText.cpp +++ b/src/openrct2/drawing/ScrollingText.cpp @@ -46,8 +46,6 @@ static uint32 _drawSCrollNextIndex = 0; static void scrolling_text_set_bitmap_for_sprite(utf8 *text, sint32 scroll, uint8 *bitmap, const sint16 *scrollPositionOffsets); static void scrolling_text_set_bitmap_for_ttf(utf8 *text, sint32 scroll, uint8 *bitmap, const sint16 *scrollPositionOffsets); -extern "C" -{ void scrolling_text_initialise_bitmaps() { uint8 drawingSurface[64]; @@ -99,7 +97,6 @@ void scrolling_text_initialise_bitmaps() } } } -} static uint8 *font_sprite_get_codepoint_bitmap(sint32 codepoint) { @@ -1421,8 +1418,6 @@ static constexpr const sint16* _scrollPositions[MAX_SCROLLING_TEXT_MODES] = { }; // clang-format on -extern "C" -{ /** * * rct2: 0x006C42D9 @@ -1474,7 +1469,6 @@ sint32 scrolling_text_setup(paint_session * session, rct_string_id stringId, uin drawing_engine_invalidate_image(imageId); return imageId; } -} static void scrolling_text_set_bitmap_for_sprite(utf8 *text, sint32 scroll, uint8 *bitmap, const sint16 *scrollPositionOffsets) { diff --git a/src/openrct2/drawing/Sprite.cpp b/src/openrct2/drawing/Sprite.cpp index 6200789c3e..dbf965e5e6 100644 --- a/src/openrct2/drawing/Sprite.cpp +++ b/src/openrct2/drawing/Sprite.cpp @@ -201,625 +201,623 @@ static std::string gfx_get_csg_data_path() return path; } -extern "C" +static void * _g1Buffer = nullptr; +static rct_gx _g2 = { 0 }; +static rct_gx _csg = { 0 }; +static bool _csgLoaded = false; + +static size_t _g1ElementsCount = 0; +static rct_g1_element * _g1Elements = nullptr; +static rct_g1_element _g1Temp = { nullptr }; +bool gTinyFontAntiAliased = false; + +/** + * + * rct2: 0x00678998 + */ +bool gfx_load_g1(void * platformEnvironment) { - static void * _g1Buffer = nullptr; - static rct_gx _g2 = { 0 }; - static rct_gx _csg = { 0 }; - static bool _csgLoaded = false; + auto env = (IPlatformEnvironment *)platformEnvironment; - static size_t _g1ElementsCount = 0; - static rct_g1_element * _g1Elements = nullptr; - static rct_g1_element _g1Temp = { nullptr }; - bool gTinyFontAntiAliased = false; - - /** - * - * rct2: 0x00678998 - */ - bool gfx_load_g1(void * platformEnvironment) + log_verbose("gfx_load_g1(...)"); + try { - auto env = (IPlatformEnvironment *)platformEnvironment; + auto path = Path::Combine(env->GetDirectoryPath(DIRBASE::RCT2, DIRID::DATA), "g1.dat"); + auto fs = FileStream(path, FILE_MODE_OPEN); + rct_g1_header header = fs.ReadValue(); - log_verbose("gfx_load_g1(...)"); - try + if (header.num_entries < SPR_G1_END) { - auto path = Path::Combine(env->GetDirectoryPath(DIRBASE::RCT2, DIRID::DATA), "g1.dat"); - auto fs = FileStream(path, FILE_MODE_OPEN); - rct_g1_header header = fs.ReadValue(); - - if (header.num_entries < SPR_G1_END) - { - throw std::runtime_error("Not enough elements in g1.dat"); - } - - // Read element headers - _g1ElementsCount = 324206; - _g1Elements = Memory::AllocateArray(_g1ElementsCount); - bool is_rctc = header.num_entries == SPR_RCTC_G1_END; - read_and_convert_gxdat(&fs, header.num_entries, is_rctc, _g1Elements); - gTinyFontAntiAliased = is_rctc; - - // Read element data - _g1Buffer = fs.ReadArray(header.total_size); - - // Fix entry data offsets - for (uint32 i = 0; i < header.num_entries; i++) - { - _g1Elements[i].offset += (uintptr_t)_g1Buffer; - } - return true; + throw std::runtime_error("Not enough elements in g1.dat"); } - catch (const std::exception &) + + // Read element headers + _g1ElementsCount = 324206; + _g1Elements = Memory::AllocateArray(_g1ElementsCount); + bool is_rctc = header.num_entries == SPR_RCTC_G1_END; + read_and_convert_gxdat(&fs, header.num_entries, is_rctc, _g1Elements); + gTinyFontAntiAliased = is_rctc; + + // Read element data + _g1Buffer = fs.ReadArray(header.total_size); + + // Fix entry data offsets + for (uint32 i = 0; i < header.num_entries; i++) { - log_fatal("Unable to load g1 graphics"); - if (!gOpenRCT2Headless) - { - IUiContext * uiContext = GetContext()->GetUiContext(); - uiContext->ShowMessageBox("Unable to load g1.dat. Your RollerCoaster Tycoon 2 path may be incorrectly set."); - } - return false; + _g1Elements[i].offset += (uintptr_t)_g1Buffer; } + return true; } - - void gfx_unload_g1() + catch (const std::exception &) { - SafeFree(_g1Buffer); - SafeFree(_g1Elements); - } - - void gfx_unload_g2() - { - SafeFree(_g2.elements); - SafeFree(_g2.data); - } - - void gfx_unload_csg() - { - SafeFree(_csg.elements); - SafeFree(_csg.data); - } - - bool gfx_load_g2() - { - log_verbose("gfx_load_g2()"); - - char path[MAX_PATH]; - - platform_get_openrct_data_path(path, sizeof(path)); - safe_strcat_path(path, "g2.dat", MAX_PATH); - try + log_fatal("Unable to load g1 graphics"); + if (!gOpenRCT2Headless) { - auto fs = FileStream(path, FILE_MODE_OPEN); - _g2.header = fs.ReadValue(); - - // Read element headers - _g2.elements = Memory::AllocateArray(_g2.header.num_entries); - read_and_convert_gxdat(&fs, _g2.header.num_entries, false, _g2.elements); - - // Read element data - _g2.data = fs.ReadArray(_g2.header.total_size); - - // Fix entry data offsets - for (uint32 i = 0; i < _g2.header.num_entries; i++) - { - _g2.elements[i].offset += (uintptr_t)_g2.data; - } - return true; - } - catch (const std::exception &) - { - log_fatal("Unable to load g2 graphics"); - if (!gOpenRCT2Headless) - { - IUiContext * uiContext = GetContext()->GetUiContext(); - uiContext->ShowMessageBox("Unable to load g2.dat"); - } + IUiContext * uiContext = GetContext()->GetUiContext(); + uiContext->ShowMessageBox("Unable to load g1.dat. Your RollerCoaster Tycoon 2 path may be incorrectly set."); } return false; } +} - bool gfx_load_csg() +void gfx_unload_g1() +{ + SafeFree(_g1Buffer); + SafeFree(_g1Elements); +} + +void gfx_unload_g2() +{ + SafeFree(_g2.elements); + SafeFree(_g2.data); +} + +void gfx_unload_csg() +{ + SafeFree(_csg.elements); + SafeFree(_csg.data); +} + +bool gfx_load_g2() +{ + log_verbose("gfx_load_g2()"); + + char path[MAX_PATH]; + + platform_get_openrct_data_path(path, sizeof(path)); + safe_strcat_path(path, "g2.dat", MAX_PATH); + try { - log_verbose("gfx_load_csg()"); + auto fs = FileStream(path, FILE_MODE_OPEN); + _g2.header = fs.ReadValue(); - if (str_is_null_or_empty(gConfigGeneral.rct1_path)) + // Read element headers + _g2.elements = Memory::AllocateArray(_g2.header.num_entries); + read_and_convert_gxdat(&fs, _g2.header.num_entries, false, _g2.elements); + + // Read element data + _g2.data = fs.ReadArray(_g2.header.total_size); + + // Fix entry data offsets + for (uint32 i = 0; i < _g2.header.num_entries; i++) { - log_verbose(" unable to load CSG, RCT1 path not set"); - return false; + _g2.elements[i].offset += (uintptr_t)_g2.data; } - - auto pathHeaderPath = gfx_get_csg_header_path(); - auto pathDataPath = gfx_get_csg_data_path(); - try + return true; + } + catch (const std::exception &) + { + log_fatal("Unable to load g2 graphics"); + if (!gOpenRCT2Headless) { - auto fileHeader = FileStream(pathHeaderPath, FILE_MODE_OPEN); - auto fileData = FileStream(pathDataPath, FILE_MODE_OPEN); - size_t fileHeaderSize = fileHeader.GetLength(); - size_t fileDataSize = fileData.GetLength(); - - _csg.header.num_entries = (uint32)(fileHeaderSize / sizeof(rct_g1_element_32bit)); - _csg.header.total_size = (uint32)fileDataSize; - - if (_csg.header.num_entries < 69917) - { - log_warning("Cannot load CSG1.DAT, it has too few entries. Only CSG1.DAT from Loopy Landscapes will work."); - return false; - } - - // Read element headers - _csg.elements = Memory::AllocateArray(_csg.header.num_entries); - read_and_convert_gxdat(&fileHeader, _csg.header.num_entries, false, _csg.elements); - - // Read element data - _csg.data = fileData.ReadArray(_csg.header.total_size); - - // Fix entry data offsets - for (uint32 i = 0; i < _csg.header.num_entries; i++) - { - _csg.elements[i].offset += (uintptr_t)_csg.data; - // RCT1 used zoomed offsets that counted from the beginning of the file, rather than from the current sprite. - _csg.elements[i].zoomed_offset = i - (SPR_CSG_BEGIN + _csg.elements[i].zoomed_offset); - } - _csgLoaded = true; - return true; - } - catch (const std::exception &) - { - log_error("Unable to load csg graphics"); - return false; + IUiContext * uiContext = GetContext()->GetUiContext(); + uiContext->ShowMessageBox("Unable to load g2.dat"); } } + return false; +} - /** - * Copies a sprite onto the buffer. There is no compression used on the sprite - * image. - * rct2: 0x0067A690 - */ - void FASTCALL gfx_bmp_sprite_to_buffer(const uint8* palette_pointer, uint8* unknown_pointer, uint8* source_pointer, uint8* dest_pointer, const rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, sint32 height, sint32 width, sint32 image_type) +bool gfx_load_csg() +{ + log_verbose("gfx_load_csg()"); + + if (str_is_null_or_empty(gConfigGeneral.rct1_path)) { - uint16 zoom_level = dest_dpi->zoom_level; - uint8 zoom_amount = 1 << zoom_level; - uint32 dest_line_width = (dest_dpi->width / zoom_amount) + dest_dpi->pitch; - uint32 source_line_width = source_image->width * zoom_amount; + log_verbose(" unable to load CSG, RCT1 path not set"); + return false; + } - // Image uses the palette pointer to remap the colours of the image - if (image_type & IMAGE_TYPE_REMAP){ - assert(palette_pointer != nullptr); + auto pathHeaderPath = gfx_get_csg_header_path(); + auto pathDataPath = gfx_get_csg_data_path(); + try + { + auto fileHeader = FileStream(pathHeaderPath, FILE_MODE_OPEN); + auto fileData = FileStream(pathDataPath, FILE_MODE_OPEN); + size_t fileHeaderSize = fileHeader.GetLength(); + size_t fileDataSize = fileData.GetLength(); - // Image with remaps - for (; height > 0; height -= zoom_amount){ - uint8* next_source_pointer = source_pointer + source_line_width; - uint8* next_dest_pointer = dest_pointer + dest_line_width; - for (sint32 no_pixels = width; no_pixels > 0; no_pixels -= zoom_amount, source_pointer += zoom_amount, dest_pointer++){ - uint8 pixel = *source_pointer; + _csg.header.num_entries = (uint32)(fileHeaderSize / sizeof(rct_g1_element_32bit)); + _csg.header.total_size = (uint32)fileDataSize; + + if (_csg.header.num_entries < 69917) + { + log_warning("Cannot load CSG1.DAT, it has too few entries. Only CSG1.DAT from Loopy Landscapes will work."); + return false; + } + + // Read element headers + _csg.elements = Memory::AllocateArray(_csg.header.num_entries); + read_and_convert_gxdat(&fileHeader, _csg.header.num_entries, false, _csg.elements); + + // Read element data + _csg.data = fileData.ReadArray(_csg.header.total_size); + + // Fix entry data offsets + for (uint32 i = 0; i < _csg.header.num_entries; i++) + { + _csg.elements[i].offset += (uintptr_t)_csg.data; + // RCT1 used zoomed offsets that counted from the beginning of the file, rather than from the current sprite. + _csg.elements[i].zoomed_offset = i - (SPR_CSG_BEGIN + _csg.elements[i].zoomed_offset); + } + _csgLoaded = true; + return true; + } + catch (const std::exception &) + { + log_error("Unable to load csg graphics"); + return false; + } +} + +/** + * Copies a sprite onto the buffer. There is no compression used on the sprite + * image. + * rct2: 0x0067A690 + */ +void FASTCALL gfx_bmp_sprite_to_buffer(const uint8* palette_pointer, uint8* unknown_pointer, uint8* source_pointer, uint8* dest_pointer, const rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, sint32 height, sint32 width, sint32 image_type) +{ + uint16 zoom_level = dest_dpi->zoom_level; + uint8 zoom_amount = 1 << zoom_level; + uint32 dest_line_width = (dest_dpi->width / zoom_amount) + dest_dpi->pitch; + uint32 source_line_width = source_image->width * zoom_amount; + + // Image uses the palette pointer to remap the colours of the image + if (image_type & IMAGE_TYPE_REMAP){ + assert(palette_pointer != nullptr); + + // Image with remaps + for (; height > 0; height -= zoom_amount){ + uint8* next_source_pointer = source_pointer + source_line_width; + uint8* next_dest_pointer = dest_pointer + dest_line_width; + for (sint32 no_pixels = width; no_pixels > 0; no_pixels -= zoom_amount, source_pointer += zoom_amount, dest_pointer++){ + uint8 pixel = *source_pointer; + pixel = palette_pointer[pixel]; + if (pixel){ + *dest_pointer = pixel; + } + } + + source_pointer = next_source_pointer; + dest_pointer = next_dest_pointer; + } + return; + } + + // Image is transparent. It only uses source pointer for + // telling if it needs to be drawn not for colour. Colour provided + // by the palette pointer. + if (image_type & IMAGE_TYPE_TRANSPARENT){ // Not tested + assert(palette_pointer != nullptr); + for (; height > 0; height -= zoom_amount){ + uint8* next_source_pointer = source_pointer + source_line_width; + uint8* next_dest_pointer = dest_pointer + dest_line_width; + + for (sint32 no_pixels = width; no_pixels > 0; no_pixels -= zoom_amount, source_pointer += zoom_amount, dest_pointer++){ + uint8 pixel = *source_pointer; + if (pixel){ + pixel = *dest_pointer; pixel = palette_pointer[pixel]; - if (pixel){ - *dest_pointer = pixel; - } + *dest_pointer = pixel; } - - source_pointer = next_source_pointer; - dest_pointer = next_dest_pointer; } - return; + + source_pointer = next_source_pointer; + dest_pointer = next_dest_pointer; } + return; + } - // Image is transparent. It only uses source pointer for - // telling if it needs to be drawn not for colour. Colour provided - // by the palette pointer. - if (image_type & IMAGE_TYPE_TRANSPARENT){ // Not tested - assert(palette_pointer != nullptr); - for (; height > 0; height -= zoom_amount){ - uint8* next_source_pointer = source_pointer + source_line_width; - uint8* next_dest_pointer = dest_pointer + dest_line_width; - - for (sint32 no_pixels = width; no_pixels > 0; no_pixels -= zoom_amount, source_pointer += zoom_amount, dest_pointer++){ - uint8 pixel = *source_pointer; - if (pixel){ - pixel = *dest_pointer; - pixel = palette_pointer[pixel]; - *dest_pointer = pixel; - } - } - - source_pointer = next_source_pointer; - dest_pointer = next_dest_pointer; - } - return; - } - - // Basic bitmap no fancy stuff - if (!(source_image->flags & G1_FLAG_BMP)){ // Not tested - for (; height > 0; height -= zoom_amount){ - uint8* next_source_pointer = source_pointer + source_line_width; - uint8* next_dest_pointer = dest_pointer + dest_line_width; - - for (sint32 no_pixels = width; no_pixels > 0; no_pixels -= zoom_amount, dest_pointer++, source_pointer += zoom_amount){ - *dest_pointer = *source_pointer; - } - - dest_pointer = next_dest_pointer; - source_pointer = next_source_pointer; - } - return; - } - - // Basic bitmap with no draw pixels + // Basic bitmap no fancy stuff + if (!(source_image->flags & G1_FLAG_BMP)){ // Not tested for (; height > 0; height -= zoom_amount){ uint8* next_source_pointer = source_pointer + source_line_width; uint8* next_dest_pointer = dest_pointer + dest_line_width; for (sint32 no_pixels = width; no_pixels > 0; no_pixels -= zoom_amount, dest_pointer++, source_pointer += zoom_amount){ - uint8 pixel = *source_pointer; - if (pixel){ - *dest_pointer = pixel; - } + *dest_pointer = *source_pointer; } + dest_pointer = next_dest_pointer; source_pointer = next_source_pointer; } + return; } - uint8* FASTCALL gfx_draw_sprite_get_palette(sint32 image_id, uint32 tertiary_colour) { - sint32 image_type = (image_id & 0xE0000000); - if (image_type == 0) - return nullptr; + // Basic bitmap with no draw pixels + for (; height > 0; height -= zoom_amount){ + uint8* next_source_pointer = source_pointer + source_line_width; + uint8* next_dest_pointer = dest_pointer + dest_line_width; - if (!(image_type & IMAGE_TYPE_REMAP_2_PLUS)) { - uint8 palette_ref = (image_id >> 19) & 0xFF; - if (!(image_type & IMAGE_TYPE_TRANSPARENT)) { - palette_ref &= 0x7F; - } - - uint16 palette_offset = palette_to_g1_offset[palette_ref]; - auto g1 = gfx_get_g1_element(palette_offset); - if (g1 == nullptr) - { - return nullptr; - } - else - { - return g1->offset; + for (sint32 no_pixels = width; no_pixels > 0; no_pixels -= zoom_amount, dest_pointer++, source_pointer += zoom_amount){ + uint8 pixel = *source_pointer; + if (pixel){ + *dest_pointer = pixel; } } - else { - uint8* palette_pointer = gPeepPalette; - - uint32 primary_offset = palette_to_g1_offset[(image_id >> 19) & 0x1F]; - uint32 secondary_offset = palette_to_g1_offset[(image_id >> 24) & 0x1F]; - - if (!(image_type & IMAGE_TYPE_REMAP)) { - palette_pointer = gOtherPalette; - #if defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2 - assert(tertiary_colour < PALETTE_TO_G1_OFFSET_COUNT); - #endif // DEBUG_LEVEL_2 - uint32 tertiary_offset = palette_to_g1_offset[tertiary_colour]; - rct_g1_element* tertiary_palette = &_g1Elements[tertiary_offset]; - memcpy(palette_pointer + 0x2E, &tertiary_palette->offset[0xF3], 12); - } - rct_g1_element* primary_palette = &_g1Elements[primary_offset]; - rct_g1_element* secondary_palette = &_g1Elements[secondary_offset]; - - memcpy(palette_pointer + 0xF3, &primary_palette->offset[0xF3], 12); - memcpy(palette_pointer + 0xCA, &secondary_palette->offset[0xF3], 12); - - return palette_pointer; - } + dest_pointer = next_dest_pointer; + source_pointer = next_source_pointer; } +} - /** - * - * rct2: 0x0067A28E - * image_id (ebx) - * image_id as below - * 0b_111X_XXXX_XXXX_XXXX_XXXX_XXXX_XXXX_XXXX image_type - * 0b_XXX1_11XX_XXXX_XXXX_XXXX_XXXX_XXXX_XXXX image_sub_type (unknown pointer) - * 0b_XXX1_1111_XXXX_XXXX_XXXX_XXXX_XXXX_XXXX secondary_colour - * 0b_XXXX_XXXX_1111_1XXX_XXXX_XXXX_XXXX_XXXX primary_colour - * 0b_XXXX_X111_1111_1XXX_XXXX_XXXX_XXXX_XXXX palette_ref - * 0b_XXXX_XXXX_XXXX_X111_1111_1111_1111_1111 image_id (offset to g1) - * x (cx) - * y (dx) - * dpi (esi) - * tertiary_colour (ebp) - */ - void FASTCALL gfx_draw_sprite_software(rct_drawpixelinfo *dpi, sint32 image_id, sint32 x, sint32 y, uint32 tertiary_colour) - { - if (image_id != -1) - { - uint8* palette_pointer = gfx_draw_sprite_get_palette(image_id, tertiary_colour); - if (image_id & IMAGE_TYPE_REMAP_2_PLUS) { - image_id |= IMAGE_TYPE_REMAP; - } +uint8* FASTCALL gfx_draw_sprite_get_palette(sint32 image_id, uint32 tertiary_colour) { + sint32 image_type = (image_id & 0xE0000000); + if (image_type == 0) + return nullptr; - gfx_draw_sprite_palette_set_software(dpi, image_id, x, y, palette_pointer, nullptr); + if (!(image_type & IMAGE_TYPE_REMAP_2_PLUS)) { + uint8 palette_ref = (image_id >> 19) & 0xFF; + if (!(image_type & IMAGE_TYPE_TRANSPARENT)) { + palette_ref &= 0x7F; } - } - /* - * rct: 0x0067A46E - * image_id (ebx) and also (0x00EDF81C) - * palette_pointer (0x9ABDA4) - * unknown_pointer (0x9E3CDC) - * dpi (edi) - * x (cx) - * y (dx) - */ - void FASTCALL gfx_draw_sprite_palette_set_software(rct_drawpixelinfo *dpi, sint32 image_id, sint32 x, sint32 y, uint8* palette_pointer, uint8* unknown_pointer) - { - sint32 image_element = image_id & 0x7FFFF; - sint32 image_type = image_id & 0xE0000000; - - const rct_g1_element * g1 = gfx_get_g1_element(image_element); + uint16 palette_offset = palette_to_g1_offset[palette_ref]; + auto g1 = gfx_get_g1_element(palette_offset); if (g1 == nullptr) - { - return; - } - - if (dpi->zoom_level != 0 && (g1->flags & G1_FLAG_HAS_ZOOM_SPRITE)) { - rct_drawpixelinfo zoomed_dpi; - zoomed_dpi.bits = dpi->bits; - zoomed_dpi.x = dpi->x >> 1; - zoomed_dpi.y = dpi->y >> 1; - zoomed_dpi.height = dpi->height >> 1; - zoomed_dpi.width = dpi->width >> 1; - zoomed_dpi.pitch = dpi->pitch; - zoomed_dpi.zoom_level = dpi->zoom_level - 1; - gfx_draw_sprite_palette_set_software(&zoomed_dpi, image_type | (image_element - g1->zoomed_offset), x >> 1, y >> 1, palette_pointer, unknown_pointer); - return; - } - - if (dpi->zoom_level != 0 && (g1->flags & G1_FLAG_NO_ZOOM_DRAW)) { - return; - } - - // Its used super often so we will define it to a separate variable. - sint32 zoom_level = dpi->zoom_level; - sint32 zoom_mask = 0xFFFFFFFF << zoom_level; - - if (zoom_level && g1->flags & G1_FLAG_RLE_COMPRESSION){ - x -= ~zoom_mask; - y -= ~zoom_mask; - } - - // This will be the height of the drawn image - sint32 height = g1->height; - // This is the start y coordinate on the destination - sint16 dest_start_y = y + g1->y_offset; - - // For whatever reason the RLE version does not use - // the zoom mask on the y coordinate but does on x. - if (g1->flags & G1_FLAG_RLE_COMPRESSION){ - dest_start_y -= dpi->y; - } - else{ - dest_start_y = (dest_start_y&zoom_mask) - dpi->y; - } - //This is the start y coordinate on the source - sint32 source_start_y = 0; - - if (dest_start_y < 0){ - // If the destination y is negative reduce the height of the - // image as we will cut off the bottom - height += dest_start_y; - // If the image is no longer visible nothing to draw - if (height <= 0){ - return; - } - // The source image will start a further up the image - source_start_y -= dest_start_y; - // The destination start is now reset to 0 - dest_start_y = 0; - } - else{ - if (g1->flags & G1_FLAG_RLE_COMPRESSION && zoom_level){ - source_start_y -= dest_start_y & ~zoom_mask; - height += dest_start_y & ~zoom_mask; - } - } - - sint32 dest_end_y = dest_start_y + height; - - if (dest_end_y > dpi->height){ - // If the destination y is outside of the drawing - // image reduce the height of the image - height -= dest_end_y - dpi->height; - } - // If the image no longer has anything to draw - if (height <= 0)return; - - dest_start_y >>= zoom_level; - - // This will be the width of the drawn image - sint32 width = g1->width; - // This is the source start x coordinate - sint32 source_start_x = 0; - // This is the destination start x coordinate - sint16 dest_start_x = ((x + g1->x_offset + ~zoom_mask)&zoom_mask) - dpi->x; - - if (dest_start_x < 0){ - // If the destination is negative reduce the width - // image will cut off the side - width += dest_start_x; - // If there is no image to draw - if (width <= 0){ - return; - } - // The source start will also need to cut off the side - source_start_x -= dest_start_x; - // Reset the destination to 0 - dest_start_x = 0; - } - else{ - if (g1->flags & G1_FLAG_RLE_COMPRESSION && zoom_level){ - source_start_x -= dest_start_x & ~zoom_mask; - } - } - - sint32 dest_end_x = dest_start_x + width; - - if (dest_end_x > dpi->width){ - // If the destination x is outside of the drawing area - // reduce the image width. - width -= dest_end_x - dpi->width; - // If there is no image to draw. - if (width <= 0)return; - } - - dest_start_x >>= zoom_level; - - uint8* dest_pointer = (uint8*)dpi->bits; - // Move the pointer to the start point of the destination - dest_pointer += ((dpi->width >> zoom_level) + dpi->pitch) * dest_start_y + dest_start_x; - - if (g1->flags & G1_FLAG_RLE_COMPRESSION){ - // We have to use a different method to move the source pointer for - // rle encoded sprites so that will be handled within this function - gfx_rle_sprite_to_buffer(g1->offset, dest_pointer, palette_pointer, dpi, image_type, source_start_y, height, source_start_x, width); - return; - } - uint8* source_pointer = g1->offset; - // Move the pointer to the start point of the source - source_pointer += g1->width*source_start_y + source_start_x; - - if (!(g1->flags & G1_FLAG_1)) { - gfx_bmp_sprite_to_buffer(palette_pointer, unknown_pointer, source_pointer, dest_pointer, g1, dpi, height, width, image_type); - } - } - - /** - * Draws the given colour image masked out by the given mask image. This can currently only cope with bitmap formatted mask and - * colour images. Presumably the original game never used RLE images for masking. Colour 0 represents transparent. - * - * rct2: 0x00681DE2 - */ - void FASTCALL gfx_draw_sprite_raw_masked_software(rct_drawpixelinfo *dpi, sint32 x, sint32 y, sint32 maskImage, sint32 colourImage) - { - sint32 left, top, right, bottom, width, height; - rct_g1_element *imgMask = &_g1Elements[maskImage & 0x7FFFF]; - rct_g1_element *imgColour = &_g1Elements[colourImage & 0x7FFFF]; - - assert(imgMask->flags & G1_FLAG_BMP); - assert(imgColour->flags & G1_FLAG_BMP); - - if (dpi->zoom_level != 0) { - // TODO: Implement other zoom levels (probably not used though) - assert(false); - return; - } - - width = Math::Min(imgMask->width, imgColour->width); - height = Math::Min(imgMask->height, imgColour->height); - - x += imgMask->x_offset; - y += imgMask->y_offset; - - left = Math::Max(dpi->x, x); - top = Math::Max(dpi->y, y); - right = Math::Min(dpi->x + dpi->width, x + width); - bottom = Math::Min(dpi->y + dpi->height, y + height); - - width = right - left; - height = bottom - top; - if (width < 0 || height < 0) - return; - - sint32 skipX = left - x; - sint32 skipY = top - y; - - uint8 const * maskSrc = imgMask->offset + (skipY * imgMask->width) + skipX; - uint8 const * colourSrc = imgColour->offset + (skipY * imgColour->width) + skipX; - uint8 * dst = dpi->bits + (left - dpi->x) + ((top - dpi->y) * (dpi->width + dpi->pitch)); - - sint32 maskWrap = imgMask->width - width; - sint32 colourWrap = imgColour->width - width; - sint32 dstWrap = ((dpi->width + dpi->pitch) - width); - - mask_fn(width, height, maskSrc, colourSrc, dst, maskWrap, colourWrap, dstWrap); - } - - const rct_g1_element * gfx_get_g1_element(sint32 image_id) - { - openrct2_assert(!gOpenRCT2NoGraphics, "gfx_get_g1_element called on headless instance"); - - if (image_id == (-1 & 0x7FFFF)) { return nullptr; } + else + { + return g1->offset; + } + } + else { + uint8* palette_pointer = gPeepPalette; - if (image_id == SPR_TEMP) - { - return &_g1Temp; + uint32 primary_offset = palette_to_g1_offset[(image_id >> 19) & 0x1F]; + uint32 secondary_offset = palette_to_g1_offset[(image_id >> 24) & 0x1F]; + + if (!(image_type & IMAGE_TYPE_REMAP)) { + palette_pointer = gOtherPalette; +#if defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2 + assert(tertiary_colour < PALETTE_TO_G1_OFFSET_COUNT); +#endif // DEBUG_LEVEL_2 + uint32 tertiary_offset = palette_to_g1_offset[tertiary_colour]; + rct_g1_element* tertiary_palette = &_g1Elements[tertiary_offset]; + memcpy(palette_pointer + 0x2E, &tertiary_palette->offset[0xF3], 12); } - else if (image_id < SPR_G2_BEGIN) - { - if (image_id >= (sint32)_g1ElementsCount) - { - return nullptr; - } - return &_g1Elements[image_id]; - } - if (image_id < SPR_CSG_BEGIN) - { - const uint32 idx = image_id - SPR_G2_BEGIN; - if (idx >= _g2.header.num_entries) - { - log_warning("Invalid entry in g2.dat requested, idx = %u. You may have to update your g2.dat.", idx); - return nullptr; - } - return &_g2.elements[idx]; + rct_g1_element* primary_palette = &_g1Elements[primary_offset]; + rct_g1_element* secondary_palette = &_g1Elements[secondary_offset]; + + memcpy(palette_pointer + 0xF3, &primary_palette->offset[0xF3], 12); + memcpy(palette_pointer + 0xCA, &secondary_palette->offset[0xF3], 12); + + return palette_pointer; + } +} + +/** + * + * rct2: 0x0067A28E + * image_id (ebx) + * image_id as below + * 0b_111X_XXXX_XXXX_XXXX_XXXX_XXXX_XXXX_XXXX image_type + * 0b_XXX1_11XX_XXXX_XXXX_XXXX_XXXX_XXXX_XXXX image_sub_type (unknown pointer) + * 0b_XXX1_1111_XXXX_XXXX_XXXX_XXXX_XXXX_XXXX secondary_colour + * 0b_XXXX_XXXX_1111_1XXX_XXXX_XXXX_XXXX_XXXX primary_colour + * 0b_XXXX_X111_1111_1XXX_XXXX_XXXX_XXXX_XXXX palette_ref + * 0b_XXXX_XXXX_XXXX_X111_1111_1111_1111_1111 image_id (offset to g1) + * x (cx) + * y (dx) + * dpi (esi) + * tertiary_colour (ebp) + */ +void FASTCALL gfx_draw_sprite_software(rct_drawpixelinfo *dpi, sint32 image_id, sint32 x, sint32 y, uint32 tertiary_colour) +{ + if (image_id != -1) + { + uint8* palette_pointer = gfx_draw_sprite_get_palette(image_id, tertiary_colour); + if (image_id & IMAGE_TYPE_REMAP_2_PLUS) { + image_id |= IMAGE_TYPE_REMAP; } - if (is_csg_loaded()) - { - const uint32 idx = image_id - SPR_CSG_BEGIN; - if (idx >= _csg.header.num_entries) - { - openrct2_assert(idx < _csg.header.num_entries, - "Invalid entry in csg.dat requested, idx = %u.", idx); - return nullptr; - } - return &_csg.elements[idx]; + gfx_draw_sprite_palette_set_software(dpi, image_id, x, y, palette_pointer, nullptr); + } +} + +/* +* rct: 0x0067A46E +* image_id (ebx) and also (0x00EDF81C) +* palette_pointer (0x9ABDA4) +* unknown_pointer (0x9E3CDC) +* dpi (edi) +* x (cx) +* y (dx) +*/ +void FASTCALL gfx_draw_sprite_palette_set_software(rct_drawpixelinfo *dpi, sint32 image_id, sint32 x, sint32 y, uint8* palette_pointer, uint8* unknown_pointer) +{ + sint32 image_element = image_id & 0x7FFFF; + sint32 image_type = image_id & 0xE0000000; + + const rct_g1_element * g1 = gfx_get_g1_element(image_element); + if (g1 == nullptr) + { + return; + } + + if (dpi->zoom_level != 0 && (g1->flags & G1_FLAG_HAS_ZOOM_SPRITE)) { + rct_drawpixelinfo zoomed_dpi; + zoomed_dpi.bits = dpi->bits; + zoomed_dpi.x = dpi->x >> 1; + zoomed_dpi.y = dpi->y >> 1; + zoomed_dpi.height = dpi->height >> 1; + zoomed_dpi.width = dpi->width >> 1; + zoomed_dpi.pitch = dpi->pitch; + zoomed_dpi.zoom_level = dpi->zoom_level - 1; + gfx_draw_sprite_palette_set_software(&zoomed_dpi, image_type | (image_element - g1->zoomed_offset), x >> 1, y >> 1, palette_pointer, unknown_pointer); + return; + } + + if (dpi->zoom_level != 0 && (g1->flags & G1_FLAG_NO_ZOOM_DRAW)) { + return; + } + + // Its used super often so we will define it to a separate variable. + sint32 zoom_level = dpi->zoom_level; + sint32 zoom_mask = 0xFFFFFFFF << zoom_level; + + if (zoom_level && g1->flags & G1_FLAG_RLE_COMPRESSION){ + x -= ~zoom_mask; + y -= ~zoom_mask; + } + + // This will be the height of the drawn image + sint32 height = g1->height; + // This is the start y coordinate on the destination + sint16 dest_start_y = y + g1->y_offset; + + // For whatever reason the RLE version does not use + // the zoom mask on the y coordinate but does on x. + if (g1->flags & G1_FLAG_RLE_COMPRESSION){ + dest_start_y -= dpi->y; + } + else{ + dest_start_y = (dest_start_y&zoom_mask) - dpi->y; + } + //This is the start y coordinate on the source + sint32 source_start_y = 0; + + if (dest_start_y < 0){ + // If the destination y is negative reduce the height of the + // image as we will cut off the bottom + height += dest_start_y; + // If the image is no longer visible nothing to draw + if (height <= 0){ + return; } + // The source image will start a further up the image + source_start_y -= dest_start_y; + // The destination start is now reset to 0 + dest_start_y = 0; + } + else{ + if (g1->flags & G1_FLAG_RLE_COMPRESSION && zoom_level){ + source_start_y -= dest_start_y & ~zoom_mask; + height += dest_start_y & ~zoom_mask; + } + } + + sint32 dest_end_y = dest_start_y + height; + + if (dest_end_y > dpi->height){ + // If the destination y is outside of the drawing + // image reduce the height of the image + height -= dest_end_y - dpi->height; + } + // If the image no longer has anything to draw + if (height <= 0)return; + + dest_start_y >>= zoom_level; + + // This will be the width of the drawn image + sint32 width = g1->width; + // This is the source start x coordinate + sint32 source_start_x = 0; + // This is the destination start x coordinate + sint16 dest_start_x = ((x + g1->x_offset + ~zoom_mask)&zoom_mask) - dpi->x; + + if (dest_start_x < 0){ + // If the destination is negative reduce the width + // image will cut off the side + width += dest_start_x; + // If there is no image to draw + if (width <= 0){ + return; + } + // The source start will also need to cut off the side + source_start_x -= dest_start_x; + // Reset the destination to 0 + dest_start_x = 0; + } + else{ + if (g1->flags & G1_FLAG_RLE_COMPRESSION && zoom_level){ + source_start_x -= dest_start_x & ~zoom_mask; + } + } + + sint32 dest_end_x = dest_start_x + width; + + if (dest_end_x > dpi->width){ + // If the destination x is outside of the drawing area + // reduce the image width. + width -= dest_end_x - dpi->width; + // If there is no image to draw. + if (width <= 0)return; + } + + dest_start_x >>= zoom_level; + + uint8* dest_pointer = (uint8*)dpi->bits; + // Move the pointer to the start point of the destination + dest_pointer += ((dpi->width >> zoom_level) + dpi->pitch) * dest_start_y + dest_start_x; + + if (g1->flags & G1_FLAG_RLE_COMPRESSION){ + // We have to use a different method to move the source pointer for + // rle encoded sprites so that will be handled within this function + gfx_rle_sprite_to_buffer(g1->offset, dest_pointer, palette_pointer, dpi, image_type, source_start_y, height, source_start_x, width); + return; + } + uint8* source_pointer = g1->offset; + // Move the pointer to the start point of the source + source_pointer += g1->width*source_start_y + source_start_x; + + if (!(g1->flags & G1_FLAG_1)) { + gfx_bmp_sprite_to_buffer(palette_pointer, unknown_pointer, source_pointer, dest_pointer, g1, dpi, height, width, image_type); + } +} + +/** + * Draws the given colour image masked out by the given mask image. This can currently only cope with bitmap formatted mask and + * colour images. Presumably the original game never used RLE images for masking. Colour 0 represents transparent. + * + * rct2: 0x00681DE2 + */ +void FASTCALL gfx_draw_sprite_raw_masked_software(rct_drawpixelinfo *dpi, sint32 x, sint32 y, sint32 maskImage, sint32 colourImage) +{ + sint32 left, top, right, bottom, width, height; + rct_g1_element *imgMask = &_g1Elements[maskImage & 0x7FFFF]; + rct_g1_element *imgColour = &_g1Elements[colourImage & 0x7FFFF]; + + assert(imgMask->flags & G1_FLAG_BMP); + assert(imgColour->flags & G1_FLAG_BMP); + + if (dpi->zoom_level != 0) { + // TODO: Implement other zoom levels (probably not used though) + assert(false); + return; + } + + width = Math::Min(imgMask->width, imgColour->width); + height = Math::Min(imgMask->height, imgColour->height); + + x += imgMask->x_offset; + y += imgMask->y_offset; + + left = Math::Max(dpi->x, x); + top = Math::Max(dpi->y, y); + right = Math::Min(dpi->x + dpi->width, x + width); + bottom = Math::Min(dpi->y + dpi->height, y + height); + + width = right - left; + height = bottom - top; + if (width < 0 || height < 0) + return; + + sint32 skipX = left - x; + sint32 skipY = top - y; + + uint8 const * maskSrc = imgMask->offset + (skipY * imgMask->width) + skipX; + uint8 const * colourSrc = imgColour->offset + (skipY * imgColour->width) + skipX; + uint8 * dst = dpi->bits + (left - dpi->x) + ((top - dpi->y) * (dpi->width + dpi->pitch)); + + sint32 maskWrap = imgMask->width - width; + sint32 colourWrap = imgColour->width - width; + sint32 dstWrap = ((dpi->width + dpi->pitch) - width); + + mask_fn(width, height, maskSrc, colourSrc, dst, maskWrap, colourWrap, dstWrap); +} + +const rct_g1_element * gfx_get_g1_element(sint32 image_id) +{ + openrct2_assert(!gOpenRCT2NoGraphics, "gfx_get_g1_element called on headless instance"); + + if (image_id == (-1 & 0x7FFFF)) + { return nullptr; } - void gfx_set_g1_element(sint32 imageId, const rct_g1_element * g1) + if (image_id == SPR_TEMP) { - openrct2_assert(!gOpenRCT2NoGraphics, "gfx_set_g1_element called on headless instance"); + return &_g1Temp; + } + else if (image_id < SPR_G2_BEGIN) + { + if (image_id >= (sint32)_g1ElementsCount) + { + return nullptr; + } + return &_g1Elements[image_id]; + } + if (image_id < SPR_CSG_BEGIN) + { + const uint32 idx = image_id - SPR_G2_BEGIN; + if (idx >= _g2.header.num_entries) + { + log_warning("Invalid entry in g2.dat requested, idx = %u. You may have to update your g2.dat.", idx); + return nullptr; + } + return &_g2.elements[idx]; + } + + if (is_csg_loaded()) + { + const uint32 idx = image_id - SPR_CSG_BEGIN; + if (idx >= _csg.header.num_entries) + { + openrct2_assert(idx < _csg.header.num_entries, + "Invalid entry in csg.dat requested, idx = %u.", idx); + return nullptr; + } + return &_csg.elements[idx]; + } + return nullptr; +} + +void gfx_set_g1_element(sint32 imageId, const rct_g1_element * g1) +{ + openrct2_assert(!gOpenRCT2NoGraphics, "gfx_set_g1_element called on headless instance"); #ifdef DEBUG - openrct2_assert((imageId >= 0 && imageId < SPR_G2_BEGIN) || imageId == SPR_TEMP, "gfx_set_g1_element called with unexpected image id"); - openrct2_assert(g1 != nullptr, "g1 was nullptr"); + openrct2_assert((imageId >= 0 && imageId < SPR_G2_BEGIN) || imageId == SPR_TEMP, "gfx_set_g1_element called with unexpected image id"); + openrct2_assert(g1 != nullptr, "g1 was nullptr"); #endif - if (imageId == SPR_TEMP) - { - _g1Temp = *g1; - } - else if (imageId >= 0 && imageId < SPR_G2_BEGIN) - { - if (imageId < (sint32)_g1ElementsCount) - { - _g1Elements[imageId] = *g1; - } - } - } - - bool is_csg_loaded() + if (imageId == SPR_TEMP) { - return _csgLoaded; + _g1Temp = *g1; } - - rct_size16 FASTCALL gfx_get_sprite_size(uint32 image_id) + else if (imageId >= 0 && imageId < SPR_G2_BEGIN) { - const rct_g1_element * g1 = gfx_get_g1_element(image_id & 0X7FFFF); - rct_size16 size = {}; - if (g1 != nullptr) + if (imageId < (sint32)_g1ElementsCount) { - size.width = g1->width; - size.height = g1->height; + _g1Elements[imageId] = *g1; } - return size; } } + +bool is_csg_loaded() +{ + return _csgLoaded; +} + +rct_size16 FASTCALL gfx_get_sprite_size(uint32 image_id) +{ + const rct_g1_element * g1 = gfx_get_g1_element(image_id & 0X7FFFF); + rct_size16 size = {}; + if (g1 != nullptr) + { + size.width = g1->width; + size.height = g1->height; + } + return size; +} + diff --git a/src/openrct2/drawing/String.cpp b/src/openrct2/drawing/String.cpp index 743880eb7a..04c68729bf 100644 --- a/src/openrct2/drawing/String.cpp +++ b/src/openrct2/drawing/String.cpp @@ -24,9 +24,6 @@ #include "../util/Util.h" #include "TTF.h" -extern "C" -{ - enum { TEXT_DRAW_FLAG_INSET = 1 << 0, TEXT_DRAW_FLAG_OUTLINE = 1 << 1, @@ -929,5 +926,3 @@ void shorten_path(utf8 *buffer, size_t bufferSize, const utf8 *path, sint32 avai safe_strcpy(buffer, path, bufferSize); } - -} diff --git a/src/openrct2/drawing/TTF.cpp b/src/openrct2/drawing/TTF.cpp index 249e5e8315..8ec974e1b3 100644 --- a/src/openrct2/drawing/TTF.cpp +++ b/src/openrct2/drawing/TTF.cpp @@ -25,9 +25,6 @@ #include "../platform/platform.h" #include "TTF.h" -extern "C" -{ - static bool _ttfInitialised = false; #define TTF_SURFACE_CACHE_SIZE 256 @@ -318,15 +315,10 @@ void ttf_free_surface(TTFSurface * surface) free(surface); } -} - #else #include "TTF.h" -extern "C" -{ - bool ttf_initialise() { return false; @@ -336,6 +328,4 @@ void ttf_dispose() { } -} - #endif // NO_TTF diff --git a/src/openrct2/drawing/TTF.h b/src/openrct2/drawing/TTF.h index 8b06bc81c4..3010a65de1 100644 --- a/src/openrct2/drawing/TTF.h +++ b/src/openrct2/drawing/TTF.h @@ -18,17 +18,9 @@ #include "Font.h" -#ifdef __cplusplus -extern "C" { -#endif - bool ttf_initialise(); void ttf_dispose(); -#ifdef __cplusplus -} -#endif - #ifndef NO_TTF typedef struct TTFSurface { @@ -38,10 +30,6 @@ typedef struct TTFSurface { sint32 pitch; } TTFSurface; -#ifdef __cplusplus -extern "C" { -#endif - TTFFontDescriptor * ttf_get_font_from_sprite_base(uint16 spriteBase); void ttf_toggle_hinting(); TTFSurface * ttf_surface_cache_get_or_add(TTF_Font * font, const utf8 * text); @@ -60,8 +48,4 @@ void TTF_CloseFont(TTF_Font *font); void TTF_SetFontHinting(TTF_Font* font, int hinting); void TTF_Quit(void); -#ifdef __cplusplus -} -#endif - #endif // NO_TTF diff --git a/src/openrct2/drawing/Text.cpp b/src/openrct2/drawing/Text.cpp index 04622fd827..e77a8b5113 100644 --- a/src/openrct2/drawing/Text.cpp +++ b/src/openrct2/drawing/Text.cpp @@ -144,105 +144,103 @@ static void DrawTextEllipsisedCompat(rct_drawpixelinfo * dpi, sint32 x, sint32 y DrawText(dpi, x, y, &_legacyPaint, buffer); } -extern "C" +void gfx_draw_string(rct_drawpixelinfo *dpi, const_utf8string buffer, uint8 colour, sint32 x, sint32 y) { - void gfx_draw_string(rct_drawpixelinfo *dpi, const_utf8string buffer, uint8 colour, sint32 x, sint32 y) - { - _legacyPaint.UnderlineText = false; - _legacyPaint.Colour = colour; - _legacyPaint.Alignment = TextAlignment::LEFT; - _legacyPaint.SpriteBase = gCurrentFontSpriteBase; - DrawText(dpi, x, y, &_legacyPaint, buffer); - } - - // Basic - void gfx_draw_string_left(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y) - { - DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::LEFT); - } - - void gfx_draw_string_centred(rct_drawpixelinfo * dpi, rct_string_id format, sint32 x, sint32 y, uint8 colour, void * args) - { - DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::CENTRE); - } - - void gfx_draw_string_right(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y) - { - DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::RIGHT); - } - - // Underline - void draw_string_left_underline(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y) - { - DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::LEFT, true); - } - - void draw_string_centred_underline(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y) - { - DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::CENTRE, true); - } - - void draw_string_right_underline(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y) - { - DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::RIGHT, true); - } - - // Ellipsised - void gfx_draw_string_left_clipped(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y, sint32 width) - { - DrawTextEllipsisedCompat(dpi, x, y, width, format, args, colour, TextAlignment::LEFT); - } - - void gfx_draw_string_centred_clipped(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y, sint32 width) - { - DrawTextEllipsisedCompat(dpi, x, y, width, format, args, colour, TextAlignment::CENTRE); - } - - void gfx_draw_string_right_clipped(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y, sint32 width) - { - DrawTextEllipsisedCompat(dpi, x, y, width, format, args, colour, TextAlignment::RIGHT); - } - - // Wrapping - sint32 gfx_draw_string_left_wrapped(rct_drawpixelinfo * dpi, void * args, sint32 x, sint32 y, sint32 width, rct_string_id format, uint8 colour) - { - utf8 buffer[256]; - format_string(buffer, sizeof(buffer), format, args); - - gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; - - _legacyPaint.UnderlineText = false; - _legacyPaint.Colour = colour; - _legacyPaint.Alignment = TextAlignment::LEFT; - _legacyPaint.SpriteBase = gCurrentFontSpriteBase; - - StaticLayout layout(buffer, _legacyPaint, width); - layout.Draw(dpi, x, y); - - return layout.GetHeight(); - } - - sint32 gfx_draw_string_centred_wrapped(rct_drawpixelinfo * dpi, void * args, sint32 x, sint32 y, sint32 width, rct_string_id format, uint8 colour) - { - utf8 buffer[256]; - format_string(buffer, sizeof(buffer), format, args); - - gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; - - _legacyPaint.UnderlineText = false; - _legacyPaint.Colour = colour; - _legacyPaint.Alignment = TextAlignment::CENTRE; - _legacyPaint.SpriteBase = gCurrentFontSpriteBase; - - StaticLayout layout(buffer, _legacyPaint, width); - - // The original tried to vertically centre the text, but used line count - 1 - sint32 lineCount = layout.GetLineCount(); - sint32 lineHeight = layout.GetHeight() / lineCount; - sint32 yOffset = (lineCount - 1) * lineHeight / 2; - - layout.Draw(dpi, x - layout.GetWidth() / 2, y - yOffset); - - return layout.GetHeight(); - } + _legacyPaint.UnderlineText = false; + _legacyPaint.Colour = colour; + _legacyPaint.Alignment = TextAlignment::LEFT; + _legacyPaint.SpriteBase = gCurrentFontSpriteBase; + DrawText(dpi, x, y, &_legacyPaint, buffer); } + +// Basic +void gfx_draw_string_left(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y) +{ + DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::LEFT); +} + +void gfx_draw_string_centred(rct_drawpixelinfo * dpi, rct_string_id format, sint32 x, sint32 y, uint8 colour, void * args) +{ + DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::CENTRE); +} + +void gfx_draw_string_right(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y) +{ + DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::RIGHT); +} + +// Underline +void draw_string_left_underline(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y) +{ + DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::LEFT, true); +} + +void draw_string_centred_underline(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y) +{ + DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::CENTRE, true); +} + +void draw_string_right_underline(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y) +{ + DrawTextCompat(dpi, x, y, format, args, colour, TextAlignment::RIGHT, true); +} + +// Ellipsised +void gfx_draw_string_left_clipped(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y, sint32 width) +{ + DrawTextEllipsisedCompat(dpi, x, y, width, format, args, colour, TextAlignment::LEFT); +} + +void gfx_draw_string_centred_clipped(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y, sint32 width) +{ + DrawTextEllipsisedCompat(dpi, x, y, width, format, args, colour, TextAlignment::CENTRE); +} + +void gfx_draw_string_right_clipped(rct_drawpixelinfo * dpi, rct_string_id format, void * args, uint8 colour, sint32 x, sint32 y, sint32 width) +{ + DrawTextEllipsisedCompat(dpi, x, y, width, format, args, colour, TextAlignment::RIGHT); +} + +// Wrapping +sint32 gfx_draw_string_left_wrapped(rct_drawpixelinfo * dpi, void * args, sint32 x, sint32 y, sint32 width, rct_string_id format, uint8 colour) +{ + utf8 buffer[256]; + format_string(buffer, sizeof(buffer), format, args); + + gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; + + _legacyPaint.UnderlineText = false; + _legacyPaint.Colour = colour; + _legacyPaint.Alignment = TextAlignment::LEFT; + _legacyPaint.SpriteBase = gCurrentFontSpriteBase; + + StaticLayout layout(buffer, _legacyPaint, width); + layout.Draw(dpi, x, y); + + return layout.GetHeight(); +} + +sint32 gfx_draw_string_centred_wrapped(rct_drawpixelinfo * dpi, void * args, sint32 x, sint32 y, sint32 width, rct_string_id format, uint8 colour) +{ + utf8 buffer[256]; + format_string(buffer, sizeof(buffer), format, args); + + gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; + + _legacyPaint.UnderlineText = false; + _legacyPaint.Colour = colour; + _legacyPaint.Alignment = TextAlignment::CENTRE; + _legacyPaint.SpriteBase = gCurrentFontSpriteBase; + + StaticLayout layout(buffer, _legacyPaint, width); + + // The original tried to vertically centre the text, but used line count - 1 + sint32 lineCount = layout.GetLineCount(); + sint32 lineHeight = layout.GetHeight() / lineCount; + sint32 yOffset = (lineCount - 1) * lineHeight / 2; + + layout.Draw(dpi, x - layout.GetWidth() / 2, y - yOffset); + + return layout.GetHeight(); +} + diff --git a/src/openrct2/interface/Chat.cpp b/src/openrct2/interface/Chat.cpp index d90920ec81..59497616cd 100644 --- a/src/openrct2/interface/Chat.cpp +++ b/src/openrct2/interface/Chat.cpp @@ -25,9 +25,6 @@ #include "../util/Util.h" #include "Chat.h" -extern "C" -{ - bool gChatOpen = false; static char _chatCurrentLine[CHAT_MAX_MESSAGE_LENGTH]; static char _chatHistory[CHAT_HISTORY_SIZE][CHAT_INPUT_SIZE]; @@ -308,5 +305,3 @@ sint32 chat_string_wrapped_get_height(void *args, sint32 width) return lineY; } - -} diff --git a/src/openrct2/interface/Chat.h b/src/openrct2/interface/Chat.h index 3272b3fe2f..0e834dfd95 100644 --- a/src/openrct2/interface/Chat.h +++ b/src/openrct2/interface/Chat.h @@ -32,10 +32,6 @@ typedef enum CHAT_INPUT CHAT_INPUT_CLOSE, } CHAT_INPUT; -#ifdef __cplusplus -extern "C" { -#endif - extern bool gChatOpen; void chat_open(); @@ -52,8 +48,4 @@ void chat_input(CHAT_INPUT input); sint32 chat_string_wrapped_get_height(void *args, sint32 width); sint32 chat_history_draw_string(rct_drawpixelinfo *dpi, void *args, sint32 x, sint32 y, sint32 width); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/interface/Colour.cpp b/src/openrct2/interface/Colour.cpp index e933d39af3..358ca9ac47 100644 --- a/src/openrct2/interface/Colour.cpp +++ b/src/openrct2/interface/Colour.cpp @@ -19,9 +19,6 @@ #include "../sprites.h" #include "Colour.h" -extern "C" -{ - rct_colour_map ColourMapA[COLOUR_COUNT] = { 0 }; enum @@ -106,4 +103,4 @@ uint8 blendColours(const uint8 paletteIndex1, const uint8 paletteIndex2) } #endif -} + diff --git a/src/openrct2/interface/Colour.h b/src/openrct2/interface/Colour.h index 7dc0148e13..cb5e2a625c 100644 --- a/src/openrct2/interface/Colour.h +++ b/src/openrct2/interface/Colour.h @@ -146,10 +146,6 @@ typedef struct rct_colour_map uint8 colour_11; } rct_colour_map; -#ifdef __cplusplus -extern "C" { -#endif - extern rct_colour_map ColourMapA[COLOUR_COUNT]; void colours_init_maps(); @@ -158,8 +154,4 @@ void colours_init_maps(); uint8 blendColours(const uint8 paletteIndex1, const uint8 paletteIndex2); #endif -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/interface/Console.cpp b/src/openrct2/interface/Console.cpp index f8019bd8d9..a7f4be0be4 100644 --- a/src/openrct2/interface/Console.cpp +++ b/src/openrct2/interface/Console.cpp @@ -67,9 +67,6 @@ #define CONSOLE_EDGE_PADDING 4 #define CONSOLE_CARET_WIDTH 6 -extern "C" -{ - bool gConsoleOpen = false; static bool _consoleInitialised = false; @@ -1589,5 +1586,3 @@ static bool invalidArguments(bool *invalid, bool arguments) } return true; } - -} diff --git a/src/openrct2/interface/Console.h b/src/openrct2/interface/Console.h index aedad14555..a999188956 100644 --- a/src/openrct2/interface/Console.h +++ b/src/openrct2/interface/Console.h @@ -32,10 +32,6 @@ typedef enum CONSOLE_INPUT CONSOLE_INPUT_SCROLL_NEXT, } CONSOLE_INPUT; -#ifdef __cplusplus -extern "C" { -#endif - extern bool gConsoleOpen; void console_open(); @@ -58,8 +54,4 @@ void console_clear_line(); void console_refresh_caret(); void console_scroll(sint32 delta); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index 131b504f39..a76cf63efa 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -36,8 +36,6 @@ using namespace OpenRCT2; -extern "C" -{ uint8 gScreenshotCountdown = 0; /** @@ -584,5 +582,3 @@ sint32 cmdline_for_screenshot(const char * * argv, sint32 argc, ScreenshotOption delete context; return 1; } - -} diff --git a/src/openrct2/interface/Screenshot.h b/src/openrct2/interface/Screenshot.h index 361e0cb3fc..ef04f41cab 100644 --- a/src/openrct2/interface/Screenshot.h +++ b/src/openrct2/interface/Screenshot.h @@ -20,33 +20,27 @@ typedef struct rct_drawpixelinfo rct_drawpixelinfo; -#ifdef __cplusplus -extern "C" +extern uint8 gScreenshotCountdown; + +struct ScreenshotOptions { -#endif - extern uint8 gScreenshotCountdown; + sint32 weather = 0; + bool hide_guests = false; + bool hide_sprites = false; + bool clear_grass = false; + bool mowed_grass = false; + bool water_plants = false; + bool fix_vandalism = false; + bool remove_litter = false; + bool tidy_up_park = false; +}; - struct ScreenshotOptions - { - sint32 weather = 0; - bool hide_guests = false; - bool hide_sprites = false; - bool clear_grass = false; - bool mowed_grass = false; - bool water_plants = false; - bool fix_vandalism = false; - bool remove_litter = false; - bool tidy_up_park = false; - }; +void screenshot_check(); +sint32 screenshot_dump(); +sint32 screenshot_dump_png(rct_drawpixelinfo *dpi); +sint32 screenshot_dump_png_32bpp(sint32 width, sint32 height, const void *pixels); - void screenshot_check(); - sint32 screenshot_dump(); - sint32 screenshot_dump_png(rct_drawpixelinfo *dpi); - sint32 screenshot_dump_png_32bpp(sint32 width, sint32 height, const void *pixels); +void screenshot_giant(); +sint32 cmdline_for_screenshot(const char * * argv, sint32 argc, ScreenshotOptions * options); +sint32 cmdline_for_gfxbench(const char **argv, sint32 argc); - void screenshot_giant(); - sint32 cmdline_for_screenshot(const char * * argv, sint32 argc, ScreenshotOptions * options); - sint32 cmdline_for_gfxbench(const char **argv, sint32 argc); -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/interface/Theme.cpp b/src/openrct2/interface/Theme.cpp index fa747a70ff..147ed3cb0d 100644 --- a/src/openrct2/interface/Theme.cpp +++ b/src/openrct2/interface/Theme.cpp @@ -658,259 +658,257 @@ namespace ThemeManager } } -extern "C" +void theme_manager_load_available_themes() { - void theme_manager_load_available_themes() - { - ThemeManager::GetAvailableThemes(&ThemeManager::AvailableThemes); - } + ThemeManager::GetAvailableThemes(&ThemeManager::AvailableThemes); +} - size_t theme_manager_get_num_available_themes() - { - return ThemeManager::AvailableThemes.size(); - } +size_t theme_manager_get_num_available_themes() +{ + return ThemeManager::AvailableThemes.size(); +} - const utf8 * theme_manager_get_available_theme_path(size_t index) - { - return ThemeManager::AvailableThemes[index].Path.c_str(); - } +const utf8 * theme_manager_get_available_theme_path(size_t index) +{ + return ThemeManager::AvailableThemes[index].Path.c_str(); +} - const utf8 * theme_manager_get_available_theme_config_name(size_t index) - { - return ThemeManager::AvailableThemes[index].Name.c_str(); - } - const utf8 * theme_manager_get_available_theme_name(size_t index) - { - if (index < ThemeManager::NumPredefinedThemes) - return language_get_string(PredefinedThemes[index].Name); - return ThemeManager::AvailableThemes[index].Name.c_str(); - } +const utf8 * theme_manager_get_available_theme_config_name(size_t index) +{ + return ThemeManager::AvailableThemes[index].Name.c_str(); +} +const utf8 * theme_manager_get_available_theme_name(size_t index) +{ + if (index < ThemeManager::NumPredefinedThemes) + return language_get_string(PredefinedThemes[index].Name); + return ThemeManager::AvailableThemes[index].Name.c_str(); +} - size_t theme_manager_get_active_available_theme_index() - { - return ThemeManager::ActiveAvailableThemeIndex; - } +size_t theme_manager_get_active_available_theme_index() +{ + return ThemeManager::ActiveAvailableThemeIndex; +} - void theme_manager_set_active_available_theme(size_t index) +void theme_manager_set_active_available_theme(size_t index) +{ + if (index < ThemeManager::NumPredefinedThemes) { - if (index < ThemeManager::NumPredefinedThemes) + ThemeManager::LoadTheme((UITheme *)PredefinedThemes[index].Theme); + } + else + { + auto path = ThemeManager::AvailableThemes[index].Path; + ThemeManager::LoadTheme(path); + + // HACK Check if theme load failed and fell back to RCT2 + if (ThemeManager::CurrentThemePath.empty()) { - ThemeManager::LoadTheme((UITheme *)PredefinedThemes[index].Theme); - } - else - { - auto path = ThemeManager::AvailableThemes[index].Path; - ThemeManager::LoadTheme(path); - - // HACK Check if theme load failed and fell back to RCT2 - if (ThemeManager::CurrentThemePath.empty()) - { - index = 1; - } - } - ThemeManager::ActiveAvailableThemeIndex = index; - String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(index)); - - colour_scheme_update_all(); - } - - size_t theme_get_index_for_name(const utf8 * name) - { - size_t count = ThemeManager::AvailableThemes.size(); - for (size_t i = 0; i < count; i++) - { - const utf8 * tn = theme_manager_get_available_theme_name(i); - if (String::Equals(tn, name, true)) - { - return i; - } - } - return SIZE_MAX; - } - - uint8 theme_get_colour(rct_windowclass wc, uint8 index) - { - const UIThemeWindowEntry * entry = ThemeManager::CurrentTheme->GetEntry(wc); - if (entry == nullptr) - { - const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); - if (desc == nullptr) - { - return 0; - } - return desc->DefaultTheme.Colours[index]; - } - else - { - return entry->Theme.Colours[index]; + index = 1; } } + ThemeManager::ActiveAvailableThemeIndex = index; + String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(index)); - void theme_set_colour(rct_windowclass wc, uint8 index, colour_t colour) + colour_scheme_update_all(); +} + +size_t theme_get_index_for_name(const utf8 * name) +{ + size_t count = ThemeManager::AvailableThemes.size(); + for (size_t i = 0; i < count; i++) { - UIThemeWindowEntry entry; - entry.WindowClass = wc; - - auto currentEntry = (UIThemeWindowEntry *)ThemeManager::CurrentTheme->GetEntry(wc); - if (currentEntry != nullptr) + const utf8 * tn = theme_manager_get_available_theme_name(i); + if (String::Equals(tn, name, true)) { - entry.Theme = currentEntry->Theme; - } - else - { - const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); - if (desc == nullptr) - { - return; - } - entry.Theme = desc->DefaultTheme; - } - - entry.Theme.Colours[index] = colour; - ThemeManager::CurrentTheme->SetEntry(&entry); - - theme_save(); - } - - uint8 theme_get_flags() - { - return ThemeManager::CurrentTheme->Flags; - } - - void theme_set_flags(uint8 flags) - { - ThemeManager::CurrentTheme->Flags = flags; - theme_save(); - } - - void theme_save() - { - ThemeManager::EnsureThemeDirectoryExists(); - ThemeManager::CurrentTheme->WriteToFile(ThemeManager::CurrentThemePath); - } - - void theme_rename(const utf8 * name) - { - const auto oldPath = ThemeManager::CurrentThemePath; - - ThemeManager::EnsureThemeDirectoryExists(); - auto newPath = ThemeManager::GetThemeFileName(name); - File::Move(oldPath, newPath); - ThemeManager::CurrentThemePath = newPath; - - ThemeManager::CurrentTheme->Name = name; - ThemeManager::CurrentTheme->WriteToFile(ThemeManager::CurrentThemePath); - - theme_manager_load_available_themes(); - for (size_t i = 0; i < ThemeManager::AvailableThemes.size(); i++) - { - if (Path::Equals(newPath, ThemeManager::AvailableThemes[i].Path)) - { - ThemeManager::ActiveAvailableThemeIndex = i; - String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(1)); - break; - } + return i; } } + return SIZE_MAX; +} - void theme_duplicate(const utf8 * name) - { - ThemeManager::EnsureThemeDirectoryExists(); - auto newPath = ThemeManager::GetThemeFileName(name); - - // Copy the theme, save it and then load it back in - UITheme * newTheme = new UITheme(*ThemeManager::CurrentTheme); - newTheme->Name = name; - newTheme->Flags &= ~UITHEME_FLAG_PREDEFINED; - newTheme->WriteToFile(newPath); - delete newTheme; - - ThemeManager::LoadTheme(newPath); - - theme_manager_load_available_themes(); - for (size_t i = 0; i < ThemeManager::AvailableThemes.size(); i++) - { - if (Path::Equals(newPath, ThemeManager::AvailableThemes[i].Path)) - { - ThemeManager::ActiveAvailableThemeIndex = i; - String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(i)); - break; - } - } - } - - void theme_delete() - { - File::Delete(ThemeManager::CurrentThemePath); - ThemeManager::LoadTheme((UITheme *)&PredefinedThemeRCT2); - ThemeManager::ActiveAvailableThemeIndex = 1; - String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(1)); - } - - void theme_manager_initialise() - { - ThemeManager::Initialise(); - } - - uint8 theme_desc_get_num_colours(rct_windowclass wc) +uint8 theme_get_colour(rct_windowclass wc, uint8 index) +{ + const UIThemeWindowEntry * entry = ThemeManager::CurrentTheme->GetEntry(wc); + if (entry == nullptr) { const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); if (desc == nullptr) { return 0; } - return desc->NumColours; + return desc->DefaultTheme.Colours[index]; } + else + { + return entry->Theme.Colours[index]; + } +} - rct_string_id theme_desc_get_name(rct_windowclass wc) +void theme_set_colour(rct_windowclass wc, uint8 index, colour_t colour) +{ + UIThemeWindowEntry entry; + entry.WindowClass = wc; + + auto currentEntry = (UIThemeWindowEntry *)ThemeManager::CurrentTheme->GetEntry(wc); + if (currentEntry != nullptr) + { + entry.Theme = currentEntry->Theme; + } + else { const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); if (desc == nullptr) { - return STR_EMPTY; + return; } - return desc->WindowName; + entry.Theme = desc->DefaultTheme; } - void colour_scheme_update_all() + entry.Theme.Colours[index] = colour; + ThemeManager::CurrentTheme->SetEntry(&entry); + + theme_save(); +} + +uint8 theme_get_flags() +{ + return ThemeManager::CurrentTheme->Flags; +} + +void theme_set_flags(uint8 flags) +{ + ThemeManager::CurrentTheme->Flags = flags; + theme_save(); +} + +void theme_save() +{ + ThemeManager::EnsureThemeDirectoryExists(); + ThemeManager::CurrentTheme->WriteToFile(ThemeManager::CurrentThemePath); +} + +void theme_rename(const utf8 * name) +{ + const auto oldPath = ThemeManager::CurrentThemePath; + + ThemeManager::EnsureThemeDirectoryExists(); + auto newPath = ThemeManager::GetThemeFileName(name); + File::Move(oldPath, newPath); + ThemeManager::CurrentThemePath = newPath; + + ThemeManager::CurrentTheme->Name = name; + ThemeManager::CurrentTheme->WriteToFile(ThemeManager::CurrentThemePath); + + theme_manager_load_available_themes(); + for (size_t i = 0; i < ThemeManager::AvailableThemes.size(); i++) { - for (rct_window *w = g_window_list; w < gWindowNextSlot; w++) + if (Path::Equals(newPath, ThemeManager::AvailableThemes[i].Path)) { - colour_scheme_update(w); + ThemeManager::ActiveAvailableThemeIndex = i; + String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(1)); + break; } } - - void colour_scheme_update(rct_window * window) - { - colour_scheme_update_by_class(window, window->classification); - } - - void colour_scheme_update_by_class(rct_window * window, rct_windowclass classification) - { - const WindowTheme * windowTheme; - const UIThemeWindowEntry * entry = ThemeManager::CurrentTheme->GetEntry(classification); - if (entry != nullptr) - { - windowTheme = &entry->Theme; - } - else - { - const WindowThemeDesc * desc = GetWindowThemeDescriptor(classification); - - // Some windows don't have a theme set (e.g. main window, title screen) - if (desc == nullptr) - { - return; - } - - windowTheme = &desc->DefaultTheme; - } - - for (sint32 i = 0; i < 6; i++) { - window->colours[i] = windowTheme->Colours[i]; - } - // Some windows need to be transparent even if the colours aren't. - // There doesn't seem to be any side-effects for all windows being transparent - window->flags |= WF_TRANSPARENT; - } } + +void theme_duplicate(const utf8 * name) +{ + ThemeManager::EnsureThemeDirectoryExists(); + auto newPath = ThemeManager::GetThemeFileName(name); + + // Copy the theme, save it and then load it back in + UITheme * newTheme = new UITheme(*ThemeManager::CurrentTheme); + newTheme->Name = name; + newTheme->Flags &= ~UITHEME_FLAG_PREDEFINED; + newTheme->WriteToFile(newPath); + delete newTheme; + + ThemeManager::LoadTheme(newPath); + + theme_manager_load_available_themes(); + for (size_t i = 0; i < ThemeManager::AvailableThemes.size(); i++) + { + if (Path::Equals(newPath, ThemeManager::AvailableThemes[i].Path)) + { + ThemeManager::ActiveAvailableThemeIndex = i; + String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(i)); + break; + } + } +} + +void theme_delete() +{ + File::Delete(ThemeManager::CurrentThemePath); + ThemeManager::LoadTheme((UITheme *)&PredefinedThemeRCT2); + ThemeManager::ActiveAvailableThemeIndex = 1; + String::DiscardDuplicate(&gConfigInterface.current_theme_preset, theme_manager_get_available_theme_config_name(1)); +} + +void theme_manager_initialise() +{ + ThemeManager::Initialise(); +} + +uint8 theme_desc_get_num_colours(rct_windowclass wc) +{ + const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); + if (desc == nullptr) + { + return 0; + } + return desc->NumColours; +} + +rct_string_id theme_desc_get_name(rct_windowclass wc) +{ + const WindowThemeDesc * desc = GetWindowThemeDescriptor(wc); + if (desc == nullptr) + { + return STR_EMPTY; + } + return desc->WindowName; +} + +void colour_scheme_update_all() +{ + for (rct_window *w = g_window_list; w < gWindowNextSlot; w++) + { + colour_scheme_update(w); + } +} + +void colour_scheme_update(rct_window * window) +{ + colour_scheme_update_by_class(window, window->classification); +} + +void colour_scheme_update_by_class(rct_window * window, rct_windowclass classification) +{ + const WindowTheme * windowTheme; + const UIThemeWindowEntry * entry = ThemeManager::CurrentTheme->GetEntry(classification); + if (entry != nullptr) + { + windowTheme = &entry->Theme; + } + else + { + const WindowThemeDesc * desc = GetWindowThemeDescriptor(classification); + + // Some windows don't have a theme set (e.g. main window, title screen) + if (desc == nullptr) + { + return; + } + + windowTheme = &desc->DefaultTheme; + } + + for (sint32 i = 0; i < 6; i++) { + window->colours[i] = windowTheme->Colours[i]; + } + // Some windows need to be transparent even if the colours aren't. + // There doesn't seem to be any side-effects for all windows being transparent + window->flags |= WF_TRANSPARENT; +} + diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 41745dea23..802fdc67fd 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -40,9 +40,6 @@ #include "Window.h" #include "Window_internal.h" -extern "C" -{ - //#define DEBUG_SHOW_DIRTY_BOX uint8 gShowGridLinesRefCount; uint8 gShowLandRightsRefCount; @@ -1794,5 +1791,3 @@ void viewport_set_saved_view() gSavedViewRotation = get_current_rotation(); } } - -} diff --git a/src/openrct2/interface/Viewport.h b/src/openrct2/interface/Viewport.h index ba8db02441..faa885630d 100644 --- a/src/openrct2/interface/Viewport.h +++ b/src/openrct2/interface/Viewport.h @@ -91,10 +91,6 @@ typedef struct viewport_interaction_info { #define MAX_VIEWPORT_COUNT WINDOW_LIMIT_MAX #define MAX_ZOOM_LEVEL 3 -#ifdef __cplusplus -extern "C" { -#endif - /** * A reference counter for whether something is forcing the grid lines to show. When the counter * is decremented to 0, the grid lines are hidden. @@ -173,8 +169,4 @@ sint16 get_height_marker_offset(); void viewport_set_saved_view(); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/interface/ViewportInteraction.cpp b/src/openrct2/interface/ViewportInteraction.cpp index 8c160e8252..1cd99f8349 100644 --- a/src/openrct2/interface/ViewportInteraction.cpp +++ b/src/openrct2/interface/ViewportInteraction.cpp @@ -36,9 +36,6 @@ #include "Window_internal.h" #include "../Context.h" -extern "C" -{ - static void viewport_interaction_remove_scenery(rct_tile_element *tileElement, sint32 x, sint32 y); static void viewport_interaction_remove_footpath(rct_tile_element *tileElement, sint32 x, sint32 y); static void viewport_interaction_remove_footpath_item(rct_tile_element *tileElement, sint32 x, sint32 y); @@ -655,5 +652,3 @@ void sub_68A15E(sint32 screenX, sint32 screenY, sint16 *x, sint16 *y, sint32 *di if (direction != nullptr) *direction = myDirection; if (tileElement != nullptr) *tileElement = myTileElement; } - -} diff --git a/src/openrct2/interface/Widget.h b/src/openrct2/interface/Widget.h index 76576608a9..a68721389f 100644 --- a/src/openrct2/interface/Widget.h +++ b/src/openrct2/interface/Widget.h @@ -54,11 +54,6 @@ enum { SCROLL_BOTH = SCROLL_HORIZONTAL | SCROLL_VERTICAL }; - -#ifdef __cplusplus -extern "C" { -#endif - void widget_scroll_update_thumbs(rct_window *w, rct_widgetindex widget_index); void widget_draw(rct_drawpixelinfo *dpi, rct_window *w, rct_widgetindex widgetIndex); @@ -72,9 +67,4 @@ void widget_scroll_get_part(rct_window *w, rct_widget* widget, sint32 x, sint32 void widget_set_enabled(rct_window *w, rct_widgetindex widgetIndex, bool enabled); void widget_set_checkbox_value(rct_window *w, rct_widgetindex widgetIndex, sint32 value); - -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 0f472df80f..09a4b14764 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -38,9 +38,6 @@ #include "Window.h" #include "Window_internal.h" -extern "C" -{ - #define RCT2_FIRST_WINDOW (g_window_list) #define RCT2_LAST_WINDOW (gWindowNextSlot - 1) #define RCT2_NEW_WINDOW (gWindowNextSlot) @@ -2726,4 +2723,3 @@ rct_windowclass window_get_classification(rct_window * window) return window->classification; } -} diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index b6f5c5c213..1e692a4c27 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -43,10 +43,6 @@ typedef struct scenario_index_entry scenario_index_entry; #define TEXT_INPUT_SIZE 1024 #define TOP_TOOLBAR_HEIGHT 27 -#ifdef __cplusplus -extern "C" { -#endif - extern uint16 TextInputDescriptionArgs[4]; extern char gTextBoxInput[TEXT_INPUT_SIZE]; extern sint32 gMaxTextBoxInputLength; @@ -729,8 +725,4 @@ extern bool _deferClose; rct_window * window_get_listening(); rct_windowclass window_get_classification(rct_window * window); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/interface/Window_internal.h b/src/openrct2/interface/Window_internal.h index 21c7dbeae5..aa090c3d77 100644 --- a/src/openrct2/interface/Window_internal.h +++ b/src/openrct2/interface/Window_internal.h @@ -17,9 +17,6 @@ #ifndef _WINDOW2_H_ #define _WINDOW2_H_ -extern "C" -{ - /** * Window structure * size: 0x4C0 @@ -103,5 +100,4 @@ struct rct_window { // rct2: 0x01420078 extern rct_window g_window_list[WINDOW_LIMIT_MAX + WINDOW_LIMIT_RESERVED]; -} #endif diff --git a/src/openrct2/interface/themes.h b/src/openrct2/interface/themes.h index ecde7ef7f0..94678c4894 100644 --- a/src/openrct2/interface/themes.h +++ b/src/openrct2/interface/themes.h @@ -28,10 +28,6 @@ enum { UITHEME_FLAG_USE_FULL_BOTTOM_TOOLBAR = 1 << 4, }; -#ifdef __cplusplus -extern "C" { -#endif - void colour_scheme_update(rct_window *window); void colour_scheme_update_all(); void colour_scheme_update_by_class(rct_window *window, rct_windowclass classification); @@ -58,8 +54,4 @@ void theme_delete(); uint8 theme_desc_get_num_colours(rct_windowclass wc); rct_string_id theme_desc_get_name(rct_windowclass wc); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/localisation/Currency.h b/src/openrct2/localisation/Currency.h index c51ee69115..4c876f854e 100644 --- a/src/openrct2/localisation/Currency.h +++ b/src/openrct2/localisation/Currency.h @@ -63,10 +63,6 @@ typedef struct currency_descriptor { rct_string_id stringId; } currency_descriptor; -#ifdef __cplusplus -extern "C" { -#endif - // List of currency formats extern currency_descriptor CurrencyDescriptors[CURRENCY_END]; @@ -76,8 +72,4 @@ extern currency_descriptor CurrencyDescriptors[CURRENCY_END]; */ void currency_load_custom_currency_config(); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/localisation/Date.h b/src/openrct2/localisation/Date.h index b7d0f94651..3770cd5dd9 100644 --- a/src/openrct2/localisation/Date.h +++ b/src/openrct2/localisation/Date.h @@ -45,10 +45,6 @@ typedef struct openrct_timeofday { uint8 hour; } openrct_timeofday; -#ifdef __cplusplus -extern "C" { -#endif - extern const sint16 days_in_month[MONTH_COUNT]; extern const rct_string_id DateFormatStringIds[]; extern const rct_string_id DateFormatStringFormatIds[]; @@ -70,8 +66,4 @@ bool date_is_week_start(sint32 monthTicks); bool date_is_fortnight_start(sint32 monthTicks); bool date_is_month_start(sint32 monthTicks); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/localisation/FormatCodes.h b/src/openrct2/localisation/FormatCodes.h index 6a0f0dc0dd..6cc7224a61 100644 --- a/src/openrct2/localisation/FormatCodes.h +++ b/src/openrct2/localisation/FormatCodes.h @@ -17,17 +17,9 @@ #ifndef _FORMAT_CODES_H_ #define _FORMAT_CODES_H_ -#ifdef __cplusplus -extern "C" { -#endif - uint32 format_get_code(const char *token); const char *format_get_token(uint32 code); -#ifdef __cplusplus -} -#endif - enum { // Font format codes diff --git a/src/openrct2/localisation/Language.cpp b/src/openrct2/localisation/Language.cpp index d2f9ffabbc..d1ab538d8f 100644 --- a/src/openrct2/localisation/Language.cpp +++ b/src/openrct2/localisation/Language.cpp @@ -54,8 +54,6 @@ const language_descriptor LanguagesDescriptors[LANGUAGE_COUNT] = }; // clang-format on -extern "C" { - sint32 gCurrentLanguage = LANGUAGE_UNDEFINED; bool gUseTrueTypeFont = false; @@ -270,8 +268,6 @@ rct_string_id language_get_object_override_string_id(const char * identifier, ui return _languageCurrent->GetObjectOverrideStringId(identifier, index); } -} - rct_string_id language_allocate_object_string(const std::string &target) { if (!_availableObjectStringIdsInitialised) diff --git a/src/openrct2/localisation/Language.h b/src/openrct2/localisation/Language.h index 9b6c0f7e6c..0f37d9c84b 100644 --- a/src/openrct2/localisation/Language.h +++ b/src/openrct2/localisation/Language.h @@ -88,10 +88,6 @@ typedef struct language_descriptor { RCT2LanguageId rct2_original_id; } language_descriptor; -#ifdef __cplusplus -extern "C" { -#endif - extern const language_descriptor LanguagesDescriptors[LANGUAGE_COUNT]; extern sint32 gCurrentLanguage; @@ -122,10 +118,6 @@ bool language_get_localised_scenario_strings(const utf8 *scenarioFilename, rct_s void language_free_object_string(rct_string_id stringId); rct_string_id language_get_object_override_string_id(const char * identifier, uint8 index); -#ifdef __cplusplus -} -#endif - #ifdef __cplusplus rct_string_id language_allocate_object_string(const std::string &target); #endif diff --git a/src/openrct2/localisation/Localisation.h b/src/openrct2/localisation/Localisation.h index d56326d1f5..047b8e98b2 100644 --- a/src/openrct2/localisation/Localisation.h +++ b/src/openrct2/localisation/Localisation.h @@ -24,10 +24,6 @@ #include "StringIds.h" #include "../management/Marketing.h" -#ifdef __cplusplus -extern "C" { -#endif - bool utf8_is_format_code(sint32 codepoint); bool utf8_is_colour_code(sint32 codepoint); bool utf8_should_use_sprite_for_codepoint(sint32 codepoint); @@ -114,8 +110,4 @@ static inline void set_format_arg_body(uint8 *args, size_t offset, uintptr_t val do { static_assert(sizeof(type) <= sizeof(uintptr_t), "Type too large"); \ set_format_arg_body(gMapTooltipFormatArgs, offset, (uintptr_t)value, sizeof(type)); } while (false) -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/localisation/User.h b/src/openrct2/localisation/User.h index b534a921d5..4b972c03c8 100644 --- a/src/openrct2/localisation/User.h +++ b/src/openrct2/localisation/User.h @@ -16,12 +16,4 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif - void reset_user_strings(); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/management/Award.h b/src/openrct2/management/Award.h index 28d46c34c2..e033d796da 100644 --- a/src/openrct2/management/Award.h +++ b/src/openrct2/management/Award.h @@ -48,15 +48,8 @@ enum PARK_AWARD #define MAX_AWARDS 4 -#ifdef __cplusplus -extern "C" -{ -#endif - extern Award gCurrentAwards[MAX_AWARDS]; +extern Award gCurrentAwards[MAX_AWARDS]; - bool award_is_positive(sint32 type); - void award_reset(); - void award_update_all(); -#ifdef __cplusplus -} -#endif \ No newline at end of file +bool award_is_positive(sint32 type); +void award_reset(); +void award_update_all(); diff --git a/src/openrct2/management/Finance.h b/src/openrct2/management/Finance.h index 3bd17eb99f..956c5f9c90 100644 --- a/src/openrct2/management/Finance.h +++ b/src/openrct2/management/Finance.h @@ -43,10 +43,6 @@ enum { #define EXPENDITURE_TABLE_MONTH_COUNT 16 #define FINANCE_GRAPH_SIZE 128 -#ifdef __cplusplus -extern "C" { -#endif - extern const money32 wage_table[STAFF_TYPE_COUNT]; extern const money32 research_cost_table[RESEARCH_FUNDING_COUNT]; @@ -92,7 +88,3 @@ money32 finance_get_current_cash(); void game_command_set_current_loan(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); money32 finance_get_last_month_shop_profit(); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/management/Marketing.h b/src/openrct2/management/Marketing.h index 5c79de9c7c..5e6babd154 100644 --- a/src/openrct2/management/Marketing.h +++ b/src/openrct2/management/Marketing.h @@ -41,10 +41,6 @@ enum { CAMPAIGN_ACTIVE_FLAG = (1 << 7) }; -#ifdef __cplusplus -extern "C" { -#endif - extern const money16 AdvertisingCampaignPricePerWeek[ADVERTISING_CAMPAIGN_COUNT]; extern uint8 gMarketingCampaignDaysLeft[20]; extern uint8 gMarketingCampaignRideIndex[22]; @@ -56,7 +52,3 @@ void game_command_callback_marketing_start_campaign(sint32 eax, sint32 ebx, sint void marketing_start_campaign(sint32 type, sint32 rideOrItem, sint32 numWeeks); void game_command_start_campaign(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp); bool marketing_is_campaign_type_applicable(sint32 campaignType); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/management/NewsItem.h b/src/openrct2/management/NewsItem.h index 705ec403d5..e37d912ac7 100644 --- a/src/openrct2/management/NewsItem.h +++ b/src/openrct2/management/NewsItem.h @@ -59,10 +59,6 @@ typedef struct NewsItem #define MAX_NEWS_ITEMS 61 -#ifdef __cplusplus -extern "C" { -#endif - extern const uint8 news_type_properties[10]; extern NewsItem gNewsItems[MAX_NEWS_ITEMS]; @@ -90,6 +86,3 @@ bool news_item_is_valid_idx(sint32 index); void news_item_add_to_queue_custom(NewsItem * newNewsItem); -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/management/Research.h b/src/openrct2/management/Research.h index 8680cbc145..50991f8b77 100644 --- a/src/openrct2/management/Research.h +++ b/src/openrct2/management/Research.h @@ -94,10 +94,6 @@ enum { RESEARCH_CATEGORY_SCENERY_GROUP }; -#ifdef __cplusplus -extern "C" { -#endif - extern uint8 gResearchFundingLevel; extern uint8 gResearchPriorities; extern uint16 gResearchProgress; @@ -155,7 +151,3 @@ void research_items_make_all_unresearched(); void research_items_make_all_researched(); void research_items_shuffle(); bool research_item_is_always_researched(rct_research_item * researchItem); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/network/ServerList.cpp b/src/openrct2/network/ServerList.cpp index 7557fe1ac6..27c1444e1d 100644 --- a/src/openrct2/network/ServerList.cpp +++ b/src/openrct2/network/ServerList.cpp @@ -21,76 +21,74 @@ #include "../platform/platform.h" -extern "C" +bool server_list_read(uint32 * outNumEntries, server_entry * * outEntries) { - bool server_list_read(uint32 * outNumEntries, server_entry * * outEntries) + log_verbose("server_list_read(...)"); + + utf8 path[MAX_PATH]; + platform_get_user_directory(path, nullptr, sizeof(path)); + Path::Append(path, sizeof(path), "servers.cfg"); + + uint32 numEntries = 0; + server_entry * entries = nullptr; + try { - log_verbose("server_list_read(...)"); + auto fs = FileStream(path, FILE_MODE_OPEN); + numEntries = fs.ReadValue(); + entries = Memory::AllocateArray(numEntries); - utf8 path[MAX_PATH]; - platform_get_user_directory(path, nullptr, sizeof(path)); - Path::Append(path, sizeof(path), "servers.cfg"); - - uint32 numEntries = 0; - server_entry * entries = nullptr; - try + // Load each server entry + for (uint32 i = 0; i < numEntries; i++) { - auto fs = FileStream(path, FILE_MODE_OPEN); - numEntries = fs.ReadValue(); - entries = Memory::AllocateArray(numEntries); - - // Load each server entry - for (uint32 i = 0; i < numEntries; i++) - { - server_entry * serverInfo = &entries[i]; - serverInfo->address = fs.ReadString(); - serverInfo->name = fs.ReadString(); - serverInfo->requiresPassword = false; - serverInfo->description = fs.ReadString(); - serverInfo->version = String::Duplicate(""); - serverInfo->favourite = true; - serverInfo->players = 0; - serverInfo->maxplayers = 0; - } + server_entry * serverInfo = &entries[i]; + serverInfo->address = fs.ReadString(); + serverInfo->name = fs.ReadString(); + serverInfo->requiresPassword = false; + serverInfo->description = fs.ReadString(); + serverInfo->version = String::Duplicate(""); + serverInfo->favourite = true; + serverInfo->players = 0; + serverInfo->maxplayers = 0; } - catch (const std::exception &) - { - Memory::FreeArray(entries, numEntries); - numEntries = 0; - entries = nullptr; - } - - *outNumEntries = numEntries; - *outEntries = entries; - return entries != nullptr; + } + catch (const std::exception &) + { + Memory::FreeArray(entries, numEntries); + numEntries = 0; + entries = nullptr; } - bool server_list_write(uint32 numEntries, server_entry * entries) + *outNumEntries = numEntries; + *outEntries = entries; + return entries != nullptr; +} + +bool server_list_write(uint32 numEntries, server_entry * entries) +{ + log_verbose("server_list_write(%d, 0x%p)", numEntries, entries); + + utf8 path[MAX_PATH]; + platform_get_user_directory(path, nullptr, sizeof(path)); + Path::Append(path, sizeof(path), "servers.cfg"); + + try { - log_verbose("server_list_write(%d, 0x%p)", numEntries, entries); + auto fs = FileStream(path, FILE_MODE_WRITE); + fs.WriteValue(numEntries); - utf8 path[MAX_PATH]; - platform_get_user_directory(path, nullptr, sizeof(path)); - Path::Append(path, sizeof(path), "servers.cfg"); - - try + // Write each server entry + for (uint32 i = 0; i < numEntries; i++) { - auto fs = FileStream(path, FILE_MODE_WRITE); - fs.WriteValue(numEntries); - - // Write each server entry - for (uint32 i = 0; i < numEntries; i++) - { - server_entry * serverInfo = &entries[i]; - fs.WriteString(serverInfo->address); - fs.WriteString(serverInfo->name); - fs.WriteString(serverInfo->description); - } - return true; - } - catch (const std::exception &) - { - return false; + server_entry * serverInfo = &entries[i]; + fs.WriteString(serverInfo->address); + fs.WriteString(serverInfo->name); + fs.WriteString(serverInfo->description); } + return true; + } + catch (const std::exception &) + { + return false; } } + diff --git a/src/openrct2/network/ServerList.h b/src/openrct2/network/ServerList.h index 5da0d19916..8bcdfb498e 100644 --- a/src/openrct2/network/ServerList.h +++ b/src/openrct2/network/ServerList.h @@ -30,12 +30,6 @@ typedef struct server_entry uint8 maxplayers; } server_entry; -#ifdef __cplusplus -extern "C" -{ -#endif - bool server_list_read(uint32 * outNumEntries, server_entry * * outEntries); - bool server_list_write(uint32 numEntries, server_entry * entries); -#ifdef __cplusplus -} -#endif +bool server_list_read(uint32 * outNumEntries, server_entry * * outEntries); +bool server_list_write(uint32 numEntries, server_entry * entries); + diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index 7c1dcc3be1..412ed49bfc 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -301,9 +301,6 @@ private: #define NETWORK_STREAM_ID "Multiplayer disabled" #endif /* DISABLE_NETWORK */ -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus void network_set_env(void * env); void network_close(); void network_shutdown_client(); @@ -373,8 +370,4 @@ const utf8 * network_get_server_provider_name(); const utf8 * network_get_server_provider_email(); const utf8 * network_get_server_provider_website(); -#ifdef __cplusplus -} -#endif // __cplusplus - #endif diff --git a/src/openrct2/network/twitch.h b/src/openrct2/network/twitch.h index 8554019209..87dc80464e 100644 --- a/src/openrct2/network/twitch.h +++ b/src/openrct2/network/twitch.h @@ -19,16 +19,8 @@ #include "../common.h" -#ifdef __cplusplus -extern "C" { -#endif - extern bool gTwitchEnable; void twitch_update(); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index 9b5e83a9bf..dff621c9b6 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -224,29 +224,20 @@ enum OBJECT_ERROR : uint32 #endif -#ifdef __cplusplus -extern "C" { -#endif - - extern sint32 object_entry_group_counts[]; - extern sint32 object_entry_group_encoding[]; - - extern const rct_object_entry_group object_entry_groups[]; - - void object_list_load(); - - bool object_entry_is_empty(const rct_object_entry *entry); - bool object_entry_compare(const rct_object_entry *a, const rct_object_entry *b); - sint32 object_calculate_checksum(const rct_object_entry * entry, const void * data, size_t dataLength); - bool find_object_in_entry_group(const rct_object_entry* entry, uint8* entry_type, uint8* entry_index); - void object_create_identifier_name(char* string_buffer, size_t size, const rct_object_entry* object); - - const rct_object_entry * object_list_find_by_name(const char *name); - const rct_object_entry * object_list_find(rct_object_entry *entry); - - void object_entry_get_name_fixed(utf8 * buffer, size_t bufferSize, const rct_object_entry * entry); - -#ifdef __cplusplus -} -#endif +extern sint32 object_entry_group_counts[]; +extern sint32 object_entry_group_encoding[]; +extern const rct_object_entry_group object_entry_groups[]; + +void object_list_load(); + +bool object_entry_is_empty(const rct_object_entry *entry); +bool object_entry_compare(const rct_object_entry *a, const rct_object_entry *b); +sint32 object_calculate_checksum(const rct_object_entry * entry, const void * data, size_t dataLength); +bool find_object_in_entry_group(const rct_object_entry* entry, uint8* entry_type, uint8* entry_index); +void object_create_identifier_name(char* string_buffer, size_t size, const rct_object_entry* object); + +const rct_object_entry * object_list_find_by_name(const char *name); +const rct_object_entry * object_list_find(rct_object_entry *entry); + +void object_entry_get_name_fixed(utf8 * buffer, size_t bufferSize, const rct_object_entry * entry); diff --git a/src/openrct2/object/ObjectList.h b/src/openrct2/object/ObjectList.h index 891ba14a06..d20bdaae91 100644 --- a/src/openrct2/object/ObjectList.h +++ b/src/openrct2/object/ObjectList.h @@ -8,11 +8,6 @@ #include "../world/Water.h" #include "ObjectLimits.h" -#ifdef __cplusplus -extern "C" -{ -#endif - extern rct_ride_entry *gRideEntries[MAX_RIDE_OBJECTS]; extern rct_small_scenery_entry *gSmallSceneryEntries[MAX_SMALL_SCENERY_OBJECTS]; extern rct_large_scenery_entry *gLargeSceneryEntries[MAX_LARGE_SCENERY_OBJECTS]; @@ -30,6 +25,3 @@ const rct_object_entry * get_loaded_object_entry(size_t index); void * get_loaded_object_chunk(size_t index); uint8 object_entry_get_source_game(const rct_object_entry * objectEntry); -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/object/ObjectManager.cpp b/src/openrct2/object/ObjectManager.cpp index a096a961eb..72dd1452cf 100644 --- a/src/openrct2/object/ObjectManager.cpp +++ b/src/openrct2/object/ObjectManager.cpp @@ -628,54 +628,52 @@ IObjectManager * GetObjectManager() return _objectManager; } -extern "C" +void * object_manager_get_loaded_object_by_index(size_t index) { - void * object_manager_get_loaded_object_by_index(size_t index) - { - IObjectManager * objectManager = GetObjectManager(); - Object * loadedObject = objectManager->GetLoadedObject(index); - return (void *)loadedObject; - } + IObjectManager * objectManager = GetObjectManager(); + Object * loadedObject = objectManager->GetLoadedObject(index); + return (void *)loadedObject; +} - void * object_manager_get_loaded_object(const rct_object_entry * entry) - { - IObjectManager * objectManager = GetObjectManager(); - Object * loadedObject = objectManager->GetLoadedObject(entry); - return (void *)loadedObject; - } +void * object_manager_get_loaded_object(const rct_object_entry * entry) +{ + IObjectManager * objectManager = GetObjectManager(); + Object * loadedObject = objectManager->GetLoadedObject(entry); + return (void *)loadedObject; +} - uint8 object_manager_get_loaded_object_entry_index(const void * loadedObject) - { - IObjectManager * objectManager = GetObjectManager(); - const Object * object = static_cast(loadedObject); - uint8 entryIndex = objectManager->GetLoadedObjectEntryIndex(object); - return entryIndex; - } +uint8 object_manager_get_loaded_object_entry_index(const void * loadedObject) +{ + IObjectManager * objectManager = GetObjectManager(); + const Object * object = static_cast(loadedObject); + uint8 entryIndex = objectManager->GetLoadedObjectEntryIndex(object); + return entryIndex; +} - void * object_manager_load_object(const rct_object_entry * entry) - { - IObjectManager * objectManager = GetObjectManager(); - Object * loadedObject = objectManager->LoadObject(entry); - return (void *)loadedObject; - } +void * object_manager_load_object(const rct_object_entry * entry) +{ + IObjectManager * objectManager = GetObjectManager(); + Object * loadedObject = objectManager->LoadObject(entry); + return (void *)loadedObject; +} - void object_manager_unload_objects(const rct_object_entry * entries, size_t count) - { - IObjectManager * objectManager = GetObjectManager(); - objectManager->UnloadObjects(entries, count); - } +void object_manager_unload_objects(const rct_object_entry * entries, size_t count) +{ + IObjectManager * objectManager = GetObjectManager(); + objectManager->UnloadObjects(entries, count); +} - void object_manager_unload_all_objects() +void object_manager_unload_all_objects() +{ + IObjectManager * objectManager = GetObjectManager(); + if (objectManager != nullptr) { - IObjectManager * objectManager = GetObjectManager(); - if (objectManager != nullptr) - { - objectManager->UnloadAll(); - } - } - - rct_string_id object_manager_get_source_game_string(const rct_object_entry * entry) - { - return ObjectManager::GetObjectSourceGameString(entry); + objectManager->UnloadAll(); } } + +rct_string_id object_manager_get_source_game_string(const rct_object_entry * entry) +{ + return ObjectManager::GetObjectSourceGameString(entry); +} + diff --git a/src/openrct2/object/ObjectManager.h b/src/openrct2/object/ObjectManager.h index 67b10afcba..b822a1e8c7 100644 --- a/src/openrct2/object/ObjectManager.h +++ b/src/openrct2/object/ObjectManager.h @@ -53,11 +53,6 @@ IObjectManager * GetObjectManager(); #endif -#ifdef __cplusplus -extern "C" -{ -#endif - void * object_manager_get_loaded_object_by_index(size_t index); void * object_manager_get_loaded_object(const rct_object_entry * entry); uint8 object_manager_get_loaded_object_entry_index(const void * loadedObject); @@ -65,7 +60,3 @@ void * object_manager_load_object(const rct_object_entry * entry); void object_manager_unload_objects(const rct_object_entry * entries, size_t count); void object_manager_unload_all_objects(); rct_string_id object_manager_get_source_game_string(const rct_object_entry * entry); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 547a0ec6d0..8bf3128a79 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -632,200 +632,198 @@ bool IsObjectCustom(const ObjectRepositoryItem * object) return !(object->ObjectEntry.flags & 0xF0); } -extern "C" +const rct_object_entry * object_list_find(rct_object_entry * entry) { - const rct_object_entry * object_list_find(rct_object_entry * entry) + const rct_object_entry * result = nullptr; + auto objRepo = GetObjectRepository(); + auto item = objRepo->FindObject(entry); + if (item != nullptr) { - const rct_object_entry * result = nullptr; - auto objRepo = GetObjectRepository(); - auto item = objRepo->FindObject(entry); - if (item != nullptr) - { - result = &item->ObjectEntry; - } - return result; + result = &item->ObjectEntry; } + return result; +} - const rct_object_entry * object_list_find_by_name(const char * name) +const rct_object_entry * object_list_find_by_name(const char * name) +{ + const rct_object_entry * result = nullptr; + auto objRepo = GetObjectRepository(); + auto item = objRepo->FindObject(name); + if (item != nullptr) { - const rct_object_entry * result = nullptr; - auto objRepo = GetObjectRepository(); - auto item = objRepo->FindObject(name); - if (item != nullptr) - { - result = &item->ObjectEntry; - } - return result; + result = &item->ObjectEntry; } + return result; +} - void object_list_load() +void object_list_load() +{ + IObjectRepository * objectRepository = GetObjectRepository(); + objectRepository->LoadOrConstruct(); + + IObjectManager * objectManager = GetObjectManager(); + objectManager->UnloadAll(); +} + +void * object_repository_load_object(const rct_object_entry * objectEntry) +{ + Object * object = nullptr; + IObjectRepository * objRepository = GetObjectRepository(); + const ObjectRepositoryItem * ori = objRepository->FindObject(objectEntry); + if (ori != nullptr) { - IObjectRepository * objectRepository = GetObjectRepository(); - objectRepository->LoadOrConstruct(); - - IObjectManager * objectManager = GetObjectManager(); - objectManager->UnloadAll(); - } - - void * object_repository_load_object(const rct_object_entry * objectEntry) - { - Object * object = nullptr; - IObjectRepository * objRepository = GetObjectRepository(); - const ObjectRepositoryItem * ori = objRepository->FindObject(objectEntry); - if (ori != nullptr) + object = objRepository->LoadObject(ori); + if (object != nullptr) { - object = objRepository->LoadObject(ori); - if (object != nullptr) - { - object->Load(); - } + object->Load(); } - return (void *)object; } + return (void *)object; +} - void scenario_translate(scenario_index_entry * scenarioEntry, const rct_object_entry * stexObjectEntry) +void scenario_translate(scenario_index_entry * scenarioEntry, const rct_object_entry * stexObjectEntry) +{ + rct_string_id localisedStringIds[3]; + if (language_get_localised_scenario_strings(scenarioEntry->name, localisedStringIds)) { - rct_string_id localisedStringIds[3]; - if (language_get_localised_scenario_strings(scenarioEntry->name, localisedStringIds)) + if (localisedStringIds[0] != STR_NONE) { - if (localisedStringIds[0] != STR_NONE) - { - String::Set(scenarioEntry->name, sizeof(scenarioEntry->name), language_get_string(localisedStringIds[0])); - } - if (localisedStringIds[2] != STR_NONE) - { - String::Set(scenarioEntry->details, sizeof(scenarioEntry->details), language_get_string(localisedStringIds[2])); - } + String::Set(scenarioEntry->name, sizeof(scenarioEntry->name), language_get_string(localisedStringIds[0])); } - else + if (localisedStringIds[2] != STR_NONE) { - // Checks for a scenario string object (possibly for localisation) - if ((stexObjectEntry->flags & 0xFF) != 255) + String::Set(scenarioEntry->details, sizeof(scenarioEntry->details), language_get_string(localisedStringIds[2])); + } + } + else + { + // Checks for a scenario string object (possibly for localisation) + if ((stexObjectEntry->flags & 0xFF) != 255) + { + IObjectRepository * objectRepository = GetObjectRepository(); + const ObjectRepositoryItem * ori = objectRepository->FindObject(stexObjectEntry); + if (ori != nullptr) { - IObjectRepository * objectRepository = GetObjectRepository(); - const ObjectRepositoryItem * ori = objectRepository->FindObject(stexObjectEntry); - if (ori != nullptr) + Object * object = objectRepository->LoadObject(ori); + if (object != nullptr) { - Object * object = objectRepository->LoadObject(ori); - if (object != nullptr) - { - auto stexObject = static_cast(object); - auto scenarioName = stexObject->GetScenarioName(); - auto scenarioDetails = stexObject->GetScenarioDetails(); + auto stexObject = static_cast(object); + auto scenarioName = stexObject->GetScenarioName(); + auto scenarioDetails = stexObject->GetScenarioDetails(); - String::Set(scenarioEntry->name, sizeof(scenarioEntry->name), scenarioName.c_str()); - String::Set(scenarioEntry->details, sizeof(scenarioEntry->details), scenarioDetails.c_str()); + String::Set(scenarioEntry->name, sizeof(scenarioEntry->name), scenarioName.c_str()); + String::Set(scenarioEntry->details, sizeof(scenarioEntry->details), scenarioDetails.c_str()); - delete object; - } + delete object; } } } } +} - size_t object_repository_get_items_count() +size_t object_repository_get_items_count() +{ + IObjectRepository * objectRepository = GetObjectRepository(); + return objectRepository->GetNumObjects(); +} + +const ObjectRepositoryItem * object_repository_get_items() +{ + IObjectRepository * objectRepository = GetObjectRepository(); + return objectRepository->GetObjects(); +} + +const ObjectRepositoryItem * object_repository_find_object_by_entry(const rct_object_entry * entry) +{ + IObjectRepository * objectRepository = GetObjectRepository(); + return objectRepository->FindObject(entry); +} + +const ObjectRepositoryItem * object_repository_find_object_by_name(const char * name) +{ + IObjectRepository * objectRepository = GetObjectRepository(); + return objectRepository->FindObject(name); +} + +void object_delete(void * object) +{ + if (object != nullptr) { - IObjectRepository * objectRepository = GetObjectRepository(); - return objectRepository->GetNumObjects(); - } - - const ObjectRepositoryItem * object_repository_get_items() - { - IObjectRepository * objectRepository = GetObjectRepository(); - return objectRepository->GetObjects(); - } - - const ObjectRepositoryItem * object_repository_find_object_by_entry(const rct_object_entry * entry) - { - IObjectRepository * objectRepository = GetObjectRepository(); - return objectRepository->FindObject(entry); - } - - const ObjectRepositoryItem * object_repository_find_object_by_name(const char * name) - { - IObjectRepository * objectRepository = GetObjectRepository(); - return objectRepository->FindObject(name); - } - - void object_delete(void * object) - { - if (object != nullptr) - { - Object * baseObject = static_cast(object); - baseObject->Unload(); - delete baseObject; - } - } - - void object_draw_preview(const void * object, rct_drawpixelinfo * dpi, sint32 width, sint32 height) - { - const Object * baseObject = static_cast(object); - baseObject->DrawPreview(dpi, width, height); - } - - bool object_entry_compare(const rct_object_entry * a, const rct_object_entry * b) - { - // If an official object don't bother checking checksum - if ((a->flags & 0xF0) || (b->flags & 0xF0)) - { - if ((a->flags & 0x0F) != (b->flags & 0x0F)) - { - return false; - } - sint32 match = memcmp(a->name, b->name, 8); - if (match) - { - return false; - } - } - else - { - if (a->flags != b->flags) - { - return false; - } - sint32 match = memcmp(a->name, b->name, 8); - if (match) - { - return false; - } - if (a->checksum != b->checksum) - { - return false; - } - } - return true; - } - - sint32 object_calculate_checksum(const rct_object_entry * entry, const void * data, size_t dataLength) - { - const uint8 * entryBytePtr = (uint8 *)entry; - - uint32 checksum = 0xF369A75B; - checksum ^= entryBytePtr[0]; - checksum = rol32(checksum, 11); - for (sint32 i = 4; i < 12; i++) - { - checksum ^= entryBytePtr[i]; - checksum = rol32(checksum, 11); - } - - uint8 * dataBytes = (uint8 *)data; - const size_t dataLength32 = dataLength - (dataLength & 31); - for (size_t i = 0; i < 32; i++) - { - for (size_t j = i; j < dataLength32; j += 32) - { - checksum ^= dataBytes[j]; - } - checksum = rol32(checksum, 11); - } - for (size_t i = dataLength32; i < dataLength; i++) - { - checksum ^= dataBytes[i]; - checksum = rol32(checksum, 11); - } - - return (sint32)checksum; + Object * baseObject = static_cast(object); + baseObject->Unload(); + delete baseObject; } } + +void object_draw_preview(const void * object, rct_drawpixelinfo * dpi, sint32 width, sint32 height) +{ + const Object * baseObject = static_cast(object); + baseObject->DrawPreview(dpi, width, height); +} + +bool object_entry_compare(const rct_object_entry * a, const rct_object_entry * b) +{ + // If an official object don't bother checking checksum + if ((a->flags & 0xF0) || (b->flags & 0xF0)) + { + if ((a->flags & 0x0F) != (b->flags & 0x0F)) + { + return false; + } + sint32 match = memcmp(a->name, b->name, 8); + if (match) + { + return false; + } + } + else + { + if (a->flags != b->flags) + { + return false; + } + sint32 match = memcmp(a->name, b->name, 8); + if (match) + { + return false; + } + if (a->checksum != b->checksum) + { + return false; + } + } + return true; +} + +sint32 object_calculate_checksum(const rct_object_entry * entry, const void * data, size_t dataLength) +{ + const uint8 * entryBytePtr = (uint8 *)entry; + + uint32 checksum = 0xF369A75B; + checksum ^= entryBytePtr[0]; + checksum = rol32(checksum, 11); + for (sint32 i = 4; i < 12; i++) + { + checksum ^= entryBytePtr[i]; + checksum = rol32(checksum, 11); + } + + uint8 * dataBytes = (uint8 *)data; + const size_t dataLength32 = dataLength - (dataLength & 31); + for (size_t i = 0; i < 32; i++) + { + for (size_t j = i; j < dataLength32; j += 32) + { + checksum ^= dataBytes[j]; + } + checksum = rol32(checksum, 11); + } + for (size_t i = dataLength32; i < dataLength; i++) + { + checksum ^= dataBytes[i]; + checksum = rol32(checksum, 11); + } + + return (sint32)checksum; +} + diff --git a/src/openrct2/object/ObjectRepository.h b/src/openrct2/object/ObjectRepository.h index 70e2e03561..fbedc6b931 100644 --- a/src/openrct2/object/ObjectRepository.h +++ b/src/openrct2/object/ObjectRepository.h @@ -94,11 +94,6 @@ bool IsObjectCustom(const ObjectRepositoryItem * object); #endif -#ifdef __cplusplus -extern "C" -{ -#endif - size_t object_repository_get_items_count(); const ObjectRepositoryItem * object_repository_get_items(); const ObjectRepositoryItem * object_repository_find_object_by_entry(const rct_object_entry * entry); @@ -107,7 +102,3 @@ void * object_repository_load_object(const rct_object_e void object_delete(void * object); void object_draw_preview(const void * object, rct_drawpixelinfo * dpi, sint32 width, sint32 height); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 82417ad335..9ef5b4f0f3 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -722,495 +722,491 @@ static void draw_pixel_info_crop_by_zoom(rct_drawpixelinfo *dpi) dpi->height >>= zoom; } -extern "C" +paint_session * paint_session_alloc(rct_drawpixelinfo * dpi) { - paint_session * paint_session_alloc(rct_drawpixelinfo * dpi) - { - // Currently limited to just one session at a time - assert(!_paintSessionInUse); - _paintSessionInUse = true; - paint_session * session = &gPaintSession; - - paint_session_init(session, dpi); - return session; - } - - void paint_session_free(paint_session * session) - { - _paintSessionInUse = false; - } - - /** - * rct2: 0x006861AC, 0x00686337, 0x006864D0, 0x0068666B, 0x0098196C - * - * @param image_id (ebx) - * @param x_offset (al) - * @param y_offset (cl) - * @param bound_box_length_x (di) - * @param bound_box_length_y (si) - * @param bound_box_length_z (ah) - * @param z_offset (dx) - * @param rotation (ebp) - * @return (ebp) paint_struct on success (CF == 0), nullptr on failure (CF == 1) - */ - paint_struct * sub_98196C( - paint_session * session, - uint32 image_id, - sint8 x_offset, sint8 y_offset, - sint16 bound_box_length_x, sint16 bound_box_length_y, sint8 bound_box_length_z, - sint16 z_offset, - uint32 rotation) - { - assert((uint16)bound_box_length_x == (sint16)bound_box_length_x); - assert((uint16)bound_box_length_y == (sint16)bound_box_length_y); - - session->UnkF1AD28 = nullptr; - session->UnkF1AD2C = nullptr; - - if (session->NextFreePaintStruct >= session->EndOfPaintStructArray) - { - return nullptr; - } - - auto g1Element = gfx_get_g1_element(image_id & 0x7FFFF); - if (g1Element == nullptr) - { - return nullptr; - } - - paint_struct *ps = &session->NextFreePaintStruct->basic; - ps->image_id = image_id; - - LocationXYZ16 coord_3d = - { - x_offset, // ax - y_offset, // cx - z_offset - }; - - LocationXYZ16 boundBox = - { - bound_box_length_x, // di - bound_box_length_y, // si - bound_box_length_z, - }; - - switch (rotation) - { - case 0: - rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_WEST); - - boundBox.x--; - boundBox.y--; - rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_WEST); - break; - - case 1: - rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_SOUTH); - - boundBox.x--; - rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_SOUTH); - break; - - case 2: - rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_EAST); - rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_EAST); - break; - - case 3: - rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_NORTH); - - boundBox.y--; - rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_NORTH); - break; - } - - coord_3d.x += session->SpritePosition.x; - coord_3d.y += session->SpritePosition.y; - - ps->bounds.x_end = coord_3d.x + boundBox.x; - ps->bounds.y_end = coord_3d.y + boundBox.y; - - // TODO: check whether this is right. edx is ((bound_box_length_z + z_offset) << 16 | z_offset) - ps->bounds.z = coord_3d.z; - ps->bounds.z_end = (boundBox.z + coord_3d.z); - - LocationXY16 map = coordinate_3d_to_2d(&coord_3d, rotation); - - ps->x = map.x; - ps->y = map.y; - - sint16 left = map.x + g1Element->x_offset; - sint16 bottom = map.y + g1Element->y_offset; - - sint16 right = left + g1Element->width; - sint16 top = bottom + g1Element->height; - - rct_drawpixelinfo *dpi = session->Unk140E9A8; - - if (right <= dpi->x) return nullptr; - if (top <= dpi->y) return nullptr; - if (left >= (dpi->x + dpi->width)) return nullptr; - if (bottom >= (dpi->y + dpi->height)) return nullptr; - - ps->flags = 0; - ps->bounds.x = coord_3d.x; - ps->bounds.y = coord_3d.y; - ps->attached_ps = nullptr; - ps->var_20 = nullptr; - ps->sprite_type = session->InteractionType; - ps->var_29 = 0; - ps->map_x = session->MapPosition.x; - ps->map_y = session->MapPosition.y; - ps->tileElement = (rct_tile_element*)session->CurrentlyDrawnItem; - - session->UnkF1AD28 = ps; - - sint32 positionHash = 0; - switch (rotation) - { - case 0: - positionHash = coord_3d.y + coord_3d.x; - break; - case 1: - positionHash = coord_3d.y - coord_3d.x + 0x2000; - break; - case 2: - positionHash = -(coord_3d.y + coord_3d.x) + 0x4000; - break; - case 3: - positionHash = coord_3d.x - coord_3d.y + 0x2000; - break; - } - paint_session_add_ps_to_quadrant(session, ps, positionHash); - - session->NextFreePaintStruct++; - - return ps; - } - - /** - * rct2: 0x00686806, 0x006869B2, 0x00686B6F, 0x00686D31, 0x0098197C - * - * @param image_id (ebx) - * @param x_offset (al) - * @param y_offset (cl) - * @param bound_box_length_x (di) - * @param bound_box_length_y (si) - * @param bound_box_length_z (ah) - * @param z_offset (dx) - * @param bound_box_offset_x (0x009DEA52) - * @param bound_box_offset_y (0x009DEA54) - * @param bound_box_offset_z (0x009DEA56) - * @param rotation (ebp) - * @return (ebp) paint_struct on success (CF == 0), nullptr on failure (CF == 1) - */ - paint_struct * sub_98197C( - paint_session * session, - uint32 image_id, - sint8 x_offset, sint8 y_offset, - sint16 bound_box_length_x, sint16 bound_box_length_y, sint8 bound_box_length_z, - sint16 z_offset, - sint16 bound_box_offset_x, sint16 bound_box_offset_y, sint16 bound_box_offset_z, - uint32 rotation) - { - session->UnkF1AD28 = nullptr; - session->UnkF1AD2C = nullptr; - - LocationXYZ16 offset = { x_offset, y_offset, z_offset }; - LocationXYZ16 boundBoxSize = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; - LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; - paint_struct * ps = sub_9819_c(session, image_id, offset, boundBoxSize, boundBoxOffset, rotation); - - if (ps == nullptr) { - return nullptr; - } - - session->UnkF1AD28 = ps; - - LocationXY16 attach = - { - (sint16)ps->bounds.x, - (sint16)ps->bounds.y - }; - - rotate_map_coordinates(&attach.x, &attach.y, rotation); - switch (rotation) - { - case 0: - break; - case 1: - case 3: - attach.x += 0x2000; - break; - case 2: - attach.x += 0x4000; - break; - } - - sint32 positionHash = attach.x + attach.y; - paint_session_add_ps_to_quadrant(session, ps, positionHash); - - session->NextFreePaintStruct++; - return ps; - } - - /** - * - * rct2: 0x00686EF0, 0x00687056, 0x006871C8, 0x0068733C, 0x0098198C - * - * @param image_id (ebx) - * @param x_offset (al) - * @param y_offset (cl) - * @param bound_box_length_x (di) - * @param bound_box_length_y (si) - * @param bound_box_length_z (ah) - * @param z_offset (dx) - * @param bound_box_offset_x (0x009DEA52) - * @param bound_box_offset_y (0x009DEA54) - * @param bound_box_offset_z (0x009DEA56) - * @param rotation (ebp) - * @return (ebp) paint_struct on success (CF == 0), nullptr on failure (CF == 1) - */ - paint_struct * sub_98198C( - paint_session * session, - uint32 image_id, - sint8 x_offset, sint8 y_offset, - sint16 bound_box_length_x, sint16 bound_box_length_y, sint8 bound_box_length_z, - sint16 z_offset, - sint16 bound_box_offset_x, sint16 bound_box_offset_y, sint16 bound_box_offset_z, - uint32 rotation) - { - assert((uint16)bound_box_length_x == (sint16)bound_box_length_x); - assert((uint16)bound_box_length_y == (sint16)bound_box_length_y); - - session->UnkF1AD28 = nullptr; - session->UnkF1AD2C = nullptr; - - LocationXYZ16 offset = { x_offset, y_offset, z_offset }; - LocationXYZ16 boundBoxSize = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; - LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; - paint_struct * ps = sub_9819_c(session, image_id, offset, boundBoxSize, boundBoxOffset, rotation); - - if (ps == nullptr) { - return nullptr; - } - - session->UnkF1AD28 = ps; - session->NextFreePaintStruct++; - return ps; - } - - /** - * - * rct2: 0x006874B0, 0x00687618, 0x0068778C, 0x00687902, 0x0098199C - * - * @param image_id (ebx) - * @param x_offset (al) - * @param y_offset (cl) - * @param bound_box_length_x (di) - * @param bound_box_length_y (si) - * @param bound_box_length_z (ah) - * @param z_offset (dx) - * @param bound_box_offset_x (0x009DEA52) - * @param bound_box_offset_y (0x009DEA54) - * @param bound_box_offset_z (0x009DEA56) - * @param rotation (ebp) - * @return (ebp) paint_struct on success (CF == 0), nullptr on failure (CF == 1) - */ - paint_struct * sub_98199C( - paint_session * session, - uint32 image_id, - sint8 x_offset, sint8 y_offset, - sint16 bound_box_length_x, sint16 bound_box_length_y, sint8 bound_box_length_z, - sint16 z_offset, - sint16 bound_box_offset_x, sint16 bound_box_offset_y, sint16 bound_box_offset_z, - uint32 rotation) - { - assert((uint16)bound_box_length_x == (sint16)bound_box_length_x); - assert((uint16)bound_box_length_y == (sint16)bound_box_length_y); - - if (session->UnkF1AD28 == nullptr) - { - return sub_98197C(session, - image_id, - x_offset, y_offset, - bound_box_length_x, bound_box_length_y, bound_box_length_z, - z_offset, - bound_box_offset_x, bound_box_offset_y, bound_box_offset_z, - rotation - ); - } - - LocationXYZ16 offset = { x_offset, y_offset, z_offset }; - LocationXYZ16 boundBox = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; - LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; - paint_struct * ps = sub_9819_c(session, image_id, offset, boundBox, boundBoxOffset, rotation); - - if (ps == nullptr) - { - return nullptr; - } - - paint_struct *old_ps = session->UnkF1AD28; - old_ps->var_20 = ps; - - session->UnkF1AD28 = ps; - session->NextFreePaintStruct++; - return ps; - } - - /** - * rct2: 0x006881D0 - * - * @param image_id (ebx) - * @param x (ax) - * @param y (cx) - * @return (!CF) success - */ - bool paint_attach_to_previous_attach(paint_session * session, uint32 image_id, uint16 x, uint16 y) - { - if (session->UnkF1AD2C == nullptr) - { - return paint_attach_to_previous_ps(session, image_id, x, y); - } - - if (session->NextFreePaintStruct >= session->EndOfPaintStructArray) - { - return false; - } - attached_paint_struct * ps = &session->NextFreePaintStruct->attached; - ps->image_id = image_id; - ps->x = x; - ps->y = y; - ps->flags = 0; - - attached_paint_struct * ebx = session->UnkF1AD2C; - - ps->next = nullptr; - ebx->next = ps; - - session->UnkF1AD2C = ps; - - session->NextFreePaintStruct++; - - return true; - } - - /** - * rct2: 0x0068818E - * - * @param image_id (ebx) - * @param x (ax) - * @param y (cx) - * @return (!CF) success - */ - bool paint_attach_to_previous_ps(paint_session * session, uint32 image_id, uint16 x, uint16 y) - { - if (session->NextFreePaintStruct >= session->EndOfPaintStructArray) - { - return false; - } - attached_paint_struct * ps = &session->NextFreePaintStruct->attached; - - ps->image_id = image_id; - ps->x = x; - ps->y = y; - ps->flags = 0; - - paint_struct * masterPs = session->UnkF1AD28; - if (masterPs == nullptr) - { - return false; - } - - session->NextFreePaintStruct++; - - attached_paint_struct * oldFirstAttached = masterPs->attached_ps; - masterPs->attached_ps = ps; - - ps->next = oldFirstAttached; - - session->UnkF1AD2C = ps; - - return true; - } - - /** - * rct2: 0x00685EBC, 0x00686046, 0x00685FC8, 0x00685F4A, 0x00685ECC - * @param amount (eax) - * @param string_id (bx) - * @param y (cx) - * @param z (dx) - * @param offset_x (si) - * @param y_offsets (di) - * @param rotation (ebp) - */ - void paint_floating_money_effect(paint_session * session, money32 amount, rct_string_id string_id, sint16 y, sint16 z, sint8 y_offsets[], sint16 offset_x, uint32 rotation) - { - if (session->NextFreePaintStruct >= session->EndOfPaintStructArray) - { - return; - } - - paint_string_struct * ps = &session->NextFreePaintStruct->string; - ps->string_id = string_id; - ps->next = nullptr; - ps->args[0] = amount; - ps->args[1] = y; - ps->args[2] = 0; - ps->args[3] = 0; - ps->y_offsets = (uint8 *)y_offsets; - - const LocationXYZ16 position = - { - session->SpritePosition.x, - session->SpritePosition.y, - z - }; - const LocationXY16 coord = coordinate_3d_to_2d(&position, rotation); - - ps->x = coord.x + offset_x; - ps->y = coord.y; - - session->NextFreePaintStruct++; - - if (session->LastPSString == nullptr) - { - session->PSStringHead = ps; - } - else - { - session->LastPSString->next = ps; - } - session->LastPSString = ps; - } - - /** - * - * rct2: 0x006860C3 - */ - void paint_draw_money_structs(rct_drawpixelinfo * dpi, paint_string_struct * ps) - { - rct_drawpixelinfo dpi2 = *dpi; - draw_pixel_info_crop_by_zoom(&dpi2); - - do - { - utf8 buffer[256]; - format_string(buffer, 256, ps->string_id, &ps->args); - gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; - - // Use sprite font unless the currency contains characters unsupported by the sprite font - bool forceSpriteFont = false; - const currency_descriptor& currencyDesc = CurrencyDescriptors[gConfigGeneral.currency_format]; - if (gUseTrueTypeFont && font_supports_string_sprite(currencyDesc.symbol_unicode)) - { - forceSpriteFont = true; - } - - gfx_draw_string_with_y_offsets(&dpi2, buffer, COLOUR_BLACK, ps->x, ps->y, (sint8 *)ps->y_offsets, forceSpriteFont); - } while ((ps = ps->next) != nullptr); - } + // Currently limited to just one session at a time + assert(!_paintSessionInUse); + _paintSessionInUse = true; + paint_session * session = &gPaintSession; + paint_session_init(session, dpi); + return session; } + +void paint_session_free(paint_session * session) +{ + _paintSessionInUse = false; +} + +/** +* rct2: 0x006861AC, 0x00686337, 0x006864D0, 0x0068666B, 0x0098196C +* +* @param image_id (ebx) +* @param x_offset (al) +* @param y_offset (cl) +* @param bound_box_length_x (di) +* @param bound_box_length_y (si) +* @param bound_box_length_z (ah) +* @param z_offset (dx) +* @param rotation (ebp) +* @return (ebp) paint_struct on success (CF == 0), nullptr on failure (CF == 1) +*/ +paint_struct * sub_98196C( + paint_session * session, + uint32 image_id, + sint8 x_offset, sint8 y_offset, + sint16 bound_box_length_x, sint16 bound_box_length_y, sint8 bound_box_length_z, + sint16 z_offset, + uint32 rotation) +{ + assert((uint16)bound_box_length_x == (sint16)bound_box_length_x); + assert((uint16)bound_box_length_y == (sint16)bound_box_length_y); + + session->UnkF1AD28 = nullptr; + session->UnkF1AD2C = nullptr; + + if (session->NextFreePaintStruct >= session->EndOfPaintStructArray) + { + return nullptr; + } + + auto g1Element = gfx_get_g1_element(image_id & 0x7FFFF); + if (g1Element == nullptr) + { + return nullptr; + } + + paint_struct *ps = &session->NextFreePaintStruct->basic; + ps->image_id = image_id; + + LocationXYZ16 coord_3d = + { + x_offset, // ax + y_offset, // cx + z_offset + }; + + LocationXYZ16 boundBox = + { + bound_box_length_x, // di + bound_box_length_y, // si + bound_box_length_z, + }; + + switch (rotation) + { + case 0: + rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_WEST); + + boundBox.x--; + boundBox.y--; + rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_WEST); + break; + + case 1: + rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_SOUTH); + + boundBox.x--; + rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_SOUTH); + break; + + case 2: + rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_EAST); + rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_EAST); + break; + + case 3: + rotate_map_coordinates(&coord_3d.x, &coord_3d.y, TILE_ELEMENT_DIRECTION_NORTH); + + boundBox.y--; + rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_NORTH); + break; + } + + coord_3d.x += session->SpritePosition.x; + coord_3d.y += session->SpritePosition.y; + + ps->bounds.x_end = coord_3d.x + boundBox.x; + ps->bounds.y_end = coord_3d.y + boundBox.y; + + // TODO: check whether this is right. edx is ((bound_box_length_z + z_offset) << 16 | z_offset) + ps->bounds.z = coord_3d.z; + ps->bounds.z_end = (boundBox.z + coord_3d.z); + + LocationXY16 map = coordinate_3d_to_2d(&coord_3d, rotation); + + ps->x = map.x; + ps->y = map.y; + + sint16 left = map.x + g1Element->x_offset; + sint16 bottom = map.y + g1Element->y_offset; + + sint16 right = left + g1Element->width; + sint16 top = bottom + g1Element->height; + + rct_drawpixelinfo *dpi = session->Unk140E9A8; + + if (right <= dpi->x) return nullptr; + if (top <= dpi->y) return nullptr; + if (left >= (dpi->x + dpi->width)) return nullptr; + if (bottom >= (dpi->y + dpi->height)) return nullptr; + + ps->flags = 0; + ps->bounds.x = coord_3d.x; + ps->bounds.y = coord_3d.y; + ps->attached_ps = nullptr; + ps->var_20 = nullptr; + ps->sprite_type = session->InteractionType; + ps->var_29 = 0; + ps->map_x = session->MapPosition.x; + ps->map_y = session->MapPosition.y; + ps->tileElement = (rct_tile_element*)session->CurrentlyDrawnItem; + + session->UnkF1AD28 = ps; + + sint32 positionHash = 0; + switch (rotation) + { + case 0: + positionHash = coord_3d.y + coord_3d.x; + break; + case 1: + positionHash = coord_3d.y - coord_3d.x + 0x2000; + break; + case 2: + positionHash = -(coord_3d.y + coord_3d.x) + 0x4000; + break; + case 3: + positionHash = coord_3d.x - coord_3d.y + 0x2000; + break; + } + paint_session_add_ps_to_quadrant(session, ps, positionHash); + + session->NextFreePaintStruct++; + + return ps; +} + +/** +* rct2: 0x00686806, 0x006869B2, 0x00686B6F, 0x00686D31, 0x0098197C +* +* @param image_id (ebx) +* @param x_offset (al) +* @param y_offset (cl) +* @param bound_box_length_x (di) +* @param bound_box_length_y (si) +* @param bound_box_length_z (ah) +* @param z_offset (dx) +* @param bound_box_offset_x (0x009DEA52) +* @param bound_box_offset_y (0x009DEA54) +* @param bound_box_offset_z (0x009DEA56) +* @param rotation (ebp) +* @return (ebp) paint_struct on success (CF == 0), nullptr on failure (CF == 1) +*/ +paint_struct * sub_98197C( + paint_session * session, + uint32 image_id, + sint8 x_offset, sint8 y_offset, + sint16 bound_box_length_x, sint16 bound_box_length_y, sint8 bound_box_length_z, + sint16 z_offset, + sint16 bound_box_offset_x, sint16 bound_box_offset_y, sint16 bound_box_offset_z, + uint32 rotation) +{ + session->UnkF1AD28 = nullptr; + session->UnkF1AD2C = nullptr; + + LocationXYZ16 offset = { x_offset, y_offset, z_offset }; + LocationXYZ16 boundBoxSize = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; + LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; + paint_struct * ps = sub_9819_c(session, image_id, offset, boundBoxSize, boundBoxOffset, rotation); + + if (ps == nullptr) { + return nullptr; + } + + session->UnkF1AD28 = ps; + + LocationXY16 attach = + { + (sint16)ps->bounds.x, + (sint16)ps->bounds.y + }; + + rotate_map_coordinates(&attach.x, &attach.y, rotation); + switch (rotation) + { + case 0: + break; + case 1: + case 3: + attach.x += 0x2000; + break; + case 2: + attach.x += 0x4000; + break; + } + + sint32 positionHash = attach.x + attach.y; + paint_session_add_ps_to_quadrant(session, ps, positionHash); + + session->NextFreePaintStruct++; + return ps; +} + +/** +* +* rct2: 0x00686EF0, 0x00687056, 0x006871C8, 0x0068733C, 0x0098198C +* +* @param image_id (ebx) +* @param x_offset (al) +* @param y_offset (cl) +* @param bound_box_length_x (di) +* @param bound_box_length_y (si) +* @param bound_box_length_z (ah) +* @param z_offset (dx) +* @param bound_box_offset_x (0x009DEA52) +* @param bound_box_offset_y (0x009DEA54) +* @param bound_box_offset_z (0x009DEA56) +* @param rotation (ebp) +* @return (ebp) paint_struct on success (CF == 0), nullptr on failure (CF == 1) +*/ +paint_struct * sub_98198C( + paint_session * session, + uint32 image_id, + sint8 x_offset, sint8 y_offset, + sint16 bound_box_length_x, sint16 bound_box_length_y, sint8 bound_box_length_z, + sint16 z_offset, + sint16 bound_box_offset_x, sint16 bound_box_offset_y, sint16 bound_box_offset_z, + uint32 rotation) +{ + assert((uint16)bound_box_length_x == (sint16)bound_box_length_x); + assert((uint16)bound_box_length_y == (sint16)bound_box_length_y); + + session->UnkF1AD28 = nullptr; + session->UnkF1AD2C = nullptr; + + LocationXYZ16 offset = { x_offset, y_offset, z_offset }; + LocationXYZ16 boundBoxSize = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; + LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; + paint_struct * ps = sub_9819_c(session, image_id, offset, boundBoxSize, boundBoxOffset, rotation); + + if (ps == nullptr) { + return nullptr; + } + + session->UnkF1AD28 = ps; + session->NextFreePaintStruct++; + return ps; +} + +/** +* +* rct2: 0x006874B0, 0x00687618, 0x0068778C, 0x00687902, 0x0098199C +* +* @param image_id (ebx) +* @param x_offset (al) +* @param y_offset (cl) +* @param bound_box_length_x (di) +* @param bound_box_length_y (si) +* @param bound_box_length_z (ah) +* @param z_offset (dx) +* @param bound_box_offset_x (0x009DEA52) +* @param bound_box_offset_y (0x009DEA54) +* @param bound_box_offset_z (0x009DEA56) +* @param rotation (ebp) +* @return (ebp) paint_struct on success (CF == 0), nullptr on failure (CF == 1) +*/ +paint_struct * sub_98199C( + paint_session * session, + uint32 image_id, + sint8 x_offset, sint8 y_offset, + sint16 bound_box_length_x, sint16 bound_box_length_y, sint8 bound_box_length_z, + sint16 z_offset, + sint16 bound_box_offset_x, sint16 bound_box_offset_y, sint16 bound_box_offset_z, + uint32 rotation) +{ + assert((uint16)bound_box_length_x == (sint16)bound_box_length_x); + assert((uint16)bound_box_length_y == (sint16)bound_box_length_y); + + if (session->UnkF1AD28 == nullptr) + { + return sub_98197C(session, + image_id, + x_offset, y_offset, + bound_box_length_x, bound_box_length_y, bound_box_length_z, + z_offset, + bound_box_offset_x, bound_box_offset_y, bound_box_offset_z, + rotation + ); + } + + LocationXYZ16 offset = { x_offset, y_offset, z_offset }; + LocationXYZ16 boundBox = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; + LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; + paint_struct * ps = sub_9819_c(session, image_id, offset, boundBox, boundBoxOffset, rotation); + + if (ps == nullptr) + { + return nullptr; + } + + paint_struct *old_ps = session->UnkF1AD28; + old_ps->var_20 = ps; + + session->UnkF1AD28 = ps; + session->NextFreePaintStruct++; + return ps; +} + +/** +* rct2: 0x006881D0 +* +* @param image_id (ebx) +* @param x (ax) +* @param y (cx) +* @return (!CF) success +*/ +bool paint_attach_to_previous_attach(paint_session * session, uint32 image_id, uint16 x, uint16 y) +{ + if (session->UnkF1AD2C == nullptr) + { + return paint_attach_to_previous_ps(session, image_id, x, y); + } + + if (session->NextFreePaintStruct >= session->EndOfPaintStructArray) + { + return false; + } + attached_paint_struct * ps = &session->NextFreePaintStruct->attached; + ps->image_id = image_id; + ps->x = x; + ps->y = y; + ps->flags = 0; + + attached_paint_struct * ebx = session->UnkF1AD2C; + + ps->next = nullptr; + ebx->next = ps; + + session->UnkF1AD2C = ps; + + session->NextFreePaintStruct++; + + return true; +} + +/** +* rct2: 0x0068818E +* +* @param image_id (ebx) +* @param x (ax) +* @param y (cx) +* @return (!CF) success +*/ +bool paint_attach_to_previous_ps(paint_session * session, uint32 image_id, uint16 x, uint16 y) +{ + if (session->NextFreePaintStruct >= session->EndOfPaintStructArray) + { + return false; + } + attached_paint_struct * ps = &session->NextFreePaintStruct->attached; + + ps->image_id = image_id; + ps->x = x; + ps->y = y; + ps->flags = 0; + + paint_struct * masterPs = session->UnkF1AD28; + if (masterPs == nullptr) + { + return false; + } + + session->NextFreePaintStruct++; + + attached_paint_struct * oldFirstAttached = masterPs->attached_ps; + masterPs->attached_ps = ps; + + ps->next = oldFirstAttached; + + session->UnkF1AD2C = ps; + + return true; +} + +/** +* rct2: 0x00685EBC, 0x00686046, 0x00685FC8, 0x00685F4A, 0x00685ECC +* @param amount (eax) +* @param string_id (bx) +* @param y (cx) +* @param z (dx) +* @param offset_x (si) +* @param y_offsets (di) +* @param rotation (ebp) +*/ +void paint_floating_money_effect(paint_session * session, money32 amount, rct_string_id string_id, sint16 y, sint16 z, sint8 y_offsets[], sint16 offset_x, uint32 rotation) +{ + if (session->NextFreePaintStruct >= session->EndOfPaintStructArray) + { + return; + } + + paint_string_struct * ps = &session->NextFreePaintStruct->string; + ps->string_id = string_id; + ps->next = nullptr; + ps->args[0] = amount; + ps->args[1] = y; + ps->args[2] = 0; + ps->args[3] = 0; + ps->y_offsets = (uint8 *)y_offsets; + + const LocationXYZ16 position = + { + session->SpritePosition.x, + session->SpritePosition.y, + z + }; + const LocationXY16 coord = coordinate_3d_to_2d(&position, rotation); + + ps->x = coord.x + offset_x; + ps->y = coord.y; + + session->NextFreePaintStruct++; + + if (session->LastPSString == nullptr) + { + session->PSStringHead = ps; + } + else + { + session->LastPSString->next = ps; + } + session->LastPSString = ps; +} + +/** +* +* rct2: 0x006860C3 +*/ +void paint_draw_money_structs(rct_drawpixelinfo * dpi, paint_string_struct * ps) +{ + rct_drawpixelinfo dpi2 = *dpi; + draw_pixel_info_crop_by_zoom(&dpi2); + + do + { + utf8 buffer[256]; + format_string(buffer, 256, ps->string_id, &ps->args); + gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM; + + // Use sprite font unless the currency contains characters unsupported by the sprite font + bool forceSpriteFont = false; + const currency_descriptor& currencyDesc = CurrencyDescriptors[gConfigGeneral.currency_format]; + if (gUseTrueTypeFont && font_supports_string_sprite(currencyDesc.symbol_unicode)) + { + forceSpriteFont = true; + } + + gfx_draw_string_with_y_offsets(&dpi2, buffer, COLOUR_BLACK, ps->x, ps->y, (sint8 *)ps->y_offsets, forceSpriteFont); + } while ((ps = ps->next) != nullptr); +} \ No newline at end of file diff --git a/src/openrct2/paint/Paint.h b/src/openrct2/paint/Paint.h index 11f3a586da..7a65b721e1 100644 --- a/src/openrct2/paint/Paint.h +++ b/src/openrct2/paint/Paint.h @@ -173,10 +173,6 @@ typedef struct paint_session extern paint_session gPaintSession; -#ifdef __cplusplus -extern "C" { -#endif - // Global for paint clipping height. extern uint8 gClipHeight; @@ -221,7 +217,3 @@ void paint_draw_money_structs(rct_drawpixelinfo * dpi, paint_string_struct * ps) #define TESTPAINT_IGNORE(direction, trackSequence) #define TESTPAINT_IGNORE_ALL() #endif - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/paint/Supports.h b/src/openrct2/paint/Supports.h index 9336214a45..5457ca5db6 100644 --- a/src/openrct2/paint/Supports.h +++ b/src/openrct2/paint/Supports.h @@ -20,10 +20,6 @@ #include "../common.h" #include "../world/Footpath.h" -#ifdef __cplusplus -extern "C" { -#endif - bool wooden_a_supports_paint_setup(paint_session * session, sint32 supportType, sint32 special, sint32 height, uint32 imageColourFlags, bool* underground); bool wooden_b_supports_paint_setup(paint_session * session, sint32 supportType, sint32 special, sint32 height, uint32 imageColourFlags, bool* underground); bool metal_a_supports_paint_setup(paint_session * session, uint8 supportType, uint8 segment, sint32 special, sint32 height, uint32 imageColourFlags); @@ -48,8 +44,4 @@ enum { METAL_SUPPORTS_BOXED_COATED // Does not seem to be used in RCT2, but it was used in RCT1 for one of the path support types. }; -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/paint/sprite/Sprite.h b/src/openrct2/paint/sprite/Sprite.h index 2952e4a346..1b2b0b88df 100644 --- a/src/openrct2/paint/sprite/Sprite.h +++ b/src/openrct2/paint/sprite/Sprite.h @@ -20,21 +20,14 @@ #include "../../common.h" #include "../../world/Sprite.h" -#ifdef __cplusplus -extern "C" { -#endif +typedef struct paint_session paint_session; - typedef struct paint_session paint_session; +void sprite_paint_setup(paint_session * session, const uint16 eax, const uint16 ecx); - void sprite_paint_setup(paint_session * session, const uint16 eax, const uint16 ecx); +void misc_paint(paint_session * session, rct_sprite *misc, sint32 imageDirection); +void litter_paint(paint_session * session, rct_litter *litter, sint32 imageDirection); +void peep_paint(paint_session * session, rct_peep *peep, sint32 imageDirection); - void misc_paint(paint_session * session, rct_sprite *misc, sint32 imageDirection); - void litter_paint(paint_session * session, rct_litter *litter, sint32 imageDirection); - void peep_paint(paint_session * session, rct_peep *peep, sint32 imageDirection); - - extern const uint32 vehicle_particle_base_sprites[5]; -#ifdef __cplusplus -} -#endif +extern const uint32 vehicle_particle_base_sprites[5]; #endif diff --git a/src/openrct2/paint/tile_element/TileElement.h b/src/openrct2/paint/tile_element/TileElement.h index 3c2da871ec..a6c480df3f 100644 --- a/src/openrct2/paint/tile_element/TileElement.h +++ b/src/openrct2/paint/tile_element/TileElement.h @@ -73,10 +73,6 @@ enum G141E9DB_FLAG_2 = 2, }; -#ifdef __cplusplus -extern "C" { -#endif - #ifdef __TESTPAINT__ extern uint16 testPaintVerticalTunnelHeight; #endif @@ -110,8 +106,4 @@ void fence_paint(paint_session * session, uint8 direction, sint32 height, rct_ti void large_scenery_paint(paint_session * session, uint8 direction, uint16 height, rct_tile_element *tileElement); void track_paint(paint_session * session, uint8 direction, sint32 height, rct_tile_element *tileElement); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 4cbdd75b50..fbad0c190d 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -720,10 +720,6 @@ enum FOR_ALL_PEEPS(sprite_index, peep) \ if ((peep)->type == PEEP_TYPE_STAFF) -#ifdef __cplusplus -extern "C" { -#endif - // rct2: 0x00982708 extern rct_peep_animation_entry g_peep_animation_entries[PEEP_SPRITE_TYPE_COUNT]; @@ -824,8 +820,4 @@ void increment_guests_heading_for_park(); void decrement_guests_in_park(); void decrement_guests_heading_for_park(); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/peep/Staff.h b/src/openrct2/peep/Staff.h index 0428092c4c..f80fdf185d 100644 --- a/src/openrct2/peep/Staff.h +++ b/src/openrct2/peep/Staff.h @@ -69,10 +69,6 @@ enum ENTERTAINER_COSTUME ENTERTAINER_COSTUME_COUNT }; -#ifdef __cplusplus -extern "C" { -#endif - extern const rct_string_id StaffCostumeNames[ENTERTAINER_COSTUME_COUNT]; extern uint32 gStaffPatrolAreas[(STAFF_MAX_COUNT + STAFF_TYPE_COUNT) * STAFF_PATROL_AREA_SIZE]; @@ -117,8 +113,4 @@ bool staff_set_colour(uint8 staffType, colour_t value); uint32 staff_get_available_entertainer_costumes(); sint32 staff_get_available_entertainer_costume_list(uint8 * costumeList); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/platform/Crash.cpp b/src/openrct2/platform/Crash.cpp index e29429d1ca..0e78cbcf78 100644 --- a/src/openrct2/platform/Crash.cpp +++ b/src/openrct2/platform/Crash.cpp @@ -28,16 +28,12 @@ #error Breakpad support not implemented yet for this platform #endif -extern "C" -{ - #include "../localisation/Language.h" - #include "../scenario/Scenario.h" - #include "platform.h" -} - #include "../core/Console.hpp" +#include "../localisation/Language.h" #include "../rct2/S6Exporter.h" +#include "../scenario/Scenario.h" #include "../Version.h" +#include "platform.h" #define WSZ(x) L"" x @@ -162,7 +158,7 @@ constexpr const wchar_t * PipeName = L"openrct2-bpad"; #endif // USE_BREAKPAD -extern "C" CExceptionHandler crash_init() +CExceptionHandler crash_init() { #ifdef USE_BREAKPAD // Path must exist and be RW! diff --git a/src/openrct2/platform/Crash.h b/src/openrct2/platform/Crash.h index 890da227d6..8dbfab917a 100644 --- a/src/openrct2/platform/Crash.h +++ b/src/openrct2/platform/Crash.h @@ -19,14 +19,7 @@ typedef void * CExceptionHandler; -#ifdef __cplusplus -extern "C" -{ -#endif - extern bool gOpenRCT2SilentBreakpad; - CExceptionHandler crash_init(); -#ifdef __cplusplus -} -#endif +extern bool gOpenRCT2SilentBreakpad; +CExceptionHandler crash_init(); #endif /* _OPENRCT2_CRASH_ */ diff --git a/src/openrct2/platform/Posix.cpp b/src/openrct2/platform/Posix.cpp index ace051e46b..8ff9cf8fc5 100644 --- a/src/openrct2/platform/Posix.cpp +++ b/src/openrct2/platform/Posix.cpp @@ -44,9 +44,6 @@ #define FILE_BUFFER_SIZE 4096 -extern "C" -{ - static utf8 _userDataDirectoryPath[MAX_PATH] = { 0 }; void platform_get_date_utc(rct2_date *out_date) @@ -465,6 +462,4 @@ bool platform_process_is_elevated() #endif // __EMSCRIPTEN__ } -} // extern "C" - #endif diff --git a/src/openrct2/platform/Shared.cpp b/src/openrct2/platform/Shared.cpp index 9bab992046..279011d0f9 100644 --- a/src/openrct2/platform/Shared.cpp +++ b/src/openrct2/platform/Shared.cpp @@ -45,9 +45,6 @@ #endif #endif -extern "C" -{ - #if defined(__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200) static mach_timebase_info_data_t _mach_base_info = { 0 }; #endif @@ -237,5 +234,3 @@ void core_init() #endif } } - -} diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp index 68f790f798..4c894de051 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -50,9 +50,6 @@ // The name of the mutex used to prevent multiple instances of the game from running #define SINGLE_INSTANCE_MUTEX_NAME "RollerCoaster Tycoon 2_GSKMUTEX" -extern "C" -{ - #define OPENRCT2_DLL_MODULE_NAME "openrct2.dll" static HMODULE _dllModule = nullptr; @@ -734,6 +731,4 @@ bool platform_setup_uri_protocol() } /////////////////////////////////////////////////////////////////////////////// - -} #endif diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index 53e7ebf163..43d506c63e 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -80,11 +80,6 @@ typedef struct file_dialog_desc { } filters[8]; } file_dialog_desc; - -#ifdef __cplusplus -extern "C" { -#endif - // Platform shared definitions void platform_update_palette(const uint8 *colours, sint32 start_index, sint32 num_colours); void platform_toggle_windowed_mode(); @@ -165,8 +160,4 @@ void core_init(); utf8* macos_str_decomp_to_precomp(utf8 *input); #endif -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/rct1/RCT1.h b/src/openrct2/rct1/RCT1.h index 924bc4266f..cb5ed6cb7f 100644 --- a/src/openrct2/rct1/RCT1.h +++ b/src/openrct2/rct1/RCT1.h @@ -1223,15 +1223,7 @@ enum { RCT1_WATER_ORANGE }; -#ifdef __cplusplus -extern "C" { -#endif - ParkLoadResult * load_from_sv4(const char *path); ParkLoadResult * load_from_sc4(const char *path); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 84fb3c0d57..ae032d207e 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2828,48 +2828,43 @@ IParkImporter * ParkImporter::CreateS4() return new S4Importer(); } -///////////////////////////////////////// -// C -> C++ transfer -///////////////////////////////////////// -extern "C" +ParkLoadResult * load_from_sv4(const utf8 * path) { - ParkLoadResult * load_from_sv4(const utf8 * path) + ParkLoadResult * result = nullptr; + auto s4Importer = std::make_unique(); + try { - ParkLoadResult * result = nullptr; - auto s4Importer = std::make_unique(); - try + result = new ParkLoadResult(s4Importer->LoadSavedGame(path)); + if (result->Error == PARK_LOAD_ERROR_OK) { - result = new ParkLoadResult(s4Importer->LoadSavedGame(path)); - if (result->Error == PARK_LOAD_ERROR_OK) - { - s4Importer->Import(); - } + s4Importer->Import(); } - catch (const std::exception &) - { - delete result; - result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); - } - return result; } - - ParkLoadResult * load_from_sc4(const utf8 * path) + catch (const std::exception &) { - ParkLoadResult * result = nullptr; - auto s4Importer = std::make_unique(); - try - { - result = new ParkLoadResult(s4Importer->LoadScenario(path)); - if (result->Error == PARK_LOAD_ERROR_OK) - { - s4Importer->Import(); - } - } - catch (const std::exception &) - { - delete result; - result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); - } - return result; + delete result; + result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); } + return result; } + +ParkLoadResult * load_from_sc4(const utf8 * path) +{ + ParkLoadResult * result = nullptr; + auto s4Importer = std::make_unique(); + try + { + result = new ParkLoadResult(s4Importer->LoadScenario(path)); + if (result->Error == PARK_LOAD_ERROR_OK) + { + s4Importer->Import(); + } + } + catch (const std::exception &) + { + delete result; + result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); + } + return result; +} + diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index b4836a5ddd..fa7aaf2be2 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -714,70 +714,68 @@ void S6Exporter::ExportResearchList() memcpy(_s6.research_items, gResearchItems, sizeof(_s6.research_items)); } -extern "C" -{ - enum { - S6_SAVE_FLAG_EXPORT = 1 << 0, - S6_SAVE_FLAG_SCENARIO = 1 << 1, - S6_SAVE_FLAG_AUTOMATIC = 1u << 31, - }; +enum { + S6_SAVE_FLAG_EXPORT = 1 << 0, + S6_SAVE_FLAG_SCENARIO = 1 << 1, + S6_SAVE_FLAG_AUTOMATIC = 1u << 31, +}; - /** - * - * rct2: 0x006754F5 - * @param flags bit 0: pack objects, 1: save as scenario - */ - sint32 scenario_save(const utf8 * path, sint32 flags) +/** + * + * rct2: 0x006754F5 + * @param flags bit 0: pack objects, 1: save as scenario + */ +sint32 scenario_save(const utf8 * path, sint32 flags) +{ + if (flags & S6_SAVE_FLAG_SCENARIO) { + log_verbose("saving scenario"); + } + else + { + log_verbose("saving game"); + } + + if (!(flags & S6_SAVE_FLAG_AUTOMATIC)) + { + window_close_construction_windows(); + } + + map_reorganise_elements(); + viewport_set_saved_view(); + + bool result = false; + auto s6exporter = new S6Exporter(); + try + { + if (flags & S6_SAVE_FLAG_EXPORT) + { + IObjectManager * objManager = GetObjectManager(); + s6exporter->ExportObjectsList = objManager->GetPackableObjects(); + } + s6exporter->RemoveTracklessRides = true; + s6exporter->Export(); if (flags & S6_SAVE_FLAG_SCENARIO) { - log_verbose("saving scenario"); + s6exporter->SaveScenario(path); } else { - log_verbose("saving game"); + s6exporter->SaveGame(path); } - - if (!(flags & S6_SAVE_FLAG_AUTOMATIC)) - { - window_close_construction_windows(); - } - - map_reorganise_elements(); - viewport_set_saved_view(); - - bool result = false; - auto s6exporter = new S6Exporter(); - try - { - if (flags & S6_SAVE_FLAG_EXPORT) - { - IObjectManager * objManager = GetObjectManager(); - s6exporter->ExportObjectsList = objManager->GetPackableObjects(); - } - s6exporter->RemoveTracklessRides = true; - s6exporter->Export(); - if (flags & S6_SAVE_FLAG_SCENARIO) - { - s6exporter->SaveScenario(path); - } - else - { - s6exporter->SaveGame(path); - } - result = true; - } - catch (const std::exception &) - { - } - delete s6exporter; - - gfx_invalidate_screen(); - - if (result && !(flags & S6_SAVE_FLAG_AUTOMATIC)) - { - gScreenAge = 0; - } - return result; + result = true; } + catch (const std::exception &) + { + } + delete s6exporter; + + gfx_invalidate_screen(); + + if (result && !(flags & S6_SAVE_FLAG_AUTOMATIC)) + { + gScreenAge = 0; + } + return result; } + diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 7c043ef3c8..36425fb03a 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -810,101 +810,99 @@ IParkImporter * ParkImporter::CreateS6(IObjectRepository * objectRepository, IOb return new S6Importer(objectRepository, objectManager); } -extern "C" +ParkLoadResult * load_from_sv6(const char * path) { - ParkLoadResult * load_from_sv6(const char * path) + ParkLoadResult * result = nullptr; + auto s6Importer = new S6Importer(GetObjectRepository(), GetObjectManager()); + try { - ParkLoadResult * result = nullptr; - auto s6Importer = new S6Importer(GetObjectRepository(), GetObjectManager()); - try - { - result = new ParkLoadResult(s6Importer->LoadSavedGame(path)); + result = new ParkLoadResult(s6Importer->LoadSavedGame(path)); - // We mustn't import if there's something - // wrong with the park data - if (result->Error == PARK_LOAD_ERROR_OK) - { - s6Importer->Import(); - - game_fix_save_vars(); - sprite_position_tween_reset(); - } - } - catch (const ObjectLoadException &) - { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; - } - catch (const IOException &) - { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_GAME_SAVE_FAILED; - } - catch (const std::exception &) - { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; - } - delete s6Importer; - - if (result == nullptr) - { - result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); - } + // We mustn't import if there's something + // wrong with the park data if (result->Error == PARK_LOAD_ERROR_OK) { - gScreenAge = 0; - gLastAutoSaveUpdate = AUTOSAVE_PAUSE; - } - return result; - } + s6Importer->Import(); - /** - * - * rct2: 0x00676053 - * scenario (ebx) - */ - ParkLoadResult * load_from_sc6(const char * path) + game_fix_save_vars(); + sprite_position_tween_reset(); + } + } + catch (const ObjectLoadException &) { - ParkLoadResult * result = nullptr; - auto s6Importer = new S6Importer(GetObjectRepository(), GetObjectManager()); - try - { - result = new ParkLoadResult(s6Importer->LoadScenario(path)); - if (result->Error == PARK_LOAD_ERROR_OK) - { - s6Importer->Import(); - - game_fix_save_vars(); - sprite_position_tween_reset(); - } - } - catch (const ObjectLoadException &) - { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_GAME_SAVE_FAILED; - } - catch (const IOException &) - { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_GAME_SAVE_FAILED; - } - catch (const std::exception &) - { - gErrorType = ERROR_TYPE_FILE_LOAD; - gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; - } - delete s6Importer; - - if (result == nullptr) - { - result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); - } - if (result->Error != PARK_LOAD_ERROR_OK) - { - gScreenAge = 0; - gLastAutoSaveUpdate = AUTOSAVE_PAUSE; - } - return result; + gErrorType = ERROR_TYPE_FILE_LOAD; + gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; } + catch (const IOException &) + { + gErrorType = ERROR_TYPE_FILE_LOAD; + gErrorStringId = STR_GAME_SAVE_FAILED; + } + catch (const std::exception &) + { + gErrorType = ERROR_TYPE_FILE_LOAD; + gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; + } + delete s6Importer; + + if (result == nullptr) + { + result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); + } + if (result->Error == PARK_LOAD_ERROR_OK) + { + gScreenAge = 0; + gLastAutoSaveUpdate = AUTOSAVE_PAUSE; + } + return result; } + +/** + * + * rct2: 0x00676053 + * scenario (ebx) + */ +ParkLoadResult * load_from_sc6(const char * path) +{ + ParkLoadResult * result = nullptr; + auto s6Importer = new S6Importer(GetObjectRepository(), GetObjectManager()); + try + { + result = new ParkLoadResult(s6Importer->LoadScenario(path)); + if (result->Error == PARK_LOAD_ERROR_OK) + { + s6Importer->Import(); + + game_fix_save_vars(); + sprite_position_tween_reset(); + } + } + catch (const ObjectLoadException &) + { + gErrorType = ERROR_TYPE_FILE_LOAD; + gErrorStringId = STR_GAME_SAVE_FAILED; + } + catch (const IOException &) + { + gErrorType = ERROR_TYPE_FILE_LOAD; + gErrorStringId = STR_GAME_SAVE_FAILED; + } + catch (const std::exception &) + { + gErrorType = ERROR_TYPE_FILE_LOAD; + gErrorStringId = STR_FILE_CONTAINS_INVALID_DATA; + } + delete s6Importer; + + if (result == nullptr) + { + result = new ParkLoadResult(ParkLoadResult::CreateUnknown()); + } + if (result->Error != PARK_LOAD_ERROR_OK) + { + gScreenAge = 0; + gLastAutoSaveUpdate = AUTOSAVE_PAUSE; + } + return result; +} + diff --git a/src/openrct2/ride/CableLift.h b/src/openrct2/ride/CableLift.h index 350067acfd..3a8672efda 100644 --- a/src/openrct2/ride/CableLift.h +++ b/src/openrct2/ride/CableLift.h @@ -20,16 +20,8 @@ #include "../common.h" #include "Vehicle.h" -#ifdef __cplusplus -extern "C" { -#endif - rct_vehicle *cable_lift_segment_create(sint32 rideIndex, sint32 x, sint32 y, sint32 z, sint32 direction, uint16 var_44, sint32 remaining_distance, bool head); void cable_lift_update(rct_vehicle *vehicle); sint32 cable_lift_update_track_motion(rct_vehicle *cableLift); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index cad43a4586..8d1151ee58 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -937,10 +937,6 @@ typedef struct rct_ride_properties { #define CONSTRUCTION_LIFT_HILL_SELECTED 1 -#ifdef __cplusplus -extern "C" { -#endif - extern const rct_ride_properties RideProperties[RIDE_TYPE_COUNT]; /** Helper macros until rides are stored in this module. */ @@ -1213,8 +1209,4 @@ LocationXY16 ride_get_rotated_coords(sint16 x, sint16 y, sint16 z); void fix_ride_entrance_and_exit_locations(); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/ride/RideData.h b/src/openrct2/ride/RideData.h index 08856c793b..a0706f19f2 100644 --- a/src/openrct2/ride/RideData.h +++ b/src/openrct2/ride/RideData.h @@ -134,10 +134,6 @@ typedef struct rct_shop_item_stats { uint16 cold_value; } rct_shop_item_stats; -#ifdef __cplusplus -extern "C" { -#endif - extern const bool hasRunningTrack[RIDE_TYPE_COUNT]; extern const uint8 initialUpkeepCosts[RIDE_TYPE_COUNT]; extern const uint8 costPerTrackPiece[RIDE_TYPE_COUNT]; @@ -181,8 +177,4 @@ extern const track_colour_preset_list RideColourPresets[RIDE_TYPE_COUNT]; extern const rct_string_id RideModeNames[RIDE_MODE_COUNT]; -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/ride/RideGroupManager.h b/src/openrct2/ride/RideGroupManager.h index cf34ffb982..025fe62646 100644 --- a/src/openrct2/ride/RideGroupManager.h +++ b/src/openrct2/ride/RideGroupManager.h @@ -19,14 +19,9 @@ #ifdef __cplusplus #include -extern "C" -{ -#endif - #include "../common.h" - #include "RideData.h" -#ifdef __cplusplus -} #endif +#include "../common.h" +#include "RideData.h" #define MAX_RIDE_GROUPS_PER_RIDE_TYPE 2 diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 477eed658c..439df69cd4 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -29,9 +29,6 @@ #include "Station.h" #include "Track.h" -extern "C" -{ - enum { RIDE_RATINGS_STATE_FIND_NEXT_RIDE, RIDE_RATINGS_STATE_INITIALISE, @@ -4362,5 +4359,3 @@ static ride_ratings_calculation ride_ratings_get_calculate_func(uint8 rideType) } #pragma endregion - -} diff --git a/src/openrct2/ride/RideRatings.h b/src/openrct2/ride/RideRatings.h index 900324b2d8..3056e41cd9 100644 --- a/src/openrct2/ride/RideRatings.h +++ b/src/openrct2/ride/RideRatings.h @@ -59,15 +59,8 @@ typedef struct rct_ride_rating_calc_data { uint16 station_flags; } rct_ride_rating_calc_data; -#ifdef __cplusplus -extern "C" { -#endif - extern rct_ride_rating_calc_data gRideRatingsCalcData; void ride_ratings_update_ride(int rideIndex); void ride_ratings_update_all(); -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/ride/Station.h b/src/openrct2/ride/Station.h index 9088d96d67..b7cc5f7daf 100644 --- a/src/openrct2/ride/Station.h +++ b/src/openrct2/ride/Station.h @@ -20,15 +20,8 @@ #include "../world/Map.h" #include "Ride.h" -#ifdef __cplusplus -extern "C" { -#endif - void ride_update_station(Ride * ride, sint32 stationIndex); sint8 ride_get_first_valid_station_exit(Ride * ride); sint8 ride_get_first_valid_station_start(const Ride * ride); sint8 ride_get_first_empty_station_start(const Ride * ride); -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/ride/Track.h b/src/openrct2/ride/Track.h index 5df17d8a1f..8a698edd4e 100644 --- a/src/openrct2/ride/Track.h +++ b/src/openrct2/ride/Track.h @@ -519,10 +519,6 @@ typedef struct track_circuit_iterator bool looped; } track_circuit_iterator; -#ifdef __cplusplus -extern "C" { -#endif - extern const rct_trackdefinition FlatRideTrackDefinitions[256]; extern const rct_trackdefinition TrackDefinitions[256]; @@ -582,7 +578,3 @@ uint8 track_element_get_ride_index(const rct_tile_element * tileElement); void track_element_set_ride_index(rct_tile_element * tileElement, uint8 rideIndex); uint8 track_element_get_type(const rct_tile_element * tileElement); void track_element_set_type(rct_tile_element * tileElement, uint8 rideIndex); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/ride/TrackData.h b/src/openrct2/ride/TrackData.h index ea45fdcbc0..08db35eac5 100644 --- a/src/openrct2/ride/TrackData.h +++ b/src/openrct2/ride/TrackData.h @@ -20,10 +20,6 @@ #include "Track.h" #include "TrackPaint.h" -#ifdef __cplusplus -extern "C" { -#endif - // 0x009968BB, 0x009968BC, 0x009968BD, 0x009968BF, 0x009968C1, 0x009968C3 extern const rct_track_coordinates TrackCoordinates[256]; // 0x009972BB, 0x009972BC, 0x009972BD, 0x009972BF, 0x009972C1, 0x009972C3 @@ -96,6 +92,3 @@ extern const uint8 FlatRideTrackSequenceElementAllowedWallEdges[256][16]; extern const uint16 FlatTrackFlags[256]; extern const uint16 TrackFlags[256]; -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/ride/TrackDesign.h b/src/openrct2/ride/TrackDesign.h index 5b18b9a920..58ee88ea45 100644 --- a/src/openrct2/ride/TrackDesign.h +++ b/src/openrct2/ride/TrackDesign.h @@ -197,10 +197,6 @@ enum { MAZE_ELEMENT_TYPE_EXIT = (1 << 7) }; -#ifdef __cplusplus -extern "C" { -#endif - extern rct_track_td6 *gActiveTrackDesign; extern bool gTrackDesignSceneryToggle; extern LocationXYZ16 gTrackPreviewMin; @@ -240,8 +236,4 @@ bool track_design_save_to_file(const utf8 *path); bool track_design_are_entrance_and_exit_placed(); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/ride/TrackDesignRepository.cpp b/src/openrct2/ride/TrackDesignRepository.cpp index 1b6b1d42d1..41b58c27b9 100644 --- a/src/openrct2/ride/TrackDesignRepository.cpp +++ b/src/openrct2/ride/TrackDesignRepository.cpp @@ -408,31 +408,29 @@ ITrackDesignRepository * GetTrackDesignRepository() return _trackDesignRepository; } -extern "C" +void track_repository_scan() { - void track_repository_scan() - { - ITrackDesignRepository * repo = GetTrackDesignRepository(); - repo->Scan(); - } - - bool track_repository_delete(const utf8 * path) - { - ITrackDesignRepository * repo = GetTrackDesignRepository(); - return repo->Delete(path); - } - - bool track_repository_rename(const utf8 * path, const utf8 * newName) - { - ITrackDesignRepository * repo = GetTrackDesignRepository(); - std::string newPath = repo->Rename(path, newName); - return !newPath.empty(); - } - - bool track_repository_install(const utf8 * srcPath) - { - ITrackDesignRepository * repo = GetTrackDesignRepository(); - std::string newPath = repo->Install(srcPath); - return !newPath.empty(); - } + ITrackDesignRepository * repo = GetTrackDesignRepository(); + repo->Scan(); } + +bool track_repository_delete(const utf8 * path) +{ + ITrackDesignRepository * repo = GetTrackDesignRepository(); + return repo->Delete(path); +} + +bool track_repository_rename(const utf8 * path, const utf8 * newName) +{ + ITrackDesignRepository * repo = GetTrackDesignRepository(); + std::string newPath = repo->Rename(path, newName); + return !newPath.empty(); +} + +bool track_repository_install(const utf8 * srcPath) +{ + ITrackDesignRepository * repo = GetTrackDesignRepository(); + std::string newPath = repo->Install(srcPath); + return !newPath.empty(); +} + diff --git a/src/openrct2/ride/TrackDesignRepository.h b/src/openrct2/ride/TrackDesignRepository.h index 88a109e234..81b8321261 100644 --- a/src/openrct2/ride/TrackDesignRepository.h +++ b/src/openrct2/ride/TrackDesignRepository.h @@ -59,14 +59,8 @@ std::string GetNameFromTrackPath(const std::string &path); #endif -#ifdef __cplusplus -extern "C" -{ -#endif - void track_repository_scan(); - bool track_repository_delete(const utf8 *path); - bool track_repository_rename(const utf8 *path, const utf8 *newName); - bool track_repository_install(const utf8 *srcPath); -#ifdef __cplusplus -} -#endif +void track_repository_scan(); +bool track_repository_delete(const utf8 *path); +bool track_repository_rename(const utf8 *path, const utf8 *newName); +bool track_repository_install(const utf8 *srcPath); + diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index 9a09ef9034..098f42ba16 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -40,9 +40,6 @@ #define TRACK_NEARBY_SCENERY_DISTANCE 1 #define TRACK_TD6_MAX_ELEMENTS 8192 -extern "C" -{ - bool gTrackDesignSaveMode = false; uint8 gTrackDesignSaveRideIndex = 255; @@ -1247,5 +1244,3 @@ bool track_design_save_to_file(const utf8 *path) free(td6Buffer.ptr); return result; } - -} diff --git a/src/openrct2/ride/TrackPaint.h b/src/openrct2/ride/TrackPaint.h index 321fb63f04..b7d0eae5b4 100644 --- a/src/openrct2/ride/TrackPaint.h +++ b/src/openrct2/ride/TrackPaint.h @@ -23,10 +23,6 @@ #include "../paint/Paint.h" #include "../world/Map.h" -#ifdef __cplusplus -extern "C" { -#endif - extern const uint8 track_map_2x2[][4]; extern const uint8 edges_2x2[]; @@ -408,8 +404,4 @@ TRACK_PAINT_FUNCTION get_track_paint_function_mini_rc(sint32 trackType, sint32 d TRACK_PAINT_FUNCTION get_track_paint_function_mine_ride(sint32 trackType, sint32 direction); TRACK_PAINT_FUNCTION get_track_paint_function_lim_launched_rc(sint32 trackType, sint32 direction); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index 90f67a33b8..e4a679e304 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -385,10 +385,6 @@ enum { #define VEHICLE_SEAT_PAIR_FLAG 0x80 #define VEHICLE_SEAT_NUM_MASK 0x7F -#ifdef __cplusplus -extern "C" { -#endif - rct_vehicle * try_get_vehicle(uint16 spriteIndex); void vehicle_update_all(); void vehicle_sounds_update(); @@ -420,10 +416,6 @@ extern uint8 _vehicleF64E2C; extern rct_vehicle * _vehicleFrontVehicle; extern LocationXYZ16 unk_F64E20; -#ifdef __cplusplus -} -#endif - /** Helper macro until rides are stored in this module. */ #define GET_VEHICLE(sprite_index) &(get_sprite(sprite_index)->vehicle) diff --git a/src/openrct2/ride/VehicleData.h b/src/openrct2/ride/VehicleData.h index 0000dbde44..c2df8208c6 100644 --- a/src/openrct2/ride/VehicleData.h +++ b/src/openrct2/ride/VehicleData.h @@ -19,10 +19,6 @@ #include "../common.h" -#ifdef __cplusplus -extern "C" { -#endif - extern const uint8 * Rotation1TimeToSpriteMaps[]; extern const uint8 * Rotation2TimeToSpriteMaps[]; extern const uint8 * Rotation3TimeToSpriteMaps[]; @@ -42,8 +38,4 @@ extern const sint32 dword_9A2970[]; extern const sint32 SpriteDirectionToSoundDirection[]; -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/ride/VehiclePaint.h b/src/openrct2/ride/VehiclePaint.h index 8abd4c3656..474176f919 100644 --- a/src/openrct2/ride/VehiclePaint.h +++ b/src/openrct2/ride/VehiclePaint.h @@ -19,10 +19,6 @@ #include "Vehicle.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct vehicle_boundbox { sint8 offset_x; sint8 offset_y; @@ -49,8 +45,4 @@ void vehicle_visual_submarine(paint_session * session, sint32 x, sint32 imageDir void vehicle_visual_mini_golf_player(paint_session * session, sint32 x, sint32 imageDirection, sint32 y, sint32 z, rct_vehicle *vehicle); void vehicle_visual_mini_golf_ball(paint_session * session, sint32 x, sint32 imageDirection, sint32 y, sint32 z, rct_vehicle *vehicle); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index ebea74a2cd..c5ca968336 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -51,9 +51,6 @@ #include "../ride/Track.h" #include "../windows/Intent.h" -extern "C" -{ - const rct_string_id ScenarioCategoryStringIds[SCENARIO_CATEGORY_COUNT] = { STR_BEGINNER_PARKS, STR_CHALLENGING_PARKS, @@ -970,4 +967,3 @@ static void scenario_objective_check() } } -} diff --git a/src/openrct2/scenario/Scenario.h b/src/openrct2/scenario/Scenario.h index 1d34230656..3975ed880a 100644 --- a/src/openrct2/scenario/Scenario.h +++ b/src/openrct2/scenario/Scenario.h @@ -360,10 +360,6 @@ enum { #define AUTOSAVE_PAUSE 0 -#ifdef __cplusplus -extern "C" { -#endif - extern const rct_string_id ScenarioCategoryStringIds[SCENARIO_CATEGORY_COUNT]; extern uint32 gScenarioTicks; @@ -415,8 +411,4 @@ void scenario_success(); void scenario_success_submit_name(const char *name); void scenario_autosave_check(); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/scenario/ScenarioRepository.cpp b/src/openrct2/scenario/ScenarioRepository.cpp index 06cc3d4461..b686794c41 100644 --- a/src/openrct2/scenario/ScenarioRepository.cpp +++ b/src/openrct2/scenario/ScenarioRepository.cpp @@ -739,29 +739,27 @@ IScenarioRepository * GetScenarioRepository() return _scenarioRepository; } -extern "C" +void scenario_repository_scan() { - void scenario_repository_scan() - { - IScenarioRepository * repo = GetScenarioRepository(); - repo->Scan(); - } - - size_t scenario_repository_get_count() - { - IScenarioRepository * repo = GetScenarioRepository(); - return repo->GetCount(); - } - - const scenario_index_entry *scenario_repository_get_by_index(size_t index) - { - IScenarioRepository * repo = GetScenarioRepository(); - return repo->GetByIndex(index); - } - - bool scenario_repository_try_record_highscore(const utf8 * scenarioFileName, money32 companyValue, const utf8 * name) - { - IScenarioRepository * repo = GetScenarioRepository(); - return repo->TryRecordHighscore(scenarioFileName, companyValue, name); - } + IScenarioRepository * repo = GetScenarioRepository(); + repo->Scan(); } + +size_t scenario_repository_get_count() +{ + IScenarioRepository * repo = GetScenarioRepository(); + return repo->GetCount(); +} + +const scenario_index_entry *scenario_repository_get_by_index(size_t index) +{ + IScenarioRepository * repo = GetScenarioRepository(); + return repo->GetByIndex(index); +} + +bool scenario_repository_try_record_highscore(const utf8 * scenarioFileName, money32 companyValue, const utf8 * name) +{ + IScenarioRepository * repo = GetScenarioRepository(); + return repo->TryRecordHighscore(scenarioFileName, companyValue, name); +} + diff --git a/src/openrct2/scenario/ScenarioRepository.h b/src/openrct2/scenario/ScenarioRepository.h index eb844a62b4..2e0c000d7e 100644 --- a/src/openrct2/scenario/ScenarioRepository.h +++ b/src/openrct2/scenario/ScenarioRepository.h @@ -84,17 +84,9 @@ IScenarioRepository * GetScenarioRepository(); #endif -#ifdef __cplusplus -extern "C" -{ -#endif +void scenario_repository_scan(); +size_t scenario_repository_get_count(); +const scenario_index_entry *scenario_repository_get_by_index(size_t index); +bool scenario_repository_try_record_highscore(const utf8 * scenarioFileName, money32 companyValue, const utf8 * name); +void scenario_translate(scenario_index_entry * scenarioEntry, const struct rct_object_entry * stexObjectEntry); - void scenario_repository_scan(); - size_t scenario_repository_get_count(); - const scenario_index_entry *scenario_repository_get_by_index(size_t index); - bool scenario_repository_try_record_highscore(const utf8 * scenarioFileName, money32 companyValue, const utf8 * name); - void scenario_translate(scenario_index_entry * scenarioEntry, const struct rct_object_entry * stexObjectEntry); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/scenario/ScenarioSources.cpp b/src/openrct2/scenario/ScenarioSources.cpp index d6c80d8717..ffb87f846a 100644 --- a/src/openrct2/scenario/ScenarioSources.cpp +++ b/src/openrct2/scenario/ScenarioSources.cpp @@ -358,20 +358,18 @@ namespace ScenarioSources } } -extern "C" +bool scenario_get_source_desc(const utf8 * name, source_desc * outDesc) { - bool scenario_get_source_desc(const utf8 * name, source_desc * outDesc) - { - return ScenarioSources::TryGetByName(name, outDesc); - } - - bool scenario_get_source_desc_by_id(uint8 id, source_desc * outDesc) - { - return ScenarioSources::TryGetById(id, outDesc); - } - - void scenario_normalise_name(utf8 * buffer, size_t bufferSize, utf8 * name) - { - ScenarioSources::NormaliseName(buffer, bufferSize, name); - } + return ScenarioSources::TryGetByName(name, outDesc); } + +bool scenario_get_source_desc_by_id(uint8 id, source_desc * outDesc) +{ + return ScenarioSources::TryGetById(id, outDesc); +} + +void scenario_normalise_name(utf8 * buffer, size_t bufferSize, utf8 * name) +{ + ScenarioSources::NormaliseName(buffer, bufferSize, name); +} + diff --git a/src/openrct2/scenario/ScenarioSources.h b/src/openrct2/scenario/ScenarioSources.h index be920b0ef8..e20533531f 100644 --- a/src/openrct2/scenario/ScenarioSources.h +++ b/src/openrct2/scenario/ScenarioSources.h @@ -38,18 +38,10 @@ namespace ScenarioSources #endif -#ifdef __cplusplus -extern "C" -{ -#endif +bool scenario_get_source_desc(const utf8 *name, source_desc *outDesc); +bool scenario_get_source_desc_by_id(uint8 id, source_desc *outDesc); +void scenario_normalise_name(utf8 *buffer, size_t bufferSize, utf8 *name); - bool scenario_get_source_desc(const utf8 *name, source_desc *outDesc); - bool scenario_get_source_desc_by_id(uint8 id, source_desc *outDesc); - void scenario_normalise_name(utf8 *buffer, size_t bufferSize, utf8 *name); - -#ifdef __cplusplus -} -#endif // RCT1 scenario index map enum diff --git a/src/openrct2/title/TitleScreen.cpp b/src/openrct2/title/TitleScreen.cpp index 1c322a4dd7..6aed4dabe3 100644 --- a/src/openrct2/title/TitleScreen.cpp +++ b/src/openrct2/title/TitleScreen.cpp @@ -279,121 +279,119 @@ bool TitleScreen::TryLoadSequence(bool loadPreview) return true; } -extern "C" +void title_load() { - void title_load() + if (_singleton != nullptr) { - if (_singleton != nullptr) - { - _singleton->Load(); - } - } - - void title_create_windows() - { - if (_singleton != nullptr) - { - _singleton->CreateWindows(); - } - } - - void * title_get_sequence_player() - { - void * result = nullptr; - if (_singleton != nullptr) - { - result = _singleton->GetSequencePlayer(); - } - return result; - } - - void title_sequence_change_preset(size_t preset) - { - if (_singleton != nullptr) - { - _singleton->ChangePresetSequence(preset); - } - } - - bool title_should_hide_version_info() - { - bool result = false; - if (_singleton != nullptr) - { - result = _singleton->ShouldHideVersionInfo(); - } - return result; - } - - void title_set_hide_version_info(bool value) - { - if (_singleton != nullptr) - { - _singleton->SetHideVersionInfo(value); - } - } - - size_t title_get_config_sequence() - { - return title_sequence_manager_get_index_for_config_id(gConfigInterface.current_title_sequence_preset); - } - - size_t title_get_current_sequence() - { - size_t result = 0; - if (_singleton != nullptr) - { - result = _singleton->GetCurrentSequence(); - } - return result; - } - - bool title_preview_sequence(size_t value) - { - if (_singleton != nullptr) - { - return _singleton->PreviewSequence(value); - } - return false; - } - - void title_stop_previewing_sequence() - { - if (_singleton != nullptr) - { - _singleton->StopPreviewingSequence(); - } - } - - bool title_is_previewing_sequence() - { - if (_singleton != nullptr) - { - return _singleton->IsPreviewingSequence(); - } - return false; - } - - void DrawOpenRCT2(rct_drawpixelinfo * dpi, sint32 x, sint32 y) - { - utf8 buffer[256]; - - // Write format codes - utf8 * ch = buffer; - ch = utf8_write_codepoint(ch, FORMAT_MEDIUMFONT); - ch = utf8_write_codepoint(ch, FORMAT_OUTLINE); - ch = utf8_write_codepoint(ch, FORMAT_WHITE); - - // Write name and version information - openrct2_write_full_version_info(ch, sizeof(buffer) - (ch - buffer)); - gfx_draw_string(dpi, buffer, COLOUR_BLACK, x + 5, y + 5 - 13); - - // Invalidate screen area - sint16 width = (sint16)gfx_get_string_width(buffer); - gfx_set_dirty_blocks(x, y, x + width, y + 30); // 30 is an arbitrary height to catch both strings - - // Write platform information - snprintf(ch, 256 - (ch - buffer), "%s (%s)", OPENRCT2_PLATFORM, OPENRCT2_ARCHITECTURE); - gfx_draw_string(dpi, buffer, COLOUR_BLACK, x + 5, y + 5); + _singleton->Load(); } } + +void title_create_windows() +{ + if (_singleton != nullptr) + { + _singleton->CreateWindows(); + } +} + +void * title_get_sequence_player() +{ + void * result = nullptr; + if (_singleton != nullptr) + { + result = _singleton->GetSequencePlayer(); + } + return result; +} + +void title_sequence_change_preset(size_t preset) +{ + if (_singleton != nullptr) + { + _singleton->ChangePresetSequence(preset); + } +} + +bool title_should_hide_version_info() +{ + bool result = false; + if (_singleton != nullptr) + { + result = _singleton->ShouldHideVersionInfo(); + } + return result; +} + +void title_set_hide_version_info(bool value) +{ + if (_singleton != nullptr) + { + _singleton->SetHideVersionInfo(value); + } +} + +size_t title_get_config_sequence() +{ + return title_sequence_manager_get_index_for_config_id(gConfigInterface.current_title_sequence_preset); +} + +size_t title_get_current_sequence() +{ + size_t result = 0; + if (_singleton != nullptr) + { + result = _singleton->GetCurrentSequence(); + } + return result; +} + +bool title_preview_sequence(size_t value) +{ + if (_singleton != nullptr) + { + return _singleton->PreviewSequence(value); + } + return false; +} + +void title_stop_previewing_sequence() +{ + if (_singleton != nullptr) + { + _singleton->StopPreviewingSequence(); + } +} + +bool title_is_previewing_sequence() +{ + if (_singleton != nullptr) + { + return _singleton->IsPreviewingSequence(); + } + return false; +} + +void DrawOpenRCT2(rct_drawpixelinfo * dpi, sint32 x, sint32 y) +{ + utf8 buffer[256]; + + // Write format codes + utf8 * ch = buffer; + ch = utf8_write_codepoint(ch, FORMAT_MEDIUMFONT); + ch = utf8_write_codepoint(ch, FORMAT_OUTLINE); + ch = utf8_write_codepoint(ch, FORMAT_WHITE); + + // Write name and version information + openrct2_write_full_version_info(ch, sizeof(buffer) - (ch - buffer)); + gfx_draw_string(dpi, buffer, COLOUR_BLACK, x + 5, y + 5 - 13); + + // Invalidate screen area + sint16 width = (sint16)gfx_get_string_width(buffer); + gfx_set_dirty_blocks(x, y, x + width, y + 30); // 30 is an arbitrary height to catch both strings + + // Write platform information + snprintf(ch, 256 - (ch - buffer), "%s (%s)", OPENRCT2_PLATFORM, OPENRCT2_ARCHITECTURE); + gfx_draw_string(dpi, buffer, COLOUR_BLACK, x + 5, y + 5); +} + diff --git a/src/openrct2/title/TitleScreen.h b/src/openrct2/title/TitleScreen.h index e9f2c5278f..c43a3f1876 100644 --- a/src/openrct2/title/TitleScreen.h +++ b/src/openrct2/title/TitleScreen.h @@ -54,22 +54,16 @@ private: }; #endif -#ifdef __cplusplus -extern "C" -{ -#endif - void title_load(); - void title_create_windows(); - void * title_get_sequence_player(); - void title_sequence_change_preset(size_t preset); - bool title_should_hide_version_info(); - void title_set_hide_version_info(bool value); - size_t title_get_config_sequence(); - size_t title_get_current_sequence(); - bool title_preview_sequence(size_t value); - void title_stop_previewing_sequence(); - bool title_is_previewing_sequence(); - void DrawOpenRCT2(rct_drawpixelinfo * dpi, sint32 x, sint32 y); -#ifdef __cplusplus -} -#endif +void title_load(); +void title_create_windows(); +void * title_get_sequence_player(); +void title_sequence_change_preset(size_t preset); +bool title_should_hide_version_info(); +void title_set_hide_version_info(bool value); +size_t title_get_config_sequence(); +size_t title_get_current_sequence(); +bool title_preview_sequence(size_t value); +void title_stop_previewing_sequence(); +bool title_is_previewing_sequence(); +void DrawOpenRCT2(rct_drawpixelinfo * dpi, sint32 x, sint32 y); + diff --git a/src/openrct2/title/TitleSequence.cpp b/src/openrct2/title/TitleSequence.cpp index d804ab48da..cba8cafa99 100644 --- a/src/openrct2/title/TitleSequence.cpp +++ b/src/openrct2/title/TitleSequence.cpp @@ -42,333 +42,330 @@ static void LegacyScriptGetLine(IStream * stream, char * parts); static void * ReadScriptFile(const utf8 * path, size_t * outSize); static utf8 * LegacyScriptWrite(TitleSequence * seq); -extern "C" +TitleSequence * CreateTitleSequence() { - TitleSequence * CreateTitleSequence() + TitleSequence * seq = Memory::Allocate(); + *seq = { 0 }; + return seq; +} + +TitleSequence * LoadTitleSequence(const utf8 * path) +{ + size_t scriptLength; + utf8 * script; + std::vector saves; + bool isZip; + + log_verbose("Loading title sequence: %s", path); + + const utf8 * ext = Path::GetExtension(path); + if (String::Equals(ext, TITLE_SEQUENCE_EXTENSION)) { - TitleSequence * seq = Memory::Allocate(); - *seq = { 0 }; - return seq; - } - - TitleSequence * LoadTitleSequence(const utf8 * path) - { - size_t scriptLength; - utf8 * script; - std::vector saves; - bool isZip; - - log_verbose("Loading title sequence: %s", path); - - const utf8 * ext = Path::GetExtension(path); - if (String::Equals(ext, TITLE_SEQUENCE_EXTENSION)) + IZipArchive * zip = Zip::TryOpen(path, ZIP_ACCESS_READ); + if (zip == nullptr) { - IZipArchive * zip = Zip::TryOpen(path, ZIP_ACCESS_READ); - if (zip == nullptr) - { - Console::Error::WriteLine("Unable to open '%s'", path); - return nullptr; - } - - script = (utf8 *)zip->GetFileData("script.txt", &scriptLength); - if (script == nullptr) - { - Console::Error::WriteLine("Unable to open script.txt in '%s'", path); - delete zip; - return nullptr; - } - - saves = GetSaves(zip); - isZip = true; + Console::Error::WriteLine("Unable to open '%s'", path); + return nullptr; + } + script = (utf8 *)zip->GetFileData("script.txt", &scriptLength); + if (script == nullptr) + { + Console::Error::WriteLine("Unable to open script.txt in '%s'", path); delete zip; + return nullptr; } - else + + saves = GetSaves(zip); + isZip = true; + + delete zip; + } + else + { + utf8 scriptPath[MAX_PATH]; + String::Set(scriptPath, sizeof(scriptPath), path); + Path::Append(scriptPath, sizeof(scriptPath), "script.txt"); + script = (utf8 *)ReadScriptFile(scriptPath, &scriptLength); + if (script == nullptr) { - utf8 scriptPath[MAX_PATH]; - String::Set(scriptPath, sizeof(scriptPath), path); - Path::Append(scriptPath, sizeof(scriptPath), "script.txt"); - script = (utf8 *)ReadScriptFile(scriptPath, &scriptLength); - if (script == nullptr) - { - Console::Error::WriteLine("Unable to open '%s'", scriptPath); - return nullptr; - } - - saves = GetSaves(path); - isZip = false; + Console::Error::WriteLine("Unable to open '%s'", scriptPath); + return nullptr; } - std::vector commands = LegacyScriptRead(script, scriptLength, saves); - Memory::Free(script); - - TitleSequence * seq = CreateTitleSequence(); - seq->Name = Path::GetFileNameWithoutExtension(path); - seq->Path = String::Duplicate(path); - seq->NumSaves = saves.size(); - seq->Saves = Collections::ToArray(saves); - seq->NumCommands = commands.size(); - seq->Commands = Collections::ToArray(commands); - seq->IsZip = isZip; - return seq; + saves = GetSaves(path); + isZip = false; } - void FreeTitleSequence(TitleSequence * seq) + std::vector commands = LegacyScriptRead(script, scriptLength, saves); + Memory::Free(script); + + TitleSequence * seq = CreateTitleSequence(); + seq->Name = Path::GetFileNameWithoutExtension(path); + seq->Path = String::Duplicate(path); + seq->NumSaves = saves.size(); + seq->Saves = Collections::ToArray(saves); + seq->NumCommands = commands.size(); + seq->Commands = Collections::ToArray(commands); + seq->IsZip = isZip; + return seq; +} + +void FreeTitleSequence(TitleSequence * seq) +{ + if (seq != nullptr) { - if (seq != nullptr) - { - Memory::Free(seq->Name); - Memory::Free(seq->Path); - Memory::Free(seq->Commands); - for (size_t i = 0; i < seq->NumSaves; i++) - { - Memory::Free(seq->Saves[i]); - } - Memory::Free(seq->Saves); - Memory::Free(seq); - } - } - - TitleSequenceParkHandle * TitleSequenceGetParkHandle(TitleSequence * seq, size_t index) - { - TitleSequenceParkHandle * handle = nullptr; - if (index <= seq->NumSaves) - { - const utf8 * filename = seq->Saves[index]; - if (seq->IsZip) - { - IZipArchive * zip = Zip::TryOpen(seq->Path, ZIP_ACCESS_READ); - if (zip != nullptr) - { - handle = Memory::Allocate(); - handle->Stream = zip->GetFileStream(filename); - handle->HintPath = String::Duplicate(filename); - delete zip; - } else { - Console::Error::WriteLine("Failed to open zipped path '%s' from zip '%s'", filename, seq->Path); - } - } - else - { - utf8 absolutePath[MAX_PATH]; - String::Set(absolutePath, sizeof(absolutePath), seq->Path); - Path::Append(absolutePath, sizeof(absolutePath), filename); - - FileStream* fileStream = nullptr; - try - { - fileStream = new FileStream(absolutePath, FILE_MODE_OPEN); - } - catch (const IOException& exception) - { - Console::Error::WriteLine(exception.what()); - } - - if (fileStream != nullptr) - { - handle = Memory::Allocate(); - handle->Stream = fileStream; - handle->HintPath = String::Duplicate(filename); - } - } - } - return handle; - } - - void TitleSequenceCloseParkHandle(TitleSequenceParkHandle * handle) - { - if (handle != nullptr) - { - Memory::Free(handle->HintPath); - delete ((IStream *)handle->Stream); - Memory::Free(handle); - } - } - - bool TitleSequenceSave(TitleSequence * seq) - { - bool success = false; - utf8 * script = LegacyScriptWrite(seq); - if (seq->IsZip) - { - IZipArchive * zip = Zip::TryOpen(seq->Path, ZIP_ACCESS_WRITE); - zip->SetFileData("script.txt", script, String::SizeOf(script)); - delete zip; - success = true; - } - else - { - utf8 scriptPath[MAX_PATH]; - String::Set(scriptPath, sizeof(scriptPath), seq->Path); - Path::Append(scriptPath, sizeof(scriptPath), "script.txt"); - - try - { - auto fs = FileStream(scriptPath, FILE_MODE_WRITE); - fs.Write(script, String::SizeOf(script)); - success = true; - } - catch (const std::exception &) - { - } - } - - Memory::Free(script); - return success; - } - - bool TitleSequenceAddPark(TitleSequence * seq, const utf8 * path, const utf8 * name) - { - // Get new save index - size_t index = SIZE_MAX; + Memory::Free(seq->Name); + Memory::Free(seq->Path); + Memory::Free(seq->Commands); for (size_t i = 0; i < seq->NumSaves; i++) { - if (String::Equals(seq->Saves[i], path, true)) - { - index = i; - break; - } + Memory::Free(seq->Saves[i]); } - if (index == SIZE_MAX) - { - seq->Saves = Memory::ReallocateArray(seq->Saves, seq->NumSaves + 1); - Guard::Assert(seq->Saves != nullptr, GUARD_LINE); - index = seq->NumSaves; - seq->NumSaves++; - } - seq->Saves[index] = String::Duplicate(name); + Memory::Free(seq->Saves); + Memory::Free(seq); + } +} +TitleSequenceParkHandle * TitleSequenceGetParkHandle(TitleSequence * seq, size_t index) +{ + TitleSequenceParkHandle * handle = nullptr; + if (index <= seq->NumSaves) + { + const utf8 * filename = seq->Saves[index]; if (seq->IsZip) { - try + IZipArchive * zip = Zip::TryOpen(seq->Path, ZIP_ACCESS_READ); + if (zip != nullptr) { - size_t fsize; - void * fdata = File::ReadAllBytes(path, &fsize); - - IZipArchive * zip = Zip::TryOpen(seq->Path, ZIP_ACCESS_WRITE); - if (zip == nullptr) - { - Console::Error::WriteLine("Unable to open '%s'", seq->Path); - return false; - } - zip->SetFileData(name, fdata, fsize); + handle = Memory::Allocate(); + handle->Stream = zip->GetFileStream(filename); + handle->HintPath = String::Duplicate(filename); delete zip; - Memory::Free(fdata); + } else { + Console::Error::WriteLine("Failed to open zipped path '%s' from zip '%s'", filename, seq->Path); } - catch (const std::exception &ex) - { - Console::Error::WriteLine(ex.what()); - } - } - else - { - // Determine destination path - utf8 dstPath[MAX_PATH]; - String::Set(dstPath, sizeof(dstPath), seq->Path); - Path::Append(dstPath, sizeof(dstPath), name); - if (!File::Copy(path, dstPath, true)) - { - Console::Error::WriteLine("Unable to copy '%s' to '%s'", path, dstPath); - return false; - } - } - return true; - } - - bool TitleSequenceRenamePark(TitleSequence * seq, size_t index, const utf8 * name) - { - Guard::Assert(index < seq->NumSaves, GUARD_LINE); - - utf8 * oldRelativePath = seq->Saves[index]; - if (seq->IsZip) - { - IZipArchive * zip = Zip::TryOpen(seq->Path, ZIP_ACCESS_WRITE); - if (zip == nullptr) - { - Console::Error::WriteLine("Unable to open '%s'", seq->Path); - return false; - } - zip->RenameFile(oldRelativePath, name); - delete zip; - } - else - { - utf8 srcPath[MAX_PATH]; - utf8 dstPath[MAX_PATH]; - String::Set(srcPath, sizeof(srcPath), seq->Path); - Path::Append(srcPath, sizeof(srcPath), oldRelativePath); - String::Set(dstPath, sizeof(dstPath), seq->Path); - Path::Append(dstPath, sizeof(dstPath), name); - if (!File::Move(srcPath, dstPath)) - { - Console::Error::WriteLine("Unable to move '%s' to '%s'", srcPath, dstPath); - return false; - } - } - - Memory::Free(seq->Saves[index]); - seq->Saves[index] = String::Duplicate(name); - return true; - } - - bool TitleSequenceRemovePark(TitleSequence * seq, size_t index) - { - Guard::Assert(index < seq->NumSaves, GUARD_LINE); - - // Delete park file - utf8 * relativePath = seq->Saves[index]; - if (seq->IsZip) - { - IZipArchive * zip = Zip::TryOpen(seq->Path, ZIP_ACCESS_WRITE); - if (zip == nullptr) - { - Console::Error::WriteLine("Unable to open '%s'", seq->Path); - return false; - } - zip->DeleteFile(relativePath); - delete zip; } else { utf8 absolutePath[MAX_PATH]; String::Set(absolutePath, sizeof(absolutePath), seq->Path); - Path::Append(absolutePath, sizeof(absolutePath), relativePath); - if (!File::Delete(absolutePath)) + Path::Append(absolutePath, sizeof(absolutePath), filename); + + FileStream* fileStream = nullptr; + try { - Console::Error::WriteLine("Unable to delete '%s'", absolutePath); + fileStream = new FileStream(absolutePath, FILE_MODE_OPEN); + } + catch (const IOException& exception) + { + Console::Error::WriteLine(exception.what()); + } + + if (fileStream != nullptr) + { + handle = Memory::Allocate(); + handle->Stream = fileStream; + handle->HintPath = String::Duplicate(filename); + } + } + } + return handle; +} + +void TitleSequenceCloseParkHandle(TitleSequenceParkHandle * handle) +{ + if (handle != nullptr) + { + Memory::Free(handle->HintPath); + delete ((IStream *)handle->Stream); + Memory::Free(handle); + } +} + +bool TitleSequenceSave(TitleSequence * seq) +{ + bool success = false; + utf8 * script = LegacyScriptWrite(seq); + if (seq->IsZip) + { + IZipArchive * zip = Zip::TryOpen(seq->Path, ZIP_ACCESS_WRITE); + zip->SetFileData("script.txt", script, String::SizeOf(script)); + delete zip; + success = true; + } + else + { + utf8 scriptPath[MAX_PATH]; + String::Set(scriptPath, sizeof(scriptPath), seq->Path); + Path::Append(scriptPath, sizeof(scriptPath), "script.txt"); + + try + { + auto fs = FileStream(scriptPath, FILE_MODE_WRITE); + fs.Write(script, String::SizeOf(script)); + success = true; + } + catch (const std::exception &) + { + } + } + + Memory::Free(script); + return success; +} + +bool TitleSequenceAddPark(TitleSequence * seq, const utf8 * path, const utf8 * name) +{ + // Get new save index + size_t index = SIZE_MAX; + for (size_t i = 0; i < seq->NumSaves; i++) + { + if (String::Equals(seq->Saves[i], path, true)) + { + index = i; + break; + } + } + if (index == SIZE_MAX) + { + seq->Saves = Memory::ReallocateArray(seq->Saves, seq->NumSaves + 1); + Guard::Assert(seq->Saves != nullptr, GUARD_LINE); + index = seq->NumSaves; + seq->NumSaves++; + } + seq->Saves[index] = String::Duplicate(name); + + if (seq->IsZip) + { + try + { + size_t fsize; + void * fdata = File::ReadAllBytes(path, &fsize); + + IZipArchive * zip = Zip::TryOpen(seq->Path, ZIP_ACCESS_WRITE); + if (zip == nullptr) + { + Console::Error::WriteLine("Unable to open '%s'", seq->Path); return false; } + zip->SetFileData(name, fdata, fsize); + delete zip; + Memory::Free(fdata); } - - // Remove from sequence - Memory::Free(relativePath); - for (size_t i = index; i < seq->NumSaves - 1; i++) + catch (const std::exception &ex) { - seq->Saves[i] = seq->Saves[i + 1]; + Console::Error::WriteLine(ex.what()); } - seq->NumSaves--; - - // Update load commands - for (size_t i = 0; i < seq->NumCommands; i++) + } + else + { + // Determine destination path + utf8 dstPath[MAX_PATH]; + String::Set(dstPath, sizeof(dstPath), seq->Path); + Path::Append(dstPath, sizeof(dstPath), name); + if (!File::Copy(path, dstPath, true)) { - TitleCommand * command = &seq->Commands[i]; - if (command->Type == TITLE_SCRIPT_LOAD) + Console::Error::WriteLine("Unable to copy '%s' to '%s'", path, dstPath); + return false; + } + } + return true; +} + +bool TitleSequenceRenamePark(TitleSequence * seq, size_t index, const utf8 * name) +{ + Guard::Assert(index < seq->NumSaves, GUARD_LINE); + + utf8 * oldRelativePath = seq->Saves[index]; + if (seq->IsZip) + { + IZipArchive * zip = Zip::TryOpen(seq->Path, ZIP_ACCESS_WRITE); + if (zip == nullptr) + { + Console::Error::WriteLine("Unable to open '%s'", seq->Path); + return false; + } + zip->RenameFile(oldRelativePath, name); + delete zip; + } + else + { + utf8 srcPath[MAX_PATH]; + utf8 dstPath[MAX_PATH]; + String::Set(srcPath, sizeof(srcPath), seq->Path); + Path::Append(srcPath, sizeof(srcPath), oldRelativePath); + String::Set(dstPath, sizeof(dstPath), seq->Path); + Path::Append(dstPath, sizeof(dstPath), name); + if (!File::Move(srcPath, dstPath)) + { + Console::Error::WriteLine("Unable to move '%s' to '%s'", srcPath, dstPath); + return false; + } + } + + Memory::Free(seq->Saves[index]); + seq->Saves[index] = String::Duplicate(name); + return true; +} + +bool TitleSequenceRemovePark(TitleSequence * seq, size_t index) +{ + Guard::Assert(index < seq->NumSaves, GUARD_LINE); + + // Delete park file + utf8 * relativePath = seq->Saves[index]; + if (seq->IsZip) + { + IZipArchive * zip = Zip::TryOpen(seq->Path, ZIP_ACCESS_WRITE); + if (zip == nullptr) + { + Console::Error::WriteLine("Unable to open '%s'", seq->Path); + return false; + } + zip->DeleteFile(relativePath); + delete zip; + } + else + { + utf8 absolutePath[MAX_PATH]; + String::Set(absolutePath, sizeof(absolutePath), seq->Path); + Path::Append(absolutePath, sizeof(absolutePath), relativePath); + if (!File::Delete(absolutePath)) + { + Console::Error::WriteLine("Unable to delete '%s'", absolutePath); + return false; + } + } + + // Remove from sequence + Memory::Free(relativePath); + for (size_t i = index; i < seq->NumSaves - 1; i++) + { + seq->Saves[i] = seq->Saves[i + 1]; + } + seq->NumSaves--; + + // Update load commands + for (size_t i = 0; i < seq->NumCommands; i++) + { + TitleCommand * command = &seq->Commands[i]; + if (command->Type == TITLE_SCRIPT_LOAD) + { + if (command->SaveIndex == index) { - if (command->SaveIndex == index) - { - // Park no longer exists, so reset load command to invalid - command->SaveIndex = SAVE_INDEX_INVALID; - } - else if (command->SaveIndex > index) - { - // Park index will have shifted by -1 - command->SaveIndex--; - } + // Park no longer exists, so reset load command to invalid + command->SaveIndex = SAVE_INDEX_INVALID; + } + else if (command->SaveIndex > index) + { + // Park index will have shifted by -1 + command->SaveIndex--; } } - - return true; } + + return true; } static std::vector GetSaves(const utf8 * directory) diff --git a/src/openrct2/title/TitleSequence.h b/src/openrct2/title/TitleSequence.h index 9e6aad6d22..6dec9d3ef2 100644 --- a/src/openrct2/title/TitleSequence.h +++ b/src/openrct2/title/TitleSequence.h @@ -90,27 +90,21 @@ enum TITLE_SCRIPT #define SAVE_INDEX_INVALID UINT8_MAX #endif -#ifdef __cplusplus -extern "C" -{ -#endif - TitleSequence * CreateTitleSequence(); - TitleSequence * LoadTitleSequence(const utf8 * path); - void FreeTitleSequence(TitleSequence * seq); +TitleSequence * CreateTitleSequence(); +TitleSequence * LoadTitleSequence(const utf8 * path); +void FreeTitleSequence(TitleSequence * seq); - TitleSequenceParkHandle * TitleSequenceGetParkHandle(TitleSequence * seq, size_t index); +TitleSequenceParkHandle * TitleSequenceGetParkHandle(TitleSequence * seq, size_t index); - /** - * Close a title sequence park handle. - * The pointer to the handle is invalid after calling this function. - */ - void TitleSequenceCloseParkHandle(TitleSequenceParkHandle * handle); - bool TitleSequenceSave(TitleSequence * seq); - bool TitleSequenceAddPark(TitleSequence * seq, const utf8 * path, const utf8 * name); - bool TitleSequenceRenamePark(TitleSequence * seq, size_t index, const utf8 * name); - bool TitleSequenceRemovePark(TitleSequence * seq, size_t index); +/** + * Close a title sequence park handle. + * The pointer to the handle is invalid after calling this function. + */ +void TitleSequenceCloseParkHandle(TitleSequenceParkHandle * handle); +bool TitleSequenceSave(TitleSequence * seq); +bool TitleSequenceAddPark(TitleSequence * seq, const utf8 * path, const utf8 * name); +bool TitleSequenceRenamePark(TitleSequence * seq, size_t index, const utf8 * name); +bool TitleSequenceRemovePark(TitleSequence * seq, size_t index); + +bool TitleSequenceIsLoadCommand(const TitleCommand * command); - bool TitleSequenceIsLoadCommand(const TitleCommand * command); -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/title/TitleSequenceManager.cpp b/src/openrct2/title/TitleSequenceManager.cpp index 521edf89fe..9ca2beb36d 100644 --- a/src/openrct2/title/TitleSequenceManager.cpp +++ b/src/openrct2/title/TitleSequenceManager.cpp @@ -314,117 +314,114 @@ namespace TitleSequenceManager } } -extern "C" +size_t title_sequence_manager_get_count() { - size_t title_sequence_manager_get_count() - { - return TitleSequenceManager::GetCount(); - } - - const utf8 * title_sequence_manager_get_name(size_t index) - { - auto item = TitleSequenceManager::GetItem(index); - if (item == nullptr) - { - return nullptr; - } - const utf8 * name = item->Name.c_str(); - return name; - } - - const utf8 * title_sequence_manager_get_path(size_t index) - { - auto item = TitleSequenceManager::GetItem(index); - if (item == nullptr) { - return nullptr; - } - const utf8 * name = item->Path.c_str(); - return name; - } - - const utf8 * title_sequence_manager_get_config_id(size_t index) - { - auto item = TitleSequenceManager::GetItem(index); - if (item == nullptr) { - return nullptr; - } - const utf8 * name = item->Name.c_str(); - const utf8 * filename = Path::GetFileName(item->Path.c_str()); - for (const auto &pseq : TitleSequenceManager::PredefinedSequences) - { - if (String::Equals(filename, pseq.Filename, true)) - { - return pseq.ConfigId; - } - } - return name; - } - - size_t title_sequence_manager_get_predefined_index(size_t index) - { - auto item = TitleSequenceManager::GetItem(index); - if (item == nullptr) { - return 0; - } - size_t predefinedIndex = item->PredefinedIndex; - return predefinedIndex; - } - - size_t title_sequence_manager_get_index_for_config_id(const utf8 * configId) - { - size_t count = TitleSequenceManager::GetCount(); - for (size_t i = 0; i < count; i++) - { - const utf8 * cid = title_sequence_manager_get_config_id(i); - if (String::Equals(cid, configId)) - { - return i; - } - } - return SIZE_MAX; - } - - size_t title_sequence_manager_get_index_for_name(const utf8 * name) - { - size_t count = TitleSequenceManager::GetCount(); - for (size_t i = 0; i < count; i++) - { - const utf8 * tn = title_sequence_manager_get_name(i); - if (String::Equals(tn, name)) - { - return i; - } - } - return SIZE_MAX; - } - - bool title_sequence_manager_is_name_reserved(const utf8 * name) - { - return TitleSequenceManager::IsNameReserved(name); - } - - void title_sequence_manager_scan() - { - TitleSequenceManager::Scan(); - } - - void title_sequence_manager_delete(size_t i) - { - TitleSequenceManager::DeleteItem(i); - } - - size_t title_sequence_manager_rename(size_t i, const utf8 * name) - { - return TitleSequenceManager::RenameItem(i, name); - } - - size_t title_sequence_manager_duplicate(size_t i, const utf8 * name) - { - return TitleSequenceManager::DuplicateItem(i, name); - } - - size_t title_sequence_manager_create(const utf8 * name) - { - return TitleSequenceManager::CreateItem(name); - } + return TitleSequenceManager::GetCount(); +} + +const utf8 * title_sequence_manager_get_name(size_t index) +{ + auto item = TitleSequenceManager::GetItem(index); + if (item == nullptr) + { + return nullptr; + } + const utf8 * name = item->Name.c_str(); + return name; +} + +const utf8 * title_sequence_manager_get_path(size_t index) +{ + auto item = TitleSequenceManager::GetItem(index); + if (item == nullptr) { + return nullptr; + } + const utf8 * name = item->Path.c_str(); + return name; +} + +const utf8 * title_sequence_manager_get_config_id(size_t index) +{ + auto item = TitleSequenceManager::GetItem(index); + if (item == nullptr) { + return nullptr; + } + const utf8 * name = item->Name.c_str(); + const utf8 * filename = Path::GetFileName(item->Path.c_str()); + for (const auto &pseq : TitleSequenceManager::PredefinedSequences) + { + if (String::Equals(filename, pseq.Filename, true)) + { + return pseq.ConfigId; + } + } + return name; +} + +size_t title_sequence_manager_get_predefined_index(size_t index) +{ + auto item = TitleSequenceManager::GetItem(index); + if (item == nullptr) { + return 0; + } + size_t predefinedIndex = item->PredefinedIndex; + return predefinedIndex; +} + +size_t title_sequence_manager_get_index_for_config_id(const utf8 * configId) +{ + size_t count = TitleSequenceManager::GetCount(); + for (size_t i = 0; i < count; i++) + { + const utf8 * cid = title_sequence_manager_get_config_id(i); + if (String::Equals(cid, configId)) + { + return i; + } + } + return SIZE_MAX; +} + +size_t title_sequence_manager_get_index_for_name(const utf8 * name) +{ + size_t count = TitleSequenceManager::GetCount(); + for (size_t i = 0; i < count; i++) + { + const utf8 * tn = title_sequence_manager_get_name(i); + if (String::Equals(tn, name)) + { + return i; + } + } + return SIZE_MAX; +} + +bool title_sequence_manager_is_name_reserved(const utf8 * name) +{ + return TitleSequenceManager::IsNameReserved(name); +} + +void title_sequence_manager_scan() +{ + TitleSequenceManager::Scan(); +} + +void title_sequence_manager_delete(size_t i) +{ + TitleSequenceManager::DeleteItem(i); +} + +size_t title_sequence_manager_rename(size_t i, const utf8 * name) +{ + return TitleSequenceManager::RenameItem(i, name); +} + +size_t title_sequence_manager_duplicate(size_t i, const utf8 * name) +{ + return TitleSequenceManager::DuplicateItem(i, name); +} + +size_t title_sequence_manager_create(const utf8 * name) +{ + return TitleSequenceManager::CreateItem(name); } diff --git a/src/openrct2/title/TitleSequenceManager.h b/src/openrct2/title/TitleSequenceManager.h index 38cf4ea5d8..ebe5ee7c15 100644 --- a/src/openrct2/title/TitleSequenceManager.h +++ b/src/openrct2/title/TitleSequenceManager.h @@ -43,23 +43,19 @@ namespace TitleSequenceManager constexpr const size_t PREDEFINED_INDEX_CUSTOM = SIZE_MAX; -extern "C" { #endif - size_t title_sequence_manager_get_count(); - const utf8 * title_sequence_manager_get_name(size_t index); - const utf8 * title_sequence_manager_get_path(size_t index); - const utf8 * title_sequence_manager_get_config_id(size_t index); - size_t title_sequence_manager_get_predefined_index(size_t index); - size_t title_sequence_manager_get_index_for_config_id(const utf8 * configId); - size_t title_sequence_manager_get_index_for_name(const utf8 * name); - bool title_sequence_manager_is_name_reserved(const utf8 * name); - void title_sequence_manager_scan(); - void title_sequence_manager_delete(size_t i); - size_t title_sequence_manager_rename(size_t i, const utf8 * name); - size_t title_sequence_manager_duplicate(size_t i, const utf8 * name); - size_t title_sequence_manager_create(const utf8 * name); +size_t title_sequence_manager_get_count(); +const utf8 * title_sequence_manager_get_name(size_t index); +const utf8 * title_sequence_manager_get_path(size_t index); +const utf8 * title_sequence_manager_get_config_id(size_t index); +size_t title_sequence_manager_get_predefined_index(size_t index); +size_t title_sequence_manager_get_index_for_config_id(const utf8 * configId); +size_t title_sequence_manager_get_index_for_name(const utf8 * name); +bool title_sequence_manager_is_name_reserved(const utf8 * name); +void title_sequence_manager_scan(); +void title_sequence_manager_delete(size_t i); +size_t title_sequence_manager_rename(size_t i, const utf8 * name); +size_t title_sequence_manager_duplicate(size_t i, const utf8 * name); +size_t title_sequence_manager_create(const utf8 * name); -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/title/TitleSequencePlayer.cpp b/src/openrct2/title/TitleSequencePlayer.cpp index 550134c978..e92ffa1041 100644 --- a/src/openrct2/title/TitleSequencePlayer.cpp +++ b/src/openrct2/title/TitleSequencePlayer.cpp @@ -582,32 +582,30 @@ ITitleSequencePlayer * CreateTitleSequencePlayer(IScenarioRepository * scenarioR return new TitleSequencePlayer(scenarioRepository); } -extern "C" +bool gPreviewingTitleSequenceInGame = false; + +sint32 title_sequence_player_get_current_position(ITitleSequencePlayer * player) { - bool gPreviewingTitleSequenceInGame = false; - - sint32 title_sequence_player_get_current_position(ITitleSequencePlayer * player) - { - return player->GetCurrentPosition(); - } - - bool title_sequence_player_begin(ITitleSequencePlayer * player, uint32 titleSequenceId) - { - return player->Begin(titleSequenceId); - } - - void title_sequence_player_reset(ITitleSequencePlayer * player) - { - player->Reset(); - } - - bool title_sequence_player_update(ITitleSequencePlayer * player) - { - return player->Update(); - } - - void title_sequence_player_seek(ITitleSequencePlayer * player, uint32 position) - { - player->Seek(position); - } + return player->GetCurrentPosition(); } + +bool title_sequence_player_begin(ITitleSequencePlayer * player, uint32 titleSequenceId) +{ + return player->Begin(titleSequenceId); +} + +void title_sequence_player_reset(ITitleSequencePlayer * player) +{ + player->Reset(); +} + +bool title_sequence_player_update(ITitleSequencePlayer * player) +{ + return player->Update(); +} + +void title_sequence_player_seek(ITitleSequencePlayer * player, uint32 position) +{ + player->Seek(position); +} + diff --git a/src/openrct2/title/TitleSequencePlayer.h b/src/openrct2/title/TitleSequencePlayer.h index c5cf67b2c7..28564fb7ea 100644 --- a/src/openrct2/title/TitleSequencePlayer.h +++ b/src/openrct2/title/TitleSequencePlayer.h @@ -41,18 +41,11 @@ typedef struct ITitleSequencePlayer ITitleSequencePlayer; #endif -#ifdef __cplusplus -extern "C" -{ -#endif - // When testing title sequences within a normal game - extern bool gPreviewingTitleSequenceInGame; +// When testing title sequences within a normal game +extern bool gPreviewingTitleSequenceInGame; - sint32 title_sequence_player_get_current_position(ITitleSequencePlayer * player); - bool title_sequence_player_begin(ITitleSequencePlayer * player, uint32 titleSequenceId); - void title_sequence_player_reset(ITitleSequencePlayer * player); - bool title_sequence_player_update(ITitleSequencePlayer * player); - void title_sequence_player_seek(ITitleSequencePlayer * player, uint32 position); -#ifdef __cplusplus -} -#endif +sint32 title_sequence_player_get_current_position(ITitleSequencePlayer * player); +bool title_sequence_player_begin(ITitleSequencePlayer * player, uint32 titleSequenceId); +void title_sequence_player_reset(ITitleSequencePlayer * player); +bool title_sequence_player_update(ITitleSequencePlayer * player); +void title_sequence_player_seek(ITitleSequencePlayer * player, uint32 position); diff --git a/src/openrct2/util/SawyerCoding.h b/src/openrct2/util/SawyerCoding.h index 7a64baa9d4..7e230a83fa 100644 --- a/src/openrct2/util/SawyerCoding.h +++ b/src/openrct2/util/SawyerCoding.h @@ -47,10 +47,6 @@ enum { FILE_TYPE_SC4 = (2 << 2) }; -#ifdef __cplusplus -extern "C" { -#endif - extern bool gUseRLE; uint32 sawyercoding_calculate_checksum(const uint8* buffer, size_t length); @@ -65,8 +61,4 @@ sint32 sawyercoding_validate_track_checksum(const uint8* src, size_t length); sint32 sawyercoding_detect_file_type(const uint8 *src, size_t length); sint32 sawyercoding_detect_rct1_version(sint32 gameVersion); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index db84379abf..012be09025 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -20,10 +20,6 @@ #include #include "../common.h" -#ifdef __cplusplus -extern "C" { -#endif - sint32 squaredmetres_to_squaredfeet(sint32 squaredMetres); sint32 metres_to_feet(sint32 metres); sint32 mph_to_kmph(sint32 mph); @@ -78,8 +74,4 @@ uint8 soft_light(uint8 a, uint8 b); size_t strcatftime(char * buffer, size_t bufferSize, const char * format, const struct tm * tp); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/windows/Intent.cpp b/src/openrct2/windows/Intent.cpp index f43a5d07c4..9dc316016f 100644 --- a/src/openrct2/windows/Intent.cpp +++ b/src/openrct2/windows/Intent.cpp @@ -127,36 +127,35 @@ close_callback Intent::GetCloseCallbackExtra(uint32 key) const return data.closeCallbackVal; } -extern "C" { - Intent *intent_create(rct_windowclass clss) - { - return new Intent(clss); - } - - void intent_release(Intent *intent) - { - delete intent; - } - - void intent_set_sint(Intent * intent, uint32 key, sint32 value) - { - intent->putExtra(key, value); - } - - void intent_set_string(Intent *intent, uint32 key, utf8string value) - { - std::string str { value }; - intent->putExtra(key, str); - } - - void intent_set_pointer(Intent *intent, uint32 key, void *value) - { - intent->putExtra(key, value); - } - - void intent_set_uint(Intent *intent, uint32 key, uint32 value) - { - intent->putExtra(key, value); - } +Intent *intent_create(rct_windowclass clss) +{ + return new Intent(clss); } +void intent_release(Intent *intent) +{ + delete intent; +} + +void intent_set_sint(Intent * intent, uint32 key, sint32 value) +{ + intent->putExtra(key, value); +} + +void intent_set_string(Intent *intent, uint32 key, utf8string value) +{ + std::string str { value }; + intent->putExtra(key, str); +} + +void intent_set_pointer(Intent *intent, uint32 key, void *value) +{ + intent->putExtra(key, value); +} + +void intent_set_uint(Intent *intent, uint32 key, uint32 value) +{ + intent->putExtra(key, value); +} + + diff --git a/src/openrct2/windows/Intent.h b/src/openrct2/windows/Intent.h index 34f9ac235a..a1f60eea58 100644 --- a/src/openrct2/windows/Intent.h +++ b/src/openrct2/windows/Intent.h @@ -47,65 +47,57 @@ public: typedef struct Intent Intent; #endif +enum +{ + INTENT_EXTRA_GUEST_LIST_FILTER, + INTENT_EXTRA_RIDE_ID, + INTENT_EXTRA_PATH, + INTENT_EXTRA_PEEP, + INTENT_EXTRA_LOADSAVE_TYPE, + INTENT_EXTRA_CALLBACK, + INTENT_EXTRA_TRACK_DESIGN, + INTENT_EXTRA_RIDE_TYPE, + INTENT_EXTRA_RIDE_ENTRY_INDEX, + INTENT_EXTRA_TILE_ELEMENT, + INTENT_EXTRA_VEHICLE, + INTENT_EXTRA_MESSAGE, + INTENT_EXTRA_LIST, + INTENT_EXTRA_LIST_COUNT, + INTENT_EXTRA_PAGE, + INTENT_EXTRA_BANNER_INDEX, +}; -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus +enum { + INTENT_ACTION_MAP, + INTENT_ACTION_NEW_RIDE_OF_TYPE, + INTENT_ACTION_REFRESH_NEW_RIDES, + INTENT_ACTION_REFRESH_RIDE_LIST, + INTENT_ACTION_UPDATE_MAZE_CONSTRUCTION, + INTENT_ACTION_RIDE_CONSTRUCTION_UPDATE_PIECES, + INTENT_ACTION_RIDE_CONSTRUCTION_UPDATE_ACTIVE_ELEMENTS, + INTENT_ACTION_INIT_SCENERY, + INTENT_ACTION_SET_DEFAULT_SCENERY_CONFIG, + INTENT_ACTION_REFRESH_SCENERY, + INTENT_ACTION_INVALIDATE_TICKER_NEWS, + INTENT_ACTION_REFRESH_GUEST_LIST, + INTENT_ACTION_CLEAR_TILE_INSPECTOR_CLIPBOARD, + INTENT_ACTION_SET_TILE_INSPECTOR_PAGE, + INTENT_ACTION_SET_TILE_INSPECTOR_BUTTONS, + INTENT_ACTION_REFRESH_STAFF_LIST, + INTENT_ACTION_INVALIDATE_VEHICLE_WINDOW, + INTENT_ACTION_UPDATE_CLIMATE, + INTENT_ACTION_UPDATE_GUEST_COUNT, + INTENT_ACTION_UPDATE_PARK_RATING, + INTENT_ACTION_UPDATE_DATE, + INTENT_ACTION_UPDATE_CASH, + INTENT_ACTION_UPDATE_BANNER, +}; - enum - { - INTENT_EXTRA_GUEST_LIST_FILTER, - INTENT_EXTRA_RIDE_ID, - INTENT_EXTRA_PATH, - INTENT_EXTRA_PEEP, - INTENT_EXTRA_LOADSAVE_TYPE, - INTENT_EXTRA_CALLBACK, - INTENT_EXTRA_TRACK_DESIGN, - INTENT_EXTRA_RIDE_TYPE, - INTENT_EXTRA_RIDE_ENTRY_INDEX, - INTENT_EXTRA_TILE_ELEMENT, - INTENT_EXTRA_VEHICLE, - INTENT_EXTRA_MESSAGE, - INTENT_EXTRA_LIST, - INTENT_EXTRA_LIST_COUNT, - INTENT_EXTRA_PAGE, - INTENT_EXTRA_BANNER_INDEX, - }; - - enum { - INTENT_ACTION_MAP, - INTENT_ACTION_NEW_RIDE_OF_TYPE, - INTENT_ACTION_REFRESH_NEW_RIDES, - INTENT_ACTION_REFRESH_RIDE_LIST, - INTENT_ACTION_UPDATE_MAZE_CONSTRUCTION, - INTENT_ACTION_RIDE_CONSTRUCTION_UPDATE_PIECES, - INTENT_ACTION_RIDE_CONSTRUCTION_UPDATE_ACTIVE_ELEMENTS, - INTENT_ACTION_INIT_SCENERY, - INTENT_ACTION_SET_DEFAULT_SCENERY_CONFIG, - INTENT_ACTION_REFRESH_SCENERY, - INTENT_ACTION_INVALIDATE_TICKER_NEWS, - INTENT_ACTION_REFRESH_GUEST_LIST, - INTENT_ACTION_CLEAR_TILE_INSPECTOR_CLIPBOARD, - INTENT_ACTION_SET_TILE_INSPECTOR_PAGE, - INTENT_ACTION_SET_TILE_INSPECTOR_BUTTONS, - INTENT_ACTION_REFRESH_STAFF_LIST, - INTENT_ACTION_INVALIDATE_VEHICLE_WINDOW, - INTENT_ACTION_UPDATE_CLIMATE, - INTENT_ACTION_UPDATE_GUEST_COUNT, - INTENT_ACTION_UPDATE_PARK_RATING, - INTENT_ACTION_UPDATE_DATE, - INTENT_ACTION_UPDATE_CASH, - INTENT_ACTION_UPDATE_BANNER, - }; - - Intent *intent_create(rct_windowclass clss); - void intent_release(Intent * intent); - void intent_set_string(Intent *, uint32 key, utf8string value); - void intent_set_pointer(Intent *, uint32 key, void * value); - void intent_set_sint(Intent *, uint32 key, sint32 value); - void intent_set_uint(Intent *, uint32 key, uint32 value); -#ifdef __cplusplus -} -#endif // __cplusplus +Intent *intent_create(rct_windowclass clss); +void intent_release(Intent * intent); +void intent_set_string(Intent *, uint32 key, utf8string value); +void intent_set_pointer(Intent *, uint32 key, void * value); +void intent_set_sint(Intent *, uint32 key, sint32 value); +void intent_set_uint(Intent *, uint32 key, uint32 value); #endif // OPENRCT2_INTENT_H diff --git a/src/openrct2/windows/tile_inspector.h b/src/openrct2/windows/tile_inspector.h index a074f63f78..42a85b5b70 100644 --- a/src/openrct2/windows/tile_inspector.h +++ b/src/openrct2/windows/tile_inspector.h @@ -33,14 +33,6 @@ typedef enum tile_inspector_page TILE_INSPECTOR_PAGE_CORRUPT } tile_inspector_page; -#ifdef __cplusplus -extern "C" { -#endif - extern uint32 windowTileInspectorTileX; extern uint32 windowTileInspectorTileY; extern sint32 windowTileInspectorElementCount; - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/src/openrct2/world/Balloon.cpp b/src/openrct2/world/Balloon.cpp index 69deefb8e9..af1caaf43d 100644 --- a/src/openrct2/world/Balloon.cpp +++ b/src/openrct2/world/Balloon.cpp @@ -111,33 +111,31 @@ static money32 game_command_balloon_press(uint16 spriteIndex, uint8 flags) } } -extern "C" +void create_balloon(sint32 x, sint32 y, sint32 z, sint32 colour, bool isPopped) { - void create_balloon(sint32 x, sint32 y, sint32 z, sint32 colour, bool isPopped) + rct_sprite* sprite = create_sprite(2); + if (sprite != nullptr) { - rct_sprite* sprite = create_sprite(2); - if (sprite != nullptr) - { - sprite->balloon.sprite_width = 13; - sprite->balloon.sprite_height_negative = 22; - sprite->balloon.sprite_height_positive = 11; - sprite->balloon.sprite_identifier = SPRITE_IDENTIFIER_MISC; - sprite_move(x, y, z, sprite); - sprite->balloon.misc_identifier = SPRITE_MISC_BALLOON; - sprite->balloon.time_to_move = 0; - sprite->balloon.frame = 0; - sprite->balloon.colour = colour; - sprite->balloon.popped = (isPopped ? 1 : 0); - } - } - - void balloon_update(rct_balloon * balloon) - { - balloon->Update(); - } - - void game_command_balloon_press(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp) - { - *ebx = game_command_balloon_press(*eax & 0xFFFF, *ebx & 0xFF); + sprite->balloon.sprite_width = 13; + sprite->balloon.sprite_height_negative = 22; + sprite->balloon.sprite_height_positive = 11; + sprite->balloon.sprite_identifier = SPRITE_IDENTIFIER_MISC; + sprite_move(x, y, z, sprite); + sprite->balloon.misc_identifier = SPRITE_MISC_BALLOON; + sprite->balloon.time_to_move = 0; + sprite->balloon.frame = 0; + sprite->balloon.colour = colour; + sprite->balloon.popped = (isPopped ? 1 : 0); } } + +void balloon_update(rct_balloon * balloon) +{ + balloon->Update(); +} + +void game_command_balloon_press(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp) +{ + *ebx = game_command_balloon_press(*eax & 0xFFFF, *ebx & 0xFF); +} + diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index 00f1c61753..4dcebfa2de 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -426,198 +426,196 @@ static uint8 BannerGetNewIndex() { return BANNER_NULL; } -extern "C" +/** + * + * rct2: 0x006B9CB0 + */ +void banner_init() { - /** - * - * rct2: 0x006B9CB0 - */ - void banner_init() - { - for (auto &banner : gBanners) { - banner.type = BANNER_NULL; - } - } - - /** - * Creates a new banner and returns the index of the banner - * If the flag GAME_COMMAND_FLAG_APPLY is NOT set then returns - * the first unused index but does NOT mark the banner as created. - * returns 0xFF on failure. - * - * rct2: 0x006BA278 - */ - sint32 create_new_banner(uint8 flags) - { - uint8 bannerIndex = BannerGetNewIndex(); - - if (bannerIndex == BANNER_NULL) - { - gGameCommandErrorText = STR_TOO_MANY_BANNERS_IN_GAME; - return BANNER_NULL; - } - - if (flags & GAME_COMMAND_FLAG_APPLY) - { - rct_banner* banner = &gBanners[bannerIndex]; - - banner->flags = 0; - banner->type = 0; - banner->string_idx = STR_DEFAULT_SIGN; - banner->colour = 2; - banner->text_colour = 2; - } - return bannerIndex; - } - - rct_tile_element *banner_get_tile_element(sint32 bannerIndex) - { - rct_banner *banner = &gBanners[bannerIndex]; - rct_tile_element *tileElement = map_get_first_element_at(banner->x, banner->y); - do - { - if (tile_element_get_banner_index(tileElement) == bannerIndex) - { - return tileElement; - } - } while (!tile_element_is_last_for_tile(tileElement++)); - return nullptr; - } - - /** - * - * rct2: 0x006B7D86 - */ - sint32 banner_get_closest_ride_index(sint32 x, sint32 y, sint32 z) - { - sint32 i, rideIndex; - Ride *ride; - - static constexpr const LocationXY16 NeighbourCheckOrder[] = - { - { 32, 0 }, - { -32, 0 }, - { 0, 32 }, - { 0, -32 }, - { -32, +32 }, - { +32, -32 }, - { +32, +32 }, - { -32, +32 }, - { 0, 0 } - }; - - for (i = 0; i < (sint32)Util::CountOf(NeighbourCheckOrder); i++) - { - rideIndex = banner_get_ride_index_at(x + NeighbourCheckOrder[i].x, y + NeighbourCheckOrder[i].y, z); - if (rideIndex != -1) - { - return rideIndex; - } - } - - rideIndex = -1; - sint32 resultDistance = std::numeric_limits::max(); - FOR_ALL_RIDES(i, ride) - { - if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_IS_SHOP)) - continue; - - LocationXY8 location = ride->overall_view; - if (location.xy == RCT_XY8_UNDEFINED) - continue; - - sint32 rideX = location.x * 32; - sint32 rideY = location.y * 32; - sint32 distance = abs(x - rideX) + abs(y - rideY); - if (distance < resultDistance) - { - resultDistance = distance; - rideIndex = i; - } - } - - return rideIndex; - } - - void banner_reset_broken_index() - { - for (sint32 bannerIndex = 0; bannerIndex < MAX_BANNERS; bannerIndex++) - { - rct_tile_element *tileElement = banner_get_tile_element(bannerIndex); - if (tileElement == nullptr) - gBanners[bannerIndex].type = BANNER_NULL; - } - } - - /** - * - * rct2: 0x006BA058 - */ - void game_command_remove_banner(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) - { - *ebx = BannerRemove( - *eax & 0xFFFF, - *ecx & 0xFFFF, - *edx & 0xFF, - (*edx >> 8) & 0xFF, - *ebx & 0xFF - ); - } - - /** - * - * rct2: 0x006BA16A - */ - void game_command_set_banner_colour(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) - { - *ebx = BannerSetColour( - *eax & 0xFFFF, - *ecx & 0xFFFF, - *edx & 0xFF, - (*edx >> 8) & 0xFF, - *ebp & 0xFF, - *ebx & 0xFF - ); - } - - /** - * - * rct2: 0x006B9E6D - */ - void game_command_place_banner(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) - { - *ebx = BannerPlace( - *eax & 0xFFFF, - *ecx & 0xFFFF, - *edx & 0xFF, - (*edx >> 8) & 0xFF, - *ebp & 0xFF, - (*ebx >> 8) & 0xFF, - (uint8 *)edi, - *ebx & 0xFF - ); - } - - void game_command_set_banner_name(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) - { - *ebx = BannerSetName( - *ecx & 0xFF, - *eax & 0xFFFF, - *edx, - *ebp, - *edi, - *ebx & 0xFF - ); - } - - void game_command_set_banner_style(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) - { - *ebx = BannerSetStyle( - *ecx & 0xFF, - *edx & 0xFF, - *edi & 0xFF, - *ebp & 0xFF, - *ebx & 0xFF - ); + for (auto &banner : gBanners) { + banner.type = BANNER_NULL; } } + +/** + * Creates a new banner and returns the index of the banner + * If the flag GAME_COMMAND_FLAG_APPLY is NOT set then returns + * the first unused index but does NOT mark the banner as created. + * returns 0xFF on failure. + * + * rct2: 0x006BA278 + */ +sint32 create_new_banner(uint8 flags) +{ + uint8 bannerIndex = BannerGetNewIndex(); + + if (bannerIndex == BANNER_NULL) + { + gGameCommandErrorText = STR_TOO_MANY_BANNERS_IN_GAME; + return BANNER_NULL; + } + + if (flags & GAME_COMMAND_FLAG_APPLY) + { + rct_banner* banner = &gBanners[bannerIndex]; + + banner->flags = 0; + banner->type = 0; + banner->string_idx = STR_DEFAULT_SIGN; + banner->colour = 2; + banner->text_colour = 2; + } + return bannerIndex; +} + +rct_tile_element *banner_get_tile_element(sint32 bannerIndex) +{ + rct_banner *banner = &gBanners[bannerIndex]; + rct_tile_element *tileElement = map_get_first_element_at(banner->x, banner->y); + do + { + if (tile_element_get_banner_index(tileElement) == bannerIndex) + { + return tileElement; + } + } while (!tile_element_is_last_for_tile(tileElement++)); + return nullptr; +} + +/** + * + * rct2: 0x006B7D86 + */ +sint32 banner_get_closest_ride_index(sint32 x, sint32 y, sint32 z) +{ + sint32 i, rideIndex; + Ride *ride; + + static constexpr const LocationXY16 NeighbourCheckOrder[] = + { + { 32, 0 }, + { -32, 0 }, + { 0, 32 }, + { 0, -32 }, + { -32, +32 }, + { +32, -32 }, + { +32, +32 }, + { -32, +32 }, + { 0, 0 } + }; + + for (i = 0; i < (sint32)Util::CountOf(NeighbourCheckOrder); i++) + { + rideIndex = banner_get_ride_index_at(x + NeighbourCheckOrder[i].x, y + NeighbourCheckOrder[i].y, z); + if (rideIndex != -1) + { + return rideIndex; + } + } + + rideIndex = -1; + sint32 resultDistance = std::numeric_limits::max(); + FOR_ALL_RIDES(i, ride) + { + if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_IS_SHOP)) + continue; + + LocationXY8 location = ride->overall_view; + if (location.xy == RCT_XY8_UNDEFINED) + continue; + + sint32 rideX = location.x * 32; + sint32 rideY = location.y * 32; + sint32 distance = abs(x - rideX) + abs(y - rideY); + if (distance < resultDistance) + { + resultDistance = distance; + rideIndex = i; + } + } + + return rideIndex; +} + +void banner_reset_broken_index() +{ + for (sint32 bannerIndex = 0; bannerIndex < MAX_BANNERS; bannerIndex++) + { + rct_tile_element *tileElement = banner_get_tile_element(bannerIndex); + if (tileElement == nullptr) + gBanners[bannerIndex].type = BANNER_NULL; + } +} + +/** + * + * rct2: 0x006BA058 + */ +void game_command_remove_banner(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) +{ + *ebx = BannerRemove( + *eax & 0xFFFF, + *ecx & 0xFFFF, + *edx & 0xFF, + (*edx >> 8) & 0xFF, + *ebx & 0xFF + ); +} + +/** + * + * rct2: 0x006BA16A + */ +void game_command_set_banner_colour(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) +{ + *ebx = BannerSetColour( + *eax & 0xFFFF, + *ecx & 0xFFFF, + *edx & 0xFF, + (*edx >> 8) & 0xFF, + *ebp & 0xFF, + *ebx & 0xFF + ); +} + +/** + * + * rct2: 0x006B9E6D + */ +void game_command_place_banner(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) +{ + *ebx = BannerPlace( + *eax & 0xFFFF, + *ecx & 0xFFFF, + *edx & 0xFF, + (*edx >> 8) & 0xFF, + *ebp & 0xFF, + (*ebx >> 8) & 0xFF, + (uint8 *)edi, + *ebx & 0xFF + ); +} + +void game_command_set_banner_name(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) +{ + *ebx = BannerSetName( + *ecx & 0xFF, + *eax & 0xFFFF, + *edx, + *ebp, + *edi, + *ebx & 0xFF + ); +} + +void game_command_set_banner_style(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) +{ + *ebx = BannerSetStyle( + *ecx & 0xFF, + *edx & 0xFF, + *edi & 0xFF, + *ebp & 0xFF, + *ebx & 0xFF + ); +} + diff --git a/src/openrct2/world/Banner.h b/src/openrct2/world/Banner.h index 7978c3acc1..e2b18fd470 100644 --- a/src/openrct2/world/Banner.h +++ b/src/openrct2/world/Banner.h @@ -43,10 +43,6 @@ enum{ BANNER_FLAG_IS_WALL = (1 << 3) }; -#ifdef __cplusplus -extern "C" { -#endif - extern rct_banner gBanners[MAX_BANNERS]; void banner_init(); @@ -56,8 +52,4 @@ sint32 banner_get_closest_ride_index(sint32 x, sint32 y, sint32 z); void banner_reset_broken_index(); void game_command_callback_place_banner(sint32 eax, sint32 ebx, sint32 ecx, sint32 edx, sint32 esi, sint32 edi, sint32 ebp); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/world/Climate.cpp b/src/openrct2/world/Climate.cpp index 75ed5ae8f1..d3f78877aa 100644 --- a/src/openrct2/world/Climate.cpp +++ b/src/openrct2/world/Climate.cpp @@ -76,145 +76,142 @@ static void climate_update_lightning(); static void climate_update_thunder(); static void climate_play_thunder(sint32 instanceIndex, sint32 soundId, sint32 volume, sint32 pan); -extern "C" +sint32 climate_celsius_to_fahrenheit(sint32 celsius) { - sint32 climate_celsius_to_fahrenheit(sint32 celsius) + return (celsius * 29) / 16 + 32; +} + +/** + * Set climate and determine start weather. + */ +void climate_reset(sint32 climate) +{ + uint8 weather = WEATHER_PARTIALLY_CLOUDY; + sint32 month = date_get_month(gDateMonthsElapsed); + const WeatherTransition * transition = &ClimateTransitions[climate][month]; + const WeatherState * weatherState = &ClimateWeatherData[weather]; + + gClimate = climate; + gClimateCurrent.Weather = weather; + gClimateCurrent.Temperature = transition->BaseTemperature + weatherState->TemperatureDelta; + gClimateCurrent.WeatherEffect = weatherState->EffectLevel; + gClimateCurrent.WeatherGloom = weatherState->GloomLevel; + gClimateCurrent.RainLevel = weatherState->RainLevel; + + _lightningTimer = 0; + _thunderTimer = 0; + if (_rainVolume != 1) { - return (celsius * 29) / 16 + 32; + audio_stop_rain_sound(); + _rainVolume = 1; } - /** - * Set climate and determine start weather. - */ - void climate_reset(sint32 climate) + climate_determine_future_weather(scenario_rand()); +} + +/** + * Weather & climate update iteration. + * Gradually changes the weather parameters towards their determined next values. + */ +void climate_update() +{ + // Only do climate logic if playing (not in scenario editor or title screen) + if (gScreenFlags & (~SCREEN_FLAGS_PLAYING)) return; + + if (!gCheatsFreezeClimate) { - uint8 weather = WEATHER_PARTIALLY_CLOUDY; - sint32 month = date_get_month(gDateMonthsElapsed); - const WeatherTransition * transition = &ClimateTransitions[climate][month]; - const WeatherState * weatherState = &ClimateWeatherData[weather]; - - gClimate = climate; - gClimateCurrent.Weather = weather; - gClimateCurrent.Temperature = transition->BaseTemperature + weatherState->TemperatureDelta; - gClimateCurrent.WeatherEffect = weatherState->EffectLevel; - gClimateCurrent.WeatherGloom = weatherState->GloomLevel; - gClimateCurrent.RainLevel = weatherState->RainLevel; - - _lightningTimer = 0; - _thunderTimer = 0; - if (_rainVolume != 1) + if (gClimateUpdateTimer) { - audio_stop_rain_sound(); - _rainVolume = 1; - } - - climate_determine_future_weather(scenario_rand()); - } - - /** - * Weather & climate update iteration. - * Gradually changes the weather parameters towards their determined next values. - */ - void climate_update() - { - // Only do climate logic if playing (not in scenario editor or title screen) - if (gScreenFlags & (~SCREEN_FLAGS_PLAYING)) return; - - if (!gCheatsFreezeClimate) - { - if (gClimateUpdateTimer) + if (gClimateUpdateTimer == 960) { - if (gClimateUpdateTimer == 960) - { - auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); - context_broadcast_intent(&intent); - } - gClimateUpdateTimer--; + auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); + context_broadcast_intent(&intent); } - else if (!(gCurrentTicks & 0x7F)) + gClimateUpdateTimer--; + } + else if (!(gCurrentTicks & 0x7F)) + { + if (gClimateCurrent.Temperature == gClimateNext.Temperature) { - if (gClimateCurrent.Temperature == gClimateNext.Temperature) + if (gClimateCurrent.WeatherGloom == gClimateNext.WeatherGloom) { - if (gClimateCurrent.WeatherGloom == gClimateNext.WeatherGloom) - { - gClimateCurrent.WeatherEffect = gClimateNext.WeatherEffect; - _thunderTimer = 0; - _lightningTimer = 0; + gClimateCurrent.WeatherEffect = gClimateNext.WeatherEffect; + _thunderTimer = 0; + _lightningTimer = 0; - if (gClimateCurrent.RainLevel == gClimateNext.RainLevel) - { - gClimateCurrent.Weather = gClimateNext.Weather; - climate_determine_future_weather(scenario_rand()); - auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); - context_broadcast_intent(&intent); - } - else if (gClimateNext.RainLevel <= RAIN_LEVEL_HEAVY) - { - gClimateCurrent.RainLevel = climate_step_weather_level(gClimateCurrent.RainLevel, gClimateNext.RainLevel); - } - } - else + if (gClimateCurrent.RainLevel == gClimateNext.RainLevel) { - gClimateCurrent.WeatherGloom = climate_step_weather_level(gClimateCurrent.WeatherGloom, gClimateNext.WeatherGloom); - gfx_invalidate_screen(); + gClimateCurrent.Weather = gClimateNext.Weather; + climate_determine_future_weather(scenario_rand()); + auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); + context_broadcast_intent(&intent); + } + else if (gClimateNext.RainLevel <= RAIN_LEVEL_HEAVY) + { + gClimateCurrent.RainLevel = climate_step_weather_level(gClimateCurrent.RainLevel, gClimateNext.RainLevel); } } else { - gClimateCurrent.Temperature = climate_step_weather_level(gClimateCurrent.Temperature, gClimateNext.Temperature); - auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); - context_broadcast_intent(&intent); + gClimateCurrent.WeatherGloom = climate_step_weather_level(gClimateCurrent.WeatherGloom, gClimateNext.WeatherGloom); + gfx_invalidate_screen(); } } - - } - - if (_thunderTimer != 0) - { - climate_update_lightning(); - climate_update_thunder(); - } - else if (gClimateCurrent.WeatherEffect == WEATHER_EFFECT_STORM) - { - // Create new thunder and lightning - uint32 randomNumber = util_rand(); - if ((randomNumber & 0xFFFF) <= 0x1B4) + else { - randomNumber >>= 16; - _thunderTimer = 43 + (randomNumber % 64); - _lightningTimer = randomNumber % 32; + gClimateCurrent.Temperature = climate_step_weather_level(gClimateCurrent.Temperature, gClimateNext.Temperature); + auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE); + context_broadcast_intent(&intent); } } + } - void climate_force_weather(uint8 weather) + if (_thunderTimer != 0) { - const auto weatherState = &ClimateWeatherData[weather]; - gClimateCurrent.Weather = weather; - gClimateCurrent.WeatherGloom = weatherState->GloomLevel; - gClimateCurrent.RainLevel = weatherState->RainLevel; - gClimateCurrent.WeatherEffect = weatherState->EffectLevel; - gClimateUpdateTimer = 1920; - - climate_update(); - - // In case of change in gloom level force a complete redraw - gfx_invalidate_screen(); + climate_update_lightning(); + climate_update_thunder(); } - - - void climate_update_sound() + else if (gClimateCurrent.WeatherEffect == WEATHER_EFFECT_STORM) { - if (gAudioCurrentDevice == -1) return; - if (gGameSoundsOff) return; - if (!gConfigSound.sound_enabled) return; - if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - - climate_update_rain_sound(); - climate_update_thunder_sound(); + // Create new thunder and lightning + uint32 randomNumber = util_rand(); + if ((randomNumber & 0xFFFF) <= 0x1B4) + { + randomNumber >>= 16; + _thunderTimer = 43 + (randomNumber % 64); + _lightningTimer = randomNumber % 32; + } } } +void climate_force_weather(uint8 weather) +{ + const auto weatherState = &ClimateWeatherData[weather]; + gClimateCurrent.Weather = weather; + gClimateCurrent.WeatherGloom = weatherState->GloomLevel; + gClimateCurrent.RainLevel = weatherState->RainLevel; + gClimateCurrent.WeatherEffect = weatherState->EffectLevel; + gClimateUpdateTimer = 1920; + + climate_update(); + + // In case of change in gloom level force a complete redraw + gfx_invalidate_screen(); +} + + +void climate_update_sound() +{ + if (gAudioCurrentDevice == -1) return; + if (gGameSoundsOff) return; + if (!gConfigSound.sound_enabled) return; + if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; + + climate_update_rain_sound(); + climate_update_thunder_sound(); +} + bool climate_is_raining() { return gClimateCurrent.RainLevel != RAIN_LEVEL_NONE; diff --git a/src/openrct2/world/Climate.h b/src/openrct2/world/Climate.h index 63d1e845b6..897b27d092 100644 --- a/src/openrct2/world/Climate.h +++ b/src/openrct2/world/Climate.h @@ -70,26 +70,18 @@ typedef struct ClimateState uint8 RainLevel; } ClimateState; -#ifdef __cplusplus -extern "C" -{ -#endif - extern uint8 gClimate; - extern ClimateState gClimateCurrent; - extern ClimateState gClimateNext; - extern uint16 gClimateUpdateTimer; - extern uint16 gClimateLightningFlash; +extern uint8 gClimate; +extern ClimateState gClimateCurrent; +extern ClimateState gClimateNext; +extern uint16 gClimateUpdateTimer; +extern uint16 gClimateLightningFlash; - sint32 climate_celsius_to_fahrenheit(sint32 celsius); - void climate_reset(sint32 climate); - void climate_update(); - void climate_update_sound(); - void climate_force_weather(uint8 weather); -#ifdef __cplusplus -} +sint32 climate_celsius_to_fahrenheit(sint32 celsius); +void climate_reset(sint32 climate); +void climate_update(); +void climate_update_sound(); +void climate_force_weather(uint8 weather); bool climate_is_raining(); FILTER_PALETTE_ID climate_get_weather_gloom_palette_id(const ClimateState &state); uint32 climate_get_weather_sprite_id(const ClimateState &state); - -#endif diff --git a/src/openrct2/world/Duck.cpp b/src/openrct2/world/Duck.cpp index faf7cc57bf..ffd609b35c 100644 --- a/src/openrct2/world/Duck.cpp +++ b/src/openrct2/world/Duck.cpp @@ -309,87 +309,85 @@ uint32 rct_duck::GetFrameImage(sint32 direction) const return imageId; } -extern "C" +void create_duck(sint32 targetX, sint32 targetY) { - void create_duck(sint32 targetX, sint32 targetY) + rct_sprite * sprite = create_sprite(2); + if (sprite != nullptr) { - rct_sprite * sprite = create_sprite(2); - if (sprite != nullptr) - { - sprite->duck.sprite_identifier = SPRITE_IDENTIFIER_MISC; - sprite->duck.misc_identifier = SPRITE_MISC_DUCK; - sprite->duck.sprite_width = 9; - sprite->duck.sprite_height_negative = 12; - sprite->duck.sprite_height_positive = 9; - sint32 offsetXY = scenario_rand() & 0x1E; - targetX += offsetXY; - targetY += offsetXY; - sprite->duck.target_x = targetX; - sprite->duck.target_y = targetY; - uint8 direction = scenario_rand() & 3; - switch (direction) { - case 0: - targetX = 8191 - (scenario_rand() & 0x3F); - break; - case 1: - targetY = scenario_rand() & 0x3F; - break; - case 2: - targetX = scenario_rand() & 0x3F; - break; - case 3: - targetY = 8191 - (scenario_rand() & 0x3F); - break; - } - sprite->duck.sprite_direction = direction << 3; - sprite_move(targetX, targetY, 496, sprite); - sprite->duck.state = DUCK_STATE::FLY_TO_WATER; - sprite->duck.frame = 0; - } - } - - void duck_update(rct_duck * duck) - { - switch ((DUCK_STATE)duck->state) { - case DUCK_STATE::FLY_TO_WATER: - duck->UpdateFlyToWater(); + sprite->duck.sprite_identifier = SPRITE_IDENTIFIER_MISC; + sprite->duck.misc_identifier = SPRITE_MISC_DUCK; + sprite->duck.sprite_width = 9; + sprite->duck.sprite_height_negative = 12; + sprite->duck.sprite_height_positive = 9; + sint32 offsetXY = scenario_rand() & 0x1E; + targetX += offsetXY; + targetY += offsetXY; + sprite->duck.target_x = targetX; + sprite->duck.target_y = targetY; + uint8 direction = scenario_rand() & 3; + switch (direction) { + case 0: + targetX = 8191 - (scenario_rand() & 0x3F); break; - case DUCK_STATE::SWIM: - duck->UpdateSwim(); + case 1: + targetY = scenario_rand() & 0x3F; break; - case DUCK_STATE::DRINK: - duck->UpdateDrink(); + case 2: + targetX = scenario_rand() & 0x3F; break; - case DUCK_STATE::DOUBLE_DRINK: - duck->UpdateDoubleDrink(); - break; - case DUCK_STATE::FLY_AWAY: - duck->UpdateFlyAway(); + case 3: + targetY = 8191 - (scenario_rand() & 0x3F); break; } - } - - void duck_press(rct_duck * duck) - { - audio_play_sound_at_location(SOUND_QUACK, duck->x, duck->y, duck->z); - } - - void duck_remove_all() - { - uint16 nextSpriteIndex; - for (uint16 spriteIndex = gSpriteListHead[SPRITE_LIST_MISC]; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = nextSpriteIndex) - { - rct_unk_sprite * sprite = &(get_sprite(spriteIndex)->unknown); - nextSpriteIndex = sprite->next; - if (sprite->misc_identifier == SPRITE_MISC_DUCK) - { - sprite_remove((rct_sprite *)sprite); - } - } - } - - uint32 duck_get_frame_image(const rct_duck * duck, sint32 direction) - { - return duck->GetFrameImage(direction); + sprite->duck.sprite_direction = direction << 3; + sprite_move(targetX, targetY, 496, sprite); + sprite->duck.state = DUCK_STATE::FLY_TO_WATER; + sprite->duck.frame = 0; } } + +void duck_update(rct_duck * duck) +{ + switch ((DUCK_STATE)duck->state) { + case DUCK_STATE::FLY_TO_WATER: + duck->UpdateFlyToWater(); + break; + case DUCK_STATE::SWIM: + duck->UpdateSwim(); + break; + case DUCK_STATE::DRINK: + duck->UpdateDrink(); + break; + case DUCK_STATE::DOUBLE_DRINK: + duck->UpdateDoubleDrink(); + break; + case DUCK_STATE::FLY_AWAY: + duck->UpdateFlyAway(); + break; + } +} + +void duck_press(rct_duck * duck) +{ + audio_play_sound_at_location(SOUND_QUACK, duck->x, duck->y, duck->z); +} + +void duck_remove_all() +{ + uint16 nextSpriteIndex; + for (uint16 spriteIndex = gSpriteListHead[SPRITE_LIST_MISC]; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = nextSpriteIndex) + { + rct_unk_sprite * sprite = &(get_sprite(spriteIndex)->unknown); + nextSpriteIndex = sprite->next; + if (sprite->misc_identifier == SPRITE_MISC_DUCK) + { + sprite_remove((rct_sprite *)sprite); + } + } +} + +uint32 duck_get_frame_image(const rct_duck * duck, sint32 direction) +{ + return duck->GetFrameImage(direction); +} + diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index ce37851f6d..99a5a52f64 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -449,256 +449,253 @@ static money32 RideEntranceExitPlaceGhost(uint8 rideIndex, sint16 x, sint16 y, u ); } -extern "C" +/** + * + * rct2: 0x00666A63 + */ +void game_command_remove_park_entrance(sint32 *eax, + sint32 *ebx, + sint32 *ecx, + sint32 *edx, + sint32 *esi, + sint32 *edi, + sint32 *ebp) { + *ebx = ParkEntranceRemove( + *eax & 0xFFFF, + *ecx & 0xFFFF, + *edx & 0xFF, + *ebx & 0xFF); +} - /** - * - * rct2: 0x00666A63 - */ - void game_command_remove_park_entrance(sint32 *eax, - sint32 *ebx, - sint32 *ecx, - sint32 *edx, - sint32 *esi, - sint32 *edi, - sint32 *ebp) +/** + * + * rct2: 0x00666F9E + */ +void park_entrance_remove_ghost() +{ + if (gParkEntranceGhostExists) { - *ebx = ParkEntranceRemove( - *eax & 0xFFFF, - *ecx & 0xFFFF, - *edx & 0xFF, - *ebx & 0xFF); - } - - /** - * - * rct2: 0x00666F9E - */ - void park_entrance_remove_ghost() - { - if (gParkEntranceGhostExists) - { - gParkEntranceGhostExists = false; - game_do_command( - gParkEntranceGhostPosition.x, - GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5 | GAME_COMMAND_FLAG_APPLY, - gParkEntranceGhostPosition.y, - gParkEntranceGhostPosition.z, - GAME_COMMAND_REMOVE_PARK_ENTRANCE, - 0, - 0 - ); - } - } - - sint32 park_entrance_get_index(sint32 x, sint32 y, sint32 z) - { - sint32 i; - - for (i = 0; i < MAX_PARK_ENTRANCES; i++) - { - if (x == gParkEntrances[i].x && - y == gParkEntrances[i].y && - z == gParkEntrances[i].z) - { - return i; - } - } - - return -1; - } - - void reset_park_entrance() - { - for (auto &parkEntrance : gParkEntrances) - { - parkEntrance.x = LOCATION_NULL; - } - } - - - void ride_entrance_exit_place_provisional_ghost() - { - if (_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT) { - RideEntranceExitPlaceGhost(_currentRideIndex, - gRideEntranceExitGhostPosition.x, - gRideEntranceExitGhostPosition.y, - gRideEntranceExitGhostPosition.direction, - gRideEntranceExitPlaceType, - gRideEntranceExitGhostStationIndex); - } - } - - void ride_entrance_exit_remove_ghost() - { - if (_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT) { - game_do_command( - gRideEntranceExitGhostPosition.x, - (GAME_COMMAND_FLAG_5 | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_APPLY), - gRideEntranceExitGhostPosition.y, - _currentRideIndex, - GAME_COMMAND_REMOVE_RIDE_ENTRANCE_OR_EXIT, - gRideEntranceExitGhostStationIndex, - 0 - ); - } - } - - - /** - * - * rct2: 0x006CA28C - */ - money32 ride_entrance_exit_place_ghost(sint32 rideIndex, - sint32 x, - sint32 y, - sint32 direction, - sint32 placeType, - sint32 stationNum) - { - ride_construction_remove_ghosts(); - money32 result = RideEntranceExitPlaceGhost(rideIndex, x, y, direction, placeType, stationNum); - - if (result != MONEY32_UNDEFINED) - { - _currentTrackSelectionFlags |= TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT; - gRideEntranceExitGhostPosition.x = x; - gRideEntranceExitGhostPosition.y = y; - gRideEntranceExitGhostPosition.direction = direction; - gRideEntranceExitGhostStationIndex = stationNum & 0xFF; - } - return result; - } - - /** - * - * rct2: 0x006660A8 - */ - void game_command_place_ride_entrance_or_exit(sint32 *eax, - sint32 *ebx, - sint32 *ecx, - sint32 *edx, - sint32 *esi, - sint32 *edi, - sint32 *ebp) - { - *ebx = RideEntranceExitPlace( - *eax & 0xFFFF, - *ecx & 0xFFFF, - *edx & 0xFF, - (*ebx >> 8) & 0xFF, - *ebx & 0xFF, - *edx & 0xFF, - *edi & 0xFF, - ((*edx >> 8) & 0xFF) != 0 - ); - } - - /** - * - * rct2: 0x0066640B - */ - void game_command_remove_ride_entrance_or_exit(sint32 *eax, - sint32 *ebx, - sint32 *ecx, - sint32 *edx, - sint32 *esi, - sint32 *edi, - sint32 *ebp) - { - *ebx = RideEntranceExitRemove( - *eax & 0xFFFF, - *ecx & 0xFFFF, - *edx & 0xFF, - *edi & 0xFF, - *ebx & 0xFF + gParkEntranceGhostExists = false; + game_do_command( + gParkEntranceGhostPosition.x, + GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5 | GAME_COMMAND_FLAG_APPLY, + gParkEntranceGhostPosition.y, + gParkEntranceGhostPosition.z, + GAME_COMMAND_REMOVE_PARK_ENTRANCE, + 0, + 0 ); } +} - /** - * Replaces the outer hedge walls for an entrance placement removal. - * rct2: 0x00666D6F - */ - void maze_entrance_hedge_replacement(sint32 x, sint32 y, rct_tile_element *tileElement) +sint32 park_entrance_get_index(sint32 x, sint32 y, sint32 z) +{ + sint32 i; + + for (i = 0; i < MAX_PARK_ENTRANCES; i++) { - sint32 direction = tile_element_get_direction(tileElement); - x += TileDirectionDelta[direction].x; - y += TileDirectionDelta[direction].y; - sint32 z = tileElement->base_height; - sint32 rideIndex = track_element_get_ride_index(tileElement); - - tileElement = map_get_first_element_at(x >> 5, y >> 5); - do { - if (tileElement->type != TILE_ELEMENT_TYPE_TRACK) continue; - if (track_element_get_ride_index(tileElement) != rideIndex) continue; - if (tileElement->base_height != z) continue; - if (track_element_get_type(tileElement) != TRACK_ELEM_MAZE) continue; - - // Each maze element is split into 4 sections with 4 different walls - uint8 mazeSection = direction * 4; - // Add the top outer wall - tileElement->properties.track.maze_entry |= (1 << ((mazeSection + 9) & 0x0F)); - // Add the bottom outer wall - tileElement->properties.track.maze_entry |= (1 << ((mazeSection + 12) & 0x0F)); - - map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8); - return; - } while (!tile_element_is_last_for_tile(tileElement++)); - } - - /** - * Removes the hedge walls for an entrance placement. - * rct2: 0x00666CBE - */ - void maze_entrance_hedge_removal(sint32 x, sint32 y, rct_tile_element *tileElement) - { - sint32 direction = tile_element_get_direction(tileElement); - x += TileDirectionDelta[direction].x; - y += TileDirectionDelta[direction].y; - sint32 z = tileElement->base_height; - sint32 rideIndex = track_element_get_ride_index(tileElement); - - tileElement = map_get_first_element_at(x >> 5, y >> 5); - do { - if (tileElement->type != TILE_ELEMENT_TYPE_TRACK) continue; - if (track_element_get_ride_index(tileElement) != rideIndex) continue; - if (tileElement->base_height != z) continue; - if (track_element_get_type(tileElement) != TRACK_ELEM_MAZE) continue; - - // Each maze element is split into 4 sections with 4 different walls - uint8 mazeSection = direction * 4; - // Remove the top outer wall - tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 9) & 0x0F)); - // Remove the bottom outer wall - tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 12) & 0x0F)); - // Remove the intersecting wall - tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 10) & 0x0F)); - // Remove the top hedge section - tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 11) & 0x0F)); - // Remove the bottom hedge section - tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 15) & 0x0F)); - - map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8); - return; - } while (!tile_element_is_last_for_tile(tileElement++)); - } - - void fix_park_entrance_locations(void) - { - // Fix gParkEntrance locations for which the tile_element no longer exists - for (auto &entrance : gParkEntrances) + if (x == gParkEntrances[i].x && + y == gParkEntrances[i].y && + z == gParkEntrances[i].z) { - if (entrance.x == LOCATION_NULL) - continue; + return i; + } + } - if (map_get_park_entrance_element_at( - entrance.x, - entrance.y, - entrance.z >> 3, false) == nullptr) - { - entrance.x = LOCATION_NULL; - } + return -1; +} + +void reset_park_entrance() +{ + for (auto &parkEntrance : gParkEntrances) + { + parkEntrance.x = LOCATION_NULL; + } +} + + +void ride_entrance_exit_place_provisional_ghost() +{ + if (_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT) { + RideEntranceExitPlaceGhost(_currentRideIndex, + gRideEntranceExitGhostPosition.x, + gRideEntranceExitGhostPosition.y, + gRideEntranceExitGhostPosition.direction, + gRideEntranceExitPlaceType, + gRideEntranceExitGhostStationIndex); + } +} + +void ride_entrance_exit_remove_ghost() +{ + if (_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT) { + game_do_command( + gRideEntranceExitGhostPosition.x, + (GAME_COMMAND_FLAG_5 | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_APPLY), + gRideEntranceExitGhostPosition.y, + _currentRideIndex, + GAME_COMMAND_REMOVE_RIDE_ENTRANCE_OR_EXIT, + gRideEntranceExitGhostStationIndex, + 0 + ); + } +} + + +/** + * + * rct2: 0x006CA28C + */ +money32 ride_entrance_exit_place_ghost(sint32 rideIndex, + sint32 x, + sint32 y, + sint32 direction, + sint32 placeType, + sint32 stationNum) +{ + ride_construction_remove_ghosts(); + money32 result = RideEntranceExitPlaceGhost(rideIndex, x, y, direction, placeType, stationNum); + + if (result != MONEY32_UNDEFINED) + { + _currentTrackSelectionFlags |= TRACK_SELECTION_FLAG_ENTRANCE_OR_EXIT; + gRideEntranceExitGhostPosition.x = x; + gRideEntranceExitGhostPosition.y = y; + gRideEntranceExitGhostPosition.direction = direction; + gRideEntranceExitGhostStationIndex = stationNum & 0xFF; + } + return result; +} + +/** + * + * rct2: 0x006660A8 + */ +void game_command_place_ride_entrance_or_exit(sint32 *eax, + sint32 *ebx, + sint32 *ecx, + sint32 *edx, + sint32 *esi, + sint32 *edi, + sint32 *ebp) +{ + *ebx = RideEntranceExitPlace( + *eax & 0xFFFF, + *ecx & 0xFFFF, + *edx & 0xFF, + (*ebx >> 8) & 0xFF, + *ebx & 0xFF, + *edx & 0xFF, + *edi & 0xFF, + ((*edx >> 8) & 0xFF) != 0 + ); +} + +/** + * + * rct2: 0x0066640B + */ +void game_command_remove_ride_entrance_or_exit(sint32 *eax, + sint32 *ebx, + sint32 *ecx, + sint32 *edx, + sint32 *esi, + sint32 *edi, + sint32 *ebp) +{ + *ebx = RideEntranceExitRemove( + *eax & 0xFFFF, + *ecx & 0xFFFF, + *edx & 0xFF, + *edi & 0xFF, + *ebx & 0xFF + ); +} + +/** + * Replaces the outer hedge walls for an entrance placement removal. + * rct2: 0x00666D6F + */ +void maze_entrance_hedge_replacement(sint32 x, sint32 y, rct_tile_element *tileElement) +{ + sint32 direction = tile_element_get_direction(tileElement); + x += TileDirectionDelta[direction].x; + y += TileDirectionDelta[direction].y; + sint32 z = tileElement->base_height; + sint32 rideIndex = track_element_get_ride_index(tileElement); + + tileElement = map_get_first_element_at(x >> 5, y >> 5); + do { + if (tileElement->type != TILE_ELEMENT_TYPE_TRACK) continue; + if (track_element_get_ride_index(tileElement) != rideIndex) continue; + if (tileElement->base_height != z) continue; + if (track_element_get_type(tileElement) != TRACK_ELEM_MAZE) continue; + + // Each maze element is split into 4 sections with 4 different walls + uint8 mazeSection = direction * 4; + // Add the top outer wall + tileElement->properties.track.maze_entry |= (1 << ((mazeSection + 9) & 0x0F)); + // Add the bottom outer wall + tileElement->properties.track.maze_entry |= (1 << ((mazeSection + 12) & 0x0F)); + + map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8); + return; + } while (!tile_element_is_last_for_tile(tileElement++)); +} + +/** + * Removes the hedge walls for an entrance placement. + * rct2: 0x00666CBE + */ +void maze_entrance_hedge_removal(sint32 x, sint32 y, rct_tile_element *tileElement) +{ + sint32 direction = tile_element_get_direction(tileElement); + x += TileDirectionDelta[direction].x; + y += TileDirectionDelta[direction].y; + sint32 z = tileElement->base_height; + sint32 rideIndex = track_element_get_ride_index(tileElement); + + tileElement = map_get_first_element_at(x >> 5, y >> 5); + do { + if (tileElement->type != TILE_ELEMENT_TYPE_TRACK) continue; + if (track_element_get_ride_index(tileElement) != rideIndex) continue; + if (tileElement->base_height != z) continue; + if (track_element_get_type(tileElement) != TRACK_ELEM_MAZE) continue; + + // Each maze element is split into 4 sections with 4 different walls + uint8 mazeSection = direction * 4; + // Remove the top outer wall + tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 9) & 0x0F)); + // Remove the bottom outer wall + tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 12) & 0x0F)); + // Remove the intersecting wall + tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 10) & 0x0F)); + // Remove the top hedge section + tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 11) & 0x0F)); + // Remove the bottom hedge section + tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 15) & 0x0F)); + + map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8); + return; + } while (!tile_element_is_last_for_tile(tileElement++)); +} + +void fix_park_entrance_locations(void) +{ + // Fix gParkEntrance locations for which the tile_element no longer exists + for (auto &entrance : gParkEntrances) + { + if (entrance.x == LOCATION_NULL) + continue; + + if (map_get_park_entrance_element_at( + entrance.x, + entrance.y, + entrance.z >> 3, false) == nullptr) + { + entrance.x = LOCATION_NULL; } } } + diff --git a/src/openrct2/world/Entrance.h b/src/openrct2/world/Entrance.h index a3147d9fd8..c31f12973b 100644 --- a/src/openrct2/world/Entrance.h +++ b/src/openrct2/world/Entrance.h @@ -29,10 +29,6 @@ typedef struct rct_entrance_type { assert_struct_size(rct_entrance_type, 8); #pragma pack(pop) -#ifdef __cplusplus -extern "C" { -#endif - void game_command_remove_park_entrance(sint32 *eax, sint32 *ebx, sint32 *ecx, sint32 *edx, sint32 *esi, sint32 *edi, sint32 *ebp); typedef struct LocationXYZ16 LocationXYZ16; @@ -60,8 +56,4 @@ void maze_entrance_hedge_removal(sint32 x, sint32 y, rct_tile_element *tileEleme void fix_park_entrance_locations(); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 25d6b6f172..7e2609865c 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -110,10 +110,6 @@ enum SLOPE_IS_IRREGULAR_FLAG = (1 << 3), // Flag set in `defaultPathSlope[]` and checked in `footpath_place_real` }; -#ifdef __cplusplus -extern "C" { -#endif - extern uint8 gFootpathProvisionalFlags; extern LocationXYZ16 gFootpathProvisionalPosition; extern uint8 gFootpathProvisionalType; @@ -175,8 +171,4 @@ rct_footpath_entry * get_footpath_entry(sint32 entryIndex); void footpath_queue_chain_reset(); void footpath_queue_chain_push(uint8 rideIndex); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/world/Fountain.cpp b/src/openrct2/world/Fountain.cpp index 8d76b1ef01..4e1aea1eb2 100644 --- a/src/openrct2/world/Fountain.cpp +++ b/src/openrct2/world/Fountain.cpp @@ -97,148 +97,146 @@ static void jumping_fountain_split(const rct_jumping_fountain * jumpingFountain, static void jumping_fountain_random(const rct_jumping_fountain * jumpingFountain, sint32 x, sint32 y, sint32 z, sint32 availableDirections); static void jumping_fountain_create_next(const rct_jumping_fountain * jumpingFountain, sint32 x, sint32 y, sint32 z, sint32 direction); -extern "C" +void jumping_fountain_begin(sint32 type, sint32 x, sint32 y, const rct_tile_element * tileElement) { - void jumping_fountain_begin(sint32 type, sint32 x, sint32 y, const rct_tile_element * tileElement) - { - sint32 randomIndex; - sint32 z = tileElement->base_height * 8; + sint32 randomIndex; + sint32 z = tileElement->base_height * 8; - // Change pattern approximately every 51 seconds - uint32 pattern = (gCurrentTicks >> 11) & 7; - switch ((PATTERN)pattern) { - case PATTERN::CYCLIC_SQUARES: - // 0, 1, 2, 3 - for (sint32 i = 0; i < 4; i++) - { - jumping_fountain_create( - type, - x + _fountainDirectionsPositive[i].x, - y + _fountainDirectionsPositive[i].y, - z, - _fountainDirections[i], - _fountainDirectionFlags[i] | _fountainPatternFlags[pattern], - 0 - ); - } - break; - case PATTERN::BOUNCING_PAIRS: - // random [0, 2 or 1, 3] - randomIndex = scenario_rand() & 1; - for (sint32 i = randomIndex; i < 4; i += 2) - { - jumping_fountain_create( - type, - x + _fountainDirectionsPositive[i].x, - y + _fountainDirectionsPositive[i].y, - z, - _fountainDirections[i], - _fountainDirectionFlags[i] | _fountainPatternFlags[pattern], - 0 - ); - } - break; - case PATTERN::RACING_PAIRS: - // random [0 - 3 and 4 - 7] - randomIndex = scenario_rand() & 3; + // Change pattern approximately every 51 seconds + uint32 pattern = (gCurrentTicks >> 11) & 7; + switch ((PATTERN)pattern) { + case PATTERN::CYCLIC_SQUARES: + // 0, 1, 2, 3 + for (sint32 i = 0; i < 4; i++) + { jumping_fountain_create( type, - x + _fountainDirectionsPositive[randomIndex].x, - y + _fountainDirectionsPositive[randomIndex].y, + x + _fountainDirectionsPositive[i].x, + y + _fountainDirectionsPositive[i].y, z, - _fountainDirections[randomIndex], - _fountainDirectionFlags[randomIndex] | _fountainPatternFlags[pattern], + _fountainDirections[i], + _fountainDirectionFlags[i] | _fountainPatternFlags[pattern], 0 ); - randomIndex += 4; + } + break; + case PATTERN::BOUNCING_PAIRS: + // random [0, 2 or 1, 3] + randomIndex = scenario_rand() & 1; + for (sint32 i = randomIndex; i < 4; i += 2) + { jumping_fountain_create( type, - x + _fountainDirectionsPositive[randomIndex].x, - y + _fountainDirectionsPositive[randomIndex].y, + x + _fountainDirectionsPositive[i].x, + y + _fountainDirectionsPositive[i].y, z, - _fountainDirections[randomIndex], - _fountainDirectionFlags[randomIndex] | _fountainPatternFlags[pattern], + _fountainDirections[i], + _fountainDirectionFlags[i] | _fountainPatternFlags[pattern], 0 ); - break; - default: - // random [0 - 7] - randomIndex = scenario_rand() & 7; - jumping_fountain_create( - type, - x + _fountainDirectionsPositive[randomIndex].x, - y + _fountainDirectionsPositive[randomIndex].y, - z, - _fountainDirections[randomIndex], - _fountainDirectionFlags[randomIndex] | _fountainPatternFlags[pattern], - 0 - ); - break; - } - } - - void jumping_fountain_create(sint32 type, sint32 x, sint32 y, sint32 z, sint32 direction, sint32 flags, sint32 iteration) - { - rct_jumping_fountain * jumpingFountain = (rct_jumping_fountain *)create_sprite(SPRITE_IDENTIFIER_MISC); - if (jumpingFountain != nullptr) - { - jumpingFountain->iteration = iteration; - jumpingFountain->fountain_flags = flags; - jumpingFountain->sprite_direction = direction << 3; - jumpingFountain->sprite_width = 33; - jumpingFountain->sprite_height_negative = 36; - jumpingFountain->sprite_height_positive = 12; - jumpingFountain->sprite_identifier = SPRITE_IDENTIFIER_MISC; - sprite_move(x, y, z, (rct_sprite *)jumpingFountain); - jumpingFountain->misc_identifier = type == JUMPING_FOUNTAIN_TYPE_SNOW ? - SPRITE_MISC_JUMPING_FOUNTAIN_SNOW : - SPRITE_MISC_JUMPING_FOUNTAIN_WATER; - jumpingFountain->num_ticks_alive = 0; - jumpingFountain->frame = 0; - } - } - - void jumping_fountain_update(rct_jumping_fountain * jumpingFountain) - { - jumpingFountain->num_ticks_alive++; - // Originaly this would not update the frame on the following - // ticks: 1, 3, 6, 9, 11, 14, 17, 19, 22, 25 - // This change was to simplefy the code base. There is a small increase - // in speed of the fountain jump because of this change. - if ((jumpingFountain->num_ticks_alive % 3) == 0) - { - return; - } - - invalidate_sprite_0((rct_sprite *)jumpingFountain); - jumpingFountain->frame++; - - switch (jumpingFountain->misc_identifier) { - case SPRITE_MISC_JUMPING_FOUNTAIN_WATER: - if (jumpingFountain->frame == 11 && (jumpingFountain->fountain_flags & FOUNTAIN_FLAG::FAST)) - { - jumping_fountain_continue(jumpingFountain); - } - if (jumpingFountain->frame == 16 && !(jumpingFountain->fountain_flags & FOUNTAIN_FLAG::FAST)) - { - jumping_fountain_continue(jumpingFountain); - } - break; - case SPRITE_MISC_JUMPING_FOUNTAIN_SNOW: - if (jumpingFountain->frame == 16) - { - jumping_fountain_continue(jumpingFountain); - } - break; - } - - if (jumpingFountain->frame == 16) - { - sprite_remove((rct_sprite*)jumpingFountain); } + break; + case PATTERN::RACING_PAIRS: + // random [0 - 3 and 4 - 7] + randomIndex = scenario_rand() & 3; + jumping_fountain_create( + type, + x + _fountainDirectionsPositive[randomIndex].x, + y + _fountainDirectionsPositive[randomIndex].y, + z, + _fountainDirections[randomIndex], + _fountainDirectionFlags[randomIndex] | _fountainPatternFlags[pattern], + 0 + ); + randomIndex += 4; + jumping_fountain_create( + type, + x + _fountainDirectionsPositive[randomIndex].x, + y + _fountainDirectionsPositive[randomIndex].y, + z, + _fountainDirections[randomIndex], + _fountainDirectionFlags[randomIndex] | _fountainPatternFlags[pattern], + 0 + ); + break; + default: + // random [0 - 7] + randomIndex = scenario_rand() & 7; + jumping_fountain_create( + type, + x + _fountainDirectionsPositive[randomIndex].x, + y + _fountainDirectionsPositive[randomIndex].y, + z, + _fountainDirections[randomIndex], + _fountainDirectionFlags[randomIndex] | _fountainPatternFlags[pattern], + 0 + ); + break; } } +void jumping_fountain_create(sint32 type, sint32 x, sint32 y, sint32 z, sint32 direction, sint32 flags, sint32 iteration) +{ + rct_jumping_fountain * jumpingFountain = (rct_jumping_fountain *)create_sprite(SPRITE_IDENTIFIER_MISC); + if (jumpingFountain != nullptr) + { + jumpingFountain->iteration = iteration; + jumpingFountain->fountain_flags = flags; + jumpingFountain->sprite_direction = direction << 3; + jumpingFountain->sprite_width = 33; + jumpingFountain->sprite_height_negative = 36; + jumpingFountain->sprite_height_positive = 12; + jumpingFountain->sprite_identifier = SPRITE_IDENTIFIER_MISC; + sprite_move(x, y, z, (rct_sprite *)jumpingFountain); + jumpingFountain->misc_identifier = type == JUMPING_FOUNTAIN_TYPE_SNOW ? + SPRITE_MISC_JUMPING_FOUNTAIN_SNOW : + SPRITE_MISC_JUMPING_FOUNTAIN_WATER; + jumpingFountain->num_ticks_alive = 0; + jumpingFountain->frame = 0; + } +} + +void jumping_fountain_update(rct_jumping_fountain * jumpingFountain) +{ + jumpingFountain->num_ticks_alive++; + // Originaly this would not update the frame on the following + // ticks: 1, 3, 6, 9, 11, 14, 17, 19, 22, 25 + // This change was to simplefy the code base. There is a small increase + // in speed of the fountain jump because of this change. + if ((jumpingFountain->num_ticks_alive % 3) == 0) + { + return; + } + + invalidate_sprite_0((rct_sprite *)jumpingFountain); + jumpingFountain->frame++; + + switch (jumpingFountain->misc_identifier) { + case SPRITE_MISC_JUMPING_FOUNTAIN_WATER: + if (jumpingFountain->frame == 11 && (jumpingFountain->fountain_flags & FOUNTAIN_FLAG::FAST)) + { + jumping_fountain_continue(jumpingFountain); + } + if (jumpingFountain->frame == 16 && !(jumpingFountain->fountain_flags & FOUNTAIN_FLAG::FAST)) + { + jumping_fountain_continue(jumpingFountain); + } + break; + case SPRITE_MISC_JUMPING_FOUNTAIN_SNOW: + if (jumpingFountain->frame == 16) + { + jumping_fountain_continue(jumpingFountain); + } + break; + } + + if (jumpingFountain->frame == 16) + { + sprite_remove((rct_sprite*)jumpingFountain); + } +} + + static sint32 jumping_fountain_get_type(const rct_jumping_fountain * jumpingFountain) { sint32 type = jumpingFountain->misc_identifier == SPRITE_MISC_JUMPING_FOUNTAIN_SNOW ? diff --git a/src/openrct2/world/Fountain.h b/src/openrct2/world/Fountain.h index 951a2cdc56..842ee73d88 100644 --- a/src/openrct2/world/Fountain.h +++ b/src/openrct2/world/Fountain.h @@ -27,13 +27,7 @@ enum JUMPING_FOUNTAIN_TYPE_SNOW }; -#ifdef __cplusplus -extern "C" -{ -#endif - void jumping_fountain_begin(sint32 type, sint32 x, sint32 y, const rct_tile_element * tileElement); - void jumping_fountain_create(sint32 type, sint32 x, sint32 y, sint32 z, sint32 direction, sint32 flags, sint32 iteration); - void jumping_fountain_update(rct_jumping_fountain * jumpingFountain); -#ifdef __cplusplus -} -#endif +void jumping_fountain_begin(sint32 type, sint32 x, sint32 y, const rct_tile_element * tileElement); +void jumping_fountain_create(sint32 type, sint32 x, sint32 y, sint32 z, sint32 direction, sint32 flags, sint32 iteration); +void jumping_fountain_update(rct_jumping_fountain * jumpingFountain); + diff --git a/src/openrct2/world/LargeScenery.cpp b/src/openrct2/world/LargeScenery.cpp index 285d40b5f6..071efb851a 100644 --- a/src/openrct2/world/LargeScenery.cpp +++ b/src/openrct2/world/LargeScenery.cpp @@ -18,66 +18,64 @@ #include "LargeScenery.h" #include "Map.h" -extern "C" +colour_t scenery_large_get_primary_colour(const rct_tile_element * tileElement) { - colour_t scenery_large_get_primary_colour(const rct_tile_element * tileElement) - { - return tileElement->properties.scenerymultiple.colour[0] & TILE_ELEMENT_COLOUR_MASK; - } - - colour_t scenery_large_get_secondary_colour(const rct_tile_element * tileElement) - { - return tileElement->properties.scenerymultiple.colour[1] & TILE_ELEMENT_COLOUR_MASK; - } - - void scenery_large_set_primary_colour(rct_tile_element * tileElement, colour_t colour) - { - assert(colour <= 31); - tileElement->properties.scenerymultiple.colour[0] &= ~TILE_ELEMENT_COLOUR_MASK; - tileElement->properties.scenerymultiple.colour[0] |= colour; - } - - void scenery_large_set_secondary_colour(rct_tile_element * tileElement, colour_t colour) - { - assert(colour <= 31); - tileElement->properties.scenerymultiple.colour[1] &= ~TILE_ELEMENT_COLOUR_MASK; - tileElement->properties.scenerymultiple.colour[1] |= colour; - } - - sint32 scenery_large_get_banner_id(rct_tile_element * tileElement) - { - return (tileElement->type & 0xC0) | - (((tileElement->properties.scenerymultiple.colour[0]) &~ TILE_ELEMENT_COLOUR_MASK) >> 2) | - (((tileElement->properties.scenerymultiple.colour[1]) &~ TILE_ELEMENT_COLOUR_MASK) >> 5); - } - - void scenery_large_set_banner_id(rct_tile_element * tileElement, uint8 bannerIndex) - { - tileElement->type |= bannerIndex & 0xC0; - tileElement->properties.scenerymultiple.colour[0] |= (bannerIndex & 0x38) << 2; - tileElement->properties.scenerymultiple.colour[1] |= (bannerIndex & 7) << 5; - } - - sint32 scenery_large_get_type(rct_tile_element * tileElement) - { - return (tileElement->properties.scenerymultiple.type & TILE_ELEMENT_LARGE_TYPE_MASK); - } - - sint32 scenery_large_get_sequence(rct_tile_element * tileElement) - { - return (tileElement->properties.scenerymultiple.type >> 10); - } - - void scenery_large_set_type(rct_tile_element * tileElement, uint16 type) - { - tileElement->properties.scenerymultiple.type &= ~TILE_ELEMENT_LARGE_TYPE_MASK; - tileElement->properties.scenerymultiple.type |= (type & TILE_ELEMENT_LARGE_TYPE_MASK); - } - - void scenery_large_set_sequence(rct_tile_element * tileElement, uint16 sequence) - { - tileElement->properties.scenerymultiple.type &= TILE_ELEMENT_LARGE_TYPE_MASK; - tileElement->properties.scenerymultiple.type |= (sequence << 10); - } + return tileElement->properties.scenerymultiple.colour[0] & TILE_ELEMENT_COLOUR_MASK; } +colour_t scenery_large_get_secondary_colour(const rct_tile_element * tileElement) +{ + return tileElement->properties.scenerymultiple.colour[1] & TILE_ELEMENT_COLOUR_MASK; +} + +void scenery_large_set_primary_colour(rct_tile_element * tileElement, colour_t colour) +{ + assert(colour <= 31); + tileElement->properties.scenerymultiple.colour[0] &= ~TILE_ELEMENT_COLOUR_MASK; + tileElement->properties.scenerymultiple.colour[0] |= colour; +} + +void scenery_large_set_secondary_colour(rct_tile_element * tileElement, colour_t colour) +{ + assert(colour <= 31); + tileElement->properties.scenerymultiple.colour[1] &= ~TILE_ELEMENT_COLOUR_MASK; + tileElement->properties.scenerymultiple.colour[1] |= colour; +} + +sint32 scenery_large_get_banner_id(rct_tile_element * tileElement) +{ + return (tileElement->type & 0xC0) | + (((tileElement->properties.scenerymultiple.colour[0]) &~ TILE_ELEMENT_COLOUR_MASK) >> 2) | + (((tileElement->properties.scenerymultiple.colour[1]) &~ TILE_ELEMENT_COLOUR_MASK) >> 5); +} + +void scenery_large_set_banner_id(rct_tile_element * tileElement, uint8 bannerIndex) +{ + tileElement->type |= bannerIndex & 0xC0; + tileElement->properties.scenerymultiple.colour[0] |= (bannerIndex & 0x38) << 2; + tileElement->properties.scenerymultiple.colour[1] |= (bannerIndex & 7) << 5; +} + +sint32 scenery_large_get_type(rct_tile_element * tileElement) +{ + return (tileElement->properties.scenerymultiple.type & TILE_ELEMENT_LARGE_TYPE_MASK); +} + +sint32 scenery_large_get_sequence(rct_tile_element * tileElement) +{ + return (tileElement->properties.scenerymultiple.type >> 10); +} + +void scenery_large_set_type(rct_tile_element * tileElement, uint16 type) +{ + tileElement->properties.scenerymultiple.type &= ~TILE_ELEMENT_LARGE_TYPE_MASK; + tileElement->properties.scenerymultiple.type |= (type & TILE_ELEMENT_LARGE_TYPE_MASK); +} + +void scenery_large_set_sequence(rct_tile_element * tileElement, uint16 sequence) +{ + tileElement->properties.scenerymultiple.type &= TILE_ELEMENT_LARGE_TYPE_MASK; + tileElement->properties.scenerymultiple.type |= (sequence << 10); +} + + diff --git a/src/openrct2/world/LargeScenery.h b/src/openrct2/world/LargeScenery.h index 65d9f65edd..48d5e0342a 100644 --- a/src/openrct2/world/LargeScenery.h +++ b/src/openrct2/world/LargeScenery.h @@ -19,10 +19,6 @@ #include "../common.h" #include "Map.h" -#ifdef __cplusplus -extern "C" { -#endif - colour_t scenery_large_get_primary_colour(const rct_tile_element * tileElement); colour_t scenery_large_get_secondary_colour(const rct_tile_element * tileElement); void scenery_large_set_primary_colour(rct_tile_element * tileElement, colour_t colour); @@ -33,7 +29,3 @@ sint32 scenery_large_get_type(rct_tile_element * tileElement); sint32 scenery_large_get_sequence(rct_tile_element * tileElement); void scenery_large_set_type(rct_tile_element * tileElement, uint16 type); void scenery_large_set_sequence(rct_tile_element * tileElement, uint16 sequence); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index bc57d42e8b..7eb7210867 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -378,10 +378,6 @@ enum CREATE_CROSSING_MODE_PATH_OVER_TRACK, }; -#ifdef __cplusplus -extern "C" { -#endif - extern const LocationXY16 TileDirectionDelta[]; extern const money32 TerrainPricing[]; @@ -592,11 +588,7 @@ uint32 map_get_available_peep_spawn_index_list(uint32* peepSpawnIndexList); uint16 check_max_allowable_land_rights_for_tile(uint8 x, uint8 y, uint8 base_z); uint8 tile_element_get_ride_index(const rct_tile_element * tileElement); -#ifdef __cplusplus void FixLandOwnershipTiles(std::initializer_list tiles); void FixLandOwnershipTilesWithOwnership(std::initializer_list tiles, uint8 ownership); -} -#endif - #endif diff --git a/src/openrct2/world/MapAnimation.h b/src/openrct2/world/MapAnimation.h index 6f200e9230..f361d8ca7f 100644 --- a/src/openrct2/world/MapAnimation.h +++ b/src/openrct2/world/MapAnimation.h @@ -53,18 +53,10 @@ enum { #define MAX_ANIMATED_OBJECTS 2000 -#ifdef __cplusplus -extern "C" { -#endif - extern uint16 gNumMapAnimations; extern rct_map_animation gAnimatedObjects[MAX_ANIMATED_OBJECTS]; void map_animation_create(sint32 type, sint32 x, sint32 y, sint32 z); void map_animation_invalidate_all(); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/world/MapGen.h b/src/openrct2/world/MapGen.h index e252ec73ca..eca17c086f 100644 --- a/src/openrct2/world/MapGen.h +++ b/src/openrct2/world/MapGen.h @@ -43,17 +43,9 @@ typedef struct mapgen_settings bool normalize_height; } mapgen_settings; -#ifdef __cplusplus -extern "C" { -#endif - void mapgen_generate_blank(mapgen_settings * settings); void mapgen_generate(mapgen_settings * settings); void mapgen_generate_custom_simplex(mapgen_settings * settings); bool mapgen_load_heightmap(const utf8 * path); void mapgen_unload_heightmap(); void mapgen_generate_from_heightmap(mapgen_settings * settings); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/world/MapHelpers.h b/src/openrct2/world/MapHelpers.h index 7b1a426ba2..53d4b80b17 100644 --- a/src/openrct2/world/MapHelpers.h +++ b/src/openrct2/world/MapHelpers.h @@ -24,15 +24,7 @@ enum { SLOPE_E_THRESHOLD_FLAGS = (1 << 3) }; -#ifdef __cplusplus -extern "C" { -#endif - sint32 map_smooth(sint32 l, sint32 t, sint32 r, sint32 b); sint32 tile_smooth(sint32 x, sint32 y); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/world/Park.h b/src/openrct2/world/Park.h index 0af561472f..498f7049d1 100644 --- a/src/openrct2/world/Park.h +++ b/src/openrct2/world/Park.h @@ -57,10 +57,6 @@ enum BUY_LAND_RIGHTS_FLAG_SET_OWNERSHIP_WITH_CHECKS, // Used in scenario editor }; -#ifdef __cplusplus -extern "C" { -#endif - extern rct_string_id gParkName; extern uint32 gParkNameArgs; extern uint32 gParkFlags; @@ -120,8 +116,4 @@ money16 park_get_entrance_fee(); bool park_ride_prices_unlocked(); bool park_entry_price_unlocked(); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/world/Scenery.h b/src/openrct2/world/Scenery.h index a56d6bb0b9..e4c84e5de5 100644 --- a/src/openrct2/world/Scenery.h +++ b/src/openrct2/world/Scenery.h @@ -231,10 +231,6 @@ enum #define SCENERY_ENTRIES_BY_TAB 1024 -#ifdef __cplusplus -extern "C" { -#endif - extern uint8 gWindowSceneryActiveTabIndex; extern uint16 gWindowSceneryTabSelections[20]; extern uint8 gWindowSceneryClusterEnabled; @@ -290,8 +286,4 @@ rct_scenery_group_entry *get_scenery_group_entry(sint32 entryIndex); sint32 get_scenery_id_from_entry_index(uint8 objectType, sint32 entryIndex); sint32 wall_entry_get_door_sound(const rct_scenery_entry * wallEntry); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/openrct2/world/SmallScenery.cpp b/src/openrct2/world/SmallScenery.cpp index 2fc80abef7..ac4d96ff6c 100644 --- a/src/openrct2/world/SmallScenery.cpp +++ b/src/openrct2/world/SmallScenery.cpp @@ -437,168 +437,166 @@ static money32 SmallSceneryPlace(sint16 x, return cost; } -extern "C" +/** + * + * rct2: 0x006E0E01 + */ +void game_command_remove_scenery(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) { - /** - * - * rct2: 0x006E0E01 - */ - void game_command_remove_scenery(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) - { - *ebx = SmallSceneryRemove( - *eax & 0xFFFF, - *ecx & 0xFFFF, - *edx & 0xFF, - ((*ebx >> 8) & 0xFF) >> 6, - (*edx >> 8) & 0xFF, - *ebx & 0xFF - ); - } - - /** - * - * rct2: 0x006E0F26 - */ - void game_command_set_scenery_colour(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) - { - *ebx = SmallScenerySetColour( - *eax & 0xFFFF, - *ecx & 0xFFFF, - *edx & 0xFF, - ((*ebx >> 8) & 0xFF) >> 6, - (*edx >> 8) & 0xFF, - *ebp & 0xFF, - (*ebp >> 8) & 0xFF, - *ebx & 0xFF - ); - } - - /** - * - * rct2: 0x006E0D6E, 0x006B8D88 - */ - sint32 map_place_scenery_clear_func(rct_tile_element** tile_element, sint32 x, sint32 y, uint8 flags, money32* price) - { - if (tile_element_get_type(*tile_element) != TILE_ELEMENT_TYPE_SMALL_SCENERY) - return 1; - - if (!(flags & GAME_COMMAND_FLAG_PATH_SCENERY)) - return 1; - - rct_scenery_entry* scenery = get_small_scenery_entry((*tile_element)->properties.scenery.type); - - if (gParkFlags & PARK_FLAGS_FORBID_TREE_REMOVAL) - { - if (scenery->small_scenery.height > 64) - return 1; - } - - if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) - *price += scenery->small_scenery.removal_price * 10; - - if (flags & GAME_COMMAND_FLAG_GHOST) - return 0; - - if (!(flags & GAME_COMMAND_FLAG_APPLY)) - return 0; - - map_invalidate_tile(x, y, (*tile_element)->base_height * 8, (*tile_element)->clearance_height * 8); - - tile_element_remove(*tile_element); - - (*tile_element)--; - return 0; - } - - /** - * - * rct2: 0x006C5A4F, 0x006CDE57, 0x006A6733, 0x0066637E - */ - sint32 map_place_non_scenery_clear_func(rct_tile_element** tile_element, sint32 x, sint32 y, uint8 flags, money32* price) - { - if (tile_element_get_type(*tile_element) != TILE_ELEMENT_TYPE_SMALL_SCENERY) - return 1; - - rct_scenery_entry* scenery = get_small_scenery_entry((*tile_element)->properties.scenery.type); - - if (gParkFlags & PARK_FLAGS_FORBID_TREE_REMOVAL) - { - if (scenery->small_scenery.height > 64) - return 1; - } - - if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) - *price += scenery->small_scenery.removal_price * 10; - - if (flags & GAME_COMMAND_FLAG_GHOST) - return 0; - - if (!(flags & GAME_COMMAND_FLAG_APPLY)) - return 0; - - map_invalidate_tile(x, y, (*tile_element)->base_height * 8, (*tile_element)->clearance_height * 8); - - tile_element_remove(*tile_element); - - (*tile_element)--; - return 0; - } - - /** - * - * rct2: 0x006E08F4 - */ - void game_command_place_scenery(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) - { - *ebx = SmallSceneryPlace( - *eax & 0xFFFF, - *ecx & 0xFFFF, - *ebp & 0xFFFF, - *edx & 0xFF, - *edi & 0xFF, - (*ebx >> 8) & 0xFF, - (*edx >> 8) & 0xFF, - (*edi >> 16) & 0xFF, - *ebx & 0xFF - ); - } - - sint32 scenery_small_get_primary_colour(const rct_tile_element * tileElement) - { - return tileElement->properties.scenery.colour_1 & TILE_ELEMENT_COLOUR_MASK; - } - - sint32 scenery_small_get_secondary_colour(const rct_tile_element * tileElement) - { - return tileElement->properties.scenery.colour_2 & TILE_ELEMENT_COLOUR_MASK; - } - - void scenery_small_set_primary_colour(rct_tile_element * tileElement, uint32 colour) - { - assert(colour <= 31); - tileElement->properties.scenery.colour_1 &= ~TILE_ELEMENT_COLOUR_MASK; - tileElement->properties.scenery.colour_1 |= colour; - } - - void scenery_small_set_secondary_colour(rct_tile_element * tileElement, uint32 colour) - { - assert(colour <= 31); - tileElement->properties.scenery.colour_2 &= ~TILE_ELEMENT_COLOUR_MASK; - tileElement->properties.scenery.colour_2 |= colour; - } - - bool scenery_small_get_supports_needed(const rct_tile_element * tileElement) - { - return (bool)(tileElement->properties.scenery.colour_1 & MAP_ELEM_SMALL_SCENERY_COLOUR_FLAG_NEEDS_SUPPORTS); - } - - void scenery_small_set_supports_needed(rct_tile_element * tileElement) - { - tileElement->properties.scenery.colour_1 |= MAP_ELEM_SMALL_SCENERY_COLOUR_FLAG_NEEDS_SUPPORTS; - } - - bool scenery_small_entry_has_flag(const rct_scenery_entry * sceneryEntry, uint32 flags) - { - return (bool)(sceneryEntry->small_scenery.flags & flags); - } + *ebx = SmallSceneryRemove( + *eax & 0xFFFF, + *ecx & 0xFFFF, + *edx & 0xFF, + ((*ebx >> 8) & 0xFF) >> 6, + (*edx >> 8) & 0xFF, + *ebx & 0xFF + ); } + +/** + * + * rct2: 0x006E0F26 + */ +void game_command_set_scenery_colour(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) +{ + *ebx = SmallScenerySetColour( + *eax & 0xFFFF, + *ecx & 0xFFFF, + *edx & 0xFF, + ((*ebx >> 8) & 0xFF) >> 6, + (*edx >> 8) & 0xFF, + *ebp & 0xFF, + (*ebp >> 8) & 0xFF, + *ebx & 0xFF + ); +} + +/** + * + * rct2: 0x006E0D6E, 0x006B8D88 + */ +sint32 map_place_scenery_clear_func(rct_tile_element** tile_element, sint32 x, sint32 y, uint8 flags, money32* price) +{ + if (tile_element_get_type(*tile_element) != TILE_ELEMENT_TYPE_SMALL_SCENERY) + return 1; + + if (!(flags & GAME_COMMAND_FLAG_PATH_SCENERY)) + return 1; + + rct_scenery_entry* scenery = get_small_scenery_entry((*tile_element)->properties.scenery.type); + + if (gParkFlags & PARK_FLAGS_FORBID_TREE_REMOVAL) + { + if (scenery->small_scenery.height > 64) + return 1; + } + + if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) + *price += scenery->small_scenery.removal_price * 10; + + if (flags & GAME_COMMAND_FLAG_GHOST) + return 0; + + if (!(flags & GAME_COMMAND_FLAG_APPLY)) + return 0; + + map_invalidate_tile(x, y, (*tile_element)->base_height * 8, (*tile_element)->clearance_height * 8); + + tile_element_remove(*tile_element); + + (*tile_element)--; + return 0; +} + +/** + * + * rct2: 0x006C5A4F, 0x006CDE57, 0x006A6733, 0x0066637E + */ +sint32 map_place_non_scenery_clear_func(rct_tile_element** tile_element, sint32 x, sint32 y, uint8 flags, money32* price) +{ + if (tile_element_get_type(*tile_element) != TILE_ELEMENT_TYPE_SMALL_SCENERY) + return 1; + + rct_scenery_entry* scenery = get_small_scenery_entry((*tile_element)->properties.scenery.type); + + if (gParkFlags & PARK_FLAGS_FORBID_TREE_REMOVAL) + { + if (scenery->small_scenery.height > 64) + return 1; + } + + if (!(gParkFlags & PARK_FLAGS_NO_MONEY)) + *price += scenery->small_scenery.removal_price * 10; + + if (flags & GAME_COMMAND_FLAG_GHOST) + return 0; + + if (!(flags & GAME_COMMAND_FLAG_APPLY)) + return 0; + + map_invalidate_tile(x, y, (*tile_element)->base_height * 8, (*tile_element)->clearance_height * 8); + + tile_element_remove(*tile_element); + + (*tile_element)--; + return 0; +} + +/** + * + * rct2: 0x006E08F4 + */ +void game_command_place_scenery(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp) +{ + *ebx = SmallSceneryPlace( + *eax & 0xFFFF, + *ecx & 0xFFFF, + *ebp & 0xFFFF, + *edx & 0xFF, + *edi & 0xFF, + (*ebx >> 8) & 0xFF, + (*edx >> 8) & 0xFF, + (*edi >> 16) & 0xFF, + *ebx & 0xFF + ); +} + +sint32 scenery_small_get_primary_colour(const rct_tile_element * tileElement) +{ + return tileElement->properties.scenery.colour_1 & TILE_ELEMENT_COLOUR_MASK; +} + +sint32 scenery_small_get_secondary_colour(const rct_tile_element * tileElement) +{ + return tileElement->properties.scenery.colour_2 & TILE_ELEMENT_COLOUR_MASK; +} + +void scenery_small_set_primary_colour(rct_tile_element * tileElement, uint32 colour) +{ + assert(colour <= 31); + tileElement->properties.scenery.colour_1 &= ~TILE_ELEMENT_COLOUR_MASK; + tileElement->properties.scenery.colour_1 |= colour; +} + +void scenery_small_set_secondary_colour(rct_tile_element * tileElement, uint32 colour) +{ + assert(colour <= 31); + tileElement->properties.scenery.colour_2 &= ~TILE_ELEMENT_COLOUR_MASK; + tileElement->properties.scenery.colour_2 |= colour; +} + +bool scenery_small_get_supports_needed(const rct_tile_element * tileElement) +{ + return (bool)(tileElement->properties.scenery.colour_1 & MAP_ELEM_SMALL_SCENERY_COLOUR_FLAG_NEEDS_SUPPORTS); +} + +void scenery_small_set_supports_needed(rct_tile_element * tileElement) +{ + tileElement->properties.scenery.colour_1 |= MAP_ELEM_SMALL_SCENERY_COLOUR_FLAG_NEEDS_SUPPORTS; +} + +bool scenery_small_entry_has_flag(const rct_scenery_entry * sceneryEntry, uint32 flags) +{ + return (bool)(sceneryEntry->small_scenery.flags & flags); +} + diff --git a/src/openrct2/world/SmallScenery.h b/src/openrct2/world/SmallScenery.h index f395a39c27..4c3b6d65e9 100644 --- a/src/openrct2/world/SmallScenery.h +++ b/src/openrct2/world/SmallScenery.h @@ -20,10 +20,6 @@ #include "Map.h" #include "Scenery.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef enum { SMALL_SCENERY_FLAG_FULL_TILE = (1 << 0), // 0x1 @@ -65,7 +61,3 @@ bool scenery_small_get_supports_needed(const rct_tile_element * tileElement); void scenery_small_set_supports_needed(rct_tile_element * tileElement); bool scenery_small_entry_has_flag(const rct_scenery_entry * sceneryEntry, uint32 flags); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 1e0dc29ec4..f87d6b1881 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -385,10 +385,6 @@ enum { LITTER_TYPE_EMPTY_BOWL_BLUE, }; -#ifdef __cplusplus -extern "C" { -#endif - rct_sprite *try_get_sprite(size_t spriteIndex); rct_sprite *get_sprite(size_t sprite_idx); @@ -462,9 +458,4 @@ sint32 check_for_sprite_list_cycles(bool fix); sint32 check_for_spatial_index_cycles(bool fix); sint32 fix_disjoint_sprites(); -#ifdef __cplusplus -} #endif - -#endif - diff --git a/src/openrct2/world/TileInspector.h b/src/openrct2/world/TileInspector.h index bf5753b526..09293727b2 100644 --- a/src/openrct2/world/TileInspector.h +++ b/src/openrct2/world/TileInspector.h @@ -54,10 +54,6 @@ typedef enum { TILE_INSPECTOR_CORRUPT_CLAMP, } tile_inspector_instruction; -#ifdef __cplusplus -extern "C" { -#endif - sint32 tile_inspector_insert_corrupt_at(sint32 x, sint32 y, sint16 elementIndex, sint32 flags); sint32 tile_inspector_remove_element_at(sint32 x, sint32 y, sint16 elementIndex, sint32 flags); sint32 tile_inspector_swap_elements_at(sint32 x, sint32 y, sint16 first, sint16 second, sint32 flags); @@ -77,7 +73,3 @@ sint32 tile_inspector_scenery_set_quarter_location(sint32 x, sint32 y, sint32 el sint32 tile_inspector_scenery_set_quarter_collision(sint32 x, sint32 y, sint32 elementIndex, sint32 quarterIndex, sint32 flags); sint32 tile_inspector_banner_toggle_blocking_edge(sint32 x, sint32 y, sint32 elementIndex, sint32 edgeIndex, sint32 flags); sint32 tile_inspector_corrupt_clamp(sint32 x, sint32 y, sint32 elementIndex, sint32 flags); - -#ifdef __cplusplus -} -#endif diff --git a/src/openrct2/world/Wall.cpp b/src/openrct2/world/Wall.cpp index 41e80d2a23..63b793d208 100644 --- a/src/openrct2/world/Wall.cpp +++ b/src/openrct2/world/Wall.cpp @@ -688,212 +688,210 @@ static money32 WallSetColour(sint16 x, return 0; } -extern "C" +uint8 wall_element_get_animation_frame(rct_tile_element * wallElement) { - uint8 wall_element_get_animation_frame(rct_tile_element * wallElement) + return (wallElement->properties.wall.animation >> 3) & 0xF; +} + +void wall_element_set_animation_frame(rct_tile_element * wallElement, uint8 frameNum) +{ + wallElement->properties.wall.animation &= WALL_ANIMATION_FLAG_ALL_FLAGS; + wallElement->properties.wall.animation |= (frameNum & 0xF) << 3; +} + +colour_t wall_get_primary_colour(const rct_tile_element * tileElement) +{ + return tileElement->properties.wall.colour_1 & TILE_ELEMENT_COLOUR_MASK; +} + +colour_t wall_get_secondary_colour(rct_tile_element * wallElement) +{ + uint8 secondaryColour = (wallElement->properties.wall.colour_1 &~ TILE_ELEMENT_COLOUR_MASK) >> 5; + secondaryColour |= (wallElement->flags & 0x60) >> 2; + return secondaryColour; +} + +colour_t wall_get_tertiary_colour(const rct_tile_element * tileElement) +{ + return tileElement->properties.wall.colour_3 & TILE_ELEMENT_COLOUR_MASK; +} + +void wall_set_primary_colour(rct_tile_element * tileElement, colour_t colour) +{ + assert(colour <= 31); + tileElement->properties.wall.colour_1 &= ~TILE_ELEMENT_COLOUR_MASK; + tileElement->properties.wall.colour_1 |= colour; +} + +void wall_set_secondary_colour(rct_tile_element * wallElement, colour_t secondaryColour) +{ + wallElement->properties.wall.colour_1 &= TILE_ELEMENT_COLOUR_MASK; + wallElement->properties.wall.colour_1 |= (secondaryColour & 0x7) << 5; + wallElement->flags &= ~0x60; + wallElement->flags |= (secondaryColour & 0x18) << 2; +} + +void wall_set_tertiary_colour(rct_tile_element * tileElement, colour_t colour) +{ + assert(colour <= 31); + tileElement->properties.wall.colour_3 &= ~TILE_ELEMENT_COLOUR_MASK; + tileElement->properties.wall.colour_3 |= colour; +} + +/** + * + * rct2: 0x006E588E + */ +void wall_remove_at(sint32 x, sint32 y, sint32 z0, sint32 z1) +{ + rct_tile_element * tileElement; + + z0 /= 8; + z1 /= 8; +repeat: + tileElement = map_get_first_element_at(x >> 5, y >> 5); + do { - return (wallElement->properties.wall.animation >> 3) & 0xF; - } + if (tile_element_get_type(tileElement) != TILE_ELEMENT_TYPE_WALL) + continue; + if (z0 >= tileElement->clearance_height) + continue; + if (z1 <= tileElement->base_height) + continue; - void wall_element_set_animation_frame(rct_tile_element * wallElement, uint8 frameNum) + tile_element_remove_banner_entry(tileElement); + map_invalidate_tile_zoom1(x, y, tileElement->base_height * 8, tileElement->base_height * 8 + 72); + tile_element_remove(tileElement); + goto repeat; + } + while (!tile_element_is_last_for_tile(tileElement++)); +} + +/** + * + * rct2: 0x006E57E6 + */ +void wall_remove_at_z(sint32 x, sint32 y, sint32 z) +{ + wall_remove_at(x, y, z, z + 48); +} + +/** + * + * rct2: 0x006E5935 + */ +void wall_remove_intersecting_walls(sint32 x, sint32 y, sint32 z0, sint32 z1, sint32 direction) +{ + rct_tile_element * tileElement; + + tileElement = map_get_first_element_at(x >> 5, y >> 5); + do { - wallElement->properties.wall.animation &= WALL_ANIMATION_FLAG_ALL_FLAGS; - wallElement->properties.wall.animation |= (frameNum & 0xF) << 3; + if (tile_element_get_type(tileElement) != TILE_ELEMENT_TYPE_WALL) + continue; + + if (tileElement->clearance_height <= z0 || tileElement->base_height >= z1) + continue; + + if (direction != tile_element_get_direction(tileElement)) + continue; + + tile_element_remove_banner_entry(tileElement); + map_invalidate_tile_zoom1(x, y, tileElement->base_height * 8, tileElement->base_height * 8 + 72); + tile_element_remove(tileElement); + tileElement--; } + while (!tile_element_is_last_for_tile(tileElement++)); +} - colour_t wall_get_primary_colour(const rct_tile_element * tileElement) - { - return tileElement->properties.wall.colour_1 & TILE_ELEMENT_COLOUR_MASK; - } +/** + * + * rct2: 0x006E519A + */ +void game_command_place_wall(sint32 * eax, + sint32 * ebx, + sint32 * ecx, + sint32 * edx, + sint32 * esi, + sint32 * edi, + sint32 * ebp) +{ + *ebx = WallPlace( + (*ebx >> 8) & 0xFF, + *eax & 0xFFFF, + *ecx & 0xFFFF, + *edi & 0xFFFF, + *edx & 0xFF, + (*edx >> 8) & 0xFF, + *ebp & 0xFF, + (*ebp >> 8) & 0xFF, + *ebx & 0xFF + ); +} - colour_t wall_get_secondary_colour(rct_tile_element * wallElement) - { - uint8 secondaryColour = (wallElement->properties.wall.colour_1 &~ TILE_ELEMENT_COLOUR_MASK) >> 5; - secondaryColour |= (wallElement->flags & 0x60) >> 2; - return secondaryColour; - } +money32 wall_place(sint32 type, + sint32 x, + sint32 y, + sint32 z, + sint32 edge, + sint32 primaryColour, + sint32 secondaryColour, + sint32 tertiaryColour, + sint32 flags) +{ + sint32 eax = x; + sint32 ebx = flags | (type << 8); + sint32 ecx = y; + sint32 edx = edge | (primaryColour << 8); + sint32 esi = 0; + sint32 edi = z; + sint32 ebp = secondaryColour | (tertiaryColour << 8); + game_command_place_wall(&eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + return ebx; +} - colour_t wall_get_tertiary_colour(const rct_tile_element * tileElement) - { - return tileElement->properties.wall.colour_3 & TILE_ELEMENT_COLOUR_MASK; - } +/** + * + * rct2: 0x006E5597 + */ +void game_command_remove_wall(sint32 * eax, + sint32 * ebx, + sint32 * ecx, + sint32 * edx, + sint32 * esi, + sint32 * edi, + sint32 * ebp) +{ + *ebx = WallRemove( + *eax & 0xFFFF, + *ecx & 0xFFFF, + (*edx >> 8) & 0xFF, + *edx & 0xFF, + *ebx & 0xFF + ); +} - void wall_set_primary_colour(rct_tile_element * tileElement, colour_t colour) - { - assert(colour <= 31); - tileElement->properties.wall.colour_1 &= ~TILE_ELEMENT_COLOUR_MASK; - tileElement->properties.wall.colour_1 |= colour; - } - - void wall_set_secondary_colour(rct_tile_element * wallElement, colour_t secondaryColour) - { - wallElement->properties.wall.colour_1 &= TILE_ELEMENT_COLOUR_MASK; - wallElement->properties.wall.colour_1 |= (secondaryColour & 0x7) << 5; - wallElement->flags &= ~0x60; - wallElement->flags |= (secondaryColour & 0x18) << 2; - } - - void wall_set_tertiary_colour(rct_tile_element * tileElement, colour_t colour) - { - assert(colour <= 31); - tileElement->properties.wall.colour_3 &= ~TILE_ELEMENT_COLOUR_MASK; - tileElement->properties.wall.colour_3 |= colour; - } - - /** - * - * rct2: 0x006E588E - */ - void wall_remove_at(sint32 x, sint32 y, sint32 z0, sint32 z1) - { - rct_tile_element * tileElement; - - z0 /= 8; - z1 /= 8; - repeat: - tileElement = map_get_first_element_at(x >> 5, y >> 5); - do - { - if (tile_element_get_type(tileElement) != TILE_ELEMENT_TYPE_WALL) - continue; - if (z0 >= tileElement->clearance_height) - continue; - if (z1 <= tileElement->base_height) - continue; - - tile_element_remove_banner_entry(tileElement); - map_invalidate_tile_zoom1(x, y, tileElement->base_height * 8, tileElement->base_height * 8 + 72); - tile_element_remove(tileElement); - goto repeat; - } - while (!tile_element_is_last_for_tile(tileElement++)); - } - - /** - * - * rct2: 0x006E57E6 - */ - void wall_remove_at_z(sint32 x, sint32 y, sint32 z) - { - wall_remove_at(x, y, z, z + 48); - } - - /** - * - * rct2: 0x006E5935 - */ - void wall_remove_intersecting_walls(sint32 x, sint32 y, sint32 z0, sint32 z1, sint32 direction) - { - rct_tile_element * tileElement; - - tileElement = map_get_first_element_at(x >> 5, y >> 5); - do - { - if (tile_element_get_type(tileElement) != TILE_ELEMENT_TYPE_WALL) - continue; - - if (tileElement->clearance_height <= z0 || tileElement->base_height >= z1) - continue; - - if (direction != tile_element_get_direction(tileElement)) - continue; - - tile_element_remove_banner_entry(tileElement); - map_invalidate_tile_zoom1(x, y, tileElement->base_height * 8, tileElement->base_height * 8 + 72); - tile_element_remove(tileElement); - tileElement--; - } - while (!tile_element_is_last_for_tile(tileElement++)); - } - - /** - * - * rct2: 0x006E519A - */ - void game_command_place_wall(sint32 * eax, - sint32 * ebx, - sint32 * ecx, - sint32 * edx, - sint32 * esi, - sint32 * edi, - sint32 * ebp) - { - *ebx = WallPlace( - (*ebx >> 8) & 0xFF, - *eax & 0xFFFF, - *ecx & 0xFFFF, - *edi & 0xFFFF, - *edx & 0xFF, - (*edx >> 8) & 0xFF, - *ebp & 0xFF, - (*ebp >> 8) & 0xFF, - *ebx & 0xFF - ); - } - - money32 wall_place(sint32 type, - sint32 x, - sint32 y, - sint32 z, - sint32 edge, - sint32 primaryColour, - sint32 secondaryColour, - sint32 tertiaryColour, - sint32 flags) - { - sint32 eax = x; - sint32 ebx = flags | (type << 8); - sint32 ecx = y; - sint32 edx = edge | (primaryColour << 8); - sint32 esi = 0; - sint32 edi = z; - sint32 ebp = secondaryColour | (tertiaryColour << 8); - game_command_place_wall(&eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - return ebx; - } - - /** - * - * rct2: 0x006E5597 - */ - void game_command_remove_wall(sint32 * eax, +/** + * + * rct2: 0x006E56B5 + */ +void game_command_set_wall_colour(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp) - { - *ebx = WallRemove( - *eax & 0xFFFF, - *ecx & 0xFFFF, - (*edx >> 8) & 0xFF, - *edx & 0xFF, - *ebx & 0xFF - ); - } - - /** - * - * rct2: 0x006E56B5 - */ - void game_command_set_wall_colour(sint32 * eax, - sint32 * ebx, - sint32 * ecx, - sint32 * edx, - sint32 * esi, - sint32 * edi, - sint32 * ebp) - { - *ebx = WallSetColour( - *eax & 0xFFFF, - *ecx & 0xFFFF, - (*edx >> 8) & 0xFF, - *edx & 0xFF, - (*ebx >> 8) & 0xFF, - *ebp & 0xFF, - (*ebp >> 8) & 0xFF, - *ebx & 0xFF - ); - } +{ + *ebx = WallSetColour( + *eax & 0xFFFF, + *ecx & 0xFFFF, + (*edx >> 8) & 0xFF, + *edx & 0xFF, + (*ebx >> 8) & 0xFF, + *ebp & 0xFF, + (*ebp >> 8) & 0xFF, + *ebx & 0xFF + ); } + diff --git a/src/openrct2/world/Wall.h b/src/openrct2/world/Wall.h index 49620320d5..a6863a8b3d 100644 --- a/src/openrct2/world/Wall.h +++ b/src/openrct2/world/Wall.h @@ -19,10 +19,6 @@ #include "../common.h" #include "Map.h" -#ifdef __cplusplus -extern "C" { -#endif - colour_t wall_get_primary_colour(const rct_tile_element * tileElement); colour_t wall_get_secondary_colour(rct_tile_element * wallElement); colour_t wall_get_tertiary_colour(const rct_tile_element * tileElement); @@ -30,6 +26,3 @@ void wall_set_primary_colour(rct_tile_element * tileElement, colour_t colour); void wall_set_secondary_colour(rct_tile_element * wallElement, colour_t secondaryColour); void wall_set_tertiary_colour(rct_tile_element * tileElement, colour_t colour); -#ifdef __cplusplus -} -#endif