ogdc 2014: component based entity system mobile game development

18
+ Component-based Entity system in Mobile Game Development CodyNguyen Mobile Game Developer, Vinova VN [email protected]

Upload: gamelandvn

Post on 20-Jun-2015

2.489 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OGDC 2014: Component based entity system mobile game development

+

Component-basedEntity system

in Mobile Game Development

CodyNguyenMobile Game Developer, Vinova [email protected]

Page 2: OGDC 2014: Component based entity system mobile game development

+Start small: cute infinite fly game

Gasboy

Page 3: OGDC 2014: Component based entity system mobile game development

+After that: a cooler (and bigger) game

Stickman

Traps

SkillsGod’s Rage

Page 4: OGDC 2014: Component based entity system mobile game development

+

architecture problems start to pop out

As with any software getting more complex,

Page 5: OGDC 2014: Component based entity system mobile game development

+Game entities share capabilities among each others

deal_damage_around

deal_damage_around deal_damage_around

deal_damage_around

movable

movable movable

throwable

throwable

lie_on_ground

lie_on_ground

delay_on_activating

delay_on_activating

activate_on_touch

activate_on_touch

Page 6: OGDC 2014: Component based entity system mobile game development

+Game entities share capabilities among each others

Impossible to build a good OOP class hierarchy!

natural relationships welcome changes code reuse

Page 7: OGDC 2014: Component based entity system mobile game development

+First solution comes to mind:mix-ins via multiple-inheritance

1. Just a small portion of the tree is a mess already

2. Multiple inheritance smells

3. Where to put logic that evolves object of different classes?

Capability

Moveable DealDamage ActivateOnTouch Throwable

Thorn Cloud Bomb Bull

Page 8: OGDC 2014: Component based entity system mobile game development

+Need a better solution

Component-based entity system has been a hot topic for years.

It helps solve our problem in an elegant way!

Page 9: OGDC 2014: Component based entity system mobile game development

+Component-based entity system

Multitude of ways to represent and implement

This talk discusses one way which we found practical and easy to understand

Three elements: Entity Component System

Page 10: OGDC 2014: Component based entity system mobile game development

+Component-based entity system

Decompose game entities by capabilities into reusable components.

Prefer aggregation over inheritance, i.e., entity has components, not is a type of some component.

Page 11: OGDC 2014: Component based entity system mobile game development

+Entity and Component

Velocity Damage Graphic ThrowAngle ActivateOnTouch

Thorn x x x

Cloud x x x

Bomb x x x x

Bull x x x x

Entity is: an unique ID + a list of components

Component contains only data

Page 12: OGDC 2014: Component based entity system mobile game development

+Where does the logic go?The systems.

Bull

Light-ning

Thorn

Cloud

Stick-

man

Game has a bunch ofentities

Entities are processed bysystems

M o v e m e n t S y s t e m

A n i m a t i o n S y s t e m

P h y s i c s S y s t e m

C o l l i s i o n S y s t e m

H e a l t h S y s t e m

Page 13: OGDC 2014: Component based entity system mobile game development

+Systems only process entities they “care” about

Entities are keys Systems are locks

http://gamedev.stackexchange.com/a/31491

Components are teeth

Page 14: OGDC 2014: Component based entity system mobile game development

+Entity system sum up

Entity Is just a unique ID with a bunch of components Doesn’t need a separate Class for each entity

Component Is the “ingredient” to make entities. Contains data only.

System Contains game logic Run on every game loop, process entities who has a set of

components it care about.

Page 15: OGDC 2014: Component based entity system mobile game development

+Other benefits of using entity system

Goes hand-in-hand with Data-Driven development: Entities are defined as bags of components, in text file. “No engineer required”, game designer can create new or

edit existing entities easily. Easy to change or fine-tune entities

Promote multi-threading Systems are independent from one another, so they can

run on separate threads

Page 16: OGDC 2014: Component based entity system mobile game development

+Artemis Entity System

An Entity system framework written in Java:http://gamadu.com/artemis/tutorial.html

Is open-source, active project

Ported to many different languages

Page 17: OGDC 2014: Component based entity system mobile game development

+Artemis Entity System and Cocos2d

Sidar Talei ported to C++, we forked, modified and maintain:https://github.com/vinova/Artemis-Cpp

Our port: Works great with cocos2d-x! Work great with any C++ framework. No external libs or C+

+11 compiler are required JavaScript binding coming soon

Page 18: OGDC 2014: Component based entity system mobile game development

+References

A Data-Driven Game Object Systemhttp://scottbilas.com/files/2002/gdc_san_jose/game_objects_slides.ppt

Entity Systems are the future of MMOG development http://t-machine.org/index.php/2007/11/11/entity-systems-are-the-future-of-mmog-development-part-2/

Evolve Your Hierarchyhttp://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/