Skip to content

ECS improvements#153

Open
Segfaultd wants to merge 3 commits intomasterfrom
experimental/ecs-improvements
Open

ECS improvements#153
Segfaultd wants to merge 3 commits intomasterfrom
experimental/ecs-improvements

Conversation

@Segfaultd
Copy link
Member

@Segfaultd Segfaultd commented Jan 28, 2026

This PR is linked with MafiaHub/Framework#181

Summary by CodeRabbit

  • Refactor

    • Restructured server-side entity update synchronization for improved network efficiency.
    • Reorganized client-side event handler configuration to streamline message routing.
  • Chores

    • Optimized build process with enhanced precompiled header reuse configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

Walkthrough

This PR refactors event handling in streaming modules across client and server. Client modules move event handlers from nested modEvents structure to top-level Streamable members while removing RPC forwarding paths. Server modules shift from per-entity event lambdas to observer-based architecture with periodic update systems. A build configuration addition enables PCH reuse.

Changes

Cohort / File(s) Summary
Client Streaming Handler Relocation
code/client/src/core/modules/human.cpp, code/client/src/core/modules/vehicle.cpp
Moved disconnect and updateTransform handlers from modEvents.*Proc nested structure to top-level *Proc members on Streamable. Removed RPC forwarding hooks (updateProc assignments) that previously sent HumanUpdate and VehicleUpdate messages over the network.
Server Build Optimization
code/server/CMakeLists.txt
Added CMake directive to reuse FrameworkServer's precompiled headers in MafiaMPServer target via target_precompile_headers().
Server Streaming Observer Pattern
code/server/src/core/modules/human.cpp, code/server/src/core/modules/vehicle.cpp
Replaced per-entity modEvents-based spawn/despawn/update lambdas with observer-based messaging. Observers now react to StreamedTo relation changes to send Spawn/Despawn messages, and new periodic update systems (VehicleStreamUpdates, human update loop) push HumanUpdate/VehicleUpdate messages with timing gating. Shift from immediate event dispatch to system-driven scheduled updates.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 From nested events to observers true,
Our streaming modules get a revamp anew,
No longer bound by modEvents chains,
The server dances with update lanes,
With handlers moved and systems sync'd,
Our rabbit code is sleekly linked! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'ECS improvements' is vague and generic, using a non-descriptive term that doesn't convey specific details about the changeset. Provide a more specific title that describes the actual changes, such as 'Refactor streaming event handlers from modEvents to observer pattern' or 'Migrate vehicle and human streaming to ECS observer-based messaging'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Segfaultd
Copy link
Member Author

@coderabbitai verify this PR in the context of this PR MafiaHub/Framework#181

@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@Segfaultd: I'll fetch the details of Framework PR #181 to verify this PR against those changes.


🏁 Script executed:

#!/bin/bash
# Fetch details of Framework PR `#181`
gh pr view 181 --repo MafiaHub/Framework --json title,body,state,files,additions,deletions

# Get the diff for Framework PR `#181` to see the actual changes
gh pr diff 181 --repo MafiaHub/Framework

Length of output: 59005


@Segfaultd: I've analyzed both PRs, and they are perfectly aligned

Key Compatibility Points

1. Callback Structure Migration

Framework PR #181 removes the modEvents structure from Streamable, and MafiaMP PR #153 correctly adapts by:

  • Moving disconnectProc and updateTransformProc from nested modEvents to top-level Streamable members
  • Removing all modEvents.updateProc assignments (no longer needed)

2. Observer-Based Event System

Framework introduces observers that send spawn messages when StreamedTo relation is added and despawn messages when removed. MafiaMP PR #153 implements this exactly:

  • Server human.cpp and vehicle.cpp add SpawnObserver and DespawnObserver on StreamedTo relations
  • Periodic update systems (HumanStreamUpdates, VehicleStreamUpdates) send updates based on StreamedTo data

3. StreamedTo Relation Usage

The framework uses StreamedTo relation to track which entities are streamed to which players, with lastUpdate timing data. MafiaMP correctly:

  • Uses StreamedTo relation observers instead of the old streamer.entities map
  • Maintains lastUpdate and updateInterval timing within StreamedTo data
  • Sends messages to streamers based on relation presence

4. Removed Dependencies

Framework removes SetupServerEmitters() and SetupClientEmitters(), and MafiaMP removes all calls to configure those old event handlers.

Summary

Fully compatible - MafiaMP PR #153 correctly implements all the changes required by Framework PR #181
Coordinated refactor - Both PRs move from callback-based to observer-based event handling
Clean migration - Old patterns removed, new ECS patterns properly adopted

The changes are consistent, well-structured, and ready for integration once Framework PR #181 is merged.


🧠 Learnings used
Learnt from: CR
Repo: MafiaHub/MafiaMP PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-20T21:02:07.332Z
Learning: Applies to code/{client,server,shared}/**/*.{cpp,hpp,h} : Use Flecs ECS for entity lifecycle management with authoritative server synchronization

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant