• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
  • entries
    20
  • comments
    2
  • views
    55877

Modular Component-Based AI Systems

Sign in to follow this  
Followers 0
ApochPiQ

2689 views

The GDC 2011 AI Summit opened up with three heavy-hitters from the AI world (Brett Laming, Joel McGinnis, and Alex Champandard) discussing the merits and motivations behind component-based architectures.

Although the term has gained popularity in recent years, and most people in the room expressed at least some familiarity with the concepts, there remains a substantial amount of uncertainty as to what exactly a component architecture entails. To address this, the lecturers presented an outline of how and why component architecture gained the spotlight in modern games engineering, and provided some tips and important rules on how to approach component-based designs.


Historical Trends
As object-oriented programming took hold and languages like C++ finally gained enough traction in the games industry to see widespread adoption, the typical design methodology involved creating rich, deep hierarchies of inter-derived classes. This quickly ran into issues such as multiple inheritance's "diamond problem," brittle structure, and questions of how to deal with "non-inheritance" situations (where some but not all functionality of a branch of the inheritance tree is desired in a particular leaf class).

One reaction to this was to push functionality towards the roots of the inheritance tree, essentially creating "fat base classes." This is even more problematic in a practical sense because bloat of code in the base classes decreases readability, clarity, and maintainability; simultaneously, bloat of data in the base classes led to immense memory wastage and overhead, which became thoroughly unacceptable as games grew in scale.

A more promising direction was to make the entire engine core highly light-weight and extremely data-driven, where virtually all of the behaviour and richness of the game simulation was accomplished in data rather than directly modeled in code. This approach still has its proponents, but suffers from a critical weakness: it lacks natural hooking points and specificity by which one can drill into the running simulation and inspect or modify its state. Put simply, offloading the complexity into data (away from code) deprives us of all the benefits of code-modeled introspection and manipulation.


Enter the Component Model
A central observation behind the introduction (and indeed the widespread adoption) of component-based architectures is that there are fundamentally four things in a simulation which need to be elegantly captured:

  1. Classification of entities (Is this a weapon? An item? A door? A sharp weapon? etc.)
  2. Key properties (How much damage does this weapon do? How much does it weigh? Which direction does the door open, and what key(s) does it require?)
  3. Defined mappings of inputs to outputs (Weapon damage values modify health values; keys modify door lock states; etc.)
  4. Interchangeability (Can I use this weapon in place of that one?)

Component architectures provide a modeling tool for all four areas; although other approaches can say the same, components provide a compact and highly elegant manner in which to reach these goals.

The main difference between the component mode of thought and older, less desirable approaches is the notion of systems. Indeed, it is worth noting that proper application of component architecture demands the use of systems richly; anything less will essentially collapse back into the same types of fat-architecture we were trying to escape in the first place. Moreover, in a systems-oriented model, granularity of functionality becomes desirable rather than problematic.

Systems are, fundamentally, the "glue" by which components are organized and compartmentalized. Moreover, systems formalize the interactions between components and other systems. This drives reusability in several key ways:

  • Inheritance can be used (sparingly!) to reuse logic and data relationships directly
  • The structure of interrelated components can be reused modularly
  • Data flow between components and systems can be interchanged as needed
  • Compartmentalization separates reusable elements into neat packages
  • As a bonus, parallelization can easily be accomplished between systems
    Careful use of class inheritance, along with factory methods, serialization, and run-time type information (RTTI) frameworks, can provide a highly data-driven model without sacrificing the specificity and hooks of a richer code model. In addition, the deployment of systems can help identify dependencies and functional structure within the simulation itself, allowing for easier maintenance and iteration on existing code.

    Another potential win of systems over gamegraphs and similar structures is the elimination of redundant searches. A system can keep track of all the components/entities which are relevant to that system directly, thereby avoiding the need to constantly traverse the game universe looking for those entities. This in turn provides a stark highlighting of the lifetime relationships between various entities, which can be a major advantage when it comes time to do dependency analysis on the simulation itself.

    Last but not least, components allow for late binding and re-binding of type information. Have a set of logic that relies on park benches, which suddenly needs to be rewritten to use dumpsters instead? The code change amounts to tweaking a single "tag" within the appropriate system, rather than making large numbers of tedious and fragile changes to raw code dependent on the actual "park bench" or "dumpster" classes. The data-driven aspects of component architectures become a major advantage in this sort of scenario.

    It is worth reinforcing the fact that component models are not "an architecture" but rather a paradigm in which architectures can be created. As with virtually everything in the engineering and architectural realms, the exact details will depend highly on the specific game or simulation we are setting out to make.


    Parallelization
    Component models can be a very powerful tool on modern platforms where concurrently-executing code is a central aspect of engine design. One important observation is that AI work (and indeed simulation work in general) essentially consists of reading and writing properties of entities in the simulation, and potentially rearranging the logical structure of those entities (moving objects, creating new NPCs, recycling old assets, etc.). Envisioning this as a sort of circuit diagram is a useful technique; data flows "down stream" between systems each frame. Any mutation of game state which can be passed down stream to later components can be accomplished using just the execution stack space, since later systems will always have access to that memory space safely. However, any "up stream" communication needs to be delayed by a frame by queuing a "message" which is read by the appropriate system in a subsequent tick. This decomposes nicely into a job/task system, which is a (deservedly) popular means of handling parallelism in modern engines.

    As with any other parallelization tasks, a few fundamental rules apply:

    • Minimize the volume of data propagated throughout the system
    • Further, minimize the lifetime of any data that does need to be passed around
    • When possible, derive data rather than duplicating it; no need to store mass, volume, and pressure when any two will suffice
    • Locality of reference is key; custom allocation is, as always, a major win here
    • NULL checks can be eliminated by using dummy non-operative objects instead of empty pointers
    • Propagate RTTI information along with pointers in order to avoid duplicate virtual-table lookups
    • Vectorize component update operations via SIMD instruction sets
    • Perform jobs in batches across cores (helps with cache/false sharing issues)
    • Interleaved allocation is a powerful tool for leveraging SIMD and other parallelization techniques

      Concluding Thoughts
      The session was a great way to open up the AI summit, cramming in vast amounts of valuable advice and information in the one time-slot when everyone's mind was guaranteed to not already be turned into jelly. Although not necessarily new details to many of those experienced with component architectures, there were plenty of nuggets to guide the decision-making process of both novice and veteran architects alike. An informal poll of the audience suggested that a substantial portion of those in attendance learned at least something valuable to take back to their own individual design efforts - the hallmark of a truly successful session.

3
Sign in to follow this  
Followers 0


0 Comments


There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now