11using Microsoft . Xna . Framework ;
22using SKSSL . ECS ;
3- using SKSSL . Space ;
43
54// ReSharper disable PublicConstructorInAbstractClass
65
76namespace SKSSL . Scenes ;
87
98/// <summary>
109/// Common contract for all worlds (used by SceneManager, ECSController, etc.)
10+ /// All worlds are inherently renderable spaces, but additional rendering code is required on the developer's part.
11+ /// This may not include menus if GumUI is used on the Screen layer.
1112/// </summary>
1213public interface IWorld
1314{
14- RenderableSpace Space { get ; }
15+ /// Initializes the Game World.
1516 void Initialize ( GraphicsDeviceManager graphics ) ;
17+ /// Update calls made into the game world.
1618 void Update ( GameTime gameTime ) ;
19+ /// Draw calls made into the game world.
1720 void Draw ( GameTime gameTime ) ;
21+ /// Actions taken before the world is destroyed. Saving measures, deletions, etc.
1822 void Destroy ( ) ;
1923}
2024
2125/// <summary>
22- /// Overridable inherited dictation of how a World, its <see cref="RenderableSpace"/> , and its systems.
26+ /// Overridable inherited dictation of how a World, its Renderable Space , and its systems.
2327/// <see cref="UsesECS"/> toggled override will permit automatic updating of underlying systems.
28+ /// A "physical" virtual space or area that is rendered for gameplay. Constitutes, typically, the entire field that
29+ /// which the user will play in. Implement this class however you see fit.
30+ /// Add your rendering / other code within your World class.
2431/// </summary>
2532public abstract class BaseWorld : IWorld
2633{
2734#pragma warning disable CS0618 // Type or member is obsolete
28- public RenderableSpace Space { get ; private set ; } = new BlankWorldSpace ( ) ;
2935 protected bool IsInitialized { get ; private set ; }
3036
3137 /// Most worlds use ECS — this depends on overall dictation. If ECS is enabled,
@@ -36,54 +42,29 @@ public abstract class BaseWorld : IWorld
3642 /// ECS controller unique to this world instance. Left null of no ECS controller.
3743 public ECSController ? ECS { get ; private set ; } = null ;
3844
39- /// Assign Rendered space field with provided space definition.
40- public void SetSpace ( RenderableSpace worldSpace )
41- {
42- Space . Destroy ( ) ;
43- Space = worldSpace ;
44- }
45-
4645 /// Calls ECS Init() (if enabled)
4746 protected BaseWorld ( )
4847 {
4948 // ReSharper disable once VirtualMemberCallInConstructor
5049 // Enable ECS if toggled-on.
5150 if ( ! UsesECS ) return ;
5251 ECS = new ECSController ( this ) ;
53- ECS . Initialize ( ) ;
5452 }
5553
5654
5755 /// Calls Spacial Initializations as base class method.
58- public virtual void Initialize ( GraphicsDeviceManager ? graphics )
59- {
60- // Avoid re-initializing what already has been initialized.
61- if ( IsInitialized ) return ;
62- IsInitialized = true ;
63-
64- // Initialize WorldSpace assuming graphics provided + exception.
65- if ( graphics != null )
66- Space . Initialize ( graphics ) ;
67- else if ( Space == null && graphics != null )
68- throw new NullReferenceException ( "Attempted to initialize WorldSpace with null GraphicsDeviceManager" ) ;
69- }
56+ public virtual void Initialize ( GraphicsDeviceManager ? graphics ) => ECS ? . Initialize ( ) ;
7057
71- public virtual void Update ( GameTime gameTime )
72- {
73- ECS ? . Update ( gameTime ) ;
74- Space . Update ( gameTime ) ;
75- }
58+ /// <inheritdoc cref="IWorld.Update"/>
59+ public virtual void Update ( GameTime gameTime ) => ECS ? . Update ( gameTime ) ;
7660
77- public virtual void Draw ( GameTime gameTime )
78- {
79- ECS ? . Draw ( gameTime ) ;
80- Space . Draw ( gameTime ) ;
81- }
61+ /// <inheritdoc cref="IWorld.Draw"/>
62+ public virtual void Draw ( GameTime gameTime ) => ECS ? . Draw ( gameTime ) ;
8263
64+ /// <inheritdoc cref="IWorld.Destroy"/>
8365 public virtual void Destroy ( )
8466 {
8567 ECS ? . Destroy ( ) ;
86- Space . Destroy ( ) ;
8768 ECS = null ;
8869 IsInitialized = false ;
8970 }
0 commit comments