From ecca35d05a92ec7601a0c0c6bee3bf4282afaecb Mon Sep 17 00:00:00 2001 From: MontyTRC89 Date: Sun, 26 Jul 2020 16:17:54 +0200 Subject: [PATCH] Lights refactor --- TR5Main/Game/room.h | 9 +++--- TR5Main/Renderer/Renderer11Compatibility.cpp | 2 +- TR5Main/Specific/level.cpp | 34 +++++++++++--------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/TR5Main/Game/room.h b/TR5Main/Game/room.h index 1362c3f77..7c3026e72 100644 --- a/TR5Main/Game/room.h +++ b/TR5Main/Game/room.h @@ -23,15 +23,16 @@ struct ROOM_DOOR typedef struct ROOM_LIGHT { - float x, y, z; // Position of light, in world coordinates + int x, y, z; // Position of light, in world coordinates float r, g, b; // Colour of the light + float intensity; float in; // Cosine of the IN value for light / size of IN value float out; // Cosine of the OUT value for light / size of OUT value - float radIn; // (IN radians) * 2 - float radOut; // (OUT radians) * 2 - float range; // Range of light + float length; // Range of light + float cutoff; // Range of light float dx, dy, dz; // Direction - used only by sun and spot lights byte type; + bool castShadows; }; typedef struct MESH_INFO diff --git a/TR5Main/Renderer/Renderer11Compatibility.cpp b/TR5Main/Renderer/Renderer11Compatibility.cpp index de17cae2c..e81a73d2c 100644 --- a/TR5Main/Renderer/Renderer11Compatibility.cpp +++ b/TR5Main/Renderer/Renderer11Compatibility.cpp @@ -283,7 +283,7 @@ namespace T5M::Renderer light.Intensity = 1.0f; light.In = oldLight->in; light.Out = oldLight->out; - light.Range = oldLight->range; + light.Range = oldLight->length; light.Type = LIGHT_TYPE_SPOT; r.Lights.push_back(light); diff --git a/TR5Main/Specific/level.cpp b/TR5Main/Specific/level.cpp index fff038611..2ba0dd3b1 100644 --- a/TR5Main/Specific/level.cpp +++ b/TR5Main/Specific/level.cpp @@ -128,21 +128,22 @@ int LoadItems() for (int m = 0; m < g_Level.Rooms[r].mesh.size(); m++) { - FLOOR_INFO* floor = &g_Level.Rooms[r].floor[((mesh->z - g_Level.Rooms[r].z) >> 10) + g_Level.Rooms[r].xSize * ((mesh->x - g_Level.Rooms[r].x) >> 10)]; + FLOOR_INFO* floor = &g_Level.Rooms[r].floor[((mesh->z - g_Level.Rooms[r].z) / 1024) + + g_Level.Rooms[r].xSize * ((mesh->x - g_Level.Rooms[r].x) / 1024)]; if (!(g_Level.Boxes[floor->box].flags & BLOCKED) && !(CurrentLevel == 5 && (r == 19 || r == 23 || r == 16))) { - int fl = floor->floor << 2; + int fl = floor->floor * 4; STATIC_INFO* st = &StaticObjects[mesh->staticNumber]; if (fl <= mesh->y - st->collisionBox.Y2 + 512 && fl < mesh->y - st->collisionBox.Y1) { if (st->collisionBox.X1 == 0 || st->collisionBox.X2 == 0 || st->collisionBox.Z1 == 0 || st->collisionBox.Z2 == 0 || - (st->collisionBox.X1 < 0 ^ st->collisionBox.X2 < 0) && - (st->collisionBox.Z1 < 0 ^ st->collisionBox.Z2 < 0)) + ((st->collisionBox.X1 < 0) ^ (st->collisionBox.X2 < 0)) && + ((st->collisionBox.Z1 < 0) ^ (st->collisionBox.Z2 < 0))) { - floor->box |= 8; + floor->stopper = true; } } } @@ -596,21 +597,22 @@ void ReadRooms() { ROOM_LIGHT light; - light.x = ReadFloat(); - light.y = ReadFloat(); - light.z = ReadFloat(); - light.r = ReadFloat(); - light.g = ReadFloat(); - light.b = ReadFloat(); - light.in = ReadFloat(); - light.out = ReadFloat(); - light.radIn = ReadFloat(); - light.radOut = ReadFloat(); - light.range = ReadFloat(); + light.x = ReadInt32(); + light.y = ReadInt32(); + light.z = ReadInt32(); light.dx = ReadFloat(); light.dy = ReadFloat(); light.dz = ReadFloat(); + light.r = ReadFloat(); + light.g = ReadFloat(); + light.b = ReadFloat(); + light.intensity = ReadFloat(); + light.in = ReadFloat(); + light.out = ReadFloat(); + light.length = ReadFloat(); + light.cutoff = ReadFloat(); light.type = ReadInt8(); + light.castShadows = ReadInt8(); room.lights.push_back(light); }