Implement FindRoomNumber and use it elsewhere

This commit is contained in:
Lwmte 2022-07-05 23:25:42 +03:00
parent cdec61d0ff
commit 82132ae405
9 changed files with 37 additions and 39 deletions

View file

@ -425,7 +425,7 @@ namespace TEN::Effects::Environment
if (!TestEnvironment(RoomEnvFlags::ENV_FLAG_WATER, roomNumber)) if (!TestEnvironment(RoomEnvFlags::ENV_FLAG_WATER, roomNumber))
continue; continue;
if (!IsPointInRoom(PHD_3DPOS(xPos, yPos, zPos), roomNumber)) if (!IsPointInRoom(Vector3Int(xPos, yPos, zPos), roomNumber))
continue; continue;
auto part = WeatherParticle(); auto part = WeatherParticle();

View file

@ -161,11 +161,11 @@ FloorInfo* GetSector(ROOM_INFO* room, int x, int z)
return &room->floor[index]; return &room->floor[index];
} }
bool IsPointInRoom(PHD_3DPOS const& pos, int roomNumber) bool IsPointInRoom(Vector3Int pos, int roomNumber)
{ {
int x = pos.Position.x; int x = pos.x;
int y = pos.Position.y; int y = pos.y;
int z = pos.Position.z; int z = pos.z;
auto* room = &g_Level.Rooms[roomNumber]; auto* room = &g_Level.Rooms[roomNumber];
int xSector = (x - room->x) / SECTOR(1); int xSector = (x - room->x) / SECTOR(1);
int zSector = (z - room->z) / SECTOR(1); int zSector = (z - room->z) / SECTOR(1);
@ -180,17 +180,27 @@ bool IsPointInRoom(PHD_3DPOS const& pos, int roomNumber)
return false; return false;
} }
PHD_3DPOS GetRoomCenter(int roomNumber) int FindRoomNumber(Vector3Int position)
{
for (int i = 0; i < g_Level.Rooms.size(); i++)
if (IsPointInRoom(position, i))
return i;
return 0;
}
Vector3Int GetRoomCenter(int roomNumber)
{ {
auto* room = &g_Level.Rooms[roomNumber]; auto* room = &g_Level.Rooms[roomNumber];
auto halfLength = SECTOR(room->xSize) / 2; auto halfLength = SECTOR(room->xSize) / 2;
auto halfDepth = SECTOR(room->zSize) / 2; auto halfDepth = SECTOR(room->zSize) / 2;
auto halfHeight = (room->maxceiling - room->minfloor) / 2; auto halfHeight = (room->maxceiling - room->minfloor) / 2;
PHD_3DPOS center; Vector3Int center;
center.Position.x = room->x + halfLength; center.x = room->x + halfLength;
center.Position.y = room->minfloor + halfHeight; center.y = room->minfloor + halfHeight;
center.Position.z = room->z + halfDepth; center.z = room->z + halfDepth;
return center; return center;
} }

View file

@ -133,8 +133,9 @@ void DoFlipMap(short group);
void AddRoomFlipItems(ROOM_INFO* room); void AddRoomFlipItems(ROOM_INFO* room);
void RemoveRoomFlipItems(ROOM_INFO* room); void RemoveRoomFlipItems(ROOM_INFO* room);
bool IsObjectInRoom(short roomNumber, short objectNumber); bool IsObjectInRoom(short roomNumber, short objectNumber);
bool IsPointInRoom(PHD_3DPOS const& pos, int roomNumber); bool IsPointInRoom(Vector3Int pos, int roomNumber);
PHD_3DPOS GetRoomCenter(int roomNumber); int FindRoomNumber(Vector3Int position);
Vector3Int GetRoomCenter(int roomNumber);
int IsRoomOutside(int x, int y, int z); int IsRoomOutside(int x, int y, int z);
std::set<int> GetRoomList(int roomNumber); std::set<int> GetRoomList(int roomNumber);

View file

@ -539,7 +539,6 @@ namespace TEN::Renderer
void AddSprite3D(RendererSprite* sprite, Vector3 vtx1, Vector3 vtx2, Vector3 vtx3, Vector3 vtx4, Vector4 color, void AddSprite3D(RendererSprite* sprite, Vector3 vtx1, Vector3 vtx2, Vector3 vtx3, Vector3 vtx4, Vector4 color,
float rotation, float scale, Vector2 size, BLEND_MODES blendMode, RenderView& view); float rotation, float scale, Vector2 size, BLEND_MODES blendMode, RenderView& view);
short GetRoomNumberForSpriteTest(Vector3 position);
RendererMesh* GetMesh(int meshIndex); RendererMesh* GetMesh(int meshIndex);
Texture2D CreateDefaultNormalTexture(); Texture2D CreateDefaultNormalTexture();

View file

