Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Component Architecture in Computer Games

Component Architecture in Computer Games

Introduction to the component architecture mainly used in computer games development.

Avatar for Adam Vesecký

Adam Vesecký

April 19, 2018

Other Decks in Programming

Transcript

  1. SINNERSCHRADER • Game Development: Brief History • Game Architecture: OO

    Approach • Game Architecture: Component Approach • Examples Agenda 2
  2. SINNERSCHRADER move_paddle ;read input from joystick lda joystick2;joy port 2

    and #8 ;right beq move_paddle_right lda joystick2 and #4 ;#left beq move_paddle_left rts check_ball_paddle_collision lda sprite_collision and #2 cmp #2 beq ball_paddle_collision rts ball_paddle_collision lda sprite_collision and #2 sta sprite_collision ;clear collision bit jsr set_ball_direction_up rts 1986 BREAKOUT 6
  3. SINNERSCHRADER 7 1993 DOOM bool P_CheckMissileRange (mobj_t* actor) { if

    (!P_CheckSight(actor, actor->target)) return false; // can’t see the target if (actor->reactiontime) return false; // do not attack yet dist = P_AproxDistance (actor, target) - 64*FRACUNIT; // no melee attack, so fire more if (!actor->info->meleestate) dist-=128*FRACUNIT; // check for ARCH-VILE if (actor->type == MT_VILE){ if (dist > 14*64) return false; // too far away } ...
  4. SINNERSCHRADER 8 2017: Platformer 2D void OnTriggerEnter2D (Collider2D other) {

    // If the player enters the trigger zone... if(other.tag == "Player") { // Get a reference to the player health script. PlayerHealth playerHealth = other.GetComponent<PlayerHealth>(); playerHealth.health += healthBonus; // Trigger a new delivery. pickupSpawner.StartCoroutine( pickupSpawner.DeliverPickup()); // Destroy the crate. Destroy(transform.root.gameObject); } }
  5. SINNERSCHRADER OO Approach 14 • simple • fast prototyping from

    scratch • low overhead • easy to debug • hard to maintain • hard to scale • not flexible • game objects may have features they don‘t need
  6. SINNERSCHRADER Component 16 • Specified interfaces and explicit context dependencies

    • components are basically plug-and-play for objects • prefers composition over inheritance
  7. SINNERSCHRADER • game object is just a container for data

    and logic • components communicate via messaging pattern Component Pattern 17
  8. SINNERSCHRADER Messages example 18 • Game object added • Game

    object removed • Animation ended • Dragon hit • Enemy died • Player revived • Spell cast • Level completed • Game over
  9. SINNERSCHRADER Conclusion 19 The overall behavior of a particular game

    object is determined by the aggregation of its components (and attributes).
  10. SINNERSCHRADER Game Architecture 20 Every dynamic game must have an

    update loop and a scene. Game architecture is usually tightly coupled with a Scene Graph. 20
  11. SINNERSCHRADER Component example 22 class RotationAnim extends Component { oninit()

    { this.subscribe("STOP"); } onmessage(msg) { if (msg.action == "STOP") { this.finish(); } } update(delta, absolute) { this.owner.trans.rotation += delta; } }
  12. SINNERSCHRADER Component Approach • scalable • data-oriented • easy to

    reuse components/behaviors • easy to make new object types • dynamic typing • all dependencies are to be linked together • hard to debug • messaging hell 32
  13. SINNERSCHRADER Component-Oriented engines 33 • Artemis Framework (Java) • https://github.com/junkdog/artemis-odb

    • Atomic Game Engine (C++, C#, JS) • https://atomicgameengine.com/ • Unity (C#) • https://unity3d.com/ • My prototypes (JS, C++) • http://github.com/dodolibs
  14. SINNERSCHRADER Questions? Tell uncle, if he gets a translator... ___________

    | _ =| . | [_] / | | / _________ .| |________/ + + __/ o o o o \ .||. ______ooo__ooo___________________|________|__|__|__________|__|[]|_ 34