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

Refactor entitycontrollers #129

Merged
merged 5 commits into from May 18, 2018
Merged

Refactor entitycontrollers #129

merged 5 commits into from May 18, 2018

Conversation

gurkenlabs
Copy link
Collaborator

Problem
Previously, the whole management of controllers that are related to entities was really inconsistent.
They were also managed globally, although an entity instance always had to be present in order to retrieve them. There were also some issues with the EntityControllerManager returning wildcard types whilst this essentially added no value.
The basic interfaces for the controllers were all generic as well which required such an implementation.

Goal
Make the basic controller interfaces non-generic while keeping the syntactic sugar to have a generic implementation for the actual classes.
With this change, the controllers are managed similar to a component-based system and can be directly used/set/retrieved from an entity.

Also, this refactoring adds a method that allows to simply scale the sprite for an entity with a simple method on the IEntityAnimationController.

Gurkenlabs added 5 commits May 18, 2018 14:48
Rename AiController to BehaviorController.
An IEntity now returns an IEntityAnimationController instead of just an IAnimationController.

Implement a method that scales the sprite for an entity via AffineTransform. This method automatically translates the scaled sprite so that it will be scaled around the center of the entity.
There was no actual external value of providing a wildcard type that inherited from IEntity because the consumers wouldn't know what the type actually was anyway.
The generic implementation is useful syntax sugar though for actual controller implementations because they might rely on some logic that is determined by a custom Entity implementation.

Move the EntityControllerManager from litiengine.entities.ai to litiengine.entities namespace.
Introduce a new IEntityProvider interface that marks implementations that provide a related entity.
The Game no longer holds a static EntityControllerManager.
Instead, every Entity gets a new EntityControllers object that manages the controllers for the instance.

The implementation has been done in such a generic way that it can be used similar to a component system.
There are three known default types of controllers in the IEntityAnimationController, IBehaviorController and IMovementController.
The default IAnimationController interface is a bit more general and doesn't require any entity. Only controllers that are related to an entity are managed this way.

Developers can reuse the new logic to define instances of the known types, define custom ones or overwrite preset instances.

The environment will automatically call the controllers attach/detach methods as entities get loaded to or unloaded from the environment.
@gurkenlabs gurkenlabs merged commit 13e2d84 into master May 18, 2018
@gurkenlabs gurkenlabs deleted the refactor-entitycontrollers branch May 18, 2018 19:19
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