@ -873,7 +873,7 @@ namespace TEN::Renderer
face.info.world = spriteMatrix; face.info.world = spriteMatrix;
face.info.blendMode = spr.BlendMode; face.info.blendMode = spr.BlendMode;
RendererRoom& room = m_rooms[GetRoomNumberForSpriteTest(spr.pos)]; RendererRoom& room = m_rooms[FindRoomNumber(Vector3Int(spr.pos))];
room.TransparentFacesToDraw.push_back(face); room.TransparentFacesToDraw.push_back(face);
} }
else else

View file

@ -4,22 +4,6 @@
namespace TEN::Renderer namespace TEN::Renderer
{ {
short Renderer11::GetRoomNumberForSpriteTest(Vector3 position)
{
for (int i = 0; i < g_Level.Rooms.size(); i++)
{
ROOM_INFO* room = &g_Level.Rooms[i];
if (position.x >= room->x && position.x <= room->x + (room->xSize - 1) * WALL_SIZE &&
position.y >= room->maxceiling && position.y <= room->minfloor &&
position.z >= room->z && position.z <= room->z + (room->zSize - 1) * WALL_SIZE)
{
return i;
}
}
return 0;
}
void Renderer11::AddSpriteBillboard(RendererSprite* sprite, Vector3 pos, Vector4 color, float rotation, float scale, Vector2 size, BLEND_MODES blendMode, RenderView& view) void Renderer11::AddSpriteBillboard(RendererSprite* sprite, Vector3 pos, Vector4 color, float rotation, float scale, Vector2 size, BLEND_MODES blendMode, RenderView& view)
{ {
if (scale <= 0.0f) if (scale <= 0.0f)

View file

@ -20,7 +20,8 @@ Functions that don't fit in the other modules.
using namespace TEN::Effects::Lightning; using namespace TEN::Effects::Lightning;
using namespace TEN::Effects::Spark; using namespace TEN::Effects::Spark;
namespace Misc { namespace Misc
{
[[nodiscard]] static bool HasLineOfSight(short roomNumber1, Vec3 pos1, Vec3 pos2) [[nodiscard]] static bool HasLineOfSight(short roomNumber1, Vec3 pos1, Vec3 pos2)
{ {
GameVector vec1, vec2; GameVector vec1, vec2;
@ -30,11 +31,6 @@ namespace Misc {
return LOS(&vec1, &vec2); return LOS(&vec1, &vec2);
} }
static int FindRoomNumber(Vec3 pos)
{
return 0;
}
static void AddLightningArc(Vec3 src, Vec3 dest, ScriptColor color, int lifetime, int amplitude, int beamWidth, int segments, int flags) static void AddLightningArc(Vec3 src, Vec3 dest, ScriptColor color, int lifetime, int amplitude, int beamWidth, int segments, int flags)
{ {
Vector3Int p1; Vector3Int p1;
@ -70,6 +66,7 @@ namespace Misc {
s->x = pos.x; s->x = pos.x;
s->y = pos.y; s->y = pos.y;
s->z = pos.z; s->z = pos.z;
s->roomNumber = FindRoomNumber(Vector3Int(pos.x, pos.y, pos.z));
s->life = s->sLife = lifetime; s->life = s->sLife = lifetime;
@ -117,7 +114,7 @@ namespace Misc {
static void AddFireFlame(Vec3 pos, float size) static void AddFireFlame(Vec3 pos, float size)
{ {
AddFire(pos.x, pos.y, pos.z, FindRoomNumber(pos), size, 0); AddFire(pos.x, pos.y, pos.z, FindRoomNumber(Vector3Int(pos.x, pos.y, pos.z)), size, 0);
} }
static void Earthquake(int strength) static void Earthquake(int strength)

View file

@ -367,12 +367,12 @@ void Moveable::Register(sol::table & parent)
void Moveable::Init() void Moveable::Init()
{ {
bool cond = IsPointInRoom(m_item->Pose, m_item->RoomNumber); bool cond = IsPointInRoom(m_item->Pose.Position, m_item->RoomNumber);
std::string err{ "Position of item \"{}\" does not match its room ID." }; std::string err{ "Position of item \"{}\" does not match its room ID." };
if (!ScriptAssertF(cond, err, m_item->LuaName)) if (!ScriptAssertF(cond, err, m_item->LuaName))
{ {
ScriptWarn("Resetting to the center of the room."); ScriptWarn("Resetting to the center of the room.");
PHD_3DPOS center = GetRoomCenter(m_item->RoomNumber); auto center = GetRoomCenter(m_item->RoomNumber);
// reset position but not rotation // reset position but not rotation
m_item->Pose.Position.x = center.Position.x; m_item->Pose.Position.x = center.Position.x;
m_item->Pose.Position.y = center.Position.y; m_item->Pose.Position.y = center.Position.y;

View file

@ -111,6 +111,13 @@ struct Vector3Int
this->z = z; this->z = z;
} }
Vector3Int(Vector3 v)
{
this->x = int(v.x);
this->y = int(v.y);
this->z = int(v.z);
}
Vector3 ToVector3() Vector3 ToVector3()
{ {
return Vector3(x, y, z); return Vector3(x, y, z);