From cdd15bf1fefaa7b005d99e9a16f69d910558f8fe Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 11 Aug 2014 18:22:28 +0100 Subject: [PATCH 01/11] Fixes water display issues. --- src/gfx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index b81bd39c99..8f419fa653 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -883,7 +883,7 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point uint8 al = *source_pointer; uint8 ah = *dest_pointer; if (image_type & IMAGE_TYPE_MIX_BACKGROUND)//Mix with background and image Not Tested - al = palette_pointer[(al | ((int)ah) << 8) - 0x100]; + al = palette_pointer[(((uint16)al << 8) | ah) - 0x100]; else //Adjust colours? al = palette_pointer[al]; *dest_pointer = al; @@ -936,7 +936,6 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y, int ebp RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); if (image_type && !(image_type & IMAGE_TYPE_UNKNOWN)) { - if (!(image_type & IMAGE_TYPE_MIX_BACKGROUND)){ eax = image_id; eax >>= 19; From bc5ac887c52ca9fc50bec29f079e13dcb59e3f44 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 11 Aug 2014 19:04:02 +0100 Subject: [PATCH 02/11] Fix primary secondary tertiary colour sprites --- src/gfx.c | 50 ++++++++++---------------------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 8f419fa653..f782d944c3 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -954,57 +954,27 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y, int ebp RCT2_GLOBAL(0x9ABDA4, uint32) = (uint32)palette_pointer; } else if (image_type && !(image_type & IMAGE_TYPE_USE_PALETTE)){ - //Has not been tested - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); - return; RCT2_GLOBAL(0x9E3CDC, uint32) = 0; unknown_pointer = NULL; - eax = image_id; - eax >>= 19; - //push edx/y - eax &= 0x1F; - ebp = palette_to_g1_offset[ebp]; //RCT2_GLOBAL(ebp * 4 + 0x97FCBC, uint32); //ebp has not been set to anything before this! ?? - //Possibly another variable input?! - eax = palette_to_g1_offset[eax]; //RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); - ebp <<= 0x4; - eax <<= 0x4; - ebp = RCT2_GLOBAL(ebp + RCT2_ADDRESS_G1_ELEMENTS, uint32); - eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); - edx = *((uint32*)(eax + 0xF3)); - esi = *((uint32*)(eax + 0xF7)); - RCT2_GLOBAL(0x9ABFFF, uint32) = edx; - RCT2_GLOBAL(0x9AC003, uint32) = esi; - edx = *((uint32*)(ebp + 0xF3)); - esi = *((uint32*)(ebp + 0xF7)); - esi = *((uint32*)(eax + 0xF7)); + uint32 primary_offset = palette_to_g1_offset[ebp]; + uint32 secondary_offset = palette_to_g1_offset[(image_id >> 19) & 0x1F]; + uint32 tertiary_offset = palette_to_g1_offset[(image_id >> 24) & 0x1F]; - edx = *((uint32*)(eax + 0xFB)); - esi = *((uint32*)(ebp + 0xFB)); + rct_g1_element* primary_colour = &RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[primary_offset]; + rct_g1_element* secondary_colour = &RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[secondary_offset]; + rct_g1_element* tertiary_colour = &RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[tertiary_offset]; - eax = image_id; - RCT2_GLOBAL(0x9AC007, uint32) = edx; - eax >>= 24; - RCT2_GLOBAL(0x9ABF42, uint32) = esi; - eax &= 0x1F; + memcpy((uint8*)0x9ABF3A, &primary_colour->offset[0xF3], 12); + memcpy((uint8*)0x9ABFFF, &secondary_colour->offset[0xF3], 12); + memcpy((uint8*)0x9ABFD6, &tertiary_colour->offset[0xF3], 12); //image_id RCT2_GLOBAL(0xEDF81C, uint32) |= 0x20000000; - image_id |= IMAGE_TYPE_USE_PALETTE; + image_id |= IMAGE_TYPE_USE_PALETTE << 28; - eax = palette_to_g1_offset[eax]; //RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); - eax <<= 4; - eax = RCT2_GLOBAL(eax + RCT2_ADDRESS_G1_ELEMENTS, uint32); - edx = *((uint32*)(eax + 0xF3)); - esi = *((uint32*)(eax + 0xF7)); - RCT2_GLOBAL(0x9ABFD6, uint32) = edx; - RCT2_GLOBAL(0x9ABFDA, uint32) = esi; - edx = *((uint32*)(eax + 0xFB)); RCT2_GLOBAL(0x9ABDA4, uint32) = 0x9ABF0C; palette_pointer = (uint8*)0x9ABF0C; - RCT2_GLOBAL(0x9ABFDE, uint32) = edx; - edx = y; - } else if (image_type){ RCT2_GLOBAL(0x9E3CDC, uint32) = 0; From 787340921ec26c2d73a03a58d03d4c4bb9e7d0bb Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 11 Aug 2014 19:14:09 +0100 Subject: [PATCH 03/11] Swapped variable names to match game --- src/gfx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index f782d944c3..9ae1407b29 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -957,17 +957,17 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y, int ebp RCT2_GLOBAL(0x9E3CDC, uint32) = 0; unknown_pointer = NULL; - uint32 primary_offset = palette_to_g1_offset[ebp]; - uint32 secondary_offset = palette_to_g1_offset[(image_id >> 19) & 0x1F]; - uint32 tertiary_offset = palette_to_g1_offset[(image_id >> 24) & 0x1F]; + uint32 primary_offset = palette_to_g1_offset[(image_id >> 19) & 0x1F]; + uint32 secondary_offset = palette_to_g1_offset[(image_id >> 24) & 0x1F]; + uint32 tertiary_offset = palette_to_g1_offset[ebp]; rct_g1_element* primary_colour = &RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[primary_offset]; rct_g1_element* secondary_colour = &RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[secondary_offset]; rct_g1_element* tertiary_colour = &RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[tertiary_offset]; - memcpy((uint8*)0x9ABF3A, &primary_colour->offset[0xF3], 12); - memcpy((uint8*)0x9ABFFF, &secondary_colour->offset[0xF3], 12); - memcpy((uint8*)0x9ABFD6, &tertiary_colour->offset[0xF3], 12); + memcpy((uint8*)0x9ABFFF, &primary_colour->offset[0xF3], 12); + memcpy((uint8*)0x9ABFD6, &secondary_colour->offset[0xF3], 12); + memcpy((uint8*)0x9ABF3A, &tertiary_colour->offset[0xF3], 12); //image_id RCT2_GLOBAL(0xEDF81C, uint32) |= 0x20000000; From 00a9ab9da373016893b5385f4c23eb146fed2917 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 11 Aug 2014 19:27:04 +0100 Subject: [PATCH 04/11] Added notes to draw_sprite --- src/gfx.c | 16 +++++++++++----- src/gfx.h | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 9ae1407b29..b67c272390 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -914,15 +914,21 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point /** * * rct2: 0x0067A28E - * image_id (ebx) + * 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_XXXX_XXXX_X111_1111_1111_1111_1111 image_id (offset to g1) * x (cx) * y (dx) * dpi (esi) - * (ebp) + * tertiary_colour (ebp) */ -void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y, int ebp) +void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint32 tertiary_colour) { - //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, ebp); + //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, tertiary_colour); //return; int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = (int)dpi; int image_type = (image_id & 0xE0000000) >> 28; @@ -959,7 +965,7 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y, int ebp uint32 primary_offset = palette_to_g1_offset[(image_id >> 19) & 0x1F]; uint32 secondary_offset = palette_to_g1_offset[(image_id >> 24) & 0x1F]; - uint32 tertiary_offset = palette_to_g1_offset[ebp]; + uint32 tertiary_offset = palette_to_g1_offset[tertiary_colour]; rct_g1_element* primary_colour = &RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[primary_offset]; rct_g1_element* secondary_colour = &RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[secondary_offset]; diff --git a/src/gfx.h b/src/gfx.h index c66c433c5e..009a7bfa65 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -70,7 +70,7 @@ void gfx_draw_pixel(rct_drawpixelinfo *dpi, int x, int y, int colour); void gfx_draw_line(rct_drawpixelinfo *dpi, int x1, int y1, int x2, int y2, int colour); void gfx_fill_rect(rct_drawpixelinfo *dpi, int left, int top, int right, int bottom, int colour); void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short right, short bottom, int colour, short _si); -void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y, int ebp); +void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint32 tertiary_colour); void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint8* palette_pointer, uint8* unknown_pointer); void gfx_draw_string(rct_drawpixelinfo *dpi, char *buffer, int colour, int x, int y); void gfx_transpose_palette(int pal, unsigned char product); From b3325bcb38bffeb1d8200f8e2aec627715a0b674 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 11 Aug 2014 19:37:30 +0100 Subject: [PATCH 05/11] Cleaned up obsolete variables --- src/gfx.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index b67c272390..13390b6e4a 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -920,6 +920,7 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point * 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) @@ -930,33 +931,30 @@ void gfx_draw_sprite(rct_drawpixelinfo *dpi, int image_id, int x, int y, uint32 { //RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, tertiary_colour); //return; - int eax = 0, ebx = image_id, ecx = x, edx = y, esi = 0, edi = (int)dpi; + int image_type = (image_id & 0xE0000000) >> 28; int image_sub_type = (image_id & 0x1C000000) >> 26; + uint8* palette_pointer = NULL; uint8 palette[0x100]; + RCT2_GLOBAL(0x00EDF81C, uint32) = image_id & 0xE0000000; - eax = (image_id >> 26) & 0x7; uint8* unknown_pointer = (uint8*)(RCT2_ADDRESS(0x9E3CE4, uint32*)[image_sub_type]); - RCT2_GLOBAL(0x009E3CDC, uint32) = RCT2_GLOBAL(0x009E3CE4 + eax * 4, uint32); + RCT2_GLOBAL(0x009E3CDC, uint32) = (uint32)unknown_pointer; if (image_type && !(image_type & IMAGE_TYPE_UNKNOWN)) { + uint8 palette_ref = (image_id >> 19) & 0xFF; if (!(image_type & IMAGE_TYPE_MIX_BACKGROUND)){ - eax = image_id; - eax >>= 19; - eax &= 0xFF; unknown_pointer = NULL; RCT2_GLOBAL(0x009E3CDC, uint32) = 0; } else{ - eax = image_id; - eax >>= 19; - eax &= 0x7F; + palette_ref &= 0x7F; } - eax = palette_to_g1_offset[eax];// RCT2_GLOBAL(eax * 4 + 0x97FCBC, uint32); - palette_pointer = ((rct_g1_element*)RCT2_ADDRESS_G1_ELEMENTS)[eax].offset; + uint16 palette_offset = palette_to_g1_offset[palette_ref]; + palette_pointer = RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[palette_offset].offset; RCT2_GLOBAL(0x9ABDA4, uint32) = (uint32)palette_pointer; } else if (image_type && !(image_type & IMAGE_TYPE_USE_PALETTE)){ From a44171205c08171a4340e558a449508cb6fffb41 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Mon, 11 Aug 2014 19:46:57 +0100 Subject: [PATCH 06/11] Removed redundant comments about not being tested --- src/gfx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 13390b6e4a..00c2a86f34 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -882,9 +882,9 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point for (; no_pixels > 0; no_pixels -= (1< Date: Tue, 12 Aug 2014 07:45:55 +0100 Subject: [PATCH 07/11] Zoomed land working. --- src/gfx.c | 57 ++++++++++++++++++++++++++-------------------------- src/gfx.h | 2 +- src/window.c | 3 ++- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 00c2a86f34..297f6e2c61 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1022,44 +1022,45 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in rct_g1_element* g1_source = &(RCT2_ADDRESS(RCT2_ADDRESS_G1_ELEMENTS, rct_g1_element)[image_element]); //Zooming code has been integrated into main code but is not working. - if (dpi->zoom_level >= 1){ //These have not been tested - //something to do with zooming - if (dpi->zoom_level == 1){ - RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); - return; - } - if (dpi->zoom_level == 2){ - RCT2_CALLPROC_X(0x0067DADA, 0, (int)g1_source, x, y, 0, (int)dpi, 0); - return; - } - RCT2_CALLPROC_X(0x0067FAAE, 0, (int)g1_source, x, y, 0, (int)dpi, 0); - return; - } - //if ( dpi->zoom_level && (g1_source->flags & (1<<4)) ){ - // rct_drawpixelinfo zoomed_dpi = { - // .bits = dpi->bits, - // .x = dpi->x >> 1, - // .y = dpi->y >> 1, - // .height = dpi->height>>1, - // .width = dpi->width>>1, - // .pitch = dpi->pitch,//In the actual code this is dpi->pitch but that doesn't seem correct. - // .zoom_level = dpi->zoom_level - 1 - // }; - // gfx_draw_sprite_palette_set(&zoomed_dpi, (image_type << 28) | (image_element - g1_source->zoomed_offset), x >> 1, y >> 1, palette_pointer, unknown_pointer); + //if (dpi->zoom_level >= 1){ //These have not been tested + // //something to do with zooming + // if (dpi->zoom_level == 1){ + // RCT2_CALLPROC_X(0x0067A28E, 0, image_id, x, y, 0, (int)dpi, 0); + // return; + // } + // if (dpi->zoom_level == 2){ + // RCT2_CALLPROC_X(0x0067DADA, 0, (int)g1_source, x, y, 0, (int)dpi, 0); + // return; + // } + // RCT2_CALLPROC_X(0x0067FAAE, 0, (int)g1_source, x, y, 0, (int)dpi, 0); // return; //} - + if ( dpi->zoom_level && (g1_source->flags & (1<<4)) ){ + rct_drawpixelinfo zoomed_dpi = { + .bits = dpi->bits, + .x = ((uint16)dpi->x) >> 1, + .y = ((uint16)dpi->y) >> 1, + .height = dpi->height>>1, + .width = dpi->width>>1, + .pitch = dpi->pitch, + .zoom_level = dpi->zoom_level - 1 + }; + gfx_draw_sprite_palette_set(&zoomed_dpi, (image_type << 28) | (image_element - g1_source->zoomed_offset), x >> 1, y >> 1, palette_pointer, unknown_pointer); + return; + } + if ( dpi->zoom_level && (g1_source->flags & (1<<5)) ){ return; } - + //Disable all buggy code + if (dpi->zoom_level)return; //Its used super often so we will define it to a seperate variable. int zoom_level = dpi->zoom_level; //This will be the height of the drawn image int height = g1_source->height >> zoom_level; //This is the start y coordinate on the destination - sint16 dest_start_y = y - dpi->y + g1_source->y_offset; + sint16 dest_start_y = y - ((uint16)dpi->y) + g1_source->y_offset; //This is the start y coordinate on the source int source_start_y = 0; @@ -1094,7 +1095,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in //This is the source start x coordinate int source_start_x = 0; //This is the destination start x coordinate - sint16 dest_start_x = x - dpi->x + g1_source->x_offset; + sint16 dest_start_x = x - ((uint16)dpi->x) + g1_source->x_offset; if (dest_start_x < 0){ //If the destination is negative reduce the width diff --git a/src/gfx.h b/src/gfx.h index 009a7bfa65..476f7420ac 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -43,7 +43,7 @@ typedef struct { sint16 x_offset; // 0x08 sint16 y_offset; // 0x0A uint16 flags; // 0x0C - sint16 zoomed_offset; // 0x0E + uint16 zoomed_offset; // 0x0E } rct_g1_element; enum{ diff --git a/src/window.c b/src/window.c index 569463783c..fe9363d2d4 100644 --- a/src/window.c +++ b/src/window.c @@ -1343,7 +1343,8 @@ void window_bubble_list_item(rct_window* w, int item_position){ void window_resize_gui(int width, int height) { if (RCT2_GLOBAL(0x9DEA68, uint8) & 0xE){ - return window_resize_gui_scenario_editor(width, height); + window_resize_gui_scenario_editor(width, height); + return; } rct_window* mainWind = window_get_main(); if (mainWind){ From 9a33bc0597fec5228bbb03cdbdb0b21145669ce5 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 12 Aug 2014 08:02:18 +0100 Subject: [PATCH 08/11] Added zoom_masks --- src/gfx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 297f6e2c61..f65fc97291 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1057,10 +1057,11 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in //Its used super often so we will define it to a seperate variable. int zoom_level = dpi->zoom_level; + uint16 zoom_mask = 0xFFFF << zoom_level; //This will be the height of the drawn image int height = g1_source->height >> zoom_level; //This is the start y coordinate on the destination - sint16 dest_start_y = y - ((uint16)dpi->y) + g1_source->y_offset; + sint16 dest_start_y = zoom_mask & (y + g1_source->y_offset) - ((uint16)dpi->y); //This is the start y coordinate on the source int source_start_y = 0; @@ -1095,7 +1096,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in //This is the source start x coordinate int source_start_x = 0; //This is the destination start x coordinate - sint16 dest_start_x = x - ((uint16)dpi->x) + g1_source->x_offset; + sint16 dest_start_x = zoom_mask & (x + g1_source->x_offset) - ((uint16)dpi->x); if (dest_start_x < 0){ //If the destination is negative reduce the width From 3bbfd972245bd280e19798e524e39e10002b4c95 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 12 Aug 2014 18:19:37 +0100 Subject: [PATCH 09/11] Zooming working again. Graphical glitch along x=0 line. --- src/gfx.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index f65fc97291..37940afa22 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -690,6 +690,7 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri */ void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* unknown_pointer, uint8* source_pointer, uint8* dest_pointer, rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, int height, int width, int image_type){ uint8 zoom_level = dest_dpi->zoom_level; + //Requires use of palette? if (image_type & IMAGE_TYPE_USE_PALETTE){ @@ -700,7 +701,7 @@ void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* unknown_pointer, ui for (; height > 0; height -= (1<width << zoom_level); uint8* next_unknown_pointer = unknown_pointer + (uint32)(source_image->width << zoom_level); - uint8* next_dest_pointer = dest_pointer + dest_dpi->width + dest_dpi->pitch; + uint8* next_dest_pointer = dest_pointer + (dest_dpi->width >> zoom_level) + dest_dpi->pitch; for (int no_pixels = width; no_pixels > 0; no_pixels -= (1< 0; height -= (1<width<width + dest_dpi->pitch; + uint8* next_dest_pointer = dest_pointer + (dest_dpi->width >> zoom_level) + dest_dpi->pitch; for (int no_pixels = width; no_pixels > 0; no_pixels -= (1< 0; height -= (1<width << zoom_level); - uint8* next_dest_pointer = dest_pointer + dest_dpi->width + dest_dpi->pitch; + uint8* next_dest_pointer = dest_pointer + (dest_dpi->width >> zoom_level) + dest_dpi->pitch; for (int no_pixels = width; no_pixels > 0; no_pixels -= (1<flags & G1_FLAG_BMP)){//Not tested for (; height > 0; height-=(1<width << zoom_level); - uint8* next_dest_pointer = dest_pointer + dest_dpi->width + dest_dpi->pitch; + uint8* next_dest_pointer = dest_pointer + (dest_dpi->width >> zoom_level) + dest_dpi->pitch; for (int no_pixels = width; no_pixels > 0; no_pixels -= (1< 0; height -= (1<width << zoom_level); uint8* next_unknown_pointer = unknown_pointer + (uint32)(source_image->width << zoom_level); - uint8* next_dest_pointer = dest_pointer + dest_dpi->width + dest_dpi->pitch; + uint8* next_dest_pointer = dest_pointer + (dest_dpi->width >> zoom_level) + dest_dpi->pitch; for (int no_pixels = width; no_pixels > 0; no_pixels -= (1< 0; height -= (1<width << zoom_level); - uint8* next_dest_pointer = dest_pointer + dest_dpi->width + dest_dpi->pitch; + uint8* next_dest_pointer = dest_pointer + (dest_dpi->width >> zoom_level) + dest_dpi->pitch; for (int no_pixels = width; no_pixels > 0; no_pixels -= (1<width + (int)dpi->pitch; + next_dest_pointer += (int)(dpi->width >> zoom_level) + (int)dpi->pitch; } } @@ -1052,8 +1053,6 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in if ( dpi->zoom_level && (g1_source->flags & (1<<5)) ){ return; } - //Disable all buggy code - if (dpi->zoom_level)return; //Its used super often so we will define it to a seperate variable. int zoom_level = dpi->zoom_level; @@ -1061,7 +1060,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in //This will be the height of the drawn image int height = g1_source->height >> zoom_level; //This is the start y coordinate on the destination - sint16 dest_start_y = zoom_mask & (y + g1_source->y_offset) - ((uint16)dpi->y); + sint16 dest_start_y = (y + g1_source->y_offset - (uint16)dpi->y) >> zoom_level; //This is the start y coordinate on the source int source_start_y = 0; @@ -1083,10 +1082,10 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in int dest_end_y = dest_start_y + height; - if (dest_end_y > dpi->height){ + if (dest_end_y > (dpi->height >> zoom_level)){ //If the destination y is outside of the drawing //image reduce the height of the image - height -= dest_end_y - dpi->height; + height -= dest_end_y - (dpi->height >> zoom_level); //If the image no longer has anything to draw if (height <= 0)return; } @@ -1096,7 +1095,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in //This is the source start x coordinate int source_start_x = 0; //This is the destination start x coordinate - sint16 dest_start_x = zoom_mask & (x + g1_source->x_offset) - ((uint16)dpi->x); + sint16 dest_start_x = (x + g1_source->x_offset - (uint16)dpi->x)>>zoom_level; if (dest_start_x < 0){ //If the destination is negative reduce the width @@ -1114,10 +1113,10 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in int dest_end_x = dest_start_x + width; - if (dest_end_x > dpi->width){ + if (dest_end_x > (dpi->width>>zoom_level)){ //If the destination x is outside of the drawing area //reduce the image width. - width -= dest_end_x - dpi->width; + width -= dest_end_x - (dpi->width >> zoom_level); //If there is no image to draw. if (width <= 0)return; } @@ -1125,7 +1124,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in uint8* dest_pointer = (uint8*)dpi->bits; //Move the pointer to the start point of the destination - dest_pointer += (dpi->width + dpi->pitch)*dest_start_y + dest_start_x; + dest_pointer += ((dpi->width >> zoom_level) + dpi->pitch)*dest_start_y + dest_start_x; height <<= zoom_level; width <<= zoom_level; From 3aaa9ef9657bfaba87bbe4757519294f4c0859f6 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 12 Aug 2014 20:11:23 +0100 Subject: [PATCH 10/11] Tidy viewport code --- src/gfx.c | 9 ++++----- src/viewport.c | 16 +++------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 37940afa22..a085447df7 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -690,7 +690,6 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri */ void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* unknown_pointer, uint8* source_pointer, uint8* dest_pointer, rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, int height, int width, int image_type){ uint8 zoom_level = dest_dpi->zoom_level; - //Requires use of palette? if (image_type & IMAGE_TYPE_USE_PALETTE){ @@ -893,6 +892,7 @@ void gfx_rle_sprite_to_buffer(uint8* source_bits_pointer, uint8* dest_bits_point else if (image_type & IMAGE_TYPE_MIX_BACKGROUND){//In the .exe these are all unraveled loops //Doesnt use source pointer ??? mix with background only? //Not Tested + for (; no_pixels > 0; no_pixels -= (1<zoom_level && (g1_source->flags & (1<<5)) ){ return; } - //Its used super often so we will define it to a seperate variable. int zoom_level = dpi->zoom_level; uint16 zoom_mask = 0xFFFF << zoom_level; @@ -1086,10 +1085,10 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in //If the destination y is outside of the drawing //image reduce the height of the image height -= dest_end_y - (dpi->height >> zoom_level); - //If the image no longer has anything to draw - if (height <= 0)return; } - + //If the image no longer has anything to draw + if (height <= 0)return; + //This will be the width of the drawn image int width = g1_source->width >> zoom_level; //This is the source start x coordinate diff --git a/src/viewport.c b/src/viewport.c index 63d9ecfbe0..0ffa77b740 100644 --- a/src/viewport.c +++ b/src/viewport.c @@ -373,20 +373,10 @@ void sub_688485(){ } } - if (!(ps->var_1A & 1)){ + if (!(ps->var_1A & 1)) gfx_draw_sprite(dpi, image_id, x, y, ps->var_04); - - if (ps->var_20 != 0){ - ps = ps->var_20; - continue; - } - paint_attached_ps(ps, ps->attached_ps, dpi); - - ps = previous_ps->var_24; - previous_ps = ps; - continue; - } - RCT2_CALLPROC_X(0x00681DE2, 0, image_id, x, y, 0, (int)dpi, ps->var_04); + else + RCT2_CALLPROC_X(0x00681DE2, 0, image_id, x, y, 0, (int)dpi, ps->var_04); if (ps->var_20 != 0){ ps = ps->var_20; From cd1f71708e34764e6beec4964d72f4bf9d34dec7 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Tue, 12 Aug 2014 20:43:38 +0100 Subject: [PATCH 11/11] Fixed zoom bug. --- src/gfx.c | 10 +++++----- src/viewport.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index a085447df7..59350e680d 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1039,8 +1039,8 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in if ( dpi->zoom_level && (g1_source->flags & (1<<4)) ){ rct_drawpixelinfo zoomed_dpi = { .bits = dpi->bits, - .x = ((uint16)dpi->x) >> 1, - .y = ((uint16)dpi->y) >> 1, + .x = dpi->x >> 1, + .y = dpi->y >> 1, .height = dpi->height>>1, .width = dpi->width>>1, .pitch = dpi->pitch, @@ -1049,7 +1049,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in gfx_draw_sprite_palette_set(&zoomed_dpi, (image_type << 28) | (image_element - g1_source->zoomed_offset), x >> 1, y >> 1, palette_pointer, unknown_pointer); return; } - + if ( dpi->zoom_level && (g1_source->flags & (1<<5)) ){ return; } @@ -1059,7 +1059,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in //This will be the height of the drawn image int height = g1_source->height >> zoom_level; //This is the start y coordinate on the destination - sint16 dest_start_y = (y + g1_source->y_offset - (uint16)dpi->y) >> zoom_level; + sint16 dest_start_y = ((sint16)y + g1_source->y_offset - dpi->y) >> zoom_level; //This is the start y coordinate on the source int source_start_y = 0; @@ -1094,7 +1094,7 @@ void gfx_draw_sprite_palette_set(rct_drawpixelinfo *dpi, int image_id, int x, in //This is the source start x coordinate int source_start_x = 0; //This is the destination start x coordinate - sint16 dest_start_x = (x + g1_source->x_offset - (uint16)dpi->x)>>zoom_level; + sint16 dest_start_x = ((sint16)x + g1_source->x_offset - dpi->x) >> zoom_level; if (dest_start_x < 0){ //If the destination is negative reduce the width diff --git a/src/viewport.c b/src/viewport.c index 0ffa77b740..ca82a26202 100644 --- a/src/viewport.c +++ b/src/viewport.c @@ -296,8 +296,8 @@ void sub_0x68615B(int ebp){ */ void paint_attached_ps(paint_struct* ps, paint_struct* attached_ps, rct_drawpixelinfo* dpi){ for (; attached_ps; attached_ps = attached_ps->next_attached_ps){ - int x = attached_ps->attached_x + ps->x; - int y = attached_ps->attached_y + ps->y; + sint16 x = attached_ps->attached_x + ps->x; + sint16 y = attached_ps->attached_y + ps->y; int image_id = attached_ps->image_id; if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_SEETHROUGH_RIDES){ @@ -335,8 +335,8 @@ void sub_688485(){ paint_struct* previous_ps = ps->var_24; for (ps = ps->var_24; ps;){ - int x = ps->x; - int y = ps->y; + sint16 x = ps->x; + sint16 y = ps->y; if (ps->sprite_type == 2){ if (dpi->zoom_level >= 1){ x &= 0xFFFE;