From c937bdbfea8f522d14d7a41f24372bddf5bdafcc Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 18 Jul 2021 00:03:57 +0300 Subject: render -> renderer (original name) --- src/render/2dEffect.h | 99 -- src/render/Antennas.cpp | 129 -- src/render/Antennas.h | 25 - src/render/Clouds.cpp | 473 ------ src/render/Clouds.h | 23 - src/render/Console.cpp | 96 -- src/render/Console.h | 27 - src/render/Coronas.cpp | 959 ----------- src/render/Coronas.h | 105 -- src/render/Credits.cpp | 820 ---------- src/render/Credits.h | 15 - src/render/CutsceneShadow.cpp | 269 ---- src/render/CutsceneShadow.h | 52 - src/render/Draw.cpp | 113 -- src/render/Draw.h | 70 - src/render/Fluff.cpp | 1364 ---------------- src/render/Fluff.h | 205 --- src/render/Font.cpp | 1938 ---------------------- src/render/Font.h | 217 --- src/render/Glass.cpp | 1027 ------------ src/render/Glass.h | 59 - src/render/Hud.cpp | 2083 ------------------------ src/render/Hud.h | 139 -- src/render/Instance.cpp | 9 - src/render/Instance.h | 14 - src/render/Lines.cpp | 74 - src/render/Lines.h | 7 - src/render/MBlur.cpp | 801 ---------- src/render/MBlur.h | 39 - src/render/Occlusion.cpp | 530 ------ src/render/Occlusion.h | 62 - src/render/Particle.cpp | 2534 ----------------------------- src/render/Particle.h | 108 -- src/render/ParticleMgr.cpp | 255 --- src/render/ParticleMgr.h | 138 -- src/render/ParticleType.h | 92 -- src/render/PlayerSkin.cpp | 164 -- src/render/PlayerSkin.h | 15 - src/render/PointLights.cpp | 330 ---- src/render/PointLights.h | 50 - src/render/RenderBuffer.cpp | 52 - src/render/RenderBuffer.h | 25 - src/render/Renderer.cpp | 1675 ------------------- src/render/Renderer.h | 105 -- src/render/Rubbish.cpp | 423 ----- src/render/Rubbish.h | 57 - src/render/ShadowCamera.cpp | 549 ------- src/render/ShadowCamera.h | 54 - src/render/Shadows.cpp | 2520 ----------------------------- src/render/Shadows.h | 210 --- src/render/Skidmarks.cpp | 259 --- src/render/Skidmarks.h | 41 - src/render/SpecialFX.cpp | 1493 ----------------- src/render/SpecialFX.h | 249 --- src/render/Sprite.cpp | 599 ------- src/render/Sprite.h | 31 - src/render/Sprite2d.cpp | 434 ----- src/render/Sprite2d.h | 54 - src/render/TexList.cpp | 41 - src/render/TexList.h | 14 - src/render/Timecycle.cpp | 526 ------ src/render/Timecycle.h | 201 --- src/render/VarConsole.cpp | 786 --------- src/render/VarConsole.h | 92 -- src/render/WaterCannon.cpp | 317 ---- src/render/WaterCannon.h | 39 - src/render/WaterCreatures.cpp | 275 ---- src/render/WaterCreatures.h | 49 - src/render/WaterLevel.cpp | 3377 --------------------------------------- src/render/WaterLevel.h | 184 --- src/render/Weather.cpp | 662 -------- src/render/Weather.h | 73 - src/render/WindModifiers.cpp | 52 - src/render/WindModifiers.h | 11 - src/renderer/2dEffect.h | 99 ++ src/renderer/Antennas.cpp | 129 ++ src/renderer/Antennas.h | 25 + src/renderer/Clouds.cpp | 473 ++++++ src/renderer/Clouds.h | 23 + src/renderer/Console.cpp | 96 ++ src/renderer/Console.h | 27 + src/renderer/Coronas.cpp | 959 +++++++++++ src/renderer/Coronas.h | 105 ++ src/renderer/Credits.cpp | 820 ++++++++++ src/renderer/Credits.h | 15 + src/renderer/CutsceneShadow.cpp | 269 ++++ src/renderer/CutsceneShadow.h | 52 + src/renderer/Draw.cpp | 113 ++ src/renderer/Draw.h | 70 + src/renderer/Fluff.cpp | 1364 ++++++++++++++++ src/renderer/Fluff.h | 205 +++ src/renderer/Font.cpp | 1938 ++++++++++++++++++++++ src/renderer/Font.h | 217 +++ src/renderer/Glass.cpp | 1027 ++++++++++++ src/renderer/Glass.h | 59 + src/renderer/Hud.cpp | 2083 ++++++++++++++++++++++++ src/renderer/Hud.h | 139 ++ src/renderer/Instance.cpp | 9 + src/renderer/Instance.h | 14 + src/renderer/Lines.cpp | 74 + src/renderer/Lines.h | 7 + src/renderer/MBlur.cpp | 801 ++++++++++ src/renderer/MBlur.h | 39 + src/renderer/Occlusion.cpp | 530 ++++++ src/renderer/Occlusion.h | 62 + src/renderer/Particle.cpp | 2534 +++++++++++++++++++++++++++++ src/renderer/Particle.h | 108 ++ src/renderer/ParticleMgr.cpp | 255 +++ src/renderer/ParticleMgr.h | 138 ++ src/renderer/ParticleType.h | 92 ++ src/renderer/PlayerSkin.cpp | 164 ++ src/renderer/PlayerSkin.h | 15 + src/renderer/PointLights.cpp | 330 ++++ src/renderer/PointLights.h | 50 + src/renderer/RenderBuffer.cpp | 52 + src/renderer/RenderBuffer.h | 25 + src/renderer/Renderer.cpp | 1675 +++++++++++++++++++ src/renderer/Renderer.h | 105 ++ src/renderer/Rubbish.cpp | 423 +++++ src/renderer/Rubbish.h | 57 + src/renderer/ShadowCamera.cpp | 549 +++++++ src/renderer/ShadowCamera.h | 54 + src/renderer/Shadows.cpp | 2520 +++++++++++++++++++++++++++++ src/renderer/Shadows.h | 210 +++ src/renderer/Skidmarks.cpp | 259 +++ src/renderer/Skidmarks.h | 41 + src/renderer/SpecialFX.cpp | 1493 +++++++++++++++++ src/renderer/SpecialFX.h | 249 +++ src/renderer/Sprite.cpp | 599 +++++++ src/renderer/Sprite.h | 31 + src/renderer/Sprite2d.cpp | 434 +++++ src/renderer/Sprite2d.h | 54 + src/renderer/TexList.cpp | 41 + src/renderer/TexList.h | 14 + src/renderer/Timecycle.cpp | 526 ++++++ src/renderer/Timecycle.h | 201 +++ src/renderer/VarConsole.cpp | 786 +++++++++ src/renderer/VarConsole.h | 92 ++ src/renderer/WaterCannon.cpp | 317 ++++ src/renderer/WaterCannon.h | 39 + src/renderer/WaterCreatures.cpp | 275 ++++ src/renderer/WaterCreatures.h | 49 + src/renderer/WaterLevel.cpp | 3377 +++++++++++++++++++++++++++++++++++++++ src/renderer/WaterLevel.h | 184 +++ src/renderer/Weather.cpp | 662 ++++++++ src/renderer/Weather.h | 73 + src/renderer/WindModifiers.cpp | 52 + src/renderer/WindModifiers.h | 11 + 148 files changed, 31058 insertions(+), 31058 deletions(-) delete mode 100644 src/render/2dEffect.h delete mode 100644 src/render/Antennas.cpp delete mode 100644 src/render/Antennas.h delete mode 100644 src/render/Clouds.cpp delete mode 100644 src/render/Clouds.h delete mode 100644 src/render/Console.cpp delete mode 100644 src/render/Console.h delete mode 100644 src/render/Coronas.cpp delete mode 100644 src/render/Coronas.h delete mode 100644 src/render/Credits.cpp delete mode 100644 src/render/Credits.h delete mode 100644 src/render/CutsceneShadow.cpp delete mode 100644 src/render/CutsceneShadow.h delete mode 100644 src/render/Draw.cpp delete mode 100644 src/render/Draw.h delete mode 100644 src/render/Fluff.cpp delete mode 100644 src/render/Fluff.h delete mode 100644 src/render/Font.cpp delete mode 100644 src/render/Font.h delete mode 100644 src/render/Glass.cpp delete mode 100644 src/render/Glass.h delete mode 100644 src/render/Hud.cpp delete mode 100644 src/render/Hud.h delete mode 100644 src/render/Instance.cpp delete mode 100644 src/render/Instance.h delete mode 100644 src/render/Lines.cpp delete mode 100644 src/render/Lines.h delete mode 100644 src/render/MBlur.cpp delete mode 100644 src/render/MBlur.h delete mode 100644 src/render/Occlusion.cpp delete mode 100644 src/render/Occlusion.h delete mode 100644 src/render/Particle.cpp delete mode 100644 src/render/Particle.h delete mode 100644 src/render/ParticleMgr.cpp delete mode 100644 src/render/ParticleMgr.h delete mode 100644 src/render/ParticleType.h delete mode 100644 src/render/PlayerSkin.cpp delete mode 100644 src/render/PlayerSkin.h delete mode 100644 src/render/PointLights.cpp delete mode 100644 src/render/PointLights.h delete mode 100644 src/render/RenderBuffer.cpp delete mode 100644 src/render/RenderBuffer.h delete mode 100644 src/render/Renderer.cpp delete mode 100644 src/render/Renderer.h delete mode 100644 src/render/Rubbish.cpp delete mode 100644 src/render/Rubbish.h delete mode 100644 src/render/ShadowCamera.cpp delete mode 100644 src/render/ShadowCamera.h delete mode 100644 src/render/Shadows.cpp delete mode 100644 src/render/Shadows.h delete mode 100644 src/render/Skidmarks.cpp delete mode 100644 src/render/Skidmarks.h delete mode 100644 src/render/SpecialFX.cpp delete mode 100644 src/render/SpecialFX.h delete mode 100644 src/render/Sprite.cpp delete mode 100644 src/render/Sprite.h delete mode 100644 src/render/Sprite2d.cpp delete mode 100644 src/render/Sprite2d.h delete mode 100644 src/render/TexList.cpp delete mode 100644 src/render/TexList.h delete mode 100644 src/render/Timecycle.cpp delete mode 100644 src/render/Timecycle.h delete mode 100644 src/render/VarConsole.cpp delete mode 100644 src/render/VarConsole.h delete mode 100644 src/render/WaterCannon.cpp delete mode 100644 src/render/WaterCannon.h delete mode 100644 src/render/WaterCreatures.cpp delete mode 100644 src/render/WaterCreatures.h delete mode 100644 src/render/WaterLevel.cpp delete mode 100644 src/render/WaterLevel.h delete mode 100644 src/render/Weather.cpp delete mode 100644 src/render/Weather.h delete mode 100644 src/render/WindModifiers.cpp delete mode 100644 src/render/WindModifiers.h create mode 100644 src/renderer/2dEffect.h create mode 100644 src/renderer/Antennas.cpp create mode 100644 src/renderer/Antennas.h create mode 100644 src/renderer/Clouds.cpp create mode 100644 src/renderer/Clouds.h create mode 100644 src/renderer/Console.cpp create mode 100644 src/renderer/Console.h create mode 100644 src/renderer/Coronas.cpp create mode 100644 src/renderer/Coronas.h create mode 100644 src/renderer/Credits.cpp create mode 100644 src/renderer/Credits.h create mode 100644 src/renderer/CutsceneShadow.cpp create mode 100644 src/renderer/CutsceneShadow.h create mode 100644 src/renderer/Draw.cpp create mode 100644 src/renderer/Draw.h create mode 100644 src/renderer/Fluff.cpp create mode 100644 src/renderer/Fluff.h create mode 100644 src/renderer/Font.cpp create mode 100644 src/renderer/Font.h create mode 100644 src/renderer/Glass.cpp create mode 100644 src/renderer/Glass.h create mode 100644 src/renderer/Hud.cpp create mode 100644 src/renderer/Hud.h create mode 100644 src/renderer/Instance.cpp create mode 100644 src/renderer/Instance.h create mode 100644 src/renderer/Lines.cpp create mode 100644 src/renderer/Lines.h create mode 100644 src/renderer/MBlur.cpp create mode 100644 src/renderer/MBlur.h create mode 100644 src/renderer/Occlusion.cpp create mode 100644 src/renderer/Occlusion.h create mode 100644 src/renderer/Particle.cpp create mode 100644 src/renderer/Particle.h create mode 100644 src/renderer/ParticleMgr.cpp create mode 100644 src/renderer/ParticleMgr.h create mode 100644 src/renderer/ParticleType.h create mode 100644 src/renderer/PlayerSkin.cpp create mode 100644 src/renderer/PlayerSkin.h create mode 100644 src/renderer/PointLights.cpp create mode 100644 src/renderer/PointLights.h create mode 100644 src/renderer/RenderBuffer.cpp create mode 100644 src/renderer/RenderBuffer.h create mode 100644 src/renderer/Renderer.cpp create mode 100644 src/renderer/Renderer.h create mode 100644 src/renderer/Rubbish.cpp create mode 100644 src/renderer/Rubbish.h create mode 100644 src/renderer/ShadowCamera.cpp create mode 100644 src/renderer/ShadowCamera.h create mode 100644 src/renderer/Shadows.cpp create mode 100644 src/renderer/Shadows.h create mode 100644 src/renderer/Skidmarks.cpp create mode 100644 src/renderer/Skidmarks.h create mode 100644 src/renderer/SpecialFX.cpp create mode 100644 src/renderer/SpecialFX.h create mode 100644 src/renderer/Sprite.cpp create mode 100644 src/renderer/Sprite.h create mode 100644 src/renderer/Sprite2d.cpp create mode 100644 src/renderer/Sprite2d.h create mode 100644 src/renderer/TexList.cpp create mode 100644 src/renderer/TexList.h create mode 100644 src/renderer/Timecycle.cpp create mode 100644 src/renderer/Timecycle.h create mode 100644 src/renderer/VarConsole.cpp create mode 100644 src/renderer/VarConsole.h create mode 100644 src/renderer/WaterCannon.cpp create mode 100644 src/renderer/WaterCannon.h create mode 100644 src/renderer/WaterCreatures.cpp create mode 100644 src/renderer/WaterCreatures.h create mode 100644 src/renderer/WaterLevel.cpp create mode 100644 src/renderer/WaterLevel.h create mode 100644 src/renderer/Weather.cpp create mode 100644 src/renderer/Weather.h create mode 100644 src/renderer/WindModifiers.cpp create mode 100644 src/renderer/WindModifiers.h (limited to 'src') diff --git a/src/render/2dEffect.h b/src/render/2dEffect.h deleted file mode 100644 index 8ad2b946..00000000 --- a/src/render/2dEffect.h +++ /dev/null @@ -1,99 +0,0 @@ -#pragma once - -enum { - EFFECT_LIGHT, - EFFECT_PARTICLE, - EFFECT_ATTRACTOR, - EFFECT_PED_ATTRACTOR, - EFFECT_SUNGLARE -}; - -enum { - LIGHT_ON, - LIGHT_ON_NIGHT, - LIGHT_FLICKER, - LIGHT_FLICKER_NIGHT, - LIGHT_FLASH1, - LIGHT_FLASH1_NIGHT, - LIGHT_FLASH2, - LIGHT_FLASH2_NIGHT, - LIGHT_FLASH3, - LIGHT_FLASH3_NIGHT, - LIGHT_RANDOM_FLICKER, - LIGHT_RANDOM_FLICKER_NIGHT, - LIGHT_SPECIAL, - LIGHT_BRIDGE_FLASH1, - LIGHT_BRIDGE_FLASH2, -}; - -enum { - ATTRACTORTYPE_ICECREAM, - ATTRACTORTYPE_STARE -}; - -enum { - LIGHTFLAG_LOSCHECK = 1, - // same order as CPointLights flags, must start at 2 - LIGHTFLAG_FOG_NORMAL = 2, // can have light and fog - LIGHTFLAG_FOG_ALWAYS = 4, // fog only - LIGHTFLAG_HIDE_OBJECT = 8, // hide the object instead of rendering light (???) - LIGHTFLAG_LONG_DIST = 16, - LIGHTFLAG_FOG = (LIGHTFLAG_FOG_NORMAL|LIGHTFLAG_FOG_ALWAYS) -}; - -class C2dEffect -{ -public: - struct Light { - float dist; - float range; // of pointlight - float size; - float shadowSize; - uint8 lightType; // LIGHT_ - uint8 roadReflection; - uint8 flareType; - uint8 shadowIntensity; - uint8 flags; // LIGHTFLAG_ - RwTexture *corona; - RwTexture *shadow; - }; - struct Particle { - int particleType; - CVector dir; - float scale; - }; - struct Attractor { - CVector dir; - int8 type; - uint8 probability; - }; - struct PedAttractor { - CVector queueDir; - CVector useDir; - int8 type; - }; - - CVector pos; - CRGBA col; - uint8 type; - union { - Light light; - Particle particle; - Attractor attractor; - PedAttractor pedattr; - }; - - C2dEffect(void) {} - void Shutdown(void){ - if(type == EFFECT_LIGHT){ - if(light.corona) - RwTextureDestroy(light.corona); - light.corona = nil; - if(light.shadow) - RwTextureDestroy(light.shadow); - light.shadow = nil; - } - } -}; - -VALIDATE_SIZE(C2dEffect, 0x34); diff --git a/src/render/Antennas.cpp b/src/render/Antennas.cpp deleted file mode 100644 index 5e30aca2..00000000 --- a/src/render/Antennas.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "Antennas.h" - -CAntenna CAntennas::aAntennas[NUMANTENNAS]; - -void -CAntennas::Init(void) -{ - int i; - for(i = 0; i < NUMANTENNAS; i++){ - aAntennas[i].active = false; - aAntennas[i].updatedLastFrame = false; - } -} - -// Free antennas that aren't used anymore -void -CAntennas::Update(void) -{ - int i; - - for(i = 0; i < NUMANTENNAS; i++){ - if(aAntennas[i].active && !aAntennas[i].updatedLastFrame) - aAntennas[i].active = false; - aAntennas[i].updatedLastFrame = false; - } -} - -// Add a new one or update an old one -void -CAntennas::RegisterOne(uint32 id, CVector dir, CVector position, float length) -{ - int i, j; - - for(i = 0; i < NUMANTENNAS; i++) - if(aAntennas[i].active && aAntennas[i].id == id) - break; - - if(i >= NUMANTENNAS){ - // not found, register new one - - // find empty slot - for(i = 0; i < NUMANTENNAS; i++) - if(!aAntennas[i].active) - break; - - // there is space - if(i < NUMANTENNAS){ - aAntennas[i].active = true; - aAntennas[i].updatedLastFrame = true; - aAntennas[i].id = id; - aAntennas[i].segmentLength = length/6.0f; - for(j = 0; j < 6; j++){ - aAntennas[i].pos[j] = position + dir*j*aAntennas[i].segmentLength; - aAntennas[i].speed[j] = CVector(0.0f, 0.0f, 0.0f); - } - } - }else{ - // found, update - aAntennas[i].Update(dir, position); - aAntennas[i].updatedLastFrame = true; - } -} - -static RwIm3DVertex vertexbufferA[2]; - -void -CAntennas::Render(void) -{ - int i, j; - - PUSH_RENDERGROUP("CAntennas::Render"); - for(i = 0; i < NUMANTENNAS; i++){ - if(!aAntennas[i].active) - continue; - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - - for(j = 0; j < 5; j++){ - RwIm3DVertexSetRGBA(&vertexbufferA[0], 200, 200, 200, 100); - RwIm3DVertexSetPos(&vertexbufferA[0], - aAntennas[i].pos[j].x, - aAntennas[i].pos[j].y, - aAntennas[i].pos[j].z); - RwIm3DVertexSetRGBA(&vertexbufferA[1], 200, 200, 200, 100); - RwIm3DVertexSetPos(&vertexbufferA[1], - aAntennas[i].pos[j+1].x, - aAntennas[i].pos[j+1].y, - aAntennas[i].pos[j+1].z); - - // LittleTest(); - if(RwIm3DTransform(vertexbufferA, 2, nil, 0)){ - RwIm3DRenderLine(0, 1); - RwIm3DEnd(); - } - } - } - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - - POP_RENDERGROUP(); -} - -void -CAntenna::Update(CVector dir, CVector basepos) -{ - int i; - - pos[0] = basepos; - pos[1] = basepos + dir*segmentLength; - - for(i = 2; i < 6; i++){ - CVector basedir = pos[i-1] - pos[i-2]; - CVector newdir = pos[i] - pos[i-1] + // drag along - dir*0.1f + // also drag up a bit for stiffness - speed[i]; // and keep moving - newdir.Normalise(); - newdir *= segmentLength; - CVector newpos = pos[i-1] + (basedir + newdir)/2.0f; - speed[i] = (newpos - pos[i])*0.9f; - pos[i] = newpos; - } -} diff --git a/src/render/Antennas.h b/src/render/Antennas.h deleted file mode 100644 index 47cb1dad..00000000 --- a/src/render/Antennas.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -class CAntenna -{ -public: - bool active; - bool updatedLastFrame; - uint32 id; - float segmentLength; - CVector pos[6]; - CVector speed[6]; - - void Update(CVector dir, CVector pos); -}; - -class CAntennas -{ - // no need to use game's array - static CAntenna aAntennas[NUMANTENNAS]; -public: - static void Init(void); - static void Update(void); - static void RegisterOne(uint32 id, CVector dir, CVector position, float length); - static void Render(void); -}; diff --git a/src/render/Clouds.cpp b/src/render/Clouds.cpp deleted file mode 100644 index 9cd32c5f..00000000 --- a/src/render/Clouds.cpp +++ /dev/null @@ -1,473 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "Sprite.h" -#include "Sprite2d.h" -#include "General.h" -#include "Game.h" -#include "Coronas.h" -#include "Camera.h" -#include "TxdStore.h" -#include "Weather.h" -#include "Clock.h" -#include "Timer.h" -#include "Timecycle.h" -#include "Renderer.h" -#include "Clouds.h" - -#define SMALLSTRIPHEIGHT 4.0f -#define HORIZSTRIPHEIGHT 48.0f - -RwTexture *gpCloudTex[5]; - -float CClouds::CloudRotation; -uint32 CClouds::IndividualRotation; - -float CClouds::ms_cameraRoll; -float CClouds::ms_horizonZ; -float CClouds::ms_HorizonTilt; -CRGBA CClouds::ms_colourTop; -CRGBA CClouds::ms_colourBottom; -CRGBA CClouds::ms_colourBkGrd; - -void -CClouds::Init(void) -{ - CTxdStore::PushCurrentTxd(); - CTxdStore::SetCurrentTxd(CTxdStore::FindTxdSlot("particle")); - gpCloudTex[0] = RwTextureRead("cloud1", nil); - gpCloudTex[1] = RwTextureRead("cloud2", nil); - gpCloudTex[2] = RwTextureRead("cloud3", nil); - gpCloudTex[3] = RwTextureRead("cloudhilit", nil); - gpCloudTex[4] = RwTextureRead("cloudmasked", nil); - CTxdStore::PopCurrentTxd(); - CloudRotation = 0.0f; -} - -void -CClouds::Shutdown(void) -{ - RwTextureDestroy(gpCloudTex[0]); - gpCloudTex[0] = nil; - RwTextureDestroy(gpCloudTex[1]); - gpCloudTex[1] = nil; - RwTextureDestroy(gpCloudTex[2]); - gpCloudTex[2] = nil; - RwTextureDestroy(gpCloudTex[3]); - gpCloudTex[3] = nil; - RwTextureDestroy(gpCloudTex[4]); - gpCloudTex[4] = nil; -} - -void -CClouds::Update(void) -{ - float s = Sin(TheCamera.Orientation - 0.85f); -#ifdef FIX_BUGS - CloudRotation += CWeather::Wind*s*0.001f*CTimer::GetTimeStepFix(); - IndividualRotation += (CWeather::Wind*CTimer::GetTimeStep()*0.5f + 0.3f*CTimer::GetTimeStepFix()) * 60.0f; -#else - CloudRotation += CWeather::Wind*s*0.001f; - IndividualRotation += (CWeather::Wind*CTimer::GetTimeStep()*0.5f + 0.3f) * 60.0f; -#endif -} - -float StarCoorsX[9] = { 0.0f, 0.05f, 0.13f, 0.4f, 0.7f, 0.6f, 0.27f, 0.55f, 0.75f }; -float StarCoorsY[9] = { 0.0f, 0.45f, 0.9f, 1.0f, 0.85f, 0.52f, 0.48f, 0.35f, 0.2f }; -float StarSizes[9] = { 1.0f, 1.4f, 0.9f, 1.0f, 0.6f, 1.5f, 1.3f, 1.0f, 0.8f }; - -float LowCloudsX[12] = { 1.0f, 0.7f, 0.0f, -0.7f, -1.0f, -0.7f, 0.0f, 0.7f, 0.8f, -0.8f, 0.4f, -0.4f }; -float LowCloudsY[12] = { 0.0f, -0.7f, -1.0f, -0.7f, 0.0f, 0.7f, 1.0f, 0.7f, 0.4f, 0.4f, -0.8f, -0.8f }; -float LowCloudsZ[12] = { 0.0f, 1.0f, 0.5f, 0.0f, 1.0f, 0.3f, 0.9f, 0.4f, 1.3f, 1.4f, 1.2f, 1.7f }; - -float CoorsOffsetX[37] = { - 0.0f, 60.0f, 72.0f, 48.0f, 21.0f, 12.0f, - 9.0f, -3.0f, -8.4f, -18.0f, -15.0f, -36.0f, - -40.0f, -48.0f, -60.0f, -24.0f, 100.0f, 100.0f, - 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, - 100.0f, 100.0f, -30.0f, -20.0f, 10.0f, 30.0f, - 0.0f, -100.0f, -100.0f, -100.0f, -100.0f, -100.0f, -100.0f -}; -float CoorsOffsetY[37] = { - 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, - 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, - 100.0f, 100.0f, 100.0f, 100.0f, -30.0f, 10.0f, - -25.0f, -5.0f, 28.0f, -10.0f, 10.0f, 0.0f, - 15.0f, 40.0f, -100.0f, -100.0f, -100.0f, -100.0f, - -100.0f, -40.0f, -20.0f, 0.0f, 10.0f, 30.0f, 35.0f -}; -float CoorsOffsetZ[37] = { - 2.0f, 1.0f, 0.0f, 0.3f, 0.7f, 1.4f, - 1.7f, 0.24f, 0.7f, 1.3f, 1.6f, 1.0f, - 1.2f, 0.3f, 0.7f, 1.4f, 0.0f, 0.1f, - 0.5f, 0.4f, 0.55f, 0.75f, 1.0f, 1.4f, - 1.7f, 2.0f, 2.0f, 2.3f, 1.9f, 2.4f, - 2.0f, 2.0f, 1.5f, 1.2f, 1.7f, 1.5f, 2.1f -}; - -uint8 BowRed[6] = { 30, 30, 30, 10, 0, 15 }; -uint8 BowGreen[6] = { 0, 15, 30, 30, 0, 0 }; -uint8 BowBlue[6] = { 0, 0, 0, 10, 30, 30 }; - -void -CClouds::Render(void) -{ - int i; - float szx, szy; - RwV3d screenpos; - RwV3d worldpos; - - if(!CGame::CanSeeOutSideFromCurrArea()) - return; - - PUSH_RENDERGROUP("CClouds::Render"); - - CCoronas::SunBlockedByClouds = false; - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - CSprite::InitSpriteBuffer(); - - float minute = CClock::GetHours()*60 + CClock::GetMinutes() + CClock::GetSeconds()/60.0f; - RwV3d campos = TheCamera.GetPosition(); - - // Moon - float moonfadeout = Abs(minute - 180.0f); // fully visible at 3AM - if((int)moonfadeout < 180){ // fade in/out 3 hours - float coverage = Max(CWeather::Foggyness, CWeather::CloudCoverage); - int brightness = (1.0f - coverage) * (180 - (int)moonfadeout); - RwV3d pos = { 0.0f, -100.0f, 15.0f }; - RwV3dAdd(&worldpos, &campos, &pos); - if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)){ - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[2])); - szx *= CCoronas::MoonSize*2.0f + 4.0f; - szy *= CCoronas::MoonSize*2.0f + 4.0f; - CSprite::RenderOneXLUSprite(screenpos.x, screenpos.y, screenpos.z, - szx, szy, brightness, brightness, brightness, 255, 1.0f/screenpos.z, 255); - } - } - - // The R* logo - int starintens = 0; - if(CClock::GetHours() < 22 && CClock::GetHours() > 5) - starintens = 0; - else if(CClock::GetHours() > 22 || CClock::GetHours() < 5) - starintens = 255; - else if(CClock::GetHours() == 22) - starintens = 255 * CClock::GetMinutes()/60.0f; - else if(CClock::GetHours() == 5) - starintens = 255 * (60 - CClock::GetMinutes())/60.0f; - if(starintens != 0){ - float coverage = Max(CWeather::Foggyness, CWeather::CloudCoverage); - int brightness = (1.0f - coverage) * starintens; - - // R - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[0])); - for(i = 0; i < 11; i++){ - RwV3d pos = { 100.0f, 0.0f, 10.0f }; - if(i >= 9) pos.x = -pos.x; - RwV3dAdd(&worldpos, &campos, &pos); - worldpos.y -= 90.0f*StarCoorsX[i%9]; - worldpos.z += 80.0f*StarCoorsY[i%9]; - if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)){ - float sz = 0.8f*StarSizes[i%9]; - CSprite::RenderBufferedOneXLUSprite(screenpos.x, screenpos.y, screenpos.z, - szx*sz, szy*sz, brightness, brightness, brightness, 255, 1.0f/screenpos.z, 255); - } - } - CSprite::FlushSpriteBuffer(); - - // * - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[0])); - RwV3d pos = { 100.0f, 0.0f, 10.0f }; - RwV3dAdd(&worldpos, &campos, &pos); - worldpos.y -= 90.0f; - if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)){ - brightness *= (CGeneral::GetRandomNumber()&127) / 640.0f + 0.5f; - CSprite::RenderOneXLUSprite(screenpos.x, screenpos.y, screenpos.z, - szx*5.0f, szy*5.0f, brightness, brightness, brightness, 255, 1.0f/screenpos.z, 255); - } - } - - // Low clouds - float lowcloudintensity = 1.0f - Max(Max(CWeather::Foggyness, CWeather::CloudCoverage), CWeather::ExtraSunnyness); - int r = CTimeCycle::GetLowCloudsRed() * lowcloudintensity; - int g = CTimeCycle::GetLowCloudsGreen() * lowcloudintensity; - int b = CTimeCycle::GetLowCloudsBlue() * lowcloudintensity; - for(int cloudtype = 0; cloudtype < 3; cloudtype++){ - for(i = cloudtype; i < 12; i += 3){ - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCloudTex[cloudtype])); - RwV3d pos = { 800.0f*LowCloudsX[i], 800.0f*LowCloudsY[i], 60.0f*LowCloudsZ[i] }; - worldpos.x = campos.x + pos.x; - worldpos.y = campos.y + pos.y; - worldpos.z = 40.0f + pos.z; - if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)) - CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension(screenpos.x, screenpos.y, screenpos.z, - szx*320.0f, szy*40.0f, r, g, b, 255, 1.0f/screenpos.z, ms_cameraRoll, 255); - } - CSprite::FlushSpriteBuffer(); - } - - // Fluffy clouds - float rot_sin = Sin(CloudRotation); - float rot_cos = Cos(CloudRotation); - int fluffyalpha = 160 * (1.0f - Max(CWeather::Foggyness, CWeather::ExtraSunnyness)); - if(fluffyalpha != 0){ - static bool bCloudOnScreen[37]; - float sundist, hilight; - - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCloudTex[4])); - for(i = 0; i < 37; i++){ - RwV3d pos = { 2.0f*CoorsOffsetX[i], 2.0f*CoorsOffsetY[i], 40.0f*CoorsOffsetZ[i] + 40.0f }; - worldpos.x = pos.x*rot_cos + pos.y*rot_sin + campos.x; - worldpos.y = pos.x*rot_sin - pos.y*rot_cos + campos.y; - worldpos.z = pos.z; - - if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)){ - sundist = Sqrt(sq(screenpos.x-CCoronas::SunScreenX) + sq(screenpos.y-CCoronas::SunScreenY)); - int tr = CTimeCycle::GetFluffyCloudsTopRed(); - int tg = CTimeCycle::GetFluffyCloudsTopGreen(); - int tb = CTimeCycle::GetFluffyCloudsTopBlue(); - int br = CTimeCycle::GetFluffyCloudsBottomRed(); - int bg = CTimeCycle::GetFluffyCloudsBottomGreen(); - int bb = CTimeCycle::GetFluffyCloudsBottomBlue(); - int distLimit = (3*SCREEN_WIDTH)/4; - if(sundist < distLimit){ - hilight = (1.0f - Max(CWeather::Foggyness, CWeather::CloudCoverage)) * (1.0f - sundist/(float)distLimit); - tr = tr*(1.0f-hilight) + 255*hilight; - tg = tg*(1.0f-hilight) + 190*hilight; - tb = tb*(1.0f-hilight) + 190*hilight; - br = br*(1.0f-hilight) + 255*hilight; - bg = bg*(1.0f-hilight) + 190*hilight; - bb = bb*(1.0f-hilight) + 190*hilight; - if(sundist < SCREEN_WIDTH/10) - CCoronas::SunBlockedByClouds = true; - }else - hilight = 0.0f; - CSprite::RenderBufferedOneXLUSprite_Rotate_2Colours(screenpos.x, screenpos.y, screenpos.z, - szx*55.0f, szy*55.0f, - tr, tg, tb, br, bg, bb, 0.0f, -1.0f, - 1.0f/screenpos.z, - (uint16)IndividualRotation/65336.0f * 6.28f + ms_cameraRoll, - fluffyalpha); - bCloudOnScreen[i] = true; - }else - bCloudOnScreen[i] = false; - } - CSprite::FlushSpriteBuffer(); - - // Highlights - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCloudTex[3])); - - for(i = 0; i < 37; i++){ - RwV3d pos = { 2.0f*CoorsOffsetX[i], 2.0f*CoorsOffsetY[i], 40.0f*CoorsOffsetZ[i] + 40.0f }; - worldpos.x = pos.x*rot_cos + pos.y*rot_sin + campos.x; - worldpos.y = pos.x*rot_sin + pos.y*rot_cos + campos.y; - worldpos.z = pos.z; - if(bCloudOnScreen[i] && CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)){ - if(sundist < SCREEN_WIDTH/3){ - CSprite::RenderBufferedOneXLUSprite_Rotate_Aspect(screenpos.x, screenpos.y, screenpos.z, - szx*30.0f, szy*30.0f, - 200*hilight, 0, 0, 255, 1.0f/screenpos.z, - 1.7f - CGeneral::GetATanOfXY(screenpos.x-CCoronas::SunScreenX, screenpos.y-CCoronas::SunScreenY) + CClouds::ms_cameraRoll, 255); - } - } - } - CSprite::FlushSpriteBuffer(); - } - - // Rainbow - if(CWeather::Rainbow != 0.0f){ - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[0])); - for(i = 0; i < 6; i++){ - RwV3d pos = { i*1.5f, 100.0f, 5.0f }; - RwV3dAdd(&worldpos, &campos, &pos); - if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)) - CSprite::RenderBufferedOneXLUSprite(screenpos.x, screenpos.y, screenpos.z, - 2.0f*szx, 50.0*szy, - BowRed[i]*CWeather::Rainbow, BowGreen[i]*CWeather::Rainbow, BowBlue[i]*CWeather::Rainbow, - 255, 1.0f/screenpos.z, 255); - - } - CSprite::FlushSpriteBuffer(); - } - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - - POP_RENDERGROUP(); -} - -bool -UseDarkBackground(void) -{ - return TheCamera.GetForward().z < -0.9f || gbShowCollisionPolys; -} - -void -CClouds::RenderBackground(int16 topred, int16 topgreen, int16 topblue, - int16 botred, int16 botgreen, int16 botblue, int16 alpha) -{ - PUSH_RENDERGROUP("CClouds::RenderBackground"); - - CVector right = CrossProduct(TheCamera.GetUp(), TheCamera.GetForward()); - right.Normalise(); - float c = right.Magnitude2D(); - if(c > 1.0f) - c = 1.0f; - ms_cameraRoll = Acos(c); - if(right.z < 0.0f) - ms_cameraRoll = -ms_cameraRoll; - - ms_HorizonTilt = SCREEN_WIDTH/2.0f * Tan(ms_cameraRoll); - - if(UseDarkBackground()){ - ms_colourTop.r = 50; - ms_colourTop.g = 50; - ms_colourTop.b = 50; - ms_colourTop.a = 255; - if(gbShowCollisionPolys){ - if(CTimer::GetFrameCounter() & 1){ - ms_colourTop.r = 0; - ms_colourTop.g = 0; - ms_colourTop.b = 0; - }else{ - ms_colourTop.r = 255; - ms_colourTop.g = 255; - ms_colourTop.b = 255; - } - } - ms_colourBottom = ms_colourTop; - CRect r(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); - CSprite2d::DrawRect(r, ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); - }else{ - ms_horizonZ = CSprite::CalcHorizonCoors(); - - int fogr = (topred + 2 * botred) / 3; - int fogg = (topgreen + 2 * botgreen) / 3; - int fogb = (topblue + 2 * botblue) / 3; - - // Draw top/bottom gradient - float gradheight = SCREEN_HEIGHT/2.0f; - - ms_colourTop.r = topred; - ms_colourTop.g = topgreen; - ms_colourTop.b = topblue; - ms_colourTop.a = alpha; - ms_colourBottom.r = botred; - ms_colourBottom.g = botgreen; - ms_colourBottom.b = botblue; - ms_colourBottom.a = alpha; - - float botright = ms_horizonZ - ms_HorizonTilt; - float botleft = ms_horizonZ + ms_HorizonTilt; - float topright = botright - gradheight; - float topleft = botleft - gradheight; - - CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, - ms_colourTop, ms_colourTop, ms_colourBottom, ms_colourBottom); - - // draw the small stripe (whatever it's supposed to be) - ms_colourTop.r = fogr; - ms_colourTop.g = fogg; - ms_colourTop.b = fogb; - ms_colourTop.a = alpha; - topright = ms_horizonZ - ms_HorizonTilt; - topleft = ms_horizonZ + ms_HorizonTilt; - botright = topright + SMALLSTRIPHEIGHT; - botleft = topleft + SMALLSTRIPHEIGHT; - CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, - ms_colourTop, ms_colourTop, ms_colourTop, ms_colourTop); - - // Only top - if(ms_horizonZ + ms_HorizonTilt - gradheight > 0.0f || - ms_horizonZ - ms_HorizonTilt - gradheight > 0.0f){ - ms_colourTop.r = topred; - ms_colourTop.g = topgreen; - ms_colourTop.b = topblue; - ms_colourTop.a = alpha; - - if(ms_horizonZ - Abs(ms_HorizonTilt) - gradheight > SCREEN_HEIGHT){ - // only top is visible - topleft = 0.0f; - topright = 0.0f; - botleft = SCREEN_HEIGHT; - botright = SCREEN_HEIGHT; - }else{ - botright = ms_horizonZ - ms_HorizonTilt - gradheight; - botleft = ms_horizonZ + ms_HorizonTilt - gradheight; - topright = Min(ms_horizonZ - ms_HorizonTilt - 2*SCREEN_HEIGHT, 0.0f); - topleft = Min(ms_horizonZ + ms_HorizonTilt - 2*SCREEN_HEIGHT, 0.0f); - } - - CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, - ms_colourTop, ms_colourTop, ms_colourTop, ms_colourTop); - } - - // Set both to fog colour for RenderHorizon - ms_colourTop.r = fogr; - ms_colourTop.g = fogg; - ms_colourTop.b = fogb; - ms_colourBottom.r = fogr; - ms_colourBottom.g = fogg; - ms_colourBottom.b = fogb; - } - - POP_RENDERGROUP(); -} - -void -CClouds::RenderHorizon(void) -{ - if(UseDarkBackground()) - return; - - PUSH_RENDERGROUP("CClouds::RenderHorizon"); - - ms_colourBottom.a = 230; - ms_colourTop.a = 80; - - float topright = ms_horizonZ - ms_HorizonTilt; - float topleft = ms_horizonZ + ms_HorizonTilt; - float botright = topright + SMALLSTRIPHEIGHT; - float botleft = topleft + SMALLSTRIPHEIGHT; - - CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, - ms_colourTop, ms_colourTop, ms_colourBottom, ms_colourBottom); - - - ms_colourBkGrd.r = 128.0f*CTimeCycle::GetAmbientRed(); - ms_colourBkGrd.g = 128.0f*CTimeCycle::GetAmbientGreen(); - ms_colourBkGrd.b = 128.0f*CTimeCycle::GetAmbientBlue(); - ms_colourBkGrd.a = 255; - - float horzstrip = SCREEN_STRETCH_Y(HORIZSTRIPHEIGHT); - topright = botright; - topleft = botleft; - botright = topright + horzstrip; - botleft = topleft + horzstrip; - - CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, - ms_colourBottom, ms_colourBottom, ms_colourBkGrd, ms_colourBkGrd); - - - topright = botright; - topleft = botleft; - botright = Max(topright, SCREEN_HEIGHT); - botleft = Max(topleft, SCREEN_HEIGHT); - - CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, - ms_colourBkGrd, ms_colourBkGrd, ms_colourBkGrd, ms_colourBkGrd); - - POP_RENDERGROUP(); -} diff --git a/src/render/Clouds.h b/src/render/Clouds.h deleted file mode 100644 index ef33030b..00000000 --- a/src/render/Clouds.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -class CClouds -{ -public: - static float CloudRotation; - static uint32 IndividualRotation; - - static float ms_cameraRoll; - static float ms_horizonZ; - static float ms_HorizonTilt; - static CRGBA ms_colourTop; - static CRGBA ms_colourBottom; - static CRGBA ms_colourBkGrd; - - static void Init(void); - static void Shutdown(void); - static void Update(void); - static void Render(void); - static void RenderBackground(int16 topred, int16 topgreen, int16 topblue, - int16 botred, int16 botgreen, int16 botblue, int16 alpha); - static void RenderHorizon(void); -}; diff --git a/src/render/Console.cpp b/src/render/Console.cpp deleted file mode 100644 index 244bfb17..00000000 --- a/src/render/Console.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include "common.h" -#include - -#include "Console.h" -#include "Font.h" -#include "Timer.h" - -#define CONSOLE_X_POS (30.0f) -#define CONSOLE_Y_POS (10.0f) -#define CONSOLE_LINE_HEIGHT (12.0f) - -CConsole TheConsole; - -void -CConsole::AddLine(char *s, uint8 r, uint8 g, uint8 b) -{ - char tempstr[MAX_STR_LEN+1]; - - while (strlen(s) > MAX_STR_LEN) { - strncpy(tempstr, s, MAX_STR_LEN); - tempstr[MAX_STR_LEN-1] = '\0'; - s += MAX_STR_LEN - 1; - AddOneLine(tempstr, r, g, b); - } - AddOneLine(s, r, g, b); -} - -void -CConsole::AddOneLine(char *s, uint8 r, uint8 g, uint8 b) -{ - int32 StrIndex = (m_nLineCount + m_nCurrentLine) % MAX_LINES; - - for (int32 i = 0; i < MAX_STR_LEN; i++) { - Buffers[StrIndex][i] = s[i]; - if (s[i] == '\0') break; - } - - uint8 _strNum1 = m_nLineCount; - if (_strNum1 < MAX_LINES) - _strNum1++; - - m_aTimer[StrIndex] = CTimer::GetTimeInMilliseconds(); - Buffers[StrIndex][MAX_STR_LEN-1] = '\0'; - m_aRed[StrIndex] = r; - m_aGreen[StrIndex] = g; - m_aBlue[StrIndex] = b; - - if (_strNum1 >= MAX_LINES) - m_nCurrentLine = (m_nCurrentLine + 1) % MAX_LINES; - else - m_nLineCount = _strNum1; - -} - -void -CConsole::Display() -{ - CFont::SetPropOn(); - CFont::SetBackgroundOff(); - CFont::SetScale(0.6f, 0.6f); - CFont::SetCentreOff(); - CFont::SetRightJustifyOff(); - CFont::SetJustifyOn(); - CFont::SetRightJustifyWrap(0.0f); - CFont::SetBackGroundOnlyTextOff(); - CFont::SetFontStyle(FONT_STANDARD); -#ifndef FIX_BUGS - CFont::SetPropOff(); // not sure why this is here anyway -#endif - CFont::SetWrapx(RsGlobal.width); - - while (m_nLineCount != 0 && CTimer::GetTimeInMilliseconds() - m_aTimer[m_nCurrentLine] > 20000) { - m_nLineCount--; - m_nCurrentLine = (m_nCurrentLine + 1) % MAX_LINES; - } - - for (int16 i = 0; i < m_nLineCount; i++) { - int16 line = (i + m_nCurrentLine) % MAX_LINES; - CFont::SetColor(CRGBA(0, 0, 0, 200)); - CFont::PrintString(CONSOLE_X_POS + 1.0f, CONSOLE_Y_POS + 1.0f + i * CONSOLE_LINE_HEIGHT, Buffers[line]); - CFont::SetColor(CRGBA(m_aRed[line], m_aGreen[line], m_aBlue[line], 200)); - CFont::PrintString(CONSOLE_X_POS, CONSOLE_Y_POS + i * CONSOLE_LINE_HEIGHT, Buffers[line]); - } -} - -void -cprintf(char* format, ...) -{ - char s[256]; - va_list vl1, vl2; - - va_start(vl1, format); - va_copy(vl2, vl1); - vsprintf(s, format, vl1); - TheConsole.AddLine(s, 255, 255, 128); -} diff --git a/src/render/Console.h b/src/render/Console.h deleted file mode 100644 index 9f22236f..00000000 --- a/src/render/Console.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -class CConsole -{ - enum - { - MAX_LINES = 8, // BUG? only shows 7 - MAX_STR_LEN = 40, - }; - - uint8 m_nLineCount; - uint8 m_nCurrentLine; - wchar Buffers[MAX_LINES][MAX_STR_LEN]; - uint32 m_aTimer[MAX_LINES]; - uint8 m_aRed[MAX_LINES]; - uint8 m_aGreen[MAX_LINES]; - uint8 m_aBlue[MAX_LINES]; -public: - void AddLine(char *s, uint8 r, uint8 g, uint8 b); - void AddOneLine(char *s, uint8 r, uint8 g, uint8 b); - void Display(); - void Init() { m_nCurrentLine = 0; m_nLineCount = 0; } -}; - -extern CConsole TheConsole; - -void cprintf(char*, ...); \ No newline at end of file diff --git a/src/render/Coronas.cpp b/src/render/Coronas.cpp deleted file mode 100644 index d9bf88d1..00000000 --- a/src/render/Coronas.cpp +++ /dev/null @@ -1,959 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "General.h" -#include "Entity.h" -#include "RenderBuffer.h" -#include "TxdStore.h" -#include "Camera.h" -#include "Sprite.h" -#include "Timer.h" -#include "World.h" -#include "Weather.h" -#include "Collision.h" -#include "Timecycle.h" -#include "Coronas.h" -#include "PointLights.h" -#include "Shadows.h" -#include "Clock.h" -#include "Bridge.h" - -struct FlareDef -{ - float position; - float size; - int16 red; - int16 green; - int16 blue; - int16 alpha; - int16 texture; -}; - -FlareDef SunFlareDef[] = { - { -0.5f, 15.0f, 50, 50, 0, 200, 1 }, - { -1.0f, 10.0f, 50, 20, 0, 200, 2 }, - { -1.5f, 15.0f, 50, 0, 0, 200, 3 }, - { -2.5f, 25.0f, 50, 0, 0, 200, 1 }, - { 0.5f, 12.5f, 40, 40, 25, 200, 1 }, - { 0.05f, 20.0f, 30, 22, 9, 200, 2 }, - { 1.3f, 7.5f, 50, 30, 9, 200, 3 }, - { 0.0f, 0.0f, 255, 255, 255, 255, 0 } -}; - -FlareDef HeadLightsFlareDef[] = { - { -0.5f, 15.5, 70, 70, 70, 200, 1 }, - { -1.0f, 10.0, 70, 70, 70, 200, 2 }, - { -1.5f, 5.5f, 50, 50, 50, 200, 3 }, - { 0.5f, 12.0f, 50, 50, 50, 200, 1 }, - { 0.05f, 20.0f, 40, 40, 40, 200, 2 }, - { 1.3f, 8.0f, 60, 60, 60, 200, 3 }, - { -2.0f, 12.0f, 50, 50, 50, 200, 1 }, - { -2.3f, 15.0f, 40, 40, 40, 200, 2 }, - { -3.0f, 16.0f, 40, 40, 40, 200, 3 }, - { 0.0f, 0.0f, 255, 255, 255, 255, 0 } -}; - - -RwTexture *gpCoronaTexture[9] = { nil, nil, nil, nil, nil, nil, nil, nil, nil }; - -float CCoronas::LightsMult = 1.0f; -float CCoronas::SunScreenX; -float CCoronas::SunScreenY; -int CCoronas::MoonSize; -bool CCoronas::SunBlockedByClouds; -int CCoronas::bChangeBrightnessImmediately; - -CRegisteredCorona CCoronas::aCoronas[NUMCORONAS]; - -const char aCoronaSpriteNames[][32] = { - "coronastar", - "corona", - "coronamoon", - "coronareflect", - "coronaheadlightline", - "coronahex", - "coronacircle", - "coronaringa", - "streek" -}; - -void -CCoronas::Init(void) -{ - int i; - - CTxdStore::PushCurrentTxd(); - CTxdStore::SetCurrentTxd(CTxdStore::FindTxdSlot("particle")); - - for(i = 0; i < 9; i++) - if(gpCoronaTexture[i] == nil) - gpCoronaTexture[i] = RwTextureRead(aCoronaSpriteNames[i], nil); - - CTxdStore::PopCurrentTxd(); - - for(i = 0; i < NUMCORONAS; i++) - aCoronas[i].id = 0; -} - -void -CCoronas::Shutdown(void) -{ - int i; - for(i = 0; i < 9; i++) - if(gpCoronaTexture[i]){ - RwTextureDestroy(gpCoronaTexture[i]); - gpCoronaTexture[i] = nil; - } -} - -void -CCoronas::Update(void) -{ - int i; - static int LastCamLook = 0; - - LightsMult = Min(LightsMult + 0.03f * CTimer::GetTimeStep(), 1.0f); - - int CamLook = 0; - if(TheCamera.Cams[TheCamera.ActiveCam].LookingLeft) CamLook |= 1; - if(TheCamera.Cams[TheCamera.ActiveCam].LookingRight) CamLook |= 2; - if(TheCamera.Cams[TheCamera.ActiveCam].LookingBehind) CamLook |= 4; - // BUG? - if(TheCamera.GetLookDirection() == LOOKING_BEHIND) CamLook |= 8; - - if(LastCamLook != CamLook) - bChangeBrightnessImmediately = 3; - else - bChangeBrightnessImmediately = Max(bChangeBrightnessImmediately-1, 0); - LastCamLook = CamLook; - - for(i = 0; i < NUMCORONAS; i++) - if(aCoronas[i].id != 0) - aCoronas[i].Update(); -} - -void -CCoronas::RegisterCorona(uint32 id, uint8 red, uint8 green, uint8 blue, uint8 alpha, - const CVector &coors, float size, float drawDist, RwTexture *tex, - int8 flareType, uint8 reflection, uint8 LOScheck, uint8 drawStreak, float someAngle, - bool useNearDist, float nearDist) -{ - int i; - - if(sq(drawDist) < (TheCamera.GetPosition() - coors).MagnitudeSqr2D()) - return; - - if(useNearDist){ - float dist = (TheCamera.GetPosition() - coors).Magnitude(); - if(dist < 35.0f) - return; - if(dist < 50.0f) - alpha *= (dist - 35.0f)/(50.0f - 35.0f); - } - - for(i = 0; i < NUMCORONAS; i++) - if(aCoronas[i].id == id) - break; - - if(i == NUMCORONAS){ - // add a new one - - // find empty slot - for(i = 0; i < NUMCORONAS; i++) - if(aCoronas[i].id == 0) - break; - if(i == NUMCORONAS) - return; // no space - - aCoronas[i].fadeAlpha = 0; - aCoronas[i].offScreen = true; - aCoronas[i].firstUpdate = true; - aCoronas[i].renderReflection = false; - aCoronas[i].lastLOScheck = 0; - aCoronas[i].sightClear = false; - aCoronas[i].hasValue[0] = false; - aCoronas[i].hasValue[1] = false; - aCoronas[i].hasValue[2] = false; - aCoronas[i].hasValue[3] = false; - aCoronas[i].hasValue[4] = false; - aCoronas[i].hasValue[5] = false; - - }else{ - // use existing one - - if(aCoronas[i].fadeAlpha == 0 && alpha == 0){ - // unregister - aCoronas[i].id = 0; - return; - } - } - - aCoronas[i].id = id; - aCoronas[i].red = red; - aCoronas[i].green = green; - aCoronas[i].blue = blue; - aCoronas[i].alpha = alpha; - aCoronas[i].coors = coors; - aCoronas[i].size = size; - aCoronas[i].someAngle = someAngle; - aCoronas[i].registeredThisFrame = true; - aCoronas[i].drawDist = drawDist; - aCoronas[i].texture = tex; - aCoronas[i].flareType = flareType; - aCoronas[i].reflection = reflection; - aCoronas[i].LOScheck = LOScheck; - aCoronas[i].drawStreak = drawStreak; - aCoronas[i].useNearDist = useNearDist; - aCoronas[i].nearDist = nearDist; -} - -void -CCoronas::RegisterCorona(uint32 id, uint8 red, uint8 green, uint8 blue, uint8 alpha, - const CVector &coors, float size, float drawDist, uint8 type, - int8 flareType, uint8 reflection, uint8 LOScheck, uint8 drawStreak, float someAngle, - bool useNearDist, float nearDist) -{ - RegisterCorona(id, red, green, blue, alpha, coors, size, drawDist, - gpCoronaTexture[type], flareType, reflection, LOScheck, drawStreak, someAngle, - useNearDist, nearDist); -} - -void -CCoronas::UpdateCoronaCoors(uint32 id, const CVector &coors, float drawDist, float someAngle) -{ - int i; - - if(sq(drawDist) < (TheCamera.GetPosition() - coors).MagnitudeSqr2D()) - return; - - for(i = 0; i < NUMCORONAS; i++) - if(aCoronas[i].id == id) - break; - - if(i == NUMCORONAS) - return; - - if(aCoronas[i].fadeAlpha == 0) - aCoronas[i].id = 0; // faded out, remove - else{ - aCoronas[i].coors = coors; - aCoronas[i].someAngle = someAngle; - } -} - -static RwIm2DVertex vertexbufferX[2]; - -void -CCoronas::Render(void) -{ - int i, j; - int screenw, screenh; - - PUSH_RENDERGROUP("CCoronas::Render"); - - screenw = RwRasterGetWidth(RwCameraGetRaster(Scene.camera)); - screenh = RwRasterGetHeight(RwCameraGetRaster(Scene.camera)); - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - - for(i = 0; i < NUMCORONAS; i++){ - for(j = 5; j > 0; j--){ - aCoronas[i].prevX[j] = aCoronas[i].prevX[j-1]; - aCoronas[i].prevY[j] = aCoronas[i].prevY[j-1]; - aCoronas[i].prevRed[j] = aCoronas[i].prevRed[j-1]; - aCoronas[i].prevGreen[j] = aCoronas[i].prevGreen[j-1]; - aCoronas[i].prevBlue[j] = aCoronas[i].prevBlue[j-1]; - aCoronas[i].hasValue[j] = aCoronas[i].hasValue[j-1]; - } - aCoronas[i].hasValue[0] = false; - - if(aCoronas[i].id == 0 || - aCoronas[i].fadeAlpha == 0 && aCoronas[i].alpha == 0) - continue; - - CVector spriteCoors; - float spritew, spriteh; - if(!CSprite::CalcScreenCoors(aCoronas[i].coors, &spriteCoors, &spritew, &spriteh, true)){ - aCoronas[i].offScreen = true; - aCoronas[i].sightClear = false; - }else{ - aCoronas[i].offScreen = false; - - if(spriteCoors.x < 0.0f || spriteCoors.y < 0.0f || - spriteCoors.x > screenw || spriteCoors.y > screenh){ - aCoronas[i].offScreen = true; - aCoronas[i].sightClear = false; - }else{ - if(CTimer::GetTimeInMilliseconds() > aCoronas[i].lastLOScheck + 2000){ - aCoronas[i].lastLOScheck = CTimer::GetTimeInMilliseconds(); - aCoronas[i].sightClear = CWorld::GetIsLineOfSightClear( - aCoronas[i].coors, TheCamera.Cams[TheCamera.ActiveCam].Source, - true, true, false, false, false, true, false); - } - - // add new streak point - if(aCoronas[i].sightClear){ - aCoronas[i].prevX[0] = spriteCoors.x; - aCoronas[i].prevY[0] = spriteCoors.y; - aCoronas[i].prevRed[0] = aCoronas[i].red; - aCoronas[i].prevGreen[0] = aCoronas[i].green; - aCoronas[i].prevBlue[0] = aCoronas[i].blue; - aCoronas[i].hasValue[0] = true; - } - - // if distance too big, break streak - if(aCoronas[i].hasValue[1]){ - if(Abs(aCoronas[i].prevX[0] - aCoronas[i].prevX[1]) > 50.0f || - Abs(aCoronas[i].prevY[0] - aCoronas[i].prevY[1]) > 50.0f) - aCoronas[i].hasValue[0] = false; - } - } - - - if(aCoronas[i].fadeAlpha && spriteCoors.z < aCoronas[i].drawDist){ - float recipz = 1.0f/spriteCoors.z; - float fadeDistance = aCoronas[i].drawDist / 2.0f; - float distanceFade = spriteCoors.z < fadeDistance ? 1.0f : 1.0f - (spriteCoors.z - fadeDistance)/fadeDistance; - int totalFade = aCoronas[i].fadeAlpha * distanceFade; - - if(aCoronas[i].LOScheck) - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - else - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - - // render corona itself - if(aCoronas[i].texture){ - float fogscale = CWeather::Foggyness*Min(spriteCoors.z, 40.0f)/40.0f + 1.0f; - if(CCoronas::aCoronas[i].id == SUN_CORE) - spriteCoors.z = 0.95f * RwCameraGetFarClipPlane(Scene.camera); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(aCoronas[i].texture)); - spriteCoors.z -= aCoronas[i].nearDist; - - if(aCoronas[i].texture == gpCoronaTexture[8]){ - // what's this? - float f = 1.0f - aCoronas[i].someAngle*2.0f/PI; - float wscale = 6.0f*sq(sq(sq(f))) + 0.5f; - float hscale = 0.35f - (wscale - 0.5f) * 0.06f; - hscale = Max(hscale, 0.15f); - - CSprite::RenderOneXLUSprite(spriteCoors.x, spriteCoors.y, spriteCoors.z, - spritew * aCoronas[i].size * wscale, - spriteh * aCoronas[i].size * fogscale * hscale, - CCoronas::aCoronas[i].red / fogscale, - CCoronas::aCoronas[i].green / fogscale, - CCoronas::aCoronas[i].blue / fogscale, - totalFade, - recipz, - 255); - }else{ - CSprite::RenderOneXLUSprite_Rotate_Aspect( - spriteCoors.x, spriteCoors.y, spriteCoors.z, - spritew * aCoronas[i].size * fogscale, - spriteh * aCoronas[i].size * fogscale, - CCoronas::aCoronas[i].red / fogscale, - CCoronas::aCoronas[i].green / fogscale, - CCoronas::aCoronas[i].blue / fogscale, - totalFade, - recipz, - 20.0f * recipz, - 255); - } - } - - // render flares - if(aCoronas[i].flareType != FLARE_NONE){ - FlareDef *flare; - - switch(aCoronas[i].flareType){ - case FLARE_SUN: flare = SunFlareDef; break; - case FLARE_HEADLIGHTS: flare = HeadLightsFlareDef; break; - default: assert(0); - } - - for(; flare->texture; flare++){ - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[flare->texture + 4])); - CSprite::RenderOneXLUSprite( - (spriteCoors.x - (screenw/2)) * flare->position + (screenw/2), - (spriteCoors.y - (screenh/2)) * flare->position + (screenh/2), - spriteCoors.z, - 4.0f*flare->size * spritew/spriteh, - 4.0f*flare->size, - (flare->red * aCoronas[i].red)>>8, - (flare->green * aCoronas[i].green)>>8, - (flare->blue * aCoronas[i].blue)>>8, - (totalFade * flare->alpha)>>8, - recipz, 255); - } - } - } - } - } - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - - // streaks - for(i = 0; i < NUMCORONAS; i++){ - if(aCoronas[i].id == 0 || !aCoronas[i].drawStreak) - continue; - - for(j = 0; j < 5; j++){ - if(!aCoronas[i].hasValue[j] || !aCoronas[i].hasValue[j+1]) - continue; - - int alpha1 = (float)(6 - j) / 6 * 128; - int alpha2 = (float)(6 - (j+1)) / 6 * 128; - - RwIm2DVertexSetScreenX(&vertexbufferX[0], aCoronas[i].prevX[j]); - RwIm2DVertexSetScreenY(&vertexbufferX[0], aCoronas[i].prevY[j]); - RwIm2DVertexSetIntRGBA(&vertexbufferX[0], aCoronas[i].prevRed[j] * alpha1 / 256, aCoronas[i].prevGreen[j] * alpha1 / 256, aCoronas[i].prevBlue[j] * alpha1 / 256, 255); - RwIm2DVertexSetScreenX(&vertexbufferX[1], aCoronas[i].prevX[j+1]); - RwIm2DVertexSetScreenY(&vertexbufferX[1], aCoronas[i].prevY[j+1]); - RwIm2DVertexSetIntRGBA(&vertexbufferX[1], aCoronas[i].prevRed[j+1] * alpha2 / 256, aCoronas[i].prevGreen[j+1] * alpha2 / 256, aCoronas[i].prevBlue[j+1] * alpha2 / 256, 255); - -#ifdef FIX_BUGS - RwIm2DVertexSetScreenZ(&vertexbufferX[0], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&vertexbufferX[0], RwCameraGetNearClipPlane(Scene.camera)); - RwIm2DVertexSetRecipCameraZ(&vertexbufferX[0], 1.0f/RwCameraGetNearClipPlane(Scene.camera)); - RwIm2DVertexSetScreenZ(&vertexbufferX[1], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&vertexbufferX[1], RwCameraGetNearClipPlane(Scene.camera)); - RwIm2DVertexSetRecipCameraZ(&vertexbufferX[1], 1.0f/RwCameraGetNearClipPlane(Scene.camera)); -#endif - - RwIm2DRenderLine(vertexbufferX, 2, 0, 1); - } - } - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - - POP_RENDERGROUP(); -} - -void -CCoronas::RenderReflections(void) -{ - int i; - CColPoint point; - CEntity *entity; - - if(CWeather::WetRoads > 0.0f){ - PUSH_RENDERGROUP("CCoronas::RenderReflections"); - - CSprite::InitSpriteBuffer(); - - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[3])); - - for(i = 0; i < NUMCORONAS; i++){ - if(aCoronas[i].id == 0 || - aCoronas[i].fadeAlpha == 0 && aCoronas[i].alpha == 0 || - aCoronas[i].reflection == 0) - continue; - - // check if we want a reflection on this corona - if(aCoronas[i].renderReflection){ - if(((CTimer::GetFrameCounter() + i) & 0xF) == 0 && - CWorld::ProcessVerticalLine(aCoronas[i].coors, -1000.0f, point, entity, true, false, false, false, true, false, nil)) - aCoronas[i].heightAboveRoad = aCoronas[i].coors.z - point.point.z; - }else{ - if(CWorld::ProcessVerticalLine(aCoronas[i].coors, -1000.0f, point, entity, true, false, false, false, true, false, nil)){ - aCoronas[i].heightAboveRoad = aCoronas[i].coors.z - point.point.z; - aCoronas[i].renderReflection = true; - } - } - - // Don't draw if reflection is too high - if(aCoronas[i].renderReflection && aCoronas[i].heightAboveRoad < 20.0f){ - // don't draw if camera is below road - if(CCoronas::aCoronas[i].coors.z - aCoronas[i].heightAboveRoad > TheCamera.GetPosition().z) - continue; - - CVector coors = aCoronas[i].coors; - coors.z -= 2.0f*aCoronas[i].heightAboveRoad; - - CVector spriteCoors; - float spritew, spriteh; - if(CSprite::CalcScreenCoors(coors, &spriteCoors, &spritew, &spriteh, true)) { - float drawDist = 0.75f * aCoronas[i].drawDist; - drawDist = Min(drawDist, 55.0f); - if(spriteCoors.z < drawDist){ - float fadeDistance = drawDist / 2.0f; - float distanceFade = spriteCoors.z < fadeDistance ? 1.0f : 1.0f - (spriteCoors.z - fadeDistance)/fadeDistance; - distanceFade = Clamp(distanceFade, 0.0f, 1.0f); - float recipz = 1.0f/RwCameraGetNearClipPlane(Scene.camera); - float heightFade = (20.0f - aCoronas[i].heightAboveRoad)/20.0f; - int intensity = distanceFade*heightFade * 230.0 * CWeather::WetRoads; - - CSprite::RenderBufferedOneXLUSprite( -#ifdef FIX_BUGS - spriteCoors.x, spriteCoors.y, spriteCoors.z, -#else - spriteCoors.x, spriteCoors.y, RwIm2DGetNearScreenZ(), -#endif - spritew * aCoronas[i].size * 0.75f, - spriteh * aCoronas[i].size * 2.0f, - (intensity * CCoronas::aCoronas[i].red)>>8, - (intensity * CCoronas::aCoronas[i].green)>>8, - (intensity * CCoronas::aCoronas[i].blue)>>8, - 255, - recipz, - 255); - } - } - } - } - CSprite::FlushSpriteBuffer(); - - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - - POP_RENDERGROUP(); - }else{ - for(i = 0; i < NUMCORONAS; i++) - aCoronas[i].renderReflection = false; - } -} - -void -CCoronas::RenderSunReflection(void) -{ - float sunZDir = CTimeCycle::GetSunDirection().z; - if(sunZDir > -0.05f){ - float intensity = (0.3f - Abs(sunZDir - 0.25f))/0.3f * - (1.0f - CWeather::CloudCoverage) * - (1.0f - CWeather::Foggyness) * - (1.0f - CWeather::Wind); - if(intensity > 0.0f){ - int r = (CTimeCycle::GetSunCoreRed() + CTimeCycle::GetSunCoronaRed())*intensity*0.25f; - int g = (CTimeCycle::GetSunCoreGreen() + CTimeCycle::GetSunCoronaGreen())*intensity*0.25f; - int b = (CTimeCycle::GetSunCoreBlue() + CTimeCycle::GetSunCoronaBlue())*intensity*0.25f; - - CVector sunPos = 40.0f*CTimeCycle::GetSunDirection() + TheCamera.GetPosition(); - sunPos.z = 0.5f*CWeather::Wind + 6.1f; - CVector sunDir = CTimeCycle::GetSunDirection(); - sunDir.z = 0.0; - sunDir.Normalise(); - - TempBufferIndicesStored = 6; - TempBufferRenderIndexList[0] = 2; - TempBufferRenderIndexList[1] = 1; - TempBufferRenderIndexList[2] = 0; - TempBufferRenderIndexList[3] = 2; - TempBufferRenderIndexList[4] = 3; - TempBufferRenderIndexList[5] = 1; - - // 60 unit square in sun direction - TempBufferVerticesStored = 4; - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[0], r, g, b, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[0], - sunPos.x + 30.0f*sunDir.y, - sunPos.y - 30.0f*sunDir.x, - sunPos.z); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[1], r, g, b, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[1], - sunPos.x - 30.0f*sunDir.y, - sunPos.y + 30.0f*sunDir.x, - sunPos.z); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[2], r, g, b, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[2], - sunPos.x + 60.0f*sunDir.x + 30.0f*sunDir.y, - sunPos.y + 60.0f*sunDir.y - 30.0f*sunDir.x, - sunPos.z); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[3], r, g, b, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[3], - sunPos.x + 60.0f*sunDir.x - 30.0f*sunDir.y, - sunPos.y + 60.0f*sunDir.y + 30.0f*sunDir.x, - sunPos.z); - - RwIm3DVertexSetU(&TempBufferRenderVertices[0], 0.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[0], 1.0f); - RwIm3DVertexSetU(&TempBufferRenderVertices[1], 1.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[1], 1.0f); - RwIm3DVertexSetU(&TempBufferRenderVertices[2], 0.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[2], 0.5f); - RwIm3DVertexSetU(&TempBufferRenderVertices[3], 1.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[3], 0.5f); - - int timeInc = 0; - int sideInc = 0; - int fwdInc = 0; - for(int i = 0; i < 20; i++){ - TempBufferRenderIndexList[TempBufferIndicesStored + 0] = TempBufferVerticesStored; - TempBufferRenderIndexList[TempBufferIndicesStored + 1] = TempBufferVerticesStored-1; - TempBufferRenderIndexList[TempBufferIndicesStored + 2] = TempBufferVerticesStored-2; - TempBufferRenderIndexList[TempBufferIndicesStored + 3] = TempBufferVerticesStored; - TempBufferRenderIndexList[TempBufferIndicesStored + 4] = TempBufferVerticesStored+1; - TempBufferRenderIndexList[TempBufferIndicesStored + 5] = TempBufferVerticesStored-1; - TempBufferIndicesStored += 6; - - // What a weird way to do it... - float fwdLen = fwdInc/20 + 60; - float sideLen = sideInc/20 + 30; - sideLen += 10.0f*Sin((float)(CTimer::GetTimeInMilliseconds()+timeInc & 0x7FF)/0x800*TWOPI); - timeInc += 900; - sideInc += 970; - fwdInc += 1440; - - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+0], r, g, b, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+0], - sunPos.x + fwdLen*sunDir.x + sideLen*sunDir.y, - sunPos.y + fwdLen*sunDir.y - sideLen*sunDir.x, - sunPos.z); - - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+1], r, g, b, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+1], - sunPos.x + fwdLen*sunDir.x - sideLen*sunDir.y, - sunPos.y + fwdLen*sunDir.y + sideLen*sunDir.x, - sunPos.z); - - RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored+0], 0.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored+0], 0.5f); - RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored+1], 1.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored+1], 0.5f); - TempBufferVerticesStored += 2; - } - - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEFOGTYPE, (void*)rwFOGTYPELINEAR); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[4])); - if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV)){ - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); - RwIm3DEnd(); - } - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - TempBufferVerticesStored = 0; - TempBufferIndicesStored = 0; - } - } -} - -void -CCoronas::DoSunAndMoon(void) -{ - // yeah, moon is done somewhere else.... - - CVector sunCoors = CTimeCycle::GetSunDirection(); - sunCoors *= 150.0f; - sunCoors += TheCamera.GetPosition(); - - if(CTimeCycle::GetSunDirection().z > -0.2f){ - float size = ((CGeneral::GetRandomNumber()&0xFF) * 0.005f + 10.0f) * CTimeCycle::GetSunSize(); - RegisterCorona(SUN_CORE, - CTimeCycle::GetSunCoreRed(), CTimeCycle::GetSunCoreGreen(), CTimeCycle::GetSunCoreBlue(), - 255, sunCoors, size, - 999999.88f, TYPE_STAR, FLARE_NONE, REFLECTION_OFF, LOSCHECK_OFF, STREAK_OFF, 0.0f); - - if(CTimeCycle::GetSunDirection().z > 0.0f && !CGame::IsInInterior()) - RegisterCorona(SUN_CORONA, - CTimeCycle::GetSunCoronaRed(), CTimeCycle::GetSunCoronaGreen(), CTimeCycle::GetSunCoronaBlue(), - 255, sunCoors, 25.0f * CTimeCycle::GetSunSize(), - 999999.88f, TYPE_STAR, FLARE_SUN, REFLECTION_OFF, LOSCHECK_ON, STREAK_OFF, 0.0f); - } - - CVector spriteCoors; - float spritew, spriteh; - if(CSprite::CalcScreenCoors(sunCoors, &spriteCoors, &spritew, &spriteh, true)) { - SunScreenX = spriteCoors.x; - SunScreenY = spriteCoors.y; - }else{ - SunScreenX = 1000000.0f; - SunScreenY = 1000000.0f; - } -} - -void -CRegisteredCorona::Update(void) -{ - if(!registeredThisFrame) - alpha = 0; - - if(LOScheck && - (CCoronas::SunBlockedByClouds && id == CCoronas::SUN_CORONA || - !CWorld::GetIsLineOfSightClear(coors, TheCamera.GetPosition(), true, false, false, false, false, false))){ - // Corona is blocked, fade out - fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); - }else if(offScreen){ - // Same when off screen - fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); - }else{ - // Visible - if(alpha > fadeAlpha){ - // fade in - fadeAlpha = Min(fadeAlpha + 15.0f*CTimer::GetTimeStep(), alpha); - if(CCoronas::bChangeBrightnessImmediately) - fadeAlpha = alpha; - }else if(alpha < fadeAlpha){ - // too visible, decrease alpha but not below alpha - fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), alpha); - } - - // darken scene when the sun is visible - if(id == CCoronas::SUN_CORONA) - CCoronas::LightsMult = Max(CCoronas::LightsMult - CTimer::GetTimeStep()*0.06f, 0.6f); - } - - // remove if invisible - if(fadeAlpha == 0 && !firstUpdate) - id = 0; - firstUpdate = false; - registeredThisFrame = false; -} - -void -CEntity::ProcessLightsForEntity(void) -{ - int i, n; - C2dEffect *effect; - CVector pos; - bool lightOn, lightFlickering; - uint32 flashTimer1, flashTimer2, flashTimer3; - - if(bRenderDamaged || !bIsVisible || GetUp().z < 0.96f) - return; - - flashTimer1 = 0; - flashTimer2 = 0; - flashTimer3 = 0; - - n = CModelInfo::GetModelInfo(GetModelIndex())->GetNum2dEffects(); - for(i = 0; i < n; i++, flashTimer1 += 0x80, flashTimer2 += 0x100, flashTimer3 += 0x200){ - effect = CModelInfo::GetModelInfo(GetModelIndex())->Get2dEffect(i); - - switch(effect->type){ - case EFFECT_LIGHT: - pos = GetMatrix() * effect->pos; - - lightOn = false; - lightFlickering = false; - switch(effect->light.lightType){ - case LIGHT_ON: - lightOn = true; - break; - case LIGHT_ON_NIGHT: - if(CClock::GetHours() > 18 || CClock::GetHours() < 7) - lightOn = true; - break; - case LIGHT_FLICKER: - if((CTimer::GetTimeInMilliseconds() ^ m_randomSeed) & 0x60) - lightOn = true; - else - lightFlickering = true; - if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed) & 3) - lightOn = true; - break; - case LIGHT_FLICKER_NIGHT: - if(CClock::GetHours() > 18 || CClock::GetHours() < 7 || CWeather::WetRoads > 0.5f){ - if((CTimer::GetTimeInMilliseconds() ^ m_randomSeed) & 0x60) - lightOn = true; - else - lightFlickering = true; - if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed) & 3) - lightOn = true; - } - break; - case LIGHT_FLASH1: - if((CTimer::GetTimeInMilliseconds() + flashTimer1) & 0x200) - lightOn = true; - break; - case LIGHT_FLASH1_NIGHT: - if(CClock::GetHours() > 18 || CClock::GetHours() < 7) - if((CTimer::GetTimeInMilliseconds() + flashTimer1) & 0x200) - lightOn = true; - break; - case LIGHT_FLASH2: - if((CTimer::GetTimeInMilliseconds() + flashTimer2) & 0x400) - lightOn = true; - break; - case LIGHT_FLASH2_NIGHT: - if(CClock::GetHours() > 18 || CClock::GetHours() < 7) - if((CTimer::GetTimeInMilliseconds() + flashTimer2) & 0x400) - lightOn = true; - break; - case LIGHT_FLASH3: - if((CTimer::GetTimeInMilliseconds() + flashTimer3) & 0x800) - lightOn = true; - break; - case LIGHT_FLASH3_NIGHT: - if(CClock::GetHours() > 18 || CClock::GetHours() < 7) - if((CTimer::GetTimeInMilliseconds() + flashTimer3) & 0x800) - lightOn = true; - break; - case LIGHT_RANDOM_FLICKER: - if(m_randomSeed > 16) - lightOn = true; - else{ - if((CTimer::GetTimeInMilliseconds() ^ m_randomSeed*8) & 0x60) - lightOn = true; - else - lightFlickering = true; - if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed*8) & 3) - lightOn = true; - } - break; - case LIGHT_RANDOM_FLICKER_NIGHT: - if(CClock::GetHours() > 18 || CClock::GetHours() < 7){ - if(m_randomSeed > 16) - lightOn = true; - else{ - if((CTimer::GetTimeInMilliseconds() ^ m_randomSeed*8) & 0x60) - lightOn = true; - else - lightFlickering = true; - if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed*8) & 3) - lightOn = true; - } - } - break; - case LIGHT_BRIDGE_FLASH1: - if(CBridge::ShouldLightsBeFlashing() && CTimer::GetTimeInMilliseconds() & 0x200) - lightOn = true; - break; - case LIGHT_BRIDGE_FLASH2: - if(CBridge::ShouldLightsBeFlashing() && (CTimer::GetTimeInMilliseconds() & 0x1FF) < 60) - lightOn = true; - break; - } - - if(effect->light.flags & LIGHTFLAG_HIDE_OBJECT){ - if(lightOn) - bDoNotRender = false; - else - bDoNotRender = true; - return; - } - - // Corona - if(lightOn) - CCoronas::RegisterCorona((uintptr)this + i, - effect->col.r, effect->col.g, effect->col.b, 255, - pos, effect->light.size, effect->light.dist, - effect->light.corona, effect->light.flareType, effect->light.roadReflection, - effect->light.flags&LIGHTFLAG_LOSCHECK, CCoronas::STREAK_OFF, 0.0f, - !!(effect->light.flags&LIGHTFLAG_LONG_DIST)); - else if(lightFlickering) - CCoronas::RegisterCorona((uintptr)this + i, - 0, 0, 0, 255, - pos, effect->light.size, effect->light.dist, - effect->light.corona, effect->light.flareType, effect->light.roadReflection, - effect->light.flags&LIGHTFLAG_LOSCHECK, CCoronas::STREAK_OFF, 0.0f, - !!(effect->light.flags&LIGHTFLAG_LONG_DIST)); - - // Pointlight - bool alreadyProcessedFog; - alreadyProcessedFog = false; - if(effect->light.range != 0.0f && lightOn){ - if(effect->col.r == 0 && effect->col.g == 0 && effect->col.b == 0){ - CPointLights::AddLight(CPointLights::LIGHT_POINT, - pos, CVector(0.0f, 0.0f, 0.0f), - effect->light.range, - 0.0f, 0.0f, 0.0f, - CPointLights::FOG_NONE, true); - }else{ - CPointLights::AddLight(CPointLights::LIGHT_POINT, - pos, CVector(0.0f, 0.0f, 0.0f), - effect->light.range, - effect->col.r*CTimeCycle::GetSpriteBrightness()/255.0f, - effect->col.g*CTimeCycle::GetSpriteBrightness()/255.0f, - effect->col.b*CTimeCycle::GetSpriteBrightness()/255.0f, - (effect->light.flags & LIGHTFLAG_FOG) >> 1, - true); - alreadyProcessedFog = true; - } - } - - if(!alreadyProcessedFog){ - if(effect->light.flags & LIGHTFLAG_FOG_ALWAYS){ - CPointLights::AddLight(CPointLights::LIGHT_FOGONLY_ALWAYS, - pos, CVector(0.0f, 0.0f, 0.0f), - 0.0f, - effect->col.r/255.0f, effect->col.g/255.0f, effect->col.b/255.0f, - CPointLights::FOG_ALWAYS, true); - }else if(effect->light.flags & LIGHTFLAG_FOG_NORMAL && lightOn && effect->light.range == 0.0f){ - CPointLights::AddLight(CPointLights::LIGHT_FOGONLY, - pos, CVector(0.0f, 0.0f, 0.0f), - 0.0f, - effect->col.r/255.0f, effect->col.g/255.0f, effect->col.b/255.0f, - CPointLights::FOG_NORMAL, true); - } - } - - // Light shadow - if(effect->light.shadowSize != 0.0f){ - if(lightOn){ - CShadows::StoreStaticShadow((uintptr)this + i, SHADOWTYPE_ADDITIVE, - effect->light.shadow, &pos, - effect->light.shadowSize, 0.0f, - 0.0f, -effect->light.shadowSize, - 128, - effect->col.r*CTimeCycle::GetSpriteBrightness()*effect->light.shadowIntensity/255.0f, - effect->col.g*CTimeCycle::GetSpriteBrightness()*effect->light.shadowIntensity/255.0f, - effect->col.b*CTimeCycle::GetSpriteBrightness()*effect->light.shadowIntensity/255.0f, - 15.0f, 1.0f, 40.0f, false, 0.0f); - }else if(lightFlickering){ - CShadows::StoreStaticShadow((uintptr)this + i, SHADOWTYPE_ADDITIVE, - effect->light.shadow, &pos, - effect->light.shadowSize, 0.0f, - 0.0f, -effect->light.shadowSize, - 0, 0.0f, 0.0f, 0.0f, - 15.0f, 1.0f, 40.0f, false, 0.0f); - } - } - break; - - case EFFECT_SUNGLARE: - if(CWeather::SunGlare >= 0.0f){ - CVector pos = GetMatrix() * effect->pos; - CVector glareDir = pos - GetPosition(); - glareDir.Normalise(); - CVector camDir = TheCamera.GetPosition() - pos; - float dist = camDir.Magnitude(); - camDir *= 2.0f/dist; - glareDir += camDir; - glareDir.Normalise(); - float camAngle = -DotProduct(glareDir, CTimeCycle::GetSunDirection()); - if(camAngle > 0.0f){ - float intens = Sqrt(camAngle) * CWeather::SunGlare; - pos += camDir; - CCoronas::RegisterCorona((uintptr)this + 33 + i, - intens * (CTimeCycle::GetSunCoreRed() + 2*255)/3.0f, - intens * (CTimeCycle::GetSunCoreGreen() + 2*255)/3.0f, - intens * (CTimeCycle::GetSunCoreBlue() + 2*255)/3.0f, - 255, - pos, 0.5f*CWeather::SunGlare*Sqrt(dist), 120.0f, - CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, - CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, - CCoronas::STREAK_OFF, 0.0f); - } - } - break; - } - } -} \ No newline at end of file diff --git a/src/render/Coronas.h b/src/render/Coronas.h deleted file mode 100644 index 45f027d8..00000000 --- a/src/render/Coronas.h +++ /dev/null @@ -1,105 +0,0 @@ -#pragma once - -extern RwTexture *gpCoronaTexture[9]; - -struct CRegisteredCorona -{ - CVector coors; - uint32 id; - uint32 lastLOScheck; - RwTexture *texture; - float size; - float someAngle; - float drawDist; - float nearDist; - float heightAboveRoad; - uint8 red; - uint8 green; - uint8 blue; - uint8 alpha; // alpha when fully visible - uint8 fadeAlpha; // actual value used for rendering, faded - bool registeredThisFrame; - int8 flareType; - int8 reflection; - - uint8 LOScheck : 1; - uint8 offScreen : 1; - uint8 firstUpdate : 1; - uint8 drawStreak : 1; - uint8 sightClear : 1; - uint8 useNearDist : 1; - uint8 renderReflection : 1; - - int16 prevX[6]; - int16 prevY[6]; - uint8 prevRed[6]; - uint8 prevGreen[6]; - uint8 prevBlue[6]; - bool hasValue[6]; - - void Update(void); -}; - -VALIDATE_SIZE(CRegisteredCorona, 0x68); - -class CCoronas -{ - static CRegisteredCorona aCoronas[NUMCORONAS]; -public: - enum { - SUN_CORE = 1, - SUN_CORONA - }; - enum { - TYPE_STAR, - TYPE_NORMAL, - TYPE_MOON, - TYPE_REFLECT, - TYPE_HEADLIGHT, - TYPE_HEX, - TYPE_CIRCLE, - TYPE_RING, - TYPE_STREAK, - }; - enum { - FLARE_NONE, - FLARE_SUN, - FLARE_HEADLIGHTS - }; - enum { - REFLECTION_OFF, - REFLECTION_ON, - }; - enum { - LOSCHECK_OFF, - LOSCHECK_ON, - }; - enum { - STREAK_OFF, - STREAK_ON, - }; - - static float LightsMult; - static float SunScreenY; - static float SunScreenX; - static int MoonSize; - static bool SunBlockedByClouds; - static int bChangeBrightnessImmediately; - - static void Init(void); - static void Shutdown(void); - static void Update(void); - static void RegisterCorona(uint32 id, uint8 red, uint8 green, uint8 blue, uint8 alpha, - const CVector &coors, float size, float drawDist, RwTexture *tex, - int8 flareType, uint8 reflection, uint8 LOScheck, uint8 drawStreak, float someAngle, - bool useNearDist = false, float nearDist = 1.5f); - static void RegisterCorona(uint32 id, uint8 red, uint8 green, uint8 blue, uint8 alpha, - const CVector &coors, float size, float drawDist, uint8 type, - int8 flareType, uint8 reflection, uint8 LOScheck, uint8 drawStreak, float someAngle, - bool useNearDist = false, float nearDist = 1.5f); - static void UpdateCoronaCoors(uint32 id, const CVector &coors, float drawDist, float someAngle); - static void Render(void); - static void RenderReflections(void); - static void RenderSunReflection(void); - static void DoSunAndMoon(void); -}; diff --git a/src/render/Credits.cpp b/src/render/Credits.cpp deleted file mode 100644 index 81e76625..00000000 --- a/src/render/Credits.cpp +++ /dev/null @@ -1,820 +0,0 @@ -#include "common.h" - -#include "Timer.h" -#include "Font.h" -#include "Frontend.h" -#include "RwHelper.h" -#include "Camera.h" -#include "Text.h" -#include "Credits.h" -#include "Pad.h" - -bool CCredits::bCreditsGoing; -uint32 CCredits::CreditsStartTime; - -void -CCredits::Init(void) -{ - Stop(); -} - -void -CCredits::Start(void) -{ - bCreditsGoing = true; - CreditsStartTime = CTimer::GetTimeInMilliseconds(); -} - -void -CCredits::Stop(void) -{ - bCreditsGoing = false; -} - -void -CCredits::PrintCreditSpace(float space, uint32 &line) -{ - line += space * 25.0f; -} - -void -CCredits::PrintCreditText(float scaleX, float scaleY, wchar *text, uint32 &lineoffset, float scrolloffset) -{ - CPad::UpdatePads(); - if (CPad::GetPad(0)->GetCrossJustDown()) - bCreditsGoing = false; - else { - float start = DEFAULT_SCREEN_HEIGHT + 20.0f; - float y = lineoffset + start - scrolloffset; - if (y > 20.0f && DEFAULT_SCREEN_HEIGHT - 20.0f > y) { - CFont::SetScale(SCREEN_SCALE_X(scaleX), SCREEN_SCALE_Y(scaleY)); - CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::PrintString(SCREEN_WIDTH / 2.0f, SCREEN_SCALE_Y(y), (uint16*)text); - CFont::SetColor(CRGBA(220, 220, 220, 220)); - CFont::PrintString(SCREEN_WIDTH / 2.0f - SCREEN_SCALE_X(1.0f), SCREEN_SCALE_Y(y - 1.0f), (uint16*)text); - } - lineoffset += scaleY*25.0f; - } -} - -void -CCredits::Render(void) -{ - uint32 lineoffset; - float scrolloffset; - - if(!bCreditsGoing || FrontEndMenuManager.m_bMenuActive) - return; - - DefinedState(); - lineoffset = 0; - scrolloffset = (CTimer::GetTimeInMilliseconds() - CreditsStartTime) / 24.0f; - CFont::SetJustifyOff(); - CFont::SetBackgroundOff(); - CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.75f)); - CFont::SetCentreOn(); - CFont::SetPropOn(); - CFont::SetFontStyle(FONT_STANDARD); - - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED001"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED002"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED003"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED004"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED005"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED006"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED007"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED008"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED025"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED026"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED027"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED028"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED029"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED030"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED031"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD031A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD031B"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD031C"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD031D"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD031E"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD024A"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED024"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED023"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD023A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD023B"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED018"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED019"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD018A"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD019A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD019B"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED020"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED021"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD022A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED022"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD022B"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD022C"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED032"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED033"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD032A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED034"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED035"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED036"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED037"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD037A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD037B"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD037C"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD041B"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED042"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED039"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED044"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED040"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD042A"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED142"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD142A"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED009"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED010"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED011"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED012"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED013"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD013A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD013B"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD013C"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED089"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED090"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED347"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED047"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED048"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED049"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED348"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED050"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED051"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED052"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED053"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED054"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED055"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED056"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD056A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD056B"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD056C"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD056D"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED349"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED350"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED351"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED352"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED353"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED354"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED355"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED356"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED357"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED359"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED360"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED361"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED362"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED363"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED364"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED365"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED366"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED367"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED368"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED369"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED370"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED371"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED372"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED373"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED256"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED257"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED258"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED057"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED058"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD057A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED059"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD060A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD060B"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD060C"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD002A"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED003"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD001A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD001B"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED060"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED061"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED062"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED063"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED064"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED069"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED070"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED065"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED066"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED067"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED068"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD071A"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD072A"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED091"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED094"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED095"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED097"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED098"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD098A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD098B"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD098C"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED099"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED096"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED273"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD092A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED092"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD092B"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED073"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED074"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED076"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED075"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED077"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED078"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED081"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED082"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED079"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED080"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED083"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED084"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD084A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD084B"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD084C"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD084D"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD084E"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED085"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED086"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD086A"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED087"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED088"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088A"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088B"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088C"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088D"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088E"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088F"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088G"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED107"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED108"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED109"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED110"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD110A"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED111"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED112"), lineoffset, scrolloffset); - - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED113"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED114"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED115"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED116"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED117"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED118"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED119"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED120"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED121"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED122"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED123"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED124"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED125"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED126"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED127"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED128"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED129"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - - CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.8f)); - - PrintCreditText(1.1f, 0.8f, TheText.Get("CRD111A"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED130"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED131"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED132"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED133"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED134"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134A"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134B"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134C"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134D"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134E"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134F"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134G"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134H"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134I"), lineoffset, scrolloffset); - - CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.7f)); - - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED135"), lineoffset, scrolloffset); - - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD136A"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD137A"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED138"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED066"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD138B"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED139"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(1.1f, 0.8f, TheText.Get("CRED140"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) - PrintCreditSpace(0.5f, lineoffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140A"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140B"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140C"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140D"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140E"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140F"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140G"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140H"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140I"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140J"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140K"), lineoffset, scrolloffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140L"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - - CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.85f)); - - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED259"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED260"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED261"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED262"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED263"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED264"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED265"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED266"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED141"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD141A"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD141B"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED143"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED144"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED145"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED146"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED147"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED148"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED149"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED150"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED151"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED152"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED153"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED154"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED155"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED156"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED157"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED158"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED159"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED160"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED161"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED162"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED163"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED164"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED165"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED166"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED167"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED168"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED169"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED170"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED171"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED172"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - - CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.75f)); - - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED217"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED218"), lineoffset, scrolloffset); - PrintCreditSpace(1.0f, lineoffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRD218A"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED219"), lineoffset, scrolloffset); - PrintCreditSpace(1.0f, lineoffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED220"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED221"), lineoffset, scrolloffset); - PrintCreditSpace(1.0f, lineoffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED222"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED223"), lineoffset, scrolloffset); - PrintCreditSpace(1.0f, lineoffset); - PrintCreditText(1.1f, 1.1f, TheText.Get("CRED224"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED227"), lineoffset, scrolloffset); - PrintCreditSpace(1.0f, lineoffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED228"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED229"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD229A"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD229B"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED274"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED275"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED276"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED277"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED278"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED279"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED280"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED281"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED282"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED283"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED284"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED285"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED286"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED287"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED288"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED289"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED290"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED291"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED292"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED293"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED294"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED295"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED296"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED297"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED298"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED299"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED300"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED301"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED302"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED303"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED304"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED305"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED306"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED307"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED308"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED309"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED310"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED314"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED315"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED316"), lineoffset, scrolloffset); - PrintCreditSpace(1.0f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED317"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED318"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED319"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED320"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED321"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED322"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED323"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED324"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED325"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED326"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED327"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED328"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED329"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED330"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED331"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED332"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - - CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.8f)); - - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED333"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED334"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED335"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED336"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED337"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED338"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED339"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED340"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED341"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED342"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditSpace(1.0f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD344A"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED344"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED345"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRD345A"), lineoffset, scrolloffset); - PrintCreditSpace(1.0f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED346"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(1.0f, lineoffset); - - PrintCreditSpace(1.5f, lineoffset); - - CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.75f)); - - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED267"), lineoffset, scrolloffset); - PrintCreditSpace(0.5f, lineoffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED268"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED269"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED270"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED271"), lineoffset, scrolloffset); - PrintCreditText(0.65f, 0.65f, TheText.Get("CRED272"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditText(0.95f, 0.7f, TheText.Get("CRED230"), lineoffset, scrolloffset); - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) - PrintCreditSpace(0.5f, lineoffset); - - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED231"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED232"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED233"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED234"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED235"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED236"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED237"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED238"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED239"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED240"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED241"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED242"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED243"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED244"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED245"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED246"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED247"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED248"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED249"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED358"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED250"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED251"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED252"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRD251A"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRD252A"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED253"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED254"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED374"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED375"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED376"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED377"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED378"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED379"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED380"), lineoffset, scrolloffset); - PrintCreditText(0.95f, 0.95f, TheText.Get("CRED381"), lineoffset, scrolloffset); - PrintCreditSpace(1.5f, lineoffset); - PrintCreditSpace(1.5f, lineoffset); - CFont::DrawFonts(); -#ifdef CUTSCENE_BORDERS_SWITCH - if (CMenuManager::m_PrefsCutsceneBorders) -#endif - if(TheCamera.m_WideScreenOn) - TheCamera.DrawBordersForWideScreen(); - -#ifdef FIX_BUGS - if(lineoffset + DEFAULT_SCREEN_HEIGHT - scrolloffset < -10.0f) -#else - if(lineoffset + SCREEN_HEIGHT - scrolloffset < -10.0f) -#endif - { - bCreditsGoing = false; - } -} - -bool CCredits::AreCreditsDone(void) -{ - return !bCreditsGoing; -} diff --git a/src/render/Credits.h b/src/render/Credits.h deleted file mode 100644 index e049ce76..00000000 --- a/src/render/Credits.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -class CCredits -{ - static bool bCreditsGoing; - static uint32 CreditsStartTime; -public: - static void Init(void); - static void Start(void); - static void Stop(void); - static bool AreCreditsDone(void); - static void Render(void); - static void PrintCreditSpace(float space, uint32 &line); - static void PrintCreditText(float scaleX, float scaleY, wchar *text, uint32 &lineoffset, float scrolloffset); -}; diff --git a/src/render/CutsceneShadow.cpp b/src/render/CutsceneShadow.cpp deleted file mode 100644 index 8cb33896..00000000 --- a/src/render/CutsceneShadow.cpp +++ /dev/null @@ -1,269 +0,0 @@ -#include "common.h" -#include "main.h" -#include "rwcore.h" -#include "rwplcore.h" -#include "CutsceneShadow.h" -#include "RwHelper.h" - -#define DLIGHT_VALUE 0.8f /* Directional light intensity */ - - -CCutsceneShadow::CCutsceneShadow() -{ - m_pAtomic = nil; - m_nRwObjectType = -1; - m_pLight = nil; - m_nBlurPasses = 0; - m_bResample = false; - m_bGradient = false; -} - -CCutsceneShadow::~CCutsceneShadow() -{ - Destroy(); -} - -bool -CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32 blurPasses, bool gradient) -{ - ASSERT(object != nil); - - RwRGBAReal color; - RwFrame *frame; - - if (!object) - return false; - - m_pLight = RpLightCreate(rpLIGHTDIRECTIONAL); - ASSERT(m_pLight != nil); - - if (!m_pLight) - return false; - - color.red = color.green = color.blue = DLIGHT_VALUE; - color.alpha = 0.0f; - - RpLightSetColor(m_pLight, &color); - - frame = RwFrameCreate(); - ASSERT(frame != nil); - - RpLightSetFrame(m_pLight, frame); - - SetLightProperties(180.0f, 90.0f, false); - - m_pObject = object; - m_nRwObjectType = RwObjectGetType(m_pObject); - - switch ( m_nRwObjectType ) - { - case rpCLUMP: - { - RpClumpGetBoundingSphere(m_pClump, &m_BoundingSphere, 1); - m_BaseSphere.radius = m_BoundingSphere.radius; - RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpClumpGetFrame(m_pClump))); - break; - } - - case rpATOMIC: - { - m_BoundingSphere = *RpAtomicGetBoundingSphere(m_pAtomic); - m_BaseSphere.radius = m_BoundingSphere.radius; - RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpAtomicGetFrame(m_pAtomic))); - break; - } - - default: - { - Destroy(); - return false; - break; - } - } - - if ( !m_Camera.Create(rasterSize) ) - { - Destroy(); - return false; - } - - m_nBlurPasses = blurPasses; - m_bResample = resample; - m_bGradient = gradient; - - if ( m_bResample && !m_ResampleCamera.Create(rasterSize - 1) ) - { - Destroy(); - return false; - } - - if ( m_nBlurPasses != 0 ) - { - if ( !m_BlurCamera.Create(resample ? rasterSize - 1 : rasterSize) ) - { - Destroy(); - return false; - } - } - - if ( m_bGradient ) - { - if ( !m_GradientCamera.Create(resample ? rasterSize - 1 : rasterSize) ) - { - Destroy(); - return false; - } - - m_GradientCamera.MakeGradientRaster(); - } - - m_Camera.SetLight(m_pLight); - - switch ( m_nRwObjectType ) - { - case rpATOMIC: - m_Camera.SetFrustum(1.1f * m_BoundingSphere.radius); - break; - - case rpCLUMP: - m_Camera.SetFrustum(1.1f * m_BoundingSphere.radius); - break; - } - - m_Camera.SetCenter(&m_BaseSphere.center); - return true; -} - -RwFrame * -CCutsceneShadow::SetLightProperties(float angleY, float angleX, bool setLight) -{ - ASSERT(m_pLight != nil); - - RwFrame *frame; - static RwV3d Xaxis = { 1.0f, 0.0f, 0.0f }; - static RwV3d Yaxis = { 0.0f, 1.0f, 0.0f }; - - frame = RpLightGetFrame(m_pLight); - ASSERT(frame != nil); - - if ( !frame ) - return nil; - - RwFrameRotate(frame, &Yaxis, angleY, rwCOMBINEREPLACE); - RwFrameRotate(frame, &Xaxis, angleX, rwCOMBINEPOSTCONCAT); - - if ( setLight ) - m_Camera.SetLight(m_pLight); - - return frame; -} - -bool -CCutsceneShadow::IsInitialized() -{ - return m_pObject != nil; -} - -void -CCutsceneShadow::Destroy() -{ - m_Camera.Destroy(); - m_ResampleCamera.Destroy(); - m_BlurCamera.Destroy(); - m_GradientCamera.Destroy(); - - m_pAtomic = nil; - - m_nRwObjectType = -1; - - if (m_pLight) - { - RwFrame *frame = RpLightGetFrame(m_pLight); - RpLightSetFrame(m_pLight, nil); - RwFrameDestroy(frame); - RpLightDestroy(m_pLight); - m_pLight = nil; - } -} - -RwRaster * -CCutsceneShadow::Update() -{ - switch ( m_nRwObjectType ) - { - case rpCLUMP: - ASSERT(m_pClump != nil); - RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpClumpGetFrame(m_pClump))); - break; - - case rpATOMIC: - ASSERT(m_pAtomic != nil); - RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpAtomicGetFrame(m_pAtomic))); - break; - } - - m_Camera.SetCenter(&m_BaseSphere.center); - - switch ( m_nRwObjectType ) - { - case rpCLUMP: - m_Camera.Update(m_pClump); - break; - - case rpATOMIC: - m_Camera.Update(m_pAtomic); - break; - } - - RwRaster *raster = m_Camera.GetRwRenderRaster(); - ASSERT(raster != nil); - - if ( m_bResample ) - return m_ResampleCamera.RasterResample(raster); - - if ( m_nBlurPasses ) - return m_BlurCamera.RasterBlur(raster, m_nBlurPasses); - - if ( m_bGradient ) - return m_GradientCamera.RasterGradient(raster); - - return raster; -} - -RwTexture * -CCutsceneShadow::UpdateForCutscene() -{ - Update(); - return GetShadowRwTexture(); -} - -CShadowCamera * -CCutsceneShadow::GetShadowCamera(int32 camType) -{ - switch ( camType ) - { - case RESAMPLE: return &m_ResampleCamera; - case BLUR: return &m_BlurCamera; - case GRADIENT: return &m_GradientCamera; - } - - return &m_Camera; -} - -RwTexture * -CCutsceneShadow::GetShadowRwTexture() -{ - if ( m_bResample ) - return m_ResampleCamera.GetRwRenderTexture(); - else - return m_Camera.GetRwRenderTexture(); -} - -void -CCutsceneShadow::DrawBorderAroundTexture(RwRGBA const& color) -{ - if ( m_bResample ) - m_ResampleCamera.DrawOutlineBorder(color); - else - m_Camera.DrawOutlineBorder(color); -} \ No newline at end of file diff --git a/src/render/CutsceneShadow.h b/src/render/CutsceneShadow.h deleted file mode 100644 index a59fe78f..00000000 --- a/src/render/CutsceneShadow.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once -#include "ShadowCamera.h" - -class CCutsceneShadow -{ -public: - enum - { - RASTER = 0, - RESAMPLE, - BLUR, - GRADIENT, - }; - - CShadowCamera m_Camera; - bool m_bResample; - CShadowCamera m_ResampleCamera; - int32 m_nBlurPasses; - CShadowCamera m_BlurCamera; - bool m_bGradient; - CShadowCamera m_GradientCamera; - - union - { - RwObject *m_pObject; - RpAtomic *m_pAtomic; - RpClump *m_pClump; - }; - - int32 m_nRwObjectType; - RpLight *m_pLight; - RwSphere m_BoundingSphere; - RwSphere m_BaseSphere; - - CCutsceneShadow(); - ~CCutsceneShadow(); - - RwSphere GetBaseSphere() - { - return m_BaseSphere; - } - - bool Create(RwObject *object, int32 rasterSize, bool resample, int32 blurPasses, bool gradient); - RwFrame *SetLightProperties(float angleY, float angleX, bool setLight); - bool IsInitialized(); - void Destroy(); - RwRaster *Update(); - RwTexture *UpdateForCutscene(); - CShadowCamera *GetShadowCamera(int32 camType = RASTER); - RwTexture *GetShadowRwTexture(); - void DrawBorderAroundTexture(RwRGBA const& color); -}; diff --git a/src/render/Draw.cpp b/src/render/Draw.cpp deleted file mode 100644 index 9c5921c3..00000000 --- a/src/render/Draw.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "common.h" - -#include "Draw.h" -#include "Frontend.h" -#include "Camera.h" -#include "CutsceneMgr.h" - -float CDraw::ms_fAspectRatio = DEFAULT_ASPECT_RATIO; -#ifdef ASPECT_RATIO_SCALE -float CDraw::ms_fScaledFOV = 45.0f; -#endif - -float CDraw::ms_fNearClipZ; -float CDraw::ms_fFarClipZ; -float CDraw::ms_fFOV = 45.0f; -float CDraw::ms_fLODDistance; - -uint8 CDraw::FadeValue; -uint8 CDraw::FadeRed; -uint8 CDraw::FadeGreen; -uint8 CDraw::FadeBlue; - -#ifdef PROPER_SCALING -bool CDraw::ms_bProperScaling = true; -#endif -#ifdef FIX_RADAR -bool CDraw::ms_bFixRadar = true; -#endif -#ifdef FIX_SPRITES -bool CDraw::ms_bFixSprites = true; -#endif - -#ifdef ASPECT_RATIO_SCALE -float -FindAspectRatio(void) -{ - switch (FrontEndMenuManager.m_PrefsUseWideScreen) { - case AR_AUTO: - return SCREEN_WIDTH / SCREEN_HEIGHT; - default: - case AR_4_3: - return 4.0f / 3.0f; - case AR_5_4: - return 5.0f / 4.0f; - case AR_16_10: - return 16.0f / 10.0f; - case AR_16_9: - return 16.0f / 9.0f; - case AR_21_9: - return 21.0f / 9.0f; - }; -} -#endif - -float -CDraw::CalculateAspectRatio(void) -{ -#ifdef ASPECT_RATIO_SCALE - if (TheCamera.m_WideScreenOn) - CDraw::ms_fAspectRatio = (5.f / 3.f) * FindAspectRatio() / (16.f / 9.f); // It's used on theatrical showings according to Wiki - else - CDraw::ms_fAspectRatio = FindAspectRatio(); -#else - if(FrontEndMenuManager.m_PrefsUseWideScreen) { - if (TheCamera.m_WideScreenOn) - CDraw::ms_fAspectRatio = 5.f / 3.f; // It's used on theatrical showings according to Wiki - else - CDraw::ms_fAspectRatio = 16.f / 9.f; - } else if (TheCamera.m_WideScreenOn) { - CDraw::ms_fAspectRatio = 5.f/4.f; - } else { - CDraw::ms_fAspectRatio = 4.f/3.f; - } -#endif - return CDraw::ms_fAspectRatio; -} - -#ifdef ASPECT_RATIO_SCALE -// convert a 4:3 hFOV to vFOV, -// then convert that vFOV to hFOV for our aspect ratio, -// i.e. HOR+ -float -CDraw::ConvertFOV(float hfov) -{ - // => tan(hFOV/2) = tan(vFOV/2)*aspectRatio - // => tan(vFOV/2) = tan(hFOV/2)/aspectRatio - float ar1 = DEFAULT_ASPECT_RATIO; - float ar2 = GetAspectRatio(); - hfov = DEGTORAD(hfov); - float vfov = Atan(tan(hfov/2) / ar1) *2; - hfov = Atan(tan(vfov/2) * ar2) *2; - return RADTODEG(hfov); -} -#endif - -void -CDraw::SetFOV(float fov) -{ -#ifdef ASPECT_RATIO_SCALE - if (!CCutsceneMgr::IsRunning()) - ms_fScaledFOV = ConvertFOV(fov); - else - ms_fScaledFOV = fov; -#endif - ms_fFOV = fov; -} - -#ifdef PROPER_SCALING -float CDraw::ScaleY(float y) -{ - return ms_bProperScaling ? y : y * ((float)DEFAULT_SCREEN_HEIGHT/SCREEN_HEIGHT_NTSC); -} -#endif \ No newline at end of file diff --git a/src/render/Draw.h b/src/render/Draw.h deleted file mode 100644 index b96fa813..00000000 --- a/src/render/Draw.h +++ /dev/null @@ -1,70 +0,0 @@ -#pragma once - -enum eAspectRatio -{ - // Make sure these work the same as FrontEndMenuManager.m_PrefsUseWideScreen - // without widescreen support - AR_AUTO, - AR_4_3, - AR_5_4, - AR_16_10, - AR_16_9, - AR_21_9, - - AR_MAX, -}; - -class CDraw -{ -private: - static float ms_fNearClipZ; - static float ms_fFarClipZ; - static float ms_fFOV; - // we use this variable to scale a lot of 2D elements - // so better cache it - static float ms_fAspectRatio; -#ifdef ASPECT_RATIO_SCALE - // similar thing for 3D rendering - static float ms_fScaledFOV; -#endif -public: - static float ms_fLODDistance; // set but unused? - - static uint8 FadeValue; - static uint8 FadeRed; - static uint8 FadeGreen; - static uint8 FadeBlue; - -#ifdef PROPER_SCALING - static bool ms_bProperScaling; -#endif -#ifdef FIX_RADAR - static bool ms_bFixRadar; -#endif -#ifdef FIX_SPRITES - static bool ms_bFixSprites; -#endif - - static void SetNearClipZ(float nearclip) { ms_fNearClipZ = nearclip; } - static float GetNearClipZ(void) { return ms_fNearClipZ; } - static void SetFarClipZ(float farclip) { ms_fFarClipZ = farclip; } - static float GetFarClipZ(void) { return ms_fFarClipZ; } - - static void SetFOV(float fov); - static float GetFOV(void) { return ms_fFOV; } -#ifdef ASPECT_RATIO_SCALE - static float GetScaledFOV(void) { return ms_fScaledFOV; } -#else - static float GetScaledFOV(void) { return ms_fFOV; } -#endif - - static float CalculateAspectRatio(void); -#ifdef ASPECT_RATIO_SCALE - static float ConvertFOV(float fov); -#endif - static float GetAspectRatio(void) { return ms_fAspectRatio; } - static void SetAspectRatio(float ratio) { ms_fAspectRatio = ratio; } -#ifdef PROPER_SCALING - static float ScaleY(float y); -#endif -}; diff --git a/src/render/Fluff.cpp b/src/render/Fluff.cpp deleted file mode 100644 index 1e4d289b..00000000 --- a/src/render/Fluff.cpp +++ /dev/null @@ -1,1364 +0,0 @@ -#include "common.h" -#include "main.h" - -#include "RenderBuffer.h" -#include "Entity.h" -#include "Fluff.h" -#include "Camera.h" -#include "Sprite.h" -#include "Coronas.h" -#include "PointLights.h" -#include "Rubbish.h" -#include "Timecycle.h" -#include "General.h" -#include "Timer.h" -#include "Clock.h" -#include "Weather.h" -#include "Stats.h" -#include "maths.h" -#include "Frontend.h" -#include "CutsceneMgr.h" -#include "PlayerPed.h" -#include "Bones.h" -#include "World.h" -#include "Replay.h" -#include "Coronas.h" -#include "SaveBuf.h" - -#ifdef COMPATIBLE_SAVES -#define SCRIPTPATHS_SAVE_SIZE 0x9C -#else -#define SCRIPTPATHS_SAVE_SIZE sizeof(aArray) -#endif - -CPlaneTrail CPlaneTrails::aArray[6]; -RwImVertexIndex TrailIndices[32] = { - 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, - 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16 -}; - -void -CPlaneTrail::Init(void) -{ - int i; - for(i = 0; i < ARRAY_SIZE(m_time); i++) - m_time[i] = 0; -} - -void -CPlaneTrail::Render(float visibility) -{ - int i; - int numVerts = 0; - if(!TheCamera.IsSphereVisible(m_pos[0], 1000.0f)) - return; - - int alpha = visibility*110.0f; - if(alpha == 0) - return; - - for(i = 0; i < ARRAY_SIZE(m_pos); i++){ - int32 time = CTimer::GetTimeInMilliseconds() - m_time[i]; - if(time > 30000) - m_time[i] = 0; - if(m_time[i] != 0){ - float fade = (30000.0f - time) / 10000.0f; - fade = Min(fade, 1.0f); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[numVerts], 255, 255, 255, (int)(alpha*fade)); - RwIm3DVertexSetPos(&TempBufferRenderVertices[numVerts], m_pos[i].x, m_pos[i].y, m_pos[i].z); - numVerts++; - } - } - if(numVerts > 1){ - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - - if(RwIm3DTransform(TempBufferRenderVertices, numVerts, nil, rwIM3D_VERTEXXYZ|rwIM3D_VERTEXRGBA)){ - RwIm3DRenderIndexedPrimitive(rwPRIMTYPELINELIST, TrailIndices, (numVerts-1)*2); - RwIm3DEnd(); - } - } -} - -void -CPlaneTrail::RegisterPoint(CVector pos) -{ - int i; - bool bNewPoint = false; - if(m_time[0] != 0 && CTimer::GetTimeInMilliseconds() - m_time[0] > 2000){ - bNewPoint = true; - for(i = ARRAY_SIZE(m_pos)-1; i > 0; i--){ - m_pos[i] = m_pos[i-1]; - m_time[i] = m_time[i-1]; - } - } - m_pos[0] = pos; - if(bNewPoint || m_time[0] == 0) - m_time[0] = CTimer::GetTimeInMilliseconds(); -} - -void -CPlaneTrails::Init(void) -{ - int i; - for(i = 0; i < ARRAY_SIZE(aArray); i++) - aArray[i].Init(); -} - -void -CPlaneTrails::Update(void) -{ - CVector planePos; - - planePos.x = 1590.0f * Sin((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); - planePos.y = 1200.0f * Cos((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); - planePos.z = 550.0f; - RegisterPoint(planePos, 3); - if(CClock::GetHours() > 22 || CClock::GetHours() < 7){ - if(CTimer::GetTimeInMilliseconds() & 0x200) - CCoronas::RegisterCorona(101, 255, 0, 0, 255, planePos, 5.0f, 2000.0f, - CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); - else - CCoronas::UpdateCoronaCoors(101, planePos, 2000.0f, 0.0f); - } - - planePos.x = 1000.0f * Sin((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); - planePos.y = -1600.0f * Cos((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); - planePos.z = 500.0f; - RegisterPoint(planePos, 4); - if(CClock::GetHours() > 22 || CClock::GetHours() < 7){ - if(CTimer::GetTimeInMilliseconds() & 0x200) - CCoronas::RegisterCorona(102, 255, 0, 0, 255, planePos, 5.0f, 2000.0f, - CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); - else - CCoronas::UpdateCoronaCoors(102, planePos, 2000.0f, 0.0f); - } - - planePos.x = 1100.0f * Cos((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); - planePos.y = 700.0f * Sin((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); - planePos.z = 600.0f; - RegisterPoint(planePos, 5); - if(CClock::GetHours() > 22 || CClock::GetHours() < 7){ - if(CTimer::GetTimeInMilliseconds() & 0x200) - CCoronas::RegisterCorona(103, 255, 0, 0, 255, planePos, 5.0f, 2000.0f, - CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, - CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); - else - CCoronas::UpdateCoronaCoors(103, planePos, 2000.0f, 0.0f); - } -} - -void -CPlaneTrails::Render(void) -{ - int i; - float visibility = Min(1.0f-CWeather::Foggyness, 1.0f-CWeather::CloudCoverage); - visibility = Min(visibility, 1.0f-CWeather::Rain); - visibility = Min(Max(Max(CTimeCycle::GetSkyTopRed(), CTimeCycle::GetSkyTopGreen()), CTimeCycle::GetSkyTopBlue())/256.0f, visibility); - if(visibility > 0.0001f) - for(i = 0; i < ARRAY_SIZE(aArray); i++) - aArray[i].Render(visibility); -} - -void -CPlaneTrails::RegisterPoint(CVector pos, uint32 id) -{ - aArray[id].RegisterPoint(pos); -} - - - -CPlaneBanner CPlaneBanners::aArray[5]; - -void -CPlaneBanner::Init(void) -{ - int i; - for(i = 0; i < ARRAY_SIZE(m_pos); i++){ - m_pos[i].x = i; - m_pos[i].y = 0.0f; - m_pos[i].z = -60.0f; - } -} - -void -CPlaneBanner::Update(void) -{ - int i; - if(m_pos[0].z > -50.0f){ - m_pos[0].z -= 0.05f*CTimer::GetTimeStep(); - m_pos[0].z = Max(m_pos[0].z, -100.0f); - for(i = 1; i < ARRAY_SIZE(m_pos); i++){ - CVector dist = m_pos[i] - m_pos[i-1]; - float len = dist.Magnitude(); - if(len > 8.0f) - m_pos[i] = m_pos[i-1] + dist/len*8.0f; - } - } -} - -void -CPlaneBanner::Render(void) -{ - int i; - if(m_pos[0].z > -50.0f){ - float camDist = (TheCamera.GetPosition() - m_pos[0]).Magnitude(); - if(TheCamera.IsSphereVisible(m_pos[4], 32.0f) && camDist < 300.0f){ - TempBufferVerticesStored = 0; - TempBufferIndicesStored = 0; - int alpha = camDist < 250.0f ? 160 : (300.0f-camDist)/(300.0f-250.0f)*160; - - TempBufferVerticesStored += 2; - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[0], 255, 255, 255, alpha); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[1], 255, 255, 255, alpha); - RwIm3DVertexSetPos(&TempBufferRenderVertices[0], m_pos[2].x, m_pos[2].y, m_pos[2].z); - RwIm3DVertexSetPos(&TempBufferRenderVertices[1], m_pos[2].x, m_pos[2].y, m_pos[2].z - 4.0f); - RwIm3DVertexSetU(&TempBufferRenderVertices[0], 0.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[0], 0.0f); - RwIm3DVertexSetU(&TempBufferRenderVertices[1], 0.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[1], 1.0f); - for(i = 2; i < 8; i++){ - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+0], 255, 255, 255, alpha); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+1], 255, 255, 255, alpha); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+0], m_pos[i].x, m_pos[i].y, m_pos[i].z); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+1], m_pos[i].x, m_pos[i].y, m_pos[i].z - 4.0f); - RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored+0], (i-2)/5.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored+0], 0.0f); - RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored+1], (i-2)/5.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored+1], 1.0f); - TempBufferRenderIndexList[TempBufferIndicesStored+0] = TempBufferVerticesStored-2; - TempBufferRenderIndexList[TempBufferIndicesStored+1] = TempBufferVerticesStored-1; - TempBufferRenderIndexList[TempBufferIndicesStored+2] = TempBufferVerticesStored+1; - TempBufferRenderIndexList[TempBufferIndicesStored+3] = TempBufferVerticesStored-2; - TempBufferRenderIndexList[TempBufferIndicesStored+4] = TempBufferVerticesStored+1; - TempBufferRenderIndexList[TempBufferIndicesStored+5] = TempBufferVerticesStored; - TempBufferVerticesStored += 2; - TempBufferIndicesStored += 6; - } - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpRubbishTexture[2])); - -#ifdef FIX_BUGS - if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXXYZ|rwIM3D_VERTEXUV|rwIM3D_VERTEXRGBA)){ -#else - if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, 0)){ -#endif - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); - RwIm3DEnd(); - } - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - - TempBufferVerticesStored = 0; - TempBufferIndicesStored = 0; - } - } -} - -void -CPlaneBanner::RegisterPoint(CVector pos) -{ - m_pos[0] = pos; -} - -void -CPlaneBanners::Init(void) -{ - int i; - for(i = 0; i < ARRAY_SIZE(aArray); i++) - aArray[i].Init(); -} - -void -CPlaneBanners::Update(void) -{ - int i; - for(i = 0; i < ARRAY_SIZE(aArray); i++) - aArray[i].Update(); -} - -void -CPlaneBanners::Render(void) -{ - int i; - for(i = 0; i < ARRAY_SIZE(aArray); i++) - aArray[i].Render(); -} - -void -CPlaneBanners::RegisterPoint(CVector pos, uint32 id) -{ - aArray[id].RegisterPoint(pos); -} - -bool CSmokeTrails::CigOn = false; -CSmokeTrail CSmokeTrails::aSmoke[3]; - -RwImVertexIndex SmokeTrailIndices[32] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, -9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16 }; - -float RandomSmoke[16] = { 10.0f, 5.0f, -1.0f, -9.0f, -7.0f, -1.0f, 0.0f, 3.0f, 6.0f, 7.0f, 4.0f, 2.0f, -5.0f, 7.0f }; - -uint8 ScrollCharSet[59][5] = { - { 0x00, 0x00, 0x00, 0x00, 0x00 }, // ' ' - { 0x00, 0x00, 0x1D, 0x00, 0x00 }, // '!' - { 0x00, 0x00, 0x00, 0x00, 0x00 }, // '"' - { 0x0A, 0x1F, 0x0A, 0x1F, 0x0A }, // '#' - { 0x00, 0x09, 0x1F, 0x12, 0x00 }, // '$' - { 0x18, 0x18, 0x00, 0x03, 0x03 }, // '%' - { 0x00, 0x00, 0x00, 0x00, 0x00 }, // '&' - { 0x00, 0x00, 0x00, 0x00, 0x00 }, // ''' - { 0x01, 0x02, 0x04, 0x08, 0x10 }, // '(' - { 0x00, 0x00, 0x18, 0x00, 0x00 }, // ')' - { 0x15, 0x04, 0x1F, 0x04, 0x15 }, // '*' - { 0x00, 0x04, 0x0E, 0x04, 0x00 }, // '+' - { 0x00, 0x00, 0x03, 0x00, 0x00 }, // ',' - { 0x00, 0x04, 0x04, 0x04, 0x00 }, // '-' - { 0x00, 0x00, 0x01, 0x00, 0x00 }, // '.' - { 0x00, 0x00, 0x00, 0x00, 0x00 }, // '/' - { 0x0E, 0x11, 0x11, 0x11, 0x0E }, // '0' - { 0x01, 0x09, 0x1F, 0x01, 0x01 }, // '1' - { 0x03, 0x15, 0x15, 0x15, 0x09 }, // '2' - { 0x11, 0x11, 0x15, 0x15, 0x0A }, // '3' - { 0x02, 0x06, 0x0A, 0x1F, 0x02 }, // '4' - { 0x1D, 0x15, 0x15, 0x15, 0x12 }, // '5' - { 0x0E, 0x15, 0x15, 0x15, 0x12 }, // '6' - { 0x18, 0x10, 0x13, 0x14, 0x18 }, // '7' - { 0x0A, 0x15, 0x15, 0x15, 0x0A }, // '8' - { 0x08, 0x15, 0x15, 0x15, 0x0E }, // '9' - { 0x00, 0x00, 0x0A, 0x00, 0x00 }, // ':' - { 0x18, 0x18, 0x00, 0x03, 0x03 }, // ';' - { 0x04, 0x08, 0x1F, 0x08, 0x04 }, // '<' - { 0x00, 0x0A, 0x0A, 0x0A, 0x00 }, // '=' - { 0x04, 0x02, 0x1F, 0x02, 0x04 }, // '>' - { 0x10, 0x10, 0x15, 0x14, 0x1D }, // '?' - { 0x00, 0x1C, 0x14, 0x1C, 0x00 }, // '@' - { 0x0F, 0x12, 0x12, 0x12, 0x0F }, // 'A' - { 0x1F, 0x15, 0x15, 0x15, 0x0A }, // 'B' - { 0x0E, 0x11, 0x11, 0x11, 0x0A }, // 'C' - { 0x1F, 0x11, 0x11, 0x11, 0x0E }, // 'D' - { 0x1F, 0x15, 0x15, 0x11, 0x11 }, // 'E' - { 0x1F, 0x14, 0x14, 0x10, 0x10 }, // 'F' - { 0x0E, 0x11, 0x15, 0x15, 0x06 }, // 'G' - { 0x1F, 0x04, 0x04, 0x04, 0x1F }, // 'H' - { 0x11, 0x11, 0x1F, 0x11, 0x11 }, // 'I' - { 0x02, 0x01, 0x01, 0x01, 0x1E }, // 'J' - { 0x1F, 0x04, 0x0C, 0x12, 0x01 }, // 'K' - { 0x1F, 0x01, 0x01, 0x01, 0x01 }, // 'L' - { 0x1F, 0x08, 0x06, 0x08, 0x1F }, // 'M' - { 0x1F, 0x08, 0x04, 0x02, 0x1F }, // 'N' - { 0x0E, 0x11, 0x11, 0x11, 0x0E }, // 'O' - { 0x1F, 0x12, 0x12, 0x12, 0x0C }, // 'P' - { 0x0C, 0x12, 0x12, 0x13, 0x0D }, // 'Q' - { 0x1F, 0x14, 0x14, 0x16, 0x09 }, // 'R' - { 0x09, 0x15, 0x15, 0x15, 0x02 }, // 'S' - { 0x10, 0x10, 0x1F, 0x10, 0x10 }, // 'T' - { 0x1E, 0x01, 0x01, 0x01, 0x1E }, // 'U' - { 0x1C, 0x02, 0x01, 0x02, 0x1C }, // 'V' - { 0x1E, 0x01, 0x06, 0x01, 0x1E }, // 'W' - { 0x11, 0x0A, 0x04, 0x0A, 0x11 }, // 'X' - { 0x18, 0x04, 0x03, 0x04, 0x18 }, // 'Y' - { 0x11, 0x13, 0x15, 0x19, 0x11 } // 'Z' -}; - -// ---------- CMovingThings ---------- -enum eScrollBarTypes -{ - SCROLL_ARENA_STRING -}; - -CScrollBar aScrollBars[1]; - -CMovingThing CMovingThings::StartCloseList; -CMovingThing CMovingThings::EndCloseList; -int16 CMovingThings::Num; -CMovingThing CMovingThings::aMovingThings[NUMMOVINGTHINGS]; - -int32 CScrollBar::TonightsEvent; - -void CMovingThings::Init() -{ - StartCloseList.m_pNext = &CMovingThings::EndCloseList; - StartCloseList.m_pPrev = nil; - EndCloseList.m_pNext = nil; - EndCloseList.m_pPrev = &CMovingThings::StartCloseList; - - CPlaneTrails::Init(); - CSmokeTrails::Init(); - CPlaneBanners::Init(); - CPointLights::Init(); - - Num = 0; - - for (int32 i = 0; i < NUMMOVINGTHINGS; i++) { - aMovingThings[i].m_nType = 0; - aMovingThings[i].m_farAway = 0; - } - - for (int i = 0; i < NUMSECTORS_X; i++) { - for (int j = 0; j < NUMSECTORS_Y; j++) { - for (CPtrNode *pNode = CWorld::GetSector(i, j)->m_lists[ENTITYLIST_BUILDINGS].first; pNode; pNode = pNode->next) { - CEntity *pEntity = (CEntity *)pNode->item; - PossiblyAddThisEntity(pEntity); - } - } - } - - for (int32 i = 0; i < NUM_LEVELS; i++) { - for (CPtrNode *pNode = CWorld::GetBigBuildingList((eLevelName)i).first; pNode; pNode = pNode->next) { - CEntity *pEntity = (CEntity *)pNode->item; - PossiblyAddThisEntity(pEntity); - } - } - - CEscalators::Init(); - aScrollBars[0].Init(CVector(-1069.209f, 1320.126f, 18.848f), CVector(-1069.209f, 1342.299f, 22.612f), SCROLL_ARENA_STRING, 128, 255, 0, 0.3f); -} - -void CMovingThings::Shutdown() -{ - - aScrollBars[0].SetVisibility(false); - CEscalators::Shutdown(); -} - -void CMovingThings::Update() -{ - CPlaneBanners::Update(); - CPlaneTrails::Update(); - CEscalators::Update(); - - const int TIME_SPAN = 8; // frames to process all aMovingThings - - int16 i; - - int block = CTimer::GetFrameCounter() % TIME_SPAN; - - for (i = (block * NUMMOVINGTHINGS) / TIME_SPAN; i < ((block + 1) * NUMMOVINGTHINGS) / TIME_SPAN; i++) { - if (aMovingThings[i].m_farAway == 1) - aMovingThings[i].Update(); - } - - for (i = 0; i < CMovingThings::Num; i++) { - if (aMovingThings[i].m_farAway == 0) - aMovingThings[i].Update(); - } - - for (i = 0; i < ARRAY_SIZE(aScrollBars); ++i) - { - if (aScrollBars[i].IsVisible() || (CTimer::GetFrameCounter() + i) % 8 == 0) - aScrollBars[i].Update(); - } -} - -void CMovingThings::Render() -{ - PUSH_RENDERGROUP("CMovingThings::Render"); - CSmokeTrails::Update(); - - int i; - for (i = 0; i < ARRAY_SIZE(aScrollBars); ++i) - { - if (aScrollBars[i].IsVisible()) - aScrollBars[i].Render(); - } - - CPlaneTrails::Render(); - CSmokeTrails::Render(); - CPlaneBanners::Render(); - POP_RENDERGROUP(); -} - -void CMovingThings::RegisterOne(CEntity *pEnt, uint16 nType) { - if (Num >= NUMMOVINGTHINGS) - return; - - aMovingThings[Num].m_pEntity = pEnt; - aMovingThings[Num].m_nType = nType; - aMovingThings[Num].m_farAway = 0; - aMovingThings[Num].m_vecPosn = pEnt->GetPosition(); - aMovingThings[Num].AddToList(&CMovingThings::StartCloseList); - Num++; -} - -void CMovingThings::PossiblyAddThisEntity(CEntity *pEnt) { - if (pEnt->GetModelIndex() == MI_LIGHTBEAM) { - RegisterOne(pEnt, 1); - } - else if (pEnt->GetModelIndex() == MI_AIRPORTRADAR) { - RegisterOne(pEnt, 2); - } - else if (pEnt->GetModelIndex() == MI_MALLFAN || pEnt->GetModelIndex() == MI_HOTELFAN_NIGHT - || pEnt->GetModelIndex() == MI_HOTELFAN_DAY || pEnt->GetModelIndex() == MI_HOTROOMFAN) { - RegisterOne(pEnt, 3); - } - else if (pEnt->GetModelIndex() == MI_BLIMP_NIGHT || pEnt->GetModelIndex() == MI_BLIMP_DAY) { - RegisterOne(pEnt, 4); - } -} - -// ---------- CMovingThing ---------- -static float maxUpdateDists[5] = { 100.0f, 1500.0f, 400.0f, 100.0f, 2000.0f }; - -void CMovingThing::Update() -{ - switch (m_nType) { - case 1: { - float angle = (CTimer::GetTimeInMilliseconds() % 0x3FFF) * TWOPI / 0x3FFF; - float s = Sin(angle); - float c = Cos(angle); - m_pEntity->GetRight() = CVector(-s, c, 0.0f); - m_pEntity->GetForward() = CVector(0.0f, 0.0f, 1.0f); - m_pEntity->GetUp() = CVector(c, s, 0.0f); - - if (CClock::GetHours() >= 20 || CClock::GetHours() < 5) { - if (Abs(TheCamera.GetPosition().x - m_pEntity->GetPosition().x) < 600.0f && - Abs(TheCamera.GetPosition().y - m_pEntity->GetPosition().y) < 600.0f) { - CVector delta = m_pEntity->GetPosition() - TheCamera.GetPosition(); - delta /= delta.Magnitude(); - - if (DotProduct(delta, CVector(c, s, 0.0f)) < -0.92f) { - CVector coors = m_pEntity->GetPosition() - 10.0f * delta; - CCoronas::RegisterCorona(43, 128, 128, 100, 255, coors, 70.0f, 600.0f, 0.0f, CCoronas::TYPE_STAR, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); - } - } - } - } - break; - case 2: { - float angle = (CTimer::GetTimeInMilliseconds() % 0x7FF) * TWOPI / 0x7FF; - float s = Sin(angle); - float c = Cos(angle); - m_pEntity->GetRight() = CVector(c, s, 0.0f); - m_pEntity->GetForward() = CVector(-s, c, 0.0f); - m_pEntity->GetUp() = CVector(0.0f, 0.0f, 1.0f); - } - break; - case 3: { - float angle = (CTimer::GetTimeInMilliseconds() % 0x3FF) * TWOPI / 0x3FF; - float s = Sin(angle); - float c = Cos(angle); - m_pEntity->GetRight() = CVector(c, s, 0.0f); - m_pEntity->GetForward() = CVector(-s, c, 0.0f); - m_pEntity->GetUp() = CVector(0.0f, 0.0f, 1.0f); - } - break; - case 4: { - float angle = (CTimer::GetTimeInMilliseconds() % 0x3FFFF) * TWOPI / 0x3FFFF; - float s = Sin(angle); - float c = Cos(angle); - m_pEntity->GetRight() = CVector(-c, -s, 0.0f); - m_pEntity->GetForward() = CVector(s, -c, 0.0f); - m_pEntity->GetUp() = CVector(0.0f, 0.0f, 1.0f); - m_pEntity->SetPosition(CVector(350.0f * c - 465.0f, 350.0f * s + 1163.0f, 260.0f)); - } - break; - default: - break; - } - - m_pEntity->GetMatrix().UpdateRW(); - m_pEntity->UpdateRwFrame(); - - if (SQR(m_pEntity->GetPosition().x - TheCamera.GetPosition().x) + SQR(m_pEntity->GetPosition().y - TheCamera.GetPosition().y) < SQR(maxUpdateDists[m_nType])) { - if (m_farAway == 1) { - AddToList(&CMovingThings::StartCloseList); - m_farAway = 0; - } - } - else { - if (m_farAway == 0) { - RemoveFromList(); - m_farAway = 1; - } - } -} - -void CMovingThing::AddToList(CMovingThing *pThing) -{ - m_pNext = pThing->m_pNext; - m_pPrev = pThing; - pThing->m_pNext = this; - m_pNext->m_pPrev = this; -} - -void CMovingThing::RemoveFromList() -{ - m_pNext->m_pPrev = m_pPrev; - m_pPrev->m_pNext = m_pNext; -} - -int16 CMovingThing::SizeList() -{ - CMovingThing *next = m_pNext; - int16 count = 0; - - while (next != nil) { - next = next->m_pNext; - count++; - } - - return count; -} - -char String_Time[] = "THE TIME IS 12:34 "; -const char* FindTimeMessage() -{ - String_Time[12] = '0' + CClock::GetHours() / 10; - String_Time[13] = '0' + CClock::GetHours() % 10; - String_Time[15] = '0' + CClock::GetMinutes() / 10; - String_Time[16] = '0' + CClock::GetMinutes() % 10; - return String_Time; -} - -// ---------- CScrollBar ---------- -void CScrollBar::Init(CVector pos1, CVector pos2, uint8 type, uint8 red, uint8 green, uint8 blue, float scale) -{ - for (int i = 0; i < ARRAY_SIZE(m_MessageBar); ++i) - m_MessageBar[i] = 0; - - m_pMessage = ". "; - m_MessageCurrentChar = 0; - m_MessageLength = strlen(m_pMessage); - - m_Counter = 0; - m_bVisible = false; - m_Position = pos1; - m_Type = type; - m_Size.x = (pos2.x - pos1.x) * 0.025f; - m_Size.y = (pos2.y - pos1.y) * 0.025f; - m_Size.z = (pos2.z - pos1.z) * 0.2f; - m_uRed = red; - m_uGreen = green; - m_uBlue = blue; - m_fScale = scale; -} - -void CScrollBar::Update() -{ - float distanceFromCamera = (TheCamera.GetPosition() - m_Position).Magnitude(); - if (distanceFromCamera > 100.0f) - { - m_bVisible = false; - return; - } - - m_bVisible = true; - - if (distanceFromCamera < 75.0f) - m_fIntensity = 1.0f; - else - m_fIntensity = 1.0f - 4.0f * (distanceFromCamera - 75.0f) / 100.0f; - - m_Counter = (m_Counter + 1) % 8; - - // if message is fully printed, load up the next one - if (m_Counter == 0 && ++m_MessageCurrentChar >= m_MessageLength) - { - const char* previousMessage = m_pMessage; - if (m_Type == SCROLL_ARENA_STRING) { - while (previousMessage == m_pMessage) - { - switch (CGeneral::GetRandomNumber() % 4) - { - case 0: - switch (TonightsEvent) { - case 0: - m_pMessage = "MAIN EVENT TONIGHT: CAR RACING . . . "; - break; - case 1: - m_pMessage = "MAIN EVENT TONIGHT: DESTRUCTION DERBY . . . "; - break; - case 2: - m_pMessage = "MAIN EVENT TONIGHT: BIKE RACING . . . "; - break; - } - break; - case 1: - switch (TonightsEvent) { - case 0: - m_pMessage = "FOR TICKETS TO THE HOT RING EVENT CALL 555-3764 . . . "; - break; - case 1: - m_pMessage = "FOR TICKETS TO THE BLOOD RING EVENT CALL 555-3765 . . . "; - break; - case 2: - m_pMessage = "FOR TICKETS TO THE DIRT RING EVENT CALL 555-3766 . . . "; - break; - } - break; - case 2: - m_pMessage = "HYMAN MEMORIAL STADIUM. HOME TO SOME OF THE BIGGEST EVENTS OF" - " THE WESTERN HEMISPHERE. ALSO AVAILABLE FOR CHILDREN PARTIES. . . "; - break; - case 3: - m_pMessage = FindTimeMessage(); - break; - default: - break; - } - } - } - - m_MessageLength = (uint32)strlen(m_pMessage); - m_MessageCurrentChar = 0; - } - - // Scroll - for (int i = 0; i < ARRAY_SIZE(m_MessageBar)-1; i++) - m_MessageBar[i] = m_MessageBar[i + 1]; - m_MessageBar[ARRAY_SIZE(m_MessageBar)-1] = m_Counter < 5 ? ScrollCharSet[m_pMessage[m_MessageCurrentChar] - ' '][m_Counter] : 0; - - // Introduce some random displaying glitches; signs aren't supposed to be perfect :P - switch (CGeneral::GetRandomNumber() & 0xFF) - { - case 0x0D: m_MessageBar[ARRAY_SIZE(m_MessageBar)-1] = 0; break; - case 0xE3: m_MessageBar[ARRAY_SIZE(m_MessageBar)-1] = 0xE3; break; - case 0x64: m_MessageBar[ARRAY_SIZE(m_MessageBar)-1] = ~m_MessageBar[ARRAY_SIZE(m_MessageBar)-1]; break; - } -} - -void CScrollBar::Render() -{ - if (!TheCamera.IsSphereVisible(m_Position, 2.0f * 20.0f * (ABS(m_Size.x) + ABS(m_Size.y)))) - return; - - CSprite::InitSpriteBuffer(); - - // Calculate intensity of colours - uint8 r = m_fIntensity * m_uRed; - uint8 g = m_fIntensity * m_uGreen; - uint8 b = m_fIntensity * m_uBlue; - - // Set render states - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[0])); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - - CVector coronaCoord, screenCoord; - float screenW, screenH; - for (int i = 1; i < ARRAY_SIZE(m_MessageBar); ++i) - { - for (int j = 0; j < 5; ++j) - { - coronaCoord.x = m_Position.x + m_Size.x * i; - coronaCoord.y = m_Position.y + m_Size.y * i; - coronaCoord.z = m_Position.z + m_Size.z * j; - - // Render main coronas - if (m_MessageBar[i] & (1 << j)) - { - if (CSprite::CalcScreenCoors(coronaCoord, &screenCoord, &screenW, &screenH, true)) - { - CSprite::RenderBufferedOneXLUSprite( - screenCoord.x, screenCoord.y, screenCoord.z, - screenW * m_fScale, screenH * m_fScale, - r, g, b, - 255, 1.0f / screenCoord.z, 255); - } - } - // Render smaller and faded coronas for a trailing effect - else if (m_MessageBar[i - 1] & (1 << j)) - { - if (CSprite::CalcScreenCoors(coronaCoord, &screenCoord, &screenW, &screenH, true)) - { - CSprite::RenderBufferedOneXLUSprite( - screenCoord.x, screenCoord.y, screenCoord.z, - screenW * m_fScale * 0.8f, - screenH * m_fScale * 0.8f, - r / 2, - g / 2, - b / 2, - 255, 1.0f / screenCoord.z, 255); - } - } - } - } - - CSprite::FlushSpriteBuffer(); -} - -void -CSmokeTrail::RegisterPoint(CVector regPosition, float opacity) { - bool bAddedNewPoint = false; - - if (m_time[0] && CTimer::GetTimeInMilliseconds() - m_time[0] > 150) { - bAddedNewPoint = true; - for (int32 i = 15; i > 0; i--) { - m_pos[i] = m_pos[i - 1]; - m_time[i] = m_time[i - 1]; - m_opacity[i] = m_opacity[i - 1]; - } - ++m_seed; - } - m_pos[0] = regPosition; - - if (bAddedNewPoint || !m_time[0]) { - m_time[0] = CTimer::GetTimeInMilliseconds(); - float density = 0.1f / (m_pos[1] - m_pos[2]).Magnitude(); - m_opacity[1] = opacity * Min(density, 1.0f); - } - m_opacity[0] = 0.0f; -} - -void -CSmokeTrail::Init(int num) { - for (int32 i = 0; i < 16; i++) - m_time[i] = 0; - m_seed = num * 2; -} - -void -CSmokeTrails::Init(void) { - for (int32 i = 0; i < 3; i++) - aSmoke[i].Init(i); -} - -void -CSmokeTrails::Render(void) { - for (int32 i = 0; i < 3; i++) - aSmoke[i].Render(); -} - -void -CSmokeTrail::Render(void) { - int numVerts = 0; - - if (TheCamera.IsSphereVisible(m_pos[0], 10.0f)) { - for (int32 i = 0; i < 16; i++) { - int timeSinceSpawned = CTimer::GetTimeInMilliseconds() - m_time[i]; - - if (timeSinceSpawned > 2250) - m_time[i] = 0; - - if (m_time[i]) { - int alpha = (1.0f - timeSinceSpawned / 2250.0f) * 110.0f * m_opacity[i]; - float offset = timeSinceSpawned * CWeather::Wind * 0.0001f; - float posX = (m_pos[i].x + timeSinceSpawned * RandomSmoke[(i - m_seed) & 0xF] * 0.00001f) - offset; - float posY = (m_pos[i].y + timeSinceSpawned * RandomSmoke[(i - m_seed + 5) & 0xF] * 0.00001f) - offset; - float posZ = m_pos[i].z + timeSinceSpawned * 0.0004f; - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[i], 200, 200, 200, alpha); - RwIm3DVertexSetPos(&TempBufferRenderVertices[i], posX, posY, posZ); - numVerts++; - } - } - } - - if (numVerts > 1) { - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - - if (RwIm3DTransform(TempBufferRenderVertices, numVerts, nil, rwIM3D_VERTEXXYZ | rwIM3D_VERTEXRGBA)) { - RwIm3DRenderIndexedPrimitive(rwPRIMTYPEPOLYLINE, SmokeTrailIndices, 2 * (numVerts - 1)); - RwIm3DEnd(); - } - } -} - -void -CSmokeTrails::Update(void) { - - if (!CSmokeTrails::CigOn || TheCamera.Using1stPersonWeaponMode() || !FindPlayerPed() || - FindPlayerVehicle() || CCutsceneMgr::IsRunning() || !FindPlayerPed()->GetClump()) - return; - - RwV3d startPos = { 0.026f, 0.15f, 0.02f }; - RwV3d endPos = { 0.026f, 0.05f, 0.02f }; - - RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(FindPlayerPed()->GetClump()); - int32 idx = RpHAnimIDGetIndex(hier, ConvertPedNode2BoneTag(PED_HEAD)); - RwMatrix *head = &RpHAnimHierarchyGetMatrixArray(hier)[idx]; - RwV3dTransformPoints(&startPos, &startPos, 1, head); - RwV3dTransformPoints(&endPos, &endPos, 1, head); - - aSmoke[0].RegisterPoint(startPos, 1.0f); - aSmoke[1].RegisterPoint(startPos, 0.75f); - aSmoke[2].RegisterPoint(startPos, 0.5f); - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[0], 255, 255, 255, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[0], startPos.x, startPos.y, startPos.z); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[1], 255, 255, 255, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[1], endPos.x, endPos.y, endPos.z); - - if (RwIm3DTransform(TempBufferRenderVertices, 2, nil, rwIM3D_VERTEXXYZ | rwIM3D_VERTEXRGBA)) { - RwIm3DRenderIndexedPrimitive(rwPRIMTYPEPOLYLINE, SmokeTrailIndices, 2); - RwIm3DEnd(); - } -} - -CEscalator CEscalators::aEscalators[NUM_ESCALATORS]; -int32 CEscalators::NumEscalators; - -CEscalator::CEscalator() { - m_bIsActive = false; - - for (int i = 0; i < 24; i++) { - m_pSteps[i] = nil; - } -} - -void -CEscalator::AddThisOne(CVector pos0, CVector pos1, CVector pos2, CVector pos3, bool b_isMovingDown) { - m_pos0 = pos0; - m_pos1 = pos1; - m_pos2 = pos2; - m_pos3 = pos3; - - float escalatorStepHeight = CModelInfo::GetModelInfo(MI_ESCALATORSTEP)->GetColModel()->boundingBox.max.z; - m_pos0.z -= escalatorStepHeight; - m_pos1.z -= escalatorStepHeight; - m_pos2.z -= escalatorStepHeight; - m_pos3.z -= escalatorStepHeight; - - float magnitudes[3]; - magnitudes[0] = (m_pos0 - m_pos1).Magnitude(); - magnitudes[1] = (m_pos1 - m_pos2).Magnitude(); - magnitudes[2] = (m_pos2 - m_pos3).Magnitude(); - - float length = magnitudes[0] + magnitudes[1] + magnitudes[2]; - - m_lowerEnd = magnitudes[0] / length; - m_upperEnd = (magnitudes[0] + magnitudes[1]) / length; - - m_stepsCount = Min(24.0f, length / 0.6f); - - CVector direction(m_pos0.x - m_pos1.x, m_pos0.y - m_pos1.y, 0.0f); - direction.Normalise(); - - m_matrix.GetUp() = CVector(0.0f, 0.0f, 1.0f); - m_matrix.GetForward() = CVector(direction.x, direction.y, 0.0f); - m_matrix.GetRight() = CVector(direction.y, -direction.x, 0.0f); - m_matrix.GetPosition() = CVector(0.0f, 0.0f, 0.0f); - - m_bIsMovingDown = b_isMovingDown; - - m_midPoint = (m_pos0 + m_pos3) / 2.0f; - - m_radius = (m_pos0 - m_midPoint).Magnitude(); -} - -void -CEscalator::Update(void) { - if (!m_bIsActive) { - if ((TheCamera.GetPosition() - m_midPoint).Magnitude() < 25.0f) { - if (TheCamera.IsSphereVisible(m_midPoint, m_radius) && (m_stepsCount + 10 < CPools::GetObjectPool()->GetNoOfFreeSpaces())) { - m_bIsActive = true; - for (int i = 0; i < m_stepsCount; i++) { - m_pSteps[i] = new CObject(MI_ESCALATORSTEP, TRUE); - if (m_pSteps[i]) { - m_pSteps[i]->SetPosition(m_pos1); - CWorld::Add(m_pSteps[i]); - m_pSteps[i]->ObjectCreatedBy = CONTROLLED_SUB_OBJECT; - } - } - } - } - } - - if (m_bIsActive) { - float time = (CTimer::GetTimeInMilliseconds() % 16384) / 16384.0f; - for (int i = 0; i < m_stepsCount; i++) { - if (m_pSteps[i]) { - float t = i / (float)m_stepsCount + time; - - if (t > 1.0f) - t -= 1.0f; - - if (m_bIsMovingDown) - t = 1.0f - t; - - CVector oldPosition = m_pSteps[i]->GetPosition(); - m_pSteps[i]->GetMatrix() = m_matrix; - - CVector newPosition; - if (t < m_lowerEnd) { - float ratio = t / m_lowerEnd; - newPosition = (ratio * m_pos1) + ((1.0f - ratio) * m_pos0); - } - else if (t < m_upperEnd) { - float ratio = (t - m_lowerEnd) / (m_upperEnd - m_lowerEnd); - newPosition = (ratio * m_pos2) + ((1.0f - ratio) * m_pos1); - } - else { - float ratio = (t - m_upperEnd) / (1.0f - m_upperEnd); - newPosition = (ratio * m_pos3) + ((1.0f - ratio) * m_pos2); - } - - m_pSteps[i]->SetPosition(newPosition); - m_pSteps[i]->m_vecMoveSpeed = (newPosition - oldPosition) / Max(CTimer::GetTimeStep(), 1.0f); - m_pSteps[i]->GetMatrix().UpdateRW(); - m_pSteps[i]->UpdateRwFrame(); - } - if ((TheCamera.GetPosition() - m_midPoint).Magnitude() > 28.0f || !TheCamera.IsSphereVisible(m_midPoint, m_radius)) - SwitchOff(); - } - } -} - -bool deletingEscalator; - -void -CEscalator::SwitchOff(void) { - if (m_bIsActive) { - for (int i = 0; i < m_stepsCount; i++) { - if (m_pSteps[i]) { - CWorld::Remove(m_pSteps[i]); - deletingEscalator = true; - delete m_pSteps[i]; - m_pSteps[i] = nil; - deletingEscalator = false; - } - } - m_bIsActive = false; - } -} - -void -CEscalators::AddOne(CVector pos0, CVector pos1, CVector pos2, CVector pos3, bool b_isMovingDown) { - aEscalators[NumEscalators++].AddThisOne(pos0, pos1, pos2, pos3, b_isMovingDown); -} - -void -CEscalators::Init(void) { - Shutdown(); - NumEscalators = 0; - - AddOne(CVector(-9.82999f, -938.04498f, 9.4219f), CVector(-8.573f, -938.04498f, 9.4219f), - CVector(-0.747f, -938.045f, 15.065f), CVector(0.88f, -938.045f, 15.065f), TRUE); - - AddOne(CVector(-9.83f, -939.966f, 9.422f), CVector(-8.573f, -939.966f, 9.422f), - CVector(-0.747f, -939.966f, 15.065f), CVector(0.880f, -939.966f, 15.065f), FALSE); - - AddOne(CVector(408.116f, 1058.36f, 18.261f), CVector(408.094f, 1057.04f, 18.261f), - CVector(408.116f, 1048.0f, 24.765f), CVector(408.094f, 1046.57f, 24.799f), TRUE); - - AddOne(CVector(406.195f, 1058.36f, 18.261f), CVector(406.173f, 1057.04f, 18.261f), - CVector(406.195f, 1048.0f, 24.729f), CVector(406.173f, 1046.57f, 24.79f), FALSE); - - AddOne(CVector(421.729f, 1058.3789f, 18.075f), CVector(421.707f, 1057.052f, 18.099f), - CVector(421.729f, 1048.016f, 24.604f), CVector(421.707f, 1046.589f, 24.637f), TRUE); - - AddOne(CVector(419.808f, 1058.378f, 18.099f), CVector(419.786f, 1057.052f, 18.099f), - CVector(419.808f, 1048.016f, 24.568f), CVector(419.786f, 1046.589f, 24.637f), FALSE); - - AddOne(CVector(412.69901f, 1102.729f, 17.569f), CVector(412.72198f, 1104.057f, 17.57f), - CVector(412.69901f, 1113.092f, 24.073f), CVector(412.72198f, 1114.3201f, 24.108f), TRUE); - - AddOne(CVector(414.62f, 1102.729f, 17.569f), CVector(414.64301f, 1104.057f, 17.57f), - CVector(414.62f, 1113.092f, 24.037001f), CVector(414.64301f, 1114.3201f, 24.099001f), FALSE); - - AddOne(CVector(414.64301f, 1145.589f, 17.57f), CVector(414.62f, 1144.261f, 17.569f), - CVector(414.64301f, 1135.226f, 24.073999f), CVector(414.62f, 1133.798f, 24.107f), TRUE); - - AddOne(CVector(412.72198f, 1145.589f, 17.57f), CVector(412.69901f, 1144.261f, 17.569f), - CVector(412.72198f, 1135.226f, 24.038f), CVector(412.69901f, 1133.798f, 24.098f), FALSE); - - AddOne(CVector(406.05099f, 1193.4771f, 18.016001f), CVector(406.07401f, 1194.8051f, 18.017f), - CVector(406.05099f, 1203.84f, 24.52f), CVector(406.07401f, 1205.2679f, 24.555f), TRUE); - - AddOne(CVector(407.97198f, 1193.4771f, 18.016001f), CVector(407.995f, 1194.8051f, 18.017f), - CVector(407.97198f, 1203.84f, 24.483999f), CVector(407.995f, 1205.2679f, 24.546f), FALSE); - - AddOne(CVector(419.659f, 1193.479f, 17.979f), CVector(419.68201f, 1194.807f, 17.98f), - CVector(419.659f, 1203.842f, 24.483f), CVector(419.68201f, 1205.27f, 24.518f), TRUE); - - AddOne(CVector(421.57999f, 1193.479f, 17.979f), CVector(421.603f, 1194.807f, 17.98f), - CVector(421.57999f, 1203.842f, 24.447001f), CVector(421.603f, 1205.27f, 24.509001f), FALSE); - - AddOne(CVector(406.23199f, 1022.857f, 17.917f), CVector(406.23199f, 1024.1851f, 17.917f), - CVector(406.23199f, 1033.22f, 24.521f), CVector(406.23199f, 1034.647f, 24.555f), TRUE); - - AddOne(CVector(408.15302f, 1022.857f, 17.917f), CVector(408.15302f, 1024.1851f, 17.916f), - CVector(408.15302f, 1033.22f, 24.486f), CVector(408.15302f, 1034.647f, 24.52f), FALSE); - - AddOne(CVector(-1506.39f, -813.13f, 13.834f), CVector(-1506.177f, -814.51703f, 13.834f), - CVector(-1504.566f, -823.20898f, 19.836f), CVector(-1504.329f, -824.48499f, 19.837f), FALSE); - - AddOne(CVector(-1481.951f, -859.05402f, 13.834f), CVector(-1482.7791f, -858.22498f, 13.834f), - CVector(-1489.03f, -851.974f, 19.836f), CVector(-1489.948f, -851.05701f, 19.837f), TRUE); - - AddOne(CVector(-1461.743f, -871.35901f, 13.834f), CVector(-1460.62f, -871.69202f, 13.834f), - CVector(-1452.144f, -874.20203f, 19.836f), CVector(-1450.9f, -874.57098f, 19.837f), FALSE); - - AddOne(CVector(-1409.889f, -871.41498f, 13.834f), CVector(-1411.0129f, -871.74701f, 13.834f), - CVector(-1419.489f, -874.258f, 19.836f), CVector(-1420.733f, -874.62701f, 19.837f), TRUE); - - AddOne(CVector(-1389.577f, -858.89301f, 13.834f), CVector(-1388.7271f, -858.08698f, 13.834f), - CVector(-1382.314f, -852.00201f, 19.836f), CVector(-1381.373f, -851.10797f, 19.837f), FALSE); - - AddOne(CVector(-1364.981f, -813.13f, 13.834f), CVector(-1365.204f, -814.28003f, 13.834f), - CVector(-1366.891f, -822.95801f, 19.83f), CVector(-1367.139f, -824.23199f, 19.837f), TRUE); - - for (int i = 0; i < NUM_ESCALATORS; i++) { - aEscalators[i].SwitchOff(); - } -} - -void -CEscalators::Update(void) { - if (CReplay::IsPlayingBack()) - return; - - for (int i = 0; i < NUM_ESCALATORS; i++) { - aEscalators[i].Update(); - } -} - -void -CEscalators::Shutdown(void) { - for (int i = 0; i < NUM_ESCALATORS; i++) { - aEscalators[i].SwitchOff(); - } - NumEscalators = 0; -} - - -CScriptPath CScriptPaths::aArray[3]; - -void CScriptPath::FindCoorsFromDistanceOnPath(float t, float *pX, float *pY, float *pZ) -{ - int32 i; - for (i = 0; m_pNode[i + 1].t < t; i++) - if (i == m_numNodes - 1) { - // don't go beyond last node - *pX = m_pNode[m_numNodes - 1].p.x; - *pY = m_pNode[m_numNodes - 1].p.y; - *pZ = m_pNode[m_numNodes - 1].p.z; - return; - } - float f = (t - m_pNode[i].t) / (m_pNode[i + 1].t - m_pNode[i].t); - *pX = (1.0f - f)*m_pNode[i].p.x + f*m_pNode[i + 1].p.x; - *pY = (1.0f - f)*m_pNode[i].p.y + f*m_pNode[i + 1].p.y; - *pZ = (1.0f - f)*m_pNode[i].p.z + f*m_pNode[i + 1].p.z; -} - -void CScriptPath::Update(void) { - if (m_state != SCRIPT_PATH_ACTIVE) - return; - - m_fPosition += m_fSpeed * CTimer::GetTimeStepInSeconds(); - m_fPosition = Clamp(m_fPosition, 0.0f, m_fTotalLength); - - if (m_pObjects[0] || m_pObjects[1] || m_pObjects[2] || m_pObjects[3] - || m_pObjects[4] || m_pObjects[5]) { - - float t1, t2; - CVector pos1, pos2; - - t1 = Max(m_fPosition - m_fObjectLength / 2.0f, 0.0f); - FindCoorsFromDistanceOnPath(t1, &pos1.x, &pos1.y, &pos1.z); - t2 = Min(m_fPosition + m_fObjectLength / 2.0f, m_fTotalLength); - FindCoorsFromDistanceOnPath(t2, &pos2.x, &pos2.y, &pos2.z); - - CVector newForward, newUp(0.0f, 0.0f, 1.0f), newRight; - - newForward = pos2 - pos1; - newForward.Normalise(); - newRight = CrossProduct(newForward, newUp); - newRight.Normalise(); - newUp = CrossProduct(newRight, newForward); - - for (int i = 0; i < 6; i++) { - if (m_pObjects[i]) { - CMatrix prevMat(m_pObjects[i]->GetMatrix()); - CVector prevPosition = m_pObjects[i]->GetPosition(); - - m_pObjects[i]->SetPosition((pos1 + pos2) / 2.0f); - m_pObjects[i]->GetRight() = newRight; - m_pObjects[i]->GetUp() = newUp; - m_pObjects[i]->GetForward() = newForward; - m_pObjects[i]->GetMatrix().UpdateRW(); - m_pObjects[i]->UpdateRwFrame(); - - if (!m_pObjects[i]->bIsBIGBuilding && prevPosition != m_pObjects[i]->GetPosition()) - m_pObjects[i]->RemoveAndAdd(); - - m_pObjects[i]->GetMatrix().UpdateRW(); - m_pObjects[i]->UpdateRwFrame(); - - m_pObjects[i]->m_vecMoveSpeed = (m_pObjects[i]->GetPosition() - prevMat.GetPosition()) / CTimer::GetTimeStep(); - - float deltaAngle = m_pObjects[i]->GetForward().Heading() - prevMat.GetForward().Heading(); - while (deltaAngle < (float)PI) deltaAngle += (float)TWOPI; - while (deltaAngle > (float)PI) deltaAngle -= (float)TWOPI; - float zTurnSpeed = deltaAngle / CTimer::GetTimeStep(); - - m_pObjects[i]->m_vecTurnSpeed = CVector(0.0f, 0.0f, zTurnSpeed); - m_pObjects[i]->m_vecMoveFriction = CVector(0.0f, 0.0f, 0.0f); - m_pObjects[i]->m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f); - } - } - } -} - -void CScriptPath::Clear(void) { - if (m_pNode) - delete[] m_pNode; - m_pNode = nil; - m_numNodes = 0; - for (int i = 0; i < 6; i++) - m_pObjects[i] = nil; - m_state = SCRIPT_PATH_DISABLED; -} - -void CScriptPath::InitialiseOne(int32 numNodes, float length) { - char Dest[32]; - sprintf(Dest, "data\\paths\\spath%d.dat", numNodes); - m_pNode = CPlane::LoadPath(Dest, m_numNodes, m_fTotalLength, false); - m_fSpeed = 1.0f; - m_fPosition = 0.0f; - m_fObjectLength = length; - m_state = SCRIPT_PATH_INITIALIZED; -} - -void CScriptPath::SetObjectToControl(CObject *pObj) { - int32 i = 0; - while (i < 6 && m_pObjects[i]) - i++; - m_pObjects[i] = pObj; - pObj->RegisterReference((CEntity**)&m_pObjects[i]); - pObj->m_phy_flagA08 = false; - m_state = SCRIPT_PATH_ACTIVE; -} - -void CScriptPaths::Init(void) { - for (int i = 0; i < 3; i++) - aArray[i].Clear(); -} - -void CScriptPaths::Shutdown(void) { - for (int i = 0; i < 3; i++) - aArray[i].Clear(); -} - -void CScriptPaths::Update(void) { - for (int i = 0; i < 3; i++) - aArray[i].Update(); -} - -bool CScriptPaths::IsOneActive(void) { - for (int i = 0; i < 3; i++) - if (aArray[i].m_state == SCRIPT_PATH_ACTIVE && aArray[i].m_fSpeed != 0.0f) - return true; - - return false; -} - -void CScriptPaths::Load(uint8 *buf, uint32 size) { -INITSAVEBUF - for (int32 i = 0; i < 3; i++) - aArray[i].Clear(); - - for (int32 i = 0; i < 3; i++) { -#ifdef COMPATIBLE_SAVES - ReadSaveBuf(&aArray[i].m_numNodes, buf); - SkipSaveBuf(buf, 4); - ReadSaveBuf(&aArray[i].m_fTotalLength, buf); - ReadSaveBuf(&aArray[i].m_fSpeed, buf); - ReadSaveBuf(&aArray[i].m_fPosition, buf); - ReadSaveBuf(&aArray[i].m_fObjectLength, buf); - ReadSaveBuf(&aArray[i].m_state, buf); -#else - ReadSaveBuf(&aArray[i], buf); -#endif - - for (int32 j = 0; j < 6; j++) { -#ifdef COMPATIBLE_SAVES - aArray[i].m_pObjects[j] = nil; - int32 tmp; - ReadSaveBuf(&tmp, buf); - if (tmp != 0) { - aArray[i].m_pObjects[j] = CPools::GetObjectPool()->GetSlot(tmp - 1); - aArray[i].m_pObjects[j]->m_phy_flagA08 = false; - } -#else - CScriptPath *pPath = &aArray[i]; - if (pPath->m_pObjects[j] != nil) { - pPath->m_pObjects[j] = CPools::GetObjectPool()->GetSlot((uintptr)pPath->m_pObjects[j] - 1); - pPath->m_pObjects[j]->m_phy_flagA08 = false; - } -#endif - } - - aArray[i].m_pNode = new CPlaneNode[aArray[i].m_numNodes]; - for (int32 j = 0; j < aArray[i].m_numNodes; j++) { - ReadSaveBuf(&aArray[i].m_pNode[j], buf); - } - } -VALIDATESAVEBUF(size) -} - -void CScriptPaths::Save(uint8 *buf, uint32 *size) { - *size = SCRIPTPATHS_SAVE_SIZE; -INITSAVEBUF - for (int32 i = 0; i < 3; i++) { -#ifdef COMPATIBLE_SAVES - WriteSaveBuf(buf, aArray[i].m_numNodes); - ZeroSaveBuf(buf, 4); - WriteSaveBuf(buf, aArray[i].m_fTotalLength); - WriteSaveBuf(buf, aArray[i].m_fSpeed); - WriteSaveBuf(buf, aArray[i].m_fPosition); - WriteSaveBuf(buf, aArray[i].m_fObjectLength); - WriteSaveBuf(buf, aArray[i].m_state); -#else - CScriptPath *pPath = WriteSaveBuf(buf, aArray[i]); -#endif - - for (int32 j = 0; j < 6; j++) { -#ifdef COMPATIBLE_SAVES - WriteSaveBuf(buf, aArray[i].m_pObjects[j] != nil ? CPools::GetObjectPool()->GetJustIndex_NoFreeAssert(aArray[i].m_pObjects[j]) + 1 : 0); -#else - if (pPath->m_pObjects[j] != nil) - pPath->m_pObjects[j] = (CObject*)(CPools::GetObjectPool()->GetJustIndex_NoFreeAssert(pPath->m_pObjects[j]) + 1); -#endif - } - - for (int32 j = 0; j < aArray[i].m_numNodes; j++) { - WriteSaveBuf(buf, aArray[i].m_pNode[j]); - *size += sizeof(aArray[i].m_pNode[j]); - } - } -VALIDATESAVEBUF(*size); -} - -CObject *g_pScriptPathObjects[18]; - -void CScriptPaths::Load_ForReplay(void) { - for (int i = 0; i < 3; i++) { - for (int32 j = 0; j < 6; j++) { - aArray[i].m_pObjects[j] = g_pScriptPathObjects[6 * i + j]; - } - } -} - -void CScriptPaths::Save_ForReplay(void) { - for (int i = 0; i < 3; i++) { - for (int32 j = 0; j < 6; j++) { - g_pScriptPathObjects[6 * i + j] = aArray[i].m_pObjects[j]; - } - } -} diff --git a/src/render/Fluff.h b/src/render/Fluff.h deleted file mode 100644 index 58c8410c..00000000 --- a/src/render/Fluff.h +++ /dev/null @@ -1,205 +0,0 @@ -#pragma once -#include "common.h" -#include "Vector.h" -#include "Object.h" -#include "Plane.h" - -enum { - SCRIPT_PATH_DISABLED = 0, - SCRIPT_PATH_INITIALIZED, - SCRIPT_PATH_ACTIVE -}; - -class CScriptPath -{ -public: - int32 m_numNodes; - CPlaneNode *m_pNode; - float m_fTotalLength; - float m_fSpeed; - float m_fPosition; - float m_fObjectLength; - int32 m_state; - CObject *m_pObjects[6]; - - void Clear(void); - void Update(void); - void InitialiseOne(int32 numNodes, float length); - void FindCoorsFromDistanceOnPath(float t, float *pX, float *pY, float *pZ); - void SetObjectToControl(CObject *pObj); -}; - -class CScriptPaths -{ -public: - static CScriptPath aArray[3]; - static void Init(void); - static void Shutdown(void); - static void Update(void); - static bool IsOneActive(void); - static void Save(uint8 *buf, uint32 *size); - static void Load(uint8 *buf, uint32 size); - static void Save_ForReplay(); - static void Load_ForReplay(); -}; - -class CPlaneTrail -{ - CVector m_pos[16]; - int32 m_time[16]; -public: - void Init(void); - void Render(float visibility); - void RegisterPoint(CVector pos); -}; - -class CPlaneTrails -{ - static CPlaneTrail aArray[6]; // NB: 3 CPlanes and 3 hardcoded far away ones -public: - static void Init(void); - static void Update(void); - static void Render(void); - static void RegisterPoint(CVector pos, uint32 id); -}; - -class CPlaneBanner -{ - CVector m_pos[8]; -public: - void Init(void); - void Update(void); - void Render(void); - void RegisterPoint(CVector pos); -}; - -class CPlaneBanners -{ - static CPlaneBanner aArray[5]; -public: - static void Init(void); - static void Update(void); - static void Render(void); - static void RegisterPoint(CVector pos, uint32 id); -}; - -class CEscalator -{ - CVector m_pos0; - CVector m_pos1; - CVector m_pos2; - CVector m_pos3; - CMatrix m_matrix; - bool m_bIsActive; - bool m_bIsMovingDown; - int32 m_stepsCount; - float m_lowerEnd; - float m_upperEnd; - CVector m_midPoint; - float m_radius; - CObject *m_pSteps[24]; -public: - CEscalator(); - void Update(void); - void SwitchOff(void); - void AddThisOne(CVector pos0, CVector pos1, CVector pos2, CVector pos3, bool b_isMovingDown); - bool IsActive() const { return m_bIsActive; }; - const CVector& GetPosition() const { return m_midPoint; }; -}; - -class CEscalators -{ - static CEscalator aEscalators[NUM_ESCALATORS]; -public: - static int32 NumEscalators; - static void Init(void); - static void Update(void); - static void AddOne(CVector pos0, CVector pos1, CVector pos2, CVector pos3, bool b_isMovingDown); - static void Shutdown(void); - static const CEscalator& GetEscalator(int ind) { return aEscalators[ind]; }; -}; - -class CMovingThing -{ -public: - CMovingThing *m_pNext; - CMovingThing *m_pPrev; - int16 m_nType; - int16 m_farAway; - CVector m_vecPosn; - CEntity* m_pEntity; - - void Update(); - void AddToList(CMovingThing *pThing); - void RemoveFromList(); - int16 SizeList(); -}; - -#define NUMMOVINGTHINGS 48 - -class CMovingThings -{ -public: - static CMovingThing StartCloseList; - static CMovingThing EndCloseList; - static int16 Num; - static CMovingThing aMovingThings[NUMMOVINGTHINGS]; - - static void Init(); - static void Shutdown(); - static void Update(); - static void Render(); - static void PossiblyAddThisEntity(CEntity *pEnt); - static void RegisterOne(CEntity *pEnt, uint16 nType); -}; - -class CScrollBar -{ -private: - uint8 m_Counter; - const char* m_pMessage; - CVector m_Position; - uint32 m_MessageCurrentChar; - uint32 m_MessageLength; - CVector m_Size; - float m_fIntensity; - uint8 m_MessageBar[40]; - uint8 m_Type; - bool m_bVisible; - uint8 m_uRed; - uint8 m_uGreen; - uint8 m_uBlue; - float m_fScale; - -public: - static int TonightsEvent; - -public: - void SetVisibility(bool visible) { m_bVisible = visible; } - bool IsVisible() { return m_bVisible; } - - void Init(CVector pos1, CVector pos2, uint8 type, uint8 red, uint8 green, uint8 blue, float scale); - void Update(); - void Render(); -}; - -class CSmokeTrail { - CVector m_pos[16]; - float m_opacity[16]; - int m_time[16]; - char m_unused[536]; - int m_seed; -public: - void Render(void); - void RegisterPoint(CVector position, float a); - void Init(int num); -}; - -class CSmokeTrails { - static CSmokeTrail aSmoke[3]; -public: - static bool CigOn; - static void Update(void); - static void Render(void); - static void Init(void); -}; \ No newline at end of file diff --git a/src/render/Font.cpp b/src/render/Font.cpp deleted file mode 100644 index 9c499248..00000000 --- a/src/render/Font.cpp +++ /dev/null @@ -1,1938 +0,0 @@ -#include "common.h" - -#include "Sprite2d.h" -#include "TxdStore.h" -#include "Font.h" -#ifdef BUTTON_ICONS -#include "FileMgr.h" -#endif -#include "Timer.h" - -void -AsciiToUnicode(const char *src, wchar *dst) -{ - while((*dst++ = (unsigned char)*src++) != '\0'); -} - -void -UnicodeStrcat(wchar *dst, wchar *append) -{ - UnicodeStrcpy(&dst[UnicodeStrlen(dst)], append); -} - -void -UnicodeStrcpy(wchar *dst, const wchar *src) -{ - while((*dst++ = *src++) != '\0'); -} - -int -UnicodeStrlen(const wchar *str) -{ - int len; - for(len = 0; *str != '\0'; len++, str++); - return len; -} - -void -UnicodeMakeUpperCase(wchar *dst, const wchar *src) //idk what to do with it, seems to be incorrect implementation by R* -{ - while (*src != '\0') { - if (*src < 'a' || *src > 'z') - *dst = *src; - else - *dst = *src - 32; - dst++; - src++; - } - *dst = '\0'; -} - -CFontDetails CFont::Details; -int16 CFont::NewLine; -CSprite2d CFont::Sprite[MAX_FONTS]; -CFontRenderState CFont::RenderState; - -#ifdef MORE_LANGUAGES -uint8 CFont::LanguageSet = FONT_LANGSET_EFIGS; -int32 CFont::Slot = -1; -#define JAP_TERMINATION (0x8000 | '~') - -int16 CFont::Size[LANGSET_MAX][MAX_FONTS][210] = { - { -#else -int16 CFont::Size[MAX_FONTS][210] = { -#endif - { - //FONT2 EFIGS - //SPC,!, $, %, &, ', [, ], +, , -, ., - 12, 9, 22, 17, 19, 19, 25, 4, 33, 33, 25, 35, 11, 10, 6, 33, - //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ??, - 18, 10, 17, 17, 17, 17, 17, 15, 12, 16, 5, 30, 30, 30, 30, 30, - // A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, - 12, 16, 19, 16, 19, 18, 18, 17, 22, 11, 17, 18, 18, 30, 22, 19, - //P, Q, R, S, T, U, V, W, X, Y, Z, ??, ??, ??, ¡, \, - #ifdef FIX_BUGS - 22, 19, 19, 20, 18, 19, 19, 29, 19, 18, 19, 19, 33, 33, 10, 19, - #else - 22, 19, 19, 20, 18, 19, 19, 29, 19, 18, 19, 19, 33, 33, 19, 19, - #endif - //??,a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, - 12, 14, 11, 11, 16, 11, 12, 14, 14, 10, 13, 12, 10, 19, 18, 12, - //p, q, r, s, t, u, v, w, x, y, z, ??, ??, ??, ??, ??, - 16, 13, 13, 11, 12, 15, 12, 15, 13, 12, 12, 37, 33, 37, 35, 37, - //À, Á, Â, Ä, Æ, Ç, È, É, Ê, Ë, Ì, Í, Î, Ï, Ò, Ó, - 16, 16, 16, 16, 33, 17, 18, 18, 18, 18, 11, 11, 11, 11, 19, 19, - //Ô, Ö, Ù, Ú, Û, Ü, ß, à, á, â, ä, æ, ç, è, é, ê, - 19, 19, 19, 19, 19, 19, 15, 14, 14, 14, 14, 20, 14, 11, 11, 11, - //ë, ì, í, î, ï, ò, ó, ô, ö, ù, ú, û, ü, Ñ, ñ, ¿, - #ifdef FIX_BUGS - 11, 10, 10, 10, 10, 12, 12, 12, 12, 15, 15, 15, 15, 22, 18, 21, - #else - 11, 10, 10, 10, 10, 12, 12, 12, 12, 15, 15, 15, 15, 24, 18, 21, - #endif - //i,BLANKS - 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - //space, unprop - 19, 16 - }, - { - //FONT1 EFIGS - //Characters with a '2' refer to the Pricedown font. - //Characters that are referred as '*I' are characters that contain icons for PS2/XBOX, but contain regular characters on PC - //in order to display them properly in the Keyboard controls menu. - //!2,!, *I,(R), $, %, &, ', [, ], *I, +, , -, ., *I, - 15, 7, 31, 25, 20, 23, 21, 7, 11, 10, 26, 14, 6, 12, 6, 26, - //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, *I, *I, *I, *I, ?, - 20, 7, 20, 20, 21, 20, 20, 19, 21, 20, 8, 30, 24, 30, 24, 19, - //TM,A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, - 20, 22, 22, 21, 22, 18, 18, 22, 22, 9, 14, 21, 18, 27, 21, 24, - //P, Q, R, S, T, U, V, W, X, Y, Z, *I, \, *I, ¡, °, - #ifdef FIX_BUGS - 22, 22, 23, 20, 19, 23, 22, 31, 23, 23, 21, 25, 13, 30, 7, 19, - #else - 22, 22, 23, 20, 19, 23, 22, 31, 23, 23, 21, 25, 13, 30, 10, 19, - #endif - //(C),a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, - 10, 17, 17, 16, 17, 17, 11, 17, 17, 7, 7, 18, 7, 25, 17, 17, - //p, q, r, s, t, u, v, w, x, y, z, *I, *I, $2, (2, )2, - 17, 17, 11, 17, 11, 17, 18, 25, 19, 18, 17, 28, 26, 20, 15, 15, - //À, Á, Â, Ä, Æ, Ç, È, É, Ê, Ë, Ì, Í, Î, Ï, Ò, Ó, - 20, 20, 20, 20, 29, 22, 19, 19, 19, 19, 9, 9, 9, 9, 23, 23, - //Ô, Ö, Ù, Ú, Û, Ü, ß, à, á, â, ä, æ, ç, è, é, ê, - 23, 23, 24, 24, 24, 24, 20, 19, 17, 17, 17, 30, 16, 17, 17, 17, - //ë, ì, í, î, ï, ò, ó, ô, ö, ù, ú, û, ü, Ñ, ñ, ¿, - #ifdef FIX_BUGS - 17, 11, 11, 15, 12, 17, 17, 17, 17, 17, 17, 17, 17, 21, 17, 19, - #else - 17, 11, 11, 15, 12, 17, 17, 17, 17, 17, 17, 17, 17, 19, 20, 20, - #endif - //02,12,22, 32, 42, 52, 62, 72, 82, 92, :2, A2, B2, C2, D2, E2, - 20, 18, 19, 19, 21, 19, 19, 19, 19, 19, 16, 19, 19, 19, 20, 19, - //F2,G2,H2, I2, J2, K2, L2, M2, N2, O2, P2, Q2, R2, S2, T2, U2, - 16, 19, 19, 9, 19, 20, 14, 29, 19, 19, 19, 19, 19, 19, 21, 19, - //V2,W2,X2, Y2, Z2, À2, Á2, Â2, Ä2, Æ2, Ç2, È2, É2, Ê2, Ë2, Ì2, - 20, 32, 20, 19, 19, 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, - //Í2,Î2,Ï2, Ò2, Ó2, Ô2, Ö2, Ù2, Ú2, Û2, Ü2, ß2, Ñ2, ¿2, '2, .2, - #ifdef FIX_BUGS - 9, 9, 9, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 10, 9, - #else - 9, 9, 9, 19, 19, 19, 19, 19, 19, 19, 19, 19, 21, 21, 10, 9, - #endif - //space, unprop - 10, 20 - } - -#ifdef MORE_LANGUAGES - }, - { - { - 5, 9, 9, 0, 17, 17, 23, 3, 21, 18, 0, 8, 3, 8, 3, 0, - 16, 9, 16, 16, 15, 19, 15, 14, 17, 17, 4, 4, 0, 0, 0, 17, - 19, 17, 19, 15, 21, 18, 19, 16, 21, 13, 15, 21, 20, 28, 21, 18, - 22, 17, 21, 20, 18, 18, 20, 26, 22, 18, 18, 0, 8, 0, 9, 8, - 0, 14, 11, 12, 16, 11, 13, 13, 15, 10, 14, 15, 11, 21, 17, 10, - 20, 15, 12, 12, 16, 17, 13, 16, 13, 21, 11, 0, 0, 0, 0, 0, - 20, 19, 19, 22, 27, 15, 18, 18, 20, 26, 21, 23, 17, 22, 21, 17, - 26, 25, 26, 17, 20, 26, 17, 16, 11, 12, 13, 21, 11, 17, 17, 12, - 21, 17, 17, 15, 24, 16, 10, 20, 23, 16, 7, 9, 16, 23, 12, 11, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, - 19, 16 - }, - { - 11, 5, 10, 15, 19, 22, 20, 5, 9, 8, 11, 12, 5, 12, 6, 12, - 19, 5, 18, 19, 20, 18, 19, 18, 20, 19, 5, 6, 26, 12, 30, 19, - 23, 21, 20, 20, 20, 16, 16, 21, 19, 5, 13, 19, 16, 24, 20, 21, - 20, 21, 20, 19, 17, 20, 21, 30, 22, 21, 20, 25, 13, 30, 5, 9, - 10, 15, 15, 14, 15, 16, 10, 15, 15, 5, 5, 15, 5, 23, 15, 16, - 15, 15, 9, 16, 10, 15, 17, 24, 18, 15, 15, 27, 5, 19, 2, 2, - 20, 20, 16, 23, 30, 19, 20, 20, 21, 24, 19, 19, 20, 23, 22, 19, - 27, 29, 25, 20, 20, 28, 24, 16, 16, 14, 19, 25, 16, 16, 16, 17, - 19, 16, 16, 17, 25, 19, 15, 23, 26, 21, 16, 14, 22, 20, 16, 19, - 15, 14, 15, 16, 17, 15, 15, 15, 15, 15, 7, 15, 15, 15, 15, 15, - 13, 15, 15, 7, 15, 16, 13, 23, 15, 15, 15, 15, 15, 15, 17, 15, - 16, 24, 17, 17, 17, 15, 15, 13, 20, 23, 15, 17, 17, 16, 24, 15, - 15, 15, 23, 18, 15, 23, 26, 23, 16, 15, 23, 15, 15, 19, 2, 2, - 10, 20 - }, - }, - { - { - //FONT2 EFIGS - //SPC,!, $, %, &, ', [, ], +, , -, ., - 12, 9, 22, 17, 19, 19, 25, 4, 33, 33, 25, 35, 11, 10, 6, 33, - //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ??, - 18, 10, 17, 17, 17, 17, 17, 15, 12, 16, 5, 30, 30, 30, 30, 30, - // A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, - 12, 16, 19, 16, 19, 18, 18, 17, 22, 11, 17, 18, 18, 30, 22, 19, - //P, Q, R, S, T, U, V, W, X, Y, Z, ??, ??, ??, ¡, \, - 22, 19, 19, 20, 18, 19, 19, 29, 19, 18, 19, 19, 33, 33, 10, 19, - //??,a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, - 12, 14, 11, 11, 16, 11, 12, 14, 14, 10, 13, 12, 10, 19, 18, 12, - //p, q, r, s, t, u, v, w, x, y, z, ??, ??, ??, ??, ??, - 16, 13, 13, 11, 12, 15, 12, 15, 13, 12, 12, 37, 33, 37, 35, 37, - //À, Á, Â, Ä, Æ, Ç, È, É, Ê, Ë, Ì, Í, Î, Ï, Ò, Ó, - 16, 16, 16, 16, 33, 17, 18, 18, 18, 18, 11, 11, 11, 11, 19, 19, - //Ô, Ö, Ù, Ú, Û, Ü, ß, à, á, â, ä, æ, ç, è, é, ê, - 19, 19, 19, 19, 19, 19, 15, 14, 14, 14, 14, 20, 14, 11, 11, 11, - //ë, ì, í, î, ï, ò, ó, ô, ö, ù, ú, û, ü, Ñ, ñ, ¿, - 11, 10, 10, 10, 10, 12, 12, 12, 12, 15, 15, 15, 15, 22, 18, 21, - //i,BLANKS - 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - //space, unprop - 19, 16 - }, - { - //FONT1 EFIGS - //Characters with a '2' refer to the Pricedown font. - //Characters that are referred as '*I' are characters that contain icons for PS2/XBOX, but contain regular characters on PC - //in order to display them properly in the Keyboard controls menu. - //!2,!, *I,(R), $, %, &, ', [, ], *I, +, , -, ., *I, - 15, 7, 31, 25, 20, 23, 21, 7, 11, 10, 26, 14, 6, 12, 6, 26, - //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, *I, *I, *I, *I, ?, - 20, 7, 20, 20, 21, 20, 20, 19, 21, 20, 8, 30, 24, 30, 24, 19, - //TM,A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, - 20, 22, 22, 21, 22, 18, 18, 22, 22, 9, 14, 21, 18, 27, 21, 24, - //P, Q, R, S, T, U, V, W, X, Y, Z, *I, \, *I, ¡, °, - 22, 22, 23, 20, 19, 23, 22, 31, 23, 23, 21, 25, 13, 30, 7, 19, - //(C),a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, - 10, 17, 17, 16, 17, 17, 11, 17, 17, 7, 7, 18, 7, 25, 17, 17, - //p, q, r, s, t, u, v, w, x, y, z, *I, *I, $2, (2, )2, - 17, 17, 11, 17, 11, 17, 18, 25, 19, 18, 17, 28, 26, 20, 15, 15, - //À, Á, Â, Ä, Æ, Ç, È, É, Ê, Ë, Ì, Í, Î, Ï, Ò, Ó, - 20, 20, 20, 20, 29, 22, 19, 19, 19, 19, 9, 9, 9, 9, 23, 23, - //Ô, Ö, Ù, Ú, Û, Ü, ß, à, á, â, ä, æ, ç, è, é, ê, - 23, 23, 24, 24, 24, 24, 20, 19, 17, 17, 17, 30, 16, 17, 17, 17, - //ë, ì, í, î, ï, ò, ó, ô, ö, ù, ú, û, ü, Ñ, ñ, ¿, - 17, 11, 11, 15, 12, 17, 17, 17, 17, 17, 17, 17, 17, 21, 17, 19, - //02,12,22, 32, 42, 52, 62, 72, 82, 92, :2, A2, B2, C2, D2, E2, - 20, 18, 19, 19, 21, 19, 19, 19, 19, 19, 16, 19, 19, 19, 20, 19, - //F2,G2,H2, I2, J2, K2, L2, M2, N2, O2, P2, Q2, R2, S2, T2, U2, - 16, 19, 19, 9, 19, 20, 14, 29, 19, 19, 19, 19, 19, 19, 21, 19, - //V2,W2,X2, Y2, Z2, À2, Á2, Â2, Ä2, Æ2, Ç2, È2, É2, Ê2, Ë2, Ì2, - 20, 32, 20, 19, 19, 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, - //Í2,Î2,Ï2, Ò2, Ó2, Ô2, Ö2, Ù2, Ú2, Û2, Ü2, ß2, Ñ2, ¿2, '2, .2, - 9, 9, 9, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 10, 9, - //space, unprop - 10, 20 - } - } -#endif -}; - -#ifdef MORE_LANGUAGES -int16 Size_jp[] = { - 15, 14, 16, 20, 19, 26, 22, 11, 18, 18, 27, 26, 13, //; 0 - 19, 20, 27, 19, 15, 19, 19, 21, 19, 20, 18, 19, 15, //; 13 - 13, 28, 15, 32, 15, 35, 15, 19, 19, 19, 19, 17, 16, //; 26 - 19, 20, 15, 19, 20, 14, 17, 19, 19, 19, 19, 19, 19, //; 39 - 19, 19, 20, 25, 20, 19, 19, 33, 31, 39, 37, 39, 37, //; 52 - 21, 21, 21, 19, 17, 15, 23, 21, 15, 19, 20, 16, 19, //; 65 - 19, 19, 20, 20, 17, 22, 19, 22, 22, 19, 22, 22, 23, //; 78 - 35, 35, 35, 35, 37, 19, 19, 19, 19, 29, 19, 19, 19, //; 91 - 19, 19, 9, 9, 9, 9, 19, 19, 19, 19, 19, 19, 19, 19, //; 104 - 19, 19, 19, 19, 19, 30, 19, 19, 19, 19, 19, 10, 10, //; 118 - 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35, //; 131 - 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 144 - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 157 - 19, 19, 19, 11, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 170 - 19, 19, 19, 19, 19, 19, 19, 19, 19, 21 -}; -#endif - -wchar foreign_table[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 176, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 177, 0, 0, 0, 0, 0, 95, 0, 0, 0, 0, 175, - 128, 129, 130, 0, 131, 0, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, - 0, 173, 142, 143, 144, 0, 145, 0, 0, 146, 147, 148, 149, 0, 0, 150, - 151, 152, 153, 0, 154, 0, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, - 0, 174, 165, 166, 167, 0, 168, 0, 0, 169, 170, 171, 172, 0, 0, 0, -}; - -union tFontRenderStatePointer -{ - CFontRenderState *pRenderState; - wchar *pStr; - - void Align() - { - if ((uintptr)pStr % 4) - pStr++; - } -}; - -tFontRenderStatePointer FontRenderStatePointer; -uint8 FontRenderStateBuf[1024]; - -#ifdef BUTTON_ICONS -CSprite2d CFont::ButtonSprite[MAX_BUTTON_ICONS]; -int CFont::PS2Symbol = BUTTON_NONE; -int CFont::ButtonsSlot = -1; -#endif // BUTTON_ICONS - -void -CFont::Initialise(void) -{ - int slot; - - slot = CTxdStore::AddTxdSlot("fonts"); -#ifdef MORE_LANGUAGES - Slot = slot; - switch (LanguageSet) - { - case FONT_LANGSET_EFIGS: - default: - CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD"); - break; - case FONT_LANGSET_POLISH: - CTxdStore::LoadTxd(slot, "MODELS/FONTS_P.TXD"); - break; - case FONT_LANGSET_RUSSIAN: - CTxdStore::LoadTxd(slot, "MODELS/FONTS_R.TXD"); - break; - case FONT_LANGSET_JAPANESE: - CTxdStore::LoadTxd(slot, "MODELS/FONTS_J.TXD"); - break; - } -#else - CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD"); -#endif - CTxdStore::AddRef(slot); - CTxdStore::PushCurrentTxd(); - CTxdStore::SetCurrentTxd(slot); - Sprite[0].SetTexture("font2", "font2m"); -#ifdef MORE_LANGUAGES - if (IsJapanese()) { - Sprite[1].SetTexture("FONTJAP", "FONTJAP_mask"); - Sprite[3].SetTexture("FONTJAP", "FONTJAP_mask"); - } -#endif // MORE_LANGUAGES - Sprite[1].SetTexture("font1", "font1m"); - SetScale(1.0f, 1.0f); - SetSlantRefPoint(SCREEN_WIDTH, 0.0f); - SetSlant(0.0f); - SetColor(CRGBA(255, 255, 255, 0)); - SetJustifyOff(); - SetCentreOff(); - SetWrapx(SCREEN_WIDTH); - SetCentreSize(SCREEN_WIDTH); - SetBackgroundOff(); - SetBackgroundColor(CRGBA(128, 128, 128, 128)); - SetBackGroundOnlyTextOff(); - SetPropOn(); - SetFontStyle(FONT_BANK); - SetRightJustifyWrap(0.0f); - SetAlphaFade(255.0f); - SetDropShadowPosition(0); - CTxdStore::PopCurrentTxd(); - -#if !defined(GAMEPAD_MENU) && defined(BUTTON_ICONS) - // loaded in CMenuManager with GAMEPAD_MENU defined - LoadButtons("MODELS/X360BTNS.TXD"); -#endif -} - -#ifdef BUTTON_ICONS -void -CFont::LoadButtons(const char *txdPath) -{ - if (int file = CFileMgr::OpenFile(txdPath)) { - CFileMgr::CloseFile(file); - if (ButtonsSlot == -1) - ButtonsSlot = CTxdStore::AddTxdSlot("buttons"); - else { - for (int i = 0; i < MAX_BUTTON_ICONS; i++) - ButtonSprite[i].Delete(); - CTxdStore::RemoveTxd(ButtonsSlot); - } - CTxdStore::LoadTxd(ButtonsSlot, txdPath); - CTxdStore::AddRef(ButtonsSlot); - CTxdStore::PushCurrentTxd(); - CTxdStore::SetCurrentTxd(ButtonsSlot); - ButtonSprite[BUTTON_UP].SetTexture("thumblyu"); - ButtonSprite[BUTTON_DOWN].SetTexture("thumblyd"); - ButtonSprite[BUTTON_LEFT].SetTexture("thumblxl"); - ButtonSprite[BUTTON_RIGHT].SetTexture("thumblxr"); - ButtonSprite[BUTTON_CROSS].SetTexture("cross"); - ButtonSprite[BUTTON_CIRCLE].SetTexture("circle"); - ButtonSprite[BUTTON_SQUARE].SetTexture("square"); - ButtonSprite[BUTTON_TRIANGLE].SetTexture("triangle"); - ButtonSprite[BUTTON_L1].SetTexture("l1"); - ButtonSprite[BUTTON_L2].SetTexture("l2"); - ButtonSprite[BUTTON_L3].SetTexture("l3"); - ButtonSprite[BUTTON_R1].SetTexture("r1"); - ButtonSprite[BUTTON_R2].SetTexture("r2"); - ButtonSprite[BUTTON_R3].SetTexture("r3"); - ButtonSprite[BUTTON_RSTICK_UP].SetTexture("thumbryu"); - ButtonSprite[BUTTON_RSTICK_DOWN].SetTexture("thumbryd"); - ButtonSprite[BUTTON_RSTICK_LEFT].SetTexture("thumbrxl"); - ButtonSprite[BUTTON_RSTICK_RIGHT].SetTexture("thumbrxr"); - CTxdStore::PopCurrentTxd(); - } - else { - if (ButtonsSlot != -1) { - for (int i = 0; i < MAX_BUTTON_ICONS; i++) - ButtonSprite[i].Delete(); - CTxdStore::RemoveTxdSlot(ButtonsSlot); - ButtonsSlot = -1; - } - } -} -#endif // BUTTON_ICONS - -#ifdef MORE_LANGUAGES -void -CFont::ReloadFonts(uint8 set) -{ - if (Slot != -1 && LanguageSet != set) { - Sprite[0].Delete(); - Sprite[1].Delete(); - if (IsJapanese()) - Sprite[2].Delete(); - CTxdStore::PushCurrentTxd(); - CTxdStore::RemoveTxd(Slot); - switch (set) - { - case FONT_LANGSET_EFIGS: - default: - CTxdStore::LoadTxd(Slot, "MODELS/FONTS.TXD"); - break; - case FONT_LANGSET_POLISH: - CTxdStore::LoadTxd(Slot, "MODELS/FONTS_P.TXD"); - break; - case FONT_LANGSET_RUSSIAN: - CTxdStore::LoadTxd(Slot, "MODELS/FONTS_R.TXD"); - break; - case FONT_LANGSET_JAPANESE: - CTxdStore::LoadTxd(Slot, "MODELS/FONTS_J.TXD"); - break; - } - CTxdStore::SetCurrentTxd(Slot); - Sprite[0].SetTexture("font2", "font2_mask"); - if (set == FONT_LANGSET_JAPANESE) { - Sprite[2].SetTexture("FONTJAP", "FONTJAP_mask"); - } - Sprite[1].SetTexture("font1", "font1_mask"); - CTxdStore::PopCurrentTxd(); - } - LanguageSet = set; -} -#endif - -void -CFont::Shutdown(void) -{ -#ifdef BUTTON_ICONS - if (ButtonsSlot != -1) { - for (int i = 0; i < MAX_BUTTON_ICONS; i++) - ButtonSprite[i].Delete(); - CTxdStore::RemoveTxdSlot(ButtonsSlot); - ButtonsSlot = -1; - } -#endif - Sprite[0].Delete(); - Sprite[1].Delete(); -#ifdef MORE_LANGUAGES - if (IsJapanese()) - Sprite[3].Delete(); - CTxdStore::RemoveTxdSlot(Slot); - Slot = -1; -#else - CTxdStore::RemoveTxdSlot(CTxdStore::FindTxdSlot("fonts")); -#endif -} - -void -CFont::InitPerFrame(void) -{ - RenderState.style = -1; - Details.anonymous_25 = 0; - FontRenderStatePointer.pRenderState = (CFontRenderState*)FontRenderStateBuf; - SetDropShadowPosition(0); - NewLine = false; -#ifdef BUTTON_ICONS - PS2Symbol = BUTTON_NONE; -#endif -} - -#ifdef BUTTON_ICONS -void -CFont::DrawButton(float x, float y) -{ - if (x <= 0.0f || x > SCREEN_WIDTH || y <= 0.0f || y > SCREEN_HEIGHT) - return; - - if (PS2Symbol != BUTTON_NONE) { - CRect rect; - rect.left = x; - rect.top = RenderState.scaleY + RenderState.scaleY + y; - rect.right = RenderState.scaleY * 17.0f + x; - rect.bottom = RenderState.scaleY * 19.0f + y; - - int vertexAlphaState; - void *raster; - RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &vertexAlphaState); - RwRenderStateGet(rwRENDERSTATETEXTURERASTER, &raster); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); - if (RenderState.bIsShadow) - ButtonSprite[PS2Symbol].Draw(rect, RenderState.color); - else - ButtonSprite[PS2Symbol].Draw(rect, CRGBA(255, 255, 255, RenderState.color.a)); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, raster); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)vertexAlphaState); - } -} -#endif - -void -CFont::PrintChar(float x, float y, wchar c) -{ - bool bDontPrint = false; - if(x <= 0.0f || x > SCREEN_WIDTH || - y <= 0.0f || y > SCREEN_HEIGHT) // BUG: game uses SCREENW again - return; - - bDontPrint = c == '\0'; - float w = GetCharacterWidth(c) / 32.0f; - if (Details.bFontHalfTexture && c == 208) - c = '\0'; - float xoff = c % 16; - float yoff = c / 16; -#ifdef MORE_LANGUAGES - if (IsJapaneseFont()) { - w = 21.0f; - xoff = (float)(c % 48); - yoff = c / 48; - } -#endif - - if(RenderState.style == FONT_BANK || RenderState.style == FONT_STANDARD){ - if (bDontPrint) return; - if (RenderState.slant == 0.0f) { -#ifdef FIX_BUGS - if (c < 192) { -#else - if (c < 193) { -#endif - CSprite2d::AddToBuffer( - CRect(x, y, - x + 32.0f * RenderState.scaleX * 1.0f, - y + 40.0f * RenderState.scaleY * 0.5f), - RenderState.color, - xoff / 16.0f, yoff / 12.8f + 0.0021f, - (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f, - xoff / 16.0f, (yoff + 1.0f) / 12.8f - 0.0021f, - (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f - 0.0021f); - } else { - CSprite2d::AddToBuffer( - CRect(x, y, - x + 32.0f * RenderState.scaleX * 1.0f, - y + 33.0f * RenderState.scaleY * 0.5f), - RenderState.color, - xoff / 16.0f, yoff / 12.8f + 0.0021f, - (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f, - xoff / 16.0f, (yoff + 1.0f) / 12.8f - 0.017f, - (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f - 0.017f); - } - } else - CSprite2d::AddToBuffer( - CRect(x, y, - x + 32.0f * RenderState.scaleX * 1.0f, - y + 40.0f * RenderState.scaleY * 0.5f), - RenderState.color, - xoff / 16.0f, yoff / 12.8f + 0.00055f, - (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f + 0.01f, - xoff / 16.0f, (yoff + 1.0f) / 12.8f - 0.009f, - (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f - 0.0021f + 0.01f); -#ifdef MORE_LANGUAGES - /*}else if (IsJapaneseFont()) { - if (Details.dropShadowPosition != 0) { - CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank - CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition), - y + SCREEN_SCALE_Y(Details.dropShadowPosition), - x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f, - y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY / 2.75f), - Details.dropColor, - xoff * w / 1024.0f, yoff / 25.6f, - xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, yoff / 25.6f, - xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f, - xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f); - } - CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank - CRect(x, y, - x + 32.0f * Details.scaleX * 1.0f, - y + 40.0f * Details.scaleY / 2.75f), - Details.color, - xoff * w / 1024.0f, yoff / 25.6f, - xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, yoff / 25.6f, - xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f - 0.002f, - xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f);*/ -#endif - } else { - if (bDontPrint) return; - CSprite2d::AddToBuffer( - CRect(x, y, - x + 32.0f * RenderState.scaleX * w, - y + 32.0f * RenderState.scaleY * 0.5f), - RenderState.color, - xoff / 16.0f, yoff / 16.0f, - (xoff + w) / 16.0f, yoff / 16.0f, - xoff / 16.0f, (yoff + 1.0f) / 16.0f, - (xoff + w) / 16.0f - 0.0001f, (yoff + 1.0f) / 16.0f - 0.0001f); - } -} - -#ifdef MORE_LANGUAGES -bool CFont::IsJapanesePunctuation(wchar *str) -{ - return (*str == 0xE7 || *str == 0x124 || *str == 0x126 || *str == 0x128 || *str == 0x104 || *str == ',' || *str == '>' || *str == '!' || *str == 0x99 || *str == '?' || *str == ':'); -} - -bool CFont::IsAnsiCharacter(wchar *s) -{ - if (*s >= 'A' && *s <= 'Z') - return true; - if (*s >= 'a' && *s <= 'z') - return true; - if (*s >= '0' && *s <= ':') - return true; - if (*s == '(' || *s == ')') - return true; - if (*s == 'D' || *s == '$') - return true; - return false; -} -#endif - -void -CFont::RenderFontBuffer() -{ - if (FontRenderStatePointer.pRenderState == (CFontRenderState*)FontRenderStateBuf) return; - - float textPosX; - float textPosY; - CRGBA color; - bool bBold = false; - bool bFlash = false; - - Sprite[RenderState.style].SetRenderState(); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RenderState = *(CFontRenderState*)&FontRenderStateBuf[0]; - textPosX = RenderState.fTextPosX; - textPosY = RenderState.fTextPosY; - color = RenderState.color; - tFontRenderStatePointer pRenderStateBufPointer; - pRenderStateBufPointer.pRenderState = (CFontRenderState*)&FontRenderStateBuf[0]; - for (++pRenderStateBufPointer.pRenderState; pRenderStateBufPointer.pStr < FontRenderStatePointer.pStr; pRenderStateBufPointer.pStr++) { - if (*pRenderStateBufPointer.pStr == '\0') { - tFontRenderStatePointer tmpPointer = pRenderStateBufPointer; - tmpPointer.pStr++; - tmpPointer.Align(); - if (tmpPointer.pStr >= FontRenderStatePointer.pStr) - break; - - RenderState = *(tmpPointer.pRenderState++); - - pRenderStateBufPointer = tmpPointer; - - textPosX = RenderState.fTextPosX; - textPosY = RenderState.fTextPosY; - color = RenderState.color; - } - if (*pRenderStateBufPointer.pStr == '~') { -#ifdef BUTTON_ICONS - PS2Symbol = BUTTON_NONE; -#endif - pRenderStateBufPointer.pStr = ParseToken(pRenderStateBufPointer.pStr, color, bFlash, bBold); -#ifdef BUTTON_ICONS - if(PS2Symbol != BUTTON_NONE) { - DrawButton(textPosX, textPosY); - textPosX += RenderState.scaleY * 17.0f; - PS2Symbol = BUTTON_NONE; - } -#endif - if (bFlash) { - if (CTimer::GetTimeInMilliseconds() - Details.nFlashTimer > 300) { - Details.bFlashState = !Details.bFlashState; - Details.nFlashTimer = CTimer::GetTimeInMilliseconds(); - } - Details.color.alpha = Details.bFlashState ? 0 : 255; - } - if (!RenderState.bIsShadow) - RenderState.color = color; - } - wchar c = *pRenderStateBufPointer.pStr; - c -= ' '; - if (RenderState.bFontHalfTexture) - c = FindNewCharacter(c); - else if (c > 155) - c = '\0'; - - if (RenderState.slant != 0.0f) - textPosY = (RenderState.slantRefX - textPosX) * RenderState.slant + RenderState.slantRefY; - PrintChar(textPosX, textPosY, c); - if (bBold) { - PrintChar(textPosX + 1.0f, textPosY, c); - PrintChar(textPosX + 2.0f, textPosY, c); - textPosX += 2.0f; - } -#ifdef FIX_BUGS - // PS2 uses different chars for some symbols - if (!RenderState.bFontHalfTexture && c == 30) c = 61; // wanted star -#endif - textPosX += RenderState.scaleX * GetCharacterWidth(c); - if (c == '\0') - textPosX += RenderState.fExtraSpace; - } - CSprite2d::RenderVertexBuffer(); - FontRenderStatePointer.pRenderState = (CFontRenderState*)FontRenderStateBuf; -} - -#if 0 //def MORE_LANGUAGES -bool -CFont::PrintString(float x, float y, wchar *start, wchar *&end, float spwidth, float japX) -{ - wchar *s, c, unused; - - if (IsJapanese()) { - float jx = 0.0f; - for (s = start; s < end; s++) { - if (*s == JAP_TERMINATION || *s == '~') - s = ParseToken(s, &unused, true); - if (NewLine) { - NewLine = false; - break; - } - jx += GetCharacterSize(*s - ' '); - } - s = start; - if (Details.centre) - x = japX - jx / 2.0f; - else if (Details.rightJustify) - x = japX - jx; - } - - for (s = start; s < end; s++) { - if (*s == '~' || (IsJapanese() && *s == JAP_TERMINATION)) - s = ParseToken(s, &unused); - if (NewLine && IsJapanese()) { - NewLine = false; - end = s; - return true; - } - c = *s - ' '; - if (Details.slant != 0.0f && !IsJapanese()) - y = (Details.slantRefX - x) * Details.slant + Details.slantRefY; - - PrintChar(x, y, c); - x += GetCharacterSize(c); - if (c == 0 && (!NewLine || !IsJapanese())) // space - x += spwidth; - } - return false; -} -#else -void -CFont::PrintString(float x, float y, uint32, wchar *start, wchar *end, float spwidth) -{ - wchar *s; - - if (RenderState.style != Details.style) { - RenderFontBuffer(); - RenderState.style = Details.style; - } - - float dropShadowPosition = Details.dropShadowPosition; - if (dropShadowPosition != 0.0f && (Details.style == FONT_BANK || Details.style == FONT_STANDARD)) { - CRGBA color = Details.color; - Details.color = Details.dropColor; - Details.dropShadowPosition = 0; - Details.bIsShadow = true; - if (Details.slant != 0.0f) { - Details.slantRefX += SCREEN_SCALE_X(dropShadowPosition); - Details.slantRefY += SCREEN_SCALE_Y(dropShadowPosition); - PrintString(SCREEN_SCALE_X(dropShadowPosition) + x, SCREEN_SCALE_Y(dropShadowPosition) + y, Details.anonymous_25, start, end, spwidth); - Details.slantRefX -= SCREEN_SCALE_X(dropShadowPosition); - Details.slantRefY -= SCREEN_SCALE_Y(dropShadowPosition); - } else { - PrintString(SCREEN_SCALE_X(dropShadowPosition) + x, SCREEN_SCALE_Y(dropShadowPosition) + y, Details.anonymous_25, start, end, spwidth); - } - Details.color = color; - Details.dropShadowPosition = dropShadowPosition; - Details.bIsShadow = false; - } - if (FontRenderStatePointer.pStr >= (wchar*)&FontRenderStateBuf[ARRAY_SIZE(FontRenderStateBuf)] - (end - start + 26)) // why 26? - RenderFontBuffer(); - CFontRenderState *pRenderState = FontRenderStatePointer.pRenderState; - pRenderState->fTextPosX = x; - pRenderState->fTextPosY = y; - pRenderState->scaleX = Details.scaleX; - pRenderState->scaleY = Details.scaleY; - pRenderState->color = Details.color; - pRenderState->fExtraSpace = spwidth; - pRenderState->slant = Details.slant; - pRenderState->slantRefX = Details.slantRefX; - pRenderState->slantRefY = Details.slantRefY; - pRenderState->bFontHalfTexture = Details.bFontHalfTexture; - pRenderState->proportional = Details.proportional; - pRenderState->style = Details.style; - pRenderState->bIsShadow = Details.bIsShadow; - FontRenderStatePointer.pRenderState++; - - for(s = start; s < end;){ - if (*s == '~') { - for (wchar *i = ParseToken(s); s != i; FontRenderStatePointer.pStr++) { - *FontRenderStatePointer.pStr = *(s++); - } - if (Details.bFlash) { - if (CTimer::GetTimeInMilliseconds() - Details.nFlashTimer > 300) { - Details.bFlashState = !Details.bFlashState; - Details.nFlashTimer = CTimer::GetTimeInMilliseconds(); - } - Details.color.a = Details.bFlashState ? 0 : 255; - } - } else - *(FontRenderStatePointer.pStr++) = *(s++); - } - *(FontRenderStatePointer.pStr++) = '\0'; - FontRenderStatePointer.Align(); -} -#endif - -void -CFont::PrintStringFromBottom(float x, float y, wchar *str) -{ - y -= (32.0f * Details.scaleY / 2.0f + 2.0f * Details.scaleY) * GetNumberLines(x, y, str); - if (Details.slant != 0.0f) - y -= ((Details.slantRefX - x) * Details.slant + Details.slantRefY); - PrintString(x, y, str); -} - -void -CFont::PrintString(float xstart, float ystart, wchar *s) -{ - CRect rect; - int numSpaces; - float lineLength; - float x, y; - bool first; - wchar *start, *t; - - Details.bFlash = false; - - if(*s == '*') - return; - - Details.anonymous_25++; - if(Details.background){ - RenderState.color = Details.color; - GetNumberLines(xstart, ystart, s); // BUG: result not used - GetTextRect(&rect, xstart, ystart, s); - CSprite2d::DrawRect(rect, Details.backgroundColor); - } - - lineLength = 0.0f; - numSpaces = 0; - first = true; - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - y = ystart; - start = s; - - // This is super ugly, I blame R* - for(;;){ - for(;;){ - for(;;){ - if(*s == '\0') - return; - float xend = Details.centre ? Details.centreSize : - Details.rightJustify ? xstart - Details.rightJustifyWrap : - Details.wrapX; -#ifdef MORE_LANGUAGES - if (IsJapaneseFont()) - xend -= SCREEN_SCALE_X(21.0f * 2.0f); -#endif - if(x + GetStringWidth(s) > xend && !first){ -#ifdef MORE_LANGUAGES - if (IsJapanese() && IsJapanesePunctuation(s)) - s--; -#endif - // flush line - float spaceWidth = !Details.justify || Details.centre ? 0.0f : - (Details.wrapX - lineLength) / numSpaces; - float xleft = Details.centre ? xstart - x/2 : - Details.rightJustify ? xstart - x : - xstart; -#if 0//def MORE_LANGUAGES - PrintString(xleft, y, start, s, spaceWidth, xstart); -#else - PrintString(xleft, y, Details.anonymous_25, start, s, spaceWidth); -#endif - // reset things - lineLength = 0.0f; - numSpaces = 0; - first = true; - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; -#ifdef MORE_LANGUAGES - if (IsJapaneseFont()) - y += 32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY; - else -#endif - y += 32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY; - start = s; - }else - break; - } - // advance by one word - t = GetNextSpace(s); - if(t[0] == '\0' || - t[0] == ' ' && t[1] == '\0') - break; - if(!first) - numSpaces++; - first = false; - x += GetStringWidth(s) + GetCharacterSize(*t - ' '); -#ifdef MORE_LANGUAGES - if (IsJapaneseFont() && IsAnsiCharacter(s)) - x += 21.0f; -#endif - lineLength = x; - s = t+1; -#if 0 //def MORE_LANGUAGES - if (IsJapaneseFont() && !*s) { - x += GetStringWidth(s); - if (IsAnsiCharacter(s)) - x += 21.0f; - float xleft = Details.centre ? xstart - x / 2 : - Details.rightJustify ? xstart - x : - xstart; - if (PrintString(xleft, y, start, s, 0.0f, xstart)) - { - start = s; - if (!Details.centre && !Details.rightJustify) - x = xstart; - else - x = 0.0f; - - y += 32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY; - numSpaces = 0; - first = true; - lineLength = 0.0f; - } - } -#endif - } - // print rest - if(t[0] == ' ' && t[1] == '\0') - t[0] = '\0'; - x += GetStringWidth(s); - s = t; - float xleft = Details.centre ? xstart - x/2 : - Details.rightJustify ? xstart - x : - xstart; -#if 0 //def MORE_LANGUAGES - if (PrintString(xleft, y, start, s, 0.0f, xstart) && IsJapaneseFont()) { - start = s; - if (!Details.centre && !Details.rightJustify) - x = xstart; - else - x = 0.0f; - y += 32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY; - numSpaces = 0; - first = true; - lineLength = 0.0f; - } -#else - PrintString(xleft, y, Details.anonymous_25, start, s, 0.0f); -#endif - } -} - -int -CFont::GetNumberLines(float xstart, float ystart, wchar *s) -{ - int n; - float x, y; - wchar *t; - n = 0; - -#if 0//def MORE_LANGUAGES - bool bSomeJapBool = false; - - if (IsJapanese()) { - t = s; - wchar unused; - while (*t) { - if (*t == JAP_TERMINATION || *t == '~') - t = ParseToken(t, &unused, true); - if (NewLine) { - n++; - NewLine = false; - bSomeJapBool = true; - } - t++; - } - } - - if (bSomeJapBool) n--; -#endif - - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - y = ystart; - - while(*s){ -#ifdef FIX_BUGS - float f = Details.centre ? Details.centreSize : - Details.rightJustify ? xstart - Details.rightJustifyWrap : - Details.wrapX; -#else - float f = (Details.centre ? Details.centreSize : Details.wrapX); -#endif - -#ifdef MORE_LANGUAGES - if (IsJapaneseFont()) - f -= SCREEN_SCALE_X(21.0f * 2.0f); -#endif - - if(x + GetStringWidth(s) > f){ -#ifdef MORE_LANGUAGES - if (IsJapanese()) - { - if (IsJapanesePunctuation(s)) - s--; - } -#endif - // reached end of line - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - n++; - // Why even? -#ifdef MORE_LANGUAGES - if (IsJapanese()) - y += 32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY; - else -#endif - y += 32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY; - }else{ - // still space in current line - t = GetNextSpace(s); - if(*t == '\0'){ - // end of string - x += GetStringWidth(s); -#ifdef MORE_LANGUAGES - if (IsJapanese() && IsAnsiCharacter(s)) - x += 21.0f; -#endif - n++; - s = t; - }else{ - x += GetStringWidth(s); -#ifdef MORE_LANGUAGES - if (IsJapanese() && IsAnsiCharacter(s)) - x += 21.0f; -#endif - s = t+1; - x += GetCharacterSize(*t - ' '); -#ifdef MORE_LANGUAGES - if (IsJapanese() && !*s) - n++; -#endif - } - } - } - - return n; -} - -void -CFont::GetTextRect(CRect *rect, float xstart, float ystart, wchar *s) -{ - int numLines; - float x, y; - int16 maxlength; - wchar *t; - - maxlength = 0; - numLines = 0; - -#ifdef MORE_LANGUAGES - if (IsJapanese()) { - numLines = GetNumberLines(xstart, ystart, s); - }else{ -#endif - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - y = ystart; - -#ifdef FIX_BUGS - float xEnd = Details.centre ? Details.centreSize : - Details.rightJustify ? xstart - Details.rightJustifyWrap : - Details.wrapX; -#else - float xEnd = (Details.centre ? Details.centreSize : Details.wrapX); -#endif - while(*s){ - if(x + GetStringWidth(s) > xEnd){ - // reached end of line - if(x > maxlength) - maxlength = x; - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - numLines++; - y += 32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY; - }else{ - // still space in current line - t = GetNextSpace(s); - if(*t == '\0'){ - // end of string - x += GetStringWidth(s); - if(x > maxlength) - maxlength = x; - numLines++; - s = t; - }else{ - x += GetStringWidth(s); - x += GetCharacterSize(*t - ' '); - s = t+1; - } - } - } -#ifdef MORE_LANGUAGES - } -#endif - - if(Details.centre){ - if(Details.backgroundOnlyText){ - rect->left = xstart - maxlength/2 - 4.0f; - rect->right = xstart + maxlength/2 + 4.0f; -#ifdef MORE_LANGUAGES - if (IsJapaneseFont()) { - rect->bottom = (32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY) * numLines + ystart + (4.0f / 2.75f); - rect->top = ystart - (4.0f / 2.75f); - } else { -#endif - rect->bottom = (32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY) * numLines + ystart + 2.0f; - rect->top = ystart - 2.0f; -#ifdef MORE_LANGUAGES - } -#endif - }else{ - rect->left = xstart - Details.centreSize*0.5f - 4.0f; - rect->right = xstart + Details.centreSize*0.5f + 4.0f; -#ifdef MORE_LANGUAGES - if (IsJapaneseFont()) { - rect->bottom = (32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY) * numLines + ystart + (4.0f / 2.75f); - rect->top = ystart - (4.0f / 2.75f); - } else { -#endif - rect->bottom = (32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY) * numLines + ystart + 2.0f; - rect->top = ystart - 2.0f; -#ifdef MORE_LANGUAGES - } -#endif - } - }else{ - rect->left = xstart - 4.0f; - rect->right = Details.wrapX; - // WTF? - rect->bottom = ystart - 4.0f + 4.0f; -#ifdef MORE_LANGUAGES - if (IsJapaneseFont()) - rect->top = (32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY) * numLines + ystart + 2.0f + (4.0f / 2.75f); - else -#endif - rect->top = (32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY) * numLines + ystart + 2.0f + 2.0f; - } -} - -float -CFont::GetCharacterWidth(wchar c) -{ -#ifdef MORE_LANGUAGES - if (IsJapanese()) { - if (!RenderState.proportional) - return Size[0][Details.style][192]; - if (c <= 94 || Details.style == FONT_HEADING || RenderState.style == FONT_BANK) { - switch (RenderState.style) - { - case FONT_JAPANESE: - return Size_jp[c]; - default: - return Size[0][RenderState.style][c]; - } - } - - switch (RenderState.style) - { - case FONT_JAPANESE: - return 29.4f; - case FONT_BANK: - return 10.0f; - default: - return Size[0][RenderState.style][c]; - } - } - - else if (RenderState.proportional) - return Size[LanguageSet][RenderState.style][c]; - else - return Size[LanguageSet][RenderState.style][209]; -#else - - if (RenderState.proportional) - return Size[RenderState.style][c]; - else - return Size[RenderState.style][209]; -#endif // MORE_LANGUAGES -} - -float -CFont::GetCharacterSize(wchar c) -{ -#ifdef MORE_LANGUAGES - - if (IsJapanese()) - { - if (!Details.proportional) - return Size[0][Details.style][209] * Details.scaleX; - if (c <= 94 || Details.style == FONT_HEADING || Details.style == FONT_BANK) { - switch (Details.style) - { - case FONT_JAPANESE: - return Size_jp[c] * Details.scaleX; - default: - return Size[0][Details.style][c] * Details.scaleX; - } - } - - switch (Details.style) - { - case FONT_JAPANESE: - return 29.4f * Details.scaleX; - case FONT_BANK: - return 10.0f * Details.scaleX; - default: - return Size[0][Details.style][c] * Details.scaleX; - } - } - else - { - if (!Details.bFontHalfTexture && c == 30) c = 61; // wanted star - if (Details.bFontHalfTexture) - c = FindNewCharacter(c); - if (Details.proportional) - return Size[LanguageSet][Details.style][c] * Details.scaleX; - else - return Size[LanguageSet][Details.style][209] * Details.scaleX; - } -#else - -#ifdef FIX_BUGS - // PS2 don't call FindNewCharacter in here at all, and also uses different chars for some symbols - if (!Details.bFontHalfTexture && c == 30) c = 61; // wanted star -#endif - if (Details.bFontHalfTexture) - c = FindNewCharacter(c); - if (Details.proportional) - return Size[Details.style][c] * Details.scaleX; - else - return Size[Details.style][209] * Details.scaleX; -#endif // MORE_LANGUAGES -} - -float -CFont::GetStringWidth(wchar *s, bool spaces) -{ - float w; - - w = 0.0f; -#ifdef MORE_LANGUAGES - if (IsJapanese()) - { - do - { - if ((*s != ' ' || spaces) && *s != '\0') { - do { - while (*s == '~' || *s == JAP_TERMINATION) { - s++; -#ifdef BUTTON_ICONS - switch (*s) { - case 'U': - case 'D': - case '<': - case '>': - case 'X': - case 'O': - case 'Q': - case 'T': - case 'K': - case 'M': - case 'A': - case 'J': - case 'V': - case 'C': - case '(': - case ')': - w += 17.0f * Details.scaleY; - break; - default: - break; - } -#endif - while (!(*s == '~' || *s == JAP_TERMINATION)) s++; - s++; - } - w += GetCharacterSize(*s - ' '); - ++s; - } while (*s == '~' || *s == JAP_TERMINATION); - } - } while (IsAnsiCharacter(s)); - } else -#endif - { - for (wchar c = *s; (c != ' ' || spaces) && c != '\0'; c = *(++s)) { - if (c == '~') { - s++; -#ifdef BUTTON_ICONS - switch (*s) { - case 'U': - case 'D': - case '<': - case '>': - case 'X': - case 'O': - case 'Q': - case 'T': - case 'K': - case 'M': - case 'A': - case 'J': - case 'V': - case 'C': - case '(': - case ')': - w += 17.0f * Details.scaleY; - break; - default: - break; - } -#endif - while (*s != '~') { - s++; - } - } - else { - w += GetCharacterSize(c - ' '); - } - } - } - return w; -} - - -#ifdef MORE_LANGUAGES -float -CFont::GetStringWidth_Jap(wchar* s) -{ - float w; - - w = 0.0f; - for (; *s != '\0';) { - do { - while (*s == '~' || *s == JAP_TERMINATION) { - s++; - while (!(*s == '~' || *s == JAP_TERMINATION)) s++; - s++; - } - w += GetCharacterSize(*s - ' '); - ++s; - } while (*s == '~' || *s == JAP_TERMINATION); - } - return w; -} -#endif - -wchar* -CFont::GetNextSpace(wchar *s) -{ -#ifdef MORE_LANGUAGES - if (IsJapanese()) { - do - { - if (*s != ' ' && *s != '\0') { - do { - while (*s == '~' || *s == JAP_TERMINATION) { - s++; - while (!(*s == '~' || *s == JAP_TERMINATION)) s++; - s++; - } - ++s; - } while (*s == '~' || *s == JAP_TERMINATION); - } - } while (IsAnsiCharacter(s)); - } else -#endif - { - for(; *s != ' ' && *s != '\0'; s++) - if(*s == '~'){ - s++; - while(*s != '~') s++; - } - } - return s; -} - -wchar* -CFont::ParseToken(wchar* str, CRGBA &color, bool &flash, bool &bold) -{ - Details.anonymous_23 = false; - wchar *s = str + 1; - if (Details.color.r || Details.color.g || Details.color.b) - { - switch (*s) - { - case 'B': - bold = !bold; - break; - case 'b': - color.r = 27; - color.g = 89; - color.b = 130; - break; - case 'f': - flash = !flash; - break; - case 'g': - color.r = 255; - color.g = 150; - color.b = 225; - break; - case 'h': - color.r = 225; - color.g = 225; - color.b = 225; - break; - case 'l': - color.r = 0; - color.g = 0; - color.b = 0; - break; - case 'o': - color.r = 229; - color.g = 125; - color.b = 126; - break; - case 'p': - color.r = 168; - color.g = 110; - color.b = 252; - break; - case 'q': - color.r = 199; - color.g = 144; - color.b = 203; - break; - case 'r': - color.r = 255; - color.g = 150; - color.b = 225; - break; - case 't': - color.r = 86; - color.g = 212; - color.b = 146; - break; - case 'w': - color.r = 175; - color.g = 175; - color.b = 175; - break; -#ifdef FIX_BUGS - case 'x': - color.r = 0; - color.g = 255; - color.b = 255; - break; -#else - case 'x': - color.r = 132; - color.g = 146; - color.b = 197; - break; -#endif - case 'y': - color.r = 255; - color.g = 227; - color.b = 79; - break; -#ifdef BUTTON_ICONS - case 'U': PS2Symbol = BUTTON_UP; break; - case 'D': PS2Symbol = BUTTON_DOWN; break; - case '<': PS2Symbol = BUTTON_LEFT; break; - case '>': PS2Symbol = BUTTON_RIGHT; break; - case 'X': PS2Symbol = BUTTON_CROSS; break; - case 'O': PS2Symbol = BUTTON_CIRCLE; break; - case 'Q': PS2Symbol = BUTTON_SQUARE; break; - case 'T': PS2Symbol = BUTTON_TRIANGLE; break; - case 'K': PS2Symbol = BUTTON_L1; break; - case 'M': PS2Symbol = BUTTON_L2; break; - case 'A': PS2Symbol = BUTTON_L3; break; - case 'J': PS2Symbol = BUTTON_R1; break; - case 'V': PS2Symbol = BUTTON_R2; break; - case 'C': PS2Symbol = BUTTON_R3; break; - case 'H': PS2Symbol = BUTTON_RSTICK_UP; break; - case 'L': PS2Symbol = BUTTON_RSTICK_DOWN; break; - case '(': PS2Symbol = BUTTON_RSTICK_LEFT; break; - case ')': PS2Symbol = BUTTON_RSTICK_RIGHT; break; -#endif - default: - break; - } - } - while (*s != '~') - ++s; - if (*(++s) == '~') - s = ParseToken(s, color, flash, bold); - return s; -} - -#if 0//def MORE_LANGUAGES -wchar* -CFont::ParseToken(wchar *s, bool japShit) -{ - s++; - if ((Details.color.r || Details.color.g || Details.color.b) && !japShit) { - wchar c = *s; - if (IsJapanese()) - c &= 0x7FFF; - switch (c) { - case 'N': - case 'n': - NewLine = true; - break; - case 'b': SetColor(CRGBA(128, 167, 243, 255)); break; - case 'g': SetColor(CRGBA(95, 160, 106, 255)); break; - case 'h': SetColor(CRGBA(225, 225, 225, 255)); break; - case 'l': SetColor(CRGBA(0, 0, 0, 255)); break; - case 'p': SetColor(CRGBA(168, 110, 252, 255)); break; - case 'r': SetColor(CRGBA(113, 43, 73, 255)); break; - case 'w': SetColor(CRGBA(175, 175, 175, 255)); break; - case 'y': SetColor(CRGBA(210, 196, 106, 255)); break; -#ifdef BUTTON_ICONS - case 'U': PS2Symbol = BUTTON_UP; break; - case 'D': PS2Symbol = BUTTON_DOWN; break; - case '<': PS2Symbol = BUTTON_LEFT; break; - case '>': PS2Symbol = BUTTON_RIGHT; break; - case 'X': PS2Symbol = BUTTON_CROSS; break; - case 'O': PS2Symbol = BUTTON_CIRCLE; break; - case 'Q': PS2Symbol = BUTTON_SQUARE; break; - case 'T': PS2Symbol = BUTTON_TRIANGLE; break; - case 'K': PS2Symbol = BUTTON_L1; break; - case 'M': PS2Symbol = BUTTON_L2; break; - case 'A': PS2Symbol = BUTTON_L3; break; - case 'J': PS2Symbol = BUTTON_R1; break; - case 'V': PS2Symbol = BUTTON_R2; break; - case 'C': PS2Symbol = BUTTON_R3; break; - case 'H': PS2Symbol = BUTTON_RSTICK_UP; break; - case 'L': PS2Symbol = BUTTON_RSTICK_DOWN; break; - case '(': PS2Symbol = BUTTON_RSTICK_LEFT; break; - case ')': PS2Symbol = BUTTON_RSTICK_RIGHT; break; -#endif - } - } else if (IsJapanese()) { - if ((*s & 0x7FFF) == 'N' || (*s & 0x7FFF) == 'n') - NewLine = true; - } - while ((!IsJapanese() || (*s != JAP_TERMINATION)) && *s != '~') s++; - return s + 1; -} -#else -wchar* -CFont::ParseToken(wchar *s) -{ - Details.anonymous_23 = false; - s++; - if(Details.color.r || Details.color.g || Details.color.b) - switch(*s){ - case 'B': - Details.bBold = !Details.bBold; - break; - case 'N': - case 'n': - NewLine = true; - break; - case 'b': - Details.color.r = 27; - Details.color.g = 89; - Details.color.b = 130; - Details.anonymous_23 = true; - break; - case 'f': - Details.bFlash = !Details.bFlash; - if (!Details.bFlash) - Details.color.a = 255; - break; - case 'g': - Details.color.r = 255; - Details.color.g = 150; - Details.color.b = 225; - Details.anonymous_23 = true; - break; - case 'h': - Details.color.r = 225; - Details.color.g = 225; - Details.color.b = 225; - Details.anonymous_23 = true; - break; - case 'l': - Details.color.r = 0; - Details.color.g = 0; - Details.color.b = 0; - Details.anonymous_23 = true; - break; - case 'o': - Details.color.r = 229; - Details.color.g = 125; - Details.color.b = 126; - Details.anonymous_23 = true; - break; - case 'p': - Details.color.r = 168; - Details.color.g = 110; - Details.color.b = 252; - Details.anonymous_23 = true; - break; - case 'q': - Details.color.r = 199; - Details.color.g = 144; - Details.color.b = 203; - Details.anonymous_23 = true; - break; - case 'r': - Details.color.r = 255; - Details.color.g = 150; - Details.color.b = 225; - Details.anonymous_23 = true; - break; - case 't': - Details.color.r = 86; - Details.color.g = 212; - Details.color.b = 146; - Details.anonymous_23 = true; - break; - case 'w': - Details.color.r = 175; - Details.color.g = 175; - Details.color.b = 175; - Details.anonymous_23 = true; - break; - case 'x': -#ifdef FIX_BUGS - Details.color.r = 0; - Details.color.g = 255; - Details.color.b = 255; -#else - Details.color.r = 132; - Details.color.g = 146; - Details.color.b = 197; -#endif - Details.anonymous_23 = true; - break; - case 'y': - Details.color.r = 255; - Details.color.g = 227; - Details.color.b = 79; - Details.anonymous_23 = true; - break; -#ifdef BUTTON_ICONS - case 'U': PS2Symbol = BUTTON_UP; break; - case 'D': PS2Symbol = BUTTON_DOWN; break; - case '<': PS2Symbol = BUTTON_LEFT; break; - case '>': PS2Symbol = BUTTON_RIGHT; break; - case 'X': PS2Symbol = BUTTON_CROSS; break; - case 'O': PS2Symbol = BUTTON_CIRCLE; break; - case 'Q': PS2Symbol = BUTTON_SQUARE; break; - case 'T': PS2Symbol = BUTTON_TRIANGLE; break; - case 'K': PS2Symbol = BUTTON_L1; break; - case 'M': PS2Symbol = BUTTON_L2; break; - case 'A': PS2Symbol = BUTTON_L3; break; - case 'J': PS2Symbol = BUTTON_R1; break; - case 'V': PS2Symbol = BUTTON_R2; break; - case 'C': PS2Symbol = BUTTON_R3; break; - case 'H': PS2Symbol = BUTTON_RSTICK_UP; break; - case 'L': PS2Symbol = BUTTON_RSTICK_DOWN; break; - case '(': PS2Symbol = BUTTON_RSTICK_LEFT; break; - case ')': PS2Symbol = BUTTON_RSTICK_RIGHT; break; -#endif - } - while(*s != '~') s++; - if (*(++s) == '~') - s = ParseToken(s); - return s; -} -#endif - -void -CFont::FilterOutTokensFromString(wchar *str) -{ - int newIdx = 0; - wchar copy[256], *c; - UnicodeStrcpy(copy, str); - - for (c = copy; *c != '\0'; c++) { - if (*c == '~') { - c++; - while (*c != '~') c++; - } else { - str[newIdx++] = *c; - } - } - str[newIdx] = '\0'; -} - -void -CFont::DrawFonts(void) -{ - RenderFontBuffer(); -} - -void -CFont::SetScale(float x, float y) -{ -#ifdef MORE_LANGUAGES - /*if (IsJapanese()) { - x *= 1.35f; - y *= 1.25f; - }*/ -#endif - Details.scaleX = x; - Details.scaleY = y; -} - -void -CFont::SetSlantRefPoint(float x, float y) -{ - Details.slantRefX = x; - Details.slantRefY = y; -} - -void -CFont::SetSlant(float s) -{ - Details.slant = s; -} - -void -CFont::SetColor(CRGBA col) -{ - Details.color = col; - if (Details.alphaFade < 255.0f) - Details.color.a *= Details.alphaFade / 255.0f; -} - -void -CFont::SetJustifyOn(void) -{ - Details.justify = true; - Details.centre = false; - Details.rightJustify = false; -} - -void -CFont::SetJustifyOff(void) -{ - Details.justify = false; - Details.rightJustify = false; -} - -void -CFont::SetCentreOn(void) -{ - Details.centre = true; - Details.justify = false; - Details.rightJustify = false; -} - -void -CFont::SetCentreOff(void) -{ - Details.centre = false; -} - -void -CFont::SetWrapx(float x) -{ - Details.wrapX = x; -} - -void -CFont::SetCentreSize(float s) -{ - Details.centreSize = s; -} - -void -CFont::SetBackgroundOn(void) -{ - Details.background = true; -} - -void -CFont::SetBackgroundOff(void) -{ - Details.background = false; -} - -void -CFont::SetBackgroundColor(CRGBA col) -{ - Details.backgroundColor = col; -} - -void -CFont::SetBackGroundOnlyTextOn(void) -{ - Details.backgroundOnlyText = true; -} - -void -CFont::SetBackGroundOnlyTextOff(void) -{ - Details.backgroundOnlyText = false; -} - -void -CFont::SetRightJustifyOn(void) -{ - Details.rightJustify = true; - Details.justify = false; - Details.centre = false; -} - -void -CFont::SetRightJustifyOff(void) -{ - Details.rightJustify = false; - Details.justify = false; - Details.centre = false; -} - -void -CFont::SetPropOff(void) -{ - Details.proportional = false; -} - -void -CFont::SetPropOn(void) -{ - Details.proportional = true; -} - -void -CFont::SetFontStyle(int16 style) -{ - if (style == FONT_HEADING) { - Details.style = FONT_STANDARD; - Details.bFontHalfTexture = true; - } else { - Details.style = style; - Details.bFontHalfTexture = false; - } -} - -void -CFont::SetRightJustifyWrap(float wrap) -{ - Details.rightJustifyWrap = wrap; -} - -void -CFont::SetAlphaFade(float fade) -{ - Details.alphaFade = fade; -} - -void -CFont::SetDropColor(CRGBA col) -{ - Details.dropColor = col; - if (Details.alphaFade < 255.0f) - Details.dropColor.a *= Details.alphaFade / 255.0f; -} - -void -CFont::SetDropShadowPosition(int16 pos) -{ - Details.dropShadowPosition = pos; -} - -wchar CFont::FindNewCharacter(wchar c) -{ - if (c >= 16 && c <= 26) return c + 128; - if (c >= 8 && c <= 9) return c + 86; - if (c == 4) return c + 89; - if (c == 7) return 206; - if (c == 14) return 207; - if (c >= 33 && c <= 58) return c + 122; - if (c >= 65 && c <= 90) return c + 90; - if (c >= 96 && c <= 118) return c + 85; - if (c >= 119 && c <= 140) return c + 62; - if (c >= 141 && c <= 142) return 204; - if (c == 143) return 205; - if (c == 1) return 208; - return c; -} - -wchar -CFont::character_code(uint8 c) -{ - if(c < 128) - return c; - return foreign_table[c-128]; -} \ No newline at end of file diff --git a/src/render/Font.h b/src/render/Font.h deleted file mode 100644 index 42eb7b4c..00000000 --- a/src/render/Font.h +++ /dev/null @@ -1,217 +0,0 @@ -#pragma once - -#include "Sprite2d.h" - -void AsciiToUnicode(const char *src, wchar *dst); -void UnicodeStrcpy(wchar *dst, const wchar *src); -void UnicodeStrcat(wchar *dst, wchar *append); -int UnicodeStrlen(const wchar *str); -void UnicodeMakeUpperCase(wchar *dst, const wchar *src); - -struct CFontDetails -{ - CRGBA color; - float scaleX; - float scaleY; - float slant; - float slantRefX; - float slantRefY; - bool8 justify; - bool8 centre; - bool8 rightJustify; - bool8 background; - bool8 backgroundOnlyText; - bool8 proportional; - bool8 bIsShadow; - bool8 bFlash; - bool8 bBold; - float alphaFade; - CRGBA backgroundColor; - float wrapX; - float centreSize; - float rightJustifyWrap; - int16 style; - bool8 bFontHalfTexture; - uint32 bank; - int16 dropShadowPosition; - CRGBA dropColor; - bool8 bFlashState; - int nFlashTimer; - bool8 anonymous_23; - uint32 anonymous_25; -}; - -struct CFontRenderState -{ - uint32 anonymous_0; - float fTextPosX; - float fTextPosY; - float scaleX; - float scaleY; - CRGBA color; - float fExtraSpace; - float slant; - float slantRefX; - float slantRefY; - bool8 bIsShadow; - bool8 bFontHalfTexture; - bool8 proportional; - bool8 anonymous_14; - int16 style; -}; - -class CSprite2d; - -enum { - FONT_BANK, - FONT_STANDARD, - FONT_HEADING, -#ifdef MORE_LANGUAGES - FONT_JAPANESE, -#endif - MAX_FONTS = FONT_HEADING -}; - -enum { - ALIGN_LEFT, - ALIGN_CENTER, - ALIGN_RIGHT, -}; - -#ifdef MORE_LANGUAGES -enum -{ - FONT_LANGSET_EFIGS, - FONT_LANGSET_RUSSIAN, - FONT_LANGSET_POLISH, - FONT_LANGSET_JAPANESE, - LANGSET_MAX -}; - -#define FONT_LOCALE(style) (CFont::IsJapanese() ? FONT_JAPANESE : style) -#else -#define FONT_LOCALE(style) (style) -#endif - -#ifdef BUTTON_ICONS -enum -{ - BUTTON_NONE = -1, - BUTTON_UP, - BUTTON_DOWN, - BUTTON_LEFT, - BUTTON_RIGHT, - BUTTON_CROSS, - BUTTON_CIRCLE, - BUTTON_SQUARE, - BUTTON_TRIANGLE, - BUTTON_L1, - BUTTON_L2, - BUTTON_L3, - BUTTON_R1, - BUTTON_R2, - BUTTON_R3, - BUTTON_RSTICK_UP, - BUTTON_RSTICK_DOWN, - BUTTON_RSTICK_LEFT, - BUTTON_RSTICK_RIGHT, - MAX_BUTTON_ICONS -}; -#endif // BUTTON_ICONS - - -class CFont -{ -#ifdef MORE_LANGUAGES - static int16 Size[LANGSET_MAX][MAX_FONTS][210]; - static uint8 LanguageSet; - static int32 Slot; -#else - static int16 Size[MAX_FONTS][210]; -#endif - static int16 NewLine; -public: - static CSprite2d Sprite[MAX_FONTS]; - static CFontDetails Details; - static CFontRenderState RenderState; - -#ifdef BUTTON_ICONS - static int32 ButtonsSlot; - static CSprite2d ButtonSprite[MAX_BUTTON_ICONS]; - static int PS2Symbol; - - static void LoadButtons(const char *txdPath); - static void DrawButton(float x, float y); -#endif // BUTTON_ICONS - - - static void Initialise(void); - static void Shutdown(void); - static void InitPerFrame(void); - static void PrintChar(float x, float y, wchar c); - static void PrintString(float x, float y, wchar *s); -#ifdef XBOX_SUBTITLES - static void PrintStringFromBottom(float x, float y, wchar *str); - static void PrintOutlinedString(float x, float y, wchar *str, float outlineStrength, bool fromBottom, CRGBA outlineColor); -#endif - static int GetNumberLines(float xstart, float ystart, wchar *s); - static void GetTextRect(CRect *rect, float xstart, float ystart, wchar *s); -//#ifdef MORE_LANGUAGES -// static bool PrintString(float x, float y, wchar *start, wchar* &end, float spwidth, float japX); -//#else - static void PrintString(float x, float y, uint32, wchar *start, wchar *end, float spwidth); -//#endif - static void PrintStringFromBottom(float x, float y, wchar *str); - static float GetCharacterWidth(wchar c); - static float GetCharacterSize(wchar c); - static float GetStringWidth(wchar *s, bool spaces = false); -#ifdef MORE_LANGUAGES - static float GetStringWidth_Jap(wchar* s); -#endif - static uint16 *GetNextSpace(wchar *s); -//#ifdef MORE_LANGUAGES -// static uint16 *ParseToken(wchar *s, bool japShit = false); -//#else - static uint16 *ParseToken(wchar *s); - static uint16 *ParseToken(wchar *s, CRGBA &color, bool &flash, bool &bold); -//#endif - static void DrawFonts(void); - static void RenderFontBuffer(void); - static uint16 character_code(uint8 c); - - static void SetScale(float x, float y); - static void SetSlantRefPoint(float x, float y); - static void SetSlant(float s); - static void SetJustifyOn(void); - static void SetJustifyOff(void); - static void SetRightJustifyOn(void); - static void SetRightJustifyOff(void); - static void SetCentreOn(void); - static void SetCentreOff(void); - static void SetWrapx(float x); - static void SetCentreSize(float s); - static void SetBackgroundOn(void); - static void SetBackgroundOff(void); - static void SetBackGroundOnlyTextOn(void); - static void SetBackGroundOnlyTextOff(void); - static void SetPropOn(void); - static void SetPropOff(void); - static void SetFontStyle(int16 style); - static void SetRightJustifyWrap(float wrap); - static void SetAlphaFade(float fade); - static void SetDropShadowPosition(int16 pos); - static void SetBackgroundColor(CRGBA col); - static void SetColor(CRGBA col); - static void SetDropColor(CRGBA col); - static wchar FindNewCharacter(wchar c); - static void FilterOutTokensFromString(wchar*); -#ifdef MORE_LANGUAGES - static void ReloadFonts(uint8 set); - - // japanese stuff - static bool IsAnsiCharacter(wchar* s); - static bool IsJapanesePunctuation(wchar* str); - static bool IsJapanese() { return LanguageSet == FONT_LANGSET_JAPANESE; } - static bool IsJapaneseFont() { return IsJapanese() && (Details.style == FONT_JAPANESE); } -#endif -}; diff --git a/src/render/Glass.cpp b/src/render/Glass.cpp deleted file mode 100644 index b4ec8c7e..00000000 --- a/src/render/Glass.cpp +++ /dev/null @@ -1,1027 +0,0 @@ -#include "common.h" - -#include "Glass.h" -#include "Timer.h" -#include "Object.h" -#include "Vehicle.h" -#include "Pools.h" -#include "General.h" -#include "AudioScriptObject.h" -#include "World.h" -#include "Timecycle.h" -#include "Particle.h" -#include "Camera.h" -#include "RenderBuffer.h" -#include "Shadows.h" -#include "ModelIndices.h" -#include "main.h" -#include "soundlist.h" -#include "SurfaceTable.h" - - -uint32 CGlass::NumGlassEntities; -CEntity *CGlass::apEntitiesToBeRendered[NUM_GLASSENTITIES]; -CFallingGlassPane CGlass::aGlassPanes[NUM_GLASSPANES]; - - -CVector2D CentersWithTriangle[NUM_GLASSTRIANGLES]; -const CVector2D CoorsWithTriangle[NUM_GLASSTRIANGLES][3] = -{ - { - CVector2D(0.0f, 0.0f), - CVector2D(0.0f, 1.0f), - CVector2D(0.4f, 0.5f) - }, - - { - CVector2D(0.0f, 1.0f), - CVector2D(1.0f, 1.0f), - CVector2D(0.4f, 0.5f) - }, - - { - CVector2D(0.0f, 0.0f), - CVector2D(0.4f, 0.5f), - CVector2D(0.7f, 0.0f) - }, - - { - CVector2D(0.7f, 0.0f), - CVector2D(0.4f, 0.5f), - CVector2D(1.0f, 1.0f) - }, - - { - CVector2D(0.7f, 0.0f), - CVector2D(1.0f, 1.0f), - CVector2D(1.0f, 0.0f) - } -}; - -#define TEMPBUFFERVERTHILIGHTOFFSET 0 -#define TEMPBUFFERINDEXHILIGHTOFFSET 0 -#define TEMPBUFFERVERTHILIGHTSIZE 256 -#define TEMPBUFFERINDEXHILIGHTSIZE 512 - -#define TEMPBUFFERVERTSHATTEREDOFFSET TEMPBUFFERVERTHILIGHTSIZE -#define TEMPBUFFERINDEXSHATTEREDOFFSET TEMPBUFFERINDEXHILIGHTSIZE -#define TEMPBUFFERVERTSHATTEREDSIZE 384 -#define TEMPBUFFERINDEXSHATTEREDSIZE 768 - -#define TEMPBUFFERVERTREFLECTIONOFFSET TEMPBUFFERVERTSHATTEREDSIZE -#define TEMPBUFFERINDEXREFLECTIONOFFSET TEMPBUFFERINDEXSHATTEREDSIZE -#define TEMPBUFFERVERTREFLECTIONSIZE 512 -#define TEMPBUFFERINDEXREFLECTIONSIZE 1024 - -int32 TempBufferIndicesStoredHiLight = 0; -int32 TempBufferVerticesStoredHiLight = 0; -int32 TempBufferIndicesStoredShattered = 0; -int32 TempBufferVerticesStoredShattered = 0; -int32 TempBufferIndicesStoredReflection = 0; -int32 TempBufferVerticesStoredReflection = 0; - -void -CFallingGlassPane::Update(void) -{ - if ( CTimer::GetTimeInMilliseconds() >= m_nTimer ) - { - // Apply MoveSpeed - if ( m_bCarGlass ) - GetPosition() += m_vecMoveSpeed * CTimer::GetTimeStep() * 0.35f; - else - GetPosition() += m_vecMoveSpeed * CTimer::GetTimeStep(); - - // Apply Gravity - if ( m_bCarGlass ) - m_vecMoveSpeed.z -= 0.01f * CTimer::GetTimeStep(); - else - m_vecMoveSpeed.z -= 0.02f * CTimer::GetTimeStep(); - - // Apply TurnSpeed - GetRight() += CrossProduct(m_vecTurn, GetRight()); - GetForward() += CrossProduct(m_vecTurn, GetForward()); - GetUp() += CrossProduct(m_vecTurn, GetUp()); - - if ( GetPosition().z < m_fGroundZ ) - { - CVector pos; - CVector dir; - - m_bActive = false; - - pos = CVector(GetPosition().x, GetPosition().y, m_fGroundZ); - - PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_LIGHT_BREAK, pos); - - RwRGBA color = { 255, 255, 255, 255 }; - - if ( !m_bCarGlass ) - { - static int32 nFrameGen = 0; - - for ( int32 i = 0; i < 4; i++ ) - { - dir.x = CGeneral::GetRandomNumberInRange(-0.35f, 0.35f); - dir.y = CGeneral::GetRandomNumberInRange(-0.35f, 0.35f); - dir.z = CGeneral::GetRandomNumberInRange(0.05f, 0.20f); - - CParticle::AddParticle(PARTICLE_CAR_DEBRIS, - pos, - dir, - nil, - CGeneral::GetRandomNumberInRange(0.02f, 0.2f), - color, - CGeneral::GetRandomNumberInRange(-40, 40), - 0, - ++nFrameGen & 3, - 500); - } - } - } - } -} - -void -CFallingGlassPane::Render(void) -{ - float distToCamera = (TheCamera.GetPosition() - GetPosition()).Magnitude(); - - CVector fwdNorm = GetForward(); - fwdNorm.Normalise(); - uint8 alpha = CGlass::CalcAlphaWithNormal(&fwdNorm); - -#ifdef FIX_BUGS - uint16 time = Clamp(CTimer::GetTimeInMilliseconds() > m_nTimer ? CTimer::GetTimeInMilliseconds() - m_nTimer : 0u, 0u, 500u); -#else - uint16 time = Clamp(CTimer::GetTimeInMilliseconds() - m_nTimer, 0, 500); -#endif - - uint8 color = int32( float(alpha) * (float(time) / 500) ); - - if ( TempBufferIndicesStoredHiLight >= TEMPBUFFERINDEXHILIGHTSIZE-7 || TempBufferVerticesStoredHiLight >= TEMPBUFFERVERTHILIGHTSIZE-4 ) - CGlass::RenderHiLightPolys(); - - // HiLight Polys - - if ( m_bCarGlass && color < 64 ) - color = 64; - - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], color, color, color, color); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], color, color, color, color); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], color, color, color, color); - - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], 0.5f); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], 0.5f); - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], 0.5f); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], 0.6f); - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], 0.6f); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], 0.6f); - - ASSERT(m_nTriIndex < NUM_GLASSTRIANGLES); - - CVector2D p0 = CoorsWithTriangle[m_nTriIndex][0] - CentersWithTriangle[m_nTriIndex]; - CVector2D p1 = CoorsWithTriangle[m_nTriIndex][1] - CentersWithTriangle[m_nTriIndex]; - CVector2D p2 = CoorsWithTriangle[m_nTriIndex][2] - CentersWithTriangle[m_nTriIndex]; - CVector v0 = *this * CVector(p0.x, 0.0f, p0.y); - CVector v1 = *this * CVector(p1.x, 0.0f, p1.y); - CVector v2 = *this * CVector(p2.x, 0.0f, p2.y); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], v0.x, v0.y, v0.z); - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], v1.x, v1.y, v1.z); - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], v2.x, v2.y, v2.z); - - TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 0] = TempBufferVerticesStoredHiLight + 0; - TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 1] = TempBufferVerticesStoredHiLight + 1; - TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 2] = TempBufferVerticesStoredHiLight + 2; - TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 3] = TempBufferVerticesStoredHiLight + 0; - TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 4] = TempBufferVerticesStoredHiLight + 2; - TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 5] = TempBufferVerticesStoredHiLight + 1; - - TempBufferVerticesStoredHiLight += 3; - TempBufferIndicesStoredHiLight += 6; - - if ( m_bShattered ) - { - if ( TempBufferIndicesStoredShattered >= TEMPBUFFERINDEXSHATTEREDSIZE-7 || TempBufferVerticesStoredShattered >= TEMPBUFFERVERTSHATTEREDSIZE-4 ) - CGlass::RenderShatteredPolys(); - - uint8 shatteredColor = 140; - if ( distToCamera > 30.0f ) - shatteredColor = int32((1.0f - (distToCamera - 30.0f) * 4.0f / 40.0f) * 140); - - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], shatteredColor, shatteredColor, shatteredColor, shatteredColor); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], shatteredColor, shatteredColor, shatteredColor, shatteredColor); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], shatteredColor, shatteredColor, shatteredColor, shatteredColor); - - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 4.0f * CoorsWithTriangle[m_nTriIndex][0].x * m_fStep); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 4.0f * CoorsWithTriangle[m_nTriIndex][0].y * m_fStep); - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 4.0f * CoorsWithTriangle[m_nTriIndex][1].x * m_fStep); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 4.0f * CoorsWithTriangle[m_nTriIndex][1].y * m_fStep); - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 4.0f * CoorsWithTriangle[m_nTriIndex][2].x * m_fStep); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 4.0f * CoorsWithTriangle[m_nTriIndex][2].y * m_fStep); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], v0.x, v0.y, v0.z); - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], v1.x, v1.y, v1.z); - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], v2.x, v2.y, v2.z); - - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 0] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 0; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 1] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 1; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 2] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 2; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 3] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 0; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 4] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 2; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 5] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 1; - - TempBufferIndicesStoredShattered += 6; - TempBufferVerticesStoredShattered += 3; - } -} - -void -CGlass::Init(void) -{ - for ( int32 i = 0; i < NUM_GLASSPANES; i++ ) - aGlassPanes[i].m_bActive = false; - - for ( int32 i = 0; i < NUM_GLASSTRIANGLES; i++ ) - CentersWithTriangle[i] = (CoorsWithTriangle[i][0] + CoorsWithTriangle[i][1] + CoorsWithTriangle[i][2]) / 3; -} - -void -CGlass::Update(void) -{ - for ( int32 i = 0; i < NUM_GLASSPANES; i++ ) - { - if ( aGlassPanes[i].m_bActive ) - aGlassPanes[i].Update(); - } -} - -void -CGlass::Render(void) -{ - TempBufferVerticesStoredHiLight = 0; - TempBufferIndicesStoredHiLight = 0; - - TempBufferVerticesStoredShattered = TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferIndicesStoredShattered = TEMPBUFFERINDEXSHATTEREDOFFSET; - - TempBufferVerticesStoredReflection = TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferIndicesStoredReflection = TEMPBUFFERINDEXREFLECTIONOFFSET; - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEFOGCOLOR, (void *)RWRGBALONG(CTimeCycle::GetFogRed(), CTimeCycle::GetFogGreen(), CTimeCycle::GetFogBlue(), 255)); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); - - PUSH_RENDERGROUP("CGlass::Render"); - - for ( int32 i = 0; i < NUM_GLASSPANES; i++ ) - { - if ( aGlassPanes[i].m_bActive ) - aGlassPanes[i].Render(); - } - - for ( uint32 i = 0; i < NumGlassEntities; i++ ) - RenderEntityInGlass(apEntitiesToBeRendered[i]); - - POP_RENDERGROUP(); - - NumGlassEntities = 0; - - RenderHiLightPolys(); - RenderShatteredPolys(); - RenderReflectionPolys(); - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE); -} - -CFallingGlassPane * -CGlass::FindFreePane(void) -{ - for ( int32 i = 0; i < NUM_GLASSPANES; i++ ) - { - if ( !aGlassPanes[i].m_bActive ) - return &aGlassPanes[i]; - } - - return nil; -} - -void -CGlass::GeneratePanesForWindow(uint32 type, CVector pos, CVector up, CVector right, CVector speed, CVector center, - float moveSpeed, bool cracked, bool explosion, int32 stepmul, bool carGlass) -{ - float upLen = up.Magnitude(); - float rightLen = right.Magnitude(); - - float upSteps = upLen + 0.75f; - if ( upSteps < 1.0f ) upSteps = 1.0f; - - float rightSteps = rightLen + 0.75f; - if ( rightSteps < 1.0f ) rightSteps = 1.0f; - - uint32 ysteps = stepmul * (uint32)upSteps; - if ( ysteps > 3 ) ysteps = 3; - - uint32 xsteps = stepmul * (uint32)rightSteps; - if ( xsteps > 3 ) xsteps = 3; - - if ( explosion ) - { - if ( ysteps > 1 ) ysteps = 1; - if ( xsteps > 1 ) xsteps = 1; - } - - float upScl = upLen / float(ysteps); - float rightScl = rightLen / float(xsteps); - - bool bZFound; - float groundZ = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z, &bZFound); - if ( !bZFound ) groundZ = pos.z - 2.0f; - - for ( uint32 y = 0; y < ysteps; y++ ) - { - for ( uint32 x = 0; x < xsteps; x++ ) - { - float stepy = float(y) * upLen / float(ysteps); - float stepx = float(x) * rightLen / float(xsteps); - - for ( int32 i = 0; i < NUM_GLASSTRIANGLES; i++ ) - { - CFallingGlassPane *pane = FindFreePane(); - if ( pane ) - { - pane->m_nTriIndex = i; - - pane->GetRight() = (right * rightScl) / rightLen; - pane->GetUp() = (up * upScl) / upLen; - - CVector fwd = CrossProduct(pane->GetRight(), pane->GetUp()); - fwd.Normalise(); - - pane->GetForward() = fwd; - - pane->GetPosition() = right / rightLen * (rightScl * CentersWithTriangle[i].x + stepx) - + up / upLen * (upScl * CentersWithTriangle[i].y + stepy) - + pos; - - pane->m_vecMoveSpeed.x = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.0015f + speed.x; - pane->m_vecMoveSpeed.y = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.0015f + speed.y; - pane->m_vecMoveSpeed.z = 0.0f + speed.z; - - if ( moveSpeed != 0.0f ) - { - CVector dist = pane->GetPosition() - center; - dist.Normalise(); - - pane->m_vecMoveSpeed += moveSpeed * dist; - } - - pane->m_vecTurn.x = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.002f; - pane->m_vecTurn.y = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.002f; - pane->m_vecTurn.z = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.002f; - - switch ( type ) - { - case 0: - case 2: - pane->m_nTimer = CTimer::GetTimeInMilliseconds(); - break; - case 1: - float dist = (pane->GetPosition() - center).Magnitude(); - pane->m_nTimer = uint32(dist*100 + CTimer::GetTimeInMilliseconds()); - break; - } - - pane->m_fGroundZ = groundZ; - pane->m_bShattered = cracked; - pane->m_fStep = upLen / float(ysteps); - pane->m_bCarGlass = carGlass; - pane->m_bActive = true; - } - } - } - } -} - -void -CGlass::AskForObjectToBeRenderedInGlass(CEntity *entity) -{ -#ifdef FIX_BUGS - if ( NumGlassEntities < NUM_GLASSENTITIES ) -#else - if ( NumGlassEntities < NUM_GLASSENTITIES-1 ) -#endif - { - apEntitiesToBeRendered[NumGlassEntities++] = entity; - } -} - -void -CGlass::RenderEntityInGlass(CEntity *entity) -{ - ASSERT(entity!=nil); - CObject *object = (CObject *)entity; - - if ( object->bGlassBroken ) - return; - - float distToCamera = (TheCamera.GetPosition() - object->GetPosition()).Magnitude(); - - if ( distToCamera > 40.0f ) - return; - - CVector fwdNorm = object->GetForward(); - fwdNorm.Normalise(); - uint8 alpha = CalcAlphaWithNormal(&fwdNorm); - - CColModel *col = object->GetColModel(); - ASSERT(col!=nil); - if ( col->numTriangles >= 2 ) - { - CVector a = object->GetMatrix() * col->vertices[0].Get(); - CVector b = object->GetMatrix() * col->vertices[1].Get(); - CVector c = object->GetMatrix() * col->vertices[2].Get(); - CVector d = object->GetMatrix() * col->vertices[3].Get(); - - if ( object->bGlassCracked ) - { - uint8 color = 255; - if ( distToCamera > 30.0f ) - color = int32((1.0f - (distToCamera - 30.0f) * 4.0f / 40.0f) * 255); - - if ( TempBufferIndicesStoredShattered >= TEMPBUFFERINDEXSHATTEREDSIZE-13 || TempBufferVerticesStoredShattered >= TEMPBUFFERVERTSHATTEREDSIZE-5 ) - RenderShatteredPolys(); - - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], color, color, color, color); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], color, color, color, color); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], color, color, color, color); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], color, color, color, color); - - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 0.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 0.0f); - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 16.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 0.0f); - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 0.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 16.0f); - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], 16.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], 16.0f); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], a.x, a.y, a.z); - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], b.x, b.y, b.z); - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], c.x, c.y, c.z); - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], d.x, d.y, d.z); - - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 0] = col->triangles[0].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 1] = col->triangles[0].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 2] = col->triangles[0].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 3] = col->triangles[1].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 4] = col->triangles[1].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 5] = col->triangles[1].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 6] = col->triangles[0].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 7] = col->triangles[0].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 8] = col->triangles[0].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 9] = col->triangles[1].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 10] = col->triangles[1].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 11] = col->triangles[1].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; - - TempBufferIndicesStoredShattered += 12; - TempBufferVerticesStoredShattered += 4; - } - - if ( TempBufferIndicesStoredReflection >= TEMPBUFFERINDEXREFLECTIONSIZE-13 || TempBufferVerticesStoredReflection >= TEMPBUFFERVERTREFLECTIONSIZE-5 ) - RenderReflectionPolys(); - - uint8 color = 100; - if ( distToCamera > 30.0f ) - color = int32((1.0f - (distToCamera - 30.0f) * 4.0f / 40.0f) * 100); - - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], color, color, color, color); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], color, color, color, color); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], color, color, color, color); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], color, color, color, color); - - float FwdAngle = CGeneral::GetATanOfXY(TheCamera.GetForward().x, TheCamera.GetForward().y); - float v = 2.0f * TheCamera.GetForward().z * 0.2f; - float u = float(object->m_randomSeed & 15) * 0.02f + (FwdAngle / TWOPI); - - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], u); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], v); - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], u+0.2f); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], v); - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], u); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], v+0.2f); - RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], u+0.2f); - RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], v+0.2f); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], a.x, a.y, a.z); - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], b.x, b.y, b.z); - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], c.x, c.y, c.z); - RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], d.x, d.y, d.z); - - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 0] = col->triangles[0].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 1] = col->triangles[0].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 2] = col->triangles[0].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 3] = col->triangles[1].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 4] = col->triangles[1].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 5] = col->triangles[1].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 6] = col->triangles[0].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 7] = col->triangles[0].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 8] = col->triangles[0].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 9] = col->triangles[1].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 10] = col->triangles[1].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 11] = col->triangles[1].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; - - TempBufferIndicesStoredReflection += 12; - TempBufferVerticesStoredReflection += 4; - } -} - -int32 -CGlass::CalcAlphaWithNormal(CVector *normal) -{ - ASSERT(normal!=nil); - - float fwdDir = 2.0f * DotProduct(*normal, TheCamera.GetForward()); - float fwdDot = DotProduct(TheCamera.GetForward()-fwdDir*(*normal), CVector(0.57f, 0.57f, -0.57f)); - return int32(lerp(fwdDot*fwdDot*fwdDot*fwdDot*fwdDot*fwdDot, 20.0f, 255.0f)); -} - -void -CGlass::RenderHiLightPolys(void) -{ - if ( TempBufferVerticesStoredHiLight != TEMPBUFFERVERTHILIGHTOFFSET ) - { - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)RwTextureGetRaster(gpShadowExplosionTex)); - - LittleTest(); - - if ( RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStoredHiLight, nil, rwIM3D_VERTEXUV) ) - { - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStoredHiLight); - RwIm3DEnd(); - } - - TempBufferVerticesStoredHiLight = TEMPBUFFERVERTHILIGHTOFFSET; - TempBufferIndicesStoredHiLight = TEMPBUFFERINDEXHILIGHTOFFSET; - } -} - -void -CGlass::RenderShatteredPolys(void) -{ - if ( TempBufferVerticesStoredShattered != TEMPBUFFERVERTSHATTEREDOFFSET ) - { - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)RwTextureGetRaster(gpCrackedGlassTex)); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - - LittleTest(); - - if ( RwIm3DTransform(&TempBufferRenderVertices[TEMPBUFFERVERTSHATTEREDOFFSET], TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET, nil, rwIM3D_VERTEXUV) ) - { - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, &TempBufferRenderIndexList[TEMPBUFFERINDEXSHATTEREDOFFSET], TempBufferIndicesStoredShattered - TEMPBUFFERINDEXSHATTEREDOFFSET); - RwIm3DEnd(); - } - - TempBufferIndicesStoredShattered = TEMPBUFFERINDEXSHATTEREDOFFSET; - TempBufferVerticesStoredShattered = TEMPBUFFERVERTSHATTEREDOFFSET; - } -} - -void -CGlass::RenderReflectionPolys(void) -{ - if ( TempBufferVerticesStoredReflection != TEMPBUFFERVERTREFLECTIONOFFSET ) - { - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)RwTextureGetRaster(gpShadowHeadLightsTex)); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - - LittleTest(); - - if ( RwIm3DTransform(&TempBufferRenderVertices[TEMPBUFFERVERTREFLECTIONOFFSET], TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET, nil, rwIM3D_VERTEXUV) ) - { - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, &TempBufferRenderIndexList[TEMPBUFFERINDEXREFLECTIONOFFSET], TempBufferIndicesStoredReflection - TEMPBUFFERINDEXREFLECTIONOFFSET); - RwIm3DEnd(); - } - - TempBufferIndicesStoredReflection = TEMPBUFFERINDEXREFLECTIONOFFSET; - TempBufferVerticesStoredReflection = TEMPBUFFERVERTREFLECTIONOFFSET; - } -} - -void -CGlass::WindowRespondsToCollision(CEntity *entity, float amount, CVector speed, CVector point, bool explosion) -{ - ASSERT(entity!=nil); - - CObject *object = (CObject *)entity; - - if ( object->bGlassBroken ) - return; - - object->bGlassCracked = true; - - CColModel *col = object->GetColModel(); - ASSERT(col!=nil); - - if ( col->numTriangles == 2 ) - { - CVector a = col->vertices[0].Get(); - CVector b = col->vertices[1].Get(); - CVector c = col->vertices[2].Get(); - CVector d = col->vertices[3].Get(); - - float minx = Min(Min(a.x, b.x), Min(c.x, d.x)); - float maxx = Max(Max(a.x, b.x), Max(c.x, d.x)); - float miny = Min(Min(a.y, b.y), Min(c.y, d.y)); - float maxy = Max(Max(a.y, b.y), Max(c.y, d.y)); - float minz = Min(Min(a.z, b.z), Min(c.z, d.z)); - float maxz = Max(Max(a.z, b.z), Max(c.z, d.z)); - - CVector pa = object->GetMatrix() * CVector(minx, miny, minz); - CVector pb = object->GetMatrix() * CVector(maxx, maxy, minz); - - if ( amount > 300.0f ) - { - PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_BREAK_L, object->GetPosition()); - - GeneratePanesForWindow(0, - pa, - CVector(0.0f, 0.0f, maxz-minz), - pb - pa, - speed, point, 0.1f, !!object->bGlassCracked, explosion, 1, false); - } - else - { - PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_BREAK_S, object->GetPosition()); - - GeneratePanesForWindow(1, - pa, - CVector(0.0f, 0.0f, maxz-minz), - pb - pa, - speed, point, 0.1f, !!object->bGlassCracked, explosion, 1, false); - } - } - - object->bGlassBroken = true; - object->bIsVisible = false; - object->bUsesCollision = false; -} - -void -CGlass::WindowRespondsToSoftCollision(CEntity *entity, float amount) -{ - ASSERT(entity!=nil); - - CObject *object = (CObject *)entity; - - if ( entity->bUsesCollision && amount > 50.0f && !object->bGlassCracked ) - { - PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_CRACK, object->GetPosition()); - object->bGlassCracked = true; - } -} - -void -CGlass::WasGlassHitByBullet(CEntity *entity, CVector point) -{ - ASSERT(entity!=nil); - - CObject *object = (CObject *)entity; - - if ( IsGlass(object->GetModelIndex()) ) - { - if ( object->bUsesCollision ) - { - if ( !object->bGlassCracked ) - { - PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_CRACK, object->GetPosition()); - object->bGlassCracked = true; - } - else - { - if ( (CGeneral::GetRandomNumber() & 3) == 2 ) - WindowRespondsToCollision(object, 0.0f, CVector(0.0f, 0.0f, 0.0f), point, false); - } - } - } -} - -void -CGlass::WindowRespondsToExplosion(CEntity *entity, CVector point) -{ - ASSERT(entity!=nil); - - CObject *object = (CObject *)entity; - - if ( object->bUsesCollision ) - { - CVector distToGlass = object->GetPosition() - point; - - float fDistToGlass = distToGlass.Magnitude(); - - if ( fDistToGlass < 10.0f ) - { - distToGlass *= (0.3f / fDistToGlass); // normalise - WindowRespondsToCollision(object, 10000.0f, distToGlass, object->GetPosition(), true); - } - else - { - if ( fDistToGlass < 30.0f ) - object->bGlassCracked = true; - } - } -} - - -void -CGlass::CarWindscreenShatters(CVehicle *vehicle, bool unk) -{ - ASSERT(vehicle!=nil); - - CColModel *col = vehicle->GetColModel(); - ASSERT(col!=nil); - - if ( col->numTriangles < 2 ) - return; - - CColTriangle *tria = nil; - int32 triIndex = -1; - CColTriangle *trib = nil; - - for ( int32 i = 0; i < col->numTriangles; i++ ) - { - CColTriangle *tri = &col->triangles[i]; - if ( tri->surface == SURFACE_GLASS ) - { - if ( tria ) - { - trib = tri; - break; - } - - triIndex = i; - tria = tri; - } - } - - if ( trib == nil ) - return; - - CCollision::CalculateTrianglePlanes(col); - - CColTrianglePlane *triPlanes = col->trianglePlanes; - - if ( triPlanes == nil ) - return; - - CVector planeNormal; - triPlanes[triIndex].GetNormal(planeNormal); - planeNormal = Multiply3x3(vehicle->GetMatrix(), planeNormal); - - CVector vec1 = CrossProduct(vehicle->GetRight(), planeNormal); - vec1.Normalise(); - - CVector vec2 = CrossProduct(planeNormal, vehicle->GetUp()); - vec2.Normalise(); - - CVector v[6]; - float proj1[6]; - float proj2[6]; - - v[0] = col->vertices[tria->a].Get(); - v[1] = col->vertices[tria->b].Get(); - v[2] = col->vertices[tria->c].Get(); - - v[3] = col->vertices[trib->a].Get(); - v[4] = col->vertices[trib->b].Get(); - v[5] = col->vertices[trib->c].Get(); - - v[0] = vehicle->GetMatrix() * v[0]; - v[1] = vehicle->GetMatrix() * v[1]; - v[2] = vehicle->GetMatrix() * v[2]; - v[3] = vehicle->GetMatrix() * v[3]; - v[4] = vehicle->GetMatrix() * v[4]; - v[5] = vehicle->GetMatrix() * v[5]; - - proj1[0] = DotProduct(v[0], vec1); - proj2[0] = DotProduct(v[0], vec2); - proj1[1] = DotProduct(v[1], vec1); - proj2[1] = DotProduct(v[1], vec2); - proj1[2] = DotProduct(v[2], vec1); - proj2[2] = DotProduct(v[2], vec2); - - proj1[3] = DotProduct(v[3], vec1); - proj2[3] = DotProduct(v[3], vec2); - proj1[4] = DotProduct(v[4], vec1); - proj2[4] = DotProduct(v[4], vec2); - proj1[5] = DotProduct(v[5], vec1); - proj2[5] = DotProduct(v[5], vec2); - - int32 originIndex = 0; - float max1 = proj1[0]; - float max2 = proj2[0]; - float origin = proj1[0] + proj2[0]; - - for ( int32 i = 1; i < 6; i++ ) - { - float o = proj1[i] + proj2[i]; - if ( o < origin ) - { - origin = o; - originIndex = i; - } - - if ( proj1[i] > max1 ) - max1 = proj1[i]; - if ( proj2[i] > max2 ) - max2 = proj2[i]; - } - - float bound1 = max1 - proj1[originIndex]; - float bound2 = max2 - proj2[originIndex]; - - PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_BREAK_L, vehicle->GetPosition()); - - CVector center = v[originIndex] + ((0.5f*bound1) * vec1) + ((0.5f*bound2) * vec2); - CVector speed = vehicle->m_vecMoveSpeed; - CVector right = bound2 * vec2; - CVector up = bound1 * vec1; - CVector pos = v[originIndex]; - - GeneratePanesForWindow(2, pos, up, right, speed, center, 0.1f, false, false, 2, true); -} - -bool -CGlass::HasGlassBeenShatteredAtCoors(float x, float y, float z) -{ - CEntity *entity = nil; - float dist = 20.0f; - - int32 nStartX = Max(CWorld::GetSectorIndexX(x - 30.0f), 0); - int32 nStartY = Max(CWorld::GetSectorIndexY(y - 30.0f), 0); - int32 nEndX = Min(CWorld::GetSectorIndexX(x + 30.0f), NUMSECTORS_X-1); - int32 nEndY = Min(CWorld::GetSectorIndexY(y + 30.0f), NUMSECTORS_Y-1); - - CWorld::AdvanceCurrentScanCode(); - - for ( int32 ys = nStartY; ys <= nEndY; ys++ ) - { - for ( int32 xs = nStartX; xs <= nEndX; xs++ ) - { - CSector *sector = CWorld::GetSector(xs, ys); - - ASSERT(sector != nil); - - FindWindowSectorList(sector->m_lists[ENTITYLIST_OBJECTS], &dist, &entity, x, y, z); - FindWindowSectorList(sector->m_lists[ENTITYLIST_DUMMIES], &dist, &entity, x, y, z); - } - } - - if ( entity ) - { - if ( entity->GetType() == ENTITY_TYPE_DUMMY ) - return false; - - return !!((CObject*)entity)->bGlassBroken; - } - - return false; -} - -void -CGlass::FindWindowSectorList(CPtrList &list, float *dist, CEntity **entity, float x, float y, float z) -{ - ASSERT(dist!=nil); - ASSERT(entity!=nil); - - CPtrNode *node = list.first; - - while ( node != nil ) - { - CEntity *ent = (CEntity *)node->item; - uint16 scanCode = ent->m_scanCode; - node = node->next; - - ASSERT(ent!=nil); - - if ( IsGlass(ent->GetModelIndex()) ) - { - if ( scanCode != CWorld::GetCurrentScanCode() ) - { - ent->m_scanCode = CWorld::GetCurrentScanCode(); - - float dst = (CVector(x,y,z) - ent->GetPosition()).Magnitude(); - - if ( dst < *dist ) - { - *dist = dst; - *entity = ent; - } - } - } - } -} - -void -CGlass::BreakGlassPhysically(CVector pos, float radius) -{ - static uint32 breakTime = 0; - - if ( CTimer::GetTimeInMilliseconds() < breakTime + 1000 && CTimer::GetTimeInMilliseconds() >= breakTime ) - return; - - CColSphere sphere; - sphere.piece = 0; - sphere.radius = radius; - sphere.surface = 0; - - for ( int32 i = CPools::GetObjectPool()->GetSize() - 1; i >= 0; i-- ) - { - CObject *object = CPools::GetObjectPool()->GetSlot(i); - if (object) - { - if ( IsGlass(object->GetModelIndex()) ) - { - if ( object->bUsesCollision ) - { - CColModel *col = object->GetColModel(); - ASSERT(col!=nil); - - if ( col->numTriangles < 2 ) - continue; - - bool hit = false; - - CVector dist = pos - object->GetPosition(); - - sphere.center.x = DotProduct(dist, object->GetRight()); - sphere.center.y = DotProduct(dist, object->GetForward()); - sphere.center.z = DotProduct(dist, object->GetUp()); - - CCollision::CalculateTrianglePlanes(col); - - for ( int32 j = 0; j < col->numTriangles; j++ ) - { - if ( CCollision::TestSphereTriangle(sphere, - col->vertices, col->triangles[j], col->trianglePlanes[j]) ) - { - hit = true; - } - } - - if ( hit ) - { - breakTime = CTimer::GetTimeInMilliseconds(); - - if ( object->bGlassCracked ) - { - CVector a = col->vertices[0].Get(); - CVector b = col->vertices[1].Get(); - CVector c = col->vertices[2].Get(); - CVector d = col->vertices[3].Get(); - - float minx = Min(Min(a.x, b.x), Min(c.x, d.x)); - float maxx = Max(Max(a.x, b.x), Max(c.x, d.x)); - float miny = Min(Min(a.y, b.y), Min(c.y, d.y)); - float maxy = Max(Max(a.y, b.y), Max(c.y, d.y)); - float minz = Min(Min(a.z, b.z), Min(c.z, d.z)); - float maxz = Max(Max(a.z, b.z), Max(c.z, d.z)); - - CVector pa = object->GetMatrix() * CVector(minx, miny, minz); - CVector pb = object->GetMatrix() * CVector(maxx, maxy, minz); - - PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_BREAK_S, object->GetPosition()); - - GeneratePanesForWindow(1, - pa, - CVector(0.0f, 0.0f, maxz-minz), - pb - pa, - CVector(0.0f, 0.0f, 0.0f), pos, 0.1f, !!object->bGlassCracked, false, 1, false); - - object->bGlassBroken = true; - object->bIsVisible = false; - object->bUsesCollision = false; - } - else - { - PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_CRACK, object->GetPosition()); - object->bGlassCracked = true; - } - } - } - } - } - } -} \ No newline at end of file diff --git a/src/render/Glass.h b/src/render/Glass.h deleted file mode 100644 index f1c85779..00000000 --- a/src/render/Glass.h +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -class CEntity; -class CVehicle; -class CPtrList; - -class CFallingGlassPane : public CMatrix -{ -public: - CVector m_vecMoveSpeed; - CVector m_vecTurn; - uint32 m_nTimer; - float m_fGroundZ; - float m_fStep; - uint8 m_nTriIndex; - bool m_bActive; - bool m_bShattered; - bool m_bCarGlass; - - CFallingGlassPane() { } - ~CFallingGlassPane() { } - - void Update(void); - void Render(void); -}; - -VALIDATE_SIZE(CFallingGlassPane, 0x70); - -enum -{ - NUM_GLASSTRIANGLES = 5, -}; - -class CGlass -{ - static uint32 NumGlassEntities; - static CEntity *apEntitiesToBeRendered[NUM_GLASSENTITIES]; - static CFallingGlassPane aGlassPanes[NUM_GLASSPANES]; -public: - static void Init(void); - static void Update(void); - static void Render(void); - static CFallingGlassPane *FindFreePane(void); - static void GeneratePanesForWindow(uint32 type, CVector pos, CVector up, CVector right, CVector speed, CVector center, float moveSpeed, bool cracked, bool explosion, int32 stepmul, bool carGlass); - static void AskForObjectToBeRenderedInGlass(CEntity *entity); - static void RenderEntityInGlass(CEntity *entity); - static int32 CalcAlphaWithNormal(CVector *normal); - static void RenderHiLightPolys(void); - static void RenderShatteredPolys(void); - static void RenderReflectionPolys(void); - static void WindowRespondsToCollision(CEntity *entity, float amount, CVector speed, CVector point, bool explosion); - static void WindowRespondsToSoftCollision(CEntity *entity, float amount); - static void WasGlassHitByBullet(CEntity *entity, CVector point); - static void WindowRespondsToExplosion(CEntity *entity, CVector point); - static void CarWindscreenShatters(CVehicle *vehicle, bool unk); - static bool HasGlassBeenShatteredAtCoors(float x, float y, float z); - static void FindWindowSectorList(CPtrList &list, float *dist, CEntity **entity, float x, float y, float z); - static void BreakGlassPhysically(CVector pos, float radius); -}; \ No newline at end of file diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp deleted file mode 100644 index 33f33358..00000000 --- a/src/render/Hud.cpp +++ /dev/null @@ -1,2083 +0,0 @@ -#include "common.h" - -#include "Camera.h" -#include "DMAudio.h" -#include "Clock.h" -#include "Darkel.h" -#include "Hud.h" -#include "Messages.h" -#include "Frontend.h" -#include "Font.h" -#include "Pad.h" -#include "Radar.h" -#include "Replay.h" -#include "Wanted.h" -#include "Sprite.h" -#include "Sprite2d.h" -#include "Text.h" -#include "Timer.h" -#include "Script.h" -#include "TxdStore.h" -#include "User.h" -#include "World.h" -#include "CutsceneMgr.h" -#include "Stats.h" -#include "main.h" -#include "General.h" -#include "VarConsole.h" - -#if defined(FIX_BUGS) - #define SCREEN_SCALE_X_FIX(a) SCREEN_SCALE_X(a) - #define SCREEN_SCALE_Y_FIX(a) SCREEN_SCALE_Y(a) - #define SCALE_AND_CENTER_X_FIX(a) SCALE_AND_CENTER_X(a) -#else - #define SCREEN_SCALE_X_FIX(a) (a) - #define SCREEN_SCALE_Y_FIX(a) (a) - #define SCALE_AND_CENTER_X_FIX(a) (a) -#endif - -// Game has colors inlined in code. -// For easier modification we collect them here: -CRGBA MONEY_COLOR(0, 207, 133, 255); -CRGBA AMMO_COLOR(255, 150, 225, 255); -CRGBA HEALTH_COLOR(255, 150, 225, 255); -CRGBA ARMOUR_COLOR(185, 185, 185, 255); -CRGBA NOTWANTED_COLOR(27, 89, 130, 255); -CRGBA WANTED_COLOR_FLASH(62, 141, 181, 255); -CRGBA WANTED_COLOR(97, 194, 247, 255); -CRGBA ZONE_COLOR(45, 155, 90, 255); -CRGBA VEHICLE_COLOR(97, 194, 247, 255); -CRGBA CLOCK_COLOR(97, 194, 247, 255); -CRGBA TIMER_COLOR(97, 194, 247, 255); -CRGBA COUNTER_COLOR(97, 194, 247, 255); -CRGBA PAGER_COLOR(32, 162, 66, 205); -CRGBA RADARDISC_COLOR(255, 255, 255, 255); -CRGBA BIGMESSAGE_COLOR(255, 150, 225, 255); -CRGBA WASTEDBUSTED_COLOR(0, 207, 133, 255); -CRGBA ODDJOB_COLOR(0, 207, 133, 255); -CRGBA ODDJOB2_COLOR(97, 194, 247, 255); -CRGBA MISSIONTITLE_COLOR(220, 172, 2, 255); - -wchar CHud::m_HelpMessage[HELP_MSG_LENGTH]; -wchar CHud::m_LastHelpMessage[HELP_MSG_LENGTH]; -uint32 CHud::m_HelpMessageState; -uint32 CHud::m_HelpMessageTimer; -int32 CHud::m_HelpMessageFadeTimer; -wchar CHud::m_HelpMessageToPrint[HELP_MSG_LENGTH]; -float CHud::m_HelpMessageDisplayTime; -bool CHud::m_HelpMessageDisplayForever; -bool CHud::m_HelpMessageQuick; -uint32 CHud::m_ZoneState; -int32 CHud::m_ZoneFadeTimer; -uint32 CHud::m_ZoneNameTimer; -wchar *CHud::m_pZoneName; -wchar *CHud::m_pLastZoneName; -wchar *CHud::m_ZoneToPrint; -uint32 CHud::m_VehicleState; -int32 CHud::m_VehicleFadeTimer; -uint32 CHud::m_VehicleNameTimer; -wchar *CHud::m_VehicleName; -wchar *CHud::m_pLastVehicleName; -wchar *CHud::m_pVehicleNameToPrint; -wchar CHud::m_Message[256]; -wchar CHud::m_PagerMessage[256]; -bool CHud::m_Wants_To_Draw_Hud; -bool CHud::m_Wants_To_Draw_3dMarkers; -wchar CHud::m_BigMessage[6][128]; -int16 CHud::m_ItemToFlash; -bool CHud::m_HideRadar; -int32 CHud::m_ClockState; - -// These aren't really in CHud -float CHud::BigMessageInUse[6]; -float CHud::BigMessageAlpha[6]; -float CHud::BigMessageX[6]; -float CHud::OddJob2OffTimer; -bool CHud::CounterOnLastFrame[NUMONSCREENCOUNTERS]; -float CHud::OddJob2XOffset; -uint16 CHud::CounterFlashTimer[NUMONSCREENCOUNTERS]; -uint16 CHud::OddJob2Timer; -bool CHud::TimerOnLastFrame; -int16 CHud::OddJob2On; -uint16 CHud::TimerFlashTimer; -int16 CHud::PagerSoundPlayed; -int32 CHud::SpriteBrightness; -float CHud::PagerXOffset; -int16 CHud::PagerTimer; -int16 CHud::PagerOn; - -wchar *prevChaseString; - -uint32 CHud::m_WantedFadeTimer; -uint32 CHud::m_WantedState; -uint32 CHud::m_WantedTimer; -uint32 CHud::m_EnergyLostFadeTimer; -uint32 CHud::m_EnergyLostState; -uint32 CHud::m_EnergyLostTimer; -uint32 CHud::m_DisplayScoreFadeTimer; -uint32 CHud::m_DisplayScoreState; -uint32 CHud::m_DisplayScoreTimer; -uint32 CHud::m_WeaponFadeTimer; -uint32 CHud::m_WeaponState; -uint32 CHud::m_WeaponTimer; - -uint32 CHud::m_LastDisplayScore; -uint32 CHud::m_LastWanted; -uint32 CHud::m_LastWeapon; -uint32 CHud::m_LastTimeEnergyLost; - -CSprite2d CHud::Sprites[NUM_HUD_SPRITES]; - -struct -{ - const char *name; - const char *mask; -} WeaponFilenames[] = { - { "fist", "fistm" }, - { "brassk", "brasskA" }, - { "screw", "screwA" }, - { "golf", "golfA" }, - { "nightstick", "nightstickA" }, - { "knife", "knifeA" }, - { "bat", "batm" }, - { "hammer", "hammerA" }, - { "cleaver", "cleaverA" }, - { "machete", "macheteA" }, - { "sword", "swordA" }, - { "chainsaw", "chainsawA" }, - { "grenade", "grenadeA" }, - { "grenade", "grenadeA" }, - { "teargas", "teargasA" }, - { "molotov", "molotovA" }, - { "rocket", "rocketA" }, - { "handGun1", "handGun1A" }, - { "", "" }, - { "python", "pythonA" }, - { "chromegun", "chromegunA" }, - { "spasshotGun", "spasshotGunA" }, - { "stubshotGun", "stubshotGunA" }, - { "tec9", "tec9A" }, - { "uzi1", "uzi1A" }, - { "uzi2", "uzi2A" }, - { "mp5", "mp5A" }, - { "", "" }, - { "m4", "m4A" }, - { "ruger", "rugerA" }, - { "sniper", "sniperA" }, - { "laserscope", "laserscopeA" }, - { "", "" }, - { "rocket", "rocketA" }, - { "flamer", "flamerA" }, - { "m60", "m60A" }, - { "minigun", "minigunA" }, - { "bomb", "bombA" }, - { "", "" }, - { "camera", "cameraA" }, - { "", "" }, - { "siterocket", "siterocket" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "radardisc", "radardisc" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "", "" }, - { "sitesniper", "sitesniperm" }, - { "siteM16", "siteM16m" }, - { "sitelaser", "sitelaserm" }, - { "laserdot", "laserdotm" }, - { "viewfinder_128", "viewfinder_128m" }, - { "bleeder", "" } -}; - -RwTexture *gpSniperSightTex; -RwTexture *gpRocketSightTex; -RwTexture *gpLaserSightTex; -RwTexture *gpLaserDotTex; -RwTexture *gpViewFinderTex; - -void CHud::Draw() -{ - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERNEAREST); - RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void*)rwTEXTUREADDRESSCLAMP); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - - // disable hud via second controller - if (CPad::GetPad(1)->GetStartJustDown()) - m_Wants_To_Draw_Hud = !m_Wants_To_Draw_Hud; - - if (CReplay::IsPlayingBack()) - return; - - if (m_Wants_To_Draw_Hud && !TheCamera.m_WideScreenOn) { - // unused statics in here - bool DrawCrossHair = false; - bool CrossHairHidesHud = false; - bool DrawCrossHairPC = false; - - CPlayerPed *playerPed = FindPlayerPed(); - eWeaponType WeaponType = playerPed->GetWeapon()->m_eWeaponType; - int32 Mode = TheCamera.Cams[TheCamera.ActiveCam].Mode; - - if ((Mode == CCam::MODE_SNIPER || Mode == CCam::MODE_ROCKETLAUNCHER || Mode == CCam::MODE_M16_1STPERSON || Mode == CCam::MODE_HELICANNON_1STPERSON || Mode == CCam::MODE_CAMERA) - && playerPed && !playerPed->GetWeapon()->IsTypeMelee()) - DrawCrossHair = true; - - if (Mode == CCam::MODE_M16_1STPERSON_RUNABOUT || Mode == CCam::MODE_ROCKETLAUNCHER_RUNABOUT || Mode == CCam::MODE_SNIPER_RUNABOUT) - DrawCrossHairPC = true; - if (TheCamera.Cams[TheCamera.ActiveCam].Using3rdPersonMouseCam() && (!CPad::GetPad(0)->GetLookBehindForPed() || TheCamera.m_bPlayerIsInGarage) - || Mode == CCam::MODE_1STPERSON_RUNABOUT) { - if (playerPed) { - if (playerPed->m_nPedState != PED_ENTER_CAR && playerPed->m_nPedState != PED_CARJACK) { - - if (WeaponType >= WEAPONTYPE_COLT45 && WeaponType <= WEAPONTYPE_RUGER - || WeaponType == WEAPONTYPE_M60 || WeaponType == WEAPONTYPE_MINIGUN - || WeaponType == WEAPONTYPE_FLAMETHROWER) { - DrawCrossHairPC = 1; - } - } - } - } - - if (DrawCrossHair || DrawCrossHairPC) { - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR); - - SpriteBrightness = Min(SpriteBrightness+1, 30); - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - - float fStep = Sin((CTimer::GetTimeInMilliseconds() & 1023)/1024.0f * 6.28f); - float fMultBright = SpriteBrightness * 0.03f * (0.25f * fStep + 0.75f); - CRect rect; - if (DrawCrossHairPC && TheCamera.Cams[TheCamera.ActiveCam].Using3rdPersonMouseCam()) { - float f3rdX = SCREEN_WIDTH * TheCamera.m_f3rdPersonCHairMultX; - float f3rdY = SCREEN_HEIGHT * TheCamera.m_f3rdPersonCHairMultY; -#ifdef ASPECT_RATIO_SCALE - f3rdY -= SCREEN_SCALE_Y(2.0f); -#endif - if (playerPed && (WeaponType == WEAPONTYPE_M4 || WeaponType == WEAPONTYPE_RUGER || WeaponType == WEAPONTYPE_M60)) { - rect.left = f3rdX - SCREEN_SCALE_X(32.0f * 0.6f); - rect.top = f3rdY - SCREEN_SCALE_Y(32.0f * 0.6f); - rect.right = f3rdX + SCREEN_SCALE_X(32.0f * 0.6f); - rect.bottom = f3rdY + SCREEN_SCALE_Y(32.0f * 0.6f); - - Sprites[HUD_SITEM16].Draw(CRect(rect), CRGBA(255, 255, 255, 255), - 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); - } - else { - rect.left = f3rdX - SCREEN_SCALE_X(32.0f * 0.4f); - rect.top = f3rdY - SCREEN_SCALE_Y(32.0f * 0.4f); - rect.right = f3rdX + SCREEN_SCALE_X(32.0f * 0.4f); - rect.bottom = f3rdY + SCREEN_SCALE_Y(32.0f * 0.4f); - - Sprites[HUD_SITEM16].Draw(CRect(rect), CRGBA(255, 255, 255, 255), - 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); - } - } else { - if (Mode == CCam::MODE_M16_1STPERSON || - Mode == CCam::MODE_M16_1STPERSON_RUNABOUT || - Mode == CCam::MODE_HELICANNON_1STPERSON) { - rect.left = (SCREEN_WIDTH / 2) - SCREEN_SCALE_X(32.0f); - rect.top = (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(32.0f); - rect.right = (SCREEN_WIDTH / 2) + SCREEN_SCALE_X(32.0f); - rect.bottom = (SCREEN_HEIGHT / 2) + SCREEN_SCALE_Y(32.0f); - Sprites[HUD_SITEM16].Draw(CRect(rect), CRGBA(255, 255, 255, 255), - 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); - } - else if (Mode == CCam::MODE_1STPERSON_RUNABOUT) { - rect.left = (SCREEN_WIDTH / 2) - SCREEN_SCALE_X(32.0f * 0.7f); - rect.top = (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(32.0f * 0.7f); - rect.right = (SCREEN_WIDTH / 2) + SCREEN_SCALE_X(32.0f * 0.7f); - rect.bottom = (SCREEN_HEIGHT / 2) + SCREEN_SCALE_Y(32.0f * 0.7f); - - Sprites[HUD_SITEM16].Draw(CRect(rect), CRGBA(255, 255, 255, 255), - 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); - } - else if (Mode == CCam::MODE_ROCKETLAUNCHER || Mode == CCam::MODE_ROCKETLAUNCHER_RUNABOUT) { - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpRocketSightTex)); - - CSprite::RenderOneXLUSprite(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 1.0f, SCREEN_SCALE_X(40.0f), SCREEN_SCALE_Y(40.0f), (100.0f * fMultBright), (200.0f * fMultBright), (100.0f * fMultBright), 255, 1.0f, 255); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - } - else { - int sprite = HUD_SITESNIPER; - float xOffset = SCREEN_SCALE_X(210.0f); - float yOffset = SCREEN_SCALE_Y(210.0f); - - if (FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_LASERSCOPE) - sprite = HUD_SITELASER; - - if (FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_CAMERA) { - sprite = HUD_VIEWFINDER; - CrossHairHidesHud = true; - xOffset = SCREEN_SCALE_X(256.0f); - yOffset = SCREEN_SCALE_Y(192.0f); - } - - rect.left = SCREEN_WIDTH/2 - xOffset; - rect.top = SCREEN_HEIGHT/2 - yOffset; - rect.right = SCREEN_WIDTH/2; - rect.bottom = SCREEN_HEIGHT/2; - Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), - 0.01f, 0.01f, 1.0f, 0.0f, 0.01f, 1.0f, 1.0f, 1.0f); - - rect.left = SCREEN_WIDTH/2; - rect.top = SCREEN_HEIGHT/2 - yOffset; - rect.right = SCREEN_WIDTH/2 + xOffset; - rect.bottom = SCREEN_HEIGHT/2; - Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), - 0.99f, 0.0f, 0.01f, 0.01f, 0.99f, 1.0f, 0.01f, 1.0f); - - rect.left = SCREEN_WIDTH/2 - xOffset; - rect.top = SCREEN_HEIGHT/2; - rect.right = SCREEN_WIDTH/2; - rect.bottom = SCREEN_HEIGHT/2 + yOffset; - Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), - 0.01f, 0.99f, 1.0f, 0.99f, 0.01f, 0.01f, 1.0f, 0.01f); - - rect.left = SCREEN_WIDTH/2; - rect.top = SCREEN_HEIGHT/2; - rect.right = SCREEN_WIDTH/2 + xOffset; - rect.bottom = SCREEN_HEIGHT/2 + yOffset; - Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), - 0.99f, 0.99f, 0.01f, 0.99f, 0.99f, 0.01f, 0.01f, 0.01f); - - CVector dotPos; - float size = 25.0f; - if (FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_LASERSCOPE && FindPlayerPed()->GetWeapon()->LaserScopeDot(&dotPos, &size)) { - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); -#ifdef FIX_BUGS - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); -#else - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVDESTALPHA); -#endif - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpLaserDotTex)); -#ifdef FIX_BUGS - int intensity = CGeneral::GetRandomNumberInRange(0, 37); -#else - int intensity = CGeneral::GetRandomNumberInRange(0, 35); -#endif - CSprite::RenderOneXLUSprite(dotPos.x, dotPos.y, dotPos.z, - SCREEN_SCALE_X(size), SCREEN_SCALE_Y(size), intensity - 36, 0, 0, intensity - 36, 1.0f, 127); - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - } - } - } - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - } - else { - SpriteBrightness = 0; - } - - if (CrossHairHidesHud) - return; - - /* - DrawMoneyCounter - */ - - wchar sPrint[16]; - wchar sPrintIcon[16]; - char sTemp[16]; - float alpha; - - if (m_LastDisplayScore == CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney) { - alpha = DrawFadeState(HUD_SCORE_FADING, 0); - } else { - alpha = DrawFadeState(HUD_SCORE_FADING, 1); - m_LastDisplayScore = CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney; - } - if (m_DisplayScoreState != FADED_OUT) { - sprintf(sTemp, "$%08d", CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney); - AsciiToUnicode(sTemp, sPrint); - - CFont::SetPropOff(); - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetCentreOff(); - CFont::SetRightJustifyOn(); - CFont::SetRightJustifyWrap(0.0f); - CFont::SetBackGroundOnlyTextOff(); - CFont::SetFontStyle(FONT_HEADING); - CFont::SetPropOff(); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, alpha)); - MONEY_COLOR.a = alpha; - CFont::SetColor(MONEY_COLOR); - - if (FrontEndMenuManager.m_PrefsShowHud) { - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f), SCREEN_SCALE_Y(43.0f), sPrint); - } - } - - /* - DrawAmmo - */ - if (m_LastWeapon == playerPed->GetWeapon()->m_eWeaponType) { - alpha = CHud::DrawFadeState(HUD_WEAPON_FADING, 0); - } else { - alpha = CHud::DrawFadeState(HUD_WEAPON_FADING, 1); - m_LastWeapon = playerPed->GetWeapon()->m_eWeaponType; - } - if (m_WeaponState != FADED_OUT) { - CWeapon *weapon = playerPed->GetWeapon(); - int32 AmmoAmount = CWeaponInfo::GetWeaponInfo((eWeaponType)WeaponType)->m_nAmountofAmmunition; - int32 AmmoInClip = weapon->m_nAmmoInClip; - int32 TotalAmmo = weapon->m_nAmmoTotal; - int32 Ammo, Clip; - - if (AmmoAmount <= 1 || AmmoAmount >= 1000) - sprintf(sTemp, "%d", TotalAmmo); - else { - if (WeaponType == WEAPONTYPE_FLAMETHROWER) { - Clip = AmmoInClip / 10; - - Ammo = Min((TotalAmmo - AmmoInClip) / 10, 9999); - } else { - Clip = AmmoInClip; - - Ammo = Min(TotalAmmo - AmmoInClip, 9999); - } - - sprintf(sTemp, "%d-%d", Ammo, Clip); - } - - AsciiToUnicode(sTemp, sPrint); - CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo((eWeaponType)WeaponType); - /* - DrawWeaponIcon - */ - - if (FrontEndMenuManager.m_PrefsShowHud) { - if (weaponInfo->m_nModelId <= 0) { - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); - if (FrontEndMenuManager.m_PrefsShowHud) - Sprites[WeaponType].Draw( - CRect(SCREEN_SCALE_FROM_RIGHT(99.0f), SCREEN_SCALE_Y(27.0f), SCREEN_SCALE_FROM_RIGHT(35.0f), SCREEN_SCALE_Y(91.0f)), - CRGBA(255, 255, 255, alpha), - 0.015f, 0.015f, - 1.0f, 0.0f, - 0.015f, 1.0f, - 1.0f, 1.0f); - } else { - CBaseModelInfo *weaponModel = CModelInfo::GetModelInfo(weaponInfo->m_nModelId); - RwTexDictionary *weaponTxd = CTxdStore::GetSlot(weaponModel->GetTxdSlot())->texDict; - if (weaponTxd) { - RwTexture *weaponIcon = RwTexDictionaryFindNamedTexture(weaponTxd, weaponModel->GetModelName()); - if (weaponIcon) { - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); -#ifndef FIX_BUGS - const float xSize = SCREEN_SCALE_X(64.0f / 2.0f); - const float ySize = SCREEN_SCALE_Y(64.0f / 2.0f); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(weaponIcon)); - CSprite::RenderOneXLUSprite(SCREEN_SCALE_FROM_RIGHT(99.0f) + xSize, SCREEN_SCALE_Y(25.0f) + ySize, 1.0f, xSize, ySize, - 255, 255, 255, 255, 1.0f, 255); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); -#else - static CSprite2d sprite; - sprite.m_pTexture = weaponIcon; - sprite.Draw( - CRect(SCREEN_SCALE_FROM_RIGHT(99.0f), SCREEN_SCALE_Y(27.0f), SCREEN_SCALE_FROM_RIGHT(35.0f), SCREEN_SCALE_Y(91.0f)), - CRGBA(255, 255, 255, alpha), - 0.015f, 0.015f, - 1.0f, 0.0f, - 0.015f, 1.0f, - 1.0f, 1.0f); - sprite.m_pTexture = nil; -#endif - } - } - } - - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(0.5f), SCREEN_SCALE_Y(0.8f)); - CFont::SetJustifyOff(); - CFont::SetCentreOn(); - CFont::SetCentreSize(SCREEN_STRETCH_X(DEFAULT_SCREEN_WIDTH)); - CFont::SetPropOn(); - CFont::SetDropShadowPosition(0); - CFont::SetFontStyle(FONT_STANDARD); - - if (Min(9999, TotalAmmo - AmmoInClip) != 9999 && !CDarkel::FrenzyOnGoing() && weaponInfo->m_nWeaponSlot > 1 && weapon->m_eWeaponType != WEAPONTYPE_DETONATOR) { - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, alpha)); - AMMO_COLOR.a = alpha; - CFont::SetColor(AMMO_COLOR); - if (FrontEndMenuManager.m_PrefsShowHud) - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(66.0f), SCREEN_SCALE_Y(90.0f), sPrint); - CFont::SetDropShadowPosition(0); - } - } - } - - /* - DrawHealth - */ - if ( m_LastTimeEnergyLost == CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss ) { - CHud::DrawFadeState(HUD_ENERGY_FADING, 0); - } else { - CHud::DrawFadeState(HUD_ENERGY_FADING, 1); - m_LastTimeEnergyLost = CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss; - } - - if (m_EnergyLostState != FADED_OUT) { - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetJustifyOff(); - CFont::SetCentreOff(); - CFont::SetRightJustifyWrap(0.0f); - CFont::SetRightJustifyOn(); - CFont::SetPropOff(); - CFont::SetFontStyle(FONT_HEADING); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - - if (m_ItemToFlash == ITEM_HEALTH && CTimer::GetFrameCounter() & 8 - || m_ItemToFlash != ITEM_HEALTH - || playerPed->m_fHealth < 10 - && CTimer::GetFrameCounter() & 8) { - if (playerPed->m_fHealth >= 10 - || playerPed->m_fHealth < 10 && CTimer::GetFrameCounter() & 8) { - - AsciiToUnicode("{", sPrintIcon); -#ifdef FIX_BUGS - sprintf(sTemp, "%03d", int32(playerPed->m_fHealth + 0.5f)); -#else - sprintf(sTemp, "%03d", (int32)playerPed->m_fHealth); -#endif - AsciiToUnicode(sTemp, sPrint); - - CFont::SetColor(HEALTH_COLOR); - if (FrontEndMenuManager.m_PrefsShowHud) { - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f), SCREEN_SCALE_Y(65.0f), sPrint); - - if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss + 2000 || CTimer::GetFrameCounter() & 4) { - // CFont::SetColor(HEALTH_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 54.0f), SCREEN_SCALE_Y(65.0f), sPrintIcon); - } - } - } - } - - /* - DrawArmour - */ - if (m_ItemToFlash == ITEM_ARMOUR && CTimer::GetFrameCounter() & 8 || m_ItemToFlash != ITEM_ARMOUR) { - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - if (playerPed->m_fArmour > 1.0f) { - AsciiToUnicode("<", sPrintIcon); -#ifdef FIX_BUGS - sprintf(sTemp, "%03d", int32(playerPed->m_fArmour + 0.5f)); -#else - sprintf(sTemp, "%03d", (int32)playerPed->m_fArmour); -#endif - AsciiToUnicode(sTemp, sPrint); - - CFont::SetColor(ARMOUR_COLOR); - if (FrontEndMenuManager.m_PrefsShowHud) { - - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f), SCREEN_SCALE_Y(65.0f), sPrint); - - if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss + 2000 || CTimer::GetFrameCounter() & 4) { - // CFont::SetColor(ARMOUR_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f + 52.0f), SCREEN_SCALE_Y(65.0f), sPrintIcon); - } - } - } - } - } - - /* - DrawWantedLevel - */ - if (m_LastWanted == playerPed->m_pWanted->GetWantedLevel()) { - alpha = DrawFadeState(HUD_WANTED_FADING, 0); - } else { - alpha = DrawFadeState(HUD_WANTED_FADING, 1); - m_LastWanted = playerPed->m_pWanted->GetWantedLevel(); - } - - if (m_WantedState != FADED_OUT) { - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetJustifyOff(); - CFont::SetCentreOff(); - CFont::SetRightJustifyOn(); - CFont::SetPropOn(); - CFont::SetFontStyle(FONT_STANDARD); - - AsciiToUnicode(">", sPrintIcon); - - for (int i = 0; i < 6; i++) { - if (FrontEndMenuManager.m_PrefsShowHud) { - if (playerPed->m_pWanted->GetWantedLevel() > i - && (CTimer::GetTimeInMilliseconds() > playerPed->m_pWanted->m_nLastWantedLevelChange - + 2000 || CTimer::GetFrameCounter() & 4)) { - - WANTED_COLOR.a = alpha; - CFont::SetColor(WANTED_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(87.0f), sPrintIcon); - - } else if (playerPed->m_pWanted->m_nMinWantedLevel > i && CTimer::GetFrameCounter() & 4) { - WANTED_COLOR_FLASH.a = alpha; - CFont::SetColor(WANTED_COLOR_FLASH); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(87.0f), sPrintIcon); - - } else if (playerPed->m_pWanted->GetWantedLevel() <= i) { - NOTWANTED_COLOR.a = alpha; - CFont::SetColor(NOTWANTED_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(87.0f), sPrintIcon); - } - } - } - } - - static int32 nMediaLevelCounter = 0; - if (CStats::ShowChaseStatOnScreen != 0) { - float fCurAttentionLevel = CWorld::Players[CWorld::PlayerInFocus].m_fMediaAttention; - if (0.7f * CStats::HighestChaseValue > fCurAttentionLevel - || fCurAttentionLevel <= 40.0f || CTheScripts::IsPlayerOnAMission()) { - nMediaLevelCounter = 0; - } - else { - if (fCurAttentionLevel == CStats::HighestChaseValue) { - sprintf(gString, "%s %d", UnicodeToAscii(TheText.Get("CHSE")), (int32)fCurAttentionLevel); - } - else { - sprintf(gString, "%s %d" "-%d-", UnicodeToAscii(TheText.Get("CHSE")), (int32)fCurAttentionLevel, (int32)CStats::HighestChaseValue); - } - AsciiToUnicode(gString, gUString); - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetCentreOff(); - CFont::SetRightJustifyOn(); - CFont::SetRightJustifyWrap(0.0f); - CFont::SetBackGroundOnlyTextOff(); - CFont::SetFontStyle(FONT_HEADING); - CFont::SetPropOff(); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - - CRGBA colour; - if (CTimer::GetTimeInMilliseconds() & 0x200) - colour = CRGBA(204, 0, 185, 180); - else - colour = CRGBA(178, 0, 162, 180); - CFont::SetColor(colour); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f), SCREEN_SCALE_Y(113.0f), gUString); - - if (CStats::FindChaseString(fCurAttentionLevel) != prevChaseString) { - prevChaseString = CStats::FindChaseString(fCurAttentionLevel); - nMediaLevelCounter = 100; - } - - if (nMediaLevelCounter != 0) { - nMediaLevelCounter--; - UnicodeMakeUpperCase(gUString, CStats::FindChaseString(fCurAttentionLevel)); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f), SCREEN_SCALE_Y(138.0f), gUString); - } - } - } - - /* - DrawZoneName - */ - if (m_pZoneName) { - - if (m_pZoneName != m_pLastZoneName) { - switch (m_ZoneState) { - case 0: - m_ZoneState = 2; - m_ZoneToPrint = m_pZoneName; - m_ZoneNameTimer = 0; - m_ZoneFadeTimer = 0; - if (m_VehicleState == 1 || m_VehicleState == 2) - m_VehicleState = 3; - break; - case 1: - case 2: - case 3: - case 4: - m_ZoneNameTimer = 5; - m_ZoneState = 4; - break; - default: - break; - } - m_pLastZoneName = m_pZoneName; - } - - float fZoneAlpha = 255.0f; - if (m_ZoneState) { - switch (m_ZoneState) { - case 1: - fZoneAlpha = 255.0f; - m_ZoneFadeTimer = 1000; - if (m_ZoneNameTimer > 10000.0f) { - m_ZoneFadeTimer = 1000; - m_ZoneState = 3; - } - break; - case 2: - m_ZoneFadeTimer += CTimer::GetTimeStepInMilliseconds(); - if (m_ZoneFadeTimer > 1000.0f) { - m_ZoneState = 1; - m_ZoneFadeTimer = 1000; - } - fZoneAlpha = m_ZoneFadeTimer * 0.001f * 255.0f; - break; - case 3: - m_ZoneFadeTimer -= CTimer::GetTimeStepInMilliseconds(); - if (m_ZoneFadeTimer < 0.0f) { - m_ZoneState = 0; - m_ZoneFadeTimer = 0; - } - fZoneAlpha = m_ZoneFadeTimer * 0.001f * 255.0f; - break; - case 4: - m_ZoneFadeTimer -= CTimer::GetTimeStepInMilliseconds(); - if (m_ZoneFadeTimer < 0.0f) { - m_ZoneFadeTimer = 0; - m_ZoneToPrint = m_pLastZoneName; - m_ZoneState = 2; - } - fZoneAlpha = m_ZoneFadeTimer * 0.001f * 255.0f; - break; - default: - break; - - } - - if (!m_Message[0] && BigMessageInUse[1] == 0.0f && BigMessageInUse[2] == 0.0f) { - - m_ZoneNameTimer += CTimer::GetTimeStepInMilliseconds(); - CFont::SetJustifyOff(); - CFont::SetPropOn(); - CFont::SetBackgroundOff(); - - if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) - CFont::SetScale(SCREEN_SCALE_X(1.7f * 0.8f), SCREEN_SCALE_Y(1.8f)); - else - CFont::SetScale(SCREEN_SCALE_X(1.7f), SCREEN_SCALE_Y(1.8f)); - - CFont::SetSlantRefPoint(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(128.0f)); - CFont::SetSlant(0.15f); - - CFont::SetRightJustifyOn(); - CFont::SetRightJustifyWrap(0.0f); - CFont::SetBackGroundOnlyTextOff(); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, fZoneAlpha)); - CFont::SetFontStyle(FONT_BANK); - CFont::SetColor(CRGBA(ZONE_COLOR.r, ZONE_COLOR.g, ZONE_COLOR.b, fZoneAlpha)); - - if (!CTheScripts::bPlayerIsInTheStatium) - CFont::PrintStringFromBottom(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(128.0f), m_ZoneToPrint); - - CFont::SetSlant(0.f); - } else { - m_ZoneState = 3; - } - } - } - - /* - DrawVehicleName - */ - if (m_VehicleName) { - float fVehicleAlpha = 0.0f; - - if (m_VehicleName != m_pLastVehicleName) { - switch (m_VehicleState) { - case 0: - m_VehicleState = 2; - m_pVehicleNameToPrint = m_VehicleName; - m_VehicleNameTimer = 0; - m_VehicleFadeTimer = 0; - if (m_ZoneState == 1 || m_ZoneState == 2) - m_ZoneState = 3; - break; - case 1: - case 2: - case 3: - case 4: - m_VehicleNameTimer = 0; - m_VehicleState = 4; - break; - default: - break; - } - m_pLastVehicleName = m_VehicleName; - } - - if (m_VehicleState) { - switch (m_VehicleState) { - case 1: - if (m_VehicleNameTimer > 10000) { - m_VehicleFadeTimer = 1000; - m_VehicleState = 3; - } - fVehicleAlpha = 255.0f; - break; - case 2: - m_VehicleFadeTimer += CTimer::GetTimeStepInMilliseconds(); - if (m_VehicleFadeTimer > 1000) { - m_VehicleState = 1; - m_VehicleFadeTimer = 1000; - } - fVehicleAlpha = m_VehicleFadeTimer * 0.001f * 255.0f; - break; - case 3: - m_VehicleFadeTimer -= CTimer::GetTimeStepInMilliseconds(); - if (m_VehicleFadeTimer < 0) { - m_VehicleState = 0; - m_VehicleFadeTimer = 0; - } - fVehicleAlpha = m_VehicleFadeTimer * 0.001f * 255.0f; - break; - case 4: - m_VehicleFadeTimer -= CTimer::GetTimeStepInMilliseconds(); - if (m_VehicleFadeTimer < 0) { - m_VehicleFadeTimer = 0; - m_pVehicleNameToPrint = m_pLastVehicleName; - m_VehicleNameTimer = 0; - m_VehicleState = 2; - } - fVehicleAlpha = m_VehicleFadeTimer * 0.001f * 255.0f; - break; - default: - break; - } - - if (!m_Message[0]) { - m_VehicleNameTimer += CTimer::GetTimeStepInMilliseconds(); - CFont::SetJustifyOff(); - CFont::SetPropOn(); - CFont::SetBackgroundOff(); - - if (FrontEndMenuManager.m_PrefsLanguage != CMenuManager::LANGUAGE_ITALIAN && FrontEndMenuManager.m_PrefsLanguage != CMenuManager::LANGUAGE_SPANISH) - CFont::SetScale(SCREEN_SCALE_X(1.7f), SCREEN_SCALE_Y(1.8f)); - else - CFont::SetScale(SCREEN_SCALE_X(1.7f * 0.85f), SCREEN_SCALE_Y(1.8f)); - - CFont::SetSlantRefPoint(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(105.0f)); - CFont::SetSlant(0.15f); - - CFont::SetRightJustifyOn(); - CFont::SetRightJustifyWrap(0.0f); - CFont::SetBackGroundOnlyTextOff(); - CFont::SetFontStyle(FONT_BANK); - CFont::SetDropShadowPosition(2); - CFont::SetColor(CRGBA(VEHICLE_COLOR.r, VEHICLE_COLOR.g, VEHICLE_COLOR.b, fVehicleAlpha)); - CFont::SetDropColor(CRGBA(0, 0, 0, fVehicleAlpha)); - - CFont::PrintStringFromBottom(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(105.0f), m_pVehicleNameToPrint); - - CFont::SetSlant(0.f); - } - } - } - else { - m_pLastVehicleName = nil; - m_VehicleState = 0; - m_VehicleFadeTimer = 0; - m_VehicleNameTimer = 0; - } - - /* - DrawClock - */ - if (m_ClockState) { - CFont::SetJustifyOff(); - CFont::SetCentreOff(); - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetBackGroundOnlyTextOff(); - CFont::SetPropOff(); - CFont::SetFontStyle(FONT_HEADING); - CFont::SetRightJustifyOn(); - CFont::SetRightJustifyWrap(0.0f); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - - sprintf(sTemp, "%02d:%02d", CClock::GetHours(), CClock::GetMinutes()); - AsciiToUnicode(sTemp, sPrint); - - CFont::SetColor(CLOCK_COLOR); - if (FrontEndMenuManager.m_PrefsShowHud) - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(111.0f), SCREEN_SCALE_Y(22.0f), sPrint); - } - - /* - DrawOnScreenTimer - */ - - wchar sTimer[16]; - - if (!CUserDisplay::OnscnTimer.m_sClocks[0].m_bClockProcessed) - TimerOnLastFrame = false; - - for(uint32 i = 0; i < NUMONSCREENCOUNTERS; i++) { - if (!CUserDisplay::OnscnTimer.m_sCounters[0].m_bCounterProcessed) - CounterOnLastFrame[i] = false; - } - - if (CUserDisplay::OnscnTimer.m_bProcessed) { - if (CUserDisplay::OnscnTimer.m_sClocks[0].m_bClockProcessed) { - if (!TimerOnLastFrame) - TimerFlashTimer = 1; - - TimerOnLastFrame = true; - - if (TimerFlashTimer != 0) { - if (++TimerFlashTimer > 50) - TimerFlashTimer = 0; - } - - if (CTimer::GetFrameCounter() & 4 || TimerFlashTimer == 0) { - AsciiToUnicode(CUserDisplay::OnscnTimer.m_sClocks[0].m_aClockBuffer, sTimer); - CFont::SetPropOn(); - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetRightJustifyOn(); - CFont::SetRightJustifyWrap(0.0f); - CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); - CFont::SetPropOff(); - CFont::SetBackGroundOnlyTextOn(); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetColor(TIMER_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f), SCREEN_SCALE_Y(110.0f), sTimer); - CFont::SetPropOn(); - - if (CUserDisplay::OnscnTimer.m_sClocks[0].m_aClockText[0]) { - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - CFont::SetColor(TIMER_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f) - SCREEN_SCALE_X(80.0f), SCREEN_SCALE_Y(110.0f), TheText.Get(CUserDisplay::OnscnTimer.m_sClocks[0].m_aClockText)); - } - } - } - - for(uint32 i = 0; i < NUMONSCREENCOUNTERS; i++) { - if (CUserDisplay::OnscnTimer.m_sCounters[i].m_bCounterProcessed) { - if (!CounterOnLastFrame[i]) - CounterFlashTimer[i] = 1; - - CounterOnLastFrame[i] = true; - - if (CounterFlashTimer[i] != 0) { - if (++CounterFlashTimer[i] > 50) - CounterFlashTimer[i] = 0; - } - - if (CTimer::GetFrameCounter() & 4 || CounterFlashTimer[i] == 0) { - if (CUserDisplay::OnscnTimer.m_sCounters[i].m_nType == COUNTER_DISPLAY_NUMBER) { - AsciiToUnicode(CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterBuffer, sTimer); - CFont::SetPropOn(); - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetCentreOff(); - CFont::SetRightJustifyOn(); - CFont::SetRightJustifyWrap(0.0f); - CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); - CFont::SetWrapx(SCREEN_STRETCH_X(DEFAULT_SCREEN_WIDTH)); - CFont::SetPropOn(); - CFont::SetBackGroundOnlyTextOn(); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - CFont::SetColor(COUNTER_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y * 20.f * i) + SCREEN_SCALE_Y(132.0f), sTimer); - } else { - int counter = atoi(CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterBuffer); - - const float barWidth = SCREEN_SCALE_X(100.f / 2.f); - const float right = SCREEN_SCALE_FROM_RIGHT(37.0f); - const float left = right - barWidth; - - const float barHeight = SCREEN_SCALE_Y(11.0f); - const float top = SCREEN_SCALE_Y(132.0f) + SCREEN_SCALE_Y(8.0f) + SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y * 20.f * i); - const float bottom = top + barHeight; - - // shadow - CSprite2d::DrawRect(CRect(left + SCREEN_SCALE_X(6.0f), top + SCREEN_SCALE_Y(2.0f), right + SCREEN_SCALE_X(6.0f), bottom + SCREEN_SCALE_Y(2.0f)), CRGBA(0, 0, 0, 255)); - - CSprite2d::DrawRect(CRect(left + SCREEN_SCALE_X(4.0f), top, right + SCREEN_SCALE_X(4.0f), bottom), CRGBA(27, 89, 130, 255)); - CSprite2d::DrawRect(CRect(left + SCREEN_SCALE_X(4.0f), top, left + SCREEN_SCALE_X(counter) / 2.0f + SCREEN_SCALE_X(4.0f), bottom), CRGBA(97, 194, 247, 255)); - } - - if (CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterText[0]) { - CFont::SetPropOn(); - CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); - CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - CFont::SetColor(COUNTER_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f) - SCREEN_SCALE_X(61.0f), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y * 20.f * i) + SCREEN_SCALE_Y(132.0f), TheText.Get(CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterText)); - } - // unused/leftover color. I wonder what was it for - CFont::SetColor(CRGBA(244, 225, 91, 255)); - } - } - } - } - - /* - DrawRadar - */ - if (FrontEndMenuManager.m_PrefsRadarMode != 2 && - !m_HideRadar && (m_ItemToFlash == ITEM_RADAR && CTimer::GetFrameCounter() & 8 || m_ItemToFlash != ITEM_RADAR)) { - - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERNEAREST); - CRadar::DrawMap(); - if (FrontEndMenuManager.m_PrefsRadarMode != 1) { - CRect rect(0.0f, 0.0f, SCREEN_SCALE_X(RADAR_WIDTH), SCREEN_SCALE_Y(RADAR_HEIGHT)); - - rect.Translate(SCREEN_SCALE_X_FIX(RADAR_LEFT), SCREEN_SCALE_FROM_BOTTOM(RADAR_BOTTOM + RADAR_HEIGHT)); - -#ifdef FIX_BUGS - rect.Grow(SCREEN_SCALE_X(6.0f), SCREEN_SCALE_X(6.0f), SCREEN_SCALE_Y(6.0f), SCREEN_SCALE_Y(6.0f)); -#else - rect.Grow(6.0f); -#endif - rect.Translate(SCREEN_SCALE_X_FIX(0.0f), SCREEN_SCALE_Y_FIX(2.0f)); - Sprites[HUD_RADARDISC].Draw(rect, CRGBA(0, 0, 0, 255)); - rect.Translate(SCREEN_SCALE_X_FIX(0.0f), SCREEN_SCALE_Y_FIX(-2.0f)); - Sprites[HUD_RADARDISC].Draw(rect, RADARDISC_COLOR); - } - CRadar::DrawBlips(); - } - } - - /* - Draw3dMarkers - */ - if (m_Wants_To_Draw_3dMarkers && !TheCamera.m_WideScreenOn && !m_BigMessage[0][0] && !m_BigMessage[2][0]) { - CRadar::Draw3dMarkers(); - } - - /* - DrawScriptText - */ - if (!CTimer::GetIsUserPaused()) { - for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroTextLines); i++) { - if (CTheScripts::IntroTextLines[i].m_Text[0] && CTheScripts::IntroTextLines[i].m_bTextBeforeFade) { - CFont::SetScale(SCREEN_SCALE_X(CTheScripts::IntroTextLines[i].m_fScaleX), SCREEN_SCALE_Y(CTheScripts::IntroTextLines[i].m_fScaleY * 0.5f)); - CFont::SetColor(CTheScripts::IntroTextLines[i].m_sColor); - - if (CTheScripts::IntroTextLines[i].m_bJustify) - CFont::SetJustifyOn(); - else - CFont::SetJustifyOff(); - - if (CTheScripts::IntroTextLines[i].m_bRightJustify) - CFont::SetRightJustifyOn(); - else - CFont::SetRightJustifyOff(); - - if (CTheScripts::IntroTextLines[i].m_bCentered) - CFont::SetCentreOn(); - else - CFont::SetCentreOff(); - - CFont::SetWrapx(SCALE_AND_CENTER_X(CTheScripts::IntroTextLines[i].m_fWrapX)); - CFont::SetCentreSize(SCREEN_SCALE_X(CTheScripts::IntroTextLines[i].m_fCenterSize)); - - if (CTheScripts::IntroTextLines[i].m_bBackground) - CFont::SetBackgroundOn(); - else - CFont::SetBackgroundOff(); - - CFont::SetBackgroundColor(CTheScripts::IntroTextLines[i].m_sBackgroundColor); - - if (CTheScripts::IntroTextLines[i].m_bBackgroundOnly) - CFont::SetBackGroundOnlyTextOn(); - else - CFont::SetBackGroundOnlyTextOff(); - - if (CTheScripts::IntroTextLines[i].m_bTextProportional) - CFont::SetPropOn(); - else - CFont::SetPropOff(); - - CFont::SetFontStyle(FONT_LOCALE(CTheScripts::IntroTextLines[i].m_nFont)); - CFont::PrintString(SCREEN_WIDTH - SCALE_AND_CENTER_X(DEFAULT_SCREEN_WIDTH - CTheScripts::IntroTextLines[i].m_fAtX), SCREEN_HEIGHT - SCREEN_SCALE_Y(DEFAULT_SCREEN_HEIGHT - CTheScripts::IntroTextLines[i].m_fAtY), CTheScripts::IntroTextLines[i].m_Text); - } - } - for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroRectangles); i++) { - intro_script_rectangle &IntroRect = CTheScripts::IntroRectangles[i]; - - // Yeah, top and bottom changed place. R* vision - if (IntroRect.m_bIsUsed && IntroRect.m_bBeforeFade) { - if (IntroRect.m_nTextureId >= 0) { - CRect rect ( - IntroRect.m_sRect.left, - IntroRect.m_sRect.bottom, - IntroRect.m_sRect.right, - IntroRect.m_sRect.top ); - - CTheScripts::ScriptSprites[IntroRect.m_nTextureId].Draw(rect, IntroRect.m_sColor); - } - else { - CRect rect ( - IntroRect.m_sRect.left, - IntroRect.m_sRect.bottom, - IntroRect.m_sRect.right, - IntroRect.m_sRect.top ); - - CSprite2d::DrawRect(rect, IntroRect.m_sColor); - } - } - } - - /* - DrawSubtitles - */ - if (m_Message[0] && !m_BigMessage[2][0]) { - if (m_VehicleState != 0) - m_VehicleState = 3; - if (m_ZoneState != 0) - m_ZoneState = 3; - - CFont::SetJustifyOff(); - CFont::SetBackgroundOff(); - CFont::SetBackgroundColor(CRGBA(0, 0, 0, 128)); - CFont::SetCentreOn(); - CFont::SetPropOn(); -#ifdef CUTSCENE_BORDERS_SWITCH - if (!FrontEndMenuManager.m_PrefsCutsceneBorders) { - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - CFont::SetDropShadowPosition(2); - } - else -#endif - CFont::SetDropShadowPosition(0); - CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); - CFont::SetColor(CRGBA(225, 225, 225, 255)); - - static bool onceItWasWidescreen = false; - - if (TheCamera.m_WideScreenOn) { - onceItWasWidescreen = true; - - if (FrontEndMenuManager.m_PrefsShowSubtitles || !CCutsceneMgr::IsRunning()) { - CFont::SetCentreSize(SCREEN_WIDTH - SCREEN_SCALE_X(60.0f)); - CFont::SetScale(SCREEN_SCALE_X(0.58f), SCREEN_SCALE_Y(1.2f)); - CFont::PrintString(SCREEN_WIDTH / 2.f, SCREEN_SCALE_FROM_BOTTOM(80.0f), m_Message); - } - } else { - if (onceItWasWidescreen) - m_Message[0] = '\0'; - - onceItWasWidescreen = false; - CFont::DrawFonts(); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - CFont::SetScale(SCREEN_SCALE_X(0.58f), SCREEN_SCALE_Y(1.22f)); - - float radarBulge = SCREEN_SCALE_X(140.0f) + SCREEN_SCALE_X(8.0f); - float rectWidth = SCREEN_WIDTH - SCREEN_SCALE_X(20.0f) - SCREEN_SCALE_X(8.0f) - radarBulge; - CFont::SetCentreSize(rectWidth); - - CFont::PrintString(rectWidth / 2.0f + radarBulge, SCREEN_SCALE_FROM_BOTTOM(105.f + 2.0f), m_Message); - } - CFont::SetDropShadowPosition(0); - } - - /* - HelpMessage - */ - - if (m_HelpMessage[0]) { - if (!CMessages::WideStringCompare(m_HelpMessage, m_LastHelpMessage, HELP_MSG_LENGTH)) { - switch (m_HelpMessageState) { - case 0: - m_HelpMessageFadeTimer = 0; - m_HelpMessageState = 2; - m_HelpMessageTimer = 0; - CMessages::WideStringCopy(m_HelpMessageToPrint, m_HelpMessage, HELP_MSG_LENGTH); - m_HelpMessageDisplayTime = CMessages::GetWideStringLength(m_HelpMessage) * 0.05f + 3.0f; - - if (TheCamera.m_ScreenReductionPercentage == 0.0f) - DMAudio.PlayFrontEndSound(SOUND_HUD, 0); - break; - case 1: - case 2: - case 3: - case 4: - m_HelpMessageTimer = 5; - m_HelpMessageState = 4; - break; - default: - break; - } - CMessages::WideStringCopy(m_LastHelpMessage, m_HelpMessage, HELP_MSG_LENGTH); - } - - float fAlpha = 225.0f; - - if (m_HelpMessageState != 0) { - switch (m_HelpMessageState) { - case 1: - fAlpha = 225.0f; - m_HelpMessageFadeTimer = 600; - if (!m_HelpMessageDisplayForever && m_HelpMessageTimer > m_HelpMessageDisplayTime * 1000.0f || - m_HelpMessageQuick && m_HelpMessageTimer > 1500.0f) { - - m_HelpMessageFadeTimer = 600; - m_HelpMessageState = 3; - } - break; - case 2: - if (TheCamera.m_WideScreenOn) - break; - - m_HelpMessageFadeTimer += 2 * CTimer::GetTimeStepInMilliseconds(); - if (m_HelpMessageFadeTimer > 0) { - m_HelpMessageState = 1; - m_HelpMessageFadeTimer = 0; - } - fAlpha = m_HelpMessageFadeTimer * 0.001f * 225.0f; - break; - case 3: - m_HelpMessageFadeTimer -= 2 * CTimer::GetTimeStepInMilliseconds(); - if (m_HelpMessageFadeTimer < 0 || TheCamera.m_WideScreenOn) { - m_HelpMessageState = 0; - m_HelpMessageFadeTimer = 0; - } - fAlpha = m_HelpMessageFadeTimer * 0.001f * 225.0f; - break; - case 4: - m_HelpMessageFadeTimer -= 2 * CTimer::GetTimeStepInMilliseconds(); - if (m_HelpMessageFadeTimer < 0) { - m_HelpMessageState = 2; - m_HelpMessageFadeTimer = 0; - CMessages::WideStringCopy(m_HelpMessageToPrint, m_LastHelpMessage, HELP_MSG_LENGTH); - } - fAlpha = m_HelpMessageFadeTimer * 0.001f * 225.0f; - break; - default: - break; - } - - if (!TheCamera.m_WideScreenOn) { - m_HelpMessageTimer += CTimer::GetTimeStepInMilliseconds(); - - CFont::SetAlphaFade(fAlpha); - CFont::SetCentreOff(); - CFont::SetPropOn(); - - if (CGame::germanGame) - CFont::SetScale(SCREEN_SCALE_X(0.52f * 0.85f), SCREEN_SCALE_Y(1.1f * 0.85f)); -#ifdef MORE_LANGUAGES - else if (CFont::IsJapanese()) - CFont::SetScale(SCREEN_SCALE_X(0.52f) * 1.35f, SCREEN_SCALE_Y(1.1f) * 1.25f); -#endif - else - CFont::SetScale(SCREEN_SCALE_X(0.52f), SCREEN_SCALE_Y(1.1f)); - - CFont::DrawFonts(); - CFont::SetColor(CRGBA(175, 175, 175, 255)); - CFont::SetJustifyOff(); -#ifdef MORE_LANGUAGES - if (CFont::IsJapanese()) - CFont::SetWrapx(SCREEN_SCALE_X(229.0f + 34.0f - 4.0f)); - else -#endif - CFont::SetWrapx(SCREEN_SCALE_X(200.0f + 34.0f - 4.0f)); - CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); - CFont::SetBackgroundOn(); - CFont::SetBackGroundOnlyTextOff(); - CFont::SetDropShadowPosition(0); - CFont::SetBackgroundColor(CRGBA(0, 0, 0, fAlpha * 0.9f)); - CFont::SetColor(CRGBA(175, 175, 175, 255)); - CFont::PrintString(SCREEN_SCALE_X(34.0f), SCREEN_SCALE_Y(28.0f + (150.0f - PagerXOffset) * 0.6f), m_HelpMessageToPrint); - CFont::SetAlphaFade(255.0f); - CFont::SetWrapx(SCREEN_WIDTH); - } - } - } else - m_HelpMessageState = 0; - - /* - DrawBigMessage - */ - // MissionCompleteFailedText - if (m_BigMessage[0][0]) { - if (BigMessageInUse[0] != 0.0f) { - CFont::SetJustifyOff(); - CFont::SetBackgroundOff(); - CFont::SetBackGroundOnlyTextOff(); - if (CGame::frenchGame || CGame::germanGame) { - CFont::SetScale(SCREEN_SCALE_X(1.6f), SCREEN_SCALE_Y(1.8f)); - } else { - CFont::SetScale(SCREEN_SCALE_X(1.8f), SCREEN_SCALE_Y(1.8f)); - } - CFont::SetPropOn(); - CFont::SetCentreOn(); - CFont::SetCentreSize(SCREEN_SCALE_X(590.0f)); - CFont::SetColor(CRGBA(255, 255, 0, BigMessageAlpha[0])); // unused color - CFont::SetFontStyle(FONT_HEADING); - - // Appearently sliding text in here was abandoned very early, since this text is centered now. - - if (BigMessageX[0] >= SCALE_AND_CENTER_X(620.0f)) { - BigMessageInUse[0] += CTimer::GetTimeStep(); - - if (BigMessageInUse[0] >= 120.0f) { - BigMessageInUse[0] = 120.0f; - BigMessageAlpha[0] -= (CTimer::GetTimeStepInMilliseconds() * 0.3f); - } - - if (BigMessageAlpha[0] <= 0.0f) { - m_BigMessage[0][0] = 0; - BigMessageAlpha[0] = 0.0f; - } - } - else { - BigMessageX[0] += SCREEN_SCALE_X((CTimer::GetTimeStepInMilliseconds() * 0.3f)); - BigMessageAlpha[0] += (CTimer::GetTimeStepInMilliseconds() * 0.3f); - - if (BigMessageAlpha[0] > 255.0f) - BigMessageAlpha[0] = 255.0f; - } - CFont::DrawFonts(); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, BigMessageAlpha[0])); - CFont::SetColor(CRGBA(BIGMESSAGE_COLOR.r, BIGMESSAGE_COLOR.g, BIGMESSAGE_COLOR.b, BigMessageAlpha[0])); - CFont::PrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(18.0f), m_BigMessage[0]); - } - else { - BigMessageAlpha[0] = 0.0f; - BigMessageX[0] = SCALE_AND_CENTER_X(-60.0f); - BigMessageInUse[0] = 1.0f; - } - } - else { - BigMessageInUse[0] = 0.0f; - } - - // WastedBustedText - if (m_BigMessage[2][0]) { - if (BigMessageInUse[2] != 0.0f) { - BigMessageAlpha[2] += (CTimer::GetTimeStepInMilliseconds() * 0.4f); - - if (BigMessageAlpha[2] > 255.0f) - BigMessageAlpha[2] = 255.0f; - - CFont::SetBackgroundOff(); - - if (CGame::frenchGame || CGame::germanGame) - CFont::SetScale(SCREEN_SCALE_X(1.4f), SCREEN_SCALE_Y(1.4f)); - else - CFont::SetScale(SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(2.0f)); - - CFont::SetPropOn(); - CFont::SetRightJustifyOn(); - CFont::SetFontStyle(FONT_HEADING); - - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, BigMessageAlpha[2])); - - CFont::SetColor(CRGBA(WASTEDBUSTED_COLOR.r, WASTEDBUSTED_COLOR.g, WASTEDBUSTED_COLOR.b, BigMessageAlpha[2])); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(90.0f), m_BigMessage[2]); - } - else { - BigMessageInUse[2] = 1.0f; - BigMessageAlpha[2] = 0.0f; - if (m_VehicleState != 0) // Hide vehicle name if wasted/busted text is displaying - m_VehicleState = 0; - if (m_ZoneState != 0) - m_ZoneState = 0; - } - } - else { - BigMessageInUse[2] = 0.0f; - } - } -} - -void CHud::DrawAfterFade() -{ - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERNEAREST); - RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void*)rwTEXTUREADDRESSCLAMP); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - - if (CTimer::GetIsUserPaused() || CReplay::IsPlayingBack()) - return; - - for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroTextLines); i++) { - intro_text_line &line = CTheScripts::IntroTextLines[i]; - if (line.m_Text[0] != '\0' && !line.m_bTextBeforeFade) { - CFont::SetScale(SCREEN_SCALE_X(line.m_fScaleX), SCREEN_SCALE_Y(line.m_fScaleY) / 2); - - CFont::SetColor(line.m_sColor); - if (line.m_bJustify) - CFont::SetJustifyOn(); - else - CFont::SetJustifyOff(); - - if (line.m_bRightJustify) - CFont::SetRightJustifyOn(); - else - CFont::SetRightJustifyOff(); - - if (line.m_bCentered) - CFont::SetCentreOn(); - else - CFont::SetCentreOff(); - - CFont::SetWrapx(SCALE_AND_CENTER_X(line.m_fWrapX)); - CFont::SetCentreSize(SCREEN_SCALE_X(line.m_fCenterSize)); - if (line.m_bBackground) - CFont::SetBackgroundOn(); - else - CFont::SetBackgroundOff(); - - CFont::SetBackgroundColor(line.m_sBackgroundColor); - if (line.m_bBackgroundOnly) - CFont::SetBackGroundOnlyTextOn(); - else - CFont::SetBackGroundOnlyTextOff(); - - if (line.m_bTextProportional) - CFont::SetPropOn(); - else - CFont::SetPropOff(); - - CFont::SetFontStyle(line.m_nFont); - CFont::PrintString(SCREEN_WIDTH - SCALE_AND_CENTER_X(DEFAULT_SCREEN_WIDTH - line.m_fAtX), SCREEN_HEIGHT - SCREEN_SCALE_Y(DEFAULT_SCREEN_HEIGHT - line.m_fAtY), line.m_Text); - } - } - for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroRectangles); i++) { - intro_script_rectangle &rectangle = CTheScripts::IntroRectangles[i]; - if (rectangle.m_bIsUsed && !rectangle.m_bBeforeFade) { - - // Yeah, top and bottom changed place. R* vision - if (rectangle.m_nTextureId >= 0) { - CTheScripts::ScriptSprites[rectangle.m_nTextureId].Draw(CRect(rectangle.m_sRect.left, rectangle.m_sRect.bottom, - rectangle.m_sRect.right, rectangle.m_sRect.top), rectangle.m_sColor); - } else { - CSprite2d::DrawRect(CRect(rectangle.m_sRect.left, rectangle.m_sRect.bottom, - rectangle.m_sRect.right, rectangle.m_sRect.top), rectangle.m_sColor); - } - } - } - - /* - DrawBigMessage2 - */ - // Oddjob - if (m_BigMessage[3][0]) { - CFont::SetJustifyOff(); - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(1.2f), SCREEN_SCALE_Y(1.5f)); - CFont::SetCentreOn(); - CFont::SetPropOn(); - CFont::SetCentreSize(SCREEN_SCALE_X(600.0f)); - CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - CFont::SetColor(ODDJOB_COLOR); - CFont::PrintString((SCREEN_WIDTH / 2), SCREEN_SCALE_Y(140.0f) - SCREEN_SCALE_Y(16.0f), m_BigMessage[3]); - } - - if (!m_BigMessage[1][0] && m_BigMessage[4][0]) { - CFont::SetJustifyOff(); - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(1.2f), SCREEN_SCALE_Y(1.5f)); - CFont::SetCentreOn(); - CFont::SetPropOn(); - CFont::SetCentreSize(SCREEN_SCALE_X(580.0f)); - CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - CFont::SetColor(ODDJOB_COLOR); - CFont::PrintString((SCREEN_WIDTH / 2), SCREEN_SCALE_Y(140.0f), m_BigMessage[4]); - } - - // Oddjob result - if (OddJob2OffTimer > 0) - OddJob2OffTimer -= CTimer::GetTimeStepInMilliseconds(); - - float fStep; - if (m_BigMessage[5][0] && OddJob2OffTimer <= 0.0f) { - switch (OddJob2On) { - case 0: - OddJob2On = 1; - OddJob2XOffset = 380.0f; - break; - case 1: - if (OddJob2XOffset <= 2.0f) { - OddJob2Timer = 0; - OddJob2On = 2; - } - else { - fStep = Min(40.0f, OddJob2XOffset / 6.0f); - OddJob2XOffset = OddJob2XOffset - fStep; - } - break; - case 2: - OddJob2Timer += CTimer::GetTimeStepInMilliseconds(); - if (OddJob2Timer > 1500) { - OddJob2On = 3; - } - break; - case 3: - fStep = Max(30.0f, OddJob2XOffset / 5.0f); - - OddJob2XOffset = OddJob2XOffset - fStep; - - if (OddJob2XOffset < -380.0f) { - OddJob2OffTimer = 5000.0f; - OddJob2On = 0; - } - break; - default: - break; - } - - if (!m_BigMessage[1][0]) { - CFont::SetJustifyOff(); - CFont::SetBackgroundOff(); - CFont::SetScale(SCREEN_SCALE_X(1.0f), SCREEN_SCALE_Y(1.2f)); - CFont::SetCentreOn(); - CFont::SetPropOn(); - CFont::SetCentreSize(SCREEN_SCALE_X(560.0f)); - CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - CFont::SetColor(ODDJOB2_COLOR); - CFont::PrintString(SCREEN_WIDTH / 2, SCREEN_SCALE_Y(217.0f), m_BigMessage[5]); - } - } - - /* - DrawMissionTitle - */ - if (m_BigMessage[1][0]) { - if (BigMessageInUse[1] != 0.0f) { - CFont::SetJustifyOff(); - CFont::SetBackgroundOff(); - - // will be overwritten below - if (CGame::frenchGame || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) - CFont::SetScale(SCREEN_SCALE_X(0.884f), SCREEN_SCALE_Y(1.36f)); - else - CFont::SetScale(SCREEN_SCALE_X(1.04f), SCREEN_SCALE_Y(1.6f)); - - CFont::SetPropOn(); - CFont::SetRightJustifyWrap(SCALE_AND_CENTER_X(0.0f)); - CFont::SetRightJustifyOn(); - CFont::SetFontStyle(FONT_BANK); - CFont::SetScale(FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_AMERICAN ? SCREEN_SCALE_X(1.7f) : SCREEN_SCALE_X(1.5f), SCREEN_SCALE_Y(1.8f)); - - if (BigMessageX[1] >= SCREEN_SCALE_FROM_RIGHT(20.0f)) { - BigMessageInUse[1] += CTimer::GetTimeStep(); - - if (BigMessageInUse[1] >= 120.0f) { - BigMessageInUse[1] = 120.0f; - BigMessageAlpha[1] -= CTimer::GetTimeStepInMilliseconds(); - } - if (BigMessageAlpha[1] <= 0.0f) { - m_BigMessage[1][0] = 0; - BigMessageInUse[1] = 0.0f; - BigMessageAlpha[1] = 0.0f; - } - } else { - BigMessageX[1] += SCREEN_SCALE_X((CTimer::GetTimeStepInMilliseconds() * 0.3f)); - BigMessageAlpha[1] += CTimer::GetTimeStepInMilliseconds(); - - if (BigMessageAlpha[1] > 255.0f) - BigMessageAlpha[1] = 255.0f; - } - - CFont::SetColor(CRGBA(40, 40, 40, BigMessageAlpha[1])); // what was that for? - - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, BigMessageAlpha[1])); - CFont::SetColor(CRGBA(MISSIONTITLE_COLOR.r, MISSIONTITLE_COLOR.g, MISSIONTITLE_COLOR.b, BigMessageAlpha[1])); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(140.0f), m_BigMessage[1]); - } else { - m_ZoneFadeTimer = 0; - BigMessageX[1] = SCREEN_SCALE_FROM_RIGHT(DEFAULT_SCREEN_WIDTH + 60.0f); - BigMessageInUse[1] = 1.0f; - m_ZoneState = 0; - } - } else { - BigMessageInUse[1] = 0.0f; - } -} - -void CHud::GetRidOfAllHudMessages() -{ - m_ZoneNameTimer = 0; - m_pZoneName = nil; - m_ZoneState = 0; - - for (int i = 0; i < HELP_MSG_LENGTH; i++) { - m_HelpMessage[i] = 0; - m_LastHelpMessage[i] = 0; - m_HelpMessageToPrint[i] = 0; - } - - m_HelpMessageTimer = 0; - m_HelpMessageFadeTimer = 0; - m_HelpMessageState = 0; - m_HelpMessageQuick = 0; - m_HelpMessageDisplayForever = false; - m_HelpMessageDisplayTime = 1.0f; - m_VehicleName = nil; - m_pVehicleNameToPrint = nil; - m_VehicleNameTimer = 0; - m_VehicleFadeTimer = 0; - m_VehicleState = 0; - - for (int i = 0; i < ARRAY_SIZE(m_Message); i++) - m_Message[i] = 0; - - for (int i = 0; i < 6; i++) { - BigMessageInUse[i] = 0.0f; - - for (int j = 0; j < 128; j++) - m_BigMessage[i][j] = 0; - } -} - -#ifdef RELOADABLES -void CHud::ReloadTXD() -{ - for (int i = 0; i < NUM_HUD_SPRITES; ++i) { - Sprites[i].Delete(); - } - - int HudTXD = CTxdStore::FindTxdSlot("hud"); - CTxdStore::RemoveTxdSlot(HudTXD); - - debug("Reloading HUD.TXD...\n"); - - HudTXD = CTxdStore::AddTxdSlot("hud"); - CTxdStore::LoadTxd(HudTXD, "MODELS/HUD.TXD"); - CTxdStore::AddRef(HudTXD); - CTxdStore::PopCurrentTxd(); - CTxdStore::SetCurrentTxd(HudTXD); - - for (int i = 0; i < NUM_HUD_SPRITES; i++) { - Sprites[i].SetTexture(WeaponFilenames[i].name, WeaponFilenames[i].mask); - } -} -#endif - -void CHud::Initialise() -{ - m_Wants_To_Draw_Hud = true; - m_Wants_To_Draw_3dMarkers = true; - - int HudTXD = CTxdStore::AddTxdSlot("hud"); - CTxdStore::LoadTxd(HudTXD, "MODELS/HUD.TXD"); - CTxdStore::AddRef(HudTXD); - CTxdStore::PopCurrentTxd(); - CTxdStore::SetCurrentTxd(HudTXD); - - for (int i = 0; i < NUM_HUD_SPRITES; i++) { - Sprites[i].SetTexture(WeaponFilenames[i].name, WeaponFilenames[i].mask); - } - - m_pLastZoneName = nil; - GetRidOfAllHudMessages(); - m_pLastVehicleName = nil; - - if (gpSniperSightTex == nil) - gpSniperSightTex = RwTextureRead("sitesniper", nil); // unused - if (gpRocketSightTex == nil) - gpRocketSightTex = RwTextureRead("siterocket", nil); - if (gpLaserSightTex == nil) - gpLaserSightTex = RwTextureRead("sitelaser", nil); // unused - if (gpLaserDotTex == nil) - gpLaserDotTex = RwTextureRead("laserdot", "laserdotm"); - if (gpViewFinderTex == nil) - gpViewFinderTex = RwTextureRead("viewfinder_128", "viewfinder_128m"); // unused - - m_ClockState = 1; - CounterOnLastFrame[0] = false; - CounterOnLastFrame[1] = false; - CounterOnLastFrame[2] = false; - - m_ItemToFlash = ITEM_NONE; - OddJob2Timer = 0; - OddJob2OffTimer = 0.0f; - OddJob2On = 0; - OddJob2XOffset = 0.0f; - CounterFlashTimer[0] = 0; - CounterFlashTimer[1] = 0; - CounterFlashTimer[2] = 0; - TimerOnLastFrame = false; - TimerFlashTimer = 0; - SpriteBrightness = 0; - PagerOn = 0; - PagerTimer = 0; - PagerSoundPlayed = 0; - PagerXOffset = 150.0f; - -#ifdef HUD_AUTO_FADE - m_EnergyLostState = START_FADE_OUT; - m_WantedState = START_FADE_OUT; - m_DisplayScoreState = START_FADE_OUT; - m_WeaponState = START_FADE_OUT; -#else - m_EnergyLostState = FADE_DISABLED; - m_WantedState = FADE_DISABLED; - m_DisplayScoreState = FADE_DISABLED; - m_WeaponState = FADE_DISABLED; -#endif - m_WantedFadeTimer = 0; - m_WantedTimer = 0; - m_EnergyLostFadeTimer = 0; - m_EnergyLostTimer = 0; - m_DisplayScoreFadeTimer = 0; - m_DisplayScoreTimer = 0; - m_WeaponFadeTimer = 0; - m_WeaponTimer = 0; - - m_HideRadar = false; - m_LastDisplayScore = CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney; - m_LastTimeEnergyLost = CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss; - m_LastWanted = 0; - m_LastWeapon = 0; - -#ifndef MASTER - VarConsole.Add("Draw HUD", &m_Wants_To_Draw_Hud, false); -#endif - CTxdStore::PopCurrentTxd(); -} - -void CHud::ReInitialise() { - m_Wants_To_Draw_Hud = true; - m_Wants_To_Draw_3dMarkers = true; - - m_pLastZoneName = nil; - GetRidOfAllHudMessages(); - m_pLastVehicleName = nil; - - CounterOnLastFrame[0] = false; - CounterOnLastFrame[1] = false; - CounterOnLastFrame[2] = false; - m_ItemToFlash = ITEM_NONE; - m_ClockState = 1; - OddJob2Timer = 0; - OddJob2OffTimer = 0.0f; - OddJob2On = 0; - OddJob2XOffset = 0.0f; - CounterFlashTimer[0] = 0; - CounterFlashTimer[1] = 0; - CounterFlashTimer[2] = 0; - TimerOnLastFrame = false; - TimerFlashTimer = 0; - SpriteBrightness = 0; - PagerOn = 0; - PagerTimer = 0; - PagerSoundPlayed = 0; - PagerXOffset = 150.0f; - -#ifdef HUD_AUTO_FADE - m_EnergyLostState = START_FADE_OUT; - m_WantedState = START_FADE_OUT; - m_DisplayScoreState = START_FADE_OUT; - m_WeaponState = START_FADE_OUT; -#else - m_EnergyLostState = FADE_DISABLED; - m_WantedState = FADE_DISABLED; - m_DisplayScoreState = FADE_DISABLED; - m_WeaponState = FADE_DISABLED; -#endif - m_WantedFadeTimer = 0; - m_WantedTimer = 0; - m_EnergyLostFadeTimer = 0; - m_EnergyLostTimer = 0; - m_DisplayScoreFadeTimer = 0; - m_DisplayScoreTimer = 0; - m_WeaponFadeTimer = 0; - m_WeaponTimer = 0; - - m_HideRadar = false; - m_LastDisplayScore = CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney; - m_LastTimeEnergyLost = CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss; - m_LastWanted = 0; - m_LastWeapon = 0; -} - -wchar LastBigMessage[6][128]; - -void CHud::SetBigMessage(wchar *message, uint16 style) -{ - int i = 0; - - if (BigMessageInUse[style] != 0.0f) - return; - - if (style == 5) { - for (i = 0; i < 128; i++) { - if (message[i] == 0) - break; - - if (message[i] != LastBigMessage[5][i]) { - OddJob2On = 0; - OddJob2OffTimer = 0.0f; - } - - m_BigMessage[5][i] = message[i]; - LastBigMessage[5][i] = message[i]; - } - } else { - for (i = 0; i < 128; i++) { - if (message[i] == 0) - break; - m_BigMessage[style][i] = message[i]; - } - } - LastBigMessage[style][i] = 0; - m_BigMessage[style][i] = 0; -} - -void CHud::SetHelpMessage(wchar *message, bool quick, bool displayForever) -{ - if (!CReplay::IsPlayingBack()) { - for (int i = 0; i < HELP_MSG_LENGTH; i++) { - m_HelpMessage[i] = 0; - } - for (int i = 0; i < HELP_MSG_LENGTH; i++) { - m_LastHelpMessage[i] = 0; - } - for (int i = 0; i < HELP_MSG_LENGTH; i++) { - m_HelpMessageToPrint[i] = 0; - } - - CMessages::WideStringCopy(m_HelpMessage, message, HELP_MSG_LENGTH); - CMessages::InsertPlayerControlKeysInString(m_HelpMessage); - if (m_HelpMessageState == 0 || !CMessages::WideStringCompare(m_HelpMessage, m_HelpMessageToPrint, HELP_MSG_LENGTH)) { - for (int i = 0; i < HELP_MSG_LENGTH; i++) { - m_LastHelpMessage[i] = 0; - } - - if (!message) { - m_HelpMessage[0] = 0; - m_HelpMessageToPrint[0] = 0; - } - if (!displayForever) { - m_HelpMessageState = displayForever; - } else { - m_HelpMessageState = 1; - CMessages::WideStringCopy(m_HelpMessageToPrint, m_HelpMessage, HELP_MSG_LENGTH); - CMessages::WideStringCopy(m_LastHelpMessage, m_HelpMessage, HELP_MSG_LENGTH); - } - - m_HelpMessageQuick = quick; - m_HelpMessageDisplayForever = displayForever; - } - - } -} - -bool CHud::IsHelpMessageBeingDisplayed(void) -{ - return m_HelpMessageState != 0; -} - -void CHud::SetMessage(wchar *message) -{ - int i = 0; - for (i = 0; i < ARRAY_SIZE(m_Message); i++) { - if (message[i] == 0) - break; - - m_Message[i] = message[i]; - } - m_Message[i] = 0; -} - -void CHud::SetPagerMessage(wchar *message) -{ - int i = 0; - for (i = 0; i < ARRAY_SIZE(m_PagerMessage); i++) { - if (message[i] == 0) - break; - - m_PagerMessage[i] = message[i]; - } - m_PagerMessage[i] = 0; -} - -void CHud::SetVehicleName(wchar *name) -{ - m_VehicleName = name; -} - -void CHud::SetZoneName(wchar *name) -{ - m_pZoneName = name; -} - -void CHud::Shutdown() -{ - for (int i = 0; i < NUM_HUD_SPRITES; ++i) { - Sprites[i].Delete(); - } - - RwTextureDestroy(gpSniperSightTex); - gpSniperSightTex = nil; - - RwTextureDestroy(gpRocketSightTex); - gpRocketSightTex = nil; - - RwTextureDestroy(gpLaserSightTex); - gpLaserSightTex = nil; - - RwTextureDestroy(gpLaserDotTex); - gpLaserDotTex = nil; - - RwTextureDestroy(gpViewFinderTex); - gpViewFinderTex = nil; - - int HudTXD = CTxdStore::FindTxdSlot("hud"); - CTxdStore::RemoveTxdSlot(HudTXD); -} - -float CHud::DrawFadeState(DRAW_FADE_STATE fadingElement, int forceFadingIn) -{ - float alpha = 255.0f; - uint32 operation, timer; - int32 fadeTimer; - - switch (fadingElement) { - case HUD_WANTED_FADING: - fadeTimer = m_WantedFadeTimer; - operation = m_WantedState; - timer = m_WantedTimer; - break; - case HUD_ENERGY_FADING: - fadeTimer = m_EnergyLostFadeTimer; - operation = m_EnergyLostState; - timer = m_EnergyLostTimer; - break; - case HUD_SCORE_FADING: - fadeTimer = m_DisplayScoreFadeTimer; - operation = m_DisplayScoreState; - timer = m_DisplayScoreTimer; - break; - case HUD_WEAPON_FADING: - fadeTimer = m_WeaponFadeTimer; - operation = m_WeaponState; - timer = m_WeaponTimer; - break; - default: - break; - } - if (forceFadingIn) { - switch (operation) { - case FADED_OUT: - fadeTimer = 0; - case START_FADE_OUT: - case FADING_OUT: - timer = 5; - operation = FADING_IN; - break; - default: - break; - } - } - if (operation != FADED_OUT && operation != FADE_DISABLED) { - switch (operation) { - case START_FADE_OUT: - fadeTimer = 1000; - alpha = 255.0f; - if (timer > 10000) { - fadeTimer = 3000; - operation = FADING_OUT; - } - break; - case FADING_IN: - fadeTimer += CTimer::GetTimeStepInMilliseconds(); - if (fadeTimer > 1000.0f) { - operation = START_FADE_OUT; - fadeTimer = 1000; - } - alpha = fadeTimer / 1000.0f * 255.0f; - break; - case FADING_OUT: - fadeTimer -= CTimer::GetTimeStepInMilliseconds(); - if (fadeTimer < 0.0f) { - fadeTimer = 0; - operation = FADED_OUT; - } - alpha = fadeTimer / 1000.0f * 255.0f; - break; - default: - break; - } - timer += CTimer::GetTimeStepInMilliseconds(); - } - - switch (fadingElement) { - case HUD_WANTED_FADING: - m_WantedFadeTimer = fadeTimer; - m_WantedState = operation; - m_WantedTimer = timer; - break; - case HUD_ENERGY_FADING: - m_EnergyLostFadeTimer = fadeTimer; - m_EnergyLostState = operation; - m_EnergyLostTimer = timer; - break; - case HUD_SCORE_FADING: - m_DisplayScoreFadeTimer = fadeTimer; - m_DisplayScoreState = operation; - m_DisplayScoreTimer = timer; - break; - case HUD_WEAPON_FADING: - m_WeaponFadeTimer = fadeTimer; - m_WeaponState = operation; - m_WeaponTimer = timer; - break; - default: - break; - } - - return Clamp(alpha, 0.0f, 255.0f); -} - -void -CHud::ResetWastedText(void) -{ - BigMessageInUse[2] = 0.0f; - BigMessageInUse[0] = 0.0f; - m_BigMessage[2][0] = 0; - m_BigMessage[0][0] = 0; -} diff --git a/src/render/Hud.h b/src/render/Hud.h deleted file mode 100644 index a4b9609a..00000000 --- a/src/render/Hud.h +++ /dev/null @@ -1,139 +0,0 @@ -#pragma once -#include "Sprite2d.h" - -#define HELP_MSG_LENGTH 256 - -#define HUD_TEXT_SCALE_X 0.7f -#define HUD_TEXT_SCALE_Y 1.25f - -enum eItems -{ - ITEM_NONE = -1, - ITEM_ARMOUR = 3, - ITEM_HEALTH = 4, - ITEM_RADAR = 8 -}; - -// Thanks for vague name, R* -enum DRAW_FADE_STATE -{ - HUD_WANTED_FADING = 0, - HUD_ENERGY_FADING, - HUD_SCORE_FADING, - HUD_WEAPON_FADING, -}; - -// My name -enum eFadeOperation -{ - FADED_OUT = 0, - START_FADE_OUT, - FADING_IN, - FADING_OUT, - FADE_DISABLED = 5, -}; - -enum eSprites -{ - HUD_FIST, - HUD_SITEROCKET = 41, - HUD_RADARDISC = 50, - HUD_SITESNIPER = 63, - HUD_SITEM16, - HUD_SITELASER, - HUD_LASERDOT, - HUD_VIEWFINDER, - HUD_BLEEDER, - NUM_HUD_SPRITES = 69, -}; - -class CHud -{ -public: - static CSprite2d Sprites[NUM_HUD_SPRITES]; - static wchar m_HelpMessage[HELP_MSG_LENGTH]; - static wchar m_LastHelpMessage[HELP_MSG_LENGTH]; - static uint32 m_HelpMessageState; - static uint32 m_HelpMessageTimer; - static int32 m_HelpMessageFadeTimer; - static wchar m_HelpMessageToPrint[HELP_MSG_LENGTH]; - static float m_HelpMessageDisplayTime; - static bool m_HelpMessageDisplayForever; - static bool m_HelpMessageQuick; - static uint32 m_ZoneState; - static int32 m_ZoneFadeTimer; - static uint32 m_ZoneNameTimer; - static wchar *m_pZoneName; - static wchar *m_pLastZoneName; - static wchar *m_ZoneToPrint; - static wchar *m_VehicleName; - static wchar *m_pLastVehicleName; - static wchar *m_pVehicleNameToPrint; - static uint32 m_VehicleState; - static int32 m_VehicleFadeTimer; - static uint32 m_VehicleNameTimer; - static wchar m_Message[256]; - static wchar m_PagerMessage[256]; - static bool m_Wants_To_Draw_Hud; - static bool m_Wants_To_Draw_3dMarkers; - static wchar m_BigMessage[6][128]; - static int16 m_ItemToFlash; - static bool m_HideRadar; - static int32 m_ClockState; - - // These aren't really in CHud - static float BigMessageInUse[6]; - static float BigMessageAlpha[6]; - static float BigMessageX[6]; - static float OddJob2OffTimer; - static bool CounterOnLastFrame[NUMONSCREENCOUNTERS]; - static float OddJob2XOffset; - static uint16 CounterFlashTimer[NUMONSCREENCOUNTERS]; - static uint16 OddJob2Timer; - static bool TimerOnLastFrame; - static int16 OddJob2On; - static uint16 TimerFlashTimer; - static int16 PagerSoundPlayed; - static int32 SpriteBrightness; - static float PagerXOffset; - static int16 PagerTimer; - static int16 PagerOn; - - static uint32 m_WantedFadeTimer; - static uint32 m_WantedState; - static uint32 m_WantedTimer; - static uint32 m_EnergyLostFadeTimer; - static uint32 m_EnergyLostState; - static uint32 m_EnergyLostTimer; - static uint32 m_DisplayScoreFadeTimer; - static uint32 m_DisplayScoreState; - static uint32 m_DisplayScoreTimer; - static uint32 m_WeaponFadeTimer; - static uint32 m_WeaponState; - static uint32 m_WeaponTimer; - - static uint32 m_LastDisplayScore; - static uint32 m_LastWanted; - static uint32 m_LastWeapon; - static uint32 m_LastTimeEnergyLost; - -public: - static void Draw(); - static void DrawAfterFade(); - static void GetRidOfAllHudMessages(); -#ifdef RELOADABLES - static void ReloadTXD(); -#endif - static void Initialise(); - static void ReInitialise(); - static void SetBigMessage(wchar *message, uint16 style); - static void SetHelpMessage(wchar *message, bool quick, bool displayForever = false); - static bool IsHelpMessageBeingDisplayed(void); - static void SetMessage(wchar *message); - static void SetPagerMessage(wchar *message); - static void SetVehicleName(wchar *name); - static void SetZoneName(wchar *name); - static void Shutdown(); - static float DrawFadeState(DRAW_FADE_STATE, int); - static void ResetWastedText(void); -}; diff --git a/src/render/Instance.cpp b/src/render/Instance.cpp deleted file mode 100644 index be6d73d6..00000000 --- a/src/render/Instance.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "common.h" - -#include "Instance.h" - -void -CInstance::Shutdown() -{ - GetMatrix().Detach(); -} diff --git a/src/render/Instance.h b/src/render/Instance.h deleted file mode 100644 index 693cfdf1..00000000 --- a/src/render/Instance.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "Placeable.h" - -// unused - -class CInstance : public CPlaceable -{ -public: - int m_modelIndex; -public: - ~CInstance() { } - void Shutdown(); -}; diff --git a/src/render/Lines.cpp b/src/render/Lines.cpp deleted file mode 100644 index b5c85149..00000000 --- a/src/render/Lines.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "Lines.h" - -// This is super inefficient, why split the line into segments at all? -void -CLines::RenderLineWithClipping(float x1, float y1, float z1, float x2, float y2, float z2, uint32 c1, uint32 c2) -{ - static RwIm3DVertex v[2]; -#ifdef THIS_IS_STUPID - int i; - float f1, f2; - float len = sqrt(sq(x1-x2) + sq(y1-y2) + sq(z1-z2)); - int numsegs = len/1.5f + 1.0f; - - RwRGBA col1; - col1.red = c1>>24; - col1.green = c1>>16; - col1.blue = c1>>8; - col1.alpha = c1; - RwRGBA col2; - col2.red = c2>>24; - col2.green = c2>>16; - col2.blue = c2>>8; - col2.alpha = c2; - - float dx = x2 - x1; - float dy = y2 - y1; - float dz = z2 - z1; - for(i = 0; i < numsegs; i++){ - f1 = (float)i/numsegs; - f2 = (float)(i+1)/numsegs; - - RwIm3DVertexSetRGBA(&v[0], (int)(col1.red + (col2.red-col1.red)*f1), - (int)(col1.green + (col2.green-col1.green)*f1), - (int)(col1.blue + (col2.blue-col1.blue)*f1), - (int)(col1.alpha + (col2.alpha-col1.alpha)*f1)); - RwIm3DVertexSetRGBA(&v[1], (int)(col1.red + (col2.red-col1.red)*f2), - (int)(col1.green + (col2.green-col1.green)*f2), - (int)(col1.blue + (col2.blue-col1.blue)*f2), - (int)(col1.alpha + (col2.alpha-col1.alpha)*f2)); - RwIm3DVertexSetPos(&v[0], x1 + dx*f1, y1 + dy*f1, z1 + dz*f1); - RwIm3DVertexSetPos(&v[1], x1 + dx*f2, y1 + dy*f2, z1 + dz*f2); - - LittleTest(); - if(RwIm3DTransform(v, 2, nil, 0)){ - RwIm3DRenderLine(0, 1); - RwIm3DEnd(); - } - } -#else - RwRGBA col1; - col1.red = c1>>24; - col1.green = c1>>16; - col1.blue = c1>>8; - col1.alpha = c1; - RwRGBA col2; - col2.red = c2>>24; - col2.green = c2>>16; - col2.blue = c2>>8; - col2.alpha = c2; - - RwIm3DVertexSetRGBA(&v[0], col1.red, col1.green, col1.blue, col1.alpha); - RwIm3DVertexSetRGBA(&v[1], col2.red, col2.green, col2.blue, col2.alpha); - RwIm3DVertexSetPos(&v[0], x1, y1, z1); - RwIm3DVertexSetPos(&v[1], x2, y2, z2); - LittleTest(); - if(RwIm3DTransform(v, 2, nil, 0)){ - RwIm3DRenderLine(0, 1); - RwIm3DEnd(); - } -#endif -} diff --git a/src/render/Lines.h b/src/render/Lines.h deleted file mode 100644 index f2694fc0..00000000 --- a/src/render/Lines.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -class CLines -{ -public: - static void RenderLineWithClipping(float x1, float y1, float z1, float x2, float y2, float z2, uint32 c1, uint32 c2); -}; diff --git a/src/render/MBlur.cpp b/src/render/MBlur.cpp deleted file mode 100644 index cc8270ce..00000000 --- a/src/render/MBlur.cpp +++ /dev/null @@ -1,801 +0,0 @@ -#ifndef LIBRW -#define WITHD3D -#endif -#include "common.h" -#ifndef LIBRW -#include -#endif - -#include "main.h" -#include "General.h" -#include "RwHelper.h" -#include "Camera.h" -#include "Timecycle.h" -#include "Particle.h" -#include "Timer.h" -#include "Hud.h" -#include "Frontend.h" -#include "MBlur.h" -#include "postfx.h" - -// Originally taken from RW example 'mblur' - -RwRaster *CMBlur::pFrontBuffer; -bool CMBlur::ms_bJustInitialised; -bool CMBlur::ms_bScaledBlur; -bool CMBlur::BlurOn; -float CMBlur::Drunkness; - -int32 CMBlur::pBufVertCount; - -static RwIm2DVertex Vertex[4]; -static RwIm2DVertex Vertex2[4]; -static RwImVertexIndex Index[6] = { 0, 1, 2, 0, 2, 3 }; - -#ifndef LIBRW -extern "C" D3DCAPS8 _RwD3D8DeviceCaps; -#endif -RwBool -CMBlur::MotionBlurOpen(RwCamera *cam) -{ -#ifdef EXTENDED_COLOURFILTER - CPostFX::Open(cam); - return TRUE; -#else -#ifdef GTA_PS2 - RwRect rect = {0, 0, 0, 0}; - - if (pFrontBuffer) - return TRUE; - - BlurOn = true; - - rect.w = RwRasterGetWidth(RwCameraGetRaster(cam)); - rect.h = RwRasterGetHeight(RwCameraGetRaster(cam)); - - pFrontBuffer = RwRasterCreate(0, 0, 0, rwRASTERDONTALLOCATE|rwRASTERTYPECAMERATEXTURE); - if (!pFrontBuffer) - { - printf("Error creating raster\n"); - return FALSE; - } - - RwRaster *raster = RwRasterSubRaster(pFrontBuffer, RwCameraGetRaster(cam), &rect); - if (!raster) - { - RwRasterDestroy(pFrontBuffer); - pFrontBuffer = NULL; - printf("Error subrastering\n"); - return FALSE; - } - - CreateImmediateModeData(cam, &rect); -#else - RwRect rect = { 0, 0, 0, 0 }; - - if(pFrontBuffer) - MotionBlurClose(); - -#ifndef LIBRW - extern void _GetVideoMemInfo(LPDWORD total, LPDWORD avaible); - DWORD total, avaible; - - _GetVideoMemInfo(&total, &avaible); - debug("Available video memory %d\n", avaible); -#endif - - if(BlurOn) - { - uint32 width = Pow(2.0f, int32(log2(RwRasterGetWidth (RwCameraGetRaster(cam))))+1); - uint32 height = Pow(2.0f, int32(log2(RwRasterGetHeight(RwCameraGetRaster(cam))))+1); - uint32 depth = RwRasterGetDepth(RwCameraGetRaster(cam)); - -#ifndef LIBRW - extern DWORD _dwMemTotalVideo; - if ( _RwD3D8DeviceCaps.MaxTextureWidth >= width && _RwD3D8DeviceCaps.MaxTextureHeight >= height ) - { - total = _dwMemTotalVideo - 3 * - ( RwRasterGetDepth(RwCameraGetRaster(cam)) - * RwRasterGetHeight(RwCameraGetRaster(cam)) - * RwRasterGetWidth(RwCameraGetRaster(cam)) / 8 ); - BlurOn = total >= height*width*(depth/8) + (12*1024*1024) /*12 MB*/; - } - else - BlurOn = false; -#endif - - if ( BlurOn ) - { - ms_bScaledBlur = false; - rect.w = width; - rect.h = height; - - pFrontBuffer = RwRasterCreate(rect.w, rect.h, depth, rwRASTERTYPECAMERATEXTURE); - if ( !pFrontBuffer ) - { - debug("MBlurOpen can't create raster."); - BlurOn = false; - rect.w = RwRasterGetWidth(RwCameraGetRaster(cam)); - rect.h = RwRasterGetHeight(RwCameraGetRaster(cam)); - } - else - ms_bJustInitialised = true; - } - else - { - rect.w = RwRasterGetWidth(RwCameraGetRaster(cam)); - rect.h = RwRasterGetHeight(RwCameraGetRaster(cam)); - } - -#ifndef LIBRW - _GetVideoMemInfo(&total, &avaible); - debug("Available video memory %d\n", avaible); -#endif - CreateImmediateModeData(cam, &rect); - } - else - { - rect.w = RwRasterGetWidth(RwCameraGetRaster(cam)); - rect.h = RwRasterGetHeight(RwCameraGetRaster(cam)); - CreateImmediateModeData(cam, &rect); - } - - return TRUE; -#endif -#endif -} - -RwBool -CMBlur::MotionBlurClose(void) -{ -#ifdef EXTENDED_COLOURFILTER - CPostFX::Close(); -#else - if(pFrontBuffer){ - RwRasterDestroy(pFrontBuffer); - pFrontBuffer = nil; - - return TRUE; - } -#endif - return FALSE; -} - -void -CMBlur::CreateImmediateModeData(RwCamera *cam, RwRect *rect) -{ - float zero, xmax, ymax; - - if(RwRasterGetDepth(RwCameraGetRaster(cam)) == 16){ - zero = HALFPX; - xmax = rect->w + HALFPX; - ymax = rect->h + HALFPX; - }else{ - zero = -HALFPX; - xmax = rect->w - HALFPX; - ymax = rect->h - HALFPX; - } - - RwIm2DVertexSetScreenX(&Vertex[0], zero); - RwIm2DVertexSetScreenY(&Vertex[0], zero); - RwIm2DVertexSetScreenZ(&Vertex[0], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&Vertex[0], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&Vertex[0], 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetU(&Vertex[0], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetV(&Vertex[0], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetIntRGBA(&Vertex[0], 255, 255, 255, 255); - - RwIm2DVertexSetScreenX(&Vertex[1], zero); - RwIm2DVertexSetScreenY(&Vertex[1], ymax); - RwIm2DVertexSetScreenZ(&Vertex[1], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&Vertex[1], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&Vertex[1], 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetU(&Vertex[1], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetV(&Vertex[1], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetIntRGBA(&Vertex[1], 255, 255, 255, 255); - - RwIm2DVertexSetScreenX(&Vertex[2], xmax); - RwIm2DVertexSetScreenY(&Vertex[2], ymax); - RwIm2DVertexSetScreenZ(&Vertex[2], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&Vertex[2], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&Vertex[2], 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetU(&Vertex[2], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetV(&Vertex[2], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetIntRGBA(&Vertex[2], 255, 255, 255, 255); - - RwIm2DVertexSetScreenX(&Vertex[3], xmax); - RwIm2DVertexSetScreenY(&Vertex[3], zero); - RwIm2DVertexSetScreenZ(&Vertex[3], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&Vertex[3], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&Vertex[3], 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetU(&Vertex[3], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetV(&Vertex[3], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetIntRGBA(&Vertex[3], 255, 255, 255, 255); - - - RwIm2DVertexSetScreenX(&Vertex2[0], zero + 2.0f); - RwIm2DVertexSetScreenY(&Vertex2[0], zero + 2.0f); - RwIm2DVertexSetScreenZ(&Vertex2[0], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&Vertex2[0], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&Vertex2[0], 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetU(&Vertex2[0], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetV(&Vertex2[0], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetIntRGBA(&Vertex2[0], 255, 255, 255, 255); - - RwIm2DVertexSetScreenX(&Vertex2[1], 2.0f); - RwIm2DVertexSetScreenY(&Vertex2[1], ymax + 2.0f); - RwIm2DVertexSetScreenZ(&Vertex2[1], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&Vertex2[1], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&Vertex2[1], 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetU(&Vertex2[1], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetV(&Vertex2[1], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetIntRGBA(&Vertex2[1], 255, 255, 255, 255); - - RwIm2DVertexSetScreenX(&Vertex2[2], xmax + 2.0f); - RwIm2DVertexSetScreenY(&Vertex2[2], ymax + 2.0f); - RwIm2DVertexSetScreenZ(&Vertex2[2], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&Vertex2[2], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&Vertex2[2], 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetU(&Vertex2[2], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetV(&Vertex2[2], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetIntRGBA(&Vertex2[2], 255, 255, 255, 255); - - RwIm2DVertexSetScreenX(&Vertex2[3], xmax + 2.0f); - RwIm2DVertexSetScreenY(&Vertex2[3], zero + 2.0f); - RwIm2DVertexSetScreenZ(&Vertex2[3], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&Vertex2[3], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&Vertex2[3], 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetU(&Vertex2[3], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetV(&Vertex2[3], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetIntRGBA(&Vertex2[3], 255, 255, 255, 255); -} - -void -CMBlur::CreateImmediateModeData(RwCamera *cam, RwRect *rect, RwIm2DVertex *verts, RwRGBA color, float u1Off, float v1Off, float u2Off, float v2Off, float z, int fullTexture) -{ - float x1 = rect->x; - float y1 = rect->y; - float x2 = rect->w; - float y2 = rect->h; - - float u1, v1, u2, v2; - if(fullTexture){ - u1 = 0.0f; - v1 = 0.0f; - u2 = 1.0f; - v2 = 1.0f; - }else{ - if(RwRasterGetDepth(RwCameraGetRaster(cam)) == 16){ - x1 += HALFPX; - y1 += HALFPX; - x2 += HALFPX; - y2 += HALFPX; - }else{ - x1 -= HALFPX; - y1 -= HALFPX; - x2 -= HALFPX; - y2 -= HALFPX; - } - - int32 width = Pow(2.0f, int32(log2(RwRasterGetWidth (RwCameraGetRaster(cam))))+1); - int32 height = Pow(2.0f, int32(log2(RwRasterGetHeight(RwCameraGetRaster(cam))))+1); - u1 = x1/width + u1Off; - v1 = y1/height + v1Off; - u2 = x2/width + u2Off; - v2 = y2/height + v2Off; - u1 = Clamp(u1, 0.0f, 1.0f); - v1 = Clamp(v1, 0.0f, 1.0f); - u2 = Clamp(u2, 0.0f, 1.0f); - v2 = Clamp(v2, 0.0f, 1.0f); - } - - float recipz = 1.0f/z; - // TODO: CameraZ is wrong, what should we do? - RwIm2DVertexSetScreenX(&verts[0], x1); - RwIm2DVertexSetScreenY(&verts[0], y1); - RwIm2DVertexSetScreenZ(&verts[0], z); - RwIm2DVertexSetCameraZ(&verts[0], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&verts[0], recipz); - RwIm2DVertexSetU(&verts[0], u1, recipz); - RwIm2DVertexSetV(&verts[0], v1, recipz); - RwIm2DVertexSetIntRGBA(&verts[0], color.red, color.green, color.blue, color.alpha); - - RwIm2DVertexSetScreenX(&verts[1], x1); - RwIm2DVertexSetScreenY(&verts[1], y2); - RwIm2DVertexSetScreenZ(&verts[1], z); - RwIm2DVertexSetCameraZ(&verts[1], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&verts[1], recipz); - RwIm2DVertexSetU(&verts[1], u1, recipz); - RwIm2DVertexSetV(&verts[1], v2, recipz); - RwIm2DVertexSetIntRGBA(&verts[1], color.red, color.green, color.blue, color.alpha); - - RwIm2DVertexSetScreenX(&verts[2], x2); - RwIm2DVertexSetScreenY(&verts[2], y2); - RwIm2DVertexSetScreenZ(&verts[2], z); - RwIm2DVertexSetCameraZ(&verts[2], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&verts[2], recipz); - RwIm2DVertexSetU(&verts[2], u2, recipz); - RwIm2DVertexSetV(&verts[2], v2, recipz); - RwIm2DVertexSetIntRGBA(&verts[2], color.red, color.green, color.blue, color.alpha); - - RwIm2DVertexSetScreenX(&verts[3], x2); - RwIm2DVertexSetScreenY(&verts[3], y1); - RwIm2DVertexSetScreenZ(&verts[3], z); - RwIm2DVertexSetCameraZ(&verts[3], RwCameraGetNearClipPlane(cam)); - RwIm2DVertexSetRecipCameraZ(&verts[3], recipz); - RwIm2DVertexSetU(&verts[3], u2, recipz); - RwIm2DVertexSetV(&verts[3], v1, recipz); - RwIm2DVertexSetIntRGBA(&verts[3], color.red, color.green, color.blue, color.alpha); -} - -void -CMBlur::MotionBlurRender(RwCamera *cam, uint32 red, uint32 green, uint32 blue, uint32 blur, int32 type, uint32 bluralpha) -{ -#ifdef EXTENDED_COLOURFILTER - CPostFX::Render(cam, red, green, blue, blur, type, bluralpha); -#else - PUSH_RENDERGROUP("CMBlur::MotionBlurRender"); - RwRGBA color = { (RwUInt8)red, (RwUInt8)green, (RwUInt8)blue, (RwUInt8)blur }; -#ifdef GTA_PS2 - if( pFrontBuffer ) - OverlayRender(cam, pFrontBuffer, color, type, bluralpha); -#else - if(ms_bJustInitialised) - ms_bJustInitialised = false; - else - OverlayRender(cam, pFrontBuffer, color, type, bluralpha); - if(BlurOn){ - RwRasterPushContext(pFrontBuffer); - RwRasterRenderFast(RwCameraGetRaster(cam), 0, 0); - RwRasterPopContext(); - } -#endif - POP_RENDERGROUP(); -#endif -} - -static uint8 DrunkBlurRed = 128; -static uint8 DrunkBlurGreen = 128; -static uint8 DrunkBlurBlue = 128; -static int32 DrunkBlurIncrement = 1; - -void -CMBlur::OverlayRender(RwCamera *cam, RwRaster *raster, RwRGBA color, int32 type, int32 bluralpha) -{ - int r, g, b, a; - - r = color.red; - g = color.green; - b = color.blue; - a = color.alpha; - - DefinedState(); - - switch(type) - { - case MOTION_BLUR_SECURITY_CAM: - r = 0; - g = 255; - b = 0; - a = 128; - break; - case MOTION_BLUR_INTRO: - r = 100; - g = 220; - b = 230; - a = 158; - break; - case MOTION_BLUR_INTRO2: - r = 80; - g = 255; - b = 230; - a = 138; - break; - case MOTION_BLUR_INTRO3: - r = 255; - g = 60; - b = 60; - a = 200; - break; - case MOTION_BLUR_INTRO4: - r = 255; - g = 180; - b = 180; - a = 128; - break; - } - - if(!BlurOn){ - // gta clamps these to 255 (probably a macro or inlined function) - int ovR = r * 0.6f; - int ovG = g * 0.6f; - int ovB = b * 0.6f; - int ovA = type == MOTION_BLUR_SNIPER ? a : a*0.6f; - RwIm2DVertexSetIntRGBA(&Vertex[0], ovR, ovG, ovB, ovA); - RwIm2DVertexSetIntRGBA(&Vertex[1], ovR, ovG, ovB, ovA); - RwIm2DVertexSetIntRGBA(&Vertex[2], ovR, ovG, ovB, ovA); - RwIm2DVertexSetIntRGBA(&Vertex[3], ovR, ovG, ovB, ovA); - }else{ - RwIm2DVertexSetIntRGBA(&Vertex2[0], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex[0], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex2[1], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex[1], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex2[2], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex[2], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex2[3], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex[3], r, g, b, a); - } - - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERNEAREST); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, raster); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - - if(BlurOn){ - if(type == MOTION_BLUR_SNIPER){ - RwIm2DVertexSetIntRGBA(&Vertex2[0], r, g, b, 80); - RwIm2DVertexSetIntRGBA(&Vertex2[1], r, g, b, 80); - RwIm2DVertexSetIntRGBA(&Vertex2[2], r, g, b, 80); - RwIm2DVertexSetIntRGBA(&Vertex2[3], r, g, b, 80); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - pBufVertCount = 0; - }else{ - RwIm2DVertexSetIntRGBA(&Vertex2[0], r*2, g*2, b*2, 30); - RwIm2DVertexSetIntRGBA(&Vertex2[1], r*2, g*2, b*2, 30); - RwIm2DVertexSetIntRGBA(&Vertex2[2], r*2, g*2, b*2, 30); - RwIm2DVertexSetIntRGBA(&Vertex2[3], r*2, g*2, b*2, 30); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, Vertex2, 4, Index, 6); - - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - - RwIm2DVertexSetIntRGBA(&Vertex2[0], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex[0], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex2[1], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex[1], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex2[2], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex[2], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex2[3], r, g, b, a); - RwIm2DVertexSetIntRGBA(&Vertex[3], r, g, b, a); - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, Vertex, 4, Index, 6); - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, Vertex2, 4, Index, 6); - } - } - - int DrunkBlurAlpha = 175.0f * Drunkness; - if(DrunkBlurAlpha != 0){ - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - if(BlurOn){ - RwIm2DVertexSetIntRGBA(&Vertex[0], 255, 255, 255, DrunkBlurAlpha); - RwIm2DVertexSetIntRGBA(&Vertex[1], 255, 255, 255, DrunkBlurAlpha); - RwIm2DVertexSetIntRGBA(&Vertex[2], 255, 255, 255, DrunkBlurAlpha); - RwIm2DVertexSetIntRGBA(&Vertex[3], 255, 255, 255, DrunkBlurAlpha); - }else{ - RwIm2DVertexSetIntRGBA(&Vertex[0], DrunkBlurRed, DrunkBlurGreen, DrunkBlurBlue, DrunkBlurAlpha); - RwIm2DVertexSetIntRGBA(&Vertex[1], DrunkBlurRed, DrunkBlurGreen, DrunkBlurBlue, DrunkBlurAlpha); - RwIm2DVertexSetIntRGBA(&Vertex[2], DrunkBlurRed, DrunkBlurGreen, DrunkBlurBlue, DrunkBlurAlpha); - RwIm2DVertexSetIntRGBA(&Vertex[3], DrunkBlurRed, DrunkBlurGreen, DrunkBlurBlue, DrunkBlurAlpha); - if(DrunkBlurIncrement){ - if(DrunkBlurRed < 255) DrunkBlurRed++; - if(DrunkBlurGreen < 255) DrunkBlurGreen++; - if(DrunkBlurBlue < 255) DrunkBlurBlue++; - if(DrunkBlurRed == 255) - DrunkBlurIncrement = 0; - }else{ - if(DrunkBlurRed > 128) DrunkBlurRed--; - if(DrunkBlurGreen > 128) DrunkBlurGreen--; - if(DrunkBlurBlue > 128) DrunkBlurBlue--; - if(DrunkBlurRed == 128) - DrunkBlurIncrement = 1; - } - } - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, Vertex, 4, Index, 6); - } - - if(type != MOTION_BLUR_SNIPER) - OverlayRenderFx(cam, pFrontBuffer); - - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); -} - -void -CMBlur::SetDrunkBlur(float drunkness) -{ - Drunkness = Clamp(drunkness, 0.0f, 1.0f); -} - -void -CMBlur::ClearDrunkBlur() -{ - Drunkness = 0.0f; - CTimer::SetTimeScale(1.0f); -} - -#define NUM_RENDER_FX 64 - -static RwRect fxRect[NUM_RENDER_FX]; -static FxType fxType[NUM_RENDER_FX]; -static float fxZ[NUM_RENDER_FX]; - -bool -CMBlur::PosInside(RwRect *rect, float x1, float y1, float x2, float y2) -{ - if((rect->x < x1 - 10.0f || rect->x > x2 + 10.0f || rect->y < y1 - 10.0f || rect->y > y2 + 10.0f) && - (rect->w < x1 - 10.0f || rect->w > x2 + 10.0f || rect->h < y1 - 10.0f || rect->h > y2 + 10.0f) && - (rect->x < x1 - 10.0f || rect->x > x2 + 10.0f || rect->h < y1 - 10.0f || rect->h > y2 + 10.0f) && - (rect->w < x1 - 10.0f || rect->w > x2 + 10.0f || rect->y < y1 - 10.0f || rect->y > y2 + 10.0f)) - return false; - return true; -} - -bool -CMBlur::AddRenderFx(RwCamera *cam, RwRect *rect, float z, FxType type) -{ - if(pBufVertCount >= NUM_RENDER_FX) - return false; - - rect->x = Max(rect->x, 0); - rect->y = Max(rect->y, 0); - rect->w = Min(rect->w, SCREEN_WIDTH); - rect->h = Min(rect->h, SCREEN_HEIGHT); - if(rect->x >= rect->w || rect->y >= rect->h) - return false; - - switch(type){ - case FXTYPE_WATER1: - case FXTYPE_WATER2: - case FXTYPE_BLOOD1: - case FXTYPE_BLOOD2: - case FXTYPE_HEATHAZE: // code seems to be duplicated for this case - for(int i = 0; i < pBufVertCount; i++) - if(fxType[i] == type && PosInside(rect, fxRect[i].x-10.0f, fxRect[i].y-10.0f, fxRect[i].w+10.0f, fxRect[i].h+10.0f)) - return false; - // TODO: fix aspect ratio scaling - // radar - if(PosInside(rect, 40.0f, SCREEN_SCALE_FROM_BOTTOM(116.0f), 40.0f + SCREEN_SCALE_X(94.0f), SCREEN_SCALE_FROM_BOTTOM(116.0f - 76.0f))) - return false; - // HUD - if(PosInside(rect, 400.0f, 0.0f, SCREEN_WIDTH, 90.0f)) - return false; - // vehicle name - if(CHud::m_VehicleState != 0 && PosInside(rect, SCREEN_WIDTH/2, 350.0f, SCREEN_WIDTH, SCREEN_HEIGHT)) - return false; - // zone name - if(CHud::m_ZoneState != 0 && PosInside(rect, SCREEN_WIDTH/2, 350.0f, SCREEN_WIDTH, SCREEN_HEIGHT)) - return false; - break; - } - - fxRect[pBufVertCount] = *rect; - fxZ[pBufVertCount] = z; - fxType[pBufVertCount] = type; - pBufVertCount++; - - return true; -} - -void -CMBlur::OverlayRenderFx(RwCamera *cam, RwRaster *frontBuf) -{ - bool drawWaterDrops = false; - RwIm2DVertex verts[4]; - int red = (0.75f*CTimeCycle::GetDirectionalRed() + CTimeCycle::GetAmbientRed())*0.55f * 255; - int green = (0.75f*CTimeCycle::GetDirectionalGreen() + CTimeCycle::GetAmbientGreen())*0.55f * 255; - int blue = (0.75f*CTimeCycle::GetDirectionalBlue() + CTimeCycle::GetAmbientBlue())*0.55f * 255; - red = Clamp(red, 0, 255); - green = Clamp(green, 0, 255); - blue = Clamp(blue, 0, 255); - - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - -#ifdef LIBRW - rw::SetRenderState(rw::STENCILENABLE, TRUE); -#else - RwD3D8SetRenderState(D3DRS_STENCILENABLE, TRUE); -#endif - - for(int i = 0; i < pBufVertCount; i++) - switch(fxType[i]){ - case FXTYPE_WATER1: - case FXTYPE_WATER2: - case FXTYPE_BLOOD1: - case FXTYPE_BLOOD2: { - drawWaterDrops = true; - int32 width = Pow(2.0f, int32(log2(RwRasterGetWidth (RwCameraGetRaster(cam))))+1); - int32 height = Pow(2.0f, int32(log2(RwRasterGetHeight(RwCameraGetRaster(cam))))+1); - - float u1Off = (fxRect[i].w - fxRect[i].x)/width; - float u2Off = u1Off - (fxRect[i].w - fxRect[i].x + 0.5f)*0.66f/width; - float halfHeight = (fxRect[i].h - fxRect[i].y + 0.5f)*0.25f/height; - - if(RwRasterGetDepth(RwCameraGetRaster(cam)) == 16){ - if(fxType[i] == FXTYPE_BLOOD1 || fxType[i] == FXTYPE_BLOOD2) - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(255, 0, 0, 128), 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); - else - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(32, 32, 32, 225), 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); - }else{ - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(32, 32, 32, 225), 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); - } - - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpDotRaster); -#ifdef LIBRW - rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILALWAYS); - rw::SetRenderState(rw::STENCILFUNCTIONREF, 1); - rw::SetRenderState(rw::STENCILFUNCTIONMASK, 0xFFFFFFFF); - rw::SetRenderState(rw::STENCILFUNCTIONWRITEMASK, 0xFFFFFFFF); - rw::SetRenderState(rw::STENCILZFAIL, rw::STENCILKEEP); - rw::SetRenderState(rw::STENCILFAIL, rw::STENCILKEEP); - rw::SetRenderState(rw::STENCILPASS, rw::STENCILREPLACE); -#else - RwD3D8SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); - RwD3D8SetRenderState(D3DRS_STENCILREF, 1); - RwD3D8SetRenderState(D3DRS_STENCILMASK, 0xFFFFFFFF); - RwD3D8SetRenderState(D3DRS_STENCILWRITEMASK, 0xFFFFFFFF); - RwD3D8SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP); - RwD3D8SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP); - RwD3D8SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); -#endif - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); - - if(RwRasterGetDepth(RwCameraGetRaster(cam)) != 16){ - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, frontBuf); -#ifdef LIBRW - rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILEQUAL); - rw::SetRenderState(rw::STENCILPASS, rw::STENCILKEEP); -#else - RwD3D8SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL); - RwD3D8SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); -#endif - if(BlurOn){ - if(fxType[i] == FXTYPE_BLOOD1 || fxType[i] == FXTYPE_BLOOD2) - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(255, 0, 0, 255), u1Off, 0.0f+halfHeight, u2Off, 0.0f-halfHeight, fxZ[i], false); - else - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(225, 225, 225, 160), u1Off, 0.0f+halfHeight, u2Off, 0.0f-halfHeight, fxZ[i], false); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDDESTALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVDESTALPHA); - }else{ - if(fxType[i] == FXTYPE_BLOOD1 || fxType[i] == FXTYPE_BLOOD2) - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(255, 0, 0, 128), u1Off, 0.0f+halfHeight, u2Off, 0.0f-halfHeight, fxZ[i], false); - else - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(128, 128, 128, 32), u1Off, 0.0f+halfHeight, u2Off, 0.0f-halfHeight, fxZ[i], false); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - } - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); - } - break; - } - case FXTYPE_SPLASH1: - case FXTYPE_SPLASH2: - case FXTYPE_SPLASH3: - drawWaterDrops = true; - break; - - case FXTYPE_HEATHAZE: - if(TheCamera.GetScreenFadeStatus() == FADE_0 && frontBuf){ - int alpha = FrontEndMenuManager.m_PrefsBrightness > 255 ? - FrontEndMenuManager.m_PrefsBrightness - 90 : - FrontEndMenuManager.m_PrefsBrightness - 130; - alpha = Clamp(alpha, 16, 200)/2; - - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(0, 0, 0, alpha), 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpHeatHazeRaster); -#ifdef LIBRW - rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILALWAYS); - rw::SetRenderState(rw::STENCILFUNCTIONREF, 1); - rw::SetRenderState(rw::STENCILFUNCTIONMASK, 0xFFFFFFFF); - rw::SetRenderState(rw::STENCILFUNCTIONWRITEMASK, 0xFFFFFFFF); - rw::SetRenderState(rw::STENCILZFAIL, rw::STENCILKEEP); - rw::SetRenderState(rw::STENCILFAIL, rw::STENCILKEEP); - rw::SetRenderState(rw::STENCILPASS, rw::STENCILREPLACE); -#else - RwD3D8SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); - RwD3D8SetRenderState(D3DRS_STENCILREF, 1); - RwD3D8SetRenderState(D3DRS_STENCILMASK, 0xFFFFFFFF); - RwD3D8SetRenderState(D3DRS_STENCILWRITEMASK, 0xFFFFFFFF); - RwD3D8SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP); - RwD3D8SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP); - RwD3D8SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); -#endif - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); - - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(255, 255, 255, alpha), - CGeneral::GetRandomNumberInRange(-0.002f, 0.002f), - CGeneral::GetRandomNumberInRange(-0.002f, 0.002f), - CGeneral::GetRandomNumberInRange(-0.002f, 0.002f), - CGeneral::GetRandomNumberInRange(-0.002f, 0.002f), - fxZ[i], false); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, frontBuf); -#ifdef LIBRW - rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILEQUAL); - rw::SetRenderState(rw::STENCILPASS, rw::STENCILKEEP); -#else - RwD3D8SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL); - RwD3D8SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); -#endif - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); - } - break; - } -#ifdef LIBRW - rw::SetRenderState(rw::STENCILENABLE, FALSE); -#else - RwD3D8SetRenderState(D3DRS_STENCILENABLE, FALSE); -#endif - - if(drawWaterDrops){ - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - - // Draw drops - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpRainDripRaster[0]); - for(int i = 0; i < pBufVertCount; i++) - if(fxType[i] == FXTYPE_WATER1 || fxType[i] == FXTYPE_BLOOD1){ - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(red, green, blue, fxType[i] == FXTYPE_BLOOD1 ? 255 : 192), - 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); - } - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpRainDripRaster[1]); - for(int i = 0; i < pBufVertCount; i++) - if(fxType[i] == FXTYPE_WATER2 || fxType[i] == FXTYPE_BLOOD2){ - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(red, green, blue, fxType[i] == FXTYPE_BLOOD2 ? 255 : 192), - 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); - } - - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpCarSplashRaster[0]); - for(int i = 0; i < pBufVertCount; i++) - if(fxType[i] == FXTYPE_SPLASH1 || fxType[i] == FXTYPE_SPLASH2 || fxType[i] == FXTYPE_SPLASH3){ - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(200, 200, 200, 255), - 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); - } - - // Darken the water drops - int alpha = 192*0.5f; - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpRainDripDarkRaster[0]); - for(int i = 0; i < pBufVertCount; i++) - if(fxType[i] == FXTYPE_WATER1){ - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(red, green, blue, alpha), - 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); - } - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpRainDripDarkRaster[1]); - for(int i = 0; i < pBufVertCount; i++) - if(fxType[i] == FXTYPE_WATER2){ - CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(red, green, blue, alpha), - 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); - } - } - - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - pBufVertCount = 0; -} diff --git a/src/render/MBlur.h b/src/render/MBlur.h deleted file mode 100644 index 3dc53082..00000000 --- a/src/render/MBlur.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -enum FxType -{ - FXTYPE_WATER1, - FXTYPE_WATER2, - FXTYPE_BLOOD1, - FXTYPE_BLOOD2, - FXTYPE_HEATHAZE, - FXTYPE_SPLASH1, - FXTYPE_SPLASH2, - FXTYPE_SPLASH3 -}; - -class CMBlur -{ -public: - static RwRaster *pFrontBuffer; - static bool ms_bJustInitialised; - static bool ms_bScaledBlur; - static bool BlurOn; - static float Drunkness; - - static int32 pBufVertCount; - -public: - static RwBool MotionBlurOpen(RwCamera *cam); - static RwBool MotionBlurClose(void); - static void CreateImmediateModeData(RwCamera *cam, RwRect *rect); - static void CreateImmediateModeData(RwCamera *cam, RwRect *rect, RwIm2DVertex *verts, RwRGBA color, float u1Off, float v1Off, float u2Off, float v2Off, float z, int fullTexture); - static void MotionBlurRender(RwCamera *cam, uint32 red, uint32 green, uint32 blue, uint32 blur, int32 type, uint32 bluralpha); - static void OverlayRender(RwCamera *cam, RwRaster *raster, RwRGBA color, int32 type, int32 bluralpha); - static void SetDrunkBlur(float drunkness); - static void ClearDrunkBlur(); - - static bool PosInside(RwRect *rect, float x1, float y1, float x2, float y2); - static bool AddRenderFx(RwCamera *cam, RwRect *rect, float z, FxType type); - static void OverlayRenderFx(RwCamera *cam, RwRaster *frontBuf); -}; diff --git a/src/render/Occlusion.cpp b/src/render/Occlusion.cpp deleted file mode 100644 index ec7101a6..00000000 --- a/src/render/Occlusion.cpp +++ /dev/null @@ -1,530 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "Entity.h" -#include "Occlusion.h" -#include "Game.h" -#include "Camera.h" -#include "Vector.h" -#include "Draw.h" -#include "Timer.h" -#include "RwHelper.h" -#include "VarConsole.h" - -int32 COcclusion::NumOccludersOnMap; -int16 COcclusion::FarAwayList; -int16 COcclusion::NearbyList; -int16 COcclusion::ListWalkThroughFA; -int16 COcclusion::PreviousListWalkThroughFA; -int16 COcclusion::NumActiveOccluders; -COccluder COcclusion::aOccluders[NUMOCCLUSIONVOLUMES]; -CActiveOccluder COcclusion::aActiveOccluders[NUMACTIVEOCCLUDERS]; - -CVector gCenterOnScreen; - -float gMinYInOccluder; -float gMinXInOccluder; -float gMaxYInOccluder; -float gMaxXInOccluder; - -bool gOccluderCoorsValid[8]; -CVector gOccluderCoorsOnScreen[8]; -CVector gOccluderCoors[8]; - -#ifndef MASTER -bool bDispayOccDebugStuff; // disPAY, yeah -#endif - -void -COcclusion::Init(void) -{ - NumOccludersOnMap = 0; -#ifndef MASTER - VarConsole.Add("Occlusion debug", &bDispayOccDebugStuff, true); -#endif - FarAwayList = -1; - NearbyList = -1; - ListWalkThroughFA = -1; - PreviousListWalkThroughFA = -1; -} - -void -COcclusion::AddOne(float x, float y, float z, float width, float length, float height, float angle) -{ - if(NumOccludersOnMap >= NUMOCCLUSIONVOLUMES) - return; - - aOccluders[NumOccludersOnMap].x = x; - aOccluders[NumOccludersOnMap].y = y; - aOccluders[NumOccludersOnMap].z = z; - aOccluders[NumOccludersOnMap].width = width; - aOccluders[NumOccludersOnMap].length = length; - aOccluders[NumOccludersOnMap].height = height; - while(angle < 0.0f) angle += 360.0f; - while(angle > 360.0f) angle -= 360.0f; - aOccluders[NumOccludersOnMap].angle = angle/360.0f * UINT16_MAX; - aOccluders[NumOccludersOnMap].listIndex = FarAwayList; - FarAwayList = NumOccludersOnMap++; -} - -bool -COccluder::NearCamera() { - return (TheCamera.GetPosition() - CVector(x, y, z)).Magnitude() - (Max(width, length) / 2.0f) < 250.0f; -} - -bool -DoesInfiniteLineCrossFiniteLine(float p1X, float p1Y, float p2X, float p2Y, float lineX, float lineY, float lineDX, float lineDY) -{ - float side1 = (p1X - lineX) * lineDY - (p1Y - lineY) * lineDX; - float side2 = (p2X - lineX) * lineDY - (p2Y - lineY) * lineDX; - return side1 * side2 < 0.0f; // if points lie on opposite sides of the infinte line, the line between them crosses it -} - -bool DoesInfiniteLineTouchScreen(float lineX, float lineY, float lineDX, float lineDY) { - if (lineX > 0.0f && lineY > 0.0f && SCREEN_WIDTH > lineX && SCREEN_HEIGHT > lineY) - return true; - - return (DoesInfiniteLineCrossFiniteLine(0.0f, 0.0f, SCREEN_WIDTH, 0.0f, lineX, lineY, lineDX, lineDY) || - DoesInfiniteLineCrossFiniteLine(0.0f, 0.0f, 0.0f, SCREEN_HEIGHT, lineX, lineY, lineDX, lineDY) || - DoesInfiniteLineCrossFiniteLine(SCREEN_WIDTH, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, lineX, lineY, lineDX, lineDY) || - DoesInfiniteLineCrossFiniteLine(0.0f, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, lineX, lineY, lineDX, lineDY)); -} - -bool IsPointInsideLine(float lineX, float lineY, float lineDX, float lineDY, float pX, float pY, float area = 0.0f) { - return (pX - lineX) * lineDY - (pY - lineY) * lineDX >= area; -} - -bool CalcScreenCoors(CVector const &in, CVector *out, float *outw, float *outh) { - *out = TheCamera.m_viewMatrix * in; - - if (out->z <= 1.0f) return false; - - float recip = 1.0f / out->z; - out->x *= SCREEN_WIDTH * recip; - out->y *= SCREEN_HEIGHT * recip; - - float fovScale = DefaultFOV / CDraw::GetFOV(); - - *outw = fovScale * recip * SCREEN_WIDTH; - *outh = fovScale * recip * SCREEN_HEIGHT; - - return true; -} - -bool CalcScreenCoors(CVector const &in, CVector *out) { - *out = TheCamera.m_viewMatrix * in; - - if (out->z <= 1.0f) return false; - - float recip = 1.0f / out->z; - out->x *= SCREEN_WIDTH * recip; - out->y *= SCREEN_HEIGHT * recip; - - return true; -} - -bool -COccluder::ProcessLineSegment(int corner1, int corner2, CActiveOccluder *occl) { - if (!gOccluderCoorsValid[corner1] && !gOccluderCoorsValid[corner2]) - return false; - - float x1, y1, x2, y2; - - CVector p1, p2; - if (!gOccluderCoorsValid[corner1]) { - float clipDist1 = Abs((TheCamera.m_viewMatrix * gOccluderCoors[corner1]).z - 1.1f); - float clipDist2 = Abs((TheCamera.m_viewMatrix * gOccluderCoors[corner2]).z - 1.1f); - float ratio = clipDist2 / (clipDist1 + clipDist2); - CVector clippedCoors = (1.0f - ratio) * gOccluderCoors[corner2] + ratio * gOccluderCoors[corner1]; - - if (!CalcScreenCoors(clippedCoors, &p1, &x1, &y1)) - return true; - } - else { - p1 = gOccluderCoorsOnScreen[corner1]; - } - - if (!gOccluderCoorsValid[corner2]) { - float clipDist1 = Abs((TheCamera.m_viewMatrix * gOccluderCoors[corner1]).z - 1.1f); - float clipDist2 = Abs((TheCamera.m_viewMatrix * gOccluderCoors[corner2]).z - 1.1f); - float ratio = clipDist1 / (clipDist1 + clipDist2); - CVector clippedCoors = (1.0f - ratio) * gOccluderCoors[corner2] + ratio * gOccluderCoors[corner1]; - - if (!CalcScreenCoors(clippedCoors, &p2, &x2, &y2)) - return true; - } - else { - p2 = gOccluderCoorsOnScreen[corner2]; - } - - gMinXInOccluder = Min(Min(gMinXInOccluder, p1.x), p2.x); - gMaxXInOccluder = Max(Max(gMaxXInOccluder, p1.x), p2.x); - gMinYInOccluder = Min(Min(gMinYInOccluder, p1.y), p2.y); - gMaxYInOccluder = Max(Max(gMaxYInOccluder, p1.y), p2.y); - - CVector2D origin = p1; - CVector2D direction = p2 - p1; - - // Make sure lines are counter-clockwise around center - if (!IsPointInsideLine(origin.x, origin.y, direction.x, direction.y, gCenterOnScreen.x, gCenterOnScreen.y, 0.0f)) { - origin += direction; - direction *= -1.0f; - } - - float magnitude = direction.Magnitude(); - - occl->lines[occl->linesCount].origin = origin; - occl->lines[occl->linesCount].direction = direction / magnitude; - occl->lines[occl->linesCount].length = magnitude; - - if (!DoesInfiniteLineTouchScreen(origin.x, origin.y, direction.x, direction.y)) - return !IsPointInsideLine(origin.x, origin.y, direction.x, direction.y, SCREEN_WIDTH / 2.0f, SCREEN_HEIGHT / 2.0f, 0.0f); - - occl->linesCount++; - - return false; -} - -bool -COccluder::ProcessOneOccluder(CActiveOccluder *occl) { - float outX, outY; - - occl->linesCount = 0; - CVector pos(x, y, z); - - if (!CalcScreenCoors(pos, &gCenterOnScreen, &outX, &outY) || gCenterOnScreen.z < -150.0f || gCenterOnScreen.z > 300.0f) { - return false; - } - - occl->radius = Max(width, length) * 0.35f + gCenterOnScreen.z; - - CVector vec[3]; - - vec[0].x = length / 2.0f * Sin(GetAngle()); - vec[0].y = -length / 2.0f * Cos(GetAngle()); - vec[0].z = 0.0f; - - vec[1].x = width / 2.0f * Cos(GetAngle()); - vec[1].y = width / 2.0f * Sin(GetAngle()); - vec[1].z = 0.0f; - - vec[2].x = 0.0f; - vec[2].y = 0.0f; - vec[2].z = height / 2.0f; - - // Figure out if we see the front or back of a face - bool bFrontFace[6]; - for (int i = 0; i < 3; i++) { - bFrontFace[i*2+0] = DotProduct((pos + vec[i] - TheCamera.GetPosition()), vec[i]) < 0.0f; - bFrontFace[i*2+1] = DotProduct((pos - vec[i] - TheCamera.GetPosition()), -vec[i]) < 0.0f; - } - - //calculating vertices of a box - gOccluderCoors[0] = pos + vec[0] + vec[1] + vec[2]; - gOccluderCoors[1] = pos - vec[0] + vec[1] + vec[2]; - gOccluderCoors[2] = pos + vec[0] - vec[1] + vec[2]; - gOccluderCoors[3] = pos - vec[0] - vec[1] + vec[2]; - gOccluderCoors[4] = pos + vec[0] + vec[1] - vec[2]; - gOccluderCoors[5] = pos - vec[0] + vec[1] - vec[2]; - gOccluderCoors[6] = pos + vec[0] - vec[1] - vec[2]; - gOccluderCoors[7] = pos - vec[0] - vec[1] - vec[2]; - - for(int i = 0; i < 8; i++) - gOccluderCoorsValid[i] = CalcScreenCoors(gOccluderCoors[i], &gOccluderCoorsOnScreen[i], &outX, &outY); - - gMinYInOccluder = 999999.875f; - gMinXInOccluder = 999999.875f; - gMaxYInOccluder = -999999.875f; - gMaxXInOccluder = -999999.875f; - - // Between two differently facing sides we see an edge, so process those - if (bFrontFace[2] != bFrontFace[0] && ProcessLineSegment(0, 4, occl)) - return false; - if (bFrontFace[3] != bFrontFace[0] && ProcessLineSegment(2, 6, occl)) - return false; - if (bFrontFace[4] != bFrontFace[0] && ProcessLineSegment(0, 2, occl)) - return false; - if (bFrontFace[5] != bFrontFace[0] && ProcessLineSegment(4, 6, occl)) - return false; - if (bFrontFace[2] != bFrontFace[1] && ProcessLineSegment(1, 5, occl)) - return false; - if (bFrontFace[3] != bFrontFace[1] && ProcessLineSegment(3, 7, occl)) - return false; - if (bFrontFace[4] != bFrontFace[1] && ProcessLineSegment(1, 3, occl)) - return false; - if (bFrontFace[5] != bFrontFace[1] && ProcessLineSegment(5, 7, occl)) - return false; - if (bFrontFace[4] != bFrontFace[2] && ProcessLineSegment(0, 1, occl)) - return false; - if (bFrontFace[3] != bFrontFace[4] && ProcessLineSegment(2, 3, occl)) - return false; - if (bFrontFace[5] != bFrontFace[3] && ProcessLineSegment(6, 7, occl)) - return false; - if (bFrontFace[2] != bFrontFace[5] && ProcessLineSegment(4, 5, occl)) - return false; - - if (gMaxXInOccluder - gMinXInOccluder < SCREEN_WIDTH * 0.1f || - gMaxYInOccluder - gMinYInOccluder < SCREEN_HEIGHT * 0.07f) - return false; - - return true; -} - -bool -COcclusion::OccluderHidesBehind(CActiveOccluder *occl1, CActiveOccluder *occl2) { - for (int i = 0; i < occl1->linesCount; i++) { - for (int j = 0; j < occl2->linesCount; j++) { - if (!IsPointInsideLine(occl2->lines[j].origin.x, occl2->lines[j].origin.y, occl2->lines[j].direction.x, - occl2->lines[j].direction.y, occl1->lines[i].origin.x, occl1->lines[i].origin.y, 0.0f)) - return false; - - - if (!IsPointInsideLine(occl2->lines[j].origin.x, occl2->lines[j].origin.y, occl2->lines[j].direction.x, - occl2->lines[j].direction.y, (occl1->lines[i].origin.x + occl1->lines[i].direction.x * occl1->lines[i].length), - (occl1->lines[i].origin.y + occl1->lines[i].direction.y * occl1->lines[i].length), 0.0f)) - return false; - } - } - - return true; -} - -void -COcclusion::ProcessBeforeRendering(void) -{ - NumActiveOccluders = 0; - -#ifndef MASTER - if (gbModelViewer) - return; -#endif - - if (CGame::currArea != AREA_MAIN_MAP) - return; - - if (ListWalkThroughFA == -1) { - PreviousListWalkThroughFA = -1; - ListWalkThroughFA = FarAwayList; - } - - int i; - for (i = 0; i < 16 && ListWalkThroughFA != -1; i++) { - if (aOccluders[ListWalkThroughFA].NearCamera()) { - int prevListWalkThroughFA = ListWalkThroughFA; - - if (PreviousListWalkThroughFA == -1) { - FarAwayList = aOccluders[ListWalkThroughFA].listIndex; - } - else { - aOccluders[PreviousListWalkThroughFA].listIndex = aOccluders[ListWalkThroughFA].listIndex; - } - - int prevNearbyList = NearbyList; - ListWalkThroughFA = aOccluders[ListWalkThroughFA].listIndex; - NearbyList = prevListWalkThroughFA; - aOccluders[prevListWalkThroughFA].listIndex = prevNearbyList; - } - else { - PreviousListWalkThroughFA = ListWalkThroughFA; - ListWalkThroughFA = aOccluders[ListWalkThroughFA].listIndex; - } - } - - int prevNearbyList = -1; - int tmpNearbyList = NearbyList; - int indexTmpNearbyList, storeTmpNearbyList, prevFarAwayList; - while (tmpNearbyList != -1) - { - if (NumActiveOccluders < NUMACTIVEOCCLUDERS && aOccluders[tmpNearbyList].ProcessOneOccluder(&aActiveOccluders[NumActiveOccluders])) - ++NumActiveOccluders; - - indexTmpNearbyList = tmpNearbyList; - if (aOccluders[indexTmpNearbyList].NearCamera()) - { - prevNearbyList = tmpNearbyList; - tmpNearbyList = aOccluders[indexTmpNearbyList].listIndex; - - } - else - { - storeTmpNearbyList = tmpNearbyList; - if (prevNearbyList == -1) { - NearbyList = aOccluders[indexTmpNearbyList].listIndex; - } - else { - aOccluders[prevNearbyList].listIndex = aOccluders[indexTmpNearbyList].listIndex; - } - tmpNearbyList = aOccluders[indexTmpNearbyList].listIndex; - prevFarAwayList = FarAwayList; - FarAwayList = storeTmpNearbyList; - aOccluders[storeTmpNearbyList].listIndex = prevFarAwayList; - } - } - - for (i = 0; i < NumActiveOccluders; i++) { - for (int j = 0; j < NumActiveOccluders; j++) { - if (i != j && aActiveOccluders[j].radius < aActiveOccluders[i].radius) { - if (OccluderHidesBehind(&aActiveOccluders[i], &aActiveOccluders[j])) { - for (int k = i; k < NumActiveOccluders - 1; k++) { - for (int l = 0; l < aActiveOccluders[k + 1].linesCount; l++) - aActiveOccluders[k].lines[l] = aActiveOccluders[k + 1].lines[l]; - aActiveOccluders[k].linesCount = aActiveOccluders[k + 1].linesCount; - aActiveOccluders[k].radius = aActiveOccluders[k + 1].radius; - } - NumActiveOccluders--; - i--; - // Taken from Mobile! -#ifdef FIX_BUGS - if (i == -1) { - i = 0; - } -#endif - } - } - } - } -} - -bool CActiveOccluder::IsPointWithinOcclusionArea(float pX, float pY, float area) { - for (int i = 0; i < linesCount; i++) { - if (!IsPointInsideLine(lines[i].origin.x, lines[i].origin.y, lines[i].direction.x, lines[i].direction.y, pX, pY, area)) - return false; - } - - return true; -} - -bool COcclusion::IsAABoxOccluded(CVector pos, float width, float length, float height) { - - CVector coors; - float outW, outH; - - if (!NumActiveOccluders || !CalcScreenCoors(pos, &coors, &outW, &outH)) - return false; - - float side = CVector(width, length, height).Magnitude() / 4.0f; - float area = Max(outW, outH) * side; - - CVector minCorner, maxCorner; - - minCorner.x = pos.x - width / 2.0f; - minCorner.y = pos.y - length / 2.0f; - minCorner.z = pos.z - height / 2.0f; - - maxCorner.x = pos.x + width / 2.0f; - maxCorner.y = pos.y + length / 2.0f; - maxCorner.z = pos.z + height / 2.0f; - - for (int i = 0; i < NumActiveOccluders; i++) { - if (coors.z - (side * 0.85f) > aActiveOccluders[i].radius) { - if (aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, area)) - return true; - - if (aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) { - if (CalcScreenCoors(minCorner, &coors) && !aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; - if (CalcScreenCoors(CVector(maxCorner.x, maxCorner.y, minCorner.z), &coors) && !aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; - if (CalcScreenCoors(CVector(maxCorner.x, minCorner.y, maxCorner.z), &coors) && !aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; - if (CalcScreenCoors(CVector(minCorner.x, maxCorner.y, maxCorner.z), &coors, &outW, &outH) && !aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; - - return true; - } - } - } - - return false; -} - -bool COcclusion::IsPositionOccluded(CVector pos, float side) { - - CVector coors; - float width, height; - - if (!NumActiveOccluders || !CalcScreenCoors(pos, &coors, &width, &height)) - return false; - - float area = Max(width, height) * side; - - for (int i = 0; i < NumActiveOccluders; i++) { - if (coors.z - (side * 0.85f) > aActiveOccluders[i].radius) - if (aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, area)) - return true; - } - - return false; -} - -#ifndef MASTER -#include "Lines.h" - -RwIm2DVertex vertexbufferT[2]; - -void COcclusion::Render() { - if (!bDispayOccDebugStuff || !(CTimer::GetTimeInMilliseconds() & 0x200)) - return; - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, FALSE); - - float recipz = 1.0f/RwCameraGetNearClipPlane(Scene.camera); - for (int i = 0; i < NumActiveOccluders; i++) { - for (int j = 0; j < aActiveOccluders[i].linesCount; j++) { - RwIm2DVertexSetScreenX(&vertexbufferT[0], aActiveOccluders[i].lines[j].origin.x); - RwIm2DVertexSetScreenY(&vertexbufferT[0], aActiveOccluders[i].lines[j].origin.y); - RwIm2DVertexSetScreenZ(&vertexbufferT[0], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&vertexbufferT[0], RwCameraGetNearClipPlane(Scene.camera)); - RwIm2DVertexSetRecipCameraZ(&vertexbufferT[0], recipz); - - RwIm2DVertexSetScreenX(&vertexbufferT[1], - aActiveOccluders[i].lines[j].origin.x + aActiveOccluders[i].lines[j].direction.x * aActiveOccluders[i].lines[j].length); - RwIm2DVertexSetScreenY(&vertexbufferT[1], - aActiveOccluders[i].lines[j].origin.y + aActiveOccluders[i].lines[j].direction.y * aActiveOccluders[i].lines[j].length); - RwIm2DVertexSetScreenZ(&vertexbufferT[1], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetCameraZ(&vertexbufferT[1], RwCameraGetNearClipPlane(Scene.camera)); - RwIm2DVertexSetRecipCameraZ(&vertexbufferT[1], recipz); - - RwIm2DVertexSetIntRGBA(&vertexbufferT[0], 255, 255, 0, 255); - RwIm2DVertexSetIntRGBA(&vertexbufferT[1], 255, 255, 0, 255); - RwIm2DRenderLine(vertexbufferT, 2, 0, 1); - } - } - - DefinedState(); -} -#endif - -bool CEntity::IsEntityOccluded(void) { - - CVector coors; - float width, height; - - if (COcclusion::NumActiveOccluders == 0 || !CalcScreenCoors(GetBoundCentre(), &coors, &width, &height)) - return false; - - float area = Max(width, height) * GetBoundRadius() * 0.9f; - - for (int i = 0; i < COcclusion::NumActiveOccluders; i++) { - if (coors.z - (GetBoundRadius() * 0.85f) > COcclusion::aActiveOccluders[i].radius) { - if (COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, area)) { - return true; - } - - if (COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) { - CVector min = m_matrix * CModelInfo::GetColModel(m_modelIndex)->boundingBox.min; - CVector max = m_matrix * CModelInfo::GetColModel(m_modelIndex)->boundingBox.max; - - if (CalcScreenCoors(min, &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; - if (CalcScreenCoors(CVector(max.x, max.y, min.z), &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; - if (CalcScreenCoors(CVector(max.x, min.y, max.z), &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; - if (CalcScreenCoors(CVector(min.x, max.y, max.z), &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; - - return true; - } - } - } - - return false; -} \ No newline at end of file diff --git a/src/render/Occlusion.h b/src/render/Occlusion.h deleted file mode 100644 index e0edef53..00000000 --- a/src/render/Occlusion.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -struct ActiveOccluderLine { - CVector2D origin; - CVector2D direction; - float length; -}; - -class CActiveOccluder { - -public: - ActiveOccluderLine lines[6]; - int32 linesCount; - float radius; - - bool IsPointWithinOcclusionArea(float x, float y, float area); -}; - -class COccluder -{ -public: - int16 length, width, height; - int16 x, y, z; - uint16 angle; - int16 listIndex; - - bool NearCamera(); - bool ProcessOneOccluder(CActiveOccluder *occl); - bool ProcessLineSegment(int corner1, int corner2, CActiveOccluder* occl); - float GetAngle(void) { return angle*TWOPI/UINT16_MAX; } -}; - -class COcclusion -{ -public: - static int32 NumOccludersOnMap; - static int16 FarAwayList; - static int16 NearbyList; - static int16 ListWalkThroughFA; - static int16 PreviousListWalkThroughFA; - static int16 NumActiveOccluders; - - static COccluder aOccluders[NUMOCCLUSIONVOLUMES]; - static CActiveOccluder aActiveOccluders[NUMACTIVEOCCLUDERS]; - - static void Init(void); - static void AddOne(float x, float y, float z, float width, float length, float height, float angle); - static void ProcessBeforeRendering(void); - static bool OccluderHidesBehind(CActiveOccluder *occl1, CActiveOccluder *occl2); - static bool IsAABoxOccluded(CVector pos, float width, float length, float height); - static bool IsPositionOccluded(CVector pos, float side); -#ifndef MASTER - static void Render(); -#endif -}; - -bool CalcScreenCoors(CVector const &in, CVector *out, float *outw, float *outh); -bool CalcScreenCoors(CVector const &in, CVector *out); - -#ifndef MASTER -extern bool bDispayOccDebugStuff; -#endif \ No newline at end of file diff --git a/src/render/Particle.cpp b/src/render/Particle.cpp deleted file mode 100644 index 461a10a6..00000000 --- a/src/render/Particle.cpp +++ /dev/null @@ -1,2534 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "General.h" -#include "Timer.h" -#include "TxdStore.h" -#include "Sprite.h" -#include "Camera.h" -#include "Clock.h" -#include "Collision.h" -#include "World.h" -#include "Shadows.h" -#include "Replay.h" -#include "Stats.h" -#include "Weather.h" -#include "MBlur.h" -#include "main.h" -#include "AudioScriptObject.h" -#include "ParticleObject.h" -#include "Particle.h" -#include "soundlist.h" -#include "SaveBuf.h" -#include "debugmenu.h" - -#define MAX_PARTICLES_ON_SCREEN (750) - - -//(5) -#define MAX_SMOKE_FILES ARRAY_SIZE(SmokeFiles) - -//(5) -#define MAX_RUBBER_FILES ARRAY_SIZE(RubberFiles) -//(5) -#define MAX_RAINSPLASH_FILES ARRAY_SIZE(RainSplashFiles) -//(3) -#define MAX_WATERSPRAY_FILES ARRAY_SIZE(WatersprayFiles) -//(6) -#define MAX_EXPLOSIONMEDIUM_FILES ARRAY_SIZE(ExplosionMediumFiles) -//(4) -#define MAX_GUNFLASH_FILES ARRAY_SIZE(GunFlashFiles) -//(2) -#define MAX_RAINSPLASHUP_FILES ARRAY_SIZE(RainSplashupFiles) -//(4) -#define MAX_BIRDFRONT_FILES ARRAY_SIZE(BirdfrontFiles) -//(8) -#define MAX_BOAT_FILES ARRAY_SIZE(BoatFiles) -//(4) -#define MAX_CARDEBRIS_FILES ARRAY_SIZE(CardebrisFiles) -//(4) -#define MAX_CARSPLASH_FILES ARRAY_SIZE(CarsplashFiles) - -#define MAX_RAINDRIP_FILES (2) - -#define MAX_LEAF_FILES (2) - - -const char SmokeFiles[][6+1] = -{ - "smoke1", - "smoke2", - "smoke3", - "smoke4", - "smoke5" -}; - - -const char RubberFiles[][7+1] = -{ - "rubber1", - "rubber2", - "rubber3", - "rubber4", - "rubber5" -}; - -const char RainSplashFiles[][7+1] = -{ - "splash1", - "splash2", - "splash3", - "splash4", - "splash5" -}; - -const char WatersprayFiles[][11+1] = -{ - "waterspray1", - "waterspray2", - "waterspray3" -}; - -const char ExplosionMediumFiles[][7+1] = -{ - "explo01", - "explo02", - "explo03", - "explo04", - "explo05", - "explo06" -}; - -const char GunFlashFiles[][9+1] = -{ - "gunflash1", - "gunflash2", - "gunflash3", - "gunflash4" -}; - -const char RainSplashupFiles[][10+1] = -{ - "splash_up1", - "splash_up2" -}; - -const char BirdfrontFiles[][8+1] = -{ - "birdf_01", - "birdf_02", - "birdf_03", - "birdf_04" -}; - -const char BoatFiles[][8+1] = -{ - "boats_01", - "boats_02", - "boats_03", - "boats_04", - "boats_05", - "boats_06", - "boats_07", - "boats_08" -}; - -const char CardebrisFiles[][12+1] = -{ - "cardebris_01", - "cardebris_02", - "cardebris_03", - "cardebris_04" -}; - -const char CarsplashFiles[][12+1] = -{ - "carsplash_01", - "carsplash_02", - "carsplash_03", - "carsplash_04" -}; - -CParticle gParticleArray[MAX_PARTICLES_ON_SCREEN]; - -RwTexture *gpSmokeTex[MAX_SMOKE_FILES]; -RwTexture *gpSmoke2Tex; -RwTexture *gpRubberTex[MAX_RUBBER_FILES]; -RwTexture *gpRainSplashTex[MAX_RAINSPLASH_FILES]; -RwTexture *gpWatersprayTex[MAX_WATERSPRAY_FILES]; -RwTexture *gpExplosionMediumTex[MAX_EXPLOSIONMEDIUM_FILES]; -RwTexture *gpGunFlashTex[MAX_GUNFLASH_FILES]; -RwTexture *gpRainSplashupTex[MAX_RAINSPLASHUP_FILES]; -RwTexture *gpBirdfrontTex[MAX_BIRDFRONT_FILES]; -RwTexture *gpBoatTex[MAX_BOAT_FILES]; -RwTexture *gpCarDebrisTex[MAX_CARDEBRIS_FILES]; -RwTexture *gpCarSplashTex[MAX_CARSPLASH_FILES]; - -RwTexture *gpBoatWakeTex; -RwTexture *gpFlame1Tex; -RwTexture *gpFlame5Tex; -RwTexture *gpRainDropSmallTex; -RwTexture *gpBloodTex; -RwTexture *gpLeafTex[MAX_LEAF_FILES]; -RwTexture *gpCloudTex1; -RwTexture *gpCloudTex4; -RwTexture *gpBloodSmallTex; -RwTexture *gpGungeTex; -RwTexture *gpCollisionSmokeTex; -RwTexture *gpBulletHitTex; -RwTexture *gpGunShellTex; -RwTexture *gpPointlightTex; - -RwRaster *gpSmokeRaster[MAX_SMOKE_FILES]; -RwRaster *gpSmoke2Raster; -RwRaster *gpRubberRaster[MAX_RUBBER_FILES]; -RwRaster *gpRainSplashRaster[MAX_RAINSPLASH_FILES]; -RwRaster *gpWatersprayRaster[MAX_WATERSPRAY_FILES]; -RwRaster *gpExplosionMediumRaster[MAX_EXPLOSIONMEDIUM_FILES]; -RwRaster *gpGunFlashRaster[MAX_GUNFLASH_FILES]; -RwRaster *gpRainSplashupRaster[MAX_RAINSPLASHUP_FILES]; -RwRaster *gpBirdfrontRaster[MAX_BIRDFRONT_FILES]; -RwRaster *gpBoatRaster[MAX_BOAT_FILES]; -RwRaster *gpCarDebrisRaster[MAX_CARDEBRIS_FILES]; -RwRaster *gpCarSplashRaster[MAX_CARSPLASH_FILES]; - -RwRaster *gpBoatWakeRaster; -RwRaster *gpFlame1Raster; -RwRaster *gpFlame5Raster; -RwRaster *gpRainDropSmallRaster; -RwRaster *gpBloodRaster; -RwRaster *gpLeafRaster[MAX_LEAF_FILES]; -RwRaster *gpCloudRaster1; -RwRaster *gpCloudRaster4; -RwRaster *gpBloodSmallRaster; -RwRaster *gpGungeRaster; -RwRaster *gpCollisionSmokeRaster; -RwRaster *gpBulletHitRaster; -RwRaster *gpGunShellRaster; -RwRaster *gpPointlightRaster; - -RwTexture *gpRainDropTex; -RwRaster *gpRainDropRaster; - -RwTexture *gpSparkTex; -RwTexture *gpNewspaperTex; -RwTexture *gpGunSmokeTex; -RwTexture *gpDotTex; -RwTexture *gpHeatHazeTex; -RwTexture *gpBeastieTex; -RwTexture *gpRainDripTex[MAX_RAINDRIP_FILES]; -RwTexture *gpRainDripDarkTex[MAX_RAINDRIP_FILES]; - -RwRaster *gpSparkRaster; -RwRaster *gpNewspaperRaster; -RwRaster *gpGunSmokeRaster; -RwRaster *gpDotRaster; -RwRaster *gpHeatHazeRaster; -RwRaster *gpBeastieRaster; -RwRaster *gpRainDripRaster[MAX_RAINDRIP_FILES]; -RwRaster *gpRainDripDarkRaster[MAX_RAINDRIP_FILES]; - -float CParticle::ms_afRandTable[CParticle::RAND_TABLE_SIZE]; -CParticle *CParticle::m_pUnusedListHead; -float CParticle::m_SinTable[CParticle::SIN_COS_TABLE_SIZE]; -float CParticle::m_CosTable[CParticle::SIN_COS_TABLE_SIZE]; - -int32 Randomizer; -int32 nParticleCreationInterval = 1; -float PARTICLE_WIND_TEST_SCALE = 0.002f; -float fParticleScaleLimit = 0.5f; - -bool clearWaterDrop; -int32 numWaterDropOnScreen; - -#ifdef DEBUGMENU -SETTWEAKPATH("Particle"); -TWEAKINT32(nParticleCreationInterval, 0, 5, 1); -TWEAKFLOAT(fParticleScaleLimit, 0.0f, 1.0f, 0.1f); -TWEAKFUNC(CParticle::ReloadConfig); -#endif - - - -void CParticle::ReloadConfig() -{ - debug("Initialising CParticleMgr..."); - - mod_ParticleSystemManager.Initialise(); - - debug("Initialising CParticle..."); - - m_pUnusedListHead = gParticleArray; - - for ( int32 i = 0; i < MAX_PARTICLES_ON_SCREEN; i++ ) - { - if ( i == MAX_PARTICLES_ON_SCREEN - 1 ) - gParticleArray[i].m_pNext = nil; - else - gParticleArray[i].m_pNext = &gParticleArray[i + 1]; - - gParticleArray[i].m_vecPosition = CVector(0.0f, 0.0f, 0.0f); - - gParticleArray[i].m_vecVelocity = CVector(0.0f, 0.0f, 0.0f); - - gParticleArray[i].m_nTimeWhenWillBeDestroyed = 0; - - gParticleArray[i].m_nTimeWhenColorWillBeChanged = 0; - - gParticleArray[i].m_fSize = 0.2f; - - gParticleArray[i].m_fExpansionRate = 0.0f; - - gParticleArray[i].m_nColorIntensity = 255; - - gParticleArray[i].m_nFadeToBlackTimer = 0; - - gParticleArray[i].m_nAlpha = 255; - - gParticleArray[i].m_nFadeAlphaTimer = 0; - - gParticleArray[i].m_nCurrentZRotation = 0; - - gParticleArray[i].m_nZRotationTimer = 0; - - gParticleArray[i].m_fCurrentZRadius = 0.0f; - - gParticleArray[i].m_nZRadiusTimer = 0; - - gParticleArray[i].m_nCurrentFrame = 0; - - gParticleArray[i].m_nAnimationSpeedTimer = 0; - - gParticleArray[i].m_nRotation = 0; - - gParticleArray[i].m_nRotationStep = 0; - } -} - -void CParticle::Initialise() -{ - ReloadConfig(); - - CParticleObject::Initialise(); - - float randVal = -1.0f; - for ( int32 i = 0; i < RAND_TABLE_SIZE; i++ ) - { - ms_afRandTable[i] = randVal; - randVal += 0.1f; - } - - for ( int32 i = 0; i < SIN_COS_TABLE_SIZE; i++ ) - { - float angle = DEGTORAD(float(i) * float(360.0f / SIN_COS_TABLE_SIZE)); - - m_SinTable[i] = ::Sin(angle); - m_CosTable[i] = ::Cos(angle); - } - - int32 slot = CTxdStore::FindTxdSlot("particle"); - - CTxdStore::PushCurrentTxd(); - CTxdStore::SetCurrentTxd(slot); - - for ( int32 i = 0; i < MAX_SMOKE_FILES; i++ ) - { - gpSmokeTex[i] = RwTextureRead(SmokeFiles[i], nil); - gpSmokeRaster[i] = RwTextureGetRaster(gpSmokeTex[i]); - } - - gpSmoke2Tex = RwTextureRead("smokeII_3", nil); - gpSmoke2Raster = RwTextureGetRaster(gpSmoke2Tex); - - for ( int32 i = 0; i < MAX_RUBBER_FILES; i++ ) - { - gpRubberTex[i] = RwTextureRead(RubberFiles[i], nil); - gpRubberRaster[i] = RwTextureGetRaster(gpRubberTex[i]); - } - - for ( int32 i = 0; i < MAX_RAINSPLASH_FILES; i++ ) - { - gpRainSplashTex[i] = RwTextureRead(RainSplashFiles[i], nil); - gpRainSplashRaster[i] = RwTextureGetRaster(gpRainSplashTex[i]); - } - - for ( int32 i = 0; i < MAX_WATERSPRAY_FILES; i++ ) - { - gpWatersprayTex[i] = RwTextureRead(WatersprayFiles[i], nil); - gpWatersprayRaster[i] = RwTextureGetRaster(gpWatersprayTex[i]); - } - - for ( int32 i = 0; i < MAX_EXPLOSIONMEDIUM_FILES; i++ ) - { - gpExplosionMediumTex[i] = RwTextureRead(ExplosionMediumFiles[i], nil); - gpExplosionMediumRaster[i] = RwTextureGetRaster(gpExplosionMediumTex[i]); - } - - for ( int32 i = 0; i < MAX_GUNFLASH_FILES; i++ ) - { - gpGunFlashTex[i] = RwTextureRead(GunFlashFiles[i], nil); - gpGunFlashRaster[i] = RwTextureGetRaster(gpGunFlashTex[i]); - } - - gpRainDropTex = RwTextureRead("raindrop4", nil); - gpRainDropRaster = RwTextureGetRaster(gpRainDropTex); - - - for ( int32 i = 0; i < MAX_RAINSPLASHUP_FILES; i++ ) - { - gpRainSplashupTex[i] = RwTextureRead(RainSplashupFiles[i], nil); - gpRainSplashupRaster[i] = RwTextureGetRaster(gpRainSplashupTex[i]); - } - - for ( int32 i = 0; i < MAX_BIRDFRONT_FILES; i++ ) - { - gpBirdfrontTex[i] = RwTextureRead(BirdfrontFiles[i], nil); - gpBirdfrontRaster[i] = RwTextureGetRaster(gpBirdfrontTex[i]); - } - - for ( int32 i = 0; i < MAX_BOAT_FILES; i++ ) - { - gpBoatTex[i] = RwTextureRead(BoatFiles[i], nil); - gpBoatRaster[i] = RwTextureGetRaster(gpBoatTex[i]); - } - - for ( int32 i = 0; i < MAX_CARDEBRIS_FILES; i++ ) - { - gpCarDebrisTex[i] = RwTextureRead(CardebrisFiles[i], nil); - gpCarDebrisRaster[i] = RwTextureGetRaster(gpCarDebrisTex[i]); - } - - for ( int32 i = 0; i < MAX_CARSPLASH_FILES; i++ ) - { - gpCarSplashTex[i] = RwTextureRead(CarsplashFiles[i], nil); - gpCarSplashRaster[i] = RwTextureGetRaster(gpCarSplashTex[i]); - } - - gpBoatWakeTex = RwTextureRead("boatwake2", nil); - gpBoatWakeRaster = RwTextureGetRaster(gpBoatWakeTex); - - gpFlame1Tex = RwTextureRead("flame1", nil); - gpFlame1Raster = RwTextureGetRaster(gpFlame1Tex); - - gpFlame5Tex = RwTextureRead("flame5", nil); - -//#ifdef FIX_BUGS -#if 0 - gpFlame5Raster = RwTextureGetRaster(gpFlame5Tex); -#else - // this seems to have become more of a design choice - gpFlame5Raster = RwTextureGetRaster(gpFlame1Tex); // copy-paste bug ? -#endif - - gpRainDropSmallTex = RwTextureRead("rainsmall", nil); - gpRainDropSmallRaster = RwTextureGetRaster(gpRainDropSmallTex); - - gpBloodTex = RwTextureRead("blood", nil); - gpBloodRaster = RwTextureGetRaster(gpBloodTex); - - gpLeafTex[0] = RwTextureRead("gameleaf01_64", nil); - gpLeafRaster[0] = RwTextureGetRaster(gpLeafTex[0]); - - gpLeafTex[1] = RwTextureRead("letter", nil); - gpLeafRaster[1] = RwTextureGetRaster(gpLeafTex[1]); - - gpCloudTex1 = RwTextureRead("cloud3", nil); - gpCloudRaster1 = RwTextureGetRaster(gpCloudTex1); - - gpCloudTex4 = RwTextureRead("cloudmasked", nil); - gpCloudRaster4 = RwTextureGetRaster(gpCloudTex4); - - gpBloodSmallTex = RwTextureRead("bloodsplat2", nil); - gpBloodSmallRaster = RwTextureGetRaster(gpBloodSmallTex); - - gpGungeTex = RwTextureRead("gunge", nil); - gpGungeRaster = RwTextureGetRaster(gpGungeTex); - - gpCollisionSmokeTex = RwTextureRead("collisionsmoke", nil); - gpCollisionSmokeRaster = RwTextureGetRaster(gpCollisionSmokeTex); - - gpBulletHitTex = RwTextureRead("bullethitsmoke", nil); - gpBulletHitRaster = RwTextureGetRaster(gpBulletHitTex); - - gpGunShellTex = RwTextureRead("gunshell", nil); - gpGunShellRaster = RwTextureGetRaster(gpGunShellTex); - - gpPointlightTex = RwTextureRead("pointlight", nil); - gpPointlightRaster = RwTextureGetRaster(gpPointlightTex); - - gpSparkTex = RwTextureRead("spark", nil); - gpSparkRaster = RwTextureGetRaster(gpSparkTex); - - gpNewspaperTex = RwTextureRead("newspaper02_64", nil); - gpNewspaperRaster = RwTextureGetRaster(gpNewspaperTex); - - gpGunSmokeTex = RwTextureRead("gunsmoke3", nil); - gpGunSmokeRaster = RwTextureGetRaster(gpGunSmokeTex); - - gpDotTex = RwTextureRead("dot", nil); - gpDotRaster = RwTextureGetRaster(gpDotTex); - - gpHeatHazeTex = RwTextureRead("heathaze", nil); - gpHeatHazeRaster = RwTextureGetRaster(gpHeatHazeTex); - - gpBeastieTex = RwTextureRead("beastie", nil); - gpBeastieRaster = RwTextureGetRaster(gpBeastieTex); - - gpRainDripTex[0] = RwTextureRead("raindrip64", nil); - gpRainDripRaster[0] = RwTextureGetRaster(gpRainDripTex[0]); - - gpRainDripTex[1] = RwTextureRead("raindripb64", nil); - gpRainDripRaster[1] = RwTextureGetRaster(gpRainDripTex[1]); - - gpRainDripDarkTex[0] = RwTextureRead("raindrip64_d", nil); - gpRainDripDarkRaster[0] = RwTextureGetRaster(gpRainDripDarkTex[0]); - - gpRainDripDarkTex[1] = RwTextureRead("raindripb64_d", nil); - gpRainDripDarkRaster[1] = RwTextureGetRaster(gpRainDripDarkTex[1]); - - CTxdStore::PopCurrentTxd(); - - for ( int32 i = 0; i < MAX_PARTICLES; i++ ) - { - tParticleSystemData *entry = &mod_ParticleSystemManager.m_aParticles[i]; - - switch ( i ) - { - case PARTICLE_SPARK: - case PARTICLE_SPARK_SMALL: - case PARTICLE_RAINDROP_SMALL: - case PARTICLE_HELI_ATTACK: - entry->m_ppRaster = &gpRainDropSmallRaster; - break; - - case PARTICLE_WATER_SPARK: - entry->m_ppRaster = &gpSparkRaster; - break; - - case PARTICLE_WHEEL_DIRT: - case PARTICLE_SAND: - case PARTICLE_STEAM2: - case PARTICLE_STEAM_NY: - case PARTICLE_STEAM_NY_SLOWMOTION: - case PARTICLE_GROUND_STEAM: - case PARTICLE_ENGINE_STEAM: - case PARTICLE_PEDFOOT_DUST: - case PARTICLE_CAR_DUST: - case PARTICLE_EXHAUST_FUMES: - entry->m_ppRaster = &gpSmoke2Raster; - break; - - case PARTICLE_WHEEL_WATER: - case PARTICLE_WATER: - case PARTICLE_SMOKE: - case PARTICLE_SMOKE_SLOWMOTION: - case PARTICLE_DRY_ICE: - case PARTICLE_GARAGEPAINT_SPRAY: - case PARTICLE_STEAM: - case PARTICLE_WATER_CANNON: - case PARTICLE_EXTINGUISH_STEAM: - case PARTICLE_HELI_DUST: - case PARTICLE_PAINT_SMOKE: - case PARTICLE_BULLETHIT_SMOKE: - entry->m_ppRaster = gpSmokeRaster; - break; - - case PARTICLE_BLOOD: - entry->m_ppRaster = &gpBloodRaster; - break; - - case PARTICLE_BLOOD_SMALL: - case PARTICLE_BLOOD_SPURT: - entry->m_ppRaster = &gpBloodSmallRaster; - break; - - case PARTICLE_DEBRIS: - case PARTICLE_TREE_LEAVES: - entry->m_ppRaster = gpLeafRaster; - break; - - case PARTICLE_DEBRIS2: - entry->m_ppRaster = &gpGungeRaster; - break; - - case PARTICLE_FLYERS: - entry->m_ppRaster = &gpNewspaperRaster; - break; - - case PARTICLE_FLAME: - case PARTICLE_CARFLAME: - entry->m_ppRaster = &gpFlame1Raster; - break; - - case PARTICLE_FIREBALL: - entry->m_ppRaster = &gpFlame5Raster; - break; - - case PARTICLE_GUNFLASH: - case PARTICLE_GUNFLASH_NOANIM: - entry->m_ppRaster = gpGunFlashRaster; - break; - - - case PARTICLE_GUNSMOKE: - case PARTICLE_WATERDROP: - case PARTICLE_BLOODDROP: - case PARTICLE_HEATHAZE: - case PARTICLE_HEATHAZE_IN_DIST: - entry->m_ppRaster = nil; - break; - - case PARTICLE_GUNSMOKE2: - case PARTICLE_BOAT_THRUSTJET: - case PARTICLE_RUBBER_SMOKE: - entry->m_ppRaster = gpRubberRaster; - break; - - case PARTICLE_CIGARETTE_SMOKE: - entry->m_ppRaster = &gpGunSmokeRaster; - break; - - case PARTICLE_TEARGAS: - entry->m_ppRaster = &gpHeatHazeRaster; - break; - - case PARTICLE_SHARD: - case PARTICLE_RAINDROP: - case PARTICLE_RAINDROP_2D: - entry->m_ppRaster = &gpRainDropRaster; - break; - - case PARTICLE_SPLASH: - case PARTICLE_PED_SPLASH: - case PARTICLE_CAR_SPLASH: - case PARTICLE_WATER_HYDRANT: - entry->m_ppRaster = gpCarSplashRaster; - break; - - case PARTICLE_RAIN_SPLASH: - case PARTICLE_RAIN_SPLASH_BIGGROW: - entry->m_ppRaster = gpRainSplashRaster; - break; - - case PARTICLE_RAIN_SPLASHUP: - entry->m_ppRaster = gpRainSplashupRaster; - break; - - case PARTICLE_WATERSPRAY: - entry->m_ppRaster = gpWatersprayRaster; - break; - - case PARTICLE_EXPLOSION_MEDIUM: - case PARTICLE_EXPLOSION_LARGE: - case PARTICLE_EXPLOSION_MFAST: - case PARTICLE_EXPLOSION_LFAST: - entry->m_ppRaster = gpExplosionMediumRaster; - break; - - case PARTICLE_BOAT_SPLASH: - entry->m_ppRaster = &gpBoatWakeRaster; - break; - - case PARTICLE_ENGINE_SMOKE: - case PARTICLE_ENGINE_SMOKE2: - case PARTICLE_CARFLAME_SMOKE: - case PARTICLE_FIREBALL_SMOKE: - case PARTICLE_ROCKET_SMOKE: - case PARTICLE_TEST: - entry->m_ppRaster = &gpCloudRaster4; - break; - - case PARTICLE_CARCOLLISION_DUST: - case PARTICLE_BURNINGRUBBER_SMOKE: - entry->m_ppRaster = &gpCollisionSmokeRaster; - break; - - case PARTICLE_CAR_DEBRIS: - case PARTICLE_HELI_DEBRIS: - case PARTICLE_BIRD_DEBRIS: - entry->m_ppRaster = gpCarDebrisRaster; - break; - - case PARTICLE_GUNSHELL_FIRST: - case PARTICLE_GUNSHELL: - case PARTICLE_GUNSHELL_BUMP1: - case PARTICLE_GUNSHELL_BUMP2: - entry->m_ppRaster = &gpGunShellRaster; - break; - - - case PARTICLE_BIRD_FRONT: - entry->m_ppRaster = gpBirdfrontRaster; - break; - - case PARTICLE_SHIP_SIDE: - entry->m_ppRaster = gpBoatRaster; - break; - - case PARTICLE_BEASTIE: - entry->m_ppRaster = &gpBeastieRaster; - break; - } - } - - debug("CParticle ready"); -} - -void CParticle::Shutdown() -{ - debug("Shutting down CParticle..."); - - for ( int32 i = 0; i < MAX_SMOKE_FILES; i++ ) - { - RwTextureDestroy(gpSmokeTex[i]); - gpSmokeTex[i] = nil; - } - - RwTextureDestroy(gpSmoke2Tex); - gpSmoke2Tex = nil; - - for ( int32 i = 0; i < MAX_RUBBER_FILES; i++ ) - { - RwTextureDestroy(gpRubberTex[i]); - gpRubberTex[i] = nil; - } - - for ( int32 i = 0; i < MAX_RAINSPLASH_FILES; i++ ) - { - RwTextureDestroy(gpRainSplashTex[i]); - gpRainSplashTex[i] = nil; - } - - for ( int32 i = 0; i < MAX_WATERSPRAY_FILES; i++ ) - { - RwTextureDestroy(gpWatersprayTex[i]); - gpWatersprayTex[i] = nil; - } - - for ( int32 i = 0; i < MAX_EXPLOSIONMEDIUM_FILES; i++ ) - { - RwTextureDestroy(gpExplosionMediumTex[i]); - gpExplosionMediumTex[i] = nil; - } - - for ( int32 i = 0; i < MAX_GUNFLASH_FILES; i++ ) - { - RwTextureDestroy(gpGunFlashTex[i]); - gpGunFlashTex[i] = nil; - } - - RwTextureDestroy(gpRainDropTex); - gpRainDropTex = nil; - - for ( int32 i = 0; i < MAX_RAINSPLASHUP_FILES; i++ ) - { - RwTextureDestroy(gpRainSplashupTex[i]); - gpRainSplashupTex[i] = nil; - } - - for ( int32 i = 0; i < MAX_BIRDFRONT_FILES; i++ ) - { - RwTextureDestroy(gpBirdfrontTex[i]); - gpBirdfrontTex[i] = nil; - } - - for ( int32 i = 0; i < MAX_BOAT_FILES; i++ ) - { - RwTextureDestroy(gpBoatTex[i]); - gpBoatTex[i] = nil; - } - - for ( int32 i = 0; i < MAX_CARDEBRIS_FILES; i++ ) - { - RwTextureDestroy(gpCarDebrisTex[i]); - gpCarDebrisTex[i] = nil; - } - - for ( int32 i = 0; i < MAX_CARSPLASH_FILES; i++ ) - { - RwTextureDestroy(gpCarSplashTex[i]); - gpCarSplashTex[i] = nil; - } - - for ( int32 i = 0; i < MAX_RAINDRIP_FILES; i++ ) - { - RwTextureDestroy(gpRainDripTex[i]); - gpRainDripTex[i] = nil; - - RwTextureDestroy(gpRainDripDarkTex[i]); - gpRainDripDarkTex[i] = nil; - } - - RwTextureDestroy(gpBoatWakeTex); - gpBoatWakeTex = nil; - - RwTextureDestroy(gpFlame1Tex); - gpFlame1Tex = nil; - - RwTextureDestroy(gpFlame5Tex); - gpFlame5Tex = nil; - - RwTextureDestroy(gpRainDropSmallTex); - gpRainDropSmallTex = nil; - - RwTextureDestroy(gpBloodTex); - gpBloodTex = nil; - - RwTextureDestroy(gpLeafTex[0]); - gpLeafTex[0] = nil; - - RwTextureDestroy(gpLeafTex[1]); - gpLeafTex[1] = nil; - - RwTextureDestroy(gpCloudTex1); - gpCloudTex1 = nil; - - RwTextureDestroy(gpCloudTex4); - gpCloudTex4 = nil; - - RwTextureDestroy(gpBloodSmallTex); - gpBloodSmallTex = nil; - - RwTextureDestroy(gpGungeTex); - gpGungeTex = nil; - - RwTextureDestroy(gpCollisionSmokeTex); - gpCollisionSmokeTex = nil; - - RwTextureDestroy(gpBulletHitTex); - gpBulletHitTex = nil; - - RwTextureDestroy(gpGunShellTex); - gpGunShellTex = nil; - - RwTextureDestroy(gpPointlightTex); - gpPointlightTex = nil; - - RwTextureDestroy(gpSparkTex); - gpSparkTex = nil; - - RwTextureDestroy(gpNewspaperTex); - gpNewspaperTex = nil; - - RwTextureDestroy(gpGunSmokeTex); - gpGunSmokeTex = nil; - - RwTextureDestroy(gpDotTex); - gpDotTex = nil; - RwTextureDestroy(gpHeatHazeTex); - gpHeatHazeTex = nil; - - RwTextureDestroy(gpBeastieTex); - gpBeastieTex = nil; - - int32 slot; - - slot = CTxdStore::FindTxdSlot("particle"); - CTxdStore::RemoveTxdSlot(slot); - - debug("CParticle shut down"); -} - - -void CParticle::AddParticlesAlongLine(tParticleType type, CVector const &vecStart, CVector const &vecEnd, CVector const &vecDir, float fPower, CEntity *pEntity, float fSize, int32 nRotationSpeed, int32 nRotation, int32 nCurFrame, int32 nLifeSpan) -{ - CVector vecDist = vecEnd - vecStart; - float fDist = vecDist.Magnitude(); - float fSteps = Max(fDist / fPower, 1.0f); - int32 nSteps = (int32)fSteps; - - CVector vecStep = vecDist * (1.0f / (float)nSteps); - - for ( int32 i = 0; i < nSteps; i++ ) - { - CVector vecPos = float(i) * vecStep + vecStart; - AddParticle(type, vecPos, vecDir, pEntity, fSize, nRotationSpeed, nRotation, nCurFrame, nLifeSpan); - } -} - -void CParticle::AddParticlesAlongLine(tParticleType type, CVector const &vecStart, CVector const &vecEnd, CVector const &vecDir, float fPower, CEntity *pEntity, float fSize, RwRGBA const &color, int32 nRotationSpeed, int32 nRotation, int32 nCurFrame, int32 nLifeSpan) -{ - CVector vecDist = vecEnd - vecStart; - float fDist = vecDist.Magnitude(); - float fSteps = Max(fDist / fPower, 1.0f); - int32 nSteps = (int32)fSteps; - - CVector vecStep = vecDist * (1.0f / (float)nSteps); - - for ( int32 i = 0; i < nSteps; i++ ) - { - CVector vecPos = float(i) * vecStep + vecStart; - - AddParticle(type, vecPos, vecDir, pEntity, fSize, color, nRotationSpeed, nRotation, nCurFrame, nLifeSpan); - } -} - -CParticle *CParticle::AddParticle(tParticleType type, CVector const &vecPos, CVector const &vecDir, CEntity *pEntity, float fSize, int32 nRotationSpeed, int32 nRotation, int32 nCurFrame, int32 nLifeSpan) -{ - CRGBA color(0, 0, 0, 0); - return AddParticle(type, vecPos, vecDir, pEntity, fSize, color, nRotationSpeed, nRotation, nCurFrame, nLifeSpan); -} - -CParticle *CParticle::AddParticle(tParticleType type, CVector const &vecPos, CVector const &vecDir, CEntity *pEntity, float fSize, RwRGBA const &color, int32 nRotationSpeed, int32 nRotation, int32 nCurFrame, int32 nLifeSpan) -{ - if ( CTimer::GetIsPaused() ) - return nil; - - if ( ( type == PARTICLE_ENGINE_SMOKE - || type == PARTICLE_ENGINE_SMOKE2 - || type == PARTICLE_ENGINE_STEAM - || type == PARTICLE_CARFLAME_SMOKE - || type == PARTICLE_RUBBER_SMOKE - || type == PARTICLE_BURNINGRUBBER_SMOKE - || type == PARTICLE_EXHAUST_FUMES - || type == PARTICLE_CARCOLLISION_DUST ) - && nParticleCreationInterval & CTimer::GetFrameCounter() ) - { - return nil; - } - - if ( !CReplay::IsPlayingBack() ) - CReplay::RecordParticle(type, vecPos, vecDir, fSize, color); - - CParticle *pParticle = m_pUnusedListHead; - - if ( pParticle == nil ) - return nil; - - tParticleSystemData *psystem = &mod_ParticleSystemManager.m_aParticles[type]; - - if ( psystem->m_fCreateRange != 0.0f && psystem->m_fCreateRange < ( TheCamera.GetPosition() - vecPos ).MagnitudeSqr() ) - return nil; - - - pParticle->m_fSize = psystem->m_fDefaultInitialRadius; - pParticle->m_fExpansionRate = psystem->m_fExpansionRate; - - if ( nLifeSpan != 0 ) - pParticle->m_nTimeWhenWillBeDestroyed = CTimer::GetTimeInMilliseconds() + nLifeSpan; - else - pParticle->m_nTimeWhenWillBeDestroyed = CTimer::GetTimeInMilliseconds() + psystem->m_nLifeSpan; - - pParticle->m_nColorIntensity = psystem->m_nFadeToBlackInitialIntensity; - - pParticle->m_nFadeToBlackTimer = psystem->m_nFadeToBlackAmount; - - if ( psystem->m_nFadeToBlackTime ) - pParticle->m_nFadeToBlackTimer /= psystem->m_nFadeToBlackTime; - - pParticle->m_nAlpha = psystem->m_nFadeAlphaInitialIntensity; - - pParticle->m_nFadeAlphaTimer = psystem->m_nFadeAlphaAmount; - - if ( psystem->m_nFadeAlphaTime ) - pParticle->m_nFadeAlphaTimer /= psystem->m_nFadeAlphaTime; - - pParticle->m_nCurrentZRotation = psystem->m_nZRotationInitialAngle; - pParticle->m_fCurrentZRadius = psystem->m_fInitialZRadius; - - if ( nCurFrame != 0 ) - pParticle->m_nCurrentFrame = nCurFrame; - else - pParticle->m_nCurrentFrame = psystem->m_nStartAnimationFrame; - - - pParticle->m_nZRotationTimer = 0; - pParticle->m_nZRadiusTimer = 0; - pParticle->m_nAnimationSpeedTimer = 0; - pParticle->m_fZGround = 0.0f; - - if ( type != PARTICLE_HEATHAZE ) - pParticle->m_vecPosition = vecPos; - else - { - CVector screen; - float w, h; - - if ( !CSprite::CalcScreenCoors(vecPos, &screen, &w, &h, true) ) - return nil; - - pParticle->m_vecPosition = screen; - psystem->m_vecTextureStretch.x = w; - psystem->m_vecTextureStretch.y = h; - } - - pParticle->m_vecVelocity = vecDir; - - pParticle->m_vecParticleMovementOffset = CVector(0.0f, 0.0f, 0.0f); - pParticle->m_nTimeWhenColorWillBeChanged = 0; - - if ( color.alpha != 0 ) - RwRGBAAssign(&pParticle->m_Color, &color); - else - { - RwRGBAAssign(&pParticle->m_Color, psystem->m_RenderColouring); - - if ( psystem->m_ColorFadeTime != 0 ) - pParticle->m_nTimeWhenColorWillBeChanged = CTimer::GetTimeInMilliseconds() + psystem->m_ColorFadeTime; - - if ( psystem->m_InitialColorVariation != 0 ) - { - int32 ColorVariation = CGeneral::GetRandomNumberInRange(-psystem->m_InitialColorVariation, psystem->m_InitialColorVariation); - //float ColorVariation = CGeneral::GetRandomNumberInRange((float)-psystem->m_InitialColorVariation, (float)psystem->m_InitialColorVariation); - - pParticle->m_Color.red = Clamp(pParticle->m_Color.red + - PERCENT(pParticle->m_Color.red, ColorVariation), - 0, 255); - - pParticle->m_Color.green = Clamp(pParticle->m_Color.green + - PERCENT(pParticle->m_Color.green, ColorVariation), - 0, 255); - - pParticle->m_Color.blue = Clamp(pParticle->m_Color.blue + - PERCENT(pParticle->m_Color.blue, ColorVariation), - 0, 255); - } - } - - pParticle->m_nRotation = nRotation; - - if ( nRotationSpeed != 0 ) - pParticle->m_nRotationStep = nRotationSpeed; - else - pParticle->m_nRotationStep = psystem->m_nRotationSpeed; - - if ( CGeneral::GetRandomNumber() & 1 ) - pParticle->m_nRotationStep = -pParticle->m_nRotationStep; - - if ( psystem->m_fPositionRandomError != 0.0f ) - { - pParticle->m_vecPosition.x += psystem->m_fPositionRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; - pParticle->m_vecPosition.y += psystem->m_fPositionRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; - - if ( psystem->Flags & RAND_VERT_V ) - pParticle->m_vecPosition.z += psystem->m_fPositionRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; - } - - if ( psystem->m_fVelocityRandomError != 0.0f ) - { - pParticle->m_vecVelocity.x += psystem->m_fVelocityRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; - pParticle->m_vecVelocity.y += psystem->m_fVelocityRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; - - if ( psystem->Flags & RAND_VERT_V ) - pParticle->m_vecVelocity.z += psystem->m_fVelocityRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; - } - - if ( psystem->m_fExpansionRateError != 0.0f && !(psystem->Flags & SCREEN_TRAIL) ) - pParticle->m_fExpansionRate += psystem->m_fExpansionRateError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE] + psystem->m_fExpansionRateError; - - if ( psystem->m_nRotationRateError != 0 ) - pParticle->m_nRotationStep += CGeneral::GetRandomNumberInRange(-psystem->m_nRotationRateError, psystem->m_nRotationRateError); - - if ( psystem->m_nLifeSpanErrorShape != 0 ) - { - float randVal = ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; - if ( randVal > 0.0f ) - pParticle->m_nTimeWhenWillBeDestroyed += int32(float(psystem->m_nLifeSpan) * randVal * float(psystem->m_nLifeSpanErrorShape)); - else - pParticle->m_nTimeWhenWillBeDestroyed += int32(float(psystem->m_nLifeSpan) * randVal / float(psystem->m_nLifeSpanErrorShape)); - } - - if ( psystem->Flags & ZCHECK_FIRST ) - { - static bool bValidGroundFound = false; - static CVector LastTestCoors; - static float LastTestGroundZ; - - if ( bValidGroundFound - && vecPos.x == LastTestCoors.x - && vecPos.y == LastTestCoors.y - && vecPos.z == LastTestCoors.z ) - { - pParticle->m_fZGround = LastTestGroundZ; - } - else - { - bValidGroundFound = false; - - CColPoint point; - CEntity *entity; - - if ( !CWorld::ProcessVerticalLine( - pParticle->m_vecPosition + CVector(0.0f, 0.0f, 0.5f), - -100.0f, point, entity, true, true, false, false, true, false, nil) ) - { - return nil; - } - - if ( point.point.z >= pParticle->m_vecPosition.z ) - return nil; - - pParticle->m_fZGround = point.point.z; - bValidGroundFound = true; - LastTestCoors = vecPos; - LastTestGroundZ = point.point.z; - } - } - - if ( psystem->Flags & ZCHECK_BUMP ) - { - static float Z_Ground = 0.0f; - - if ( psystem->Flags & ZCHECK_BUMP_FIRST ) - { - bool bZFound = false; - - Z_Ground = CWorld::FindGroundZFor3DCoord(vecPos.x, vecPos.y, vecPos.z, (bool *)&bZFound); - - if ( bZFound == false ) - return nil; - - pParticle->m_fZGround = Z_Ground; - } - - pParticle->m_fZGround = Z_Ground; - } - - switch ( type ) - { - case PARTICLE_DEBRIS: - pParticle->m_vecVelocity.z *= CGeneral::GetRandomNumberInRange(0.5f, 3.0f); - break; - - case PARTICLE_EXPLOSION_MEDIUM: - pParticle->m_nColorIntensity -= 30 * (CGeneral::GetRandomNumber() & 1); // mb "+= -30 * rand" here ? - pParticle->m_nAnimationSpeedTimer = CGeneral::GetRandomNumber() & 7; - pParticle->m_fSize = CGeneral::GetRandomNumberInRange(0.3f, 0.8f); - pParticle->m_vecPosition.z -= CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); - break; - - case PARTICLE_EXPLOSION_LARGE: - pParticle->m_nColorIntensity -= 30 * (CGeneral::GetRandomNumber() & 1); // mb "+= -30 * rand" here ? - pParticle->m_nAnimationSpeedTimer = CGeneral::GetRandomNumber() & 7; - pParticle->m_fSize = CGeneral::GetRandomNumberInRange(0.8f, 1.4f); - pParticle->m_vecPosition.z -= CGeneral::GetRandomNumberInRange(-0.3f, 0.3f); - break; - - case PARTICLE_WATER_HYDRANT: - pParticle->m_vecPosition.z += 20.0f * psystem->m_fPositionRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; - break; - default: break; - } - - if ( fSize != 0.0f ) - pParticle->m_fSize = fSize; - - m_pUnusedListHead = pParticle->m_pNext; - - pParticle->m_pNext = psystem->m_pParticles; - - psystem->m_pParticles = pParticle; - - return pParticle; -} - -void CParticle::Update() -{ - if ( CTimer::GetIsPaused() ) - return; - - CRGBA color(0, 0, 0, 0); - - float fFricDeccel50 = pow(0.50f, CTimer::GetTimeStep()); - float fFricDeccel80 = pow(0.80f, CTimer::GetTimeStep()); - float fFricDeccel90 = pow(0.90f, CTimer::GetTimeStep()); - float fFricDeccel95 = pow(0.95f, CTimer::GetTimeStep()); - float fFricDeccel96 = pow(0.96f, CTimer::GetTimeStep()); - float fFricDeccel99 = pow(0.99f, CTimer::GetTimeStep()); - - CParticleObject::UpdateAll(); - - // ejaculation at 23:00, 23:15, 23:30, 23:45 - if ( CClock::ms_nGameClockHours == 23 && - ( CClock::ms_nGameClockMinutes == 0 - || CClock::ms_nGameClockMinutes == 15 - || CClock::ms_nGameClockMinutes == 30 - || CClock::ms_nGameClockMinutes == 45 ) ) - { - AddParticle(PARTICLE_CAR_SPLASH, - CVector(557.03f, -4.0f, 151.46f), - CVector(0.0f, 0.0f, 2.5f), - NULL, - 2.0f, - CRGBA(255, 255, 255, 255), - 0, - 0, - 1, - 1000); - } - - for ( int32 i = 0; i < MAX_PARTICLES; i++ ) - { - tParticleSystemData *psystem = &mod_ParticleSystemManager.m_aParticles[i]; - CParticle *particle = psystem->m_pParticles; - CParticle *prevParticle = nil; - bool bRemoveParticle; - - if ( particle == nil ) - continue; - - for ( ; particle != nil; _Next(particle, prevParticle, psystem, bRemoveParticle) ) - { - CVector vecWind(0.0f, 0.0f, 0.0f); - - bRemoveParticle = false; - - CVector vecMoveStep = particle->m_vecVelocity * CTimer::GetTimeStep(); - CVector vecPos = particle->m_vecPosition; - - if ( numWaterDropOnScreen == 0 ) - clearWaterDrop = false; - - if ( psystem->m_Type == PARTICLE_WATERDROP ) - { - if ( CGame::IsInInterior() || clearWaterDrop == true ) - { - bRemoveParticle = true; - continue; - } - - static uint8 nWaterDropCount; - - if ( nWaterDropCount == 5 ) - { - vecMoveStep = CVector(0.0f, 0.0f, 0.0f); - particle->m_nTimeWhenWillBeDestroyed += 1250; - nWaterDropCount = 0; - } - else - { - if ( TheCamera.m_CameraAverageSpeed > 0.35f ) - { - if ( vecMoveStep.Magnitude() > 0.5f ) - { - if ( vecMoveStep.Magnitude() > 0.4f && vecMoveStep.Magnitude() < 0.8f ) - { - vecMoveStep.x += TheCamera.m_CameraAverageSpeed * 1.5f; - vecMoveStep.y += TheCamera.m_CameraAverageSpeed * 1.5f; - } - else if ( vecMoveStep.Magnitude() != 0.0f ) - { - vecMoveStep.x += CGeneral::GetRandomNumberInRange(0.01f, 0.05f); - vecMoveStep.y += CGeneral::GetRandomNumberInRange(0.01f, 0.05f); - } - } - } - - nWaterDropCount++; - } - - if ( vecPos.z <= 1.5f ) - vecMoveStep.z = 0.0f; - } - - if ( psystem->m_Type == PARTICLE_HEATHAZE || psystem->m_Type == PARTICLE_HEATHAZE_IN_DIST ) - { -#ifdef FIX_BUGS - int32 nSinCosIndex = (int32(DEGTORAD((float)particle->m_nRotation) * float(SIN_COS_TABLE_SIZE) / TWOPI) + SIN_COS_TABLE_SIZE) % SIN_COS_TABLE_SIZE; -#else - int32 nSinCosIndex = int32(DEGTORAD((float)particle->m_nRotation) * float(SIN_COS_TABLE_SIZE) / TWOPI) % SIN_COS_TABLE_SIZE; -#endif - vecMoveStep.x = Sin(nSinCosIndex); - vecMoveStep.y = Sin(nSinCosIndex); - - if ( psystem->m_Type == PARTICLE_HEATHAZE_IN_DIST ) - particle->m_nRotation = int16((float)particle->m_nRotation + 0.75f); - else - particle->m_nRotation = int16((float)particle->m_nRotation + 1.0f); - } - - if ( psystem->m_Type == PARTICLE_BEASTIE ) - { -#ifdef FIX_BUGS - int32 nSinCosIndex = (int32(DEGTORAD((float)particle->m_nRotation) * float(SIN_COS_TABLE_SIZE) / TWOPI) + SIN_COS_TABLE_SIZE) % SIN_COS_TABLE_SIZE; -#else - int32 nSinCosIndex = int32(DEGTORAD((float)particle->m_nRotation) * float(SIN_COS_TABLE_SIZE) / TWOPI) % SIN_COS_TABLE_SIZE; -#endif - particle->m_vecVelocity.x = 0.50f * Cos(nSinCosIndex); - particle->m_vecVelocity.y = Cos(nSinCosIndex); - particle->m_vecVelocity.z = 0.25f * Sin(nSinCosIndex); - - if ( particle->m_vecVelocity.Magnitude() > 2.0f - || vecPos.z > 40.0f - || (TheCamera.GetPosition() - vecPos).Magnitude() < 60.0f - ) - { - bRemoveParticle = true; - continue; - } - } - - vecPos += vecMoveStep; - - if ( psystem->m_Type == PARTICLE_FIREBALL ) - { - AddParticle(PARTICLE_HEATHAZE, particle->m_vecPosition, CVector(0.0f, 0.0f, 0.0f), - nil, particle->m_fSize * 5.0f); - } - - if ( psystem->m_Type == PARTICLE_GUNSMOKE2 ) - { - if ( CTimer::GetFrameCounter() & 10 ) - { -#ifdef FIX_BUGS - if ( FindPlayerPed() && FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN ) -#else - if ( FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN ) -#endif - { - AddParticle(PARTICLE_HEATHAZE, particle->m_vecPosition, CVector(0.0f, 0.0f, 0.0f)); - } - } - } - - if ( CWeather::Wind > 0.0f ) - { - if ( vecMoveStep.Magnitude() != 0.0f ) - { - vecWind.x = CGeneral::GetRandomNumberInRange(0.75f, 1.25f) * -CWeather::Wind; - vecWind.y = CGeneral::GetRandomNumberInRange(0.75f, 1.25f) * -CWeather::Wind; - vecWind *= PARTICLE_WIND_TEST_SCALE * psystem->m_fWindFactor * CTimer::GetTimeStep(); - particle->m_vecVelocity += vecWind; - } - } - - if ( psystem->m_Type == PARTICLE_RAINDROP - || psystem->m_Type == PARTICLE_RAINDROP_SMALL - || psystem->m_Type == PARTICLE_RAIN_SPLASH - || psystem->m_Type == PARTICLE_RAIN_SPLASH_BIGGROW - || psystem->m_Type == PARTICLE_CAR_SPLASH - || psystem->m_Type == PARTICLE_BOAT_SPLASH - || psystem->m_Type == PARTICLE_RAINDROP_2D ) - { - int32 nMaxDrops = int32(6.0f * TheCamera.m_CameraAverageSpeed + 1.0f); - float fDistToCam = 0.0f; - - if ( psystem->m_Type == PARTICLE_BOAT_SPLASH || psystem->m_Type == PARTICLE_CAR_SPLASH ) - { - if ( vecPos.z + particle->m_fSize < 5.0f ) - { - bRemoveParticle = true; - continue; - } - - switch ( TheCamera.GetLookDirection() ) - { - case LOOKING_LEFT: - case LOOKING_RIGHT: - case LOOKING_FORWARD: - nMaxDrops /= 2; - break; - - default: - nMaxDrops = 0; - break; - } - - fDistToCam = (TheCamera.GetPosition() - vecPos).Magnitude(); - } - - if ( numWaterDropOnScreen < nMaxDrops && numWaterDropOnScreen < 63 - && fDistToCam < 10.0f - && clearWaterDrop == false - && !CGame::IsInInterior() ) - { - CVector vecWaterdropTarget - ( - CGeneral::GetRandomNumberInRange(-0.25f, 0.25f), - CGeneral::GetRandomNumberInRange(0.1f, 0.75f), - -0.01f - ); - - CVector vecWaterdropPos; - - if ( TheCamera.m_CameraAverageSpeed < 0.35f ) - vecWaterdropPos.x = (float)CGeneral::GetRandomNumberInRange(50, int32(SCREEN_WIDTH) - 50); - else - vecWaterdropPos.x = (float)CGeneral::GetRandomNumberInRange(200, int32(SCREEN_WIDTH) - 200); - - if ( psystem->m_Type == PARTICLE_BOAT_SPLASH || psystem->m_Type == PARTICLE_CAR_SPLASH ) - vecWaterdropPos.y = (float)CGeneral::GetRandomNumberInRange(SCREEN_HEIGHT / 2, SCREEN_HEIGHT); - else - { - if ( TheCamera.m_CameraAverageSpeed < 0.35f ) - vecWaterdropPos.y = (float)CGeneral::GetRandomNumberInRange(0, int32(SCREEN_HEIGHT)); - else - vecWaterdropPos.y = (float)CGeneral::GetRandomNumberInRange(150, int32(SCREEN_HEIGHT) - 200); - } - - vecWaterdropPos.z = 2.0f; - - if ( AddParticle(PARTICLE_WATERDROP, - vecWaterdropPos, - vecWaterdropTarget, - nil, - CGeneral::GetRandomNumberInRange(0.1f, 0.15f), - 0, - 0, - CGeneral::GetRandomNumber() & 1, - 0) != nil ) - { - numWaterDropOnScreen++; - } - } - } - - if ( CTimer::GetTimeInMilliseconds() > particle->m_nTimeWhenWillBeDestroyed || particle->m_nAlpha == 0 ) - { - bRemoveParticle = true; - continue; - } - - if ( particle->m_nTimeWhenColorWillBeChanged != 0 ) - { - if ( particle->m_nTimeWhenColorWillBeChanged > CTimer::GetTimeInMilliseconds() ) - { - float colorMul = 1.0f - float(particle->m_nTimeWhenColorWillBeChanged - CTimer::GetTimeInMilliseconds()) / float(psystem->m_ColorFadeTime); - - particle->m_Color.red = Clamp( - psystem->m_RenderColouring.red + int32(float(psystem->m_FadeDestinationColor.red - psystem->m_RenderColouring.red) * colorMul), - 0, 255); - - particle->m_Color.green = Clamp( - psystem->m_RenderColouring.green + int32(float(psystem->m_FadeDestinationColor.green - psystem->m_RenderColouring.green) * colorMul), - 0, 255); - - particle->m_Color.blue = Clamp( - psystem->m_RenderColouring.blue + int32(float(psystem->m_FadeDestinationColor.blue - psystem->m_RenderColouring.blue) * colorMul), - 0, 255); - } - else - RwRGBAAssign(&particle->m_Color, psystem->m_FadeDestinationColor); - } - - if ( psystem->Flags & CLIPOUT2D ) - { - if ( particle->m_vecPosition.x < -10.0f || particle->m_vecPosition.x > SCREEN_WIDTH + 10.0f - || particle->m_vecPosition.y < -10.0f || particle->m_vecPosition.y > SCREEN_HEIGHT + 10.0f ) - { - bRemoveParticle = true; - continue; - } - } - - if ( !(psystem->Flags & SCREEN_TRAIL) ) - { - float size; - - if ( particle->m_fExpansionRate > 0.0f ) - { - float speed = Max(vecWind.Magnitude(), vecMoveStep.Magnitude()); - - if ( psystem->m_Type == PARTICLE_EXHAUST_FUMES || psystem->m_Type == PARTICLE_ENGINE_STEAM ) - speed *= 2.0f; - - if ( ( psystem->m_Type == PARTICLE_BOAT_SPLASH || psystem->m_Type == PARTICLE_CAR_SPLASH ) - && particle->m_fSize > 1.2f ) - { - size = particle->m_fSize - (1.0f + speed) * particle->m_fExpansionRate; - particle->m_vecVelocity.z -= 0.15f; - } - else - size = particle->m_fSize + (1.0f + speed) * particle->m_fExpansionRate; - } - else - size = particle->m_fSize + particle->m_fExpansionRate; - - if ( psystem->m_Type == PARTICLE_WATERDROP ) - size = (size - Abs(vecMoveStep.x) * 0.000150000007f) + (Abs(vecMoveStep.z) * 0.0500000007f); //TODO: - - if ( size < 0.0f ) - { - bRemoveParticle = true; - continue; - } - - particle->m_fSize = size; - } - - switch ( psystem->m_nFrictionDecceleration ) - { - case 50: - particle->m_vecVelocity *= fFricDeccel50; - break; - - case 80: - particle->m_vecVelocity *= fFricDeccel80; - break; - - case 90: - particle->m_vecVelocity *= fFricDeccel90; - break; - - case 95: - particle->m_vecVelocity *= fFricDeccel95; - break; - - case 96: - particle->m_vecVelocity *= fFricDeccel96; - break; - - case 99: - particle->m_vecVelocity *= fFricDeccel99; - break; - } - - if ( psystem->m_fGravitationalAcceleration > 0.0f ) - { - if ( -50.0f * psystem->m_fGravitationalAcceleration < particle->m_vecVelocity.z ) - particle->m_vecVelocity.z -= psystem->m_fGravitationalAcceleration * CTimer::GetTimeStep(); - - if ( psystem->Flags & ZCHECK_FIRST ) - { - if ( particle->m_vecPosition.z < particle->m_fZGround ) - { - switch ( psystem->m_Type ) - { - case PARTICLE_RAINDROP: - case PARTICLE_RAINDROP_SMALL: - { - bRemoveParticle = true; - - if ( CGeneral::GetRandomNumber() & 1 ) - { - AddParticle(PARTICLE_RAIN_SPLASH, - CVector - ( - particle->m_vecPosition.x, - particle->m_vecPosition.y, - 0.05f + particle->m_fZGround - ), - CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, 0, 0, 0, 0); - } - else - { - AddParticle(PARTICLE_RAIN_SPLASHUP, - CVector - ( - particle->m_vecPosition.x, - particle->m_vecPosition.y, - 0.05f + particle->m_fZGround - ), - CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, 0, 0, 0, 0); - } - - continue; - } - break; - - case PARTICLE_WHEEL_WATER: - { - bRemoveParticle = true; - - int32 randVal = CGeneral::GetRandomNumber(); - - if ( randVal & 1 ) - { - if ( (randVal % 5) == 0 ) - { - AddParticle(PARTICLE_RAIN_SPLASH, - CVector - ( - particle->m_vecPosition.x, - particle->m_vecPosition.y, - 0.05f + particle->m_fZGround - ), - CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, 0, 0, 0, 0); - } - else - { - AddParticle(PARTICLE_RAIN_SPLASHUP, - CVector - ( - particle->m_vecPosition.x, - particle->m_vecPosition.y, - 0.05f + particle->m_fZGround - ), - CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, 0, 0, 0, 0); - } - - } - continue; - } - break; - - case PARTICLE_BLOOD: - case PARTICLE_BLOOD_SMALL: - { - bRemoveParticle = true; - - CVector vecPosn = particle->m_vecPosition; - vecPosn.z += 1.0f; - - Randomizer++; - int32 randVal = int32(Randomizer & 7); - - if ( randVal == 5 ) - { - CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpBloodPoolTex, &vecPosn, - 0.1f, 0.0f, 0.0f, -0.1f, - 255, - 255, 0, 0, - 4.0f, (CGeneral::GetRandomNumber() & 4095) + 2000, 1.0f); - } - else if ( randVal == 2 ) - { - CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpBloodPoolTex, &vecPosn, - 0.2f, 0.0f, 0.0f, -0.2f, - 255, - 255, 0, 0, - 4.0f, (CGeneral::GetRandomNumber() & 4095) + 8000, 1.0f); - } - continue; - } - break; - default: break; - } - } - } - else if ( psystem->Flags & ZCHECK_STEP ) - { - CColPoint point; - CEntity *entity; - - if ( CWorld::ProcessVerticalLine(particle->m_vecPosition, vecPos.z, point, entity, - true, true, false, false, true, false, nil) ) - { - if ( vecPos.z <= point.point.z ) - { - vecPos.z = point.point.z; - if ( psystem->m_Type == PARTICLE_DEBRIS2 ) - { - particle->m_vecVelocity.x *= 0.8f; - particle->m_vecVelocity.y *= 0.8f; - particle->m_vecVelocity.z *= -0.4f; - if ( particle->m_vecVelocity.z < 0.005f ) - particle->m_vecVelocity.z = 0.0f; - } - } - } - } - else if ( psystem->Flags & ZCHECK_BUMP ) - { - if ( particle->m_vecPosition.z < particle->m_fZGround ) - { - switch ( psystem->m_Type ) - { - case PARTICLE_GUNSHELL_FIRST: - case PARTICLE_GUNSHELL: - { - bRemoveParticle = true; - - AddParticle(PARTICLE_GUNSHELL_BUMP1, - CVector - ( - particle->m_vecPosition.x, - particle->m_vecPosition.y, - 0.05f + particle->m_fZGround - ), - CVector - ( - CGeneral::GetRandomNumberInRange(-0.02f, 0.02f), - CGeneral::GetRandomNumberInRange(-0.02f, 0.02f), - CGeneral::GetRandomNumberInRange(0.05f, 0.1f) - ), - nil, - particle->m_fSize, color, particle->m_nRotationStep, 0, 0, 0); - - PlayOneShotScriptObject(SCRIPT_SOUND_GUNSHELL_DROP, particle->m_vecPosition); - } - break; - - case PARTICLE_GUNSHELL_BUMP1: - { - bRemoveParticle = true; - - AddParticle(PARTICLE_GUNSHELL_BUMP2, - CVector - ( - particle->m_vecPosition.x, - particle->m_vecPosition.y, - 0.05f + particle->m_fZGround - ), - CVector(0.0f, 0.0f, CGeneral::GetRandomNumberInRange(0.03f, 0.06f)), - nil, - particle->m_fSize, color, 0, 0, 0, 0); - - PlayOneShotScriptObject(SCRIPT_SOUND_GUNSHELL_DROP_SOFT, particle->m_vecPosition); - } - break; - - case PARTICLE_GUNSHELL_BUMP2: - { - bRemoveParticle = true; - continue; - } - break; - default: break; - } - } - } - } - else - { - if ( psystem->m_fGravitationalAcceleration < 0.0f ) - { - if ( -5.0f * psystem->m_fGravitationalAcceleration > particle->m_vecVelocity.z ) - particle->m_vecVelocity.z -= psystem->m_fGravitationalAcceleration * CTimer::GetTimeStep(); - } - else - { - if ( psystem->Flags & ZCHECK_STEP ) - { - CColPoint point; - CEntity *entity; - - if ( CWorld::ProcessVerticalLine(particle->m_vecPosition, vecPos.z, point, entity, - true, false, false, false, true, false, nil) ) - { - if ( vecPos.z <= point.point.z ) - { - vecPos.z = point.point.z; - if ( psystem->m_Type == PARTICLE_HELI_ATTACK ) - { - bRemoveParticle = true; - AddParticle(PARTICLE_STEAM, vecPos, CVector(0.0f, 0.0f, 0.05f), nil, 0.2f, 0, 0, 0, 0); - continue; - } - } - } - } - } - } - - if ( particle->m_nFadeToBlackTimer != 0 ) - { - particle->m_nColorIntensity = Clamp(particle->m_nColorIntensity - particle->m_nFadeToBlackTimer, - 0, 255); - } - - if ( particle->m_nFadeAlphaTimer != 0 ) - { - particle->m_nAlpha = Clamp(particle->m_nAlpha - particle->m_nFadeAlphaTimer, - 0, 255); - if ( particle->m_nAlpha == 0 ) - { - bRemoveParticle = true; - continue; - } - } - - if ( psystem->m_nZRotationAngleChangeAmount != 0 ) - { - if ( particle->m_nZRotationTimer >= psystem->m_nZRotationChangeTime ) - { - particle->m_nZRotationTimer = 0; - particle->m_nCurrentZRotation += psystem->m_nZRotationAngleChangeAmount; - } - else - ++particle->m_nZRotationTimer; - } - - if ( psystem->m_fZRadiusChangeAmount != 0.0f ) - { - if ( particle->m_nZRadiusTimer >= psystem->m_nZRadiusChangeTime ) - { - particle->m_nZRadiusTimer = 0; - particle->m_fCurrentZRadius += psystem->m_fZRadiusChangeAmount; - } - else - ++particle->m_nZRadiusTimer; - } - - if ( psystem->m_nAnimationSpeed != 0 ) - { - if ( particle->m_nAnimationSpeedTimer > psystem->m_nAnimationSpeed ) - { - particle->m_nAnimationSpeedTimer = 0; - - if ( ++particle->m_nCurrentFrame > psystem->m_nFinalAnimationFrame ) - { - if ( psystem->Flags & CYCLE_ANIM ) - particle->m_nCurrentFrame = psystem->m_nStartAnimationFrame; - else - --particle->m_nCurrentFrame; - } - } - else - ++particle->m_nAnimationSpeedTimer; - } - - if ( particle->m_nRotationStep != 0 ) -#ifdef FIX_BUGS - particle->m_nRotation = CGeneral::LimitAngle(particle->m_nRotation + particle->m_nRotationStep); -#else - particle->m_nRotation += particle->m_nRotationStep; -#endif - - if ( particle->m_fCurrentZRadius != 0.0f ) - { - int32 nSinCosIndex = particle->m_nCurrentZRotation % SIN_COS_TABLE_SIZE; - - float fX = (Cos(nSinCosIndex) - Sin(nSinCosIndex)) * particle->m_fCurrentZRadius; - - float fY = (Sin(nSinCosIndex) + Cos(nSinCosIndex)) * particle->m_fCurrentZRadius; - - vecPos -= particle->m_vecParticleMovementOffset; - - vecPos += CVector(fX, fY, 0.0f); - - particle->m_vecParticleMovementOffset = CVector(fX, fY, 0.0f); - } - - particle->m_vecPosition = vecPos; - } - } -} - -void CParticle::Render() -{ - PUSH_RENDERGROUP("CParticle::Render"); - - RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void *)rwTEXTUREADDRESSWRAP); - RwRenderStateSet(rwRENDERSTATETEXTUREPERSPECTIVE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - - CSprite::InitSpriteBuffer2D(); - - uint32 flags = DRAW_OPAQUE; - - RwRaster *prevFrame = nil; - - for ( int32 i = 0; i < MAX_PARTICLES; i++ ) - { - tParticleSystemData *psystem = &mod_ParticleSystemManager.m_aParticles[i]; - bool particleBanned = false; - CParticle *particle = psystem->m_pParticles; - - RwRaster **frames = psystem->m_ppRaster; - tParticleType type = psystem->m_Type; - - if ( type == PARTICLE_ENGINE_SMOKE - || type == PARTICLE_ENGINE_SMOKE2 - || type == PARTICLE_ENGINE_STEAM - || type == PARTICLE_CARFLAME_SMOKE - || type == PARTICLE_RUBBER_SMOKE - || type == PARTICLE_BURNINGRUBBER_SMOKE - || type == PARTICLE_EXHAUST_FUMES - || type == PARTICLE_CARCOLLISION_DUST ) - { - particleBanned = true; - } - - if ( particle ) - { - if ( (flags & DRAW_OPAQUE) != (psystem->Flags & DRAW_OPAQUE) - || (flags & DRAW_DARK) != (psystem->Flags & DRAW_DARK) ) - { - CSprite::FlushSpriteBuffer(); - - if ( psystem->Flags & DRAW_OPAQUE ) - { - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - } - else - { - if ( psystem->Flags & DRAW_DARK ) - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - else - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); - - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); - } - - flags = psystem->Flags; - } - - if ( frames != nil ) - { - RwRaster *curFrame = *frames; - if ( curFrame != prevFrame ) - { - CSprite::FlushSpriteBuffer(); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)curFrame); - prevFrame = curFrame; - } - } - } - - while ( particle != nil ) - { - bool canDraw = true; - - if ( particle->m_nAlpha == 0 ) - canDraw = false; - - if ( canDraw && psystem->m_nFinalAnimationFrame != 0 && frames != nil ) - { - RwRaster *curFrame = frames[particle->m_nCurrentFrame]; - if ( prevFrame != curFrame ) - { - CSprite::FlushSpriteBuffer(); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)curFrame); - prevFrame = curFrame; - } - } - - if ( canDraw && psystem->Flags & DRAWTOP2D ) - { - float screenZ; -#ifdef FIX_BUGS - bool zIsZero = true; - if ( particle->m_vecPosition.z != 0.0f ) { -#endif - screenZ = (particle->m_vecPosition.z - CDraw::GetNearClipZ()) - * (CSprite::GetFarScreenZ() - CSprite::GetNearScreenZ()) - * CDraw::GetFarClipZ() - / ( (CDraw::GetFarClipZ() - CDraw::GetNearClipZ()) * particle->m_vecPosition.z ) - + CSprite::GetNearScreenZ(); -#ifdef FIX_BUGS - zIsZero = false; - } -#endif - - float stretchTexW; - float stretchTexH; - - if ( i == PARTICLE_RAINDROP || i == PARTICLE_RAINDROP_SMALL || i == PARTICLE_RAINDROP_2D ) - { - stretchTexW = CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.x * (float)particle->m_nCurrentFrame + 63.0f; - stretchTexH = CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.y * (float)particle->m_nCurrentFrame + 63.0f; - } - else - { - stretchTexW = CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.x + 63.0f; - stretchTexH = CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.y + 63.0f; - } - -#ifdef FIX_BUGS - if (!zIsZero) { -#endif - - if ( i == PARTICLE_WATERDROP ) - { - int32 timeLeft = (particle->m_nTimeWhenWillBeDestroyed - CTimer::GetTimeInMilliseconds()) / particle->m_nTimeWhenWillBeDestroyed; - - stretchTexH += (1.0f - (float)timeLeft ) * psystem->m_vecTextureStretch.y; - - RwRect rect; - - rect.x = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); - rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH)); - rect.w = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); - rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH)); - - FxType fxtype; - - if ( particle->m_nCurrentFrame != 0 ) - fxtype = FXTYPE_WATER2; - else - fxtype = FXTYPE_WATER1; - - CMBlur::AddRenderFx(Scene.camera, &rect, screenZ, fxtype); - - canDraw = false; - } - - if ( i == PARTICLE_BLOODDROP ) - { - int32 timeLeft = (particle->m_nTimeWhenWillBeDestroyed - CTimer::GetTimeInMilliseconds()) / particle->m_nTimeWhenWillBeDestroyed; - - stretchTexH += (1.0f + (float)timeLeft) * psystem->m_vecTextureStretch.y; - stretchTexW += (1.0f - (float)timeLeft) * psystem->m_vecTextureStretch.x; - - RwRect rect; - - rect.x = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); - rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH)); - rect.w = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); - rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH)); - - FxType fxtype; - - if ( particle->m_nCurrentFrame ) - fxtype = FXTYPE_BLOOD2; - else - fxtype = FXTYPE_BLOOD1; - - CMBlur::AddRenderFx(Scene.camera, &rect, screenZ, fxtype); - - canDraw = false; - } - - if ( i == PARTICLE_HEATHAZE_IN_DIST ) - { - RwRect rect; - - rect.x = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); - rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH * 0.15f)); - rect.w = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); - rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH * 0.15f)); - - CMBlur::AddRenderFx(Scene.camera, &rect, screenZ, FXTYPE_HEATHAZE); - - canDraw = false; - } - - if ( i == PARTICLE_HEATHAZE ) - { - RwRect rect; - - switch ( TheCamera.GetLookDirection() ) - { - case LOOKING_LEFT: - rect.x = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x * 2.0f)); - rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); - rect.w = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x)); - rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); - - break; - - case LOOKING_RIGHT: - rect.x = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x)); - rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); - rect.w = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x * 4.0f)); - rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); - - break; - - default: - rect.x = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x)); - rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); - rect.w = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x)); - rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); - - break; - } - - CMBlur::AddRenderFx(Scene.camera, &rect, screenZ, FXTYPE_HEATHAZE); - - canDraw = false; - } -#ifdef FIX_BUGS - } - if ( !(zIsZero && (i == PARTICLE_WATERDROP || i == PARTICLE_BLOODDROP || i == PARTICLE_HEATHAZE_IN_DIST || i == PARTICLE_HEATHAZE) ) ) -#endif - if ( canDraw ) - { - if ( particle->m_nRotation != 0 ) - { - CSprite::RenderBufferedOneXLUSprite2D_Rotate_Dimension( - particle->m_vecPosition.x, - particle->m_vecPosition.y, - particle->m_fSize * stretchTexW, - particle->m_fSize * stretchTexH, - particle->m_Color, - particle->m_nColorIntensity, - DEGTORAD((float)particle->m_nRotation), - particle->m_nAlpha); - } - else - { - CSprite::RenderBufferedOneXLUSprite2D( - particle->m_vecPosition.x, - particle->m_vecPosition.y, - particle->m_fSize * stretchTexW, - particle->m_fSize * stretchTexH, - particle->m_Color, - particle->m_nColorIntensity, - particle->m_nAlpha); - } - } - - canDraw = false; - } - - if ( canDraw ) - { - CVector coors; - float w; - float h; - - if ( CSprite::CalcScreenCoors(particle->m_vecPosition, &coors, &w, &h, true) ) - { - - if ( i == PARTICLE_ENGINE_STEAM - || i == PARTICLE_ENGINE_SMOKE - || i == PARTICLE_ENGINE_SMOKE2 - || i == PARTICLE_CARFLAME_SMOKE - || i == PARTICLE_CARCOLLISION_DUST - || i == PARTICLE_EXHAUST_FUMES - || i == PARTICLE_RUBBER_SMOKE - || i == PARTICLE_BURNINGRUBBER_SMOKE ) - { - switch ( TheCamera.GetLookDirection() ) - { - case LOOKING_LEFT: - case LOOKING_RIGHT: - w += CGeneral::GetRandomNumberInRange(1.0f, 7.5f) * psystem->m_vecTextureStretch.x; - h += CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.y; - break; - - default: - w += CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.x; - h += CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.y; - break; - } - } - else if ( i == PARTICLE_WATER_HYDRANT ) - { - int32 timeLeft = (particle->m_nTimeWhenWillBeDestroyed - CTimer::GetTimeInMilliseconds()) / particle->m_nTimeWhenWillBeDestroyed; - - w += (1.0f - (float)timeLeft) * psystem->m_vecTextureStretch.x; - h += (1.0f - (float)timeLeft) * psystem->m_vecTextureStretch.y; - } - else if ( i == PARTICLE_FLYERS ) - { - w += psystem->m_vecTextureStretch.x; - h += psystem->m_vecTextureStretch.y; - - w = Max(w, 12.0f); - h = Max(h, 12.0f); - } - else - { - w += CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.x; - h += CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.y; - } - - if ( i == PARTICLE_WATER_HYDRANT - || (!particleBanned || SCREEN_WIDTH * fParticleScaleLimit >= w) - && SCREEN_HEIGHT * fParticleScaleLimit >= h ) - { - if ( i == PARTICLE_WATER_HYDRANT ) - { - RwRect rect; - - if ( w > 0.0f ) - { - rect.x = int32(coors.x - SCREEN_STRETCH_X(particle->m_fSize * w)); - rect.w = int32(coors.x + SCREEN_STRETCH_X(particle->m_fSize * w)); - } - else - { - rect.w = int32(coors.x - SCREEN_STRETCH_X(particle->m_fSize * w)); - rect.x = int32(coors.x + SCREEN_STRETCH_X(particle->m_fSize * w)); - } - - if ( h > 0.0f ) - { - rect.y = int32(coors.y - SCREEN_STRETCH_Y(particle->m_fSize * h)); - rect.h = int32(coors.y + SCREEN_STRETCH_Y(particle->m_fSize * h)); - } - else - { - rect.h = int32(coors.y - SCREEN_STRETCH_Y(particle->m_fSize * h)); - rect.y = int32(coors.y + SCREEN_STRETCH_Y(particle->m_fSize * h)); - } - - float screenZ = (coors.z - CDraw::GetNearClipZ()) - * (CSprite::GetFarScreenZ() - CSprite::GetNearScreenZ()) * CDraw::GetFarClipZ() - / ( (CDraw::GetFarClipZ() - CDraw::GetNearClipZ()) * coors.z ) + CSprite::GetNearScreenZ(); - - CMBlur::AddRenderFx(Scene.camera, &rect, screenZ, FXTYPE_SPLASH1); - } - else - { - if ( particle->m_nRotation != 0 && i != PARTICLE_BEASTIE ) - { - CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension(coors.x, coors.y, coors.z, - particle->m_fSize * w, particle->m_fSize * h, - particle->m_Color.red, - particle->m_Color.green, - particle->m_Color.blue, - particle->m_nColorIntensity, - 1.0f / coors.z, - DEGTORAD((float)particle->m_nRotation), - particle->m_nAlpha); - } - else if ( psystem->Flags & SCREEN_TRAIL ) - { - float fRotation; - float fTrailLength; - - if ( particle->m_fZGround == 0.0f ) - { - fTrailLength = 0.0f; - fRotation = 0.0f; - } - else - { - CVector2D vecDist - ( - coors.x - particle->m_fZGround, - coors.y - particle->m_fExpansionRate - ); - - float fDist = vecDist.Magnitude(); - - fTrailLength = fDist; - - float fRot = Asin(vecDist.x / fDist); - - fRotation = fRot; - - if ( vecDist.y < 0.0f ) - fRotation = -1.0f * fRot + DEGTORAD(180.0f); - - float fSpeed = particle->m_vecVelocity.Magnitude(); - - float fNewTrailLength = fSpeed * CTimer::GetTimeStep() * w * 2.0f; - - if ( fDist > fNewTrailLength ) - fTrailLength = fNewTrailLength; - } - - CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension(coors.x, coors.y, coors.z, - particle->m_fSize * w, - particle->m_fSize * h + fTrailLength * psystem->m_fTrailLengthMultiplier, - particle->m_Color.red, - particle->m_Color.green, - particle->m_Color.blue, - particle->m_nColorIntensity, - 1.0f / coors.z, - fRotation, - particle->m_nAlpha); - - particle->m_fZGround = coors.x; // WTF ? - particle->m_fExpansionRate = coors.y; // WTF ? - } - else if ( psystem->Flags & SPEED_TRAIL ) - { - CVector vecPrevPos = particle->m_vecPosition - particle->m_vecVelocity; - float fRotation; - float fTrailLength; - CVector vecScreenPosition; - - if ( CSprite::CalcScreenCoors(vecPrevPos, &vecScreenPosition, &fTrailLength, &fRotation, true) ) - { - CVector2D vecDist - ( - coors.x - vecScreenPosition.x, - coors.y - vecScreenPosition.y - ); - - float fDist = vecDist.Magnitude(); - - fTrailLength = fDist; - - float fRot = Asin(vecDist.x / fDist); - - fRotation = fRot; - - if ( vecDist.y < 0.0f ) - fRotation = -1.0f * fRot + DEGTORAD(180.0f); - } - else - { - fRotation = 0.0f; - fTrailLength = 0.0f; - } - - CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension(coors.x, coors.y, coors.z, - particle->m_fSize * w, - particle->m_fSize * h + fTrailLength * psystem->m_fTrailLengthMultiplier, - particle->m_Color.red, - particle->m_Color.green, - particle->m_Color.blue, - particle->m_nColorIntensity, - 1.0f / coors.z, - fRotation, - particle->m_nAlpha); - } - else if ( psystem->Flags & VERT_TRAIL ) - { - float fTrailLength = fabsf(particle->m_vecVelocity.z * 10.0f); - - CSprite::RenderBufferedOneXLUSprite(coors.x, coors.y, coors.z, - particle->m_fSize * w, - (particle->m_fSize + fTrailLength * psystem->m_fTrailLengthMultiplier) * h, - particle->m_Color.red, - particle->m_Color.green, - particle->m_Color.blue, - particle->m_nColorIntensity, - 1.0f / coors.z, - particle->m_nAlpha); - } - else if ( i == PARTICLE_RAINDROP_SMALL ) - { - CSprite::RenderBufferedOneXLUSprite(coors.x, coors.y, coors.z, - particle->m_fSize * w * 0.05f, - particle->m_fSize * h, - particle->m_Color.red, - particle->m_Color.green, - particle->m_Color.blue, - particle->m_nColorIntensity, - 1.0f / coors.z, - particle->m_nAlpha); - } - /*else if ( i == PARTICLE_BOAT_WAKE )*/ - else - { - CSprite::RenderBufferedOneXLUSprite(coors.x, coors.y, coors.z, - particle->m_fSize * w, - particle->m_fSize * h, - particle->m_Color.red, - particle->m_Color.green, - particle->m_Color.blue, - particle->m_nColorIntensity, - 1.0f / coors.z, - particle->m_nAlpha); - } - } - } - } - } - - particle = particle->m_pNext; - } - - CSprite::FlushSpriteBuffer(); - - } - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - - POP_RENDERGROUP(); -} - -void CParticle::RemovePSystem(tParticleType type) -{ - tParticleSystemData *psystemdata = &mod_ParticleSystemManager.m_aParticles[type]; - - for ( CParticle *particle = psystemdata->m_pParticles; particle; particle = psystemdata->m_pParticles ) - RemoveParticle(particle, nil, psystemdata); -} - -void CParticle::RemoveParticle(CParticle *pParticle, CParticle *pPrevParticle, tParticleSystemData *pPSystemData) -{ - if ( pPSystemData->m_Type == PARTICLE_WATERDROP ) - --numWaterDropOnScreen; - - if ( pPrevParticle ) - pPrevParticle->m_pNext = pParticle->m_pNext; - else - pPSystemData->m_pParticles = pParticle->m_pNext; - - pParticle->m_pNext = m_pUnusedListHead; - m_pUnusedListHead = pParticle; -} - -void CParticle::AddJetExplosion(CVector const &vecPos, float fPower, float fSize) -{ - CRGBA color(240, 240, 240, 255); - - if ( fPower < 1.0f ) - fPower = 1.0f; - - CVector vecRandOffset - ( - CGeneral::GetRandomNumberInRange(-0.4f, 0.4f), - CGeneral::GetRandomNumberInRange(-0.4f, 0.4f), - CGeneral::GetRandomNumberInRange(0.1f, 0.3f) - ); - - vecRandOffset *= 2.0f; - - CVector vecStepPos = vecPos; - - for ( int32 i = 0; i < int32(fPower * 4.0f); i++ ) - { - AddParticle(PARTICLE_EXPLOSION_MFAST, - vecStepPos, - CVector - ( - CGeneral::GetRandomNumberInRange(-0.02f, 0.02f), - CGeneral::GetRandomNumberInRange(-0.02f, 0.02f), - CGeneral::GetRandomNumberInRange(-0.02f, 0.0f) - ), - nil, - fSize, color, 0, 0, 0, 0); - - AddParticle(PARTICLE_EXPLOSION_MFAST, - vecStepPos, - CVector - ( - CGeneral::GetRandomNumberInRange(-0.04f, 0.04f), - CGeneral::GetRandomNumberInRange(-0.04f, 0.04f), - CGeneral::GetRandomNumberInRange(0.0f, 0.07f) - ), - nil, - fSize, color, 0, 0, 0, 0); - - AddParticle(PARTICLE_EXPLOSION_MFAST, - vecStepPos, - CVector - ( - CGeneral::GetRandomNumberInRange(-0.04f, 0.04f), - CGeneral::GetRandomNumberInRange(-0.04f, 0.04f), - CGeneral::GetRandomNumberInRange(0.0f, 0.07f) - ), - nil, - fSize, color, 0, 0, 0, 0); - - vecStepPos += vecRandOffset; - } -} - -void CParticle::AddYardieDoorSmoke(CVector const &vecPos, CMatrix const &matMatrix) -{ - CRGBA color(0, 0, 0, 0); - - CMatrix invMat(Invert(matMatrix)); - - CVector vecBasePos = matMatrix * (invMat * vecPos + CVector(0.0f, -1.0f, 0.5f)); - - for ( int32 i = 0; i < 5; i++ ) - { - CVector pos = vecBasePos; - - pos.x += CGeneral::GetRandomNumberInRange(-0.5f, 0.5f); - pos.y += CGeneral::GetRandomNumberInRange(-0.5f, 0.5f); - - AddParticle(PARTICLE_CARCOLLISION_DUST, - pos, - CVector(0.0f, 0.0f, 0.0f), - nil, - 0.3f, color, 0, 0, 0, 0); - } -} - -void CParticle::CalWindDir(CVector *vecDirIn, CVector *vecDirOut) -{ - vecDirOut->x = (Cos(128) * vecDirIn->x) + (Sin(128) * vecDirIn->y); - - vecDirOut->x = (Cos(128) * vecDirIn->x) + (Sin(128) * vecDirIn->y) * CWeather::Wind; - vecDirOut->y = (Sin(128) * vecDirIn->x) - (Cos(128) * vecDirIn->y) * CWeather::Wind; -} - -void CParticle::HandleShipsAtHorizonStuff() -{ - tParticleSystemData *psystemdata = &mod_ParticleSystemManager.m_aParticles[PARTICLE_SHIP_SIDE]; - - for ( CParticle *particle = psystemdata->m_pParticles; particle; particle = particle->m_pNext ) - { - if ( CTimer::GetTimeInMilliseconds() > particle->m_nTimeWhenWillBeDestroyed - 32000 - && CTimer::GetTimeInMilliseconds() < particle->m_nTimeWhenWillBeDestroyed - 22000 ) - { - particle->m_nAlpha = Min(particle->m_nAlpha + 1, 96); - } - if ( CTimer::GetTimeInMilliseconds() > particle->m_nTimeWhenWillBeDestroyed - 10000 ) - particle->m_nFadeAlphaTimer = 1; - } -} - -void CParticle::HandleShootableBirdsStuff(CEntity *entity, CVector const&camPos) -{ - float fHeadingRad = entity->GetForward().Heading(); - float fHeading = RADTODEG(fHeadingRad); - float fBirdAngle = ::Cos(DEGTORAD(1.5f)); - - tParticleSystemData *psystem = &mod_ParticleSystemManager.m_aParticles[PARTICLE_BIRD_FRONT]; - CParticle *particle = psystem->m_pParticles; - CParticle *prevParticle = nil; - bool bRemoveParticle; - - for ( ; particle != nil; _Next(particle, prevParticle, psystem, bRemoveParticle) ) - { - bRemoveParticle = false; - - CVector2D vecPos(particle->m_vecPosition.x, particle->m_vecPosition.y); - CVector2D vecCamPos(camPos.x, camPos.y); - - CVector2D vecDist = vecPos - vecCamPos; - vecDist.Normalise(); - - float fHead = DEGTORAD(fHeading); - - CVector2D vecDir(-::Sin(fHead), ::Cos(fHead)); - vecDir.Normalise(); - - float fDot = DotProduct2D(vecDir, vecDist); - - if ( fDot > 0.0f && fDot > fBirdAngle ) - { - if ( (camPos - particle->m_vecPosition).MagnitudeSqr() < 40000.0f ) - { - CStats::SeagullsKilled++; - - bRemoveParticle = true; - - for ( int32 i = 0; i < 8; i++ ) - { - CParticle *pBirdDerbis = AddParticle(PARTICLE_BIRD_DEBRIS, - particle->m_vecPosition, - CVector - ( - CGeneral::GetRandomNumberInRange(-3.0f, 3.0f), - CGeneral::GetRandomNumberInRange(-3.0f, 3.0f), - CGeneral::GetRandomNumberInRange(-3.0f, 3.0f) - ), - nil, - 0.3f, - particle->m_Color, - CGeneral::GetRandomNumberInRange(20, 40), - 0, - CGeneral::GetRandomNumber() & 3, - 200); - if ( pBirdDerbis ) - pBirdDerbis->m_nAlpha = particle->m_nAlpha; - } - } - } - } - -} - -void -CEntity::AddSteamsFromGround(CVector *unused) -{ - int i, n; - C2dEffect *effect; - CVector pos; - - n = CModelInfo::GetModelInfo(GetModelIndex())->GetNum2dEffects(); - for(i = 0; i < n; i++){ - effect = CModelInfo::GetModelInfo(GetModelIndex())->Get2dEffect(i); - if(effect->type != EFFECT_PARTICLE) - continue; - - pos = GetMatrix() * effect->pos; - switch(effect->particle.particleType){ - case 0: - CParticleObject::AddObject(POBJECT_PAVEMENT_STEAM, pos, effect->particle.dir, effect->particle.scale, false); - break; - case 1: - CParticleObject::AddObject(POBJECT_WALL_STEAM, pos, effect->particle.dir, effect->particle.scale, false); - break; - case 2: - CParticleObject::AddObject(POBJECT_DRY_ICE, pos, effect->particle.scale, false); - break; - case 3: - CParticleObject::AddObject(POBJECT_SMALL_FIRE, pos, effect->particle.dir, effect->particle.scale, false); - break; - case 4: - CParticleObject::AddObject(POBJECT_DARK_SMOKE, pos, effect->particle.dir, effect->particle.scale, false); - break; - case 5: - CParticleObject::AddObject(POBJECT_WATER_FOUNTAIN_VERT, pos, effect->particle.dir, effect->particle.scale, false); - break; - case 6: - CParticleObject::AddObject(POBJECT_WATER_FOUNTAIN_HORIZ, pos, effect->particle.dir, effect->particle.scale, false); - break; - } - } -} diff --git a/src/render/Particle.h b/src/render/Particle.h deleted file mode 100644 index 5542dc02..00000000 --- a/src/render/Particle.h +++ /dev/null @@ -1,108 +0,0 @@ -#pragma once -#include "ParticleMgr.h" - - -class CEntity; - -class CParticle -{ -public: - enum - { - RAND_TABLE_SIZE = 20, - SIN_COS_TABLE_SIZE = 1024 - }; - - CVector m_vecPosition; - CVector m_vecVelocity; - uint32 m_nTimeWhenWillBeDestroyed; - uint32 m_nTimeWhenColorWillBeChanged; - float m_fZGround; - CVector m_vecParticleMovementOffset; - int16 m_nCurrentZRotation; - uint16 m_nZRotationTimer; - float m_fCurrentZRadius; - uint16 m_nZRadiusTimer; - uint8 m_nColorIntensity; - uint8 m_nAlpha; - float m_fSize; - float m_fExpansionRate; - int16 m_nFadeToBlackTimer; - int16 m_nFadeAlphaTimer; - int16 m_nAnimationSpeedTimer; - int16 m_nRotationStep; - int16 m_nRotation; - uint8 m_nCurrentFrame; - RwRGBA m_Color; - CParticle *m_pNext; - - CParticle() - { - ; - } - - ~CParticle() - { - ; - } - - static float ms_afRandTable[RAND_TABLE_SIZE]; - static CParticle *m_pUnusedListHead; - - static float m_SinTable[SIN_COS_TABLE_SIZE]; - static float m_CosTable[SIN_COS_TABLE_SIZE]; - - static float Sin(int32 value) { return m_SinTable[value]; } - static float Cos(int32 value) { return m_CosTable[value]; } - - static void ReloadConfig(); - static void Initialise(); - static void Shutdown(); - - static void AddParticlesAlongLine(tParticleType type, CVector const &vecStart, CVector const &vecEnd, CVector const &vecDir, float fPower, CEntity *pEntity = nil, float fSize = 0.0f, int32 nRotationSpeed = 0, int32 nRotation = 0, int32 nCurFrame = 0, int32 nLifeSpan = 0); - static void AddParticlesAlongLine(tParticleType type, CVector const &vecStart, CVector const &vecEnd, CVector const &vecDir, float fPower, CEntity *pEntity, float fSize, RwRGBA const&color, int32 nRotationSpeed = 0, int32 nRotation = 0, int32 nCurFrame = 0, int32 nLifeSpan = 0); - - static CParticle *AddParticle(tParticleType type, CVector const &vecPos, CVector const &vecDir, CEntity *pEntity = nil, float fSize = 0.0f, int32 nRotationSpeed = 0, int32 nRotation = 0, int32 nCurFrame = 0, int32 nLifeSpan = 0); - static CParticle *AddParticle(tParticleType type, CVector const &vecPos, CVector const &vecDir, CEntity *pEntity, float fSize, RwRGBA const &color, int32 nRotationSpeed = 0, int32 nRotation = 0, int32 nCurFrame = 0, int32 nLifeSpan = 0); - - static void Update(); - static void Render(); - - static void RemovePSystem(tParticleType type); - static void RemoveParticle(CParticle *pParticle, CParticle *pPrevParticle, tParticleSystemData *pPSystemData); - - static void _Next(CParticle *&pParticle, CParticle *&pPrevParticle, tParticleSystemData *pPSystemData, bool bRemoveParticle) - { - if ( bRemoveParticle ) - { - RemoveParticle(pParticle, pPrevParticle, pPSystemData); - - if ( pPrevParticle ) - pParticle = pPrevParticle->m_pNext; - else - pParticle = pPSystemData->m_pParticles; - } - else - { - pPrevParticle = pParticle; - pParticle = pParticle->m_pNext; - } - } - - static void AddJetExplosion(CVector const &vecPos, float fPower, float fSize); - static void AddYardieDoorSmoke(CVector const &vecPos, CMatrix const &matMatrix); - static void CalWindDir(CVector *vecDirIn, CVector *vecDirOut); - - static void HandleShipsAtHorizonStuff(); - static void HandleShootableBirdsStuff(CEntity *entity, CVector const&camPos); -}; - -extern bool clearWaterDrop; -extern int32 numWaterDropOnScreen; -extern RwRaster *gpCarSplashRaster[]; -extern RwRaster *gpHeatHazeRaster; -extern RwRaster *gpDotRaster; -extern RwRaster *gpRainDripRaster[]; -extern RwRaster *gpRainDripDarkRaster[]; - -VALIDATE_SIZE(CParticle, 0x58); diff --git a/src/render/ParticleMgr.cpp b/src/render/ParticleMgr.cpp deleted file mode 100644 index f6919435..00000000 --- a/src/render/ParticleMgr.cpp +++ /dev/null @@ -1,255 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "FileMgr.h" -#include "ParticleMgr.h" - -cParticleSystemMgr mod_ParticleSystemManager; - -const char *ParticleFilename = "PARTICLE.CFG"; - -cParticleSystemMgr::cParticleSystemMgr() -{ - memset(this, 0, sizeof(*this)); -} - -void cParticleSystemMgr::Initialise() -{ - LoadParticleData(); - - for ( int32 i = 0; i < MAX_PARTICLES; i++ ) - m_aParticles[i].m_pParticles = nil; -} - -void cParticleSystemMgr::LoadParticleData() -{ - CFileMgr::SetDir("DATA"); - CFileMgr::LoadFile(ParticleFilename, work_buff, ARRAY_SIZE(work_buff), "r"); - CFileMgr::SetDir(""); - - tParticleSystemData *entry = nil; - int32 type = PARTICLE_FIRST; - - char *lineStart = (char *)work_buff; - char *lineEnd = lineStart + 1; - - char line[500]; - char delims[4]; - - while ( true ) - { - ASSERT(lineStart != nil); - ASSERT(lineEnd != nil); - - while ( *lineEnd != '\n' ) - ++lineEnd; - - int32 lineLength = lineEnd - lineStart; - - ASSERT(lineLength < 500); - - strncpy(line, lineStart, lineLength); - - line[lineLength] = '\0'; - - if ( !strcmp(line, ";the end") ) - break; - - if ( *line != ';' ) - { - int32 param = CFG_PARAM_FIRST; - - strcpy(delims, " \t"); - - char *value = strtok(line, delims); - - ASSERT(value != nil); - - do - { - switch ( param ) - { - case CFG_PARAM_PARTICLE_TYPE_NAME: - ASSERT(type < MAX_PARTICLES); - entry = &m_aParticles[type]; - ASSERT(entry != nil); - entry->m_Type = (tParticleType)type++; - strcpy(entry->m_aName, value); - break; - - case CFG_PARAM_RENDER_COLOURING_R: - entry->m_RenderColouring.red = atoi(value); - break; - - case CFG_PARAM_RENDER_COLOURING_G: - entry->m_RenderColouring.green = atoi(value); - break; - - case CFG_PARAM_RENDER_COLOURING_B: - entry->m_RenderColouring.blue = atoi(value); - break; - - case CFG_PARAM_INITIAL_COLOR_VARIATION: - entry->m_InitialColorVariation = Min(atoi(value), 100); - break; - - case CFG_PARAM_FADE_DESTINATION_COLOR_R: - entry->m_FadeDestinationColor.red = atoi(value); - break; - - case CFG_PARAM_FADE_DESTINATION_COLOR_G: - entry->m_FadeDestinationColor.green = atoi(value); - break; - - case CFG_PARAM_FADE_DESTINATION_COLOR_B: - entry->m_FadeDestinationColor.blue = atoi(value); - break; - - case CFG_PARAM_COLOR_FADE_TIME: - entry->m_ColorFadeTime = atoi(value); - break; - - case CFG_PARAM_DEFAULT_INITIAL_RADIUS: - entry->m_fDefaultInitialRadius = atof(value); - break; - - case CFG_PARAM_EXPANSION_RATE: - entry->m_fExpansionRate = atof(value); - break; - - case CFG_PARAM_INITIAL_INTENSITY: - entry->m_nFadeToBlackInitialIntensity = atoi(value); - break; - - case CFG_PARAM_FADE_TIME: - entry->m_nFadeToBlackTime = atoi(value); - break; - - case CFG_PARAM_FADE_AMOUNT: - entry->m_nFadeToBlackAmount = atoi(value); - break; - - case CFG_PARAM_INITIAL_ALPHA_INTENSITY: - entry->m_nFadeAlphaInitialIntensity = atoi(value); - break; - - case CFG_PARAM_FADE_ALPHA_TIME: - entry->m_nFadeAlphaTime = atoi(value); - break; - - case CFG_PARAM_FADE_ALPHA_AMOUNT: - entry->m_nFadeAlphaAmount = atoi(value); - break; - - case CFG_PARAM_INITIAL_ANGLE: - entry->m_nZRotationInitialAngle = atoi(value); - break; - - case CFG_PARAM_CHANGE_TIME: - entry->m_nZRotationChangeTime = atoi(value); - break; - - case CFG_PARAM_ANGLE_CHANGE_AMOUNT: - entry->m_nZRotationAngleChangeAmount = atoi(value); - break; - - case CFG_PARAM_INITIAL_Z_RADIUS: - entry->m_fInitialZRadius = atof(value); - break; - - case CFG_PARAM_Z_RADIUS_CHANGE_TIME: - entry->m_nZRadiusChangeTime = atoi(value); - break; - - case CFG_PARAM_Z_RADIUS_CHANGE_AMOUNT: - entry->m_fZRadiusChangeAmount = atof(value); - break; - - case CFG_PARAM_ANIMATION_SPEED: - entry->m_nAnimationSpeed = atoi(value); - break; - - case CFG_PARAM_START_ANIMATION_FRAME: - entry->m_nStartAnimationFrame = atoi(value); - break; - - case CFG_PARAM_FINAL_ANIMATION_FRAME: - entry->m_nFinalAnimationFrame = atoi(value); - break; - - case CFG_PARAM_ROTATION_SPEED: - entry->m_nRotationSpeed = atoi(value); - break; - - case CFG_PARAM_GRAVITATIONAL_ACCELERATION: - entry->m_fGravitationalAcceleration = atof(value); - break; - - case CFG_PARAM_FRICTION_DECCELERATION: - entry->m_nFrictionDecceleration = atoi(value); - break; - - case CFG_PARAM_LIFE_SPAN: - entry->m_nLifeSpan = atoi(value); - break; - - case CFG_PARAM_POSITION_RANDOM_ERROR: - entry->m_fPositionRandomError = atof(value); - break; - - case CFG_PARAM_VELOCITY_RANDOM_ERROR: - entry->m_fVelocityRandomError = atof(value); - break; - - case CFG_PARAM_EXPANSION_RATE_ERROR: - entry->m_fExpansionRateError = atof(value); - break; - - case CFG_PARAM_ROTATION_RATE_ERROR: - entry->m_nRotationRateError = atoi(value); - break; - - case CFG_PARAM_LIFE_SPAN_ERROR_SHAPE: - entry->m_nLifeSpanErrorShape = atoi(value); - break; - - case CFG_PARAM_TRAIL_LENGTH_MULTIPLIER: - entry->m_fTrailLengthMultiplier = atof(value); - break; - - case CFG_PARAM_STRETCH_VALUE_X: - entry->m_vecTextureStretch.x = atof(value); - break; - - case CFG_PARAM_STRETCH_VALUE_Y: - entry->m_vecTextureStretch.y = atof(value); - break; - - case CFG_PARAM_WIND_FACTOR: - entry->m_fWindFactor = atof(value); - break; - - case CFG_PARAM_PARTICLE_CREATE_RANGE: - entry->m_fCreateRange = SQR(atof(value)); - break; - - case CFG_PARAM_FLAGS: - entry->Flags = atoi(value); - break; - } - - value = strtok(nil, delims); - - param++; - - if ( param > CFG_PARAM_LAST ) - param = CFG_PARAM_FIRST; - - } while ( value != nil ); - } - - lineEnd++; - lineStart = lineEnd; - lineEnd++; - } -} diff --git a/src/render/ParticleMgr.h b/src/render/ParticleMgr.h deleted file mode 100644 index f4afc018..00000000 --- a/src/render/ParticleMgr.h +++ /dev/null @@ -1,138 +0,0 @@ -#pragma once - -#include "ParticleType.h" - -class CParticle; - -enum -{ - ZCHECK_FIRST = BIT(0), - ZCHECK_STEP = BIT(1), - DRAW_OPAQUE = BIT(2), - SCREEN_TRAIL = BIT(3), - SPEED_TRAIL = BIT(4), - RAND_VERT_V = BIT(5), - CYCLE_ANIM = BIT(6), - DRAW_DARK = BIT(7), - VERT_TRAIL = BIT(8), - _FLAG9 = BIT(9), // unused - DRAWTOP2D = BIT(10), - CLIPOUT2D = BIT(11), - ZCHECK_BUMP = BIT(12), - ZCHECK_BUMP_FIRST = BIT(13) -}; - - -struct tParticleSystemData -{ - tParticleType m_Type; - char m_aName[20]; - float m_fCreateRange; - float m_fDefaultInitialRadius; - float m_fExpansionRate; - uint16 m_nZRotationInitialAngle; - int16 m_nZRotationAngleChangeAmount; - uint16 m_nZRotationChangeTime; - uint16 m_nZRadiusChangeTime; - float m_fInitialZRadius; - float m_fZRadiusChangeAmount; - int16 m_nFadeToBlackTime; - uint8 m_nFadeToBlackInitialIntensity; - int16 m_nFadeToBlackAmount; - uint8 m_nFadeAlphaInitialIntensity; - int16 m_nFadeAlphaTime; - int16 m_nFadeAlphaAmount; - uint8 m_nStartAnimationFrame; - uint8 m_nFinalAnimationFrame; - uint16 m_nAnimationSpeed; - uint16 m_nRotationSpeed; - float m_fGravitationalAcceleration; - int32 m_nFrictionDecceleration; - int32 m_nLifeSpan; - float m_fPositionRandomError; - float m_fVelocityRandomError; - float m_fExpansionRateError; - int32 m_nRotationRateError; - uint32 m_nLifeSpanErrorShape; - float m_fTrailLengthMultiplier; - uint32 Flags; - CRGBA m_RenderColouring; - uint8 m_InitialColorVariation; - CRGBA m_FadeDestinationColor; - uint32 m_ColorFadeTime; - - CVector2D m_vecTextureStretch; - float m_fWindFactor; - - RwRaster **m_ppRaster; - CParticle *m_pParticles; -}; - -VALIDATE_SIZE(tParticleSystemData, 0x94); - -class cParticleSystemMgr -{ - enum - { - CFG_PARAM_PARTICLE_TYPE_NAME = 0, - CFG_PARAM_RENDER_COLOURING_R, - CFG_PARAM_RENDER_COLOURING_G, - CFG_PARAM_RENDER_COLOURING_B, - CFG_PARAM_INITIAL_COLOR_VARIATION, - CFG_PARAM_FADE_DESTINATION_COLOR_R, - CFG_PARAM_FADE_DESTINATION_COLOR_G, - CFG_PARAM_FADE_DESTINATION_COLOR_B, - CFG_PARAM_COLOR_FADE_TIME, - CFG_PARAM_DEFAULT_INITIAL_RADIUS, - CFG_PARAM_EXPANSION_RATE, - CFG_PARAM_INITIAL_INTENSITY, - CFG_PARAM_FADE_TIME, - CFG_PARAM_FADE_AMOUNT, - CFG_PARAM_INITIAL_ALPHA_INTENSITY, - CFG_PARAM_FADE_ALPHA_TIME, - CFG_PARAM_FADE_ALPHA_AMOUNT, - CFG_PARAM_INITIAL_ANGLE, - CFG_PARAM_CHANGE_TIME, - CFG_PARAM_ANGLE_CHANGE_AMOUNT, - CFG_PARAM_INITIAL_Z_RADIUS, - CFG_PARAM_Z_RADIUS_CHANGE_TIME, - CFG_PARAM_Z_RADIUS_CHANGE_AMOUNT, - CFG_PARAM_ANIMATION_SPEED, - CFG_PARAM_START_ANIMATION_FRAME, - CFG_PARAM_FINAL_ANIMATION_FRAME, - CFG_PARAM_ROTATION_SPEED, - CFG_PARAM_GRAVITATIONAL_ACCELERATION, - CFG_PARAM_FRICTION_DECCELERATION, - CFG_PARAM_LIFE_SPAN, - CFG_PARAM_POSITION_RANDOM_ERROR, - CFG_PARAM_VELOCITY_RANDOM_ERROR, - CFG_PARAM_EXPANSION_RATE_ERROR, - CFG_PARAM_ROTATION_RATE_ERROR, - CFG_PARAM_LIFE_SPAN_ERROR_SHAPE, - CFG_PARAM_TRAIL_LENGTH_MULTIPLIER, - - CFG_PARAM_STRETCH_VALUE_X, - CFG_PARAM_STRETCH_VALUE_Y, - CFG_PARAM_WIND_FACTOR, - - CFG_PARAM_PARTICLE_CREATE_RANGE, - CFG_PARAM_FLAGS, - - MAX_CFG_PARAMS, - CFG_PARAM_FIRST = CFG_PARAM_PARTICLE_TYPE_NAME, - CFG_PARAM_LAST = CFG_PARAM_FLAGS - }; - -public: - tParticleSystemData m_aParticles[MAX_PARTICLES]; - - cParticleSystemMgr(); - - void Initialise(); - void LoadParticleData(); - void RangeCheck(tParticleSystemData *pData) { } -}; - -VALIDATE_SIZE(cParticleSystemMgr, 0x2FFC); - -extern cParticleSystemMgr mod_ParticleSystemManager; diff --git a/src/render/ParticleType.h b/src/render/ParticleType.h deleted file mode 100644 index 9578083d..00000000 --- a/src/render/ParticleType.h +++ /dev/null @@ -1,92 +0,0 @@ -#pragma once - -enum tParticleType -{ - PARTICLE_SPARK = 0, - PARTICLE_SPARK_SMALL, - PARTICLE_WATER_SPARK, - PARTICLE_WHEEL_DIRT, - PARTICLE_SAND, - PARTICLE_WHEEL_WATER, - PARTICLE_BLOOD, - PARTICLE_BLOOD_SMALL, - PARTICLE_BLOOD_SPURT, - PARTICLE_DEBRIS, - PARTICLE_DEBRIS2, - PARTICLE_FLYERS, - PARTICLE_WATER, - PARTICLE_FLAME, - PARTICLE_FIREBALL, - PARTICLE_GUNFLASH, - PARTICLE_GUNFLASH_NOANIM, - PARTICLE_GUNSMOKE, - PARTICLE_GUNSMOKE2, - PARTICLE_CIGARETTE_SMOKE, - PARTICLE_SMOKE, - PARTICLE_SMOKE_SLOWMOTION, - PARTICLE_DRY_ICE, - PARTICLE_TEARGAS, - PARTICLE_GARAGEPAINT_SPRAY, - PARTICLE_SHARD, - PARTICLE_SPLASH, - PARTICLE_CARFLAME, - PARTICLE_STEAM, - PARTICLE_STEAM2, - PARTICLE_STEAM_NY, - PARTICLE_STEAM_NY_SLOWMOTION, - PARTICLE_GROUND_STEAM, - PARTICLE_ENGINE_STEAM, - PARTICLE_RAINDROP, - PARTICLE_RAINDROP_SMALL, - PARTICLE_RAIN_SPLASH, - PARTICLE_RAIN_SPLASH_BIGGROW, - PARTICLE_RAIN_SPLASHUP, - PARTICLE_WATERSPRAY, - PARTICLE_WATERDROP, - PARTICLE_BLOODDROP, - PARTICLE_EXPLOSION_MEDIUM, - PARTICLE_EXPLOSION_LARGE, - PARTICLE_EXPLOSION_MFAST, - PARTICLE_EXPLOSION_LFAST, - PARTICLE_CAR_SPLASH, - PARTICLE_BOAT_SPLASH, - PARTICLE_BOAT_THRUSTJET, - PARTICLE_WATER_HYDRANT, - PARTICLE_WATER_CANNON, - PARTICLE_EXTINGUISH_STEAM, - PARTICLE_PED_SPLASH, - PARTICLE_PEDFOOT_DUST, - PARTICLE_CAR_DUST, - PARTICLE_HELI_DUST, - PARTICLE_HELI_ATTACK, - PARTICLE_ENGINE_SMOKE, - PARTICLE_ENGINE_SMOKE2, - PARTICLE_CARFLAME_SMOKE, - PARTICLE_FIREBALL_SMOKE, - PARTICLE_PAINT_SMOKE, - PARTICLE_TREE_LEAVES, - PARTICLE_CARCOLLISION_DUST, - PARTICLE_CAR_DEBRIS, - PARTICLE_BIRD_DEBRIS, - PARTICLE_HELI_DEBRIS, - PARTICLE_EXHAUST_FUMES, - PARTICLE_RUBBER_SMOKE, - PARTICLE_BURNINGRUBBER_SMOKE, - PARTICLE_BULLETHIT_SMOKE, - PARTICLE_GUNSHELL_FIRST, - PARTICLE_GUNSHELL, - PARTICLE_GUNSHELL_BUMP1, - PARTICLE_GUNSHELL_BUMP2, - PARTICLE_ROCKET_SMOKE, - PARTICLE_TEST, - PARTICLE_BIRD_FRONT, - PARTICLE_SHIP_SIDE, - PARTICLE_BEASTIE, - PARTICLE_RAINDROP_2D, - PARTICLE_HEATHAZE, - PARTICLE_HEATHAZE_IN_DIST, - - MAX_PARTICLES, - PARTICLE_FIRST = PARTICLE_SPARK, - PARTICLE_LAST = PARTICLE_HEATHAZE_IN_DIST -}; \ No newline at end of file diff --git a/src/render/PlayerSkin.cpp b/src/render/PlayerSkin.cpp deleted file mode 100644 index ee944ca7..00000000 --- a/src/render/PlayerSkin.cpp +++ /dev/null @@ -1,164 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "PlayerSkin.h" -#include "TxdStore.h" -#include "rtbmp.h" -#include "ClumpModelInfo.h" -#include "VisibilityPlugins.h" -#include "World.h" -#include "PlayerInfo.h" -#include "CdStream.h" -#include "FileMgr.h" -#include "Directory.h" -#include "RwHelper.h" -#include "Timer.h" -#include "Lights.h" -#include "MemoryMgr.h" - -RpClump *gpPlayerClump; -float gOldFov; - -int CPlayerSkin::m_txdSlot; - -void -FindPlayerDff(uint32 &offset, uint32 &size) -{ - int file; - CDirectory::DirectoryInfo info; - - file = CFileMgr::OpenFile("models\\gta3.dir", "rb"); - - do { - if (!CFileMgr::Read(file, (char*)&info, sizeof(CDirectory::DirectoryInfo))) - return; - } while (strcasecmp("player.dff", info.name) != 0); - - offset = info.offset; - size = info.size; -} - -void -LoadPlayerDff(void) -{ - RwStream *stream; - RwMemory mem; - uint32 offset, size; - uint8 *buffer; - bool streamWasAdded = false; - - if (CdStreamGetNumImages() == 0) { - CdStreamAddImage("models\\gta3.img"); - streamWasAdded = true; - } - - FindPlayerDff(offset, size); - buffer = (uint8*)RwMallocAlign(size << 11, 2048); - CdStreamRead(0, buffer, offset, size); - CdStreamSync(0); - - mem.start = buffer; - mem.length = size << 11; - stream = RwStreamOpen(rwSTREAMMEMORY, rwSTREAMREAD, &mem); - - if (RwStreamFindChunk(stream, rwID_CLUMP, nil, nil)) - gpPlayerClump = RpClumpStreamRead(stream); - - RwStreamClose(stream, &mem); - RwFreeAlign(buffer); - - if (streamWasAdded) - CdStreamRemoveImages(); -} - -void -CPlayerSkin::Initialise(void) -{ - // empty on PS2 - m_txdSlot = CTxdStore::AddTxdSlot("skin"); - CTxdStore::Create(m_txdSlot); - CTxdStore::AddRef(m_txdSlot); -} - -void -CPlayerSkin::Shutdown(void) -{ - // empty on PS2 - CTxdStore::RemoveTxdSlot(m_txdSlot); -} - -RwTexture * -CPlayerSkin::GetSkinTexture(const char *texName) -{ - RwTexture *tex; - RwRaster *raster; - int32 width, height, depth, format; - - CTxdStore::PushCurrentTxd(); - CTxdStore::SetCurrentTxd(m_txdSlot); - tex = RwTextureRead(texName, NULL); - CTxdStore::PopCurrentTxd(); - if (tex != nil) return tex; - - if (strcmp(DEFAULT_SKIN_NAME, texName) == 0 || texName[0] == '\0') - sprintf(gString, "models\\generic\\player.bmp"); - else - sprintf(gString, "skins\\%s.bmp", texName); - - if (RwImage *image = RtBMPImageRead(gString)) { - RwImageFindRasterFormat(image, rwRASTERTYPETEXTURE, &width, &height, &depth, &format); - raster = RwRasterCreate(width, height, depth, format); - RwRasterSetFromImage(raster, image); - - tex = RwTextureCreate(raster); - RwTextureSetName(tex, texName); - RwTextureSetFilterMode(tex, rwFILTERLINEAR); - RwTexDictionaryAddTexture(CTxdStore::GetSlot(m_txdSlot)->texDict, tex); - - RwImageDestroy(image); - } - return tex; -} - -void -CPlayerSkin::BeginFrontendSkinEdit(void) -{ - LoadPlayerDff(); - RpClumpForAllAtomics(gpPlayerClump, CClumpModelInfo::SetAtomicRendererCB, (void*)CVisibilityPlugins::RenderPlayerCB); - CWorld::Players[0].LoadPlayerSkin(); - gOldFov = CDraw::GetFOV(); - CDraw::SetFOV(30.0f); -} - -void -CPlayerSkin::EndFrontendSkinEdit(void) -{ - RpClumpDestroy(gpPlayerClump); - gpPlayerClump = NULL; - CDraw::SetFOV(gOldFov); -} - -void -CPlayerSkin::RenderFrontendSkinEdit(void) -{ - static float rotation = 0.0f; - RwRGBAReal AmbientColor = { 0.65f, 0.65f, 0.65f, 1.0f }; - const RwV3d pos = { 1.35f, 0.35f, 7.725f }; - const RwV3d axis = { 0.0f, 1.0f, 0.0f }; - static uint32 LastFlash = 0; - - RwFrame *frame = RpClumpGetFrame(gpPlayerClump); - - if (CTimer::GetTimeInMillisecondsPauseMode() - LastFlash > 7) { - rotation += 2.0f; - if (rotation > 360.0f) - rotation -= 360.0f; - LastFlash = CTimer::GetTimeInMillisecondsPauseMode(); - } - RwFrameTransform(frame, RwFrameGetMatrix(RwCameraGetFrame(Scene.camera)), rwCOMBINEREPLACE); - RwFrameTranslate(frame, &pos, rwCOMBINEPRECONCAT); - RwFrameRotate(frame, &axis, rotation, rwCOMBINEPRECONCAT); - RwFrameUpdateObjects(frame); - SetAmbientColours(&AmbientColor); - RpClumpRender(gpPlayerClump); -} diff --git a/src/render/PlayerSkin.h b/src/render/PlayerSkin.h deleted file mode 100644 index e0214ce0..00000000 --- a/src/render/PlayerSkin.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#define DEFAULT_SKIN_NAME "$$\"\"" - -class CPlayerSkin -{ - static int m_txdSlot; -public: - static void Initialise(); - static void Shutdown(); - static RwTexture *GetSkinTexture(const char *texName); - static void BeginFrontendSkinEdit(); - static void EndFrontendSkinEdit(); - static void RenderFrontendSkinEdit(); -}; \ No newline at end of file diff --git a/src/render/PointLights.cpp b/src/render/PointLights.cpp deleted file mode 100644 index 13872401..00000000 --- a/src/render/PointLights.cpp +++ /dev/null @@ -1,330 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "CutsceneMgr.h" -#include "Lights.h" -#include "Camera.h" -#include "Weather.h" -#include "World.h" -#include "Collision.h" -#include "Sprite.h" -#include "Timer.h" -#include "PointLights.h" - -int16 CPointLights::NumLights; -CRegisteredPointLight CPointLights::aLights[NUMPOINTLIGHTS]; -CVector CPointLights::aCachedMapReads[32]; -float CPointLights::aCachedMapReadResults[32]; -int32 CPointLights::NextCachedValue; - -void -CPointLights::Init(void) -{ - for(int i = 0; i < ARRAY_SIZE(aCachedMapReads); i++){ - aCachedMapReads[i] = CVector(0.0f, 0.0f, 0.0f); - aCachedMapReadResults[i] = 0.0f; - } - NextCachedValue = 0; -} - -void -CPointLights::InitPerFrame(void) -{ - NumLights = 0; -} - -#define MAX_DIST 22.0f - -void -CPointLights::AddLight(uint8 type, CVector coors, CVector dir, float radius, float red, float green, float blue, uint8 fogType, bool castExtraShadows) -{ - CVector dist; - float distance; - - // The check is done in some weird way in the game - // we're doing it a bit better here - if(NumLights >= NUMPOINTLIGHTS) - return; - - dist = coors - TheCamera.GetPosition(); - if(Abs(dist.x) < MAX_DIST && Abs(dist.y) < MAX_DIST){ - distance = dist.Magnitude(); - if(distance < MAX_DIST){ - aLights[NumLights].type = type; - aLights[NumLights].fogType = fogType; - aLights[NumLights].coors = coors; - aLights[NumLights].dir = dir; - aLights[NumLights].radius = radius; - aLights[NumLights].castExtraShadows = castExtraShadows; - if(distance < MAX_DIST*0.75f){ - aLights[NumLights].red = red; - aLights[NumLights].green = green; - aLights[NumLights].blue = blue; - }else{ - float fade = 1.0f - (distance/MAX_DIST - 0.75f)*4.0f; - aLights[NumLights].red = red * fade; - aLights[NumLights].green = green * fade; - aLights[NumLights].blue = blue * fade; - } - NumLights++; - } - } -} - -float -CPointLights::GenerateLightsAffectingObject(Const CVector *objCoors) -{ - int i; - float ret; - CVector dist; - float radius, distance; - - ret = 1.0f; - for(i = 0; i < NumLights; i++){ - if(aLights[i].type == LIGHT_FOGONLY || aLights[i].type == LIGHT_FOGONLY_ALWAYS) - continue; - - // same weird distance calculation. simplified here - dist = aLights[i].coors - *objCoors; - radius = aLights[i].radius; - if(Abs(dist.x) < radius && - Abs(dist.y) < radius && - Abs(dist.z) < radius){ - - distance = dist.Magnitude(); - if(distance < radius){ - - float distNorm = distance/radius; - if(aLights[i].type == LIGHT_DARKEN){ - // darken the object the closer it is - ret *= distNorm; - }else{ - float intensity; - // distance fade - if(distNorm < 0.5f) - intensity = 1.0f; - else - intensity = 1.0f - (distNorm - 0.5f)/(1.0f - 0.5f); - - if(distance != 0.0f){ - CVector dir = dist / distance; - - if(aLights[i].type == LIGHT_DIRECTIONAL){ - float dot = -DotProduct(dir, aLights[i].dir); - intensity *= Max((dot-0.5f)*2.0f, 0.0f); - } - - if(intensity > 0.0f) - AddAnExtraDirectionalLight(Scene.world, - dir.x, dir.y, dir.z, - aLights[i].red*intensity, aLights[i].green*intensity, aLights[i].blue*intensity); - } - } - } - } - } - - return ret; -} - -extern RwRaster *gpPointlightRaster; - -void -CPointLights::RemoveLightsAffectingObject(void) -{ - RemoveExtraDirectionalLights(Scene.world); -} - -// for directional fog -#define FOG_AREA_LENGTH 12.0f -#define FOG_AREA_WIDTH 5.0f -// for pointlight fog -#define FOG_AREA_RADIUS 9.0f - -float FogSizes[8] = { 1.3f, 2.0f, 1.7f, 2.0f, 1.4f, 2.1f, 1.5f, 2.3f }; - -void -CPointLights::RenderFogEffect(void) -{ - int i; - float fogginess; - CColPoint point; - CEntity *entity; - float xmin, ymin; - float xmax, ymax; - int16 xi, yi; - CVector spriteCoors; - float spritew, spriteh; - - if(CCutsceneMgr::IsRunning()) - return; - - PUSH_RENDERGROUP("CPointLights::RenderFogEffect"); - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpPointlightRaster); - - CSprite::InitSpriteBuffer(); - - for(i = 0; i < NumLights; i++){ - if(aLights[i].fogType != FOG_NORMAL && aLights[i].fogType != FOG_ALWAYS) - continue; - - fogginess = aLights[i].fogType == FOG_NORMAL ? CWeather::Foggyness : 1.0f; - if(fogginess == 0.0f) - continue; - - if(aLights[i].type == LIGHT_DIRECTIONAL){ - - // TODO: test this. haven't found directional fog so far - - float coors2X = aLights[i].coors.x + FOG_AREA_LENGTH*aLights[i].dir.x; - float coors2Y = aLights[i].coors.y + FOG_AREA_LENGTH*aLights[i].dir.y; - - if(coors2X < aLights[i].coors.x){ - xmin = coors2X; - xmax = aLights[i].coors.x; - }else{ - xmax = coors2X; - xmin = aLights[i].coors.x; - } - if(coors2Y < aLights[i].coors.y){ - ymin = coors2Y; - ymax = aLights[i].coors.y; - }else{ - ymax = coors2Y; - ymin = aLights[i].coors.y; - } - - xmin -= 5.0f; - ymin -= 5.0f; - xmax += 5.0f; - ymax += 5.0f; - - for(xi = (int16)xmin - (int16)xmin % 4; xi <= (int16)xmax + 4; xi += 4){ - for(yi = (int16)ymin - (int16)ymin % 4; yi <= (int16)ymax + 4; yi += 4){ - // Some kind of pseudo random number? - int r = (xi ^ yi)>>2 & 0xF; - if((r & 1) == 0) - continue; - - // Check if fog effect is close enough to directional line in x and y - float dx = xi - aLights[i].coors.x; - float dy = yi - aLights[i].coors.y; - float dot = dx*aLights[i].dir.x + dy*aLights[i].dir.y; - float distsq = sq(dx) + sq(dy); - float linedistsq = distsq - sq(dot); - if(dot > 0.0f && dot < FOG_AREA_LENGTH && linedistsq < sq(FOG_AREA_WIDTH)){ - CVector fogcoors(xi, yi, aLights[i].coors.z + 10.0f); - if(CWorld::ProcessVerticalLine(fogcoors, fogcoors.z - 20.0f, - point, entity, true, false, false, false, true, false, nil)){ - // Now same check again in xyz - fogcoors.z = point.point.z + 1.3f; - // actually we don't have to recalculate x and y, but the game does it that way - dx = xi - aLights[i].coors.x; - dy = yi - aLights[i].coors.y; - float dz = fogcoors.z - aLights[i].coors.z; - dot = dx*aLights[i].dir.x + dy*aLights[i].dir.y + dz*aLights[i].dir.z; - distsq = sq(dx) + sq(dy) + sq(dz); - linedistsq = distsq - sq(dot); - if(dot > 0.0f && dot < FOG_AREA_LENGTH && linedistsq < sq(FOG_AREA_WIDTH)){ - float intensity = 158.0f * fogginess; - // more intensity the smaller the angle - intensity *= dot/Sqrt(distsq); - // more intensity the closer to light source - intensity *= 1.0f - sq(dot/FOG_AREA_LENGTH); - // more intensity the closer to line - intensity *= 1.0f - sq(Sqrt(linedistsq) / FOG_AREA_WIDTH); - - if(CSprite::CalcScreenCoors(fogcoors, &spriteCoors, &spritew, &spriteh, true)) { - float rotation = (CTimer::GetTimeInMilliseconds()&0x1FFF) * 2*3.14f / 0x2000; - float size = FogSizes[r>>1]; - CSprite::RenderBufferedOneXLUSprite_Rotate_Aspect(spriteCoors.x, spriteCoors.y, spriteCoors.z, - spritew * size, spriteh * size, - aLights[i].red * intensity, aLights[i].green * intensity, aLights[i].blue * intensity, - intensity, 1/spriteCoors.z, rotation, 255); - } - } - } - } - } - } - - }else if(aLights[i].type == LIGHT_POINT || aLights[i].type == LIGHT_FOGONLY || aLights[i].type == LIGHT_FOGONLY_ALWAYS){ - float groundZ; - if(ProcessVerticalLineUsingCache(aLights[i].coors, &groundZ)){ - xmin = aLights[i].coors.x - FOG_AREA_RADIUS; - ymin = aLights[i].coors.y - FOG_AREA_RADIUS; - xmax = aLights[i].coors.x + FOG_AREA_RADIUS; - ymax = aLights[i].coors.y + FOG_AREA_RADIUS; - - for(xi = (int16)xmin - (int16)xmin % 2; xi <= (int16)xmax + 2; xi += 2){ - for(yi = (int16)ymin - (int16)ymin % 2; yi <= (int16)ymax + 2; yi += 2){ - // Some kind of pseudo random number? - int r = (xi ^ yi)>>1 & 0xF; - if((r & 1) == 0) - continue; - - float dx = xi - aLights[i].coors.x; - float dy = yi - aLights[i].coors.y; - float lightdist = Sqrt(sq(dx) + sq(dy)); - if(lightdist < FOG_AREA_RADIUS){ - dx = xi - TheCamera.GetPosition().x; - dy = yi - TheCamera.GetPosition().y; - float camdist = Sqrt(sq(dx) + sq(dy)); - if(camdist < MAX_DIST){ - float intensity; - // distance fade - if(camdist < MAX_DIST/2) - intensity = 1.0f; - else - intensity = 1.0f - (camdist - MAX_DIST/2) / (MAX_DIST/2); - intensity *= 132.0f * fogginess; - // more intensity the closer to light source - intensity *= 1.0f - sq(lightdist / FOG_AREA_RADIUS); - - CVector fogcoors(xi, yi, groundZ + 1.6f); - if(CSprite::CalcScreenCoors(fogcoors, &spriteCoors, &spritew, &spriteh, true)) { - float rotation = (CTimer::GetTimeInMilliseconds()&0x3FFF) * 2*3.14f / 0x4000; - float size = FogSizes[r>>1]; - CSprite::RenderBufferedOneXLUSprite_Rotate_Aspect(spriteCoors.x, spriteCoors.y, spriteCoors.z, - spritew * size, spriteh * size, - aLights[i].red * intensity, aLights[i].green * intensity, aLights[i].blue * intensity, - intensity, 1/spriteCoors.z, rotation, 255); - } - } - } - } - } - } - } - } - - CSprite::FlushSpriteBuffer(); - - POP_RENDERGROUP(); -} - -bool -CPointLights::ProcessVerticalLineUsingCache(CVector coors, float *groundZ) -{ - for(int i = 0; i < ARRAY_SIZE(aCachedMapReads); i++) - if(aCachedMapReads[i] == coors){ - *groundZ = aCachedMapReadResults[i]; - return true; - } - - CColPoint point; - CEntity *entity; - if(CWorld::ProcessVerticalLine(coors, coors.z - 20.0f, point, entity, true, false, false, false, true, false, nil)){ - aCachedMapReads[NextCachedValue] = coors; - aCachedMapReadResults[NextCachedValue] = point.point.z; - NextCachedValue = (NextCachedValue+1) % ARRAY_SIZE(aCachedMapReads); - *groundZ = point.point.z; - return true; - } - return false; -} diff --git a/src/render/PointLights.h b/src/render/PointLights.h deleted file mode 100644 index 827200b9..00000000 --- a/src/render/PointLights.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -class CRegisteredPointLight -{ -public: - CVector coors; - CVector dir; - float radius; - float red; - float green; - float blue; - int8 type; - int8 fogType; - bool castExtraShadows; -}; -VALIDATE_SIZE(CRegisteredPointLight, 0x2C); - -class CPointLights -{ -public: - static int16 NumLights; - static CRegisteredPointLight aLights[NUMPOINTLIGHTS]; - static CVector aCachedMapReads[32]; - static float aCachedMapReadResults[32]; - static int32 NextCachedValue; - - enum { - LIGHT_POINT, - LIGHT_DIRECTIONAL, - LIGHT_DARKEN, // no effects at all - // these have only fog, otherwise no difference? - // only used by CEntity::ProcessLightsForEntity it seems - // and there used together with fog type - LIGHT_FOGONLY_ALWAYS, - LIGHT_FOGONLY, - }; - enum { - FOG_NONE, - FOG_NORMAL, // taken from Foggyness - FOG_ALWAYS - }; - - static void Init(void); - static void InitPerFrame(void); - static void AddLight(uint8 type, CVector coors, CVector dir, float radius, float red, float green, float blue, uint8 fogType, bool castExtraShadows); - static float GenerateLightsAffectingObject(Const CVector *objCoors); - static void RemoveLightsAffectingObject(void); - static void RenderFogEffect(void); - static bool ProcessVerticalLineUsingCache(CVector coors, float *groundZ); -}; diff --git a/src/render/RenderBuffer.cpp b/src/render/RenderBuffer.cpp deleted file mode 100644 index 687cc76b..00000000 --- a/src/render/RenderBuffer.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "common.h" - -#include "RenderBuffer.h" - -int32 TempBufferVerticesStored; -int32 TempBufferIndicesStored; - -VertexBufferUnion TempVertexBuffer; -RwImVertexIndex TempBufferRenderIndexList[TEMPBUFFERINDEXSIZE]; - -int RenderBuffer::VerticesToBeStored; -int RenderBuffer::IndicesToBeStored; - -void -RenderBuffer::ClearRenderBuffer(void) -{ - TempBufferVerticesStored = 0; - TempBufferIndicesStored = 0; -} - -void -RenderBuffer::StartStoring(int numIndices, int numVertices, RwImVertexIndex **indexStart, RwIm3DVertex **vertexStart) -{ - if(TempBufferIndicesStored + numIndices >= TEMPBUFFERINDEXSIZE) - RenderStuffInBuffer(); - if(TempBufferVerticesStored + numVertices >= TEMPBUFFERVERTSIZE) - RenderStuffInBuffer(); - *indexStart = &TempBufferRenderIndexList[TempBufferIndicesStored]; - *vertexStart = &TempBufferRenderVertices[TempBufferVerticesStored]; - IndicesToBeStored = numIndices; - VerticesToBeStored = numVertices; -} - -void -RenderBuffer::StopStoring(void) -{ - int i; - for(i = TempBufferIndicesStored; i < TempBufferIndicesStored+IndicesToBeStored; i++) - TempBufferRenderIndexList[i] += TempBufferVerticesStored; - TempBufferIndicesStored += IndicesToBeStored; - TempBufferVerticesStored += VerticesToBeStored; -} - -void -RenderBuffer::RenderStuffInBuffer(void) -{ - if(TempBufferVerticesStored && RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV)){ - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); - RwIm3DEnd(); - } - ClearRenderBuffer(); -} diff --git a/src/render/RenderBuffer.h b/src/render/RenderBuffer.h deleted file mode 100644 index a0f3e7b9..00000000 --- a/src/render/RenderBuffer.h +++ /dev/null @@ -1,25 +0,0 @@ -class RenderBuffer -{ -public: - static int VerticesToBeStored; - static int IndicesToBeStored; - static void ClearRenderBuffer(void); - static void StartStoring(int numIndices, int numVertices, RwImVertexIndex **indexStart, RwIm3DVertex **vertexStart); - static void StopStoring(void); - static void RenderStuffInBuffer(void); -}; - -#define TEMPBUFFERVERTSIZE 512 -#define TEMPBUFFERINDEXSIZE 1024 - -struct VertexBufferUnion -{ - RwIm2DVertex im2d[TEMPBUFFERVERTSIZE]; - RwIm3DVertex im3d[TEMPBUFFERVERTSIZE]; -}; - -extern int32 TempBufferVerticesStored; -extern int32 TempBufferIndicesStored; -extern VertexBufferUnion TempVertexBuffer; -#define TempBufferRenderVertices (TempVertexBuffer.im3d) -extern RwImVertexIndex TempBufferRenderIndexList[TEMPBUFFERINDEXSIZE]; \ No newline at end of file diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp deleted file mode 100644 index 6b306b6c..00000000 --- a/src/render/Renderer.cpp +++ /dev/null @@ -1,1675 +0,0 @@ -#define WITHD3D -#include "common.h" - -#include "main.h" -#include "Lights.h" -#include "ModelInfo.h" -#include "Treadable.h" -#include "Ped.h" -#include "Vehicle.h" -#include "Boat.h" -#include "Heli.h" -#include "Bike.h" -#include "Object.h" -#include "PathFind.h" -#include "Collision.h" -#include "VisibilityPlugins.h" -#include "Clock.h" -#include "World.h" -#include "Camera.h" -#include "ModelIndices.h" -#include "Streaming.h" -#include "Shadows.h" -#include "PointLights.h" -#include "Occlusion.h" -#include "Renderer.h" -#include "custompipes.h" -#include "Frontend.h" - -bool gbShowPedRoadGroups; -bool gbShowCarRoadGroups; -bool gbShowCollisionPolys; -bool gbShowCollisionLines; -bool gbBigWhiteDebugLightSwitchedOn; - -bool gbDontRenderBuildings; -bool gbDontRenderBigBuildings; -bool gbDontRenderPeds; -bool gbDontRenderObjects; -bool gbDontRenderVehicles; - -// unused -int16 TestCloseThings; -int16 TestBigThings; - -struct EntityInfo -{ - CEntity *ent; - float sort; -}; - -CLinkList gSortedVehiclesAndPeds; - -int32 CRenderer::ms_nNoOfVisibleEntities; -CEntity *CRenderer::ms_aVisibleEntityPtrs[NUMVISIBLEENTITIES]; -CEntity *CRenderer::ms_aInVisibleEntityPtrs[NUMINVISIBLEENTITIES]; -int32 CRenderer::ms_nNoOfInVisibleEntities; -#ifdef NEW_RENDERER -int32 CRenderer::ms_nNoOfVisibleVehicles; -CEntity *CRenderer::ms_aVisibleVehiclePtrs[NUMVISIBLEENTITIES]; -int32 CRenderer::ms_nNoOfVisibleBuildings; -CEntity *CRenderer::ms_aVisibleBuildingPtrs[NUMVISIBLEENTITIES]; -#endif - -CVector CRenderer::ms_vecCameraPosition; -CVehicle *CRenderer::m_pFirstPersonVehicle; -bool CRenderer::m_loadingPriority; -float CRenderer::ms_lodDistScale = 1.2f; - -// unused -BlockedRange CRenderer::aBlockedRanges[16]; -BlockedRange* CRenderer::pFullBlockedRanges; -BlockedRange* CRenderer::pEmptyBlockedRanges; - -void -CRenderer::Init(void) -{ - gSortedVehiclesAndPeds.Init(40); - SortBIGBuildings(); -} - -void -CRenderer::Shutdown(void) -{ - gSortedVehiclesAndPeds.Shutdown(); -} - -void -CRenderer::PreRender(void) -{ - int i; - CLink *node; - - for(i = 0; i < ms_nNoOfVisibleEntities; i++) - ms_aVisibleEntityPtrs[i]->PreRender(); - -#ifdef NEW_RENDERER - if(gbNewRenderer){ - for(i = 0; i < ms_nNoOfVisibleVehicles; i++) - ms_aVisibleVehiclePtrs[i]->PreRender(); - // How is this done with cWorldStream? - for(i = 0; i < ms_nNoOfVisibleBuildings; i++) - ms_aVisibleBuildingPtrs[i]->PreRender(); - for(node = CVisibilityPlugins::m_alphaBuildingList.head.next; - node != &CVisibilityPlugins::m_alphaBuildingList.tail; - node = node->next) - ((CEntity*)node->item.entity)->PreRender(); - } -#endif - - for (i = 0; i < ms_nNoOfInVisibleEntities; i++) { -#ifdef SQUEEZE_PERFORMANCE - if (ms_aInVisibleEntityPtrs[i]->IsVehicle() && ((CVehicle*)ms_aInVisibleEntityPtrs[i])->IsHeli()) -#endif - ms_aInVisibleEntityPtrs[i]->PreRender(); - } - - for(node = CVisibilityPlugins::m_alphaEntityList.head.next; - node != &CVisibilityPlugins::m_alphaEntityList.tail; - node = node->next) - ((CEntity*)node->item.entity)->PreRender(); - - CHeli::SpecialHeliPreRender(); - CShadows::RenderExtraPlayerShadows(); -} - -void -CRenderer::RenderOneRoad(CEntity *e) -{ - if(gbDontRenderBuildings) - return; - if(gbShowCollisionPolys) - CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(), e->GetModelIndex()); - else{ - PUSH_RENDERGROUP(CModelInfo::GetModelInfo(e->GetModelIndex())->GetModelName()); - - e->Render(); - - POP_RENDERGROUP(); - } -} - -void -CRenderer::RenderOneNonRoad(CEntity *e) -{ - CPed *ped; - CVehicle *veh; - int i; - bool resetLights; - -#ifndef MASTER - if(gbShowCollisionPolys){ - if(!e->IsVehicle()){ - CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(), e->GetModelIndex()); - return; - } - }else if(e->IsBuilding()){ - if(e->bIsBIGBuilding){ - if(gbDontRenderBigBuildings) - return; - }else{ - if(gbDontRenderBuildings) - return; - } - }else -#endif - if(e->IsPed()){ -#ifndef MASTER - if(gbDontRenderPeds) - return; -#endif - ped = (CPed*)e; - if(ped->m_nPedState == PED_DRIVING) - return; - } -#ifndef MASTER - else if(e->IsObject() || e->IsDummy()){ - if(gbDontRenderObjects) - return; - }else if(e->IsVehicle()){ - // re3 addition - if(gbDontRenderVehicles) - return; - } -#endif - - PUSH_RENDERGROUP(CModelInfo::GetModelInfo(e->GetModelIndex())->GetModelName()); - - resetLights = e->SetupLighting(); - - if(e->IsVehicle()){ - // unfortunately can't use GetClump here - CVisibilityPlugins::SetupVehicleVariables((RpClump*)e->m_rwObject); - CVisibilityPlugins::InitAlphaAtomicList(); - } - - // Render Peds in vehicle before vehicle itself - if(e->IsVehicle()){ - veh = (CVehicle*)e; - if(veh->pDriver && veh->pDriver->m_nPedState == PED_DRIVING) - veh->pDriver->Render(); - for(i = 0; i < 8; i++) - if(veh->pPassengers[i] && veh->pPassengers[i]->m_nPedState == PED_DRIVING) - veh->pPassengers[i]->Render(); - SetCullMode(rwCULLMODECULLNONE); - } - e->Render(); - - if(e->IsVehicle()){ - e->bImBeingRendered = true; - CVisibilityPlugins::RenderAlphaAtomics(); - e->bImBeingRendered = false; - SetCullMode(rwCULLMODECULLBACK); - } - - e->RemoveLighting(resetLights); - - POP_RENDERGROUP(); -} - -void -CRenderer::RenderFirstPersonVehicle(void) -{ - if(m_pFirstPersonVehicle == nil) - return; - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RenderOneNonRoad(m_pFirstPersonVehicle); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); -} - -inline bool IsRoad(CEntity *e) { return e->IsBuilding() && ((CSimpleModelInfo*)CModelInfo::GetModelInfo(e->GetModelIndex()))->m_wetRoadReflection; } - -void -CRenderer::RenderRoads(void) -{ - int i; - CEntity *e; - - PUSH_RENDERGROUP("CRenderer::RenderRoads"); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - SetCullMode(rwCULLMODECULLBACK); - DeActivateDirectional(); - SetAmbientColours(); - - for(i = 0; i < ms_nNoOfVisibleEntities; i++){ - e = ms_aVisibleEntityPtrs[i]; - if(IsRoad(e)) - RenderOneRoad(e); - } - POP_RENDERGROUP(); -} - -inline bool PutIntoSortedVehicleList(CVehicle *veh) -{ - if(veh->IsBoat()){ - int mode = TheCamera.Cams[TheCamera.ActiveCam].Mode; - if(mode == CCam::MODE_WHEELCAM || - mode == CCam::MODE_1STPERSON && TheCamera.GetLookDirection() != LOOKING_FORWARD && TheCamera.GetLookDirection() != LOOKING_BEHIND || - CVisibilityPlugins::GetClumpAlpha(veh->GetClump()) != 255) - return false; - return true; - }else - return veh->bTouchingWater; -} - -void -CRenderer::RenderEverythingBarRoads(void) -{ - int i; - CEntity *e; - EntityInfo ei; - - PUSH_RENDERGROUP("CRenderer::RenderEverythingBarRoads"); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - SetCullMode(rwCULLMODECULLBACK); - gSortedVehiclesAndPeds.Clear(); - - for(i = 0; i < ms_nNoOfVisibleEntities; i++){ - e = ms_aVisibleEntityPtrs[i]; - - if(IsRoad(e)) - continue; - -#ifdef EXTENDED_PIPELINES - if(CustomPipes::bRenderingEnvMap && (e->IsPed() || e->IsVehicle())) - continue; -#endif - - if(e->IsVehicle() || - e->IsPed() && CVisibilityPlugins::GetClumpAlpha((RpClump*)e->m_rwObject) != 255){ - if(e->IsVehicle() && PutIntoSortedVehicleList((CVehicle*)e)){ - ei.ent = e; - ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr(); - gSortedVehiclesAndPeds.InsertSorted(ei); - }else{ - if(!CVisibilityPlugins::InsertEntityIntoSortedList(e, (ms_vecCameraPosition - e->GetPosition()).Magnitude())){ - printf("Ran out of space in alpha entity list"); - RenderOneNonRoad(e); - } - } - }else - RenderOneNonRoad(e); - } - POP_RENDERGROUP(); -} - -void -CRenderer::RenderBoats(void) -{ - CLink *node; - - PUSH_RENDERGROUP("CRenderer::RenderBoats"); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - SetCullMode(rwCULLMODECULLBACK); - -#ifdef NEW_RENDERER - int i; - CEntity *e; - EntityInfo ei; - if(gbNewRenderer){ - gSortedVehiclesAndPeds.Clear(); - // not the real thing - for(i = 0; i < ms_nNoOfVisibleVehicles; i++){ - e = ms_aVisibleVehiclePtrs[i]; - if(e->IsVehicle() && PutIntoSortedVehicleList((CVehicle*)e)){ - ei.ent = e; - ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr(); - gSortedVehiclesAndPeds.InsertSorted(ei); - } - } - } -#endif - - for(node = gSortedVehiclesAndPeds.tail.prev; - node != &gSortedVehiclesAndPeds.head; - node = node->prev){ - CVehicle *v = (CVehicle*)node->item.ent; - RenderOneNonRoad(v); - } - POP_RENDERGROUP(); -} - -#ifdef NEW_RENDERER -#ifndef LIBRW -#error "Need librw for EXTENDED_PIPELINES" -#endif -#include "WaterLevel.h" - -enum { - // blend passes - PASS_NOZ, // no z-write - PASS_ADD, // additive - PASS_BLEND // normal blend -}; - -static void -SetStencilState(int state) -{ - switch(state){ - // disable stencil - case 0: - rw::SetRenderState(rw::STENCILENABLE, FALSE); - break; - // test against stencil - case 1: - rw::SetRenderState(rw::STENCILENABLE, TRUE); - rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILNOTEQUAL); - rw::SetRenderState(rw::STENCILPASS, rw::STENCILKEEP); - rw::SetRenderState(rw::STENCILFAIL, rw::STENCILKEEP); - rw::SetRenderState(rw::STENCILZFAIL, rw::STENCILKEEP); - rw::SetRenderState(rw::STENCILFUNCTIONMASK, 0xFF); - rw::SetRenderState(rw::STENCILFUNCTIONREF, 0xFF); - break; - // write to stencil - case 2: - rw::SetRenderState(rw::STENCILENABLE, TRUE); - rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILALWAYS); - rw::SetRenderState(rw::STENCILPASS, rw::STENCILREPLACE); - rw::SetRenderState(rw::STENCILFUNCTIONREF, 0xFF); - break; - } -} - -void -CRenderer::RenderOneBuilding(CEntity *ent, float camdist) -{ - if(ent->m_rwObject == nil) - return; - - ent->bImBeingRendered = true; // TODO: this seems wrong, but do we even need it? - - assert(RwObjectGetType(ent->m_rwObject) == rpATOMIC); - RpAtomic *atomic = (RpAtomic*)ent->m_rwObject; - CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(ent->GetModelIndex()); - - int pass = PASS_BLEND; - if(mi->m_additive) // very questionable - pass = PASS_ADD; - if(mi->m_noZwrite) - pass = PASS_NOZ; - - if(ent->bDistanceFade){ - RpAtomic *lodatm; - float fadefactor; - uint32 alpha; - - lodatm = mi->GetAtomicFromDistance(camdist - FADE_DISTANCE); - fadefactor = (mi->GetLargestLodDistance() - (camdist - FADE_DISTANCE))/FADE_DISTANCE; - if(fadefactor > 1.0f) - fadefactor = 1.0f; - alpha = mi->m_alpha * fadefactor; - - if(alpha == 255) - WorldRender::AtomicFirstPass(atomic, pass); - else{ - // not quite sure what this is about, do we have to do that? - RpGeometry *geo = RpAtomicGetGeometry(lodatm); - if(geo != RpAtomicGetGeometry(atomic)) - RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE); - WorldRender::AtomicFullyTransparent(atomic, pass, alpha); - } - }else - WorldRender::AtomicFirstPass(atomic, pass); - - ent->bImBeingRendered = false; // TODO: this seems wrong, but do we even need it? -} - -void -CRenderer::RenderWorld(int pass) -{ - int i; - CEntity *e; - CLink *node; - - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); - SetCullMode(rwCULLMODECULLBACK); - DeActivateDirectional(); - SetAmbientColours(); - - // Temporary...have to figure out sorting better - switch(pass){ - case 0: - // Roads - PUSH_RENDERGROUP("CRenderer::RenderWorld - Roads"); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - for(i = 0; i < ms_nNoOfVisibleBuildings; i++){ - e = ms_aVisibleBuildingPtrs[i]; - if(e->bIsBIGBuilding || IsRoad(e)) - RenderOneBuilding(e); - } - for(node = CVisibilityPlugins::m_alphaBuildingList.tail.prev; - node != &CVisibilityPlugins::m_alphaBuildingList.head; - node = node->prev){ - e = node->item.entity; - if(e->bIsBIGBuilding || IsRoad(e)) - RenderOneBuilding(e, node->item.sort); - } - POP_RENDERGROUP(); - break; - case 1: - // Opaque - PUSH_RENDERGROUP("CRenderer::RenderWorld - Opaque"); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - for(i = 0; i < ms_nNoOfVisibleBuildings; i++){ - e = ms_aVisibleBuildingPtrs[i]; - if(!(e->bIsBIGBuilding || IsRoad(e))) - RenderOneBuilding(e); - } - for(node = CVisibilityPlugins::m_alphaBuildingList.tail.prev; - node != &CVisibilityPlugins::m_alphaBuildingList.head; - node = node->prev){ - e = node->item.entity; - if(!(e->bIsBIGBuilding || IsRoad(e))) - RenderOneBuilding(e, node->item.sort); - } - // Now we have iterated through all visible buildings (unsorted and sorted) - // and the transparency list is done. - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); - WorldRender::RenderBlendPass(PASS_NOZ); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - POP_RENDERGROUP(); - break; - case 2: - // Transparent - PUSH_RENDERGROUP("CRenderer::RenderWorld - Transparent"); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - WorldRender::RenderBlendPass(PASS_ADD); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - WorldRender::RenderBlendPass(PASS_BLEND); - POP_RENDERGROUP(); - break; - } -} - -void -CRenderer::RenderPeds(void) -{ - int i; - CEntity *e; - - PUSH_RENDERGROUP("CRenderer::RenderPeds"); - for(i = 0; i < ms_nNoOfVisibleVehicles; i++){ - e = ms_aVisibleVehiclePtrs[i]; - if(e->IsPed()) - RenderOneNonRoad(e); - } - POP_RENDERGROUP(); -} - -void -CRenderer::RenderVehicles(void) -{ - int i; - CEntity *e; - EntityInfo ei; - CLink *node; - - PUSH_RENDERGROUP("CRenderer::RenderVehicles"); - // not the real thing - for(i = 0; i < ms_nNoOfVisibleVehicles; i++){ - e = ms_aVisibleVehiclePtrs[i]; - if(!e->IsVehicle()) - continue; - if(PutIntoSortedVehicleList((CVehicle*)e)) - continue; // boats handled elsewhere - ei.ent = e; - ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr(); - gSortedVehiclesAndPeds.InsertSorted(ei); - } - - for(node = gSortedVehiclesAndPeds.tail.prev; - node != &gSortedVehiclesAndPeds.head; - node = node->prev) - RenderOneNonRoad(node->item.ent); - POP_RENDERGROUP(); -} - -void -CRenderer::RenderTransparentWater(void) -{ - int i; - CEntity *e; - - PUSH_RENDERGROUP("CRenderer::RenderTransparentWater"); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDZERO); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - SetStencilState(2); - - for(i = 0; i < ms_nNoOfVisibleVehicles; i++){ - e = ms_aVisibleVehiclePtrs[i]; - if(e->IsVehicle() && ((CVehicle*)e)->IsBoat()) - ((CBoat*)e)->RenderWaterOutPolys(); - } - - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - SetStencilState(1); - - CWaterLevel::RenderTransparentWater(); - - SetStencilState(0); - POP_RENDERGROUP(); -} - -void -CRenderer::ClearForFrame(void) -{ - ms_nNoOfVisibleEntities = 0; - ms_nNoOfVisibleVehicles = 0; - ms_nNoOfVisibleBuildings = 0; - ms_nNoOfInVisibleEntities = 0; - gSortedVehiclesAndPeds.Clear(); - - WorldRender::numBlendInsts[PASS_NOZ] = 0; - WorldRender::numBlendInsts[PASS_ADD] = 0; - WorldRender::numBlendInsts[PASS_BLEND] = 0; -} -#endif - -void -CRenderer::RenderFadingInEntities(void) -{ - PUSH_RENDERGROUP("CRenderer::RenderFadingInEntities"); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - SetCullMode(rwCULLMODECULLBACK); - DeActivateDirectional(); - SetAmbientColours(); - CVisibilityPlugins::RenderFadingEntities(); - POP_RENDERGROUP(); -} - -void -CRenderer::RenderFadingInUnderwaterEntities(void) -{ - PUSH_RENDERGROUP("CRenderer::RenderFadingInUnderwaterEntities"); - DeActivateDirectional(); - SetAmbientColours(); - CVisibilityPlugins::RenderFadingUnderwaterEntities(); - POP_RENDERGROUP(); -} - -void -CRenderer::RenderCollisionLines(void) -{ - int i; - - // game doesn't draw fading in entities - // this should probably be fixed - for(i = 0; i < ms_nNoOfVisibleEntities; i++){ - CEntity *e = ms_aVisibleEntityPtrs[i]; - if(Abs(e->GetPosition().x - ms_vecCameraPosition.x) < 100.0f && - Abs(e->GetPosition().y - ms_vecCameraPosition.y) < 100.0f) - CCollision::DrawColModel(e->GetMatrix(), *e->GetColModel()); - } -} - -enum Visbility -{ - VIS_INVISIBLE, - VIS_VISIBLE, - VIS_OFFSCREEN, - VIS_STREAMME -}; - -// Time Objects can be time culled if -// other == -1 || CModelInfo::GetModelInfo(other)->GetRwObject() -// i.e. we have to draw even at the wrong time if -// other != -1 && CModelInfo::GetModelInfo(other)->GetRwObject() == nil - -#define OTHERUNAVAILABLE (other != -1 && CModelInfo::GetModelInfo(other)->GetRwObject() == nil) -#define CANTIMECULL (!OTHERUNAVAILABLE) - -int32 -CRenderer::SetupEntityVisibility(CEntity *ent) -{ - CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(ent->m_modelIndex); - CTimeModelInfo *ti; - int32 other; - float dist; - - bool request = true; - if(mi->GetModelType() == MITYPE_TIME){ - ti = (CTimeModelInfo*)mi; - other = ti->GetOtherTimeModel(); - if(CClock::GetIsTimeInRange(ti->GetTimeOn(), ti->GetTimeOff())){ - // don't fade in, or between time objects - if(CANTIMECULL) - ti->m_alpha = 255; - }else{ - // Hide if possible - if(CANTIMECULL) - return VIS_INVISIBLE; - // can't cull, so we'll try to draw this one, but don't request - // it since what we really want is the other one. - request = false; - } - }else{ - if(mi->GetModelType() != MITYPE_SIMPLE && mi->GetModelType() != MITYPE_WEAPON){ - if(FindPlayerVehicle() == ent && - TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_1STPERSON && - !(FindPlayerVehicle()->IsBike() && ((CBike*)FindPlayerVehicle())->bWheelieCam)){ - // Player's vehicle in first person mode - CVehicle *veh = (CVehicle*)ent; - int model = veh->GetModelIndex(); - int direction = TheCamera.Cams[TheCamera.ActiveCam].DirectionWasLooking; - if(direction == LOOKING_FORWARD || - ent->GetModelIndex() == MI_RHINO || - ent->GetModelIndex() == MI_COACH || - TheCamera.m_bInATunnelAndABigVehicle || - direction == LOOKING_BEHIND && veh->pHandling->Flags & HANDLING_UNKNOWN){ - ent->bNoBrightHeadLights = true; - return VIS_OFFSCREEN; - } - - if(direction != LOOKING_BEHIND || - !veh->IsBoat() || model == MI_REEFER || model == MI_TROPIC || model == MI_PREDATOR || model == MI_SKIMMER){ - m_pFirstPersonVehicle = (CVehicle*)ent; - ent->bNoBrightHeadLights = false; - return VIS_OFFSCREEN; - } - } - - // All sorts of Clumps - if(ent->m_rwObject == nil || !ent->bIsVisible) - return VIS_INVISIBLE; - if(!ent->GetIsOnScreen() || ent->IsEntityOccluded()) - return VIS_OFFSCREEN; - if(ent->bDrawLast){ - dist = (ent->GetPosition() - ms_vecCameraPosition).Magnitude(); - CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); - ent->bDistanceFade = false; - return VIS_INVISIBLE; - } - return VIS_VISIBLE; - } - if(ent->bDontStream){ - if(ent->m_rwObject == nil || !ent->bIsVisible) - return VIS_INVISIBLE; - if(!ent->GetIsOnScreen() || ent->IsEntityOccluded()) - return VIS_OFFSCREEN; - if(ent->bDrawLast){ - dist = (ent->GetPosition() - ms_vecCameraPosition).Magnitude(); - CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); - ent->bDistanceFade = false; - return VIS_INVISIBLE; - } - return VIS_VISIBLE; - } - } - - // Simple ModelInfo - - if(!IsAreaVisible(ent->m_area)) - return VIS_INVISIBLE; - - dist = (ent->GetPosition() - ms_vecCameraPosition).Magnitude(); - -#ifndef FIX_BUGS - // Whatever this is supposed to do, it breaks fading for objects - // whose draw dist is > LOD_DISTANCE-FADE_DISTANCE, i.e. 280 - // because decreasing dist here makes the object visible above LOD_DISTANCE - // before fading normally once below LOD_DISTANCE. - // aha! this must be a workaround for the fact that we're not taking - // the LOD multiplier into account here anywhere - if(LOD_DISTANCE < dist && dist < mi->GetLargestLodDistance() + FADE_DISTANCE) - dist += mi->GetLargestLodDistance() - LOD_DISTANCE; -#endif - - if(ent->IsObject() && ent->bRenderDamaged) - mi->m_isDamaged = true; - - RpAtomic *a = mi->GetAtomicFromDistance(dist); - if(a){ - mi->m_isDamaged = false; - if(ent->m_rwObject == nil) - ent->CreateRwObject(); - assert(ent->m_rwObject); - RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject; - // Make sure our atomic uses the right geometry and not - // that of an atomic for another draw distance. - if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj)) - RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?) - mi->IncreaseAlpha(); - if(ent->m_rwObject == nil || !ent->bIsVisible) - return VIS_INVISIBLE; - - if(!ent->GetIsOnScreen() || ent->IsEntityOccluded()){ - mi->m_alpha = 255; - return VIS_OFFSCREEN; - } - - if(mi->m_alpha != 255){ - CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); - ent->bDistanceFade = true; - return VIS_INVISIBLE; - } - - if(mi->m_drawLast || ent->bDrawLast){ - if(CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist)){ - ent->bDistanceFade = false; - return VIS_INVISIBLE; - } - } - return VIS_VISIBLE; - } - - // Object is not loaded, figure out what to do - - if(mi->m_noFade){ - mi->m_isDamaged = false; - // request model - if(dist - STREAM_DISTANCE < mi->GetLargestLodDistance() && request) - return VIS_STREAMME; - return VIS_INVISIBLE; - } - - // We might be fading - - a = mi->GetAtomicFromDistance(dist - FADE_DISTANCE); - mi->m_isDamaged = false; - if(a == nil){ - // request model - if(dist - FADE_DISTANCE - STREAM_DISTANCE < mi->GetLargestLodDistance() && request) - return VIS_STREAMME; - return VIS_INVISIBLE; - } - - if(ent->m_rwObject == nil) - ent->CreateRwObject(); - assert(ent->m_rwObject); - RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject; - if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj)) - RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?) - mi->IncreaseAlpha(); - if(ent->m_rwObject == nil || !ent->bIsVisible) - return VIS_INVISIBLE; - - if(!ent->GetIsOnScreen() || ent->IsEntityOccluded()){ - mi->m_alpha = 255; - return VIS_OFFSCREEN; - }else{ - CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); - ent->bDistanceFade = true; - return VIS_OFFSCREEN; // Why this? - } -} - -int32 -CRenderer::SetupBigBuildingVisibility(CEntity *ent) -{ - CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(ent->m_modelIndex); - CTimeModelInfo *ti; - int32 other; - - if(!IsAreaVisible(ent->m_area)) - return VIS_INVISIBLE; - - bool request = true; - if(mi->GetModelType() == MITYPE_TIME){ - ti = (CTimeModelInfo*)mi; - other = ti->GetOtherTimeModel(); - if(CClock::GetIsTimeInRange(ti->GetTimeOn(), ti->GetTimeOff())){ - // don't fade in, or between time objects - if(CANTIMECULL) - ti->m_alpha = 255; - }else{ - // Hide if possible - if(CANTIMECULL){ - ent->DeleteRwObject(); - return VIS_INVISIBLE; - } - // can't cull, so we'll try to draw this one, but don't request - // it since what we really want is the other one. - request = false; - } - }else if(mi->GetModelType() == MITYPE_VEHICLE) - return ent->IsVisible() ? VIS_VISIBLE : VIS_INVISIBLE; - - float dist = (ms_vecCameraPosition-ent->GetPosition()).Magnitude(); - CSimpleModelInfo *nonLOD = mi->GetRelatedModel(); - - // Find out whether to draw below near distance. - // This is only the case if there is a non-LOD which is either not - // loaded or not completely faded in yet. - if(dist < mi->GetNearDistance() && dist < LOD_DISTANCE){ - // No non-LOD or non-LOD is completely visible. - if(nonLOD == nil || - nonLOD->GetRwObject() && nonLOD->m_alpha == 255) - return VIS_INVISIBLE; - - // But if it is a time object, we'd rather draw the wrong - // non-LOD than the right LOD. - if(nonLOD->GetModelType() == MITYPE_TIME){ - ti = (CTimeModelInfo*)nonLOD; - other = ti->GetOtherTimeModel(); - if(other != -1 && CModelInfo::GetModelInfo(other)->GetRwObject()) - return VIS_INVISIBLE; - } - } - - RpAtomic *a = mi->GetFirstAtomicFromDistance(dist); - if(a){ - if(ent->m_rwObject == nil) - ent->CreateRwObject(); - assert(ent->m_rwObject); - RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject; - - // Make sure our atomic uses the right geometry and not - // that of an atomic for another draw distance. - if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj)) - RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?) - mi->IncreaseAlpha(); - if(!ent->IsVisible() || !ent->GetIsOnScreenComplex() || ent->IsEntityOccluded()){ - mi->m_alpha = 255; - return VIS_INVISIBLE; - } - - if(mi->m_alpha != 255){ - CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); - ent->bDistanceFade = true; - return VIS_INVISIBLE; - } - - if(mi->m_drawLast){ - CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); - ent->bDistanceFade = false; - return VIS_INVISIBLE; - } - return VIS_VISIBLE; - } - - if(mi->m_noFade){ - ent->DeleteRwObject(); - return VIS_INVISIBLE; - } - - - // get faded atomic - a = mi->GetFirstAtomicFromDistance(dist - FADE_DISTANCE); - if(a == nil){ - if(ent->bStreamBIGBuilding && dist-STREAM_DISTANCE < mi->GetLodDistance(0) && request){ - return ent->GetIsOnScreen() ? VIS_STREAMME : VIS_INVISIBLE; - }else{ - ent->DeleteRwObject(); - return VIS_INVISIBLE; - } - } - - // Fade... - if(ent->m_rwObject == nil) - ent->CreateRwObject(); - assert(ent->m_rwObject); - RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject; - if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj)) - RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?) - mi->IncreaseAlpha(); - if(!ent->IsVisible() || !ent->GetIsOnScreenComplex() || ent->IsEntityOccluded()){ - mi->m_alpha = 255; - return VIS_INVISIBLE; - } - CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); - ent->bDistanceFade = true; - return VIS_INVISIBLE; -} - -void -CRenderer::ConstructRenderList(void) -{ - COcclusion::ProcessBeforeRendering(); -#ifdef NEW_RENDERER - if(!gbNewRenderer) -#endif -{ - ms_nNoOfVisibleEntities = 0; - ms_nNoOfInVisibleEntities = 0; -} - ms_vecCameraPosition = TheCamera.GetPosition(); - - // unused - pFullBlockedRanges = nil; - pEmptyBlockedRanges = aBlockedRanges; - for(int i = 0; i < 16; i++){ - aBlockedRanges[i].prev = &aBlockedRanges[i-1]; - aBlockedRanges[i].next = &aBlockedRanges[i+1]; - } - aBlockedRanges[0].prev = nil; - aBlockedRanges[15].next = nil; - - // unused - TestCloseThings = 0; - TestBigThings = 0; - - ScanWorld(); -} - -void -LimitFrustumVector(CVector &vec1, const CVector &vec2, float l) -{ - float f; - f = (l - vec2.z) / (vec1.z - vec2.z); - vec1.x = f*(vec1.x - vec2.x) + vec2.x; - vec1.y = f*(vec1.y - vec2.y) + vec2.y; - vec1.z = f*(vec1.z - vec2.z) + vec2.z; -} - -enum Corners -{ - CORNER_CAM = 0, - CORNER_FAR_TOPLEFT, - CORNER_FAR_TOPRIGHT, - CORNER_FAR_BOTRIGHT, - CORNER_FAR_BOTLEFT, - CORNER_LOD_LEFT, - CORNER_LOD_RIGHT, - CORNER_PRIO_LEFT, - CORNER_PRIO_RIGHT, -}; - -void -CRenderer::ScanWorld(void) -{ - float f = RwCameraGetFarClipPlane(TheCamera.m_pRwCamera); - RwV2d vw = *RwCameraGetViewWindow(TheCamera.m_pRwCamera); - CVector vectors[9]; - RwMatrix *cammatrix; - RwV2d poly[3]; - - memset(vectors, 0, sizeof(vectors)); - vectors[CORNER_FAR_TOPLEFT].x = -vw.x * f; - vectors[CORNER_FAR_TOPLEFT].y = vw.y * f; - vectors[CORNER_FAR_TOPLEFT].z = f; - vectors[CORNER_FAR_TOPRIGHT].x = vw.x * f; - vectors[CORNER_FAR_TOPRIGHT].y = vw.y * f; - vectors[CORNER_FAR_TOPRIGHT].z = f; - vectors[CORNER_FAR_BOTRIGHT].x = vw.x * f; - vectors[CORNER_FAR_BOTRIGHT].y = -vw.y * f; - vectors[CORNER_FAR_BOTRIGHT].z = f; - vectors[CORNER_FAR_BOTLEFT].x = -vw.x * f; - vectors[CORNER_FAR_BOTLEFT].y = -vw.y * f; - vectors[CORNER_FAR_BOTLEFT].z = f; - - cammatrix = RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera)); - - m_pFirstPersonVehicle = nil; - CVisibilityPlugins::InitAlphaEntityList(); - CWorld::AdvanceCurrentScanCode(); - - // unused - static CVector prevPos; - static CVector prevFwd; - static bool smallMovement; - smallMovement = (TheCamera.GetPosition() - prevPos).MagnitudeSqr() < SQR(4.0f) && - DotProduct(TheCamera.GetForward(), prevFwd) > 0.98f; - prevPos = TheCamera.GetPosition(); - prevFwd = TheCamera.GetForward(); - - if(cammatrix->at.z > 0.0f){ - // looking up, bottom corners are further away - vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_BOTLEFT] * LOD_DISTANCE/f; - vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_BOTRIGHT] * LOD_DISTANCE/f; - }else{ - // looking down, top corners are further away - vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_TOPLEFT] * LOD_DISTANCE/f; - vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_TOPRIGHT] * LOD_DISTANCE/f; - } - vectors[CORNER_PRIO_LEFT].x = vectors[CORNER_LOD_LEFT].x * 0.2f; - vectors[CORNER_PRIO_LEFT].y = vectors[CORNER_LOD_LEFT].y * 0.2f; - vectors[CORNER_PRIO_LEFT].z = vectors[CORNER_LOD_LEFT].z; - vectors[CORNER_PRIO_RIGHT].x = vectors[CORNER_LOD_RIGHT].x * 0.2f; - vectors[CORNER_PRIO_RIGHT].y = vectors[CORNER_LOD_RIGHT].y * 0.2f; - vectors[CORNER_PRIO_RIGHT].z = vectors[CORNER_LOD_RIGHT].z; - RwV3dTransformPoints(vectors, vectors, 9, cammatrix); - - m_loadingPriority = false; - if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN || -#ifdef FIX_BUGS - TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_GTACLASSIC || -#endif - TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){ - CRect rect; - int x1, x2, y1, y2; - LimitFrustumVector(vectors[CORNER_FAR_TOPLEFT], vectors[CORNER_CAM], -100.0f); - rect.ContainPoint(vectors[CORNER_FAR_TOPLEFT]); - LimitFrustumVector(vectors[CORNER_FAR_TOPRIGHT], vectors[CORNER_CAM], -100.0f); - rect.ContainPoint(vectors[CORNER_FAR_TOPRIGHT]); - LimitFrustumVector(vectors[CORNER_FAR_BOTRIGHT], vectors[CORNER_CAM], -100.0f); - rect.ContainPoint(vectors[CORNER_FAR_BOTRIGHT]); - LimitFrustumVector(vectors[CORNER_FAR_BOTLEFT], vectors[CORNER_CAM], -100.0f); - rect.ContainPoint(vectors[CORNER_FAR_BOTLEFT]); - x1 = CWorld::GetSectorIndexX(rect.left); - if(x1 < 0) x1 = 0; - x2 = CWorld::GetSectorIndexX(rect.right); - if(x2 >= NUMSECTORS_X-1) x2 = NUMSECTORS_X-1; - y1 = CWorld::GetSectorIndexY(rect.top); - if(y1 < 0) y1 = 0; - y2 = CWorld::GetSectorIndexY(rect.bottom); - if(y2 >= NUMSECTORS_Y-1) y2 = NUMSECTORS_Y-1; - for(; x1 <= x2; x1++) - for(int y = y1; y <= y2; y++) - ScanSectorList(CWorld::GetSector(x1, y)->m_lists); - }else{ -#ifdef GTA_TRAIN - CVehicle *train = FindPlayerTrain(); - if(train && train->GetPosition().z < 0.0f){ - poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x); - poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y); - poly[1].x = CWorld::GetSectorX(vectors[CORNER_LOD_LEFT].x); - poly[1].y = CWorld::GetSectorY(vectors[CORNER_LOD_LEFT].y); - poly[2].x = CWorld::GetSectorX(vectors[CORNER_LOD_RIGHT].x); - poly[2].y = CWorld::GetSectorY(vectors[CORNER_LOD_RIGHT].y); - ScanSectorPoly(poly, 3, ScanSectorList_Subway); - }else -#endif - { - if(f > LOD_DISTANCE){ - // priority - poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x); - poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y); - poly[1].x = CWorld::GetSectorX(vectors[CORNER_PRIO_LEFT].x); - poly[1].y = CWorld::GetSectorY(vectors[CORNER_PRIO_LEFT].y); - poly[2].x = CWorld::GetSectorX(vectors[CORNER_PRIO_RIGHT].x); - poly[2].y = CWorld::GetSectorY(vectors[CORNER_PRIO_RIGHT].y); - ScanSectorPoly(poly, 3, ScanSectorList_Priority); - - // below LOD - poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x); - poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y); - poly[1].x = CWorld::GetSectorX(vectors[CORNER_LOD_LEFT].x); - poly[1].y = CWorld::GetSectorY(vectors[CORNER_LOD_LEFT].y); - poly[2].x = CWorld::GetSectorX(vectors[CORNER_LOD_RIGHT].x); - poly[2].y = CWorld::GetSectorY(vectors[CORNER_LOD_RIGHT].y); - ScanSectorPoly(poly, 3, ScanSectorList); - }else{ - poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x); - poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y); - poly[1].x = CWorld::GetSectorX(vectors[CORNER_FAR_TOPLEFT].x); - poly[1].y = CWorld::GetSectorY(vectors[CORNER_FAR_TOPLEFT].y); - poly[2].x = CWorld::GetSectorX(vectors[CORNER_FAR_TOPRIGHT].x); - poly[2].y = CWorld::GetSectorY(vectors[CORNER_FAR_TOPRIGHT].y); - ScanSectorPoly(poly, 3, ScanSectorList); - } - -#ifdef NO_ISLAND_LOADING - if (FrontEndMenuManager.m_PrefsIslandLoading == CMenuManager::ISLAND_LOADING_HIGH) { - ScanBigBuildingList(CWorld::GetBigBuildingList(LEVEL_BEACH)); - ScanBigBuildingList(CWorld::GetBigBuildingList(LEVEL_MAINLAND)); - } else -#endif - { -#ifdef FIX_BUGS - if(CCollision::ms_collisionInMemory != LEVEL_GENERIC) -#endif - ScanBigBuildingList(CWorld::GetBigBuildingList(CGame::currLevel)); - } - ScanBigBuildingList(CWorld::GetBigBuildingList(LEVEL_GENERIC)); - } - } -} - -void -CRenderer::RequestObjectsInFrustum(void) -{ - float f = RwCameraGetFarClipPlane(TheCamera.m_pRwCamera); - RwV2d vw = *RwCameraGetViewWindow(TheCamera.m_pRwCamera); - CVector vectors[9]; - RwMatrix *cammatrix; - RwV2d poly[3]; - - memset(vectors, 0, sizeof(vectors)); - vectors[CORNER_FAR_TOPLEFT].x = -vw.x * f; - vectors[CORNER_FAR_TOPLEFT].y = vw.y * f; - vectors[CORNER_FAR_TOPLEFT].z = f; - vectors[CORNER_FAR_TOPRIGHT].x = vw.x * f; - vectors[CORNER_FAR_TOPRIGHT].y = vw.y * f; - vectors[CORNER_FAR_TOPRIGHT].z = f; - vectors[CORNER_FAR_BOTRIGHT].x = vw.x * f; - vectors[CORNER_FAR_BOTRIGHT].y = -vw.y * f; - vectors[CORNER_FAR_BOTRIGHT].z = f; - vectors[CORNER_FAR_BOTLEFT].x = -vw.x * f; - vectors[CORNER_FAR_BOTLEFT].y = -vw.y * f; - vectors[CORNER_FAR_BOTLEFT].z = f; - - cammatrix = RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera)); - - CWorld::AdvanceCurrentScanCode(); - ms_vecCameraPosition = TheCamera.GetPosition(); - - if(cammatrix->at.z > 0.0f){ - // looking up, bottom corners are further away - vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_BOTLEFT] * LOD_DISTANCE/f; - vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_BOTRIGHT] * LOD_DISTANCE/f; - }else{ - // looking down, top corners are further away - vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_TOPLEFT] * LOD_DISTANCE/f; - vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_TOPRIGHT] * LOD_DISTANCE/f; - } - vectors[CORNER_PRIO_LEFT].x = vectors[CORNER_LOD_LEFT].x * 0.2f; - vectors[CORNER_PRIO_LEFT].y = vectors[CORNER_LOD_LEFT].y * 0.2f; - vectors[CORNER_PRIO_LEFT].z = vectors[CORNER_LOD_LEFT].z; - vectors[CORNER_PRIO_RIGHT].x = vectors[CORNER_LOD_RIGHT].x * 0.2f; - vectors[CORNER_PRIO_RIGHT].y = vectors[CORNER_LOD_RIGHT].y * 0.2f; - vectors[CORNER_PRIO_RIGHT].z = vectors[CORNER_LOD_RIGHT].z; - RwV3dTransformPoints(vectors, vectors, 9, cammatrix); - - if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN || -#ifdef FIX_BUGS - TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_GTACLASSIC || -#endif - TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){ - CRect rect; - int x1, x2, y1, y2; - LimitFrustumVector(vectors[CORNER_FAR_TOPLEFT], vectors[CORNER_CAM], -100.0f); - rect.ContainPoint(vectors[CORNER_FAR_TOPLEFT]); - LimitFrustumVector(vectors[CORNER_FAR_TOPRIGHT], vectors[CORNER_CAM], -100.0f); - rect.ContainPoint(vectors[CORNER_FAR_TOPRIGHT]); - LimitFrustumVector(vectors[CORNER_FAR_BOTRIGHT], vectors[CORNER_CAM], -100.0f); - rect.ContainPoint(vectors[CORNER_FAR_BOTRIGHT]); - LimitFrustumVector(vectors[CORNER_FAR_BOTLEFT], vectors[CORNER_CAM], -100.0f); - rect.ContainPoint(vectors[CORNER_FAR_BOTLEFT]); - x1 = CWorld::GetSectorIndexX(rect.left); - if(x1 < 0) x1 = 0; - x2 = CWorld::GetSectorIndexX(rect.right); - if(x2 >= NUMSECTORS_X-1) x2 = NUMSECTORS_X-1; - y1 = CWorld::GetSectorIndexY(rect.top); - if(y1 < 0) y1 = 0; - y2 = CWorld::GetSectorIndexY(rect.bottom); - if(y2 >= NUMSECTORS_Y-1) y2 = NUMSECTORS_Y-1; - for(; x1 <= x2; x1++) - for(int y = y1; y <= y2; y++) - ScanSectorList_RequestModels(CWorld::GetSector(x1, y)->m_lists); - }else{ - poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x); - poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y); - poly[1].x = CWorld::GetSectorX(vectors[CORNER_LOD_LEFT].x); - poly[1].y = CWorld::GetSectorY(vectors[CORNER_LOD_LEFT].y); - poly[2].x = CWorld::GetSectorX(vectors[CORNER_LOD_RIGHT].x); - poly[2].y = CWorld::GetSectorY(vectors[CORNER_LOD_RIGHT].y); - ScanSectorPoly(poly, 3, ScanSectorList_RequestModels); - } -} - -bool -CEntity::SetupLighting(void) -{ - return false; -} - -void -CEntity::RemoveLighting(bool) -{ -} - -bool -CPed::SetupLighting(void) -{ - ActivateDirectional(); - SetAmbientColoursForPedsCarsAndObjects(); - -#ifndef MASTER - // Originally this was being called through iteration of Sectors, but putting it here is better. - if (GetDebugDisplay() != 0 && !IsPlayer()) - DebugRenderOnePedText(); -#endif - - if (bRenderScorched) { - WorldReplaceNormalLightsWithScorched(Scene.world, 0.1f); - } else { - // Note that this lightMult is only affected by LIGHT_DARKEN. If there's no LIGHT_DARKEN, it will be 1.0. - float lightMult = CPointLights::GenerateLightsAffectingObject(&GetPosition()); - if (lightMult != 1.0f) { - SetAmbientAndDirectionalColours(lightMult); - return true; - } - } - return false; -} - -void -CPed::RemoveLighting(bool reset) -{ - if (!bRenderScorched) { - CRenderer::RemoveVehiclePedLights(this, reset); - if (reset) - ReSetAmbientAndDirectionalColours(); - } - SetAmbientColours(); - DeActivateDirectional(); -} - -float -CalcNewDelta(RwV2d *a, RwV2d *b) -{ - return (b->x - a->x) / (b->y - a->y); -} - -#ifdef FIX_BUGS -#define TOINT(x) ((int)Floor(x)) -#else -#define TOINT(x) ((int)(x)) -#endif - -void -CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrList *)) -{ - float miny, maxy; - int y, yend; - int x, xstart, xend; - int i; - int a1, a2, b1, b2; - float deltaA, deltaB; - float xA, xB; - - miny = poly[0].y; - maxy = poly[0].y; - a2 = 0; - xstart = 9999; - xend = -9999; - - for(i = 1; i < numVertices; i++){ - if(poly[i].y > maxy) - maxy = poly[i].y; - if(poly[i].y < miny){ - miny = poly[i].y; - a2 = i; - } - } - y = TOINT(miny); - yend = TOINT(maxy); - - // Go left in poly to find first edge b - b2 = a2; - for(i = 0; i < numVertices; i++){ - b1 = b2--; - if(b2 < 0) b2 = numVertices-1; - if(poly[b1].x < xstart) - xstart = TOINT(poly[b1].x); - if(TOINT(poly[b1].y) != TOINT(poly[b2].y)) - break; - } - // Go right to find first edge a - for(i = 0; i < numVertices; i++){ - a1 = a2++; - if(a2 == numVertices) a2 = 0; - if(poly[a1].x > xend) - xend = TOINT(poly[a1].x); - if(TOINT(poly[a1].y) != TOINT(poly[a2].y)) - break; - } - - // prestep x1 and x2 to next integer y - deltaA = CalcNewDelta(&poly[a1], &poly[a2]); - xA = deltaA * (Ceil(poly[a1].y) - poly[a1].y) + poly[a1].x; - deltaB = CalcNewDelta(&poly[b1], &poly[b2]); - xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x; - - if(y != yend){ - if(deltaB < 0.0f && TOINT(xB) < xstart) - xstart = TOINT(xB); - if(deltaA >= 0.0f && TOINT(xA) > xend) - xend = TOINT(xA); - } - - while(y <= yend && y < NUMSECTORS_Y){ - // scan one x-line - if(y >= 0 && xstart < NUMSECTORS_X) - for(x = xstart; x <= xend && x != NUMSECTORS_X; x++) - if(x >= 0) - scanfunc(CWorld::GetSector(x, y)->m_lists); - - // advance one scan line - y++; - xA += deltaA; - xB += deltaB; - - // update left side - if(y == TOINT(poly[b2].y)){ - // reached end of edge - if(y == yend){ - if(deltaB < 0.0f){ - do{ - xstart = TOINT(poly[b2--].x); - if(b2 < 0) b2 = numVertices-1; - }while(xstart > TOINT(poly[b2].x)); - }else - xstart = TOINT(xB - deltaB); - }else{ - // switch edges - if(deltaB < 0.0f) - xstart = TOINT(poly[b2].x); - else - xstart = TOINT(xB - deltaB); - do{ - b1 = b2--; - if(b2 < 0) b2 = numVertices-1; - if(TOINT(poly[b1].x) < xstart) - xstart = TOINT(poly[b1].x); - }while(y == TOINT(poly[b2].y)); - deltaB = CalcNewDelta(&poly[b1], &poly[b2]); - xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x; - if(deltaB < 0.0f && TOINT(xB) < xstart) - xstart = TOINT(xB); - } - }else{ - if(deltaB < 0.0f) - xstart = TOINT(xB); - else - xstart = TOINT(xB - deltaB); - } - - // update right side - if(y == TOINT(poly[a2].y)){ - // reached end of edge - if(y == yend){ - if(deltaA < 0.0f) - xend = TOINT(xA - deltaA); - else{ - do{ - xend = TOINT(poly[a2++].x); - if(a2 == numVertices) a2 = 0; - }while(xend < TOINT(poly[a2].x)); - } - }else{ - // switch edges - if(deltaA < 0.0f) - xend = TOINT(xA - deltaA); - else - xend = TOINT(poly[a2].x); - do{ - a1 = a2++; - if(a2 == numVertices) a2 = 0; - if(TOINT(poly[a1].x) > xend) - xend = TOINT(poly[a1].x); - }while(y == TOINT(poly[a2].y)); - deltaA = CalcNewDelta(&poly[a1], &poly[a2]); - xA = deltaA * (Ceil(poly[a1].y) - poly[a1].y) + poly[a1].x; - if(deltaA >= 0.0f && TOINT(xA) > xend) - xend = TOINT(xA); - } - }else{ - if(deltaA < 0.0f) - xend = TOINT(xA - deltaA); - else - xend = TOINT(xA); - } - } -} - -void -CRenderer::InsertEntityIntoList(CEntity *ent) -{ -#ifdef FIX_BUGS - if (!ent->m_rwObject) return; -#endif - -#ifdef NEW_RENDERER - // TODO: there are more flags being checked here - if(gbNewRenderer && (ent->IsVehicle() || ent->IsPed())) - ms_aVisibleVehiclePtrs[ms_nNoOfVisibleVehicles++] = ent; - else if(gbNewRenderer && ent->IsBuilding()) - ms_aVisibleBuildingPtrs[ms_nNoOfVisibleBuildings++] = ent; - else -#endif - ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent; -} - -void -CRenderer::ScanBigBuildingList(CPtrList &list) -{ - CPtrNode *node; - CEntity *ent; - int vis; - - int f = CTimer::GetFrameCounter() & 3; - for(node = list.first; node; node = node->next){ - ent = (CEntity*)node->item; - if(ent->bOffscreen || (ent->m_randomSeed&3) != f){ - ent->bOffscreen = true; - vis = SetupBigBuildingVisibility(ent); - }else - vis = VIS_VISIBLE; - switch(vis){ - case VIS_VISIBLE: - InsertEntityIntoList(ent); - ent->bOffscreen = false; - break; - case VIS_STREAMME: - if(!CStreaming::ms_disableStreaming) - CStreaming::RequestModel(ent->GetModelIndex(), 0); - break; - } - } -} - -void -CRenderer::ScanSectorList(CPtrList *lists) -{ - CPtrNode *node; - CPtrList *list; - CEntity *ent; - int i; - float dx, dy; - - for(i = 0; i < NUMSECTORENTITYLISTS; i++){ - list = &lists[i]; - for(node = list->first; node; node = node->next){ - ent = (CEntity*)node->item; - if(ent->m_scanCode == CWorld::GetCurrentScanCode()) - continue; // already seen - ent->m_scanCode = CWorld::GetCurrentScanCode(); - ent->bOffscreen = false; - - switch(SetupEntityVisibility(ent)){ - case VIS_VISIBLE: - InsertEntityIntoList(ent); - break; - case VIS_INVISIBLE: - if(!IsGlass(ent->GetModelIndex())) - break; - // fall through - case VIS_OFFSCREEN: - ent->bOffscreen = true; - dx = ms_vecCameraPosition.x - ent->GetPosition().x; - dy = ms_vecCameraPosition.y - ent->GetPosition().y; - if(dx > -30.0f && dx < 30.0f && - dy > -30.0f && dy < 30.0f && - ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1) - ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent; - break; - case VIS_STREAMME: - if(!CStreaming::ms_disableStreaming) - if(!m_loadingPriority || CStreaming::ms_numModelsRequested < 10) - CStreaming::RequestModel(ent->GetModelIndex(), 0); - break; - } - } - } -} - -void -CRenderer::ScanSectorList_Priority(CPtrList *lists) -{ - CPtrNode *node; - CPtrList *list; - CEntity *ent; - int i; - float dx, dy; - - for(i = 0; i < NUMSECTORENTITYLISTS; i++){ - list = &lists[i]; - for(node = list->first; node; node = node->next){ - ent = (CEntity*)node->item; - if(ent->m_scanCode == CWorld::GetCurrentScanCode()) - continue; // already seen - ent->m_scanCode = CWorld::GetCurrentScanCode(); - ent->bOffscreen = false; - - switch(SetupEntityVisibility(ent)){ - case VIS_VISIBLE: - InsertEntityIntoList(ent); - break; - case VIS_INVISIBLE: - if(!IsGlass(ent->GetModelIndex())) - break; - // fall through - case VIS_OFFSCREEN: - ent->bOffscreen = true; - dx = ms_vecCameraPosition.x - ent->GetPosition().x; - dy = ms_vecCameraPosition.y - ent->GetPosition().y; - if(dx > -30.0f && dx < 30.0f && - dy > -30.0f && dy < 30.0f && - ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1) - ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent; - break; - case VIS_STREAMME: - if(!CStreaming::ms_disableStreaming){ - CStreaming::RequestModel(ent->GetModelIndex(), 0); - if(CStreaming::ms_aInfoForModel[ent->GetModelIndex()].m_loadState != STREAMSTATE_LOADED) - m_loadingPriority = true; - } - break; - } - } - } -} - -#ifdef GTA_TRAIN -void -CRenderer::ScanSectorList_Subway(CPtrList *lists) -{ - CPtrNode *node; - CPtrList *list; - CEntity *ent; - int i; - float dx, dy; - - for(i = 0; i < NUMSECTORENTITYLISTS; i++){ - list = &lists[i]; - for(node = list->first; node; node = node->next){ - ent = (CEntity*)node->item; - if(ent->m_scanCode == CWorld::GetCurrentScanCode()) - continue; // already seen - ent->m_scanCode = CWorld::GetCurrentScanCode(); - ent->bOffscreen = false; - switch(SetupEntityVisibility(ent)){ - case VIS_VISIBLE: - InsertEntityIntoList(ent); - break; - case VIS_OFFSCREEN: - ent->bOffscreen = true; - dx = ms_vecCameraPosition.x - ent->GetPosition().x; - dy = ms_vecCameraPosition.y - ent->GetPosition().y; - if(dx > -30.0f && dx < 30.0f && - dy > -30.0f && dy < 30.0f && - ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1) - ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent; - break; - } - } - } -} -#endif - -void -CRenderer::ScanSectorList_RequestModels(CPtrList *lists) -{ - CPtrNode *node; - CPtrList *list; - CEntity *ent; - int i; - - for(i = 0; i < NUMSECTORENTITYLISTS; i++){ - list = &lists[i]; - for(node = list->first; node; node = node->next){ - ent = (CEntity*)node->item; - if(ent->m_scanCode == CWorld::GetCurrentScanCode()) - continue; // already seen - ent->m_scanCode = CWorld::GetCurrentScanCode(); - if(ShouldModelBeStreamed(ent, ms_vecCameraPosition)) - CStreaming::RequestModel(ent->GetModelIndex(), 0); - } - } -} - -// Put big buildings in front -// This seems pointless because the sector lists shouldn't have big buildings in the first place -void -CRenderer::SortBIGBuildings(void) -{ - int x, y; - for(y = 0; y < NUMSECTORS_Y; y++) - for(x = 0; x < NUMSECTORS_X; x++){ - SortBIGBuildingsForSectorList(&CWorld::GetSector(x, y)->m_lists[ENTITYLIST_BUILDINGS]); - SortBIGBuildingsForSectorList(&CWorld::GetSector(x, y)->m_lists[ENTITYLIST_BUILDINGS_OVERLAP]); - } -} - -void -CRenderer::SortBIGBuildingsForSectorList(CPtrList *list) -{ - CPtrNode *node; - CEntity *ent; - - for(node = list->first; node; node = node->next){ - ent = (CEntity*)node->item; - if(ent->bIsBIGBuilding){ - list->RemoveNode(node); - list->InsertNode(node); - } - } -} - -bool -CRenderer::ShouldModelBeStreamed(CEntity *ent, const CVector &campos) -{ - if(!IsAreaVisible(ent->m_area)) - return false; - CTimeModelInfo *mi = (CTimeModelInfo *)CModelInfo::GetModelInfo(ent->GetModelIndex()); - if(mi->GetModelType() == MITYPE_TIME) - if(!CClock::GetIsTimeInRange(mi->GetTimeOn(), mi->GetTimeOff())) - return false; - float dist = (ent->GetPosition() - campos).Magnitude(); - if(mi->m_noFade) - return dist - STREAM_DISTANCE < mi->GetLargestLodDistance(); - else - return dist - FADE_DISTANCE - STREAM_DISTANCE < mi->GetLargestLodDistance(); -} - -void -CRenderer::RemoveVehiclePedLights(CEntity *ent, bool reset) -{ - if(!ent->bRenderScorched){ - CPointLights::RemoveLightsAffectingObject(); - if(reset) - ReSetAmbientAndDirectionalColours(); - } - SetAmbientColours(); - DeActivateDirectional(); -} diff --git a/src/render/Renderer.h b/src/render/Renderer.h deleted file mode 100644 index 9b202098..00000000 --- a/src/render/Renderer.h +++ /dev/null @@ -1,105 +0,0 @@ -#pragma once - -class CEntity; - -#ifdef FIX_BUGS -#define LOD_DISTANCE (300.0f*TheCamera.LODDistMultiplier) -#else -#define LOD_DISTANCE 300.0f -#endif -#define FADE_DISTANCE 20.0f -#define STREAM_DISTANCE 30.0f - -extern bool gbShowPedRoadGroups; -extern bool gbShowCarRoadGroups; -extern bool gbShowCollisionPolys; -extern bool gbShowCollisionLines; -extern bool gbBigWhiteDebugLightSwitchedOn; - -extern bool gbDontRenderBuildings; -extern bool gbDontRenderBigBuildings; -extern bool gbDontRenderPeds; -extern bool gbDontRenderObjects; -extern bool gbDontRenderVehicles; - -class CVehicle; -class CPtrList; - -// unused -struct BlockedRange -{ - float a, b; // unknown - BlockedRange *prev, *next; -}; - -class CRenderer -{ - static int32 ms_nNoOfVisibleEntities; - static CEntity *ms_aVisibleEntityPtrs[NUMVISIBLEENTITIES]; - static int32 ms_nNoOfInVisibleEntities; - static CEntity *ms_aInVisibleEntityPtrs[NUMINVISIBLEENTITIES]; -#ifdef NEW_RENDERER - static int32 ms_nNoOfVisibleVehicles; - static CEntity *ms_aVisibleVehiclePtrs[NUMVISIBLEENTITIES]; - // for cWorldStream emulation - static int32 ms_nNoOfVisibleBuildings; - static CEntity *ms_aVisibleBuildingPtrs[NUMVISIBLEENTITIES]; -#endif - - static CVector ms_vecCameraPosition; - static CVehicle *m_pFirstPersonVehicle; - - // unused - static BlockedRange aBlockedRanges[16]; - static BlockedRange *pFullBlockedRanges; - static BlockedRange *pEmptyBlockedRanges; -public: - static float ms_lodDistScale; - static bool m_loadingPriority; - - static void Init(void); - static void Shutdown(void); - static void PreRender(void); - - static void RenderRoads(void); - static void RenderFadingInEntities(void); - static void RenderFadingInUnderwaterEntities(void); - static void RenderEverythingBarRoads(void); - static void RenderBoats(void); - static void RenderOneRoad(CEntity *); - static void RenderOneNonRoad(CEntity *); - static void RenderFirstPersonVehicle(void); - - static void RenderCollisionLines(void); - - static int32 SetupEntityVisibility(CEntity *ent); - static int32 SetupBigBuildingVisibility(CEntity *ent); - - static void ConstructRenderList(void); - static void ScanWorld(void); - static void RequestObjectsInFrustum(void); - static void ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrList *)); - static void ScanBigBuildingList(CPtrList &list); - static void ScanSectorList(CPtrList *lists); - static void ScanSectorList_Priority(CPtrList *lists); - static void ScanSectorList_Subway(CPtrList *lists); - static void ScanSectorList_RequestModels(CPtrList *lists); - - static void SortBIGBuildings(void); - static void SortBIGBuildingsForSectorList(CPtrList *list); - - static bool ShouldModelBeStreamed(CEntity *ent, const CVector &campos); - - static void RemoveVehiclePedLights(CEntity *ent, bool reset); - - -#ifdef NEW_RENDERER - static void ClearForFrame(void); - static void RenderPeds(void); - static void RenderVehicles(void); // also renders peds in LCS - static void RenderOneBuilding(CEntity *ent, float camdist = 0.0f); - static void RenderWorld(int pass); // like cWorldStream::Render(int) - static void RenderTransparentWater(void); // keep-out polys and transparent water -#endif - static void InsertEntityIntoList(CEntity *ent); -}; diff --git a/src/render/Rubbish.cpp b/src/render/Rubbish.cpp deleted file mode 100644 index 147c97b1..00000000 --- a/src/render/Rubbish.cpp +++ /dev/null @@ -1,423 +0,0 @@ -#include "common.h" -#include "main.h" - -#include "General.h" -#include "Timer.h" -#include "Weather.h" -#include "Camera.h" -#include "World.h" -#include "Vehicle.h" -#include "ZoneCull.h" -#include "Stats.h" -#include "TxdStore.h" -#include "RenderBuffer.h" -#include "Rubbish.h" - -#define RUBBISH_MAX_DIST (23.0f) -#define RUBBISH_FADE_DIST (20.0f) - -RwTexture *gpRubbishTexture[4]; -RwImVertexIndex RubbishIndexList[6]; -bool CRubbish::bRubbishInvisible; -int CRubbish::RubbishVisibility; -COneSheet CRubbish::aSheets[NUM_RUBBISH_SHEETS]; -COneSheet CRubbish::StartEmptyList; -COneSheet CRubbish::EndEmptyList; -COneSheet CRubbish::StartStaticsList; -COneSheet CRubbish::EndStaticsList; -COneSheet CRubbish::StartMoversList; -COneSheet CRubbish::EndMoversList; - - -void -COneSheet::AddToList(COneSheet *list) -{ - this->m_next = list->m_next; - this->m_prev = list; - list->m_next = this; - this->m_next->m_prev = this; -} - -void -COneSheet::RemoveFromList(void) -{ - m_next->m_prev = m_prev; - m_prev->m_next = m_next; -} - - -void -CRubbish::Render(void) -{ - int type; - - if(RubbishVisibility == 0) - return; - - PUSH_RENDERGROUP("CRubbish::Render"); - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); - - for(type = 0; type < 4; type++){ - if(type < 3 || CStats::PamphletMissionPassed) - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpRubbishTexture[type])); - - TempBufferIndicesStored = 0; - TempBufferVerticesStored = 0; - - COneSheet *sheet; - for(sheet = &aSheets[type*NUM_RUBBISH_SHEETS / 4]; - sheet < &aSheets[(type+1)*NUM_RUBBISH_SHEETS / 4]; - sheet++){ - if(sheet->m_state == 0) - continue; - - uint32 alpha = 100; - CVector pos; - if(sheet->m_state == 1){ - pos = sheet->m_basePos; - if(!sheet->m_isVisible) - alpha = 0; - }else{ - pos = sheet->m_animatedPos; - // Not fully visible during animation, calculate current alpha - if(!sheet->m_isVisible || !sheet->m_targetIsVisible){ - float t = (float)(CTimer::GetTimeInMilliseconds() - sheet->m_moveStart)/sheet->m_moveDuration; - float f1 = sheet->m_isVisible ? 1.0f-t : 0.0f; - float f2 = sheet->m_targetIsVisible ? t : 0.0f; - alpha = 100 * (f1+f2); - } - } - - float camDist = (pos - TheCamera.GetPosition()).Magnitude2D(); - if(camDist < RUBBISH_MAX_DIST){ - if(camDist >= RUBBISH_FADE_DIST) - alpha -= alpha*(camDist-RUBBISH_FADE_DIST)/(RUBBISH_MAX_DIST-RUBBISH_FADE_DIST); - alpha = (RubbishVisibility*alpha)/256; - - float vx1, vy1, vx2, vy2; - if(type == 0 || type == 1){ - vx1 = 0.9f*Sin(sheet->m_angle); - vy1 = 0.9f*Cos(sheet->m_angle); - vx2 = 0.3f*Cos(sheet->m_angle); - vy2 = -0.3f*Sin(sheet->m_angle); - }else{ - vx1 = 0.3f*Sin(sheet->m_angle); - vy1 = 0.3f*Cos(sheet->m_angle); - vx2 = 0.3f*Cos(sheet->m_angle); - vy2 = -0.3f*Sin(sheet->m_angle); - } - - int v = TempBufferVerticesStored; - RwIm3DVertexSetPos(&TempBufferRenderVertices[v+0], pos.x + vx1 + vx2, pos.y + vy1 + vy2, pos.z); - RwIm3DVertexSetPos(&TempBufferRenderVertices[v+1], pos.x + vx1 - vx2, pos.y + vy1 - vy2, pos.z); - RwIm3DVertexSetPos(&TempBufferRenderVertices[v+2], pos.x - vx1 + vx2, pos.y - vy1 + vy2, pos.z); - RwIm3DVertexSetPos(&TempBufferRenderVertices[v+3], pos.x - vx1 - vx2, pos.y - vy1 - vy2, pos.z); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+0], 255, 255, 255, alpha); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+1], 255, 255, 255, alpha); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+2], 255, 255, 255, alpha); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+3], 255, 255, 255, alpha); - RwIm3DVertexSetU(&TempBufferRenderVertices[v+0], 0.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[v+0], 0.0f); - RwIm3DVertexSetU(&TempBufferRenderVertices[v+1], 1.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[v+1], 0.0f); - RwIm3DVertexSetU(&TempBufferRenderVertices[v+2], 0.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[v+2], 1.0f); - RwIm3DVertexSetU(&TempBufferRenderVertices[v+3], 1.0f); - RwIm3DVertexSetV(&TempBufferRenderVertices[v+3], 1.0f); - - int i = TempBufferIndicesStored; - TempBufferRenderIndexList[i+0] = RubbishIndexList[0] + TempBufferVerticesStored; - TempBufferRenderIndexList[i+1] = RubbishIndexList[1] + TempBufferVerticesStored; - TempBufferRenderIndexList[i+2] = RubbishIndexList[2] + TempBufferVerticesStored; - TempBufferRenderIndexList[i+3] = RubbishIndexList[3] + TempBufferVerticesStored; - TempBufferRenderIndexList[i+4] = RubbishIndexList[4] + TempBufferVerticesStored; - TempBufferRenderIndexList[i+5] = RubbishIndexList[5] + TempBufferVerticesStored; - TempBufferVerticesStored += 4; - TempBufferIndicesStored += 6; - } - } - - if(TempBufferIndicesStored != 0){ - LittleTest(); - if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV)){ - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); - RwIm3DEnd(); - } - } - } - - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - - POP_RENDERGROUP(); -} - -void -CRubbish::StirUp(CVehicle *veh) -{ - if((CTimer::GetFrameCounter() ^ (veh->m_randomSeed&3)) == 0) - return; - - if(Abs(veh->GetPosition().x - TheCamera.GetPosition().x) < 20.0f && - Abs(veh->GetPosition().y - TheCamera.GetPosition().y) < 20.0f) - if(Abs(veh->GetMoveSpeed().x) > 0.05f || Abs(veh->GetMoveSpeed().y) > 0.05f){ - float speed = veh->GetMoveSpeed().Magnitude2D(); - if(speed > 0.05f){ - bool movingForward = DotProduct2D(veh->GetMoveSpeed(), veh->GetForward()) > 0.0f; - COneSheet *sheet = StartStaticsList.m_next; - CVector2D size = veh->GetColModel()->boundingBox.max; - - // Check all static sheets - while(sheet != &EndStaticsList){ - COneSheet *next = sheet->m_next; - CVector2D carToSheet = sheet->m_basePos - veh->GetPosition(); - float distFwd = DotProduct2D(carToSheet, veh->GetForward()); - - // sheet has to be a bit behind car - if(movingForward && distFwd < -0.5f*size.y && distFwd > -1.5f*size.y || - !movingForward && distFwd > 0.5f*size.y && distFwd < 1.5f*size.y){ - float distSide = Abs(DotProduct2D(carToSheet, veh->GetRight())); - if(distSide < 1.5*size.x){ - // Check with higher speed for sheet directly behind car - float speedToCheck = distSide < size.x ? speed : speed*0.5f; - if(speedToCheck > 0.05f){ - sheet->m_state = 2; - if(speedToCheck > 0.15f) - sheet->m_animationType = 2; - else - sheet->m_animationType = 1; - sheet->m_moveDuration = 2000; - sheet->m_xDist = veh->GetMoveSpeed().x; - sheet->m_yDist = veh->GetMoveSpeed().y; - float dist = Sqrt(SQR(sheet->m_xDist)+SQR(sheet->m_yDist)); - sheet->m_xDist *= 25.0f*speed/dist; - sheet->m_yDist *= 25.0f*speed/dist; - sheet->m_animHeight = 3.0f*speed; - sheet->m_moveStart = CTimer::GetTimeInMilliseconds(); - float tx = sheet->m_basePos.x + sheet->m_xDist; - float ty = sheet->m_basePos.y + sheet->m_yDist; - float tz = sheet->m_basePos.z + 3.0f; - sheet->m_targetZ = CWorld::FindGroundZFor3DCoord(tx, ty, tz, nil) + 0.1f; - sheet->RemoveFromList(); - sheet->AddToList(&StartMoversList); - } - } - } - - sheet = next; - } - } - } -} - -static float aAnimations[3][34] = { - { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, - - // Normal move - { 0.0f, 0.05f, 0.12f, 0.25f, 0.42f, 0.57f, 0.68f, 0.8f, 0.86f, 0.9f, 0.93f, 0.95f, 0.96f, 0.97f, 0.98f, 0.99f, 1.0f, // XY movemnt - 0.15f, 0.35f, 0.6f, 0.9f, 1.2f, 1.25f, 1.3f, 1.2f, 1.1f, 0.95f, 0.8f, 0.6f, 0.45f, 0.3f, 0.2f, 0.1f, 0 }, // Z movement - - // Stirred up by fast vehicle - { 0.0f, 0.05f, 0.12f, 0.25f, 0.42f, 0.57f, 0.68f, 0.8f, 0.95f, 1.1f, 1.15f, 1.18f, 1.15f, 1.1f, 1.05f, 1.03f, 1.0f, - 0.15f, 0.35f, 0.6f, 0.9f, 1.2f, 1.25f, 1.3f, 1.2f, 1.1f, 0.95f, 0.8f, 0.6f, 0.45f, 0.3f, 0.2f, 0.1f, 0 } -}; - -void -CRubbish::Update(void) -{ - bool foundGround; - - // FRAMETIME - if(bRubbishInvisible) - RubbishVisibility = Max(RubbishVisibility-5, 0); - else - RubbishVisibility = Min(RubbishVisibility+5, 255); - - // Spawn a new sheet - COneSheet *sheet = StartEmptyList.m_next; - if(sheet != &EndEmptyList){ - float spawnDist; - float spawnAngle; - - spawnDist = (CGeneral::GetRandomNumber()&0xFF)/256.0f + RUBBISH_MAX_DIST; - uint8 r = CGeneral::GetRandomNumber(); - if(r&1) - spawnAngle = (CGeneral::GetRandomNumber()&0xFF)/256.0f * 6.28f; - else - spawnAngle = (r-128)/160.0f + TheCamera.Orientation; - sheet->m_basePos.x = TheCamera.GetPosition().x + spawnDist*Sin(spawnAngle); - sheet->m_basePos.y = TheCamera.GetPosition().y + spawnDist*Cos(spawnAngle); - sheet->m_basePos.z = CWorld::FindGroundZFor3DCoord(sheet->m_basePos.x, sheet->m_basePos.y, TheCamera.GetPosition().z, &foundGround) + 0.1f; - if(foundGround){ - // Found ground, so add to statics list - sheet->m_angle = (CGeneral::GetRandomNumber()&0xFF)/256.0f * 6.28f; - sheet->m_state = 1; - if(CCullZones::FindAttributesForCoors(sheet->m_basePos, nil) & ATTRZONE_NORAIN) - sheet->m_isVisible = false; - else - sheet->m_isVisible = true; - sheet->RemoveFromList(); - sheet->AddToList(&StartStaticsList); - } - } - - // Process animation - sheet = StartMoversList.m_next; - while(sheet != &EndMoversList){ - uint32 currentTime = CTimer::GetTimeInMilliseconds() - sheet->m_moveStart; - if(currentTime < sheet->m_moveDuration){ - // Animation - int step = 16 * currentTime / sheet->m_moveDuration; // 16 steps in animation - int stepTime = sheet->m_moveDuration/16; // time in each step - float s = (float)(currentTime - stepTime*step) / stepTime; // position on step - float t = (float)currentTime / sheet->m_moveDuration; // position on total animation - // factors for xy and z-movment - float fxy = aAnimations[sheet->m_animationType][step]*(1.0f-s) + aAnimations[sheet->m_animationType][step+1]*s; - float fz = aAnimations[sheet->m_animationType][step+17]*(1.0f-s) + aAnimations[sheet->m_animationType][step+1+17]*s; - sheet->m_animatedPos.x = sheet->m_basePos.x + fxy*sheet->m_xDist; - sheet->m_animatedPos.y = sheet->m_basePos.y + fxy*sheet->m_yDist; - sheet->m_animatedPos.z = (1.0f-t)*sheet->m_basePos.z + t*sheet->m_targetZ + fz*sheet->m_animHeight; - sheet->m_angle += CTimer::GetTimeStep()*0.04f; - if(sheet->m_angle > 6.28f) - sheet->m_angle -= 6.28f; - sheet = sheet->m_next; - }else{ - // End of animation, back into statics list - sheet->m_basePos.x += sheet->m_xDist; - sheet->m_basePos.y += sheet->m_yDist; - sheet->m_basePos.z = sheet->m_targetZ; - sheet->m_state = 1; - sheet->m_isVisible = sheet->m_targetIsVisible; - - COneSheet *next = sheet->m_next; - sheet->RemoveFromList(); - sheet->AddToList(&StartStaticsList); - sheet = next; - } - } - - // Stir up a sheet by wind - // FRAMETIME - int freq; - if(CWeather::Wind < 0.1f) - freq = 31; - else if(CWeather::Wind < 0.4f) - freq = 7; - else if(CWeather::Wind < 0.7f) - freq = 1; - else - freq = 0; - if((CTimer::GetFrameCounter() & freq) == 0){ - // Pick a random sheet and set animation state if static - int i = CGeneral::GetRandomNumber() % NUM_RUBBISH_SHEETS; - if(aSheets[i].m_state == 1){ - aSheets[i].m_moveStart = CTimer::GetTimeInMilliseconds(); - aSheets[i].m_moveDuration = CWeather::Wind*1500.0f + 1000.0f; - aSheets[i].m_animHeight = 0.2f; - aSheets[i].m_xDist = 3.0f*CWeather::Wind; - aSheets[i].m_yDist = 3.0f*CWeather::Wind; - // Check if target position is ok - float tx = aSheets[i].m_basePos.x + aSheets[i].m_xDist; - float ty = aSheets[i].m_basePos.y + aSheets[i].m_yDist; - float tz = aSheets[i].m_basePos.z + 3.0f; - aSheets[i].m_targetZ = CWorld::FindGroundZFor3DCoord(tx, ty, tz, &foundGround) + 0.1f; - if(CCullZones::FindAttributesForCoors(CVector(tx, ty, aSheets[i].m_targetZ), nil) & ATTRZONE_NORAIN) - aSheets[i].m_targetIsVisible = false; - else - aSheets[i].m_targetIsVisible = true; - if(foundGround){ - // start animation - aSheets[i].m_state = 2; - aSheets[i].m_animationType = 1; - aSheets[i].RemoveFromList(); - aSheets[i].AddToList(&StartMoversList); - } - } - } - - // Remove sheets that are too far away - int i = (CTimer::GetFrameCounter()%(NUM_RUBBISH_SHEETS/4))*4; - int last = ((CTimer::GetFrameCounter()%(NUM_RUBBISH_SHEETS/4)) + 1)*4; - for(; i < last; i++){ - if(aSheets[i].m_state == 1 && - (aSheets[i].m_basePos - TheCamera.GetPosition()).MagnitudeSqr2D() > SQR(RUBBISH_MAX_DIST+1.0f)){ - aSheets[i].m_state = 0; - aSheets[i].RemoveFromList(); - aSheets[i].AddToList(&StartEmptyList); - } - } -} - -void -CRubbish::SetVisibility(bool visible) -{ - bRubbishInvisible = !visible; -} - -void -CRubbish::Init(void) -{ - int i; - for(i = 0; i < NUM_RUBBISH_SHEETS; i++){ - aSheets[i].m_state = 0; - if(i < NUM_RUBBISH_SHEETS-1) - aSheets[i].m_next = &aSheets[i+1]; - else - aSheets[i].m_next = &EndEmptyList; - if(i > 0) - aSheets[i].m_prev = &aSheets[i-1]; - else - aSheets[i].m_prev = &StartEmptyList; - } - - StartEmptyList.m_next = &aSheets[0]; - StartEmptyList.m_prev = nil; - EndEmptyList.m_next = nil; - EndEmptyList.m_prev = &aSheets[NUM_RUBBISH_SHEETS-1]; - - StartStaticsList.m_next = &EndStaticsList; - StartStaticsList.m_prev = nil; - EndStaticsList.m_next = nil; - EndStaticsList.m_prev = &StartStaticsList; - - StartMoversList.m_next = &EndMoversList; - StartMoversList.m_prev = nil; - EndMoversList.m_next = nil; - EndMoversList.m_prev = &StartMoversList; - - RubbishIndexList[0] = 0; - RubbishIndexList[1] = 1; - RubbishIndexList[2] = 2; - RubbishIndexList[3] = 1; - RubbishIndexList[4] = 3; - RubbishIndexList[5] = 2; - - CTxdStore::PushCurrentTxd(); - int slot = CTxdStore::FindTxdSlot("particle"); - CTxdStore::SetCurrentTxd(slot); - gpRubbishTexture[0] = RwTextureRead("gameleaf01_64", nil); - gpRubbishTexture[1] = RwTextureRead("gameleaf02_64", nil); - gpRubbishTexture[2] = RwTextureRead("newspaper01_64", nil); - gpRubbishTexture[3] = RwTextureRead("newspaper02_64", nil); - CTxdStore::PopCurrentTxd(); - RubbishVisibility = 255; - bRubbishInvisible = false; -} - -void -CRubbish::Shutdown(void) -{ - RwTextureDestroy(gpRubbishTexture[0]); - gpRubbishTexture[0] = nil; - RwTextureDestroy(gpRubbishTexture[1]); - gpRubbishTexture[1] = nil; - RwTextureDestroy(gpRubbishTexture[2]); - gpRubbishTexture[2] = nil; - RwTextureDestroy(gpRubbishTexture[3]); - gpRubbishTexture[3] = nil; -} diff --git a/src/render/Rubbish.h b/src/render/Rubbish.h deleted file mode 100644 index 5a4e479b..00000000 --- a/src/render/Rubbish.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -class CVehicle; - -enum { - // NB: not all values are allowed, check the code -#ifdef SQUEEZE_PERFORMANCE - NUM_RUBBISH_SHEETS = 32 -#else - NUM_RUBBISH_SHEETS = 64 -#endif -}; - -class COneSheet -{ -public: - CVector m_basePos; - CVector m_animatedPos; - float m_targetZ; - int8 m_state; - int8 m_animationType; - uint32 m_moveStart; - uint32 m_moveDuration; - float m_animHeight; - float m_xDist; - float m_yDist; - float m_angle; - bool m_isVisible; - bool m_targetIsVisible; - COneSheet *m_next; - COneSheet *m_prev; - - void AddToList(COneSheet *list); - void RemoveFromList(void); -}; - -class CRubbish -{ - static bool bRubbishInvisible; - static int RubbishVisibility; - static COneSheet aSheets[NUM_RUBBISH_SHEETS]; - static COneSheet StartEmptyList; - static COneSheet EndEmptyList; - static COneSheet StartStaticsList; - static COneSheet EndStaticsList; - static COneSheet StartMoversList; - static COneSheet EndMoversList; -public: - static void Render(void); - static void StirUp(CVehicle *veh); // CAutomobile on PS2 - static void Update(void); - static void SetVisibility(bool visible); - static void Init(void); - static void Shutdown(void); -}; - -extern RwTexture *gpRubbishTexture[4]; diff --git a/src/render/ShadowCamera.cpp b/src/render/ShadowCamera.cpp deleted file mode 100644 index f69c234f..00000000 --- a/src/render/ShadowCamera.cpp +++ /dev/null @@ -1,549 +0,0 @@ -#include "common.h" -#include "rwcore.h" -#include "ShadowCamera.h" -#include "RwHelper.h" - -#define TEXELOFFSET 0.5f - -RpAtomic *ShadowRenderCallBack(RpAtomic *atomic, void *data) -{ - RpAtomicCallBackRender savedCB = RpAtomicGetRenderCallBack(atomic); - RpAtomicSetRenderCallBack(atomic, AtomicDefaultRenderCallBack); - RpAtomicRender(atomic); - RpAtomicSetRenderCallBack(atomic, savedCB); - return atomic; -} - -CShadowCamera::CShadowCamera() -{ - m_pCamera = nil; - m_pTexture = nil; -} - -CShadowCamera::~CShadowCamera() -{ - Destroy(); -} - -void -CShadowCamera::Destroy() -{ - if ( m_pCamera ) - { - RwRaster *raster; - RwFrame *frame; - - frame = RwCameraGetFrame(m_pCamera); - - if ( frame ) - { - RwCameraSetFrame(m_pCamera, nil); - RwFrameDestroy(frame); - } - - raster = RwCameraGetZRaster(m_pCamera); - if ( raster ) - { - RwCameraSetZRaster(m_pCamera, nil); - RwRasterDestroy(raster); - } - - raster = RwCameraGetRaster(m_pCamera); - if ( raster ) - { - RwCameraSetRaster(m_pCamera, nil); - RwRasterDestroy(raster); - } - - if ( m_pTexture ) - { - RwTextureSetRaster(m_pTexture, nil); - RwTextureDestroy(m_pTexture); - m_pTexture = nil; - } - - RwCameraDestroy(m_pCamera); - m_pCamera = nil; - } - return; -} - -RwCamera * -CShadowCamera::Create(int32 rasterSize) -{ - int32 size = 1 << rasterSize; - - m_pCamera = RwCameraCreate(); - ASSERT(m_pCamera != nil); - - if ( m_pCamera ) - { - RwCameraSetFrame(m_pCamera, RwFrameCreate()); - - if( RwCameraGetFrame(m_pCamera) ) - { - RwRaster *zRaster = RwRasterCreate(size, size, 0, rwRASTERTYPEZBUFFER); - ASSERT(zRaster != nil); - - if ( zRaster ) - { - RwCameraSetZRaster(m_pCamera, zRaster); - - RwRaster *raster = RwRasterCreate(size, size, 0, rwRASTERTYPECAMERATEXTURE); - ASSERT(raster != nil); - - if ( raster ) - { - RwCameraSetRaster(m_pCamera, raster); - m_pTexture = RwTextureCreate(raster); - ASSERT(m_pTexture != nil); - - if ( m_pTexture ) - { - RwTextureSetAddressing(m_pTexture, rwTEXTUREADDRESSCLAMP); - RwTextureSetFilterMode(m_pTexture, rwFILTERLINEAR); - RwCameraSetProjection(m_pCamera, rwPARALLEL); - return (m_pCamera); - } - } - } - } - } - - Destroy(); - - return (nil); -} - -RwCamera * -CShadowCamera::SetFrustum(float objectRadius) -{ - ASSERT(m_pCamera != nil); - - RwV2d vw; - - RwCameraSetFarClipPlane (m_pCamera, 2.0f * objectRadius); - RwCameraSetNearClipPlane(m_pCamera, 0.001f * objectRadius); - - vw.x = objectRadius; - vw.y = objectRadius; - RwCameraSetViewWindow(m_pCamera, &vw); - - return m_pCamera; -} - -RwCamera * -CShadowCamera::SetLight(RpLight *light) -{ - ASSERT(light != nil); - ASSERT(m_pCamera != nil); - - RwFrame *camFrame = RwCameraGetFrame(m_pCamera); - RwMatrix *camMatrix = RwFrameGetMatrix(camFrame); - RwFrame *lightFrame = RpLightGetFrame(light); - RwMatrix *lightMatrix = RwFrameGetMatrix(lightFrame); - - *RwMatrixGetRight(camMatrix) = *RwMatrixGetRight(lightMatrix); - *RwMatrixGetUp(camMatrix) = *RwMatrixGetUp(lightMatrix); - *RwMatrixGetAt(camMatrix) = *RwMatrixGetAt(lightMatrix); - - RwMatrixUpdate(camMatrix); - RwFrameUpdateObjects(camFrame); - - return m_pCamera; -} - -RwCamera * -CShadowCamera::SetCenter(RwV3d *center) -{ - ASSERT(center != nil); - ASSERT(m_pCamera != nil); - - RwFrame *camFrame = RwCameraGetFrame(m_pCamera); - RwMatrix *camMatrix = RwFrameGetMatrix(camFrame); - - *RwMatrixGetPos(camMatrix) = *center; - - RwV3dIncrementScaled(RwMatrixGetPos(camMatrix), RwMatrixGetAt(camMatrix), -0.5f * RwCameraGetFarClipPlane(m_pCamera)); - - RwMatrixUpdate(camMatrix); - RwFrameUpdateObjects(camFrame); - RwFrameOrthoNormalize(camFrame); - - return m_pCamera; -} - -RwCamera * -CShadowCamera::Update(RpClump *clump) -{ - ASSERT(clump != nil); - ASSERT(m_pCamera != nil); - - RwUInt32 flags; - RpGeometry *geometry; - - RwRGBA bgColor = { 255, 255, 255, 0 }; - - RwCameraClear(m_pCamera, &bgColor, rwCAMERACLEARZ | rwCAMERACLEARIMAGE); - - if ( RwCameraBeginUpdate(m_pCamera) ) - { - geometry = RpAtomicGetGeometry(GetFirstAtomic(clump)); - ASSERT(geometry != nil); - - flags = RpGeometryGetFlags(geometry); - - RpGeometrySetFlags(geometry, flags & ~(rpGEOMETRYPRELIT|rpGEOMETRYLIGHT - |rpGEOMETRYTEXTURED|rpGEOMETRYTEXTURED2|rpGEOMETRYMODULATEMATERIALCOLOR)); - - RpClumpForAllAtomics(clump, ShadowRenderCallBack, nil); - - RpGeometrySetFlags(geometry, flags); - - InvertRaster(); - RwCameraEndUpdate(m_pCamera); - } - - return m_pCamera; -} - -RwCamera * -CShadowCamera::Update(RpAtomic *atomic) -{ - ASSERT(atomic != nil); - ASSERT(m_pCamera != nil); - - RwUInt32 flags; - RpGeometry *geometry; - - RwRGBA bgColor = { 255, 255, 255, 0 }; - - RwCameraClear(m_pCamera, &bgColor, rwCAMERACLEARZ | rwCAMERACLEARIMAGE); - - if ( RwCameraBeginUpdate(m_pCamera) ) - { - geometry = RpAtomicGetGeometry(atomic); - ASSERT(geometry != nil); - flags = RpGeometryGetFlags(geometry); - - RpGeometrySetFlags(geometry, flags & ~(rpGEOMETRYPRELIT|rpGEOMETRYLIGHT - |rpGEOMETRYTEXTURED|rpGEOMETRYTEXTURED2|rpGEOMETRYMODULATEMATERIALCOLOR|rpGEOMETRYNORMALS)); - - ShadowRenderCallBack(atomic, nil); - - RpGeometrySetFlags(geometry, flags); - - InvertRaster(); - RwCameraEndUpdate(m_pCamera); - } - - return m_pCamera; -} - -void -CShadowCamera::InvertRaster() -{ - ASSERT(m_pCamera != nil); - - RwIm2DVertex vx[4]; - float crw, crh; - RwRaster *raster; - float recipZ; - - raster = RwCameraGetRaster(m_pCamera); - ASSERT(raster != nil); - - crw = (float)RwRasterGetWidth(raster); - crh = (float)RwRasterGetHeight(raster); - - recipZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); - - RwIm2DVertexSetScreenX (&vx[0], 0.0f); - RwIm2DVertexSetScreenY (&vx[0], 0.0f); - RwIm2DVertexSetScreenZ (&vx[0], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetRecipCameraZ(&vx[0], recipZ); - RwIm2DVertexSetIntRGBA (&vx[0], 255, 255, 255, 255); - - RwIm2DVertexSetScreenX (&vx[1], 0.0f); - RwIm2DVertexSetScreenY (&vx[1], crh); - RwIm2DVertexSetScreenZ (&vx[1], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetRecipCameraZ(&vx[1], recipZ); - RwIm2DVertexSetIntRGBA (&vx[1], 255, 255, 255, 255); - - RwIm2DVertexSetScreenX (&vx[2], crw); - RwIm2DVertexSetScreenY (&vx[2], 0.0f); - RwIm2DVertexSetScreenZ (&vx[2], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetRecipCameraZ(&vx[2], recipZ); - RwIm2DVertexSetIntRGBA (&vx[2], 255, 255, 255, 255); - - RwIm2DVertexSetScreenX (&vx[3], crw); - RwIm2DVertexSetScreenY (&vx[3], crh); - RwIm2DVertexSetScreenZ (&vx[3], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetRecipCameraZ(&vx[3], recipZ); - RwIm2DVertexSetIntRGBA (&vx[3], 255, 255, 255, 255); - - - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)nil); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDINVDESTCOLOR); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO); - - RwIm2DRenderPrimitive(rwPRIMTYPETRISTRIP, vx, 4); - - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); -} - -RwRaster * -CShadowCamera::MakeGradientRaster() -{ - ASSERT(m_pCamera != nil); - - RwIm2DVertex vx[2]; - - if ( !m_pCamera ) - return nil; - - float recipCamZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); - - RwRaster *raster = RwCameraGetRaster(m_pCamera); - ASSERT(raster != nil); - - float width = (float)RwRasterGetWidth(raster); - float height = (float)RwRasterGetHeight(raster); - - if ( height < 1 ) - return nil; - - if ( RwCameraBeginUpdate(m_pCamera) ) - { - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)rwFILTERNAFILTERMODE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDINVDESTCOLOR); - RwRenderStateSet(rwRENDERSTATESHADEMODE, (void *)rwSHADEMODEFLAT); - - float color = 255.0f; - float step = (-191.0f / height); - - for ( int32 i = 0; i < height; i++ ) - { - RwIm2DVertexSetScreenX (&vx[0], 0.0f); - RwIm2DVertexSetScreenY (&vx[0], i); - RwIm2DVertexSetScreenZ (&vx[0], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetRecipCameraZ(&vx[0], recipCamZ); - RwIm2DVertexSetIntRGBA (&vx[0], (uint32)color, (uint32)color, (uint32)color, (uint32)color); - - RwIm2DVertexSetScreenX (&vx[1], width - 1); - RwIm2DVertexSetScreenY (&vx[1], i); - RwIm2DVertexSetScreenZ (&vx[1], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetRecipCameraZ(&vx[1], recipCamZ); - RwIm2DVertexSetIntRGBA (&vx[1], (uint32)color, (uint32)color, (uint32)color, (uint32)color); - - RwIm2DRenderLine(vx, 2, 0, 1); - - color += step; - } - - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATESHADEMODE, (void *)rwSHADEMODEGOURAUD); - - RwCameraEndUpdate(m_pCamera); - } - - return raster; -} - -RwRaster * -CShadowCamera::RasterResample(RwRaster *dstRaster) -{ - ASSERT(dstRaster != nil); - ASSERT(m_pCamera != nil); - - if ( !m_pCamera ) - return nil; - - RwRaster *raster = RwCameraGetRaster(m_pCamera); - ASSERT(raster != nil); - - float size = (float) RwRasterGetWidth(raster); - float uvOffset = TEXELOFFSET / size; - float recipCamZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); - - if ( RwCameraBeginUpdate(m_pCamera) ) - { - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)dstRaster); - - Im2DRenderQuad(0.0f, 0.0f, size, size, RwIm2DGetNearScreenZ(), recipCamZ, uvOffset); - - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - - RwCameraEndUpdate(m_pCamera); - } - - return raster; -} - -RwRaster * -CShadowCamera::RasterBlur(RwRaster *dstRaster, int32 numPasses) -{ - ASSERT(dstRaster != nil); - ASSERT(m_pCamera != nil); - - if ( !m_pCamera ) - return nil; - - RwRaster *raster = RwCameraGetRaster(m_pCamera); - ASSERT(raster != nil); - - float size = (float) RwRasterGetWidth(dstRaster); - float recipCamZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); - - for (int i = 0; i < numPasses; i++ ) - { - RwCameraSetRaster(m_pCamera, raster); - - if ( RwCameraBeginUpdate(m_pCamera) ) - { - if ( i == 0 ) - { - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR); - } - - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)dstRaster); - Im2DRenderQuad(0.0f, 0.0f, size, size, RwIm2DGetNearScreenZ(), recipCamZ, 1.0f / size); - RwCameraEndUpdate(m_pCamera); - } - - RwCameraSetRaster(m_pCamera, dstRaster); - - if ( RwCameraBeginUpdate(m_pCamera) ) - { - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)raster); - Im2DRenderQuad(0.0f, 0.0f, size, size, RwIm2DGetNearScreenZ(), recipCamZ, 0); - - if ( i == numPasses - 1 ) - { - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - } - - RwCameraEndUpdate(m_pCamera); - } - } - - RwCameraSetRaster(m_pCamera, raster); - - return dstRaster; -} - -RwRaster * -CShadowCamera::RasterGradient(RwRaster *dstRaster) -{ - ASSERT(dstRaster != nil); - ASSERT(m_pCamera != nil); - - RwRaster *raster = RwCameraGetRaster(m_pCamera); - ASSERT(raster != nil); - - float size = (float)RwRasterGetWidth(dstRaster); - float recipCamZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); - - RwCameraSetRaster(m_pCamera, dstRaster); - - if ( RwCameraBeginUpdate(m_pCamera) ) - { - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDZERO); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDSRCCOLOR); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)raster); - - Im2DRenderQuad(0, 0, size, size, RwIm2DGetNearScreenZ(), recipCamZ, 0); - - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - - RwCameraEndUpdate(m_pCamera); - } - - RwCameraSetRaster(m_pCamera, raster); - - return dstRaster; -} - -RwRaster *CShadowCamera::DrawOutlineBorder(RwRGBA const& color) -{ - ASSERT(m_pCamera != nil); - - RwIm2DVertex vx[4]; - RwImVertexIndex ix[5]; - - RwRaster *raster = RwCameraGetRaster(m_pCamera); - ASSERT(raster != nil); - - float size = (float)RwRasterGetWidth(raster) - 1.0f; - float recipCamZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); - - RwIm2DVertexSetScreenX (&vx[0], 0.0f); - RwIm2DVertexSetScreenY (&vx[0], 0.0f); - RwIm2DVertexSetScreenZ (&vx[0], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetIntRGBA (&vx[0], color.red, color.green, color.blue, color.alpha); - RwIm2DVertexSetRecipCameraZ(&vx[0], recipCamZ); - - RwIm2DVertexSetScreenX (&vx[1], size); - RwIm2DVertexSetScreenY (&vx[1], 0.0f); - RwIm2DVertexSetScreenZ (&vx[1], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetIntRGBA (&vx[1], color.red, color.green, color.blue, color.alpha); - RwIm2DVertexSetRecipCameraZ(&vx[1], recipCamZ); - - RwIm2DVertexSetScreenX (&vx[2], size); - RwIm2DVertexSetScreenY (&vx[2], size); - RwIm2DVertexSetScreenZ (&vx[2], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetIntRGBA (&vx[2], color.red, color.green, color.blue, color.alpha); - RwIm2DVertexSetRecipCameraZ(&vx[2], recipCamZ); - - RwIm2DVertexSetScreenX (&vx[3], 0.0f); - RwIm2DVertexSetScreenY (&vx[3], size); - RwIm2DVertexSetScreenZ (&vx[3], RwIm2DGetNearScreenZ()); - RwIm2DVertexSetIntRGBA (&vx[3], color.red, color.green, color.blue, color.alpha); - RwIm2DVertexSetRecipCameraZ(&vx[3], recipCamZ); - - ix[0] = 0; - ix[4] = 0; - ix[1] = 1; - ix[2] = 2; - ix[3] = 3; - - if ( RwCameraBeginUpdate(m_pCamera) ) - { - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)nil); - - RwIm2DRenderIndexedPrimitive(rwPRIMTYPEPOLYLINE, vx, 4, ix, 5); - - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); - - RwCameraEndUpdate(m_pCamera); - } - - return raster; -} \ No newline at end of file diff --git a/src/render/ShadowCamera.h b/src/render/ShadowCamera.h deleted file mode 100644 index a2149db7..00000000 --- a/src/render/ShadowCamera.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - - -class CShadowCamera -{ -public: - RwCamera *m_pCamera; - RwTexture *m_pTexture; - - CShadowCamera(); - ~CShadowCamera(); - - RwCamera *Create(int32 rasterSize); - void Destroy(); - - RwCamera *SetFrustum(float objectRadius); - RwCamera *SetLight(RpLight *light); - RwCamera *SetCenter(RwV3d *center); - - RwCamera *Update(RpClump *clump); - RwCamera *Update(RpAtomic *atomic); - - void InvertRaster(); - - RwRaster* GetRwRenderRaster() - { - return RwCameraGetRaster(m_pCamera); - } - - // ShadowRasterRender(RwV2d *) - // ApplyAlphaMapToRaster(void) - - RwRaster *MakeGradientRaster(); - - RwTexture *GetRwRenderTexture() - { - return m_pTexture; - } - - RwRaster* GetRwZRaster() - { - return RwCameraGetZRaster(m_pCamera); - } - - RwRaster *RasterResample(RwRaster *dstRaster); - RwRaster *RasterBlur(RwRaster *dstRaster, int32 numPasses); - RwRaster *RasterGradient(RwRaster *dstRaster); - RwRaster *DrawOutlineBorder(RwRGBA const& color); - - RwCamera *GetRwCamera() - { - return m_pCamera; - } -}; \ No newline at end of file diff --git a/src/render/Shadows.cpp b/src/render/Shadows.cpp deleted file mode 100644 index dd87bff6..00000000 --- a/src/render/Shadows.cpp +++ /dev/null @@ -1,2520 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "TxdStore.h" -#include "Timer.h" -#include "Camera.h" -#include "Timecycle.h" -#include "CutsceneMgr.h" -#include "Automobile.h" -#include "Bike.h" -#include "Ped.h" -#include "PlayerPed.h" -#include "World.h" -#include "Weather.h" -#include "ModelIndices.h" -#include "RenderBuffer.h" -#ifdef FIX_BUGS -#include "Replay.h" -#endif -#include "PointLights.h" -#include "SpecialFX.h" -#include "Script.h" -#include "TimeStep.h" -#include "Shadows.h" -#include "CutsceneObject.h" -#include "CutsceneShadow.h" -#include "Clock.h" -#include "VarConsole.h" - -#ifdef DEBUGMENU -//SETTWEAKPATH("Shadows"); -//TWEAKBOOL(gbPrintShite); -#endif - -RwImVertexIndex ShadowIndexList[24]; - -RwTexture *gpShadowCarTex; -RwTexture *gpShadowPedTex; -RwTexture *gpShadowHeliTex; -RwTexture *gpShadowBikeTex; -RwTexture *gpShadowBaronTex; -RwTexture *gpShadowExplosionTex; -RwTexture *gpShadowHeadLightsTex; -RwTexture *gpOutline1Tex; -RwTexture *gpOutline2Tex; -RwTexture *gpOutline3Tex; -RwTexture *gpBloodPoolTex; -RwTexture *gpReflectionTex; -RwTexture *gpWalkDontTex; -RwTexture *gpCrackedGlassTex; -RwTexture *gpPostShadowTex; -RwTexture *gpGoalTex; - -int16 CShadows::ShadowsStoredToBeRendered; -CStoredShadow CShadows::asShadowsStored [MAX_STOREDSHADOWS]; -CPolyBunch CShadows::aPolyBunches [MAX_POLYBUNCHES]; -CStaticShadow CShadows::aStaticShadows [MAX_STATICSHADOWS]; -CPolyBunch *CShadows::pEmptyBunchList; -CPermanentShadow CShadows::aPermanentShadows[MAX_PERMAMENTSHADOWS]; - -#ifndef MASTER -bool gbCountPolysInShadow; -#endif - -void -CShadows::Init(void) -{ - CTxdStore::PushCurrentTxd(); - - int32 slut = CTxdStore::FindTxdSlot("particle"); - CTxdStore::SetCurrentTxd(slut); - - gpShadowCarTex = RwTextureRead("shad_car", nil); - gpShadowPedTex = RwTextureRead("shad_ped", nil); - gpShadowHeliTex = RwTextureRead("shad_heli", nil); - gpShadowBikeTex = RwTextureRead("shad_bike", nil); - gpShadowBaronTex = RwTextureRead("shad_rcbaron", nil); - gpShadowExplosionTex = RwTextureRead("shad_exp", nil); - gpShadowHeadLightsTex = RwTextureRead("headlight", nil); - gpOutline1Tex = RwTextureRead("outline_64", nil); - gpOutline2Tex = RwTextureRead("outline2_64", nil); - gpOutline3Tex = RwTextureRead("outline3_64", nil); - gpBloodPoolTex = RwTextureRead("bloodpool_64", nil); - gpReflectionTex = RwTextureRead("reflection01", nil); - gpWalkDontTex = RwTextureRead("walk_dont", nil); - gpCrackedGlassTex = RwTextureRead("wincrack_32", nil); - gpPostShadowTex = RwTextureRead("lamp_shad_64", nil); - - CTxdStore::PopCurrentTxd(); - - ASSERT(gpShadowCarTex != nil); - ASSERT(gpShadowPedTex != nil); - ASSERT(gpShadowHeliTex != nil); - ASSERT(gpShadowBikeTex != nil); - ASSERT(gpShadowBaronTex != nil); - ASSERT(gpShadowExplosionTex != nil); - ASSERT(gpShadowHeadLightsTex != nil); - ASSERT(gpOutline1Tex != nil); - ASSERT(gpOutline2Tex != nil); - ASSERT(gpOutline3Tex != nil); - ASSERT(gpBloodPoolTex != nil); - ASSERT(gpReflectionTex != nil); - ASSERT(gpWalkDontTex != nil); - ASSERT(gpCrackedGlassTex != nil); - ASSERT(gpPostShadowTex != nil); - - - ShadowIndexList[0] = 0; - ShadowIndexList[1] = 2; - ShadowIndexList[2] = 1; - - ShadowIndexList[3] = 0; - ShadowIndexList[4] = 3; - ShadowIndexList[5] = 2; - - ShadowIndexList[6] = 0; - ShadowIndexList[7] = 4; - ShadowIndexList[8] = 3; - - ShadowIndexList[9] = 0; - ShadowIndexList[10] = 5; - ShadowIndexList[11] = 4; - - ShadowIndexList[12] = 0; - ShadowIndexList[13] = 6; - ShadowIndexList[14] = 5; - - ShadowIndexList[15] = 0; - ShadowIndexList[16] = 7; - ShadowIndexList[17] = 6; - - ShadowIndexList[18] = 0; - ShadowIndexList[19] = 8; - ShadowIndexList[20] = 7; - - ShadowIndexList[21] = 0; - ShadowIndexList[22] = 9; - ShadowIndexList[23] = 8; - - - for ( int32 i = 0; i < MAX_STATICSHADOWS; i++ ) - { - aStaticShadows[i].m_nId = 0; - aStaticShadows[i].m_pPolyBunch = nil; - } - - pEmptyBunchList = &aPolyBunches[0]; - - for ( int32 i = 0; i < MAX_POLYBUNCHES; i++ ) - { - if ( i == MAX_POLYBUNCHES - 1 ) - aPolyBunches[i].m_pNext = nil; - else - aPolyBunches[i].m_pNext = &aPolyBunches[i + 1]; - } - - for ( int32 i = 0; i < MAX_PERMAMENTSHADOWS; i++ ) - { - aPermanentShadows[i].m_nType = SHADOWTYPE_NONE; - } - -#ifndef MASTER - VarConsole.Add("Count polys in shadow", &gbCountPolysInShadow, true); -#endif -} - -void -CShadows::Shutdown(void) -{ - ASSERT(gpShadowCarTex != nil); - ASSERT(gpShadowPedTex != nil); - ASSERT(gpShadowHeliTex != nil); - ASSERT(gpShadowBikeTex != nil); - ASSERT(gpShadowBaronTex != nil); - ASSERT(gpShadowExplosionTex != nil); - ASSERT(gpShadowHeadLightsTex != nil); - ASSERT(gpOutline1Tex != nil); - ASSERT(gpOutline2Tex != nil); - ASSERT(gpOutline3Tex != nil); - ASSERT(gpBloodPoolTex != nil); - ASSERT(gpReflectionTex != nil); - ASSERT(gpWalkDontTex != nil); - ASSERT(gpCrackedGlassTex != nil); - ASSERT(gpPostShadowTex != nil); - - RwTextureDestroy(gpShadowCarTex); - RwTextureDestroy(gpShadowPedTex); - RwTextureDestroy(gpShadowHeliTex); - RwTextureDestroy(gpShadowBikeTex); - RwTextureDestroy(gpShadowBaronTex); - RwTextureDestroy(gpShadowExplosionTex); - RwTextureDestroy(gpShadowHeadLightsTex); - RwTextureDestroy(gpOutline1Tex); - RwTextureDestroy(gpOutline2Tex); - RwTextureDestroy(gpOutline3Tex); - RwTextureDestroy(gpBloodPoolTex); - RwTextureDestroy(gpReflectionTex); - RwTextureDestroy(gpWalkDontTex); - RwTextureDestroy(gpCrackedGlassTex); - RwTextureDestroy(gpPostShadowTex); -} - -void -CShadows::AddPermanentShadow(uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, - float fFrontX, float fFrontY, float fSideX, float fSideY, - int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, - float fZDistance, uint32 nTime, float fScale) -{ - ASSERT(pTexture != nil); - ASSERT(pPosn != nil); - - - // find free slot - int32 nSlot = 0; - while ( nSlot < MAX_PERMAMENTSHADOWS && aPermanentShadows[nSlot].m_nType != SHADOWTYPE_NONE ) - nSlot++; - - if ( nSlot < MAX_PERMAMENTSHADOWS ) - { - aPermanentShadows[nSlot].m_nType = ShadowType; - aPermanentShadows[nSlot].m_pTexture = pTexture; - aPermanentShadows[nSlot].m_vecPos = *pPosn; - aPermanentShadows[nSlot].m_vecFront.x = fFrontX; - aPermanentShadows[nSlot].m_vecFront.y = fFrontY; - aPermanentShadows[nSlot].m_vecSide.x = fSideX; - aPermanentShadows[nSlot].m_vecSide.y = fSideY; - aPermanentShadows[nSlot].m_nIntensity = nIntensity; - aPermanentShadows[nSlot].m_nRed = nRed; - aPermanentShadows[nSlot].m_nGreen = nGreen; - aPermanentShadows[nSlot].m_nBlue = nBlue; - aPermanentShadows[nSlot].m_fZDistance = fZDistance; - aPermanentShadows[nSlot].m_nLifeTime = nTime; - aPermanentShadows[nSlot].m_nTimeCreated = CTimer::GetTimeInMilliseconds(); - } -} - -bool -CShadows::StoreStaticShadow(uint32 nID, uint8 ShadowType, RwTexture *pTexture, Const CVector *pPosn, - float fFrontX, float fFrontY, float fSideX, float fSideY, - int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, - float fZDistance, float fScale, float fDrawDistance, bool bTempShadow, float fUpDistance) -{ - ASSERT(pPosn != nil); - - float fDistToCamSqr = (*pPosn - TheCamera.GetPosition()).MagnitudeSqr2D(); - - if ( SQR(fDrawDistance) > fDistToCamSqr || fDrawDistance == 0.0f ) - { - if ( fDrawDistance != 0.0f ) - { - float fDistToCam = Sqrt(fDistToCamSqr); - - if ( fDistToCam >= (fDrawDistance*(1.0f-(1.0f/4.0f))) ) - { - //fDistToCam == 0 -> 4 - //fDistToCam == fDrawDistance -> 0 - float fMult = 1.0f - (4.0f / fDrawDistance) * (fDistToCam - (fDrawDistance*(1.0f-(1.0f/4.0f)))); - - nIntensity = (int32)(nIntensity * fMult); - nRed = (int32)(nRed * fMult); - nGreen = (int32)(nGreen * fMult); - nBlue = (int32)(nBlue * fMult); - } - } - - int32 nSlot; - - nSlot = 0; - while ( nSlot < MAX_STATICSHADOWS && !(nID == aStaticShadows[nSlot].m_nId && aStaticShadows[nSlot].m_pPolyBunch != nil) ) - nSlot++; - - if ( nSlot < MAX_STATICSHADOWS ) - { - if ( Abs(pPosn->x - aStaticShadows[nSlot].m_vecPosn.x) < fUpDistance - && Abs(pPosn->y - aStaticShadows[nSlot].m_vecPosn.y) < fUpDistance ) - { - aStaticShadows[nSlot].m_bJustCreated = true; - aStaticShadows[nSlot].m_nType = ShadowType; - aStaticShadows[nSlot].m_pTexture = pTexture; - aStaticShadows[nSlot].m_nIntensity = nIntensity; - aStaticShadows[nSlot].m_nRed = nRed; - aStaticShadows[nSlot].m_nGreen = nGreen; - aStaticShadows[nSlot].m_nBlue = nBlue; - aStaticShadows[nSlot].m_fZDistance = fZDistance; - aStaticShadows[nSlot].m_fScale = fScale; - aStaticShadows[nSlot].m_bTemp = bTempShadow; - aStaticShadows[nSlot].m_nTimeCreated = CTimer::GetTimeInMilliseconds(); - - return true; - } - else if ( Abs(pPosn->x - aStaticShadows[nSlot].m_vecPosn.x) < 0.05f - && Abs(pPosn->y - aStaticShadows[nSlot].m_vecPosn.y) < 0.05f - && Abs(pPosn->z - aStaticShadows[nSlot].m_vecPosn.z) < 2.0f - - && fFrontX == aStaticShadows[nSlot].m_vecFront.x - && fFrontY == aStaticShadows[nSlot].m_vecFront.y - && fSideX == aStaticShadows[nSlot].m_vecSide.x - && fSideY == aStaticShadows[nSlot].m_vecSide.y ) - { - aStaticShadows[nSlot].m_bJustCreated = true; - aStaticShadows[nSlot].m_nType = ShadowType; - aStaticShadows[nSlot].m_pTexture = pTexture; - aStaticShadows[nSlot].m_nIntensity = nIntensity; - aStaticShadows[nSlot].m_nRed = nRed; - aStaticShadows[nSlot].m_nGreen = nGreen; - aStaticShadows[nSlot].m_nBlue = nBlue; - aStaticShadows[nSlot].m_fZDistance = fZDistance; - aStaticShadows[nSlot].m_fScale = fScale; - aStaticShadows[nSlot].m_bTemp = bTempShadow; - aStaticShadows[nSlot].m_nTimeCreated = CTimer::GetTimeInMilliseconds(); - - return true; - } - else - { - aStaticShadows[nSlot].Free(); - - aStaticShadows[nSlot].m_nId = nID; - aStaticShadows[nSlot].m_nType = ShadowType; - aStaticShadows[nSlot].m_pTexture = pTexture; - aStaticShadows[nSlot].m_nIntensity = nIntensity; - aStaticShadows[nSlot].m_nRed = nRed; - aStaticShadows[nSlot].m_nGreen = nGreen; - aStaticShadows[nSlot].m_nBlue = nBlue; - aStaticShadows[nSlot].m_fZDistance = fZDistance; - aStaticShadows[nSlot].m_fScale = fScale; - aStaticShadows[nSlot].m_vecPosn = *pPosn; - aStaticShadows[nSlot].m_vecFront.x = fFrontX; - aStaticShadows[nSlot].m_vecFront.y = fFrontY; - aStaticShadows[nSlot].m_vecSide.x = fSideX; - aStaticShadows[nSlot].m_vecSide.y = fSideY; - aStaticShadows[nSlot].m_bJustCreated = true; - aStaticShadows[nSlot].m_bTemp = bTempShadow; - aStaticShadows[nSlot].m_nTimeCreated = CTimer::GetTimeInMilliseconds(); - - GeneratePolysForStaticShadow(nSlot); - - return aStaticShadows[nSlot].m_pPolyBunch != nil; - } - } - else - { - nSlot = 0; - while ( nSlot < MAX_STATICSHADOWS && aStaticShadows[nSlot].m_pPolyBunch != nil ) - nSlot++; - - if ( nSlot != MAX_STATICSHADOWS ) - { - aStaticShadows[nSlot].m_nId = nID; - aStaticShadows[nSlot].m_nType = ShadowType; - aStaticShadows[nSlot].m_pTexture = pTexture; - aStaticShadows[nSlot].m_nIntensity = nIntensity; - aStaticShadows[nSlot].m_nRed = nRed; - aStaticShadows[nSlot].m_nGreen = nGreen; - aStaticShadows[nSlot].m_nBlue = nBlue; - aStaticShadows[nSlot].m_fZDistance = fZDistance; - aStaticShadows[nSlot].m_fScale = fScale; - aStaticShadows[nSlot].m_vecPosn = *pPosn; - aStaticShadows[nSlot].m_vecFront.x = fFrontX; - aStaticShadows[nSlot].m_vecFront.y = fFrontY; - aStaticShadows[nSlot].m_vecSide.x = fSideX; - aStaticShadows[nSlot].m_vecSide.y = fSideY; - aStaticShadows[nSlot].m_bJustCreated = true; - aStaticShadows[nSlot].m_bTemp = bTempShadow; - aStaticShadows[nSlot].m_nTimeCreated = CTimer::GetTimeInMilliseconds(); - - GeneratePolysForStaticShadow(nSlot); - - return aStaticShadows[nSlot].m_pPolyBunch != nil; - } - } - } - - return true; -} - -void -CShadows::StoreShadowToBeRendered(uint8 ShadowTexture, CVector *pPosn, - float fFrontX, float fFrontY, float fSideX, float fSideY, - int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue) -{ - ASSERT(pPosn != nil); - - switch ( ShadowTexture ) - { - case SHADOWTEX_NONE: - { - break; - } - - case SHADOWTEX_CAR: - { - StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowCarTex, pPosn, - fFrontX, fFrontY, fSideX, fSideY, - nIntensity, nRed, nGreen, nBlue, - 15.0f, false, 1.0f, nil, false); - - break; - } - - case SHADOWTEX_PED: - { - StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowPedTex, pPosn, - fFrontX, fFrontY, fSideX, fSideY, - nIntensity, nRed, nGreen, nBlue, - 15.0f, false, 1.0f, nil, false); - - break; - } - - case SHADOWTEX_EXPLOSION: - { - StoreShadowToBeRendered(SHADOWTYPE_ADDITIVE, gpShadowExplosionTex, pPosn, - fFrontX, fFrontY, fSideX, fSideY, - nIntensity, nRed, nGreen, nBlue, - 15.0f, false, 1.0f, nil, false); - - break; - } - - case SHADOWTEX_HELI: - { - StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowHeliTex, pPosn, - fFrontX, fFrontY, fSideX, fSideY, - nIntensity, nRed, nGreen, nBlue, - 15.0f, false, 1.0f, nil, false); - - break; - } - - case SHADOWTEX_HEADLIGHTS: - { - StoreShadowToBeRendered(SHADOWTYPE_ADDITIVE, gpShadowHeadLightsTex, pPosn, - fFrontX, fFrontY, fSideX, fSideY, - nIntensity, nRed, nGreen, nBlue, - 15.0f, false, 1.0f, nil, false); - - break; - } - - case SHADOWTEX_BLOOD: - { - StoreShadowToBeRendered(SHADOWTYPE_DARK, gpBloodPoolTex, pPosn, - fFrontX, fFrontY, fSideX, fSideY, - nIntensity, nRed, 150, 0, - 15.0f, false, 1.0f, nil, false); - - break; - } - } - - //ASSERT(false); -} - -void -CShadows::StoreShadowToBeRendered(uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, - float fFrontX, float fFrontY, float fSideX, float fSideY, - int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, - float fZDistance, bool bDrawOnWater, float fScale, CCutsceneShadow *pShadow, bool bDrawOnBuildings) -{ - ASSERT(pTexture != nil); - ASSERT(pPosn != nil); - - if ( ShadowsStoredToBeRendered < MAX_STOREDSHADOWS ) - { - asShadowsStored[ShadowsStoredToBeRendered].m_ShadowType = ShadowType; - asShadowsStored[ShadowsStoredToBeRendered].m_pTexture = pTexture; - asShadowsStored[ShadowsStoredToBeRendered].m_vecPos = *pPosn; - asShadowsStored[ShadowsStoredToBeRendered].m_vecFront.x = fFrontX; - asShadowsStored[ShadowsStoredToBeRendered].m_vecFront.y = fFrontY; - asShadowsStored[ShadowsStoredToBeRendered].m_vecSide.x = fSideX; - asShadowsStored[ShadowsStoredToBeRendered].m_vecSide.y = fSideY; - asShadowsStored[ShadowsStoredToBeRendered].m_nIntensity = nIntensity; - asShadowsStored[ShadowsStoredToBeRendered].m_nRed = nRed; - asShadowsStored[ShadowsStoredToBeRendered].m_nGreen = nGreen; - asShadowsStored[ShadowsStoredToBeRendered].m_nBlue = nBlue; - asShadowsStored[ShadowsStoredToBeRendered].m_fZDistance = fZDistance; - asShadowsStored[ShadowsStoredToBeRendered].m_nFlags.bDrawOnWater = bDrawOnWater; - asShadowsStored[ShadowsStoredToBeRendered].m_nFlags.bDrawOnBuildings = bDrawOnBuildings; - asShadowsStored[ShadowsStoredToBeRendered].m_fScale = fScale; - asShadowsStored[ShadowsStoredToBeRendered].m_pCutsceneShadow = pShadow; - - ShadowsStoredToBeRendered++; - } -} - - -void -CShadows::StoreShadowForVehicle(CVehicle *pCar, VEH_SHD_TYPE type) -{ - ASSERT(pCar != nil); - - if ( CTimeCycle::GetShadowStrength() != 0 ) - { - CVector CarPos = pCar->GetPosition(); - float fDistToCamSqr = (CarPos - TheCamera.GetPosition()).MagnitudeSqr2D(); - - if ( CCutsceneMgr::IsRunning() ) - fDistToCamSqr /= SQR(TheCamera.LODDistMultiplier) * 4.0f; - - float fDrawDistance; - switch ( type ) - { - case VEH_SHD_TYPE_SEAPLANE: - case VEH_SHD_TYPE_RCPLANE: - fDrawDistance = 144.0f; - break; - - case VEH_SHD_TYPE_HELI: - fDrawDistance = 144.0f; - break; - - default: - fDrawDistance = 18.0f; - break; - } - - if ( fDistToCamSqr < SQR(fDrawDistance) ) - { - float fDistToCam = Sqrt(fDistToCamSqr); - - //fDistToCam == 0 -> 4 - //fDistToCam == fDrawDistance -> 0 - float fMult = 1.0f - (fDistToCam - (fDrawDistance*(1.0f-(1.0f/4.0f)))) / (fDrawDistance*(1.0f/4.0f)); - - int32 nColorStrength; - - if ( fDistToCam >= (fDrawDistance*(1.0f-(1.0f/4.0f))) ) - nColorStrength = (int32)(fMult * CTimeCycle::GetShadowStrength()); - else - nColorStrength = CTimeCycle::GetShadowStrength(); - - - float fVehicleHeight = pCar->GetColModel()->boundingBox.GetSize().y; - float fVehicleWidth = pCar->GetColModel()->boundingBox.GetSize().x; - - float size = 1.0f; - - if ( pCar->GetModelIndex() == MI_HUNTER ) - { - fVehicleWidth *= 3.0f; - fVehicleHeight *= 1.4f; - size *= 0.5f; - } - else if ( pCar->GetModelIndex() == MI_ANGEL ) - { - fVehicleHeight = fVehicleHeight * 1.5f; - size = 0.03f; - } - else if ( pCar->GetModelIndex() == MI_SEASPAR ) - { - fVehicleWidth *= 3.0f; - fVehicleHeight *= 1.4f; - size *= 0.5f; - } - else if ( pCar->GetModelIndex() == MI_PIZZABOY || pCar->GetModelIndex() == MI_PCJ600 || pCar->GetModelIndex() == MI_FAGGIO ) - { - fVehicleHeight *= 1.2f; - size = 0.05f; - } - else if ( pCar->GetModelIndex() == MI_FREEWAY ) - { - fVehicleHeight *= 1.5f; - size = 0.03f; - } - else if ( pCar->GetModelIndex() == MI_RCRAIDER ) - { - fVehicleHeight *= 1.5f; - fVehicleWidth *= 2.0f; - size = 0.2f; - } - else if ( pCar->GetModelIndex() == MI_SANCHEZ ) - { - fVehicleHeight *= 1.5f; - size = 0.03f; - } - else if ( pCar->GetModelIndex() == MI_SPARROW || pCar->GetModelIndex() == MI_MAVERICK || pCar->GetModelIndex() == MI_VCNMAV || pCar->GetModelIndex() == MI_POLMAV ) - { - fVehicleWidth *= 3.0f; - fVehicleHeight *= 1.4f; - size *= 0.5f; - } - else if ( pCar->GetModelIndex() == MI_RCGOBLIN ) - { - fVehicleHeight *= 1.5f; - fVehicleWidth *= 2.0f; - size = 0.2f; - } - else if ( pCar->GetModelIndex() == MI_DODO ) - { - fVehicleHeight *= 0.9f; - fVehicleWidth *= 0.4f; - } - - CarPos.x -= pCar->GetForward().x * (((fVehicleHeight/2) - pCar->GetColModel()->boundingBox.max.y)*size); - CarPos.y -= pCar->GetForward().y * (((fVehicleHeight/2) - pCar->GetColModel()->boundingBox.max.y)*size); - - RwTexture *tex = gpShadowCarTex; - switch ( type ) - { - case VEH_SHD_TYPE_BIKE: - { - float wheelZ = Abs(((CBike*)pCar)->m_fLeanLRAngle); - float mul = 5.092958f * wheelZ + 1.0f; - if (pCar->GetStatus() == STATUS_PHYSICS) - { - float z = pCar->GetRight().z; - if (z > 0.6f) - mul += 4.0f * z; - } - fVehicleWidth *= mul; - tex = gpShadowBikeTex; - break; - } - - case VEH_SHD_TYPE_HELI: - tex = gpShadowHeliTex; - break; - - case VEH_SHD_TYPE_SEAPLANE: - nColorStrength = CTimeCycle::GetShadowStrength(); - tex = gpShadowBaronTex; - break; - - case VEH_SHD_TYPE_RCPLANE: - tex = gpShadowBaronTex; - fVehicleHeight *= 1.5f; - fVehicleWidth *= 2.2f; - break; - - case VEH_SHD_TYPE_CAR: - tex = gpShadowCarTex; - break; - } - - float frontx = pCar->GetForward().x; - float fronty = pCar->GetForward().y; - float sidex = pCar->GetRight().x; - float sidey = pCar->GetRight().y; - - switch ( type ) - { - case VEH_SHD_TYPE_BIKE: - if ( Abs(pCar->GetRight().z) > 0.6f ) - { - sidex = pCar->GetUp().x; - sidey = pCar->GetUp().y; - } - break; - - case VEH_SHD_TYPE_HELI: - if ( Abs(pCar->GetRight().z) > 0.57f ) - { - sidex = pCar->GetUp().x; - sidey = pCar->GetUp().y; - } - if ( Abs(pCar->GetForward().z) > 0.57f ) - { - frontx = pCar->GetUp().x; - fronty = pCar->GetUp().y; - } - break; - } - - bool bDrawOnBuildings = false; - if ( pCar->GetModelIndex() == MI_RCBANDIT - || pCar->GetModelIndex() == MI_RCBARON - || pCar->GetModelIndex() == MI_RCRAIDER - || pCar->GetModelIndex() == MI_RCGOBLIN - || pCar == FindPlayerVehicle() ) - { - bDrawOnBuildings = true; - } - - if ( pCar->m_vecMoveSpeed.Magnitude() * CTimeStep::ms_fTimeStep > 0.1f || bDrawOnBuildings ) - { - if ( pCar->GetUp().z > 0.0f ) - { - StoreShadowToBeRendered(SHADOWTYPE_DARK, tex, &CarPos, - frontx * (fVehicleHeight / 2), - fronty * (fVehicleHeight / 2), - sidex * (fVehicleWidth / 2), - sidey * (fVehicleWidth / 2), - nColorStrength, nColorStrength, nColorStrength, nColorStrength, - 4.5f, false, 1.0f, nil, bDrawOnBuildings); - } - else - { - StoreShadowToBeRendered(SHADOWTYPE_DARK, tex, &CarPos, - frontx * (fVehicleHeight / 2), - fronty * (fVehicleHeight / 2), - -sidex * (fVehicleWidth / 2), - -sidey * (fVehicleWidth / 2), - nColorStrength, nColorStrength, nColorStrength, nColorStrength, - 4.5f, false, 1.0f, nil, bDrawOnBuildings); - } - } - else - { - if ( pCar->GetUp().z > 0.0f ) - { - StoreStaticShadow((uintptr)pCar + 1, SHADOWTYPE_DARK, tex, &CarPos, - frontx * (fVehicleHeight / 2), - fronty * (fVehicleHeight / 2), - sidex * (fVehicleWidth / 2), - sidey * (fVehicleWidth / 2), - nColorStrength, nColorStrength, nColorStrength, nColorStrength, - 4.5f, 1.0f, 0.0f, false, 0.1f); - } - else - { - StoreStaticShadow((uintptr)pCar + 1, SHADOWTYPE_DARK, tex, &CarPos, - frontx * (fVehicleHeight / 2), - fronty * (fVehicleHeight / 2), - -sidex * (fVehicleWidth / 2), - -sidey * (fVehicleWidth / 2), - nColorStrength, nColorStrength, nColorStrength, nColorStrength, - 4.5f, 1.0f, 0.0f, false, 0.1f); - } - } - } - } -} - -void -CShadows::StoreCarLightShadow(CVehicle *pCar, int32 nID, RwTexture *pTexture, CVector *pPosn, - float fFrontX, float fFrontY, float fSideX, float fSideY, uint8 nRed, uint8 nGreen, uint8 nBlue, - float fMaxViewAngle) -{ - ASSERT(pCar != nil); - ASSERT(pPosn != nil); - - float fDistToCamSqr = (*pPosn - TheCamera.GetPosition()).MagnitudeSqr2D(); - - bool bSpecialCam = TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN - || TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED - || CCutsceneMgr::IsRunning(); - - float fDrawDistance = 27.0f; - - if ( fDistToCamSqr < SQR(fDrawDistance) || bSpecialCam ) - { - if ( bSpecialCam || DotProduct2D(CVector2D(TheCamera.CamFrontXNorm, TheCamera.CamFrontYNorm), - *pPosn - TheCamera.GetPosition() ) > -fMaxViewAngle ) - { - float fDistToCam = Sqrt(fDistToCamSqr); - - if ( fDistToCam >= (fDrawDistance*(1.0f-(1.0f/4.0f))) && !bSpecialCam ) // BUG? must be 3.0? - { - //fDistToCam == 0 -> 3 - //fDistToCam == fDrawDistance -> 0 - float fMult = 1.0f - (3.0f / fDrawDistance) * (fDistToCam - (fDrawDistance*(1.0f-(1.0f/3.0f))) ); - - nRed = (int32)(nRed * fMult); - nGreen = (int32)(nGreen * fMult); - nBlue = (int32)(nBlue * fMult); - } - - if ( pCar->m_vecMoveSpeed.Magnitude() * CTimeStep::ms_fTimeStep > 0.4f || pCar == FindPlayerVehicle() ) - { - StoreShadowToBeRendered(SHADOWTYPE_ADDITIVE, pTexture, pPosn, - fFrontX, fFrontY, - fSideX, fSideY, - 128, nRed, nGreen, nBlue, - 6.0f, false, 1.0f, - nil, pCar == FindPlayerVehicle()); - } - else - { - StoreStaticShadow((uintptr)pCar + nID, SHADOWTYPE_ADDITIVE, pTexture, pPosn, - fFrontX, fFrontY, - fSideX, fSideY, - 128, nRed, nGreen, nBlue, - 6.0f, 1.0f, 27.0f, - false, 0.4f); - } - } - } -} - - -#ifdef USE_CUTSCENE_SHADOW_FOR_PED -void -StoreShadowForCutscenePedObject(CPed *pObject, float fDisplacementX, float fDisplacementY, - float fFrontX, float fFrontY, float fSideX, float fSideY) -{ - ASSERT(pObject != nil); - - CCutsceneShadow *shadow = pObject->m_pRTShadow; - - if ( shadow == nil ) - return; - - if ( !shadow->IsInitialized() ) - return; - - CVector pos = pObject->GetPosition(); - - float fDistToCamSqr = (pos - TheCamera.GetPosition()).MagnitudeSqr2D(); - - float fDrawDistance = 100.0f; - - if ( fDistToCamSqr < SQR(fDrawDistance*0.5f) ) - { - if ( (CEntity*)pObject == FindPlayerPed() || TheCamera.IsSphereVisible(pos, 2.0f) ) - { - float fDistToCam = Sqrt(fDistToCamSqr); - - float fMult = 1.0f - (4.0f / fDrawDistance) * (fDistToCam - (fDrawDistance*(1.0f/4.0f))); - int32 nColorStrength; - - if ( fDistToCam >= (fDrawDistance*(1.0f/4.0f)) ) - nColorStrength = (int32)(CTimeCycle::GetShadowStrength() * fMult); - else - nColorStrength = CTimeCycle::GetShadowStrength(); - - int32 color = int32(nColorStrength * 0.8f); - - pos.x += fDisplacementX; - pos.y += fDisplacementY; - - RwTexture *texture = shadow->GetShadowRwTexture(); - ASSERT(texture); - RwRGBA bordercolor = {0, 0, 0, 0}; - shadow->DrawBorderAroundTexture(bordercolor); - - pos.x -= fDisplacementX; - pos.y -= fDisplacementY; - - float angleY = 360.0f - RADTODEG((CClock::ms_nGameClockMinutes - +60*CClock::ms_nGameClockHours+CClock::ms_nGameClockSeconds/60)*(HALFPI/360.0f)); - - RwFrame *frame = shadow->SetLightProperties(angleY, -85.0f, true); - ASSERT(frame); - CVector at(RwFrameGetMatrix(frame)->at); - at.Normalise(); - - CShadows::CalcPedShadowValues(at, &fFrontX, &fFrontY, &fSideX, &fSideY, &fDisplacementX, &fDisplacementY); - - pos.x -= 2.5f * fDisplacementX; - pos.y -= 2.5f * fDisplacementY; - - CShadows::StoreShadowToBeRendered(SHADOWTYPE_INVCOLOR, texture, &pos, - fFrontX * 1.5f, fFrontY * 1.5f, - fSideX * 1.5f, fSideY * 1.5f, - color, color, color, color, - 4.0f, false, 1.0f, shadow, false); - } - } -} -#endif - - -void -CShadows::StoreShadowForPed(CPed *pPed, float fDisplacementX, float fDisplacementY, - float fFrontX, float fFrontY, float fSideX, float fSideY) -{ - ASSERT(pPed != nil); - - if ( pPed->bIsVisible ) - { - if ( !(pPed->bInVehicle && pPed->m_nPedState != PED_DRAG_FROM_CAR && pPed->m_nPedState != PED_EXIT_CAR) ) - { - if ( CTimeCycle::GetShadowStrength() != 0 ) - { -#ifdef USE_CUTSCENE_SHADOW_FOR_PED - CCutsceneShadow *pShadow = pPed->m_pRTShadow; - - if (pShadow) - { - if (pShadow->IsInitialized()) - pShadow->UpdateForCutscene(); - ::StoreShadowForCutscenePedObject(pPed, fDisplacementX, fDisplacementY, fFrontX, fFrontY, fSideX, fSideY); - } - - return; -#endif - - StoreShadowForPedObject(pPed, - fDisplacementX, fDisplacementY, - fFrontX, fFrontY, - fSideX, fSideY); - } - } - } -} - -void -CShadows::StoreShadowForPedObject(CEntity *pPedObject, float fDisplacementX, float fDisplacementY, - float fFrontX, float fFrontY, float fSideX, float fSideY) -{ - ASSERT(pPedObject != nil); - - CVector PedPos = pPedObject->GetPosition(); - - float fDistToCamSqr = (PedPos - TheCamera.GetPosition()).MagnitudeSqr2D(); - - float fDrawDistance = 26.0f; - - if ( fDistToCamSqr < SQR(fDrawDistance*0.5f) ) - { - if ( pPedObject == FindPlayerPed() || TheCamera.IsSphereVisible(PedPos, 2.0f) != false ) - { - float fDistToCam = Sqrt(fDistToCamSqr); - - //fDistToCam == 0 -> 2 - //fDistToCam == fDrawDistance -> -2 - float fMult = 1.0f - (4.0f / fDrawDistance) * (fDistToCam - (fDrawDistance*(1.0f/4.0f))); // BUG ? negative - int32 nColorStrength; - - if ( fDistToCam >= (fDrawDistance*(1.0f/4.0f)) ) // BUG ? negative - nColorStrength = (int32)(CTimeCycle::GetShadowStrength() * fMult); - else - nColorStrength = CTimeCycle::GetShadowStrength(); - - PedPos.x += fDisplacementX; - PedPos.y += fDisplacementY; - - StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowPedTex, &PedPos, - fFrontX, fFrontY, - fSideX, fSideY, - nColorStrength, nColorStrength, nColorStrength, nColorStrength, - 4.0f, false, 1.0f, nil, pPedObject == FindPlayerPed()); - } - } -} - - -void -CShadows::StoreShadowForCutscenePedObject(CCutsceneObject *pObject, float fDisplacementX, float fDisplacementY, - float fFrontX, float fFrontY, float fSideX, float fSideY) -{ -#ifdef DISABLE_CUTSCENE_SHADOWS - return; -#endif - ASSERT(pObject != nil); - - CCutsceneShadow *shadow = pObject->m_pShadow; - - if ( shadow == nil ) - return; - - if ( !shadow->IsInitialized() ) - return; - - CVector pos = pObject->GetPosition(); - - float fDistToCamSqr = (pos - TheCamera.GetPosition()).MagnitudeSqr2D(); - - float fDrawDistance = 100.0f; - - if ( fDistToCamSqr < SQR(fDrawDistance*0.5f) ) - { - if ( (CEntity*)pObject == FindPlayerPed() || TheCamera.IsSphereVisible(pos, 2.0f) ) - { - float fDistToCam = Sqrt(fDistToCamSqr); - - float fMult = 1.0f - (4.0f / fDrawDistance) * (fDistToCam - (fDrawDistance*(1.0f/4.0f))); - int32 nColorStrength; - - if ( fDistToCam >= (fDrawDistance*(1.0f/4.0f)) ) - nColorStrength = (int32)(CTimeCycle::GetShadowStrength() * fMult); - else - nColorStrength = CTimeCycle::GetShadowStrength(); - - int32 color = int32(nColorStrength * 0.8f); - - pos.x += fDisplacementX; - pos.y += fDisplacementY; - - RwTexture *texture = shadow->GetShadowRwTexture(); - ASSERT(texture); - RwRGBA bordercolor = {0, 0, 0, 0}; - shadow->DrawBorderAroundTexture(bordercolor); - - pos.x -= fDisplacementX; - pos.y -= fDisplacementY; - - float angleY = 360.0f - RADTODEG((CClock::ms_nGameClockMinutes+60* - CClock::ms_nGameClockHours+CClock::ms_nGameClockSeconds/60)*(HALFPI/360.0f)); - - RwFrame *frame = shadow->SetLightProperties(angleY, -85.0f, true); - ASSERT(frame); - CVector at(RwFrameGetMatrix(frame)->at); - at.Normalise(); - - CalcPedShadowValues(at, &fFrontX, &fFrontY, &fSideX, &fSideY, &fDisplacementX, &fDisplacementY); - - pos.x -= 2.5f * fDisplacementX; - pos.y -= 2.5f * fDisplacementY; - - StoreShadowToBeRendered(SHADOWTYPE_INVCOLOR, texture, &pos, - fFrontX * 1.5f, fFrontY * 1.5f, - fSideX * 1.5f, fSideY * 1.5f, - color, color, color, color, - 4.0f, false, 1.0f, shadow, false); - } - } -} - -void -CShadows::StoreShadowForTree(CEntity *pTree) -{ - ASSERT(pTree != nil); -} - - -void -CShadows::StoreShadowForPole(CEntity *pPole, float fOffsetX, float fOffsetY, float fOffsetZ, - float fPoleHeight, float fPoleWidth, uint32 nID) -{ - ASSERT(pPole != nil); - - if ( CTimeCycle::GetShadowStrength() != 0 ) - { - if ( pPole->GetUp().z < 0.5f ) - return; - - CVector PolePos = pPole->GetPosition(); - - PolePos.x += fOffsetX * pPole->GetRight().x + fOffsetY * pPole->GetForward().x; - PolePos.y += fOffsetX * pPole->GetRight().y + fOffsetY * pPole->GetForward().y; - PolePos.z += fOffsetZ; - - PolePos.x += -CTimeCycle::GetSunDirection().x * (fPoleHeight / 2); - PolePos.y += -CTimeCycle::GetSunDirection().y * (fPoleHeight / 2); - - StoreStaticShadow((uintptr)pPole + nID + _TODOCONST(51), SHADOWTYPE_DARK, gpPostShadowTex, &PolePos, - -CTimeCycle::GetSunDirection().x * (fPoleHeight / 2), - -CTimeCycle::GetSunDirection().y * (fPoleHeight / 2), - CTimeCycle::GetShadowSideX() * fPoleWidth, - CTimeCycle::GetShadowSideY() * fPoleWidth, - 2 * (int32)((pPole->GetUp().z - 0.5f) * CTimeCycle::GetShadowStrength() * 2.0f) / 3, - 0, 0, 0, - 15.0f, 1.0f, 40.0f, false, 0.0f); - } -} - -void -CShadows::SetRenderModeForShadowType(uint8 ShadowType) -{ - switch ( ShadowType ) - { - case SHADOWTYPE_DARK: - { - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - break; - } - - case SHADOWTYPE_ADDITIVE: - { - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); - break; - } - - case SHADOWTYPE_INVCOLOR: - { - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDZERO); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCCOLOR); - break; - } - } -} - - -void -CShadows::RenderStoredShadows(void) -{ - PUSH_RENDERGROUP("CShadows::RenderStoredShadows"); - - RenderBuffer::ClearRenderBuffer(); - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void *)rwTEXTUREADDRESSCLAMP); - - - for ( int32 i = 0; i < ShadowsStoredToBeRendered; i++ ) - asShadowsStored[i].m_nFlags.bRendered = false; - - - for ( int32 i = 0; i < ShadowsStoredToBeRendered; i++ ) - { - if ( !asShadowsStored[i].m_nFlags.bRendered ) - { - SetRenderModeForShadowType(asShadowsStored[i].m_ShadowType); - - ASSERT(asShadowsStored[i].m_pTexture != nil); - - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(asShadowsStored[i].m_pTexture)); - - for ( int32 j = i; j < ShadowsStoredToBeRendered; j++ ) - { - if ( asShadowsStored[i].m_ShadowType == asShadowsStored[j].m_ShadowType - && asShadowsStored[i].m_pTexture == asShadowsStored[j].m_pTexture ) - { - float fWidth = Abs(asShadowsStored[j].m_vecFront.x) + Abs(asShadowsStored[j].m_vecSide.x); - float fHeight = Abs(asShadowsStored[j].m_vecFront.y) + Abs(asShadowsStored[j].m_vecSide.y); - - CVector shadowPos = asShadowsStored[j].m_vecPos; - - float fStartX = shadowPos.x - fWidth; - float fEndX = shadowPos.x + fWidth; - float fStartY = shadowPos.y - fHeight; - float fEndY = shadowPos.y + fHeight; - - int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); - int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); - int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); - int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); - - CWorld::AdvanceCurrentScanCode(); - - for ( int32 y = nStartY; y <= nEndY; y++ ) - { - for ( int32 x = nStartX; x <= nEndX; x++ ) - { - CSector *pCurSector = CWorld::GetSector(x, y); - - ASSERT(pCurSector != nil); - - if ( asShadowsStored[j].m_pCutsceneShadow ) - { - CastCutsceneShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS], - fStartX, fStartY, - fEndX, fEndY, - &shadowPos, - asShadowsStored[j].m_vecFront.x, - asShadowsStored[j].m_vecFront.y, - asShadowsStored[j].m_vecSide.x, - asShadowsStored[j].m_vecSide.y, - asShadowsStored[j].m_nIntensity, - asShadowsStored[j].m_nRed, - asShadowsStored[j].m_nGreen, - asShadowsStored[j].m_nBlue, - asShadowsStored[j].m_fZDistance, - asShadowsStored[j].m_fScale, - nil, - asShadowsStored[j].m_pCutsceneShadow); - - CastCutsceneShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP], - fStartX, fStartY, - fEndX, fEndY, - &shadowPos, - asShadowsStored[j].m_vecFront.x, - asShadowsStored[j].m_vecFront.y, - asShadowsStored[j].m_vecSide.x, - asShadowsStored[j].m_vecSide.y, - asShadowsStored[j].m_nIntensity, - asShadowsStored[j].m_nRed, - asShadowsStored[j].m_nGreen, - asShadowsStored[j].m_nBlue, - asShadowsStored[j].m_fZDistance, - asShadowsStored[j].m_fScale, - nil, - asShadowsStored[j].m_pCutsceneShadow); - } - else if ( asShadowsStored[j].m_nFlags.bDrawOnBuildings ) - { - CastPlayerShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS], - fStartX, fStartY, - fEndX, fEndY, - &shadowPos, - asShadowsStored[j].m_vecFront.x, - asShadowsStored[j].m_vecFront.y, - asShadowsStored[j].m_vecSide.x, - asShadowsStored[j].m_vecSide.y, - asShadowsStored[j].m_nIntensity, - asShadowsStored[j].m_nRed, - asShadowsStored[j].m_nGreen, - asShadowsStored[j].m_nBlue, - asShadowsStored[j].m_fZDistance, - asShadowsStored[j].m_fScale, - nil); - - CastPlayerShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP], - fStartX, fStartY, - fEndX, fEndY, - &shadowPos, - asShadowsStored[j].m_vecFront.x, - asShadowsStored[j].m_vecFront.y, - asShadowsStored[j].m_vecSide.x, - asShadowsStored[j].m_vecSide.y, - asShadowsStored[j].m_nIntensity, - asShadowsStored[j].m_nRed, - asShadowsStored[j].m_nGreen, - asShadowsStored[j].m_nBlue, - asShadowsStored[j].m_fZDistance, - asShadowsStored[j].m_fScale, - nil); - } - else - { - CastShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS], - fStartX, fStartY, - fEndX, fEndY, - &shadowPos, - asShadowsStored[j].m_vecFront.x, - asShadowsStored[j].m_vecFront.y, - asShadowsStored[j].m_vecSide.x, - asShadowsStored[j].m_vecSide.y, - asShadowsStored[j].m_nIntensity, - asShadowsStored[j].m_nRed, - asShadowsStored[j].m_nGreen, - asShadowsStored[j].m_nBlue, - asShadowsStored[j].m_fZDistance, - asShadowsStored[j].m_fScale, - nil); - - CastShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP], - fStartX, fStartY, - fEndX, fEndY, - &shadowPos, - asShadowsStored[j].m_vecFront.x, - asShadowsStored[j].m_vecFront.y, - asShadowsStored[j].m_vecSide.x, - asShadowsStored[j].m_vecSide.y, - asShadowsStored[j].m_nIntensity, - asShadowsStored[j].m_nRed, - asShadowsStored[j].m_nGreen, - asShadowsStored[j].m_nBlue, - asShadowsStored[j].m_fZDistance, - asShadowsStored[j].m_fScale, - nil); - } - } - } - - asShadowsStored[j].m_nFlags.bRendered = true; - } - } - - RenderBuffer::RenderStuffInBuffer(); - } - } - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void *)rwTEXTUREADDRESSWRAP); - - ShadowsStoredToBeRendered = 0; - - POP_RENDERGROUP(); -} - - -void -CShadows::RenderStaticShadows(void) -{ - PUSH_RENDERGROUP("CShadows::RenderStaticShadows"); - - RenderBuffer::ClearRenderBuffer(); - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE); - - SetAlphaTest(0); - - for ( int32 i = 0; i < MAX_STATICSHADOWS; i++ ) - aStaticShadows[i].m_bRendered = false; - - for ( int32 i = 0; i < MAX_STATICSHADOWS; i++ ) - { - if ( aStaticShadows[i].m_pPolyBunch && !aStaticShadows[i].m_bRendered ) - { - SetRenderModeForShadowType(aStaticShadows[i].m_nType); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(aStaticShadows[i].m_pTexture)); - - // optimization trick, render all shadows with same renderstate and texture - for ( int32 j = i; j < MAX_STATICSHADOWS; j++ ) - { - if ( aStaticShadows[j].m_pPolyBunch != nil - && aStaticShadows[i].m_nType == aStaticShadows[j].m_nType - && aStaticShadows[i].m_pTexture == aStaticShadows[j].m_pTexture ) - { - for ( CPolyBunch *bunch = aStaticShadows[j].m_pPolyBunch; bunch != nil; bunch = bunch->m_pNext ) - { - RwImVertexIndex *pIndexes; - RwIm3DVertex *pVerts; - - RenderBuffer::StartStoring(3 * (bunch->m_nNumVerts - 2), bunch->m_nNumVerts, &pIndexes, &pVerts); - - ASSERT(pIndexes != nil); - ASSERT(pVerts != nil); - - for ( int32 k = 0; k < bunch->m_nNumVerts; k++ ) - { - RwIm3DVertexSetRGBA(&pVerts[k], - aStaticShadows[j].m_nRed, - aStaticShadows[j].m_nGreen, - aStaticShadows[j].m_nBlue, - (int32)(aStaticShadows[j].m_nIntensity * (1.0f - CWeather::Foggyness * 0.5f))); - - RwIm3DVertexSetU (&pVerts[k], bunch->m_aU[k] / 200.0f); - RwIm3DVertexSetV (&pVerts[k], bunch->m_aV[k] / 200.0f); - RwIm3DVertexSetPos(&pVerts[k], bunch->m_aVerts[k].x, bunch->m_aVerts[k].y, bunch->m_aVerts[k].z + 0.03f); - } - - for ( int32 k = 0; k < 3 * (bunch->m_nNumVerts - 2); k++ ) - pIndexes[k] = ShadowIndexList[k]; - - RenderBuffer::StopStoring(); - } - - aStaticShadows[j].m_bRendered = true; - } - } - - RenderBuffer::RenderStuffInBuffer(); - } - } - RestoreAlphaTest(); - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE); - - POP_RENDERGROUP(); -} - - -void -CShadows::GeneratePolysForStaticShadow(int16 nStaticShadowID) -{ - float fWidth = Abs(aStaticShadows[nStaticShadowID].m_vecFront.x) + Abs(aStaticShadows[nStaticShadowID].m_vecSide.x); - float fHeight = Abs(aStaticShadows[nStaticShadowID].m_vecFront.y) + Abs(aStaticShadows[nStaticShadowID].m_vecSide.y); - - CVector shadowPos = aStaticShadows[nStaticShadowID].m_vecPosn; - - float fStartX = shadowPos.x - fWidth; - float fEndX = shadowPos.x + fWidth; - float fStartY = shadowPos.y - fHeight; - float fEndY = shadowPos.y + fHeight; - - int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); - int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); - int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); - int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); - - CWorld::AdvanceCurrentScanCode(); - - for ( int32 y = nStartY; y <= nEndY; y++ ) - { - for ( int32 x = nStartX; x <= nEndX; x++ ) - { - CSector *pCurSector = CWorld::GetSector(x, y); - - ASSERT(pCurSector != nil); - - CastShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS], - fStartX, fStartY, - fEndX, fEndY, - &shadowPos, - aStaticShadows[nStaticShadowID].m_vecFront.x, - aStaticShadows[nStaticShadowID].m_vecFront.y, - aStaticShadows[nStaticShadowID].m_vecSide.x, - aStaticShadows[nStaticShadowID].m_vecSide.y, - 0, 0, 0, 0, - aStaticShadows[nStaticShadowID].m_fZDistance, - aStaticShadows[nStaticShadowID].m_fScale, - &aStaticShadows[nStaticShadowID].m_pPolyBunch); - - CastShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP], - fStartX, fStartY, - fEndX, fEndY, - &shadowPos, - aStaticShadows[nStaticShadowID].m_vecFront.x, - aStaticShadows[nStaticShadowID].m_vecFront.y, - aStaticShadows[nStaticShadowID].m_vecSide.x, - aStaticShadows[nStaticShadowID].m_vecSide.y, - 0, 0, 0, 0, - aStaticShadows[nStaticShadowID].m_fZDistance, - aStaticShadows[nStaticShadowID].m_fScale, - &aStaticShadows[nStaticShadowID].m_pPolyBunch); - } - } -} - - -void -CShadows::CastShadowSectorList(CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, CVector *pPosn, - float fFrontX, float fFrontY, float fSideX, float fSideY, - int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, - float fZDistance, float fScale, CPolyBunch **ppPolyBunch) -{ - ASSERT(pPosn != nil); - - CPtrNode *pNode = PtrList.first; - - CRect Bound; - - while ( pNode != nil ) - { - CEntity *pEntity = (CEntity *)pNode->item; - uint16 nScanCode = pEntity->m_scanCode; - pNode = pNode->next; - - ASSERT( pEntity != nil ); - - if ( nScanCode != CWorld::GetCurrentScanCode() ) - { - pEntity->m_scanCode = CWorld::GetCurrentScanCode(); - - if ( pEntity->bUsesCollision && !pEntity->bDontCastShadowsOn) - { - if ( IsAreaVisible(pEntity->m_area) ) - { - Bound = pEntity->GetBoundRect(); - - if ( fStartX < Bound.right - && fEndX > Bound.left - && fStartY < Bound.bottom - && fEndY > Bound.top ) - { - if ( pPosn->z - fZDistance < pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.max.z - && pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.min.z < pPosn->z ) - { - CastShadowEntityXY(pEntity, - fStartX, fStartY, - fEndX, fEndY, - pPosn, - fFrontX, fFrontY, - fSideX, fSideY, - nIntensity, nRed, nGreen, nBlue, - fZDistance, fScale, ppPolyBunch); - } - } - } - } - } - } -} - - -void -CShadows::CastPlayerShadowSectorList(CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, CVector *pPosn, - float fFrontX, float fFrontY, float fSideX, float fSideY, - int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, - float fZDistance, float fScale, CPolyBunch **ppPolyBunch) -{ - ASSERT(pPosn != nil); - - CPtrNode *pNode = PtrList.first; - - CRect Bound; - - while ( pNode != nil ) - { - CEntity *pEntity = (CEntity *)pNode->item; - uint16 nScanCode = pEntity->m_scanCode; - pNode = pNode->next; - - ASSERT( pEntity != nil ); - - if ( nScanCode != CWorld::GetCurrentScanCode() ) - { - pEntity->m_scanCode = CWorld::GetCurrentScanCode(); - - if ( pEntity->bUsesCollision ) - { - if ( IsAreaVisible(pEntity->m_area) ) - { - Bound = pEntity->GetBoundRect(); - - if ( fStartX < Bound.right - && fEndX > Bound.left - && fStartY < Bound.bottom - && fEndY > Bound.top ) - { - if ( pPosn->z - fZDistance < pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.max.z - && pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.min.z < pPosn->z ) - { - CastShadowEntityXY(pEntity, - fStartX, fStartY, - fEndX, fEndY, - pPosn, - fFrontX, fFrontY, - fSideX, fSideY, - nIntensity, nRed, nGreen, nBlue, - fZDistance, fScale, ppPolyBunch); - } - } - } - } - } - } -} - - -void -CShadows::CastCutsceneShadowSectorList(CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, CVector *pPosn, - float fFrontX, float fFrontY, float fSideX, float fSideY, - int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, - float fZDistance, float fScale, CPolyBunch **ppPolyBunch, CCutsceneShadow *pShadow) -{ - ASSERT(pPosn != nil); - ASSERT(pShadow != nil); - - CPtrNode *pNode = PtrList.first; - - CRect Bound; - - while ( pNode != nil ) - { - CEntity *pEntity = (CEntity *)pNode->item; - uint16 nScanCode = pEntity->m_scanCode; - pNode = pNode->next; - - ASSERT( pEntity != nil ); - - if ( nScanCode != CWorld::GetCurrentScanCode() ) - { - pEntity->m_scanCode = CWorld::GetCurrentScanCode(); - - if ( pEntity->bUsesCollision ) - { - if ( IsAreaVisible(pEntity->m_area) ) - { - Bound = pEntity->GetBoundRect(); - - if ( fStartX < Bound.right - && fEndX > Bound.left - && fStartY < Bound.bottom - && fEndY > Bound.top ) - { - if ( pPosn->z - fZDistance < pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.max.z - && pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.min.z < pPosn->z ) - { - CastShadowEntityXYZ(pEntity, pPosn, - fFrontX, fFrontY, - fSideX, fSideY, - nIntensity, nRed, nGreen, nBlue, - fZDistance, fScale, ppPolyBunch, pShadow); - } - } - } - } - } - } -} - -void -CShadows::CastShadowEntityXY(CEntity *pEntity, float fStartX, float fStartY, float fEndX, float fEndY, CVector *pPosn, - float fFrontX, float fFrontY, float fSideX, float fSideY, - int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, - float fZDistance, float fScale, CPolyBunch **ppPolyBunch) -{ - ASSERT(pEntity != nil); - ASSERT(pPosn != nil); - - static CVector List [20]; - static CVector Texture[20]; - static CVector Points [4]; - - CColModel *pCol = pEntity->GetColModel(); - ASSERT(pCol != nil); - -#ifndef MASTER - if ( gbPrintShite ) - printf("MI:%d Triangles:%d Coors:%f %f BBoxXY:%f %f\n", - pEntity->GetModelIndex(), - pCol->numTriangles, - pEntity->GetPosition().x, - pEntity->GetPosition().y, - pCol->boundingBox.GetSize().x, - pCol->boundingBox.GetSize().y); -#endif - - CCollision::CalculateTrianglePlanes(pCol); - - float fFrontRight = DotProduct2D(CVector2D(fFrontX, fFrontY), pEntity->GetRight()); - float fFrontForward = DotProduct2D(CVector2D(fFrontX, fFrontY), pEntity->GetForward()); - float fSideRight = DotProduct2D(CVector2D(fSideX, fSideY), pEntity->GetRight()); - float fSideForward = DotProduct2D(CVector2D(fSideX, fSideY), pEntity->GetForward()); - float fLengthRight = DotProduct2D(*pPosn - pEntity->GetPosition(), pEntity->GetRight()); - float fLengthForward = DotProduct2D(*pPosn - pEntity->GetPosition(), pEntity->GetForward()); - - Points[0].x = (fLengthRight + fFrontRight ) - fSideRight; - Points[0].y = (fLengthForward + fFrontForward) - fSideForward; - - Points[1].x = fSideRight + (fLengthRight + fFrontRight); - Points[1].y = fSideForward + (fLengthForward + fFrontForward); - - Points[2].x = fSideRight + (fLengthRight - fFrontRight); - Points[2].y = fSideForward + (fLengthForward - fFrontForward); - - Points[3].x = (fLengthRight - fFrontRight) - fSideRight; - Points[3].y = (fLengthForward - fFrontForward) - fSideForward; - - float MinX = Min(Min(Points[0].x, Points[1].x), Min(Points[2].x, Points[3].x)); - float MaxX = Max(Max(Points[0].x, Points[1].x), Max(Points[2].x, Points[3].x)); - - float MinY = Min(Min(Points[0].y, Points[1].y), Min(Points[2].y, Points[3].y)); - float MaxY = Max(Max(Points[0].y, Points[1].y), Max(Points[2].y, Points[3].y)); - - float MaxZ = pPosn->z - pEntity->GetPosition().z; - float MinZ = MaxZ - fZDistance; - - for ( int32 i = 0; i < pCol->numTriangles; i++ ) - { - CColTrianglePlane *pColTriPlanes = pCol->trianglePlanes; - ASSERT(pColTriPlanes != nil); - - CVector normal; - pColTriPlanes[i].GetNormal(normal); - if ( Abs(normal.z) > 0.1f ) - { - CColTriangle *pColTri = pCol->triangles; - ASSERT(pColTri != nil); - - CVector PointA, PointB, PointC; - - pCol->GetTrianglePoint(PointA, pColTri[i].a); - pCol->GetTrianglePoint(PointB, pColTri[i].b); - pCol->GetTrianglePoint(PointC, pColTri[i].c); - - if ( (PointA.x > MinX || PointB.x > MinX || PointC.x > MinX) - && (PointA.x < MaxX || PointB.x < MaxX || PointC.x < MaxX) - && (PointA.y > MinY || PointB.y > MinY || PointC.y > MinY) - && (PointA.y < MaxY || PointB.y < MaxY || PointC.y < MaxY) - && (PointA.z < MaxZ || PointB.z < MaxZ || PointC.z < MaxZ) - && (PointA.z > MinZ || PointB.z > MinZ || PointC.z > MinZ) ) - - { - List[0].x = Points[0].x; - List[0].y = Points[0].y; - - List[1].x = Points[1].x; - List[1].y = Points[1].y; - - List[2].x = Points[2].x; - List[2].y = Points[2].y; - - List[3].x = Points[3].x; - List[3].y = Points[3].y; - - Texture[0].x = 0.0f; - Texture[0].y = 0.0f; - - Texture[1].x = 1.0f; - Texture[1].y = 0.0f; - - Texture[2].x = 1.0f; - Texture[2].y = 1.0f; - - Texture[3].x = 0.0f; - Texture[3].y = 1.0f; - - - CVector2D start; - CVector2D dist; - - int32 numVerts1 = 0; - int16 vertType1 = 0; - { - for ( int32 j = 0; j < 4; j++ ) - { - start = PointA; - dist = PointB - PointA; - - int32 in = j; - - float cp = CrossProduct2D(CVector2D(List[in]) - start, dist); - - if ( cp > 0.0f ) - { - switch ( vertType1 ) - { - case 0: - { - int32 out = numVerts1++ + 10; - - Texture[out].x = Texture[in].x; - Texture[out].y = Texture[in].y; - List[out].x = List[in].x; - List[out].y = List[in].y; - - break; - } - - case 1: - { - int32 out = numVerts1++ + 10; - - Texture[out].x = Texture[in].x; - Texture[out].y = Texture[in].y; - List[out].x = List[in].x; - List[out].y = List[in].y; - - break; - } - - case 2: - { - float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); - - float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); - float Compl = 1.0f - Scale; - - int32 out1 = numVerts1++ + 10; - int32 out2 = numVerts1++ + 10; - - Texture[out1].x = Compl*Texture[in-1].x + Scale*Texture[in].x; - Texture[out1].y = Compl*Texture[in-1].y + Scale*Texture[in].y; - List[out1].x = Compl*List[in-1].x + Scale*List[in].x; - List[out1].y = Compl*List[in-1].y + Scale*List[in].y; - - Texture[out2].x = Texture[in].x; - Texture[out2].y = Texture[in].y; - List[out2].x = List[in].x; - List[out2].y = List[in].y; - - break; - } - } - - vertType1 = 1; - } - else - { - switch ( vertType1 ) - { - case 1: - { - float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); - - float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); - float Compl = 1.0f - Scale; - - int32 out = numVerts1++ + 10; - - Texture[out].x = Compl*Texture[in-1].x + Scale*Texture[in].x; - Texture[out].y = Compl*Texture[in-1].y + Scale*Texture[in].y; - List[out].x = Compl*List[in-1].x + Scale*List[in].x; - List[out].y = Compl*List[in-1].y + Scale*List[in].y; - - break; - } - } - - vertType1 = 2; - } - } - - float cp1 = CrossProduct2D(CVector2D(List[0]) - start, dist); - if ( cp1 > 0.0f && vertType1 == 2 || cp1 <= 0.0f && vertType1 == 1 ) - { - float cp2 = CrossProduct2D(CVector2D(List[3]) - start, dist); - - float Scale = Abs(cp2) / (Abs(cp2) + Abs(cp1)); - float Compl = 1.0f - Scale; - - int32 out = numVerts1++ + 10; - - Texture[out].x = Compl*Texture[3].x + Scale*Texture[0].x; - Texture[out].y = Compl*Texture[3].y + Scale*Texture[0].y; - List[out].x = Compl*List[3].x + Scale*List[0].x; - List[out].y = Compl*List[3].y + Scale*List[0].y; - } - } - - int32 numVerts2 = 0; - int16 vertType2 = 0; - { - for ( int32 j = 0; j < numVerts1; j++ ) - { - start = PointB; - dist = PointC - PointB; - - int32 in = j + 10; - float cp = CrossProduct2D(CVector2D(List[in]) - start, dist); - - if ( cp > 0.0f ) - { - switch ( vertType2 ) - { - case 0: - { - int32 out = numVerts2++; - - Texture[out].x = Texture[in].x; - Texture[out].y = Texture[in].y; - List[out].x = List[in].x; - List[out].y = List[in].y; - - break; - } - - case 1: - { - int32 out = numVerts2++; - - Texture[out].x = Texture[in].x; - Texture[out].y = Texture[in].y; - List[out].x = List[in].x; - List[out].y = List[in].y; - - break; - } - - case 2: - { - float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); - - float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); - float Compl = 1.0f - Scale; - - int32 out1 = numVerts2++; - int32 out2 = numVerts2++; - - Texture[out1].x = Compl*Texture[in-1].x + Scale*Texture[in].x; - Texture[out1].y = Compl*Texture[in-1].y + Scale*Texture[in].y; - List[out1].x = Compl*List[in-1].x + Scale*List[in].x; - List[out1].y = Compl*List[in-1].y + Scale*List[in].y; - - Texture[out2].x = Texture[in].x; - Texture[out2].y = Texture[in].y; - List[out2].x = List[in].x; - List[out2].y = List[in].y; - - break; - } - } - - vertType2 = 1; - } - else - { - switch ( vertType2 ) - { - case 1: - { - float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); - - float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); - float Compl = 1.0f - Scale; - - int32 out = numVerts2++; - - Texture[out].x = Compl*Texture[in-1].x + Scale*Texture[in].x; - Texture[out].y = Compl*Texture[in-1].y + Scale*Texture[in].y; - List[out].x = Compl*List[in-1].x + Scale*List[in].x; - List[out].y = Compl*List[in-1].y + Scale*List[in].y; - - break; - } - } - - vertType2 = 2; - } - } - - float cp1 = CrossProduct2D(CVector2D(List[10]) - start, dist); - if ( cp1 > 0.0f && vertType2 == 2 || cp1 <= 0.0f && vertType2 == 1 ) - { - int32 in = numVerts1 + 10; - - float cp2 = CrossProduct2D(CVector2D(List[in-1]) - start, dist); - - float Scale = Abs(cp2) / (Abs(cp2) + Abs(cp1)); - float Compl = 1.0f - Scale; - - int32 out = numVerts2++; - - Texture[out].x = Compl*Texture[in-1].x + Scale*Texture[10].x; - Texture[out].y = Compl*Texture[in-1].y + Scale*Texture[10].y; - List[out].x = Compl*List[in-1].x + Scale*List[10].x; - List[out].y = Compl*List[in-1].y + Scale*List[10].y; - } - } - - int32 numVerts3 = 0; - int16 vertType3 = 0; - { - for ( int32 j = 0; j < numVerts2; j++ ) - { - start = PointC; - dist = PointA - PointC; - - int32 in = j; - float cp = CrossProduct2D(CVector2D(List[in]) - start, dist); - - if ( cp > 0.0f ) - { - switch ( vertType3 ) - { - case 0: - { - int32 out = numVerts3++ + 10; - - Texture[out].x = Texture[in].x; - Texture[out].y = Texture[in].y; - List[out].x = List[in].x; - List[out].y = List[in].y; - - break; - } - - case 1: - { - int32 out = numVerts3++ + 10; - - Texture[out].x = Texture[in].x; - Texture[out].y = Texture[in].y; - List[out].x = List[in].x; - List[out].y = List[in].y; - - break; - } - - case 2: - { - float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); - - float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); - float Compl = 1.0f - Scale; - - int32 out1 = numVerts3++ + 10; - int32 out2 = numVerts3++ + 10; - - Texture[out1].x = Compl*Texture[in-1].x + Scale*Texture[in].x; - Texture[out1].y = Compl*Texture[in-1].y + Scale*Texture[in].y; - List[out1].x = Compl*List[in-1].x + Scale*List[in].x; - List[out1].y = Compl*List[in-1].y + Scale*List[in].y; - - Texture[out2].x = Texture[in].x; - Texture[out2].y = Texture[in].y; - List[out2].x = List[in].x; - List[out2].y = List[in].y; - - break; - } - } - - vertType3 = 1; - } - else - { - switch ( vertType3 ) - { - case 1: - { - float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); - - float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); - float Compl = 1.0f - Scale; - - int32 out = numVerts3++ + 10; - - Texture[out].x = Compl*Texture[in-1].x + Scale*Texture[in].x; - Texture[out].y = Compl*Texture[in-1].y + Scale*Texture[in].y; - List[out].x = Compl*List[in-1].x + Scale*List[in].x; - List[out].y = Compl*List[in-1].y + Scale*List[in].y; - - break; - } - } - - vertType3 = 2; - } - } - - float cp1 = CrossProduct2D(CVector2D(List[0]) - start, dist); - if ( cp1 > 0.0f && vertType3 == 2 || cp1 <= 0.0f && vertType3 == 1 ) - { - int32 in = numVerts2; - - float cp2 = CrossProduct2D(CVector2D(List[in-1]) - start, dist); - - float Scale = Abs(cp2) / (Abs(cp2) + Abs(cp1)); - float Compl = 1.0f - Scale; - - int32 out = numVerts3++ + 10; - - Texture[out].x = Compl*Texture[in-1].x + Scale*Texture[0].x; - Texture[out].y = Compl*Texture[in-1].y + Scale*Texture[0].y; - List[out].x = Compl*List[in-1].x + Scale*List[0].x; - List[out].y = Compl*List[in-1].y + Scale*List[0].y; - } - } - - if ( numVerts3 >= 3 ) - { - CVector norm; - - pColTriPlanes[i].GetNormal(norm); - - float dot = DotProduct(norm, PointA); - - for ( int32 j = 0; j < numVerts3; j++ ) - { - int32 idx = j + 10; - - List[idx].z = -(DotProduct2D(norm, List[idx]) - dot) / norm.z; - } - - for ( int32 j = 0; j < numVerts3; j++ ) - { - int32 idx = j + 10; - - CVector p = List[idx]; - - List[idx].x = p.y * pEntity->GetForward().x + p.x * pEntity->GetRight().x + pEntity->GetPosition().x; - List[idx].y = p.y * pEntity->GetForward().y + p.x * pEntity->GetRight().y + pEntity->GetPosition().y; - List[idx].z = p.z + pEntity->GetPosition().z; - } - - - if ( ppPolyBunch != nil ) - { - if ( pEmptyBunchList != nil ) - { - CPolyBunch *pBunch = pEmptyBunchList; - ASSERT(pBunch != nil); - pEmptyBunchList = pEmptyBunchList->m_pNext; - pBunch->m_pNext = *ppPolyBunch; - *ppPolyBunch = pBunch; - - pBunch->m_nNumVerts = numVerts3; - - for ( int32 j = 0; j < numVerts3; j++ ) - { - int32 in = j + 10; - - pBunch->m_aVerts[j] = List[in]; - - pBunch->m_aU[j] = (int32)(Texture[in].x * 200.0f); - pBunch->m_aV[j] = (int32)(Texture[in].y * 200.0f); - } - } - } - else - { - RwImVertexIndex *pIndexes; - RwIm3DVertex *pVerts; - - RenderBuffer::StartStoring(3 * (numVerts3 - 2), numVerts3, &pIndexes, &pVerts); - - ASSERT(pIndexes != nil); - ASSERT(pVerts != nil); - - - for ( int32 j = 0; j < numVerts3; j++ ) - { - int32 in = j + 10; - - RwIm3DVertexSetRGBA(&pVerts[j], nRed, nGreen, nBlue, nIntensity); - RwIm3DVertexSetU (&pVerts[j], Texture[in].x*fScale); - RwIm3DVertexSetV (&pVerts[j], Texture[in].y*fScale); - RwIm3DVertexSetPos (&pVerts[j], List[in].x, List[in].y, List[in].z + 0.03f); - } - - for ( int32 j = 0; j < 3*(numVerts3 - 2); j++ ) - pIndexes[j] = ShadowIndexList[j]; - - RenderBuffer::StopStoring(); - } - } - } - } - } -} - - -typedef struct _ProjectionParam -{ - RwV3d at; /* Camera at vector */ - RwMatrix invMatrix; /* Transforms to shadow camera space */ - RwUInt8 shadowValue; /* Shadow opacity value */ - RwBool fade; /* Shadow fades with distance */ - RwUInt32 numIm3DBatch; /* Number of buffer flushes */ - RwMatrix entityMatrix; -} -ProjectionParam; - -RwV3d *ShadowRenderTriangleCB(RwV3d *points, RwV3d *normal, ProjectionParam *param) -{ - RwV3d vIn[3]; - RwV3d vShad[3]; - - RwV3dTransformPoints(&vIn[0], points, 3, ¶m->entityMatrix); - - /* - * Reject backfacing triangles - * This reject the triangles parallel to the light as well - */ - if (RwV3dDotProduct(normal, ¶m->at) > 0.0f) - { - return points; - } - - RwV3dTransformPoints(&vShad[0], &vIn[0], 3, ¶m->invMatrix); - - /* - * Reject triangles behind the camera (z test). Note that any world - * triangles lying in front of the camera but before the object may - * have a shadow applied. To minimize such artefacts, this test could - * be modified to use a specific value rather than 0.0f, perhaps - * to reject triangles behind the center plane of the object. - * - * Reject triangles that lie entirely outside the shadow texture range - * (x,y test). - */ - if (((vShad[0].z < 0.0f) && (vShad[1].z < 0.0f) - && (vShad[2].z < 0.0f)) || ((vShad[0].x < 0.0f) - && (vShad[1].x < 0.0f) - && (vShad[2].x < 0.0f)) - || ((vShad[0].x > 1.0f) && (vShad[1].x > 1.0f) - && (vShad[2].x > 1.0f)) || ((vShad[0].y < 0.0f) - && (vShad[1].y < 0.0f) - && (vShad[2].y < 0.0f)) - || ((vShad[0].y > 1.0f) && (vShad[1].y > 1.0f) - && (vShad[2].y > 1.0f))) - { - return points; - } - - RwIm3DVertex *imv = nil; - RwImVertexIndex *imi = nil; - - RenderBuffer::StartStoring(3, 3, &imi, &imv); - - /* - * Set the immediate mode vertices for this triangle - */ - - RwIm3DVertexSetPos(imv, vIn[0].x, vIn[0].y, vIn[0].z); - RwIm3DVertexSetPos(imv + 1, vIn[1].x, vIn[1].y, vIn[1].z); - RwIm3DVertexSetPos(imv + 2, vIn[2].x, vIn[2].y, vIn[2].z); - - RwIm3DVertexSetU(imv, vShad[0].x); - RwIm3DVertexSetU(imv + 1, vShad[1].x); - RwIm3DVertexSetU(imv + 2, vShad[2].x); - - RwIm3DVertexSetV(imv, vShad[0].y); - RwIm3DVertexSetV(imv + 1, vShad[1].y); - RwIm3DVertexSetV(imv + 2, vShad[2].y); - - /* - * Do we fade out the shadow with distance? - */ - if (param->fade) - { - RwReal fadeVal; - RwUInt8 val; - - fadeVal = 1.0f - vShad[0].z * vShad[0].z; - val = - (fadeVal < - 0.0f) ? 0 : (RwUInt8) (fadeVal * param->shadowValue); - RwIm3DVertexSetRGBA(imv, val, val, val, val); - - fadeVal = 1.0f - vShad[1].z * vShad[1].z; - val = - (fadeVal < - 0.0f) ? 0 : (RwUInt8) (fadeVal * param->shadowValue); - RwIm3DVertexSetRGBA(imv + 1, val, val, val, val); - - fadeVal = 1.0f - vShad[2].z * vShad[2].z; - val = - (fadeVal < - 0.0f) ? 0 : (RwUInt8) (fadeVal * param->shadowValue); - RwIm3DVertexSetRGBA(imv + 2, val, val, val, val); - } - else - { - RwUInt8 val = param->shadowValue; - - RwIm3DVertexSetRGBA(imv, val, val, val, val); - RwIm3DVertexSetRGBA(imv + 1, val, val, val, val); - RwIm3DVertexSetRGBA(imv + 2, val, val, val, val); - } - - /* - * Update buffer position - */ - imi[0] = 0; - imi[1] = 1; - imi[2] = 2; - - RenderBuffer::StopStoring(); - - return points; -} - -void -CShadows::CastShadowEntityXYZ(CEntity *pEntity, CVector *pPosn, - float fFrontX, float fFrontY, float fSideX, float fSideY, - int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, - float fZDistance, float fScale, CPolyBunch **ppPolyBunch, CCutsceneShadow *pShadow) -{ - ASSERT(pEntity != nil); - ASSERT(pPosn != nil); - - if ( pShadow ) - { - ProjectionParam proj; - RwV3d scl; - RwV3d tr; - - CShadowCamera *shadow = pShadow->GetShadowCamera(); - CColModel *collision = pEntity->GetColModel(); - - CCollision::CalculateTrianglePlanes(collision); - - RwMatrix mat; - mat = *RwFrameGetMatrix(RwCameraGetFrame(shadow->GetRwCamera())); - - RwV3d Xaxis = { 1.0f, 0.0f, 0.0f }; - - RwMatrixRotate(&mat, &Xaxis, -45.0f, rwCOMBINEPRECONCAT); - - proj.at = mat.at; - pEntity->GetMatrix().CopyToRwMatrix(&proj.entityMatrix); - - RwMatrixInvert(&proj.invMatrix, &mat); - RwReal radius = RwCameraGetViewWindow(shadow->GetRwCamera())->x; - - scl.x = scl.y = -0.5f / (radius*0.9f); - scl.z = 1.0f / (radius*0.8f); - RwMatrixScale(&proj.invMatrix, &scl, rwCOMBINEPOSTCONCAT); - - tr.x = 0.5f; - tr.y = tr.z = 0.0f; - RwMatrixTranslate(&proj.invMatrix, &tr, rwCOMBINEPOSTCONCAT); - - proj.shadowValue = nIntensity; - proj.fade = 0; - - RwMatrix matrix; - pEntity->GetMatrix().CopyToRwMatrix(&matrix); - RwMatrix invMatrix; - RwMatrixInvert(&invMatrix, &matrix); - - - CVector center(pShadow->GetBaseSphere().center); - center += CVector(-fFrontX * 1.1f, -fFrontY * 1.1f, -0.5f); - - CSphere sphere; - sphere.Set(2.0f, center); - - RwV3d point; - RwV3dTransformPoints(&point, ¢er, 1, &invMatrix); - - CColSphere colSphere; - colSphere.Set(2.0f, CVector(point), 0, 0); - - int i = 0; - while ( i < collision->numTriangles ) - { - CVector p[3]; - - collision->GetTrianglePoint(p[0], collision->triangles[i].a); - collision->GetTrianglePoint(p[1], collision->triangles[i].b); - collision->GetTrianglePoint(p[2], collision->triangles[i].c); - - if ( CCollision::TestSphereTriangle(colSphere, collision->vertices, collision->triangles[i], collision->trianglePlanes[i]) ) - { - CVector n(collision->trianglePlanes[i].GetNormalX(), collision->trianglePlanes[i].GetNormalY(), collision->trianglePlanes[i].GetNormalZ()); - CVector offset = n * 0.028f; - - p[0] += offset; - p[1] += offset; - p[2] += offset; - - if ( !ShadowRenderTriangleCB(p, &n, &proj) ) - break; - } - i++; - } - } -} - -void -CShadows::UpdateStaticShadows(void) -{ - for ( int32 i = 0; i < MAX_STATICSHADOWS; i++ ) - { - if ( aStaticShadows[i].m_pPolyBunch != nil && !aStaticShadows[i].m_bJustCreated - && (!aStaticShadows[i].m_bTemp || CTimer::GetTimeInMilliseconds() > aStaticShadows[i].m_nTimeCreated + 5000) ) - { - aStaticShadows[i].Free(); - } - - aStaticShadows[i].m_bJustCreated = false; - } -} - -void -CShadows::UpdatePermanentShadows(void) -{ - for ( int32 i = 0; i < MAX_PERMAMENTSHADOWS; i++ ) - { - if ( aPermanentShadows[i].m_nType != SHADOWTYPE_NONE ) - { - uint32 timePassed = CTimer::GetTimeInMilliseconds() - aPermanentShadows[i].m_nTimeCreated; - - if ( timePassed >= aPermanentShadows[i].m_nLifeTime ) - aPermanentShadows[i].m_nType = SHADOWTYPE_NONE; - else - { - bool bOk; - if ( timePassed >= (aPermanentShadows[i].m_nLifeTime * 3 / 4) ) - { - // timePassed == 0 -> 4 - // timePassed == aPermanentShadows[i].m_nLifeTime -> 0 - float fMult = 1.0f - float(timePassed - (aPermanentShadows[i].m_nLifeTime * 3 / 4)) / (aPermanentShadows[i].m_nLifeTime / 4); - - bOk = StoreStaticShadow((uintptr)&aPermanentShadows[i], - aPermanentShadows[i].m_nType, - aPermanentShadows[i].m_pTexture, - &aPermanentShadows[i].m_vecPos, - aPermanentShadows[i].m_vecFront.x, - aPermanentShadows[i].m_vecFront.y, - aPermanentShadows[i].m_vecSide.x, - aPermanentShadows[i].m_vecSide.y, - (int32)(aPermanentShadows[i].m_nIntensity * fMult), - (int32)(aPermanentShadows[i].m_nRed * fMult), - (int32)(aPermanentShadows[i].m_nGreen * fMult), - (int32)(aPermanentShadows[i].m_nBlue * fMult), - aPermanentShadows[i].m_fZDistance, - 1.0f, 40.0f, false, 0.0f); - } - else - { - bOk = StoreStaticShadow((uintptr)&aPermanentShadows[i], - aPermanentShadows[i].m_nType, - aPermanentShadows[i].m_pTexture, - &aPermanentShadows[i].m_vecPos, - aPermanentShadows[i].m_vecFront.x, - aPermanentShadows[i].m_vecFront.y, - aPermanentShadows[i].m_vecSide.x, - aPermanentShadows[i].m_vecSide.y, - aPermanentShadows[i].m_nIntensity, - aPermanentShadows[i].m_nRed, - aPermanentShadows[i].m_nGreen, - aPermanentShadows[i].m_nBlue, - aPermanentShadows[i].m_fZDistance, - 1.0f, 40.0f, false, 0.0f); - } - - if ( !bOk ) - aPermanentShadows[i].m_nType = SHADOWTYPE_NONE; - } - } - } -} - -void -CStaticShadow::Free(void) -{ - if ( m_pPolyBunch != nil ) - { - CPolyBunch *pFree = CShadows::pEmptyBunchList; - CShadows::pEmptyBunchList = m_pPolyBunch; - - CPolyBunch *pUsed = m_pPolyBunch; - while (pUsed->m_pNext != nil) - pUsed = pUsed->m_pNext; - - pUsed->m_pNext = pFree; - } - - m_pPolyBunch = nil; - - m_nId = 0; -} - -void -CShadows::CalcPedShadowValues(CVector vecLightDir, - float *pfFrontX, float *pfFrontY, - float *pfSideX, float *pfSideY, - float *pfDisplacementX, float *pfDisplacementY) -{ - ASSERT(pfFrontX != nil); - ASSERT(pfFrontY != nil); - ASSERT(pfSideX != nil); - ASSERT(pfSideY != nil); - ASSERT(pfDisplacementX != nil); - ASSERT(pfDisplacementY != nil); - - *pfFrontX = -vecLightDir.x; - *pfFrontY = -vecLightDir.y; - - float fDist = Sqrt(*pfFrontY * *pfFrontY + *pfFrontX * *pfFrontX); - float fMult = (fDist + 1.0f) / fDist; - - *pfFrontX *= fMult; - *pfFrontY *= fMult; - - *pfSideX = -vecLightDir.y / fDist; - *pfSideY = vecLightDir.x / fDist; - - *pfDisplacementX = -vecLightDir.x; - *pfDisplacementY = -vecLightDir.y; - - *pfFrontX /= 2; - *pfFrontY /= 2; - - *pfSideX /= 2; - *pfSideY /= 2; - - *pfDisplacementX /= 2; - *pfDisplacementY /= 2; - -} - - -void -CShadows::RenderExtraPlayerShadows(void) -{ -#ifdef FIX_BUGS - if (CReplay::IsPlayingBack()) - return; -#endif - if ( CTimeCycle::GetLightShadowStrength() != 0 ) - { - CVehicle *pCar = FindPlayerVehicle(); - if ( pCar == nil ) - ; // R* cut it out for playerped - else - { - if ( pCar->GetModelIndex() != MI_RCBANDIT - && pCar->GetVehicleAppearance() != VEHICLE_APPEARANCE_BIKE - && !pCar->IsBike() && !pCar->IsPlane() && !pCar->IsBoat() ) - { - for ( int32 i = 0; i < CPointLights::NumLights; i++ ) - { - if ( CPointLights::aLights[i].type == CPointLights::LIGHT_POINT - && CPointLights::aLights[i].castExtraShadows - &&(0.0f != CPointLights::aLights[i].red - || 0.0f != CPointLights::aLights[i].green - || 0.0f != CPointLights::aLights[i].blue) ) - { - CVector vecLight = CPointLights::aLights[i].coors - FindPlayerCoors(); - float fLightDist = vecLight.Magnitude(); - float fRadius = CPointLights::aLights[i].radius; - - if ( fLightDist < fRadius ) - { - // fLightDist == 0 -> 2.0f - // fLightDist == fRadius -> 0.0f - float fMult = (1.0f - (2.0f * fLightDist - fRadius) / fRadius); - - int32 nColorStrength; - if ( fLightDist < fRadius*0.5f ) - nColorStrength = (5*CTimeCycle::GetLightShadowStrength()/8); - else - nColorStrength = int32((5*CTimeCycle::GetLightShadowStrength()/8) * fMult); - - float fInv = 1.0f / fLightDist; - vecLight.x *= fInv; - vecLight.y *= fInv; - vecLight.z *= fInv; - - CVector shadowPos = pCar->GetPosition(); - - shadowPos.x -= vecLight.x * 1.2f; - shadowPos.y -= vecLight.y * 1.2f; - - float fVehicleWidth = pCar->GetColModel()->boundingBox.GetSize().x; - float fVehicleHeight = pCar->GetColModel()->boundingBox.GetSize().y; - - shadowPos.x -= ((fVehicleHeight/2) - pCar->GetColModel()->boundingBox.max.y) - * pCar->GetForward().x; - - shadowPos.y -= ((fVehicleHeight/2) - pCar->GetColModel()->boundingBox.max.y) - * pCar->GetForward().y; - - if ( pCar->GetUp().z > 0.0f ) - { - StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowCarTex, &shadowPos, - pCar->GetForward().x * (fVehicleHeight/2), - pCar->GetForward().y * (fVehicleHeight/2), - pCar->GetRight().x * (fVehicleWidth/3), - pCar->GetRight().y * (fVehicleWidth/3), - nColorStrength, 0, 0, 0, - 4.5f, false, 1.0f, nil, false); - } - else - { - StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowCarTex, &shadowPos, - pCar->GetForward().x * (fVehicleHeight/2), - pCar->GetForward().y * (fVehicleHeight/2), - -pCar->GetRight().x * (fVehicleWidth/2), - -pCar->GetRight().y * (fVehicleWidth/2), - nColorStrength, 0, 0, 0, - 4.5f, false, 1.0f, nil, false); - } - } - } - } - } - } - } -} - -void -CShadows::TidyUpShadows(void) -{ - for ( int32 i = 0; i < MAX_PERMAMENTSHADOWS; i++ ) - aPermanentShadows[i].m_nType = SHADOWTYPE_NONE; -} - -void -CShadows::RenderIndicatorShadow(uint32 nID, uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, - float fFrontX, float fFrontY, float fSideX, float fSideY, - int16 nIntensity) -{ - ASSERT(pPosn != nil); - - C3dMarkers::PlaceMarkerSet(nID, MARKERTYPE_CYLINDER, *pPosn, Max(fFrontX, -fSideY), - SPHERE_MARKER_R, SPHERE_MARKER_G, SPHERE_MARKER_B, - SPHERE_MARKER_A, SPHERE_MARKER_PULSE_PERIOD, 0.2f, 0); -} diff --git a/src/render/Shadows.h b/src/render/Shadows.h deleted file mode 100644 index 937ff4eb..00000000 --- a/src/render/Shadows.h +++ /dev/null @@ -1,210 +0,0 @@ -#pragma once - -#define MAX_STOREDSHADOWS 48 -#define MAX_POLYBUNCHES 380 -#define MAX_STATICSHADOWS 48 -#define MAX_PERMAMENTSHADOWS 48 - - - -class CEntity; -class CPtrList; -class CAutomobile; -class CVehicle; -class CPed; -class CCutsceneShadow; -class CCutsceneObject; - -enum eShadowType -{ - SHADOWTYPE_NONE = 0, - SHADOWTYPE_DARK, - SHADOWTYPE_ADDITIVE, - SHADOWTYPE_INVCOLOR -}; - -enum eShadowTextureType -{ - SHADOWTEX_NONE = 0, - SHADOWTEX_CAR, - SHADOWTEX_PED, - SHADOWTEX_EXPLOSION, - SHADOWTEX_HELI, - SHADOWTEX_HEADLIGHTS, - SHADOWTEX_BLOOD -}; - -enum VEH_SHD_TYPE -{ - VEH_SHD_TYPE_CAR = 0, - VEH_SHD_TYPE_BIKE, - VEH_SHD_TYPE_HELI, - VEH_SHD_TYPE_SEAPLANE, - VEH_SHD_TYPE_RCPLANE, -}; - - -class CStoredShadow -{ -public: - CVector m_vecPos; - CVector2D m_vecFront; - CVector2D m_vecSide; - float m_fZDistance; - float m_fScale; - RwTexture *m_pTexture; - CCutsceneShadow *m_pCutsceneShadow; - int16 m_nIntensity; - uint8 m_ShadowType; - uint8 m_nRed; - uint8 m_nGreen; - uint8 m_nBlue; - struct - { - uint8 bDrawOnWater : 1; - uint8 bRendered : 1; - uint8 bDrawOnBuildings : 1; - } m_nFlags; - - - CStoredShadow() - { } -}; - -VALIDATE_SIZE(CStoredShadow, 0x30); - -class CPolyBunch -{ -public: - CVector m_aVerts[7]; - CPolyBunch *m_pNext; - int16 m_nNumVerts; - uint8 m_aU[7]; - uint8 m_aV[7]; - - CPolyBunch() - { } -}; - -VALIDATE_SIZE(CPolyBunch, 0x6C); - -class CStaticShadow -{ -public: - uint32 m_nId; - CPolyBunch *m_pPolyBunch; - uint32 m_nTimeCreated; - CVector m_vecPosn; - CVector2D m_vecFront; - CVector2D m_vecSide; - float m_fZDistance; - float m_fScale; - RwTexture *m_pTexture; - int16 m_nIntensity; // unsigned ? - uint8 m_nType; - uint8 m_nRed; - uint8 m_nGreen; - uint8 m_nBlue; - bool m_bJustCreated; - bool m_bRendered; - bool m_bTemp; - - - CStaticShadow() - { } - - void Free(); -}; - -VALIDATE_SIZE(CStaticShadow, 0x40); - -class CPermanentShadow -{ -public: - CVector m_vecPos; - CVector2D m_vecFront; - CVector2D m_vecSide; - float m_fZDistance; - float m_fScale; - uint32 m_nTimeCreated; - uint32 m_nLifeTime; - RwTexture *m_pTexture; - int16 m_nIntensity; - uint8 m_nType; // eShadowType - uint8 m_nRed; - uint8 m_nGreen; - uint8 m_nBlue; - - CPermanentShadow() - { } -}; - -VALIDATE_SIZE(CPermanentShadow, 0x38); - -class CShadows -{ -public: - static int16 ShadowsStoredToBeRendered; - static CStoredShadow asShadowsStored [MAX_STOREDSHADOWS]; - static CPolyBunch aPolyBunches [MAX_POLYBUNCHES]; - static CStaticShadow aStaticShadows [MAX_STATICSHADOWS]; - static CPolyBunch *pEmptyBunchList; - static CPermanentShadow aPermanentShadows[MAX_PERMAMENTSHADOWS]; - - static void Init (void); - static void Shutdown (void); - static void AddPermanentShadow ( uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, uint32 nTime, float fScale); - - static bool StoreStaticShadow (uint32 nID, uint8 ShadowType, RwTexture *pTexture, Const CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, float fDrawDistance, bool bTempShadow, float fUpDistance); - static void StoreShadowToBeRendered ( uint8 ShadowType, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue); - static void StoreShadowToBeRendered ( uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, bool bDrawOnWater, float fScale, CCutsceneShadow *pShadow, bool bDrawOnBuildings); - static void StoreShadowForVehicle (CVehicle *pCar, VEH_SHD_TYPE type); - static void StoreCarLightShadow (CVehicle *pCar, int32 nID, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, uint8 nRed, uint8 nGreen, uint8 nBlue, float fMaxViewAngle); - static void StoreShadowForPed (CPed *pPed, float fDisplacementX, float fDisplacementY, float fFrontX, float fFrontY, float fSideX, float fSideY); - static void StoreShadowForPedObject (CEntity *pPedObject, float fDisplacementX, float fDisplacementY, float fFrontX, float fFrontY, float fSideX, float fSideY); - static void StoreShadowForCutscenePedObject(CCutsceneObject *pObject, float fDisplacementX, float fDisplacementY, float fFrontX, float fFrontY, float fSideX, float fSideY); - static void StoreShadowForTree (CEntity *pTree); - static void StoreShadowForPole (CEntity *pPole, float fOffsetX, float fOffsetY, float fOffsetZ, float fPoleHeight, float fPoleWidth, uint32 nID); - static void SetRenderModeForShadowType (uint8 ShadowType); - static void RenderStoredShadows (void); - static void RenderStaticShadows (void); - - static void GeneratePolysForStaticShadow (int16 nStaticShadowID); - static void CastShadowSectorList (CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, - CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch); - - static void CastPlayerShadowSectorList (CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, - CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch); - - static void CastCutsceneShadowSectorList (CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, - CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch, CCutsceneShadow *pShadow); - - static void CastShadowEntityXY (CEntity *pEntity, float fStartX, float fStartY, float fEndX, float fEndY, - CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch); - - static void CastShadowEntityXYZ (CEntity *pEntity, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch, CCutsceneShadow *pShadow); - - static void UpdateStaticShadows (void); - static void UpdatePermanentShadows (void); - static void CalcPedShadowValues (CVector vecLightDir, float *pfFrontX, float *pfFrontY, float *pfSideX, float *pfSideY, float *pfDisplacementX, float *pfDisplacementY); - static void RenderExtraPlayerShadows (void); - static void TidyUpShadows (void); - static void RenderIndicatorShadow (uint32 nID, uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity); -}; - -extern RwTexture *gpShadowCarTex; -extern RwTexture *gpShadowPedTex; -extern RwTexture *gpShadowHeliTex; -extern RwTexture *gpShadowBikeTex; -extern RwTexture *gpShadowBaronTex; -extern RwTexture *gpShadowExplosionTex; -extern RwTexture *gpShadowHeadLightsTex; -extern RwTexture *gpOutline1Tex; -extern RwTexture *gpOutline2Tex; -extern RwTexture *gpOutline3Tex; -extern RwTexture *gpBloodPoolTex; -extern RwTexture *gpReflectionTex; -extern RwTexture *gpWalkDontTex; -extern RwTexture *gpCrackedGlassTex; -extern RwTexture *gpPostShadowTex; -extern RwTexture *gpGoalTex; diff --git a/src/render/Skidmarks.cpp b/src/render/Skidmarks.cpp deleted file mode 100644 index 08df330d..00000000 --- a/src/render/Skidmarks.cpp +++ /dev/null @@ -1,259 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "TxdStore.h" -#include "Timer.h" -#include "Replay.h" -#include "Skidmarks.h" - -CSkidmark CSkidmarks::aSkidmarks[NUMSKIDMARKS]; - -RwImVertexIndex SkidmarkIndexList[SKIDMARK_LENGTH * 6]; -RwIm3DVertex SkidmarkVertices[SKIDMARK_LENGTH * 2]; -RwTexture *gpSkidTex; - -void -CSkidmarks::Init(void) -{ - int i, ix, slot; - CTxdStore::PushCurrentTxd(); - slot = CTxdStore::FindTxdSlot("particle"); - CTxdStore::SetCurrentTxd(slot); - gpSkidTex = RwTextureRead("particleskid", nil); - CTxdStore::PopCurrentTxd(); - - for(i = 0; i < NUMSKIDMARKS; i++){ - aSkidmarks[i].m_state = 0; - aSkidmarks[i].m_wasUpdated = false; - } - - ix = 0; - for(i = 0; i < SKIDMARK_LENGTH; i++){ - SkidmarkIndexList[i*6+0] = ix+0; - SkidmarkIndexList[i*6+1] = ix+2; - SkidmarkIndexList[i*6+2] = ix+1; - SkidmarkIndexList[i*6+3] = ix+1; - SkidmarkIndexList[i*6+4] = ix+2; - SkidmarkIndexList[i*6+5] = ix+3; - ix += 2; - } -} - -void -CSkidmarks::Shutdown(void) -{ - RwTextureDestroy(gpSkidTex); - gpSkidTex = nil; -} - -void -CSkidmarks::Clear(void) -{ - int i; - for(i = 0; i < NUMSKIDMARKS; i++){ - aSkidmarks[i].m_state = 0; - aSkidmarks[i].m_wasUpdated = false; - } -} - -void -CSkidmarks::Update(void) -{ - int i; - uint32 t1 = CTimer::GetTimeInMilliseconds() + 2500; - uint32 t2 = CTimer::GetTimeInMilliseconds() + 5000; - uint32 t3 = CTimer::GetTimeInMilliseconds() + 10000; - uint32 t4 = CTimer::GetTimeInMilliseconds() + 20000; - for(i = 0; i < NUMSKIDMARKS; i++){ - switch(aSkidmarks[i].m_state){ - case 1: - if(!aSkidmarks[i].m_wasUpdated){ - // Didn't continue this one last time, so finish it and set fade times - aSkidmarks[i].m_state = 2; - if(aSkidmarks[i].m_last < 4){ - aSkidmarks[i].m_fadeStart = t1; - aSkidmarks[i].m_fadeEnd = t2; - }else if(aSkidmarks[i].m_last < 9){ - aSkidmarks[i].m_fadeStart = t2; - aSkidmarks[i].m_fadeEnd = t3; - }else{ - aSkidmarks[i].m_fadeStart = t3; - aSkidmarks[i].m_fadeEnd = t4; - } - } - break; - case 2: - if(CTimer::GetTimeInMilliseconds() > aSkidmarks[i].m_fadeEnd) - aSkidmarks[i].m_state = 0; - break; - } - aSkidmarks[i].m_wasUpdated = false; - } -} - -void -CSkidmarks::Render(void) -{ - int i, j; - - PUSH_RENDERGROUP("CSkidmarks::Render"); - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpSkidTex)); - - for(i = 0; i < NUMSKIDMARKS; i++){ - if(aSkidmarks[i].m_state == 0 || aSkidmarks[i].m_last < 1) - continue; - - CRGBA color(0, 0, 0, 255); - switch(aSkidmarks[i].m_type){ - case SKIDMARK_NORMAL: color = CRGBA(0, 0, 0, 255); break; - case SKIDMARK_MUDDY: color = CRGBA(90, 62, 9, 255); break; - case SKIDMARK_SANDY: color = CRGBA(108, 108, 96, 255); break; - case SKIDMARK_BLOODY: color = CRGBA(132, 34, 11, 255); break; - } - - uint32 fade, alpha; - if(aSkidmarks[i].m_state == 1 || CTimer::GetTimeInMilliseconds() < aSkidmarks[i].m_fadeStart) - fade = 255; - else - fade = 255*(aSkidmarks[i].m_fadeEnd - CTimer::GetTimeInMilliseconds()) / (aSkidmarks[i].m_fadeEnd - aSkidmarks[i].m_fadeStart); - - for(j = 0; j <= aSkidmarks[i].m_last; j++){ - alpha = 128; - if(j == 0 || j == aSkidmarks[i].m_last && aSkidmarks[i].m_state == 2) - alpha = 0; - alpha = alpha*fade/256; - - CVector p1 = aSkidmarks[i].m_pos[j]; - p1.x += aSkidmarks[i].m_sideX[j]; - p1.y += aSkidmarks[i].m_sideY[j]; - CVector p2 = aSkidmarks[i].m_pos[j]; - p2.x -= aSkidmarks[i].m_sideX[j]; - p2.y -= aSkidmarks[i].m_sideY[j]; - RwIm3DVertexSetRGBA(&SkidmarkVertices[j*2+0], color.red, color.green, color.blue, alpha); - RwIm3DVertexSetPos(&SkidmarkVertices[j*2+0], p1.x, p1.y, p1.z+0.1f); - RwIm3DVertexSetU(&SkidmarkVertices[j*2+0], 0.0f); - RwIm3DVertexSetV(&SkidmarkVertices[j*2+0], j*5.01f); - RwIm3DVertexSetRGBA(&SkidmarkVertices[j*2+1], color.red, color.green, color.blue, alpha); - RwIm3DVertexSetPos(&SkidmarkVertices[j*2+1], p2.x, p2.y, p2.z+0.1f); - RwIm3DVertexSetU(&SkidmarkVertices[j*2+1], 1.0f); - RwIm3DVertexSetV(&SkidmarkVertices[j*2+1], j*5.01f); - } - - LittleTest(); - if(RwIm3DTransform(SkidmarkVertices, 2*(aSkidmarks[i].m_last+1), nil, rwIM3D_VERTEXUV)){ - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, SkidmarkIndexList, 6*aSkidmarks[i].m_last); - RwIm3DEnd(); - } - } - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - - POP_RENDERGROUP(); -} - -void -CSkidmarks::RegisterOne(uintptr id, const CVector &pos, float fwdX, float fwdY, bool *isMuddy, bool *isBloody) -{ - eSkidmarkType type; - if(*isBloody) - type = SKIDMARK_BLOODY; - else if(*isMuddy) - type = SKIDMARK_MUDDY; - else - type = SKIDMARK_NORMAL; - RegisterOne(id, pos, fwdX, fwdY, type, isBloody); -} - -void -CSkidmarks::RegisterOne(uintptr id, const CVector &pos, float fwdX, float fwdY, eSkidmarkType type, bool *isBloody) -{ - int i; - CVector2D fwd(fwdX, fwdY); - - if(CReplay::IsPlayingBack()) - return; - - // Find a skidmark to continue - for(i = 0; i < NUMSKIDMARKS; i++) - if(aSkidmarks[i].m_state == 1 && aSkidmarks[i].m_id == id) - break; - - if(i < NUMSKIDMARKS){ - // Continue this one - - if((aSkidmarks[i].m_type==SKIDMARK_BLOODY) != *isBloody){ - // Blood-status changed, end this one - aSkidmarks[i].m_state = 2; - aSkidmarks[i].m_fadeStart = CTimer::GetTimeInMilliseconds() + 10000; - aSkidmarks[i].m_fadeEnd = CTimer::GetTimeInMilliseconds() + 20000; - return; - } - - aSkidmarks[i].m_wasUpdated = true; - - if(CTimer::GetTimeInMilliseconds() - aSkidmarks[i].m_lastUpdate <= 100){ - // Last update was recently, just change last coords - aSkidmarks[i].m_pos[aSkidmarks[i].m_last] = pos; - return; - } - aSkidmarks[i].m_lastUpdate = CTimer::GetTimeInMilliseconds(); - - if(aSkidmarks[i].m_last >= SKIDMARK_LENGTH-1){ - // No space to continue, end it - aSkidmarks[i].m_state = 2; - aSkidmarks[i].m_fadeStart = CTimer::GetTimeInMilliseconds() + 10000; - aSkidmarks[i].m_fadeEnd = CTimer::GetTimeInMilliseconds() + 20000; - *isBloody = false; // stpo blood marks at end - return; - } - aSkidmarks[i].m_last++; - - aSkidmarks[i].m_pos[aSkidmarks[i].m_last] = pos; - - CVector2D right(aSkidmarks[i].m_pos[aSkidmarks[i].m_last].y - aSkidmarks[i].m_pos[aSkidmarks[i].m_last - 1].y, - aSkidmarks[i].m_pos[aSkidmarks[i].m_last - 1].x - aSkidmarks[i].m_pos[aSkidmarks[i].m_last].x); - - right.Normalise(); - fwd.Normalise(); - float turn = DotProduct2D(fwd, right); - turn = Abs(turn) + 1.0f; - aSkidmarks[i].m_sideX[aSkidmarks[i].m_last] = right.x * turn * 0.125f; - aSkidmarks[i].m_sideY[aSkidmarks[i].m_last] = right.y * turn * 0.125f; - if(aSkidmarks[i].m_last == 1){ - aSkidmarks[i].m_sideX[0] = aSkidmarks[i].m_sideX[1]; - aSkidmarks[i].m_sideY[0] = aSkidmarks[i].m_sideY[1]; - } - - if(aSkidmarks[i].m_last > 8) - *isBloody = false; // stop blood marks after 8 - return; - } - - // Start a new one - for(i = 0; i < NUMSKIDMARKS; i++) - if(aSkidmarks[i].m_state == 0) - break; - if(i < NUMSKIDMARKS){ - // Found a free slot - aSkidmarks[i].m_state = 1; - aSkidmarks[i].m_id = id; - aSkidmarks[i].m_pos[0] = pos; - aSkidmarks[i].m_sideX[0] = 0.0f; - aSkidmarks[i].m_sideY[0] = 0.0f; - aSkidmarks[i].m_wasUpdated = true; - aSkidmarks[i].m_last = 0; - aSkidmarks[i].m_lastUpdate = CTimer::GetTimeInMilliseconds() - 1000; - if(*isBloody) - aSkidmarks[i].m_type = SKIDMARK_BLOODY; - else - aSkidmarks[i].m_type = type; - }else - *isBloody = false; // stop blood marks if no space -} diff --git a/src/render/Skidmarks.h b/src/render/Skidmarks.h deleted file mode 100644 index 28082f08..00000000 --- a/src/render/Skidmarks.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -enum { SKIDMARK_LENGTH = 16 }; - -enum eSkidmarkType -{ - SKIDMARK_NORMAL, - SKIDMARK_MUDDY, - SKIDMARK_SANDY, - SKIDMARK_BLOODY -}; - -class CSkidmark -{ -public: - CVector m_pos[SKIDMARK_LENGTH]; - float m_sideX[SKIDMARK_LENGTH]; - float m_sideY[SKIDMARK_LENGTH]; - uintptr m_id; - uint32 m_lastUpdate; - uint32 m_fadeStart; - uint32 m_fadeEnd; - uint32 m_type; - int16 m_last; - uint8 m_state; - bool m_wasUpdated; -}; - -class CSkidmarks -{ - static CSkidmark aSkidmarks[NUMSKIDMARKS]; -public: - - static void Init(void); - static void Shutdown(void); - static void Clear(void); - static void Update(void); - static void Render(void); - static void RegisterOne(uintptr id, const CVector &pos, float fwdX, float fwdY, eSkidmarkType type, bool *isBloody); - static void RegisterOne(uintptr id, const CVector &pos, float fwdX, float fwdY, bool *isMuddy, bool *isBloody); -}; diff --git a/src/render/SpecialFX.cpp b/src/render/SpecialFX.cpp deleted file mode 100644 index 61750f85..00000000 --- a/src/render/SpecialFX.cpp +++ /dev/null @@ -1,1493 +0,0 @@ -#include "common.h" - -#include "SpecialFX.h" -#include "RenderBuffer.h" -#include "Timer.h" -#include "Sprite.h" -#include "Font.h" -#include "Text.h" -#include "TxdStore.h" -#include "FileMgr.h" -#include "FileLoader.h" -#include "Timecycle.h" -#include "Lights.h" -#include "ModelIndices.h" -#include "VisibilityPlugins.h" -#include "World.h" -#include "PlayerPed.h" -#include "Particle.h" -#include "Shadows.h" -#include "General.h" -#include "Camera.h" -#include "Shadows.h" -#include "main.h" -#include "ColStore.h" -#include "Coronas.h" -#include "Script.h" -#include "DMAudio.h" - -RwIm3DVertex StreakVertices[4]; -RwImVertexIndex StreakIndexList[12]; - -RwIm3DVertex TraceVertices[10]; -static RwImVertexIndex TraceIndexList[48] = {0, 5, 7, 0, 7, 2, 0, 7, 5, 0, 2, 7, 0, 4, 9, 0, - 9, 5, 0, 9, 4, 0, 5, 9, 0, 1, 6, 0, 6, 5, 0, 6, - 1, 0, 5, 6, 0, 3, 8, 0, 8, 5, 0, 8, 3, 0, 5, 8 }; - -bool CSpecialFX::bVideoCam; -bool CSpecialFX::bLiftCam; -bool CSpecialFX::bSnapShotActive; -int32 CSpecialFX::SnapShotFrames; -static RwTexture* gpSmokeTrailTexture; - - -void -CSpecialFX::Init(void) -{ - CBulletTraces::Init(); - - RwIm3DVertexSetU(&TraceVertices[0], 0.0); - RwIm3DVertexSetV(&TraceVertices[0], 0.0); - RwIm3DVertexSetU(&TraceVertices[1], 1.0); - RwIm3DVertexSetV(&TraceVertices[1], 0.0); - RwIm3DVertexSetU(&TraceVertices[2], 1.0); - RwIm3DVertexSetV(&TraceVertices[2], 0.0); - RwIm3DVertexSetU(&TraceVertices[3], 1.0); - RwIm3DVertexSetV(&TraceVertices[3], 0.0); - RwIm3DVertexSetU(&TraceVertices[4], 1.0); - RwIm3DVertexSetV(&TraceVertices[4], 0.0); - RwIm3DVertexSetU(&TraceVertices[5], 0.0); - RwIm3DVertexSetU(&TraceVertices[6], 1.0); - RwIm3DVertexSetU(&TraceVertices[7], 1.0); - RwIm3DVertexSetU(&TraceVertices[8], 1.0); - RwIm3DVertexSetU(&TraceVertices[9], 1.0); - - RwIm3DVertexSetU(&StreakVertices[0], 0.0f); - RwIm3DVertexSetV(&StreakVertices[0], 0.0f); - RwIm3DVertexSetU(&StreakVertices[1], 1.0f); - RwIm3DVertexSetV(&StreakVertices[1], 0.0f); - RwIm3DVertexSetU(&StreakVertices[2], 0.0f); - RwIm3DVertexSetV(&StreakVertices[2], 0.0f); - RwIm3DVertexSetU(&StreakVertices[3], 1.0f); - RwIm3DVertexSetV(&StreakVertices[3], 0.0f); - StreakIndexList[0] = 0; - StreakIndexList[1] = 1; - StreakIndexList[2] = 2; - StreakIndexList[3] = 1; - StreakIndexList[4] = 3; - StreakIndexList[5] = 2; - StreakIndexList[6] = 0; - StreakIndexList[7] = 2; - StreakIndexList[8] = 1; - StreakIndexList[9] = 1; - StreakIndexList[10] = 2; - StreakIndexList[11] = 3; - - CMotionBlurStreaks::Init(); - CBrightLights::Init(); - CShinyTexts::Init(); - CMoneyMessages::Init(); - C3dMarkers::Init(); - CSpecialFX::bSnapShotActive = false; - CSpecialFX::bVideoCam = false; - CSpecialFX::SnapShotFrames = 0; - CSpecialFX::bLiftCam = false; - CTxdStore::PushCurrentTxd(); - CTxdStore::SetCurrentTxd(CTxdStore::FindTxdSlot("particle")); - if(gpSmokeTrailTexture == nil) - gpSmokeTrailTexture = RwTextureRead("smoketrail", 0); - CTxdStore::PopCurrentTxd(); -} - -void -CSpecialFX::AddWeaponStreak(int type) -{ - static CMatrix matrix; - CVector start; - CVector end; - - if (FindPlayerPed() != nil && FindPlayerPed()->m_pWeaponModel != nil) { - switch (type) { - case WEAPONTYPE_BASEBALLBAT: - matrix = RwFrameGetLTM(RpAtomicGetFrame(FindPlayerPed()->m_pWeaponModel)); - start = matrix * CVector(0.02f, 0.05f, 0.07f); - end = matrix * CVector(0.246f, 0.0325f, 0.796f); - break; - case WEAPONTYPE_GOLFCLUB: - matrix = RwFrameGetLTM(RpAtomicGetFrame(FindPlayerPed()->m_pWeaponModel)); - start = matrix * CVector(0.02f, 0.05f, 0.07f); - end = matrix * CVector(-0.054f, 0.0325f, 0.796f); - break; - case WEAPONTYPE_KATANA: - matrix = RwFrameGetLTM(RpAtomicGetFrame(FindPlayerPed()->m_pWeaponModel)); - start = matrix * CVector(0.02f, 0.05f, 0.07f); - end = matrix * CVector(0.096f, -0.0175f, 1.096f); - break; - default: - return; - } - CMotionBlurStreaks::RegisterStreak((uintptr)FindPlayerPed()->m_pWeaponModel, 100, 100, 100, start, end); - } -} - -RwObject* -LookForBatCB(RwObject *object, void *data) -{ - static CMatrix MatLTM; - - if(CVisibilityPlugins::GetAtomicModelInfo((RpAtomic*)object) == (CSimpleModelInfo*)data){ - MatLTM = CMatrix(RwFrameGetLTM(RpAtomicGetFrame((RpAtomic*)object))); - CVector p1 = MatLTM * CVector(0.02f, 0.05f, 0.07f); - CVector p2 = MatLTM * CVector(0.246f, 0.0325f, 0.796f); - CMotionBlurStreaks::RegisterStreak((uintptr)object, 100, 100, 100, p1, p2); - } - return nil; -} - -void -CSpecialFX::Update(void) -{ - CMotionBlurStreaks::Update(); - CBulletTraces::Update(); -} - -void -CSpecialFX::Shutdown(void) -{ - C3dMarkers::Shutdown(); - if (gpSmokeTrailTexture) { - RwTextureDestroy(gpSmokeTrailTexture); - gpSmokeTrailTexture = nil; - } -} - -void -CSpecialFX::Render(void) -{ - PUSH_RENDERGROUP("CSpecialFX::Render"); - CMotionBlurStreaks::Render(); - CBulletTraces::Render(); - CBrightLights::Render(); - CShinyTexts::Render(); - CMoneyMessages::Render(); -#ifdef NEW_RENDERER - if(!(gbNewRenderer && FredIsInFirstPersonCam())) -#endif - C3dMarkers::Render(); - POP_RENDERGROUP(); -} - -void -CSpecialFX::Render2DFXs(void) -{ - if (CSpecialFX::bVideoCam) { - CFont::SetScale(SCREEN_SCALE_X(1.5f), SCREEN_SCALE_Y(1.5f)); - CFont::SetJustifyOff(); - CFont::SetBackgroundOff(); - CFont::SetCentreSize(SCREEN_SCALE_X(620.0f)); // unused - CFont::SetCentreOff(); - CFont::SetPropOn(); - CFont::SetColor(CRGBA(0, 255, 0, 200)); - CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); - sprintf(gString, "%d", CTimer::GetFrameCounter() & 0x3F); // mb % 63 - AsciiToUnicode(gString, gUString); - CFont::PrintString(SCREEN_WIDTH * 8 / 10, SCREEN_HEIGHT * 8 / 10, gUString); - for (int32 i = 0; i < SCREEN_HEIGHT; i += 4) { - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); - CSprite2d::Draw2DPolygon(0.0f, i, SCREEN_WIDTH, i, 0.0f, i+1, SCREEN_WIDTH, i+1, CRGBA(0, 100, 0, 100)); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - CSprite2d::Draw2DPolygon(0.0f, i+2, SCREEN_WIDTH, i+2, 0.0f, i+3, SCREEN_WIDTH, i+3, CRGBA(0, 0, 0, 150)); - } - int32 tmp = (CTimer::GetTimeInMilliseconds() & 0x7ff) * (SCREEN_HEIGHT + 70.0f) / 2048 - 70.0f; //mb % 2048 - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - CSprite2d::Draw2DPolygon(0.0, tmp, SCREEN_WIDTH, tmp, 0.0, tmp + 70.0f, SCREEN_WIDTH, tmp + 70.0f , CRGBA(0, 100, 0, 60)); - } - if (CSpecialFX::bLiftCam) { - CFont::SetScale(SCREEN_SCALE_X(1.5f), SCREEN_SCALE_Y(1.5f)); - CFont::SetJustifyOff(); - CFont::SetBackgroundOff(); - CFont::SetCentreSize(SCREEN_SCALE_X(620.0f)); // unused - CFont::SetCentreOff(); - CFont::SetPropOn(); - CFont::SetColor(CRGBA(100, 100, 100, 200)); - CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); - for (int32 i = 0; i < SCREEN_HEIGHT; i += 4) { - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - CSprite2d::Draw2DPolygon(0.0f, i, SCREEN_WIDTH, i, 0.0f, i + 1, SCREEN_WIDTH, i + 1, CRGBA(100, 100, 100, 100)); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - CSprite2d::Draw2DPolygon(0.0f, i + 2, SCREEN_WIDTH, i + 2, 0.0f, i + 3, SCREEN_WIDTH, i + 3, CRGBA(0, 0, 0, 150)); - } - int32 tmp = (CTimer::GetTimeInMilliseconds() & 0x7ff) * (SCREEN_HEIGHT + 70.0f) / 2048 - 70.0f; //mb % 2048 - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - CSprite2d::Draw2DPolygon(0.0, tmp, SCREEN_WIDTH, tmp, 0.0, tmp + 70.0f, SCREEN_WIDTH, tmp + 70.0f, CRGBA(100, 100, 100, 60)); - for (int32 i = 0; i < 200; i++) { - int32 posX = CGeneral::GetRandomNumber() % (int32)SCREEN_WIDTH; - int32 posY = CGeneral::GetRandomNumber() % (int32)SCREEN_HEIGHT; - CSprite2d::DrawRect(CRect(posX, posY + 2, posX+20, posY), CRGBA(255, 255, 255, 64)); - } - } - if (CSpecialFX::bSnapShotActive) { - if (++CSpecialFX::SnapShotFrames > 20) { - CSpecialFX::bSnapShotActive = false; - CTimer::SetTimeScale(1.0f); - } else { - CTimer::SetTimeScale(0.0f); //in andro it's 0.00001 - if (CSpecialFX::SnapShotFrames < 10) { - int32 tmp = (255 - 255 * CSpecialFX::SnapShotFrames / 10) * 0.65f; - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - CSprite2d::Draw2DPolygon(0.0f, 0.0f, SCREEN_WIDTH, 0.0f, 0.0f, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, CRGBA(tmp, tmp, tmp, tmp)); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - } - } - } -} - -CRegisteredMotionBlurStreak CMotionBlurStreaks::aStreaks[NUMMBLURSTREAKS]; - -void -CRegisteredMotionBlurStreak::Update(void) -{ - int i; - bool wasUpdated; - bool lastWasUpdated = false; - for(i = 2; i > 0; i--){ - m_pos1[i] = m_pos1[i-1]; - m_pos2[i] = m_pos2[i-1]; - m_isValid[i] = m_isValid[i-1]; - wasUpdated = true; - if(!lastWasUpdated && !m_isValid[i]) - wasUpdated = false; - lastWasUpdated = wasUpdated; - } - m_isValid[0] = false; - if(!wasUpdated) - m_id = 0; -} - -void -CRegisteredMotionBlurStreak::Render(void) -{ - int i; - int a1, a2; - for(i = 0; i < 2; i++) - if(m_isValid[i] && m_isValid[i+1]){ - a1 = (255/3)*(3-i)/3; - RwIm3DVertexSetRGBA(&StreakVertices[0], m_red, m_green, m_blue, a1); - RwIm3DVertexSetRGBA(&StreakVertices[1], m_red, m_green, m_blue, a1); - a2 = (255/3)*(3-(i+1))/3; - RwIm3DVertexSetRGBA(&StreakVertices[2], m_red, m_green, m_blue, a2); - RwIm3DVertexSetRGBA(&StreakVertices[3], m_red, m_green, m_blue, a2); - RwIm3DVertexSetPos(&StreakVertices[0], m_pos1[i].x, m_pos1[i].y, m_pos1[i].z); - RwIm3DVertexSetPos(&StreakVertices[1], m_pos2[i].x, m_pos2[i].y, m_pos2[i].z); - RwIm3DVertexSetPos(&StreakVertices[2], m_pos1[i+1].x, m_pos1[i+1].y, m_pos1[i+1].z); - RwIm3DVertexSetPos(&StreakVertices[3], m_pos2[i+1].x, m_pos2[i+1].y, m_pos2[i+1].z); - LittleTest(); - if(RwIm3DTransform(StreakVertices, 4, nil, rwIM3D_VERTEXUV)){ - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, StreakIndexList, 12); - RwIm3DEnd(); - } - } -} - -void -CMotionBlurStreaks::Init(void) -{ - int i; - for(i = 0; i < NUMMBLURSTREAKS; i++) - aStreaks[i].m_id = 0; -} - -void -CMotionBlurStreaks::Update(void) -{ - int i; - for(i = 0; i < NUMMBLURSTREAKS; i++) - if(aStreaks[i].m_id != 0) - aStreaks[i].Update(); -} - -void -CMotionBlurStreaks::RegisterStreak(uintptr id, uint8 r, uint8 g, uint8 b, CVector p1, CVector p2) -{ - int i; - - for(i = 0; i < NUMMBLURSTREAKS; i++){ - if(aStreaks[i].m_id == id){ - // Found a streak from last frame, update - aStreaks[i].m_red = r; - aStreaks[i].m_green = g; - aStreaks[i].m_blue = b; - aStreaks[i].m_pos1[0] = p1; - aStreaks[i].m_pos2[0] = p2; - aStreaks[i].m_isValid[0] = true; - return; - } - } - - // Find free slot - for(i = 0; aStreaks[i].m_id != 0 ; i++) - if(i == NUMMBLURSTREAKS-1) - return; - - // Create a new streak - aStreaks[i].m_id = id; - aStreaks[i].m_red = r; - aStreaks[i].m_green = g; - aStreaks[i].m_blue = b; - aStreaks[i].m_pos1[0] = p1; - aStreaks[i].m_pos2[0] = p2; - aStreaks[i].m_isValid[0] = true; - aStreaks[i].m_isValid[1] = false; - aStreaks[i].m_isValid[2] = false; -} - -void -CMotionBlurStreaks::Render(void) -{ - bool setRenderStates = false; - int i; - for(i = 0; i < NUMMBLURSTREAKS; i++) - if(aStreaks[i].m_id != 0){ - if(!setRenderStates){ - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEFOGCOLOR, - (void*)RWRGBALONG(CTimeCycle::GetFogRed(), CTimeCycle::GetFogGreen(), CTimeCycle::GetFogBlue(), 255)); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void*)FALSE); - setRenderStates = true; - } - aStreaks[i].Render(); - } - if(setRenderStates){ - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE); - } -} - - -CBulletTrace CBulletTraces::aTraces[NUMBULLETTRACES]; - -void CBulletTraces::Init(void) -{ - for (int i = 0; i < NUMBULLETTRACES; i++) - aTraces[i].m_bInUse = false; -} - -void CBulletTraces::AddTrace(CVector* start, CVector* end, float thickness, uint32 lifeTime, uint8 visibility) -{ - int32 enabledCount; - uint32 modifiedLifeTime; - int32 nextSlot; - - enabledCount = 0; - for (int i = 0; i < NUMBULLETTRACES; i++) - if (aTraces[i].m_bInUse) - enabledCount++; - if (enabledCount >= 10) - modifiedLifeTime = lifeTime / 4; - else if (enabledCount >= 5) - modifiedLifeTime = lifeTime / 2; - else - modifiedLifeTime = lifeTime; - - nextSlot = 0; - for (int i = 0; nextSlot < NUMBULLETTRACES && aTraces[i].m_bInUse; i++) - nextSlot++; - if (nextSlot < 16) { - aTraces[nextSlot].m_vecStartPos = *start; - aTraces[nextSlot].m_vecEndPos = *end; - aTraces[nextSlot].m_bInUse = true; - aTraces[nextSlot].m_nCreationTime = CTimer::GetTimeInMilliseconds(); - aTraces[nextSlot].m_fVisibility = visibility; - aTraces[nextSlot].m_fThickness = thickness; - aTraces[nextSlot].m_nLifeTime = modifiedLifeTime; - } - - float startProjFwd = DotProduct(TheCamera.GetForward(), *start - TheCamera.GetPosition()); - float endProjFwd = DotProduct(TheCamera.GetForward(), *end - TheCamera.GetPosition()); - if (startProjFwd * endProjFwd < 0.0f) { //if one of point behind us and second before us - float fStartDistFwd = Abs(startProjFwd) / (Abs(startProjFwd) + Abs(endProjFwd)); - - float startProjUp = DotProduct(TheCamera.GetUp(), *start - TheCamera.GetPosition()); - float endProjUp = DotProduct(TheCamera.GetUp(), *end - TheCamera.GetPosition()); - float distUp = (endProjUp - startProjUp) * fStartDistFwd + startProjUp; - - float startProjRight = DotProduct(TheCamera.GetRight(), *start - TheCamera.GetPosition()); - float endProjRight = DotProduct(TheCamera.GetRight(), *end - TheCamera.GetPosition()); - float distRight = (endProjRight - startProjRight) * fStartDistFwd + startProjRight; - - float dist = Sqrt(SQR(distUp) + SQR(distRight)); - if (dist < 2.0f) { - if(distRight < 0.0f) - DMAudio.PlayFrontEndSound(SOUND_BULLETTRACE_2, 127 * (1.0f - dist * 0.5f)); - else - DMAudio.PlayFrontEndSound(SOUND_BULLETTRACE_1, 127 * (1.0f - dist * 0.5f)); - } - } -} - -void CBulletTraces::AddTrace(CVector* start, CVector* end, int32 weaponType, class CEntity* shooter) -{ - CPhysical* player; - float speed; - int16 camMode; - - if (shooter == (CEntity*)FindPlayerPed() || (FindPlayerVehicle() != nil && FindPlayerVehicle() == (CVehicle*)shooter)) { - camMode = TheCamera.Cams[TheCamera.ActiveCam].Mode; - if (camMode == CCam::MODE_M16_1STPERSON - || camMode == CCam::MODE_CAMERA - || camMode == CCam::MODE_SNIPER - || camMode == CCam::MODE_M16_1STPERSON_RUNABOUT - || camMode == CCam::MODE_ROCKETLAUNCHER - || camMode == CCam::MODE_ROCKETLAUNCHER_RUNABOUT - || camMode == CCam::MODE_SNIPER_RUNABOUT - || camMode == CCam::MODE_HELICANNON_1STPERSON) { - - player = FindPlayerVehicle() ? (CPhysical*)FindPlayerVehicle() : (CPhysical*)FindPlayerPed(); - speed = player->m_vecMoveSpeed.Magnitude(); - if (speed < 0.05f) - return; - } - } - - switch (weaponType) { - case WEAPONTYPE_PYTHON: - case WEAPONTYPE_SHOTGUN: - case WEAPONTYPE_SPAS12_SHOTGUN: - case WEAPONTYPE_STUBBY_SHOTGUN: - CBulletTraces::AddTrace(start, end, 0.7f, 1000, 200); - break; - case WEAPONTYPE_M4: - case WEAPONTYPE_RUGER: - case WEAPONTYPE_SNIPERRIFLE: - case WEAPONTYPE_LASERSCOPE: - case WEAPONTYPE_M60: - case WEAPONTYPE_MINIGUN: - case WEAPONTYPE_HELICANNON: - CBulletTraces::AddTrace(start, end, 1.0f, 2000, 220); - break; - default: - CBulletTraces::AddTrace(start, end, 0.4f, 750, 150); - break; - } -} - -void CBulletTraces::Render(void) -{ - for (int i = 0; i < NUMBULLETTRACES; i++) { - if (!aTraces[i].m_bInUse) - continue; - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpSmokeTrailTexture)); - - float timeAlive = CTimer::GetTimeInMilliseconds() - aTraces[i].m_nCreationTime; - - float traceThickness = aTraces[i].m_fThickness * timeAlive / aTraces[i].m_nLifeTime; - CVector horizontalOffset = aTraces[i].m_vecEndPos - aTraces[i].m_vecStartPos; - horizontalOffset.Normalise(); - horizontalOffset *= traceThickness; - - //then closer trace to die then it more transparent - uint8 nAlphaValue = aTraces[i].m_fVisibility * (aTraces[i].m_nLifeTime - timeAlive) / aTraces[i].m_nLifeTime; - - CVector start = aTraces[i].m_vecStartPos; - CVector end = aTraces[i].m_vecEndPos; - float startProj = DotProduct(start - TheCamera.GetPosition(), TheCamera.GetForward()) - 0.7f; - float endProj = DotProduct(end - TheCamera.GetPosition(), TheCamera.GetForward()) - 0.7f; - if (startProj < 0.0f && endProj < 0.0f) //we dont need render trace behind us - continue; - - if (startProj < 0.0f) { //if strat behind us move it closer - float absStartProj = Abs(startProj); - float absEndProj = Abs(endProj); - start = (absEndProj * start + absStartProj * end) / (absStartProj + absEndProj); - } else if (endProj < 0.0f) { - float absStartProj = Abs(startProj); - float absEndProj = Abs(endProj); - end = (absEndProj * start + absStartProj * end) / (absStartProj + absEndProj); - } - - //we divide trace at three parts - CVector start2 = (7.0f * start + end) / 8; - CVector end2 = (7.0f * end + start) / 8; - - RwIm3DVertexSetV(&TraceVertices[5], 10.0f); - RwIm3DVertexSetV(&TraceVertices[6], 10.0f); - RwIm3DVertexSetV(&TraceVertices[7], 10.0f); - RwIm3DVertexSetV(&TraceVertices[8], 10.0f); - RwIm3DVertexSetV(&TraceVertices[9], 10.0f); - - RwIm3DVertexSetRGBA(&TraceVertices[0], 255, 255, 255, nAlphaValue); - RwIm3DVertexSetRGBA(&TraceVertices[1], 255, 255, 255, nAlphaValue); - RwIm3DVertexSetRGBA(&TraceVertices[2], 255, 255, 255, nAlphaValue); - RwIm3DVertexSetRGBA(&TraceVertices[3], 255, 255, 255, nAlphaValue); - RwIm3DVertexSetRGBA(&TraceVertices[4], 255, 255, 255, nAlphaValue); - RwIm3DVertexSetRGBA(&TraceVertices[5], 255, 255, 255, nAlphaValue); - RwIm3DVertexSetRGBA(&TraceVertices[6], 255, 255, 255, nAlphaValue); - RwIm3DVertexSetRGBA(&TraceVertices[7], 255, 255, 255, nAlphaValue); - RwIm3DVertexSetRGBA(&TraceVertices[8], 255, 255, 255, nAlphaValue); - RwIm3DVertexSetRGBA(&TraceVertices[9], 255, 255, 255, nAlphaValue); - //two points in center - RwIm3DVertexSetPos(&TraceVertices[0], start2.x, start2.y, start2.z); - RwIm3DVertexSetPos(&TraceVertices[5], end2.x, end2.y, end2.z); - //vertical planes - RwIm3DVertexSetPos(&TraceVertices[1], start2.x, start2.y, start2.z + traceThickness); - RwIm3DVertexSetPos(&TraceVertices[3], start2.x, start2.y, start2.z - traceThickness); - RwIm3DVertexSetPos(&TraceVertices[6], end2.x, end2.y, end2.z + traceThickness); - RwIm3DVertexSetPos(&TraceVertices[8], end2.x, end2.y, end2.z - traceThickness); - //horizontal planes - RwIm3DVertexSetPos(&TraceVertices[2], start2.x + horizontalOffset.y, start2.y - horizontalOffset.x, start2.z); - RwIm3DVertexSetPos(&TraceVertices[7], end2.x + horizontalOffset.y, end2.y - horizontalOffset.x, end2.z); -#ifdef FIX_BUGS //this point calculated wrong for some reason - RwIm3DVertexSetPos(&TraceVertices[4], start2.x - horizontalOffset.y, start2.y + horizontalOffset.x, start2.z); - RwIm3DVertexSetPos(&TraceVertices[9], end2.x - horizontalOffset.y, end2.y + horizontalOffset.x, end2.z); -#else - RwIm3DVertexSetPos(&TraceVertices[4], start2.x - horizontalOffset.y, start2.y - horizontalOffset.y, start2.z); - RwIm3DVertexSetPos(&TraceVertices[9], end2.x - horizontalOffset.y, end2.y - horizontalOffset.y, end2.z); -#endif - - if (RwIm3DTransform(TraceVertices, ARRAY_SIZE(TraceVertices), nil, 1)) { - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TraceIndexList, ARRAY_SIZE(TraceIndexList)); - RwIm3DEnd(); - } - - RwIm3DVertexSetV(&TraceVertices[5], 2.0f); - RwIm3DVertexSetV(&TraceVertices[6], 2.0f); - RwIm3DVertexSetV(&TraceVertices[7], 2.0f); - RwIm3DVertexSetV(&TraceVertices[8], 2.0f); - RwIm3DVertexSetV(&TraceVertices[9], 2.0f); - RwIm3DVertexSetRGBA(&TraceVertices[0], 255, 255, 255, 0); - RwIm3DVertexSetRGBA(&TraceVertices[1], 255, 255, 255, 0); - RwIm3DVertexSetRGBA(&TraceVertices[2], 255, 255, 255, 0); - RwIm3DVertexSetRGBA(&TraceVertices[3], 255, 255, 255, 0); - RwIm3DVertexSetRGBA(&TraceVertices[4], 255, 255, 255, 0); - - RwIm3DVertexSetPos(&TraceVertices[0], start.x, start.y, start.z); - RwIm3DVertexSetPos(&TraceVertices[1], start.x, start.y, start.z + traceThickness); - RwIm3DVertexSetPos(&TraceVertices[3], start.x, start.y, start.z - traceThickness); - RwIm3DVertexSetPos(&TraceVertices[2], start.x + horizontalOffset.y, start.y - horizontalOffset.x, start.z); - - RwIm3DVertexSetPos(&TraceVertices[5], start2.x, start2.y, start2.z); - RwIm3DVertexSetPos(&TraceVertices[6], start2.x, start2.y, start2.z + traceThickness); - RwIm3DVertexSetPos(&TraceVertices[8], start2.x, start2.y, start2.z - traceThickness); - RwIm3DVertexSetPos(&TraceVertices[7], start2.x + horizontalOffset.y, start2.y - horizontalOffset.x, start2.z); -#ifdef FIX_BUGS - RwIm3DVertexSetPos(&TraceVertices[4], start.x - horizontalOffset.y, start.y + horizontalOffset.x, start.z); - RwIm3DVertexSetPos(&TraceVertices[9], start2.x - horizontalOffset.y, start2.y + horizontalOffset.x, start2.z); -#else - RwIm3DVertexSetPos(&TraceVertices[4], start.x - horizontalOffset.y, start.y - horizontalOffset.y, start.z); - RwIm3DVertexSetPos(&TraceVertices[9], start2.x - horizontalOffset.y, start2.y - horizontalOffset.y, start2.z); -#endif - - if (RwIm3DTransform(TraceVertices, ARRAY_SIZE(TraceVertices), nil, rwIM3D_VERTEXUV)) { - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TraceIndexList, ARRAY_SIZE(TraceIndexList)); - RwIm3DEnd(); - } - - RwIm3DVertexSetPos(&TraceVertices[1], end.x, end.y, end.z); - RwIm3DVertexSetPos(&TraceVertices[2], end.x, end.y, end.z + traceThickness); - RwIm3DVertexSetPos(&TraceVertices[4], end.x, end.y, end.z - traceThickness); - RwIm3DVertexSetPos(&TraceVertices[3], end.x + horizontalOffset.y, end.y - horizontalOffset.x, end.z); - - RwIm3DVertexSetPos(&TraceVertices[5], end2.x, end2.y, end2.z); - RwIm3DVertexSetPos(&TraceVertices[6], end2.x, end2.y, end2.z + traceThickness); - RwIm3DVertexSetPos(&TraceVertices[8], end2.x, end2.y, end2.z - traceThickness); - RwIm3DVertexSetPos(&TraceVertices[7], end2.x + horizontalOffset.y, end2.y - horizontalOffset.x, end2.z); -#ifdef FIX_BUGS - RwIm3DVertexSetPos(&TraceVertices[5], end.x - horizontalOffset.y, end.y + horizontalOffset.x, end.z); - RwIm3DVertexSetPos(&TraceVertices[9], end2.x - horizontalOffset.y, end2.y + horizontalOffset.x, end2.z); -#else - RwIm3DVertexSetPos(&TraceVertices[5], end.x - horizontalOffset.y, end.y - horizontalOffset.y, end.z); - RwIm3DVertexSetPos(&TraceVertices[9], end2.x - horizontalOffset.y, end2.y - horizontalOffset.y, end2.z); -#endif - - if (RwIm3DTransform(TraceVertices, ARRAY_SIZE(TraceVertices), nil, rwIM3D_VERTEXUV)) { - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TraceIndexList, ARRAY_SIZE(TraceIndexList)); - RwIm3DEnd(); - } - } - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); -} - -void CBulletTraces::Update(void) -{ - for (int i = 0; i < NUMBULLETTRACES; i++) { - if (aTraces[i].m_bInUse) - aTraces[i].Update(); - } -} - -void CBulletTrace::Update(void) -{ - if (CTimer::GetTimeInMilliseconds() - m_nCreationTime >= m_nLifeTime) - m_bInUse = false; -} - -RpAtomic * -MarkerAtomicCB(RpAtomic *atomic, void *data) -{ - *(RpAtomic**)data = atomic; - return atomic; -} - -bool -C3dMarker::AddMarker(uint32 identifier, uint16 type, float fSize, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate) -{ - m_nIdentifier = identifier; - - m_Matrix.SetUnity(); - - RpAtomic *origAtomic; - origAtomic = nil; - RpClumpForAllAtomics(C3dMarkers::m_pRpClumpArray[type], MarkerAtomicCB, &origAtomic); - - RpAtomic *atomic = RpAtomicClone(origAtomic); - RwFrame *frame = RwFrameCreate(); - RpAtomicSetFrame(atomic, frame); - CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil); - - RpGeometry *geometry = RpAtomicGetGeometry(atomic); - RpGeometrySetFlags(geometry, RpGeometryGetFlags(geometry) | rpGEOMETRYMODULATEMATERIALCOLOR); - - m_pAtomic = atomic; - m_Matrix.Attach(RwFrameGetMatrix(RpAtomicGetFrame(m_pAtomic))); - m_pMaterial = RpGeometryGetMaterial(geometry, 0); - m_fSize = fSize; - m_fStdSize = m_fSize; - m_Color.red = r; - m_Color.green = g; - m_Color.blue = b; - m_Color.alpha = a; - m_nPulsePeriod = pulsePeriod; - m_fPulseFraction = pulseFraction; - m_nRotateRate = rotateRate; - m_nStartTime = CTimer::GetTimeInMilliseconds(); - m_nType = type; - return m_pAtomic != nil; -} - -void -C3dMarker::DeleteMarkerObject() -{ - RwFrame *frame; - - m_nIdentifier = 0; - m_nStartTime = 0; - m_bIsUsed = false; - m_bFindZOnNextPlacement = false; - m_nType = MARKERTYPE_INVALID; - - frame = RpAtomicGetFrame(m_pAtomic); - RpAtomicDestroy(m_pAtomic); - RwFrameDestroy(frame); - m_pAtomic = nil; -} - -void -C3dMarker::Render() -{ - if (m_pAtomic == nil) return; - - RpMaterialSetColor(m_pMaterial, &m_Color); - - m_Matrix.UpdateRW(); - - CMatrix matrix; - matrix.Attach(m_Matrix.m_attachment); - matrix.Scale(m_fSize); - matrix.UpdateRW(); - - RwFrameUpdateObjects(RpAtomicGetFrame(m_pAtomic)); - SetBrightMarkerColours(m_fBrightness); - if (m_nType != MARKERTYPE_ARROW) - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RpAtomicRender(m_pAtomic); - if (m_nType != MARKERTYPE_ARROW) - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - ReSetAmbientAndDirectionalColours(); -} - -C3dMarker C3dMarkers::m_aMarkerArray[NUM3DMARKERS]; -int32 C3dMarkers::NumActiveMarkers; -RpClump* C3dMarkers::m_pRpClumpArray[NUMMARKERTYPES]; - -void -C3dMarkers::Init() -{ - for (int i = 0; i < NUM3DMARKERS; i++) { - m_aMarkerArray[i].m_pAtomic = nil; - m_aMarkerArray[i].m_nType = MARKERTYPE_INVALID; - m_aMarkerArray[i].m_bIsUsed = false; - m_aMarkerArray[i].m_bFindZOnNextPlacement = false; - m_aMarkerArray[i].m_nIdentifier = 0; - m_aMarkerArray[i].m_Color.red = 255; - m_aMarkerArray[i].m_Color.green = 255; - m_aMarkerArray[i].m_Color.blue = 255; - m_aMarkerArray[i].m_Color.alpha = 255; - m_aMarkerArray[i].m_nPulsePeriod = 1024; - m_aMarkerArray[i].m_nRotateRate = 5; - m_aMarkerArray[i].m_nStartTime = 0; - m_aMarkerArray[i].m_fPulseFraction = 0.25f; - m_aMarkerArray[i].m_fStdSize = 1.0f; - m_aMarkerArray[i].m_fSize = 1.0f; - m_aMarkerArray[i].m_fBrightness = 1.0f; - m_aMarkerArray[i].m_fCameraRange = 0.0f; - } - NumActiveMarkers = 0; - int txdSlot = CTxdStore::FindTxdSlot("particle"); - CTxdStore::PushCurrentTxd(); - CTxdStore::SetCurrentTxd(txdSlot); - CFileMgr::ChangeDir("\\"); - m_pRpClumpArray[MARKERTYPE_ARROW] = CFileLoader::LoadAtomicFile2Return("models/generic/arrow.dff"); - m_pRpClumpArray[MARKERTYPE_CYLINDER] = CFileLoader::LoadAtomicFile2Return("models/generic/zonecylb.dff"); - CTxdStore::PopCurrentTxd(); -} - -void -C3dMarkers::Shutdown() -{ - for (int i = 0; i < NUM3DMARKERS; i++) { - if (m_aMarkerArray[i].m_pAtomic != nil) - m_aMarkerArray[i].DeleteMarkerObject(); - } - - for (int i = 0; i < NUMMARKERTYPES; i++) { - if (m_pRpClumpArray[i] != nil) - RpClumpDestroy(m_pRpClumpArray[i]); - } -} - -void -C3dMarkers::Render() -{ - NumActiveMarkers = 0; - ActivateDirectional(); - for (int i = 0; i < NUM3DMARKERS; i++) { - if (m_aMarkerArray[i].m_bIsUsed) { - if (m_aMarkerArray[i].m_fCameraRange < 150.0f) { - m_aMarkerArray[i].Render(); - if (m_aMarkerArray[i].m_nType == MARKERTYPE_ARROW) { - CCoronas::RegisterCorona((uintptr)&m_aMarkerArray[i], - SPHERE_MARKER_R, SPHERE_MARKER_G, SPHERE_MARKER_B, 192, - m_aMarkerArray[i].m_Matrix.GetPosition(), 1.2f * m_aMarkerArray[i].m_fSize, 50.0f * TheCamera.LODDistMultiplier, - CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f, false); - } - } - NumActiveMarkers++; - m_aMarkerArray[i].m_bIsUsed = false; - } else if (m_aMarkerArray[i].m_pAtomic != nil) { - m_aMarkerArray[i].DeleteMarkerObject(); - } - } -} - -C3dMarker * -C3dMarkers::PlaceMarker(uint32 identifier, uint16 type, CVector &pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate) -{ - C3dMarker *pMarker; - CVector2D playerPos = FindPlayerCentreOfWorld(0); - pMarker = nil; - float dist = ((CVector2D)pos - playerPos).Magnitude(); - - if (type != MARKERTYPE_ARROW && type != MARKERTYPE_CYLINDER) return nil; - - for (int i = 0; i < NUM3DMARKERS; i++) { - if (!m_aMarkerArray[i].m_bIsUsed && m_aMarkerArray[i].m_nIdentifier == identifier) { - pMarker = &m_aMarkerArray[i]; - break; - } - } - - if (pMarker == nil) { - for (int i = 0; i < NUM3DMARKERS; i++) { - if (m_aMarkerArray[i].m_nType == MARKERTYPE_INVALID) { - pMarker = &m_aMarkerArray[i]; - break; - } - } - } - - if (pMarker == nil && type == MARKERTYPE_ARROW) { - for (int i = 0; i < NUM3DMARKERS; i++) { - if (dist < m_aMarkerArray[i].m_fCameraRange && m_aMarkerArray[i].m_nType == MARKERTYPE_ARROW && (pMarker == nil || m_aMarkerArray[i].m_fCameraRange > pMarker->m_fCameraRange)) { - pMarker = &m_aMarkerArray[i]; - break; - } - } - - if (pMarker != nil) - pMarker->m_nType = MARKERTYPE_INVALID; - } - - if (pMarker == nil) return pMarker; - - pMarker->m_fCameraRange = dist; - if (pMarker->m_nIdentifier == identifier && pMarker->m_nType == type) { - if (type == MARKERTYPE_ARROW) { - if (dist < 25.0f) { - if (dist > 5.0f) - pMarker->m_fStdSize = size - (25.0f - dist) * (0.3f * size) / 20.0f; - else - pMarker->m_fStdSize = size - 0.3f * size; - } else { - pMarker->m_fStdSize = size; - } - } else if (type == MARKERTYPE_CYLINDER) { - if (dist < size + 12.0f) { - if (dist > size + 1.0f) - pMarker->m_Color.alpha = (1.0f - (size + 12.0f - dist) * 0.7f / 11.0f) * (float)a; - else - pMarker->m_Color.alpha = (float)a * 0.3f; - } else { - pMarker->m_Color.alpha = a; - } - } - float someSin = Sin(TWOPI * (float)((pMarker->m_nPulsePeriod - 1) & (CTimer::GetTimeInMilliseconds() - pMarker->m_nStartTime)) / (float)pMarker->m_nPulsePeriod); - pMarker->m_fSize = pMarker->m_fStdSize - pulseFraction * pMarker->m_fStdSize * someSin; - - if (type == MARKERTYPE_ARROW) { - pos.z += 0.25f * pMarker->m_fStdSize * someSin; - } else if (type == MARKERTYPE_0) { - if (someSin > 0.0f) - pMarker->m_Color.alpha = (float)a * 0.7f * someSin + a; - else - pMarker->m_Color.alpha = (float)a * 0.4f * someSin + a; - } - if (pMarker->m_nRotateRate != 0) { - CVector pos = pMarker->m_Matrix.GetPosition(); - pMarker->m_Matrix.RotateZ(DEGTORAD(pMarker->m_nRotateRate * CTimer::GetTimeStep())); - pMarker->m_Matrix.GetPosition() = pos; - } - if (type == MARKERTYPE_ARROW) - pMarker->m_Matrix.GetPosition() = pos; - - if (pMarker->m_bFindZOnNextPlacement) { - if ((playerPos - pos).MagnitudeSqr() < sq(100.f) && CColStore::HasCollisionLoaded(CVector2D(pos))) { - float z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z + 1.0f, nil); - if (z != 0.0f) - pMarker->m_Matrix.GetPosition().z = z - 0.05f * size; - pMarker->m_bFindZOnNextPlacement = false; - } - } - pMarker->m_bIsUsed = true; - return pMarker; - } - - if (pMarker->m_nIdentifier != 0) - pMarker->DeleteMarkerObject(); - - pMarker->AddMarker(identifier, type, size, r, g, b, a, pulsePeriod, pulseFraction, rotateRate); - if (type == MARKERTYPE_CYLINDER || type == MARKERTYPE_0 || type == MARKERTYPE_2) { - if ((playerPos - pos).MagnitudeSqr() < sq(100.f) && CColStore::HasCollisionLoaded(CVector2D(pos))) { - float z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z + 1.0f, nil); - if (z != 0.0f) - pos.z = z - 0.05f * size; - pMarker->m_bFindZOnNextPlacement = false; - } else { - pMarker->m_bFindZOnNextPlacement = true; - } - } - pMarker->m_Matrix.SetTranslate(pos.x, pos.y, pos.z); - if (type == MARKERTYPE_2) { - pMarker->m_Matrix.RotateX(PI); - pMarker->m_Matrix.GetPosition() = pos; - } - pMarker->m_Matrix.UpdateRW(); - if (type == MARKERTYPE_ARROW) { - if (dist < 25.0f) { - if (dist > 5.0f) - pMarker->m_fStdSize = size - (25.0f - dist) * (0.3f * size) / 20.0f; - else - pMarker->m_fStdSize = size - 0.3f * size; - } else { - pMarker->m_fStdSize = size; - } - } else if (type == MARKERTYPE_CYLINDER) { - if (dist < size + 12.0f) { - if (dist > size + 1.0f) - pMarker->m_Color.alpha = (1.0f - (size + 12.0f - dist) * 0.7f / 11.0f) * (float)a; - else - pMarker->m_Color.alpha = (float)a * 0.3f; - } else { - pMarker->m_Color.alpha = a; - } - } - pMarker->m_bIsUsed = true; - return pMarker; -} - -void -C3dMarkers::PlaceMarkerSet(uint32 id, uint16 type, CVector &pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate) -{ - PlaceMarker(id, type, pos, size, r, g, b, a, pulsePeriod, pulseFraction, 1); - PlaceMarker(id, type, pos, size * 0.93f, r, g, b, a, pulsePeriod, pulseFraction, 2); - PlaceMarker(id, type, pos, size * 0.86f, r, g, b, a, pulsePeriod, pulseFraction, -1); -} - - -void -C3dMarkers::Update() -{ -} - - -#define BRIGHTLIGHTS_MAX_DIST (60.0f) // invisible beyond this -#define BRIGHTLIGHTS_FADE_DIST (45.0f) // strongest between these two -#define CARLIGHTS_MAX_DIST (30.0f) -#define CARLIGHTS_FADE_DIST (15.0f) // 31 for close lights - -int CBrightLights::NumBrightLights; -CBrightLight CBrightLights::aBrightLights[NUMBRIGHTLIGHTS]; - -void -CBrightLights::Init(void) -{ - NumBrightLights = 0; -} - -void -CBrightLights::RegisterOne(CVector pos, CVector up, CVector side, CVector front, - uint8 type, uint8 red, uint8 green, uint8 blue) -{ - if(NumBrightLights >= NUMBRIGHTLIGHTS) - return; - - aBrightLights[NumBrightLights].m_camDist = (pos - TheCamera.GetPosition()).Magnitude(); - if(aBrightLights[NumBrightLights].m_camDist > BRIGHTLIGHTS_MAX_DIST) - return; - - aBrightLights[NumBrightLights].m_pos = pos; - aBrightLights[NumBrightLights].m_up = up; - aBrightLights[NumBrightLights].m_side = side; - aBrightLights[NumBrightLights].m_front = front; - aBrightLights[NumBrightLights].m_type = type; - aBrightLights[NumBrightLights].m_red = red; - aBrightLights[NumBrightLights].m_green = green; - aBrightLights[NumBrightLights].m_blue = blue; - - NumBrightLights++; -} - -static float TrafficLightsSide[6] = { -0.09f, 0.09f, 0.162f, 0.09f, -0.09f, -0.162f }; -static float TrafficLightsUp[6] = { 0.162f, 0.162f, 0.0f, -0.162f, -0.162f, 0.0f }; -static float LongCarHeadLightsSide[8] = { -0.2f, 0.2f, -0.2f, 0.2f, -0.2f, 0.2f, -0.2f, 0.2f }; -static float LongCarHeadLightsFront[8] = { 0.1f, 0.1f, -0.1f, -0.1f, 0.1f, 0.1f, -0.1f, -0.1f }; -static float LongCarHeadLightsUp[8] = { 0.1f, 0.1f, 0.1f, 0.1f, -0.1f, -0.1f, -0.1f, -0.1f }; -static float SmallCarHeadLightsSide[8] = { -0.08f, 0.08f, -0.08f, 0.08f, -0.08f, 0.08f, -0.08f, 0.08f }; -static float SmallCarHeadLightsFront[8] = { 0.08f, 0.08f, -0.08f, -0.08f, 0.08f, 0.08f, -0.08f, -0.08f }; -static float SmallCarHeadLightsUp[8] = { 0.08f, 0.08f, 0.08f, 0.08f, -0.08f, -0.08f, -0.08f, -0.08f }; -static float BigCarHeadLightsSide[8] = { -0.15f, 0.15f, -0.15f, 0.15f, -0.15f, 0.15f, -0.15f, 0.15f }; -static float BigCarHeadLightsFront[8] = { 0.15f, 0.15f, -0.15f, -0.15f, 0.15f, 0.15f, -0.15f, -0.15f }; -static float BigCarHeadLightsUp[8] = { 0.15f, 0.15f, 0.15f, 0.15f, -0.15f, -0.15f, -0.15f, -0.15f }; -static float TallCarHeadLightsSide[8] = { -0.08f, 0.08f, -0.08f, 0.08f, -0.08f, 0.08f, -0.08f, 0.08f }; -static float TallCarHeadLightsFront[8] = { 0.08f, 0.08f, -0.08f, -0.08f, 0.08f, 0.08f, -0.08f, -0.08f }; -static float TallCarHeadLightsUp[8] = { 0.2f, 0.2f, 0.2f, 0.2f, -0.2f, -0.2f, -0.2f, -0.2f }; -static float SirenLightsSide[6] = { -0.04f, 0.04f, 0.06f, 0.04f, -0.04f, -0.06f }; -static float SirenLightsUp[6] = { 0.06f, 0.06f, 0.0f, -0.06f, -0.06f, 0.0f }; -static RwImVertexIndex TrafficLightIndices[4*3] = { 0, 1, 5, 1, 2, 3, 1, 3, 4, 1, 4, 5 }; -static RwImVertexIndex CubeIndices[12*3] = { - 0, 2, 1, 1, 2, 3, 3, 5, 1, 3, 7, 5, - 2, 7, 3, 2, 6, 7, 4, 0, 1, 4, 1, 5, - 6, 0, 4, 6, 2, 0, 6, 5, 7, 6, 4, 5 -}; - -void -CBrightLights::Render(void) -{ - int i, j; - CVector pos; - - if(NumBrightLights == 0) - return; - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - - TempBufferVerticesStored = 0; - TempBufferIndicesStored = 0; - - for(i = 0; i < NumBrightLights; i++){ - if(TempBufferIndicesStored > TEMPBUFFERINDEXSIZE-40 || TempBufferVerticesStored > TEMPBUFFERVERTSIZE-40) - RenderOutGeometryBuffer(); - - int r, g, b, a; - float flicker = (CGeneral::GetRandomNumber()&0xFF) * 0.2f; - switch(aBrightLights[i].m_type){ - case BRIGHTLIGHT_TRAFFIC_GREEN: - r = flicker; g = 255; b = flicker; - break; - case BRIGHTLIGHT_TRAFFIC_YELLOW: - r = 255; g = 128; b = flicker; - break; - case BRIGHTLIGHT_TRAFFIC_RED: - r = 255; g = flicker; b = flicker; - break; - - case BRIGHTLIGHT_FRONT_LONG: - case BRIGHTLIGHT_FRONT_SMALL: - case BRIGHTLIGHT_FRONT_BIG: - case BRIGHTLIGHT_FRONT_TALL: - r = 255; g = 255; b = 255; - break; - - case BRIGHTLIGHT_REAR_LONG: - case BRIGHTLIGHT_REAR_SMALL: - case BRIGHTLIGHT_REAR_BIG: - case BRIGHTLIGHT_REAR_TALL: - r = 255; g = flicker; b = flicker; - break; - - case BRIGHTLIGHT_SIREN: - r = aBrightLights[i].m_red; - g = aBrightLights[i].m_green; - b = aBrightLights[i].m_blue; - break; -#ifdef FIX_BUGS //just to make sure that color never will be undefined - default: - return; -#endif - } - - if(aBrightLights[i].m_camDist < BRIGHTLIGHTS_FADE_DIST) - a = 255; - else - a = 255*(1.0f - (aBrightLights[i].m_camDist-BRIGHTLIGHTS_FADE_DIST)/(BRIGHTLIGHTS_MAX_DIST-BRIGHTLIGHTS_FADE_DIST)); - // fade car lights down to 31 as they come near - if(aBrightLights[i].m_type >= BRIGHTLIGHT_FRONT_LONG && aBrightLights[i].m_type <= BRIGHTLIGHT_REAR_TALL){ - if(aBrightLights[i].m_camDist < CARLIGHTS_FADE_DIST) - a = 31; - else if(aBrightLights[i].m_camDist < CARLIGHTS_MAX_DIST) - a = 31 + (255-31)*((aBrightLights[i].m_camDist-CARLIGHTS_FADE_DIST)/(CARLIGHTS_MAX_DIST-CARLIGHTS_FADE_DIST)); - } - - switch(aBrightLights[i].m_type){ - case BRIGHTLIGHT_TRAFFIC_GREEN: - case BRIGHTLIGHT_TRAFFIC_YELLOW: - case BRIGHTLIGHT_TRAFFIC_RED: - for(j = 0; j < 6; j++){ - pos = TrafficLightsSide[j]*aBrightLights[i].m_side + - TrafficLightsUp[j]*aBrightLights[i].m_up + - aBrightLights[i].m_pos; - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+j], r, g, b, a); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+j], pos.x, pos.y, pos.z); - } - for(j = 0; j < 4*3; j++) - TempBufferRenderIndexList[TempBufferIndicesStored+j] = TrafficLightIndices[j] + TempBufferVerticesStored; - TempBufferVerticesStored += 6; - TempBufferIndicesStored += 4*3; - break; - - case BRIGHTLIGHT_FRONT_LONG: - case BRIGHTLIGHT_REAR_LONG: - for(j = 0; j < 8; j++){ - pos = LongCarHeadLightsSide[j]*aBrightLights[i].m_side + - LongCarHeadLightsUp[j]*aBrightLights[i].m_up + - LongCarHeadLightsFront[j]*aBrightLights[i].m_front + - aBrightLights[i].m_pos; - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+j], r, g, b, a); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+j], pos.x, pos.y, pos.z); - } - for(j = 0; j < 12*3; j++) - TempBufferRenderIndexList[TempBufferIndicesStored+j] = CubeIndices[j] + TempBufferVerticesStored; - TempBufferVerticesStored += 8; - TempBufferIndicesStored += 12*3; - break; - - case BRIGHTLIGHT_FRONT_SMALL: - case BRIGHTLIGHT_REAR_SMALL: - for(j = 0; j < 8; j++){ - pos = SmallCarHeadLightsSide[j]*aBrightLights[i].m_side + - SmallCarHeadLightsUp[j]*aBrightLights[i].m_up + - SmallCarHeadLightsFront[j]*aBrightLights[i].m_front + - aBrightLights[i].m_pos; - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+j], r, g, b, a); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+j], pos.x, pos.y, pos.z); - } - for(j = 0; j < 12*3; j++) - TempBufferRenderIndexList[TempBufferIndicesStored+j] = CubeIndices[j] + TempBufferVerticesStored; - TempBufferVerticesStored += 8; - TempBufferIndicesStored += 12*3; - break; - - case BRIGHTLIGHT_FRONT_BIG: - case BRIGHTLIGHT_REAR_BIG: - for (j = 0; j < 8; j++) { - pos = BigCarHeadLightsSide[j] * aBrightLights[i].m_side + - BigCarHeadLightsUp[j] * aBrightLights[i].m_up + - BigCarHeadLightsFront[j] * aBrightLights[i].m_front + - aBrightLights[i].m_pos; - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + j], r, g, b, a); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + j], pos.x, pos.y, pos.z); - } - for (j = 0; j < 12 * 3; j++) - TempBufferRenderIndexList[TempBufferIndicesStored + j] = CubeIndices[j] + TempBufferVerticesStored; - TempBufferVerticesStored += 8; - TempBufferIndicesStored += 12 * 3; - break; - - case BRIGHTLIGHT_FRONT_TALL: - case BRIGHTLIGHT_REAR_TALL: - for(j = 0; j < 8; j++){ - pos = TallCarHeadLightsSide[j]*aBrightLights[i].m_side + - TallCarHeadLightsUp[j]*aBrightLights[i].m_up + - TallCarHeadLightsFront[j]*aBrightLights[i].m_front + - aBrightLights[i].m_pos; - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+j], r, g, b, a); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+j], pos.x, pos.y, pos.z); - } - for(j = 0; j < 12*3; j++) - TempBufferRenderIndexList[TempBufferIndicesStored+j] = CubeIndices[j] + TempBufferVerticesStored; - TempBufferVerticesStored += 8; - TempBufferIndicesStored += 12*3; - break; - - case BRIGHTLIGHT_SIREN: - for(j = 0; j < 6; j++){ - pos = SirenLightsSide[j] * TheCamera.GetRight() + - SirenLightsUp[j] * TheCamera.GetUp() + - aBrightLights[i].m_pos; - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+j], r, g, b, a); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+j], pos.x, pos.y, pos.z); - } - for(j = 0; j < 4*3; j++) - TempBufferRenderIndexList[TempBufferIndicesStored+j] = TrafficLightIndices[j] + TempBufferVerticesStored; - TempBufferVerticesStored += 6; - TempBufferIndicesStored += 4*3; - break; - - } - } - - RenderOutGeometryBuffer(); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - NumBrightLights = 0; -} - -void -CBrightLights::RenderOutGeometryBuffer(void) -{ - if(TempBufferIndicesStored != 0){ - LittleTest(); - if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV)){ - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); - RwIm3DEnd(); - } - TempBufferVerticesStored = 0; - TempBufferIndicesStored = 0; - } -} - -int CShinyTexts::NumShinyTexts; -CShinyText CShinyTexts::aShinyTexts[NUMSHINYTEXTS]; - -void -CShinyTexts::Init(void) -{ - NumShinyTexts = 0; -} - -void -CShinyTexts::RegisterOne(CVector p0, CVector p1, CVector p2, CVector p3, - float u0, float v0, float u1, float v1, float u2, float v2, float u3, float v3, - uint8 type, uint8 red, uint8 green, uint8 blue, float maxDist) -{ - if(NumShinyTexts >= NUMSHINYTEXTS) - return; - - aShinyTexts[NumShinyTexts].m_camDist = (p0 - TheCamera.GetPosition()).Magnitude(); - if(aShinyTexts[NumShinyTexts].m_camDist > maxDist) - return; - aShinyTexts[NumShinyTexts].m_verts[0] = p0; - aShinyTexts[NumShinyTexts].m_verts[1] = p1; - aShinyTexts[NumShinyTexts].m_verts[2] = p2; - aShinyTexts[NumShinyTexts].m_verts[3] = p3; - aShinyTexts[NumShinyTexts].m_texCoords[0].x = u0; - aShinyTexts[NumShinyTexts].m_texCoords[0].y = v0; - aShinyTexts[NumShinyTexts].m_texCoords[1].x = u1; - aShinyTexts[NumShinyTexts].m_texCoords[1].y = v1; - aShinyTexts[NumShinyTexts].m_texCoords[2].x = u2; - aShinyTexts[NumShinyTexts].m_texCoords[2].y = v2; - aShinyTexts[NumShinyTexts].m_texCoords[3].x = u3; - aShinyTexts[NumShinyTexts].m_texCoords[3].y = v3; - aShinyTexts[NumShinyTexts].m_type = type; - aShinyTexts[NumShinyTexts].m_red = red; - aShinyTexts[NumShinyTexts].m_green = green; - aShinyTexts[NumShinyTexts].m_blue = blue; - // Fade out at half the max dist - float halfDist = maxDist*0.5f; - if(aShinyTexts[NumShinyTexts].m_camDist > halfDist){ - float f = 1.0f - (aShinyTexts[NumShinyTexts].m_camDist - halfDist)/halfDist; - aShinyTexts[NumShinyTexts].m_red *= f; - aShinyTexts[NumShinyTexts].m_green *= f; - aShinyTexts[NumShinyTexts].m_blue *= f; - } - - NumShinyTexts++; -} - -void -CShinyTexts::Render(void) -{ - int i, ix, v; - RwTexture *lastTex = nil; - - if(NumShinyTexts == 0) - return; - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - - TempBufferVerticesStored = 0; - TempBufferIndicesStored = 0; - - for(i = 0; i < NumShinyTexts; i++){ - if(TempBufferIndicesStored > TEMPBUFFERINDEXSIZE-64 || TempBufferVerticesStored > TEMPBUFFERVERTSIZE-62) - RenderOutGeometryBuffer(); - - uint8 r = aShinyTexts[i].m_red; - uint8 g = aShinyTexts[i].m_green; - uint8 b = aShinyTexts[i].m_blue; - - switch(aShinyTexts[i].m_type){ - case SHINYTEXT_WALK: - if(lastTex != gpWalkDontTex){ - RenderOutGeometryBuffer(); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpWalkDontTex)); - lastTex = gpWalkDontTex; - } - quad: - v = TempBufferVerticesStored; - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+0], r, g, b, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[v+0], aShinyTexts[i].m_verts[0].x, aShinyTexts[i].m_verts[0].y, aShinyTexts[i].m_verts[0].z); - RwIm3DVertexSetU(&TempBufferRenderVertices[v+0], aShinyTexts[i].m_texCoords[0].x); - RwIm3DVertexSetV(&TempBufferRenderVertices[v+0], aShinyTexts[i].m_texCoords[0].y); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+1], r, g, b, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[v+1], aShinyTexts[i].m_verts[1].x, aShinyTexts[i].m_verts[1].y, aShinyTexts[i].m_verts[1].z); - RwIm3DVertexSetU(&TempBufferRenderVertices[v+1], aShinyTexts[i].m_texCoords[1].x); - RwIm3DVertexSetV(&TempBufferRenderVertices[v+1], aShinyTexts[i].m_texCoords[1].y); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+2], r, g, b, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[v+2], aShinyTexts[i].m_verts[2].x, aShinyTexts[i].m_verts[2].y, aShinyTexts[i].m_verts[2].z); - RwIm3DVertexSetU(&TempBufferRenderVertices[v+2], aShinyTexts[i].m_texCoords[2].x); - RwIm3DVertexSetV(&TempBufferRenderVertices[v+2], aShinyTexts[i].m_texCoords[2].y); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+3], r, g, b, 255); - RwIm3DVertexSetPos(&TempBufferRenderVertices[v+3], aShinyTexts[i].m_verts[3].x, aShinyTexts[i].m_verts[3].y, aShinyTexts[i].m_verts[3].z); - RwIm3DVertexSetU(&TempBufferRenderVertices[v+3], aShinyTexts[i].m_texCoords[3].x); - RwIm3DVertexSetV(&TempBufferRenderVertices[v+3], aShinyTexts[i].m_texCoords[3].y); - ix = TempBufferIndicesStored; - TempBufferRenderIndexList[ix+0] = 0 + TempBufferVerticesStored; - TempBufferRenderIndexList[ix+1] = 1 + TempBufferVerticesStored; - TempBufferRenderIndexList[ix+2] = 2 + TempBufferVerticesStored; - TempBufferRenderIndexList[ix+3] = 2 + TempBufferVerticesStored; - TempBufferRenderIndexList[ix+4] = 1 + TempBufferVerticesStored; - TempBufferRenderIndexList[ix+5] = 3 + TempBufferVerticesStored; - TempBufferVerticesStored += 4; - TempBufferIndicesStored += 6; - break; - - case SHINYTEXT_FLAT: - if(lastTex != nil){ - RenderOutGeometryBuffer(); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - lastTex = nil; - } - goto quad; - } - } - - RenderOutGeometryBuffer(); - NumShinyTexts = 0; - - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); -} - -void -CShinyTexts::RenderOutGeometryBuffer(void) -{ - if(TempBufferIndicesStored != 0){ - LittleTest(); - if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV)){ - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); - RwIm3DEnd(); - } - TempBufferVerticesStored = 0; - TempBufferIndicesStored = 0; - } -} - - - -#define MONEY_MESSAGE_LIFETIME_MS 2000 - -CMoneyMessage CMoneyMessages::aMoneyMessages[NUMMONEYMESSAGES]; - -void -CMoneyMessage::Render() -{ - const float MAX_SCALE = 4.0f; - uint32 nLifeTime = CTimer::GetTimeInMilliseconds() - m_nTimeRegistered; - if (nLifeTime >= MONEY_MESSAGE_LIFETIME_MS) { - m_nTimeRegistered = 0; - } else { - float fLifeTime = (float)nLifeTime / MONEY_MESSAGE_LIFETIME_MS; - RwV3d vecOut; - float fDistX, fDistY; - if (CSprite::CalcScreenCoors(m_vecPosition + CVector(0.0f, 0.0f, fLifeTime), &vecOut, &fDistX, &fDistY, true)) { - fDistX *= (0.7f * fLifeTime + 2.0f) * m_fSize; - fDistY *= (0.7f * fLifeTime + 2.0f) * m_fSize; - CFont::SetPropOn(); - CFont::SetBackgroundOff(); - float fScaleY = Min(fDistY / 100.0f, MAX_SCALE); - float fScaleX = Min(fDistX / 100.0f, MAX_SCALE); - -#ifdef FIX_BUGS - CFont::SetScale(SCREEN_SCALE_X(fScaleX), SCREEN_SCALE_Y(fScaleY)); -#else - CFont::SetScale(fScaleX, fScaleY); -#endif - CFont::SetCentreOn(); - CFont::SetCentreSize(SCREEN_WIDTH); - CFont::SetJustifyOff(); - CFont::SetColor(CRGBA(m_Colour.r, m_Colour.g, m_Colour.b, (255.0f - 255.0f * fLifeTime) * m_fOpacity)); - CFont::SetBackGroundOnlyTextOff(); - FONT_LOCALE(FONT_STANDARD); - CFont::PrintString(vecOut.x, vecOut.y, m_aText); - } - } -} - -void -CMoneyMessages::Init() -{ - for (int32 i = 0; i < NUMMONEYMESSAGES; i++) - aMoneyMessages[i].m_nTimeRegistered = 0; -} - -void -CMoneyMessages::Render() -{ - for (int32 i = 0; i < NUMMONEYMESSAGES; i++) { - if (aMoneyMessages[i].m_nTimeRegistered != 0) - aMoneyMessages[i].Render(); - } -} - -void -CMoneyMessages::RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity) -{ - uint32 i; -#ifdef FIX_BUGS - for(i = 0; i < NUMMONEYMESSAGES && aMoneyMessages[i].m_nTimeRegistered != 0; i++); -#else - for(i = 0; aMoneyMessages[i].m_nTimeRegistered != 0 && i < NUMMONEYMESSAGES; i++); -#endif - - if(i < NUMMONEYMESSAGES) { - // Add data of this money message to the array - AsciiToUnicode(pText, aMoneyMessages[i].m_aText); - - aMoneyMessages[i].m_nTimeRegistered = CTimer::GetTimeInMilliseconds(); - aMoneyMessages[i].m_vecPosition = vecPos; - aMoneyMessages[i].m_Colour.red = bRed; - aMoneyMessages[i].m_Colour.green = bGreen; - aMoneyMessages[i].m_Colour.blue = bBlue; - aMoneyMessages[i].m_fSize = fSize; - aMoneyMessages[i].m_fOpacity = fOpacity; - } -} - -CRGBA FoamColour(255, 255, 255, 255); -uint32 CSpecialParticleStuff::BoatFromStart; - -void -CSpecialParticleStuff::CreateFoamAroundObject(CMatrix* pMatrix, float innerFw, float innerRg, float innerUp, int32 particles) -{ - float outerFw = innerFw + 5.0f; - float outerRg = innerRg + 5.0f; - float outerUp = innerUp + 5.0f; - for (int attempts = 0; particles > 0 && attempts < 1000; attempts++) { - CVector pos; - int rnd = CGeneral::GetRandomNumber(); - pos.x = (int8)(rnd - 128) * innerFw / 110.0f; - pos.y = (int8)((rnd >> 8) - 128) * innerFw / 110.0f; - pos.z = 0.0f; - if (DotProduct2D(pos, TheCamera.GetForward()) >= 0) - continue; - // was there any point in adding it here? - pos += pMatrix->GetPosition(); - pos.z = 2.0f; - float fw = Abs(DotProduct(pMatrix->GetForward(), pos - pMatrix->GetPosition())); - if (fw >= outerFw) - continue; - float rg = Abs(DotProduct(pMatrix->GetRight(), pos - pMatrix->GetPosition())); - if (rg >= outerRg) - continue; - float up = Abs(DotProduct(pMatrix->GetUp(), pos - pMatrix->GetPosition())); - if (up >= outerUp) - continue; - if (fw > innerFw || rg > innerRg || up > innerUp) { - CParticle::AddParticle(PARTICLE_STEAM2, pos, CVector(0.0f, 0.0f, 0.0f), nil, 4.0f, FoamColour, 1, 0, 0, 0); - particles--; - } - } -} - -void -CSpecialParticleStuff::StartBoatFoamAnimation() -{ - BoatFromStart = CTimer::GetTimeInMilliseconds(); -} - -void -CSpecialParticleStuff::UpdateBoatFoamAnimation(CMatrix* pMatrix) -{ - static int32 FrameInAnimation = 0; - static float X, Y, Z, dX, dY, dZ; - CreateFoamAroundObject(pMatrix, 107.0f, 24.1f, 30.5f, 2); - uint32 prev = CTimer::GetPreviousTimeInMilliseconds(); - uint32 cur = CTimer::GetTimeInMilliseconds(); - if (FrameInAnimation != 0) { - X += dX; - Y += dY; - Z += dZ; - CVector pos = *pMatrix * CVector(X, Y, Z); - CParticle::AddParticle(PARTICLE_STEAM_NY, pos, CVector(0.0f, 0.0f, 0.0f), - nil, FrameInAnimation * 0.5f + 2.0f, FoamColour, 1, 0, 0, 0); - if (++FrameInAnimation > 15) - FrameInAnimation = 0; - } - if ((cur & 0x3FF) < (prev & 0x3FF)) { - FrameInAnimation = 1; - int rnd = CGeneral::GetRandomNumber(); - X = (int8)(rnd - 128) * 0.2f; - Y = (int8)((rnd >> 8) - 128) * 0.2f; - Z = 10.0f; - rnd = CGeneral::GetRandomNumber(); - dX = (int8)(rnd - 128) * 0.02f; - dY = (int8)((rnd >> 8) - 128) * 0.02f; - dZ = 2.0f; - } -} diff --git a/src/render/SpecialFX.h b/src/render/SpecialFX.h deleted file mode 100644 index f163d8ca..00000000 --- a/src/render/SpecialFX.h +++ /dev/null @@ -1,249 +0,0 @@ -#pragma once - -//file done - -class CSpecialFX -{ -public: - static bool bVideoCam; - static bool bLiftCam; - static bool bSnapShotActive; - static int32 SnapShotFrames; - - static void Render(void); - static void Update(void); - static void Init(void); - static void Shutdown(void); - static void AddWeaponStreak(int type); - static void Render2DFXs(); -}; - - -class CRegisteredMotionBlurStreak -{ -public: - uintptr m_id; - uint8 m_red; - uint8 m_green; - uint8 m_blue; - CVector m_pos1[3]; - CVector m_pos2[3]; - bool m_isValid[3]; - - void Update(void); - void Render(void); -}; - - -class CMotionBlurStreaks -{ - static CRegisteredMotionBlurStreak aStreaks[NUMMBLURSTREAKS]; -public: - static void Init(void); - static void Update(void); - static void RegisterStreak(uintptr id, uint8 r, uint8 g, uint8 b, CVector p1, CVector p2); - static void Render(void); -}; - - -struct CBulletTrace -{ - CVector m_vecStartPos; - CVector m_vecEndPos; - bool m_bInUse; - uint32 m_nCreationTime; - uint32 m_nLifeTime; - float m_fThickness; - uint8 m_fVisibility; - - void Update(void); -}; - - -class CBulletTraces -{ -public: - static CBulletTrace aTraces[NUMBULLETTRACES]; - - static void Init(void); - static void Render(void); - static void Update(void); - static void AddTrace(CVector* start, CVector* end, float thickness, uint32 lifeTime, uint8 visibility); - static void AddTrace(CVector* start, CVector* end, int32 weaponType, class CEntity* shooter); -}; - -enum -{ - MARKERTYPE_0 = 0, - MARKERTYPE_ARROW, - MARKERTYPE_2, - MARKERTYPE_3, - MARKERTYPE_CYLINDER, - NUMMARKERTYPES, - - MARKERTYPE_INVALID = 0x101 -}; - - -class C3dMarker -{ -public: - CMatrix m_Matrix; - RpAtomic *m_pAtomic; - RpMaterial *m_pMaterial; - uint16 m_nType; - bool m_bIsUsed; - bool m_bFindZOnNextPlacement; - uint32 m_nIdentifier; - RwRGBA m_Color; - uint16 m_nPulsePeriod; - int16 m_nRotateRate; - uint32 m_nStartTime; - float m_fPulseFraction; - float m_fStdSize; - float m_fSize; - float m_fBrightness; - float m_fCameraRange; - - bool AddMarker(uint32 identifier, uint16 type, float fSize, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate); - void DeleteMarkerObject(); - void Render(); -}; - - -class C3dMarkers -{ -public: - static void Init(); - static void Shutdown(); - static C3dMarker *PlaceMarker(uint32 id, uint16 type, CVector &pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate); - static void PlaceMarkerSet(uint32 id, uint16 type, CVector &pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate); - static void Render(); - static void Update(); - - static C3dMarker m_aMarkerArray[NUM3DMARKERS]; - static int32 NumActiveMarkers; - static RpClump* m_pRpClumpArray[NUMMARKERTYPES]; -}; - -enum -{ - BRIGHTLIGHT_INVALID, - BRIGHTLIGHT_TRAFFIC_GREEN, - BRIGHTLIGHT_TRAFFIC_YELLOW, - BRIGHTLIGHT_TRAFFIC_RED, - - // white - BRIGHTLIGHT_FRONT_LONG, - BRIGHTLIGHT_FRONT_SMALL, - BRIGHTLIGHT_FRONT_BIG, - BRIGHTLIGHT_FRONT_TALL, - - // red - BRIGHTLIGHT_REAR_LONG, - BRIGHTLIGHT_REAR_SMALL, - BRIGHTLIGHT_REAR_BIG, - BRIGHTLIGHT_REAR_TALL, - - BRIGHTLIGHT_SIREN, // unused - - BRIGHTLIGHT_FRONT = BRIGHTLIGHT_FRONT_LONG, - BRIGHTLIGHT_REAR = BRIGHTLIGHT_REAR_LONG, -}; - - -class CBrightLight -{ -public: - CVector m_pos; - CVector m_up; - CVector m_side; - CVector m_front; - float m_camDist; - uint8 m_type; - uint8 m_red; - uint8 m_green; - uint8 m_blue; -}; - - -class CBrightLights -{ - static int NumBrightLights; - static CBrightLight aBrightLights[NUMBRIGHTLIGHTS]; -public: - static void Init(void); - static void RegisterOne(CVector pos, CVector up, CVector side, CVector front, - uint8 type, uint8 red = 0, uint8 green = 0, uint8 blue = 0); - static void Render(void); - static void RenderOutGeometryBuffer(void); -}; - - -enum -{ - SHINYTEXT_WALK = 1, - SHINYTEXT_FLAT -}; - - -class CShinyText -{ -public: - CVector m_verts[4]; - CVector2D m_texCoords[4]; - float m_camDist; - uint8 m_type; - uint8 m_red; - uint8 m_green; - uint8 m_blue; -}; - - -class CShinyTexts -{ - static int NumShinyTexts; - static CShinyText aShinyTexts[NUMSHINYTEXTS]; -public: - static void Init(void); - static void RegisterOne(CVector p0, CVector p1, CVector p2, CVector p3, - float u0, float v0, float u1, float v1, float u2, float v2, float u3, float v3, - uint8 type, uint8 red, uint8 green, uint8 blue, float maxDist); //not used - static void Render(void); - static void RenderOutGeometryBuffer(void); -}; - - -class CMoneyMessage -{ - friend class CMoneyMessages; - - uint32 m_nTimeRegistered; - CVector m_vecPosition; - wchar m_aText[16]; - CRGBA m_Colour; - float m_fSize; - float m_fOpacity; -public: - void Render(); -}; - - -class CMoneyMessages -{ - static CMoneyMessage aMoneyMessages[NUMMONEYMESSAGES]; -public: - static void Init(); - static void Render(); - static void RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity); -}; - - -class CSpecialParticleStuff -{ - static uint32 BoatFromStart; -public: - static void CreateFoamAroundObject(CMatrix*, float, float, float, int32); //not used - static void StartBoatFoamAnimation(); //not used - static void UpdateBoatFoamAnimation(CMatrix*); //not used -}; diff --git a/src/render/Sprite.cpp b/src/render/Sprite.cpp deleted file mode 100644 index 58b29ea9..00000000 --- a/src/render/Sprite.cpp +++ /dev/null @@ -1,599 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "Draw.h" -#include "Camera.h" -#include "Sprite.h" - -float CSprite::m_f2DNearScreenZ; -float CSprite::m_f2DFarScreenZ; -float CSprite::m_fRecipNearClipPlane; -int32 CSprite::m_bFlushSpriteBufferSwitchZTest; - -float -CSprite::CalcHorizonCoors(void) -{ - CVector p = TheCamera.GetPosition() + CVector(TheCamera.CamFrontXNorm, TheCamera.CamFrontYNorm, 0.0f)*3000.0f; - p.z = 0.0f; - p = TheCamera.m_viewMatrix * p; - return p.y * SCREEN_HEIGHT / p.z; -} - -bool -CSprite::CalcScreenCoors(const RwV3d &in, RwV3d *out, float *outw, float *outh, bool farclip) -{ - CVector viewvec = TheCamera.m_viewMatrix * in; - *out = viewvec; - if(out->z <= CDraw::GetNearClipZ() + 1.0f) return false; - if(out->z >= CDraw::GetFarClipZ() && farclip) return false; - float recip = 1.0f/out->z; - out->x *= SCREEN_WIDTH * recip; - out->y *= SCREEN_HEIGHT * recip; - const float fov = DefaultFOV; - // this is used to scale correctly if you zoom in with sniper rifle - float fovScale = fov / CDraw::GetFOV(); - -#ifdef FIX_SPRITES - *outw = CDraw::ms_bFixSprites ? (fovScale * recip * SCREEN_HEIGHT) : (fovScale * SCREEN_SCALE_AR(recip) * SCREEN_WIDTH); -#else - *outw = fovScale * SCREEN_SCALE_AR(recip) * SCREEN_WIDTH; -#endif - *outh = fovScale * recip * SCREEN_HEIGHT; - - return true; -} - -#define SPRITEBUFFERSIZE 64 -static int32 nSpriteBufferIndex; -static RwIm2DVertex SpriteBufferVerts[SPRITEBUFFERSIZE*6]; -static RwIm2DVertex verts[4]; - -void -CSprite::InitSpriteBuffer(void) -{ - m_f2DNearScreenZ = RwIm2DGetNearScreenZ(); - m_f2DFarScreenZ = RwIm2DGetFarScreenZ(); -} - -void -CSprite::InitSpriteBuffer2D(void) -{ - m_fRecipNearClipPlane = 1.0f / RwCameraGetNearClipPlane(Scene.camera); - InitSpriteBuffer(); -} - -void -CSprite::FlushSpriteBuffer(void) -{ - if(nSpriteBufferIndex > 0){ - if(m_bFlushSpriteBufferSwitchZTest){ - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwIm2DRenderPrimitive(rwPRIMTYPETRILIST, SpriteBufferVerts, nSpriteBufferIndex*6); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - }else - RwIm2DRenderPrimitive(rwPRIMTYPETRILIST, SpriteBufferVerts, nSpriteBufferIndex*6); - nSpriteBufferIndex = 0; - } -} - -void -CSprite::RenderOneXLUSprite(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, uint8 a) -{ - static short indices[] = { 0, 1, 2, 3 }; - // 0---3 - // | | - // 1---2 - float xs[4]; - float ys[4]; - float us[4]; - float vs[4]; - int i; - - xs[0] = x-w; us[0] = 0.0f; - xs[1] = x-w; us[1] = 0.0f; - xs[2] = x+w; us[2] = 1.0f; - xs[3] = x+w; us[3] = 1.0f; - - ys[0] = y-h; vs[0] = 0.0f; - ys[1] = y+h; vs[1] = 1.0f; - ys[2] = y+h; vs[2] = 1.0f; - ys[3] = y-h; vs[3] = 0.0f; - - // clip - for(i = 0; i < 4; i++){ - if(xs[i] < 0.0f){ - us[i] = -xs[i] / (2.0f*w); - xs[i] = 0.0f; - } - if(xs[i] > SCREEN_WIDTH){ - us[i] = 1.0f - (xs[i]-SCREEN_WIDTH) / (2.0f*w); - xs[i] = SCREEN_WIDTH; - } - if(ys[i] < 0.0f){ - vs[i] = -ys[i] / (2.0f*h); - ys[i] = 0.0f; - } - if(ys[i] > SCREEN_HEIGHT){ - vs[i] = 1.0f - (ys[i]-SCREEN_HEIGHT) / (2.0f*h); - ys[i] = SCREEN_HEIGHT; - } - } - - // (DrawZ - DrawNear)/(DrawFar - DrawNear) = (SpriteZ-SpriteNear)/(SpriteFar-SpriteNear) - // So to calculate SpriteZ: - float screenz = m_f2DNearScreenZ + - (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / - ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); - - for(i = 0; i < 4; i++){ - RwIm2DVertexSetScreenX(&verts[i], xs[i]); - RwIm2DVertexSetScreenY(&verts[i], ys[i]); - RwIm2DVertexSetScreenZ(&verts[i], screenz); - RwIm2DVertexSetCameraZ(&verts[i], z); - RwIm2DVertexSetRecipCameraZ(&verts[i], recipz); - RwIm2DVertexSetIntRGBA(&verts[i], r*intens>>8, g*intens>>8, b*intens>>8, a); - RwIm2DVertexSetU(&verts[i], us[i], recipz); - RwIm2DVertexSetV(&verts[i], vs[i], recipz); - } - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, verts, 4); -} - -void -CSprite::RenderOneXLUSprite_Rotate_Aspect(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float rotation, uint8 a) -{ - float c = Cos(rotation); - float s = Sin(rotation); - - float xs[4]; - float ys[4]; - float us[4]; - float vs[4]; - int i; - - // Fade out when too near - // why not in buffered version? - if(z < 2.3f){ - if(z < 1.3f) - return; - int f = (z - 1.3f)/(2.3f-1.3f) * 255; - r = f*r >> 8; - g = f*g >> 8; - b = f*b >> 8; - intens = f*intens >> 8; - } - - xs[0] = x + w*(-c-s); us[0] = 0.0f; - xs[1] = x + w*(-c+s); us[1] = 0.0f; - xs[2] = x + w*(+c+s); us[2] = 1.0f; - xs[3] = x + w*(+c-s); us[3] = 1.0f; - - ys[0] = y + h*(-c+s); vs[0] = 0.0f; - ys[1] = y + h*(+c+s); vs[1] = 1.0f; - ys[2] = y + h*(+c-s); vs[2] = 1.0f; - ys[3] = y + h*(-c-s); vs[3] = 0.0f; - - // No clipping, just culling - if(xs[0] < 0.0f && xs[1] < 0.0f && xs[2] < 0.0f && xs[3] < 0.0f) return; - if(ys[0] < 0.0f && ys[1] < 0.0f && ys[2] < 0.0f && ys[3] < 0.0f) return; - if(xs[0] > SCREEN_WIDTH && xs[1] > SCREEN_WIDTH && - xs[2] > SCREEN_WIDTH && xs[3] > SCREEN_WIDTH) return; - if(ys[0] > SCREEN_HEIGHT && ys[1] > SCREEN_HEIGHT && - ys[2] > SCREEN_HEIGHT && ys[3] > SCREEN_HEIGHT) return; - - float screenz = m_f2DNearScreenZ + - (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / - ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); - - for(i = 0; i < 4; i++){ - RwIm2DVertexSetScreenX(&verts[i], xs[i]); - RwIm2DVertexSetScreenY(&verts[i], ys[i]); - RwIm2DVertexSetScreenZ(&verts[i], screenz); - RwIm2DVertexSetCameraZ(&verts[i], z); - RwIm2DVertexSetRecipCameraZ(&verts[i], recipz); - RwIm2DVertexSetIntRGBA(&verts[i], r*intens>>8, g*intens>>8, b*intens>>8, a); - RwIm2DVertexSetU(&verts[i], us[i], recipz); - RwIm2DVertexSetV(&verts[i], vs[i], recipz); - } - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, verts, 4); -} - -void -CSprite::RenderBufferedOneXLUSprite(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, uint8 a) -{ - m_bFlushSpriteBufferSwitchZTest = 0; - - // 0---3 - // | | - // 1---2 - float xs[4]; - float ys[4]; - float us[4]; - float vs[4]; - int i; - - xs[0] = x-w; us[0] = 0.0f; - xs[1] = x-w; us[1] = 0.0f; - xs[2] = x+w; us[2] = 1.0f; - xs[3] = x+w; us[3] = 1.0f; - - ys[0] = y-h; vs[0] = 0.0f; - ys[1] = y+h; vs[1] = 1.0f; - ys[2] = y+h; vs[2] = 1.0f; - ys[3] = y-h; vs[3] = 0.0f; - - // clip - for(i = 0; i < 4; i++){ - if(xs[i] < 0.0f){ - us[i] = -xs[i] / (2.0f*w); - xs[i] = 0.0f; - } - if(xs[i] > SCREEN_WIDTH){ - us[i] = 1.0f - (xs[i]-SCREEN_WIDTH) / (2.0f*w); - xs[i] = SCREEN_WIDTH; - } - if(ys[i] < 0.0f){ - vs[i] = -ys[i] / (2.0f*h); - ys[i] = 0.0f; - } - if(ys[i] > SCREEN_HEIGHT){ - vs[i] = 1.0f - (ys[i]-SCREEN_HEIGHT) / (2.0f*h); - ys[i] = SCREEN_HEIGHT; - } - } - - float screenz = m_f2DNearScreenZ + - (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / - ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); - - RwIm2DVertex *vert = &SpriteBufferVerts[nSpriteBufferIndex*6]; - static int indices[6] = { 0, 1, 2, 3, 0, 2 }; - for(i = 0; i < 6; i++){ - RwIm2DVertexSetScreenX(&vert[i], xs[indices[i]]); - RwIm2DVertexSetScreenY(&vert[i], ys[indices[i]]); - RwIm2DVertexSetScreenZ(&vert[i], screenz); - RwIm2DVertexSetCameraZ(&vert[i], z); - RwIm2DVertexSetRecipCameraZ(&vert[i], recipz); - RwIm2DVertexSetIntRGBA(&vert[i], r*intens>>8, g*intens>>8, b*intens>>8, a); - RwIm2DVertexSetU(&vert[i], us[indices[i]], recipz); - RwIm2DVertexSetV(&vert[i], vs[indices[i]], recipz); - } - nSpriteBufferIndex++; - if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) - FlushSpriteBuffer(); -} - -void -CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float rotation, uint8 a) -{ - m_bFlushSpriteBufferSwitchZTest = 0; - // TODO: replace with lookup - float c = Cos(rotation); - float s = Sin(rotation); - - float xs[4]; - float ys[4]; - float us[4]; - float vs[4]; - int i; - - xs[0] = x - c*w - s*h; us[0] = 0.0f; - xs[1] = x - c*w + s*h; us[1] = 0.0f; - xs[2] = x + c*w + s*h; us[2] = 1.0f; - xs[3] = x + c*w - s*h; us[3] = 1.0f; - - ys[0] = y - c*h + s*w; vs[0] = 0.0f; - ys[1] = y + c*h + s*w; vs[1] = 1.0f; - ys[2] = y + c*h - s*w; vs[2] = 1.0f; - ys[3] = y - c*h - s*w; vs[3] = 0.0f; - - // No clipping, just culling - if(xs[0] < 0.0f && xs[1] < 0.0f && xs[2] < 0.0f && xs[3] < 0.0f) return; - if(ys[0] < 0.0f && ys[1] < 0.0f && ys[2] < 0.0f && ys[3] < 0.0f) return; - if(xs[0] > SCREEN_WIDTH && xs[1] > SCREEN_WIDTH && - xs[2] > SCREEN_WIDTH && xs[3] > SCREEN_WIDTH) return; - if(ys[0] > SCREEN_HEIGHT && ys[1] > SCREEN_HEIGHT && - ys[2] > SCREEN_HEIGHT && ys[3] > SCREEN_HEIGHT) return; - - float screenz = m_f2DNearScreenZ + - (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / - ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); - - RwIm2DVertex *vert = &SpriteBufferVerts[nSpriteBufferIndex*6]; - static int indices[6] = { 0, 1, 2, 3, 0, 2 }; - for(i = 0; i < 6; i++){ - RwIm2DVertexSetScreenX(&vert[i], xs[indices[i]]); - RwIm2DVertexSetScreenY(&vert[i], ys[indices[i]]); - RwIm2DVertexSetScreenZ(&vert[i], screenz); - RwIm2DVertexSetCameraZ(&vert[i], z); - RwIm2DVertexSetRecipCameraZ(&vert[i], recipz); - RwIm2DVertexSetIntRGBA(&vert[i], r*intens>>8, g*intens>>8, b*intens>>8, a); - RwIm2DVertexSetU(&vert[i], us[indices[i]], recipz); - RwIm2DVertexSetV(&vert[i], vs[indices[i]], recipz); - } - nSpriteBufferIndex++; - if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) - FlushSpriteBuffer(); -} - -void -CSprite::RenderBufferedOneXLUSprite_Rotate_Aspect(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float rotation, uint8 a) -{ - m_bFlushSpriteBufferSwitchZTest = 0; - float c = Cos(rotation); - float s = Sin(rotation); - - float xs[4]; - float ys[4]; - float us[4]; - float vs[4]; - int i; - - xs[0] = x + w*(-c-s); us[0] = 0.0f; - xs[1] = x + w*(-c+s); us[1] = 0.0f; - xs[2] = x + w*(+c+s); us[2] = 1.0f; - xs[3] = x + w*(+c-s); us[3] = 1.0f; - - ys[0] = y + h*(-c+s); vs[0] = 0.0f; - ys[1] = y + h*(+c+s); vs[1] = 1.0f; - ys[2] = y + h*(+c-s); vs[2] = 1.0f; - ys[3] = y + h*(-c-s); vs[3] = 0.0f; - - // No clipping, just culling - if(xs[0] < 0.0f && xs[1] < 0.0f && xs[2] < 0.0f && xs[3] < 0.0f) return; - if(ys[0] < 0.0f && ys[1] < 0.0f && ys[2] < 0.0f && ys[3] < 0.0f) return; - if(xs[0] > SCREEN_WIDTH && xs[1] > SCREEN_WIDTH && - xs[2] > SCREEN_WIDTH && xs[3] > SCREEN_WIDTH) return; - if(ys[0] > SCREEN_HEIGHT && ys[1] > SCREEN_HEIGHT && - ys[2] > SCREEN_HEIGHT && ys[3] > SCREEN_HEIGHT) return; - - float screenz = m_f2DNearScreenZ + - (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / - ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); - - RwIm2DVertex *vert = &SpriteBufferVerts[nSpriteBufferIndex*6]; - static int indices[6] = { 0, 1, 2, 3, 0, 2 }; - for(i = 0; i < 6; i++){ - RwIm2DVertexSetScreenX(&vert[i], xs[indices[i]]); - RwIm2DVertexSetScreenY(&vert[i], ys[indices[i]]); - RwIm2DVertexSetScreenZ(&vert[i], screenz); - RwIm2DVertexSetCameraZ(&vert[i], z); - RwIm2DVertexSetRecipCameraZ(&vert[i], recipz); - RwIm2DVertexSetIntRGBA(&vert[i], r*intens>>8, g*intens>>8, b*intens>>8, a); - RwIm2DVertexSetU(&vert[i], us[indices[i]], recipz); - RwIm2DVertexSetV(&vert[i], vs[indices[i]], recipz); - } - nSpriteBufferIndex++; - if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) - FlushSpriteBuffer(); -} - -void -CSprite::RenderBufferedOneXLUSprite_Rotate_2Colours(float x, float y, float z, float w, float h, uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2, float cx, float cy, float recipz, float rotation, uint8 a) -{ - m_bFlushSpriteBufferSwitchZTest = 0; - float c = Cos(rotation); - float s = Sin(rotation); - - float xs[4]; - float ys[4]; - float us[4]; - float vs[4]; - float cf[4]; - int i; - - xs[0] = x + w*(-c-s); us[0] = 0.0f; - xs[1] = x + w*(-c+s); us[1] = 0.0f; - xs[2] = x + w*(+c+s); us[2] = 1.0f; - xs[3] = x + w*(+c-s); us[3] = 1.0f; - - ys[0] = y + h*(-c+s); vs[0] = 0.0f; - ys[1] = y + h*(+c+s); vs[1] = 1.0f; - ys[2] = y + h*(+c-s); vs[2] = 1.0f; - ys[3] = y + h*(-c-s); vs[3] = 0.0f; - - // No clipping, just culling - if(xs[0] < 0.0f && xs[1] < 0.0f && xs[2] < 0.0f && xs[3] < 0.0f) return; - if(ys[0] < 0.0f && ys[1] < 0.0f && ys[2] < 0.0f && ys[3] < 0.0f) return; - if(xs[0] > SCREEN_WIDTH && xs[1] > SCREEN_WIDTH && - xs[2] > SCREEN_WIDTH && xs[3] > SCREEN_WIDTH) return; - if(ys[0] > SCREEN_HEIGHT && ys[1] > SCREEN_HEIGHT && - ys[2] > SCREEN_HEIGHT && ys[3] > SCREEN_HEIGHT) return; - - // Colour factors, cx/y is the direction in which colours change from rgb1 to rgb2 - cf[0] = (cx*(-c-s) + cy*(-c+s))*0.5f + 0.5f; - cf[0] = Clamp(cf[0], 0.0f, 1.0f); - cf[1] = (cx*(-c+s) + cy*( c+s))*0.5f + 0.5f; - cf[1] = Clamp(cf[1], 0.0f, 1.0f); - cf[2] = (cx*( c+s) + cy*( c-s))*0.5f + 0.5f; - cf[2] = Clamp(cf[2], 0.0f, 1.0f); - cf[3] = (cx*( c-s) + cy*(-c-s))*0.5f + 0.5f; - cf[3] = Clamp(cf[3], 0.0f, 1.0f); - - float screenz = m_f2DNearScreenZ + - (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / - ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); - - RwIm2DVertex *vert = &SpriteBufferVerts[nSpriteBufferIndex*6]; - static int indices[6] = { 0, 1, 2, 3, 0, 2 }; - for(i = 0; i < 6; i++){ - RwIm2DVertexSetScreenX(&vert[i], xs[indices[i]]); - RwIm2DVertexSetScreenY(&vert[i], ys[indices[i]]); - RwIm2DVertexSetScreenZ(&vert[i], screenz); - RwIm2DVertexSetCameraZ(&vert[i], z); - RwIm2DVertexSetRecipCameraZ(&vert[i], recipz); - RwIm2DVertexSetIntRGBA(&vert[i], - r1*cf[indices[i]] + r2*(1.0f - cf[indices[i]]), - g1*cf[indices[i]] + g2*(1.0f - cf[indices[i]]), - b1*cf[indices[i]] + b2*(1.0f - cf[indices[i]]), - a); - RwIm2DVertexSetU(&vert[i], us[indices[i]], recipz); - RwIm2DVertexSetV(&vert[i], vs[indices[i]], recipz); - } - nSpriteBufferIndex++; - if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) - FlushSpriteBuffer(); -} - -void -CSprite::Set6Vertices2D(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) -{ - float screenz, recipz; - float z = RwCameraGetNearClipPlane(Scene.camera); // not done by game - - screenz = m_f2DNearScreenZ; - recipz = m_fRecipNearClipPlane; - - RwIm2DVertexSetScreenX(&verts[0], r.left); - RwIm2DVertexSetScreenY(&verts[0], r.top); - RwIm2DVertexSetScreenZ(&verts[0], screenz); - RwIm2DVertexSetCameraZ(&verts[0], z); - RwIm2DVertexSetRecipCameraZ(&verts[0], recipz); - RwIm2DVertexSetIntRGBA(&verts[0], c2.r, c2.g, c2.b, c2.a); - RwIm2DVertexSetU(&verts[0], 0.0f, recipz); - RwIm2DVertexSetV(&verts[0], 0.0f, recipz); - - RwIm2DVertexSetScreenX(&verts[1], r.right); - RwIm2DVertexSetScreenY(&verts[1], r.top); - RwIm2DVertexSetScreenZ(&verts[1], screenz); - RwIm2DVertexSetCameraZ(&verts[1], z); - RwIm2DVertexSetRecipCameraZ(&verts[1], recipz); - RwIm2DVertexSetIntRGBA(&verts[1], c3.r, c3.g, c3.b, c3.a); - RwIm2DVertexSetU(&verts[1], 1.0f, recipz); - RwIm2DVertexSetV(&verts[1], 0.0f, recipz); - - RwIm2DVertexSetScreenX(&verts[2], r.right); - RwIm2DVertexSetScreenY(&verts[2], r.bottom); - RwIm2DVertexSetScreenZ(&verts[2], screenz); - RwIm2DVertexSetCameraZ(&verts[2], z); - RwIm2DVertexSetRecipCameraZ(&verts[2], recipz); - RwIm2DVertexSetIntRGBA(&verts[2], c1.r, c1.g, c1.b, c1.a); - RwIm2DVertexSetU(&verts[2], 1.0f, recipz); - RwIm2DVertexSetV(&verts[2], 1.0f, recipz); - - RwIm2DVertexSetScreenX(&verts[3], r.left); - RwIm2DVertexSetScreenY(&verts[3], r.bottom); - RwIm2DVertexSetScreenZ(&verts[3], screenz); - RwIm2DVertexSetCameraZ(&verts[3], z); - RwIm2DVertexSetRecipCameraZ(&verts[3], recipz); - RwIm2DVertexSetIntRGBA(&verts[3], c0.r, c0.g, c0.b, c0.a); - RwIm2DVertexSetU(&verts[3], 0.0f, recipz); - RwIm2DVertexSetV(&verts[3], 1.0f, recipz); - - RwIm2DVertexSetScreenX(&verts[4], r.left); - RwIm2DVertexSetScreenY(&verts[4], r.top); - RwIm2DVertexSetScreenZ(&verts[4], screenz); - RwIm2DVertexSetCameraZ(&verts[4], z); - RwIm2DVertexSetRecipCameraZ(&verts[4], recipz); - RwIm2DVertexSetIntRGBA(&verts[4], c2.r, c2.g, c2.b, c2.a); - RwIm2DVertexSetU(&verts[4], 0.0f, recipz); - RwIm2DVertexSetV(&verts[4], 0.0f, recipz); - - RwIm2DVertexSetScreenX(&verts[5], r.right); - RwIm2DVertexSetScreenY(&verts[5], r.bottom); - RwIm2DVertexSetScreenZ(&verts[5], screenz); - RwIm2DVertexSetCameraZ(&verts[5], z); - RwIm2DVertexSetRecipCameraZ(&verts[5], recipz); - RwIm2DVertexSetIntRGBA(&verts[5], c1.r, c1.g, c1.b, c1.a); - RwIm2DVertexSetU(&verts[5], 1.0f, recipz); - RwIm2DVertexSetV(&verts[5], 1.0f, recipz); -} - -void -CSprite::Set6Vertices2D(RwIm2DVertex *verts, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, - const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) -{ - float screenz, recipz; - float z = RwCameraGetNearClipPlane(Scene.camera); // not done by game - - screenz = m_f2DNearScreenZ; - recipz = m_fRecipNearClipPlane; - - RwIm2DVertexSetScreenX(&verts[0], x3); - RwIm2DVertexSetScreenY(&verts[0], y3); - RwIm2DVertexSetScreenZ(&verts[0], screenz); - RwIm2DVertexSetCameraZ(&verts[0], z); - RwIm2DVertexSetRecipCameraZ(&verts[0], recipz); - RwIm2DVertexSetIntRGBA(&verts[0], c2.r, c2.g, c2.b, c2.a); - RwIm2DVertexSetU(&verts[0], 0.0f, recipz); - RwIm2DVertexSetV(&verts[0], 0.0f, recipz); - - RwIm2DVertexSetScreenX(&verts[1], x4); - RwIm2DVertexSetScreenY(&verts[1], y4); - RwIm2DVertexSetScreenZ(&verts[1], screenz); - RwIm2DVertexSetCameraZ(&verts[1], z); - RwIm2DVertexSetRecipCameraZ(&verts[1], recipz); - RwIm2DVertexSetIntRGBA(&verts[1], c3.r, c3.g, c3.b, c3.a); - RwIm2DVertexSetU(&verts[1], 1.0f, recipz); - RwIm2DVertexSetV(&verts[1], 0.0f, recipz); - - RwIm2DVertexSetScreenX(&verts[2], x2); - RwIm2DVertexSetScreenY(&verts[2], y2); - RwIm2DVertexSetScreenZ(&verts[2], screenz); - RwIm2DVertexSetCameraZ(&verts[2], z); - RwIm2DVertexSetRecipCameraZ(&verts[2], recipz); - RwIm2DVertexSetIntRGBA(&verts[2], c1.r, c1.g, c1.b, c1.a); - RwIm2DVertexSetU(&verts[2], 1.0f, recipz); - RwIm2DVertexSetV(&verts[2], 1.0f, recipz); - - RwIm2DVertexSetScreenX(&verts[3], x1); - RwIm2DVertexSetScreenY(&verts[3], y1); - RwIm2DVertexSetScreenZ(&verts[3], screenz); - RwIm2DVertexSetCameraZ(&verts[3], z); - RwIm2DVertexSetRecipCameraZ(&verts[3], recipz); - RwIm2DVertexSetIntRGBA(&verts[3], c0.r, c0.g, c0.b, c0.a); - RwIm2DVertexSetU(&verts[3], 0.0f, recipz); - RwIm2DVertexSetV(&verts[3], 1.0f, recipz); - - RwIm2DVertexSetScreenX(&verts[4], x3); - RwIm2DVertexSetScreenY(&verts[4], y3); - RwIm2DVertexSetScreenZ(&verts[4], screenz); - RwIm2DVertexSetCameraZ(&verts[4], z); - RwIm2DVertexSetRecipCameraZ(&verts[4], recipz); - RwIm2DVertexSetIntRGBA(&verts[4], c2.r, c2.g, c2.b, c2.a); - RwIm2DVertexSetU(&verts[4], 0.0f, recipz); - RwIm2DVertexSetV(&verts[4], 0.0f, recipz); - - RwIm2DVertexSetScreenX(&verts[5], x2); - RwIm2DVertexSetScreenY(&verts[5], y2); - RwIm2DVertexSetScreenZ(&verts[5], screenz); - RwIm2DVertexSetCameraZ(&verts[5], z); - RwIm2DVertexSetRecipCameraZ(&verts[5], recipz); - RwIm2DVertexSetIntRGBA(&verts[5], c1.r, c1.g, c1.b, c1.a); - RwIm2DVertexSetU(&verts[5], 1.0f, recipz); - RwIm2DVertexSetV(&verts[5], 1.0f, recipz); -} - -void -CSprite::RenderBufferedOneXLUSprite2D(float x, float y, float w, float h, const RwRGBA &colour, int16 intens, uint8 alpha) -{ - m_bFlushSpriteBufferSwitchZTest = 1; - CRGBA col(intens * colour.red >> 8, intens * colour.green >> 8, intens * colour.blue >> 8, alpha); - CRect rect(x - w, y - h, x + h, y + h); - Set6Vertices2D(&SpriteBufferVerts[6 * nSpriteBufferIndex], rect, col, col, col, col); - nSpriteBufferIndex++; - if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) - FlushSpriteBuffer(); -} - -void -CSprite::RenderBufferedOneXLUSprite2D_Rotate_Dimension(float x, float y, float w, float h, const RwRGBA &colour, int16 intens, float rotation, uint8 alpha) -{ - m_bFlushSpriteBufferSwitchZTest = 1; - CRGBA col(intens * colour.red >> 8, intens * colour.green >> 8, intens * colour.blue >> 8, alpha); - float c = Cos(rotation); - float s = Sin(rotation); - - Set6Vertices2D(&SpriteBufferVerts[6 * nSpriteBufferIndex], - x + c*w - s*h, - y - c*h - s*w, - x + c*w + s*h, - y + c*h - s*w, - x - c*w - s*h, - y - c*h + s*w, - x - c*w + s*h, - y + c*h + s*w, - col, col, col, col); - nSpriteBufferIndex++; - if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) - FlushSpriteBuffer(); -} diff --git a/src/render/Sprite.h b/src/render/Sprite.h deleted file mode 100644 index fae6684e..00000000 --- a/src/render/Sprite.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -class CSprite -{ - static float m_f2DNearScreenZ; - static float m_f2DFarScreenZ; - static float m_fRecipNearClipPlane; - static int32 m_bFlushSpriteBufferSwitchZTest; -public: - static float GetNearScreenZ(void) { return m_f2DNearScreenZ; } - static float GetFarScreenZ(void) { return m_f2DFarScreenZ; } - - static float CalcHorizonCoors(void); - static bool CalcScreenCoors(const RwV3d &in, RwV3d *out, float *outw, float *outh, bool farclip); - static void InitSpriteBuffer(void); - static void InitSpriteBuffer2D(void); - static void FlushSpriteBuffer(void); - static void RenderOneXLUSprite(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, uint8 a); - static void RenderOneXLUSprite_Rotate_Aspect(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float roll, uint8 a); - static void RenderBufferedOneXLUSprite(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, uint8 a); - static void RenderBufferedOneXLUSprite_Rotate_Dimension(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float roll, uint8 a); - static void RenderBufferedOneXLUSprite_Rotate_Aspect(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float roll, uint8 a); - // cx/y is the direction in which the colour changes - static void RenderBufferedOneXLUSprite_Rotate_2Colours(float x, float y, float z, float w, float h, uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2, float cx, float cy, float recipz, float rotation, uint8 a); - static void Set6Vertices2D(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); - static void Set6Vertices2D(RwIm2DVertex *verts, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, - const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); - static void RenderBufferedOneXLUSprite2D(float x, float y, float w, float h, const RwRGBA &colour, int16 intens, uint8 alpha); - static void RenderBufferedOneXLUSprite2D_Rotate_Dimension(float x, float y, float w, float h, const RwRGBA &colour, int16 intens, float rotation, uint8 alpha); - -}; diff --git a/src/render/Sprite2d.cpp b/src/render/Sprite2d.cpp deleted file mode 100644 index 92f326f8..00000000 --- a/src/render/Sprite2d.cpp +++ /dev/null @@ -1,434 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "Draw.h" -#include "Camera.h" -#include "Sprite2d.h" -#include "Font.h" -#include "RenderBuffer.h" - -float CSprite2d::RecipNearClip; -float CSprite2d::NearScreenZ; -float CSprite2d::NearCamZ; -int CSprite2d::nextBufferVertex; -int CSprite2d::nextBufferIndex; -RwIm2DVertex CSprite2d::maVertices[8]; - -void -CSprite2d::SetRecipNearClip(void) -{ - // Used but empty in VC, instead they set in InitPerFrame. Isn't that great? -} - -void -CSprite2d::InitPerFrame(void) -{ - nextBufferVertex = 0; - nextBufferIndex = 0; - RecipNearClip = 1.0f / RwCameraGetNearClipPlane(Scene.camera); - NearScreenZ = RwIm2DGetNearScreenZ(); - // not original but you're supposed to set camera z too - // wrapping all this in FIX_BUGS is too ugly - NearCamZ = RwCameraGetNearClipPlane(Scene.camera); -} -void -CSprite2d::Delete(void) -{ - if(m_pTexture){ - RwTextureDestroy(m_pTexture); - m_pTexture = nil; - } -} - -void -CSprite2d::SetTexture(const char *name) -{ - Delete(); - if(name) - m_pTexture = RwTextureRead(name, nil); -} - -void -CSprite2d::SetTexture(const char *name, const char *mask) -{ - Delete(); - if(name) - m_pTexture = RwTextureRead(name, mask); -} - -void -CSprite2d::SetAddressing(RwTextureAddressMode addr) -{ - if(m_pTexture) - RwTextureSetAddressing(m_pTexture, addr); -} - -void -CSprite2d::SetRenderState(void) -{ - if(m_pTexture) - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(m_pTexture)); - else - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); -} - -void -CSprite2d::Draw(float x, float y, float w, float h, const CRGBA &col) -{ - SetVertices(CRect(x, y, x + w, y + h), col, col, col, col); - SetRenderState(); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); -} - -void -CSprite2d::Draw(const CRect &rect, const CRGBA &col) -{ - SetVertices(rect, col, col, col, col); - SetRenderState(); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); -} - -void -CSprite2d::Draw(const CRect &rect, const CRGBA &col, - float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2) -{ - SetVertices(rect, col, col, col, col, u0, v0, u1, v1, u3, v3, u2, v2); - SetRenderState(); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); -} - -void -CSprite2d::Draw(const CRect &rect, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) -{ - SetVertices(rect, c0, c1, c2, c3); - SetRenderState(); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); -} - -void -CSprite2d::Draw(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &col) -{ - SetVertices(x1, y1, x2, y2, x3, y3, x4, y4, col, col, col, col); - SetRenderState(); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); -} - -// Arguments: -// 2---3 -// | | -// 0---1 -void -CSprite2d::SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) -{ - float offset = 1.0f/1024.0f; - - // This is what we draw: - // 0---1 - // | / | - // 3---2 - RwIm2DVertexSetScreenX(&maVertices[0], r.left); - RwIm2DVertexSetScreenY(&maVertices[0], r.top); - RwIm2DVertexSetScreenZ(&maVertices[0], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[0], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[0], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[0], c2.r, c2.g, c2.b, c2.a); - RwIm2DVertexSetU(&maVertices[0], 0.0f+offset, RecipNearClip); - RwIm2DVertexSetV(&maVertices[0], 0.0f+offset, RecipNearClip); - - RwIm2DVertexSetScreenX(&maVertices[1], r.right); - RwIm2DVertexSetScreenY(&maVertices[1], r.top); - RwIm2DVertexSetScreenZ(&maVertices[1], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[1], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[1], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[1], c3.r, c3.g, c3.b, c3.a); - RwIm2DVertexSetU(&maVertices[1], 1.0f+offset, RecipNearClip); - RwIm2DVertexSetV(&maVertices[1], 0.0f+offset, RecipNearClip); - - RwIm2DVertexSetScreenX(&maVertices[2], r.right); - RwIm2DVertexSetScreenY(&maVertices[2], r.bottom); - RwIm2DVertexSetScreenZ(&maVertices[2], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[2], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[2], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[2], c1.r, c1.g, c1.b, c1.a); - RwIm2DVertexSetU(&maVertices[2], 1.0f+offset, RecipNearClip); - RwIm2DVertexSetV(&maVertices[2], 1.0f+offset, RecipNearClip); - - RwIm2DVertexSetScreenX(&maVertices[3], r.left); - RwIm2DVertexSetScreenY(&maVertices[3], r.bottom); - RwIm2DVertexSetScreenZ(&maVertices[3], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[3], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[3], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[3], c0.r, c0.g, c0.b, c0.a); - RwIm2DVertexSetU(&maVertices[3], 0.0f+offset, RecipNearClip); - RwIm2DVertexSetV(&maVertices[3], 1.0f+offset, RecipNearClip); -} - -void -CSprite2d::SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3, - float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2) -{ - // This is what we draw: - // 0---1 - // | / | - // 3---2 - RwIm2DVertexSetScreenX(&maVertices[0], r.left); - RwIm2DVertexSetScreenY(&maVertices[0], r.top); - RwIm2DVertexSetScreenZ(&maVertices[0], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[0], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[0], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[0], c2.r, c2.g, c2.b, c2.a); - RwIm2DVertexSetU(&maVertices[0], u0, RecipNearClip); - RwIm2DVertexSetV(&maVertices[0], v0, RecipNearClip); - - RwIm2DVertexSetScreenX(&maVertices[1], r.right); - RwIm2DVertexSetScreenY(&maVertices[1], r.top); - RwIm2DVertexSetScreenZ(&maVertices[1], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[1], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[1], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[1], c3.r, c3.g, c3.b, c3.a); - RwIm2DVertexSetU(&maVertices[1], u1, RecipNearClip); - RwIm2DVertexSetV(&maVertices[1], v1, RecipNearClip); - - RwIm2DVertexSetScreenX(&maVertices[2], r.right); - RwIm2DVertexSetScreenY(&maVertices[2], r.bottom); - RwIm2DVertexSetScreenZ(&maVertices[2], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[2], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[2], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[2], c1.r, c1.g, c1.b, c1.a); - RwIm2DVertexSetU(&maVertices[2], u2, RecipNearClip); - RwIm2DVertexSetV(&maVertices[2], v2, RecipNearClip); - - RwIm2DVertexSetScreenX(&maVertices[3], r.left); - RwIm2DVertexSetScreenY(&maVertices[3], r.bottom); - RwIm2DVertexSetScreenZ(&maVertices[3], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[3], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[3], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[3], c0.r, c0.g, c0.b, c0.a); - RwIm2DVertexSetU(&maVertices[3], u3, RecipNearClip); - RwIm2DVertexSetV(&maVertices[3], v3, RecipNearClip); -} - -void -CSprite2d::SetVertices(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, - const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) -{ - RwIm2DVertexSetScreenX(&maVertices[0], x3); - RwIm2DVertexSetScreenY(&maVertices[0], y3); - RwIm2DVertexSetScreenZ(&maVertices[0], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[0], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[0], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[0], c2.r, c2.g, c2.b, c2.a); - RwIm2DVertexSetU(&maVertices[0], 0.0f, RecipNearClip); - RwIm2DVertexSetV(&maVertices[0], 0.0f, RecipNearClip); - - RwIm2DVertexSetScreenX(&maVertices[1], x4); - RwIm2DVertexSetScreenY(&maVertices[1], y4); - RwIm2DVertexSetScreenZ(&maVertices[1], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[1], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[1], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[1], c3.r, c3.g, c3.b, c3.a); - RwIm2DVertexSetU(&maVertices[1], 1.0f, RecipNearClip); - RwIm2DVertexSetV(&maVertices[1], 0.0f, RecipNearClip); - - RwIm2DVertexSetScreenX(&maVertices[2], x2); - RwIm2DVertexSetScreenY(&maVertices[2], y2); - RwIm2DVertexSetScreenZ(&maVertices[2], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[2], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[2], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[2], c1.r, c1.g, c1.b, c1.a); - RwIm2DVertexSetU(&maVertices[2], 1.0f, RecipNearClip); - RwIm2DVertexSetV(&maVertices[2], 1.0f, RecipNearClip); - - RwIm2DVertexSetScreenX(&maVertices[3], x1); - RwIm2DVertexSetScreenY(&maVertices[3], y1); - RwIm2DVertexSetScreenZ(&maVertices[3], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[3], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[3], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[3], c0.r, c0.g, c0.b, c0.a); - RwIm2DVertexSetU(&maVertices[3], 0.0f, RecipNearClip); - RwIm2DVertexSetV(&maVertices[3], 1.0f, RecipNearClip); -} - -void -CSprite2d::SetVertices(int n, float *positions, float *uvs, const CRGBA &col) -{ - int i; - - for(i = 0; i < n; i++){ - RwIm2DVertexSetScreenX(&maVertices[i], positions[i*2 + 0]); - RwIm2DVertexSetScreenY(&maVertices[i], positions[i*2 + 1]); - RwIm2DVertexSetScreenZ(&maVertices[i], NearScreenZ + 0.0001f); - RwIm2DVertexSetCameraZ(&maVertices[i], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[i], RecipNearClip); - RwIm2DVertexSetIntRGBA(&maVertices[i], col.r, col.g, col.b, col.a); - RwIm2DVertexSetU(&maVertices[i], uvs[i*2 + 0], RecipNearClip); - RwIm2DVertexSetV(&maVertices[i], uvs[i*2 + 1], RecipNearClip); - } -} - -void -CSprite2d::SetMaskVertices(int n, float *positions) -{ - int i; - - for(i = 0; i < n; i++){ - RwIm2DVertexSetScreenX(&maVertices[i], positions[i*2 + 0]); - RwIm2DVertexSetScreenY(&maVertices[i], positions[i*2 + 1]); - RwIm2DVertexSetScreenZ(&maVertices[i], NearScreenZ); - RwIm2DVertexSetCameraZ(&maVertices[i], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&maVertices[i], RecipNearClip); -#if !defined(GTA_PS2_STUFF) && defined(RWLIBS) - RwIm2DVertexSetIntRGBA(&maVertices[i], 0, 0, 0, 0); -#else - RwIm2DVertexSetIntRGBA(&maVertices[i], 255, 255, 255, 255); -#endif - } -} - -void -CSprite2d::SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3, - float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2) -{ - RwIm2DVertexSetScreenX(&verts[0], r.left); - RwIm2DVertexSetScreenY(&verts[0], r.top); - RwIm2DVertexSetScreenZ(&verts[0], NearScreenZ); - RwIm2DVertexSetCameraZ(&verts[0], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&verts[0], RecipNearClip); - RwIm2DVertexSetIntRGBA(&verts[0], c2.r, c2.g, c2.b, c2.a); - RwIm2DVertexSetU(&verts[0], u0, RecipNearClip); - RwIm2DVertexSetV(&verts[0], v0, RecipNearClip); - - RwIm2DVertexSetScreenX(&verts[1], r.right); - RwIm2DVertexSetScreenY(&verts[1], r.top); - RwIm2DVertexSetScreenZ(&verts[1], NearScreenZ); - RwIm2DVertexSetCameraZ(&verts[1], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&verts[1], RecipNearClip); - RwIm2DVertexSetIntRGBA(&verts[1], c3.r, c3.g, c3.b, c3.a); - RwIm2DVertexSetU(&verts[1], u1, RecipNearClip); - RwIm2DVertexSetV(&verts[1], v1, RecipNearClip); - - RwIm2DVertexSetScreenX(&verts[2], r.right); - RwIm2DVertexSetScreenY(&verts[2], r.bottom); - RwIm2DVertexSetScreenZ(&verts[2], NearScreenZ); - RwIm2DVertexSetCameraZ(&verts[2], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&verts[2], RecipNearClip); - RwIm2DVertexSetIntRGBA(&verts[2], c1.r, c1.g, c1.b, c1.a); - RwIm2DVertexSetU(&verts[2], u2, RecipNearClip); - RwIm2DVertexSetV(&verts[2], v2, RecipNearClip); - - RwIm2DVertexSetScreenX(&verts[3], r.left); - RwIm2DVertexSetScreenY(&verts[3], r.bottom); - RwIm2DVertexSetScreenZ(&verts[3], NearScreenZ); - RwIm2DVertexSetCameraZ(&verts[3], NearCamZ); - RwIm2DVertexSetRecipCameraZ(&verts[3], RecipNearClip); - RwIm2DVertexSetIntRGBA(&verts[3], c0.r, c0.g, c0.b, c0.a); - RwIm2DVertexSetU(&verts[3], u3, RecipNearClip); - RwIm2DVertexSetV(&verts[3], v3, RecipNearClip); -} - -void -CSprite2d::DrawRect(const CRect &r, const CRGBA &col) -{ - SetVertices(r, col, col, col, col); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEFLAT); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)(col.a != 255)); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, maVertices, 4); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD); -} - -void -CSprite2d::DrawRect(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) -{ - SetVertices(r, c0, c1, c2, c3); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, maVertices, 4); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); -} - -void -CSprite2d::DrawRectXLU(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) -{ - SetVertices(r, c0, c1, c2, c3); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); -} - -void -CSprite2d::DrawAnyRect(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, - const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) -{ - SetVertices(x1, y1, x2, y2, x3, y3, x4, y4, c0, c1, c2, c3); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); - RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)(c0.alpha != 255 || c1.alpha != 255 || c2.alpha != 255 || c3.alpha != 255)); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD); -} - -void CSprite2d::Draw2DPolygon(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &color) -{ - SetVertices(x1, y1, x2, y2, x3, y3, x4, y4, color, color, color, color); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, 0); - RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEFLAT); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)(color.a != 255)); - RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD); -} - -void -CSprite2d::AddToBuffer(const CRect &r, const CRGBA &c, float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2) -{ - SetVertices(&TempVertexBuffer.im2d[nextBufferVertex], r, c, c, c, c, u0, v0, u1, v1, u3, v3, u2, v2); - RwImVertexIndex *pIndexList = &TempBufferRenderIndexList[nextBufferIndex]; - pIndexList[0] = nextBufferVertex; - pIndexList[1] = nextBufferVertex + 1; - pIndexList[2] = nextBufferVertex + 2; - pIndexList[3] = nextBufferVertex + 3; - pIndexList[4] = nextBufferVertex; - pIndexList[5] = nextBufferVertex + 2; - nextBufferIndex += 6; - nextBufferVertex += 4; - if (IsVertexBufferFull()) - RenderVertexBuffer(); -} - -bool -CSprite2d::IsVertexBufferFull() -{ - return (nextBufferVertex > TEMPBUFFERVERTSIZE-128-4 || nextBufferIndex > ARRAY_SIZE(TempBufferRenderIndexList)-6); -} - -void -CSprite2d::RenderVertexBuffer() -{ - if (nextBufferVertex > 0) { - RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); - RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempVertexBuffer.im2d, nextBufferVertex, TempBufferRenderIndexList, nextBufferIndex); - nextBufferVertex = 0; - nextBufferIndex = 0; - } -} \ No newline at end of file diff --git a/src/render/Sprite2d.h b/src/render/Sprite2d.h deleted file mode 100644 index 5abd8d71..00000000 --- a/src/render/Sprite2d.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -class CSprite2d -{ - static float RecipNearClip; - static float NearScreenZ; - static float NearCamZ; // not original - static int nextBufferVertex; - static int nextBufferIndex; - static RwIm2DVertex maVertices[8]; -public: - RwTexture *m_pTexture; - - static void SetRecipNearClip(void); - static void InitPerFrame(void); - - CSprite2d(void) : m_pTexture(nil) {}; - ~CSprite2d(void) { Delete(); }; - void Delete(void); - void SetRenderState(void); - void SetTexture(const char *name); - void SetTexture(const char *name, const char *mask); - void SetAddressing(RwTextureAddressMode addr); - void Draw(float x, float y, float w, float h, const CRGBA &col); - void Draw(const CRect &rect, const CRGBA &col); - void Draw(const CRect &rect, const CRGBA &col, - float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2); - void Draw(const CRect &rect, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); - void Draw(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &col); - - static void SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); - static void SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3, - float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2); - static void SetVertices(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, - const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); - static void SetVertices(int n, float *positions, float *uvs, const CRGBA &col); - static void SetMaskVertices(int n, float *positions); - static void SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3, - float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2); - - static void DrawRect(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); - static void DrawRect(const CRect &r, const CRGBA &col); - static void DrawRectXLU(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); - static void DrawAnyRect(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, - const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); - - static void Draw2DPolygon(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &color); - - static RwIm2DVertex* GetVertices() { return maVertices; }; - - static bool IsVertexBufferFull(); - static void AddToBuffer(const CRect &a1, const CRGBA &a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10); - static void RenderVertexBuffer(); -}; diff --git a/src/render/TexList.cpp b/src/render/TexList.cpp deleted file mode 100644 index 1689837f..00000000 --- a/src/render/TexList.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "common.h" -#include "TexList.h" -#include "rtbmp.h" -#include "FileMgr.h" - -bool CTexList::ms_nTexUsed[MAX_TEXUSED]; - -void -CTexList::Initialise() -{} - -void -CTexList::Shutdown() -{} - -RwTexture * -CTexList::SetTexture(int32 slot, char *name) -{ - return nil; -} - -int32 -CTexList::GetFirstFreeTexture() -{ - for (int32 i = 0; i < MAX_TEXUSED; i++) - if (!ms_nTexUsed[i]) - return i; - return -1; -} - -RwTexture * -CTexList::LoadFileNameTexture(char *name) -{ - return SetTexture(GetFirstFreeTexture(), name); -} - -void -CTexList::LoadGlobalTextureList() -{ - CFileMgr::SetDir("TEXTURES"); -} \ No newline at end of file diff --git a/src/render/TexList.h b/src/render/TexList.h deleted file mode 100644 index 7e042211..00000000 --- a/src/render/TexList.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -class CTexList -{ - enum { MAX_TEXUSED = 400, }; - static bool ms_nTexUsed[MAX_TEXUSED]; -public: - static void Initialise(); - static void Shutdown(); - static RwTexture *SetTexture(int32 slot, char *name); - static int32 GetFirstFreeTexture(); - static RwTexture *LoadFileNameTexture(char *name); - static void LoadGlobalTextureList(); -}; \ No newline at end of file diff --git a/src/render/Timecycle.cpp b/src/render/Timecycle.cpp deleted file mode 100644 index 95d9fe3c..00000000 --- a/src/render/Timecycle.cpp +++ /dev/null @@ -1,526 +0,0 @@ -#include "common.h" - -#include "main.h" -#include "Clock.h" -#include "Weather.h" -#include "Camera.h" -#include "Shadows.h" -#include "ZoneCull.h" -#include "CutsceneMgr.h" -#include "FileMgr.h" -#include "Timecycle.h" - -uint8 CTimeCycle::m_nAmbientRed[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nAmbientGreen[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nAmbientBlue[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nAmbientRed_Obj[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nAmbientGreen_Obj[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nAmbientBlue_Obj[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nAmbientRed_Bl[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nAmbientGreen_Bl[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nAmbientBlue_Bl[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nAmbientRed_Obj_Bl[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nAmbientGreen_Obj_Bl[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nAmbientBlue_Obj_Bl[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nDirectionalRed[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nDirectionalGreen[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nDirectionalBlue[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSkyTopRed[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSkyTopGreen[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSkyTopBlue[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSkyBottomRed[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSkyBottomGreen[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSkyBottomBlue[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSunCoreRed[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSunCoreGreen[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSunCoreBlue[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSunCoronaRed[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSunCoronaGreen[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nSunCoronaBlue[NUMHOURS][NUMWEATHERS]; -int8 CTimeCycle::m_fSunSize[NUMHOURS][NUMWEATHERS]; -int8 CTimeCycle::m_fSpriteSize[NUMHOURS][NUMWEATHERS]; -int8 CTimeCycle::m_fSpriteBrightness[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nShadowStrength[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nLightShadowStrength[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nPoleShadowStrength[NUMHOURS][NUMWEATHERS]; -int16 CTimeCycle::m_fFogStart[NUMHOURS][NUMWEATHERS]; -int16 CTimeCycle::m_fFarClip[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_fLightsOnGroundBrightness[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nLowCloudsRed[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nLowCloudsGreen[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nLowCloudsBlue[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nFluffyCloudsTopRed[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nFluffyCloudsTopGreen[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nFluffyCloudsTopBlue[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nFluffyCloudsBottomRed[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nFluffyCloudsBottomGreen[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_nFluffyCloudsBottomBlue[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_fBlurRed[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_fBlurGreen[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_fBlurBlue[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_fWaterRed[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_fWaterGreen[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_fWaterBlue[NUMHOURS][NUMWEATHERS]; -uint8 CTimeCycle::m_fWaterAlpha[NUMHOURS][NUMWEATHERS]; - - -float CTimeCycle::m_fCurrentAmbientRed; -float CTimeCycle::m_fCurrentAmbientGreen; -float CTimeCycle::m_fCurrentAmbientBlue; -float CTimeCycle::m_fCurrentAmbientRed_Obj; -float CTimeCycle::m_fCurrentAmbientGreen_Obj; -float CTimeCycle::m_fCurrentAmbientBlue_Obj; -float CTimeCycle::m_fCurrentAmbientRed_Bl; -float CTimeCycle::m_fCurrentAmbientGreen_Bl; -float CTimeCycle::m_fCurrentAmbientBlue_Bl; -float CTimeCycle::m_fCurrentAmbientRed_Obj_Bl; -float CTimeCycle::m_fCurrentAmbientGreen_Obj_Bl; -float CTimeCycle::m_fCurrentAmbientBlue_Obj_Bl; -float CTimeCycle::m_fCurrentDirectionalRed; -float CTimeCycle::m_fCurrentDirectionalGreen; -float CTimeCycle::m_fCurrentDirectionalBlue; -int32 CTimeCycle::m_nCurrentSkyTopRed; -int32 CTimeCycle::m_nCurrentSkyTopGreen; -int32 CTimeCycle::m_nCurrentSkyTopBlue; -int32 CTimeCycle::m_nCurrentSkyBottomRed; -int32 CTimeCycle::m_nCurrentSkyBottomGreen; -int32 CTimeCycle::m_nCurrentSkyBottomBlue; -int32 CTimeCycle::m_nCurrentSunCoreRed; -int32 CTimeCycle::m_nCurrentSunCoreGreen; -int32 CTimeCycle::m_nCurrentSunCoreBlue; -int32 CTimeCycle::m_nCurrentSunCoronaRed; -int32 CTimeCycle::m_nCurrentSunCoronaGreen; -int32 CTimeCycle::m_nCurrentSunCoronaBlue; -float CTimeCycle::m_fCurrentSunSize; -float CTimeCycle::m_fCurrentSpriteSize; -float CTimeCycle::m_fCurrentSpriteBrightness; -int32 CTimeCycle::m_nCurrentShadowStrength; -int32 CTimeCycle::m_nCurrentLightShadowStrength; -int32 CTimeCycle::m_nCurrentPoleShadowStrength; -float CTimeCycle::m_fCurrentFogStart; -float CTimeCycle::m_fCurrentFarClip; -float CTimeCycle::m_fCurrentLightsOnGroundBrightness; -int32 CTimeCycle::m_nCurrentLowCloudsRed; -int32 CTimeCycle::m_nCurrentLowCloudsGreen; -int32 CTimeCycle::m_nCurrentLowCloudsBlue; -int32 CTimeCycle::m_nCurrentFluffyCloudsTopRed; -int32 CTimeCycle::m_nCurrentFluffyCloudsTopGreen; -int32 CTimeCycle::m_nCurrentFluffyCloudsTopBlue; -int32 CTimeCycle::m_nCurrentFluffyCloudsBottomRed; -int32 CTimeCycle::m_nCurrentFluffyCloudsBottomGreen; -int32 CTimeCycle::m_nCurrentFluffyCloudsBottomBlue; -float CTimeCycle::m_fCurrentBlurRed; -float CTimeCycle::m_fCurrentBlurGreen; -float CTimeCycle::m_fCurrentBlurBlue; -float CTimeCycle::m_fCurrentWaterRed; -float CTimeCycle::m_fCurrentWaterGreen; -float CTimeCycle::m_fCurrentWaterBlue; -float CTimeCycle::m_fCurrentWaterAlpha; -int32 CTimeCycle::m_nCurrentFogColourRed; -int32 CTimeCycle::m_nCurrentFogColourGreen; -int32 CTimeCycle::m_nCurrentFogColourBlue; - -int32 CTimeCycle::m_FogReduction; -int32 CTimeCycle::m_bExtraColourOn; -int32 CTimeCycle::m_ExtraColour; -float CTimeCycle::m_ExtraColourInter; - -int32 CTimeCycle::m_CurrentStoredValue; -CVector CTimeCycle::m_VectorToSun[16]; -float CTimeCycle::m_fShadowFrontX[16]; -float CTimeCycle::m_fShadowFrontY[16]; -float CTimeCycle::m_fShadowSideX[16]; -float CTimeCycle::m_fShadowSideY[16]; -float CTimeCycle::m_fShadowDisplacementX[16]; -float CTimeCycle::m_fShadowDisplacementY[16]; - -void -CTimeCycle::Initialise(void) -{ - int w, h; - int li, bi; - char line[1040]; - - int ambR, ambG, ambB; - int ambobjR, ambobjG, ambobjB; - int ambblR, ambblG, ambblB; - int ambobjblR, ambobjblG, ambobjblB; - int dirR, dirG, dirB; - int skyTopR, skyTopG, skyTopB; - int skyBotR, skyBotG, skyBotB; - int sunCoreR, sunCoreG, sunCoreB; - int sunCoronaR, sunCoronaG, sunCoronaB; - float sunSz, sprSz, sprBght; - int shad, lightShad, poleShad; - float farClp, fogSt, lightGnd; - int cloudR, cloudG, cloudB; - int fluffyTopR, fluffyTopG, fluffyTopB; - int fluffyBotR, fluffyBotG, fluffyBotB; - float blurR, blurG, blurB; - float waterR, waterG, waterB, waterA; - - debug("Intialising CTimeCycle...\n"); - - CFileMgr::SetDir("DATA"); - CFileMgr::LoadFile("TIMECYC.DAT", work_buff, sizeof(work_buff), "rb"); - CFileMgr::SetDir(""); - - line[0] = '\0'; - bi = 0; - for(w = 0; w < NUMWEATHERS; w++) - for(h = 0; h < NUMHOURS; h++){ - li = 0; - while(work_buff[bi] == '/' || work_buff[bi] == '\n' || - work_buff[bi] == '\0' || work_buff[bi] == ' ' || work_buff[bi] == '\r'){ - while(work_buff[bi] != '\n' && work_buff[bi] != '\0' && work_buff[bi] != '\r') - bi++; - bi++; - } - while(work_buff[bi] != '\n' -#ifdef FIX_BUGS - && work_buff[bi] != '\0' -#endif - ) - line[li++] = work_buff[bi++]; - line[li] = '\0'; - bi++; - - sscanf(line, "%d %d %d %d %d %d %d %d %d %d %d %d " - "%d %d %d %d %d %d %d %d %d " - "%d %d %d %d %d %d %f %f %f %d %d %d %f %f %f " - "%d %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f", - &ambR, &ambG, &ambB, - &ambobjR, &ambobjG, &ambobjB, - &ambblR, &ambblG, &ambblB, - &ambobjblR, &ambobjblG, &ambobjblB, - &dirR, &dirG, &dirB, - &skyTopR, &skyTopG, &skyTopB, - &skyBotR, &skyBotG, &skyBotB, - &sunCoreR, &sunCoreG, &sunCoreB, - &sunCoronaR, &sunCoronaG, &sunCoronaB, - &sunSz, &sprSz, &sprBght, - &shad, &lightShad, &poleShad, - &farClp, &fogSt, &lightGnd, - &cloudR, &cloudG, &cloudB, - &fluffyTopR, &fluffyTopG, &fluffyTopB, - &fluffyBotR, &fluffyBotG, &fluffyBotB, - &blurR, &blurG, &blurB, - &waterR, &waterG, &waterB, &waterA); - - m_nAmbientRed[h][w] = ambR; - m_nAmbientGreen[h][w] = ambG; - m_nAmbientBlue[h][w] = ambB; - m_nAmbientRed_Obj[h][w] = ambobjR; - m_nAmbientGreen_Obj[h][w] = ambobjG; - m_nAmbientBlue_Obj[h][w] = ambobjB; - m_nAmbientRed_Bl[h][w] = ambblR; - m_nAmbientGreen_Bl[h][w] = ambblG; - m_nAmbientBlue_Bl[h][w] = ambblB; - m_nAmbientRed_Obj_Bl[h][w] = ambobjblR; - m_nAmbientGreen_Obj_Bl[h][w] = ambobjblG; - m_nAmbientBlue_Obj_Bl[h][w] = ambobjblB; - m_nDirectionalRed[h][w] = dirR; - m_nDirectionalGreen[h][w] = dirG; - m_nDirectionalBlue[h][w] = dirB; - m_nSkyTopRed[h][w] = skyTopR; - m_nSkyTopGreen[h][w] = skyTopG; - m_nSkyTopBlue[h][w] = skyTopB; - m_nSkyBottomRed[h][w] = skyBotR; - m_nSkyBottomGreen[h][w] = skyBotG; - m_nSkyBottomBlue[h][w] = skyBotB; - m_nSunCoreRed[h][w] = sunCoreR; - m_nSunCoreGreen[h][w] = sunCoreG; - m_nSunCoreBlue[h][w] = sunCoreB; - m_nSunCoronaRed[h][w] = sunCoronaR; - m_nSunCoronaGreen[h][w] = sunCoronaG; - m_nSunCoronaBlue[h][w] = sunCoronaB; - m_fSunSize[h][w] = sunSz * 10.0f; - m_fSpriteSize[h][w] = sprSz * 10.0f; - m_fSpriteBrightness[h][w] = sprBght * 10.0f; - m_nShadowStrength[h][w] = shad; - m_nLightShadowStrength[h][w] = lightShad; - m_nPoleShadowStrength[h][w] = poleShad; - m_fFarClip[h][w] = farClp; - m_fFogStart[h][w] = fogSt; - m_fLightsOnGroundBrightness[h][w] = lightGnd * 10.0f; - m_nLowCloudsRed[h][w] = cloudR; - m_nLowCloudsGreen[h][w] = cloudG; - m_nLowCloudsBlue[h][w] = cloudB; - m_nFluffyCloudsTopRed[h][w] = fluffyTopR; - m_nFluffyCloudsTopGreen[h][w] = fluffyTopG; - m_nFluffyCloudsTopBlue[h][w] = fluffyTopB; - m_nFluffyCloudsBottomRed[h][w] = fluffyBotR; - m_nFluffyCloudsBottomGreen[h][w] = fluffyBotG; - m_nFluffyCloudsBottomBlue[h][w] = fluffyBotB; - m_fBlurRed[h][w] = blurR; - m_fBlurGreen[h][w] = blurG; - m_fBlurBlue[h][w] = blurB; - m_fWaterRed[h][w] = waterR; - m_fWaterGreen[h][w] = waterG; - m_fWaterBlue[h][w] = waterB; - m_fWaterAlpha[h][w] = waterA; - } - - m_FogReduction = 0; - - debug("CTimeCycle ready\n"); -} - -static float interp_c0, interp_c1, interp_c2, interp_c3; - -float CTimeCycle::Interpolate(int8 *a, int8 *b) -{ - return a[CWeather::OldWeatherType] * interp_c0 + - b[CWeather::OldWeatherType] * interp_c1 + - a[CWeather::NewWeatherType] * interp_c2 + - b[CWeather::NewWeatherType] * interp_c3; -} - -float CTimeCycle::Interpolate(uint8 *a, uint8 *b) -{ - return a[CWeather::OldWeatherType] * interp_c0 + - b[CWeather::OldWeatherType] * interp_c1 + - a[CWeather::NewWeatherType] * interp_c2 + - b[CWeather::NewWeatherType] * interp_c3; -} - -float CTimeCycle::Interpolate(int16 *a, int16 *b) -{ - return a[CWeather::OldWeatherType] * interp_c0 + - b[CWeather::OldWeatherType] * interp_c1 + - a[CWeather::NewWeatherType] * interp_c2 + - b[CWeather::NewWeatherType] * interp_c3; -} - -void -CTimeCycle::StartExtraColour(int32 c, bool fade) -{ - m_bExtraColourOn = true; - m_ExtraColour = c; - if(fade) - m_ExtraColourInter = 0.0f; - else - m_ExtraColourInter = 1.0f; -} - -void -CTimeCycle::StopExtraColour(bool fade) -{ - m_bExtraColourOn = false; - if(!fade) - m_ExtraColourInter = 0.0f; -} - -void -CTimeCycle::Update(void) -{ - int h1 = CClock::GetHours(); - int h2 = (h1+1)%24; - int w1 = CWeather::OldWeatherType; - int w2 = CWeather::NewWeatherType; - float timeInterp = (CClock::GetMinutes() + CClock::GetSeconds()/60.0f)/60.0f; - // coefficients for a bilinear interpolation - interp_c0 = (1.0f-timeInterp) * (1.0f-CWeather::InterpolationValue); - interp_c1 = timeInterp * (1.0f-CWeather::InterpolationValue); - interp_c2 = (1.0f-timeInterp) * CWeather::InterpolationValue; - interp_c3 = timeInterp * CWeather::InterpolationValue; - -#define INTERP(v) Interpolate(v[h1], v[h2]) - - m_nCurrentSkyTopRed = INTERP(m_nSkyTopRed); - m_nCurrentSkyTopGreen = INTERP(m_nSkyTopGreen); - m_nCurrentSkyTopBlue = INTERP(m_nSkyTopBlue); - - m_nCurrentSkyBottomRed = INTERP(m_nSkyBottomRed); - m_nCurrentSkyBottomGreen = INTERP(m_nSkyBottomGreen); - m_nCurrentSkyBottomBlue = INTERP(m_nSkyBottomBlue); - - m_fCurrentAmbientRed = INTERP(m_nAmbientRed); - m_fCurrentAmbientGreen = INTERP(m_nAmbientGreen); - m_fCurrentAmbientBlue = INTERP(m_nAmbientBlue); - - m_fCurrentAmbientRed_Obj = INTERP(m_nAmbientRed_Obj); - m_fCurrentAmbientGreen_Obj = INTERP(m_nAmbientGreen_Obj); - m_fCurrentAmbientBlue_Obj = INTERP(m_nAmbientBlue_Obj); - - m_fCurrentAmbientRed_Bl = INTERP(m_nAmbientRed_Bl); - m_fCurrentAmbientGreen_Bl = INTERP(m_nAmbientGreen_Bl); - m_fCurrentAmbientBlue_Bl = INTERP(m_nAmbientBlue_Bl); - - m_fCurrentAmbientRed_Obj_Bl = INTERP(m_nAmbientRed_Obj_Bl); - m_fCurrentAmbientGreen_Obj_Bl = INTERP(m_nAmbientGreen_Obj_Bl); - m_fCurrentAmbientBlue_Obj_Bl = INTERP(m_nAmbientBlue_Obj_Bl); - - m_fCurrentDirectionalRed = INTERP(m_nDirectionalRed); - m_fCurrentDirectionalGreen = INTERP(m_nDirectionalGreen); - m_fCurrentDirectionalBlue = INTERP(m_nDirectionalBlue); - - m_nCurrentSunCoreRed = INTERP(m_nSunCoreRed); - m_nCurrentSunCoreGreen = INTERP(m_nSunCoreGreen); - m_nCurrentSunCoreBlue = INTERP(m_nSunCoreBlue); - - m_nCurrentSunCoronaRed = INTERP(m_nSunCoronaRed); - m_nCurrentSunCoronaGreen = INTERP(m_nSunCoronaGreen); - m_nCurrentSunCoronaBlue = INTERP(m_nSunCoronaBlue); - - m_fCurrentSunSize = INTERP(m_fSunSize)/10.0f; - m_fCurrentSpriteSize = INTERP(m_fSpriteSize)/10.0f; - m_fCurrentSpriteBrightness = INTERP(m_fSpriteBrightness)/10.0f; - m_nCurrentShadowStrength = INTERP(m_nShadowStrength); - m_nCurrentLightShadowStrength = INTERP(m_nLightShadowStrength); - m_nCurrentPoleShadowStrength = INTERP(m_nPoleShadowStrength); - m_fCurrentFarClip = INTERP(m_fFarClip); - m_fCurrentFogStart = INTERP(m_fFogStart); - m_fCurrentLightsOnGroundBrightness = INTERP(m_fLightsOnGroundBrightness)/10.0f; - - m_nCurrentLowCloudsRed = INTERP(m_nLowCloudsRed); - m_nCurrentLowCloudsGreen = INTERP(m_nLowCloudsGreen); - m_nCurrentLowCloudsBlue = INTERP(m_nLowCloudsBlue); - - m_nCurrentFluffyCloudsTopRed = INTERP(m_nFluffyCloudsTopRed); - m_nCurrentFluffyCloudsTopGreen = INTERP(m_nFluffyCloudsTopGreen); - m_nCurrentFluffyCloudsTopBlue = INTERP(m_nFluffyCloudsTopBlue); - - m_nCurrentFluffyCloudsBottomRed = INTERP(m_nFluffyCloudsBottomRed); - m_nCurrentFluffyCloudsBottomGreen = INTERP(m_nFluffyCloudsBottomGreen); - m_nCurrentFluffyCloudsBottomBlue = INTERP(m_nFluffyCloudsBottomBlue); - - m_fCurrentBlurRed = INTERP(m_fBlurRed); - m_fCurrentBlurGreen = INTERP(m_fBlurGreen); - m_fCurrentBlurBlue = INTERP(m_fBlurBlue); - - m_fCurrentWaterRed = INTERP(m_fWaterRed); - m_fCurrentWaterGreen = INTERP(m_fWaterGreen); - m_fCurrentWaterBlue = INTERP(m_fWaterBlue); - m_fCurrentWaterAlpha = INTERP(m_fWaterAlpha); -#undef INTERP - - if(m_FogReduction != 0) - m_fCurrentFarClip = Max(m_fCurrentFarClip, m_FogReduction/64.0f * 650.0f); - - m_CurrentStoredValue = (m_CurrentStoredValue+1)&0xF; - - float sunAngle = 2*PI*(CClock::GetSeconds()/60.0f + CClock::GetMinutes() + CClock::GetHours()*60)/(24*60); - CVector &sunPos = GetSunDirection(); - sunPos.x = Sin(sunAngle); - sunPos.y = 1.0f; - sunPos.z = 0.2f - Cos(sunAngle); - sunPos.Normalise(); - - if(m_bExtraColourOn) - m_ExtraColourInter = Min(1.0f, m_ExtraColourInter + CTimer::GetTimeStep()/120.0f); - else - m_ExtraColourInter = Max(-.0f, m_ExtraColourInter - CTimer::GetTimeStep()/120.0f); - if(m_ExtraColourInter > 0.0f){ -#define INTERP(extra,cur) (m_ExtraColourInter*extra[m_ExtraColour][WEATHER_EXTRACOLOURS] + (1.0f-m_ExtraColourInter)*cur) -#define INTERPscl(extra,scl,cur) (m_ExtraColourInter*extra[m_ExtraColour][WEATHER_EXTRACOLOURS]/scl + (1.0f-m_ExtraColourInter)*cur) - if(m_nSkyTopRed[m_ExtraColour][WEATHER_EXTRACOLOURS] != 0 || - m_nSkyTopGreen[m_ExtraColour][WEATHER_EXTRACOLOURS] != 0 || - m_nSkyTopBlue[m_ExtraColour][WEATHER_EXTRACOLOURS] != 0){ - m_nCurrentSkyTopRed = INTERP(m_nSkyTopRed,m_nCurrentSkyTopRed); - m_nCurrentSkyTopGreen = INTERP(m_nSkyTopGreen,m_nCurrentSkyTopGreen); - m_nCurrentSkyTopBlue = INTERP(m_nSkyTopBlue,m_nCurrentSkyTopBlue); - - m_nCurrentSkyBottomRed = INTERP(m_nSkyBottomRed,m_nCurrentSkyBottomRed); - m_nCurrentSkyBottomGreen = INTERP(m_nSkyBottomGreen,m_nCurrentSkyBottomGreen); - m_nCurrentSkyBottomBlue = INTERP(m_nSkyBottomBlue,m_nCurrentSkyBottomBlue); - - m_nCurrentSunCoreRed = INTERP(m_nSunCoreRed,m_nCurrentSunCoreRed); - m_nCurrentSunCoreGreen = INTERP(m_nSunCoreGreen,m_nCurrentSunCoreGreen); - m_nCurrentSunCoreBlue = INTERP(m_nSunCoreBlue,m_nCurrentSunCoreBlue); - - m_nCurrentSunCoronaRed = INTERP(m_nSunCoronaRed,m_nCurrentSunCoronaRed); - m_nCurrentSunCoronaGreen = INTERP(m_nSunCoronaGreen,m_nCurrentSunCoronaGreen); - m_nCurrentSunCoronaBlue = INTERP(m_nSunCoronaBlue,m_nCurrentSunCoronaBlue); - - m_fCurrentSunSize = INTERPscl(m_fSunSize,10.0f,m_fCurrentSunSize); - - m_nCurrentLowCloudsRed = INTERP(m_nLowCloudsRed,m_nCurrentLowCloudsRed); - m_nCurrentLowCloudsGreen = INTERP(m_nLowCloudsGreen,m_nCurrentLowCloudsGreen); - m_nCurrentLowCloudsBlue = INTERP(m_nLowCloudsBlue,m_nCurrentLowCloudsBlue); - - m_nCurrentFluffyCloudsTopRed = INTERP(m_nFluffyCloudsTopRed,m_nCurrentFluffyCloudsTopRed); - m_nCurrentFluffyCloudsTopGreen = INTERP(m_nFluffyCloudsTopGreen,m_nCurrentFluffyCloudsTopGreen); - m_nCurrentFluffyCloudsTopBlue = INTERP(m_nFluffyCloudsTopBlue,m_nCurrentFluffyCloudsTopBlue); - - m_nCurrentFluffyCloudsBottomRed = INTERP(m_nFluffyCloudsBottomRed,m_nCurrentFluffyCloudsBottomRed); - m_nCurrentFluffyCloudsBottomGreen = INTERP(m_nFluffyCloudsBottomGreen,m_nCurrentFluffyCloudsBottomGreen); - m_nCurrentFluffyCloudsBottomBlue = INTERP(m_nFluffyCloudsBottomBlue,m_nCurrentFluffyCloudsBottomBlue); - - m_fCurrentWaterRed = INTERP(m_fWaterRed,m_fCurrentWaterRed); - m_fCurrentWaterGreen = INTERP(m_fWaterGreen,m_fCurrentWaterGreen); - m_fCurrentWaterBlue = INTERP(m_fWaterBlue,m_fCurrentWaterBlue); - m_fCurrentWaterAlpha = INTERP(m_fWaterAlpha,m_fCurrentWaterAlpha); - } - - m_fCurrentAmbientRed = INTERP(m_nAmbientRed,m_fCurrentAmbientRed); - m_fCurrentAmbientGreen = INTERP(m_nAmbientGreen,m_fCurrentAmbientGreen); - m_fCurrentAmbientBlue = INTERP(m_nAmbientBlue,m_fCurrentAmbientBlue); - - m_fCurrentAmbientRed_Obj = INTERP(m_nAmbientRed_Obj,m_fCurrentAmbientRed_Obj); - m_fCurrentAmbientGreen_Obj = INTERP(m_nAmbientGreen_Obj,m_fCurrentAmbientGreen_Obj); - m_fCurrentAmbientBlue_Obj = INTERP(m_nAmbientBlue_Obj,m_fCurrentAmbientBlue_Obj); - - m_fCurrentAmbientRed_Bl = INTERP(m_nAmbientRed_Bl,m_fCurrentAmbientRed_Bl); - m_fCurrentAmbientGreen_Bl = INTERP(m_nAmbientGreen_Bl,m_fCurrentAmbientGreen_Bl); - m_fCurrentAmbientBlue_Bl = INTERP(m_nAmbientBlue_Bl,m_fCurrentAmbientBlue_Bl); - - m_fCurrentAmbientRed_Obj_Bl = INTERP(m_nAmbientRed_Obj_Bl,m_fCurrentAmbientRed_Obj_Bl); - m_fCurrentAmbientGreen_Obj_Bl = INTERP(m_nAmbientGreen_Obj_Bl,m_fCurrentAmbientGreen_Obj_Bl); - m_fCurrentAmbientBlue_Obj_Bl = INTERP(m_nAmbientBlue_Obj_Bl,m_fCurrentAmbientBlue_Obj_Bl); - - m_fCurrentDirectionalRed = INTERP(m_nDirectionalRed,m_fCurrentDirectionalRed); - m_fCurrentDirectionalGreen = INTERP(m_nDirectionalGreen,m_fCurrentDirectionalGreen); - m_fCurrentDirectionalBlue = INTERP(m_nDirectionalBlue,m_fCurrentDirectionalBlue); - - m_fCurrentSpriteSize = INTERPscl(m_fSpriteSize,10.0f,m_fCurrentSpriteSize); - m_fCurrentSpriteBrightness = INTERPscl(m_fSpriteBrightness,10.0f,m_fCurrentSpriteBrightness); - m_nCurrentShadowStrength = INTERP(m_nShadowStrength,m_nCurrentShadowStrength); - m_nCurrentLightShadowStrength = INTERP(m_nLightShadowStrength,m_nCurrentLightShadowStrength); - m_nCurrentPoleShadowStrength = INTERP(m_nPoleShadowStrength,m_nCurrentPoleShadowStrength); - m_fCurrentFarClip = INTERP(m_fFarClip,m_fCurrentFarClip); - m_fCurrentFogStart = INTERP(m_fFogStart,m_fCurrentFogStart); - m_fCurrentLightsOnGroundBrightness = INTERPscl(m_fLightsOnGroundBrightness,10.0f,m_fCurrentLightsOnGroundBrightness); - - m_fCurrentBlurRed = INTERP(m_fBlurRed,m_fCurrentBlurRed); - m_fCurrentBlurGreen = INTERP(m_fBlurGreen,m_fCurrentBlurGreen); - m_fCurrentBlurBlue = INTERP(m_fBlurBlue,m_fCurrentBlurBlue); - -#undef INTERP -#undef INTERPscl - } - - if(TheCamera.m_BlurType == MOTION_BLUR_NONE || TheCamera.m_BlurType == MOTION_BLUR_LIGHT_SCENE) - TheCamera.SetMotionBlur(m_fCurrentBlurRed, m_fCurrentBlurGreen, m_fCurrentBlurBlue, 5, MOTION_BLUR_LIGHT_SCENE); - - m_nCurrentFogColourRed = (m_nCurrentSkyTopRed + 2*m_nCurrentSkyBottomRed) / 3; - m_nCurrentFogColourGreen = (m_nCurrentSkyTopGreen + 2*m_nCurrentSkyBottomGreen) / 3; - m_nCurrentFogColourBlue = (m_nCurrentSkyTopBlue + 2*m_nCurrentSkyBottomBlue) / 3; - - m_fCurrentAmbientRed /= 255.0f; - m_fCurrentAmbientGreen /= 255.0f; - m_fCurrentAmbientBlue /= 255.0f; - m_fCurrentAmbientRed_Obj /= 255.0f; - m_fCurrentAmbientGreen_Obj /= 255.0f; - m_fCurrentAmbientBlue_Obj /= 255.0f; - m_fCurrentAmbientRed_Bl /= 255.0f; - m_fCurrentAmbientGreen_Bl /= 255.0f; - m_fCurrentAmbientBlue_Bl /= 255.0f; - m_fCurrentAmbientRed_Obj_Bl /= 255.0f; - m_fCurrentAmbientGreen_Obj_Bl /= 255.0f; - m_fCurrentAmbientBlue_Obj_Bl /= 255.0f; - m_fCurrentDirectionalRed /= 255.0f; - m_fCurrentDirectionalGreen /= 255.0f; - m_fCurrentDirectionalBlue /= 255.0f; - - CShadows::CalcPedShadowValues(sunPos, - &m_fShadowFrontX[m_CurrentStoredValue], &m_fShadowFrontY[m_CurrentStoredValue], - &m_fShadowSideX[m_CurrentStoredValue], &m_fShadowSideY[m_CurrentStoredValue], - &m_fShadowDisplacementX[m_CurrentStoredValue], &m_fShadowDisplacementY[m_CurrentStoredValue]); - - if(TheCamera.GetForward().z < -0.9f || - !CWeather::bScriptsForceRain && (CCullZones::PlayerNoRain() || CCullZones::CamNoRain() || CCutsceneMgr::IsRunning())) - m_FogReduction = Min(m_FogReduction+1, 64); - else - m_FogReduction = Max(m_FogReduction-1, 0); -} diff --git a/src/render/Timecycle.h b/src/render/Timecycle.h deleted file mode 100644 index da911b75..00000000 --- a/src/render/Timecycle.h +++ /dev/null @@ -1,201 +0,0 @@ -#pragma once - -class CTimeCycle -{ - static uint8 m_nAmbientRed[NUMHOURS][NUMWEATHERS]; - static uint8 m_nAmbientGreen[NUMHOURS][NUMWEATHERS]; - static uint8 m_nAmbientBlue[NUMHOURS][NUMWEATHERS]; - static uint8 m_nAmbientRed_Obj[NUMHOURS][NUMWEATHERS]; - static uint8 m_nAmbientGreen_Obj[NUMHOURS][NUMWEATHERS]; - static uint8 m_nAmbientBlue_Obj[NUMHOURS][NUMWEATHERS]; - static uint8 m_nAmbientRed_Bl[NUMHOURS][NUMWEATHERS]; - static uint8 m_nAmbientGreen_Bl[NUMHOURS][NUMWEATHERS]; - static uint8 m_nAmbientBlue_Bl[NUMHOURS][NUMWEATHERS]; - static uint8 m_nAmbientRed_Obj_Bl[NUMHOURS][NUMWEATHERS]; - static uint8 m_nAmbientGreen_Obj_Bl[NUMHOURS][NUMWEATHERS]; - static uint8 m_nAmbientBlue_Obj_Bl[NUMHOURS][NUMWEATHERS]; - static uint8 m_nDirectionalRed[NUMHOURS][NUMWEATHERS]; - static uint8 m_nDirectionalGreen[NUMHOURS][NUMWEATHERS]; - static uint8 m_nDirectionalBlue[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSkyTopRed[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSkyTopGreen[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSkyTopBlue[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSkyBottomRed[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSkyBottomGreen[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSkyBottomBlue[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSunCoreRed[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSunCoreGreen[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSunCoreBlue[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSunCoronaRed[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSunCoronaGreen[NUMHOURS][NUMWEATHERS]; - static uint8 m_nSunCoronaBlue[NUMHOURS][NUMWEATHERS]; - static int8 m_fSunSize[NUMHOURS][NUMWEATHERS]; - static int8 m_fSpriteSize[NUMHOURS][NUMWEATHERS]; - static int8 m_fSpriteBrightness[NUMHOURS][NUMWEATHERS]; - static uint8 m_nShadowStrength[NUMHOURS][NUMWEATHERS]; - static uint8 m_nLightShadowStrength[NUMHOURS][NUMWEATHERS]; - static uint8 m_nPoleShadowStrength[NUMHOURS][NUMWEATHERS]; - static int16 m_fFogStart[NUMHOURS][NUMWEATHERS]; - static int16 m_fFarClip[NUMHOURS][NUMWEATHERS]; - static uint8 m_fLightsOnGroundBrightness[NUMHOURS][NUMWEATHERS]; - static uint8 m_nLowCloudsRed[NUMHOURS][NUMWEATHERS]; - static uint8 m_nLowCloudsGreen[NUMHOURS][NUMWEATHERS]; - static uint8 m_nLowCloudsBlue[NUMHOURS][NUMWEATHERS]; - static uint8 m_nFluffyCloudsTopRed[NUMHOURS][NUMWEATHERS]; - static uint8 m_nFluffyCloudsTopGreen[NUMHOURS][NUMWEATHERS]; - static uint8 m_nFluffyCloudsTopBlue[NUMHOURS][NUMWEATHERS]; - static uint8 m_nFluffyCloudsBottomRed[NUMHOURS][NUMWEATHERS]; - static uint8 m_nFluffyCloudsBottomGreen[NUMHOURS][NUMWEATHERS]; - static uint8 m_nFluffyCloudsBottomBlue[NUMHOURS][NUMWEATHERS]; - static uint8 m_fBlurRed[NUMHOURS][NUMWEATHERS]; - static uint8 m_fBlurGreen[NUMHOURS][NUMWEATHERS]; - static uint8 m_fBlurBlue[NUMHOURS][NUMWEATHERS]; - static uint8 m_fWaterRed[NUMHOURS][NUMWEATHERS]; - static uint8 m_fWaterGreen[NUMHOURS][NUMWEATHERS]; - static uint8 m_fWaterBlue[NUMHOURS][NUMWEATHERS]; - static uint8 m_fWaterAlpha[NUMHOURS][NUMWEATHERS]; - - static float m_fCurrentAmbientRed; - static float m_fCurrentAmbientGreen; - static float m_fCurrentAmbientBlue; - static float m_fCurrentAmbientRed_Obj; - static float m_fCurrentAmbientGreen_Obj; - static float m_fCurrentAmbientBlue_Obj; - static float m_fCurrentAmbientRed_Bl; - static float m_fCurrentAmbientGreen_Bl; - static float m_fCurrentAmbientBlue_Bl; - static float m_fCurrentAmbientRed_Obj_Bl; - static float m_fCurrentAmbientGreen_Obj_Bl; - static float m_fCurrentAmbientBlue_Obj_Bl; - static float m_fCurrentDirectionalRed; - static float m_fCurrentDirectionalGreen; - static float m_fCurrentDirectionalBlue; - static int32 m_nCurrentSkyTopRed; - static int32 m_nCurrentSkyTopGreen; - static int32 m_nCurrentSkyTopBlue; - static int32 m_nCurrentSkyBottomRed; - static int32 m_nCurrentSkyBottomGreen; - static int32 m_nCurrentSkyBottomBlue; - static int32 m_nCurrentSunCoreRed; - static int32 m_nCurrentSunCoreGreen; - static int32 m_nCurrentSunCoreBlue; - static int32 m_nCurrentSunCoronaRed; - static int32 m_nCurrentSunCoronaGreen; - static int32 m_nCurrentSunCoronaBlue; - static float m_fCurrentSunSize; - static float m_fCurrentSpriteSize; - static float m_fCurrentSpriteBrightness; - static int32 m_nCurrentShadowStrength; - static int32 m_nCurrentLightShadowStrength; - static int32 m_nCurrentPoleShadowStrength; - static float m_fCurrentFogStart; - static float m_fCurrentFarClip; - static float m_fCurrentLightsOnGroundBrightness; - static int32 m_nCurrentLowCloudsRed; - static int32 m_nCurrentLowCloudsGreen; - static int32 m_nCurrentLowCloudsBlue; - static int32 m_nCurrentFluffyCloudsTopRed; - static int32 m_nCurrentFluffyCloudsTopGreen; - static int32 m_nCurrentFluffyCloudsTopBlue; - static int32 m_nCurrentFluffyCloudsBottomRed; - static int32 m_nCurrentFluffyCloudsBottomGreen; - static int32 m_nCurrentFluffyCloudsBottomBlue; - static float m_fCurrentBlurRed; - static float m_fCurrentBlurGreen; - static float m_fCurrentBlurBlue; - static float m_fCurrentWaterRed; - static float m_fCurrentWaterGreen; - static float m_fCurrentWaterBlue; - static float m_fCurrentWaterAlpha; - static int32 m_nCurrentFogColourRed; - static int32 m_nCurrentFogColourGreen; - static int32 m_nCurrentFogColourBlue; - - static int32 m_FogReduction; - -public: - static int32 m_bExtraColourOn; - static int32 m_ExtraColour; - static float m_ExtraColourInter; - static int32 m_CurrentStoredValue; - static CVector m_VectorToSun[16]; - static float m_fShadowFrontX[16]; - static float m_fShadowFrontY[16]; - static float m_fShadowSideX[16]; - static float m_fShadowSideY[16]; - static float m_fShadowDisplacementX[16]; - static float m_fShadowDisplacementY[16]; - - static float GetAmbientRed(void) { return m_fCurrentAmbientRed; } - static float GetAmbientGreen(void) { return m_fCurrentAmbientGreen; } - static float GetAmbientBlue(void) { return m_fCurrentAmbientBlue; } - static float GetAmbientRed_Obj(void) { return m_fCurrentAmbientRed_Obj; } - static float GetAmbientGreen_Obj(void) { return m_fCurrentAmbientGreen_Obj; } - static float GetAmbientBlue_Obj(void) { return m_fCurrentAmbientBlue_Obj; } - static float GetAmbientRed_Bl(void) { return m_fCurrentAmbientRed_Bl; } - static float GetAmbientGreen_Bl(void) { return m_fCurrentAmbientGreen_Bl; } - static float GetAmbientBlue_Bl(void) { return m_fCurrentAmbientBlue_Bl; } - static float GetAmbientRed_Obj_Bl(void) { return m_fCurrentAmbientRed_Obj_Bl; } - static float GetAmbientGreen_Obj_Bl(void) { return m_fCurrentAmbientGreen_Obj_Bl; } - static float GetAmbientBlue_Obj_Bl(void) { return m_fCurrentAmbientBlue_Obj_Bl; } - static float GetDirectionalRed(void) { return m_fCurrentDirectionalRed; } - static float GetDirectionalGreen(void) { return m_fCurrentDirectionalGreen; } - static float GetDirectionalBlue(void) { return m_fCurrentDirectionalBlue; } - static int32 GetSkyTopRed(void) { return m_nCurrentSkyTopRed; } - static int32 GetSkyTopGreen(void) { return m_nCurrentSkyTopGreen; } - static int32 GetSkyTopBlue(void) { return m_nCurrentSkyTopBlue; } - static int32 GetSkyBottomRed(void) { return m_nCurrentSkyBottomRed; } - static int32 GetSkyBottomGreen(void) { return m_nCurrentSkyBottomGreen; } - static int32 GetSkyBottomBlue(void) { return m_nCurrentSkyBottomBlue; } - static int32 GetSunCoreRed(void) { return m_nCurrentSunCoreRed; } - static int32 GetSunCoreGreen(void) { return m_nCurrentSunCoreGreen; } - static int32 GetSunCoreBlue(void) { return m_nCurrentSunCoreBlue; } - static int32 GetSunCoronaRed(void) { return m_nCurrentSunCoronaRed; } - static int32 GetSunCoronaGreen(void) { return m_nCurrentSunCoronaGreen; } - static int32 GetSunCoronaBlue(void) { return m_nCurrentSunCoronaBlue; } - static float GetSunSize(void) { return m_fCurrentSunSize; } - static float GetSpriteBrightness(void) { return m_fCurrentSpriteBrightness; } - static float GetSpriteSize(void) { return m_fCurrentSpriteSize; } - static int32 GetShadowStrength(void) { return m_nCurrentShadowStrength; } - static int32 GetLightShadowStrength(void) { return m_nCurrentLightShadowStrength; } - static float GetLightOnGroundBrightness(void) { return m_fCurrentLightsOnGroundBrightness; } - static float GetFarClip(void) { return m_fCurrentFarClip; } - static float GetFogStart(void) { return m_fCurrentFogStart; } - - static int32 GetLowCloudsRed(void) { return m_nCurrentLowCloudsRed; } - static int32 GetLowCloudsGreen(void) { return m_nCurrentLowCloudsGreen; } - static int32 GetLowCloudsBlue(void) { return m_nCurrentLowCloudsBlue; } - static int32 GetFluffyCloudsTopRed(void) { return m_nCurrentFluffyCloudsTopRed; } - static int32 GetFluffyCloudsTopGreen(void) { return m_nCurrentFluffyCloudsTopGreen; } - static int32 GetFluffyCloudsTopBlue(void) { return m_nCurrentFluffyCloudsTopBlue; } - static int32 GetFluffyCloudsBottomRed(void) { return m_nCurrentFluffyCloudsBottomRed; } - static int32 GetFluffyCloudsBottomGreen(void) { return m_nCurrentFluffyCloudsBottomGreen; } - static int32 GetFluffyCloudsBottomBlue(void) { return m_nCurrentFluffyCloudsBottomBlue; } - static int32 GetFogRed(void) { return m_nCurrentFogColourRed; } - static int32 GetFogGreen(void) { return m_nCurrentFogColourGreen; } - static int32 GetFogBlue(void) { return m_nCurrentFogColourBlue; } - static int32 GetFogReduction(void) { return m_FogReduction; } - - static int32 GetBlurRed(void) { return m_fCurrentBlurRed; } - static int32 GetBlurGreen(void) { return m_fCurrentBlurGreen; } - static int32 GetBlurBlue(void) { return m_fCurrentBlurBlue; } - static int32 GetWaterRed(void) { return m_fCurrentWaterRed; } - static int32 GetWaterGreen(void) { return m_fCurrentWaterGreen; } - static int32 GetWaterBlue(void) { return m_fCurrentWaterBlue; } - static int32 GetWaterAlpha(void) { return m_fCurrentWaterAlpha; } - - static void Initialise(void); - static void Update(void); - static float Interpolate(int8 *a, int8 *b); - static float Interpolate(uint8 *a, uint8 *b); - static float Interpolate(int16 *a, int16 *b); - static void StartExtraColour(int32 c, bool fade); - static void StopExtraColour(bool fade); - static CVector &GetSunDirection(void) { return m_VectorToSun[m_CurrentStoredValue]; } - static float GetShadowFrontX(void) { return m_fShadowFrontX[m_CurrentStoredValue]; } - static float GetShadowFrontY(void) { return m_fShadowFrontY[m_CurrentStoredValue]; } - static float GetShadowSideX(void) { return m_fShadowSideX[m_CurrentStoredValue]; } - static float GetShadowSideY(void) { return m_fShadowSideY[m_CurrentStoredValue]; } - static float GetShadowDisplacementX(void) { return m_fShadowDisplacementX[m_CurrentStoredValue]; } - static float GetShadowDisplacementY(void) { return m_fShadowDisplacementY[m_CurrentStoredValue]; } -}; diff --git a/src/render/VarConsole.cpp b/src/render/VarConsole.cpp deleted file mode 100644 index 372a091a..00000000 --- a/src/render/VarConsole.cpp +++ /dev/null @@ -1,786 +0,0 @@ -#include "common.h" -#include "VarConsole.h" -#include "Font.h" -#include "Pad.h" - -#define VAR_CONSOLE_PAD 1 - -CVarConsole VarConsole; - -void -CVarConsole::Initialise() -{ - m_nCountEntries = 0; - m_nCurPage = 1; - m_bIsOpen = false; - m_nCurEntry = 0; - m_nFirstEntryOnPage = 0; -} - -void -CVarConsole::Add(char *text, int8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pInt8Value = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_INT8; - m_aEntries[i].I8_step = step; - m_aEntries[i].I8_min = min; - m_aEntries[i].I8_max = max; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, int16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pInt16Value = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_INT16; - m_aEntries[i].I16_step = step; - m_aEntries[i].I16_min = min; - m_aEntries[i].I16_max = max; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, int32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pInt32Value = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_INT32; - m_aEntries[i].I32_step = step; - m_aEntries[i].I32_min = min; - m_aEntries[i].I32_max = max; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, int64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pInt64Value = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_INT64; - m_aEntries[i].I64_step = step; - m_aEntries[i].I64_min = min; - m_aEntries[i].I64_max = max; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, uint8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pUint8Value = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_UINT8; - m_aEntries[i].I8_step = step; - m_aEntries[i].I8_min = min; - m_aEntries[i].I8_max = max; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, uint16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pUint16Value = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_UINT16; - m_aEntries[i].I16_step = step; - m_aEntries[i].I16_min = min; - m_aEntries[i].I16_max = max; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, uint32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pUint32Value = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_UINT32; - m_aEntries[i].I32_step = step; - m_aEntries[i].I32_min = min; - m_aEntries[i].I32_max = max; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, uint64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pUint64Value = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_UINT64; - m_aEntries[i].I64_step = step; - m_aEntries[i].I64_min = min; - m_aEntries[i].I64_max = max; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, float *pVal, float step, float min, float max, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pFloatValue = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_FLOAT; - m_aEntries[i].F_step = step; - m_aEntries[i].F_min = min; - m_aEntries[i].F_max = max; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, bool *pVal, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pBoolValue = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_BOOL; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, bool8 *pVal, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pUint8Value = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_BOOL8; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, bool16 *pVal, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pUint16Value = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_BOOL16; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, bool32 *pVal, bool8 isVar) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pUint32Value = pVal; - m_aEntries[i].bAllowExceedBounds = isVar; - m_aEntries[i].VarType = VCE_TYPE_BOOL32; - m_nCountEntries++; -} - -void -CVarConsole::Add(char *text, void (*pCallback)(void)) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - return; - } - - m_aEntries[i].text = text; - m_aEntries[i].pCallback = pCallback; - m_aEntries[i].VarType = VCE_TYPE_FUNCTION; - m_nCountEntries++; -} - -void -CVarConsole::Remove(char *text) -{ - int i; - for (i = 0; i < m_nCountEntries; i++) { - if (m_aEntries[i].text == text) - { - for (int j = i; j < m_nCountEntries-1; j++) - m_aEntries[j] = m_aEntries[j+1]; - m_nCountEntries--; - return; - } - } -} - -void -CVarConsole::SortPages() -{ - m_nNumPages = m_nCountEntries / 30 + 1; -} - -void -CVarConsole::Display() -{ - char s[256]; - wchar ws[256]; - - CFont::SetColor(CRGBA(200, 200, 200, 255)); - CFont::SetFontStyle(FONT_STANDARD); - CFont::SetScale(SCREEN_SCALE_X(0.5f), SCREEN_SCALE_Y(0.6f)); - CFont::SetDropShadowPosition(2); - CFont::SetDropColor(CRGBA(0, 0, 0, 255)); - CFont::SetPropOn(); - CFont::SetWrapx(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH)); - CFont::SetRightJustifyWrap(0.0f); - sprintf(s, "PAGE %d", m_nCurPage); - AsciiToUnicode(s, ws); - CFont::SetRightJustifyOn(); - CFont::PrintString(SCREEN_SCALE_X(310.0f), SCREEN_SCALE_Y(30.0f), ws); - CFont::SetRightJustifyOff(); - int y = 45; - for (int i = m_nFirstEntryOnPage; i < m_nCountEntries && i < m_nFirstEntryOnPage + 30; i++) - { - switch (m_aEntries[i].VarType) - { - case VCE_TYPE_INT8: - sprintf(s, "(%d) %s:I8:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt8Value); - break; - case VCE_TYPE_INT16: - sprintf(s, "(%d) %s:I16:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt16Value); - break; - case VCE_TYPE_INT32: - sprintf(s, "(%d) %s:I32:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt32Value); - break; - case VCE_TYPE_INT64: -#ifdef FIX_BUGS - sprintf(s, "(%d) %s:I64:%lld", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt64Value); -#else - sprintf(s, "(%d) %s:I64:%d", i + 1, m_aEntries[i].text, (int32)*m_aEntries[i].pInt64Value); -#endif - break; - case VCE_TYPE_UINT8: - sprintf(s, "(%d) %s:U8:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint8Value); - break; - case VCE_TYPE_UINT16: - sprintf(s, "(%d) %s:U6:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint16Value); - break; - case VCE_TYPE_UINT32: - sprintf(s, "(%d) %s:U32:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint32Value); - break; - case VCE_TYPE_UINT64: -#ifdef FIX_BUGS - sprintf(s, "(%d) %s:U64:%llu", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint64Value); -#else - sprintf(s, "(%d) %s:U64:%d", i + 1, m_aEntries[i].text, (uint32)*m_aEntries[i].pUint64Value); -#endif - break; - case VCE_TYPE_FLOAT: - sprintf(s, "(%d) %s:F:%f", i + 1, m_aEntries[i].text, *m_aEntries[i].pFloatValue); - break; - case VCE_TYPE_BOOL: - if (*m_aEntries[i].pBoolValue) - sprintf(s, "(%d) %s:B:TRUE", i + 1, m_aEntries[i].text); - else - sprintf(s, "(%d) %s:B : FALSE", i + 1, m_aEntries[i].text); - break; - case VCE_TYPE_BOOL8: - if (*m_aEntries[i].pUint8Value == FALSE) - sprintf(s, "(%d) %s:B8:FALSE", i + 1, m_aEntries[i].text); - else - sprintf(s, "(%d) %s:B8:TRUE", i + 1, m_aEntries[i].text); - break; - case VCE_TYPE_BOOL16: - if (*m_aEntries[i].pUint16Value == FALSE) - sprintf(s, "(%d) %s:B16:FALSE", i + 1, m_aEntries[i].text); - else - sprintf(s, "(%d) %s:B16:TRUE", i + 1, m_aEntries[i].text); - break; - case VCE_TYPE_BOOL32: - if (*m_aEntries[i].pUint32Value == FALSE) - sprintf(s, "(%d) %s:B32:FALSE", i + 1, m_aEntries[i].text); - else - sprintf(s, "(%d) %s:B32:TRUE", i + 1, m_aEntries[i].text); - break; - case VCE_TYPE_FUNCTION: - sprintf(s, "(%d) %s:FUNCTION:call this function?", i + 1, m_aEntries[i].text); - break; - } - AsciiToUnicode(s, ws); - if (m_nCurEntry == i) { - CFont::SetBackgroundOn(); -#ifdef FIX_BUGS - CFont::SetBackgroundColor(CRGBA(128, 128, 128, 128)); -#endif - } -#ifdef FIX_BUGS - else - CFont::SetBackgroundColor(CRGBA(128, 128, 128, 0)); -#endif - - CFont::SetColor(CRGBA(200, 200, 200, 255)); - CFont::PrintString(SCREEN_SCALE_X(30.0f), SCREEN_SCALE_Y(y), ws); - if (m_nCurEntry == i) - CFont::SetBackgroundOff(); - y += 12; - } -} - -void -CVarConsole::ModifyLeft() -{ - CVarConsoleEntry &entry = m_aEntries[m_nCurEntry]; - switch (entry.VarType) - { - case VCE_TYPE_INT8: - *entry.pInt8Value -= entry.I8_step; - if (entry.bAllowExceedBounds) { - if (*entry.pInt8Value < entry.I8_min) - *entry.pInt8Value = entry.I8_max; - } else { - if (*entry.pInt8Value < entry.I8_min) - *entry.pInt8Value = entry.I8_min; - } - break; - case VCE_TYPE_INT16: - *entry.pInt16Value -= entry.I16_step; - if (entry.bAllowExceedBounds) { - if (*entry.pInt16Value < entry.I16_min) - *entry.pInt16Value = entry.I16_max; - } - else { - if (*entry.pInt16Value < entry.I16_min) - *entry.pInt16Value = entry.I16_min; - } - break; - case VCE_TYPE_INT32: - *entry.pInt32Value -= entry.I32_step; - if (entry.bAllowExceedBounds) { - if (*entry.pInt32Value < entry.I32_min) - *entry.pInt32Value = entry.I32_max; - } - else { - if (*entry.pInt32Value < entry.I32_min) - *entry.pInt32Value = entry.I32_min; - } - break; - case VCE_TYPE_INT64: - *entry.pInt64Value -= entry.I64_step; - if (entry.bAllowExceedBounds) { - if (*entry.pInt64Value < entry.I64_min) - *entry.pInt64Value = entry.I64_max; - } - else { - if (*entry.pInt64Value < entry.I64_min) - *entry.pInt64Value = entry.I64_min; - } - break; - case VCE_TYPE_UINT8: - *entry.pUint8Value -= entry.I8_step; - if (entry.bAllowExceedBounds) { - if (*(int8*)entry.pUint8Value < entry.I8_min) - *entry.pUint8Value = entry.I8_max; - } - else { - if (*(int8*)entry.pUint8Value < entry.I8_min) - *entry.pUint8Value = entry.I8_min; - } - break; - case VCE_TYPE_UINT16: - *entry.pUint16Value -= entry.I16_step; - if (entry.bAllowExceedBounds) { - if (*(int16*)entry.pUint16Value < entry.I16_min) - *entry.pUint16Value = entry.I16_max; - } - else { - if (*(int16*)entry.pUint16Value < entry.I16_min) - *entry.pUint16Value = entry.I16_min; - } - break; - case VCE_TYPE_UINT32: - *entry.pUint32Value -= entry.I32_step; - if (entry.bAllowExceedBounds) { - if (*(int32*)entry.pUint32Value < entry.I32_min) - *entry.pUint32Value = entry.I32_max; - } - else { - if (*(int32*)entry.pUint32Value < entry.I32_min) - *entry.pUint32Value = entry.I32_min; - } - break; - case VCE_TYPE_UINT64: - *entry.pUint64Value -= entry.I64_step; - if (entry.bAllowExceedBounds) { - if (*(int64*)entry.pUint64Value < entry.I64_min) - *entry.pUint64Value = entry.I64_max; - } - else { - if (*(int64*)entry.pUint64Value < entry.I64_min) - *entry.pUint64Value = entry.I64_min; - } - break; - case VCE_TYPE_FLOAT: - *entry.pFloatValue -= entry.F_step; - if (entry.bAllowExceedBounds) { - if (*entry.pFloatValue < entry.F_min) - *entry.pFloatValue = entry.F_max; - } - else { - if (*entry.pFloatValue < entry.F_min) - *entry.pFloatValue = entry.F_min; - } - break; - case VCE_TYPE_BOOL: - if (entry.bAllowExceedBounds) - *entry.pBoolValue ^= true; - else - *entry.pBoolValue = false; - break; - case VCE_TYPE_BOOL8: - if (entry.bAllowExceedBounds) - *entry.pUint8Value = *entry.pUint8Value == false; - else - *entry.pUint8Value = false; - break; - case VCE_TYPE_BOOL16: - if (entry.bAllowExceedBounds) - *entry.pUint16Value = *entry.pUint16Value == false; - else - *entry.pUint16Value = false; - break; - case VCE_TYPE_BOOL32: - if (entry.bAllowExceedBounds) - *entry.pUint32Value = *entry.pUint32Value == false; - else - *entry.pUint32Value = false; - break; - case VCE_TYPE_FUNCTION: - entry.pCallback(); - break; - default: - return; - } -} - -void -CVarConsole::ModifyRight() -{ - CVarConsoleEntry &entry = m_aEntries[m_nCurEntry]; - switch (entry.VarType) - { - case VCE_TYPE_INT8: - *entry.pInt8Value += entry.I8_step; - if (entry.bAllowExceedBounds) { - if (*entry.pInt8Value > entry.I8_max) - *entry.pInt8Value = entry.I8_min; - } - else { - if (*entry.pInt8Value > entry.I8_max) - *entry.pInt8Value = entry.I8_max; - } - break; - case VCE_TYPE_INT16: - *entry.pInt16Value += entry.I16_step; - if (entry.bAllowExceedBounds) { - if (*entry.pInt16Value > entry.I16_max) - *entry.pInt16Value = entry.I16_min; - } - else { - if (*entry.pInt16Value > entry.I16_max) - *entry.pInt16Value = entry.I16_max; - } - break; - case VCE_TYPE_INT32: - *entry.pInt32Value += entry.I32_step; - if (entry.bAllowExceedBounds) { - if (*entry.pInt32Value > entry.I32_max) - *entry.pInt32Value = entry.I32_min; - } - else { - if (*entry.pInt32Value > entry.I32_max) - *entry.pInt32Value = entry.I32_max; - } - break; - case VCE_TYPE_INT64: - *entry.pInt64Value += entry.I64_step; - if (entry.bAllowExceedBounds) { - if (*entry.pInt64Value > entry.I64_max) - *entry.pInt64Value = entry.I64_min; - } - else { - if (*entry.pInt64Value > entry.I64_max) - *entry.pInt64Value = entry.I64_max; - } - break; - case VCE_TYPE_UINT8: - *entry.pUint8Value += entry.I8_step; - if (entry.bAllowExceedBounds) { - if (*entry.pUint8Value > (uint8)entry.I8_max) - *entry.pUint8Value = entry.I8_min; - } - else { - if (*entry.pUint8Value > (uint8)entry.I8_max) - *entry.pUint8Value = entry.I8_max; - } - break; - case VCE_TYPE_UINT16: - *entry.pUint16Value += entry.I16_step; - if (entry.bAllowExceedBounds) { - if (*entry.pUint16Value > (uint16)entry.I16_max) - *entry.pUint16Value = entry.I16_min; - } - else { - if (*entry.pUint16Value > (uint16)entry.I16_max) - *entry.pUint16Value = entry.I16_max; - } - break; - case VCE_TYPE_UINT32: - *entry.pUint32Value += entry.I32_step; - if (entry.bAllowExceedBounds) { - if (*entry.pUint32Value > (uint32)entry.I32_max) - *entry.pUint32Value = entry.I32_min; - } - else { - if (*entry.pUint32Value > (uint32)entry.I32_max) - *entry.pUint32Value = entry.I32_max; - } - break; - case VCE_TYPE_UINT64: - *entry.pUint64Value += entry.I64_step; - if (entry.bAllowExceedBounds) { - if (*entry.pUint64Value > (uint64)entry.I64_max) - *entry.pUint64Value = entry.I64_min; - } - else { - if (*entry.pUint64Value > (uint64)entry.I64_max) - *entry.pUint64Value = entry.I64_max; - } - break; - case VCE_TYPE_FLOAT: - *entry.pFloatValue += entry.F_step; - if (entry.bAllowExceedBounds) { - if (*entry.pFloatValue > entry.F_max) - *entry.pFloatValue = entry.F_min; - } - else { - if (*entry.pFloatValue > entry.F_max) - *entry.pFloatValue = entry.F_max; - } - break; - case VCE_TYPE_BOOL: - if (entry.bAllowExceedBounds) - *entry.pBoolValue ^= true; - else - *entry.pBoolValue = true; - break; - case VCE_TYPE_BOOL8: - if (entry.bAllowExceedBounds) - *entry.pUint8Value = *entry.pUint8Value == false; - else - *entry.pUint8Value = true; - break; - case VCE_TYPE_BOOL16: - if (entry.bAllowExceedBounds) - *entry.pUint16Value = *entry.pUint16Value == false; - else - *entry.pUint16Value = true; - break; - case VCE_TYPE_BOOL32: - if (entry.bAllowExceedBounds) - *entry.pUint32Value = *entry.pUint32Value == false; - else - *entry.pUint32Value = true; - break; - case VCE_TYPE_FUNCTION: - entry.pCallback(); - break; - default: - return; - } -} - -void -CVarConsole::Enter() -{ - m_bIsOpen = true; -} - -void -CVarConsole::Exit() -{ - m_bIsOpen = false; -} - -void -CVarConsole::Input() -{ - if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadDownJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadDown()) - { - m_nCurEntry++; - if (m_nCurEntry < m_nCountEntries) - { - if (m_nCurEntry > m_nFirstEntryOnPage + 29) - { - m_nFirstEntryOnPage = m_nCurEntry; - ++m_nCurPage; - } - } - else - { - m_nCurEntry = m_nCountEntries - 1; - } - } - - if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadUpJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadUp()) - { - m_nCurEntry--; - if (m_nCurEntry < m_nFirstEntryOnPage) - { - m_nFirstEntryOnPage = m_nCurEntry - 29; - --m_nCurPage; - } - if (m_nFirstEntryOnPage < 0) - { - m_nCurEntry = 0; - m_nFirstEntryOnPage = 0; - m_nCurPage = 1; - } - } - if (CPad::GetPad(VAR_CONSOLE_PAD)->GetSquare()) - ModifyLeft(); - if (CPad::GetPad(VAR_CONSOLE_PAD)->GetTriangle()) - ModifyRight(); - - if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadLeftJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadLeft()) - ModifyLeft(); - - if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadRightJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadRight()) - ModifyRight(); - - if (CPad::GetPad(VAR_CONSOLE_PAD)->GetLeftShoulder2JustDown()) - { - if (m_nCurPage > 1) - { - m_nCurPage--; - m_nFirstEntryOnPage -= 30; - m_nCurEntry = m_nFirstEntryOnPage; - if (m_nFirstEntryOnPage < 0) - { - m_nFirstEntryOnPage = 0; - m_nCurEntry = m_nFirstEntryOnPage; - m_nCurPage = 1; - } - } - } - - if (CPad::GetPad(VAR_CONSOLE_PAD)->GetRightShoulder2JustDown()) - { - if (m_nCurPage < m_nNumPages) - { - m_nCurPage++; - m_nFirstEntryOnPage += 30; - m_nCurEntry = m_nFirstEntryOnPage; - if (m_nFirstEntryOnPage >= m_nCountEntries) - { - m_nFirstEntryOnPage -= 30; - m_nCurEntry = m_nFirstEntryOnPage; - m_nCurPage--; - } - } - } - - if (CPad::GetPad(VAR_CONSOLE_PAD)->GetRightShoulder1JustDown() && CPad::GetPad(VAR_CONSOLE_PAD)->GetLeftShoulder1JustDown()) - Exit(); -} - -void -CVarConsole::Process() -{ - Input(); - SortPages(); - Display(); -} - -bool8 -CVarConsole::Open() -{ - return m_bIsOpen; -} - -void -CVarConsole::Check() -{ - if (Open()) - Process(); - else if (CPad::GetPad(VAR_CONSOLE_PAD)->GetRightShoulder1JustDown() && CPad::GetPad(VAR_CONSOLE_PAD)->GetLeftShoulder1JustDown()) - Enter(); -} \ No newline at end of file diff --git a/src/render/VarConsole.h b/src/render/VarConsole.h deleted file mode 100644 index 5179a10d..00000000 --- a/src/render/VarConsole.h +++ /dev/null @@ -1,92 +0,0 @@ -#pragma once - -enum eVarConsoleEntryType -{ - VCE_TYPE_INT8, - VCE_TYPE_INT16, - VCE_TYPE_INT32, - VCE_TYPE_INT64, - VCE_TYPE_UINT8, - VCE_TYPE_UINT16, - VCE_TYPE_UINT32, - VCE_TYPE_UINT64, - VCE_TYPE_FLOAT, - VCE_TYPE_BOOL, - VCE_TYPE_BOOL8, - VCE_TYPE_BOOL16, - VCE_TYPE_BOOL32, - VCE_TYPE_FUNCTION, -}; - -struct CVarConsoleEntry -{ - char *text; - int8 *pInt8Value; - int16 *pInt16Value; - int32 *pInt32Value; - int64 *pInt64Value; - uint8 *pUint8Value; - uint16 *pUint16Value; - uint32 *pUint32Value; - uint64 *pUint64Value; - float *pFloatValue; - bool *pBoolValue; - void (*pCallback)(void); - int8 I8_step, I8_max, I8_min; - int16 I16_step, I16_max, I16_min; - int32 I32_step, I32_max, I32_min; - int64 I64_step, I64_max, I64_min; - float F_step, F_max, F_min; - bool8 bAllowExceedBounds; - uint8 VarType; -}; - - -class CVarConsole -{ - int32 m_nCountEntries; - bool8 m_bIsOpen; - int32 m_nCurEntry; - int32 m_nFirstEntryOnPage; - int32 m_nCurPage; - int32 m_nNumPages; - CVarConsoleEntry m_aEntries[91]; -public: -#ifdef FIX_BUGS - CVarConsole() { Initialise(); } -#endif - void Initialise(); - void Add(char *text, int8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar); - void Add(char *text, int16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar); - void Add(char *text, int32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar); - void Add(char *text, int64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar); - void Add(char *text, uint8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar); - void Add(char *text, uint16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar); - void Add(char *text, uint32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar); - void Add(char *text, uint64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar); - void Add(char *text, float *pVal, float step, float min, float max, bool8 isVar); - void Add(char *text, bool *pVal, bool8 isVar); - void Add(char *text, bool8 *pVal, bool8 isVar); - void Add(char *text, bool16 *pVal, bool8 isVar); - void Add(char *text, bool32 *pVal, bool8 isVar); - void Add(char *text, void (*pVar)(void)); - - void Remove(char *text); - - void SortPages(); - void Display(); - - void ModifyLeft(); - void ModifyRight(); - - void Enter(); - void Exit(); - - void Input(); - void Process(); - - bool8 Open(); - void Check(); -}; - -extern CVarConsole VarConsole; \ No newline at end of file diff --git a/src/render/WaterCannon.cpp b/src/render/WaterCannon.cpp deleted file mode 100644 index 4976f8a3..00000000 --- a/src/render/WaterCannon.cpp +++ /dev/null @@ -1,317 +0,0 @@ -#include "common.h" - -#include "WaterCannon.h" -#include "Vector.h" -#include "General.h" -#include "main.h" -#include "Timer.h" -#include "Pools.h" -#include "Ped.h" -#include "AnimManager.h" -#include "Fire.h" -#include "WaterLevel.h" -#include "Camera.h" -#include "Particle.h" - -#define WATERCANNONVERTS 4 -#define WATERCANNONINDEXES 12 - -RwIm3DVertex WaterCannonVertices[WATERCANNONVERTS]; -RwImVertexIndex WaterCannonIndexList[WATERCANNONINDEXES]; - -CWaterCannon CWaterCannons::aCannons[NUM_WATERCANNONS]; - -void CWaterCannon::Init(void) -{ - m_nId = 0; - m_nCur = 0; - m_nTimeCreated = CTimer::GetTimeInMilliseconds(); - - for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ ) - m_abUsed[i] = false; - - RwIm3DVertexSetU(&WaterCannonVertices[0], 0.0f); - RwIm3DVertexSetV(&WaterCannonVertices[0], 0.0f); - - RwIm3DVertexSetU(&WaterCannonVertices[1], 1.0f); - RwIm3DVertexSetV(&WaterCannonVertices[1], 0.0f); - - RwIm3DVertexSetU(&WaterCannonVertices[2], 0.0f); - RwIm3DVertexSetV(&WaterCannonVertices[2], 0.0f); - - RwIm3DVertexSetU(&WaterCannonVertices[3], 1.0f); - RwIm3DVertexSetV(&WaterCannonVertices[3], 0.0f); - - WaterCannonIndexList[0] = 0; - WaterCannonIndexList[1] = 1; - WaterCannonIndexList[2] = 2; - - WaterCannonIndexList[3] = 1; - WaterCannonIndexList[4] = 3; - WaterCannonIndexList[5] = 2; - - WaterCannonIndexList[6] = 0; - WaterCannonIndexList[7] = 2; - WaterCannonIndexList[8] = 1; - - WaterCannonIndexList[9] = 1; - WaterCannonIndexList[10] = 2; - WaterCannonIndexList[11] = 3; -} - -void CWaterCannon::Update_OncePerFrame(int16 index) -{ - ASSERT(index < NUM_WATERCANNONS); - - if (CTimer::GetTimeInMilliseconds() > m_nTimeCreated + WATERCANNON_LIFETIME ) - { - m_nCur = (m_nCur + 1) % NUM_SEGMENTPOINTS; - m_abUsed[m_nCur] = false; - } - - for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ ) - { - if ( m_abUsed[i] ) - { - m_avecVelocity[i].z += -WATERCANNON_GRAVITY * CTimer::GetTimeStep(); - m_avecPos[i] += m_avecVelocity[i] * CTimer::GetTimeStep(); - } - } - - for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ ) - { - if ( m_abUsed[i] && gFireManager.ExtinguishPointWithWater(m_avecPos[i], 4.0f) ) - { - break; - } - } - - if ( ((index + CTimer::GetFrameCounter()) & 3) == 0 ) - PushPeds(); - - // free if unused - - int32 i = 0; - while ( 1 ) - { - if ( m_abUsed[i] ) - break; - - if ( ++i >= NUM_SEGMENTPOINTS ) - { - m_nId = 0; - return; - } - } -} - -void CWaterCannon::Update_NewInput(CVector *pos, CVector *dir) -{ - ASSERT(pos != NULL); - ASSERT(dir != NULL); - - m_avecPos[m_nCur] = *pos; - m_avecVelocity[m_nCur] = *dir; - m_abUsed[m_nCur] = true; -} - -void CWaterCannon::Render(void) -{ - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterRaster); - - float v = float(CGeneral::GetRandomNumber() & 255) / 256; - - RwIm3DVertexSetV(&WaterCannonVertices[0], v); - RwIm3DVertexSetV(&WaterCannonVertices[1], v); - RwIm3DVertexSetV(&WaterCannonVertices[2], v); - RwIm3DVertexSetV(&WaterCannonVertices[3], v); - - int16 pointA = m_nCur % NUM_SEGMENTPOINTS; - - int16 pointB = pointA - 1; - if ( pointB < 0 ) - pointB += NUM_SEGMENTPOINTS; - - bool bInit = false; - CVector norm; - - for ( int32 i = 0; i < NUM_SEGMENTPOINTS - 1; i++ ) - { - if ( m_abUsed[pointA] && m_abUsed[pointB] ) - { - if ( !bInit ) - { - CVector cp = CrossProduct(m_avecPos[pointB] - m_avecPos[pointA], TheCamera.GetForward()); - norm = cp * (0.05f / cp.Magnitude()); - bInit = true; - } - - float dist = float(i*i*i) / 300.0f + 1.0f; - float brightness = float(i) / NUM_SEGMENTPOINTS; - - int32 color = (int32)((1.0f - brightness*brightness) * 255.0f); - CVector offset = dist * norm; - - RwIm3DVertexSetRGBA(&WaterCannonVertices[0], color, color, color, color); - RwIm3DVertexSetPos (&WaterCannonVertices[0], m_avecPos[pointA].x - offset.x, m_avecPos[pointA].y - offset.y, m_avecPos[pointA].z - offset.z); - - RwIm3DVertexSetRGBA(&WaterCannonVertices[1], color, color, color, color); - RwIm3DVertexSetPos (&WaterCannonVertices[1], m_avecPos[pointA].x + offset.x, m_avecPos[pointA].y + offset.y, m_avecPos[pointA].z + offset.z); - - RwIm3DVertexSetRGBA(&WaterCannonVertices[2], color, color, color, color); - RwIm3DVertexSetPos (&WaterCannonVertices[2], m_avecPos[pointB].x - offset.x, m_avecPos[pointB].y - offset.y, m_avecPos[pointB].z - offset.z); - - RwIm3DVertexSetRGBA(&WaterCannonVertices[3], color, color, color, color); - RwIm3DVertexSetPos (&WaterCannonVertices[3], m_avecPos[pointB].x + offset.x, m_avecPos[pointB].y + offset.y, m_avecPos[pointB].z + offset.z); - - LittleTest(); - - if ( RwIm3DTransform(WaterCannonVertices, WATERCANNONVERTS, NULL, rwIM3D_VERTEXUV) ) - { - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, WaterCannonIndexList, WATERCANNONINDEXES); - RwIm3DEnd(); - } - } - - pointA = pointB--; - if ( pointB < 0 ) - pointB += NUM_SEGMENTPOINTS; - } - - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE); -} - -void CWaterCannon::PushPeds(void) -{ - float minx = 10000.0f; - float maxx = -10000.0f; - float miny = 10000.0f; - float maxy = -10000.0f; - float minz = 10000.0f; - float maxz = -10000.0f; - - for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ ) - { - if ( m_abUsed[i] ) - { - minx = Min(minx, m_avecPos[i].x); - maxx = Max(maxx, m_avecPos[i].x); - - miny = Min(miny, m_avecPos[i].y); - maxy = Max(maxy, m_avecPos[i].y); - - minz = Min(minz, m_avecPos[i].z); - maxz = Max(maxz, m_avecPos[i].z); - } - } - - for ( int32 i = CPools::GetPedPool()->GetSize() - 1; i >= 0; i--) - { - CPed *ped = CPools::GetPedPool()->GetSlot(i); - if ( ped ) - { - if ( ped->GetPosition().x > minx && ped->GetPosition().x < maxx - && ped->GetPosition().y > miny && ped->GetPosition().y < maxy - && ped->GetPosition().z > minz && ped->GetPosition().z < maxz ) - { - for ( int32 j = 0; j < NUM_SEGMENTPOINTS; j++ ) - { - if ( m_abUsed[j] ) - { - CVector dist = m_avecPos[j] - ped->GetPosition(); - - if ( dist.MagnitudeSqr() < 5.0f ) - { - int32 localDir = ped->GetLocalDirection(CVector2D(1.0f, 0.0f)); - - ped->bIsStanding = false; - - ped->ApplyMoveForce(0.0f, 0.0f, 2.0f * CTimer::GetTimeStep()); - - ped->m_vecMoveSpeed.x = (0.6f * m_avecVelocity[j].x + ped->m_vecMoveSpeed.x) * 0.5f; - ped->m_vecMoveSpeed.y = (0.6f * m_avecVelocity[j].y + ped->m_vecMoveSpeed.y) * 0.5f; - - float pedSpeed2D = ped->m_vecMoveSpeed.Magnitude2D(); - - if ( pedSpeed2D > 0.2f ) { - ped->m_vecMoveSpeed.x *= (0.2f / pedSpeed2D); - ped->m_vecMoveSpeed.y *= (0.2f / pedSpeed2D); - } - ped->SetFall(2000, (AnimationId)(localDir + ANIM_STD_HIGHIMPACT_FRONT), 0); - CParticle::AddParticle(PARTICLE_STEAM_NY_SLOWMOTION, ped->GetPosition(), ped->m_vecMoveSpeed * 0.3f, 0, 0.5f); - CParticle::AddParticle(PARTICLE_CAR_SPLASH, ped->GetPosition(), ped->m_vecMoveSpeed * -0.3f + CVector(0.f, 0.f, 0.5f), 0, 0.5f, - CGeneral::GetRandomNumberInRange(0.f, 10.f), CGeneral::GetRandomNumberInRange(0.f, 90.f), 1); - - j = NUM_SEGMENTPOINTS; - } - } - } - } - } - } -} - -void CWaterCannons::Init(void) -{ - for ( int32 i = 0; i < NUM_WATERCANNONS; i++ ) - aCannons[i].Init(); -} - -void CWaterCannons::UpdateOne(uint32 id, CVector *pos, CVector *dir) -{ - ASSERT(pos != NULL); - ASSERT(dir != NULL); - - // find the one by id - { - int32 n = 0; - while ( n < NUM_WATERCANNONS && id != aCannons[n].m_nId ) - n++; - - if ( n < NUM_WATERCANNONS ) - { - aCannons[n].Update_NewInput(pos, dir); - return; - } - } - - // if no luck then find a free one - { - int32 n = 0; - while ( n < NUM_WATERCANNONS && 0 != aCannons[n].m_nId ) - n++; - - if ( n < NUM_WATERCANNONS ) - { - aCannons[n].Init(); - aCannons[n].m_nId = id; - aCannons[n].Update_NewInput(pos, dir); - return; - } - } -} - -void CWaterCannons::Update(void) -{ - for ( int32 i = 0; i < NUM_WATERCANNONS; i++ ) - { - if ( aCannons[i].m_nId != 0 ) - aCannons[i].Update_OncePerFrame(i); - } -} - -void CWaterCannons::Render(void) -{ - PUSH_RENDERGROUP("CWaterCannons::Render"); - for ( int32 i = 0; i < NUM_WATERCANNONS; i++ ) - { - if ( aCannons[i].m_nId != 0 ) - aCannons[i].Render(); - } - POP_RENDERGROUP(); -} diff --git a/src/render/WaterCannon.h b/src/render/WaterCannon.h deleted file mode 100644 index a37bdd12..00000000 --- a/src/render/WaterCannon.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#define WATERCANNON_GRAVITY (0.009f) -#define WATERCANNON_LIFETIME (150) - -class CWaterCannon -{ -public: - enum - { - NUM_SEGMENTPOINTS = 16, - }; - - int32 m_nId; - int16 m_nCur; - uint32 m_nTimeCreated; - CVector m_avecPos[NUM_SEGMENTPOINTS]; - CVector m_avecVelocity[NUM_SEGMENTPOINTS]; - bool m_abUsed[NUM_SEGMENTPOINTS]; - - void Init(void); - void Update_OncePerFrame(int16 index); - void Update_NewInput(CVector *pos, CVector *dir); - void Render(void); - void PushPeds(void); -}; - -VALIDATE_SIZE(CWaterCannon, 412); - -class CWaterCannons -{ -public: - static CWaterCannon aCannons[NUM_WATERCANNONS]; - - static void Init(void); - static void UpdateOne(uint32 id, CVector *pos, CVector *dir); - static void Update(); - static void Render(void); -}; \ No newline at end of file diff --git a/src/render/WaterCreatures.cpp b/src/render/WaterCreatures.cpp deleted file mode 100644 index 92fb74ee..00000000 --- a/src/render/WaterCreatures.cpp +++ /dev/null @@ -1,275 +0,0 @@ -#include "common.h" -#include "WaterCreatures.h" -#include "ModelIndices.h" -#include "World.h" -#include "WaterLevel.h" -#include "Camera.h" -#include "PlayerPed.h" -#include "General.h" -#include "Object.h" - -int CWaterCreatures::nNumActiveSeaLifeForms; -CWaterCreature CWaterCreatures::aWaterCreatures[NUM_WATER_CREATURES]; - -struct WaterCreatureProperties aProperties[65] = { - { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_JELLYFISH, 0.01f, 2.2f, 0.0005f, 3.5f }, - { &MI_JELLYFISH01, 0.01f, 2.2f, 0.0005f, 3.5f }, - { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_TURTLE, 0.01f, 2.0f, 0.0005f, 4.0f }, - { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_DOLPHIN, 0.03f, 1.5f, 0.0005f, 4.0f }, - { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_SHARK, 0.03f, 0.4f, 0.0005f, 4.0f }, - { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, - { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, - { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, -}; - -CWaterCreature::CWaterCreature() { - Free(); -} - -void CWaterCreature::Initialise(CObject *pObj, float fFwdSpeed, float fZTurnSpeed, float fWaterDepth, uint32 alpha, eFishSlotState state) { - this->m_pObj = pObj; - this->m_fFwdSpeed = fFwdSpeed; - this->m_fZTurnSpeed = fZTurnSpeed; - this->m_fWaterDepth = fWaterDepth; - this->m_alpha = alpha; - this->m_state = state; -} - -void CWaterCreature::Allocate(CObject *pObj, float fFwdSpeed, float fZTurnSpeed, float fWaterDepth, uint32 alpha, eFishSlotState state) { - CWaterCreature::Initialise(pObj, fFwdSpeed, fZTurnSpeed, fWaterDepth, alpha, state); -} - -void CWaterCreature::Free() { - CWaterCreature::Initialise(nil, 0.0f, 0.0f, 0.0f, 0, WATER_CREATURE_DISABLED); -} - -CWaterCreature *CWaterCreatures::GetFishStructSlot() { - for (int i = 0; i < NUM_WATER_CREATURES; i++) - if (aWaterCreatures[i].m_state == WATER_CREATURE_DISABLED) - return &aWaterCreatures[i]; - - return nil; -} - -CObject *CWaterCreatures::CreateSeaLifeForm(CVector const& pos, int16 modelID, int32 zRotAngle) { - if (CObject::nNoTempObjects >= NUMTEMPOBJECTS) - return nil; - - CObject *pObj = new CObject(modelID, true); - - if (!pObj) return nil; - - pObj->SetPosition(pos); - pObj->GetMatrix().UpdateRW(); - pObj->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); - pObj->m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); - pObj->GetMatrix().SetRotateZOnly(DEGTORAD(zRotAngle)); - pObj->GetMatrix().UpdateRW(); - pObj->ObjectCreatedBy = CONTROLLED_SUB_OBJECT; - pObj->bIsStatic = false; - - if (pObj->ObjectCreatedBy == TEMP_OBJECT) { - CObject::nNoTempObjects++; - pObj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 60000; - } - - pObj->bTouchingWater = true; - pObj->bUnderwater = true; - CWorld::Add(pObj); - - return pObj; -} - -bool CWaterCreatures::IsSpaceForMoreWaterCreatures() { - return nNumActiveSeaLifeForms < NUM_WATER_CREATURES; -} - -float CWaterCreatures::CalculateFishHeading(CVector const& pos1, CVector const& pos2) { - CVector delta = pos1 - pos2; - delta.Normalise(); - - return CGeneral::GetRandomNumberInRange(-90, 90) + - RADTODEG(delta.Heading() + HALFPI + PI); -} - -void CWaterCreatures::CreateOne(CVector const& pos, int32 modelID) { - if (!IsSpaceForMoreWaterCreatures()) - return; - - CVector playerPos = FindPlayerPed()->GetPosition(); - CVector fishPos = pos; - float fDepth, fLevelNoWaves; - if (!TheCamera.IsSphereVisible(fishPos, 3.0f) - && CWaterLevel::GetWaterDepth(fishPos, &fDepth, &fLevelNoWaves, nil) && fDepth > 4.5f) { - - if (modelID == -1 || modelID < 0 || modelID > 64) - modelID = CGeneral::GetRandomNumberInRange(0, 64); - - WaterCreatureProperties *creature = &aProperties[modelID]; - fishPos.z = fLevelNoWaves - creature->fLevel; - float fFwdSpeed = CGeneral::GetRandomNumberInRange(0.0f, creature->fFwdSpeed) + 0.01f; - float angle = CWaterCreatures::CalculateFishHeading(playerPos, fishPos); - - CObject *fish = CreateSeaLifeForm(fishPos, *creature->modelID, angle); - if (!fish) return; - - fish->SetRwObjectAlpha(255); - CWaterCreature *wc = GetFishStructSlot(); - wc->Allocate(fish, fFwdSpeed, 0.0f, creature->fWaterDepth, 255, WATER_CREATURE_INIT); - nNumActiveSeaLifeForms++; - } -} - -void CWaterCreatures::FreeFishStructSlot(CWaterCreature *wc) { - wc->Free(); -} - -void CWaterCreatures::UpdateAll() { - if (nNumActiveSeaLifeForms == 0) - return; - - CVector playerPos = FindPlayerPed()->GetPosition(); - for (int i = 0; i < NUM_WATER_CREATURES; i++) { - switch (aWaterCreatures[i].m_state) { - case WATER_CREATURE_ACTIVE: - // is this even reachable? - aWaterCreatures[i].m_pObj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 40000; - if (!aWaterCreatures[i].m_pObj->GetIsOnScreen()) { - aWaterCreatures[i].m_pObj->SetRwObjectAlpha(0); - aWaterCreatures[i].m_state = WATER_CREATURE_REMOVE; - break; - } - // fall through - case WATER_CREATURE_INIT: { - if ((playerPos - aWaterCreatures[i].m_pObj->GetPosition()).MagnitudeSqr() < SQR(75.0f)) { - if (aWaterCreatures[i].m_alpha < 255) - aWaterCreatures[i].m_alpha = Min(aWaterCreatures[i].m_alpha + 4, 255); - aWaterCreatures[i].m_pObj->SetRwObjectAlpha(aWaterCreatures[i].m_alpha); - CVector fwd = aWaterCreatures[i].m_pObj->GetRight(); // for some reason they used x for forward - fwd.Normalise(); - aWaterCreatures[i].m_pObj->m_vecMoveSpeed = fwd * aWaterCreatures[i].m_fFwdSpeed; - aWaterCreatures[i].m_pObj->m_vecTurnSpeed = CVector(0.0f, 0.0f, aWaterCreatures[i].m_fZTurnSpeed); - aWaterCreatures[i].m_pObj->bIsStatic = false; - float fDepth = 0.0; - CWaterLevel::GetWaterDepth(aWaterCreatures[i].m_pObj->GetPosition(), &fDepth, nil, nil); - if (aWaterCreatures[i].m_fWaterDepth < fDepth) { - // it looks like this can never be true initially, looks like a BUG - if (aWaterCreatures[i].m_pObj->m_nEndOfLifeTime - 40000 <= CTimer::GetTimeInMilliseconds()) - aWaterCreatures[i].m_state = WATER_CREATURE_ACTIVE; - } - else { - // creature is deeper than water - aWaterCreatures[i].m_state = WATER_CREATURE_FADE_OUT; - } - - } - else { - aWaterCreatures[i].m_state = WATER_CREATURE_REMOVE; - } - break; - } - case WATER_CREATURE_FADE_OUT: { - aWaterCreatures[i].m_pObj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 40000; - if (aWaterCreatures[i].m_alpha <= 0) { - aWaterCreatures[i].m_state = WATER_CREATURE_REMOVE; - } - else { - aWaterCreatures[i].m_alpha = Max(aWaterCreatures[i].m_alpha - 6, 0); - aWaterCreatures[i].m_pObj->SetRwObjectAlpha(aWaterCreatures[i].m_alpha); - CVector speed = aWaterCreatures[i].m_pObj->GetRight(); - speed.Normalise(); - speed.x *= aWaterCreatures[i].m_fFwdSpeed; - speed.y *= aWaterCreatures[i].m_fFwdSpeed; - speed.z = -0.015f; - aWaterCreatures[i].m_pObj->m_vecMoveSpeed = speed; - - if (!aWaterCreatures[i].m_pObj->GetIsOnScreen()) - aWaterCreatures[i].m_state = WATER_CREATURE_REMOVE; - } - break; - } - case WATER_CREATURE_REMOVE: - if (aWaterCreatures[i].m_pObj){ - CWorld::Remove(aWaterCreatures[i].m_pObj); - delete aWaterCreatures[i].m_pObj; - } - FreeFishStructSlot(&aWaterCreatures[i]); - nNumActiveSeaLifeForms--; - aWaterCreatures[i].m_state = WATER_CREATURE_DISABLED; - break; - default: - break; - } - } -} - -void CWaterCreatures::RemoveAll() { - for (int i = 0; i < NUM_WATER_CREATURES; i++) { - if (aWaterCreatures[i].m_state != WATER_CREATURE_DISABLED) { - if (aWaterCreatures[i].m_pObj){ - CWorld::Remove(aWaterCreatures[i].m_pObj); - delete aWaterCreatures[i].m_pObj; - } - FreeFishStructSlot(&aWaterCreatures[i]); - aWaterCreatures[i].m_state = WATER_CREATURE_DISABLED; - nNumActiveSeaLifeForms--; - } - } -} \ No newline at end of file diff --git a/src/render/WaterCreatures.h b/src/render/WaterCreatures.h deleted file mode 100644 index 32754a10..00000000 --- a/src/render/WaterCreatures.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -class CObject; - -enum eFishSlotState { - WATER_CREATURE_INIT = 0, - WATER_CREATURE_ACTIVE, - WATER_CREATURE_FADE_OUT, - WATER_CREATURE_REMOVE, - WATER_CREATURE_DISABLED -}; - -class CWaterCreature { -public: - CObject *m_pObj; - float m_fFwdSpeed; - float m_fZTurnSpeed; - int32 m_alpha; - float m_fWaterDepth; - int32 m_state; - - CWaterCreature(); - void Allocate(CObject *pObj, float fFwdSpeed, float fZTurnSpeed, float fWaterDepth, uint32 alpha, eFishSlotState state); - void Free(); - void Initialise(CObject *pObj, float fFwdSpeed, float fZTurnSpeed, float fWaterDepth, uint32 alpha, eFishSlotState state); -}; - -class CWaterCreatures { - -public: - static CWaterCreature aWaterCreatures[NUM_WATER_CREATURES]; - static int32 nNumActiveSeaLifeForms; - static CObject *CreateSeaLifeForm(CVector const& pos, int16 modelID, int32 zRotAngle); - static void CreateOne(CVector const& pos, int32 modelID); - static void UpdateAll(); - static void FreeFishStructSlot(CWaterCreature *wc); - static bool IsSpaceForMoreWaterCreatures(); - static float CalculateFishHeading(CVector const& pos1, CVector const& pos2); - static void RemoveAll(); - static CWaterCreature* GetFishStructSlot(); -}; - -struct WaterCreatureProperties { - int16 *modelID; - float fFwdSpeed; - float fLevel; - float fUnknown; //unused - float fWaterDepth; -}; \ No newline at end of file diff --git a/src/render/WaterLevel.cpp b/src/render/WaterLevel.cpp deleted file mode 100644 index dee60d66..00000000 --- a/src/render/WaterLevel.cpp +++ /dev/null @@ -1,3377 +0,0 @@ -#include "common.h" -#include "main.h" -#include "FileMgr.h" -#include "FileLoader.h" -#include "TxdStore.h" -#include "Timer.h" -#include "Weather.h" -#include "Camera.h" -#include "Vehicle.h" -#include "PlayerPed.h" -#include "Boat.h" -#include "World.h" -#include "General.h" -#include "Timecycle.h" -#include "ZoneCull.h" -#include "Clock.h" -#include "Particle.h" -#include "ParticleMgr.h" -#include "RwHelper.h" -#include "Streaming.h" -#include "ColStore.h" -#include "CdStream.h" -#include "Pad.h" -#include "RenderBuffer.h" -#include -#include -#include -#include "Occlusion.h" -#include "Replay.h" -#include "WaterLevel.h" -#include "SurfaceTable.h" -#include "WaterCreatures.h" - -#define RwIm3DVertexSet_RGBA(vert, rgba) RwIm3DVertexSetRGBA(vert, rgba.red, rgba.green, rgba.blue, rgba.alpha) // (RwRGBAAssign(&(_dst)->color, &_src)) - -float TEXTURE_ADDU; -float TEXTURE_ADDV; - -float _TEXTURE_MASK_ADDU; -float _TEXTURE_MASK_ADDV; - -float _TEXTURE_WAKE_ADDU; -float _TEXTURE_WAKE_ADDV; - -int32 CWaterLevel::ms_nNoOfWaterLevels; -float CWaterLevel::ms_aWaterZs[48]; -CRect CWaterLevel::ms_aWaterRects[48]; -int8 CWaterLevel::aWaterBlockList[MAX_LARGE_SECTORS][MAX_LARGE_SECTORS]; -int8 CWaterLevel::aWaterFineBlockList[MAX_SMALL_SECTORS][MAX_SMALL_SECTORS]; -bool CWaterLevel::WavesCalculatedThisFrame; - - -bool CWaterLevel::RequireWavySector; -bool CWaterLevel::MaskCalculatedThisFrame; -CVector CWaterLevel::PreCalculatedMaskPosn; -bool CWaterLevel::m_bRenderSeaBed; -int32 CWaterLevel::m_nRenderWaterLayers; - -RpAtomic *CWaterLevel::ms_pWavyAtomic; -RpAtomic *CWaterLevel::ms_pMaskAtomic; -//"Custom" Don't Render Water Toggle -bool gbDontRenderWater; - - -RwTexture *gpWaterTex; -RwTexture *gpWaterEnvTex; -RwTexture *gpWaterEnvBaseTex; -RwTexture *gpWaterWakeTex; - -RwRaster *gpWaterRaster; -RwRaster *gpWaterEnvRaster; -RwRaster *gpWaterEnvBaseRaster; -RwRaster *gpWaterWakeRaster; - -bool _bSeaLife; -float _fWaterZOffset = WATER_Z_OFFSET; - -#ifdef PC_WATER -float fEnvScale = 0.25f; -#else -float fEnvScale = 0.5f; -#endif -float fWave2InvLength = 0.03f; -float fWave2NormScale = 0.5f; -float fWave2Ampl = 0.1f; -uint8 nWaterAlpha = 192; -uint8 nWakeAlpha = 192; -float fUnder1 = 4.0; -float fUnder2 = 2.5; -float fUnder3 = 1.5; -int nMaskAlpha = 230; -float fAdd1 = 180.0f; -float fAdd2 = 80.0; -float fRedMult = 0.6f; -float fGreenMult = 1.0f; -float fBlueMult = 1.4f; -float fAlphaMult = 500.0f; -float fAlphaBase = 30.0f; -float fRandomMoveDiv = 8.0f; -float fRandomDamp = 0.99f; -float fNormMult = 2.0f; -float fNormMultB = 1.0f; -float fBumpScale = 1.5; -float fBumpTexRepeat = 2.0; -float fNormalDirectionScalar1 = 2.0f; -float fNormalDirectionScalar2 = 1.0f; -bool bTestDoNormals = true; -float fSeaBedZ = 25.0f; -float aAlphaFade[5] = { 0.4f, 1.0f, 0.2f, 1.0f, 0.4f}; //CWaterLevel::RenderWakeSegment -float fFlatWaterBlendRange = 0.05f; -float fStartBlendDistanceAdd = 64.0f; -float fMinWaterAlphaMult = -30.0f; - - -void -CWaterLevel::Initialise(Const char *pWaterDat) -{ - ms_nNoOfWaterLevels = 0; - -#ifdef MASTER - int32 hFile = -1; - - do - { - hFile = CFileMgr::OpenFile("DATA\\waterpro.dat", "rb"); - } - while ( hFile < 0 ); -#else - int32 hFile = CFileMgr::OpenFile("DATA\\waterpro.dat", "rb"); -#endif - - if (hFile > 0) - { - CFileMgr::Read(hFile, (char *)&ms_nNoOfWaterLevels, sizeof(ms_nNoOfWaterLevels)); - CFileMgr::Read(hFile, (char *)ms_aWaterZs, sizeof(ms_aWaterZs)); - CFileMgr::Read(hFile, (char *)ms_aWaterRects, sizeof(ms_aWaterRects)); - CFileMgr::Read(hFile, (char *)aWaterBlockList, sizeof(aWaterBlockList)); - CFileMgr::Read(hFile, (char *)aWaterFineBlockList, sizeof(aWaterFineBlockList)); - CFileMgr::CloseFile(hFile); - } -#ifndef MASTER - else - { - printf("Init waterlevels\n"); - - // collision is streamed in VC - CColStore::LoadAllCollision(); - - CFileMgr::SetDir(""); - hFile = CFileMgr::OpenFile(pWaterDat, "r"); - - char *line; - - while ((line = CFileLoader::LoadLine(hFile))) - { - if (*line && *line != ';' && !strstr(line, "* ;end of file")) - { - float z, l, b, r, t; - sscanf(line, "%f %f %f %f %f", &z, &l, &b, &r, &t); - AddWaterLevel(l, b, r, t, z); - } - } - - CFileMgr::CloseFile(hFile); - - for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) - { - for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) - { - aWaterFineBlockList[x][y] = NO_WATER; - } - } - - // rasterize water rects read from file - for (int32 i = 0; i < ms_nNoOfWaterLevels; i++) - { - int32 l = WATER_HUGE_X(ms_aWaterRects[i].left + WATER_X_OFFSET); - int32 r = WATER_HUGE_X(ms_aWaterRects[i].right + WATER_X_OFFSET) + 1.0f; - int32 t = WATER_HUGE_Y(ms_aWaterRects[i].top); - int32 b = WATER_HUGE_Y(ms_aWaterRects[i].bottom) + 1.0f; - - l = Clamp(l, 0, MAX_SMALL_SECTORS - 1); - r = Clamp(r, 0, MAX_SMALL_SECTORS - 1); - t = Clamp(t, 0, MAX_SMALL_SECTORS - 1); - b = Clamp(b, 0, MAX_SMALL_SECTORS - 1); - - for (int32 x = l; x <= r; x++) - { - for (int32 y = t; y <= b; y++) - { - aWaterFineBlockList[x][y] = i; - } - } - } - - // remove tiles that are obscured by land - for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) - { - float worldX = WATER_START_X + x * SMALL_SECTOR_SIZE - WATER_X_OFFSET; - - for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) - { - if (CWaterLevel::aWaterFineBlockList[x][y] >= 0) - { - float worldY = WATER_START_Y + y * SMALL_SECTOR_SIZE; - - int32 i; - for (i = 0; i <= 8; i++) - { - for (int32 j = 0; j <= 8; j++) - { - CVector worldPos = CVector(worldX + i * (SMALL_SECTOR_SIZE / 8), worldY + j * (SMALL_SECTOR_SIZE / 8), ms_aWaterZs[aWaterFineBlockList[x][y]]); - - if ((worldPos.x > WORLD_MIN_X && worldPos.x < WORLD_MAX_X) && (worldPos.y > WORLD_MIN_Y && worldPos.y < WORLD_MAX_Y) && - (!WaterLevelAccordingToRectangles(worldPos.x, worldPos.y) || TestVisibilityForFineWaterBlocks(worldPos))) - continue; - - // at least one point in the tile wasn't blocked, so don't remove water - i = 1000; - break; - } - } - - if (i < 1000) - aWaterFineBlockList[x][y] = NO_WATER; - } - } - } - - RemoveIsolatedWater(); - - // calculate coarse tiles from fine tiles - for (int32 x = 0; x < MAX_LARGE_SECTORS; x++) - { - for (int32 y = 0; y < MAX_LARGE_SECTORS; y++) - { - if (aWaterFineBlockList[x * 2][y * 2] >= 0) - { - aWaterBlockList[x][y] = aWaterFineBlockList[x * 2][y * 2]; - } - else if (aWaterFineBlockList[x * 2 + 1][y * 2] >= 0) - { - aWaterBlockList[x][y] = aWaterFineBlockList[x * 2 + 1][y * 2]; - } - else if (aWaterFineBlockList[x * 2][y * 2 + 1] >= 0) - { - aWaterBlockList[x][y] = aWaterFineBlockList[x * 2][y * 2 + 1]; - } - else if (aWaterFineBlockList[x * 2 + 1][y * 2 + 1] >= 0) - { - aWaterBlockList[x][y] = aWaterFineBlockList[x * 2 + 1][y * 2 + 1]; - } - else - { - aWaterBlockList[x][y] = NO_WATER; - } - } - } - - hFile = CFileMgr::OpenFileForWriting("data\\waterpro.dat"); - - if (hFile > 0) - { - CFileMgr::Write(hFile, (char *)&ms_nNoOfWaterLevels, sizeof(ms_nNoOfWaterLevels)); - CFileMgr::Write(hFile, (char *)ms_aWaterZs, sizeof(ms_aWaterZs)); - CFileMgr::Write(hFile, (char *)ms_aWaterRects, sizeof(ms_aWaterRects)); - CFileMgr::Write(hFile, (char *)aWaterBlockList, sizeof(aWaterBlockList)); - CFileMgr::Write(hFile, (char *)aWaterFineBlockList, sizeof(aWaterFineBlockList)); - - CFileMgr::CloseFile(hFile); - } - - // collision is streamed in VC - CColStore::RemoveAllCollision(); - } -#endif - - CTxdStore::PushCurrentTxd(); - - int32 slot = CTxdStore::FindTxdSlot("particle"); - CTxdStore::SetCurrentTxd(slot); - - if ( gpWaterTex == nil ) - gpWaterTex = RwTextureRead("waterclear256", nil); - gpWaterRaster = RwTextureGetRaster(gpWaterTex); - - if ( gpWaterEnvTex == nil ) - gpWaterEnvTex = RwTextureRead("waterreflection2", nil); - gpWaterEnvRaster = RwTextureGetRaster(gpWaterEnvTex); - -#ifdef PC_WATER - if ( gpWaterEnvBaseTex == nil ) - gpWaterEnvBaseTex = RwTextureRead("sandywater", nil); - gpWaterEnvBaseRaster = RwTextureGetRaster(gpWaterEnvBaseTex); -#endif - - if ( gpWaterWakeTex == nil ) - gpWaterWakeTex = RwTextureRead("waterwake", nil); - gpWaterWakeRaster = RwTextureGetRaster(gpWaterWakeTex); - - CTxdStore::PopCurrentTxd(); - - CreateWavyAtomic(); - - printf("Done Initing waterlevels\n"); -} - -void -CWaterLevel::Shutdown() -{ - DestroyWavyAtomic(); - -#define _DELETE_TEXTURE(t) if ( t ) \ - { \ - RwTextureDestroy(t); \ - t = nil; \ - } - - _DELETE_TEXTURE(gpWaterTex); - _DELETE_TEXTURE(gpWaterEnvTex); - _DELETE_TEXTURE(gpWaterWakeTex); - _DELETE_TEXTURE(gpWaterEnvBaseTex); - -#undef _DELETE_TEXTURE -} - -void -CWaterLevel::CreateWavyAtomic() -{ - RpGeometry *wavyGeometry; - RpGeometry *maskGeometry; - RpMaterial *wavyMaterial; - RpMaterial *maskMaterial; - - RpTriangle *wavytlist; - RpTriangle *masktlist; - - RpMorphTarget *wavyMorphTarget; - RpMorphTarget *maskMorphTarget; - - RwSphere boundingSphere; - - RwV3d *wavyVert; - RwV3d *wavyNormal; - - RwV3d *maskVert; - RwV3d *maskNormal; - - RwFrame *wavyFrame; - RwFrame *maskFrame; - - { - wavyGeometry = RpGeometryCreate(17*17, 512, rpGEOMETRYTRISTRIP - |rpGEOMETRYTEXTURED - |rpGEOMETRYPRELIT - |rpGEOMETRYNORMALS - |rpGEOMETRYMODULATEMATERIALCOLOR); -#ifdef PC_WATER - RpGeometryAddMorphTarget(wavyGeometry); -#endif - } - - { - maskGeometry = RpGeometryCreate(33*33, 2048, rpGEOMETRYTRISTRIP - |rpGEOMETRYTEXTURED - |rpGEOMETRYPRELIT - |rpGEOMETRYNORMALS - |rpGEOMETRYMODULATEMATERIALCOLOR); -#ifdef PC_WATER - RpGeometryAddMorphTarget(maskGeometry); -#endif - } - - { - wavyMaterial = RpMaterialCreate(); - RpMaterialSetTexture(wavyMaterial, gpWaterTex); - RwRGBA watercolor = { 255, 255, 255, 192 }; - RpMaterialSetColor(wavyMaterial, &watercolor); - } - - { - maskMaterial = RpMaterialCreate(); -#ifdef PC_WATER - RpMaterialSetTexture(maskMaterial, gpWaterEnvBaseTex); -#else - RpMaterialSetTexture(maskMaterial, gpWaterTex); -#endif - RwRGBA watercolor = { 255, 255, 255, 192 }; - RpMaterialSetColor(maskMaterial, &watercolor); - } - - { - wavytlist = RpGeometryGetTriangles(wavyGeometry); - - for ( int32 i = 0; i < 16; i++ ) - { - for ( int32 j = 0; j < 16; j++ ) - { - const RwUInt16 base = (RwUInt16)((16 + 1)*i+j); - - RpGeometryTriangleSetVertexIndices(wavyGeometry, - wavytlist, (RwInt16)base, (RwInt16)(base+1), (RwInt16)(base+16+2)); - - RpGeometryTriangleSetVertexIndices(wavyGeometry, - (wavytlist+1), (RwInt16)base, (RwInt16)(base+16+2), (RwInt16)(base+16+1)); - - RpGeometryTriangleSetMaterial(wavyGeometry, wavytlist, wavyMaterial); - - RpGeometryTriangleSetMaterial(wavyGeometry, (wavytlist+1), wavyMaterial); - - wavytlist+=2; - } - } - } - - { - masktlist = RpGeometryGetTriangles(maskGeometry); - - for ( int32 i = 0; i < 32; i++ ) - { - for ( int32 j = 0; j < 32; j++ ) - { - const RwUInt16 base = (RwUInt16)((32 + 1)*i+j); - - RpGeometryTriangleSetVertexIndices(maskGeometry, - masktlist, (RwInt16)base, (RwInt16)(base+1), (RwInt16)(base+32+2)); - - RpGeometryTriangleSetVertexIndices(maskGeometry, - (masktlist+1), (RwInt16)base, (RwInt16)(base+32+2), (RwInt16)(base+32+1)); - - RpGeometryTriangleSetMaterial(maskGeometry, masktlist, maskMaterial); - - RpGeometryTriangleSetMaterial(maskGeometry, (masktlist+1), maskMaterial); - - masktlist+=2; - } - } - } - - { - wavyMorphTarget = RpGeometryGetMorphTarget(wavyGeometry, 0); - wavyVert = RpMorphTargetGetVertices(wavyMorphTarget); - wavyNormal = RpMorphTargetGetVertexNormals(wavyMorphTarget); - - for ( int32 i = 0; i < 17; i++ ) - { - for ( int32 j = 0; j < 17; j++ ) - { - (*wavyVert).x = (float)i * 2.0f; - (*wavyVert).y = (float)j * 2.0f; - (*wavyVert).z = 0.0f; - - (*wavyNormal).x = 0.0f; - (*wavyNormal).y = 0.0f; - (*wavyNormal).z = 1.0f; - - wavyVert++; - wavyNormal++; - } - } - - RpMorphTargetCalcBoundingSphere(wavyMorphTarget, &boundingSphere); - RpMorphTargetSetBoundingSphere(wavyMorphTarget, &boundingSphere); - RpGeometryUnlock(wavyGeometry); - } - - { - maskMorphTarget = RpGeometryGetMorphTarget(maskGeometry, 0); - maskVert = RpMorphTargetGetVertices(maskMorphTarget); - maskNormal = RpMorphTargetGetVertexNormals(maskMorphTarget); - - for ( int32 i = 0; i < 33; i++ ) - { - for ( int32 j = 0; j < 33; j++ ) - { - (*maskVert).x = (float)i * 2.0f; - (*maskVert).y = (float)j * 2.0f; - (*maskVert).z = 0.0f; - - (*maskNormal).x = 0.0f; - (*maskNormal).y = 0.0f; - (*maskNormal).z = 1.0f; - - maskVert++; - maskNormal++; - } - } - - RpMorphTargetCalcBoundingSphere(maskMorphTarget, &boundingSphere); - RpMorphTargetSetBoundingSphere(maskMorphTarget, &boundingSphere); - RpGeometryUnlock(maskGeometry); - } - - { - wavyFrame = RwFrameCreate(); - ms_pWavyAtomic = RpAtomicCreate(); - RpAtomicSetGeometry(ms_pWavyAtomic, wavyGeometry, 0); - RpAtomicSetFrame(ms_pWavyAtomic, wavyFrame); - RpMaterialDestroy(wavyMaterial); - RpGeometryDestroy(wavyGeometry); - } - - { - maskFrame = RwFrameCreate(); - ms_pMaskAtomic = RpAtomicCreate(); - RpAtomicSetGeometry(ms_pMaskAtomic, maskGeometry, 0); - RpAtomicSetFrame(ms_pMaskAtomic, maskFrame); - RpMaterialDestroy(maskMaterial); - RpGeometryDestroy(maskGeometry); - } - - static RwFrame *wakeEnvFrame; - - if ( wakeEnvFrame == nil ) - { - wakeEnvFrame = RwFrameCreate(); - RwMatrixSetIdentity(RwFrameGetMatrix(wakeEnvFrame)); - RwFrameUpdateObjects(wakeEnvFrame); - } - - RpMatFXMaterialSetEffects(maskMaterial, rpMATFXEFFECTENVMAP); - RpMatFXMaterialSetupEnvMap(maskMaterial, gpWaterEnvTex, wakeEnvFrame, TRUE, fEnvScale); - RpMatFXAtomicEnableEffects(ms_pMaskAtomic); -} - -void -CWaterLevel::DestroyWavyAtomic() -{ -#define _DELETE_ATOMIC(a) \ - { \ - RwFrame *frame; \ - frame = RpAtomicGetFrame(a); \ - RpAtomicDestroy(a); \ - RwFrameDestroy(frame); \ - } - - _DELETE_ATOMIC(ms_pWavyAtomic); - _DELETE_ATOMIC(ms_pMaskAtomic); - -#undef _DELETE_ATOMIC -} - -#ifndef MASTER -void -CWaterLevel::AddWaterLevel(float fXLeft, float fYBottom, float fXRight, float fYTop, float fLevel) -{ - ms_aWaterRects[ms_nNoOfWaterLevels] = CRect(fXLeft, fYBottom, fXRight, fYTop); - ms_aWaterZs[ms_nNoOfWaterLevels] = fLevel; - ms_nNoOfWaterLevels++; -} - -bool -CWaterLevel::WaterLevelAccordingToRectangles(float fX, float fY, float *pfOutLevel) -{ - if (ms_nNoOfWaterLevels <= 0) return false; - - for (int32 i = 0; i < ms_nNoOfWaterLevels; i++) - { - if (fX >= ms_aWaterRects[i].left && fX <= ms_aWaterRects[i].right - && fY >= ms_aWaterRects[i].top && fY <= ms_aWaterRects[i].bottom) - { - if (pfOutLevel) *pfOutLevel = ms_aWaterZs[i]; - - return true; - } - } - - return false; -} - -bool -CWaterLevel::TestVisibilityForFineWaterBlocks(const CVector &worldPos) -{ - static CVector2D tab[] = - { - { 50.0f, 50.0f }, - { -50.0f, 50.0f }, - { -50.0f, -50.0f }, - { 50.0f, -50.0f }, - { 50.0f, 0.0f }, - { -50.0f, 0.0f }, - { 0.0f, -50.0f }, - { 0.0f, 50.0f }, - }; - - CEntity *entity; - CColPoint col; - CVector lineStart, lineEnd; - - lineStart = worldPos; - - if (!CWorld::ProcessVerticalLine(lineStart, lineStart.z + 100.0f, col, entity, true, false, false, false, true, false, nil)) - { - lineStart.x += 0.4f; - lineStart.y += 0.4f; - - if (!CWorld::ProcessVerticalLine(lineStart, lineStart.z + 100.0f, col, entity, true, false, false, false, true, false, nil)) - { - return false; - } - } - - for (int32 i = 0; i < ARRAY_SIZE(tab); i++) - { - lineStart = worldPos; - lineEnd = worldPos; - - lineEnd.x += tab[i].x; - lineEnd.y += tab[i].y; - lineEnd.z += 100.0f; - - if ((lineEnd.x > WORLD_MIN_X && lineEnd.x < WORLD_MAX_X) && (lineEnd.y > WORLD_MIN_Y && lineEnd.y < WORLD_MAX_Y)) - { - if (!CWorld::ProcessLineOfSight(lineStart, lineEnd, col, entity, true, false, false, false, true, false)) - { - lineStart.x += 0.4f; - lineStart.y += 0.4f; - lineEnd.x += 0.4f; - lineEnd.y += 0.4f; - - if (!CWorld::ProcessLineOfSight(lineStart, lineEnd, col, entity, true, false, false, false, true, false)) - { - return false; - } - } - } - } - - return true; -} - -void -CWaterLevel::RemoveIsolatedWater() -{ - bool (*isConnected)[MAX_SMALL_SECTORS] = new bool[MAX_SMALL_SECTORS][MAX_SMALL_SECTORS]; - - for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) - { - for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) - { - isConnected[x][y] = false; - } - } - - isConnected[0][0] = true; - bool keepGoing; - - do - { - keepGoing = false; - - for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) - { - for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) - { - if (aWaterFineBlockList[x][y] < 0 || isConnected[x][y]) - continue; - - if (x > 0 && isConnected[x - 1][y]) - { - isConnected[x][y] = true; - keepGoing = true; - } - - if (y > 0 && isConnected[x][y - 1]) - { - isConnected[x][y] = true; - keepGoing = true; - } - - if (x + 1 < MAX_SMALL_SECTORS && isConnected[x + 1][y]) - { - isConnected[x][y] = true; - keepGoing = true; - } - - if (y + 1 < MAX_SMALL_SECTORS && isConnected[x][y + 1]) - { - isConnected[x][y] = true; - keepGoing = true; - } - } - } - } - while (keepGoing); - - int32 numRemoved = 0; - - for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) - { - for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) - { - if (aWaterFineBlockList[x][y] >= 0 && !isConnected[x][y] && ms_aWaterZs[aWaterFineBlockList[x][y]] == 6.0f) - { - numRemoved++; - aWaterFineBlockList[x][y] = NO_WATER; - } - } - } - - printf("Removed %d isolated patches of water\n", numRemoved); - - delete[] isConnected; -} -#endif - -bool -CWaterLevel::GetWaterLevel(float fX, float fY, float fZ, float *pfOutLevel, bool bDontCheckZ) -{ - int32 x = WATER_TO_SMALL_SECTOR_X(fX + WATER_X_OFFSET); - int32 y = WATER_TO_SMALL_SECTOR_Y(fY); - -#ifdef FIX_BUGS - if ( x < 0 || x >= MAX_SMALL_SECTORS ) return false; - if ( y < 0 || y >= MAX_SMALL_SECTORS ) return false; -#endif - - int8 nBlock = aWaterFineBlockList[x][y]; - - if ( nBlock == NO_WATER ) - return false; - - ASSERT( pfOutLevel != nil ); - *pfOutLevel = ms_aWaterZs[nBlock]; - - float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); - - float fWave = Sin - ( - ( WATER_UNSIGN_Y(fY) - y*SMALL_SECTOR_SIZE - + WATER_UNSIGN_X(fX + WATER_X_OFFSET) - x*SMALL_SECTOR_SIZE ) - - * (TWOPI / SMALL_SECTOR_SIZE ) + fAngle - ); - - float fWindFactor = CWeather::WindClipped * 0.4f + 0.2f; - - *pfOutLevel += fWave * fWindFactor; - - if ( bDontCheckZ == false && (*pfOutLevel - fZ) > 3.0f ) - { - *pfOutLevel = 0.0f; - return false; - } - - return true; -} - -bool -CWaterLevel::GetWaterLevelNoWaves(float fX, float fY, float fZ, float *pfOutLevel) -{ - int32 x = WATER_TO_SMALL_SECTOR_X(fX + WATER_X_OFFSET); - int32 y = WATER_TO_SMALL_SECTOR_Y(fY); - -#ifdef FIX_BUGS - if ( x < 0 || x >= MAX_SMALL_SECTORS ) return false; - if ( y < 0 || y >= MAX_SMALL_SECTORS ) return false; -#endif - - int8 nBlock = aWaterFineBlockList[x][y]; - - if ( nBlock == NO_WATER ) - return false; - - ASSERT( pfOutLevel != nil ); - *pfOutLevel = ms_aWaterZs[nBlock]; - - return true; -} - -float -CWaterLevel::GetWaterWavesOnly(short x, short y) -{ - float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); - - float fWindFactor = CWeather::WindClipped * 0.7f + 0.3f; - - float fWave = Sin( float(float(4 * y + 4 * x) * (TWOPI / SMALL_SECTOR_SIZE )) + fAngle ); - - return fWave * fWindFactor; -} - -CVector -CWaterLevel::GetWaterNormal(float fX, float fY) -{ - //TODO: BUG ? no x offset - - int32 x = WATER_TO_SMALL_SECTOR_X(fX); - int32 y = WATER_TO_SMALL_SECTOR_Y(fY); - - float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); - float fWindFactor = CWeather::WindClipped * 0.4f + 0.2f; - - float _fWave = (WATER_UNSIGN_Y(fY) - y*SMALL_SECTOR_SIZE + WATER_UNSIGN_X(fX) - x*SMALL_SECTOR_SIZE) - * (TWOPI / SMALL_SECTOR_SIZE ) + fAngle; - - CVector vA(1.0f, 0.0f, fWindFactor * (TWOPI / SMALL_SECTOR_SIZE ) * Cos(_fWave)); - CVector vB(0.0f, 1.0f, fWindFactor * (TWOPI / SMALL_SECTOR_SIZE ) * Cos(_fWave)); - - CVector norm = CrossProduct(vA, vB); - - norm.Normalise(); - - return norm; -} - - -inline float -_GetWaterDrawDist() -{ - if ( TheCamera.GetPosition().z < 15.0f ) return 1200.0f; - if ( TheCamera.GetPosition().z > 60.0f ) return 2000.0f; - return ( TheCamera.GetPosition().z + -15.0f ) * 800.0f / 45.0f + 1200.0f; -} - -inline float -_GetWavyDrawDist() -{ - if ( FindPlayerVehicle() && FindPlayerVehicle()->IsBoat() ) - return 120.0f; - else - return 70.0f; -} - -inline void -_GetCamBounds(bool *bUseCamStartY, bool *bUseCamEndY, bool *bUseCamStartX, bool *bUseCamEndX) -{ - if ( TheCamera.GetForward().z > -0.8f ) - { - if ( Abs(TheCamera.GetForward().x) > Abs(TheCamera.GetForward().y) ) - { - if ( TheCamera.GetForward().x > 0.0f ) - *bUseCamStartX = true; - else - *bUseCamEndX = true; - } - else - { - if ( TheCamera.GetForward().y > 0.0f ) - *bUseCamStartY = true; - else - *bUseCamEndY = true; - } - } -} - - -inline bool -_IsColideWithBlock(int32 x, int32 y, int32 &block) -{ - block = CWaterLevel::aWaterFineBlockList[x + 0][y + 0]; - if (block >= 0) - return true; - - block = CWaterLevel::aWaterFineBlockList[x + 0][y + 1]; - if (block >= 0) - { - block = CWaterLevel::aWaterFineBlockList[x + 0][y + 2]; - if (block >= 0) - return true; - } - - block = CWaterLevel::aWaterFineBlockList[x + 1][y + 0]; - if (block >= 0) - return true; - - block = CWaterLevel::aWaterFineBlockList[x + 1][y + 1]; - if (block >= 0) - { - block = CWaterLevel::aWaterFineBlockList[x + 1][y + 2]; - if (block >= 0) - return true; - } - - block = CWaterLevel::aWaterFineBlockList[x + 2][y + 0]; - if (block >= 0) - return true; - - block = CWaterLevel::aWaterFineBlockList[x + 2][y + 1]; - if (block >= 0) - { - block = CWaterLevel::aWaterFineBlockList[x + 2][y + 2]; - if (block >= 0) - return true; - } - - return false; -} - -inline float -SectorRadius(float fSize) -{ - return Sqrt(Pow(fSize, 2) + Pow(fSize, 2)); -} - -void -CWaterLevel::RenderWater() -{ -//"Custom" Don't Render Water Toggle -#ifndef MASTER - if (gbDontRenderWater) - return; -#endif - bool bUseCamEndX = false; - bool bUseCamStartY = false; - - bool bUseCamStartX = false; - bool bUseCamEndY = false; - - if ( !CGame::CanSeeWaterFromCurrArea() ) - return; - - _GetCamBounds(&bUseCamStartY, &bUseCamEndY, &bUseCamStartX, &bUseCamEndX); - - float fHugeSectorMaxRenderDist = _GetWaterDrawDist(); - float fHugeSectorMaxRenderDistSqr = SQR(fHugeSectorMaxRenderDist); - - float windAddUV = CWeather::WindClipped * 0.0005f + 0.0006f; - - float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); - - if ( !CTimer::GetIsPaused() ) - { - TEXTURE_ADDU += windAddUV; - TEXTURE_ADDV += windAddUV; - - _TEXTURE_MASK_ADDU += Sin(fAngle) * 0.0005f + 1.1f * windAddUV; - _TEXTURE_MASK_ADDV -= Cos(fAngle * 1.3f) * 0.0005f + 1.2f * windAddUV; - - _TEXTURE_WAKE_ADDU -= Sin(fAngle) * 0.0003f + windAddUV; - _TEXTURE_WAKE_ADDV += Cos(fAngle * 0.7f) * 0.0003f + windAddUV; - } - - if ( _TEXTURE_MASK_ADDU >= 1.0f ) - _TEXTURE_MASK_ADDU = 0.0f; - if ( _TEXTURE_MASK_ADDV >= 1.0f ) - _TEXTURE_MASK_ADDV = 0.0f; - - if ( _TEXTURE_WAKE_ADDU >= 1.0f ) - _TEXTURE_WAKE_ADDU = 0.0f; - if ( _TEXTURE_WAKE_ADDV >= 1.0f ) - _TEXTURE_WAKE_ADDV = 0.0f; - - if ( TEXTURE_ADDU >= 1.0f ) - TEXTURE_ADDU = 0.0f; - if ( TEXTURE_ADDV >= 1.0f ) - TEXTURE_ADDV = 0.0f; - -#ifdef PC_WATER - _fWaterZOffset = CWeather::WindClipped * 0.5f + 0.25f; -#endif - - RwRGBA color = { 0, 0, 0, 255 }; - - color.red = CTimeCycle::GetWaterRed(); - color.green = CTimeCycle::GetWaterGreen(); - color.blue = CTimeCycle::GetWaterBlue(); - -#ifndef PC_WATER - RwRGBA colorUnderwater = { 0, 0, 0, 255 }; - colorUnderwater.red = (uint32)(0.8f * (float)colorUnderwater.red); - colorUnderwater.green = (uint32)(0.8f * (float)colorUnderwater.green); - colorUnderwater.blue = (uint32)(0.8f * (float)colorUnderwater.blue); -#endif - - TempBufferVerticesStored = 0; - TempBufferIndicesStored = 0; - -#ifndef PC_WATER - WavesCalculatedThisFrame = false; -#endif - - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterRaster); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO); - - CVector2D camPos(TheCamera.GetPosition().x, TheCamera.GetPosition().y); - - int32 nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x - fHugeSectorMaxRenderDist + WATER_X_OFFSET); - int32 nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + fHugeSectorMaxRenderDist + WATER_X_OFFSET) + 1; - int32 nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y - fHugeSectorMaxRenderDist); - int32 nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y + fHugeSectorMaxRenderDist) + 1; - - if ( bUseCamStartX ) - nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET); - if ( bUseCamEndX ) - nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET); - if ( bUseCamStartY ) - nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y); - if ( bUseCamEndY ) - nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y); - - nStartX = Clamp(nStartX, 0, MAX_HUGE_SECTORS - 1); - nEndX = Clamp(nEndX, 0, MAX_HUGE_SECTORS - 1); - nStartY = Clamp(nStartY, 0, MAX_HUGE_SECTORS - 1); - nEndY = Clamp(nEndY, 0, MAX_HUGE_SECTORS - 1); - - for ( int32 x = nStartX; x <= nEndX; x++ ) - { - for ( int32 y = nStartY; y <= nEndY; y++ ) - { - if ( aWaterBlockList[2*x+0][2*y+0] >= 0 - || aWaterBlockList[2*x+1][2*y+0] >= 0 - || aWaterBlockList[2*x+0][2*y+1] >= 0 - || aWaterBlockList[2*x+1][2*y+1] >= 0 ) - { - float fX = WATER_FROM_HUGE_SECTOR_X(x) - WATER_X_OFFSET; - float fY = WATER_FROM_HUGE_SECTOR_Y(y); - - CVector2D vecHugeSectorCentre(fX + HUGE_SECTOR_SIZE/2,fY + HUGE_SECTOR_SIZE/2); - - float fHugeSectorDistToCamSqr = (camPos - vecHugeSectorCentre).MagnitudeSqr(); - - if ( fHugeSectorMaxRenderDistSqr > fHugeSectorDistToCamSqr ) - { - if ( TheCamera.IsSphereVisible(CVector(vecHugeSectorCentre.x, vecHugeSectorCentre.y, 0.0f), SectorRadius(HUGE_SECTOR_SIZE)) ) - { -#ifndef PC_WATER - WavesCalculatedThisFrame = true; -#endif - - - float fZ; - - if ( aWaterBlockList[2*x+0][2*y+0] >= 0 ) - fZ = ms_aWaterZs[ aWaterBlockList[2*x+0][2*y+0] ]; - - if ( aWaterBlockList[2*x+1][2*y+0] >= 0 ) - fZ = ms_aWaterZs[ aWaterBlockList[2*x+1][2*y+0] ]; - - if ( aWaterBlockList[2*x+0][2*y+1] >= 0 ) - fZ = ms_aWaterZs[ aWaterBlockList[2*x+0][2*y+1] ]; - - if ( aWaterBlockList[2*x+1][2*y+1] >= 0 ) - fZ = ms_aWaterZs[ aWaterBlockList[2*x+1][2*y+1] ]; - - if ( fHugeSectorDistToCamSqr >= SQR(500.0f) ) - { - RenderOneFlatHugeWaterPoly(fX, fY, fZ, color); - } - else - { -#ifndef PC_WATER - if (m_bRenderSeaBed) - RenderOneSlopedUnderWaterPoly(fX, fY, fZ, colorUnderwater); -#endif - // see RenderTransparentWater() - ; - } - } - } - } - } - } - - /* - ----------- ---------------------- ---------------------- - | [N] | | [ EndY ] | | [ top ] | - | | | | | | - |[W] [0] [E]| |[StartX] [] [ EndX ]| |[ left ] [] [ right]| - | | | | | | - | [S] | | [StartY] | | [bottom] | - ----------- ---------------------- ---------------------- - - - [S] [StartY] [bottom] - [N] [EndY] [top] - [W] [StartX] [left] - [E] [EndX] [right] - - [S] -> [N] && [W] -> [E] - bottom -> top && left -> right - */ - - for ( int32 x = 0; x < 26; x++ ) - { - for ( int32 y = 0; y < 5; y++ ) - { - float fX = WATER_SIGN_X(float(x) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f - WATER_X_OFFSET; - float fY = WATER_SIGN_Y(float(y) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f; - - if ( !bUseCamStartY ) - { - CVector2D vecExtraHugeSectorCentre(fX + EXTRAHUGE_SECTOR_SIZE/2, fY + EXTRAHUGE_SECTOR_SIZE/2); - - float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude(); - - if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr ) - { - if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE)) ) - { - RenderOneFlatExtraHugeWaterPoly( - vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2, - vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2, - 0.0f, - color); - } - } - } - - if ( !bUseCamEndY ) - { - CVector2D vecExtraHugeSectorCentre(fX + EXTRAHUGE_SECTOR_SIZE/2, -(fY + EXTRAHUGE_SECTOR_SIZE/2)); - - float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude(); - - if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr ) - { - if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE)) ) - { - RenderOneFlatExtraHugeWaterPoly( - vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2, - vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2, - 0.0f, - color); - } - } - } - } - } - - for ( int32 y = 5; y < 21; y++ ) - { - for ( int32 x = 0; x < 5; x++ ) - { - float fX = WATER_SIGN_X(float(x) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f - WATER_X_OFFSET; - float fX2 = WATER_SIGN_X(float(x) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f + WATER_X_OFFSET; - float fY = WATER_SIGN_Y(float(y) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f; - - if ( !bUseCamStartX ) - { - CVector2D vecExtraHugeSectorCentre(fX + EXTRAHUGE_SECTOR_SIZE/2, fY + EXTRAHUGE_SECTOR_SIZE/2); - - float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude(); - - if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr ) - { - if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE)) ) - { - RenderOneFlatExtraHugeWaterPoly( - vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2, - vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2, - 0.0f, - color); - } - } - } - - if ( !bUseCamEndX ) - { - CVector2D vecExtraHugeSectorCentre(-(fX2 + EXTRAHUGE_SECTOR_SIZE/2), fY + EXTRAHUGE_SECTOR_SIZE/2); - - float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude(); - - if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr ) - { - if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.x, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE)) ) - { - RenderOneFlatExtraHugeWaterPoly( - vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2, - vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2, - 0.0f, - color); - } - } - } - } - } - - RenderAndEmptyRenderBuffer(); - - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); - - if ( WavesCalculatedThisFrame ) - { - RenderSeaBirds(); - RenderShipsOnHorizon(); - CParticle::HandleShipsAtHorizonStuff(); - HandleBeachToysStuff(); - } - - if ( _bSeaLife ) - HandleSeaLifeForms(); - - DefinedState(); -} - - -void -CWaterLevel::RenderTransparentWater(void) -{ - bool bUseCamEndX = false; - bool bUseCamStartY = false; - - bool bUseCamStartX = false; - bool bUseCamEndY = false; - - _bSeaLife = false; - - if ( !CGame::CanSeeWaterFromCurrArea() ) - return; - - PUSH_RENDERGROUP("CWaterLevel::RenderTransparentWater"); - - float fWaterDrawDist = _GetWavyDrawDist(); - float fWaterDrawDistLarge = fWaterDrawDist + 90.0f; - float fWavySectorMaxRenderDistSqr = SQR(fWaterDrawDist); - - _GetCamBounds(&bUseCamStartY, &bUseCamEndY, &bUseCamStartX, &bUseCamEndX); - - float fHugeSectorMaxRenderDist = _GetWaterDrawDist(); - float fHugeSectorMaxRenderDistSqr = SQR(fHugeSectorMaxRenderDist); - - RenderBoatWakes(); - - RwRGBA color; - - color.red = CTimeCycle::GetWaterRed(); - color.green = CTimeCycle::GetWaterGreen(); - color.blue = CTimeCycle::GetWaterBlue(); - color.alpha = 255; - - RwRGBA colorTrans; - - colorTrans.red = CTimeCycle::GetWaterRed(); - colorTrans.green = CTimeCycle::GetWaterGreen(); - colorTrans.blue = CTimeCycle::GetWaterBlue(); - colorTrans.alpha = CTimeCycle::GetWaterAlpha(); - - TempBufferVerticesStored = 0; - TempBufferIndicesStored = 0; - -#ifndef PC_WATER - WavesCalculatedThisFrame = false; -#endif - - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterRaster); -#ifndef PC_WATER - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); -#endif - - CVector2D camPos(TheCamera.GetPosition().x, TheCamera.GetPosition().y); - - int32 nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x - fHugeSectorMaxRenderDist + WATER_X_OFFSET); - int32 nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + fHugeSectorMaxRenderDist + WATER_X_OFFSET) + 1; - int32 nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y - fHugeSectorMaxRenderDist ); - int32 nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y + fHugeSectorMaxRenderDist ) + 1; - - if ( bUseCamStartX ) - nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET); - if ( bUseCamEndX ) - nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET); - if ( bUseCamStartY ) - nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y ); - if ( bUseCamEndY ) - nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y ); - - nStartX = Clamp(nStartX, 0, MAX_HUGE_SECTORS - 1); - nEndX = Clamp(nEndX, 0, MAX_HUGE_SECTORS - 1); - nStartY = Clamp(nStartY, 0, MAX_HUGE_SECTORS - 1); - nEndY = Clamp(nEndY, 0, MAX_HUGE_SECTORS - 1); - - - for ( int32 x = nStartX; x <= nEndX; x++ ) - { - for ( int32 y = nStartY; y <= nEndY; y++ ) - { - if ( aWaterBlockList[2*x+0][2*y+0] >= 0 - || aWaterBlockList[2*x+1][2*y+0] >= 0 - || aWaterBlockList[2*x+0][2*y+1] >= 0 - || aWaterBlockList[2*x+1][2*y+1] >= 0 ) - { - float fX = WATER_FROM_HUGE_SECTOR_X(x) - WATER_X_OFFSET; - float fY = WATER_FROM_HUGE_SECTOR_Y(y); - - CVector2D vecHugeSectorCentre - ( - fX + HUGE_SECTOR_SIZE/2, - fY + HUGE_SECTOR_SIZE/2 - ); - - float fHugeSectorDistToCamSqr = (camPos - vecHugeSectorCentre).MagnitudeSqr(); - - if ( fHugeSectorMaxRenderDistSqr > fHugeSectorDistToCamSqr ) - { - if ( TheCamera.IsSphereVisible(CVector(vecHugeSectorCentre.x, vecHugeSectorCentre.y, 0.0f), SectorRadius(HUGE_SECTOR_SIZE)) ) - { - if ( fHugeSectorDistToCamSqr >= SQR(500.0f) ) - { - // see RenderWater() - ; - } - else - { - for ( int32 x2 = 2*x; x2 <= 2*x+1; x2++ ) - { - for ( int32 y2 = 2*y; y2 <= 2*y+1; y2++ ) - { - if ( aWaterBlockList[x2][y2] >= 0 ) - { - float fLargeX = WATER_FROM_LARGE_SECTOR_X(x2) - WATER_X_OFFSET; - float fLargeY = WATER_FROM_LARGE_SECTOR_Y(y2); - - CVector2D vecLargeSectorCentre(fLargeX + LARGE_SECTOR_SIZE/2, fLargeY + LARGE_SECTOR_SIZE/2); - - float fLargeSectorDistToCamSqr = (camPos - vecLargeSectorCentre).MagnitudeSqr(); - - if ( fLargeSectorDistToCamSqr < fHugeSectorMaxRenderDistSqr ) - { - if ( TheCamera.IsSphereVisible(CVector(vecLargeSectorCentre.x, vecLargeSectorCentre.y, 0.0f), SectorRadius(LARGE_SECTOR_SIZE)) ) - { - // Render four small(32x32) sectors, or one large(64x64). - - // - // [N] - // --------- - // |0x1|1x1| - // [W] --------- [E] - // |0x0|1x0| - // --------- - // [S] - // - - float fLargeSectorDrawDistSqr = SQR((fWaterDrawDistLarge + 16.0f)); - - if ( fLargeSectorDistToCamSqr < fLargeSectorDrawDistSqr ) - { - _bSeaLife = true; - - float fZ; - - // WS - if ( aWaterFineBlockList[2*x2+0][2*y2+0] >= 0 ) - { - float fSmallX = fLargeX; - float fSmallY = fLargeY; - - CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2, fSmallY + SMALL_SECTOR_SIZE/2); - - float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr(); - fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+0][2*y2+0] ]; - - if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr ) - RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans); - else - RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist); - } - - // SE - if ( aWaterFineBlockList[2*x2+1][2*y2+0] >= 0 ) - { - float fSmallX = fLargeX + (LARGE_SECTOR_SIZE/2); - float fSmallY = fLargeY; - - CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2, fSmallY + SMALL_SECTOR_SIZE/2); - - float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr(); - fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+1][2*y2+0] ]; - - if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr ) - RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans); - else - RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist); - } - - // WN - if ( aWaterFineBlockList[2*x2+0][2*y2+1] >= 0 ) - { - float fSmallX = fLargeX; - float fSmallY = fLargeY + (LARGE_SECTOR_SIZE/2); - - CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2,fSmallY + SMALL_SECTOR_SIZE/2); - - float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr(); - fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+0][2*y2+1] ]; - - if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr ) - RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans); - else - RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist); - } - - //NE - if ( aWaterFineBlockList[2*x2+1][2*y2+1] >= 0 ) - { - float fSmallX = fLargeX + (LARGE_SECTOR_SIZE/2); - float fSmallY = fLargeY + (LARGE_SECTOR_SIZE/2); - - CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2, fSmallY + SMALL_SECTOR_SIZE/2); - - float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr(); - fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+1][2*y2+1] ]; - - if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr ) - RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans); - else - RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist); - } - } - else - { - float fZ; - - fZ = ms_aWaterZs[ aWaterBlockList[x2][y2] ]; - - RenderOneFlatLargeWaterPoly(fLargeX, fLargeY, fZ, color); - } - } - } - } - } - } - } - } - } - } - } - } - - RenderAndEmptyRenderBuffer(); - -#ifdef PC_WATER - if ( MaskCalculatedThisFrame - && (m_nRenderWaterLayers == 0 || m_nRenderWaterLayers == 2 || m_nRenderWaterLayers == 3) ) - { - RwV3d pos = { 0.0f, 0.0f, 0.0f }; - - pos.x = PreCalculatedMaskPosn.x; - pos.y = PreCalculatedMaskPosn.y; - pos.z = PreCalculatedMaskPosn.z; - - RpMatFXMaterialSetEnvMapFrame(RpGeometryGetMaterial(RpAtomicGetGeometry(ms_pMaskAtomic), 0), - RwCameraGetFrame(RwCameraGetCurrentCamera())); - - RwFrameTranslate(RpAtomicGetFrame(ms_pMaskAtomic), &pos, rwCOMBINEREPLACE); - - RpAtomicRender(ms_pMaskAtomic); - } -#else - if (!CCullZones::WaterFudge()) - { - int32 signX = 0; - int32 signY = 0; - - float fCamX = camPos.x - SMALL_SECTOR_SIZE; - float fCamY = camPos.y - SMALL_SECTOR_SIZE; - - if (TheCamera.GetForward().x > 0.3f) - signX = 1; - else if (TheCamera.GetForward().x < -0.3f) - signX = -1; - - fCamX += 0.3f * (float)signX * float(SMALL_SECTOR_SIZE * 2.0f); // 19.2f - - if (TheCamera.GetForward().y > 0.3f) - signY = 1; - else if (TheCamera.GetForward().y < -0.3f) - signY = -1; - - fCamY += 0.3f * (float)signY * float(SMALL_SECTOR_SIZE * 2.0f); // 19.2f - - int32 nBlock; - - int32 BlockX = WATER_TO_SMALL_SECTOR_X(fCamX + WATER_X_OFFSET) + 1; - int32 BlockY = WATER_TO_SMALL_SECTOR_Y(fCamY) + 1; - - if (_IsColideWithBlock(BlockX, BlockY, nBlock)) - { - if (m_nRenderWaterLayers != 1 && m_nRenderWaterLayers != 6) - { - float fMaskX = Floor(fCamX / 2.0f) * 2.0f; - float fMaskY = Floor(fCamY / 2.0f) * 2.0f; - float fWaterZ = CWaterLevel::ms_aWaterZs[nBlock]; - float fSectorX = WATER_FROM_SMALL_SECTOR_X(BlockX) - WATER_X_OFFSET; - float fSectorY = WATER_FROM_SMALL_SECTOR_Y(BlockY); - - RenderWavyMask(fMaskX, fMaskY, fWaterZ, - fSectorX, fSectorY, - signX, signY, colorTrans); - } - } - } - - DefinedState(); -#endif - - POP_RENDERGROUP(); -} - -void CWaterLevel::RenderOneFlatSmallWaterPoly(float fX, float fY, float fZ, RwRGBA const &color) -{ - if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) - RenderAndEmptyRenderBuffer(); - - int32 vidx = TempBufferVerticesStored; - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], color); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 1.0f); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], color); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + SMALL_SECTOR_SIZE, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 1.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 1.0f); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], color); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + SMALL_SECTOR_SIZE, fY, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 1.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], color); - - - int32 iidx = TempBufferIndicesStored; - - TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; - TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; - TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; - TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; - - TempBufferVerticesStored += 4; - TempBufferIndicesStored += 6; -} - -void -CWaterLevel::RenderOneFlatLargeWaterPoly(float fX, float fY, float fZ, RwRGBA const &color) -{ - if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) - RenderAndEmptyRenderBuffer(); - - int32 vidx = TempBufferVerticesStored; - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], color); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + LARGE_SECTOR_SIZE, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 2.0f); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], color); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + LARGE_SECTOR_SIZE, fY + LARGE_SECTOR_SIZE, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 2.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 2.0f); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], color); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + LARGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 2.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], color); - - - int32 iidx = TempBufferIndicesStored; - - TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; - TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; - TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; - TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; - - TempBufferVerticesStored += 4; - TempBufferIndicesStored += 6; -} - -void -CWaterLevel::RenderOneFlatHugeWaterPoly(float fX, float fY, float fZ, RwRGBA const &color) -{ - if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) - RenderAndEmptyRenderBuffer(); - - int32 vidx = TempBufferVerticesStored; - - RwRGBA c; - - c.red = color.red; - c.green = color.green; - c.blue = color.blue; - c.alpha = 255; - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], c); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 4.0f); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], c); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + HUGE_SECTOR_SIZE, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 4.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 4.0f); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], c); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + HUGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 4.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], c); - - - int32 iidx = TempBufferIndicesStored; - - TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; - TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; - TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; - TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; - - TempBufferVerticesStored += 4; - TempBufferIndicesStored += 6; -} - -void -CWaterLevel::RenderOneFlatExtraHugeWaterPoly(float fX, float fY, float fZ, RwRGBA const &color) -{ - if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) - RenderAndEmptyRenderBuffer(); - - int32 vidx = TempBufferVerticesStored; - - RwRGBA c; - - c.red = color.red; - c.green = color.green; - c.blue = color.blue; - c.alpha = 255; - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], c); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + EXTRAHUGE_SECTOR_SIZE, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 8.0f); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], c); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + EXTRAHUGE_SECTOR_SIZE, fY + EXTRAHUGE_SECTOR_SIZE, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 8.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 8.0f); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], c); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + EXTRAHUGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 8.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV); - RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], c); - - - int32 iidx = TempBufferIndicesStored; - - TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; - TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; - TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; - TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; - - TempBufferVerticesStored += 4; - TempBufferIndicesStored += 6; -} - -void -CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &color, bool bDontRender) -{ - CVector vecSectorPos(fX + (SMALL_SECTOR_SIZE/2), fY + (SMALL_SECTOR_SIZE/2), fZ + 2.0f); - - if ( COcclusion::IsAABoxOccluded(vecSectorPos, SMALL_SECTOR_SIZE, SMALL_SECTOR_SIZE, 4.0f) ) - return; - -#ifdef PC_WATER - RequireWavySector = true; -#else - if (!WavesCalculatedThisFrame) - { - WavesCalculatedThisFrame = true; - - float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); - - RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); - RwTexCoords *wavyTexCoords = RpGeometryGetVertexTexCoords(wavyGeometry, rwTEXTURECOORDINATEINDEX0); - RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0); - RwRGBA *wavyPreLight = RpGeometryGetPreLightColors(wavyGeometry); - RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph); - RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph); - - RpGeometryLock(wavyGeometry, rpGEOMETRYLOCKVERTICES | rpGEOMETRYLOCKNORMALS | rpGEOMETRYLOCKPRELIGHT | rpGEOMETRYLOCKTEXCOORDS); - - RwMatrix *camMat = RwFrameGetLTM(RwCameraGetFrame(RwCameraGetCurrentCamera())); //or curWorld - - float randomDampInv2 = (1.0f - fRandomDamp) * 2.0f; - - float move = 1.0f / 16.0f; - float randomMove = 1.0f / (16.0f * fRandomMoveDiv); - - float vertMul = 0.5f; - - float wind = CWeather::WindClipped * 0.4f + 0.2f; - float waveWind = CWeather::WindClipped * fWave2Ampl + 0.05f; - - float waveA = (TWOPI / 16.0f) - * ((fNormalDirectionScalar1 * Abs(camMat->at.x + camMat->at.y) + fNormMult) * (CWeather::WindClipped * 0.4f + 0.2f)); - - float waveB = TWOPI / (16.0f * fWave2NormScale) - * ((fNormalDirectionScalar2 * Abs(camMat->at.y - camMat->at.x) + fNormMultB) * (CWeather::WindClipped * 0.2f + 0.1f)); - - CVector vA(1.0f, 0.0f, 0.0f); - CVector vB(0.0f, 1.0f, 0.0f); - - for ( int32 i = 0; i < 17; i++ ) - { - for ( int32 j = 0; j < 17; j++ ) - { - wavyTexCoords->u = float(i) * move + TEXTURE_ADDV; - wavyTexCoords->v = float(j) * move + TEXTURE_ADDU; - - RwRGBAAssign(wavyPreLight, &color); - - if (i > 0 && i < 16 && j > 0 && j < 16) - { - wavyMorphVerts->x += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove; - wavyMorphVerts->x *= fRandomDamp; - wavyMorphVerts->x += float(i) * randomDampInv2; - - wavyMorphVerts->y += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove; - wavyMorphVerts->y *= fRandomDamp; - wavyMorphVerts->y += float(j) * randomDampInv2; - } - - float morphVertXHalf = (i == 16) ? 0.0f : vertMul * wavyMorphVerts->x; - float morphVertYHalf = (j == 16) ? 0.0f : vertMul * wavyMorphVerts->y; - - float waveMulA = (morphVertYHalf + morphVertXHalf) * (TWOPI / 16.0f) + fAngle; - float waveMulB = (morphVertYHalf - morphVertXHalf) * (TWOPI / (16.0f * fWave2InvLength)) + fAngle; - - wavyMorphVerts->z = wind * Sin(waveMulA) + waveWind * Sin(waveMulB); - - vA.z = (waveA * Cos(waveMulA)) - (waveB * Cos(waveMulB)); - vB.z = (waveA * Cos(waveMulA)) + (waveB * Cos(waveMulB)); - - CVector norm = CrossProduct(vA, vB); - norm.Normalise(); - - wavyMorphNormals->x = norm.x; - wavyMorphNormals->y = norm.y; - wavyMorphNormals->z = norm.z; - - ++wavyPreLight; - ++wavyTexCoords; - - ++wavyMorphVerts; - ++wavyMorphNormals; - } - } - - RpGeometryUnlock(wavyGeometry); - } - - float fCentreX = fX + (SMALL_SECTOR_SIZE / 2); - float fCentreY = fY + (SMALL_SECTOR_SIZE / 2); -#endif - -#ifdef PC_WATER - if ( WavesCalculatedThisFrame ) -#endif - { - if (bDontRender == false - && m_nRenderWaterLayers != 2 - && m_nRenderWaterLayers != 4 - && m_nRenderWaterLayers != 6 ) - { - RwV3d pos = { 0.0f, 0.0f, 0.0f }; - - pos.x = fX; - pos.y = fY; - pos.z = fZ; - - RwFrameTranslate(RpAtomicGetFrame(ms_pWavyAtomic), &pos, rwCOMBINEREPLACE); - - RpAtomicRender(ms_pWavyAtomic); - } - } -} - -int16 -_RoundValue(int32 v) -{ - int16 result = v; - - while ( result < 0 ) result += 16; - while ( result > 16 ) result -= 16; - - return result; -} - -void -CWaterLevel::RenderWavyMask(float fX, float fY, float fZ, - float fSectorX, float fSectorY, -#ifdef PC_WATER - float fCamPosX, float fCamPosY, - float fCamDirX, float fCamDirY, RwRGBA const&color) -#else - int32 nCamDirX, int32 nCamDirY, RwRGBA const&color) -#endif -{ -#ifndef PC_WATER - bool bRender = true; - if (m_nRenderWaterLayers != 0 && m_nRenderWaterLayers != 2 && m_nRenderWaterLayers != 3) - bRender = false; -#endif - CVector vecSectorPos(fX + (LARGE_SECTOR_SIZE/2), fY + (LARGE_SECTOR_SIZE/2), fZ + 2.0f); - - if ( COcclusion::IsAABoxOccluded(vecSectorPos, LARGE_SECTOR_SIZE, LARGE_SECTOR_SIZE, 4.0f) ) - return; - -#ifndef PC_WATER - float fUOffset = fX - (MAX_LARGE_SECTORS * (int32)Floor(fX / MAX_LARGE_SECTORS)); - float fVOffset = fY - (MAX_LARGE_SECTORS * (int32)Floor(fY / MAX_LARGE_SECTORS)); - - int32 nSecsX = (int32)((fX - fSectorX) / 2.0f); - int32 nSecsY = (int32)((fY - fSectorY) / 2.0f); -#endif - - RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); - RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0); - RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph); - RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph); - - RpGeometry *maskGeometry = RpAtomicGetGeometry(ms_pMaskAtomic); - RwTexCoords *maskTexCoords = RpGeometryGetVertexTexCoords(maskGeometry, rwTEXTURECOORDINATEINDEX0); - RwRGBA *maskPreLight = RpGeometryGetPreLightColors(maskGeometry); - RpMorphTarget *maskMorph = RpGeometryGetMorphTarget(maskGeometry, 0); - RwV3d *maskMorphVerts = RpMorphTargetGetVertices(maskMorph); - RwV3d *maskMorphNormals = RpMorphTargetGetVertexNormals(maskMorph); - - RpGeometryLock(maskGeometry, rpGEOMETRYLOCKVERTICES|rpGEOMETRYLOCKNORMALS|rpGEOMETRYLOCKPRELIGHT|rpGEOMETRYLOCKTEXCOORDS); - -#ifndef PC_WATER - RpMaterial *maskMat = RpGeometryGetMaterial(maskGeometry, 0); - RpMatFXMaterialSetEnvMapFrame(maskMat, RwCameraGetFrame(RwCameraGetCurrentCamera())); - RpMatFXMaterialSetEnvMapCoefficient(maskMat, fEnvScale); - RpMatFXMaterialSetEnvMapFrameBufferAlpha(maskMat, TRUE); -#endif - -#ifndef PC_WATER - float fMinSparkZ = (CWeather::WindClipped * fWave2Ampl + 0.05f + - CWeather::WindClipped * 0.4f + 0.2) * (1.0f - 0.04f * CWeather::SunGlare); - - int32 randval = CGeneral::GetRandomNumber(); - - float fUVStep = 0.125f; - float f27 = 2.0f; - - float fMinU = (fUOffset / 16.0f) + _TEXTURE_MASK_ADDU; - float fMinV = (fVOffset / 16.0f) + _TEXTURE_MASK_ADDV; - - float fAlphaMul = ((float)color.alpha * 0.4f) / 16.0f; - - float fXOffset = 16.0f; - if (nCamDirX > 0) - fXOffset = 6.4f; - else if (nCamDirX < 0) - fXOffset = 25.6f; - - float fYOffset = 16.0f; - if (nCamDirY > 0) - fYOffset = 6.4f; - else if (nCamDirY < 0) - fYOffset = 25.6f; - - int16 nX = _RoundValue(nSecsX - 1); - int16 nY = _RoundValue(nSecsY - 1); -#else - float fMinSparkZ = (fWave2Ampl * CWeather::WindClipped + 0.05f + - 0.4f * CWeather::WindClipped + 0.2) * (1.0f - 0.02f * CWeather::SunGlare); - - int32 randval = CGeneral::GetRandomNumber() & 255; - - int16 nX = _RoundValue((int32)((fX - fSectorX) * 0.5f) - 1); - int16 nY = _RoundValue((int32)((fY - fSectorY) * 0.5f) - 1); -#endif - int16 idxX = nX; - - for ( int32 i = 0; i < 17; i++ ) - { - int16 idxY = nY; - - if ( ++idxX > 16 ) - idxX -= 16; - - for ( int32 j = 0; j < 17; j++ ) - { - if ( ++idxY > 16 ) - idxY -= 16; - - const int32 a = (0*16); - const int32 b = (1*16); - const int32 c = (33*16); - const int32 d = (34*16); - - int32 base = (i*33+j); - -#ifndef PC_WATER - maskTexCoords[base + a].u = fMinU + ((float)i * fUVStep); - maskTexCoords[base + a].v = fMinV + ((float)j * fUVStep); - - maskTexCoords[base + b].u = maskTexCoords[base + a].u; - maskTexCoords[base + b].v = maskTexCoords[base + a].v + (16.0f * fUVStep); - - maskTexCoords[base + c].u = maskTexCoords[base + a].u + (16.0f * fUVStep); - maskTexCoords[base + c].v = maskTexCoords[base + a].v; - - maskTexCoords[base + d].u = maskTexCoords[base + a].u + (16.0f * fUVStep); - maskTexCoords[base + d].v = maskTexCoords[base + a].v + (16.0f * fUVStep); -#else - maskTexCoords[base+a].v = float(j) / SMALL_SECTOR_SIZE + ((fCamPosY - fY) / 64); - maskTexCoords[base+c].v = maskTexCoords[base+a].v; - maskTexCoords[base+d].v = maskTexCoords[base+a].v + 0.5f; - maskTexCoords[base+b].v = maskTexCoords[base+d].v; - - maskTexCoords[base+a].u = float(i) / SMALL_SECTOR_SIZE + ((fCamPosX - fX) / 64); - maskTexCoords[base+b].u = maskTexCoords[base+a].u; - maskTexCoords[base+d].u = maskTexCoords[base+a].u + 0.5f; - maskTexCoords[base+c].u = maskTexCoords[base+d].u; -#endif - - maskMorphVerts[base+a].x = (wavyMorphVerts[idxY + (17 * idxX)].x - (float)idxX * 2.0f) + (float(i) * 2.0f); - maskMorphVerts[base+b].x = maskMorphVerts[base+a].x; - maskMorphVerts[base+c].x = maskMorphVerts[base+a].x + SMALL_SECTOR_SIZE; - maskMorphVerts[base+d].x = maskMorphVerts[base+c].x; - - maskMorphVerts[base+a].y = (wavyMorphVerts[idxY + (17 * idxX)].y - (float)idxY * 2.0f) + (float(j) * 2.0f); - maskMorphVerts[base+c].y = maskMorphVerts[base+a].y; - maskMorphVerts[base+b].y = maskMorphVerts[base+a].y + SMALL_SECTOR_SIZE; - maskMorphVerts[base+d].y = maskMorphVerts[base+b].y; - - maskMorphVerts[base+a].z = wavyMorphVerts[idxY + (17 * idxX)].z; - maskMorphVerts[base+d].z = maskMorphVerts[base+a].z; - maskMorphVerts[base+c].z = maskMorphVerts[base+d].z; - maskMorphVerts[base+b].z = maskMorphVerts[base+c].z; - -#ifndef PC_WATER - if (maskMorphVerts[base].z >= fMinSparkZ) -#else - if ( maskMorphVerts[base].z > fMinSparkZ ) -#endif - { - switch ( (i + j + randval) & 3 ) - { - case 0: - { - CVector vecPos - ( - fX + maskMorphVerts[base+a].x, - fY + maskMorphVerts[base+a].y, - fZ + maskMorphVerts[base+a].z + 0.12f - ); - - vecPos -= 0.05f * TheCamera.GetForward(); - - CParticle::AddParticle(PARTICLE_WATER_SPARK, - vecPos, - CVector(0.0f, 0.0f, 0.0f), - nil, - 0.0f, - 15, - CGeneral::GetRandomNumberInRange(-90, 90), - 0, - 0); - } - break; - - case 1: - { - CVector vecPos - ( - fX + maskMorphVerts[base+c].x, - fY + maskMorphVerts[base+c].y, - fZ + maskMorphVerts[base+c].z + 0.12f - ); - - vecPos -= 0.05f * TheCamera.GetForward(); - - CParticle::AddParticle(PARTICLE_WATER_SPARK, - vecPos, - CVector(0.0f, 0.0f, 0.0f), - nil, - 0.0f, - 15, - CGeneral::GetRandomNumberInRange(-90, 90), - 0, - 0); - } - break; - - case 2: - { - CVector vecPos - ( - fX + maskMorphVerts[base+b].x, - fY + maskMorphVerts[base+b].y, - fZ + maskMorphVerts[base+b].z + 0.12f - ); - - vecPos -= 0.05f * TheCamera.GetForward(); - - CParticle::AddParticle(PARTICLE_WATER_SPARK, - vecPos, - CVector(0.0f, 0.0f, 0.0f), - nil, - 0.0f, - 15, - CGeneral::GetRandomNumberInRange(-90, 90), - 0, - 0); - } - break; - - case 3: - { - CVector vecPos - ( - fX + maskMorphVerts[base+d].x, - fY + maskMorphVerts[base+d].y, - fZ + maskMorphVerts[base+d].z + 0.12f - ); - - vecPos -= 0.05f * TheCamera.GetForward(); - - CParticle::AddParticle(PARTICLE_WATER_SPARK, - vecPos, - CVector(0.0f, 0.0f, 0.0f), - nil, - 0.0f, - 15, - CGeneral::GetRandomNumberInRange(-90, 90), - 0, - 0); - } - break; - } - } - - maskMorphNormals[base+a].x = wavyMorphNormals[idxY + (17 * idxX)].x; - maskMorphNormals[base+a].y = wavyMorphNormals[idxY + (17 * idxX)].y; - maskMorphNormals[base+a].z = wavyMorphNormals[idxY + (17 * idxX)].z; - - maskMorphNormals[base+d].x = maskMorphNormals[base+a].x; - maskMorphNormals[base+d].y = maskMorphNormals[base+a].y; - maskMorphNormals[base+d].z = maskMorphNormals[base+a].z; - - maskMorphNormals[base+c].x = maskMorphNormals[base+d].x; - maskMorphNormals[base+c].y = maskMorphNormals[base+d].y; - maskMorphNormals[base+c].z = maskMorphNormals[base+d].z; - - maskMorphNormals[base+b].x = maskMorphNormals[base+c].x; - maskMorphNormals[base+b].y = maskMorphNormals[base+c].y; - maskMorphNormals[base+b].z = maskMorphNormals[base+c].z; - - maskPreLight[base+a].red = color.red; - maskPreLight[base+a].green = color.green; - maskPreLight[base+a].blue = color.blue; - maskPreLight[base+a].alpha = color.alpha; - - maskPreLight[base+d].red = maskPreLight[base+a].red; - maskPreLight[base+d].green = maskPreLight[base+a].green; - maskPreLight[base+d].blue = maskPreLight[base+a].blue; - maskPreLight[base+d].alpha = maskPreLight[base+a].alpha; - - maskPreLight[base+c].red = maskPreLight[base+d].red; - maskPreLight[base+c].green = maskPreLight[base+d].green; - maskPreLight[base+c].blue = maskPreLight[base+d].blue; - maskPreLight[base+c].alpha = maskPreLight[base+d].alpha; - - maskPreLight[base+b].red = maskPreLight[base+c].red; - maskPreLight[base+b].green = maskPreLight[base+c].green; - maskPreLight[base+b].blue = maskPreLight[base+c].blue; - maskPreLight[base+b].alpha = maskPreLight[base+c].alpha; - -#ifndef PC_WATER - maskPreLight[base + a].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs((float)i - fXOffset) + Abs((float)j - fYOffset))))); - maskPreLight[base + b].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs((float)i - fXOffset) + Abs(16.0f + (float)j - fYOffset))))); - maskPreLight[base + c].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs(16.0f + (float)i - fXOffset) + Abs((float)j - fYOffset))))); - maskPreLight[base + d].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs(16.0f + (float)i - fXOffset) + Abs(16.0f + (float)j - fYOffset))))); -#endif - } - } - - RpGeometryUnlock(maskGeometry); - -#ifndef PC_WATER - { - RwV3d pos = { 0.0f, 0.0f, 0.0f }; - - pos.x = fX; - pos.y = fY; - pos.z = fZ + 0.05f; - - RwFrameTranslate(RpAtomicGetFrame(ms_pMaskAtomic), &pos, rwCOMBINEREPLACE); - - if (bRender) - { -#ifdef PS2 - RpSkyTexCacheFlush(); -#endif - RpAtomicRender(ms_pMaskAtomic); - } - } -#endif -} - -#ifdef PC_WATER -void -CWaterLevel::PreCalcWaterGeometry(void) -{ - if ( !RequireWavySector ) - { - WavesCalculatedThisFrame = false; - MaskCalculatedThisFrame = false; - return; - } - - RequireWavySector = false; - WavesCalculatedThisFrame = true; - - RwRGBA color; - - color.red = CTimeCycle::GetWaterRed(); - color.green = CTimeCycle::GetWaterGreen(); - color.blue = CTimeCycle::GetWaterBlue(); - color.alpha = CTimeCycle::GetWaterAlpha(); - - PreCalcWavySector(color); - - if ( CCullZones::WaterFudge() ) - { - MaskCalculatedThisFrame = false; - return; - } - - CVector CamFwdDir = TheCamera.GetForward(); - CamFwdDir.z = 0.0f; - CamFwdDir.Normalise(); - - float fCamX = TheCamera.GetPosition().x - SMALL_SECTOR_SIZE; - float fCamY = TheCamera.GetPosition().y - SMALL_SECTOR_SIZE; - - //1.4144272f; 1.4144f; - float signX = CamFwdDir.x * 1.4144272f; - float signY = CamFwdDir.y * 1.4144272f; - - signX = Clamp(signX, -1.0f, 1.0f); - fCamX += 0.4f * signX * float(SMALL_SECTOR_SIZE * 2.0f); - - signY = Clamp(signY, -1.0f, 1.0f); - fCamY += 0.4f * signY * float(SMALL_SECTOR_SIZE * 2.0f); - - int32 nBlock; - - int32 BlockX = WATER_TO_SMALL_SECTOR_X(fCamX + WATER_X_OFFSET) + 1; - int32 BlockY = WATER_TO_SMALL_SECTOR_Y(fCamY ) + 1; - - ASSERT( BlockX >= 0 && BlockX < MAX_SMALL_SECTORS ); - ASSERT( BlockY >= 0 && BlockY < MAX_SMALL_SECTORS ); - - if ( _IsColideWithBlock(BlockX, BlockY, nBlock) ) - { - float fMaskX = Floor(fCamX / 2.0f) * 2.0f; - float fMaskY = Floor(fCamY / 2.0f) * 2.0f; - - float fSectorX = WATER_FROM_SMALL_SECTOR_X(BlockX) - WATER_X_OFFSET; - float fSectorY = WATER_FROM_SMALL_SECTOR_Y(BlockY); - - if ( PreCalcWavyMask( fMaskX, fMaskY, ms_aWaterZs[nBlock], - fSectorX, fSectorY, fCamX, fCamY, CamFwdDir.x, CamFwdDir.y, color ) ) - { - PreCalculatedMaskPosn.x = fMaskX; - PreCalculatedMaskPosn.y = fMaskY; - PreCalculatedMaskPosn.z = ms_aWaterZs[nBlock] + 0.05f; - - MaskCalculatedThisFrame = true; - } - else - MaskCalculatedThisFrame = false; - } - else - MaskCalculatedThisFrame = false; -} - -bool -CWaterLevel::PreCalcWavySector(RwRGBA const &color) -{ - float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); - - RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); - - RwTexCoords *wavyTexCoords = RpGeometryGetVertexTexCoords(wavyGeometry, rwTEXTURECOORDINATEINDEX0); - RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0); - - RwRGBA *wavyPreLight = RpGeometryGetPreLightColors(wavyGeometry); - RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph); - RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph); - - if ( !m_bRenderSeaBed ) - RpGeometryLock(wavyGeometry, rpGEOMETRYLOCKVERTICES - |rpGEOMETRYLOCKNORMALS - |rpGEOMETRYLOCKPRELIGHT - |rpGEOMETRYLOCKTEXCOORDS); - - CVector camPosUp = TheCamera.GetForward(); - - float randomDampInv2 = (1.0f - fRandomDamp) * 2.0f; - - float randomMove = 1.0f / (16.0f * fRandomMoveDiv); - - float wind = CWeather::WindClipped * 0.4f + 0.2f; - float waveWind = CWeather::WindClipped * fWave2Ampl + 0.05f; - - float waveA = (TWOPI / 16.0f) - * ((CWeather::WindClipped * 0.4f + 0.2f) * (fNormalDirectionScalar1 * Abs(camPosUp.x + camPosUp.y) + fNormMult)); - - float waveB = TWOPI / (16.0f * fWave2NormScale) - * ((CWeather::WindClipped * 0.2f + 0.1f) * (fNormalDirectionScalar2 * Abs(camPosUp.y - camPosUp.x) + fNormMultB)); - - - CVector vA(1.0f, 0.0f, 0.0f); - CVector vB(0.0f, 1.0f, 0.0f); - - for ( int32 i = 0; i < 17; i++ ) - { - for ( int32 j = 0; j < 17; j++ ) - { - wavyTexCoords->u = (float(i) / 16.0f) + TEXTURE_ADDV; - wavyTexCoords->v = (float(j) / 16.0f) + TEXTURE_ADDU; - - RwRGBAAssign(wavyPreLight, &color); - - if ( i > 0 && i < 16 && j > 0 && j < 16 ) - { - wavyMorphVerts->x += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove; - wavyMorphVerts->x *= fRandomDamp; - wavyMorphVerts->x += float(i) * randomDampInv2; - - wavyMorphVerts->y += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove; - wavyMorphVerts->y *= fRandomDamp; - wavyMorphVerts->y += float(j) * randomDampInv2; - } - - float morphVertXHalf = ( i == 16 ) ? 0.0f : 0.5f * wavyMorphVerts->x; - float morphVertYHalf = ( j == 16 ) ? 0.0f : 0.5f * wavyMorphVerts->y; - - float waveMulA = (morphVertYHalf + morphVertXHalf) * (TWOPI / 16.0f) + fAngle; - float waveMulB = (morphVertYHalf - morphVertXHalf) * (TWOPI / (16.0f * fWave2InvLength)) + fAngle; - - wavyMorphVerts->z = wind * Sin(waveMulA) + waveWind * Sin(waveMulB); - - vA.z = (waveA * Cos(waveMulA)) - (waveB * Cos(waveMulB)); - vB.z = (waveA * Cos(waveMulA)) + (waveB * Cos(waveMulB)); - - CVector norm = CrossProduct(vA, vB); - norm.Normalise(); - - wavyMorphNormals->x = norm.x; - wavyMorphNormals->y = norm.y; - wavyMorphNormals->z = norm.z; - - ++wavyPreLight; - ++wavyTexCoords; - - ++wavyMorphVerts; - ++wavyMorphNormals; - } - } - - RpGeometryUnlock(wavyGeometry); - - return true; -} - -bool -CWaterLevel::PreCalcWavyMask(float fX, float fY, float fZ, - float fSectorX, float fSectorY, - float fCamPosX, float fCamPosY, - float fCamDirX, float fCamDirY, - RwRGBA const&color) -{ - CVector vecSectorPos(fX + (MAX_LARGE_SECTORS/2), fY + (MAX_LARGE_SECTORS/2), fZ + 2.0f); - - if ( COcclusion::IsAABoxOccluded(vecSectorPos, MAX_LARGE_SECTORS, MAX_LARGE_SECTORS, 4.0f) ) - return false; - - Floor(fX / MAX_LARGE_SECTORS); - Floor(fY / MAX_LARGE_SECTORS); - - RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); - RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0); - RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph); - RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph); - - RpGeometry *maskGeometry = RpAtomicGetGeometry(ms_pMaskAtomic); - RwTexCoords *maskTexCoords = RpGeometryGetVertexTexCoords(maskGeometry, rwTEXTURECOORDINATEINDEX0); - RwRGBA *maskPreLight = RpGeometryGetPreLightColors(maskGeometry); - RpMorphTarget *maskMorph = RpGeometryGetMorphTarget(maskGeometry, 0); - RwV3d *maskMorphVerts = RpMorphTargetGetVertices(maskMorph); - RwV3d *maskMorphNormals = RpMorphTargetGetVertexNormals(maskMorph); - - if ( !m_bRenderSeaBed ) - RpGeometryLock(maskGeometry, rpGEOMETRYLOCKVERTICES | rpGEOMETRYLOCKNORMALS | rpGEOMETRYLOCKPRELIGHT | rpGEOMETRYLOCKTEXCOORDS); - - - float fMinSparkZ = (fWave2Ampl * CWeather::WindClipped + 0.05f + - 0.4f * CWeather::WindClipped + 0.2) * (1.0f - 0.02f * CWeather::SunGlare); - - int32 randval = CGeneral::GetRandomNumber() & 255; - - int16 nX = _RoundValue((int32)((fX - fSectorX) * 0.5f) - 1); - int16 nY = _RoundValue((int32)((fY - fSectorY) * 0.5f) - 1); - - int16 idxX = nX; - - for ( int32 i = 0; i < 17; i++ ) - { - int16 idxY = nY; - - if ( ++idxX > 16 ) - idxX -= 16; - - for ( int32 j = 0; j < 17; j++ ) - { - if ( ++idxY > 16 ) - idxY -= 16; - - const int32 a = (0*16); - const int32 b = (1*16); - const int32 c = (33*16); - const int32 d = (34*16); - - int32 base = (i*33+j); - - maskTexCoords[base+a].v = float(j) / 32 + ((fCamPosY - fY) / 64); - maskTexCoords[base+c].v = maskTexCoords[base+a].v; - maskTexCoords[base+d].v = maskTexCoords[base+a].v + 0.5f; - maskTexCoords[base+b].v = maskTexCoords[base+d].v; - - maskTexCoords[base+a].u = float(i) / 32 + ((fCamPosX - fX) / 64); - maskTexCoords[base+b].u = maskTexCoords[base+a].u; - maskTexCoords[base+d].u = maskTexCoords[base+a].u + 0.5f; - maskTexCoords[base+c].u = maskTexCoords[base+d].u; - - maskMorphVerts[base+a].x = (wavyMorphVerts[idxY + (17 * idxX)].x - (float)idxX * 2.0f) + (float(i) * 2.0f); - maskMorphVerts[base+b].x = maskMorphVerts[base+a].x; - maskMorphVerts[base+c].x = maskMorphVerts[base+a].x + SMALL_SECTOR_SIZE; - maskMorphVerts[base+d].x = maskMorphVerts[base+c].x; - - maskMorphVerts[base+a].y = (wavyMorphVerts[idxY + (17 * idxX)].y - (float)idxY * 2.0f) + (float(j) * 2.0f); - maskMorphVerts[base+c].y = maskMorphVerts[base+a].y; - maskMorphVerts[base+b].y = maskMorphVerts[base+a].y + SMALL_SECTOR_SIZE; - maskMorphVerts[base+d].y = maskMorphVerts[base+b].y; - - maskMorphVerts[base+a].z = wavyMorphVerts[idxY + (17 * idxX)].z; - maskMorphVerts[base+d].z = maskMorphVerts[base+a].z; - maskMorphVerts[base+c].z = maskMorphVerts[base+d].z; - maskMorphVerts[base+b].z = maskMorphVerts[base+c].z; - - if ( maskMorphVerts[base].z > fMinSparkZ ) - { - switch ( (i + j + randval) & 3 ) - { - case 0: - { - CVector vecPos - ( - fX + maskMorphVerts[base+a].x, - fY + maskMorphVerts[base+a].y, - fZ + maskMorphVerts[base+a].z + 0.12f - ); - - vecPos -= 0.05f * TheCamera.GetForward(); - - CParticle::AddParticle(PARTICLE_WATER_SPARK, - vecPos, - CVector(0.0f, 0.0f, 0.0f), - nil, - 0.0f, - 15, - CGeneral::GetRandomNumberInRange(-90, 90), - 0, - 0); - } - break; - - case 1: - { - CVector vecPos - ( - fX + maskMorphVerts[base+c].x, - fY + maskMorphVerts[base+c].y, - fZ + maskMorphVerts[base+c].z + 0.12f - ); - - vecPos -= 0.05f * TheCamera.GetForward(); - - CParticle::AddParticle(PARTICLE_WATER_SPARK, - vecPos, - CVector(0.0f, 0.0f, 0.0f), - nil, - 0.0f, - 15, - CGeneral::GetRandomNumberInRange(-90, 90), - 0, - 0); - } - break; - - case 2: - { - CVector vecPos - ( - fX + maskMorphVerts[base+b].x, - fY + maskMorphVerts[base+b].y, - fZ + maskMorphVerts[base+b].z + 0.12f - ); - - vecPos -= 0.05f * TheCamera.GetForward(); - - CParticle::AddParticle(PARTICLE_WATER_SPARK, - vecPos, - CVector(0.0f, 0.0f, 0.0f), - nil, - 0.0f, - 15, - CGeneral::GetRandomNumberInRange(-90, 90), - 0, - 0); - } - break; - - case 3: - { - CVector vecPos - ( - fX + maskMorphVerts[base+d].x, - fY + maskMorphVerts[base+d].y, - fZ + maskMorphVerts[base+d].z + 0.12f - ); - - vecPos -= 0.05f * TheCamera.GetForward(); - - CParticle::AddParticle(PARTICLE_WATER_SPARK, - vecPos, - CVector(0.0f, 0.0f, 0.0f), - nil, - 0.0f, - 15, - CGeneral::GetRandomNumberInRange(-90, 90), - 0, - 0); - } - break; - } - } - - maskMorphNormals[base+a].x = wavyMorphNormals[idxY + (17 * idxX)].x; - maskMorphNormals[base+a].y = wavyMorphNormals[idxY + (17 * idxX)].y; - maskMorphNormals[base+a].z = wavyMorphNormals[idxY + (17 * idxX)].z; - - maskMorphNormals[base+d].x = maskMorphNormals[base+a].x; - maskMorphNormals[base+d].y = maskMorphNormals[base+a].y; - maskMorphNormals[base+d].z = maskMorphNormals[base+a].z; - - maskMorphNormals[base+c].x = maskMorphNormals[base+d].x; - maskMorphNormals[base+c].y = maskMorphNormals[base+d].y; - maskMorphNormals[base+c].z = maskMorphNormals[base+d].z; - - maskMorphNormals[base+b].x = maskMorphNormals[base+c].x; - maskMorphNormals[base+b].y = maskMorphNormals[base+c].y; - maskMorphNormals[base+b].z = maskMorphNormals[base+c].z; - - maskPreLight[base+a].red = color.red; - maskPreLight[base+a].green = color.green; - maskPreLight[base+a].blue = color.blue; - maskPreLight[base+a].alpha = color.alpha; - - maskPreLight[base+d].red = maskPreLight[base+a].red; - maskPreLight[base+d].green = maskPreLight[base+a].green; - maskPreLight[base+d].blue = maskPreLight[base+a].blue; - maskPreLight[base+d].alpha = maskPreLight[base+a].alpha; - - maskPreLight[base+c].red = maskPreLight[base+d].red; - maskPreLight[base+c].green = maskPreLight[base+d].green; - maskPreLight[base+c].blue = maskPreLight[base+d].blue; - maskPreLight[base+c].alpha = maskPreLight[base+d].alpha; - - maskPreLight[base+b].red = maskPreLight[base+c].red; - maskPreLight[base+b].green = maskPreLight[base+c].green; - maskPreLight[base+b].blue = maskPreLight[base+c].blue; - maskPreLight[base+b].alpha = maskPreLight[base+c].alpha; - } - } - - RpGeometryUnlock(maskGeometry); - return true; -} -#endif - -void -CWaterLevel::RenderBoatWakes(void) -{ - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterWakeRaster); -#ifndef PC_WATER - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); -#endif - -#ifdef _XBOX - // TODO save and restore rwRENDERSTATESRCBLEND rwRENDERSTATEDESTBLEND -#endif - - CBoat::FillBoatList(); - - float fWakeZ = 5.97f; - float fWakeLifeTimeMult = 0.01f / CBoat::WAKE_LIFETIME; - - for ( int32 idx = 0; idx < ARRAY_SIZE(CBoat::apFrameWakeGeneratingBoats); idx++ ) - { - CBoat *pBoat = CBoat::apFrameWakeGeneratingBoats[idx]; - - if ( pBoat == nil ) - break; - - CVector2D vecDistA(pBoat->GetForward().x, pBoat->GetForward().y); - - - float fSize = pBoat->GetColModel()->boundingBox.max.z - * 0.65f; - - if ( pBoat->GetModelIndex() == MI_SKIMMER) - fSize *= 0.4f; - - float fAplhaA = 255.0f; - float fSizeA = fSize; - float fAplhaB; - float fSizeB; - - for ( int32 wake = 1; wake < pBoat->m_nNumWakePoints; wake++ ) - { - bool bRender = true; - - float fTimeleft = CBoat::WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[wake]; - - float fWakeSizeB = ((float)wake * 0.19f) + fSize - fWakeLifeTimeMult * Max(fTimeleft, 0.0f); - - fSizeB = fWakeSizeB / CBoat::MIN_WAKE_INTERVAL; - if ( fSizeB < 0.0f ) - fSizeB = 1.0f; - - if ( wake == pBoat->m_nNumWakePoints - 1 ) - { - // set alpha to 0 if it's last point - fAplhaB = 0.0f; - } - else - { - // clip (-100, 500), less lifetime - less val - float val = 500.0f - (CBoat::WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[wake]) - * 600.0f / CBoat::WAKE_LIFETIME; - - fAplhaB = Clamp(val, 0.0f, 255.0f); - } - - CVector2D vecDistB = pBoat->m_avec2dWakePoints[wake - 1] - pBoat->m_avec2dWakePoints[wake]; - - float fScal = vecDistB.MagnitudeSqr(); - - // normalize if distance between points is greater than 3 - - if ( fScal > SQR(3.0f) ) - { - float fNorm = 1.0f / sqrt(fScal); - - vecDistB.x *= fNorm; - vecDistB.y *= fNorm; - - // disable render if distance between points too big - - if ( sqrt(fScal) > 13.0f ) - bRender = false; - } - - CVector2D vecAA - ( - pBoat->m_avec2dWakePoints[wake - 1].x - (fSizeA * vecDistA.y), - pBoat->m_avec2dWakePoints[wake - 1].y + (fSizeA * vecDistA.x) - ); - CVector2D vecAB - ( - pBoat->m_avec2dWakePoints[wake - 1].x + (fSizeA * vecDistA.y), - pBoat->m_avec2dWakePoints[wake - 1].y - (fSizeA * vecDistA.x) - ); - CVector2D vecBA - ( - pBoat->m_avec2dWakePoints[wake].x + (fSizeB * vecDistB.y), - pBoat->m_avec2dWakePoints[wake].y - (fSizeB * vecDistB.x) - ); - CVector2D vecBB - ( - pBoat->m_avec2dWakePoints[wake].x - (fSizeB * vecDistB.y), - pBoat->m_avec2dWakePoints[wake].y + (fSizeB * vecDistB.x) - ); - - if ( bRender ) - RenderWakeSegment(vecAA, vecAB, vecBA, vecBB, fSizeA, fSizeB, fAplhaA, fAplhaB, fWakeZ); - - vecDistA = vecDistB; - fSizeA = fSizeB; - - fAplhaB = fAplhaA; - } - } - - RenderAndEmptyRenderBuffer(); -} - -inline float -_GetWindedWave(float fX, float fY) -{ - float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); - float x = WATER_HUGE_X(fX + WATER_X_OFFSET); - float y = WATER_HUGE_Y(fY); - - float fWindFactor (CWeather::WindClipped * 0.4f + 0.2f); - float fWave = Sin(( (x - Floor(x)) + (y - Floor(y)) ) * TWOPI + fAngle); - - return fWindFactor * fWave; -} - -void -CWaterLevel::RenderWakeSegment(CVector2D &vecA, CVector2D &vecB, CVector2D &vecC, CVector2D &vecD, - float &fSizeA, float &fSizeB, - float &fAlphaA, float &fAlphaB, - float &fWakeZ) -{ - for ( int32 i = 0; i < 4; i++ ) - { - if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) - RenderAndEmptyRenderBuffer(); - - float fCurStep = (float)i / 4; - float fNxtStep = (float)(i + 1) / 4; - - float fLeftCurStep = 1.0f - fCurStep; - float fLeftNxtStep = 1.0f - fNxtStep; - - uint8 AlphaA = (uint32)(fAlphaA * aAlphaFade[i] ); - uint8 AlphaB = (uint32)(fAlphaA * aAlphaFade[i + 1]); - uint8 AlphaC = (uint32)(fAlphaB * aAlphaFade[i + 1]); - uint8 AlphaD = (uint32)(fAlphaB * aAlphaFade[i] ); - - CVector2D PosA = vecB*fCurStep + vecA*fLeftCurStep; - CVector2D PosB = vecB*fNxtStep + vecA*fLeftNxtStep; - CVector2D PosC = vecC*fNxtStep + vecD*fLeftNxtStep; - CVector2D PosD = vecC*fCurStep + vecD*fLeftCurStep; - - float fUA = (PosA.x / 4) + _TEXTURE_WAKE_ADDU; - float fVA = (PosA.y / 4) + _TEXTURE_WAKE_ADDV; - - float fUB = (PosB.x / 4) + _TEXTURE_WAKE_ADDU; - float fVB = (PosB.y / 4) + _TEXTURE_WAKE_ADDV; - - float fUC = (PosC.x / 4) + _TEXTURE_WAKE_ADDU; - float fVC = (PosC.y / 4) + _TEXTURE_WAKE_ADDV; - - float fUD = (PosD.x / 4) + _TEXTURE_WAKE_ADDU; - float fVD = (PosD.y / 4) + _TEXTURE_WAKE_ADDV; - -#define MIN4(a, b, c, d) (Min((a), Min((b), Min((c), (d))))) - float fMinU = Floor(MIN4(fUA, fUB, fUC, fUD)); - float fMinV = Floor(MIN4(fVA, fVB, fVC, fVD)); -#undef MIN4 - - float fZA = _GetWindedWave(PosA.x, PosA.y) + fWakeZ; - float fZB = _GetWindedWave(PosB.x, PosB.y) + fWakeZ; - float fZC = _GetWindedWave(PosC.x, PosC.y) + fWakeZ; - float fZD = _GetWindedWave(PosD.x, PosD.y) + fWakeZ; - - int32 vidx = TempBufferVerticesStored; - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], PosA.x, PosA.y, fZA); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], fUA - fMinU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], fVA - fMinV); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 0], 255, 255, 255, AlphaA); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], PosB.x, PosB.y, fZB); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], fUB - fMinU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], fVB - fMinV); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 1], 255, 255, 255, AlphaB); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], PosC.x, PosC.y, fZC); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], fUC - fMinU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], fVC - fMinV); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 2], 255, 255, 255, AlphaC); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], PosD.x, PosD.y, fZD); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], fUD - fMinU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], fVD - fMinV); - RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 3], 255, 255, 255, AlphaD); - - int32 iidx = TempBufferIndicesStored; - - TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; - TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; - TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; - TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; - - TempBufferVerticesStored += 4; - - TempBufferIndicesStored += 6; - } -} - -void -CWaterLevel::RenderOneSlopedUnderWaterPoly(float fX, float fY, float fZ, RwRGBA const&color) -{ - CVector2D camPos(TheCamera.GetPosition().x, TheCamera.GetPosition().y); - - float fDistA = (CVector2D(fX, fY) - camPos).Magnitude() + -140.0f; - float fDistB = (CVector2D(fX, fY + HUGE_SECTOR_SIZE) - camPos).Magnitude() + -140.0f; - float fDistC = (CVector2D(fX + HUGE_SECTOR_SIZE, fY + HUGE_SECTOR_SIZE) - camPos).Magnitude() + -140.0f; - float fDistD = (CVector2D(fX + HUGE_SECTOR_SIZE, fY) - camPos).Magnitude() + -140.0f; - -#ifndef PC_WATER -#define CALCSEABED(v, d) \ - { \ - if ( d < 0.0f ) \ - v = 0.1f + fSeaBedZ; \ - else if ( d > 240.0f ) \ - v = 0.1f; \ - else \ - v = 0.1f + ((fSeaBedZ * (240.0f - d)) / 240.0f); \ - } -#else - #define CALCSEABED(v, d) \ - { \ - v = 0.1f; \ - if ( d < 0.0f ) \ - v += fSeaBedZ; \ - else if ( d <= 240.0f ) \ - v += (fSeaBedZ / 240.0f) * (240.0f - d); \ - } -#endif - float fSeaBedA, fSeaBedB, fSeaBedC, fSeaBedD; - - CALCSEABED(fSeaBedA, fDistA); - CALCSEABED(fSeaBedB, fDistB); - CALCSEABED(fSeaBedC, fDistC); - CALCSEABED(fSeaBedD, fDistD); - - #undef CALCSEABED - - if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) - RenderAndEmptyRenderBuffer(); - - int32 vidx = TempBufferVerticesStored; - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset - fSeaBedA); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], 0.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], 0.0f); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 0], color.red, color.green, color.blue, 255); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset - fSeaBedB); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], 0.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], 4.0f); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 1], color.red, color.green, color.blue, 255); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + HUGE_SECTOR_SIZE, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset - fSeaBedC); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], 4.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], 4.0f); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 2], color.red, color.green, color.blue, 255); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + HUGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset - fSeaBedD); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], 4.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], 0.0f); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 3], color.red, color.green, color.blue, 255); - - int32 iidx = TempBufferIndicesStored; - - TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; - TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; - TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; - TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; - - TempBufferVerticesStored += 4; - - TempBufferIndicesStored += 6; -} - -void -CWaterLevel::RenderOneFlatSmallWaterPolyBlended(float fX, float fY, float fZ, float fCamX, float fCamY, - RwRGBA const &color, RwRGBA const &colorTrans, - float fDrawDist) -{ - if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) - RenderAndEmptyRenderBuffer(); - - int32 vidx = TempBufferVerticesStored; - - float fBlendDrawDist = fDrawDist + fStartBlendDistanceAdd; - - float fDistStartX = SQR(fX - fCamX); - float fDistStartY = SQR(fY - fCamY); - float fDistEndX = SQR((fX + SMALL_SECTOR_SIZE) - fCamX); - float fDistEndY = SQR((fY + SMALL_SECTOR_SIZE) - fCamY); - - - float fAlphaBlendMulA - = Min(fFlatWaterBlendRange * Max(sqrt(fDistStartX + fDistStartY) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f); - float fAlphaBlendMulB - = Min(fFlatWaterBlendRange * Max(sqrt(fDistStartX + fDistEndY ) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f); - float fAlphaBlendMulC - = Min(fFlatWaterBlendRange * Max(sqrt(fDistEndX + fDistEndY ) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f); - float fAlphaBlendMulD - = Min(fFlatWaterBlendRange * Max(sqrt(fDistEndX + fDistStartY) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f); - - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 0], color.red, color.green, color.blue, - (colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulA)); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 1.0f); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 1], color.red, color.green, color.blue, - (colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulB)); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + SMALL_SECTOR_SIZE, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 1.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 1.0f); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 2], color.red, color.green, color.blue, - (colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulC)); - - RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + SMALL_SECTOR_SIZE, fY, fZ - _fWaterZOffset); - RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 1.0f); - RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 3], color.red, color.green, color.blue, - (colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulD)); - - - int32 iidx = TempBufferIndicesStored; - - TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; - TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; - TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; - TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; - - TempBufferVerticesStored += 4; - - TempBufferIndicesStored += 6; -} - -float -CWaterLevel::CalcDistanceToWater(float fX, float fY) -{ - const float fSectorMaxRenderDist = 250.0f; - - int32 nStartX = WATER_TO_SMALL_SECTOR_X(fX - fSectorMaxRenderDist + WATER_X_OFFSET) - 1; - int32 nEndX = WATER_TO_SMALL_SECTOR_X(fX + fSectorMaxRenderDist + WATER_X_OFFSET) + 1; - int32 nStartY = WATER_TO_SMALL_SECTOR_Y(fY - fSectorMaxRenderDist) - 1; - int32 nEndY = WATER_TO_SMALL_SECTOR_Y(fY + fSectorMaxRenderDist) + 1; - - nStartX = Clamp(nStartX, 0, MAX_SMALL_SECTORS - 1); - nEndX = Clamp(nEndX, 0, MAX_SMALL_SECTORS - 1); - nStartY = Clamp(nStartY, 0, MAX_SMALL_SECTORS - 1); - nEndY = Clamp(nEndY, 0, MAX_SMALL_SECTORS - 1); - - float fDistSqr = 1.0e10f; - - for ( int32 x = nStartX; x <= nEndX; x++ ) - { - for ( int32 y = nStartY; y <= nEndY; y++ ) - { - if ( aWaterFineBlockList[x][y] >= 0 ) - { - float fSectorX = WATER_FROM_SMALL_SECTOR_X(x) - WATER_X_OFFSET; - float fSectorY = WATER_FROM_SMALL_SECTOR_Y(y); - - CVector2D vecDist - ( - fSectorX + SMALL_SECTOR_SIZE - fX, - fSectorY + SMALL_SECTOR_SIZE - fY - ); - - fDistSqr = Min(vecDist.MagnitudeSqr(), fDistSqr); - } - } - } - - return Clamp(Sqrt(fDistSqr) - 23.0f, 0.0f, fSectorMaxRenderDist); -} - -void -CWaterLevel::RenderAndEmptyRenderBuffer() -{ - if ( TempBufferVerticesStored ) - { - LittleTest(); - - if ( RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV) ) - { - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); - RwIm3DEnd(); - } - } - - TempBufferIndicesStored = 0; - TempBufferVerticesStored = 0; -} - -bool -CWaterLevel::GetGroundLevel(CVector const &vecPosn, float *pfOutLevel, ColData *pData, float fDistance) -{ - CColPoint point; - CEntity *entity; - - if ( !CWorld::ProcessVerticalLine(vecPosn + CVector(0.0f, 0.0f, fDistance), - -fDistance, point, entity, true, false, false, false, true, false, nil) ) - return false; - - *pfOutLevel = point.point.z; - - if ( pData != nil ) - { - pData->SurfaceType = point.surfaceB; - pData->PieceType = point.pieceB; - } - - return true; -} - -bool -CWaterLevel::IsLocationOutOfWorldBounds_WS(CVector const &vecPosn, int nOffset) -{ - int32 x = int32((vecPosn.x / 50.0f) + 48.0f); - int32 y = int32((vecPosn.y / 50.0f) + 40.0f); - - return x < nOffset || x >= 80 - nOffset || y < nOffset || y >= 80 - nOffset; -} - -bool -CWaterLevel::GetGroundLevel_WS(CVector const &vecPosn, float *pfOutLevel, ColData *pData, float fDistance) -{ - if ( IsLocationOutOfWorldBounds_WS(vecPosn, 0) ) - return false; - else - return GetGroundLevel(vecPosn, pfOutLevel, pData, fDistance); -} - -bool -CWaterLevel::GetWaterDepth(CVector const &vecPosn, float *pfDepth, float *pfLevelNoWaves, float *pfGroundLevel) -{ - float fLevelNoWaves; - float fGroundLevel; - - if ( !GetWaterLevelNoWaves(vecPosn.x, vecPosn.y, vecPosn.z, &fLevelNoWaves) ) - return false; - - if ( !GetGroundLevel(vecPosn, &fGroundLevel, nil, 30.0f) ) - fGroundLevel = -100.0; - - if ( pfDepth != nil ) - *pfDepth = fLevelNoWaves - fGroundLevel; - - if ( pfLevelNoWaves != nil ) - *pfLevelNoWaves = fLevelNoWaves; - - if ( pfGroundLevel != nil ) - *pfGroundLevel = fGroundLevel; - - return true; -} - -void -CWaterLevel::RenderSeaBirds() -{ - CVector cur_pos = TheCamera.GetPosition(); - - if ( !CCullZones::CamNoRain() - && !CCullZones::PlayerNoRain() - && (CWeather::NewWeatherType == WEATHER_SUNNY || CWeather::NewWeatherType == WEATHER_EXTRA_SUNNY) - && CClock::ms_nGameClockHours > 6 && CClock::ms_nGameClockHours < 20 ) - { - static CVector prev_pos(0.0f, 0.0f, 0.0f); - static CVector prev_front(0.0f, 0.0f, 0.0f); - static int32 timecounter; - - if ( Abs(prev_pos.x - cur_pos.x) + Abs(prev_pos.y - cur_pos.y) + Abs(prev_pos.z - cur_pos.z) > 1.5f ) - { - prev_pos = cur_pos; - timecounter = CTimer::GetTimeInMilliseconds(); - } - else if ( (CTimer::GetTimeInMilliseconds() - timecounter) > 5000 ) - { - static int32 birdgenTime = 0; - - if ( (CTimer::GetTimeInMilliseconds() - birdgenTime) > 1000 ) - { - birdgenTime = CTimer::GetTimeInMilliseconds(); - - CVector vecPos = cur_pos; - - float fAngle = CGeneral::GetRandomNumberInRange(90.0f, 150.0f); - - uint16 nSinCosIdx = CGeneral::GetRandomNumber() % (CParticle::SIN_COS_TABLE_SIZE-1); - - float fCos = CParticle::Cos(nSinCosIdx); - float fSin = CParticle::Sin(nSinCosIdx); - - vecPos.x += (fCos - fSin) * fAngle; - vecPos.y += (fSin + fCos) * fAngle; - vecPos.z += CGeneral::GetRandomNumberInRange(10.0f, 30.0f); - - CVector vecDir(CGeneral::GetRandomNumberInRange(-1.0f, 1.0f), - CGeneral::GetRandomNumberInRange(-1.0f, 1.0f), - 0.0f); - - CParticle::AddParticle(PARTICLE_BIRD_FRONT, vecPos, vecDir, nil, 0.0f, 0, 0, 0, 0); - } - } - } -} - -void -CWaterLevel::RenderShipsOnHorizon() -{ -#ifdef FIX_BUGS - CVector cur_pos = FindPlayerCoors(); -#else - CVector cur_pos = FindPlayerPed()->GetPosition(); -#endif - - static CVector prev_pos(0.0f, 0.0f, 0.0f); - static CVector prev_front(0.0f, 0.0f, 0.0f); - static int32 timecounter; - - if ( Abs(prev_pos.x - cur_pos.x) + Abs(prev_pos.y - cur_pos.y) + Abs(prev_pos.z - cur_pos.z) > 1.5f ) - { - prev_pos = cur_pos; - timecounter = CTimer::GetTimeInMilliseconds(); - } - else if ( (CTimer::GetTimeInMilliseconds() - timecounter) > 5000 ) - { - static int32 shipgenTime = 0; - - if ( (CTimer::GetTimeInMilliseconds() - shipgenTime) > 4000 ) - { - shipgenTime = CTimer::GetTimeInMilliseconds(); - - CVector vecPos = cur_pos; - - float fAngle = CGeneral::GetRandomNumberInRange(450.0f, 750.0f); - - uint16 nSinCosIdx = CGeneral::GetRandomNumber() % (CParticle::SIN_COS_TABLE_SIZE-1); - - float fCos = CParticle::Cos(nSinCosIdx); - float fSin = CParticle::Sin(nSinCosIdx); - - vecPos.x += (fCos - fSin) * fAngle; - vecPos.y += (fSin + fCos) * fAngle; - - float fLevelNoWaves; - - if ( GetWaterLevelNoWaves(vecPos.x, vecPos.y, vecPos.z, &fLevelNoWaves) ) - { - if ( IsLocationOutOfWorldBounds_WS(vecPos, 1) ) - { - vecPos.z = fLevelNoWaves + 9.5f; - - CVector vecDir - ( - CGeneral::GetRandomNumberInRange(-0.1f, 0.1f), - 0.0f, - 0.0f - ); - - CParticle::AddParticle(PARTICLE_SHIP_SIDE, vecPos, vecDir, - nil, 0.0f, 0, 0, CGeneral::GetRandomNumber() & 7, 0); - } - } - } - } -} - -void -CWaterLevel::HandleSeaLifeForms() -{ - if ( CReplay::IsPlayingBack() ) - return; - - CVector cur_pos = FindPlayerPed()->GetPosition(); - - static CVector prev_pos(0.0f, 0.0f, 0.0f); - static int32 timecounter; - - if ( Abs(prev_pos.x - cur_pos.x) + Abs(prev_pos.y - cur_pos.y) + Abs(prev_pos.z - cur_pos.z) > 1.5f ) - { - prev_pos = cur_pos; - timecounter = CTimer::GetTimeInMilliseconds(); - } - else if ( (CTimer::GetTimeInMilliseconds() - timecounter) > 5000 ) - { - if ( CWaterCreatures::IsSpaceForMoreWaterCreatures() ) - { - for ( int32 i = 0; i < 3; i++ ) - { - CVector vecPos = cur_pos; - - float fAngle = CGeneral::GetRandomNumberInRange(15.0f, 30.0f); - - uint16 nSinCosIdx = CGeneral::GetRandomNumber() % (CParticle::SIN_COS_TABLE_SIZE-1); - - float fCos = CParticle::Cos(nSinCosIdx); - float fSin = CParticle::Sin(nSinCosIdx); - - vecPos.x += (fCos - fSin) * fAngle; - vecPos.y += (fSin + fCos) * fAngle; - - CWaterCreatures::CreateOne(vecPos, -1); - } - } - } - - CWaterCreatures::UpdateAll(); -} - -void -CWaterLevel::HandleBeachToysStuff(void) -{ -#ifdef FIX_BUGS - CVector cur_pos = FindPlayerCoors(); -#else - CVector cur_pos = FindPlayerPed()->GetPosition(); -#endif - - static bool bBeachBallInit = true; - static CVector FirstBeachBallPos = cur_pos; - static bool bLoungeInit = true; - static CVector FirstLoungePos = cur_pos; - static CVector prev_pos(0.0f, 0.0f, 0.0f); - static int32 timecounter; - - if ( Abs(prev_pos.x - cur_pos.x) + Abs(prev_pos.y - cur_pos.y) + Abs(prev_pos.z - cur_pos.z) > 1.5f ) - { - prev_pos = cur_pos; - timecounter = CTimer::GetTimeInMilliseconds(); - } - else if ( (CTimer::GetTimeInMilliseconds() - timecounter) > 5000 ) - { - static int32 toygenTime = CTimer::GetTimeInMilliseconds(); - - if ( (CTimer::GetTimeInMilliseconds() - toygenTime) > 20000 ) - { - toygenTime = CTimer::GetTimeInMilliseconds(); - - if ( bBeachBallInit || (cur_pos - FirstBeachBallPos).MagnitudeSqr() > 6400.0f ) - { - for ( int32 i = 0; i < 3; i++ ) - { - CVector vecPos = cur_pos; - - float fAngle = CGeneral::GetRandomNumberInRange(20.0f, 35.0f); - - uint16 nSinCosIdx = CGeneral::GetRandomNumber() % (CParticle::SIN_COS_TABLE_SIZE-1); - - float fCos = CParticle::Cos(nSinCosIdx); - float fSin = CParticle::Sin(nSinCosIdx); - - vecPos.x += (fCos - fSin) * fAngle; - vecPos.y += (fSin + fCos) * fAngle; - - if ( TheCamera.IsSphereVisible(vecPos, 1.0f) ) - { - float fWaterLevel; - - if ( !GetWaterLevel(vecPos.x, vecPos.y, vecPos.z, &fWaterLevel, false) ) - { - float fGroundLevel; - ColData coldata; - - if ( GetGroundLevel(vecPos, &fGroundLevel, &coldata, 30.0f) ) - { - if ( coldata.SurfaceType == SURFACE_SAND ) - { - CEntity *toy = CreateBeachToy(vecPos, BEACHTOY_BALL); - - if ( toy ) - { - FirstBeachBallPos = cur_pos; - bBeachBallInit = false; - i = 10; - } - } - } - } - } - } - } - - if ( bLoungeInit || (cur_pos - FirstLoungePos).MagnitudeSqr() > 6400.0f ) - { - for ( int32 i = 0; i < 5; i++ ) - { - CVector vecPos = cur_pos; - - float fAngle = CGeneral::GetRandomNumberInRange(20.0f, 35.0f); - - uint16 nSinCosIdx = CGeneral::GetRandomNumber() % (CParticle::SIN_COS_TABLE_SIZE-1); - - float fCos = CParticle::Cos(nSinCosIdx); - float fSin = CParticle::Sin(nSinCosIdx); - - vecPos.x += (fCos - fSin) * fAngle; - vecPos.y += (fSin + fCos) * fAngle; - - if ( TheCamera.IsSphereVisible(vecPos, 2.0f) ) - { - float fWaterLevel; - - if ( !GetWaterLevel(vecPos.x, vecPos.y, vecPos.z, &fWaterLevel, false) ) - { - float fGroundLevel; - ColData coldata; - - if ( GetGroundLevel(vecPos, &fGroundLevel, &coldata, 30.0f) ) - { - if ( coldata.SurfaceType == SURFACE_SAND ) - { - CEntity *toy = CreateBeachToy(vecPos, BEACHTOY_ANY_LOUNGE); - if ( toy ) - { - toy->SetHeading(DEGTORAD(CGeneral::GetRandomNumberInRange(0.0f, 359.0f))); - FirstLoungePos = cur_pos; - bLoungeInit = false; - } - } - } - } - } - } - } - } - } -} - -CEntity * -CWaterLevel::CreateBeachToy(CVector const &vec, eBeachToy beachtoy) -{ - if (CObject::nNoTempObjects >= NUMTEMPOBJECTS) - return nil; - - int finalToy = beachtoy; - bool isStatic = false; - int model = MI_BEACHBALL; - switch (beachtoy) { - case BEACHTOY_ANY_LOUNGE: - switch ( CGeneral::GetRandomNumber() & 7 ) { - case 1: - case 7: - finalToy = BEACHTOY_LOUNGE_WOOD_UP; - break; - case 3: - case 5: - finalToy = BEACHTOY_LOUNGE_TOWEL_UP; - break; - default: - finalToy = BEACHTOY_LOUNGE_WOOD_ON; - break; - } - break; - case BEACHTOY_ANY_TOWEL: - switch ( CGeneral::GetRandomNumber() & 7 ) { - case 1: - case 7: - finalToy = BEACHTOY_TOWEL2; - break; - case 2: - case 6: - finalToy = BEACHTOY_TOWEL3; - break; - case 3: - case 5: - finalToy = BEACHTOY_TOWEL4; - break; - default: - finalToy = BEACHTOY_TOWEL1; - break; - } - if (CObject::nNoTempObjects >= 35) { - return nil; - } - default: - break; - } - switch (finalToy) { - case BEACHTOY_BALL: - isStatic = false; - model = MI_BEACHBALL; - break; - case BEACHTOY_LOUNGE_WOOD_UP: - isStatic = false; - model = MI_LOUNGE_WOOD_UP; - break; - case BEACHTOY_LOUNGE_TOWEL_UP: - isStatic = false; - model = MI_LOUNGE_TOWEL_UP; - break; - case BEACHTOY_LOUNGE_WOOD_ON: - isStatic = false; - model = MI_LOUNGE_WOOD_DN; - break; - case BEACHTOY_LOTION: - model = MI_LOTION; - isStatic = true; - break; - case BEACHTOY_TOWEL1: - model = MI_BEACHTOWEL01; - isStatic = true; - break; - case BEACHTOY_TOWEL2: - model = MI_BEACHTOWEL02; - isStatic = true; - break; - case BEACHTOY_TOWEL3: - model = MI_BEACHTOWEL03; - isStatic = true; - break; - case BEACHTOY_TOWEL4: - model = MI_BEACHTOWEL04; - isStatic = true; - break; - default: - break; - } - CObject *toy = new CObject(model, true); - if (toy) { - toy->SetPosition(vec); - toy->GetMatrix().UpdateRW(); - toy->m_vecMoveSpeed = CVector(0.f, 0.f, 0.f); - toy->m_vecTurnSpeed = CVector(0.f, 0.f, 0.f); - toy->ObjectCreatedBy = TEMP_OBJECT; - toy->bIsStatic = isStatic; - CObject::nNoTempObjects++; - toy->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 43200000; - CWorld::Add(toy); - return toy; - } else - return nil; -} \ No newline at end of file diff --git a/src/render/WaterLevel.h b/src/render/WaterLevel.h deleted file mode 100644 index 6d6614d8..00000000 --- a/src/render/WaterLevel.h +++ /dev/null @@ -1,184 +0,0 @@ -#pragma once - -#define WATER_X_OFFSET (400.0f) - -#define WATER_Z_OFFSET (0.5f) - -#define NO_WATER -128 - -#define MAX_SMALL_SECTORS 128 -#define MAX_LARGE_SECTORS 64 -#define MAX_HUGE_SECTORS 32 -#define MAX_EXTRAHUGE_SECTORS 16 - -#define SMALL_SECTOR_SIZE 32 -#define LARGE_SECTOR_SIZE 64 -#define HUGE_SECTOR_SIZE 128 -#define EXTRAHUGE_SECTOR_SIZE 256 - -#define WATER_START_X -2048.0f -#define WATER_END_X 2048.0f - -#define WATER_START_Y -2048.0f -#define WATER_END_Y 2048.0f - -#define WATER_WIDTH ((WATER_END_X - WATER_START_X)) -#define WATER_HEIGHT ((WATER_END_Y - WATER_START_Y)) - -#define WATER_UNSIGN_X(x) ( (x) + (WATER_WIDTH /2) ) -#define WATER_UNSIGN_Y(y) ( (y) + (WATER_HEIGHT/2) ) -#define WATER_SIGN_X(x) ( (x) - (WATER_WIDTH /2) ) -#define WATER_SIGN_Y(y) ( (y) - (WATER_HEIGHT/2) ) - -// 64x64 Large blocks 64x64 each -#define WATER_TO_BLOCK_X(x) ( WATER_UNSIGN_X(x) / WATER_BLOCK_SECTORS ) -#define WATER_TO_BLOCK_Y(x) ( WATER_UNSIGN_Y(x) / WATER_BLOCK_SECTORS ) - -// 128x128 Small blocks 32x32 each -#define WATER_TO_FINEBLOCK_X(x) ( WATER_UNSIGN_X(x) / WATER_FINEBLOCK_SECTORS ) -#define WATER_TO_FINEBLOCK_Y(x) ( WATER_UNSIGN_Y(x) / WATER_FINEBLOCK_SECTORS ) - -// 32 -#define WATER_SMALL_X(x) ( WATER_UNSIGN_X(x) / MAX_SMALL_SECTORS ) -#define WATER_SMALL_Y(y) ( WATER_UNSIGN_Y(y) / MAX_SMALL_SECTORS ) -#define WATER_FROM_SMALL_SECTOR_X(x) ( ((x) - (MAX_SMALL_SECTORS/2) ) * SMALL_SECTOR_SIZE ) -#define WATER_FROM_SMALL_SECTOR_Y(y) ( ((y) - (MAX_SMALL_SECTORS/2) ) * SMALL_SECTOR_SIZE ) -#define WATER_TO_SMALL_SECTOR_X(x) ( WATER_UNSIGN_X(x) / SMALL_SECTOR_SIZE ) -#define WATER_TO_SMALL_SECTOR_Y(y) ( WATER_UNSIGN_Y(y) / SMALL_SECTOR_SIZE ) - -// 64 -#define WATER_LARGE_X(x) ( WATER_UNSIGN_X(x) / MAX_LARGE_SECTORS ) -#define WATER_LARGE_Y(y) ( WATER_UNSIGN_Y(y) / MAX_LARGE_SECTORS ) -#define WATER_FROM_LARGE_SECTOR_X(x) ( ((x) - (MAX_LARGE_SECTORS/2) ) * LARGE_SECTOR_SIZE ) -#define WATER_FROM_LARGE_SECTOR_Y(y) ( ((y) - (MAX_LARGE_SECTORS/2) ) * LARGE_SECTOR_SIZE ) -#define WATER_TO_LARGE_SECTOR_X(x) ( WATER_UNSIGN_X(x) / LARGE_SECTOR_SIZE ) -#define WATER_TO_LARGE_SECTOR_Y(y) ( WATER_UNSIGN_Y(y) / LARGE_SECTOR_SIZE ) - -// 128 -#define WATER_HUGE_X(x) ( WATER_UNSIGN_X(x) / MAX_HUGE_SECTORS ) -#define WATER_HUGE_Y(y) ( WATER_UNSIGN_Y(y) / MAX_HUGE_SECTORS ) -#define WATER_FROM_HUGE_SECTOR_X(x) ( ((x) - (MAX_HUGE_SECTORS/2) ) * HUGE_SECTOR_SIZE ) -#define WATER_FROM_HUGE_SECTOR_Y(y) ( ((y) - (MAX_HUGE_SECTORS/2) ) * HUGE_SECTOR_SIZE ) -#define WATER_TO_HUGE_SECTOR_X(x) ( WATER_UNSIGN_X(x) / HUGE_SECTOR_SIZE ) -#define WATER_TO_HUGE_SECTOR_Y(y) ( WATER_UNSIGN_Y(y) / HUGE_SECTOR_SIZE ) - -// 256 -#define WATER_EXTRAHUGE_X(x) ( WATER_UNSIGN_X(x) / MAX_EXTRAHUGE_SECTORS ) -#define WATER_EXTRAHUGE_Y(y) ( WATER_UNSIGN_Y(y) / MAX_EXTRAHUGE_SECTORS ) -#define WATER_FROM_EXTRAHUGE_SECTOR_X(x) ( ((x) - (MAX_EXTRAHUGE_SECTORS/2)) * EXTRAHUGE_SECTOR_SIZE ) -#define WATER_FROM_EXTRAHUGE_SECTOR_Y(y) ( ((y) - (MAX_EXTRAHUGE_SECTORS/2)) * EXTRAHUGE_SECTOR_SIZE ) -#define WATER_TO_EXTRAHUGE_SECTOR_X(x) ( WATER_UNSIGN_X(x) / EXTRAHUGE_SECTOR_SIZE ) -#define WATER_TO_EXTRAHUGE_SECTOR_Y(y) ( WATER_UNSIGN_Y(y) / EXTRAHUGE_SECTOR_SIZE ) - -struct ColData -{ - uint8 SurfaceType; - uint8 PieceType; -}; - -enum eBeachToy -{ - BEACHTOY_0 = 0, - BEACHTOY_BALL, - BEACHTOY_LOUNGE_WOOD_UP, - BEACHTOY_LOUNGE_TOWEL_UP, - BEACHTOY_LOUNGE_WOOD_ON, - BEACHTOY_ANY_LOUNGE, - BEACHTOY_LOTION, - BEACHTOY_TOWEL1, - BEACHTOY_TOWEL2, - BEACHTOY_TOWEL3, - BEACHTOY_TOWEL4, - BEACHTOY_ANY_TOWEL, -}; - -extern RwRaster* gpWaterRaster; -extern bool gbDontRenderWater; - -class CEntity; - -class CWaterLevel -{ -public: - static int32 ms_nNoOfWaterLevels; - static float ms_aWaterZs[48]; - static CRect ms_aWaterRects[48]; - static int8 aWaterBlockList[MAX_LARGE_SECTORS][MAX_LARGE_SECTORS]; // 64x64 Large blocks 64x64 each - static int8 aWaterFineBlockList[MAX_SMALL_SECTORS][MAX_SMALL_SECTORS]; // 128x128 Small blocks 32x32 each - static bool WavesCalculatedThisFrame; - - static bool RequireWavySector; - static bool MaskCalculatedThisFrame; - static CVector PreCalculatedMaskPosn; - static bool m_bRenderSeaBed; - static int32 m_nRenderWaterLayers; - - static RpAtomic *ms_pWavyAtomic; - static RpAtomic *ms_pMaskAtomic; - - static void Initialise(Const char *pWaterDat); // out of class in III PC and later because of SecuROM - static void Shutdown(); - - static void CreateWavyAtomic(); - static void DestroyWavyAtomic(); - - static void AddWaterLevel(float fXLeft, float fYBottom, float fXRight, float fYTop, float fLevel); - static bool WaterLevelAccordingToRectangles(float fX, float fY, float *pfOutLevel = nil); - static bool TestVisibilityForFineWaterBlocks(const CVector &worldPos); - static void RemoveIsolatedWater(); - - static bool GetWaterLevel(float fX, float fY, float fZ, float *pfOutLevel, bool bDontCheckZ); - static bool GetWaterLevel(CVector coors, float *pfOutLevel, bool bDontCheckZ) { return GetWaterLevel(coors.x, coors.y, coors.z, pfOutLevel, bDontCheckZ); } - static bool GetWaterLevelNoWaves(float fX, float fY, float fZ, float *pfOutLevel); - static float GetWaterWavesOnly(short x, short y); // unused - static CVector GetWaterNormal(float fX, float fY); - - static void RenderWater(); - static void RenderTransparentWater(void); - // unused - static void RenderOneFlatSmallWaterPoly (float fX, float fY, float fZ, RwRGBA const &color); - // inlined - static void RenderOneFlatLargeWaterPoly (float fX, float fY, float fZ, RwRGBA const &color); - static void RenderOneFlatHugeWaterPoly (float fX, float fY, float fZ, RwRGBA const &color); - static void RenderOneFlatExtraHugeWaterPoly(float fX, float fY, float fZ, RwRGBA const &color); - // inlined - static void RenderOneWavySector (float fX, float fY, float fZ, RwRGBA const &color, bool bDontRender = false); - // unused -#ifdef PC_WATER - static void RenderWavyMask(float fX, float fY, float fZ, float fSectorX, float fSectorY, float fCamPosX, float fCamPosY, float fCamDirX, float fCamDirY, RwRGBA const&color); -#else - static void RenderWavyMask(float fX, float fY, float fZ, float fSectorX, float fSectorY, int32 nCamDirX, int32 nCamDirY, RwRGBA const&color); -#endif - -#ifdef PC_WATER - static void PreCalcWaterGeometry(void); - static bool PreCalcWavySector(RwRGBA const &color); //fucked up - static bool PreCalcWavyMask(float fX, float fY, float fZ, float fSectorX, float fSectorY, float fCamPosX, float fCamPosY, float fCamDirX, float fCamDirY, RwRGBA const&color); -#endif - - - static void RenderBoatWakes(void); - static void RenderWakeSegment(CVector2D &vecA, CVector2D &vecB, CVector2D &vecC, CVector2D &vecD, float &fSizeA, float &fSizeB, float &fAlphaA, float &fAlphaB, float &fWakeZ); - - // unused - static void RenderOneSlopedUnderWaterPoly(float fX, float fY, float fZ, RwRGBA const&color); // UNUSED - static void RenderOneFlatSmallWaterPolyBlended(float fX, float fY, float fZ, float fCamX, float fCamY, RwRGBA const &color, RwRGBA const &colorTrans, float fDrawDist); - static float CalcDistanceToWater(float fX, float fY); - static void RenderAndEmptyRenderBuffer(); - - static bool GetGroundLevel(CVector const &vecPosn, float *pfOutLevel, ColData *pData, float fDistance); - - // unused - static bool IsLocationOutOfWorldBounds_WS(CVector const &vecPosn, int nOffset); - // unused - static bool GetGroundLevel_WS(CVector const & vecPosn, float *pfOutLevel, ColData *pData, float fDistance); - static bool GetWaterDepth(CVector const &vecPosn, float *pfDepth, float *pfLevelNoWaves, float *pfGroundLevel); - - static void RenderSeaBirds(); - static void RenderShipsOnHorizon(); - - static void HandleSeaLifeForms(); - - static void HandleBeachToysStuff(void); - static CEntity *CreateBeachToy(CVector const &vec, eBeachToy beachtoy); -}; diff --git a/src/render/Weather.cpp b/src/render/Weather.cpp deleted file mode 100644 index 9f925a8c..00000000 --- a/src/render/Weather.cpp +++ /dev/null @@ -1,662 +0,0 @@ -#include "common.h" - -#include "Weather.h" - -#include "Camera.h" -#include "Clock.h" -#include "CutsceneMgr.h" -#include "DMAudio.h" -#include "General.h" -#include "Pad.h" -#include "PlayerPed.h" -#include "Particle.h" -#include "RenderBuffer.h" -#include "Stats.h" -#include "Shadows.h" -#include "Timecycle.h" -#include "Timer.h" -#include "Vehicle.h" -#include "World.h" -#include "ZoneCull.h" -#include "SpecialFX.h" -#include "Replay.h" - -int32 CWeather::SoundHandle = -1; - -int32 CWeather::WeatherTypeInList; -int16 CWeather::OldWeatherType; -int16 CWeather::NewWeatherType; -int16 CWeather::ForcedWeatherType; - -bool CWeather::LightningFlash; -bool CWeather::LightningBurst; -uint32 CWeather::LightningStart; -uint32 CWeather::LightningFlashLastChange; -uint32 CWeather::WhenToPlayLightningSound; -uint32 CWeather::LightningDuration; -int32 CWeather::StreamAfterRainTimer; - -float CWeather::ExtraSunnyness; -float CWeather::Foggyness; -float CWeather::CloudCoverage; -float CWeather::Wind; -float CWeather::Rain; -float CWeather::InterpolationValue; -float CWeather::WetRoads; -float CWeather::Rainbow; -float CWeather::SunGlare; -float CWeather::WindClipped; -float CWeather::TrafficLightBrightness; - -bool CWeather::bScriptsForceRain; - -tRainStreak Streaks[NUM_RAIN_STREAKS]; - -int16 WeatherTypesList[] = { - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, - WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, - WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, - WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_CLOUDY, - WEATHER_RAINY, WEATHER_RAINY, WEATHER_RAINY, WEATHER_RAINY, - WEATHER_CLOUDY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, - WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY -}; - -int16 WeatherTypesList_WithHurricanes[] = { - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, - WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_CLOUDY, - WEATHER_HURRICANE, WEATHER_HURRICANE, WEATHER_CLOUDY, WEATHER_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, - WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, - WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, - WEATHER_CLOUDY, WEATHER_HURRICANE, WEATHER_HURRICANE, WEATHER_HURRICANE, - WEATHER_CLOUDY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, - WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, - WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY -}; - -const float Windyness[] = { - 0.25f,// WEATHER_SUNNY - 0.7f, // WEATHER_CLOUDY - 1.0f, // WEATHER_RAINY - 0.0f, // WEATHER_FOGGY - 0.0f, // WEATHER_EXTRA_SUNNY - 2.0f, // WEATHER_HURRICANE - 0.0f -}; - -#define MIN_TIME_BETWEEN_LIGHTNING_FLASH_CHANGES (50) - -#define RAIN_CHANGE_SPEED (0.003f) - -#define DROPLETS_LEFT_OFFSET (10.0f) -#define DROPLETS_RIGHT_OFFSET (10.0f) -#define DROPLETS_TOP_OFFSET (10.0f) -#define DROPLETS_BOTTOM_OFFSET (10.0f) - -#define STREAK_U (10.0f) -#define STREAK_V (18.0f) -#define LARGE_STREAK_COEFFICIENT (1.23f) -#define STREAK_MIN_DISTANCE (8.0f) -#define STREAK_MAX_DISTANCE (16.0f) - -#define SPLASH_CHECK_RADIUS (7.0f) -#define SPLASH_OFFSET_RADIUS (2.0f) - -#define STREAK_LIFETIME (4.0f) -#define STREAK_INTEROLATION_TIME (0.3f) - -#define RAIN_COLOUR_R (200) -#define RAIN_COLOUR_G (200) -#define RAIN_COLOUR_B (256) -#define RAIN_ALPHA (255) - -void CWeather::Init(void) -{ - NewWeatherType = WEATHER_EXTRA_SUNNY; - bScriptsForceRain = false; - OldWeatherType = WEATHER_EXTRA_SUNNY; - InterpolationValue = 0.0f; - WhenToPlayLightningSound = 0; - WeatherTypeInList = 0; - ForcedWeatherType = WEATHER_RANDOM; - SoundHandle = DMAudio.CreateEntity(AUDIOTYPE_WEATHER, (void*)1); - if (SoundHandle >= 0) - DMAudio.SetEntityStatus(SoundHandle, TRUE); -} - -void CWeather::Update(void) -{ - if(!CReplay::IsPlayingBack()){ - float fNewInterpolation = (CClock::GetMinutes() + CClock::GetSeconds()/60.0f)/60.0f; - if (fNewInterpolation < InterpolationValue) { - // new hour - OldWeatherType = NewWeatherType; - if (ForcedWeatherType >= 0) - NewWeatherType = ForcedWeatherType; - else { - WeatherTypeInList = (WeatherTypeInList + 1) % ARRAY_SIZE(WeatherTypesList); - NewWeatherType = CStats::NoMoreHurricanes ? WeatherTypesList[WeatherTypeInList] : WeatherTypesList_WithHurricanes[WeatherTypeInList]; - } - } - InterpolationValue = fNewInterpolation; - } - -#ifndef FINAL - if (CPad::GetPad(1)->GetRightShockJustDown()) { - NewWeatherType = (NewWeatherType + 1) % WEATHER_TOTAL; - OldWeatherType = NewWeatherType; - } -#endif - - // Lightning - if (NewWeatherType != WEATHER_RAINY || OldWeatherType != WEATHER_RAINY) { - LightningFlash = false; - LightningBurst = false; - } - else{ - if (LightningBurst) { - if ((CGeneral::GetRandomNumber() & 255) >= 32) { - // 0.875 probability - if (CTimer::GetTimeInMilliseconds() - LightningFlashLastChange > MIN_TIME_BETWEEN_LIGHTNING_FLASH_CHANGES) { - bool bOldLightningFlash = LightningFlash; - LightningFlash = CGeneral::GetRandomTrueFalse(); - if (LightningFlash != bOldLightningFlash) - LightningFlashLastChange = CTimer::GetTimeInMilliseconds(); - } - } - else { - // 0.125 probability - LightningBurst = false; - LightningDuration = Min(CTimer::GetFrameCounter() - LightningStart, 20); - LightningFlash = false; - WhenToPlayLightningSound = CTimer::GetTimeInMilliseconds() + 150 * (20 - LightningDuration); - } - } - else { - if (CGeneral::GetRandomNumber() >= 200) { - // lower probability on PC due to randomness bug - LightningFlash = false; - } - else { - LightningBurst = true; - LightningStart = CTimer::GetFrameCounter(); - LightningFlashLastChange = CTimer::GetTimeInMilliseconds(); - LightningFlash = true; - } - } - } - if (WhenToPlayLightningSound && CTimer::GetTimeInMilliseconds() > WhenToPlayLightningSound) { - DMAudio.PlayOneShot(SoundHandle, SOUND_LIGHTNING, LightningDuration); - CPad::GetPad(0)->StartShake(40 * LightningDuration + 100, 2 * LightningDuration + 80); - WhenToPlayLightningSound = 0; - } - - // Wet roads - if (OldWeatherType == WEATHER_RAINY || OldWeatherType == WEATHER_HURRICANE) { - if (NewWeatherType == WEATHER_RAINY || NewWeatherType == WEATHER_HURRICANE) - WetRoads = 1.0f; - else - WetRoads = 1.0f - InterpolationValue; - } - else { - if (NewWeatherType == WEATHER_RAINY || NewWeatherType == WEATHER_HURRICANE) - WetRoads = InterpolationValue; - else - WetRoads = 0.0f; - } - - // Rain - float fNewRain; - if (NewWeatherType == WEATHER_RAINY || NewWeatherType == WEATHER_HURRICANE) { - // if raining for >1 hour, values: 0, 0.33, switching every ~16.5s - fNewRain = (((uint16)CTimer::GetTimeInMilliseconds() >> 14) & 1) * 0.33f; - if (OldWeatherType != WEATHER_RAINY && OldWeatherType != WEATHER_HURRICANE) { - if (InterpolationValue < 0.4f) - // if rain has just started (<24 minutes), always 0.5 - fNewRain = 0.5f; - else - // if rain is ongoing for >24 minutes, values: 0.25, 0.5, switching every ~16.5s - fNewRain = 0.25f + (((uint16)CTimer::GetTimeInMilliseconds() >> 14) & 1) * 0.25f; - } - fNewRain = Max(fNewRain, 0.5f); - } - else - fNewRain = 0.0f; - Rain = fNewRain; - - // Clouds - if (OldWeatherType != WEATHER_SUNNY && OldWeatherType != WEATHER_EXTRA_SUNNY) - CloudCoverage = 1.0f - InterpolationValue; - else - CloudCoverage = 0.0f; - if (NewWeatherType != WEATHER_SUNNY && OldWeatherType != WEATHER_EXTRA_SUNNY) - CloudCoverage += InterpolationValue; - - // Fog - if (OldWeatherType == WEATHER_FOGGY) - Foggyness = 1.0f - InterpolationValue; - else - Foggyness = 0.0f; - if (NewWeatherType == WEATHER_FOGGY) - Foggyness += InterpolationValue; - - // Extra Sunnyness - if (OldWeatherType == WEATHER_EXTRA_SUNNY) - ExtraSunnyness = 1.0f - InterpolationValue; - else - ExtraSunnyness = 0.0f; - if (NewWeatherType == WEATHER_EXTRA_SUNNY) - ExtraSunnyness += InterpolationValue; - - // Rainbow - if (OldWeatherType == WEATHER_CLOUDY && (NewWeatherType == WEATHER_SUNNY || NewWeatherType == WEATHER_EXTRA_SUNNY) && - InterpolationValue < 0.5f && CClock::GetHours() > 6 && CClock::GetHours() < 21) - Rainbow = 1.0f - 4.0f * Abs(InterpolationValue - 0.25f) / 4.0f; - else - Rainbow = 0.0f; - - // Sun Glare - if (OldWeatherType == WEATHER_EXTRA_SUNNY) - SunGlare = 1.0f - InterpolationValue; - else - SunGlare = 0.0f; - if (NewWeatherType == WEATHER_EXTRA_SUNNY) - SunGlare += InterpolationValue; - - if (SunGlare > 0.0f) { - SunGlare *= Min(1.0f, 7.0 * CTimeCycle::GetSunDirection().z); - SunGlare = Clamp(SunGlare, 0.0f, 1.0f); - if (!CSpecialFX::bSnapShotActive) - SunGlare *= (1.0f - (CGeneral::GetRandomNumber()&0x1F)*0.007f); - } - - Wind = InterpolationValue * Windyness[NewWeatherType] + (1.0f - InterpolationValue) * Windyness[OldWeatherType]; - WindClipped = Min(1.0f, Wind); - - if (CClock::GetHours() > 20) - TrafficLightBrightness = 1.0f; - else if (CClock::GetHours() > 19) - TrafficLightBrightness = CClock::GetMinutes() / 60.0f; - else if (CClock::GetHours() > 6) - TrafficLightBrightness = 0.0f; - else if (CClock::GetHours() > 5) - TrafficLightBrightness = 1.0f - CClock::GetMinutes() / 60.0f; - else - TrafficLightBrightness = 1.0f; - TrafficLightBrightness = Max(WetRoads, TrafficLightBrightness); - TrafficLightBrightness = Max(Foggyness, TrafficLightBrightness); - TrafficLightBrightness = Max(Rain, TrafficLightBrightness); - - AddRain(); - - if ((NewWeatherType == WEATHER_SUNNY || NewWeatherType == WEATHER_EXTRA_SUNNY) && - !CGame::IsInInterior() && !CCutsceneMgr::IsRunning() && (CTimer::GetFrameCounter() & 7) == 0) { -#ifdef FIX_BUGS - if (FindPlayerPed() && (!FindPlayerPed()->CheckIfInTheAir() || FindPlayerPed()->CheckIfInTheAir() && FindPlayerPed()->GetPosition().z < 7.5f && - CClock::GetHours() > 6 && CClock::GetHours() < 18)) -#else - if (!FindPlayerPed()->CheckIfInTheAir() || FindPlayerPed()->CheckIfInTheAir() && FindPlayerPed()->GetPosition().z < 7.5f && - CClock::GetHours() > 6 && CClock::GetHours() < 18) -#endif - AddHeatHaze(); - } - - if ((NewWeatherType == WEATHER_SUNNY || NewWeatherType == WEATHER_EXTRA_SUNNY) && !CGame::IsInInterior() && !CCutsceneMgr::IsRunning()) - AddBeastie(); -} - -void CWeather::AddHeatHaze() -{ - if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN || - TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED) - return; - CVector pos; - pos.x = SCREEN_WIDTH*0.5f; - if(TheCamera.GetLookingForwardFirstPerson()) - pos.y = CGeneral::GetRandomNumberInRange(SCREEN_HEIGHT*0.25f, SCREEN_HEIGHT*0.9f); - else - pos.y = CGeneral::GetRandomNumberInRange(SCREEN_HEIGHT*0.4f, SCREEN_HEIGHT*0.9f); - pos.z = 100.0f; - CParticle::AddParticle(PARTICLE_HEATHAZE_IN_DIST, pos, CVector(0.0f, 0.0f, 0.0f)); -} - -void CWeather::AddBeastie() -{ - if(FindPlayerVehicle() || CTimer::GetFrameCounter()%10 || (CGeneral::GetRandomNumber()&5) == 0) - return; - CVector pos = TheCamera.GetPosition(); - float dist = CGeneral::GetRandomNumberInRange(90.0f, 60.0f); - int angle = CGeneral::GetRandomNumber() % CParticle::SIN_COS_TABLE_SIZE; - float c = CParticle::m_CosTable[angle]; - float s = CParticle::m_SinTable[angle]; - pos.x += dist*(c - s); - pos.y += dist*(c + s); - pos.z += CGeneral::GetRandomNumberInRange(7.5f, 30.0f); - CParticle::AddParticle(PARTICLE_BEASTIE, pos, CVector(0.0f, 0.0f, 0.0f)); -} - -void CWeather::ForceWeather(int16 weather) -{ - ForcedWeatherType = weather; -} - -void CWeather::ForceWeatherNow(int16 weather) -{ - OldWeatherType = weather; - NewWeatherType = weather; - ForcedWeatherType = weather; -} - -void CWeather::ReleaseWeather() -{ - ForcedWeatherType = -1; -} - -void CWeather::AddSplashesDuringHurricane() -{ - RwRGBA colour = { 255, 255, 255, 32 }; - CVector pos = TheCamera.pTargetEntity ? TheCamera.pTargetEntity->GetPosition() : TheCamera.GetPosition(); - bool foundGround; - float groundZ = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z, &foundGround) + 0.1f; - if(!foundGround) - groundZ = pos.z + 0.5f; - for(int i = 0; i < 20; i++){ - float dist = (CGeneral::GetRandomNumber()&0xFF)/255.0f + - CGeneral::GetRandomNumberInRange(-10.0f, 30.0f); - float angle; - uint8 rnd = CGeneral::GetRandomNumber(); - if(rnd&1) - angle = (CGeneral::GetRandomNumber()&0x7F)/128.0f * TWOPI; - else - angle = TheCamera.Orientation + (rnd-128)/160.0f; - pos.x = TheCamera.GetPosition().x + dist*Sin(angle); - pos.y = TheCamera.GetPosition().y + dist*Cos(angle); - pos.z = groundZ; - if(foundGround) - CParticle::AddParticle(PARTICLE_GROUND_STEAM, pos, CVector(-0.002f, -0.002f, 0.015f), nil, 0.0f, colour); - } -} - -static int startStreamAfterRain; - -void CWeather::AddStreamAfterRain() -{ - if(CClock::GetHours() > 6 && CClock::GetHours() < 18){ - RwRGBA colour = { 255, 255, 255, 24 }; - CVector pos = TheCamera.pTargetEntity ? TheCamera.pTargetEntity->GetPosition() : TheCamera.GetPosition(); - bool foundGround; - float groundZ = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z, &foundGround) + 0.2f; - if(!foundGround) - groundZ = pos.z + 0.75f; - for(int i = 0; i < 20; i++){ - float dist = (CGeneral::GetRandomNumber()&0xFF)/255.0f + - CGeneral::GetRandomNumberInRange(-10.0f, 30.0f); - float angle; - uint8 rnd = CGeneral::GetRandomNumber(); - if(rnd&1) - angle = (CGeneral::GetRandomNumber()&0x7F)/128.0f * TWOPI; - else - angle = TheCamera.Orientation + (rnd-128)/160.0f; - pos.x = TheCamera.GetPosition().x + dist*Sin(angle); - pos.y = TheCamera.GetPosition().y + dist*Cos(angle); - pos.z = groundZ; - CParticle::AddParticle(PARTICLE_GROUND_STEAM, pos, CVector(0.0f, 0.0f, 0.015f), nil, 0.0f, colour); - } - }else{ - startStreamAfterRain = 0; - StreamAfterRainTimer = 800; - } -} - -void CWeather::AddRain() -{ - if (CCullZones::CamNoRain() || CCullZones::PlayerNoRain()) - return; - if (TheCamera.GetLookingLRBFirstPerson()) { - CVehicle* pVehicle = FindPlayerVehicle(); - if (pVehicle && pVehicle->CarHasRoof()) { - CParticle::RemovePSystem(PARTICLE_RAINDROP_2D); - return; - } - } - - if(Rain > 0.0){ - startStreamAfterRain = 1; - StreamAfterRainTimer = 800; - }else if(startStreamAfterRain){ - if(StreamAfterRainTimer > 0){ - AddStreamAfterRain(); - StreamAfterRainTimer--; - }else{ - startStreamAfterRain = 0; - StreamAfterRainTimer = 800; - } - } - - if (Wind > 1.1f) - AddSplashesDuringHurricane(); - - if (Rain <= 0.1f) - return; - static RwRGBA colour; - int numDrops = 5.0f * Rain; - int numSplashes = 2.0f * Rain; - CVector pos, dir; - for(int i = 0; i < numDrops; i++){ - pos.x = CGeneral::GetRandomNumberInRange(0, (int)SCREEN_WIDTH); - pos.y = CGeneral::GetRandomNumberInRange(0, (int)SCREEN_HEIGHT/5); - pos.z = 0.0f; - dir.x = 0.0f; - dir.y = CGeneral::GetRandomNumberInRange(30.0f, 40.0f); - dir.z = 0.0f; - CParticle::AddParticle(PARTICLE_RAINDROP_2D, pos, dir, nil, CGeneral::GetRandomNumberInRange(0.1f, 0.75f), 0, 0, (int)Rain&3, 0); - - pos.x = CGeneral::GetRandomNumberInRange(0, (int)SCREEN_WIDTH); - pos.y = CGeneral::GetRandomNumberInRange((int)SCREEN_HEIGHT/5, (int)SCREEN_HEIGHT/2); - pos.z = 0.0f; - dir.x = 0.0f; - dir.y = CGeneral::GetRandomNumberInRange(30.0f, 40.0f); - dir.z = 0.0f; - CParticle::AddParticle(PARTICLE_RAINDROP_2D, pos, dir, nil, CGeneral::GetRandomNumberInRange(0.1f, 0.75f), 0, 0, (int)Rain&3, 0); - - pos.x = CGeneral::GetRandomNumberInRange(0, (int)SCREEN_WIDTH); - pos.y = 0.0f; - pos.z = 0.0f; - dir.x = 0.0f; - dir.y = CGeneral::GetRandomNumberInRange(30.0f, 40.0f); - dir.z = 0.0f; - CParticle::AddParticle(PARTICLE_RAINDROP_2D, pos, dir, nil, CGeneral::GetRandomNumberInRange(0.1f, 0.75f), 0, 0, (int)Rain&3, 0); - - float dist = CGeneral::GetRandomNumberInRange(0.0f, Max(10.0f*Rain, 40.0f)/2.0f); - float angle; - uint8 rnd = CGeneral::GetRandomNumber(); - if(rnd&1) - angle = (CGeneral::GetRandomNumber()&0x7F)/128.0f * TWOPI; - else - angle = TheCamera.Orientation + (rnd-128)/160.0f; - pos.x = TheCamera.GetPosition().x + dist*Sin(angle); - pos.y = TheCamera.GetPosition().y + dist*Cos(angle); - pos.z = 0.0f; - CColPoint point; - CEntity *ent; - if(CWorld::ProcessVerticalLine(pos+CVector(0.0f, 0.0f, 40.0f), -40.0f, point, ent, true, false, false, false, true, false, nil)){ - pos.z = point.point.z; - for(int j = 0; j < numSplashes+15; j++){ - CVector pos2 = pos; - pos2.x += CGeneral::GetRandomNumberInRange(-15.0f, 15.0f); - pos2.y += CGeneral::GetRandomNumberInRange(-15.0f, 15.0f); - if(CGeneral::GetRandomNumber() & 1) - CParticle::AddParticle(PARTICLE_RAIN_SPLASH, pos2, CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, colour); - else - CParticle::AddParticle(PARTICLE_RAIN_SPLASHUP, pos2, CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, colour); - } - } - } -} - -void RenderOneRainStreak(CVector pos, CVector unused, int intensity, bool scale, float distance) -{ - static float RandomTex; - static float RandomTexX; - static float RandomTexY; - TempBufferRenderIndexList[TempBufferIndicesStored + 0] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[TempBufferIndicesStored + 1] = TempBufferVerticesStored + 2; - TempBufferRenderIndexList[TempBufferIndicesStored + 2] = TempBufferVerticesStored + 1; - TempBufferRenderIndexList[TempBufferIndicesStored + 3] = TempBufferVerticesStored + 0; - TempBufferRenderIndexList[TempBufferIndicesStored + 4] = TempBufferVerticesStored + 3; - TempBufferRenderIndexList[TempBufferIndicesStored + 5] = TempBufferVerticesStored + 2; - TempBufferRenderIndexList[TempBufferIndicesStored + 6] = TempBufferVerticesStored + 1; - TempBufferRenderIndexList[TempBufferIndicesStored + 7] = TempBufferVerticesStored + 2; - TempBufferRenderIndexList[TempBufferIndicesStored + 8] = TempBufferVerticesStored + 4; - TempBufferRenderIndexList[TempBufferIndicesStored + 9] = TempBufferVerticesStored + 2; - TempBufferRenderIndexList[TempBufferIndicesStored + 10] = TempBufferVerticesStored + 3; - TempBufferRenderIndexList[TempBufferIndicesStored + 11] = TempBufferVerticesStored + 4; - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + 0], 0, 0, 0, 0); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + 0], pos.x + 11.0f * TheCamera.GetUp().x, pos.y + 11.0f * TheCamera.GetUp().y, pos.z + 11.0f * TheCamera.GetUp().z); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + 1], 0, 0, 0, 0); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + 1], pos.x - 9.0f * TheCamera.GetRight().x, pos.y - 9.0f * TheCamera.GetRight().y, pos.z - 9.0f * TheCamera.GetRight().z); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + 2], RAIN_COLOUR_R * intensity / 256, RAIN_COLOUR_G * intensity / 256, RAIN_COLOUR_B * intensity / 256, RAIN_ALPHA); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + 2], pos.x, pos.y, pos.z); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + 3], 0, 0, 0, 0); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + 3], pos.x + 9.0f * TheCamera.GetRight().x, pos.y + 9.0f * TheCamera.GetRight().y, pos.z + 9.0f * TheCamera.GetRight().z); - RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + 4], 0, 0, 0, 0); - RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + 4], pos.x - 11.0f * TheCamera.GetUp().x, pos.y - 11.0f * TheCamera.GetUp().y, pos.z - 11.0f * TheCamera.GetUp().z); - float u = STREAK_U; - float v = STREAK_V; - if (scale) { - u *= LARGE_STREAK_COEFFICIENT; - v *= LARGE_STREAK_COEFFICIENT; - } - float distance_coefficient; - if (distance < STREAK_MIN_DISTANCE) - distance_coefficient = 1.0f; - else if (distance > STREAK_MAX_DISTANCE) - distance_coefficient = 0.5f; - else - distance_coefficient = 1.0f - 0.5f * (distance - STREAK_MIN_DISTANCE) / (STREAK_MAX_DISTANCE - STREAK_MIN_DISTANCE); - u *= distance_coefficient; - v *= distance_coefficient; - if (!CTimer::GetIsPaused()) { - RandomTex = 0.0f; - RandomTexX = 0.0f; - RandomTexY = 0.0f; - } - RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored + 0], 0.5f * u - RandomTex + RandomTexX); - RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored + 0], -v * 0.5f + RandomTexY); - RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored + 1], RandomTexX); - RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored + 1], RandomTexY); - RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored + 2], 0.5f * u + RandomTexX); - RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored + 2], RandomTexY); - RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored + 3], u + RandomTexX); - RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored + 3], RandomTexY); - RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored + 4], 0.5f * u + RandomTex + RandomTexX); - RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored + 5], 0.5f * v + RandomTexY); - TempBufferIndicesStored += 12; - TempBufferVerticesStored += 5; -} - -void CWeather::RenderRainStreaks(void) -{ - if (CTimer::GetIsCodePaused()) - return; - int base_intensity = (64.0f - CTimeCycle::GetFogReduction()) / 64.0f * int(255 * Rain); - if (base_intensity == 0) - return; - if (TheCamera.m_CameraAverageSpeed > 1.75f) - return; - TempBufferIndicesStored = 0; - TempBufferVerticesStored = 0; - for (int i = 0; i < NUM_RAIN_STREAKS; i++) { - if (Streaks[i].timer) { - float secondsElapsed = (CTimer::GetTimeInMilliseconds() - Streaks[i].timer) / 1024.0f; - if (secondsElapsed > STREAK_LIFETIME) - Streaks[i].timer = 0; - else{ - int intensity; - if (secondsElapsed < STREAK_INTEROLATION_TIME) - intensity = base_intensity * 0.25f * secondsElapsed / STREAK_INTEROLATION_TIME; - else if (secondsElapsed > (STREAK_LIFETIME - STREAK_INTEROLATION_TIME)) - intensity = (STREAK_LIFETIME - secondsElapsed) * 0.25f * base_intensity / STREAK_INTEROLATION_TIME; - else - intensity = base_intensity * 0.25f; - CVector dir = Streaks[i].direction; - dir.Normalise(); - CVector pos = Streaks[i].position + secondsElapsed * Streaks[i].direction; - RenderOneRainStreak(pos, dir, intensity, false, (pos - TheCamera.GetPosition()).Magnitude()); -#ifndef FIX_BUGS // remove useless code - if (secondsElapsed > 1.0f && secondsElapsed < STREAK_LIFETIME - 1.0f) { - CGeneral::GetRandomNumber(), CGeneral::GetRandomNumber(); - } -#endif - } - } - else if ((CGeneral::GetRandomNumber() & 0xF00) == 0){ - // 1/16 probability - Streaks[i].direction = CVector(0.0f, 0.0f, -12.0f); - Streaks[i].position = 6.0f * TheCamera.GetForward() + TheCamera.GetPosition() + CVector(-1.8f * Streaks[i].direction.x, -1.8f * Streaks[i].direction.y, 8.0f); - if (!CCutsceneMgr::IsRunning()) { - Streaks[i].position.x += 2.0f * FindPlayerSpeed().x * 60.0f; - Streaks[i].position.y += 2.0f * FindPlayerSpeed().y * 60.0f; - } - else - Streaks[i].position += (TheCamera.GetPosition() - TheCamera.m_RealPreviousCameraPosition) * 20.0f; - Streaks[i].position.x += ((CGeneral::GetRandomNumber() & 255) - 128) * 0.04f; - Streaks[i].position.y += ((CGeneral::GetRandomNumber() & 255) - 128) * 0.04f; - Streaks[i].timer = CTimer::GetTimeInMilliseconds(); - } - } - if (TempBufferIndicesStored){ - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEFOGTYPE, (void*)rwFOGTYPELINEAR); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpRainDropTex)); - if (RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, 1)) - { - RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); - RwIm3DEnd(); - } - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); - RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); - RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); - RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); - } - TempBufferVerticesStored = 0; - TempBufferIndicesStored = 0; -} - -#ifdef SECUROM -void CWeather::ForceHurricaneWeather() -{ - for (int i = 0; i < ARRAY_SIZE(WeatherTypesList_WithHurricanes); i++) - { - WeatherTypesList[i] = WEATHER_HURRICANE; - WeatherTypesList_WithHurricanes[i] = WEATHER_HURRICANE; - } - - CWeather::OldWeatherType = WEATHER_HURRICANE; - CWeather::NewWeatherType = WEATHER_HURRICANE; - CWeather::ForcedWeatherType = WEATHER_HURRICANE; -} -#endif diff --git a/src/render/Weather.h b/src/render/Weather.h deleted file mode 100644 index bda57d55..00000000 --- a/src/render/Weather.h +++ /dev/null @@ -1,73 +0,0 @@ -enum { - WEATHER_RANDOM = -1, - WEATHER_SUNNY = 0, - WEATHER_CLOUDY, - WEATHER_RAINY, - WEATHER_FOGGY, - WEATHER_EXTRA_SUNNY, - WEATHER_HURRICANE, - WEATHER_TOTAL, - - WEATHER_EXTRACOLOURS = 6 -}; - -class CWeather -{ -public: - static int32 SoundHandle; - - static int32 WeatherTypeInList; - static int16 OldWeatherType; - static int16 NewWeatherType; - static int16 ForcedWeatherType; - - static bool LightningFlash; - static bool LightningBurst; - static uint32 LightningStart; - static uint32 LightningFlashLastChange; - static uint32 WhenToPlayLightningSound; - static uint32 LightningDuration; - static int32 StreamAfterRainTimer; - - static float ExtraSunnyness; - static float Foggyness; - static float CloudCoverage; - static float Wind; - static float Rain; - static float InterpolationValue; - static float WetRoads; - static float Rainbow; - static float SunGlare; - static float WindClipped; - static float TrafficLightBrightness; - - static bool bScriptsForceRain; - - static void RenderRainStreaks(void); - static void Update(void); - static void Init(void); - - static void ReleaseWeather(); - static void ForceWeather(int16); - static void ForceWeatherNow(int16); - static void AddSplashesDuringHurricane(); - static void AddStreamAfterRain(); - static void AddRain(); - static void AddHeatHaze(); - static void AddBeastie(); - - static void ForceHurricaneWeather(); -}; - -enum { - NUM_RAIN_STREAKS = 35 -}; - -struct tRainStreak -{ - CVector position; - CVector direction; - uint32 timer; -}; - -extern RwTexture* gpRainDropTex; \ No newline at end of file diff --git a/src/render/WindModifiers.cpp b/src/render/WindModifiers.cpp deleted file mode 100644 index 3bd6ac9c..00000000 --- a/src/render/WindModifiers.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "common.h" -#include "WindModifiers.h" -#include "Camera.h" -#include "General.h" - -#define MAX_HEIGHT_DIST 40.0f -#define MIN_FADE_DIST 20.0f -#define MAX_FADE_DIST 50.0f - -CWindModifiers Array[16]; -int32 CWindModifiers::Number; - -void -CWindModifiers::RegisterOne(CVector pos, int32 type = 1) -{ - if (CWindModifiers::Number < 16 && (pos - TheCamera.GetPosition()).Magnitude() < 100.0f) { - Array[Number].m_pos = pos; - Array[Number].m_type = type; - Number++; - } -} - -bool -CWindModifiers::FindWindModifier(CVector pos, float *x, float *y) -{ - bool bWasWindModifierFound = false; - CVector2D dir; - for (int i = 0; i < Number; i++) { - if (Array[i].m_type == 1) { - float zDist = Abs(15.0f + pos.z - Array[i].m_pos.z); - - if (zDist < MAX_HEIGHT_DIST) { - float dist = (pos - Array[i].m_pos).Magnitude(); - if (dist < MAX_FADE_DIST) { - float distFade = dist < MIN_FADE_DIST ? 1.0f : 1.0f - (dist - MIN_FADE_DIST) / (MAX_FADE_DIST - MIN_FADE_DIST); - float heightFade = 1.0f - zDist / MAX_HEIGHT_DIST; - float fade = distFade * heightFade * 0.5f; - dir = (pos - Array[i].m_pos) * fade / dist; - bWasWindModifierFound = true; - } - } - } - } - - if (bWasWindModifierFound) { - float directionMult = ((CGeneral::GetRandomNumber() & 0x1F) - 16) * 0.0035f + 1.0f; - *x += dir.x * directionMult; - *y += dir.y * directionMult; - } - - return bWasWindModifierFound; -} diff --git a/src/render/WindModifiers.h b/src/render/WindModifiers.h deleted file mode 100644 index 7c2e57bd..00000000 --- a/src/render/WindModifiers.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -class CWindModifiers -{ - CVector m_pos; - int32 m_type; -public: - static int32 Number; - static void RegisterOne(CVector pos, int32 windSourceType); - static bool FindWindModifier(CVector pos, float *x, float *y); -}; diff --git a/src/renderer/2dEffect.h b/src/renderer/2dEffect.h new file mode 100644 index 00000000..8ad2b946 --- /dev/null +++ b/src/renderer/2dEffect.h @@ -0,0 +1,99 @@ +#pragma once + +enum { + EFFECT_LIGHT, + EFFECT_PARTICLE, + EFFECT_ATTRACTOR, + EFFECT_PED_ATTRACTOR, + EFFECT_SUNGLARE +}; + +enum { + LIGHT_ON, + LIGHT_ON_NIGHT, + LIGHT_FLICKER, + LIGHT_FLICKER_NIGHT, + LIGHT_FLASH1, + LIGHT_FLASH1_NIGHT, + LIGHT_FLASH2, + LIGHT_FLASH2_NIGHT, + LIGHT_FLASH3, + LIGHT_FLASH3_NIGHT, + LIGHT_RANDOM_FLICKER, + LIGHT_RANDOM_FLICKER_NIGHT, + LIGHT_SPECIAL, + LIGHT_BRIDGE_FLASH1, + LIGHT_BRIDGE_FLASH2, +}; + +enum { + ATTRACTORTYPE_ICECREAM, + ATTRACTORTYPE_STARE +}; + +enum { + LIGHTFLAG_LOSCHECK = 1, + // same order as CPointLights flags, must start at 2 + LIGHTFLAG_FOG_NORMAL = 2, // can have light and fog + LIGHTFLAG_FOG_ALWAYS = 4, // fog only + LIGHTFLAG_HIDE_OBJECT = 8, // hide the object instead of rendering light (???) + LIGHTFLAG_LONG_DIST = 16, + LIGHTFLAG_FOG = (LIGHTFLAG_FOG_NORMAL|LIGHTFLAG_FOG_ALWAYS) +}; + +class C2dEffect +{ +public: + struct Light { + float dist; + float range; // of pointlight + float size; + float shadowSize; + uint8 lightType; // LIGHT_ + uint8 roadReflection; + uint8 flareType; + uint8 shadowIntensity; + uint8 flags; // LIGHTFLAG_ + RwTexture *corona; + RwTexture *shadow; + }; + struct Particle { + int particleType; + CVector dir; + float scale; + }; + struct Attractor { + CVector dir; + int8 type; + uint8 probability; + }; + struct PedAttractor { + CVector queueDir; + CVector useDir; + int8 type; + }; + + CVector pos; + CRGBA col; + uint8 type; + union { + Light light; + Particle particle; + Attractor attractor; + PedAttractor pedattr; + }; + + C2dEffect(void) {} + void Shutdown(void){ + if(type == EFFECT_LIGHT){ + if(light.corona) + RwTextureDestroy(light.corona); + light.corona = nil; + if(light.shadow) + RwTextureDestroy(light.shadow); + light.shadow = nil; + } + } +}; + +VALIDATE_SIZE(C2dEffect, 0x34); diff --git a/src/renderer/Antennas.cpp b/src/renderer/Antennas.cpp new file mode 100644 index 00000000..5e30aca2 --- /dev/null +++ b/src/renderer/Antennas.cpp @@ -0,0 +1,129 @@ +#include "common.h" + +#include "main.h" +#include "Antennas.h" + +CAntenna CAntennas::aAntennas[NUMANTENNAS]; + +void +CAntennas::Init(void) +{ + int i; + for(i = 0; i < NUMANTENNAS; i++){ + aAntennas[i].active = false; + aAntennas[i].updatedLastFrame = false; + } +} + +// Free antennas that aren't used anymore +void +CAntennas::Update(void) +{ + int i; + + for(i = 0; i < NUMANTENNAS; i++){ + if(aAntennas[i].active && !aAntennas[i].updatedLastFrame) + aAntennas[i].active = false; + aAntennas[i].updatedLastFrame = false; + } +} + +// Add a new one or update an old one +void +CAntennas::RegisterOne(uint32 id, CVector dir, CVector position, float length) +{ + int i, j; + + for(i = 0; i < NUMANTENNAS; i++) + if(aAntennas[i].active && aAntennas[i].id == id) + break; + + if(i >= NUMANTENNAS){ + // not found, register new one + + // find empty slot + for(i = 0; i < NUMANTENNAS; i++) + if(!aAntennas[i].active) + break; + + // there is space + if(i < NUMANTENNAS){ + aAntennas[i].active = true; + aAntennas[i].updatedLastFrame = true; + aAntennas[i].id = id; + aAntennas[i].segmentLength = length/6.0f; + for(j = 0; j < 6; j++){ + aAntennas[i].pos[j] = position + dir*j*aAntennas[i].segmentLength; + aAntennas[i].speed[j] = CVector(0.0f, 0.0f, 0.0f); + } + } + }else{ + // found, update + aAntennas[i].Update(dir, position); + aAntennas[i].updatedLastFrame = true; + } +} + +static RwIm3DVertex vertexbufferA[2]; + +void +CAntennas::Render(void) +{ + int i, j; + + PUSH_RENDERGROUP("CAntennas::Render"); + for(i = 0; i < NUMANTENNAS; i++){ + if(!aAntennas[i].active) + continue; + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + + for(j = 0; j < 5; j++){ + RwIm3DVertexSetRGBA(&vertexbufferA[0], 200, 200, 200, 100); + RwIm3DVertexSetPos(&vertexbufferA[0], + aAntennas[i].pos[j].x, + aAntennas[i].pos[j].y, + aAntennas[i].pos[j].z); + RwIm3DVertexSetRGBA(&vertexbufferA[1], 200, 200, 200, 100); + RwIm3DVertexSetPos(&vertexbufferA[1], + aAntennas[i].pos[j+1].x, + aAntennas[i].pos[j+1].y, + aAntennas[i].pos[j+1].z); + + // LittleTest(); + if(RwIm3DTransform(vertexbufferA, 2, nil, 0)){ + RwIm3DRenderLine(0, 1); + RwIm3DEnd(); + } + } + } + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + + POP_RENDERGROUP(); +} + +void +CAntenna::Update(CVector dir, CVector basepos) +{ + int i; + + pos[0] = basepos; + pos[1] = basepos + dir*segmentLength; + + for(i = 2; i < 6; i++){ + CVector basedir = pos[i-1] - pos[i-2]; + CVector newdir = pos[i] - pos[i-1] + // drag along + dir*0.1f + // also drag up a bit for stiffness + speed[i]; // and keep moving + newdir.Normalise(); + newdir *= segmentLength; + CVector newpos = pos[i-1] + (basedir + newdir)/2.0f; + speed[i] = (newpos - pos[i])*0.9f; + pos[i] = newpos; + } +} diff --git a/src/renderer/Antennas.h b/src/renderer/Antennas.h new file mode 100644 index 00000000..47cb1dad --- /dev/null +++ b/src/renderer/Antennas.h @@ -0,0 +1,25 @@ +#pragma once + +class CAntenna +{ +public: + bool active; + bool updatedLastFrame; + uint32 id; + float segmentLength; + CVector pos[6]; + CVector speed[6]; + + void Update(CVector dir, CVector pos); +}; + +class CAntennas +{ + // no need to use game's array + static CAntenna aAntennas[NUMANTENNAS]; +public: + static void Init(void); + static void Update(void); + static void RegisterOne(uint32 id, CVector dir, CVector position, float length); + static void Render(void); +}; diff --git a/src/renderer/Clouds.cpp b/src/renderer/Clouds.cpp new file mode 100644 index 00000000..9cd32c5f --- /dev/null +++ b/src/renderer/Clouds.cpp @@ -0,0 +1,473 @@ +#include "common.h" + +#include "main.h" +#include "Sprite.h" +#include "Sprite2d.h" +#include "General.h" +#include "Game.h" +#include "Coronas.h" +#include "Camera.h" +#include "TxdStore.h" +#include "Weather.h" +#include "Clock.h" +#include "Timer.h" +#include "Timecycle.h" +#include "Renderer.h" +#include "Clouds.h" + +#define SMALLSTRIPHEIGHT 4.0f +#define HORIZSTRIPHEIGHT 48.0f + +RwTexture *gpCloudTex[5]; + +float CClouds::CloudRotation; +uint32 CClouds::IndividualRotation; + +float CClouds::ms_cameraRoll; +float CClouds::ms_horizonZ; +float CClouds::ms_HorizonTilt; +CRGBA CClouds::ms_colourTop; +CRGBA CClouds::ms_colourBottom; +CRGBA CClouds::ms_colourBkGrd; + +void +CClouds::Init(void) +{ + CTxdStore::PushCurrentTxd(); + CTxdStore::SetCurrentTxd(CTxdStore::FindTxdSlot("particle")); + gpCloudTex[0] = RwTextureRead("cloud1", nil); + gpCloudTex[1] = RwTextureRead("cloud2", nil); + gpCloudTex[2] = RwTextureRead("cloud3", nil); + gpCloudTex[3] = RwTextureRead("cloudhilit", nil); + gpCloudTex[4] = RwTextureRead("cloudmasked", nil); + CTxdStore::PopCurrentTxd(); + CloudRotation = 0.0f; +} + +void +CClouds::Shutdown(void) +{ + RwTextureDestroy(gpCloudTex[0]); + gpCloudTex[0] = nil; + RwTextureDestroy(gpCloudTex[1]); + gpCloudTex[1] = nil; + RwTextureDestroy(gpCloudTex[2]); + gpCloudTex[2] = nil; + RwTextureDestroy(gpCloudTex[3]); + gpCloudTex[3] = nil; + RwTextureDestroy(gpCloudTex[4]); + gpCloudTex[4] = nil; +} + +void +CClouds::Update(void) +{ + float s = Sin(TheCamera.Orientation - 0.85f); +#ifdef FIX_BUGS + CloudRotation += CWeather::Wind*s*0.001f*CTimer::GetTimeStepFix(); + IndividualRotation += (CWeather::Wind*CTimer::GetTimeStep()*0.5f + 0.3f*CTimer::GetTimeStepFix()) * 60.0f; +#else + CloudRotation += CWeather::Wind*s*0.001f; + IndividualRotation += (CWeather::Wind*CTimer::GetTimeStep()*0.5f + 0.3f) * 60.0f; +#endif +} + +float StarCoorsX[9] = { 0.0f, 0.05f, 0.13f, 0.4f, 0.7f, 0.6f, 0.27f, 0.55f, 0.75f }; +float StarCoorsY[9] = { 0.0f, 0.45f, 0.9f, 1.0f, 0.85f, 0.52f, 0.48f, 0.35f, 0.2f }; +float StarSizes[9] = { 1.0f, 1.4f, 0.9f, 1.0f, 0.6f, 1.5f, 1.3f, 1.0f, 0.8f }; + +float LowCloudsX[12] = { 1.0f, 0.7f, 0.0f, -0.7f, -1.0f, -0.7f, 0.0f, 0.7f, 0.8f, -0.8f, 0.4f, -0.4f }; +float LowCloudsY[12] = { 0.0f, -0.7f, -1.0f, -0.7f, 0.0f, 0.7f, 1.0f, 0.7f, 0.4f, 0.4f, -0.8f, -0.8f }; +float LowCloudsZ[12] = { 0.0f, 1.0f, 0.5f, 0.0f, 1.0f, 0.3f, 0.9f, 0.4f, 1.3f, 1.4f, 1.2f, 1.7f }; + +float CoorsOffsetX[37] = { + 0.0f, 60.0f, 72.0f, 48.0f, 21.0f, 12.0f, + 9.0f, -3.0f, -8.4f, -18.0f, -15.0f, -36.0f, + -40.0f, -48.0f, -60.0f, -24.0f, 100.0f, 100.0f, + 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, + 100.0f, 100.0f, -30.0f, -20.0f, 10.0f, 30.0f, + 0.0f, -100.0f, -100.0f, -100.0f, -100.0f, -100.0f, -100.0f +}; +float CoorsOffsetY[37] = { + 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, + 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, 100.0f, + 100.0f, 100.0f, 100.0f, 100.0f, -30.0f, 10.0f, + -25.0f, -5.0f, 28.0f, -10.0f, 10.0f, 0.0f, + 15.0f, 40.0f, -100.0f, -100.0f, -100.0f, -100.0f, + -100.0f, -40.0f, -20.0f, 0.0f, 10.0f, 30.0f, 35.0f +}; +float CoorsOffsetZ[37] = { + 2.0f, 1.0f, 0.0f, 0.3f, 0.7f, 1.4f, + 1.7f, 0.24f, 0.7f, 1.3f, 1.6f, 1.0f, + 1.2f, 0.3f, 0.7f, 1.4f, 0.0f, 0.1f, + 0.5f, 0.4f, 0.55f, 0.75f, 1.0f, 1.4f, + 1.7f, 2.0f, 2.0f, 2.3f, 1.9f, 2.4f, + 2.0f, 2.0f, 1.5f, 1.2f, 1.7f, 1.5f, 2.1f +}; + +uint8 BowRed[6] = { 30, 30, 30, 10, 0, 15 }; +uint8 BowGreen[6] = { 0, 15, 30, 30, 0, 0 }; +uint8 BowBlue[6] = { 0, 0, 0, 10, 30, 30 }; + +void +CClouds::Render(void) +{ + int i; + float szx, szy; + RwV3d screenpos; + RwV3d worldpos; + + if(!CGame::CanSeeOutSideFromCurrArea()) + return; + + PUSH_RENDERGROUP("CClouds::Render"); + + CCoronas::SunBlockedByClouds = false; + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + CSprite::InitSpriteBuffer(); + + float minute = CClock::GetHours()*60 + CClock::GetMinutes() + CClock::GetSeconds()/60.0f; + RwV3d campos = TheCamera.GetPosition(); + + // Moon + float moonfadeout = Abs(minute - 180.0f); // fully visible at 3AM + if((int)moonfadeout < 180){ // fade in/out 3 hours + float coverage = Max(CWeather::Foggyness, CWeather::CloudCoverage); + int brightness = (1.0f - coverage) * (180 - (int)moonfadeout); + RwV3d pos = { 0.0f, -100.0f, 15.0f }; + RwV3dAdd(&worldpos, &campos, &pos); + if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)){ + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[2])); + szx *= CCoronas::MoonSize*2.0f + 4.0f; + szy *= CCoronas::MoonSize*2.0f + 4.0f; + CSprite::RenderOneXLUSprite(screenpos.x, screenpos.y, screenpos.z, + szx, szy, brightness, brightness, brightness, 255, 1.0f/screenpos.z, 255); + } + } + + // The R* logo + int starintens = 0; + if(CClock::GetHours() < 22 && CClock::GetHours() > 5) + starintens = 0; + else if(CClock::GetHours() > 22 || CClock::GetHours() < 5) + starintens = 255; + else if(CClock::GetHours() == 22) + starintens = 255 * CClock::GetMinutes()/60.0f; + else if(CClock::GetHours() == 5) + starintens = 255 * (60 - CClock::GetMinutes())/60.0f; + if(starintens != 0){ + float coverage = Max(CWeather::Foggyness, CWeather::CloudCoverage); + int brightness = (1.0f - coverage) * starintens; + + // R + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[0])); + for(i = 0; i < 11; i++){ + RwV3d pos = { 100.0f, 0.0f, 10.0f }; + if(i >= 9) pos.x = -pos.x; + RwV3dAdd(&worldpos, &campos, &pos); + worldpos.y -= 90.0f*StarCoorsX[i%9]; + worldpos.z += 80.0f*StarCoorsY[i%9]; + if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)){ + float sz = 0.8f*StarSizes[i%9]; + CSprite::RenderBufferedOneXLUSprite(screenpos.x, screenpos.y, screenpos.z, + szx*sz, szy*sz, brightness, brightness, brightness, 255, 1.0f/screenpos.z, 255); + } + } + CSprite::FlushSpriteBuffer(); + + // * + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[0])); + RwV3d pos = { 100.0f, 0.0f, 10.0f }; + RwV3dAdd(&worldpos, &campos, &pos); + worldpos.y -= 90.0f; + if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)){ + brightness *= (CGeneral::GetRandomNumber()&127) / 640.0f + 0.5f; + CSprite::RenderOneXLUSprite(screenpos.x, screenpos.y, screenpos.z, + szx*5.0f, szy*5.0f, brightness, brightness, brightness, 255, 1.0f/screenpos.z, 255); + } + } + + // Low clouds + float lowcloudintensity = 1.0f - Max(Max(CWeather::Foggyness, CWeather::CloudCoverage), CWeather::ExtraSunnyness); + int r = CTimeCycle::GetLowCloudsRed() * lowcloudintensity; + int g = CTimeCycle::GetLowCloudsGreen() * lowcloudintensity; + int b = CTimeCycle::GetLowCloudsBlue() * lowcloudintensity; + for(int cloudtype = 0; cloudtype < 3; cloudtype++){ + for(i = cloudtype; i < 12; i += 3){ + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCloudTex[cloudtype])); + RwV3d pos = { 800.0f*LowCloudsX[i], 800.0f*LowCloudsY[i], 60.0f*LowCloudsZ[i] }; + worldpos.x = campos.x + pos.x; + worldpos.y = campos.y + pos.y; + worldpos.z = 40.0f + pos.z; + if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)) + CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension(screenpos.x, screenpos.y, screenpos.z, + szx*320.0f, szy*40.0f, r, g, b, 255, 1.0f/screenpos.z, ms_cameraRoll, 255); + } + CSprite::FlushSpriteBuffer(); + } + + // Fluffy clouds + float rot_sin = Sin(CloudRotation); + float rot_cos = Cos(CloudRotation); + int fluffyalpha = 160 * (1.0f - Max(CWeather::Foggyness, CWeather::ExtraSunnyness)); + if(fluffyalpha != 0){ + static bool bCloudOnScreen[37]; + float sundist, hilight; + + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCloudTex[4])); + for(i = 0; i < 37; i++){ + RwV3d pos = { 2.0f*CoorsOffsetX[i], 2.0f*CoorsOffsetY[i], 40.0f*CoorsOffsetZ[i] + 40.0f }; + worldpos.x = pos.x*rot_cos + pos.y*rot_sin + campos.x; + worldpos.y = pos.x*rot_sin - pos.y*rot_cos + campos.y; + worldpos.z = pos.z; + + if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)){ + sundist = Sqrt(sq(screenpos.x-CCoronas::SunScreenX) + sq(screenpos.y-CCoronas::SunScreenY)); + int tr = CTimeCycle::GetFluffyCloudsTopRed(); + int tg = CTimeCycle::GetFluffyCloudsTopGreen(); + int tb = CTimeCycle::GetFluffyCloudsTopBlue(); + int br = CTimeCycle::GetFluffyCloudsBottomRed(); + int bg = CTimeCycle::GetFluffyCloudsBottomGreen(); + int bb = CTimeCycle::GetFluffyCloudsBottomBlue(); + int distLimit = (3*SCREEN_WIDTH)/4; + if(sundist < distLimit){ + hilight = (1.0f - Max(CWeather::Foggyness, CWeather::CloudCoverage)) * (1.0f - sundist/(float)distLimit); + tr = tr*(1.0f-hilight) + 255*hilight; + tg = tg*(1.0f-hilight) + 190*hilight; + tb = tb*(1.0f-hilight) + 190*hilight; + br = br*(1.0f-hilight) + 255*hilight; + bg = bg*(1.0f-hilight) + 190*hilight; + bb = bb*(1.0f-hilight) + 190*hilight; + if(sundist < SCREEN_WIDTH/10) + CCoronas::SunBlockedByClouds = true; + }else + hilight = 0.0f; + CSprite::RenderBufferedOneXLUSprite_Rotate_2Colours(screenpos.x, screenpos.y, screenpos.z, + szx*55.0f, szy*55.0f, + tr, tg, tb, br, bg, bb, 0.0f, -1.0f, + 1.0f/screenpos.z, + (uint16)IndividualRotation/65336.0f * 6.28f + ms_cameraRoll, + fluffyalpha); + bCloudOnScreen[i] = true; + }else + bCloudOnScreen[i] = false; + } + CSprite::FlushSpriteBuffer(); + + // Highlights + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCloudTex[3])); + + for(i = 0; i < 37; i++){ + RwV3d pos = { 2.0f*CoorsOffsetX[i], 2.0f*CoorsOffsetY[i], 40.0f*CoorsOffsetZ[i] + 40.0f }; + worldpos.x = pos.x*rot_cos + pos.y*rot_sin + campos.x; + worldpos.y = pos.x*rot_sin + pos.y*rot_cos + campos.y; + worldpos.z = pos.z; + if(bCloudOnScreen[i] && CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)){ + if(sundist < SCREEN_WIDTH/3){ + CSprite::RenderBufferedOneXLUSprite_Rotate_Aspect(screenpos.x, screenpos.y, screenpos.z, + szx*30.0f, szy*30.0f, + 200*hilight, 0, 0, 255, 1.0f/screenpos.z, + 1.7f - CGeneral::GetATanOfXY(screenpos.x-CCoronas::SunScreenX, screenpos.y-CCoronas::SunScreenY) + CClouds::ms_cameraRoll, 255); + } + } + } + CSprite::FlushSpriteBuffer(); + } + + // Rainbow + if(CWeather::Rainbow != 0.0f){ + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[0])); + for(i = 0; i < 6; i++){ + RwV3d pos = { i*1.5f, 100.0f, 5.0f }; + RwV3dAdd(&worldpos, &campos, &pos); + if(CSprite::CalcScreenCoors(worldpos, &screenpos, &szx, &szy, false)) + CSprite::RenderBufferedOneXLUSprite(screenpos.x, screenpos.y, screenpos.z, + 2.0f*szx, 50.0*szy, + BowRed[i]*CWeather::Rainbow, BowGreen[i]*CWeather::Rainbow, BowBlue[i]*CWeather::Rainbow, + 255, 1.0f/screenpos.z, 255); + + } + CSprite::FlushSpriteBuffer(); + } + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + + POP_RENDERGROUP(); +} + +bool +UseDarkBackground(void) +{ + return TheCamera.GetForward().z < -0.9f || gbShowCollisionPolys; +} + +void +CClouds::RenderBackground(int16 topred, int16 topgreen, int16 topblue, + int16 botred, int16 botgreen, int16 botblue, int16 alpha) +{ + PUSH_RENDERGROUP("CClouds::RenderBackground"); + + CVector right = CrossProduct(TheCamera.GetUp(), TheCamera.GetForward()); + right.Normalise(); + float c = right.Magnitude2D(); + if(c > 1.0f) + c = 1.0f; + ms_cameraRoll = Acos(c); + if(right.z < 0.0f) + ms_cameraRoll = -ms_cameraRoll; + + ms_HorizonTilt = SCREEN_WIDTH/2.0f * Tan(ms_cameraRoll); + + if(UseDarkBackground()){ + ms_colourTop.r = 50; + ms_colourTop.g = 50; + ms_colourTop.b = 50; + ms_colourTop.a = 255; + if(gbShowCollisionPolys){ + if(CTimer::GetFrameCounter() & 1){ + ms_colourTop.r = 0; + ms_colourTop.g = 0; + ms_colourTop.b = 0; + }else{ + ms_colourTop.r = 255; + ms_colourTop.g = 255; + ms_colourTop.b = 255; + } + } + ms_colourBottom = ms_colourTop; + CRect r(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + CSprite2d::DrawRect(r, ms_colourBottom, ms_colourBottom, ms_colourTop, ms_colourTop); + }else{ + ms_horizonZ = CSprite::CalcHorizonCoors(); + + int fogr = (topred + 2 * botred) / 3; + int fogg = (topgreen + 2 * botgreen) / 3; + int fogb = (topblue + 2 * botblue) / 3; + + // Draw top/bottom gradient + float gradheight = SCREEN_HEIGHT/2.0f; + + ms_colourTop.r = topred; + ms_colourTop.g = topgreen; + ms_colourTop.b = topblue; + ms_colourTop.a = alpha; + ms_colourBottom.r = botred; + ms_colourBottom.g = botgreen; + ms_colourBottom.b = botblue; + ms_colourBottom.a = alpha; + + float botright = ms_horizonZ - ms_HorizonTilt; + float botleft = ms_horizonZ + ms_HorizonTilt; + float topright = botright - gradheight; + float topleft = botleft - gradheight; + + CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, + ms_colourTop, ms_colourTop, ms_colourBottom, ms_colourBottom); + + // draw the small stripe (whatever it's supposed to be) + ms_colourTop.r = fogr; + ms_colourTop.g = fogg; + ms_colourTop.b = fogb; + ms_colourTop.a = alpha; + topright = ms_horizonZ - ms_HorizonTilt; + topleft = ms_horizonZ + ms_HorizonTilt; + botright = topright + SMALLSTRIPHEIGHT; + botleft = topleft + SMALLSTRIPHEIGHT; + CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, + ms_colourTop, ms_colourTop, ms_colourTop, ms_colourTop); + + // Only top + if(ms_horizonZ + ms_HorizonTilt - gradheight > 0.0f || + ms_horizonZ - ms_HorizonTilt - gradheight > 0.0f){ + ms_colourTop.r = topred; + ms_colourTop.g = topgreen; + ms_colourTop.b = topblue; + ms_colourTop.a = alpha; + + if(ms_horizonZ - Abs(ms_HorizonTilt) - gradheight > SCREEN_HEIGHT){ + // only top is visible + topleft = 0.0f; + topright = 0.0f; + botleft = SCREEN_HEIGHT; + botright = SCREEN_HEIGHT; + }else{ + botright = ms_horizonZ - ms_HorizonTilt - gradheight; + botleft = ms_horizonZ + ms_HorizonTilt - gradheight; + topright = Min(ms_horizonZ - ms_HorizonTilt - 2*SCREEN_HEIGHT, 0.0f); + topleft = Min(ms_horizonZ + ms_HorizonTilt - 2*SCREEN_HEIGHT, 0.0f); + } + + CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, + ms_colourTop, ms_colourTop, ms_colourTop, ms_colourTop); + } + + // Set both to fog colour for RenderHorizon + ms_colourTop.r = fogr; + ms_colourTop.g = fogg; + ms_colourTop.b = fogb; + ms_colourBottom.r = fogr; + ms_colourBottom.g = fogg; + ms_colourBottom.b = fogb; + } + + POP_RENDERGROUP(); +} + +void +CClouds::RenderHorizon(void) +{ + if(UseDarkBackground()) + return; + + PUSH_RENDERGROUP("CClouds::RenderHorizon"); + + ms_colourBottom.a = 230; + ms_colourTop.a = 80; + + float topright = ms_horizonZ - ms_HorizonTilt; + float topleft = ms_horizonZ + ms_HorizonTilt; + float botright = topright + SMALLSTRIPHEIGHT; + float botleft = topleft + SMALLSTRIPHEIGHT; + + CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, + ms_colourTop, ms_colourTop, ms_colourBottom, ms_colourBottom); + + + ms_colourBkGrd.r = 128.0f*CTimeCycle::GetAmbientRed(); + ms_colourBkGrd.g = 128.0f*CTimeCycle::GetAmbientGreen(); + ms_colourBkGrd.b = 128.0f*CTimeCycle::GetAmbientBlue(); + ms_colourBkGrd.a = 255; + + float horzstrip = SCREEN_STRETCH_Y(HORIZSTRIPHEIGHT); + topright = botright; + topleft = botleft; + botright = topright + horzstrip; + botleft = topleft + horzstrip; + + CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, + ms_colourBottom, ms_colourBottom, ms_colourBkGrd, ms_colourBkGrd); + + + topright = botright; + topleft = botleft; + botright = Max(topright, SCREEN_HEIGHT); + botleft = Max(topleft, SCREEN_HEIGHT); + + CSprite2d::DrawAnyRect(0.0f, topleft, SCREEN_WIDTH, topright, 0.0f, botleft, SCREEN_WIDTH, botright, + ms_colourBkGrd, ms_colourBkGrd, ms_colourBkGrd, ms_colourBkGrd); + + POP_RENDERGROUP(); +} diff --git a/src/renderer/Clouds.h b/src/renderer/Clouds.h new file mode 100644 index 00000000..ef33030b --- /dev/null +++ b/src/renderer/Clouds.h @@ -0,0 +1,23 @@ +#pragma once + +class CClouds +{ +public: + static float CloudRotation; + static uint32 IndividualRotation; + + static float ms_cameraRoll; + static float ms_horizonZ; + static float ms_HorizonTilt; + static CRGBA ms_colourTop; + static CRGBA ms_colourBottom; + static CRGBA ms_colourBkGrd; + + static void Init(void); + static void Shutdown(void); + static void Update(void); + static void Render(void); + static void RenderBackground(int16 topred, int16 topgreen, int16 topblue, + int16 botred, int16 botgreen, int16 botblue, int16 alpha); + static void RenderHorizon(void); +}; diff --git a/src/renderer/Console.cpp b/src/renderer/Console.cpp new file mode 100644 index 00000000..244bfb17 --- /dev/null +++ b/src/renderer/Console.cpp @@ -0,0 +1,96 @@ +#include "common.h" +#include + +#include "Console.h" +#include "Font.h" +#include "Timer.h" + +#define CONSOLE_X_POS (30.0f) +#define CONSOLE_Y_POS (10.0f) +#define CONSOLE_LINE_HEIGHT (12.0f) + +CConsole TheConsole; + +void +CConsole::AddLine(char *s, uint8 r, uint8 g, uint8 b) +{ + char tempstr[MAX_STR_LEN+1]; + + while (strlen(s) > MAX_STR_LEN) { + strncpy(tempstr, s, MAX_STR_LEN); + tempstr[MAX_STR_LEN-1] = '\0'; + s += MAX_STR_LEN - 1; + AddOneLine(tempstr, r, g, b); + } + AddOneLine(s, r, g, b); +} + +void +CConsole::AddOneLine(char *s, uint8 r, uint8 g, uint8 b) +{ + int32 StrIndex = (m_nLineCount + m_nCurrentLine) % MAX_LINES; + + for (int32 i = 0; i < MAX_STR_LEN; i++) { + Buffers[StrIndex][i] = s[i]; + if (s[i] == '\0') break; + } + + uint8 _strNum1 = m_nLineCount; + if (_strNum1 < MAX_LINES) + _strNum1++; + + m_aTimer[StrIndex] = CTimer::GetTimeInMilliseconds(); + Buffers[StrIndex][MAX_STR_LEN-1] = '\0'; + m_aRed[StrIndex] = r; + m_aGreen[StrIndex] = g; + m_aBlue[StrIndex] = b; + + if (_strNum1 >= MAX_LINES) + m_nCurrentLine = (m_nCurrentLine + 1) % MAX_LINES; + else + m_nLineCount = _strNum1; + +} + +void +CConsole::Display() +{ + CFont::SetPropOn(); + CFont::SetBackgroundOff(); + CFont::SetScale(0.6f, 0.6f); + CFont::SetCentreOff(); + CFont::SetRightJustifyOff(); + CFont::SetJustifyOn(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetBackGroundOnlyTextOff(); + CFont::SetFontStyle(FONT_STANDARD); +#ifndef FIX_BUGS + CFont::SetPropOff(); // not sure why this is here anyway +#endif + CFont::SetWrapx(RsGlobal.width); + + while (m_nLineCount != 0 && CTimer::GetTimeInMilliseconds() - m_aTimer[m_nCurrentLine] > 20000) { + m_nLineCount--; + m_nCurrentLine = (m_nCurrentLine + 1) % MAX_LINES; + } + + for (int16 i = 0; i < m_nLineCount; i++) { + int16 line = (i + m_nCurrentLine) % MAX_LINES; + CFont::SetColor(CRGBA(0, 0, 0, 200)); + CFont::PrintString(CONSOLE_X_POS + 1.0f, CONSOLE_Y_POS + 1.0f + i * CONSOLE_LINE_HEIGHT, Buffers[line]); + CFont::SetColor(CRGBA(m_aRed[line], m_aGreen[line], m_aBlue[line], 200)); + CFont::PrintString(CONSOLE_X_POS, CONSOLE_Y_POS + i * CONSOLE_LINE_HEIGHT, Buffers[line]); + } +} + +void +cprintf(char* format, ...) +{ + char s[256]; + va_list vl1, vl2; + + va_start(vl1, format); + va_copy(vl2, vl1); + vsprintf(s, format, vl1); + TheConsole.AddLine(s, 255, 255, 128); +} diff --git a/src/renderer/Console.h b/src/renderer/Console.h new file mode 100644 index 00000000..9f22236f --- /dev/null +++ b/src/renderer/Console.h @@ -0,0 +1,27 @@ +#pragma once + +class CConsole +{ + enum + { + MAX_LINES = 8, // BUG? only shows 7 + MAX_STR_LEN = 40, + }; + + uint8 m_nLineCount; + uint8 m_nCurrentLine; + wchar Buffers[MAX_LINES][MAX_STR_LEN]; + uint32 m_aTimer[MAX_LINES]; + uint8 m_aRed[MAX_LINES]; + uint8 m_aGreen[MAX_LINES]; + uint8 m_aBlue[MAX_LINES]; +public: + void AddLine(char *s, uint8 r, uint8 g, uint8 b); + void AddOneLine(char *s, uint8 r, uint8 g, uint8 b); + void Display(); + void Init() { m_nCurrentLine = 0; m_nLineCount = 0; } +}; + +extern CConsole TheConsole; + +void cprintf(char*, ...); \ No newline at end of file diff --git a/src/renderer/Coronas.cpp b/src/renderer/Coronas.cpp new file mode 100644 index 00000000..d9bf88d1 --- /dev/null +++ b/src/renderer/Coronas.cpp @@ -0,0 +1,959 @@ +#include "common.h" + +#include "main.h" +#include "General.h" +#include "Entity.h" +#include "RenderBuffer.h" +#include "TxdStore.h" +#include "Camera.h" +#include "Sprite.h" +#include "Timer.h" +#include "World.h" +#include "Weather.h" +#include "Collision.h" +#include "Timecycle.h" +#include "Coronas.h" +#include "PointLights.h" +#include "Shadows.h" +#include "Clock.h" +#include "Bridge.h" + +struct FlareDef +{ + float position; + float size; + int16 red; + int16 green; + int16 blue; + int16 alpha; + int16 texture; +}; + +FlareDef SunFlareDef[] = { + { -0.5f, 15.0f, 50, 50, 0, 200, 1 }, + { -1.0f, 10.0f, 50, 20, 0, 200, 2 }, + { -1.5f, 15.0f, 50, 0, 0, 200, 3 }, + { -2.5f, 25.0f, 50, 0, 0, 200, 1 }, + { 0.5f, 12.5f, 40, 40, 25, 200, 1 }, + { 0.05f, 20.0f, 30, 22, 9, 200, 2 }, + { 1.3f, 7.5f, 50, 30, 9, 200, 3 }, + { 0.0f, 0.0f, 255, 255, 255, 255, 0 } +}; + +FlareDef HeadLightsFlareDef[] = { + { -0.5f, 15.5, 70, 70, 70, 200, 1 }, + { -1.0f, 10.0, 70, 70, 70, 200, 2 }, + { -1.5f, 5.5f, 50, 50, 50, 200, 3 }, + { 0.5f, 12.0f, 50, 50, 50, 200, 1 }, + { 0.05f, 20.0f, 40, 40, 40, 200, 2 }, + { 1.3f, 8.0f, 60, 60, 60, 200, 3 }, + { -2.0f, 12.0f, 50, 50, 50, 200, 1 }, + { -2.3f, 15.0f, 40, 40, 40, 200, 2 }, + { -3.0f, 16.0f, 40, 40, 40, 200, 3 }, + { 0.0f, 0.0f, 255, 255, 255, 255, 0 } +}; + + +RwTexture *gpCoronaTexture[9] = { nil, nil, nil, nil, nil, nil, nil, nil, nil }; + +float CCoronas::LightsMult = 1.0f; +float CCoronas::SunScreenX; +float CCoronas::SunScreenY; +int CCoronas::MoonSize; +bool CCoronas::SunBlockedByClouds; +int CCoronas::bChangeBrightnessImmediately; + +CRegisteredCorona CCoronas::aCoronas[NUMCORONAS]; + +const char aCoronaSpriteNames[][32] = { + "coronastar", + "corona", + "coronamoon", + "coronareflect", + "coronaheadlightline", + "coronahex", + "coronacircle", + "coronaringa", + "streek" +}; + +void +CCoronas::Init(void) +{ + int i; + + CTxdStore::PushCurrentTxd(); + CTxdStore::SetCurrentTxd(CTxdStore::FindTxdSlot("particle")); + + for(i = 0; i < 9; i++) + if(gpCoronaTexture[i] == nil) + gpCoronaTexture[i] = RwTextureRead(aCoronaSpriteNames[i], nil); + + CTxdStore::PopCurrentTxd(); + + for(i = 0; i < NUMCORONAS; i++) + aCoronas[i].id = 0; +} + +void +CCoronas::Shutdown(void) +{ + int i; + for(i = 0; i < 9; i++) + if(gpCoronaTexture[i]){ + RwTextureDestroy(gpCoronaTexture[i]); + gpCoronaTexture[i] = nil; + } +} + +void +CCoronas::Update(void) +{ + int i; + static int LastCamLook = 0; + + LightsMult = Min(LightsMult + 0.03f * CTimer::GetTimeStep(), 1.0f); + + int CamLook = 0; + if(TheCamera.Cams[TheCamera.ActiveCam].LookingLeft) CamLook |= 1; + if(TheCamera.Cams[TheCamera.ActiveCam].LookingRight) CamLook |= 2; + if(TheCamera.Cams[TheCamera.ActiveCam].LookingBehind) CamLook |= 4; + // BUG? + if(TheCamera.GetLookDirection() == LOOKING_BEHIND) CamLook |= 8; + + if(LastCamLook != CamLook) + bChangeBrightnessImmediately = 3; + else + bChangeBrightnessImmediately = Max(bChangeBrightnessImmediately-1, 0); + LastCamLook = CamLook; + + for(i = 0; i < NUMCORONAS; i++) + if(aCoronas[i].id != 0) + aCoronas[i].Update(); +} + +void +CCoronas::RegisterCorona(uint32 id, uint8 red, uint8 green, uint8 blue, uint8 alpha, + const CVector &coors, float size, float drawDist, RwTexture *tex, + int8 flareType, uint8 reflection, uint8 LOScheck, uint8 drawStreak, float someAngle, + bool useNearDist, float nearDist) +{ + int i; + + if(sq(drawDist) < (TheCamera.GetPosition() - coors).MagnitudeSqr2D()) + return; + + if(useNearDist){ + float dist = (TheCamera.GetPosition() - coors).Magnitude(); + if(dist < 35.0f) + return; + if(dist < 50.0f) + alpha *= (dist - 35.0f)/(50.0f - 35.0f); + } + + for(i = 0; i < NUMCORONAS; i++) + if(aCoronas[i].id == id) + break; + + if(i == NUMCORONAS){ + // add a new one + + // find empty slot + for(i = 0; i < NUMCORONAS; i++) + if(aCoronas[i].id == 0) + break; + if(i == NUMCORONAS) + return; // no space + + aCoronas[i].fadeAlpha = 0; + aCoronas[i].offScreen = true; + aCoronas[i].firstUpdate = true; + aCoronas[i].renderReflection = false; + aCoronas[i].lastLOScheck = 0; + aCoronas[i].sightClear = false; + aCoronas[i].hasValue[0] = false; + aCoronas[i].hasValue[1] = false; + aCoronas[i].hasValue[2] = false; + aCoronas[i].hasValue[3] = false; + aCoronas[i].hasValue[4] = false; + aCoronas[i].hasValue[5] = false; + + }else{ + // use existing one + + if(aCoronas[i].fadeAlpha == 0 && alpha == 0){ + // unregister + aCoronas[i].id = 0; + return; + } + } + + aCoronas[i].id = id; + aCoronas[i].red = red; + aCoronas[i].green = green; + aCoronas[i].blue = blue; + aCoronas[i].alpha = alpha; + aCoronas[i].coors = coors; + aCoronas[i].size = size; + aCoronas[i].someAngle = someAngle; + aCoronas[i].registeredThisFrame = true; + aCoronas[i].drawDist = drawDist; + aCoronas[i].texture = tex; + aCoronas[i].flareType = flareType; + aCoronas[i].reflection = reflection; + aCoronas[i].LOScheck = LOScheck; + aCoronas[i].drawStreak = drawStreak; + aCoronas[i].useNearDist = useNearDist; + aCoronas[i].nearDist = nearDist; +} + +void +CCoronas::RegisterCorona(uint32 id, uint8 red, uint8 green, uint8 blue, uint8 alpha, + const CVector &coors, float size, float drawDist, uint8 type, + int8 flareType, uint8 reflection, uint8 LOScheck, uint8 drawStreak, float someAngle, + bool useNearDist, float nearDist) +{ + RegisterCorona(id, red, green, blue, alpha, coors, size, drawDist, + gpCoronaTexture[type], flareType, reflection, LOScheck, drawStreak, someAngle, + useNearDist, nearDist); +} + +void +CCoronas::UpdateCoronaCoors(uint32 id, const CVector &coors, float drawDist, float someAngle) +{ + int i; + + if(sq(drawDist) < (TheCamera.GetPosition() - coors).MagnitudeSqr2D()) + return; + + for(i = 0; i < NUMCORONAS; i++) + if(aCoronas[i].id == id) + break; + + if(i == NUMCORONAS) + return; + + if(aCoronas[i].fadeAlpha == 0) + aCoronas[i].id = 0; // faded out, remove + else{ + aCoronas[i].coors = coors; + aCoronas[i].someAngle = someAngle; + } +} + +static RwIm2DVertex vertexbufferX[2]; + +void +CCoronas::Render(void) +{ + int i, j; + int screenw, screenh; + + PUSH_RENDERGROUP("CCoronas::Render"); + + screenw = RwRasterGetWidth(RwCameraGetRaster(Scene.camera)); + screenh = RwRasterGetHeight(RwCameraGetRaster(Scene.camera)); + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + + for(i = 0; i < NUMCORONAS; i++){ + for(j = 5; j > 0; j--){ + aCoronas[i].prevX[j] = aCoronas[i].prevX[j-1]; + aCoronas[i].prevY[j] = aCoronas[i].prevY[j-1]; + aCoronas[i].prevRed[j] = aCoronas[i].prevRed[j-1]; + aCoronas[i].prevGreen[j] = aCoronas[i].prevGreen[j-1]; + aCoronas[i].prevBlue[j] = aCoronas[i].prevBlue[j-1]; + aCoronas[i].hasValue[j] = aCoronas[i].hasValue[j-1]; + } + aCoronas[i].hasValue[0] = false; + + if(aCoronas[i].id == 0 || + aCoronas[i].fadeAlpha == 0 && aCoronas[i].alpha == 0) + continue; + + CVector spriteCoors; + float spritew, spriteh; + if(!CSprite::CalcScreenCoors(aCoronas[i].coors, &spriteCoors, &spritew, &spriteh, true)){ + aCoronas[i].offScreen = true; + aCoronas[i].sightClear = false; + }else{ + aCoronas[i].offScreen = false; + + if(spriteCoors.x < 0.0f || spriteCoors.y < 0.0f || + spriteCoors.x > screenw || spriteCoors.y > screenh){ + aCoronas[i].offScreen = true; + aCoronas[i].sightClear = false; + }else{ + if(CTimer::GetTimeInMilliseconds() > aCoronas[i].lastLOScheck + 2000){ + aCoronas[i].lastLOScheck = CTimer::GetTimeInMilliseconds(); + aCoronas[i].sightClear = CWorld::GetIsLineOfSightClear( + aCoronas[i].coors, TheCamera.Cams[TheCamera.ActiveCam].Source, + true, true, false, false, false, true, false); + } + + // add new streak point + if(aCoronas[i].sightClear){ + aCoronas[i].prevX[0] = spriteCoors.x; + aCoronas[i].prevY[0] = spriteCoors.y; + aCoronas[i].prevRed[0] = aCoronas[i].red; + aCoronas[i].prevGreen[0] = aCoronas[i].green; + aCoronas[i].prevBlue[0] = aCoronas[i].blue; + aCoronas[i].hasValue[0] = true; + } + + // if distance too big, break streak + if(aCoronas[i].hasValue[1]){ + if(Abs(aCoronas[i].prevX[0] - aCoronas[i].prevX[1]) > 50.0f || + Abs(aCoronas[i].prevY[0] - aCoronas[i].prevY[1]) > 50.0f) + aCoronas[i].hasValue[0] = false; + } + } + + + if(aCoronas[i].fadeAlpha && spriteCoors.z < aCoronas[i].drawDist){ + float recipz = 1.0f/spriteCoors.z; + float fadeDistance = aCoronas[i].drawDist / 2.0f; + float distanceFade = spriteCoors.z < fadeDistance ? 1.0f : 1.0f - (spriteCoors.z - fadeDistance)/fadeDistance; + int totalFade = aCoronas[i].fadeAlpha * distanceFade; + + if(aCoronas[i].LOScheck) + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + else + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + + // render corona itself + if(aCoronas[i].texture){ + float fogscale = CWeather::Foggyness*Min(spriteCoors.z, 40.0f)/40.0f + 1.0f; + if(CCoronas::aCoronas[i].id == SUN_CORE) + spriteCoors.z = 0.95f * RwCameraGetFarClipPlane(Scene.camera); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(aCoronas[i].texture)); + spriteCoors.z -= aCoronas[i].nearDist; + + if(aCoronas[i].texture == gpCoronaTexture[8]){ + // what's this? + float f = 1.0f - aCoronas[i].someAngle*2.0f/PI; + float wscale = 6.0f*sq(sq(sq(f))) + 0.5f; + float hscale = 0.35f - (wscale - 0.5f) * 0.06f; + hscale = Max(hscale, 0.15f); + + CSprite::RenderOneXLUSprite(spriteCoors.x, spriteCoors.y, spriteCoors.z, + spritew * aCoronas[i].size * wscale, + spriteh * aCoronas[i].size * fogscale * hscale, + CCoronas::aCoronas[i].red / fogscale, + CCoronas::aCoronas[i].green / fogscale, + CCoronas::aCoronas[i].blue / fogscale, + totalFade, + recipz, + 255); + }else{ + CSprite::RenderOneXLUSprite_Rotate_Aspect( + spriteCoors.x, spriteCoors.y, spriteCoors.z, + spritew * aCoronas[i].size * fogscale, + spriteh * aCoronas[i].size * fogscale, + CCoronas::aCoronas[i].red / fogscale, + CCoronas::aCoronas[i].green / fogscale, + CCoronas::aCoronas[i].blue / fogscale, + totalFade, + recipz, + 20.0f * recipz, + 255); + } + } + + // render flares + if(aCoronas[i].flareType != FLARE_NONE){ + FlareDef *flare; + + switch(aCoronas[i].flareType){ + case FLARE_SUN: flare = SunFlareDef; break; + case FLARE_HEADLIGHTS: flare = HeadLightsFlareDef; break; + default: assert(0); + } + + for(; flare->texture; flare++){ + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[flare->texture + 4])); + CSprite::RenderOneXLUSprite( + (spriteCoors.x - (screenw/2)) * flare->position + (screenw/2), + (spriteCoors.y - (screenh/2)) * flare->position + (screenh/2), + spriteCoors.z, + 4.0f*flare->size * spritew/spriteh, + 4.0f*flare->size, + (flare->red * aCoronas[i].red)>>8, + (flare->green * aCoronas[i].green)>>8, + (flare->blue * aCoronas[i].blue)>>8, + (totalFade * flare->alpha)>>8, + recipz, 255); + } + } + } + } + } + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + + // streaks + for(i = 0; i < NUMCORONAS; i++){ + if(aCoronas[i].id == 0 || !aCoronas[i].drawStreak) + continue; + + for(j = 0; j < 5; j++){ + if(!aCoronas[i].hasValue[j] || !aCoronas[i].hasValue[j+1]) + continue; + + int alpha1 = (float)(6 - j) / 6 * 128; + int alpha2 = (float)(6 - (j+1)) / 6 * 128; + + RwIm2DVertexSetScreenX(&vertexbufferX[0], aCoronas[i].prevX[j]); + RwIm2DVertexSetScreenY(&vertexbufferX[0], aCoronas[i].prevY[j]); + RwIm2DVertexSetIntRGBA(&vertexbufferX[0], aCoronas[i].prevRed[j] * alpha1 / 256, aCoronas[i].prevGreen[j] * alpha1 / 256, aCoronas[i].prevBlue[j] * alpha1 / 256, 255); + RwIm2DVertexSetScreenX(&vertexbufferX[1], aCoronas[i].prevX[j+1]); + RwIm2DVertexSetScreenY(&vertexbufferX[1], aCoronas[i].prevY[j+1]); + RwIm2DVertexSetIntRGBA(&vertexbufferX[1], aCoronas[i].prevRed[j+1] * alpha2 / 256, aCoronas[i].prevGreen[j+1] * alpha2 / 256, aCoronas[i].prevBlue[j+1] * alpha2 / 256, 255); + +#ifdef FIX_BUGS + RwIm2DVertexSetScreenZ(&vertexbufferX[0], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&vertexbufferX[0], RwCameraGetNearClipPlane(Scene.camera)); + RwIm2DVertexSetRecipCameraZ(&vertexbufferX[0], 1.0f/RwCameraGetNearClipPlane(Scene.camera)); + RwIm2DVertexSetScreenZ(&vertexbufferX[1], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&vertexbufferX[1], RwCameraGetNearClipPlane(Scene.camera)); + RwIm2DVertexSetRecipCameraZ(&vertexbufferX[1], 1.0f/RwCameraGetNearClipPlane(Scene.camera)); +#endif + + RwIm2DRenderLine(vertexbufferX, 2, 0, 1); + } + } + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + + POP_RENDERGROUP(); +} + +void +CCoronas::RenderReflections(void) +{ + int i; + CColPoint point; + CEntity *entity; + + if(CWeather::WetRoads > 0.0f){ + PUSH_RENDERGROUP("CCoronas::RenderReflections"); + + CSprite::InitSpriteBuffer(); + + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[3])); + + for(i = 0; i < NUMCORONAS; i++){ + if(aCoronas[i].id == 0 || + aCoronas[i].fadeAlpha == 0 && aCoronas[i].alpha == 0 || + aCoronas[i].reflection == 0) + continue; + + // check if we want a reflection on this corona + if(aCoronas[i].renderReflection){ + if(((CTimer::GetFrameCounter() + i) & 0xF) == 0 && + CWorld::ProcessVerticalLine(aCoronas[i].coors, -1000.0f, point, entity, true, false, false, false, true, false, nil)) + aCoronas[i].heightAboveRoad = aCoronas[i].coors.z - point.point.z; + }else{ + if(CWorld::ProcessVerticalLine(aCoronas[i].coors, -1000.0f, point, entity, true, false, false, false, true, false, nil)){ + aCoronas[i].heightAboveRoad = aCoronas[i].coors.z - point.point.z; + aCoronas[i].renderReflection = true; + } + } + + // Don't draw if reflection is too high + if(aCoronas[i].renderReflection && aCoronas[i].heightAboveRoad < 20.0f){ + // don't draw if camera is below road + if(CCoronas::aCoronas[i].coors.z - aCoronas[i].heightAboveRoad > TheCamera.GetPosition().z) + continue; + + CVector coors = aCoronas[i].coors; + coors.z -= 2.0f*aCoronas[i].heightAboveRoad; + + CVector spriteCoors; + float spritew, spriteh; + if(CSprite::CalcScreenCoors(coors, &spriteCoors, &spritew, &spriteh, true)) { + float drawDist = 0.75f * aCoronas[i].drawDist; + drawDist = Min(drawDist, 55.0f); + if(spriteCoors.z < drawDist){ + float fadeDistance = drawDist / 2.0f; + float distanceFade = spriteCoors.z < fadeDistance ? 1.0f : 1.0f - (spriteCoors.z - fadeDistance)/fadeDistance; + distanceFade = Clamp(distanceFade, 0.0f, 1.0f); + float recipz = 1.0f/RwCameraGetNearClipPlane(Scene.camera); + float heightFade = (20.0f - aCoronas[i].heightAboveRoad)/20.0f; + int intensity = distanceFade*heightFade * 230.0 * CWeather::WetRoads; + + CSprite::RenderBufferedOneXLUSprite( +#ifdef FIX_BUGS + spriteCoors.x, spriteCoors.y, spriteCoors.z, +#else + spriteCoors.x, spriteCoors.y, RwIm2DGetNearScreenZ(), +#endif + spritew * aCoronas[i].size * 0.75f, + spriteh * aCoronas[i].size * 2.0f, + (intensity * CCoronas::aCoronas[i].red)>>8, + (intensity * CCoronas::aCoronas[i].green)>>8, + (intensity * CCoronas::aCoronas[i].blue)>>8, + 255, + recipz, + 255); + } + } + } + } + CSprite::FlushSpriteBuffer(); + + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + + POP_RENDERGROUP(); + }else{ + for(i = 0; i < NUMCORONAS; i++) + aCoronas[i].renderReflection = false; + } +} + +void +CCoronas::RenderSunReflection(void) +{ + float sunZDir = CTimeCycle::GetSunDirection().z; + if(sunZDir > -0.05f){ + float intensity = (0.3f - Abs(sunZDir - 0.25f))/0.3f * + (1.0f - CWeather::CloudCoverage) * + (1.0f - CWeather::Foggyness) * + (1.0f - CWeather::Wind); + if(intensity > 0.0f){ + int r = (CTimeCycle::GetSunCoreRed() + CTimeCycle::GetSunCoronaRed())*intensity*0.25f; + int g = (CTimeCycle::GetSunCoreGreen() + CTimeCycle::GetSunCoronaGreen())*intensity*0.25f; + int b = (CTimeCycle::GetSunCoreBlue() + CTimeCycle::GetSunCoronaBlue())*intensity*0.25f; + + CVector sunPos = 40.0f*CTimeCycle::GetSunDirection() + TheCamera.GetPosition(); + sunPos.z = 0.5f*CWeather::Wind + 6.1f; + CVector sunDir = CTimeCycle::GetSunDirection(); + sunDir.z = 0.0; + sunDir.Normalise(); + + TempBufferIndicesStored = 6; + TempBufferRenderIndexList[0] = 2; + TempBufferRenderIndexList[1] = 1; + TempBufferRenderIndexList[2] = 0; + TempBufferRenderIndexList[3] = 2; + TempBufferRenderIndexList[4] = 3; + TempBufferRenderIndexList[5] = 1; + + // 60 unit square in sun direction + TempBufferVerticesStored = 4; + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[0], r, g, b, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[0], + sunPos.x + 30.0f*sunDir.y, + sunPos.y - 30.0f*sunDir.x, + sunPos.z); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[1], r, g, b, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[1], + sunPos.x - 30.0f*sunDir.y, + sunPos.y + 30.0f*sunDir.x, + sunPos.z); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[2], r, g, b, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[2], + sunPos.x + 60.0f*sunDir.x + 30.0f*sunDir.y, + sunPos.y + 60.0f*sunDir.y - 30.0f*sunDir.x, + sunPos.z); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[3], r, g, b, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[3], + sunPos.x + 60.0f*sunDir.x - 30.0f*sunDir.y, + sunPos.y + 60.0f*sunDir.y + 30.0f*sunDir.x, + sunPos.z); + + RwIm3DVertexSetU(&TempBufferRenderVertices[0], 0.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[0], 1.0f); + RwIm3DVertexSetU(&TempBufferRenderVertices[1], 1.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[1], 1.0f); + RwIm3DVertexSetU(&TempBufferRenderVertices[2], 0.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[2], 0.5f); + RwIm3DVertexSetU(&TempBufferRenderVertices[3], 1.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[3], 0.5f); + + int timeInc = 0; + int sideInc = 0; + int fwdInc = 0; + for(int i = 0; i < 20; i++){ + TempBufferRenderIndexList[TempBufferIndicesStored + 0] = TempBufferVerticesStored; + TempBufferRenderIndexList[TempBufferIndicesStored + 1] = TempBufferVerticesStored-1; + TempBufferRenderIndexList[TempBufferIndicesStored + 2] = TempBufferVerticesStored-2; + TempBufferRenderIndexList[TempBufferIndicesStored + 3] = TempBufferVerticesStored; + TempBufferRenderIndexList[TempBufferIndicesStored + 4] = TempBufferVerticesStored+1; + TempBufferRenderIndexList[TempBufferIndicesStored + 5] = TempBufferVerticesStored-1; + TempBufferIndicesStored += 6; + + // What a weird way to do it... + float fwdLen = fwdInc/20 + 60; + float sideLen = sideInc/20 + 30; + sideLen += 10.0f*Sin((float)(CTimer::GetTimeInMilliseconds()+timeInc & 0x7FF)/0x800*TWOPI); + timeInc += 900; + sideInc += 970; + fwdInc += 1440; + + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+0], r, g, b, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+0], + sunPos.x + fwdLen*sunDir.x + sideLen*sunDir.y, + sunPos.y + fwdLen*sunDir.y - sideLen*sunDir.x, + sunPos.z); + + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+1], r, g, b, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+1], + sunPos.x + fwdLen*sunDir.x - sideLen*sunDir.y, + sunPos.y + fwdLen*sunDir.y + sideLen*sunDir.x, + sunPos.z); + + RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored+0], 0.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored+0], 0.5f); + RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored+1], 1.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored+1], 0.5f); + TempBufferVerticesStored += 2; + } + + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEFOGTYPE, (void*)rwFOGTYPELINEAR); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[4])); + if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV)){ + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); + RwIm3DEnd(); + } + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + TempBufferVerticesStored = 0; + TempBufferIndicesStored = 0; + } + } +} + +void +CCoronas::DoSunAndMoon(void) +{ + // yeah, moon is done somewhere else.... + + CVector sunCoors = CTimeCycle::GetSunDirection(); + sunCoors *= 150.0f; + sunCoors += TheCamera.GetPosition(); + + if(CTimeCycle::GetSunDirection().z > -0.2f){ + float size = ((CGeneral::GetRandomNumber()&0xFF) * 0.005f + 10.0f) * CTimeCycle::GetSunSize(); + RegisterCorona(SUN_CORE, + CTimeCycle::GetSunCoreRed(), CTimeCycle::GetSunCoreGreen(), CTimeCycle::GetSunCoreBlue(), + 255, sunCoors, size, + 999999.88f, TYPE_STAR, FLARE_NONE, REFLECTION_OFF, LOSCHECK_OFF, STREAK_OFF, 0.0f); + + if(CTimeCycle::GetSunDirection().z > 0.0f && !CGame::IsInInterior()) + RegisterCorona(SUN_CORONA, + CTimeCycle::GetSunCoronaRed(), CTimeCycle::GetSunCoronaGreen(), CTimeCycle::GetSunCoronaBlue(), + 255, sunCoors, 25.0f * CTimeCycle::GetSunSize(), + 999999.88f, TYPE_STAR, FLARE_SUN, REFLECTION_OFF, LOSCHECK_ON, STREAK_OFF, 0.0f); + } + + CVector spriteCoors; + float spritew, spriteh; + if(CSprite::CalcScreenCoors(sunCoors, &spriteCoors, &spritew, &spriteh, true)) { + SunScreenX = spriteCoors.x; + SunScreenY = spriteCoors.y; + }else{ + SunScreenX = 1000000.0f; + SunScreenY = 1000000.0f; + } +} + +void +CRegisteredCorona::Update(void) +{ + if(!registeredThisFrame) + alpha = 0; + + if(LOScheck && + (CCoronas::SunBlockedByClouds && id == CCoronas::SUN_CORONA || + !CWorld::GetIsLineOfSightClear(coors, TheCamera.GetPosition(), true, false, false, false, false, false))){ + // Corona is blocked, fade out + fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); + }else if(offScreen){ + // Same when off screen + fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), 0.0f); + }else{ + // Visible + if(alpha > fadeAlpha){ + // fade in + fadeAlpha = Min(fadeAlpha + 15.0f*CTimer::GetTimeStep(), alpha); + if(CCoronas::bChangeBrightnessImmediately) + fadeAlpha = alpha; + }else if(alpha < fadeAlpha){ + // too visible, decrease alpha but not below alpha + fadeAlpha = Max(fadeAlpha - 15.0f*CTimer::GetTimeStep(), alpha); + } + + // darken scene when the sun is visible + if(id == CCoronas::SUN_CORONA) + CCoronas::LightsMult = Max(CCoronas::LightsMult - CTimer::GetTimeStep()*0.06f, 0.6f); + } + + // remove if invisible + if(fadeAlpha == 0 && !firstUpdate) + id = 0; + firstUpdate = false; + registeredThisFrame = false; +} + +void +CEntity::ProcessLightsForEntity(void) +{ + int i, n; + C2dEffect *effect; + CVector pos; + bool lightOn, lightFlickering; + uint32 flashTimer1, flashTimer2, flashTimer3; + + if(bRenderDamaged || !bIsVisible || GetUp().z < 0.96f) + return; + + flashTimer1 = 0; + flashTimer2 = 0; + flashTimer3 = 0; + + n = CModelInfo::GetModelInfo(GetModelIndex())->GetNum2dEffects(); + for(i = 0; i < n; i++, flashTimer1 += 0x80, flashTimer2 += 0x100, flashTimer3 += 0x200){ + effect = CModelInfo::GetModelInfo(GetModelIndex())->Get2dEffect(i); + + switch(effect->type){ + case EFFECT_LIGHT: + pos = GetMatrix() * effect->pos; + + lightOn = false; + lightFlickering = false; + switch(effect->light.lightType){ + case LIGHT_ON: + lightOn = true; + break; + case LIGHT_ON_NIGHT: + if(CClock::GetHours() > 18 || CClock::GetHours() < 7) + lightOn = true; + break; + case LIGHT_FLICKER: + if((CTimer::GetTimeInMilliseconds() ^ m_randomSeed) & 0x60) + lightOn = true; + else + lightFlickering = true; + if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed) & 3) + lightOn = true; + break; + case LIGHT_FLICKER_NIGHT: + if(CClock::GetHours() > 18 || CClock::GetHours() < 7 || CWeather::WetRoads > 0.5f){ + if((CTimer::GetTimeInMilliseconds() ^ m_randomSeed) & 0x60) + lightOn = true; + else + lightFlickering = true; + if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed) & 3) + lightOn = true; + } + break; + case LIGHT_FLASH1: + if((CTimer::GetTimeInMilliseconds() + flashTimer1) & 0x200) + lightOn = true; + break; + case LIGHT_FLASH1_NIGHT: + if(CClock::GetHours() > 18 || CClock::GetHours() < 7) + if((CTimer::GetTimeInMilliseconds() + flashTimer1) & 0x200) + lightOn = true; + break; + case LIGHT_FLASH2: + if((CTimer::GetTimeInMilliseconds() + flashTimer2) & 0x400) + lightOn = true; + break; + case LIGHT_FLASH2_NIGHT: + if(CClock::GetHours() > 18 || CClock::GetHours() < 7) + if((CTimer::GetTimeInMilliseconds() + flashTimer2) & 0x400) + lightOn = true; + break; + case LIGHT_FLASH3: + if((CTimer::GetTimeInMilliseconds() + flashTimer3) & 0x800) + lightOn = true; + break; + case LIGHT_FLASH3_NIGHT: + if(CClock::GetHours() > 18 || CClock::GetHours() < 7) + if((CTimer::GetTimeInMilliseconds() + flashTimer3) & 0x800) + lightOn = true; + break; + case LIGHT_RANDOM_FLICKER: + if(m_randomSeed > 16) + lightOn = true; + else{ + if((CTimer::GetTimeInMilliseconds() ^ m_randomSeed*8) & 0x60) + lightOn = true; + else + lightFlickering = true; + if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed*8) & 3) + lightOn = true; + } + break; + case LIGHT_RANDOM_FLICKER_NIGHT: + if(CClock::GetHours() > 18 || CClock::GetHours() < 7){ + if(m_randomSeed > 16) + lightOn = true; + else{ + if((CTimer::GetTimeInMilliseconds() ^ m_randomSeed*8) & 0x60) + lightOn = true; + else + lightFlickering = true; + if((CTimer::GetTimeInMilliseconds()>>11 ^ m_randomSeed*8) & 3) + lightOn = true; + } + } + break; + case LIGHT_BRIDGE_FLASH1: + if(CBridge::ShouldLightsBeFlashing() && CTimer::GetTimeInMilliseconds() & 0x200) + lightOn = true; + break; + case LIGHT_BRIDGE_FLASH2: + if(CBridge::ShouldLightsBeFlashing() && (CTimer::GetTimeInMilliseconds() & 0x1FF) < 60) + lightOn = true; + break; + } + + if(effect->light.flags & LIGHTFLAG_HIDE_OBJECT){ + if(lightOn) + bDoNotRender = false; + else + bDoNotRender = true; + return; + } + + // Corona + if(lightOn) + CCoronas::RegisterCorona((uintptr)this + i, + effect->col.r, effect->col.g, effect->col.b, 255, + pos, effect->light.size, effect->light.dist, + effect->light.corona, effect->light.flareType, effect->light.roadReflection, + effect->light.flags&LIGHTFLAG_LOSCHECK, CCoronas::STREAK_OFF, 0.0f, + !!(effect->light.flags&LIGHTFLAG_LONG_DIST)); + else if(lightFlickering) + CCoronas::RegisterCorona((uintptr)this + i, + 0, 0, 0, 255, + pos, effect->light.size, effect->light.dist, + effect->light.corona, effect->light.flareType, effect->light.roadReflection, + effect->light.flags&LIGHTFLAG_LOSCHECK, CCoronas::STREAK_OFF, 0.0f, + !!(effect->light.flags&LIGHTFLAG_LONG_DIST)); + + // Pointlight + bool alreadyProcessedFog; + alreadyProcessedFog = false; + if(effect->light.range != 0.0f && lightOn){ + if(effect->col.r == 0 && effect->col.g == 0 && effect->col.b == 0){ + CPointLights::AddLight(CPointLights::LIGHT_POINT, + pos, CVector(0.0f, 0.0f, 0.0f), + effect->light.range, + 0.0f, 0.0f, 0.0f, + CPointLights::FOG_NONE, true); + }else{ + CPointLights::AddLight(CPointLights::LIGHT_POINT, + pos, CVector(0.0f, 0.0f, 0.0f), + effect->light.range, + effect->col.r*CTimeCycle::GetSpriteBrightness()/255.0f, + effect->col.g*CTimeCycle::GetSpriteBrightness()/255.0f, + effect->col.b*CTimeCycle::GetSpriteBrightness()/255.0f, + (effect->light.flags & LIGHTFLAG_FOG) >> 1, + true); + alreadyProcessedFog = true; + } + } + + if(!alreadyProcessedFog){ + if(effect->light.flags & LIGHTFLAG_FOG_ALWAYS){ + CPointLights::AddLight(CPointLights::LIGHT_FOGONLY_ALWAYS, + pos, CVector(0.0f, 0.0f, 0.0f), + 0.0f, + effect->col.r/255.0f, effect->col.g/255.0f, effect->col.b/255.0f, + CPointLights::FOG_ALWAYS, true); + }else if(effect->light.flags & LIGHTFLAG_FOG_NORMAL && lightOn && effect->light.range == 0.0f){ + CPointLights::AddLight(CPointLights::LIGHT_FOGONLY, + pos, CVector(0.0f, 0.0f, 0.0f), + 0.0f, + effect->col.r/255.0f, effect->col.g/255.0f, effect->col.b/255.0f, + CPointLights::FOG_NORMAL, true); + } + } + + // Light shadow + if(effect->light.shadowSize != 0.0f){ + if(lightOn){ + CShadows::StoreStaticShadow((uintptr)this + i, SHADOWTYPE_ADDITIVE, + effect->light.shadow, &pos, + effect->light.shadowSize, 0.0f, + 0.0f, -effect->light.shadowSize, + 128, + effect->col.r*CTimeCycle::GetSpriteBrightness()*effect->light.shadowIntensity/255.0f, + effect->col.g*CTimeCycle::GetSpriteBrightness()*effect->light.shadowIntensity/255.0f, + effect->col.b*CTimeCycle::GetSpriteBrightness()*effect->light.shadowIntensity/255.0f, + 15.0f, 1.0f, 40.0f, false, 0.0f); + }else if(lightFlickering){ + CShadows::StoreStaticShadow((uintptr)this + i, SHADOWTYPE_ADDITIVE, + effect->light.shadow, &pos, + effect->light.shadowSize, 0.0f, + 0.0f, -effect->light.shadowSize, + 0, 0.0f, 0.0f, 0.0f, + 15.0f, 1.0f, 40.0f, false, 0.0f); + } + } + break; + + case EFFECT_SUNGLARE: + if(CWeather::SunGlare >= 0.0f){ + CVector pos = GetMatrix() * effect->pos; + CVector glareDir = pos - GetPosition(); + glareDir.Normalise(); + CVector camDir = TheCamera.GetPosition() - pos; + float dist = camDir.Magnitude(); + camDir *= 2.0f/dist; + glareDir += camDir; + glareDir.Normalise(); + float camAngle = -DotProduct(glareDir, CTimeCycle::GetSunDirection()); + if(camAngle > 0.0f){ + float intens = Sqrt(camAngle) * CWeather::SunGlare; + pos += camDir; + CCoronas::RegisterCorona((uintptr)this + 33 + i, + intens * (CTimeCycle::GetSunCoreRed() + 2*255)/3.0f, + intens * (CTimeCycle::GetSunCoreGreen() + 2*255)/3.0f, + intens * (CTimeCycle::GetSunCoreBlue() + 2*255)/3.0f, + 255, + pos, 0.5f*CWeather::SunGlare*Sqrt(dist), 120.0f, + CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, + CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, + CCoronas::STREAK_OFF, 0.0f); + } + } + break; + } + } +} \ No newline at end of file diff --git a/src/renderer/Coronas.h b/src/renderer/Coronas.h new file mode 100644 index 00000000..45f027d8 --- /dev/null +++ b/src/renderer/Coronas.h @@ -0,0 +1,105 @@ +#pragma once + +extern RwTexture *gpCoronaTexture[9]; + +struct CRegisteredCorona +{ + CVector coors; + uint32 id; + uint32 lastLOScheck; + RwTexture *texture; + float size; + float someAngle; + float drawDist; + float nearDist; + float heightAboveRoad; + uint8 red; + uint8 green; + uint8 blue; + uint8 alpha; // alpha when fully visible + uint8 fadeAlpha; // actual value used for rendering, faded + bool registeredThisFrame; + int8 flareType; + int8 reflection; + + uint8 LOScheck : 1; + uint8 offScreen : 1; + uint8 firstUpdate : 1; + uint8 drawStreak : 1; + uint8 sightClear : 1; + uint8 useNearDist : 1; + uint8 renderReflection : 1; + + int16 prevX[6]; + int16 prevY[6]; + uint8 prevRed[6]; + uint8 prevGreen[6]; + uint8 prevBlue[6]; + bool hasValue[6]; + + void Update(void); +}; + +VALIDATE_SIZE(CRegisteredCorona, 0x68); + +class CCoronas +{ + static CRegisteredCorona aCoronas[NUMCORONAS]; +public: + enum { + SUN_CORE = 1, + SUN_CORONA + }; + enum { + TYPE_STAR, + TYPE_NORMAL, + TYPE_MOON, + TYPE_REFLECT, + TYPE_HEADLIGHT, + TYPE_HEX, + TYPE_CIRCLE, + TYPE_RING, + TYPE_STREAK, + }; + enum { + FLARE_NONE, + FLARE_SUN, + FLARE_HEADLIGHTS + }; + enum { + REFLECTION_OFF, + REFLECTION_ON, + }; + enum { + LOSCHECK_OFF, + LOSCHECK_ON, + }; + enum { + STREAK_OFF, + STREAK_ON, + }; + + static float LightsMult; + static float SunScreenY; + static float SunScreenX; + static int MoonSize; + static bool SunBlockedByClouds; + static int bChangeBrightnessImmediately; + + static void Init(void); + static void Shutdown(void); + static void Update(void); + static void RegisterCorona(uint32 id, uint8 red, uint8 green, uint8 blue, uint8 alpha, + const CVector &coors, float size, float drawDist, RwTexture *tex, + int8 flareType, uint8 reflection, uint8 LOScheck, uint8 drawStreak, float someAngle, + bool useNearDist = false, float nearDist = 1.5f); + static void RegisterCorona(uint32 id, uint8 red, uint8 green, uint8 blue, uint8 alpha, + const CVector &coors, float size, float drawDist, uint8 type, + int8 flareType, uint8 reflection, uint8 LOScheck, uint8 drawStreak, float someAngle, + bool useNearDist = false, float nearDist = 1.5f); + static void UpdateCoronaCoors(uint32 id, const CVector &coors, float drawDist, float someAngle); + static void Render(void); + static void RenderReflections(void); + static void RenderSunReflection(void); + static void DoSunAndMoon(void); +}; diff --git a/src/renderer/Credits.cpp b/src/renderer/Credits.cpp new file mode 100644 index 00000000..81e76625 --- /dev/null +++ b/src/renderer/Credits.cpp @@ -0,0 +1,820 @@ +#include "common.h" + +#include "Timer.h" +#include "Font.h" +#include "Frontend.h" +#include "RwHelper.h" +#include "Camera.h" +#include "Text.h" +#include "Credits.h" +#include "Pad.h" + +bool CCredits::bCreditsGoing; +uint32 CCredits::CreditsStartTime; + +void +CCredits::Init(void) +{ + Stop(); +} + +void +CCredits::Start(void) +{ + bCreditsGoing = true; + CreditsStartTime = CTimer::GetTimeInMilliseconds(); +} + +void +CCredits::Stop(void) +{ + bCreditsGoing = false; +} + +void +CCredits::PrintCreditSpace(float space, uint32 &line) +{ + line += space * 25.0f; +} + +void +CCredits::PrintCreditText(float scaleX, float scaleY, wchar *text, uint32 &lineoffset, float scrolloffset) +{ + CPad::UpdatePads(); + if (CPad::GetPad(0)->GetCrossJustDown()) + bCreditsGoing = false; + else { + float start = DEFAULT_SCREEN_HEIGHT + 20.0f; + float y = lineoffset + start - scrolloffset; + if (y > 20.0f && DEFAULT_SCREEN_HEIGHT - 20.0f > y) { + CFont::SetScale(SCREEN_SCALE_X(scaleX), SCREEN_SCALE_Y(scaleY)); + CFont::SetColor(CRGBA(0, 0, 0, 255)); + CFont::PrintString(SCREEN_WIDTH / 2.0f, SCREEN_SCALE_Y(y), (uint16*)text); + CFont::SetColor(CRGBA(220, 220, 220, 220)); + CFont::PrintString(SCREEN_WIDTH / 2.0f - SCREEN_SCALE_X(1.0f), SCREEN_SCALE_Y(y - 1.0f), (uint16*)text); + } + lineoffset += scaleY*25.0f; + } +} + +void +CCredits::Render(void) +{ + uint32 lineoffset; + float scrolloffset; + + if(!bCreditsGoing || FrontEndMenuManager.m_bMenuActive) + return; + + DefinedState(); + lineoffset = 0; + scrolloffset = (CTimer::GetTimeInMilliseconds() - CreditsStartTime) / 24.0f; + CFont::SetJustifyOff(); + CFont::SetBackgroundOff(); + CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.75f)); + CFont::SetCentreOn(); + CFont::SetPropOn(); + CFont::SetFontStyle(FONT_STANDARD); + + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED001"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED002"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED003"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED004"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED005"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED006"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED007"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED008"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED025"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED026"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED027"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED028"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED029"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED030"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED031"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD031A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD031B"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD031C"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD031D"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD031E"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD024A"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED024"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED023"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD023A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD023B"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED018"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED019"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD018A"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD019A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD019B"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED020"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED021"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD022A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED022"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD022B"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD022C"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED032"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED033"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD032A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED034"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED035"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED036"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED037"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD037A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD037B"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD037C"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD041B"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED042"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED039"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED044"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED040"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD042A"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED142"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD142A"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED009"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED010"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED011"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED012"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED013"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD013A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD013B"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD013C"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED089"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED090"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED347"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED047"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED048"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED049"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED348"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED050"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED051"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED052"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED053"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED054"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED055"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED056"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD056A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD056B"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD056C"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD056D"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED349"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED350"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED351"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED352"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED353"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED354"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED355"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED356"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED357"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED359"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED360"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED361"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED362"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED363"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED364"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED365"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED366"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED367"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED368"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED369"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED370"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED371"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED372"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED373"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED256"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED257"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED258"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED057"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED058"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD057A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED059"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD060A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD060B"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD060C"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD002A"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED003"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD001A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD001B"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED060"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED061"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED062"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED063"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED064"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED069"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED070"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED065"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED066"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED067"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED068"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD071A"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD072A"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED091"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED094"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED095"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED097"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED098"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD098A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD098B"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD098C"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED099"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED096"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED273"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD092A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED092"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD092B"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED073"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED074"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED076"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED075"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED077"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED078"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED081"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED082"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED079"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED080"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED083"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED084"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD084A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD084B"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD084C"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD084D"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD084E"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED085"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED086"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD086A"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED087"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED088"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088A"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088B"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088C"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088D"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088E"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088F"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD088G"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED107"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED108"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED109"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED110"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD110A"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED111"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED112"), lineoffset, scrolloffset); + + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED113"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED114"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED115"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED116"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED117"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED118"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED119"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED120"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED121"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED122"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED123"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED124"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED125"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED126"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED127"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED128"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED129"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + + CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.8f)); + + PrintCreditText(1.1f, 0.8f, TheText.Get("CRD111A"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED130"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED131"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED132"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED133"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED134"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134A"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134B"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134C"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134D"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134E"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134F"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134G"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134H"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD134I"), lineoffset, scrolloffset); + + CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.7f)); + + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED135"), lineoffset, scrolloffset); + + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD136A"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD137A"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED138"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED066"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD138B"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED139"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(1.1f, 0.8f, TheText.Get("CRED140"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_FRENCH) + PrintCreditSpace(0.5f, lineoffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140A"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140B"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140C"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140D"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140E"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140F"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140G"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140H"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140I"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140J"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140K"), lineoffset, scrolloffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD140L"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + + CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.85f)); + + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED259"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED260"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED261"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED262"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED263"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED264"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED265"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED266"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED141"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD141A"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD141B"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED143"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED144"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED145"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED146"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED147"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED148"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED149"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED150"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED151"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED152"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED153"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED154"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED155"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED156"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED157"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED158"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED159"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED160"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED161"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED162"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED163"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED164"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED165"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED166"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED167"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED168"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED169"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED170"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED171"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED172"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + + CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.75f)); + + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED217"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED218"), lineoffset, scrolloffset); + PrintCreditSpace(1.0f, lineoffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRD218A"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED219"), lineoffset, scrolloffset); + PrintCreditSpace(1.0f, lineoffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED220"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED221"), lineoffset, scrolloffset); + PrintCreditSpace(1.0f, lineoffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED222"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED223"), lineoffset, scrolloffset); + PrintCreditSpace(1.0f, lineoffset); + PrintCreditText(1.1f, 1.1f, TheText.Get("CRED224"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED227"), lineoffset, scrolloffset); + PrintCreditSpace(1.0f, lineoffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED228"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED229"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD229A"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD229B"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED274"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED275"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED276"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED277"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED278"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED279"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED280"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED281"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED282"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED283"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED284"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED285"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED286"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED287"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED288"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED289"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED290"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED291"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED292"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED293"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED294"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED295"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED296"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED297"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED298"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED299"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED300"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED301"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED302"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED303"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED304"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED305"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED306"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED307"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED308"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED309"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED310"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED314"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED315"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED316"), lineoffset, scrolloffset); + PrintCreditSpace(1.0f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED317"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED318"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED319"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED320"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED321"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED322"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED323"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED324"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED325"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED326"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED327"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED328"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED329"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED330"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED331"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED332"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + + CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.8f)); + + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED333"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED334"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED335"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED336"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED337"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED338"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED339"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED340"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED341"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED342"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditSpace(1.0f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD344A"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED344"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED345"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRD345A"), lineoffset, scrolloffset); + PrintCreditSpace(1.0f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED346"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(1.0f, lineoffset); + + PrintCreditSpace(1.5f, lineoffset); + + CFont::SetCentreSize(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH * 0.75f)); + + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED267"), lineoffset, scrolloffset); + PrintCreditSpace(0.5f, lineoffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED268"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED269"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED270"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED271"), lineoffset, scrolloffset); + PrintCreditText(0.65f, 0.65f, TheText.Get("CRED272"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditText(0.95f, 0.7f, TheText.Get("CRED230"), lineoffset, scrolloffset); + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_ITALIAN) + PrintCreditSpace(0.5f, lineoffset); + + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED231"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED232"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED233"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED234"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED235"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED236"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED237"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED238"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED239"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED240"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED241"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED242"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED243"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED244"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED245"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED246"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED247"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED248"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED249"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED358"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED250"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED251"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED252"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRD251A"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRD252A"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED253"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED254"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED374"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED375"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED376"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED377"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED378"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED379"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED380"), lineoffset, scrolloffset); + PrintCreditText(0.95f, 0.95f, TheText.Get("CRED381"), lineoffset, scrolloffset); + PrintCreditSpace(1.5f, lineoffset); + PrintCreditSpace(1.5f, lineoffset); + CFont::DrawFonts(); +#ifdef CUTSCENE_BORDERS_SWITCH + if (CMenuManager::m_PrefsCutsceneBorders) +#endif + if(TheCamera.m_WideScreenOn) + TheCamera.DrawBordersForWideScreen(); + +#ifdef FIX_BUGS + if(lineoffset + DEFAULT_SCREEN_HEIGHT - scrolloffset < -10.0f) +#else + if(lineoffset + SCREEN_HEIGHT - scrolloffset < -10.0f) +#endif + { + bCreditsGoing = false; + } +} + +bool CCredits::AreCreditsDone(void) +{ + return !bCreditsGoing; +} diff --git a/src/renderer/Credits.h b/src/renderer/Credits.h new file mode 100644 index 00000000..e049ce76 --- /dev/null +++ b/src/renderer/Credits.h @@ -0,0 +1,15 @@ +#pragma once + +class CCredits +{ + static bool bCreditsGoing; + static uint32 CreditsStartTime; +public: + static void Init(void); + static void Start(void); + static void Stop(void); + static bool AreCreditsDone(void); + static void Render(void); + static void PrintCreditSpace(float space, uint32 &line); + static void PrintCreditText(float scaleX, float scaleY, wchar *text, uint32 &lineoffset, float scrolloffset); +}; diff --git a/src/renderer/CutsceneShadow.cpp b/src/renderer/CutsceneShadow.cpp new file mode 100644 index 00000000..8cb33896 --- /dev/null +++ b/src/renderer/CutsceneShadow.cpp @@ -0,0 +1,269 @@ +#include "common.h" +#include "main.h" +#include "rwcore.h" +#include "rwplcore.h" +#include "CutsceneShadow.h" +#include "RwHelper.h" + +#define DLIGHT_VALUE 0.8f /* Directional light intensity */ + + +CCutsceneShadow::CCutsceneShadow() +{ + m_pAtomic = nil; + m_nRwObjectType = -1; + m_pLight = nil; + m_nBlurPasses = 0; + m_bResample = false; + m_bGradient = false; +} + +CCutsceneShadow::~CCutsceneShadow() +{ + Destroy(); +} + +bool +CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32 blurPasses, bool gradient) +{ + ASSERT(object != nil); + + RwRGBAReal color; + RwFrame *frame; + + if (!object) + return false; + + m_pLight = RpLightCreate(rpLIGHTDIRECTIONAL); + ASSERT(m_pLight != nil); + + if (!m_pLight) + return false; + + color.red = color.green = color.blue = DLIGHT_VALUE; + color.alpha = 0.0f; + + RpLightSetColor(m_pLight, &color); + + frame = RwFrameCreate(); + ASSERT(frame != nil); + + RpLightSetFrame(m_pLight, frame); + + SetLightProperties(180.0f, 90.0f, false); + + m_pObject = object; + m_nRwObjectType = RwObjectGetType(m_pObject); + + switch ( m_nRwObjectType ) + { + case rpCLUMP: + { + RpClumpGetBoundingSphere(m_pClump, &m_BoundingSphere, 1); + m_BaseSphere.radius = m_BoundingSphere.radius; + RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpClumpGetFrame(m_pClump))); + break; + } + + case rpATOMIC: + { + m_BoundingSphere = *RpAtomicGetBoundingSphere(m_pAtomic); + m_BaseSphere.radius = m_BoundingSphere.radius; + RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpAtomicGetFrame(m_pAtomic))); + break; + } + + default: + { + Destroy(); + return false; + break; + } + } + + if ( !m_Camera.Create(rasterSize) ) + { + Destroy(); + return false; + } + + m_nBlurPasses = blurPasses; + m_bResample = resample; + m_bGradient = gradient; + + if ( m_bResample && !m_ResampleCamera.Create(rasterSize - 1) ) + { + Destroy(); + return false; + } + + if ( m_nBlurPasses != 0 ) + { + if ( !m_BlurCamera.Create(resample ? rasterSize - 1 : rasterSize) ) + { + Destroy(); + return false; + } + } + + if ( m_bGradient ) + { + if ( !m_GradientCamera.Create(resample ? rasterSize - 1 : rasterSize) ) + { + Destroy(); + return false; + } + + m_GradientCamera.MakeGradientRaster(); + } + + m_Camera.SetLight(m_pLight); + + switch ( m_nRwObjectType ) + { + case rpATOMIC: + m_Camera.SetFrustum(1.1f * m_BoundingSphere.radius); + break; + + case rpCLUMP: + m_Camera.SetFrustum(1.1f * m_BoundingSphere.radius); + break; + } + + m_Camera.SetCenter(&m_BaseSphere.center); + return true; +} + +RwFrame * +CCutsceneShadow::SetLightProperties(float angleY, float angleX, bool setLight) +{ + ASSERT(m_pLight != nil); + + RwFrame *frame; + static RwV3d Xaxis = { 1.0f, 0.0f, 0.0f }; + static RwV3d Yaxis = { 0.0f, 1.0f, 0.0f }; + + frame = RpLightGetFrame(m_pLight); + ASSERT(frame != nil); + + if ( !frame ) + return nil; + + RwFrameRotate(frame, &Yaxis, angleY, rwCOMBINEREPLACE); + RwFrameRotate(frame, &Xaxis, angleX, rwCOMBINEPOSTCONCAT); + + if ( setLight ) + m_Camera.SetLight(m_pLight); + + return frame; +} + +bool +CCutsceneShadow::IsInitialized() +{ + return m_pObject != nil; +} + +void +CCutsceneShadow::Destroy() +{ + m_Camera.Destroy(); + m_ResampleCamera.Destroy(); + m_BlurCamera.Destroy(); + m_GradientCamera.Destroy(); + + m_pAtomic = nil; + + m_nRwObjectType = -1; + + if (m_pLight) + { + RwFrame *frame = RpLightGetFrame(m_pLight); + RpLightSetFrame(m_pLight, nil); + RwFrameDestroy(frame); + RpLightDestroy(m_pLight); + m_pLight = nil; + } +} + +RwRaster * +CCutsceneShadow::Update() +{ + switch ( m_nRwObjectType ) + { + case rpCLUMP: + ASSERT(m_pClump != nil); + RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpClumpGetFrame(m_pClump))); + break; + + case rpATOMIC: + ASSERT(m_pAtomic != nil); + RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpAtomicGetFrame(m_pAtomic))); + break; + } + + m_Camera.SetCenter(&m_BaseSphere.center); + + switch ( m_nRwObjectType ) + { + case rpCLUMP: + m_Camera.Update(m_pClump); + break; + + case rpATOMIC: + m_Camera.Update(m_pAtomic); + break; + } + + RwRaster *raster = m_Camera.GetRwRenderRaster(); + ASSERT(raster != nil); + + if ( m_bResample ) + return m_ResampleCamera.RasterResample(raster); + + if ( m_nBlurPasses ) + return m_BlurCamera.RasterBlur(raster, m_nBlurPasses); + + if ( m_bGradient ) + return m_GradientCamera.RasterGradient(raster); + + return raster; +} + +RwTexture * +CCutsceneShadow::UpdateForCutscene() +{ + Update(); + return GetShadowRwTexture(); +} + +CShadowCamera * +CCutsceneShadow::GetShadowCamera(int32 camType) +{ + switch ( camType ) + { + case RESAMPLE: return &m_ResampleCamera; + case BLUR: return &m_BlurCamera; + case GRADIENT: return &m_GradientCamera; + } + + return &m_Camera; +} + +RwTexture * +CCutsceneShadow::GetShadowRwTexture() +{ + if ( m_bResample ) + return m_ResampleCamera.GetRwRenderTexture(); + else + return m_Camera.GetRwRenderTexture(); +} + +void +CCutsceneShadow::DrawBorderAroundTexture(RwRGBA const& color) +{ + if ( m_bResample ) + m_ResampleCamera.DrawOutlineBorder(color); + else + m_Camera.DrawOutlineBorder(color); +} \ No newline at end of file diff --git a/src/renderer/CutsceneShadow.h b/src/renderer/CutsceneShadow.h new file mode 100644 index 00000000..a59fe78f --- /dev/null +++ b/src/renderer/CutsceneShadow.h @@ -0,0 +1,52 @@ +#pragma once +#include "ShadowCamera.h" + +class CCutsceneShadow +{ +public: + enum + { + RASTER = 0, + RESAMPLE, + BLUR, + GRADIENT, + }; + + CShadowCamera m_Camera; + bool m_bResample; + CShadowCamera m_ResampleCamera; + int32 m_nBlurPasses; + CShadowCamera m_BlurCamera; + bool m_bGradient; + CShadowCamera m_GradientCamera; + + union + { + RwObject *m_pObject; + RpAtomic *m_pAtomic; + RpClump *m_pClump; + }; + + int32 m_nRwObjectType; + RpLight *m_pLight; + RwSphere m_BoundingSphere; + RwSphere m_BaseSphere; + + CCutsceneShadow(); + ~CCutsceneShadow(); + + RwSphere GetBaseSphere() + { + return m_BaseSphere; + } + + bool Create(RwObject *object, int32 rasterSize, bool resample, int32 blurPasses, bool gradient); + RwFrame *SetLightProperties(float angleY, float angleX, bool setLight); + bool IsInitialized(); + void Destroy(); + RwRaster *Update(); + RwTexture *UpdateForCutscene(); + CShadowCamera *GetShadowCamera(int32 camType = RASTER); + RwTexture *GetShadowRwTexture(); + void DrawBorderAroundTexture(RwRGBA const& color); +}; diff --git a/src/renderer/Draw.cpp b/src/renderer/Draw.cpp new file mode 100644 index 00000000..9c5921c3 --- /dev/null +++ b/src/renderer/Draw.cpp @@ -0,0 +1,113 @@ +#include "common.h" + +#include "Draw.h" +#include "Frontend.h" +#include "Camera.h" +#include "CutsceneMgr.h" + +float CDraw::ms_fAspectRatio = DEFAULT_ASPECT_RATIO; +#ifdef ASPECT_RATIO_SCALE +float CDraw::ms_fScaledFOV = 45.0f; +#endif + +float CDraw::ms_fNearClipZ; +float CDraw::ms_fFarClipZ; +float CDraw::ms_fFOV = 45.0f; +float CDraw::ms_fLODDistance; + +uint8 CDraw::FadeValue; +uint8 CDraw::FadeRed; +uint8 CDraw::FadeGreen; +uint8 CDraw::FadeBlue; + +#ifdef PROPER_SCALING +bool CDraw::ms_bProperScaling = true; +#endif +#ifdef FIX_RADAR +bool CDraw::ms_bFixRadar = true; +#endif +#ifdef FIX_SPRITES +bool CDraw::ms_bFixSprites = true; +#endif + +#ifdef ASPECT_RATIO_SCALE +float +FindAspectRatio(void) +{ + switch (FrontEndMenuManager.m_PrefsUseWideScreen) { + case AR_AUTO: + return SCREEN_WIDTH / SCREEN_HEIGHT; + default: + case AR_4_3: + return 4.0f / 3.0f; + case AR_5_4: + return 5.0f / 4.0f; + case AR_16_10: + return 16.0f / 10.0f; + case AR_16_9: + return 16.0f / 9.0f; + case AR_21_9: + return 21.0f / 9.0f; + }; +} +#endif + +float +CDraw::CalculateAspectRatio(void) +{ +#ifdef ASPECT_RATIO_SCALE + if (TheCamera.m_WideScreenOn) + CDraw::ms_fAspectRatio = (5.f / 3.f) * FindAspectRatio() / (16.f / 9.f); // It's used on theatrical showings according to Wiki + else + CDraw::ms_fAspectRatio = FindAspectRatio(); +#else + if(FrontEndMenuManager.m_PrefsUseWideScreen) { + if (TheCamera.m_WideScreenOn) + CDraw::ms_fAspectRatio = 5.f / 3.f; // It's used on theatrical showings according to Wiki + else + CDraw::ms_fAspectRatio = 16.f / 9.f; + } else if (TheCamera.m_WideScreenOn) { + CDraw::ms_fAspectRatio = 5.f/4.f; + } else { + CDraw::ms_fAspectRatio = 4.f/3.f; + } +#endif + return CDraw::ms_fAspectRatio; +} + +#ifdef ASPECT_RATIO_SCALE +// convert a 4:3 hFOV to vFOV, +// then convert that vFOV to hFOV for our aspect ratio, +// i.e. HOR+ +float +CDraw::ConvertFOV(float hfov) +{ + // => tan(hFOV/2) = tan(vFOV/2)*aspectRatio + // => tan(vFOV/2) = tan(hFOV/2)/aspectRatio + float ar1 = DEFAULT_ASPECT_RATIO; + float ar2 = GetAspectRatio(); + hfov = DEGTORAD(hfov); + float vfov = Atan(tan(hfov/2) / ar1) *2; + hfov = Atan(tan(vfov/2) * ar2) *2; + return RADTODEG(hfov); +} +#endif + +void +CDraw::SetFOV(float fov) +{ +#ifdef ASPECT_RATIO_SCALE + if (!CCutsceneMgr::IsRunning()) + ms_fScaledFOV = ConvertFOV(fov); + else + ms_fScaledFOV = fov; +#endif + ms_fFOV = fov; +} + +#ifdef PROPER_SCALING +float CDraw::ScaleY(float y) +{ + return ms_bProperScaling ? y : y * ((float)DEFAULT_SCREEN_HEIGHT/SCREEN_HEIGHT_NTSC); +} +#endif \ No newline at end of file diff --git a/src/renderer/Draw.h b/src/renderer/Draw.h new file mode 100644 index 00000000..b96fa813 --- /dev/null +++ b/src/renderer/Draw.h @@ -0,0 +1,70 @@ +#pragma once + +enum eAspectRatio +{ + // Make sure these work the same as FrontEndMenuManager.m_PrefsUseWideScreen + // without widescreen support + AR_AUTO, + AR_4_3, + AR_5_4, + AR_16_10, + AR_16_9, + AR_21_9, + + AR_MAX, +}; + +class CDraw +{ +private: + static float ms_fNearClipZ; + static float ms_fFarClipZ; + static float ms_fFOV; + // we use this variable to scale a lot of 2D elements + // so better cache it + static float ms_fAspectRatio; +#ifdef ASPECT_RATIO_SCALE + // similar thing for 3D rendering + static float ms_fScaledFOV; +#endif +public: + static float ms_fLODDistance; // set but unused? + + static uint8 FadeValue; + static uint8 FadeRed; + static uint8 FadeGreen; + static uint8 FadeBlue; + +#ifdef PROPER_SCALING + static bool ms_bProperScaling; +#endif +#ifdef FIX_RADAR + static bool ms_bFixRadar; +#endif +#ifdef FIX_SPRITES + static bool ms_bFixSprites; +#endif + + static void SetNearClipZ(float nearclip) { ms_fNearClipZ = nearclip; } + static float GetNearClipZ(void) { return ms_fNearClipZ; } + static void SetFarClipZ(float farclip) { ms_fFarClipZ = farclip; } + static float GetFarClipZ(void) { return ms_fFarClipZ; } + + static void SetFOV(float fov); + static float GetFOV(void) { return ms_fFOV; } +#ifdef ASPECT_RATIO_SCALE + static float GetScaledFOV(void) { return ms_fScaledFOV; } +#else + static float GetScaledFOV(void) { return ms_fFOV; } +#endif + + static float CalculateAspectRatio(void); +#ifdef ASPECT_RATIO_SCALE + static float ConvertFOV(float fov); +#endif + static float GetAspectRatio(void) { return ms_fAspectRatio; } + static void SetAspectRatio(float ratio) { ms_fAspectRatio = ratio; } +#ifdef PROPER_SCALING + static float ScaleY(float y); +#endif +}; diff --git a/src/renderer/Fluff.cpp b/src/renderer/Fluff.cpp new file mode 100644 index 00000000..1e4d289b --- /dev/null +++ b/src/renderer/Fluff.cpp @@ -0,0 +1,1364 @@ +#include "common.h" +#include "main.h" + +#include "RenderBuffer.h" +#include "Entity.h" +#include "Fluff.h" +#include "Camera.h" +#include "Sprite.h" +#include "Coronas.h" +#include "PointLights.h" +#include "Rubbish.h" +#include "Timecycle.h" +#include "General.h" +#include "Timer.h" +#include "Clock.h" +#include "Weather.h" +#include "Stats.h" +#include "maths.h" +#include "Frontend.h" +#include "CutsceneMgr.h" +#include "PlayerPed.h" +#include "Bones.h" +#include "World.h" +#include "Replay.h" +#include "Coronas.h" +#include "SaveBuf.h" + +#ifdef COMPATIBLE_SAVES +#define SCRIPTPATHS_SAVE_SIZE 0x9C +#else +#define SCRIPTPATHS_SAVE_SIZE sizeof(aArray) +#endif + +CPlaneTrail CPlaneTrails::aArray[6]; +RwImVertexIndex TrailIndices[32] = { + 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, + 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16 +}; + +void +CPlaneTrail::Init(void) +{ + int i; + for(i = 0; i < ARRAY_SIZE(m_time); i++) + m_time[i] = 0; +} + +void +CPlaneTrail::Render(float visibility) +{ + int i; + int numVerts = 0; + if(!TheCamera.IsSphereVisible(m_pos[0], 1000.0f)) + return; + + int alpha = visibility*110.0f; + if(alpha == 0) + return; + + for(i = 0; i < ARRAY_SIZE(m_pos); i++){ + int32 time = CTimer::GetTimeInMilliseconds() - m_time[i]; + if(time > 30000) + m_time[i] = 0; + if(m_time[i] != 0){ + float fade = (30000.0f - time) / 10000.0f; + fade = Min(fade, 1.0f); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[numVerts], 255, 255, 255, (int)(alpha*fade)); + RwIm3DVertexSetPos(&TempBufferRenderVertices[numVerts], m_pos[i].x, m_pos[i].y, m_pos[i].z); + numVerts++; + } + } + if(numVerts > 1){ + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + + if(RwIm3DTransform(TempBufferRenderVertices, numVerts, nil, rwIM3D_VERTEXXYZ|rwIM3D_VERTEXRGBA)){ + RwIm3DRenderIndexedPrimitive(rwPRIMTYPELINELIST, TrailIndices, (numVerts-1)*2); + RwIm3DEnd(); + } + } +} + +void +CPlaneTrail::RegisterPoint(CVector pos) +{ + int i; + bool bNewPoint = false; + if(m_time[0] != 0 && CTimer::GetTimeInMilliseconds() - m_time[0] > 2000){ + bNewPoint = true; + for(i = ARRAY_SIZE(m_pos)-1; i > 0; i--){ + m_pos[i] = m_pos[i-1]; + m_time[i] = m_time[i-1]; + } + } + m_pos[0] = pos; + if(bNewPoint || m_time[0] == 0) + m_time[0] = CTimer::GetTimeInMilliseconds(); +} + +void +CPlaneTrails::Init(void) +{ + int i; + for(i = 0; i < ARRAY_SIZE(aArray); i++) + aArray[i].Init(); +} + +void +CPlaneTrails::Update(void) +{ + CVector planePos; + + planePos.x = 1590.0f * Sin((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); + planePos.y = 1200.0f * Cos((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); + planePos.z = 550.0f; + RegisterPoint(planePos, 3); + if(CClock::GetHours() > 22 || CClock::GetHours() < 7){ + if(CTimer::GetTimeInMilliseconds() & 0x200) + CCoronas::RegisterCorona(101, 255, 0, 0, 255, planePos, 5.0f, 2000.0f, + CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); + else + CCoronas::UpdateCoronaCoors(101, planePos, 2000.0f, 0.0f); + } + + planePos.x = 1000.0f * Sin((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); + planePos.y = -1600.0f * Cos((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); + planePos.z = 500.0f; + RegisterPoint(planePos, 4); + if(CClock::GetHours() > 22 || CClock::GetHours() < 7){ + if(CTimer::GetTimeInMilliseconds() & 0x200) + CCoronas::RegisterCorona(102, 255, 0, 0, 255, planePos, 5.0f, 2000.0f, + CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); + else + CCoronas::UpdateCoronaCoors(102, planePos, 2000.0f, 0.0f); + } + + planePos.x = 1100.0f * Cos((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); + planePos.y = 700.0f * Sin((float)(CTimer::GetTimeInMilliseconds() & 0x1FFFF)/0x20000 * TWOPI); + planePos.z = 600.0f; + RegisterPoint(planePos, 5); + if(CClock::GetHours() > 22 || CClock::GetHours() < 7){ + if(CTimer::GetTimeInMilliseconds() & 0x200) + CCoronas::RegisterCorona(103, 255, 0, 0, 255, planePos, 5.0f, 2000.0f, + CCoronas::TYPE_NORMAL, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, + CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); + else + CCoronas::UpdateCoronaCoors(103, planePos, 2000.0f, 0.0f); + } +} + +void +CPlaneTrails::Render(void) +{ + int i; + float visibility = Min(1.0f-CWeather::Foggyness, 1.0f-CWeather::CloudCoverage); + visibility = Min(visibility, 1.0f-CWeather::Rain); + visibility = Min(Max(Max(CTimeCycle::GetSkyTopRed(), CTimeCycle::GetSkyTopGreen()), CTimeCycle::GetSkyTopBlue())/256.0f, visibility); + if(visibility > 0.0001f) + for(i = 0; i < ARRAY_SIZE(aArray); i++) + aArray[i].Render(visibility); +} + +void +CPlaneTrails::RegisterPoint(CVector pos, uint32 id) +{ + aArray[id].RegisterPoint(pos); +} + + + +CPlaneBanner CPlaneBanners::aArray[5]; + +void +CPlaneBanner::Init(void) +{ + int i; + for(i = 0; i < ARRAY_SIZE(m_pos); i++){ + m_pos[i].x = i; + m_pos[i].y = 0.0f; + m_pos[i].z = -60.0f; + } +} + +void +CPlaneBanner::Update(void) +{ + int i; + if(m_pos[0].z > -50.0f){ + m_pos[0].z -= 0.05f*CTimer::GetTimeStep(); + m_pos[0].z = Max(m_pos[0].z, -100.0f); + for(i = 1; i < ARRAY_SIZE(m_pos); i++){ + CVector dist = m_pos[i] - m_pos[i-1]; + float len = dist.Magnitude(); + if(len > 8.0f) + m_pos[i] = m_pos[i-1] + dist/len*8.0f; + } + } +} + +void +CPlaneBanner::Render(void) +{ + int i; + if(m_pos[0].z > -50.0f){ + float camDist = (TheCamera.GetPosition() - m_pos[0]).Magnitude(); + if(TheCamera.IsSphereVisible(m_pos[4], 32.0f) && camDist < 300.0f){ + TempBufferVerticesStored = 0; + TempBufferIndicesStored = 0; + int alpha = camDist < 250.0f ? 160 : (300.0f-camDist)/(300.0f-250.0f)*160; + + TempBufferVerticesStored += 2; + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[0], 255, 255, 255, alpha); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[1], 255, 255, 255, alpha); + RwIm3DVertexSetPos(&TempBufferRenderVertices[0], m_pos[2].x, m_pos[2].y, m_pos[2].z); + RwIm3DVertexSetPos(&TempBufferRenderVertices[1], m_pos[2].x, m_pos[2].y, m_pos[2].z - 4.0f); + RwIm3DVertexSetU(&TempBufferRenderVertices[0], 0.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[0], 0.0f); + RwIm3DVertexSetU(&TempBufferRenderVertices[1], 0.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[1], 1.0f); + for(i = 2; i < 8; i++){ + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+0], 255, 255, 255, alpha); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+1], 255, 255, 255, alpha); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+0], m_pos[i].x, m_pos[i].y, m_pos[i].z); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+1], m_pos[i].x, m_pos[i].y, m_pos[i].z - 4.0f); + RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored+0], (i-2)/5.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored+0], 0.0f); + RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored+1], (i-2)/5.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored+1], 1.0f); + TempBufferRenderIndexList[TempBufferIndicesStored+0] = TempBufferVerticesStored-2; + TempBufferRenderIndexList[TempBufferIndicesStored+1] = TempBufferVerticesStored-1; + TempBufferRenderIndexList[TempBufferIndicesStored+2] = TempBufferVerticesStored+1; + TempBufferRenderIndexList[TempBufferIndicesStored+3] = TempBufferVerticesStored-2; + TempBufferRenderIndexList[TempBufferIndicesStored+4] = TempBufferVerticesStored+1; + TempBufferRenderIndexList[TempBufferIndicesStored+5] = TempBufferVerticesStored; + TempBufferVerticesStored += 2; + TempBufferIndicesStored += 6; + } + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpRubbishTexture[2])); + +#ifdef FIX_BUGS + if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXXYZ|rwIM3D_VERTEXUV|rwIM3D_VERTEXRGBA)){ +#else + if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, 0)){ +#endif + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); + RwIm3DEnd(); + } + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + + TempBufferVerticesStored = 0; + TempBufferIndicesStored = 0; + } + } +} + +void +CPlaneBanner::RegisterPoint(CVector pos) +{ + m_pos[0] = pos; +} + +void +CPlaneBanners::Init(void) +{ + int i; + for(i = 0; i < ARRAY_SIZE(aArray); i++) + aArray[i].Init(); +} + +void +CPlaneBanners::Update(void) +{ + int i; + for(i = 0; i < ARRAY_SIZE(aArray); i++) + aArray[i].Update(); +} + +void +CPlaneBanners::Render(void) +{ + int i; + for(i = 0; i < ARRAY_SIZE(aArray); i++) + aArray[i].Render(); +} + +void +CPlaneBanners::RegisterPoint(CVector pos, uint32 id) +{ + aArray[id].RegisterPoint(pos); +} + +bool CSmokeTrails::CigOn = false; +CSmokeTrail CSmokeTrails::aSmoke[3]; + +RwImVertexIndex SmokeTrailIndices[32] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, +9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16 }; + +float RandomSmoke[16] = { 10.0f, 5.0f, -1.0f, -9.0f, -7.0f, -1.0f, 0.0f, 3.0f, 6.0f, 7.0f, 4.0f, 2.0f, +5.0f, 7.0f }; + +uint8 ScrollCharSet[59][5] = { + { 0x00, 0x00, 0x00, 0x00, 0x00 }, // ' ' + { 0x00, 0x00, 0x1D, 0x00, 0x00 }, // '!' + { 0x00, 0x00, 0x00, 0x00, 0x00 }, // '"' + { 0x0A, 0x1F, 0x0A, 0x1F, 0x0A }, // '#' + { 0x00, 0x09, 0x1F, 0x12, 0x00 }, // '$' + { 0x18, 0x18, 0x00, 0x03, 0x03 }, // '%' + { 0x00, 0x00, 0x00, 0x00, 0x00 }, // '&' + { 0x00, 0x00, 0x00, 0x00, 0x00 }, // ''' + { 0x01, 0x02, 0x04, 0x08, 0x10 }, // '(' + { 0x00, 0x00, 0x18, 0x00, 0x00 }, // ')' + { 0x15, 0x04, 0x1F, 0x04, 0x15 }, // '*' + { 0x00, 0x04, 0x0E, 0x04, 0x00 }, // '+' + { 0x00, 0x00, 0x03, 0x00, 0x00 }, // ',' + { 0x00, 0x04, 0x04, 0x04, 0x00 }, // '-' + { 0x00, 0x00, 0x01, 0x00, 0x00 }, // '.' + { 0x00, 0x00, 0x00, 0x00, 0x00 }, // '/' + { 0x0E, 0x11, 0x11, 0x11, 0x0E }, // '0' + { 0x01, 0x09, 0x1F, 0x01, 0x01 }, // '1' + { 0x03, 0x15, 0x15, 0x15, 0x09 }, // '2' + { 0x11, 0x11, 0x15, 0x15, 0x0A }, // '3' + { 0x02, 0x06, 0x0A, 0x1F, 0x02 }, // '4' + { 0x1D, 0x15, 0x15, 0x15, 0x12 }, // '5' + { 0x0E, 0x15, 0x15, 0x15, 0x12 }, // '6' + { 0x18, 0x10, 0x13, 0x14, 0x18 }, // '7' + { 0x0A, 0x15, 0x15, 0x15, 0x0A }, // '8' + { 0x08, 0x15, 0x15, 0x15, 0x0E }, // '9' + { 0x00, 0x00, 0x0A, 0x00, 0x00 }, // ':' + { 0x18, 0x18, 0x00, 0x03, 0x03 }, // ';' + { 0x04, 0x08, 0x1F, 0x08, 0x04 }, // '<' + { 0x00, 0x0A, 0x0A, 0x0A, 0x00 }, // '=' + { 0x04, 0x02, 0x1F, 0x02, 0x04 }, // '>' + { 0x10, 0x10, 0x15, 0x14, 0x1D }, // '?' + { 0x00, 0x1C, 0x14, 0x1C, 0x00 }, // '@' + { 0x0F, 0x12, 0x12, 0x12, 0x0F }, // 'A' + { 0x1F, 0x15, 0x15, 0x15, 0x0A }, // 'B' + { 0x0E, 0x11, 0x11, 0x11, 0x0A }, // 'C' + { 0x1F, 0x11, 0x11, 0x11, 0x0E }, // 'D' + { 0x1F, 0x15, 0x15, 0x11, 0x11 }, // 'E' + { 0x1F, 0x14, 0x14, 0x10, 0x10 }, // 'F' + { 0x0E, 0x11, 0x15, 0x15, 0x06 }, // 'G' + { 0x1F, 0x04, 0x04, 0x04, 0x1F }, // 'H' + { 0x11, 0x11, 0x1F, 0x11, 0x11 }, // 'I' + { 0x02, 0x01, 0x01, 0x01, 0x1E }, // 'J' + { 0x1F, 0x04, 0x0C, 0x12, 0x01 }, // 'K' + { 0x1F, 0x01, 0x01, 0x01, 0x01 }, // 'L' + { 0x1F, 0x08, 0x06, 0x08, 0x1F }, // 'M' + { 0x1F, 0x08, 0x04, 0x02, 0x1F }, // 'N' + { 0x0E, 0x11, 0x11, 0x11, 0x0E }, // 'O' + { 0x1F, 0x12, 0x12, 0x12, 0x0C }, // 'P' + { 0x0C, 0x12, 0x12, 0x13, 0x0D }, // 'Q' + { 0x1F, 0x14, 0x14, 0x16, 0x09 }, // 'R' + { 0x09, 0x15, 0x15, 0x15, 0x02 }, // 'S' + { 0x10, 0x10, 0x1F, 0x10, 0x10 }, // 'T' + { 0x1E, 0x01, 0x01, 0x01, 0x1E }, // 'U' + { 0x1C, 0x02, 0x01, 0x02, 0x1C }, // 'V' + { 0x1E, 0x01, 0x06, 0x01, 0x1E }, // 'W' + { 0x11, 0x0A, 0x04, 0x0A, 0x11 }, // 'X' + { 0x18, 0x04, 0x03, 0x04, 0x18 }, // 'Y' + { 0x11, 0x13, 0x15, 0x19, 0x11 } // 'Z' +}; + +// ---------- CMovingThings ---------- +enum eScrollBarTypes +{ + SCROLL_ARENA_STRING +}; + +CScrollBar aScrollBars[1]; + +CMovingThing CMovingThings::StartCloseList; +CMovingThing CMovingThings::EndCloseList; +int16 CMovingThings::Num; +CMovingThing CMovingThings::aMovingThings[NUMMOVINGTHINGS]; + +int32 CScrollBar::TonightsEvent; + +void CMovingThings::Init() +{ + StartCloseList.m_pNext = &CMovingThings::EndCloseList; + StartCloseList.m_pPrev = nil; + EndCloseList.m_pNext = nil; + EndCloseList.m_pPrev = &CMovingThings::StartCloseList; + + CPlaneTrails::Init(); + CSmokeTrails::Init(); + CPlaneBanners::Init(); + CPointLights::Init(); + + Num = 0; + + for (int32 i = 0; i < NUMMOVINGTHINGS; i++) { + aMovingThings[i].m_nType = 0; + aMovingThings[i].m_farAway = 0; + } + + for (int i = 0; i < NUMSECTORS_X; i++) { + for (int j = 0; j < NUMSECTORS_Y; j++) { + for (CPtrNode *pNode = CWorld::GetSector(i, j)->m_lists[ENTITYLIST_BUILDINGS].first; pNode; pNode = pNode->next) { + CEntity *pEntity = (CEntity *)pNode->item; + PossiblyAddThisEntity(pEntity); + } + } + } + + for (int32 i = 0; i < NUM_LEVELS; i++) { + for (CPtrNode *pNode = CWorld::GetBigBuildingList((eLevelName)i).first; pNode; pNode = pNode->next) { + CEntity *pEntity = (CEntity *)pNode->item; + PossiblyAddThisEntity(pEntity); + } + } + + CEscalators::Init(); + aScrollBars[0].Init(CVector(-1069.209f, 1320.126f, 18.848f), CVector(-1069.209f, 1342.299f, 22.612f), SCROLL_ARENA_STRING, 128, 255, 0, 0.3f); +} + +void CMovingThings::Shutdown() +{ + + aScrollBars[0].SetVisibility(false); + CEscalators::Shutdown(); +} + +void CMovingThings::Update() +{ + CPlaneBanners::Update(); + CPlaneTrails::Update(); + CEscalators::Update(); + + const int TIME_SPAN = 8; // frames to process all aMovingThings + + int16 i; + + int block = CTimer::GetFrameCounter() % TIME_SPAN; + + for (i = (block * NUMMOVINGTHINGS) / TIME_SPAN; i < ((block + 1) * NUMMOVINGTHINGS) / TIME_SPAN; i++) { + if (aMovingThings[i].m_farAway == 1) + aMovingThings[i].Update(); + } + + for (i = 0; i < CMovingThings::Num; i++) { + if (aMovingThings[i].m_farAway == 0) + aMovingThings[i].Update(); + } + + for (i = 0; i < ARRAY_SIZE(aScrollBars); ++i) + { + if (aScrollBars[i].IsVisible() || (CTimer::GetFrameCounter() + i) % 8 == 0) + aScrollBars[i].Update(); + } +} + +void CMovingThings::Render() +{ + PUSH_RENDERGROUP("CMovingThings::Render"); + CSmokeTrails::Update(); + + int i; + for (i = 0; i < ARRAY_SIZE(aScrollBars); ++i) + { + if (aScrollBars[i].IsVisible()) + aScrollBars[i].Render(); + } + + CPlaneTrails::Render(); + CSmokeTrails::Render(); + CPlaneBanners::Render(); + POP_RENDERGROUP(); +} + +void CMovingThings::RegisterOne(CEntity *pEnt, uint16 nType) { + if (Num >= NUMMOVINGTHINGS) + return; + + aMovingThings[Num].m_pEntity = pEnt; + aMovingThings[Num].m_nType = nType; + aMovingThings[Num].m_farAway = 0; + aMovingThings[Num].m_vecPosn = pEnt->GetPosition(); + aMovingThings[Num].AddToList(&CMovingThings::StartCloseList); + Num++; +} + +void CMovingThings::PossiblyAddThisEntity(CEntity *pEnt) { + if (pEnt->GetModelIndex() == MI_LIGHTBEAM) { + RegisterOne(pEnt, 1); + } + else if (pEnt->GetModelIndex() == MI_AIRPORTRADAR) { + RegisterOne(pEnt, 2); + } + else if (pEnt->GetModelIndex() == MI_MALLFAN || pEnt->GetModelIndex() == MI_HOTELFAN_NIGHT + || pEnt->GetModelIndex() == MI_HOTELFAN_DAY || pEnt->GetModelIndex() == MI_HOTROOMFAN) { + RegisterOne(pEnt, 3); + } + else if (pEnt->GetModelIndex() == MI_BLIMP_NIGHT || pEnt->GetModelIndex() == MI_BLIMP_DAY) { + RegisterOne(pEnt, 4); + } +} + +// ---------- CMovingThing ---------- +static float maxUpdateDists[5] = { 100.0f, 1500.0f, 400.0f, 100.0f, 2000.0f }; + +void CMovingThing::Update() +{ + switch (m_nType) { + case 1: { + float angle = (CTimer::GetTimeInMilliseconds() % 0x3FFF) * TWOPI / 0x3FFF; + float s = Sin(angle); + float c = Cos(angle); + m_pEntity->GetRight() = CVector(-s, c, 0.0f); + m_pEntity->GetForward() = CVector(0.0f, 0.0f, 1.0f); + m_pEntity->GetUp() = CVector(c, s, 0.0f); + + if (CClock::GetHours() >= 20 || CClock::GetHours() < 5) { + if (Abs(TheCamera.GetPosition().x - m_pEntity->GetPosition().x) < 600.0f && + Abs(TheCamera.GetPosition().y - m_pEntity->GetPosition().y) < 600.0f) { + CVector delta = m_pEntity->GetPosition() - TheCamera.GetPosition(); + delta /= delta.Magnitude(); + + if (DotProduct(delta, CVector(c, s, 0.0f)) < -0.92f) { + CVector coors = m_pEntity->GetPosition() - 10.0f * delta; + CCoronas::RegisterCorona(43, 128, 128, 100, 255, coors, 70.0f, 600.0f, 0.0f, CCoronas::TYPE_STAR, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); + } + } + } + } + break; + case 2: { + float angle = (CTimer::GetTimeInMilliseconds() % 0x7FF) * TWOPI / 0x7FF; + float s = Sin(angle); + float c = Cos(angle); + m_pEntity->GetRight() = CVector(c, s, 0.0f); + m_pEntity->GetForward() = CVector(-s, c, 0.0f); + m_pEntity->GetUp() = CVector(0.0f, 0.0f, 1.0f); + } + break; + case 3: { + float angle = (CTimer::GetTimeInMilliseconds() % 0x3FF) * TWOPI / 0x3FF; + float s = Sin(angle); + float c = Cos(angle); + m_pEntity->GetRight() = CVector(c, s, 0.0f); + m_pEntity->GetForward() = CVector(-s, c, 0.0f); + m_pEntity->GetUp() = CVector(0.0f, 0.0f, 1.0f); + } + break; + case 4: { + float angle = (CTimer::GetTimeInMilliseconds() % 0x3FFFF) * TWOPI / 0x3FFFF; + float s = Sin(angle); + float c = Cos(angle); + m_pEntity->GetRight() = CVector(-c, -s, 0.0f); + m_pEntity->GetForward() = CVector(s, -c, 0.0f); + m_pEntity->GetUp() = CVector(0.0f, 0.0f, 1.0f); + m_pEntity->SetPosition(CVector(350.0f * c - 465.0f, 350.0f * s + 1163.0f, 260.0f)); + } + break; + default: + break; + } + + m_pEntity->GetMatrix().UpdateRW(); + m_pEntity->UpdateRwFrame(); + + if (SQR(m_pEntity->GetPosition().x - TheCamera.GetPosition().x) + SQR(m_pEntity->GetPosition().y - TheCamera.GetPosition().y) < SQR(maxUpdateDists[m_nType])) { + if (m_farAway == 1) { + AddToList(&CMovingThings::StartCloseList); + m_farAway = 0; + } + } + else { + if (m_farAway == 0) { + RemoveFromList(); + m_farAway = 1; + } + } +} + +void CMovingThing::AddToList(CMovingThing *pThing) +{ + m_pNext = pThing->m_pNext; + m_pPrev = pThing; + pThing->m_pNext = this; + m_pNext->m_pPrev = this; +} + +void CMovingThing::RemoveFromList() +{ + m_pNext->m_pPrev = m_pPrev; + m_pPrev->m_pNext = m_pNext; +} + +int16 CMovingThing::SizeList() +{ + CMovingThing *next = m_pNext; + int16 count = 0; + + while (next != nil) { + next = next->m_pNext; + count++; + } + + return count; +} + +char String_Time[] = "THE TIME IS 12:34 "; +const char* FindTimeMessage() +{ + String_Time[12] = '0' + CClock::GetHours() / 10; + String_Time[13] = '0' + CClock::GetHours() % 10; + String_Time[15] = '0' + CClock::GetMinutes() / 10; + String_Time[16] = '0' + CClock::GetMinutes() % 10; + return String_Time; +} + +// ---------- CScrollBar ---------- +void CScrollBar::Init(CVector pos1, CVector pos2, uint8 type, uint8 red, uint8 green, uint8 blue, float scale) +{ + for (int i = 0; i < ARRAY_SIZE(m_MessageBar); ++i) + m_MessageBar[i] = 0; + + m_pMessage = ". "; + m_MessageCurrentChar = 0; + m_MessageLength = strlen(m_pMessage); + + m_Counter = 0; + m_bVisible = false; + m_Position = pos1; + m_Type = type; + m_Size.x = (pos2.x - pos1.x) * 0.025f; + m_Size.y = (pos2.y - pos1.y) * 0.025f; + m_Size.z = (pos2.z - pos1.z) * 0.2f; + m_uRed = red; + m_uGreen = green; + m_uBlue = blue; + m_fScale = scale; +} + +void CScrollBar::Update() +{ + float distanceFromCamera = (TheCamera.GetPosition() - m_Position).Magnitude(); + if (distanceFromCamera > 100.0f) + { + m_bVisible = false; + return; + } + + m_bVisible = true; + + if (distanceFromCamera < 75.0f) + m_fIntensity = 1.0f; + else + m_fIntensity = 1.0f - 4.0f * (distanceFromCamera - 75.0f) / 100.0f; + + m_Counter = (m_Counter + 1) % 8; + + // if message is fully printed, load up the next one + if (m_Counter == 0 && ++m_MessageCurrentChar >= m_MessageLength) + { + const char* previousMessage = m_pMessage; + if (m_Type == SCROLL_ARENA_STRING) { + while (previousMessage == m_pMessage) + { + switch (CGeneral::GetRandomNumber() % 4) + { + case 0: + switch (TonightsEvent) { + case 0: + m_pMessage = "MAIN EVENT TONIGHT: CAR RACING . . . "; + break; + case 1: + m_pMessage = "MAIN EVENT TONIGHT: DESTRUCTION DERBY . . . "; + break; + case 2: + m_pMessage = "MAIN EVENT TONIGHT: BIKE RACING . . . "; + break; + } + break; + case 1: + switch (TonightsEvent) { + case 0: + m_pMessage = "FOR TICKETS TO THE HOT RING EVENT CALL 555-3764 . . . "; + break; + case 1: + m_pMessage = "FOR TICKETS TO THE BLOOD RING EVENT CALL 555-3765 . . . "; + break; + case 2: + m_pMessage = "FOR TICKETS TO THE DIRT RING EVENT CALL 555-3766 . . . "; + break; + } + break; + case 2: + m_pMessage = "HYMAN MEMORIAL STADIUM. HOME TO SOME OF THE BIGGEST EVENTS OF" + " THE WESTERN HEMISPHERE. ALSO AVAILABLE FOR CHILDREN PARTIES. . . "; + break; + case 3: + m_pMessage = FindTimeMessage(); + break; + default: + break; + } + } + } + + m_MessageLength = (uint32)strlen(m_pMessage); + m_MessageCurrentChar = 0; + } + + // Scroll + for (int i = 0; i < ARRAY_SIZE(m_MessageBar)-1; i++) + m_MessageBar[i] = m_MessageBar[i + 1]; + m_MessageBar[ARRAY_SIZE(m_MessageBar)-1] = m_Counter < 5 ? ScrollCharSet[m_pMessage[m_MessageCurrentChar] - ' '][m_Counter] : 0; + + // Introduce some random displaying glitches; signs aren't supposed to be perfect :P + switch (CGeneral::GetRandomNumber() & 0xFF) + { + case 0x0D: m_MessageBar[ARRAY_SIZE(m_MessageBar)-1] = 0; break; + case 0xE3: m_MessageBar[ARRAY_SIZE(m_MessageBar)-1] = 0xE3; break; + case 0x64: m_MessageBar[ARRAY_SIZE(m_MessageBar)-1] = ~m_MessageBar[ARRAY_SIZE(m_MessageBar)-1]; break; + } +} + +void CScrollBar::Render() +{ + if (!TheCamera.IsSphereVisible(m_Position, 2.0f * 20.0f * (ABS(m_Size.x) + ABS(m_Size.y)))) + return; + + CSprite::InitSpriteBuffer(); + + // Calculate intensity of colours + uint8 r = m_fIntensity * m_uRed; + uint8 g = m_fIntensity * m_uGreen; + uint8 b = m_fIntensity * m_uBlue; + + // Set render states + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpCoronaTexture[0])); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + + CVector coronaCoord, screenCoord; + float screenW, screenH; + for (int i = 1; i < ARRAY_SIZE(m_MessageBar); ++i) + { + for (int j = 0; j < 5; ++j) + { + coronaCoord.x = m_Position.x + m_Size.x * i; + coronaCoord.y = m_Position.y + m_Size.y * i; + coronaCoord.z = m_Position.z + m_Size.z * j; + + // Render main coronas + if (m_MessageBar[i] & (1 << j)) + { + if (CSprite::CalcScreenCoors(coronaCoord, &screenCoord, &screenW, &screenH, true)) + { + CSprite::RenderBufferedOneXLUSprite( + screenCoord.x, screenCoord.y, screenCoord.z, + screenW * m_fScale, screenH * m_fScale, + r, g, b, + 255, 1.0f / screenCoord.z, 255); + } + } + // Render smaller and faded coronas for a trailing effect + else if (m_MessageBar[i - 1] & (1 << j)) + { + if (CSprite::CalcScreenCoors(coronaCoord, &screenCoord, &screenW, &screenH, true)) + { + CSprite::RenderBufferedOneXLUSprite( + screenCoord.x, screenCoord.y, screenCoord.z, + screenW * m_fScale * 0.8f, + screenH * m_fScale * 0.8f, + r / 2, + g / 2, + b / 2, + 255, 1.0f / screenCoord.z, 255); + } + } + } + } + + CSprite::FlushSpriteBuffer(); +} + +void +CSmokeTrail::RegisterPoint(CVector regPosition, float opacity) { + bool bAddedNewPoint = false; + + if (m_time[0] && CTimer::GetTimeInMilliseconds() - m_time[0] > 150) { + bAddedNewPoint = true; + for (int32 i = 15; i > 0; i--) { + m_pos[i] = m_pos[i - 1]; + m_time[i] = m_time[i - 1]; + m_opacity[i] = m_opacity[i - 1]; + } + ++m_seed; + } + m_pos[0] = regPosition; + + if (bAddedNewPoint || !m_time[0]) { + m_time[0] = CTimer::GetTimeInMilliseconds(); + float density = 0.1f / (m_pos[1] - m_pos[2]).Magnitude(); + m_opacity[1] = opacity * Min(density, 1.0f); + } + m_opacity[0] = 0.0f; +} + +void +CSmokeTrail::Init(int num) { + for (int32 i = 0; i < 16; i++) + m_time[i] = 0; + m_seed = num * 2; +} + +void +CSmokeTrails::Init(void) { + for (int32 i = 0; i < 3; i++) + aSmoke[i].Init(i); +} + +void +CSmokeTrails::Render(void) { + for (int32 i = 0; i < 3; i++) + aSmoke[i].Render(); +} + +void +CSmokeTrail::Render(void) { + int numVerts = 0; + + if (TheCamera.IsSphereVisible(m_pos[0], 10.0f)) { + for (int32 i = 0; i < 16; i++) { + int timeSinceSpawned = CTimer::GetTimeInMilliseconds() - m_time[i]; + + if (timeSinceSpawned > 2250) + m_time[i] = 0; + + if (m_time[i]) { + int alpha = (1.0f - timeSinceSpawned / 2250.0f) * 110.0f * m_opacity[i]; + float offset = timeSinceSpawned * CWeather::Wind * 0.0001f; + float posX = (m_pos[i].x + timeSinceSpawned * RandomSmoke[(i - m_seed) & 0xF] * 0.00001f) - offset; + float posY = (m_pos[i].y + timeSinceSpawned * RandomSmoke[(i - m_seed + 5) & 0xF] * 0.00001f) - offset; + float posZ = m_pos[i].z + timeSinceSpawned * 0.0004f; + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[i], 200, 200, 200, alpha); + RwIm3DVertexSetPos(&TempBufferRenderVertices[i], posX, posY, posZ); + numVerts++; + } + } + } + + if (numVerts > 1) { + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + + if (RwIm3DTransform(TempBufferRenderVertices, numVerts, nil, rwIM3D_VERTEXXYZ | rwIM3D_VERTEXRGBA)) { + RwIm3DRenderIndexedPrimitive(rwPRIMTYPEPOLYLINE, SmokeTrailIndices, 2 * (numVerts - 1)); + RwIm3DEnd(); + } + } +} + +void +CSmokeTrails::Update(void) { + + if (!CSmokeTrails::CigOn || TheCamera.Using1stPersonWeaponMode() || !FindPlayerPed() || + FindPlayerVehicle() || CCutsceneMgr::IsRunning() || !FindPlayerPed()->GetClump()) + return; + + RwV3d startPos = { 0.026f, 0.15f, 0.02f }; + RwV3d endPos = { 0.026f, 0.05f, 0.02f }; + + RpHAnimHierarchy *hier = GetAnimHierarchyFromSkinClump(FindPlayerPed()->GetClump()); + int32 idx = RpHAnimIDGetIndex(hier, ConvertPedNode2BoneTag(PED_HEAD)); + RwMatrix *head = &RpHAnimHierarchyGetMatrixArray(hier)[idx]; + RwV3dTransformPoints(&startPos, &startPos, 1, head); + RwV3dTransformPoints(&endPos, &endPos, 1, head); + + aSmoke[0].RegisterPoint(startPos, 1.0f); + aSmoke[1].RegisterPoint(startPos, 0.75f); + aSmoke[2].RegisterPoint(startPos, 0.5f); + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[0], 255, 255, 255, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[0], startPos.x, startPos.y, startPos.z); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[1], 255, 255, 255, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[1], endPos.x, endPos.y, endPos.z); + + if (RwIm3DTransform(TempBufferRenderVertices, 2, nil, rwIM3D_VERTEXXYZ | rwIM3D_VERTEXRGBA)) { + RwIm3DRenderIndexedPrimitive(rwPRIMTYPEPOLYLINE, SmokeTrailIndices, 2); + RwIm3DEnd(); + } +} + +CEscalator CEscalators::aEscalators[NUM_ESCALATORS]; +int32 CEscalators::NumEscalators; + +CEscalator::CEscalator() { + m_bIsActive = false; + + for (int i = 0; i < 24; i++) { + m_pSteps[i] = nil; + } +} + +void +CEscalator::AddThisOne(CVector pos0, CVector pos1, CVector pos2, CVector pos3, bool b_isMovingDown) { + m_pos0 = pos0; + m_pos1 = pos1; + m_pos2 = pos2; + m_pos3 = pos3; + + float escalatorStepHeight = CModelInfo::GetModelInfo(MI_ESCALATORSTEP)->GetColModel()->boundingBox.max.z; + m_pos0.z -= escalatorStepHeight; + m_pos1.z -= escalatorStepHeight; + m_pos2.z -= escalatorStepHeight; + m_pos3.z -= escalatorStepHeight; + + float magnitudes[3]; + magnitudes[0] = (m_pos0 - m_pos1).Magnitude(); + magnitudes[1] = (m_pos1 - m_pos2).Magnitude(); + magnitudes[2] = (m_pos2 - m_pos3).Magnitude(); + + float length = magnitudes[0] + magnitudes[1] + magnitudes[2]; + + m_lowerEnd = magnitudes[0] / length; + m_upperEnd = (magnitudes[0] + magnitudes[1]) / length; + + m_stepsCount = Min(24.0f, length / 0.6f); + + CVector direction(m_pos0.x - m_pos1.x, m_pos0.y - m_pos1.y, 0.0f); + direction.Normalise(); + + m_matrix.GetUp() = CVector(0.0f, 0.0f, 1.0f); + m_matrix.GetForward() = CVector(direction.x, direction.y, 0.0f); + m_matrix.GetRight() = CVector(direction.y, -direction.x, 0.0f); + m_matrix.GetPosition() = CVector(0.0f, 0.0f, 0.0f); + + m_bIsMovingDown = b_isMovingDown; + + m_midPoint = (m_pos0 + m_pos3) / 2.0f; + + m_radius = (m_pos0 - m_midPoint).Magnitude(); +} + +void +CEscalator::Update(void) { + if (!m_bIsActive) { + if ((TheCamera.GetPosition() - m_midPoint).Magnitude() < 25.0f) { + if (TheCamera.IsSphereVisible(m_midPoint, m_radius) && (m_stepsCount + 10 < CPools::GetObjectPool()->GetNoOfFreeSpaces())) { + m_bIsActive = true; + for (int i = 0; i < m_stepsCount; i++) { + m_pSteps[i] = new CObject(MI_ESCALATORSTEP, TRUE); + if (m_pSteps[i]) { + m_pSteps[i]->SetPosition(m_pos1); + CWorld::Add(m_pSteps[i]); + m_pSteps[i]->ObjectCreatedBy = CONTROLLED_SUB_OBJECT; + } + } + } + } + } + + if (m_bIsActive) { + float time = (CTimer::GetTimeInMilliseconds() % 16384) / 16384.0f; + for (int i = 0; i < m_stepsCount; i++) { + if (m_pSteps[i]) { + float t = i / (float)m_stepsCount + time; + + if (t > 1.0f) + t -= 1.0f; + + if (m_bIsMovingDown) + t = 1.0f - t; + + CVector oldPosition = m_pSteps[i]->GetPosition(); + m_pSteps[i]->GetMatrix() = m_matrix; + + CVector newPosition; + if (t < m_lowerEnd) { + float ratio = t / m_lowerEnd; + newPosition = (ratio * m_pos1) + ((1.0f - ratio) * m_pos0); + } + else if (t < m_upperEnd) { + float ratio = (t - m_lowerEnd) / (m_upperEnd - m_lowerEnd); + newPosition = (ratio * m_pos2) + ((1.0f - ratio) * m_pos1); + } + else { + float ratio = (t - m_upperEnd) / (1.0f - m_upperEnd); + newPosition = (ratio * m_pos3) + ((1.0f - ratio) * m_pos2); + } + + m_pSteps[i]->SetPosition(newPosition); + m_pSteps[i]->m_vecMoveSpeed = (newPosition - oldPosition) / Max(CTimer::GetTimeStep(), 1.0f); + m_pSteps[i]->GetMatrix().UpdateRW(); + m_pSteps[i]->UpdateRwFrame(); + } + if ((TheCamera.GetPosition() - m_midPoint).Magnitude() > 28.0f || !TheCamera.IsSphereVisible(m_midPoint, m_radius)) + SwitchOff(); + } + } +} + +bool deletingEscalator; + +void +CEscalator::SwitchOff(void) { + if (m_bIsActive) { + for (int i = 0; i < m_stepsCount; i++) { + if (m_pSteps[i]) { + CWorld::Remove(m_pSteps[i]); + deletingEscalator = true; + delete m_pSteps[i]; + m_pSteps[i] = nil; + deletingEscalator = false; + } + } + m_bIsActive = false; + } +} + +void +CEscalators::AddOne(CVector pos0, CVector pos1, CVector pos2, CVector pos3, bool b_isMovingDown) { + aEscalators[NumEscalators++].AddThisOne(pos0, pos1, pos2, pos3, b_isMovingDown); +} + +void +CEscalators::Init(void) { + Shutdown(); + NumEscalators = 0; + + AddOne(CVector(-9.82999f, -938.04498f, 9.4219f), CVector(-8.573f, -938.04498f, 9.4219f), + CVector(-0.747f, -938.045f, 15.065f), CVector(0.88f, -938.045f, 15.065f), TRUE); + + AddOne(CVector(-9.83f, -939.966f, 9.422f), CVector(-8.573f, -939.966f, 9.422f), + CVector(-0.747f, -939.966f, 15.065f), CVector(0.880f, -939.966f, 15.065f), FALSE); + + AddOne(CVector(408.116f, 1058.36f, 18.261f), CVector(408.094f, 1057.04f, 18.261f), + CVector(408.116f, 1048.0f, 24.765f), CVector(408.094f, 1046.57f, 24.799f), TRUE); + + AddOne(CVector(406.195f, 1058.36f, 18.261f), CVector(406.173f, 1057.04f, 18.261f), + CVector(406.195f, 1048.0f, 24.729f), CVector(406.173f, 1046.57f, 24.79f), FALSE); + + AddOne(CVector(421.729f, 1058.3789f, 18.075f), CVector(421.707f, 1057.052f, 18.099f), + CVector(421.729f, 1048.016f, 24.604f), CVector(421.707f, 1046.589f, 24.637f), TRUE); + + AddOne(CVector(419.808f, 1058.378f, 18.099f), CVector(419.786f, 1057.052f, 18.099f), + CVector(419.808f, 1048.016f, 24.568f), CVector(419.786f, 1046.589f, 24.637f), FALSE); + + AddOne(CVector(412.69901f, 1102.729f, 17.569f), CVector(412.72198f, 1104.057f, 17.57f), + CVector(412.69901f, 1113.092f, 24.073f), CVector(412.72198f, 1114.3201f, 24.108f), TRUE); + + AddOne(CVector(414.62f, 1102.729f, 17.569f), CVector(414.64301f, 1104.057f, 17.57f), + CVector(414.62f, 1113.092f, 24.037001f), CVector(414.64301f, 1114.3201f, 24.099001f), FALSE); + + AddOne(CVector(414.64301f, 1145.589f, 17.57f), CVector(414.62f, 1144.261f, 17.569f), + CVector(414.64301f, 1135.226f, 24.073999f), CVector(414.62f, 1133.798f, 24.107f), TRUE); + + AddOne(CVector(412.72198f, 1145.589f, 17.57f), CVector(412.69901f, 1144.261f, 17.569f), + CVector(412.72198f, 1135.226f, 24.038f), CVector(412.69901f, 1133.798f, 24.098f), FALSE); + + AddOne(CVector(406.05099f, 1193.4771f, 18.016001f), CVector(406.07401f, 1194.8051f, 18.017f), + CVector(406.05099f, 1203.84f, 24.52f), CVector(406.07401f, 1205.2679f, 24.555f), TRUE); + + AddOne(CVector(407.97198f, 1193.4771f, 18.016001f), CVector(407.995f, 1194.8051f, 18.017f), + CVector(407.97198f, 1203.84f, 24.483999f), CVector(407.995f, 1205.2679f, 24.546f), FALSE); + + AddOne(CVector(419.659f, 1193.479f, 17.979f), CVector(419.68201f, 1194.807f, 17.98f), + CVector(419.659f, 1203.842f, 24.483f), CVector(419.68201f, 1205.27f, 24.518f), TRUE); + + AddOne(CVector(421.57999f, 1193.479f, 17.979f), CVector(421.603f, 1194.807f, 17.98f), + CVector(421.57999f, 1203.842f, 24.447001f), CVector(421.603f, 1205.27f, 24.509001f), FALSE); + + AddOne(CVector(406.23199f, 1022.857f, 17.917f), CVector(406.23199f, 1024.1851f, 17.917f), + CVector(406.23199f, 1033.22f, 24.521f), CVector(406.23199f, 1034.647f, 24.555f), TRUE); + + AddOne(CVector(408.15302f, 1022.857f, 17.917f), CVector(408.15302f, 1024.1851f, 17.916f), + CVector(408.15302f, 1033.22f, 24.486f), CVector(408.15302f, 1034.647f, 24.52f), FALSE); + + AddOne(CVector(-1506.39f, -813.13f, 13.834f), CVector(-1506.177f, -814.51703f, 13.834f), + CVector(-1504.566f, -823.20898f, 19.836f), CVector(-1504.329f, -824.48499f, 19.837f), FALSE); + + AddOne(CVector(-1481.951f, -859.05402f, 13.834f), CVector(-1482.7791f, -858.22498f, 13.834f), + CVector(-1489.03f, -851.974f, 19.836f), CVector(-1489.948f, -851.05701f, 19.837f), TRUE); + + AddOne(CVector(-1461.743f, -871.35901f, 13.834f), CVector(-1460.62f, -871.69202f, 13.834f), + CVector(-1452.144f, -874.20203f, 19.836f), CVector(-1450.9f, -874.57098f, 19.837f), FALSE); + + AddOne(CVector(-1409.889f, -871.41498f, 13.834f), CVector(-1411.0129f, -871.74701f, 13.834f), + CVector(-1419.489f, -874.258f, 19.836f), CVector(-1420.733f, -874.62701f, 19.837f), TRUE); + + AddOne(CVector(-1389.577f, -858.89301f, 13.834f), CVector(-1388.7271f, -858.08698f, 13.834f), + CVector(-1382.314f, -852.00201f, 19.836f), CVector(-1381.373f, -851.10797f, 19.837f), FALSE); + + AddOne(CVector(-1364.981f, -813.13f, 13.834f), CVector(-1365.204f, -814.28003f, 13.834f), + CVector(-1366.891f, -822.95801f, 19.83f), CVector(-1367.139f, -824.23199f, 19.837f), TRUE); + + for (int i = 0; i < NUM_ESCALATORS; i++) { + aEscalators[i].SwitchOff(); + } +} + +void +CEscalators::Update(void) { + if (CReplay::IsPlayingBack()) + return; + + for (int i = 0; i < NUM_ESCALATORS; i++) { + aEscalators[i].Update(); + } +} + +void +CEscalators::Shutdown(void) { + for (int i = 0; i < NUM_ESCALATORS; i++) { + aEscalators[i].SwitchOff(); + } + NumEscalators = 0; +} + + +CScriptPath CScriptPaths::aArray[3]; + +void CScriptPath::FindCoorsFromDistanceOnPath(float t, float *pX, float *pY, float *pZ) +{ + int32 i; + for (i = 0; m_pNode[i + 1].t < t; i++) + if (i == m_numNodes - 1) { + // don't go beyond last node + *pX = m_pNode[m_numNodes - 1].p.x; + *pY = m_pNode[m_numNodes - 1].p.y; + *pZ = m_pNode[m_numNodes - 1].p.z; + return; + } + float f = (t - m_pNode[i].t) / (m_pNode[i + 1].t - m_pNode[i].t); + *pX = (1.0f - f)*m_pNode[i].p.x + f*m_pNode[i + 1].p.x; + *pY = (1.0f - f)*m_pNode[i].p.y + f*m_pNode[i + 1].p.y; + *pZ = (1.0f - f)*m_pNode[i].p.z + f*m_pNode[i + 1].p.z; +} + +void CScriptPath::Update(void) { + if (m_state != SCRIPT_PATH_ACTIVE) + return; + + m_fPosition += m_fSpeed * CTimer::GetTimeStepInSeconds(); + m_fPosition = Clamp(m_fPosition, 0.0f, m_fTotalLength); + + if (m_pObjects[0] || m_pObjects[1] || m_pObjects[2] || m_pObjects[3] + || m_pObjects[4] || m_pObjects[5]) { + + float t1, t2; + CVector pos1, pos2; + + t1 = Max(m_fPosition - m_fObjectLength / 2.0f, 0.0f); + FindCoorsFromDistanceOnPath(t1, &pos1.x, &pos1.y, &pos1.z); + t2 = Min(m_fPosition + m_fObjectLength / 2.0f, m_fTotalLength); + FindCoorsFromDistanceOnPath(t2, &pos2.x, &pos2.y, &pos2.z); + + CVector newForward, newUp(0.0f, 0.0f, 1.0f), newRight; + + newForward = pos2 - pos1; + newForward.Normalise(); + newRight = CrossProduct(newForward, newUp); + newRight.Normalise(); + newUp = CrossProduct(newRight, newForward); + + for (int i = 0; i < 6; i++) { + if (m_pObjects[i]) { + CMatrix prevMat(m_pObjects[i]->GetMatrix()); + CVector prevPosition = m_pObjects[i]->GetPosition(); + + m_pObjects[i]->SetPosition((pos1 + pos2) / 2.0f); + m_pObjects[i]->GetRight() = newRight; + m_pObjects[i]->GetUp() = newUp; + m_pObjects[i]->GetForward() = newForward; + m_pObjects[i]->GetMatrix().UpdateRW(); + m_pObjects[i]->UpdateRwFrame(); + + if (!m_pObjects[i]->bIsBIGBuilding && prevPosition != m_pObjects[i]->GetPosition()) + m_pObjects[i]->RemoveAndAdd(); + + m_pObjects[i]->GetMatrix().UpdateRW(); + m_pObjects[i]->UpdateRwFrame(); + + m_pObjects[i]->m_vecMoveSpeed = (m_pObjects[i]->GetPosition() - prevMat.GetPosition()) / CTimer::GetTimeStep(); + + float deltaAngle = m_pObjects[i]->GetForward().Heading() - prevMat.GetForward().Heading(); + while (deltaAngle < (float)PI) deltaAngle += (float)TWOPI; + while (deltaAngle > (float)PI) deltaAngle -= (float)TWOPI; + float zTurnSpeed = deltaAngle / CTimer::GetTimeStep(); + + m_pObjects[i]->m_vecTurnSpeed = CVector(0.0f, 0.0f, zTurnSpeed); + m_pObjects[i]->m_vecMoveFriction = CVector(0.0f, 0.0f, 0.0f); + m_pObjects[i]->m_vecTurnFriction = CVector(0.0f, 0.0f, 0.0f); + } + } + } +} + +void CScriptPath::Clear(void) { + if (m_pNode) + delete[] m_pNode; + m_pNode = nil; + m_numNodes = 0; + for (int i = 0; i < 6; i++) + m_pObjects[i] = nil; + m_state = SCRIPT_PATH_DISABLED; +} + +void CScriptPath::InitialiseOne(int32 numNodes, float length) { + char Dest[32]; + sprintf(Dest, "data\\paths\\spath%d.dat", numNodes); + m_pNode = CPlane::LoadPath(Dest, m_numNodes, m_fTotalLength, false); + m_fSpeed = 1.0f; + m_fPosition = 0.0f; + m_fObjectLength = length; + m_state = SCRIPT_PATH_INITIALIZED; +} + +void CScriptPath::SetObjectToControl(CObject *pObj) { + int32 i = 0; + while (i < 6 && m_pObjects[i]) + i++; + m_pObjects[i] = pObj; + pObj->RegisterReference((CEntity**)&m_pObjects[i]); + pObj->m_phy_flagA08 = false; + m_state = SCRIPT_PATH_ACTIVE; +} + +void CScriptPaths::Init(void) { + for (int i = 0; i < 3; i++) + aArray[i].Clear(); +} + +void CScriptPaths::Shutdown(void) { + for (int i = 0; i < 3; i++) + aArray[i].Clear(); +} + +void CScriptPaths::Update(void) { + for (int i = 0; i < 3; i++) + aArray[i].Update(); +} + +bool CScriptPaths::IsOneActive(void) { + for (int i = 0; i < 3; i++) + if (aArray[i].m_state == SCRIPT_PATH_ACTIVE && aArray[i].m_fSpeed != 0.0f) + return true; + + return false; +} + +void CScriptPaths::Load(uint8 *buf, uint32 size) { +INITSAVEBUF + for (int32 i = 0; i < 3; i++) + aArray[i].Clear(); + + for (int32 i = 0; i < 3; i++) { +#ifdef COMPATIBLE_SAVES + ReadSaveBuf(&aArray[i].m_numNodes, buf); + SkipSaveBuf(buf, 4); + ReadSaveBuf(&aArray[i].m_fTotalLength, buf); + ReadSaveBuf(&aArray[i].m_fSpeed, buf); + ReadSaveBuf(&aArray[i].m_fPosition, buf); + ReadSaveBuf(&aArray[i].m_fObjectLength, buf); + ReadSaveBuf(&aArray[i].m_state, buf); +#else + ReadSaveBuf(&aArray[i], buf); +#endif + + for (int32 j = 0; j < 6; j++) { +#ifdef COMPATIBLE_SAVES + aArray[i].m_pObjects[j] = nil; + int32 tmp; + ReadSaveBuf(&tmp, buf); + if (tmp != 0) { + aArray[i].m_pObjects[j] = CPools::GetObjectPool()->GetSlot(tmp - 1); + aArray[i].m_pObjects[j]->m_phy_flagA08 = false; + } +#else + CScriptPath *pPath = &aArray[i]; + if (pPath->m_pObjects[j] != nil) { + pPath->m_pObjects[j] = CPools::GetObjectPool()->GetSlot((uintptr)pPath->m_pObjects[j] - 1); + pPath->m_pObjects[j]->m_phy_flagA08 = false; + } +#endif + } + + aArray[i].m_pNode = new CPlaneNode[aArray[i].m_numNodes]; + for (int32 j = 0; j < aArray[i].m_numNodes; j++) { + ReadSaveBuf(&aArray[i].m_pNode[j], buf); + } + } +VALIDATESAVEBUF(size) +} + +void CScriptPaths::Save(uint8 *buf, uint32 *size) { + *size = SCRIPTPATHS_SAVE_SIZE; +INITSAVEBUF + for (int32 i = 0; i < 3; i++) { +#ifdef COMPATIBLE_SAVES + WriteSaveBuf(buf, aArray[i].m_numNodes); + ZeroSaveBuf(buf, 4); + WriteSaveBuf(buf, aArray[i].m_fTotalLength); + WriteSaveBuf(buf, aArray[i].m_fSpeed); + WriteSaveBuf(buf, aArray[i].m_fPosition); + WriteSaveBuf(buf, aArray[i].m_fObjectLength); + WriteSaveBuf(buf, aArray[i].m_state); +#else + CScriptPath *pPath = WriteSaveBuf(buf, aArray[i]); +#endif + + for (int32 j = 0; j < 6; j++) { +#ifdef COMPATIBLE_SAVES + WriteSaveBuf(buf, aArray[i].m_pObjects[j] != nil ? CPools::GetObjectPool()->GetJustIndex_NoFreeAssert(aArray[i].m_pObjects[j]) + 1 : 0); +#else + if (pPath->m_pObjects[j] != nil) + pPath->m_pObjects[j] = (CObject*)(CPools::GetObjectPool()->GetJustIndex_NoFreeAssert(pPath->m_pObjects[j]) + 1); +#endif + } + + for (int32 j = 0; j < aArray[i].m_numNodes; j++) { + WriteSaveBuf(buf, aArray[i].m_pNode[j]); + *size += sizeof(aArray[i].m_pNode[j]); + } + } +VALIDATESAVEBUF(*size); +} + +CObject *g_pScriptPathObjects[18]; + +void CScriptPaths::Load_ForReplay(void) { + for (int i = 0; i < 3; i++) { + for (int32 j = 0; j < 6; j++) { + aArray[i].m_pObjects[j] = g_pScriptPathObjects[6 * i + j]; + } + } +} + +void CScriptPaths::Save_ForReplay(void) { + for (int i = 0; i < 3; i++) { + for (int32 j = 0; j < 6; j++) { + g_pScriptPathObjects[6 * i + j] = aArray[i].m_pObjects[j]; + } + } +} diff --git a/src/renderer/Fluff.h b/src/renderer/Fluff.h new file mode 100644 index 00000000..58c8410c --- /dev/null +++ b/src/renderer/Fluff.h @@ -0,0 +1,205 @@ +#pragma once +#include "common.h" +#include "Vector.h" +#include "Object.h" +#include "Plane.h" + +enum { + SCRIPT_PATH_DISABLED = 0, + SCRIPT_PATH_INITIALIZED, + SCRIPT_PATH_ACTIVE +}; + +class CScriptPath +{ +public: + int32 m_numNodes; + CPlaneNode *m_pNode; + float m_fTotalLength; + float m_fSpeed; + float m_fPosition; + float m_fObjectLength; + int32 m_state; + CObject *m_pObjects[6]; + + void Clear(void); + void Update(void); + void InitialiseOne(int32 numNodes, float length); + void FindCoorsFromDistanceOnPath(float t, float *pX, float *pY, float *pZ); + void SetObjectToControl(CObject *pObj); +}; + +class CScriptPaths +{ +public: + static CScriptPath aArray[3]; + static void Init(void); + static void Shutdown(void); + static void Update(void); + static bool IsOneActive(void); + static void Save(uint8 *buf, uint32 *size); + static void Load(uint8 *buf, uint32 size); + static void Save_ForReplay(); + static void Load_ForReplay(); +}; + +class CPlaneTrail +{ + CVector m_pos[16]; + int32 m_time[16]; +public: + void Init(void); + void Render(float visibility); + void RegisterPoint(CVector pos); +}; + +class CPlaneTrails +{ + static CPlaneTrail aArray[6]; // NB: 3 CPlanes and 3 hardcoded far away ones +public: + static void Init(void); + static void Update(void); + static void Render(void); + static void RegisterPoint(CVector pos, uint32 id); +}; + +class CPlaneBanner +{ + CVector m_pos[8]; +public: + void Init(void); + void Update(void); + void Render(void); + void RegisterPoint(CVector pos); +}; + +class CPlaneBanners +{ + static CPlaneBanner aArray[5]; +public: + static void Init(void); + static void Update(void); + static void Render(void); + static void RegisterPoint(CVector pos, uint32 id); +}; + +class CEscalator +{ + CVector m_pos0; + CVector m_pos1; + CVector m_pos2; + CVector m_pos3; + CMatrix m_matrix; + bool m_bIsActive; + bool m_bIsMovingDown; + int32 m_stepsCount; + float m_lowerEnd; + float m_upperEnd; + CVector m_midPoint; + float m_radius; + CObject *m_pSteps[24]; +public: + CEscalator(); + void Update(void); + void SwitchOff(void); + void AddThisOne(CVector pos0, CVector pos1, CVector pos2, CVector pos3, bool b_isMovingDown); + bool IsActive() const { return m_bIsActive; }; + const CVector& GetPosition() const { return m_midPoint; }; +}; + +class CEscalators +{ + static CEscalator aEscalators[NUM_ESCALATORS]; +public: + static int32 NumEscalators; + static void Init(void); + static void Update(void); + static void AddOne(CVector pos0, CVector pos1, CVector pos2, CVector pos3, bool b_isMovingDown); + static void Shutdown(void); + static const CEscalator& GetEscalator(int ind) { return aEscalators[ind]; }; +}; + +class CMovingThing +{ +public: + CMovingThing *m_pNext; + CMovingThing *m_pPrev; + int16 m_nType; + int16 m_farAway; + CVector m_vecPosn; + CEntity* m_pEntity; + + void Update(); + void AddToList(CMovingThing *pThing); + void RemoveFromList(); + int16 SizeList(); +}; + +#define NUMMOVINGTHINGS 48 + +class CMovingThings +{ +public: + static CMovingThing StartCloseList; + static CMovingThing EndCloseList; + static int16 Num; + static CMovingThing aMovingThings[NUMMOVINGTHINGS]; + + static void Init(); + static void Shutdown(); + static void Update(); + static void Render(); + static void PossiblyAddThisEntity(CEntity *pEnt); + static void RegisterOne(CEntity *pEnt, uint16 nType); +}; + +class CScrollBar +{ +private: + uint8 m_Counter; + const char* m_pMessage; + CVector m_Position; + uint32 m_MessageCurrentChar; + uint32 m_MessageLength; + CVector m_Size; + float m_fIntensity; + uint8 m_MessageBar[40]; + uint8 m_Type; + bool m_bVisible; + uint8 m_uRed; + uint8 m_uGreen; + uint8 m_uBlue; + float m_fScale; + +public: + static int TonightsEvent; + +public: + void SetVisibility(bool visible) { m_bVisible = visible; } + bool IsVisible() { return m_bVisible; } + + void Init(CVector pos1, CVector pos2, uint8 type, uint8 red, uint8 green, uint8 blue, float scale); + void Update(); + void Render(); +}; + +class CSmokeTrail { + CVector m_pos[16]; + float m_opacity[16]; + int m_time[16]; + char m_unused[536]; + int m_seed; +public: + void Render(void); + void RegisterPoint(CVector position, float a); + void Init(int num); +}; + +class CSmokeTrails { + static CSmokeTrail aSmoke[3]; +public: + static bool CigOn; + static void Update(void); + static void Render(void); + static void Init(void); +}; \ No newline at end of file diff --git a/src/renderer/Font.cpp b/src/renderer/Font.cpp new file mode 100644 index 00000000..9c499248 --- /dev/null +++ b/src/renderer/Font.cpp @@ -0,0 +1,1938 @@ +#include "common.h" + +#include "Sprite2d.h" +#include "TxdStore.h" +#include "Font.h" +#ifdef BUTTON_ICONS +#include "FileMgr.h" +#endif +#include "Timer.h" + +void +AsciiToUnicode(const char *src, wchar *dst) +{ + while((*dst++ = (unsigned char)*src++) != '\0'); +} + +void +UnicodeStrcat(wchar *dst, wchar *append) +{ + UnicodeStrcpy(&dst[UnicodeStrlen(dst)], append); +} + +void +UnicodeStrcpy(wchar *dst, const wchar *src) +{ + while((*dst++ = *src++) != '\0'); +} + +int +UnicodeStrlen(const wchar *str) +{ + int len; + for(len = 0; *str != '\0'; len++, str++); + return len; +} + +void +UnicodeMakeUpperCase(wchar *dst, const wchar *src) //idk what to do with it, seems to be incorrect implementation by R* +{ + while (*src != '\0') { + if (*src < 'a' || *src > 'z') + *dst = *src; + else + *dst = *src - 32; + dst++; + src++; + } + *dst = '\0'; +} + +CFontDetails CFont::Details; +int16 CFont::NewLine; +CSprite2d CFont::Sprite[MAX_FONTS]; +CFontRenderState CFont::RenderState; + +#ifdef MORE_LANGUAGES +uint8 CFont::LanguageSet = FONT_LANGSET_EFIGS; +int32 CFont::Slot = -1; +#define JAP_TERMINATION (0x8000 | '~') + +int16 CFont::Size[LANGSET_MAX][MAX_FONTS][210] = { + { +#else +int16 CFont::Size[MAX_FONTS][210] = { +#endif + { + //FONT2 EFIGS + //SPC,!, $, %, &, ', [, ], +, , -, ., + 12, 9, 22, 17, 19, 19, 25, 4, 33, 33, 25, 35, 11, 10, 6, 33, + //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ??, + 18, 10, 17, 17, 17, 17, 17, 15, 12, 16, 5, 30, 30, 30, 30, 30, + // A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, + 12, 16, 19, 16, 19, 18, 18, 17, 22, 11, 17, 18, 18, 30, 22, 19, + //P, Q, R, S, T, U, V, W, X, Y, Z, ??, ??, ??, ¡, \, + #ifdef FIX_BUGS + 22, 19, 19, 20, 18, 19, 19, 29, 19, 18, 19, 19, 33, 33, 10, 19, + #else + 22, 19, 19, 20, 18, 19, 19, 29, 19, 18, 19, 19, 33, 33, 19, 19, + #endif + //??,a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, + 12, 14, 11, 11, 16, 11, 12, 14, 14, 10, 13, 12, 10, 19, 18, 12, + //p, q, r, s, t, u, v, w, x, y, z, ??, ??, ??, ??, ??, + 16, 13, 13, 11, 12, 15, 12, 15, 13, 12, 12, 37, 33, 37, 35, 37, + //À, Á, Â, Ä, Æ, Ç, È, É, Ê, Ë, Ì, Í, Î, Ï, Ò, Ó, + 16, 16, 16, 16, 33, 17, 18, 18, 18, 18, 11, 11, 11, 11, 19, 19, + //Ô, Ö, Ù, Ú, Û, Ü, ß, à, á, â, ä, æ, ç, è, é, ê, + 19, 19, 19, 19, 19, 19, 15, 14, 14, 14, 14, 20, 14, 11, 11, 11, + //ë, ì, í, î, ï, ò, ó, ô, ö, ù, ú, û, ü, Ñ, ñ, ¿, + #ifdef FIX_BUGS + 11, 10, 10, 10, 10, 12, 12, 12, 12, 15, 15, 15, 15, 22, 18, 21, + #else + 11, 10, 10, 10, 10, 12, 12, 12, 12, 15, 15, 15, 15, 24, 18, 21, + #endif + //i,BLANKS + 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + //space, unprop + 19, 16 + }, + { + //FONT1 EFIGS + //Characters with a '2' refer to the Pricedown font. + //Characters that are referred as '*I' are characters that contain icons for PS2/XBOX, but contain regular characters on PC + //in order to display them properly in the Keyboard controls menu. + //!2,!, *I,(R), $, %, &, ', [, ], *I, +, , -, ., *I, + 15, 7, 31, 25, 20, 23, 21, 7, 11, 10, 26, 14, 6, 12, 6, 26, + //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, *I, *I, *I, *I, ?, + 20, 7, 20, 20, 21, 20, 20, 19, 21, 20, 8, 30, 24, 30, 24, 19, + //TM,A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, + 20, 22, 22, 21, 22, 18, 18, 22, 22, 9, 14, 21, 18, 27, 21, 24, + //P, Q, R, S, T, U, V, W, X, Y, Z, *I, \, *I, ¡, °, + #ifdef FIX_BUGS + 22, 22, 23, 20, 19, 23, 22, 31, 23, 23, 21, 25, 13, 30, 7, 19, + #else + 22, 22, 23, 20, 19, 23, 22, 31, 23, 23, 21, 25, 13, 30, 10, 19, + #endif + //(C),a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, + 10, 17, 17, 16, 17, 17, 11, 17, 17, 7, 7, 18, 7, 25, 17, 17, + //p, q, r, s, t, u, v, w, x, y, z, *I, *I, $2, (2, )2, + 17, 17, 11, 17, 11, 17, 18, 25, 19, 18, 17, 28, 26, 20, 15, 15, + //À, Á, Â, Ä, Æ, Ç, È, É, Ê, Ë, Ì, Í, Î, Ï, Ò, Ó, + 20, 20, 20, 20, 29, 22, 19, 19, 19, 19, 9, 9, 9, 9, 23, 23, + //Ô, Ö, Ù, Ú, Û, Ü, ß, à, á, â, ä, æ, ç, è, é, ê, + 23, 23, 24, 24, 24, 24, 20, 19, 17, 17, 17, 30, 16, 17, 17, 17, + //ë, ì, í, î, ï, ò, ó, ô, ö, ù, ú, û, ü, Ñ, ñ, ¿, + #ifdef FIX_BUGS + 17, 11, 11, 15, 12, 17, 17, 17, 17, 17, 17, 17, 17, 21, 17, 19, + #else + 17, 11, 11, 15, 12, 17, 17, 17, 17, 17, 17, 17, 17, 19, 20, 20, + #endif + //02,12,22, 32, 42, 52, 62, 72, 82, 92, :2, A2, B2, C2, D2, E2, + 20, 18, 19, 19, 21, 19, 19, 19, 19, 19, 16, 19, 19, 19, 20, 19, + //F2,G2,H2, I2, J2, K2, L2, M2, N2, O2, P2, Q2, R2, S2, T2, U2, + 16, 19, 19, 9, 19, 20, 14, 29, 19, 19, 19, 19, 19, 19, 21, 19, + //V2,W2,X2, Y2, Z2, À2, Á2, Â2, Ä2, Æ2, Ç2, È2, É2, Ê2, Ë2, Ì2, + 20, 32, 20, 19, 19, 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, + //Í2,Î2,Ï2, Ò2, Ó2, Ô2, Ö2, Ù2, Ú2, Û2, Ü2, ß2, Ñ2, ¿2, '2, .2, + #ifdef FIX_BUGS + 9, 9, 9, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 10, 9, + #else + 9, 9, 9, 19, 19, 19, 19, 19, 19, 19, 19, 19, 21, 21, 10, 9, + #endif + //space, unprop + 10, 20 + } + +#ifdef MORE_LANGUAGES + }, + { + { + 5, 9, 9, 0, 17, 17, 23, 3, 21, 18, 0, 8, 3, 8, 3, 0, + 16, 9, 16, 16, 15, 19, 15, 14, 17, 17, 4, 4, 0, 0, 0, 17, + 19, 17, 19, 15, 21, 18, 19, 16, 21, 13, 15, 21, 20, 28, 21, 18, + 22, 17, 21, 20, 18, 18, 20, 26, 22, 18, 18, 0, 8, 0, 9, 8, + 0, 14, 11, 12, 16, 11, 13, 13, 15, 10, 14, 15, 11, 21, 17, 10, + 20, 15, 12, 12, 16, 17, 13, 16, 13, 21, 11, 0, 0, 0, 0, 0, + 20, 19, 19, 22, 27, 15, 18, 18, 20, 26, 21, 23, 17, 22, 21, 17, + 26, 25, 26, 17, 20, 26, 17, 16, 11, 12, 13, 21, 11, 17, 17, 12, + 21, 17, 17, 15, 24, 16, 10, 20, 23, 16, 7, 9, 16, 23, 12, 11, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, + 19, 16 + }, + { + 11, 5, 10, 15, 19, 22, 20, 5, 9, 8, 11, 12, 5, 12, 6, 12, + 19, 5, 18, 19, 20, 18, 19, 18, 20, 19, 5, 6, 26, 12, 30, 19, + 23, 21, 20, 20, 20, 16, 16, 21, 19, 5, 13, 19, 16, 24, 20, 21, + 20, 21, 20, 19, 17, 20, 21, 30, 22, 21, 20, 25, 13, 30, 5, 9, + 10, 15, 15, 14, 15, 16, 10, 15, 15, 5, 5, 15, 5, 23, 15, 16, + 15, 15, 9, 16, 10, 15, 17, 24, 18, 15, 15, 27, 5, 19, 2, 2, + 20, 20, 16, 23, 30, 19, 20, 20, 21, 24, 19, 19, 20, 23, 22, 19, + 27, 29, 25, 20, 20, 28, 24, 16, 16, 14, 19, 25, 16, 16, 16, 17, + 19, 16, 16, 17, 25, 19, 15, 23, 26, 21, 16, 14, 22, 20, 16, 19, + 15, 14, 15, 16, 17, 15, 15, 15, 15, 15, 7, 15, 15, 15, 15, 15, + 13, 15, 15, 7, 15, 16, 13, 23, 15, 15, 15, 15, 15, 15, 17, 15, + 16, 24, 17, 17, 17, 15, 15, 13, 20, 23, 15, 17, 17, 16, 24, 15, + 15, 15, 23, 18, 15, 23, 26, 23, 16, 15, 23, 15, 15, 19, 2, 2, + 10, 20 + }, + }, + { + { + //FONT2 EFIGS + //SPC,!, $, %, &, ', [, ], +, , -, ., + 12, 9, 22, 17, 19, 19, 25, 4, 33, 33, 25, 35, 11, 10, 6, 33, + //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ??, + 18, 10, 17, 17, 17, 17, 17, 15, 12, 16, 5, 30, 30, 30, 30, 30, + // A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, + 12, 16, 19, 16, 19, 18, 18, 17, 22, 11, 17, 18, 18, 30, 22, 19, + //P, Q, R, S, T, U, V, W, X, Y, Z, ??, ??, ??, ¡, \, + 22, 19, 19, 20, 18, 19, 19, 29, 19, 18, 19, 19, 33, 33, 10, 19, + //??,a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, + 12, 14, 11, 11, 16, 11, 12, 14, 14, 10, 13, 12, 10, 19, 18, 12, + //p, q, r, s, t, u, v, w, x, y, z, ??, ??, ??, ??, ??, + 16, 13, 13, 11, 12, 15, 12, 15, 13, 12, 12, 37, 33, 37, 35, 37, + //À, Á, Â, Ä, Æ, Ç, È, É, Ê, Ë, Ì, Í, Î, Ï, Ò, Ó, + 16, 16, 16, 16, 33, 17, 18, 18, 18, 18, 11, 11, 11, 11, 19, 19, + //Ô, Ö, Ù, Ú, Û, Ü, ß, à, á, â, ä, æ, ç, è, é, ê, + 19, 19, 19, 19, 19, 19, 15, 14, 14, 14, 14, 20, 14, 11, 11, 11, + //ë, ì, í, î, ï, ò, ó, ô, ö, ù, ú, û, ü, Ñ, ñ, ¿, + 11, 10, 10, 10, 10, 12, 12, 12, 12, 15, 15, 15, 15, 22, 18, 21, + //i,BLANKS + 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + //space, unprop + 19, 16 + }, + { + //FONT1 EFIGS + //Characters with a '2' refer to the Pricedown font. + //Characters that are referred as '*I' are characters that contain icons for PS2/XBOX, but contain regular characters on PC + //in order to display them properly in the Keyboard controls menu. + //!2,!, *I,(R), $, %, &, ', [, ], *I, +, , -, ., *I, + 15, 7, 31, 25, 20, 23, 21, 7, 11, 10, 26, 14, 6, 12, 6, 26, + //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, *I, *I, *I, *I, ?, + 20, 7, 20, 20, 21, 20, 20, 19, 21, 20, 8, 30, 24, 30, 24, 19, + //TM,A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, + 20, 22, 22, 21, 22, 18, 18, 22, 22, 9, 14, 21, 18, 27, 21, 24, + //P, Q, R, S, T, U, V, W, X, Y, Z, *I, \, *I, ¡, °, + 22, 22, 23, 20, 19, 23, 22, 31, 23, 23, 21, 25, 13, 30, 7, 19, + //(C),a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, + 10, 17, 17, 16, 17, 17, 11, 17, 17, 7, 7, 18, 7, 25, 17, 17, + //p, q, r, s, t, u, v, w, x, y, z, *I, *I, $2, (2, )2, + 17, 17, 11, 17, 11, 17, 18, 25, 19, 18, 17, 28, 26, 20, 15, 15, + //À, Á, Â, Ä, Æ, Ç, È, É, Ê, Ë, Ì, Í, Î, Ï, Ò, Ó, + 20, 20, 20, 20, 29, 22, 19, 19, 19, 19, 9, 9, 9, 9, 23, 23, + //Ô, Ö, Ù, Ú, Û, Ü, ß, à, á, â, ä, æ, ç, è, é, ê, + 23, 23, 24, 24, 24, 24, 20, 19, 17, 17, 17, 30, 16, 17, 17, 17, + //ë, ì, í, î, ï, ò, ó, ô, ö, ù, ú, û, ü, Ñ, ñ, ¿, + 17, 11, 11, 15, 12, 17, 17, 17, 17, 17, 17, 17, 17, 21, 17, 19, + //02,12,22, 32, 42, 52, 62, 72, 82, 92, :2, A2, B2, C2, D2, E2, + 20, 18, 19, 19, 21, 19, 19, 19, 19, 19, 16, 19, 19, 19, 20, 19, + //F2,G2,H2, I2, J2, K2, L2, M2, N2, O2, P2, Q2, R2, S2, T2, U2, + 16, 19, 19, 9, 19, 20, 14, 29, 19, 19, 19, 19, 19, 19, 21, 19, + //V2,W2,X2, Y2, Z2, À2, Á2, Â2, Ä2, Æ2, Ç2, È2, É2, Ê2, Ë2, Ì2, + 20, 32, 20, 19, 19, 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, + //Í2,Î2,Ï2, Ò2, Ó2, Ô2, Ö2, Ù2, Ú2, Û2, Ü2, ß2, Ñ2, ¿2, '2, .2, + 9, 9, 9, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 10, 9, + //space, unprop + 10, 20 + } + } +#endif +}; + +#ifdef MORE_LANGUAGES +int16 Size_jp[] = { + 15, 14, 16, 20, 19, 26, 22, 11, 18, 18, 27, 26, 13, //; 0 + 19, 20, 27, 19, 15, 19, 19, 21, 19, 20, 18, 19, 15, //; 13 + 13, 28, 15, 32, 15, 35, 15, 19, 19, 19, 19, 17, 16, //; 26 + 19, 20, 15, 19, 20, 14, 17, 19, 19, 19, 19, 19, 19, //; 39 + 19, 19, 20, 25, 20, 19, 19, 33, 31, 39, 37, 39, 37, //; 52 + 21, 21, 21, 19, 17, 15, 23, 21, 15, 19, 20, 16, 19, //; 65 + 19, 19, 20, 20, 17, 22, 19, 22, 22, 19, 22, 22, 23, //; 78 + 35, 35, 35, 35, 37, 19, 19, 19, 19, 29, 19, 19, 19, //; 91 + 19, 19, 9, 9, 9, 9, 19, 19, 19, 19, 19, 19, 19, 19, //; 104 + 19, 19, 19, 19, 19, 30, 19, 19, 19, 19, 19, 10, 10, //; 118 + 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35, //; 131 + 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 144 + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 157 + 19, 19, 19, 11, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 170 + 19, 19, 19, 19, 19, 19, 19, 19, 19, 21 +}; +#endif + +wchar foreign_table[128] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 176, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 177, 0, 0, 0, 0, 0, 95, 0, 0, 0, 0, 175, + 128, 129, 130, 0, 131, 0, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, + 0, 173, 142, 143, 144, 0, 145, 0, 0, 146, 147, 148, 149, 0, 0, 150, + 151, 152, 153, 0, 154, 0, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, + 0, 174, 165, 166, 167, 0, 168, 0, 0, 169, 170, 171, 172, 0, 0, 0, +}; + +union tFontRenderStatePointer +{ + CFontRenderState *pRenderState; + wchar *pStr; + + void Align() + { + if ((uintptr)pStr % 4) + pStr++; + } +}; + +tFontRenderStatePointer FontRenderStatePointer; +uint8 FontRenderStateBuf[1024]; + +#ifdef BUTTON_ICONS +CSprite2d CFont::ButtonSprite[MAX_BUTTON_ICONS]; +int CFont::PS2Symbol = BUTTON_NONE; +int CFont::ButtonsSlot = -1; +#endif // BUTTON_ICONS + +void +CFont::Initialise(void) +{ + int slot; + + slot = CTxdStore::AddTxdSlot("fonts"); +#ifdef MORE_LANGUAGES + Slot = slot; + switch (LanguageSet) + { + case FONT_LANGSET_EFIGS: + default: + CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD"); + break; + case FONT_LANGSET_POLISH: + CTxdStore::LoadTxd(slot, "MODELS/FONTS_P.TXD"); + break; + case FONT_LANGSET_RUSSIAN: + CTxdStore::LoadTxd(slot, "MODELS/FONTS_R.TXD"); + break; + case FONT_LANGSET_JAPANESE: + CTxdStore::LoadTxd(slot, "MODELS/FONTS_J.TXD"); + break; + } +#else + CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD"); +#endif + CTxdStore::AddRef(slot); + CTxdStore::PushCurrentTxd(); + CTxdStore::SetCurrentTxd(slot); + Sprite[0].SetTexture("font2", "font2m"); +#ifdef MORE_LANGUAGES + if (IsJapanese()) { + Sprite[1].SetTexture("FONTJAP", "FONTJAP_mask"); + Sprite[3].SetTexture("FONTJAP", "FONTJAP_mask"); + } +#endif // MORE_LANGUAGES + Sprite[1].SetTexture("font1", "font1m"); + SetScale(1.0f, 1.0f); + SetSlantRefPoint(SCREEN_WIDTH, 0.0f); + SetSlant(0.0f); + SetColor(CRGBA(255, 255, 255, 0)); + SetJustifyOff(); + SetCentreOff(); + SetWrapx(SCREEN_WIDTH); + SetCentreSize(SCREEN_WIDTH); + SetBackgroundOff(); + SetBackgroundColor(CRGBA(128, 128, 128, 128)); + SetBackGroundOnlyTextOff(); + SetPropOn(); + SetFontStyle(FONT_BANK); + SetRightJustifyWrap(0.0f); + SetAlphaFade(255.0f); + SetDropShadowPosition(0); + CTxdStore::PopCurrentTxd(); + +#if !defined(GAMEPAD_MENU) && defined(BUTTON_ICONS) + // loaded in CMenuManager with GAMEPAD_MENU defined + LoadButtons("MODELS/X360BTNS.TXD"); +#endif +} + +#ifdef BUTTON_ICONS +void +CFont::LoadButtons(const char *txdPath) +{ + if (int file = CFileMgr::OpenFile(txdPath)) { + CFileMgr::CloseFile(file); + if (ButtonsSlot == -1) + ButtonsSlot = CTxdStore::AddTxdSlot("buttons"); + else { + for (int i = 0; i < MAX_BUTTON_ICONS; i++) + ButtonSprite[i].Delete(); + CTxdStore::RemoveTxd(ButtonsSlot); + } + CTxdStore::LoadTxd(ButtonsSlot, txdPath); + CTxdStore::AddRef(ButtonsSlot); + CTxdStore::PushCurrentTxd(); + CTxdStore::SetCurrentTxd(ButtonsSlot); + ButtonSprite[BUTTON_UP].SetTexture("thumblyu"); + ButtonSprite[BUTTON_DOWN].SetTexture("thumblyd"); + ButtonSprite[BUTTON_LEFT].SetTexture("thumblxl"); + ButtonSprite[BUTTON_RIGHT].SetTexture("thumblxr"); + ButtonSprite[BUTTON_CROSS].SetTexture("cross"); + ButtonSprite[BUTTON_CIRCLE].SetTexture("circle"); + ButtonSprite[BUTTON_SQUARE].SetTexture("square"); + ButtonSprite[BUTTON_TRIANGLE].SetTexture("triangle"); + ButtonSprite[BUTTON_L1].SetTexture("l1"); + ButtonSprite[BUTTON_L2].SetTexture("l2"); + ButtonSprite[BUTTON_L3].SetTexture("l3"); + ButtonSprite[BUTTON_R1].SetTexture("r1"); + ButtonSprite[BUTTON_R2].SetTexture("r2"); + ButtonSprite[BUTTON_R3].SetTexture("r3"); + ButtonSprite[BUTTON_RSTICK_UP].SetTexture("thumbryu"); + ButtonSprite[BUTTON_RSTICK_DOWN].SetTexture("thumbryd"); + ButtonSprite[BUTTON_RSTICK_LEFT].SetTexture("thumbrxl"); + ButtonSprite[BUTTON_RSTICK_RIGHT].SetTexture("thumbrxr"); + CTxdStore::PopCurrentTxd(); + } + else { + if (ButtonsSlot != -1) { + for (int i = 0; i < MAX_BUTTON_ICONS; i++) + ButtonSprite[i].Delete(); + CTxdStore::RemoveTxdSlot(ButtonsSlot); + ButtonsSlot = -1; + } + } +} +#endif // BUTTON_ICONS + +#ifdef MORE_LANGUAGES +void +CFont::ReloadFonts(uint8 set) +{ + if (Slot != -1 && LanguageSet != set) { + Sprite[0].Delete(); + Sprite[1].Delete(); + if (IsJapanese()) + Sprite[2].Delete(); + CTxdStore::PushCurrentTxd(); + CTxdStore::RemoveTxd(Slot); + switch (set) + { + case FONT_LANGSET_EFIGS: + default: + CTxdStore::LoadTxd(Slot, "MODELS/FONTS.TXD"); + break; + case FONT_LANGSET_POLISH: + CTxdStore::LoadTxd(Slot, "MODELS/FONTS_P.TXD"); + break; + case FONT_LANGSET_RUSSIAN: + CTxdStore::LoadTxd(Slot, "MODELS/FONTS_R.TXD"); + break; + case FONT_LANGSET_JAPANESE: + CTxdStore::LoadTxd(Slot, "MODELS/FONTS_J.TXD"); + break; + } + CTxdStore::SetCurrentTxd(Slot); + Sprite[0].SetTexture("font2", "font2_mask"); + if (set == FONT_LANGSET_JAPANESE) { + Sprite[2].SetTexture("FONTJAP", "FONTJAP_mask"); + } + Sprite[1].SetTexture("font1", "font1_mask"); + CTxdStore::PopCurrentTxd(); + } + LanguageSet = set; +} +#endif + +void +CFont::Shutdown(void) +{ +#ifdef BUTTON_ICONS + if (ButtonsSlot != -1) { + for (int i = 0; i < MAX_BUTTON_ICONS; i++) + ButtonSprite[i].Delete(); + CTxdStore::RemoveTxdSlot(ButtonsSlot); + ButtonsSlot = -1; + } +#endif + Sprite[0].Delete(); + Sprite[1].Delete(); +#ifdef MORE_LANGUAGES + if (IsJapanese()) + Sprite[3].Delete(); + CTxdStore::RemoveTxdSlot(Slot); + Slot = -1; +#else + CTxdStore::RemoveTxdSlot(CTxdStore::FindTxdSlot("fonts")); +#endif +} + +void +CFont::InitPerFrame(void) +{ + RenderState.style = -1; + Details.anonymous_25 = 0; + FontRenderStatePointer.pRenderState = (CFontRenderState*)FontRenderStateBuf; + SetDropShadowPosition(0); + NewLine = false; +#ifdef BUTTON_ICONS + PS2Symbol = BUTTON_NONE; +#endif +} + +#ifdef BUTTON_ICONS +void +CFont::DrawButton(float x, float y) +{ + if (x <= 0.0f || x > SCREEN_WIDTH || y <= 0.0f || y > SCREEN_HEIGHT) + return; + + if (PS2Symbol != BUTTON_NONE) { + CRect rect; + rect.left = x; + rect.top = RenderState.scaleY + RenderState.scaleY + y; + rect.right = RenderState.scaleY * 17.0f + x; + rect.bottom = RenderState.scaleY * 19.0f + y; + + int vertexAlphaState; + void *raster; + RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &vertexAlphaState); + RwRenderStateGet(rwRENDERSTATETEXTURERASTER, &raster); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); + if (RenderState.bIsShadow) + ButtonSprite[PS2Symbol].Draw(rect, RenderState.color); + else + ButtonSprite[PS2Symbol].Draw(rect, CRGBA(255, 255, 255, RenderState.color.a)); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, raster); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)vertexAlphaState); + } +} +#endif + +void +CFont::PrintChar(float x, float y, wchar c) +{ + bool bDontPrint = false; + if(x <= 0.0f || x > SCREEN_WIDTH || + y <= 0.0f || y > SCREEN_HEIGHT) // BUG: game uses SCREENW again + return; + + bDontPrint = c == '\0'; + float w = GetCharacterWidth(c) / 32.0f; + if (Details.bFontHalfTexture && c == 208) + c = '\0'; + float xoff = c % 16; + float yoff = c / 16; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) { + w = 21.0f; + xoff = (float)(c % 48); + yoff = c / 48; + } +#endif + + if(RenderState.style == FONT_BANK || RenderState.style == FONT_STANDARD){ + if (bDontPrint) return; + if (RenderState.slant == 0.0f) { +#ifdef FIX_BUGS + if (c < 192) { +#else + if (c < 193) { +#endif + CSprite2d::AddToBuffer( + CRect(x, y, + x + 32.0f * RenderState.scaleX * 1.0f, + y + 40.0f * RenderState.scaleY * 0.5f), + RenderState.color, + xoff / 16.0f, yoff / 12.8f + 0.0021f, + (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f, + xoff / 16.0f, (yoff + 1.0f) / 12.8f - 0.0021f, + (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f - 0.0021f); + } else { + CSprite2d::AddToBuffer( + CRect(x, y, + x + 32.0f * RenderState.scaleX * 1.0f, + y + 33.0f * RenderState.scaleY * 0.5f), + RenderState.color, + xoff / 16.0f, yoff / 12.8f + 0.0021f, + (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f, + xoff / 16.0f, (yoff + 1.0f) / 12.8f - 0.017f, + (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f - 0.017f); + } + } else + CSprite2d::AddToBuffer( + CRect(x, y, + x + 32.0f * RenderState.scaleX * 1.0f, + y + 40.0f * RenderState.scaleY * 0.5f), + RenderState.color, + xoff / 16.0f, yoff / 12.8f + 0.00055f, + (xoff + 1.0f) / 16.0f - 0.001f, yoff / 12.8f + 0.0021f + 0.01f, + xoff / 16.0f, (yoff + 1.0f) / 12.8f - 0.009f, + (xoff + 1.0f) / 16.0f - 0.001f, (yoff + 1.0f) / 12.8f - 0.0021f + 0.01f); +#ifdef MORE_LANGUAGES + /*}else if (IsJapaneseFont()) { + if (Details.dropShadowPosition != 0) { + CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank + CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition), + y + SCREEN_SCALE_Y(Details.dropShadowPosition), + x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f, + y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY / 2.75f), + Details.dropColor, + xoff * w / 1024.0f, yoff / 25.6f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, yoff / 25.6f, + xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f); + } + CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank + CRect(x, y, + x + 32.0f * Details.scaleX * 1.0f, + y + 40.0f * Details.scaleY / 2.75f), + Details.color, + xoff * w / 1024.0f, yoff / 25.6f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, yoff / 25.6f, + xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f - 0.002f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f);*/ +#endif + } else { + if (bDontPrint) return; + CSprite2d::AddToBuffer( + CRect(x, y, + x + 32.0f * RenderState.scaleX * w, + y + 32.0f * RenderState.scaleY * 0.5f), + RenderState.color, + xoff / 16.0f, yoff / 16.0f, + (xoff + w) / 16.0f, yoff / 16.0f, + xoff / 16.0f, (yoff + 1.0f) / 16.0f, + (xoff + w) / 16.0f - 0.0001f, (yoff + 1.0f) / 16.0f - 0.0001f); + } +} + +#ifdef MORE_LANGUAGES +bool CFont::IsJapanesePunctuation(wchar *str) +{ + return (*str == 0xE7 || *str == 0x124 || *str == 0x126 || *str == 0x128 || *str == 0x104 || *str == ',' || *str == '>' || *str == '!' || *str == 0x99 || *str == '?' || *str == ':'); +} + +bool CFont::IsAnsiCharacter(wchar *s) +{ + if (*s >= 'A' && *s <= 'Z') + return true; + if (*s >= 'a' && *s <= 'z') + return true; + if (*s >= '0' && *s <= ':') + return true; + if (*s == '(' || *s == ')') + return true; + if (*s == 'D' || *s == '$') + return true; + return false; +} +#endif + +void +CFont::RenderFontBuffer() +{ + if (FontRenderStatePointer.pRenderState == (CFontRenderState*)FontRenderStateBuf) return; + + float textPosX; + float textPosY; + CRGBA color; + bool bBold = false; + bool bFlash = false; + + Sprite[RenderState.style].SetRenderState(); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RenderState = *(CFontRenderState*)&FontRenderStateBuf[0]; + textPosX = RenderState.fTextPosX; + textPosY = RenderState.fTextPosY; + color = RenderState.color; + tFontRenderStatePointer pRenderStateBufPointer; + pRenderStateBufPointer.pRenderState = (CFontRenderState*)&FontRenderStateBuf[0]; + for (++pRenderStateBufPointer.pRenderState; pRenderStateBufPointer.pStr < FontRenderStatePointer.pStr; pRenderStateBufPointer.pStr++) { + if (*pRenderStateBufPointer.pStr == '\0') { + tFontRenderStatePointer tmpPointer = pRenderStateBufPointer; + tmpPointer.pStr++; + tmpPointer.Align(); + if (tmpPointer.pStr >= FontRenderStatePointer.pStr) + break; + + RenderState = *(tmpPointer.pRenderState++); + + pRenderStateBufPointer = tmpPointer; + + textPosX = RenderState.fTextPosX; + textPosY = RenderState.fTextPosY; + color = RenderState.color; + } + if (*pRenderStateBufPointer.pStr == '~') { +#ifdef BUTTON_ICONS + PS2Symbol = BUTTON_NONE; +#endif + pRenderStateBufPointer.pStr = ParseToken(pRenderStateBufPointer.pStr, color, bFlash, bBold); +#ifdef BUTTON_ICONS + if(PS2Symbol != BUTTON_NONE) { + DrawButton(textPosX, textPosY); + textPosX += RenderState.scaleY * 17.0f; + PS2Symbol = BUTTON_NONE; + } +#endif + if (bFlash) { + if (CTimer::GetTimeInMilliseconds() - Details.nFlashTimer > 300) { + Details.bFlashState = !Details.bFlashState; + Details.nFlashTimer = CTimer::GetTimeInMilliseconds(); + } + Details.color.alpha = Details.bFlashState ? 0 : 255; + } + if (!RenderState.bIsShadow) + RenderState.color = color; + } + wchar c = *pRenderStateBufPointer.pStr; + c -= ' '; + if (RenderState.bFontHalfTexture) + c = FindNewCharacter(c); + else if (c > 155) + c = '\0'; + + if (RenderState.slant != 0.0f) + textPosY = (RenderState.slantRefX - textPosX) * RenderState.slant + RenderState.slantRefY; + PrintChar(textPosX, textPosY, c); + if (bBold) { + PrintChar(textPosX + 1.0f, textPosY, c); + PrintChar(textPosX + 2.0f, textPosY, c); + textPosX += 2.0f; + } +#ifdef FIX_BUGS + // PS2 uses different chars for some symbols + if (!RenderState.bFontHalfTexture && c == 30) c = 61; // wanted star +#endif + textPosX += RenderState.scaleX * GetCharacterWidth(c); + if (c == '\0') + textPosX += RenderState.fExtraSpace; + } + CSprite2d::RenderVertexBuffer(); + FontRenderStatePointer.pRenderState = (CFontRenderState*)FontRenderStateBuf; +} + +#if 0 //def MORE_LANGUAGES +bool +CFont::PrintString(float x, float y, wchar *start, wchar *&end, float spwidth, float japX) +{ + wchar *s, c, unused; + + if (IsJapanese()) { + float jx = 0.0f; + for (s = start; s < end; s++) { + if (*s == JAP_TERMINATION || *s == '~') + s = ParseToken(s, &unused, true); + if (NewLine) { + NewLine = false; + break; + } + jx += GetCharacterSize(*s - ' '); + } + s = start; + if (Details.centre) + x = japX - jx / 2.0f; + else if (Details.rightJustify) + x = japX - jx; + } + + for (s = start; s < end; s++) { + if (*s == '~' || (IsJapanese() && *s == JAP_TERMINATION)) + s = ParseToken(s, &unused); + if (NewLine && IsJapanese()) { + NewLine = false; + end = s; + return true; + } + c = *s - ' '; + if (Details.slant != 0.0f && !IsJapanese()) + y = (Details.slantRefX - x) * Details.slant + Details.slantRefY; + + PrintChar(x, y, c); + x += GetCharacterSize(c); + if (c == 0 && (!NewLine || !IsJapanese())) // space + x += spwidth; + } + return false; +} +#else +void +CFont::PrintString(float x, float y, uint32, wchar *start, wchar *end, float spwidth) +{ + wchar *s; + + if (RenderState.style != Details.style) { + RenderFontBuffer(); + RenderState.style = Details.style; + } + + float dropShadowPosition = Details.dropShadowPosition; + if (dropShadowPosition != 0.0f && (Details.style == FONT_BANK || Details.style == FONT_STANDARD)) { + CRGBA color = Details.color; + Details.color = Details.dropColor; + Details.dropShadowPosition = 0; + Details.bIsShadow = true; + if (Details.slant != 0.0f) { + Details.slantRefX += SCREEN_SCALE_X(dropShadowPosition); + Details.slantRefY += SCREEN_SCALE_Y(dropShadowPosition); + PrintString(SCREEN_SCALE_X(dropShadowPosition) + x, SCREEN_SCALE_Y(dropShadowPosition) + y, Details.anonymous_25, start, end, spwidth); + Details.slantRefX -= SCREEN_SCALE_X(dropShadowPosition); + Details.slantRefY -= SCREEN_SCALE_Y(dropShadowPosition); + } else { + PrintString(SCREEN_SCALE_X(dropShadowPosition) + x, SCREEN_SCALE_Y(dropShadowPosition) + y, Details.anonymous_25, start, end, spwidth); + } + Details.color = color; + Details.dropShadowPosition = dropShadowPosition; + Details.bIsShadow = false; + } + if (FontRenderStatePointer.pStr >= (wchar*)&FontRenderStateBuf[ARRAY_SIZE(FontRenderStateBuf)] - (end - start + 26)) // why 26? + RenderFontBuffer(); + CFontRenderState *pRenderState = FontRenderStatePointer.pRenderState; + pRenderState->fTextPosX = x; + pRenderState->fTextPosY = y; + pRenderState->scaleX = Details.scaleX; + pRenderState->scaleY = Details.scaleY; + pRenderState->color = Details.color; + pRenderState->fExtraSpace = spwidth; + pRenderState->slant = Details.slant; + pRenderState->slantRefX = Details.slantRefX; + pRenderState->slantRefY = Details.slantRefY; + pRenderState->bFontHalfTexture = Details.bFontHalfTexture; + pRenderState->proportional = Details.proportional; + pRenderState->style = Details.style; + pRenderState->bIsShadow = Details.bIsShadow; + FontRenderStatePointer.pRenderState++; + + for(s = start; s < end;){ + if (*s == '~') { + for (wchar *i = ParseToken(s); s != i; FontRenderStatePointer.pStr++) { + *FontRenderStatePointer.pStr = *(s++); + } + if (Details.bFlash) { + if (CTimer::GetTimeInMilliseconds() - Details.nFlashTimer > 300) { + Details.bFlashState = !Details.bFlashState; + Details.nFlashTimer = CTimer::GetTimeInMilliseconds(); + } + Details.color.a = Details.bFlashState ? 0 : 255; + } + } else + *(FontRenderStatePointer.pStr++) = *(s++); + } + *(FontRenderStatePointer.pStr++) = '\0'; + FontRenderStatePointer.Align(); +} +#endif + +void +CFont::PrintStringFromBottom(float x, float y, wchar *str) +{ + y -= (32.0f * Details.scaleY / 2.0f + 2.0f * Details.scaleY) * GetNumberLines(x, y, str); + if (Details.slant != 0.0f) + y -= ((Details.slantRefX - x) * Details.slant + Details.slantRefY); + PrintString(x, y, str); +} + +void +CFont::PrintString(float xstart, float ystart, wchar *s) +{ + CRect rect; + int numSpaces; + float lineLength; + float x, y; + bool first; + wchar *start, *t; + + Details.bFlash = false; + + if(*s == '*') + return; + + Details.anonymous_25++; + if(Details.background){ + RenderState.color = Details.color; + GetNumberLines(xstart, ystart, s); // BUG: result not used + GetTextRect(&rect, xstart, ystart, s); + CSprite2d::DrawRect(rect, Details.backgroundColor); + } + + lineLength = 0.0f; + numSpaces = 0; + first = true; + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; + y = ystart; + start = s; + + // This is super ugly, I blame R* + for(;;){ + for(;;){ + for(;;){ + if(*s == '\0') + return; + float xend = Details.centre ? Details.centreSize : + Details.rightJustify ? xstart - Details.rightJustifyWrap : + Details.wrapX; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) + xend -= SCREEN_SCALE_X(21.0f * 2.0f); +#endif + if(x + GetStringWidth(s) > xend && !first){ +#ifdef MORE_LANGUAGES + if (IsJapanese() && IsJapanesePunctuation(s)) + s--; +#endif + // flush line + float spaceWidth = !Details.justify || Details.centre ? 0.0f : + (Details.wrapX - lineLength) / numSpaces; + float xleft = Details.centre ? xstart - x/2 : + Details.rightJustify ? xstart - x : + xstart; +#if 0//def MORE_LANGUAGES + PrintString(xleft, y, start, s, spaceWidth, xstart); +#else + PrintString(xleft, y, Details.anonymous_25, start, s, spaceWidth); +#endif + // reset things + lineLength = 0.0f; + numSpaces = 0; + first = true; + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) + y += 32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY; + else +#endif + y += 32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY; + start = s; + }else + break; + } + // advance by one word + t = GetNextSpace(s); + if(t[0] == '\0' || + t[0] == ' ' && t[1] == '\0') + break; + if(!first) + numSpaces++; + first = false; + x += GetStringWidth(s) + GetCharacterSize(*t - ' '); +#ifdef MORE_LANGUAGES + if (IsJapaneseFont() && IsAnsiCharacter(s)) + x += 21.0f; +#endif + lineLength = x; + s = t+1; +#if 0 //def MORE_LANGUAGES + if (IsJapaneseFont() && !*s) { + x += GetStringWidth(s); + if (IsAnsiCharacter(s)) + x += 21.0f; + float xleft = Details.centre ? xstart - x / 2 : + Details.rightJustify ? xstart - x : + xstart; + if (PrintString(xleft, y, start, s, 0.0f, xstart)) + { + start = s; + if (!Details.centre && !Details.rightJustify) + x = xstart; + else + x = 0.0f; + + y += 32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY; + numSpaces = 0; + first = true; + lineLength = 0.0f; + } + } +#endif + } + // print rest + if(t[0] == ' ' && t[1] == '\0') + t[0] = '\0'; + x += GetStringWidth(s); + s = t; + float xleft = Details.centre ? xstart - x/2 : + Details.rightJustify ? xstart - x : + xstart; +#if 0 //def MORE_LANGUAGES + if (PrintString(xleft, y, start, s, 0.0f, xstart) && IsJapaneseFont()) { + start = s; + if (!Details.centre && !Details.rightJustify) + x = xstart; + else + x = 0.0f; + y += 32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY; + numSpaces = 0; + first = true; + lineLength = 0.0f; + } +#else + PrintString(xleft, y, Details.anonymous_25, start, s, 0.0f); +#endif + } +} + +int +CFont::GetNumberLines(float xstart, float ystart, wchar *s) +{ + int n; + float x, y; + wchar *t; + n = 0; + +#if 0//def MORE_LANGUAGES + bool bSomeJapBool = false; + + if (IsJapanese()) { + t = s; + wchar unused; + while (*t) { + if (*t == JAP_TERMINATION || *t == '~') + t = ParseToken(t, &unused, true); + if (NewLine) { + n++; + NewLine = false; + bSomeJapBool = true; + } + t++; + } + } + + if (bSomeJapBool) n--; +#endif + + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; + y = ystart; + + while(*s){ +#ifdef FIX_BUGS + float f = Details.centre ? Details.centreSize : + Details.rightJustify ? xstart - Details.rightJustifyWrap : + Details.wrapX; +#else + float f = (Details.centre ? Details.centreSize : Details.wrapX); +#endif + +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) + f -= SCREEN_SCALE_X(21.0f * 2.0f); +#endif + + if(x + GetStringWidth(s) > f){ +#ifdef MORE_LANGUAGES + if (IsJapanese()) + { + if (IsJapanesePunctuation(s)) + s--; + } +#endif + // reached end of line + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; + n++; + // Why even? +#ifdef MORE_LANGUAGES + if (IsJapanese()) + y += 32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY; + else +#endif + y += 32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY; + }else{ + // still space in current line + t = GetNextSpace(s); + if(*t == '\0'){ + // end of string + x += GetStringWidth(s); +#ifdef MORE_LANGUAGES + if (IsJapanese() && IsAnsiCharacter(s)) + x += 21.0f; +#endif + n++; + s = t; + }else{ + x += GetStringWidth(s); +#ifdef MORE_LANGUAGES + if (IsJapanese() && IsAnsiCharacter(s)) + x += 21.0f; +#endif + s = t+1; + x += GetCharacterSize(*t - ' '); +#ifdef MORE_LANGUAGES + if (IsJapanese() && !*s) + n++; +#endif + } + } + } + + return n; +} + +void +CFont::GetTextRect(CRect *rect, float xstart, float ystart, wchar *s) +{ + int numLines; + float x, y; + int16 maxlength; + wchar *t; + + maxlength = 0; + numLines = 0; + +#ifdef MORE_LANGUAGES + if (IsJapanese()) { + numLines = GetNumberLines(xstart, ystart, s); + }else{ +#endif + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; + y = ystart; + +#ifdef FIX_BUGS + float xEnd = Details.centre ? Details.centreSize : + Details.rightJustify ? xstart - Details.rightJustifyWrap : + Details.wrapX; +#else + float xEnd = (Details.centre ? Details.centreSize : Details.wrapX); +#endif + while(*s){ + if(x + GetStringWidth(s) > xEnd){ + // reached end of line + if(x > maxlength) + maxlength = x; + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; + numLines++; + y += 32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY; + }else{ + // still space in current line + t = GetNextSpace(s); + if(*t == '\0'){ + // end of string + x += GetStringWidth(s); + if(x > maxlength) + maxlength = x; + numLines++; + s = t; + }else{ + x += GetStringWidth(s); + x += GetCharacterSize(*t - ' '); + s = t+1; + } + } + } +#ifdef MORE_LANGUAGES + } +#endif + + if(Details.centre){ + if(Details.backgroundOnlyText){ + rect->left = xstart - maxlength/2 - 4.0f; + rect->right = xstart + maxlength/2 + 4.0f; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) { + rect->bottom = (32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY) * numLines + ystart + (4.0f / 2.75f); + rect->top = ystart - (4.0f / 2.75f); + } else { +#endif + rect->bottom = (32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY) * numLines + ystart + 2.0f; + rect->top = ystart - 2.0f; +#ifdef MORE_LANGUAGES + } +#endif + }else{ + rect->left = xstart - Details.centreSize*0.5f - 4.0f; + rect->right = xstart + Details.centreSize*0.5f + 4.0f; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) { + rect->bottom = (32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY) * numLines + ystart + (4.0f / 2.75f); + rect->top = ystart - (4.0f / 2.75f); + } else { +#endif + rect->bottom = (32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY) * numLines + ystart + 2.0f; + rect->top = ystart - 2.0f; +#ifdef MORE_LANGUAGES + } +#endif + } + }else{ + rect->left = xstart - 4.0f; + rect->right = Details.wrapX; + // WTF? + rect->bottom = ystart - 4.0f + 4.0f; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) + rect->top = (32.0f * Details.scaleY / 2.75f + 2.0f * Details.scaleY) * numLines + ystart + 2.0f + (4.0f / 2.75f); + else +#endif + rect->top = (32.0f * Details.scaleY * 0.5f + 2.0f * Details.scaleY) * numLines + ystart + 2.0f + 2.0f; + } +} + +float +CFont::GetCharacterWidth(wchar c) +{ +#ifdef MORE_LANGUAGES + if (IsJapanese()) { + if (!RenderState.proportional) + return Size[0][Details.style][192]; + if (c <= 94 || Details.style == FONT_HEADING || RenderState.style == FONT_BANK) { + switch (RenderState.style) + { + case FONT_JAPANESE: + return Size_jp[c]; + default: + return Size[0][RenderState.style][c]; + } + } + + switch (RenderState.style) + { + case FONT_JAPANESE: + return 29.4f; + case FONT_BANK: + return 10.0f; + default: + return Size[0][RenderState.style][c]; + } + } + + else if (RenderState.proportional) + return Size[LanguageSet][RenderState.style][c]; + else + return Size[LanguageSet][RenderState.style][209]; +#else + + if (RenderState.proportional) + return Size[RenderState.style][c]; + else + return Size[RenderState.style][209]; +#endif // MORE_LANGUAGES +} + +float +CFont::GetCharacterSize(wchar c) +{ +#ifdef MORE_LANGUAGES + + if (IsJapanese()) + { + if (!Details.proportional) + return Size[0][Details.style][209] * Details.scaleX; + if (c <= 94 || Details.style == FONT_HEADING || Details.style == FONT_BANK) { + switch (Details.style) + { + case FONT_JAPANESE: + return Size_jp[c] * Details.scaleX; + default: + return Size[0][Details.style][c] * Details.scaleX; + } + } + + switch (Details.style) + { + case FONT_JAPANESE: + return 29.4f * Details.scaleX; + case FONT_BANK: + return 10.0f * Details.scaleX; + default: + return Size[0][Details.style][c] * Details.scaleX; + } + } + else + { + if (!Details.bFontHalfTexture && c == 30) c = 61; // wanted star + if (Details.bFontHalfTexture) + c = FindNewCharacter(c); + if (Details.proportional) + return Size[LanguageSet][Details.style][c] * Details.scaleX; + else + return Size[LanguageSet][Details.style][209] * Details.scaleX; + } +#else + +#ifdef FIX_BUGS + // PS2 don't call FindNewCharacter in here at all, and also uses different chars for some symbols + if (!Details.bFontHalfTexture && c == 30) c = 61; // wanted star +#endif + if (Details.bFontHalfTexture) + c = FindNewCharacter(c); + if (Details.proportional) + return Size[Details.style][c] * Details.scaleX; + else + return Size[Details.style][209] * Details.scaleX; +#endif // MORE_LANGUAGES +} + +float +CFont::GetStringWidth(wchar *s, bool spaces) +{ + float w; + + w = 0.0f; +#ifdef MORE_LANGUAGES + if (IsJapanese()) + { + do + { + if ((*s != ' ' || spaces) && *s != '\0') { + do { + while (*s == '~' || *s == JAP_TERMINATION) { + s++; +#ifdef BUTTON_ICONS + switch (*s) { + case 'U': + case 'D': + case '<': + case '>': + case 'X': + case 'O': + case 'Q': + case 'T': + case 'K': + case 'M': + case 'A': + case 'J': + case 'V': + case 'C': + case '(': + case ')': + w += 17.0f * Details.scaleY; + break; + default: + break; + } +#endif + while (!(*s == '~' || *s == JAP_TERMINATION)) s++; + s++; + } + w += GetCharacterSize(*s - ' '); + ++s; + } while (*s == '~' || *s == JAP_TERMINATION); + } + } while (IsAnsiCharacter(s)); + } else +#endif + { + for (wchar c = *s; (c != ' ' || spaces) && c != '\0'; c = *(++s)) { + if (c == '~') { + s++; +#ifdef BUTTON_ICONS + switch (*s) { + case 'U': + case 'D': + case '<': + case '>': + case 'X': + case 'O': + case 'Q': + case 'T': + case 'K': + case 'M': + case 'A': + case 'J': + case 'V': + case 'C': + case '(': + case ')': + w += 17.0f * Details.scaleY; + break; + default: + break; + } +#endif + while (*s != '~') { + s++; + } + } + else { + w += GetCharacterSize(c - ' '); + } + } + } + return w; +} + + +#ifdef MORE_LANGUAGES +float +CFont::GetStringWidth_Jap(wchar* s) +{ + float w; + + w = 0.0f; + for (; *s != '\0';) { + do { + while (*s == '~' || *s == JAP_TERMINATION) { + s++; + while (!(*s == '~' || *s == JAP_TERMINATION)) s++; + s++; + } + w += GetCharacterSize(*s - ' '); + ++s; + } while (*s == '~' || *s == JAP_TERMINATION); + } + return w; +} +#endif + +wchar* +CFont::GetNextSpace(wchar *s) +{ +#ifdef MORE_LANGUAGES + if (IsJapanese()) { + do + { + if (*s != ' ' && *s != '\0') { + do { + while (*s == '~' || *s == JAP_TERMINATION) { + s++; + while (!(*s == '~' || *s == JAP_TERMINATION)) s++; + s++; + } + ++s; + } while (*s == '~' || *s == JAP_TERMINATION); + } + } while (IsAnsiCharacter(s)); + } else +#endif + { + for(; *s != ' ' && *s != '\0'; s++) + if(*s == '~'){ + s++; + while(*s != '~') s++; + } + } + return s; +} + +wchar* +CFont::ParseToken(wchar* str, CRGBA &color, bool &flash, bool &bold) +{ + Details.anonymous_23 = false; + wchar *s = str + 1; + if (Details.color.r || Details.color.g || Details.color.b) + { + switch (*s) + { + case 'B': + bold = !bold; + break; + case 'b': + color.r = 27; + color.g = 89; + color.b = 130; + break; + case 'f': + flash = !flash; + break; + case 'g': + color.r = 255; + color.g = 150; + color.b = 225; + break; + case 'h': + color.r = 225; + color.g = 225; + color.b = 225; + break; + case 'l': + color.r = 0; + color.g = 0; + color.b = 0; + break; + case 'o': + color.r = 229; + color.g = 125; + color.b = 126; + break; + case 'p': + color.r = 168; + color.g = 110; + color.b = 252; + break; + case 'q': + color.r = 199; + color.g = 144; + color.b = 203; + break; + case 'r': + color.r = 255; + color.g = 150; + color.b = 225; + break; + case 't': + color.r = 86; + color.g = 212; + color.b = 146; + break; + case 'w': + color.r = 175; + color.g = 175; + color.b = 175; + break; +#ifdef FIX_BUGS + case 'x': + color.r = 0; + color.g = 255; + color.b = 255; + break; +#else + case 'x': + color.r = 132; + color.g = 146; + color.b = 197; + break; +#endif + case 'y': + color.r = 255; + color.g = 227; + color.b = 79; + break; +#ifdef BUTTON_ICONS + case 'U': PS2Symbol = BUTTON_UP; break; + case 'D': PS2Symbol = BUTTON_DOWN; break; + case '<': PS2Symbol = BUTTON_LEFT; break; + case '>': PS2Symbol = BUTTON_RIGHT; break; + case 'X': PS2Symbol = BUTTON_CROSS; break; + case 'O': PS2Symbol = BUTTON_CIRCLE; break; + case 'Q': PS2Symbol = BUTTON_SQUARE; break; + case 'T': PS2Symbol = BUTTON_TRIANGLE; break; + case 'K': PS2Symbol = BUTTON_L1; break; + case 'M': PS2Symbol = BUTTON_L2; break; + case 'A': PS2Symbol = BUTTON_L3; break; + case 'J': PS2Symbol = BUTTON_R1; break; + case 'V': PS2Symbol = BUTTON_R2; break; + case 'C': PS2Symbol = BUTTON_R3; break; + case 'H': PS2Symbol = BUTTON_RSTICK_UP; break; + case 'L': PS2Symbol = BUTTON_RSTICK_DOWN; break; + case '(': PS2Symbol = BUTTON_RSTICK_LEFT; break; + case ')': PS2Symbol = BUTTON_RSTICK_RIGHT; break; +#endif + default: + break; + } + } + while (*s != '~') + ++s; + if (*(++s) == '~') + s = ParseToken(s, color, flash, bold); + return s; +} + +#if 0//def MORE_LANGUAGES +wchar* +CFont::ParseToken(wchar *s, bool japShit) +{ + s++; + if ((Details.color.r || Details.color.g || Details.color.b) && !japShit) { + wchar c = *s; + if (IsJapanese()) + c &= 0x7FFF; + switch (c) { + case 'N': + case 'n': + NewLine = true; + break; + case 'b': SetColor(CRGBA(128, 167, 243, 255)); break; + case 'g': SetColor(CRGBA(95, 160, 106, 255)); break; + case 'h': SetColor(CRGBA(225, 225, 225, 255)); break; + case 'l': SetColor(CRGBA(0, 0, 0, 255)); break; + case 'p': SetColor(CRGBA(168, 110, 252, 255)); break; + case 'r': SetColor(CRGBA(113, 43, 73, 255)); break; + case 'w': SetColor(CRGBA(175, 175, 175, 255)); break; + case 'y': SetColor(CRGBA(210, 196, 106, 255)); break; +#ifdef BUTTON_ICONS + case 'U': PS2Symbol = BUTTON_UP; break; + case 'D': PS2Symbol = BUTTON_DOWN; break; + case '<': PS2Symbol = BUTTON_LEFT; break; + case '>': PS2Symbol = BUTTON_RIGHT; break; + case 'X': PS2Symbol = BUTTON_CROSS; break; + case 'O': PS2Symbol = BUTTON_CIRCLE; break; + case 'Q': PS2Symbol = BUTTON_SQUARE; break; + case 'T': PS2Symbol = BUTTON_TRIANGLE; break; + case 'K': PS2Symbol = BUTTON_L1; break; + case 'M': PS2Symbol = BUTTON_L2; break; + case 'A': PS2Symbol = BUTTON_L3; break; + case 'J': PS2Symbol = BUTTON_R1; break; + case 'V': PS2Symbol = BUTTON_R2; break; + case 'C': PS2Symbol = BUTTON_R3; break; + case 'H': PS2Symbol = BUTTON_RSTICK_UP; break; + case 'L': PS2Symbol = BUTTON_RSTICK_DOWN; break; + case '(': PS2Symbol = BUTTON_RSTICK_LEFT; break; + case ')': PS2Symbol = BUTTON_RSTICK_RIGHT; break; +#endif + } + } else if (IsJapanese()) { + if ((*s & 0x7FFF) == 'N' || (*s & 0x7FFF) == 'n') + NewLine = true; + } + while ((!IsJapanese() || (*s != JAP_TERMINATION)) && *s != '~') s++; + return s + 1; +} +#else +wchar* +CFont::ParseToken(wchar *s) +{ + Details.anonymous_23 = false; + s++; + if(Details.color.r || Details.color.g || Details.color.b) + switch(*s){ + case 'B': + Details.bBold = !Details.bBold; + break; + case 'N': + case 'n': + NewLine = true; + break; + case 'b': + Details.color.r = 27; + Details.color.g = 89; + Details.color.b = 130; + Details.anonymous_23 = true; + break; + case 'f': + Details.bFlash = !Details.bFlash; + if (!Details.bFlash) + Details.color.a = 255; + break; + case 'g': + Details.color.r = 255; + Details.color.g = 150; + Details.color.b = 225; + Details.anonymous_23 = true; + break; + case 'h': + Details.color.r = 225; + Details.color.g = 225; + Details.color.b = 225; + Details.anonymous_23 = true; + break; + case 'l': + Details.color.r = 0; + Details.color.g = 0; + Details.color.b = 0; + Details.anonymous_23 = true; + break; + case 'o': + Details.color.r = 229; + Details.color.g = 125; + Details.color.b = 126; + Details.anonymous_23 = true; + break; + case 'p': + Details.color.r = 168; + Details.color.g = 110; + Details.color.b = 252; + Details.anonymous_23 = true; + break; + case 'q': + Details.color.r = 199; + Details.color.g = 144; + Details.color.b = 203; + Details.anonymous_23 = true; + break; + case 'r': + Details.color.r = 255; + Details.color.g = 150; + Details.color.b = 225; + Details.anonymous_23 = true; + break; + case 't': + Details.color.r = 86; + Details.color.g = 212; + Details.color.b = 146; + Details.anonymous_23 = true; + break; + case 'w': + Details.color.r = 175; + Details.color.g = 175; + Details.color.b = 175; + Details.anonymous_23 = true; + break; + case 'x': +#ifdef FIX_BUGS + Details.color.r = 0; + Details.color.g = 255; + Details.color.b = 255; +#else + Details.color.r = 132; + Details.color.g = 146; + Details.color.b = 197; +#endif + Details.anonymous_23 = true; + break; + case 'y': + Details.color.r = 255; + Details.color.g = 227; + Details.color.b = 79; + Details.anonymous_23 = true; + break; +#ifdef BUTTON_ICONS + case 'U': PS2Symbol = BUTTON_UP; break; + case 'D': PS2Symbol = BUTTON_DOWN; break; + case '<': PS2Symbol = BUTTON_LEFT; break; + case '>': PS2Symbol = BUTTON_RIGHT; break; + case 'X': PS2Symbol = BUTTON_CROSS; break; + case 'O': PS2Symbol = BUTTON_CIRCLE; break; + case 'Q': PS2Symbol = BUTTON_SQUARE; break; + case 'T': PS2Symbol = BUTTON_TRIANGLE; break; + case 'K': PS2Symbol = BUTTON_L1; break; + case 'M': PS2Symbol = BUTTON_L2; break; + case 'A': PS2Symbol = BUTTON_L3; break; + case 'J': PS2Symbol = BUTTON_R1; break; + case 'V': PS2Symbol = BUTTON_R2; break; + case 'C': PS2Symbol = BUTTON_R3; break; + case 'H': PS2Symbol = BUTTON_RSTICK_UP; break; + case 'L': PS2Symbol = BUTTON_RSTICK_DOWN; break; + case '(': PS2Symbol = BUTTON_RSTICK_LEFT; break; + case ')': PS2Symbol = BUTTON_RSTICK_RIGHT; break; +#endif + } + while(*s != '~') s++; + if (*(++s) == '~') + s = ParseToken(s); + return s; +} +#endif + +void +CFont::FilterOutTokensFromString(wchar *str) +{ + int newIdx = 0; + wchar copy[256], *c; + UnicodeStrcpy(copy, str); + + for (c = copy; *c != '\0'; c++) { + if (*c == '~') { + c++; + while (*c != '~') c++; + } else { + str[newIdx++] = *c; + } + } + str[newIdx] = '\0'; +} + +void +CFont::DrawFonts(void) +{ + RenderFontBuffer(); +} + +void +CFont::SetScale(float x, float y) +{ +#ifdef MORE_LANGUAGES + /*if (IsJapanese()) { + x *= 1.35f; + y *= 1.25f; + }*/ +#endif + Details.scaleX = x; + Details.scaleY = y; +} + +void +CFont::SetSlantRefPoint(float x, float y) +{ + Details.slantRefX = x; + Details.slantRefY = y; +} + +void +CFont::SetSlant(float s) +{ + Details.slant = s; +} + +void +CFont::SetColor(CRGBA col) +{ + Details.color = col; + if (Details.alphaFade < 255.0f) + Details.color.a *= Details.alphaFade / 255.0f; +} + +void +CFont::SetJustifyOn(void) +{ + Details.justify = true; + Details.centre = false; + Details.rightJustify = false; +} + +void +CFont::SetJustifyOff(void) +{ + Details.justify = false; + Details.rightJustify = false; +} + +void +CFont::SetCentreOn(void) +{ + Details.centre = true; + Details.justify = false; + Details.rightJustify = false; +} + +void +CFont::SetCentreOff(void) +{ + Details.centre = false; +} + +void +CFont::SetWrapx(float x) +{ + Details.wrapX = x; +} + +void +CFont::SetCentreSize(float s) +{ + Details.centreSize = s; +} + +void +CFont::SetBackgroundOn(void) +{ + Details.background = true; +} + +void +CFont::SetBackgroundOff(void) +{ + Details.background = false; +} + +void +CFont::SetBackgroundColor(CRGBA col) +{ + Details.backgroundColor = col; +} + +void +CFont::SetBackGroundOnlyTextOn(void) +{ + Details.backgroundOnlyText = true; +} + +void +CFont::SetBackGroundOnlyTextOff(void) +{ + Details.backgroundOnlyText = false; +} + +void +CFont::SetRightJustifyOn(void) +{ + Details.rightJustify = true; + Details.justify = false; + Details.centre = false; +} + +void +CFont::SetRightJustifyOff(void) +{ + Details.rightJustify = false; + Details.justify = false; + Details.centre = false; +} + +void +CFont::SetPropOff(void) +{ + Details.proportional = false; +} + +void +CFont::SetPropOn(void) +{ + Details.proportional = true; +} + +void +CFont::SetFontStyle(int16 style) +{ + if (style == FONT_HEADING) { + Details.style = FONT_STANDARD; + Details.bFontHalfTexture = true; + } else { + Details.style = style; + Details.bFontHalfTexture = false; + } +} + +void +CFont::SetRightJustifyWrap(float wrap) +{ + Details.rightJustifyWrap = wrap; +} + +void +CFont::SetAlphaFade(float fade) +{ + Details.alphaFade = fade; +} + +void +CFont::SetDropColor(CRGBA col) +{ + Details.dropColor = col; + if (Details.alphaFade < 255.0f) + Details.dropColor.a *= Details.alphaFade / 255.0f; +} + +void +CFont::SetDropShadowPosition(int16 pos) +{ + Details.dropShadowPosition = pos; +} + +wchar CFont::FindNewCharacter(wchar c) +{ + if (c >= 16 && c <= 26) return c + 128; + if (c >= 8 && c <= 9) return c + 86; + if (c == 4) return c + 89; + if (c == 7) return 206; + if (c == 14) return 207; + if (c >= 33 && c <= 58) return c + 122; + if (c >= 65 && c <= 90) return c + 90; + if (c >= 96 && c <= 118) return c + 85; + if (c >= 119 && c <= 140) return c + 62; + if (c >= 141 && c <= 142) return 204; + if (c == 143) return 205; + if (c == 1) return 208; + return c; +} + +wchar +CFont::character_code(uint8 c) +{ + if(c < 128) + return c; + return foreign_table[c-128]; +} \ No newline at end of file diff --git a/src/renderer/Font.h b/src/renderer/Font.h new file mode 100644 index 00000000..42eb7b4c --- /dev/null +++ b/src/renderer/Font.h @@ -0,0 +1,217 @@ +#pragma once + +#include "Sprite2d.h" + +void AsciiToUnicode(const char *src, wchar *dst); +void UnicodeStrcpy(wchar *dst, const wchar *src); +void UnicodeStrcat(wchar *dst, wchar *append); +int UnicodeStrlen(const wchar *str); +void UnicodeMakeUpperCase(wchar *dst, const wchar *src); + +struct CFontDetails +{ + CRGBA color; + float scaleX; + float scaleY; + float slant; + float slantRefX; + float slantRefY; + bool8 justify; + bool8 centre; + bool8 rightJustify; + bool8 background; + bool8 backgroundOnlyText; + bool8 proportional; + bool8 bIsShadow; + bool8 bFlash; + bool8 bBold; + float alphaFade; + CRGBA backgroundColor; + float wrapX; + float centreSize; + float rightJustifyWrap; + int16 style; + bool8 bFontHalfTexture; + uint32 bank; + int16 dropShadowPosition; + CRGBA dropColor; + bool8 bFlashState; + int nFlashTimer; + bool8 anonymous_23; + uint32 anonymous_25; +}; + +struct CFontRenderState +{ + uint32 anonymous_0; + float fTextPosX; + float fTextPosY; + float scaleX; + float scaleY; + CRGBA color; + float fExtraSpace; + float slant; + float slantRefX; + float slantRefY; + bool8 bIsShadow; + bool8 bFontHalfTexture; + bool8 proportional; + bool8 anonymous_14; + int16 style; +}; + +class CSprite2d; + +enum { + FONT_BANK, + FONT_STANDARD, + FONT_HEADING, +#ifdef MORE_LANGUAGES + FONT_JAPANESE, +#endif + MAX_FONTS = FONT_HEADING +}; + +enum { + ALIGN_LEFT, + ALIGN_CENTER, + ALIGN_RIGHT, +}; + +#ifdef MORE_LANGUAGES +enum +{ + FONT_LANGSET_EFIGS, + FONT_LANGSET_RUSSIAN, + FONT_LANGSET_POLISH, + FONT_LANGSET_JAPANESE, + LANGSET_MAX +}; + +#define FONT_LOCALE(style) (CFont::IsJapanese() ? FONT_JAPANESE : style) +#else +#define FONT_LOCALE(style) (style) +#endif + +#ifdef BUTTON_ICONS +enum +{ + BUTTON_NONE = -1, + BUTTON_UP, + BUTTON_DOWN, + BUTTON_LEFT, + BUTTON_RIGHT, + BUTTON_CROSS, + BUTTON_CIRCLE, + BUTTON_SQUARE, + BUTTON_TRIANGLE, + BUTTON_L1, + BUTTON_L2, + BUTTON_L3, + BUTTON_R1, + BUTTON_R2, + BUTTON_R3, + BUTTON_RSTICK_UP, + BUTTON_RSTICK_DOWN, + BUTTON_RSTICK_LEFT, + BUTTON_RSTICK_RIGHT, + MAX_BUTTON_ICONS +}; +#endif // BUTTON_ICONS + + +class CFont +{ +#ifdef MORE_LANGUAGES + static int16 Size[LANGSET_MAX][MAX_FONTS][210]; + static uint8 LanguageSet; + static int32 Slot; +#else + static int16 Size[MAX_FONTS][210]; +#endif + static int16 NewLine; +public: + static CSprite2d Sprite[MAX_FONTS]; + static CFontDetails Details; + static CFontRenderState RenderState; + +#ifdef BUTTON_ICONS + static int32 ButtonsSlot; + static CSprite2d ButtonSprite[MAX_BUTTON_ICONS]; + static int PS2Symbol; + + static void LoadButtons(const char *txdPath); + static void DrawButton(float x, float y); +#endif // BUTTON_ICONS + + + static void Initialise(void); + static void Shutdown(void); + static void InitPerFrame(void); + static void PrintChar(float x, float y, wchar c); + static void PrintString(float x, float y, wchar *s); +#ifdef XBOX_SUBTITLES + static void PrintStringFromBottom(float x, float y, wchar *str); + static void PrintOutlinedString(float x, float y, wchar *str, float outlineStrength, bool fromBottom, CRGBA outlineColor); +#endif + static int GetNumberLines(float xstart, float ystart, wchar *s); + static void GetTextRect(CRect *rect, float xstart, float ystart, wchar *s); +//#ifdef MORE_LANGUAGES +// static bool PrintString(float x, float y, wchar *start, wchar* &end, float spwidth, float japX); +//#else + static void PrintString(float x, float y, uint32, wchar *start, wchar *end, float spwidth); +//#endif + static void PrintStringFromBottom(float x, float y, wchar *str); + static float GetCharacterWidth(wchar c); + static float GetCharacterSize(wchar c); + static float GetStringWidth(wchar *s, bool spaces = false); +#ifdef MORE_LANGUAGES + static float GetStringWidth_Jap(wchar* s); +#endif + static uint16 *GetNextSpace(wchar *s); +//#ifdef MORE_LANGUAGES +// static uint16 *ParseToken(wchar *s, bool japShit = false); +//#else + static uint16 *ParseToken(wchar *s); + static uint16 *ParseToken(wchar *s, CRGBA &color, bool &flash, bool &bold); +//#endif + static void DrawFonts(void); + static void RenderFontBuffer(void); + static uint16 character_code(uint8 c); + + static void SetScale(float x, float y); + static void SetSlantRefPoint(float x, float y); + static void SetSlant(float s); + static void SetJustifyOn(void); + static void SetJustifyOff(void); + static void SetRightJustifyOn(void); + static void SetRightJustifyOff(void); + static void SetCentreOn(void); + static void SetCentreOff(void); + static void SetWrapx(float x); + static void SetCentreSize(float s); + static void SetBackgroundOn(void); + static void SetBackgroundOff(void); + static void SetBackGroundOnlyTextOn(void); + static void SetBackGroundOnlyTextOff(void); + static void SetPropOn(void); + static void SetPropOff(void); + static void SetFontStyle(int16 style); + static void SetRightJustifyWrap(float wrap); + static void SetAlphaFade(float fade); + static void SetDropShadowPosition(int16 pos); + static void SetBackgroundColor(CRGBA col); + static void SetColor(CRGBA col); + static void SetDropColor(CRGBA col); + static wchar FindNewCharacter(wchar c); + static void FilterOutTokensFromString(wchar*); +#ifdef MORE_LANGUAGES + static void ReloadFonts(uint8 set); + + // japanese stuff + static bool IsAnsiCharacter(wchar* s); + static bool IsJapanesePunctuation(wchar* str); + static bool IsJapanese() { return LanguageSet == FONT_LANGSET_JAPANESE; } + static bool IsJapaneseFont() { return IsJapanese() && (Details.style == FONT_JAPANESE); } +#endif +}; diff --git a/src/renderer/Glass.cpp b/src/renderer/Glass.cpp new file mode 100644 index 00000000..b4ec8c7e --- /dev/null +++ b/src/renderer/Glass.cpp @@ -0,0 +1,1027 @@ +#include "common.h" + +#include "Glass.h" +#include "Timer.h" +#include "Object.h" +#include "Vehicle.h" +#include "Pools.h" +#include "General.h" +#include "AudioScriptObject.h" +#include "World.h" +#include "Timecycle.h" +#include "Particle.h" +#include "Camera.h" +#include "RenderBuffer.h" +#include "Shadows.h" +#include "ModelIndices.h" +#include "main.h" +#include "soundlist.h" +#include "SurfaceTable.h" + + +uint32 CGlass::NumGlassEntities; +CEntity *CGlass::apEntitiesToBeRendered[NUM_GLASSENTITIES]; +CFallingGlassPane CGlass::aGlassPanes[NUM_GLASSPANES]; + + +CVector2D CentersWithTriangle[NUM_GLASSTRIANGLES]; +const CVector2D CoorsWithTriangle[NUM_GLASSTRIANGLES][3] = +{ + { + CVector2D(0.0f, 0.0f), + CVector2D(0.0f, 1.0f), + CVector2D(0.4f, 0.5f) + }, + + { + CVector2D(0.0f, 1.0f), + CVector2D(1.0f, 1.0f), + CVector2D(0.4f, 0.5f) + }, + + { + CVector2D(0.0f, 0.0f), + CVector2D(0.4f, 0.5f), + CVector2D(0.7f, 0.0f) + }, + + { + CVector2D(0.7f, 0.0f), + CVector2D(0.4f, 0.5f), + CVector2D(1.0f, 1.0f) + }, + + { + CVector2D(0.7f, 0.0f), + CVector2D(1.0f, 1.0f), + CVector2D(1.0f, 0.0f) + } +}; + +#define TEMPBUFFERVERTHILIGHTOFFSET 0 +#define TEMPBUFFERINDEXHILIGHTOFFSET 0 +#define TEMPBUFFERVERTHILIGHTSIZE 256 +#define TEMPBUFFERINDEXHILIGHTSIZE 512 + +#define TEMPBUFFERVERTSHATTEREDOFFSET TEMPBUFFERVERTHILIGHTSIZE +#define TEMPBUFFERINDEXSHATTEREDOFFSET TEMPBUFFERINDEXHILIGHTSIZE +#define TEMPBUFFERVERTSHATTEREDSIZE 384 +#define TEMPBUFFERINDEXSHATTEREDSIZE 768 + +#define TEMPBUFFERVERTREFLECTIONOFFSET TEMPBUFFERVERTSHATTEREDSIZE +#define TEMPBUFFERINDEXREFLECTIONOFFSET TEMPBUFFERINDEXSHATTEREDSIZE +#define TEMPBUFFERVERTREFLECTIONSIZE 512 +#define TEMPBUFFERINDEXREFLECTIONSIZE 1024 + +int32 TempBufferIndicesStoredHiLight = 0; +int32 TempBufferVerticesStoredHiLight = 0; +int32 TempBufferIndicesStoredShattered = 0; +int32 TempBufferVerticesStoredShattered = 0; +int32 TempBufferIndicesStoredReflection = 0; +int32 TempBufferVerticesStoredReflection = 0; + +void +CFallingGlassPane::Update(void) +{ + if ( CTimer::GetTimeInMilliseconds() >= m_nTimer ) + { + // Apply MoveSpeed + if ( m_bCarGlass ) + GetPosition() += m_vecMoveSpeed * CTimer::GetTimeStep() * 0.35f; + else + GetPosition() += m_vecMoveSpeed * CTimer::GetTimeStep(); + + // Apply Gravity + if ( m_bCarGlass ) + m_vecMoveSpeed.z -= 0.01f * CTimer::GetTimeStep(); + else + m_vecMoveSpeed.z -= 0.02f * CTimer::GetTimeStep(); + + // Apply TurnSpeed + GetRight() += CrossProduct(m_vecTurn, GetRight()); + GetForward() += CrossProduct(m_vecTurn, GetForward()); + GetUp() += CrossProduct(m_vecTurn, GetUp()); + + if ( GetPosition().z < m_fGroundZ ) + { + CVector pos; + CVector dir; + + m_bActive = false; + + pos = CVector(GetPosition().x, GetPosition().y, m_fGroundZ); + + PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_LIGHT_BREAK, pos); + + RwRGBA color = { 255, 255, 255, 255 }; + + if ( !m_bCarGlass ) + { + static int32 nFrameGen = 0; + + for ( int32 i = 0; i < 4; i++ ) + { + dir.x = CGeneral::GetRandomNumberInRange(-0.35f, 0.35f); + dir.y = CGeneral::GetRandomNumberInRange(-0.35f, 0.35f); + dir.z = CGeneral::GetRandomNumberInRange(0.05f, 0.20f); + + CParticle::AddParticle(PARTICLE_CAR_DEBRIS, + pos, + dir, + nil, + CGeneral::GetRandomNumberInRange(0.02f, 0.2f), + color, + CGeneral::GetRandomNumberInRange(-40, 40), + 0, + ++nFrameGen & 3, + 500); + } + } + } + } +} + +void +CFallingGlassPane::Render(void) +{ + float distToCamera = (TheCamera.GetPosition() - GetPosition()).Magnitude(); + + CVector fwdNorm = GetForward(); + fwdNorm.Normalise(); + uint8 alpha = CGlass::CalcAlphaWithNormal(&fwdNorm); + +#ifdef FIX_BUGS + uint16 time = Clamp(CTimer::GetTimeInMilliseconds() > m_nTimer ? CTimer::GetTimeInMilliseconds() - m_nTimer : 0u, 0u, 500u); +#else + uint16 time = Clamp(CTimer::GetTimeInMilliseconds() - m_nTimer, 0, 500); +#endif + + uint8 color = int32( float(alpha) * (float(time) / 500) ); + + if ( TempBufferIndicesStoredHiLight >= TEMPBUFFERINDEXHILIGHTSIZE-7 || TempBufferVerticesStoredHiLight >= TEMPBUFFERVERTHILIGHTSIZE-4 ) + CGlass::RenderHiLightPolys(); + + // HiLight Polys + + if ( m_bCarGlass && color < 64 ) + color = 64; + + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], color, color, color, color); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], color, color, color, color); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], color, color, color, color); + + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], 0.5f); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], 0.5f); + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], 0.5f); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], 0.6f); + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], 0.6f); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], 0.6f); + + ASSERT(m_nTriIndex < NUM_GLASSTRIANGLES); + + CVector2D p0 = CoorsWithTriangle[m_nTriIndex][0] - CentersWithTriangle[m_nTriIndex]; + CVector2D p1 = CoorsWithTriangle[m_nTriIndex][1] - CentersWithTriangle[m_nTriIndex]; + CVector2D p2 = CoorsWithTriangle[m_nTriIndex][2] - CentersWithTriangle[m_nTriIndex]; + CVector v0 = *this * CVector(p0.x, 0.0f, p0.y); + CVector v1 = *this * CVector(p1.x, 0.0f, p1.y); + CVector v2 = *this * CVector(p2.x, 0.0f, p2.y); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], v0.x, v0.y, v0.z); + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], v1.x, v1.y, v1.z); + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], v2.x, v2.y, v2.z); + + TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 0] = TempBufferVerticesStoredHiLight + 0; + TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 1] = TempBufferVerticesStoredHiLight + 1; + TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 2] = TempBufferVerticesStoredHiLight + 2; + TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 3] = TempBufferVerticesStoredHiLight + 0; + TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 4] = TempBufferVerticesStoredHiLight + 2; + TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 5] = TempBufferVerticesStoredHiLight + 1; + + TempBufferVerticesStoredHiLight += 3; + TempBufferIndicesStoredHiLight += 6; + + if ( m_bShattered ) + { + if ( TempBufferIndicesStoredShattered >= TEMPBUFFERINDEXSHATTEREDSIZE-7 || TempBufferVerticesStoredShattered >= TEMPBUFFERVERTSHATTEREDSIZE-4 ) + CGlass::RenderShatteredPolys(); + + uint8 shatteredColor = 140; + if ( distToCamera > 30.0f ) + shatteredColor = int32((1.0f - (distToCamera - 30.0f) * 4.0f / 40.0f) * 140); + + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], shatteredColor, shatteredColor, shatteredColor, shatteredColor); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], shatteredColor, shatteredColor, shatteredColor, shatteredColor); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], shatteredColor, shatteredColor, shatteredColor, shatteredColor); + + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 4.0f * CoorsWithTriangle[m_nTriIndex][0].x * m_fStep); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 4.0f * CoorsWithTriangle[m_nTriIndex][0].y * m_fStep); + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 4.0f * CoorsWithTriangle[m_nTriIndex][1].x * m_fStep); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 4.0f * CoorsWithTriangle[m_nTriIndex][1].y * m_fStep); + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 4.0f * CoorsWithTriangle[m_nTriIndex][2].x * m_fStep); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 4.0f * CoorsWithTriangle[m_nTriIndex][2].y * m_fStep); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], v0.x, v0.y, v0.z); + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], v1.x, v1.y, v1.z); + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], v2.x, v2.y, v2.z); + + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 0] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 0; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 1] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 1; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 2] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 2; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 3] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 0; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 4] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 2; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 5] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 1; + + TempBufferIndicesStoredShattered += 6; + TempBufferVerticesStoredShattered += 3; + } +} + +void +CGlass::Init(void) +{ + for ( int32 i = 0; i < NUM_GLASSPANES; i++ ) + aGlassPanes[i].m_bActive = false; + + for ( int32 i = 0; i < NUM_GLASSTRIANGLES; i++ ) + CentersWithTriangle[i] = (CoorsWithTriangle[i][0] + CoorsWithTriangle[i][1] + CoorsWithTriangle[i][2]) / 3; +} + +void +CGlass::Update(void) +{ + for ( int32 i = 0; i < NUM_GLASSPANES; i++ ) + { + if ( aGlassPanes[i].m_bActive ) + aGlassPanes[i].Update(); + } +} + +void +CGlass::Render(void) +{ + TempBufferVerticesStoredHiLight = 0; + TempBufferIndicesStoredHiLight = 0; + + TempBufferVerticesStoredShattered = TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferIndicesStoredShattered = TEMPBUFFERINDEXSHATTEREDOFFSET; + + TempBufferVerticesStoredReflection = TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferIndicesStoredReflection = TEMPBUFFERINDEXREFLECTIONOFFSET; + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEFOGCOLOR, (void *)RWRGBALONG(CTimeCycle::GetFogRed(), CTimeCycle::GetFogGreen(), CTimeCycle::GetFogBlue(), 255)); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); + + PUSH_RENDERGROUP("CGlass::Render"); + + for ( int32 i = 0; i < NUM_GLASSPANES; i++ ) + { + if ( aGlassPanes[i].m_bActive ) + aGlassPanes[i].Render(); + } + + for ( uint32 i = 0; i < NumGlassEntities; i++ ) + RenderEntityInGlass(apEntitiesToBeRendered[i]); + + POP_RENDERGROUP(); + + NumGlassEntities = 0; + + RenderHiLightPolys(); + RenderShatteredPolys(); + RenderReflectionPolys(); + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE); +} + +CFallingGlassPane * +CGlass::FindFreePane(void) +{ + for ( int32 i = 0; i < NUM_GLASSPANES; i++ ) + { + if ( !aGlassPanes[i].m_bActive ) + return &aGlassPanes[i]; + } + + return nil; +} + +void +CGlass::GeneratePanesForWindow(uint32 type, CVector pos, CVector up, CVector right, CVector speed, CVector center, + float moveSpeed, bool cracked, bool explosion, int32 stepmul, bool carGlass) +{ + float upLen = up.Magnitude(); + float rightLen = right.Magnitude(); + + float upSteps = upLen + 0.75f; + if ( upSteps < 1.0f ) upSteps = 1.0f; + + float rightSteps = rightLen + 0.75f; + if ( rightSteps < 1.0f ) rightSteps = 1.0f; + + uint32 ysteps = stepmul * (uint32)upSteps; + if ( ysteps > 3 ) ysteps = 3; + + uint32 xsteps = stepmul * (uint32)rightSteps; + if ( xsteps > 3 ) xsteps = 3; + + if ( explosion ) + { + if ( ysteps > 1 ) ysteps = 1; + if ( xsteps > 1 ) xsteps = 1; + } + + float upScl = upLen / float(ysteps); + float rightScl = rightLen / float(xsteps); + + bool bZFound; + float groundZ = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z, &bZFound); + if ( !bZFound ) groundZ = pos.z - 2.0f; + + for ( uint32 y = 0; y < ysteps; y++ ) + { + for ( uint32 x = 0; x < xsteps; x++ ) + { + float stepy = float(y) * upLen / float(ysteps); + float stepx = float(x) * rightLen / float(xsteps); + + for ( int32 i = 0; i < NUM_GLASSTRIANGLES; i++ ) + { + CFallingGlassPane *pane = FindFreePane(); + if ( pane ) + { + pane->m_nTriIndex = i; + + pane->GetRight() = (right * rightScl) / rightLen; + pane->GetUp() = (up * upScl) / upLen; + + CVector fwd = CrossProduct(pane->GetRight(), pane->GetUp()); + fwd.Normalise(); + + pane->GetForward() = fwd; + + pane->GetPosition() = right / rightLen * (rightScl * CentersWithTriangle[i].x + stepx) + + up / upLen * (upScl * CentersWithTriangle[i].y + stepy) + + pos; + + pane->m_vecMoveSpeed.x = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.0015f + speed.x; + pane->m_vecMoveSpeed.y = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.0015f + speed.y; + pane->m_vecMoveSpeed.z = 0.0f + speed.z; + + if ( moveSpeed != 0.0f ) + { + CVector dist = pane->GetPosition() - center; + dist.Normalise(); + + pane->m_vecMoveSpeed += moveSpeed * dist; + } + + pane->m_vecTurn.x = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.002f; + pane->m_vecTurn.y = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.002f; + pane->m_vecTurn.z = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.002f; + + switch ( type ) + { + case 0: + case 2: + pane->m_nTimer = CTimer::GetTimeInMilliseconds(); + break; + case 1: + float dist = (pane->GetPosition() - center).Magnitude(); + pane->m_nTimer = uint32(dist*100 + CTimer::GetTimeInMilliseconds()); + break; + } + + pane->m_fGroundZ = groundZ; + pane->m_bShattered = cracked; + pane->m_fStep = upLen / float(ysteps); + pane->m_bCarGlass = carGlass; + pane->m_bActive = true; + } + } + } + } +} + +void +CGlass::AskForObjectToBeRenderedInGlass(CEntity *entity) +{ +#ifdef FIX_BUGS + if ( NumGlassEntities < NUM_GLASSENTITIES ) +#else + if ( NumGlassEntities < NUM_GLASSENTITIES-1 ) +#endif + { + apEntitiesToBeRendered[NumGlassEntities++] = entity; + } +} + +void +CGlass::RenderEntityInGlass(CEntity *entity) +{ + ASSERT(entity!=nil); + CObject *object = (CObject *)entity; + + if ( object->bGlassBroken ) + return; + + float distToCamera = (TheCamera.GetPosition() - object->GetPosition()).Magnitude(); + + if ( distToCamera > 40.0f ) + return; + + CVector fwdNorm = object->GetForward(); + fwdNorm.Normalise(); + uint8 alpha = CalcAlphaWithNormal(&fwdNorm); + + CColModel *col = object->GetColModel(); + ASSERT(col!=nil); + if ( col->numTriangles >= 2 ) + { + CVector a = object->GetMatrix() * col->vertices[0].Get(); + CVector b = object->GetMatrix() * col->vertices[1].Get(); + CVector c = object->GetMatrix() * col->vertices[2].Get(); + CVector d = object->GetMatrix() * col->vertices[3].Get(); + + if ( object->bGlassCracked ) + { + uint8 color = 255; + if ( distToCamera > 30.0f ) + color = int32((1.0f - (distToCamera - 30.0f) * 4.0f / 40.0f) * 255); + + if ( TempBufferIndicesStoredShattered >= TEMPBUFFERINDEXSHATTEREDSIZE-13 || TempBufferVerticesStoredShattered >= TEMPBUFFERVERTSHATTEREDSIZE-5 ) + RenderShatteredPolys(); + + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], color, color, color, color); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], color, color, color, color); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], color, color, color, color); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], color, color, color, color); + + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 0.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 0.0f); + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 16.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 0.0f); + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 0.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 16.0f); + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], 16.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], 16.0f); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], a.x, a.y, a.z); + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], b.x, b.y, b.z); + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], c.x, c.y, c.z); + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], d.x, d.y, d.z); + + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 0] = col->triangles[0].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 1] = col->triangles[0].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 2] = col->triangles[0].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 3] = col->triangles[1].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 4] = col->triangles[1].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 5] = col->triangles[1].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 6] = col->triangles[0].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 7] = col->triangles[0].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 8] = col->triangles[0].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 9] = col->triangles[1].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 10] = col->triangles[1].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 11] = col->triangles[1].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET; + + TempBufferIndicesStoredShattered += 12; + TempBufferVerticesStoredShattered += 4; + } + + if ( TempBufferIndicesStoredReflection >= TEMPBUFFERINDEXREFLECTIONSIZE-13 || TempBufferVerticesStoredReflection >= TEMPBUFFERVERTREFLECTIONSIZE-5 ) + RenderReflectionPolys(); + + uint8 color = 100; + if ( distToCamera > 30.0f ) + color = int32((1.0f - (distToCamera - 30.0f) * 4.0f / 40.0f) * 100); + + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], color, color, color, color); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], color, color, color, color); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], color, color, color, color); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], color, color, color, color); + + float FwdAngle = CGeneral::GetATanOfXY(TheCamera.GetForward().x, TheCamera.GetForward().y); + float v = 2.0f * TheCamera.GetForward().z * 0.2f; + float u = float(object->m_randomSeed & 15) * 0.02f + (FwdAngle / TWOPI); + + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], u); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], v); + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], u+0.2f); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], v); + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], u); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], v+0.2f); + RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], u+0.2f); + RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], v+0.2f); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], a.x, a.y, a.z); + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], b.x, b.y, b.z); + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], c.x, c.y, c.z); + RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], d.x, d.y, d.z); + + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 0] = col->triangles[0].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 1] = col->triangles[0].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 2] = col->triangles[0].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 3] = col->triangles[1].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 4] = col->triangles[1].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 5] = col->triangles[1].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 6] = col->triangles[0].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 7] = col->triangles[0].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 8] = col->triangles[0].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 9] = col->triangles[1].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 10] = col->triangles[1].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 11] = col->triangles[1].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET; + + TempBufferIndicesStoredReflection += 12; + TempBufferVerticesStoredReflection += 4; + } +} + +int32 +CGlass::CalcAlphaWithNormal(CVector *normal) +{ + ASSERT(normal!=nil); + + float fwdDir = 2.0f * DotProduct(*normal, TheCamera.GetForward()); + float fwdDot = DotProduct(TheCamera.GetForward()-fwdDir*(*normal), CVector(0.57f, 0.57f, -0.57f)); + return int32(lerp(fwdDot*fwdDot*fwdDot*fwdDot*fwdDot*fwdDot, 20.0f, 255.0f)); +} + +void +CGlass::RenderHiLightPolys(void) +{ + if ( TempBufferVerticesStoredHiLight != TEMPBUFFERVERTHILIGHTOFFSET ) + { + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)RwTextureGetRaster(gpShadowExplosionTex)); + + LittleTest(); + + if ( RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStoredHiLight, nil, rwIM3D_VERTEXUV) ) + { + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStoredHiLight); + RwIm3DEnd(); + } + + TempBufferVerticesStoredHiLight = TEMPBUFFERVERTHILIGHTOFFSET; + TempBufferIndicesStoredHiLight = TEMPBUFFERINDEXHILIGHTOFFSET; + } +} + +void +CGlass::RenderShatteredPolys(void) +{ + if ( TempBufferVerticesStoredShattered != TEMPBUFFERVERTSHATTEREDOFFSET ) + { + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)RwTextureGetRaster(gpCrackedGlassTex)); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + + LittleTest(); + + if ( RwIm3DTransform(&TempBufferRenderVertices[TEMPBUFFERVERTSHATTEREDOFFSET], TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET, nil, rwIM3D_VERTEXUV) ) + { + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, &TempBufferRenderIndexList[TEMPBUFFERINDEXSHATTEREDOFFSET], TempBufferIndicesStoredShattered - TEMPBUFFERINDEXSHATTEREDOFFSET); + RwIm3DEnd(); + } + + TempBufferIndicesStoredShattered = TEMPBUFFERINDEXSHATTEREDOFFSET; + TempBufferVerticesStoredShattered = TEMPBUFFERVERTSHATTEREDOFFSET; + } +} + +void +CGlass::RenderReflectionPolys(void) +{ + if ( TempBufferVerticesStoredReflection != TEMPBUFFERVERTREFLECTIONOFFSET ) + { + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)RwTextureGetRaster(gpShadowHeadLightsTex)); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + + LittleTest(); + + if ( RwIm3DTransform(&TempBufferRenderVertices[TEMPBUFFERVERTREFLECTIONOFFSET], TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET, nil, rwIM3D_VERTEXUV) ) + { + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, &TempBufferRenderIndexList[TEMPBUFFERINDEXREFLECTIONOFFSET], TempBufferIndicesStoredReflection - TEMPBUFFERINDEXREFLECTIONOFFSET); + RwIm3DEnd(); + } + + TempBufferIndicesStoredReflection = TEMPBUFFERINDEXREFLECTIONOFFSET; + TempBufferVerticesStoredReflection = TEMPBUFFERVERTREFLECTIONOFFSET; + } +} + +void +CGlass::WindowRespondsToCollision(CEntity *entity, float amount, CVector speed, CVector point, bool explosion) +{ + ASSERT(entity!=nil); + + CObject *object = (CObject *)entity; + + if ( object->bGlassBroken ) + return; + + object->bGlassCracked = true; + + CColModel *col = object->GetColModel(); + ASSERT(col!=nil); + + if ( col->numTriangles == 2 ) + { + CVector a = col->vertices[0].Get(); + CVector b = col->vertices[1].Get(); + CVector c = col->vertices[2].Get(); + CVector d = col->vertices[3].Get(); + + float minx = Min(Min(a.x, b.x), Min(c.x, d.x)); + float maxx = Max(Max(a.x, b.x), Max(c.x, d.x)); + float miny = Min(Min(a.y, b.y), Min(c.y, d.y)); + float maxy = Max(Max(a.y, b.y), Max(c.y, d.y)); + float minz = Min(Min(a.z, b.z), Min(c.z, d.z)); + float maxz = Max(Max(a.z, b.z), Max(c.z, d.z)); + + CVector pa = object->GetMatrix() * CVector(minx, miny, minz); + CVector pb = object->GetMatrix() * CVector(maxx, maxy, minz); + + if ( amount > 300.0f ) + { + PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_BREAK_L, object->GetPosition()); + + GeneratePanesForWindow(0, + pa, + CVector(0.0f, 0.0f, maxz-minz), + pb - pa, + speed, point, 0.1f, !!object->bGlassCracked, explosion, 1, false); + } + else + { + PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_BREAK_S, object->GetPosition()); + + GeneratePanesForWindow(1, + pa, + CVector(0.0f, 0.0f, maxz-minz), + pb - pa, + speed, point, 0.1f, !!object->bGlassCracked, explosion, 1, false); + } + } + + object->bGlassBroken = true; + object->bIsVisible = false; + object->bUsesCollision = false; +} + +void +CGlass::WindowRespondsToSoftCollision(CEntity *entity, float amount) +{ + ASSERT(entity!=nil); + + CObject *object = (CObject *)entity; + + if ( entity->bUsesCollision && amount > 50.0f && !object->bGlassCracked ) + { + PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_CRACK, object->GetPosition()); + object->bGlassCracked = true; + } +} + +void +CGlass::WasGlassHitByBullet(CEntity *entity, CVector point) +{ + ASSERT(entity!=nil); + + CObject *object = (CObject *)entity; + + if ( IsGlass(object->GetModelIndex()) ) + { + if ( object->bUsesCollision ) + { + if ( !object->bGlassCracked ) + { + PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_CRACK, object->GetPosition()); + object->bGlassCracked = true; + } + else + { + if ( (CGeneral::GetRandomNumber() & 3) == 2 ) + WindowRespondsToCollision(object, 0.0f, CVector(0.0f, 0.0f, 0.0f), point, false); + } + } + } +} + +void +CGlass::WindowRespondsToExplosion(CEntity *entity, CVector point) +{ + ASSERT(entity!=nil); + + CObject *object = (CObject *)entity; + + if ( object->bUsesCollision ) + { + CVector distToGlass = object->GetPosition() - point; + + float fDistToGlass = distToGlass.Magnitude(); + + if ( fDistToGlass < 10.0f ) + { + distToGlass *= (0.3f / fDistToGlass); // normalise + WindowRespondsToCollision(object, 10000.0f, distToGlass, object->GetPosition(), true); + } + else + { + if ( fDistToGlass < 30.0f ) + object->bGlassCracked = true; + } + } +} + + +void +CGlass::CarWindscreenShatters(CVehicle *vehicle, bool unk) +{ + ASSERT(vehicle!=nil); + + CColModel *col = vehicle->GetColModel(); + ASSERT(col!=nil); + + if ( col->numTriangles < 2 ) + return; + + CColTriangle *tria = nil; + int32 triIndex = -1; + CColTriangle *trib = nil; + + for ( int32 i = 0; i < col->numTriangles; i++ ) + { + CColTriangle *tri = &col->triangles[i]; + if ( tri->surface == SURFACE_GLASS ) + { + if ( tria ) + { + trib = tri; + break; + } + + triIndex = i; + tria = tri; + } + } + + if ( trib == nil ) + return; + + CCollision::CalculateTrianglePlanes(col); + + CColTrianglePlane *triPlanes = col->trianglePlanes; + + if ( triPlanes == nil ) + return; + + CVector planeNormal; + triPlanes[triIndex].GetNormal(planeNormal); + planeNormal = Multiply3x3(vehicle->GetMatrix(), planeNormal); + + CVector vec1 = CrossProduct(vehicle->GetRight(), planeNormal); + vec1.Normalise(); + + CVector vec2 = CrossProduct(planeNormal, vehicle->GetUp()); + vec2.Normalise(); + + CVector v[6]; + float proj1[6]; + float proj2[6]; + + v[0] = col->vertices[tria->a].Get(); + v[1] = col->vertices[tria->b].Get(); + v[2] = col->vertices[tria->c].Get(); + + v[3] = col->vertices[trib->a].Get(); + v[4] = col->vertices[trib->b].Get(); + v[5] = col->vertices[trib->c].Get(); + + v[0] = vehicle->GetMatrix() * v[0]; + v[1] = vehicle->GetMatrix() * v[1]; + v[2] = vehicle->GetMatrix() * v[2]; + v[3] = vehicle->GetMatrix() * v[3]; + v[4] = vehicle->GetMatrix() * v[4]; + v[5] = vehicle->GetMatrix() * v[5]; + + proj1[0] = DotProduct(v[0], vec1); + proj2[0] = DotProduct(v[0], vec2); + proj1[1] = DotProduct(v[1], vec1); + proj2[1] = DotProduct(v[1], vec2); + proj1[2] = DotProduct(v[2], vec1); + proj2[2] = DotProduct(v[2], vec2); + + proj1[3] = DotProduct(v[3], vec1); + proj2[3] = DotProduct(v[3], vec2); + proj1[4] = DotProduct(v[4], vec1); + proj2[4] = DotProduct(v[4], vec2); + proj1[5] = DotProduct(v[5], vec1); + proj2[5] = DotProduct(v[5], vec2); + + int32 originIndex = 0; + float max1 = proj1[0]; + float max2 = proj2[0]; + float origin = proj1[0] + proj2[0]; + + for ( int32 i = 1; i < 6; i++ ) + { + float o = proj1[i] + proj2[i]; + if ( o < origin ) + { + origin = o; + originIndex = i; + } + + if ( proj1[i] > max1 ) + max1 = proj1[i]; + if ( proj2[i] > max2 ) + max2 = proj2[i]; + } + + float bound1 = max1 - proj1[originIndex]; + float bound2 = max2 - proj2[originIndex]; + + PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_BREAK_L, vehicle->GetPosition()); + + CVector center = v[originIndex] + ((0.5f*bound1) * vec1) + ((0.5f*bound2) * vec2); + CVector speed = vehicle->m_vecMoveSpeed; + CVector right = bound2 * vec2; + CVector up = bound1 * vec1; + CVector pos = v[originIndex]; + + GeneratePanesForWindow(2, pos, up, right, speed, center, 0.1f, false, false, 2, true); +} + +bool +CGlass::HasGlassBeenShatteredAtCoors(float x, float y, float z) +{ + CEntity *entity = nil; + float dist = 20.0f; + + int32 nStartX = Max(CWorld::GetSectorIndexX(x - 30.0f), 0); + int32 nStartY = Max(CWorld::GetSectorIndexY(y - 30.0f), 0); + int32 nEndX = Min(CWorld::GetSectorIndexX(x + 30.0f), NUMSECTORS_X-1); + int32 nEndY = Min(CWorld::GetSectorIndexY(y + 30.0f), NUMSECTORS_Y-1); + + CWorld::AdvanceCurrentScanCode(); + + for ( int32 ys = nStartY; ys <= nEndY; ys++ ) + { + for ( int32 xs = nStartX; xs <= nEndX; xs++ ) + { + CSector *sector = CWorld::GetSector(xs, ys); + + ASSERT(sector != nil); + + FindWindowSectorList(sector->m_lists[ENTITYLIST_OBJECTS], &dist, &entity, x, y, z); + FindWindowSectorList(sector->m_lists[ENTITYLIST_DUMMIES], &dist, &entity, x, y, z); + } + } + + if ( entity ) + { + if ( entity->GetType() == ENTITY_TYPE_DUMMY ) + return false; + + return !!((CObject*)entity)->bGlassBroken; + } + + return false; +} + +void +CGlass::FindWindowSectorList(CPtrList &list, float *dist, CEntity **entity, float x, float y, float z) +{ + ASSERT(dist!=nil); + ASSERT(entity!=nil); + + CPtrNode *node = list.first; + + while ( node != nil ) + { + CEntity *ent = (CEntity *)node->item; + uint16 scanCode = ent->m_scanCode; + node = node->next; + + ASSERT(ent!=nil); + + if ( IsGlass(ent->GetModelIndex()) ) + { + if ( scanCode != CWorld::GetCurrentScanCode() ) + { + ent->m_scanCode = CWorld::GetCurrentScanCode(); + + float dst = (CVector(x,y,z) - ent->GetPosition()).Magnitude(); + + if ( dst < *dist ) + { + *dist = dst; + *entity = ent; + } + } + } + } +} + +void +CGlass::BreakGlassPhysically(CVector pos, float radius) +{ + static uint32 breakTime = 0; + + if ( CTimer::GetTimeInMilliseconds() < breakTime + 1000 && CTimer::GetTimeInMilliseconds() >= breakTime ) + return; + + CColSphere sphere; + sphere.piece = 0; + sphere.radius = radius; + sphere.surface = 0; + + for ( int32 i = CPools::GetObjectPool()->GetSize() - 1; i >= 0; i-- ) + { + CObject *object = CPools::GetObjectPool()->GetSlot(i); + if (object) + { + if ( IsGlass(object->GetModelIndex()) ) + { + if ( object->bUsesCollision ) + { + CColModel *col = object->GetColModel(); + ASSERT(col!=nil); + + if ( col->numTriangles < 2 ) + continue; + + bool hit = false; + + CVector dist = pos - object->GetPosition(); + + sphere.center.x = DotProduct(dist, object->GetRight()); + sphere.center.y = DotProduct(dist, object->GetForward()); + sphere.center.z = DotProduct(dist, object->GetUp()); + + CCollision::CalculateTrianglePlanes(col); + + for ( int32 j = 0; j < col->numTriangles; j++ ) + { + if ( CCollision::TestSphereTriangle(sphere, + col->vertices, col->triangles[j], col->trianglePlanes[j]) ) + { + hit = true; + } + } + + if ( hit ) + { + breakTime = CTimer::GetTimeInMilliseconds(); + + if ( object->bGlassCracked ) + { + CVector a = col->vertices[0].Get(); + CVector b = col->vertices[1].Get(); + CVector c = col->vertices[2].Get(); + CVector d = col->vertices[3].Get(); + + float minx = Min(Min(a.x, b.x), Min(c.x, d.x)); + float maxx = Max(Max(a.x, b.x), Max(c.x, d.x)); + float miny = Min(Min(a.y, b.y), Min(c.y, d.y)); + float maxy = Max(Max(a.y, b.y), Max(c.y, d.y)); + float minz = Min(Min(a.z, b.z), Min(c.z, d.z)); + float maxz = Max(Max(a.z, b.z), Max(c.z, d.z)); + + CVector pa = object->GetMatrix() * CVector(minx, miny, minz); + CVector pb = object->GetMatrix() * CVector(maxx, maxy, minz); + + PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_BREAK_S, object->GetPosition()); + + GeneratePanesForWindow(1, + pa, + CVector(0.0f, 0.0f, maxz-minz), + pb - pa, + CVector(0.0f, 0.0f, 0.0f), pos, 0.1f, !!object->bGlassCracked, false, 1, false); + + object->bGlassBroken = true; + object->bIsVisible = false; + object->bUsesCollision = false; + } + else + { + PlayOneShotScriptObject(SCRIPT_SOUND_GLASS_CRACK, object->GetPosition()); + object->bGlassCracked = true; + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/renderer/Glass.h b/src/renderer/Glass.h new file mode 100644 index 00000000..f1c85779 --- /dev/null +++ b/src/renderer/Glass.h @@ -0,0 +1,59 @@ +#pragma once + +class CEntity; +class CVehicle; +class CPtrList; + +class CFallingGlassPane : public CMatrix +{ +public: + CVector m_vecMoveSpeed; + CVector m_vecTurn; + uint32 m_nTimer; + float m_fGroundZ; + float m_fStep; + uint8 m_nTriIndex; + bool m_bActive; + bool m_bShattered; + bool m_bCarGlass; + + CFallingGlassPane() { } + ~CFallingGlassPane() { } + + void Update(void); + void Render(void); +}; + +VALIDATE_SIZE(CFallingGlassPane, 0x70); + +enum +{ + NUM_GLASSTRIANGLES = 5, +}; + +class CGlass +{ + static uint32 NumGlassEntities; + static CEntity *apEntitiesToBeRendered[NUM_GLASSENTITIES]; + static CFallingGlassPane aGlassPanes[NUM_GLASSPANES]; +public: + static void Init(void); + static void Update(void); + static void Render(void); + static CFallingGlassPane *FindFreePane(void); + static void GeneratePanesForWindow(uint32 type, CVector pos, CVector up, CVector right, CVector speed, CVector center, float moveSpeed, bool cracked, bool explosion, int32 stepmul, bool carGlass); + static void AskForObjectToBeRenderedInGlass(CEntity *entity); + static void RenderEntityInGlass(CEntity *entity); + static int32 CalcAlphaWithNormal(CVector *normal); + static void RenderHiLightPolys(void); + static void RenderShatteredPolys(void); + static void RenderReflectionPolys(void); + static void WindowRespondsToCollision(CEntity *entity, float amount, CVector speed, CVector point, bool explosion); + static void WindowRespondsToSoftCollision(CEntity *entity, float amount); + static void WasGlassHitByBullet(CEntity *entity, CVector point); + static void WindowRespondsToExplosion(CEntity *entity, CVector point); + static void CarWindscreenShatters(CVehicle *vehicle, bool unk); + static bool HasGlassBeenShatteredAtCoors(float x, float y, float z); + static void FindWindowSectorList(CPtrList &list, float *dist, CEntity **entity, float x, float y, float z); + static void BreakGlassPhysically(CVector pos, float radius); +}; \ No newline at end of file diff --git a/src/renderer/Hud.cpp b/src/renderer/Hud.cpp new file mode 100644 index 00000000..33f33358 --- /dev/null +++ b/src/renderer/Hud.cpp @@ -0,0 +1,2083 @@ +#include "common.h" + +#include "Camera.h" +#include "DMAudio.h" +#include "Clock.h" +#include "Darkel.h" +#include "Hud.h" +#include "Messages.h" +#include "Frontend.h" +#include "Font.h" +#include "Pad.h" +#include "Radar.h" +#include "Replay.h" +#include "Wanted.h" +#include "Sprite.h" +#include "Sprite2d.h" +#include "Text.h" +#include "Timer.h" +#include "Script.h" +#include "TxdStore.h" +#include "User.h" +#include "World.h" +#include "CutsceneMgr.h" +#include "Stats.h" +#include "main.h" +#include "General.h" +#include "VarConsole.h" + +#if defined(FIX_BUGS) + #define SCREEN_SCALE_X_FIX(a) SCREEN_SCALE_X(a) + #define SCREEN_SCALE_Y_FIX(a) SCREEN_SCALE_Y(a) + #define SCALE_AND_CENTER_X_FIX(a) SCALE_AND_CENTER_X(a) +#else + #define SCREEN_SCALE_X_FIX(a) (a) + #define SCREEN_SCALE_Y_FIX(a) (a) + #define SCALE_AND_CENTER_X_FIX(a) (a) +#endif + +// Game has colors inlined in code. +// For easier modification we collect them here: +CRGBA MONEY_COLOR(0, 207, 133, 255); +CRGBA AMMO_COLOR(255, 150, 225, 255); +CRGBA HEALTH_COLOR(255, 150, 225, 255); +CRGBA ARMOUR_COLOR(185, 185, 185, 255); +CRGBA NOTWANTED_COLOR(27, 89, 130, 255); +CRGBA WANTED_COLOR_FLASH(62, 141, 181, 255); +CRGBA WANTED_COLOR(97, 194, 247, 255); +CRGBA ZONE_COLOR(45, 155, 90, 255); +CRGBA VEHICLE_COLOR(97, 194, 247, 255); +CRGBA CLOCK_COLOR(97, 194, 247, 255); +CRGBA TIMER_COLOR(97, 194, 247, 255); +CRGBA COUNTER_COLOR(97, 194, 247, 255); +CRGBA PAGER_COLOR(32, 162, 66, 205); +CRGBA RADARDISC_COLOR(255, 255, 255, 255); +CRGBA BIGMESSAGE_COLOR(255, 150, 225, 255); +CRGBA WASTEDBUSTED_COLOR(0, 207, 133, 255); +CRGBA ODDJOB_COLOR(0, 207, 133, 255); +CRGBA ODDJOB2_COLOR(97, 194, 247, 255); +CRGBA MISSIONTITLE_COLOR(220, 172, 2, 255); + +wchar CHud::m_HelpMessage[HELP_MSG_LENGTH]; +wchar CHud::m_LastHelpMessage[HELP_MSG_LENGTH]; +uint32 CHud::m_HelpMessageState; +uint32 CHud::m_HelpMessageTimer; +int32 CHud::m_HelpMessageFadeTimer; +wchar CHud::m_HelpMessageToPrint[HELP_MSG_LENGTH]; +float CHud::m_HelpMessageDisplayTime; +bool CHud::m_HelpMessageDisplayForever; +bool CHud::m_HelpMessageQuick; +uint32 CHud::m_ZoneState; +int32 CHud::m_ZoneFadeTimer; +uint32 CHud::m_ZoneNameTimer; +wchar *CHud::m_pZoneName; +wchar *CHud::m_pLastZoneName; +wchar *CHud::m_ZoneToPrint; +uint32 CHud::m_VehicleState; +int32 CHud::m_VehicleFadeTimer; +uint32 CHud::m_VehicleNameTimer; +wchar *CHud::m_VehicleName; +wchar *CHud::m_pLastVehicleName; +wchar *CHud::m_pVehicleNameToPrint; +wchar CHud::m_Message[256]; +wchar CHud::m_PagerMessage[256]; +bool CHud::m_Wants_To_Draw_Hud; +bool CHud::m_Wants_To_Draw_3dMarkers; +wchar CHud::m_BigMessage[6][128]; +int16 CHud::m_ItemToFlash; +bool CHud::m_HideRadar; +int32 CHud::m_ClockState; + +// These aren't really in CHud +float CHud::BigMessageInUse[6]; +float CHud::BigMessageAlpha[6]; +float CHud::BigMessageX[6]; +float CHud::OddJob2OffTimer; +bool CHud::CounterOnLastFrame[NUMONSCREENCOUNTERS]; +float CHud::OddJob2XOffset; +uint16 CHud::CounterFlashTimer[NUMONSCREENCOUNTERS]; +uint16 CHud::OddJob2Timer; +bool CHud::TimerOnLastFrame; +int16 CHud::OddJob2On; +uint16 CHud::TimerFlashTimer; +int16 CHud::PagerSoundPlayed; +int32 CHud::SpriteBrightness; +float CHud::PagerXOffset; +int16 CHud::PagerTimer; +int16 CHud::PagerOn; + +wchar *prevChaseString; + +uint32 CHud::m_WantedFadeTimer; +uint32 CHud::m_WantedState; +uint32 CHud::m_WantedTimer; +uint32 CHud::m_EnergyLostFadeTimer; +uint32 CHud::m_EnergyLostState; +uint32 CHud::m_EnergyLostTimer; +uint32 CHud::m_DisplayScoreFadeTimer; +uint32 CHud::m_DisplayScoreState; +uint32 CHud::m_DisplayScoreTimer; +uint32 CHud::m_WeaponFadeTimer; +uint32 CHud::m_WeaponState; +uint32 CHud::m_WeaponTimer; + +uint32 CHud::m_LastDisplayScore; +uint32 CHud::m_LastWanted; +uint32 CHud::m_LastWeapon; +uint32 CHud::m_LastTimeEnergyLost; + +CSprite2d CHud::Sprites[NUM_HUD_SPRITES]; + +struct +{ + const char *name; + const char *mask; +} WeaponFilenames[] = { + { "fist", "fistm" }, + { "brassk", "brasskA" }, + { "screw", "screwA" }, + { "golf", "golfA" }, + { "nightstick", "nightstickA" }, + { "knife", "knifeA" }, + { "bat", "batm" }, + { "hammer", "hammerA" }, + { "cleaver", "cleaverA" }, + { "machete", "macheteA" }, + { "sword", "swordA" }, + { "chainsaw", "chainsawA" }, + { "grenade", "grenadeA" }, + { "grenade", "grenadeA" }, + { "teargas", "teargasA" }, + { "molotov", "molotovA" }, + { "rocket", "rocketA" }, + { "handGun1", "handGun1A" }, + { "", "" }, + { "python", "pythonA" }, + { "chromegun", "chromegunA" }, + { "spasshotGun", "spasshotGunA" }, + { "stubshotGun", "stubshotGunA" }, + { "tec9", "tec9A" }, + { "uzi1", "uzi1A" }, + { "uzi2", "uzi2A" }, + { "mp5", "mp5A" }, + { "", "" }, + { "m4", "m4A" }, + { "ruger", "rugerA" }, + { "sniper", "sniperA" }, + { "laserscope", "laserscopeA" }, + { "", "" }, + { "rocket", "rocketA" }, + { "flamer", "flamerA" }, + { "m60", "m60A" }, + { "minigun", "minigunA" }, + { "bomb", "bombA" }, + { "", "" }, + { "camera", "cameraA" }, + { "", "" }, + { "siterocket", "siterocket" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "radardisc", "radardisc" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "", "" }, + { "sitesniper", "sitesniperm" }, + { "siteM16", "siteM16m" }, + { "sitelaser", "sitelaserm" }, + { "laserdot", "laserdotm" }, + { "viewfinder_128", "viewfinder_128m" }, + { "bleeder", "" } +}; + +RwTexture *gpSniperSightTex; +RwTexture *gpRocketSightTex; +RwTexture *gpLaserSightTex; +RwTexture *gpLaserDotTex; +RwTexture *gpViewFinderTex; + +void CHud::Draw() +{ + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERNEAREST); + RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void*)rwTEXTUREADDRESSCLAMP); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + + // disable hud via second controller + if (CPad::GetPad(1)->GetStartJustDown()) + m_Wants_To_Draw_Hud = !m_Wants_To_Draw_Hud; + + if (CReplay::IsPlayingBack()) + return; + + if (m_Wants_To_Draw_Hud && !TheCamera.m_WideScreenOn) { + // unused statics in here + bool DrawCrossHair = false; + bool CrossHairHidesHud = false; + bool DrawCrossHairPC = false; + + CPlayerPed *playerPed = FindPlayerPed(); + eWeaponType WeaponType = playerPed->GetWeapon()->m_eWeaponType; + int32 Mode = TheCamera.Cams[TheCamera.ActiveCam].Mode; + + if ((Mode == CCam::MODE_SNIPER || Mode == CCam::MODE_ROCKETLAUNCHER || Mode == CCam::MODE_M16_1STPERSON || Mode == CCam::MODE_HELICANNON_1STPERSON || Mode == CCam::MODE_CAMERA) + && playerPed && !playerPed->GetWeapon()->IsTypeMelee()) + DrawCrossHair = true; + + if (Mode == CCam::MODE_M16_1STPERSON_RUNABOUT || Mode == CCam::MODE_ROCKETLAUNCHER_RUNABOUT || Mode == CCam::MODE_SNIPER_RUNABOUT) + DrawCrossHairPC = true; + if (TheCamera.Cams[TheCamera.ActiveCam].Using3rdPersonMouseCam() && (!CPad::GetPad(0)->GetLookBehindForPed() || TheCamera.m_bPlayerIsInGarage) + || Mode == CCam::MODE_1STPERSON_RUNABOUT) { + if (playerPed) { + if (playerPed->m_nPedState != PED_ENTER_CAR && playerPed->m_nPedState != PED_CARJACK) { + + if (WeaponType >= WEAPONTYPE_COLT45 && WeaponType <= WEAPONTYPE_RUGER + || WeaponType == WEAPONTYPE_M60 || WeaponType == WEAPONTYPE_MINIGUN + || WeaponType == WEAPONTYPE_FLAMETHROWER) { + DrawCrossHairPC = 1; + } + } + } + } + + if (DrawCrossHair || DrawCrossHairPC) { + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR); + + SpriteBrightness = Min(SpriteBrightness+1, 30); + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + + float fStep = Sin((CTimer::GetTimeInMilliseconds() & 1023)/1024.0f * 6.28f); + float fMultBright = SpriteBrightness * 0.03f * (0.25f * fStep + 0.75f); + CRect rect; + if (DrawCrossHairPC && TheCamera.Cams[TheCamera.ActiveCam].Using3rdPersonMouseCam()) { + float f3rdX = SCREEN_WIDTH * TheCamera.m_f3rdPersonCHairMultX; + float f3rdY = SCREEN_HEIGHT * TheCamera.m_f3rdPersonCHairMultY; +#ifdef ASPECT_RATIO_SCALE + f3rdY -= SCREEN_SCALE_Y(2.0f); +#endif + if (playerPed && (WeaponType == WEAPONTYPE_M4 || WeaponType == WEAPONTYPE_RUGER || WeaponType == WEAPONTYPE_M60)) { + rect.left = f3rdX - SCREEN_SCALE_X(32.0f * 0.6f); + rect.top = f3rdY - SCREEN_SCALE_Y(32.0f * 0.6f); + rect.right = f3rdX + SCREEN_SCALE_X(32.0f * 0.6f); + rect.bottom = f3rdY + SCREEN_SCALE_Y(32.0f * 0.6f); + + Sprites[HUD_SITEM16].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); + } + else { + rect.left = f3rdX - SCREEN_SCALE_X(32.0f * 0.4f); + rect.top = f3rdY - SCREEN_SCALE_Y(32.0f * 0.4f); + rect.right = f3rdX + SCREEN_SCALE_X(32.0f * 0.4f); + rect.bottom = f3rdY + SCREEN_SCALE_Y(32.0f * 0.4f); + + Sprites[HUD_SITEM16].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); + } + } else { + if (Mode == CCam::MODE_M16_1STPERSON || + Mode == CCam::MODE_M16_1STPERSON_RUNABOUT || + Mode == CCam::MODE_HELICANNON_1STPERSON) { + rect.left = (SCREEN_WIDTH / 2) - SCREEN_SCALE_X(32.0f); + rect.top = (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(32.0f); + rect.right = (SCREEN_WIDTH / 2) + SCREEN_SCALE_X(32.0f); + rect.bottom = (SCREEN_HEIGHT / 2) + SCREEN_SCALE_Y(32.0f); + Sprites[HUD_SITEM16].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); + } + else if (Mode == CCam::MODE_1STPERSON_RUNABOUT) { + rect.left = (SCREEN_WIDTH / 2) - SCREEN_SCALE_X(32.0f * 0.7f); + rect.top = (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(32.0f * 0.7f); + rect.right = (SCREEN_WIDTH / 2) + SCREEN_SCALE_X(32.0f * 0.7f); + rect.bottom = (SCREEN_HEIGHT / 2) + SCREEN_SCALE_Y(32.0f * 0.7f); + + Sprites[HUD_SITEM16].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); + } + else if (Mode == CCam::MODE_ROCKETLAUNCHER || Mode == CCam::MODE_ROCKETLAUNCHER_RUNABOUT) { + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpRocketSightTex)); + + CSprite::RenderOneXLUSprite(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 1.0f, SCREEN_SCALE_X(40.0f), SCREEN_SCALE_Y(40.0f), (100.0f * fMultBright), (200.0f * fMultBright), (100.0f * fMultBright), 255, 1.0f, 255); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + } + else { + int sprite = HUD_SITESNIPER; + float xOffset = SCREEN_SCALE_X(210.0f); + float yOffset = SCREEN_SCALE_Y(210.0f); + + if (FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_LASERSCOPE) + sprite = HUD_SITELASER; + + if (FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_CAMERA) { + sprite = HUD_VIEWFINDER; + CrossHairHidesHud = true; + xOffset = SCREEN_SCALE_X(256.0f); + yOffset = SCREEN_SCALE_Y(192.0f); + } + + rect.left = SCREEN_WIDTH/2 - xOffset; + rect.top = SCREEN_HEIGHT/2 - yOffset; + rect.right = SCREEN_WIDTH/2; + rect.bottom = SCREEN_HEIGHT/2; + Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + 0.01f, 0.01f, 1.0f, 0.0f, 0.01f, 1.0f, 1.0f, 1.0f); + + rect.left = SCREEN_WIDTH/2; + rect.top = SCREEN_HEIGHT/2 - yOffset; + rect.right = SCREEN_WIDTH/2 + xOffset; + rect.bottom = SCREEN_HEIGHT/2; + Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + 0.99f, 0.0f, 0.01f, 0.01f, 0.99f, 1.0f, 0.01f, 1.0f); + + rect.left = SCREEN_WIDTH/2 - xOffset; + rect.top = SCREEN_HEIGHT/2; + rect.right = SCREEN_WIDTH/2; + rect.bottom = SCREEN_HEIGHT/2 + yOffset; + Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + 0.01f, 0.99f, 1.0f, 0.99f, 0.01f, 0.01f, 1.0f, 0.01f); + + rect.left = SCREEN_WIDTH/2; + rect.top = SCREEN_HEIGHT/2; + rect.right = SCREEN_WIDTH/2 + xOffset; + rect.bottom = SCREEN_HEIGHT/2 + yOffset; + Sprites[sprite].Draw(CRect(rect), CRGBA(255, 255, 255, 255), + 0.99f, 0.99f, 0.01f, 0.99f, 0.99f, 0.01f, 0.01f, 0.01f); + + CVector dotPos; + float size = 25.0f; + if (FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_LASERSCOPE && FindPlayerPed()->GetWeapon()->LaserScopeDot(&dotPos, &size)) { + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); +#ifdef FIX_BUGS + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); +#else + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVDESTALPHA); +#endif + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpLaserDotTex)); +#ifdef FIX_BUGS + int intensity = CGeneral::GetRandomNumberInRange(0, 37); +#else + int intensity = CGeneral::GetRandomNumberInRange(0, 35); +#endif + CSprite::RenderOneXLUSprite(dotPos.x, dotPos.y, dotPos.z, + SCREEN_SCALE_X(size), SCREEN_SCALE_Y(size), intensity - 36, 0, 0, intensity - 36, 1.0f, 127); + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + } + } + } + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + } + else { + SpriteBrightness = 0; + } + + if (CrossHairHidesHud) + return; + + /* + DrawMoneyCounter + */ + + wchar sPrint[16]; + wchar sPrintIcon[16]; + char sTemp[16]; + float alpha; + + if (m_LastDisplayScore == CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney) { + alpha = DrawFadeState(HUD_SCORE_FADING, 0); + } else { + alpha = DrawFadeState(HUD_SCORE_FADING, 1); + m_LastDisplayScore = CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney; + } + if (m_DisplayScoreState != FADED_OUT) { + sprintf(sTemp, "$%08d", CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney); + AsciiToUnicode(sTemp, sPrint); + + CFont::SetPropOff(); + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + CFont::SetCentreOff(); + CFont::SetRightJustifyOn(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetBackGroundOnlyTextOff(); + CFont::SetFontStyle(FONT_HEADING); + CFont::SetPropOff(); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, alpha)); + MONEY_COLOR.a = alpha; + CFont::SetColor(MONEY_COLOR); + + if (FrontEndMenuManager.m_PrefsShowHud) { + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f), SCREEN_SCALE_Y(43.0f), sPrint); + } + } + + /* + DrawAmmo + */ + if (m_LastWeapon == playerPed->GetWeapon()->m_eWeaponType) { + alpha = CHud::DrawFadeState(HUD_WEAPON_FADING, 0); + } else { + alpha = CHud::DrawFadeState(HUD_WEAPON_FADING, 1); + m_LastWeapon = playerPed->GetWeapon()->m_eWeaponType; + } + if (m_WeaponState != FADED_OUT) { + CWeapon *weapon = playerPed->GetWeapon(); + int32 AmmoAmount = CWeaponInfo::GetWeaponInfo((eWeaponType)WeaponType)->m_nAmountofAmmunition; + int32 AmmoInClip = weapon->m_nAmmoInClip; + int32 TotalAmmo = weapon->m_nAmmoTotal; + int32 Ammo, Clip; + + if (AmmoAmount <= 1 || AmmoAmount >= 1000) + sprintf(sTemp, "%d", TotalAmmo); + else { + if (WeaponType == WEAPONTYPE_FLAMETHROWER) { + Clip = AmmoInClip / 10; + + Ammo = Min((TotalAmmo - AmmoInClip) / 10, 9999); + } else { + Clip = AmmoInClip; + + Ammo = Min(TotalAmmo - AmmoInClip, 9999); + } + + sprintf(sTemp, "%d-%d", Ammo, Clip); + } + + AsciiToUnicode(sTemp, sPrint); + CWeaponInfo *weaponInfo = CWeaponInfo::GetWeaponInfo((eWeaponType)WeaponType); + /* + DrawWeaponIcon + */ + + if (FrontEndMenuManager.m_PrefsShowHud) { + if (weaponInfo->m_nModelId <= 0) { + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); + if (FrontEndMenuManager.m_PrefsShowHud) + Sprites[WeaponType].Draw( + CRect(SCREEN_SCALE_FROM_RIGHT(99.0f), SCREEN_SCALE_Y(27.0f), SCREEN_SCALE_FROM_RIGHT(35.0f), SCREEN_SCALE_Y(91.0f)), + CRGBA(255, 255, 255, alpha), + 0.015f, 0.015f, + 1.0f, 0.0f, + 0.015f, 1.0f, + 1.0f, 1.0f); + } else { + CBaseModelInfo *weaponModel = CModelInfo::GetModelInfo(weaponInfo->m_nModelId); + RwTexDictionary *weaponTxd = CTxdStore::GetSlot(weaponModel->GetTxdSlot())->texDict; + if (weaponTxd) { + RwTexture *weaponIcon = RwTexDictionaryFindNamedTexture(weaponTxd, weaponModel->GetModelName()); + if (weaponIcon) { + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); +#ifndef FIX_BUGS + const float xSize = SCREEN_SCALE_X(64.0f / 2.0f); + const float ySize = SCREEN_SCALE_Y(64.0f / 2.0f); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(weaponIcon)); + CSprite::RenderOneXLUSprite(SCREEN_SCALE_FROM_RIGHT(99.0f) + xSize, SCREEN_SCALE_Y(25.0f) + ySize, 1.0f, xSize, ySize, + 255, 255, 255, 255, 1.0f, 255); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); +#else + static CSprite2d sprite; + sprite.m_pTexture = weaponIcon; + sprite.Draw( + CRect(SCREEN_SCALE_FROM_RIGHT(99.0f), SCREEN_SCALE_Y(27.0f), SCREEN_SCALE_FROM_RIGHT(35.0f), SCREEN_SCALE_Y(91.0f)), + CRGBA(255, 255, 255, alpha), + 0.015f, 0.015f, + 1.0f, 0.0f, + 0.015f, 1.0f, + 1.0f, 1.0f); + sprite.m_pTexture = nil; +#endif + } + } + } + + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(0.5f), SCREEN_SCALE_Y(0.8f)); + CFont::SetJustifyOff(); + CFont::SetCentreOn(); + CFont::SetCentreSize(SCREEN_STRETCH_X(DEFAULT_SCREEN_WIDTH)); + CFont::SetPropOn(); + CFont::SetDropShadowPosition(0); + CFont::SetFontStyle(FONT_STANDARD); + + if (Min(9999, TotalAmmo - AmmoInClip) != 9999 && !CDarkel::FrenzyOnGoing() && weaponInfo->m_nWeaponSlot > 1 && weapon->m_eWeaponType != WEAPONTYPE_DETONATOR) { + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, alpha)); + AMMO_COLOR.a = alpha; + CFont::SetColor(AMMO_COLOR); + if (FrontEndMenuManager.m_PrefsShowHud) + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(66.0f), SCREEN_SCALE_Y(90.0f), sPrint); + CFont::SetDropShadowPosition(0); + } + } + } + + /* + DrawHealth + */ + if ( m_LastTimeEnergyLost == CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss ) { + CHud::DrawFadeState(HUD_ENERGY_FADING, 0); + } else { + CHud::DrawFadeState(HUD_ENERGY_FADING, 1); + m_LastTimeEnergyLost = CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss; + } + + if (m_EnergyLostState != FADED_OUT) { + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + CFont::SetJustifyOff(); + CFont::SetCentreOff(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetRightJustifyOn(); + CFont::SetPropOff(); + CFont::SetFontStyle(FONT_HEADING); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + + if (m_ItemToFlash == ITEM_HEALTH && CTimer::GetFrameCounter() & 8 + || m_ItemToFlash != ITEM_HEALTH + || playerPed->m_fHealth < 10 + && CTimer::GetFrameCounter() & 8) { + if (playerPed->m_fHealth >= 10 + || playerPed->m_fHealth < 10 && CTimer::GetFrameCounter() & 8) { + + AsciiToUnicode("{", sPrintIcon); +#ifdef FIX_BUGS + sprintf(sTemp, "%03d", int32(playerPed->m_fHealth + 0.5f)); +#else + sprintf(sTemp, "%03d", (int32)playerPed->m_fHealth); +#endif + AsciiToUnicode(sTemp, sPrint); + + CFont::SetColor(HEALTH_COLOR); + if (FrontEndMenuManager.m_PrefsShowHud) { + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f), SCREEN_SCALE_Y(65.0f), sPrint); + + if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss + 2000 || CTimer::GetFrameCounter() & 4) { + // CFont::SetColor(HEALTH_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 54.0f), SCREEN_SCALE_Y(65.0f), sPrintIcon); + } + } + } + } + + /* + DrawArmour + */ + if (m_ItemToFlash == ITEM_ARMOUR && CTimer::GetFrameCounter() & 8 || m_ItemToFlash != ITEM_ARMOUR) { + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + if (playerPed->m_fArmour > 1.0f) { + AsciiToUnicode("<", sPrintIcon); +#ifdef FIX_BUGS + sprintf(sTemp, "%03d", int32(playerPed->m_fArmour + 0.5f)); +#else + sprintf(sTemp, "%03d", (int32)playerPed->m_fArmour); +#endif + AsciiToUnicode(sTemp, sPrint); + + CFont::SetColor(ARMOUR_COLOR); + if (FrontEndMenuManager.m_PrefsShowHud) { + + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f), SCREEN_SCALE_Y(65.0f), sPrint); + + if (!CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss || CTimer::GetTimeInMilliseconds() > CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastArmourLoss + 2000 || CTimer::GetFrameCounter() & 4) { + // CFont::SetColor(ARMOUR_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(182.0f + 52.0f), SCREEN_SCALE_Y(65.0f), sPrintIcon); + } + } + } + } + } + + /* + DrawWantedLevel + */ + if (m_LastWanted == playerPed->m_pWanted->GetWantedLevel()) { + alpha = DrawFadeState(HUD_WANTED_FADING, 0); + } else { + alpha = DrawFadeState(HUD_WANTED_FADING, 1); + m_LastWanted = playerPed->m_pWanted->GetWantedLevel(); + } + + if (m_WantedState != FADED_OUT) { + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + CFont::SetJustifyOff(); + CFont::SetCentreOff(); + CFont::SetRightJustifyOn(); + CFont::SetPropOn(); + CFont::SetFontStyle(FONT_STANDARD); + + AsciiToUnicode(">", sPrintIcon); + + for (int i = 0; i < 6; i++) { + if (FrontEndMenuManager.m_PrefsShowHud) { + if (playerPed->m_pWanted->GetWantedLevel() > i + && (CTimer::GetTimeInMilliseconds() > playerPed->m_pWanted->m_nLastWantedLevelChange + + 2000 || CTimer::GetFrameCounter() & 4)) { + + WANTED_COLOR.a = alpha; + CFont::SetColor(WANTED_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(87.0f), sPrintIcon); + + } else if (playerPed->m_pWanted->m_nMinWantedLevel > i && CTimer::GetFrameCounter() & 4) { + WANTED_COLOR_FLASH.a = alpha; + CFont::SetColor(WANTED_COLOR_FLASH); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(87.0f), sPrintIcon); + + } else if (playerPed->m_pWanted->GetWantedLevel() <= i) { + NOTWANTED_COLOR.a = alpha; + CFont::SetColor(NOTWANTED_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(87.0f), sPrintIcon); + } + } + } + } + + static int32 nMediaLevelCounter = 0; + if (CStats::ShowChaseStatOnScreen != 0) { + float fCurAttentionLevel = CWorld::Players[CWorld::PlayerInFocus].m_fMediaAttention; + if (0.7f * CStats::HighestChaseValue > fCurAttentionLevel + || fCurAttentionLevel <= 40.0f || CTheScripts::IsPlayerOnAMission()) { + nMediaLevelCounter = 0; + } + else { + if (fCurAttentionLevel == CStats::HighestChaseValue) { + sprintf(gString, "%s %d", UnicodeToAscii(TheText.Get("CHSE")), (int32)fCurAttentionLevel); + } + else { + sprintf(gString, "%s %d" "-%d-", UnicodeToAscii(TheText.Get("CHSE")), (int32)fCurAttentionLevel, (int32)CStats::HighestChaseValue); + } + AsciiToUnicode(gString, gUString); + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + CFont::SetCentreOff(); + CFont::SetRightJustifyOn(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetBackGroundOnlyTextOff(); + CFont::SetFontStyle(FONT_HEADING); + CFont::SetPropOff(); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + + CRGBA colour; + if (CTimer::GetTimeInMilliseconds() & 0x200) + colour = CRGBA(204, 0, 185, 180); + else + colour = CRGBA(178, 0, 162, 180); + CFont::SetColor(colour); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f), SCREEN_SCALE_Y(113.0f), gUString); + + if (CStats::FindChaseString(fCurAttentionLevel) != prevChaseString) { + prevChaseString = CStats::FindChaseString(fCurAttentionLevel); + nMediaLevelCounter = 100; + } + + if (nMediaLevelCounter != 0) { + nMediaLevelCounter--; + UnicodeMakeUpperCase(gUString, CStats::FindChaseString(fCurAttentionLevel)); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f), SCREEN_SCALE_Y(138.0f), gUString); + } + } + } + + /* + DrawZoneName + */ + if (m_pZoneName) { + + if (m_pZoneName != m_pLastZoneName) { + switch (m_ZoneState) { + case 0: + m_ZoneState = 2; + m_ZoneToPrint = m_pZoneName; + m_ZoneNameTimer = 0; + m_ZoneFadeTimer = 0; + if (m_VehicleState == 1 || m_VehicleState == 2) + m_VehicleState = 3; + break; + case 1: + case 2: + case 3: + case 4: + m_ZoneNameTimer = 5; + m_ZoneState = 4; + break; + default: + break; + } + m_pLastZoneName = m_pZoneName; + } + + float fZoneAlpha = 255.0f; + if (m_ZoneState) { + switch (m_ZoneState) { + case 1: + fZoneAlpha = 255.0f; + m_ZoneFadeTimer = 1000; + if (m_ZoneNameTimer > 10000.0f) { + m_ZoneFadeTimer = 1000; + m_ZoneState = 3; + } + break; + case 2: + m_ZoneFadeTimer += CTimer::GetTimeStepInMilliseconds(); + if (m_ZoneFadeTimer > 1000.0f) { + m_ZoneState = 1; + m_ZoneFadeTimer = 1000; + } + fZoneAlpha = m_ZoneFadeTimer * 0.001f * 255.0f; + break; + case 3: + m_ZoneFadeTimer -= CTimer::GetTimeStepInMilliseconds(); + if (m_ZoneFadeTimer < 0.0f) { + m_ZoneState = 0; + m_ZoneFadeTimer = 0; + } + fZoneAlpha = m_ZoneFadeTimer * 0.001f * 255.0f; + break; + case 4: + m_ZoneFadeTimer -= CTimer::GetTimeStepInMilliseconds(); + if (m_ZoneFadeTimer < 0.0f) { + m_ZoneFadeTimer = 0; + m_ZoneToPrint = m_pLastZoneName; + m_ZoneState = 2; + } + fZoneAlpha = m_ZoneFadeTimer * 0.001f * 255.0f; + break; + default: + break; + + } + + if (!m_Message[0] && BigMessageInUse[1] == 0.0f && BigMessageInUse[2] == 0.0f) { + + m_ZoneNameTimer += CTimer::GetTimeStepInMilliseconds(); + CFont::SetJustifyOff(); + CFont::SetPropOn(); + CFont::SetBackgroundOff(); + + if (FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) + CFont::SetScale(SCREEN_SCALE_X(1.7f * 0.8f), SCREEN_SCALE_Y(1.8f)); + else + CFont::SetScale(SCREEN_SCALE_X(1.7f), SCREEN_SCALE_Y(1.8f)); + + CFont::SetSlantRefPoint(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(128.0f)); + CFont::SetSlant(0.15f); + + CFont::SetRightJustifyOn(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetBackGroundOnlyTextOff(); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, fZoneAlpha)); + CFont::SetFontStyle(FONT_BANK); + CFont::SetColor(CRGBA(ZONE_COLOR.r, ZONE_COLOR.g, ZONE_COLOR.b, fZoneAlpha)); + + if (!CTheScripts::bPlayerIsInTheStatium) + CFont::PrintStringFromBottom(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(128.0f), m_ZoneToPrint); + + CFont::SetSlant(0.f); + } else { + m_ZoneState = 3; + } + } + } + + /* + DrawVehicleName + */ + if (m_VehicleName) { + float fVehicleAlpha = 0.0f; + + if (m_VehicleName != m_pLastVehicleName) { + switch (m_VehicleState) { + case 0: + m_VehicleState = 2; + m_pVehicleNameToPrint = m_VehicleName; + m_VehicleNameTimer = 0; + m_VehicleFadeTimer = 0; + if (m_ZoneState == 1 || m_ZoneState == 2) + m_ZoneState = 3; + break; + case 1: + case 2: + case 3: + case 4: + m_VehicleNameTimer = 0; + m_VehicleState = 4; + break; + default: + break; + } + m_pLastVehicleName = m_VehicleName; + } + + if (m_VehicleState) { + switch (m_VehicleState) { + case 1: + if (m_VehicleNameTimer > 10000) { + m_VehicleFadeTimer = 1000; + m_VehicleState = 3; + } + fVehicleAlpha = 255.0f; + break; + case 2: + m_VehicleFadeTimer += CTimer::GetTimeStepInMilliseconds(); + if (m_VehicleFadeTimer > 1000) { + m_VehicleState = 1; + m_VehicleFadeTimer = 1000; + } + fVehicleAlpha = m_VehicleFadeTimer * 0.001f * 255.0f; + break; + case 3: + m_VehicleFadeTimer -= CTimer::GetTimeStepInMilliseconds(); + if (m_VehicleFadeTimer < 0) { + m_VehicleState = 0; + m_VehicleFadeTimer = 0; + } + fVehicleAlpha = m_VehicleFadeTimer * 0.001f * 255.0f; + break; + case 4: + m_VehicleFadeTimer -= CTimer::GetTimeStepInMilliseconds(); + if (m_VehicleFadeTimer < 0) { + m_VehicleFadeTimer = 0; + m_pVehicleNameToPrint = m_pLastVehicleName; + m_VehicleNameTimer = 0; + m_VehicleState = 2; + } + fVehicleAlpha = m_VehicleFadeTimer * 0.001f * 255.0f; + break; + default: + break; + } + + if (!m_Message[0]) { + m_VehicleNameTimer += CTimer::GetTimeStepInMilliseconds(); + CFont::SetJustifyOff(); + CFont::SetPropOn(); + CFont::SetBackgroundOff(); + + if (FrontEndMenuManager.m_PrefsLanguage != CMenuManager::LANGUAGE_ITALIAN && FrontEndMenuManager.m_PrefsLanguage != CMenuManager::LANGUAGE_SPANISH) + CFont::SetScale(SCREEN_SCALE_X(1.7f), SCREEN_SCALE_Y(1.8f)); + else + CFont::SetScale(SCREEN_SCALE_X(1.7f * 0.85f), SCREEN_SCALE_Y(1.8f)); + + CFont::SetSlantRefPoint(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(105.0f)); + CFont::SetSlant(0.15f); + + CFont::SetRightJustifyOn(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetBackGroundOnlyTextOff(); + CFont::SetFontStyle(FONT_BANK); + CFont::SetDropShadowPosition(2); + CFont::SetColor(CRGBA(VEHICLE_COLOR.r, VEHICLE_COLOR.g, VEHICLE_COLOR.b, fVehicleAlpha)); + CFont::SetDropColor(CRGBA(0, 0, 0, fVehicleAlpha)); + + CFont::PrintStringFromBottom(SCREEN_SCALE_FROM_RIGHT(32.0f), SCREEN_SCALE_FROM_BOTTOM(105.0f), m_pVehicleNameToPrint); + + CFont::SetSlant(0.f); + } + } + } + else { + m_pLastVehicleName = nil; + m_VehicleState = 0; + m_VehicleFadeTimer = 0; + m_VehicleNameTimer = 0; + } + + /* + DrawClock + */ + if (m_ClockState) { + CFont::SetJustifyOff(); + CFont::SetCentreOff(); + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + CFont::SetBackGroundOnlyTextOff(); + CFont::SetPropOff(); + CFont::SetFontStyle(FONT_HEADING); + CFont::SetRightJustifyOn(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + + sprintf(sTemp, "%02d:%02d", CClock::GetHours(), CClock::GetMinutes()); + AsciiToUnicode(sTemp, sPrint); + + CFont::SetColor(CLOCK_COLOR); + if (FrontEndMenuManager.m_PrefsShowHud) + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(111.0f), SCREEN_SCALE_Y(22.0f), sPrint); + } + + /* + DrawOnScreenTimer + */ + + wchar sTimer[16]; + + if (!CUserDisplay::OnscnTimer.m_sClocks[0].m_bClockProcessed) + TimerOnLastFrame = false; + + for(uint32 i = 0; i < NUMONSCREENCOUNTERS; i++) { + if (!CUserDisplay::OnscnTimer.m_sCounters[0].m_bCounterProcessed) + CounterOnLastFrame[i] = false; + } + + if (CUserDisplay::OnscnTimer.m_bProcessed) { + if (CUserDisplay::OnscnTimer.m_sClocks[0].m_bClockProcessed) { + if (!TimerOnLastFrame) + TimerFlashTimer = 1; + + TimerOnLastFrame = true; + + if (TimerFlashTimer != 0) { + if (++TimerFlashTimer > 50) + TimerFlashTimer = 0; + } + + if (CTimer::GetFrameCounter() & 4 || TimerFlashTimer == 0) { + AsciiToUnicode(CUserDisplay::OnscnTimer.m_sClocks[0].m_aClockBuffer, sTimer); + CFont::SetPropOn(); + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + CFont::SetRightJustifyOn(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); + CFont::SetPropOff(); + CFont::SetBackGroundOnlyTextOn(); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + CFont::SetColor(TIMER_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f), SCREEN_SCALE_Y(110.0f), sTimer); + CFont::SetPropOn(); + + if (CUserDisplay::OnscnTimer.m_sClocks[0].m_aClockText[0]) { + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetColor(TIMER_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f) - SCREEN_SCALE_X(80.0f), SCREEN_SCALE_Y(110.0f), TheText.Get(CUserDisplay::OnscnTimer.m_sClocks[0].m_aClockText)); + } + } + } + + for(uint32 i = 0; i < NUMONSCREENCOUNTERS; i++) { + if (CUserDisplay::OnscnTimer.m_sCounters[i].m_bCounterProcessed) { + if (!CounterOnLastFrame[i]) + CounterFlashTimer[i] = 1; + + CounterOnLastFrame[i] = true; + + if (CounterFlashTimer[i] != 0) { + if (++CounterFlashTimer[i] > 50) + CounterFlashTimer[i] = 0; + } + + if (CTimer::GetFrameCounter() & 4 || CounterFlashTimer[i] == 0) { + if (CUserDisplay::OnscnTimer.m_sCounters[i].m_nType == COUNTER_DISPLAY_NUMBER) { + AsciiToUnicode(CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterBuffer, sTimer); + CFont::SetPropOn(); + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + CFont::SetCentreOff(); + CFont::SetRightJustifyOn(); + CFont::SetRightJustifyWrap(0.0f); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); + CFont::SetWrapx(SCREEN_STRETCH_X(DEFAULT_SCREEN_WIDTH)); + CFont::SetPropOn(); + CFont::SetBackGroundOnlyTextOn(); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetColor(COUNTER_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y * 20.f * i) + SCREEN_SCALE_Y(132.0f), sTimer); + } else { + int counter = atoi(CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterBuffer); + + const float barWidth = SCREEN_SCALE_X(100.f / 2.f); + const float right = SCREEN_SCALE_FROM_RIGHT(37.0f); + const float left = right - barWidth; + + const float barHeight = SCREEN_SCALE_Y(11.0f); + const float top = SCREEN_SCALE_Y(132.0f) + SCREEN_SCALE_Y(8.0f) + SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y * 20.f * i); + const float bottom = top + barHeight; + + // shadow + CSprite2d::DrawRect(CRect(left + SCREEN_SCALE_X(6.0f), top + SCREEN_SCALE_Y(2.0f), right + SCREEN_SCALE_X(6.0f), bottom + SCREEN_SCALE_Y(2.0f)), CRGBA(0, 0, 0, 255)); + + CSprite2d::DrawRect(CRect(left + SCREEN_SCALE_X(4.0f), top, right + SCREEN_SCALE_X(4.0f), bottom), CRGBA(27, 89, 130, 255)); + CSprite2d::DrawRect(CRect(left + SCREEN_SCALE_X(4.0f), top, left + SCREEN_SCALE_X(counter) / 2.0f + SCREEN_SCALE_X(4.0f), bottom), CRGBA(97, 194, 247, 255)); + } + + if (CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterText[0]) { + CFont::SetPropOn(); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); + CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetColor(COUNTER_COLOR); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(37.0f) - SCREEN_SCALE_X(61.0f), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y * 20.f * i) + SCREEN_SCALE_Y(132.0f), TheText.Get(CUserDisplay::OnscnTimer.m_sCounters[i].m_aCounterText)); + } + // unused/leftover color. I wonder what was it for + CFont::SetColor(CRGBA(244, 225, 91, 255)); + } + } + } + } + + /* + DrawRadar + */ + if (FrontEndMenuManager.m_PrefsRadarMode != 2 && + !m_HideRadar && (m_ItemToFlash == ITEM_RADAR && CTimer::GetFrameCounter() & 8 || m_ItemToFlash != ITEM_RADAR)) { + + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERNEAREST); + CRadar::DrawMap(); + if (FrontEndMenuManager.m_PrefsRadarMode != 1) { + CRect rect(0.0f, 0.0f, SCREEN_SCALE_X(RADAR_WIDTH), SCREEN_SCALE_Y(RADAR_HEIGHT)); + + rect.Translate(SCREEN_SCALE_X_FIX(RADAR_LEFT), SCREEN_SCALE_FROM_BOTTOM(RADAR_BOTTOM + RADAR_HEIGHT)); + +#ifdef FIX_BUGS + rect.Grow(SCREEN_SCALE_X(6.0f), SCREEN_SCALE_X(6.0f), SCREEN_SCALE_Y(6.0f), SCREEN_SCALE_Y(6.0f)); +#else + rect.Grow(6.0f); +#endif + rect.Translate(SCREEN_SCALE_X_FIX(0.0f), SCREEN_SCALE_Y_FIX(2.0f)); + Sprites[HUD_RADARDISC].Draw(rect, CRGBA(0, 0, 0, 255)); + rect.Translate(SCREEN_SCALE_X_FIX(0.0f), SCREEN_SCALE_Y_FIX(-2.0f)); + Sprites[HUD_RADARDISC].Draw(rect, RADARDISC_COLOR); + } + CRadar::DrawBlips(); + } + } + + /* + Draw3dMarkers + */ + if (m_Wants_To_Draw_3dMarkers && !TheCamera.m_WideScreenOn && !m_BigMessage[0][0] && !m_BigMessage[2][0]) { + CRadar::Draw3dMarkers(); + } + + /* + DrawScriptText + */ + if (!CTimer::GetIsUserPaused()) { + for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroTextLines); i++) { + if (CTheScripts::IntroTextLines[i].m_Text[0] && CTheScripts::IntroTextLines[i].m_bTextBeforeFade) { + CFont::SetScale(SCREEN_SCALE_X(CTheScripts::IntroTextLines[i].m_fScaleX), SCREEN_SCALE_Y(CTheScripts::IntroTextLines[i].m_fScaleY * 0.5f)); + CFont::SetColor(CTheScripts::IntroTextLines[i].m_sColor); + + if (CTheScripts::IntroTextLines[i].m_bJustify) + CFont::SetJustifyOn(); + else + CFont::SetJustifyOff(); + + if (CTheScripts::IntroTextLines[i].m_bRightJustify) + CFont::SetRightJustifyOn(); + else + CFont::SetRightJustifyOff(); + + if (CTheScripts::IntroTextLines[i].m_bCentered) + CFont::SetCentreOn(); + else + CFont::SetCentreOff(); + + CFont::SetWrapx(SCALE_AND_CENTER_X(CTheScripts::IntroTextLines[i].m_fWrapX)); + CFont::SetCentreSize(SCREEN_SCALE_X(CTheScripts::IntroTextLines[i].m_fCenterSize)); + + if (CTheScripts::IntroTextLines[i].m_bBackground) + CFont::SetBackgroundOn(); + else + CFont::SetBackgroundOff(); + + CFont::SetBackgroundColor(CTheScripts::IntroTextLines[i].m_sBackgroundColor); + + if (CTheScripts::IntroTextLines[i].m_bBackgroundOnly) + CFont::SetBackGroundOnlyTextOn(); + else + CFont::SetBackGroundOnlyTextOff(); + + if (CTheScripts::IntroTextLines[i].m_bTextProportional) + CFont::SetPropOn(); + else + CFont::SetPropOff(); + + CFont::SetFontStyle(FONT_LOCALE(CTheScripts::IntroTextLines[i].m_nFont)); + CFont::PrintString(SCREEN_WIDTH - SCALE_AND_CENTER_X(DEFAULT_SCREEN_WIDTH - CTheScripts::IntroTextLines[i].m_fAtX), SCREEN_HEIGHT - SCREEN_SCALE_Y(DEFAULT_SCREEN_HEIGHT - CTheScripts::IntroTextLines[i].m_fAtY), CTheScripts::IntroTextLines[i].m_Text); + } + } + for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroRectangles); i++) { + intro_script_rectangle &IntroRect = CTheScripts::IntroRectangles[i]; + + // Yeah, top and bottom changed place. R* vision + if (IntroRect.m_bIsUsed && IntroRect.m_bBeforeFade) { + if (IntroRect.m_nTextureId >= 0) { + CRect rect ( + IntroRect.m_sRect.left, + IntroRect.m_sRect.bottom, + IntroRect.m_sRect.right, + IntroRect.m_sRect.top ); + + CTheScripts::ScriptSprites[IntroRect.m_nTextureId].Draw(rect, IntroRect.m_sColor); + } + else { + CRect rect ( + IntroRect.m_sRect.left, + IntroRect.m_sRect.bottom, + IntroRect.m_sRect.right, + IntroRect.m_sRect.top ); + + CSprite2d::DrawRect(rect, IntroRect.m_sColor); + } + } + } + + /* + DrawSubtitles + */ + if (m_Message[0] && !m_BigMessage[2][0]) { + if (m_VehicleState != 0) + m_VehicleState = 3; + if (m_ZoneState != 0) + m_ZoneState = 3; + + CFont::SetJustifyOff(); + CFont::SetBackgroundOff(); + CFont::SetBackgroundColor(CRGBA(0, 0, 0, 128)); + CFont::SetCentreOn(); + CFont::SetPropOn(); +#ifdef CUTSCENE_BORDERS_SWITCH + if (!FrontEndMenuManager.m_PrefsCutsceneBorders) { + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetDropShadowPosition(2); + } + else +#endif + CFont::SetDropShadowPosition(0); + CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); + CFont::SetColor(CRGBA(225, 225, 225, 255)); + + static bool onceItWasWidescreen = false; + + if (TheCamera.m_WideScreenOn) { + onceItWasWidescreen = true; + + if (FrontEndMenuManager.m_PrefsShowSubtitles || !CCutsceneMgr::IsRunning()) { + CFont::SetCentreSize(SCREEN_WIDTH - SCREEN_SCALE_X(60.0f)); + CFont::SetScale(SCREEN_SCALE_X(0.58f), SCREEN_SCALE_Y(1.2f)); + CFont::PrintString(SCREEN_WIDTH / 2.f, SCREEN_SCALE_FROM_BOTTOM(80.0f), m_Message); + } + } else { + if (onceItWasWidescreen) + m_Message[0] = '\0'; + + onceItWasWidescreen = false; + CFont::DrawFonts(); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetScale(SCREEN_SCALE_X(0.58f), SCREEN_SCALE_Y(1.22f)); + + float radarBulge = SCREEN_SCALE_X(140.0f) + SCREEN_SCALE_X(8.0f); + float rectWidth = SCREEN_WIDTH - SCREEN_SCALE_X(20.0f) - SCREEN_SCALE_X(8.0f) - radarBulge; + CFont::SetCentreSize(rectWidth); + + CFont::PrintString(rectWidth / 2.0f + radarBulge, SCREEN_SCALE_FROM_BOTTOM(105.f + 2.0f), m_Message); + } + CFont::SetDropShadowPosition(0); + } + + /* + HelpMessage + */ + + if (m_HelpMessage[0]) { + if (!CMessages::WideStringCompare(m_HelpMessage, m_LastHelpMessage, HELP_MSG_LENGTH)) { + switch (m_HelpMessageState) { + case 0: + m_HelpMessageFadeTimer = 0; + m_HelpMessageState = 2; + m_HelpMessageTimer = 0; + CMessages::WideStringCopy(m_HelpMessageToPrint, m_HelpMessage, HELP_MSG_LENGTH); + m_HelpMessageDisplayTime = CMessages::GetWideStringLength(m_HelpMessage) * 0.05f + 3.0f; + + if (TheCamera.m_ScreenReductionPercentage == 0.0f) + DMAudio.PlayFrontEndSound(SOUND_HUD, 0); + break; + case 1: + case 2: + case 3: + case 4: + m_HelpMessageTimer = 5; + m_HelpMessageState = 4; + break; + default: + break; + } + CMessages::WideStringCopy(m_LastHelpMessage, m_HelpMessage, HELP_MSG_LENGTH); + } + + float fAlpha = 225.0f; + + if (m_HelpMessageState != 0) { + switch (m_HelpMessageState) { + case 1: + fAlpha = 225.0f; + m_HelpMessageFadeTimer = 600; + if (!m_HelpMessageDisplayForever && m_HelpMessageTimer > m_HelpMessageDisplayTime * 1000.0f || + m_HelpMessageQuick && m_HelpMessageTimer > 1500.0f) { + + m_HelpMessageFadeTimer = 600; + m_HelpMessageState = 3; + } + break; + case 2: + if (TheCamera.m_WideScreenOn) + break; + + m_HelpMessageFadeTimer += 2 * CTimer::GetTimeStepInMilliseconds(); + if (m_HelpMessageFadeTimer > 0) { + m_HelpMessageState = 1; + m_HelpMessageFadeTimer = 0; + } + fAlpha = m_HelpMessageFadeTimer * 0.001f * 225.0f; + break; + case 3: + m_HelpMessageFadeTimer -= 2 * CTimer::GetTimeStepInMilliseconds(); + if (m_HelpMessageFadeTimer < 0 || TheCamera.m_WideScreenOn) { + m_HelpMessageState = 0; + m_HelpMessageFadeTimer = 0; + } + fAlpha = m_HelpMessageFadeTimer * 0.001f * 225.0f; + break; + case 4: + m_HelpMessageFadeTimer -= 2 * CTimer::GetTimeStepInMilliseconds(); + if (m_HelpMessageFadeTimer < 0) { + m_HelpMessageState = 2; + m_HelpMessageFadeTimer = 0; + CMessages::WideStringCopy(m_HelpMessageToPrint, m_LastHelpMessage, HELP_MSG_LENGTH); + } + fAlpha = m_HelpMessageFadeTimer * 0.001f * 225.0f; + break; + default: + break; + } + + if (!TheCamera.m_WideScreenOn) { + m_HelpMessageTimer += CTimer::GetTimeStepInMilliseconds(); + + CFont::SetAlphaFade(fAlpha); + CFont::SetCentreOff(); + CFont::SetPropOn(); + + if (CGame::germanGame) + CFont::SetScale(SCREEN_SCALE_X(0.52f * 0.85f), SCREEN_SCALE_Y(1.1f * 0.85f)); +#ifdef MORE_LANGUAGES + else if (CFont::IsJapanese()) + CFont::SetScale(SCREEN_SCALE_X(0.52f) * 1.35f, SCREEN_SCALE_Y(1.1f) * 1.25f); +#endif + else + CFont::SetScale(SCREEN_SCALE_X(0.52f), SCREEN_SCALE_Y(1.1f)); + + CFont::DrawFonts(); + CFont::SetColor(CRGBA(175, 175, 175, 255)); + CFont::SetJustifyOff(); +#ifdef MORE_LANGUAGES + if (CFont::IsJapanese()) + CFont::SetWrapx(SCREEN_SCALE_X(229.0f + 34.0f - 4.0f)); + else +#endif + CFont::SetWrapx(SCREEN_SCALE_X(200.0f + 34.0f - 4.0f)); + CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); + CFont::SetBackgroundOn(); + CFont::SetBackGroundOnlyTextOff(); + CFont::SetDropShadowPosition(0); + CFont::SetBackgroundColor(CRGBA(0, 0, 0, fAlpha * 0.9f)); + CFont::SetColor(CRGBA(175, 175, 175, 255)); + CFont::PrintString(SCREEN_SCALE_X(34.0f), SCREEN_SCALE_Y(28.0f + (150.0f - PagerXOffset) * 0.6f), m_HelpMessageToPrint); + CFont::SetAlphaFade(255.0f); + CFont::SetWrapx(SCREEN_WIDTH); + } + } + } else + m_HelpMessageState = 0; + + /* + DrawBigMessage + */ + // MissionCompleteFailedText + if (m_BigMessage[0][0]) { + if (BigMessageInUse[0] != 0.0f) { + CFont::SetJustifyOff(); + CFont::SetBackgroundOff(); + CFont::SetBackGroundOnlyTextOff(); + if (CGame::frenchGame || CGame::germanGame) { + CFont::SetScale(SCREEN_SCALE_X(1.6f), SCREEN_SCALE_Y(1.8f)); + } else { + CFont::SetScale(SCREEN_SCALE_X(1.8f), SCREEN_SCALE_Y(1.8f)); + } + CFont::SetPropOn(); + CFont::SetCentreOn(); + CFont::SetCentreSize(SCREEN_SCALE_X(590.0f)); + CFont::SetColor(CRGBA(255, 255, 0, BigMessageAlpha[0])); // unused color + CFont::SetFontStyle(FONT_HEADING); + + // Appearently sliding text in here was abandoned very early, since this text is centered now. + + if (BigMessageX[0] >= SCALE_AND_CENTER_X(620.0f)) { + BigMessageInUse[0] += CTimer::GetTimeStep(); + + if (BigMessageInUse[0] >= 120.0f) { + BigMessageInUse[0] = 120.0f; + BigMessageAlpha[0] -= (CTimer::GetTimeStepInMilliseconds() * 0.3f); + } + + if (BigMessageAlpha[0] <= 0.0f) { + m_BigMessage[0][0] = 0; + BigMessageAlpha[0] = 0.0f; + } + } + else { + BigMessageX[0] += SCREEN_SCALE_X((CTimer::GetTimeStepInMilliseconds() * 0.3f)); + BigMessageAlpha[0] += (CTimer::GetTimeStepInMilliseconds() * 0.3f); + + if (BigMessageAlpha[0] > 255.0f) + BigMessageAlpha[0] = 255.0f; + } + CFont::DrawFonts(); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, BigMessageAlpha[0])); + CFont::SetColor(CRGBA(BIGMESSAGE_COLOR.r, BIGMESSAGE_COLOR.g, BIGMESSAGE_COLOR.b, BigMessageAlpha[0])); + CFont::PrintString(SCREEN_WIDTH / 2, (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(18.0f), m_BigMessage[0]); + } + else { + BigMessageAlpha[0] = 0.0f; + BigMessageX[0] = SCALE_AND_CENTER_X(-60.0f); + BigMessageInUse[0] = 1.0f; + } + } + else { + BigMessageInUse[0] = 0.0f; + } + + // WastedBustedText + if (m_BigMessage[2][0]) { + if (BigMessageInUse[2] != 0.0f) { + BigMessageAlpha[2] += (CTimer::GetTimeStepInMilliseconds() * 0.4f); + + if (BigMessageAlpha[2] > 255.0f) + BigMessageAlpha[2] = 255.0f; + + CFont::SetBackgroundOff(); + + if (CGame::frenchGame || CGame::germanGame) + CFont::SetScale(SCREEN_SCALE_X(1.4f), SCREEN_SCALE_Y(1.4f)); + else + CFont::SetScale(SCREEN_SCALE_X(2.0f), SCREEN_SCALE_Y(2.0f)); + + CFont::SetPropOn(); + CFont::SetRightJustifyOn(); + CFont::SetFontStyle(FONT_HEADING); + + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, BigMessageAlpha[2])); + + CFont::SetColor(CRGBA(WASTEDBUSTED_COLOR.r, WASTEDBUSTED_COLOR.g, WASTEDBUSTED_COLOR.b, BigMessageAlpha[2])); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(90.0f), m_BigMessage[2]); + } + else { + BigMessageInUse[2] = 1.0f; + BigMessageAlpha[2] = 0.0f; + if (m_VehicleState != 0) // Hide vehicle name if wasted/busted text is displaying + m_VehicleState = 0; + if (m_ZoneState != 0) + m_ZoneState = 0; + } + } + else { + BigMessageInUse[2] = 0.0f; + } + } +} + +void CHud::DrawAfterFade() +{ + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERNEAREST); + RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void*)rwTEXTUREADDRESSCLAMP); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + + if (CTimer::GetIsUserPaused() || CReplay::IsPlayingBack()) + return; + + for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroTextLines); i++) { + intro_text_line &line = CTheScripts::IntroTextLines[i]; + if (line.m_Text[0] != '\0' && !line.m_bTextBeforeFade) { + CFont::SetScale(SCREEN_SCALE_X(line.m_fScaleX), SCREEN_SCALE_Y(line.m_fScaleY) / 2); + + CFont::SetColor(line.m_sColor); + if (line.m_bJustify) + CFont::SetJustifyOn(); + else + CFont::SetJustifyOff(); + + if (line.m_bRightJustify) + CFont::SetRightJustifyOn(); + else + CFont::SetRightJustifyOff(); + + if (line.m_bCentered) + CFont::SetCentreOn(); + else + CFont::SetCentreOff(); + + CFont::SetWrapx(SCALE_AND_CENTER_X(line.m_fWrapX)); + CFont::SetCentreSize(SCREEN_SCALE_X(line.m_fCenterSize)); + if (line.m_bBackground) + CFont::SetBackgroundOn(); + else + CFont::SetBackgroundOff(); + + CFont::SetBackgroundColor(line.m_sBackgroundColor); + if (line.m_bBackgroundOnly) + CFont::SetBackGroundOnlyTextOn(); + else + CFont::SetBackGroundOnlyTextOff(); + + if (line.m_bTextProportional) + CFont::SetPropOn(); + else + CFont::SetPropOff(); + + CFont::SetFontStyle(line.m_nFont); + CFont::PrintString(SCREEN_WIDTH - SCALE_AND_CENTER_X(DEFAULT_SCREEN_WIDTH - line.m_fAtX), SCREEN_HEIGHT - SCREEN_SCALE_Y(DEFAULT_SCREEN_HEIGHT - line.m_fAtY), line.m_Text); + } + } + for (int i = 0; i < ARRAY_SIZE(CTheScripts::IntroRectangles); i++) { + intro_script_rectangle &rectangle = CTheScripts::IntroRectangles[i]; + if (rectangle.m_bIsUsed && !rectangle.m_bBeforeFade) { + + // Yeah, top and bottom changed place. R* vision + if (rectangle.m_nTextureId >= 0) { + CTheScripts::ScriptSprites[rectangle.m_nTextureId].Draw(CRect(rectangle.m_sRect.left, rectangle.m_sRect.bottom, + rectangle.m_sRect.right, rectangle.m_sRect.top), rectangle.m_sColor); + } else { + CSprite2d::DrawRect(CRect(rectangle.m_sRect.left, rectangle.m_sRect.bottom, + rectangle.m_sRect.right, rectangle.m_sRect.top), rectangle.m_sColor); + } + } + } + + /* + DrawBigMessage2 + */ + // Oddjob + if (m_BigMessage[3][0]) { + CFont::SetJustifyOff(); + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(1.2f), SCREEN_SCALE_Y(1.5f)); + CFont::SetCentreOn(); + CFont::SetPropOn(); + CFont::SetCentreSize(SCREEN_SCALE_X(600.0f)); + CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetColor(ODDJOB_COLOR); + CFont::PrintString((SCREEN_WIDTH / 2), SCREEN_SCALE_Y(140.0f) - SCREEN_SCALE_Y(16.0f), m_BigMessage[3]); + } + + if (!m_BigMessage[1][0] && m_BigMessage[4][0]) { + CFont::SetJustifyOff(); + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(1.2f), SCREEN_SCALE_Y(1.5f)); + CFont::SetCentreOn(); + CFont::SetPropOn(); + CFont::SetCentreSize(SCREEN_SCALE_X(580.0f)); + CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetColor(ODDJOB_COLOR); + CFont::PrintString((SCREEN_WIDTH / 2), SCREEN_SCALE_Y(140.0f), m_BigMessage[4]); + } + + // Oddjob result + if (OddJob2OffTimer > 0) + OddJob2OffTimer -= CTimer::GetTimeStepInMilliseconds(); + + float fStep; + if (m_BigMessage[5][0] && OddJob2OffTimer <= 0.0f) { + switch (OddJob2On) { + case 0: + OddJob2On = 1; + OddJob2XOffset = 380.0f; + break; + case 1: + if (OddJob2XOffset <= 2.0f) { + OddJob2Timer = 0; + OddJob2On = 2; + } + else { + fStep = Min(40.0f, OddJob2XOffset / 6.0f); + OddJob2XOffset = OddJob2XOffset - fStep; + } + break; + case 2: + OddJob2Timer += CTimer::GetTimeStepInMilliseconds(); + if (OddJob2Timer > 1500) { + OddJob2On = 3; + } + break; + case 3: + fStep = Max(30.0f, OddJob2XOffset / 5.0f); + + OddJob2XOffset = OddJob2XOffset - fStep; + + if (OddJob2XOffset < -380.0f) { + OddJob2OffTimer = 5000.0f; + OddJob2On = 0; + } + break; + default: + break; + } + + if (!m_BigMessage[1][0]) { + CFont::SetJustifyOff(); + CFont::SetBackgroundOff(); + CFont::SetScale(SCREEN_SCALE_X(1.0f), SCREEN_SCALE_Y(1.2f)); + CFont::SetCentreOn(); + CFont::SetPropOn(); + CFont::SetCentreSize(SCREEN_SCALE_X(560.0f)); + CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetColor(ODDJOB2_COLOR); + CFont::PrintString(SCREEN_WIDTH / 2, SCREEN_SCALE_Y(217.0f), m_BigMessage[5]); + } + } + + /* + DrawMissionTitle + */ + if (m_BigMessage[1][0]) { + if (BigMessageInUse[1] != 0.0f) { + CFont::SetJustifyOff(); + CFont::SetBackgroundOff(); + + // will be overwritten below + if (CGame::frenchGame || FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_SPANISH) + CFont::SetScale(SCREEN_SCALE_X(0.884f), SCREEN_SCALE_Y(1.36f)); + else + CFont::SetScale(SCREEN_SCALE_X(1.04f), SCREEN_SCALE_Y(1.6f)); + + CFont::SetPropOn(); + CFont::SetRightJustifyWrap(SCALE_AND_CENTER_X(0.0f)); + CFont::SetRightJustifyOn(); + CFont::SetFontStyle(FONT_BANK); + CFont::SetScale(FrontEndMenuManager.m_PrefsLanguage == CMenuManager::LANGUAGE_AMERICAN ? SCREEN_SCALE_X(1.7f) : SCREEN_SCALE_X(1.5f), SCREEN_SCALE_Y(1.8f)); + + if (BigMessageX[1] >= SCREEN_SCALE_FROM_RIGHT(20.0f)) { + BigMessageInUse[1] += CTimer::GetTimeStep(); + + if (BigMessageInUse[1] >= 120.0f) { + BigMessageInUse[1] = 120.0f; + BigMessageAlpha[1] -= CTimer::GetTimeStepInMilliseconds(); + } + if (BigMessageAlpha[1] <= 0.0f) { + m_BigMessage[1][0] = 0; + BigMessageInUse[1] = 0.0f; + BigMessageAlpha[1] = 0.0f; + } + } else { + BigMessageX[1] += SCREEN_SCALE_X((CTimer::GetTimeStepInMilliseconds() * 0.3f)); + BigMessageAlpha[1] += CTimer::GetTimeStepInMilliseconds(); + + if (BigMessageAlpha[1] > 255.0f) + BigMessageAlpha[1] = 255.0f; + } + + CFont::SetColor(CRGBA(40, 40, 40, BigMessageAlpha[1])); // what was that for? + + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, BigMessageAlpha[1])); + CFont::SetColor(CRGBA(MISSIONTITLE_COLOR.r, MISSIONTITLE_COLOR.g, MISSIONTITLE_COLOR.b, BigMessageAlpha[1])); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(140.0f), m_BigMessage[1]); + } else { + m_ZoneFadeTimer = 0; + BigMessageX[1] = SCREEN_SCALE_FROM_RIGHT(DEFAULT_SCREEN_WIDTH + 60.0f); + BigMessageInUse[1] = 1.0f; + m_ZoneState = 0; + } + } else { + BigMessageInUse[1] = 0.0f; + } +} + +void CHud::GetRidOfAllHudMessages() +{ + m_ZoneNameTimer = 0; + m_pZoneName = nil; + m_ZoneState = 0; + + for (int i = 0; i < HELP_MSG_LENGTH; i++) { + m_HelpMessage[i] = 0; + m_LastHelpMessage[i] = 0; + m_HelpMessageToPrint[i] = 0; + } + + m_HelpMessageTimer = 0; + m_HelpMessageFadeTimer = 0; + m_HelpMessageState = 0; + m_HelpMessageQuick = 0; + m_HelpMessageDisplayForever = false; + m_HelpMessageDisplayTime = 1.0f; + m_VehicleName = nil; + m_pVehicleNameToPrint = nil; + m_VehicleNameTimer = 0; + m_VehicleFadeTimer = 0; + m_VehicleState = 0; + + for (int i = 0; i < ARRAY_SIZE(m_Message); i++) + m_Message[i] = 0; + + for (int i = 0; i < 6; i++) { + BigMessageInUse[i] = 0.0f; + + for (int j = 0; j < 128; j++) + m_BigMessage[i][j] = 0; + } +} + +#ifdef RELOADABLES +void CHud::ReloadTXD() +{ + for (int i = 0; i < NUM_HUD_SPRITES; ++i) { + Sprites[i].Delete(); + } + + int HudTXD = CTxdStore::FindTxdSlot("hud"); + CTxdStore::RemoveTxdSlot(HudTXD); + + debug("Reloading HUD.TXD...\n"); + + HudTXD = CTxdStore::AddTxdSlot("hud"); + CTxdStore::LoadTxd(HudTXD, "MODELS/HUD.TXD"); + CTxdStore::AddRef(HudTXD); + CTxdStore::PopCurrentTxd(); + CTxdStore::SetCurrentTxd(HudTXD); + + for (int i = 0; i < NUM_HUD_SPRITES; i++) { + Sprites[i].SetTexture(WeaponFilenames[i].name, WeaponFilenames[i].mask); + } +} +#endif + +void CHud::Initialise() +{ + m_Wants_To_Draw_Hud = true; + m_Wants_To_Draw_3dMarkers = true; + + int HudTXD = CTxdStore::AddTxdSlot("hud"); + CTxdStore::LoadTxd(HudTXD, "MODELS/HUD.TXD"); + CTxdStore::AddRef(HudTXD); + CTxdStore::PopCurrentTxd(); + CTxdStore::SetCurrentTxd(HudTXD); + + for (int i = 0; i < NUM_HUD_SPRITES; i++) { + Sprites[i].SetTexture(WeaponFilenames[i].name, WeaponFilenames[i].mask); + } + + m_pLastZoneName = nil; + GetRidOfAllHudMessages(); + m_pLastVehicleName = nil; + + if (gpSniperSightTex == nil) + gpSniperSightTex = RwTextureRead("sitesniper", nil); // unused + if (gpRocketSightTex == nil) + gpRocketSightTex = RwTextureRead("siterocket", nil); + if (gpLaserSightTex == nil) + gpLaserSightTex = RwTextureRead("sitelaser", nil); // unused + if (gpLaserDotTex == nil) + gpLaserDotTex = RwTextureRead("laserdot", "laserdotm"); + if (gpViewFinderTex == nil) + gpViewFinderTex = RwTextureRead("viewfinder_128", "viewfinder_128m"); // unused + + m_ClockState = 1; + CounterOnLastFrame[0] = false; + CounterOnLastFrame[1] = false; + CounterOnLastFrame[2] = false; + + m_ItemToFlash = ITEM_NONE; + OddJob2Timer = 0; + OddJob2OffTimer = 0.0f; + OddJob2On = 0; + OddJob2XOffset = 0.0f; + CounterFlashTimer[0] = 0; + CounterFlashTimer[1] = 0; + CounterFlashTimer[2] = 0; + TimerOnLastFrame = false; + TimerFlashTimer = 0; + SpriteBrightness = 0; + PagerOn = 0; + PagerTimer = 0; + PagerSoundPlayed = 0; + PagerXOffset = 150.0f; + +#ifdef HUD_AUTO_FADE + m_EnergyLostState = START_FADE_OUT; + m_WantedState = START_FADE_OUT; + m_DisplayScoreState = START_FADE_OUT; + m_WeaponState = START_FADE_OUT; +#else + m_EnergyLostState = FADE_DISABLED; + m_WantedState = FADE_DISABLED; + m_DisplayScoreState = FADE_DISABLED; + m_WeaponState = FADE_DISABLED; +#endif + m_WantedFadeTimer = 0; + m_WantedTimer = 0; + m_EnergyLostFadeTimer = 0; + m_EnergyLostTimer = 0; + m_DisplayScoreFadeTimer = 0; + m_DisplayScoreTimer = 0; + m_WeaponFadeTimer = 0; + m_WeaponTimer = 0; + + m_HideRadar = false; + m_LastDisplayScore = CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney; + m_LastTimeEnergyLost = CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss; + m_LastWanted = 0; + m_LastWeapon = 0; + +#ifndef MASTER + VarConsole.Add("Draw HUD", &m_Wants_To_Draw_Hud, false); +#endif + CTxdStore::PopCurrentTxd(); +} + +void CHud::ReInitialise() { + m_Wants_To_Draw_Hud = true; + m_Wants_To_Draw_3dMarkers = true; + + m_pLastZoneName = nil; + GetRidOfAllHudMessages(); + m_pLastVehicleName = nil; + + CounterOnLastFrame[0] = false; + CounterOnLastFrame[1] = false; + CounterOnLastFrame[2] = false; + m_ItemToFlash = ITEM_NONE; + m_ClockState = 1; + OddJob2Timer = 0; + OddJob2OffTimer = 0.0f; + OddJob2On = 0; + OddJob2XOffset = 0.0f; + CounterFlashTimer[0] = 0; + CounterFlashTimer[1] = 0; + CounterFlashTimer[2] = 0; + TimerOnLastFrame = false; + TimerFlashTimer = 0; + SpriteBrightness = 0; + PagerOn = 0; + PagerTimer = 0; + PagerSoundPlayed = 0; + PagerXOffset = 150.0f; + +#ifdef HUD_AUTO_FADE + m_EnergyLostState = START_FADE_OUT; + m_WantedState = START_FADE_OUT; + m_DisplayScoreState = START_FADE_OUT; + m_WeaponState = START_FADE_OUT; +#else + m_EnergyLostState = FADE_DISABLED; + m_WantedState = FADE_DISABLED; + m_DisplayScoreState = FADE_DISABLED; + m_WeaponState = FADE_DISABLED; +#endif + m_WantedFadeTimer = 0; + m_WantedTimer = 0; + m_EnergyLostFadeTimer = 0; + m_EnergyLostTimer = 0; + m_DisplayScoreFadeTimer = 0; + m_DisplayScoreTimer = 0; + m_WeaponFadeTimer = 0; + m_WeaponTimer = 0; + + m_HideRadar = false; + m_LastDisplayScore = CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney; + m_LastTimeEnergyLost = CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss; + m_LastWanted = 0; + m_LastWeapon = 0; +} + +wchar LastBigMessage[6][128]; + +void CHud::SetBigMessage(wchar *message, uint16 style) +{ + int i = 0; + + if (BigMessageInUse[style] != 0.0f) + return; + + if (style == 5) { + for (i = 0; i < 128; i++) { + if (message[i] == 0) + break; + + if (message[i] != LastBigMessage[5][i]) { + OddJob2On = 0; + OddJob2OffTimer = 0.0f; + } + + m_BigMessage[5][i] = message[i]; + LastBigMessage[5][i] = message[i]; + } + } else { + for (i = 0; i < 128; i++) { + if (message[i] == 0) + break; + m_BigMessage[style][i] = message[i]; + } + } + LastBigMessage[style][i] = 0; + m_BigMessage[style][i] = 0; +} + +void CHud::SetHelpMessage(wchar *message, bool quick, bool displayForever) +{ + if (!CReplay::IsPlayingBack()) { + for (int i = 0; i < HELP_MSG_LENGTH; i++) { + m_HelpMessage[i] = 0; + } + for (int i = 0; i < HELP_MSG_LENGTH; i++) { + m_LastHelpMessage[i] = 0; + } + for (int i = 0; i < HELP_MSG_LENGTH; i++) { + m_HelpMessageToPrint[i] = 0; + } + + CMessages::WideStringCopy(m_HelpMessage, message, HELP_MSG_LENGTH); + CMessages::InsertPlayerControlKeysInString(m_HelpMessage); + if (m_HelpMessageState == 0 || !CMessages::WideStringCompare(m_HelpMessage, m_HelpMessageToPrint, HELP_MSG_LENGTH)) { + for (int i = 0; i < HELP_MSG_LENGTH; i++) { + m_LastHelpMessage[i] = 0; + } + + if (!message) { + m_HelpMessage[0] = 0; + m_HelpMessageToPrint[0] = 0; + } + if (!displayForever) { + m_HelpMessageState = displayForever; + } else { + m_HelpMessageState = 1; + CMessages::WideStringCopy(m_HelpMessageToPrint, m_HelpMessage, HELP_MSG_LENGTH); + CMessages::WideStringCopy(m_LastHelpMessage, m_HelpMessage, HELP_MSG_LENGTH); + } + + m_HelpMessageQuick = quick; + m_HelpMessageDisplayForever = displayForever; + } + + } +} + +bool CHud::IsHelpMessageBeingDisplayed(void) +{ + return m_HelpMessageState != 0; +} + +void CHud::SetMessage(wchar *message) +{ + int i = 0; + for (i = 0; i < ARRAY_SIZE(m_Message); i++) { + if (message[i] == 0) + break; + + m_Message[i] = message[i]; + } + m_Message[i] = 0; +} + +void CHud::SetPagerMessage(wchar *message) +{ + int i = 0; + for (i = 0; i < ARRAY_SIZE(m_PagerMessage); i++) { + if (message[i] == 0) + break; + + m_PagerMessage[i] = message[i]; + } + m_PagerMessage[i] = 0; +} + +void CHud::SetVehicleName(wchar *name) +{ + m_VehicleName = name; +} + +void CHud::SetZoneName(wchar *name) +{ + m_pZoneName = name; +} + +void CHud::Shutdown() +{ + for (int i = 0; i < NUM_HUD_SPRITES; ++i) { + Sprites[i].Delete(); + } + + RwTextureDestroy(gpSniperSightTex); + gpSniperSightTex = nil; + + RwTextureDestroy(gpRocketSightTex); + gpRocketSightTex = nil; + + RwTextureDestroy(gpLaserSightTex); + gpLaserSightTex = nil; + + RwTextureDestroy(gpLaserDotTex); + gpLaserDotTex = nil; + + RwTextureDestroy(gpViewFinderTex); + gpViewFinderTex = nil; + + int HudTXD = CTxdStore::FindTxdSlot("hud"); + CTxdStore::RemoveTxdSlot(HudTXD); +} + +float CHud::DrawFadeState(DRAW_FADE_STATE fadingElement, int forceFadingIn) +{ + float alpha = 255.0f; + uint32 operation, timer; + int32 fadeTimer; + + switch (fadingElement) { + case HUD_WANTED_FADING: + fadeTimer = m_WantedFadeTimer; + operation = m_WantedState; + timer = m_WantedTimer; + break; + case HUD_ENERGY_FADING: + fadeTimer = m_EnergyLostFadeTimer; + operation = m_EnergyLostState; + timer = m_EnergyLostTimer; + break; + case HUD_SCORE_FADING: + fadeTimer = m_DisplayScoreFadeTimer; + operation = m_DisplayScoreState; + timer = m_DisplayScoreTimer; + break; + case HUD_WEAPON_FADING: + fadeTimer = m_WeaponFadeTimer; + operation = m_WeaponState; + timer = m_WeaponTimer; + break; + default: + break; + } + if (forceFadingIn) { + switch (operation) { + case FADED_OUT: + fadeTimer = 0; + case START_FADE_OUT: + case FADING_OUT: + timer = 5; + operation = FADING_IN; + break; + default: + break; + } + } + if (operation != FADED_OUT && operation != FADE_DISABLED) { + switch (operation) { + case START_FADE_OUT: + fadeTimer = 1000; + alpha = 255.0f; + if (timer > 10000) { + fadeTimer = 3000; + operation = FADING_OUT; + } + break; + case FADING_IN: + fadeTimer += CTimer::GetTimeStepInMilliseconds(); + if (fadeTimer > 1000.0f) { + operation = START_FADE_OUT; + fadeTimer = 1000; + } + alpha = fadeTimer / 1000.0f * 255.0f; + break; + case FADING_OUT: + fadeTimer -= CTimer::GetTimeStepInMilliseconds(); + if (fadeTimer < 0.0f) { + fadeTimer = 0; + operation = FADED_OUT; + } + alpha = fadeTimer / 1000.0f * 255.0f; + break; + default: + break; + } + timer += CTimer::GetTimeStepInMilliseconds(); + } + + switch (fadingElement) { + case HUD_WANTED_FADING: + m_WantedFadeTimer = fadeTimer; + m_WantedState = operation; + m_WantedTimer = timer; + break; + case HUD_ENERGY_FADING: + m_EnergyLostFadeTimer = fadeTimer; + m_EnergyLostState = operation; + m_EnergyLostTimer = timer; + break; + case HUD_SCORE_FADING: + m_DisplayScoreFadeTimer = fadeTimer; + m_DisplayScoreState = operation; + m_DisplayScoreTimer = timer; + break; + case HUD_WEAPON_FADING: + m_WeaponFadeTimer = fadeTimer; + m_WeaponState = operation; + m_WeaponTimer = timer; + break; + default: + break; + } + + return Clamp(alpha, 0.0f, 255.0f); +} + +void +CHud::ResetWastedText(void) +{ + BigMessageInUse[2] = 0.0f; + BigMessageInUse[0] = 0.0f; + m_BigMessage[2][0] = 0; + m_BigMessage[0][0] = 0; +} diff --git a/src/renderer/Hud.h b/src/renderer/Hud.h new file mode 100644 index 00000000..a4b9609a --- /dev/null +++ b/src/renderer/Hud.h @@ -0,0 +1,139 @@ +#pragma once +#include "Sprite2d.h" + +#define HELP_MSG_LENGTH 256 + +#define HUD_TEXT_SCALE_X 0.7f +#define HUD_TEXT_SCALE_Y 1.25f + +enum eItems +{ + ITEM_NONE = -1, + ITEM_ARMOUR = 3, + ITEM_HEALTH = 4, + ITEM_RADAR = 8 +}; + +// Thanks for vague name, R* +enum DRAW_FADE_STATE +{ + HUD_WANTED_FADING = 0, + HUD_ENERGY_FADING, + HUD_SCORE_FADING, + HUD_WEAPON_FADING, +}; + +// My name +enum eFadeOperation +{ + FADED_OUT = 0, + START_FADE_OUT, + FADING_IN, + FADING_OUT, + FADE_DISABLED = 5, +}; + +enum eSprites +{ + HUD_FIST, + HUD_SITEROCKET = 41, + HUD_RADARDISC = 50, + HUD_SITESNIPER = 63, + HUD_SITEM16, + HUD_SITELASER, + HUD_LASERDOT, + HUD_VIEWFINDER, + HUD_BLEEDER, + NUM_HUD_SPRITES = 69, +}; + +class CHud +{ +public: + static CSprite2d Sprites[NUM_HUD_SPRITES]; + static wchar m_HelpMessage[HELP_MSG_LENGTH]; + static wchar m_LastHelpMessage[HELP_MSG_LENGTH]; + static uint32 m_HelpMessageState; + static uint32 m_HelpMessageTimer; + static int32 m_HelpMessageFadeTimer; + static wchar m_HelpMessageToPrint[HELP_MSG_LENGTH]; + static float m_HelpMessageDisplayTime; + static bool m_HelpMessageDisplayForever; + static bool m_HelpMessageQuick; + static uint32 m_ZoneState; + static int32 m_ZoneFadeTimer; + static uint32 m_ZoneNameTimer; + static wchar *m_pZoneName; + static wchar *m_pLastZoneName; + static wchar *m_ZoneToPrint; + static wchar *m_VehicleName; + static wchar *m_pLastVehicleName; + static wchar *m_pVehicleNameToPrint; + static uint32 m_VehicleState; + static int32 m_VehicleFadeTimer; + static uint32 m_VehicleNameTimer; + static wchar m_Message[256]; + static wchar m_PagerMessage[256]; + static bool m_Wants_To_Draw_Hud; + static bool m_Wants_To_Draw_3dMarkers; + static wchar m_BigMessage[6][128]; + static int16 m_ItemToFlash; + static bool m_HideRadar; + static int32 m_ClockState; + + // These aren't really in CHud + static float BigMessageInUse[6]; + static float BigMessageAlpha[6]; + static float BigMessageX[6]; + static float OddJob2OffTimer; + static bool CounterOnLastFrame[NUMONSCREENCOUNTERS]; + static float OddJob2XOffset; + static uint16 CounterFlashTimer[NUMONSCREENCOUNTERS]; + static uint16 OddJob2Timer; + static bool TimerOnLastFrame; + static int16 OddJob2On; + static uint16 TimerFlashTimer; + static int16 PagerSoundPlayed; + static int32 SpriteBrightness; + static float PagerXOffset; + static int16 PagerTimer; + static int16 PagerOn; + + static uint32 m_WantedFadeTimer; + static uint32 m_WantedState; + static uint32 m_WantedTimer; + static uint32 m_EnergyLostFadeTimer; + static uint32 m_EnergyLostState; + static uint32 m_EnergyLostTimer; + static uint32 m_DisplayScoreFadeTimer; + static uint32 m_DisplayScoreState; + static uint32 m_DisplayScoreTimer; + static uint32 m_WeaponFadeTimer; + static uint32 m_WeaponState; + static uint32 m_WeaponTimer; + + static uint32 m_LastDisplayScore; + static uint32 m_LastWanted; + static uint32 m_LastWeapon; + static uint32 m_LastTimeEnergyLost; + +public: + static void Draw(); + static void DrawAfterFade(); + static void GetRidOfAllHudMessages(); +#ifdef RELOADABLES + static void ReloadTXD(); +#endif + static void Initialise(); + static void ReInitialise(); + static void SetBigMessage(wchar *message, uint16 style); + static void SetHelpMessage(wchar *message, bool quick, bool displayForever = false); + static bool IsHelpMessageBeingDisplayed(void); + static void SetMessage(wchar *message); + static void SetPagerMessage(wchar *message); + static void SetVehicleName(wchar *name); + static void SetZoneName(wchar *name); + static void Shutdown(); + static float DrawFadeState(DRAW_FADE_STATE, int); + static void ResetWastedText(void); +}; diff --git a/src/renderer/Instance.cpp b/src/renderer/Instance.cpp new file mode 100644 index 00000000..be6d73d6 --- /dev/null +++ b/src/renderer/Instance.cpp @@ -0,0 +1,9 @@ +#include "common.h" + +#include "Instance.h" + +void +CInstance::Shutdown() +{ + GetMatrix().Detach(); +} diff --git a/src/renderer/Instance.h b/src/renderer/Instance.h new file mode 100644 index 00000000..693cfdf1 --- /dev/null +++ b/src/renderer/Instance.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Placeable.h" + +// unused + +class CInstance : public CPlaceable +{ +public: + int m_modelIndex; +public: + ~CInstance() { } + void Shutdown(); +}; diff --git a/src/renderer/Lines.cpp b/src/renderer/Lines.cpp new file mode 100644 index 00000000..b5c85149 --- /dev/null +++ b/src/renderer/Lines.cpp @@ -0,0 +1,74 @@ +#include "common.h" + +#include "main.h" +#include "Lines.h" + +// This is super inefficient, why split the line into segments at all? +void +CLines::RenderLineWithClipping(float x1, float y1, float z1, float x2, float y2, float z2, uint32 c1, uint32 c2) +{ + static RwIm3DVertex v[2]; +#ifdef THIS_IS_STUPID + int i; + float f1, f2; + float len = sqrt(sq(x1-x2) + sq(y1-y2) + sq(z1-z2)); + int numsegs = len/1.5f + 1.0f; + + RwRGBA col1; + col1.red = c1>>24; + col1.green = c1>>16; + col1.blue = c1>>8; + col1.alpha = c1; + RwRGBA col2; + col2.red = c2>>24; + col2.green = c2>>16; + col2.blue = c2>>8; + col2.alpha = c2; + + float dx = x2 - x1; + float dy = y2 - y1; + float dz = z2 - z1; + for(i = 0; i < numsegs; i++){ + f1 = (float)i/numsegs; + f2 = (float)(i+1)/numsegs; + + RwIm3DVertexSetRGBA(&v[0], (int)(col1.red + (col2.red-col1.red)*f1), + (int)(col1.green + (col2.green-col1.green)*f1), + (int)(col1.blue + (col2.blue-col1.blue)*f1), + (int)(col1.alpha + (col2.alpha-col1.alpha)*f1)); + RwIm3DVertexSetRGBA(&v[1], (int)(col1.red + (col2.red-col1.red)*f2), + (int)(col1.green + (col2.green-col1.green)*f2), + (int)(col1.blue + (col2.blue-col1.blue)*f2), + (int)(col1.alpha + (col2.alpha-col1.alpha)*f2)); + RwIm3DVertexSetPos(&v[0], x1 + dx*f1, y1 + dy*f1, z1 + dz*f1); + RwIm3DVertexSetPos(&v[1], x1 + dx*f2, y1 + dy*f2, z1 + dz*f2); + + LittleTest(); + if(RwIm3DTransform(v, 2, nil, 0)){ + RwIm3DRenderLine(0, 1); + RwIm3DEnd(); + } + } +#else + RwRGBA col1; + col1.red = c1>>24; + col1.green = c1>>16; + col1.blue = c1>>8; + col1.alpha = c1; + RwRGBA col2; + col2.red = c2>>24; + col2.green = c2>>16; + col2.blue = c2>>8; + col2.alpha = c2; + + RwIm3DVertexSetRGBA(&v[0], col1.red, col1.green, col1.blue, col1.alpha); + RwIm3DVertexSetRGBA(&v[1], col2.red, col2.green, col2.blue, col2.alpha); + RwIm3DVertexSetPos(&v[0], x1, y1, z1); + RwIm3DVertexSetPos(&v[1], x2, y2, z2); + LittleTest(); + if(RwIm3DTransform(v, 2, nil, 0)){ + RwIm3DRenderLine(0, 1); + RwIm3DEnd(); + } +#endif +} diff --git a/src/renderer/Lines.h b/src/renderer/Lines.h new file mode 100644 index 00000000..f2694fc0 --- /dev/null +++ b/src/renderer/Lines.h @@ -0,0 +1,7 @@ +#pragma once + +class CLines +{ +public: + static void RenderLineWithClipping(float x1, float y1, float z1, float x2, float y2, float z2, uint32 c1, uint32 c2); +}; diff --git a/src/renderer/MBlur.cpp b/src/renderer/MBlur.cpp new file mode 100644 index 00000000..cc8270ce --- /dev/null +++ b/src/renderer/MBlur.cpp @@ -0,0 +1,801 @@ +#ifndef LIBRW +#define WITHD3D +#endif +#include "common.h" +#ifndef LIBRW +#include +#endif + +#include "main.h" +#include "General.h" +#include "RwHelper.h" +#include "Camera.h" +#include "Timecycle.h" +#include "Particle.h" +#include "Timer.h" +#include "Hud.h" +#include "Frontend.h" +#include "MBlur.h" +#include "postfx.h" + +// Originally taken from RW example 'mblur' + +RwRaster *CMBlur::pFrontBuffer; +bool CMBlur::ms_bJustInitialised; +bool CMBlur::ms_bScaledBlur; +bool CMBlur::BlurOn; +float CMBlur::Drunkness; + +int32 CMBlur::pBufVertCount; + +static RwIm2DVertex Vertex[4]; +static RwIm2DVertex Vertex2[4]; +static RwImVertexIndex Index[6] = { 0, 1, 2, 0, 2, 3 }; + +#ifndef LIBRW +extern "C" D3DCAPS8 _RwD3D8DeviceCaps; +#endif +RwBool +CMBlur::MotionBlurOpen(RwCamera *cam) +{ +#ifdef EXTENDED_COLOURFILTER + CPostFX::Open(cam); + return TRUE; +#else +#ifdef GTA_PS2 + RwRect rect = {0, 0, 0, 0}; + + if (pFrontBuffer) + return TRUE; + + BlurOn = true; + + rect.w = RwRasterGetWidth(RwCameraGetRaster(cam)); + rect.h = RwRasterGetHeight(RwCameraGetRaster(cam)); + + pFrontBuffer = RwRasterCreate(0, 0, 0, rwRASTERDONTALLOCATE|rwRASTERTYPECAMERATEXTURE); + if (!pFrontBuffer) + { + printf("Error creating raster\n"); + return FALSE; + } + + RwRaster *raster = RwRasterSubRaster(pFrontBuffer, RwCameraGetRaster(cam), &rect); + if (!raster) + { + RwRasterDestroy(pFrontBuffer); + pFrontBuffer = NULL; + printf("Error subrastering\n"); + return FALSE; + } + + CreateImmediateModeData(cam, &rect); +#else + RwRect rect = { 0, 0, 0, 0 }; + + if(pFrontBuffer) + MotionBlurClose(); + +#ifndef LIBRW + extern void _GetVideoMemInfo(LPDWORD total, LPDWORD avaible); + DWORD total, avaible; + + _GetVideoMemInfo(&total, &avaible); + debug("Available video memory %d\n", avaible); +#endif + + if(BlurOn) + { + uint32 width = Pow(2.0f, int32(log2(RwRasterGetWidth (RwCameraGetRaster(cam))))+1); + uint32 height = Pow(2.0f, int32(log2(RwRasterGetHeight(RwCameraGetRaster(cam))))+1); + uint32 depth = RwRasterGetDepth(RwCameraGetRaster(cam)); + +#ifndef LIBRW + extern DWORD _dwMemTotalVideo; + if ( _RwD3D8DeviceCaps.MaxTextureWidth >= width && _RwD3D8DeviceCaps.MaxTextureHeight >= height ) + { + total = _dwMemTotalVideo - 3 * + ( RwRasterGetDepth(RwCameraGetRaster(cam)) + * RwRasterGetHeight(RwCameraGetRaster(cam)) + * RwRasterGetWidth(RwCameraGetRaster(cam)) / 8 ); + BlurOn = total >= height*width*(depth/8) + (12*1024*1024) /*12 MB*/; + } + else + BlurOn = false; +#endif + + if ( BlurOn ) + { + ms_bScaledBlur = false; + rect.w = width; + rect.h = height; + + pFrontBuffer = RwRasterCreate(rect.w, rect.h, depth, rwRASTERTYPECAMERATEXTURE); + if ( !pFrontBuffer ) + { + debug("MBlurOpen can't create raster."); + BlurOn = false; + rect.w = RwRasterGetWidth(RwCameraGetRaster(cam)); + rect.h = RwRasterGetHeight(RwCameraGetRaster(cam)); + } + else + ms_bJustInitialised = true; + } + else + { + rect.w = RwRasterGetWidth(RwCameraGetRaster(cam)); + rect.h = RwRasterGetHeight(RwCameraGetRaster(cam)); + } + +#ifndef LIBRW + _GetVideoMemInfo(&total, &avaible); + debug("Available video memory %d\n", avaible); +#endif + CreateImmediateModeData(cam, &rect); + } + else + { + rect.w = RwRasterGetWidth(RwCameraGetRaster(cam)); + rect.h = RwRasterGetHeight(RwCameraGetRaster(cam)); + CreateImmediateModeData(cam, &rect); + } + + return TRUE; +#endif +#endif +} + +RwBool +CMBlur::MotionBlurClose(void) +{ +#ifdef EXTENDED_COLOURFILTER + CPostFX::Close(); +#else + if(pFrontBuffer){ + RwRasterDestroy(pFrontBuffer); + pFrontBuffer = nil; + + return TRUE; + } +#endif + return FALSE; +} + +void +CMBlur::CreateImmediateModeData(RwCamera *cam, RwRect *rect) +{ + float zero, xmax, ymax; + + if(RwRasterGetDepth(RwCameraGetRaster(cam)) == 16){ + zero = HALFPX; + xmax = rect->w + HALFPX; + ymax = rect->h + HALFPX; + }else{ + zero = -HALFPX; + xmax = rect->w - HALFPX; + ymax = rect->h - HALFPX; + } + + RwIm2DVertexSetScreenX(&Vertex[0], zero); + RwIm2DVertexSetScreenY(&Vertex[0], zero); + RwIm2DVertexSetScreenZ(&Vertex[0], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Vertex[0], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&Vertex[0], 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetU(&Vertex[0], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetV(&Vertex[0], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetIntRGBA(&Vertex[0], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&Vertex[1], zero); + RwIm2DVertexSetScreenY(&Vertex[1], ymax); + RwIm2DVertexSetScreenZ(&Vertex[1], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Vertex[1], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&Vertex[1], 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetU(&Vertex[1], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetV(&Vertex[1], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetIntRGBA(&Vertex[1], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&Vertex[2], xmax); + RwIm2DVertexSetScreenY(&Vertex[2], ymax); + RwIm2DVertexSetScreenZ(&Vertex[2], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Vertex[2], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&Vertex[2], 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetU(&Vertex[2], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetV(&Vertex[2], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetIntRGBA(&Vertex[2], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&Vertex[3], xmax); + RwIm2DVertexSetScreenY(&Vertex[3], zero); + RwIm2DVertexSetScreenZ(&Vertex[3], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Vertex[3], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&Vertex[3], 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetU(&Vertex[3], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetV(&Vertex[3], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetIntRGBA(&Vertex[3], 255, 255, 255, 255); + + + RwIm2DVertexSetScreenX(&Vertex2[0], zero + 2.0f); + RwIm2DVertexSetScreenY(&Vertex2[0], zero + 2.0f); + RwIm2DVertexSetScreenZ(&Vertex2[0], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Vertex2[0], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&Vertex2[0], 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetU(&Vertex2[0], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetV(&Vertex2[0], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetIntRGBA(&Vertex2[0], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&Vertex2[1], 2.0f); + RwIm2DVertexSetScreenY(&Vertex2[1], ymax + 2.0f); + RwIm2DVertexSetScreenZ(&Vertex2[1], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Vertex2[1], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&Vertex2[1], 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetU(&Vertex2[1], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetV(&Vertex2[1], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetIntRGBA(&Vertex2[1], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&Vertex2[2], xmax + 2.0f); + RwIm2DVertexSetScreenY(&Vertex2[2], ymax + 2.0f); + RwIm2DVertexSetScreenZ(&Vertex2[2], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Vertex2[2], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&Vertex2[2], 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetU(&Vertex2[2], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetV(&Vertex2[2], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetIntRGBA(&Vertex2[2], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX(&Vertex2[3], xmax + 2.0f); + RwIm2DVertexSetScreenY(&Vertex2[3], zero + 2.0f); + RwIm2DVertexSetScreenZ(&Vertex2[3], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&Vertex2[3], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&Vertex2[3], 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetU(&Vertex2[3], 1.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetV(&Vertex2[3], 0.0f, 1.0f/RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetIntRGBA(&Vertex2[3], 255, 255, 255, 255); +} + +void +CMBlur::CreateImmediateModeData(RwCamera *cam, RwRect *rect, RwIm2DVertex *verts, RwRGBA color, float u1Off, float v1Off, float u2Off, float v2Off, float z, int fullTexture) +{ + float x1 = rect->x; + float y1 = rect->y; + float x2 = rect->w; + float y2 = rect->h; + + float u1, v1, u2, v2; + if(fullTexture){ + u1 = 0.0f; + v1 = 0.0f; + u2 = 1.0f; + v2 = 1.0f; + }else{ + if(RwRasterGetDepth(RwCameraGetRaster(cam)) == 16){ + x1 += HALFPX; + y1 += HALFPX; + x2 += HALFPX; + y2 += HALFPX; + }else{ + x1 -= HALFPX; + y1 -= HALFPX; + x2 -= HALFPX; + y2 -= HALFPX; + } + + int32 width = Pow(2.0f, int32(log2(RwRasterGetWidth (RwCameraGetRaster(cam))))+1); + int32 height = Pow(2.0f, int32(log2(RwRasterGetHeight(RwCameraGetRaster(cam))))+1); + u1 = x1/width + u1Off; + v1 = y1/height + v1Off; + u2 = x2/width + u2Off; + v2 = y2/height + v2Off; + u1 = Clamp(u1, 0.0f, 1.0f); + v1 = Clamp(v1, 0.0f, 1.0f); + u2 = Clamp(u2, 0.0f, 1.0f); + v2 = Clamp(v2, 0.0f, 1.0f); + } + + float recipz = 1.0f/z; + // TODO: CameraZ is wrong, what should we do? + RwIm2DVertexSetScreenX(&verts[0], x1); + RwIm2DVertexSetScreenY(&verts[0], y1); + RwIm2DVertexSetScreenZ(&verts[0], z); + RwIm2DVertexSetCameraZ(&verts[0], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&verts[0], recipz); + RwIm2DVertexSetU(&verts[0], u1, recipz); + RwIm2DVertexSetV(&verts[0], v1, recipz); + RwIm2DVertexSetIntRGBA(&verts[0], color.red, color.green, color.blue, color.alpha); + + RwIm2DVertexSetScreenX(&verts[1], x1); + RwIm2DVertexSetScreenY(&verts[1], y2); + RwIm2DVertexSetScreenZ(&verts[1], z); + RwIm2DVertexSetCameraZ(&verts[1], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&verts[1], recipz); + RwIm2DVertexSetU(&verts[1], u1, recipz); + RwIm2DVertexSetV(&verts[1], v2, recipz); + RwIm2DVertexSetIntRGBA(&verts[1], color.red, color.green, color.blue, color.alpha); + + RwIm2DVertexSetScreenX(&verts[2], x2); + RwIm2DVertexSetScreenY(&verts[2], y2); + RwIm2DVertexSetScreenZ(&verts[2], z); + RwIm2DVertexSetCameraZ(&verts[2], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&verts[2], recipz); + RwIm2DVertexSetU(&verts[2], u2, recipz); + RwIm2DVertexSetV(&verts[2], v2, recipz); + RwIm2DVertexSetIntRGBA(&verts[2], color.red, color.green, color.blue, color.alpha); + + RwIm2DVertexSetScreenX(&verts[3], x2); + RwIm2DVertexSetScreenY(&verts[3], y1); + RwIm2DVertexSetScreenZ(&verts[3], z); + RwIm2DVertexSetCameraZ(&verts[3], RwCameraGetNearClipPlane(cam)); + RwIm2DVertexSetRecipCameraZ(&verts[3], recipz); + RwIm2DVertexSetU(&verts[3], u2, recipz); + RwIm2DVertexSetV(&verts[3], v1, recipz); + RwIm2DVertexSetIntRGBA(&verts[3], color.red, color.green, color.blue, color.alpha); +} + +void +CMBlur::MotionBlurRender(RwCamera *cam, uint32 red, uint32 green, uint32 blue, uint32 blur, int32 type, uint32 bluralpha) +{ +#ifdef EXTENDED_COLOURFILTER + CPostFX::Render(cam, red, green, blue, blur, type, bluralpha); +#else + PUSH_RENDERGROUP("CMBlur::MotionBlurRender"); + RwRGBA color = { (RwUInt8)red, (RwUInt8)green, (RwUInt8)blue, (RwUInt8)blur }; +#ifdef GTA_PS2 + if( pFrontBuffer ) + OverlayRender(cam, pFrontBuffer, color, type, bluralpha); +#else + if(ms_bJustInitialised) + ms_bJustInitialised = false; + else + OverlayRender(cam, pFrontBuffer, color, type, bluralpha); + if(BlurOn){ + RwRasterPushContext(pFrontBuffer); + RwRasterRenderFast(RwCameraGetRaster(cam), 0, 0); + RwRasterPopContext(); + } +#endif + POP_RENDERGROUP(); +#endif +} + +static uint8 DrunkBlurRed = 128; +static uint8 DrunkBlurGreen = 128; +static uint8 DrunkBlurBlue = 128; +static int32 DrunkBlurIncrement = 1; + +void +CMBlur::OverlayRender(RwCamera *cam, RwRaster *raster, RwRGBA color, int32 type, int32 bluralpha) +{ + int r, g, b, a; + + r = color.red; + g = color.green; + b = color.blue; + a = color.alpha; + + DefinedState(); + + switch(type) + { + case MOTION_BLUR_SECURITY_CAM: + r = 0; + g = 255; + b = 0; + a = 128; + break; + case MOTION_BLUR_INTRO: + r = 100; + g = 220; + b = 230; + a = 158; + break; + case MOTION_BLUR_INTRO2: + r = 80; + g = 255; + b = 230; + a = 138; + break; + case MOTION_BLUR_INTRO3: + r = 255; + g = 60; + b = 60; + a = 200; + break; + case MOTION_BLUR_INTRO4: + r = 255; + g = 180; + b = 180; + a = 128; + break; + } + + if(!BlurOn){ + // gta clamps these to 255 (probably a macro or inlined function) + int ovR = r * 0.6f; + int ovG = g * 0.6f; + int ovB = b * 0.6f; + int ovA = type == MOTION_BLUR_SNIPER ? a : a*0.6f; + RwIm2DVertexSetIntRGBA(&Vertex[0], ovR, ovG, ovB, ovA); + RwIm2DVertexSetIntRGBA(&Vertex[1], ovR, ovG, ovB, ovA); + RwIm2DVertexSetIntRGBA(&Vertex[2], ovR, ovG, ovB, ovA); + RwIm2DVertexSetIntRGBA(&Vertex[3], ovR, ovG, ovB, ovA); + }else{ + RwIm2DVertexSetIntRGBA(&Vertex2[0], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex[0], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex2[1], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex[1], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex2[2], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex[2], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex2[3], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex[3], r, g, b, a); + } + + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERNEAREST); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, raster); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + + if(BlurOn){ + if(type == MOTION_BLUR_SNIPER){ + RwIm2DVertexSetIntRGBA(&Vertex2[0], r, g, b, 80); + RwIm2DVertexSetIntRGBA(&Vertex2[1], r, g, b, 80); + RwIm2DVertexSetIntRGBA(&Vertex2[2], r, g, b, 80); + RwIm2DVertexSetIntRGBA(&Vertex2[3], r, g, b, 80); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + pBufVertCount = 0; + }else{ + RwIm2DVertexSetIntRGBA(&Vertex2[0], r*2, g*2, b*2, 30); + RwIm2DVertexSetIntRGBA(&Vertex2[1], r*2, g*2, b*2, 30); + RwIm2DVertexSetIntRGBA(&Vertex2[2], r*2, g*2, b*2, 30); + RwIm2DVertexSetIntRGBA(&Vertex2[3], r*2, g*2, b*2, 30); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, Vertex2, 4, Index, 6); + + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + + RwIm2DVertexSetIntRGBA(&Vertex2[0], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex[0], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex2[1], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex[1], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex2[2], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex[2], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex2[3], r, g, b, a); + RwIm2DVertexSetIntRGBA(&Vertex[3], r, g, b, a); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, Vertex, 4, Index, 6); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, Vertex2, 4, Index, 6); + } + } + + int DrunkBlurAlpha = 175.0f * Drunkness; + if(DrunkBlurAlpha != 0){ + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + if(BlurOn){ + RwIm2DVertexSetIntRGBA(&Vertex[0], 255, 255, 255, DrunkBlurAlpha); + RwIm2DVertexSetIntRGBA(&Vertex[1], 255, 255, 255, DrunkBlurAlpha); + RwIm2DVertexSetIntRGBA(&Vertex[2], 255, 255, 255, DrunkBlurAlpha); + RwIm2DVertexSetIntRGBA(&Vertex[3], 255, 255, 255, DrunkBlurAlpha); + }else{ + RwIm2DVertexSetIntRGBA(&Vertex[0], DrunkBlurRed, DrunkBlurGreen, DrunkBlurBlue, DrunkBlurAlpha); + RwIm2DVertexSetIntRGBA(&Vertex[1], DrunkBlurRed, DrunkBlurGreen, DrunkBlurBlue, DrunkBlurAlpha); + RwIm2DVertexSetIntRGBA(&Vertex[2], DrunkBlurRed, DrunkBlurGreen, DrunkBlurBlue, DrunkBlurAlpha); + RwIm2DVertexSetIntRGBA(&Vertex[3], DrunkBlurRed, DrunkBlurGreen, DrunkBlurBlue, DrunkBlurAlpha); + if(DrunkBlurIncrement){ + if(DrunkBlurRed < 255) DrunkBlurRed++; + if(DrunkBlurGreen < 255) DrunkBlurGreen++; + if(DrunkBlurBlue < 255) DrunkBlurBlue++; + if(DrunkBlurRed == 255) + DrunkBlurIncrement = 0; + }else{ + if(DrunkBlurRed > 128) DrunkBlurRed--; + if(DrunkBlurGreen > 128) DrunkBlurGreen--; + if(DrunkBlurBlue > 128) DrunkBlurBlue--; + if(DrunkBlurRed == 128) + DrunkBlurIncrement = 1; + } + } + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, Vertex, 4, Index, 6); + } + + if(type != MOTION_BLUR_SNIPER) + OverlayRenderFx(cam, pFrontBuffer); + + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); +} + +void +CMBlur::SetDrunkBlur(float drunkness) +{ + Drunkness = Clamp(drunkness, 0.0f, 1.0f); +} + +void +CMBlur::ClearDrunkBlur() +{ + Drunkness = 0.0f; + CTimer::SetTimeScale(1.0f); +} + +#define NUM_RENDER_FX 64 + +static RwRect fxRect[NUM_RENDER_FX]; +static FxType fxType[NUM_RENDER_FX]; +static float fxZ[NUM_RENDER_FX]; + +bool +CMBlur::PosInside(RwRect *rect, float x1, float y1, float x2, float y2) +{ + if((rect->x < x1 - 10.0f || rect->x > x2 + 10.0f || rect->y < y1 - 10.0f || rect->y > y2 + 10.0f) && + (rect->w < x1 - 10.0f || rect->w > x2 + 10.0f || rect->h < y1 - 10.0f || rect->h > y2 + 10.0f) && + (rect->x < x1 - 10.0f || rect->x > x2 + 10.0f || rect->h < y1 - 10.0f || rect->h > y2 + 10.0f) && + (rect->w < x1 - 10.0f || rect->w > x2 + 10.0f || rect->y < y1 - 10.0f || rect->y > y2 + 10.0f)) + return false; + return true; +} + +bool +CMBlur::AddRenderFx(RwCamera *cam, RwRect *rect, float z, FxType type) +{ + if(pBufVertCount >= NUM_RENDER_FX) + return false; + + rect->x = Max(rect->x, 0); + rect->y = Max(rect->y, 0); + rect->w = Min(rect->w, SCREEN_WIDTH); + rect->h = Min(rect->h, SCREEN_HEIGHT); + if(rect->x >= rect->w || rect->y >= rect->h) + return false; + + switch(type){ + case FXTYPE_WATER1: + case FXTYPE_WATER2: + case FXTYPE_BLOOD1: + case FXTYPE_BLOOD2: + case FXTYPE_HEATHAZE: // code seems to be duplicated for this case + for(int i = 0; i < pBufVertCount; i++) + if(fxType[i] == type && PosInside(rect, fxRect[i].x-10.0f, fxRect[i].y-10.0f, fxRect[i].w+10.0f, fxRect[i].h+10.0f)) + return false; + // TODO: fix aspect ratio scaling + // radar + if(PosInside(rect, 40.0f, SCREEN_SCALE_FROM_BOTTOM(116.0f), 40.0f + SCREEN_SCALE_X(94.0f), SCREEN_SCALE_FROM_BOTTOM(116.0f - 76.0f))) + return false; + // HUD + if(PosInside(rect, 400.0f, 0.0f, SCREEN_WIDTH, 90.0f)) + return false; + // vehicle name + if(CHud::m_VehicleState != 0 && PosInside(rect, SCREEN_WIDTH/2, 350.0f, SCREEN_WIDTH, SCREEN_HEIGHT)) + return false; + // zone name + if(CHud::m_ZoneState != 0 && PosInside(rect, SCREEN_WIDTH/2, 350.0f, SCREEN_WIDTH, SCREEN_HEIGHT)) + return false; + break; + } + + fxRect[pBufVertCount] = *rect; + fxZ[pBufVertCount] = z; + fxType[pBufVertCount] = type; + pBufVertCount++; + + return true; +} + +void +CMBlur::OverlayRenderFx(RwCamera *cam, RwRaster *frontBuf) +{ + bool drawWaterDrops = false; + RwIm2DVertex verts[4]; + int red = (0.75f*CTimeCycle::GetDirectionalRed() + CTimeCycle::GetAmbientRed())*0.55f * 255; + int green = (0.75f*CTimeCycle::GetDirectionalGreen() + CTimeCycle::GetAmbientGreen())*0.55f * 255; + int blue = (0.75f*CTimeCycle::GetDirectionalBlue() + CTimeCycle::GetAmbientBlue())*0.55f * 255; + red = Clamp(red, 0, 255); + green = Clamp(green, 0, 255); + blue = Clamp(blue, 0, 255); + + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + +#ifdef LIBRW + rw::SetRenderState(rw::STENCILENABLE, TRUE); +#else + RwD3D8SetRenderState(D3DRS_STENCILENABLE, TRUE); +#endif + + for(int i = 0; i < pBufVertCount; i++) + switch(fxType[i]){ + case FXTYPE_WATER1: + case FXTYPE_WATER2: + case FXTYPE_BLOOD1: + case FXTYPE_BLOOD2: { + drawWaterDrops = true; + int32 width = Pow(2.0f, int32(log2(RwRasterGetWidth (RwCameraGetRaster(cam))))+1); + int32 height = Pow(2.0f, int32(log2(RwRasterGetHeight(RwCameraGetRaster(cam))))+1); + + float u1Off = (fxRect[i].w - fxRect[i].x)/width; + float u2Off = u1Off - (fxRect[i].w - fxRect[i].x + 0.5f)*0.66f/width; + float halfHeight = (fxRect[i].h - fxRect[i].y + 0.5f)*0.25f/height; + + if(RwRasterGetDepth(RwCameraGetRaster(cam)) == 16){ + if(fxType[i] == FXTYPE_BLOOD1 || fxType[i] == FXTYPE_BLOOD2) + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(255, 0, 0, 128), 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); + else + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(32, 32, 32, 225), 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); + }else{ + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(32, 32, 32, 225), 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); + } + + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpDotRaster); +#ifdef LIBRW + rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILALWAYS); + rw::SetRenderState(rw::STENCILFUNCTIONREF, 1); + rw::SetRenderState(rw::STENCILFUNCTIONMASK, 0xFFFFFFFF); + rw::SetRenderState(rw::STENCILFUNCTIONWRITEMASK, 0xFFFFFFFF); + rw::SetRenderState(rw::STENCILZFAIL, rw::STENCILKEEP); + rw::SetRenderState(rw::STENCILFAIL, rw::STENCILKEEP); + rw::SetRenderState(rw::STENCILPASS, rw::STENCILREPLACE); +#else + RwD3D8SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); + RwD3D8SetRenderState(D3DRS_STENCILREF, 1); + RwD3D8SetRenderState(D3DRS_STENCILMASK, 0xFFFFFFFF); + RwD3D8SetRenderState(D3DRS_STENCILWRITEMASK, 0xFFFFFFFF); + RwD3D8SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP); + RwD3D8SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP); + RwD3D8SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); +#endif + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); + + if(RwRasterGetDepth(RwCameraGetRaster(cam)) != 16){ + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, frontBuf); +#ifdef LIBRW + rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILEQUAL); + rw::SetRenderState(rw::STENCILPASS, rw::STENCILKEEP); +#else + RwD3D8SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL); + RwD3D8SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); +#endif + if(BlurOn){ + if(fxType[i] == FXTYPE_BLOOD1 || fxType[i] == FXTYPE_BLOOD2) + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(255, 0, 0, 255), u1Off, 0.0f+halfHeight, u2Off, 0.0f-halfHeight, fxZ[i], false); + else + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(225, 225, 225, 160), u1Off, 0.0f+halfHeight, u2Off, 0.0f-halfHeight, fxZ[i], false); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDDESTALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVDESTALPHA); + }else{ + if(fxType[i] == FXTYPE_BLOOD1 || fxType[i] == FXTYPE_BLOOD2) + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(255, 0, 0, 128), u1Off, 0.0f+halfHeight, u2Off, 0.0f-halfHeight, fxZ[i], false); + else + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(128, 128, 128, 32), u1Off, 0.0f+halfHeight, u2Off, 0.0f-halfHeight, fxZ[i], false); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + } + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); + } + break; + } + case FXTYPE_SPLASH1: + case FXTYPE_SPLASH2: + case FXTYPE_SPLASH3: + drawWaterDrops = true; + break; + + case FXTYPE_HEATHAZE: + if(TheCamera.GetScreenFadeStatus() == FADE_0 && frontBuf){ + int alpha = FrontEndMenuManager.m_PrefsBrightness > 255 ? + FrontEndMenuManager.m_PrefsBrightness - 90 : + FrontEndMenuManager.m_PrefsBrightness - 130; + alpha = Clamp(alpha, 16, 200)/2; + + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(0, 0, 0, alpha), 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpHeatHazeRaster); +#ifdef LIBRW + rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILALWAYS); + rw::SetRenderState(rw::STENCILFUNCTIONREF, 1); + rw::SetRenderState(rw::STENCILFUNCTIONMASK, 0xFFFFFFFF); + rw::SetRenderState(rw::STENCILFUNCTIONWRITEMASK, 0xFFFFFFFF); + rw::SetRenderState(rw::STENCILZFAIL, rw::STENCILKEEP); + rw::SetRenderState(rw::STENCILFAIL, rw::STENCILKEEP); + rw::SetRenderState(rw::STENCILPASS, rw::STENCILREPLACE); +#else + RwD3D8SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); + RwD3D8SetRenderState(D3DRS_STENCILREF, 1); + RwD3D8SetRenderState(D3DRS_STENCILMASK, 0xFFFFFFFF); + RwD3D8SetRenderState(D3DRS_STENCILWRITEMASK, 0xFFFFFFFF); + RwD3D8SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP); + RwD3D8SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP); + RwD3D8SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); +#endif + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); + + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(255, 255, 255, alpha), + CGeneral::GetRandomNumberInRange(-0.002f, 0.002f), + CGeneral::GetRandomNumberInRange(-0.002f, 0.002f), + CGeneral::GetRandomNumberInRange(-0.002f, 0.002f), + CGeneral::GetRandomNumberInRange(-0.002f, 0.002f), + fxZ[i], false); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, frontBuf); +#ifdef LIBRW + rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILEQUAL); + rw::SetRenderState(rw::STENCILPASS, rw::STENCILKEEP); +#else + RwD3D8SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL); + RwD3D8SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); +#endif + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); + } + break; + } +#ifdef LIBRW + rw::SetRenderState(rw::STENCILENABLE, FALSE); +#else + RwD3D8SetRenderState(D3DRS_STENCILENABLE, FALSE); +#endif + + if(drawWaterDrops){ + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + + // Draw drops + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpRainDripRaster[0]); + for(int i = 0; i < pBufVertCount; i++) + if(fxType[i] == FXTYPE_WATER1 || fxType[i] == FXTYPE_BLOOD1){ + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(red, green, blue, fxType[i] == FXTYPE_BLOOD1 ? 255 : 192), + 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); + } + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpRainDripRaster[1]); + for(int i = 0; i < pBufVertCount; i++) + if(fxType[i] == FXTYPE_WATER2 || fxType[i] == FXTYPE_BLOOD2){ + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(red, green, blue, fxType[i] == FXTYPE_BLOOD2 ? 255 : 192), + 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); + } + + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpCarSplashRaster[0]); + for(int i = 0; i < pBufVertCount; i++) + if(fxType[i] == FXTYPE_SPLASH1 || fxType[i] == FXTYPE_SPLASH2 || fxType[i] == FXTYPE_SPLASH3){ + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(200, 200, 200, 255), + 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); + } + + // Darken the water drops + int alpha = 192*0.5f; + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpRainDripDarkRaster[0]); + for(int i = 0; i < pBufVertCount; i++) + if(fxType[i] == FXTYPE_WATER1){ + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(red, green, blue, alpha), + 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); + } + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpRainDripDarkRaster[1]); + for(int i = 0; i < pBufVertCount; i++) + if(fxType[i] == FXTYPE_WATER2){ + CreateImmediateModeData(cam, &fxRect[i], verts, CRGBA(red, green, blue, alpha), + 0.0f, 0.0f, 0.0f, 0.0f, fxZ[i], true); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, verts, 4, Index, 6); + } + } + + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + pBufVertCount = 0; +} diff --git a/src/renderer/MBlur.h b/src/renderer/MBlur.h new file mode 100644 index 00000000..3dc53082 --- /dev/null +++ b/src/renderer/MBlur.h @@ -0,0 +1,39 @@ +#pragma once + +enum FxType +{ + FXTYPE_WATER1, + FXTYPE_WATER2, + FXTYPE_BLOOD1, + FXTYPE_BLOOD2, + FXTYPE_HEATHAZE, + FXTYPE_SPLASH1, + FXTYPE_SPLASH2, + FXTYPE_SPLASH3 +}; + +class CMBlur +{ +public: + static RwRaster *pFrontBuffer; + static bool ms_bJustInitialised; + static bool ms_bScaledBlur; + static bool BlurOn; + static float Drunkness; + + static int32 pBufVertCount; + +public: + static RwBool MotionBlurOpen(RwCamera *cam); + static RwBool MotionBlurClose(void); + static void CreateImmediateModeData(RwCamera *cam, RwRect *rect); + static void CreateImmediateModeData(RwCamera *cam, RwRect *rect, RwIm2DVertex *verts, RwRGBA color, float u1Off, float v1Off, float u2Off, float v2Off, float z, int fullTexture); + static void MotionBlurRender(RwCamera *cam, uint32 red, uint32 green, uint32 blue, uint32 blur, int32 type, uint32 bluralpha); + static void OverlayRender(RwCamera *cam, RwRaster *raster, RwRGBA color, int32 type, int32 bluralpha); + static void SetDrunkBlur(float drunkness); + static void ClearDrunkBlur(); + + static bool PosInside(RwRect *rect, float x1, float y1, float x2, float y2); + static bool AddRenderFx(RwCamera *cam, RwRect *rect, float z, FxType type); + static void OverlayRenderFx(RwCamera *cam, RwRaster *frontBuf); +}; diff --git a/src/renderer/Occlusion.cpp b/src/renderer/Occlusion.cpp new file mode 100644 index 00000000..ec7101a6 --- /dev/null +++ b/src/renderer/Occlusion.cpp @@ -0,0 +1,530 @@ +#include "common.h" + +#include "main.h" +#include "Entity.h" +#include "Occlusion.h" +#include "Game.h" +#include "Camera.h" +#include "Vector.h" +#include "Draw.h" +#include "Timer.h" +#include "RwHelper.h" +#include "VarConsole.h" + +int32 COcclusion::NumOccludersOnMap; +int16 COcclusion::FarAwayList; +int16 COcclusion::NearbyList; +int16 COcclusion::ListWalkThroughFA; +int16 COcclusion::PreviousListWalkThroughFA; +int16 COcclusion::NumActiveOccluders; +COccluder COcclusion::aOccluders[NUMOCCLUSIONVOLUMES]; +CActiveOccluder COcclusion::aActiveOccluders[NUMACTIVEOCCLUDERS]; + +CVector gCenterOnScreen; + +float gMinYInOccluder; +float gMinXInOccluder; +float gMaxYInOccluder; +float gMaxXInOccluder; + +bool gOccluderCoorsValid[8]; +CVector gOccluderCoorsOnScreen[8]; +CVector gOccluderCoors[8]; + +#ifndef MASTER +bool bDispayOccDebugStuff; // disPAY, yeah +#endif + +void +COcclusion::Init(void) +{ + NumOccludersOnMap = 0; +#ifndef MASTER + VarConsole.Add("Occlusion debug", &bDispayOccDebugStuff, true); +#endif + FarAwayList = -1; + NearbyList = -1; + ListWalkThroughFA = -1; + PreviousListWalkThroughFA = -1; +} + +void +COcclusion::AddOne(float x, float y, float z, float width, float length, float height, float angle) +{ + if(NumOccludersOnMap >= NUMOCCLUSIONVOLUMES) + return; + + aOccluders[NumOccludersOnMap].x = x; + aOccluders[NumOccludersOnMap].y = y; + aOccluders[NumOccludersOnMap].z = z; + aOccluders[NumOccludersOnMap].width = width; + aOccluders[NumOccludersOnMap].length = length; + aOccluders[NumOccludersOnMap].height = height; + while(angle < 0.0f) angle += 360.0f; + while(angle > 360.0f) angle -= 360.0f; + aOccluders[NumOccludersOnMap].angle = angle/360.0f * UINT16_MAX; + aOccluders[NumOccludersOnMap].listIndex = FarAwayList; + FarAwayList = NumOccludersOnMap++; +} + +bool +COccluder::NearCamera() { + return (TheCamera.GetPosition() - CVector(x, y, z)).Magnitude() - (Max(width, length) / 2.0f) < 250.0f; +} + +bool +DoesInfiniteLineCrossFiniteLine(float p1X, float p1Y, float p2X, float p2Y, float lineX, float lineY, float lineDX, float lineDY) +{ + float side1 = (p1X - lineX) * lineDY - (p1Y - lineY) * lineDX; + float side2 = (p2X - lineX) * lineDY - (p2Y - lineY) * lineDX; + return side1 * side2 < 0.0f; // if points lie on opposite sides of the infinte line, the line between them crosses it +} + +bool DoesInfiniteLineTouchScreen(float lineX, float lineY, float lineDX, float lineDY) { + if (lineX > 0.0f && lineY > 0.0f && SCREEN_WIDTH > lineX && SCREEN_HEIGHT > lineY) + return true; + + return (DoesInfiniteLineCrossFiniteLine(0.0f, 0.0f, SCREEN_WIDTH, 0.0f, lineX, lineY, lineDX, lineDY) || + DoesInfiniteLineCrossFiniteLine(0.0f, 0.0f, 0.0f, SCREEN_HEIGHT, lineX, lineY, lineDX, lineDY) || + DoesInfiniteLineCrossFiniteLine(SCREEN_WIDTH, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, lineX, lineY, lineDX, lineDY) || + DoesInfiniteLineCrossFiniteLine(0.0f, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, lineX, lineY, lineDX, lineDY)); +} + +bool IsPointInsideLine(float lineX, float lineY, float lineDX, float lineDY, float pX, float pY, float area = 0.0f) { + return (pX - lineX) * lineDY - (pY - lineY) * lineDX >= area; +} + +bool CalcScreenCoors(CVector const &in, CVector *out, float *outw, float *outh) { + *out = TheCamera.m_viewMatrix * in; + + if (out->z <= 1.0f) return false; + + float recip = 1.0f / out->z; + out->x *= SCREEN_WIDTH * recip; + out->y *= SCREEN_HEIGHT * recip; + + float fovScale = DefaultFOV / CDraw::GetFOV(); + + *outw = fovScale * recip * SCREEN_WIDTH; + *outh = fovScale * recip * SCREEN_HEIGHT; + + return true; +} + +bool CalcScreenCoors(CVector const &in, CVector *out) { + *out = TheCamera.m_viewMatrix * in; + + if (out->z <= 1.0f) return false; + + float recip = 1.0f / out->z; + out->x *= SCREEN_WIDTH * recip; + out->y *= SCREEN_HEIGHT * recip; + + return true; +} + +bool +COccluder::ProcessLineSegment(int corner1, int corner2, CActiveOccluder *occl) { + if (!gOccluderCoorsValid[corner1] && !gOccluderCoorsValid[corner2]) + return false; + + float x1, y1, x2, y2; + + CVector p1, p2; + if (!gOccluderCoorsValid[corner1]) { + float clipDist1 = Abs((TheCamera.m_viewMatrix * gOccluderCoors[corner1]).z - 1.1f); + float clipDist2 = Abs((TheCamera.m_viewMatrix * gOccluderCoors[corner2]).z - 1.1f); + float ratio = clipDist2 / (clipDist1 + clipDist2); + CVector clippedCoors = (1.0f - ratio) * gOccluderCoors[corner2] + ratio * gOccluderCoors[corner1]; + + if (!CalcScreenCoors(clippedCoors, &p1, &x1, &y1)) + return true; + } + else { + p1 = gOccluderCoorsOnScreen[corner1]; + } + + if (!gOccluderCoorsValid[corner2]) { + float clipDist1 = Abs((TheCamera.m_viewMatrix * gOccluderCoors[corner1]).z - 1.1f); + float clipDist2 = Abs((TheCamera.m_viewMatrix * gOccluderCoors[corner2]).z - 1.1f); + float ratio = clipDist1 / (clipDist1 + clipDist2); + CVector clippedCoors = (1.0f - ratio) * gOccluderCoors[corner2] + ratio * gOccluderCoors[corner1]; + + if (!CalcScreenCoors(clippedCoors, &p2, &x2, &y2)) + return true; + } + else { + p2 = gOccluderCoorsOnScreen[corner2]; + } + + gMinXInOccluder = Min(Min(gMinXInOccluder, p1.x), p2.x); + gMaxXInOccluder = Max(Max(gMaxXInOccluder, p1.x), p2.x); + gMinYInOccluder = Min(Min(gMinYInOccluder, p1.y), p2.y); + gMaxYInOccluder = Max(Max(gMaxYInOccluder, p1.y), p2.y); + + CVector2D origin = p1; + CVector2D direction = p2 - p1; + + // Make sure lines are counter-clockwise around center + if (!IsPointInsideLine(origin.x, origin.y, direction.x, direction.y, gCenterOnScreen.x, gCenterOnScreen.y, 0.0f)) { + origin += direction; + direction *= -1.0f; + } + + float magnitude = direction.Magnitude(); + + occl->lines[occl->linesCount].origin = origin; + occl->lines[occl->linesCount].direction = direction / magnitude; + occl->lines[occl->linesCount].length = magnitude; + + if (!DoesInfiniteLineTouchScreen(origin.x, origin.y, direction.x, direction.y)) + return !IsPointInsideLine(origin.x, origin.y, direction.x, direction.y, SCREEN_WIDTH / 2.0f, SCREEN_HEIGHT / 2.0f, 0.0f); + + occl->linesCount++; + + return false; +} + +bool +COccluder::ProcessOneOccluder(CActiveOccluder *occl) { + float outX, outY; + + occl->linesCount = 0; + CVector pos(x, y, z); + + if (!CalcScreenCoors(pos, &gCenterOnScreen, &outX, &outY) || gCenterOnScreen.z < -150.0f || gCenterOnScreen.z > 300.0f) { + return false; + } + + occl->radius = Max(width, length) * 0.35f + gCenterOnScreen.z; + + CVector vec[3]; + + vec[0].x = length / 2.0f * Sin(GetAngle()); + vec[0].y = -length / 2.0f * Cos(GetAngle()); + vec[0].z = 0.0f; + + vec[1].x = width / 2.0f * Cos(GetAngle()); + vec[1].y = width / 2.0f * Sin(GetAngle()); + vec[1].z = 0.0f; + + vec[2].x = 0.0f; + vec[2].y = 0.0f; + vec[2].z = height / 2.0f; + + // Figure out if we see the front or back of a face + bool bFrontFace[6]; + for (int i = 0; i < 3; i++) { + bFrontFace[i*2+0] = DotProduct((pos + vec[i] - TheCamera.GetPosition()), vec[i]) < 0.0f; + bFrontFace[i*2+1] = DotProduct((pos - vec[i] - TheCamera.GetPosition()), -vec[i]) < 0.0f; + } + + //calculating vertices of a box + gOccluderCoors[0] = pos + vec[0] + vec[1] + vec[2]; + gOccluderCoors[1] = pos - vec[0] + vec[1] + vec[2]; + gOccluderCoors[2] = pos + vec[0] - vec[1] + vec[2]; + gOccluderCoors[3] = pos - vec[0] - vec[1] + vec[2]; + gOccluderCoors[4] = pos + vec[0] + vec[1] - vec[2]; + gOccluderCoors[5] = pos - vec[0] + vec[1] - vec[2]; + gOccluderCoors[6] = pos + vec[0] - vec[1] - vec[2]; + gOccluderCoors[7] = pos - vec[0] - vec[1] - vec[2]; + + for(int i = 0; i < 8; i++) + gOccluderCoorsValid[i] = CalcScreenCoors(gOccluderCoors[i], &gOccluderCoorsOnScreen[i], &outX, &outY); + + gMinYInOccluder = 999999.875f; + gMinXInOccluder = 999999.875f; + gMaxYInOccluder = -999999.875f; + gMaxXInOccluder = -999999.875f; + + // Between two differently facing sides we see an edge, so process those + if (bFrontFace[2] != bFrontFace[0] && ProcessLineSegment(0, 4, occl)) + return false; + if (bFrontFace[3] != bFrontFace[0] && ProcessLineSegment(2, 6, occl)) + return false; + if (bFrontFace[4] != bFrontFace[0] && ProcessLineSegment(0, 2, occl)) + return false; + if (bFrontFace[5] != bFrontFace[0] && ProcessLineSegment(4, 6, occl)) + return false; + if (bFrontFace[2] != bFrontFace[1] && ProcessLineSegment(1, 5, occl)) + return false; + if (bFrontFace[3] != bFrontFace[1] && ProcessLineSegment(3, 7, occl)) + return false; + if (bFrontFace[4] != bFrontFace[1] && ProcessLineSegment(1, 3, occl)) + return false; + if (bFrontFace[5] != bFrontFace[1] && ProcessLineSegment(5, 7, occl)) + return false; + if (bFrontFace[4] != bFrontFace[2] && ProcessLineSegment(0, 1, occl)) + return false; + if (bFrontFace[3] != bFrontFace[4] && ProcessLineSegment(2, 3, occl)) + return false; + if (bFrontFace[5] != bFrontFace[3] && ProcessLineSegment(6, 7, occl)) + return false; + if (bFrontFace[2] != bFrontFace[5] && ProcessLineSegment(4, 5, occl)) + return false; + + if (gMaxXInOccluder - gMinXInOccluder < SCREEN_WIDTH * 0.1f || + gMaxYInOccluder - gMinYInOccluder < SCREEN_HEIGHT * 0.07f) + return false; + + return true; +} + +bool +COcclusion::OccluderHidesBehind(CActiveOccluder *occl1, CActiveOccluder *occl2) { + for (int i = 0; i < occl1->linesCount; i++) { + for (int j = 0; j < occl2->linesCount; j++) { + if (!IsPointInsideLine(occl2->lines[j].origin.x, occl2->lines[j].origin.y, occl2->lines[j].direction.x, + occl2->lines[j].direction.y, occl1->lines[i].origin.x, occl1->lines[i].origin.y, 0.0f)) + return false; + + + if (!IsPointInsideLine(occl2->lines[j].origin.x, occl2->lines[j].origin.y, occl2->lines[j].direction.x, + occl2->lines[j].direction.y, (occl1->lines[i].origin.x + occl1->lines[i].direction.x * occl1->lines[i].length), + (occl1->lines[i].origin.y + occl1->lines[i].direction.y * occl1->lines[i].length), 0.0f)) + return false; + } + } + + return true; +} + +void +COcclusion::ProcessBeforeRendering(void) +{ + NumActiveOccluders = 0; + +#ifndef MASTER + if (gbModelViewer) + return; +#endif + + if (CGame::currArea != AREA_MAIN_MAP) + return; + + if (ListWalkThroughFA == -1) { + PreviousListWalkThroughFA = -1; + ListWalkThroughFA = FarAwayList; + } + + int i; + for (i = 0; i < 16 && ListWalkThroughFA != -1; i++) { + if (aOccluders[ListWalkThroughFA].NearCamera()) { + int prevListWalkThroughFA = ListWalkThroughFA; + + if (PreviousListWalkThroughFA == -1) { + FarAwayList = aOccluders[ListWalkThroughFA].listIndex; + } + else { + aOccluders[PreviousListWalkThroughFA].listIndex = aOccluders[ListWalkThroughFA].listIndex; + } + + int prevNearbyList = NearbyList; + ListWalkThroughFA = aOccluders[ListWalkThroughFA].listIndex; + NearbyList = prevListWalkThroughFA; + aOccluders[prevListWalkThroughFA].listIndex = prevNearbyList; + } + else { + PreviousListWalkThroughFA = ListWalkThroughFA; + ListWalkThroughFA = aOccluders[ListWalkThroughFA].listIndex; + } + } + + int prevNearbyList = -1; + int tmpNearbyList = NearbyList; + int indexTmpNearbyList, storeTmpNearbyList, prevFarAwayList; + while (tmpNearbyList != -1) + { + if (NumActiveOccluders < NUMACTIVEOCCLUDERS && aOccluders[tmpNearbyList].ProcessOneOccluder(&aActiveOccluders[NumActiveOccluders])) + ++NumActiveOccluders; + + indexTmpNearbyList = tmpNearbyList; + if (aOccluders[indexTmpNearbyList].NearCamera()) + { + prevNearbyList = tmpNearbyList; + tmpNearbyList = aOccluders[indexTmpNearbyList].listIndex; + + } + else + { + storeTmpNearbyList = tmpNearbyList; + if (prevNearbyList == -1) { + NearbyList = aOccluders[indexTmpNearbyList].listIndex; + } + else { + aOccluders[prevNearbyList].listIndex = aOccluders[indexTmpNearbyList].listIndex; + } + tmpNearbyList = aOccluders[indexTmpNearbyList].listIndex; + prevFarAwayList = FarAwayList; + FarAwayList = storeTmpNearbyList; + aOccluders[storeTmpNearbyList].listIndex = prevFarAwayList; + } + } + + for (i = 0; i < NumActiveOccluders; i++) { + for (int j = 0; j < NumActiveOccluders; j++) { + if (i != j && aActiveOccluders[j].radius < aActiveOccluders[i].radius) { + if (OccluderHidesBehind(&aActiveOccluders[i], &aActiveOccluders[j])) { + for (int k = i; k < NumActiveOccluders - 1; k++) { + for (int l = 0; l < aActiveOccluders[k + 1].linesCount; l++) + aActiveOccluders[k].lines[l] = aActiveOccluders[k + 1].lines[l]; + aActiveOccluders[k].linesCount = aActiveOccluders[k + 1].linesCount; + aActiveOccluders[k].radius = aActiveOccluders[k + 1].radius; + } + NumActiveOccluders--; + i--; + // Taken from Mobile! +#ifdef FIX_BUGS + if (i == -1) { + i = 0; + } +#endif + } + } + } + } +} + +bool CActiveOccluder::IsPointWithinOcclusionArea(float pX, float pY, float area) { + for (int i = 0; i < linesCount; i++) { + if (!IsPointInsideLine(lines[i].origin.x, lines[i].origin.y, lines[i].direction.x, lines[i].direction.y, pX, pY, area)) + return false; + } + + return true; +} + +bool COcclusion::IsAABoxOccluded(CVector pos, float width, float length, float height) { + + CVector coors; + float outW, outH; + + if (!NumActiveOccluders || !CalcScreenCoors(pos, &coors, &outW, &outH)) + return false; + + float side = CVector(width, length, height).Magnitude() / 4.0f; + float area = Max(outW, outH) * side; + + CVector minCorner, maxCorner; + + minCorner.x = pos.x - width / 2.0f; + minCorner.y = pos.y - length / 2.0f; + minCorner.z = pos.z - height / 2.0f; + + maxCorner.x = pos.x + width / 2.0f; + maxCorner.y = pos.y + length / 2.0f; + maxCorner.z = pos.z + height / 2.0f; + + for (int i = 0; i < NumActiveOccluders; i++) { + if (coors.z - (side * 0.85f) > aActiveOccluders[i].radius) { + if (aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, area)) + return true; + + if (aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) { + if (CalcScreenCoors(minCorner, &coors) && !aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + if (CalcScreenCoors(CVector(maxCorner.x, maxCorner.y, minCorner.z), &coors) && !aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + if (CalcScreenCoors(CVector(maxCorner.x, minCorner.y, maxCorner.z), &coors) && !aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + if (CalcScreenCoors(CVector(minCorner.x, maxCorner.y, maxCorner.z), &coors, &outW, &outH) && !aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + + return true; + } + } + } + + return false; +} + +bool COcclusion::IsPositionOccluded(CVector pos, float side) { + + CVector coors; + float width, height; + + if (!NumActiveOccluders || !CalcScreenCoors(pos, &coors, &width, &height)) + return false; + + float area = Max(width, height) * side; + + for (int i = 0; i < NumActiveOccluders; i++) { + if (coors.z - (side * 0.85f) > aActiveOccluders[i].radius) + if (aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, area)) + return true; + } + + return false; +} + +#ifndef MASTER +#include "Lines.h" + +RwIm2DVertex vertexbufferT[2]; + +void COcclusion::Render() { + if (!bDispayOccDebugStuff || !(CTimer::GetTimeInMilliseconds() & 0x200)) + return; + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, FALSE); + + float recipz = 1.0f/RwCameraGetNearClipPlane(Scene.camera); + for (int i = 0; i < NumActiveOccluders; i++) { + for (int j = 0; j < aActiveOccluders[i].linesCount; j++) { + RwIm2DVertexSetScreenX(&vertexbufferT[0], aActiveOccluders[i].lines[j].origin.x); + RwIm2DVertexSetScreenY(&vertexbufferT[0], aActiveOccluders[i].lines[j].origin.y); + RwIm2DVertexSetScreenZ(&vertexbufferT[0], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&vertexbufferT[0], RwCameraGetNearClipPlane(Scene.camera)); + RwIm2DVertexSetRecipCameraZ(&vertexbufferT[0], recipz); + + RwIm2DVertexSetScreenX(&vertexbufferT[1], + aActiveOccluders[i].lines[j].origin.x + aActiveOccluders[i].lines[j].direction.x * aActiveOccluders[i].lines[j].length); + RwIm2DVertexSetScreenY(&vertexbufferT[1], + aActiveOccluders[i].lines[j].origin.y + aActiveOccluders[i].lines[j].direction.y * aActiveOccluders[i].lines[j].length); + RwIm2DVertexSetScreenZ(&vertexbufferT[1], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetCameraZ(&vertexbufferT[1], RwCameraGetNearClipPlane(Scene.camera)); + RwIm2DVertexSetRecipCameraZ(&vertexbufferT[1], recipz); + + RwIm2DVertexSetIntRGBA(&vertexbufferT[0], 255, 255, 0, 255); + RwIm2DVertexSetIntRGBA(&vertexbufferT[1], 255, 255, 0, 255); + RwIm2DRenderLine(vertexbufferT, 2, 0, 1); + } + } + + DefinedState(); +} +#endif + +bool CEntity::IsEntityOccluded(void) { + + CVector coors; + float width, height; + + if (COcclusion::NumActiveOccluders == 0 || !CalcScreenCoors(GetBoundCentre(), &coors, &width, &height)) + return false; + + float area = Max(width, height) * GetBoundRadius() * 0.9f; + + for (int i = 0; i < COcclusion::NumActiveOccluders; i++) { + if (coors.z - (GetBoundRadius() * 0.85f) > COcclusion::aActiveOccluders[i].radius) { + if (COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, area)) { + return true; + } + + if (COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) { + CVector min = m_matrix * CModelInfo::GetColModel(m_modelIndex)->boundingBox.min; + CVector max = m_matrix * CModelInfo::GetColModel(m_modelIndex)->boundingBox.max; + + if (CalcScreenCoors(min, &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + if (CalcScreenCoors(CVector(max.x, max.y, min.z), &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + if (CalcScreenCoors(CVector(max.x, min.y, max.z), &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + if (CalcScreenCoors(CVector(min.x, max.y, max.z), &coors) && !COcclusion::aActiveOccluders[i].IsPointWithinOcclusionArea(coors.x, coors.y, 0.0f)) continue; + + return true; + } + } + } + + return false; +} \ No newline at end of file diff --git a/src/renderer/Occlusion.h b/src/renderer/Occlusion.h new file mode 100644 index 00000000..e0edef53 --- /dev/null +++ b/src/renderer/Occlusion.h @@ -0,0 +1,62 @@ +#pragma once + +struct ActiveOccluderLine { + CVector2D origin; + CVector2D direction; + float length; +}; + +class CActiveOccluder { + +public: + ActiveOccluderLine lines[6]; + int32 linesCount; + float radius; + + bool IsPointWithinOcclusionArea(float x, float y, float area); +}; + +class COccluder +{ +public: + int16 length, width, height; + int16 x, y, z; + uint16 angle; + int16 listIndex; + + bool NearCamera(); + bool ProcessOneOccluder(CActiveOccluder *occl); + bool ProcessLineSegment(int corner1, int corner2, CActiveOccluder* occl); + float GetAngle(void) { return angle*TWOPI/UINT16_MAX; } +}; + +class COcclusion +{ +public: + static int32 NumOccludersOnMap; + static int16 FarAwayList; + static int16 NearbyList; + static int16 ListWalkThroughFA; + static int16 PreviousListWalkThroughFA; + static int16 NumActiveOccluders; + + static COccluder aOccluders[NUMOCCLUSIONVOLUMES]; + static CActiveOccluder aActiveOccluders[NUMACTIVEOCCLUDERS]; + + static void Init(void); + static void AddOne(float x, float y, float z, float width, float length, float height, float angle); + static void ProcessBeforeRendering(void); + static bool OccluderHidesBehind(CActiveOccluder *occl1, CActiveOccluder *occl2); + static bool IsAABoxOccluded(CVector pos, float width, float length, float height); + static bool IsPositionOccluded(CVector pos, float side); +#ifndef MASTER + static void Render(); +#endif +}; + +bool CalcScreenCoors(CVector const &in, CVector *out, float *outw, float *outh); +bool CalcScreenCoors(CVector const &in, CVector *out); + +#ifndef MASTER +extern bool bDispayOccDebugStuff; +#endif \ No newline at end of file diff --git a/src/renderer/Particle.cpp b/src/renderer/Particle.cpp new file mode 100644 index 00000000..461a10a6 --- /dev/null +++ b/src/renderer/Particle.cpp @@ -0,0 +1,2534 @@ +#include "common.h" + +#include "main.h" +#include "General.h" +#include "Timer.h" +#include "TxdStore.h" +#include "Sprite.h" +#include "Camera.h" +#include "Clock.h" +#include "Collision.h" +#include "World.h" +#include "Shadows.h" +#include "Replay.h" +#include "Stats.h" +#include "Weather.h" +#include "MBlur.h" +#include "main.h" +#include "AudioScriptObject.h" +#include "ParticleObject.h" +#include "Particle.h" +#include "soundlist.h" +#include "SaveBuf.h" +#include "debugmenu.h" + +#define MAX_PARTICLES_ON_SCREEN (750) + + +//(5) +#define MAX_SMOKE_FILES ARRAY_SIZE(SmokeFiles) + +//(5) +#define MAX_RUBBER_FILES ARRAY_SIZE(RubberFiles) +//(5) +#define MAX_RAINSPLASH_FILES ARRAY_SIZE(RainSplashFiles) +//(3) +#define MAX_WATERSPRAY_FILES ARRAY_SIZE(WatersprayFiles) +//(6) +#define MAX_EXPLOSIONMEDIUM_FILES ARRAY_SIZE(ExplosionMediumFiles) +//(4) +#define MAX_GUNFLASH_FILES ARRAY_SIZE(GunFlashFiles) +//(2) +#define MAX_RAINSPLASHUP_FILES ARRAY_SIZE(RainSplashupFiles) +//(4) +#define MAX_BIRDFRONT_FILES ARRAY_SIZE(BirdfrontFiles) +//(8) +#define MAX_BOAT_FILES ARRAY_SIZE(BoatFiles) +//(4) +#define MAX_CARDEBRIS_FILES ARRAY_SIZE(CardebrisFiles) +//(4) +#define MAX_CARSPLASH_FILES ARRAY_SIZE(CarsplashFiles) + +#define MAX_RAINDRIP_FILES (2) + +#define MAX_LEAF_FILES (2) + + +const char SmokeFiles[][6+1] = +{ + "smoke1", + "smoke2", + "smoke3", + "smoke4", + "smoke5" +}; + + +const char RubberFiles[][7+1] = +{ + "rubber1", + "rubber2", + "rubber3", + "rubber4", + "rubber5" +}; + +const char RainSplashFiles[][7+1] = +{ + "splash1", + "splash2", + "splash3", + "splash4", + "splash5" +}; + +const char WatersprayFiles[][11+1] = +{ + "waterspray1", + "waterspray2", + "waterspray3" +}; + +const char ExplosionMediumFiles[][7+1] = +{ + "explo01", + "explo02", + "explo03", + "explo04", + "explo05", + "explo06" +}; + +const char GunFlashFiles[][9+1] = +{ + "gunflash1", + "gunflash2", + "gunflash3", + "gunflash4" +}; + +const char RainSplashupFiles[][10+1] = +{ + "splash_up1", + "splash_up2" +}; + +const char BirdfrontFiles[][8+1] = +{ + "birdf_01", + "birdf_02", + "birdf_03", + "birdf_04" +}; + +const char BoatFiles[][8+1] = +{ + "boats_01", + "boats_02", + "boats_03", + "boats_04", + "boats_05", + "boats_06", + "boats_07", + "boats_08" +}; + +const char CardebrisFiles[][12+1] = +{ + "cardebris_01", + "cardebris_02", + "cardebris_03", + "cardebris_04" +}; + +const char CarsplashFiles[][12+1] = +{ + "carsplash_01", + "carsplash_02", + "carsplash_03", + "carsplash_04" +}; + +CParticle gParticleArray[MAX_PARTICLES_ON_SCREEN]; + +RwTexture *gpSmokeTex[MAX_SMOKE_FILES]; +RwTexture *gpSmoke2Tex; +RwTexture *gpRubberTex[MAX_RUBBER_FILES]; +RwTexture *gpRainSplashTex[MAX_RAINSPLASH_FILES]; +RwTexture *gpWatersprayTex[MAX_WATERSPRAY_FILES]; +RwTexture *gpExplosionMediumTex[MAX_EXPLOSIONMEDIUM_FILES]; +RwTexture *gpGunFlashTex[MAX_GUNFLASH_FILES]; +RwTexture *gpRainSplashupTex[MAX_RAINSPLASHUP_FILES]; +RwTexture *gpBirdfrontTex[MAX_BIRDFRONT_FILES]; +RwTexture *gpBoatTex[MAX_BOAT_FILES]; +RwTexture *gpCarDebrisTex[MAX_CARDEBRIS_FILES]; +RwTexture *gpCarSplashTex[MAX_CARSPLASH_FILES]; + +RwTexture *gpBoatWakeTex; +RwTexture *gpFlame1Tex; +RwTexture *gpFlame5Tex; +RwTexture *gpRainDropSmallTex; +RwTexture *gpBloodTex; +RwTexture *gpLeafTex[MAX_LEAF_FILES]; +RwTexture *gpCloudTex1; +RwTexture *gpCloudTex4; +RwTexture *gpBloodSmallTex; +RwTexture *gpGungeTex; +RwTexture *gpCollisionSmokeTex; +RwTexture *gpBulletHitTex; +RwTexture *gpGunShellTex; +RwTexture *gpPointlightTex; + +RwRaster *gpSmokeRaster[MAX_SMOKE_FILES]; +RwRaster *gpSmoke2Raster; +RwRaster *gpRubberRaster[MAX_RUBBER_FILES]; +RwRaster *gpRainSplashRaster[MAX_RAINSPLASH_FILES]; +RwRaster *gpWatersprayRaster[MAX_WATERSPRAY_FILES]; +RwRaster *gpExplosionMediumRaster[MAX_EXPLOSIONMEDIUM_FILES]; +RwRaster *gpGunFlashRaster[MAX_GUNFLASH_FILES]; +RwRaster *gpRainSplashupRaster[MAX_RAINSPLASHUP_FILES]; +RwRaster *gpBirdfrontRaster[MAX_BIRDFRONT_FILES]; +RwRaster *gpBoatRaster[MAX_BOAT_FILES]; +RwRaster *gpCarDebrisRaster[MAX_CARDEBRIS_FILES]; +RwRaster *gpCarSplashRaster[MAX_CARSPLASH_FILES]; + +RwRaster *gpBoatWakeRaster; +RwRaster *gpFlame1Raster; +RwRaster *gpFlame5Raster; +RwRaster *gpRainDropSmallRaster; +RwRaster *gpBloodRaster; +RwRaster *gpLeafRaster[MAX_LEAF_FILES]; +RwRaster *gpCloudRaster1; +RwRaster *gpCloudRaster4; +RwRaster *gpBloodSmallRaster; +RwRaster *gpGungeRaster; +RwRaster *gpCollisionSmokeRaster; +RwRaster *gpBulletHitRaster; +RwRaster *gpGunShellRaster; +RwRaster *gpPointlightRaster; + +RwTexture *gpRainDropTex; +RwRaster *gpRainDropRaster; + +RwTexture *gpSparkTex; +RwTexture *gpNewspaperTex; +RwTexture *gpGunSmokeTex; +RwTexture *gpDotTex; +RwTexture *gpHeatHazeTex; +RwTexture *gpBeastieTex; +RwTexture *gpRainDripTex[MAX_RAINDRIP_FILES]; +RwTexture *gpRainDripDarkTex[MAX_RAINDRIP_FILES]; + +RwRaster *gpSparkRaster; +RwRaster *gpNewspaperRaster; +RwRaster *gpGunSmokeRaster; +RwRaster *gpDotRaster; +RwRaster *gpHeatHazeRaster; +RwRaster *gpBeastieRaster; +RwRaster *gpRainDripRaster[MAX_RAINDRIP_FILES]; +RwRaster *gpRainDripDarkRaster[MAX_RAINDRIP_FILES]; + +float CParticle::ms_afRandTable[CParticle::RAND_TABLE_SIZE]; +CParticle *CParticle::m_pUnusedListHead; +float CParticle::m_SinTable[CParticle::SIN_COS_TABLE_SIZE]; +float CParticle::m_CosTable[CParticle::SIN_COS_TABLE_SIZE]; + +int32 Randomizer; +int32 nParticleCreationInterval = 1; +float PARTICLE_WIND_TEST_SCALE = 0.002f; +float fParticleScaleLimit = 0.5f; + +bool clearWaterDrop; +int32 numWaterDropOnScreen; + +#ifdef DEBUGMENU +SETTWEAKPATH("Particle"); +TWEAKINT32(nParticleCreationInterval, 0, 5, 1); +TWEAKFLOAT(fParticleScaleLimit, 0.0f, 1.0f, 0.1f); +TWEAKFUNC(CParticle::ReloadConfig); +#endif + + + +void CParticle::ReloadConfig() +{ + debug("Initialising CParticleMgr..."); + + mod_ParticleSystemManager.Initialise(); + + debug("Initialising CParticle..."); + + m_pUnusedListHead = gParticleArray; + + for ( int32 i = 0; i < MAX_PARTICLES_ON_SCREEN; i++ ) + { + if ( i == MAX_PARTICLES_ON_SCREEN - 1 ) + gParticleArray[i].m_pNext = nil; + else + gParticleArray[i].m_pNext = &gParticleArray[i + 1]; + + gParticleArray[i].m_vecPosition = CVector(0.0f, 0.0f, 0.0f); + + gParticleArray[i].m_vecVelocity = CVector(0.0f, 0.0f, 0.0f); + + gParticleArray[i].m_nTimeWhenWillBeDestroyed = 0; + + gParticleArray[i].m_nTimeWhenColorWillBeChanged = 0; + + gParticleArray[i].m_fSize = 0.2f; + + gParticleArray[i].m_fExpansionRate = 0.0f; + + gParticleArray[i].m_nColorIntensity = 255; + + gParticleArray[i].m_nFadeToBlackTimer = 0; + + gParticleArray[i].m_nAlpha = 255; + + gParticleArray[i].m_nFadeAlphaTimer = 0; + + gParticleArray[i].m_nCurrentZRotation = 0; + + gParticleArray[i].m_nZRotationTimer = 0; + + gParticleArray[i].m_fCurrentZRadius = 0.0f; + + gParticleArray[i].m_nZRadiusTimer = 0; + + gParticleArray[i].m_nCurrentFrame = 0; + + gParticleArray[i].m_nAnimationSpeedTimer = 0; + + gParticleArray[i].m_nRotation = 0; + + gParticleArray[i].m_nRotationStep = 0; + } +} + +void CParticle::Initialise() +{ + ReloadConfig(); + + CParticleObject::Initialise(); + + float randVal = -1.0f; + for ( int32 i = 0; i < RAND_TABLE_SIZE; i++ ) + { + ms_afRandTable[i] = randVal; + randVal += 0.1f; + } + + for ( int32 i = 0; i < SIN_COS_TABLE_SIZE; i++ ) + { + float angle = DEGTORAD(float(i) * float(360.0f / SIN_COS_TABLE_SIZE)); + + m_SinTable[i] = ::Sin(angle); + m_CosTable[i] = ::Cos(angle); + } + + int32 slot = CTxdStore::FindTxdSlot("particle"); + + CTxdStore::PushCurrentTxd(); + CTxdStore::SetCurrentTxd(slot); + + for ( int32 i = 0; i < MAX_SMOKE_FILES; i++ ) + { + gpSmokeTex[i] = RwTextureRead(SmokeFiles[i], nil); + gpSmokeRaster[i] = RwTextureGetRaster(gpSmokeTex[i]); + } + + gpSmoke2Tex = RwTextureRead("smokeII_3", nil); + gpSmoke2Raster = RwTextureGetRaster(gpSmoke2Tex); + + for ( int32 i = 0; i < MAX_RUBBER_FILES; i++ ) + { + gpRubberTex[i] = RwTextureRead(RubberFiles[i], nil); + gpRubberRaster[i] = RwTextureGetRaster(gpRubberTex[i]); + } + + for ( int32 i = 0; i < MAX_RAINSPLASH_FILES; i++ ) + { + gpRainSplashTex[i] = RwTextureRead(RainSplashFiles[i], nil); + gpRainSplashRaster[i] = RwTextureGetRaster(gpRainSplashTex[i]); + } + + for ( int32 i = 0; i < MAX_WATERSPRAY_FILES; i++ ) + { + gpWatersprayTex[i] = RwTextureRead(WatersprayFiles[i], nil); + gpWatersprayRaster[i] = RwTextureGetRaster(gpWatersprayTex[i]); + } + + for ( int32 i = 0; i < MAX_EXPLOSIONMEDIUM_FILES; i++ ) + { + gpExplosionMediumTex[i] = RwTextureRead(ExplosionMediumFiles[i], nil); + gpExplosionMediumRaster[i] = RwTextureGetRaster(gpExplosionMediumTex[i]); + } + + for ( int32 i = 0; i < MAX_GUNFLASH_FILES; i++ ) + { + gpGunFlashTex[i] = RwTextureRead(GunFlashFiles[i], nil); + gpGunFlashRaster[i] = RwTextureGetRaster(gpGunFlashTex[i]); + } + + gpRainDropTex = RwTextureRead("raindrop4", nil); + gpRainDropRaster = RwTextureGetRaster(gpRainDropTex); + + + for ( int32 i = 0; i < MAX_RAINSPLASHUP_FILES; i++ ) + { + gpRainSplashupTex[i] = RwTextureRead(RainSplashupFiles[i], nil); + gpRainSplashupRaster[i] = RwTextureGetRaster(gpRainSplashupTex[i]); + } + + for ( int32 i = 0; i < MAX_BIRDFRONT_FILES; i++ ) + { + gpBirdfrontTex[i] = RwTextureRead(BirdfrontFiles[i], nil); + gpBirdfrontRaster[i] = RwTextureGetRaster(gpBirdfrontTex[i]); + } + + for ( int32 i = 0; i < MAX_BOAT_FILES; i++ ) + { + gpBoatTex[i] = RwTextureRead(BoatFiles[i], nil); + gpBoatRaster[i] = RwTextureGetRaster(gpBoatTex[i]); + } + + for ( int32 i = 0; i < MAX_CARDEBRIS_FILES; i++ ) + { + gpCarDebrisTex[i] = RwTextureRead(CardebrisFiles[i], nil); + gpCarDebrisRaster[i] = RwTextureGetRaster(gpCarDebrisTex[i]); + } + + for ( int32 i = 0; i < MAX_CARSPLASH_FILES; i++ ) + { + gpCarSplashTex[i] = RwTextureRead(CarsplashFiles[i], nil); + gpCarSplashRaster[i] = RwTextureGetRaster(gpCarSplashTex[i]); + } + + gpBoatWakeTex = RwTextureRead("boatwake2", nil); + gpBoatWakeRaster = RwTextureGetRaster(gpBoatWakeTex); + + gpFlame1Tex = RwTextureRead("flame1", nil); + gpFlame1Raster = RwTextureGetRaster(gpFlame1Tex); + + gpFlame5Tex = RwTextureRead("flame5", nil); + +//#ifdef FIX_BUGS +#if 0 + gpFlame5Raster = RwTextureGetRaster(gpFlame5Tex); +#else + // this seems to have become more of a design choice + gpFlame5Raster = RwTextureGetRaster(gpFlame1Tex); // copy-paste bug ? +#endif + + gpRainDropSmallTex = RwTextureRead("rainsmall", nil); + gpRainDropSmallRaster = RwTextureGetRaster(gpRainDropSmallTex); + + gpBloodTex = RwTextureRead("blood", nil); + gpBloodRaster = RwTextureGetRaster(gpBloodTex); + + gpLeafTex[0] = RwTextureRead("gameleaf01_64", nil); + gpLeafRaster[0] = RwTextureGetRaster(gpLeafTex[0]); + + gpLeafTex[1] = RwTextureRead("letter", nil); + gpLeafRaster[1] = RwTextureGetRaster(gpLeafTex[1]); + + gpCloudTex1 = RwTextureRead("cloud3", nil); + gpCloudRaster1 = RwTextureGetRaster(gpCloudTex1); + + gpCloudTex4 = RwTextureRead("cloudmasked", nil); + gpCloudRaster4 = RwTextureGetRaster(gpCloudTex4); + + gpBloodSmallTex = RwTextureRead("bloodsplat2", nil); + gpBloodSmallRaster = RwTextureGetRaster(gpBloodSmallTex); + + gpGungeTex = RwTextureRead("gunge", nil); + gpGungeRaster = RwTextureGetRaster(gpGungeTex); + + gpCollisionSmokeTex = RwTextureRead("collisionsmoke", nil); + gpCollisionSmokeRaster = RwTextureGetRaster(gpCollisionSmokeTex); + + gpBulletHitTex = RwTextureRead("bullethitsmoke", nil); + gpBulletHitRaster = RwTextureGetRaster(gpBulletHitTex); + + gpGunShellTex = RwTextureRead("gunshell", nil); + gpGunShellRaster = RwTextureGetRaster(gpGunShellTex); + + gpPointlightTex = RwTextureRead("pointlight", nil); + gpPointlightRaster = RwTextureGetRaster(gpPointlightTex); + + gpSparkTex = RwTextureRead("spark", nil); + gpSparkRaster = RwTextureGetRaster(gpSparkTex); + + gpNewspaperTex = RwTextureRead("newspaper02_64", nil); + gpNewspaperRaster = RwTextureGetRaster(gpNewspaperTex); + + gpGunSmokeTex = RwTextureRead("gunsmoke3", nil); + gpGunSmokeRaster = RwTextureGetRaster(gpGunSmokeTex); + + gpDotTex = RwTextureRead("dot", nil); + gpDotRaster = RwTextureGetRaster(gpDotTex); + + gpHeatHazeTex = RwTextureRead("heathaze", nil); + gpHeatHazeRaster = RwTextureGetRaster(gpHeatHazeTex); + + gpBeastieTex = RwTextureRead("beastie", nil); + gpBeastieRaster = RwTextureGetRaster(gpBeastieTex); + + gpRainDripTex[0] = RwTextureRead("raindrip64", nil); + gpRainDripRaster[0] = RwTextureGetRaster(gpRainDripTex[0]); + + gpRainDripTex[1] = RwTextureRead("raindripb64", nil); + gpRainDripRaster[1] = RwTextureGetRaster(gpRainDripTex[1]); + + gpRainDripDarkTex[0] = RwTextureRead("raindrip64_d", nil); + gpRainDripDarkRaster[0] = RwTextureGetRaster(gpRainDripDarkTex[0]); + + gpRainDripDarkTex[1] = RwTextureRead("raindripb64_d", nil); + gpRainDripDarkRaster[1] = RwTextureGetRaster(gpRainDripDarkTex[1]); + + CTxdStore::PopCurrentTxd(); + + for ( int32 i = 0; i < MAX_PARTICLES; i++ ) + { + tParticleSystemData *entry = &mod_ParticleSystemManager.m_aParticles[i]; + + switch ( i ) + { + case PARTICLE_SPARK: + case PARTICLE_SPARK_SMALL: + case PARTICLE_RAINDROP_SMALL: + case PARTICLE_HELI_ATTACK: + entry->m_ppRaster = &gpRainDropSmallRaster; + break; + + case PARTICLE_WATER_SPARK: + entry->m_ppRaster = &gpSparkRaster; + break; + + case PARTICLE_WHEEL_DIRT: + case PARTICLE_SAND: + case PARTICLE_STEAM2: + case PARTICLE_STEAM_NY: + case PARTICLE_STEAM_NY_SLOWMOTION: + case PARTICLE_GROUND_STEAM: + case PARTICLE_ENGINE_STEAM: + case PARTICLE_PEDFOOT_DUST: + case PARTICLE_CAR_DUST: + case PARTICLE_EXHAUST_FUMES: + entry->m_ppRaster = &gpSmoke2Raster; + break; + + case PARTICLE_WHEEL_WATER: + case PARTICLE_WATER: + case PARTICLE_SMOKE: + case PARTICLE_SMOKE_SLOWMOTION: + case PARTICLE_DRY_ICE: + case PARTICLE_GARAGEPAINT_SPRAY: + case PARTICLE_STEAM: + case PARTICLE_WATER_CANNON: + case PARTICLE_EXTINGUISH_STEAM: + case PARTICLE_HELI_DUST: + case PARTICLE_PAINT_SMOKE: + case PARTICLE_BULLETHIT_SMOKE: + entry->m_ppRaster = gpSmokeRaster; + break; + + case PARTICLE_BLOOD: + entry->m_ppRaster = &gpBloodRaster; + break; + + case PARTICLE_BLOOD_SMALL: + case PARTICLE_BLOOD_SPURT: + entry->m_ppRaster = &gpBloodSmallRaster; + break; + + case PARTICLE_DEBRIS: + case PARTICLE_TREE_LEAVES: + entry->m_ppRaster = gpLeafRaster; + break; + + case PARTICLE_DEBRIS2: + entry->m_ppRaster = &gpGungeRaster; + break; + + case PARTICLE_FLYERS: + entry->m_ppRaster = &gpNewspaperRaster; + break; + + case PARTICLE_FLAME: + case PARTICLE_CARFLAME: + entry->m_ppRaster = &gpFlame1Raster; + break; + + case PARTICLE_FIREBALL: + entry->m_ppRaster = &gpFlame5Raster; + break; + + case PARTICLE_GUNFLASH: + case PARTICLE_GUNFLASH_NOANIM: + entry->m_ppRaster = gpGunFlashRaster; + break; + + + case PARTICLE_GUNSMOKE: + case PARTICLE_WATERDROP: + case PARTICLE_BLOODDROP: + case PARTICLE_HEATHAZE: + case PARTICLE_HEATHAZE_IN_DIST: + entry->m_ppRaster = nil; + break; + + case PARTICLE_GUNSMOKE2: + case PARTICLE_BOAT_THRUSTJET: + case PARTICLE_RUBBER_SMOKE: + entry->m_ppRaster = gpRubberRaster; + break; + + case PARTICLE_CIGARETTE_SMOKE: + entry->m_ppRaster = &gpGunSmokeRaster; + break; + + case PARTICLE_TEARGAS: + entry->m_ppRaster = &gpHeatHazeRaster; + break; + + case PARTICLE_SHARD: + case PARTICLE_RAINDROP: + case PARTICLE_RAINDROP_2D: + entry->m_ppRaster = &gpRainDropRaster; + break; + + case PARTICLE_SPLASH: + case PARTICLE_PED_SPLASH: + case PARTICLE_CAR_SPLASH: + case PARTICLE_WATER_HYDRANT: + entry->m_ppRaster = gpCarSplashRaster; + break; + + case PARTICLE_RAIN_SPLASH: + case PARTICLE_RAIN_SPLASH_BIGGROW: + entry->m_ppRaster = gpRainSplashRaster; + break; + + case PARTICLE_RAIN_SPLASHUP: + entry->m_ppRaster = gpRainSplashupRaster; + break; + + case PARTICLE_WATERSPRAY: + entry->m_ppRaster = gpWatersprayRaster; + break; + + case PARTICLE_EXPLOSION_MEDIUM: + case PARTICLE_EXPLOSION_LARGE: + case PARTICLE_EXPLOSION_MFAST: + case PARTICLE_EXPLOSION_LFAST: + entry->m_ppRaster = gpExplosionMediumRaster; + break; + + case PARTICLE_BOAT_SPLASH: + entry->m_ppRaster = &gpBoatWakeRaster; + break; + + case PARTICLE_ENGINE_SMOKE: + case PARTICLE_ENGINE_SMOKE2: + case PARTICLE_CARFLAME_SMOKE: + case PARTICLE_FIREBALL_SMOKE: + case PARTICLE_ROCKET_SMOKE: + case PARTICLE_TEST: + entry->m_ppRaster = &gpCloudRaster4; + break; + + case PARTICLE_CARCOLLISION_DUST: + case PARTICLE_BURNINGRUBBER_SMOKE: + entry->m_ppRaster = &gpCollisionSmokeRaster; + break; + + case PARTICLE_CAR_DEBRIS: + case PARTICLE_HELI_DEBRIS: + case PARTICLE_BIRD_DEBRIS: + entry->m_ppRaster = gpCarDebrisRaster; + break; + + case PARTICLE_GUNSHELL_FIRST: + case PARTICLE_GUNSHELL: + case PARTICLE_GUNSHELL_BUMP1: + case PARTICLE_GUNSHELL_BUMP2: + entry->m_ppRaster = &gpGunShellRaster; + break; + + + case PARTICLE_BIRD_FRONT: + entry->m_ppRaster = gpBirdfrontRaster; + break; + + case PARTICLE_SHIP_SIDE: + entry->m_ppRaster = gpBoatRaster; + break; + + case PARTICLE_BEASTIE: + entry->m_ppRaster = &gpBeastieRaster; + break; + } + } + + debug("CParticle ready"); +} + +void CParticle::Shutdown() +{ + debug("Shutting down CParticle..."); + + for ( int32 i = 0; i < MAX_SMOKE_FILES; i++ ) + { + RwTextureDestroy(gpSmokeTex[i]); + gpSmokeTex[i] = nil; + } + + RwTextureDestroy(gpSmoke2Tex); + gpSmoke2Tex = nil; + + for ( int32 i = 0; i < MAX_RUBBER_FILES; i++ ) + { + RwTextureDestroy(gpRubberTex[i]); + gpRubberTex[i] = nil; + } + + for ( int32 i = 0; i < MAX_RAINSPLASH_FILES; i++ ) + { + RwTextureDestroy(gpRainSplashTex[i]); + gpRainSplashTex[i] = nil; + } + + for ( int32 i = 0; i < MAX_WATERSPRAY_FILES; i++ ) + { + RwTextureDestroy(gpWatersprayTex[i]); + gpWatersprayTex[i] = nil; + } + + for ( int32 i = 0; i < MAX_EXPLOSIONMEDIUM_FILES; i++ ) + { + RwTextureDestroy(gpExplosionMediumTex[i]); + gpExplosionMediumTex[i] = nil; + } + + for ( int32 i = 0; i < MAX_GUNFLASH_FILES; i++ ) + { + RwTextureDestroy(gpGunFlashTex[i]); + gpGunFlashTex[i] = nil; + } + + RwTextureDestroy(gpRainDropTex); + gpRainDropTex = nil; + + for ( int32 i = 0; i < MAX_RAINSPLASHUP_FILES; i++ ) + { + RwTextureDestroy(gpRainSplashupTex[i]); + gpRainSplashupTex[i] = nil; + } + + for ( int32 i = 0; i < MAX_BIRDFRONT_FILES; i++ ) + { + RwTextureDestroy(gpBirdfrontTex[i]); + gpBirdfrontTex[i] = nil; + } + + for ( int32 i = 0; i < MAX_BOAT_FILES; i++ ) + { + RwTextureDestroy(gpBoatTex[i]); + gpBoatTex[i] = nil; + } + + for ( int32 i = 0; i < MAX_CARDEBRIS_FILES; i++ ) + { + RwTextureDestroy(gpCarDebrisTex[i]); + gpCarDebrisTex[i] = nil; + } + + for ( int32 i = 0; i < MAX_CARSPLASH_FILES; i++ ) + { + RwTextureDestroy(gpCarSplashTex[i]); + gpCarSplashTex[i] = nil; + } + + for ( int32 i = 0; i < MAX_RAINDRIP_FILES; i++ ) + { + RwTextureDestroy(gpRainDripTex[i]); + gpRainDripTex[i] = nil; + + RwTextureDestroy(gpRainDripDarkTex[i]); + gpRainDripDarkTex[i] = nil; + } + + RwTextureDestroy(gpBoatWakeTex); + gpBoatWakeTex = nil; + + RwTextureDestroy(gpFlame1Tex); + gpFlame1Tex = nil; + + RwTextureDestroy(gpFlame5Tex); + gpFlame5Tex = nil; + + RwTextureDestroy(gpRainDropSmallTex); + gpRainDropSmallTex = nil; + + RwTextureDestroy(gpBloodTex); + gpBloodTex = nil; + + RwTextureDestroy(gpLeafTex[0]); + gpLeafTex[0] = nil; + + RwTextureDestroy(gpLeafTex[1]); + gpLeafTex[1] = nil; + + RwTextureDestroy(gpCloudTex1); + gpCloudTex1 = nil; + + RwTextureDestroy(gpCloudTex4); + gpCloudTex4 = nil; + + RwTextureDestroy(gpBloodSmallTex); + gpBloodSmallTex = nil; + + RwTextureDestroy(gpGungeTex); + gpGungeTex = nil; + + RwTextureDestroy(gpCollisionSmokeTex); + gpCollisionSmokeTex = nil; + + RwTextureDestroy(gpBulletHitTex); + gpBulletHitTex = nil; + + RwTextureDestroy(gpGunShellTex); + gpGunShellTex = nil; + + RwTextureDestroy(gpPointlightTex); + gpPointlightTex = nil; + + RwTextureDestroy(gpSparkTex); + gpSparkTex = nil; + + RwTextureDestroy(gpNewspaperTex); + gpNewspaperTex = nil; + + RwTextureDestroy(gpGunSmokeTex); + gpGunSmokeTex = nil; + + RwTextureDestroy(gpDotTex); + gpDotTex = nil; + RwTextureDestroy(gpHeatHazeTex); + gpHeatHazeTex = nil; + + RwTextureDestroy(gpBeastieTex); + gpBeastieTex = nil; + + int32 slot; + + slot = CTxdStore::FindTxdSlot("particle"); + CTxdStore::RemoveTxdSlot(slot); + + debug("CParticle shut down"); +} + + +void CParticle::AddParticlesAlongLine(tParticleType type, CVector const &vecStart, CVector const &vecEnd, CVector const &vecDir, float fPower, CEntity *pEntity, float fSize, int32 nRotationSpeed, int32 nRotation, int32 nCurFrame, int32 nLifeSpan) +{ + CVector vecDist = vecEnd - vecStart; + float fDist = vecDist.Magnitude(); + float fSteps = Max(fDist / fPower, 1.0f); + int32 nSteps = (int32)fSteps; + + CVector vecStep = vecDist * (1.0f / (float)nSteps); + + for ( int32 i = 0; i < nSteps; i++ ) + { + CVector vecPos = float(i) * vecStep + vecStart; + AddParticle(type, vecPos, vecDir, pEntity, fSize, nRotationSpeed, nRotation, nCurFrame, nLifeSpan); + } +} + +void CParticle::AddParticlesAlongLine(tParticleType type, CVector const &vecStart, CVector const &vecEnd, CVector const &vecDir, float fPower, CEntity *pEntity, float fSize, RwRGBA const &color, int32 nRotationSpeed, int32 nRotation, int32 nCurFrame, int32 nLifeSpan) +{ + CVector vecDist = vecEnd - vecStart; + float fDist = vecDist.Magnitude(); + float fSteps = Max(fDist / fPower, 1.0f); + int32 nSteps = (int32)fSteps; + + CVector vecStep = vecDist * (1.0f / (float)nSteps); + + for ( int32 i = 0; i < nSteps; i++ ) + { + CVector vecPos = float(i) * vecStep + vecStart; + + AddParticle(type, vecPos, vecDir, pEntity, fSize, color, nRotationSpeed, nRotation, nCurFrame, nLifeSpan); + } +} + +CParticle *CParticle::AddParticle(tParticleType type, CVector const &vecPos, CVector const &vecDir, CEntity *pEntity, float fSize, int32 nRotationSpeed, int32 nRotation, int32 nCurFrame, int32 nLifeSpan) +{ + CRGBA color(0, 0, 0, 0); + return AddParticle(type, vecPos, vecDir, pEntity, fSize, color, nRotationSpeed, nRotation, nCurFrame, nLifeSpan); +} + +CParticle *CParticle::AddParticle(tParticleType type, CVector const &vecPos, CVector const &vecDir, CEntity *pEntity, float fSize, RwRGBA const &color, int32 nRotationSpeed, int32 nRotation, int32 nCurFrame, int32 nLifeSpan) +{ + if ( CTimer::GetIsPaused() ) + return nil; + + if ( ( type == PARTICLE_ENGINE_SMOKE + || type == PARTICLE_ENGINE_SMOKE2 + || type == PARTICLE_ENGINE_STEAM + || type == PARTICLE_CARFLAME_SMOKE + || type == PARTICLE_RUBBER_SMOKE + || type == PARTICLE_BURNINGRUBBER_SMOKE + || type == PARTICLE_EXHAUST_FUMES + || type == PARTICLE_CARCOLLISION_DUST ) + && nParticleCreationInterval & CTimer::GetFrameCounter() ) + { + return nil; + } + + if ( !CReplay::IsPlayingBack() ) + CReplay::RecordParticle(type, vecPos, vecDir, fSize, color); + + CParticle *pParticle = m_pUnusedListHead; + + if ( pParticle == nil ) + return nil; + + tParticleSystemData *psystem = &mod_ParticleSystemManager.m_aParticles[type]; + + if ( psystem->m_fCreateRange != 0.0f && psystem->m_fCreateRange < ( TheCamera.GetPosition() - vecPos ).MagnitudeSqr() ) + return nil; + + + pParticle->m_fSize = psystem->m_fDefaultInitialRadius; + pParticle->m_fExpansionRate = psystem->m_fExpansionRate; + + if ( nLifeSpan != 0 ) + pParticle->m_nTimeWhenWillBeDestroyed = CTimer::GetTimeInMilliseconds() + nLifeSpan; + else + pParticle->m_nTimeWhenWillBeDestroyed = CTimer::GetTimeInMilliseconds() + psystem->m_nLifeSpan; + + pParticle->m_nColorIntensity = psystem->m_nFadeToBlackInitialIntensity; + + pParticle->m_nFadeToBlackTimer = psystem->m_nFadeToBlackAmount; + + if ( psystem->m_nFadeToBlackTime ) + pParticle->m_nFadeToBlackTimer /= psystem->m_nFadeToBlackTime; + + pParticle->m_nAlpha = psystem->m_nFadeAlphaInitialIntensity; + + pParticle->m_nFadeAlphaTimer = psystem->m_nFadeAlphaAmount; + + if ( psystem->m_nFadeAlphaTime ) + pParticle->m_nFadeAlphaTimer /= psystem->m_nFadeAlphaTime; + + pParticle->m_nCurrentZRotation = psystem->m_nZRotationInitialAngle; + pParticle->m_fCurrentZRadius = psystem->m_fInitialZRadius; + + if ( nCurFrame != 0 ) + pParticle->m_nCurrentFrame = nCurFrame; + else + pParticle->m_nCurrentFrame = psystem->m_nStartAnimationFrame; + + + pParticle->m_nZRotationTimer = 0; + pParticle->m_nZRadiusTimer = 0; + pParticle->m_nAnimationSpeedTimer = 0; + pParticle->m_fZGround = 0.0f; + + if ( type != PARTICLE_HEATHAZE ) + pParticle->m_vecPosition = vecPos; + else + { + CVector screen; + float w, h; + + if ( !CSprite::CalcScreenCoors(vecPos, &screen, &w, &h, true) ) + return nil; + + pParticle->m_vecPosition = screen; + psystem->m_vecTextureStretch.x = w; + psystem->m_vecTextureStretch.y = h; + } + + pParticle->m_vecVelocity = vecDir; + + pParticle->m_vecParticleMovementOffset = CVector(0.0f, 0.0f, 0.0f); + pParticle->m_nTimeWhenColorWillBeChanged = 0; + + if ( color.alpha != 0 ) + RwRGBAAssign(&pParticle->m_Color, &color); + else + { + RwRGBAAssign(&pParticle->m_Color, psystem->m_RenderColouring); + + if ( psystem->m_ColorFadeTime != 0 ) + pParticle->m_nTimeWhenColorWillBeChanged = CTimer::GetTimeInMilliseconds() + psystem->m_ColorFadeTime; + + if ( psystem->m_InitialColorVariation != 0 ) + { + int32 ColorVariation = CGeneral::GetRandomNumberInRange(-psystem->m_InitialColorVariation, psystem->m_InitialColorVariation); + //float ColorVariation = CGeneral::GetRandomNumberInRange((float)-psystem->m_InitialColorVariation, (float)psystem->m_InitialColorVariation); + + pParticle->m_Color.red = Clamp(pParticle->m_Color.red + + PERCENT(pParticle->m_Color.red, ColorVariation), + 0, 255); + + pParticle->m_Color.green = Clamp(pParticle->m_Color.green + + PERCENT(pParticle->m_Color.green, ColorVariation), + 0, 255); + + pParticle->m_Color.blue = Clamp(pParticle->m_Color.blue + + PERCENT(pParticle->m_Color.blue, ColorVariation), + 0, 255); + } + } + + pParticle->m_nRotation = nRotation; + + if ( nRotationSpeed != 0 ) + pParticle->m_nRotationStep = nRotationSpeed; + else + pParticle->m_nRotationStep = psystem->m_nRotationSpeed; + + if ( CGeneral::GetRandomNumber() & 1 ) + pParticle->m_nRotationStep = -pParticle->m_nRotationStep; + + if ( psystem->m_fPositionRandomError != 0.0f ) + { + pParticle->m_vecPosition.x += psystem->m_fPositionRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; + pParticle->m_vecPosition.y += psystem->m_fPositionRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; + + if ( psystem->Flags & RAND_VERT_V ) + pParticle->m_vecPosition.z += psystem->m_fPositionRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; + } + + if ( psystem->m_fVelocityRandomError != 0.0f ) + { + pParticle->m_vecVelocity.x += psystem->m_fVelocityRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; + pParticle->m_vecVelocity.y += psystem->m_fVelocityRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; + + if ( psystem->Flags & RAND_VERT_V ) + pParticle->m_vecVelocity.z += psystem->m_fVelocityRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; + } + + if ( psystem->m_fExpansionRateError != 0.0f && !(psystem->Flags & SCREEN_TRAIL) ) + pParticle->m_fExpansionRate += psystem->m_fExpansionRateError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE] + psystem->m_fExpansionRateError; + + if ( psystem->m_nRotationRateError != 0 ) + pParticle->m_nRotationStep += CGeneral::GetRandomNumberInRange(-psystem->m_nRotationRateError, psystem->m_nRotationRateError); + + if ( psystem->m_nLifeSpanErrorShape != 0 ) + { + float randVal = ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; + if ( randVal > 0.0f ) + pParticle->m_nTimeWhenWillBeDestroyed += int32(float(psystem->m_nLifeSpan) * randVal * float(psystem->m_nLifeSpanErrorShape)); + else + pParticle->m_nTimeWhenWillBeDestroyed += int32(float(psystem->m_nLifeSpan) * randVal / float(psystem->m_nLifeSpanErrorShape)); + } + + if ( psystem->Flags & ZCHECK_FIRST ) + { + static bool bValidGroundFound = false; + static CVector LastTestCoors; + static float LastTestGroundZ; + + if ( bValidGroundFound + && vecPos.x == LastTestCoors.x + && vecPos.y == LastTestCoors.y + && vecPos.z == LastTestCoors.z ) + { + pParticle->m_fZGround = LastTestGroundZ; + } + else + { + bValidGroundFound = false; + + CColPoint point; + CEntity *entity; + + if ( !CWorld::ProcessVerticalLine( + pParticle->m_vecPosition + CVector(0.0f, 0.0f, 0.5f), + -100.0f, point, entity, true, true, false, false, true, false, nil) ) + { + return nil; + } + + if ( point.point.z >= pParticle->m_vecPosition.z ) + return nil; + + pParticle->m_fZGround = point.point.z; + bValidGroundFound = true; + LastTestCoors = vecPos; + LastTestGroundZ = point.point.z; + } + } + + if ( psystem->Flags & ZCHECK_BUMP ) + { + static float Z_Ground = 0.0f; + + if ( psystem->Flags & ZCHECK_BUMP_FIRST ) + { + bool bZFound = false; + + Z_Ground = CWorld::FindGroundZFor3DCoord(vecPos.x, vecPos.y, vecPos.z, (bool *)&bZFound); + + if ( bZFound == false ) + return nil; + + pParticle->m_fZGround = Z_Ground; + } + + pParticle->m_fZGround = Z_Ground; + } + + switch ( type ) + { + case PARTICLE_DEBRIS: + pParticle->m_vecVelocity.z *= CGeneral::GetRandomNumberInRange(0.5f, 3.0f); + break; + + case PARTICLE_EXPLOSION_MEDIUM: + pParticle->m_nColorIntensity -= 30 * (CGeneral::GetRandomNumber() & 1); // mb "+= -30 * rand" here ? + pParticle->m_nAnimationSpeedTimer = CGeneral::GetRandomNumber() & 7; + pParticle->m_fSize = CGeneral::GetRandomNumberInRange(0.3f, 0.8f); + pParticle->m_vecPosition.z -= CGeneral::GetRandomNumberInRange(-0.1f, 0.1f); + break; + + case PARTICLE_EXPLOSION_LARGE: + pParticle->m_nColorIntensity -= 30 * (CGeneral::GetRandomNumber() & 1); // mb "+= -30 * rand" here ? + pParticle->m_nAnimationSpeedTimer = CGeneral::GetRandomNumber() & 7; + pParticle->m_fSize = CGeneral::GetRandomNumberInRange(0.8f, 1.4f); + pParticle->m_vecPosition.z -= CGeneral::GetRandomNumberInRange(-0.3f, 0.3f); + break; + + case PARTICLE_WATER_HYDRANT: + pParticle->m_vecPosition.z += 20.0f * psystem->m_fPositionRandomError * ms_afRandTable[CGeneral::GetRandomNumber() % RAND_TABLE_SIZE]; + break; + default: break; + } + + if ( fSize != 0.0f ) + pParticle->m_fSize = fSize; + + m_pUnusedListHead = pParticle->m_pNext; + + pParticle->m_pNext = psystem->m_pParticles; + + psystem->m_pParticles = pParticle; + + return pParticle; +} + +void CParticle::Update() +{ + if ( CTimer::GetIsPaused() ) + return; + + CRGBA color(0, 0, 0, 0); + + float fFricDeccel50 = pow(0.50f, CTimer::GetTimeStep()); + float fFricDeccel80 = pow(0.80f, CTimer::GetTimeStep()); + float fFricDeccel90 = pow(0.90f, CTimer::GetTimeStep()); + float fFricDeccel95 = pow(0.95f, CTimer::GetTimeStep()); + float fFricDeccel96 = pow(0.96f, CTimer::GetTimeStep()); + float fFricDeccel99 = pow(0.99f, CTimer::GetTimeStep()); + + CParticleObject::UpdateAll(); + + // ejaculation at 23:00, 23:15, 23:30, 23:45 + if ( CClock::ms_nGameClockHours == 23 && + ( CClock::ms_nGameClockMinutes == 0 + || CClock::ms_nGameClockMinutes == 15 + || CClock::ms_nGameClockMinutes == 30 + || CClock::ms_nGameClockMinutes == 45 ) ) + { + AddParticle(PARTICLE_CAR_SPLASH, + CVector(557.03f, -4.0f, 151.46f), + CVector(0.0f, 0.0f, 2.5f), + NULL, + 2.0f, + CRGBA(255, 255, 255, 255), + 0, + 0, + 1, + 1000); + } + + for ( int32 i = 0; i < MAX_PARTICLES; i++ ) + { + tParticleSystemData *psystem = &mod_ParticleSystemManager.m_aParticles[i]; + CParticle *particle = psystem->m_pParticles; + CParticle *prevParticle = nil; + bool bRemoveParticle; + + if ( particle == nil ) + continue; + + for ( ; particle != nil; _Next(particle, prevParticle, psystem, bRemoveParticle) ) + { + CVector vecWind(0.0f, 0.0f, 0.0f); + + bRemoveParticle = false; + + CVector vecMoveStep = particle->m_vecVelocity * CTimer::GetTimeStep(); + CVector vecPos = particle->m_vecPosition; + + if ( numWaterDropOnScreen == 0 ) + clearWaterDrop = false; + + if ( psystem->m_Type == PARTICLE_WATERDROP ) + { + if ( CGame::IsInInterior() || clearWaterDrop == true ) + { + bRemoveParticle = true; + continue; + } + + static uint8 nWaterDropCount; + + if ( nWaterDropCount == 5 ) + { + vecMoveStep = CVector(0.0f, 0.0f, 0.0f); + particle->m_nTimeWhenWillBeDestroyed += 1250; + nWaterDropCount = 0; + } + else + { + if ( TheCamera.m_CameraAverageSpeed > 0.35f ) + { + if ( vecMoveStep.Magnitude() > 0.5f ) + { + if ( vecMoveStep.Magnitude() > 0.4f && vecMoveStep.Magnitude() < 0.8f ) + { + vecMoveStep.x += TheCamera.m_CameraAverageSpeed * 1.5f; + vecMoveStep.y += TheCamera.m_CameraAverageSpeed * 1.5f; + } + else if ( vecMoveStep.Magnitude() != 0.0f ) + { + vecMoveStep.x += CGeneral::GetRandomNumberInRange(0.01f, 0.05f); + vecMoveStep.y += CGeneral::GetRandomNumberInRange(0.01f, 0.05f); + } + } + } + + nWaterDropCount++; + } + + if ( vecPos.z <= 1.5f ) + vecMoveStep.z = 0.0f; + } + + if ( psystem->m_Type == PARTICLE_HEATHAZE || psystem->m_Type == PARTICLE_HEATHAZE_IN_DIST ) + { +#ifdef FIX_BUGS + int32 nSinCosIndex = (int32(DEGTORAD((float)particle->m_nRotation) * float(SIN_COS_TABLE_SIZE) / TWOPI) + SIN_COS_TABLE_SIZE) % SIN_COS_TABLE_SIZE; +#else + int32 nSinCosIndex = int32(DEGTORAD((float)particle->m_nRotation) * float(SIN_COS_TABLE_SIZE) / TWOPI) % SIN_COS_TABLE_SIZE; +#endif + vecMoveStep.x = Sin(nSinCosIndex); + vecMoveStep.y = Sin(nSinCosIndex); + + if ( psystem->m_Type == PARTICLE_HEATHAZE_IN_DIST ) + particle->m_nRotation = int16((float)particle->m_nRotation + 0.75f); + else + particle->m_nRotation = int16((float)particle->m_nRotation + 1.0f); + } + + if ( psystem->m_Type == PARTICLE_BEASTIE ) + { +#ifdef FIX_BUGS + int32 nSinCosIndex = (int32(DEGTORAD((float)particle->m_nRotation) * float(SIN_COS_TABLE_SIZE) / TWOPI) + SIN_COS_TABLE_SIZE) % SIN_COS_TABLE_SIZE; +#else + int32 nSinCosIndex = int32(DEGTORAD((float)particle->m_nRotation) * float(SIN_COS_TABLE_SIZE) / TWOPI) % SIN_COS_TABLE_SIZE; +#endif + particle->m_vecVelocity.x = 0.50f * Cos(nSinCosIndex); + particle->m_vecVelocity.y = Cos(nSinCosIndex); + particle->m_vecVelocity.z = 0.25f * Sin(nSinCosIndex); + + if ( particle->m_vecVelocity.Magnitude() > 2.0f + || vecPos.z > 40.0f + || (TheCamera.GetPosition() - vecPos).Magnitude() < 60.0f + ) + { + bRemoveParticle = true; + continue; + } + } + + vecPos += vecMoveStep; + + if ( psystem->m_Type == PARTICLE_FIREBALL ) + { + AddParticle(PARTICLE_HEATHAZE, particle->m_vecPosition, CVector(0.0f, 0.0f, 0.0f), + nil, particle->m_fSize * 5.0f); + } + + if ( psystem->m_Type == PARTICLE_GUNSMOKE2 ) + { + if ( CTimer::GetFrameCounter() & 10 ) + { +#ifdef FIX_BUGS + if ( FindPlayerPed() && FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN ) +#else + if ( FindPlayerPed()->GetWeapon()->m_eWeaponType == WEAPONTYPE_MINIGUN ) +#endif + { + AddParticle(PARTICLE_HEATHAZE, particle->m_vecPosition, CVector(0.0f, 0.0f, 0.0f)); + } + } + } + + if ( CWeather::Wind > 0.0f ) + { + if ( vecMoveStep.Magnitude() != 0.0f ) + { + vecWind.x = CGeneral::GetRandomNumberInRange(0.75f, 1.25f) * -CWeather::Wind; + vecWind.y = CGeneral::GetRandomNumberInRange(0.75f, 1.25f) * -CWeather::Wind; + vecWind *= PARTICLE_WIND_TEST_SCALE * psystem->m_fWindFactor * CTimer::GetTimeStep(); + particle->m_vecVelocity += vecWind; + } + } + + if ( psystem->m_Type == PARTICLE_RAINDROP + || psystem->m_Type == PARTICLE_RAINDROP_SMALL + || psystem->m_Type == PARTICLE_RAIN_SPLASH + || psystem->m_Type == PARTICLE_RAIN_SPLASH_BIGGROW + || psystem->m_Type == PARTICLE_CAR_SPLASH + || psystem->m_Type == PARTICLE_BOAT_SPLASH + || psystem->m_Type == PARTICLE_RAINDROP_2D ) + { + int32 nMaxDrops = int32(6.0f * TheCamera.m_CameraAverageSpeed + 1.0f); + float fDistToCam = 0.0f; + + if ( psystem->m_Type == PARTICLE_BOAT_SPLASH || psystem->m_Type == PARTICLE_CAR_SPLASH ) + { + if ( vecPos.z + particle->m_fSize < 5.0f ) + { + bRemoveParticle = true; + continue; + } + + switch ( TheCamera.GetLookDirection() ) + { + case LOOKING_LEFT: + case LOOKING_RIGHT: + case LOOKING_FORWARD: + nMaxDrops /= 2; + break; + + default: + nMaxDrops = 0; + break; + } + + fDistToCam = (TheCamera.GetPosition() - vecPos).Magnitude(); + } + + if ( numWaterDropOnScreen < nMaxDrops && numWaterDropOnScreen < 63 + && fDistToCam < 10.0f + && clearWaterDrop == false + && !CGame::IsInInterior() ) + { + CVector vecWaterdropTarget + ( + CGeneral::GetRandomNumberInRange(-0.25f, 0.25f), + CGeneral::GetRandomNumberInRange(0.1f, 0.75f), + -0.01f + ); + + CVector vecWaterdropPos; + + if ( TheCamera.m_CameraAverageSpeed < 0.35f ) + vecWaterdropPos.x = (float)CGeneral::GetRandomNumberInRange(50, int32(SCREEN_WIDTH) - 50); + else + vecWaterdropPos.x = (float)CGeneral::GetRandomNumberInRange(200, int32(SCREEN_WIDTH) - 200); + + if ( psystem->m_Type == PARTICLE_BOAT_SPLASH || psystem->m_Type == PARTICLE_CAR_SPLASH ) + vecWaterdropPos.y = (float)CGeneral::GetRandomNumberInRange(SCREEN_HEIGHT / 2, SCREEN_HEIGHT); + else + { + if ( TheCamera.m_CameraAverageSpeed < 0.35f ) + vecWaterdropPos.y = (float)CGeneral::GetRandomNumberInRange(0, int32(SCREEN_HEIGHT)); + else + vecWaterdropPos.y = (float)CGeneral::GetRandomNumberInRange(150, int32(SCREEN_HEIGHT) - 200); + } + + vecWaterdropPos.z = 2.0f; + + if ( AddParticle(PARTICLE_WATERDROP, + vecWaterdropPos, + vecWaterdropTarget, + nil, + CGeneral::GetRandomNumberInRange(0.1f, 0.15f), + 0, + 0, + CGeneral::GetRandomNumber() & 1, + 0) != nil ) + { + numWaterDropOnScreen++; + } + } + } + + if ( CTimer::GetTimeInMilliseconds() > particle->m_nTimeWhenWillBeDestroyed || particle->m_nAlpha == 0 ) + { + bRemoveParticle = true; + continue; + } + + if ( particle->m_nTimeWhenColorWillBeChanged != 0 ) + { + if ( particle->m_nTimeWhenColorWillBeChanged > CTimer::GetTimeInMilliseconds() ) + { + float colorMul = 1.0f - float(particle->m_nTimeWhenColorWillBeChanged - CTimer::GetTimeInMilliseconds()) / float(psystem->m_ColorFadeTime); + + particle->m_Color.red = Clamp( + psystem->m_RenderColouring.red + int32(float(psystem->m_FadeDestinationColor.red - psystem->m_RenderColouring.red) * colorMul), + 0, 255); + + particle->m_Color.green = Clamp( + psystem->m_RenderColouring.green + int32(float(psystem->m_FadeDestinationColor.green - psystem->m_RenderColouring.green) * colorMul), + 0, 255); + + particle->m_Color.blue = Clamp( + psystem->m_RenderColouring.blue + int32(float(psystem->m_FadeDestinationColor.blue - psystem->m_RenderColouring.blue) * colorMul), + 0, 255); + } + else + RwRGBAAssign(&particle->m_Color, psystem->m_FadeDestinationColor); + } + + if ( psystem->Flags & CLIPOUT2D ) + { + if ( particle->m_vecPosition.x < -10.0f || particle->m_vecPosition.x > SCREEN_WIDTH + 10.0f + || particle->m_vecPosition.y < -10.0f || particle->m_vecPosition.y > SCREEN_HEIGHT + 10.0f ) + { + bRemoveParticle = true; + continue; + } + } + + if ( !(psystem->Flags & SCREEN_TRAIL) ) + { + float size; + + if ( particle->m_fExpansionRate > 0.0f ) + { + float speed = Max(vecWind.Magnitude(), vecMoveStep.Magnitude()); + + if ( psystem->m_Type == PARTICLE_EXHAUST_FUMES || psystem->m_Type == PARTICLE_ENGINE_STEAM ) + speed *= 2.0f; + + if ( ( psystem->m_Type == PARTICLE_BOAT_SPLASH || psystem->m_Type == PARTICLE_CAR_SPLASH ) + && particle->m_fSize > 1.2f ) + { + size = particle->m_fSize - (1.0f + speed) * particle->m_fExpansionRate; + particle->m_vecVelocity.z -= 0.15f; + } + else + size = particle->m_fSize + (1.0f + speed) * particle->m_fExpansionRate; + } + else + size = particle->m_fSize + particle->m_fExpansionRate; + + if ( psystem->m_Type == PARTICLE_WATERDROP ) + size = (size - Abs(vecMoveStep.x) * 0.000150000007f) + (Abs(vecMoveStep.z) * 0.0500000007f); //TODO: + + if ( size < 0.0f ) + { + bRemoveParticle = true; + continue; + } + + particle->m_fSize = size; + } + + switch ( psystem->m_nFrictionDecceleration ) + { + case 50: + particle->m_vecVelocity *= fFricDeccel50; + break; + + case 80: + particle->m_vecVelocity *= fFricDeccel80; + break; + + case 90: + particle->m_vecVelocity *= fFricDeccel90; + break; + + case 95: + particle->m_vecVelocity *= fFricDeccel95; + break; + + case 96: + particle->m_vecVelocity *= fFricDeccel96; + break; + + case 99: + particle->m_vecVelocity *= fFricDeccel99; + break; + } + + if ( psystem->m_fGravitationalAcceleration > 0.0f ) + { + if ( -50.0f * psystem->m_fGravitationalAcceleration < particle->m_vecVelocity.z ) + particle->m_vecVelocity.z -= psystem->m_fGravitationalAcceleration * CTimer::GetTimeStep(); + + if ( psystem->Flags & ZCHECK_FIRST ) + { + if ( particle->m_vecPosition.z < particle->m_fZGround ) + { + switch ( psystem->m_Type ) + { + case PARTICLE_RAINDROP: + case PARTICLE_RAINDROP_SMALL: + { + bRemoveParticle = true; + + if ( CGeneral::GetRandomNumber() & 1 ) + { + AddParticle(PARTICLE_RAIN_SPLASH, + CVector + ( + particle->m_vecPosition.x, + particle->m_vecPosition.y, + 0.05f + particle->m_fZGround + ), + CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, 0, 0, 0, 0); + } + else + { + AddParticle(PARTICLE_RAIN_SPLASHUP, + CVector + ( + particle->m_vecPosition.x, + particle->m_vecPosition.y, + 0.05f + particle->m_fZGround + ), + CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, 0, 0, 0, 0); + } + + continue; + } + break; + + case PARTICLE_WHEEL_WATER: + { + bRemoveParticle = true; + + int32 randVal = CGeneral::GetRandomNumber(); + + if ( randVal & 1 ) + { + if ( (randVal % 5) == 0 ) + { + AddParticle(PARTICLE_RAIN_SPLASH, + CVector + ( + particle->m_vecPosition.x, + particle->m_vecPosition.y, + 0.05f + particle->m_fZGround + ), + CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, 0, 0, 0, 0); + } + else + { + AddParticle(PARTICLE_RAIN_SPLASHUP, + CVector + ( + particle->m_vecPosition.x, + particle->m_vecPosition.y, + 0.05f + particle->m_fZGround + ), + CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, 0, 0, 0, 0); + } + + } + continue; + } + break; + + case PARTICLE_BLOOD: + case PARTICLE_BLOOD_SMALL: + { + bRemoveParticle = true; + + CVector vecPosn = particle->m_vecPosition; + vecPosn.z += 1.0f; + + Randomizer++; + int32 randVal = int32(Randomizer & 7); + + if ( randVal == 5 ) + { + CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpBloodPoolTex, &vecPosn, + 0.1f, 0.0f, 0.0f, -0.1f, + 255, + 255, 0, 0, + 4.0f, (CGeneral::GetRandomNumber() & 4095) + 2000, 1.0f); + } + else if ( randVal == 2 ) + { + CShadows::AddPermanentShadow(SHADOWTYPE_DARK, gpBloodPoolTex, &vecPosn, + 0.2f, 0.0f, 0.0f, -0.2f, + 255, + 255, 0, 0, + 4.0f, (CGeneral::GetRandomNumber() & 4095) + 8000, 1.0f); + } + continue; + } + break; + default: break; + } + } + } + else if ( psystem->Flags & ZCHECK_STEP ) + { + CColPoint point; + CEntity *entity; + + if ( CWorld::ProcessVerticalLine(particle->m_vecPosition, vecPos.z, point, entity, + true, true, false, false, true, false, nil) ) + { + if ( vecPos.z <= point.point.z ) + { + vecPos.z = point.point.z; + if ( psystem->m_Type == PARTICLE_DEBRIS2 ) + { + particle->m_vecVelocity.x *= 0.8f; + particle->m_vecVelocity.y *= 0.8f; + particle->m_vecVelocity.z *= -0.4f; + if ( particle->m_vecVelocity.z < 0.005f ) + particle->m_vecVelocity.z = 0.0f; + } + } + } + } + else if ( psystem->Flags & ZCHECK_BUMP ) + { + if ( particle->m_vecPosition.z < particle->m_fZGround ) + { + switch ( psystem->m_Type ) + { + case PARTICLE_GUNSHELL_FIRST: + case PARTICLE_GUNSHELL: + { + bRemoveParticle = true; + + AddParticle(PARTICLE_GUNSHELL_BUMP1, + CVector + ( + particle->m_vecPosition.x, + particle->m_vecPosition.y, + 0.05f + particle->m_fZGround + ), + CVector + ( + CGeneral::GetRandomNumberInRange(-0.02f, 0.02f), + CGeneral::GetRandomNumberInRange(-0.02f, 0.02f), + CGeneral::GetRandomNumberInRange(0.05f, 0.1f) + ), + nil, + particle->m_fSize, color, particle->m_nRotationStep, 0, 0, 0); + + PlayOneShotScriptObject(SCRIPT_SOUND_GUNSHELL_DROP, particle->m_vecPosition); + } + break; + + case PARTICLE_GUNSHELL_BUMP1: + { + bRemoveParticle = true; + + AddParticle(PARTICLE_GUNSHELL_BUMP2, + CVector + ( + particle->m_vecPosition.x, + particle->m_vecPosition.y, + 0.05f + particle->m_fZGround + ), + CVector(0.0f, 0.0f, CGeneral::GetRandomNumberInRange(0.03f, 0.06f)), + nil, + particle->m_fSize, color, 0, 0, 0, 0); + + PlayOneShotScriptObject(SCRIPT_SOUND_GUNSHELL_DROP_SOFT, particle->m_vecPosition); + } + break; + + case PARTICLE_GUNSHELL_BUMP2: + { + bRemoveParticle = true; + continue; + } + break; + default: break; + } + } + } + } + else + { + if ( psystem->m_fGravitationalAcceleration < 0.0f ) + { + if ( -5.0f * psystem->m_fGravitationalAcceleration > particle->m_vecVelocity.z ) + particle->m_vecVelocity.z -= psystem->m_fGravitationalAcceleration * CTimer::GetTimeStep(); + } + else + { + if ( psystem->Flags & ZCHECK_STEP ) + { + CColPoint point; + CEntity *entity; + + if ( CWorld::ProcessVerticalLine(particle->m_vecPosition, vecPos.z, point, entity, + true, false, false, false, true, false, nil) ) + { + if ( vecPos.z <= point.point.z ) + { + vecPos.z = point.point.z; + if ( psystem->m_Type == PARTICLE_HELI_ATTACK ) + { + bRemoveParticle = true; + AddParticle(PARTICLE_STEAM, vecPos, CVector(0.0f, 0.0f, 0.05f), nil, 0.2f, 0, 0, 0, 0); + continue; + } + } + } + } + } + } + + if ( particle->m_nFadeToBlackTimer != 0 ) + { + particle->m_nColorIntensity = Clamp(particle->m_nColorIntensity - particle->m_nFadeToBlackTimer, + 0, 255); + } + + if ( particle->m_nFadeAlphaTimer != 0 ) + { + particle->m_nAlpha = Clamp(particle->m_nAlpha - particle->m_nFadeAlphaTimer, + 0, 255); + if ( particle->m_nAlpha == 0 ) + { + bRemoveParticle = true; + continue; + } + } + + if ( psystem->m_nZRotationAngleChangeAmount != 0 ) + { + if ( particle->m_nZRotationTimer >= psystem->m_nZRotationChangeTime ) + { + particle->m_nZRotationTimer = 0; + particle->m_nCurrentZRotation += psystem->m_nZRotationAngleChangeAmount; + } + else + ++particle->m_nZRotationTimer; + } + + if ( psystem->m_fZRadiusChangeAmount != 0.0f ) + { + if ( particle->m_nZRadiusTimer >= psystem->m_nZRadiusChangeTime ) + { + particle->m_nZRadiusTimer = 0; + particle->m_fCurrentZRadius += psystem->m_fZRadiusChangeAmount; + } + else + ++particle->m_nZRadiusTimer; + } + + if ( psystem->m_nAnimationSpeed != 0 ) + { + if ( particle->m_nAnimationSpeedTimer > psystem->m_nAnimationSpeed ) + { + particle->m_nAnimationSpeedTimer = 0; + + if ( ++particle->m_nCurrentFrame > psystem->m_nFinalAnimationFrame ) + { + if ( psystem->Flags & CYCLE_ANIM ) + particle->m_nCurrentFrame = psystem->m_nStartAnimationFrame; + else + --particle->m_nCurrentFrame; + } + } + else + ++particle->m_nAnimationSpeedTimer; + } + + if ( particle->m_nRotationStep != 0 ) +#ifdef FIX_BUGS + particle->m_nRotation = CGeneral::LimitAngle(particle->m_nRotation + particle->m_nRotationStep); +#else + particle->m_nRotation += particle->m_nRotationStep; +#endif + + if ( particle->m_fCurrentZRadius != 0.0f ) + { + int32 nSinCosIndex = particle->m_nCurrentZRotation % SIN_COS_TABLE_SIZE; + + float fX = (Cos(nSinCosIndex) - Sin(nSinCosIndex)) * particle->m_fCurrentZRadius; + + float fY = (Sin(nSinCosIndex) + Cos(nSinCosIndex)) * particle->m_fCurrentZRadius; + + vecPos -= particle->m_vecParticleMovementOffset; + + vecPos += CVector(fX, fY, 0.0f); + + particle->m_vecParticleMovementOffset = CVector(fX, fY, 0.0f); + } + + particle->m_vecPosition = vecPos; + } + } +} + +void CParticle::Render() +{ + PUSH_RENDERGROUP("CParticle::Render"); + + RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void *)rwTEXTUREADDRESSWRAP); + RwRenderStateSet(rwRENDERSTATETEXTUREPERSPECTIVE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + + CSprite::InitSpriteBuffer2D(); + + uint32 flags = DRAW_OPAQUE; + + RwRaster *prevFrame = nil; + + for ( int32 i = 0; i < MAX_PARTICLES; i++ ) + { + tParticleSystemData *psystem = &mod_ParticleSystemManager.m_aParticles[i]; + bool particleBanned = false; + CParticle *particle = psystem->m_pParticles; + + RwRaster **frames = psystem->m_ppRaster; + tParticleType type = psystem->m_Type; + + if ( type == PARTICLE_ENGINE_SMOKE + || type == PARTICLE_ENGINE_SMOKE2 + || type == PARTICLE_ENGINE_STEAM + || type == PARTICLE_CARFLAME_SMOKE + || type == PARTICLE_RUBBER_SMOKE + || type == PARTICLE_BURNINGRUBBER_SMOKE + || type == PARTICLE_EXHAUST_FUMES + || type == PARTICLE_CARCOLLISION_DUST ) + { + particleBanned = true; + } + + if ( particle ) + { + if ( (flags & DRAW_OPAQUE) != (psystem->Flags & DRAW_OPAQUE) + || (flags & DRAW_DARK) != (psystem->Flags & DRAW_DARK) ) + { + CSprite::FlushSpriteBuffer(); + + if ( psystem->Flags & DRAW_OPAQUE ) + { + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + } + else + { + if ( psystem->Flags & DRAW_DARK ) + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + else + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); + + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); + } + + flags = psystem->Flags; + } + + if ( frames != nil ) + { + RwRaster *curFrame = *frames; + if ( curFrame != prevFrame ) + { + CSprite::FlushSpriteBuffer(); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)curFrame); + prevFrame = curFrame; + } + } + } + + while ( particle != nil ) + { + bool canDraw = true; + + if ( particle->m_nAlpha == 0 ) + canDraw = false; + + if ( canDraw && psystem->m_nFinalAnimationFrame != 0 && frames != nil ) + { + RwRaster *curFrame = frames[particle->m_nCurrentFrame]; + if ( prevFrame != curFrame ) + { + CSprite::FlushSpriteBuffer(); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)curFrame); + prevFrame = curFrame; + } + } + + if ( canDraw && psystem->Flags & DRAWTOP2D ) + { + float screenZ; +#ifdef FIX_BUGS + bool zIsZero = true; + if ( particle->m_vecPosition.z != 0.0f ) { +#endif + screenZ = (particle->m_vecPosition.z - CDraw::GetNearClipZ()) + * (CSprite::GetFarScreenZ() - CSprite::GetNearScreenZ()) + * CDraw::GetFarClipZ() + / ( (CDraw::GetFarClipZ() - CDraw::GetNearClipZ()) * particle->m_vecPosition.z ) + + CSprite::GetNearScreenZ(); +#ifdef FIX_BUGS + zIsZero = false; + } +#endif + + float stretchTexW; + float stretchTexH; + + if ( i == PARTICLE_RAINDROP || i == PARTICLE_RAINDROP_SMALL || i == PARTICLE_RAINDROP_2D ) + { + stretchTexW = CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.x * (float)particle->m_nCurrentFrame + 63.0f; + stretchTexH = CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.y * (float)particle->m_nCurrentFrame + 63.0f; + } + else + { + stretchTexW = CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.x + 63.0f; + stretchTexH = CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.y + 63.0f; + } + +#ifdef FIX_BUGS + if (!zIsZero) { +#endif + + if ( i == PARTICLE_WATERDROP ) + { + int32 timeLeft = (particle->m_nTimeWhenWillBeDestroyed - CTimer::GetTimeInMilliseconds()) / particle->m_nTimeWhenWillBeDestroyed; + + stretchTexH += (1.0f - (float)timeLeft ) * psystem->m_vecTextureStretch.y; + + RwRect rect; + + rect.x = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); + rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH)); + rect.w = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); + rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH)); + + FxType fxtype; + + if ( particle->m_nCurrentFrame != 0 ) + fxtype = FXTYPE_WATER2; + else + fxtype = FXTYPE_WATER1; + + CMBlur::AddRenderFx(Scene.camera, &rect, screenZ, fxtype); + + canDraw = false; + } + + if ( i == PARTICLE_BLOODDROP ) + { + int32 timeLeft = (particle->m_nTimeWhenWillBeDestroyed - CTimer::GetTimeInMilliseconds()) / particle->m_nTimeWhenWillBeDestroyed; + + stretchTexH += (1.0f + (float)timeLeft) * psystem->m_vecTextureStretch.y; + stretchTexW += (1.0f - (float)timeLeft) * psystem->m_vecTextureStretch.x; + + RwRect rect; + + rect.x = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); + rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH)); + rect.w = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); + rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH)); + + FxType fxtype; + + if ( particle->m_nCurrentFrame ) + fxtype = FXTYPE_BLOOD2; + else + fxtype = FXTYPE_BLOOD1; + + CMBlur::AddRenderFx(Scene.camera, &rect, screenZ, fxtype); + + canDraw = false; + } + + if ( i == PARTICLE_HEATHAZE_IN_DIST ) + { + RwRect rect; + + rect.x = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); + rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH * 0.15f)); + rect.w = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * stretchTexW)); + rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * stretchTexH * 0.15f)); + + CMBlur::AddRenderFx(Scene.camera, &rect, screenZ, FXTYPE_HEATHAZE); + + canDraw = false; + } + + if ( i == PARTICLE_HEATHAZE ) + { + RwRect rect; + + switch ( TheCamera.GetLookDirection() ) + { + case LOOKING_LEFT: + rect.x = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x * 2.0f)); + rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); + rect.w = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x)); + rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); + + break; + + case LOOKING_RIGHT: + rect.x = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x)); + rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); + rect.w = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x * 4.0f)); + rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); + + break; + + default: + rect.x = int32(particle->m_vecPosition.x - SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x)); + rect.y = int32(particle->m_vecPosition.y - SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); + rect.w = int32(particle->m_vecPosition.x + SCREEN_STRETCH_X(particle->m_fSize * psystem->m_vecTextureStretch.x)); + rect.h = int32(particle->m_vecPosition.y + SCREEN_STRETCH_Y(particle->m_fSize * psystem->m_vecTextureStretch.y)); + + break; + } + + CMBlur::AddRenderFx(Scene.camera, &rect, screenZ, FXTYPE_HEATHAZE); + + canDraw = false; + } +#ifdef FIX_BUGS + } + if ( !(zIsZero && (i == PARTICLE_WATERDROP || i == PARTICLE_BLOODDROP || i == PARTICLE_HEATHAZE_IN_DIST || i == PARTICLE_HEATHAZE) ) ) +#endif + if ( canDraw ) + { + if ( particle->m_nRotation != 0 ) + { + CSprite::RenderBufferedOneXLUSprite2D_Rotate_Dimension( + particle->m_vecPosition.x, + particle->m_vecPosition.y, + particle->m_fSize * stretchTexW, + particle->m_fSize * stretchTexH, + particle->m_Color, + particle->m_nColorIntensity, + DEGTORAD((float)particle->m_nRotation), + particle->m_nAlpha); + } + else + { + CSprite::RenderBufferedOneXLUSprite2D( + particle->m_vecPosition.x, + particle->m_vecPosition.y, + particle->m_fSize * stretchTexW, + particle->m_fSize * stretchTexH, + particle->m_Color, + particle->m_nColorIntensity, + particle->m_nAlpha); + } + } + + canDraw = false; + } + + if ( canDraw ) + { + CVector coors; + float w; + float h; + + if ( CSprite::CalcScreenCoors(particle->m_vecPosition, &coors, &w, &h, true) ) + { + + if ( i == PARTICLE_ENGINE_STEAM + || i == PARTICLE_ENGINE_SMOKE + || i == PARTICLE_ENGINE_SMOKE2 + || i == PARTICLE_CARFLAME_SMOKE + || i == PARTICLE_CARCOLLISION_DUST + || i == PARTICLE_EXHAUST_FUMES + || i == PARTICLE_RUBBER_SMOKE + || i == PARTICLE_BURNINGRUBBER_SMOKE ) + { + switch ( TheCamera.GetLookDirection() ) + { + case LOOKING_LEFT: + case LOOKING_RIGHT: + w += CGeneral::GetRandomNumberInRange(1.0f, 7.5f) * psystem->m_vecTextureStretch.x; + h += CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.y; + break; + + default: + w += CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.x; + h += CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.y; + break; + } + } + else if ( i == PARTICLE_WATER_HYDRANT ) + { + int32 timeLeft = (particle->m_nTimeWhenWillBeDestroyed - CTimer::GetTimeInMilliseconds()) / particle->m_nTimeWhenWillBeDestroyed; + + w += (1.0f - (float)timeLeft) * psystem->m_vecTextureStretch.x; + h += (1.0f - (float)timeLeft) * psystem->m_vecTextureStretch.y; + } + else if ( i == PARTICLE_FLYERS ) + { + w += psystem->m_vecTextureStretch.x; + h += psystem->m_vecTextureStretch.y; + + w = Max(w, 12.0f); + h = Max(h, 12.0f); + } + else + { + w += CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.x; + h += CGeneral::GetRandomNumberInRange(0.1f, 1.0f) * psystem->m_vecTextureStretch.y; + } + + if ( i == PARTICLE_WATER_HYDRANT + || (!particleBanned || SCREEN_WIDTH * fParticleScaleLimit >= w) + && SCREEN_HEIGHT * fParticleScaleLimit >= h ) + { + if ( i == PARTICLE_WATER_HYDRANT ) + { + RwRect rect; + + if ( w > 0.0f ) + { + rect.x = int32(coors.x - SCREEN_STRETCH_X(particle->m_fSize * w)); + rect.w = int32(coors.x + SCREEN_STRETCH_X(particle->m_fSize * w)); + } + else + { + rect.w = int32(coors.x - SCREEN_STRETCH_X(particle->m_fSize * w)); + rect.x = int32(coors.x + SCREEN_STRETCH_X(particle->m_fSize * w)); + } + + if ( h > 0.0f ) + { + rect.y = int32(coors.y - SCREEN_STRETCH_Y(particle->m_fSize * h)); + rect.h = int32(coors.y + SCREEN_STRETCH_Y(particle->m_fSize * h)); + } + else + { + rect.h = int32(coors.y - SCREEN_STRETCH_Y(particle->m_fSize * h)); + rect.y = int32(coors.y + SCREEN_STRETCH_Y(particle->m_fSize * h)); + } + + float screenZ = (coors.z - CDraw::GetNearClipZ()) + * (CSprite::GetFarScreenZ() - CSprite::GetNearScreenZ()) * CDraw::GetFarClipZ() + / ( (CDraw::GetFarClipZ() - CDraw::GetNearClipZ()) * coors.z ) + CSprite::GetNearScreenZ(); + + CMBlur::AddRenderFx(Scene.camera, &rect, screenZ, FXTYPE_SPLASH1); + } + else + { + if ( particle->m_nRotation != 0 && i != PARTICLE_BEASTIE ) + { + CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension(coors.x, coors.y, coors.z, + particle->m_fSize * w, particle->m_fSize * h, + particle->m_Color.red, + particle->m_Color.green, + particle->m_Color.blue, + particle->m_nColorIntensity, + 1.0f / coors.z, + DEGTORAD((float)particle->m_nRotation), + particle->m_nAlpha); + } + else if ( psystem->Flags & SCREEN_TRAIL ) + { + float fRotation; + float fTrailLength; + + if ( particle->m_fZGround == 0.0f ) + { + fTrailLength = 0.0f; + fRotation = 0.0f; + } + else + { + CVector2D vecDist + ( + coors.x - particle->m_fZGround, + coors.y - particle->m_fExpansionRate + ); + + float fDist = vecDist.Magnitude(); + + fTrailLength = fDist; + + float fRot = Asin(vecDist.x / fDist); + + fRotation = fRot; + + if ( vecDist.y < 0.0f ) + fRotation = -1.0f * fRot + DEGTORAD(180.0f); + + float fSpeed = particle->m_vecVelocity.Magnitude(); + + float fNewTrailLength = fSpeed * CTimer::GetTimeStep() * w * 2.0f; + + if ( fDist > fNewTrailLength ) + fTrailLength = fNewTrailLength; + } + + CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension(coors.x, coors.y, coors.z, + particle->m_fSize * w, + particle->m_fSize * h + fTrailLength * psystem->m_fTrailLengthMultiplier, + particle->m_Color.red, + particle->m_Color.green, + particle->m_Color.blue, + particle->m_nColorIntensity, + 1.0f / coors.z, + fRotation, + particle->m_nAlpha); + + particle->m_fZGround = coors.x; // WTF ? + particle->m_fExpansionRate = coors.y; // WTF ? + } + else if ( psystem->Flags & SPEED_TRAIL ) + { + CVector vecPrevPos = particle->m_vecPosition - particle->m_vecVelocity; + float fRotation; + float fTrailLength; + CVector vecScreenPosition; + + if ( CSprite::CalcScreenCoors(vecPrevPos, &vecScreenPosition, &fTrailLength, &fRotation, true) ) + { + CVector2D vecDist + ( + coors.x - vecScreenPosition.x, + coors.y - vecScreenPosition.y + ); + + float fDist = vecDist.Magnitude(); + + fTrailLength = fDist; + + float fRot = Asin(vecDist.x / fDist); + + fRotation = fRot; + + if ( vecDist.y < 0.0f ) + fRotation = -1.0f * fRot + DEGTORAD(180.0f); + } + else + { + fRotation = 0.0f; + fTrailLength = 0.0f; + } + + CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension(coors.x, coors.y, coors.z, + particle->m_fSize * w, + particle->m_fSize * h + fTrailLength * psystem->m_fTrailLengthMultiplier, + particle->m_Color.red, + particle->m_Color.green, + particle->m_Color.blue, + particle->m_nColorIntensity, + 1.0f / coors.z, + fRotation, + particle->m_nAlpha); + } + else if ( psystem->Flags & VERT_TRAIL ) + { + float fTrailLength = fabsf(particle->m_vecVelocity.z * 10.0f); + + CSprite::RenderBufferedOneXLUSprite(coors.x, coors.y, coors.z, + particle->m_fSize * w, + (particle->m_fSize + fTrailLength * psystem->m_fTrailLengthMultiplier) * h, + particle->m_Color.red, + particle->m_Color.green, + particle->m_Color.blue, + particle->m_nColorIntensity, + 1.0f / coors.z, + particle->m_nAlpha); + } + else if ( i == PARTICLE_RAINDROP_SMALL ) + { + CSprite::RenderBufferedOneXLUSprite(coors.x, coors.y, coors.z, + particle->m_fSize * w * 0.05f, + particle->m_fSize * h, + particle->m_Color.red, + particle->m_Color.green, + particle->m_Color.blue, + particle->m_nColorIntensity, + 1.0f / coors.z, + particle->m_nAlpha); + } + /*else if ( i == PARTICLE_BOAT_WAKE )*/ + else + { + CSprite::RenderBufferedOneXLUSprite(coors.x, coors.y, coors.z, + particle->m_fSize * w, + particle->m_fSize * h, + particle->m_Color.red, + particle->m_Color.green, + particle->m_Color.blue, + particle->m_nColorIntensity, + 1.0f / coors.z, + particle->m_nAlpha); + } + } + } + } + } + + particle = particle->m_pNext; + } + + CSprite::FlushSpriteBuffer(); + + } + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + + POP_RENDERGROUP(); +} + +void CParticle::RemovePSystem(tParticleType type) +{ + tParticleSystemData *psystemdata = &mod_ParticleSystemManager.m_aParticles[type]; + + for ( CParticle *particle = psystemdata->m_pParticles; particle; particle = psystemdata->m_pParticles ) + RemoveParticle(particle, nil, psystemdata); +} + +void CParticle::RemoveParticle(CParticle *pParticle, CParticle *pPrevParticle, tParticleSystemData *pPSystemData) +{ + if ( pPSystemData->m_Type == PARTICLE_WATERDROP ) + --numWaterDropOnScreen; + + if ( pPrevParticle ) + pPrevParticle->m_pNext = pParticle->m_pNext; + else + pPSystemData->m_pParticles = pParticle->m_pNext; + + pParticle->m_pNext = m_pUnusedListHead; + m_pUnusedListHead = pParticle; +} + +void CParticle::AddJetExplosion(CVector const &vecPos, float fPower, float fSize) +{ + CRGBA color(240, 240, 240, 255); + + if ( fPower < 1.0f ) + fPower = 1.0f; + + CVector vecRandOffset + ( + CGeneral::GetRandomNumberInRange(-0.4f, 0.4f), + CGeneral::GetRandomNumberInRange(-0.4f, 0.4f), + CGeneral::GetRandomNumberInRange(0.1f, 0.3f) + ); + + vecRandOffset *= 2.0f; + + CVector vecStepPos = vecPos; + + for ( int32 i = 0; i < int32(fPower * 4.0f); i++ ) + { + AddParticle(PARTICLE_EXPLOSION_MFAST, + vecStepPos, + CVector + ( + CGeneral::GetRandomNumberInRange(-0.02f, 0.02f), + CGeneral::GetRandomNumberInRange(-0.02f, 0.02f), + CGeneral::GetRandomNumberInRange(-0.02f, 0.0f) + ), + nil, + fSize, color, 0, 0, 0, 0); + + AddParticle(PARTICLE_EXPLOSION_MFAST, + vecStepPos, + CVector + ( + CGeneral::GetRandomNumberInRange(-0.04f, 0.04f), + CGeneral::GetRandomNumberInRange(-0.04f, 0.04f), + CGeneral::GetRandomNumberInRange(0.0f, 0.07f) + ), + nil, + fSize, color, 0, 0, 0, 0); + + AddParticle(PARTICLE_EXPLOSION_MFAST, + vecStepPos, + CVector + ( + CGeneral::GetRandomNumberInRange(-0.04f, 0.04f), + CGeneral::GetRandomNumberInRange(-0.04f, 0.04f), + CGeneral::GetRandomNumberInRange(0.0f, 0.07f) + ), + nil, + fSize, color, 0, 0, 0, 0); + + vecStepPos += vecRandOffset; + } +} + +void CParticle::AddYardieDoorSmoke(CVector const &vecPos, CMatrix const &matMatrix) +{ + CRGBA color(0, 0, 0, 0); + + CMatrix invMat(Invert(matMatrix)); + + CVector vecBasePos = matMatrix * (invMat * vecPos + CVector(0.0f, -1.0f, 0.5f)); + + for ( int32 i = 0; i < 5; i++ ) + { + CVector pos = vecBasePos; + + pos.x += CGeneral::GetRandomNumberInRange(-0.5f, 0.5f); + pos.y += CGeneral::GetRandomNumberInRange(-0.5f, 0.5f); + + AddParticle(PARTICLE_CARCOLLISION_DUST, + pos, + CVector(0.0f, 0.0f, 0.0f), + nil, + 0.3f, color, 0, 0, 0, 0); + } +} + +void CParticle::CalWindDir(CVector *vecDirIn, CVector *vecDirOut) +{ + vecDirOut->x = (Cos(128) * vecDirIn->x) + (Sin(128) * vecDirIn->y); + + vecDirOut->x = (Cos(128) * vecDirIn->x) + (Sin(128) * vecDirIn->y) * CWeather::Wind; + vecDirOut->y = (Sin(128) * vecDirIn->x) - (Cos(128) * vecDirIn->y) * CWeather::Wind; +} + +void CParticle::HandleShipsAtHorizonStuff() +{ + tParticleSystemData *psystemdata = &mod_ParticleSystemManager.m_aParticles[PARTICLE_SHIP_SIDE]; + + for ( CParticle *particle = psystemdata->m_pParticles; particle; particle = particle->m_pNext ) + { + if ( CTimer::GetTimeInMilliseconds() > particle->m_nTimeWhenWillBeDestroyed - 32000 + && CTimer::GetTimeInMilliseconds() < particle->m_nTimeWhenWillBeDestroyed - 22000 ) + { + particle->m_nAlpha = Min(particle->m_nAlpha + 1, 96); + } + if ( CTimer::GetTimeInMilliseconds() > particle->m_nTimeWhenWillBeDestroyed - 10000 ) + particle->m_nFadeAlphaTimer = 1; + } +} + +void CParticle::HandleShootableBirdsStuff(CEntity *entity, CVector const&camPos) +{ + float fHeadingRad = entity->GetForward().Heading(); + float fHeading = RADTODEG(fHeadingRad); + float fBirdAngle = ::Cos(DEGTORAD(1.5f)); + + tParticleSystemData *psystem = &mod_ParticleSystemManager.m_aParticles[PARTICLE_BIRD_FRONT]; + CParticle *particle = psystem->m_pParticles; + CParticle *prevParticle = nil; + bool bRemoveParticle; + + for ( ; particle != nil; _Next(particle, prevParticle, psystem, bRemoveParticle) ) + { + bRemoveParticle = false; + + CVector2D vecPos(particle->m_vecPosition.x, particle->m_vecPosition.y); + CVector2D vecCamPos(camPos.x, camPos.y); + + CVector2D vecDist = vecPos - vecCamPos; + vecDist.Normalise(); + + float fHead = DEGTORAD(fHeading); + + CVector2D vecDir(-::Sin(fHead), ::Cos(fHead)); + vecDir.Normalise(); + + float fDot = DotProduct2D(vecDir, vecDist); + + if ( fDot > 0.0f && fDot > fBirdAngle ) + { + if ( (camPos - particle->m_vecPosition).MagnitudeSqr() < 40000.0f ) + { + CStats::SeagullsKilled++; + + bRemoveParticle = true; + + for ( int32 i = 0; i < 8; i++ ) + { + CParticle *pBirdDerbis = AddParticle(PARTICLE_BIRD_DEBRIS, + particle->m_vecPosition, + CVector + ( + CGeneral::GetRandomNumberInRange(-3.0f, 3.0f), + CGeneral::GetRandomNumberInRange(-3.0f, 3.0f), + CGeneral::GetRandomNumberInRange(-3.0f, 3.0f) + ), + nil, + 0.3f, + particle->m_Color, + CGeneral::GetRandomNumberInRange(20, 40), + 0, + CGeneral::GetRandomNumber() & 3, + 200); + if ( pBirdDerbis ) + pBirdDerbis->m_nAlpha = particle->m_nAlpha; + } + } + } + } + +} + +void +CEntity::AddSteamsFromGround(CVector *unused) +{ + int i, n; + C2dEffect *effect; + CVector pos; + + n = CModelInfo::GetModelInfo(GetModelIndex())->GetNum2dEffects(); + for(i = 0; i < n; i++){ + effect = CModelInfo::GetModelInfo(GetModelIndex())->Get2dEffect(i); + if(effect->type != EFFECT_PARTICLE) + continue; + + pos = GetMatrix() * effect->pos; + switch(effect->particle.particleType){ + case 0: + CParticleObject::AddObject(POBJECT_PAVEMENT_STEAM, pos, effect->particle.dir, effect->particle.scale, false); + break; + case 1: + CParticleObject::AddObject(POBJECT_WALL_STEAM, pos, effect->particle.dir, effect->particle.scale, false); + break; + case 2: + CParticleObject::AddObject(POBJECT_DRY_ICE, pos, effect->particle.scale, false); + break; + case 3: + CParticleObject::AddObject(POBJECT_SMALL_FIRE, pos, effect->particle.dir, effect->particle.scale, false); + break; + case 4: + CParticleObject::AddObject(POBJECT_DARK_SMOKE, pos, effect->particle.dir, effect->particle.scale, false); + break; + case 5: + CParticleObject::AddObject(POBJECT_WATER_FOUNTAIN_VERT, pos, effect->particle.dir, effect->particle.scale, false); + break; + case 6: + CParticleObject::AddObject(POBJECT_WATER_FOUNTAIN_HORIZ, pos, effect->particle.dir, effect->particle.scale, false); + break; + } + } +} diff --git a/src/renderer/Particle.h b/src/renderer/Particle.h new file mode 100644 index 00000000..5542dc02 --- /dev/null +++ b/src/renderer/Particle.h @@ -0,0 +1,108 @@ +#pragma once +#include "ParticleMgr.h" + + +class CEntity; + +class CParticle +{ +public: + enum + { + RAND_TABLE_SIZE = 20, + SIN_COS_TABLE_SIZE = 1024 + }; + + CVector m_vecPosition; + CVector m_vecVelocity; + uint32 m_nTimeWhenWillBeDestroyed; + uint32 m_nTimeWhenColorWillBeChanged; + float m_fZGround; + CVector m_vecParticleMovementOffset; + int16 m_nCurrentZRotation; + uint16 m_nZRotationTimer; + float m_fCurrentZRadius; + uint16 m_nZRadiusTimer; + uint8 m_nColorIntensity; + uint8 m_nAlpha; + float m_fSize; + float m_fExpansionRate; + int16 m_nFadeToBlackTimer; + int16 m_nFadeAlphaTimer; + int16 m_nAnimationSpeedTimer; + int16 m_nRotationStep; + int16 m_nRotation; + uint8 m_nCurrentFrame; + RwRGBA m_Color; + CParticle *m_pNext; + + CParticle() + { + ; + } + + ~CParticle() + { + ; + } + + static float ms_afRandTable[RAND_TABLE_SIZE]; + static CParticle *m_pUnusedListHead; + + static float m_SinTable[SIN_COS_TABLE_SIZE]; + static float m_CosTable[SIN_COS_TABLE_SIZE]; + + static float Sin(int32 value) { return m_SinTable[value]; } + static float Cos(int32 value) { return m_CosTable[value]; } + + static void ReloadConfig(); + static void Initialise(); + static void Shutdown(); + + static void AddParticlesAlongLine(tParticleType type, CVector const &vecStart, CVector const &vecEnd, CVector const &vecDir, float fPower, CEntity *pEntity = nil, float fSize = 0.0f, int32 nRotationSpeed = 0, int32 nRotation = 0, int32 nCurFrame = 0, int32 nLifeSpan = 0); + static void AddParticlesAlongLine(tParticleType type, CVector const &vecStart, CVector const &vecEnd, CVector const &vecDir, float fPower, CEntity *pEntity, float fSize, RwRGBA const&color, int32 nRotationSpeed = 0, int32 nRotation = 0, int32 nCurFrame = 0, int32 nLifeSpan = 0); + + static CParticle *AddParticle(tParticleType type, CVector const &vecPos, CVector const &vecDir, CEntity *pEntity = nil, float fSize = 0.0f, int32 nRotationSpeed = 0, int32 nRotation = 0, int32 nCurFrame = 0, int32 nLifeSpan = 0); + static CParticle *AddParticle(tParticleType type, CVector const &vecPos, CVector const &vecDir, CEntity *pEntity, float fSize, RwRGBA const &color, int32 nRotationSpeed = 0, int32 nRotation = 0, int32 nCurFrame = 0, int32 nLifeSpan = 0); + + static void Update(); + static void Render(); + + static void RemovePSystem(tParticleType type); + static void RemoveParticle(CParticle *pParticle, CParticle *pPrevParticle, tParticleSystemData *pPSystemData); + + static void _Next(CParticle *&pParticle, CParticle *&pPrevParticle, tParticleSystemData *pPSystemData, bool bRemoveParticle) + { + if ( bRemoveParticle ) + { + RemoveParticle(pParticle, pPrevParticle, pPSystemData); + + if ( pPrevParticle ) + pParticle = pPrevParticle->m_pNext; + else + pParticle = pPSystemData->m_pParticles; + } + else + { + pPrevParticle = pParticle; + pParticle = pParticle->m_pNext; + } + } + + static void AddJetExplosion(CVector const &vecPos, float fPower, float fSize); + static void AddYardieDoorSmoke(CVector const &vecPos, CMatrix const &matMatrix); + static void CalWindDir(CVector *vecDirIn, CVector *vecDirOut); + + static void HandleShipsAtHorizonStuff(); + static void HandleShootableBirdsStuff(CEntity *entity, CVector const&camPos); +}; + +extern bool clearWaterDrop; +extern int32 numWaterDropOnScreen; +extern RwRaster *gpCarSplashRaster[]; +extern RwRaster *gpHeatHazeRaster; +extern RwRaster *gpDotRaster; +extern RwRaster *gpRainDripRaster[]; +extern RwRaster *gpRainDripDarkRaster[]; + +VALIDATE_SIZE(CParticle, 0x58); diff --git a/src/renderer/ParticleMgr.cpp b/src/renderer/ParticleMgr.cpp new file mode 100644 index 00000000..f6919435 --- /dev/null +++ b/src/renderer/ParticleMgr.cpp @@ -0,0 +1,255 @@ +#include "common.h" + +#include "main.h" +#include "FileMgr.h" +#include "ParticleMgr.h" + +cParticleSystemMgr mod_ParticleSystemManager; + +const char *ParticleFilename = "PARTICLE.CFG"; + +cParticleSystemMgr::cParticleSystemMgr() +{ + memset(this, 0, sizeof(*this)); +} + +void cParticleSystemMgr::Initialise() +{ + LoadParticleData(); + + for ( int32 i = 0; i < MAX_PARTICLES; i++ ) + m_aParticles[i].m_pParticles = nil; +} + +void cParticleSystemMgr::LoadParticleData() +{ + CFileMgr::SetDir("DATA"); + CFileMgr::LoadFile(ParticleFilename, work_buff, ARRAY_SIZE(work_buff), "r"); + CFileMgr::SetDir(""); + + tParticleSystemData *entry = nil; + int32 type = PARTICLE_FIRST; + + char *lineStart = (char *)work_buff; + char *lineEnd = lineStart + 1; + + char line[500]; + char delims[4]; + + while ( true ) + { + ASSERT(lineStart != nil); + ASSERT(lineEnd != nil); + + while ( *lineEnd != '\n' ) + ++lineEnd; + + int32 lineLength = lineEnd - lineStart; + + ASSERT(lineLength < 500); + + strncpy(line, lineStart, lineLength); + + line[lineLength] = '\0'; + + if ( !strcmp(line, ";the end") ) + break; + + if ( *line != ';' ) + { + int32 param = CFG_PARAM_FIRST; + + strcpy(delims, " \t"); + + char *value = strtok(line, delims); + + ASSERT(value != nil); + + do + { + switch ( param ) + { + case CFG_PARAM_PARTICLE_TYPE_NAME: + ASSERT(type < MAX_PARTICLES); + entry = &m_aParticles[type]; + ASSERT(entry != nil); + entry->m_Type = (tParticleType)type++; + strcpy(entry->m_aName, value); + break; + + case CFG_PARAM_RENDER_COLOURING_R: + entry->m_RenderColouring.red = atoi(value); + break; + + case CFG_PARAM_RENDER_COLOURING_G: + entry->m_RenderColouring.green = atoi(value); + break; + + case CFG_PARAM_RENDER_COLOURING_B: + entry->m_RenderColouring.blue = atoi(value); + break; + + case CFG_PARAM_INITIAL_COLOR_VARIATION: + entry->m_InitialColorVariation = Min(atoi(value), 100); + break; + + case CFG_PARAM_FADE_DESTINATION_COLOR_R: + entry->m_FadeDestinationColor.red = atoi(value); + break; + + case CFG_PARAM_FADE_DESTINATION_COLOR_G: + entry->m_FadeDestinationColor.green = atoi(value); + break; + + case CFG_PARAM_FADE_DESTINATION_COLOR_B: + entry->m_FadeDestinationColor.blue = atoi(value); + break; + + case CFG_PARAM_COLOR_FADE_TIME: + entry->m_ColorFadeTime = atoi(value); + break; + + case CFG_PARAM_DEFAULT_INITIAL_RADIUS: + entry->m_fDefaultInitialRadius = atof(value); + break; + + case CFG_PARAM_EXPANSION_RATE: + entry->m_fExpansionRate = atof(value); + break; + + case CFG_PARAM_INITIAL_INTENSITY: + entry->m_nFadeToBlackInitialIntensity = atoi(value); + break; + + case CFG_PARAM_FADE_TIME: + entry->m_nFadeToBlackTime = atoi(value); + break; + + case CFG_PARAM_FADE_AMOUNT: + entry->m_nFadeToBlackAmount = atoi(value); + break; + + case CFG_PARAM_INITIAL_ALPHA_INTENSITY: + entry->m_nFadeAlphaInitialIntensity = atoi(value); + break; + + case CFG_PARAM_FADE_ALPHA_TIME: + entry->m_nFadeAlphaTime = atoi(value); + break; + + case CFG_PARAM_FADE_ALPHA_AMOUNT: + entry->m_nFadeAlphaAmount = atoi(value); + break; + + case CFG_PARAM_INITIAL_ANGLE: + entry->m_nZRotationInitialAngle = atoi(value); + break; + + case CFG_PARAM_CHANGE_TIME: + entry->m_nZRotationChangeTime = atoi(value); + break; + + case CFG_PARAM_ANGLE_CHANGE_AMOUNT: + entry->m_nZRotationAngleChangeAmount = atoi(value); + break; + + case CFG_PARAM_INITIAL_Z_RADIUS: + entry->m_fInitialZRadius = atof(value); + break; + + case CFG_PARAM_Z_RADIUS_CHANGE_TIME: + entry->m_nZRadiusChangeTime = atoi(value); + break; + + case CFG_PARAM_Z_RADIUS_CHANGE_AMOUNT: + entry->m_fZRadiusChangeAmount = atof(value); + break; + + case CFG_PARAM_ANIMATION_SPEED: + entry->m_nAnimationSpeed = atoi(value); + break; + + case CFG_PARAM_START_ANIMATION_FRAME: + entry->m_nStartAnimationFrame = atoi(value); + break; + + case CFG_PARAM_FINAL_ANIMATION_FRAME: + entry->m_nFinalAnimationFrame = atoi(value); + break; + + case CFG_PARAM_ROTATION_SPEED: + entry->m_nRotationSpeed = atoi(value); + break; + + case CFG_PARAM_GRAVITATIONAL_ACCELERATION: + entry->m_fGravitationalAcceleration = atof(value); + break; + + case CFG_PARAM_FRICTION_DECCELERATION: + entry->m_nFrictionDecceleration = atoi(value); + break; + + case CFG_PARAM_LIFE_SPAN: + entry->m_nLifeSpan = atoi(value); + break; + + case CFG_PARAM_POSITION_RANDOM_ERROR: + entry->m_fPositionRandomError = atof(value); + break; + + case CFG_PARAM_VELOCITY_RANDOM_ERROR: + entry->m_fVelocityRandomError = atof(value); + break; + + case CFG_PARAM_EXPANSION_RATE_ERROR: + entry->m_fExpansionRateError = atof(value); + break; + + case CFG_PARAM_ROTATION_RATE_ERROR: + entry->m_nRotationRateError = atoi(value); + break; + + case CFG_PARAM_LIFE_SPAN_ERROR_SHAPE: + entry->m_nLifeSpanErrorShape = atoi(value); + break; + + case CFG_PARAM_TRAIL_LENGTH_MULTIPLIER: + entry->m_fTrailLengthMultiplier = atof(value); + break; + + case CFG_PARAM_STRETCH_VALUE_X: + entry->m_vecTextureStretch.x = atof(value); + break; + + case CFG_PARAM_STRETCH_VALUE_Y: + entry->m_vecTextureStretch.y = atof(value); + break; + + case CFG_PARAM_WIND_FACTOR: + entry->m_fWindFactor = atof(value); + break; + + case CFG_PARAM_PARTICLE_CREATE_RANGE: + entry->m_fCreateRange = SQR(atof(value)); + break; + + case CFG_PARAM_FLAGS: + entry->Flags = atoi(value); + break; + } + + value = strtok(nil, delims); + + param++; + + if ( param > CFG_PARAM_LAST ) + param = CFG_PARAM_FIRST; + + } while ( value != nil ); + } + + lineEnd++; + lineStart = lineEnd; + lineEnd++; + } +} diff --git a/src/renderer/ParticleMgr.h b/src/renderer/ParticleMgr.h new file mode 100644 index 00000000..f4afc018 --- /dev/null +++ b/src/renderer/ParticleMgr.h @@ -0,0 +1,138 @@ +#pragma once + +#include "ParticleType.h" + +class CParticle; + +enum +{ + ZCHECK_FIRST = BIT(0), + ZCHECK_STEP = BIT(1), + DRAW_OPAQUE = BIT(2), + SCREEN_TRAIL = BIT(3), + SPEED_TRAIL = BIT(4), + RAND_VERT_V = BIT(5), + CYCLE_ANIM = BIT(6), + DRAW_DARK = BIT(7), + VERT_TRAIL = BIT(8), + _FLAG9 = BIT(9), // unused + DRAWTOP2D = BIT(10), + CLIPOUT2D = BIT(11), + ZCHECK_BUMP = BIT(12), + ZCHECK_BUMP_FIRST = BIT(13) +}; + + +struct tParticleSystemData +{ + tParticleType m_Type; + char m_aName[20]; + float m_fCreateRange; + float m_fDefaultInitialRadius; + float m_fExpansionRate; + uint16 m_nZRotationInitialAngle; + int16 m_nZRotationAngleChangeAmount; + uint16 m_nZRotationChangeTime; + uint16 m_nZRadiusChangeTime; + float m_fInitialZRadius; + float m_fZRadiusChangeAmount; + int16 m_nFadeToBlackTime; + uint8 m_nFadeToBlackInitialIntensity; + int16 m_nFadeToBlackAmount; + uint8 m_nFadeAlphaInitialIntensity; + int16 m_nFadeAlphaTime; + int16 m_nFadeAlphaAmount; + uint8 m_nStartAnimationFrame; + uint8 m_nFinalAnimationFrame; + uint16 m_nAnimationSpeed; + uint16 m_nRotationSpeed; + float m_fGravitationalAcceleration; + int32 m_nFrictionDecceleration; + int32 m_nLifeSpan; + float m_fPositionRandomError; + float m_fVelocityRandomError; + float m_fExpansionRateError; + int32 m_nRotationRateError; + uint32 m_nLifeSpanErrorShape; + float m_fTrailLengthMultiplier; + uint32 Flags; + CRGBA m_RenderColouring; + uint8 m_InitialColorVariation; + CRGBA m_FadeDestinationColor; + uint32 m_ColorFadeTime; + + CVector2D m_vecTextureStretch; + float m_fWindFactor; + + RwRaster **m_ppRaster; + CParticle *m_pParticles; +}; + +VALIDATE_SIZE(tParticleSystemData, 0x94); + +class cParticleSystemMgr +{ + enum + { + CFG_PARAM_PARTICLE_TYPE_NAME = 0, + CFG_PARAM_RENDER_COLOURING_R, + CFG_PARAM_RENDER_COLOURING_G, + CFG_PARAM_RENDER_COLOURING_B, + CFG_PARAM_INITIAL_COLOR_VARIATION, + CFG_PARAM_FADE_DESTINATION_COLOR_R, + CFG_PARAM_FADE_DESTINATION_COLOR_G, + CFG_PARAM_FADE_DESTINATION_COLOR_B, + CFG_PARAM_COLOR_FADE_TIME, + CFG_PARAM_DEFAULT_INITIAL_RADIUS, + CFG_PARAM_EXPANSION_RATE, + CFG_PARAM_INITIAL_INTENSITY, + CFG_PARAM_FADE_TIME, + CFG_PARAM_FADE_AMOUNT, + CFG_PARAM_INITIAL_ALPHA_INTENSITY, + CFG_PARAM_FADE_ALPHA_TIME, + CFG_PARAM_FADE_ALPHA_AMOUNT, + CFG_PARAM_INITIAL_ANGLE, + CFG_PARAM_CHANGE_TIME, + CFG_PARAM_ANGLE_CHANGE_AMOUNT, + CFG_PARAM_INITIAL_Z_RADIUS, + CFG_PARAM_Z_RADIUS_CHANGE_TIME, + CFG_PARAM_Z_RADIUS_CHANGE_AMOUNT, + CFG_PARAM_ANIMATION_SPEED, + CFG_PARAM_START_ANIMATION_FRAME, + CFG_PARAM_FINAL_ANIMATION_FRAME, + CFG_PARAM_ROTATION_SPEED, + CFG_PARAM_GRAVITATIONAL_ACCELERATION, + CFG_PARAM_FRICTION_DECCELERATION, + CFG_PARAM_LIFE_SPAN, + CFG_PARAM_POSITION_RANDOM_ERROR, + CFG_PARAM_VELOCITY_RANDOM_ERROR, + CFG_PARAM_EXPANSION_RATE_ERROR, + CFG_PARAM_ROTATION_RATE_ERROR, + CFG_PARAM_LIFE_SPAN_ERROR_SHAPE, + CFG_PARAM_TRAIL_LENGTH_MULTIPLIER, + + CFG_PARAM_STRETCH_VALUE_X, + CFG_PARAM_STRETCH_VALUE_Y, + CFG_PARAM_WIND_FACTOR, + + CFG_PARAM_PARTICLE_CREATE_RANGE, + CFG_PARAM_FLAGS, + + MAX_CFG_PARAMS, + CFG_PARAM_FIRST = CFG_PARAM_PARTICLE_TYPE_NAME, + CFG_PARAM_LAST = CFG_PARAM_FLAGS + }; + +public: + tParticleSystemData m_aParticles[MAX_PARTICLES]; + + cParticleSystemMgr(); + + void Initialise(); + void LoadParticleData(); + void RangeCheck(tParticleSystemData *pData) { } +}; + +VALIDATE_SIZE(cParticleSystemMgr, 0x2FFC); + +extern cParticleSystemMgr mod_ParticleSystemManager; diff --git a/src/renderer/ParticleType.h b/src/renderer/ParticleType.h new file mode 100644 index 00000000..9578083d --- /dev/null +++ b/src/renderer/ParticleType.h @@ -0,0 +1,92 @@ +#pragma once + +enum tParticleType +{ + PARTICLE_SPARK = 0, + PARTICLE_SPARK_SMALL, + PARTICLE_WATER_SPARK, + PARTICLE_WHEEL_DIRT, + PARTICLE_SAND, + PARTICLE_WHEEL_WATER, + PARTICLE_BLOOD, + PARTICLE_BLOOD_SMALL, + PARTICLE_BLOOD_SPURT, + PARTICLE_DEBRIS, + PARTICLE_DEBRIS2, + PARTICLE_FLYERS, + PARTICLE_WATER, + PARTICLE_FLAME, + PARTICLE_FIREBALL, + PARTICLE_GUNFLASH, + PARTICLE_GUNFLASH_NOANIM, + PARTICLE_GUNSMOKE, + PARTICLE_GUNSMOKE2, + PARTICLE_CIGARETTE_SMOKE, + PARTICLE_SMOKE, + PARTICLE_SMOKE_SLOWMOTION, + PARTICLE_DRY_ICE, + PARTICLE_TEARGAS, + PARTICLE_GARAGEPAINT_SPRAY, + PARTICLE_SHARD, + PARTICLE_SPLASH, + PARTICLE_CARFLAME, + PARTICLE_STEAM, + PARTICLE_STEAM2, + PARTICLE_STEAM_NY, + PARTICLE_STEAM_NY_SLOWMOTION, + PARTICLE_GROUND_STEAM, + PARTICLE_ENGINE_STEAM, + PARTICLE_RAINDROP, + PARTICLE_RAINDROP_SMALL, + PARTICLE_RAIN_SPLASH, + PARTICLE_RAIN_SPLASH_BIGGROW, + PARTICLE_RAIN_SPLASHUP, + PARTICLE_WATERSPRAY, + PARTICLE_WATERDROP, + PARTICLE_BLOODDROP, + PARTICLE_EXPLOSION_MEDIUM, + PARTICLE_EXPLOSION_LARGE, + PARTICLE_EXPLOSION_MFAST, + PARTICLE_EXPLOSION_LFAST, + PARTICLE_CAR_SPLASH, + PARTICLE_BOAT_SPLASH, + PARTICLE_BOAT_THRUSTJET, + PARTICLE_WATER_HYDRANT, + PARTICLE_WATER_CANNON, + PARTICLE_EXTINGUISH_STEAM, + PARTICLE_PED_SPLASH, + PARTICLE_PEDFOOT_DUST, + PARTICLE_CAR_DUST, + PARTICLE_HELI_DUST, + PARTICLE_HELI_ATTACK, + PARTICLE_ENGINE_SMOKE, + PARTICLE_ENGINE_SMOKE2, + PARTICLE_CARFLAME_SMOKE, + PARTICLE_FIREBALL_SMOKE, + PARTICLE_PAINT_SMOKE, + PARTICLE_TREE_LEAVES, + PARTICLE_CARCOLLISION_DUST, + PARTICLE_CAR_DEBRIS, + PARTICLE_BIRD_DEBRIS, + PARTICLE_HELI_DEBRIS, + PARTICLE_EXHAUST_FUMES, + PARTICLE_RUBBER_SMOKE, + PARTICLE_BURNINGRUBBER_SMOKE, + PARTICLE_BULLETHIT_SMOKE, + PARTICLE_GUNSHELL_FIRST, + PARTICLE_GUNSHELL, + PARTICLE_GUNSHELL_BUMP1, + PARTICLE_GUNSHELL_BUMP2, + PARTICLE_ROCKET_SMOKE, + PARTICLE_TEST, + PARTICLE_BIRD_FRONT, + PARTICLE_SHIP_SIDE, + PARTICLE_BEASTIE, + PARTICLE_RAINDROP_2D, + PARTICLE_HEATHAZE, + PARTICLE_HEATHAZE_IN_DIST, + + MAX_PARTICLES, + PARTICLE_FIRST = PARTICLE_SPARK, + PARTICLE_LAST = PARTICLE_HEATHAZE_IN_DIST +}; \ No newline at end of file diff --git a/src/renderer/PlayerSkin.cpp b/src/renderer/PlayerSkin.cpp new file mode 100644 index 00000000..ee944ca7 --- /dev/null +++ b/src/renderer/PlayerSkin.cpp @@ -0,0 +1,164 @@ +#include "common.h" + +#include "main.h" +#include "PlayerSkin.h" +#include "TxdStore.h" +#include "rtbmp.h" +#include "ClumpModelInfo.h" +#include "VisibilityPlugins.h" +#include "World.h" +#include "PlayerInfo.h" +#include "CdStream.h" +#include "FileMgr.h" +#include "Directory.h" +#include "RwHelper.h" +#include "Timer.h" +#include "Lights.h" +#include "MemoryMgr.h" + +RpClump *gpPlayerClump; +float gOldFov; + +int CPlayerSkin::m_txdSlot; + +void +FindPlayerDff(uint32 &offset, uint32 &size) +{ + int file; + CDirectory::DirectoryInfo info; + + file = CFileMgr::OpenFile("models\\gta3.dir", "rb"); + + do { + if (!CFileMgr::Read(file, (char*)&info, sizeof(CDirectory::DirectoryInfo))) + return; + } while (strcasecmp("player.dff", info.name) != 0); + + offset = info.offset; + size = info.size; +} + +void +LoadPlayerDff(void) +{ + RwStream *stream; + RwMemory mem; + uint32 offset, size; + uint8 *buffer; + bool streamWasAdded = false; + + if (CdStreamGetNumImages() == 0) { + CdStreamAddImage("models\\gta3.img"); + streamWasAdded = true; + } + + FindPlayerDff(offset, size); + buffer = (uint8*)RwMallocAlign(size << 11, 2048); + CdStreamRead(0, buffer, offset, size); + CdStreamSync(0); + + mem.start = buffer; + mem.length = size << 11; + stream = RwStreamOpen(rwSTREAMMEMORY, rwSTREAMREAD, &mem); + + if (RwStreamFindChunk(stream, rwID_CLUMP, nil, nil)) + gpPlayerClump = RpClumpStreamRead(stream); + + RwStreamClose(stream, &mem); + RwFreeAlign(buffer); + + if (streamWasAdded) + CdStreamRemoveImages(); +} + +void +CPlayerSkin::Initialise(void) +{ + // empty on PS2 + m_txdSlot = CTxdStore::AddTxdSlot("skin"); + CTxdStore::Create(m_txdSlot); + CTxdStore::AddRef(m_txdSlot); +} + +void +CPlayerSkin::Shutdown(void) +{ + // empty on PS2 + CTxdStore::RemoveTxdSlot(m_txdSlot); +} + +RwTexture * +CPlayerSkin::GetSkinTexture(const char *texName) +{ + RwTexture *tex; + RwRaster *raster; + int32 width, height, depth, format; + + CTxdStore::PushCurrentTxd(); + CTxdStore::SetCurrentTxd(m_txdSlot); + tex = RwTextureRead(texName, NULL); + CTxdStore::PopCurrentTxd(); + if (tex != nil) return tex; + + if (strcmp(DEFAULT_SKIN_NAME, texName) == 0 || texName[0] == '\0') + sprintf(gString, "models\\generic\\player.bmp"); + else + sprintf(gString, "skins\\%s.bmp", texName); + + if (RwImage *image = RtBMPImageRead(gString)) { + RwImageFindRasterFormat(image, rwRASTERTYPETEXTURE, &width, &height, &depth, &format); + raster = RwRasterCreate(width, height, depth, format); + RwRasterSetFromImage(raster, image); + + tex = RwTextureCreate(raster); + RwTextureSetName(tex, texName); + RwTextureSetFilterMode(tex, rwFILTERLINEAR); + RwTexDictionaryAddTexture(CTxdStore::GetSlot(m_txdSlot)->texDict, tex); + + RwImageDestroy(image); + } + return tex; +} + +void +CPlayerSkin::BeginFrontendSkinEdit(void) +{ + LoadPlayerDff(); + RpClumpForAllAtomics(gpPlayerClump, CClumpModelInfo::SetAtomicRendererCB, (void*)CVisibilityPlugins::RenderPlayerCB); + CWorld::Players[0].LoadPlayerSkin(); + gOldFov = CDraw::GetFOV(); + CDraw::SetFOV(30.0f); +} + +void +CPlayerSkin::EndFrontendSkinEdit(void) +{ + RpClumpDestroy(gpPlayerClump); + gpPlayerClump = NULL; + CDraw::SetFOV(gOldFov); +} + +void +CPlayerSkin::RenderFrontendSkinEdit(void) +{ + static float rotation = 0.0f; + RwRGBAReal AmbientColor = { 0.65f, 0.65f, 0.65f, 1.0f }; + const RwV3d pos = { 1.35f, 0.35f, 7.725f }; + const RwV3d axis = { 0.0f, 1.0f, 0.0f }; + static uint32 LastFlash = 0; + + RwFrame *frame = RpClumpGetFrame(gpPlayerClump); + + if (CTimer::GetTimeInMillisecondsPauseMode() - LastFlash > 7) { + rotation += 2.0f; + if (rotation > 360.0f) + rotation -= 360.0f; + LastFlash = CTimer::GetTimeInMillisecondsPauseMode(); + } + RwFrameTransform(frame, RwFrameGetMatrix(RwCameraGetFrame(Scene.camera)), rwCOMBINEREPLACE); + RwFrameTranslate(frame, &pos, rwCOMBINEPRECONCAT); + RwFrameRotate(frame, &axis, rotation, rwCOMBINEPRECONCAT); + RwFrameUpdateObjects(frame); + SetAmbientColours(&AmbientColor); + RpClumpRender(gpPlayerClump); +} diff --git a/src/renderer/PlayerSkin.h b/src/renderer/PlayerSkin.h new file mode 100644 index 00000000..e0214ce0 --- /dev/null +++ b/src/renderer/PlayerSkin.h @@ -0,0 +1,15 @@ +#pragma once + +#define DEFAULT_SKIN_NAME "$$\"\"" + +class CPlayerSkin +{ + static int m_txdSlot; +public: + static void Initialise(); + static void Shutdown(); + static RwTexture *GetSkinTexture(const char *texName); + static void BeginFrontendSkinEdit(); + static void EndFrontendSkinEdit(); + static void RenderFrontendSkinEdit(); +}; \ No newline at end of file diff --git a/src/renderer/PointLights.cpp b/src/renderer/PointLights.cpp new file mode 100644 index 00000000..13872401 --- /dev/null +++ b/src/renderer/PointLights.cpp @@ -0,0 +1,330 @@ +#include "common.h" + +#include "main.h" +#include "CutsceneMgr.h" +#include "Lights.h" +#include "Camera.h" +#include "Weather.h" +#include "World.h" +#include "Collision.h" +#include "Sprite.h" +#include "Timer.h" +#include "PointLights.h" + +int16 CPointLights::NumLights; +CRegisteredPointLight CPointLights::aLights[NUMPOINTLIGHTS]; +CVector CPointLights::aCachedMapReads[32]; +float CPointLights::aCachedMapReadResults[32]; +int32 CPointLights::NextCachedValue; + +void +CPointLights::Init(void) +{ + for(int i = 0; i < ARRAY_SIZE(aCachedMapReads); i++){ + aCachedMapReads[i] = CVector(0.0f, 0.0f, 0.0f); + aCachedMapReadResults[i] = 0.0f; + } + NextCachedValue = 0; +} + +void +CPointLights::InitPerFrame(void) +{ + NumLights = 0; +} + +#define MAX_DIST 22.0f + +void +CPointLights::AddLight(uint8 type, CVector coors, CVector dir, float radius, float red, float green, float blue, uint8 fogType, bool castExtraShadows) +{ + CVector dist; + float distance; + + // The check is done in some weird way in the game + // we're doing it a bit better here + if(NumLights >= NUMPOINTLIGHTS) + return; + + dist = coors - TheCamera.GetPosition(); + if(Abs(dist.x) < MAX_DIST && Abs(dist.y) < MAX_DIST){ + distance = dist.Magnitude(); + if(distance < MAX_DIST){ + aLights[NumLights].type = type; + aLights[NumLights].fogType = fogType; + aLights[NumLights].coors = coors; + aLights[NumLights].dir = dir; + aLights[NumLights].radius = radius; + aLights[NumLights].castExtraShadows = castExtraShadows; + if(distance < MAX_DIST*0.75f){ + aLights[NumLights].red = red; + aLights[NumLights].green = green; + aLights[NumLights].blue = blue; + }else{ + float fade = 1.0f - (distance/MAX_DIST - 0.75f)*4.0f; + aLights[NumLights].red = red * fade; + aLights[NumLights].green = green * fade; + aLights[NumLights].blue = blue * fade; + } + NumLights++; + } + } +} + +float +CPointLights::GenerateLightsAffectingObject(Const CVector *objCoors) +{ + int i; + float ret; + CVector dist; + float radius, distance; + + ret = 1.0f; + for(i = 0; i < NumLights; i++){ + if(aLights[i].type == LIGHT_FOGONLY || aLights[i].type == LIGHT_FOGONLY_ALWAYS) + continue; + + // same weird distance calculation. simplified here + dist = aLights[i].coors - *objCoors; + radius = aLights[i].radius; + if(Abs(dist.x) < radius && + Abs(dist.y) < radius && + Abs(dist.z) < radius){ + + distance = dist.Magnitude(); + if(distance < radius){ + + float distNorm = distance/radius; + if(aLights[i].type == LIGHT_DARKEN){ + // darken the object the closer it is + ret *= distNorm; + }else{ + float intensity; + // distance fade + if(distNorm < 0.5f) + intensity = 1.0f; + else + intensity = 1.0f - (distNorm - 0.5f)/(1.0f - 0.5f); + + if(distance != 0.0f){ + CVector dir = dist / distance; + + if(aLights[i].type == LIGHT_DIRECTIONAL){ + float dot = -DotProduct(dir, aLights[i].dir); + intensity *= Max((dot-0.5f)*2.0f, 0.0f); + } + + if(intensity > 0.0f) + AddAnExtraDirectionalLight(Scene.world, + dir.x, dir.y, dir.z, + aLights[i].red*intensity, aLights[i].green*intensity, aLights[i].blue*intensity); + } + } + } + } + } + + return ret; +} + +extern RwRaster *gpPointlightRaster; + +void +CPointLights::RemoveLightsAffectingObject(void) +{ + RemoveExtraDirectionalLights(Scene.world); +} + +// for directional fog +#define FOG_AREA_LENGTH 12.0f +#define FOG_AREA_WIDTH 5.0f +// for pointlight fog +#define FOG_AREA_RADIUS 9.0f + +float FogSizes[8] = { 1.3f, 2.0f, 1.7f, 2.0f, 1.4f, 2.1f, 1.5f, 2.3f }; + +void +CPointLights::RenderFogEffect(void) +{ + int i; + float fogginess; + CColPoint point; + CEntity *entity; + float xmin, ymin; + float xmax, ymax; + int16 xi, yi; + CVector spriteCoors; + float spritew, spriteh; + + if(CCutsceneMgr::IsRunning()) + return; + + PUSH_RENDERGROUP("CPointLights::RenderFogEffect"); + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpPointlightRaster); + + CSprite::InitSpriteBuffer(); + + for(i = 0; i < NumLights; i++){ + if(aLights[i].fogType != FOG_NORMAL && aLights[i].fogType != FOG_ALWAYS) + continue; + + fogginess = aLights[i].fogType == FOG_NORMAL ? CWeather::Foggyness : 1.0f; + if(fogginess == 0.0f) + continue; + + if(aLights[i].type == LIGHT_DIRECTIONAL){ + + // TODO: test this. haven't found directional fog so far + + float coors2X = aLights[i].coors.x + FOG_AREA_LENGTH*aLights[i].dir.x; + float coors2Y = aLights[i].coors.y + FOG_AREA_LENGTH*aLights[i].dir.y; + + if(coors2X < aLights[i].coors.x){ + xmin = coors2X; + xmax = aLights[i].coors.x; + }else{ + xmax = coors2X; + xmin = aLights[i].coors.x; + } + if(coors2Y < aLights[i].coors.y){ + ymin = coors2Y; + ymax = aLights[i].coors.y; + }else{ + ymax = coors2Y; + ymin = aLights[i].coors.y; + } + + xmin -= 5.0f; + ymin -= 5.0f; + xmax += 5.0f; + ymax += 5.0f; + + for(xi = (int16)xmin - (int16)xmin % 4; xi <= (int16)xmax + 4; xi += 4){ + for(yi = (int16)ymin - (int16)ymin % 4; yi <= (int16)ymax + 4; yi += 4){ + // Some kind of pseudo random number? + int r = (xi ^ yi)>>2 & 0xF; + if((r & 1) == 0) + continue; + + // Check if fog effect is close enough to directional line in x and y + float dx = xi - aLights[i].coors.x; + float dy = yi - aLights[i].coors.y; + float dot = dx*aLights[i].dir.x + dy*aLights[i].dir.y; + float distsq = sq(dx) + sq(dy); + float linedistsq = distsq - sq(dot); + if(dot > 0.0f && dot < FOG_AREA_LENGTH && linedistsq < sq(FOG_AREA_WIDTH)){ + CVector fogcoors(xi, yi, aLights[i].coors.z + 10.0f); + if(CWorld::ProcessVerticalLine(fogcoors, fogcoors.z - 20.0f, + point, entity, true, false, false, false, true, false, nil)){ + // Now same check again in xyz + fogcoors.z = point.point.z + 1.3f; + // actually we don't have to recalculate x and y, but the game does it that way + dx = xi - aLights[i].coors.x; + dy = yi - aLights[i].coors.y; + float dz = fogcoors.z - aLights[i].coors.z; + dot = dx*aLights[i].dir.x + dy*aLights[i].dir.y + dz*aLights[i].dir.z; + distsq = sq(dx) + sq(dy) + sq(dz); + linedistsq = distsq - sq(dot); + if(dot > 0.0f && dot < FOG_AREA_LENGTH && linedistsq < sq(FOG_AREA_WIDTH)){ + float intensity = 158.0f * fogginess; + // more intensity the smaller the angle + intensity *= dot/Sqrt(distsq); + // more intensity the closer to light source + intensity *= 1.0f - sq(dot/FOG_AREA_LENGTH); + // more intensity the closer to line + intensity *= 1.0f - sq(Sqrt(linedistsq) / FOG_AREA_WIDTH); + + if(CSprite::CalcScreenCoors(fogcoors, &spriteCoors, &spritew, &spriteh, true)) { + float rotation = (CTimer::GetTimeInMilliseconds()&0x1FFF) * 2*3.14f / 0x2000; + float size = FogSizes[r>>1]; + CSprite::RenderBufferedOneXLUSprite_Rotate_Aspect(spriteCoors.x, spriteCoors.y, spriteCoors.z, + spritew * size, spriteh * size, + aLights[i].red * intensity, aLights[i].green * intensity, aLights[i].blue * intensity, + intensity, 1/spriteCoors.z, rotation, 255); + } + } + } + } + } + } + + }else if(aLights[i].type == LIGHT_POINT || aLights[i].type == LIGHT_FOGONLY || aLights[i].type == LIGHT_FOGONLY_ALWAYS){ + float groundZ; + if(ProcessVerticalLineUsingCache(aLights[i].coors, &groundZ)){ + xmin = aLights[i].coors.x - FOG_AREA_RADIUS; + ymin = aLights[i].coors.y - FOG_AREA_RADIUS; + xmax = aLights[i].coors.x + FOG_AREA_RADIUS; + ymax = aLights[i].coors.y + FOG_AREA_RADIUS; + + for(xi = (int16)xmin - (int16)xmin % 2; xi <= (int16)xmax + 2; xi += 2){ + for(yi = (int16)ymin - (int16)ymin % 2; yi <= (int16)ymax + 2; yi += 2){ + // Some kind of pseudo random number? + int r = (xi ^ yi)>>1 & 0xF; + if((r & 1) == 0) + continue; + + float dx = xi - aLights[i].coors.x; + float dy = yi - aLights[i].coors.y; + float lightdist = Sqrt(sq(dx) + sq(dy)); + if(lightdist < FOG_AREA_RADIUS){ + dx = xi - TheCamera.GetPosition().x; + dy = yi - TheCamera.GetPosition().y; + float camdist = Sqrt(sq(dx) + sq(dy)); + if(camdist < MAX_DIST){ + float intensity; + // distance fade + if(camdist < MAX_DIST/2) + intensity = 1.0f; + else + intensity = 1.0f - (camdist - MAX_DIST/2) / (MAX_DIST/2); + intensity *= 132.0f * fogginess; + // more intensity the closer to light source + intensity *= 1.0f - sq(lightdist / FOG_AREA_RADIUS); + + CVector fogcoors(xi, yi, groundZ + 1.6f); + if(CSprite::CalcScreenCoors(fogcoors, &spriteCoors, &spritew, &spriteh, true)) { + float rotation = (CTimer::GetTimeInMilliseconds()&0x3FFF) * 2*3.14f / 0x4000; + float size = FogSizes[r>>1]; + CSprite::RenderBufferedOneXLUSprite_Rotate_Aspect(spriteCoors.x, spriteCoors.y, spriteCoors.z, + spritew * size, spriteh * size, + aLights[i].red * intensity, aLights[i].green * intensity, aLights[i].blue * intensity, + intensity, 1/spriteCoors.z, rotation, 255); + } + } + } + } + } + } + } + } + + CSprite::FlushSpriteBuffer(); + + POP_RENDERGROUP(); +} + +bool +CPointLights::ProcessVerticalLineUsingCache(CVector coors, float *groundZ) +{ + for(int i = 0; i < ARRAY_SIZE(aCachedMapReads); i++) + if(aCachedMapReads[i] == coors){ + *groundZ = aCachedMapReadResults[i]; + return true; + } + + CColPoint point; + CEntity *entity; + if(CWorld::ProcessVerticalLine(coors, coors.z - 20.0f, point, entity, true, false, false, false, true, false, nil)){ + aCachedMapReads[NextCachedValue] = coors; + aCachedMapReadResults[NextCachedValue] = point.point.z; + NextCachedValue = (NextCachedValue+1) % ARRAY_SIZE(aCachedMapReads); + *groundZ = point.point.z; + return true; + } + return false; +} diff --git a/src/renderer/PointLights.h b/src/renderer/PointLights.h new file mode 100644 index 00000000..827200b9 --- /dev/null +++ b/src/renderer/PointLights.h @@ -0,0 +1,50 @@ +#pragma once + +class CRegisteredPointLight +{ +public: + CVector coors; + CVector dir; + float radius; + float red; + float green; + float blue; + int8 type; + int8 fogType; + bool castExtraShadows; +}; +VALIDATE_SIZE(CRegisteredPointLight, 0x2C); + +class CPointLights +{ +public: + static int16 NumLights; + static CRegisteredPointLight aLights[NUMPOINTLIGHTS]; + static CVector aCachedMapReads[32]; + static float aCachedMapReadResults[32]; + static int32 NextCachedValue; + + enum { + LIGHT_POINT, + LIGHT_DIRECTIONAL, + LIGHT_DARKEN, // no effects at all + // these have only fog, otherwise no difference? + // only used by CEntity::ProcessLightsForEntity it seems + // and there used together with fog type + LIGHT_FOGONLY_ALWAYS, + LIGHT_FOGONLY, + }; + enum { + FOG_NONE, + FOG_NORMAL, // taken from Foggyness + FOG_ALWAYS + }; + + static void Init(void); + static void InitPerFrame(void); + static void AddLight(uint8 type, CVector coors, CVector dir, float radius, float red, float green, float blue, uint8 fogType, bool castExtraShadows); + static float GenerateLightsAffectingObject(Const CVector *objCoors); + static void RemoveLightsAffectingObject(void); + static void RenderFogEffect(void); + static bool ProcessVerticalLineUsingCache(CVector coors, float *groundZ); +}; diff --git a/src/renderer/RenderBuffer.cpp b/src/renderer/RenderBuffer.cpp new file mode 100644 index 00000000..687cc76b --- /dev/null +++ b/src/renderer/RenderBuffer.cpp @@ -0,0 +1,52 @@ +#include "common.h" + +#include "RenderBuffer.h" + +int32 TempBufferVerticesStored; +int32 TempBufferIndicesStored; + +VertexBufferUnion TempVertexBuffer; +RwImVertexIndex TempBufferRenderIndexList[TEMPBUFFERINDEXSIZE]; + +int RenderBuffer::VerticesToBeStored; +int RenderBuffer::IndicesToBeStored; + +void +RenderBuffer::ClearRenderBuffer(void) +{ + TempBufferVerticesStored = 0; + TempBufferIndicesStored = 0; +} + +void +RenderBuffer::StartStoring(int numIndices, int numVertices, RwImVertexIndex **indexStart, RwIm3DVertex **vertexStart) +{ + if(TempBufferIndicesStored + numIndices >= TEMPBUFFERINDEXSIZE) + RenderStuffInBuffer(); + if(TempBufferVerticesStored + numVertices >= TEMPBUFFERVERTSIZE) + RenderStuffInBuffer(); + *indexStart = &TempBufferRenderIndexList[TempBufferIndicesStored]; + *vertexStart = &TempBufferRenderVertices[TempBufferVerticesStored]; + IndicesToBeStored = numIndices; + VerticesToBeStored = numVertices; +} + +void +RenderBuffer::StopStoring(void) +{ + int i; + for(i = TempBufferIndicesStored; i < TempBufferIndicesStored+IndicesToBeStored; i++) + TempBufferRenderIndexList[i] += TempBufferVerticesStored; + TempBufferIndicesStored += IndicesToBeStored; + TempBufferVerticesStored += VerticesToBeStored; +} + +void +RenderBuffer::RenderStuffInBuffer(void) +{ + if(TempBufferVerticesStored && RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV)){ + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); + RwIm3DEnd(); + } + ClearRenderBuffer(); +} diff --git a/src/renderer/RenderBuffer.h b/src/renderer/RenderBuffer.h new file mode 100644 index 00000000..a0f3e7b9 --- /dev/null +++ b/src/renderer/RenderBuffer.h @@ -0,0 +1,25 @@ +class RenderBuffer +{ +public: + static int VerticesToBeStored; + static int IndicesToBeStored; + static void ClearRenderBuffer(void); + static void StartStoring(int numIndices, int numVertices, RwImVertexIndex **indexStart, RwIm3DVertex **vertexStart); + static void StopStoring(void); + static void RenderStuffInBuffer(void); +}; + +#define TEMPBUFFERVERTSIZE 512 +#define TEMPBUFFERINDEXSIZE 1024 + +struct VertexBufferUnion +{ + RwIm2DVertex im2d[TEMPBUFFERVERTSIZE]; + RwIm3DVertex im3d[TEMPBUFFERVERTSIZE]; +}; + +extern int32 TempBufferVerticesStored; +extern int32 TempBufferIndicesStored; +extern VertexBufferUnion TempVertexBuffer; +#define TempBufferRenderVertices (TempVertexBuffer.im3d) +extern RwImVertexIndex TempBufferRenderIndexList[TEMPBUFFERINDEXSIZE]; \ No newline at end of file diff --git a/src/renderer/Renderer.cpp b/src/renderer/Renderer.cpp new file mode 100644 index 00000000..6b306b6c --- /dev/null +++ b/src/renderer/Renderer.cpp @@ -0,0 +1,1675 @@ +#define WITHD3D +#include "common.h" + +#include "main.h" +#include "Lights.h" +#include "ModelInfo.h" +#include "Treadable.h" +#include "Ped.h" +#include "Vehicle.h" +#include "Boat.h" +#include "Heli.h" +#include "Bike.h" +#include "Object.h" +#include "PathFind.h" +#include "Collision.h" +#include "VisibilityPlugins.h" +#include "Clock.h" +#include "World.h" +#include "Camera.h" +#include "ModelIndices.h" +#include "Streaming.h" +#include "Shadows.h" +#include "PointLights.h" +#include "Occlusion.h" +#include "Renderer.h" +#include "custompipes.h" +#include "Frontend.h" + +bool gbShowPedRoadGroups; +bool gbShowCarRoadGroups; +bool gbShowCollisionPolys; +bool gbShowCollisionLines; +bool gbBigWhiteDebugLightSwitchedOn; + +bool gbDontRenderBuildings; +bool gbDontRenderBigBuildings; +bool gbDontRenderPeds; +bool gbDontRenderObjects; +bool gbDontRenderVehicles; + +// unused +int16 TestCloseThings; +int16 TestBigThings; + +struct EntityInfo +{ + CEntity *ent; + float sort; +}; + +CLinkList gSortedVehiclesAndPeds; + +int32 CRenderer::ms_nNoOfVisibleEntities; +CEntity *CRenderer::ms_aVisibleEntityPtrs[NUMVISIBLEENTITIES]; +CEntity *CRenderer::ms_aInVisibleEntityPtrs[NUMINVISIBLEENTITIES]; +int32 CRenderer::ms_nNoOfInVisibleEntities; +#ifdef NEW_RENDERER +int32 CRenderer::ms_nNoOfVisibleVehicles; +CEntity *CRenderer::ms_aVisibleVehiclePtrs[NUMVISIBLEENTITIES]; +int32 CRenderer::ms_nNoOfVisibleBuildings; +CEntity *CRenderer::ms_aVisibleBuildingPtrs[NUMVISIBLEENTITIES]; +#endif + +CVector CRenderer::ms_vecCameraPosition; +CVehicle *CRenderer::m_pFirstPersonVehicle; +bool CRenderer::m_loadingPriority; +float CRenderer::ms_lodDistScale = 1.2f; + +// unused +BlockedRange CRenderer::aBlockedRanges[16]; +BlockedRange* CRenderer::pFullBlockedRanges; +BlockedRange* CRenderer::pEmptyBlockedRanges; + +void +CRenderer::Init(void) +{ + gSortedVehiclesAndPeds.Init(40); + SortBIGBuildings(); +} + +void +CRenderer::Shutdown(void) +{ + gSortedVehiclesAndPeds.Shutdown(); +} + +void +CRenderer::PreRender(void) +{ + int i; + CLink *node; + + for(i = 0; i < ms_nNoOfVisibleEntities; i++) + ms_aVisibleEntityPtrs[i]->PreRender(); + +#ifdef NEW_RENDERER + if(gbNewRenderer){ + for(i = 0; i < ms_nNoOfVisibleVehicles; i++) + ms_aVisibleVehiclePtrs[i]->PreRender(); + // How is this done with cWorldStream? + for(i = 0; i < ms_nNoOfVisibleBuildings; i++) + ms_aVisibleBuildingPtrs[i]->PreRender(); + for(node = CVisibilityPlugins::m_alphaBuildingList.head.next; + node != &CVisibilityPlugins::m_alphaBuildingList.tail; + node = node->next) + ((CEntity*)node->item.entity)->PreRender(); + } +#endif + + for (i = 0; i < ms_nNoOfInVisibleEntities; i++) { +#ifdef SQUEEZE_PERFORMANCE + if (ms_aInVisibleEntityPtrs[i]->IsVehicle() && ((CVehicle*)ms_aInVisibleEntityPtrs[i])->IsHeli()) +#endif + ms_aInVisibleEntityPtrs[i]->PreRender(); + } + + for(node = CVisibilityPlugins::m_alphaEntityList.head.next; + node != &CVisibilityPlugins::m_alphaEntityList.tail; + node = node->next) + ((CEntity*)node->item.entity)->PreRender(); + + CHeli::SpecialHeliPreRender(); + CShadows::RenderExtraPlayerShadows(); +} + +void +CRenderer::RenderOneRoad(CEntity *e) +{ + if(gbDontRenderBuildings) + return; + if(gbShowCollisionPolys) + CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(), e->GetModelIndex()); + else{ + PUSH_RENDERGROUP(CModelInfo::GetModelInfo(e->GetModelIndex())->GetModelName()); + + e->Render(); + + POP_RENDERGROUP(); + } +} + +void +CRenderer::RenderOneNonRoad(CEntity *e) +{ + CPed *ped; + CVehicle *veh; + int i; + bool resetLights; + +#ifndef MASTER + if(gbShowCollisionPolys){ + if(!e->IsVehicle()){ + CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(), e->GetModelIndex()); + return; + } + }else if(e->IsBuilding()){ + if(e->bIsBIGBuilding){ + if(gbDontRenderBigBuildings) + return; + }else{ + if(gbDontRenderBuildings) + return; + } + }else +#endif + if(e->IsPed()){ +#ifndef MASTER + if(gbDontRenderPeds) + return; +#endif + ped = (CPed*)e; + if(ped->m_nPedState == PED_DRIVING) + return; + } +#ifndef MASTER + else if(e->IsObject() || e->IsDummy()){ + if(gbDontRenderObjects) + return; + }else if(e->IsVehicle()){ + // re3 addition + if(gbDontRenderVehicles) + return; + } +#endif + + PUSH_RENDERGROUP(CModelInfo::GetModelInfo(e->GetModelIndex())->GetModelName()); + + resetLights = e->SetupLighting(); + + if(e->IsVehicle()){ + // unfortunately can't use GetClump here + CVisibilityPlugins::SetupVehicleVariables((RpClump*)e->m_rwObject); + CVisibilityPlugins::InitAlphaAtomicList(); + } + + // Render Peds in vehicle before vehicle itself + if(e->IsVehicle()){ + veh = (CVehicle*)e; + if(veh->pDriver && veh->pDriver->m_nPedState == PED_DRIVING) + veh->pDriver->Render(); + for(i = 0; i < 8; i++) + if(veh->pPassengers[i] && veh->pPassengers[i]->m_nPedState == PED_DRIVING) + veh->pPassengers[i]->Render(); + SetCullMode(rwCULLMODECULLNONE); + } + e->Render(); + + if(e->IsVehicle()){ + e->bImBeingRendered = true; + CVisibilityPlugins::RenderAlphaAtomics(); + e->bImBeingRendered = false; + SetCullMode(rwCULLMODECULLBACK); + } + + e->RemoveLighting(resetLights); + + POP_RENDERGROUP(); +} + +void +CRenderer::RenderFirstPersonVehicle(void) +{ + if(m_pFirstPersonVehicle == nil) + return; + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RenderOneNonRoad(m_pFirstPersonVehicle); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); +} + +inline bool IsRoad(CEntity *e) { return e->IsBuilding() && ((CSimpleModelInfo*)CModelInfo::GetModelInfo(e->GetModelIndex()))->m_wetRoadReflection; } + +void +CRenderer::RenderRoads(void) +{ + int i; + CEntity *e; + + PUSH_RENDERGROUP("CRenderer::RenderRoads"); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + SetCullMode(rwCULLMODECULLBACK); + DeActivateDirectional(); + SetAmbientColours(); + + for(i = 0; i < ms_nNoOfVisibleEntities; i++){ + e = ms_aVisibleEntityPtrs[i]; + if(IsRoad(e)) + RenderOneRoad(e); + } + POP_RENDERGROUP(); +} + +inline bool PutIntoSortedVehicleList(CVehicle *veh) +{ + if(veh->IsBoat()){ + int mode = TheCamera.Cams[TheCamera.ActiveCam].Mode; + if(mode == CCam::MODE_WHEELCAM || + mode == CCam::MODE_1STPERSON && TheCamera.GetLookDirection() != LOOKING_FORWARD && TheCamera.GetLookDirection() != LOOKING_BEHIND || + CVisibilityPlugins::GetClumpAlpha(veh->GetClump()) != 255) + return false; + return true; + }else + return veh->bTouchingWater; +} + +void +CRenderer::RenderEverythingBarRoads(void) +{ + int i; + CEntity *e; + EntityInfo ei; + + PUSH_RENDERGROUP("CRenderer::RenderEverythingBarRoads"); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + SetCullMode(rwCULLMODECULLBACK); + gSortedVehiclesAndPeds.Clear(); + + for(i = 0; i < ms_nNoOfVisibleEntities; i++){ + e = ms_aVisibleEntityPtrs[i]; + + if(IsRoad(e)) + continue; + +#ifdef EXTENDED_PIPELINES + if(CustomPipes::bRenderingEnvMap && (e->IsPed() || e->IsVehicle())) + continue; +#endif + + if(e->IsVehicle() || + e->IsPed() && CVisibilityPlugins::GetClumpAlpha((RpClump*)e->m_rwObject) != 255){ + if(e->IsVehicle() && PutIntoSortedVehicleList((CVehicle*)e)){ + ei.ent = e; + ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr(); + gSortedVehiclesAndPeds.InsertSorted(ei); + }else{ + if(!CVisibilityPlugins::InsertEntityIntoSortedList(e, (ms_vecCameraPosition - e->GetPosition()).Magnitude())){ + printf("Ran out of space in alpha entity list"); + RenderOneNonRoad(e); + } + } + }else + RenderOneNonRoad(e); + } + POP_RENDERGROUP(); +} + +void +CRenderer::RenderBoats(void) +{ + CLink *node; + + PUSH_RENDERGROUP("CRenderer::RenderBoats"); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + SetCullMode(rwCULLMODECULLBACK); + +#ifdef NEW_RENDERER + int i; + CEntity *e; + EntityInfo ei; + if(gbNewRenderer){ + gSortedVehiclesAndPeds.Clear(); + // not the real thing + for(i = 0; i < ms_nNoOfVisibleVehicles; i++){ + e = ms_aVisibleVehiclePtrs[i]; + if(e->IsVehicle() && PutIntoSortedVehicleList((CVehicle*)e)){ + ei.ent = e; + ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr(); + gSortedVehiclesAndPeds.InsertSorted(ei); + } + } + } +#endif + + for(node = gSortedVehiclesAndPeds.tail.prev; + node != &gSortedVehiclesAndPeds.head; + node = node->prev){ + CVehicle *v = (CVehicle*)node->item.ent; + RenderOneNonRoad(v); + } + POP_RENDERGROUP(); +} + +#ifdef NEW_RENDERER +#ifndef LIBRW +#error "Need librw for EXTENDED_PIPELINES" +#endif +#include "WaterLevel.h" + +enum { + // blend passes + PASS_NOZ, // no z-write + PASS_ADD, // additive + PASS_BLEND // normal blend +}; + +static void +SetStencilState(int state) +{ + switch(state){ + // disable stencil + case 0: + rw::SetRenderState(rw::STENCILENABLE, FALSE); + break; + // test against stencil + case 1: + rw::SetRenderState(rw::STENCILENABLE, TRUE); + rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILNOTEQUAL); + rw::SetRenderState(rw::STENCILPASS, rw::STENCILKEEP); + rw::SetRenderState(rw::STENCILFAIL, rw::STENCILKEEP); + rw::SetRenderState(rw::STENCILZFAIL, rw::STENCILKEEP); + rw::SetRenderState(rw::STENCILFUNCTIONMASK, 0xFF); + rw::SetRenderState(rw::STENCILFUNCTIONREF, 0xFF); + break; + // write to stencil + case 2: + rw::SetRenderState(rw::STENCILENABLE, TRUE); + rw::SetRenderState(rw::STENCILFUNCTION, rw::STENCILALWAYS); + rw::SetRenderState(rw::STENCILPASS, rw::STENCILREPLACE); + rw::SetRenderState(rw::STENCILFUNCTIONREF, 0xFF); + break; + } +} + +void +CRenderer::RenderOneBuilding(CEntity *ent, float camdist) +{ + if(ent->m_rwObject == nil) + return; + + ent->bImBeingRendered = true; // TODO: this seems wrong, but do we even need it? + + assert(RwObjectGetType(ent->m_rwObject) == rpATOMIC); + RpAtomic *atomic = (RpAtomic*)ent->m_rwObject; + CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(ent->GetModelIndex()); + + int pass = PASS_BLEND; + if(mi->m_additive) // very questionable + pass = PASS_ADD; + if(mi->m_noZwrite) + pass = PASS_NOZ; + + if(ent->bDistanceFade){ + RpAtomic *lodatm; + float fadefactor; + uint32 alpha; + + lodatm = mi->GetAtomicFromDistance(camdist - FADE_DISTANCE); + fadefactor = (mi->GetLargestLodDistance() - (camdist - FADE_DISTANCE))/FADE_DISTANCE; + if(fadefactor > 1.0f) + fadefactor = 1.0f; + alpha = mi->m_alpha * fadefactor; + + if(alpha == 255) + WorldRender::AtomicFirstPass(atomic, pass); + else{ + // not quite sure what this is about, do we have to do that? + RpGeometry *geo = RpAtomicGetGeometry(lodatm); + if(geo != RpAtomicGetGeometry(atomic)) + RpAtomicSetGeometry(atomic, geo, rpATOMICSAMEBOUNDINGSPHERE); + WorldRender::AtomicFullyTransparent(atomic, pass, alpha); + } + }else + WorldRender::AtomicFirstPass(atomic, pass); + + ent->bImBeingRendered = false; // TODO: this seems wrong, but do we even need it? +} + +void +CRenderer::RenderWorld(int pass) +{ + int i; + CEntity *e; + CLink *node; + + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); + SetCullMode(rwCULLMODECULLBACK); + DeActivateDirectional(); + SetAmbientColours(); + + // Temporary...have to figure out sorting better + switch(pass){ + case 0: + // Roads + PUSH_RENDERGROUP("CRenderer::RenderWorld - Roads"); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + for(i = 0; i < ms_nNoOfVisibleBuildings; i++){ + e = ms_aVisibleBuildingPtrs[i]; + if(e->bIsBIGBuilding || IsRoad(e)) + RenderOneBuilding(e); + } + for(node = CVisibilityPlugins::m_alphaBuildingList.tail.prev; + node != &CVisibilityPlugins::m_alphaBuildingList.head; + node = node->prev){ + e = node->item.entity; + if(e->bIsBIGBuilding || IsRoad(e)) + RenderOneBuilding(e, node->item.sort); + } + POP_RENDERGROUP(); + break; + case 1: + // Opaque + PUSH_RENDERGROUP("CRenderer::RenderWorld - Opaque"); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + for(i = 0; i < ms_nNoOfVisibleBuildings; i++){ + e = ms_aVisibleBuildingPtrs[i]; + if(!(e->bIsBIGBuilding || IsRoad(e))) + RenderOneBuilding(e); + } + for(node = CVisibilityPlugins::m_alphaBuildingList.tail.prev; + node != &CVisibilityPlugins::m_alphaBuildingList.head; + node = node->prev){ + e = node->item.entity; + if(!(e->bIsBIGBuilding || IsRoad(e))) + RenderOneBuilding(e, node->item.sort); + } + // Now we have iterated through all visible buildings (unsorted and sorted) + // and the transparency list is done. + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); + WorldRender::RenderBlendPass(PASS_NOZ); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + POP_RENDERGROUP(); + break; + case 2: + // Transparent + PUSH_RENDERGROUP("CRenderer::RenderWorld - Transparent"); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + WorldRender::RenderBlendPass(PASS_ADD); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + WorldRender::RenderBlendPass(PASS_BLEND); + POP_RENDERGROUP(); + break; + } +} + +void +CRenderer::RenderPeds(void) +{ + int i; + CEntity *e; + + PUSH_RENDERGROUP("CRenderer::RenderPeds"); + for(i = 0; i < ms_nNoOfVisibleVehicles; i++){ + e = ms_aVisibleVehiclePtrs[i]; + if(e->IsPed()) + RenderOneNonRoad(e); + } + POP_RENDERGROUP(); +} + +void +CRenderer::RenderVehicles(void) +{ + int i; + CEntity *e; + EntityInfo ei; + CLink *node; + + PUSH_RENDERGROUP("CRenderer::RenderVehicles"); + // not the real thing + for(i = 0; i < ms_nNoOfVisibleVehicles; i++){ + e = ms_aVisibleVehiclePtrs[i]; + if(!e->IsVehicle()) + continue; + if(PutIntoSortedVehicleList((CVehicle*)e)) + continue; // boats handled elsewhere + ei.ent = e; + ei.sort = (ms_vecCameraPosition - e->GetPosition()).MagnitudeSqr(); + gSortedVehiclesAndPeds.InsertSorted(ei); + } + + for(node = gSortedVehiclesAndPeds.tail.prev; + node != &gSortedVehiclesAndPeds.head; + node = node->prev) + RenderOneNonRoad(node->item.ent); + POP_RENDERGROUP(); +} + +void +CRenderer::RenderTransparentWater(void) +{ + int i; + CEntity *e; + + PUSH_RENDERGROUP("CRenderer::RenderTransparentWater"); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDZERO); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + SetStencilState(2); + + for(i = 0; i < ms_nNoOfVisibleVehicles; i++){ + e = ms_aVisibleVehiclePtrs[i]; + if(e->IsVehicle() && ((CVehicle*)e)->IsBoat()) + ((CBoat*)e)->RenderWaterOutPolys(); + } + + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + SetStencilState(1); + + CWaterLevel::RenderTransparentWater(); + + SetStencilState(0); + POP_RENDERGROUP(); +} + +void +CRenderer::ClearForFrame(void) +{ + ms_nNoOfVisibleEntities = 0; + ms_nNoOfVisibleVehicles = 0; + ms_nNoOfVisibleBuildings = 0; + ms_nNoOfInVisibleEntities = 0; + gSortedVehiclesAndPeds.Clear(); + + WorldRender::numBlendInsts[PASS_NOZ] = 0; + WorldRender::numBlendInsts[PASS_ADD] = 0; + WorldRender::numBlendInsts[PASS_BLEND] = 0; +} +#endif + +void +CRenderer::RenderFadingInEntities(void) +{ + PUSH_RENDERGROUP("CRenderer::RenderFadingInEntities"); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + SetCullMode(rwCULLMODECULLBACK); + DeActivateDirectional(); + SetAmbientColours(); + CVisibilityPlugins::RenderFadingEntities(); + POP_RENDERGROUP(); +} + +void +CRenderer::RenderFadingInUnderwaterEntities(void) +{ + PUSH_RENDERGROUP("CRenderer::RenderFadingInUnderwaterEntities"); + DeActivateDirectional(); + SetAmbientColours(); + CVisibilityPlugins::RenderFadingUnderwaterEntities(); + POP_RENDERGROUP(); +} + +void +CRenderer::RenderCollisionLines(void) +{ + int i; + + // game doesn't draw fading in entities + // this should probably be fixed + for(i = 0; i < ms_nNoOfVisibleEntities; i++){ + CEntity *e = ms_aVisibleEntityPtrs[i]; + if(Abs(e->GetPosition().x - ms_vecCameraPosition.x) < 100.0f && + Abs(e->GetPosition().y - ms_vecCameraPosition.y) < 100.0f) + CCollision::DrawColModel(e->GetMatrix(), *e->GetColModel()); + } +} + +enum Visbility +{ + VIS_INVISIBLE, + VIS_VISIBLE, + VIS_OFFSCREEN, + VIS_STREAMME +}; + +// Time Objects can be time culled if +// other == -1 || CModelInfo::GetModelInfo(other)->GetRwObject() +// i.e. we have to draw even at the wrong time if +// other != -1 && CModelInfo::GetModelInfo(other)->GetRwObject() == nil + +#define OTHERUNAVAILABLE (other != -1 && CModelInfo::GetModelInfo(other)->GetRwObject() == nil) +#define CANTIMECULL (!OTHERUNAVAILABLE) + +int32 +CRenderer::SetupEntityVisibility(CEntity *ent) +{ + CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(ent->m_modelIndex); + CTimeModelInfo *ti; + int32 other; + float dist; + + bool request = true; + if(mi->GetModelType() == MITYPE_TIME){ + ti = (CTimeModelInfo*)mi; + other = ti->GetOtherTimeModel(); + if(CClock::GetIsTimeInRange(ti->GetTimeOn(), ti->GetTimeOff())){ + // don't fade in, or between time objects + if(CANTIMECULL) + ti->m_alpha = 255; + }else{ + // Hide if possible + if(CANTIMECULL) + return VIS_INVISIBLE; + // can't cull, so we'll try to draw this one, but don't request + // it since what we really want is the other one. + request = false; + } + }else{ + if(mi->GetModelType() != MITYPE_SIMPLE && mi->GetModelType() != MITYPE_WEAPON){ + if(FindPlayerVehicle() == ent && + TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_1STPERSON && + !(FindPlayerVehicle()->IsBike() && ((CBike*)FindPlayerVehicle())->bWheelieCam)){ + // Player's vehicle in first person mode + CVehicle *veh = (CVehicle*)ent; + int model = veh->GetModelIndex(); + int direction = TheCamera.Cams[TheCamera.ActiveCam].DirectionWasLooking; + if(direction == LOOKING_FORWARD || + ent->GetModelIndex() == MI_RHINO || + ent->GetModelIndex() == MI_COACH || + TheCamera.m_bInATunnelAndABigVehicle || + direction == LOOKING_BEHIND && veh->pHandling->Flags & HANDLING_UNKNOWN){ + ent->bNoBrightHeadLights = true; + return VIS_OFFSCREEN; + } + + if(direction != LOOKING_BEHIND || + !veh->IsBoat() || model == MI_REEFER || model == MI_TROPIC || model == MI_PREDATOR || model == MI_SKIMMER){ + m_pFirstPersonVehicle = (CVehicle*)ent; + ent->bNoBrightHeadLights = false; + return VIS_OFFSCREEN; + } + } + + // All sorts of Clumps + if(ent->m_rwObject == nil || !ent->bIsVisible) + return VIS_INVISIBLE; + if(!ent->GetIsOnScreen() || ent->IsEntityOccluded()) + return VIS_OFFSCREEN; + if(ent->bDrawLast){ + dist = (ent->GetPosition() - ms_vecCameraPosition).Magnitude(); + CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); + ent->bDistanceFade = false; + return VIS_INVISIBLE; + } + return VIS_VISIBLE; + } + if(ent->bDontStream){ + if(ent->m_rwObject == nil || !ent->bIsVisible) + return VIS_INVISIBLE; + if(!ent->GetIsOnScreen() || ent->IsEntityOccluded()) + return VIS_OFFSCREEN; + if(ent->bDrawLast){ + dist = (ent->GetPosition() - ms_vecCameraPosition).Magnitude(); + CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); + ent->bDistanceFade = false; + return VIS_INVISIBLE; + } + return VIS_VISIBLE; + } + } + + // Simple ModelInfo + + if(!IsAreaVisible(ent->m_area)) + return VIS_INVISIBLE; + + dist = (ent->GetPosition() - ms_vecCameraPosition).Magnitude(); + +#ifndef FIX_BUGS + // Whatever this is supposed to do, it breaks fading for objects + // whose draw dist is > LOD_DISTANCE-FADE_DISTANCE, i.e. 280 + // because decreasing dist here makes the object visible above LOD_DISTANCE + // before fading normally once below LOD_DISTANCE. + // aha! this must be a workaround for the fact that we're not taking + // the LOD multiplier into account here anywhere + if(LOD_DISTANCE < dist && dist < mi->GetLargestLodDistance() + FADE_DISTANCE) + dist += mi->GetLargestLodDistance() - LOD_DISTANCE; +#endif + + if(ent->IsObject() && ent->bRenderDamaged) + mi->m_isDamaged = true; + + RpAtomic *a = mi->GetAtomicFromDistance(dist); + if(a){ + mi->m_isDamaged = false; + if(ent->m_rwObject == nil) + ent->CreateRwObject(); + assert(ent->m_rwObject); + RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject; + // Make sure our atomic uses the right geometry and not + // that of an atomic for another draw distance. + if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj)) + RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?) + mi->IncreaseAlpha(); + if(ent->m_rwObject == nil || !ent->bIsVisible) + return VIS_INVISIBLE; + + if(!ent->GetIsOnScreen() || ent->IsEntityOccluded()){ + mi->m_alpha = 255; + return VIS_OFFSCREEN; + } + + if(mi->m_alpha != 255){ + CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); + ent->bDistanceFade = true; + return VIS_INVISIBLE; + } + + if(mi->m_drawLast || ent->bDrawLast){ + if(CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist)){ + ent->bDistanceFade = false; + return VIS_INVISIBLE; + } + } + return VIS_VISIBLE; + } + + // Object is not loaded, figure out what to do + + if(mi->m_noFade){ + mi->m_isDamaged = false; + // request model + if(dist - STREAM_DISTANCE < mi->GetLargestLodDistance() && request) + return VIS_STREAMME; + return VIS_INVISIBLE; + } + + // We might be fading + + a = mi->GetAtomicFromDistance(dist - FADE_DISTANCE); + mi->m_isDamaged = false; + if(a == nil){ + // request model + if(dist - FADE_DISTANCE - STREAM_DISTANCE < mi->GetLargestLodDistance() && request) + return VIS_STREAMME; + return VIS_INVISIBLE; + } + + if(ent->m_rwObject == nil) + ent->CreateRwObject(); + assert(ent->m_rwObject); + RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject; + if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj)) + RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?) + mi->IncreaseAlpha(); + if(ent->m_rwObject == nil || !ent->bIsVisible) + return VIS_INVISIBLE; + + if(!ent->GetIsOnScreen() || ent->IsEntityOccluded()){ + mi->m_alpha = 255; + return VIS_OFFSCREEN; + }else{ + CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); + ent->bDistanceFade = true; + return VIS_OFFSCREEN; // Why this? + } +} + +int32 +CRenderer::SetupBigBuildingVisibility(CEntity *ent) +{ + CSimpleModelInfo *mi = (CSimpleModelInfo*)CModelInfo::GetModelInfo(ent->m_modelIndex); + CTimeModelInfo *ti; + int32 other; + + if(!IsAreaVisible(ent->m_area)) + return VIS_INVISIBLE; + + bool request = true; + if(mi->GetModelType() == MITYPE_TIME){ + ti = (CTimeModelInfo*)mi; + other = ti->GetOtherTimeModel(); + if(CClock::GetIsTimeInRange(ti->GetTimeOn(), ti->GetTimeOff())){ + // don't fade in, or between time objects + if(CANTIMECULL) + ti->m_alpha = 255; + }else{ + // Hide if possible + if(CANTIMECULL){ + ent->DeleteRwObject(); + return VIS_INVISIBLE; + } + // can't cull, so we'll try to draw this one, but don't request + // it since what we really want is the other one. + request = false; + } + }else if(mi->GetModelType() == MITYPE_VEHICLE) + return ent->IsVisible() ? VIS_VISIBLE : VIS_INVISIBLE; + + float dist = (ms_vecCameraPosition-ent->GetPosition()).Magnitude(); + CSimpleModelInfo *nonLOD = mi->GetRelatedModel(); + + // Find out whether to draw below near distance. + // This is only the case if there is a non-LOD which is either not + // loaded or not completely faded in yet. + if(dist < mi->GetNearDistance() && dist < LOD_DISTANCE){ + // No non-LOD or non-LOD is completely visible. + if(nonLOD == nil || + nonLOD->GetRwObject() && nonLOD->m_alpha == 255) + return VIS_INVISIBLE; + + // But if it is a time object, we'd rather draw the wrong + // non-LOD than the right LOD. + if(nonLOD->GetModelType() == MITYPE_TIME){ + ti = (CTimeModelInfo*)nonLOD; + other = ti->GetOtherTimeModel(); + if(other != -1 && CModelInfo::GetModelInfo(other)->GetRwObject()) + return VIS_INVISIBLE; + } + } + + RpAtomic *a = mi->GetFirstAtomicFromDistance(dist); + if(a){ + if(ent->m_rwObject == nil) + ent->CreateRwObject(); + assert(ent->m_rwObject); + RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject; + + // Make sure our atomic uses the right geometry and not + // that of an atomic for another draw distance. + if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj)) + RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?) + mi->IncreaseAlpha(); + if(!ent->IsVisible() || !ent->GetIsOnScreenComplex() || ent->IsEntityOccluded()){ + mi->m_alpha = 255; + return VIS_INVISIBLE; + } + + if(mi->m_alpha != 255){ + CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); + ent->bDistanceFade = true; + return VIS_INVISIBLE; + } + + if(mi->m_drawLast){ + CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); + ent->bDistanceFade = false; + return VIS_INVISIBLE; + } + return VIS_VISIBLE; + } + + if(mi->m_noFade){ + ent->DeleteRwObject(); + return VIS_INVISIBLE; + } + + + // get faded atomic + a = mi->GetFirstAtomicFromDistance(dist - FADE_DISTANCE); + if(a == nil){ + if(ent->bStreamBIGBuilding && dist-STREAM_DISTANCE < mi->GetLodDistance(0) && request){ + return ent->GetIsOnScreen() ? VIS_STREAMME : VIS_INVISIBLE; + }else{ + ent->DeleteRwObject(); + return VIS_INVISIBLE; + } + } + + // Fade... + if(ent->m_rwObject == nil) + ent->CreateRwObject(); + assert(ent->m_rwObject); + RpAtomic *rwobj = (RpAtomic*)ent->m_rwObject; + if(RpAtomicGetGeometry(a) != RpAtomicGetGeometry(rwobj)) + RpAtomicSetGeometry(rwobj, RpAtomicGetGeometry(a), rpATOMICSAMEBOUNDINGSPHERE); // originally 5 (mistake?) + mi->IncreaseAlpha(); + if(!ent->IsVisible() || !ent->GetIsOnScreenComplex() || ent->IsEntityOccluded()){ + mi->m_alpha = 255; + return VIS_INVISIBLE; + } + CVisibilityPlugins::InsertEntityIntoSortedList(ent, dist); + ent->bDistanceFade = true; + return VIS_INVISIBLE; +} + +void +CRenderer::ConstructRenderList(void) +{ + COcclusion::ProcessBeforeRendering(); +#ifdef NEW_RENDERER + if(!gbNewRenderer) +#endif +{ + ms_nNoOfVisibleEntities = 0; + ms_nNoOfInVisibleEntities = 0; +} + ms_vecCameraPosition = TheCamera.GetPosition(); + + // unused + pFullBlockedRanges = nil; + pEmptyBlockedRanges = aBlockedRanges; + for(int i = 0; i < 16; i++){ + aBlockedRanges[i].prev = &aBlockedRanges[i-1]; + aBlockedRanges[i].next = &aBlockedRanges[i+1]; + } + aBlockedRanges[0].prev = nil; + aBlockedRanges[15].next = nil; + + // unused + TestCloseThings = 0; + TestBigThings = 0; + + ScanWorld(); +} + +void +LimitFrustumVector(CVector &vec1, const CVector &vec2, float l) +{ + float f; + f = (l - vec2.z) / (vec1.z - vec2.z); + vec1.x = f*(vec1.x - vec2.x) + vec2.x; + vec1.y = f*(vec1.y - vec2.y) + vec2.y; + vec1.z = f*(vec1.z - vec2.z) + vec2.z; +} + +enum Corners +{ + CORNER_CAM = 0, + CORNER_FAR_TOPLEFT, + CORNER_FAR_TOPRIGHT, + CORNER_FAR_BOTRIGHT, + CORNER_FAR_BOTLEFT, + CORNER_LOD_LEFT, + CORNER_LOD_RIGHT, + CORNER_PRIO_LEFT, + CORNER_PRIO_RIGHT, +}; + +void +CRenderer::ScanWorld(void) +{ + float f = RwCameraGetFarClipPlane(TheCamera.m_pRwCamera); + RwV2d vw = *RwCameraGetViewWindow(TheCamera.m_pRwCamera); + CVector vectors[9]; + RwMatrix *cammatrix; + RwV2d poly[3]; + + memset(vectors, 0, sizeof(vectors)); + vectors[CORNER_FAR_TOPLEFT].x = -vw.x * f; + vectors[CORNER_FAR_TOPLEFT].y = vw.y * f; + vectors[CORNER_FAR_TOPLEFT].z = f; + vectors[CORNER_FAR_TOPRIGHT].x = vw.x * f; + vectors[CORNER_FAR_TOPRIGHT].y = vw.y * f; + vectors[CORNER_FAR_TOPRIGHT].z = f; + vectors[CORNER_FAR_BOTRIGHT].x = vw.x * f; + vectors[CORNER_FAR_BOTRIGHT].y = -vw.y * f; + vectors[CORNER_FAR_BOTRIGHT].z = f; + vectors[CORNER_FAR_BOTLEFT].x = -vw.x * f; + vectors[CORNER_FAR_BOTLEFT].y = -vw.y * f; + vectors[CORNER_FAR_BOTLEFT].z = f; + + cammatrix = RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera)); + + m_pFirstPersonVehicle = nil; + CVisibilityPlugins::InitAlphaEntityList(); + CWorld::AdvanceCurrentScanCode(); + + // unused + static CVector prevPos; + static CVector prevFwd; + static bool smallMovement; + smallMovement = (TheCamera.GetPosition() - prevPos).MagnitudeSqr() < SQR(4.0f) && + DotProduct(TheCamera.GetForward(), prevFwd) > 0.98f; + prevPos = TheCamera.GetPosition(); + prevFwd = TheCamera.GetForward(); + + if(cammatrix->at.z > 0.0f){ + // looking up, bottom corners are further away + vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_BOTLEFT] * LOD_DISTANCE/f; + vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_BOTRIGHT] * LOD_DISTANCE/f; + }else{ + // looking down, top corners are further away + vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_TOPLEFT] * LOD_DISTANCE/f; + vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_TOPRIGHT] * LOD_DISTANCE/f; + } + vectors[CORNER_PRIO_LEFT].x = vectors[CORNER_LOD_LEFT].x * 0.2f; + vectors[CORNER_PRIO_LEFT].y = vectors[CORNER_LOD_LEFT].y * 0.2f; + vectors[CORNER_PRIO_LEFT].z = vectors[CORNER_LOD_LEFT].z; + vectors[CORNER_PRIO_RIGHT].x = vectors[CORNER_LOD_RIGHT].x * 0.2f; + vectors[CORNER_PRIO_RIGHT].y = vectors[CORNER_LOD_RIGHT].y * 0.2f; + vectors[CORNER_PRIO_RIGHT].z = vectors[CORNER_LOD_RIGHT].z; + RwV3dTransformPoints(vectors, vectors, 9, cammatrix); + + m_loadingPriority = false; + if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN || +#ifdef FIX_BUGS + TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_GTACLASSIC || +#endif + TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){ + CRect rect; + int x1, x2, y1, y2; + LimitFrustumVector(vectors[CORNER_FAR_TOPLEFT], vectors[CORNER_CAM], -100.0f); + rect.ContainPoint(vectors[CORNER_FAR_TOPLEFT]); + LimitFrustumVector(vectors[CORNER_FAR_TOPRIGHT], vectors[CORNER_CAM], -100.0f); + rect.ContainPoint(vectors[CORNER_FAR_TOPRIGHT]); + LimitFrustumVector(vectors[CORNER_FAR_BOTRIGHT], vectors[CORNER_CAM], -100.0f); + rect.ContainPoint(vectors[CORNER_FAR_BOTRIGHT]); + LimitFrustumVector(vectors[CORNER_FAR_BOTLEFT], vectors[CORNER_CAM], -100.0f); + rect.ContainPoint(vectors[CORNER_FAR_BOTLEFT]); + x1 = CWorld::GetSectorIndexX(rect.left); + if(x1 < 0) x1 = 0; + x2 = CWorld::GetSectorIndexX(rect.right); + if(x2 >= NUMSECTORS_X-1) x2 = NUMSECTORS_X-1; + y1 = CWorld::GetSectorIndexY(rect.top); + if(y1 < 0) y1 = 0; + y2 = CWorld::GetSectorIndexY(rect.bottom); + if(y2 >= NUMSECTORS_Y-1) y2 = NUMSECTORS_Y-1; + for(; x1 <= x2; x1++) + for(int y = y1; y <= y2; y++) + ScanSectorList(CWorld::GetSector(x1, y)->m_lists); + }else{ +#ifdef GTA_TRAIN + CVehicle *train = FindPlayerTrain(); + if(train && train->GetPosition().z < 0.0f){ + poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x); + poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y); + poly[1].x = CWorld::GetSectorX(vectors[CORNER_LOD_LEFT].x); + poly[1].y = CWorld::GetSectorY(vectors[CORNER_LOD_LEFT].y); + poly[2].x = CWorld::GetSectorX(vectors[CORNER_LOD_RIGHT].x); + poly[2].y = CWorld::GetSectorY(vectors[CORNER_LOD_RIGHT].y); + ScanSectorPoly(poly, 3, ScanSectorList_Subway); + }else +#endif + { + if(f > LOD_DISTANCE){ + // priority + poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x); + poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y); + poly[1].x = CWorld::GetSectorX(vectors[CORNER_PRIO_LEFT].x); + poly[1].y = CWorld::GetSectorY(vectors[CORNER_PRIO_LEFT].y); + poly[2].x = CWorld::GetSectorX(vectors[CORNER_PRIO_RIGHT].x); + poly[2].y = CWorld::GetSectorY(vectors[CORNER_PRIO_RIGHT].y); + ScanSectorPoly(poly, 3, ScanSectorList_Priority); + + // below LOD + poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x); + poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y); + poly[1].x = CWorld::GetSectorX(vectors[CORNER_LOD_LEFT].x); + poly[1].y = CWorld::GetSectorY(vectors[CORNER_LOD_LEFT].y); + poly[2].x = CWorld::GetSectorX(vectors[CORNER_LOD_RIGHT].x); + poly[2].y = CWorld::GetSectorY(vectors[CORNER_LOD_RIGHT].y); + ScanSectorPoly(poly, 3, ScanSectorList); + }else{ + poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x); + poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y); + poly[1].x = CWorld::GetSectorX(vectors[CORNER_FAR_TOPLEFT].x); + poly[1].y = CWorld::GetSectorY(vectors[CORNER_FAR_TOPLEFT].y); + poly[2].x = CWorld::GetSectorX(vectors[CORNER_FAR_TOPRIGHT].x); + poly[2].y = CWorld::GetSectorY(vectors[CORNER_FAR_TOPRIGHT].y); + ScanSectorPoly(poly, 3, ScanSectorList); + } + +#ifdef NO_ISLAND_LOADING + if (FrontEndMenuManager.m_PrefsIslandLoading == CMenuManager::ISLAND_LOADING_HIGH) { + ScanBigBuildingList(CWorld::GetBigBuildingList(LEVEL_BEACH)); + ScanBigBuildingList(CWorld::GetBigBuildingList(LEVEL_MAINLAND)); + } else +#endif + { +#ifdef FIX_BUGS + if(CCollision::ms_collisionInMemory != LEVEL_GENERIC) +#endif + ScanBigBuildingList(CWorld::GetBigBuildingList(CGame::currLevel)); + } + ScanBigBuildingList(CWorld::GetBigBuildingList(LEVEL_GENERIC)); + } + } +} + +void +CRenderer::RequestObjectsInFrustum(void) +{ + float f = RwCameraGetFarClipPlane(TheCamera.m_pRwCamera); + RwV2d vw = *RwCameraGetViewWindow(TheCamera.m_pRwCamera); + CVector vectors[9]; + RwMatrix *cammatrix; + RwV2d poly[3]; + + memset(vectors, 0, sizeof(vectors)); + vectors[CORNER_FAR_TOPLEFT].x = -vw.x * f; + vectors[CORNER_FAR_TOPLEFT].y = vw.y * f; + vectors[CORNER_FAR_TOPLEFT].z = f; + vectors[CORNER_FAR_TOPRIGHT].x = vw.x * f; + vectors[CORNER_FAR_TOPRIGHT].y = vw.y * f; + vectors[CORNER_FAR_TOPRIGHT].z = f; + vectors[CORNER_FAR_BOTRIGHT].x = vw.x * f; + vectors[CORNER_FAR_BOTRIGHT].y = -vw.y * f; + vectors[CORNER_FAR_BOTRIGHT].z = f; + vectors[CORNER_FAR_BOTLEFT].x = -vw.x * f; + vectors[CORNER_FAR_BOTLEFT].y = -vw.y * f; + vectors[CORNER_FAR_BOTLEFT].z = f; + + cammatrix = RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera)); + + CWorld::AdvanceCurrentScanCode(); + ms_vecCameraPosition = TheCamera.GetPosition(); + + if(cammatrix->at.z > 0.0f){ + // looking up, bottom corners are further away + vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_BOTLEFT] * LOD_DISTANCE/f; + vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_BOTRIGHT] * LOD_DISTANCE/f; + }else{ + // looking down, top corners are further away + vectors[CORNER_LOD_LEFT] = vectors[CORNER_FAR_TOPLEFT] * LOD_DISTANCE/f; + vectors[CORNER_LOD_RIGHT] = vectors[CORNER_FAR_TOPRIGHT] * LOD_DISTANCE/f; + } + vectors[CORNER_PRIO_LEFT].x = vectors[CORNER_LOD_LEFT].x * 0.2f; + vectors[CORNER_PRIO_LEFT].y = vectors[CORNER_LOD_LEFT].y * 0.2f; + vectors[CORNER_PRIO_LEFT].z = vectors[CORNER_LOD_LEFT].z; + vectors[CORNER_PRIO_RIGHT].x = vectors[CORNER_LOD_RIGHT].x * 0.2f; + vectors[CORNER_PRIO_RIGHT].y = vectors[CORNER_LOD_RIGHT].y * 0.2f; + vectors[CORNER_PRIO_RIGHT].z = vectors[CORNER_LOD_RIGHT].z; + RwV3dTransformPoints(vectors, vectors, 9, cammatrix); + + if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN || +#ifdef FIX_BUGS + TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_GTACLASSIC || +#endif + TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){ + CRect rect; + int x1, x2, y1, y2; + LimitFrustumVector(vectors[CORNER_FAR_TOPLEFT], vectors[CORNER_CAM], -100.0f); + rect.ContainPoint(vectors[CORNER_FAR_TOPLEFT]); + LimitFrustumVector(vectors[CORNER_FAR_TOPRIGHT], vectors[CORNER_CAM], -100.0f); + rect.ContainPoint(vectors[CORNER_FAR_TOPRIGHT]); + LimitFrustumVector(vectors[CORNER_FAR_BOTRIGHT], vectors[CORNER_CAM], -100.0f); + rect.ContainPoint(vectors[CORNER_FAR_BOTRIGHT]); + LimitFrustumVector(vectors[CORNER_FAR_BOTLEFT], vectors[CORNER_CAM], -100.0f); + rect.ContainPoint(vectors[CORNER_FAR_BOTLEFT]); + x1 = CWorld::GetSectorIndexX(rect.left); + if(x1 < 0) x1 = 0; + x2 = CWorld::GetSectorIndexX(rect.right); + if(x2 >= NUMSECTORS_X-1) x2 = NUMSECTORS_X-1; + y1 = CWorld::GetSectorIndexY(rect.top); + if(y1 < 0) y1 = 0; + y2 = CWorld::GetSectorIndexY(rect.bottom); + if(y2 >= NUMSECTORS_Y-1) y2 = NUMSECTORS_Y-1; + for(; x1 <= x2; x1++) + for(int y = y1; y <= y2; y++) + ScanSectorList_RequestModels(CWorld::GetSector(x1, y)->m_lists); + }else{ + poly[0].x = CWorld::GetSectorX(vectors[CORNER_CAM].x); + poly[0].y = CWorld::GetSectorY(vectors[CORNER_CAM].y); + poly[1].x = CWorld::GetSectorX(vectors[CORNER_LOD_LEFT].x); + poly[1].y = CWorld::GetSectorY(vectors[CORNER_LOD_LEFT].y); + poly[2].x = CWorld::GetSectorX(vectors[CORNER_LOD_RIGHT].x); + poly[2].y = CWorld::GetSectorY(vectors[CORNER_LOD_RIGHT].y); + ScanSectorPoly(poly, 3, ScanSectorList_RequestModels); + } +} + +bool +CEntity::SetupLighting(void) +{ + return false; +} + +void +CEntity::RemoveLighting(bool) +{ +} + +bool +CPed::SetupLighting(void) +{ + ActivateDirectional(); + SetAmbientColoursForPedsCarsAndObjects(); + +#ifndef MASTER + // Originally this was being called through iteration of Sectors, but putting it here is better. + if (GetDebugDisplay() != 0 && !IsPlayer()) + DebugRenderOnePedText(); +#endif + + if (bRenderScorched) { + WorldReplaceNormalLightsWithScorched(Scene.world, 0.1f); + } else { + // Note that this lightMult is only affected by LIGHT_DARKEN. If there's no LIGHT_DARKEN, it will be 1.0. + float lightMult = CPointLights::GenerateLightsAffectingObject(&GetPosition()); + if (lightMult != 1.0f) { + SetAmbientAndDirectionalColours(lightMult); + return true; + } + } + return false; +} + +void +CPed::RemoveLighting(bool reset) +{ + if (!bRenderScorched) { + CRenderer::RemoveVehiclePedLights(this, reset); + if (reset) + ReSetAmbientAndDirectionalColours(); + } + SetAmbientColours(); + DeActivateDirectional(); +} + +float +CalcNewDelta(RwV2d *a, RwV2d *b) +{ + return (b->x - a->x) / (b->y - a->y); +} + +#ifdef FIX_BUGS +#define TOINT(x) ((int)Floor(x)) +#else +#define TOINT(x) ((int)(x)) +#endif + +void +CRenderer::ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrList *)) +{ + float miny, maxy; + int y, yend; + int x, xstart, xend; + int i; + int a1, a2, b1, b2; + float deltaA, deltaB; + float xA, xB; + + miny = poly[0].y; + maxy = poly[0].y; + a2 = 0; + xstart = 9999; + xend = -9999; + + for(i = 1; i < numVertices; i++){ + if(poly[i].y > maxy) + maxy = poly[i].y; + if(poly[i].y < miny){ + miny = poly[i].y; + a2 = i; + } + } + y = TOINT(miny); + yend = TOINT(maxy); + + // Go left in poly to find first edge b + b2 = a2; + for(i = 0; i < numVertices; i++){ + b1 = b2--; + if(b2 < 0) b2 = numVertices-1; + if(poly[b1].x < xstart) + xstart = TOINT(poly[b1].x); + if(TOINT(poly[b1].y) != TOINT(poly[b2].y)) + break; + } + // Go right to find first edge a + for(i = 0; i < numVertices; i++){ + a1 = a2++; + if(a2 == numVertices) a2 = 0; + if(poly[a1].x > xend) + xend = TOINT(poly[a1].x); + if(TOINT(poly[a1].y) != TOINT(poly[a2].y)) + break; + } + + // prestep x1 and x2 to next integer y + deltaA = CalcNewDelta(&poly[a1], &poly[a2]); + xA = deltaA * (Ceil(poly[a1].y) - poly[a1].y) + poly[a1].x; + deltaB = CalcNewDelta(&poly[b1], &poly[b2]); + xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x; + + if(y != yend){ + if(deltaB < 0.0f && TOINT(xB) < xstart) + xstart = TOINT(xB); + if(deltaA >= 0.0f && TOINT(xA) > xend) + xend = TOINT(xA); + } + + while(y <= yend && y < NUMSECTORS_Y){ + // scan one x-line + if(y >= 0 && xstart < NUMSECTORS_X) + for(x = xstart; x <= xend && x != NUMSECTORS_X; x++) + if(x >= 0) + scanfunc(CWorld::GetSector(x, y)->m_lists); + + // advance one scan line + y++; + xA += deltaA; + xB += deltaB; + + // update left side + if(y == TOINT(poly[b2].y)){ + // reached end of edge + if(y == yend){ + if(deltaB < 0.0f){ + do{ + xstart = TOINT(poly[b2--].x); + if(b2 < 0) b2 = numVertices-1; + }while(xstart > TOINT(poly[b2].x)); + }else + xstart = TOINT(xB - deltaB); + }else{ + // switch edges + if(deltaB < 0.0f) + xstart = TOINT(poly[b2].x); + else + xstart = TOINT(xB - deltaB); + do{ + b1 = b2--; + if(b2 < 0) b2 = numVertices-1; + if(TOINT(poly[b1].x) < xstart) + xstart = TOINT(poly[b1].x); + }while(y == TOINT(poly[b2].y)); + deltaB = CalcNewDelta(&poly[b1], &poly[b2]); + xB = deltaB * (Ceil(poly[b1].y) - poly[b1].y) + poly[b1].x; + if(deltaB < 0.0f && TOINT(xB) < xstart) + xstart = TOINT(xB); + } + }else{ + if(deltaB < 0.0f) + xstart = TOINT(xB); + else + xstart = TOINT(xB - deltaB); + } + + // update right side + if(y == TOINT(poly[a2].y)){ + // reached end of edge + if(y == yend){ + if(deltaA < 0.0f) + xend = TOINT(xA - deltaA); + else{ + do{ + xend = TOINT(poly[a2++].x); + if(a2 == numVertices) a2 = 0; + }while(xend < TOINT(poly[a2].x)); + } + }else{ + // switch edges + if(deltaA < 0.0f) + xend = TOINT(xA - deltaA); + else + xend = TOINT(poly[a2].x); + do{ + a1 = a2++; + if(a2 == numVertices) a2 = 0; + if(TOINT(poly[a1].x) > xend) + xend = TOINT(poly[a1].x); + }while(y == TOINT(poly[a2].y)); + deltaA = CalcNewDelta(&poly[a1], &poly[a2]); + xA = deltaA * (Ceil(poly[a1].y) - poly[a1].y) + poly[a1].x; + if(deltaA >= 0.0f && TOINT(xA) > xend) + xend = TOINT(xA); + } + }else{ + if(deltaA < 0.0f) + xend = TOINT(xA - deltaA); + else + xend = TOINT(xA); + } + } +} + +void +CRenderer::InsertEntityIntoList(CEntity *ent) +{ +#ifdef FIX_BUGS + if (!ent->m_rwObject) return; +#endif + +#ifdef NEW_RENDERER + // TODO: there are more flags being checked here + if(gbNewRenderer && (ent->IsVehicle() || ent->IsPed())) + ms_aVisibleVehiclePtrs[ms_nNoOfVisibleVehicles++] = ent; + else if(gbNewRenderer && ent->IsBuilding()) + ms_aVisibleBuildingPtrs[ms_nNoOfVisibleBuildings++] = ent; + else +#endif + ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent; +} + +void +CRenderer::ScanBigBuildingList(CPtrList &list) +{ + CPtrNode *node; + CEntity *ent; + int vis; + + int f = CTimer::GetFrameCounter() & 3; + for(node = list.first; node; node = node->next){ + ent = (CEntity*)node->item; + if(ent->bOffscreen || (ent->m_randomSeed&3) != f){ + ent->bOffscreen = true; + vis = SetupBigBuildingVisibility(ent); + }else + vis = VIS_VISIBLE; + switch(vis){ + case VIS_VISIBLE: + InsertEntityIntoList(ent); + ent->bOffscreen = false; + break; + case VIS_STREAMME: + if(!CStreaming::ms_disableStreaming) + CStreaming::RequestModel(ent->GetModelIndex(), 0); + break; + } + } +} + +void +CRenderer::ScanSectorList(CPtrList *lists) +{ + CPtrNode *node; + CPtrList *list; + CEntity *ent; + int i; + float dx, dy; + + for(i = 0; i < NUMSECTORENTITYLISTS; i++){ + list = &lists[i]; + for(node = list->first; node; node = node->next){ + ent = (CEntity*)node->item; + if(ent->m_scanCode == CWorld::GetCurrentScanCode()) + continue; // already seen + ent->m_scanCode = CWorld::GetCurrentScanCode(); + ent->bOffscreen = false; + + switch(SetupEntityVisibility(ent)){ + case VIS_VISIBLE: + InsertEntityIntoList(ent); + break; + case VIS_INVISIBLE: + if(!IsGlass(ent->GetModelIndex())) + break; + // fall through + case VIS_OFFSCREEN: + ent->bOffscreen = true; + dx = ms_vecCameraPosition.x - ent->GetPosition().x; + dy = ms_vecCameraPosition.y - ent->GetPosition().y; + if(dx > -30.0f && dx < 30.0f && + dy > -30.0f && dy < 30.0f && + ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1) + ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent; + break; + case VIS_STREAMME: + if(!CStreaming::ms_disableStreaming) + if(!m_loadingPriority || CStreaming::ms_numModelsRequested < 10) + CStreaming::RequestModel(ent->GetModelIndex(), 0); + break; + } + } + } +} + +void +CRenderer::ScanSectorList_Priority(CPtrList *lists) +{ + CPtrNode *node; + CPtrList *list; + CEntity *ent; + int i; + float dx, dy; + + for(i = 0; i < NUMSECTORENTITYLISTS; i++){ + list = &lists[i]; + for(node = list->first; node; node = node->next){ + ent = (CEntity*)node->item; + if(ent->m_scanCode == CWorld::GetCurrentScanCode()) + continue; // already seen + ent->m_scanCode = CWorld::GetCurrentScanCode(); + ent->bOffscreen = false; + + switch(SetupEntityVisibility(ent)){ + case VIS_VISIBLE: + InsertEntityIntoList(ent); + break; + case VIS_INVISIBLE: + if(!IsGlass(ent->GetModelIndex())) + break; + // fall through + case VIS_OFFSCREEN: + ent->bOffscreen = true; + dx = ms_vecCameraPosition.x - ent->GetPosition().x; + dy = ms_vecCameraPosition.y - ent->GetPosition().y; + if(dx > -30.0f && dx < 30.0f && + dy > -30.0f && dy < 30.0f && + ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1) + ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent; + break; + case VIS_STREAMME: + if(!CStreaming::ms_disableStreaming){ + CStreaming::RequestModel(ent->GetModelIndex(), 0); + if(CStreaming::ms_aInfoForModel[ent->GetModelIndex()].m_loadState != STREAMSTATE_LOADED) + m_loadingPriority = true; + } + break; + } + } + } +} + +#ifdef GTA_TRAIN +void +CRenderer::ScanSectorList_Subway(CPtrList *lists) +{ + CPtrNode *node; + CPtrList *list; + CEntity *ent; + int i; + float dx, dy; + + for(i = 0; i < NUMSECTORENTITYLISTS; i++){ + list = &lists[i]; + for(node = list->first; node; node = node->next){ + ent = (CEntity*)node->item; + if(ent->m_scanCode == CWorld::GetCurrentScanCode()) + continue; // already seen + ent->m_scanCode = CWorld::GetCurrentScanCode(); + ent->bOffscreen = false; + switch(SetupEntityVisibility(ent)){ + case VIS_VISIBLE: + InsertEntityIntoList(ent); + break; + case VIS_OFFSCREEN: + ent->bOffscreen = true; + dx = ms_vecCameraPosition.x - ent->GetPosition().x; + dy = ms_vecCameraPosition.y - ent->GetPosition().y; + if(dx > -30.0f && dx < 30.0f && + dy > -30.0f && dy < 30.0f && + ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1) + ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent; + break; + } + } + } +} +#endif + +void +CRenderer::ScanSectorList_RequestModels(CPtrList *lists) +{ + CPtrNode *node; + CPtrList *list; + CEntity *ent; + int i; + + for(i = 0; i < NUMSECTORENTITYLISTS; i++){ + list = &lists[i]; + for(node = list->first; node; node = node->next){ + ent = (CEntity*)node->item; + if(ent->m_scanCode == CWorld::GetCurrentScanCode()) + continue; // already seen + ent->m_scanCode = CWorld::GetCurrentScanCode(); + if(ShouldModelBeStreamed(ent, ms_vecCameraPosition)) + CStreaming::RequestModel(ent->GetModelIndex(), 0); + } + } +} + +// Put big buildings in front +// This seems pointless because the sector lists shouldn't have big buildings in the first place +void +CRenderer::SortBIGBuildings(void) +{ + int x, y; + for(y = 0; y < NUMSECTORS_Y; y++) + for(x = 0; x < NUMSECTORS_X; x++){ + SortBIGBuildingsForSectorList(&CWorld::GetSector(x, y)->m_lists[ENTITYLIST_BUILDINGS]); + SortBIGBuildingsForSectorList(&CWorld::GetSector(x, y)->m_lists[ENTITYLIST_BUILDINGS_OVERLAP]); + } +} + +void +CRenderer::SortBIGBuildingsForSectorList(CPtrList *list) +{ + CPtrNode *node; + CEntity *ent; + + for(node = list->first; node; node = node->next){ + ent = (CEntity*)node->item; + if(ent->bIsBIGBuilding){ + list->RemoveNode(node); + list->InsertNode(node); + } + } +} + +bool +CRenderer::ShouldModelBeStreamed(CEntity *ent, const CVector &campos) +{ + if(!IsAreaVisible(ent->m_area)) + return false; + CTimeModelInfo *mi = (CTimeModelInfo *)CModelInfo::GetModelInfo(ent->GetModelIndex()); + if(mi->GetModelType() == MITYPE_TIME) + if(!CClock::GetIsTimeInRange(mi->GetTimeOn(), mi->GetTimeOff())) + return false; + float dist = (ent->GetPosition() - campos).Magnitude(); + if(mi->m_noFade) + return dist - STREAM_DISTANCE < mi->GetLargestLodDistance(); + else + return dist - FADE_DISTANCE - STREAM_DISTANCE < mi->GetLargestLodDistance(); +} + +void +CRenderer::RemoveVehiclePedLights(CEntity *ent, bool reset) +{ + if(!ent->bRenderScorched){ + CPointLights::RemoveLightsAffectingObject(); + if(reset) + ReSetAmbientAndDirectionalColours(); + } + SetAmbientColours(); + DeActivateDirectional(); +} diff --git a/src/renderer/Renderer.h b/src/renderer/Renderer.h new file mode 100644 index 00000000..9b202098 --- /dev/null +++ b/src/renderer/Renderer.h @@ -0,0 +1,105 @@ +#pragma once + +class CEntity; + +#ifdef FIX_BUGS +#define LOD_DISTANCE (300.0f*TheCamera.LODDistMultiplier) +#else +#define LOD_DISTANCE 300.0f +#endif +#define FADE_DISTANCE 20.0f +#define STREAM_DISTANCE 30.0f + +extern bool gbShowPedRoadGroups; +extern bool gbShowCarRoadGroups; +extern bool gbShowCollisionPolys; +extern bool gbShowCollisionLines; +extern bool gbBigWhiteDebugLightSwitchedOn; + +extern bool gbDontRenderBuildings; +extern bool gbDontRenderBigBuildings; +extern bool gbDontRenderPeds; +extern bool gbDontRenderObjects; +extern bool gbDontRenderVehicles; + +class CVehicle; +class CPtrList; + +// unused +struct BlockedRange +{ + float a, b; // unknown + BlockedRange *prev, *next; +}; + +class CRenderer +{ + static int32 ms_nNoOfVisibleEntities; + static CEntity *ms_aVisibleEntityPtrs[NUMVISIBLEENTITIES]; + static int32 ms_nNoOfInVisibleEntities; + static CEntity *ms_aInVisibleEntityPtrs[NUMINVISIBLEENTITIES]; +#ifdef NEW_RENDERER + static int32 ms_nNoOfVisibleVehicles; + static CEntity *ms_aVisibleVehiclePtrs[NUMVISIBLEENTITIES]; + // for cWorldStream emulation + static int32 ms_nNoOfVisibleBuildings; + static CEntity *ms_aVisibleBuildingPtrs[NUMVISIBLEENTITIES]; +#endif + + static CVector ms_vecCameraPosition; + static CVehicle *m_pFirstPersonVehicle; + + // unused + static BlockedRange aBlockedRanges[16]; + static BlockedRange *pFullBlockedRanges; + static BlockedRange *pEmptyBlockedRanges; +public: + static float ms_lodDistScale; + static bool m_loadingPriority; + + static void Init(void); + static void Shutdown(void); + static void PreRender(void); + + static void RenderRoads(void); + static void RenderFadingInEntities(void); + static void RenderFadingInUnderwaterEntities(void); + static void RenderEverythingBarRoads(void); + static void RenderBoats(void); + static void RenderOneRoad(CEntity *); + static void RenderOneNonRoad(CEntity *); + static void RenderFirstPersonVehicle(void); + + static void RenderCollisionLines(void); + + static int32 SetupEntityVisibility(CEntity *ent); + static int32 SetupBigBuildingVisibility(CEntity *ent); + + static void ConstructRenderList(void); + static void ScanWorld(void); + static void RequestObjectsInFrustum(void); + static void ScanSectorPoly(RwV2d *poly, int32 numVertices, void (*scanfunc)(CPtrList *)); + static void ScanBigBuildingList(CPtrList &list); + static void ScanSectorList(CPtrList *lists); + static void ScanSectorList_Priority(CPtrList *lists); + static void ScanSectorList_Subway(CPtrList *lists); + static void ScanSectorList_RequestModels(CPtrList *lists); + + static void SortBIGBuildings(void); + static void SortBIGBuildingsForSectorList(CPtrList *list); + + static bool ShouldModelBeStreamed(CEntity *ent, const CVector &campos); + + static void RemoveVehiclePedLights(CEntity *ent, bool reset); + + +#ifdef NEW_RENDERER + static void ClearForFrame(void); + static void RenderPeds(void); + static void RenderVehicles(void); // also renders peds in LCS + static void RenderOneBuilding(CEntity *ent, float camdist = 0.0f); + static void RenderWorld(int pass); // like cWorldStream::Render(int) + static void RenderTransparentWater(void); // keep-out polys and transparent water +#endif + static void InsertEntityIntoList(CEntity *ent); +}; diff --git a/src/renderer/Rubbish.cpp b/src/renderer/Rubbish.cpp new file mode 100644 index 00000000..147c97b1 --- /dev/null +++ b/src/renderer/Rubbish.cpp @@ -0,0 +1,423 @@ +#include "common.h" +#include "main.h" + +#include "General.h" +#include "Timer.h" +#include "Weather.h" +#include "Camera.h" +#include "World.h" +#include "Vehicle.h" +#include "ZoneCull.h" +#include "Stats.h" +#include "TxdStore.h" +#include "RenderBuffer.h" +#include "Rubbish.h" + +#define RUBBISH_MAX_DIST (23.0f) +#define RUBBISH_FADE_DIST (20.0f) + +RwTexture *gpRubbishTexture[4]; +RwImVertexIndex RubbishIndexList[6]; +bool CRubbish::bRubbishInvisible; +int CRubbish::RubbishVisibility; +COneSheet CRubbish::aSheets[NUM_RUBBISH_SHEETS]; +COneSheet CRubbish::StartEmptyList; +COneSheet CRubbish::EndEmptyList; +COneSheet CRubbish::StartStaticsList; +COneSheet CRubbish::EndStaticsList; +COneSheet CRubbish::StartMoversList; +COneSheet CRubbish::EndMoversList; + + +void +COneSheet::AddToList(COneSheet *list) +{ + this->m_next = list->m_next; + this->m_prev = list; + list->m_next = this; + this->m_next->m_prev = this; +} + +void +COneSheet::RemoveFromList(void) +{ + m_next->m_prev = m_prev; + m_prev->m_next = m_next; +} + + +void +CRubbish::Render(void) +{ + int type; + + if(RubbishVisibility == 0) + return; + + PUSH_RENDERGROUP("CRubbish::Render"); + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)TRUE); + + for(type = 0; type < 4; type++){ + if(type < 3 || CStats::PamphletMissionPassed) + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpRubbishTexture[type])); + + TempBufferIndicesStored = 0; + TempBufferVerticesStored = 0; + + COneSheet *sheet; + for(sheet = &aSheets[type*NUM_RUBBISH_SHEETS / 4]; + sheet < &aSheets[(type+1)*NUM_RUBBISH_SHEETS / 4]; + sheet++){ + if(sheet->m_state == 0) + continue; + + uint32 alpha = 100; + CVector pos; + if(sheet->m_state == 1){ + pos = sheet->m_basePos; + if(!sheet->m_isVisible) + alpha = 0; + }else{ + pos = sheet->m_animatedPos; + // Not fully visible during animation, calculate current alpha + if(!sheet->m_isVisible || !sheet->m_targetIsVisible){ + float t = (float)(CTimer::GetTimeInMilliseconds() - sheet->m_moveStart)/sheet->m_moveDuration; + float f1 = sheet->m_isVisible ? 1.0f-t : 0.0f; + float f2 = sheet->m_targetIsVisible ? t : 0.0f; + alpha = 100 * (f1+f2); + } + } + + float camDist = (pos - TheCamera.GetPosition()).Magnitude2D(); + if(camDist < RUBBISH_MAX_DIST){ + if(camDist >= RUBBISH_FADE_DIST) + alpha -= alpha*(camDist-RUBBISH_FADE_DIST)/(RUBBISH_MAX_DIST-RUBBISH_FADE_DIST); + alpha = (RubbishVisibility*alpha)/256; + + float vx1, vy1, vx2, vy2; + if(type == 0 || type == 1){ + vx1 = 0.9f*Sin(sheet->m_angle); + vy1 = 0.9f*Cos(sheet->m_angle); + vx2 = 0.3f*Cos(sheet->m_angle); + vy2 = -0.3f*Sin(sheet->m_angle); + }else{ + vx1 = 0.3f*Sin(sheet->m_angle); + vy1 = 0.3f*Cos(sheet->m_angle); + vx2 = 0.3f*Cos(sheet->m_angle); + vy2 = -0.3f*Sin(sheet->m_angle); + } + + int v = TempBufferVerticesStored; + RwIm3DVertexSetPos(&TempBufferRenderVertices[v+0], pos.x + vx1 + vx2, pos.y + vy1 + vy2, pos.z); + RwIm3DVertexSetPos(&TempBufferRenderVertices[v+1], pos.x + vx1 - vx2, pos.y + vy1 - vy2, pos.z); + RwIm3DVertexSetPos(&TempBufferRenderVertices[v+2], pos.x - vx1 + vx2, pos.y - vy1 + vy2, pos.z); + RwIm3DVertexSetPos(&TempBufferRenderVertices[v+3], pos.x - vx1 - vx2, pos.y - vy1 - vy2, pos.z); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+0], 255, 255, 255, alpha); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+1], 255, 255, 255, alpha); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+2], 255, 255, 255, alpha); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+3], 255, 255, 255, alpha); + RwIm3DVertexSetU(&TempBufferRenderVertices[v+0], 0.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[v+0], 0.0f); + RwIm3DVertexSetU(&TempBufferRenderVertices[v+1], 1.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[v+1], 0.0f); + RwIm3DVertexSetU(&TempBufferRenderVertices[v+2], 0.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[v+2], 1.0f); + RwIm3DVertexSetU(&TempBufferRenderVertices[v+3], 1.0f); + RwIm3DVertexSetV(&TempBufferRenderVertices[v+3], 1.0f); + + int i = TempBufferIndicesStored; + TempBufferRenderIndexList[i+0] = RubbishIndexList[0] + TempBufferVerticesStored; + TempBufferRenderIndexList[i+1] = RubbishIndexList[1] + TempBufferVerticesStored; + TempBufferRenderIndexList[i+2] = RubbishIndexList[2] + TempBufferVerticesStored; + TempBufferRenderIndexList[i+3] = RubbishIndexList[3] + TempBufferVerticesStored; + TempBufferRenderIndexList[i+4] = RubbishIndexList[4] + TempBufferVerticesStored; + TempBufferRenderIndexList[i+5] = RubbishIndexList[5] + TempBufferVerticesStored; + TempBufferVerticesStored += 4; + TempBufferIndicesStored += 6; + } + } + + if(TempBufferIndicesStored != 0){ + LittleTest(); + if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV)){ + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); + RwIm3DEnd(); + } + } + } + + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + + POP_RENDERGROUP(); +} + +void +CRubbish::StirUp(CVehicle *veh) +{ + if((CTimer::GetFrameCounter() ^ (veh->m_randomSeed&3)) == 0) + return; + + if(Abs(veh->GetPosition().x - TheCamera.GetPosition().x) < 20.0f && + Abs(veh->GetPosition().y - TheCamera.GetPosition().y) < 20.0f) + if(Abs(veh->GetMoveSpeed().x) > 0.05f || Abs(veh->GetMoveSpeed().y) > 0.05f){ + float speed = veh->GetMoveSpeed().Magnitude2D(); + if(speed > 0.05f){ + bool movingForward = DotProduct2D(veh->GetMoveSpeed(), veh->GetForward()) > 0.0f; + COneSheet *sheet = StartStaticsList.m_next; + CVector2D size = veh->GetColModel()->boundingBox.max; + + // Check all static sheets + while(sheet != &EndStaticsList){ + COneSheet *next = sheet->m_next; + CVector2D carToSheet = sheet->m_basePos - veh->GetPosition(); + float distFwd = DotProduct2D(carToSheet, veh->GetForward()); + + // sheet has to be a bit behind car + if(movingForward && distFwd < -0.5f*size.y && distFwd > -1.5f*size.y || + !movingForward && distFwd > 0.5f*size.y && distFwd < 1.5f*size.y){ + float distSide = Abs(DotProduct2D(carToSheet, veh->GetRight())); + if(distSide < 1.5*size.x){ + // Check with higher speed for sheet directly behind car + float speedToCheck = distSide < size.x ? speed : speed*0.5f; + if(speedToCheck > 0.05f){ + sheet->m_state = 2; + if(speedToCheck > 0.15f) + sheet->m_animationType = 2; + else + sheet->m_animationType = 1; + sheet->m_moveDuration = 2000; + sheet->m_xDist = veh->GetMoveSpeed().x; + sheet->m_yDist = veh->GetMoveSpeed().y; + float dist = Sqrt(SQR(sheet->m_xDist)+SQR(sheet->m_yDist)); + sheet->m_xDist *= 25.0f*speed/dist; + sheet->m_yDist *= 25.0f*speed/dist; + sheet->m_animHeight = 3.0f*speed; + sheet->m_moveStart = CTimer::GetTimeInMilliseconds(); + float tx = sheet->m_basePos.x + sheet->m_xDist; + float ty = sheet->m_basePos.y + sheet->m_yDist; + float tz = sheet->m_basePos.z + 3.0f; + sheet->m_targetZ = CWorld::FindGroundZFor3DCoord(tx, ty, tz, nil) + 0.1f; + sheet->RemoveFromList(); + sheet->AddToList(&StartMoversList); + } + } + } + + sheet = next; + } + } + } +} + +static float aAnimations[3][34] = { + { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, + + // Normal move + { 0.0f, 0.05f, 0.12f, 0.25f, 0.42f, 0.57f, 0.68f, 0.8f, 0.86f, 0.9f, 0.93f, 0.95f, 0.96f, 0.97f, 0.98f, 0.99f, 1.0f, // XY movemnt + 0.15f, 0.35f, 0.6f, 0.9f, 1.2f, 1.25f, 1.3f, 1.2f, 1.1f, 0.95f, 0.8f, 0.6f, 0.45f, 0.3f, 0.2f, 0.1f, 0 }, // Z movement + + // Stirred up by fast vehicle + { 0.0f, 0.05f, 0.12f, 0.25f, 0.42f, 0.57f, 0.68f, 0.8f, 0.95f, 1.1f, 1.15f, 1.18f, 1.15f, 1.1f, 1.05f, 1.03f, 1.0f, + 0.15f, 0.35f, 0.6f, 0.9f, 1.2f, 1.25f, 1.3f, 1.2f, 1.1f, 0.95f, 0.8f, 0.6f, 0.45f, 0.3f, 0.2f, 0.1f, 0 } +}; + +void +CRubbish::Update(void) +{ + bool foundGround; + + // FRAMETIME + if(bRubbishInvisible) + RubbishVisibility = Max(RubbishVisibility-5, 0); + else + RubbishVisibility = Min(RubbishVisibility+5, 255); + + // Spawn a new sheet + COneSheet *sheet = StartEmptyList.m_next; + if(sheet != &EndEmptyList){ + float spawnDist; + float spawnAngle; + + spawnDist = (CGeneral::GetRandomNumber()&0xFF)/256.0f + RUBBISH_MAX_DIST; + uint8 r = CGeneral::GetRandomNumber(); + if(r&1) + spawnAngle = (CGeneral::GetRandomNumber()&0xFF)/256.0f * 6.28f; + else + spawnAngle = (r-128)/160.0f + TheCamera.Orientation; + sheet->m_basePos.x = TheCamera.GetPosition().x + spawnDist*Sin(spawnAngle); + sheet->m_basePos.y = TheCamera.GetPosition().y + spawnDist*Cos(spawnAngle); + sheet->m_basePos.z = CWorld::FindGroundZFor3DCoord(sheet->m_basePos.x, sheet->m_basePos.y, TheCamera.GetPosition().z, &foundGround) + 0.1f; + if(foundGround){ + // Found ground, so add to statics list + sheet->m_angle = (CGeneral::GetRandomNumber()&0xFF)/256.0f * 6.28f; + sheet->m_state = 1; + if(CCullZones::FindAttributesForCoors(sheet->m_basePos, nil) & ATTRZONE_NORAIN) + sheet->m_isVisible = false; + else + sheet->m_isVisible = true; + sheet->RemoveFromList(); + sheet->AddToList(&StartStaticsList); + } + } + + // Process animation + sheet = StartMoversList.m_next; + while(sheet != &EndMoversList){ + uint32 currentTime = CTimer::GetTimeInMilliseconds() - sheet->m_moveStart; + if(currentTime < sheet->m_moveDuration){ + // Animation + int step = 16 * currentTime / sheet->m_moveDuration; // 16 steps in animation + int stepTime = sheet->m_moveDuration/16; // time in each step + float s = (float)(currentTime - stepTime*step) / stepTime; // position on step + float t = (float)currentTime / sheet->m_moveDuration; // position on total animation + // factors for xy and z-movment + float fxy = aAnimations[sheet->m_animationType][step]*(1.0f-s) + aAnimations[sheet->m_animationType][step+1]*s; + float fz = aAnimations[sheet->m_animationType][step+17]*(1.0f-s) + aAnimations[sheet->m_animationType][step+1+17]*s; + sheet->m_animatedPos.x = sheet->m_basePos.x + fxy*sheet->m_xDist; + sheet->m_animatedPos.y = sheet->m_basePos.y + fxy*sheet->m_yDist; + sheet->m_animatedPos.z = (1.0f-t)*sheet->m_basePos.z + t*sheet->m_targetZ + fz*sheet->m_animHeight; + sheet->m_angle += CTimer::GetTimeStep()*0.04f; + if(sheet->m_angle > 6.28f) + sheet->m_angle -= 6.28f; + sheet = sheet->m_next; + }else{ + // End of animation, back into statics list + sheet->m_basePos.x += sheet->m_xDist; + sheet->m_basePos.y += sheet->m_yDist; + sheet->m_basePos.z = sheet->m_targetZ; + sheet->m_state = 1; + sheet->m_isVisible = sheet->m_targetIsVisible; + + COneSheet *next = sheet->m_next; + sheet->RemoveFromList(); + sheet->AddToList(&StartStaticsList); + sheet = next; + } + } + + // Stir up a sheet by wind + // FRAMETIME + int freq; + if(CWeather::Wind < 0.1f) + freq = 31; + else if(CWeather::Wind < 0.4f) + freq = 7; + else if(CWeather::Wind < 0.7f) + freq = 1; + else + freq = 0; + if((CTimer::GetFrameCounter() & freq) == 0){ + // Pick a random sheet and set animation state if static + int i = CGeneral::GetRandomNumber() % NUM_RUBBISH_SHEETS; + if(aSheets[i].m_state == 1){ + aSheets[i].m_moveStart = CTimer::GetTimeInMilliseconds(); + aSheets[i].m_moveDuration = CWeather::Wind*1500.0f + 1000.0f; + aSheets[i].m_animHeight = 0.2f; + aSheets[i].m_xDist = 3.0f*CWeather::Wind; + aSheets[i].m_yDist = 3.0f*CWeather::Wind; + // Check if target position is ok + float tx = aSheets[i].m_basePos.x + aSheets[i].m_xDist; + float ty = aSheets[i].m_basePos.y + aSheets[i].m_yDist; + float tz = aSheets[i].m_basePos.z + 3.0f; + aSheets[i].m_targetZ = CWorld::FindGroundZFor3DCoord(tx, ty, tz, &foundGround) + 0.1f; + if(CCullZones::FindAttributesForCoors(CVector(tx, ty, aSheets[i].m_targetZ), nil) & ATTRZONE_NORAIN) + aSheets[i].m_targetIsVisible = false; + else + aSheets[i].m_targetIsVisible = true; + if(foundGround){ + // start animation + aSheets[i].m_state = 2; + aSheets[i].m_animationType = 1; + aSheets[i].RemoveFromList(); + aSheets[i].AddToList(&StartMoversList); + } + } + } + + // Remove sheets that are too far away + int i = (CTimer::GetFrameCounter()%(NUM_RUBBISH_SHEETS/4))*4; + int last = ((CTimer::GetFrameCounter()%(NUM_RUBBISH_SHEETS/4)) + 1)*4; + for(; i < last; i++){ + if(aSheets[i].m_state == 1 && + (aSheets[i].m_basePos - TheCamera.GetPosition()).MagnitudeSqr2D() > SQR(RUBBISH_MAX_DIST+1.0f)){ + aSheets[i].m_state = 0; + aSheets[i].RemoveFromList(); + aSheets[i].AddToList(&StartEmptyList); + } + } +} + +void +CRubbish::SetVisibility(bool visible) +{ + bRubbishInvisible = !visible; +} + +void +CRubbish::Init(void) +{ + int i; + for(i = 0; i < NUM_RUBBISH_SHEETS; i++){ + aSheets[i].m_state = 0; + if(i < NUM_RUBBISH_SHEETS-1) + aSheets[i].m_next = &aSheets[i+1]; + else + aSheets[i].m_next = &EndEmptyList; + if(i > 0) + aSheets[i].m_prev = &aSheets[i-1]; + else + aSheets[i].m_prev = &StartEmptyList; + } + + StartEmptyList.m_next = &aSheets[0]; + StartEmptyList.m_prev = nil; + EndEmptyList.m_next = nil; + EndEmptyList.m_prev = &aSheets[NUM_RUBBISH_SHEETS-1]; + + StartStaticsList.m_next = &EndStaticsList; + StartStaticsList.m_prev = nil; + EndStaticsList.m_next = nil; + EndStaticsList.m_prev = &StartStaticsList; + + StartMoversList.m_next = &EndMoversList; + StartMoversList.m_prev = nil; + EndMoversList.m_next = nil; + EndMoversList.m_prev = &StartMoversList; + + RubbishIndexList[0] = 0; + RubbishIndexList[1] = 1; + RubbishIndexList[2] = 2; + RubbishIndexList[3] = 1; + RubbishIndexList[4] = 3; + RubbishIndexList[5] = 2; + + CTxdStore::PushCurrentTxd(); + int slot = CTxdStore::FindTxdSlot("particle"); + CTxdStore::SetCurrentTxd(slot); + gpRubbishTexture[0] = RwTextureRead("gameleaf01_64", nil); + gpRubbishTexture[1] = RwTextureRead("gameleaf02_64", nil); + gpRubbishTexture[2] = RwTextureRead("newspaper01_64", nil); + gpRubbishTexture[3] = RwTextureRead("newspaper02_64", nil); + CTxdStore::PopCurrentTxd(); + RubbishVisibility = 255; + bRubbishInvisible = false; +} + +void +CRubbish::Shutdown(void) +{ + RwTextureDestroy(gpRubbishTexture[0]); + gpRubbishTexture[0] = nil; + RwTextureDestroy(gpRubbishTexture[1]); + gpRubbishTexture[1] = nil; + RwTextureDestroy(gpRubbishTexture[2]); + gpRubbishTexture[2] = nil; + RwTextureDestroy(gpRubbishTexture[3]); + gpRubbishTexture[3] = nil; +} diff --git a/src/renderer/Rubbish.h b/src/renderer/Rubbish.h new file mode 100644 index 00000000..5a4e479b --- /dev/null +++ b/src/renderer/Rubbish.h @@ -0,0 +1,57 @@ +#pragma once + +class CVehicle; + +enum { + // NB: not all values are allowed, check the code +#ifdef SQUEEZE_PERFORMANCE + NUM_RUBBISH_SHEETS = 32 +#else + NUM_RUBBISH_SHEETS = 64 +#endif +}; + +class COneSheet +{ +public: + CVector m_basePos; + CVector m_animatedPos; + float m_targetZ; + int8 m_state; + int8 m_animationType; + uint32 m_moveStart; + uint32 m_moveDuration; + float m_animHeight; + float m_xDist; + float m_yDist; + float m_angle; + bool m_isVisible; + bool m_targetIsVisible; + COneSheet *m_next; + COneSheet *m_prev; + + void AddToList(COneSheet *list); + void RemoveFromList(void); +}; + +class CRubbish +{ + static bool bRubbishInvisible; + static int RubbishVisibility; + static COneSheet aSheets[NUM_RUBBISH_SHEETS]; + static COneSheet StartEmptyList; + static COneSheet EndEmptyList; + static COneSheet StartStaticsList; + static COneSheet EndStaticsList; + static COneSheet StartMoversList; + static COneSheet EndMoversList; +public: + static void Render(void); + static void StirUp(CVehicle *veh); // CAutomobile on PS2 + static void Update(void); + static void SetVisibility(bool visible); + static void Init(void); + static void Shutdown(void); +}; + +extern RwTexture *gpRubbishTexture[4]; diff --git a/src/renderer/ShadowCamera.cpp b/src/renderer/ShadowCamera.cpp new file mode 100644 index 00000000..f69c234f --- /dev/null +++ b/src/renderer/ShadowCamera.cpp @@ -0,0 +1,549 @@ +#include "common.h" +#include "rwcore.h" +#include "ShadowCamera.h" +#include "RwHelper.h" + +#define TEXELOFFSET 0.5f + +RpAtomic *ShadowRenderCallBack(RpAtomic *atomic, void *data) +{ + RpAtomicCallBackRender savedCB = RpAtomicGetRenderCallBack(atomic); + RpAtomicSetRenderCallBack(atomic, AtomicDefaultRenderCallBack); + RpAtomicRender(atomic); + RpAtomicSetRenderCallBack(atomic, savedCB); + return atomic; +} + +CShadowCamera::CShadowCamera() +{ + m_pCamera = nil; + m_pTexture = nil; +} + +CShadowCamera::~CShadowCamera() +{ + Destroy(); +} + +void +CShadowCamera::Destroy() +{ + if ( m_pCamera ) + { + RwRaster *raster; + RwFrame *frame; + + frame = RwCameraGetFrame(m_pCamera); + + if ( frame ) + { + RwCameraSetFrame(m_pCamera, nil); + RwFrameDestroy(frame); + } + + raster = RwCameraGetZRaster(m_pCamera); + if ( raster ) + { + RwCameraSetZRaster(m_pCamera, nil); + RwRasterDestroy(raster); + } + + raster = RwCameraGetRaster(m_pCamera); + if ( raster ) + { + RwCameraSetRaster(m_pCamera, nil); + RwRasterDestroy(raster); + } + + if ( m_pTexture ) + { + RwTextureSetRaster(m_pTexture, nil); + RwTextureDestroy(m_pTexture); + m_pTexture = nil; + } + + RwCameraDestroy(m_pCamera); + m_pCamera = nil; + } + return; +} + +RwCamera * +CShadowCamera::Create(int32 rasterSize) +{ + int32 size = 1 << rasterSize; + + m_pCamera = RwCameraCreate(); + ASSERT(m_pCamera != nil); + + if ( m_pCamera ) + { + RwCameraSetFrame(m_pCamera, RwFrameCreate()); + + if( RwCameraGetFrame(m_pCamera) ) + { + RwRaster *zRaster = RwRasterCreate(size, size, 0, rwRASTERTYPEZBUFFER); + ASSERT(zRaster != nil); + + if ( zRaster ) + { + RwCameraSetZRaster(m_pCamera, zRaster); + + RwRaster *raster = RwRasterCreate(size, size, 0, rwRASTERTYPECAMERATEXTURE); + ASSERT(raster != nil); + + if ( raster ) + { + RwCameraSetRaster(m_pCamera, raster); + m_pTexture = RwTextureCreate(raster); + ASSERT(m_pTexture != nil); + + if ( m_pTexture ) + { + RwTextureSetAddressing(m_pTexture, rwTEXTUREADDRESSCLAMP); + RwTextureSetFilterMode(m_pTexture, rwFILTERLINEAR); + RwCameraSetProjection(m_pCamera, rwPARALLEL); + return (m_pCamera); + } + } + } + } + } + + Destroy(); + + return (nil); +} + +RwCamera * +CShadowCamera::SetFrustum(float objectRadius) +{ + ASSERT(m_pCamera != nil); + + RwV2d vw; + + RwCameraSetFarClipPlane (m_pCamera, 2.0f * objectRadius); + RwCameraSetNearClipPlane(m_pCamera, 0.001f * objectRadius); + + vw.x = objectRadius; + vw.y = objectRadius; + RwCameraSetViewWindow(m_pCamera, &vw); + + return m_pCamera; +} + +RwCamera * +CShadowCamera::SetLight(RpLight *light) +{ + ASSERT(light != nil); + ASSERT(m_pCamera != nil); + + RwFrame *camFrame = RwCameraGetFrame(m_pCamera); + RwMatrix *camMatrix = RwFrameGetMatrix(camFrame); + RwFrame *lightFrame = RpLightGetFrame(light); + RwMatrix *lightMatrix = RwFrameGetMatrix(lightFrame); + + *RwMatrixGetRight(camMatrix) = *RwMatrixGetRight(lightMatrix); + *RwMatrixGetUp(camMatrix) = *RwMatrixGetUp(lightMatrix); + *RwMatrixGetAt(camMatrix) = *RwMatrixGetAt(lightMatrix); + + RwMatrixUpdate(camMatrix); + RwFrameUpdateObjects(camFrame); + + return m_pCamera; +} + +RwCamera * +CShadowCamera::SetCenter(RwV3d *center) +{ + ASSERT(center != nil); + ASSERT(m_pCamera != nil); + + RwFrame *camFrame = RwCameraGetFrame(m_pCamera); + RwMatrix *camMatrix = RwFrameGetMatrix(camFrame); + + *RwMatrixGetPos(camMatrix) = *center; + + RwV3dIncrementScaled(RwMatrixGetPos(camMatrix), RwMatrixGetAt(camMatrix), -0.5f * RwCameraGetFarClipPlane(m_pCamera)); + + RwMatrixUpdate(camMatrix); + RwFrameUpdateObjects(camFrame); + RwFrameOrthoNormalize(camFrame); + + return m_pCamera; +} + +RwCamera * +CShadowCamera::Update(RpClump *clump) +{ + ASSERT(clump != nil); + ASSERT(m_pCamera != nil); + + RwUInt32 flags; + RpGeometry *geometry; + + RwRGBA bgColor = { 255, 255, 255, 0 }; + + RwCameraClear(m_pCamera, &bgColor, rwCAMERACLEARZ | rwCAMERACLEARIMAGE); + + if ( RwCameraBeginUpdate(m_pCamera) ) + { + geometry = RpAtomicGetGeometry(GetFirstAtomic(clump)); + ASSERT(geometry != nil); + + flags = RpGeometryGetFlags(geometry); + + RpGeometrySetFlags(geometry, flags & ~(rpGEOMETRYPRELIT|rpGEOMETRYLIGHT + |rpGEOMETRYTEXTURED|rpGEOMETRYTEXTURED2|rpGEOMETRYMODULATEMATERIALCOLOR)); + + RpClumpForAllAtomics(clump, ShadowRenderCallBack, nil); + + RpGeometrySetFlags(geometry, flags); + + InvertRaster(); + RwCameraEndUpdate(m_pCamera); + } + + return m_pCamera; +} + +RwCamera * +CShadowCamera::Update(RpAtomic *atomic) +{ + ASSERT(atomic != nil); + ASSERT(m_pCamera != nil); + + RwUInt32 flags; + RpGeometry *geometry; + + RwRGBA bgColor = { 255, 255, 255, 0 }; + + RwCameraClear(m_pCamera, &bgColor, rwCAMERACLEARZ | rwCAMERACLEARIMAGE); + + if ( RwCameraBeginUpdate(m_pCamera) ) + { + geometry = RpAtomicGetGeometry(atomic); + ASSERT(geometry != nil); + flags = RpGeometryGetFlags(geometry); + + RpGeometrySetFlags(geometry, flags & ~(rpGEOMETRYPRELIT|rpGEOMETRYLIGHT + |rpGEOMETRYTEXTURED|rpGEOMETRYTEXTURED2|rpGEOMETRYMODULATEMATERIALCOLOR|rpGEOMETRYNORMALS)); + + ShadowRenderCallBack(atomic, nil); + + RpGeometrySetFlags(geometry, flags); + + InvertRaster(); + RwCameraEndUpdate(m_pCamera); + } + + return m_pCamera; +} + +void +CShadowCamera::InvertRaster() +{ + ASSERT(m_pCamera != nil); + + RwIm2DVertex vx[4]; + float crw, crh; + RwRaster *raster; + float recipZ; + + raster = RwCameraGetRaster(m_pCamera); + ASSERT(raster != nil); + + crw = (float)RwRasterGetWidth(raster); + crh = (float)RwRasterGetHeight(raster); + + recipZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); + + RwIm2DVertexSetScreenX (&vx[0], 0.0f); + RwIm2DVertexSetScreenY (&vx[0], 0.0f); + RwIm2DVertexSetScreenZ (&vx[0], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetRecipCameraZ(&vx[0], recipZ); + RwIm2DVertexSetIntRGBA (&vx[0], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX (&vx[1], 0.0f); + RwIm2DVertexSetScreenY (&vx[1], crh); + RwIm2DVertexSetScreenZ (&vx[1], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetRecipCameraZ(&vx[1], recipZ); + RwIm2DVertexSetIntRGBA (&vx[1], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX (&vx[2], crw); + RwIm2DVertexSetScreenY (&vx[2], 0.0f); + RwIm2DVertexSetScreenZ (&vx[2], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetRecipCameraZ(&vx[2], recipZ); + RwIm2DVertexSetIntRGBA (&vx[2], 255, 255, 255, 255); + + RwIm2DVertexSetScreenX (&vx[3], crw); + RwIm2DVertexSetScreenY (&vx[3], crh); + RwIm2DVertexSetScreenZ (&vx[3], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetRecipCameraZ(&vx[3], recipZ); + RwIm2DVertexSetIntRGBA (&vx[3], 255, 255, 255, 255); + + + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)nil); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDINVDESTCOLOR); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO); + + RwIm2DRenderPrimitive(rwPRIMTYPETRISTRIP, vx, 4); + + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); +} + +RwRaster * +CShadowCamera::MakeGradientRaster() +{ + ASSERT(m_pCamera != nil); + + RwIm2DVertex vx[2]; + + if ( !m_pCamera ) + return nil; + + float recipCamZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); + + RwRaster *raster = RwCameraGetRaster(m_pCamera); + ASSERT(raster != nil); + + float width = (float)RwRasterGetWidth(raster); + float height = (float)RwRasterGetHeight(raster); + + if ( height < 1 ) + return nil; + + if ( RwCameraBeginUpdate(m_pCamera) ) + { + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)rwFILTERNAFILTERMODE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDINVDESTCOLOR); + RwRenderStateSet(rwRENDERSTATESHADEMODE, (void *)rwSHADEMODEFLAT); + + float color = 255.0f; + float step = (-191.0f / height); + + for ( int32 i = 0; i < height; i++ ) + { + RwIm2DVertexSetScreenX (&vx[0], 0.0f); + RwIm2DVertexSetScreenY (&vx[0], i); + RwIm2DVertexSetScreenZ (&vx[0], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetRecipCameraZ(&vx[0], recipCamZ); + RwIm2DVertexSetIntRGBA (&vx[0], (uint32)color, (uint32)color, (uint32)color, (uint32)color); + + RwIm2DVertexSetScreenX (&vx[1], width - 1); + RwIm2DVertexSetScreenY (&vx[1], i); + RwIm2DVertexSetScreenZ (&vx[1], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetRecipCameraZ(&vx[1], recipCamZ); + RwIm2DVertexSetIntRGBA (&vx[1], (uint32)color, (uint32)color, (uint32)color, (uint32)color); + + RwIm2DRenderLine(vx, 2, 0, 1); + + color += step; + } + + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATESHADEMODE, (void *)rwSHADEMODEGOURAUD); + + RwCameraEndUpdate(m_pCamera); + } + + return raster; +} + +RwRaster * +CShadowCamera::RasterResample(RwRaster *dstRaster) +{ + ASSERT(dstRaster != nil); + ASSERT(m_pCamera != nil); + + if ( !m_pCamera ) + return nil; + + RwRaster *raster = RwCameraGetRaster(m_pCamera); + ASSERT(raster != nil); + + float size = (float) RwRasterGetWidth(raster); + float uvOffset = TEXELOFFSET / size; + float recipCamZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); + + if ( RwCameraBeginUpdate(m_pCamera) ) + { + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)dstRaster); + + Im2DRenderQuad(0.0f, 0.0f, size, size, RwIm2DGetNearScreenZ(), recipCamZ, uvOffset); + + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + + RwCameraEndUpdate(m_pCamera); + } + + return raster; +} + +RwRaster * +CShadowCamera::RasterBlur(RwRaster *dstRaster, int32 numPasses) +{ + ASSERT(dstRaster != nil); + ASSERT(m_pCamera != nil); + + if ( !m_pCamera ) + return nil; + + RwRaster *raster = RwCameraGetRaster(m_pCamera); + ASSERT(raster != nil); + + float size = (float) RwRasterGetWidth(dstRaster); + float recipCamZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); + + for (int i = 0; i < numPasses; i++ ) + { + RwCameraSetRaster(m_pCamera, raster); + + if ( RwCameraBeginUpdate(m_pCamera) ) + { + if ( i == 0 ) + { + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR); + } + + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)dstRaster); + Im2DRenderQuad(0.0f, 0.0f, size, size, RwIm2DGetNearScreenZ(), recipCamZ, 1.0f / size); + RwCameraEndUpdate(m_pCamera); + } + + RwCameraSetRaster(m_pCamera, dstRaster); + + if ( RwCameraBeginUpdate(m_pCamera) ) + { + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)raster); + Im2DRenderQuad(0.0f, 0.0f, size, size, RwIm2DGetNearScreenZ(), recipCamZ, 0); + + if ( i == numPasses - 1 ) + { + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + } + + RwCameraEndUpdate(m_pCamera); + } + } + + RwCameraSetRaster(m_pCamera, raster); + + return dstRaster; +} + +RwRaster * +CShadowCamera::RasterGradient(RwRaster *dstRaster) +{ + ASSERT(dstRaster != nil); + ASSERT(m_pCamera != nil); + + RwRaster *raster = RwCameraGetRaster(m_pCamera); + ASSERT(raster != nil); + + float size = (float)RwRasterGetWidth(dstRaster); + float recipCamZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); + + RwCameraSetRaster(m_pCamera, dstRaster); + + if ( RwCameraBeginUpdate(m_pCamera) ) + { + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDZERO); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDSRCCOLOR); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)raster); + + Im2DRenderQuad(0, 0, size, size, RwIm2DGetNearScreenZ(), recipCamZ, 0); + + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + + RwCameraEndUpdate(m_pCamera); + } + + RwCameraSetRaster(m_pCamera, raster); + + return dstRaster; +} + +RwRaster *CShadowCamera::DrawOutlineBorder(RwRGBA const& color) +{ + ASSERT(m_pCamera != nil); + + RwIm2DVertex vx[4]; + RwImVertexIndex ix[5]; + + RwRaster *raster = RwCameraGetRaster(m_pCamera); + ASSERT(raster != nil); + + float size = (float)RwRasterGetWidth(raster) - 1.0f; + float recipCamZ = 1.0f / RwCameraGetNearClipPlane(m_pCamera); + + RwIm2DVertexSetScreenX (&vx[0], 0.0f); + RwIm2DVertexSetScreenY (&vx[0], 0.0f); + RwIm2DVertexSetScreenZ (&vx[0], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetIntRGBA (&vx[0], color.red, color.green, color.blue, color.alpha); + RwIm2DVertexSetRecipCameraZ(&vx[0], recipCamZ); + + RwIm2DVertexSetScreenX (&vx[1], size); + RwIm2DVertexSetScreenY (&vx[1], 0.0f); + RwIm2DVertexSetScreenZ (&vx[1], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetIntRGBA (&vx[1], color.red, color.green, color.blue, color.alpha); + RwIm2DVertexSetRecipCameraZ(&vx[1], recipCamZ); + + RwIm2DVertexSetScreenX (&vx[2], size); + RwIm2DVertexSetScreenY (&vx[2], size); + RwIm2DVertexSetScreenZ (&vx[2], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetIntRGBA (&vx[2], color.red, color.green, color.blue, color.alpha); + RwIm2DVertexSetRecipCameraZ(&vx[2], recipCamZ); + + RwIm2DVertexSetScreenX (&vx[3], 0.0f); + RwIm2DVertexSetScreenY (&vx[3], size); + RwIm2DVertexSetScreenZ (&vx[3], RwIm2DGetNearScreenZ()); + RwIm2DVertexSetIntRGBA (&vx[3], color.red, color.green, color.blue, color.alpha); + RwIm2DVertexSetRecipCameraZ(&vx[3], recipCamZ); + + ix[0] = 0; + ix[4] = 0; + ix[1] = 1; + ix[2] = 2; + ix[3] = 3; + + if ( RwCameraBeginUpdate(m_pCamera) ) + { + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)nil); + + RwIm2DRenderIndexedPrimitive(rwPRIMTYPEPOLYLINE, vx, 4, ix, 5); + + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); + + RwCameraEndUpdate(m_pCamera); + } + + return raster; +} \ No newline at end of file diff --git a/src/renderer/ShadowCamera.h b/src/renderer/ShadowCamera.h new file mode 100644 index 00000000..a2149db7 --- /dev/null +++ b/src/renderer/ShadowCamera.h @@ -0,0 +1,54 @@ +#pragma once + + +class CShadowCamera +{ +public: + RwCamera *m_pCamera; + RwTexture *m_pTexture; + + CShadowCamera(); + ~CShadowCamera(); + + RwCamera *Create(int32 rasterSize); + void Destroy(); + + RwCamera *SetFrustum(float objectRadius); + RwCamera *SetLight(RpLight *light); + RwCamera *SetCenter(RwV3d *center); + + RwCamera *Update(RpClump *clump); + RwCamera *Update(RpAtomic *atomic); + + void InvertRaster(); + + RwRaster* GetRwRenderRaster() + { + return RwCameraGetRaster(m_pCamera); + } + + // ShadowRasterRender(RwV2d *) + // ApplyAlphaMapToRaster(void) + + RwRaster *MakeGradientRaster(); + + RwTexture *GetRwRenderTexture() + { + return m_pTexture; + } + + RwRaster* GetRwZRaster() + { + return RwCameraGetZRaster(m_pCamera); + } + + RwRaster *RasterResample(RwRaster *dstRaster); + RwRaster *RasterBlur(RwRaster *dstRaster, int32 numPasses); + RwRaster *RasterGradient(RwRaster *dstRaster); + RwRaster *DrawOutlineBorder(RwRGBA const& color); + + RwCamera *GetRwCamera() + { + return m_pCamera; + } +}; \ No newline at end of file diff --git a/src/renderer/Shadows.cpp b/src/renderer/Shadows.cpp new file mode 100644 index 00000000..dd87bff6 --- /dev/null +++ b/src/renderer/Shadows.cpp @@ -0,0 +1,2520 @@ +#include "common.h" + +#include "main.h" +#include "TxdStore.h" +#include "Timer.h" +#include "Camera.h" +#include "Timecycle.h" +#include "CutsceneMgr.h" +#include "Automobile.h" +#include "Bike.h" +#include "Ped.h" +#include "PlayerPed.h" +#include "World.h" +#include "Weather.h" +#include "ModelIndices.h" +#include "RenderBuffer.h" +#ifdef FIX_BUGS +#include "Replay.h" +#endif +#include "PointLights.h" +#include "SpecialFX.h" +#include "Script.h" +#include "TimeStep.h" +#include "Shadows.h" +#include "CutsceneObject.h" +#include "CutsceneShadow.h" +#include "Clock.h" +#include "VarConsole.h" + +#ifdef DEBUGMENU +//SETTWEAKPATH("Shadows"); +//TWEAKBOOL(gbPrintShite); +#endif + +RwImVertexIndex ShadowIndexList[24]; + +RwTexture *gpShadowCarTex; +RwTexture *gpShadowPedTex; +RwTexture *gpShadowHeliTex; +RwTexture *gpShadowBikeTex; +RwTexture *gpShadowBaronTex; +RwTexture *gpShadowExplosionTex; +RwTexture *gpShadowHeadLightsTex; +RwTexture *gpOutline1Tex; +RwTexture *gpOutline2Tex; +RwTexture *gpOutline3Tex; +RwTexture *gpBloodPoolTex; +RwTexture *gpReflectionTex; +RwTexture *gpWalkDontTex; +RwTexture *gpCrackedGlassTex; +RwTexture *gpPostShadowTex; +RwTexture *gpGoalTex; + +int16 CShadows::ShadowsStoredToBeRendered; +CStoredShadow CShadows::asShadowsStored [MAX_STOREDSHADOWS]; +CPolyBunch CShadows::aPolyBunches [MAX_POLYBUNCHES]; +CStaticShadow CShadows::aStaticShadows [MAX_STATICSHADOWS]; +CPolyBunch *CShadows::pEmptyBunchList; +CPermanentShadow CShadows::aPermanentShadows[MAX_PERMAMENTSHADOWS]; + +#ifndef MASTER +bool gbCountPolysInShadow; +#endif + +void +CShadows::Init(void) +{ + CTxdStore::PushCurrentTxd(); + + int32 slut = CTxdStore::FindTxdSlot("particle"); + CTxdStore::SetCurrentTxd(slut); + + gpShadowCarTex = RwTextureRead("shad_car", nil); + gpShadowPedTex = RwTextureRead("shad_ped", nil); + gpShadowHeliTex = RwTextureRead("shad_heli", nil); + gpShadowBikeTex = RwTextureRead("shad_bike", nil); + gpShadowBaronTex = RwTextureRead("shad_rcbaron", nil); + gpShadowExplosionTex = RwTextureRead("shad_exp", nil); + gpShadowHeadLightsTex = RwTextureRead("headlight", nil); + gpOutline1Tex = RwTextureRead("outline_64", nil); + gpOutline2Tex = RwTextureRead("outline2_64", nil); + gpOutline3Tex = RwTextureRead("outline3_64", nil); + gpBloodPoolTex = RwTextureRead("bloodpool_64", nil); + gpReflectionTex = RwTextureRead("reflection01", nil); + gpWalkDontTex = RwTextureRead("walk_dont", nil); + gpCrackedGlassTex = RwTextureRead("wincrack_32", nil); + gpPostShadowTex = RwTextureRead("lamp_shad_64", nil); + + CTxdStore::PopCurrentTxd(); + + ASSERT(gpShadowCarTex != nil); + ASSERT(gpShadowPedTex != nil); + ASSERT(gpShadowHeliTex != nil); + ASSERT(gpShadowBikeTex != nil); + ASSERT(gpShadowBaronTex != nil); + ASSERT(gpShadowExplosionTex != nil); + ASSERT(gpShadowHeadLightsTex != nil); + ASSERT(gpOutline1Tex != nil); + ASSERT(gpOutline2Tex != nil); + ASSERT(gpOutline3Tex != nil); + ASSERT(gpBloodPoolTex != nil); + ASSERT(gpReflectionTex != nil); + ASSERT(gpWalkDontTex != nil); + ASSERT(gpCrackedGlassTex != nil); + ASSERT(gpPostShadowTex != nil); + + + ShadowIndexList[0] = 0; + ShadowIndexList[1] = 2; + ShadowIndexList[2] = 1; + + ShadowIndexList[3] = 0; + ShadowIndexList[4] = 3; + ShadowIndexList[5] = 2; + + ShadowIndexList[6] = 0; + ShadowIndexList[7] = 4; + ShadowIndexList[8] = 3; + + ShadowIndexList[9] = 0; + ShadowIndexList[10] = 5; + ShadowIndexList[11] = 4; + + ShadowIndexList[12] = 0; + ShadowIndexList[13] = 6; + ShadowIndexList[14] = 5; + + ShadowIndexList[15] = 0; + ShadowIndexList[16] = 7; + ShadowIndexList[17] = 6; + + ShadowIndexList[18] = 0; + ShadowIndexList[19] = 8; + ShadowIndexList[20] = 7; + + ShadowIndexList[21] = 0; + ShadowIndexList[22] = 9; + ShadowIndexList[23] = 8; + + + for ( int32 i = 0; i < MAX_STATICSHADOWS; i++ ) + { + aStaticShadows[i].m_nId = 0; + aStaticShadows[i].m_pPolyBunch = nil; + } + + pEmptyBunchList = &aPolyBunches[0]; + + for ( int32 i = 0; i < MAX_POLYBUNCHES; i++ ) + { + if ( i == MAX_POLYBUNCHES - 1 ) + aPolyBunches[i].m_pNext = nil; + else + aPolyBunches[i].m_pNext = &aPolyBunches[i + 1]; + } + + for ( int32 i = 0; i < MAX_PERMAMENTSHADOWS; i++ ) + { + aPermanentShadows[i].m_nType = SHADOWTYPE_NONE; + } + +#ifndef MASTER + VarConsole.Add("Count polys in shadow", &gbCountPolysInShadow, true); +#endif +} + +void +CShadows::Shutdown(void) +{ + ASSERT(gpShadowCarTex != nil); + ASSERT(gpShadowPedTex != nil); + ASSERT(gpShadowHeliTex != nil); + ASSERT(gpShadowBikeTex != nil); + ASSERT(gpShadowBaronTex != nil); + ASSERT(gpShadowExplosionTex != nil); + ASSERT(gpShadowHeadLightsTex != nil); + ASSERT(gpOutline1Tex != nil); + ASSERT(gpOutline2Tex != nil); + ASSERT(gpOutline3Tex != nil); + ASSERT(gpBloodPoolTex != nil); + ASSERT(gpReflectionTex != nil); + ASSERT(gpWalkDontTex != nil); + ASSERT(gpCrackedGlassTex != nil); + ASSERT(gpPostShadowTex != nil); + + RwTextureDestroy(gpShadowCarTex); + RwTextureDestroy(gpShadowPedTex); + RwTextureDestroy(gpShadowHeliTex); + RwTextureDestroy(gpShadowBikeTex); + RwTextureDestroy(gpShadowBaronTex); + RwTextureDestroy(gpShadowExplosionTex); + RwTextureDestroy(gpShadowHeadLightsTex); + RwTextureDestroy(gpOutline1Tex); + RwTextureDestroy(gpOutline2Tex); + RwTextureDestroy(gpOutline3Tex); + RwTextureDestroy(gpBloodPoolTex); + RwTextureDestroy(gpReflectionTex); + RwTextureDestroy(gpWalkDontTex); + RwTextureDestroy(gpCrackedGlassTex); + RwTextureDestroy(gpPostShadowTex); +} + +void +CShadows::AddPermanentShadow(uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, + float fFrontX, float fFrontY, float fSideX, float fSideY, + int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, + float fZDistance, uint32 nTime, float fScale) +{ + ASSERT(pTexture != nil); + ASSERT(pPosn != nil); + + + // find free slot + int32 nSlot = 0; + while ( nSlot < MAX_PERMAMENTSHADOWS && aPermanentShadows[nSlot].m_nType != SHADOWTYPE_NONE ) + nSlot++; + + if ( nSlot < MAX_PERMAMENTSHADOWS ) + { + aPermanentShadows[nSlot].m_nType = ShadowType; + aPermanentShadows[nSlot].m_pTexture = pTexture; + aPermanentShadows[nSlot].m_vecPos = *pPosn; + aPermanentShadows[nSlot].m_vecFront.x = fFrontX; + aPermanentShadows[nSlot].m_vecFront.y = fFrontY; + aPermanentShadows[nSlot].m_vecSide.x = fSideX; + aPermanentShadows[nSlot].m_vecSide.y = fSideY; + aPermanentShadows[nSlot].m_nIntensity = nIntensity; + aPermanentShadows[nSlot].m_nRed = nRed; + aPermanentShadows[nSlot].m_nGreen = nGreen; + aPermanentShadows[nSlot].m_nBlue = nBlue; + aPermanentShadows[nSlot].m_fZDistance = fZDistance; + aPermanentShadows[nSlot].m_nLifeTime = nTime; + aPermanentShadows[nSlot].m_nTimeCreated = CTimer::GetTimeInMilliseconds(); + } +} + +bool +CShadows::StoreStaticShadow(uint32 nID, uint8 ShadowType, RwTexture *pTexture, Const CVector *pPosn, + float fFrontX, float fFrontY, float fSideX, float fSideY, + int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, + float fZDistance, float fScale, float fDrawDistance, bool bTempShadow, float fUpDistance) +{ + ASSERT(pPosn != nil); + + float fDistToCamSqr = (*pPosn - TheCamera.GetPosition()).MagnitudeSqr2D(); + + if ( SQR(fDrawDistance) > fDistToCamSqr || fDrawDistance == 0.0f ) + { + if ( fDrawDistance != 0.0f ) + { + float fDistToCam = Sqrt(fDistToCamSqr); + + if ( fDistToCam >= (fDrawDistance*(1.0f-(1.0f/4.0f))) ) + { + //fDistToCam == 0 -> 4 + //fDistToCam == fDrawDistance -> 0 + float fMult = 1.0f - (4.0f / fDrawDistance) * (fDistToCam - (fDrawDistance*(1.0f-(1.0f/4.0f)))); + + nIntensity = (int32)(nIntensity * fMult); + nRed = (int32)(nRed * fMult); + nGreen = (int32)(nGreen * fMult); + nBlue = (int32)(nBlue * fMult); + } + } + + int32 nSlot; + + nSlot = 0; + while ( nSlot < MAX_STATICSHADOWS && !(nID == aStaticShadows[nSlot].m_nId && aStaticShadows[nSlot].m_pPolyBunch != nil) ) + nSlot++; + + if ( nSlot < MAX_STATICSHADOWS ) + { + if ( Abs(pPosn->x - aStaticShadows[nSlot].m_vecPosn.x) < fUpDistance + && Abs(pPosn->y - aStaticShadows[nSlot].m_vecPosn.y) < fUpDistance ) + { + aStaticShadows[nSlot].m_bJustCreated = true; + aStaticShadows[nSlot].m_nType = ShadowType; + aStaticShadows[nSlot].m_pTexture = pTexture; + aStaticShadows[nSlot].m_nIntensity = nIntensity; + aStaticShadows[nSlot].m_nRed = nRed; + aStaticShadows[nSlot].m_nGreen = nGreen; + aStaticShadows[nSlot].m_nBlue = nBlue; + aStaticShadows[nSlot].m_fZDistance = fZDistance; + aStaticShadows[nSlot].m_fScale = fScale; + aStaticShadows[nSlot].m_bTemp = bTempShadow; + aStaticShadows[nSlot].m_nTimeCreated = CTimer::GetTimeInMilliseconds(); + + return true; + } + else if ( Abs(pPosn->x - aStaticShadows[nSlot].m_vecPosn.x) < 0.05f + && Abs(pPosn->y - aStaticShadows[nSlot].m_vecPosn.y) < 0.05f + && Abs(pPosn->z - aStaticShadows[nSlot].m_vecPosn.z) < 2.0f + + && fFrontX == aStaticShadows[nSlot].m_vecFront.x + && fFrontY == aStaticShadows[nSlot].m_vecFront.y + && fSideX == aStaticShadows[nSlot].m_vecSide.x + && fSideY == aStaticShadows[nSlot].m_vecSide.y ) + { + aStaticShadows[nSlot].m_bJustCreated = true; + aStaticShadows[nSlot].m_nType = ShadowType; + aStaticShadows[nSlot].m_pTexture = pTexture; + aStaticShadows[nSlot].m_nIntensity = nIntensity; + aStaticShadows[nSlot].m_nRed = nRed; + aStaticShadows[nSlot].m_nGreen = nGreen; + aStaticShadows[nSlot].m_nBlue = nBlue; + aStaticShadows[nSlot].m_fZDistance = fZDistance; + aStaticShadows[nSlot].m_fScale = fScale; + aStaticShadows[nSlot].m_bTemp = bTempShadow; + aStaticShadows[nSlot].m_nTimeCreated = CTimer::GetTimeInMilliseconds(); + + return true; + } + else + { + aStaticShadows[nSlot].Free(); + + aStaticShadows[nSlot].m_nId = nID; + aStaticShadows[nSlot].m_nType = ShadowType; + aStaticShadows[nSlot].m_pTexture = pTexture; + aStaticShadows[nSlot].m_nIntensity = nIntensity; + aStaticShadows[nSlot].m_nRed = nRed; + aStaticShadows[nSlot].m_nGreen = nGreen; + aStaticShadows[nSlot].m_nBlue = nBlue; + aStaticShadows[nSlot].m_fZDistance = fZDistance; + aStaticShadows[nSlot].m_fScale = fScale; + aStaticShadows[nSlot].m_vecPosn = *pPosn; + aStaticShadows[nSlot].m_vecFront.x = fFrontX; + aStaticShadows[nSlot].m_vecFront.y = fFrontY; + aStaticShadows[nSlot].m_vecSide.x = fSideX; + aStaticShadows[nSlot].m_vecSide.y = fSideY; + aStaticShadows[nSlot].m_bJustCreated = true; + aStaticShadows[nSlot].m_bTemp = bTempShadow; + aStaticShadows[nSlot].m_nTimeCreated = CTimer::GetTimeInMilliseconds(); + + GeneratePolysForStaticShadow(nSlot); + + return aStaticShadows[nSlot].m_pPolyBunch != nil; + } + } + else + { + nSlot = 0; + while ( nSlot < MAX_STATICSHADOWS && aStaticShadows[nSlot].m_pPolyBunch != nil ) + nSlot++; + + if ( nSlot != MAX_STATICSHADOWS ) + { + aStaticShadows[nSlot].m_nId = nID; + aStaticShadows[nSlot].m_nType = ShadowType; + aStaticShadows[nSlot].m_pTexture = pTexture; + aStaticShadows[nSlot].m_nIntensity = nIntensity; + aStaticShadows[nSlot].m_nRed = nRed; + aStaticShadows[nSlot].m_nGreen = nGreen; + aStaticShadows[nSlot].m_nBlue = nBlue; + aStaticShadows[nSlot].m_fZDistance = fZDistance; + aStaticShadows[nSlot].m_fScale = fScale; + aStaticShadows[nSlot].m_vecPosn = *pPosn; + aStaticShadows[nSlot].m_vecFront.x = fFrontX; + aStaticShadows[nSlot].m_vecFront.y = fFrontY; + aStaticShadows[nSlot].m_vecSide.x = fSideX; + aStaticShadows[nSlot].m_vecSide.y = fSideY; + aStaticShadows[nSlot].m_bJustCreated = true; + aStaticShadows[nSlot].m_bTemp = bTempShadow; + aStaticShadows[nSlot].m_nTimeCreated = CTimer::GetTimeInMilliseconds(); + + GeneratePolysForStaticShadow(nSlot); + + return aStaticShadows[nSlot].m_pPolyBunch != nil; + } + } + } + + return true; +} + +void +CShadows::StoreShadowToBeRendered(uint8 ShadowTexture, CVector *pPosn, + float fFrontX, float fFrontY, float fSideX, float fSideY, + int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue) +{ + ASSERT(pPosn != nil); + + switch ( ShadowTexture ) + { + case SHADOWTEX_NONE: + { + break; + } + + case SHADOWTEX_CAR: + { + StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowCarTex, pPosn, + fFrontX, fFrontY, fSideX, fSideY, + nIntensity, nRed, nGreen, nBlue, + 15.0f, false, 1.0f, nil, false); + + break; + } + + case SHADOWTEX_PED: + { + StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowPedTex, pPosn, + fFrontX, fFrontY, fSideX, fSideY, + nIntensity, nRed, nGreen, nBlue, + 15.0f, false, 1.0f, nil, false); + + break; + } + + case SHADOWTEX_EXPLOSION: + { + StoreShadowToBeRendered(SHADOWTYPE_ADDITIVE, gpShadowExplosionTex, pPosn, + fFrontX, fFrontY, fSideX, fSideY, + nIntensity, nRed, nGreen, nBlue, + 15.0f, false, 1.0f, nil, false); + + break; + } + + case SHADOWTEX_HELI: + { + StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowHeliTex, pPosn, + fFrontX, fFrontY, fSideX, fSideY, + nIntensity, nRed, nGreen, nBlue, + 15.0f, false, 1.0f, nil, false); + + break; + } + + case SHADOWTEX_HEADLIGHTS: + { + StoreShadowToBeRendered(SHADOWTYPE_ADDITIVE, gpShadowHeadLightsTex, pPosn, + fFrontX, fFrontY, fSideX, fSideY, + nIntensity, nRed, nGreen, nBlue, + 15.0f, false, 1.0f, nil, false); + + break; + } + + case SHADOWTEX_BLOOD: + { + StoreShadowToBeRendered(SHADOWTYPE_DARK, gpBloodPoolTex, pPosn, + fFrontX, fFrontY, fSideX, fSideY, + nIntensity, nRed, 150, 0, + 15.0f, false, 1.0f, nil, false); + + break; + } + } + + //ASSERT(false); +} + +void +CShadows::StoreShadowToBeRendered(uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, + float fFrontX, float fFrontY, float fSideX, float fSideY, + int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, + float fZDistance, bool bDrawOnWater, float fScale, CCutsceneShadow *pShadow, bool bDrawOnBuildings) +{ + ASSERT(pTexture != nil); + ASSERT(pPosn != nil); + + if ( ShadowsStoredToBeRendered < MAX_STOREDSHADOWS ) + { + asShadowsStored[ShadowsStoredToBeRendered].m_ShadowType = ShadowType; + asShadowsStored[ShadowsStoredToBeRendered].m_pTexture = pTexture; + asShadowsStored[ShadowsStoredToBeRendered].m_vecPos = *pPosn; + asShadowsStored[ShadowsStoredToBeRendered].m_vecFront.x = fFrontX; + asShadowsStored[ShadowsStoredToBeRendered].m_vecFront.y = fFrontY; + asShadowsStored[ShadowsStoredToBeRendered].m_vecSide.x = fSideX; + asShadowsStored[ShadowsStoredToBeRendered].m_vecSide.y = fSideY; + asShadowsStored[ShadowsStoredToBeRendered].m_nIntensity = nIntensity; + asShadowsStored[ShadowsStoredToBeRendered].m_nRed = nRed; + asShadowsStored[ShadowsStoredToBeRendered].m_nGreen = nGreen; + asShadowsStored[ShadowsStoredToBeRendered].m_nBlue = nBlue; + asShadowsStored[ShadowsStoredToBeRendered].m_fZDistance = fZDistance; + asShadowsStored[ShadowsStoredToBeRendered].m_nFlags.bDrawOnWater = bDrawOnWater; + asShadowsStored[ShadowsStoredToBeRendered].m_nFlags.bDrawOnBuildings = bDrawOnBuildings; + asShadowsStored[ShadowsStoredToBeRendered].m_fScale = fScale; + asShadowsStored[ShadowsStoredToBeRendered].m_pCutsceneShadow = pShadow; + + ShadowsStoredToBeRendered++; + } +} + + +void +CShadows::StoreShadowForVehicle(CVehicle *pCar, VEH_SHD_TYPE type) +{ + ASSERT(pCar != nil); + + if ( CTimeCycle::GetShadowStrength() != 0 ) + { + CVector CarPos = pCar->GetPosition(); + float fDistToCamSqr = (CarPos - TheCamera.GetPosition()).MagnitudeSqr2D(); + + if ( CCutsceneMgr::IsRunning() ) + fDistToCamSqr /= SQR(TheCamera.LODDistMultiplier) * 4.0f; + + float fDrawDistance; + switch ( type ) + { + case VEH_SHD_TYPE_SEAPLANE: + case VEH_SHD_TYPE_RCPLANE: + fDrawDistance = 144.0f; + break; + + case VEH_SHD_TYPE_HELI: + fDrawDistance = 144.0f; + break; + + default: + fDrawDistance = 18.0f; + break; + } + + if ( fDistToCamSqr < SQR(fDrawDistance) ) + { + float fDistToCam = Sqrt(fDistToCamSqr); + + //fDistToCam == 0 -> 4 + //fDistToCam == fDrawDistance -> 0 + float fMult = 1.0f - (fDistToCam - (fDrawDistance*(1.0f-(1.0f/4.0f)))) / (fDrawDistance*(1.0f/4.0f)); + + int32 nColorStrength; + + if ( fDistToCam >= (fDrawDistance*(1.0f-(1.0f/4.0f))) ) + nColorStrength = (int32)(fMult * CTimeCycle::GetShadowStrength()); + else + nColorStrength = CTimeCycle::GetShadowStrength(); + + + float fVehicleHeight = pCar->GetColModel()->boundingBox.GetSize().y; + float fVehicleWidth = pCar->GetColModel()->boundingBox.GetSize().x; + + float size = 1.0f; + + if ( pCar->GetModelIndex() == MI_HUNTER ) + { + fVehicleWidth *= 3.0f; + fVehicleHeight *= 1.4f; + size *= 0.5f; + } + else if ( pCar->GetModelIndex() == MI_ANGEL ) + { + fVehicleHeight = fVehicleHeight * 1.5f; + size = 0.03f; + } + else if ( pCar->GetModelIndex() == MI_SEASPAR ) + { + fVehicleWidth *= 3.0f; + fVehicleHeight *= 1.4f; + size *= 0.5f; + } + else if ( pCar->GetModelIndex() == MI_PIZZABOY || pCar->GetModelIndex() == MI_PCJ600 || pCar->GetModelIndex() == MI_FAGGIO ) + { + fVehicleHeight *= 1.2f; + size = 0.05f; + } + else if ( pCar->GetModelIndex() == MI_FREEWAY ) + { + fVehicleHeight *= 1.5f; + size = 0.03f; + } + else if ( pCar->GetModelIndex() == MI_RCRAIDER ) + { + fVehicleHeight *= 1.5f; + fVehicleWidth *= 2.0f; + size = 0.2f; + } + else if ( pCar->GetModelIndex() == MI_SANCHEZ ) + { + fVehicleHeight *= 1.5f; + size = 0.03f; + } + else if ( pCar->GetModelIndex() == MI_SPARROW || pCar->GetModelIndex() == MI_MAVERICK || pCar->GetModelIndex() == MI_VCNMAV || pCar->GetModelIndex() == MI_POLMAV ) + { + fVehicleWidth *= 3.0f; + fVehicleHeight *= 1.4f; + size *= 0.5f; + } + else if ( pCar->GetModelIndex() == MI_RCGOBLIN ) + { + fVehicleHeight *= 1.5f; + fVehicleWidth *= 2.0f; + size = 0.2f; + } + else if ( pCar->GetModelIndex() == MI_DODO ) + { + fVehicleHeight *= 0.9f; + fVehicleWidth *= 0.4f; + } + + CarPos.x -= pCar->GetForward().x * (((fVehicleHeight/2) - pCar->GetColModel()->boundingBox.max.y)*size); + CarPos.y -= pCar->GetForward().y * (((fVehicleHeight/2) - pCar->GetColModel()->boundingBox.max.y)*size); + + RwTexture *tex = gpShadowCarTex; + switch ( type ) + { + case VEH_SHD_TYPE_BIKE: + { + float wheelZ = Abs(((CBike*)pCar)->m_fLeanLRAngle); + float mul = 5.092958f * wheelZ + 1.0f; + if (pCar->GetStatus() == STATUS_PHYSICS) + { + float z = pCar->GetRight().z; + if (z > 0.6f) + mul += 4.0f * z; + } + fVehicleWidth *= mul; + tex = gpShadowBikeTex; + break; + } + + case VEH_SHD_TYPE_HELI: + tex = gpShadowHeliTex; + break; + + case VEH_SHD_TYPE_SEAPLANE: + nColorStrength = CTimeCycle::GetShadowStrength(); + tex = gpShadowBaronTex; + break; + + case VEH_SHD_TYPE_RCPLANE: + tex = gpShadowBaronTex; + fVehicleHeight *= 1.5f; + fVehicleWidth *= 2.2f; + break; + + case VEH_SHD_TYPE_CAR: + tex = gpShadowCarTex; + break; + } + + float frontx = pCar->GetForward().x; + float fronty = pCar->GetForward().y; + float sidex = pCar->GetRight().x; + float sidey = pCar->GetRight().y; + + switch ( type ) + { + case VEH_SHD_TYPE_BIKE: + if ( Abs(pCar->GetRight().z) > 0.6f ) + { + sidex = pCar->GetUp().x; + sidey = pCar->GetUp().y; + } + break; + + case VEH_SHD_TYPE_HELI: + if ( Abs(pCar->GetRight().z) > 0.57f ) + { + sidex = pCar->GetUp().x; + sidey = pCar->GetUp().y; + } + if ( Abs(pCar->GetForward().z) > 0.57f ) + { + frontx = pCar->GetUp().x; + fronty = pCar->GetUp().y; + } + break; + } + + bool bDrawOnBuildings = false; + if ( pCar->GetModelIndex() == MI_RCBANDIT + || pCar->GetModelIndex() == MI_RCBARON + || pCar->GetModelIndex() == MI_RCRAIDER + || pCar->GetModelIndex() == MI_RCGOBLIN + || pCar == FindPlayerVehicle() ) + { + bDrawOnBuildings = true; + } + + if ( pCar->m_vecMoveSpeed.Magnitude() * CTimeStep::ms_fTimeStep > 0.1f || bDrawOnBuildings ) + { + if ( pCar->GetUp().z > 0.0f ) + { + StoreShadowToBeRendered(SHADOWTYPE_DARK, tex, &CarPos, + frontx * (fVehicleHeight / 2), + fronty * (fVehicleHeight / 2), + sidex * (fVehicleWidth / 2), + sidey * (fVehicleWidth / 2), + nColorStrength, nColorStrength, nColorStrength, nColorStrength, + 4.5f, false, 1.0f, nil, bDrawOnBuildings); + } + else + { + StoreShadowToBeRendered(SHADOWTYPE_DARK, tex, &CarPos, + frontx * (fVehicleHeight / 2), + fronty * (fVehicleHeight / 2), + -sidex * (fVehicleWidth / 2), + -sidey * (fVehicleWidth / 2), + nColorStrength, nColorStrength, nColorStrength, nColorStrength, + 4.5f, false, 1.0f, nil, bDrawOnBuildings); + } + } + else + { + if ( pCar->GetUp().z > 0.0f ) + { + StoreStaticShadow((uintptr)pCar + 1, SHADOWTYPE_DARK, tex, &CarPos, + frontx * (fVehicleHeight / 2), + fronty * (fVehicleHeight / 2), + sidex * (fVehicleWidth / 2), + sidey * (fVehicleWidth / 2), + nColorStrength, nColorStrength, nColorStrength, nColorStrength, + 4.5f, 1.0f, 0.0f, false, 0.1f); + } + else + { + StoreStaticShadow((uintptr)pCar + 1, SHADOWTYPE_DARK, tex, &CarPos, + frontx * (fVehicleHeight / 2), + fronty * (fVehicleHeight / 2), + -sidex * (fVehicleWidth / 2), + -sidey * (fVehicleWidth / 2), + nColorStrength, nColorStrength, nColorStrength, nColorStrength, + 4.5f, 1.0f, 0.0f, false, 0.1f); + } + } + } + } +} + +void +CShadows::StoreCarLightShadow(CVehicle *pCar, int32 nID, RwTexture *pTexture, CVector *pPosn, + float fFrontX, float fFrontY, float fSideX, float fSideY, uint8 nRed, uint8 nGreen, uint8 nBlue, + float fMaxViewAngle) +{ + ASSERT(pCar != nil); + ASSERT(pPosn != nil); + + float fDistToCamSqr = (*pPosn - TheCamera.GetPosition()).MagnitudeSqr2D(); + + bool bSpecialCam = TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN + || TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED + || CCutsceneMgr::IsRunning(); + + float fDrawDistance = 27.0f; + + if ( fDistToCamSqr < SQR(fDrawDistance) || bSpecialCam ) + { + if ( bSpecialCam || DotProduct2D(CVector2D(TheCamera.CamFrontXNorm, TheCamera.CamFrontYNorm), + *pPosn - TheCamera.GetPosition() ) > -fMaxViewAngle ) + { + float fDistToCam = Sqrt(fDistToCamSqr); + + if ( fDistToCam >= (fDrawDistance*(1.0f-(1.0f/4.0f))) && !bSpecialCam ) // BUG? must be 3.0? + { + //fDistToCam == 0 -> 3 + //fDistToCam == fDrawDistance -> 0 + float fMult = 1.0f - (3.0f / fDrawDistance) * (fDistToCam - (fDrawDistance*(1.0f-(1.0f/3.0f))) ); + + nRed = (int32)(nRed * fMult); + nGreen = (int32)(nGreen * fMult); + nBlue = (int32)(nBlue * fMult); + } + + if ( pCar->m_vecMoveSpeed.Magnitude() * CTimeStep::ms_fTimeStep > 0.4f || pCar == FindPlayerVehicle() ) + { + StoreShadowToBeRendered(SHADOWTYPE_ADDITIVE, pTexture, pPosn, + fFrontX, fFrontY, + fSideX, fSideY, + 128, nRed, nGreen, nBlue, + 6.0f, false, 1.0f, + nil, pCar == FindPlayerVehicle()); + } + else + { + StoreStaticShadow((uintptr)pCar + nID, SHADOWTYPE_ADDITIVE, pTexture, pPosn, + fFrontX, fFrontY, + fSideX, fSideY, + 128, nRed, nGreen, nBlue, + 6.0f, 1.0f, 27.0f, + false, 0.4f); + } + } + } +} + + +#ifdef USE_CUTSCENE_SHADOW_FOR_PED +void +StoreShadowForCutscenePedObject(CPed *pObject, float fDisplacementX, float fDisplacementY, + float fFrontX, float fFrontY, float fSideX, float fSideY) +{ + ASSERT(pObject != nil); + + CCutsceneShadow *shadow = pObject->m_pRTShadow; + + if ( shadow == nil ) + return; + + if ( !shadow->IsInitialized() ) + return; + + CVector pos = pObject->GetPosition(); + + float fDistToCamSqr = (pos - TheCamera.GetPosition()).MagnitudeSqr2D(); + + float fDrawDistance = 100.0f; + + if ( fDistToCamSqr < SQR(fDrawDistance*0.5f) ) + { + if ( (CEntity*)pObject == FindPlayerPed() || TheCamera.IsSphereVisible(pos, 2.0f) ) + { + float fDistToCam = Sqrt(fDistToCamSqr); + + float fMult = 1.0f - (4.0f / fDrawDistance) * (fDistToCam - (fDrawDistance*(1.0f/4.0f))); + int32 nColorStrength; + + if ( fDistToCam >= (fDrawDistance*(1.0f/4.0f)) ) + nColorStrength = (int32)(CTimeCycle::GetShadowStrength() * fMult); + else + nColorStrength = CTimeCycle::GetShadowStrength(); + + int32 color = int32(nColorStrength * 0.8f); + + pos.x += fDisplacementX; + pos.y += fDisplacementY; + + RwTexture *texture = shadow->GetShadowRwTexture(); + ASSERT(texture); + RwRGBA bordercolor = {0, 0, 0, 0}; + shadow->DrawBorderAroundTexture(bordercolor); + + pos.x -= fDisplacementX; + pos.y -= fDisplacementY; + + float angleY = 360.0f - RADTODEG((CClock::ms_nGameClockMinutes + +60*CClock::ms_nGameClockHours+CClock::ms_nGameClockSeconds/60)*(HALFPI/360.0f)); + + RwFrame *frame = shadow->SetLightProperties(angleY, -85.0f, true); + ASSERT(frame); + CVector at(RwFrameGetMatrix(frame)->at); + at.Normalise(); + + CShadows::CalcPedShadowValues(at, &fFrontX, &fFrontY, &fSideX, &fSideY, &fDisplacementX, &fDisplacementY); + + pos.x -= 2.5f * fDisplacementX; + pos.y -= 2.5f * fDisplacementY; + + CShadows::StoreShadowToBeRendered(SHADOWTYPE_INVCOLOR, texture, &pos, + fFrontX * 1.5f, fFrontY * 1.5f, + fSideX * 1.5f, fSideY * 1.5f, + color, color, color, color, + 4.0f, false, 1.0f, shadow, false); + } + } +} +#endif + + +void +CShadows::StoreShadowForPed(CPed *pPed, float fDisplacementX, float fDisplacementY, + float fFrontX, float fFrontY, float fSideX, float fSideY) +{ + ASSERT(pPed != nil); + + if ( pPed->bIsVisible ) + { + if ( !(pPed->bInVehicle && pPed->m_nPedState != PED_DRAG_FROM_CAR && pPed->m_nPedState != PED_EXIT_CAR) ) + { + if ( CTimeCycle::GetShadowStrength() != 0 ) + { +#ifdef USE_CUTSCENE_SHADOW_FOR_PED + CCutsceneShadow *pShadow = pPed->m_pRTShadow; + + if (pShadow) + { + if (pShadow->IsInitialized()) + pShadow->UpdateForCutscene(); + ::StoreShadowForCutscenePedObject(pPed, fDisplacementX, fDisplacementY, fFrontX, fFrontY, fSideX, fSideY); + } + + return; +#endif + + StoreShadowForPedObject(pPed, + fDisplacementX, fDisplacementY, + fFrontX, fFrontY, + fSideX, fSideY); + } + } + } +} + +void +CShadows::StoreShadowForPedObject(CEntity *pPedObject, float fDisplacementX, float fDisplacementY, + float fFrontX, float fFrontY, float fSideX, float fSideY) +{ + ASSERT(pPedObject != nil); + + CVector PedPos = pPedObject->GetPosition(); + + float fDistToCamSqr = (PedPos - TheCamera.GetPosition()).MagnitudeSqr2D(); + + float fDrawDistance = 26.0f; + + if ( fDistToCamSqr < SQR(fDrawDistance*0.5f) ) + { + if ( pPedObject == FindPlayerPed() || TheCamera.IsSphereVisible(PedPos, 2.0f) != false ) + { + float fDistToCam = Sqrt(fDistToCamSqr); + + //fDistToCam == 0 -> 2 + //fDistToCam == fDrawDistance -> -2 + float fMult = 1.0f - (4.0f / fDrawDistance) * (fDistToCam - (fDrawDistance*(1.0f/4.0f))); // BUG ? negative + int32 nColorStrength; + + if ( fDistToCam >= (fDrawDistance*(1.0f/4.0f)) ) // BUG ? negative + nColorStrength = (int32)(CTimeCycle::GetShadowStrength() * fMult); + else + nColorStrength = CTimeCycle::GetShadowStrength(); + + PedPos.x += fDisplacementX; + PedPos.y += fDisplacementY; + + StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowPedTex, &PedPos, + fFrontX, fFrontY, + fSideX, fSideY, + nColorStrength, nColorStrength, nColorStrength, nColorStrength, + 4.0f, false, 1.0f, nil, pPedObject == FindPlayerPed()); + } + } +} + + +void +CShadows::StoreShadowForCutscenePedObject(CCutsceneObject *pObject, float fDisplacementX, float fDisplacementY, + float fFrontX, float fFrontY, float fSideX, float fSideY) +{ +#ifdef DISABLE_CUTSCENE_SHADOWS + return; +#endif + ASSERT(pObject != nil); + + CCutsceneShadow *shadow = pObject->m_pShadow; + + if ( shadow == nil ) + return; + + if ( !shadow->IsInitialized() ) + return; + + CVector pos = pObject->GetPosition(); + + float fDistToCamSqr = (pos - TheCamera.GetPosition()).MagnitudeSqr2D(); + + float fDrawDistance = 100.0f; + + if ( fDistToCamSqr < SQR(fDrawDistance*0.5f) ) + { + if ( (CEntity*)pObject == FindPlayerPed() || TheCamera.IsSphereVisible(pos, 2.0f) ) + { + float fDistToCam = Sqrt(fDistToCamSqr); + + float fMult = 1.0f - (4.0f / fDrawDistance) * (fDistToCam - (fDrawDistance*(1.0f/4.0f))); + int32 nColorStrength; + + if ( fDistToCam >= (fDrawDistance*(1.0f/4.0f)) ) + nColorStrength = (int32)(CTimeCycle::GetShadowStrength() * fMult); + else + nColorStrength = CTimeCycle::GetShadowStrength(); + + int32 color = int32(nColorStrength * 0.8f); + + pos.x += fDisplacementX; + pos.y += fDisplacementY; + + RwTexture *texture = shadow->GetShadowRwTexture(); + ASSERT(texture); + RwRGBA bordercolor = {0, 0, 0, 0}; + shadow->DrawBorderAroundTexture(bordercolor); + + pos.x -= fDisplacementX; + pos.y -= fDisplacementY; + + float angleY = 360.0f - RADTODEG((CClock::ms_nGameClockMinutes+60* + CClock::ms_nGameClockHours+CClock::ms_nGameClockSeconds/60)*(HALFPI/360.0f)); + + RwFrame *frame = shadow->SetLightProperties(angleY, -85.0f, true); + ASSERT(frame); + CVector at(RwFrameGetMatrix(frame)->at); + at.Normalise(); + + CalcPedShadowValues(at, &fFrontX, &fFrontY, &fSideX, &fSideY, &fDisplacementX, &fDisplacementY); + + pos.x -= 2.5f * fDisplacementX; + pos.y -= 2.5f * fDisplacementY; + + StoreShadowToBeRendered(SHADOWTYPE_INVCOLOR, texture, &pos, + fFrontX * 1.5f, fFrontY * 1.5f, + fSideX * 1.5f, fSideY * 1.5f, + color, color, color, color, + 4.0f, false, 1.0f, shadow, false); + } + } +} + +void +CShadows::StoreShadowForTree(CEntity *pTree) +{ + ASSERT(pTree != nil); +} + + +void +CShadows::StoreShadowForPole(CEntity *pPole, float fOffsetX, float fOffsetY, float fOffsetZ, + float fPoleHeight, float fPoleWidth, uint32 nID) +{ + ASSERT(pPole != nil); + + if ( CTimeCycle::GetShadowStrength() != 0 ) + { + if ( pPole->GetUp().z < 0.5f ) + return; + + CVector PolePos = pPole->GetPosition(); + + PolePos.x += fOffsetX * pPole->GetRight().x + fOffsetY * pPole->GetForward().x; + PolePos.y += fOffsetX * pPole->GetRight().y + fOffsetY * pPole->GetForward().y; + PolePos.z += fOffsetZ; + + PolePos.x += -CTimeCycle::GetSunDirection().x * (fPoleHeight / 2); + PolePos.y += -CTimeCycle::GetSunDirection().y * (fPoleHeight / 2); + + StoreStaticShadow((uintptr)pPole + nID + _TODOCONST(51), SHADOWTYPE_DARK, gpPostShadowTex, &PolePos, + -CTimeCycle::GetSunDirection().x * (fPoleHeight / 2), + -CTimeCycle::GetSunDirection().y * (fPoleHeight / 2), + CTimeCycle::GetShadowSideX() * fPoleWidth, + CTimeCycle::GetShadowSideY() * fPoleWidth, + 2 * (int32)((pPole->GetUp().z - 0.5f) * CTimeCycle::GetShadowStrength() * 2.0f) / 3, + 0, 0, 0, + 15.0f, 1.0f, 40.0f, false, 0.0f); + } +} + +void +CShadows::SetRenderModeForShadowType(uint8 ShadowType) +{ + switch ( ShadowType ) + { + case SHADOWTYPE_DARK: + { + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + break; + } + + case SHADOWTYPE_ADDITIVE: + { + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); + break; + } + + case SHADOWTYPE_INVCOLOR: + { + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDZERO); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCCOLOR); + break; + } + } +} + + +void +CShadows::RenderStoredShadows(void) +{ + PUSH_RENDERGROUP("CShadows::RenderStoredShadows"); + + RenderBuffer::ClearRenderBuffer(); + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void *)rwTEXTUREADDRESSCLAMP); + + + for ( int32 i = 0; i < ShadowsStoredToBeRendered; i++ ) + asShadowsStored[i].m_nFlags.bRendered = false; + + + for ( int32 i = 0; i < ShadowsStoredToBeRendered; i++ ) + { + if ( !asShadowsStored[i].m_nFlags.bRendered ) + { + SetRenderModeForShadowType(asShadowsStored[i].m_ShadowType); + + ASSERT(asShadowsStored[i].m_pTexture != nil); + + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(asShadowsStored[i].m_pTexture)); + + for ( int32 j = i; j < ShadowsStoredToBeRendered; j++ ) + { + if ( asShadowsStored[i].m_ShadowType == asShadowsStored[j].m_ShadowType + && asShadowsStored[i].m_pTexture == asShadowsStored[j].m_pTexture ) + { + float fWidth = Abs(asShadowsStored[j].m_vecFront.x) + Abs(asShadowsStored[j].m_vecSide.x); + float fHeight = Abs(asShadowsStored[j].m_vecFront.y) + Abs(asShadowsStored[j].m_vecSide.y); + + CVector shadowPos = asShadowsStored[j].m_vecPos; + + float fStartX = shadowPos.x - fWidth; + float fEndX = shadowPos.x + fWidth; + float fStartY = shadowPos.y - fHeight; + float fEndY = shadowPos.y + fHeight; + + int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); + int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); + int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); + int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); + + CWorld::AdvanceCurrentScanCode(); + + for ( int32 y = nStartY; y <= nEndY; y++ ) + { + for ( int32 x = nStartX; x <= nEndX; x++ ) + { + CSector *pCurSector = CWorld::GetSector(x, y); + + ASSERT(pCurSector != nil); + + if ( asShadowsStored[j].m_pCutsceneShadow ) + { + CastCutsceneShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS], + fStartX, fStartY, + fEndX, fEndY, + &shadowPos, + asShadowsStored[j].m_vecFront.x, + asShadowsStored[j].m_vecFront.y, + asShadowsStored[j].m_vecSide.x, + asShadowsStored[j].m_vecSide.y, + asShadowsStored[j].m_nIntensity, + asShadowsStored[j].m_nRed, + asShadowsStored[j].m_nGreen, + asShadowsStored[j].m_nBlue, + asShadowsStored[j].m_fZDistance, + asShadowsStored[j].m_fScale, + nil, + asShadowsStored[j].m_pCutsceneShadow); + + CastCutsceneShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP], + fStartX, fStartY, + fEndX, fEndY, + &shadowPos, + asShadowsStored[j].m_vecFront.x, + asShadowsStored[j].m_vecFront.y, + asShadowsStored[j].m_vecSide.x, + asShadowsStored[j].m_vecSide.y, + asShadowsStored[j].m_nIntensity, + asShadowsStored[j].m_nRed, + asShadowsStored[j].m_nGreen, + asShadowsStored[j].m_nBlue, + asShadowsStored[j].m_fZDistance, + asShadowsStored[j].m_fScale, + nil, + asShadowsStored[j].m_pCutsceneShadow); + } + else if ( asShadowsStored[j].m_nFlags.bDrawOnBuildings ) + { + CastPlayerShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS], + fStartX, fStartY, + fEndX, fEndY, + &shadowPos, + asShadowsStored[j].m_vecFront.x, + asShadowsStored[j].m_vecFront.y, + asShadowsStored[j].m_vecSide.x, + asShadowsStored[j].m_vecSide.y, + asShadowsStored[j].m_nIntensity, + asShadowsStored[j].m_nRed, + asShadowsStored[j].m_nGreen, + asShadowsStored[j].m_nBlue, + asShadowsStored[j].m_fZDistance, + asShadowsStored[j].m_fScale, + nil); + + CastPlayerShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP], + fStartX, fStartY, + fEndX, fEndY, + &shadowPos, + asShadowsStored[j].m_vecFront.x, + asShadowsStored[j].m_vecFront.y, + asShadowsStored[j].m_vecSide.x, + asShadowsStored[j].m_vecSide.y, + asShadowsStored[j].m_nIntensity, + asShadowsStored[j].m_nRed, + asShadowsStored[j].m_nGreen, + asShadowsStored[j].m_nBlue, + asShadowsStored[j].m_fZDistance, + asShadowsStored[j].m_fScale, + nil); + } + else + { + CastShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS], + fStartX, fStartY, + fEndX, fEndY, + &shadowPos, + asShadowsStored[j].m_vecFront.x, + asShadowsStored[j].m_vecFront.y, + asShadowsStored[j].m_vecSide.x, + asShadowsStored[j].m_vecSide.y, + asShadowsStored[j].m_nIntensity, + asShadowsStored[j].m_nRed, + asShadowsStored[j].m_nGreen, + asShadowsStored[j].m_nBlue, + asShadowsStored[j].m_fZDistance, + asShadowsStored[j].m_fScale, + nil); + + CastShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP], + fStartX, fStartY, + fEndX, fEndY, + &shadowPos, + asShadowsStored[j].m_vecFront.x, + asShadowsStored[j].m_vecFront.y, + asShadowsStored[j].m_vecSide.x, + asShadowsStored[j].m_vecSide.y, + asShadowsStored[j].m_nIntensity, + asShadowsStored[j].m_nRed, + asShadowsStored[j].m_nGreen, + asShadowsStored[j].m_nBlue, + asShadowsStored[j].m_fZDistance, + asShadowsStored[j].m_fScale, + nil); + } + } + } + + asShadowsStored[j].m_nFlags.bRendered = true; + } + } + + RenderBuffer::RenderStuffInBuffer(); + } + } + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void *)rwTEXTUREADDRESSWRAP); + + ShadowsStoredToBeRendered = 0; + + POP_RENDERGROUP(); +} + + +void +CShadows::RenderStaticShadows(void) +{ + PUSH_RENDERGROUP("CShadows::RenderStaticShadows"); + + RenderBuffer::ClearRenderBuffer(); + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE); + + SetAlphaTest(0); + + for ( int32 i = 0; i < MAX_STATICSHADOWS; i++ ) + aStaticShadows[i].m_bRendered = false; + + for ( int32 i = 0; i < MAX_STATICSHADOWS; i++ ) + { + if ( aStaticShadows[i].m_pPolyBunch && !aStaticShadows[i].m_bRendered ) + { + SetRenderModeForShadowType(aStaticShadows[i].m_nType); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(aStaticShadows[i].m_pTexture)); + + // optimization trick, render all shadows with same renderstate and texture + for ( int32 j = i; j < MAX_STATICSHADOWS; j++ ) + { + if ( aStaticShadows[j].m_pPolyBunch != nil + && aStaticShadows[i].m_nType == aStaticShadows[j].m_nType + && aStaticShadows[i].m_pTexture == aStaticShadows[j].m_pTexture ) + { + for ( CPolyBunch *bunch = aStaticShadows[j].m_pPolyBunch; bunch != nil; bunch = bunch->m_pNext ) + { + RwImVertexIndex *pIndexes; + RwIm3DVertex *pVerts; + + RenderBuffer::StartStoring(3 * (bunch->m_nNumVerts - 2), bunch->m_nNumVerts, &pIndexes, &pVerts); + + ASSERT(pIndexes != nil); + ASSERT(pVerts != nil); + + for ( int32 k = 0; k < bunch->m_nNumVerts; k++ ) + { + RwIm3DVertexSetRGBA(&pVerts[k], + aStaticShadows[j].m_nRed, + aStaticShadows[j].m_nGreen, + aStaticShadows[j].m_nBlue, + (int32)(aStaticShadows[j].m_nIntensity * (1.0f - CWeather::Foggyness * 0.5f))); + + RwIm3DVertexSetU (&pVerts[k], bunch->m_aU[k] / 200.0f); + RwIm3DVertexSetV (&pVerts[k], bunch->m_aV[k] / 200.0f); + RwIm3DVertexSetPos(&pVerts[k], bunch->m_aVerts[k].x, bunch->m_aVerts[k].y, bunch->m_aVerts[k].z + 0.03f); + } + + for ( int32 k = 0; k < 3 * (bunch->m_nNumVerts - 2); k++ ) + pIndexes[k] = ShadowIndexList[k]; + + RenderBuffer::StopStoring(); + } + + aStaticShadows[j].m_bRendered = true; + } + } + + RenderBuffer::RenderStuffInBuffer(); + } + } + RestoreAlphaTest(); + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE); + + POP_RENDERGROUP(); +} + + +void +CShadows::GeneratePolysForStaticShadow(int16 nStaticShadowID) +{ + float fWidth = Abs(aStaticShadows[nStaticShadowID].m_vecFront.x) + Abs(aStaticShadows[nStaticShadowID].m_vecSide.x); + float fHeight = Abs(aStaticShadows[nStaticShadowID].m_vecFront.y) + Abs(aStaticShadows[nStaticShadowID].m_vecSide.y); + + CVector shadowPos = aStaticShadows[nStaticShadowID].m_vecPosn; + + float fStartX = shadowPos.x - fWidth; + float fEndX = shadowPos.x + fWidth; + float fStartY = shadowPos.y - fHeight; + float fEndY = shadowPos.y + fHeight; + + int32 nStartX = Max(CWorld::GetSectorIndexX(fStartX), 0); + int32 nStartY = Max(CWorld::GetSectorIndexY(fStartY), 0); + int32 nEndX = Min(CWorld::GetSectorIndexX(fEndX), NUMSECTORS_X-1); + int32 nEndY = Min(CWorld::GetSectorIndexY(fEndY), NUMSECTORS_Y-1); + + CWorld::AdvanceCurrentScanCode(); + + for ( int32 y = nStartY; y <= nEndY; y++ ) + { + for ( int32 x = nStartX; x <= nEndX; x++ ) + { + CSector *pCurSector = CWorld::GetSector(x, y); + + ASSERT(pCurSector != nil); + + CastShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS], + fStartX, fStartY, + fEndX, fEndY, + &shadowPos, + aStaticShadows[nStaticShadowID].m_vecFront.x, + aStaticShadows[nStaticShadowID].m_vecFront.y, + aStaticShadows[nStaticShadowID].m_vecSide.x, + aStaticShadows[nStaticShadowID].m_vecSide.y, + 0, 0, 0, 0, + aStaticShadows[nStaticShadowID].m_fZDistance, + aStaticShadows[nStaticShadowID].m_fScale, + &aStaticShadows[nStaticShadowID].m_pPolyBunch); + + CastShadowSectorList(pCurSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP], + fStartX, fStartY, + fEndX, fEndY, + &shadowPos, + aStaticShadows[nStaticShadowID].m_vecFront.x, + aStaticShadows[nStaticShadowID].m_vecFront.y, + aStaticShadows[nStaticShadowID].m_vecSide.x, + aStaticShadows[nStaticShadowID].m_vecSide.y, + 0, 0, 0, 0, + aStaticShadows[nStaticShadowID].m_fZDistance, + aStaticShadows[nStaticShadowID].m_fScale, + &aStaticShadows[nStaticShadowID].m_pPolyBunch); + } + } +} + + +void +CShadows::CastShadowSectorList(CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, CVector *pPosn, + float fFrontX, float fFrontY, float fSideX, float fSideY, + int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, + float fZDistance, float fScale, CPolyBunch **ppPolyBunch) +{ + ASSERT(pPosn != nil); + + CPtrNode *pNode = PtrList.first; + + CRect Bound; + + while ( pNode != nil ) + { + CEntity *pEntity = (CEntity *)pNode->item; + uint16 nScanCode = pEntity->m_scanCode; + pNode = pNode->next; + + ASSERT( pEntity != nil ); + + if ( nScanCode != CWorld::GetCurrentScanCode() ) + { + pEntity->m_scanCode = CWorld::GetCurrentScanCode(); + + if ( pEntity->bUsesCollision && !pEntity->bDontCastShadowsOn) + { + if ( IsAreaVisible(pEntity->m_area) ) + { + Bound = pEntity->GetBoundRect(); + + if ( fStartX < Bound.right + && fEndX > Bound.left + && fStartY < Bound.bottom + && fEndY > Bound.top ) + { + if ( pPosn->z - fZDistance < pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.max.z + && pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.min.z < pPosn->z ) + { + CastShadowEntityXY(pEntity, + fStartX, fStartY, + fEndX, fEndY, + pPosn, + fFrontX, fFrontY, + fSideX, fSideY, + nIntensity, nRed, nGreen, nBlue, + fZDistance, fScale, ppPolyBunch); + } + } + } + } + } + } +} + + +void +CShadows::CastPlayerShadowSectorList(CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, CVector *pPosn, + float fFrontX, float fFrontY, float fSideX, float fSideY, + int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, + float fZDistance, float fScale, CPolyBunch **ppPolyBunch) +{ + ASSERT(pPosn != nil); + + CPtrNode *pNode = PtrList.first; + + CRect Bound; + + while ( pNode != nil ) + { + CEntity *pEntity = (CEntity *)pNode->item; + uint16 nScanCode = pEntity->m_scanCode; + pNode = pNode->next; + + ASSERT( pEntity != nil ); + + if ( nScanCode != CWorld::GetCurrentScanCode() ) + { + pEntity->m_scanCode = CWorld::GetCurrentScanCode(); + + if ( pEntity->bUsesCollision ) + { + if ( IsAreaVisible(pEntity->m_area) ) + { + Bound = pEntity->GetBoundRect(); + + if ( fStartX < Bound.right + && fEndX > Bound.left + && fStartY < Bound.bottom + && fEndY > Bound.top ) + { + if ( pPosn->z - fZDistance < pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.max.z + && pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.min.z < pPosn->z ) + { + CastShadowEntityXY(pEntity, + fStartX, fStartY, + fEndX, fEndY, + pPosn, + fFrontX, fFrontY, + fSideX, fSideY, + nIntensity, nRed, nGreen, nBlue, + fZDistance, fScale, ppPolyBunch); + } + } + } + } + } + } +} + + +void +CShadows::CastCutsceneShadowSectorList(CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, CVector *pPosn, + float fFrontX, float fFrontY, float fSideX, float fSideY, + int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, + float fZDistance, float fScale, CPolyBunch **ppPolyBunch, CCutsceneShadow *pShadow) +{ + ASSERT(pPosn != nil); + ASSERT(pShadow != nil); + + CPtrNode *pNode = PtrList.first; + + CRect Bound; + + while ( pNode != nil ) + { + CEntity *pEntity = (CEntity *)pNode->item; + uint16 nScanCode = pEntity->m_scanCode; + pNode = pNode->next; + + ASSERT( pEntity != nil ); + + if ( nScanCode != CWorld::GetCurrentScanCode() ) + { + pEntity->m_scanCode = CWorld::GetCurrentScanCode(); + + if ( pEntity->bUsesCollision ) + { + if ( IsAreaVisible(pEntity->m_area) ) + { + Bound = pEntity->GetBoundRect(); + + if ( fStartX < Bound.right + && fEndX > Bound.left + && fStartY < Bound.bottom + && fEndY > Bound.top ) + { + if ( pPosn->z - fZDistance < pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.max.z + && pEntity->GetPosition().z + pEntity->GetColModel()->boundingBox.min.z < pPosn->z ) + { + CastShadowEntityXYZ(pEntity, pPosn, + fFrontX, fFrontY, + fSideX, fSideY, + nIntensity, nRed, nGreen, nBlue, + fZDistance, fScale, ppPolyBunch, pShadow); + } + } + } + } + } + } +} + +void +CShadows::CastShadowEntityXY(CEntity *pEntity, float fStartX, float fStartY, float fEndX, float fEndY, CVector *pPosn, + float fFrontX, float fFrontY, float fSideX, float fSideY, + int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, + float fZDistance, float fScale, CPolyBunch **ppPolyBunch) +{ + ASSERT(pEntity != nil); + ASSERT(pPosn != nil); + + static CVector List [20]; + static CVector Texture[20]; + static CVector Points [4]; + + CColModel *pCol = pEntity->GetColModel(); + ASSERT(pCol != nil); + +#ifndef MASTER + if ( gbPrintShite ) + printf("MI:%d Triangles:%d Coors:%f %f BBoxXY:%f %f\n", + pEntity->GetModelIndex(), + pCol->numTriangles, + pEntity->GetPosition().x, + pEntity->GetPosition().y, + pCol->boundingBox.GetSize().x, + pCol->boundingBox.GetSize().y); +#endif + + CCollision::CalculateTrianglePlanes(pCol); + + float fFrontRight = DotProduct2D(CVector2D(fFrontX, fFrontY), pEntity->GetRight()); + float fFrontForward = DotProduct2D(CVector2D(fFrontX, fFrontY), pEntity->GetForward()); + float fSideRight = DotProduct2D(CVector2D(fSideX, fSideY), pEntity->GetRight()); + float fSideForward = DotProduct2D(CVector2D(fSideX, fSideY), pEntity->GetForward()); + float fLengthRight = DotProduct2D(*pPosn - pEntity->GetPosition(), pEntity->GetRight()); + float fLengthForward = DotProduct2D(*pPosn - pEntity->GetPosition(), pEntity->GetForward()); + + Points[0].x = (fLengthRight + fFrontRight ) - fSideRight; + Points[0].y = (fLengthForward + fFrontForward) - fSideForward; + + Points[1].x = fSideRight + (fLengthRight + fFrontRight); + Points[1].y = fSideForward + (fLengthForward + fFrontForward); + + Points[2].x = fSideRight + (fLengthRight - fFrontRight); + Points[2].y = fSideForward + (fLengthForward - fFrontForward); + + Points[3].x = (fLengthRight - fFrontRight) - fSideRight; + Points[3].y = (fLengthForward - fFrontForward) - fSideForward; + + float MinX = Min(Min(Points[0].x, Points[1].x), Min(Points[2].x, Points[3].x)); + float MaxX = Max(Max(Points[0].x, Points[1].x), Max(Points[2].x, Points[3].x)); + + float MinY = Min(Min(Points[0].y, Points[1].y), Min(Points[2].y, Points[3].y)); + float MaxY = Max(Max(Points[0].y, Points[1].y), Max(Points[2].y, Points[3].y)); + + float MaxZ = pPosn->z - pEntity->GetPosition().z; + float MinZ = MaxZ - fZDistance; + + for ( int32 i = 0; i < pCol->numTriangles; i++ ) + { + CColTrianglePlane *pColTriPlanes = pCol->trianglePlanes; + ASSERT(pColTriPlanes != nil); + + CVector normal; + pColTriPlanes[i].GetNormal(normal); + if ( Abs(normal.z) > 0.1f ) + { + CColTriangle *pColTri = pCol->triangles; + ASSERT(pColTri != nil); + + CVector PointA, PointB, PointC; + + pCol->GetTrianglePoint(PointA, pColTri[i].a); + pCol->GetTrianglePoint(PointB, pColTri[i].b); + pCol->GetTrianglePoint(PointC, pColTri[i].c); + + if ( (PointA.x > MinX || PointB.x > MinX || PointC.x > MinX) + && (PointA.x < MaxX || PointB.x < MaxX || PointC.x < MaxX) + && (PointA.y > MinY || PointB.y > MinY || PointC.y > MinY) + && (PointA.y < MaxY || PointB.y < MaxY || PointC.y < MaxY) + && (PointA.z < MaxZ || PointB.z < MaxZ || PointC.z < MaxZ) + && (PointA.z > MinZ || PointB.z > MinZ || PointC.z > MinZ) ) + + { + List[0].x = Points[0].x; + List[0].y = Points[0].y; + + List[1].x = Points[1].x; + List[1].y = Points[1].y; + + List[2].x = Points[2].x; + List[2].y = Points[2].y; + + List[3].x = Points[3].x; + List[3].y = Points[3].y; + + Texture[0].x = 0.0f; + Texture[0].y = 0.0f; + + Texture[1].x = 1.0f; + Texture[1].y = 0.0f; + + Texture[2].x = 1.0f; + Texture[2].y = 1.0f; + + Texture[3].x = 0.0f; + Texture[3].y = 1.0f; + + + CVector2D start; + CVector2D dist; + + int32 numVerts1 = 0; + int16 vertType1 = 0; + { + for ( int32 j = 0; j < 4; j++ ) + { + start = PointA; + dist = PointB - PointA; + + int32 in = j; + + float cp = CrossProduct2D(CVector2D(List[in]) - start, dist); + + if ( cp > 0.0f ) + { + switch ( vertType1 ) + { + case 0: + { + int32 out = numVerts1++ + 10; + + Texture[out].x = Texture[in].x; + Texture[out].y = Texture[in].y; + List[out].x = List[in].x; + List[out].y = List[in].y; + + break; + } + + case 1: + { + int32 out = numVerts1++ + 10; + + Texture[out].x = Texture[in].x; + Texture[out].y = Texture[in].y; + List[out].x = List[in].x; + List[out].y = List[in].y; + + break; + } + + case 2: + { + float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); + + float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); + float Compl = 1.0f - Scale; + + int32 out1 = numVerts1++ + 10; + int32 out2 = numVerts1++ + 10; + + Texture[out1].x = Compl*Texture[in-1].x + Scale*Texture[in].x; + Texture[out1].y = Compl*Texture[in-1].y + Scale*Texture[in].y; + List[out1].x = Compl*List[in-1].x + Scale*List[in].x; + List[out1].y = Compl*List[in-1].y + Scale*List[in].y; + + Texture[out2].x = Texture[in].x; + Texture[out2].y = Texture[in].y; + List[out2].x = List[in].x; + List[out2].y = List[in].y; + + break; + } + } + + vertType1 = 1; + } + else + { + switch ( vertType1 ) + { + case 1: + { + float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); + + float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); + float Compl = 1.0f - Scale; + + int32 out = numVerts1++ + 10; + + Texture[out].x = Compl*Texture[in-1].x + Scale*Texture[in].x; + Texture[out].y = Compl*Texture[in-1].y + Scale*Texture[in].y; + List[out].x = Compl*List[in-1].x + Scale*List[in].x; + List[out].y = Compl*List[in-1].y + Scale*List[in].y; + + break; + } + } + + vertType1 = 2; + } + } + + float cp1 = CrossProduct2D(CVector2D(List[0]) - start, dist); + if ( cp1 > 0.0f && vertType1 == 2 || cp1 <= 0.0f && vertType1 == 1 ) + { + float cp2 = CrossProduct2D(CVector2D(List[3]) - start, dist); + + float Scale = Abs(cp2) / (Abs(cp2) + Abs(cp1)); + float Compl = 1.0f - Scale; + + int32 out = numVerts1++ + 10; + + Texture[out].x = Compl*Texture[3].x + Scale*Texture[0].x; + Texture[out].y = Compl*Texture[3].y + Scale*Texture[0].y; + List[out].x = Compl*List[3].x + Scale*List[0].x; + List[out].y = Compl*List[3].y + Scale*List[0].y; + } + } + + int32 numVerts2 = 0; + int16 vertType2 = 0; + { + for ( int32 j = 0; j < numVerts1; j++ ) + { + start = PointB; + dist = PointC - PointB; + + int32 in = j + 10; + float cp = CrossProduct2D(CVector2D(List[in]) - start, dist); + + if ( cp > 0.0f ) + { + switch ( vertType2 ) + { + case 0: + { + int32 out = numVerts2++; + + Texture[out].x = Texture[in].x; + Texture[out].y = Texture[in].y; + List[out].x = List[in].x; + List[out].y = List[in].y; + + break; + } + + case 1: + { + int32 out = numVerts2++; + + Texture[out].x = Texture[in].x; + Texture[out].y = Texture[in].y; + List[out].x = List[in].x; + List[out].y = List[in].y; + + break; + } + + case 2: + { + float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); + + float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); + float Compl = 1.0f - Scale; + + int32 out1 = numVerts2++; + int32 out2 = numVerts2++; + + Texture[out1].x = Compl*Texture[in-1].x + Scale*Texture[in].x; + Texture[out1].y = Compl*Texture[in-1].y + Scale*Texture[in].y; + List[out1].x = Compl*List[in-1].x + Scale*List[in].x; + List[out1].y = Compl*List[in-1].y + Scale*List[in].y; + + Texture[out2].x = Texture[in].x; + Texture[out2].y = Texture[in].y; + List[out2].x = List[in].x; + List[out2].y = List[in].y; + + break; + } + } + + vertType2 = 1; + } + else + { + switch ( vertType2 ) + { + case 1: + { + float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); + + float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); + float Compl = 1.0f - Scale; + + int32 out = numVerts2++; + + Texture[out].x = Compl*Texture[in-1].x + Scale*Texture[in].x; + Texture[out].y = Compl*Texture[in-1].y + Scale*Texture[in].y; + List[out].x = Compl*List[in-1].x + Scale*List[in].x; + List[out].y = Compl*List[in-1].y + Scale*List[in].y; + + break; + } + } + + vertType2 = 2; + } + } + + float cp1 = CrossProduct2D(CVector2D(List[10]) - start, dist); + if ( cp1 > 0.0f && vertType2 == 2 || cp1 <= 0.0f && vertType2 == 1 ) + { + int32 in = numVerts1 + 10; + + float cp2 = CrossProduct2D(CVector2D(List[in-1]) - start, dist); + + float Scale = Abs(cp2) / (Abs(cp2) + Abs(cp1)); + float Compl = 1.0f - Scale; + + int32 out = numVerts2++; + + Texture[out].x = Compl*Texture[in-1].x + Scale*Texture[10].x; + Texture[out].y = Compl*Texture[in-1].y + Scale*Texture[10].y; + List[out].x = Compl*List[in-1].x + Scale*List[10].x; + List[out].y = Compl*List[in-1].y + Scale*List[10].y; + } + } + + int32 numVerts3 = 0; + int16 vertType3 = 0; + { + for ( int32 j = 0; j < numVerts2; j++ ) + { + start = PointC; + dist = PointA - PointC; + + int32 in = j; + float cp = CrossProduct2D(CVector2D(List[in]) - start, dist); + + if ( cp > 0.0f ) + { + switch ( vertType3 ) + { + case 0: + { + int32 out = numVerts3++ + 10; + + Texture[out].x = Texture[in].x; + Texture[out].y = Texture[in].y; + List[out].x = List[in].x; + List[out].y = List[in].y; + + break; + } + + case 1: + { + int32 out = numVerts3++ + 10; + + Texture[out].x = Texture[in].x; + Texture[out].y = Texture[in].y; + List[out].x = List[in].x; + List[out].y = List[in].y; + + break; + } + + case 2: + { + float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); + + float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); + float Compl = 1.0f - Scale; + + int32 out1 = numVerts3++ + 10; + int32 out2 = numVerts3++ + 10; + + Texture[out1].x = Compl*Texture[in-1].x + Scale*Texture[in].x; + Texture[out1].y = Compl*Texture[in-1].y + Scale*Texture[in].y; + List[out1].x = Compl*List[in-1].x + Scale*List[in].x; + List[out1].y = Compl*List[in-1].y + Scale*List[in].y; + + Texture[out2].x = Texture[in].x; + Texture[out2].y = Texture[in].y; + List[out2].x = List[in].x; + List[out2].y = List[in].y; + + break; + } + } + + vertType3 = 1; + } + else + { + switch ( vertType3 ) + { + case 1: + { + float prevcp = CrossProduct2D(CVector2D(List[in-1]) - start, dist); + + float Scale = Abs(prevcp) / (Abs(prevcp) + Abs(cp)); + float Compl = 1.0f - Scale; + + int32 out = numVerts3++ + 10; + + Texture[out].x = Compl*Texture[in-1].x + Scale*Texture[in].x; + Texture[out].y = Compl*Texture[in-1].y + Scale*Texture[in].y; + List[out].x = Compl*List[in-1].x + Scale*List[in].x; + List[out].y = Compl*List[in-1].y + Scale*List[in].y; + + break; + } + } + + vertType3 = 2; + } + } + + float cp1 = CrossProduct2D(CVector2D(List[0]) - start, dist); + if ( cp1 > 0.0f && vertType3 == 2 || cp1 <= 0.0f && vertType3 == 1 ) + { + int32 in = numVerts2; + + float cp2 = CrossProduct2D(CVector2D(List[in-1]) - start, dist); + + float Scale = Abs(cp2) / (Abs(cp2) + Abs(cp1)); + float Compl = 1.0f - Scale; + + int32 out = numVerts3++ + 10; + + Texture[out].x = Compl*Texture[in-1].x + Scale*Texture[0].x; + Texture[out].y = Compl*Texture[in-1].y + Scale*Texture[0].y; + List[out].x = Compl*List[in-1].x + Scale*List[0].x; + List[out].y = Compl*List[in-1].y + Scale*List[0].y; + } + } + + if ( numVerts3 >= 3 ) + { + CVector norm; + + pColTriPlanes[i].GetNormal(norm); + + float dot = DotProduct(norm, PointA); + + for ( int32 j = 0; j < numVerts3; j++ ) + { + int32 idx = j + 10; + + List[idx].z = -(DotProduct2D(norm, List[idx]) - dot) / norm.z; + } + + for ( int32 j = 0; j < numVerts3; j++ ) + { + int32 idx = j + 10; + + CVector p = List[idx]; + + List[idx].x = p.y * pEntity->GetForward().x + p.x * pEntity->GetRight().x + pEntity->GetPosition().x; + List[idx].y = p.y * pEntity->GetForward().y + p.x * pEntity->GetRight().y + pEntity->GetPosition().y; + List[idx].z = p.z + pEntity->GetPosition().z; + } + + + if ( ppPolyBunch != nil ) + { + if ( pEmptyBunchList != nil ) + { + CPolyBunch *pBunch = pEmptyBunchList; + ASSERT(pBunch != nil); + pEmptyBunchList = pEmptyBunchList->m_pNext; + pBunch->m_pNext = *ppPolyBunch; + *ppPolyBunch = pBunch; + + pBunch->m_nNumVerts = numVerts3; + + for ( int32 j = 0; j < numVerts3; j++ ) + { + int32 in = j + 10; + + pBunch->m_aVerts[j] = List[in]; + + pBunch->m_aU[j] = (int32)(Texture[in].x * 200.0f); + pBunch->m_aV[j] = (int32)(Texture[in].y * 200.0f); + } + } + } + else + { + RwImVertexIndex *pIndexes; + RwIm3DVertex *pVerts; + + RenderBuffer::StartStoring(3 * (numVerts3 - 2), numVerts3, &pIndexes, &pVerts); + + ASSERT(pIndexes != nil); + ASSERT(pVerts != nil); + + + for ( int32 j = 0; j < numVerts3; j++ ) + { + int32 in = j + 10; + + RwIm3DVertexSetRGBA(&pVerts[j], nRed, nGreen, nBlue, nIntensity); + RwIm3DVertexSetU (&pVerts[j], Texture[in].x*fScale); + RwIm3DVertexSetV (&pVerts[j], Texture[in].y*fScale); + RwIm3DVertexSetPos (&pVerts[j], List[in].x, List[in].y, List[in].z + 0.03f); + } + + for ( int32 j = 0; j < 3*(numVerts3 - 2); j++ ) + pIndexes[j] = ShadowIndexList[j]; + + RenderBuffer::StopStoring(); + } + } + } + } + } +} + + +typedef struct _ProjectionParam +{ + RwV3d at; /* Camera at vector */ + RwMatrix invMatrix; /* Transforms to shadow camera space */ + RwUInt8 shadowValue; /* Shadow opacity value */ + RwBool fade; /* Shadow fades with distance */ + RwUInt32 numIm3DBatch; /* Number of buffer flushes */ + RwMatrix entityMatrix; +} +ProjectionParam; + +RwV3d *ShadowRenderTriangleCB(RwV3d *points, RwV3d *normal, ProjectionParam *param) +{ + RwV3d vIn[3]; + RwV3d vShad[3]; + + RwV3dTransformPoints(&vIn[0], points, 3, ¶m->entityMatrix); + + /* + * Reject backfacing triangles + * This reject the triangles parallel to the light as well + */ + if (RwV3dDotProduct(normal, ¶m->at) > 0.0f) + { + return points; + } + + RwV3dTransformPoints(&vShad[0], &vIn[0], 3, ¶m->invMatrix); + + /* + * Reject triangles behind the camera (z test). Note that any world + * triangles lying in front of the camera but before the object may + * have a shadow applied. To minimize such artefacts, this test could + * be modified to use a specific value rather than 0.0f, perhaps + * to reject triangles behind the center plane of the object. + * + * Reject triangles that lie entirely outside the shadow texture range + * (x,y test). + */ + if (((vShad[0].z < 0.0f) && (vShad[1].z < 0.0f) + && (vShad[2].z < 0.0f)) || ((vShad[0].x < 0.0f) + && (vShad[1].x < 0.0f) + && (vShad[2].x < 0.0f)) + || ((vShad[0].x > 1.0f) && (vShad[1].x > 1.0f) + && (vShad[2].x > 1.0f)) || ((vShad[0].y < 0.0f) + && (vShad[1].y < 0.0f) + && (vShad[2].y < 0.0f)) + || ((vShad[0].y > 1.0f) && (vShad[1].y > 1.0f) + && (vShad[2].y > 1.0f))) + { + return points; + } + + RwIm3DVertex *imv = nil; + RwImVertexIndex *imi = nil; + + RenderBuffer::StartStoring(3, 3, &imi, &imv); + + /* + * Set the immediate mode vertices for this triangle + */ + + RwIm3DVertexSetPos(imv, vIn[0].x, vIn[0].y, vIn[0].z); + RwIm3DVertexSetPos(imv + 1, vIn[1].x, vIn[1].y, vIn[1].z); + RwIm3DVertexSetPos(imv + 2, vIn[2].x, vIn[2].y, vIn[2].z); + + RwIm3DVertexSetU(imv, vShad[0].x); + RwIm3DVertexSetU(imv + 1, vShad[1].x); + RwIm3DVertexSetU(imv + 2, vShad[2].x); + + RwIm3DVertexSetV(imv, vShad[0].y); + RwIm3DVertexSetV(imv + 1, vShad[1].y); + RwIm3DVertexSetV(imv + 2, vShad[2].y); + + /* + * Do we fade out the shadow with distance? + */ + if (param->fade) + { + RwReal fadeVal; + RwUInt8 val; + + fadeVal = 1.0f - vShad[0].z * vShad[0].z; + val = + (fadeVal < + 0.0f) ? 0 : (RwUInt8) (fadeVal * param->shadowValue); + RwIm3DVertexSetRGBA(imv, val, val, val, val); + + fadeVal = 1.0f - vShad[1].z * vShad[1].z; + val = + (fadeVal < + 0.0f) ? 0 : (RwUInt8) (fadeVal * param->shadowValue); + RwIm3DVertexSetRGBA(imv + 1, val, val, val, val); + + fadeVal = 1.0f - vShad[2].z * vShad[2].z; + val = + (fadeVal < + 0.0f) ? 0 : (RwUInt8) (fadeVal * param->shadowValue); + RwIm3DVertexSetRGBA(imv + 2, val, val, val, val); + } + else + { + RwUInt8 val = param->shadowValue; + + RwIm3DVertexSetRGBA(imv, val, val, val, val); + RwIm3DVertexSetRGBA(imv + 1, val, val, val, val); + RwIm3DVertexSetRGBA(imv + 2, val, val, val, val); + } + + /* + * Update buffer position + */ + imi[0] = 0; + imi[1] = 1; + imi[2] = 2; + + RenderBuffer::StopStoring(); + + return points; +} + +void +CShadows::CastShadowEntityXYZ(CEntity *pEntity, CVector *pPosn, + float fFrontX, float fFrontY, float fSideX, float fSideY, + int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, + float fZDistance, float fScale, CPolyBunch **ppPolyBunch, CCutsceneShadow *pShadow) +{ + ASSERT(pEntity != nil); + ASSERT(pPosn != nil); + + if ( pShadow ) + { + ProjectionParam proj; + RwV3d scl; + RwV3d tr; + + CShadowCamera *shadow = pShadow->GetShadowCamera(); + CColModel *collision = pEntity->GetColModel(); + + CCollision::CalculateTrianglePlanes(collision); + + RwMatrix mat; + mat = *RwFrameGetMatrix(RwCameraGetFrame(shadow->GetRwCamera())); + + RwV3d Xaxis = { 1.0f, 0.0f, 0.0f }; + + RwMatrixRotate(&mat, &Xaxis, -45.0f, rwCOMBINEPRECONCAT); + + proj.at = mat.at; + pEntity->GetMatrix().CopyToRwMatrix(&proj.entityMatrix); + + RwMatrixInvert(&proj.invMatrix, &mat); + RwReal radius = RwCameraGetViewWindow(shadow->GetRwCamera())->x; + + scl.x = scl.y = -0.5f / (radius*0.9f); + scl.z = 1.0f / (radius*0.8f); + RwMatrixScale(&proj.invMatrix, &scl, rwCOMBINEPOSTCONCAT); + + tr.x = 0.5f; + tr.y = tr.z = 0.0f; + RwMatrixTranslate(&proj.invMatrix, &tr, rwCOMBINEPOSTCONCAT); + + proj.shadowValue = nIntensity; + proj.fade = 0; + + RwMatrix matrix; + pEntity->GetMatrix().CopyToRwMatrix(&matrix); + RwMatrix invMatrix; + RwMatrixInvert(&invMatrix, &matrix); + + + CVector center(pShadow->GetBaseSphere().center); + center += CVector(-fFrontX * 1.1f, -fFrontY * 1.1f, -0.5f); + + CSphere sphere; + sphere.Set(2.0f, center); + + RwV3d point; + RwV3dTransformPoints(&point, ¢er, 1, &invMatrix); + + CColSphere colSphere; + colSphere.Set(2.0f, CVector(point), 0, 0); + + int i = 0; + while ( i < collision->numTriangles ) + { + CVector p[3]; + + collision->GetTrianglePoint(p[0], collision->triangles[i].a); + collision->GetTrianglePoint(p[1], collision->triangles[i].b); + collision->GetTrianglePoint(p[2], collision->triangles[i].c); + + if ( CCollision::TestSphereTriangle(colSphere, collision->vertices, collision->triangles[i], collision->trianglePlanes[i]) ) + { + CVector n(collision->trianglePlanes[i].GetNormalX(), collision->trianglePlanes[i].GetNormalY(), collision->trianglePlanes[i].GetNormalZ()); + CVector offset = n * 0.028f; + + p[0] += offset; + p[1] += offset; + p[2] += offset; + + if ( !ShadowRenderTriangleCB(p, &n, &proj) ) + break; + } + i++; + } + } +} + +void +CShadows::UpdateStaticShadows(void) +{ + for ( int32 i = 0; i < MAX_STATICSHADOWS; i++ ) + { + if ( aStaticShadows[i].m_pPolyBunch != nil && !aStaticShadows[i].m_bJustCreated + && (!aStaticShadows[i].m_bTemp || CTimer::GetTimeInMilliseconds() > aStaticShadows[i].m_nTimeCreated + 5000) ) + { + aStaticShadows[i].Free(); + } + + aStaticShadows[i].m_bJustCreated = false; + } +} + +void +CShadows::UpdatePermanentShadows(void) +{ + for ( int32 i = 0; i < MAX_PERMAMENTSHADOWS; i++ ) + { + if ( aPermanentShadows[i].m_nType != SHADOWTYPE_NONE ) + { + uint32 timePassed = CTimer::GetTimeInMilliseconds() - aPermanentShadows[i].m_nTimeCreated; + + if ( timePassed >= aPermanentShadows[i].m_nLifeTime ) + aPermanentShadows[i].m_nType = SHADOWTYPE_NONE; + else + { + bool bOk; + if ( timePassed >= (aPermanentShadows[i].m_nLifeTime * 3 / 4) ) + { + // timePassed == 0 -> 4 + // timePassed == aPermanentShadows[i].m_nLifeTime -> 0 + float fMult = 1.0f - float(timePassed - (aPermanentShadows[i].m_nLifeTime * 3 / 4)) / (aPermanentShadows[i].m_nLifeTime / 4); + + bOk = StoreStaticShadow((uintptr)&aPermanentShadows[i], + aPermanentShadows[i].m_nType, + aPermanentShadows[i].m_pTexture, + &aPermanentShadows[i].m_vecPos, + aPermanentShadows[i].m_vecFront.x, + aPermanentShadows[i].m_vecFront.y, + aPermanentShadows[i].m_vecSide.x, + aPermanentShadows[i].m_vecSide.y, + (int32)(aPermanentShadows[i].m_nIntensity * fMult), + (int32)(aPermanentShadows[i].m_nRed * fMult), + (int32)(aPermanentShadows[i].m_nGreen * fMult), + (int32)(aPermanentShadows[i].m_nBlue * fMult), + aPermanentShadows[i].m_fZDistance, + 1.0f, 40.0f, false, 0.0f); + } + else + { + bOk = StoreStaticShadow((uintptr)&aPermanentShadows[i], + aPermanentShadows[i].m_nType, + aPermanentShadows[i].m_pTexture, + &aPermanentShadows[i].m_vecPos, + aPermanentShadows[i].m_vecFront.x, + aPermanentShadows[i].m_vecFront.y, + aPermanentShadows[i].m_vecSide.x, + aPermanentShadows[i].m_vecSide.y, + aPermanentShadows[i].m_nIntensity, + aPermanentShadows[i].m_nRed, + aPermanentShadows[i].m_nGreen, + aPermanentShadows[i].m_nBlue, + aPermanentShadows[i].m_fZDistance, + 1.0f, 40.0f, false, 0.0f); + } + + if ( !bOk ) + aPermanentShadows[i].m_nType = SHADOWTYPE_NONE; + } + } + } +} + +void +CStaticShadow::Free(void) +{ + if ( m_pPolyBunch != nil ) + { + CPolyBunch *pFree = CShadows::pEmptyBunchList; + CShadows::pEmptyBunchList = m_pPolyBunch; + + CPolyBunch *pUsed = m_pPolyBunch; + while (pUsed->m_pNext != nil) + pUsed = pUsed->m_pNext; + + pUsed->m_pNext = pFree; + } + + m_pPolyBunch = nil; + + m_nId = 0; +} + +void +CShadows::CalcPedShadowValues(CVector vecLightDir, + float *pfFrontX, float *pfFrontY, + float *pfSideX, float *pfSideY, + float *pfDisplacementX, float *pfDisplacementY) +{ + ASSERT(pfFrontX != nil); + ASSERT(pfFrontY != nil); + ASSERT(pfSideX != nil); + ASSERT(pfSideY != nil); + ASSERT(pfDisplacementX != nil); + ASSERT(pfDisplacementY != nil); + + *pfFrontX = -vecLightDir.x; + *pfFrontY = -vecLightDir.y; + + float fDist = Sqrt(*pfFrontY * *pfFrontY + *pfFrontX * *pfFrontX); + float fMult = (fDist + 1.0f) / fDist; + + *pfFrontX *= fMult; + *pfFrontY *= fMult; + + *pfSideX = -vecLightDir.y / fDist; + *pfSideY = vecLightDir.x / fDist; + + *pfDisplacementX = -vecLightDir.x; + *pfDisplacementY = -vecLightDir.y; + + *pfFrontX /= 2; + *pfFrontY /= 2; + + *pfSideX /= 2; + *pfSideY /= 2; + + *pfDisplacementX /= 2; + *pfDisplacementY /= 2; + +} + + +void +CShadows::RenderExtraPlayerShadows(void) +{ +#ifdef FIX_BUGS + if (CReplay::IsPlayingBack()) + return; +#endif + if ( CTimeCycle::GetLightShadowStrength() != 0 ) + { + CVehicle *pCar = FindPlayerVehicle(); + if ( pCar == nil ) + ; // R* cut it out for playerped + else + { + if ( pCar->GetModelIndex() != MI_RCBANDIT + && pCar->GetVehicleAppearance() != VEHICLE_APPEARANCE_BIKE + && !pCar->IsBike() && !pCar->IsPlane() && !pCar->IsBoat() ) + { + for ( int32 i = 0; i < CPointLights::NumLights; i++ ) + { + if ( CPointLights::aLights[i].type == CPointLights::LIGHT_POINT + && CPointLights::aLights[i].castExtraShadows + &&(0.0f != CPointLights::aLights[i].red + || 0.0f != CPointLights::aLights[i].green + || 0.0f != CPointLights::aLights[i].blue) ) + { + CVector vecLight = CPointLights::aLights[i].coors - FindPlayerCoors(); + float fLightDist = vecLight.Magnitude(); + float fRadius = CPointLights::aLights[i].radius; + + if ( fLightDist < fRadius ) + { + // fLightDist == 0 -> 2.0f + // fLightDist == fRadius -> 0.0f + float fMult = (1.0f - (2.0f * fLightDist - fRadius) / fRadius); + + int32 nColorStrength; + if ( fLightDist < fRadius*0.5f ) + nColorStrength = (5*CTimeCycle::GetLightShadowStrength()/8); + else + nColorStrength = int32((5*CTimeCycle::GetLightShadowStrength()/8) * fMult); + + float fInv = 1.0f / fLightDist; + vecLight.x *= fInv; + vecLight.y *= fInv; + vecLight.z *= fInv; + + CVector shadowPos = pCar->GetPosition(); + + shadowPos.x -= vecLight.x * 1.2f; + shadowPos.y -= vecLight.y * 1.2f; + + float fVehicleWidth = pCar->GetColModel()->boundingBox.GetSize().x; + float fVehicleHeight = pCar->GetColModel()->boundingBox.GetSize().y; + + shadowPos.x -= ((fVehicleHeight/2) - pCar->GetColModel()->boundingBox.max.y) + * pCar->GetForward().x; + + shadowPos.y -= ((fVehicleHeight/2) - pCar->GetColModel()->boundingBox.max.y) + * pCar->GetForward().y; + + if ( pCar->GetUp().z > 0.0f ) + { + StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowCarTex, &shadowPos, + pCar->GetForward().x * (fVehicleHeight/2), + pCar->GetForward().y * (fVehicleHeight/2), + pCar->GetRight().x * (fVehicleWidth/3), + pCar->GetRight().y * (fVehicleWidth/3), + nColorStrength, 0, 0, 0, + 4.5f, false, 1.0f, nil, false); + } + else + { + StoreShadowToBeRendered(SHADOWTYPE_DARK, gpShadowCarTex, &shadowPos, + pCar->GetForward().x * (fVehicleHeight/2), + pCar->GetForward().y * (fVehicleHeight/2), + -pCar->GetRight().x * (fVehicleWidth/2), + -pCar->GetRight().y * (fVehicleWidth/2), + nColorStrength, 0, 0, 0, + 4.5f, false, 1.0f, nil, false); + } + } + } + } + } + } + } +} + +void +CShadows::TidyUpShadows(void) +{ + for ( int32 i = 0; i < MAX_PERMAMENTSHADOWS; i++ ) + aPermanentShadows[i].m_nType = SHADOWTYPE_NONE; +} + +void +CShadows::RenderIndicatorShadow(uint32 nID, uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, + float fFrontX, float fFrontY, float fSideX, float fSideY, + int16 nIntensity) +{ + ASSERT(pPosn != nil); + + C3dMarkers::PlaceMarkerSet(nID, MARKERTYPE_CYLINDER, *pPosn, Max(fFrontX, -fSideY), + SPHERE_MARKER_R, SPHERE_MARKER_G, SPHERE_MARKER_B, + SPHERE_MARKER_A, SPHERE_MARKER_PULSE_PERIOD, 0.2f, 0); +} diff --git a/src/renderer/Shadows.h b/src/renderer/Shadows.h new file mode 100644 index 00000000..937ff4eb --- /dev/null +++ b/src/renderer/Shadows.h @@ -0,0 +1,210 @@ +#pragma once + +#define MAX_STOREDSHADOWS 48 +#define MAX_POLYBUNCHES 380 +#define MAX_STATICSHADOWS 48 +#define MAX_PERMAMENTSHADOWS 48 + + + +class CEntity; +class CPtrList; +class CAutomobile; +class CVehicle; +class CPed; +class CCutsceneShadow; +class CCutsceneObject; + +enum eShadowType +{ + SHADOWTYPE_NONE = 0, + SHADOWTYPE_DARK, + SHADOWTYPE_ADDITIVE, + SHADOWTYPE_INVCOLOR +}; + +enum eShadowTextureType +{ + SHADOWTEX_NONE = 0, + SHADOWTEX_CAR, + SHADOWTEX_PED, + SHADOWTEX_EXPLOSION, + SHADOWTEX_HELI, + SHADOWTEX_HEADLIGHTS, + SHADOWTEX_BLOOD +}; + +enum VEH_SHD_TYPE +{ + VEH_SHD_TYPE_CAR = 0, + VEH_SHD_TYPE_BIKE, + VEH_SHD_TYPE_HELI, + VEH_SHD_TYPE_SEAPLANE, + VEH_SHD_TYPE_RCPLANE, +}; + + +class CStoredShadow +{ +public: + CVector m_vecPos; + CVector2D m_vecFront; + CVector2D m_vecSide; + float m_fZDistance; + float m_fScale; + RwTexture *m_pTexture; + CCutsceneShadow *m_pCutsceneShadow; + int16 m_nIntensity; + uint8 m_ShadowType; + uint8 m_nRed; + uint8 m_nGreen; + uint8 m_nBlue; + struct + { + uint8 bDrawOnWater : 1; + uint8 bRendered : 1; + uint8 bDrawOnBuildings : 1; + } m_nFlags; + + + CStoredShadow() + { } +}; + +VALIDATE_SIZE(CStoredShadow, 0x30); + +class CPolyBunch +{ +public: + CVector m_aVerts[7]; + CPolyBunch *m_pNext; + int16 m_nNumVerts; + uint8 m_aU[7]; + uint8 m_aV[7]; + + CPolyBunch() + { } +}; + +VALIDATE_SIZE(CPolyBunch, 0x6C); + +class CStaticShadow +{ +public: + uint32 m_nId; + CPolyBunch *m_pPolyBunch; + uint32 m_nTimeCreated; + CVector m_vecPosn; + CVector2D m_vecFront; + CVector2D m_vecSide; + float m_fZDistance; + float m_fScale; + RwTexture *m_pTexture; + int16 m_nIntensity; // unsigned ? + uint8 m_nType; + uint8 m_nRed; + uint8 m_nGreen; + uint8 m_nBlue; + bool m_bJustCreated; + bool m_bRendered; + bool m_bTemp; + + + CStaticShadow() + { } + + void Free(); +}; + +VALIDATE_SIZE(CStaticShadow, 0x40); + +class CPermanentShadow +{ +public: + CVector m_vecPos; + CVector2D m_vecFront; + CVector2D m_vecSide; + float m_fZDistance; + float m_fScale; + uint32 m_nTimeCreated; + uint32 m_nLifeTime; + RwTexture *m_pTexture; + int16 m_nIntensity; + uint8 m_nType; // eShadowType + uint8 m_nRed; + uint8 m_nGreen; + uint8 m_nBlue; + + CPermanentShadow() + { } +}; + +VALIDATE_SIZE(CPermanentShadow, 0x38); + +class CShadows +{ +public: + static int16 ShadowsStoredToBeRendered; + static CStoredShadow asShadowsStored [MAX_STOREDSHADOWS]; + static CPolyBunch aPolyBunches [MAX_POLYBUNCHES]; + static CStaticShadow aStaticShadows [MAX_STATICSHADOWS]; + static CPolyBunch *pEmptyBunchList; + static CPermanentShadow aPermanentShadows[MAX_PERMAMENTSHADOWS]; + + static void Init (void); + static void Shutdown (void); + static void AddPermanentShadow ( uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, uint32 nTime, float fScale); + + static bool StoreStaticShadow (uint32 nID, uint8 ShadowType, RwTexture *pTexture, Const CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, float fDrawDistance, bool bTempShadow, float fUpDistance); + static void StoreShadowToBeRendered ( uint8 ShadowType, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue); + static void StoreShadowToBeRendered ( uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, bool bDrawOnWater, float fScale, CCutsceneShadow *pShadow, bool bDrawOnBuildings); + static void StoreShadowForVehicle (CVehicle *pCar, VEH_SHD_TYPE type); + static void StoreCarLightShadow (CVehicle *pCar, int32 nID, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, uint8 nRed, uint8 nGreen, uint8 nBlue, float fMaxViewAngle); + static void StoreShadowForPed (CPed *pPed, float fDisplacementX, float fDisplacementY, float fFrontX, float fFrontY, float fSideX, float fSideY); + static void StoreShadowForPedObject (CEntity *pPedObject, float fDisplacementX, float fDisplacementY, float fFrontX, float fFrontY, float fSideX, float fSideY); + static void StoreShadowForCutscenePedObject(CCutsceneObject *pObject, float fDisplacementX, float fDisplacementY, float fFrontX, float fFrontY, float fSideX, float fSideY); + static void StoreShadowForTree (CEntity *pTree); + static void StoreShadowForPole (CEntity *pPole, float fOffsetX, float fOffsetY, float fOffsetZ, float fPoleHeight, float fPoleWidth, uint32 nID); + static void SetRenderModeForShadowType (uint8 ShadowType); + static void RenderStoredShadows (void); + static void RenderStaticShadows (void); + + static void GeneratePolysForStaticShadow (int16 nStaticShadowID); + static void CastShadowSectorList (CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, + CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch); + + static void CastPlayerShadowSectorList (CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, + CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch); + + static void CastCutsceneShadowSectorList (CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY, + CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch, CCutsceneShadow *pShadow); + + static void CastShadowEntityXY (CEntity *pEntity, float fStartX, float fStartY, float fEndX, float fEndY, + CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch); + + static void CastShadowEntityXYZ (CEntity *pEntity, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch, CCutsceneShadow *pShadow); + + static void UpdateStaticShadows (void); + static void UpdatePermanentShadows (void); + static void CalcPedShadowValues (CVector vecLightDir, float *pfFrontX, float *pfFrontY, float *pfSideX, float *pfSideY, float *pfDisplacementX, float *pfDisplacementY); + static void RenderExtraPlayerShadows (void); + static void TidyUpShadows (void); + static void RenderIndicatorShadow (uint32 nID, uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity); +}; + +extern RwTexture *gpShadowCarTex; +extern RwTexture *gpShadowPedTex; +extern RwTexture *gpShadowHeliTex; +extern RwTexture *gpShadowBikeTex; +extern RwTexture *gpShadowBaronTex; +extern RwTexture *gpShadowExplosionTex; +extern RwTexture *gpShadowHeadLightsTex; +extern RwTexture *gpOutline1Tex; +extern RwTexture *gpOutline2Tex; +extern RwTexture *gpOutline3Tex; +extern RwTexture *gpBloodPoolTex; +extern RwTexture *gpReflectionTex; +extern RwTexture *gpWalkDontTex; +extern RwTexture *gpCrackedGlassTex; +extern RwTexture *gpPostShadowTex; +extern RwTexture *gpGoalTex; diff --git a/src/renderer/Skidmarks.cpp b/src/renderer/Skidmarks.cpp new file mode 100644 index 00000000..08df330d --- /dev/null +++ b/src/renderer/Skidmarks.cpp @@ -0,0 +1,259 @@ +#include "common.h" + +#include "main.h" +#include "TxdStore.h" +#include "Timer.h" +#include "Replay.h" +#include "Skidmarks.h" + +CSkidmark CSkidmarks::aSkidmarks[NUMSKIDMARKS]; + +RwImVertexIndex SkidmarkIndexList[SKIDMARK_LENGTH * 6]; +RwIm3DVertex SkidmarkVertices[SKIDMARK_LENGTH * 2]; +RwTexture *gpSkidTex; + +void +CSkidmarks::Init(void) +{ + int i, ix, slot; + CTxdStore::PushCurrentTxd(); + slot = CTxdStore::FindTxdSlot("particle"); + CTxdStore::SetCurrentTxd(slot); + gpSkidTex = RwTextureRead("particleskid", nil); + CTxdStore::PopCurrentTxd(); + + for(i = 0; i < NUMSKIDMARKS; i++){ + aSkidmarks[i].m_state = 0; + aSkidmarks[i].m_wasUpdated = false; + } + + ix = 0; + for(i = 0; i < SKIDMARK_LENGTH; i++){ + SkidmarkIndexList[i*6+0] = ix+0; + SkidmarkIndexList[i*6+1] = ix+2; + SkidmarkIndexList[i*6+2] = ix+1; + SkidmarkIndexList[i*6+3] = ix+1; + SkidmarkIndexList[i*6+4] = ix+2; + SkidmarkIndexList[i*6+5] = ix+3; + ix += 2; + } +} + +void +CSkidmarks::Shutdown(void) +{ + RwTextureDestroy(gpSkidTex); + gpSkidTex = nil; +} + +void +CSkidmarks::Clear(void) +{ + int i; + for(i = 0; i < NUMSKIDMARKS; i++){ + aSkidmarks[i].m_state = 0; + aSkidmarks[i].m_wasUpdated = false; + } +} + +void +CSkidmarks::Update(void) +{ + int i; + uint32 t1 = CTimer::GetTimeInMilliseconds() + 2500; + uint32 t2 = CTimer::GetTimeInMilliseconds() + 5000; + uint32 t3 = CTimer::GetTimeInMilliseconds() + 10000; + uint32 t4 = CTimer::GetTimeInMilliseconds() + 20000; + for(i = 0; i < NUMSKIDMARKS; i++){ + switch(aSkidmarks[i].m_state){ + case 1: + if(!aSkidmarks[i].m_wasUpdated){ + // Didn't continue this one last time, so finish it and set fade times + aSkidmarks[i].m_state = 2; + if(aSkidmarks[i].m_last < 4){ + aSkidmarks[i].m_fadeStart = t1; + aSkidmarks[i].m_fadeEnd = t2; + }else if(aSkidmarks[i].m_last < 9){ + aSkidmarks[i].m_fadeStart = t2; + aSkidmarks[i].m_fadeEnd = t3; + }else{ + aSkidmarks[i].m_fadeStart = t3; + aSkidmarks[i].m_fadeEnd = t4; + } + } + break; + case 2: + if(CTimer::GetTimeInMilliseconds() > aSkidmarks[i].m_fadeEnd) + aSkidmarks[i].m_state = 0; + break; + } + aSkidmarks[i].m_wasUpdated = false; + } +} + +void +CSkidmarks::Render(void) +{ + int i, j; + + PUSH_RENDERGROUP("CSkidmarks::Render"); + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpSkidTex)); + + for(i = 0; i < NUMSKIDMARKS; i++){ + if(aSkidmarks[i].m_state == 0 || aSkidmarks[i].m_last < 1) + continue; + + CRGBA color(0, 0, 0, 255); + switch(aSkidmarks[i].m_type){ + case SKIDMARK_NORMAL: color = CRGBA(0, 0, 0, 255); break; + case SKIDMARK_MUDDY: color = CRGBA(90, 62, 9, 255); break; + case SKIDMARK_SANDY: color = CRGBA(108, 108, 96, 255); break; + case SKIDMARK_BLOODY: color = CRGBA(132, 34, 11, 255); break; + } + + uint32 fade, alpha; + if(aSkidmarks[i].m_state == 1 || CTimer::GetTimeInMilliseconds() < aSkidmarks[i].m_fadeStart) + fade = 255; + else + fade = 255*(aSkidmarks[i].m_fadeEnd - CTimer::GetTimeInMilliseconds()) / (aSkidmarks[i].m_fadeEnd - aSkidmarks[i].m_fadeStart); + + for(j = 0; j <= aSkidmarks[i].m_last; j++){ + alpha = 128; + if(j == 0 || j == aSkidmarks[i].m_last && aSkidmarks[i].m_state == 2) + alpha = 0; + alpha = alpha*fade/256; + + CVector p1 = aSkidmarks[i].m_pos[j]; + p1.x += aSkidmarks[i].m_sideX[j]; + p1.y += aSkidmarks[i].m_sideY[j]; + CVector p2 = aSkidmarks[i].m_pos[j]; + p2.x -= aSkidmarks[i].m_sideX[j]; + p2.y -= aSkidmarks[i].m_sideY[j]; + RwIm3DVertexSetRGBA(&SkidmarkVertices[j*2+0], color.red, color.green, color.blue, alpha); + RwIm3DVertexSetPos(&SkidmarkVertices[j*2+0], p1.x, p1.y, p1.z+0.1f); + RwIm3DVertexSetU(&SkidmarkVertices[j*2+0], 0.0f); + RwIm3DVertexSetV(&SkidmarkVertices[j*2+0], j*5.01f); + RwIm3DVertexSetRGBA(&SkidmarkVertices[j*2+1], color.red, color.green, color.blue, alpha); + RwIm3DVertexSetPos(&SkidmarkVertices[j*2+1], p2.x, p2.y, p2.z+0.1f); + RwIm3DVertexSetU(&SkidmarkVertices[j*2+1], 1.0f); + RwIm3DVertexSetV(&SkidmarkVertices[j*2+1], j*5.01f); + } + + LittleTest(); + if(RwIm3DTransform(SkidmarkVertices, 2*(aSkidmarks[i].m_last+1), nil, rwIM3D_VERTEXUV)){ + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, SkidmarkIndexList, 6*aSkidmarks[i].m_last); + RwIm3DEnd(); + } + } + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + + POP_RENDERGROUP(); +} + +void +CSkidmarks::RegisterOne(uintptr id, const CVector &pos, float fwdX, float fwdY, bool *isMuddy, bool *isBloody) +{ + eSkidmarkType type; + if(*isBloody) + type = SKIDMARK_BLOODY; + else if(*isMuddy) + type = SKIDMARK_MUDDY; + else + type = SKIDMARK_NORMAL; + RegisterOne(id, pos, fwdX, fwdY, type, isBloody); +} + +void +CSkidmarks::RegisterOne(uintptr id, const CVector &pos, float fwdX, float fwdY, eSkidmarkType type, bool *isBloody) +{ + int i; + CVector2D fwd(fwdX, fwdY); + + if(CReplay::IsPlayingBack()) + return; + + // Find a skidmark to continue + for(i = 0; i < NUMSKIDMARKS; i++) + if(aSkidmarks[i].m_state == 1 && aSkidmarks[i].m_id == id) + break; + + if(i < NUMSKIDMARKS){ + // Continue this one + + if((aSkidmarks[i].m_type==SKIDMARK_BLOODY) != *isBloody){ + // Blood-status changed, end this one + aSkidmarks[i].m_state = 2; + aSkidmarks[i].m_fadeStart = CTimer::GetTimeInMilliseconds() + 10000; + aSkidmarks[i].m_fadeEnd = CTimer::GetTimeInMilliseconds() + 20000; + return; + } + + aSkidmarks[i].m_wasUpdated = true; + + if(CTimer::GetTimeInMilliseconds() - aSkidmarks[i].m_lastUpdate <= 100){ + // Last update was recently, just change last coords + aSkidmarks[i].m_pos[aSkidmarks[i].m_last] = pos; + return; + } + aSkidmarks[i].m_lastUpdate = CTimer::GetTimeInMilliseconds(); + + if(aSkidmarks[i].m_last >= SKIDMARK_LENGTH-1){ + // No space to continue, end it + aSkidmarks[i].m_state = 2; + aSkidmarks[i].m_fadeStart = CTimer::GetTimeInMilliseconds() + 10000; + aSkidmarks[i].m_fadeEnd = CTimer::GetTimeInMilliseconds() + 20000; + *isBloody = false; // stpo blood marks at end + return; + } + aSkidmarks[i].m_last++; + + aSkidmarks[i].m_pos[aSkidmarks[i].m_last] = pos; + + CVector2D right(aSkidmarks[i].m_pos[aSkidmarks[i].m_last].y - aSkidmarks[i].m_pos[aSkidmarks[i].m_last - 1].y, + aSkidmarks[i].m_pos[aSkidmarks[i].m_last - 1].x - aSkidmarks[i].m_pos[aSkidmarks[i].m_last].x); + + right.Normalise(); + fwd.Normalise(); + float turn = DotProduct2D(fwd, right); + turn = Abs(turn) + 1.0f; + aSkidmarks[i].m_sideX[aSkidmarks[i].m_last] = right.x * turn * 0.125f; + aSkidmarks[i].m_sideY[aSkidmarks[i].m_last] = right.y * turn * 0.125f; + if(aSkidmarks[i].m_last == 1){ + aSkidmarks[i].m_sideX[0] = aSkidmarks[i].m_sideX[1]; + aSkidmarks[i].m_sideY[0] = aSkidmarks[i].m_sideY[1]; + } + + if(aSkidmarks[i].m_last > 8) + *isBloody = false; // stop blood marks after 8 + return; + } + + // Start a new one + for(i = 0; i < NUMSKIDMARKS; i++) + if(aSkidmarks[i].m_state == 0) + break; + if(i < NUMSKIDMARKS){ + // Found a free slot + aSkidmarks[i].m_state = 1; + aSkidmarks[i].m_id = id; + aSkidmarks[i].m_pos[0] = pos; + aSkidmarks[i].m_sideX[0] = 0.0f; + aSkidmarks[i].m_sideY[0] = 0.0f; + aSkidmarks[i].m_wasUpdated = true; + aSkidmarks[i].m_last = 0; + aSkidmarks[i].m_lastUpdate = CTimer::GetTimeInMilliseconds() - 1000; + if(*isBloody) + aSkidmarks[i].m_type = SKIDMARK_BLOODY; + else + aSkidmarks[i].m_type = type; + }else + *isBloody = false; // stop blood marks if no space +} diff --git a/src/renderer/Skidmarks.h b/src/renderer/Skidmarks.h new file mode 100644 index 00000000..28082f08 --- /dev/null +++ b/src/renderer/Skidmarks.h @@ -0,0 +1,41 @@ +#pragma once + +enum { SKIDMARK_LENGTH = 16 }; + +enum eSkidmarkType +{ + SKIDMARK_NORMAL, + SKIDMARK_MUDDY, + SKIDMARK_SANDY, + SKIDMARK_BLOODY +}; + +class CSkidmark +{ +public: + CVector m_pos[SKIDMARK_LENGTH]; + float m_sideX[SKIDMARK_LENGTH]; + float m_sideY[SKIDMARK_LENGTH]; + uintptr m_id; + uint32 m_lastUpdate; + uint32 m_fadeStart; + uint32 m_fadeEnd; + uint32 m_type; + int16 m_last; + uint8 m_state; + bool m_wasUpdated; +}; + +class CSkidmarks +{ + static CSkidmark aSkidmarks[NUMSKIDMARKS]; +public: + + static void Init(void); + static void Shutdown(void); + static void Clear(void); + static void Update(void); + static void Render(void); + static void RegisterOne(uintptr id, const CVector &pos, float fwdX, float fwdY, eSkidmarkType type, bool *isBloody); + static void RegisterOne(uintptr id, const CVector &pos, float fwdX, float fwdY, bool *isMuddy, bool *isBloody); +}; diff --git a/src/renderer/SpecialFX.cpp b/src/renderer/SpecialFX.cpp new file mode 100644 index 00000000..61750f85 --- /dev/null +++ b/src/renderer/SpecialFX.cpp @@ -0,0 +1,1493 @@ +#include "common.h" + +#include "SpecialFX.h" +#include "RenderBuffer.h" +#include "Timer.h" +#include "Sprite.h" +#include "Font.h" +#include "Text.h" +#include "TxdStore.h" +#include "FileMgr.h" +#include "FileLoader.h" +#include "Timecycle.h" +#include "Lights.h" +#include "ModelIndices.h" +#include "VisibilityPlugins.h" +#include "World.h" +#include "PlayerPed.h" +#include "Particle.h" +#include "Shadows.h" +#include "General.h" +#include "Camera.h" +#include "Shadows.h" +#include "main.h" +#include "ColStore.h" +#include "Coronas.h" +#include "Script.h" +#include "DMAudio.h" + +RwIm3DVertex StreakVertices[4]; +RwImVertexIndex StreakIndexList[12]; + +RwIm3DVertex TraceVertices[10]; +static RwImVertexIndex TraceIndexList[48] = {0, 5, 7, 0, 7, 2, 0, 7, 5, 0, 2, 7, 0, 4, 9, 0, + 9, 5, 0, 9, 4, 0, 5, 9, 0, 1, 6, 0, 6, 5, 0, 6, + 1, 0, 5, 6, 0, 3, 8, 0, 8, 5, 0, 8, 3, 0, 5, 8 }; + +bool CSpecialFX::bVideoCam; +bool CSpecialFX::bLiftCam; +bool CSpecialFX::bSnapShotActive; +int32 CSpecialFX::SnapShotFrames; +static RwTexture* gpSmokeTrailTexture; + + +void +CSpecialFX::Init(void) +{ + CBulletTraces::Init(); + + RwIm3DVertexSetU(&TraceVertices[0], 0.0); + RwIm3DVertexSetV(&TraceVertices[0], 0.0); + RwIm3DVertexSetU(&TraceVertices[1], 1.0); + RwIm3DVertexSetV(&TraceVertices[1], 0.0); + RwIm3DVertexSetU(&TraceVertices[2], 1.0); + RwIm3DVertexSetV(&TraceVertices[2], 0.0); + RwIm3DVertexSetU(&TraceVertices[3], 1.0); + RwIm3DVertexSetV(&TraceVertices[3], 0.0); + RwIm3DVertexSetU(&TraceVertices[4], 1.0); + RwIm3DVertexSetV(&TraceVertices[4], 0.0); + RwIm3DVertexSetU(&TraceVertices[5], 0.0); + RwIm3DVertexSetU(&TraceVertices[6], 1.0); + RwIm3DVertexSetU(&TraceVertices[7], 1.0); + RwIm3DVertexSetU(&TraceVertices[8], 1.0); + RwIm3DVertexSetU(&TraceVertices[9], 1.0); + + RwIm3DVertexSetU(&StreakVertices[0], 0.0f); + RwIm3DVertexSetV(&StreakVertices[0], 0.0f); + RwIm3DVertexSetU(&StreakVertices[1], 1.0f); + RwIm3DVertexSetV(&StreakVertices[1], 0.0f); + RwIm3DVertexSetU(&StreakVertices[2], 0.0f); + RwIm3DVertexSetV(&StreakVertices[2], 0.0f); + RwIm3DVertexSetU(&StreakVertices[3], 1.0f); + RwIm3DVertexSetV(&StreakVertices[3], 0.0f); + StreakIndexList[0] = 0; + StreakIndexList[1] = 1; + StreakIndexList[2] = 2; + StreakIndexList[3] = 1; + StreakIndexList[4] = 3; + StreakIndexList[5] = 2; + StreakIndexList[6] = 0; + StreakIndexList[7] = 2; + StreakIndexList[8] = 1; + StreakIndexList[9] = 1; + StreakIndexList[10] = 2; + StreakIndexList[11] = 3; + + CMotionBlurStreaks::Init(); + CBrightLights::Init(); + CShinyTexts::Init(); + CMoneyMessages::Init(); + C3dMarkers::Init(); + CSpecialFX::bSnapShotActive = false; + CSpecialFX::bVideoCam = false; + CSpecialFX::SnapShotFrames = 0; + CSpecialFX::bLiftCam = false; + CTxdStore::PushCurrentTxd(); + CTxdStore::SetCurrentTxd(CTxdStore::FindTxdSlot("particle")); + if(gpSmokeTrailTexture == nil) + gpSmokeTrailTexture = RwTextureRead("smoketrail", 0); + CTxdStore::PopCurrentTxd(); +} + +void +CSpecialFX::AddWeaponStreak(int type) +{ + static CMatrix matrix; + CVector start; + CVector end; + + if (FindPlayerPed() != nil && FindPlayerPed()->m_pWeaponModel != nil) { + switch (type) { + case WEAPONTYPE_BASEBALLBAT: + matrix = RwFrameGetLTM(RpAtomicGetFrame(FindPlayerPed()->m_pWeaponModel)); + start = matrix * CVector(0.02f, 0.05f, 0.07f); + end = matrix * CVector(0.246f, 0.0325f, 0.796f); + break; + case WEAPONTYPE_GOLFCLUB: + matrix = RwFrameGetLTM(RpAtomicGetFrame(FindPlayerPed()->m_pWeaponModel)); + start = matrix * CVector(0.02f, 0.05f, 0.07f); + end = matrix * CVector(-0.054f, 0.0325f, 0.796f); + break; + case WEAPONTYPE_KATANA: + matrix = RwFrameGetLTM(RpAtomicGetFrame(FindPlayerPed()->m_pWeaponModel)); + start = matrix * CVector(0.02f, 0.05f, 0.07f); + end = matrix * CVector(0.096f, -0.0175f, 1.096f); + break; + default: + return; + } + CMotionBlurStreaks::RegisterStreak((uintptr)FindPlayerPed()->m_pWeaponModel, 100, 100, 100, start, end); + } +} + +RwObject* +LookForBatCB(RwObject *object, void *data) +{ + static CMatrix MatLTM; + + if(CVisibilityPlugins::GetAtomicModelInfo((RpAtomic*)object) == (CSimpleModelInfo*)data){ + MatLTM = CMatrix(RwFrameGetLTM(RpAtomicGetFrame((RpAtomic*)object))); + CVector p1 = MatLTM * CVector(0.02f, 0.05f, 0.07f); + CVector p2 = MatLTM * CVector(0.246f, 0.0325f, 0.796f); + CMotionBlurStreaks::RegisterStreak((uintptr)object, 100, 100, 100, p1, p2); + } + return nil; +} + +void +CSpecialFX::Update(void) +{ + CMotionBlurStreaks::Update(); + CBulletTraces::Update(); +} + +void +CSpecialFX::Shutdown(void) +{ + C3dMarkers::Shutdown(); + if (gpSmokeTrailTexture) { + RwTextureDestroy(gpSmokeTrailTexture); + gpSmokeTrailTexture = nil; + } +} + +void +CSpecialFX::Render(void) +{ + PUSH_RENDERGROUP("CSpecialFX::Render"); + CMotionBlurStreaks::Render(); + CBulletTraces::Render(); + CBrightLights::Render(); + CShinyTexts::Render(); + CMoneyMessages::Render(); +#ifdef NEW_RENDERER + if(!(gbNewRenderer && FredIsInFirstPersonCam())) +#endif + C3dMarkers::Render(); + POP_RENDERGROUP(); +} + +void +CSpecialFX::Render2DFXs(void) +{ + if (CSpecialFX::bVideoCam) { + CFont::SetScale(SCREEN_SCALE_X(1.5f), SCREEN_SCALE_Y(1.5f)); + CFont::SetJustifyOff(); + CFont::SetBackgroundOff(); + CFont::SetCentreSize(SCREEN_SCALE_X(620.0f)); // unused + CFont::SetCentreOff(); + CFont::SetPropOn(); + CFont::SetColor(CRGBA(0, 255, 0, 200)); + CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); + sprintf(gString, "%d", CTimer::GetFrameCounter() & 0x3F); // mb % 63 + AsciiToUnicode(gString, gUString); + CFont::PrintString(SCREEN_WIDTH * 8 / 10, SCREEN_HEIGHT * 8 / 10, gUString); + for (int32 i = 0; i < SCREEN_HEIGHT; i += 4) { + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE); + CSprite2d::Draw2DPolygon(0.0f, i, SCREEN_WIDTH, i, 0.0f, i+1, SCREEN_WIDTH, i+1, CRGBA(0, 100, 0, 100)); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + CSprite2d::Draw2DPolygon(0.0f, i+2, SCREEN_WIDTH, i+2, 0.0f, i+3, SCREEN_WIDTH, i+3, CRGBA(0, 0, 0, 150)); + } + int32 tmp = (CTimer::GetTimeInMilliseconds() & 0x7ff) * (SCREEN_HEIGHT + 70.0f) / 2048 - 70.0f; //mb % 2048 + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + CSprite2d::Draw2DPolygon(0.0, tmp, SCREEN_WIDTH, tmp, 0.0, tmp + 70.0f, SCREEN_WIDTH, tmp + 70.0f , CRGBA(0, 100, 0, 60)); + } + if (CSpecialFX::bLiftCam) { + CFont::SetScale(SCREEN_SCALE_X(1.5f), SCREEN_SCALE_Y(1.5f)); + CFont::SetJustifyOff(); + CFont::SetBackgroundOff(); + CFont::SetCentreSize(SCREEN_SCALE_X(620.0f)); // unused + CFont::SetCentreOff(); + CFont::SetPropOn(); + CFont::SetColor(CRGBA(100, 100, 100, 200)); + CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); + for (int32 i = 0; i < SCREEN_HEIGHT; i += 4) { + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + CSprite2d::Draw2DPolygon(0.0f, i, SCREEN_WIDTH, i, 0.0f, i + 1, SCREEN_WIDTH, i + 1, CRGBA(100, 100, 100, 100)); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + CSprite2d::Draw2DPolygon(0.0f, i + 2, SCREEN_WIDTH, i + 2, 0.0f, i + 3, SCREEN_WIDTH, i + 3, CRGBA(0, 0, 0, 150)); + } + int32 tmp = (CTimer::GetTimeInMilliseconds() & 0x7ff) * (SCREEN_HEIGHT + 70.0f) / 2048 - 70.0f; //mb % 2048 + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + CSprite2d::Draw2DPolygon(0.0, tmp, SCREEN_WIDTH, tmp, 0.0, tmp + 70.0f, SCREEN_WIDTH, tmp + 70.0f, CRGBA(100, 100, 100, 60)); + for (int32 i = 0; i < 200; i++) { + int32 posX = CGeneral::GetRandomNumber() % (int32)SCREEN_WIDTH; + int32 posY = CGeneral::GetRandomNumber() % (int32)SCREEN_HEIGHT; + CSprite2d::DrawRect(CRect(posX, posY + 2, posX+20, posY), CRGBA(255, 255, 255, 64)); + } + } + if (CSpecialFX::bSnapShotActive) { + if (++CSpecialFX::SnapShotFrames > 20) { + CSpecialFX::bSnapShotActive = false; + CTimer::SetTimeScale(1.0f); + } else { + CTimer::SetTimeScale(0.0f); //in andro it's 0.00001 + if (CSpecialFX::SnapShotFrames < 10) { + int32 tmp = (255 - 255 * CSpecialFX::SnapShotFrames / 10) * 0.65f; + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + CSprite2d::Draw2DPolygon(0.0f, 0.0f, SCREEN_WIDTH, 0.0f, 0.0f, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, CRGBA(tmp, tmp, tmp, tmp)); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + } + } + } +} + +CRegisteredMotionBlurStreak CMotionBlurStreaks::aStreaks[NUMMBLURSTREAKS]; + +void +CRegisteredMotionBlurStreak::Update(void) +{ + int i; + bool wasUpdated; + bool lastWasUpdated = false; + for(i = 2; i > 0; i--){ + m_pos1[i] = m_pos1[i-1]; + m_pos2[i] = m_pos2[i-1]; + m_isValid[i] = m_isValid[i-1]; + wasUpdated = true; + if(!lastWasUpdated && !m_isValid[i]) + wasUpdated = false; + lastWasUpdated = wasUpdated; + } + m_isValid[0] = false; + if(!wasUpdated) + m_id = 0; +} + +void +CRegisteredMotionBlurStreak::Render(void) +{ + int i; + int a1, a2; + for(i = 0; i < 2; i++) + if(m_isValid[i] && m_isValid[i+1]){ + a1 = (255/3)*(3-i)/3; + RwIm3DVertexSetRGBA(&StreakVertices[0], m_red, m_green, m_blue, a1); + RwIm3DVertexSetRGBA(&StreakVertices[1], m_red, m_green, m_blue, a1); + a2 = (255/3)*(3-(i+1))/3; + RwIm3DVertexSetRGBA(&StreakVertices[2], m_red, m_green, m_blue, a2); + RwIm3DVertexSetRGBA(&StreakVertices[3], m_red, m_green, m_blue, a2); + RwIm3DVertexSetPos(&StreakVertices[0], m_pos1[i].x, m_pos1[i].y, m_pos1[i].z); + RwIm3DVertexSetPos(&StreakVertices[1], m_pos2[i].x, m_pos2[i].y, m_pos2[i].z); + RwIm3DVertexSetPos(&StreakVertices[2], m_pos1[i+1].x, m_pos1[i+1].y, m_pos1[i+1].z); + RwIm3DVertexSetPos(&StreakVertices[3], m_pos2[i+1].x, m_pos2[i+1].y, m_pos2[i+1].z); + LittleTest(); + if(RwIm3DTransform(StreakVertices, 4, nil, rwIM3D_VERTEXUV)){ + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, StreakIndexList, 12); + RwIm3DEnd(); + } + } +} + +void +CMotionBlurStreaks::Init(void) +{ + int i; + for(i = 0; i < NUMMBLURSTREAKS; i++) + aStreaks[i].m_id = 0; +} + +void +CMotionBlurStreaks::Update(void) +{ + int i; + for(i = 0; i < NUMMBLURSTREAKS; i++) + if(aStreaks[i].m_id != 0) + aStreaks[i].Update(); +} + +void +CMotionBlurStreaks::RegisterStreak(uintptr id, uint8 r, uint8 g, uint8 b, CVector p1, CVector p2) +{ + int i; + + for(i = 0; i < NUMMBLURSTREAKS; i++){ + if(aStreaks[i].m_id == id){ + // Found a streak from last frame, update + aStreaks[i].m_red = r; + aStreaks[i].m_green = g; + aStreaks[i].m_blue = b; + aStreaks[i].m_pos1[0] = p1; + aStreaks[i].m_pos2[0] = p2; + aStreaks[i].m_isValid[0] = true; + return; + } + } + + // Find free slot + for(i = 0; aStreaks[i].m_id != 0 ; i++) + if(i == NUMMBLURSTREAKS-1) + return; + + // Create a new streak + aStreaks[i].m_id = id; + aStreaks[i].m_red = r; + aStreaks[i].m_green = g; + aStreaks[i].m_blue = b; + aStreaks[i].m_pos1[0] = p1; + aStreaks[i].m_pos2[0] = p2; + aStreaks[i].m_isValid[0] = true; + aStreaks[i].m_isValid[1] = false; + aStreaks[i].m_isValid[2] = false; +} + +void +CMotionBlurStreaks::Render(void) +{ + bool setRenderStates = false; + int i; + for(i = 0; i < NUMMBLURSTREAKS; i++) + if(aStreaks[i].m_id != 0){ + if(!setRenderStates){ + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEFOGCOLOR, + (void*)RWRGBALONG(CTimeCycle::GetFogRed(), CTimeCycle::GetFogGreen(), CTimeCycle::GetFogBlue(), 255)); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void*)FALSE); + setRenderStates = true; + } + aStreaks[i].Render(); + } + if(setRenderStates){ + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE); + } +} + + +CBulletTrace CBulletTraces::aTraces[NUMBULLETTRACES]; + +void CBulletTraces::Init(void) +{ + for (int i = 0; i < NUMBULLETTRACES; i++) + aTraces[i].m_bInUse = false; +} + +void CBulletTraces::AddTrace(CVector* start, CVector* end, float thickness, uint32 lifeTime, uint8 visibility) +{ + int32 enabledCount; + uint32 modifiedLifeTime; + int32 nextSlot; + + enabledCount = 0; + for (int i = 0; i < NUMBULLETTRACES; i++) + if (aTraces[i].m_bInUse) + enabledCount++; + if (enabledCount >= 10) + modifiedLifeTime = lifeTime / 4; + else if (enabledCount >= 5) + modifiedLifeTime = lifeTime / 2; + else + modifiedLifeTime = lifeTime; + + nextSlot = 0; + for (int i = 0; nextSlot < NUMBULLETTRACES && aTraces[i].m_bInUse; i++) + nextSlot++; + if (nextSlot < 16) { + aTraces[nextSlot].m_vecStartPos = *start; + aTraces[nextSlot].m_vecEndPos = *end; + aTraces[nextSlot].m_bInUse = true; + aTraces[nextSlot].m_nCreationTime = CTimer::GetTimeInMilliseconds(); + aTraces[nextSlot].m_fVisibility = visibility; + aTraces[nextSlot].m_fThickness = thickness; + aTraces[nextSlot].m_nLifeTime = modifiedLifeTime; + } + + float startProjFwd = DotProduct(TheCamera.GetForward(), *start - TheCamera.GetPosition()); + float endProjFwd = DotProduct(TheCamera.GetForward(), *end - TheCamera.GetPosition()); + if (startProjFwd * endProjFwd < 0.0f) { //if one of point behind us and second before us + float fStartDistFwd = Abs(startProjFwd) / (Abs(startProjFwd) + Abs(endProjFwd)); + + float startProjUp = DotProduct(TheCamera.GetUp(), *start - TheCamera.GetPosition()); + float endProjUp = DotProduct(TheCamera.GetUp(), *end - TheCamera.GetPosition()); + float distUp = (endProjUp - startProjUp) * fStartDistFwd + startProjUp; + + float startProjRight = DotProduct(TheCamera.GetRight(), *start - TheCamera.GetPosition()); + float endProjRight = DotProduct(TheCamera.GetRight(), *end - TheCamera.GetPosition()); + float distRight = (endProjRight - startProjRight) * fStartDistFwd + startProjRight; + + float dist = Sqrt(SQR(distUp) + SQR(distRight)); + if (dist < 2.0f) { + if(distRight < 0.0f) + DMAudio.PlayFrontEndSound(SOUND_BULLETTRACE_2, 127 * (1.0f - dist * 0.5f)); + else + DMAudio.PlayFrontEndSound(SOUND_BULLETTRACE_1, 127 * (1.0f - dist * 0.5f)); + } + } +} + +void CBulletTraces::AddTrace(CVector* start, CVector* end, int32 weaponType, class CEntity* shooter) +{ + CPhysical* player; + float speed; + int16 camMode; + + if (shooter == (CEntity*)FindPlayerPed() || (FindPlayerVehicle() != nil && FindPlayerVehicle() == (CVehicle*)shooter)) { + camMode = TheCamera.Cams[TheCamera.ActiveCam].Mode; + if (camMode == CCam::MODE_M16_1STPERSON + || camMode == CCam::MODE_CAMERA + || camMode == CCam::MODE_SNIPER + || camMode == CCam::MODE_M16_1STPERSON_RUNABOUT + || camMode == CCam::MODE_ROCKETLAUNCHER + || camMode == CCam::MODE_ROCKETLAUNCHER_RUNABOUT + || camMode == CCam::MODE_SNIPER_RUNABOUT + || camMode == CCam::MODE_HELICANNON_1STPERSON) { + + player = FindPlayerVehicle() ? (CPhysical*)FindPlayerVehicle() : (CPhysical*)FindPlayerPed(); + speed = player->m_vecMoveSpeed.Magnitude(); + if (speed < 0.05f) + return; + } + } + + switch (weaponType) { + case WEAPONTYPE_PYTHON: + case WEAPONTYPE_SHOTGUN: + case WEAPONTYPE_SPAS12_SHOTGUN: + case WEAPONTYPE_STUBBY_SHOTGUN: + CBulletTraces::AddTrace(start, end, 0.7f, 1000, 200); + break; + case WEAPONTYPE_M4: + case WEAPONTYPE_RUGER: + case WEAPONTYPE_SNIPERRIFLE: + case WEAPONTYPE_LASERSCOPE: + case WEAPONTYPE_M60: + case WEAPONTYPE_MINIGUN: + case WEAPONTYPE_HELICANNON: + CBulletTraces::AddTrace(start, end, 1.0f, 2000, 220); + break; + default: + CBulletTraces::AddTrace(start, end, 0.4f, 750, 150); + break; + } +} + +void CBulletTraces::Render(void) +{ + for (int i = 0; i < NUMBULLETTRACES; i++) { + if (!aTraces[i].m_bInUse) + continue; + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpSmokeTrailTexture)); + + float timeAlive = CTimer::GetTimeInMilliseconds() - aTraces[i].m_nCreationTime; + + float traceThickness = aTraces[i].m_fThickness * timeAlive / aTraces[i].m_nLifeTime; + CVector horizontalOffset = aTraces[i].m_vecEndPos - aTraces[i].m_vecStartPos; + horizontalOffset.Normalise(); + horizontalOffset *= traceThickness; + + //then closer trace to die then it more transparent + uint8 nAlphaValue = aTraces[i].m_fVisibility * (aTraces[i].m_nLifeTime - timeAlive) / aTraces[i].m_nLifeTime; + + CVector start = aTraces[i].m_vecStartPos; + CVector end = aTraces[i].m_vecEndPos; + float startProj = DotProduct(start - TheCamera.GetPosition(), TheCamera.GetForward()) - 0.7f; + float endProj = DotProduct(end - TheCamera.GetPosition(), TheCamera.GetForward()) - 0.7f; + if (startProj < 0.0f && endProj < 0.0f) //we dont need render trace behind us + continue; + + if (startProj < 0.0f) { //if strat behind us move it closer + float absStartProj = Abs(startProj); + float absEndProj = Abs(endProj); + start = (absEndProj * start + absStartProj * end) / (absStartProj + absEndProj); + } else if (endProj < 0.0f) { + float absStartProj = Abs(startProj); + float absEndProj = Abs(endProj); + end = (absEndProj * start + absStartProj * end) / (absStartProj + absEndProj); + } + + //we divide trace at three parts + CVector start2 = (7.0f * start + end) / 8; + CVector end2 = (7.0f * end + start) / 8; + + RwIm3DVertexSetV(&TraceVertices[5], 10.0f); + RwIm3DVertexSetV(&TraceVertices[6], 10.0f); + RwIm3DVertexSetV(&TraceVertices[7], 10.0f); + RwIm3DVertexSetV(&TraceVertices[8], 10.0f); + RwIm3DVertexSetV(&TraceVertices[9], 10.0f); + + RwIm3DVertexSetRGBA(&TraceVertices[0], 255, 255, 255, nAlphaValue); + RwIm3DVertexSetRGBA(&TraceVertices[1], 255, 255, 255, nAlphaValue); + RwIm3DVertexSetRGBA(&TraceVertices[2], 255, 255, 255, nAlphaValue); + RwIm3DVertexSetRGBA(&TraceVertices[3], 255, 255, 255, nAlphaValue); + RwIm3DVertexSetRGBA(&TraceVertices[4], 255, 255, 255, nAlphaValue); + RwIm3DVertexSetRGBA(&TraceVertices[5], 255, 255, 255, nAlphaValue); + RwIm3DVertexSetRGBA(&TraceVertices[6], 255, 255, 255, nAlphaValue); + RwIm3DVertexSetRGBA(&TraceVertices[7], 255, 255, 255, nAlphaValue); + RwIm3DVertexSetRGBA(&TraceVertices[8], 255, 255, 255, nAlphaValue); + RwIm3DVertexSetRGBA(&TraceVertices[9], 255, 255, 255, nAlphaValue); + //two points in center + RwIm3DVertexSetPos(&TraceVertices[0], start2.x, start2.y, start2.z); + RwIm3DVertexSetPos(&TraceVertices[5], end2.x, end2.y, end2.z); + //vertical planes + RwIm3DVertexSetPos(&TraceVertices[1], start2.x, start2.y, start2.z + traceThickness); + RwIm3DVertexSetPos(&TraceVertices[3], start2.x, start2.y, start2.z - traceThickness); + RwIm3DVertexSetPos(&TraceVertices[6], end2.x, end2.y, end2.z + traceThickness); + RwIm3DVertexSetPos(&TraceVertices[8], end2.x, end2.y, end2.z - traceThickness); + //horizontal planes + RwIm3DVertexSetPos(&TraceVertices[2], start2.x + horizontalOffset.y, start2.y - horizontalOffset.x, start2.z); + RwIm3DVertexSetPos(&TraceVertices[7], end2.x + horizontalOffset.y, end2.y - horizontalOffset.x, end2.z); +#ifdef FIX_BUGS //this point calculated wrong for some reason + RwIm3DVertexSetPos(&TraceVertices[4], start2.x - horizontalOffset.y, start2.y + horizontalOffset.x, start2.z); + RwIm3DVertexSetPos(&TraceVertices[9], end2.x - horizontalOffset.y, end2.y + horizontalOffset.x, end2.z); +#else + RwIm3DVertexSetPos(&TraceVertices[4], start2.x - horizontalOffset.y, start2.y - horizontalOffset.y, start2.z); + RwIm3DVertexSetPos(&TraceVertices[9], end2.x - horizontalOffset.y, end2.y - horizontalOffset.y, end2.z); +#endif + + if (RwIm3DTransform(TraceVertices, ARRAY_SIZE(TraceVertices), nil, 1)) { + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TraceIndexList, ARRAY_SIZE(TraceIndexList)); + RwIm3DEnd(); + } + + RwIm3DVertexSetV(&TraceVertices[5], 2.0f); + RwIm3DVertexSetV(&TraceVertices[6], 2.0f); + RwIm3DVertexSetV(&TraceVertices[7], 2.0f); + RwIm3DVertexSetV(&TraceVertices[8], 2.0f); + RwIm3DVertexSetV(&TraceVertices[9], 2.0f); + RwIm3DVertexSetRGBA(&TraceVertices[0], 255, 255, 255, 0); + RwIm3DVertexSetRGBA(&TraceVertices[1], 255, 255, 255, 0); + RwIm3DVertexSetRGBA(&TraceVertices[2], 255, 255, 255, 0); + RwIm3DVertexSetRGBA(&TraceVertices[3], 255, 255, 255, 0); + RwIm3DVertexSetRGBA(&TraceVertices[4], 255, 255, 255, 0); + + RwIm3DVertexSetPos(&TraceVertices[0], start.x, start.y, start.z); + RwIm3DVertexSetPos(&TraceVertices[1], start.x, start.y, start.z + traceThickness); + RwIm3DVertexSetPos(&TraceVertices[3], start.x, start.y, start.z - traceThickness); + RwIm3DVertexSetPos(&TraceVertices[2], start.x + horizontalOffset.y, start.y - horizontalOffset.x, start.z); + + RwIm3DVertexSetPos(&TraceVertices[5], start2.x, start2.y, start2.z); + RwIm3DVertexSetPos(&TraceVertices[6], start2.x, start2.y, start2.z + traceThickness); + RwIm3DVertexSetPos(&TraceVertices[8], start2.x, start2.y, start2.z - traceThickness); + RwIm3DVertexSetPos(&TraceVertices[7], start2.x + horizontalOffset.y, start2.y - horizontalOffset.x, start2.z); +#ifdef FIX_BUGS + RwIm3DVertexSetPos(&TraceVertices[4], start.x - horizontalOffset.y, start.y + horizontalOffset.x, start.z); + RwIm3DVertexSetPos(&TraceVertices[9], start2.x - horizontalOffset.y, start2.y + horizontalOffset.x, start2.z); +#else + RwIm3DVertexSetPos(&TraceVertices[4], start.x - horizontalOffset.y, start.y - horizontalOffset.y, start.z); + RwIm3DVertexSetPos(&TraceVertices[9], start2.x - horizontalOffset.y, start2.y - horizontalOffset.y, start2.z); +#endif + + if (RwIm3DTransform(TraceVertices, ARRAY_SIZE(TraceVertices), nil, rwIM3D_VERTEXUV)) { + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TraceIndexList, ARRAY_SIZE(TraceIndexList)); + RwIm3DEnd(); + } + + RwIm3DVertexSetPos(&TraceVertices[1], end.x, end.y, end.z); + RwIm3DVertexSetPos(&TraceVertices[2], end.x, end.y, end.z + traceThickness); + RwIm3DVertexSetPos(&TraceVertices[4], end.x, end.y, end.z - traceThickness); + RwIm3DVertexSetPos(&TraceVertices[3], end.x + horizontalOffset.y, end.y - horizontalOffset.x, end.z); + + RwIm3DVertexSetPos(&TraceVertices[5], end2.x, end2.y, end2.z); + RwIm3DVertexSetPos(&TraceVertices[6], end2.x, end2.y, end2.z + traceThickness); + RwIm3DVertexSetPos(&TraceVertices[8], end2.x, end2.y, end2.z - traceThickness); + RwIm3DVertexSetPos(&TraceVertices[7], end2.x + horizontalOffset.y, end2.y - horizontalOffset.x, end2.z); +#ifdef FIX_BUGS + RwIm3DVertexSetPos(&TraceVertices[5], end.x - horizontalOffset.y, end.y + horizontalOffset.x, end.z); + RwIm3DVertexSetPos(&TraceVertices[9], end2.x - horizontalOffset.y, end2.y + horizontalOffset.x, end2.z); +#else + RwIm3DVertexSetPos(&TraceVertices[5], end.x - horizontalOffset.y, end.y - horizontalOffset.y, end.z); + RwIm3DVertexSetPos(&TraceVertices[9], end2.x - horizontalOffset.y, end2.y - horizontalOffset.y, end2.z); +#endif + + if (RwIm3DTransform(TraceVertices, ARRAY_SIZE(TraceVertices), nil, rwIM3D_VERTEXUV)) { + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TraceIndexList, ARRAY_SIZE(TraceIndexList)); + RwIm3DEnd(); + } + } + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); +} + +void CBulletTraces::Update(void) +{ + for (int i = 0; i < NUMBULLETTRACES; i++) { + if (aTraces[i].m_bInUse) + aTraces[i].Update(); + } +} + +void CBulletTrace::Update(void) +{ + if (CTimer::GetTimeInMilliseconds() - m_nCreationTime >= m_nLifeTime) + m_bInUse = false; +} + +RpAtomic * +MarkerAtomicCB(RpAtomic *atomic, void *data) +{ + *(RpAtomic**)data = atomic; + return atomic; +} + +bool +C3dMarker::AddMarker(uint32 identifier, uint16 type, float fSize, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate) +{ + m_nIdentifier = identifier; + + m_Matrix.SetUnity(); + + RpAtomic *origAtomic; + origAtomic = nil; + RpClumpForAllAtomics(C3dMarkers::m_pRpClumpArray[type], MarkerAtomicCB, &origAtomic); + + RpAtomic *atomic = RpAtomicClone(origAtomic); + RwFrame *frame = RwFrameCreate(); + RpAtomicSetFrame(atomic, frame); + CVisibilityPlugins::SetAtomicRenderCallback(atomic, nil); + + RpGeometry *geometry = RpAtomicGetGeometry(atomic); + RpGeometrySetFlags(geometry, RpGeometryGetFlags(geometry) | rpGEOMETRYMODULATEMATERIALCOLOR); + + m_pAtomic = atomic; + m_Matrix.Attach(RwFrameGetMatrix(RpAtomicGetFrame(m_pAtomic))); + m_pMaterial = RpGeometryGetMaterial(geometry, 0); + m_fSize = fSize; + m_fStdSize = m_fSize; + m_Color.red = r; + m_Color.green = g; + m_Color.blue = b; + m_Color.alpha = a; + m_nPulsePeriod = pulsePeriod; + m_fPulseFraction = pulseFraction; + m_nRotateRate = rotateRate; + m_nStartTime = CTimer::GetTimeInMilliseconds(); + m_nType = type; + return m_pAtomic != nil; +} + +void +C3dMarker::DeleteMarkerObject() +{ + RwFrame *frame; + + m_nIdentifier = 0; + m_nStartTime = 0; + m_bIsUsed = false; + m_bFindZOnNextPlacement = false; + m_nType = MARKERTYPE_INVALID; + + frame = RpAtomicGetFrame(m_pAtomic); + RpAtomicDestroy(m_pAtomic); + RwFrameDestroy(frame); + m_pAtomic = nil; +} + +void +C3dMarker::Render() +{ + if (m_pAtomic == nil) return; + + RpMaterialSetColor(m_pMaterial, &m_Color); + + m_Matrix.UpdateRW(); + + CMatrix matrix; + matrix.Attach(m_Matrix.m_attachment); + matrix.Scale(m_fSize); + matrix.UpdateRW(); + + RwFrameUpdateObjects(RpAtomicGetFrame(m_pAtomic)); + SetBrightMarkerColours(m_fBrightness); + if (m_nType != MARKERTYPE_ARROW) + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RpAtomicRender(m_pAtomic); + if (m_nType != MARKERTYPE_ARROW) + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + ReSetAmbientAndDirectionalColours(); +} + +C3dMarker C3dMarkers::m_aMarkerArray[NUM3DMARKERS]; +int32 C3dMarkers::NumActiveMarkers; +RpClump* C3dMarkers::m_pRpClumpArray[NUMMARKERTYPES]; + +void +C3dMarkers::Init() +{ + for (int i = 0; i < NUM3DMARKERS; i++) { + m_aMarkerArray[i].m_pAtomic = nil; + m_aMarkerArray[i].m_nType = MARKERTYPE_INVALID; + m_aMarkerArray[i].m_bIsUsed = false; + m_aMarkerArray[i].m_bFindZOnNextPlacement = false; + m_aMarkerArray[i].m_nIdentifier = 0; + m_aMarkerArray[i].m_Color.red = 255; + m_aMarkerArray[i].m_Color.green = 255; + m_aMarkerArray[i].m_Color.blue = 255; + m_aMarkerArray[i].m_Color.alpha = 255; + m_aMarkerArray[i].m_nPulsePeriod = 1024; + m_aMarkerArray[i].m_nRotateRate = 5; + m_aMarkerArray[i].m_nStartTime = 0; + m_aMarkerArray[i].m_fPulseFraction = 0.25f; + m_aMarkerArray[i].m_fStdSize = 1.0f; + m_aMarkerArray[i].m_fSize = 1.0f; + m_aMarkerArray[i].m_fBrightness = 1.0f; + m_aMarkerArray[i].m_fCameraRange = 0.0f; + } + NumActiveMarkers = 0; + int txdSlot = CTxdStore::FindTxdSlot("particle"); + CTxdStore::PushCurrentTxd(); + CTxdStore::SetCurrentTxd(txdSlot); + CFileMgr::ChangeDir("\\"); + m_pRpClumpArray[MARKERTYPE_ARROW] = CFileLoader::LoadAtomicFile2Return("models/generic/arrow.dff"); + m_pRpClumpArray[MARKERTYPE_CYLINDER] = CFileLoader::LoadAtomicFile2Return("models/generic/zonecylb.dff"); + CTxdStore::PopCurrentTxd(); +} + +void +C3dMarkers::Shutdown() +{ + for (int i = 0; i < NUM3DMARKERS; i++) { + if (m_aMarkerArray[i].m_pAtomic != nil) + m_aMarkerArray[i].DeleteMarkerObject(); + } + + for (int i = 0; i < NUMMARKERTYPES; i++) { + if (m_pRpClumpArray[i] != nil) + RpClumpDestroy(m_pRpClumpArray[i]); + } +} + +void +C3dMarkers::Render() +{ + NumActiveMarkers = 0; + ActivateDirectional(); + for (int i = 0; i < NUM3DMARKERS; i++) { + if (m_aMarkerArray[i].m_bIsUsed) { + if (m_aMarkerArray[i].m_fCameraRange < 150.0f) { + m_aMarkerArray[i].Render(); + if (m_aMarkerArray[i].m_nType == MARKERTYPE_ARROW) { + CCoronas::RegisterCorona((uintptr)&m_aMarkerArray[i], + SPHERE_MARKER_R, SPHERE_MARKER_G, SPHERE_MARKER_B, 192, + m_aMarkerArray[i].m_Matrix.GetPosition(), 1.2f * m_aMarkerArray[i].m_fSize, 50.0f * TheCamera.LODDistMultiplier, + CCoronas::TYPE_STAR, CCoronas::FLARE_NONE, CCoronas::REFLECTION_OFF, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_ON, 0.0f, false); + } + } + NumActiveMarkers++; + m_aMarkerArray[i].m_bIsUsed = false; + } else if (m_aMarkerArray[i].m_pAtomic != nil) { + m_aMarkerArray[i].DeleteMarkerObject(); + } + } +} + +C3dMarker * +C3dMarkers::PlaceMarker(uint32 identifier, uint16 type, CVector &pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate) +{ + C3dMarker *pMarker; + CVector2D playerPos = FindPlayerCentreOfWorld(0); + pMarker = nil; + float dist = ((CVector2D)pos - playerPos).Magnitude(); + + if (type != MARKERTYPE_ARROW && type != MARKERTYPE_CYLINDER) return nil; + + for (int i = 0; i < NUM3DMARKERS; i++) { + if (!m_aMarkerArray[i].m_bIsUsed && m_aMarkerArray[i].m_nIdentifier == identifier) { + pMarker = &m_aMarkerArray[i]; + break; + } + } + + if (pMarker == nil) { + for (int i = 0; i < NUM3DMARKERS; i++) { + if (m_aMarkerArray[i].m_nType == MARKERTYPE_INVALID) { + pMarker = &m_aMarkerArray[i]; + break; + } + } + } + + if (pMarker == nil && type == MARKERTYPE_ARROW) { + for (int i = 0; i < NUM3DMARKERS; i++) { + if (dist < m_aMarkerArray[i].m_fCameraRange && m_aMarkerArray[i].m_nType == MARKERTYPE_ARROW && (pMarker == nil || m_aMarkerArray[i].m_fCameraRange > pMarker->m_fCameraRange)) { + pMarker = &m_aMarkerArray[i]; + break; + } + } + + if (pMarker != nil) + pMarker->m_nType = MARKERTYPE_INVALID; + } + + if (pMarker == nil) return pMarker; + + pMarker->m_fCameraRange = dist; + if (pMarker->m_nIdentifier == identifier && pMarker->m_nType == type) { + if (type == MARKERTYPE_ARROW) { + if (dist < 25.0f) { + if (dist > 5.0f) + pMarker->m_fStdSize = size - (25.0f - dist) * (0.3f * size) / 20.0f; + else + pMarker->m_fStdSize = size - 0.3f * size; + } else { + pMarker->m_fStdSize = size; + } + } else if (type == MARKERTYPE_CYLINDER) { + if (dist < size + 12.0f) { + if (dist > size + 1.0f) + pMarker->m_Color.alpha = (1.0f - (size + 12.0f - dist) * 0.7f / 11.0f) * (float)a; + else + pMarker->m_Color.alpha = (float)a * 0.3f; + } else { + pMarker->m_Color.alpha = a; + } + } + float someSin = Sin(TWOPI * (float)((pMarker->m_nPulsePeriod - 1) & (CTimer::GetTimeInMilliseconds() - pMarker->m_nStartTime)) / (float)pMarker->m_nPulsePeriod); + pMarker->m_fSize = pMarker->m_fStdSize - pulseFraction * pMarker->m_fStdSize * someSin; + + if (type == MARKERTYPE_ARROW) { + pos.z += 0.25f * pMarker->m_fStdSize * someSin; + } else if (type == MARKERTYPE_0) { + if (someSin > 0.0f) + pMarker->m_Color.alpha = (float)a * 0.7f * someSin + a; + else + pMarker->m_Color.alpha = (float)a * 0.4f * someSin + a; + } + if (pMarker->m_nRotateRate != 0) { + CVector pos = pMarker->m_Matrix.GetPosition(); + pMarker->m_Matrix.RotateZ(DEGTORAD(pMarker->m_nRotateRate * CTimer::GetTimeStep())); + pMarker->m_Matrix.GetPosition() = pos; + } + if (type == MARKERTYPE_ARROW) + pMarker->m_Matrix.GetPosition() = pos; + + if (pMarker->m_bFindZOnNextPlacement) { + if ((playerPos - pos).MagnitudeSqr() < sq(100.f) && CColStore::HasCollisionLoaded(CVector2D(pos))) { + float z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z + 1.0f, nil); + if (z != 0.0f) + pMarker->m_Matrix.GetPosition().z = z - 0.05f * size; + pMarker->m_bFindZOnNextPlacement = false; + } + } + pMarker->m_bIsUsed = true; + return pMarker; + } + + if (pMarker->m_nIdentifier != 0) + pMarker->DeleteMarkerObject(); + + pMarker->AddMarker(identifier, type, size, r, g, b, a, pulsePeriod, pulseFraction, rotateRate); + if (type == MARKERTYPE_CYLINDER || type == MARKERTYPE_0 || type == MARKERTYPE_2) { + if ((playerPos - pos).MagnitudeSqr() < sq(100.f) && CColStore::HasCollisionLoaded(CVector2D(pos))) { + float z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z + 1.0f, nil); + if (z != 0.0f) + pos.z = z - 0.05f * size; + pMarker->m_bFindZOnNextPlacement = false; + } else { + pMarker->m_bFindZOnNextPlacement = true; + } + } + pMarker->m_Matrix.SetTranslate(pos.x, pos.y, pos.z); + if (type == MARKERTYPE_2) { + pMarker->m_Matrix.RotateX(PI); + pMarker->m_Matrix.GetPosition() = pos; + } + pMarker->m_Matrix.UpdateRW(); + if (type == MARKERTYPE_ARROW) { + if (dist < 25.0f) { + if (dist > 5.0f) + pMarker->m_fStdSize = size - (25.0f - dist) * (0.3f * size) / 20.0f; + else + pMarker->m_fStdSize = size - 0.3f * size; + } else { + pMarker->m_fStdSize = size; + } + } else if (type == MARKERTYPE_CYLINDER) { + if (dist < size + 12.0f) { + if (dist > size + 1.0f) + pMarker->m_Color.alpha = (1.0f - (size + 12.0f - dist) * 0.7f / 11.0f) * (float)a; + else + pMarker->m_Color.alpha = (float)a * 0.3f; + } else { + pMarker->m_Color.alpha = a; + } + } + pMarker->m_bIsUsed = true; + return pMarker; +} + +void +C3dMarkers::PlaceMarkerSet(uint32 id, uint16 type, CVector &pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate) +{ + PlaceMarker(id, type, pos, size, r, g, b, a, pulsePeriod, pulseFraction, 1); + PlaceMarker(id, type, pos, size * 0.93f, r, g, b, a, pulsePeriod, pulseFraction, 2); + PlaceMarker(id, type, pos, size * 0.86f, r, g, b, a, pulsePeriod, pulseFraction, -1); +} + + +void +C3dMarkers::Update() +{ +} + + +#define BRIGHTLIGHTS_MAX_DIST (60.0f) // invisible beyond this +#define BRIGHTLIGHTS_FADE_DIST (45.0f) // strongest between these two +#define CARLIGHTS_MAX_DIST (30.0f) +#define CARLIGHTS_FADE_DIST (15.0f) // 31 for close lights + +int CBrightLights::NumBrightLights; +CBrightLight CBrightLights::aBrightLights[NUMBRIGHTLIGHTS]; + +void +CBrightLights::Init(void) +{ + NumBrightLights = 0; +} + +void +CBrightLights::RegisterOne(CVector pos, CVector up, CVector side, CVector front, + uint8 type, uint8 red, uint8 green, uint8 blue) +{ + if(NumBrightLights >= NUMBRIGHTLIGHTS) + return; + + aBrightLights[NumBrightLights].m_camDist = (pos - TheCamera.GetPosition()).Magnitude(); + if(aBrightLights[NumBrightLights].m_camDist > BRIGHTLIGHTS_MAX_DIST) + return; + + aBrightLights[NumBrightLights].m_pos = pos; + aBrightLights[NumBrightLights].m_up = up; + aBrightLights[NumBrightLights].m_side = side; + aBrightLights[NumBrightLights].m_front = front; + aBrightLights[NumBrightLights].m_type = type; + aBrightLights[NumBrightLights].m_red = red; + aBrightLights[NumBrightLights].m_green = green; + aBrightLights[NumBrightLights].m_blue = blue; + + NumBrightLights++; +} + +static float TrafficLightsSide[6] = { -0.09f, 0.09f, 0.162f, 0.09f, -0.09f, -0.162f }; +static float TrafficLightsUp[6] = { 0.162f, 0.162f, 0.0f, -0.162f, -0.162f, 0.0f }; +static float LongCarHeadLightsSide[8] = { -0.2f, 0.2f, -0.2f, 0.2f, -0.2f, 0.2f, -0.2f, 0.2f }; +static float LongCarHeadLightsFront[8] = { 0.1f, 0.1f, -0.1f, -0.1f, 0.1f, 0.1f, -0.1f, -0.1f }; +static float LongCarHeadLightsUp[8] = { 0.1f, 0.1f, 0.1f, 0.1f, -0.1f, -0.1f, -0.1f, -0.1f }; +static float SmallCarHeadLightsSide[8] = { -0.08f, 0.08f, -0.08f, 0.08f, -0.08f, 0.08f, -0.08f, 0.08f }; +static float SmallCarHeadLightsFront[8] = { 0.08f, 0.08f, -0.08f, -0.08f, 0.08f, 0.08f, -0.08f, -0.08f }; +static float SmallCarHeadLightsUp[8] = { 0.08f, 0.08f, 0.08f, 0.08f, -0.08f, -0.08f, -0.08f, -0.08f }; +static float BigCarHeadLightsSide[8] = { -0.15f, 0.15f, -0.15f, 0.15f, -0.15f, 0.15f, -0.15f, 0.15f }; +static float BigCarHeadLightsFront[8] = { 0.15f, 0.15f, -0.15f, -0.15f, 0.15f, 0.15f, -0.15f, -0.15f }; +static float BigCarHeadLightsUp[8] = { 0.15f, 0.15f, 0.15f, 0.15f, -0.15f, -0.15f, -0.15f, -0.15f }; +static float TallCarHeadLightsSide[8] = { -0.08f, 0.08f, -0.08f, 0.08f, -0.08f, 0.08f, -0.08f, 0.08f }; +static float TallCarHeadLightsFront[8] = { 0.08f, 0.08f, -0.08f, -0.08f, 0.08f, 0.08f, -0.08f, -0.08f }; +static float TallCarHeadLightsUp[8] = { 0.2f, 0.2f, 0.2f, 0.2f, -0.2f, -0.2f, -0.2f, -0.2f }; +static float SirenLightsSide[6] = { -0.04f, 0.04f, 0.06f, 0.04f, -0.04f, -0.06f }; +static float SirenLightsUp[6] = { 0.06f, 0.06f, 0.0f, -0.06f, -0.06f, 0.0f }; +static RwImVertexIndex TrafficLightIndices[4*3] = { 0, 1, 5, 1, 2, 3, 1, 3, 4, 1, 4, 5 }; +static RwImVertexIndex CubeIndices[12*3] = { + 0, 2, 1, 1, 2, 3, 3, 5, 1, 3, 7, 5, + 2, 7, 3, 2, 6, 7, 4, 0, 1, 4, 1, 5, + 6, 0, 4, 6, 2, 0, 6, 5, 7, 6, 4, 5 +}; + +void +CBrightLights::Render(void) +{ + int i, j; + CVector pos; + + if(NumBrightLights == 0) + return; + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + + TempBufferVerticesStored = 0; + TempBufferIndicesStored = 0; + + for(i = 0; i < NumBrightLights; i++){ + if(TempBufferIndicesStored > TEMPBUFFERINDEXSIZE-40 || TempBufferVerticesStored > TEMPBUFFERVERTSIZE-40) + RenderOutGeometryBuffer(); + + int r, g, b, a; + float flicker = (CGeneral::GetRandomNumber()&0xFF) * 0.2f; + switch(aBrightLights[i].m_type){ + case BRIGHTLIGHT_TRAFFIC_GREEN: + r = flicker; g = 255; b = flicker; + break; + case BRIGHTLIGHT_TRAFFIC_YELLOW: + r = 255; g = 128; b = flicker; + break; + case BRIGHTLIGHT_TRAFFIC_RED: + r = 255; g = flicker; b = flicker; + break; + + case BRIGHTLIGHT_FRONT_LONG: + case BRIGHTLIGHT_FRONT_SMALL: + case BRIGHTLIGHT_FRONT_BIG: + case BRIGHTLIGHT_FRONT_TALL: + r = 255; g = 255; b = 255; + break; + + case BRIGHTLIGHT_REAR_LONG: + case BRIGHTLIGHT_REAR_SMALL: + case BRIGHTLIGHT_REAR_BIG: + case BRIGHTLIGHT_REAR_TALL: + r = 255; g = flicker; b = flicker; + break; + + case BRIGHTLIGHT_SIREN: + r = aBrightLights[i].m_red; + g = aBrightLights[i].m_green; + b = aBrightLights[i].m_blue; + break; +#ifdef FIX_BUGS //just to make sure that color never will be undefined + default: + return; +#endif + } + + if(aBrightLights[i].m_camDist < BRIGHTLIGHTS_FADE_DIST) + a = 255; + else + a = 255*(1.0f - (aBrightLights[i].m_camDist-BRIGHTLIGHTS_FADE_DIST)/(BRIGHTLIGHTS_MAX_DIST-BRIGHTLIGHTS_FADE_DIST)); + // fade car lights down to 31 as they come near + if(aBrightLights[i].m_type >= BRIGHTLIGHT_FRONT_LONG && aBrightLights[i].m_type <= BRIGHTLIGHT_REAR_TALL){ + if(aBrightLights[i].m_camDist < CARLIGHTS_FADE_DIST) + a = 31; + else if(aBrightLights[i].m_camDist < CARLIGHTS_MAX_DIST) + a = 31 + (255-31)*((aBrightLights[i].m_camDist-CARLIGHTS_FADE_DIST)/(CARLIGHTS_MAX_DIST-CARLIGHTS_FADE_DIST)); + } + + switch(aBrightLights[i].m_type){ + case BRIGHTLIGHT_TRAFFIC_GREEN: + case BRIGHTLIGHT_TRAFFIC_YELLOW: + case BRIGHTLIGHT_TRAFFIC_RED: + for(j = 0; j < 6; j++){ + pos = TrafficLightsSide[j]*aBrightLights[i].m_side + + TrafficLightsUp[j]*aBrightLights[i].m_up + + aBrightLights[i].m_pos; + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+j], r, g, b, a); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+j], pos.x, pos.y, pos.z); + } + for(j = 0; j < 4*3; j++) + TempBufferRenderIndexList[TempBufferIndicesStored+j] = TrafficLightIndices[j] + TempBufferVerticesStored; + TempBufferVerticesStored += 6; + TempBufferIndicesStored += 4*3; + break; + + case BRIGHTLIGHT_FRONT_LONG: + case BRIGHTLIGHT_REAR_LONG: + for(j = 0; j < 8; j++){ + pos = LongCarHeadLightsSide[j]*aBrightLights[i].m_side + + LongCarHeadLightsUp[j]*aBrightLights[i].m_up + + LongCarHeadLightsFront[j]*aBrightLights[i].m_front + + aBrightLights[i].m_pos; + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+j], r, g, b, a); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+j], pos.x, pos.y, pos.z); + } + for(j = 0; j < 12*3; j++) + TempBufferRenderIndexList[TempBufferIndicesStored+j] = CubeIndices[j] + TempBufferVerticesStored; + TempBufferVerticesStored += 8; + TempBufferIndicesStored += 12*3; + break; + + case BRIGHTLIGHT_FRONT_SMALL: + case BRIGHTLIGHT_REAR_SMALL: + for(j = 0; j < 8; j++){ + pos = SmallCarHeadLightsSide[j]*aBrightLights[i].m_side + + SmallCarHeadLightsUp[j]*aBrightLights[i].m_up + + SmallCarHeadLightsFront[j]*aBrightLights[i].m_front + + aBrightLights[i].m_pos; + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+j], r, g, b, a); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+j], pos.x, pos.y, pos.z); + } + for(j = 0; j < 12*3; j++) + TempBufferRenderIndexList[TempBufferIndicesStored+j] = CubeIndices[j] + TempBufferVerticesStored; + TempBufferVerticesStored += 8; + TempBufferIndicesStored += 12*3; + break; + + case BRIGHTLIGHT_FRONT_BIG: + case BRIGHTLIGHT_REAR_BIG: + for (j = 0; j < 8; j++) { + pos = BigCarHeadLightsSide[j] * aBrightLights[i].m_side + + BigCarHeadLightsUp[j] * aBrightLights[i].m_up + + BigCarHeadLightsFront[j] * aBrightLights[i].m_front + + aBrightLights[i].m_pos; + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + j], r, g, b, a); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + j], pos.x, pos.y, pos.z); + } + for (j = 0; j < 12 * 3; j++) + TempBufferRenderIndexList[TempBufferIndicesStored + j] = CubeIndices[j] + TempBufferVerticesStored; + TempBufferVerticesStored += 8; + TempBufferIndicesStored += 12 * 3; + break; + + case BRIGHTLIGHT_FRONT_TALL: + case BRIGHTLIGHT_REAR_TALL: + for(j = 0; j < 8; j++){ + pos = TallCarHeadLightsSide[j]*aBrightLights[i].m_side + + TallCarHeadLightsUp[j]*aBrightLights[i].m_up + + TallCarHeadLightsFront[j]*aBrightLights[i].m_front + + aBrightLights[i].m_pos; + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+j], r, g, b, a); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+j], pos.x, pos.y, pos.z); + } + for(j = 0; j < 12*3; j++) + TempBufferRenderIndexList[TempBufferIndicesStored+j] = CubeIndices[j] + TempBufferVerticesStored; + TempBufferVerticesStored += 8; + TempBufferIndicesStored += 12*3; + break; + + case BRIGHTLIGHT_SIREN: + for(j = 0; j < 6; j++){ + pos = SirenLightsSide[j] * TheCamera.GetRight() + + SirenLightsUp[j] * TheCamera.GetUp() + + aBrightLights[i].m_pos; + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored+j], r, g, b, a); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored+j], pos.x, pos.y, pos.z); + } + for(j = 0; j < 4*3; j++) + TempBufferRenderIndexList[TempBufferIndicesStored+j] = TrafficLightIndices[j] + TempBufferVerticesStored; + TempBufferVerticesStored += 6; + TempBufferIndicesStored += 4*3; + break; + + } + } + + RenderOutGeometryBuffer(); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + NumBrightLights = 0; +} + +void +CBrightLights::RenderOutGeometryBuffer(void) +{ + if(TempBufferIndicesStored != 0){ + LittleTest(); + if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV)){ + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); + RwIm3DEnd(); + } + TempBufferVerticesStored = 0; + TempBufferIndicesStored = 0; + } +} + +int CShinyTexts::NumShinyTexts; +CShinyText CShinyTexts::aShinyTexts[NUMSHINYTEXTS]; + +void +CShinyTexts::Init(void) +{ + NumShinyTexts = 0; +} + +void +CShinyTexts::RegisterOne(CVector p0, CVector p1, CVector p2, CVector p3, + float u0, float v0, float u1, float v1, float u2, float v2, float u3, float v3, + uint8 type, uint8 red, uint8 green, uint8 blue, float maxDist) +{ + if(NumShinyTexts >= NUMSHINYTEXTS) + return; + + aShinyTexts[NumShinyTexts].m_camDist = (p0 - TheCamera.GetPosition()).Magnitude(); + if(aShinyTexts[NumShinyTexts].m_camDist > maxDist) + return; + aShinyTexts[NumShinyTexts].m_verts[0] = p0; + aShinyTexts[NumShinyTexts].m_verts[1] = p1; + aShinyTexts[NumShinyTexts].m_verts[2] = p2; + aShinyTexts[NumShinyTexts].m_verts[3] = p3; + aShinyTexts[NumShinyTexts].m_texCoords[0].x = u0; + aShinyTexts[NumShinyTexts].m_texCoords[0].y = v0; + aShinyTexts[NumShinyTexts].m_texCoords[1].x = u1; + aShinyTexts[NumShinyTexts].m_texCoords[1].y = v1; + aShinyTexts[NumShinyTexts].m_texCoords[2].x = u2; + aShinyTexts[NumShinyTexts].m_texCoords[2].y = v2; + aShinyTexts[NumShinyTexts].m_texCoords[3].x = u3; + aShinyTexts[NumShinyTexts].m_texCoords[3].y = v3; + aShinyTexts[NumShinyTexts].m_type = type; + aShinyTexts[NumShinyTexts].m_red = red; + aShinyTexts[NumShinyTexts].m_green = green; + aShinyTexts[NumShinyTexts].m_blue = blue; + // Fade out at half the max dist + float halfDist = maxDist*0.5f; + if(aShinyTexts[NumShinyTexts].m_camDist > halfDist){ + float f = 1.0f - (aShinyTexts[NumShinyTexts].m_camDist - halfDist)/halfDist; + aShinyTexts[NumShinyTexts].m_red *= f; + aShinyTexts[NumShinyTexts].m_green *= f; + aShinyTexts[NumShinyTexts].m_blue *= f; + } + + NumShinyTexts++; +} + +void +CShinyTexts::Render(void) +{ + int i, ix, v; + RwTexture *lastTex = nil; + + if(NumShinyTexts == 0) + return; + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + + TempBufferVerticesStored = 0; + TempBufferIndicesStored = 0; + + for(i = 0; i < NumShinyTexts; i++){ + if(TempBufferIndicesStored > TEMPBUFFERINDEXSIZE-64 || TempBufferVerticesStored > TEMPBUFFERVERTSIZE-62) + RenderOutGeometryBuffer(); + + uint8 r = aShinyTexts[i].m_red; + uint8 g = aShinyTexts[i].m_green; + uint8 b = aShinyTexts[i].m_blue; + + switch(aShinyTexts[i].m_type){ + case SHINYTEXT_WALK: + if(lastTex != gpWalkDontTex){ + RenderOutGeometryBuffer(); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpWalkDontTex)); + lastTex = gpWalkDontTex; + } + quad: + v = TempBufferVerticesStored; + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+0], r, g, b, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[v+0], aShinyTexts[i].m_verts[0].x, aShinyTexts[i].m_verts[0].y, aShinyTexts[i].m_verts[0].z); + RwIm3DVertexSetU(&TempBufferRenderVertices[v+0], aShinyTexts[i].m_texCoords[0].x); + RwIm3DVertexSetV(&TempBufferRenderVertices[v+0], aShinyTexts[i].m_texCoords[0].y); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+1], r, g, b, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[v+1], aShinyTexts[i].m_verts[1].x, aShinyTexts[i].m_verts[1].y, aShinyTexts[i].m_verts[1].z); + RwIm3DVertexSetU(&TempBufferRenderVertices[v+1], aShinyTexts[i].m_texCoords[1].x); + RwIm3DVertexSetV(&TempBufferRenderVertices[v+1], aShinyTexts[i].m_texCoords[1].y); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+2], r, g, b, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[v+2], aShinyTexts[i].m_verts[2].x, aShinyTexts[i].m_verts[2].y, aShinyTexts[i].m_verts[2].z); + RwIm3DVertexSetU(&TempBufferRenderVertices[v+2], aShinyTexts[i].m_texCoords[2].x); + RwIm3DVertexSetV(&TempBufferRenderVertices[v+2], aShinyTexts[i].m_texCoords[2].y); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[v+3], r, g, b, 255); + RwIm3DVertexSetPos(&TempBufferRenderVertices[v+3], aShinyTexts[i].m_verts[3].x, aShinyTexts[i].m_verts[3].y, aShinyTexts[i].m_verts[3].z); + RwIm3DVertexSetU(&TempBufferRenderVertices[v+3], aShinyTexts[i].m_texCoords[3].x); + RwIm3DVertexSetV(&TempBufferRenderVertices[v+3], aShinyTexts[i].m_texCoords[3].y); + ix = TempBufferIndicesStored; + TempBufferRenderIndexList[ix+0] = 0 + TempBufferVerticesStored; + TempBufferRenderIndexList[ix+1] = 1 + TempBufferVerticesStored; + TempBufferRenderIndexList[ix+2] = 2 + TempBufferVerticesStored; + TempBufferRenderIndexList[ix+3] = 2 + TempBufferVerticesStored; + TempBufferRenderIndexList[ix+4] = 1 + TempBufferVerticesStored; + TempBufferRenderIndexList[ix+5] = 3 + TempBufferVerticesStored; + TempBufferVerticesStored += 4; + TempBufferIndicesStored += 6; + break; + + case SHINYTEXT_FLAT: + if(lastTex != nil){ + RenderOutGeometryBuffer(); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + lastTex = nil; + } + goto quad; + } + } + + RenderOutGeometryBuffer(); + NumShinyTexts = 0; + + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); +} + +void +CShinyTexts::RenderOutGeometryBuffer(void) +{ + if(TempBufferIndicesStored != 0){ + LittleTest(); + if(RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV)){ + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); + RwIm3DEnd(); + } + TempBufferVerticesStored = 0; + TempBufferIndicesStored = 0; + } +} + + + +#define MONEY_MESSAGE_LIFETIME_MS 2000 + +CMoneyMessage CMoneyMessages::aMoneyMessages[NUMMONEYMESSAGES]; + +void +CMoneyMessage::Render() +{ + const float MAX_SCALE = 4.0f; + uint32 nLifeTime = CTimer::GetTimeInMilliseconds() - m_nTimeRegistered; + if (nLifeTime >= MONEY_MESSAGE_LIFETIME_MS) { + m_nTimeRegistered = 0; + } else { + float fLifeTime = (float)nLifeTime / MONEY_MESSAGE_LIFETIME_MS; + RwV3d vecOut; + float fDistX, fDistY; + if (CSprite::CalcScreenCoors(m_vecPosition + CVector(0.0f, 0.0f, fLifeTime), &vecOut, &fDistX, &fDistY, true)) { + fDistX *= (0.7f * fLifeTime + 2.0f) * m_fSize; + fDistY *= (0.7f * fLifeTime + 2.0f) * m_fSize; + CFont::SetPropOn(); + CFont::SetBackgroundOff(); + float fScaleY = Min(fDistY / 100.0f, MAX_SCALE); + float fScaleX = Min(fDistX / 100.0f, MAX_SCALE); + +#ifdef FIX_BUGS + CFont::SetScale(SCREEN_SCALE_X(fScaleX), SCREEN_SCALE_Y(fScaleY)); +#else + CFont::SetScale(fScaleX, fScaleY); +#endif + CFont::SetCentreOn(); + CFont::SetCentreSize(SCREEN_WIDTH); + CFont::SetJustifyOff(); + CFont::SetColor(CRGBA(m_Colour.r, m_Colour.g, m_Colour.b, (255.0f - 255.0f * fLifeTime) * m_fOpacity)); + CFont::SetBackGroundOnlyTextOff(); + FONT_LOCALE(FONT_STANDARD); + CFont::PrintString(vecOut.x, vecOut.y, m_aText); + } + } +} + +void +CMoneyMessages::Init() +{ + for (int32 i = 0; i < NUMMONEYMESSAGES; i++) + aMoneyMessages[i].m_nTimeRegistered = 0; +} + +void +CMoneyMessages::Render() +{ + for (int32 i = 0; i < NUMMONEYMESSAGES; i++) { + if (aMoneyMessages[i].m_nTimeRegistered != 0) + aMoneyMessages[i].Render(); + } +} + +void +CMoneyMessages::RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity) +{ + uint32 i; +#ifdef FIX_BUGS + for(i = 0; i < NUMMONEYMESSAGES && aMoneyMessages[i].m_nTimeRegistered != 0; i++); +#else + for(i = 0; aMoneyMessages[i].m_nTimeRegistered != 0 && i < NUMMONEYMESSAGES; i++); +#endif + + if(i < NUMMONEYMESSAGES) { + // Add data of this money message to the array + AsciiToUnicode(pText, aMoneyMessages[i].m_aText); + + aMoneyMessages[i].m_nTimeRegistered = CTimer::GetTimeInMilliseconds(); + aMoneyMessages[i].m_vecPosition = vecPos; + aMoneyMessages[i].m_Colour.red = bRed; + aMoneyMessages[i].m_Colour.green = bGreen; + aMoneyMessages[i].m_Colour.blue = bBlue; + aMoneyMessages[i].m_fSize = fSize; + aMoneyMessages[i].m_fOpacity = fOpacity; + } +} + +CRGBA FoamColour(255, 255, 255, 255); +uint32 CSpecialParticleStuff::BoatFromStart; + +void +CSpecialParticleStuff::CreateFoamAroundObject(CMatrix* pMatrix, float innerFw, float innerRg, float innerUp, int32 particles) +{ + float outerFw = innerFw + 5.0f; + float outerRg = innerRg + 5.0f; + float outerUp = innerUp + 5.0f; + for (int attempts = 0; particles > 0 && attempts < 1000; attempts++) { + CVector pos; + int rnd = CGeneral::GetRandomNumber(); + pos.x = (int8)(rnd - 128) * innerFw / 110.0f; + pos.y = (int8)((rnd >> 8) - 128) * innerFw / 110.0f; + pos.z = 0.0f; + if (DotProduct2D(pos, TheCamera.GetForward()) >= 0) + continue; + // was there any point in adding it here? + pos += pMatrix->GetPosition(); + pos.z = 2.0f; + float fw = Abs(DotProduct(pMatrix->GetForward(), pos - pMatrix->GetPosition())); + if (fw >= outerFw) + continue; + float rg = Abs(DotProduct(pMatrix->GetRight(), pos - pMatrix->GetPosition())); + if (rg >= outerRg) + continue; + float up = Abs(DotProduct(pMatrix->GetUp(), pos - pMatrix->GetPosition())); + if (up >= outerUp) + continue; + if (fw > innerFw || rg > innerRg || up > innerUp) { + CParticle::AddParticle(PARTICLE_STEAM2, pos, CVector(0.0f, 0.0f, 0.0f), nil, 4.0f, FoamColour, 1, 0, 0, 0); + particles--; + } + } +} + +void +CSpecialParticleStuff::StartBoatFoamAnimation() +{ + BoatFromStart = CTimer::GetTimeInMilliseconds(); +} + +void +CSpecialParticleStuff::UpdateBoatFoamAnimation(CMatrix* pMatrix) +{ + static int32 FrameInAnimation = 0; + static float X, Y, Z, dX, dY, dZ; + CreateFoamAroundObject(pMatrix, 107.0f, 24.1f, 30.5f, 2); + uint32 prev = CTimer::GetPreviousTimeInMilliseconds(); + uint32 cur = CTimer::GetTimeInMilliseconds(); + if (FrameInAnimation != 0) { + X += dX; + Y += dY; + Z += dZ; + CVector pos = *pMatrix * CVector(X, Y, Z); + CParticle::AddParticle(PARTICLE_STEAM_NY, pos, CVector(0.0f, 0.0f, 0.0f), + nil, FrameInAnimation * 0.5f + 2.0f, FoamColour, 1, 0, 0, 0); + if (++FrameInAnimation > 15) + FrameInAnimation = 0; + } + if ((cur & 0x3FF) < (prev & 0x3FF)) { + FrameInAnimation = 1; + int rnd = CGeneral::GetRandomNumber(); + X = (int8)(rnd - 128) * 0.2f; + Y = (int8)((rnd >> 8) - 128) * 0.2f; + Z = 10.0f; + rnd = CGeneral::GetRandomNumber(); + dX = (int8)(rnd - 128) * 0.02f; + dY = (int8)((rnd >> 8) - 128) * 0.02f; + dZ = 2.0f; + } +} diff --git a/src/renderer/SpecialFX.h b/src/renderer/SpecialFX.h new file mode 100644 index 00000000..f163d8ca --- /dev/null +++ b/src/renderer/SpecialFX.h @@ -0,0 +1,249 @@ +#pragma once + +//file done + +class CSpecialFX +{ +public: + static bool bVideoCam; + static bool bLiftCam; + static bool bSnapShotActive; + static int32 SnapShotFrames; + + static void Render(void); + static void Update(void); + static void Init(void); + static void Shutdown(void); + static void AddWeaponStreak(int type); + static void Render2DFXs(); +}; + + +class CRegisteredMotionBlurStreak +{ +public: + uintptr m_id; + uint8 m_red; + uint8 m_green; + uint8 m_blue; + CVector m_pos1[3]; + CVector m_pos2[3]; + bool m_isValid[3]; + + void Update(void); + void Render(void); +}; + + +class CMotionBlurStreaks +{ + static CRegisteredMotionBlurStreak aStreaks[NUMMBLURSTREAKS]; +public: + static void Init(void); + static void Update(void); + static void RegisterStreak(uintptr id, uint8 r, uint8 g, uint8 b, CVector p1, CVector p2); + static void Render(void); +}; + + +struct CBulletTrace +{ + CVector m_vecStartPos; + CVector m_vecEndPos; + bool m_bInUse; + uint32 m_nCreationTime; + uint32 m_nLifeTime; + float m_fThickness; + uint8 m_fVisibility; + + void Update(void); +}; + + +class CBulletTraces +{ +public: + static CBulletTrace aTraces[NUMBULLETTRACES]; + + static void Init(void); + static void Render(void); + static void Update(void); + static void AddTrace(CVector* start, CVector* end, float thickness, uint32 lifeTime, uint8 visibility); + static void AddTrace(CVector* start, CVector* end, int32 weaponType, class CEntity* shooter); +}; + +enum +{ + MARKERTYPE_0 = 0, + MARKERTYPE_ARROW, + MARKERTYPE_2, + MARKERTYPE_3, + MARKERTYPE_CYLINDER, + NUMMARKERTYPES, + + MARKERTYPE_INVALID = 0x101 +}; + + +class C3dMarker +{ +public: + CMatrix m_Matrix; + RpAtomic *m_pAtomic; + RpMaterial *m_pMaterial; + uint16 m_nType; + bool m_bIsUsed; + bool m_bFindZOnNextPlacement; + uint32 m_nIdentifier; + RwRGBA m_Color; + uint16 m_nPulsePeriod; + int16 m_nRotateRate; + uint32 m_nStartTime; + float m_fPulseFraction; + float m_fStdSize; + float m_fSize; + float m_fBrightness; + float m_fCameraRange; + + bool AddMarker(uint32 identifier, uint16 type, float fSize, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate); + void DeleteMarkerObject(); + void Render(); +}; + + +class C3dMarkers +{ +public: + static void Init(); + static void Shutdown(); + static C3dMarker *PlaceMarker(uint32 id, uint16 type, CVector &pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate); + static void PlaceMarkerSet(uint32 id, uint16 type, CVector &pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate); + static void Render(); + static void Update(); + + static C3dMarker m_aMarkerArray[NUM3DMARKERS]; + static int32 NumActiveMarkers; + static RpClump* m_pRpClumpArray[NUMMARKERTYPES]; +}; + +enum +{ + BRIGHTLIGHT_INVALID, + BRIGHTLIGHT_TRAFFIC_GREEN, + BRIGHTLIGHT_TRAFFIC_YELLOW, + BRIGHTLIGHT_TRAFFIC_RED, + + // white + BRIGHTLIGHT_FRONT_LONG, + BRIGHTLIGHT_FRONT_SMALL, + BRIGHTLIGHT_FRONT_BIG, + BRIGHTLIGHT_FRONT_TALL, + + // red + BRIGHTLIGHT_REAR_LONG, + BRIGHTLIGHT_REAR_SMALL, + BRIGHTLIGHT_REAR_BIG, + BRIGHTLIGHT_REAR_TALL, + + BRIGHTLIGHT_SIREN, // unused + + BRIGHTLIGHT_FRONT = BRIGHTLIGHT_FRONT_LONG, + BRIGHTLIGHT_REAR = BRIGHTLIGHT_REAR_LONG, +}; + + +class CBrightLight +{ +public: + CVector m_pos; + CVector m_up; + CVector m_side; + CVector m_front; + float m_camDist; + uint8 m_type; + uint8 m_red; + uint8 m_green; + uint8 m_blue; +}; + + +class CBrightLights +{ + static int NumBrightLights; + static CBrightLight aBrightLights[NUMBRIGHTLIGHTS]; +public: + static void Init(void); + static void RegisterOne(CVector pos, CVector up, CVector side, CVector front, + uint8 type, uint8 red = 0, uint8 green = 0, uint8 blue = 0); + static void Render(void); + static void RenderOutGeometryBuffer(void); +}; + + +enum +{ + SHINYTEXT_WALK = 1, + SHINYTEXT_FLAT +}; + + +class CShinyText +{ +public: + CVector m_verts[4]; + CVector2D m_texCoords[4]; + float m_camDist; + uint8 m_type; + uint8 m_red; + uint8 m_green; + uint8 m_blue; +}; + + +class CShinyTexts +{ + static int NumShinyTexts; + static CShinyText aShinyTexts[NUMSHINYTEXTS]; +public: + static void Init(void); + static void RegisterOne(CVector p0, CVector p1, CVector p2, CVector p3, + float u0, float v0, float u1, float v1, float u2, float v2, float u3, float v3, + uint8 type, uint8 red, uint8 green, uint8 blue, float maxDist); //not used + static void Render(void); + static void RenderOutGeometryBuffer(void); +}; + + +class CMoneyMessage +{ + friend class CMoneyMessages; + + uint32 m_nTimeRegistered; + CVector m_vecPosition; + wchar m_aText[16]; + CRGBA m_Colour; + float m_fSize; + float m_fOpacity; +public: + void Render(); +}; + + +class CMoneyMessages +{ + static CMoneyMessage aMoneyMessages[NUMMONEYMESSAGES]; +public: + static void Init(); + static void Render(); + static void RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity); +}; + + +class CSpecialParticleStuff +{ + static uint32 BoatFromStart; +public: + static void CreateFoamAroundObject(CMatrix*, float, float, float, int32); //not used + static void StartBoatFoamAnimation(); //not used + static void UpdateBoatFoamAnimation(CMatrix*); //not used +}; diff --git a/src/renderer/Sprite.cpp b/src/renderer/Sprite.cpp new file mode 100644 index 00000000..58b29ea9 --- /dev/null +++ b/src/renderer/Sprite.cpp @@ -0,0 +1,599 @@ +#include "common.h" + +#include "main.h" +#include "Draw.h" +#include "Camera.h" +#include "Sprite.h" + +float CSprite::m_f2DNearScreenZ; +float CSprite::m_f2DFarScreenZ; +float CSprite::m_fRecipNearClipPlane; +int32 CSprite::m_bFlushSpriteBufferSwitchZTest; + +float +CSprite::CalcHorizonCoors(void) +{ + CVector p = TheCamera.GetPosition() + CVector(TheCamera.CamFrontXNorm, TheCamera.CamFrontYNorm, 0.0f)*3000.0f; + p.z = 0.0f; + p = TheCamera.m_viewMatrix * p; + return p.y * SCREEN_HEIGHT / p.z; +} + +bool +CSprite::CalcScreenCoors(const RwV3d &in, RwV3d *out, float *outw, float *outh, bool farclip) +{ + CVector viewvec = TheCamera.m_viewMatrix * in; + *out = viewvec; + if(out->z <= CDraw::GetNearClipZ() + 1.0f) return false; + if(out->z >= CDraw::GetFarClipZ() && farclip) return false; + float recip = 1.0f/out->z; + out->x *= SCREEN_WIDTH * recip; + out->y *= SCREEN_HEIGHT * recip; + const float fov = DefaultFOV; + // this is used to scale correctly if you zoom in with sniper rifle + float fovScale = fov / CDraw::GetFOV(); + +#ifdef FIX_SPRITES + *outw = CDraw::ms_bFixSprites ? (fovScale * recip * SCREEN_HEIGHT) : (fovScale * SCREEN_SCALE_AR(recip) * SCREEN_WIDTH); +#else + *outw = fovScale * SCREEN_SCALE_AR(recip) * SCREEN_WIDTH; +#endif + *outh = fovScale * recip * SCREEN_HEIGHT; + + return true; +} + +#define SPRITEBUFFERSIZE 64 +static int32 nSpriteBufferIndex; +static RwIm2DVertex SpriteBufferVerts[SPRITEBUFFERSIZE*6]; +static RwIm2DVertex verts[4]; + +void +CSprite::InitSpriteBuffer(void) +{ + m_f2DNearScreenZ = RwIm2DGetNearScreenZ(); + m_f2DFarScreenZ = RwIm2DGetFarScreenZ(); +} + +void +CSprite::InitSpriteBuffer2D(void) +{ + m_fRecipNearClipPlane = 1.0f / RwCameraGetNearClipPlane(Scene.camera); + InitSpriteBuffer(); +} + +void +CSprite::FlushSpriteBuffer(void) +{ + if(nSpriteBufferIndex > 0){ + if(m_bFlushSpriteBufferSwitchZTest){ + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwIm2DRenderPrimitive(rwPRIMTYPETRILIST, SpriteBufferVerts, nSpriteBufferIndex*6); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + }else + RwIm2DRenderPrimitive(rwPRIMTYPETRILIST, SpriteBufferVerts, nSpriteBufferIndex*6); + nSpriteBufferIndex = 0; + } +} + +void +CSprite::RenderOneXLUSprite(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, uint8 a) +{ + static short indices[] = { 0, 1, 2, 3 }; + // 0---3 + // | | + // 1---2 + float xs[4]; + float ys[4]; + float us[4]; + float vs[4]; + int i; + + xs[0] = x-w; us[0] = 0.0f; + xs[1] = x-w; us[1] = 0.0f; + xs[2] = x+w; us[2] = 1.0f; + xs[3] = x+w; us[3] = 1.0f; + + ys[0] = y-h; vs[0] = 0.0f; + ys[1] = y+h; vs[1] = 1.0f; + ys[2] = y+h; vs[2] = 1.0f; + ys[3] = y-h; vs[3] = 0.0f; + + // clip + for(i = 0; i < 4; i++){ + if(xs[i] < 0.0f){ + us[i] = -xs[i] / (2.0f*w); + xs[i] = 0.0f; + } + if(xs[i] > SCREEN_WIDTH){ + us[i] = 1.0f - (xs[i]-SCREEN_WIDTH) / (2.0f*w); + xs[i] = SCREEN_WIDTH; + } + if(ys[i] < 0.0f){ + vs[i] = -ys[i] / (2.0f*h); + ys[i] = 0.0f; + } + if(ys[i] > SCREEN_HEIGHT){ + vs[i] = 1.0f - (ys[i]-SCREEN_HEIGHT) / (2.0f*h); + ys[i] = SCREEN_HEIGHT; + } + } + + // (DrawZ - DrawNear)/(DrawFar - DrawNear) = (SpriteZ-SpriteNear)/(SpriteFar-SpriteNear) + // So to calculate SpriteZ: + float screenz = m_f2DNearScreenZ + + (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / + ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); + + for(i = 0; i < 4; i++){ + RwIm2DVertexSetScreenX(&verts[i], xs[i]); + RwIm2DVertexSetScreenY(&verts[i], ys[i]); + RwIm2DVertexSetScreenZ(&verts[i], screenz); + RwIm2DVertexSetCameraZ(&verts[i], z); + RwIm2DVertexSetRecipCameraZ(&verts[i], recipz); + RwIm2DVertexSetIntRGBA(&verts[i], r*intens>>8, g*intens>>8, b*intens>>8, a); + RwIm2DVertexSetU(&verts[i], us[i], recipz); + RwIm2DVertexSetV(&verts[i], vs[i], recipz); + } + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, verts, 4); +} + +void +CSprite::RenderOneXLUSprite_Rotate_Aspect(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float rotation, uint8 a) +{ + float c = Cos(rotation); + float s = Sin(rotation); + + float xs[4]; + float ys[4]; + float us[4]; + float vs[4]; + int i; + + // Fade out when too near + // why not in buffered version? + if(z < 2.3f){ + if(z < 1.3f) + return; + int f = (z - 1.3f)/(2.3f-1.3f) * 255; + r = f*r >> 8; + g = f*g >> 8; + b = f*b >> 8; + intens = f*intens >> 8; + } + + xs[0] = x + w*(-c-s); us[0] = 0.0f; + xs[1] = x + w*(-c+s); us[1] = 0.0f; + xs[2] = x + w*(+c+s); us[2] = 1.0f; + xs[3] = x + w*(+c-s); us[3] = 1.0f; + + ys[0] = y + h*(-c+s); vs[0] = 0.0f; + ys[1] = y + h*(+c+s); vs[1] = 1.0f; + ys[2] = y + h*(+c-s); vs[2] = 1.0f; + ys[3] = y + h*(-c-s); vs[3] = 0.0f; + + // No clipping, just culling + if(xs[0] < 0.0f && xs[1] < 0.0f && xs[2] < 0.0f && xs[3] < 0.0f) return; + if(ys[0] < 0.0f && ys[1] < 0.0f && ys[2] < 0.0f && ys[3] < 0.0f) return; + if(xs[0] > SCREEN_WIDTH && xs[1] > SCREEN_WIDTH && + xs[2] > SCREEN_WIDTH && xs[3] > SCREEN_WIDTH) return; + if(ys[0] > SCREEN_HEIGHT && ys[1] > SCREEN_HEIGHT && + ys[2] > SCREEN_HEIGHT && ys[3] > SCREEN_HEIGHT) return; + + float screenz = m_f2DNearScreenZ + + (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / + ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); + + for(i = 0; i < 4; i++){ + RwIm2DVertexSetScreenX(&verts[i], xs[i]); + RwIm2DVertexSetScreenY(&verts[i], ys[i]); + RwIm2DVertexSetScreenZ(&verts[i], screenz); + RwIm2DVertexSetCameraZ(&verts[i], z); + RwIm2DVertexSetRecipCameraZ(&verts[i], recipz); + RwIm2DVertexSetIntRGBA(&verts[i], r*intens>>8, g*intens>>8, b*intens>>8, a); + RwIm2DVertexSetU(&verts[i], us[i], recipz); + RwIm2DVertexSetV(&verts[i], vs[i], recipz); + } + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, verts, 4); +} + +void +CSprite::RenderBufferedOneXLUSprite(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, uint8 a) +{ + m_bFlushSpriteBufferSwitchZTest = 0; + + // 0---3 + // | | + // 1---2 + float xs[4]; + float ys[4]; + float us[4]; + float vs[4]; + int i; + + xs[0] = x-w; us[0] = 0.0f; + xs[1] = x-w; us[1] = 0.0f; + xs[2] = x+w; us[2] = 1.0f; + xs[3] = x+w; us[3] = 1.0f; + + ys[0] = y-h; vs[0] = 0.0f; + ys[1] = y+h; vs[1] = 1.0f; + ys[2] = y+h; vs[2] = 1.0f; + ys[3] = y-h; vs[3] = 0.0f; + + // clip + for(i = 0; i < 4; i++){ + if(xs[i] < 0.0f){ + us[i] = -xs[i] / (2.0f*w); + xs[i] = 0.0f; + } + if(xs[i] > SCREEN_WIDTH){ + us[i] = 1.0f - (xs[i]-SCREEN_WIDTH) / (2.0f*w); + xs[i] = SCREEN_WIDTH; + } + if(ys[i] < 0.0f){ + vs[i] = -ys[i] / (2.0f*h); + ys[i] = 0.0f; + } + if(ys[i] > SCREEN_HEIGHT){ + vs[i] = 1.0f - (ys[i]-SCREEN_HEIGHT) / (2.0f*h); + ys[i] = SCREEN_HEIGHT; + } + } + + float screenz = m_f2DNearScreenZ + + (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / + ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); + + RwIm2DVertex *vert = &SpriteBufferVerts[nSpriteBufferIndex*6]; + static int indices[6] = { 0, 1, 2, 3, 0, 2 }; + for(i = 0; i < 6; i++){ + RwIm2DVertexSetScreenX(&vert[i], xs[indices[i]]); + RwIm2DVertexSetScreenY(&vert[i], ys[indices[i]]); + RwIm2DVertexSetScreenZ(&vert[i], screenz); + RwIm2DVertexSetCameraZ(&vert[i], z); + RwIm2DVertexSetRecipCameraZ(&vert[i], recipz); + RwIm2DVertexSetIntRGBA(&vert[i], r*intens>>8, g*intens>>8, b*intens>>8, a); + RwIm2DVertexSetU(&vert[i], us[indices[i]], recipz); + RwIm2DVertexSetV(&vert[i], vs[indices[i]], recipz); + } + nSpriteBufferIndex++; + if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) + FlushSpriteBuffer(); +} + +void +CSprite::RenderBufferedOneXLUSprite_Rotate_Dimension(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float rotation, uint8 a) +{ + m_bFlushSpriteBufferSwitchZTest = 0; + // TODO: replace with lookup + float c = Cos(rotation); + float s = Sin(rotation); + + float xs[4]; + float ys[4]; + float us[4]; + float vs[4]; + int i; + + xs[0] = x - c*w - s*h; us[0] = 0.0f; + xs[1] = x - c*w + s*h; us[1] = 0.0f; + xs[2] = x + c*w + s*h; us[2] = 1.0f; + xs[3] = x + c*w - s*h; us[3] = 1.0f; + + ys[0] = y - c*h + s*w; vs[0] = 0.0f; + ys[1] = y + c*h + s*w; vs[1] = 1.0f; + ys[2] = y + c*h - s*w; vs[2] = 1.0f; + ys[3] = y - c*h - s*w; vs[3] = 0.0f; + + // No clipping, just culling + if(xs[0] < 0.0f && xs[1] < 0.0f && xs[2] < 0.0f && xs[3] < 0.0f) return; + if(ys[0] < 0.0f && ys[1] < 0.0f && ys[2] < 0.0f && ys[3] < 0.0f) return; + if(xs[0] > SCREEN_WIDTH && xs[1] > SCREEN_WIDTH && + xs[2] > SCREEN_WIDTH && xs[3] > SCREEN_WIDTH) return; + if(ys[0] > SCREEN_HEIGHT && ys[1] > SCREEN_HEIGHT && + ys[2] > SCREEN_HEIGHT && ys[3] > SCREEN_HEIGHT) return; + + float screenz = m_f2DNearScreenZ + + (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / + ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); + + RwIm2DVertex *vert = &SpriteBufferVerts[nSpriteBufferIndex*6]; + static int indices[6] = { 0, 1, 2, 3, 0, 2 }; + for(i = 0; i < 6; i++){ + RwIm2DVertexSetScreenX(&vert[i], xs[indices[i]]); + RwIm2DVertexSetScreenY(&vert[i], ys[indices[i]]); + RwIm2DVertexSetScreenZ(&vert[i], screenz); + RwIm2DVertexSetCameraZ(&vert[i], z); + RwIm2DVertexSetRecipCameraZ(&vert[i], recipz); + RwIm2DVertexSetIntRGBA(&vert[i], r*intens>>8, g*intens>>8, b*intens>>8, a); + RwIm2DVertexSetU(&vert[i], us[indices[i]], recipz); + RwIm2DVertexSetV(&vert[i], vs[indices[i]], recipz); + } + nSpriteBufferIndex++; + if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) + FlushSpriteBuffer(); +} + +void +CSprite::RenderBufferedOneXLUSprite_Rotate_Aspect(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float rotation, uint8 a) +{ + m_bFlushSpriteBufferSwitchZTest = 0; + float c = Cos(rotation); + float s = Sin(rotation); + + float xs[4]; + float ys[4]; + float us[4]; + float vs[4]; + int i; + + xs[0] = x + w*(-c-s); us[0] = 0.0f; + xs[1] = x + w*(-c+s); us[1] = 0.0f; + xs[2] = x + w*(+c+s); us[2] = 1.0f; + xs[3] = x + w*(+c-s); us[3] = 1.0f; + + ys[0] = y + h*(-c+s); vs[0] = 0.0f; + ys[1] = y + h*(+c+s); vs[1] = 1.0f; + ys[2] = y + h*(+c-s); vs[2] = 1.0f; + ys[3] = y + h*(-c-s); vs[3] = 0.0f; + + // No clipping, just culling + if(xs[0] < 0.0f && xs[1] < 0.0f && xs[2] < 0.0f && xs[3] < 0.0f) return; + if(ys[0] < 0.0f && ys[1] < 0.0f && ys[2] < 0.0f && ys[3] < 0.0f) return; + if(xs[0] > SCREEN_WIDTH && xs[1] > SCREEN_WIDTH && + xs[2] > SCREEN_WIDTH && xs[3] > SCREEN_WIDTH) return; + if(ys[0] > SCREEN_HEIGHT && ys[1] > SCREEN_HEIGHT && + ys[2] > SCREEN_HEIGHT && ys[3] > SCREEN_HEIGHT) return; + + float screenz = m_f2DNearScreenZ + + (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / + ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); + + RwIm2DVertex *vert = &SpriteBufferVerts[nSpriteBufferIndex*6]; + static int indices[6] = { 0, 1, 2, 3, 0, 2 }; + for(i = 0; i < 6; i++){ + RwIm2DVertexSetScreenX(&vert[i], xs[indices[i]]); + RwIm2DVertexSetScreenY(&vert[i], ys[indices[i]]); + RwIm2DVertexSetScreenZ(&vert[i], screenz); + RwIm2DVertexSetCameraZ(&vert[i], z); + RwIm2DVertexSetRecipCameraZ(&vert[i], recipz); + RwIm2DVertexSetIntRGBA(&vert[i], r*intens>>8, g*intens>>8, b*intens>>8, a); + RwIm2DVertexSetU(&vert[i], us[indices[i]], recipz); + RwIm2DVertexSetV(&vert[i], vs[indices[i]], recipz); + } + nSpriteBufferIndex++; + if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) + FlushSpriteBuffer(); +} + +void +CSprite::RenderBufferedOneXLUSprite_Rotate_2Colours(float x, float y, float z, float w, float h, uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2, float cx, float cy, float recipz, float rotation, uint8 a) +{ + m_bFlushSpriteBufferSwitchZTest = 0; + float c = Cos(rotation); + float s = Sin(rotation); + + float xs[4]; + float ys[4]; + float us[4]; + float vs[4]; + float cf[4]; + int i; + + xs[0] = x + w*(-c-s); us[0] = 0.0f; + xs[1] = x + w*(-c+s); us[1] = 0.0f; + xs[2] = x + w*(+c+s); us[2] = 1.0f; + xs[3] = x + w*(+c-s); us[3] = 1.0f; + + ys[0] = y + h*(-c+s); vs[0] = 0.0f; + ys[1] = y + h*(+c+s); vs[1] = 1.0f; + ys[2] = y + h*(+c-s); vs[2] = 1.0f; + ys[3] = y + h*(-c-s); vs[3] = 0.0f; + + // No clipping, just culling + if(xs[0] < 0.0f && xs[1] < 0.0f && xs[2] < 0.0f && xs[3] < 0.0f) return; + if(ys[0] < 0.0f && ys[1] < 0.0f && ys[2] < 0.0f && ys[3] < 0.0f) return; + if(xs[0] > SCREEN_WIDTH && xs[1] > SCREEN_WIDTH && + xs[2] > SCREEN_WIDTH && xs[3] > SCREEN_WIDTH) return; + if(ys[0] > SCREEN_HEIGHT && ys[1] > SCREEN_HEIGHT && + ys[2] > SCREEN_HEIGHT && ys[3] > SCREEN_HEIGHT) return; + + // Colour factors, cx/y is the direction in which colours change from rgb1 to rgb2 + cf[0] = (cx*(-c-s) + cy*(-c+s))*0.5f + 0.5f; + cf[0] = Clamp(cf[0], 0.0f, 1.0f); + cf[1] = (cx*(-c+s) + cy*( c+s))*0.5f + 0.5f; + cf[1] = Clamp(cf[1], 0.0f, 1.0f); + cf[2] = (cx*( c+s) + cy*( c-s))*0.5f + 0.5f; + cf[2] = Clamp(cf[2], 0.0f, 1.0f); + cf[3] = (cx*( c-s) + cy*(-c-s))*0.5f + 0.5f; + cf[3] = Clamp(cf[3], 0.0f, 1.0f); + + float screenz = m_f2DNearScreenZ + + (z-CDraw::GetNearClipZ())*(m_f2DFarScreenZ-m_f2DNearScreenZ)*CDraw::GetFarClipZ() / + ((CDraw::GetFarClipZ()-CDraw::GetNearClipZ())*z); + + RwIm2DVertex *vert = &SpriteBufferVerts[nSpriteBufferIndex*6]; + static int indices[6] = { 0, 1, 2, 3, 0, 2 }; + for(i = 0; i < 6; i++){ + RwIm2DVertexSetScreenX(&vert[i], xs[indices[i]]); + RwIm2DVertexSetScreenY(&vert[i], ys[indices[i]]); + RwIm2DVertexSetScreenZ(&vert[i], screenz); + RwIm2DVertexSetCameraZ(&vert[i], z); + RwIm2DVertexSetRecipCameraZ(&vert[i], recipz); + RwIm2DVertexSetIntRGBA(&vert[i], + r1*cf[indices[i]] + r2*(1.0f - cf[indices[i]]), + g1*cf[indices[i]] + g2*(1.0f - cf[indices[i]]), + b1*cf[indices[i]] + b2*(1.0f - cf[indices[i]]), + a); + RwIm2DVertexSetU(&vert[i], us[indices[i]], recipz); + RwIm2DVertexSetV(&vert[i], vs[indices[i]], recipz); + } + nSpriteBufferIndex++; + if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) + FlushSpriteBuffer(); +} + +void +CSprite::Set6Vertices2D(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) +{ + float screenz, recipz; + float z = RwCameraGetNearClipPlane(Scene.camera); // not done by game + + screenz = m_f2DNearScreenZ; + recipz = m_fRecipNearClipPlane; + + RwIm2DVertexSetScreenX(&verts[0], r.left); + RwIm2DVertexSetScreenY(&verts[0], r.top); + RwIm2DVertexSetScreenZ(&verts[0], screenz); + RwIm2DVertexSetCameraZ(&verts[0], z); + RwIm2DVertexSetRecipCameraZ(&verts[0], recipz); + RwIm2DVertexSetIntRGBA(&verts[0], c2.r, c2.g, c2.b, c2.a); + RwIm2DVertexSetU(&verts[0], 0.0f, recipz); + RwIm2DVertexSetV(&verts[0], 0.0f, recipz); + + RwIm2DVertexSetScreenX(&verts[1], r.right); + RwIm2DVertexSetScreenY(&verts[1], r.top); + RwIm2DVertexSetScreenZ(&verts[1], screenz); + RwIm2DVertexSetCameraZ(&verts[1], z); + RwIm2DVertexSetRecipCameraZ(&verts[1], recipz); + RwIm2DVertexSetIntRGBA(&verts[1], c3.r, c3.g, c3.b, c3.a); + RwIm2DVertexSetU(&verts[1], 1.0f, recipz); + RwIm2DVertexSetV(&verts[1], 0.0f, recipz); + + RwIm2DVertexSetScreenX(&verts[2], r.right); + RwIm2DVertexSetScreenY(&verts[2], r.bottom); + RwIm2DVertexSetScreenZ(&verts[2], screenz); + RwIm2DVertexSetCameraZ(&verts[2], z); + RwIm2DVertexSetRecipCameraZ(&verts[2], recipz); + RwIm2DVertexSetIntRGBA(&verts[2], c1.r, c1.g, c1.b, c1.a); + RwIm2DVertexSetU(&verts[2], 1.0f, recipz); + RwIm2DVertexSetV(&verts[2], 1.0f, recipz); + + RwIm2DVertexSetScreenX(&verts[3], r.left); + RwIm2DVertexSetScreenY(&verts[3], r.bottom); + RwIm2DVertexSetScreenZ(&verts[3], screenz); + RwIm2DVertexSetCameraZ(&verts[3], z); + RwIm2DVertexSetRecipCameraZ(&verts[3], recipz); + RwIm2DVertexSetIntRGBA(&verts[3], c0.r, c0.g, c0.b, c0.a); + RwIm2DVertexSetU(&verts[3], 0.0f, recipz); + RwIm2DVertexSetV(&verts[3], 1.0f, recipz); + + RwIm2DVertexSetScreenX(&verts[4], r.left); + RwIm2DVertexSetScreenY(&verts[4], r.top); + RwIm2DVertexSetScreenZ(&verts[4], screenz); + RwIm2DVertexSetCameraZ(&verts[4], z); + RwIm2DVertexSetRecipCameraZ(&verts[4], recipz); + RwIm2DVertexSetIntRGBA(&verts[4], c2.r, c2.g, c2.b, c2.a); + RwIm2DVertexSetU(&verts[4], 0.0f, recipz); + RwIm2DVertexSetV(&verts[4], 0.0f, recipz); + + RwIm2DVertexSetScreenX(&verts[5], r.right); + RwIm2DVertexSetScreenY(&verts[5], r.bottom); + RwIm2DVertexSetScreenZ(&verts[5], screenz); + RwIm2DVertexSetCameraZ(&verts[5], z); + RwIm2DVertexSetRecipCameraZ(&verts[5], recipz); + RwIm2DVertexSetIntRGBA(&verts[5], c1.r, c1.g, c1.b, c1.a); + RwIm2DVertexSetU(&verts[5], 1.0f, recipz); + RwIm2DVertexSetV(&verts[5], 1.0f, recipz); +} + +void +CSprite::Set6Vertices2D(RwIm2DVertex *verts, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, + const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) +{ + float screenz, recipz; + float z = RwCameraGetNearClipPlane(Scene.camera); // not done by game + + screenz = m_f2DNearScreenZ; + recipz = m_fRecipNearClipPlane; + + RwIm2DVertexSetScreenX(&verts[0], x3); + RwIm2DVertexSetScreenY(&verts[0], y3); + RwIm2DVertexSetScreenZ(&verts[0], screenz); + RwIm2DVertexSetCameraZ(&verts[0], z); + RwIm2DVertexSetRecipCameraZ(&verts[0], recipz); + RwIm2DVertexSetIntRGBA(&verts[0], c2.r, c2.g, c2.b, c2.a); + RwIm2DVertexSetU(&verts[0], 0.0f, recipz); + RwIm2DVertexSetV(&verts[0], 0.0f, recipz); + + RwIm2DVertexSetScreenX(&verts[1], x4); + RwIm2DVertexSetScreenY(&verts[1], y4); + RwIm2DVertexSetScreenZ(&verts[1], screenz); + RwIm2DVertexSetCameraZ(&verts[1], z); + RwIm2DVertexSetRecipCameraZ(&verts[1], recipz); + RwIm2DVertexSetIntRGBA(&verts[1], c3.r, c3.g, c3.b, c3.a); + RwIm2DVertexSetU(&verts[1], 1.0f, recipz); + RwIm2DVertexSetV(&verts[1], 0.0f, recipz); + + RwIm2DVertexSetScreenX(&verts[2], x2); + RwIm2DVertexSetScreenY(&verts[2], y2); + RwIm2DVertexSetScreenZ(&verts[2], screenz); + RwIm2DVertexSetCameraZ(&verts[2], z); + RwIm2DVertexSetRecipCameraZ(&verts[2], recipz); + RwIm2DVertexSetIntRGBA(&verts[2], c1.r, c1.g, c1.b, c1.a); + RwIm2DVertexSetU(&verts[2], 1.0f, recipz); + RwIm2DVertexSetV(&verts[2], 1.0f, recipz); + + RwIm2DVertexSetScreenX(&verts[3], x1); + RwIm2DVertexSetScreenY(&verts[3], y1); + RwIm2DVertexSetScreenZ(&verts[3], screenz); + RwIm2DVertexSetCameraZ(&verts[3], z); + RwIm2DVertexSetRecipCameraZ(&verts[3], recipz); + RwIm2DVertexSetIntRGBA(&verts[3], c0.r, c0.g, c0.b, c0.a); + RwIm2DVertexSetU(&verts[3], 0.0f, recipz); + RwIm2DVertexSetV(&verts[3], 1.0f, recipz); + + RwIm2DVertexSetScreenX(&verts[4], x3); + RwIm2DVertexSetScreenY(&verts[4], y3); + RwIm2DVertexSetScreenZ(&verts[4], screenz); + RwIm2DVertexSetCameraZ(&verts[4], z); + RwIm2DVertexSetRecipCameraZ(&verts[4], recipz); + RwIm2DVertexSetIntRGBA(&verts[4], c2.r, c2.g, c2.b, c2.a); + RwIm2DVertexSetU(&verts[4], 0.0f, recipz); + RwIm2DVertexSetV(&verts[4], 0.0f, recipz); + + RwIm2DVertexSetScreenX(&verts[5], x2); + RwIm2DVertexSetScreenY(&verts[5], y2); + RwIm2DVertexSetScreenZ(&verts[5], screenz); + RwIm2DVertexSetCameraZ(&verts[5], z); + RwIm2DVertexSetRecipCameraZ(&verts[5], recipz); + RwIm2DVertexSetIntRGBA(&verts[5], c1.r, c1.g, c1.b, c1.a); + RwIm2DVertexSetU(&verts[5], 1.0f, recipz); + RwIm2DVertexSetV(&verts[5], 1.0f, recipz); +} + +void +CSprite::RenderBufferedOneXLUSprite2D(float x, float y, float w, float h, const RwRGBA &colour, int16 intens, uint8 alpha) +{ + m_bFlushSpriteBufferSwitchZTest = 1; + CRGBA col(intens * colour.red >> 8, intens * colour.green >> 8, intens * colour.blue >> 8, alpha); + CRect rect(x - w, y - h, x + h, y + h); + Set6Vertices2D(&SpriteBufferVerts[6 * nSpriteBufferIndex], rect, col, col, col, col); + nSpriteBufferIndex++; + if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) + FlushSpriteBuffer(); +} + +void +CSprite::RenderBufferedOneXLUSprite2D_Rotate_Dimension(float x, float y, float w, float h, const RwRGBA &colour, int16 intens, float rotation, uint8 alpha) +{ + m_bFlushSpriteBufferSwitchZTest = 1; + CRGBA col(intens * colour.red >> 8, intens * colour.green >> 8, intens * colour.blue >> 8, alpha); + float c = Cos(rotation); + float s = Sin(rotation); + + Set6Vertices2D(&SpriteBufferVerts[6 * nSpriteBufferIndex], + x + c*w - s*h, + y - c*h - s*w, + x + c*w + s*h, + y + c*h - s*w, + x - c*w - s*h, + y - c*h + s*w, + x - c*w + s*h, + y + c*h + s*w, + col, col, col, col); + nSpriteBufferIndex++; + if(nSpriteBufferIndex >= SPRITEBUFFERSIZE) + FlushSpriteBuffer(); +} diff --git a/src/renderer/Sprite.h b/src/renderer/Sprite.h new file mode 100644 index 00000000..fae6684e --- /dev/null +++ b/src/renderer/Sprite.h @@ -0,0 +1,31 @@ +#pragma once + +class CSprite +{ + static float m_f2DNearScreenZ; + static float m_f2DFarScreenZ; + static float m_fRecipNearClipPlane; + static int32 m_bFlushSpriteBufferSwitchZTest; +public: + static float GetNearScreenZ(void) { return m_f2DNearScreenZ; } + static float GetFarScreenZ(void) { return m_f2DFarScreenZ; } + + static float CalcHorizonCoors(void); + static bool CalcScreenCoors(const RwV3d &in, RwV3d *out, float *outw, float *outh, bool farclip); + static void InitSpriteBuffer(void); + static void InitSpriteBuffer2D(void); + static void FlushSpriteBuffer(void); + static void RenderOneXLUSprite(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, uint8 a); + static void RenderOneXLUSprite_Rotate_Aspect(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float roll, uint8 a); + static void RenderBufferedOneXLUSprite(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, uint8 a); + static void RenderBufferedOneXLUSprite_Rotate_Dimension(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float roll, uint8 a); + static void RenderBufferedOneXLUSprite_Rotate_Aspect(float x, float y, float z, float w, float h, uint8 r, uint8 g, uint8 b, int16 intens, float recipz, float roll, uint8 a); + // cx/y is the direction in which the colour changes + static void RenderBufferedOneXLUSprite_Rotate_2Colours(float x, float y, float z, float w, float h, uint8 r1, uint8 g1, uint8 b1, uint8 r2, uint8 g2, uint8 b2, float cx, float cy, float recipz, float rotation, uint8 a); + static void Set6Vertices2D(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); + static void Set6Vertices2D(RwIm2DVertex *verts, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, + const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); + static void RenderBufferedOneXLUSprite2D(float x, float y, float w, float h, const RwRGBA &colour, int16 intens, uint8 alpha); + static void RenderBufferedOneXLUSprite2D_Rotate_Dimension(float x, float y, float w, float h, const RwRGBA &colour, int16 intens, float rotation, uint8 alpha); + +}; diff --git a/src/renderer/Sprite2d.cpp b/src/renderer/Sprite2d.cpp new file mode 100644 index 00000000..92f326f8 --- /dev/null +++ b/src/renderer/Sprite2d.cpp @@ -0,0 +1,434 @@ +#include "common.h" + +#include "main.h" +#include "Draw.h" +#include "Camera.h" +#include "Sprite2d.h" +#include "Font.h" +#include "RenderBuffer.h" + +float CSprite2d::RecipNearClip; +float CSprite2d::NearScreenZ; +float CSprite2d::NearCamZ; +int CSprite2d::nextBufferVertex; +int CSprite2d::nextBufferIndex; +RwIm2DVertex CSprite2d::maVertices[8]; + +void +CSprite2d::SetRecipNearClip(void) +{ + // Used but empty in VC, instead they set in InitPerFrame. Isn't that great? +} + +void +CSprite2d::InitPerFrame(void) +{ + nextBufferVertex = 0; + nextBufferIndex = 0; + RecipNearClip = 1.0f / RwCameraGetNearClipPlane(Scene.camera); + NearScreenZ = RwIm2DGetNearScreenZ(); + // not original but you're supposed to set camera z too + // wrapping all this in FIX_BUGS is too ugly + NearCamZ = RwCameraGetNearClipPlane(Scene.camera); +} +void +CSprite2d::Delete(void) +{ + if(m_pTexture){ + RwTextureDestroy(m_pTexture); + m_pTexture = nil; + } +} + +void +CSprite2d::SetTexture(const char *name) +{ + Delete(); + if(name) + m_pTexture = RwTextureRead(name, nil); +} + +void +CSprite2d::SetTexture(const char *name, const char *mask) +{ + Delete(); + if(name) + m_pTexture = RwTextureRead(name, mask); +} + +void +CSprite2d::SetAddressing(RwTextureAddressMode addr) +{ + if(m_pTexture) + RwTextureSetAddressing(m_pTexture, addr); +} + +void +CSprite2d::SetRenderState(void) +{ + if(m_pTexture) + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(m_pTexture)); + else + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); +} + +void +CSprite2d::Draw(float x, float y, float w, float h, const CRGBA &col) +{ + SetVertices(CRect(x, y, x + w, y + h), col, col, col, col); + SetRenderState(); + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); +} + +void +CSprite2d::Draw(const CRect &rect, const CRGBA &col) +{ + SetVertices(rect, col, col, col, col); + SetRenderState(); + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); +} + +void +CSprite2d::Draw(const CRect &rect, const CRGBA &col, + float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2) +{ + SetVertices(rect, col, col, col, col, u0, v0, u1, v1, u3, v3, u2, v2); + SetRenderState(); + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); +} + +void +CSprite2d::Draw(const CRect &rect, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) +{ + SetVertices(rect, c0, c1, c2, c3); + SetRenderState(); + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); +} + +void +CSprite2d::Draw(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &col) +{ + SetVertices(x1, y1, x2, y2, x3, y3, x4, y4, col, col, col, col); + SetRenderState(); + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); +} + +// Arguments: +// 2---3 +// | | +// 0---1 +void +CSprite2d::SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) +{ + float offset = 1.0f/1024.0f; + + // This is what we draw: + // 0---1 + // | / | + // 3---2 + RwIm2DVertexSetScreenX(&maVertices[0], r.left); + RwIm2DVertexSetScreenY(&maVertices[0], r.top); + RwIm2DVertexSetScreenZ(&maVertices[0], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[0], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[0], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[0], c2.r, c2.g, c2.b, c2.a); + RwIm2DVertexSetU(&maVertices[0], 0.0f+offset, RecipNearClip); + RwIm2DVertexSetV(&maVertices[0], 0.0f+offset, RecipNearClip); + + RwIm2DVertexSetScreenX(&maVertices[1], r.right); + RwIm2DVertexSetScreenY(&maVertices[1], r.top); + RwIm2DVertexSetScreenZ(&maVertices[1], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[1], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[1], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[1], c3.r, c3.g, c3.b, c3.a); + RwIm2DVertexSetU(&maVertices[1], 1.0f+offset, RecipNearClip); + RwIm2DVertexSetV(&maVertices[1], 0.0f+offset, RecipNearClip); + + RwIm2DVertexSetScreenX(&maVertices[2], r.right); + RwIm2DVertexSetScreenY(&maVertices[2], r.bottom); + RwIm2DVertexSetScreenZ(&maVertices[2], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[2], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[2], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[2], c1.r, c1.g, c1.b, c1.a); + RwIm2DVertexSetU(&maVertices[2], 1.0f+offset, RecipNearClip); + RwIm2DVertexSetV(&maVertices[2], 1.0f+offset, RecipNearClip); + + RwIm2DVertexSetScreenX(&maVertices[3], r.left); + RwIm2DVertexSetScreenY(&maVertices[3], r.bottom); + RwIm2DVertexSetScreenZ(&maVertices[3], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[3], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[3], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[3], c0.r, c0.g, c0.b, c0.a); + RwIm2DVertexSetU(&maVertices[3], 0.0f+offset, RecipNearClip); + RwIm2DVertexSetV(&maVertices[3], 1.0f+offset, RecipNearClip); +} + +void +CSprite2d::SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3, + float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2) +{ + // This is what we draw: + // 0---1 + // | / | + // 3---2 + RwIm2DVertexSetScreenX(&maVertices[0], r.left); + RwIm2DVertexSetScreenY(&maVertices[0], r.top); + RwIm2DVertexSetScreenZ(&maVertices[0], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[0], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[0], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[0], c2.r, c2.g, c2.b, c2.a); + RwIm2DVertexSetU(&maVertices[0], u0, RecipNearClip); + RwIm2DVertexSetV(&maVertices[0], v0, RecipNearClip); + + RwIm2DVertexSetScreenX(&maVertices[1], r.right); + RwIm2DVertexSetScreenY(&maVertices[1], r.top); + RwIm2DVertexSetScreenZ(&maVertices[1], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[1], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[1], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[1], c3.r, c3.g, c3.b, c3.a); + RwIm2DVertexSetU(&maVertices[1], u1, RecipNearClip); + RwIm2DVertexSetV(&maVertices[1], v1, RecipNearClip); + + RwIm2DVertexSetScreenX(&maVertices[2], r.right); + RwIm2DVertexSetScreenY(&maVertices[2], r.bottom); + RwIm2DVertexSetScreenZ(&maVertices[2], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[2], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[2], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[2], c1.r, c1.g, c1.b, c1.a); + RwIm2DVertexSetU(&maVertices[2], u2, RecipNearClip); + RwIm2DVertexSetV(&maVertices[2], v2, RecipNearClip); + + RwIm2DVertexSetScreenX(&maVertices[3], r.left); + RwIm2DVertexSetScreenY(&maVertices[3], r.bottom); + RwIm2DVertexSetScreenZ(&maVertices[3], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[3], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[3], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[3], c0.r, c0.g, c0.b, c0.a); + RwIm2DVertexSetU(&maVertices[3], u3, RecipNearClip); + RwIm2DVertexSetV(&maVertices[3], v3, RecipNearClip); +} + +void +CSprite2d::SetVertices(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, + const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) +{ + RwIm2DVertexSetScreenX(&maVertices[0], x3); + RwIm2DVertexSetScreenY(&maVertices[0], y3); + RwIm2DVertexSetScreenZ(&maVertices[0], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[0], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[0], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[0], c2.r, c2.g, c2.b, c2.a); + RwIm2DVertexSetU(&maVertices[0], 0.0f, RecipNearClip); + RwIm2DVertexSetV(&maVertices[0], 0.0f, RecipNearClip); + + RwIm2DVertexSetScreenX(&maVertices[1], x4); + RwIm2DVertexSetScreenY(&maVertices[1], y4); + RwIm2DVertexSetScreenZ(&maVertices[1], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[1], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[1], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[1], c3.r, c3.g, c3.b, c3.a); + RwIm2DVertexSetU(&maVertices[1], 1.0f, RecipNearClip); + RwIm2DVertexSetV(&maVertices[1], 0.0f, RecipNearClip); + + RwIm2DVertexSetScreenX(&maVertices[2], x2); + RwIm2DVertexSetScreenY(&maVertices[2], y2); + RwIm2DVertexSetScreenZ(&maVertices[2], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[2], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[2], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[2], c1.r, c1.g, c1.b, c1.a); + RwIm2DVertexSetU(&maVertices[2], 1.0f, RecipNearClip); + RwIm2DVertexSetV(&maVertices[2], 1.0f, RecipNearClip); + + RwIm2DVertexSetScreenX(&maVertices[3], x1); + RwIm2DVertexSetScreenY(&maVertices[3], y1); + RwIm2DVertexSetScreenZ(&maVertices[3], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[3], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[3], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[3], c0.r, c0.g, c0.b, c0.a); + RwIm2DVertexSetU(&maVertices[3], 0.0f, RecipNearClip); + RwIm2DVertexSetV(&maVertices[3], 1.0f, RecipNearClip); +} + +void +CSprite2d::SetVertices(int n, float *positions, float *uvs, const CRGBA &col) +{ + int i; + + for(i = 0; i < n; i++){ + RwIm2DVertexSetScreenX(&maVertices[i], positions[i*2 + 0]); + RwIm2DVertexSetScreenY(&maVertices[i], positions[i*2 + 1]); + RwIm2DVertexSetScreenZ(&maVertices[i], NearScreenZ + 0.0001f); + RwIm2DVertexSetCameraZ(&maVertices[i], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[i], RecipNearClip); + RwIm2DVertexSetIntRGBA(&maVertices[i], col.r, col.g, col.b, col.a); + RwIm2DVertexSetU(&maVertices[i], uvs[i*2 + 0], RecipNearClip); + RwIm2DVertexSetV(&maVertices[i], uvs[i*2 + 1], RecipNearClip); + } +} + +void +CSprite2d::SetMaskVertices(int n, float *positions) +{ + int i; + + for(i = 0; i < n; i++){ + RwIm2DVertexSetScreenX(&maVertices[i], positions[i*2 + 0]); + RwIm2DVertexSetScreenY(&maVertices[i], positions[i*2 + 1]); + RwIm2DVertexSetScreenZ(&maVertices[i], NearScreenZ); + RwIm2DVertexSetCameraZ(&maVertices[i], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&maVertices[i], RecipNearClip); +#if !defined(GTA_PS2_STUFF) && defined(RWLIBS) + RwIm2DVertexSetIntRGBA(&maVertices[i], 0, 0, 0, 0); +#else + RwIm2DVertexSetIntRGBA(&maVertices[i], 255, 255, 255, 255); +#endif + } +} + +void +CSprite2d::SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3, + float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2) +{ + RwIm2DVertexSetScreenX(&verts[0], r.left); + RwIm2DVertexSetScreenY(&verts[0], r.top); + RwIm2DVertexSetScreenZ(&verts[0], NearScreenZ); + RwIm2DVertexSetCameraZ(&verts[0], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&verts[0], RecipNearClip); + RwIm2DVertexSetIntRGBA(&verts[0], c2.r, c2.g, c2.b, c2.a); + RwIm2DVertexSetU(&verts[0], u0, RecipNearClip); + RwIm2DVertexSetV(&verts[0], v0, RecipNearClip); + + RwIm2DVertexSetScreenX(&verts[1], r.right); + RwIm2DVertexSetScreenY(&verts[1], r.top); + RwIm2DVertexSetScreenZ(&verts[1], NearScreenZ); + RwIm2DVertexSetCameraZ(&verts[1], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&verts[1], RecipNearClip); + RwIm2DVertexSetIntRGBA(&verts[1], c3.r, c3.g, c3.b, c3.a); + RwIm2DVertexSetU(&verts[1], u1, RecipNearClip); + RwIm2DVertexSetV(&verts[1], v1, RecipNearClip); + + RwIm2DVertexSetScreenX(&verts[2], r.right); + RwIm2DVertexSetScreenY(&verts[2], r.bottom); + RwIm2DVertexSetScreenZ(&verts[2], NearScreenZ); + RwIm2DVertexSetCameraZ(&verts[2], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&verts[2], RecipNearClip); + RwIm2DVertexSetIntRGBA(&verts[2], c1.r, c1.g, c1.b, c1.a); + RwIm2DVertexSetU(&verts[2], u2, RecipNearClip); + RwIm2DVertexSetV(&verts[2], v2, RecipNearClip); + + RwIm2DVertexSetScreenX(&verts[3], r.left); + RwIm2DVertexSetScreenY(&verts[3], r.bottom); + RwIm2DVertexSetScreenZ(&verts[3], NearScreenZ); + RwIm2DVertexSetCameraZ(&verts[3], NearCamZ); + RwIm2DVertexSetRecipCameraZ(&verts[3], RecipNearClip); + RwIm2DVertexSetIntRGBA(&verts[3], c0.r, c0.g, c0.b, c0.a); + RwIm2DVertexSetU(&verts[3], u3, RecipNearClip); + RwIm2DVertexSetV(&verts[3], v3, RecipNearClip); +} + +void +CSprite2d::DrawRect(const CRect &r, const CRGBA &col) +{ + SetVertices(r, col, col, col, col); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEFLAT); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)(col.a != 255)); + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, maVertices, 4); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD); +} + +void +CSprite2d::DrawRect(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) +{ + SetVertices(r, c0, c1, c2, c3); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, maVertices, 4); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); +} + +void +CSprite2d::DrawRectXLU(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) +{ + SetVertices(r, c0, c1, c2, c3); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); +} + +void +CSprite2d::DrawAnyRect(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, + const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3) +{ + SetVertices(x1, y1, x2, y2, x3, y3, x4, y4, c0, c1, c2, c3); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); + RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)(c0.alpha != 255 || c1.alpha != 255 || c2.alpha != 255 || c3.alpha != 255)); + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD); +} + +void CSprite2d::Draw2DPolygon(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &color) +{ + SetVertices(x1, y1, x2, y2, x3, y3, x4, y4, color, color, color, color); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, 0); + RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEFLAT); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)(color.a != 255)); + RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESHADEMODE, (void*)rwSHADEMODEGOURAUD); +} + +void +CSprite2d::AddToBuffer(const CRect &r, const CRGBA &c, float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2) +{ + SetVertices(&TempVertexBuffer.im2d[nextBufferVertex], r, c, c, c, c, u0, v0, u1, v1, u3, v3, u2, v2); + RwImVertexIndex *pIndexList = &TempBufferRenderIndexList[nextBufferIndex]; + pIndexList[0] = nextBufferVertex; + pIndexList[1] = nextBufferVertex + 1; + pIndexList[2] = nextBufferVertex + 2; + pIndexList[3] = nextBufferVertex + 3; + pIndexList[4] = nextBufferVertex; + pIndexList[5] = nextBufferVertex + 2; + nextBufferIndex += 6; + nextBufferVertex += 4; + if (IsVertexBufferFull()) + RenderVertexBuffer(); +} + +bool +CSprite2d::IsVertexBufferFull() +{ + return (nextBufferVertex > TEMPBUFFERVERTSIZE-128-4 || nextBufferIndex > ARRAY_SIZE(TempBufferRenderIndexList)-6); +} + +void +CSprite2d::RenderVertexBuffer() +{ + if (nextBufferVertex > 0) { + RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERLINEAR); + RwIm2DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempVertexBuffer.im2d, nextBufferVertex, TempBufferRenderIndexList, nextBufferIndex); + nextBufferVertex = 0; + nextBufferIndex = 0; + } +} \ No newline at end of file diff --git a/src/renderer/Sprite2d.h b/src/renderer/Sprite2d.h new file mode 100644 index 00000000..5abd8d71 --- /dev/null +++ b/src/renderer/Sprite2d.h @@ -0,0 +1,54 @@ +#pragma once + +class CSprite2d +{ + static float RecipNearClip; + static float NearScreenZ; + static float NearCamZ; // not original + static int nextBufferVertex; + static int nextBufferIndex; + static RwIm2DVertex maVertices[8]; +public: + RwTexture *m_pTexture; + + static void SetRecipNearClip(void); + static void InitPerFrame(void); + + CSprite2d(void) : m_pTexture(nil) {}; + ~CSprite2d(void) { Delete(); }; + void Delete(void); + void SetRenderState(void); + void SetTexture(const char *name); + void SetTexture(const char *name, const char *mask); + void SetAddressing(RwTextureAddressMode addr); + void Draw(float x, float y, float w, float h, const CRGBA &col); + void Draw(const CRect &rect, const CRGBA &col); + void Draw(const CRect &rect, const CRGBA &col, + float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2); + void Draw(const CRect &rect, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); + void Draw(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &col); + + static void SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); + static void SetVertices(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3, + float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2); + static void SetVertices(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, + const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); + static void SetVertices(int n, float *positions, float *uvs, const CRGBA &col); + static void SetMaskVertices(int n, float *positions); + static void SetVertices(RwIm2DVertex *verts, const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3, + float u0, float v0, float u1, float v1, float u3, float v3, float u2, float v2); + + static void DrawRect(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); + static void DrawRect(const CRect &r, const CRGBA &col); + static void DrawRectXLU(const CRect &r, const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); + static void DrawAnyRect(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, + const CRGBA &c0, const CRGBA &c1, const CRGBA &c2, const CRGBA &c3); + + static void Draw2DPolygon(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &color); + + static RwIm2DVertex* GetVertices() { return maVertices; }; + + static bool IsVertexBufferFull(); + static void AddToBuffer(const CRect &a1, const CRGBA &a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10); + static void RenderVertexBuffer(); +}; diff --git a/src/renderer/TexList.cpp b/src/renderer/TexList.cpp new file mode 100644 index 00000000..1689837f --- /dev/null +++ b/src/renderer/TexList.cpp @@ -0,0 +1,41 @@ +#include "common.h" +#include "TexList.h" +#include "rtbmp.h" +#include "FileMgr.h" + +bool CTexList::ms_nTexUsed[MAX_TEXUSED]; + +void +CTexList::Initialise() +{} + +void +CTexList::Shutdown() +{} + +RwTexture * +CTexList::SetTexture(int32 slot, char *name) +{ + return nil; +} + +int32 +CTexList::GetFirstFreeTexture() +{ + for (int32 i = 0; i < MAX_TEXUSED; i++) + if (!ms_nTexUsed[i]) + return i; + return -1; +} + +RwTexture * +CTexList::LoadFileNameTexture(char *name) +{ + return SetTexture(GetFirstFreeTexture(), name); +} + +void +CTexList::LoadGlobalTextureList() +{ + CFileMgr::SetDir("TEXTURES"); +} \ No newline at end of file diff --git a/src/renderer/TexList.h b/src/renderer/TexList.h new file mode 100644 index 00000000..7e042211 --- /dev/null +++ b/src/renderer/TexList.h @@ -0,0 +1,14 @@ +#pragma once + +class CTexList +{ + enum { MAX_TEXUSED = 400, }; + static bool ms_nTexUsed[MAX_TEXUSED]; +public: + static void Initialise(); + static void Shutdown(); + static RwTexture *SetTexture(int32 slot, char *name); + static int32 GetFirstFreeTexture(); + static RwTexture *LoadFileNameTexture(char *name); + static void LoadGlobalTextureList(); +}; \ No newline at end of file diff --git a/src/renderer/Timecycle.cpp b/src/renderer/Timecycle.cpp new file mode 100644 index 00000000..95d9fe3c --- /dev/null +++ b/src/renderer/Timecycle.cpp @@ -0,0 +1,526 @@ +#include "common.h" + +#include "main.h" +#include "Clock.h" +#include "Weather.h" +#include "Camera.h" +#include "Shadows.h" +#include "ZoneCull.h" +#include "CutsceneMgr.h" +#include "FileMgr.h" +#include "Timecycle.h" + +uint8 CTimeCycle::m_nAmbientRed[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nAmbientGreen[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nAmbientBlue[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nAmbientRed_Obj[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nAmbientGreen_Obj[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nAmbientBlue_Obj[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nAmbientRed_Bl[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nAmbientGreen_Bl[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nAmbientBlue_Bl[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nAmbientRed_Obj_Bl[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nAmbientGreen_Obj_Bl[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nAmbientBlue_Obj_Bl[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nDirectionalRed[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nDirectionalGreen[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nDirectionalBlue[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSkyTopRed[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSkyTopGreen[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSkyTopBlue[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSkyBottomRed[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSkyBottomGreen[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSkyBottomBlue[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSunCoreRed[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSunCoreGreen[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSunCoreBlue[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSunCoronaRed[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSunCoronaGreen[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nSunCoronaBlue[NUMHOURS][NUMWEATHERS]; +int8 CTimeCycle::m_fSunSize[NUMHOURS][NUMWEATHERS]; +int8 CTimeCycle::m_fSpriteSize[NUMHOURS][NUMWEATHERS]; +int8 CTimeCycle::m_fSpriteBrightness[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nShadowStrength[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nLightShadowStrength[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nPoleShadowStrength[NUMHOURS][NUMWEATHERS]; +int16 CTimeCycle::m_fFogStart[NUMHOURS][NUMWEATHERS]; +int16 CTimeCycle::m_fFarClip[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_fLightsOnGroundBrightness[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nLowCloudsRed[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nLowCloudsGreen[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nLowCloudsBlue[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nFluffyCloudsTopRed[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nFluffyCloudsTopGreen[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nFluffyCloudsTopBlue[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nFluffyCloudsBottomRed[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nFluffyCloudsBottomGreen[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_nFluffyCloudsBottomBlue[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_fBlurRed[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_fBlurGreen[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_fBlurBlue[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_fWaterRed[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_fWaterGreen[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_fWaterBlue[NUMHOURS][NUMWEATHERS]; +uint8 CTimeCycle::m_fWaterAlpha[NUMHOURS][NUMWEATHERS]; + + +float CTimeCycle::m_fCurrentAmbientRed; +float CTimeCycle::m_fCurrentAmbientGreen; +float CTimeCycle::m_fCurrentAmbientBlue; +float CTimeCycle::m_fCurrentAmbientRed_Obj; +float CTimeCycle::m_fCurrentAmbientGreen_Obj; +float CTimeCycle::m_fCurrentAmbientBlue_Obj; +float CTimeCycle::m_fCurrentAmbientRed_Bl; +float CTimeCycle::m_fCurrentAmbientGreen_Bl; +float CTimeCycle::m_fCurrentAmbientBlue_Bl; +float CTimeCycle::m_fCurrentAmbientRed_Obj_Bl; +float CTimeCycle::m_fCurrentAmbientGreen_Obj_Bl; +float CTimeCycle::m_fCurrentAmbientBlue_Obj_Bl; +float CTimeCycle::m_fCurrentDirectionalRed; +float CTimeCycle::m_fCurrentDirectionalGreen; +float CTimeCycle::m_fCurrentDirectionalBlue; +int32 CTimeCycle::m_nCurrentSkyTopRed; +int32 CTimeCycle::m_nCurrentSkyTopGreen; +int32 CTimeCycle::m_nCurrentSkyTopBlue; +int32 CTimeCycle::m_nCurrentSkyBottomRed; +int32 CTimeCycle::m_nCurrentSkyBottomGreen; +int32 CTimeCycle::m_nCurrentSkyBottomBlue; +int32 CTimeCycle::m_nCurrentSunCoreRed; +int32 CTimeCycle::m_nCurrentSunCoreGreen; +int32 CTimeCycle::m_nCurrentSunCoreBlue; +int32 CTimeCycle::m_nCurrentSunCoronaRed; +int32 CTimeCycle::m_nCurrentSunCoronaGreen; +int32 CTimeCycle::m_nCurrentSunCoronaBlue; +float CTimeCycle::m_fCurrentSunSize; +float CTimeCycle::m_fCurrentSpriteSize; +float CTimeCycle::m_fCurrentSpriteBrightness; +int32 CTimeCycle::m_nCurrentShadowStrength; +int32 CTimeCycle::m_nCurrentLightShadowStrength; +int32 CTimeCycle::m_nCurrentPoleShadowStrength; +float CTimeCycle::m_fCurrentFogStart; +float CTimeCycle::m_fCurrentFarClip; +float CTimeCycle::m_fCurrentLightsOnGroundBrightness; +int32 CTimeCycle::m_nCurrentLowCloudsRed; +int32 CTimeCycle::m_nCurrentLowCloudsGreen; +int32 CTimeCycle::m_nCurrentLowCloudsBlue; +int32 CTimeCycle::m_nCurrentFluffyCloudsTopRed; +int32 CTimeCycle::m_nCurrentFluffyCloudsTopGreen; +int32 CTimeCycle::m_nCurrentFluffyCloudsTopBlue; +int32 CTimeCycle::m_nCurrentFluffyCloudsBottomRed; +int32 CTimeCycle::m_nCurrentFluffyCloudsBottomGreen; +int32 CTimeCycle::m_nCurrentFluffyCloudsBottomBlue; +float CTimeCycle::m_fCurrentBlurRed; +float CTimeCycle::m_fCurrentBlurGreen; +float CTimeCycle::m_fCurrentBlurBlue; +float CTimeCycle::m_fCurrentWaterRed; +float CTimeCycle::m_fCurrentWaterGreen; +float CTimeCycle::m_fCurrentWaterBlue; +float CTimeCycle::m_fCurrentWaterAlpha; +int32 CTimeCycle::m_nCurrentFogColourRed; +int32 CTimeCycle::m_nCurrentFogColourGreen; +int32 CTimeCycle::m_nCurrentFogColourBlue; + +int32 CTimeCycle::m_FogReduction; +int32 CTimeCycle::m_bExtraColourOn; +int32 CTimeCycle::m_ExtraColour; +float CTimeCycle::m_ExtraColourInter; + +int32 CTimeCycle::m_CurrentStoredValue; +CVector CTimeCycle::m_VectorToSun[16]; +float CTimeCycle::m_fShadowFrontX[16]; +float CTimeCycle::m_fShadowFrontY[16]; +float CTimeCycle::m_fShadowSideX[16]; +float CTimeCycle::m_fShadowSideY[16]; +float CTimeCycle::m_fShadowDisplacementX[16]; +float CTimeCycle::m_fShadowDisplacementY[16]; + +void +CTimeCycle::Initialise(void) +{ + int w, h; + int li, bi; + char line[1040]; + + int ambR, ambG, ambB; + int ambobjR, ambobjG, ambobjB; + int ambblR, ambblG, ambblB; + int ambobjblR, ambobjblG, ambobjblB; + int dirR, dirG, dirB; + int skyTopR, skyTopG, skyTopB; + int skyBotR, skyBotG, skyBotB; + int sunCoreR, sunCoreG, sunCoreB; + int sunCoronaR, sunCoronaG, sunCoronaB; + float sunSz, sprSz, sprBght; + int shad, lightShad, poleShad; + float farClp, fogSt, lightGnd; + int cloudR, cloudG, cloudB; + int fluffyTopR, fluffyTopG, fluffyTopB; + int fluffyBotR, fluffyBotG, fluffyBotB; + float blurR, blurG, blurB; + float waterR, waterG, waterB, waterA; + + debug("Intialising CTimeCycle...\n"); + + CFileMgr::SetDir("DATA"); + CFileMgr::LoadFile("TIMECYC.DAT", work_buff, sizeof(work_buff), "rb"); + CFileMgr::SetDir(""); + + line[0] = '\0'; + bi = 0; + for(w = 0; w < NUMWEATHERS; w++) + for(h = 0; h < NUMHOURS; h++){ + li = 0; + while(work_buff[bi] == '/' || work_buff[bi] == '\n' || + work_buff[bi] == '\0' || work_buff[bi] == ' ' || work_buff[bi] == '\r'){ + while(work_buff[bi] != '\n' && work_buff[bi] != '\0' && work_buff[bi] != '\r') + bi++; + bi++; + } + while(work_buff[bi] != '\n' +#ifdef FIX_BUGS + && work_buff[bi] != '\0' +#endif + ) + line[li++] = work_buff[bi++]; + line[li] = '\0'; + bi++; + + sscanf(line, "%d %d %d %d %d %d %d %d %d %d %d %d " + "%d %d %d %d %d %d %d %d %d " + "%d %d %d %d %d %d %f %f %f %d %d %d %f %f %f " + "%d %d %d %d %d %d %d %d %d %f %f %f %f %f %f %f", + &ambR, &ambG, &ambB, + &ambobjR, &ambobjG, &ambobjB, + &ambblR, &ambblG, &ambblB, + &ambobjblR, &ambobjblG, &ambobjblB, + &dirR, &dirG, &dirB, + &skyTopR, &skyTopG, &skyTopB, + &skyBotR, &skyBotG, &skyBotB, + &sunCoreR, &sunCoreG, &sunCoreB, + &sunCoronaR, &sunCoronaG, &sunCoronaB, + &sunSz, &sprSz, &sprBght, + &shad, &lightShad, &poleShad, + &farClp, &fogSt, &lightGnd, + &cloudR, &cloudG, &cloudB, + &fluffyTopR, &fluffyTopG, &fluffyTopB, + &fluffyBotR, &fluffyBotG, &fluffyBotB, + &blurR, &blurG, &blurB, + &waterR, &waterG, &waterB, &waterA); + + m_nAmbientRed[h][w] = ambR; + m_nAmbientGreen[h][w] = ambG; + m_nAmbientBlue[h][w] = ambB; + m_nAmbientRed_Obj[h][w] = ambobjR; + m_nAmbientGreen_Obj[h][w] = ambobjG; + m_nAmbientBlue_Obj[h][w] = ambobjB; + m_nAmbientRed_Bl[h][w] = ambblR; + m_nAmbientGreen_Bl[h][w] = ambblG; + m_nAmbientBlue_Bl[h][w] = ambblB; + m_nAmbientRed_Obj_Bl[h][w] = ambobjblR; + m_nAmbientGreen_Obj_Bl[h][w] = ambobjblG; + m_nAmbientBlue_Obj_Bl[h][w] = ambobjblB; + m_nDirectionalRed[h][w] = dirR; + m_nDirectionalGreen[h][w] = dirG; + m_nDirectionalBlue[h][w] = dirB; + m_nSkyTopRed[h][w] = skyTopR; + m_nSkyTopGreen[h][w] = skyTopG; + m_nSkyTopBlue[h][w] = skyTopB; + m_nSkyBottomRed[h][w] = skyBotR; + m_nSkyBottomGreen[h][w] = skyBotG; + m_nSkyBottomBlue[h][w] = skyBotB; + m_nSunCoreRed[h][w] = sunCoreR; + m_nSunCoreGreen[h][w] = sunCoreG; + m_nSunCoreBlue[h][w] = sunCoreB; + m_nSunCoronaRed[h][w] = sunCoronaR; + m_nSunCoronaGreen[h][w] = sunCoronaG; + m_nSunCoronaBlue[h][w] = sunCoronaB; + m_fSunSize[h][w] = sunSz * 10.0f; + m_fSpriteSize[h][w] = sprSz * 10.0f; + m_fSpriteBrightness[h][w] = sprBght * 10.0f; + m_nShadowStrength[h][w] = shad; + m_nLightShadowStrength[h][w] = lightShad; + m_nPoleShadowStrength[h][w] = poleShad; + m_fFarClip[h][w] = farClp; + m_fFogStart[h][w] = fogSt; + m_fLightsOnGroundBrightness[h][w] = lightGnd * 10.0f; + m_nLowCloudsRed[h][w] = cloudR; + m_nLowCloudsGreen[h][w] = cloudG; + m_nLowCloudsBlue[h][w] = cloudB; + m_nFluffyCloudsTopRed[h][w] = fluffyTopR; + m_nFluffyCloudsTopGreen[h][w] = fluffyTopG; + m_nFluffyCloudsTopBlue[h][w] = fluffyTopB; + m_nFluffyCloudsBottomRed[h][w] = fluffyBotR; + m_nFluffyCloudsBottomGreen[h][w] = fluffyBotG; + m_nFluffyCloudsBottomBlue[h][w] = fluffyBotB; + m_fBlurRed[h][w] = blurR; + m_fBlurGreen[h][w] = blurG; + m_fBlurBlue[h][w] = blurB; + m_fWaterRed[h][w] = waterR; + m_fWaterGreen[h][w] = waterG; + m_fWaterBlue[h][w] = waterB; + m_fWaterAlpha[h][w] = waterA; + } + + m_FogReduction = 0; + + debug("CTimeCycle ready\n"); +} + +static float interp_c0, interp_c1, interp_c2, interp_c3; + +float CTimeCycle::Interpolate(int8 *a, int8 *b) +{ + return a[CWeather::OldWeatherType] * interp_c0 + + b[CWeather::OldWeatherType] * interp_c1 + + a[CWeather::NewWeatherType] * interp_c2 + + b[CWeather::NewWeatherType] * interp_c3; +} + +float CTimeCycle::Interpolate(uint8 *a, uint8 *b) +{ + return a[CWeather::OldWeatherType] * interp_c0 + + b[CWeather::OldWeatherType] * interp_c1 + + a[CWeather::NewWeatherType] * interp_c2 + + b[CWeather::NewWeatherType] * interp_c3; +} + +float CTimeCycle::Interpolate(int16 *a, int16 *b) +{ + return a[CWeather::OldWeatherType] * interp_c0 + + b[CWeather::OldWeatherType] * interp_c1 + + a[CWeather::NewWeatherType] * interp_c2 + + b[CWeather::NewWeatherType] * interp_c3; +} + +void +CTimeCycle::StartExtraColour(int32 c, bool fade) +{ + m_bExtraColourOn = true; + m_ExtraColour = c; + if(fade) + m_ExtraColourInter = 0.0f; + else + m_ExtraColourInter = 1.0f; +} + +void +CTimeCycle::StopExtraColour(bool fade) +{ + m_bExtraColourOn = false; + if(!fade) + m_ExtraColourInter = 0.0f; +} + +void +CTimeCycle::Update(void) +{ + int h1 = CClock::GetHours(); + int h2 = (h1+1)%24; + int w1 = CWeather::OldWeatherType; + int w2 = CWeather::NewWeatherType; + float timeInterp = (CClock::GetMinutes() + CClock::GetSeconds()/60.0f)/60.0f; + // coefficients for a bilinear interpolation + interp_c0 = (1.0f-timeInterp) * (1.0f-CWeather::InterpolationValue); + interp_c1 = timeInterp * (1.0f-CWeather::InterpolationValue); + interp_c2 = (1.0f-timeInterp) * CWeather::InterpolationValue; + interp_c3 = timeInterp * CWeather::InterpolationValue; + +#define INTERP(v) Interpolate(v[h1], v[h2]) + + m_nCurrentSkyTopRed = INTERP(m_nSkyTopRed); + m_nCurrentSkyTopGreen = INTERP(m_nSkyTopGreen); + m_nCurrentSkyTopBlue = INTERP(m_nSkyTopBlue); + + m_nCurrentSkyBottomRed = INTERP(m_nSkyBottomRed); + m_nCurrentSkyBottomGreen = INTERP(m_nSkyBottomGreen); + m_nCurrentSkyBottomBlue = INTERP(m_nSkyBottomBlue); + + m_fCurrentAmbientRed = INTERP(m_nAmbientRed); + m_fCurrentAmbientGreen = INTERP(m_nAmbientGreen); + m_fCurrentAmbientBlue = INTERP(m_nAmbientBlue); + + m_fCurrentAmbientRed_Obj = INTERP(m_nAmbientRed_Obj); + m_fCurrentAmbientGreen_Obj = INTERP(m_nAmbientGreen_Obj); + m_fCurrentAmbientBlue_Obj = INTERP(m_nAmbientBlue_Obj); + + m_fCurrentAmbientRed_Bl = INTERP(m_nAmbientRed_Bl); + m_fCurrentAmbientGreen_Bl = INTERP(m_nAmbientGreen_Bl); + m_fCurrentAmbientBlue_Bl = INTERP(m_nAmbientBlue_Bl); + + m_fCurrentAmbientRed_Obj_Bl = INTERP(m_nAmbientRed_Obj_Bl); + m_fCurrentAmbientGreen_Obj_Bl = INTERP(m_nAmbientGreen_Obj_Bl); + m_fCurrentAmbientBlue_Obj_Bl = INTERP(m_nAmbientBlue_Obj_Bl); + + m_fCurrentDirectionalRed = INTERP(m_nDirectionalRed); + m_fCurrentDirectionalGreen = INTERP(m_nDirectionalGreen); + m_fCurrentDirectionalBlue = INTERP(m_nDirectionalBlue); + + m_nCurrentSunCoreRed = INTERP(m_nSunCoreRed); + m_nCurrentSunCoreGreen = INTERP(m_nSunCoreGreen); + m_nCurrentSunCoreBlue = INTERP(m_nSunCoreBlue); + + m_nCurrentSunCoronaRed = INTERP(m_nSunCoronaRed); + m_nCurrentSunCoronaGreen = INTERP(m_nSunCoronaGreen); + m_nCurrentSunCoronaBlue = INTERP(m_nSunCoronaBlue); + + m_fCurrentSunSize = INTERP(m_fSunSize)/10.0f; + m_fCurrentSpriteSize = INTERP(m_fSpriteSize)/10.0f; + m_fCurrentSpriteBrightness = INTERP(m_fSpriteBrightness)/10.0f; + m_nCurrentShadowStrength = INTERP(m_nShadowStrength); + m_nCurrentLightShadowStrength = INTERP(m_nLightShadowStrength); + m_nCurrentPoleShadowStrength = INTERP(m_nPoleShadowStrength); + m_fCurrentFarClip = INTERP(m_fFarClip); + m_fCurrentFogStart = INTERP(m_fFogStart); + m_fCurrentLightsOnGroundBrightness = INTERP(m_fLightsOnGroundBrightness)/10.0f; + + m_nCurrentLowCloudsRed = INTERP(m_nLowCloudsRed); + m_nCurrentLowCloudsGreen = INTERP(m_nLowCloudsGreen); + m_nCurrentLowCloudsBlue = INTERP(m_nLowCloudsBlue); + + m_nCurrentFluffyCloudsTopRed = INTERP(m_nFluffyCloudsTopRed); + m_nCurrentFluffyCloudsTopGreen = INTERP(m_nFluffyCloudsTopGreen); + m_nCurrentFluffyCloudsTopBlue = INTERP(m_nFluffyCloudsTopBlue); + + m_nCurrentFluffyCloudsBottomRed = INTERP(m_nFluffyCloudsBottomRed); + m_nCurrentFluffyCloudsBottomGreen = INTERP(m_nFluffyCloudsBottomGreen); + m_nCurrentFluffyCloudsBottomBlue = INTERP(m_nFluffyCloudsBottomBlue); + + m_fCurrentBlurRed = INTERP(m_fBlurRed); + m_fCurrentBlurGreen = INTERP(m_fBlurGreen); + m_fCurrentBlurBlue = INTERP(m_fBlurBlue); + + m_fCurrentWaterRed = INTERP(m_fWaterRed); + m_fCurrentWaterGreen = INTERP(m_fWaterGreen); + m_fCurrentWaterBlue = INTERP(m_fWaterBlue); + m_fCurrentWaterAlpha = INTERP(m_fWaterAlpha); +#undef INTERP + + if(m_FogReduction != 0) + m_fCurrentFarClip = Max(m_fCurrentFarClip, m_FogReduction/64.0f * 650.0f); + + m_CurrentStoredValue = (m_CurrentStoredValue+1)&0xF; + + float sunAngle = 2*PI*(CClock::GetSeconds()/60.0f + CClock::GetMinutes() + CClock::GetHours()*60)/(24*60); + CVector &sunPos = GetSunDirection(); + sunPos.x = Sin(sunAngle); + sunPos.y = 1.0f; + sunPos.z = 0.2f - Cos(sunAngle); + sunPos.Normalise(); + + if(m_bExtraColourOn) + m_ExtraColourInter = Min(1.0f, m_ExtraColourInter + CTimer::GetTimeStep()/120.0f); + else + m_ExtraColourInter = Max(-.0f, m_ExtraColourInter - CTimer::GetTimeStep()/120.0f); + if(m_ExtraColourInter > 0.0f){ +#define INTERP(extra,cur) (m_ExtraColourInter*extra[m_ExtraColour][WEATHER_EXTRACOLOURS] + (1.0f-m_ExtraColourInter)*cur) +#define INTERPscl(extra,scl,cur) (m_ExtraColourInter*extra[m_ExtraColour][WEATHER_EXTRACOLOURS]/scl + (1.0f-m_ExtraColourInter)*cur) + if(m_nSkyTopRed[m_ExtraColour][WEATHER_EXTRACOLOURS] != 0 || + m_nSkyTopGreen[m_ExtraColour][WEATHER_EXTRACOLOURS] != 0 || + m_nSkyTopBlue[m_ExtraColour][WEATHER_EXTRACOLOURS] != 0){ + m_nCurrentSkyTopRed = INTERP(m_nSkyTopRed,m_nCurrentSkyTopRed); + m_nCurrentSkyTopGreen = INTERP(m_nSkyTopGreen,m_nCurrentSkyTopGreen); + m_nCurrentSkyTopBlue = INTERP(m_nSkyTopBlue,m_nCurrentSkyTopBlue); + + m_nCurrentSkyBottomRed = INTERP(m_nSkyBottomRed,m_nCurrentSkyBottomRed); + m_nCurrentSkyBottomGreen = INTERP(m_nSkyBottomGreen,m_nCurrentSkyBottomGreen); + m_nCurrentSkyBottomBlue = INTERP(m_nSkyBottomBlue,m_nCurrentSkyBottomBlue); + + m_nCurrentSunCoreRed = INTERP(m_nSunCoreRed,m_nCurrentSunCoreRed); + m_nCurrentSunCoreGreen = INTERP(m_nSunCoreGreen,m_nCurrentSunCoreGreen); + m_nCurrentSunCoreBlue = INTERP(m_nSunCoreBlue,m_nCurrentSunCoreBlue); + + m_nCurrentSunCoronaRed = INTERP(m_nSunCoronaRed,m_nCurrentSunCoronaRed); + m_nCurrentSunCoronaGreen = INTERP(m_nSunCoronaGreen,m_nCurrentSunCoronaGreen); + m_nCurrentSunCoronaBlue = INTERP(m_nSunCoronaBlue,m_nCurrentSunCoronaBlue); + + m_fCurrentSunSize = INTERPscl(m_fSunSize,10.0f,m_fCurrentSunSize); + + m_nCurrentLowCloudsRed = INTERP(m_nLowCloudsRed,m_nCurrentLowCloudsRed); + m_nCurrentLowCloudsGreen = INTERP(m_nLowCloudsGreen,m_nCurrentLowCloudsGreen); + m_nCurrentLowCloudsBlue = INTERP(m_nLowCloudsBlue,m_nCurrentLowCloudsBlue); + + m_nCurrentFluffyCloudsTopRed = INTERP(m_nFluffyCloudsTopRed,m_nCurrentFluffyCloudsTopRed); + m_nCurrentFluffyCloudsTopGreen = INTERP(m_nFluffyCloudsTopGreen,m_nCurrentFluffyCloudsTopGreen); + m_nCurrentFluffyCloudsTopBlue = INTERP(m_nFluffyCloudsTopBlue,m_nCurrentFluffyCloudsTopBlue); + + m_nCurrentFluffyCloudsBottomRed = INTERP(m_nFluffyCloudsBottomRed,m_nCurrentFluffyCloudsBottomRed); + m_nCurrentFluffyCloudsBottomGreen = INTERP(m_nFluffyCloudsBottomGreen,m_nCurrentFluffyCloudsBottomGreen); + m_nCurrentFluffyCloudsBottomBlue = INTERP(m_nFluffyCloudsBottomBlue,m_nCurrentFluffyCloudsBottomBlue); + + m_fCurrentWaterRed = INTERP(m_fWaterRed,m_fCurrentWaterRed); + m_fCurrentWaterGreen = INTERP(m_fWaterGreen,m_fCurrentWaterGreen); + m_fCurrentWaterBlue = INTERP(m_fWaterBlue,m_fCurrentWaterBlue); + m_fCurrentWaterAlpha = INTERP(m_fWaterAlpha,m_fCurrentWaterAlpha); + } + + m_fCurrentAmbientRed = INTERP(m_nAmbientRed,m_fCurrentAmbientRed); + m_fCurrentAmbientGreen = INTERP(m_nAmbientGreen,m_fCurrentAmbientGreen); + m_fCurrentAmbientBlue = INTERP(m_nAmbientBlue,m_fCurrentAmbientBlue); + + m_fCurrentAmbientRed_Obj = INTERP(m_nAmbientRed_Obj,m_fCurrentAmbientRed_Obj); + m_fCurrentAmbientGreen_Obj = INTERP(m_nAmbientGreen_Obj,m_fCurrentAmbientGreen_Obj); + m_fCurrentAmbientBlue_Obj = INTERP(m_nAmbientBlue_Obj,m_fCurrentAmbientBlue_Obj); + + m_fCurrentAmbientRed_Bl = INTERP(m_nAmbientRed_Bl,m_fCurrentAmbientRed_Bl); + m_fCurrentAmbientGreen_Bl = INTERP(m_nAmbientGreen_Bl,m_fCurrentAmbientGreen_Bl); + m_fCurrentAmbientBlue_Bl = INTERP(m_nAmbientBlue_Bl,m_fCurrentAmbientBlue_Bl); + + m_fCurrentAmbientRed_Obj_Bl = INTERP(m_nAmbientRed_Obj_Bl,m_fCurrentAmbientRed_Obj_Bl); + m_fCurrentAmbientGreen_Obj_Bl = INTERP(m_nAmbientGreen_Obj_Bl,m_fCurrentAmbientGreen_Obj_Bl); + m_fCurrentAmbientBlue_Obj_Bl = INTERP(m_nAmbientBlue_Obj_Bl,m_fCurrentAmbientBlue_Obj_Bl); + + m_fCurrentDirectionalRed = INTERP(m_nDirectionalRed,m_fCurrentDirectionalRed); + m_fCurrentDirectionalGreen = INTERP(m_nDirectionalGreen,m_fCurrentDirectionalGreen); + m_fCurrentDirectionalBlue = INTERP(m_nDirectionalBlue,m_fCurrentDirectionalBlue); + + m_fCurrentSpriteSize = INTERPscl(m_fSpriteSize,10.0f,m_fCurrentSpriteSize); + m_fCurrentSpriteBrightness = INTERPscl(m_fSpriteBrightness,10.0f,m_fCurrentSpriteBrightness); + m_nCurrentShadowStrength = INTERP(m_nShadowStrength,m_nCurrentShadowStrength); + m_nCurrentLightShadowStrength = INTERP(m_nLightShadowStrength,m_nCurrentLightShadowStrength); + m_nCurrentPoleShadowStrength = INTERP(m_nPoleShadowStrength,m_nCurrentPoleShadowStrength); + m_fCurrentFarClip = INTERP(m_fFarClip,m_fCurrentFarClip); + m_fCurrentFogStart = INTERP(m_fFogStart,m_fCurrentFogStart); + m_fCurrentLightsOnGroundBrightness = INTERPscl(m_fLightsOnGroundBrightness,10.0f,m_fCurrentLightsOnGroundBrightness); + + m_fCurrentBlurRed = INTERP(m_fBlurRed,m_fCurrentBlurRed); + m_fCurrentBlurGreen = INTERP(m_fBlurGreen,m_fCurrentBlurGreen); + m_fCurrentBlurBlue = INTERP(m_fBlurBlue,m_fCurrentBlurBlue); + +#undef INTERP +#undef INTERPscl + } + + if(TheCamera.m_BlurType == MOTION_BLUR_NONE || TheCamera.m_BlurType == MOTION_BLUR_LIGHT_SCENE) + TheCamera.SetMotionBlur(m_fCurrentBlurRed, m_fCurrentBlurGreen, m_fCurrentBlurBlue, 5, MOTION_BLUR_LIGHT_SCENE); + + m_nCurrentFogColourRed = (m_nCurrentSkyTopRed + 2*m_nCurrentSkyBottomRed) / 3; + m_nCurrentFogColourGreen = (m_nCurrentSkyTopGreen + 2*m_nCurrentSkyBottomGreen) / 3; + m_nCurrentFogColourBlue = (m_nCurrentSkyTopBlue + 2*m_nCurrentSkyBottomBlue) / 3; + + m_fCurrentAmbientRed /= 255.0f; + m_fCurrentAmbientGreen /= 255.0f; + m_fCurrentAmbientBlue /= 255.0f; + m_fCurrentAmbientRed_Obj /= 255.0f; + m_fCurrentAmbientGreen_Obj /= 255.0f; + m_fCurrentAmbientBlue_Obj /= 255.0f; + m_fCurrentAmbientRed_Bl /= 255.0f; + m_fCurrentAmbientGreen_Bl /= 255.0f; + m_fCurrentAmbientBlue_Bl /= 255.0f; + m_fCurrentAmbientRed_Obj_Bl /= 255.0f; + m_fCurrentAmbientGreen_Obj_Bl /= 255.0f; + m_fCurrentAmbientBlue_Obj_Bl /= 255.0f; + m_fCurrentDirectionalRed /= 255.0f; + m_fCurrentDirectionalGreen /= 255.0f; + m_fCurrentDirectionalBlue /= 255.0f; + + CShadows::CalcPedShadowValues(sunPos, + &m_fShadowFrontX[m_CurrentStoredValue], &m_fShadowFrontY[m_CurrentStoredValue], + &m_fShadowSideX[m_CurrentStoredValue], &m_fShadowSideY[m_CurrentStoredValue], + &m_fShadowDisplacementX[m_CurrentStoredValue], &m_fShadowDisplacementY[m_CurrentStoredValue]); + + if(TheCamera.GetForward().z < -0.9f || + !CWeather::bScriptsForceRain && (CCullZones::PlayerNoRain() || CCullZones::CamNoRain() || CCutsceneMgr::IsRunning())) + m_FogReduction = Min(m_FogReduction+1, 64); + else + m_FogReduction = Max(m_FogReduction-1, 0); +} diff --git a/src/renderer/Timecycle.h b/src/renderer/Timecycle.h new file mode 100644 index 00000000..da911b75 --- /dev/null +++ b/src/renderer/Timecycle.h @@ -0,0 +1,201 @@ +#pragma once + +class CTimeCycle +{ + static uint8 m_nAmbientRed[NUMHOURS][NUMWEATHERS]; + static uint8 m_nAmbientGreen[NUMHOURS][NUMWEATHERS]; + static uint8 m_nAmbientBlue[NUMHOURS][NUMWEATHERS]; + static uint8 m_nAmbientRed_Obj[NUMHOURS][NUMWEATHERS]; + static uint8 m_nAmbientGreen_Obj[NUMHOURS][NUMWEATHERS]; + static uint8 m_nAmbientBlue_Obj[NUMHOURS][NUMWEATHERS]; + static uint8 m_nAmbientRed_Bl[NUMHOURS][NUMWEATHERS]; + static uint8 m_nAmbientGreen_Bl[NUMHOURS][NUMWEATHERS]; + static uint8 m_nAmbientBlue_Bl[NUMHOURS][NUMWEATHERS]; + static uint8 m_nAmbientRed_Obj_Bl[NUMHOURS][NUMWEATHERS]; + static uint8 m_nAmbientGreen_Obj_Bl[NUMHOURS][NUMWEATHERS]; + static uint8 m_nAmbientBlue_Obj_Bl[NUMHOURS][NUMWEATHERS]; + static uint8 m_nDirectionalRed[NUMHOURS][NUMWEATHERS]; + static uint8 m_nDirectionalGreen[NUMHOURS][NUMWEATHERS]; + static uint8 m_nDirectionalBlue[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSkyTopRed[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSkyTopGreen[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSkyTopBlue[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSkyBottomRed[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSkyBottomGreen[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSkyBottomBlue[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSunCoreRed[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSunCoreGreen[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSunCoreBlue[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSunCoronaRed[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSunCoronaGreen[NUMHOURS][NUMWEATHERS]; + static uint8 m_nSunCoronaBlue[NUMHOURS][NUMWEATHERS]; + static int8 m_fSunSize[NUMHOURS][NUMWEATHERS]; + static int8 m_fSpriteSize[NUMHOURS][NUMWEATHERS]; + static int8 m_fSpriteBrightness[NUMHOURS][NUMWEATHERS]; + static uint8 m_nShadowStrength[NUMHOURS][NUMWEATHERS]; + static uint8 m_nLightShadowStrength[NUMHOURS][NUMWEATHERS]; + static uint8 m_nPoleShadowStrength[NUMHOURS][NUMWEATHERS]; + static int16 m_fFogStart[NUMHOURS][NUMWEATHERS]; + static int16 m_fFarClip[NUMHOURS][NUMWEATHERS]; + static uint8 m_fLightsOnGroundBrightness[NUMHOURS][NUMWEATHERS]; + static uint8 m_nLowCloudsRed[NUMHOURS][NUMWEATHERS]; + static uint8 m_nLowCloudsGreen[NUMHOURS][NUMWEATHERS]; + static uint8 m_nLowCloudsBlue[NUMHOURS][NUMWEATHERS]; + static uint8 m_nFluffyCloudsTopRed[NUMHOURS][NUMWEATHERS]; + static uint8 m_nFluffyCloudsTopGreen[NUMHOURS][NUMWEATHERS]; + static uint8 m_nFluffyCloudsTopBlue[NUMHOURS][NUMWEATHERS]; + static uint8 m_nFluffyCloudsBottomRed[NUMHOURS][NUMWEATHERS]; + static uint8 m_nFluffyCloudsBottomGreen[NUMHOURS][NUMWEATHERS]; + static uint8 m_nFluffyCloudsBottomBlue[NUMHOURS][NUMWEATHERS]; + static uint8 m_fBlurRed[NUMHOURS][NUMWEATHERS]; + static uint8 m_fBlurGreen[NUMHOURS][NUMWEATHERS]; + static uint8 m_fBlurBlue[NUMHOURS][NUMWEATHERS]; + static uint8 m_fWaterRed[NUMHOURS][NUMWEATHERS]; + static uint8 m_fWaterGreen[NUMHOURS][NUMWEATHERS]; + static uint8 m_fWaterBlue[NUMHOURS][NUMWEATHERS]; + static uint8 m_fWaterAlpha[NUMHOURS][NUMWEATHERS]; + + static float m_fCurrentAmbientRed; + static float m_fCurrentAmbientGreen; + static float m_fCurrentAmbientBlue; + static float m_fCurrentAmbientRed_Obj; + static float m_fCurrentAmbientGreen_Obj; + static float m_fCurrentAmbientBlue_Obj; + static float m_fCurrentAmbientRed_Bl; + static float m_fCurrentAmbientGreen_Bl; + static float m_fCurrentAmbientBlue_Bl; + static float m_fCurrentAmbientRed_Obj_Bl; + static float m_fCurrentAmbientGreen_Obj_Bl; + static float m_fCurrentAmbientBlue_Obj_Bl; + static float m_fCurrentDirectionalRed; + static float m_fCurrentDirectionalGreen; + static float m_fCurrentDirectionalBlue; + static int32 m_nCurrentSkyTopRed; + static int32 m_nCurrentSkyTopGreen; + static int32 m_nCurrentSkyTopBlue; + static int32 m_nCurrentSkyBottomRed; + static int32 m_nCurrentSkyBottomGreen; + static int32 m_nCurrentSkyBottomBlue; + static int32 m_nCurrentSunCoreRed; + static int32 m_nCurrentSunCoreGreen; + static int32 m_nCurrentSunCoreBlue; + static int32 m_nCurrentSunCoronaRed; + static int32 m_nCurrentSunCoronaGreen; + static int32 m_nCurrentSunCoronaBlue; + static float m_fCurrentSunSize; + static float m_fCurrentSpriteSize; + static float m_fCurrentSpriteBrightness; + static int32 m_nCurrentShadowStrength; + static int32 m_nCurrentLightShadowStrength; + static int32 m_nCurrentPoleShadowStrength; + static float m_fCurrentFogStart; + static float m_fCurrentFarClip; + static float m_fCurrentLightsOnGroundBrightness; + static int32 m_nCurrentLowCloudsRed; + static int32 m_nCurrentLowCloudsGreen; + static int32 m_nCurrentLowCloudsBlue; + static int32 m_nCurrentFluffyCloudsTopRed; + static int32 m_nCurrentFluffyCloudsTopGreen; + static int32 m_nCurrentFluffyCloudsTopBlue; + static int32 m_nCurrentFluffyCloudsBottomRed; + static int32 m_nCurrentFluffyCloudsBottomGreen; + static int32 m_nCurrentFluffyCloudsBottomBlue; + static float m_fCurrentBlurRed; + static float m_fCurrentBlurGreen; + static float m_fCurrentBlurBlue; + static float m_fCurrentWaterRed; + static float m_fCurrentWaterGreen; + static float m_fCurrentWaterBlue; + static float m_fCurrentWaterAlpha; + static int32 m_nCurrentFogColourRed; + static int32 m_nCurrentFogColourGreen; + static int32 m_nCurrentFogColourBlue; + + static int32 m_FogReduction; + +public: + static int32 m_bExtraColourOn; + static int32 m_ExtraColour; + static float m_ExtraColourInter; + static int32 m_CurrentStoredValue; + static CVector m_VectorToSun[16]; + static float m_fShadowFrontX[16]; + static float m_fShadowFrontY[16]; + static float m_fShadowSideX[16]; + static float m_fShadowSideY[16]; + static float m_fShadowDisplacementX[16]; + static float m_fShadowDisplacementY[16]; + + static float GetAmbientRed(void) { return m_fCurrentAmbientRed; } + static float GetAmbientGreen(void) { return m_fCurrentAmbientGreen; } + static float GetAmbientBlue(void) { return m_fCurrentAmbientBlue; } + static float GetAmbientRed_Obj(void) { return m_fCurrentAmbientRed_Obj; } + static float GetAmbientGreen_Obj(void) { return m_fCurrentAmbientGreen_Obj; } + static float GetAmbientBlue_Obj(void) { return m_fCurrentAmbientBlue_Obj; } + static float GetAmbientRed_Bl(void) { return m_fCurrentAmbientRed_Bl; } + static float GetAmbientGreen_Bl(void) { return m_fCurrentAmbientGreen_Bl; } + static float GetAmbientBlue_Bl(void) { return m_fCurrentAmbientBlue_Bl; } + static float GetAmbientRed_Obj_Bl(void) { return m_fCurrentAmbientRed_Obj_Bl; } + static float GetAmbientGreen_Obj_Bl(void) { return m_fCurrentAmbientGreen_Obj_Bl; } + static float GetAmbientBlue_Obj_Bl(void) { return m_fCurrentAmbientBlue_Obj_Bl; } + static float GetDirectionalRed(void) { return m_fCurrentDirectionalRed; } + static float GetDirectionalGreen(void) { return m_fCurrentDirectionalGreen; } + static float GetDirectionalBlue(void) { return m_fCurrentDirectionalBlue; } + static int32 GetSkyTopRed(void) { return m_nCurrentSkyTopRed; } + static int32 GetSkyTopGreen(void) { return m_nCurrentSkyTopGreen; } + static int32 GetSkyTopBlue(void) { return m_nCurrentSkyTopBlue; } + static int32 GetSkyBottomRed(void) { return m_nCurrentSkyBottomRed; } + static int32 GetSkyBottomGreen(void) { return m_nCurrentSkyBottomGreen; } + static int32 GetSkyBottomBlue(void) { return m_nCurrentSkyBottomBlue; } + static int32 GetSunCoreRed(void) { return m_nCurrentSunCoreRed; } + static int32 GetSunCoreGreen(void) { return m_nCurrentSunCoreGreen; } + static int32 GetSunCoreBlue(void) { return m_nCurrentSunCoreBlue; } + static int32 GetSunCoronaRed(void) { return m_nCurrentSunCoronaRed; } + static int32 GetSunCoronaGreen(void) { return m_nCurrentSunCoronaGreen; } + static int32 GetSunCoronaBlue(void) { return m_nCurrentSunCoronaBlue; } + static float GetSunSize(void) { return m_fCurrentSunSize; } + static float GetSpriteBrightness(void) { return m_fCurrentSpriteBrightness; } + static float GetSpriteSize(void) { return m_fCurrentSpriteSize; } + static int32 GetShadowStrength(void) { return m_nCurrentShadowStrength; } + static int32 GetLightShadowStrength(void) { return m_nCurrentLightShadowStrength; } + static float GetLightOnGroundBrightness(void) { return m_fCurrentLightsOnGroundBrightness; } + static float GetFarClip(void) { return m_fCurrentFarClip; } + static float GetFogStart(void) { return m_fCurrentFogStart; } + + static int32 GetLowCloudsRed(void) { return m_nCurrentLowCloudsRed; } + static int32 GetLowCloudsGreen(void) { return m_nCurrentLowCloudsGreen; } + static int32 GetLowCloudsBlue(void) { return m_nCurrentLowCloudsBlue; } + static int32 GetFluffyCloudsTopRed(void) { return m_nCurrentFluffyCloudsTopRed; } + static int32 GetFluffyCloudsTopGreen(void) { return m_nCurrentFluffyCloudsTopGreen; } + static int32 GetFluffyCloudsTopBlue(void) { return m_nCurrentFluffyCloudsTopBlue; } + static int32 GetFluffyCloudsBottomRed(void) { return m_nCurrentFluffyCloudsBottomRed; } + static int32 GetFluffyCloudsBottomGreen(void) { return m_nCurrentFluffyCloudsBottomGreen; } + static int32 GetFluffyCloudsBottomBlue(void) { return m_nCurrentFluffyCloudsBottomBlue; } + static int32 GetFogRed(void) { return m_nCurrentFogColourRed; } + static int32 GetFogGreen(void) { return m_nCurrentFogColourGreen; } + static int32 GetFogBlue(void) { return m_nCurrentFogColourBlue; } + static int32 GetFogReduction(void) { return m_FogReduction; } + + static int32 GetBlurRed(void) { return m_fCurrentBlurRed; } + static int32 GetBlurGreen(void) { return m_fCurrentBlurGreen; } + static int32 GetBlurBlue(void) { return m_fCurrentBlurBlue; } + static int32 GetWaterRed(void) { return m_fCurrentWaterRed; } + static int32 GetWaterGreen(void) { return m_fCurrentWaterGreen; } + static int32 GetWaterBlue(void) { return m_fCurrentWaterBlue; } + static int32 GetWaterAlpha(void) { return m_fCurrentWaterAlpha; } + + static void Initialise(void); + static void Update(void); + static float Interpolate(int8 *a, int8 *b); + static float Interpolate(uint8 *a, uint8 *b); + static float Interpolate(int16 *a, int16 *b); + static void StartExtraColour(int32 c, bool fade); + static void StopExtraColour(bool fade); + static CVector &GetSunDirection(void) { return m_VectorToSun[m_CurrentStoredValue]; } + static float GetShadowFrontX(void) { return m_fShadowFrontX[m_CurrentStoredValue]; } + static float GetShadowFrontY(void) { return m_fShadowFrontY[m_CurrentStoredValue]; } + static float GetShadowSideX(void) { return m_fShadowSideX[m_CurrentStoredValue]; } + static float GetShadowSideY(void) { return m_fShadowSideY[m_CurrentStoredValue]; } + static float GetShadowDisplacementX(void) { return m_fShadowDisplacementX[m_CurrentStoredValue]; } + static float GetShadowDisplacementY(void) { return m_fShadowDisplacementY[m_CurrentStoredValue]; } +}; diff --git a/src/renderer/VarConsole.cpp b/src/renderer/VarConsole.cpp new file mode 100644 index 00000000..372a091a --- /dev/null +++ b/src/renderer/VarConsole.cpp @@ -0,0 +1,786 @@ +#include "common.h" +#include "VarConsole.h" +#include "Font.h" +#include "Pad.h" + +#define VAR_CONSOLE_PAD 1 + +CVarConsole VarConsole; + +void +CVarConsole::Initialise() +{ + m_nCountEntries = 0; + m_nCurPage = 1; + m_bIsOpen = false; + m_nCurEntry = 0; + m_nFirstEntryOnPage = 0; +} + +void +CVarConsole::Add(char *text, int8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pInt8Value = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_INT8; + m_aEntries[i].I8_step = step; + m_aEntries[i].I8_min = min; + m_aEntries[i].I8_max = max; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, int16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pInt16Value = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_INT16; + m_aEntries[i].I16_step = step; + m_aEntries[i].I16_min = min; + m_aEntries[i].I16_max = max; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, int32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pInt32Value = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_INT32; + m_aEntries[i].I32_step = step; + m_aEntries[i].I32_min = min; + m_aEntries[i].I32_max = max; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, int64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pInt64Value = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_INT64; + m_aEntries[i].I64_step = step; + m_aEntries[i].I64_min = min; + m_aEntries[i].I64_max = max; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, uint8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pUint8Value = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_UINT8; + m_aEntries[i].I8_step = step; + m_aEntries[i].I8_min = min; + m_aEntries[i].I8_max = max; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, uint16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pUint16Value = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_UINT16; + m_aEntries[i].I16_step = step; + m_aEntries[i].I16_min = min; + m_aEntries[i].I16_max = max; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, uint32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pUint32Value = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_UINT32; + m_aEntries[i].I32_step = step; + m_aEntries[i].I32_min = min; + m_aEntries[i].I32_max = max; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, uint64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pUint64Value = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_UINT64; + m_aEntries[i].I64_step = step; + m_aEntries[i].I64_min = min; + m_aEntries[i].I64_max = max; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, float *pVal, float step, float min, float max, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pFloatValue = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_FLOAT; + m_aEntries[i].F_step = step; + m_aEntries[i].F_min = min; + m_aEntries[i].F_max = max; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, bool *pVal, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pBoolValue = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_BOOL; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, bool8 *pVal, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pUint8Value = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_BOOL8; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, bool16 *pVal, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pUint16Value = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_BOOL16; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, bool32 *pVal, bool8 isVar) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pUint32Value = pVal; + m_aEntries[i].bAllowExceedBounds = isVar; + m_aEntries[i].VarType = VCE_TYPE_BOOL32; + m_nCountEntries++; +} + +void +CVarConsole::Add(char *text, void (*pCallback)(void)) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + return; + } + + m_aEntries[i].text = text; + m_aEntries[i].pCallback = pCallback; + m_aEntries[i].VarType = VCE_TYPE_FUNCTION; + m_nCountEntries++; +} + +void +CVarConsole::Remove(char *text) +{ + int i; + for (i = 0; i < m_nCountEntries; i++) { + if (m_aEntries[i].text == text) + { + for (int j = i; j < m_nCountEntries-1; j++) + m_aEntries[j] = m_aEntries[j+1]; + m_nCountEntries--; + return; + } + } +} + +void +CVarConsole::SortPages() +{ + m_nNumPages = m_nCountEntries / 30 + 1; +} + +void +CVarConsole::Display() +{ + char s[256]; + wchar ws[256]; + + CFont::SetColor(CRGBA(200, 200, 200, 255)); + CFont::SetFontStyle(FONT_STANDARD); + CFont::SetScale(SCREEN_SCALE_X(0.5f), SCREEN_SCALE_Y(0.6f)); + CFont::SetDropShadowPosition(2); + CFont::SetDropColor(CRGBA(0, 0, 0, 255)); + CFont::SetPropOn(); + CFont::SetWrapx(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH)); + CFont::SetRightJustifyWrap(0.0f); + sprintf(s, "PAGE %d", m_nCurPage); + AsciiToUnicode(s, ws); + CFont::SetRightJustifyOn(); + CFont::PrintString(SCREEN_SCALE_X(310.0f), SCREEN_SCALE_Y(30.0f), ws); + CFont::SetRightJustifyOff(); + int y = 45; + for (int i = m_nFirstEntryOnPage; i < m_nCountEntries && i < m_nFirstEntryOnPage + 30; i++) + { + switch (m_aEntries[i].VarType) + { + case VCE_TYPE_INT8: + sprintf(s, "(%d) %s:I8:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt8Value); + break; + case VCE_TYPE_INT16: + sprintf(s, "(%d) %s:I16:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt16Value); + break; + case VCE_TYPE_INT32: + sprintf(s, "(%d) %s:I32:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt32Value); + break; + case VCE_TYPE_INT64: +#ifdef FIX_BUGS + sprintf(s, "(%d) %s:I64:%lld", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt64Value); +#else + sprintf(s, "(%d) %s:I64:%d", i + 1, m_aEntries[i].text, (int32)*m_aEntries[i].pInt64Value); +#endif + break; + case VCE_TYPE_UINT8: + sprintf(s, "(%d) %s:U8:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint8Value); + break; + case VCE_TYPE_UINT16: + sprintf(s, "(%d) %s:U6:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint16Value); + break; + case VCE_TYPE_UINT32: + sprintf(s, "(%d) %s:U32:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint32Value); + break; + case VCE_TYPE_UINT64: +#ifdef FIX_BUGS + sprintf(s, "(%d) %s:U64:%llu", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint64Value); +#else + sprintf(s, "(%d) %s:U64:%d", i + 1, m_aEntries[i].text, (uint32)*m_aEntries[i].pUint64Value); +#endif + break; + case VCE_TYPE_FLOAT: + sprintf(s, "(%d) %s:F:%f", i + 1, m_aEntries[i].text, *m_aEntries[i].pFloatValue); + break; + case VCE_TYPE_BOOL: + if (*m_aEntries[i].pBoolValue) + sprintf(s, "(%d) %s:B:TRUE", i + 1, m_aEntries[i].text); + else + sprintf(s, "(%d) %s:B : FALSE", i + 1, m_aEntries[i].text); + break; + case VCE_TYPE_BOOL8: + if (*m_aEntries[i].pUint8Value == FALSE) + sprintf(s, "(%d) %s:B8:FALSE", i + 1, m_aEntries[i].text); + else + sprintf(s, "(%d) %s:B8:TRUE", i + 1, m_aEntries[i].text); + break; + case VCE_TYPE_BOOL16: + if (*m_aEntries[i].pUint16Value == FALSE) + sprintf(s, "(%d) %s:B16:FALSE", i + 1, m_aEntries[i].text); + else + sprintf(s, "(%d) %s:B16:TRUE", i + 1, m_aEntries[i].text); + break; + case VCE_TYPE_BOOL32: + if (*m_aEntries[i].pUint32Value == FALSE) + sprintf(s, "(%d) %s:B32:FALSE", i + 1, m_aEntries[i].text); + else + sprintf(s, "(%d) %s:B32:TRUE", i + 1, m_aEntries[i].text); + break; + case VCE_TYPE_FUNCTION: + sprintf(s, "(%d) %s:FUNCTION:call this function?", i + 1, m_aEntries[i].text); + break; + } + AsciiToUnicode(s, ws); + if (m_nCurEntry == i) { + CFont::SetBackgroundOn(); +#ifdef FIX_BUGS + CFont::SetBackgroundColor(CRGBA(128, 128, 128, 128)); +#endif + } +#ifdef FIX_BUGS + else + CFont::SetBackgroundColor(CRGBA(128, 128, 128, 0)); +#endif + + CFont::SetColor(CRGBA(200, 200, 200, 255)); + CFont::PrintString(SCREEN_SCALE_X(30.0f), SCREEN_SCALE_Y(y), ws); + if (m_nCurEntry == i) + CFont::SetBackgroundOff(); + y += 12; + } +} + +void +CVarConsole::ModifyLeft() +{ + CVarConsoleEntry &entry = m_aEntries[m_nCurEntry]; + switch (entry.VarType) + { + case VCE_TYPE_INT8: + *entry.pInt8Value -= entry.I8_step; + if (entry.bAllowExceedBounds) { + if (*entry.pInt8Value < entry.I8_min) + *entry.pInt8Value = entry.I8_max; + } else { + if (*entry.pInt8Value < entry.I8_min) + *entry.pInt8Value = entry.I8_min; + } + break; + case VCE_TYPE_INT16: + *entry.pInt16Value -= entry.I16_step; + if (entry.bAllowExceedBounds) { + if (*entry.pInt16Value < entry.I16_min) + *entry.pInt16Value = entry.I16_max; + } + else { + if (*entry.pInt16Value < entry.I16_min) + *entry.pInt16Value = entry.I16_min; + } + break; + case VCE_TYPE_INT32: + *entry.pInt32Value -= entry.I32_step; + if (entry.bAllowExceedBounds) { + if (*entry.pInt32Value < entry.I32_min) + *entry.pInt32Value = entry.I32_max; + } + else { + if (*entry.pInt32Value < entry.I32_min) + *entry.pInt32Value = entry.I32_min; + } + break; + case VCE_TYPE_INT64: + *entry.pInt64Value -= entry.I64_step; + if (entry.bAllowExceedBounds) { + if (*entry.pInt64Value < entry.I64_min) + *entry.pInt64Value = entry.I64_max; + } + else { + if (*entry.pInt64Value < entry.I64_min) + *entry.pInt64Value = entry.I64_min; + } + break; + case VCE_TYPE_UINT8: + *entry.pUint8Value -= entry.I8_step; + if (entry.bAllowExceedBounds) { + if (*(int8*)entry.pUint8Value < entry.I8_min) + *entry.pUint8Value = entry.I8_max; + } + else { + if (*(int8*)entry.pUint8Value < entry.I8_min) + *entry.pUint8Value = entry.I8_min; + } + break; + case VCE_TYPE_UINT16: + *entry.pUint16Value -= entry.I16_step; + if (entry.bAllowExceedBounds) { + if (*(int16*)entry.pUint16Value < entry.I16_min) + *entry.pUint16Value = entry.I16_max; + } + else { + if (*(int16*)entry.pUint16Value < entry.I16_min) + *entry.pUint16Value = entry.I16_min; + } + break; + case VCE_TYPE_UINT32: + *entry.pUint32Value -= entry.I32_step; + if (entry.bAllowExceedBounds) { + if (*(int32*)entry.pUint32Value < entry.I32_min) + *entry.pUint32Value = entry.I32_max; + } + else { + if (*(int32*)entry.pUint32Value < entry.I32_min) + *entry.pUint32Value = entry.I32_min; + } + break; + case VCE_TYPE_UINT64: + *entry.pUint64Value -= entry.I64_step; + if (entry.bAllowExceedBounds) { + if (*(int64*)entry.pUint64Value < entry.I64_min) + *entry.pUint64Value = entry.I64_max; + } + else { + if (*(int64*)entry.pUint64Value < entry.I64_min) + *entry.pUint64Value = entry.I64_min; + } + break; + case VCE_TYPE_FLOAT: + *entry.pFloatValue -= entry.F_step; + if (entry.bAllowExceedBounds) { + if (*entry.pFloatValue < entry.F_min) + *entry.pFloatValue = entry.F_max; + } + else { + if (*entry.pFloatValue < entry.F_min) + *entry.pFloatValue = entry.F_min; + } + break; + case VCE_TYPE_BOOL: + if (entry.bAllowExceedBounds) + *entry.pBoolValue ^= true; + else + *entry.pBoolValue = false; + break; + case VCE_TYPE_BOOL8: + if (entry.bAllowExceedBounds) + *entry.pUint8Value = *entry.pUint8Value == false; + else + *entry.pUint8Value = false; + break; + case VCE_TYPE_BOOL16: + if (entry.bAllowExceedBounds) + *entry.pUint16Value = *entry.pUint16Value == false; + else + *entry.pUint16Value = false; + break; + case VCE_TYPE_BOOL32: + if (entry.bAllowExceedBounds) + *entry.pUint32Value = *entry.pUint32Value == false; + else + *entry.pUint32Value = false; + break; + case VCE_TYPE_FUNCTION: + entry.pCallback(); + break; + default: + return; + } +} + +void +CVarConsole::ModifyRight() +{ + CVarConsoleEntry &entry = m_aEntries[m_nCurEntry]; + switch (entry.VarType) + { + case VCE_TYPE_INT8: + *entry.pInt8Value += entry.I8_step; + if (entry.bAllowExceedBounds) { + if (*entry.pInt8Value > entry.I8_max) + *entry.pInt8Value = entry.I8_min; + } + else { + if (*entry.pInt8Value > entry.I8_max) + *entry.pInt8Value = entry.I8_max; + } + break; + case VCE_TYPE_INT16: + *entry.pInt16Value += entry.I16_step; + if (entry.bAllowExceedBounds) { + if (*entry.pInt16Value > entry.I16_max) + *entry.pInt16Value = entry.I16_min; + } + else { + if (*entry.pInt16Value > entry.I16_max) + *entry.pInt16Value = entry.I16_max; + } + break; + case VCE_TYPE_INT32: + *entry.pInt32Value += entry.I32_step; + if (entry.bAllowExceedBounds) { + if (*entry.pInt32Value > entry.I32_max) + *entry.pInt32Value = entry.I32_min; + } + else { + if (*entry.pInt32Value > entry.I32_max) + *entry.pInt32Value = entry.I32_max; + } + break; + case VCE_TYPE_INT64: + *entry.pInt64Value += entry.I64_step; + if (entry.bAllowExceedBounds) { + if (*entry.pInt64Value > entry.I64_max) + *entry.pInt64Value = entry.I64_min; + } + else { + if (*entry.pInt64Value > entry.I64_max) + *entry.pInt64Value = entry.I64_max; + } + break; + case VCE_TYPE_UINT8: + *entry.pUint8Value += entry.I8_step; + if (entry.bAllowExceedBounds) { + if (*entry.pUint8Value > (uint8)entry.I8_max) + *entry.pUint8Value = entry.I8_min; + } + else { + if (*entry.pUint8Value > (uint8)entry.I8_max) + *entry.pUint8Value = entry.I8_max; + } + break; + case VCE_TYPE_UINT16: + *entry.pUint16Value += entry.I16_step; + if (entry.bAllowExceedBounds) { + if (*entry.pUint16Value > (uint16)entry.I16_max) + *entry.pUint16Value = entry.I16_min; + } + else { + if (*entry.pUint16Value > (uint16)entry.I16_max) + *entry.pUint16Value = entry.I16_max; + } + break; + case VCE_TYPE_UINT32: + *entry.pUint32Value += entry.I32_step; + if (entry.bAllowExceedBounds) { + if (*entry.pUint32Value > (uint32)entry.I32_max) + *entry.pUint32Value = entry.I32_min; + } + else { + if (*entry.pUint32Value > (uint32)entry.I32_max) + *entry.pUint32Value = entry.I32_max; + } + break; + case VCE_TYPE_UINT64: + *entry.pUint64Value += entry.I64_step; + if (entry.bAllowExceedBounds) { + if (*entry.pUint64Value > (uint64)entry.I64_max) + *entry.pUint64Value = entry.I64_min; + } + else { + if (*entry.pUint64Value > (uint64)entry.I64_max) + *entry.pUint64Value = entry.I64_max; + } + break; + case VCE_TYPE_FLOAT: + *entry.pFloatValue += entry.F_step; + if (entry.bAllowExceedBounds) { + if (*entry.pFloatValue > entry.F_max) + *entry.pFloatValue = entry.F_min; + } + else { + if (*entry.pFloatValue > entry.F_max) + *entry.pFloatValue = entry.F_max; + } + break; + case VCE_TYPE_BOOL: + if (entry.bAllowExceedBounds) + *entry.pBoolValue ^= true; + else + *entry.pBoolValue = true; + break; + case VCE_TYPE_BOOL8: + if (entry.bAllowExceedBounds) + *entry.pUint8Value = *entry.pUint8Value == false; + else + *entry.pUint8Value = true; + break; + case VCE_TYPE_BOOL16: + if (entry.bAllowExceedBounds) + *entry.pUint16Value = *entry.pUint16Value == false; + else + *entry.pUint16Value = true; + break; + case VCE_TYPE_BOOL32: + if (entry.bAllowExceedBounds) + *entry.pUint32Value = *entry.pUint32Value == false; + else + *entry.pUint32Value = true; + break; + case VCE_TYPE_FUNCTION: + entry.pCallback(); + break; + default: + return; + } +} + +void +CVarConsole::Enter() +{ + m_bIsOpen = true; +} + +void +CVarConsole::Exit() +{ + m_bIsOpen = false; +} + +void +CVarConsole::Input() +{ + if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadDownJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadDown()) + { + m_nCurEntry++; + if (m_nCurEntry < m_nCountEntries) + { + if (m_nCurEntry > m_nFirstEntryOnPage + 29) + { + m_nFirstEntryOnPage = m_nCurEntry; + ++m_nCurPage; + } + } + else + { + m_nCurEntry = m_nCountEntries - 1; + } + } + + if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadUpJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadUp()) + { + m_nCurEntry--; + if (m_nCurEntry < m_nFirstEntryOnPage) + { + m_nFirstEntryOnPage = m_nCurEntry - 29; + --m_nCurPage; + } + if (m_nFirstEntryOnPage < 0) + { + m_nCurEntry = 0; + m_nFirstEntryOnPage = 0; + m_nCurPage = 1; + } + } + if (CPad::GetPad(VAR_CONSOLE_PAD)->GetSquare()) + ModifyLeft(); + if (CPad::GetPad(VAR_CONSOLE_PAD)->GetTriangle()) + ModifyRight(); + + if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadLeftJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadLeft()) + ModifyLeft(); + + if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadRightJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadRight()) + ModifyRight(); + + if (CPad::GetPad(VAR_CONSOLE_PAD)->GetLeftShoulder2JustDown()) + { + if (m_nCurPage > 1) + { + m_nCurPage--; + m_nFirstEntryOnPage -= 30; + m_nCurEntry = m_nFirstEntryOnPage; + if (m_nFirstEntryOnPage < 0) + { + m_nFirstEntryOnPage = 0; + m_nCurEntry = m_nFirstEntryOnPage; + m_nCurPage = 1; + } + } + } + + if (CPad::GetPad(VAR_CONSOLE_PAD)->GetRightShoulder2JustDown()) + { + if (m_nCurPage < m_nNumPages) + { + m_nCurPage++; + m_nFirstEntryOnPage += 30; + m_nCurEntry = m_nFirstEntryOnPage; + if (m_nFirstEntryOnPage >= m_nCountEntries) + { + m_nFirstEntryOnPage -= 30; + m_nCurEntry = m_nFirstEntryOnPage; + m_nCurPage--; + } + } + } + + if (CPad::GetPad(VAR_CONSOLE_PAD)->GetRightShoulder1JustDown() && CPad::GetPad(VAR_CONSOLE_PAD)->GetLeftShoulder1JustDown()) + Exit(); +} + +void +CVarConsole::Process() +{ + Input(); + SortPages(); + Display(); +} + +bool8 +CVarConsole::Open() +{ + return m_bIsOpen; +} + +void +CVarConsole::Check() +{ + if (Open()) + Process(); + else if (CPad::GetPad(VAR_CONSOLE_PAD)->GetRightShoulder1JustDown() && CPad::GetPad(VAR_CONSOLE_PAD)->GetLeftShoulder1JustDown()) + Enter(); +} \ No newline at end of file diff --git a/src/renderer/VarConsole.h b/src/renderer/VarConsole.h new file mode 100644 index 00000000..5179a10d --- /dev/null +++ b/src/renderer/VarConsole.h @@ -0,0 +1,92 @@ +#pragma once + +enum eVarConsoleEntryType +{ + VCE_TYPE_INT8, + VCE_TYPE_INT16, + VCE_TYPE_INT32, + VCE_TYPE_INT64, + VCE_TYPE_UINT8, + VCE_TYPE_UINT16, + VCE_TYPE_UINT32, + VCE_TYPE_UINT64, + VCE_TYPE_FLOAT, + VCE_TYPE_BOOL, + VCE_TYPE_BOOL8, + VCE_TYPE_BOOL16, + VCE_TYPE_BOOL32, + VCE_TYPE_FUNCTION, +}; + +struct CVarConsoleEntry +{ + char *text; + int8 *pInt8Value; + int16 *pInt16Value; + int32 *pInt32Value; + int64 *pInt64Value; + uint8 *pUint8Value; + uint16 *pUint16Value; + uint32 *pUint32Value; + uint64 *pUint64Value; + float *pFloatValue; + bool *pBoolValue; + void (*pCallback)(void); + int8 I8_step, I8_max, I8_min; + int16 I16_step, I16_max, I16_min; + int32 I32_step, I32_max, I32_min; + int64 I64_step, I64_max, I64_min; + float F_step, F_max, F_min; + bool8 bAllowExceedBounds; + uint8 VarType; +}; + + +class CVarConsole +{ + int32 m_nCountEntries; + bool8 m_bIsOpen; + int32 m_nCurEntry; + int32 m_nFirstEntryOnPage; + int32 m_nCurPage; + int32 m_nNumPages; + CVarConsoleEntry m_aEntries[91]; +public: +#ifdef FIX_BUGS + CVarConsole() { Initialise(); } +#endif + void Initialise(); + void Add(char *text, int8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar); + void Add(char *text, int16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar); + void Add(char *text, int32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar); + void Add(char *text, int64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar); + void Add(char *text, uint8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar); + void Add(char *text, uint16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar); + void Add(char *text, uint32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar); + void Add(char *text, uint64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar); + void Add(char *text, float *pVal, float step, float min, float max, bool8 isVar); + void Add(char *text, bool *pVal, bool8 isVar); + void Add(char *text, bool8 *pVal, bool8 isVar); + void Add(char *text, bool16 *pVal, bool8 isVar); + void Add(char *text, bool32 *pVal, bool8 isVar); + void Add(char *text, void (*pVar)(void)); + + void Remove(char *text); + + void SortPages(); + void Display(); + + void ModifyLeft(); + void ModifyRight(); + + void Enter(); + void Exit(); + + void Input(); + void Process(); + + bool8 Open(); + void Check(); +}; + +extern CVarConsole VarConsole; \ No newline at end of file diff --git a/src/renderer/WaterCannon.cpp b/src/renderer/WaterCannon.cpp new file mode 100644 index 00000000..4976f8a3 --- /dev/null +++ b/src/renderer/WaterCannon.cpp @@ -0,0 +1,317 @@ +#include "common.h" + +#include "WaterCannon.h" +#include "Vector.h" +#include "General.h" +#include "main.h" +#include "Timer.h" +#include "Pools.h" +#include "Ped.h" +#include "AnimManager.h" +#include "Fire.h" +#include "WaterLevel.h" +#include "Camera.h" +#include "Particle.h" + +#define WATERCANNONVERTS 4 +#define WATERCANNONINDEXES 12 + +RwIm3DVertex WaterCannonVertices[WATERCANNONVERTS]; +RwImVertexIndex WaterCannonIndexList[WATERCANNONINDEXES]; + +CWaterCannon CWaterCannons::aCannons[NUM_WATERCANNONS]; + +void CWaterCannon::Init(void) +{ + m_nId = 0; + m_nCur = 0; + m_nTimeCreated = CTimer::GetTimeInMilliseconds(); + + for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ ) + m_abUsed[i] = false; + + RwIm3DVertexSetU(&WaterCannonVertices[0], 0.0f); + RwIm3DVertexSetV(&WaterCannonVertices[0], 0.0f); + + RwIm3DVertexSetU(&WaterCannonVertices[1], 1.0f); + RwIm3DVertexSetV(&WaterCannonVertices[1], 0.0f); + + RwIm3DVertexSetU(&WaterCannonVertices[2], 0.0f); + RwIm3DVertexSetV(&WaterCannonVertices[2], 0.0f); + + RwIm3DVertexSetU(&WaterCannonVertices[3], 1.0f); + RwIm3DVertexSetV(&WaterCannonVertices[3], 0.0f); + + WaterCannonIndexList[0] = 0; + WaterCannonIndexList[1] = 1; + WaterCannonIndexList[2] = 2; + + WaterCannonIndexList[3] = 1; + WaterCannonIndexList[4] = 3; + WaterCannonIndexList[5] = 2; + + WaterCannonIndexList[6] = 0; + WaterCannonIndexList[7] = 2; + WaterCannonIndexList[8] = 1; + + WaterCannonIndexList[9] = 1; + WaterCannonIndexList[10] = 2; + WaterCannonIndexList[11] = 3; +} + +void CWaterCannon::Update_OncePerFrame(int16 index) +{ + ASSERT(index < NUM_WATERCANNONS); + + if (CTimer::GetTimeInMilliseconds() > m_nTimeCreated + WATERCANNON_LIFETIME ) + { + m_nCur = (m_nCur + 1) % NUM_SEGMENTPOINTS; + m_abUsed[m_nCur] = false; + } + + for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ ) + { + if ( m_abUsed[i] ) + { + m_avecVelocity[i].z += -WATERCANNON_GRAVITY * CTimer::GetTimeStep(); + m_avecPos[i] += m_avecVelocity[i] * CTimer::GetTimeStep(); + } + } + + for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ ) + { + if ( m_abUsed[i] && gFireManager.ExtinguishPointWithWater(m_avecPos[i], 4.0f) ) + { + break; + } + } + + if ( ((index + CTimer::GetFrameCounter()) & 3) == 0 ) + PushPeds(); + + // free if unused + + int32 i = 0; + while ( 1 ) + { + if ( m_abUsed[i] ) + break; + + if ( ++i >= NUM_SEGMENTPOINTS ) + { + m_nId = 0; + return; + } + } +} + +void CWaterCannon::Update_NewInput(CVector *pos, CVector *dir) +{ + ASSERT(pos != NULL); + ASSERT(dir != NULL); + + m_avecPos[m_nCur] = *pos; + m_avecVelocity[m_nCur] = *dir; + m_abUsed[m_nCur] = true; +} + +void CWaterCannon::Render(void) +{ + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterRaster); + + float v = float(CGeneral::GetRandomNumber() & 255) / 256; + + RwIm3DVertexSetV(&WaterCannonVertices[0], v); + RwIm3DVertexSetV(&WaterCannonVertices[1], v); + RwIm3DVertexSetV(&WaterCannonVertices[2], v); + RwIm3DVertexSetV(&WaterCannonVertices[3], v); + + int16 pointA = m_nCur % NUM_SEGMENTPOINTS; + + int16 pointB = pointA - 1; + if ( pointB < 0 ) + pointB += NUM_SEGMENTPOINTS; + + bool bInit = false; + CVector norm; + + for ( int32 i = 0; i < NUM_SEGMENTPOINTS - 1; i++ ) + { + if ( m_abUsed[pointA] && m_abUsed[pointB] ) + { + if ( !bInit ) + { + CVector cp = CrossProduct(m_avecPos[pointB] - m_avecPos[pointA], TheCamera.GetForward()); + norm = cp * (0.05f / cp.Magnitude()); + bInit = true; + } + + float dist = float(i*i*i) / 300.0f + 1.0f; + float brightness = float(i) / NUM_SEGMENTPOINTS; + + int32 color = (int32)((1.0f - brightness*brightness) * 255.0f); + CVector offset = dist * norm; + + RwIm3DVertexSetRGBA(&WaterCannonVertices[0], color, color, color, color); + RwIm3DVertexSetPos (&WaterCannonVertices[0], m_avecPos[pointA].x - offset.x, m_avecPos[pointA].y - offset.y, m_avecPos[pointA].z - offset.z); + + RwIm3DVertexSetRGBA(&WaterCannonVertices[1], color, color, color, color); + RwIm3DVertexSetPos (&WaterCannonVertices[1], m_avecPos[pointA].x + offset.x, m_avecPos[pointA].y + offset.y, m_avecPos[pointA].z + offset.z); + + RwIm3DVertexSetRGBA(&WaterCannonVertices[2], color, color, color, color); + RwIm3DVertexSetPos (&WaterCannonVertices[2], m_avecPos[pointB].x - offset.x, m_avecPos[pointB].y - offset.y, m_avecPos[pointB].z - offset.z); + + RwIm3DVertexSetRGBA(&WaterCannonVertices[3], color, color, color, color); + RwIm3DVertexSetPos (&WaterCannonVertices[3], m_avecPos[pointB].x + offset.x, m_avecPos[pointB].y + offset.y, m_avecPos[pointB].z + offset.z); + + LittleTest(); + + if ( RwIm3DTransform(WaterCannonVertices, WATERCANNONVERTS, NULL, rwIM3D_VERTEXUV) ) + { + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, WaterCannonIndexList, WATERCANNONINDEXES); + RwIm3DEnd(); + } + } + + pointA = pointB--; + if ( pointB < 0 ) + pointB += NUM_SEGMENTPOINTS; + } + + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE); +} + +void CWaterCannon::PushPeds(void) +{ + float minx = 10000.0f; + float maxx = -10000.0f; + float miny = 10000.0f; + float maxy = -10000.0f; + float minz = 10000.0f; + float maxz = -10000.0f; + + for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ ) + { + if ( m_abUsed[i] ) + { + minx = Min(minx, m_avecPos[i].x); + maxx = Max(maxx, m_avecPos[i].x); + + miny = Min(miny, m_avecPos[i].y); + maxy = Max(maxy, m_avecPos[i].y); + + minz = Min(minz, m_avecPos[i].z); + maxz = Max(maxz, m_avecPos[i].z); + } + } + + for ( int32 i = CPools::GetPedPool()->GetSize() - 1; i >= 0; i--) + { + CPed *ped = CPools::GetPedPool()->GetSlot(i); + if ( ped ) + { + if ( ped->GetPosition().x > minx && ped->GetPosition().x < maxx + && ped->GetPosition().y > miny && ped->GetPosition().y < maxy + && ped->GetPosition().z > minz && ped->GetPosition().z < maxz ) + { + for ( int32 j = 0; j < NUM_SEGMENTPOINTS; j++ ) + { + if ( m_abUsed[j] ) + { + CVector dist = m_avecPos[j] - ped->GetPosition(); + + if ( dist.MagnitudeSqr() < 5.0f ) + { + int32 localDir = ped->GetLocalDirection(CVector2D(1.0f, 0.0f)); + + ped->bIsStanding = false; + + ped->ApplyMoveForce(0.0f, 0.0f, 2.0f * CTimer::GetTimeStep()); + + ped->m_vecMoveSpeed.x = (0.6f * m_avecVelocity[j].x + ped->m_vecMoveSpeed.x) * 0.5f; + ped->m_vecMoveSpeed.y = (0.6f * m_avecVelocity[j].y + ped->m_vecMoveSpeed.y) * 0.5f; + + float pedSpeed2D = ped->m_vecMoveSpeed.Magnitude2D(); + + if ( pedSpeed2D > 0.2f ) { + ped->m_vecMoveSpeed.x *= (0.2f / pedSpeed2D); + ped->m_vecMoveSpeed.y *= (0.2f / pedSpeed2D); + } + ped->SetFall(2000, (AnimationId)(localDir + ANIM_STD_HIGHIMPACT_FRONT), 0); + CParticle::AddParticle(PARTICLE_STEAM_NY_SLOWMOTION, ped->GetPosition(), ped->m_vecMoveSpeed * 0.3f, 0, 0.5f); + CParticle::AddParticle(PARTICLE_CAR_SPLASH, ped->GetPosition(), ped->m_vecMoveSpeed * -0.3f + CVector(0.f, 0.f, 0.5f), 0, 0.5f, + CGeneral::GetRandomNumberInRange(0.f, 10.f), CGeneral::GetRandomNumberInRange(0.f, 90.f), 1); + + j = NUM_SEGMENTPOINTS; + } + } + } + } + } + } +} + +void CWaterCannons::Init(void) +{ + for ( int32 i = 0; i < NUM_WATERCANNONS; i++ ) + aCannons[i].Init(); +} + +void CWaterCannons::UpdateOne(uint32 id, CVector *pos, CVector *dir) +{ + ASSERT(pos != NULL); + ASSERT(dir != NULL); + + // find the one by id + { + int32 n = 0; + while ( n < NUM_WATERCANNONS && id != aCannons[n].m_nId ) + n++; + + if ( n < NUM_WATERCANNONS ) + { + aCannons[n].Update_NewInput(pos, dir); + return; + } + } + + // if no luck then find a free one + { + int32 n = 0; + while ( n < NUM_WATERCANNONS && 0 != aCannons[n].m_nId ) + n++; + + if ( n < NUM_WATERCANNONS ) + { + aCannons[n].Init(); + aCannons[n].m_nId = id; + aCannons[n].Update_NewInput(pos, dir); + return; + } + } +} + +void CWaterCannons::Update(void) +{ + for ( int32 i = 0; i < NUM_WATERCANNONS; i++ ) + { + if ( aCannons[i].m_nId != 0 ) + aCannons[i].Update_OncePerFrame(i); + } +} + +void CWaterCannons::Render(void) +{ + PUSH_RENDERGROUP("CWaterCannons::Render"); + for ( int32 i = 0; i < NUM_WATERCANNONS; i++ ) + { + if ( aCannons[i].m_nId != 0 ) + aCannons[i].Render(); + } + POP_RENDERGROUP(); +} diff --git a/src/renderer/WaterCannon.h b/src/renderer/WaterCannon.h new file mode 100644 index 00000000..a37bdd12 --- /dev/null +++ b/src/renderer/WaterCannon.h @@ -0,0 +1,39 @@ +#pragma once + +#define WATERCANNON_GRAVITY (0.009f) +#define WATERCANNON_LIFETIME (150) + +class CWaterCannon +{ +public: + enum + { + NUM_SEGMENTPOINTS = 16, + }; + + int32 m_nId; + int16 m_nCur; + uint32 m_nTimeCreated; + CVector m_avecPos[NUM_SEGMENTPOINTS]; + CVector m_avecVelocity[NUM_SEGMENTPOINTS]; + bool m_abUsed[NUM_SEGMENTPOINTS]; + + void Init(void); + void Update_OncePerFrame(int16 index); + void Update_NewInput(CVector *pos, CVector *dir); + void Render(void); + void PushPeds(void); +}; + +VALIDATE_SIZE(CWaterCannon, 412); + +class CWaterCannons +{ +public: + static CWaterCannon aCannons[NUM_WATERCANNONS]; + + static void Init(void); + static void UpdateOne(uint32 id, CVector *pos, CVector *dir); + static void Update(); + static void Render(void); +}; \ No newline at end of file diff --git a/src/renderer/WaterCreatures.cpp b/src/renderer/WaterCreatures.cpp new file mode 100644 index 00000000..92fb74ee --- /dev/null +++ b/src/renderer/WaterCreatures.cpp @@ -0,0 +1,275 @@ +#include "common.h" +#include "WaterCreatures.h" +#include "ModelIndices.h" +#include "World.h" +#include "WaterLevel.h" +#include "Camera.h" +#include "PlayerPed.h" +#include "General.h" +#include "Object.h" + +int CWaterCreatures::nNumActiveSeaLifeForms; +CWaterCreature CWaterCreatures::aWaterCreatures[NUM_WATER_CREATURES]; + +struct WaterCreatureProperties aProperties[65] = { + { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_JELLYFISH, 0.01f, 2.2f, 0.0005f, 3.5f }, + { &MI_JELLYFISH01, 0.01f, 2.2f, 0.0005f, 3.5f }, + { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_TURTLE, 0.01f, 2.0f, 0.0005f, 4.0f }, + { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_DOLPHIN, 0.03f, 1.5f, 0.0005f, 4.0f }, + { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_SHARK, 0.03f, 0.4f, 0.0005f, 4.0f }, + { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH1SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH2SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH2S, 0.04f, 1.5f, 0.0008f, 3.0f }, + { &MI_FISH3SINGLE, 0.04f, 1.0f, 0.0008f, 3.0f }, + { &MI_FISH3S, 0.04f, 1.5f, 0.0008f, 3.0f }, +}; + +CWaterCreature::CWaterCreature() { + Free(); +} + +void CWaterCreature::Initialise(CObject *pObj, float fFwdSpeed, float fZTurnSpeed, float fWaterDepth, uint32 alpha, eFishSlotState state) { + this->m_pObj = pObj; + this->m_fFwdSpeed = fFwdSpeed; + this->m_fZTurnSpeed = fZTurnSpeed; + this->m_fWaterDepth = fWaterDepth; + this->m_alpha = alpha; + this->m_state = state; +} + +void CWaterCreature::Allocate(CObject *pObj, float fFwdSpeed, float fZTurnSpeed, float fWaterDepth, uint32 alpha, eFishSlotState state) { + CWaterCreature::Initialise(pObj, fFwdSpeed, fZTurnSpeed, fWaterDepth, alpha, state); +} + +void CWaterCreature::Free() { + CWaterCreature::Initialise(nil, 0.0f, 0.0f, 0.0f, 0, WATER_CREATURE_DISABLED); +} + +CWaterCreature *CWaterCreatures::GetFishStructSlot() { + for (int i = 0; i < NUM_WATER_CREATURES; i++) + if (aWaterCreatures[i].m_state == WATER_CREATURE_DISABLED) + return &aWaterCreatures[i]; + + return nil; +} + +CObject *CWaterCreatures::CreateSeaLifeForm(CVector const& pos, int16 modelID, int32 zRotAngle) { + if (CObject::nNoTempObjects >= NUMTEMPOBJECTS) + return nil; + + CObject *pObj = new CObject(modelID, true); + + if (!pObj) return nil; + + pObj->SetPosition(pos); + pObj->GetMatrix().UpdateRW(); + pObj->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f); + pObj->m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); + pObj->GetMatrix().SetRotateZOnly(DEGTORAD(zRotAngle)); + pObj->GetMatrix().UpdateRW(); + pObj->ObjectCreatedBy = CONTROLLED_SUB_OBJECT; + pObj->bIsStatic = false; + + if (pObj->ObjectCreatedBy == TEMP_OBJECT) { + CObject::nNoTempObjects++; + pObj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 60000; + } + + pObj->bTouchingWater = true; + pObj->bUnderwater = true; + CWorld::Add(pObj); + + return pObj; +} + +bool CWaterCreatures::IsSpaceForMoreWaterCreatures() { + return nNumActiveSeaLifeForms < NUM_WATER_CREATURES; +} + +float CWaterCreatures::CalculateFishHeading(CVector const& pos1, CVector const& pos2) { + CVector delta = pos1 - pos2; + delta.Normalise(); + + return CGeneral::GetRandomNumberInRange(-90, 90) + + RADTODEG(delta.Heading() + HALFPI + PI); +} + +void CWaterCreatures::CreateOne(CVector const& pos, int32 modelID) { + if (!IsSpaceForMoreWaterCreatures()) + return; + + CVector playerPos = FindPlayerPed()->GetPosition(); + CVector fishPos = pos; + float fDepth, fLevelNoWaves; + if (!TheCamera.IsSphereVisible(fishPos, 3.0f) + && CWaterLevel::GetWaterDepth(fishPos, &fDepth, &fLevelNoWaves, nil) && fDepth > 4.5f) { + + if (modelID == -1 || modelID < 0 || modelID > 64) + modelID = CGeneral::GetRandomNumberInRange(0, 64); + + WaterCreatureProperties *creature = &aProperties[modelID]; + fishPos.z = fLevelNoWaves - creature->fLevel; + float fFwdSpeed = CGeneral::GetRandomNumberInRange(0.0f, creature->fFwdSpeed) + 0.01f; + float angle = CWaterCreatures::CalculateFishHeading(playerPos, fishPos); + + CObject *fish = CreateSeaLifeForm(fishPos, *creature->modelID, angle); + if (!fish) return; + + fish->SetRwObjectAlpha(255); + CWaterCreature *wc = GetFishStructSlot(); + wc->Allocate(fish, fFwdSpeed, 0.0f, creature->fWaterDepth, 255, WATER_CREATURE_INIT); + nNumActiveSeaLifeForms++; + } +} + +void CWaterCreatures::FreeFishStructSlot(CWaterCreature *wc) { + wc->Free(); +} + +void CWaterCreatures::UpdateAll() { + if (nNumActiveSeaLifeForms == 0) + return; + + CVector playerPos = FindPlayerPed()->GetPosition(); + for (int i = 0; i < NUM_WATER_CREATURES; i++) { + switch (aWaterCreatures[i].m_state) { + case WATER_CREATURE_ACTIVE: + // is this even reachable? + aWaterCreatures[i].m_pObj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 40000; + if (!aWaterCreatures[i].m_pObj->GetIsOnScreen()) { + aWaterCreatures[i].m_pObj->SetRwObjectAlpha(0); + aWaterCreatures[i].m_state = WATER_CREATURE_REMOVE; + break; + } + // fall through + case WATER_CREATURE_INIT: { + if ((playerPos - aWaterCreatures[i].m_pObj->GetPosition()).MagnitudeSqr() < SQR(75.0f)) { + if (aWaterCreatures[i].m_alpha < 255) + aWaterCreatures[i].m_alpha = Min(aWaterCreatures[i].m_alpha + 4, 255); + aWaterCreatures[i].m_pObj->SetRwObjectAlpha(aWaterCreatures[i].m_alpha); + CVector fwd = aWaterCreatures[i].m_pObj->GetRight(); // for some reason they used x for forward + fwd.Normalise(); + aWaterCreatures[i].m_pObj->m_vecMoveSpeed = fwd * aWaterCreatures[i].m_fFwdSpeed; + aWaterCreatures[i].m_pObj->m_vecTurnSpeed = CVector(0.0f, 0.0f, aWaterCreatures[i].m_fZTurnSpeed); + aWaterCreatures[i].m_pObj->bIsStatic = false; + float fDepth = 0.0; + CWaterLevel::GetWaterDepth(aWaterCreatures[i].m_pObj->GetPosition(), &fDepth, nil, nil); + if (aWaterCreatures[i].m_fWaterDepth < fDepth) { + // it looks like this can never be true initially, looks like a BUG + if (aWaterCreatures[i].m_pObj->m_nEndOfLifeTime - 40000 <= CTimer::GetTimeInMilliseconds()) + aWaterCreatures[i].m_state = WATER_CREATURE_ACTIVE; + } + else { + // creature is deeper than water + aWaterCreatures[i].m_state = WATER_CREATURE_FADE_OUT; + } + + } + else { + aWaterCreatures[i].m_state = WATER_CREATURE_REMOVE; + } + break; + } + case WATER_CREATURE_FADE_OUT: { + aWaterCreatures[i].m_pObj->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 40000; + if (aWaterCreatures[i].m_alpha <= 0) { + aWaterCreatures[i].m_state = WATER_CREATURE_REMOVE; + } + else { + aWaterCreatures[i].m_alpha = Max(aWaterCreatures[i].m_alpha - 6, 0); + aWaterCreatures[i].m_pObj->SetRwObjectAlpha(aWaterCreatures[i].m_alpha); + CVector speed = aWaterCreatures[i].m_pObj->GetRight(); + speed.Normalise(); + speed.x *= aWaterCreatures[i].m_fFwdSpeed; + speed.y *= aWaterCreatures[i].m_fFwdSpeed; + speed.z = -0.015f; + aWaterCreatures[i].m_pObj->m_vecMoveSpeed = speed; + + if (!aWaterCreatures[i].m_pObj->GetIsOnScreen()) + aWaterCreatures[i].m_state = WATER_CREATURE_REMOVE; + } + break; + } + case WATER_CREATURE_REMOVE: + if (aWaterCreatures[i].m_pObj){ + CWorld::Remove(aWaterCreatures[i].m_pObj); + delete aWaterCreatures[i].m_pObj; + } + FreeFishStructSlot(&aWaterCreatures[i]); + nNumActiveSeaLifeForms--; + aWaterCreatures[i].m_state = WATER_CREATURE_DISABLED; + break; + default: + break; + } + } +} + +void CWaterCreatures::RemoveAll() { + for (int i = 0; i < NUM_WATER_CREATURES; i++) { + if (aWaterCreatures[i].m_state != WATER_CREATURE_DISABLED) { + if (aWaterCreatures[i].m_pObj){ + CWorld::Remove(aWaterCreatures[i].m_pObj); + delete aWaterCreatures[i].m_pObj; + } + FreeFishStructSlot(&aWaterCreatures[i]); + aWaterCreatures[i].m_state = WATER_CREATURE_DISABLED; + nNumActiveSeaLifeForms--; + } + } +} \ No newline at end of file diff --git a/src/renderer/WaterCreatures.h b/src/renderer/WaterCreatures.h new file mode 100644 index 00000000..32754a10 --- /dev/null +++ b/src/renderer/WaterCreatures.h @@ -0,0 +1,49 @@ +#pragma once + +class CObject; + +enum eFishSlotState { + WATER_CREATURE_INIT = 0, + WATER_CREATURE_ACTIVE, + WATER_CREATURE_FADE_OUT, + WATER_CREATURE_REMOVE, + WATER_CREATURE_DISABLED +}; + +class CWaterCreature { +public: + CObject *m_pObj; + float m_fFwdSpeed; + float m_fZTurnSpeed; + int32 m_alpha; + float m_fWaterDepth; + int32 m_state; + + CWaterCreature(); + void Allocate(CObject *pObj, float fFwdSpeed, float fZTurnSpeed, float fWaterDepth, uint32 alpha, eFishSlotState state); + void Free(); + void Initialise(CObject *pObj, float fFwdSpeed, float fZTurnSpeed, float fWaterDepth, uint32 alpha, eFishSlotState state); +}; + +class CWaterCreatures { + +public: + static CWaterCreature aWaterCreatures[NUM_WATER_CREATURES]; + static int32 nNumActiveSeaLifeForms; + static CObject *CreateSeaLifeForm(CVector const& pos, int16 modelID, int32 zRotAngle); + static void CreateOne(CVector const& pos, int32 modelID); + static void UpdateAll(); + static void FreeFishStructSlot(CWaterCreature *wc); + static bool IsSpaceForMoreWaterCreatures(); + static float CalculateFishHeading(CVector const& pos1, CVector const& pos2); + static void RemoveAll(); + static CWaterCreature* GetFishStructSlot(); +}; + +struct WaterCreatureProperties { + int16 *modelID; + float fFwdSpeed; + float fLevel; + float fUnknown; //unused + float fWaterDepth; +}; \ No newline at end of file diff --git a/src/renderer/WaterLevel.cpp b/src/renderer/WaterLevel.cpp new file mode 100644 index 00000000..dee60d66 --- /dev/null +++ b/src/renderer/WaterLevel.cpp @@ -0,0 +1,3377 @@ +#include "common.h" +#include "main.h" +#include "FileMgr.h" +#include "FileLoader.h" +#include "TxdStore.h" +#include "Timer.h" +#include "Weather.h" +#include "Camera.h" +#include "Vehicle.h" +#include "PlayerPed.h" +#include "Boat.h" +#include "World.h" +#include "General.h" +#include "Timecycle.h" +#include "ZoneCull.h" +#include "Clock.h" +#include "Particle.h" +#include "ParticleMgr.h" +#include "RwHelper.h" +#include "Streaming.h" +#include "ColStore.h" +#include "CdStream.h" +#include "Pad.h" +#include "RenderBuffer.h" +#include +#include +#include +#include "Occlusion.h" +#include "Replay.h" +#include "WaterLevel.h" +#include "SurfaceTable.h" +#include "WaterCreatures.h" + +#define RwIm3DVertexSet_RGBA(vert, rgba) RwIm3DVertexSetRGBA(vert, rgba.red, rgba.green, rgba.blue, rgba.alpha) // (RwRGBAAssign(&(_dst)->color, &_src)) + +float TEXTURE_ADDU; +float TEXTURE_ADDV; + +float _TEXTURE_MASK_ADDU; +float _TEXTURE_MASK_ADDV; + +float _TEXTURE_WAKE_ADDU; +float _TEXTURE_WAKE_ADDV; + +int32 CWaterLevel::ms_nNoOfWaterLevels; +float CWaterLevel::ms_aWaterZs[48]; +CRect CWaterLevel::ms_aWaterRects[48]; +int8 CWaterLevel::aWaterBlockList[MAX_LARGE_SECTORS][MAX_LARGE_SECTORS]; +int8 CWaterLevel::aWaterFineBlockList[MAX_SMALL_SECTORS][MAX_SMALL_SECTORS]; +bool CWaterLevel::WavesCalculatedThisFrame; + + +bool CWaterLevel::RequireWavySector; +bool CWaterLevel::MaskCalculatedThisFrame; +CVector CWaterLevel::PreCalculatedMaskPosn; +bool CWaterLevel::m_bRenderSeaBed; +int32 CWaterLevel::m_nRenderWaterLayers; + +RpAtomic *CWaterLevel::ms_pWavyAtomic; +RpAtomic *CWaterLevel::ms_pMaskAtomic; +//"Custom" Don't Render Water Toggle +bool gbDontRenderWater; + + +RwTexture *gpWaterTex; +RwTexture *gpWaterEnvTex; +RwTexture *gpWaterEnvBaseTex; +RwTexture *gpWaterWakeTex; + +RwRaster *gpWaterRaster; +RwRaster *gpWaterEnvRaster; +RwRaster *gpWaterEnvBaseRaster; +RwRaster *gpWaterWakeRaster; + +bool _bSeaLife; +float _fWaterZOffset = WATER_Z_OFFSET; + +#ifdef PC_WATER +float fEnvScale = 0.25f; +#else +float fEnvScale = 0.5f; +#endif +float fWave2InvLength = 0.03f; +float fWave2NormScale = 0.5f; +float fWave2Ampl = 0.1f; +uint8 nWaterAlpha = 192; +uint8 nWakeAlpha = 192; +float fUnder1 = 4.0; +float fUnder2 = 2.5; +float fUnder3 = 1.5; +int nMaskAlpha = 230; +float fAdd1 = 180.0f; +float fAdd2 = 80.0; +float fRedMult = 0.6f; +float fGreenMult = 1.0f; +float fBlueMult = 1.4f; +float fAlphaMult = 500.0f; +float fAlphaBase = 30.0f; +float fRandomMoveDiv = 8.0f; +float fRandomDamp = 0.99f; +float fNormMult = 2.0f; +float fNormMultB = 1.0f; +float fBumpScale = 1.5; +float fBumpTexRepeat = 2.0; +float fNormalDirectionScalar1 = 2.0f; +float fNormalDirectionScalar2 = 1.0f; +bool bTestDoNormals = true; +float fSeaBedZ = 25.0f; +float aAlphaFade[5] = { 0.4f, 1.0f, 0.2f, 1.0f, 0.4f}; //CWaterLevel::RenderWakeSegment +float fFlatWaterBlendRange = 0.05f; +float fStartBlendDistanceAdd = 64.0f; +float fMinWaterAlphaMult = -30.0f; + + +void +CWaterLevel::Initialise(Const char *pWaterDat) +{ + ms_nNoOfWaterLevels = 0; + +#ifdef MASTER + int32 hFile = -1; + + do + { + hFile = CFileMgr::OpenFile("DATA\\waterpro.dat", "rb"); + } + while ( hFile < 0 ); +#else + int32 hFile = CFileMgr::OpenFile("DATA\\waterpro.dat", "rb"); +#endif + + if (hFile > 0) + { + CFileMgr::Read(hFile, (char *)&ms_nNoOfWaterLevels, sizeof(ms_nNoOfWaterLevels)); + CFileMgr::Read(hFile, (char *)ms_aWaterZs, sizeof(ms_aWaterZs)); + CFileMgr::Read(hFile, (char *)ms_aWaterRects, sizeof(ms_aWaterRects)); + CFileMgr::Read(hFile, (char *)aWaterBlockList, sizeof(aWaterBlockList)); + CFileMgr::Read(hFile, (char *)aWaterFineBlockList, sizeof(aWaterFineBlockList)); + CFileMgr::CloseFile(hFile); + } +#ifndef MASTER + else + { + printf("Init waterlevels\n"); + + // collision is streamed in VC + CColStore::LoadAllCollision(); + + CFileMgr::SetDir(""); + hFile = CFileMgr::OpenFile(pWaterDat, "r"); + + char *line; + + while ((line = CFileLoader::LoadLine(hFile))) + { + if (*line && *line != ';' && !strstr(line, "* ;end of file")) + { + float z, l, b, r, t; + sscanf(line, "%f %f %f %f %f", &z, &l, &b, &r, &t); + AddWaterLevel(l, b, r, t, z); + } + } + + CFileMgr::CloseFile(hFile); + + for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) + { + for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) + { + aWaterFineBlockList[x][y] = NO_WATER; + } + } + + // rasterize water rects read from file + for (int32 i = 0; i < ms_nNoOfWaterLevels; i++) + { + int32 l = WATER_HUGE_X(ms_aWaterRects[i].left + WATER_X_OFFSET); + int32 r = WATER_HUGE_X(ms_aWaterRects[i].right + WATER_X_OFFSET) + 1.0f; + int32 t = WATER_HUGE_Y(ms_aWaterRects[i].top); + int32 b = WATER_HUGE_Y(ms_aWaterRects[i].bottom) + 1.0f; + + l = Clamp(l, 0, MAX_SMALL_SECTORS - 1); + r = Clamp(r, 0, MAX_SMALL_SECTORS - 1); + t = Clamp(t, 0, MAX_SMALL_SECTORS - 1); + b = Clamp(b, 0, MAX_SMALL_SECTORS - 1); + + for (int32 x = l; x <= r; x++) + { + for (int32 y = t; y <= b; y++) + { + aWaterFineBlockList[x][y] = i; + } + } + } + + // remove tiles that are obscured by land + for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) + { + float worldX = WATER_START_X + x * SMALL_SECTOR_SIZE - WATER_X_OFFSET; + + for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) + { + if (CWaterLevel::aWaterFineBlockList[x][y] >= 0) + { + float worldY = WATER_START_Y + y * SMALL_SECTOR_SIZE; + + int32 i; + for (i = 0; i <= 8; i++) + { + for (int32 j = 0; j <= 8; j++) + { + CVector worldPos = CVector(worldX + i * (SMALL_SECTOR_SIZE / 8), worldY + j * (SMALL_SECTOR_SIZE / 8), ms_aWaterZs[aWaterFineBlockList[x][y]]); + + if ((worldPos.x > WORLD_MIN_X && worldPos.x < WORLD_MAX_X) && (worldPos.y > WORLD_MIN_Y && worldPos.y < WORLD_MAX_Y) && + (!WaterLevelAccordingToRectangles(worldPos.x, worldPos.y) || TestVisibilityForFineWaterBlocks(worldPos))) + continue; + + // at least one point in the tile wasn't blocked, so don't remove water + i = 1000; + break; + } + } + + if (i < 1000) + aWaterFineBlockList[x][y] = NO_WATER; + } + } + } + + RemoveIsolatedWater(); + + // calculate coarse tiles from fine tiles + for (int32 x = 0; x < MAX_LARGE_SECTORS; x++) + { + for (int32 y = 0; y < MAX_LARGE_SECTORS; y++) + { + if (aWaterFineBlockList[x * 2][y * 2] >= 0) + { + aWaterBlockList[x][y] = aWaterFineBlockList[x * 2][y * 2]; + } + else if (aWaterFineBlockList[x * 2 + 1][y * 2] >= 0) + { + aWaterBlockList[x][y] = aWaterFineBlockList[x * 2 + 1][y * 2]; + } + else if (aWaterFineBlockList[x * 2][y * 2 + 1] >= 0) + { + aWaterBlockList[x][y] = aWaterFineBlockList[x * 2][y * 2 + 1]; + } + else if (aWaterFineBlockList[x * 2 + 1][y * 2 + 1] >= 0) + { + aWaterBlockList[x][y] = aWaterFineBlockList[x * 2 + 1][y * 2 + 1]; + } + else + { + aWaterBlockList[x][y] = NO_WATER; + } + } + } + + hFile = CFileMgr::OpenFileForWriting("data\\waterpro.dat"); + + if (hFile > 0) + { + CFileMgr::Write(hFile, (char *)&ms_nNoOfWaterLevels, sizeof(ms_nNoOfWaterLevels)); + CFileMgr::Write(hFile, (char *)ms_aWaterZs, sizeof(ms_aWaterZs)); + CFileMgr::Write(hFile, (char *)ms_aWaterRects, sizeof(ms_aWaterRects)); + CFileMgr::Write(hFile, (char *)aWaterBlockList, sizeof(aWaterBlockList)); + CFileMgr::Write(hFile, (char *)aWaterFineBlockList, sizeof(aWaterFineBlockList)); + + CFileMgr::CloseFile(hFile); + } + + // collision is streamed in VC + CColStore::RemoveAllCollision(); + } +#endif + + CTxdStore::PushCurrentTxd(); + + int32 slot = CTxdStore::FindTxdSlot("particle"); + CTxdStore::SetCurrentTxd(slot); + + if ( gpWaterTex == nil ) + gpWaterTex = RwTextureRead("waterclear256", nil); + gpWaterRaster = RwTextureGetRaster(gpWaterTex); + + if ( gpWaterEnvTex == nil ) + gpWaterEnvTex = RwTextureRead("waterreflection2", nil); + gpWaterEnvRaster = RwTextureGetRaster(gpWaterEnvTex); + +#ifdef PC_WATER + if ( gpWaterEnvBaseTex == nil ) + gpWaterEnvBaseTex = RwTextureRead("sandywater", nil); + gpWaterEnvBaseRaster = RwTextureGetRaster(gpWaterEnvBaseTex); +#endif + + if ( gpWaterWakeTex == nil ) + gpWaterWakeTex = RwTextureRead("waterwake", nil); + gpWaterWakeRaster = RwTextureGetRaster(gpWaterWakeTex); + + CTxdStore::PopCurrentTxd(); + + CreateWavyAtomic(); + + printf("Done Initing waterlevels\n"); +} + +void +CWaterLevel::Shutdown() +{ + DestroyWavyAtomic(); + +#define _DELETE_TEXTURE(t) if ( t ) \ + { \ + RwTextureDestroy(t); \ + t = nil; \ + } + + _DELETE_TEXTURE(gpWaterTex); + _DELETE_TEXTURE(gpWaterEnvTex); + _DELETE_TEXTURE(gpWaterWakeTex); + _DELETE_TEXTURE(gpWaterEnvBaseTex); + +#undef _DELETE_TEXTURE +} + +void +CWaterLevel::CreateWavyAtomic() +{ + RpGeometry *wavyGeometry; + RpGeometry *maskGeometry; + RpMaterial *wavyMaterial; + RpMaterial *maskMaterial; + + RpTriangle *wavytlist; + RpTriangle *masktlist; + + RpMorphTarget *wavyMorphTarget; + RpMorphTarget *maskMorphTarget; + + RwSphere boundingSphere; + + RwV3d *wavyVert; + RwV3d *wavyNormal; + + RwV3d *maskVert; + RwV3d *maskNormal; + + RwFrame *wavyFrame; + RwFrame *maskFrame; + + { + wavyGeometry = RpGeometryCreate(17*17, 512, rpGEOMETRYTRISTRIP + |rpGEOMETRYTEXTURED + |rpGEOMETRYPRELIT + |rpGEOMETRYNORMALS + |rpGEOMETRYMODULATEMATERIALCOLOR); +#ifdef PC_WATER + RpGeometryAddMorphTarget(wavyGeometry); +#endif + } + + { + maskGeometry = RpGeometryCreate(33*33, 2048, rpGEOMETRYTRISTRIP + |rpGEOMETRYTEXTURED + |rpGEOMETRYPRELIT + |rpGEOMETRYNORMALS + |rpGEOMETRYMODULATEMATERIALCOLOR); +#ifdef PC_WATER + RpGeometryAddMorphTarget(maskGeometry); +#endif + } + + { + wavyMaterial = RpMaterialCreate(); + RpMaterialSetTexture(wavyMaterial, gpWaterTex); + RwRGBA watercolor = { 255, 255, 255, 192 }; + RpMaterialSetColor(wavyMaterial, &watercolor); + } + + { + maskMaterial = RpMaterialCreate(); +#ifdef PC_WATER + RpMaterialSetTexture(maskMaterial, gpWaterEnvBaseTex); +#else + RpMaterialSetTexture(maskMaterial, gpWaterTex); +#endif + RwRGBA watercolor = { 255, 255, 255, 192 }; + RpMaterialSetColor(maskMaterial, &watercolor); + } + + { + wavytlist = RpGeometryGetTriangles(wavyGeometry); + + for ( int32 i = 0; i < 16; i++ ) + { + for ( int32 j = 0; j < 16; j++ ) + { + const RwUInt16 base = (RwUInt16)((16 + 1)*i+j); + + RpGeometryTriangleSetVertexIndices(wavyGeometry, + wavytlist, (RwInt16)base, (RwInt16)(base+1), (RwInt16)(base+16+2)); + + RpGeometryTriangleSetVertexIndices(wavyGeometry, + (wavytlist+1), (RwInt16)base, (RwInt16)(base+16+2), (RwInt16)(base+16+1)); + + RpGeometryTriangleSetMaterial(wavyGeometry, wavytlist, wavyMaterial); + + RpGeometryTriangleSetMaterial(wavyGeometry, (wavytlist+1), wavyMaterial); + + wavytlist+=2; + } + } + } + + { + masktlist = RpGeometryGetTriangles(maskGeometry); + + for ( int32 i = 0; i < 32; i++ ) + { + for ( int32 j = 0; j < 32; j++ ) + { + const RwUInt16 base = (RwUInt16)((32 + 1)*i+j); + + RpGeometryTriangleSetVertexIndices(maskGeometry, + masktlist, (RwInt16)base, (RwInt16)(base+1), (RwInt16)(base+32+2)); + + RpGeometryTriangleSetVertexIndices(maskGeometry, + (masktlist+1), (RwInt16)base, (RwInt16)(base+32+2), (RwInt16)(base+32+1)); + + RpGeometryTriangleSetMaterial(maskGeometry, masktlist, maskMaterial); + + RpGeometryTriangleSetMaterial(maskGeometry, (masktlist+1), maskMaterial); + + masktlist+=2; + } + } + } + + { + wavyMorphTarget = RpGeometryGetMorphTarget(wavyGeometry, 0); + wavyVert = RpMorphTargetGetVertices(wavyMorphTarget); + wavyNormal = RpMorphTargetGetVertexNormals(wavyMorphTarget); + + for ( int32 i = 0; i < 17; i++ ) + { + for ( int32 j = 0; j < 17; j++ ) + { + (*wavyVert).x = (float)i * 2.0f; + (*wavyVert).y = (float)j * 2.0f; + (*wavyVert).z = 0.0f; + + (*wavyNormal).x = 0.0f; + (*wavyNormal).y = 0.0f; + (*wavyNormal).z = 1.0f; + + wavyVert++; + wavyNormal++; + } + } + + RpMorphTargetCalcBoundingSphere(wavyMorphTarget, &boundingSphere); + RpMorphTargetSetBoundingSphere(wavyMorphTarget, &boundingSphere); + RpGeometryUnlock(wavyGeometry); + } + + { + maskMorphTarget = RpGeometryGetMorphTarget(maskGeometry, 0); + maskVert = RpMorphTargetGetVertices(maskMorphTarget); + maskNormal = RpMorphTargetGetVertexNormals(maskMorphTarget); + + for ( int32 i = 0; i < 33; i++ ) + { + for ( int32 j = 0; j < 33; j++ ) + { + (*maskVert).x = (float)i * 2.0f; + (*maskVert).y = (float)j * 2.0f; + (*maskVert).z = 0.0f; + + (*maskNormal).x = 0.0f; + (*maskNormal).y = 0.0f; + (*maskNormal).z = 1.0f; + + maskVert++; + maskNormal++; + } + } + + RpMorphTargetCalcBoundingSphere(maskMorphTarget, &boundingSphere); + RpMorphTargetSetBoundingSphere(maskMorphTarget, &boundingSphere); + RpGeometryUnlock(maskGeometry); + } + + { + wavyFrame = RwFrameCreate(); + ms_pWavyAtomic = RpAtomicCreate(); + RpAtomicSetGeometry(ms_pWavyAtomic, wavyGeometry, 0); + RpAtomicSetFrame(ms_pWavyAtomic, wavyFrame); + RpMaterialDestroy(wavyMaterial); + RpGeometryDestroy(wavyGeometry); + } + + { + maskFrame = RwFrameCreate(); + ms_pMaskAtomic = RpAtomicCreate(); + RpAtomicSetGeometry(ms_pMaskAtomic, maskGeometry, 0); + RpAtomicSetFrame(ms_pMaskAtomic, maskFrame); + RpMaterialDestroy(maskMaterial); + RpGeometryDestroy(maskGeometry); + } + + static RwFrame *wakeEnvFrame; + + if ( wakeEnvFrame == nil ) + { + wakeEnvFrame = RwFrameCreate(); + RwMatrixSetIdentity(RwFrameGetMatrix(wakeEnvFrame)); + RwFrameUpdateObjects(wakeEnvFrame); + } + + RpMatFXMaterialSetEffects(maskMaterial, rpMATFXEFFECTENVMAP); + RpMatFXMaterialSetupEnvMap(maskMaterial, gpWaterEnvTex, wakeEnvFrame, TRUE, fEnvScale); + RpMatFXAtomicEnableEffects(ms_pMaskAtomic); +} + +void +CWaterLevel::DestroyWavyAtomic() +{ +#define _DELETE_ATOMIC(a) \ + { \ + RwFrame *frame; \ + frame = RpAtomicGetFrame(a); \ + RpAtomicDestroy(a); \ + RwFrameDestroy(frame); \ + } + + _DELETE_ATOMIC(ms_pWavyAtomic); + _DELETE_ATOMIC(ms_pMaskAtomic); + +#undef _DELETE_ATOMIC +} + +#ifndef MASTER +void +CWaterLevel::AddWaterLevel(float fXLeft, float fYBottom, float fXRight, float fYTop, float fLevel) +{ + ms_aWaterRects[ms_nNoOfWaterLevels] = CRect(fXLeft, fYBottom, fXRight, fYTop); + ms_aWaterZs[ms_nNoOfWaterLevels] = fLevel; + ms_nNoOfWaterLevels++; +} + +bool +CWaterLevel::WaterLevelAccordingToRectangles(float fX, float fY, float *pfOutLevel) +{ + if (ms_nNoOfWaterLevels <= 0) return false; + + for (int32 i = 0; i < ms_nNoOfWaterLevels; i++) + { + if (fX >= ms_aWaterRects[i].left && fX <= ms_aWaterRects[i].right + && fY >= ms_aWaterRects[i].top && fY <= ms_aWaterRects[i].bottom) + { + if (pfOutLevel) *pfOutLevel = ms_aWaterZs[i]; + + return true; + } + } + + return false; +} + +bool +CWaterLevel::TestVisibilityForFineWaterBlocks(const CVector &worldPos) +{ + static CVector2D tab[] = + { + { 50.0f, 50.0f }, + { -50.0f, 50.0f }, + { -50.0f, -50.0f }, + { 50.0f, -50.0f }, + { 50.0f, 0.0f }, + { -50.0f, 0.0f }, + { 0.0f, -50.0f }, + { 0.0f, 50.0f }, + }; + + CEntity *entity; + CColPoint col; + CVector lineStart, lineEnd; + + lineStart = worldPos; + + if (!CWorld::ProcessVerticalLine(lineStart, lineStart.z + 100.0f, col, entity, true, false, false, false, true, false, nil)) + { + lineStart.x += 0.4f; + lineStart.y += 0.4f; + + if (!CWorld::ProcessVerticalLine(lineStart, lineStart.z + 100.0f, col, entity, true, false, false, false, true, false, nil)) + { + return false; + } + } + + for (int32 i = 0; i < ARRAY_SIZE(tab); i++) + { + lineStart = worldPos; + lineEnd = worldPos; + + lineEnd.x += tab[i].x; + lineEnd.y += tab[i].y; + lineEnd.z += 100.0f; + + if ((lineEnd.x > WORLD_MIN_X && lineEnd.x < WORLD_MAX_X) && (lineEnd.y > WORLD_MIN_Y && lineEnd.y < WORLD_MAX_Y)) + { + if (!CWorld::ProcessLineOfSight(lineStart, lineEnd, col, entity, true, false, false, false, true, false)) + { + lineStart.x += 0.4f; + lineStart.y += 0.4f; + lineEnd.x += 0.4f; + lineEnd.y += 0.4f; + + if (!CWorld::ProcessLineOfSight(lineStart, lineEnd, col, entity, true, false, false, false, true, false)) + { + return false; + } + } + } + } + + return true; +} + +void +CWaterLevel::RemoveIsolatedWater() +{ + bool (*isConnected)[MAX_SMALL_SECTORS] = new bool[MAX_SMALL_SECTORS][MAX_SMALL_SECTORS]; + + for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) + { + for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) + { + isConnected[x][y] = false; + } + } + + isConnected[0][0] = true; + bool keepGoing; + + do + { + keepGoing = false; + + for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) + { + for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) + { + if (aWaterFineBlockList[x][y] < 0 || isConnected[x][y]) + continue; + + if (x > 0 && isConnected[x - 1][y]) + { + isConnected[x][y] = true; + keepGoing = true; + } + + if (y > 0 && isConnected[x][y - 1]) + { + isConnected[x][y] = true; + keepGoing = true; + } + + if (x + 1 < MAX_SMALL_SECTORS && isConnected[x + 1][y]) + { + isConnected[x][y] = true; + keepGoing = true; + } + + if (y + 1 < MAX_SMALL_SECTORS && isConnected[x][y + 1]) + { + isConnected[x][y] = true; + keepGoing = true; + } + } + } + } + while (keepGoing); + + int32 numRemoved = 0; + + for (int32 x = 0; x < MAX_SMALL_SECTORS; x++) + { + for (int32 y = 0; y < MAX_SMALL_SECTORS; y++) + { + if (aWaterFineBlockList[x][y] >= 0 && !isConnected[x][y] && ms_aWaterZs[aWaterFineBlockList[x][y]] == 6.0f) + { + numRemoved++; + aWaterFineBlockList[x][y] = NO_WATER; + } + } + } + + printf("Removed %d isolated patches of water\n", numRemoved); + + delete[] isConnected; +} +#endif + +bool +CWaterLevel::GetWaterLevel(float fX, float fY, float fZ, float *pfOutLevel, bool bDontCheckZ) +{ + int32 x = WATER_TO_SMALL_SECTOR_X(fX + WATER_X_OFFSET); + int32 y = WATER_TO_SMALL_SECTOR_Y(fY); + +#ifdef FIX_BUGS + if ( x < 0 || x >= MAX_SMALL_SECTORS ) return false; + if ( y < 0 || y >= MAX_SMALL_SECTORS ) return false; +#endif + + int8 nBlock = aWaterFineBlockList[x][y]; + + if ( nBlock == NO_WATER ) + return false; + + ASSERT( pfOutLevel != nil ); + *pfOutLevel = ms_aWaterZs[nBlock]; + + float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); + + float fWave = Sin + ( + ( WATER_UNSIGN_Y(fY) - y*SMALL_SECTOR_SIZE + + WATER_UNSIGN_X(fX + WATER_X_OFFSET) - x*SMALL_SECTOR_SIZE ) + + * (TWOPI / SMALL_SECTOR_SIZE ) + fAngle + ); + + float fWindFactor = CWeather::WindClipped * 0.4f + 0.2f; + + *pfOutLevel += fWave * fWindFactor; + + if ( bDontCheckZ == false && (*pfOutLevel - fZ) > 3.0f ) + { + *pfOutLevel = 0.0f; + return false; + } + + return true; +} + +bool +CWaterLevel::GetWaterLevelNoWaves(float fX, float fY, float fZ, float *pfOutLevel) +{ + int32 x = WATER_TO_SMALL_SECTOR_X(fX + WATER_X_OFFSET); + int32 y = WATER_TO_SMALL_SECTOR_Y(fY); + +#ifdef FIX_BUGS + if ( x < 0 || x >= MAX_SMALL_SECTORS ) return false; + if ( y < 0 || y >= MAX_SMALL_SECTORS ) return false; +#endif + + int8 nBlock = aWaterFineBlockList[x][y]; + + if ( nBlock == NO_WATER ) + return false; + + ASSERT( pfOutLevel != nil ); + *pfOutLevel = ms_aWaterZs[nBlock]; + + return true; +} + +float +CWaterLevel::GetWaterWavesOnly(short x, short y) +{ + float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); + + float fWindFactor = CWeather::WindClipped * 0.7f + 0.3f; + + float fWave = Sin( float(float(4 * y + 4 * x) * (TWOPI / SMALL_SECTOR_SIZE )) + fAngle ); + + return fWave * fWindFactor; +} + +CVector +CWaterLevel::GetWaterNormal(float fX, float fY) +{ + //TODO: BUG ? no x offset + + int32 x = WATER_TO_SMALL_SECTOR_X(fX); + int32 y = WATER_TO_SMALL_SECTOR_Y(fY); + + float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); + float fWindFactor = CWeather::WindClipped * 0.4f + 0.2f; + + float _fWave = (WATER_UNSIGN_Y(fY) - y*SMALL_SECTOR_SIZE + WATER_UNSIGN_X(fX) - x*SMALL_SECTOR_SIZE) + * (TWOPI / SMALL_SECTOR_SIZE ) + fAngle; + + CVector vA(1.0f, 0.0f, fWindFactor * (TWOPI / SMALL_SECTOR_SIZE ) * Cos(_fWave)); + CVector vB(0.0f, 1.0f, fWindFactor * (TWOPI / SMALL_SECTOR_SIZE ) * Cos(_fWave)); + + CVector norm = CrossProduct(vA, vB); + + norm.Normalise(); + + return norm; +} + + +inline float +_GetWaterDrawDist() +{ + if ( TheCamera.GetPosition().z < 15.0f ) return 1200.0f; + if ( TheCamera.GetPosition().z > 60.0f ) return 2000.0f; + return ( TheCamera.GetPosition().z + -15.0f ) * 800.0f / 45.0f + 1200.0f; +} + +inline float +_GetWavyDrawDist() +{ + if ( FindPlayerVehicle() && FindPlayerVehicle()->IsBoat() ) + return 120.0f; + else + return 70.0f; +} + +inline void +_GetCamBounds(bool *bUseCamStartY, bool *bUseCamEndY, bool *bUseCamStartX, bool *bUseCamEndX) +{ + if ( TheCamera.GetForward().z > -0.8f ) + { + if ( Abs(TheCamera.GetForward().x) > Abs(TheCamera.GetForward().y) ) + { + if ( TheCamera.GetForward().x > 0.0f ) + *bUseCamStartX = true; + else + *bUseCamEndX = true; + } + else + { + if ( TheCamera.GetForward().y > 0.0f ) + *bUseCamStartY = true; + else + *bUseCamEndY = true; + } + } +} + + +inline bool +_IsColideWithBlock(int32 x, int32 y, int32 &block) +{ + block = CWaterLevel::aWaterFineBlockList[x + 0][y + 0]; + if (block >= 0) + return true; + + block = CWaterLevel::aWaterFineBlockList[x + 0][y + 1]; + if (block >= 0) + { + block = CWaterLevel::aWaterFineBlockList[x + 0][y + 2]; + if (block >= 0) + return true; + } + + block = CWaterLevel::aWaterFineBlockList[x + 1][y + 0]; + if (block >= 0) + return true; + + block = CWaterLevel::aWaterFineBlockList[x + 1][y + 1]; + if (block >= 0) + { + block = CWaterLevel::aWaterFineBlockList[x + 1][y + 2]; + if (block >= 0) + return true; + } + + block = CWaterLevel::aWaterFineBlockList[x + 2][y + 0]; + if (block >= 0) + return true; + + block = CWaterLevel::aWaterFineBlockList[x + 2][y + 1]; + if (block >= 0) + { + block = CWaterLevel::aWaterFineBlockList[x + 2][y + 2]; + if (block >= 0) + return true; + } + + return false; +} + +inline float +SectorRadius(float fSize) +{ + return Sqrt(Pow(fSize, 2) + Pow(fSize, 2)); +} + +void +CWaterLevel::RenderWater() +{ +//"Custom" Don't Render Water Toggle +#ifndef MASTER + if (gbDontRenderWater) + return; +#endif + bool bUseCamEndX = false; + bool bUseCamStartY = false; + + bool bUseCamStartX = false; + bool bUseCamEndY = false; + + if ( !CGame::CanSeeWaterFromCurrArea() ) + return; + + _GetCamBounds(&bUseCamStartY, &bUseCamEndY, &bUseCamStartX, &bUseCamEndX); + + float fHugeSectorMaxRenderDist = _GetWaterDrawDist(); + float fHugeSectorMaxRenderDistSqr = SQR(fHugeSectorMaxRenderDist); + + float windAddUV = CWeather::WindClipped * 0.0005f + 0.0006f; + + float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); + + if ( !CTimer::GetIsPaused() ) + { + TEXTURE_ADDU += windAddUV; + TEXTURE_ADDV += windAddUV; + + _TEXTURE_MASK_ADDU += Sin(fAngle) * 0.0005f + 1.1f * windAddUV; + _TEXTURE_MASK_ADDV -= Cos(fAngle * 1.3f) * 0.0005f + 1.2f * windAddUV; + + _TEXTURE_WAKE_ADDU -= Sin(fAngle) * 0.0003f + windAddUV; + _TEXTURE_WAKE_ADDV += Cos(fAngle * 0.7f) * 0.0003f + windAddUV; + } + + if ( _TEXTURE_MASK_ADDU >= 1.0f ) + _TEXTURE_MASK_ADDU = 0.0f; + if ( _TEXTURE_MASK_ADDV >= 1.0f ) + _TEXTURE_MASK_ADDV = 0.0f; + + if ( _TEXTURE_WAKE_ADDU >= 1.0f ) + _TEXTURE_WAKE_ADDU = 0.0f; + if ( _TEXTURE_WAKE_ADDV >= 1.0f ) + _TEXTURE_WAKE_ADDV = 0.0f; + + if ( TEXTURE_ADDU >= 1.0f ) + TEXTURE_ADDU = 0.0f; + if ( TEXTURE_ADDV >= 1.0f ) + TEXTURE_ADDV = 0.0f; + +#ifdef PC_WATER + _fWaterZOffset = CWeather::WindClipped * 0.5f + 0.25f; +#endif + + RwRGBA color = { 0, 0, 0, 255 }; + + color.red = CTimeCycle::GetWaterRed(); + color.green = CTimeCycle::GetWaterGreen(); + color.blue = CTimeCycle::GetWaterBlue(); + +#ifndef PC_WATER + RwRGBA colorUnderwater = { 0, 0, 0, 255 }; + colorUnderwater.red = (uint32)(0.8f * (float)colorUnderwater.red); + colorUnderwater.green = (uint32)(0.8f * (float)colorUnderwater.green); + colorUnderwater.blue = (uint32)(0.8f * (float)colorUnderwater.blue); +#endif + + TempBufferVerticesStored = 0; + TempBufferIndicesStored = 0; + +#ifndef PC_WATER + WavesCalculatedThisFrame = false; +#endif + + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterRaster); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO); + + CVector2D camPos(TheCamera.GetPosition().x, TheCamera.GetPosition().y); + + int32 nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x - fHugeSectorMaxRenderDist + WATER_X_OFFSET); + int32 nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + fHugeSectorMaxRenderDist + WATER_X_OFFSET) + 1; + int32 nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y - fHugeSectorMaxRenderDist); + int32 nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y + fHugeSectorMaxRenderDist) + 1; + + if ( bUseCamStartX ) + nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET); + if ( bUseCamEndX ) + nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET); + if ( bUseCamStartY ) + nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y); + if ( bUseCamEndY ) + nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y); + + nStartX = Clamp(nStartX, 0, MAX_HUGE_SECTORS - 1); + nEndX = Clamp(nEndX, 0, MAX_HUGE_SECTORS - 1); + nStartY = Clamp(nStartY, 0, MAX_HUGE_SECTORS - 1); + nEndY = Clamp(nEndY, 0, MAX_HUGE_SECTORS - 1); + + for ( int32 x = nStartX; x <= nEndX; x++ ) + { + for ( int32 y = nStartY; y <= nEndY; y++ ) + { + if ( aWaterBlockList[2*x+0][2*y+0] >= 0 + || aWaterBlockList[2*x+1][2*y+0] >= 0 + || aWaterBlockList[2*x+0][2*y+1] >= 0 + || aWaterBlockList[2*x+1][2*y+1] >= 0 ) + { + float fX = WATER_FROM_HUGE_SECTOR_X(x) - WATER_X_OFFSET; + float fY = WATER_FROM_HUGE_SECTOR_Y(y); + + CVector2D vecHugeSectorCentre(fX + HUGE_SECTOR_SIZE/2,fY + HUGE_SECTOR_SIZE/2); + + float fHugeSectorDistToCamSqr = (camPos - vecHugeSectorCentre).MagnitudeSqr(); + + if ( fHugeSectorMaxRenderDistSqr > fHugeSectorDistToCamSqr ) + { + if ( TheCamera.IsSphereVisible(CVector(vecHugeSectorCentre.x, vecHugeSectorCentre.y, 0.0f), SectorRadius(HUGE_SECTOR_SIZE)) ) + { +#ifndef PC_WATER + WavesCalculatedThisFrame = true; +#endif + + + float fZ; + + if ( aWaterBlockList[2*x+0][2*y+0] >= 0 ) + fZ = ms_aWaterZs[ aWaterBlockList[2*x+0][2*y+0] ]; + + if ( aWaterBlockList[2*x+1][2*y+0] >= 0 ) + fZ = ms_aWaterZs[ aWaterBlockList[2*x+1][2*y+0] ]; + + if ( aWaterBlockList[2*x+0][2*y+1] >= 0 ) + fZ = ms_aWaterZs[ aWaterBlockList[2*x+0][2*y+1] ]; + + if ( aWaterBlockList[2*x+1][2*y+1] >= 0 ) + fZ = ms_aWaterZs[ aWaterBlockList[2*x+1][2*y+1] ]; + + if ( fHugeSectorDistToCamSqr >= SQR(500.0f) ) + { + RenderOneFlatHugeWaterPoly(fX, fY, fZ, color); + } + else + { +#ifndef PC_WATER + if (m_bRenderSeaBed) + RenderOneSlopedUnderWaterPoly(fX, fY, fZ, colorUnderwater); +#endif + // see RenderTransparentWater() + ; + } + } + } + } + } + } + + /* + ----------- ---------------------- ---------------------- + | [N] | | [ EndY ] | | [ top ] | + | | | | | | + |[W] [0] [E]| |[StartX] [] [ EndX ]| |[ left ] [] [ right]| + | | | | | | + | [S] | | [StartY] | | [bottom] | + ----------- ---------------------- ---------------------- + + + [S] [StartY] [bottom] + [N] [EndY] [top] + [W] [StartX] [left] + [E] [EndX] [right] + + [S] -> [N] && [W] -> [E] + bottom -> top && left -> right + */ + + for ( int32 x = 0; x < 26; x++ ) + { + for ( int32 y = 0; y < 5; y++ ) + { + float fX = WATER_SIGN_X(float(x) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f - WATER_X_OFFSET; + float fY = WATER_SIGN_Y(float(y) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f; + + if ( !bUseCamStartY ) + { + CVector2D vecExtraHugeSectorCentre(fX + EXTRAHUGE_SECTOR_SIZE/2, fY + EXTRAHUGE_SECTOR_SIZE/2); + + float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude(); + + if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr ) + { + if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE)) ) + { + RenderOneFlatExtraHugeWaterPoly( + vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2, + vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2, + 0.0f, + color); + } + } + } + + if ( !bUseCamEndY ) + { + CVector2D vecExtraHugeSectorCentre(fX + EXTRAHUGE_SECTOR_SIZE/2, -(fY + EXTRAHUGE_SECTOR_SIZE/2)); + + float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude(); + + if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr ) + { + if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE)) ) + { + RenderOneFlatExtraHugeWaterPoly( + vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2, + vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2, + 0.0f, + color); + } + } + } + } + } + + for ( int32 y = 5; y < 21; y++ ) + { + for ( int32 x = 0; x < 5; x++ ) + { + float fX = WATER_SIGN_X(float(x) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f - WATER_X_OFFSET; + float fX2 = WATER_SIGN_X(float(x) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f + WATER_X_OFFSET; + float fY = WATER_SIGN_Y(float(y) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f; + + if ( !bUseCamStartX ) + { + CVector2D vecExtraHugeSectorCentre(fX + EXTRAHUGE_SECTOR_SIZE/2, fY + EXTRAHUGE_SECTOR_SIZE/2); + + float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude(); + + if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr ) + { + if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE)) ) + { + RenderOneFlatExtraHugeWaterPoly( + vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2, + vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2, + 0.0f, + color); + } + } + } + + if ( !bUseCamEndX ) + { + CVector2D vecExtraHugeSectorCentre(-(fX2 + EXTRAHUGE_SECTOR_SIZE/2), fY + EXTRAHUGE_SECTOR_SIZE/2); + + float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude(); + + if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr ) + { + if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.x, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE)) ) + { + RenderOneFlatExtraHugeWaterPoly( + vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2, + vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2, + 0.0f, + color); + } + } + } + } + } + + RenderAndEmptyRenderBuffer(); + + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); + + if ( WavesCalculatedThisFrame ) + { + RenderSeaBirds(); + RenderShipsOnHorizon(); + CParticle::HandleShipsAtHorizonStuff(); + HandleBeachToysStuff(); + } + + if ( _bSeaLife ) + HandleSeaLifeForms(); + + DefinedState(); +} + + +void +CWaterLevel::RenderTransparentWater(void) +{ + bool bUseCamEndX = false; + bool bUseCamStartY = false; + + bool bUseCamStartX = false; + bool bUseCamEndY = false; + + _bSeaLife = false; + + if ( !CGame::CanSeeWaterFromCurrArea() ) + return; + + PUSH_RENDERGROUP("CWaterLevel::RenderTransparentWater"); + + float fWaterDrawDist = _GetWavyDrawDist(); + float fWaterDrawDistLarge = fWaterDrawDist + 90.0f; + float fWavySectorMaxRenderDistSqr = SQR(fWaterDrawDist); + + _GetCamBounds(&bUseCamStartY, &bUseCamEndY, &bUseCamStartX, &bUseCamEndX); + + float fHugeSectorMaxRenderDist = _GetWaterDrawDist(); + float fHugeSectorMaxRenderDistSqr = SQR(fHugeSectorMaxRenderDist); + + RenderBoatWakes(); + + RwRGBA color; + + color.red = CTimeCycle::GetWaterRed(); + color.green = CTimeCycle::GetWaterGreen(); + color.blue = CTimeCycle::GetWaterBlue(); + color.alpha = 255; + + RwRGBA colorTrans; + + colorTrans.red = CTimeCycle::GetWaterRed(); + colorTrans.green = CTimeCycle::GetWaterGreen(); + colorTrans.blue = CTimeCycle::GetWaterBlue(); + colorTrans.alpha = CTimeCycle::GetWaterAlpha(); + + TempBufferVerticesStored = 0; + TempBufferIndicesStored = 0; + +#ifndef PC_WATER + WavesCalculatedThisFrame = false; +#endif + + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterRaster); +#ifndef PC_WATER + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); +#endif + + CVector2D camPos(TheCamera.GetPosition().x, TheCamera.GetPosition().y); + + int32 nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x - fHugeSectorMaxRenderDist + WATER_X_OFFSET); + int32 nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + fHugeSectorMaxRenderDist + WATER_X_OFFSET) + 1; + int32 nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y - fHugeSectorMaxRenderDist ); + int32 nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y + fHugeSectorMaxRenderDist ) + 1; + + if ( bUseCamStartX ) + nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET); + if ( bUseCamEndX ) + nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET); + if ( bUseCamStartY ) + nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y ); + if ( bUseCamEndY ) + nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y ); + + nStartX = Clamp(nStartX, 0, MAX_HUGE_SECTORS - 1); + nEndX = Clamp(nEndX, 0, MAX_HUGE_SECTORS - 1); + nStartY = Clamp(nStartY, 0, MAX_HUGE_SECTORS - 1); + nEndY = Clamp(nEndY, 0, MAX_HUGE_SECTORS - 1); + + + for ( int32 x = nStartX; x <= nEndX; x++ ) + { + for ( int32 y = nStartY; y <= nEndY; y++ ) + { + if ( aWaterBlockList[2*x+0][2*y+0] >= 0 + || aWaterBlockList[2*x+1][2*y+0] >= 0 + || aWaterBlockList[2*x+0][2*y+1] >= 0 + || aWaterBlockList[2*x+1][2*y+1] >= 0 ) + { + float fX = WATER_FROM_HUGE_SECTOR_X(x) - WATER_X_OFFSET; + float fY = WATER_FROM_HUGE_SECTOR_Y(y); + + CVector2D vecHugeSectorCentre + ( + fX + HUGE_SECTOR_SIZE/2, + fY + HUGE_SECTOR_SIZE/2 + ); + + float fHugeSectorDistToCamSqr = (camPos - vecHugeSectorCentre).MagnitudeSqr(); + + if ( fHugeSectorMaxRenderDistSqr > fHugeSectorDistToCamSqr ) + { + if ( TheCamera.IsSphereVisible(CVector(vecHugeSectorCentre.x, vecHugeSectorCentre.y, 0.0f), SectorRadius(HUGE_SECTOR_SIZE)) ) + { + if ( fHugeSectorDistToCamSqr >= SQR(500.0f) ) + { + // see RenderWater() + ; + } + else + { + for ( int32 x2 = 2*x; x2 <= 2*x+1; x2++ ) + { + for ( int32 y2 = 2*y; y2 <= 2*y+1; y2++ ) + { + if ( aWaterBlockList[x2][y2] >= 0 ) + { + float fLargeX = WATER_FROM_LARGE_SECTOR_X(x2) - WATER_X_OFFSET; + float fLargeY = WATER_FROM_LARGE_SECTOR_Y(y2); + + CVector2D vecLargeSectorCentre(fLargeX + LARGE_SECTOR_SIZE/2, fLargeY + LARGE_SECTOR_SIZE/2); + + float fLargeSectorDistToCamSqr = (camPos - vecLargeSectorCentre).MagnitudeSqr(); + + if ( fLargeSectorDistToCamSqr < fHugeSectorMaxRenderDistSqr ) + { + if ( TheCamera.IsSphereVisible(CVector(vecLargeSectorCentre.x, vecLargeSectorCentre.y, 0.0f), SectorRadius(LARGE_SECTOR_SIZE)) ) + { + // Render four small(32x32) sectors, or one large(64x64). + + // + // [N] + // --------- + // |0x1|1x1| + // [W] --------- [E] + // |0x0|1x0| + // --------- + // [S] + // + + float fLargeSectorDrawDistSqr = SQR((fWaterDrawDistLarge + 16.0f)); + + if ( fLargeSectorDistToCamSqr < fLargeSectorDrawDistSqr ) + { + _bSeaLife = true; + + float fZ; + + // WS + if ( aWaterFineBlockList[2*x2+0][2*y2+0] >= 0 ) + { + float fSmallX = fLargeX; + float fSmallY = fLargeY; + + CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2, fSmallY + SMALL_SECTOR_SIZE/2); + + float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr(); + fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+0][2*y2+0] ]; + + if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr ) + RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans); + else + RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist); + } + + // SE + if ( aWaterFineBlockList[2*x2+1][2*y2+0] >= 0 ) + { + float fSmallX = fLargeX + (LARGE_SECTOR_SIZE/2); + float fSmallY = fLargeY; + + CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2, fSmallY + SMALL_SECTOR_SIZE/2); + + float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr(); + fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+1][2*y2+0] ]; + + if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr ) + RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans); + else + RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist); + } + + // WN + if ( aWaterFineBlockList[2*x2+0][2*y2+1] >= 0 ) + { + float fSmallX = fLargeX; + float fSmallY = fLargeY + (LARGE_SECTOR_SIZE/2); + + CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2,fSmallY + SMALL_SECTOR_SIZE/2); + + float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr(); + fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+0][2*y2+1] ]; + + if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr ) + RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans); + else + RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist); + } + + //NE + if ( aWaterFineBlockList[2*x2+1][2*y2+1] >= 0 ) + { + float fSmallX = fLargeX + (LARGE_SECTOR_SIZE/2); + float fSmallY = fLargeY + (LARGE_SECTOR_SIZE/2); + + CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2, fSmallY + SMALL_SECTOR_SIZE/2); + + float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr(); + fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+1][2*y2+1] ]; + + if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr ) + RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans); + else + RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist); + } + } + else + { + float fZ; + + fZ = ms_aWaterZs[ aWaterBlockList[x2][y2] ]; + + RenderOneFlatLargeWaterPoly(fLargeX, fLargeY, fZ, color); + } + } + } + } + } + } + } + } + } + } + } + } + + RenderAndEmptyRenderBuffer(); + +#ifdef PC_WATER + if ( MaskCalculatedThisFrame + && (m_nRenderWaterLayers == 0 || m_nRenderWaterLayers == 2 || m_nRenderWaterLayers == 3) ) + { + RwV3d pos = { 0.0f, 0.0f, 0.0f }; + + pos.x = PreCalculatedMaskPosn.x; + pos.y = PreCalculatedMaskPosn.y; + pos.z = PreCalculatedMaskPosn.z; + + RpMatFXMaterialSetEnvMapFrame(RpGeometryGetMaterial(RpAtomicGetGeometry(ms_pMaskAtomic), 0), + RwCameraGetFrame(RwCameraGetCurrentCamera())); + + RwFrameTranslate(RpAtomicGetFrame(ms_pMaskAtomic), &pos, rwCOMBINEREPLACE); + + RpAtomicRender(ms_pMaskAtomic); + } +#else + if (!CCullZones::WaterFudge()) + { + int32 signX = 0; + int32 signY = 0; + + float fCamX = camPos.x - SMALL_SECTOR_SIZE; + float fCamY = camPos.y - SMALL_SECTOR_SIZE; + + if (TheCamera.GetForward().x > 0.3f) + signX = 1; + else if (TheCamera.GetForward().x < -0.3f) + signX = -1; + + fCamX += 0.3f * (float)signX * float(SMALL_SECTOR_SIZE * 2.0f); // 19.2f + + if (TheCamera.GetForward().y > 0.3f) + signY = 1; + else if (TheCamera.GetForward().y < -0.3f) + signY = -1; + + fCamY += 0.3f * (float)signY * float(SMALL_SECTOR_SIZE * 2.0f); // 19.2f + + int32 nBlock; + + int32 BlockX = WATER_TO_SMALL_SECTOR_X(fCamX + WATER_X_OFFSET) + 1; + int32 BlockY = WATER_TO_SMALL_SECTOR_Y(fCamY) + 1; + + if (_IsColideWithBlock(BlockX, BlockY, nBlock)) + { + if (m_nRenderWaterLayers != 1 && m_nRenderWaterLayers != 6) + { + float fMaskX = Floor(fCamX / 2.0f) * 2.0f; + float fMaskY = Floor(fCamY / 2.0f) * 2.0f; + float fWaterZ = CWaterLevel::ms_aWaterZs[nBlock]; + float fSectorX = WATER_FROM_SMALL_SECTOR_X(BlockX) - WATER_X_OFFSET; + float fSectorY = WATER_FROM_SMALL_SECTOR_Y(BlockY); + + RenderWavyMask(fMaskX, fMaskY, fWaterZ, + fSectorX, fSectorY, + signX, signY, colorTrans); + } + } + } + + DefinedState(); +#endif + + POP_RENDERGROUP(); +} + +void CWaterLevel::RenderOneFlatSmallWaterPoly(float fX, float fY, float fZ, RwRGBA const &color) +{ + if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) + RenderAndEmptyRenderBuffer(); + + int32 vidx = TempBufferVerticesStored; + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], color); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 1.0f); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], color); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + SMALL_SECTOR_SIZE, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 1.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 1.0f); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], color); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + SMALL_SECTOR_SIZE, fY, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 1.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], color); + + + int32 iidx = TempBufferIndicesStored; + + TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; + TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; + TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; + TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; + + TempBufferVerticesStored += 4; + TempBufferIndicesStored += 6; +} + +void +CWaterLevel::RenderOneFlatLargeWaterPoly(float fX, float fY, float fZ, RwRGBA const &color) +{ + if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) + RenderAndEmptyRenderBuffer(); + + int32 vidx = TempBufferVerticesStored; + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], color); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + LARGE_SECTOR_SIZE, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 2.0f); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], color); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + LARGE_SECTOR_SIZE, fY + LARGE_SECTOR_SIZE, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 2.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 2.0f); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], color); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + LARGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 2.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], color); + + + int32 iidx = TempBufferIndicesStored; + + TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; + TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; + TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; + TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; + + TempBufferVerticesStored += 4; + TempBufferIndicesStored += 6; +} + +void +CWaterLevel::RenderOneFlatHugeWaterPoly(float fX, float fY, float fZ, RwRGBA const &color) +{ + if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) + RenderAndEmptyRenderBuffer(); + + int32 vidx = TempBufferVerticesStored; + + RwRGBA c; + + c.red = color.red; + c.green = color.green; + c.blue = color.blue; + c.alpha = 255; + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], c); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 4.0f); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], c); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + HUGE_SECTOR_SIZE, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 4.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 4.0f); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], c); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + HUGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 4.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], c); + + + int32 iidx = TempBufferIndicesStored; + + TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; + TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; + TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; + TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; + + TempBufferVerticesStored += 4; + TempBufferIndicesStored += 6; +} + +void +CWaterLevel::RenderOneFlatExtraHugeWaterPoly(float fX, float fY, float fZ, RwRGBA const &color) +{ + if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) + RenderAndEmptyRenderBuffer(); + + int32 vidx = TempBufferVerticesStored; + + RwRGBA c; + + c.red = color.red; + c.green = color.green; + c.blue = color.blue; + c.alpha = 255; + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], c); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + EXTRAHUGE_SECTOR_SIZE, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 8.0f); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], c); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + EXTRAHUGE_SECTOR_SIZE, fY + EXTRAHUGE_SECTOR_SIZE, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 8.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 8.0f); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], c); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + EXTRAHUGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 8.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV); + RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], c); + + + int32 iidx = TempBufferIndicesStored; + + TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; + TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; + TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; + TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; + + TempBufferVerticesStored += 4; + TempBufferIndicesStored += 6; +} + +void +CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &color, bool bDontRender) +{ + CVector vecSectorPos(fX + (SMALL_SECTOR_SIZE/2), fY + (SMALL_SECTOR_SIZE/2), fZ + 2.0f); + + if ( COcclusion::IsAABoxOccluded(vecSectorPos, SMALL_SECTOR_SIZE, SMALL_SECTOR_SIZE, 4.0f) ) + return; + +#ifdef PC_WATER + RequireWavySector = true; +#else + if (!WavesCalculatedThisFrame) + { + WavesCalculatedThisFrame = true; + + float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); + + RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); + RwTexCoords *wavyTexCoords = RpGeometryGetVertexTexCoords(wavyGeometry, rwTEXTURECOORDINATEINDEX0); + RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0); + RwRGBA *wavyPreLight = RpGeometryGetPreLightColors(wavyGeometry); + RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph); + RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph); + + RpGeometryLock(wavyGeometry, rpGEOMETRYLOCKVERTICES | rpGEOMETRYLOCKNORMALS | rpGEOMETRYLOCKPRELIGHT | rpGEOMETRYLOCKTEXCOORDS); + + RwMatrix *camMat = RwFrameGetLTM(RwCameraGetFrame(RwCameraGetCurrentCamera())); //or curWorld + + float randomDampInv2 = (1.0f - fRandomDamp) * 2.0f; + + float move = 1.0f / 16.0f; + float randomMove = 1.0f / (16.0f * fRandomMoveDiv); + + float vertMul = 0.5f; + + float wind = CWeather::WindClipped * 0.4f + 0.2f; + float waveWind = CWeather::WindClipped * fWave2Ampl + 0.05f; + + float waveA = (TWOPI / 16.0f) + * ((fNormalDirectionScalar1 * Abs(camMat->at.x + camMat->at.y) + fNormMult) * (CWeather::WindClipped * 0.4f + 0.2f)); + + float waveB = TWOPI / (16.0f * fWave2NormScale) + * ((fNormalDirectionScalar2 * Abs(camMat->at.y - camMat->at.x) + fNormMultB) * (CWeather::WindClipped * 0.2f + 0.1f)); + + CVector vA(1.0f, 0.0f, 0.0f); + CVector vB(0.0f, 1.0f, 0.0f); + + for ( int32 i = 0; i < 17; i++ ) + { + for ( int32 j = 0; j < 17; j++ ) + { + wavyTexCoords->u = float(i) * move + TEXTURE_ADDV; + wavyTexCoords->v = float(j) * move + TEXTURE_ADDU; + + RwRGBAAssign(wavyPreLight, &color); + + if (i > 0 && i < 16 && j > 0 && j < 16) + { + wavyMorphVerts->x += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove; + wavyMorphVerts->x *= fRandomDamp; + wavyMorphVerts->x += float(i) * randomDampInv2; + + wavyMorphVerts->y += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove; + wavyMorphVerts->y *= fRandomDamp; + wavyMorphVerts->y += float(j) * randomDampInv2; + } + + float morphVertXHalf = (i == 16) ? 0.0f : vertMul * wavyMorphVerts->x; + float morphVertYHalf = (j == 16) ? 0.0f : vertMul * wavyMorphVerts->y; + + float waveMulA = (morphVertYHalf + morphVertXHalf) * (TWOPI / 16.0f) + fAngle; + float waveMulB = (morphVertYHalf - morphVertXHalf) * (TWOPI / (16.0f * fWave2InvLength)) + fAngle; + + wavyMorphVerts->z = wind * Sin(waveMulA) + waveWind * Sin(waveMulB); + + vA.z = (waveA * Cos(waveMulA)) - (waveB * Cos(waveMulB)); + vB.z = (waveA * Cos(waveMulA)) + (waveB * Cos(waveMulB)); + + CVector norm = CrossProduct(vA, vB); + norm.Normalise(); + + wavyMorphNormals->x = norm.x; + wavyMorphNormals->y = norm.y; + wavyMorphNormals->z = norm.z; + + ++wavyPreLight; + ++wavyTexCoords; + + ++wavyMorphVerts; + ++wavyMorphNormals; + } + } + + RpGeometryUnlock(wavyGeometry); + } + + float fCentreX = fX + (SMALL_SECTOR_SIZE / 2); + float fCentreY = fY + (SMALL_SECTOR_SIZE / 2); +#endif + +#ifdef PC_WATER + if ( WavesCalculatedThisFrame ) +#endif + { + if (bDontRender == false + && m_nRenderWaterLayers != 2 + && m_nRenderWaterLayers != 4 + && m_nRenderWaterLayers != 6 ) + { + RwV3d pos = { 0.0f, 0.0f, 0.0f }; + + pos.x = fX; + pos.y = fY; + pos.z = fZ; + + RwFrameTranslate(RpAtomicGetFrame(ms_pWavyAtomic), &pos, rwCOMBINEREPLACE); + + RpAtomicRender(ms_pWavyAtomic); + } + } +} + +int16 +_RoundValue(int32 v) +{ + int16 result = v; + + while ( result < 0 ) result += 16; + while ( result > 16 ) result -= 16; + + return result; +} + +void +CWaterLevel::RenderWavyMask(float fX, float fY, float fZ, + float fSectorX, float fSectorY, +#ifdef PC_WATER + float fCamPosX, float fCamPosY, + float fCamDirX, float fCamDirY, RwRGBA const&color) +#else + int32 nCamDirX, int32 nCamDirY, RwRGBA const&color) +#endif +{ +#ifndef PC_WATER + bool bRender = true; + if (m_nRenderWaterLayers != 0 && m_nRenderWaterLayers != 2 && m_nRenderWaterLayers != 3) + bRender = false; +#endif + CVector vecSectorPos(fX + (LARGE_SECTOR_SIZE/2), fY + (LARGE_SECTOR_SIZE/2), fZ + 2.0f); + + if ( COcclusion::IsAABoxOccluded(vecSectorPos, LARGE_SECTOR_SIZE, LARGE_SECTOR_SIZE, 4.0f) ) + return; + +#ifndef PC_WATER + float fUOffset = fX - (MAX_LARGE_SECTORS * (int32)Floor(fX / MAX_LARGE_SECTORS)); + float fVOffset = fY - (MAX_LARGE_SECTORS * (int32)Floor(fY / MAX_LARGE_SECTORS)); + + int32 nSecsX = (int32)((fX - fSectorX) / 2.0f); + int32 nSecsY = (int32)((fY - fSectorY) / 2.0f); +#endif + + RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); + RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0); + RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph); + RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph); + + RpGeometry *maskGeometry = RpAtomicGetGeometry(ms_pMaskAtomic); + RwTexCoords *maskTexCoords = RpGeometryGetVertexTexCoords(maskGeometry, rwTEXTURECOORDINATEINDEX0); + RwRGBA *maskPreLight = RpGeometryGetPreLightColors(maskGeometry); + RpMorphTarget *maskMorph = RpGeometryGetMorphTarget(maskGeometry, 0); + RwV3d *maskMorphVerts = RpMorphTargetGetVertices(maskMorph); + RwV3d *maskMorphNormals = RpMorphTargetGetVertexNormals(maskMorph); + + RpGeometryLock(maskGeometry, rpGEOMETRYLOCKVERTICES|rpGEOMETRYLOCKNORMALS|rpGEOMETRYLOCKPRELIGHT|rpGEOMETRYLOCKTEXCOORDS); + +#ifndef PC_WATER + RpMaterial *maskMat = RpGeometryGetMaterial(maskGeometry, 0); + RpMatFXMaterialSetEnvMapFrame(maskMat, RwCameraGetFrame(RwCameraGetCurrentCamera())); + RpMatFXMaterialSetEnvMapCoefficient(maskMat, fEnvScale); + RpMatFXMaterialSetEnvMapFrameBufferAlpha(maskMat, TRUE); +#endif + +#ifndef PC_WATER + float fMinSparkZ = (CWeather::WindClipped * fWave2Ampl + 0.05f + + CWeather::WindClipped * 0.4f + 0.2) * (1.0f - 0.04f * CWeather::SunGlare); + + int32 randval = CGeneral::GetRandomNumber(); + + float fUVStep = 0.125f; + float f27 = 2.0f; + + float fMinU = (fUOffset / 16.0f) + _TEXTURE_MASK_ADDU; + float fMinV = (fVOffset / 16.0f) + _TEXTURE_MASK_ADDV; + + float fAlphaMul = ((float)color.alpha * 0.4f) / 16.0f; + + float fXOffset = 16.0f; + if (nCamDirX > 0) + fXOffset = 6.4f; + else if (nCamDirX < 0) + fXOffset = 25.6f; + + float fYOffset = 16.0f; + if (nCamDirY > 0) + fYOffset = 6.4f; + else if (nCamDirY < 0) + fYOffset = 25.6f; + + int16 nX = _RoundValue(nSecsX - 1); + int16 nY = _RoundValue(nSecsY - 1); +#else + float fMinSparkZ = (fWave2Ampl * CWeather::WindClipped + 0.05f + + 0.4f * CWeather::WindClipped + 0.2) * (1.0f - 0.02f * CWeather::SunGlare); + + int32 randval = CGeneral::GetRandomNumber() & 255; + + int16 nX = _RoundValue((int32)((fX - fSectorX) * 0.5f) - 1); + int16 nY = _RoundValue((int32)((fY - fSectorY) * 0.5f) - 1); +#endif + int16 idxX = nX; + + for ( int32 i = 0; i < 17; i++ ) + { + int16 idxY = nY; + + if ( ++idxX > 16 ) + idxX -= 16; + + for ( int32 j = 0; j < 17; j++ ) + { + if ( ++idxY > 16 ) + idxY -= 16; + + const int32 a = (0*16); + const int32 b = (1*16); + const int32 c = (33*16); + const int32 d = (34*16); + + int32 base = (i*33+j); + +#ifndef PC_WATER + maskTexCoords[base + a].u = fMinU + ((float)i * fUVStep); + maskTexCoords[base + a].v = fMinV + ((float)j * fUVStep); + + maskTexCoords[base + b].u = maskTexCoords[base + a].u; + maskTexCoords[base + b].v = maskTexCoords[base + a].v + (16.0f * fUVStep); + + maskTexCoords[base + c].u = maskTexCoords[base + a].u + (16.0f * fUVStep); + maskTexCoords[base + c].v = maskTexCoords[base + a].v; + + maskTexCoords[base + d].u = maskTexCoords[base + a].u + (16.0f * fUVStep); + maskTexCoords[base + d].v = maskTexCoords[base + a].v + (16.0f * fUVStep); +#else + maskTexCoords[base+a].v = float(j) / SMALL_SECTOR_SIZE + ((fCamPosY - fY) / 64); + maskTexCoords[base+c].v = maskTexCoords[base+a].v; + maskTexCoords[base+d].v = maskTexCoords[base+a].v + 0.5f; + maskTexCoords[base+b].v = maskTexCoords[base+d].v; + + maskTexCoords[base+a].u = float(i) / SMALL_SECTOR_SIZE + ((fCamPosX - fX) / 64); + maskTexCoords[base+b].u = maskTexCoords[base+a].u; + maskTexCoords[base+d].u = maskTexCoords[base+a].u + 0.5f; + maskTexCoords[base+c].u = maskTexCoords[base+d].u; +#endif + + maskMorphVerts[base+a].x = (wavyMorphVerts[idxY + (17 * idxX)].x - (float)idxX * 2.0f) + (float(i) * 2.0f); + maskMorphVerts[base+b].x = maskMorphVerts[base+a].x; + maskMorphVerts[base+c].x = maskMorphVerts[base+a].x + SMALL_SECTOR_SIZE; + maskMorphVerts[base+d].x = maskMorphVerts[base+c].x; + + maskMorphVerts[base+a].y = (wavyMorphVerts[idxY + (17 * idxX)].y - (float)idxY * 2.0f) + (float(j) * 2.0f); + maskMorphVerts[base+c].y = maskMorphVerts[base+a].y; + maskMorphVerts[base+b].y = maskMorphVerts[base+a].y + SMALL_SECTOR_SIZE; + maskMorphVerts[base+d].y = maskMorphVerts[base+b].y; + + maskMorphVerts[base+a].z = wavyMorphVerts[idxY + (17 * idxX)].z; + maskMorphVerts[base+d].z = maskMorphVerts[base+a].z; + maskMorphVerts[base+c].z = maskMorphVerts[base+d].z; + maskMorphVerts[base+b].z = maskMorphVerts[base+c].z; + +#ifndef PC_WATER + if (maskMorphVerts[base].z >= fMinSparkZ) +#else + if ( maskMorphVerts[base].z > fMinSparkZ ) +#endif + { + switch ( (i + j + randval) & 3 ) + { + case 0: + { + CVector vecPos + ( + fX + maskMorphVerts[base+a].x, + fY + maskMorphVerts[base+a].y, + fZ + maskMorphVerts[base+a].z + 0.12f + ); + + vecPos -= 0.05f * TheCamera.GetForward(); + + CParticle::AddParticle(PARTICLE_WATER_SPARK, + vecPos, + CVector(0.0f, 0.0f, 0.0f), + nil, + 0.0f, + 15, + CGeneral::GetRandomNumberInRange(-90, 90), + 0, + 0); + } + break; + + case 1: + { + CVector vecPos + ( + fX + maskMorphVerts[base+c].x, + fY + maskMorphVerts[base+c].y, + fZ + maskMorphVerts[base+c].z + 0.12f + ); + + vecPos -= 0.05f * TheCamera.GetForward(); + + CParticle::AddParticle(PARTICLE_WATER_SPARK, + vecPos, + CVector(0.0f, 0.0f, 0.0f), + nil, + 0.0f, + 15, + CGeneral::GetRandomNumberInRange(-90, 90), + 0, + 0); + } + break; + + case 2: + { + CVector vecPos + ( + fX + maskMorphVerts[base+b].x, + fY + maskMorphVerts[base+b].y, + fZ + maskMorphVerts[base+b].z + 0.12f + ); + + vecPos -= 0.05f * TheCamera.GetForward(); + + CParticle::AddParticle(PARTICLE_WATER_SPARK, + vecPos, + CVector(0.0f, 0.0f, 0.0f), + nil, + 0.0f, + 15, + CGeneral::GetRandomNumberInRange(-90, 90), + 0, + 0); + } + break; + + case 3: + { + CVector vecPos + ( + fX + maskMorphVerts[base+d].x, + fY + maskMorphVerts[base+d].y, + fZ + maskMorphVerts[base+d].z + 0.12f + ); + + vecPos -= 0.05f * TheCamera.GetForward(); + + CParticle::AddParticle(PARTICLE_WATER_SPARK, + vecPos, + CVector(0.0f, 0.0f, 0.0f), + nil, + 0.0f, + 15, + CGeneral::GetRandomNumberInRange(-90, 90), + 0, + 0); + } + break; + } + } + + maskMorphNormals[base+a].x = wavyMorphNormals[idxY + (17 * idxX)].x; + maskMorphNormals[base+a].y = wavyMorphNormals[idxY + (17 * idxX)].y; + maskMorphNormals[base+a].z = wavyMorphNormals[idxY + (17 * idxX)].z; + + maskMorphNormals[base+d].x = maskMorphNormals[base+a].x; + maskMorphNormals[base+d].y = maskMorphNormals[base+a].y; + maskMorphNormals[base+d].z = maskMorphNormals[base+a].z; + + maskMorphNormals[base+c].x = maskMorphNormals[base+d].x; + maskMorphNormals[base+c].y = maskMorphNormals[base+d].y; + maskMorphNormals[base+c].z = maskMorphNormals[base+d].z; + + maskMorphNormals[base+b].x = maskMorphNormals[base+c].x; + maskMorphNormals[base+b].y = maskMorphNormals[base+c].y; + maskMorphNormals[base+b].z = maskMorphNormals[base+c].z; + + maskPreLight[base+a].red = color.red; + maskPreLight[base+a].green = color.green; + maskPreLight[base+a].blue = color.blue; + maskPreLight[base+a].alpha = color.alpha; + + maskPreLight[base+d].red = maskPreLight[base+a].red; + maskPreLight[base+d].green = maskPreLight[base+a].green; + maskPreLight[base+d].blue = maskPreLight[base+a].blue; + maskPreLight[base+d].alpha = maskPreLight[base+a].alpha; + + maskPreLight[base+c].red = maskPreLight[base+d].red; + maskPreLight[base+c].green = maskPreLight[base+d].green; + maskPreLight[base+c].blue = maskPreLight[base+d].blue; + maskPreLight[base+c].alpha = maskPreLight[base+d].alpha; + + maskPreLight[base+b].red = maskPreLight[base+c].red; + maskPreLight[base+b].green = maskPreLight[base+c].green; + maskPreLight[base+b].blue = maskPreLight[base+c].blue; + maskPreLight[base+b].alpha = maskPreLight[base+c].alpha; + +#ifndef PC_WATER + maskPreLight[base + a].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs((float)i - fXOffset) + Abs((float)j - fYOffset))))); + maskPreLight[base + b].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs((float)i - fXOffset) + Abs(16.0f + (float)j - fYOffset))))); + maskPreLight[base + c].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs(16.0f + (float)i - fXOffset) + Abs((float)j - fYOffset))))); + maskPreLight[base + d].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs(16.0f + (float)i - fXOffset) + Abs(16.0f + (float)j - fYOffset))))); +#endif + } + } + + RpGeometryUnlock(maskGeometry); + +#ifndef PC_WATER + { + RwV3d pos = { 0.0f, 0.0f, 0.0f }; + + pos.x = fX; + pos.y = fY; + pos.z = fZ + 0.05f; + + RwFrameTranslate(RpAtomicGetFrame(ms_pMaskAtomic), &pos, rwCOMBINEREPLACE); + + if (bRender) + { +#ifdef PS2 + RpSkyTexCacheFlush(); +#endif + RpAtomicRender(ms_pMaskAtomic); + } + } +#endif +} + +#ifdef PC_WATER +void +CWaterLevel::PreCalcWaterGeometry(void) +{ + if ( !RequireWavySector ) + { + WavesCalculatedThisFrame = false; + MaskCalculatedThisFrame = false; + return; + } + + RequireWavySector = false; + WavesCalculatedThisFrame = true; + + RwRGBA color; + + color.red = CTimeCycle::GetWaterRed(); + color.green = CTimeCycle::GetWaterGreen(); + color.blue = CTimeCycle::GetWaterBlue(); + color.alpha = CTimeCycle::GetWaterAlpha(); + + PreCalcWavySector(color); + + if ( CCullZones::WaterFudge() ) + { + MaskCalculatedThisFrame = false; + return; + } + + CVector CamFwdDir = TheCamera.GetForward(); + CamFwdDir.z = 0.0f; + CamFwdDir.Normalise(); + + float fCamX = TheCamera.GetPosition().x - SMALL_SECTOR_SIZE; + float fCamY = TheCamera.GetPosition().y - SMALL_SECTOR_SIZE; + + //1.4144272f; 1.4144f; + float signX = CamFwdDir.x * 1.4144272f; + float signY = CamFwdDir.y * 1.4144272f; + + signX = Clamp(signX, -1.0f, 1.0f); + fCamX += 0.4f * signX * float(SMALL_SECTOR_SIZE * 2.0f); + + signY = Clamp(signY, -1.0f, 1.0f); + fCamY += 0.4f * signY * float(SMALL_SECTOR_SIZE * 2.0f); + + int32 nBlock; + + int32 BlockX = WATER_TO_SMALL_SECTOR_X(fCamX + WATER_X_OFFSET) + 1; + int32 BlockY = WATER_TO_SMALL_SECTOR_Y(fCamY ) + 1; + + ASSERT( BlockX >= 0 && BlockX < MAX_SMALL_SECTORS ); + ASSERT( BlockY >= 0 && BlockY < MAX_SMALL_SECTORS ); + + if ( _IsColideWithBlock(BlockX, BlockY, nBlock) ) + { + float fMaskX = Floor(fCamX / 2.0f) * 2.0f; + float fMaskY = Floor(fCamY / 2.0f) * 2.0f; + + float fSectorX = WATER_FROM_SMALL_SECTOR_X(BlockX) - WATER_X_OFFSET; + float fSectorY = WATER_FROM_SMALL_SECTOR_Y(BlockY); + + if ( PreCalcWavyMask( fMaskX, fMaskY, ms_aWaterZs[nBlock], + fSectorX, fSectorY, fCamX, fCamY, CamFwdDir.x, CamFwdDir.y, color ) ) + { + PreCalculatedMaskPosn.x = fMaskX; + PreCalculatedMaskPosn.y = fMaskY; + PreCalculatedMaskPosn.z = ms_aWaterZs[nBlock] + 0.05f; + + MaskCalculatedThisFrame = true; + } + else + MaskCalculatedThisFrame = false; + } + else + MaskCalculatedThisFrame = false; +} + +bool +CWaterLevel::PreCalcWavySector(RwRGBA const &color) +{ + float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); + + RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); + + RwTexCoords *wavyTexCoords = RpGeometryGetVertexTexCoords(wavyGeometry, rwTEXTURECOORDINATEINDEX0); + RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0); + + RwRGBA *wavyPreLight = RpGeometryGetPreLightColors(wavyGeometry); + RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph); + RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph); + + if ( !m_bRenderSeaBed ) + RpGeometryLock(wavyGeometry, rpGEOMETRYLOCKVERTICES + |rpGEOMETRYLOCKNORMALS + |rpGEOMETRYLOCKPRELIGHT + |rpGEOMETRYLOCKTEXCOORDS); + + CVector camPosUp = TheCamera.GetForward(); + + float randomDampInv2 = (1.0f - fRandomDamp) * 2.0f; + + float randomMove = 1.0f / (16.0f * fRandomMoveDiv); + + float wind = CWeather::WindClipped * 0.4f + 0.2f; + float waveWind = CWeather::WindClipped * fWave2Ampl + 0.05f; + + float waveA = (TWOPI / 16.0f) + * ((CWeather::WindClipped * 0.4f + 0.2f) * (fNormalDirectionScalar1 * Abs(camPosUp.x + camPosUp.y) + fNormMult)); + + float waveB = TWOPI / (16.0f * fWave2NormScale) + * ((CWeather::WindClipped * 0.2f + 0.1f) * (fNormalDirectionScalar2 * Abs(camPosUp.y - camPosUp.x) + fNormMultB)); + + + CVector vA(1.0f, 0.0f, 0.0f); + CVector vB(0.0f, 1.0f, 0.0f); + + for ( int32 i = 0; i < 17; i++ ) + { + for ( int32 j = 0; j < 17; j++ ) + { + wavyTexCoords->u = (float(i) / 16.0f) + TEXTURE_ADDV; + wavyTexCoords->v = (float(j) / 16.0f) + TEXTURE_ADDU; + + RwRGBAAssign(wavyPreLight, &color); + + if ( i > 0 && i < 16 && j > 0 && j < 16 ) + { + wavyMorphVerts->x += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove; + wavyMorphVerts->x *= fRandomDamp; + wavyMorphVerts->x += float(i) * randomDampInv2; + + wavyMorphVerts->y += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove; + wavyMorphVerts->y *= fRandomDamp; + wavyMorphVerts->y += float(j) * randomDampInv2; + } + + float morphVertXHalf = ( i == 16 ) ? 0.0f : 0.5f * wavyMorphVerts->x; + float morphVertYHalf = ( j == 16 ) ? 0.0f : 0.5f * wavyMorphVerts->y; + + float waveMulA = (morphVertYHalf + morphVertXHalf) * (TWOPI / 16.0f) + fAngle; + float waveMulB = (morphVertYHalf - morphVertXHalf) * (TWOPI / (16.0f * fWave2InvLength)) + fAngle; + + wavyMorphVerts->z = wind * Sin(waveMulA) + waveWind * Sin(waveMulB); + + vA.z = (waveA * Cos(waveMulA)) - (waveB * Cos(waveMulB)); + vB.z = (waveA * Cos(waveMulA)) + (waveB * Cos(waveMulB)); + + CVector norm = CrossProduct(vA, vB); + norm.Normalise(); + + wavyMorphNormals->x = norm.x; + wavyMorphNormals->y = norm.y; + wavyMorphNormals->z = norm.z; + + ++wavyPreLight; + ++wavyTexCoords; + + ++wavyMorphVerts; + ++wavyMorphNormals; + } + } + + RpGeometryUnlock(wavyGeometry); + + return true; +} + +bool +CWaterLevel::PreCalcWavyMask(float fX, float fY, float fZ, + float fSectorX, float fSectorY, + float fCamPosX, float fCamPosY, + float fCamDirX, float fCamDirY, + RwRGBA const&color) +{ + CVector vecSectorPos(fX + (MAX_LARGE_SECTORS/2), fY + (MAX_LARGE_SECTORS/2), fZ + 2.0f); + + if ( COcclusion::IsAABoxOccluded(vecSectorPos, MAX_LARGE_SECTORS, MAX_LARGE_SECTORS, 4.0f) ) + return false; + + Floor(fX / MAX_LARGE_SECTORS); + Floor(fY / MAX_LARGE_SECTORS); + + RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic); + RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0); + RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph); + RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph); + + RpGeometry *maskGeometry = RpAtomicGetGeometry(ms_pMaskAtomic); + RwTexCoords *maskTexCoords = RpGeometryGetVertexTexCoords(maskGeometry, rwTEXTURECOORDINATEINDEX0); + RwRGBA *maskPreLight = RpGeometryGetPreLightColors(maskGeometry); + RpMorphTarget *maskMorph = RpGeometryGetMorphTarget(maskGeometry, 0); + RwV3d *maskMorphVerts = RpMorphTargetGetVertices(maskMorph); + RwV3d *maskMorphNormals = RpMorphTargetGetVertexNormals(maskMorph); + + if ( !m_bRenderSeaBed ) + RpGeometryLock(maskGeometry, rpGEOMETRYLOCKVERTICES | rpGEOMETRYLOCKNORMALS | rpGEOMETRYLOCKPRELIGHT | rpGEOMETRYLOCKTEXCOORDS); + + + float fMinSparkZ = (fWave2Ampl * CWeather::WindClipped + 0.05f + + 0.4f * CWeather::WindClipped + 0.2) * (1.0f - 0.02f * CWeather::SunGlare); + + int32 randval = CGeneral::GetRandomNumber() & 255; + + int16 nX = _RoundValue((int32)((fX - fSectorX) * 0.5f) - 1); + int16 nY = _RoundValue((int32)((fY - fSectorY) * 0.5f) - 1); + + int16 idxX = nX; + + for ( int32 i = 0; i < 17; i++ ) + { + int16 idxY = nY; + + if ( ++idxX > 16 ) + idxX -= 16; + + for ( int32 j = 0; j < 17; j++ ) + { + if ( ++idxY > 16 ) + idxY -= 16; + + const int32 a = (0*16); + const int32 b = (1*16); + const int32 c = (33*16); + const int32 d = (34*16); + + int32 base = (i*33+j); + + maskTexCoords[base+a].v = float(j) / 32 + ((fCamPosY - fY) / 64); + maskTexCoords[base+c].v = maskTexCoords[base+a].v; + maskTexCoords[base+d].v = maskTexCoords[base+a].v + 0.5f; + maskTexCoords[base+b].v = maskTexCoords[base+d].v; + + maskTexCoords[base+a].u = float(i) / 32 + ((fCamPosX - fX) / 64); + maskTexCoords[base+b].u = maskTexCoords[base+a].u; + maskTexCoords[base+d].u = maskTexCoords[base+a].u + 0.5f; + maskTexCoords[base+c].u = maskTexCoords[base+d].u; + + maskMorphVerts[base+a].x = (wavyMorphVerts[idxY + (17 * idxX)].x - (float)idxX * 2.0f) + (float(i) * 2.0f); + maskMorphVerts[base+b].x = maskMorphVerts[base+a].x; + maskMorphVerts[base+c].x = maskMorphVerts[base+a].x + SMALL_SECTOR_SIZE; + maskMorphVerts[base+d].x = maskMorphVerts[base+c].x; + + maskMorphVerts[base+a].y = (wavyMorphVerts[idxY + (17 * idxX)].y - (float)idxY * 2.0f) + (float(j) * 2.0f); + maskMorphVerts[base+c].y = maskMorphVerts[base+a].y; + maskMorphVerts[base+b].y = maskMorphVerts[base+a].y + SMALL_SECTOR_SIZE; + maskMorphVerts[base+d].y = maskMorphVerts[base+b].y; + + maskMorphVerts[base+a].z = wavyMorphVerts[idxY + (17 * idxX)].z; + maskMorphVerts[base+d].z = maskMorphVerts[base+a].z; + maskMorphVerts[base+c].z = maskMorphVerts[base+d].z; + maskMorphVerts[base+b].z = maskMorphVerts[base+c].z; + + if ( maskMorphVerts[base].z > fMinSparkZ ) + { + switch ( (i + j + randval) & 3 ) + { + case 0: + { + CVector vecPos + ( + fX + maskMorphVerts[base+a].x, + fY + maskMorphVerts[base+a].y, + fZ + maskMorphVerts[base+a].z + 0.12f + ); + + vecPos -= 0.05f * TheCamera.GetForward(); + + CParticle::AddParticle(PARTICLE_WATER_SPARK, + vecPos, + CVector(0.0f, 0.0f, 0.0f), + nil, + 0.0f, + 15, + CGeneral::GetRandomNumberInRange(-90, 90), + 0, + 0); + } + break; + + case 1: + { + CVector vecPos + ( + fX + maskMorphVerts[base+c].x, + fY + maskMorphVerts[base+c].y, + fZ + maskMorphVerts[base+c].z + 0.12f + ); + + vecPos -= 0.05f * TheCamera.GetForward(); + + CParticle::AddParticle(PARTICLE_WATER_SPARK, + vecPos, + CVector(0.0f, 0.0f, 0.0f), + nil, + 0.0f, + 15, + CGeneral::GetRandomNumberInRange(-90, 90), + 0, + 0); + } + break; + + case 2: + { + CVector vecPos + ( + fX + maskMorphVerts[base+b].x, + fY + maskMorphVerts[base+b].y, + fZ + maskMorphVerts[base+b].z + 0.12f + ); + + vecPos -= 0.05f * TheCamera.GetForward(); + + CParticle::AddParticle(PARTICLE_WATER_SPARK, + vecPos, + CVector(0.0f, 0.0f, 0.0f), + nil, + 0.0f, + 15, + CGeneral::GetRandomNumberInRange(-90, 90), + 0, + 0); + } + break; + + case 3: + { + CVector vecPos + ( + fX + maskMorphVerts[base+d].x, + fY + maskMorphVerts[base+d].y, + fZ + maskMorphVerts[base+d].z + 0.12f + ); + + vecPos -= 0.05f * TheCamera.GetForward(); + + CParticle::AddParticle(PARTICLE_WATER_SPARK, + vecPos, + CVector(0.0f, 0.0f, 0.0f), + nil, + 0.0f, + 15, + CGeneral::GetRandomNumberInRange(-90, 90), + 0, + 0); + } + break; + } + } + + maskMorphNormals[base+a].x = wavyMorphNormals[idxY + (17 * idxX)].x; + maskMorphNormals[base+a].y = wavyMorphNormals[idxY + (17 * idxX)].y; + maskMorphNormals[base+a].z = wavyMorphNormals[idxY + (17 * idxX)].z; + + maskMorphNormals[base+d].x = maskMorphNormals[base+a].x; + maskMorphNormals[base+d].y = maskMorphNormals[base+a].y; + maskMorphNormals[base+d].z = maskMorphNormals[base+a].z; + + maskMorphNormals[base+c].x = maskMorphNormals[base+d].x; + maskMorphNormals[base+c].y = maskMorphNormals[base+d].y; + maskMorphNormals[base+c].z = maskMorphNormals[base+d].z; + + maskMorphNormals[base+b].x = maskMorphNormals[base+c].x; + maskMorphNormals[base+b].y = maskMorphNormals[base+c].y; + maskMorphNormals[base+b].z = maskMorphNormals[base+c].z; + + maskPreLight[base+a].red = color.red; + maskPreLight[base+a].green = color.green; + maskPreLight[base+a].blue = color.blue; + maskPreLight[base+a].alpha = color.alpha; + + maskPreLight[base+d].red = maskPreLight[base+a].red; + maskPreLight[base+d].green = maskPreLight[base+a].green; + maskPreLight[base+d].blue = maskPreLight[base+a].blue; + maskPreLight[base+d].alpha = maskPreLight[base+a].alpha; + + maskPreLight[base+c].red = maskPreLight[base+d].red; + maskPreLight[base+c].green = maskPreLight[base+d].green; + maskPreLight[base+c].blue = maskPreLight[base+d].blue; + maskPreLight[base+c].alpha = maskPreLight[base+d].alpha; + + maskPreLight[base+b].red = maskPreLight[base+c].red; + maskPreLight[base+b].green = maskPreLight[base+c].green; + maskPreLight[base+b].blue = maskPreLight[base+c].blue; + maskPreLight[base+b].alpha = maskPreLight[base+c].alpha; + } + } + + RpGeometryUnlock(maskGeometry); + return true; +} +#endif + +void +CWaterLevel::RenderBoatWakes(void) +{ + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterWakeRaster); +#ifndef PC_WATER + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA); +#endif + +#ifdef _XBOX + // TODO save and restore rwRENDERSTATESRCBLEND rwRENDERSTATEDESTBLEND +#endif + + CBoat::FillBoatList(); + + float fWakeZ = 5.97f; + float fWakeLifeTimeMult = 0.01f / CBoat::WAKE_LIFETIME; + + for ( int32 idx = 0; idx < ARRAY_SIZE(CBoat::apFrameWakeGeneratingBoats); idx++ ) + { + CBoat *pBoat = CBoat::apFrameWakeGeneratingBoats[idx]; + + if ( pBoat == nil ) + break; + + CVector2D vecDistA(pBoat->GetForward().x, pBoat->GetForward().y); + + + float fSize = pBoat->GetColModel()->boundingBox.max.z + * 0.65f; + + if ( pBoat->GetModelIndex() == MI_SKIMMER) + fSize *= 0.4f; + + float fAplhaA = 255.0f; + float fSizeA = fSize; + float fAplhaB; + float fSizeB; + + for ( int32 wake = 1; wake < pBoat->m_nNumWakePoints; wake++ ) + { + bool bRender = true; + + float fTimeleft = CBoat::WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[wake]; + + float fWakeSizeB = ((float)wake * 0.19f) + fSize - fWakeLifeTimeMult * Max(fTimeleft, 0.0f); + + fSizeB = fWakeSizeB / CBoat::MIN_WAKE_INTERVAL; + if ( fSizeB < 0.0f ) + fSizeB = 1.0f; + + if ( wake == pBoat->m_nNumWakePoints - 1 ) + { + // set alpha to 0 if it's last point + fAplhaB = 0.0f; + } + else + { + // clip (-100, 500), less lifetime - less val + float val = 500.0f - (CBoat::WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[wake]) + * 600.0f / CBoat::WAKE_LIFETIME; + + fAplhaB = Clamp(val, 0.0f, 255.0f); + } + + CVector2D vecDistB = pBoat->m_avec2dWakePoints[wake - 1] - pBoat->m_avec2dWakePoints[wake]; + + float fScal = vecDistB.MagnitudeSqr(); + + // normalize if distance between points is greater than 3 + + if ( fScal > SQR(3.0f) ) + { + float fNorm = 1.0f / sqrt(fScal); + + vecDistB.x *= fNorm; + vecDistB.y *= fNorm; + + // disable render if distance between points too big + + if ( sqrt(fScal) > 13.0f ) + bRender = false; + } + + CVector2D vecAA + ( + pBoat->m_avec2dWakePoints[wake - 1].x - (fSizeA * vecDistA.y), + pBoat->m_avec2dWakePoints[wake - 1].y + (fSizeA * vecDistA.x) + ); + CVector2D vecAB + ( + pBoat->m_avec2dWakePoints[wake - 1].x + (fSizeA * vecDistA.y), + pBoat->m_avec2dWakePoints[wake - 1].y - (fSizeA * vecDistA.x) + ); + CVector2D vecBA + ( + pBoat->m_avec2dWakePoints[wake].x + (fSizeB * vecDistB.y), + pBoat->m_avec2dWakePoints[wake].y - (fSizeB * vecDistB.x) + ); + CVector2D vecBB + ( + pBoat->m_avec2dWakePoints[wake].x - (fSizeB * vecDistB.y), + pBoat->m_avec2dWakePoints[wake].y + (fSizeB * vecDistB.x) + ); + + if ( bRender ) + RenderWakeSegment(vecAA, vecAB, vecBA, vecBB, fSizeA, fSizeB, fAplhaA, fAplhaB, fWakeZ); + + vecDistA = vecDistB; + fSizeA = fSizeB; + + fAplhaB = fAplhaA; + } + } + + RenderAndEmptyRenderBuffer(); +} + +inline float +_GetWindedWave(float fX, float fY) +{ + float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f); + float x = WATER_HUGE_X(fX + WATER_X_OFFSET); + float y = WATER_HUGE_Y(fY); + + float fWindFactor (CWeather::WindClipped * 0.4f + 0.2f); + float fWave = Sin(( (x - Floor(x)) + (y - Floor(y)) ) * TWOPI + fAngle); + + return fWindFactor * fWave; +} + +void +CWaterLevel::RenderWakeSegment(CVector2D &vecA, CVector2D &vecB, CVector2D &vecC, CVector2D &vecD, + float &fSizeA, float &fSizeB, + float &fAlphaA, float &fAlphaB, + float &fWakeZ) +{ + for ( int32 i = 0; i < 4; i++ ) + { + if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) + RenderAndEmptyRenderBuffer(); + + float fCurStep = (float)i / 4; + float fNxtStep = (float)(i + 1) / 4; + + float fLeftCurStep = 1.0f - fCurStep; + float fLeftNxtStep = 1.0f - fNxtStep; + + uint8 AlphaA = (uint32)(fAlphaA * aAlphaFade[i] ); + uint8 AlphaB = (uint32)(fAlphaA * aAlphaFade[i + 1]); + uint8 AlphaC = (uint32)(fAlphaB * aAlphaFade[i + 1]); + uint8 AlphaD = (uint32)(fAlphaB * aAlphaFade[i] ); + + CVector2D PosA = vecB*fCurStep + vecA*fLeftCurStep; + CVector2D PosB = vecB*fNxtStep + vecA*fLeftNxtStep; + CVector2D PosC = vecC*fNxtStep + vecD*fLeftNxtStep; + CVector2D PosD = vecC*fCurStep + vecD*fLeftCurStep; + + float fUA = (PosA.x / 4) + _TEXTURE_WAKE_ADDU; + float fVA = (PosA.y / 4) + _TEXTURE_WAKE_ADDV; + + float fUB = (PosB.x / 4) + _TEXTURE_WAKE_ADDU; + float fVB = (PosB.y / 4) + _TEXTURE_WAKE_ADDV; + + float fUC = (PosC.x / 4) + _TEXTURE_WAKE_ADDU; + float fVC = (PosC.y / 4) + _TEXTURE_WAKE_ADDV; + + float fUD = (PosD.x / 4) + _TEXTURE_WAKE_ADDU; + float fVD = (PosD.y / 4) + _TEXTURE_WAKE_ADDV; + +#define MIN4(a, b, c, d) (Min((a), Min((b), Min((c), (d))))) + float fMinU = Floor(MIN4(fUA, fUB, fUC, fUD)); + float fMinV = Floor(MIN4(fVA, fVB, fVC, fVD)); +#undef MIN4 + + float fZA = _GetWindedWave(PosA.x, PosA.y) + fWakeZ; + float fZB = _GetWindedWave(PosB.x, PosB.y) + fWakeZ; + float fZC = _GetWindedWave(PosC.x, PosC.y) + fWakeZ; + float fZD = _GetWindedWave(PosD.x, PosD.y) + fWakeZ; + + int32 vidx = TempBufferVerticesStored; + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], PosA.x, PosA.y, fZA); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], fUA - fMinU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], fVA - fMinV); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 0], 255, 255, 255, AlphaA); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], PosB.x, PosB.y, fZB); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], fUB - fMinU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], fVB - fMinV); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 1], 255, 255, 255, AlphaB); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], PosC.x, PosC.y, fZC); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], fUC - fMinU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], fVC - fMinV); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 2], 255, 255, 255, AlphaC); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], PosD.x, PosD.y, fZD); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], fUD - fMinU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], fVD - fMinV); + RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 3], 255, 255, 255, AlphaD); + + int32 iidx = TempBufferIndicesStored; + + TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; + TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; + TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; + TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; + + TempBufferVerticesStored += 4; + + TempBufferIndicesStored += 6; + } +} + +void +CWaterLevel::RenderOneSlopedUnderWaterPoly(float fX, float fY, float fZ, RwRGBA const&color) +{ + CVector2D camPos(TheCamera.GetPosition().x, TheCamera.GetPosition().y); + + float fDistA = (CVector2D(fX, fY) - camPos).Magnitude() + -140.0f; + float fDistB = (CVector2D(fX, fY + HUGE_SECTOR_SIZE) - camPos).Magnitude() + -140.0f; + float fDistC = (CVector2D(fX + HUGE_SECTOR_SIZE, fY + HUGE_SECTOR_SIZE) - camPos).Magnitude() + -140.0f; + float fDistD = (CVector2D(fX + HUGE_SECTOR_SIZE, fY) - camPos).Magnitude() + -140.0f; + +#ifndef PC_WATER +#define CALCSEABED(v, d) \ + { \ + if ( d < 0.0f ) \ + v = 0.1f + fSeaBedZ; \ + else if ( d > 240.0f ) \ + v = 0.1f; \ + else \ + v = 0.1f + ((fSeaBedZ * (240.0f - d)) / 240.0f); \ + } +#else + #define CALCSEABED(v, d) \ + { \ + v = 0.1f; \ + if ( d < 0.0f ) \ + v += fSeaBedZ; \ + else if ( d <= 240.0f ) \ + v += (fSeaBedZ / 240.0f) * (240.0f - d); \ + } +#endif + float fSeaBedA, fSeaBedB, fSeaBedC, fSeaBedD; + + CALCSEABED(fSeaBedA, fDistA); + CALCSEABED(fSeaBedB, fDistB); + CALCSEABED(fSeaBedC, fDistC); + CALCSEABED(fSeaBedD, fDistD); + + #undef CALCSEABED + + if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) + RenderAndEmptyRenderBuffer(); + + int32 vidx = TempBufferVerticesStored; + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset - fSeaBedA); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], 0.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], 0.0f); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 0], color.red, color.green, color.blue, 255); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset - fSeaBedB); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], 0.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], 4.0f); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 1], color.red, color.green, color.blue, 255); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + HUGE_SECTOR_SIZE, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset - fSeaBedC); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], 4.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], 4.0f); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 2], color.red, color.green, color.blue, 255); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + HUGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset - fSeaBedD); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], 4.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], 0.0f); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 3], color.red, color.green, color.blue, 255); + + int32 iidx = TempBufferIndicesStored; + + TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; + TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; + TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; + TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; + + TempBufferVerticesStored += 4; + + TempBufferIndicesStored += 6; +} + +void +CWaterLevel::RenderOneFlatSmallWaterPolyBlended(float fX, float fY, float fZ, float fCamX, float fCamY, + RwRGBA const &color, RwRGBA const &colorTrans, + float fDrawDist) +{ + if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 ) + RenderAndEmptyRenderBuffer(); + + int32 vidx = TempBufferVerticesStored; + + float fBlendDrawDist = fDrawDist + fStartBlendDistanceAdd; + + float fDistStartX = SQR(fX - fCamX); + float fDistStartY = SQR(fY - fCamY); + float fDistEndX = SQR((fX + SMALL_SECTOR_SIZE) - fCamX); + float fDistEndY = SQR((fY + SMALL_SECTOR_SIZE) - fCamY); + + + float fAlphaBlendMulA + = Min(fFlatWaterBlendRange * Max(sqrt(fDistStartX + fDistStartY) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f); + float fAlphaBlendMulB + = Min(fFlatWaterBlendRange * Max(sqrt(fDistStartX + fDistEndY ) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f); + float fAlphaBlendMulC + = Min(fFlatWaterBlendRange * Max(sqrt(fDistEndX + fDistEndY ) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f); + float fAlphaBlendMulD + = Min(fFlatWaterBlendRange * Max(sqrt(fDistEndX + fDistStartY) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f); + + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 0], color.red, color.green, color.blue, + (colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulA)); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 1.0f); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 1], color.red, color.green, color.blue, + (colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulB)); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + SMALL_SECTOR_SIZE, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 1.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 1.0f); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 2], color.red, color.green, color.blue, + (colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulC)); + + RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + SMALL_SECTOR_SIZE, fY, fZ - _fWaterZOffset); + RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 1.0f); + RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 3], color.red, color.green, color.blue, + (colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulD)); + + + int32 iidx = TempBufferIndicesStored; + + TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2; + TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1; + TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3; + TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2; + + TempBufferVerticesStored += 4; + + TempBufferIndicesStored += 6; +} + +float +CWaterLevel::CalcDistanceToWater(float fX, float fY) +{ + const float fSectorMaxRenderDist = 250.0f; + + int32 nStartX = WATER_TO_SMALL_SECTOR_X(fX - fSectorMaxRenderDist + WATER_X_OFFSET) - 1; + int32 nEndX = WATER_TO_SMALL_SECTOR_X(fX + fSectorMaxRenderDist + WATER_X_OFFSET) + 1; + int32 nStartY = WATER_TO_SMALL_SECTOR_Y(fY - fSectorMaxRenderDist) - 1; + int32 nEndY = WATER_TO_SMALL_SECTOR_Y(fY + fSectorMaxRenderDist) + 1; + + nStartX = Clamp(nStartX, 0, MAX_SMALL_SECTORS - 1); + nEndX = Clamp(nEndX, 0, MAX_SMALL_SECTORS - 1); + nStartY = Clamp(nStartY, 0, MAX_SMALL_SECTORS - 1); + nEndY = Clamp(nEndY, 0, MAX_SMALL_SECTORS - 1); + + float fDistSqr = 1.0e10f; + + for ( int32 x = nStartX; x <= nEndX; x++ ) + { + for ( int32 y = nStartY; y <= nEndY; y++ ) + { + if ( aWaterFineBlockList[x][y] >= 0 ) + { + float fSectorX = WATER_FROM_SMALL_SECTOR_X(x) - WATER_X_OFFSET; + float fSectorY = WATER_FROM_SMALL_SECTOR_Y(y); + + CVector2D vecDist + ( + fSectorX + SMALL_SECTOR_SIZE - fX, + fSectorY + SMALL_SECTOR_SIZE - fY + ); + + fDistSqr = Min(vecDist.MagnitudeSqr(), fDistSqr); + } + } + } + + return Clamp(Sqrt(fDistSqr) - 23.0f, 0.0f, fSectorMaxRenderDist); +} + +void +CWaterLevel::RenderAndEmptyRenderBuffer() +{ + if ( TempBufferVerticesStored ) + { + LittleTest(); + + if ( RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, rwIM3D_VERTEXUV) ) + { + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); + RwIm3DEnd(); + } + } + + TempBufferIndicesStored = 0; + TempBufferVerticesStored = 0; +} + +bool +CWaterLevel::GetGroundLevel(CVector const &vecPosn, float *pfOutLevel, ColData *pData, float fDistance) +{ + CColPoint point; + CEntity *entity; + + if ( !CWorld::ProcessVerticalLine(vecPosn + CVector(0.0f, 0.0f, fDistance), + -fDistance, point, entity, true, false, false, false, true, false, nil) ) + return false; + + *pfOutLevel = point.point.z; + + if ( pData != nil ) + { + pData->SurfaceType = point.surfaceB; + pData->PieceType = point.pieceB; + } + + return true; +} + +bool +CWaterLevel::IsLocationOutOfWorldBounds_WS(CVector const &vecPosn, int nOffset) +{ + int32 x = int32((vecPosn.x / 50.0f) + 48.0f); + int32 y = int32((vecPosn.y / 50.0f) + 40.0f); + + return x < nOffset || x >= 80 - nOffset || y < nOffset || y >= 80 - nOffset; +} + +bool +CWaterLevel::GetGroundLevel_WS(CVector const &vecPosn, float *pfOutLevel, ColData *pData, float fDistance) +{ + if ( IsLocationOutOfWorldBounds_WS(vecPosn, 0) ) + return false; + else + return GetGroundLevel(vecPosn, pfOutLevel, pData, fDistance); +} + +bool +CWaterLevel::GetWaterDepth(CVector const &vecPosn, float *pfDepth, float *pfLevelNoWaves, float *pfGroundLevel) +{ + float fLevelNoWaves; + float fGroundLevel; + + if ( !GetWaterLevelNoWaves(vecPosn.x, vecPosn.y, vecPosn.z, &fLevelNoWaves) ) + return false; + + if ( !GetGroundLevel(vecPosn, &fGroundLevel, nil, 30.0f) ) + fGroundLevel = -100.0; + + if ( pfDepth != nil ) + *pfDepth = fLevelNoWaves - fGroundLevel; + + if ( pfLevelNoWaves != nil ) + *pfLevelNoWaves = fLevelNoWaves; + + if ( pfGroundLevel != nil ) + *pfGroundLevel = fGroundLevel; + + return true; +} + +void +CWaterLevel::RenderSeaBirds() +{ + CVector cur_pos = TheCamera.GetPosition(); + + if ( !CCullZones::CamNoRain() + && !CCullZones::PlayerNoRain() + && (CWeather::NewWeatherType == WEATHER_SUNNY || CWeather::NewWeatherType == WEATHER_EXTRA_SUNNY) + && CClock::ms_nGameClockHours > 6 && CClock::ms_nGameClockHours < 20 ) + { + static CVector prev_pos(0.0f, 0.0f, 0.0f); + static CVector prev_front(0.0f, 0.0f, 0.0f); + static int32 timecounter; + + if ( Abs(prev_pos.x - cur_pos.x) + Abs(prev_pos.y - cur_pos.y) + Abs(prev_pos.z - cur_pos.z) > 1.5f ) + { + prev_pos = cur_pos; + timecounter = CTimer::GetTimeInMilliseconds(); + } + else if ( (CTimer::GetTimeInMilliseconds() - timecounter) > 5000 ) + { + static int32 birdgenTime = 0; + + if ( (CTimer::GetTimeInMilliseconds() - birdgenTime) > 1000 ) + { + birdgenTime = CTimer::GetTimeInMilliseconds(); + + CVector vecPos = cur_pos; + + float fAngle = CGeneral::GetRandomNumberInRange(90.0f, 150.0f); + + uint16 nSinCosIdx = CGeneral::GetRandomNumber() % (CParticle::SIN_COS_TABLE_SIZE-1); + + float fCos = CParticle::Cos(nSinCosIdx); + float fSin = CParticle::Sin(nSinCosIdx); + + vecPos.x += (fCos - fSin) * fAngle; + vecPos.y += (fSin + fCos) * fAngle; + vecPos.z += CGeneral::GetRandomNumberInRange(10.0f, 30.0f); + + CVector vecDir(CGeneral::GetRandomNumberInRange(-1.0f, 1.0f), + CGeneral::GetRandomNumberInRange(-1.0f, 1.0f), + 0.0f); + + CParticle::AddParticle(PARTICLE_BIRD_FRONT, vecPos, vecDir, nil, 0.0f, 0, 0, 0, 0); + } + } + } +} + +void +CWaterLevel::RenderShipsOnHorizon() +{ +#ifdef FIX_BUGS + CVector cur_pos = FindPlayerCoors(); +#else + CVector cur_pos = FindPlayerPed()->GetPosition(); +#endif + + static CVector prev_pos(0.0f, 0.0f, 0.0f); + static CVector prev_front(0.0f, 0.0f, 0.0f); + static int32 timecounter; + + if ( Abs(prev_pos.x - cur_pos.x) + Abs(prev_pos.y - cur_pos.y) + Abs(prev_pos.z - cur_pos.z) > 1.5f ) + { + prev_pos = cur_pos; + timecounter = CTimer::GetTimeInMilliseconds(); + } + else if ( (CTimer::GetTimeInMilliseconds() - timecounter) > 5000 ) + { + static int32 shipgenTime = 0; + + if ( (CTimer::GetTimeInMilliseconds() - shipgenTime) > 4000 ) + { + shipgenTime = CTimer::GetTimeInMilliseconds(); + + CVector vecPos = cur_pos; + + float fAngle = CGeneral::GetRandomNumberInRange(450.0f, 750.0f); + + uint16 nSinCosIdx = CGeneral::GetRandomNumber() % (CParticle::SIN_COS_TABLE_SIZE-1); + + float fCos = CParticle::Cos(nSinCosIdx); + float fSin = CParticle::Sin(nSinCosIdx); + + vecPos.x += (fCos - fSin) * fAngle; + vecPos.y += (fSin + fCos) * fAngle; + + float fLevelNoWaves; + + if ( GetWaterLevelNoWaves(vecPos.x, vecPos.y, vecPos.z, &fLevelNoWaves) ) + { + if ( IsLocationOutOfWorldBounds_WS(vecPos, 1) ) + { + vecPos.z = fLevelNoWaves + 9.5f; + + CVector vecDir + ( + CGeneral::GetRandomNumberInRange(-0.1f, 0.1f), + 0.0f, + 0.0f + ); + + CParticle::AddParticle(PARTICLE_SHIP_SIDE, vecPos, vecDir, + nil, 0.0f, 0, 0, CGeneral::GetRandomNumber() & 7, 0); + } + } + } + } +} + +void +CWaterLevel::HandleSeaLifeForms() +{ + if ( CReplay::IsPlayingBack() ) + return; + + CVector cur_pos = FindPlayerPed()->GetPosition(); + + static CVector prev_pos(0.0f, 0.0f, 0.0f); + static int32 timecounter; + + if ( Abs(prev_pos.x - cur_pos.x) + Abs(prev_pos.y - cur_pos.y) + Abs(prev_pos.z - cur_pos.z) > 1.5f ) + { + prev_pos = cur_pos; + timecounter = CTimer::GetTimeInMilliseconds(); + } + else if ( (CTimer::GetTimeInMilliseconds() - timecounter) > 5000 ) + { + if ( CWaterCreatures::IsSpaceForMoreWaterCreatures() ) + { + for ( int32 i = 0; i < 3; i++ ) + { + CVector vecPos = cur_pos; + + float fAngle = CGeneral::GetRandomNumberInRange(15.0f, 30.0f); + + uint16 nSinCosIdx = CGeneral::GetRandomNumber() % (CParticle::SIN_COS_TABLE_SIZE-1); + + float fCos = CParticle::Cos(nSinCosIdx); + float fSin = CParticle::Sin(nSinCosIdx); + + vecPos.x += (fCos - fSin) * fAngle; + vecPos.y += (fSin + fCos) * fAngle; + + CWaterCreatures::CreateOne(vecPos, -1); + } + } + } + + CWaterCreatures::UpdateAll(); +} + +void +CWaterLevel::HandleBeachToysStuff(void) +{ +#ifdef FIX_BUGS + CVector cur_pos = FindPlayerCoors(); +#else + CVector cur_pos = FindPlayerPed()->GetPosition(); +#endif + + static bool bBeachBallInit = true; + static CVector FirstBeachBallPos = cur_pos; + static bool bLoungeInit = true; + static CVector FirstLoungePos = cur_pos; + static CVector prev_pos(0.0f, 0.0f, 0.0f); + static int32 timecounter; + + if ( Abs(prev_pos.x - cur_pos.x) + Abs(prev_pos.y - cur_pos.y) + Abs(prev_pos.z - cur_pos.z) > 1.5f ) + { + prev_pos = cur_pos; + timecounter = CTimer::GetTimeInMilliseconds(); + } + else if ( (CTimer::GetTimeInMilliseconds() - timecounter) > 5000 ) + { + static int32 toygenTime = CTimer::GetTimeInMilliseconds(); + + if ( (CTimer::GetTimeInMilliseconds() - toygenTime) > 20000 ) + { + toygenTime = CTimer::GetTimeInMilliseconds(); + + if ( bBeachBallInit || (cur_pos - FirstBeachBallPos).MagnitudeSqr() > 6400.0f ) + { + for ( int32 i = 0; i < 3; i++ ) + { + CVector vecPos = cur_pos; + + float fAngle = CGeneral::GetRandomNumberInRange(20.0f, 35.0f); + + uint16 nSinCosIdx = CGeneral::GetRandomNumber() % (CParticle::SIN_COS_TABLE_SIZE-1); + + float fCos = CParticle::Cos(nSinCosIdx); + float fSin = CParticle::Sin(nSinCosIdx); + + vecPos.x += (fCos - fSin) * fAngle; + vecPos.y += (fSin + fCos) * fAngle; + + if ( TheCamera.IsSphereVisible(vecPos, 1.0f) ) + { + float fWaterLevel; + + if ( !GetWaterLevel(vecPos.x, vecPos.y, vecPos.z, &fWaterLevel, false) ) + { + float fGroundLevel; + ColData coldata; + + if ( GetGroundLevel(vecPos, &fGroundLevel, &coldata, 30.0f) ) + { + if ( coldata.SurfaceType == SURFACE_SAND ) + { + CEntity *toy = CreateBeachToy(vecPos, BEACHTOY_BALL); + + if ( toy ) + { + FirstBeachBallPos = cur_pos; + bBeachBallInit = false; + i = 10; + } + } + } + } + } + } + } + + if ( bLoungeInit || (cur_pos - FirstLoungePos).MagnitudeSqr() > 6400.0f ) + { + for ( int32 i = 0; i < 5; i++ ) + { + CVector vecPos = cur_pos; + + float fAngle = CGeneral::GetRandomNumberInRange(20.0f, 35.0f); + + uint16 nSinCosIdx = CGeneral::GetRandomNumber() % (CParticle::SIN_COS_TABLE_SIZE-1); + + float fCos = CParticle::Cos(nSinCosIdx); + float fSin = CParticle::Sin(nSinCosIdx); + + vecPos.x += (fCos - fSin) * fAngle; + vecPos.y += (fSin + fCos) * fAngle; + + if ( TheCamera.IsSphereVisible(vecPos, 2.0f) ) + { + float fWaterLevel; + + if ( !GetWaterLevel(vecPos.x, vecPos.y, vecPos.z, &fWaterLevel, false) ) + { + float fGroundLevel; + ColData coldata; + + if ( GetGroundLevel(vecPos, &fGroundLevel, &coldata, 30.0f) ) + { + if ( coldata.SurfaceType == SURFACE_SAND ) + { + CEntity *toy = CreateBeachToy(vecPos, BEACHTOY_ANY_LOUNGE); + if ( toy ) + { + toy->SetHeading(DEGTORAD(CGeneral::GetRandomNumberInRange(0.0f, 359.0f))); + FirstLoungePos = cur_pos; + bLoungeInit = false; + } + } + } + } + } + } + } + } + } +} + +CEntity * +CWaterLevel::CreateBeachToy(CVector const &vec, eBeachToy beachtoy) +{ + if (CObject::nNoTempObjects >= NUMTEMPOBJECTS) + return nil; + + int finalToy = beachtoy; + bool isStatic = false; + int model = MI_BEACHBALL; + switch (beachtoy) { + case BEACHTOY_ANY_LOUNGE: + switch ( CGeneral::GetRandomNumber() & 7 ) { + case 1: + case 7: + finalToy = BEACHTOY_LOUNGE_WOOD_UP; + break; + case 3: + case 5: + finalToy = BEACHTOY_LOUNGE_TOWEL_UP; + break; + default: + finalToy = BEACHTOY_LOUNGE_WOOD_ON; + break; + } + break; + case BEACHTOY_ANY_TOWEL: + switch ( CGeneral::GetRandomNumber() & 7 ) { + case 1: + case 7: + finalToy = BEACHTOY_TOWEL2; + break; + case 2: + case 6: + finalToy = BEACHTOY_TOWEL3; + break; + case 3: + case 5: + finalToy = BEACHTOY_TOWEL4; + break; + default: + finalToy = BEACHTOY_TOWEL1; + break; + } + if (CObject::nNoTempObjects >= 35) { + return nil; + } + default: + break; + } + switch (finalToy) { + case BEACHTOY_BALL: + isStatic = false; + model = MI_BEACHBALL; + break; + case BEACHTOY_LOUNGE_WOOD_UP: + isStatic = false; + model = MI_LOUNGE_WOOD_UP; + break; + case BEACHTOY_LOUNGE_TOWEL_UP: + isStatic = false; + model = MI_LOUNGE_TOWEL_UP; + break; + case BEACHTOY_LOUNGE_WOOD_ON: + isStatic = false; + model = MI_LOUNGE_WOOD_DN; + break; + case BEACHTOY_LOTION: + model = MI_LOTION; + isStatic = true; + break; + case BEACHTOY_TOWEL1: + model = MI_BEACHTOWEL01; + isStatic = true; + break; + case BEACHTOY_TOWEL2: + model = MI_BEACHTOWEL02; + isStatic = true; + break; + case BEACHTOY_TOWEL3: + model = MI_BEACHTOWEL03; + isStatic = true; + break; + case BEACHTOY_TOWEL4: + model = MI_BEACHTOWEL04; + isStatic = true; + break; + default: + break; + } + CObject *toy = new CObject(model, true); + if (toy) { + toy->SetPosition(vec); + toy->GetMatrix().UpdateRW(); + toy->m_vecMoveSpeed = CVector(0.f, 0.f, 0.f); + toy->m_vecTurnSpeed = CVector(0.f, 0.f, 0.f); + toy->ObjectCreatedBy = TEMP_OBJECT; + toy->bIsStatic = isStatic; + CObject::nNoTempObjects++; + toy->m_nEndOfLifeTime = CTimer::GetTimeInMilliseconds() + 43200000; + CWorld::Add(toy); + return toy; + } else + return nil; +} \ No newline at end of file diff --git a/src/renderer/WaterLevel.h b/src/renderer/WaterLevel.h new file mode 100644 index 00000000..6d6614d8 --- /dev/null +++ b/src/renderer/WaterLevel.h @@ -0,0 +1,184 @@ +#pragma once + +#define WATER_X_OFFSET (400.0f) + +#define WATER_Z_OFFSET (0.5f) + +#define NO_WATER -128 + +#define MAX_SMALL_SECTORS 128 +#define MAX_LARGE_SECTORS 64 +#define MAX_HUGE_SECTORS 32 +#define MAX_EXTRAHUGE_SECTORS 16 + +#define SMALL_SECTOR_SIZE 32 +#define LARGE_SECTOR_SIZE 64 +#define HUGE_SECTOR_SIZE 128 +#define EXTRAHUGE_SECTOR_SIZE 256 + +#define WATER_START_X -2048.0f +#define WATER_END_X 2048.0f + +#define WATER_START_Y -2048.0f +#define WATER_END_Y 2048.0f + +#define WATER_WIDTH ((WATER_END_X - WATER_START_X)) +#define WATER_HEIGHT ((WATER_END_Y - WATER_START_Y)) + +#define WATER_UNSIGN_X(x) ( (x) + (WATER_WIDTH /2) ) +#define WATER_UNSIGN_Y(y) ( (y) + (WATER_HEIGHT/2) ) +#define WATER_SIGN_X(x) ( (x) - (WATER_WIDTH /2) ) +#define WATER_SIGN_Y(y) ( (y) - (WATER_HEIGHT/2) ) + +// 64x64 Large blocks 64x64 each +#define WATER_TO_BLOCK_X(x) ( WATER_UNSIGN_X(x) / WATER_BLOCK_SECTORS ) +#define WATER_TO_BLOCK_Y(x) ( WATER_UNSIGN_Y(x) / WATER_BLOCK_SECTORS ) + +// 128x128 Small blocks 32x32 each +#define WATER_TO_FINEBLOCK_X(x) ( WATER_UNSIGN_X(x) / WATER_FINEBLOCK_SECTORS ) +#define WATER_TO_FINEBLOCK_Y(x) ( WATER_UNSIGN_Y(x) / WATER_FINEBLOCK_SECTORS ) + +// 32 +#define WATER_SMALL_X(x) ( WATER_UNSIGN_X(x) / MAX_SMALL_SECTORS ) +#define WATER_SMALL_Y(y) ( WATER_UNSIGN_Y(y) / MAX_SMALL_SECTORS ) +#define WATER_FROM_SMALL_SECTOR_X(x) ( ((x) - (MAX_SMALL_SECTORS/2) ) * SMALL_SECTOR_SIZE ) +#define WATER_FROM_SMALL_SECTOR_Y(y) ( ((y) - (MAX_SMALL_SECTORS/2) ) * SMALL_SECTOR_SIZE ) +#define WATER_TO_SMALL_SECTOR_X(x) ( WATER_UNSIGN_X(x) / SMALL_SECTOR_SIZE ) +#define WATER_TO_SMALL_SECTOR_Y(y) ( WATER_UNSIGN_Y(y) / SMALL_SECTOR_SIZE ) + +// 64 +#define WATER_LARGE_X(x) ( WATER_UNSIGN_X(x) / MAX_LARGE_SECTORS ) +#define WATER_LARGE_Y(y) ( WATER_UNSIGN_Y(y) / MAX_LARGE_SECTORS ) +#define WATER_FROM_LARGE_SECTOR_X(x) ( ((x) - (MAX_LARGE_SECTORS/2) ) * LARGE_SECTOR_SIZE ) +#define WATER_FROM_LARGE_SECTOR_Y(y) ( ((y) - (MAX_LARGE_SECTORS/2) ) * LARGE_SECTOR_SIZE ) +#define WATER_TO_LARGE_SECTOR_X(x) ( WATER_UNSIGN_X(x) / LARGE_SECTOR_SIZE ) +#define WATER_TO_LARGE_SECTOR_Y(y) ( WATER_UNSIGN_Y(y) / LARGE_SECTOR_SIZE ) + +// 128 +#define WATER_HUGE_X(x) ( WATER_UNSIGN_X(x) / MAX_HUGE_SECTORS ) +#define WATER_HUGE_Y(y) ( WATER_UNSIGN_Y(y) / MAX_HUGE_SECTORS ) +#define WATER_FROM_HUGE_SECTOR_X(x) ( ((x) - (MAX_HUGE_SECTORS/2) ) * HUGE_SECTOR_SIZE ) +#define WATER_FROM_HUGE_SECTOR_Y(y) ( ((y) - (MAX_HUGE_SECTORS/2) ) * HUGE_SECTOR_SIZE ) +#define WATER_TO_HUGE_SECTOR_X(x) ( WATER_UNSIGN_X(x) / HUGE_SECTOR_SIZE ) +#define WATER_TO_HUGE_SECTOR_Y(y) ( WATER_UNSIGN_Y(y) / HUGE_SECTOR_SIZE ) + +// 256 +#define WATER_EXTRAHUGE_X(x) ( WATER_UNSIGN_X(x) / MAX_EXTRAHUGE_SECTORS ) +#define WATER_EXTRAHUGE_Y(y) ( WATER_UNSIGN_Y(y) / MAX_EXTRAHUGE_SECTORS ) +#define WATER_FROM_EXTRAHUGE_SECTOR_X(x) ( ((x) - (MAX_EXTRAHUGE_SECTORS/2)) * EXTRAHUGE_SECTOR_SIZE ) +#define WATER_FROM_EXTRAHUGE_SECTOR_Y(y) ( ((y) - (MAX_EXTRAHUGE_SECTORS/2)) * EXTRAHUGE_SECTOR_SIZE ) +#define WATER_TO_EXTRAHUGE_SECTOR_X(x) ( WATER_UNSIGN_X(x) / EXTRAHUGE_SECTOR_SIZE ) +#define WATER_TO_EXTRAHUGE_SECTOR_Y(y) ( WATER_UNSIGN_Y(y) / EXTRAHUGE_SECTOR_SIZE ) + +struct ColData +{ + uint8 SurfaceType; + uint8 PieceType; +}; + +enum eBeachToy +{ + BEACHTOY_0 = 0, + BEACHTOY_BALL, + BEACHTOY_LOUNGE_WOOD_UP, + BEACHTOY_LOUNGE_TOWEL_UP, + BEACHTOY_LOUNGE_WOOD_ON, + BEACHTOY_ANY_LOUNGE, + BEACHTOY_LOTION, + BEACHTOY_TOWEL1, + BEACHTOY_TOWEL2, + BEACHTOY_TOWEL3, + BEACHTOY_TOWEL4, + BEACHTOY_ANY_TOWEL, +}; + +extern RwRaster* gpWaterRaster; +extern bool gbDontRenderWater; + +class CEntity; + +class CWaterLevel +{ +public: + static int32 ms_nNoOfWaterLevels; + static float ms_aWaterZs[48]; + static CRect ms_aWaterRects[48]; + static int8 aWaterBlockList[MAX_LARGE_SECTORS][MAX_LARGE_SECTORS]; // 64x64 Large blocks 64x64 each + static int8 aWaterFineBlockList[MAX_SMALL_SECTORS][MAX_SMALL_SECTORS]; // 128x128 Small blocks 32x32 each + static bool WavesCalculatedThisFrame; + + static bool RequireWavySector; + static bool MaskCalculatedThisFrame; + static CVector PreCalculatedMaskPosn; + static bool m_bRenderSeaBed; + static int32 m_nRenderWaterLayers; + + static RpAtomic *ms_pWavyAtomic; + static RpAtomic *ms_pMaskAtomic; + + static void Initialise(Const char *pWaterDat); // out of class in III PC and later because of SecuROM + static void Shutdown(); + + static void CreateWavyAtomic(); + static void DestroyWavyAtomic(); + + static void AddWaterLevel(float fXLeft, float fYBottom, float fXRight, float fYTop, float fLevel); + static bool WaterLevelAccordingToRectangles(float fX, float fY, float *pfOutLevel = nil); + static bool TestVisibilityForFineWaterBlocks(const CVector &worldPos); + static void RemoveIsolatedWater(); + + static bool GetWaterLevel(float fX, float fY, float fZ, float *pfOutLevel, bool bDontCheckZ); + static bool GetWaterLevel(CVector coors, float *pfOutLevel, bool bDontCheckZ) { return GetWaterLevel(coors.x, coors.y, coors.z, pfOutLevel, bDontCheckZ); } + static bool GetWaterLevelNoWaves(float fX, float fY, float fZ, float *pfOutLevel); + static float GetWaterWavesOnly(short x, short y); // unused + static CVector GetWaterNormal(float fX, float fY); + + static void RenderWater(); + static void RenderTransparentWater(void); + // unused + static void RenderOneFlatSmallWaterPoly (float fX, float fY, float fZ, RwRGBA const &color); + // inlined + static void RenderOneFlatLargeWaterPoly (float fX, float fY, float fZ, RwRGBA const &color); + static void RenderOneFlatHugeWaterPoly (float fX, float fY, float fZ, RwRGBA const &color); + static void RenderOneFlatExtraHugeWaterPoly(float fX, float fY, float fZ, RwRGBA const &color); + // inlined + static void RenderOneWavySector (float fX, float fY, float fZ, RwRGBA const &color, bool bDontRender = false); + // unused +#ifdef PC_WATER + static void RenderWavyMask(float fX, float fY, float fZ, float fSectorX, float fSectorY, float fCamPosX, float fCamPosY, float fCamDirX, float fCamDirY, RwRGBA const&color); +#else + static void RenderWavyMask(float fX, float fY, float fZ, float fSectorX, float fSectorY, int32 nCamDirX, int32 nCamDirY, RwRGBA const&color); +#endif + +#ifdef PC_WATER + static void PreCalcWaterGeometry(void); + static bool PreCalcWavySector(RwRGBA const &color); //fucked up + static bool PreCalcWavyMask(float fX, float fY, float fZ, float fSectorX, float fSectorY, float fCamPosX, float fCamPosY, float fCamDirX, float fCamDirY, RwRGBA const&color); +#endif + + + static void RenderBoatWakes(void); + static void RenderWakeSegment(CVector2D &vecA, CVector2D &vecB, CVector2D &vecC, CVector2D &vecD, float &fSizeA, float &fSizeB, float &fAlphaA, float &fAlphaB, float &fWakeZ); + + // unused + static void RenderOneSlopedUnderWaterPoly(float fX, float fY, float fZ, RwRGBA const&color); // UNUSED + static void RenderOneFlatSmallWaterPolyBlended(float fX, float fY, float fZ, float fCamX, float fCamY, RwRGBA const &color, RwRGBA const &colorTrans, float fDrawDist); + static float CalcDistanceToWater(float fX, float fY); + static void RenderAndEmptyRenderBuffer(); + + static bool GetGroundLevel(CVector const &vecPosn, float *pfOutLevel, ColData *pData, float fDistance); + + // unused + static bool IsLocationOutOfWorldBounds_WS(CVector const &vecPosn, int nOffset); + // unused + static bool GetGroundLevel_WS(CVector const & vecPosn, float *pfOutLevel, ColData *pData, float fDistance); + static bool GetWaterDepth(CVector const &vecPosn, float *pfDepth, float *pfLevelNoWaves, float *pfGroundLevel); + + static void RenderSeaBirds(); + static void RenderShipsOnHorizon(); + + static void HandleSeaLifeForms(); + + static void HandleBeachToysStuff(void); + static CEntity *CreateBeachToy(CVector const &vec, eBeachToy beachtoy); +}; diff --git a/src/renderer/Weather.cpp b/src/renderer/Weather.cpp new file mode 100644 index 00000000..9f925a8c --- /dev/null +++ b/src/renderer/Weather.cpp @@ -0,0 +1,662 @@ +#include "common.h" + +#include "Weather.h" + +#include "Camera.h" +#include "Clock.h" +#include "CutsceneMgr.h" +#include "DMAudio.h" +#include "General.h" +#include "Pad.h" +#include "PlayerPed.h" +#include "Particle.h" +#include "RenderBuffer.h" +#include "Stats.h" +#include "Shadows.h" +#include "Timecycle.h" +#include "Timer.h" +#include "Vehicle.h" +#include "World.h" +#include "ZoneCull.h" +#include "SpecialFX.h" +#include "Replay.h" + +int32 CWeather::SoundHandle = -1; + +int32 CWeather::WeatherTypeInList; +int16 CWeather::OldWeatherType; +int16 CWeather::NewWeatherType; +int16 CWeather::ForcedWeatherType; + +bool CWeather::LightningFlash; +bool CWeather::LightningBurst; +uint32 CWeather::LightningStart; +uint32 CWeather::LightningFlashLastChange; +uint32 CWeather::WhenToPlayLightningSound; +uint32 CWeather::LightningDuration; +int32 CWeather::StreamAfterRainTimer; + +float CWeather::ExtraSunnyness; +float CWeather::Foggyness; +float CWeather::CloudCoverage; +float CWeather::Wind; +float CWeather::Rain; +float CWeather::InterpolationValue; +float CWeather::WetRoads; +float CWeather::Rainbow; +float CWeather::SunGlare; +float CWeather::WindClipped; +float CWeather::TrafficLightBrightness; + +bool CWeather::bScriptsForceRain; + +tRainStreak Streaks[NUM_RAIN_STREAKS]; + +int16 WeatherTypesList[] = { + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, + WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, + WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, + WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_CLOUDY, + WEATHER_RAINY, WEATHER_RAINY, WEATHER_RAINY, WEATHER_RAINY, + WEATHER_CLOUDY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, + WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY +}; + +int16 WeatherTypesList_WithHurricanes[] = { + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, + WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_CLOUDY, + WEATHER_HURRICANE, WEATHER_HURRICANE, WEATHER_CLOUDY, WEATHER_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, + WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, + WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, + WEATHER_CLOUDY, WEATHER_HURRICANE, WEATHER_HURRICANE, WEATHER_HURRICANE, + WEATHER_CLOUDY, WEATHER_SUNNY, WEATHER_SUNNY, WEATHER_SUNNY, + WEATHER_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, + WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY, WEATHER_EXTRA_SUNNY +}; + +const float Windyness[] = { + 0.25f,// WEATHER_SUNNY + 0.7f, // WEATHER_CLOUDY + 1.0f, // WEATHER_RAINY + 0.0f, // WEATHER_FOGGY + 0.0f, // WEATHER_EXTRA_SUNNY + 2.0f, // WEATHER_HURRICANE + 0.0f +}; + +#define MIN_TIME_BETWEEN_LIGHTNING_FLASH_CHANGES (50) + +#define RAIN_CHANGE_SPEED (0.003f) + +#define DROPLETS_LEFT_OFFSET (10.0f) +#define DROPLETS_RIGHT_OFFSET (10.0f) +#define DROPLETS_TOP_OFFSET (10.0f) +#define DROPLETS_BOTTOM_OFFSET (10.0f) + +#define STREAK_U (10.0f) +#define STREAK_V (18.0f) +#define LARGE_STREAK_COEFFICIENT (1.23f) +#define STREAK_MIN_DISTANCE (8.0f) +#define STREAK_MAX_DISTANCE (16.0f) + +#define SPLASH_CHECK_RADIUS (7.0f) +#define SPLASH_OFFSET_RADIUS (2.0f) + +#define STREAK_LIFETIME (4.0f) +#define STREAK_INTEROLATION_TIME (0.3f) + +#define RAIN_COLOUR_R (200) +#define RAIN_COLOUR_G (200) +#define RAIN_COLOUR_B (256) +#define RAIN_ALPHA (255) + +void CWeather::Init(void) +{ + NewWeatherType = WEATHER_EXTRA_SUNNY; + bScriptsForceRain = false; + OldWeatherType = WEATHER_EXTRA_SUNNY; + InterpolationValue = 0.0f; + WhenToPlayLightningSound = 0; + WeatherTypeInList = 0; + ForcedWeatherType = WEATHER_RANDOM; + SoundHandle = DMAudio.CreateEntity(AUDIOTYPE_WEATHER, (void*)1); + if (SoundHandle >= 0) + DMAudio.SetEntityStatus(SoundHandle, TRUE); +} + +void CWeather::Update(void) +{ + if(!CReplay::IsPlayingBack()){ + float fNewInterpolation = (CClock::GetMinutes() + CClock::GetSeconds()/60.0f)/60.0f; + if (fNewInterpolation < InterpolationValue) { + // new hour + OldWeatherType = NewWeatherType; + if (ForcedWeatherType >= 0) + NewWeatherType = ForcedWeatherType; + else { + WeatherTypeInList = (WeatherTypeInList + 1) % ARRAY_SIZE(WeatherTypesList); + NewWeatherType = CStats::NoMoreHurricanes ? WeatherTypesList[WeatherTypeInList] : WeatherTypesList_WithHurricanes[WeatherTypeInList]; + } + } + InterpolationValue = fNewInterpolation; + } + +#ifndef FINAL + if (CPad::GetPad(1)->GetRightShockJustDown()) { + NewWeatherType = (NewWeatherType + 1) % WEATHER_TOTAL; + OldWeatherType = NewWeatherType; + } +#endif + + // Lightning + if (NewWeatherType != WEATHER_RAINY || OldWeatherType != WEATHER_RAINY) { + LightningFlash = false; + LightningBurst = false; + } + else{ + if (LightningBurst) { + if ((CGeneral::GetRandomNumber() & 255) >= 32) { + // 0.875 probability + if (CTimer::GetTimeInMilliseconds() - LightningFlashLastChange > MIN_TIME_BETWEEN_LIGHTNING_FLASH_CHANGES) { + bool bOldLightningFlash = LightningFlash; + LightningFlash = CGeneral::GetRandomTrueFalse(); + if (LightningFlash != bOldLightningFlash) + LightningFlashLastChange = CTimer::GetTimeInMilliseconds(); + } + } + else { + // 0.125 probability + LightningBurst = false; + LightningDuration = Min(CTimer::GetFrameCounter() - LightningStart, 20); + LightningFlash = false; + WhenToPlayLightningSound = CTimer::GetTimeInMilliseconds() + 150 * (20 - LightningDuration); + } + } + else { + if (CGeneral::GetRandomNumber() >= 200) { + // lower probability on PC due to randomness bug + LightningFlash = false; + } + else { + LightningBurst = true; + LightningStart = CTimer::GetFrameCounter(); + LightningFlashLastChange = CTimer::GetTimeInMilliseconds(); + LightningFlash = true; + } + } + } + if (WhenToPlayLightningSound && CTimer::GetTimeInMilliseconds() > WhenToPlayLightningSound) { + DMAudio.PlayOneShot(SoundHandle, SOUND_LIGHTNING, LightningDuration); + CPad::GetPad(0)->StartShake(40 * LightningDuration + 100, 2 * LightningDuration + 80); + WhenToPlayLightningSound = 0; + } + + // Wet roads + if (OldWeatherType == WEATHER_RAINY || OldWeatherType == WEATHER_HURRICANE) { + if (NewWeatherType == WEATHER_RAINY || NewWeatherType == WEATHER_HURRICANE) + WetRoads = 1.0f; + else + WetRoads = 1.0f - InterpolationValue; + } + else { + if (NewWeatherType == WEATHER_RAINY || NewWeatherType == WEATHER_HURRICANE) + WetRoads = InterpolationValue; + else + WetRoads = 0.0f; + } + + // Rain + float fNewRain; + if (NewWeatherType == WEATHER_RAINY || NewWeatherType == WEATHER_HURRICANE) { + // if raining for >1 hour, values: 0, 0.33, switching every ~16.5s + fNewRain = (((uint16)CTimer::GetTimeInMilliseconds() >> 14) & 1) * 0.33f; + if (OldWeatherType != WEATHER_RAINY && OldWeatherType != WEATHER_HURRICANE) { + if (InterpolationValue < 0.4f) + // if rain has just started (<24 minutes), always 0.5 + fNewRain = 0.5f; + else + // if rain is ongoing for >24 minutes, values: 0.25, 0.5, switching every ~16.5s + fNewRain = 0.25f + (((uint16)CTimer::GetTimeInMilliseconds() >> 14) & 1) * 0.25f; + } + fNewRain = Max(fNewRain, 0.5f); + } + else + fNewRain = 0.0f; + Rain = fNewRain; + + // Clouds + if (OldWeatherType != WEATHER_SUNNY && OldWeatherType != WEATHER_EXTRA_SUNNY) + CloudCoverage = 1.0f - InterpolationValue; + else + CloudCoverage = 0.0f; + if (NewWeatherType != WEATHER_SUNNY && OldWeatherType != WEATHER_EXTRA_SUNNY) + CloudCoverage += InterpolationValue; + + // Fog + if (OldWeatherType == WEATHER_FOGGY) + Foggyness = 1.0f - InterpolationValue; + else + Foggyness = 0.0f; + if (NewWeatherType == WEATHER_FOGGY) + Foggyness += InterpolationValue; + + // Extra Sunnyness + if (OldWeatherType == WEATHER_EXTRA_SUNNY) + ExtraSunnyness = 1.0f - InterpolationValue; + else + ExtraSunnyness = 0.0f; + if (NewWeatherType == WEATHER_EXTRA_SUNNY) + ExtraSunnyness += InterpolationValue; + + // Rainbow + if (OldWeatherType == WEATHER_CLOUDY && (NewWeatherType == WEATHER_SUNNY || NewWeatherType == WEATHER_EXTRA_SUNNY) && + InterpolationValue < 0.5f && CClock::GetHours() > 6 && CClock::GetHours() < 21) + Rainbow = 1.0f - 4.0f * Abs(InterpolationValue - 0.25f) / 4.0f; + else + Rainbow = 0.0f; + + // Sun Glare + if (OldWeatherType == WEATHER_EXTRA_SUNNY) + SunGlare = 1.0f - InterpolationValue; + else + SunGlare = 0.0f; + if (NewWeatherType == WEATHER_EXTRA_SUNNY) + SunGlare += InterpolationValue; + + if (SunGlare > 0.0f) { + SunGlare *= Min(1.0f, 7.0 * CTimeCycle::GetSunDirection().z); + SunGlare = Clamp(SunGlare, 0.0f, 1.0f); + if (!CSpecialFX::bSnapShotActive) + SunGlare *= (1.0f - (CGeneral::GetRandomNumber()&0x1F)*0.007f); + } + + Wind = InterpolationValue * Windyness[NewWeatherType] + (1.0f - InterpolationValue) * Windyness[OldWeatherType]; + WindClipped = Min(1.0f, Wind); + + if (CClock::GetHours() > 20) + TrafficLightBrightness = 1.0f; + else if (CClock::GetHours() > 19) + TrafficLightBrightness = CClock::GetMinutes() / 60.0f; + else if (CClock::GetHours() > 6) + TrafficLightBrightness = 0.0f; + else if (CClock::GetHours() > 5) + TrafficLightBrightness = 1.0f - CClock::GetMinutes() / 60.0f; + else + TrafficLightBrightness = 1.0f; + TrafficLightBrightness = Max(WetRoads, TrafficLightBrightness); + TrafficLightBrightness = Max(Foggyness, TrafficLightBrightness); + TrafficLightBrightness = Max(Rain, TrafficLightBrightness); + + AddRain(); + + if ((NewWeatherType == WEATHER_SUNNY || NewWeatherType == WEATHER_EXTRA_SUNNY) && + !CGame::IsInInterior() && !CCutsceneMgr::IsRunning() && (CTimer::GetFrameCounter() & 7) == 0) { +#ifdef FIX_BUGS + if (FindPlayerPed() && (!FindPlayerPed()->CheckIfInTheAir() || FindPlayerPed()->CheckIfInTheAir() && FindPlayerPed()->GetPosition().z < 7.5f && + CClock::GetHours() > 6 && CClock::GetHours() < 18)) +#else + if (!FindPlayerPed()->CheckIfInTheAir() || FindPlayerPed()->CheckIfInTheAir() && FindPlayerPed()->GetPosition().z < 7.5f && + CClock::GetHours() > 6 && CClock::GetHours() < 18) +#endif + AddHeatHaze(); + } + + if ((NewWeatherType == WEATHER_SUNNY || NewWeatherType == WEATHER_EXTRA_SUNNY) && !CGame::IsInInterior() && !CCutsceneMgr::IsRunning()) + AddBeastie(); +} + +void CWeather::AddHeatHaze() +{ + if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN || + TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED) + return; + CVector pos; + pos.x = SCREEN_WIDTH*0.5f; + if(TheCamera.GetLookingForwardFirstPerson()) + pos.y = CGeneral::GetRandomNumberInRange(SCREEN_HEIGHT*0.25f, SCREEN_HEIGHT*0.9f); + else + pos.y = CGeneral::GetRandomNumberInRange(SCREEN_HEIGHT*0.4f, SCREEN_HEIGHT*0.9f); + pos.z = 100.0f; + CParticle::AddParticle(PARTICLE_HEATHAZE_IN_DIST, pos, CVector(0.0f, 0.0f, 0.0f)); +} + +void CWeather::AddBeastie() +{ + if(FindPlayerVehicle() || CTimer::GetFrameCounter()%10 || (CGeneral::GetRandomNumber()&5) == 0) + return; + CVector pos = TheCamera.GetPosition(); + float dist = CGeneral::GetRandomNumberInRange(90.0f, 60.0f); + int angle = CGeneral::GetRandomNumber() % CParticle::SIN_COS_TABLE_SIZE; + float c = CParticle::m_CosTable[angle]; + float s = CParticle::m_SinTable[angle]; + pos.x += dist*(c - s); + pos.y += dist*(c + s); + pos.z += CGeneral::GetRandomNumberInRange(7.5f, 30.0f); + CParticle::AddParticle(PARTICLE_BEASTIE, pos, CVector(0.0f, 0.0f, 0.0f)); +} + +void CWeather::ForceWeather(int16 weather) +{ + ForcedWeatherType = weather; +} + +void CWeather::ForceWeatherNow(int16 weather) +{ + OldWeatherType = weather; + NewWeatherType = weather; + ForcedWeatherType = weather; +} + +void CWeather::ReleaseWeather() +{ + ForcedWeatherType = -1; +} + +void CWeather::AddSplashesDuringHurricane() +{ + RwRGBA colour = { 255, 255, 255, 32 }; + CVector pos = TheCamera.pTargetEntity ? TheCamera.pTargetEntity->GetPosition() : TheCamera.GetPosition(); + bool foundGround; + float groundZ = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z, &foundGround) + 0.1f; + if(!foundGround) + groundZ = pos.z + 0.5f; + for(int i = 0; i < 20; i++){ + float dist = (CGeneral::GetRandomNumber()&0xFF)/255.0f + + CGeneral::GetRandomNumberInRange(-10.0f, 30.0f); + float angle; + uint8 rnd = CGeneral::GetRandomNumber(); + if(rnd&1) + angle = (CGeneral::GetRandomNumber()&0x7F)/128.0f * TWOPI; + else + angle = TheCamera.Orientation + (rnd-128)/160.0f; + pos.x = TheCamera.GetPosition().x + dist*Sin(angle); + pos.y = TheCamera.GetPosition().y + dist*Cos(angle); + pos.z = groundZ; + if(foundGround) + CParticle::AddParticle(PARTICLE_GROUND_STEAM, pos, CVector(-0.002f, -0.002f, 0.015f), nil, 0.0f, colour); + } +} + +static int startStreamAfterRain; + +void CWeather::AddStreamAfterRain() +{ + if(CClock::GetHours() > 6 && CClock::GetHours() < 18){ + RwRGBA colour = { 255, 255, 255, 24 }; + CVector pos = TheCamera.pTargetEntity ? TheCamera.pTargetEntity->GetPosition() : TheCamera.GetPosition(); + bool foundGround; + float groundZ = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z, &foundGround) + 0.2f; + if(!foundGround) + groundZ = pos.z + 0.75f; + for(int i = 0; i < 20; i++){ + float dist = (CGeneral::GetRandomNumber()&0xFF)/255.0f + + CGeneral::GetRandomNumberInRange(-10.0f, 30.0f); + float angle; + uint8 rnd = CGeneral::GetRandomNumber(); + if(rnd&1) + angle = (CGeneral::GetRandomNumber()&0x7F)/128.0f * TWOPI; + else + angle = TheCamera.Orientation + (rnd-128)/160.0f; + pos.x = TheCamera.GetPosition().x + dist*Sin(angle); + pos.y = TheCamera.GetPosition().y + dist*Cos(angle); + pos.z = groundZ; + CParticle::AddParticle(PARTICLE_GROUND_STEAM, pos, CVector(0.0f, 0.0f, 0.015f), nil, 0.0f, colour); + } + }else{ + startStreamAfterRain = 0; + StreamAfterRainTimer = 800; + } +} + +void CWeather::AddRain() +{ + if (CCullZones::CamNoRain() || CCullZones::PlayerNoRain()) + return; + if (TheCamera.GetLookingLRBFirstPerson()) { + CVehicle* pVehicle = FindPlayerVehicle(); + if (pVehicle && pVehicle->CarHasRoof()) { + CParticle::RemovePSystem(PARTICLE_RAINDROP_2D); + return; + } + } + + if(Rain > 0.0){ + startStreamAfterRain = 1; + StreamAfterRainTimer = 800; + }else if(startStreamAfterRain){ + if(StreamAfterRainTimer > 0){ + AddStreamAfterRain(); + StreamAfterRainTimer--; + }else{ + startStreamAfterRain = 0; + StreamAfterRainTimer = 800; + } + } + + if (Wind > 1.1f) + AddSplashesDuringHurricane(); + + if (Rain <= 0.1f) + return; + static RwRGBA colour; + int numDrops = 5.0f * Rain; + int numSplashes = 2.0f * Rain; + CVector pos, dir; + for(int i = 0; i < numDrops; i++){ + pos.x = CGeneral::GetRandomNumberInRange(0, (int)SCREEN_WIDTH); + pos.y = CGeneral::GetRandomNumberInRange(0, (int)SCREEN_HEIGHT/5); + pos.z = 0.0f; + dir.x = 0.0f; + dir.y = CGeneral::GetRandomNumberInRange(30.0f, 40.0f); + dir.z = 0.0f; + CParticle::AddParticle(PARTICLE_RAINDROP_2D, pos, dir, nil, CGeneral::GetRandomNumberInRange(0.1f, 0.75f), 0, 0, (int)Rain&3, 0); + + pos.x = CGeneral::GetRandomNumberInRange(0, (int)SCREEN_WIDTH); + pos.y = CGeneral::GetRandomNumberInRange((int)SCREEN_HEIGHT/5, (int)SCREEN_HEIGHT/2); + pos.z = 0.0f; + dir.x = 0.0f; + dir.y = CGeneral::GetRandomNumberInRange(30.0f, 40.0f); + dir.z = 0.0f; + CParticle::AddParticle(PARTICLE_RAINDROP_2D, pos, dir, nil, CGeneral::GetRandomNumberInRange(0.1f, 0.75f), 0, 0, (int)Rain&3, 0); + + pos.x = CGeneral::GetRandomNumberInRange(0, (int)SCREEN_WIDTH); + pos.y = 0.0f; + pos.z = 0.0f; + dir.x = 0.0f; + dir.y = CGeneral::GetRandomNumberInRange(30.0f, 40.0f); + dir.z = 0.0f; + CParticle::AddParticle(PARTICLE_RAINDROP_2D, pos, dir, nil, CGeneral::GetRandomNumberInRange(0.1f, 0.75f), 0, 0, (int)Rain&3, 0); + + float dist = CGeneral::GetRandomNumberInRange(0.0f, Max(10.0f*Rain, 40.0f)/2.0f); + float angle; + uint8 rnd = CGeneral::GetRandomNumber(); + if(rnd&1) + angle = (CGeneral::GetRandomNumber()&0x7F)/128.0f * TWOPI; + else + angle = TheCamera.Orientation + (rnd-128)/160.0f; + pos.x = TheCamera.GetPosition().x + dist*Sin(angle); + pos.y = TheCamera.GetPosition().y + dist*Cos(angle); + pos.z = 0.0f; + CColPoint point; + CEntity *ent; + if(CWorld::ProcessVerticalLine(pos+CVector(0.0f, 0.0f, 40.0f), -40.0f, point, ent, true, false, false, false, true, false, nil)){ + pos.z = point.point.z; + for(int j = 0; j < numSplashes+15; j++){ + CVector pos2 = pos; + pos2.x += CGeneral::GetRandomNumberInRange(-15.0f, 15.0f); + pos2.y += CGeneral::GetRandomNumberInRange(-15.0f, 15.0f); + if(CGeneral::GetRandomNumber() & 1) + CParticle::AddParticle(PARTICLE_RAIN_SPLASH, pos2, CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, colour); + else + CParticle::AddParticle(PARTICLE_RAIN_SPLASHUP, pos2, CVector(0.0f, 0.0f, 0.0f), nil, 0.0f, colour); + } + } + } +} + +void RenderOneRainStreak(CVector pos, CVector unused, int intensity, bool scale, float distance) +{ + static float RandomTex; + static float RandomTexX; + static float RandomTexY; + TempBufferRenderIndexList[TempBufferIndicesStored + 0] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[TempBufferIndicesStored + 1] = TempBufferVerticesStored + 2; + TempBufferRenderIndexList[TempBufferIndicesStored + 2] = TempBufferVerticesStored + 1; + TempBufferRenderIndexList[TempBufferIndicesStored + 3] = TempBufferVerticesStored + 0; + TempBufferRenderIndexList[TempBufferIndicesStored + 4] = TempBufferVerticesStored + 3; + TempBufferRenderIndexList[TempBufferIndicesStored + 5] = TempBufferVerticesStored + 2; + TempBufferRenderIndexList[TempBufferIndicesStored + 6] = TempBufferVerticesStored + 1; + TempBufferRenderIndexList[TempBufferIndicesStored + 7] = TempBufferVerticesStored + 2; + TempBufferRenderIndexList[TempBufferIndicesStored + 8] = TempBufferVerticesStored + 4; + TempBufferRenderIndexList[TempBufferIndicesStored + 9] = TempBufferVerticesStored + 2; + TempBufferRenderIndexList[TempBufferIndicesStored + 10] = TempBufferVerticesStored + 3; + TempBufferRenderIndexList[TempBufferIndicesStored + 11] = TempBufferVerticesStored + 4; + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + 0], 0, 0, 0, 0); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + 0], pos.x + 11.0f * TheCamera.GetUp().x, pos.y + 11.0f * TheCamera.GetUp().y, pos.z + 11.0f * TheCamera.GetUp().z); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + 1], 0, 0, 0, 0); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + 1], pos.x - 9.0f * TheCamera.GetRight().x, pos.y - 9.0f * TheCamera.GetRight().y, pos.z - 9.0f * TheCamera.GetRight().z); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + 2], RAIN_COLOUR_R * intensity / 256, RAIN_COLOUR_G * intensity / 256, RAIN_COLOUR_B * intensity / 256, RAIN_ALPHA); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + 2], pos.x, pos.y, pos.z); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + 3], 0, 0, 0, 0); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + 3], pos.x + 9.0f * TheCamera.GetRight().x, pos.y + 9.0f * TheCamera.GetRight().y, pos.z + 9.0f * TheCamera.GetRight().z); + RwIm3DVertexSetRGBA(&TempBufferRenderVertices[TempBufferVerticesStored + 4], 0, 0, 0, 0); + RwIm3DVertexSetPos(&TempBufferRenderVertices[TempBufferVerticesStored + 4], pos.x - 11.0f * TheCamera.GetUp().x, pos.y - 11.0f * TheCamera.GetUp().y, pos.z - 11.0f * TheCamera.GetUp().z); + float u = STREAK_U; + float v = STREAK_V; + if (scale) { + u *= LARGE_STREAK_COEFFICIENT; + v *= LARGE_STREAK_COEFFICIENT; + } + float distance_coefficient; + if (distance < STREAK_MIN_DISTANCE) + distance_coefficient = 1.0f; + else if (distance > STREAK_MAX_DISTANCE) + distance_coefficient = 0.5f; + else + distance_coefficient = 1.0f - 0.5f * (distance - STREAK_MIN_DISTANCE) / (STREAK_MAX_DISTANCE - STREAK_MIN_DISTANCE); + u *= distance_coefficient; + v *= distance_coefficient; + if (!CTimer::GetIsPaused()) { + RandomTex = 0.0f; + RandomTexX = 0.0f; + RandomTexY = 0.0f; + } + RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored + 0], 0.5f * u - RandomTex + RandomTexX); + RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored + 0], -v * 0.5f + RandomTexY); + RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored + 1], RandomTexX); + RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored + 1], RandomTexY); + RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored + 2], 0.5f * u + RandomTexX); + RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored + 2], RandomTexY); + RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored + 3], u + RandomTexX); + RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored + 3], RandomTexY); + RwIm3DVertexSetU(&TempBufferRenderVertices[TempBufferVerticesStored + 4], 0.5f * u + RandomTex + RandomTexX); + RwIm3DVertexSetV(&TempBufferRenderVertices[TempBufferVerticesStored + 5], 0.5f * v + RandomTexY); + TempBufferIndicesStored += 12; + TempBufferVerticesStored += 5; +} + +void CWeather::RenderRainStreaks(void) +{ + if (CTimer::GetIsCodePaused()) + return; + int base_intensity = (64.0f - CTimeCycle::GetFogReduction()) / 64.0f * int(255 * Rain); + if (base_intensity == 0) + return; + if (TheCamera.m_CameraAverageSpeed > 1.75f) + return; + TempBufferIndicesStored = 0; + TempBufferVerticesStored = 0; + for (int i = 0; i < NUM_RAIN_STREAKS; i++) { + if (Streaks[i].timer) { + float secondsElapsed = (CTimer::GetTimeInMilliseconds() - Streaks[i].timer) / 1024.0f; + if (secondsElapsed > STREAK_LIFETIME) + Streaks[i].timer = 0; + else{ + int intensity; + if (secondsElapsed < STREAK_INTEROLATION_TIME) + intensity = base_intensity * 0.25f * secondsElapsed / STREAK_INTEROLATION_TIME; + else if (secondsElapsed > (STREAK_LIFETIME - STREAK_INTEROLATION_TIME)) + intensity = (STREAK_LIFETIME - secondsElapsed) * 0.25f * base_intensity / STREAK_INTEROLATION_TIME; + else + intensity = base_intensity * 0.25f; + CVector dir = Streaks[i].direction; + dir.Normalise(); + CVector pos = Streaks[i].position + secondsElapsed * Streaks[i].direction; + RenderOneRainStreak(pos, dir, intensity, false, (pos - TheCamera.GetPosition()).Magnitude()); +#ifndef FIX_BUGS // remove useless code + if (secondsElapsed > 1.0f && secondsElapsed < STREAK_LIFETIME - 1.0f) { + CGeneral::GetRandomNumber(), CGeneral::GetRandomNumber(); + } +#endif + } + } + else if ((CGeneral::GetRandomNumber() & 0xF00) == 0){ + // 1/16 probability + Streaks[i].direction = CVector(0.0f, 0.0f, -12.0f); + Streaks[i].position = 6.0f * TheCamera.GetForward() + TheCamera.GetPosition() + CVector(-1.8f * Streaks[i].direction.x, -1.8f * Streaks[i].direction.y, 8.0f); + if (!CCutsceneMgr::IsRunning()) { + Streaks[i].position.x += 2.0f * FindPlayerSpeed().x * 60.0f; + Streaks[i].position.y += 2.0f * FindPlayerSpeed().y * 60.0f; + } + else + Streaks[i].position += (TheCamera.GetPosition() - TheCamera.m_RealPreviousCameraPosition) * 20.0f; + Streaks[i].position.x += ((CGeneral::GetRandomNumber() & 255) - 128) * 0.04f; + Streaks[i].position.y += ((CGeneral::GetRandomNumber() & 255) - 128) * 0.04f; + Streaks[i].timer = CTimer::GetTimeInMilliseconds(); + } + } + if (TempBufferIndicesStored){ + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEFOGTYPE, (void*)rwFOGTYPELINEAR); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDONE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpRainDropTex)); + if (RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, nil, 1)) + { + RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored); + RwIm3DEnd(); + } + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)TRUE); + RwRenderStateSet(rwRENDERSTATESRCBLEND, (void*)rwBLENDSRCALPHA); + RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void*)rwBLENDINVSRCALPHA); + RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void*)FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)FALSE); + } + TempBufferVerticesStored = 0; + TempBufferIndicesStored = 0; +} + +#ifdef SECUROM +void CWeather::ForceHurricaneWeather() +{ + for (int i = 0; i < ARRAY_SIZE(WeatherTypesList_WithHurricanes); i++) + { + WeatherTypesList[i] = WEATHER_HURRICANE; + WeatherTypesList_WithHurricanes[i] = WEATHER_HURRICANE; + } + + CWeather::OldWeatherType = WEATHER_HURRICANE; + CWeather::NewWeatherType = WEATHER_HURRICANE; + CWeather::ForcedWeatherType = WEATHER_HURRICANE; +} +#endif diff --git a/src/renderer/Weather.h b/src/renderer/Weather.h new file mode 100644 index 00000000..bda57d55 --- /dev/null +++ b/src/renderer/Weather.h @@ -0,0 +1,73 @@ +enum { + WEATHER_RANDOM = -1, + WEATHER_SUNNY = 0, + WEATHER_CLOUDY, + WEATHER_RAINY, + WEATHER_FOGGY, + WEATHER_EXTRA_SUNNY, + WEATHER_HURRICANE, + WEATHER_TOTAL, + + WEATHER_EXTRACOLOURS = 6 +}; + +class CWeather +{ +public: + static int32 SoundHandle; + + static int32 WeatherTypeInList; + static int16 OldWeatherType; + static int16 NewWeatherType; + static int16 ForcedWeatherType; + + static bool LightningFlash; + static bool LightningBurst; + static uint32 LightningStart; + static uint32 LightningFlashLastChange; + static uint32 WhenToPlayLightningSound; + static uint32 LightningDuration; + static int32 StreamAfterRainTimer; + + static float ExtraSunnyness; + static float Foggyness; + static float CloudCoverage; + static float Wind; + static float Rain; + static float InterpolationValue; + static float WetRoads; + static float Rainbow; + static float SunGlare; + static float WindClipped; + static float TrafficLightBrightness; + + static bool bScriptsForceRain; + + static void RenderRainStreaks(void); + static void Update(void); + static void Init(void); + + static void ReleaseWeather(); + static void ForceWeather(int16); + static void ForceWeatherNow(int16); + static void AddSplashesDuringHurricane(); + static void AddStreamAfterRain(); + static void AddRain(); + static void AddHeatHaze(); + static void AddBeastie(); + + static void ForceHurricaneWeather(); +}; + +enum { + NUM_RAIN_STREAKS = 35 +}; + +struct tRainStreak +{ + CVector position; + CVector direction; + uint32 timer; +}; + +extern RwTexture* gpRainDropTex; \ No newline at end of file diff --git a/src/renderer/WindModifiers.cpp b/src/renderer/WindModifiers.cpp new file mode 100644 index 00000000..3bd6ac9c --- /dev/null +++ b/src/renderer/WindModifiers.cpp @@ -0,0 +1,52 @@ +#include "common.h" +#include "WindModifiers.h" +#include "Camera.h" +#include "General.h" + +#define MAX_HEIGHT_DIST 40.0f +#define MIN_FADE_DIST 20.0f +#define MAX_FADE_DIST 50.0f + +CWindModifiers Array[16]; +int32 CWindModifiers::Number; + +void +CWindModifiers::RegisterOne(CVector pos, int32 type = 1) +{ + if (CWindModifiers::Number < 16 && (pos - TheCamera.GetPosition()).Magnitude() < 100.0f) { + Array[Number].m_pos = pos; + Array[Number].m_type = type; + Number++; + } +} + +bool +CWindModifiers::FindWindModifier(CVector pos, float *x, float *y) +{ + bool bWasWindModifierFound = false; + CVector2D dir; + for (int i = 0; i < Number; i++) { + if (Array[i].m_type == 1) { + float zDist = Abs(15.0f + pos.z - Array[i].m_pos.z); + + if (zDist < MAX_HEIGHT_DIST) { + float dist = (pos - Array[i].m_pos).Magnitude(); + if (dist < MAX_FADE_DIST) { + float distFade = dist < MIN_FADE_DIST ? 1.0f : 1.0f - (dist - MIN_FADE_DIST) / (MAX_FADE_DIST - MIN_FADE_DIST); + float heightFade = 1.0f - zDist / MAX_HEIGHT_DIST; + float fade = distFade * heightFade * 0.5f; + dir = (pos - Array[i].m_pos) * fade / dist; + bWasWindModifierFound = true; + } + } + } + } + + if (bWasWindModifierFound) { + float directionMult = ((CGeneral::GetRandomNumber() & 0x1F) - 16) * 0.0035f + 1.0f; + *x += dir.x * directionMult; + *y += dir.y * directionMult; + } + + return bWasWindModifierFound; +} diff --git a/src/renderer/WindModifiers.h b/src/renderer/WindModifiers.h new file mode 100644 index 00000000..7c2e57bd --- /dev/null +++ b/src/renderer/WindModifiers.h @@ -0,0 +1,11 @@ +#pragma once + +class CWindModifiers +{ + CVector m_pos; + int32 m_type; +public: + static int32 Number; + static void RegisterOne(CVector pos, int32 windSourceType); + static bool FindWindModifier(CVector pos, float *x, float *y); +}; -- cgit v1.2.3 From 76558e9313c481c39f40b2c73c4a3f68bf560d4e Mon Sep 17 00:00:00 2001 From: withmorten Date: Mon, 19 Jul 2021 23:39:56 +0200 Subject: fix garbage data written in garage save block --- src/control/Garages.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index d7394902..34ed11eb 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -2259,6 +2259,9 @@ void CGarages::Save(uint8 * buf, uint32 * size) //INITSAVEBUF *size = 7876; // for some reason it's not actual size again //*size = (6 * sizeof(uint32) + TOTAL_COLLECTCARS_GARAGES * sizeof(*CarTypesCollected) + sizeof(uint32) + TOTAL_HIDEOUT_GARAGES * NUM_GARAGE_STORED_CARS * sizeof(CStoredCar) + NUM_GARAGES * sizeof(CGarage)); +#if !defined THIS_IS_STUPID && defined COMPATIBLE_SAVES + memset(buf + 7340, 0, *size - 7340); // garbage data is written otherwise +#endif CloseHideOutGaragesBeforeSave(); WriteSaveBuf(buf, NumGarages); WriteSaveBuf(buf, (uint32)BombsAreFree); -- cgit v1.2.3 From a1444b992f47ef058d0f270716d9b00791e80862 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 22 Jul 2021 07:01:04 +0300 Subject: Fix Predator shooting sound --- src/audio/AudioLogic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/audio/AudioLogic.cpp b/src/audio/AudioLogic.cpp index 5ee5ddd1..6c53eb10 100644 --- a/src/audio/AudioLogic.cpp +++ b/src/audio/AudioLogic.cpp @@ -2955,7 +2955,7 @@ cAudioManager::ProcessVehicleOneShots(cVehicleParams& params) CPed *pPed = params.m_pVehicle->pDriver; if(!pPed) break; - if(!pPed->HasWeaponSlot(WEAPONSLOT_SUBMACHINEGUN)) { + if(!pPed->HasWeaponSlot(WEAPONSLOT_SUBMACHINEGUN) || (params.m_pVehicle->GetModelIndex() == MI_PREDATOR && !pPed->IsPedDoingDriveByShooting())) { sampleIndex = SFX_UZI_LEFT; frequency = SampleManager.GetSampleBaseFrequency(sampleIndex); frequency += RandomDisplacement(frequency / 32); -- cgit v1.2.3 From bbbe9b2632018ded5f455dfb12c3775907c70fc1 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 22 Jul 2021 07:06:54 +0300 Subject: Fix enum use --- src/weapons/Weapon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/weapons/Weapon.cpp b/src/weapons/Weapon.cpp index 36303c2c..d4cb1cbe 100644 --- a/src/weapons/Weapon.cpp +++ b/src/weapons/Weapon.cpp @@ -3182,7 +3182,7 @@ bool CPed::IsPedDoingDriveByShooting(void) { #ifdef FIX_BUGS - if (FindPlayerPed() == this && CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_nWeaponSlot == 5) { + if (FindPlayerPed() == this && CWeaponInfo::GetWeaponInfo(GetWeapon()->m_eWeaponType)->m_nWeaponSlot == WEAPONSLOT_SUBMACHINEGUN) { #else if (FindPlayerPed() == this && GetWeapon()->m_eWeaponType == WEAPONTYPE_UZI) { #endif -- cgit v1.2.3 From 953e4fc4ff96e9e2c180f74b36e3b591c979b1e2 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 22 Jul 2021 20:07:51 +0300 Subject: Fix falling damage --- src/peds/Ped.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index cad10d8a..b52d054c 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -3009,7 +3009,7 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) lowerSpeedLimit *= 1.5f; } CAnimBlendAssociation *fallAnim = RpAnimBlendClumpGetAssociation(GetClump(), ANIM_STD_FALL); - if (!bWasStanding && speed > upperSpeedLimit && (!bPushedAlongByCar || m_vecMoveSpeed.z < lowerSpeedLimit) + if (!bWasStanding && ((speed > upperSpeedLimit && !bPushedAlongByCar) || (m_vecMoveSpeed.z < lowerSpeedLimit)) && m_pCollidingEntity != collidingEnt) { float damage = 100.0f * Max(speed - 0.25f, 0.0f); -- cgit v1.2.3 From 5e34b1efcf4443124beece5ec97082da776df074 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 22 Jul 2021 07:26:19 +0300 Subject: Possible fix of RemoveAndAdd crash --- src/peds/Ped.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index b52d054c..002cbe3b 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -2362,12 +2362,12 @@ CPed::ProcessControl(void) } else { obstacleForFlyingOtherDirZ = 501.0f; } - uint8 flyDir = 0; + int16 flyDir = 0; float feetZ = GetPosition().z - FEET_OFFSET; #ifdef FIX_BUGS - if (obstacleForFlyingZ > feetZ && obstacleForFlyingOtherDirZ < 501.0f) + if (obstacleForFlyingZ > feetZ && obstacleForFlyingZ < 500.0f) flyDir = 1; - else if (obstacleForFlyingOtherDirZ > feetZ && obstacleForFlyingZ < 500.0f) + else if (obstacleForFlyingOtherDirZ > feetZ && obstacleForFlyingOtherDirZ < 501.0f) flyDir = 2; #else if ((obstacleForFlyingZ > feetZ && obstacleForFlyingOtherDirZ < 500.0f) || (obstacleForFlyingZ > feetZ && obstacleForFlyingOtherDirZ > feetZ)) @@ -2376,8 +2376,8 @@ CPed::ProcessControl(void) flyDir = 2; #endif - if (flyDir != 0 && !bHeadStuckInCollision) { - SetPosition((flyDir == 2 ? obstacleForFlyingOtherDir.point : obstacleForFlying.point)); + if (flyDir > 0 && !bHeadStuckInCollision) { + GetMatrix().SetTranslateOnly(flyDir == 2 ? obstacleForFlyingOtherDir.point : obstacleForFlying.point); GetMatrix().GetPosition().z += FEET_OFFSET; GetMatrix().UpdateRW(); SetLanding(); -- cgit v1.2.3