<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Game_Engines_2021W_Lecture_13</id>
	<title>Game Engines 2021W Lecture 13 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Game_Engines_2021W_Lecture_13"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Game_Engines_2021W_Lecture_13&amp;action=history"/>
	<updated>2026-04-08T03:33:35Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Game_Engines_2021W_Lecture_13&amp;diff=22995&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;&lt;pre&gt; Lecture 13 ----------  Godot categorizes its elements differently than other game engines  - nodes &amp; scenes vs much more complex divisions (entities, prefabs, worlds, et...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Game_Engines_2021W_Lecture_13&amp;diff=22995&amp;oldid=prev"/>
		<updated>2021-03-04T13:12:58Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;pre&amp;gt; Lecture 13 ----------  Godot categorizes its elements differently than other game engines  - nodes &amp;amp; scenes vs much more complex divisions (entities, prefabs, worlds, et...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 13&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
Godot categorizes its elements differently than other game engines&lt;br /&gt;
 - nodes &amp;amp; scenes vs much more complex divisions (entities, prefabs, worlds, etc)&lt;br /&gt;
&lt;br /&gt;
The more complex divisions come from entity-component architectures, or&lt;br /&gt;
entity component systems architectures&lt;br /&gt;
&lt;br /&gt;
Games care about performance&lt;br /&gt;
&lt;br /&gt;
cache-friendly code?&lt;br /&gt;
&lt;br /&gt;
Modern computer architecture, memory&lt;br /&gt;
 - CPUs are MUCH faster than RAM&lt;br /&gt;
   - thus, we have caches: faster memory between RAM and the CPU&lt;br /&gt;
   - different kinds, L1, L2, L3&lt;br /&gt;
     - L1 is smaller and faster than L2&lt;br /&gt;
&lt;br /&gt;
If your code is going to go fast, it should be cache friendly&lt;br /&gt;
&lt;br /&gt;
Classic object-oriented code (can be) very cache unfriendly&lt;br /&gt;
&lt;br /&gt;
(ECS is a path to cache friendly code, basically)&lt;br /&gt;
&lt;br /&gt;
How do you use cache most effectively?  Key insight:&lt;br /&gt;
 - data is loaded into cache in bulk&lt;br /&gt;
 - request one byte, get 64 bytes or more (cache lines)&lt;br /&gt;
&lt;br /&gt;
How cache behaves is a black box&lt;br /&gt;
 - very complex&lt;br /&gt;
&lt;br /&gt;
To get good cache performance, you want spatial and temporal locality&lt;br /&gt;
 T: if x is used, it is likely x is used again sooner rather than later&lt;br /&gt;
 S: if x is used, y is used where y is close to x&lt;br /&gt;
&lt;br /&gt;
Imagine a for loop traversing an array&lt;br /&gt;
 - while accessing element 1, elements 2, 3, and 4 may be loaded into cache when 1 is loaded&lt;br /&gt;
 - so access to 2, 3, and 4 will be much faster &amp;lt;- spatial locality&lt;br /&gt;
 - but, if you accessed the array randomly, will have to go to main memory&lt;br /&gt;
   much more frequently&lt;br /&gt;
&lt;br /&gt;
Main memory has high latency but also high bandwidth&lt;br /&gt;
 - takes a while to get one byte, but gets lots of data for each access&lt;br /&gt;
   - you never just get one byte&lt;br /&gt;
&lt;br /&gt;
Never underestimate the bandwidth of a truck or a boat with LOTS of hard drives (spinning or SSD)&lt;br /&gt;
 - but its latency is crap, a week to get the first byte&lt;br /&gt;
&lt;br /&gt;
bandwidth is average bytes per second, latency is time for first byte (or roundtrip cost)&lt;br /&gt;
&lt;br /&gt;
latency matters for games, i.e., how long does the system take to respond to pressing a button&lt;br /&gt;
 - measure of responsiveness&lt;br /&gt;
&lt;br /&gt;
Classic objects are, from a storage point of view, just structs&lt;br /&gt;
Imagine doing an operation on lots of objects&lt;br /&gt;
 - only need a few properties of each object&lt;br /&gt;
 - this is very cache-unfriendly, because you aren&amp;#039;t using most of the object&lt;br /&gt;
    - but whole objects will be put into cache&lt;br /&gt;
    - load 512 bytes but only use 16&lt;br /&gt;
    - waste of bandwidth&lt;br /&gt;
&lt;br /&gt;
ECS is an architecture to turn this around to make it cache friendly&lt;br /&gt;
(assuming you do operations on small portions of objects at once)&lt;br /&gt;
&lt;br /&gt;
instead, split up the objects into components, and keep components in arrays&lt;br /&gt;
  - so, if you loop through components, you&amp;#039;ll be cache friendly&lt;br /&gt;
&lt;br /&gt;
Unify components using &amp;quot;entities&amp;quot;, i.e., a unique ID to group togother components&lt;br /&gt;
&lt;br /&gt;
Instead of an object with properties ID, A, B, C, and D, instead you have&lt;br /&gt;
 - array of A&amp;#039;s&lt;br /&gt;
 - array of B&amp;#039;s&lt;br /&gt;
 - array of C&amp;#039;s&lt;br /&gt;
 - array of D&amp;#039;s&lt;br /&gt;
 - each element of the arrays also has ID&lt;br /&gt;
   - or use the array index as the ID&lt;br /&gt;
&lt;br /&gt;
So, looping through A&amp;#039;s is very fast&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;system&amp;quot; part is the code that processes each property&lt;br /&gt;
  - i.e., physics system just deals with physics-related properties,&lt;br /&gt;
  - because they are stored separately, can be accessed all at once,&lt;br /&gt;
    fast, without looking at the other data associated with the entities&lt;br /&gt;
&lt;br /&gt;
Godot doesn&amp;#039;t do this because it isn&amp;#039;t so simple for developers&lt;br /&gt;
 - less generality&lt;br /&gt;
&lt;br /&gt;
But its objects are at a higher level, really just an interface&lt;br /&gt;
&lt;br /&gt;
Underlying servers can be cache friendly as you like&lt;br /&gt;
 - e.g., physics server&lt;br /&gt;
&lt;br /&gt;
Really, ECS is a pattern of has-a OO, rather than is-a OO (inheritance)&lt;br /&gt;
&lt;br /&gt;
Note that JavaScript is very has-a OO (why it has no real classes)&lt;br /&gt;
&lt;br /&gt;
ECS is a game dev specific pattern to &amp;quot;data oriented&amp;quot; code&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>