Skip to content

Commit

Permalink
Reversed colibits from GMS.
Browse files Browse the repository at this point in the history
Added small filter to fix low fps in some places.
  • Loading branch information
DronCode committed Oct 3, 2024
1 parent 96c6f01 commit 0b46894
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
15 changes: 15 additions & 0 deletions Assets/g1/ECollisionMask.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"typename": "ECollisionMask",
"kind": "TypeKind.ENUM",
"enum": {
"COLIMASK_All" : 1,
"COLIMASK_Background": 2,
"COLIMASK_Shot": 4,
"COLIMASK_WaterGlass": 8,
"COLIMASK_NoWalk": 16,
"COLIMASK_Sight": 32,
"COLIMASK_Hero": 64,
"COLIMASK_Camera": 128,
"COLIMASK_NPC": 256
}
}
17 changes: 14 additions & 3 deletions BMEdit/Editor/Source/Widgets/SceneRenderWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ namespace widgets
{
static render::Shader* g_pLastKnownShader = nullptr;

static bool canDrawGeom(const gamelib::scene::SceneObject* pObject)
{
using CM = gamelib::gms::ECollisionMask;
constexpr uint32_t kExpectedToSeeMask = CM::COLIMASK_Sight | CM::COLIMASK_Hero | CM::COLIMASK_NPC | CM::COLIMASK_Background;

return pObject && (pObject->getGeomInfo().getColiBits() & kExpectedToSeeMask);
}

struct RenderState
{
bool bHasBlend = false;
Expand Down Expand Up @@ -1341,6 +1349,9 @@ namespace widgets
if (visitedObjects.contains(sObject.pObject.get()))
continue; // Skip because it's in render list already

if (!canDrawGeom(sObject.pObject.get()))
continue;

if (auto bbox = getGameObjectBoundingBox(sObject.pObject, true); bbox.has_value() && m_camera.canSeeObject(bbox.value()))
{
// Need to render it
Expand Down Expand Up @@ -1451,9 +1462,9 @@ namespace widgets
return;
}

// Don't draw invisible things
if (bInvisible)
return;
if (!bIgnoreVisibility)
if (bInvisible || !canDrawGeom(geom))
return;

if (g_bannedObjectIds.contains(std::string_view{geom->getName()}) || geom->getName().starts_with("CloneGroup_"))
return;
Expand Down
18 changes: 14 additions & 4 deletions BMEdit/GameLib/Include/GameLib/GMS/GMSGeomEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ namespace ZBio::ZBinaryReader

namespace gamelib::gms
{
enum ECollisionMask : uint32_t
{
COLIMASK_All = 1,
COLIMASK_Background = 2,
COLIMASK_Shot = 4,
COLIMASK_WaterGlass = 8,
COLIMASK_NoWalk = 16,
COLIMASK_Sight = 32,
COLIMASK_Hero = 64,
COLIMASK_Camera = 128,
COLIMASK_NPC = 256
};

class GMSGeomEntity
{
///----------
Expand Down Expand Up @@ -53,10 +66,7 @@ namespace gamelib::gms
uint32_t m_unk10 { };
uint32_t m_typeId { };
uint32_t m_unk18 { };
uint8_t m_coliBits {}; // +1C
uint8_t m_unk1D {};
uint8_t m_unk1E {};
uint8_t m_unk1F {};
uint32_t m_coliBits {}; // +1C. NOTE: ECollisionMask contains all possible & expected values
uint32_t m_unk20 { };
uint32_t m_unk24 { };
uint32_t m_unk28 { };
Expand Down
7 changes: 2 additions & 5 deletions BMEdit/GameLib/Source/GameLib/GMS/GMSGeomEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace gamelib::gms

uint32_t GMSGeomEntity::getColiBits() const
{
return static_cast<uint32_t>(m_coliBits);
return m_coliBits;
}

uint32_t GMSGeomEntity::getParentGeomIndex() const
Expand Down Expand Up @@ -79,10 +79,7 @@ namespace gamelib::gms
entity.m_unk18 = gmsBinaryReader->read<uint32_t, ZBio::Endianness::LE>();

// Read coliBits
entity.m_coliBits = gmsBinaryReader->read<uint8_t, ZBio::Endianness::LE>();
entity.m_unk1D = gmsBinaryReader->read<uint8_t, ZBio::Endianness::LE>();
entity.m_unk1E = gmsBinaryReader->read<uint8_t, ZBio::Endianness::LE>();
entity.m_unk1F = gmsBinaryReader->read<uint8_t, ZBio::Endianness::LE>();
entity.m_coliBits = gmsBinaryReader->read<uint32_t, ZBio::Endianness::LE>();

// Read unk20, 24, 28, 2C
entity.m_unk20 = gmsBinaryReader->read<uint32_t, ZBio::Endianness::LE>();
Expand Down

0 comments on commit 0b46894

Please sign in to comment.