Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Entity Creation and Scene Management #249

Conversation

softwareantics
Copy link
Owner

@softwareantics softwareantics commented Aug 15, 2023

Description

This PR produces the features described in issue #244:

  • Created an ISceneManager that provides readonly access to the currently active/loaded scene.
  • Create a Scene model that provides the ability to add an entity to the transient injected IEntityWorld service.
    • The model provides access to the currently added entities via a readonly collection for use with view models.
    • The model also has a Render method that simply ensures that all systems that have a execution type of Render will be processed.
  • The SceneRenderer has been updated to render the currently active/loaded Scene via the ISceneManager.

Closes #244

Dependencies

This PR introduces no new dependencies.

Type of change

  • New feature (non-breaking change which adds functionality).

How Has This Been Tested?

I have provided unit tests for all testable changes I've made. Final Code Coverage is showing 100% code coverage (obviously excluding any ExcludeFromCodeCoverage attributes). All unit tests pass locally on my machine. I've done my best to ensure that this feature is implemented correctly but I will not know until #248 is implemented.

Test Configuration:

  • Operating System: Windows 10 Home
  • Hardware: Intel i7-6700HQ, 16GB RAM, GTX 950M
  • Toolchain: VS Community 2022 17.5.4

Proposed Design

Scene Manager

The ISceneManager service is provided to access the currently active/loaded Scene. Final Engine doesn't support creating, loading or saving new scenes yet so this is likely to be added in the future. But for now, it is simply an interface to provide access to a Scene model. Currently, a transient scene is passed into the ISceneManager implementation on application startup using the IoC container. This will likely be adjusted in the near future.

public interface ISceneManager
{
    IScene ActiveScene { get; }
}

Scenes

A Scene currently provides a way to add entities to an IEntityWorld (transient) via dependency injection. In the future a Scene will have the ability to serialized and de-serialized to allow for saving and loading of scenes. The Scene model also provides a Render function which simply invokes world.ProcessAll(GameLoopType.Render) to process all registered entity systems.

The Scene model also exposes a readonly collection of entities that will be accessed by the view models implemented in #248 when we address the front-end UI logic. An entity is added to both the injected IEntityWorld service and the collection that is initialized in the models constructor. The reasoning for this design decision is to make sure that the end-user cannot enumerate over an entities components as that is a job an entity system.

/// <summary>
/// Defines an interface that represents a scene.
/// </summary>
public interface IScene
{
    /// <summary>
    /// Gets the entities contained within this scene.
    /// </summary>
    /// <value>
    /// The entities contained within this scene.
    /// </value>
    IReadOnlyCollection<Entity> Entities { get; }

    /// <summary>
    /// Adds the specified <paramref name="entity"/> to the scene.
    /// </summary>
    /// <param name="entity">
    /// The entity to be added.
    /// </param>
    void AddEntity(Entity entity);

    /// <summary>
    /// Renders the scene, processing all rendering systems.
    /// </summary>
    void Render();
}

Possible Issues

I'm sure there will be some issue that will arise and can be addressed in the future but for now I think this is mostly boilerplate code. Most things I can think of are UI specific and should not be listed here and instead will be addressed when #248 is implemented.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • My changes generate no new warnings

@softwareantics softwareantics self-assigned this Aug 15, 2023
@softwareantics softwareantics marked this pull request as ready for review August 15, 2023 11:21
@sonarcloud
Copy link

sonarcloud bot commented Aug 15, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

warning The version of Java (11.0.20) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

@softwareantics softwareantics merged commit 829df4b into epic/112-editor Aug 15, 2023
3 checks passed
@softwareantics softwareantics deleted the feature/244-entity-creation-and-scene-management branch August 15, 2023 11:25
This was referenced Aug 15, 2023
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.

None yet

1 participant