|
13 | 13 | #include "gamesa_renderware.h"
|
14 | 14 | #include "C2DEffectSA.h"
|
15 | 15 | #include "C2DEffectSAInterface.h"
|
| 16 | +#include "CGameSA.h" |
| 17 | + |
| 18 | +extern CGameSA* pGame; |
| 19 | + |
| 20 | +C2DEffectSA::C2DEffectSA(C2DEffectSAInterface* effectInterface, std::uint32_t modelID) : m_effectInterface(effectInterface), m_model(modelID) |
| 21 | +{ |
| 22 | + pGame->Get2DEffects()->AddToList(this); |
| 23 | +} |
| 24 | + |
| 25 | +void C2DEffectSA::Destroy() const |
| 26 | +{ |
| 27 | + CModelInfo* modelInfo = pGame->GetModelInfo(m_model); |
| 28 | + if (modelInfo) |
| 29 | + modelInfo->Remove2DFX(m_effectInterface, false); |
| 30 | +} |
| 31 | + |
| 32 | +void C2DEffectSA::SetPosition(const CVector& position) |
| 33 | +{ |
| 34 | + if (m_effectInterface) |
| 35 | + m_effectInterface->position = RwV3d{position.fX, position.fY, position.fZ}; |
| 36 | +} |
| 37 | + |
| 38 | +CVector& C2DEffectSA::GetPosition() |
| 39 | +{ |
| 40 | + if (m_effectInterface) |
| 41 | + return CVector(m_effectInterface->position.x, m_effectInterface->position.y, m_effectInterface->position.z); |
| 42 | + |
| 43 | + return CVector(); |
| 44 | +} |
| 45 | + |
| 46 | +void C2DEffectSA::SetCoronaFarClip(float clip) |
| 47 | +{ |
| 48 | + if (IsValidLight()) |
| 49 | + m_effectInterface->effect.light.coronaFarClip = clip; |
| 50 | +} |
| 51 | + |
| 52 | +void C2DEffectSA::SetCoronaPointLightRange(float range) |
| 53 | +{ |
| 54 | + if (IsValidLight()) |
| 55 | + m_effectInterface->effect.light.pointLightRange = range; |
| 56 | +} |
| 57 | + |
| 58 | +void C2DEffectSA::SetCoronaSize(float size) |
| 59 | +{ |
| 60 | + if (IsValidLight()) |
| 61 | + m_effectInterface->effect.light.coronaSize = size; |
| 62 | +} |
| 63 | + |
| 64 | +void C2DEffectSA::SetShadowSize(float size) |
| 65 | +{ |
| 66 | + if (IsValidLight()) |
| 67 | + m_effectInterface->effect.light.shadowSize = size; |
| 68 | +} |
| 69 | + |
| 70 | +void C2DEffectSA::SetShadowMultiplier(std::uint8_t multiplier) |
| 71 | +{ |
| 72 | + if (IsValidLight()) |
| 73 | + m_effectInterface->effect.light.shadowColorMultiplier = multiplier; |
| 74 | +} |
| 75 | + |
| 76 | +void C2DEffectSA::SetCoronaShowMode(e2dCoronaFlashType showMode) |
| 77 | +{ |
| 78 | + if (IsValidLight()) |
| 79 | + m_effectInterface->effect.light.coronaFlashType = showMode; |
| 80 | +} |
| 81 | + |
| 82 | +void C2DEffectSA::SetCoronaReflectionsEnabled(bool enable) |
| 83 | +{ |
| 84 | + if (IsValidLight()) |
| 85 | + m_effectInterface->effect.light.coronaEnableReflection = enable; |
| 86 | +} |
| 87 | + |
| 88 | +void C2DEffectSA::SetCoronaFlareType(std::uint8_t flareType) |
| 89 | +{ |
| 90 | + if (IsValidLight()) |
| 91 | + m_effectInterface->effect.light.coronaFlareType = flareType; |
| 92 | +} |
| 93 | + |
| 94 | +void C2DEffectSA::SetLightFlags(std::uint16_t flags) |
| 95 | +{ |
| 96 | + if (IsValidLight()) |
| 97 | + m_effectInterface->effect.light.flags = flags; |
| 98 | +} |
| 99 | + |
| 100 | +void C2DEffectSA::SetShadowDistance(std::int8_t distance) |
| 101 | +{ |
| 102 | + if (IsValidLight()) |
| 103 | + m_effectInterface->effect.light.shadowZDistance = distance; |
| 104 | +} |
| 105 | + |
| 106 | +void C2DEffectSA::SetCoronaOffsets(const CVector& offsets) |
| 107 | +{ |
| 108 | + if (IsValidLight()) |
| 109 | + { |
| 110 | + m_effectInterface->effect.light.offsetX = offsets.fX; |
| 111 | + m_effectInterface->effect.light.offsetY = offsets.fY; |
| 112 | + m_effectInterface->effect.light.offsetZ = offsets.fZ; |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +void C2DEffectSA::SetCoronaColor(const RwColor& color) |
| 117 | +{ |
| 118 | + if (IsValidLight()) |
| 119 | + m_effectInterface->effect.light.color = color; |
| 120 | +} |
| 121 | + |
| 122 | +void C2DEffectSA::SetCoronaTexture(const std::string& name) |
| 123 | +{ |
| 124 | + if (IsValidLight()) |
| 125 | + { |
| 126 | + if (m_effectInterface->effect.light.coronaTex) |
| 127 | + RwTextureDestroy(m_effectInterface->effect.light.coronaTex); |
| 128 | + |
| 129 | + // Call CTxdStore::PushCurrentTxd |
| 130 | + ((void(__cdecl*)())FUNC_PushCurrentTxd)(); |
| 131 | + // Call CTxdStore::FindTxdSlot |
| 132 | + int slot = ((int(__cdecl*)(const char*))FUNC_FindTxdSlot)("particle"); |
| 133 | + // Call CTxdStore::SetCurrentTxd |
| 134 | + ((void(__cdecl*)(int))FUNC_SetCurrentTxd)(slot); |
| 135 | + |
| 136 | + m_effectInterface->effect.light.coronaTex = RwReadTexture(name.c_str(), nullptr); |
| 137 | + |
| 138 | + // Call CTxdStore::PopCurrentTxd |
| 139 | + ((void(__cdecl*)())FUNC_PopCurrentTxd)(); |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +void C2DEffectSA::SetShadowTexture(const std::string& name) |
| 144 | +{ |
| 145 | + if (IsValidLight()) |
| 146 | + { |
| 147 | + if (m_effectInterface->effect.light.shadowTex) |
| 148 | + RwTextureDestroy(m_effectInterface->effect.light.shadowTex); |
| 149 | + |
| 150 | + // Call CTxdStore::PushCurrentTxd |
| 151 | + ((void(__cdecl*)())FUNC_PushCurrentTxd)(); |
| 152 | + // Call CTxdStore::FindTxdSlot |
| 153 | + int slot = ((int(__cdecl*)(const char*))FUNC_FindTxdSlot)("particle"); |
| 154 | + // Call CTxdStore::SetCurrentTxd |
| 155 | + ((void(__cdecl*)(int))FUNC_SetCurrentTxd)(slot); |
| 156 | + |
| 157 | + m_effectInterface->effect.light.shadowTex = RwReadTexture(name.c_str(), nullptr); |
| 158 | + |
| 159 | + // Call CTxdStore::PopCurrentTxd |
| 160 | + ((void(__cdecl*)())FUNC_PopCurrentTxd)(); |
| 161 | + } |
| 162 | +} |
| 163 | + |
| 164 | +CVector C2DEffectSA::GetCoronaOffsets() const |
| 165 | +{ |
| 166 | + if (IsValidLight()) |
| 167 | + return CVector(m_effectInterface->effect.light.offsetX, m_effectInterface->effect.light.offsetY, m_effectInterface->effect.light.offsetZ); |
| 168 | + |
| 169 | + return CVector(); |
| 170 | +} |
| 171 | + |
| 172 | +void C2DEffectSA::SetParticleName(const std::string& name) |
| 173 | +{ |
| 174 | + if (m_effectInterface && m_effectInterface->type == e2dEffectType::PARTICLE) |
| 175 | + std::strncpy(m_effectInterface->effect.particle.szName, name.c_str(), 24); |
| 176 | +} |
| 177 | + |
| 178 | +void C2DEffectSA::SetRoadsignSize(const RwV2d& size) |
| 179 | +{ |
| 180 | + if (IsValidRoadsign()) |
| 181 | + m_effectInterface->effect.roadsign.size = size; |
| 182 | +} |
| 183 | + |
| 184 | +void C2DEffectSA::SetRoadsignRotation(const RwV3d& rotation) |
| 185 | +{ |
| 186 | + if (IsValidRoadsign()) |
| 187 | + m_effectInterface->effect.roadsign.rotation = rotation; |
| 188 | +} |
| 189 | + |
| 190 | +void C2DEffectSA::SetRoadsignFlags(std::uint8_t flags) |
| 191 | +{ |
| 192 | + if (IsValidRoadsign()) |
| 193 | + m_effectInterface->effect.roadsign.flags = flags; |
| 194 | +} |
| 195 | + |
| 196 | +void C2DEffectSA::SetRoadsignText(const std::string& text, std::uint8_t line) |
| 197 | +{ |
| 198 | + if (IsValidRoadsign()) |
| 199 | + { |
| 200 | + if (!m_effectInterface->effect.roadsign.text) |
| 201 | + m_effectInterface->effect.roadsign.text = static_cast<char*>(std::malloc(64)); |
| 202 | + |
| 203 | + if (!m_effectInterface->effect.roadsign.text) |
| 204 | + return; |
| 205 | + |
| 206 | + std::strncpy(m_effectInterface->effect.roadsign.text + 16 * (line - 1), text.c_str(), 16); |
| 207 | + } |
| 208 | +} |
| 209 | + |
| 210 | +void C2DEffectSA::SetEscalatorBottom(const RwV3d& bottom) |
| 211 | +{ |
| 212 | + if (IsValidEscalator()) |
| 213 | + m_effectInterface->effect.escalator.bottom = bottom; |
| 214 | +} |
| 215 | + |
| 216 | +void C2DEffectSA::SetEscalatorTop(const RwV3d& top) |
| 217 | +{ |
| 218 | + if (IsValidEscalator()) |
| 219 | + m_effectInterface->effect.escalator.top = top; |
| 220 | +} |
| 221 | + |
| 222 | +void C2DEffectSA::SetEscalatorEnd(const RwV3d& end) |
| 223 | +{ |
| 224 | + if (IsValidEscalator()) |
| 225 | + m_effectInterface->effect.escalator.end = end; |
| 226 | +} |
| 227 | + |
| 228 | +void C2DEffectSA::SetEscalatorDirection(std::uint8_t direction) |
| 229 | +{ |
| 230 | + if (IsValidEscalator()) |
| 231 | + m_effectInterface->effect.escalator.direction = direction; |
| 232 | +} |
| 233 | + |
| 234 | +C2DEffectSAInterface* C2DEffectSA::CreateCopy(C2DEffectSAInterface* effect) |
| 235 | +{ |
| 236 | + C2DEffectSAInterface* copy = new C2DEffectSAInterface(); |
| 237 | + MemCpyFast(copy, effect, sizeof(C2DEffectSAInterface)); |
| 238 | + |
| 239 | + // Create a copy of textures for the lights |
| 240 | + // We must to do this, because C2DEffect::Shutdown removes them |
| 241 | + if (copy->type == e2dEffectType::LIGHT) |
| 242 | + { |
| 243 | + if (effect->effect.light.coronaTex && effect->effect.light.shadowTex) |
| 244 | + C2DEffectSA::PrepareTexturesForLightEffect(copy->effect.light.coronaTex, copy->effect.light.shadowTex, effect->effect.light.coronaTex->name, effect->effect.light.shadowTex->name, false); |
| 245 | + } |
| 246 | + else if (copy->type == e2dEffectType::ROADSIGN) |
| 247 | + { |
| 248 | + // Create a copy of text and atomic for the roadsign |
| 249 | + // We must to do this, because C2DEffect::Shutdown removes them |
| 250 | + copy->effect.roadsign.text = static_cast<char*>(std::malloc(64)); |
| 251 | + if (copy->effect.roadsign.text) |
| 252 | + { |
| 253 | + std::memset(copy->effect.roadsign.text, 0, 64); |
| 254 | + std::strncpy(copy->effect.roadsign.text, effect->effect.roadsign.text, 64); |
| 255 | + } |
| 256 | + |
| 257 | + copy->effect.roadsign.atomic = RpAtomicClone(effect->effect.roadsign.atomic); |
| 258 | + } |
| 259 | + |
| 260 | + return copy; |
| 261 | +} |
16 | 262 |
|
17 | 263 | // C2DEffect::Shutdown causes random unknown crash in ntdll.dll so we need own function
|
18 | 264 | void C2DEffectSA::Shutdown(C2DEffectSAInterface* effect)
|
|
0 commit comments