From 0245d3ad026227dbe93c6c88eb7ff609c543519f Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Tue, 31 May 2016 23:41:19 +0200 Subject: [PATCH 01/44] Flags --- src/common.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common.h b/src/common.h index ad7871fca9..d8a05a6f2e 100644 --- a/src/common.h +++ b/src/common.h @@ -49,4 +49,8 @@ #define FASTCALL #endif // PLATFORM_X86 +#define STOUT_EXPANDED_RENDERING +#define STOUT_EXPANDED_RENDERING_MTT +#define STOUT_EXPANDED_RENDERING_LIGHT + #endif From f5783231c0a223f2fc054834f4b67a0a5fd16c06 Mon Sep 17 00:00:00 2001 From: JeroenDStout Date: Tue, 31 May 2016 23:49:58 +0200 Subject: [PATCH 02/44] Lightfx --- src/paint/map_element/entrance.c | 31 +++ src/paint/map_element/path.c | 31 ++- src/paint/sprite/peep.c | 32 +++ src/platform/platform.h | 1 + src/platform/shared.c | 384 +++++++++++++++++++++++++++---- src/rct2.c | 13 ++ src/ride/vehicle_paint.c | 105 ++++++++- 7 files changed, 553 insertions(+), 44 deletions(-) diff --git a/src/paint/map_element/entrance.c b/src/paint/map_element/entrance.c index 48f0f1e68e..11d98e6803 100644 --- a/src/paint/map_element/entrance.c +++ b/src/paint/map_element/entrance.c @@ -24,6 +24,7 @@ #include "../../ride/ride_data.h" #include "../../world/entrance.h" #include "../../world/footpath.h" +#include "../../drawing/lightfx.h" #include "map_element.h" /** @@ -32,6 +33,7 @@ */ void ride_entrance_exit_paint(uint8 direction, int height, rct_map_element* map_element) { + uint8 is_exit = map_element->properties.entrance.type == ENTRANCE_TYPE_RIDE_EXIT; if (RCT2_GLOBAL(0x9DEA6F, uint8_t) & 1){ @@ -39,6 +41,29 @@ void ride_entrance_exit_paint(uint8 direction, int height, rct_map_element* map_ return; } +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + + if (!is_exit) { + lightfx_add_3d_light_magic_from_drawing_tile(0, 0, height + 45, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + + switch (map_element->type & MAP_ELEMENT_DIRECTION_MASK) { + case 0: + lightfx_add_3d_light_magic_from_drawing_tile(16, 0, height + 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); + break; + case 1: + lightfx_add_3d_light_magic_from_drawing_tile(0, -16, height + 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); + break; + case 2: + lightfx_add_3d_light_magic_from_drawing_tile(-16, 0, height + 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); + break; + case 3: + lightfx_add_3d_light_magic_from_drawing_tile(0, 16, height + 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); + break; + }; + +#endif + rct_ride* ride = get_ride(map_element->properties.entrance.ride_index); if (ride->entrance_style == RIDE_ENTRANCE_STYLE_NONE) return; @@ -163,6 +188,12 @@ void park_entrance_paint(uint8 direction, int height, rct_map_element* map_eleme if (RCT2_GLOBAL(0x9DEA6F, uint8_t) & 1) return; +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + + lightfx_add_3d_light_magic_from_drawing_tile(0, 0, 155, LIGHTFX_LIGHT_TYPE_LANTERN_3); + +#endif + gPaintInteractionType = VIEWPORT_INTERACTION_ITEM_PARK; RCT2_GLOBAL(0x009E32BC, uint32) = 0; uint32 image_id, ghost_id = 0; diff --git a/src/paint/map_element/path.c b/src/paint/map_element/path.c index ce9b3b83e4..42b5090220 100644 --- a/src/paint/map_element/path.c +++ b/src/paint/map_element/path.c @@ -17,6 +17,9 @@ #include "map_element.h" #include "../../addresses.h" #include "../../world/map.h" +#include "../../world/scenery.h" +#include "../../drawing/lightfx.h" +#include "../../world/footpath.h" // #3628: Until path_paint is implemented, this variable is used by scrolling_text_setup // to use the old string arguments array. Remove when scrolling_text_setup is no @@ -27,4 +30,30 @@ void path_paint(uint8 direction, uint16 height, rct_map_element *mapElement) { TempForScrollText = true; RCT2_CALLPROC_X(0x6A3590, 0, 0, direction, height, (int)mapElement, 0, 0); TempForScrollText = false; -} + +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + + if (footpath_element_has_path_scenery(mapElement)) { + rct_scenery_entry *sceneryEntry; + + sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(mapElement)); + + if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_LAMP) { + + if (!(mapElement->properties.path.edges & (1 << 0))) { + lightfx_add_3d_light_magic_from_drawing_tile(-16, 0, height + 23, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + if (!(mapElement->properties.path.edges & (1 << 1))) { + lightfx_add_3d_light_magic_from_drawing_tile(0, 16, height + 23, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + if (!(mapElement->properties.path.edges & (1 << 2))) { + lightfx_add_3d_light_magic_from_drawing_tile(16, 0, height + 23, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + if (!(mapElement->properties.path.edges & (1 << 3))) { + lightfx_add_3d_light_magic_from_drawing_tile(0, -16, height + 23, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + } + } +#endif + +} diff --git a/src/paint/sprite/peep.c b/src/paint/sprite/peep.c index 5ce823c651..60d69b384c 100644 --- a/src/paint/sprite/peep.c +++ b/src/paint/sprite/peep.c @@ -18,6 +18,7 @@ #include "../../interface/viewport.h" #include "../../peep/peep.h" #include "../paint.h" +#include "../../drawing/lightfx.h" /** * @@ -25,6 +26,37 @@ */ void peep_paint(rct_peep * peep, int imageDirection) { +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + + if (peep->type == PEEP_TYPE_STAFF){ + sint16 peep_x, peep_y, peep_z; + + peep_x = peep->x; + peep_y = peep->y; + peep_z = peep->z; + + switch (peep->sprite_direction) { + case 0: + peep_x -= 10; + break; + case 8: + peep_y += 10; + break; + case 16: + peep_x += 10; + break; + case 24: + peep_y -= 10; + break; + default: + return; + }; + + lightfx_add_3d_light(peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_SPOT_1); + } + +#endif + rct_drawpixelinfo * dpi = RCT2_GLOBAL(0x140E9A8, rct_drawpixelinfo*); if (dpi->zoom_level > 2) { return; diff --git a/src/platform/platform.h b/src/platform/platform.h index dccafe8e92..f792d82f6d 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -124,6 +124,7 @@ void platform_update_fullscreen_resolutions(); void platform_get_closest_resolution(int inWidth, int inHeight, int *outWidth, int *outHeight); void platform_init(); void platform_draw(); +void platform_draw_require_end(); void platform_free(); void platform_trigger_resize(); void platform_update_palette(const uint8 *colours, int start_index, int num_colours); diff --git a/src/platform/shared.c b/src/platform/shared.c index fd68199744..e14591b6b0 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -31,6 +31,7 @@ #include "../title.h" #include "../util/util.h" #include "../world/climate.h" +#include "../drawing/lightfx.h" #include "platform.h" typedef void(*update_palette_func)(const uint8*, int, int); @@ -55,7 +56,9 @@ SDL_Renderer *gRenderer = NULL; SDL_Texture *gBufferTexture = NULL; SDL_PixelFormat *gBufferTextureFormat = NULL; SDL_Color gPalette[256]; +SDL_Color gPalette_light[256]; uint32 gPaletteHWMapped[256]; +uint32 gPaletteHWMapped_light[256]; bool gHardwareDisplay; bool gSteamOverlayActive = false; @@ -65,6 +68,8 @@ static SDL_Surface *_RGBASurface = NULL; static SDL_Palette *_palette = NULL; static void *_screenBuffer; +static void *_screenBuffer_back; +static rct_drawpixelinfo _screenDPI_back; static int _screenBufferSize; static int _screenBufferWidth; static int _screenBufferHeight; @@ -217,6 +222,120 @@ static void overlay_post_render_check(int width, int height) { overlayActive = newOverlayActive; } +typedef enum { + MTT_STATE_LOCK, + MTT_STATE_WAITING, + MTT_STATE_RENDER +} +dialog_type; + +static int _mtt_screen_width; +static int _mtt_screen_height; +static int _mtt_pitch; +static void* _mtt_screenBuffer; +static void* _mtt_pixels; +static uint8 _mtt_state = MTT_STATE_LOCK; +static SDL_Thread *_mtt_thread; +static uint32 _mtt_palette_base[256]; +static uint32 _mtt_palette_light[256]; +static uint16 _mtt_palette_base_rich[256*4]; +static uint16 _mtt_palette_light_rich[256*4]; + +int platform_draw_hardware(void *dat) +{ + uint8 *src = (uint8*)_mtt_screenBuffer; + int padding = _mtt_pitch - (_mtt_screen_width * 4); + if (_mtt_pitch == _mtt_screen_width * 4) { + uint32 *dst = _mtt_pixels; + +#ifndef STOUT_EXPANDED_RENDERING_LIGHT + + for (int i = _mtt_screen_width * _mtt_screen_height; i > 0; i--) { + *dst++ = *(uint32 *)(&_mtt_palette_base[*src++]); + } + +#else + + lightfx_render_lights_to_frontbuffer(); + + for (int i = 0; i < 256; i++) { + _mtt_palette_base_rich[i * 4 + 0] = (0xFF00 & (_mtt_palette_base[i] >> 8)); + _mtt_palette_base_rich[i * 4 + 1] = (0xFF00 & (_mtt_palette_base[i] >> 0)); + _mtt_palette_base_rich[i * 4 + 2] = (0xFF00 & (_mtt_palette_base[i] << 8)); + _mtt_palette_light_rich[i * 4 + 0] = (0xFF0 & (_mtt_palette_light[i] >> 12)); + _mtt_palette_light_rich[i * 4 + 1] = (0xFF0 & (_mtt_palette_light[i] >> 4)); + _mtt_palette_light_rich[i * 4 + 2] = (0xFF0 & (_mtt_palette_light[i] << 4)); + } + + const uint8 *lightFXBuf = (uint8*)lightfx_get_front_buffer(); + + for (int i = _mtt_screen_width * _mtt_screen_height; i > 0; i--) { + uint32 srcIndex = *src * 4; + + *dst = ((0xFF00 & (min(0xFF00, _mtt_palette_base_rich[srcIndex + 0] + (_mtt_palette_light_rich[srcIndex + 0] * *lightFXBuf)))) << 8) | + ((0xFF00 & (min(0xFF00, _mtt_palette_base_rich[srcIndex + 1] + (_mtt_palette_light_rich[srcIndex + 1] * *lightFXBuf)))) << 0) | + ((0xFF00 & (min(0xFF00, _mtt_palette_base_rich[srcIndex + 2] + (_mtt_palette_light_rich[srcIndex + 2] * *lightFXBuf)))) >> 8); + dst++; + src++; + lightFXBuf++; + } + +#endif + + } + else if (_mtt_pitch == (_mtt_screen_width * 2) + padding) { + uint16 *dst = _mtt_pixels; + for (int y = _mtt_screen_height; y > 0; y--) { + for (int x = _mtt_screen_width; x > 0; x--) { + const uint8 lower = *(uint8 *)(&_mtt_palette_base[*src++]); + const uint8 upper = *(uint8 *)(&_mtt_palette_base[*src++]); + *dst++ = (lower << 8) | upper; + } + dst = (uint16*)(((uint8 *)dst) + padding); + } + } + else if (_mtt_pitch == _mtt_screen_width + padding) { + uint8 *dst = _mtt_pixels; + for (int y = _mtt_screen_height; y > 0; y--) { + for (int x = _mtt_screen_width; x > 0; x--) { *dst++ = *(uint8 *)(&_mtt_palette_base[*src++]); } + dst += padding; + } + } + + return 1; +} + +static void platfrom_do_render() +{ + SDL_UnlockTexture(gBufferTexture); + + SDL_RenderCopy(gRenderer, gBufferTexture, NULL, NULL); + + if (gSteamOverlayActive && gConfigGeneral.steam_overlay_pause) { + overlay_pre_render_check(_mtt_screen_width, _mtt_screen_height); + } + + SDL_RenderPresent(gRenderer); + + if (gSteamOverlayActive && gConfigGeneral.steam_overlay_pause) { + overlay_post_render_check(_mtt_screen_width, _mtt_screen_height); + } + + _mtt_state = MTT_STATE_LOCK; +} + +void platform_draw_require_end() +{ +#ifdef STOUT_EXPANDED_RENDERING_MTT + if (_mtt_state == MTT_STATE_WAITING) { + int out; + SDL_WaitThread(_mtt_thread, &out); + platfrom_do_render(); + } +#endif + +} + void platform_draw() { int width = gScreenWidth; @@ -224,48 +343,57 @@ void platform_draw() if (!gOpenRCT2Headless) { if (gHardwareDisplay) { - void *pixels; - int pitch; - if (SDL_LockTexture(gBufferTexture, NULL, &pixels, &pitch) == 0) { - uint8 *src = (uint8*)_screenBuffer; - int padding = pitch - (width * 4); - if (pitch == width * 4) { - uint32 *dst = pixels; - for (int i = width * height; i > 0; i--) { *dst++ = *(uint32 *)(&gPaletteHWMapped[*src++]); } - } - else - if (pitch == (width * 2) + padding) { - uint16 *dst = pixels; - for (int y = height; y > 0; y--) { - for (int x = width; x > 0; x--) { - const uint8 lower = *(uint8 *)(&gPaletteHWMapped[*src++]); - const uint8 upper = *(uint8 *)(&gPaletteHWMapped[*src++]); - *dst++ = (lower << 8) | upper; - } - dst = (uint16*)(((uint8 *)dst) + padding); - } + _mtt_screen_width = width; + _mtt_screen_height = height; + +#ifdef STOUT_EXPANDED_RENDERING_MTT + platform_draw_require_end(); + if (_mtt_state == MTT_STATE_RENDER) { + platfrom_do_render(); + } +#endif + + if (_mtt_state == MTT_STATE_LOCK) { + if (SDL_LockTexture(gBufferTexture, NULL, &_mtt_pixels, &_mtt_pitch) == 0) { +#ifndef STOUT_EXPANDED_RENDERING_MTT + platform_draw_hardware(0); + platfrom_do_render(); +#else + + // Swap back and front + + void *tmp = _screenBuffer_back; + _screenBuffer_back = _screenBuffer; + _screenBuffer = tmp; + rct_drawpixelinfo tmpPx; + memcpy(&tmpPx, &gScreenDPI, sizeof(rct_drawpixelinfo)); + memcpy(&gScreenDPI, &_screenDPI_back, sizeof(rct_drawpixelinfo)); + memcpy(&_screenDPI_back, &tmpPx, sizeof(rct_drawpixelinfo)); + + // This messes up drawing, so force a full redraw + + gfx_invalidate_screen(); + + lightfx_add_3d_light(gCursorState.x, gCursorState.y, 0x7FFF, LIGHTFX_LIGHT_TYPE_LANTERN_3); + + lightfx_prepare_light_list(); + lightfx_swap_buffers(); + + // Make palette safe + + for (int i = 0; i < 256; i++) { + _mtt_palette_base[i] = gPaletteHWMapped[i]; + _mtt_palette_light[i] = gPaletteHWMapped_light[i]; } - else - if (pitch == width + padding) { - uint8 *dst = pixels; - for (int y = height; y > 0; y--) { - for (int x = width; x > 0; x--) { *dst++ = *(uint8 *)(&gPaletteHWMapped[*src++]); } - dst += padding; - } - } - SDL_UnlockTexture(gBufferTexture); - } - SDL_RenderCopy(gRenderer, gBufferTexture, NULL, NULL); - - if (gSteamOverlayActive && gConfigGeneral.steam_overlay_pause) { - overlay_pre_render_check(width, height); - } - - SDL_RenderPresent(gRenderer); - - if (gSteamOverlayActive && gConfigGeneral.steam_overlay_pause) { - overlay_post_render_check(width, height); + _mtt_screenBuffer = _screenBuffer_back; + _mtt_thread = SDL_CreateThread(&platform_draw_hardware, "Blit", 0); + _mtt_state = MTT_STATE_WAITING; +#endif + } + else { + _mtt_state = MTT_STATE_LOCK; + } } } else { @@ -314,6 +442,8 @@ void platform_draw() static void platform_resize(int width, int height) { + platform_draw_require_end(); + uint32 flags; int dst_w = (int)(width / gConfigGeneral.window_scale); int dst_h = (int)(height / gConfigGeneral.window_scale); @@ -390,8 +520,21 @@ static uint8 lerp(uint8 a, uint8 b, float t) return (uint8)(a + amount); } +static float flerp(float a, float b, float t) +{ + if (t <= 0) return a; + if (t >= 1) return b; + + float range = b - a; + float amount = range * t; + return a + amount; +} + void platform_update_palette(const uint8* colours, int start_index, int num_colours) { + start_index= 0; + num_colours= 256; + SDL_Surface *surface; int i; colours += start_index * 4; @@ -402,16 +545,138 @@ void platform_update_palette(const uint8* colours, int start_index, int num_colo gPalette[i].b = colours[0]; gPalette[i].a = 0; - float night = gDayNightCycle; - if (night >= 0 && gClimateLightningFlash == 0) { + float night = (float)(pow(gDayNightCycle, 1.5)); + +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + + float natLightR = 1.0f; + float natLightG = 1.0f; + float natLightB = 1.0f; + + static float wetness = 0.0f; + static float fogginess = 0.0f; + + float sunLight = max(0.0f, min(1.0f, 2.0f - night * 3.0f)); + + // Night version + natLightR = flerp(natLightR * 4.0f, 0.335f, (float)(pow(night, 0.035f + sunLight * 10.50f))); + natLightG = flerp(natLightG * 4.0f, 0.350f, (float)(pow(night, 0.100f + sunLight * 5.50f))); + natLightB = flerp(natLightB * 4.0f, 0.550f, (float)(pow(night, 0.200f + sunLight * 1.5f))); + + float lightAvg = (natLightR + natLightG + natLightB) / 3.0f; + float lightMax = (natLightR + natLightG + natLightB) / 3.0f; + float overExpose = 0.0f; + + // overExpose += ((lightMax - lightAvg) / lightMax) * 0.01f; + + if (gClimateCurrentTemperature > 20) { + float offset = ((float)(gClimateCurrentTemperature - 20)) * 0.04f; + offset *= 1.0f - night; + lightAvg /= 1.0f + offset; + // overExpose += offset * 0.1f; + } + + // lightAvg += (lightMax - lightAvg) * 0.6f; + + if (lightAvg > 1.0f) { + natLightR /= lightAvg; + natLightG /= lightAvg; + natLightB /= lightAvg; + } + + natLightR *= 1.0f + overExpose; + natLightG *= 1.0f + overExpose; + natLightB *= 1.0f + overExpose; + overExpose *= 255.0f; + + float targetFogginess = (float)(gClimateCurrentRainLevel) / 5.0f; + targetFogginess += (night * night) * 0.35f; + + if (gClimateCurrentTemperature < 10) { + targetFogginess += ((float)(10 - gClimateCurrentTemperature)) * 0.01f; + } + + fogginess -= (fogginess - targetFogginess) * 0.00001f; + + wetness *= 0.999995f; + wetness += fogginess * 0.001f; + wetness = min(wetness, 1.0f); + + float boost = 1.0f; + float envFog = fogginess; + float lightFog = envFog; + + float addLightNatR = 0.0f; + float addLightNatG = 0.0f; + float addLightNatB = 0.0f; + + float reduceColourNat = 1.0f; + float reduceColourLit = 1.0f; + + reduceColourLit *= night / (float)pow(max(1.01f, 0.4f + lightAvg), 2.0); + + reduceColourLit += (float)(gClimateCurrentRainLevel) / 35.0f; + + lightFog *= reduceColourLit; + + reduceColourNat *= 1.0f - envFog; + reduceColourLit *= 1.0f - lightFog; + + float fogR = 35.5f * natLightR * 1.3f; + float fogG = 45.0f * natLightG * 1.3f; + float fogB = 50.0f * natLightB * 1.3f; + lightFog *= 10.0f; + + float wetnessBoost = 1.0f;//1.0f + wetness * wetness * 0.1f; + +#endif + + if (night >= 0 && gClimateLightningFlash != 1) { gPalette[i].r = lerp(gPalette[i].r, soft_light(gPalette[i].r, 8), night); gPalette[i].g = lerp(gPalette[i].g, soft_light(gPalette[i].g, 8), night); gPalette[i].b = lerp(gPalette[i].b, soft_light(gPalette[i].b, 128), night); + +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + + // if (i == 32) + // boost = 300000.0f; + if ((i % 32) == 0) + boost = 1.01f * wetnessBoost; + else if ((i % 16) < 7) + boost = 1.001f * wetnessBoost; + if (i > 230 && i < 232) + boost = ((float)(gPalette[i].b)) / 64.0f; + + if (false) { + // This experiment shifts the colour of pixels as-if they are wet, but it is not a pretty solution at all + if ((i % 16)) { + float iVal = ((float)((i + 12) % 16)) / 16.0f; + float eff = (wetness * ((float)pow(iVal, 1.5) * 0.85f)); + reduceColourNat *= 1.0f - eff; + addLightNatR += fogR * eff * 3.95f; + addLightNatG += fogR * eff * 3.95f; + addLightNatB += fogR * eff * 3.95f; + } + } + + addLightNatR *= 1.0f - envFog; + addLightNatG *= 1.0f - envFog; + addLightNatB *= 1.0f - envFog; + + gPalette[i].r = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(gPalette[i].r) * reduceColourNat * natLightR + envFog * fogR + addLightNatR)))); + gPalette[i].g = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(gPalette[i].g) * reduceColourNat * natLightG + envFog * fogG + addLightNatG)))); + gPalette[i].b = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(gPalette[i].b) * reduceColourNat * natLightB + envFog * fogB + addLightNatB)))); + gPalette_light[i].r = (uint8)(min(0xFF, ((float)(gPalette[i].r) * reduceColourLit * boost + lightFog) * 1.0f)); + gPalette_light[i].g = (uint8)(min(0xFF, ((float)(gPalette[i].g) * reduceColourLit * boost + lightFog) * 0.85f)); + gPalette_light[i].b = (uint8)(min(0xFF, ((float)(gPalette[i].b) * reduceColourLit * boost + lightFog) * 0.30f)); + +#endif } colours += 4; if (gBufferTextureFormat != NULL) { gPaletteHWMapped[i] = SDL_MapRGB(gBufferTextureFormat, gPalette[i].r, gPalette[i].g, gPalette[i].b); + gPaletteHWMapped_light[i] = SDL_MapRGB(gBufferTextureFormat, gPalette_light[i].r, gPalette_light[i].g, gPalette_light[i].b); } } @@ -986,6 +1251,13 @@ void platform_refresh_video() static void platform_refresh_screenbuffer(int width, int height, int pitch) { +#ifdef STOUT_EXPANDED_RENDERING_MTT + + platform_draw_require_end(); + +#endif + + int newScreenBufferSize = pitch * height; char *newScreenBuffer = (char*)malloc(newScreenBufferSize); if (_screenBuffer == NULL) { @@ -1019,6 +1291,17 @@ static void platform_refresh_screenbuffer(int width, int height, int pitch) _screenBufferHeight = height; _screenBufferPitch = pitch; +#ifdef STOUT_EXPANDED_RENDERING_MTT + newScreenBuffer = (char*)malloc(newScreenBufferSize); + if (_screenBuffer_back == NULL) { + memset(newScreenBuffer, 0xFF, newScreenBufferSize); + } + else { + memset(newScreenBuffer, 0xFF, newScreenBufferSize); + } + _screenBuffer_back = newScreenBuffer; +#endif + rct_drawpixelinfo *screenDPI = &gScreenDPI; screenDPI->bits = _screenBuffer; screenDPI->x = 0; @@ -1027,6 +1310,23 @@ static void platform_refresh_screenbuffer(int width, int height, int pitch) screenDPI->height = height; screenDPI->pitch = _screenBufferPitch - width; +#ifdef STOUT_EXPANDED_RENDERING_MTT + screenDPI = &_screenDPI_back; + screenDPI->bits = _screenBuffer_back; + screenDPI->x = 0; + screenDPI->y = 0; + screenDPI->width = width; + screenDPI->height = height; + screenDPI->pitch = _screenBufferPitch - width; + +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + + lightfx_update_buffers(screenDPI); + +#endif + +#endif + gfx_configure_dirty_grid(); } diff --git a/src/rct2.c b/src/rct2.c index 52f7456f08..9e23452eb6 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -51,6 +51,12 @@ #include "world/scenery.h" #include "world/sprite.h" +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + +#include "drawing/lightfx.h" + +#endif + // rct2: 0x0097F67C const char * const RCT2FilePaths[PATH_ID_END] = { "Data\\g1.dat", @@ -184,6 +190,13 @@ int rct2_init() window_guest_list_init_vars_b(); window_staff_list_init_vars(); + +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + + lightfx_init(); + +#endif + if (!gOpenRCT2Headless) { title_load(); diff --git a/src/ride/vehicle_paint.c b/src/ride/vehicle_paint.c index b1f2c34f8f..7307944866 100644 --- a/src/ride/vehicle_paint.c +++ b/src/ride/vehicle_paint.c @@ -21,6 +21,7 @@ #include "../ride/track.h" #include "../interface/viewport.h" #include "../game.h" +#include "../drawing/lightfx.h" #include "vehicle_paint.h" // 0x0098E52C: @@ -891,6 +892,7 @@ const vehicle_boundbox VehicleBoundboxes[16][224] = { // 6D5214 void vehicle_sprite_paint(rct_vehicle *vehicle, int ebx, int ecx, int z, const rct_ride_entry_vehicle *vehicleEntry) { + int baseImage_id = ebx; vehicle_boundbox bb = VehicleBoundboxes[vehicleEntry->draw_order][ecx]; if (vehicleEntry->flags_a & 0x4000) { @@ -2334,7 +2336,7 @@ void vehicle_visual_default(int x, int imageDirection, int y, int z, rct_vehicle */ void vehicle_paint(rct_vehicle *vehicle, int imageDirection) { - rct_ride_entry *rideEntry; + rct_ride_entry *rideEntry = 0; const rct_ride_entry_vehicle *vehicleEntry; int x = vehicle->x; @@ -2359,6 +2361,107 @@ void vehicle_paint(rct_vehicle *vehicle, int imageDirection) } } +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + + sint16 peep_x, peep_y, peep_z; + + peep_x = vehicle->x; + peep_y = vehicle->y; + peep_z = vehicle->z; + + static const sint16 offsetLookup[32] = { 10, 10, 9, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -9, -10, -10, -10, -9, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 9, 10 }; + + switch (vehicleEntry->car_visual) { + case VEHICLE_VISUAL_MINI_GOLF_PLAYER: { + peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32]; + peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32]; + lightfx_add_3d_light(peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_SPOT_1); + break; + }; + default: { + rct_ride *ride = get_ride(vehicle->ride); + switch (ride->type) { + case RIDE_TYPE_OBSERVATION_TOWER: + lightfx_add_3d_light(vehicle->x, vehicle->y + 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicle->x + 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicle->x - 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicle->x, vehicle->y - 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + break; + case RIDE_TYPE_MINE_TRAIN_COASTER: + if (vehicle == vehicle_get_head(vehicle)) { + peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + break; + case RIDE_TYPE_CHAIRLIFT: + lightfx_add_3d_light(peep_x, peep_y, peep_z - 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); + break; + case RIDE_TYPE_BOAT_RIDE: + case RIDE_TYPE_CAR_RIDE: + case RIDE_TYPE_GO_KARTS: + case RIDE_TYPE_DODGEMS: + case RIDE_TYPE_MINI_HELICOPTERS: + case RIDE_TYPE_MONORAIL_CYCLES: + case RIDE_TYPE_SUBMARINE_RIDE: + case RIDE_TYPE_SPLASH_BOATS: + case RIDE_TYPE_WATER_COASTER: { + rct_vehicle *vehicle_draw = vehicle_get_head(vehicle); + if (vehicle_draw->next_vehicle_on_train != 0xFFFF) { + vehicle_draw = GET_VEHICLE(vehicle_draw->next_vehicle_on_train); + } + peep_x = vehicle_draw->x; + peep_y = vehicle_draw->y; + peep_z = vehicle_draw->z; + peep_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; + peep_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; + lightfx_add_3d_light(peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_SPOT_2); + peep_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; + peep_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; + lightfx_add_3d_light(peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_SPOT_2); + } + break; + case RIDE_TYPE_MONORAIL: + lightfx_add_3d_light(vehicle->x, vehicle->y, vehicle->z + 12, LIGHTFX_LIGHT_TYPE_LANTERN_2); + if (vehicle == vehicle_get_head(vehicle)) { + peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(peep_x, peep_y, peep_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 3; + peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 3; + lightfx_add_3d_light(peep_x, peep_y, peep_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + if (vehicle == vehicle_get_tail(vehicle)) { + peep_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + peep_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(peep_x, peep_y, peep_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + peep_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + peep_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(peep_x, peep_y, peep_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + break; + case RIDE_TYPE_MINIATURE_RAILWAY: + if (vehicle == vehicle_get_head(vehicle)) { + peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(peep_x, peep_y, peep_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(peep_x, peep_y, peep_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + else { + lightfx_add_3d_light(vehicle->x, vehicle->y, vehicle->z + 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); + } + break; + case RIDE_TYPE_GHOST_TRAIN: + default: + break; + }; + }; + } + +#endif + uint32 rct2VehiclePtrFormat = ((uint32)vehicleEntry) - offsetof(rct_ride_entry, vehicles); RCT2_GLOBAL(0x00F64DFC, uint32) = rct2VehiclePtrFormat; switch (vehicleEntry->car_visual) { From 4f4003b499944c6deecb9bcd27e2e5f43736f927 Mon Sep 17 00:00:00 2001 From: JeroenDStout Date: Tue, 31 May 2016 23:56:58 +0200 Subject: [PATCH 03/44] vcxproj --- openrct2.vcxproj | 1066 +++++++++++++++++++++++----------------------- 1 file changed, 534 insertions(+), 532 deletions(-) diff --git a/openrct2.vcxproj b/openrct2.vcxproj index 4ee5ba88a4..fa387e49aa 100644 --- a/openrct2.vcxproj +++ b/openrct2.vcxproj @@ -1,533 +1,535 @@ - - - - - - - - - Debug - Win32 - - - Release - Win32 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {D24D94F6-2A74-480C-B512-629C306CE92F} - openrct2 - openrct2 - - - - DynamicLibrary - true - v140 - MultiByte - - - DynamicLibrary - false - v140 - true - MultiByte - - - - - - - - - - - - $(SolutionDir)lib\include;$(SolutionDir)lib\include\breakpad;$(SolutionDir)lib\include\libspeex;$(SolutionDir)lib\include\sdl;$(SolutionDir)lib\include\jansson;$(SolutionDir)lib\include\sdl_ttf;$(SolutionDir)lib\include\libpng;$(SolutionDir)lib\include\zlib;$(IncludePath) - $(SolutionDir)lib;$(LibraryPath) - $(SolutionDir)bin\ - $(SolutionDir)obj\$(ProjectName)\$(Configuration)\ - - - - $(SolutionDir)lib\include;$(SolutionDir)lib\include\breakpad;$(SolutionDir)lib\include\libspeex;$(SolutionDir)lib\include\sdl;$(SolutionDir)lib\include\jansson;$(SolutionDir)lib\include\sdl_ttf;$(SolutionDir)lib\include\libpng;$(SolutionDir)lib\include\zlib;$(IncludePath) - $(SolutionDir)lib;$(LibraryPath) - $(SolutionDir)bin\ - $(SolutionDir)obj\$(ProjectName)\$(Configuration)\ - - - - USE_BREAKPAD;%(PreprocessorDefinitions) - - - - - 4091;%(DisableSpecificWarnings) - Level3 - Disabled - true - 1Byte - $(OpenRCT2_DEFINES);DEBUG;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) - MultiThreaded - true - $(IntDir)\%(RelativeDir) - 4013 - false - true - - - true - openrct2-libs-vs2015.lib;imm32.lib;version.lib;winmm.lib;%(AdditionalDependencies) - UseFastLinkTimeCodeGeneration - /OPT:NOLBR /ignore:4099 %(AdditionalOptions) - - - - - 4091;%(DisableSpecificWarnings) - Level3 - Full - true - true - - MultiThreaded - 1Byte - 4013 - - false - $(OpenRCT2_DEFINES);_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;%(PreprocessorDefinitions) - $(IntDir)\%(RelativeDir) - true - Speed - true - - - true - true - true - openrct2-libs-vs2015.lib;imm32.lib;version.lib;winmm.lib;%(AdditionalDependencies) - /ignore:4099 %(AdditionalOptions) - - - - + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {D24D94F6-2A74-480C-B512-629C306CE92F} + openrct2 + openrct2 + + + + DynamicLibrary + true + v140 + MultiByte + + + DynamicLibrary + false + v140 + true + MultiByte + + + + + + + + + + + + $(SolutionDir)lib\include;$(SolutionDir)lib\include\breakpad;$(SolutionDir)lib\include\libspeex;$(SolutionDir)lib\include\sdl;$(SolutionDir)lib\include\jansson;$(SolutionDir)lib\include\sdl_ttf;$(SolutionDir)lib\include\libpng;$(SolutionDir)lib\include\zlib;$(IncludePath) + $(SolutionDir)lib;$(LibraryPath) + $(SolutionDir)bin\ + $(SolutionDir)obj\$(ProjectName)\$(Configuration)\ + + + + $(SolutionDir)lib\include;$(SolutionDir)lib\include\breakpad;$(SolutionDir)lib\include\libspeex;$(SolutionDir)lib\include\sdl;$(SolutionDir)lib\include\jansson;$(SolutionDir)lib\include\sdl_ttf;$(SolutionDir)lib\include\libpng;$(SolutionDir)lib\include\zlib;$(IncludePath) + $(SolutionDir)lib;$(LibraryPath) + $(SolutionDir)bin\ + $(SolutionDir)obj\$(ProjectName)\$(Configuration)\ + + + + USE_BREAKPAD;%(PreprocessorDefinitions) + + + + + 4091;%(DisableSpecificWarnings) + Level3 + Disabled + true + 1Byte + $(OpenRCT2_DEFINES);DEBUG;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + MultiThreaded + true + $(IntDir)\%(RelativeDir) + 4013 + false + true + + + true + openrct2-libs-vs2015.lib;imm32.lib;version.lib;winmm.lib;%(AdditionalDependencies) + UseFastLinkTimeCodeGeneration + /OPT:NOLBR /ignore:4099 %(AdditionalOptions) + + + + + 4091;%(DisableSpecificWarnings) + Level3 + Full + true + true + + MultiThreaded + 1Byte + 4013 + + false + $(OpenRCT2_DEFINES);_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;%(PreprocessorDefinitions) + $(IntDir)\%(RelativeDir) + true + Speed + true + + + true + true + true + openrct2-libs-vs2015.lib;imm32.lib;version.lib;winmm.lib;%(AdditionalDependencies) + /ignore:4099 %(AdditionalOptions) + + + + \ No newline at end of file From 2a126d885352a0e0644d895cd46b061cdf838c90 Mon Sep 17 00:00:00 2001 From: JeroenDStout Date: Wed, 1 Jun 2016 00:45:08 +0200 Subject: [PATCH 04/44] Lanterns no longer emit light when broken --- src/paint/map_element/path.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/paint/map_element/path.c b/src/paint/map_element/path.c index 42b5090220..7eae95bdb0 100644 --- a/src/paint/map_element/path.c +++ b/src/paint/map_element/path.c @@ -33,13 +33,12 @@ void path_paint(uint8 direction, uint16 height, rct_map_element *mapElement) { #ifdef STOUT_EXPANDED_RENDERING_LIGHT - if (footpath_element_has_path_scenery(mapElement)) { + if (footpath_element_has_path_scenery(mapElement) && !(mapElement->flags & MAP_ELEMENT_FLAG_BROKEN)) { rct_scenery_entry *sceneryEntry; sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(mapElement)); if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_LAMP) { - if (!(mapElement->properties.path.edges & (1 << 0))) { lightfx_add_3d_light_magic_from_drawing_tile(-16, 0, height + 23, LIGHTFX_LIGHT_TYPE_LANTERN_3); } From ee360ecb3d835f0206b24bb817789c36ece60bd4 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Wed, 1 Jun 2016 15:09:53 +0200 Subject: [PATCH 05/44] Fixed line endings in vcxproj --- openrct2.vcxproj | 1068 +++++++++++++++++++++++----------------------- 1 file changed, 534 insertions(+), 534 deletions(-) diff --git a/openrct2.vcxproj b/openrct2.vcxproj index fa387e49aa..ca1876230f 100644 --- a/openrct2.vcxproj +++ b/openrct2.vcxproj @@ -1,535 +1,535 @@ - - - - - - - - - Debug - Win32 - - - Release - Win32 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {D24D94F6-2A74-480C-B512-629C306CE92F} - openrct2 - openrct2 - - - - DynamicLibrary - true - v140 - MultiByte - - - DynamicLibrary - false - v140 - true - MultiByte - - - - - - - - - - - - $(SolutionDir)lib\include;$(SolutionDir)lib\include\breakpad;$(SolutionDir)lib\include\libspeex;$(SolutionDir)lib\include\sdl;$(SolutionDir)lib\include\jansson;$(SolutionDir)lib\include\sdl_ttf;$(SolutionDir)lib\include\libpng;$(SolutionDir)lib\include\zlib;$(IncludePath) - $(SolutionDir)lib;$(LibraryPath) - $(SolutionDir)bin\ - $(SolutionDir)obj\$(ProjectName)\$(Configuration)\ - - - - $(SolutionDir)lib\include;$(SolutionDir)lib\include\breakpad;$(SolutionDir)lib\include\libspeex;$(SolutionDir)lib\include\sdl;$(SolutionDir)lib\include\jansson;$(SolutionDir)lib\include\sdl_ttf;$(SolutionDir)lib\include\libpng;$(SolutionDir)lib\include\zlib;$(IncludePath) - $(SolutionDir)lib;$(LibraryPath) - $(SolutionDir)bin\ - $(SolutionDir)obj\$(ProjectName)\$(Configuration)\ - - - - USE_BREAKPAD;%(PreprocessorDefinitions) - - - - - 4091;%(DisableSpecificWarnings) - Level3 - Disabled - true - 1Byte - $(OpenRCT2_DEFINES);DEBUG;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) - MultiThreaded - true - $(IntDir)\%(RelativeDir) - 4013 - false - true - - - true - openrct2-libs-vs2015.lib;imm32.lib;version.lib;winmm.lib;%(AdditionalDependencies) - UseFastLinkTimeCodeGeneration - /OPT:NOLBR /ignore:4099 %(AdditionalOptions) - - - - - 4091;%(DisableSpecificWarnings) - Level3 - Full - true - true - - MultiThreaded - 1Byte - 4013 - - false - $(OpenRCT2_DEFINES);_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;%(PreprocessorDefinitions) - $(IntDir)\%(RelativeDir) - true - Speed - true - - - true - true - true - openrct2-libs-vs2015.lib;imm32.lib;version.lib;winmm.lib;%(AdditionalDependencies) - /ignore:4099 %(AdditionalOptions) - - - - + + + + + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {D24D94F6-2A74-480C-B512-629C306CE92F} + openrct2 + openrct2 + + + + DynamicLibrary + true + v140 + MultiByte + + + DynamicLibrary + false + v140 + true + MultiByte + + + + + + + + + + + + $(SolutionDir)lib\include;$(SolutionDir)lib\include\breakpad;$(SolutionDir)lib\include\libspeex;$(SolutionDir)lib\include\sdl;$(SolutionDir)lib\include\jansson;$(SolutionDir)lib\include\sdl_ttf;$(SolutionDir)lib\include\libpng;$(SolutionDir)lib\include\zlib;$(IncludePath) + $(SolutionDir)lib;$(LibraryPath) + $(SolutionDir)bin\ + $(SolutionDir)obj\$(ProjectName)\$(Configuration)\ + + + + $(SolutionDir)lib\include;$(SolutionDir)lib\include\breakpad;$(SolutionDir)lib\include\libspeex;$(SolutionDir)lib\include\sdl;$(SolutionDir)lib\include\jansson;$(SolutionDir)lib\include\sdl_ttf;$(SolutionDir)lib\include\libpng;$(SolutionDir)lib\include\zlib;$(IncludePath) + $(SolutionDir)lib;$(LibraryPath) + $(SolutionDir)bin\ + $(SolutionDir)obj\$(ProjectName)\$(Configuration)\ + + + + USE_BREAKPAD;%(PreprocessorDefinitions) + + + + + 4091;%(DisableSpecificWarnings) + Level3 + Disabled + true + 1Byte + $(OpenRCT2_DEFINES);DEBUG;_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) + MultiThreaded + true + $(IntDir)\%(RelativeDir) + 4013 + false + true + + + true + openrct2-libs-vs2015.lib;imm32.lib;version.lib;winmm.lib;%(AdditionalDependencies) + UseFastLinkTimeCodeGeneration + /OPT:NOLBR /ignore:4099 %(AdditionalOptions) + + + + + 4091;%(DisableSpecificWarnings) + Level3 + Full + true + true + + MultiThreaded + 1Byte + 4013 + + false + $(OpenRCT2_DEFINES);_CRT_SECURE_NO_WARNINGS;_USE_MATH_DEFINES;CURL_STATICLIB;SDL_MAIN_HANDLED;%(PreprocessorDefinitions) + $(IntDir)\%(RelativeDir) + true + Speed + true + + + true + true + true + openrct2-libs-vs2015.lib;imm32.lib;version.lib;winmm.lib;%(AdditionalDependencies) + /ignore:4099 %(AdditionalOptions) + + + + \ No newline at end of file From 29b91c442c3afd28500afd709fc10f1db34916f7 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Wed, 1 Jun 2016 16:00:00 +0200 Subject: [PATCH 06/44] Replaced 'peep_*' with 'vehicle_*' in light insertions in vehicle_paint --- src/ride/vehicle_paint.c | 76 ++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/ride/vehicle_paint.c b/src/ride/vehicle_paint.c index 7307944866..4cc2149586 100644 --- a/src/ride/vehicle_paint.c +++ b/src/ride/vehicle_paint.c @@ -2363,19 +2363,19 @@ void vehicle_paint(rct_vehicle *vehicle, int imageDirection) #ifdef STOUT_EXPANDED_RENDERING_LIGHT - sint16 peep_x, peep_y, peep_z; + sint16 place_x, place_y, place_z; - peep_x = vehicle->x; - peep_y = vehicle->y; - peep_z = vehicle->z; + place_x = vehicle->x; + place_y = vehicle->y; + place_z = vehicle->z; static const sint16 offsetLookup[32] = { 10, 10, 9, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -9, -10, -10, -10, -9, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 9, 10 }; switch (vehicleEntry->car_visual) { case VEHICLE_VISUAL_MINI_GOLF_PLAYER: { - peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32]; - peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32]; - lightfx_add_3d_light(peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_SPOT_1); + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32]; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32]; + lightfx_add_3d_light(place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_1); break; }; default: { @@ -2389,13 +2389,13 @@ void vehicle_paint(rct_vehicle *vehicle, int imageDirection) break; case RIDE_TYPE_MINE_TRAIN_COASTER: if (vehicle == vehicle_get_head(vehicle)) { - peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(place_x, place_x, place_z, LIGHTFX_LIGHT_TYPE_LANTERN_3); } break; case RIDE_TYPE_CHAIRLIFT: - lightfx_add_3d_light(peep_x, peep_y, peep_z - 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); + lightfx_add_3d_light(place_x, place_y, place_z - 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); break; case RIDE_TYPE_BOAT_RIDE: case RIDE_TYPE_CAR_RIDE: @@ -2410,44 +2410,44 @@ void vehicle_paint(rct_vehicle *vehicle, int imageDirection) if (vehicle_draw->next_vehicle_on_train != 0xFFFF) { vehicle_draw = GET_VEHICLE(vehicle_draw->next_vehicle_on_train); } - peep_x = vehicle_draw->x; - peep_y = vehicle_draw->y; - peep_z = vehicle_draw->z; - peep_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; - peep_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; - lightfx_add_3d_light(peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_SPOT_2); - peep_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; - peep_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; - lightfx_add_3d_light(peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_SPOT_2); + place_x = vehicle_draw->x; + place_y = vehicle_draw->y; + place_z = vehicle_draw->z; + place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; + place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; + lightfx_add_3d_light(place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); + place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; + place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; + lightfx_add_3d_light(place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); } break; case RIDE_TYPE_MONORAIL: lightfx_add_3d_light(vehicle->x, vehicle->y, vehicle->z + 12, LIGHTFX_LIGHT_TYPE_LANTERN_2); if (vehicle == vehicle_get_head(vehicle)) { - peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(peep_x, peep_y, peep_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); - peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 3; - peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 3; - lightfx_add_3d_light(peep_x, peep_y, peep_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 3; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 3; + lightfx_add_3d_light(place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); } if (vehicle == vehicle_get_tail(vehicle)) { - peep_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - peep_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(peep_x, peep_y, peep_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); - peep_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - peep_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(peep_x, peep_y, peep_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); } break; case RIDE_TYPE_MINIATURE_RAILWAY: if (vehicle == vehicle_get_head(vehicle)) { - peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(peep_x, peep_y, peep_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); - peep_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - peep_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(peep_x, peep_y, peep_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); } else { lightfx_add_3d_light(vehicle->x, vehicle->y, vehicle->z + 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); From 892daffbf6993a2a857c9cd65852f028c603cb33 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Thu, 2 Jun 2016 01:30:24 +0200 Subject: [PATCH 07/44] Included lightfx files --- src/drawing/lightfx.c | 380 ++++++++++++++++++++++++++++++++++++++++++ src/drawing/lightfx.h | 59 +++++++ 2 files changed, 439 insertions(+) create mode 100644 src/drawing/lightfx.c create mode 100644 src/drawing/lightfx.h diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c new file mode 100644 index 0000000000..e5234354b1 --- /dev/null +++ b/src/drawing/lightfx.c @@ -0,0 +1,380 @@ +#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/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 +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#include "lightfx.h" +#include "drawing.h" +#include "../rct2.h" +#include "../interface/window.h" +#include "../interface/viewport.h" + +static uint8 _bakedLightTexture_lantern_0[32*32]; +static uint8 _bakedLightTexture_lantern_1[64*64]; +static uint8 _bakedLightTexture_lantern_2[128*128]; +static uint8 _bakedLightTexture_lantern_3[256*256]; +static uint8 _bakedLightTexture_spot_0[32 * 32]; +static uint8 _bakedLightTexture_spot_1[64 * 64]; +static uint8 _bakedLightTexture_spot_2[128 * 128]; +static uint8 _bakedLightTexture_spot_3[256 * 256]; +static rct_drawpixelinfo _pixelInfo; + +static void* _light_rendered_buffer_back = 0; +static void* _light_rendered_buffer_front = 0; + +static uint32 _lightPolution_back = 0; +static uint32 _lightPolution_front = 0; + +typedef struct lightlist_entry { + sint16 x, y, z; + uint8 lightType; + uint8 pad[3]; +} lightlist_entry; + +static lightlist_entry _LightListA[16000]; +static lightlist_entry _LightListB[16000]; + +static lightlist_entry *_LightListBack; +static lightlist_entry *_LightListFront; + +static uint32 LightListCurrentCountBack; +static uint32 LightListCurrentCountFront; + +uint8 calc_light_intensity_lantern(sint32 x, sint32 y) { + double distance = (double)(x * x + y * y); + + double light = 0.09 + pow(10.0 / (1.0 + distance / 100.0), 0.55); + light *= min(1.0, max(0.0f, 2.0 - sqrt(distance) / 64)); + light *= 0.25f; + + return (uint8)(min(255.0, light * 255.0)); +} + +uint8 calc_light_intensity_spot(sint32 x, sint32 y) { + double distance = (double)(x * x + y * y); + + double light = 0.3 + pow(10.0 / (1.0 + distance / 100.0), 0.75); + light *= min(1.0, max(0.0f, 2.0 - sqrt(distance) / 64)); + light *= 0.5f; + + return (uint8)(min(255.0, light * 255.0)) >> 3; +} + +void calc_rescale_light_half( uint8 *target, uint8 *source,uint32 targetWidth, uint32 targetHeight) { + uint8 *parcerRead = source; + uint8 *parcerWrite = target; + + for (uint32 y = 0; y < targetHeight; y++) { + for (uint32 x = 0; x < targetWidth; x++) { + *parcerWrite = (*parcerRead); + parcerWrite++; + parcerRead += 2; + } + parcerRead += targetWidth * 2; + } +} + +void lightfx_init() +{ + _LightListBack = _LightListA; + _LightListFront = _LightListB; + + memset(_bakedLightTexture_lantern_0, 0xFF, 32 * 32); + memset(_bakedLightTexture_lantern_1, 0xFF, 64 * 64); + memset(_bakedLightTexture_lantern_2, 0xFF, 128 * 128); + memset(_bakedLightTexture_lantern_3, 0xFF, 256 * 256); + + uint8 *parcer = _bakedLightTexture_lantern_3; + + for (int y = 0; y < 256; y++) { + for (int x = 0; x < 256; x++) { + *parcer = calc_light_intensity_lantern(x - 128, y - 128); + parcer++; + } + } + + parcer = _bakedLightTexture_spot_3; + + for (int y = 0; y < 256; y++) { + for (int x = 0; x < 256; x++) { + *parcer = calc_light_intensity_spot(x - 128, y - 128); + parcer++; + } + } + + calc_rescale_light_half(_bakedLightTexture_lantern_2, _bakedLightTexture_lantern_3, 128, 128); + calc_rescale_light_half(_bakedLightTexture_lantern_1, _bakedLightTexture_lantern_2, 64, 64); + calc_rescale_light_half(_bakedLightTexture_lantern_0, _bakedLightTexture_lantern_1, 32, 32); + + calc_rescale_light_half(_bakedLightTexture_spot_2, _bakedLightTexture_spot_3, 128, 128); + calc_rescale_light_half(_bakedLightTexture_spot_1, _bakedLightTexture_spot_2, 64, 64); + calc_rescale_light_half(_bakedLightTexture_spot_0, _bakedLightTexture_spot_1, 32, 32); +} + +void lightfx_update_buffers(rct_drawpixelinfo *info) +{ + _light_rendered_buffer_front = realloc(_light_rendered_buffer_front, info->width * info->height); + _light_rendered_buffer_back = realloc(_light_rendered_buffer_back, info->width * info->height); + + memcpy(&_pixelInfo, info, sizeof(rct_drawpixelinfo)); +} + +void lightfx_prepare_light_list() +{ + rct_window *mainWindow = window_get_main(); + if (!mainWindow) { + LightListCurrentCountBack = 0; + return; + } + + for (uint32 light = 0; light < LightListCurrentCountFront; light++) { + lightlist_entry *entry = &_LightListBack[light]; + + if (entry->z == 0x7FFF) { + continue; + } + + rct_xyz16 coord_3d = { + .x = entry->x, + .y = entry->y, + .z = entry->z + }; + + rct_xy16 coord_2d = coordinate_3d_to_2d(&coord_3d, get_current_rotation()); + + entry->x = coord_2d.x - mainWindow->viewport->view_x; + entry->y = coord_2d.y - mainWindow->viewport->view_y; + + for (uint8 q = 0; q < mainWindow->viewport->zoom; q++) { + entry->x >>= 1; + entry->y >>= 1; + entry->lightType = max(entry->lightType & ~0x3, entry->lightType - 1); + } + } +} + +void lightfx_swap_buffers() +{ + void *tmp = _light_rendered_buffer_back; + _light_rendered_buffer_back = _light_rendered_buffer_front; + _light_rendered_buffer_front = tmp; + + tmp = _light_rendered_buffer_back; + _light_rendered_buffer_back = _light_rendered_buffer_front; + _light_rendered_buffer_front = tmp; + + tmp = _LightListBack; + _LightListBack = _LightListFront; + _LightListFront = tmp; + + LightListCurrentCountFront = LightListCurrentCountBack; + LightListCurrentCountBack = 0x0; + + uint32 uTmp = _lightPolution_back; + _lightPolution_back = _lightPolution_front; + _lightPolution_front = uTmp; +} + +void lightfx_render_lights_to_frontbuffer() +{ + memset(_light_rendered_buffer_front, 0, _pixelInfo.width * _pixelInfo.height); + + _lightPolution_back = 0; + +// log_warning("%i lights", LightListCurrentCountFront); + + for (uint32 light = 0; light < LightListCurrentCountFront; light++) { + + const uint8 *bufReadBase = 0; + uint8 *bufWriteBase = _light_rendered_buffer_front; + uint32 bufReadWidth, bufReadHeight; + sint32 bufWriteX, bufWriteY; + sint32 bufWriteWidth, bufWriteHeight; + uint32 bufReadSkip, bufWriteSkip; + + lightlist_entry * entry = &_LightListFront[light]; + + switch (entry->lightType) { + case LIGHTFX_LIGHT_TYPE_LANTERN_0: + bufReadWidth = 32; + bufReadHeight = 32; + bufReadBase = _bakedLightTexture_lantern_0; + break; + case LIGHTFX_LIGHT_TYPE_LANTERN_1: + bufReadWidth = 64; + bufReadHeight = 64; + bufReadBase = _bakedLightTexture_lantern_1; + break; + case LIGHTFX_LIGHT_TYPE_LANTERN_2: + bufReadWidth = 128; + bufReadHeight = 128; + bufReadBase = _bakedLightTexture_lantern_2; + break; + case LIGHTFX_LIGHT_TYPE_LANTERN_3: + bufReadWidth = 256; + bufReadHeight = 256; + bufReadBase = _bakedLightTexture_lantern_3; + break; + case LIGHTFX_LIGHT_TYPE_SPOT_0: + bufReadWidth = 32; + bufReadHeight = 32; + bufReadBase = _bakedLightTexture_spot_0; + break; + case LIGHTFX_LIGHT_TYPE_SPOT_1: + bufReadWidth = 64; + bufReadHeight = 64; + bufReadBase = _bakedLightTexture_spot_1; + break; + case LIGHTFX_LIGHT_TYPE_SPOT_2: + bufReadWidth = 128; + bufReadHeight = 128; + bufReadBase = _bakedLightTexture_spot_2; + break; + case LIGHTFX_LIGHT_TYPE_SPOT_3: + bufReadWidth = 256; + bufReadHeight = 256; + bufReadBase = _bakedLightTexture_spot_3; + break; + default: + continue; + } + + bufWriteX = entry->x - bufReadWidth / 2; + bufWriteY = entry->y - bufReadHeight / 2; + + bufWriteWidth = bufReadWidth; + bufWriteHeight = bufReadHeight; + + if (bufWriteX < 0) { + bufReadBase += -bufWriteX; + bufWriteWidth += bufWriteX; + } + else { + bufWriteBase += bufWriteX; + } + + if (bufWriteWidth <= 0) + continue; + + if (bufWriteY < 0) { + bufReadBase += -bufWriteY * bufReadWidth; + bufWriteHeight += bufWriteY; + } + else { + bufWriteBase += bufWriteY * _pixelInfo.width; + } + + + if (bufWriteHeight <= 0) + continue; + + sint32 rightEdge = bufWriteX + bufWriteWidth; + sint32 bottomEdge = bufWriteY + bufWriteHeight; + + if (rightEdge > _pixelInfo.width) { + bufWriteWidth -= rightEdge - _pixelInfo.width; + } + if (bottomEdge > _pixelInfo.height) { + bufWriteHeight -= bottomEdge - _pixelInfo.height; + } + + if (bufWriteWidth <= 0) + continue; + if (bufWriteHeight <= 0) + continue; + + _lightPolution_back += (bufWriteWidth * bufWriteHeight) / 256; + + bufReadSkip = bufReadWidth - bufWriteWidth; + bufWriteSkip = _pixelInfo.width - bufWriteWidth; + + for (int y = 0; y < bufWriteHeight; y++) { + for (int x = 0; x < bufWriteWidth; x++) { + *bufWriteBase = min(0xFF, *bufWriteBase + *bufReadBase); + bufWriteBase++; + bufReadBase++; + } + + bufWriteBase += bufWriteSkip; + bufReadBase += bufReadSkip; + } + } +} + +void* lightfx_get_front_buffer() +{ + return _light_rendered_buffer_front; +} + +void lightfx_add_3d_light(sint16 x, sint16 y, uint16 z, uint8 lightType) +{ + if (LightListCurrentCountBack == 15999) { + return; + } + + for (uint32 i = 0; i < LightListCurrentCountBack; i++) { + lightlist_entry *entry = &_LightListBack[i]; + if (entry->x != x) + continue; + if (entry->y != y) + continue; + if (entry->z != z) + continue; + if (entry->lightType != lightType) + continue; + + return; + } + + lightlist_entry *entry = &_LightListBack[LightListCurrentCountBack++]; + + entry->x = x; + entry->y = y; + entry->z = z; + entry->lightType = lightType; +} + +void lightfx_add_3d_light_magic_from_drawing_tile(sint16 offsetX, sint16 offsetY, sint16 offsetZ, uint8 lightType) +{ + sint16 x = RCT2_GLOBAL(0x9DE56A, sint16) + offsetX; + sint16 y = RCT2_GLOBAL(0x9DE56C, sint16) + offsetY; + + switch (get_current_rotation()) { + case 0: + x += 16; + y += 16; + break; + case 1: + x += 16; + y += 16; + break; + case 2: + x += 16; + y -= 16; + break; + case 3: + x += 16; + y -= 16; + break; + default: + return; + } + + lightfx_add_3d_light(x, y, offsetZ, lightType); +} + +uint32 lightfx_get_light_polution() +{ + return _lightPolution_front; +} \ No newline at end of file diff --git a/src/drawing/lightfx.h b/src/drawing/lightfx.h new file mode 100644 index 0000000000..0936e9f9dc --- /dev/null +++ b/src/drawing/lightfx.h @@ -0,0 +1,59 @@ +#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/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 +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#ifndef _LIGHTFX_H +#define _LIGHTFX_H + +#include "drawing.h" +#include "../common.h" + +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + +enum LIGHTFX_LIGHT_TYPE { + LIGHTFX_LIGHT_TYPE_NONE = 0, + LIGHTFX_LIGHT_TYPE_RESERVED_01 = 1, + + LIGHTFX_LIGHT_TYPE_LANTERN_0 = 4, + LIGHTFX_LIGHT_TYPE_LANTERN_1 = 5, + LIGHTFX_LIGHT_TYPE_LANTERN_2 = 6, + LIGHTFX_LIGHT_TYPE_LANTERN_3 = 7, + + LIGHTFX_LIGHT_TYPE_SPOT_0 = 8, + LIGHTFX_LIGHT_TYPE_SPOT_1 = 9, + LIGHTFX_LIGHT_TYPE_SPOT_2 = 10, + LIGHTFX_LIGHT_TYPE_SPOT_3 = 11, + + LIGHTFX_LIGHT_TYPE_RESERVED_FF = 0xFF +}; + +extern void lightfx_init(); + +extern void lightfx_update_buffers(rct_drawpixelinfo*); + +extern void lightfx_prepare_light_list(); +extern void lightfx_swap_buffers(); +extern void lightfx_render_lights_to_frontbuffer(); + +extern void* lightfx_get_front_buffer(); + +extern void lightfx_add_3d_light(sint16 x, sint16 y, uint16 z, uint8 lightType); + +extern void lightfx_add_3d_light_magic_from_drawing_tile(sint16 offsetX, sint16 offsetY, sint16 offsetZ, uint8 lightType); + +extern uint32 lightfx_get_light_polution(); + +#endif +#endif \ No newline at end of file From d038576427f2a2e4d9e5e63cc20d3eaad4308cbc Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Thu, 2 Jun 2016 02:26:39 +0200 Subject: [PATCH 08/44] Correctly updating viewport settings - no more lag or light-ahead --- src/drawing/lightfx.c | 53 ++++++++++++++++++++++++++++++++----------- src/drawing/lightfx.h | 1 + 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index e5234354b1..55c36fccf9 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -51,6 +51,16 @@ static lightlist_entry *_LightListFront; static uint32 LightListCurrentCountBack; static uint32 LightListCurrentCountFront; +static sint16 _current_view_x_front = 0; +static sint16 _current_view_y_front = 0; +static uint8 _current_view_rotation_front = 0; +static uint8 _current_view_zoom_front = 0; +static sint16 _current_view_x_back = 0; +static sint16 _current_view_y_back = 0; +static uint8 _current_view_rotation_back = 0; +static uint8 _current_view_zoom_back = 0; +static uint8 _current_view_zoom_back_delay = 0; + uint8 calc_light_intensity_lantern(sint32 x, sint32 y) { double distance = (double)(x * x + y * y); @@ -132,14 +142,9 @@ void lightfx_update_buffers(rct_drawpixelinfo *info) void lightfx_prepare_light_list() { - rct_window *mainWindow = window_get_main(); - if (!mainWindow) { - LightListCurrentCountBack = 0; - return; - } for (uint32 light = 0; light < LightListCurrentCountFront; light++) { - lightlist_entry *entry = &_LightListBack[light]; + lightlist_entry *entry = &_LightListFront[light]; if (entry->z == 0x7FFF) { continue; @@ -151,15 +156,20 @@ void lightfx_prepare_light_list() .z = entry->z }; - rct_xy16 coord_2d = coordinate_3d_to_2d(&coord_3d, get_current_rotation()); + rct_xy16 coord_2d = coordinate_3d_to_2d(&coord_3d, _current_view_rotation_front); - entry->x = coord_2d.x - mainWindow->viewport->view_x; - entry->y = coord_2d.y - mainWindow->viewport->view_y; + entry->x = coord_2d.x - _current_view_x_front; + entry->y = coord_2d.y - _current_view_y_front; - for (uint8 q = 0; q < mainWindow->viewport->zoom; q++) { - entry->x >>= 1; - entry->y >>= 1; - entry->lightType = max(entry->lightType & ~0x3, entry->lightType - 1); + if (_current_view_zoom_front > 0) { + if ((entry->lightType & 0x3) < _current_view_zoom_front) { + entry->lightType = LIGHTFX_LIGHT_TYPE_NONE; + continue; + } + + entry->x >>= _current_view_zoom_front; + entry->y >>= _current_view_zoom_front; + entry->lightType -= _current_view_zoom_front; } } } @@ -184,6 +194,23 @@ void lightfx_swap_buffers() uint32 uTmp = _lightPolution_back; _lightPolution_back = _lightPolution_front; _lightPolution_front = uTmp; + + _current_view_x_front = _current_view_x_back; + _current_view_y_front = _current_view_y_back; + _current_view_rotation_front = _current_view_rotation_back; + _current_view_zoom_front = _current_view_zoom_back_delay; + _current_view_zoom_back_delay = _current_view_zoom_back; +} + +void lightfx_update_viewport_settings() +{ + rct_window *mainWindow = window_get_main(); + if (mainWindow) { + _current_view_x_back = mainWindow->viewport->view_x; + _current_view_y_back = mainWindow->viewport->view_y; + _current_view_rotation_back = get_current_rotation(); + _current_view_zoom_back = mainWindow->viewport->zoom; + } } void lightfx_render_lights_to_frontbuffer() diff --git a/src/drawing/lightfx.h b/src/drawing/lightfx.h index 0936e9f9dc..2f8792a9c7 100644 --- a/src/drawing/lightfx.h +++ b/src/drawing/lightfx.h @@ -46,6 +46,7 @@ extern void lightfx_update_buffers(rct_drawpixelinfo*); extern void lightfx_prepare_light_list(); extern void lightfx_swap_buffers(); extern void lightfx_render_lights_to_frontbuffer(); +extern void lightfx_update_viewport_settings(); extern void* lightfx_get_front_buffer(); From 198bb2fb5720c06600d1883e42cf9a3ce12364d8 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Thu, 2 Jun 2016 02:26:59 +0200 Subject: [PATCH 09/44] Reduced per-lantern intensity of light halo --- src/drawing/lightfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 55c36fccf9..d5175838fb 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -66,7 +66,7 @@ uint8 calc_light_intensity_lantern(sint32 x, sint32 y) { double light = 0.09 + pow(10.0 / (1.0 + distance / 100.0), 0.55); light *= min(1.0, max(0.0f, 2.0 - sqrt(distance) / 64)); - light *= 0.25f; + light *= 0.15f; return (uint8)(min(255.0, light * 255.0)); } From 27c34c1c224df1631b172acd6f1fde3e0cd5f9de Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Thu, 2 Jun 2016 02:27:17 +0200 Subject: [PATCH 10/44] Updates for viewport settings --- src/platform/shared.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/shared.c b/src/platform/shared.c index e14591b6b0..9f2e4a7b04 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -376,8 +376,9 @@ void platform_draw() lightfx_add_3d_light(gCursorState.x, gCursorState.y, 0x7FFF, LIGHTFX_LIGHT_TYPE_LANTERN_3); - lightfx_prepare_light_list(); + lightfx_update_viewport_settings(); lightfx_swap_buffers(); + lightfx_prepare_light_list(); // Make palette safe From 30b6754c6f367ebd037de03e2de6e152125235c8 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Thu, 2 Jun 2016 02:27:44 +0200 Subject: [PATCH 11/44] Changes to light behaviour - slight dynamic exposure effect, better fog --- src/platform/shared.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/platform/shared.c b/src/platform/shared.c index 9f2e4a7b04..edbc1f50c5 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -554,15 +554,20 @@ void platform_update_palette(const uint8* colours, int start_index, int num_colo float natLightG = 1.0f; float natLightB = 1.0f; + float elecMultR = 1.0f; + float elecMultG = 0.95f; + float elecMultB = 0.45f; + static float wetness = 0.0f; static float fogginess = 0.0f; + static float lightPolution = 0.0f; float sunLight = max(0.0f, min(1.0f, 2.0f - night * 3.0f)); // Night version - natLightR = flerp(natLightR * 4.0f, 0.335f, (float)(pow(night, 0.035f + sunLight * 10.50f))); - natLightG = flerp(natLightG * 4.0f, 0.350f, (float)(pow(night, 0.100f + sunLight * 5.50f))); - natLightB = flerp(natLightB * 4.0f, 0.550f, (float)(pow(night, 0.200f + sunLight * 1.5f))); + natLightR = flerp(natLightR * 4.0f, 0.635f, (float)(pow(night, 0.035f + sunLight * 10.50f))); + natLightG = flerp(natLightG * 4.0f, 0.650f, (float)(pow(night, 0.100f + sunLight * 5.50f))); + natLightB = flerp(natLightB * 4.0f, 0.850f, (float)(pow(night, 0.200f + sunLight * 1.5f))); float lightAvg = (natLightR + natLightG + natLightB) / 3.0f; float lightMax = (natLightR + natLightG + natLightB) / 3.0f; @@ -590,8 +595,8 @@ void platform_update_palette(const uint8* colours, int start_index, int num_colo natLightB *= 1.0f + overExpose; overExpose *= 255.0f; - float targetFogginess = (float)(gClimateCurrentRainLevel) / 5.0f; - targetFogginess += (night * night) * 0.35f; + float targetFogginess = (float)(gClimateCurrentRainLevel) / 8.0f; + targetFogginess += (night * night) * 0.15f; if (gClimateCurrentTemperature < 10) { targetFogginess += ((float)(10 - gClimateCurrentTemperature)) * 0.01f; @@ -616,7 +621,25 @@ void platform_update_palette(const uint8* colours, int start_index, int num_colo reduceColourLit *= night / (float)pow(max(1.01f, 0.4f + lightAvg), 2.0); - reduceColourLit += (float)(gClimateCurrentRainLevel) / 35.0f; + float targetLightPollution = reduceColourLit * max(0.0f, 0.0f + 0.000001f * (float)lightfx_get_light_polution()); + lightPolution -= (lightPolution - targetLightPollution) * 0.001f; + + // lightPollution /= 1.0f + fogginess * 1.0f; + + natLightR /= 1.0f + lightPolution * 50.0f; + natLightG /= 1.0f + lightPolution * 50.0f; + natLightB /= 1.0f + lightPolution * 50.0f; + natLightR += elecMultR * 0.6f * lightPolution; + natLightG += elecMultG * 0.6f * lightPolution; + natLightB += elecMultB * 0.6f * lightPolution; + natLightR /= 1.0f + lightPolution; + natLightG /= 1.0f + lightPolution; + natLightB /= 1.0f + lightPolution; + + reduceColourLit += (float)(gClimateCurrentRainLevel) / 2.0f; + + reduceColourNat /= 1.0f + fogginess; + reduceColourLit /= 1.0f + fogginess; lightFog *= reduceColourLit; @@ -667,9 +690,9 @@ void platform_update_palette(const uint8* colours, int start_index, int num_colo gPalette[i].r = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(gPalette[i].r) * reduceColourNat * natLightR + envFog * fogR + addLightNatR)))); gPalette[i].g = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(gPalette[i].g) * reduceColourNat * natLightG + envFog * fogG + addLightNatG)))); gPalette[i].b = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(gPalette[i].b) * reduceColourNat * natLightB + envFog * fogB + addLightNatB)))); - gPalette_light[i].r = (uint8)(min(0xFF, ((float)(gPalette[i].r) * reduceColourLit * boost + lightFog) * 1.0f)); - gPalette_light[i].g = (uint8)(min(0xFF, ((float)(gPalette[i].g) * reduceColourLit * boost + lightFog) * 0.85f)); - gPalette_light[i].b = (uint8)(min(0xFF, ((float)(gPalette[i].b) * reduceColourLit * boost + lightFog) * 0.30f)); + gPalette_light[i].r = (uint8)(min(0xFF, ((float)(gPalette[i].r) * reduceColourLit * boost + lightFog) * elecMultR)); + gPalette_light[i].g = (uint8)(min(0xFF, ((float)(gPalette[i].g) * reduceColourLit * boost + lightFog) * elecMultG)); + gPalette_light[i].b = (uint8)(min(0xFF, ((float)(gPalette[i].b) * reduceColourLit * boost + lightFog) * elecMultB)); #endif } From 8ed350e3b9399948d5e1dbe29062e0eb22c31f77 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Thu, 2 Jun 2016 02:39:35 +0200 Subject: [PATCH 12/44] Reduced darkening effect for environment light while looking at light --- src/platform/shared.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/shared.c b/src/platform/shared.c index edbc1f50c5..76b6986097 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -626,9 +626,9 @@ void platform_update_palette(const uint8* colours, int start_index, int num_colo // lightPollution /= 1.0f + fogginess * 1.0f; - natLightR /= 1.0f + lightPolution * 50.0f; - natLightG /= 1.0f + lightPolution * 50.0f; - natLightB /= 1.0f + lightPolution * 50.0f; + natLightR /= 1.0f + lightPolution * 20.0f; + natLightG /= 1.0f + lightPolution * 20.0f; + natLightB /= 1.0f + lightPolution * 20.0f; natLightR += elecMultR * 0.6f * lightPolution; natLightG += elecMultG * 0.6f * lightPolution; natLightB += elecMultB * 0.6f * lightPolution; From 1124b612e31d75151d8ab73a34a72f62f9ad7423 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Thu, 2 Jun 2016 02:39:45 +0200 Subject: [PATCH 13/44] Reduced light intensity --- src/drawing/lightfx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index d5175838fb..b61f96f444 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -64,9 +64,9 @@ static uint8 _current_view_zoom_back_delay = 0; uint8 calc_light_intensity_lantern(sint32 x, sint32 y) { double distance = (double)(x * x + y * y); - double light = 0.09 + pow(10.0 / (1.0 + distance / 100.0), 0.55); + double light = 0.03 + pow(10.0 / (1.0 + distance / 100.0), 0.55); light *= min(1.0, max(0.0f, 2.0 - sqrt(distance) / 64)); - light *= 0.15f; + light *= 0.1f; return (uint8)(min(255.0, light * 255.0)); } From 8ad7ed3ad0961d5c77dbadd4deb1eb9d8a1f3b19 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 00:40:25 +0200 Subject: [PATCH 14/44] Major updates to lightfx, enabling light consistency (non-duplication) and culling --- src/drawing/lightfx.c | 280 +++++++++++++++++++++++++++++++++++++----- src/drawing/lightfx.h | 6 +- 2 files changed, 255 insertions(+), 31 deletions(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index b61f96f444..c37c71c60c 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -39,7 +39,11 @@ static uint32 _lightPolution_front = 0; typedef struct lightlist_entry { sint16 x, y, z; uint8 lightType; - uint8 pad[3]; + uint8 lightIntensity; + uint32 lightID; + uint16 lightIDqualifier; + uint8 lightLinger; + uint8 pad[1]; } lightlist_entry; static lightlist_entry _LightListA[16000]; @@ -78,7 +82,7 @@ uint8 calc_light_intensity_spot(sint32 x, sint32 y) { light *= min(1.0, max(0.0f, 2.0 - sqrt(distance) / 64)); light *= 0.5f; - return (uint8)(min(255.0, light * 255.0)) >> 3; + return (uint8)(min(255.0, light * 255.0)) >> 4; } void calc_rescale_light_half( uint8 *target, uint8 *source,uint32 targetWidth, uint32 targetHeight) { @@ -140,13 +144,16 @@ void lightfx_update_buffers(rct_drawpixelinfo *info) memcpy(&_pixelInfo, info, sizeof(rct_drawpixelinfo)); } +extern void sub_68862C(); +extern void viewport_paint_setup(); + void lightfx_prepare_light_list() { - for (uint32 light = 0; light < LightListCurrentCountFront; light++) { lightlist_entry *entry = &_LightListFront[light]; if (entry->z == 0x7FFF) { + entry->lightIntensity = 0xFF; continue; } @@ -158,8 +165,189 @@ void lightfx_prepare_light_list() rct_xy16 coord_2d = coordinate_3d_to_2d(&coord_3d, _current_view_rotation_front); - entry->x = coord_2d.x - _current_view_x_front; - entry->y = coord_2d.y - _current_view_y_front; + entry->x = coord_2d.x;// - (_current_view_x_front); + entry->y = coord_2d.y;// - (_current_view_y_front); + + sint32 posOnScreenX = entry->x - _current_view_x_front; + sint32 posOnScreenY = entry->y - _current_view_y_front; + + if ((posOnScreenX < -128) || + (posOnScreenY < -128) || + (posOnScreenX > _pixelInfo.width + 128) || + (posOnScreenY > _pixelInfo.height + 128)) { + entry->lightIntensity = 0xFF; + continue; + } + + + // entry->x >>= _current_view_zoom_front; + // entry->y >>= _current_view_zoom_front; + + static sint16 offsetPattern[26] = { 0, 0, -7, 0, 0, -5, 7, 0, 0, 5, + -3, -1, -1, -2, 3, 1, 1, 2, + -6, -4, -6, 4, 6, -4, 6, 4 }; + + int mapFrontDiv = 1 << _current_view_zoom_front; + + uint32 lightIntensityOccluded = 0x0; + + sint32 dirVecX = 707; + sint32 dirVecY = 707; + + switch (_current_view_rotation_front) { + case 0: + dirVecX = 707; + dirVecY = 707; + break; + case 1: + dirVecX = -707; + dirVecY = 707; + break; + case 2: + dirVecX = -707; + dirVecY = -707; + break; + case 3: + dirVecX = 707; + dirVecY = -707; + break; + default: + dirVecX = 0; + dirVecY = 0; + break; + } + + if (true) { + int totalSamplePoints = 1; + int lastSampleCount = 0; + + for (int pat = 0; pat < totalSamplePoints; pat++) { + rct_xy16 mapCoord = { 0 }; + + rct_map_element *mapElement = 0; + + int interactionType; + + rct_window *w = window_get_main(); + if (w != NULL) { + // get_map_coordinates_from_pos(entry->x + offsetPattern[pat*2] / mapFrontDiv, entry->y + offsetPattern[pat*2+1] / mapFrontDiv, VIEWPORT_INTERACTION_MASK_NONE, &mapCoord.x, &mapCoord.y, &interactionType, &mapElement, NULL); + + RCT2_GLOBAL(0x9AC154, uint16_t) = VIEWPORT_INTERACTION_MASK_NONE & 0xFFFF; + RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16_t) = _current_view_zoom_front; + RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, int16_t) = entry->x + offsetPattern[0 + pat * 2] / mapFrontDiv; + RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_Y, int16_t) = entry->y + offsetPattern[1 + pat * 2] / mapFrontDiv; + rct_drawpixelinfo* dpi = RCT2_ADDRESS(RCT2_ADDRESS_VIEWPORT_DPI, rct_drawpixelinfo); + dpi->x = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, int16_t); + dpi->y = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_Y, int16_t); + dpi->zoom_level = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16_t); + dpi->height = 1; + dpi->width = 1; + RCT2_GLOBAL(0xEE7880, uint32_t) = 0xF1A4CC; + RCT2_GLOBAL(0x140E9A8, rct_drawpixelinfo*) = dpi; + painter_setup(); + viewport_paint_setup(); + sub_688217(); + sub_68862C(); + + // log_warning("[%i, %i]", dpi->x, dpi->y); + + mapCoord.x = RCT2_GLOBAL(0x9AC14C, int16_t); + mapCoord.y = RCT2_GLOBAL(0x9AC14E, int16_t); + interactionType = RCT2_GLOBAL(0x9AC148, uint8_t); + mapElement = RCT2_GLOBAL(0x9AC150, rct_map_element*); + + //RCT2_GLOBAL(0x9AC154, uint16_t) = VIEWPORT_INTERACTION_MASK_NONE; + //RCT2_GLOBAL(0x9AC148, uint8_t) = 0; + //RCT2_GLOBAL(0x9AC138 + 4, int16_t) = screenX; + //RCT2_GLOBAL(0x9AC138 + 6, int16_t) = screenY; + //if (screenX >= 0 && screenX < (int)myviewport->width && screenY >= 0 && screenY < (int)myviewport->height) + //{ + // screenX <<= myviewport->zoom; + // screenY <<= myviewport->zoom; + // screenX += (int)myviewport->view_x; + // screenY += (int)myviewport->view_y; + // RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16_t) = myviewport->zoom; + // screenX &= (0xFFFF << myviewport->zoom) & 0xFFFF; + // screenY &= (0xFFFF << myviewport->zoom) & 0xFFFF; + // RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, int16_t) = screenX; + // RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_Y, int16_t) = screenY; + // rct_drawpixelinfo* dpi = RCT2_ADDRESS(RCT2_ADDRESS_VIEWPORT_DPI, rct_drawpixelinfo); + // dpi->y = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_Y, int16_t); + // dpi->height = 1; + // dpi->zoom_level = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16_t); + // dpi->x = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, int16_t); + // dpi->width = 1; + // RCT2_GLOBAL(0xEE7880, uint32_t) = 0xF1A4CC; + // RCT2_GLOBAL(0x140E9A8, rct_drawpixelinfo*) = dpi; + // painter_setup(); + // viewport_paint_setup(); + // sub_688217(); + // sub_68862C(); + //} + } + + sint32 minDist = 0; + sint32 baseHeight = -999; + + if (interactionType != VIEWPORT_INTERACTION_ITEM_SPRITE && mapElement) { + baseHeight = mapElement->base_height; + } + + minDist = ((baseHeight * 8) - coord_3d.z) / 2; + + sint32 deltaX = mapCoord.x - coord_3d.x; + sint32 deltaY = mapCoord.y - coord_3d.y; + + sint32 projDot = (dirVecX * deltaX + dirVecY * deltaY) / 1000; + + projDot = max(minDist, projDot); + + if (projDot < 5) { + lightIntensityOccluded += 100; + } + else { + lightIntensityOccluded += max(0, 200 - (projDot * 20)); + } + + // log_warning("light %i [%i, %i, %i], [%i, %i] minDist to %i: %i; projdot: %i", light, coord_3d.x, coord_3d.y, coord_3d.z, mapCoord.x, mapCoord.y, baseHeight, minDist, projDot); + + // break; + + if (pat == 0) { + if (_current_view_zoom_front > 3) + break; + totalSamplePoints += 4; + } + else if (pat == 4) { + if (_current_view_zoom_front > 2) + break; + if (lightIntensityOccluded == 0 || lightIntensityOccluded == 500) + break; + lastSampleCount = lightIntensityOccluded / 500; + // break; + totalSamplePoints += 4; + } + else if (pat == 8) { + if (_current_view_zoom_front > 1) + break; + int newSampleCount = lightIntensityOccluded / 900; + if (abs(newSampleCount - lastSampleCount) < 10) + break; + totalSamplePoints += 4; + } + } + + if (lightIntensityOccluded == 0) { + entry->lightType = LIGHTFX_LIGHT_TYPE_NONE; + continue; + } + + // log_warning("sample-count: %i, occlusion: %i", totalSamplePoints, lightIntensityOccluded / totalSamplePoints); + + entry->lightIntensity = min(0xFF, (entry->lightIntensity * lightIntensityOccluded) / (totalSamplePoints * 100)); + + // log_warning("lightIntensityOccluded: %i, entry->lightIntensity: %i", lightIntensityOccluded, entry->lightIntensity); + } if (_current_view_zoom_front > 0) { if ((entry->lightType & 0x3) < _current_view_zoom_front) { @@ -167,8 +355,6 @@ void lightfx_prepare_light_list() continue; } - entry->x >>= _current_view_zoom_front; - entry->y >>= _current_view_zoom_front; entry->lightType -= _current_view_zoom_front; } } @@ -222,7 +408,6 @@ void lightfx_render_lights_to_frontbuffer() // log_warning("%i lights", LightListCurrentCountFront); for (uint32 light = 0; light < LightListCurrentCountFront; light++) { - const uint8 *bufReadBase = 0; uint8 *bufWriteBase = _light_rendered_buffer_front; uint32 bufReadWidth, bufReadHeight; @@ -232,6 +417,14 @@ void lightfx_render_lights_to_frontbuffer() lightlist_entry * entry = &_LightListFront[light]; + uint32 inRectCentreX = entry->x; + uint32 inRectCentreY = entry->y; + + if (entry->z != 0x7FFF) { + inRectCentreX -= _current_view_x_front; + inRectCentreY -= _current_view_y_front; + } + switch (entry->lightType) { case LIGHTFX_LIGHT_TYPE_LANTERN_0: bufReadWidth = 32; @@ -277,8 +470,8 @@ void lightfx_render_lights_to_frontbuffer() continue; } - bufWriteX = entry->x - bufReadWidth / 2; - bufWriteY = entry->y - bufReadHeight / 2; + bufWriteX = inRectCentreX - bufReadWidth / 2; + bufWriteY = inRectCentreY - bufReadHeight / 2; bufWriteWidth = bufReadWidth; bufWriteHeight = bufReadHeight; @@ -326,15 +519,29 @@ void lightfx_render_lights_to_frontbuffer() bufReadSkip = bufReadWidth - bufWriteWidth; bufWriteSkip = _pixelInfo.width - bufWriteWidth; - for (int y = 0; y < bufWriteHeight; y++) { - for (int x = 0; x < bufWriteWidth; x++) { - *bufWriteBase = min(0xFF, *bufWriteBase + *bufReadBase); - bufWriteBase++; - bufReadBase++; - } + if (entry->lightIntensity == 0xFF) { + for (int y = 0; y < bufWriteHeight; y++) { + for (int x = 0; x < bufWriteWidth; x++) { + *bufWriteBase = min(0xFF, *bufWriteBase + *bufReadBase); + bufWriteBase++; + bufReadBase++; + } - bufWriteBase += bufWriteSkip; - bufReadBase += bufReadSkip; + bufWriteBase += bufWriteSkip; + bufReadBase += bufReadSkip; + } + } + else { + for (int y = 0; y < bufWriteHeight; y++) { + for (int x = 0; x < bufWriteWidth; x++) { + *bufWriteBase = min(0xFF, *bufWriteBase + (((*bufReadBase) * (1 + entry->lightIntensity)) >> 8)); + bufWriteBase++; + bufReadBase++; + } + + bufWriteBase += bufWriteSkip; + bufReadBase += bufReadSkip; + } } } } @@ -344,32 +551,45 @@ void* lightfx_get_front_buffer() return _light_rendered_buffer_front; } -void lightfx_add_3d_light(sint16 x, sint16 y, uint16 z, uint8 lightType) +void lightfx_add_3d_light(uint32 lightID, uint16 lightIDqualifier, sint16 x, sint16 y, uint16 z, uint8 lightType) { if (LightListCurrentCountBack == 15999) { return; } +// log_warning("%i lights in back", LightListCurrentCountBack); + for (uint32 i = 0; i < LightListCurrentCountBack; i++) { lightlist_entry *entry = &_LightListBack[i]; - if (entry->x != x) + if (entry->lightID != lightID) continue; - if (entry->y != y) - continue; - if (entry->z != z) - continue; - if (entry->lightType != lightType) + if (entry->lightIDqualifier != lightIDqualifier) continue; + entry->x = x; + entry->y = y; + entry->z = z; + entry->lightType = lightType; + entry->lightIntensity = 0xFF; + entry->lightID = lightID; + entry->lightIDqualifier = lightIDqualifier; + entry->lightLinger = 1; + return; } lightlist_entry *entry = &_LightListBack[LightListCurrentCountBack++]; - entry->x = x; - entry->y = y; - entry->z = z; - entry->lightType = lightType; + entry->x = x; + entry->y = y; + entry->z = z; + entry->lightType = lightType; + entry->lightIntensity = 0xFF; + entry->lightID = lightID; + entry->lightIDqualifier = lightIDqualifier; + entry->lightLinger = 1; + +// log_warning("new 3d light"); } void lightfx_add_3d_light_magic_from_drawing_tile(sint16 offsetX, sint16 offsetY, sint16 offsetZ, uint8 lightType) @@ -398,7 +618,7 @@ void lightfx_add_3d_light_magic_from_drawing_tile(sint16 offsetX, sint16 offsetY return; } - lightfx_add_3d_light(x, y, offsetZ, lightType); + lightfx_add_3d_light((x << 16) | y, offsetZ, x, y, offsetZ, lightType); } uint32 lightfx_get_light_polution() diff --git a/src/drawing/lightfx.h b/src/drawing/lightfx.h index 2f8792a9c7..efee2de7d6 100644 --- a/src/drawing/lightfx.h +++ b/src/drawing/lightfx.h @@ -39,6 +39,10 @@ enum LIGHTFX_LIGHT_TYPE { LIGHTFX_LIGHT_TYPE_RESERVED_FF = 0xFF }; +enum LIGHTFX_LIGHT_QUALIFIER { + LIGHTFX_LIGHT_QUALIFIER_VEHICLE = 0x1 +}; + extern void lightfx_init(); extern void lightfx_update_buffers(rct_drawpixelinfo*); @@ -50,7 +54,7 @@ extern void lightfx_update_viewport_settings(); extern void* lightfx_get_front_buffer(); -extern void lightfx_add_3d_light(sint16 x, sint16 y, uint16 z, uint8 lightType); +extern void lightfx_add_3d_light(uint32 lightID, uint16 lightIDqualifier, sint16 x, sint16 y, uint16 z, uint8 lightType); extern void lightfx_add_3d_light_magic_from_drawing_tile(sint16 offsetX, sint16 offsetY, sint16 offsetZ, uint8 lightType); From b60cb199398fdf35aad533f40505011bd9d8249c Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 00:56:15 +0200 Subject: [PATCH 15/44] Renamed qualifier from vehicle to sprite (all sprites share a qualifier) --- src/drawing/lightfx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drawing/lightfx.h b/src/drawing/lightfx.h index efee2de7d6..c590a4aa3b 100644 --- a/src/drawing/lightfx.h +++ b/src/drawing/lightfx.h @@ -40,7 +40,7 @@ enum LIGHTFX_LIGHT_TYPE { }; enum LIGHTFX_LIGHT_QUALIFIER { - LIGHTFX_LIGHT_QUALIFIER_VEHICLE = 0x1 + LIGHTFX_LIGHT_QUALIFIER_SPRITE = 0x1 }; extern void lightfx_init(); From 158f75b70fa3a8c3d13e4309ffac991b4ab2799d Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 01:02:18 +0200 Subject: [PATCH 16/44] Peeps drawing light --- src/paint/sprite/peep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/paint/sprite/peep.c b/src/paint/sprite/peep.c index 60d69b384c..ded2953e9e 100644 --- a/src/paint/sprite/peep.c +++ b/src/paint/sprite/peep.c @@ -52,7 +52,8 @@ void peep_paint(rct_peep * peep, int imageDirection) return; }; - lightfx_add_3d_light(peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_SPOT_1); + uint32 uniqueID = RCT2_GLOBAL(0x9DE578, uint32); + lightfx_add_3d_light(uniqueID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_SPOT_1); } #endif From 49b749693b715429512d5def35f6f74e1143f936 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 01:02:35 +0200 Subject: [PATCH 17/44] Add light to cursor with special state --- src/platform/shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/shared.c b/src/platform/shared.c index 76b6986097..f7c3d0e0ea 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -374,7 +374,7 @@ void platform_draw() gfx_invalidate_screen(); - lightfx_add_3d_light(gCursorState.x, gCursorState.y, 0x7FFF, LIGHTFX_LIGHT_TYPE_LANTERN_3); + lightfx_add_3d_light(0xFFFFFFFF, 0xFFFF, gCursorState.x, gCursorState.y, 0x7FFF, LIGHTFX_LIGHT_TYPE_LANTERN_3); lightfx_update_viewport_settings(); lightfx_swap_buffers(); From c98b121a05311fc89b9475d8f2fc1bf05faac3c9 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 01:03:22 +0200 Subject: [PATCH 18/44] Add lights to rides --- src/ride/vehicle_paint.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/ride/vehicle_paint.c b/src/ride/vehicle_paint.c index 4cc2149586..1a61a3e3c0 100644 --- a/src/ride/vehicle_paint.c +++ b/src/ride/vehicle_paint.c @@ -2363,6 +2363,8 @@ void vehicle_paint(rct_vehicle *vehicle, int imageDirection) #ifdef STOUT_EXPANDED_RENDERING_LIGHT + uint32 vehicleID = RCT2_GLOBAL(0x9DE578, uint32); + sint16 place_x, place_y, place_z; place_x = vehicle->x; @@ -2375,27 +2377,28 @@ void vehicle_paint(rct_vehicle *vehicle, int imageDirection) case VEHICLE_VISUAL_MINI_GOLF_PLAYER: { place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32]; place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32]; - lightfx_add_3d_light(place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_1); + // lightfx_add_3d_light(place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_1); break; }; default: { rct_ride *ride = get_ride(vehicle->ride); switch (ride->type) { case RIDE_TYPE_OBSERVATION_TOWER: - lightfx_add_3d_light(vehicle->x, vehicle->y + 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); - lightfx_add_3d_light(vehicle->x + 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); - lightfx_add_3d_light(vehicle->x - 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); - lightfx_add_3d_light(vehicle->x, vehicle->y - 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y + 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x + 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x - 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicleID, 0x0300 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y - 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); break; case RIDE_TYPE_MINE_TRAIN_COASTER: + case RIDE_TYPE_GHOST_TRAIN: if (vehicle == vehicle_get_head(vehicle)) { place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(place_x, place_x, place_z, LIGHTFX_LIGHT_TYPE_LANTERN_3); + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_3); } break; case RIDE_TYPE_CHAIRLIFT: - lightfx_add_3d_light(place_x, place_y, place_z - 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z - 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); break; case RIDE_TYPE_BOAT_RIDE: case RIDE_TYPE_CAR_RIDE: @@ -2415,45 +2418,44 @@ void vehicle_paint(rct_vehicle *vehicle, int imageDirection) place_z = vehicle_draw->z; place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; - lightfx_add_3d_light(place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; - lightfx_add_3d_light(place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); } break; case RIDE_TYPE_MONORAIL: - lightfx_add_3d_light(vehicle->x, vehicle->y, vehicle->z + 12, LIGHTFX_LIGHT_TYPE_LANTERN_2); + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y, vehicle->z + 12, LIGHTFX_LIGHT_TYPE_SPOT_2); if (vehicle == vehicle_get_head(vehicle)) { place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 3; place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 3; - lightfx_add_3d_light(place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); } if (vehicle == vehicle_get_tail(vehicle)) { place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + lightfx_add_3d_light(vehicleID, 0x0300 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + lightfx_add_3d_light(vehicleID, 0x0400 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); } break; case RIDE_TYPE_MINIATURE_RAILWAY: if (vehicle == vehicle_get_head(vehicle)) { place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); } else { - lightfx_add_3d_light(vehicle->x, vehicle->y, vehicle->z + 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); } break; - case RIDE_TYPE_GHOST_TRAIN: default: break; }; From b0ab2b0a8d898900bf4ad9fa2348194d0d7d2b1d Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 05:25:28 +0200 Subject: [PATCH 19/44] Reduced light soft check radius --- src/drawing/lightfx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index c37c71c60c..87e081bc7d 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -183,9 +183,9 @@ void lightfx_prepare_light_list() // entry->x >>= _current_view_zoom_front; // entry->y >>= _current_view_zoom_front; - static sint16 offsetPattern[26] = { 0, 0, -7, 0, 0, -5, 7, 0, 0, 5, - -3, -1, -1, -2, 3, 1, 1, 2, - -6, -4, -6, 4, 6, -4, 6, 4 }; + static sint16 offsetPattern[26] = { 0, 0, -4, 0, 0, -3, 4, 0, 0, 3, + -2, -1, -1, -1, 2, 1, 1, 1, + -3, -2, -3, 2, 3, -2, 3, 2 }; int mapFrontDiv = 1 << _current_view_zoom_front; From 5ea9ec4eb631bc4a12452f22f44d7c1d3d4163a0 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 05:26:07 +0200 Subject: [PATCH 20/44] Introduced tile offset for viewing directions --- src/drawing/lightfx.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 87e081bc7d..50648e5af4 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -194,22 +194,33 @@ void lightfx_prepare_light_list() sint32 dirVecX = 707; sint32 dirVecY = 707; + sint32 tileOffsetX = 0; + sint32 tileOffsetY = 0; + switch (_current_view_rotation_front) { case 0: dirVecX = 707; dirVecY = 707; + tileOffsetX = 0; + tileOffsetY = 0; break; case 1: dirVecX = -707; dirVecY = 707; + tileOffsetX = 16; + tileOffsetY = 0; break; case 2: dirVecX = -707; dirVecY = -707; + tileOffsetX = 32; + tileOffsetY = 32; break; case 3: dirVecX = 707; dirVecY = -707; + tileOffsetX = 0; + tileOffsetY = 16; break; default: dirVecX = 0; From f903b0c0942c72c3b2f08fa5763edf5819c76a2f Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 05:26:32 +0200 Subject: [PATCH 21/44] For now no longer occluding lights by sprites. --- src/drawing/lightfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 50648e5af4..bfff312c13 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -243,7 +243,7 @@ void lightfx_prepare_light_list() if (w != NULL) { // get_map_coordinates_from_pos(entry->x + offsetPattern[pat*2] / mapFrontDiv, entry->y + offsetPattern[pat*2+1] / mapFrontDiv, VIEWPORT_INTERACTION_MASK_NONE, &mapCoord.x, &mapCoord.y, &interactionType, &mapElement, NULL); - RCT2_GLOBAL(0x9AC154, uint16_t) = VIEWPORT_INTERACTION_MASK_NONE & 0xFFFF; + RCT2_GLOBAL(0x9AC154, uint16_t) = ~VIEWPORT_INTERACTION_MASK_SPRITE & 0xFFFF; RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16_t) = _current_view_zoom_front; RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, int16_t) = entry->x + offsetPattern[0 + pat * 2] / mapFrontDiv; RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_Y, int16_t) = entry->y + offsetPattern[1 + pat * 2] / mapFrontDiv; From a099096f1bd98851fbbc52555b3a1b5ea4cbf359 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 05:26:42 +0200 Subject: [PATCH 22/44] Added offset to map coord. --- src/drawing/lightfx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index bfff312c13..d0bd0c254a 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -262,8 +262,8 @@ void lightfx_prepare_light_list() // log_warning("[%i, %i]", dpi->x, dpi->y); - mapCoord.x = RCT2_GLOBAL(0x9AC14C, int16_t); - mapCoord.y = RCT2_GLOBAL(0x9AC14E, int16_t); + mapCoord.x = RCT2_GLOBAL(0x9AC14C, int16_t) + tileOffsetX; + mapCoord.y = RCT2_GLOBAL(0x9AC14E, int16_t) + tileOffsetY; interactionType = RCT2_GLOBAL(0x9AC148, uint8_t); mapElement = RCT2_GLOBAL(0x9AC150, rct_map_element*); From 3f10698bf7f1b599b0b76a08a53ba40d31713b64 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 15:31:32 +0200 Subject: [PATCH 23/44] Removed insertion code from vehicle paint (was unreliable) --- src/ride/vehicle_paint.c | 103 --------------------------------------- 1 file changed, 103 deletions(-) diff --git a/src/ride/vehicle_paint.c b/src/ride/vehicle_paint.c index 1a61a3e3c0..15e3a10088 100644 --- a/src/ride/vehicle_paint.c +++ b/src/ride/vehicle_paint.c @@ -2361,109 +2361,6 @@ void vehicle_paint(rct_vehicle *vehicle, int imageDirection) } } -#ifdef STOUT_EXPANDED_RENDERING_LIGHT - - uint32 vehicleID = RCT2_GLOBAL(0x9DE578, uint32); - - sint16 place_x, place_y, place_z; - - place_x = vehicle->x; - place_y = vehicle->y; - place_z = vehicle->z; - - static const sint16 offsetLookup[32] = { 10, 10, 9, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -9, -10, -10, -10, -9, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 9, 10 }; - - switch (vehicleEntry->car_visual) { - case VEHICLE_VISUAL_MINI_GOLF_PLAYER: { - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32]; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32]; - // lightfx_add_3d_light(place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_1); - break; - }; - default: { - rct_ride *ride = get_ride(vehicle->ride); - switch (ride->type) { - case RIDE_TYPE_OBSERVATION_TOWER: - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y + 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); - lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x + 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); - lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x - 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); - lightfx_add_3d_light(vehicleID, 0x0300 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y - 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); - break; - case RIDE_TYPE_MINE_TRAIN_COASTER: - case RIDE_TYPE_GHOST_TRAIN: - if (vehicle == vehicle_get_head(vehicle)) { - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_3); - } - break; - case RIDE_TYPE_CHAIRLIFT: - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z - 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); - break; - case RIDE_TYPE_BOAT_RIDE: - case RIDE_TYPE_CAR_RIDE: - case RIDE_TYPE_GO_KARTS: - case RIDE_TYPE_DODGEMS: - case RIDE_TYPE_MINI_HELICOPTERS: - case RIDE_TYPE_MONORAIL_CYCLES: - case RIDE_TYPE_SUBMARINE_RIDE: - case RIDE_TYPE_SPLASH_BOATS: - case RIDE_TYPE_WATER_COASTER: { - rct_vehicle *vehicle_draw = vehicle_get_head(vehicle); - if (vehicle_draw->next_vehicle_on_train != 0xFFFF) { - vehicle_draw = GET_VEHICLE(vehicle_draw->next_vehicle_on_train); - } - place_x = vehicle_draw->x; - place_y = vehicle_draw->y; - place_z = vehicle_draw->z; - place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; - place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); - place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; - place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; - lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); - } - break; - case RIDE_TYPE_MONORAIL: - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y, vehicle->z + 12, LIGHTFX_LIGHT_TYPE_SPOT_2); - if (vehicle == vehicle_get_head(vehicle)) { - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 3; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 3; - lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); - } - if (vehicle == vehicle_get_tail(vehicle)) { - place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0300 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); - place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0400 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); - } - break; - case RIDE_TYPE_MINIATURE_RAILWAY: - if (vehicle == vehicle_get_head(vehicle)) { - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); - } - else { - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); - } - break; - default: - break; - }; - }; - } - -#endif - uint32 rct2VehiclePtrFormat = ((uint32)vehicleEntry) - offsetof(rct_ride_entry, vehicles); RCT2_GLOBAL(0x00F64DFC, uint32) = rct2VehiclePtrFormat; switch (vehicleEntry->car_visual) { From 91b97f7b7a7ba22c4255af3dc31f7c3eeff9f183 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 15:31:46 +0200 Subject: [PATCH 24/44] Added sprite source identifier --- src/drawing/lightfx.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/drawing/lightfx.h b/src/drawing/lightfx.h index c590a4aa3b..c60fa31cb6 100644 --- a/src/drawing/lightfx.h +++ b/src/drawing/lightfx.h @@ -40,7 +40,8 @@ enum LIGHTFX_LIGHT_TYPE { }; enum LIGHTFX_LIGHT_QUALIFIER { - LIGHTFX_LIGHT_QUALIFIER_SPRITE = 0x1 + LIGHTFX_LIGHT_QUALIFIER_SPRITE = 0x1, + LIGHTFX_LIGHT_QUALIFIER_MAP = 0x2 }; extern void lightfx_init(); From b1968936030545408078e4afdbb706cc7147b06e Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 15:31:56 +0200 Subject: [PATCH 25/44] Added 'magic' function for adding all vehicles to light list --- src/drawing/lightfx.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/drawing/lightfx.h b/src/drawing/lightfx.h index c60fa31cb6..c39cb44f8d 100644 --- a/src/drawing/lightfx.h +++ b/src/drawing/lightfx.h @@ -59,6 +59,8 @@ extern void lightfx_add_3d_light(uint32 lightID, uint16 lightIDqualifier, sint16 extern void lightfx_add_3d_light_magic_from_drawing_tile(sint16 offsetX, sint16 offsetY, sint16 offsetZ, uint8 lightType); +extern void lightfx_add_lights_magic_vehicles(); + extern uint32 lightfx_get_light_polution(); #endif From fb7b31a379cfaec5dc07b8eb2d0704c07f449ea6 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 15:32:13 +0200 Subject: [PATCH 26/44] Calling 'magic' all lights by vehicles function --- src/platform/shared.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/platform/shared.c b/src/platform/shared.c index f7c3d0e0ea..893a45798c 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -374,6 +374,7 @@ void platform_draw() gfx_invalidate_screen(); + lightfx_add_lights_magic_vehicles(); lightfx_add_3d_light(0xFFFFFFFF, 0xFFFF, gCursorState.x, gCursorState.y, 0x7FFF, LIGHTFX_LIGHT_TYPE_LANTERN_3); lightfx_update_viewport_settings(); From b5abb21445079ccb3dee653d5508df07b652f307 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 15:33:20 +0200 Subject: [PATCH 27/44] Better dynamic dithering for light cull check --- src/drawing/lightfx.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index d0bd0c254a..7541727fae 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -229,10 +229,16 @@ void lightfx_prepare_light_list() } if (true) { - int totalSamplePoints = 1; + int totalSamplePoints = 5; + int startSamplePoint = 1; int lastSampleCount = 0; - for (int pat = 0; pat < totalSamplePoints; pat++) { + if ((entry->lightIDqualifier & 0xF) == LIGHTFX_LIGHT_QUALIFIER_MAP) { + startSamplePoint = 0; + totalSamplePoints = 1; + } + + for (int pat = startSamplePoint; pat < totalSamplePoints; pat++) { rct_xy16 mapCoord = { 0 }; rct_map_element *mapElement = 0; @@ -322,15 +328,16 @@ void lightfx_prepare_light_list() // log_warning("light %i [%i, %i, %i], [%i, %i] minDist to %i: %i; projdot: %i", light, coord_3d.x, coord_3d.y, coord_3d.z, mapCoord.x, mapCoord.y, baseHeight, minDist, projDot); - // break; if (pat == 0) { - if (_current_view_zoom_front > 3) + if (lightIntensityOccluded == 100) + break; + if (_current_view_zoom_front > 2) break; totalSamplePoints += 4; } else if (pat == 4) { - if (_current_view_zoom_front > 2) + if (_current_view_zoom_front > 1) break; if (lightIntensityOccluded == 0 || lightIntensityOccluded == 500) break; @@ -339,7 +346,8 @@ void lightfx_prepare_light_list() totalSamplePoints += 4; } else if (pat == 8) { - if (_current_view_zoom_front > 1) + break; + if (_current_view_zoom_front > 0) break; int newSampleCount = lightIntensityOccluded / 900; if (abs(newSampleCount - lastSampleCount) < 10) @@ -348,6 +356,12 @@ void lightfx_prepare_light_list() } } + totalSamplePoints -= startSamplePoint; + + // lightIntensityOccluded = totalSamplePoints * 100; + + // log_warning("sample-count: %i, occlusion: %i", totalSamplePoints, lightIntensityOccluded); + if (lightIntensityOccluded == 0) { entry->lightType = LIGHTFX_LIGHT_TYPE_NONE; continue; From add1e47d09213b2d22bafd563146881fa7c214c6 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 15:33:43 +0200 Subject: [PATCH 28/44] Gave map-based lights a qualifier from magic function --- src/drawing/lightfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 7541727fae..1db1ffe6e6 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -643,7 +643,7 @@ void lightfx_add_3d_light_magic_from_drawing_tile(sint16 offsetX, sint16 offsetY return; } - lightfx_add_3d_light((x << 16) | y, offsetZ, x, y, offsetZ, lightType); + lightfx_add_3d_light((x << 16) | y, (offsetZ << 8) | LIGHTFX_LIGHT_QUALIFIER_MAP, x, y, offsetZ, lightType); } uint32 lightfx_get_light_polution() From 2ea10a1e6b248efbc6c7e2704150f5c0bb8dbfd7 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 15:33:53 +0200 Subject: [PATCH 29/44] Add all lights from vehicles function --- src/drawing/lightfx.c | 128 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 1db1ffe6e6..43365ab49e 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -649,4 +649,132 @@ void lightfx_add_3d_light_magic_from_drawing_tile(sint16 offsetX, sint16 offsetY uint32 lightfx_get_light_polution() { return _lightPolution_front; +} + +void lightfx_add_lights_magic_vehicles() +{ + for (uint16 i = gSpriteListHead[SPRITE_LIST_VEHICLE]; i != SPRITE_INDEX_NULL; i = g_sprite_list[i].vehicle.next) { + uint32 vehicleID = i; + + rct_vehicle *mother_vehicle = GET_VEHICLE(i); + rct_vehicle *vehicle = mother_vehicle; + + rct_ride_entry *rideEntry = 0; + const rct_ride_entry_vehicle *vehicleEntry; + + if (mother_vehicle->ride_subtype == 0xFF) { + continue; + } + else { + rideEntry = get_ride_entry(mother_vehicle->ride_subtype); + vehicleEntry = &rideEntry->vehicles[mother_vehicle->vehicle_type]; + } + + for (uint16 q = i; q != SPRITE_INDEX_NULL; ) { + rct_vehicle *vehicle = GET_VEHICLE(q); + + vehicleID = q; + if (vehicle->next_vehicle_on_train == q) + break; + q = vehicle->next_vehicle_on_train; + + sint16 place_x, place_y, place_z; + + place_x = vehicle->x; + place_y = vehicle->y; + place_z = vehicle->z; + + static const sint16 offsetLookup[32] = { 10, 10, 9, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -9, -10, -10, -10, -9, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 9, 10 }; + + switch (vehicleEntry->car_visual) { + case VEHICLE_VISUAL_MINI_GOLF_PLAYER: { + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32]; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32]; + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_1); + break; + }; + default: { + rct_ride *ride = get_ride(vehicle->ride); + switch (ride->type) { + case RIDE_TYPE_OBSERVATION_TOWER: + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y + 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x + 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x - 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicleID, 0x0300 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y - 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + break; + case RIDE_TYPE_MINE_TRAIN_COASTER: + case RIDE_TYPE_GHOST_TRAIN: + if (vehicle == vehicle_get_head(vehicle)) { + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_3); + } + break; + case RIDE_TYPE_CHAIRLIFT: + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z - 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); + break; + case RIDE_TYPE_BOAT_RIDE: + case RIDE_TYPE_CAR_RIDE: + case RIDE_TYPE_GO_KARTS: + case RIDE_TYPE_DODGEMS: + case RIDE_TYPE_MINI_HELICOPTERS: + case RIDE_TYPE_MONORAIL_CYCLES: + case RIDE_TYPE_SUBMARINE_RIDE: + case RIDE_TYPE_SPLASH_BOATS: + case RIDE_TYPE_WATER_COASTER: { + rct_vehicle *vehicle_draw = vehicle_get_head(vehicle); + if (vehicle_draw->next_vehicle_on_train != 0xFFFF) { + vehicle_draw = GET_VEHICLE(vehicle_draw->next_vehicle_on_train); + } + place_x = vehicle_draw->x; + place_y = vehicle_draw->y; + place_z = vehicle_draw->z; + place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; + place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); + place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; + place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); + break; + } + case RIDE_TYPE_MONORAIL: + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y, vehicle->z + 12, LIGHTFX_LIGHT_TYPE_SPOT_2); + if (vehicle == vehicle_get_head(vehicle)) { + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 3; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 3; + lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + if (vehicle == vehicle_get_tail(vehicle)) { + place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0300 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0400 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + break; + case RIDE_TYPE_MINIATURE_RAILWAY: + if (vehicle == vehicle_get_head(vehicle)) { + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + + } + else { + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + break; + default: + break; + }; + }; + } + } + } } \ No newline at end of file From 12a0c87bfd80b179606d05ee377be7b75d6f4f12 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 16:22:14 +0200 Subject: [PATCH 30/44] Culling based on viewport for zoom levels --- src/drawing/lightfx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 43365ab49e..aca15052a6 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -171,6 +171,9 @@ void lightfx_prepare_light_list() sint32 posOnScreenX = entry->x - _current_view_x_front; sint32 posOnScreenY = entry->y - _current_view_y_front; + posOnScreenX >>= _current_view_zoom_front; + posOnScreenY >>= _current_view_zoom_front; + if ((posOnScreenX < -128) || (posOnScreenY < -128) || (posOnScreenX > _pixelInfo.width + 128) || From de4b79b4199cd26c98c8fa6997b86dff21d5da08 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 16:22:21 +0200 Subject: [PATCH 31/44] Remove light when off-screen --- src/drawing/lightfx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index aca15052a6..a93f5aaf3d 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -178,7 +178,7 @@ void lightfx_prepare_light_list() (posOnScreenY < -128) || (posOnScreenX > _pixelInfo.width + 128) || (posOnScreenY > _pixelInfo.height + 128)) { - entry->lightIntensity = 0xFF; + entry->lightType = LIGHTFX_LIGHT_TYPE_NONE; continue; } From 956c796f4a6ee52252782b12068f5d0b495f74d0 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 16:23:05 +0200 Subject: [PATCH 32/44] Reduce light intensity for zoom levels --- src/drawing/lightfx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index a93f5aaf3d..88355b44de 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -373,8 +373,7 @@ void lightfx_prepare_light_list() // log_warning("sample-count: %i, occlusion: %i", totalSamplePoints, lightIntensityOccluded / totalSamplePoints); entry->lightIntensity = min(0xFF, (entry->lightIntensity * lightIntensityOccluded) / (totalSamplePoints * 100)); - - // log_warning("lightIntensityOccluded: %i, entry->lightIntensity: %i", lightIntensityOccluded, entry->lightIntensity); + entry->lightIntensity = max(0x00, entry->lightIntensity - _current_view_zoom_front * 5); } if (_current_view_zoom_front > 0) { From e299b4d7f7e593adfe06270031636edc80d14303 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 16:23:23 +0200 Subject: [PATCH 33/44] Moving lights correctly on-screen for zoom --- src/drawing/lightfx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 88355b44de..0685c6de15 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -444,12 +444,14 @@ void lightfx_render_lights_to_frontbuffer() lightlist_entry * entry = &_LightListFront[light]; - uint32 inRectCentreX = entry->x; - uint32 inRectCentreY = entry->y; + sint32 inRectCentreX = entry->x; + sint32 inRectCentreY = entry->y; if (entry->z != 0x7FFF) { inRectCentreX -= _current_view_x_front; inRectCentreY -= _current_view_y_front; + inRectCentreX >>= _current_view_zoom_front; + inRectCentreY >>= _current_view_zoom_front; } switch (entry->lightType) { From 9be89416e49bfaf3011731a291326d40e52d2f76 Mon Sep 17 00:00:00 2001 From: Jeroen D Stout Date: Sat, 4 Jun 2016 16:23:49 +0200 Subject: [PATCH 34/44] Removed minigolf check --- src/drawing/lightfx.c | 166 ++++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 88 deletions(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 0685c6de15..4f57826f14 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -690,95 +690,85 @@ void lightfx_add_lights_magic_vehicles() static const sint16 offsetLookup[32] = { 10, 10, 9, 8, 7, 6, 4, 2, 0, -2, -4, -6, -7, -8, -9, -10, -10, -10, -9, -8, -7, -6, -4, -2, 0, 2, 4, 6, 7, 8, 9, 10 }; - switch (vehicleEntry->car_visual) { - case VEHICLE_VISUAL_MINI_GOLF_PLAYER: { - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32]; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32]; - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_1); - break; - }; - default: { - rct_ride *ride = get_ride(vehicle->ride); - switch (ride->type) { - case RIDE_TYPE_OBSERVATION_TOWER: - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y + 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); - lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x + 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); - lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x - 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); - lightfx_add_3d_light(vehicleID, 0x0300 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y - 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); - break; - case RIDE_TYPE_MINE_TRAIN_COASTER: - case RIDE_TYPE_GHOST_TRAIN: - if (vehicle == vehicle_get_head(vehicle)) { - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_3); - } - break; - case RIDE_TYPE_CHAIRLIFT: - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z - 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); - break; - case RIDE_TYPE_BOAT_RIDE: - case RIDE_TYPE_CAR_RIDE: - case RIDE_TYPE_GO_KARTS: - case RIDE_TYPE_DODGEMS: - case RIDE_TYPE_MINI_HELICOPTERS: - case RIDE_TYPE_MONORAIL_CYCLES: - case RIDE_TYPE_SUBMARINE_RIDE: - case RIDE_TYPE_SPLASH_BOATS: - case RIDE_TYPE_WATER_COASTER: { - rct_vehicle *vehicle_draw = vehicle_get_head(vehicle); - if (vehicle_draw->next_vehicle_on_train != 0xFFFF) { - vehicle_draw = GET_VEHICLE(vehicle_draw->next_vehicle_on_train); - } - place_x = vehicle_draw->x; - place_y = vehicle_draw->y; - place_z = vehicle_draw->z; - place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; - place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); - place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; - place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; - lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); - break; - } - case RIDE_TYPE_MONORAIL: - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y, vehicle->z + 12, LIGHTFX_LIGHT_TYPE_SPOT_2); - if (vehicle == vehicle_get_head(vehicle)) { - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 3; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 3; - lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); - } - if (vehicle == vehicle_get_tail(vehicle)) { - place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0300 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); - place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0400 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); - } - break; - case RIDE_TYPE_MINIATURE_RAILWAY: - if (vehicle == vehicle_get_head(vehicle)) { - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); - place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; - place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; - lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); - - } - else { - lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); - } - break; - default: - break; - }; - }; + rct_ride *ride = get_ride(vehicle->ride); + switch (ride->type) { + case RIDE_TYPE_OBSERVATION_TOWER: + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y + 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x + 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x - 16, vehicle->y, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + lightfx_add_3d_light(vehicleID, 0x0300 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y - 16, vehicle->z, LIGHTFX_LIGHT_TYPE_SPOT_3); + break; + case RIDE_TYPE_MINE_TRAIN_COASTER: + case RIDE_TYPE_GHOST_TRAIN: + if (vehicle == vehicle_get_head(vehicle)) { + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_3); + } + break; + case RIDE_TYPE_CHAIRLIFT: + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z - 16, LIGHTFX_LIGHT_TYPE_LANTERN_2); + break; + case RIDE_TYPE_BOAT_RIDE: + case RIDE_TYPE_CAR_RIDE: + case RIDE_TYPE_GO_KARTS: + case RIDE_TYPE_DODGEMS: + case RIDE_TYPE_MINI_HELICOPTERS: + case RIDE_TYPE_MONORAIL_CYCLES: + case RIDE_TYPE_SUBMARINE_RIDE: + case RIDE_TYPE_SPLASH_BOATS: + case RIDE_TYPE_WATER_COASTER: { + rct_vehicle *vehicle_draw = vehicle_get_head(vehicle); + if (vehicle_draw->next_vehicle_on_train != 0xFFFF) { + vehicle_draw = GET_VEHICLE(vehicle_draw->next_vehicle_on_train); + } + place_x = vehicle_draw->x; + place_y = vehicle_draw->y; + place_z = vehicle_draw->z; + place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; + place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); + place_x -= offsetLookup[(vehicle_draw->sprite_direction + 0) % 32]; + place_y -= offsetLookup[(vehicle_draw->sprite_direction + 8) % 32]; + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z, LIGHTFX_LIGHT_TYPE_SPOT_2); + break; } + case RIDE_TYPE_MONORAIL: + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, vehicle->x, vehicle->y, vehicle->z + 12, LIGHTFX_LIGHT_TYPE_SPOT_2); + if (vehicle == vehicle_get_head(vehicle)) { + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 3; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 3; + lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + if (vehicle == vehicle_get_tail(vehicle)) { + place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0300 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x += offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y += offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0400 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + break; + case RIDE_TYPE_MINIATURE_RAILWAY: + if (vehicle == vehicle_get_head(vehicle)) { + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0100 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + place_x -= offsetLookup[(vehicle->sprite_direction + 0) % 32] * 2; + place_y -= offsetLookup[(vehicle->sprite_direction + 8) % 32] * 2; + lightfx_add_3d_light(vehicleID, 0x0200 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 2, LIGHTFX_LIGHT_TYPE_LANTERN_3); + + } + else { + lightfx_add_3d_light(vehicleID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, place_x, place_y, place_z + 10, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + break; + default: + break; + }; } } } \ No newline at end of file From 55cae4a2309d7c0b0d0736a29925885e618fdcf4 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 17 Oct 2016 00:03:32 +0100 Subject: [PATCH 35/44] Fix compile errors --- src/drawing/lightfx.c | 47 +++++++++++++++++++++++------------------ src/paint/sprite/peep.c | 3 +-- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 4f57826f14..7c4ebcd302 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -19,6 +19,7 @@ #include "../rct2.h" #include "../interface/window.h" #include "../interface/viewport.h" +#include "../paint/map_element/map_element.h" static uint8 _bakedLightTexture_lantern_0[32*32]; static uint8 _bakedLightTexture_lantern_1[64*64]; @@ -246,24 +247,25 @@ void lightfx_prepare_light_list() rct_map_element *mapElement = 0; - int interactionType; + int interactionType = 0; rct_window *w = window_get_main(); if (w != NULL) { // get_map_coordinates_from_pos(entry->x + offsetPattern[pat*2] / mapFrontDiv, entry->y + offsetPattern[pat*2+1] / mapFrontDiv, VIEWPORT_INTERACTION_MASK_NONE, &mapCoord.x, &mapCoord.y, &interactionType, &mapElement, NULL); - RCT2_GLOBAL(0x9AC154, uint16_t) = ~VIEWPORT_INTERACTION_MASK_SPRITE & 0xFFFF; - RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16_t) = _current_view_zoom_front; - RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, int16_t) = entry->x + offsetPattern[0 + pat * 2] / mapFrontDiv; - RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_Y, int16_t) = entry->y + offsetPattern[1 + pat * 2] / mapFrontDiv; - rct_drawpixelinfo* dpi = RCT2_ADDRESS(RCT2_ADDRESS_VIEWPORT_DPI, rct_drawpixelinfo); - dpi->x = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_X, int16_t); - dpi->y = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_PAINT_Y, int16_t); - dpi->zoom_level = RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16_t); +#if 0 + _unk9AC154 = ~VIEWPORT_INTERACTION_MASK_SPRITE & 0xFFFF; + _viewportDpi1.zoom = _current_view_zoom_front; + _viewportDpi1.x = entry->x + offsetPattern[0 + pat * 2] / mapFrontDiv; + _viewportDpi1.y = entry->y + offsetPattern[1 + pat * 2] / mapFrontDiv; + rct_drawpixelinfo* dpi = &_viewportDpi2; + dpi->x = _viewportDpi1.x; + dpi->y = _viewportDpi1.y; + dpi->zoom_level = _viewportDpi1.zoom; dpi->height = 1; dpi->width = 1; - RCT2_GLOBAL(0xEE7880, uint32_t) = 0xF1A4CC; - RCT2_GLOBAL(0x140E9A8, rct_drawpixelinfo*) = dpi; + gEndOfPaintStructArray = 0xF1A4CC; + unk_140E9A8 = dpi; painter_setup(); viewport_paint_setup(); sub_688217(); @@ -271,10 +273,11 @@ void lightfx_prepare_light_list() // log_warning("[%i, %i]", dpi->x, dpi->y); - mapCoord.x = RCT2_GLOBAL(0x9AC14C, int16_t) + tileOffsetX; - mapCoord.y = RCT2_GLOBAL(0x9AC14E, int16_t) + tileOffsetY; - interactionType = RCT2_GLOBAL(0x9AC148, uint8_t); + mapCoord.x = _unk9AC14C + tileOffsetX; + mapCoord.y = _unk9AC14E + tileOffsetY; + interactionType = _unk9AC148; mapElement = RCT2_GLOBAL(0x9AC150, rct_map_element*); +#endif //RCT2_GLOBAL(0x9AC154, uint16_t) = VIEWPORT_INTERACTION_MASK_NONE; //RCT2_GLOBAL(0x9AC148, uint8_t) = 0; @@ -623,8 +626,8 @@ void lightfx_add_3d_light(uint32 lightID, uint16 lightIDqualifier, sint16 x, sin void lightfx_add_3d_light_magic_from_drawing_tile(sint16 offsetX, sint16 offsetY, sint16 offsetZ, uint8 lightType) { - sint16 x = RCT2_GLOBAL(0x9DE56A, sint16) + offsetX; - sint16 y = RCT2_GLOBAL(0x9DE56C, sint16) + offsetY; + sint16 x = gPaintMapPosition.x + offsetX; + sint16 y = gPaintMapPosition.y + offsetY; switch (get_current_rotation()) { case 0: @@ -657,11 +660,13 @@ uint32 lightfx_get_light_polution() void lightfx_add_lights_magic_vehicles() { - for (uint16 i = gSpriteListHead[SPRITE_LIST_VEHICLE]; i != SPRITE_INDEX_NULL; i = g_sprite_list[i].vehicle.next) { - uint32 vehicleID = i; + uint16 spriteIndex = gSpriteListHead[SPRITE_LIST_VEHICLE]; + while (spriteIndex != SPRITE_INDEX_NULL) { + rct_vehicle * vehicle = &(get_sprite(spriteIndex)->vehicle); + uint16 vehicleID = spriteIndex; + spriteIndex = vehicle->next; - rct_vehicle *mother_vehicle = GET_VEHICLE(i); - rct_vehicle *vehicle = mother_vehicle; + rct_vehicle *mother_vehicle = vehicle; rct_ride_entry *rideEntry = 0; const rct_ride_entry_vehicle *vehicleEntry; @@ -674,7 +679,7 @@ void lightfx_add_lights_magic_vehicles() vehicleEntry = &rideEntry->vehicles[mother_vehicle->vehicle_type]; } - for (uint16 q = i; q != SPRITE_INDEX_NULL; ) { + for (uint16 q = vehicleID; q != SPRITE_INDEX_NULL; ) { rct_vehicle *vehicle = GET_VEHICLE(q); vehicleID = q; diff --git a/src/paint/sprite/peep.c b/src/paint/sprite/peep.c index 6539fe3ed7..5431045e1c 100644 --- a/src/paint/sprite/peep.c +++ b/src/paint/sprite/peep.c @@ -53,8 +53,7 @@ void peep_paint(rct_peep * peep, int imageDirection) return; }; - uint32 uniqueID = RCT2_GLOBAL(0x9DE578, uint32); - lightfx_add_3d_light(uniqueID, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_SPOT_1); + lightfx_add_3d_light(peep->sprite_index, 0x0000 | LIGHTFX_LIGHT_QUALIFIER_SPRITE, peep_x, peep_y, peep_z, LIGHTFX_LIGHT_TYPE_SPOT_1); } #endif From c4f67e9d95ff9ac7f988595bc41205da9212dadc Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 17 Oct 2016 18:43:44 +0100 Subject: [PATCH 36/44] Use lightfx palette transform --- src/drawing/lightfx.c | 195 +++++++++++++++++++++++++++++++++++++++++- src/drawing/lightfx.h | 2 + src/platform/shared.c | 22 +++-- 3 files changed, 208 insertions(+), 11 deletions(-) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 7c4ebcd302..811b23748c 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -14,12 +14,14 @@ *****************************************************************************/ #pragma endregion -#include "lightfx.h" -#include "drawing.h" +#include "../game.h" #include "../rct2.h" -#include "../interface/window.h" #include "../interface/viewport.h" +#include "../interface/window.h" #include "../paint/map_element/map_element.h" +#include "../world/climate.h" +#include "drawing.h" +#include "lightfx.h" static uint8 _bakedLightTexture_lantern_0[32*32]; static uint8 _bakedLightTexture_lantern_1[64*64]; @@ -66,6 +68,12 @@ static uint8 _current_view_rotation_back = 0; static uint8 _current_view_zoom_back = 0; static uint8 _current_view_zoom_back_delay = 0; +static SDL_Color gPalette_light[256]; + +static uint8 soft_light(uint8 a, uint8 b); +static uint8 lerp(uint8 a, uint8 b, float t); +static float flerp(float a, float b, float t); + uint8 calc_light_intensity_lantern(sint32 x, sint32 y) { double distance = (double)(x * x + y * y); @@ -776,4 +784,183 @@ void lightfx_add_lights_magic_vehicles() }; } } -} \ No newline at end of file +} + +void lightfx_apply_palette_filter(uint8 i, uint8 *r, uint8 *g, uint8 *b) +{ + float night = (float)(pow(gDayNightCycle, 1.5)); + + float natLightR = 1.0f; + float natLightG = 1.0f; + float natLightB = 1.0f; + + float elecMultR = 1.0f; + float elecMultG = 0.95f; + float elecMultB = 0.45f; + + static float wetness = 0.0f; + static float fogginess = 0.0f; + static float lightPolution = 0.0f; + + float sunLight = max(0.0f, min(1.0f, 2.0f - night * 3.0f)); + + // Night version + natLightR = flerp(natLightR * 4.0f, 0.635f, (float)(pow(night, 0.035f + sunLight * 10.50f))); + natLightG = flerp(natLightG * 4.0f, 0.650f, (float)(pow(night, 0.100f + sunLight * 5.50f))); + natLightB = flerp(natLightB * 4.0f, 0.850f, (float)(pow(night, 0.200f + sunLight * 1.5f))); + + float lightAvg = (natLightR + natLightG + natLightB) / 3.0f; + float lightMax = (natLightR + natLightG + natLightB) / 3.0f; + float overExpose = 0.0f; + + // overExpose += ((lightMax - lightAvg) / lightMax) * 0.01f; + + if (gClimateCurrentTemperature > 20) { + float offset = ((float)(gClimateCurrentTemperature - 20)) * 0.04f; + offset *= 1.0f - night; + lightAvg /= 1.0f + offset; + // overExpose += offset * 0.1f; + } + + // lightAvg += (lightMax - lightAvg) * 0.6f; + + if (lightAvg > 1.0f) { + natLightR /= lightAvg; + natLightG /= lightAvg; + natLightB /= lightAvg; + } + + natLightR *= 1.0f + overExpose; + natLightG *= 1.0f + overExpose; + natLightB *= 1.0f + overExpose; + overExpose *= 255.0f; + + float targetFogginess = (float)(gClimateCurrentRainLevel) / 8.0f; + targetFogginess += (night * night) * 0.15f; + + if (gClimateCurrentTemperature < 10) { + targetFogginess += ((float)(10 - gClimateCurrentTemperature)) * 0.01f; + } + + fogginess -= (fogginess - targetFogginess) * 0.00001f; + + wetness *= 0.999995f; + wetness += fogginess * 0.001f; + wetness = min(wetness, 1.0f); + + float boost = 1.0f; + float envFog = fogginess; + float lightFog = envFog; + + float addLightNatR = 0.0f; + float addLightNatG = 0.0f; + float addLightNatB = 0.0f; + + float reduceColourNat = 1.0f; + float reduceColourLit = 1.0f; + + reduceColourLit *= night / (float)pow(max(1.01f, 0.4f + lightAvg), 2.0); + + float targetLightPollution = reduceColourLit * max(0.0f, 0.0f + 0.000001f * (float)lightfx_get_light_polution()); + lightPolution -= (lightPolution - targetLightPollution) * 0.001f; + + // lightPollution /= 1.0f + fogginess * 1.0f; + + natLightR /= 1.0f + lightPolution * 20.0f; + natLightG /= 1.0f + lightPolution * 20.0f; + natLightB /= 1.0f + lightPolution * 20.0f; + natLightR += elecMultR * 0.6f * lightPolution; + natLightG += elecMultG * 0.6f * lightPolution; + natLightB += elecMultB * 0.6f * lightPolution; + natLightR /= 1.0f + lightPolution; + natLightG /= 1.0f + lightPolution; + natLightB /= 1.0f + lightPolution; + + reduceColourLit += (float)(gClimateCurrentRainLevel) / 2.0f; + + reduceColourNat /= 1.0f + fogginess; + reduceColourLit /= 1.0f + fogginess; + + lightFog *= reduceColourLit; + + reduceColourNat *= 1.0f - envFog; + reduceColourLit *= 1.0f - lightFog; + + float fogR = 35.5f * natLightR * 1.3f; + float fogG = 45.0f * natLightG * 1.3f; + float fogB = 50.0f * natLightB * 1.3f; + lightFog *= 10.0f; + + float wetnessBoost = 1.0f;//1.0f + wetness * wetness * 0.1f; + + if (night >= 0 && gClimateLightningFlash != 1) { + *r = lerp(*r, soft_light(*r, 8), night); + *g = lerp(*g, soft_light(*g, 8), night); + *b = lerp(*b, soft_light(*b, 128), night); + + // if (i == 32) + // boost = 300000.0f; + if ((i % 32) == 0) + boost = 1.01f * wetnessBoost; + else if ((i % 16) < 7) + boost = 1.001f * wetnessBoost; + if (i > 230 && i < 232) + boost = ((float)(*b)) / 64.0f; + + if (false) { + // This experiment shifts the colour of pixels as-if they are wet, but it is not a pretty solution at all + if ((i % 16)) { + float iVal = ((float)((i + 12) % 16)) / 16.0f; + float eff = (wetness * ((float)pow(iVal, 1.5) * 0.85f)); + reduceColourNat *= 1.0f - eff; + addLightNatR += fogR * eff * 3.95f; + addLightNatG += fogR * eff * 3.95f; + addLightNatB += fogR * eff * 3.95f; + } + } + + addLightNatR *= 1.0f - envFog; + addLightNatG *= 1.0f - envFog; + addLightNatB *= 1.0f - envFog; + + *r = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(*r) * reduceColourNat * natLightR + envFog * fogR + addLightNatR)))); + *g = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(*g) * reduceColourNat * natLightG + envFog * fogG + addLightNatG)))); + *b = (uint8)(min(255.0f, max(0.0f, (-overExpose + (float)(*b) * reduceColourNat * natLightB + envFog * fogB + addLightNatB)))); + gPalette_light[i].r = (uint8)(min(0xFF, ((float)(*r) * reduceColourLit * boost + lightFog) * elecMultR)); + gPalette_light[i].g = (uint8)(min(0xFF, ((float)(*g) * reduceColourLit * boost + lightFog) * elecMultG)); + gPalette_light[i].b = (uint8)(min(0xFF, ((float)(*b) * reduceColourLit * boost + lightFog) * elecMultB)); + } +} + +static uint8 soft_light(uint8 a, uint8 b) +{ + float fa = a / 255.0f; + float fb = b / 255.0f; + float fr; + if (fb < 0.5f) { + fr = (2 * fa * fb) + ((fa * fa) * (1 - (2 * fb))); + } else { + fr = (2 * fa * (1 - fb)) + (sqrtf(fa) * ((2 * fb) - 1)); + } + return (uint8)(clamp(0.0f, fr, 1.0f) * 255.0f); +} + +static uint8 lerp(uint8 a, uint8 b, float t) +{ + if (t <= 0) return a; + if (t >= 1) return b; + + int range = b - a; + int amount = (int)(range * t); + return (uint8)(a + amount); +} + +static float flerp(float a, float b, float t) +{ + if (t <= 0) return a; + if (t >= 1) return b; + + float range = b - a; + float amount = range * t; + return a + amount; +} diff --git a/src/drawing/lightfx.h b/src/drawing/lightfx.h index c39cb44f8d..3e5adf46ab 100644 --- a/src/drawing/lightfx.h +++ b/src/drawing/lightfx.h @@ -63,5 +63,7 @@ extern void lightfx_add_lights_magic_vehicles(); extern uint32 lightfx_get_light_polution(); +void lightfx_apply_palette_filter(uint8 i, uint8 *r, uint8 *g, uint8 *b); + #endif #endif \ No newline at end of file diff --git a/src/platform/shared.c b/src/platform/shared.c index f71e61ecc5..fea87b087e 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -18,6 +18,7 @@ #include "../audio/mixer.h" #include "../config.h" #include "../drawing/drawing.h" +#include "../drawing/lightfx.h" #include "../game.h" #include "../input.h" #include "../interface/console.h" @@ -254,18 +255,25 @@ void platform_update_palette(const uint8* colours, int start_index, int num_colo colours += start_index * 4; for (int i = start_index; i < num_colours + start_index; i++) { - gPalette[i].r = colours[2]; - gPalette[i].g = colours[1]; - gPalette[i].b = colours[0]; - gPalette[i].a = 0; + uint8 r = colours[2]; + uint8 g = colours[1]; + uint8 b = colours[0]; +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + lightfx_apply_palette_filter(i, &r, &g, &b); +#else float night = gDayNightCycle; if (night >= 0 && gClimateLightningFlash == 0) { - gPalette[i].r = lerp(gPalette[i].r, soft_light(gPalette[i].r, 8), night); - gPalette[i].g = lerp(gPalette[i].g, soft_light(gPalette[i].g, 8), night); - gPalette[i].b = lerp(gPalette[i].b, soft_light(gPalette[i].b, 128), night); + r = lerp(r, soft_light(r, 8), night); + g = lerp(g, soft_light(g, 8), night); + b = lerp(b, soft_light(b, 128), night); } +#endif + gPalette[i].r = r; + gPalette[i].g = g; + gPalette[i].b = b; + gPalette[i].a = 0; colours += 4; if (gBufferTextureFormat != NULL) { gPaletteHWMapped[i] = SDL_MapRGB(gBufferTextureFormat, gPalette[i].r, gPalette[i].g, gPalette[i].b); From 6d45c5ac5ee777b113bf92fafd9fc1884c2dd366 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 17 Oct 2016 22:51:18 +0100 Subject: [PATCH 37/44] Fix footpath lights --- src/paint/map_element/path.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/paint/map_element/path.c b/src/paint/map_element/path.c index 65b94806eb..4ea2652067 100644 --- a/src/paint/map_element/path.c +++ b/src/paint/map_element/path.c @@ -763,6 +763,26 @@ void path_paint(uint8 direction, uint16 height, rct_map_element * map_element) } else { loc_6A3B57(map_element, height, footpathEntry, word_F3F038, imageFlags, sceneryImageFlags); } + +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + if (footpath_element_has_path_scenery(map_element) && !(map_element->flags & MAP_ELEMENT_FLAG_BROKEN)) { + rct_scenery_entry *sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(map_element)); + if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_LAMP) { + if (!(map_element->properties.path.edges & (1 << 0))) { + lightfx_add_3d_light_magic_from_drawing_tile(-16, 0, height + 23, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + if (!(map_element->properties.path.edges & (1 << 1))) { + lightfx_add_3d_light_magic_from_drawing_tile(0, 16, height + 23, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + if (!(map_element->properties.path.edges & (1 << 2))) { + lightfx_add_3d_light_magic_from_drawing_tile(16, 0, height + 23, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + if (!(map_element->properties.path.edges & (1 << 3))) { + lightfx_add_3d_light_magic_from_drawing_tile(0, -16, height + 23, LIGHTFX_LIGHT_TYPE_LANTERN_3); + } + } + } +#endif } void loc_6A37C9(rct_map_element * mapElement, int height, rct_footpath_entry * footpathEntry, bool hasFences, uint32 imageFlags, uint32 sceneryImageFlags) From 1ddb95874a315877b6f30419d33203cc69ecb346 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 17 Oct 2016 22:54:25 +0100 Subject: [PATCH 38/44] Add lightfx_get_palette --- src/drawing/lightfx.c | 5 +++++ src/drawing/lightfx.h | 1 + 2 files changed, 6 insertions(+) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 811b23748c..38c080f4dc 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -591,6 +591,11 @@ void* lightfx_get_front_buffer() return _light_rendered_buffer_front; } +const SDL_Color * lightfx_get_palette() +{ + return gPalette_light; +} + void lightfx_add_3d_light(uint32 lightID, uint16 lightIDqualifier, sint16 x, sint16 y, uint16 z, uint8 lightType) { if (LightListCurrentCountBack == 15999) { diff --git a/src/drawing/lightfx.h b/src/drawing/lightfx.h index 3e5adf46ab..f6d2e49c47 100644 --- a/src/drawing/lightfx.h +++ b/src/drawing/lightfx.h @@ -54,6 +54,7 @@ extern void lightfx_render_lights_to_frontbuffer(); extern void lightfx_update_viewport_settings(); extern void* lightfx_get_front_buffer(); +const SDL_Color * lightfx_get_palette(); extern void lightfx_add_3d_light(uint32 lightID, uint16 lightIDqualifier, sint16 x, sint16 y, uint16 z, uint8 lightType); From 8da6654fc6c2cd7f529913338e95e43e0a234563 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 17 Oct 2016 22:56:08 +0100 Subject: [PATCH 39/44] Mix lights into hw texture --- src/drawing/engines/SoftwareDrawingEngine.cpp | 125 +++++++++++++----- 1 file changed, 90 insertions(+), 35 deletions(-) diff --git a/src/drawing/engines/SoftwareDrawingEngine.cpp b/src/drawing/engines/SoftwareDrawingEngine.cpp index be3a2114ab..ac1e8991a4 100644 --- a/src/drawing/engines/SoftwareDrawingEngine.cpp +++ b/src/drawing/engines/SoftwareDrawingEngine.cpp @@ -30,6 +30,7 @@ extern "C" #include "../../interface/window.h" #include "../../intro.h" #include "../drawing.h" + #include "../lightfx.h" } class SoftwareDrawingEngine; @@ -194,6 +195,7 @@ private: SDL_Texture * _screenTexture = nullptr; SDL_PixelFormat * _screenTextureFormat = nullptr; uint32 _paletteHWMapped[256] = { 0 }; + uint32 _lightPaletteHWMapped[256] = { 0 }; // Steam overlay checking uint32 _pixelBeforeOverlay = 0; @@ -268,7 +270,7 @@ public: } _screenTexture = SDL_CreateTexture(_sdlRenderer, pixelFormat, SDL_TEXTUREACCESS_STREAMING, width, height); - + uint32 format; SDL_QueryTexture(_screenTexture, &format, 0, 0, 0); _screenTextureFormat = SDL_AllocFormat(format); @@ -306,9 +308,11 @@ public: { if (_screenTextureFormat != nullptr) { + const SDL_Color * lightPalette = lightfx_get_palette(); for (int i = 0; i < 256; i++) { _paletteHWMapped[i] = SDL_MapRGB(_screenTextureFormat, palette[i].r, palette[i].g, palette[i].b); + _lightPaletteHWMapped[i] = SDL_MapRGBA(_screenTextureFormat, lightPalette[i].r, lightPalette[i].g, lightPalette[i].b, lightPalette[i].a); } } } @@ -522,6 +526,8 @@ private: dpi->pitch = _pitch - width; ConfigureDirtyGrid(); + + lightfx_update_buffers(dpi); } void ConfigureDirtyGrid() @@ -679,54 +685,55 @@ private: } } + uint8 LerpByte(uint8 a, uint8 b, uint8 t) + { + uint8 delta = b - a; + uint8 result = a + ((delta * t) >> 8); + return result; + } + void DisplayViaTexture() { + lightfx_update_viewport_settings(); + lightfx_swap_buffers(); + lightfx_prepare_light_list(); + lightfx_render_lights_to_frontbuffer(); + + uint8 * lightBits = (uint8 *)lightfx_get_front_buffer(); + void * pixels; int pitch; if (SDL_LockTexture(_screenTexture, nullptr, &pixels, &pitch) == 0) { - uint8 * src = _bits; - int padding = pitch - (_width * 4); - if ((uint32)pitch == _width * 4) { - uint32 * dst = (uint32 *)pixels; - for (int i = _width * _height; i > 0; i--) - { - *dst++ = _paletteHWMapped[*src++]; - } - } - else + for (uint32 y = 0; y < _height; y++) { - if ((uint32)pitch == (_width * 2) + padding) + uintptr_t dstOffset = (uintptr_t)(y * pitch); + uint32 * dst = (uint32 *)((uintptr_t)pixels + dstOffset); + for (uint32 x = 0; x < _width; x++) { - uint16 * dst = (uint16 *)pixels; - for (sint32 y = (sint32)_height; y > 0; y--) { - for (sint32 x = (sint32)_width; x > 0; x--) { - const uint8 lower = *(uint8 *)(&_paletteHWMapped[*src++]); - const uint8 upper = *(uint8 *)(&_paletteHWMapped[*src++]); - *dst++ = (lower << 8) | upper; - } - dst = (uint16*)(((uint8 *)dst) + padding); - } - } - else - { - if ((uint32)pitch == _width + padding) + uint8 * src = &_bits[y * _width + x]; + uint32 darkColour = _paletteHWMapped[*src]; + uint32 lightColour = _lightPaletteHWMapped[*src]; + uint8 lightIntensity = lightBits[y * _width + x]; + + uint32 colour = 0; + if (lightIntensity == 0) { - uint8 * dst = (uint8 *)pixels; - for (sint32 y = (sint32)_height; y > 0; y--) { - for (sint32 x = (sint32)_width; x > 0; x--) - { - *dst++ = *(uint8 *)(&_paletteHWMapped[*src++]); - } - dst += padding; - } + colour = darkColour; } + else + { + colour |= LerpByte((darkColour >> 0) & 0xFF, (lightColour >> 0) & 0xFF, lightIntensity); + colour |= LerpByte((darkColour >> 8) & 0xFF, (lightColour >> 8) & 0xFF, lightIntensity) << 8; + colour |= LerpByte((darkColour >> 16) & 0xFF, (lightColour >> 16) & 0xFF, lightIntensity) << 16; + colour |= LerpByte((darkColour >> 24) & 0xFF, (lightColour >> 24) & 0xFF, lightIntensity) << 24; + } + *dst++ = colour; } } SDL_UnlockTexture(_screenTexture); } - - SDL_RenderCopy(_sdlRenderer, _screenTexture, NULL, NULL); + SDL_RenderCopy(_sdlRenderer, _screenTexture, nullptr, nullptr); if (gSteamOverlayActive && gConfigGeneral.steam_overlay_pause) { @@ -741,6 +748,54 @@ private: } } + void CopyBitsToTexture(SDL_Texture * texture, uint8 * src, sint32 width, sint32 height, uint32 * palette) + { + void * pixels; + int pitch; + if (SDL_LockTexture(texture, nullptr, &pixels, &pitch) == 0) + { + sint32 padding = pitch - (width * 4); + if (pitch == width * 4) + { + uint32 * dst = (uint32 *)pixels; + for (sint32 i = width * height; i > 0; i--) + { + *dst++ = palette[*src++]; + } + } + else + { + if (pitch == (width * 2) + padding) + { + uint16 * dst = (uint16 *)pixels; + for (sint32 y = height; y > 0; y--) + { + for (sint32 x = width; x > 0; x--) + { + const uint8 lower = *(uint8 *)(&palette[*src++]); + const uint8 upper = *(uint8 *)(&palette[*src++]); + *dst++ = (lower << 8) | upper; + } + dst = (uint16*)(((uint8 *)dst) + padding); + } + } + else if (pitch == width + padding) + { + uint8 * dst = (uint8 *)pixels; + for (sint32 y = height; y > 0; y--) + { + for (sint32 x = width; x > 0; x--) + { + *dst++ = *(uint8 *)(&palette[*src++]); + } + dst += padding; + } + } + } + SDL_UnlockTexture(texture); + } + } + void ReadCentrePixel(uint32 * pixel) { SDL_Rect centrePixelRegion = { (sint32)(_width / 2), (sint32)(_height / 2), 1, 1 }; From d773d14473c80d86ba93f907a888c3414939242b Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 17 Oct 2016 23:28:02 +0100 Subject: [PATCH 40/44] Add light instead of lerp --- src/drawing/engines/SoftwareDrawingEngine.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/drawing/engines/SoftwareDrawingEngine.cpp b/src/drawing/engines/SoftwareDrawingEngine.cpp index ac1e8991a4..b73106a1d3 100644 --- a/src/drawing/engines/SoftwareDrawingEngine.cpp +++ b/src/drawing/engines/SoftwareDrawingEngine.cpp @@ -685,10 +685,12 @@ private: } } - uint8 LerpByte(uint8 a, uint8 b, uint8 t) + uint8 MixLight(uint32 a, uint32 b, uint32 intensity) { - uint8 delta = b - a; - uint8 result = a + ((delta * t) >> 8); + intensity = intensity * 6; + uint32 bMul = (b * intensity) >> 8; + uint32 ab = a + bMul; + uint8 result = Math::Min(255, ab); return result; } @@ -723,10 +725,10 @@ private: } else { - colour |= LerpByte((darkColour >> 0) & 0xFF, (lightColour >> 0) & 0xFF, lightIntensity); - colour |= LerpByte((darkColour >> 8) & 0xFF, (lightColour >> 8) & 0xFF, lightIntensity) << 8; - colour |= LerpByte((darkColour >> 16) & 0xFF, (lightColour >> 16) & 0xFF, lightIntensity) << 16; - colour |= LerpByte((darkColour >> 24) & 0xFF, (lightColour >> 24) & 0xFF, lightIntensity) << 24; + colour |= MixLight((darkColour >> 0) & 0xFF, (lightColour >> 0) & 0xFF, lightIntensity); + colour |= MixLight((darkColour >> 8) & 0xFF, (lightColour >> 8) & 0xFF, lightIntensity) << 8; + colour |= MixLight((darkColour >> 16) & 0xFF, (lightColour >> 16) & 0xFF, lightIntensity) << 16; + colour |= MixLight((darkColour >> 24) & 0xFF, (lightColour >> 24) & 0xFF, lightIntensity) << 24; } *dst++ = colour; } From a9908b80c9407153e7566813186a7edb9ba53aed Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 18 Oct 2016 13:35:33 +0100 Subject: [PATCH 41/44] Add debug assistance --- openrct2.vcxproj.user | 1 + src/scenario.c | 1 + 2 files changed, 2 insertions(+) diff --git a/openrct2.vcxproj.user b/openrct2.vcxproj.user index b782b153c4..2883f6c8ea 100644 --- a/openrct2.vcxproj.user +++ b/openrct2.vcxproj.user @@ -20,6 +20,7 @@ $(TargetDir) WindowsLocalDebugger + C:\Users\Ted\Documents\OpenRCT2\save\lights-2.sv6 $(TargetDir) diff --git a/src/scenario.c b/src/scenario.c index 7e50a5c9b9..51c27c3751 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -509,6 +509,7 @@ static void scenario_update_daynight_cycle() } else { gDayNightCycle = 0.0f; } + gDayNightCycle = 1; } // Only update palette if day / night cycle has changed From ca47770825317f50520510911eeca61d8d512e76 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 24 Oct 2016 13:05:44 +0100 Subject: [PATCH 42/44] Move rendering to lightfx.c and protect all areas with guard --- src/common.h | 4 +- src/drawing/engines/SoftwareDrawingEngine.cpp | 61 ++++--------------- src/drawing/lightfx.c | 58 ++++++++++++++++++ src/drawing/lightfx.h | 18 ++++-- 4 files changed, 86 insertions(+), 55 deletions(-) diff --git a/src/common.h b/src/common.h index 6909d5d92f..904e97d1a0 100644 --- a/src/common.h +++ b/src/common.h @@ -144,8 +144,6 @@ assert_struct_size(registers, 7 * 4); #define UNUSED(x) ((void)(x)) -#define STOUT_EXPANDED_RENDERING -#define STOUT_EXPANDED_RENDERING_MTT -#define STOUT_EXPANDED_RENDERING_LIGHT +// #define STOUT_EXPANDED_RENDERING_LIGHT #endif diff --git a/src/drawing/engines/SoftwareDrawingEngine.cpp b/src/drawing/engines/SoftwareDrawingEngine.cpp index b73106a1d3..158de95221 100644 --- a/src/drawing/engines/SoftwareDrawingEngine.cpp +++ b/src/drawing/engines/SoftwareDrawingEngine.cpp @@ -195,7 +195,9 @@ private: SDL_Texture * _screenTexture = nullptr; SDL_PixelFormat * _screenTextureFormat = nullptr; uint32 _paletteHWMapped[256] = { 0 }; +#ifdef STOUT_EXPANDED_RENDERING_LIGHT uint32 _lightPaletteHWMapped[256] = { 0 }; +#endif // Steam overlay checking uint32 _pixelBeforeOverlay = 0; @@ -308,11 +310,15 @@ public: { if (_screenTextureFormat != nullptr) { +#ifdef STOUT_EXPANDED_RENDERING_LIGHT const SDL_Color * lightPalette = lightfx_get_palette(); +#endif for (int i = 0; i < 256; i++) { _paletteHWMapped[i] = SDL_MapRGB(_screenTextureFormat, palette[i].r, palette[i].g, palette[i].b); +#ifdef STOUT_EXPANDED_RENDERING_LIGHT _lightPaletteHWMapped[i] = SDL_MapRGBA(_screenTextureFormat, lightPalette[i].r, lightPalette[i].g, lightPalette[i].b, lightPalette[i].a); +#endif } } } @@ -527,7 +533,9 @@ private: ConfigureDirtyGrid(); +#ifdef STOUT_EXPANDED_RENDERING_LIGHT lightfx_update_buffers(dpi); +#endif } void ConfigureDirtyGrid() @@ -685,56 +693,13 @@ private: } } - uint8 MixLight(uint32 a, uint32 b, uint32 intensity) - { - intensity = intensity * 6; - uint32 bMul = (b * intensity) >> 8; - uint32 ab = a + bMul; - uint8 result = Math::Min(255, ab); - return result; - } - void DisplayViaTexture() { - lightfx_update_viewport_settings(); - lightfx_swap_buffers(); - lightfx_prepare_light_list(); - lightfx_render_lights_to_frontbuffer(); - - uint8 * lightBits = (uint8 *)lightfx_get_front_buffer(); - - void * pixels; - int pitch; - if (SDL_LockTexture(_screenTexture, nullptr, &pixels, &pitch) == 0) - { - for (uint32 y = 0; y < _height; y++) - { - uintptr_t dstOffset = (uintptr_t)(y * pitch); - uint32 * dst = (uint32 *)((uintptr_t)pixels + dstOffset); - for (uint32 x = 0; x < _width; x++) - { - uint8 * src = &_bits[y * _width + x]; - uint32 darkColour = _paletteHWMapped[*src]; - uint32 lightColour = _lightPaletteHWMapped[*src]; - uint8 lightIntensity = lightBits[y * _width + x]; - - uint32 colour = 0; - if (lightIntensity == 0) - { - colour = darkColour; - } - else - { - colour |= MixLight((darkColour >> 0) & 0xFF, (lightColour >> 0) & 0xFF, lightIntensity); - colour |= MixLight((darkColour >> 8) & 0xFF, (lightColour >> 8) & 0xFF, lightIntensity) << 8; - colour |= MixLight((darkColour >> 16) & 0xFF, (lightColour >> 16) & 0xFF, lightIntensity) << 16; - colour |= MixLight((darkColour >> 24) & 0xFF, (lightColour >> 24) & 0xFF, lightIntensity) << 24; - } - *dst++ = colour; - } - } - SDL_UnlockTexture(_screenTexture); - } +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + lightfx_render_to_texture(_screenTexture, _bits, _width, _height, _paletteHWMapped, _lightPaletteHWMapped); +#else + CopyBitsToTexture(_screenTexture, _bits, (sint32)_width, (sint32)_height, _paletteHWMapped); +#endif SDL_RenderCopy(_sdlRenderer, _screenTexture, nullptr, nullptr); if (gSteamOverlayActive && gConfigGeneral.steam_overlay_pause) diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 38c080f4dc..9c99489705 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -14,6 +14,10 @@ *****************************************************************************/ #pragma endregion +#ifdef STOUT_EXPANDED_RENDERING_LIGHT + +#include "../common.h" +#include #include "../game.h" #include "../rct2.h" #include "../interface/viewport.h" @@ -969,3 +973,57 @@ static float flerp(float a, float b, float t) float amount = range * t; return a + amount; } + +static uint8 mix_light(uint32 a, uint32 b, uint32 intensity) +{ + intensity = intensity * 6; + uint32 bMul = (b * intensity) >> 8; + uint32 ab = a + bMul; + uint8 result = min(255, ab); + return result; +} + +void lightfx_render_to_texture( + SDL_Texture * texture, + uint8 * bits, + uint32 width, + uint32 height, + uint32 * palette, + uint32 * lightPalette) +{ + lightfx_update_viewport_settings(); + lightfx_swap_buffers(); + lightfx_prepare_light_list(); + lightfx_render_lights_to_frontbuffer(); + + uint8 * lightBits = (uint8 *)lightfx_get_front_buffer(); + + void * pixels; + int pitch; + if (SDL_LockTexture(texture, NULL, &pixels, &pitch) == 0) { + for (uint32 y = 0; y < height; y++) { + uintptr_t dstOffset = (uintptr_t)(y * pitch); + uint32 * dst = (uint32 *)((uintptr_t)pixels + dstOffset); + for (uint32 x = 0; x < width; x++) { + uint8 * src = &bits[y * width + x]; + uint32 darkColour = palette[*src]; + uint32 lightColour = lightPalette[*src]; + uint8 lightIntensity = lightBits[y * width + x]; + + uint32 colour = 0; + if (lightIntensity == 0) { + colour = darkColour; + } else { + colour |= mix_light((darkColour >> 0) & 0xFF, (lightColour >> 0) & 0xFF, lightIntensity); + colour |= mix_light((darkColour >> 8) & 0xFF, (lightColour >> 8) & 0xFF, lightIntensity) << 8; + colour |= mix_light((darkColour >> 16) & 0xFF, (lightColour >> 16) & 0xFF, lightIntensity) << 16; + colour |= mix_light((darkColour >> 24) & 0xFF, (lightColour >> 24) & 0xFF, lightIntensity) << 24; + } + *dst++ = colour; + } + } + SDL_UnlockTexture(texture); + } +} + +#endif // STOUT_EXPANDED_RENDERING_LIGHT diff --git a/src/drawing/lightfx.h b/src/drawing/lightfx.h index f6d2e49c47..a6c15e90f4 100644 --- a/src/drawing/lightfx.h +++ b/src/drawing/lightfx.h @@ -17,11 +17,13 @@ #ifndef _LIGHTFX_H #define _LIGHTFX_H -#include "drawing.h" -#include "../common.h" - #ifdef STOUT_EXPANDED_RENDERING_LIGHT +#include "../common.h" +#include "drawing.h" + +typedef struct SDL_Texture; + enum LIGHTFX_LIGHT_TYPE { LIGHTFX_LIGHT_TYPE_NONE = 0, LIGHTFX_LIGHT_TYPE_RESERVED_01 = 1, @@ -65,6 +67,14 @@ extern void lightfx_add_lights_magic_vehicles(); extern uint32 lightfx_get_light_polution(); void lightfx_apply_palette_filter(uint8 i, uint8 *r, uint8 *g, uint8 *b); +void lightfx_render_to_texture( + struct SDL_Texture * texture, + uint8 * bits, + uint32 width, + uint32 height, + uint32 * palette, + uint32 * lightPalette); + +#endif // STOUT_EXPANDED_RENDERING_LIGHT #endif -#endif \ No newline at end of file From ebe4ca4df453a00da2fde25baefbfa14a14770b4 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 24 Oct 2016 13:06:44 +0100 Subject: [PATCH 43/44] Rename lightfx guard --- src/common.h | 2 -- src/drawing/engines/SoftwareDrawingEngine.cpp | 10 +++++----- src/drawing/lightfx.c | 4 ++-- src/drawing/lightfx.h | 4 ++-- src/paint/map_element/entrance.c | 4 ++-- src/paint/map_element/path.c | 2 +- src/paint/sprite/peep.c | 2 +- src/platform/shared.c | 2 +- src/rct2.c | 4 ++-- 9 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/common.h b/src/common.h index 904e97d1a0..7de291a628 100644 --- a/src/common.h +++ b/src/common.h @@ -144,6 +144,4 @@ assert_struct_size(registers, 7 * 4); #define UNUSED(x) ((void)(x)) -// #define STOUT_EXPANDED_RENDERING_LIGHT - #endif diff --git a/src/drawing/engines/SoftwareDrawingEngine.cpp b/src/drawing/engines/SoftwareDrawingEngine.cpp index 158de95221..a595557497 100644 --- a/src/drawing/engines/SoftwareDrawingEngine.cpp +++ b/src/drawing/engines/SoftwareDrawingEngine.cpp @@ -195,7 +195,7 @@ private: SDL_Texture * _screenTexture = nullptr; SDL_PixelFormat * _screenTextureFormat = nullptr; uint32 _paletteHWMapped[256] = { 0 }; -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ uint32 _lightPaletteHWMapped[256] = { 0 }; #endif @@ -310,13 +310,13 @@ public: { if (_screenTextureFormat != nullptr) { -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ const SDL_Color * lightPalette = lightfx_get_palette(); #endif for (int i = 0; i < 256; i++) { _paletteHWMapped[i] = SDL_MapRGB(_screenTextureFormat, palette[i].r, palette[i].g, palette[i].b); -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ _lightPaletteHWMapped[i] = SDL_MapRGBA(_screenTextureFormat, lightPalette[i].r, lightPalette[i].g, lightPalette[i].b, lightPalette[i].a); #endif } @@ -533,7 +533,7 @@ private: ConfigureDirtyGrid(); -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ lightfx_update_buffers(dpi); #endif } @@ -695,7 +695,7 @@ private: void DisplayViaTexture() { -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ lightfx_render_to_texture(_screenTexture, _bits, _width, _height, _paletteHWMapped, _lightPaletteHWMapped); #else CopyBitsToTexture(_screenTexture, _bits, (sint32)_width, (sint32)_height, _paletteHWMapped); diff --git a/src/drawing/lightfx.c b/src/drawing/lightfx.c index 9c99489705..53840b3915 100644 --- a/src/drawing/lightfx.c +++ b/src/drawing/lightfx.c @@ -14,7 +14,7 @@ *****************************************************************************/ #pragma endregion -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ #include "../common.h" #include @@ -1026,4 +1026,4 @@ void lightfx_render_to_texture( } } -#endif // STOUT_EXPANDED_RENDERING_LIGHT +#endif // __ENABLE_LIGHTFX__ diff --git a/src/drawing/lightfx.h b/src/drawing/lightfx.h index a6c15e90f4..7706815718 100644 --- a/src/drawing/lightfx.h +++ b/src/drawing/lightfx.h @@ -17,7 +17,7 @@ #ifndef _LIGHTFX_H #define _LIGHTFX_H -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ #include "../common.h" #include "drawing.h" @@ -75,6 +75,6 @@ void lightfx_render_to_texture( uint32 * palette, uint32 * lightPalette); -#endif // STOUT_EXPANDED_RENDERING_LIGHT +#endif // __ENABLE_LIGHTFX__ #endif diff --git a/src/paint/map_element/entrance.c b/src/paint/map_element/entrance.c index 5535e2ab19..2f989d85a8 100644 --- a/src/paint/map_element/entrance.c +++ b/src/paint/map_element/entrance.c @@ -42,7 +42,7 @@ static void ride_entrance_exit_paint(uint8 direction, int height, rct_map_elemen return; } -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ if (!is_exit) { lightfx_add_3d_light_magic_from_drawing_tile(0, 0, height + 45, LIGHTFX_LIGHT_TYPE_LANTERN_3); @@ -189,7 +189,7 @@ static void park_entrance_paint(uint8 direction, int height, rct_map_element* ma if (gTrackDesignSaveMode) return; -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ lightfx_add_3d_light_magic_from_drawing_tile(0, 0, 155, LIGHTFX_LIGHT_TYPE_LANTERN_3); diff --git a/src/paint/map_element/path.c b/src/paint/map_element/path.c index 4ea2652067..801486cd26 100644 --- a/src/paint/map_element/path.c +++ b/src/paint/map_element/path.c @@ -764,7 +764,7 @@ void path_paint(uint8 direction, uint16 height, rct_map_element * map_element) loc_6A3B57(map_element, height, footpathEntry, word_F3F038, imageFlags, sceneryImageFlags); } -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ if (footpath_element_has_path_scenery(map_element) && !(map_element->flags & MAP_ELEMENT_FLAG_BROKEN)) { rct_scenery_entry *sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(map_element)); if (sceneryEntry->path_bit.flags & PATH_BIT_FLAG_LAMP) { diff --git a/src/paint/sprite/peep.c b/src/paint/sprite/peep.c index 5431045e1c..1b1a926dc6 100644 --- a/src/paint/sprite/peep.c +++ b/src/paint/sprite/peep.c @@ -27,7 +27,7 @@ */ void peep_paint(rct_peep * peep, int imageDirection) { -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ if (peep->type == PEEP_TYPE_STAFF){ sint16 peep_x, peep_y, peep_z; diff --git a/src/platform/shared.c b/src/platform/shared.c index fea87b087e..2e6d427310 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -259,7 +259,7 @@ void platform_update_palette(const uint8* colours, int start_index, int num_colo uint8 g = colours[1]; uint8 b = colours[0]; -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ lightfx_apply_palette_filter(i, &r, &g, &b); #else float night = gDayNightCycle; diff --git a/src/rct2.c b/src/rct2.c index 4f5bd145b8..70fcd61e74 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -51,7 +51,7 @@ #include "world/scenery.h" #include "world/sprite.h" -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ #include "drawing/lightfx.h" @@ -199,7 +199,7 @@ bool rct2_init() window_staff_list_init_vars(); -#ifdef STOUT_EXPANDED_RENDERING_LIGHT +#ifdef __ENABLE_LIGHTFX__ lightfx_init(); From 07f56823922fe72e700ec0aaa7ee825453eb6a47 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 24 Oct 2016 18:52:42 +0100 Subject: [PATCH 44/44] Remove lightfx debug stuff --- openrct2.vcxproj.user | 1 - src/scenario.c | 1 - 2 files changed, 2 deletions(-) diff --git a/openrct2.vcxproj.user b/openrct2.vcxproj.user index 2883f6c8ea..b782b153c4 100644 --- a/openrct2.vcxproj.user +++ b/openrct2.vcxproj.user @@ -20,7 +20,6 @@ $(TargetDir) WindowsLocalDebugger - C:\Users\Ted\Documents\OpenRCT2\save\lights-2.sv6 $(TargetDir) diff --git a/src/scenario.c b/src/scenario.c index 51c27c3751..7e50a5c9b9 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -509,7 +509,6 @@ static void scenario_update_daynight_cycle() } else { gDayNightCycle = 0.0f; } - gDayNightCycle = 1; } // Only update palette if day / night cycle has changed