Games Development 2 Overview & Entity IDs and Communication CO3301 Week 1.

Slides:



Advertisements
Similar presentations
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Advertisements

Hash Tables and Sets Lecture 3. Sets A set is simply a collection of elements Unlike lists, elements are not ordered Very abstract, general concept with.
CSE 1302 Lecture 23 Hashing and Hash Tables Richard Gesick.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
The Assembly Language Level
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Topics in Programming Reactive Systems Prof. Ronen Brafman and Dr. Gera Weiss.
Searching Kruse and Ryba Ch and 9.6. Problem: Search We are given a list of records. Each record has an associated key. Give efficient algorithm.
CS 261 – Data Structures Hash Tables Part 1. Open Address Hashing.
Binary Heaps CSE 373 Data Structures Lecture 11. 2/5/03Binary Heaps - Lecture 112 Readings Reading ›Sections
VBA Modules, Functions, Variables, and Constants
1 Chapter 9 Maps and Dictionaries. 2 A basic problem We have to store some records and perform the following: add new record add new record delete record.
hashing1 Hashing It’s not just for breakfast anymore!
Sets and Maps Chapter 9. Chapter 9: Sets and Maps2 Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn about.
Hashing General idea: Get a large array
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Chapter 3: Arrays, Linked Lists, and Recursion
Games Development 2 Entity / Architecture Review CO3301 Week
CHP - 9 File Structures. INTRODUCTION In some of the previous chapters, we have discussed representations of and operations on data structures. These.
Games Development 2 Resource Management CO3301 Week 3.
Hashing CS 105. Hashing Slide 2 Hashing - Introduction In a dictionary, if it can be arranged such that the key is also the index to the array that stores.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
Lecture 10: Class Review Dr John Levine Algorithms and Complexity March 13th 2006.
Brought to you by Max (ICQ: TEL: ) February 5, 2005 Advanced Data Structures Introduction.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
Chapter 11 Heap. Overview ● The heap is a special type of binary tree. ● It may be used either as a priority queue or as a tool for sorting.
Summer Computing Workshop. Introduction  Boolean Expressions – In programming, a Boolean expression is an expression that is either true or false. In.
1 Symbol Tables The symbol table contains information about –variables –functions –class names –type names –temporary variables –etc.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Games Development 2 Component-Based Entities
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
Lecture 6 : Intro. to Generic Programming Acknowledgement : courtesy of Prof. Dekai Wu lecture slides.
P p Chapter 11 discusses several ways of storing information in an array, and later searching for the information. p p Hash tables are a common approach.
Games Development 2 Review & Revision Strategy CO3301 End of Semester 1.
Exceptions, cont’d. Factory Design Pattern COMP 401 Fall 2014 Lecture 12 9/30/2014.
CS201: Data Structures and Discrete Mathematics I Hash Table.
CS 206 Introduction to Computer Science II 11 / 16 / 2009 Instructor: Michael Eckmann.
Chapter 10 Hashing. The search time of each algorithm depend on the number n of elements of the collection S of the data. A searching technique called.
Chapter 11 Hash Tables © John Urrutia 2014, All Rights Reserved1.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Games Development Game Architecture: Entities CO2301 Games Development 1 Week 22.
Games Development 2 Entity Update & Rendering CO3301 Week 2, Part 1.
CE Operating Systems Lecture 17 File systems – interface and implementation.
Hash Table March COP 3502, UCF 1. Outline Hash Table: – Motivation – Direct Access Table – Hash Table Solutions for Collision Problem: – Open.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Hashing CS 110: Data Structures and Algorithms First Semester,
Hashing Suppose we want to search for a data item in a huge data record tables How long will it take? – It depends on the data structure – (unsorted) linked.
Games Development 1 Review / Revision CO2301 Games Development 1 Semester 2.
Lecture 10 Page 1 CS 111 Summer 2013 File Systems Control Structures A file is a named collection of information Primary roles of file system: – To store.
Hash Tables © Rick Mercer.  Outline  Discuss what a hash method does  translates a string key into an integer  Discuss a few strategies for implementing.
Hashing COMP171. Hashing 2 Hashing … * Again, a (dynamic) set of elements in which we do ‘search’, ‘insert’, and ‘delete’ n Linear ones: lists, stacks,
Advanced Data Structure By Kayman 21 Jan Outline Review of some data structures Array Linked List Sorted Array New stuff 3 of the most important.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
1 Resolving Collision Although collisions should be avoided as much as possible, they are inevitable Need a strategy for resolving collisions. We look.
TOPIC 5 ASSIGNMENT SORTING, HASH TABLES & LINKED LISTS Yerusha Nuh & Ivan Yu.
Lecture 5 Page 1 CS 111 Summer 2013 Bounded Buffers A higher level abstraction than shared domains or simple messages But not quite as high level as RPC.
©2004 Joel Jones 1 CS 403: Programming Languages Lecture 3 Fall 2004 Department of Computer Science University of Alabama Joel Jones.
CSC 212 – Data Structures Lecture 28: More Hash and Dictionaries.
Games Development 2 semester 1 Review & Revision
CO Games Development 2 Week 19 Extensions to Finite State Machines
Advanced Associative Structures
Hash Table.
Hash Tables Chapter 12 discusses several ways of storing information in an array, and later searching for the information. Hash tables are a common.
Hash Tables Chapter 12 discusses several ways of storing information in an array, and later searching for the information. Hash tables are a common.
Games Development Game Architecture: Entities
Games Development 1 Review / Revision
CO4301 – Advanced Games Development Week 12 Using Trees
Games Development 2 Entity / Architecture Review
Presentation transcript:

