Physics engine optimisations

This commit is contained in:
UnknownShadow200 2018-02-07 15:08:28 +11:00
parent 5b979cf39d
commit 303b71c3d5
21 changed files with 117 additions and 133 deletions

View File

@ -1,45 +0,0 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
namespace MCGalaxy.Blocks.Physics {
public static class AIPhysics {
public static Player ClosestPlayer(Level lvl, ushort x, ushort y, ushort z) {
if (!lvl.Config.AnimalHuntAI) return null;
int closestDist = 75;
Player closetPlayer = null;
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {
if (p.level == lvl && !p.invincible) {
int curDist = Math.Abs(p.Pos.BlockX - x) +
Math.Abs(p.Pos.BlockY - y) +
Math.Abs(p.Pos.BlockZ - z);
if (curDist < closestDist) {
closestDist = curDist;
closetPlayer = p;
}
}
}
return closetPlayer;
}
}
}

View File

@ -38,8 +38,8 @@ namespace MCGalaxy.Blocks.Physics {
!lvl.listUpdateExists.Get(x + dx * 2, y + dy * 2, z + dz * 2);
if (isFree) {
lvl.AddUpdate(bHead, Block.RocketHead);
lvl.AddUpdate(bTail, Block.LavaFire);
lvl.AddUpdate(bHead, Block.RocketHead, default(PhysicsArgs));
lvl.AddUpdate(bTail, Block.LavaFire, default(PhysicsArgs));
}
} else if (block == Block.Fireworks) {
bool isFree =
@ -49,7 +49,7 @@ namespace MCGalaxy.Blocks.Physics {
!lvl.listUpdateExists.Get(x + dx, y + dy + 2, z + dz);
if (isFree) {
lvl.AddUpdate(bHead, Block.Fireworks);
lvl.AddUpdate(bHead, Block.Fireworks, default(PhysicsArgs));
PhysicsArgs args = default(PhysicsArgs);
args.Type1 = PhysicsArgs.Dissipate; args.Value1 = 100;
lvl.AddUpdate(bTail, Block.StillLava, args);
@ -123,8 +123,7 @@ namespace MCGalaxy.Blocks.Physics {
if (index == -1) return;
byte block = lvl.blocks[index];
BlockID convBlock = Block.Convert(block);
if (convBlock == Block.Water || convBlock == Block.Lava ||
(block >= Block.Red && block <= Block.White)) {
if (convBlock == Block.Water || convBlock == Block.Lava || (block >= Block.Red && block <= Block.White)) {
lvl.AddCheck(index); return;
}

View File

@ -42,7 +42,7 @@ namespace MCGalaxy.Blocks.Physics {
public static void DoFlood(Level lvl, ref Check C, AirFlood mode, byte block) {
if (C.data.Data >= 1) {
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
C.data.Data = PhysicsArgs.RemoveFromChecks; return;
}
ushort x, y, z;

View File

@ -60,7 +60,7 @@ namespace MCGalaxy.Blocks.Physics {
FlyTo(lvl, ref C, x, y, (ushort)(z + 1), block);
break;
}
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
C.data.Data = PhysicsArgs.RemoveFromChecks;
}

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Blocks.Physics {
BlockID below = lvl.GetBlock(x, (ushort)(y - 1), z);
if (below == Block.Air) {
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), Block.Magma);
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), Block.Magma, default(PhysicsArgs));
} else if (below != Block.Magma) {
byte block = lvl.blocks[C.b];
LiquidPhysics.PhysLava(lvl, (ushort)(x + 1), y, z, block);
@ -57,7 +57,7 @@ namespace MCGalaxy.Blocks.Physics {
BlockID block = lvl.GetBlock((ushort)x, (ushort)y, (ushort)z, out index);
if (index >= 0 && lvl.Props[block].LavaKills) {
lvl.AddUpdate(index, Block.Magma);
lvl.AddUpdate(index, Block.Magma, default(PhysicsArgs));
flowUp = true;
}
}
@ -69,7 +69,7 @@ namespace MCGalaxy.Blocks.Physics {
BlockID below = lvl.GetBlock(x, (ushort)(y - 1), z);
if (below == Block.Air) {
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), Block.Geyser);
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), Block.Geyser, default(PhysicsArgs));
} else if (below != Block.Geyser) {
byte block = lvl.blocks[C.b];
LiquidPhysics.PhysWater(lvl, (ushort)(x + 1), y, z, block);
@ -96,7 +96,7 @@ namespace MCGalaxy.Blocks.Physics {
BlockID block = lvl.GetBlock((ushort)x, (ushort)y, (ushort)z, out index);
if (index >= 0 && lvl.Props[block].WaterKills) {
lvl.AddUpdate(index, Block.Geyser);
lvl.AddUpdate(index, Block.Geyser, default(PhysicsArgs));
flowUp = true;
}
}
@ -108,7 +108,7 @@ namespace MCGalaxy.Blocks.Physics {
switch (below) {
case Block.Air:
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), Block.WaterDown);
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), Block.WaterDown, default(PhysicsArgs));
if (!C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
break;
case Block.Air_FloodDown:
@ -136,7 +136,7 @@ namespace MCGalaxy.Blocks.Physics {
switch (below)
{
case Block.Air:
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), Block.LavaDown);
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), Block.LavaDown, default(PhysicsArgs));
if (!C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
break;
case Block.Air_FloodDown:
@ -169,7 +169,7 @@ namespace MCGalaxy.Blocks.Physics {
byte block = lvl.blocks[index];
if (block == Block.Air || block == target) {
if (rand.Next(1, 10) > 7)
lvl.AddUpdate(index, Block.Air_FloodDown);
lvl.AddUpdate(index, Block.Air_FloodDown, default(PhysicsArgs));
} else if (block == Block.Air_FloodDown) {
if (rand.Next(1, 10) > 4)
lvl.AddUpdate(index, target);

View File

@ -69,7 +69,7 @@ namespace MCGalaxy.Blocks.Physics {
if (args.Wait) {
if (C.data.Door && C.data.Data == 0) {
BlockID block = (BlockID)(C.data.Value2 | (C.data.ExtBlock ? Block.Extended : 0));
BlockID block = (BlockID)(C.data.Value2 | (C.data.ExtBlock ? Block.Extended : 0));
bool tdoor = lvl.Props[block].IsTDoor;
if (tdoor) DoorPhysics.tDoor(lvl, ref C);
@ -125,7 +125,7 @@ namespace MCGalaxy.Blocks.Physics {
// drop can generate another block with no dissipate/explode information.
if (args.Dissipate && rand.Next(1, 100) <= args.DissipateNum) {
if (!lvl.listUpdateExists.Get(x, y, z)) {
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
C.data.ResetTypes();
args.Drop = false;
} else {
@ -150,10 +150,10 @@ namespace MCGalaxy.Blocks.Physics {
lvl.AddUpdate(C.b, Block.Red, C.data);
} else {
BlockID next = block == Block.Pink ? Block.Red : (BlockID)(block + 1);
lvl.AddUpdate(C.b, next);
lvl.AddUpdate(C.b, next, default(PhysicsArgs));
}
} else {
lvl.AddUpdate(C.b, (BlockID)rand.Next(Block.Red, Block.Pink + 1));
lvl.AddUpdate(C.b, (BlockID)rand.Next(Block.Red, Block.Pink + 1), default(PhysicsArgs));
}
}
@ -166,7 +166,7 @@ namespace MCGalaxy.Blocks.Physics {
return;
if (rand.Next(1, 100) < dropnum && lvl.AddUpdate(index, lvl.blocks[C.b], C.data)) {
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
C.data.ResetTypes();
}
}

View File

@ -31,10 +31,10 @@ namespace MCGalaxy.Blocks.Physics {
BlockID below = lvl.GetBlock(x, (ushort)(y - 1), z);
if (below == Block.Air) {
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), lvl.blocks[C.b], C.data);
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
C.data.ResetTypes();
} else if (below == Block.StillWater || below == Block.StillLava) {
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
C.data.ResetTypes();
} else {
const int count = 25;
@ -69,7 +69,7 @@ namespace MCGalaxy.Blocks.Physics {
int index;
if (lvl.IsAirAt(posX, y, posZ, out index) && lvl.AddUpdate(index, lvl.blocks[C.b], C.data)) {
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
C.data.ResetTypes();
return;
}
@ -81,7 +81,7 @@ namespace MCGalaxy.Blocks.Physics {
static bool Expand(Level lvl, int x, int y, int z) {
int index = lvl.PosToInt((ushort)x, (ushort)y, (ushort)z);
if (index >= 0 && lvl.blocks[index] == Block.Air &&
lvl.AddUpdate(index, Block.FiniteWater)) {
lvl.AddUpdate(index, Block.FiniteWater, default(PhysicsArgs))) {
return true;
}
return false;

View File

@ -25,7 +25,7 @@ namespace MCGalaxy.Blocks.Physics {
static bool ExpandSimple(Level lvl, int x, int y, int z) {
int index;
if (lvl.IsAirAt((ushort)x, (ushort)y, (ushort)z, out index)) {
lvl.AddUpdate(index, Block.Fire);
lvl.AddUpdate(index, Block.Fire, default(PhysicsArgs));
return true;
}
return false;
@ -38,11 +38,11 @@ namespace MCGalaxy.Blocks.Physics {
if (!lvl.Props[block].LavaKills) return;
if (dx != 0)
lvl.AddUpdate(lvl.PosToInt((ushort)(x + dx), y, z), Block.Fire);
lvl.AddUpdate(lvl.PosToInt((ushort)(x + dx), y, z), Block.Fire, default(PhysicsArgs));
if (dy != 0)
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y + dy), z), Block.Fire);
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y + dy), z), Block.Fire, default(PhysicsArgs));
if (dz != 0)
lvl.AddUpdate(lvl.PosToInt(x, y, (ushort)(z + dz)), Block.Fire);
lvl.AddUpdate(lvl.PosToInt(x, y, (ushort)(z + dz)), Block.Fire, default(PhysicsArgs));
}
static void ExpandAvanced(Level lvl, int x, int y, int z) {
@ -53,7 +53,7 @@ namespace MCGalaxy.Blocks.Physics {
if (block == Block.TNT) {
lvl.MakeExplosion((ushort)x, (ushort)y, (ushort)z, -1);
} else if (lvl.Props[block].LavaKills) {
lvl.AddUpdate(index, Block.Fire);
lvl.AddUpdate(index, Block.Fire, default(PhysicsArgs));
}
}
@ -102,15 +102,15 @@ namespace MCGalaxy.Blocks.Physics {
if (C.data.Data > 5) {
int dropType = rand.Next(1, 10);
if (dropType <= 2) {
lvl.AddUpdate(C.b, Block.CoalOre);
lvl.AddUpdate(C.b, Block.CoalOre, default(PhysicsArgs));
C.data.Type1 = PhysicsArgs.Drop; C.data.Value1 = 63;
C.data.Type2 = PhysicsArgs.Dissipate; C.data.Value2 = 10;
} else if (dropType <= 4) {
lvl.AddUpdate(C.b, Block.Obsidian);
lvl.AddUpdate(C.b, Block.Obsidian, default(PhysicsArgs));
C.data.Type1 = PhysicsArgs.Drop; C.data.Value1 = 63;
C.data.Type2 = PhysicsArgs.Dissipate; C.data.Value2 = 10;
} else if (dropType <= 8) {
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
} else {
C.data.Data = 3;
}

View File

@ -42,7 +42,7 @@ namespace MCGalaxy.Blocks.Physics {
args.Type1 = PhysicsArgs.Wait; args.Value1 = 1;
args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 100;
lvl.AddUpdate(bAbove, Block.Fireworks);
lvl.AddUpdate(bAbove, Block.Fireworks, default(PhysicsArgs));
lvl.AddUpdate(C.b, Block.StillLava, args);
args.Data = C.data.Data;
C.data = args;
@ -60,7 +60,7 @@ namespace MCGalaxy.Blocks.Physics {
int min = Math.Min(rand1, rand2), max = Math.Max(rand1, rand2);
// Not using override, since override = true makes it more likely that a colored block will be
// generated with no extraInfo, because it sets a Check for that position with no extraInfo.
lvl.AddUpdate(lvl.PosToInt(x, y, z), Block.Air);
lvl.AddUpdate(lvl.PosToInt(x, y, z), Block.Air, default(PhysicsArgs));
int index;
for (int yy = y - (size + 1); yy <= y + (size + 1); ++yy)

View File

@ -22,13 +22,13 @@ namespace MCGalaxy.Blocks.Physics {
public static class HunterPhysics {
// dir is 1 for hunting birds (they go towards the closest player)
// dir is -1 for fleeing birds (they go away from the closest player)
// dir is 1 for hunting animals (they go towards the closest player)
// dir is -1 for fleeing animals (they go away from the closest player)
public static void Do(Level lvl, ref Check C, BlockID target, int dir) {
Random rand = lvl.physRandom;
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);
Player closest = AIPhysics.ClosestPlayer(lvl, x, y, z);
Player closest = ClosestPlayer(lvl, x, y, z);
if (closest != null && rand.Next(1, 20) < 19) {
int dirsVisited = 0;
@ -103,5 +103,23 @@ namespace MCGalaxy.Blocks.Physics {
}
return false;
}
public static Player ClosestPlayer(Level lvl, ushort x, ushort y, ushort z) {
if (!lvl.Config.AnimalHuntAI) return null;
int closestDist = 75;
Player closetPlayer = null;
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {
if (p.level != lvl || p.invincible) continue;
Position pos = p.Pos;
int curDist = Math.Abs(pos.BlockX - x) + Math.Abs(pos.BlockY - y) + Math.Abs(pos.BlockZ - z);
if (curDist < closestDist) {
closestDist = curDist;
closetPlayer = p;
}
}
return closetPlayer;
}
}
}

View File

@ -42,7 +42,7 @@ namespace MCGalaxy.Blocks.Physics {
}
// Perform actual leaf decay, then remove from physics list
if (DoLeafDecay(lvl, ref C)) lvl.AddUpdate(C.b, Block.Air);
if (DoLeafDecay(lvl, ref C)) lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
C.data.Data = PhysicsArgs.RemoveFromChecks;
}

View File

@ -31,13 +31,17 @@ namespace MCGalaxy.Blocks.Physics {
switch (block) {
case Block.Air:
if (!lvl.CheckSpongeWater(x, y, z)) lvl.AddUpdate(b, type);
if (!lvl.CheckSpongeWater(x, y, z)) {
lvl.AddUpdate(b, type);
}
break;
case Block.Lava:
case Block.FastLava:
case Block.Deadly_ActiveLava:
if (!lvl.CheckSpongeWater(x, y, z)) lvl.AddUpdate(b, Block.Stone);
if (!lvl.CheckSpongeWater(x, y, z)) {
lvl.AddUpdate(b, Block.Stone, default(PhysicsArgs));
}
break;
case Block.Sand:
@ -49,8 +53,9 @@ namespace MCGalaxy.Blocks.Physics {
// Adv physics kills flowers and mushrooms in water
if (!lvl.Props[block].WaterKills) break;
if (lvl.physics > 1 && !lvl.CheckSpongeWater(x, y, z))
lvl.AddUpdate(b, Block.Air);
if (lvl.physics > 1 && !lvl.CheckSpongeWater(x, y, z)) {
lvl.AddUpdate(b, Block.Air, default(PhysicsArgs));
}
break;
}
}
@ -64,17 +69,23 @@ namespace MCGalaxy.Blocks.Physics {
switch (block) {
case Block.Air:
if (!lvl.CheckSpongeLava(x, y, z)) lvl.AddUpdate(b, type);
if (!lvl.CheckSpongeLava(x, y, z)) {
lvl.AddUpdate(b, type);
}
break;
case Block.Water:
case Block.Deadly_ActiveWater:
if (!lvl.CheckSpongeLava(x, y, z)) lvl.AddUpdate(b, Block.Stone);
if (!lvl.CheckSpongeLava(x, y, z)) {
lvl.AddUpdate(b, Block.Stone, default(PhysicsArgs));
}
break;
case Block.Sand:
if (lvl.physics > 1) { //Adv physics changes sand to glass next to lava
if (lvl.physics != 5) lvl.AddUpdate(b, Block.Glass);
if (lvl.physics != 5) {
lvl.AddUpdate(b, Block.Glass, default(PhysicsArgs));
}
} else {
lvl.AddCheck(b);
} break;
@ -86,8 +97,9 @@ namespace MCGalaxy.Blocks.Physics {
//Adv physics kills flowers, wool, mushrooms, and wood type blocks in lava
if (!lvl.Props[block].LavaKills) break;
if (lvl.physics > 1 && !lvl.CheckSpongeLava(x, y, z))
lvl.AddUpdate(b, Block.Air);
if (lvl.physics > 1 && !lvl.CheckSpongeLava(x, y, z)) {
lvl.AddUpdate(b, Block.Air, default(PhysicsArgs));
}
break;
}
}

View File

@ -59,7 +59,7 @@ namespace MCGalaxy.Blocks.Physics {
} while (true);
if (movedDown) {
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
if (lvl.physics > 1)
lvl.AddUpdate(index, block);
else
@ -76,13 +76,13 @@ namespace MCGalaxy.Blocks.Physics {
int index;
if (lvl.GetBlock(x, (ushort)(y - 1), z, out index) == Block.Air) {
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(index, Block.FloatWood);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
lvl.AddUpdate(index, Block.FloatWood, default(PhysicsArgs));
} else {
BlockID above = lvl.GetBlock(x, (ushort)(y + 1), z, out index);
if (above == Block.StillWater || Block.Convert(above) == Block.Water) {
lvl.AddUpdate(C.b, lvl.blocks[index]);
lvl.AddUpdate(index, Block.FloatWood);
lvl.AddUpdate(index, Block.FloatWood, default(PhysicsArgs));
}
}
C.data.Data = PhysicsArgs.RemoveFromChecks;
@ -168,7 +168,7 @@ namespace MCGalaxy.Blocks.Physics {
if (block == Block.Invalid) continue;
if (Block.Convert(block) == target || Block.Convert(block) == alt) {
lvl.AddUpdate(index, Block.Air);
lvl.AddUpdate(index, Block.Air, default(PhysicsArgs));
}
}
C.data.Data = PhysicsArgs.RemoveFromChecks;
@ -184,7 +184,7 @@ namespace MCGalaxy.Blocks.Physics {
for (int zz = -3; zz <= +3; ++zz)
for (int xx = -3; xx <= +3; ++xx)
{
if (Math.Abs(xx) == 3 || Math.Abs(yy) == 3 || Math.Abs(zz) == 3) { // Calc only edge
if (Math.Abs(xx) == 3 || Math.Abs(yy) == 3 || Math.Abs(zz) == 3) { // Calc only edge
int index;
BlockID block = lvl.GetBlock((ushort)(x + xx), (ushort)(y + yy), (ushort)(z + zz), out index);
if (block == Block.Invalid) continue;

View File

@ -42,14 +42,14 @@ namespace MCGalaxy.Blocks.Physics {
bool unblocked = !lvl.listUpdateExists.Get(x, y, z) && (headIndex < 0 || !lvl.listUpdateExists.Get(x - cx, y - cy, z - cz));
if (unblocked && (rocketHead == Block.Air || rocketHead == Block.RocketStart)) {
lvl.AddUpdate(headIndex, Block.RocketHead);
lvl.AddUpdate(C.b, Block.LavaFire);
lvl.AddUpdate(headIndex, Block.RocketHead, default(PhysicsArgs));
lvl.AddUpdate(C.b, Block.LavaFire, default(PhysicsArgs));
} else if (rocketHead == Block.LavaFire) {
} else {
if (lvl.physics > 2)
lvl.MakeExplosion(x, y, z, 2);
else
lvl.AddUpdate(C.b, Block.LavaFire);
lvl.AddUpdate(C.b, Block.LavaFire, default(PhysicsArgs));
}
}
}

View File

@ -120,7 +120,7 @@ namespace MCGalaxy.Blocks.Physics {
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
} else { //was placed near sponge
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
if (!C.data.HasWait) {
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
@ -141,7 +141,7 @@ namespace MCGalaxy.Blocks.Physics {
LiquidPhysics.PhysWater(lvl, x, y, (ushort)(z - 1), block);
LiquidPhysics.PhysWater(lvl, x, (ushort)(y - 1), z, block);
} else { //was placed near sponge
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
}
if (!C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
}
@ -232,7 +232,7 @@ namespace MCGalaxy.Blocks.Physics {
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
} else { //was placed near sponge
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
if (!checkWait || !C.data.HasWait) {
C.data.Data = PhysicsArgs.RemoveFromChecks;
}
@ -251,7 +251,7 @@ namespace MCGalaxy.Blocks.Physics {
LiquidPhysics.PhysLava(lvl, x, y, (ushort)(z - 1), block);
LiquidPhysics.PhysLava(lvl, x, (ushort)(y - 1), z, block);
} else { //was placed near sponge
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
}
if (!checkWait || !C.data.HasWait) {

View File

@ -27,7 +27,7 @@ namespace MCGalaxy.Blocks.Physics {
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);
int dirsVisited = 0;
Player closest = AIPhysics.ClosestPlayer(lvl, x, y, z);
Player closest = HunterPhysics.ClosestPlayer(lvl, x, y, z);
if (closest != null && rand.Next(1, 20) < 19) {
switch (rand.Next(1, 10)) {

View File

@ -35,7 +35,7 @@ namespace MCGalaxy.Blocks.Physics {
public static void DoTntExplosion(Level lvl, ref Check C) {
Random rand = lvl.physRandom;
if (rand.Next(1, 11) <= 7)
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
}
public static void DoLargeTnt(Level lvl, ref Check C, int power) {
@ -125,8 +125,9 @@ namespace MCGalaxy.Blocks.Physics {
int index;
BlockID block = lvl.GetBlock(x, y, z, out index);
if (index >= 0 && !lvl.Props[block].OPBlock)
lvl.AddUpdate(index, Block.TNT_Explosion, true);
if (index >= 0 && !lvl.Props[block].OPBlock) {
lvl.AddUpdate(index, Block.TNT_Explosion, default(PhysicsArgs), true);
}
Explode(lvl, x, y, z, size + 1, rand, -1, game);
Explode(lvl, x, y, z, size + 2, rand, 7, game);
@ -152,9 +153,9 @@ namespace MCGalaxy.Blocks.Physics {
int mode = rand.Next(1, 11);
if (mode <= 4) {
lvl.AddUpdate(index, Block.TNT_Explosion);
lvl.AddUpdate(index, Block.TNT_Explosion, default(PhysicsArgs));
} else if (mode <= 8) {
lvl.AddUpdate(index, Block.Air);
lvl.AddUpdate(index, Block.Air, default(PhysicsArgs));
} else {
PhysicsArgs args = default(PhysicsArgs);
args.Type1 = PhysicsArgs.Drop; args.Value1 = 50;
@ -162,7 +163,7 @@ namespace MCGalaxy.Blocks.Physics {
lvl.AddCheck(index, false, args);
}
} else if (block == Block.TNT) {
lvl.AddUpdate(index, Block.TNT_Small);
lvl.AddUpdate(index, Block.TNT_Small, default(PhysicsArgs));
} else if (block == Block.TNT_Small || block == Block.TNT_Big || block == Block.TNT_Nuke) {
lvl.AddCheck(index);
}

View File

@ -41,8 +41,8 @@ namespace MCGalaxy.Blocks.Physics {
bool isRails = lvl.Props[below].IsRails;
if (isRails && (block == Block.Air || block == Block.Water) && !lvl.listUpdateExists.Get(x + dx, y + dy, z + dz)) {
lvl.AddUpdate(index, Block.Train);
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(index, Block.Train, default(PhysicsArgs));
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
BlockID newBlock = below == Block.Op_Air ? Block.Glass : Block.Obsidian;
int belowIndex;

View File

@ -35,7 +35,7 @@ namespace MCGalaxy.Blocks.Physics {
return;
}
bool checkTime = true;
Player closest = AIPhysics.ClosestPlayer(lvl, x, y, z);
Player closest = HunterPhysics.ClosestPlayer(lvl, x, y, z);
if (closest != null && rand.Next(1, 20) < 18) {
ushort xx, zz;
@ -98,8 +98,8 @@ namespace MCGalaxy.Blocks.Physics {
if (dirsVisited >= 4) return;
goto case 1;
}
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(lvl.IntOffset(C.b, 0, 1, 0), Block.Air);
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
lvl.AddUpdate(lvl.IntOffset(C.b, 0, 1, 0), Block.Air, default(PhysicsArgs));
}
public static void DoHead(Level lvl, ref Check C) {
@ -124,9 +124,9 @@ namespace MCGalaxy.Blocks.Physics {
}
if (lvl.AddUpdate(index, lvl.blocks[C.b])) {
lvl.AddUpdate(lvl.IntOffset(index, 0, 1, 0), Block.ZombieHead);
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(lvl.IntOffset(C.b, 0, 1, 0), Block.Air);
lvl.AddUpdate(lvl.IntOffset(index, 0, 1, 0), Block.ZombieHead, default(PhysicsArgs));
lvl.AddUpdate(C.b, Block.Air, default(PhysicsArgs));
lvl.AddUpdate(lvl.IntOffset(C.b, 0, 1, 0), Block.Air, default(PhysicsArgs));
return true;
}
return false;

View File

@ -210,7 +210,8 @@ namespace MCGalaxy {
if (x >= Width || y >= Height || z >= Length) return;
if (!listCheckExists.Get(x, y, z)) {
ListCheck.Add(new Check(index, data)); //Adds block to list to be updated
Check check; check.b = index; check.data = data;
ListCheck.Add(check); // Adds block to list to be updated
listCheckExists.Set(x, y, z, true);
} else if (overRide) {
Check[] items = ListCheck.Items;
@ -260,7 +261,10 @@ namespace MCGalaxy {
} else {
return false;
}
ListUpdate.Add(new Update(index, (byte)block, data));
data.Data = (byte)block;
Update update; update.b = index; update.data = data;
ListUpdate.Add(update);
if (!physThreadStarted && physics > 0)
StartPhysics();
@ -383,24 +387,20 @@ namespace MCGalaxy {
}
}
public struct PhysInfo {
public ushort X, Y, Z;
public BlockID Block;
public int Index;
public PhysicsArgs Data;
}
public struct Check {
public int b;
public PhysicsArgs data;
public Check(int b, PhysicsArgs data) {
this.b = b;
this.data = data;
}
}
public struct Update {
public int b;
public PhysicsArgs data;
public Update(int b, byte type, PhysicsArgs data) {
this.b = b;
this.data = data;
this.data.Data = type;
}
}
}

View File

@ -552,7 +552,6 @@
<Compile Include="Levels\LevelInfo.cs" />
<Compile Include="Levels\LevelOptions.cs" />
<Compile Include="Blocks\Physics\ActivateablePhysics.cs" />
<Compile Include="Blocks\Physics\AIPhysics.cs" />
<Compile Include="Blocks\Physics\AirPhysics.cs" />
<Compile Include="Blocks\Physics\BirdPhysics.cs" />
<Compile Include="Blocks\Physics\C4Physics.cs" />