Skip to content

Commit

Permalink
Fixed backward compatibility of checkpoints and arrows marker (#3540)
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX authored Jul 15, 2024
1 parent 49fb6c6 commit 121048c
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 16 deletions.
8 changes: 8 additions & 0 deletions Client/mods/deathmatch/logic/CClient3DMarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,11 @@ void CClient3DMarker::DoPulse()
}
}
}

void CClient3DMarker::SetColor(const SColor& color) noexcept
{
m_Color = color;

if (!m_ignoreAlphaLimits && m_dwType == MARKER3D_ARROW)
m_Color.A = 255;
}
6 changes: 5 additions & 1 deletion Client/mods/deathmatch/logic/CClient3DMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ class CClient3DMarker : public CClientMarkerCommon
void SetVisible(bool bVisible) { m_bVisible = bVisible; };

SColor GetColor() const { return m_Color; }
void SetColor(const SColor& color) { m_Color = color; }
void SetColor(const SColor& color) noexcept;

float GetSize() const { return m_fSize; };
void SetSize(float fSize) { m_fSize = fSize; };

float GetPulseFraction() { return static_cast<float>(m_pMarker->GetPulseFraction()); };
void SetPulseFraction(float fFraction) { m_pMarker->SetPulseFraction(fFraction); };

void SetIgnoreAlphaLimits(bool ignore) noexcept { m_ignoreAlphaLimits = ignore; };
bool AreAlphaLimitsIgnored() const noexcept override { return m_ignoreAlphaLimits; };

protected:
void StreamIn();
void StreamOut();
Expand All @@ -70,4 +73,5 @@ class CClient3DMarker : public CClientMarkerCommon
C3DMarker* m_pMarker;
unsigned int m_ulIdentifier;
bool m_bMarkerStreamedIn;
bool m_ignoreAlphaLimits;
};
11 changes: 9 additions & 2 deletions Client/mods/deathmatch/logic/CClientCheckpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ CClientCheckpoint::CClientCheckpoint(CClientMarker* pThis)
m_bStreamedIn = false;
m_bVisible = true;
m_uiIcon = CClientCheckpoint::ICON_NONE;
m_Color = SColorRGBA(255, 0, 0, 255);
m_Color = SColorRGBA(255, 0, 0, 128);
m_fSize = 4.0f;
m_dwType = CHECKPOINT_EMPTYTUBE;
m_vecDirection.fX = 1.0f;
m_bHasTarget = false;
m_ignoreAlphaLimits = false;
m_TargetArrowColor = SColorRGBA(255, 64, 64, 255);
m_TargetArrowSize = m_fSize * 0.625f;
}
Expand Down Expand Up @@ -250,8 +251,14 @@ void CClientCheckpoint::SetColor(const SColor& color)
// Different from our current color?
if (m_Color != color)
{
// Set it and recreate
// Set it
m_Color = color;

// Default alpha
if (!m_ignoreAlphaLimits && GetCheckpointType() == CClientCheckpoint::TYPE_NORMAL)
m_Color.A = 128;

// Recreate
ReCreate();
}
}
Expand Down
4 changes: 4 additions & 0 deletions Client/mods/deathmatch/logic/CClientCheckpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class CClientCheckpoint : public CClientMarkerCommon
static bool IconToString(unsigned char ucIcon, SString& strOutString);
void ReCreateWithSameIdentifier();

void SetIgnoreAlphaLimits(bool ignore) noexcept { m_ignoreAlphaLimits = ignore; };
bool AreAlphaLimitsIgnored() const noexcept override { return m_ignoreAlphaLimits; };

SColor GetTargetArrowColor() const noexcept { return m_TargetArrowColor; };
float GetTargetArrowSize() const noexcept { return m_TargetArrowSize; };
void SetTargetArrowProperties(const SColor& arrowColor, float size) noexcept;
Expand All @@ -100,6 +103,7 @@ class CClientCheckpoint : public CClientMarkerCommon
float m_fSize;
SColor m_Color;
CCheckpoint* m_pCheckpoint;
bool m_ignoreAlphaLimits;
SColor m_TargetArrowColor;
float m_TargetArrowSize;

Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientCorona.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class CClientCorona : public CClientMarkerCommon
void SetReflectionEnabled(bool bEnabled) { m_bReflectionEnabled = bEnabled; };
bool IsReflectionEnabled() const { return m_bReflectionEnabled; };