Games Development 2 Overview & Entity IDs and Communication CO3301 Week 1

Module Overview Two parts: –Semester 1 with me: Various Game and Entity Architecture topics Plus any requests(?) –Semester 2 with Gareth: Various Real-Time AI topics Some topics will be extended in Tech for Games 1 Assignment on my material Two 2-hour exams, one at end of each semester

Today’s Lecture 1.Entities Recap 2.Referencing Entities 3.Use of Entity Pointers 4.Entity UIDs / Handles Hash Maps 5.Entity Messaging System

Entities Recap Entity = interactive self-contained game element Each type of entity has a generic template Each instance has some specific data: Character 1 ID Position / Rotation Hit Points Character 2 ID Position / Rotation Hit Points Character Template Mesh Animations Max Hit Points Script This instance/template pair for an entity replaces the model classes that we have previously used Also corresponds to a game agent from AI work

Entities Recap Entities can be held centrally in a list –To easily add/remove them and for overall control Most games will need to store entities in other data structures as well: –E.g. in a map grid for an RTS –Or an BSP tree for a FPS Entities need to be updated periodically –For AI, movement etc. But not all entities need to be updated simultaneously –A priority queue can be used to order updates –Nearby entities at front of queue, distant/inactive at end

Entity IDs and Communication Entities need to communicate with each other –“I have hit you” –“I have picked you up” –“What is your HP”, etc. To do so they need to be able to identify the other entities: –But how? By name? pointer? ID? Also they need to have a means of interaction: –Direct member data access? function calls? messages? These are related issues We will look at some of the possible approaches

Use of Entity Pointers Very tempting to have entities to hold pointers to each other and use these for communication and interaction: –A character drops a mine –The mine entity retains a pointer to the character entity –A vehicle drives over the mine and is damaged –The mine uses the character pointer to award some score Sounds OK, but problems when entities are destroyed: –What if the character has died, or left the area? –The pointer is invalid (unless we track all ex-entities) –Could cause exception (or worse…) –Variants on this situation occur frequently Need something more robust than pointers…

UIDs A UID (Unique IDentifier) or handle is a value that uniquely identifies some resource –Can be used for any kind of resource Hold UIDs instead of pointers whenever possible Use a function to safely convert a UID into a pointer to the associated resource –When we need to interact with the resource Exactly how the function maps UIDs to resources is implementation dependent It just returns an error if the resource doesn’t exist –Game can respond to the missing entity sensibly –Removing the problem of invalid pointers

