mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-23 04:34:58 -04:00
Only pick a block if the intersection point is exactly within reach distance. Should address #461.
This commit is contained in:
parent
8ebc8cda7b
commit
bee207138c
@ -299,13 +299,8 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
}
|
||||
|
||||
internal override void DrawIndexedVb_TrisT2fC4b(int indicesCount, int startIndex) {
|
||||
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, startIndex / 6 * 4,
|
||||
indicesCount / 6 * 4, startIndex, indicesCount / 3);
|
||||
}
|
||||
|
||||
internal override void DrawIndexedVb_TrisT2fC4b(int indicesCount, int startVertex, int startIndex) {
|
||||
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, startVertex, 0,
|
||||
indicesCount / 6 * 4, startIndex, indicesCount / 3);
|
||||
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, startIndex / 6 * 4, 0,
|
||||
indicesCount / 6 * 4, 0, indicesCount / 3);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -180,8 +180,6 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
public abstract void DrawVb_IndexedTris(int indicesCount);
|
||||
|
||||
/// <summary> Optimised version of DrawIndexedVb for VertexFormat.Pos3fTex2fCol4b </summary>
|
||||
internal abstract void DrawIndexedVb_TrisT2fC4b(int indicesCount, int offsetVertex, int startIndex);
|
||||
|
||||
internal abstract void DrawIndexedVb_TrisT2fC4b(int indicesCount, int startIndex);
|
||||
|
||||
protected static int[] strideSizes = { 16, 24 };
|
||||
|
@ -395,22 +395,6 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
GL.DrawElements(BeginMode.Triangles, indicesCount, indexType, IntPtr.Zero);
|
||||
}
|
||||
|
||||
internal override void DrawIndexedVb_TrisT2fC4b(int indicesCount, int startVertex, int startIndex) {
|
||||
// TODO: This renders the whole map, bad performance!! FIX FIX
|
||||
if (glLists) {
|
||||
if (activeList != lastPartialList) {
|
||||
GL.CallList(activeList); lastPartialList = activeList;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int offset = startVertex * VertexP3fT2fC4b.Size;
|
||||
GL.VertexPointer(3, PointerType.Float, VertexP3fT2fC4b.Size, new IntPtr(offset));
|
||||
GL.ColorPointer(4, PointerType.UnsignedByte, VertexP3fT2fC4b.Size, new IntPtr(offset + 12));
|
||||
GL.TexCoordPointer(2, PointerType.Float, VertexP3fT2fC4b.Size, new IntPtr(offset + 16));
|
||||
GL.DrawElements(BeginMode.Triangles, indicesCount, indexType, IntPtr.Zero);
|
||||
}
|
||||
|
||||
IntPtr zero = new IntPtr(0), twelve = new IntPtr(12), sixteen = new IntPtr(16);
|
||||
|
||||
void SetupVbPos3fCol4b() {
|
||||
|
@ -11,7 +11,7 @@ using BlockID = System.Byte;
|
||||
#endif
|
||||
|
||||
namespace ClassicalSharp {
|
||||
public static class Picking {
|
||||
public static class Picking {
|
||||
|
||||
static RayTracer t = new RayTracer();
|
||||
|
||||
@ -34,7 +34,14 @@ namespace ClassicalSharp {
|
||||
if (!Intersection.RayIntersectsBox(t.Origin, t.Dir, t.Min, t.Max, out t0, out t1))
|
||||
return false;
|
||||
Vector3 I = t.Origin + t.Dir * t0;
|
||||
pos.SetAsValid(t.X, t.Y, t.Z, t.Min, t.Max, t.Block, I);
|
||||
|
||||
float lenSq = (I - t.Origin).LengthSquared;
|
||||
float reach = game.LocalPlayer.ReachDistance;
|
||||
if (lenSq <= reach * reach) {
|
||||
pos.SetAsValid(t.X, t.Y, t.Z, t.Min, t.Max, t.Block, I);
|
||||
} else {
|
||||
pos.SetAsInvalid();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -60,12 +67,12 @@ namespace ClassicalSharp {
|
||||
pos.SetAsValid(t.X, t.Y, t.Z, t.Min, t.Max, t.Block, I);
|
||||
|
||||
switch (pos.Face) {
|
||||
case BlockFace.XMin: pos.Intersect.X -= adjust; break;
|
||||
case BlockFace.XMax: pos.Intersect.X += adjust; break;
|
||||
case BlockFace.YMin: pos.Intersect.Y -= adjust; break;
|
||||
case BlockFace.YMax: pos.Intersect.Y += adjust; break;
|
||||
case BlockFace.ZMin: pos.Intersect.Z -= adjust; break;
|
||||
case BlockFace.ZMax: pos.Intersect.Z += adjust; break;
|
||||
case BlockFace.XMin: pos.Intersect.X -= adjust; break;
|
||||
case BlockFace.XMax: pos.Intersect.X += adjust; break;
|
||||
case BlockFace.YMin: pos.Intersect.Y -= adjust; break;
|
||||
case BlockFace.YMax: pos.Intersect.Y += adjust; break;
|
||||
case BlockFace.ZMin: pos.Intersect.Z -= adjust; break;
|
||||
case BlockFace.ZMax: pos.Intersect.Z += adjust; break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -197,8 +197,6 @@ namespace ClassicalSharp.Renderers {
|
||||
gfx.AlphaBlending = false;
|
||||
}
|
||||
|
||||
const int maxVertex = 65536;
|
||||
const int maxIndices = maxVertex / 4 * 6;
|
||||
void RenderNormalBatch(int batch) {
|
||||
for (int i = 0; i < renderCount; i++) {
|
||||
ChunkInfo info = renderChunks[i];
|
||||
@ -242,37 +240,16 @@ namespace ClassicalSharp.Renderers {
|
||||
game.Vertices += part.BackCount;
|
||||
}
|
||||
|
||||
// Special handling for top and bottom face, as these can go over 65536 vertices and we need to adjust the indices in this case.
|
||||
if (drawBottom && drawTop) {
|
||||
gfx.FaceCulling = true;
|
||||
if (part.IndicesCount > maxIndices) {
|
||||
int part1Count = maxIndices - part.BottomIndex;
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part1Count, part.BottomIndex);
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount + part.TopCount - part1Count, maxVertex, 0);
|
||||
} else {
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount + part.TopCount, part.BottomIndex);
|
||||
}
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount + part.TopCount, part.BottomIndex);
|
||||
gfx.FaceCulling = false;
|
||||
game.Vertices += part.TopCount + part.BottomCount;
|
||||
} else if (drawBottom) {
|
||||
int part1Count;
|
||||
if (part.IndicesCount > maxIndices &&
|
||||
(part1Count = maxIndices - part.BottomIndex) < part.BottomCount) {
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part1Count, part.BottomIndex);
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount - part1Count, maxVertex, 0);
|
||||
} else {
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, part.BottomIndex);
|
||||
}
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part.BottomCount, part.BottomIndex);
|
||||
game.Vertices += part.BottomCount;
|
||||
} else if (drawTop) {
|
||||
int part1Count;
|
||||
if (part.IndicesCount > maxIndices &&
|
||||
(part1Count = maxIndices - part.TopIndex) < part.TopCount) {
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part1Count, part.TopIndex);
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount - part1Count, maxVertex, 0);
|
||||
} else {
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, part.TopIndex);
|
||||
}
|
||||
gfx.DrawIndexedVb_TrisT2fC4b(part.TopCount, part.TopIndex);
|
||||
game.Vertices += part.TopCount;
|
||||
}
|
||||
|
||||
|
@ -374,15 +374,9 @@ void Gfx_DrawVb_IndexedTris_Range(Int32 indicesCount, Int32 startIndex) {
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_DrawVb_IndexedTris");
|
||||
}
|
||||
|
||||
void Gfx_DrawIndexedVb_TrisT2fC4b_Range(Int32 indicesCount, Int32 offsetVertex, Int32 startIndex) {
|
||||
ReturnCode hresult = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, offsetVertex,
|
||||
0, VCOUNT(indicesCount), startIndex, indicesCount / 3);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_DrawIndexedVb_TrisT2fC4b_Range");
|
||||
}
|
||||
|
||||
void Gfx_DrawIndexedVb_TrisT2fC4b(Int32 indicesCount, Int32 startIndex) {
|
||||
ReturnCode hresult = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0,
|
||||
VCOUNT(startIndex), VCOUNT(indicesCount), startIndex, indicesCount / 3);
|
||||
ReturnCode hresult = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, VCOUNT(startIndex),
|
||||
0, VCOUNT(indicesCount), 0, indicesCount / 3);
|
||||
ErrorHandler_CheckOrFail(hresult, "D3D9_DrawIndexedVb_TrisT2fC4b");
|
||||
}
|
||||
|
||||
|
@ -167,9 +167,6 @@ void Gfx_DrawVb_IndexedTris_Range(Int32 indicesCount, Int32 startIndex);
|
||||
/* Draws the specified subset of the vertices in the current vertex buffer as triangles. */
|
||||
void Gfx_DrawVb_IndexedTris(Int32 indicesCount);
|
||||
|
||||
/* Optimised version of DrawIndexedVb for VertexFormat_Pos3fTex2fCol4b */
|
||||
void Gfx_DrawIndexedVb_TrisT2fC4b_Range(Int32 indicesCount, Int32 offsetVertex, Int32 startIndex);
|
||||
|
||||
/* Optimised version of DrawIndexedVb for VertexFormat_Pos3fTex2fCol4b */
|
||||
void Gfx_DrawIndexedVb_TrisT2fC4b(Int32 indicesCount, Int32 startIndex);
|
||||
|
||||
|
@ -164,36 +164,17 @@ void MapRenderer_RenderNormalBatch(Int32 batch) {
|
||||
}
|
||||
offset += part.ZMinCount + part.ZMaxCount;
|
||||
|
||||
/* Special handling for top and bottom face, as these can go over 65536 vertices and we need to adjust the indices in this case. */
|
||||
if (drawYMin && drawYMax) {
|
||||
Gfx_SetFaceCulling(true);
|
||||
if (part.IndicesCount > Gfx_MaxIndices) {
|
||||
Int32 part1Count = Gfx_MaxIndices - offset;
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(part1Count, offset);
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b_Range(part.YMinCount + part.YMaxCount - part1Count, Gfx_MaxVertex, 0);
|
||||
} else {
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(part.YMinCount + part.YMaxCount, offset);
|
||||
}
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(part.YMinCount + part.YMaxCount, offset);
|
||||
Gfx_SetFaceCulling(false);
|
||||
Game_Vertices += part.YMaxCount + part.YMinCount;
|
||||
} else if (drawYMin) {
|
||||
Int32 part1Count;
|
||||
if (part.IndicesCount > Gfx_MaxIndices && (part1Count = Gfx_MaxIndices - offset) < part.YMinCount) {
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(part1Count, offset);
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b_Range(part.YMinCount - part1Count, Gfx_MaxVertex, 0);
|
||||
} else {
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(part.YMinCount, offset);
|
||||
}
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(part.YMinCount, offset);
|
||||
Game_Vertices += part.YMinCount;
|
||||
} else if (drawYMax) {
|
||||
offset += part.YMinCount;
|
||||
Int32 part1Count;
|
||||
if (part.IndicesCount > Gfx_MaxIndices && (part1Count = Gfx_MaxIndices - offset) < part.YMaxCount) {
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(part1Count, offset);
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b_Range(part.YMaxCount - part1Count, Gfx_MaxVertex, 0);
|
||||
} else {
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(part.YMaxCount, offset);
|
||||
}
|
||||
Gfx_DrawIndexedVb_TrisT2fC4b(part.YMaxCount, offset);
|
||||
Game_Vertices += part.YMaxCount;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user