mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-11 04:56:49 +03:00
Implement FindRoomNumber and use it elsewhere
This commit is contained in:
parent
cdec61d0ff
commit
82132ae405
9 changed files with 37 additions and 39 deletions
|
@ -425,7 +425,7 @@ namespace TEN::Effects::Environment
|
|||
if (!TestEnvironment(RoomEnvFlags::ENV_FLAG_WATER, roomNumber))
|
||||
continue;
|
||||
|
||||
if (!IsPointInRoom(PHD_3DPOS(xPos, yPos, zPos), roomNumber))
|
||||
if (!IsPointInRoom(Vector3Int(xPos, yPos, zPos), roomNumber))
|
||||
continue;
|
||||
|
||||
auto part = WeatherParticle();
|
||||
|
|
|
@ -161,11 +161,11 @@ FloorInfo* GetSector(ROOM_INFO* room, int x, int z)
|
|||
return &room->floor[index];
|
||||
}
|
||||
|
||||
bool IsPointInRoom(PHD_3DPOS const& pos, int roomNumber)
|
||||
bool IsPointInRoom(Vector3Int pos, int roomNumber)
|
||||
{
|
||||
int x = pos.Position.x;
|
||||
int y = pos.Position.y;
|
||||
int z = pos.Position.z;
|
||||
int x = pos.x;
|
||||
int y = pos.y;
|
||||
int z = pos.z;
|
||||
auto* room = &g_Level.Rooms[roomNumber];
|
||||
int xSector = (x - room->x) / SECTOR(1);
|
||||
int zSector = (z - room->z) / SECTOR(1);
|
||||
|
@ -180,17 +180,27 @@ bool IsPointInRoom(PHD_3DPOS const& pos, int roomNumber)
|
|||
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 halfLength = SECTOR(room->xSize) / 2;
|
||||
auto halfDepth = SECTOR(room->zSize) / 2;
|
||||
auto halfHeight = (room->maxceiling - room->minfloor) / 2;
|
||||
|
||||
PHD_3DPOS center;
|
||||
center.Position.x = room->x + halfLength;
|
||||
center.Position.y = room->minfloor + halfHeight;
|
||||
center.Position.z = room->z + halfDepth;
|
||||
Vector3Int center;
|
||||
center.x = room->x + halfLength;
|
||||
center.y = room->minfloor + halfHeight;
|
||||
center.z = room->z + halfDepth;
|
||||
|
||||
return center;
|
||||
}
|
||||
|
||||
|
|
|
@ -133,8 +133,9 @@ void DoFlipMap(short group);
|
|||
void AddRoomFlipItems(ROOM_INFO* room);
|
||||
void RemoveRoomFlipItems(ROOM_INFO* room);
|
||||
bool IsObjectInRoom(short roomNumber, short objectNumber);
|
||||
bool IsPointInRoom(PHD_3DPOS const& pos, int roomNumber);
|
||||
PHD_3DPOS GetRoomCenter(int roomNumber);
|
||||
bool IsPointInRoom(Vector3Int pos, int roomNumber);
|
||||
int FindRoomNumber(Vector3Int position);
|
||||
Vector3Int GetRoomCenter(int roomNumber);
|
||||
int IsRoomOutside(int x, int y, int z);
|
||||
std::set<int> GetRoomList(int roomNumber);
|
||||
|
||||
|
|
|
@ -539,7 +539,6 @@ namespace TEN::Renderer
|
|||
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);
|
||||
|
||||
short GetRoomNumberForSpriteTest(Vector3 position);
|
||||
RendererMesh* GetMesh(int meshIndex);
|
||||
Texture2D CreateDefaultNormalTexture();
|
||||
|
||||
|
|
|
@ -873,7 +873,7 @@ namespace TEN::Renderer
|
|||
face.info.world = spriteMatrix;
|
||||
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);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -4,22 +4,6 @@
|
|||
|
||||
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)
|
||||
{
|
||||
if (scale <= 0.0f)
|
||||
|
|
|
@ -20,7 +20,8 @@ Functions that don't fit in the other modules.
|
|||
using namespace TEN::Effects::Lightning;
|
||||
using namespace TEN::Effects::Spark;
|
||||
|
||||
namespace Misc {
|
||||
namespace Misc
|
||||
{
|
||||
[[nodiscard]] static bool HasLineOfSight(short roomNumber1, Vec3 pos1, Vec3 pos2)
|
||||
{
|
||||
GameVector vec1, vec2;
|
||||
|
@ -30,11 +31,6 @@ namespace Misc {
|
|||
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)
|
||||
{
|
||||
Vector3Int p1;
|
||||
|
@ -70,6 +66,7 @@ namespace Misc {
|
|||
s->x = pos.x;
|
||||
s->y = pos.y;
|
||||
s->z = pos.z;
|
||||
s->roomNumber = FindRoomNumber(Vector3Int(pos.x, pos.y, pos.z));
|
||||
|
||||
s->life = s->sLife = lifetime;
|
||||
|
||||
|
@ -117,7 +114,7 @@ namespace Misc {
|
|||
|
||||
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)
|
||||
|
|
|
@ -367,12 +367,12 @@ void Moveable::Register(sol::table & parent)
|
|||
|
||||
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." };
|
||||
if (!ScriptAssertF(cond, err, m_item->LuaName))
|
||||
{
|
||||
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
|
||||
m_item->Pose.Position.x = center.Position.x;
|
||||
m_item->Pose.Position.y = center.Position.y;
|
||||
|
|
|
@ -111,6 +111,13 @@ struct Vector3Int
|
|||
this->z = z;
|
||||
}
|
||||
|
||||
Vector3Int(Vector3 v)
|
||||
{
|
||||
this->x = int(v.x);
|
||||
this->y = int(v.y);
|
||||
this->z = int(v.z);
|
||||
}
|
||||
|
||||
Vector3 ToVector3()
|
||||
{
|
||||
return Vector3(x, y, z);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue