FIT CTU

Adam Vesecký

vesecky.adam@gmail.com

Lecture 3

Assets

Architecture of Computer Games

Adam Vesecký

Introduction to Assets

What are assets?

Everything that is specific to a game (and not to an engine).

Any piece of data which is in a format that can be used by the game engine.

All visual elements that are presented to the user and protected by copyright.

What are assets

  • many games are very similar in their mechanics, yet the assets are different
Super Mario

Super Mario (1985)

Dangerous Dave

Dangerous Dave (1988)

What are assets

Trolls

Trolls (1992)

Oscar

Oscar (1993)

World of Warcraft

World of Warcraft (2004)

Order and Chaos 2

Order and Chaos 2 (2015)

Assets

Binary assets

Binary data

Bytecode assets

Bytecode

Text assets

Text files

Hybrid assets

Hybrid files

Assets
Assets diagram

Medias

NES cartridge
NES cartridge
8kB - 1MB
Super Mario
GameBoy cartridge
Game Boy cartridge
256 kB - 8 MB
Pokémon Yellow
Floppy disk
Floppy Disk
1.44 MB
Duke Nukem 1
Compact Disk
CD
700 MB
Half-Life
DVD disk
DVD
4.7 GB - 8.5 GB
GTA San Andreas
Bluray disk
Blu-ray
25 GB - 50 GB
Witcher 3
HDD
HDD
¯\_(ツ)_/¯
Call of Duty: Warzone
Super Mario took less space than the actual screenshot of it!

Size of game assets

Assets size in games
And where is Call of Duty 4?

Asset Types

Sounds

  • AIFF, WAV, MP3, OGG

Images

  • PNG, JPG, TGA, SVG

Video

  • MP4, MKV, AVI, MOV, MPG, WEBM

3D Models

  • OBJ, FBX, BLEND, DAE, 3DS, X3D

Game Data

  • ZIP, XML, JSON, INI, CFG, SQLITE,...

Levels

  • CAS, DAT, RPF, TIGER, WAD

Fonts

  • OTF, TTF, WOFF

Scripts

  • JS, LUA, PY, CS
HEX data

Assets management

Game Resources

Resource Manager

Resource Manager

Provides access to all resources (~assets)
  • meshes, materials, shaders, animations, textures, clips, levels
  • many assets are not used in their original format
  • Resource Cache - used for faster access
Manages lifetime of each resource
  • most managers maintain some kind of registry
Ensures that only one copy of each resource exists in memory
  • resource GUID - usually path to the file, guaranteed to be unique
Loads required resources and unloads those no longer needed
  • loading is simpler than unloading
Handles streaming
  • in case of open worlds

Example: Godot Engine Resource Loader

1 RES ResourceLoader::_load(const String &p_path, const String &p_original_path,
2 const String &p_type_hint, bool p_no_cache, Error *r_error, bool p_use_sub_threads,
3 float *r_progress) {
4 bool found = false;
5
6 // Try all loaders and pick the first match for the type hint
7 for (int i = 0; i < loader_count; i++) {
8 if (!loader[i]->recognize_path(p_path, p_type_hint)) {
9 continue;
10 }
11 found = true;
12 RES res = loader[i]->load(p_path, p_original_path != String() ?
13 p_original_path : p_path, r_error, p_use_sub_threads, r_progress, p_no_cache);
14 if (res.is_null()) {
15 continue;
16 }
17
18 return res;
19 }
20
21 ERR_FAIL_COND_V_MSG(found, RES(), vformat("Failed loading resource: %s.", p_path));
22 }

Example: Godot Engine Resource Cache

1 HashMap<String, Resource *> ResourceCache::resources;
2
3 Resource *ResourceCache::get(const String &p_path) {
4 lock->read_lock();
5
6 Resource **res = resources.getptr(p_path);
7
8 lock->read_unlock();
9
10 if (!res) {
11 return nullptr;
12 }
13
14 return *res;
15 }
16

Multimedia assets

Music Formats

AIFF

  • Audio Interchange File Format
  • uncompressed pulse-code modulation
  • may contain loops and samples

MP3

  • MPEG-1 Audio Layer III
  • lossy data-compression

