Component-Entity-Systems

http://www.gamedev.net/page/resources/_/technical/game-programming/understanding-component-entity-systems-r3013

 

Normal OO:

 添加新的类有时候比较麻烦,已经定义好的类结构优势需要重构,可扩展性欠佳

 

Componet-entity-system里包括三个要素

  •  Component
    • 可复用的组件,没有任何逻辑,只有数据
  • Entity
    • 是Component的集合,也没有逻辑,只有一堆Component
    • Entity之间没有继承关系,它们通过加入不同的Component实现不同的功能
  • System
    • 里面只有逻辑,控制Entity里的Component

一些例子:

Component

  • Position (x, y)
  • Velocity (x, y)
  • Physics (body)
  • Sprite (images, animations)
  • Health (value)
  • Character (name, level)
  • Player (empty)

Entity

  • Rock (Position, Sprite)
  • Crate (Position, Sprite, Health)
  • Sign (Position, Sprite, Text)
  • Ball (Position, Velocity, Physics, Sprite)
  • Enemy (Position, Velocity, Sprite, Character, Input, AI)
  • Player (Position, Velocity, Sprite, Character, Input, Player)

System

  • Movement (Position, Velocity) - Adds velocity to position
  • Gravity (Velocity) - Accelerates velocity due to gravity
  • Render (Position, Sprite) - Draws sprites
  • PlayerControl (Input, Player) - Sets the player-controlled entity's input according to a controller
  • BotControl (Input, AI) - Sets a bot-controlled entity's input according to an AI agent

 


个人观点:这个component-entity-system有点太极端了,把逻辑内置到component以及entity里有点更符合OO的思想,就像UE3里那样

 

posted @ 2013-06-06 14:14  大兵八世  阅读(394)  评论(0)    收藏  举报