HyCodeYourTale

Threading

Threading

Dokumentace k thread safety a synchronizaci v Hytale.

Soubory

Rychlý Přehled

Threading Model

Main Thread
├── World Thread (default)
├── World Thread (nether)
├── World Thread (custom)
├── Scheduler Thread
└── Network Thread

Základní Pravidla

1. Component operace musí běžet na správném World threadu
2. Nikdy neblokuj World thread (žádné sleep, blocking I/O)
3. Používej thread-safe kolekce pro sdílená data

Kdy Použít world.execute()

| Situace | Potřeba world.execute() |
|---------|-------------------------|
| AbstractPlayerCommand.execute() | Ne (automaticky) |
| EntityEventSystem.handle() | Ne (automaticky) |
| Sync event handler | Ne |
| Async event handler | Ano |
| CommandBase.executeSync() | Ano (pro komponenty) |
| CompletableFuture callback | Ano |

Příklad

// Async event → potřeba world.execute()
getEventRegistry().registerAsyncGlobal(PlayerChatEvent.class, future -> {
future.thenAccept(event -> {
Player player = event.getPlayer();
World world = player.getWorld();

world.execute(() -> {
// Teď bezpečné pro komponenty
Store store = player.getRef().getStore();
CustomComp comp = store.getComponent(ref, CustomComp.getComponentType());
});
});
});


Last updated: 20. ledna 2026