Skip to content

Commit

Permalink
revert tick delta related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dicedpixels committed Oct 28, 2024
1 parent ab17051 commit 0f62e21
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion develop/rendering/basic-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ The `MatrixStack` class has the following methods:

You can also multiply the top matrix on the stack using quaternions, which we will cover in the next section.

Taking from our example above, we can make our diamond scale up and down by using the `MatrixStack` and the `tickDelta` - which is the "progress" between the last game tick and the next game tick.
Taking from our example above, we can make our diamond scale up and down by using the `MatrixStack` and the `tickDelta` - which is the time that has passed since the last frame.

::: warning
You must first push the matrix stack and then pop it after you're done with it. If you don't, you'll end up with a broken matrix stack, which will cause rendering issues.
Expand Down
10 changes: 5 additions & 5 deletions develop/rendering/hud.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ authors:

# Rendering in the Hud {#rendering-in-the-hud}

We already briefly touched on rendering things to the hud in the [Basic Rendering Concepts](./basic-concepts) page and [Using The Drawing Context](./draw-context), so on this page we'll stick to the `HudRenderCallback` event and the `tickCounter` parameter.
We already briefly touched on rendering things to the hud in the [Basic Rendering Concepts](./basic-concepts) page and [Using The Drawing Context](./draw-context), so on this page we'll stick to the `HudRenderCallback` event and the `deltaTick` parameter.

## HudRenderCallback {#hudrendercallback}

The `HudRenderCallback` event - provided by Fabric API - is called every frame, and is used to render things to the HUD.

To register to this event, you can simply call `HudRenderCallback.EVENT.register` and pass in a lambda that takes a `DrawContext` and a `RenderTickCounter` (tickCounter) as parameters.
To register to this event, you can simply call `HudRenderCallback.EVENT.register` and pass in a lambda that takes a `DrawContext` and a `float` (deltaTick) as parameters.

The draw context can be used to access the various rendering utilities provided by the game, and access the raw matrix stack.

You should check out the [Draw Context](./draw-context) page to learn more about the draw context.

### Tick Delta {#deltatick}
### DeltaTick {#deltatick}

Frames are rendered faster than the game ticks. Tick delta is a `float` from `0.0` to `1.0` that represents the "progress" between the last game tick and the next game tick. This can be used to make animations and other time-based effects.
The `deltaTick` refers to the time since the last frame, in seconds. This can be used to make animations and other time-based effects.

For example, let's say you want to lerp a color over time. You can use the `tickCounter` to get the tick delta, and store it over time to lerp the color:
For example, let's say you want to lerp a color over time. You can use the `deltaTickManager` to get the deltaTick, and store it over time to lerp the color:

@[code lang=java transcludeWith=:::1](@/reference/latest/src/client/java/com/example/docs/rendering/HudRenderingEntrypoint.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public class HudRenderingEntrypoint implements ClientModInitializer {
@Override
public void onInitializeClient() {
// :::1
HudRenderCallback.EVENT.register((context, tickCounter) -> {
HudRenderCallback.EVENT.register((context, tickDeltaManager) -> {
int color = 0xFFFF0000; // Red
int targetColor = 0xFF00FF00; // Green

// Total tick delta is stored in a field, so we can use it later.
totalTickDelta += tickCounter.getTickDelta(true);
totalTickDelta += tickDeltaManager.getTickDelta(true);

// "lerp" simply means "linear interpolation", which is a fancy way of saying "blend".
float lerpedAmount = MathHelper.abs(MathHelper.sin(totalTickDelta / 50F));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class RenderingConceptsEntrypoint implements ClientModInitializer {
public void onInitializeClient() {
// "A Practical Example: Rendering a Triangle Strip"
// :::1
HudRenderCallback.EVENT.register((drawContext, tickCounter) -> {
HudRenderCallback.EVENT.register((drawContext, tickDeltaManager) -> {
// :::1
if (true) {
return;
Expand All @@ -33,7 +33,7 @@ public void onInitializeClient() {
MatrixStack matrices = drawContext.getMatrices();

// Store the total tick delta in a field, so we can use it later.
totalTickDelta += tickCounter.getTickDelta(true);
totalTickDelta += tickDeltaManager.getTickDelta(true);

// Push a new matrix onto the stack.
matrices.push();
Expand Down

0 comments on commit 0f62e21

Please sign in to comment.