Skip to content

Conversation

@Nu11ified
Copy link

@Nu11ified Nu11ified commented Sep 20, 2025

Video:

20.09.2025_01.17.49_REC.mp4

This is a completely unneeded cosmetic change and I understand if it's too heavy for the purposes of this project. Also I saw in another PR that you wanted issues created before PRs that is completely my bad I missed that in the readme.

Summary

  1. Encode prior horizontal deltas inside MobData and cache tiny per-mob scratch buffers so we can interpolate movement without adding to the struct size.
  2. Rework the tick loop to capture deltas, preserve panic headings, retry blocked moves, and queue interpolation phases only when something actually changes.
  3. Add a lightweight interpolation scheduler (default 6 slices) that smooths horizontal motion, emits a discrete “hop” profile for vertical climbs/drops, and clears deltas/ yaw once the move settles to prevent snap-backs.
  4. Expose helpers so player joins spawn in-flight mobs at the correct interpolated position/yaw, and keep head rotation deterministic.

Goal: mimic Minecraft’s block-step feel with minimal RAM/CPU so an ESP32-hosted server stays responsive.

Memory impact

  1. MobData remains unchanged.
  2. New state: mob_interp_dy[MAX_MOBS] and mob_interp_yaw[MAX_MOBS] (1 byte each). With the default MAX_MOBS = 16, total additional RAM = 32 bytes.

Bandwidth impact

  1. Each predicted slice still uses the standard Teleport Entity + Set Head Rotation packets (~78 B combined).
  2. With MOB_INTERP_STEPS = 6, one move now emits up to 6 slices (~468 B) instead of 1 (~78 B). Idle mobs remain silent.

Config / tuning

  1. MOB_INTERP_STEPS (in src/procedures.c) controls interpolation granularity. Lower values reduce bandwidth at the cost of choppier motion; 4–6 works well.
  2. The vertical profile currently hops on the final two slices. Tweak mobVerticalProfile if you want a taller or earlier jump.
  3. MOB_COORD_OFFSET/MASK constrain mob positions to +/-8192 blocks per axis, still well beyond what the ESP32 can serve.

Adds packed coordinate encoding for mob positions and movement deltas, and introduces a multi-step interpolation system for mob movement. Mob positions are now updated smoothly between ticks, improving client-side rendering and reducing visual stutter. Related functions and usage are updated across main logic and procedures.
Implements interpolation for mob vertical movement and yaw, improving smoothness of mob movement and orientation updates. Refactors mob yaw calculation and exposes pending vertical delta and yaw via new API functions. Increases interpolation steps for finer movement and adds fallback logic for panic movement.
Introduced mobClearHorizontalDelta to reset mob x and z deltas. Updated processMobInterpolation to call this function and reset mob_interp_yaw when interpolation completes, ensuring proper mob state after movement.
Introduces mobVerticalProfile for improved vertical movement interpolation and exposes getMobInterpolationPhase and sampleMobVerticalPosition APIs. Updates mob interpolation logic in main.c and procedures.c to use the new sampling function for more accurate mob Y position calculation.
@Nu11ified Nu11ified marked this pull request as ready for review September 20, 2025 06:20
@p2r3
Copy link
Owner

p2r3 commented Sep 20, 2025

I'm not really a fan of how this is implemented. I touched on a much simpler opt-in interpolation approach in #78, and I'll probably be doing that one myself at some point.

Primarily, I want any change that measurably impacts memory usage or bandwidth to be opt-in. This has way too many direct changes to mob behavior for that (including some that seem outside the scope of this feature).

@p2r3
Copy link
Owner

p2r3 commented Sep 20, 2025

I also don't think you need 11 new global functions for interpolated movement.

Readded mob interpolation logic and replaced it with an optional midpoint interpolation system, controlled by ENABLE_OPTIN_MOB_INTERPOLATION. Updated mob movement broadcasting to simplify position and yaw calculation, and cleaned up related code in main.c, globals.h, procedures.h, and procedures.c. This improves code clarity and allows for more efficient mob movement updates, especially on constrained targets.
@Nu11ified
Copy link
Author

I also don't think you need 11 new global functions for interpolated movement.

But we do need 11 global functions...just kidding a lot can be cleaned up as my implementation is very rough. I looked at what you said in #78. Obviously the interpolation idea is pretty hard to get to a decent state without large memory requirements. My idea was to capture a mobs start/end position for every tick, stash that in a tiny opt-in buffer, and feed a midpoint "teleportation" before each tick. This is so we don't have to mess with the existing integer pathing. If I am wrong, if you have any thoughts that you want to add, or if you have any specification requirements for this feature I am open to discussion.

I understand you said you wanted to implement this in the future yourself, but if you don't mind I would like to try to get this working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants