mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-06-26 07:03:22 +00:00
Attempt to cut out a lot of synchronized calls
A lot of these don't actually have any effect as they'll only be called on the main thread or they are getters where the state is guaranteed to be consistent whenever it is accessed. Hopefully this'll reduce the chance of world updates being blocked by waiting for peripheral locks to be released.
This commit is contained in:
parent
efa57521c7
commit
c6bd88f3ad
|
@ -112,12 +112,12 @@ public void setDirection( EnumFacing dir )
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized int getAnim()
|
||||
public int getAnim()
|
||||
{
|
||||
return m_anim;
|
||||
}
|
||||
|
||||
public synchronized void setAnim( int anim )
|
||||
public void setAnim( int anim )
|
||||
{
|
||||
if( anim != m_anim )
|
||||
{
|
||||
|
@ -127,12 +127,12 @@ public synchronized void setAnim( int anim )
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update()
|
||||
public void update()
|
||||
{
|
||||
if( m_changed )
|
||||
{
|
||||
updateBlock();
|
||||
m_changed = false;
|
||||
updateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,12 +80,9 @@ public TileDiskDrive()
|
|||
public void destroy()
|
||||
{
|
||||
ejectContents( true );
|
||||
synchronized( this )
|
||||
if( m_recordPlaying )
|
||||
{
|
||||
if( m_recordPlaying )
|
||||
{
|
||||
stopRecord();
|
||||
}
|
||||
stopRecord();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,13 +167,10 @@ public void update()
|
|||
super.update();
|
||||
|
||||
// Ejection
|
||||
synchronized( this )
|
||||
if( m_ejectQueued )
|
||||
{
|
||||
if( m_ejectQueued )
|
||||
{
|
||||
ejectContents( false );
|
||||
m_ejectQueued = false;
|
||||
}
|
||||
ejectContents( false );
|
||||
m_ejectQueued = false;
|
||||
}
|
||||
|
||||
// Music
|
||||
|
@ -391,10 +385,7 @@ public boolean isUsableByPlayer( @Nonnull EntityPlayer player )
|
|||
@Override
|
||||
public void clear()
|
||||
{
|
||||
synchronized( this )
|
||||
{
|
||||
setInventorySlotContents( 0, ItemStack.EMPTY );
|
||||
}
|
||||
setInventorySlotContents( 0, ItemStack.EMPTY );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -425,18 +416,12 @@ public IPeripheral getPeripheral( EnumFacing side )
|
|||
@Nonnull
|
||||
public ItemStack getDiskStack()
|
||||
{
|
||||
synchronized( this )
|
||||
{
|
||||
return getStackInSlot( 0 );
|
||||
}
|
||||
return getStackInSlot( 0 );
|
||||
}
|
||||
|
||||
public void setDiskStack( @Nonnull ItemStack stack )
|
||||
{
|
||||
synchronized( this )
|
||||
{
|
||||
setInventorySlotContents( 0, stack );
|
||||
}
|
||||
setInventorySlotContents( 0, stack );
|
||||
}
|
||||
|
||||
public IMedia getDiskMedia()
|
||||
|
@ -569,7 +554,7 @@ private synchronized void unmountDisk( IComputerAccess computer )
|
|||
}
|
||||
}
|
||||
|
||||
private synchronized void updateAnim()
|
||||
private void updateAnim()
|
||||
{
|
||||
if( !m_diskStack.isEmpty() )
|
||||
{
|
||||
|
|
|
@ -75,7 +75,7 @@ public synchronized void destroy()
|
|||
m_open = false;
|
||||
}
|
||||
|
||||
public synchronized boolean pollChanged()
|
||||
public boolean pollChanged()
|
||||
{
|
||||
if( m_changed )
|
||||
{
|
||||
|
@ -85,9 +85,9 @@ public synchronized boolean pollChanged()
|
|||
return false;
|
||||
}
|
||||
|
||||
public synchronized boolean isActive()
|
||||
public boolean isActive()
|
||||
{
|
||||
return (m_computer != null) && m_open;
|
||||
return m_computer != null && m_open;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,7 +37,7 @@ protected TileModemBase()
|
|||
protected abstract ModemPeripheral createPeripheral();
|
||||
|
||||
@Override
|
||||
public synchronized void destroy()
|
||||
public void destroy()
|
||||
{
|
||||
if( m_modem != null )
|
||||
{
|
||||
|
|
|
@ -190,10 +190,7 @@ public boolean isEmpty()
|
|||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
synchronized( m_inventory )
|
||||
{
|
||||
return m_inventory.get( i );
|
||||
}
|
||||
return m_inventory.get( i );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
|
||||
import static dan200.computercraft.core.apis.ArgumentHelper.optReal;
|
||||
|
@ -28,13 +29,13 @@ public class SpeakerPeripheral implements IPeripheral {
|
|||
private TileSpeaker m_speaker;
|
||||
private long m_clock;
|
||||
private long m_lastPlayTime;
|
||||
private int m_notesThisTick;
|
||||
private final AtomicInteger m_notesThisTick;
|
||||
|
||||
public SpeakerPeripheral()
|
||||
{
|
||||
m_clock = 0;
|
||||
m_lastPlayTime = 0;
|
||||
m_notesThisTick = 0;
|
||||
m_notesThisTick = new AtomicInteger( );
|
||||
}
|
||||
|
||||
SpeakerPeripheral(TileSpeaker speaker)
|
||||
|
@ -43,10 +44,10 @@ public SpeakerPeripheral()
|
|||
m_speaker = speaker;
|
||||
}
|
||||
|
||||
public synchronized void update()
|
||||
public void update()
|
||||
{
|
||||
m_clock++;
|
||||
m_notesThisTick = 0;
|
||||
m_notesThisTick.set( 0 );
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
|
@ -59,9 +60,9 @@ public BlockPos getPos()
|
|||
return m_speaker.getPos();
|
||||
}
|
||||
|
||||
public synchronized boolean madeSound(long ticks)
|
||||
public boolean madeSound(long ticks)
|
||||
{
|
||||
return (m_clock - m_lastPlayTime <= ticks) ;
|
||||
return m_clock - m_lastPlayTime <= ticks;
|
||||
}
|
||||
|
||||
/* IPeripheral implementation */
|
||||
|
@ -146,7 +147,7 @@ private synchronized Object[] playNote( Object[] arguments, ILuaContext context
|
|||
|
||||
if( returnValue[0] instanceof Boolean && (Boolean) returnValue[0] )
|
||||
{
|
||||
m_notesThisTick++;
|
||||
m_notesThisTick.incrementAndGet();
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
|
@ -161,7 +162,7 @@ private synchronized Object[] playSound( Object[] arguments, ILuaContext context
|
|||
|
||||
ResourceLocation resourceName = new ResourceLocation( name );
|
||||
|
||||
if( m_clock - m_lastPlayTime >= TileSpeaker.MIN_TICKS_BETWEEN_SOUNDS || ( ( m_clock - m_lastPlayTime == 0 ) && ( m_notesThisTick < ComputerCraft.maxNotesPerTick ) && isNote ) )
|
||||
if( m_clock - m_lastPlayTime >= TileSpeaker.MIN_TICKS_BETWEEN_SOUNDS || (isNote && m_clock - m_lastPlayTime == 0 && m_notesThisTick.get() < ComputerCraft.maxNotesPerTick) )
|
||||
{
|
||||
if( SoundEvent.REGISTRY.containsKey(resourceName) )
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@ public TileSpeaker()
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized void update()
|
||||
public void update()
|
||||
{
|
||||
m_peripheral.update();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user