1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-02-02 19:56:13 +01:00

Merge pull request #239 from duncanspumpkin/viewport_paint

Viewport paint
This commit is contained in:
Ted John
2014-07-27 22:54:20 +01:00
6 changed files with 314 additions and 35 deletions

View File

@@ -86,6 +86,17 @@
#define RCT2_ADDRESS_LIGHTNING_ACTIVE 0x009AC068
#define RCT2_ADDRESS_VIEWPORT_PAINT_BITS_PTR 0x009AC118
#define RCT2_ADDRESS_VIEWPORT_PAINT_X 0x009AC11C
#define RCT2_ADDRESS_VIEWPORT_PAINT_Y 0x009AC11E
#define RCT2_ADDRESS_VIEWPORT_PAINT_WIDTH 0x009AC120
#define RCT2_ADDRESS_VIEWPORT_PAINT_HEIGHT 0x009AC122
#define RCT2_ADDRESS_VIEWPORT_PAINT_PITCH 0x009AC124
#define RCT2_ADDRESS_VIEWPORT_DPI 0x009AC128
#define RCT2_ADDRESS_VIEWPORT_ZOOM 0x009AC126
#define RCT2_ADDRESS_RUN_INTRO_TICK_PART 0x009AC319
#define RCT2_ADDRESS_INSTALLED_OBJECT_LIST 0x009ADAE8
@@ -268,6 +279,8 @@
#define RCT2_ADDRESS_GAME_COMMAND_ERROR_STRING_ID 0x0141E9AE
#define RCT2_ADDRESS_CURRENT_ROTATION 0x0141E9E0
#define RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS 0x0141E9E4
#define RCT2_ADDRESS_FONT_CHAR_WIDTH 0x0141E9E8
#define RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER 0x0141ED68

View File