void SetIgnoreAlphaLimits(bool ignore) noexcept {};
bool AreAlphaLimitsIgnored() const noexcept override { return true; };

protected:
bool IsStreamedIn() { return m_bStreamedIn; };
void StreamIn();
Expand Down
5 changes: 5 additions & 0 deletions Client/mods/deathmatch/logic/CClientMarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,8 @@ CSphere CClientMarker::GetWorldBoundingSphere()
sphere.fRadius = GetSize();
return sphere;
}

void CClientMarker::SetIgnoreAlphaLimits(bool ignore)
{
m_pMarker->SetIgnoreAlphaLimits(ignore);
}
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class CClientMarker final : public CClientStreamElement, private CClientColCallb

virtual CSphere GetWorldBoundingSphere();

void SetIgnoreAlphaLimits(bool ignore);
bool AreAlphaLimitsIgnored() const noexcept { return m_pMarker->AreAlphaLimitsIgnored(); };

protected:
void StreamIn(bool bInstantly);
void StreamOut();
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientMarkerCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ class CClientMarkerCommon

virtual void StreamIn() = 0;
virtual void StreamOut() = 0;

virtual void SetIgnoreAlphaLimits(bool ignore) noexcept = 0;
virtual bool AreAlphaLimitsIgnored() const noexcept = 0;
};
7 changes: 6 additions & 1 deletion Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3632,7 +3632,6 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream)
CClientMarker* pMarker = new CClientMarker(g_pClientGame->m_pManager, EntityID, ucType);
pMarker->SetPosition(position.data.vecPosition);
pMarker->SetSize(fSize);
pMarker->SetColor(color);

// Entity is this
pEntity = pMarker;
Expand Down Expand Up @@ -3669,6 +3668,12 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream)
}
}
}

// Read out alpha limit flag
if (bitStream.Can(eBitStreamVersion::Marker_IgnoreAlphaLimits))
pMarker->SetIgnoreAlphaLimits(bitStream.ReadBit());

