GAME ENGINE
ARCHITECTURE
UNIT 12:
Prof. Dr. Eike Langbehn
Department of Media Technology
Faculty of Design, Media and Information
Hamburg University of Applied Sciences
EXAMPLES
UNIT 2:
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
1. INTRO
2. REQUIREMENT
ANALYSIS
3. GAME
DESIGN
0. ORGANIZATION
4. GETTING STARTED
WITH GODOT
5. USER
STUDIES
6. ANALYSIS OF
HUMAN FACTORS
7. INTERACTION
DESIGN
8. ADVANCED PROGRAMMING
WITH GODOT
9. EVALUATION
MODELS
10. MARKET
ANALYSIS
11. NARRATIVE
DESIGN
12. GAME ENGINE
ARCHITECTURE
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
Get problem
Learn code
Code solution
Clean up
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
Runtime Performance (Game’s Execution Speed)
(Short-term) Development Speed
(Long-term) Development Speed
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
"A game engine is a software development environment designed for people to build games."
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
Application Layer
Game Logic
Game View
Application Layer
Game Logic
Game View
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
Application Layer
Game Logic
Game View
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
Application Layer
Game Logic
Game View
Communication
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
Game Logic
Game View
Player_hit_brake
GameState_updated
ButtonA_pressed
Plays Sound Effect
Plays Visual Effect
Exactly the same for Human, AI, Remote, ...
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
Game Logic
Game View
Application Layer
Hardware
OS
Game Lifetime
Game View - AI Agent
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
public static void main()
{ //Start
Console.Write("I did something!");
} //end
public static void main()
{
while (running)
{
Event* event = waitForEvent();
dispatchEvent(event);
}
}
public static void main()
{
while(running)
{
processInput();
updateGameState();
output();
}
}
Initialization
Process Player Input
Perform Game Logic
(AI, Physics, World Simulation, etc.)
Render Scene, Play SFX, etc.
Shutdown
exit
Main Loop
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
public static void main() {
while
(running
)
{
processInput();
updateGameState();
output();
}void main() {
initGame();
while (true) { // game loop
readHumanInterfaceDevices();
if (quitButtonPressed())
break; // exit the game loop
movePaddles();
moveBall();
collideAndBounceBall();
if (ballImpactedSide(LEFT_PLAYER)) {
incremenentScore(RIGHT_PLAYER);
resetBall();
} else if (ballImpactedSide(RIGHT_PLAYER)) {
incrementScore(LEFT_PLAYER);
resetBall();
}
renderPlayfield();
}
}
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
public static void main()
{
while(running)
{
processInput();
updateGameState();
output();
}
}
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
public static void main()
{
while(running)
{
processInput();
updateGameState();
output();
}
}
public static void main()
{
while(running)
{
processInput();
updateGameState();
output();
sleep(start + millisecondsPerFrame - getCurrentTime());
}
}public static void main()
{
double lastTime = getCurrentTime();
while (running)
{
double current = getCurrentTime();
double deltaTime = current - lastTime;
processInput();
updateGameState(deltaTime);
output();
lastTime = current;
}
}public static void main()
{
double previous = getCurrentTime();
double lag = 0.0;
while (true)
{
double current = getCurrentTime();
double deltaTime = current - previous;
previous = current;
lag += deltaTime;
processInput();
while (lag >= millisecondsPerFrame)
{
updateGameState();
lag -= millisecondsPerFrame;
}
output();
}
}PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
MSG msg;
int time, oldtime, newtime;
char* cddir;
ParseCommandLine (lpCmdLine);
Qcommon_Init (argc, argv);
oldtime = Sys_Milliseconds ();
while (1) { // main window message loop
// Windows message pump.
while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!GetMessage (&msg, NULL, 0, 0)) Com_Quit ();
sys_msg_time = msg.time;
TranslateMessage (&msg);
DispatchMessage (&msg);
}
// Measure real delta time in milliseconds.
do {
newtime = Sys_Milliseconds ();
time = newtime - oldtime;
} while (time < 1);
// Run a frame of the game.
Qcommon_Frame (time);
oldtime = newtime;
43
}
return TRUE; // never gets here
}
void Qcommon_Frame (int msec) {
char *s;
int time_before, time_between, time_after;
// [some details omitted...]
// Handle fixed-time mode and time scaling.
if (fixedtime->value) msec = fixedtime->value;
else if (timescale->value) {
msec *= timescale->value;
if (msec < 1) msec = 1;
}
// Service the in-game console.
do {
s = Sys_ConsoleInput ();
if (s) Cbuf_AddText (va("%s\n",s));
} while (s);
Cbuf_Execute ();
// Run a server frame.
SV_Frame (msec);
// Run a client frame.
CL_Frame (msec);
// [some details omitted...]
}PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
public static void main()
{
while(running)
{
processInput();
updateGameState();
output();
}
}
public void output()
{
// processes other output
otherOutput();
// draws the updated state
draw();
}
public void output()
{
// processes other output
otherOutput();
// draws the updated state
draw();
// change to back buffer
swapBuffers();
}
Double Buffering
1. Draw
graphics
Image
Screen
Back Buffer
Primary Surface
2. Blt
(copy)
Image
Screen
Back Buffer
Primary Surface
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
Time
Event arrives
Lag
process input
update state
render
process input
update state
render
process input
update state
render
}
{
{
{
Frame time
Frame time
Frame time
.
.
.
.
.
.
PLAYER-COMPUTER INTERACTION
UNIT 12: GAME ENGINE ARCHITECTURE
func _ready():
# Do something...
pass
func _process(delta):
# Do something...
pass
func _physics_process(delta):
# Do something...
pass
The contents of this Open Educational Resource are licensed under the Creative-Commons Attribution 4.0 International license (CC BY 4.0)
Attribution: Eike Langbehn, Anh Sang Tran, Peter Wood