From 5ceafd66a3f90bb8b7e91c91e47133c1163af1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 22 Sep 2015 19:02:39 +0200 Subject: [PATCH 1/6] Fix memory leak in screenshot.c and guest.c --- src/interface/screenshot.c | 26 ++++--- src/windows/guest.c | 136 +++++++++++++++++++------------------ 2 files changed, 86 insertions(+), 76 deletions(-) diff --git a/src/interface/screenshot.c b/src/interface/screenshot.c index 8e75f01b0a..be15586f89 100644 --- a/src/interface/screenshot.c +++ b/src/interface/screenshot.c @@ -8,12 +8,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * You should have received a copy of the GNU General Public License * along with this program. If not, see . *****************************************************************************/ @@ -38,7 +38,7 @@ static int screenshot_dump_bmp(); static int screenshot_dump_png(); /** - * + * * rct2: 0x006E3AEC */ void screenshot_check() @@ -133,7 +133,7 @@ typedef struct { } BitmapInfoHeader; /** - * + * * rct2: 0x00683D20 */ int screenshot_dump_bmp() @@ -176,7 +176,9 @@ int screenshot_dump_bmp() bytesWritten = SDL_RWwrite(fp, &header, sizeof(BitmapFileHeader), 1); if (bytesWritten != 1) { SDL_RWclose(fp); - free(buffer); + SafeFree(buffer); + log_error("failed to save screenshot"); + return -1; } // Info header @@ -193,7 +195,9 @@ int screenshot_dump_bmp() bytesWritten = SDL_RWwrite(fp, &info, sizeof(BitmapInfoHeader), 1); if (bytesWritten != 1) { SDL_RWclose(fp); - free(buffer); + SafeFree(buffer); + log_error("failed to save screenshot"); + return -1; } // Palette @@ -207,7 +211,9 @@ int screenshot_dump_bmp() bytesWritten = SDL_RWwrite(fp, buffer, sizeof(char), 246 * 4); if (bytesWritten != 246*4){ SDL_RWclose(fp); - free(buffer); + SafeFree(buffer); + log_error("failed to save screenshot"); + return -1; } // Image, save upside down @@ -221,7 +227,9 @@ int screenshot_dump_bmp() bytesWritten = SDL_RWwrite(fp, buffer, sizeof(char), stride); if (bytesWritten != stride){ SDL_RWclose(fp); - free(buffer); + SafeFree(buffer); + log_error("failed to save screenshot"); + return -1; } } @@ -451,7 +459,7 @@ int cmdline_for_screenshot(const char **argv, int argc) bool centreMapX = false; bool centreMapY = false; int resolutionWidth, resolutionHeight, customX, customY, customZoom, customRotation; - + const char *inputPath = argv[0]; const char *outputPath = argv[1]; if (giantScreenshot) { diff --git a/src/windows/guest.c b/src/windows/guest.c index 846a8a9d3d..0e538fc903 100644 --- a/src/windows/guest.c +++ b/src/windows/guest.c @@ -63,16 +63,16 @@ enum WINDOW_GUEST_WIDGET_IDX { WIDX_MARQUEE = 10, WIDX_VIEWPORT, - WIDX_ACTION_LBL, + WIDX_ACTION_LBL, WIDX_PICKUP, WIDX_RENAME, WIDX_LOCATE, WIDX_TRACK, - + WIDX_RIDE_SCROLL = 10 }; -rct_widget window_guest_overview_widgets[] = { +rct_widget window_guest_overview_widgets[] = { { WWT_FRAME, 0, 0, 191, 0, 156, 0x0FFFFFFFF, STR_NONE }, // Panel / Background { WWT_CAPTION, 0, 1, 190, 1, 14, 865, STR_WINDOW_TITLE_TIP }, // Title { WWT_CLOSEBOX, 0, 179, 189, 2, 13, 824, STR_CLOSE_WINDOW_TIP }, // Close x button @@ -482,7 +482,7 @@ uint32 window_guest_page_enabled_widgets[] = { * */ void window_guest_open(rct_peep* peep){ - + if (peep->type == PEEP_TYPE_STAFF){ window_staff_open(peep); return; @@ -512,22 +512,22 @@ void window_guest_open(rct_peep* peep){ window->viewport_focus_coordinates.y = -1; } - + window->page = 0; window_invalidate(window); - + window->widgets = window_guest_page_widgets[WINDOW_GUEST_OVERVIEW]; window->enabled_widgets = window_guest_page_enabled_widgets[WINDOW_GUEST_OVERVIEW]; window->hold_down_widgets = 0; window->event_handlers = window_guest_page_events[WINDOW_GUEST_OVERVIEW]; window->pressed_widgets = 0; - + window_guest_disable_widgets(window); window_init_scroll_widgets(window); window_guest_viewport_init(window); } -/* rct2: 0x006987A6 +/* rct2: 0x006987A6 * Disables the finance tab when no money. * Disables peep pickup when in certain no pickup states. */ @@ -552,10 +552,10 @@ void window_guest_disable_widgets(rct_window* w){ /* rct2: 0x00696A75 */ void window_guest_overview_close(rct_window *w) -{ +{ if (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_FLAGS, uint32) & INPUT_FLAG_TOOL_ACTIVE){ - if (w->classification == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS,rct_windowclass) && - w->number == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER,rct_windownumber)) + if (w->classification == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS,rct_windowclass) && + w->number == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER,rct_windownumber)) tool_cancel(); } } @@ -564,13 +564,13 @@ void window_guest_overview_close(rct_window *w) void window_guest_overview_resize(rct_window *w){ window_guest_disable_widgets(w); window_event_invalidate_call(w); - + widget_invalidate(w, WIDX_MARQUEE); - + window_set_resize(w, 192, 159, 500, 450); - + rct_viewport* view = w->viewport; - + if (view){ if ((w->width - 30) == view->width){ if ((w->height - 72) == view->height){ @@ -611,7 +611,7 @@ void window_guest_overview_mouse_up(rct_window *w, int widgetIndex) if (tool_set(w, widgetIndex, 7)) { return; } - + w->var_48C = peep->x; remove_peep_from_ride(peep); @@ -642,26 +642,26 @@ void window_guest_set_page(rct_window* w, int page){ if(w->number == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber) && w->classification == RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass)) tool_cancel(); - + } int listen = 0; if ( page == WINDOW_GUEST_OVERVIEW && w->page==WINDOW_GUEST_OVERVIEW && w->viewport){ if(!(w->viewport->flags & VIEWPORT_FLAG_SOUND_ON)) listen = 1; } - - + + w->page = page; w->frame_no = 0; w->no_list_items = 0; w->selected_list_item = -1; - + rct_viewport* viewport = w->viewport; w->viewport = 0; if (viewport){ viewport->width = 0; } - + w->enabled_widgets = window_guest_page_enabled_widgets[page]; w->hold_down_widgets = 0; w->event_handlers = window_guest_page_events[page]; @@ -673,7 +673,7 @@ void window_guest_set_page(rct_window* w, int page){ window_event_invalidate_call(w); window_init_scroll_widgets(w); window_invalidate(w); - + if (listen && w->viewport) w->viewport->flags |= VIEWPORT_FLAG_SOUND_ON; } @@ -692,7 +692,7 @@ void window_guest_viewport_init(rct_window* w){ } focus = { 0 }; //The focus will be either a sprite or a coordinate. focus.sprite.sprite_id = w->number; - + rct_peep* peep = GET_PEEP(w->number); if (peep->state == PEEP_STATE_PICKED){ @@ -700,8 +700,8 @@ void window_guest_viewport_init(rct_window* w){ } else{ uint8 final_check = 1; - if (peep->state == PEEP_STATE_ON_RIDE - || peep->state == PEEP_STATE_ENTERING_RIDE + if (peep->state == PEEP_STATE_ON_RIDE + || peep->state == PEEP_STATE_ENTERING_RIDE || (peep->state == PEEP_STATE_LEAVING_RIDE && peep->x == SPRITE_LOCATION_NULL)){ rct_ride* ride = &(RCT2_ADDRESS(RCT2_ADDRESS_RIDE_LIST, rct_ride)[peep->current_ride]); @@ -739,7 +739,7 @@ void window_guest_viewport_init(rct_window* w){ if (w->viewport){ //Check all combos, for now skipping y and rot - if (focus.coordinate.x == w->viewport_focus_coordinates.x && + if (focus.coordinate.x == w->viewport_focus_coordinates.x && focus.coordinate.y == w->viewport_focus_coordinates.y && focus.coordinate.z == w->viewport_focus_coordinates.z && focus.coordinate.rotation == w->viewport_focus_coordinates.rotation) @@ -785,58 +785,58 @@ void window_guest_viewport_init(rct_window* w){ } /** - * rct2: 0x6983dd + * rct2: 0x6983dd * used by window_staff as well */ void window_guest_overview_tab_paint(rct_window* w, rct_drawpixelinfo* dpi){ if (w->disabled_widgets & (1<widgets[WIDX_TAB_1]; int width = widget->right - widget->left - 1; int height = widget->bottom - widget->top - 1; int x = widget->left + 1 + w->x; int y = widget->top + 1 + w->y; if (w->page == WINDOW_GUEST_OVERVIEW) height++; - + rct_drawpixelinfo* clip_dpi = clip_drawpixelinfo(dpi, x, width, y, height ); if (!clip_dpi) return; - + x = 14; y = 20; - + rct_peep* peep = GET_PEEP(w->number); - + if (peep->type == PEEP_TYPE_STAFF && peep->staff_type == STAFF_TYPE_ENTERTAINER) y++; - + int ebx = *(RCT2_ADDRESS(0x982708, uint32*)[peep->sprite_type * 2]) + 1; - + int eax = 0; - + if (w->page == WINDOW_GUEST_OVERVIEW){ eax = w->var_494>>16; eax &= 0xFFFC; } ebx += eax; - + int sprite_id = ebx | (peep->tshirt_colour << 19) | (peep->trousers_colour << 24) | 0xA0000000; gfx_draw_sprite( clip_dpi, sprite_id, x, y, 0); - + // If holding a balloon if (ebx >= 0x2A1D && ebx < 0x2A3D){ ebx += 32; ebx |= (peep->balloon_colour << 19) | 0x20000000; gfx_draw_sprite( clip_dpi, ebx, x, y, 0); } - + // If holding umbrella if (ebx >= 0x2BBD && ebx < 0x2BDD){ ebx += 32; ebx |= (peep->umbrella_colour << 19) | 0x20000000; gfx_draw_sprite(clip_dpi, ebx, x, y, 0); } - + // If wearing hat if (ebx >= 0x29DD && ebx < 0x29FD){ ebx += 32; @@ -887,9 +887,9 @@ void window_guest_rides_tab_paint(rct_window* w, rct_drawpixelinfo* dpi){ int image_id = SPR_TAB_RIDE_0; if ( w->page == WINDOW_GUEST_RIDES ){ - image_id += (w->frame_no / 4) & 0xF; + image_id += (w->frame_no / 4) & 0xF; } - + gfx_draw_sprite(dpi, image_id, x, y, 0); } @@ -904,9 +904,9 @@ void window_guest_finance_tab_paint(rct_window* w, rct_drawpixelinfo* dpi){ int image_id = SPR_TAB_FINANCES_SUMMARY_0; if ( w->page == WINDOW_GUEST_FINANCE ){ - image_id += (w->frame_no / 2) & 0x7; + image_id += (w->frame_no / 2) & 0x7; } - + gfx_draw_sprite(dpi, image_id, x, y, 0); } @@ -921,9 +921,9 @@ void window_guest_thoughts_tab_paint(rct_window* w, rct_drawpixelinfo* dpi){ int image_id = 5269; if ( w->page == WINDOW_GUEST_THOUGHTS ){ - image_id += (w->frame_no / 2) & 0x7; + image_id += (w->frame_no / 2) & 0x7; } - + gfx_draw_sprite(dpi, image_id, x, y, 0); } @@ -936,7 +936,7 @@ void window_guest_inventory_tab_paint(rct_window* w, rct_drawpixelinfo* dpi){ int y = widget->top + w->y; int image_id = 5326; - + gfx_draw_sprite(dpi, image_id, x, y, 0); } @@ -985,6 +985,7 @@ void window_guest_overview_paint(rct_window *w, rct_drawpixelinfo *dpi) for (; i < PEEP_MAX_THOUGHTS; ++i){ if (peep->thoughts[i].type == PEEP_THOUGHT_TYPE_NONE){ w->list_information_type = 0; + rct2_free(dpi_marquee); return; } if (peep->thoughts[i].var_2 == 1){ // If a fresh thought @@ -993,6 +994,7 @@ void window_guest_overview_paint(rct_window *w, rct_drawpixelinfo *dpi) } if (i == PEEP_MAX_THOUGHTS){ w->list_information_type = 0; + rct2_free(dpi_marquee); return; } @@ -1012,32 +1014,32 @@ void window_guest_overview_paint(rct_window *w, rct_drawpixelinfo *dpi) void window_guest_overview_invalidate(rct_window *w) { colour_scheme_update(w); - + if (window_guest_page_widgets[w->page] != w->widgets){ w->widgets = window_guest_page_widgets[w->page]; window_init_scroll_widgets(w); } - + w->pressed_widgets &= ~(WIDX_TAB_1 | WIDX_TAB_2 |WIDX_TAB_3 |WIDX_TAB_4 |WIDX_TAB_5 |WIDX_TAB_6); w->pressed_widgets |= 1ULL << (w->page + WIDX_TAB_1); - + rct_peep* peep = GET_PEEP(w->number); RCT2_GLOBAL(0x13CE952,uint16) = peep->name_string_idx; RCT2_GLOBAL(0x13CE954,uint32) = peep->id; - + w->pressed_widgets &= ~(1<flags & 0x8){ w->pressed_widgets |= (1<width - 1; window_guest_overview_widgets[WIDX_BACKGROUND].bottom = w->height - 1; - + window_guest_overview_widgets[WIDX_PAGE_BACKGROUND].right =w->width - 1; window_guest_overview_widgets[WIDX_PAGE_BACKGROUND].bottom = w->height - 1; - + window_guest_overview_widgets[WIDX_TITLE].right = w->width - 2; - + window_guest_overview_widgets[WIDX_CLOSE].left = w->width - 13; window_guest_overview_widgets[WIDX_CLOSE].right = w->width - 3; @@ -1047,7 +1049,7 @@ void window_guest_overview_invalidate(rct_window *w) window_guest_overview_widgets[WIDX_ACTION_LBL].top = w->height - 12; window_guest_overview_widgets[WIDX_ACTION_LBL].bottom = w->height - 3; window_guest_overview_widgets[WIDX_ACTION_LBL].right = w->width - 24; - + window_guest_overview_widgets[WIDX_MARQUEE].right = w->width - 24; window_guest_overview_widgets[WIDX_PICKUP].right = w->width - 2; @@ -1059,7 +1061,7 @@ void window_guest_overview_invalidate(rct_window *w) window_guest_overview_widgets[WIDX_RENAME].left = w->width - 25; window_guest_overview_widgets[WIDX_LOCATE].left = w->width - 25; window_guest_overview_widgets[WIDX_TRACK].left = w->width - 25; - + window_align_tabs(w, WIDX_TAB_1, WIDX_TAB_6); } @@ -1073,7 +1075,7 @@ void window_guest_overview_update(rct_window* w){ widget_invalidate(w, WIDX_TAB_1); widget_invalidate(w, WIDX_TAB_2); - + w->list_information_type += 2; if ((w->var_494 & 0xFFFF) == 0xFFFF) @@ -1101,7 +1103,7 @@ void window_guest_overview_text_input(rct_window *w, int widgetIndex, char *text if (text == NULL) return; - + RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, uint16) = STR_CANT_NAME_GUEST; game_do_command(1, GAME_COMMAND_FLAG_APPLY, w->number, *((int*)(text + 0)), GAME_COMMAND_SET_PEEP_NAME, *((int*)(text + 8)), *((int*)(text + 4))); game_do_command(2, GAME_COMMAND_FLAG_APPLY, w->number, *((int*)(text + 12)), GAME_COMMAND_SET_PEEP_NAME, *((int*)(text + 20)), *((int*)(text + 16))); @@ -1143,7 +1145,7 @@ void window_guest_overview_tool_update(rct_window* w, int widgetIndex, int x, in RCT2_GLOBAL(RCT2_ADDRESS_PICKEDUP_PEEP_Y, uint16) = y; w->var_492++; if (w->var_492 >= 48)w->var_492 = 0; - + rct_peep* peep; peep = GET_PEEP(w->number); int ebx = (RCT2_ADDRESS(0x982708, uint32*)[peep->sprite_type * 2])[22]; @@ -1168,7 +1170,7 @@ void window_guest_overview_tool_down(rct_window* w, int widgetIndex, int x, int if (dest_x == (sint16)0x8000)return; - // Set the coordinate of destination to be exactly + // Set the coordinate of destination to be exactly // in the middle of a tile. dest_x += 16; dest_y += 16; @@ -1264,7 +1266,7 @@ void window_guest_stats_resize(rct_window *w) window_set_resize(w, 192, 162, 192, 162); } -/* rct2: 0x6974ED, 0x00697959, 0x00697C7B, 0x00697ED2, 0x00698333 +/* rct2: 0x6974ED, 0x00697959, 0x00697C7B, 0x00697ED2, 0x00698333 * This is a combination of 5 functions that were identical */ void window_guest_unknown_05(rct_window *w) @@ -1315,7 +1317,7 @@ void window_guest_stats_invalidate(rct_window *w) /** * * rct2: 0x0066ECC1 -* +* * ebp: colour, contains flag 0x80000000 for blinking */ void window_guest_stats_bars_paint(int value, int x, int y, rct_window *w, rct_drawpixelinfo *dpi, int colour){ @@ -1545,8 +1547,8 @@ void window_guest_rides_scroll_get_size(rct_window *w, int scrollIndex, int *wid window_invalidate(w); } - int visable_height = *height - - window_guest_rides_widgets[WIDX_RIDE_SCROLL].bottom + int visable_height = *height + - window_guest_rides_widgets[WIDX_RIDE_SCROLL].bottom + window_guest_rides_widgets[WIDX_RIDE_SCROLL].top + 21; @@ -1638,7 +1640,7 @@ void window_guest_rides_paint(rct_window *w, rct_drawpixelinfo *dpi) y = w->y + window_guest_rides_widgets[WIDX_PAGE_BACKGROUND].bottom - 12; - int ride_string_id = 3094; + int ride_string_id = 3094; int ride_string_arguments = 0; if (peep->favourite_ride != 0xFF){ rct_ride* ride = GET_RIDE(peep->favourite_ride); @@ -1886,7 +1888,7 @@ void window_guest_thoughts_paint(rct_window *w, rct_drawpixelinfo *dpi) RCT2_GLOBAL(0x13CE952, uint32) = argument1; RCT2_GLOBAL(0x13CE956, uint32) = argument2; - int width = window_guest_thoughts_widgets[WIDX_PAGE_BACKGROUND].right + int width = window_guest_thoughts_widgets[WIDX_PAGE_BACKGROUND].right - window_guest_thoughts_widgets[WIDX_PAGE_BACKGROUND].left - 8; @@ -2050,7 +2052,7 @@ void window_guest_inventory_paint(rct_window *w, rct_drawpixelinfo *dpi) for (int item = 0; item < SHOP_ITEM_COUNT; item++) { if (y >= maxY) break; if (!peep_has_item(peep, item)) continue; - + void *args = (void*)0x013CE952; rct_string_id stringId = window_guest_inventory_format_item(peep, item, (uint8*)args); y += gfx_draw_string_left_wrapped(dpi, args, x, y, itemNameWidth, stringId, 0); From cf7c827d0d5b3eae78aea19dca54ed252a05945e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 22 Sep 2015 19:03:44 +0200 Subject: [PATCH 2/6] Fix possible null dereference and resource leak --- src/title.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/title.c b/src/title.c index dd1874f8dc..f4d0d6de75 100644 --- a/src/title.c +++ b/src/title.c @@ -579,11 +579,11 @@ static uint8 *title_script_load() sprintf(path, "%s%c%s", gExePath, platform_get_path_separator(), filePath); log_verbose("loading title script, %s", path); file = SDL_RWFromFile(path, "r"); - sint64 fileSize = SDL_RWsize(file); if (file == NULL) { log_error("unable to load title script"); return NULL; } + sint64 fileSize = SDL_RWsize(file); uint8 *binaryScript = (uint8*)malloc(1024 * 8); if (binaryScript == NULL) { @@ -624,7 +624,8 @@ static uint8 *title_script_load() *scriptPtr++ = atoi(part1) & 0xFF; } else { log_error("unknown token, %s", token); - free(binaryScript); + SafeFree(binaryScript); + SDL_RWclose(file); return NULL; } } From 33d5e0b79f92518587a20ca826aa146bb7cddfe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 22 Sep 2015 19:05:00 +0200 Subject: [PATCH 3/6] fix loop counter --- src/platform/shared.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/platform/shared.c b/src/platform/shared.c index dc48f40c8c..3bb73a91ff 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (c) 2014 Ted John * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. - * + * * This file is part of OpenRCT2. - * + * * OpenRCT2 is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -117,7 +117,7 @@ void platform_update_fullscreen_resolutions() gNumResolutions = 0; for (i = 0; i < numDisplayModes; i++) { SDL_GetDisplayMode(displayIndex, i, &mode); - + aspectRatio = (float)mode.w / mode.h; if (gResolutionsAllowAnyAspectRatio || fabs(desktopAspectRatio - aspectRatio) < 0.0001f) { gResolutions[gNumResolutions].width = mode.w; @@ -198,7 +198,7 @@ void platform_draw() else if (pitch == (width * 2) + padding) { uint16 *dst = pixels; - for (int y = height; y > 0; y++) { + for (int y = height; y > 0; y--) { for (int x = width; x > 0; x--) { *dst++ = *(uint16 *)(&gPaletteHWMapped[*src++]); } dst = (uint16*)(((uint8 *)dst) + padding); } @@ -206,7 +206,7 @@ void platform_draw() else if (pitch == width + padding) { uint8 *dst = pixels; - for (int y = height; y > 0; y++) { + for (int y = height; y > 0; y--) { for (int x = width; x > 0; x--) { *dst++ = *(uint8 *)(&gPaletteHWMapped[*src++]); } dst += padding; } @@ -649,7 +649,7 @@ int platform_scancode_to_rct_keycode(int sdl_key) { char keycode = (char)SDL_GetKeyFromScancode((SDL_Scancode)sdl_key); - // Until we reshufle the text files to use the new positions + // Until we reshufle the text files to use the new positions // this will suffice to move the majority to the correct positions. // Note any special buttons PgUp PgDwn are mapped wrong. if (keycode >= 'a' && keycode <= 'z') @@ -804,7 +804,7 @@ void platform_refresh_video() { int width = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16); int height = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16); - + SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, gConfigGeneral.minimize_fullscreen_focus_loss ? "1" : "0"); if (gConfigGeneral.hardware_display) { @@ -826,7 +826,7 @@ void platform_refresh_video() pixelformat = format; } } - + gBufferTexture = SDL_CreateTexture(gRenderer, pixelformat, SDL_TEXTUREACCESS_STREAMING, width, height); Uint32 format; SDL_QueryTexture(gBufferTexture, &format, 0, 0, 0); From 8ec1054477a68c2ccfc808cfdfc965c23c15b4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 22 Sep 2015 19:06:42 +0200 Subject: [PATCH 4/6] add missing parntheses --- src/ride/ride.c | 182 ++++++++++++++++++++++++------------------------ 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/src/ride/ride.c b/src/ride/ride.c index 5ff8e7e958..e07840e230 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -8,12 +8,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * You should have received a copy of the GNU General Public License * along with this program. If not, see . *****************************************************************************/ @@ -286,7 +286,7 @@ money32 ride_calculate_income_per_hour(rct_ride *ride) } /** - * + * * rct2: 0x006CAF80 * ax result x * bx result y @@ -405,7 +405,7 @@ bool track_block_get_next_from_zero(sint16 x, sint16 y, sint16 z_start, uint8 ri } /** - * + * * rct2: 0x006C60C2 */ bool track_block_get_next(rct_xy_element *input, rct_xy_element *output, int *z, int *direction) @@ -461,9 +461,9 @@ bool track_block_get_next(rct_xy_element *input, rct_xy_element *output, int *z, return track_block_get_next_from_zero(x, y, OriginZ, rideIndex, directionStart, output, z, direction); } -/* rct2: 0x006C63D6 +/* rct2: 0x006C63D6 * Returns the begin position / direction and end position / direction of the track piece that procedes the given location. - * Gets the previous track block coordinates from the + * Gets the previous track block coordinates from the * coordinates of the first of element of a track block. * Use track_block_get_previous if you are unsure if you are * on the first element of a track block @@ -561,7 +561,7 @@ bool track_block_get_previous_from_zero(sint16 x, sint16 y, sint16 z, uint8 ride } /** - * + * * rct2: 0x006C6402 * * @remarks outTrackBeginEnd.begin_x and outTrackBeginEnd.begin_y will be in the higher two bytes of ecx and edx where as @@ -612,7 +612,7 @@ bool track_block_get_previous(int x, int y, rct_map_element *mapElement, track_b } /** - * + * * Make sure to pass in the x and y of the start track element too. * rct2: 0x006CB02F * ax result x @@ -631,7 +631,7 @@ int ride_find_track_gap(rct_xy_element *input, rct_xy_element *output) if (ride->type == RIDE_TYPE_MAZE) return 0; - + w = window_find_by_class(WC_RIDE_CONSTRUCTION); if (w != NULL && _rideConstructionState != RIDE_CONSTRUCTION_STATE_0 && _currentRideIndex == rideIndex) sub_6C9627(); @@ -652,7 +652,7 @@ int ride_find_track_gap(rct_xy_element *input, rct_xy_element *output) } /** - * + * * rct2: 0x006AF561 */ void ride_get_status(int rideIndex, int *formatSecondary, int *argument) @@ -726,7 +726,7 @@ int ride_can_have_multiple_circuits(rct_ride *ride) ) { return 0; } - + // Must have no more than one vehicle and one station if (ride->num_vehicles > 1 || ride->num_stations > 1) return 0; @@ -789,7 +789,7 @@ static int ride_check_if_construction_allowed(rct_ride *ride) if (ride->status != RIDE_STATUS_CLOSED) { RCT2_GLOBAL(0x013CE952 + 6, uint16) = ride->name; RCT2_GLOBAL(0x013CE952 + 8, uint32) = ride->name_arguments; - window_error_open(STR_CANT_START_CONSTRUCTION_ON, STR_MUST_BE_CLOSED_FIRST); + window_error_open(STR_CANT_START_CONSTRUCTION_ON, STR_MUST_BE_CLOSED_FIRST); return 0; } @@ -867,7 +867,7 @@ void ride_construct(int rideIndex) } /** - * + * * rct2: 0x006DD4D5 */ static void ride_remove_cable_lift(rct_ride *ride) @@ -888,7 +888,7 @@ static void ride_remove_cable_lift(rct_ride *ride) } /** - * + * * rct2: 0x006DD506 */ static void ride_remove_vehicles(rct_ride *ride) @@ -919,7 +919,7 @@ static void ride_remove_vehicles(rct_ride *ride) } /** - * + * * rct2: 0x006DD4AC */ void ride_clear_for_construction(int rideIndex) @@ -930,7 +930,7 @@ void ride_clear_for_construction(int rideIndex) ride = GET_RIDE(rideIndex); ride_measurement_clear(ride); - + ride->lifecycle_flags &= ~(RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN); ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST; @@ -943,7 +943,7 @@ void ride_clear_for_construction(int rideIndex) } /** - * + * * rct2: 0x006664DF */ void ride_remove_peeps(int rideIndex) @@ -1020,7 +1020,7 @@ void ride_remove_peeps(int rideIndex) invalidate_sprite_2((rct_sprite*)peep); peep->state = PEEP_STATE_FALLING; sub_693BE5(peep, 0); - + peep->happiness = min(peep->happiness, peep->happiness_growth_rate) / 2; peep->happiness_growth_rate = peep->happiness; peep->window_invalidate_flags |= PEEP_INVALIDATE_PEEP_STATS; @@ -1034,7 +1034,7 @@ void ride_remove_peeps(int rideIndex) /** * Gets the origin track element (sequence 0). Seems to do more than that though and even invalidates track. - * rct2: 0x006C683D + * rct2: 0x006C683D * ax : x * bx : direction << 8, type * cx : y @@ -1178,7 +1178,7 @@ int sub_6C683D(int* x, int* y, int* z, int direction, int type, uint16 extra_par } /** - * + * * rct2: 0x006C96C0 */ void sub_6C96C0() @@ -1203,7 +1203,7 @@ void sub_6C96C0() rideIndex = _currentRideIndex; RCT2_GLOBAL(0x00F441D2, uint8) = rideIndex; - + x = RCT2_GLOBAL(0x00F440C5, uint16); y = RCT2_GLOBAL(0x00F440C7, uint16); z = RCT2_GLOBAL(0x00F440C9, uint16); @@ -1221,7 +1221,7 @@ void sub_6C96C0() y -= TileDirectionDelta[direction].y; } rct_xy_element next_track; - + if (track_block_get_next_from_zero(x, y, z, rideIndex, direction, &next_track, &z, &direction)) { game_do_command( next_track.x, @@ -1280,7 +1280,7 @@ void sub_6C9627() } /** - * + * * rct2: 0x006C9B19 */ static void ride_construction_reset_current_piece() @@ -1306,7 +1306,7 @@ static void ride_construction_reset_current_piece() } /** - * + * * rct2: 0x006C9800 */ void ride_construction_set_default_next_piece() @@ -1432,7 +1432,7 @@ void ride_construction_set_default_next_piece() } /** - * + * * rct2: 0x006C9296 */ void ride_select_next_section() @@ -1490,7 +1490,7 @@ void ride_select_next_section() } /** - * + * * rct2: 0x006C93B8 */ void ride_select_previous_section() @@ -1540,7 +1540,7 @@ void ride_select_previous_section() } /** - * + * * rct2: 0x006CC2CA */ static int ride_modify_entrance_or_exit(rct_map_element *mapElement, int x, int y) @@ -1592,13 +1592,13 @@ static int ride_modify_entrance_or_exit(rct_map_element *mapElement, int x, int RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WIDGETINDEX, uint16) = entranceType == ENTRANCE_TYPE_RIDE_ENTRANCE ? 29 : 30; RCT2_GLOBAL(0x00F44191, uint8) = entranceType; } - + window_invalidate_by_class(WC_RIDE_CONSTRUCTION); return 1; } /** - * + * * rct2: 0x006CC287 */ int ride_modify_maze(rct_map_element *mapElement, int x, int y) @@ -1615,7 +1615,7 @@ int ride_modify_maze(rct_map_element *mapElement, int x, int y) } /** - * + * * rct2: 0x006CC056 */ int ride_modify(rct_xy_element *input) @@ -1661,7 +1661,7 @@ int ride_modify(rct_xy_element *input) z = mapElement.element->base_height * 8; direction = mapElement.element->type & 3; type = mapElement.element->properties.track.type; - + if (sub_6C683D(&x, &y, &z, direction, type, 0, NULL, 0)) return 0; @@ -1713,7 +1713,7 @@ int ride_modify(rct_xy_element *input) } /** - * + * * rct2: 0x006CC3FB */ int sub_6CC3FB(int rideIndex) @@ -1799,7 +1799,7 @@ static void ride_update(int rideIndex) { int i; rct_ride *ride = GET_RIDE(rideIndex); - + if (ride->var_1CA != 0) ride->var_1CA--; @@ -2066,7 +2066,7 @@ static void ride_breakdown_update(int rideIndex) return; if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_TRACK_DESIGNER) return; - + if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_CRASHED)) ride->var_19C++; @@ -2131,7 +2131,7 @@ static int ride_get_new_breakdown_problem(rct_ride *ride) entry = ride_get_entry(ride); if (entry->flags & RIDE_ENTRY_FLAG_14) return -1; - + availableBreakdownProblems = RideAvailableBreakdowns[ride->type]; // Calculate the total probability range for all possible breakdown problems @@ -2198,7 +2198,7 @@ void ride_prepare_breakdown(int rideIndex, int breakdownReason) ride->mechanic_status = RIDE_MECHANIC_STATUS_UNDEFINED; ride->var_1AC = 0; ride->var_1AD = 0; - + switch (breakdownReason) { case BREAKDOWN_SAFETY_CUT_OUT: case BREAKDOWN_CONTROL_FAILURE: @@ -2303,7 +2303,7 @@ static void ride_mechanic_status_update(int rideIndex, int mechanicStatus) int breakdownReason; rct_ride *ride; rct_peep *mechanic; - + ride = GET_RIDE(rideIndex); switch (mechanicStatus) { case RIDE_MECHANIC_STATUS_UNDEFINED: @@ -2402,7 +2402,7 @@ rct_peep *ride_find_closest_mechanic(rct_ride *ride, int forInspection) int x, y, z, stationIndex, direction; uint16 xy; rct_map_element *mapElement; - + // Get either exit position or entrance position if there is no exit stationIndex = ride->inspection_station; xy = ride->exits[stationIndex]; @@ -2441,7 +2441,7 @@ rct_peep *find_closest_mechanic(int x, int y, int forInspection) unsigned int closestDistance, distance; uint16 spriteIndex; rct_peep *peep, *closestMechanic = NULL; - + closestDistance = -1; FOR_ALL_STAFF(spriteIndex, peep) { if (peep->staff_type != STAFF_TYPE_MECHANIC) @@ -2465,7 +2465,7 @@ rct_peep *find_closest_mechanic(int x, int y, int forInspection) if (map_is_location_in_park(x, y)) if (!mechanic_is_location_in_patrol(peep, x & 0xFFE0, y & 0xFFE0)) continue; - + if (peep->x == (sint16)0x8000) continue; @@ -2572,7 +2572,7 @@ static void ride_music_update(int rideIndex) } } - // Oscillate parameters for a power cut effect when breaking down + // Oscillate parameters for a power cut effect when breaking down if (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)) { if (ride->breakdown_reason_pending == BREAKDOWN_CONTROL_FAILURE) { if (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TICKS, uint32) & 7)) @@ -2788,7 +2788,7 @@ int ride_get_free_measurement() } /** - * + * * rct2: 0x006B66D9 */ rct_ride_measurement *ride_get_measurement(int rideIndex, rct_string_id *message) @@ -2830,7 +2830,7 @@ rct_ride_measurement *ride_get_measurement(int rideIndex, rct_string_id *message } else { measurement = GET_RIDE_MEASUREMENT(i); } - + measurement->ride_index = rideIndex; ride->measurement_index = i; measurement->flags = 0; @@ -2938,8 +2938,8 @@ void ride_check_all_reachable() { rct_ride *ride; int i; - - FOR_ALL_RIDES(i, ride) { + + FOR_ALL_RIDES(i, ride) { if (ride->connected_message_throttle != 0) ride->connected_message_throttle--; if (ride->status != RIDE_STATUS_OPEN || ride->connected_message_throttle != 0) @@ -2999,11 +2999,11 @@ static void ride_entrance_exit_connected(rct_ride* ride, int ride_idx) if (entrance != 0xFFFF && !ride_entrance_exit_is_reachable(entrance, ride, i)) { // name of ride is parameter of the format string RCT2_GLOBAL(0x013CE952, uint16) = ride->name; - RCT2_GLOBAL(0x013CE954, uint32) = ride->name_arguments; + RCT2_GLOBAL(0x013CE954, uint32) = ride->name_arguments; news_item_add_to_queue(1, STR_ENTRANCE_NOT_CONNECTED, ride_idx); ride->connected_message_throttle = 3; } - + if (exit != 0xFFFF && !ride_entrance_exit_is_reachable(exit, ride, i)) { // name of ride is parameter of the format string RCT2_GLOBAL(0x013CE952, uint16) = ride->name; @@ -3012,7 +3012,7 @@ static void ride_entrance_exit_connected(rct_ride* ride, int ride_idx) ride->connected_message_throttle = 3; } - } + } } static void ride_shop_connected(rct_ride* ride, int ride_idx) @@ -3026,7 +3026,7 @@ static void ride_shop_connected(rct_ride* ride, int ride_idx) x = (coordinate & 0xFF); y = (coordinate >> 8) & 0xFF; - + mapElement = map_get_first_element_at(x, y); do { if (map_element_get_type(mapElement) == MAP_ELEMENT_TYPE_TRACK && mapElement->properties.track.ride_index == ride_idx) @@ -3191,7 +3191,7 @@ void ride_set_map_tooltip(rct_map_element *mapElement) } /** - * + * * rct2: 0x006BC3AC * Update ride music parameters * @param x (ax) @@ -3638,7 +3638,7 @@ void ride_music_update_final() void game_command_set_ride_setting(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp) { RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) = RCT_EXPENDITURE_TYPE_RIDE_RUNNING_COSTS * 4; - + uint8 ride_id = *edx & 0xFF; rct_ride* ride = GET_RIDE(ride_id); @@ -3752,7 +3752,7 @@ void game_command_set_ride_setting(int *eax, int *ebx, int *ecx, int *edx, int * } /** - * + * * rct2: 0x006B4CC1 */ int ride_mode_check_valid_station_numbers(rct_ride *ride) @@ -3813,7 +3813,7 @@ int ride_mode_check_station_present(rct_ride* ride){ } /** - * + * * rct2: 0x006B5872 */ int ride_check_for_entrance_exit(int rideIndex) @@ -3833,11 +3833,11 @@ int ride_check_for_entrance_exit(int rideIndex) if (ride->entrances[i] != 0xFFFF) { entrance = 1; } - + if (ride->exits[i] != 0xFFFF) { exit = 1; } - + // If station start and no entrance/exit // Sets same error message as no entrance if (ride->exits[i] == 0xFFFF && ride->entrances[i] == 0xFFFF){ @@ -3860,7 +3860,7 @@ int ride_check_for_entrance_exit(int rideIndex) } /** - * + * * rct2: 0x006B5952 */ void sub_6B5952(int rideIndex) @@ -3890,7 +3890,7 @@ void sub_6B5952(int rideIndex) } /** - * + * * rct2: 0x006D3319 */ int ride_check_block_brakes(rct_xy_element *input, rct_xy_element *output) @@ -4006,13 +4006,13 @@ bool ride_check_track_contains_banked(rct_xy_element *input, rct_xy_element *out } /** - * + * * rct2: 0x006CB25D */ int ride_check_station_length(rct_xy_element *input, rct_xy_element *output) { rct_window* w = window_find_by_class(WC_RIDE_CONSTRUCTION); - if (w != 0 && + if (w != 0 && _rideConstructionState != RIDE_CONSTRUCTION_STATE_0 && _currentRideIndex == input->element->properties.track.ride_index){ sub_6C9627(); @@ -4055,7 +4055,7 @@ int ride_check_station_length(rct_xy_element *input, rct_xy_element *output) } /** - * + * * rct2: 0x006CB2DA */ bool ride_check_start_and_end_is_station(rct_xy_element *input, rct_xy_element *output) @@ -4128,7 +4128,7 @@ void ride_set_boat_hire_return_point(rct_ride *ride, rct_xy_element *startElemen } /** - * + * * rct2: 0x006B4D39 */ static void ride_set_maze_entrance_exit_points(rct_ride *ride) @@ -4334,7 +4334,7 @@ static bool sub_6D31A6(rct_ride *ride, bool isApplying) } /** - * + * * rct2: 0x006DF4D4 */ bool ride_create_cable_lift(int rideIndex, bool isApplying) @@ -4408,7 +4408,7 @@ bool ride_create_cable_lift(int rideIndex, bool isApplying) } /** - * + * * rct2: 0x006B51C0 */ void loc_6B51C0(int rideIndex) @@ -4463,7 +4463,7 @@ void loc_6B51C0(int rideIndex) } /** - * + * * rct2: 0x006B528A */ void loc_6B528A(rct_xy_element *trackElement) @@ -4485,7 +4485,7 @@ void loc_6B528A(rct_xy_element *trackElement) } /** - * + * * rct2: 0x006B4F6B */ rct_map_element *loc_6B4F6B(int rideIndex, int x, int y) @@ -4509,7 +4509,7 @@ rct_map_element *loc_6B4F6B(int rideIndex, int x, int y) if (mapElement->properties.track.ride_index == rideIndex) return mapElement; } while (!map_element_is_last_for_tile(mapElement++)); - + return NULL; } @@ -4633,7 +4633,7 @@ int ride_is_valid_for_test(int rideIndex, int goingToBeOpen, int isApplying) return 1; } /** - * + * * rct2: 0x006B4EEA */ int ride_is_valid_for_open(int rideIndex, int goingToBeOpen, int isApplying) @@ -4661,7 +4661,7 @@ int ride_is_valid_for_open(int rideIndex, int goingToBeOpen, int isApplying) sub_6B5952(rideIndex); ride->lifecycle_flags |= RIDE_LIFECYCLE_EVER_BEEN_OPENED; } - + // z = ride->station_heights[i] * 8; trackElement.x = (ride->station_starts[stationIndex] & 0xFF) * 32; trackElement.y = (ride->station_starts[stationIndex] >> 8) * 32; @@ -4762,7 +4762,7 @@ void ride_set_status(int rideIndex, int status) } /** - * + * * rct2: 0x006B4EA6 */ void game_command_set_ride_status(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp) @@ -4788,7 +4788,7 @@ void game_command_set_ride_status(int *eax, int *ebx, int *ecx, int *edx, int *e ride_remove_peeps(rideIndex); } } - + ride->status = RIDE_STATUS_CLOSED; ride->lifecycle_flags &= ~RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING; ride->race_winner = 0xFFFF; @@ -4836,7 +4836,7 @@ void ride_set_name(int rideIndex, const char *name) } /** - * + * * rct2: 0x006B578B */ void game_command_set_ride_name(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp) @@ -4905,7 +4905,7 @@ void game_command_set_ride_name(int *eax, int *ebx, int *ecx, int *edx, int *esi } /** - * + * * rct2: 0x006CB7FB */ int ride_get_refund_price(int ride_id) @@ -4985,7 +4985,7 @@ int ride_get_refund_price(int ride_id) } /** - * + * * rct2: 0x00696707 */ static void ride_stop_peeps_queuing(int rideIndex) @@ -5067,7 +5067,7 @@ static bool ride_name_exists(char *name) } /** - * + * * rct2: 0x006B4776 */ static void ride_set_to_random_colour_preset(rct_ride *ride) @@ -5140,7 +5140,7 @@ static bool shop_item_has_common_price(int shopItem) } /** - * + * * rct2: 0x006B3F0F */ money32 ride_create(int type, int subType, int flags, int *outRideIndex) @@ -5269,7 +5269,7 @@ foundRideEntry: ride->var_120 = 0; ride->var_122 = 0; ride->var_148 = 0; - + ride->price = 0; ride->price_secondary = 0; if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) { @@ -5286,7 +5286,7 @@ foundRideEntry: if (rideEntry->shop_item_secondary != 255) { ride->price_secondary = DefaultShopItemPrice[rideEntry->shop_item_secondary]; } - + if (RCT2_GLOBAL(RCT2_ADDRESS_OBJECTIVE_TYPE, uint8) == OBJECTIVE_BUILD_THE_BEST) { ride->price = 0; } @@ -5331,7 +5331,7 @@ foundRideEntry: ride->running_cost = 0; ride->var_134 = 0; ride->var_136 = 0; - + ride->value = 0xFFFF; ride->satisfaction = 255; ride->satisfaction_time_out = 0; @@ -5379,7 +5379,7 @@ foundRideEntry: } /** - * + * * rct2: 0x006B3F0F */ void game_command_create_ride(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp) @@ -5395,7 +5395,7 @@ void game_command_callback_ride_construct_new(int eax, int ebx, int ecx, int edx } /** - * + * * rct2: 0x006B49D9 */ void game_command_demolish_ride(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp) @@ -5440,7 +5440,7 @@ void game_command_demolish_ride(int *eax, int *ebx, int *ecx, int *edx, int *esi sub_6CB945(ride_id); news_item_disable_news(NEWS_ITEM_RIDE, ride_id); - + for(int i = 0; i < MAX_BANNERS; i++){ rct_banner *banner = &gBanners[i]; if(banner->type != BANNER_NULL && banner->flags & BANNER_FLAG_2 && banner->colour == ride_id){ @@ -5450,7 +5450,7 @@ void game_command_demolish_ride(int *eax, int *ebx, int *ecx, int *edx, int *esi } uint16 spriteIndex; - rct_peep *peep; + rct_peep *peep; FOR_ALL_GUESTS(spriteIndex, peep){ uint8 ride_id_bit = ride_id & 0x3; uint8 ride_id_offset = ride_id / 8; @@ -5523,7 +5523,7 @@ void game_command_demolish_ride(int *eax, int *ebx, int *ecx, int *edx, int *esi } /** - * + * * rct2: 0x006B2FC5 */ void game_command_set_ride_appearance(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp) @@ -5580,7 +5580,7 @@ void game_command_set_ride_appearance(int *eax, int *ebx, int *ecx, int *edx, in } /** - * + * * rct2: 0x006B53E9 */ void game_command_set_ride_price(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp) @@ -5591,7 +5591,7 @@ void game_command_set_ride_price(int *eax, int *ebx, int *ecx, int *edx, int *es rct_ride *ride; rct_ride_type *ride_type; bool secondary_price; - + flags = *ebx; ride_number = (*edx & 0xFF); ride = GET_RIDE(ride_number); @@ -5944,7 +5944,7 @@ int loc_6CD18E(short mapX, short mapY, short entranceMinX, short entranceMinY, s } /** - * + * * rct2: 0x006CCF70 */ void ride_get_entrance_or_exit_position_from_screen_position(int screenX, int screenY, int *outX, int *outY, int *outDirection) @@ -6025,7 +6025,7 @@ void ride_get_entrance_or_exit_position_from_screen_position(int screenX, int sc } if (map_get_station(mapElement) != RCT2_GLOBAL(0x00F44193, uint8)) continue; - + int ebx = (mapElement->properties.track.type << 4) + (mapElement->properties.track.sequence & 0x0F); int eax = (direction + 2 - mapElement->type) & MAP_ELEMENT_DIRECTION_MASK; if (RCT2_ADDRESS(0x0099CA64, uint8)[ebx] & (1 << eax)) { @@ -6154,7 +6154,7 @@ bool ride_are_all_possible_entrances_and_exits_built(rct_ride *ride) { if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_IS_SHOP)) return true; - + for (int i = 0; i < 4; i++) { if (ride->station_starts[i] == 0xFFFF) continue; if (ride->entrances[i] == 0xFFFF) { @@ -6273,14 +6273,14 @@ static void ride_update_vehicle_colours(int rideIndex) } /** - * + * * rct2: 0x006DE4CD * trainLayout: Originally fixed to 0x00F64E38. This no longer postfixes with 255. */ void ride_entry_get_train_layout(int rideEntryIndex, int numCarsPerTrain, uint8 *trainLayout) { rct_ride_type *rideEntry = GET_RIDE_ENTRY(rideEntryIndex); - + for (int i = 0; i < numCarsPerTrain; i++) { uint8 vehicleType = rideEntry->default_vehicle; if (i == 0 && rideEntry->front_vehicle != 255) { @@ -6333,7 +6333,7 @@ static int ride_get_track_length(rct_ride *ride) continue; trackType = mapElement->properties.track.type; - if (!RCT2_GLOBAL(0x0099BA64 + (trackType * 16), uint32) & 0x10) + if (!(RCT2_GLOBAL(0x0099BA64 + (trackType * 16), uint32) & 0x10)) continue; if (mapElement->base_height != z) From a3d407079f50d76d92891076e9e41a85e039146c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 22 Sep 2015 19:18:57 +0200 Subject: [PATCH 5/6] fix windows position clamping --- src/interface/window.c | 82 +++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/interface/window.c b/src/interface/window.c index db2b98c60b..3e9b3e3a0e 100644 --- a/src/interface/window.c +++ b/src/interface/window.c @@ -142,7 +142,7 @@ rct_widget *window_get_scroll_widget(rct_window *w, int scrollIndex) } /** - * + * * rct2: 0x006ED7B0 */ void window_dispatch_update_all() @@ -165,7 +165,7 @@ void window_update_all_viewports() } /** - * + * * rct2: 0x006E77A1 */ void window_update_all() @@ -201,7 +201,7 @@ void window_update_all() } /** - * + * * rct2: 0x006E78E3 */ static void window_scroll_wheel_input(rct_window *w, int scrollIndex, int wheel) @@ -209,7 +209,7 @@ static void window_scroll_wheel_input(rct_window *w, int scrollIndex, int wheel) int widgetIndex, size; rct_scroll *scroll; rct_widget *widget; - + scroll = &w->scrolls[scrollIndex]; widget = window_get_scroll_widget(w, scrollIndex); widgetIndex = window_get_widget_index(w, widget); @@ -233,7 +233,7 @@ static void window_scroll_wheel_input(rct_window *w, int scrollIndex, int wheel) } /** - * + * * rct2: 0x006E793B */ static int window_wheel_input(rct_window *w, int wheel) @@ -260,7 +260,7 @@ static int window_wheel_input(rct_window *w, int wheel) } /** - * + * * rct2: 0x006E79FB */ static void window_viewport_wheel_input(rct_window *w, int wheel) @@ -275,7 +275,7 @@ static void window_viewport_wheel_input(rct_window *w, int wheel) } /** - * + * * rct2: 0x006E7868 */ static void window_all_wheel_input() @@ -328,7 +328,7 @@ static void window_all_wheel_input() return; } } - + // Check other scroll views on window if (window_wheel_input(w, wheel)) return; @@ -430,7 +430,7 @@ rct_window *window_create(int x, int y, int width, int height, rct_window_event_ } /** - * + * * rct2: 0x006EA934 * * @param x (dx) @@ -455,7 +455,7 @@ static bool sub_6EA8EC(int x, int y, int width, int height) } /** - * + * * rct2: 0x006EA934 * * @param x (dx) @@ -473,7 +473,7 @@ static bool sub_6EA934(int x, int y, int width, int height) } /** - * + * * rct2: 0x006EA934 * * @param x (dx) @@ -624,7 +624,7 @@ rct_window *window_create_auto_pos(int width, int height, rct_window_event_list // Clamp to inside the screen foundSpace: if (x < 0) - x = x; + x = 0; if (x + width > screenWidth) x = screenWidth - width; @@ -708,7 +708,7 @@ void window_close_by_class(rct_windowclass cls) void window_close_by_number(rct_windowclass cls, rct_windownumber number) { rct_window* w; - + for (w = g_window_list; w < RCT2_NEW_WINDOW; w++) { if (w->classification == cls && w->number == number) { window_close(w); @@ -744,7 +744,7 @@ rct_window *window_find_by_class(rct_windowclass cls) rct_window *window_find_by_number(rct_windowclass cls, rct_windownumber number) { rct_window *w; - + for (w = g_window_list; w < RCT2_NEW_WINDOW; w++) if (w->classification == cls && w->number == number) return w; @@ -807,7 +807,7 @@ void window_close_all_except_class(rct_windowclass cls) { } /** - * + * * rct2: 0x006EA845 */ rct_window *window_find_from_point(int x, int y) @@ -827,7 +827,7 @@ rct_window *window_find_from_point(int x, int y) widget = &w->widgets[widget_index]; } - + return w; } @@ -835,7 +835,7 @@ rct_window *window_find_from_point(int x, int y) } /** - * + * * rct2: 0x006EA594 * x (ax) * y (bx) @@ -953,7 +953,7 @@ void widget_invalidate(rct_window *w, int widgetIndex) void widget_invalidate_by_class(rct_windowclass cls, int widgetIndex) { rct_window* w; - + for (w = g_window_list; w < RCT2_NEW_WINDOW; w++) if (w->classification == cls) widget_invalidate(w, widgetIndex); @@ -969,7 +969,7 @@ void widget_invalidate_by_class(rct_windowclass cls, int widgetIndex) void widget_invalidate_by_number(rct_windowclass cls, rct_windownumber number, int widgetIndex) { rct_window* w; - + for (w = g_window_list; w < RCT2_NEW_WINDOW; w++) if (w->classification == cls && w->number == number) widget_invalidate(w, widgetIndex); @@ -1019,7 +1019,7 @@ void window_init_scroll_widgets(rct_window *w) } /** - * + * * rct2: 0x006EAE4E * * @param w The window (esi). @@ -1081,7 +1081,7 @@ int window_get_scroll_data_index(rct_window *w, int widget_index) } /** - * + * * rct2: 0x006ECDA4 */ rct_window *window_bring_to_front(rct_window *w) @@ -1133,7 +1133,7 @@ rct_window *window_bring_to_front_by_class(rct_windowclass cls) } /** - * + * * rct2: 0x006ED78A * cls (cl) * number (dx) @@ -1184,7 +1184,7 @@ void window_push_others_right(rct_window* window) } /** - * + * * rct2: 0x006EE6EA */ void window_push_others_below(rct_window *w1) @@ -1228,13 +1228,13 @@ void window_push_others_below(rct_window *w1) /** - * + * * rct2: 0x006EE2E4 */ rct_window *window_get_main() { rct_window* w; - + for (w = g_window_list; w < RCT2_NEW_WINDOW; w++) if (w->classification == WC_MAIN_WINDOW) return w; @@ -1243,9 +1243,9 @@ rct_window *window_get_main() } /** - * Based on + * Based on * rct2: 0x696ee9 & 0x66842F & 0x006AF3B3 - * + * */ void window_scroll_to_viewport(rct_window *w) { @@ -1345,7 +1345,7 @@ void window_scroll_to_location(rct_window *w, int x, int y, int z) } /** - * + * * rct2: 0x00688956 */ void sub_688956() @@ -1357,7 +1357,7 @@ void sub_688956() } /** - * + * * rct2: 0x0068881A * direction can be used to alter the camera rotation: * 1: clockwise @@ -1438,7 +1438,7 @@ void window_zoom_set(rct_window *w, int zoomLevel) } /** - * + * * rct2: 0x006887A6 */ void window_zoom_in(rct_window *w) @@ -1447,7 +1447,7 @@ void window_zoom_in(rct_window *w) } /** - * + * * rct2: 0x006887E0 */ void window_zoom_out(rct_window *w) @@ -1456,7 +1456,7 @@ void window_zoom_out(rct_window *w) } /** - * + * * rct2: 0x006EE308 * DEPRECIATED please use the new text_input window. */ @@ -1602,7 +1602,7 @@ static int window_draw_split(rct_window *w, int left, int top, int right, int bo } /** - * + * * rct2: 0x006EB15C * * @param window (esi) @@ -1636,7 +1636,7 @@ void window_draw_widgets(rct_window *w, rct_drawpixelinfo *dpi) } /** - * + * * rct2: 0x00685BE1 * * @param dpi (edi) @@ -1726,7 +1726,7 @@ void window_set_resize(rct_window *w, int minWidth, int minHeight, int maxWidth, } /** - * + * * rct2: 0x006EE212 * * @param tool (al) @@ -1758,7 +1758,7 @@ int tool_set(rct_window *w, int widgetIndex, int tool) } /** - * + * * rct2: 0x006EE281 */ void tool_cancel() @@ -2006,7 +2006,7 @@ void window_bubble_list_item(rct_window* w, int item_position){ w->list_item_positions[item_position + 1] = swap; } -/* rct2: 0x006ED710 +/* rct2: 0x006ED710 * Called after a window resize to move windows if they * are going to be out of sight. */ @@ -2140,7 +2140,7 @@ void window_resize_gui_scenario_editor(int width, int height) RCT2_GLOBAL(0x9A998A, uint16) = bottomWind->width - 198; RCT2_GLOBAL(0x9A998C, uint16) = bottomWind->width - 3; } - + } /* Based on rct2: 0x6987ED and another version from window_park */ @@ -2148,7 +2148,7 @@ void window_align_tabs(rct_window *w, uint8 start_tab_id, uint8 end_tab_id) { int i, x = w->widgets[start_tab_id].left; int tab_width = w->widgets[start_tab_id].right - w->widgets[start_tab_id].left; - + for (i = start_tab_id; i <= end_tab_id; i++) { if (!(w->disabled_widgets & (1LL << i))) { w->widgets[i].left = x; @@ -2380,7 +2380,7 @@ void window_move_and_snap(rct_window *w, int newWindowX, int newWindowY, int sna int originalY = w->y; newWindowY = clamp(29, newWindowY, RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - 34); - + if (snapProximity > 0) { w->x = newWindowX; w->y = newWindowY; @@ -2498,4 +2498,4 @@ void window_update_textbox() widget_invalidate(w, gCurrentTextBox.widget_index); window_event_textinput_call(w, gCurrentTextBox.widget_index, gTextBoxInput); } -} \ No newline at end of file +} From 52e0b737bebed912091d68e0865da57cc1601381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 22 Sep 2015 22:45:03 +0200 Subject: [PATCH 6/6] Drop initial null check from SafeFree Both free and delete treat nullptr the same way: as a no-op [1][2]. Get rid of checking if the pointer passed is a null one before acting on it. See stackoverflow.com/q/154136/do-while-and-if-else-statements-in in case you are wondering why is it done this way. [1] http://www.cplusplus.com/reference/cstdlib/free/ [2] http://www.cplusplus.com/reference/new/operator%20delete/ --- src/common.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/common.h b/src/common.h index a965995ce0..b488f7c8e7 100644 --- a/src/common.h +++ b/src/common.h @@ -1,9 +1,9 @@ /***************************************************************************** * Copyright (c) 2014 Ted John * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. - * + * * This file is part of OpenRCT2. - * + * * OpenRCT2 is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -17,21 +17,21 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . *****************************************************************************/ - + #ifndef _COMMON_H_ #define _COMMON_H_ #include "diagnostic.h" #include "rct2.h" -#define SafeFree(x) if ((x) != NULL) { free(x); (x) = NULL; } +#define SafeFree(x) do { free(x); (x) = NULL; } while (0) -#define SafeDelete(x) if ((x) != nullptr) { delete (x); (x) = nullptr; } -#define SafeDeleteArray(x) if ((x) != nullptr) { delete[] (x); (x) = nullptr; } +#define SafeDelete(x) do { delete (x); (x) = nullptr; } while (0) +#define SafeDeleteArray(x) do { delete[] (x); (x) = nullptr; } while (0) #ifndef interface #define interface struct #endif #define abstract = 0 -#endif \ No newline at end of file +#endif