game engine architecture game engine architecture spring
play

Game Engine Architecture Game Engine Architecture Spring 2017 - PDF document

Game Engine Architecture Game Engine Architecture Spring 2017 Spring 2017 03. Event systems for game engines 03. Event systems for game engines 03. Event systems for game engines 03. Event systems for game engines Juha Vihavainen Juha


  1. Game Engine Architecture Game Engine Architecture Spring 2017 Spring 2017 03. Event systems for game engines 03. Event systems for game engines 03. Event systems for game engines 03. Event systems for game engines Juha Vihavainen Juha Vihavainen University of Helsinki University of Helsinki [ [ McShaffry McShaffry, Ch. 6: , Ch. 6: Game actors and component architecture Game actors and component architecture , Ch. 11: Ch. 11: Game event management Ch. 11: Game event management Ch. 11: Game event management ] Game event management ] [ Gregory, [ Gregory, Ch. 5.4: Ch. 5.4: Strings, unique ids Strings, unique ids , localization localization , , etc., 274, etc., 274, Ch.15.2: Ch.15.2: Runtime object model architectures Runtime object model architectures , 873 , 873 Ch. 15.7: Ch. 15.7: Events and message passing, 933 Events and message passing, 933 ] [Meyers (2015): [Meyers (2015): Effective Modern C Effective Modern C ++ ++] Lecture outline Lecture outline � On events and event handling On events and event handling � using Observer using Observer Observer (MVC) and Observer (MVC) and (MVC) and Command (MVC) and Command Command design patterns Command design patterns � using using design patterns design patterns � � Updates Updates are not enough for game software are not enough for game software � � Typed Typed Message Message design pattern (Vlissides, 1997) design pattern (Vlissides, 1997) � � breaking dependencies between senders & receivers breaking dependencies between senders & receivers � � Queueing of messages for later delivery Queueing of messages for later delivery Queueing of messages for later delivery Queueing of messages for later delivery � Using unique object ids object ids for game entities and types � Using unique for game entities and types � 24.2.2017 24.2.2017 Juha Vihavainen / University of Helsinki Juha Vihavainen / University of Helsinki 2

  2. The Observer Observer design pattern The design pattern � Problem Problem � � certain objects need to be informed about the changes occurring certain objects need to be informed about the changes occurring � in in other objects other objects a subject a subject subject has to be observed by one or subject has to be observed by one or more observers more observers observers observers � a a has to be observed by one or more has to be observed by one or more � � decouple as much as possible decouple as much as possible and reduce and reduce the dependencies the dependencies � � Solution Solution � � define a one define a one-to to-many dependency between objects so that when many dependency between objects so that when � one object one object changes its state changes its state, all its dependents , all its dependents are automatically are automatically notified and updated notified and updated A cornerstone of the Model Model-View View-Controller Controller architectural design, � A cornerstone of the architectural design, � where the Model implements the mechanics of the program, and the where the Model implements the mechanics of the program, and the Views are implemented as Observers that are kept uncoupled from Views are implemented as Observers that are kept uncoupled from the the Model components Model components Modified from Joey Paquet, 2007 Modified from Joey Paquet, 2007-2014 2014 24.2.2017 24.2.2017 University of Helsinki University of Helsinki 3 Erich Gamma et al., Design Patterns ( 1994) Observer Observer pattern: class design pattern: class design "View "View View" classes View" classes classes classes "Model Model" classes classes Updates multiple Updates multiple ( seems ( seems observers on changes Notifies all its observers complicated..) 24.2.2017 24.2.2017 University of Helsinki University of Helsinki 4

  3. The participants The participants � Subject Subject - abstract class defining the operations for attaching and de abstract class defining the operations for attaching and de- � as " Observable Observable " attaching observers to the client attaching observers to the client; often ; often referred to referred to as " � ConcreteSubject ConcreteSubject - concrete Subject class. ConcreteSubject - concrete Subject class. ConcreteSubject concrete Subject class. It maintains concrete Subject class. It maintains It maintains the state of It maintains the state of the state of the state of � the observed object and when a change in its state occurs it notifies the observed object and when a change in its state occurs it notifies the attached Observers. If used as part of MVC, the the attached Observers. If used as part of MVC, the ConcreteSubject ConcreteSubject classes are the Model classes that have Views attached classes are the Model classes that have Views attached to them to them � Observer Observer - interface or abstract class defining the operations to be interface or abstract class defining the operations to be � used to notify the registered used to notify the registered Observer objects Observer objects � ConcreteObserver � ConcreteObserver ConcreteObserver - concrete observer ConcreteObserver - concrete observer concrete observer subclasses that are attached concrete observer subclasses that are attached subclasses that are attached subclasses that are attached � � to a to a particular subject class particular subject class � There There may may be multiple different be multiple different concrete observers attached to a concrete observers attached to a � single subject single subject that will provide a different view of that will provide a different view of that subject that subject 24.2.2017 24.2.2017 University of Helsinki University of Helsinki 5 On behaviour of Observer pattern On behaviour of Observer pattern client class instantiates the ConcreteObservable ConcreteObservable object � The The client class instantiates the object � � Then Then it instantiates and attaches the concrete observers to it using it instantiates and attaches the concrete observers to it using � the methods defined in the Observable the methods defined in the Observable Observable interface Observable interface the methods defined in the the methods defined in the interface interface � Each Each time the (observable) state of the subject is changing, it time the (observable) state of the subject is changing, it � notifies all the attached observers using the methods defined in notifies all the attached observers using the methods defined in the Observer Observer interface the interface a new Observer Observer is added to the application, all we need to � When When a new is added to the application, all we need to � do is to instantiate it in the client class and do is to instantiate it in the client class and to attach do is to instantiate it in the client class and do is to instantiate it in the client class and to attach to attach it to the to attach it to the it to the it to the Observable Observable object object � The The classes already classes already created (framework) will created (framework) will remain mostly remain mostly � unchanged unchanged 24.2.2017 24.2.2017 University of Helsinki University of Helsinki 6

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend