fix: update logic worktrace

This commit is contained in:
Tungdv
2025-10-20 16:37:08 +07:00
parent 8ea53ac651
commit beb9d0f322
3 changed files with 108 additions and 93 deletions
@@ -1,6 +1,9 @@
using BrewMonster.Scripts.Player;
using CSNetwork.GPDataType;
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using ARectF = BrewMonster.Scripts.ARect<float>;
using ARectI = BrewMonster.Scripts.ARect<int>;
using BlockArray = System.Collections.Generic.List<BrewMonster.Scripts.World.A3DTerrain2Block>;
@@ -240,6 +243,7 @@ namespace BrewMonster.Scripts.World
public int m_iNumAllBlockRow = 0; // Row number of all blocks
public int m_iNumAllBlockCol = 0; // Column number of all blocks
public bool m_bVertexLight = false; // true, force to use vertex light rather than lightmap
public List<MeshFilter> m_lstMesh;
// Check lightmap or vertex-light is used
public bool UseLightmapTech() { return !m_bVertexLight; }
@@ -249,8 +253,16 @@ namespace BrewMonster.Scripts.World
// Get grid faces of specified area
public bool GetFacesOfArea(A3DVECTOR3 vCenter, int iGridWid, int iGridLen, ref A3DVECTOR3[] pVertBuf, ref WORD[] pIdxBuf)
{
if (m_pCurActBlocks.rcArea.IsEmpty())
//if (m_pCurActBlocks.rcArea.IsEmpty())
// return false;
if(m_lstMesh == null || m_lstMesh.Count == 0)
{
return false;
}
float halfW = (iGridWid * m_fGridSize) / 2f;
float halfL = (iGridLen * m_fGridSize) / 2f;
Bounds area = new Bounds(EC_Utility.ToVector3(vCenter), new Vector3(halfW * 2, 1000f, halfL * 2));
float fInvGridSize = 1.0f / m_fGridSize;
@@ -10,87 +10,88 @@ namespace BrewMonster.Scripts.Ornament
public virtual bool TraceWithBrush(ref BrushTraceInfo pInfo)
{
bool bCollide = false;
//TO DO: fix later
//save original result
bool bStartSolid = pInfo.bStartSolid; // Collide something at start point
bool bAllSolid = pInfo.bAllSolid; // All in something
int iClipPlane = pInfo.iClipPlane; // Clip plane's index
float fFraction = 100.0f; // Fraction
A3DVECTOR3 vNormal = pInfo.ClipPlane.GetNormal(); //clip plane normal
float fDist = pInfo.ClipPlane.GetDist(); //clip plane dist
//bool bStartSolid = pInfo.bStartSolid; // Collide something at start point
//bool bAllSolid = pInfo.bAllSolid; // All in something
//int iClipPlane = pInfo.iClipPlane; // Clip plane's index
//float fFraction = 100.0f; // Fraction
//A3DVECTOR3 vNormal = pInfo.ClipPlane.GetNormal(); //clip plane normal
//float fDist = pInfo.ClipPlane.GetDist(); //clip plane dist
if (m_pBrushMan != null && m_pBrushMan.Trace(pInfo)
&& (pInfo.fFraction < fFraction))
{
fFraction = pInfo.fFraction;
bAllSolid = pInfo.bAllSolid;
bStartSolid = pInfo.bStartSolid;
iClipPlane = pInfo.iClipPlane;
vNormal = pInfo.ClipPlane.GetNormal();
fDist = pInfo.ClipPlane.GetDist();
bCollide = true;
}
//if (m_pBrushMan != null && m_pBrushMan.Trace(pInfo)
// && (pInfo.fFraction < fFraction))
//{
// fFraction = pInfo.fFraction;
// bAllSolid = pInfo.bAllSolid;
// bStartSolid = pInfo.bStartSolid;
// iClipPlane = pInfo.iClipPlane;
// vNormal = pInfo.ClipPlane.GetNormal();
// fDist = pInfo.ClipPlane.GetDist();
// bCollide = true;
//}
HomeOnmtTable::iterator it1 = m_HomeOrnamentTab.begin();
for (; it1 != m_HomeOrnamentTab.end(); ++it1)
{
CECHomeOrnament* pHomeOrnament = *it1.value();
if (!pHomeOrnament.IsLoaded())
continue;
//HomeOnmtTable::iterator it1 = m_HomeOrnamentTab.begin();
//for (; it1 != m_HomeOrnamentTab.end(); ++it1)
//{
// CECHomeOrnament* pHomeOrnament = *it1.value();
// if (!pHomeOrnament.IsLoaded())
// continue;
CELBuildingWithBrush* pBuildingWithBrush = pHomeOrnament.GetBuildingWithBrush();
if (pBuildingWithBrush && pBuildingWithBrush.TraceWithBrush(pInfo) && (pInfo.fFraction < fFraction))
{
fFraction = pInfo.fFraction;
bAllSolid = pInfo.bAllSolid;
bStartSolid = pInfo.bStartSolid;
iClipPlane = pInfo.iClipPlane;
vNormal = pInfo.ClipPlane.GetNormal();
fDist = pInfo.ClipPlane.GetDist();
bCollide = true;
}
}
// CELBuildingWithBrush* pBuildingWithBrush = pHomeOrnament.GetBuildingWithBrush();
// if (pBuildingWithBrush && pBuildingWithBrush.TraceWithBrush(pInfo) && (pInfo.fFraction < fFraction))
// {
// fFraction = pInfo.fFraction;
// bAllSolid = pInfo.bAllSolid;
// bStartSolid = pInfo.bStartSolid;
// iClipPlane = pInfo.iClipPlane;
// vNormal = pInfo.ClipPlane.GetNormal();
// fDist = pInfo.ClipPlane.GetDist();
// bCollide = true;
// }
//}
// now see if collide with forest
CELForest* pForest = g_pGame.GetGameRun().GetWorld().GetForest();
if ((fFraction > 0.0f) && pForest
&& pForest.TraceWithBrush(pInfo)
&& (pInfo.fFraction < fFraction))
{
fFraction = pInfo.fFraction;
bAllSolid = pInfo.bAllSolid;
bStartSolid = pInfo.bStartSolid;
iClipPlane = pInfo.iClipPlane;
vNormal = pInfo.ClipPlane.GetNormal();
fDist = pInfo.ClipPlane.GetDist();
bCollide = true;
}
//// now see if collide with forest
//CELForest* pForest = g_pGame.GetGameRun().GetWorld().GetForest();
//if ((fFraction > 0.0f) && pForest
// && pForest.TraceWithBrush(pInfo)
// && (pInfo.fFraction < fFraction))
//{
// fFraction = pInfo.fFraction;
// bAllSolid = pInfo.bAllSolid;
// bStartSolid = pInfo.bStartSolid;
// iClipPlane = pInfo.iClipPlane;
// vNormal = pInfo.ClipPlane.GetNormal();
// fDist = pInfo.ClipPlane.GetDist();
// bCollide = true;
//}
// now see if collide with dynamic scene building
ECModelTable::iterator it = m_ECModelTab.begin();
for (; it != m_ECModelTab.end(); ++it)
{
ECMODELNODE* pNode = *it.value();
if ((fFraction > 0.0f) && pNode
&& pNode.TraceWithBrush(pInfo)
&& (pInfo.fFraction < fFraction))
{
fFraction = pInfo.fFraction;
bAllSolid = pInfo.bAllSolid;
bStartSolid = pInfo.bStartSolid;
iClipPlane = pInfo.iClipPlane;
vNormal = pInfo.ClipPlane.GetNormal();
fDist = pInfo.ClipPlane.GetDist();
bCollide = true;
}
}
//// now see if collide with dynamic scene building
//ECModelTable::iterator it = m_ECModelTab.begin();
//for (; it != m_ECModelTab.end(); ++it)
//{
// ECMODELNODE* pNode = *it.value();
// if ((fFraction > 0.0f) && pNode
// && pNode.TraceWithBrush(pInfo)
// && (pInfo.fFraction < fFraction))
// {
// fFraction = pInfo.fFraction;
// bAllSolid = pInfo.bAllSolid;
// bStartSolid = pInfo.bStartSolid;
// iClipPlane = pInfo.iClipPlane;
// vNormal = pInfo.ClipPlane.GetNormal();
// fDist = pInfo.ClipPlane.GetDist();
// bCollide = true;
// }
//}
//set back
pInfo.fFraction = fFraction;
pInfo.bStartSolid = bStartSolid;
pInfo.bAllSolid = bAllSolid;
pInfo.iClipPlane = iClipPlane;
pInfo.ClipPlane.SetNormal(vNormal);
pInfo.ClipPlane.SetD(fDist);
////set back
//pInfo.fFraction = fFraction;
//pInfo.bStartSolid = bStartSolid;
//pInfo.bAllSolid = bAllSolid;
//pInfo.iClipPlane = iClipPlane;
//pInfo.ClipPlane.SetNormal(vNormal);
//pInfo.ClipPlane.SetD(fDist);
return bCollide;
}
+20 -18
View File
@@ -502,28 +502,30 @@ namespace BrewMonster.Scripts
public static bool AABBCollideWithBrush(ref BrushTraceInfo pInfo)
{
CECWorld pWorld = CECWorld.Instance; //g_pGame.GetGameRun().GetWorld();
//TO DO: fix later
return false;
//CECWorld pWorld = CECWorld.Instance; //g_pGame.GetGameRun().GetWorld();
CECOrnamentMan pOrnMan = pWorld.GetOrnamentMan();
bool bBrush = pOrnMan.TraceWithBrush(ref pInfo);
//CECOrnamentMan pOrnMan = pWorld.GetOrnamentMan();
//bool bBrush = pOrnMan.TraceWithBrush(ref pInfo);
BrushTraceInfo info = pInfo;
CECMatterMan pMatterMan = pWorld.GetMatterMan();
if (pMatterMan.TraceWithBrush(&info) && info.fFraction < pInfo.fFraction)
{
*pInfo = info;
bBrush = true;
}
//BrushTraceInfo info = pInfo;
//CECMatterMan pMatterMan = pWorld.GetMatterMan();
//if (pMatterMan.TraceWithBrush(ref info) && info.fFraction < pInfo.fFraction)
//{
// pInfo = info;
// bBrush = true;
//}
info = *pInfo;
CECNPCMan* pNPCMan = pWorld.GetNPCMan();
if (pNPCMan.TraceWithBrush(&info) && info.fFraction < pInfo.fFraction)
{
*pInfo = info;
bBrush = true;
}
//info = pInfo;
//CECNPCMan pNPCMan = pWorld.GetNPCMan();
//if (pNPCMan.TraceWithBrush(ref info) && info.fFraction < pInfo.fFraction)
//{
// pInfo = info;
// bBrush = true;
//}
return bBrush;
//return bBrush;
}
}
public struct OtherPlayer_Move_Info