1 / 28

component based programming

component based programming. Sajad Beigjani sajad.b@gmail.com seganx.com cpp studio. topics :. notes structure / function class hierarchy data hierarchy function hierarchy component function driven component data driven component component management

arwen
Télécharger la présentation

component based programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. component based programming SajadBeigjani sajad.b@gmail.com seganx.com cpp studio

  2. topics : notes structure / function class hierarchy data hierarchy function hierarchy component function driven component data driven component component management communication between components messaging registry table Components every where ?

  3. notes • use memory manager • to show you memory leaks • use call stack system • to show you where your code crashed • free memory before use it • we are humans and humans forget to free allocated memory • every where you allocate a memory block, find a place to free it before using that

  4. notes • some things we should beware of • use some huge data as function parameters • structure • class • array • pass some huge data out from function • return structure • return class • return array • return allocated memory

  5. structure / function define objects as structure ( a pattern for memory ) write functions to operate on memory

  6. class same as structure specific functions constructor destructor member scope

  7. hierarchy http://library.thinkquest.org/C0120962/java/section3/ extend data ( data hierarchy ) override functions ( function hierarchy )

  8. data hierarchy paste structures consecutively

  9. function hierarchy • member functions have __thiscall conventions • these functions have ‘this’ pointer • virtual member functions are just pointer to functions • table of virtual function • table filled at calling constructor

  10. component components are everywhere each Atari film is a component each program in OS is a component

  11. component • we can make a software system while some data and or processes are placed into separated components • first became prominent with ‘Douglas McIlroy’ • 1968, “Mass Produced Software Components” • components are substitutable • replace component at runtime • components can contain huge data • design minimal objects • less programming, more variation of objects • design different objects by attaching different components

  12. component • software components • application services, web services • object components • attached in/to the other applications • component communicate with application via interface • interface !?

  13. component • interface can be an string as a message • browsers, web services, … • interface is a class or structure with some sort of virtual functions or pointer to functions

  14. function driven component component has no additional data replace component means changing functions functions process data on application

  15. data driven component component has additional data replace component means changing functions functions process own data and application data smaller objects more complexity

  16. component management • objects has a list of components attached to • easy to implement • CPU enemy • object has a list of components ID • components placed in the manager • application updates all components • more complexity • CPU friendly

  17. component management • use prefab component library • name , type name , type .. • each component have serialization functions • Component::Save( Stream* stream ); • Component::Load( Stream* stream ); • save components at saving object • write number of components • for each component write it’s type • call Component::Save(…) function • load components at loading object • read number of components • in the loop, read type of component • create component from prefab library • call Component::Load(…) function

  18. communication between components • what kind of communications ? • notify to a component that some things happen • call a functions of a component • read or write some values of a component • where is the solutions ? • search through components and find what we want • message processing • registry table

  19. messaging • messages are the part of the event based architecture system • easy to handle performance penalties • no need to know the type of object • just using interfaces • no need to know component exist or not • set/get values by message • get pointers from objects by message • call a function • notify to the another • broadcasting • just say to an object “fire to him” • say to allies “oh ! leave me alone! I’m goanna die!”

  20. messaging can be string null or pointer to anything Do you have any weapon ? if yes, please fill this form :D Your Type : …………….. Your Health : ……………. Your Speed : ……………… Pointer to weapon : …………. Thank you for your patient Mr. Killer agent 1 agent 2 • what is a message ? • unique integer code • additional data

  21. message data • message data can be an structure • data can contain some conditional rules • ignore processing by the others • choose the specified object among the others • call a function • client can read/write from/to message data

  22. process message • Object processes the message and then gives the message to his components • who process the message first ? • set a priority for components • sorting components by priority • place flags ( conditions ) in data

  23. process message editor message data can be an structure client can read from message data client can write to message data

  24. registry table • messaging is a simple event driven architectures • messaging system is not good for use in game loop • traversing a message through all components is time consuming for real time applications registry table is a simple solution for keep components communication alive in real time • registry table is safe • it is fast enough to use in game loop • no need to connect components directly to each other • no need to know the type of other components • components use the table to share variables and objects • avoid messaging in game loop

  25. registry table Object registry table key , pointer … … … • components use the table to share variables and objects • components register variables when they attached • components search for variables when they initialized component On Attach ( …. On Initialize ( …. component On Attach ( …. On Initialize ( …. • contain a unique Key and a pointer • key can be a code which generated by CRC … • key can be an string as name • in addition can contain a reference counter • components use the table to share variables and objects • components register variables when they attached • components search for variables when they initialized

  26. components every where ? • using components is the best programming pattern ? • there is no best solution • every programming paradigm has pros and cons • depend on game or application, we should use different patterns for every parts • it depends on : • performance • game mechanics • game scale • world scale in game • number of active entities • ...

  27. Question ?

  28. Thank you

More Related