-
My code digs into the library's internals a bit to do two things:
// com: deserialized component data
for (cstor in Echoes._componentStorage) { // for some reason Echoes.componentStorage was null?
if (cstor.componentType == com.typename) {
((cast cstor) : ComponentStorage<Dynamic>).add(ent, com.data);
break;
}
}
// this method is less susceptible to floating point inaccuracies
var curTime = haxe.Timer.stamp();
var ticks = 0;
while (curTime - tickStartTime >= TICK_LEN) {
tickStartTime += TICK_LEN;
ticks++;
// processing is taking too long, bail out
if (ticks > 10) {
tickStartTime = curTime;
break;
}
@:privateAccess fixedRateSystemList.__update__(TICK_LEN);
}
partialFrame = (curTime - tickStartTime) / TICK_LEN;
@:privateAccess variableRateSystemList.__update__(dt); With that out of the way, it seems if I call Is there a way I can fix this? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 20 replies
-
I find HashLink can be weird about casting to/from primitive types. In my case, it would convert I'd like to get more information about the deserialization process. //Unrelated to the main issue, but I'd like to check if it's really null.
trace(Echoes.componentStorage?.length + ", " + Echoes.get_componentStorage()?.length + ", " + Echoes._componentStorage?.length);
for (cstor in Echoes._componentStorage) {
if (cstor.componentType == com.typename) {
((cast cstor) : ComponentStorage<Dynamic>).add(ent, com.data);
//For the main issue, let's examine the value being added.
if (cstor == Echoes.getComponentStorage(Mass)) {
trace(com.data);
trace(Type.typeof(com.data));
trace(cstor.get(entity));
trace((cstor.get(entity):Null<Mass>));
}
break;
}
} |
Beta Was this translation helpful? Give feedback.
-
I'm also curious about the "floating point inaccuracies." Do you happen to have an example where |
Beta Was this translation helpful? Give feedback.
-
These are my results from your test:
The third trace is interesting... I added the Mass component to the entity by typing About the floating point inaccuracies thing, I can't really give a concrete example but when using I learned that method from someone else when I was experiencing a worse stuttering problem in a Love2D project a while ago. They explained that it was due to floating point error accumulation and as a solution gave that method, and when I used it it removed the stuttering problem (iirc). It would make sense that repeated additions of the varying delta-time would probably be more prone to error accumulation. |
Beta Was this translation helpful? Give feedback.
-
Perhaps it's inferring integer because it's stored in JSON as Let's update the test slightly, to be sure. if (cstor == Echoes.getComponentStorage(Mass)) {
trace(com.data);
trace(Type.typeof(com.data));
trace(Echoes.getComponentStorage(Mass).get(ent));
} |
Beta Was this translation helpful? Give feedback.
-
I don't think I believe that floating point error can cause visible stuttering. There's very little difference between your code and mine, and I can't see how that small a difference could create visible frame drops. Are you sure you tried fixedRateSystemList.clock.setFixedTimeStep(TICK_LEN);
fixedRateSystemList.clock.maxTime = 10 * TICK_LEN; You can even calculate the same " |
Beta Was this translation helpful? Give feedback.
-
edit: nevermind, I didn't realize I was supposed to make a new Clock for the fixed-rate system list. the rendering system was using the same fixed timestep as a consequence. well, i knew it was supposed to be a separate clock but I don't recall the examples saying about about it so I kind of just assumed it would work I guess. I'm not sure if I should make this a separate discussion, as I feel like this is kind of a small question and also that this may be contributing to my "stuttering" problem. how do i calculate the blending factor correctly? fixedSystemList.clock.setFixedTickLength(TICK_LEN); // TICK_LEN changes for debug slow-mo mode
Echoes.clock.paused = paused;
Echoes.update();
// update graphics interpolators
// class Interpolator { var oldValue:Float; var newValue:Float; var alpha:Float; }
partialFrame = Echoes.clock.time / TICK_LEN;
for (interp in interpolators) {
interp.alpha = partialFrame;
} It doesn't seem to be interpolating correctly because it's choppy when TICK_LEN is lower than the refresh rate. However with the method I used it works as intended. It just occurred to me that the alpha value is delayed by one frame because it updates the graphics using the interpolated value in the RenderSystem, but interpolator alpha values are updated afterwards. But it changed nothing when I fixed it. |
Beta Was this translation helpful? Give feedback.
These are my results from your test:
The third trace is interesting... I added the Mass component to the entity by typing
entity.add((1.0 : Mass))
. If I instead typeentity.add((1.1 : Mass))
, the problem disappears and it prints TFloat instead of TInt, as it should. Also, I only have one entity kind that uses the Mass component. So it does look like it's caused by HashLink converting primitive types.About the floating point inaccuracies thing, I can't really give a concrete example but when using
Echoes.update
, sometimes the game stutters even though the …