OGG

  • more advanced and a bit smaller in size than MP3
  • open-source (in sharp contrast with MP3)

WAV

  • linear pulse-code modulation
  • used when time involved in compressing is a concern (short sounds)

Trackers

  • will be discussed in next lectures
Music assets

MP3

  • lossy format
  • reduces accuracy by psychoacoustic analysis
MP3 formats

Image Formats

JPEG

  • Joint Photographic Experts Group
  • used for storing digital photography
  • doesn't support alpha channel

PNG

  • Portable Network Graphics
  • good results for simple images (not real pictures)

TGA

  • Truevision TGA
  • favorite format for textures

SVG

  • Scalable Vector Graphics
  • format for vector images
JPG image
PNG image
SVG image

JPEG

  • lossy compression for digital images
  • note very good for pixel art or masking (compression noise)
  • Stages
    • Color Transform - RGB to YCbCr
    • Down-sampling - chroma reduction
    • DCT - discrete cosine transform, from color domain into frequency domain
    • Quantization - removal of high-frequency components
JPEG format diagram
DCT grid

PNG

  • lossless compression
  • appropriate for solid-color images
  • if there is no reason to do otherwise, use PNG for image assets
  • DEFLATE algorithm, supports alpha channel
  • Stages
    • Indexing - creates a palette if only up to 256 colors are present
    • Alpha compaction - optimizing - replaces the alpha channel with a color that is not present
    • Pass extraction - splits an image into a few interlaced images
PNG format diagram

Videos and Cutscenes

  • Cutscene
    • one of the most progressive properties of a game
    • a) fully progressive - video, in-game cutscene
    • b) partially progressive - i.e. custom skin of the avatar in the scene
    • c) partially emergent - the player can walk around but can't control the scene
    • d) fully emergent - generated cutscene
  • 1980's - in-game cutscenes
  • 1990's - pre-rendered video cutscenes
  • 2000's - in-game cutscenes
  • 2010's - pre-rendered video cutscenes ¯\_(ツ)_/¯
Warcraft cutsceneHellblade cutscene

Videos and Cutscenes

Tomb Raider cutscene

Shadow of the Tomb Raider, in-game

Wolfenstein New Collosus cutscene

Wolfenstein 2: New Colossus, video

Warcraft cutscene

Warcraft 3, in-game

Warcraft reforged cutscene

Warcraft 3 Reforged, video

meme ifonly

Textures

  • pieces of bitmap that are applied to an object
  • textures are ultimately converted to formats that are specific to platform and graphic API

Types

  • diffuse texture
  • displacement texture
  • normal texture
  • volumetric texture
  • tileable texture
  • sprite atlas

Formats

  • Desktop: BC6H, BC7, DXT1, DXT5
  • iOS: ATSC, PVRTC
  • Android: ASTC
Color texture

Diffuse

Displacement texture

Displacement

Normal texture

Normal

Volumetric texture

Volumetric

Tileable texture

Tileable

Sprite animation

Sprite atlas

Sprites

Sprite

  • a single graphic image that is incorporated into a scene
  • allows to create large scenes as you can manipulate each sprite separately

Spritesheet

  • a set of corresponding sprites

Sprite atlas

  • a single texture image containing a list of spritesheets
Prince of Persia sprites

3D Objects

3D ship example

3D File Formats

  • encode 3D geometry, material, textures, animations,...
  • geometry encoding - approximate mesh, precise mesh and constructive solid geometry (CSG)
  • BLEND - internal blender file, supported by many engines
  • COLLADA - .DAE, sharing models across CAD software
  • X3D - popular format for WEB
Appr. meshPrec. meshCSGColorMaterialTextureCameraLights
STL
OBJ
FBX
DAE
3DS
STEP
X3D
BLEND

Generic Assets

ZIP

  • many games use their own proprietary format derived from ZIP

ZIP

  • lossless archive format
  • compressions: shrink, DEFLATE, bzip2, none
  • directory-like structure

zlib

  • open-source library
  • implements DEFLATE compression

Game Data

Serialized data

  • XML, JSON, CSV, CFG,...
  • it's good to use XML for tree-like structures and JSON for flat entities
  • some languages (such as C++) don't provide a standardized serialization facility
  • JSON is a good fit for JavaScript as it is it's natural object notation

Database

  • Web environment: Web storage (small data), IndexedDB (large data)
  • Desktop/mobile: SQLite
  • Games that don't have multiplayer rarely need more than a simple database for config and save data

Save data

  • dump of all the parts of the game engine required to restore the full state
  • size varies, for most games it's usually a few MBs

Web Storage

Local Storage

  • for data of smaller size (config, game state)
  • up to 10MBs, no expiration time
  • keys and values are strings
1 let myStorage = window.localStorage;
2
3 myStorage.setItem('player_state', player.stateId);
4 myStorage.removeItem('player_state');
5 myStorage.clear();

IndexedDB

  • JS-based object-oriented DB
  • low-level API for structured data
1 await db.players.add({
2 name: 'Warrior',
3 avatar: await getBlob('sprite_warrior.png'),
4 key_mapping: 'default'
5 });
1 {
2 "player": {
3 "difficulty": "hard",
4 "scene": "mountains_02",
5 "posX" : 12,
6 "posY" : 56,
7 "inventory" : ["flashlight, lighter, candle"],
8 "stamina": 45,
9 "agility": 12
10 }
11 }

Example: OpenTTD Save format

OpenTTD save format
  • 3 data layers
  • very complex
Transport Tycoon Deluxe

Example: DOOM Save format

  • DSG files
  • the game loads the level and restores the state by going through its aspects
  • virtually nullifies the feasibility of manual hacking except the player data
  • Aspects:
    • doors, switches, elevators, stairs, lights
    • items picked/available
    • projectiles, teleport, respawn
    • animation, damage
    • linedefs seen on automap
    • items/kills gained counter
1 // p_saveg.c::P_UnArchiveThinkers
2 while (1) {
3 tclass = *save_p++;
4 switch (tclass) {
5 case tc_mobj:
6 PADSAVEP();
7 mobj = Z_Malloc (sizeof(*mobj), PU_LEVEL, NULL);
8 memcpy (mobj, save_p, sizeof(*mobj));
9 save_p += sizeof(*mobj);
10 mobj->state = &states[(int)mobj->state];
11 mobj->target = NULL;
12 if (mobj->player) {
13 mobj->player = &players[(int)mobj->player-1];
14 mobj->player->mo = mobj;
15 }
16 P_SetThingPosition (mobj);
17 mobj->info = &mobjinfo[mobj->type];
18 P_AddThinker (&mobj->thinker);

Levels, Maps, Dialogues

  • mostly proprietary formats of respective libraries/frameworks
  • TMX Maps
    • tile map XML format for 2D games
    • layers, properties, objects, animations, terrains, wangsets
  • Popular tools for Unity
    • Chat Mapper - tool for writing nonlinear dialogue
      • branching trees
      • barks and alerts
      • QTE
      • localization
      • optional scripting
    • Articy Draft - visual database of characters, storylines and game variables
    • Quest Machine - extensible quest system
Tileset

Example: DOOM WAD file

  • "Where's All the Data"
  • Binary format of package files for Doom
    • Levels (walls, floors, monsters)
    • Sound effects, music
    • Color palettes, images
  • Designed by John D. Carmack
Doom Map
Doom WAD format

Tilemaps

  • several layers - 1st-layer tiles, sprites, 2nd-layer tiles, background (for parallax scrolling)
  • Tile - the smallest element on a map
  • Wang - a set of tiles that make a unified whole (e.g. a building)
Zelda tilemap

Zelda (2004)

The Messenger screenshot

The Messenger (2018)

The Messenger tiles

Lecture Summary

  • I know what game assets are
  • I know the purpose of a Resource manager
  • I know the difference between the use-cases of WAV and MP3/OGG formats
  • I know the difference between PNG and JPEG formats
  • I know what a cutscene is
  • I know what a sprite is
  • I know the types of textures
  • I know what a tilemap is

Goodbye Quote

Hope is what makes us strong. It is why we are here. It is what we fight with when all else is lost.God of War