Core/Vmap: Fix vmaps not getting floor on gameobjects

This commit is contained in:
hondacrx
2018-03-21 23:44:08 -04:00
parent caa3cfed24
commit caad52f636
6 changed files with 24 additions and 21 deletions
@@ -33,12 +33,10 @@ namespace Game.Collision
void init_empty() void init_empty()
{ {
tree.Clear(); tree= new uint[3];
objects.Clear(); objects = new uint[0];
// create space for the first node // create space for the first node
tree.Add(3u << 30); // dummy leaf tree[0] = (3u << 30); // dummy leaf
tree.Add(0);
tree.Add(0);
} }
void buildHierarchy(List<uint> tempTree, buildData dat, BuildStats stats) void buildHierarchy(List<uint> tempTree, buildData dat, BuildStats stats)
@@ -278,14 +276,14 @@ namespace Game.Collision
bounds = new AxisAlignedBox(lo, hi); bounds = new AxisAlignedBox(lo, hi);
uint treeSize = reader.ReadUInt32(); uint treeSize = reader.ReadUInt32();
tree.Clear(); tree = new uint[treeSize];
for (var i = 0; i < treeSize; i++) for (var i = 0; i < treeSize; i++)
tree.Add(reader.ReadUInt32()); tree[i] = reader.ReadUInt32();
var count = reader.ReadUInt32(); var count = reader.ReadUInt32();
objects.Clear(); objects = new uint[count];
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
objects.Add(reader.ReadUInt32()); objects[i] = reader.ReadUInt32();
return true; return true;
} }
@@ -314,12 +312,14 @@ namespace Game.Collision
BuildStats stats = new BuildStats(); BuildStats stats = new BuildStats();
buildHierarchy(tempTree, dat, stats); buildHierarchy(tempTree, dat, stats);
objects = new uint[dat.numPrims];
for (int i = 0; i < dat.numPrims; ++i) for (int i = 0; i < dat.numPrims; ++i)
objects.Add(dat.indices[i]); objects[i] = dat.indices[i];
tree = tempTree;
tree = tempTree.ToArray();
} }
public uint primCount() { return (uint)objects.Count; } public uint primCount() { return (uint)objects.Length; }
public void intersectRay(Ray r, WorkerCallback intersectCallback, ref float maxDist, bool stopAtFirst = false) public void intersectRay(Ray r, WorkerCallback intersectCallback, ref float maxDist, bool stopAtFirst = false)
{ {
@@ -612,8 +612,8 @@ namespace Game.Collision
AxisAlignedBox bounds; AxisAlignedBox bounds;
List<uint> tree = new List<uint>(); uint[] tree;
List<uint> objects = new List<uint>(); uint[] objects;
[StructLayout(LayoutKind.Explicit)] [StructLayout(LayoutKind.Explicit)]
public struct FloatToIntConverter public struct FloatToIntConverter
@@ -85,7 +85,7 @@ namespace Game.Collision
} }
/// Intersect ray /// Intersect ray
public override bool Invoke(Ray ray, uint idx, ref float maxDist) public override bool Invoke(Ray ray, uint idx, ref float maxDist, bool stopAtFirst)
{ {
if (idx >= objects_size) if (idx >= objects_size)
return false; return false;
+2 -3
View File
@@ -25,7 +25,6 @@ namespace Game.Collision
{ {
public virtual void Invoke(Vector3 point, uint entry) { } public virtual void Invoke(Vector3 point, uint entry) { }
public virtual bool Invoke(Ray ray, uint entry, ref float distance, bool pStopAtFirstHit) { return false; } public virtual bool Invoke(Ray ray, uint entry, ref float distance, bool pStopAtFirstHit) { return false; }
public virtual bool Invoke(Ray r, GameObjectModel obj, ref float distance) { return false; }
public virtual bool Invoke(Ray r, IModel obj, ref float distance) { return false; } public virtual bool Invoke(Ray r, IModel obj, ref float distance) { return false; }
public virtual bool Invoke(Ray ray, uint idx, ref float maxDist) { return false; } public virtual bool Invoke(Ray ray, uint idx, ref float maxDist) { return false; }
} }
@@ -234,9 +233,9 @@ namespace Game.Collision
_phases = phases; _phases = phases;
} }
public override bool Invoke(Ray r, GameObjectModel obj, ref float distance) public override bool Invoke(Ray r, IModel obj, ref float distance)
{ {
_didHit = obj.intersectRay(r, ref distance, true, _phases); _didHit = obj.IntersectRay(r, ref distance, true, _phases);
return _didHit; return _didHit;
} }
@@ -86,7 +86,7 @@ namespace Game.Collision
return mdl; return mdl;
} }
public bool intersectRay(Ray ray, ref float maxDist, bool stopAtFirstHit, List<uint> phases) public override bool IntersectRay(Ray ray, ref float maxDist, bool stopAtFirstHit, List<uint> phases)
{ {
if (!isCollisionEnabled() || !owner.IsSpawned()) if (!isCollisionEnabled() || !owner.IsSpawned())
return false; return false;
+4
View File
@@ -16,6 +16,7 @@
*/ */
using Framework.GameMath; using Framework.GameMath;
using System.Collections.Generic;
namespace Game.Collision namespace Game.Collision
{ {
@@ -23,5 +24,8 @@ namespace Game.Collision
{ {
public virtual Vector3 getPosition() { return default(Vector3); } public virtual Vector3 getPosition() { return default(Vector3); }
public virtual AxisAlignedBox getBounds() { return default(AxisAlignedBox); } public virtual AxisAlignedBox getBounds() { return default(AxisAlignedBox); }
public virtual bool IntersectRay(Ray ray, ref float maxDist, bool stopAtFirstHit, List<uint> phases) { return false; }
public virtual bool IntersectRay(Ray ray, ref float distance, bool stopAtFirstHit) { return false; }
} }
} }
+2 -2
View File
@@ -249,7 +249,7 @@ namespace Game.Collision
return true; return true;
} }
public bool IntersectRay(Ray ray, ref float distance, bool stopAtFirstHit) public override bool IntersectRay(Ray ray, ref float distance, bool stopAtFirstHit)
{ {
if (triangles.Empty()) if (triangles.Empty())
return false; return false;
@@ -311,7 +311,7 @@ namespace Game.Collision
RootWMOID = 0; RootWMOID = 0;
} }
public bool IntersectRay(Ray ray, ref float distance, bool stopAtFirstHit) public override bool IntersectRay(Ray ray, ref float distance, bool stopAtFirstHit)
{ {
// small M2 workaround, maybe better make separate class with virtual intersection funcs // small M2 workaround, maybe better make separate class with virtual intersection funcs
// in any case, there's no need to use a bound tree if we only have one submodel // in any case, there's no need to use a bound tree if we only have one submodel