Skip to content

Commit 56cfac7

Browse files
committed
Updated readme
1 parent ad82a2d commit 56cfac7

7 files changed

+36
-6
lines changed

_text/10-bytecode.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ The programmers with no skillz write their code in a .txt-file. You read that fi
88

99
**When is it useful?**
1010

11-
- If you want to add modding support.
11+
- To add modding support.
1212

13-
- If you don't want to hard-code behaviour.
13+
- To avoid hard-coded behaviour.
14+
15+
- To handle cutscenes and dialogue systems. Scripted sequences or dialogue interactions can be expressed in bytecode, allowing for easier management and execution of these sequences during gameplay.
16+
17+
- To manage and execute the conditions and actions required to unlock achievements or track player progress.
1418

1519

1620
## [Back](../)

_text/15-service-locator.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 15. Service Locator
22

3-
When making your game you use many standardized methods to for example generate random numbers. These are called services and should be accessible from everywhere (globally) but still be independet from your game's main code.
3+
When making your game you use many standardized methods to for example generate random numbers. These are called services and should be accessible from everywhere (globally) but still be independet from your game's main code. The pattern allows services to be easily replaced or extended without affecting the existing code that relies on them.
44

55
**How to implement?**
66

@@ -16,6 +16,14 @@ Unity has implemented this pattern in the form of the GetComponent() method.
1616

1717
- In the game you may have different audio objects depending on if the game is running on a console or PC. This is the same example as in the book so you can find the code for it in the code section.
1818

19+
- To inject dependencies into game objects or systems - aka dependency injection. Instead of hardcoding the references to specific services, game objects can use the service locator to request and retrieve the required services at runtime.
20+
21+
- To obtain the input service, abstracting away the underlying input device handling.
22+
23+
- Objects or systems that need to display localized text can use the service locator to retrieve the appropriate localization service.
24+
25+
- Objects that need AI functionality can use the service locator to access AI-related services, such as pathfinding or decision-making algorithms.
26+
1927
**Related patterns**
2028

2129
- **Singleton.** Both provide a global access to an object. So the problems with the Singleton also applies to this pattern.

_text/17-dirty-flag.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 17. Dirty Flag
22

3-
This pattern is useful if something has changed in your game and if so you have to run a costly operation. A Dirty Flag is used to tell that something has changed but the costly operation hasn't been activated yet. You can often postpone the costly operation until the result is actually needed.
3+
This pattern is useful if something has changed in your game and if so you have to run a costly operation. A Dirty Flag is used to tell that something has changed but the costly operation hasn't been activated yet. You can often postpone the costly operation until the result is actually needed. So this pattern allows games to avoid unnecessary computations, updates, and data processing.
44

55
**How to implement?**
66

@@ -16,5 +16,9 @@ The dirty flag is just a bool.
1616

1717
- I used this pattern when experimenting with Genetic Algorithms (GA) and the Traveling Salesman Problem (TSP) where you find the shortest path between multiple cities. The GA generates multiple solutions, like 100, to the TSP and then each iteration you evolve 100 better solutions by calculating a cost function, which is the distance between all cities. You can use "tournament selection" to find good solutions from the previous iteration to the next, which is basically picking 3 solutions and returns the solution with the shortest distance between all cities. I realized I didn't have to calculate the cost fuction 100 times each iteration because it's a costly operation. To optimize I only calculate the cost function of the cities being picked by the tournament selection. I kept track of which solution has had its cost fuction calculated by using a bool which is set to false each iteration and then to true if the cost function has been run.
1818

19+
- In multiplayer games, the Dirty Flag Pattern can be used to track changes in game state for network synchronization. Only data that has been marked as "dirty" needs to be sent across the network, reducing bandwidth usage and improving network performance.
20+
21+
- Can be used to track changes in the game environment or AI state. The AI system can then prioritize updates and decision-making for objects or AI agents with "dirty" data.
22+
1923

2024
## [Back](../)

_text/19-spatial-partition.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ If the objects move you have to update the data structure. These data stuctures
2121

2222
**When is it useful?**
2323

24-
- Find the closest object to a character. This can be a really slow process if you have hundreds of objects around the character. And if you have soldiers fighting soldiers, you have to make that seach for each soldier. A better way is to divide the search-area so you don't have to search thorough all objects - just the ones closest to you.
24+
- Find the closest object to a character. This can be a really slow process if you have hundreds of objects around the character. And if you have soldiers fighting soldiers, you have to make that search for each soldier. A better way is to divide the search-area so you don't have to search thorough all objects - just the ones closest to you.
2525

2626
- To increase the performance of collision detection and raytracing.
2727

28+
- To deactivate objects if they are far away from your character to improve performance. This is called culling. You can hide for example trees and AI far away don't have to update themselves.
29+
30+
- In games with pathfinding, spatial partitioning can help optimize the search for valid paths. By organizing the game world into a navigation grid or spatial data structure, pathfinding algorithms can be restricted to search only within relevant partitions, reducing computation time.
31+
2832

2933
## [Back](../)

_text/20-decorator.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 20. Decorator
22

3-
You have a class you want to add some behaviors to in a flexible way without modifying the original class.
3+
You have a class you want to add some behaviors to in a flexible to an object way without modifying the original class. Other objects of the same class are uneffected, so it is used to dynamically extend the functionality of objects at runtime. Overall, the Decorator Pattern is a versatile and flexible design pattern that enables game developers to enhance and customize game objects or systems without modifying their core implementation.
44

55
**How to implement?**
66

@@ -12,6 +12,12 @@ You have a class and now you create several "decorator" classes that modifies so
1212

1313
- If you ever played Pubg you know you have weapons to which you can attach various attachments you find while playing the game. You can find magazines, sights, silenzers, etc, modifying the weapon's properties. You can use the Decorator pattern to implement this in your game.
1414

15+
- To implement power-ups that temporarily modify the behavior of game objects. Each power-up can be represented as a decorator that wraps around the original object, adding specific enhancements, such as increased speed, damage boost, or invincibility.
16+
17+
- To add special effects or animations to UI buttons, panels, or icons.
18+
19+
- To dynamically adjust the difficulty level of a game. Decorators can be added or removed based on player performance or preferences, altering the game's challenges accordingly.
20+
1521
**Related patterns**
1622

1723
- **Subclass Sandbox.** You may end up with many child-classes. To easier handle the code, you can define high-level methods in the parent.

_text/21-factory.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ If you are creating several different factories, then they should inherit from s
1616

1717
- To keep track of all of your Singletons.
1818

19+
- The Factory Pattern can be used to create game objects, such as characters, enemies, items, obstacles, terrain features, structures, power-ups, collectibles, buttons, particles, etc.
20+
1921
**Related patterns**
2022

2123
- **Prototype.** The Prototype pattern is generally used if you want to make a copy of an existing object, while the Factory pattern is generating new objects. But some argue you can put the Prototype pattern inside of the Factory pattern.

_text/6-state.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ You could use an enum that keeps track of each state and then a switch statement
2020

2121
- The game itself can be a number of states: intro video, main menu, main game, mini game, etc.
2222

23+
- Can be used to manage interactions between different game objects. For example, a door object can have states like open, closed, locked, and unlocked, and its behavior changes depending on its current state.
24+
2325
**Related patterns**
2426

2527
- **Type Object.** In both cases you have a main object and then you add another object to define something. The difference is that in State you switch the other object, while in Type Object that object remains the same. So if the object in Type Object can be switched you get the State pattern.

0 commit comments

Comments
 (0)