How to Map UIDs to Entities? Store pointers to all entities in an array or container Maybe UIDs could be indexes into this array? –If array[N] = 0 then entity N doesn’t exist But would need an entry for every entity that ever existed –Not likely to be possible (might be in simple cases) Couldn’t we reuse empty array indexes? –But if we have an entity UID 35, and array index 35 contains an entity pointer… –…how would we know if this is the entity 35 we want or a new one reusing that entry? Need a more robust solution

Hash Tables A hash table or hash map associates each of a set of keys with a specific value –The keys & values are data of any type E.g. A hash table might associate names (the keys) with telephone numbers (the values): The goal of a hash table is to provide efficient lookup of a value given a key Even if the keys are complex types

Hash Tables To efficiently perform the mapping, we provide a hash function to convert keys into integers –Used to look up the values (in an array or container) An ideal function gives a unique index for each key –This is rarely easy or efficient and most functions have collisions – same index for different keys

Hash Tables There are several general functions to efficiently convert a block of arbitrary data to a single integer –Usually creating some collisions Resolve the collisions by storing a bucket of key/value pairs for each index –Given a bucket, we search for value matches our key

Hash Tables for UIDs We make the UIDs globally unique integers –Initialise a global integer – when we add a new entity, use this integer as its UID –Increase the global integer for each entity –This process can be encapsulated by an entity manager class to avoid the use of actual global variables Use static class member variables instead Use a hash table to map the UID an entity pointer The hash function can be very simple: –Index = UID%ArraySize; will work, but many collisions –Index = RandomiseFn(UID)%ArraySize; is better Resolves the problems of using a simple array

Entity Interaction Now we have UIDs to safely get entity pointers, should we use them for entity-entity interaction? Certainly we won’t have entity objects accessing each other’s private data –A health pack isn’t going do this: character->HP += 10; However, using entity member functions seems OK: Entity* character = EntityManager->GetEntity(charID); character->IncreaseHP( 10 ); But this means each entity class will need to know all the available functions of the other entity classes –Too close coupling, difficult to maintain code Also such interaction is processed immediately –We may wish to manage the timing differently

Entity Messaging More flexible to use a messaging system If one entity wishes to interact with another: –Send a message to the UID of the other entity –The system has a messenger class, which collects, queues and sends message between entities It works with UIDs (no need for entities to use pointers) Can also hand messages to groups, broadcast messages, system messages etc. –The entity receiving the message can act on it or ignore Entities only need to know the message types –Coupling is kept to a minimum Can make some interaction more complex –E.g. If there is a need for a reply message etc.

Example Messaging Sequence Two tanks, UID 5 (leader) and 11: –Leader: SendMsg(11,"Status Report"); Assume Tank 11 receives message –Tank 11: SendMsg(5,"HP=100,Idle"); –Tank 5: SendMsg(11,"SupportMe"); Tank 11 follows order, until a shell hits it: –Shell 58: SendMsg(11,"Damage=500"); Later… –Tank 5: SendMsg(11,"Retreat"); Ignored, second tank is dead Would use variables, not constants, for UIDs, e.g. –SendMsg(Leader,"Status Report"); // Leader = 11

Message Types System messenger class is fairly trivial to implement –But it must be efficient – will be many messages The data type for the messages is important –Simple system – one data type holds all possible messages Message ID (type) + generic data –More complex – a class hierarchy of message types More flexible, less efficient In any case, message code may need optimisation –Minimise message copying (reference parameters etc) –Avoid new and delete (use static containers)

In Practice Using messages for all entity entity interaction can be cumbersome –The examples above show where they work well –But, for example, finding the position of another entity is clumsy using messages –Also they introduce latency waiting for responses Possible solutions: –Entity UIDs can be converted to pointers to access generic or commonly used data, position, velocity, etc. –Implement an ImmediateMessage function Message sent directly to the entity, return value is response Many of the same benefits as messaging Target entity response limited since it is not in its update function