From 9a49d4600528123e7d17b68552dedb78681d697f Mon Sep 17 00:00:00 2001 From: XProger Date: Sun, 30 Sep 2018 06:03:12 +0300 Subject: [PATCH] #23 fix rebuild water surfaces after setting changes, fix swap interval for TR1 animated textures --- src/format.h | 9 ++++++--- src/level.h | 8 ++++++-- src/mesh.h | 22 ++++++++++++++-------- src/utils.h | 4 ++++ 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/format.h b/src/format.h index e19e549..79547c8 100644 --- a/src/format.h +++ b/src/format.h @@ -1180,10 +1180,10 @@ namespace TR { struct { uint16 texture:15, doubleSided:1; }; uint16 value; } flags; - uint8 colored; // !!! not existing in file - uint8 vCount; // !!! not existing in file - short3 normal; // !!! not existing in file + + short3 normal; uint16 vertices[4]; + uint8 water:1, colored:1, vCount:6; static int cmp(const Face &a, const Face &b) { int aIndex = a.flags.texture; @@ -3124,6 +3124,8 @@ namespace TR { #else f.colored = false; #endif + + f.water = false; } void readRoom(Stream &stream, int roomIndex) { @@ -3362,6 +3364,7 @@ namespace TR { f.vertices[2] >>= 2; f.vertices[3] >>= 2; f.colored = false; + f.water = false; } } else for (int i = 0; i < d.rCount; i++) readFace(stream, d.faces[idx++], false, false); diff --git a/src/level.h b/src/level.h index 11c43bb..98b7085 100644 --- a/src/level.h +++ b/src/level.h @@ -1638,9 +1638,13 @@ struct Level : IGame { params->time += Core::deltaTime; animTexTimer += Core::deltaTime; - if (animTexTimer > ANIM_TEX_TIMESTEP) { + float timeStep = ANIM_TEX_TIMESTEP; + if (level.version & TR::VER_TR1) + timeStep *= 0.5f; + + if (animTexTimer > timeStep) { level.shiftAnimTex(); - animTexTimer -= ANIM_TEX_TIMESTEP; + animTexTimer -= timeStep; } updateEffect(); diff --git a/src/mesh.h b/src/mesh.h index 873c8c5..ad1845f 100644 --- a/src/mesh.h +++ b/src/mesh.h @@ -206,8 +206,7 @@ struct MeshBuilder { iCount += (d.rCount * 6 + d.tCount * 3) * DOUBLE_SIDED; vCount += (d.rCount * 4 + d.tCount * 3); - if (Core::settings.detail.water > Core::Settings::LOW) - roomRemoveWaterSurfaces(r, iCount, vCount); + roomRemoveWaterSurfaces(r, iCount, vCount); for (int j = 0; j < r.meshesCount; j++) { TR::Room::Mesh &m = r.meshes[j]; @@ -687,11 +686,18 @@ struct MeshBuilder { } void roomRemoveWaterSurfaces(TR::Room &room, int &iCount, int &vCount) { + + if (Core::settings.detail.water == Core::Settings::LOW) { + for (int i = 0; i < room.data.fCount; i++) + room.data.faces[i].water = false; + return; + } + room.waterLevel = -1; for (int i = 0; i < room.data.fCount; i++) { TR::Face &f = room.data.faces[i]; - if (f.flags.value == 0xFFFF) continue; + if (f.water) continue; TR::Vertex &a = room.data.vertices[f.vertices[0]].vertex; TR::Vertex &b = room.data.vertices[f.vertices[1]].vertex; @@ -712,7 +718,7 @@ struct MeshBuilder { if (isWaterSurface(yt, s.roomAbove, room.flags.water) || isWaterSurface(yb, s.roomBelow, room.flags.water)) { - f.flags.value = 0xFFFF; // mark as unused + f.water = true; room.waterLevel = a.y; if (f.vCount == 4) { @@ -767,8 +773,8 @@ struct MeshBuilder { for (int i = 0; i < room.data.fCount; i++) { TR::Face &f = room.data.faces[i]; - if (f.flags.value != 0xFFFF) continue; - + if (!f.water) continue; + Index idx[4]; idx[0] = addUniqueVertex(wVertices, room.data.vertices[f.vertices[0]].vertex); @@ -905,7 +911,7 @@ struct MeshBuilder { TR::Face &f = d.faces[j]; TR::ObjectTexture &t = level.objectTextures[f.flags.texture]; - if (f.flags.value == 0xFFFF) continue; // skip if marks as unused (removing water planes) + if (f.water) continue; CHECK_ROOM_NORMAL(f); @@ -939,7 +945,7 @@ struct MeshBuilder { TR::Face &f = d.faces[j]; TR::ObjectTexture &t = level.objectTextures[f.flags.texture]; - if (f.flags.value == 0xFFFF) continue; // skip if marks as unused (removing water planes) + if (f.water) continue; if (!(blendMask & getBlendMask(t.attribute))) continue; diff --git a/src/utils.h b/src/utils.h index 2bdde17..acf7970 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1646,6 +1646,10 @@ struct Array { count = 0; } + void sort() { + ::sort(items, count); + } + T& operator[] (int index) { ASSERT(index >= 0 && index < count); return items[index];