diff --git a/src/gfx.c b/src/gfx.c index b81bd39c99..59350e680d 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -700,7 +700,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< 0; no_pixels -= (1< 0; no_pixels -= (1<width + (int)dpi->pitch; + next_dest_pointer += (int)(dpi->width >> zoom_level) + (int)dpi->pitch; } } /** * * 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_X111_1111_1XXX_XXXX_XXXX_XXXX_XXXX palette_ref + * 0b_XXXX_XXXX_XXXX_X111_1111_1111_1111_1111 image_id (offset to g1) * x (cx) * y (dx) * dpi (esi) - * (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; 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)){ - //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[(image_id >> 19) & 0x1F]; + uint32 secondary_offset = palette_to_g1_offset[(image_id >> 24) & 0x1F]; + uint32 tertiary_offset = palette_to_g1_offset[tertiary_colour]; - 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*)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; - 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; @@ -1049,44 +1023,43 @@ 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 = dpi->x >> 1, + .y = 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; } - - //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 - dpi->y + g1_source->y_offset; + 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; @@ -1108,20 +1081,20 @@ 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; - //If the image no longer has anything to draw - if (height <= 0)return; + height -= dest_end_y - (dpi->height >> zoom_level); } - + //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 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 = ((sint16)x + g1_source->x_offset - dpi->x) >> zoom_level; if (dest_start_x < 0){ //If the destination is negative reduce the width @@ -1139,10 +1112,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; } @@ -1150,7 +1123,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; diff --git a/src/gfx.h b/src/gfx.h index c66c433c5e..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{ @@ -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); diff --git a/src/viewport.c b/src/viewport.c index 63d9ecfbe0..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; @@ -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; 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){