mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Inline SetTile for better perf
This commit is contained in:
parent
b3c34edd20
commit
eeccdf30dc
@ -191,8 +191,20 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lvl.SetTile(b.X, b.Y, b.Z, b.Block, p, b.ExtBlock, op.Flags);
|
|
||||||
p.IncrementBlockStats(b.Block, true);
|
// Set the block (inlined)
|
||||||
|
lvl.blocks[index] = b.Block;
|
||||||
|
lvl.changed = true;
|
||||||
|
if (old == Block.custom_block && b.Block != Block.custom_block) {
|
||||||
|
lvl.RevertExtTileNoCheck(b.X, b.Y, b.Z);
|
||||||
|
}
|
||||||
|
if (b.Block == Block.custom_block) {
|
||||||
|
lvl.SetExtTileNoCheck(b.X, b.Y, b.Z, b.ExtBlock);
|
||||||
|
}
|
||||||
|
if (p != null) {
|
||||||
|
lvl.BlockDB.Cache.Add(p, b.X, b.Y, b.Z, op.Flags, old, oldExt, b.Block, b.ExtBlock);
|
||||||
|
}
|
||||||
|
p.loginBlocks++; p.overallBlocks++; p.TotalDrawn++; // increment block stats inline
|
||||||
|
|
||||||
|
|
||||||
// Potentially buffer the block change
|
// Potentially buffer the block change
|
||||||
@ -201,9 +213,18 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
lock (lvl.queueLock)
|
lock (lvl.queueLock)
|
||||||
lvl.blockqueue.Clear();
|
lvl.blockqueue.Clear();
|
||||||
} else if (op.TotalModified < Server.DrawReloadLimit) {
|
} else if (op.TotalModified < Server.DrawReloadLimit) {
|
||||||
same = old == Block.custom_block
|
same = old == Block.custom_block
|
||||||
? oldExt == b.ExtBlock : Block.Convert(old) == Block.Convert(b.Block);
|
? oldExt == b.ExtBlock : Block.Convert(old) == Block.Convert(b.Block);
|
||||||
if (!same) BlockQueue.Addblock(p, index, b.Block, b.ExtBlock);
|
if (!same) BlockQueue.Addblock(p, index, b.Block, b.ExtBlock);
|
||||||
|
|
||||||
|
if (lvl.physics > 0) {
|
||||||
|
if (old == Block.sponge && b.Block != Block.sponge)
|
||||||
|
OtherPhysics.DoSpongeRemoved(lvl, index, false);
|
||||||
|
if (old == Block.lava_sponge && b.Block != Block.lava_sponge)
|
||||||
|
OtherPhysics.DoSpongeRemoved(lvl, index, true);
|
||||||
|
|
||||||
|
if (lvl.ActivatesPhysics(b.Block, b.ExtBlock)) lvl.AddCheck(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
op.TotalModified++;
|
op.TotalModified++;
|
||||||
|
|
||||||
@ -211,18 +232,18 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
// Attempt to prevent the BlockDB from growing too large (> 1,000,000 entries)
|
// Attempt to prevent the BlockDB from growing too large (> 1,000,000 entries)
|
||||||
int count = lvl.BlockDB.Cache.Count;
|
int count = lvl.BlockDB.Cache.Count;
|
||||||
if (count == 0 || (count % 1000000) != 0) return;
|
if (count == 0 || (count % 1000000) != 0) return;
|
||||||
Server.s.Log("okay.. we should probably save here"); // TODO: remove this debugging stuff
|
Server.s.Log("rightio saving BlockDB!"); // TODO: remove this debugging stuff
|
||||||
|
|
||||||
// if drawop has a read lock on BlockDB (e.g. undo/redo), we must release it here
|
// if drawop has a read lock on BlockDB (e.g. undo/redo), we must release it here
|
||||||
bool hasReadLock = false;
|
bool hasReadLock = false;
|
||||||
if (op.BlockDBReadLock != null) {
|
if (op.BlockDBReadLock != null) {
|
||||||
op.BlockDBReadLock.Dispose();
|
op.BlockDBReadLock.Dispose();
|
||||||
hasReadLock = true;
|
hasReadLock = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
using (IDisposable wLock = lvl.BlockDB.Locker.AccquireWrite(100)) {
|
using (IDisposable wLock = lvl.BlockDB.Locker.AccquireWrite(100)) {
|
||||||
Server.s.Log("GOT IT? " + (wLock == null ? "NO" : "YES"));
|
Server.s.Log("GOT WRITE LOCK? " + (wLock == null ? "NO" : "YES"));
|
||||||
if (wLock != null) lvl.BlockDB.WriteEntries();
|
if (wLock != null) lvl.BlockDB.WriteEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasReadLock) return;
|
if (!hasReadLock) return;
|
||||||
|
@ -276,9 +276,14 @@ namespace MCGalaxy {
|
|||||||
if (old == Block.lava_sponge && physics > 0 && block != Block.lava_sponge)
|
if (old == Block.lava_sponge && physics > 0 && block != Block.lava_sponge)
|
||||||
OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z), true);
|
OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z), true);
|
||||||
|
|
||||||
|
p.loginBlocks++;
|
||||||
|
p.overallBlocks++;
|
||||||
|
|
||||||
|
if (drawn) p.TotalDrawn++;
|
||||||
|
else if (block == 0) p.TotalDeleted++;
|
||||||
|
else p.TotalPlaced++;
|
||||||
|
|
||||||
errorLocation = "Setting tile";
|
errorLocation = "Setting tile";
|
||||||
p.IncrementBlockStats(block, drawn);
|
|
||||||
|
|
||||||
SetTile(x, y, z, block);
|
SetTile(x, y, z, block);
|
||||||
if (old == Block.custom_block && block != Block.custom_block)
|
if (old == Block.custom_block && block != Block.custom_block)
|
||||||
RevertExtTileNoCheck(x, y, z);
|
RevertExtTileNoCheck(x, y, z);
|
||||||
|
@ -29,15 +29,6 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public sealed partial class Player : IDisposable {
|
public sealed partial class Player : IDisposable {
|
||||||
|
|
||||||
public void IncrementBlockStats(byte block, bool drawn) {
|
|
||||||
loginBlocks++;
|
|
||||||
overallBlocks++;
|
|
||||||
|
|
||||||
if (drawn) TotalDrawn++;
|
|
||||||
else if (block == 0) TotalDeleted++;
|
|
||||||
else TotalPlaced++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte GetActualHeldBlock(out byte extBlock) {
|
public byte GetActualHeldBlock(out byte extBlock) {
|
||||||
byte block = RawHeldBlock;
|
byte block = RawHeldBlock;
|
||||||
extBlock = 0;
|
extBlock = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user