Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0009608: add bShallow argument for server-side water as well #240

Merged
merged 6 commits into from Aug 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Expand Up @@ -3902,14 +3902,19 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream)
vecVertices[i].fX = sX;
vecVertices[i].fY = sY;
}

bool bShallow = false;
if (bitStream.Version() >= 0x06C)
bitStream.ReadBit(bShallow);

CClientWater* pWater = NULL;
if (ucNumVertices == 3)
{
pWater = new CClientWater(g_pClientGame->GetManager(), EntityID, vecVertices[0], vecVertices[1], vecVertices[2]);
pWater = new CClientWater(g_pClientGame->GetManager(), EntityID, vecVertices[0], vecVertices[1], vecVertices[2], bShallow);
}
else
{
pWater = new CClientWater(g_pClientGame->GetManager(), EntityID, vecVertices[0], vecVertices[1], vecVertices[2], vecVertices[3]);
pWater = new CClientWater(g_pClientGame->GetManager(), EntityID, vecVertices[0], vecVertices[1], vecVertices[2], vecVertices[3], bShallow);
}
if (!pWater->Exists())
{
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaWaterDefs.cpp
Expand Up @@ -63,7 +63,7 @@ void CLuaWaterDefs::AddClass(lua_State* luaVM)

int CLuaWaterDefs::CreateWater(lua_State* luaVM)
{
// water createWater ( float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3 [, float x4, float y4, float z4 ] )
// water createWater ( float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3 [, float x4, float y4, float z4 ] [, bool bShallow = false ] )
CVector v1;
CVector v2;
CVector v3;
Expand Down
2 changes: 1 addition & 1 deletion Client/version.h
Expand Up @@ -74,7 +74,7 @@
#define _NETCODE_VERSION_BRANCH_ID 0x4 // Use 0x1 - 0xF to indicate an incompatible branch is being used (0x0 is reserved, 0x4 is trunk)
#define _CLIENT_NET_MODULE_VERSION 0x0A8 // (0x000 - 0xfff) Lvl9 wizards only
#define _NETCODE_VERSION 0x1DA // (0x000 - 0xfff) Increment when net messages change (pre-release)
#define MTA_DM_BITSTREAM_VERSION 0x06B // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).
#define MTA_DM_BITSTREAM_VERSION 0x06C // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).

// To avoid user confusion, make sure the ASE version matches only if communication is possible
#if defined(MTA_DM_CONNECT_TO_PUBLIC)
Expand Down
4 changes: 2 additions & 2 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -9093,12 +9093,12 @@ bool CStaticFunctionDefinitions::SetTeamFriendlyFire(CTeam* pTeam, bool bFriendl
return false;
}

CWater* CStaticFunctionDefinitions::CreateWater(CResource* pResource, CVector* pV1, CVector* pV2, CVector* pV3, CVector* pV4)
CWater* CStaticFunctionDefinitions::CreateWater(CResource* pResource, CVector* pV1, CVector* pV2, CVector* pV3, CVector* pV4, bool bShallow)
{
if (!pV1 || !pV2 || !pV3)
return NULL;

CWater* pWater = m_pWaterManager->Create(pV4 ? CWater::QUAD : CWater::TRIANGLE, pResource->GetDynamicElementRoot());
CWater* pWater = m_pWaterManager->Create(pV4 ? CWater::QUAD : CWater::TRIANGLE, pResource->GetDynamicElementRoot(), NULL, bShallow);

if (pWater)
{
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Expand Up @@ -522,7 +522,7 @@ class CStaticFunctionDefinitions
static bool SetTeamFriendlyFire(CTeam* pTeam, bool bFriendlyFire);

// Water funcs
static CWater* CreateWater(CResource* pResource, CVector* pV1, CVector* pV2, CVector* pV3, CVector* pV4);
static CWater* CreateWater(CResource* pResource, CVector* pV1, CVector* pV2, CVector* pV3, CVector* pV4, bool bShallow);
static bool SetElementWaterLevel(CWater* pWater, float fLevel);
static bool SetAllElementWaterLevel(float fLevel);
static bool SetWorldWaterLevel(float fLevel, bool bIncludeWorldNonSeaLevel);
Expand Down
7 changes: 6 additions & 1 deletion Server/mods/deathmatch/logic/CWater.cpp
Expand Up @@ -11,7 +11,7 @@

#include "StdInc.h"

CWater::CWater(CWaterManager* pWaterManager, CElement* pParent, CXMLNode* pNode, EWaterType waterType) : CElement(pParent, pNode)
CWater::CWater(CWaterManager* pWaterManager, CElement* pParent, CXMLNode* pNode, EWaterType waterType, bool bShallow) : CElement(pParent, pNode)
{
m_pWaterManager = pWaterManager;

Expand All @@ -25,6 +25,8 @@ CWater::CWater(CWaterManager* pWaterManager, CElement* pParent, CXMLNode* pNode,
if (m_WaterType == QUAD)
m_Vertices[3] = CVector(10.0f, 10.0f, 0.0f);

m_bShallow = bShallow;

if (m_pWaterManager)
m_pWaterManager->AddToList(this);
}
Expand Down Expand Up @@ -129,6 +131,9 @@ bool CWater::ReadSpecialData()
}
}

if (!GetCustomDataBool("shallow", m_bShallow, true))
m_bShallow = false;

RoundVertices();
if (!Valid())
{
Expand Down
4 changes: 3 additions & 1 deletion Server/mods/deathmatch/logic/CWater.h
Expand Up @@ -22,7 +22,7 @@ class CWater : public CElement
QUAD
};

CWater(CWaterManager* pWaterManager, CElement* pParent, CXMLNode* pNode = NULL, EWaterType waterType = QUAD);
CWater(CWaterManager* pWaterManager, CElement* pParent, CXMLNode* pNode = NULL, EWaterType waterType = QUAD, bool bShallow = false);
~CWater();

bool IsEntity() { return true; }
Expand All @@ -35,6 +35,7 @@ class CWater : public CElement
void Unlink();
bool ReadSpecialData();

bool IsWaterShallow() const { return m_bShallow; }
EWaterType GetWaterType() const { return m_WaterType; }
int GetNumVertices() const { return m_WaterType == TRIANGLE ? 3 : 4; }
bool GetVertex(int index, CVector& vecPosition) const;
Expand All @@ -51,4 +52,5 @@ class CWater : public CElement

SFixedArray<CVector, 4> m_Vertices;
EWaterType m_WaterType;
bool m_bShallow;
};
4 changes: 2 additions & 2 deletions Server/mods/deathmatch/logic/CWaterManager.cpp
Expand Up @@ -24,9 +24,9 @@ CWaterManager::~CWaterManager()
DeleteAll();
}

CWater* CWaterManager::Create(CWater::EWaterType waterType, CElement* pParent, CXMLNode* pNode)
CWater* CWaterManager::Create(CWater::EWaterType waterType, CElement* pParent, CXMLNode* pNode, bool bShallow)
{
CWater* pWater = new CWater(this, pParent, pNode, waterType);
CWater* pWater = new CWater(this, pParent, pNode, waterType, bShallow);
if (pWater->GetID() == INVALID_ELEMENT_ID)
{
delete pWater;
Expand Down
2 changes: 1 addition & 1 deletion Server/mods/deathmatch/logic/CWaterManager.h
Expand Up @@ -21,7 +21,7 @@ class CWaterManager
CWaterManager();
~CWaterManager();

CWater* Create(CWater::EWaterType waterType, CElement* pParent, CXMLNode* Node = NULL);
CWater* Create(CWater::EWaterType waterType, CElement* pParent, CXMLNode* Node = NULL, bool bShallow = false);
CWater* CreateFromXML(CElement* pParent, CXMLNode& Node, CEvents* pEvents);
void DeleteAll();

Expand Down
5 changes: 4 additions & 1 deletion Server/mods/deathmatch/logic/luadefs/CLuaWaterDefs.cpp
Expand Up @@ -56,6 +56,7 @@ int CLuaWaterDefs::CreateWater(lua_State* luaVM)

CVector v1, v2, v3, v4;
CVector* pv4 = NULL;
bool bShallow;
CScriptArgReader argStream(luaVM);
argStream.ReadVector3D(v1);
argStream.ReadVector3D(v2);
Expand All @@ -67,9 +68,11 @@ int CLuaWaterDefs::CreateWater(lua_State* luaVM)
pv4 = &v4;
}

argStream.ReadBool(bShallow, false);

if (!argStream.HasErrors())
{
CWater* pWater = CStaticFunctionDefinitions::CreateWater(pLuaMain->GetResource(), &v1, &v2, &v3, pv4);
CWater* pWater = CStaticFunctionDefinitions::CreateWater(pLuaMain->GetResource(), &v1, &v2, &v3, pv4, bShallow);
if (pWater)
{
CElementGroup* pGroup = pLuaMain->GetResource()->GetElementGroup();
Expand Down
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/packets/CEntityAddPacket.cpp
Expand Up @@ -1050,6 +1050,8 @@ bool CEntityAddPacket::Write(NetBitStreamInterface& BitStream) const
BitStream.Write((short)vecVertex.fY);
BitStream.Write(vecVertex.fZ);
}
if (BitStream.Version() >= 0x06C)
BitStream.WriteBit(pWater->IsWaterShallow());
break;
}

Expand Down
2 changes: 1 addition & 1 deletion Server/version.h
Expand Up @@ -77,7 +77,7 @@
#define _NETCODE_VERSION_BRANCH_ID 0x4 // Use 0x1 - 0xF to indicate an incompatible branch is being used (0x0 is reserved, 0x4 is trunk)
#define _SERVER_NET_MODULE_VERSION 0x0A8 // (0x000 - 0xfff) Lvl9 wizards only
#define _NETCODE_VERSION 0x1DA // (0x000 - 0xfff) Increment when net messages change (pre-release)
#define MTA_DM_BITSTREAM_VERSION 0x06B // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).
#define MTA_DM_BITSTREAM_VERSION 0x06C // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).

// To avoid user confusion, make sure the ASE version matches only if communication is possible
#if defined(MTA_DM_CONNECT_FROM_PUBLIC)
Expand Down