Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start planning out a Component system.
Huge thanks to all the great discussion on http://forums.spongepowered.org/t/component-system-and-minecraft/76/39 Signed-off-by: Chris Sanders <zidane@outlook.com>
- Loading branch information
Chris Sanders
committed
Sep 11, 2014
1 parent
3668cdb
commit 7756f2d
Showing
7 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/org/spongepowered/api/component/Component.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.spongepowered.api.component; | ||
|
||
import org.spongepowered.api.Game; | ||
|
||
/** | ||
* Represents a data holder for a {@link org.spongepowered.api.component.ComponentHolder}. | ||
*/ | ||
public interface Component<H> { | ||
/** | ||
* Returns the{@link org.spongepowered.api.component.ComponentHolder} holding this component. | ||
* @return The holder | ||
*/ | ||
H getHolder(); | ||
|
||
/** | ||
* Gets the {@link org.spongepowered.api.Game} object. | ||
* @return The game | ||
*/ | ||
Game getGame(); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/spongepowered/api/component/ComponentHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.spongepowered.api.component; | ||
|
||
/** | ||
* Marks an object as holding {@link org.spongepowered.api.component.Component}s. | ||
*/ | ||
public interface ComponentHolder<C> { | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/spongepowered/api/component/entity/EntityComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.spongepowered.api.component.entity; | ||
|
||
import org.spongepowered.api.component.Component; | ||
import org.spongepowered.api.entity.Entity; | ||
|
||
/** | ||
* Represents a {@link org.spongepowered.api.component.Component> attachable to {@link org.spongepowered.api.entity.Entity}s. | ||
*/ | ||
public interface EntityComponent extends Component<Entity> { | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/spongepowered/api/component/entity/attribute/Health.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.spongepowered.api.component.entity.attribute; | ||
|
||
import org.spongepowered.api.component.entity.EntityComponent; | ||
|
||
/** | ||
* Gives the attribute "health" to an {@link org.spongepowered.api.entity.Entity}. | ||
*/ | ||
public interface Health extends EntityComponent { | ||
/** | ||
* Gets the value of the current health | ||
* @return The value | ||
*/ | ||
double getHealth(); | ||
|
||
/** | ||
* Sets the value for the health | ||
* @param value The value | ||
*/ | ||
void setHealth(double value); | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/spongepowered/api/component/system/ComponentSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.spongepowered.api.component.system; | ||
|
||
import org.spongepowered.api.component.Component; | ||
import org.spongepowered.api.component.ComponentHolder; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Represents a relationship system of {@link org.spongepowered.api.component.ComponentHolder}s and their {@link org.spongepowered.api.component.Component}s. | ||
*/ | ||
public interface ComponentSystem { | ||
/** | ||
* Registers a {@link org.spongepowered.api.component.ComponentHolder} and {@link org.spongepowered.api.component.Component} relationship in the system | ||
* | ||
* @param holder The holder | ||
* @param component The component | ||
* @return The component, for chaining | ||
*/ | ||
public <T extends Component> T register(ComponentHolder<? super T> holder, T component); | ||
|
||
/** | ||
* Gets a {@link org.spongepowered.api.component.Component} for the {@link org.spongepowered.api.component.ComponentHolder} in the system. | ||
* | ||
* @param holder The holder | ||
* @param clazz The component class | ||
* @return The component | ||
*/ | ||
@Nullable | ||
<T extends Component> T get(ComponentHolder<? super T> holder, Class<T> clazz); | ||
|
||
/** | ||
* Removes a {@link org.spongepowered.api.component.ComponentHolder} and {@link org.spongepowered.api.component.Component}'s relationship from the system. | ||
* | ||
* @param holder The holder | ||
* @param clazz The component's class | ||
* @return The component that was removed | ||
*/ | ||
public <T extends Component> T remove(ComponentHolder<? super T> holder, Class<T> clazz); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/spongepowered/api/component/system/TickableComponentSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.spongepowered.api.component.system; | ||
|
||
/** | ||
* Represents a system where {@link org.spongepowered.api.component.Component}s are processed each implementation's tick. | ||
*/ | ||
public interface TickableComponentSystem extends ComponentSystem { | ||
/** | ||
* Called by the implementation to "process" the system | ||
* @param dt Time since last tick | ||
*/ | ||
void tick(float dt); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters