internal unsafe void InvalidateRange(Vector3I minVoxelChanged, Vector3I maxVoxelChanged, int lod) { if (this.m_bodiesInitialized) { if (this.m_queueInvalidation) { if (this.m_queuedRange.Max.X < 0) { this.m_queuedRange = new BoundingBoxI(minVoxelChanged, maxVoxelChanged); } else { BoundingBoxI box = new BoundingBoxI(minVoxelChanged, maxVoxelChanged); this.m_queuedRange.Include(ref box); } } else { Vector3I vectori; Vector3I vectori2; minVoxelChanged -= 2; maxVoxelChanged = (Vector3I)(maxVoxelChanged + 1); this.m_voxelMap.Storage.ClampVoxelCoord(ref minVoxelChanged, 1); this.m_voxelMap.Storage.ClampVoxelCoord(ref maxVoxelChanged, 1); MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref minVoxelChanged, out vectori); MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref maxVoxelChanged, out vectori2); Vector3I minChanged = (vectori - this.m_cellsOffset) >> lod; Vector3I result = (vectori2 - this.m_cellsOffset) >> lod; Vector3I geometryCellCoord = this.m_voxelMap.Size - 1; Vector3I *vectoriPtr1 = (Vector3I *)ref geometryCellCoord; MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref (Vector3I) ref vectoriPtr1, out geometryCellCoord); geometryCellCoord = geometryCellCoord >> lod; Vector3I *vectoriPtr2 = (Vector3I *)ref result; Vector3I.Min(ref (Vector3I) ref vectoriPtr2, ref geometryCellCoord, out result); HkRigidBody rigidBody = this.GetRigidBody(lod); if ((minChanged == Vector3I.Zero) && (result == geometryCellCoord)) { this.m_workTracker.CancelAll(); } else { using (MyUtils.ReuseCollection <MyCellCoord>(ref m_toBeCancelledCache)) { BoundingBoxI xi2 = new BoundingBoxI(vectori, vectori2); foreach (KeyValuePair <MyCellCoord, MyPrecalcJobPhysicsPrefetch> pair in this.m_workTracker) { if (xi2.Contains(pair.Key.CoordInLod) != ContainmentType.Disjoint) { m_toBeCancelledCache.Add(pair.Key); } } foreach (MyCellCoord coord in m_toBeCancelledCache) { this.m_workTracker.CancelIfStarted(coord); } } } if (rigidBody != null) { HkUniformGridShape shape = (HkUniformGridShape)rigidBody.GetShape(); int size = ((result - minChanged) + 1).Size; if (size >= m_cellsToGenerateBuffer.Length) { m_cellsToGenerateBuffer = new Vector3I[MathHelper.GetNearestBiggerPowerOfTwo(size)]; } int num2 = shape.InvalidateRange(ref minChanged, ref result, m_cellsToGenerateBuffer); for (int i = 0; i < num2; i++) { this.StartPrecalcJobPhysicsIfNeeded(lod, i); } } this.m_voxelMap.RaisePhysicsChanged(); } } }
private static unsafe void RemoveSmallVoxelsUsingChachedVoxels() { Vector3I vectori; Vector3I vectori2 = m_cache.Size3D; Vector3I max = vectori2 - 1; vectori.X = 0; goto TR_001E; TR_0003: int *numPtr4 = (int *)ref vectori.Z; numPtr4[0]++; TR_0018: while (true) { if (vectori.Z < vectori2.Z) { bool flag; int num = m_cache.Content(ref vectori); if (num <= 0) { goto TR_0003; } else if (num >= 0x7f) { goto TR_0003; } else { Vector3I vectori4; Vector3I result = vectori - 1; Vector3I vectori6 = (Vector3I)(vectori + 1); Vector3I *vectoriPtr1 = (Vector3I *)ref result; Vector3I.Clamp(ref (Vector3I) ref vectoriPtr1, ref Vector3I.Zero, ref max, out result); Vector3I *vectoriPtr2 = (Vector3I *)ref vectori6; Vector3I.Clamp(ref (Vector3I) ref vectoriPtr2, ref Vector3I.Zero, ref max, out vectori6); flag = false; vectori4.X = result.X; while (true) { if (vectori4.X > vectori6.X) { break; } vectori4.Y = result.Y; while (true) { if (vectori4.Y <= vectori6.Y) { vectori4.Z = result.Z; while (true) { if (vectori4.Z <= vectori6.Z) { if (m_cache.Content(ref vectori4) < 0x7f) { int *numPtr1 = (int *)ref vectori4.Z; numPtr1[0]++; continue; } flag = true; break; } else { int *numPtr2 = (int *)ref vectori4.Y; numPtr2[0]++; } break; } continue; } else { int *numPtr3 = (int *)ref vectori4.X; numPtr3[0]++; } break; } } } if (!flag) { m_cache.Content(ref vectori, 0); m_cache.Material(ref vectori, 0xff); } goto TR_0003; } else { int *numPtr5 = (int *)ref vectori.Y; numPtr5[0]++; } break; } TR_001B: while (true) { if (vectori.Y >= vectori2.Y) { int *numPtr6 = (int *)ref vectori.X; numPtr6[0]++; break; } vectori.Z = 0; goto TR_0018; } TR_001E: while (true) { if (vectori.X >= vectori2.X) { return; } vectori.Y = 0; break; } goto TR_001B; }
internal void Draw() { EntityShadow mode = game.Entities.ShadowMode; Vector3 Position = entity.Position; float posX = Position.X, posZ = Position.Z; int posY = Math.Min((int)Position.Y, game.World.Height - 1); int index = 0, vb = 0; radius = 7f * Math.Min(entity.ModelScale, 1) * entity.Model.ShadowScale; VertexP3fT2fC4b[] verts = null; int posCount = 0, dataCount = 0; Vector3I * coords = stackalloc Vector3I[4]; ShadowData *data = stackalloc ShadowData[4]; for (int i = 0; i < 4; i++) { coords[i] = new Vector3I(int.MinValue); data[i] = new ShadowData(); } if (mode == EntityShadow.SnapToBlock) { vb = game.Graphics.texVb; verts = game.Graphics.texVerts; if (!GetBlocks(coords, ref posCount, posX, posZ, posY, data, ref dataCount)) { return; } float x1 = Utils.Floor(posX), z1 = Utils.Floor(posZ); DraqSquareShadow(verts, ref index, data[0].Y, 220, x1, z1); } else { vb = game.ModelCache.vb; verts = game.ModelCache.vertices; float x = posX - radius / 16f, z = posZ - radius / 16f; if (GetBlocks(coords, ref posCount, x, z, posY, data, ref dataCount) && data[0].A > 0) { DrawCircle(verts, ref index, data, dataCount, x, z); } x = Math.Max(posX - radius / 16f, Utils.Floor(posX + radius / 16f)); if (GetBlocks(coords, ref posCount, x, z, posY, data, ref dataCount) && data[0].A > 0) { DrawCircle(verts, ref index, data, dataCount, x, z); } z = Math.Max(posZ - radius / 16f, Utils.Floor(posZ + radius / 16f)); if (GetBlocks(coords, ref posCount, x, z, posY, data, ref dataCount) && data[0].A > 0) { DrawCircle(verts, ref index, data, dataCount, x, z); } x = posX - radius / 16f; if (GetBlocks(coords, ref posCount, x, z, posY, data, ref dataCount) && data[0].A > 0) { DrawCircle(verts, ref index, data, dataCount, x, z); } } if (index == 0) { return; } CheckShadowTexture(game.Graphics); if (!boundShadowTex) { game.Graphics.BindTexture(shadowTex); boundShadowTex = true; } game.Graphics.UpdateDynamicIndexedVb(DrawMode.Triangles, vb, verts, index); }