-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsimulation.rs
More file actions
813 lines (690 loc) · 27.4 KB
/
simulation.rs
File metadata and controls
813 lines (690 loc) · 27.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
use std::collections::HashSet;
use std::ops::{Add, Deref};
use std::pin::Pin;
use strum::EnumDiscriminants;
use common::*;
use resources::Resources;
use unit::world::{WorldPosition, WorldPositionRange};
use world::block::BlockType;
use world::loader::{TerrainUpdatesRes, WorldTerrainUpdate};
use world::WorldChangeEvent;
use crate::activity::ActivitySystem;
use crate::ai::{AiComponent, AiSystem};
use crate::alloc::FrameAllocator;
use crate::backend::TickResponse;
use crate::ecs::*;
use crate::event::{DeathReason, EntityEventQueue, RuntimeTimers};
use crate::input::{
BlockPlacement, InputEvent, InputSystem, MouseLocation, SelectedEntities, SelectedTiles,
UiCommand, UiPopup, UiRequest, UiResponsePayload,
};
use crate::item::{ContainerComponent, HaulSystem};
use crate::movement::MovementFulfilmentSystem;
use crate::needs::{EatingSystem, HungerSystem};
use crate::path::{NavigationAreaDebugRenderer, PathDebugRenderer, PathSteeringSystem};
use crate::physics::PhysicsSystem;
use crate::queued_update::QueuedUpdates;
use crate::render::{
AxesDebugRenderer, ChunkBoundariesDebugRenderer, DebugRendererError, DebugRenderers,
DebugRenderersState, UiElementPruneSystem,
};
use crate::render::{RenderSystem, Renderer};
use crate::runtime::{Runtime, RuntimeSystem};
use crate::scripting::ScriptingContext;
use crate::senses::{SensesDebugRenderer, SensesSystem};
use crate::society::{NameGeneration, PlayerSociety};
use crate::spatial::{Spatial, SpatialSystem};
use crate::steer::{SteeringDebugRenderer, SteeringSystem};
use crate::string::StringCache;
use crate::world_debug::FeatureBoundaryDebugRenderer;
use crate::{
definitions, BackendData, EntityEvent, EntityEventPayload, EntityLoggingComponent,
ThreadedWorldLoader, WorldRef, WorldViewer,
};
use crate::{ComponentWorld, Societies, SocietyHandle};
#[derive(Debug, EnumDiscriminants)]
#[strum_discriminants(name(AssociatedBlockDataType))]
#[non_exhaustive]
pub enum AssociatedBlockData {
Container(Entity),
}
pub struct WorldContext;
/// Monotonically increasing tick counter. Defaults to 0, the tick BEFORE the game starts, never
/// produced in tick()
static mut TICK: u32 = 0;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
/// Represents a game tick
pub struct Tick(u32);
#[derive(Copy, Clone)]
enum RunStatus {
Running,
Paused,
}
pub struct Simulation<R: Renderer> {
ecs_world: Pin<Box<EcsWorld>>,
voxel_world: WorldRef,
running: RunStatus,
/// Last interpolation passed to renderer, to reuse when paused
last_interpolation: f64,
world_loader: ThreadedWorldLoader,
/// Terrain updates, queued and applied per tick
/// TODO if order matters, use an IndexSet instead
terrain_changes: HashSet<WorldTerrainUpdate>,
/// World change events populated during terrain updates, consumed every tick
change_events: Vec<WorldChangeEvent>,
debug_renderers: DebugRenderers<R>,
scripting: ScriptingContext,
/// One off system that caches some allocations
display_text_system: DisplayTextSystem,
}
/// A little bundle of references to the game state without the generic [Renderer] param
/// on [Simulation], and no renderer fields
pub struct SimulationRefLite<'s> {
pub ecs: &'s EcsWorld,
pub world: &'s WorldRef,
pub loader: &'s ThreadedWorldLoader,
}
/// A little bundle of references to the game state without the generic [Renderer] param
/// on [Simulation], with renderer fields
pub struct SimulationRef<'s> {
pub ecs: &'s EcsWorld,
pub world: &'s WorldRef,
pub loader: &'s ThreadedWorldLoader,
pub viewer: &'s WorldViewer,
pub debug_renderers: &'s DebugRenderersState,
}
pub struct EcsWorldRef(Pin<&'static EcsWorld>);
impl world::WorldContext for WorldContext {
type AssociatedBlockData = AssociatedBlockData;
}
impl<R: Renderer> Simulation<R> {
/// world_loader should have had some slabs requested
pub fn new(world_loader: ThreadedWorldLoader, resources: Resources) -> BoxedResult<Self> {
let string_cache = StringCache::default();
// load entity definitions from file system
let definitions = {
let def_root = resources.definitions()?;
definitions::load(def_root, &string_cache)?
};
let voxel_world = world_loader.world();
// make ecs world and insert resources
let mut ecs_world = EcsWorld::with_definitions(definitions)?;
ecs_world.insert(voxel_world.clone());
ecs_world.insert(string_cache);
register_resources(&mut ecs_world, resources)?;
// get a self referential ecs world resource pointing to itself
// safety: static lifetime is as long as the game is running, as any system that uses it
// lives within in
let mut pinned_world = Box::pin(ecs_world);
unsafe {
let w = Pin::get_unchecked_mut(pinned_world.as_mut());
let world_ptr = w as *mut EcsWorld as *const EcsWorld;
let pinned_ref = Pin::new(&*world_ptr as &'static EcsWorld);
w.insert(EcsWorldRef(pinned_ref));
}
let debug_renderers = register_debug_renderers()?;
// ensure tick is reset
reset_tick();
Ok(Self {
ecs_world: pinned_world,
voxel_world,
last_interpolation: 0.0,
running: RunStatus::Running,
world_loader,
debug_renderers,
terrain_changes: HashSet::with_capacity(1024),
change_events: Vec::with_capacity(1024),
scripting: ScriptingContext::new()?,
display_text_system: DisplayTextSystem::default(),
})
}
pub fn tick(
&mut self,
commands: impl Iterator<Item = UiCommand>,
world_viewer: &mut WorldViewer,
backend_data: &BackendData,
response: &mut TickResponse,
) {
let _span = tracy_client::Span::new("tick", "Simulation::tick", file!(), line!(), 100);
// update tick
if !self.is_paused() {
increment_tick();
}
// TODO sort out systems so they all have an ecs_world reference and can keep state
// TODO limit time/count
self.apply_world_updates(world_viewer);
// process backend input
if let Some(point) = backend_data.mouse_position {
let z = {
let w = self.voxel_world.borrow();
let range = world_viewer.entity_range();
let start_from =
WorldPosition::new(point.x() as i32, point.y() as i32, range.top());
match w.find_accessible_block_in_column_with_range(start_from, Some(range.bottom()))
{
Some(pos) => pos.2,
None => range.bottom(),
}
};
let pos = point.into_world_point(NotNan::new(z.slice() as f32).unwrap()); // z is not nan
self.ecs_world.insert(MouseLocation(pos));
}
// apply player inputs
self.process_ui_commands(commands, response);
// tick game logic
self.tick_systems();
// per tick maintenance
// must remove resource from world first so we can use &mut ecs_world
let mut updates = self.ecs_world.remove::<QueuedUpdates>().unwrap();
updates.execute(Pin::as_mut(&mut self.ecs_world));
self.ecs_world.insert(updates);
self.delete_queued_entities();
self.ecs_world.maintain();
}
fn is_paused(&self) -> bool {
matches!(self.running, RunStatus::Paused)
}
fn tick_systems(&mut self) {
macro_rules! run {
($system:expr, $name:expr) => {{
let _span = tracy_client::Span::new($name, "tick_systems", file!(), line!(), 1);
$system.run_now(&self.ecs_world);
}};
($system:expr) => {
run!($system, std::stringify!($system))
};
}
// validate inventory soundness
#[cfg(debug_assertions)]
{
use crate::item::validation::InventoryValidationSystem;
run!(InventoryValidationSystem);
}
if !self.is_paused() {
// needs
run!(HungerSystem);
run!(EatingSystem);
// update senses
run!(SensesSystem);
// choose and tick activity
run!(AiSystem);
run!(
ActivitySystem(Pin::as_ref(&self.ecs_world)),
"ActivitySystem"
);
{
let _span = tracy_client::Span::new("Runtime", "tick_systems", file!(), line!(), 1);
self.ecs_world.resource::<Runtime>().tick();
}
// follow paths with steering
run!(PathSteeringSystem);
// apply steering
run!(SteeringSystem);
// attempt to fulfil desired velocity
run!(MovementFulfilmentSystem);
// process entity events
run!(RuntimeSystem);
// apply physics
run!(PhysicsSystem);
// sync hauled item positions
run!(HaulSystem);
// update spatial
run!(SpatialSystem);
// prune ui elements
run!(UiElementPruneSystem);
// prune dead entities from selection
self.ecs_world
.resource_mut::<SelectedEntities>()
.prune(&self.ecs_world);
}
// update display text for rendering
run!(self.display_text_system, "DisplayTextSystem");
// reset frame bump allocator
self.ecs_world.resource_mut::<FrameAllocator>().reset();
}
fn delete_queued_entities(&mut self) {
let deathlist_ref = self.ecs_world.resource_mut::<EntitiesToKill>();
let n = deathlist_ref.count();
if n > 0 {
// take out of resource so we can get a mutable world ref
let deathlist = deathlist_ref.replace_entities(Vec::new());
if let Err(err) = self.ecs_world.delete_entities(&deathlist) {
error!("failed to kill entities"; "entities" => ?deathlist, "error" => %err);
}
// put it back
let deathlist_ref = self.ecs_world.resource_mut::<EntitiesToKill>();
let empty = deathlist_ref.replace_entities(deathlist);
debug_assert!(empty.is_empty());
std::mem::forget(empty);
// post events
let event_queue = self.ecs_world.resource_mut::<EntityEventQueue>();
event_queue.post_multiple(deathlist_ref.iter().map(|(e, reason)| EntityEvent {
subject: e,
payload: EntityEventPayload::Died(reason),
}));
debug!("killed {} entities", n);
deathlist_ref.clear();
}
}
pub fn voxel_world(&self) -> WorldRef {
self.voxel_world.clone()
}
pub fn world_mut(&mut self) -> &mut EcsWorld {
&mut self.ecs_world
}
pub fn world(&self) -> &EcsWorld {
&self.ecs_world
}
pub fn societies_mut(&mut self) -> &mut Societies {
self.ecs_world.resource_mut()
}
pub fn set_player_society(&mut self, soc: SocietyHandle) {
self.ecs_world.insert(PlayerSociety::with_society(soc));
}
fn apply_world_updates(&mut self, world_viewer: &mut WorldViewer) {
// request new slabs
let discovered = empty(); // TODO include slabs discovered by members of player's society
let requested_slabs = world_viewer.requested_slabs(discovered);
let actual_requested_slabs = requested_slabs.as_ref().iter().copied();
self.world_loader.request_slabs(actual_requested_slabs);
drop(requested_slabs);
let mut world = self.voxel_world.borrow_mut();
// apply occlusion updates
self.world_loader
.iter_occlusion_updates(|update| world.apply_occlusion_update(update));
// mark modified slabs as dirty in world viewer, which will cache it until the slab is visible
world.dirty_slabs().for_each(|s| world_viewer.mark_dirty(s));
drop(world);
// aggregate all terrain changes for this tick
let updates = &mut self.terrain_changes;
self.world_loader.steal_queued_block_updates(updates);
updates.extend(self.ecs_world.resource_mut::<TerrainUpdatesRes>().drain(..));
// apply all applicable terrain changes
{
let n_before = updates.len();
self.world_loader
.apply_terrain_updates(updates, &mut self.change_events);
let n_after = updates.len();
debug_assert!(n_after <= n_before);
if n_before > 0 {
debug!(
"applied {applied} terrain updates, deferring {deferred}",
applied = n_before - n_after,
deferred = n_after
);
}
}
// consume change events
let mut events = std::mem::take(&mut self.change_events);
self.on_world_changes(&events);
events.clear();
// swap storage back and forget empty vec
std::mem::forget(std::mem::replace(&mut self.change_events, events));
}
fn process_ui_commands(
&mut self,
commands: impl Iterator<Item = UiCommand>,
tick: &mut TickResponse,
) {
for cmd in commands {
let (req, resp) = cmd.consume();
match req {
UiRequest::DisableAllDebugRenderers => {
self.debug_renderers.disable_all(&self.ecs_world);
}
UiRequest::SetDebugRendererEnabled { ident, enabled } => {
if let Err(e) =
self.debug_renderers
.set_enabled(ident, enabled, &self.ecs_world)
{
warn!("failed to set debug renderer state"; "error" => %e);
}
}
UiRequest::FillSelectedTiles(placement, block_type) => {
let selection = self.ecs_world.resource::<SelectedTiles>();
if let Some((mut from, mut to)) =
selection.current_selected().map(|sel| sel.range().bounds())
{
if let BlockPlacement::PlaceAbove = placement {
// move the range up 1 block
from = from.above();
to = to.above();
}
let range = WorldPositionRange::with_inclusive_range(from, to);
debug!("filling in block range"; "range" => ?range, "block_type" => ?block_type);
self.terrain_changes
.insert(WorldTerrainUpdate::new(range, block_type));
}
}
UiRequest::IssueDivineCommand(_) | UiRequest::CancelDivineCommand => {
let mut ais = self.ecs_world.write_storage::<AiComponent>();
let selected_entities = self.ecs_world.resource_mut::<SelectedEntities>();
for selected in selected_entities.iter() {
if let Some(ai) = selected.get_mut(&mut ais) {
if let UiRequest::IssueDivineCommand(ref command) = req {
ai.add_divine_command(command.clone());
} else {
ai.remove_divine_command();
}
}
}
}
UiRequest::IssueSocietyCommand(society, command) => {
let society = match self
.world()
.resource::<Societies>()
.society_by_handle(society)
{
Some(s) => s,
None => {
warn!("invalid society while issuing command"; "society" => ?society, "command" => ?command);
continue;
}
};
debug!("submitting command to society"; "society" => ?society, "command" => ?command);
if let Err(command) = command.submit_job_to_society(society, &self.ecs_world) {
warn!("failed to issue society command"; "command" => ?command);
continue;
}
}
UiRequest::CancelJob(job) => {
if let Some(society) = self
.world()
.resource::<Societies>()
.society_by_handle(job.society())
{
society.jobs_mut().cancel(job);
}
}
UiRequest::SetContainerOwnership {
container,
owner,
communal,
} => {
match self
.ecs_world
.component_mut::<ContainerComponent>(container)
{
Err(e) => {
warn!("invalid container entity"; "entity" => container, "error" => %e);
continue;
}
Ok(mut c) => {
if let Some(owner) = owner {
c.owner = owner;
info!("set container owner"; "container" => container, "owner" => owner)
}
if let Some(communal) = communal {
if let Err(e) = self
.ecs_world
.helpers_containers()
.set_container_communal(container, communal)
{
warn!("failed to set container society"; "container" => container, "society" => ?communal, "error" => %e);
}
}
}
}
}
UiRequest::ExitGame(ex) => tick.exit = Some(ex),
UiRequest::ExecuteScript(path) => {
info!("executing script"; "path" => %path.display());
let result = self
.scripting
.eval_path(&path, &*self.ecs_world)
.map(|output| output.into_string());
if let Err(err) = result.as_ref() {
warn!("script errored"; "error" => %err);
}
resp.set_response(UiResponsePayload::ScriptOutput(result));
}
UiRequest::ToggleEntityLogging { entity, enabled } => {
if enabled {
let _ = self
.ecs_world
.add_now::<EntityLoggingComponent>(entity, Default::default());
} else {
let _ = self.ecs_world.remove_now::<EntityLoggingComponent>(entity);
}
}
UiRequest::ModifySelection(modification) => {
let sel = self.ecs_world.resource_mut::<SelectedTiles>();
sel.modify(modification, &self.voxel_world);
}
UiRequest::CancelSelection => {
// close current popup if there is one
let popup = self.ecs_world.resource_mut::<UiPopup>();
if !popup.close() {
// fallback to clearing tile and entity selections
let tiles = self.ecs_world.resource_mut::<SelectedTiles>();
let entities = self.ecs_world.resource_mut::<SelectedEntities>();
tiles.clear();
entities.unselect_all(&self.ecs_world);
}
}
UiRequest::CancelPopup => {
// close current popup only
self.ecs_world.resource_mut::<UiPopup>().close();
}
UiRequest::TogglePaused => {
self.running = match self.running {
RunStatus::Running => RunStatus::Paused,
RunStatus::Paused => RunStatus::Running,
};
debug!(
"{} gameplay",
if self.is_paused() {
"paused"
} else {
"resumed"
}
)
}
UiRequest::ChangeGameSpeed(change) => {
tick.speed_change = Some(change);
}
}
}
}
/// Target is for this frame only
pub fn render(
&mut self,
world_viewer: &WorldViewer,
target: R::FrameContext,
renderer: &mut R,
interpolation: f64,
input: &[InputEvent],
) -> R::FrameContext {
// process input before rendering
InputSystem::with_events(input).run_now(&*self.ecs_world);
// start frame
renderer.init(target);
let interpolation = if self.is_paused() {
// reuse last interpolation to avoid jittering
self.last_interpolation
} else {
self.last_interpolation = interpolation;
interpolation
};
// render simulation
{
renderer.sim_start();
{
let mut render_system = RenderSystem {
renderer,
slices: world_viewer.entity_range(),
interpolation: interpolation as f32,
};
render_system.run_now(&*self.ecs_world);
}
if let Err(e) = renderer.sim_finish() {
warn!("render sim_finish() failed"; "error" => %e);
}
}
// render debug shapes
{
renderer.debug_start();
let ecs_world = &*self.ecs_world;
let voxel_world = self.voxel_world.borrow();
let world_loader = &self.world_loader;
self.debug_renderers.iter_enabled().for_each(|r| {
r.render(
renderer,
&voxel_world,
world_loader,
ecs_world,
world_viewer,
)
});
if let Err(e) = renderer.debug_finish() {
warn!("render debug_finish() failed"; "error" => %e);
}
}
// end frame
renderer.deinit()
}
fn on_world_changes(&mut self, events: &[WorldChangeEvent]) {
let selection = self.ecs_world.resource_mut::<SelectedTiles>();
let mut selection_modified = false;
for &WorldChangeEvent { pos, prev, new } in events {
match (prev, new) {
(a, b) if a == b => continue,
(_, BlockType::Chest) => {
// new chest placed
if let Err(err) = self
.ecs_world
.helpers_containers()
.create_container_voxel(pos, "core_storage_chest")
{
error!("failed to create container entity"; "error" => %err);
}
}
(BlockType::Chest, _) => {
// chest destroyed
self.ecs_world.resource::<QueuedUpdates>().queue(
"destroy container",
move |world| match world
.helpers_containers()
.destroy_container(pos, DeathReason::BlockDestroyed)
{
Err(err) => {
error!("failed to destroy container"; "error" => %err);
Err(err.into())
}
Ok(()) => Ok(()),
},
)
}
_ => {}
}
if !selection_modified {
if let Some(sel) = selection.current_selected() {
if sel.range().contains(&pos) {
selection_modified = true;
}
}
}
}
if selection_modified {
selection.on_world_change(&self.voxel_world);
}
}
pub fn as_lite_ref(&self) -> SimulationRefLite {
SimulationRefLite {
ecs: &*self.ecs_world,
world: &self.voxel_world,
loader: &self.world_loader,
}
}
pub fn as_ref<'a>(&'a self, viewer: &'a WorldViewer) -> SimulationRef<'a> {
SimulationRef {
ecs: &*self.ecs_world,
world: &self.voxel_world,
loader: &self.world_loader,
viewer,
debug_renderers: self.debug_renderers.state(),
}
}
}
fn increment_tick() {
// safety: called before ticking systems
unsafe {
TICK += 1;
}
}
fn reset_tick() {
// safety: called before ticking systems
unsafe {
TICK = 0;
}
}
pub fn current_tick() -> u32 {
// safety: only modified between ticks
unsafe { TICK }
}
impl Tick {
pub fn fetch() -> Self {
Self(current_tick())
}
pub fn value(self) -> u32 {
self.0
}
/// self is later
pub fn elapsed_since(self, other: Self) -> u32 {
self.0.saturating_sub(other.0)
}
#[cfg(test)]
pub fn with(tick: u32) -> Self {
Self(tick)
}
}
impl Add<u32> for Tick {
type Output = Self;
fn add(self, rhs: u32) -> Self::Output {
Self(self.0 + rhs)
}
}
fn register_resources(world: &mut EcsWorld, resources: Resources) -> BoxedResult<()> {
world.insert(QueuedUpdates::default());
world.insert(EntitiesToKill::default());
world.insert(SelectedEntities::default());
world.insert(SelectedTiles::default());
world.insert(TerrainUpdatesRes::default());
world.insert(Societies::default());
world.insert(PlayerSociety::default());
world.insert(EntityEventQueue::default());
world.insert(Spatial::default());
world.insert(RuntimeTimers::default());
world.insert(Runtime::default());
world.insert(MouseLocation::default());
world.insert(NameGeneration::load(&resources)?);
world.insert(FrameAllocator::default());
world.insert(UiPopup::default());
Ok(())
}
fn register_debug_renderers<R: Renderer>() -> Result<DebugRenderers<R>, DebugRendererError> {
let mut builder = DebugRenderers::builder();
// order is preserved in ui
builder.register::<AxesDebugRenderer>()?;
builder.register::<ChunkBoundariesDebugRenderer>()?;
builder.register::<SteeringDebugRenderer>()?;
builder.register::<PathDebugRenderer>()?;
builder.register::<NavigationAreaDebugRenderer>()?;
builder.register::<SensesDebugRenderer>()?;
builder.register::<FeatureBoundaryDebugRenderer>()?;
builder.register::<EntityIdDebugRenderer>()?;
builder.register::<AllSocietyVisibilityDebugRenderer>()?;
Ok(builder.build())
}
impl Default for EcsWorldRef {
fn default() -> Self {
// register manually
unreachable!()
}
}
impl Deref for EcsWorldRef {
type Target = EcsWorld;
fn deref(&self) -> &Self::Target {
&*self.0
}
}