Made thread pause during main menu
This commit is contained in:
parent
a7c0e8c502
commit
1cef920e62
4 changed files with 59 additions and 41 deletions
|
@ -7,6 +7,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
import resonantinduction.core.ResonantInduction;
|
||||||
import resonantinduction.core.grid.Grid;
|
import resonantinduction.core.grid.Grid;
|
||||||
import resonantinduction.core.grid.TickingGrid;
|
import resonantinduction.core.grid.TickingGrid;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
|
@ -68,7 +69,8 @@ public class MechanicalNode extends EnergyNode
|
||||||
{
|
{
|
||||||
prevAngularVelocity = angularVelocity;
|
prevAngularVelocity = angularVelocity;
|
||||||
|
|
||||||
angle += angularVelocity * deltaTime;
|
if (!ResonantInduction.proxy.isPaused())
|
||||||
|
angle += angularVelocity * deltaTime;
|
||||||
|
|
||||||
if (angle % (Math.PI * 2) != angle)
|
if (angle % (Math.PI * 2) != angle)
|
||||||
{
|
{
|
||||||
|
@ -127,7 +129,7 @@ public class MechanicalNode extends EnergyNode
|
||||||
/**
|
/**
|
||||||
* Set all current rotations
|
* Set all current rotations
|
||||||
*/
|
*/
|
||||||
//adjacentMech.angle = Math.abs(angle) * (adjacentMech.angle >= 0 ? 1 : -1);
|
// adjacentMech.angle = Math.abs(angle) * (adjacentMech.angle >= 0 ? 1 : -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,6 @@ import calclavia.lib.prefab.ProxyBase;
|
||||||
*/
|
*/
|
||||||
public class CommonProxy extends ProxyBase
|
public class CommonProxy extends ProxyBase
|
||||||
{
|
{
|
||||||
@Override
|
|
||||||
public void postInit()
|
|
||||||
{
|
|
||||||
ThreadedGridTicker.INSTANCE.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPaused()
|
public boolean isPaused()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -11,6 +11,7 @@ import net.minecraftforge.fluids.BlockFluidFinite;
|
||||||
import org.modstats.ModstatInfo;
|
import org.modstats.ModstatInfo;
|
||||||
import org.modstats.Modstats;
|
import org.modstats.Modstats;
|
||||||
|
|
||||||
|
import resonantinduction.core.grid.ThreadedGridTicker;
|
||||||
import resonantinduction.core.handler.TextureHookHandler;
|
import resonantinduction.core.handler.TextureHookHandler;
|
||||||
import resonantinduction.core.prefab.part.PacketMultiPart;
|
import resonantinduction.core.prefab.part.PacketMultiPart;
|
||||||
import resonantinduction.core.resource.BlockDust;
|
import resonantinduction.core.resource.BlockDust;
|
||||||
|
@ -35,6 +36,8 @@ import cpw.mods.fml.common.SidedProxy;
|
||||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
|
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||||
|
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
|
||||||
import cpw.mods.fml.common.network.NetworkMod;
|
import cpw.mods.fml.common.network.NetworkMod;
|
||||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
@ -139,4 +142,18 @@ public class ResonantInduction
|
||||||
ResourceGenerator.generateOreResources();
|
ResourceGenerator.generateOreResources();
|
||||||
proxy.postInit();
|
proxy.postInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void serverStarting(FMLServerStartingEvent event)
|
||||||
|
{
|
||||||
|
if (!ThreadedGridTicker.INSTANCE.isAlive())
|
||||||
|
ThreadedGridTicker.INSTANCE.start();
|
||||||
|
ThreadedGridTicker.INSTANCE.pause = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onServerStopping(FMLServerStoppingEvent evt)
|
||||||
|
{
|
||||||
|
ThreadedGridTicker.INSTANCE.pause = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,9 @@ public class ThreadedGridTicker extends Thread
|
||||||
/** For queuing Forge events to be invoked the next tick. */
|
/** For queuing Forge events to be invoked the next tick. */
|
||||||
private final Queue<Event> queuedEvents = new ConcurrentLinkedQueue<Event>();
|
private final Queue<Event> queuedEvents = new ConcurrentLinkedQueue<Event>();
|
||||||
|
|
||||||
private ThreadedGridTicker()
|
public boolean pause = false;
|
||||||
|
|
||||||
|
public ThreadedGridTicker()
|
||||||
{
|
{
|
||||||
setName("Universal Electricity");
|
setName("Universal Electricity");
|
||||||
setPriority(MIN_PRIORITY);
|
setPriority(MIN_PRIORITY);
|
||||||
|
@ -56,49 +58,52 @@ public class ThreadedGridTicker extends Thread
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
long current = System.currentTimeMillis();
|
if (!pause)
|
||||||
long delta = current - last;
|
|
||||||
|
|
||||||
/** Tick all updaters. */
|
|
||||||
synchronized (updaters)
|
|
||||||
{
|
{
|
||||||
Set<IUpdate> removeUpdaters = Collections.newSetFromMap(new WeakHashMap<IUpdate, Boolean>());
|
long current = System.currentTimeMillis();
|
||||||
|
long delta = current - last;
|
||||||
|
|
||||||
Iterator<IUpdate> updaterIt = new HashSet<IUpdate>(updaters).iterator();
|
/** Tick all updaters. */
|
||||||
|
synchronized (updaters)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
while (updaterIt.hasNext())
|
Set<IUpdate> removeUpdaters = Collections.newSetFromMap(new WeakHashMap<IUpdate, Boolean>());
|
||||||
|
|
||||||
|
Iterator<IUpdate> updaterIt = new HashSet<IUpdate>(updaters).iterator();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
IUpdate updater = updaterIt.next();
|
while (updaterIt.hasNext())
|
||||||
|
|
||||||
if (updater.canUpdate())
|
|
||||||
{
|
{
|
||||||
updater.update();
|
IUpdate updater = updaterIt.next();
|
||||||
|
|
||||||
|
if (updater.canUpdate())
|
||||||
|
{
|
||||||
|
updater.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!updater.continueUpdate())
|
||||||
|
{
|
||||||
|
removeUpdaters.add(updater);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!updater.continueUpdate())
|
updaters.removeAll(removeUpdaters);
|
||||||
{
|
}
|
||||||
removeUpdaters.add(updater);
|
catch (Exception e)
|
||||||
}
|
{
|
||||||
|
System.out.println("Universal Electricity Threaded Ticker: Failed while tcking updater. This is a bug! Clearing all tickers for self repair.");
|
||||||
|
updaters.clear();
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
updaters.removeAll(removeUpdaters);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Universal Electricity Threaded Ticker: Failed while tcking updater. This is a bug! Clearing all tickers for self repair.");
|
|
||||||
updaters.clear();
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Perform all queued events */
|
/** Perform all queued events */
|
||||||
synchronized (queuedEvents)
|
synchronized (queuedEvents)
|
||||||
{
|
|
||||||
while (!queuedEvents.isEmpty())
|
|
||||||
{
|
{
|
||||||
MinecraftForge.EVENT_BUS.post(queuedEvents.poll());
|
while (!queuedEvents.isEmpty())
|
||||||
|
{
|
||||||
|
MinecraftForge.EVENT_BUS.post(queuedEvents.poll());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue