Databases
- Tables
- Organization
- One table similar to spreadsheet
- Power with many related tables
- Terms
- Columns = fields/attributes
- Rows = records
- Key = unique field per record
- Compound key = combination of fields guaranteed to be unique
- Compared to components
- Each table = entity or component
- Queries
- SQL = structured query language
- SELECT fields FROM table
- WHERE field meets condition
- JOIN table ON field = field
- UPDATE table SET ... WHERE ...
- DELETE ...
- INSERT ...
- Compiled vs. run-time queries
- Compare vs. noSQL
- Key/value most relevant (vs. document, graph, etc.)
- Normal forms
- Formalize & remove redundant / unnecessary data
- Make easier to do atomic updates
- Make easier to extend
- 1st normal form
- Dense tables
- Like components: add tables mapping ID to optional values
- No repeating columns
- Additional mapping table rather than list
- 2nd normal form
- No column dependent on a subset of the key
- So if key = full name, no column for first name
- 3rd normal form
- Attributes determined by keys, not other data in table
- e.g. HP and isDead: isDead iff HP=0
- also car model and manufacturer: model implies manufacturer
- Boyce-Codd Normal Form (BCNF)
- Remove "functional dependency"
- If can be derived by function, don't put in the database
- 4th normal form
- Remove multivalued dependencies
- Split tables rather than have product of entries (e.g. size x color)
- 5th normal form
- Split tables if combinations of attributes aren't allowed
- Orc weapon vs. human weapon example
- 6th normal form
- Consider temporal updates
- Split static from update
- Database advantages
- Data Persistence
- Data is already in a file
- Consistency guarantees
- Scalability
- Query optimization
- Ability to create indices to accelerate queries
- Database use
- Configuration data
- Easy to change/update
- Easy to access with external tools
- Internationalization
- String table per language, same keys, different data
- Language as part of key in table for all languages
- Maybe different asset tables too (limits on blood, guns, etc.)
- Game state
- Always saved
- Must put all state into database
- Multi-player
- Database holds shared state
- Local client (or database) for non-shared state
- Updates (esp. mobile games)
- Makes core game smaller
- Load just active subset of data
- Update on the fly (new items, new characters, new locations)
- Game update for database changes
- Game must be able to function with new unrecognized data
- Scalability
- Amazon & cloud popular
- Add servers as game/app popularity grows
- From Massively Multiplayer Game Development
- Data driven reduces cost of maintenance & updates
- Import sources
- Text files
- Spreadsheet
- XML
- Scripting language generated
- Indexing
- Index columns used in conditional requests
- Can drastically accelerate multi-column queries
- "all players that have hit points > 80, belong to a guild, and are not a member of a group"
- Slow down updates, so use carefully
- Performance
- Avoid joins for more than 2-3 tables
- Queue deletes (mark or put into a delete table to batch process)
- Database maintenance, including deferred updates, in off hours
- Cache data (in server process, in client)
- Track transaction loads to identify needed indices, caches
- Pool connections, opening & closing is expensive
- Caching concerns
- Predict on client based on cached state
- Position, direction, velocity, ...
- Update client to server reality
- Jump
- Pull on spring
- What about hit to miss or miss to hit?
- Update server to client reality
- Design uncertainty into client
- I see you in my crosshairs, you can't tell if you were or not
- Roll back events and replay according to new reality
- Multiple servers
- Login, character, object, guild, NPC, region
- Regions
- Size limit for load
- Limit visibility to < 1 tile
- Client needs to know about neighboring tiles
- Proxy objects in border
- Soft vs. hard borders
- Seamless
- Cluster for interaction
- Rebalance as needed
- Server may be more involved in updates