Entity Systems - Artemis-odb (Part2)

Artemis-odb is a high performance java based Entity-Component-System framework.
It is mature, actively maintained, and a continuation of the popular Artemis.

Highlights

Getting started

Community

Share your thoughts and questions with us!

Maven

<dependency>     <groupId>net.onedaybeard.artemis</groupId>     <artifactId>artemis-odb</artifactId>     <version>1.4.0</version> </dependency>

Gradle

  dependencies { compile "net.onedaybeard.artemis:artemis-odb:1.4.0" }

Manual Download

Entity Systems - Introduction (Part1)

What is an Entity System?

An entity system (also known as a Entity Component System) consists of three primary items:
  • Components
    • A component simply holds a piece of data and does not contain any game logic. Your typical component will have fields for primitive values and data objects.
  • Entities
    • An entity is a collection of components.
  • Systems
    • A system is typically an implementation that iteratively operates on a group of entities that share a specific set of components.

Can you give me an example?

Let's take a simple platform game where you have characters that move around. In this hypothetical example, you'll need ways of dealing with the character's game physics, drawing the character, and driving how the character moves. To build this, we could start with the following components:
  • Motion, for driving how the character moves
  • Spatial, for drawing how the character appears
  • Physics, for maintaining physical information about the character for collision handling, applying physical forces, etc.
  • PlayerInput, for defining player input
From this, we'd define a "player entity" and then add those components at run-time.
Next, we create systems to act on the various components. Our systems could be:

  • RenderSystem, which acts on any entities that contain Physics and Spatial components. We utilize the Physics component to determine where in the physics space the character is. We utilize the Spatial component to determine how to draw the character. If an entity does not have both of these components, then it will NOT be processed by RenderSystem.
  • MotionSystem, which acts on any entities that contain Physics and Motion components. We utilize the Motion component to determine what motion effects are applied to an entity (left, right, jump, etc.) We utilize the Physics component to apply forces to the entity based on Motion. As above, if an entity does not have both of these components, then it will not be processed by MotionSystem
  • PlayerInputSystem, which acts on any entities that contain Motion and PlayerInput components. The player input component could contain info about whether the related input is "locally" or "remotely" (via network or some other means) defined. For a "local" player entity, keypresses update the Motion component with information. For a "remote" player entity, network commands update the Motion component with information.
An example flow of this architecture would be: local player presses the "move left" key. PlayerInputSystem executes and detects the keypress, updating the Motion component. MotionSystem executes and "sees" the Motion for the entity is to the left, applying a Physics force to the left. The RenderSystem executes and reads the current position of the entity, and draws it according to the Spatial definition (which may include texture region / animation information).

Ugh. Seems like a lot of work. Why not use standard OOP?

One of the advantages of the Entity System is that it helps decompose or compartmentalize things. You have code that operates on very specific things and does this regardless of other components that the entity might have. Further, it helps prevent from things degenerating into the "blob" anti-pattern. As the game architecture becomes more complex, you simply add or remove components without having to worry about massive refactoring.
In a hierarchical approach, if two classes in very different places of the hierarchy tree require commonality, they'll either need to be derived from the same super class which takes on the shared qualities or copying and pasting will be required. This is fine for shallow trees, but games tend to evolve over time turning this into a potential chore.
Decomposing the architecture using an entity system gives us a very easy path for adding / extending / altering operation. Let's say in our example above, we now wanted to create some enemies. Rather than deriving or cutting and pasting things, we create a new component: EnemyAI. We then create a new entity that consists of:
  • Motion component
  • Physics component
  • Spatial component
  • EnemyAI component
...and we create a new "EnemyAISystem" that operates on any entity with the EnemyAI, Physics, and Motion components. This system implements enemy behaviors that define when and how to move the related entity, updating the Motion component in the process.

Our RenderSystem and MotionSystem will pick up new enemy entities with no further changes required.

How to setup Libgdx for Android Studio

What is Android Studio?
Android studio is an IDE for Android developers. First announced earlier 2013, it has since grown to be a very effective tool. Last month, June 2014, Android Studio has went from alpha to beta. If you wish not to use an ‘in progress’ IDE, your other option is Eclipse. But hey, out with the old and in with the new. Source: http://en.wikipedia.org/wiki/Android_Studio
Unlike Eclipse, Android Studio is, in my own opinion:
·       Faster
·       Responsive
·       Visually unified
·       More productive

What is libGDX?
I like to call it a convenience. It is like XNA game studios for Android developers. It integrates easily into Android Studio, is cross-platform, and is super-fast. For a full detailed list, visit their feature page http://libgdx.badlogicgames.com/features.html

How to correctly setup libGDX
It took me three days to figure this out. I am letting you do it in one day.
Go to the libGDX download page and download the setup app. This file will generate an Android Studio Project with all the necessary libgdx libraries and cross-platform modules for you. http://libgdx.badlogicgames.com/download.html
1.    This is only file you need to download.

2.    Click on the download file and save it to your computer.


Save this file to your computer
3.    Open the jar file. Then, fill in the dialog box as follows:
A.    Leave Name: unchanged
B.    Leave Package: unchanged.
C.   Leave GameClass: unchanged
D.   Go to your \AndroidStudioProjects Folder in the Library Explorer and create a new folder called \SetupGame. This is where our new project will be generated.
E.    Change Destination to:
                        i.          C:\Users\<USER_NAME>\AndroidStudioProjects\SetupGame
F.    Change AndroidSDK to:
                        i.         C:\Users\<USER_NAME>\AppData\Local\Android\android-studio\sdk
G.   Leave all Sub Projects: checked
H.   Uncheck the Box2d Extension unless you know you are going to use it.
I.      Click Generate:
Do not worry, it is not as complicated as it looks
4.   From the Android Studio welcome screen, click Import Project and select: C:\Users\<USER_NAME>\AndroidStudioProjects\SetupGame\build.gradld. This is going to open up the project for us.
Here you see the build.gradle file you need to import.
5.   DO NOT PANIC. You will get this screen saying there is an error. This is easy to fix
As you see, there is an incompatible version begin used.
6.   In your Library Explorer,
A.    Navigate to C:\Users\<USER_NAME>\AndroidStudioProjects\SetupGame.
B.    Right click on the .idea folder
C.   Delete It.
Simple isn’t it. Just delete the .idea folder.
7.   Back in Android Studio. Press (Ctrl+Alt+Y) to synchronize your project. A new .idea folder will be auto-generated with the correct contents. Honestly, I do not know why it does this. I just know that it works.
8.    Double tap on any of the file breadcrumb tabs to open up the project file viewer screen.
Doesn’t this look so clean. Anyway, this is what you will see on the left-hand side of the screen.
9.   Now open up your MySetupGame/build.gradle file and make one small change.
Change: classpath ‘com.android.tools.build:gradle:0.10+’ to …0.12+’
Yup, simply change that 0.10 to 0.12+
10. Sync your project again



If you do not get any errors, this is a success. you now have now setup libgdx for Android Studio.

Copyright © Am I a developer?. From Do Viet Kien.

Scroll to top