Working simple scheduled ticking, Player ticks

This commit is contained in:
Christian 2012-06-28 23:37:30 -04:00
parent d3b48f0c21
commit 731dbf5175
9 changed files with 211 additions and 74 deletions

View File

@ -85,6 +85,8 @@ public class FMLCommonHandler
private PriorityQueue<TickQueueElement> tickHandlers = new PriorityQueue<TickQueueElement>();
private List<IScheduledTickHandler> scheduledTicks = new ArrayList<IScheduledTickHandler>();
private Set<IWorldGenerator> worldGenerators = new HashSet<IWorldGenerator>();
/**
* We register our delegate here
@ -97,16 +99,17 @@ public class FMLCommonHandler
public TickQueueElement(IScheduledTickHandler ticker)
{
this.ticker = ticker;
update();
}
@Override
public int compareTo(TickQueueElement o)
{
return (int)(o.next - next);
return (int)(next - o.next);
}
public void update()
{
next = tickCounter + ticker.nextTickSpacing();
next = tickCounter + Math.max(ticker.nextTickSpacing(),1);
}
private long next;
@ -114,7 +117,7 @@ public class FMLCommonHandler
public boolean scheduledNow()
{
return tickCounter == next;
return tickCounter >= next;
}
}
@ -126,16 +129,33 @@ public class FMLCommonHandler
getFMLLogger().info("Completed early MinecraftForge initialization");
}
public void tickStart(EnumSet<TickType> ticks, Object ... data)
public void rescheduleTicks()
{
sidedDelegate.profileStart("modTickStart$"+ticks);
for (int i = 0; i < tickHandlers.size(); i++)
sidedDelegate.profileStart("modTickScheduling");
TickQueueElement.tickCounter++;
scheduledTicks.clear();
while (true)
{
if (!tickHandlers.peek().scheduledNow())
if (tickHandlers.size()==0 || !tickHandlers.peek().scheduledNow())
{
break;
}
IScheduledTickHandler ticker = tickHandlers.peek().ticker;
TickQueueElement tickQueueElement = tickHandlers.poll();
tickQueueElement.update();
tickHandlers.offer(tickQueueElement);
scheduledTicks.add(tickQueueElement.ticker);
}
sidedDelegate.profileEnd();
}
public void tickStart(EnumSet<TickType> ticks, Object ... data)
{
if (scheduledTicks.size()==0)
{
return;
}
sidedDelegate.profileStart("modTickStart$"+ticks);
for (IScheduledTickHandler ticker : scheduledTicks)
{
EnumSet<TickType> ticksToRun = EnumSet.copyOf(ticker.ticks());
ticksToRun.removeAll(EnumSet.complementOf(ticks));
if (!ticksToRun.isEmpty())
@ -150,15 +170,13 @@ public class FMLCommonHandler
public void tickEnd(EnumSet<TickType> ticks, Object ... data)
{
sidedDelegate.profileStart("modTickEnd$"+ticks);
for (int i = 0; i < tickHandlers.size(); i++)
if (scheduledTicks.size()==0)
{
return;
}
sidedDelegate.profileStart("modTickEnd$"+ticks);
for (IScheduledTickHandler ticker : scheduledTicks)
{
if (!tickHandlers.peek().scheduledNow())
{
break;
}
TickQueueElement tickQueueElement = tickHandlers.poll();
IScheduledTickHandler ticker = tickQueueElement.ticker;
EnumSet<TickType> ticksToRun = EnumSet.copyOf(ticker.ticks());
ticksToRun.removeAll(EnumSet.complementOf(ticks));
if (!ticksToRun.isEmpty())
@ -167,8 +185,6 @@ public class FMLCommonHandler
ticker.tickEnd(ticksToRun, data);
sidedDelegate.profileEnd();
}
tickQueueElement.update();
tickHandlers.offer(tickQueueElement);
}
sidedDelegate.profileEnd();
}

View File

@ -65,7 +65,13 @@ public enum TickType {
* arg 0 : the player
* arg 1 : the world the player is in
*/
PLAYER;
PLAYER,
/**
* This is a special internal tick type that is
* not sent to mods. It resets the scheduler for
* the next tick pass.
*/
RESETMARKER;
/**
* Partner ticks that are also cancelled by returning false from onTickInGame

View File

@ -12,6 +12,13 @@
<stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_DESTINATION_PROJECT" value="ProfileProject"/>
<booleanAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILE_TO_FILE" value="false"/>
<stringAttribute key="org.eclipse.hyades.trace.ui.ATTR_PROFILING_SET" value="tptp-dummy-profiling-set-FML-Client"/>
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6&quot; javaProject=&quot;FML-Client&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#10;&lt;memento exportedEntriesOnly=&quot;false&quot; project=&quot;FML-Client&quot;/&gt;&#10;&lt;/runtimeClasspathEntry&gt;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry path=&quot;3&quot; projectName=&quot;simpletestmod&quot; type=&quot;1&quot;/&gt;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;runtimeClasspathEntry path=&quot;3&quot; projectName=&quot;FML-Client&quot; type=&quot;1&quot;/&gt;&#10;"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="Start"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="FML-Client"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xincgc -Xmx1024M -Xms1024M"/>

View File

@ -1,4 +1,3 @@
#Thu Jun 02 15:56:40 CEST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6

View File

@ -3,13 +3,13 @@ package net.minecraft.src;
import java.util.EnumSet;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.IScheduledTickHandler;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import net.minecraft.client.Minecraft;
public class mod_testMod extends BaseMod implements ITickHandler {
public class mod_testMod extends BaseMod {
private long ts;
private long tsg;
@Override
public String getVersion() {
return "test";
@ -17,23 +17,30 @@ public class mod_testMod extends BaseMod implements ITickHandler {
@Override
public void load() {
ModLoader.setInGameHook(this, true, true);
ModLoader.setInGUIHook(this, true, false);
FMLCommonHandler.instance().registerTickHandler(this);
ts=System.currentTimeMillis();
tsg=ts;
ModLoader.setInGameHook(this, true, false);
// ModLoader.setInGUIHook(this, true, false);
// FMLCommonHandler.instance().registerTickHandler(this);
TickTester t1 = new TickTester();
t1.interval=1;
TickTester t2 = new TickTester();
t2.interval=2;
TickTester t3 = new TickTester();
t3.interval=3;
FMLCommonHandler.instance().registerScheduledTickHandler(t1);
FMLCommonHandler.instance().registerScheduledTickHandler(t2);
FMLCommonHandler.instance().registerScheduledTickHandler(t3);
}
@Override
public boolean onTickInGame(float time, Minecraft minecraftInstance)
{
long now = System.currentTimeMillis();
long del=now-ts;
ts=now;
System.out.printf("%d %d %d %d MLTICK\n",del, ts, tsg, now);
System.out.printf("%d %d %d MLTICK\n",del, ts, now);
return true;
}
@Override
public boolean onTickInGUI(float tick, Minecraft game, GuiScreen gui)
{
@ -41,35 +48,46 @@ public class mod_testMod extends BaseMod implements ITickHandler {
return true;
}
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
public class TickTester implements IScheduledTickHandler
{
}
public int interval;
public long tsg = System.currentTimeMillis();
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
long now = System.currentTimeMillis();
long del=now-tsg;
System.out.printf("Begin GAMETICK [%d] %d\n",interval, del);
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
long now = System.currentTimeMillis();
long del=now-tsg;
tsg=now;
System.out.printf("%d %d %d %d GAMETICK\n",del, ts, tsg, now);
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
long now = System.currentTimeMillis();
long del=now-tsg;
tsg=now;
System.out.printf("End GAMETICK [%d] %d\n",interval, del);
}
@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.GAME);
}
@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.GAME);
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ITickHandler#getLabel()
*/
@Override
public String getLabel()
{
// TODO Auto-generated method stub
return "TickTester";
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ITickHandler#getLabel()
*/
@Override
public String getLabel()
{
return "TickTester";
}
@Override
public int nextTickSpacing()
{
return interval;
}
}
}

View File

@ -1,15 +1,25 @@
--- ../src-base/minecraft/net/minecraft/client/Minecraft.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src-work/minecraft/net/minecraft/client/Minecraft.java 0000-00-00 00:00:00.000000000 -0000
@@ -117,6 +117,8 @@
@@ -9,6 +9,7 @@
import java.awt.Graphics;
import java.io.File;
import java.text.DecimalFormat;
+import java.util.EnumSet;
import java.util.List;
import net.minecraft.src.AchievementList;
import net.minecraft.src.AnvilSaveConverter;
@@ -117,6 +118,10 @@
import org.lwjgl.opengl.PixelFormat;
import org.lwjgl.util.glu.GLU;
+import cpw.mods.fml.client.FMLClientHandler;
+import cpw.mods.fml.common.FMLCommonHandler;
+import cpw.mods.fml.common.TickType;
+
public abstract class Minecraft implements Runnable
{
public static byte[] field_28006_b = new byte[10485760];
@@ -288,6 +290,7 @@
@@ -288,6 +293,7 @@
this.field_6315_n = new RenderEngine(this.field_6298_C, this.field_6304_y);
this.func_6257_q();
this.field_6314_o = new FontRenderer(this.field_6304_y, "/font/default.png", this.field_6315_n, false);
@ -17,7 +27,7 @@
this.field_40007_r = new FontRenderer(this.field_6304_y, "/font/alternate.png", this.field_6315_n, false);
if (this.field_6304_y.field_44018_Q != null)
@@ -330,6 +333,9 @@
@@ -330,6 +336,9 @@
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
@ -27,7 +37,7 @@
this.func_6250_c("Startup");
this.field_6286_O = new OpenGlCapsChecker();
this.field_6301_A.func_340_a(this.field_6304_y);
@@ -744,9 +750,11 @@
@@ -744,9 +753,11 @@
this.field_6327_b.func_6467_a(this.field_9237_P.field_1378_c);
}
@ -39,7 +49,15 @@
}
GL11.glFlush();
@@ -1340,6 +1348,7 @@
@@ -1330,6 +1341,7 @@
public void func_6246_i()
{
+ FMLCommonHandler.instance().rescheduleTicks();
if (this.field_35001_ab > 0)
{
--this.field_35001_ab;
@@ -1340,6 +1352,7 @@
this.func_28001_B();
}
@ -47,7 +65,7 @@
Profiler.func_40663_a("stats");
this.field_25001_G.func_27178_d();
Profiler.func_40661_c("gui");
@@ -1730,6 +1739,7 @@
@@ -1730,6 +1743,7 @@
}
Profiler.func_40662_b();
@ -55,7 +73,7 @@
this.field_6287_N = System.currentTimeMillis();
}
@@ -1985,6 +1995,7 @@
@@ -1985,6 +1999,7 @@
System.gc();
this.field_6287_N = 0L;
@ -63,14 +81,13 @@
}
private void func_22002_b(String p_22002_1_, String p_22002_2_)
@@ -2250,7 +2261,11 @@
@@ -2250,7 +2265,11 @@
{
var2 = p_main_0_[1];
}
-
+ FMLClientHandler.instance().preGameLoad(var1, var2);
+ }
+
+ public static void fmlReentry(String var1, String var2)
+ {
func_6269_a(var1, var2);

View File

@ -0,0 +1,31 @@
--- ../src-base/minecraft/net/minecraft/src/EntityPlayer.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src-work/minecraft/net/minecraft/src/EntityPlayer.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,8 +1,12 @@
package net.minecraft.src;
+import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
+import cpw.mods.fml.common.FMLCommonHandler;
+import cpw.mods.fml.common.TickType;
+
public abstract class EntityPlayer extends EntityLiving
{
public InventoryPlayer field_778_b = new InventoryPlayer(this);
@@ -122,6 +126,7 @@
public void func_370_e_()
{
+ FMLCommonHandler.instance().tickStart(EnumSet.of(TickType.PLAYER), this, this.field_615_ag);
if (this.field_34907_d != null)
{
ItemStack var1 = this.field_778_b.func_494_a();
@@ -253,6 +258,7 @@
{
this.field_35217_av.func_35768_a(this);
}
+ FMLCommonHandler.instance().tickEnd(EnumSet.of(TickType.PLAYER), this, this.field_615_ag);
}
protected void func_35201_a(ItemStack p_35201_1_, int p_35201_2_)

View File

@ -1,16 +1,24 @@
--- ../src-base/minecraft_server/net/minecraft/server/MinecraftServer.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src-work/minecraft_server/net/minecraft/server/MinecraftServer.java 0000-00-00 00:00:00.000000000 -0000
@@ -13,6 +13,9 @@
@@ -7,12 +7,17 @@
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
+
+import cpw.mods.fml.common.FMLCommonHandler;
+import cpw.mods.fml.common.TickType;
+import cpw.mods.fml.server.FMLServerHandler;
import net.minecraft.src.AnvilSaveConverter;
import net.minecraft.src.AnvilSaveHandler;
import net.minecraft.src.AxisAlignedBB;
@@ -100,6 +103,7 @@
@@ -100,6 +105,7 @@
var1.start();
ConsoleLogManager.func_641_a();
field_6038_a.info("Starting minecraft server version 1.2.5");
@ -18,7 +26,7 @@
if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L)
{
@@ -146,6 +150,7 @@
@@ -146,6 +152,7 @@
field_6038_a.warning("To change this, set \"online-mode\" to \"true\" in the server.settings file.");
}
@ -26,16 +34,20 @@
this.field_6033_f = new ServerConfigurationManager(this);
this.field_6028_k[0] = new EntityTracker(this, 0);
this.field_6028_k[1] = new EntityTracker(this, -1);
@@ -353,6 +358,8 @@
@@ -353,6 +360,8 @@
{
long var1 = System.currentTimeMillis();
+ FMLServerHandler.instance().onWorldLoadTick();
+
+
for (long var3 = 0L; this.field_6025_n; Thread.sleep(1L))
{
long var5 = System.currentTimeMillis();
@@ -447,6 +454,7 @@
@@ -444,9 +453,11 @@
private void func_6018_h()
{
+ FMLCommonHandler.instance().rescheduleTicks();
long var1 = System.nanoTime();
ArrayList var3 = new ArrayList();
Iterator var4 = field_6037_b.keySet().iterator();
@ -43,7 +55,7 @@
while (var4.hasNext())
{
@@ -487,7 +495,9 @@
@@ -487,7 +498,9 @@
this.field_6033_f.func_28169_a(new Packet4UpdateTime(var7.func_22080_k()), var7.field_4272_q.field_6165_g);
}
@ -53,7 +65,7 @@
while (true)
{
@@ -533,6 +543,7 @@
@@ -533,6 +546,7 @@
this.field_48076_G = Packet.field_48101_l;
this.field_48082_x[this.field_9014_h % 100] = Packet.field_48102_m - this.field_48077_H;
this.field_48077_H = Packet.field_48102_m;

View File

@ -0,0 +1,31 @@
--- ../src-base/minecraft_server/net/minecraft/src/EntityPlayer.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src-work/minecraft_server/net/minecraft/src/EntityPlayer.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,8 +1,12 @@
package net.minecraft.src;
+import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
+import cpw.mods.fml.common.FMLCommonHandler;
+import cpw.mods.fml.common.TickType;
+
public abstract class EntityPlayer extends EntityLiving
{
public InventoryPlayer field_416_aj = new InventoryPlayer(this);
@@ -104,6 +108,7 @@
public void func_106_b_()
{
+ FMLCommonHandler.instance().tickStart(EnumSet.of(TickType.PLAYER), this, this.field_9093_l);
if (this.field_34908_d != null)
{
ItemStack var1 = this.field_416_aj.func_213_b();
@@ -235,6 +240,7 @@
{
this.field_35217_m.func_35584_a(this);
}
+ FMLCommonHandler.instance().tickEnd(EnumSet.of(TickType.PLAYER), this, this.field_9093_l);
}
protected void func_35208_b(ItemStack p_35208_1_, int p_35208_2_)