# component different programs need to be kept separate from each other, we don't want AI physics to render sounds, and so on, and so on, like this.// Badif(Collidingwithfloor () && (getrenderstate ()! =INVISIBLE)) {PlaySound (Hit_floor);} "An entity can be isolated across multiple domains, in different domains (componentclass), Entity==container of component (container of components) # # When-to-use1one object uses multiple functions, you want different functions to isolate each other2A class becomes very large and more and more difficult to use3just want to use a function of the base class, you need to make that feature into a build. You don't have to inherit it. ##### problem Building Communication Performance Lower # # # # #classgraphicscomponent{ Public: voidUpdate (bjorn& Bjorn, graphics&graphics) {Sprite* Sprite = &Spritestand_; if(Bjorn.velocity <0) {Sprite= &Spritewalkleft_; } Else if(Bjorn.velocity >0) {Sprite= &Spritewalkright_; } Graphics.draw (*Sprite, bjorn.x, BJORN.Y); }Private: Sprite spritestand_; Sprite Spritewalkleft_; Sprite Spritewalkright_;};classphysicscomponent{};classinputcomponent{}classPlayerinputcomponent: Publicinputcomponent {}classbjorn{ Public: intVelocity; intx, y; Bjorn (Inputcomponent* Input, Physicscomponent *phys, Graphicscomponent *graph): input_ (Input), Physics_ (Phys), Graphics_ (graph) {}voidUpdate (world& World, graphics&graphics) {Input_->update (* This); Physics_.update (* This, World); Graphics_.update (* This, graphics); }Private: Inputcomponent*Input_; Physicscomponent Physics_; Graphicscomponent Graphics_;}; Gameobject*Createbjorn () {return NewGameobject (Newplayerinputcomponent (),Newbjornphysicscomponent (),Newbjorngraphicscomponent ());} "' # # # How DoWhat is the communicate with each of the other?1by modifying the state of the container object (the container object is complex, the implementation of the state)2contains direct references (fast, but component instances are coupled)3By sending messages (complex, decoupled, container objects Simple)
14_ Component Game development Component mode