pMarker->SetColor(color);
}
else
{
Expand Down
6 changes: 5 additions & 1 deletion Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4774,7 +4774,7 @@ bool CStaticFunctionDefinitions::SetBlipVisibleDistance(CClientEntity& Entity, u
return false;
}

CClientMarker* CStaticFunctionDefinitions::CreateMarker(CResource& Resource, const CVector& vecPosition, const char* szType, float fSize, const SColor color)
CClientMarker* CStaticFunctionDefinitions::CreateMarker(CResource& Resource, const CVector& vecPosition, const char* szType, float fSize, const SColor color, bool ignoreAlphaLimits)
{
assert(szType);

Expand All @@ -4788,6 +4788,10 @@ CClientMarker* CStaticFunctionDefinitions::CreateMarker(CResource& Resource, con
// Set its parent and its properties
pMarker->SetParent(Resource.GetResourceDynamicEntity());
pMarker->SetPosition(vecPosition);

if (ucType == CClientMarker::MARKER_ARROW || ucType == CClientMarker::MARKER_CHECKPOINT)
pMarker->SetIgnoreAlphaLimits(ignoreAlphaLimits);

pMarker->SetColor(color);
pMarker->SetSize(fSize);

Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class CStaticFunctionDefinitions
static bool SetBlipVisibleDistance(CClientEntity& Entity, unsigned short usVisibleDistance);

// Marker create/destroy funcs
static CClientMarker* CreateMarker(CResource& Resource, const CVector& vecPosition, const char* szType, float fSize, const SColor color);
static CClientMarker* CreateMarker(CResource& Resource, const CVector& vecPosition, const char* szType, float fSize, const SColor color, bool ignoreAlphaLimits);

// Marker get funcs
static bool GetMarkerTarget(CClientMarker& Marker, CVector& vecTarget);
Expand Down
11 changes: 9 additions & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaMarkerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int CLuaMarkerDefs::CreateMarker(lua_State* luaVM)
float fSize = 4.0f;
SColorRGBA color(0, 0, 255, 255);
SString strType = "default";
bool ignoreAlphaLimits;
CScriptArgReader argStream(luaVM);
argStream.ReadVector3D(vecPosition);
argStream.ReadString(strType, "default");
Expand All @@ -85,6 +86,7 @@ int CLuaMarkerDefs::CreateMarker(lua_State* luaVM)
argStream.ReadNumber(color.G, 0);
argStream.ReadNumber(color.B, 255);
argStream.ReadNumber(color.A, 255);
argStream.ReadBool(ignoreAlphaLimits, false);

if (!argStream.HasErrors())
{
Expand All @@ -94,7 +96,7 @@ int CLuaMarkerDefs::CreateMarker(lua_State* luaVM)
CResource* pResource = pLuaMain->GetResource();
{
// Create it
CClientMarker* pMarker = CStaticFunctionDefinitions::CreateMarker(*pResource, vecPosition, strType, fSize, color);
CClientMarker* pMarker = CStaticFunctionDefinitions::CreateMarker(*pResource, vecPosition, strType, fSize, color, ignoreAlphaLimits);
if (pMarker)
{
CElementGroup* pGroup = pResource->GetElementGroup();
Expand Down Expand Up @@ -179,7 +181,12 @@ int CLuaMarkerDefs::GetMarkerColor(lua_State* luaVM)
lua_pushnumber(luaVM, static_cast<lua_Number>(color.R));
lua_pushnumber(luaVM, static_cast<lua_Number>(color.G));
lua_pushnumber(luaVM, static_cast<lua_Number>(color.B));
lua_pushnumber(luaVM, static_cast<lua_Number>(color.A));

if (!pMarker->AreAlphaLimitsIgnored() && (pMarker->GetMarkerType() == CClientMarker::MARKER_CHECKPOINT || pMarker->GetMarkerType() == CClientMarker::MARKER_ARROW))
lua_pushnumber(luaVM, 255); // fake alpha
else
lua_pushnumber(luaVM, static_cast<lua_Number>(color.A));

return 4;
}
else
Expand Down
17 changes: 13 additions & 4 deletions Server/mods/deathmatch/logic/CMarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CMarker::CMarker(CMarkerManager* pMarkerManager, CColManager* pColManager, CElem
m_Color = SColorRGBA(255, 255, 255, 255);
m_bHasTarget = false;
m_ucIcon = ICON_NONE;
m_ignoreAlphaLimits = false;
m_TargetArrowColor = SColorRGBA(255, 64, 64, 255);
m_TargetArrowSize = m_fSize * 0.625f;

Expand Down Expand Up @@ -282,12 +283,20 @@ void CMarker::SetColor(const SColor color)
// Set the new color
m_Color = color;

if (!m_ignoreAlphaLimits)
{
if (m_ucType == CMarker::TYPE_CHECKPOINT)
m_Color.A = 128;
else if (m_ucType == CMarker::TYPE_ARROW)
m_Color.A = 255;
}

// Tell all the players
CBitStream BitStream;
BitStream.pBitStream->Write(color.B);
BitStream.pBitStream->Write(color.G);
BitStream.pBitStream->Write(color.R);
BitStream.pBitStream->Write(color.A);
BitStream.pBitStream->Write(m_Color.B);
BitStream.pBitStream->Write(m_Color.G);
BitStream.pBitStream->Write(m_Color.R);
BitStream.pBitStream->Write(m_Color.A);
BroadcastOnlyVisible(CElementRPCPacket(this, SET_MARKER_COLOR, *BitStream.pBitStream));
}
}
Expand Down
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/logic/CMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class CMarker : public CPerPlayerEntity, private CColCallback

virtual CSphere GetWorldBoundingSphere();

void SetIgnoreAlphaLimits(bool ignore) noexcept { m_ignoreAlphaLimits = ignore; };
bool AreAlphaLimitsIgnored() const noexcept { return m_ignoreAlphaLimits; };

SColor GetTargetArrowColor() const noexcept { return m_TargetArrowColor; };
float GetTargetArrowSize() const noexcept { return m_TargetArrowSize; };
void SetTargetArrowProperties(const SColor color, float size) noexcept;
Expand All @@ -89,6 +92,7 @@ class CMarker : public CPerPlayerEntity, private CColCallback
float m_fSize;
SColor m_Color;
unsigned char m_ucIcon;
bool m_ignoreAlphaLimits;
SColor m_TargetArrowColor;
float m_TargetArrowSize;

Expand Down
3 changes: 2 additions & 1 deletion Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7666,7 +7666,7 @@ bool CStaticFunctionDefinitions::SetVehicleDoorOpenRatio(CElement* pElement, uns
}

CMarker* CStaticFunctionDefinitions::CreateMarker(CResource* pResource, const CVector& vecPosition, const char* szType, float fSize, const SColor color,
CElement* pVisibleTo)
CElement* pVisibleTo, bool ignoreAlphaLimits)
{
assert(szType);

Expand All @@ -7682,6 +7682,7 @@ CMarker* CStaticFunctionDefinitions::CreateMarker(CResource* pResource, const CV
// Set the properties
pMarker->SetPosition(vecPosition);
pMarker->SetMarkerType(ucType);
pMarker->SetIgnoreAlphaLimits(ignoreAlphaLimits);
pMarker->SetColor(color);
pMarker->SetSize(fSize);

Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class CStaticFunctionDefinitions
static bool RemoveVehicleSirens(CVehicle* pVehicle);

// Marker create/destroy functions
static CMarker* CreateMarker(CResource* pResource, const CVector& vecPosition, const char* szType, float fSize, const SColor color, CElement* pVisibleTo);
static CMarker* CreateMarker(CResource* pResource, const CVector& vecPosition, const char* szType, float fSize, const SColor color, CElement* pVisibleTo, bool ignoreAlphaLimits);

// Marker get functions
static bool GetMarkerCount(unsigned int& uiCount);
Expand Down
13 changes: 11 additions & 2 deletions Server/mods/deathmatch/logic/luadefs/CLuaMarkerDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ int CLuaMarkerDefs::CreateMarker(lua_State* luaVM)
SColorRGBA color(0, 0, 255, 255);
SString strType;
CElement* pVisibleTo;
bool ignoreAlphaLimits;

CScriptArgReader argStream(luaVM);
argStream.ReadVector3D(vecPosition);
Expand All @@ -92,10 +93,13 @@ int CLuaMarkerDefs::CreateMarker(lua_State* luaVM)
if (argStream.NextIsBool() || argStream.NextIsNil())
{
pVisibleTo = NULL;
argStream.m_iIndex++;
}
else
argStream.ReadUserData(pVisibleTo, m_pRootElement);

argStream.ReadBool(ignoreAlphaLimits, false);

if (!argStream.HasErrors())
{
CLuaMain* pLuaMain = g_pGame->GetLuaManager()->GetVirtualMachine(luaVM);
Expand All @@ -105,7 +109,7 @@ int CLuaMarkerDefs::CreateMarker(lua_State* luaVM)
if (pResource)
{
// Create it
CMarker* pMarker = CStaticFunctionDefinitions::CreateMarker(pResource, vecPosition, strType, fSize, color, pVisibleTo);
CMarker* pMarker = CStaticFunctionDefinitions::CreateMarker(pResource, vecPosition, strType, fSize, color, pVisibleTo, ignoreAlphaLimits);
if (pMarker)
{
CElementGroup* pGroup = pResource->GetElementGroup();
Expand Down Expand Up @@ -200,7 +204,12 @@ int CLuaMarkerDefs::GetMarkerColor(lua_State* luaVM)
lua_pushnumber(luaVM, static_cast<lua_Number>(color.R));
lua_pushnumber(luaVM, static_cast<lua_Number>(color.G));
lua_pushnumber(luaVM, static_cast<lua_Number>(color.B));
lua_pushnumber(luaVM, static_cast<lua_Number>(color.A));

if (!pMarker->AreAlphaLimitsIgnored() && (pMarker->GetMarkerType() == CMarker::TYPE_CHECKPOINT || pMarker->GetMarkerType() == CMarker::TYPE_ARROW))
lua_pushnumber(luaVM, 255); // fake alpha
else
lua_pushnumber(luaVM, static_cast<lua_Number>(color.A));

return 4;
}
}
Expand Down
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/logic/packets/CEntityAddPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,10 @@ bool CEntityAddPacket::Write(NetBitStreamInterface& BitStream) const
BitStream.WriteBit(false);
}

// Alpha limit
if (BitStream.Can(eBitStreamVersion::Marker_IgnoreAlphaLimits))
BitStream.WriteBit(pMarker->AreAlphaLimitsIgnored());

break;
}

Expand Down
4 changes: 4 additions & 0 deletions Shared/sdk/net/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ enum class eBitStreamVersion : unsigned short
// 2024-06-30
WorldSpecialProperty_TunnelWeatherBlend,

// Checkpoint & arrow alpha fix
// 2024-07-03
Marker_IgnoreAlphaLimits,

// Add "setMarkerTargetArrowProperties"
// 2024-07-05
SetMarkerTargetArrowProperties,
Expand Down

0 comments on commit 121048c

Please sign in to comment.