@@ -34,7 +34,8 @@
rct_viewport* g_viewport_list = RCT2_ADDRESS(RCT2_ADDRESS_VIEWPORT_LIST, rct_viewport);
/**
*
* This is not a viewport function. It is used to setup many variables for
* multiple things.
* rct2: 0x006E6EAC
*/
void viewport_init_all()
@@ -109,23 +110,25 @@ void center_2d_coordinates(int x, int y, int z, int* out_x, int* out_y, rct_view
}
/**
*
* rct2: 0x006EB009
* x: ax
* y: eax (top 16)
* width: bx
* height: ebx (top 16)
* zoom: cl (8 bits)
* ecx: ecx (top 16 bits see zoom)
* edx: edx
* w: esi
*/
void viewport_create(rct_window *w, int x, int y, int width, int height, int zoom, int ecx, int edx)
*
* rct2: 0x006EB009
* x: ax
* y: eax (top 16)
* width: bx
* height: ebx (top 16)
* zoom: cl (8 bits)
* center_x: edx lower 16 bits
* center_y: edx upper 16 bits
* center_z: ecx upper 16 bits
* sprite: edx lower 16 bits
* flags: edx top most 2 bits 0b_X1 for zoom clear see below for 2nd bit.
* w: esi
*
* Viewport will look at sprite or at coordinates as specified in flags 0b_1X for sprite 0b_0X for coordinates
*/
void viewport_create(rct_window *w, int x, int y, int width, int height, int zoom, int center_x, int center_y, int center_z, char flags, sint16 sprite)
{
rct_viewport* viewport;
int eax = 0xFF000001;
int ebx = -1;
for (viewport = g_viewport_list; viewport->width != 0; viewport++){
if (viewport >= RCT2_ADDRESS(RCT2_ADDRESS_NEW_VIEWPORT_PTR, rct_viewport)){
error_string_quit(0xFF000001, -1);
@@ -137,10 +140,9 @@ void viewport_create(rct_window *w, int x, int y, int width, int height, int zoo
viewport->width = width;
viewport->height = height;
if (!(edx & (1 << 30))){
if (!(flags & (1 << 0))){
zoom = 0;
}
edx &= ~(1 << 30);
viewport->view_width = width << zoom;
viewport->view_height = height << zoom;
@@ -151,20 +153,15 @@ void viewport_create(rct_window *w, int x, int y, int width, int height, int zoo
viewport->flags |= VIEWPORT_FLAG_GRIDLINES;
}
w->viewport = viewport;
int center_x, center_y, center_z;
if (edx & (1 << 31)){
edx &= 0xFFFF;
w->viewport_target_sprite = edx;
rct_sprite* sprite = &g_sprite_list[edx];
center_x = sprite->unknown.x;
center_y = sprite->unknown.y;
center_z = sprite->unknown.z;
if (flags & (1<<1)){
w->viewport_target_sprite = sprite;
rct_sprite* center_sprite = &g_sprite_list[sprite];
center_x = center_sprite->unknown.x;
center_y = center_sprite->unknown.y;
center_z = center_sprite->unknown.z;
}
else{
center_x = edx & 0xFFFF;
center_y = edx >> 16;
center_z = ecx >> 16;
w->viewport_target_sprite = SPR_NONE;
}
@@ -253,6 +250,176 @@ void viewport_render(rct_drawpixelinfo *dpi, rct_viewport *viewport, int left, i
viewport_paint(viewport, dpi, left, top, right, bottom);
}
/**
* Readies the viewport for underground view/remove base land/remove vert faces
* rct2:0x00678A9F
* edi: dpi
* ebp: colour
*/
void viewport_paint_underground_setup(rct_drawpixelinfo* dpi, uint8 colour){
uint8* bits_pointer = dpi->bits;
for (int i = dpi->height >> dpi->zoom_level; i != 0; --i){
memset(bits_pointer, colour, dpi->width >> dpi->zoom_level);
bits_pointer += (dpi->width >> dpi->zoom_level) + dpi->pitch;
}
}
/**
*
* rct2: 0x0068615B
* ebp: ebp
*/
void sub_0x68615B(int ebp){
RCT2_GLOBAL(0xEE7888, uint32) = ebp;
RCT2_GLOBAL(0xF1AD28, uint32) = 0;
RCT2_GLOBAL(0xF1AD2C, uint32) = 0;
uint8* edi = RCT2_ADDRESS(0xF1A50C, uint8);
memset(edi, 0, 2048);
RCT2_GLOBAL(0xF1AD0C, sint32) = -1;
RCT2_GLOBAL(0xF1AD10, uint32) = 0;
RCT2_GLOBAL(0xF1AD20, uint32) = 0;
RCT2_GLOBAL(0xF1AD24, uint32) = 0;
}
/**
*
* rct2: 0x0068615B
* ebp: ebp
*/
void sub_0x68B6C2(){
rct_drawpixelinfo* dpi = RCT2_GLOBAL(0x140E9A8, rct_drawpixelinfo*);
sint16 ax, bx, cx, dx;
switch (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32)){
case 0:
ax = dpi->y;
bx = dpi->x;
ax -= 16;
bx &= 0xFFE0;
ax &= 0xFFE0;
bx >>= 1;
cx = ax;
ax -= bx;
cx += bx;
ax &= 0xFFE0;
cx &= 0xFFE0;
dx = dpi->height;
dx += 2128;
dx >>= 5;
for (int i = dx; i > 0; --i){
RCT2_CALLPROC_X(0x68B35F, ax, 0, cx, 0, 0, 0, 0);
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
cx += 0x20;
ax -= 0x20;
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
ax += 0x20;
RCT2_CALLPROC_X(0x68B35F, ax, 0, cx, 0, 0, 0, 0);
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
ax += 0x20;
cx -= 0x20;
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
cx += 0x20;
}
break;
case 1:
ax = dpi->y;
bx = dpi->x;
ax -= 0x10;
bx &= 0xFFE0;
ax &= 0xFFE0;
bx >>= 1;
cx = ax;
ax = -ax;
ax -= bx;
cx -= bx;
cx -= 0x10;
ax &= 0xFFE0;
cx &= 0xFFE0;
dx = dpi->height;
dx += 0x860;
dx >>= 5;
for (int i = dx; i > 0; i--){
RCT2_CALLPROC_X(0x68B35F, ax, 0, cx, 0, 0, 0, 0);
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
ax -= 0x20;
cx -= 0x20;
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
cx += 0x20;
RCT2_CALLPROC_X(0x68B35F, ax, 0, cx, 0, 0, 0, 0);
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
ax += 0x20;
cx += 0x20;
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
ax -= 0x20;
}
break;
case 2:
ax = dpi->y;
bx = dpi->x;
ax -= 0x10;
bx &= 0xFFE0;
ax &= 0xFFE0;
bx >>= 1;
ax = -ax;
cx = ax;
ax += bx;
cx -= bx;
ax &= 0xFFE0;
cx &= 0xFFE0;
dx = dpi->height;
dx += 0x860;
dx >>= 5;
for (int i = dx; i > 0; i--){
RCT2_CALLPROC_X(0x68B35F, ax, 0, cx, 0, 0, 0, 0);
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
ax += 0x20;
cx -= 0x20;
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
ax -= 0x20;
RCT2_CALLPROC_X(0x68B35F, ax, 0, cx, 0, 0, 0, 0);
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
ax -= 0x20;
cx += 0x20;
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
cx -= 0x20;
}
break;
case 3:
ax = dpi->y;
bx = dpi->x;
ax -= 0x10;
bx &= 0xFFE0;
ax &= 0xFFE0;
bx >>= 1;
cx = ax;
ax += bx;
cx = -cx;
cx += bx;
cx -= 0x10;
ax &= 0xFFE0;
cx &= 0xFFE0;
dx = dpi->height;
dx += 0x860;
dx >>= 5;
for (int i = dx; i > 0; i--){
RCT2_CALLPROC_X(0x68B35F, ax, 0, cx, 0, 0, 0, 0);
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
ax += 0x20;
cx += 0x20;
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
cx -= 0x20;
RCT2_CALLPROC_X(0x68B35F, ax, 0, cx, 0, 0, 0, 0);
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
ax -= 0x20;
cx -= 0x20;
RCT2_CALLPROC_X(0x69E8B0, ax, 0, cx, 0, 0, 0, 0);
ax += 0x20;
}
break;
}
}
/**
*
* rct2:0x00685CBF
@@ -264,7 +431,100 @@ void viewport_render(rct_drawpixelinfo *dpi, rct_viewport *viewport, int left, i
* ebp: bottom
*/
void viewport_paint(rct_viewport* viewport, rct_drawpixelinfo* dpi, int left, int top, int right, int bottom){
RCT2_CALLPROC_X(0x00685CBF, left, top, 0, right, (int)viewport, (int)dpi, bottom);
//RCT2_CALLPROC_X(0x00685CBF, left, top, 0, right, (int)viewport, (int)dpi, bottom);
//return;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) = viewport->flags;
RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16) = viewport->zoom;
uint16 width = right - left;
uint16 height = bottom - top;
uint16 bitmask = 0xFFFF & (0xFFFF << viewport->zoom);
width &= bitmask;
height &= bitmask;
left &= bitmask;
top &= bitmask;
RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, uint16) = left;
RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_Y, uint16) = top;
RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_WIDTH, uint16) = width;
RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_HEIGHT, uint16) = height;
width >>= viewport->zoom;
RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_PITCH, uint16) = (dpi->width + dpi->pitch) - width;
int x = (sint16)(left - (sint16)(viewport->view_x & bitmask));
x >>= viewport->zoom;
x += viewport->x;
int y = (sint16)(top - (sint16)(viewport->view_y & bitmask));
y >>= viewport->zoom;
y += viewport->y;
uint8* bits_pointer = x - dpi->x + (y - dpi->y)*(dpi->width + dpi->pitch) + dpi->bits;
RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_BITS_PTR, uint8*) = bits_pointer;
rct_drawpixelinfo* dpi2 = RCT2_ADDRESS(RCT2_ADDRESS_VIEWPORT_DPI, rct_drawpixelinfo);
dpi2->y = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_Y, uint16);
dpi2->height = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_HEIGHT, uint16);
dpi2->zoom_level = (uint8)RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16);
//Splits the screen into 32 pixel columns and renders them.
for (x = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, uint16) & 0xFFFFFFE0;
x < RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, uint16) + RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_WIDTH, uint16);
x += 32){
int start_x = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, uint16);
int width_col = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_WIDTH, uint16);
bits_pointer = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_BITS_PTR, uint8*);
int pitch = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_PITCH, uint16);
int zoom = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16);
if (x >= start_x){
int left_pitch = x - start_x;
width_col -= left_pitch;
bits_pointer += left_pitch >> zoom;
pitch += left_pitch >> zoom;
start_x = x;
}
int paint_right = start_x + width_col;
if (paint_right >= x + 32){
int right_pitch = paint_right - x - 32;
paint_right -= right_pitch;
pitch += right_pitch >> zoom;
}
width_col = paint_right - start_x;
dpi2->x = start_x;
dpi2->width = width_col;
dpi2->bits = bits_pointer;
dpi2->pitch = pitch;
if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & 0x3001){
uint8 colour = 0x0A;
if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & 0x4000){
colour = 0;
}
viewport_paint_underground_setup(dpi2, colour);
}
RCT2_GLOBAL(0xEE7880, uint32) = 0xF1A4CC;
RCT2_GLOBAL(0x140E9A8, uint32) = (int)dpi2;
int ebp = 0, ebx = 0, esi = 0, ecx = 0;
sub_0x68615B(0xEE788C); //Memory copy
sub_0x68B6C2();
//RCT2_CALLPROC_X(0x68B6C2, 0, 0, 0, 0, 0, 0, 0); //Big function call 4 rotation versions
RCT2_CALLFUNC_X(0x688217, &start_x, &ebx, &ecx, (int*)&bits_pointer, &esi, (int*)&dpi2, &ebp); //Move memory
RCT2_CALLFUNC_X(0x688485, &start_x, &ebx, &ecx, (int*)&bits_pointer, &esi, (int*)&dpi2, &ebp); //Big function call
int weather_colour = RCT2_ADDRESS(0x98195C, uint32)[RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER_GLOOM, uint8)];
if ((weather_colour != -1) && (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & 0x4000) && (RCT2_GLOBAL(0x9DEA6F, uint8) & 1)){
dpi2 = RCT2_GLOBAL(0x140E9A8, rct_drawpixelinfo*);
gfx_fill_rect(dpi2, dpi2->x, dpi2->y, dpi2->width + dpi2->x - 1, dpi2->height + dpi2->y - 1, weather_colour);
}
RCT2_CALLPROC_EBPSAFE(0x6860C3); //string related
}
//RCT2_CALLPROC_X(0x00685CBF, left, top, 0, right, (int)viewport, (int)dpi, bottom);
}
/**

View File

@@ -46,7 +46,7 @@ enum {
extern rct_viewport* g_viewport_list;
void viewport_init_all();
void viewport_create(rct_window *w, int x, int y, int width, int height, int zoom, int ecx, int edx);
void viewport_create(rct_window *w, int x, int y, int width, int height, int zoom, int center_x, int center_y, int center_z, char flags, sint16 sprite);
void viewport_update_pointers();
void viewport_update_position(rct_window *window);
void viewport_render(rct_drawpixelinfo *dpi, rct_viewport *viewport, int left, int top, int right, int bottom);

View File

@@ -141,7 +141,10 @@ void window_banner_open()
(viewportWidget->bottom - viewportWidget->top) - 2,
0,
100, // TODO: needs banner map position
100 // TODO: needs banner map position
100, // TODO: needs banner map position
100,
0,
-1
);
w->viewport->flags = (RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_FLAGS, uint8) & CONFIG_FLAG_ALWAYS_SHOW_GRIDLINES) ? VIEWPORT_FLAG_GRIDLINES : 0;

View File

@@ -81,7 +81,7 @@ void window_main_open()
);
window->widgets = window_main_widgets;
viewport_create(window, window->x, window->y, window->width, window->height, 0, 0x40000000, 0x0FFF0FFF);
viewport_create(window, window->x, window->y, window->width, window->height, 0,0x0FFF,0x0FFF, 0, 0x1, -1);
window->viewport->flags |= 0x0400;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, sint32) = 0;
RCT2_GLOBAL(0x009E32B0, uint8) = 0;

View File

@@ -1167,8 +1167,11 @@ static void window_park_init_viewport(rct_window *w)
(viewportWidget->right - viewportWidget->left) - 2,
(viewportWidget->bottom - viewportWidget->top) - 2,
zr&0xFF,
zr,
xy
x,
y,
z,
xy&0xC0000000 >> 30,
-1
);
w->flags |= (1 << 2);
window_invalidate(w);