From 2d55356e6e31fd34bf841d201e51813fc5280daf Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Tue, 30 Aug 2016 20:36:07 +0200 Subject: [PATCH 1/6] Update .gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 9d80ff739d..45b4b4ec1f 100644 --- a/.gitignore +++ b/.gitignore @@ -282,3 +282,8 @@ data/g2.dat # KDE folder settings .directory + +############### +## JetBrains ## +############### +.idea/ \ No newline at end of file From 02c1db82afbc579bd5b7176e3b07b0717661bbf4 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Wed, 31 Aug 2016 18:58:58 +0200 Subject: [PATCH 2/6] Fix assertion getting hit on valid path types --- src/rct1/S4Importer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rct1/S4Importer.h b/src/rct1/S4Importer.h index c450d9c3cc..813d57d43f 100644 --- a/src/rct1/S4Importer.h +++ b/src/rct1/S4Importer.h @@ -54,7 +54,7 @@ private: uint8 _smallSceneryTypeToEntryMap[256]; uint8 _largeSceneryTypeToEntryMap[256]; uint8 _wallTypeToEntryMap[256]; - uint8 _pathTypeToEntryMap[16]; + uint8 _pathTypeToEntryMap[24]; uint8 _pathAdditionTypeToEntryMap[16]; uint8 _sceneryThemeTypeToEntryMap[24]; From 4e8e664e945a02cc1e2954f62538f699771e80e4 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Wed, 31 Aug 2016 21:11:11 +0200 Subject: [PATCH 3/6] Integrate 0x00F1AD61 --- src/windows/map.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/windows/map.c b/src/windows/map.c index 07e1474aa5..d74b089cce 100644 --- a/src/windows/map.c +++ b/src/windows/map.c @@ -162,6 +162,8 @@ static rct_window_event_list window_map_events = { window_map_scrollpaint }; +/** rct2: 0x00F1AD61 */ +static uint8 _activeTool; static void window_map_init_map(); static void window_map_center_on_view_point(); @@ -273,7 +275,7 @@ static void window_map_mouseup(rct_window *w, int widgetIndex) window_invalidate(w); if (tool_set(w, widgetIndex, 2)) break; - RCT2_GLOBAL(0xF1AD61, sint8) = 2; + _activeTool = 2; // Prevent mountain tool tool size. gLandToolSize = max(MINIMUM_TOOL_SIZE, gLandToolSize); show_gridlines(); @@ -281,34 +283,34 @@ static void window_map_mouseup(rct_window *w, int widgetIndex) show_construction_rights(); break; case WIDX_LAND_OWNED_CHECKBOX: - RCT2_GLOBAL(0xF1AD61, sint8) ^= 2; + _activeTool ^= 2; - if (RCT2_GLOBAL(0xF1AD61, sint8) & 2) - RCT2_GLOBAL(0xF1AD61, sint8) &= 0xF2; + if (_activeTool & 2) + _activeTool &= 0xF2; window_invalidate(w); break; case WIDX_LAND_SALE_CHECKBOX: - RCT2_GLOBAL(0xF1AD61, sint8) ^= 8; + _activeTool ^= 8; - if (RCT2_GLOBAL(0xF1AD61, sint8) & 8) - RCT2_GLOBAL(0xF1AD61, sint8) &= 0xF8; + if (_activeTool & 8) + _activeTool &= 0xF8; window_invalidate(w); break; case WIDX_CONSTRUCTION_RIGHTS_OWNED_CHECKBOX: - RCT2_GLOBAL(0xF1AD61, sint8) ^= 1; + _activeTool ^= 1; - if (RCT2_GLOBAL(0xF1AD61, sint8) & 1) - RCT2_GLOBAL(0xF1AD61, sint8) &= 0xF1; + if (_activeTool & 1) + _activeTool &= 0xF1; window_invalidate(w); break; case WIDX_CONSTRUCTION_RIGHTS_SALE_CHECKBOX: - RCT2_GLOBAL(0xF1AD61, sint8) ^= 4; + _activeTool ^= 4; - if (RCT2_GLOBAL(0xF1AD61, sint8) & 4) - RCT2_GLOBAL(0xF1AD61, sint8) &= 0xF4; + if (_activeTool & 4) + _activeTool &= 0xF4; window_invalidate(w); break; @@ -488,7 +490,7 @@ static void window_map_tooldrag(rct_window* w, int widgetIndex, int x, int y) gMapSelectPositionA.x, GAME_COMMAND_FLAG_APPLY, gMapSelectPositionA.y, - RCT2_GLOBAL(0x00F1AD61, uint8), + _activeTool, GAME_COMMAND_SET_LAND_OWNERSHIP, gMapSelectPositionB.x, gMapSelectPositionB.y @@ -607,7 +609,7 @@ static void window_map_scrollmousedown(rct_window *w, int scrollIndex, int x, in gMapSelectPositionA.x, GAME_COMMAND_FLAG_APPLY, gMapSelectPositionA.y, - RCT2_GLOBAL(0x00F1AD61, uint8), + _activeTool, GAME_COMMAND_SET_LAND_OWNERSHIP, gMapSelectPositionB.x, gMapSelectPositionB.y @@ -687,16 +689,16 @@ static void window_map_invalidate(rct_window *w) pressedWidgets |= (1ULL << (WIDX_PEOPLE_TAB + w->selected_tab)); pressedWidgets |= (1ULL << WIDX_LAND_TOOL); - if (RCT2_GLOBAL(0x00F1AD61, uint8) & (1 << 3)) + if (_activeTool & (1 << 3)) pressedWidgets |= (1 << WIDX_LAND_SALE_CHECKBOX); - if (RCT2_GLOBAL(0x00F1AD61, uint8) & (1 << 2)) + if (_activeTool & (1 << 2)) pressedWidgets |= (1 << WIDX_CONSTRUCTION_RIGHTS_SALE_CHECKBOX); - if (RCT2_GLOBAL(0x00F1AD61, uint8) & (1 << 1)) + if (_activeTool & (1 << 1)) pressedWidgets |= (1 << WIDX_LAND_OWNED_CHECKBOX); - if (RCT2_GLOBAL(0x00F1AD61, uint8) & (1 << 0)) + if (_activeTool & (1 << 0)) pressedWidgets |= (1 << WIDX_CONSTRUCTION_RIGHTS_OWNED_CHECKBOX); w->pressed_widgets = pressedWidgets; From 2431930a8ecd3e91a3ef141542413143bcfd35ed Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Thu, 1 Sep 2016 00:08:59 +0200 Subject: [PATCH 4/6] Integrate map array --- src/windows/map.c | 56 ++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/windows/map.c b/src/windows/map.c index d74b089cce..9b5227aebe 100644 --- a/src/windows/map.c +++ b/src/windows/map.c @@ -165,6 +165,12 @@ static rct_window_event_list window_map_events = { /** rct2: 0x00F1AD61 */ static uint8 _activeTool; +/** rct2: 0x00F1AD6C */ +static uint32 _curPixel; + +/** rct2: 0x00F1AD68 */ +static uint8 _mapImageData[512][512]; + static void window_map_init_map(); static void window_map_center_on_view_point(); static void window_map_show_default_scenario_editor_buttons(rct_window *w); @@ -194,7 +200,6 @@ static void map_window_screen_to_map(int screenX, int screenY, int *mapX, int *m void window_map_open() { rct_window *w; - uint32 *map_image_data; // Check if window is already open w = window_bring_to_front_by_class(WC_MAP); @@ -204,11 +209,6 @@ void window_map_open() return; } - map_image_data = malloc(256 * 256 * sizeof(uint32)); - if (map_image_data == NULL) - return; - - RCT2_GLOBAL(RCT2_ADDRESS_MAP_IMAGE_DATA, uint32*) = map_image_data; w = window_create_auto_pos(245, 259, &window_map_events, WC_MAP, WF_10); w->widgets = window_map_widgets; w->enabled_widgets = @@ -253,7 +253,6 @@ void window_map_open() */ static void window_map_close(rct_window *w) { - free(RCT2_GLOBAL(RCT2_ADDRESS_MAP_IMAGE_DATA, uint32*)); if ((gInputFlags & INPUT_FLAG_TOOL_ACTIVE) && gCurrentToolWidget.window_classification == w->classification && gCurrentToolWidget.window_number == w->number) { @@ -872,11 +871,11 @@ static void window_map_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int sc g1_element = &g1Elements[0]; pushed_g1_element = *g1_element; - g1_element->offset = RCT2_GLOBAL(RCT2_ADDRESS_MAP_IMAGE_DATA, uint8*); - g1_element->width = 0x200; - g1_element->height = 0x200; - g1_element->x_offset = 0xFFF8; - g1_element->y_offset = 0xFFF8; + g1_element->offset = &_mapImageData[0][0]; + g1_element->width = 512; + g1_element->height = 512; + g1_element->x_offset = -8; + g1_element->y_offset = -8; g1_element->flags = 0; gfx_draw_sprite(dpi, 0, 0, 0, 0); @@ -897,8 +896,8 @@ static void window_map_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int sc */ static void window_map_init_map() { - memset(RCT2_GLOBAL(RCT2_ADDRESS_MAP_IMAGE_DATA, void*), 0x0A, 256 * 256 * sizeof(uint32)); - RCT2_GLOBAL(0x00F1AD6C, uint32) = 0; + memset(_mapImageData, 0x0A, sizeof(_mapImageData)); + _curPixel = 0; } /** @@ -1630,32 +1629,35 @@ static uint16 map_window_get_pixel_colour_ride(int x, int y) static void map_window_set_pixels(rct_window *w) { - uint16 colour = 0, *destination; + uint16 colour = 0; + uint8 *destination; int x = 0, y = 0, dx = 0, dy = 0; - destination = (uint16*)((RCT2_GLOBAL(0x00F1AD6C, uint32) * 511) + RCT2_GLOBAL(RCT2_ADDRESS_MAP_IMAGE_DATA, uint32) + 255); + int pos = (_curPixel * 511) + 255; + rct_xy16 destinationPosition = {.y = pos/512, .x = pos % 512}; + destination = &_mapImageData[destinationPosition.y][destinationPosition.x]; switch (get_current_rotation()) { case 0: - x = RCT2_GLOBAL(0x00F1AD6C, uint32) * 32; + x = _curPixel * 32; y = 0; dx = 0; dy = 32; break; case 1: x = 8192 - 32; - y = RCT2_GLOBAL(0x00F1AD6C, uint32) * 32; + y = _curPixel * 32; dx = -32; dy = 0; break; case 2: - x = (255 - RCT2_GLOBAL(0x00F1AD6C, uint32)) * 32; + x = (255 - _curPixel) * 32; y = 8192 - 32; dx = 0; dy = -32; break; case 3: x = 0; - y = (255 - RCT2_GLOBAL(0x00F1AD6C, uint32)) * 32; + y = (255 - _curPixel) * 32; dx = 32; dy = 0; break; @@ -1676,15 +1678,19 @@ static void map_window_set_pixels(rct_window *w) colour = map_window_get_pixel_colour_ride(x, y); break; } - *destination = colour; + destination[0] = HIBYTE(colour); + destination[1] = LOBYTE(colour); } x += dx; y += dy; - destination = (uint16*)((uintptr_t)destination + 513); + + destinationPosition.x++; + destinationPosition.y++; + destination = &_mapImageData[destinationPosition.y][destinationPosition.x]; } - RCT2_GLOBAL(0x00F1AD6C, uint32)++; - if (RCT2_GLOBAL(0x00F1AD6C, uint32) >= 256) - RCT2_GLOBAL(0x00F1AD6C, uint32) = 0; + _curPixel++; + if (_curPixel >= 256) + _curPixel = 0; } static void map_window_screen_to_map(int screenX, int screenY, int *mapX, int *mapY) From 74eac21162c6ba4d47c9e5b416d11bfd6f8b133c Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Thu, 1 Sep 2016 13:07:28 +0200 Subject: [PATCH 5/6] Dynamically allocate memory for map --- src/windows/map.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/windows/map.c b/src/windows/map.c index 9b5227aebe..f9389938ca 100644 --- a/src/windows/map.c +++ b/src/windows/map.c @@ -169,7 +169,7 @@ static uint8 _activeTool; static uint32 _curPixel; /** rct2: 0x00F1AD68 */ -static uint8 _mapImageData[512][512]; +static uint8 (*_mapImageData)[512][512]; static void window_map_init_map(); static void window_map_center_on_view_point(); @@ -209,6 +209,11 @@ void window_map_open() return; } + _mapImageData = malloc(sizeof(*_mapImageData)); + if (_mapImageData == NULL) { + return; + } + w = window_create_auto_pos(245, 259, &window_map_events, WC_MAP, WF_10); w->widgets = window_map_widgets; w->enabled_widgets = @@ -253,6 +258,7 @@ void window_map_open() */ static void window_map_close(rct_window *w) { + free(_mapImageData); if ((gInputFlags & INPUT_FLAG_TOOL_ACTIVE) && gCurrentToolWidget.window_classification == w->classification && gCurrentToolWidget.window_number == w->number) { @@ -871,7 +877,7 @@ static void window_map_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int sc g1_element = &g1Elements[0]; pushed_g1_element = *g1_element; - g1_element->offset = &_mapImageData[0][0]; + g1_element->offset = (uint8 *) _mapImageData; g1_element->width = 512; g1_element->height = 512; g1_element->x_offset = -8; @@ -896,7 +902,7 @@ static void window_map_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int sc */ static void window_map_init_map() { - memset(_mapImageData, 0x0A, sizeof(_mapImageData)); + memset(_mapImageData, 0x0A, sizeof(*_mapImageData)); _curPixel = 0; } @@ -1635,7 +1641,7 @@ static void map_window_set_pixels(rct_window *w) int pos = (_curPixel * 511) + 255; rct_xy16 destinationPosition = {.y = pos/512, .x = pos % 512}; - destination = &_mapImageData[destinationPosition.y][destinationPosition.x]; + destination = &(*_mapImageData)[destinationPosition.y][destinationPosition.x]; switch (get_current_rotation()) { case 0: x = _curPixel * 32; @@ -1686,7 +1692,7 @@ static void map_window_set_pixels(rct_window *w) destinationPosition.x++; destinationPosition.y++; - destination = &_mapImageData[destinationPosition.y][destinationPosition.x]; + destination = &(*_mapImageData)[destinationPosition.y][destinationPosition.x]; } _curPixel++; if (_curPixel >= 256) From 7766faf00d775dca9f241c726af34908d94bf528 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Thu, 1 Sep 2016 13:13:07 +0200 Subject: [PATCH 6/6] Rename _curPixel to _currentLine --- src/windows/map.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/windows/map.c b/src/windows/map.c index f9389938ca..8468354c21 100644 --- a/src/windows/map.c +++ b/src/windows/map.c @@ -166,7 +166,7 @@ static rct_window_event_list window_map_events = { static uint8 _activeTool; /** rct2: 0x00F1AD6C */ -static uint32 _curPixel; +static uint32 _currentLine; /** rct2: 0x00F1AD68 */ static uint8 (*_mapImageData)[512][512]; @@ -903,7 +903,7 @@ static void window_map_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, int sc static void window_map_init_map() { memset(_mapImageData, 0x0A, sizeof(*_mapImageData)); - _curPixel = 0; + _currentLine = 0; } /** @@ -1639,31 +1639,31 @@ static void map_window_set_pixels(rct_window *w) uint8 *destination; int x = 0, y = 0, dx = 0, dy = 0; - int pos = (_curPixel * 511) + 255; + int pos = (_currentLine * 511) + 255; rct_xy16 destinationPosition = {.y = pos/512, .x = pos % 512}; destination = &(*_mapImageData)[destinationPosition.y][destinationPosition.x]; switch (get_current_rotation()) { case 0: - x = _curPixel * 32; + x = _currentLine * 32; y = 0; dx = 0; dy = 32; break; case 1: x = 8192 - 32; - y = _curPixel * 32; + y = _currentLine * 32; dx = -32; dy = 0; break; case 2: - x = (255 - _curPixel) * 32; + x = (255 - _currentLine) * 32; y = 8192 - 32; dx = 0; dy = -32; break; case 3: x = 0; - y = (255 - _curPixel) * 32; + y = (255 - _currentLine) * 32; dx = 32; dy = 0; break; @@ -1694,9 +1694,9 @@ static void map_window_set_pixels(rct_window *w) destinationPosition.y++; destination = &(*_mapImageData)[destinationPosition.y][destinationPosition.x]; } - _curPixel++; - if (_curPixel >= 256) - _curPixel = 0; + _currentLine++; + if (_currentLine >= 256) + _currentLine = 0; } static void map_window_screen_to_map(int screenX, int screenY, int *mapX, int *mapY)