Skip to content

Commit 322ebb0

Browse files
committed
continue game architecture
1 parent 52aaf55 commit 322ebb0

File tree

6 files changed

+162
-4
lines changed

6 files changed

+162
-4
lines changed

docs/assets/fig/acts_scenes.png

9.44 KB
Loading

docs/manual_architecture.adoc

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,54 @@ This section will teach you how to organize your game globally, from top to bott
1010

1111
xref:manual.adoc[< Back to the manual]
1212

13-
== Acts and scenes
13+
== Acts and Scenes
1414

15-
== Model, data and state
15+
In this section, we see how to split a game into several components called acts. Each act can then be split into scenes. Figure <<acts_scenes>> gives an overview of a game with two acts: _Kickoff_ and _World_.
1616

17-
== Resources and entities
17+
[#acts_scenes]
18+
.Acts and Scenes
19+
image::fig/acts_scenes.png[Acts and Scenes]
20+
21+
=== Acts
22+
23+
A *game* is represented by a class that derives from a scene manager. Generally, xref:SceneSystem.adoc[`gf::SceneSystem`] is the scene manager you want. It provides a random engine, a resource manager, a font manager and an audio manager. A game is composed of one or several acts. For simple games, a single act is enough. For more complex games, with an initial menu with several features, and then one or several large levels, you may need several acts.
24+
25+
In order to define the game represented in the previous figure, you can declare the `Game` class. In this case, the _World_ act (`WorldAct`) is associated with a model (`WorldModel`), but not the _Kickoff_ act (`KickoffAct`) because the _Kickoff_ act does not need data or state.
26+
27+
.Definition of a game
28+
[source,indent=0]
29+
----
30+
include::snippets/manual_arch.cc[tag=game_h]
31+
----
32+
33+
An *act* is a set of one or more consistent scenes. Each act is associated with its own resources (see <<resources-and-entities>>) and it can be associated with a model (see <<model-data-and-state>>). An act can be loaded asynchronously if its loading time needs a beautiful loading scene, but the first act must be loaded as fast as possible.
34+
35+
An act generally needs the game class (`Game`) and the relevant resources to initialize all the scenes. The _World_ act (`WorldAct`) has two scenes: the _Map_ scene (`MapScene`) and the _Options_ scene (`OptionsScene`) that are initialized in the act's contructor.
36+
37+
.Definition of an act
38+
[source,indent=0]
39+
----
40+
include::snippets/manual_arch.cc[tag=act_h]
41+
----
42+
43+
=== Scenes
44+
45+
A *scene* is a game loop that is split into different steps. In the scene manager, scenes are organized in a stack at runtime. You can push a scene, pop a scene or completely replace all the scenes (generally when you go through the next act). When multiple scenes are in the stack, the different steps are called for every scenes, from the bottom of the stack to the top of the stack. The scope of a scene can vary according to the game and inside a game. Generally, when you need a new set of actions (keyboard, mouse, etc) and/or a new set of entities to render elements of the game, you need a new scene.
46+
47+
A scene class derives from xref:BasicScene.adoc[`gf::BasicScene`] that provides only basic features. For a general purpose scene, you may want to derive from xref:Scene.adoc[`gf::Scene`]. This scene is built around two set of entities: the world entities that are meant to be in the world of the game; the hud entities that are meant to display link:HUD[https://en.wikipedia.org/wiki/HUD_(video_games)] elements.
48+
49+
.Definition of a scene
50+
[source,indent=0]
51+
----
52+
include::snippets/manual_arch.cc[tag=scene_h]
53+
----
54+
55+
56+
To go deeper in scenes, you can check the xref:manual_scenes.adoc[Scenes] section.
57+
58+
== Model, Data and State
59+
60+
== Resources and Entities
1861

1962
== Conclusion
2063

docs/snippets/manual_arch.cc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <memory>
2+
3+
#include <gf2/framework/SceneSystem.h>
4+
#include <gf2/graphics/Scene.h>
5+
6+
struct KickoffResources {
7+
};
8+
9+
struct KickoffAct;
10+
11+
struct WorldResources {
12+
};
13+
14+
struct WorldModel {
15+
};
16+
17+
struct WorldAct;
18+
19+
// tag::game_h[]
20+
class Game : public gf::SceneSystem {
21+
public:
22+
Game();
23+
24+
KickoffAct* kickoff_act() { return m_kickoff_act.get(); }
25+
26+
WorldAct* world_act() { return m_world_act.get(); }
27+
28+
WorldModel* world_model() { return &m_world_model; }
29+
30+
private:
31+
KickoffResources m_kickoff_resources;
32+
std::unique_ptr<KickoffAct> m_kickoff_act;
33+
34+
WorldResources m_world_resources;
35+
WorldModel m_world_model;
36+
std::unique_ptr<WorldAct> m_world_act;
37+
};
38+
// end::game_h[]
39+
40+
// tag::scene_h[]
41+
class MapScene : public gf::Scene {
42+
public:
43+
MapScene(Game* game, const WorldResources& resources);
44+
45+
};
46+
// end::scene_h[]
47+
48+
class OptionsScene : public gf::Scene {
49+
public:
50+
OptionsScene(Game* game, const WorldResources& resources);
51+
52+
};
53+
54+
// tag::act_h[]
55+
struct WorldAct {
56+
WorldAct(Game* game, const WorldResources& resources);
57+
58+
MapScene map_scene;
59+
OptionsScene option_scene;
60+
};
61+
// end::act_h[]
62+
63+

docs/tex/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ all: generate_images
55
grids.pdf: grids.tex
66
pdflatex grids.tex
77

8-
generate_images: grids.pdf
8+
architecture.pdf: architecture.tex
9+
pdflatex architecture.tex
10+
11+
generate_images: grids.pdf architecture.pdf
912
pdftocairo -png -r 200 -cropbox grids.pdf
13+
pdftocairo -png -r 200 -cropbox architecture.pdf
1014
./crop-images.sh

docs/tex/architecture.tex

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
\documentclass[a4paper]{article}
2+
3+
% packages
4+
\usepackage[utf8]{inputenc}
5+
\usepackage[T1]{fontenc}
6+
\usepackage[english]{babel}
7+
\usepackage{libertine}
8+
\usepackage{xcolor}
9+
\usepackage{tikz}
10+
11+
\definecolor{tilecolor}{rgb}{0,0.5,1}
12+
13+
\newenvironment{onepagefig}{\begin{center}\begin{tikzpicture}}{\end{tikzpicture}\end{center}\clearpage}
14+
15+
\begin{document}
16+
17+
\pagestyle{empty}
18+
19+
\begin{onepagefig}
20+
\node[draw,rectangle,rounded corners=3pt,minimum height=4cm,minimum width=12.5cm] (Game) at (0,0) { } ;
21+
\draw (Game.north) node [below] { Game } ;
22+
23+
\node[draw,rectangle,rounded corners=3pt,minimum height=3cm,minimum width=5cm] (Act1) at (-3,0) { } ;
24+
\draw (Act1.north) node [below] { Act \#1: Kickoff } ;
25+
26+
\node[draw,rectangle,rounded corners=3pt,minimum height=2cm,minimum width=2cm] (SceneA) at (-4, 0) { } ;
27+
\draw (SceneA.north) node [below] { Menu } ;
28+
29+
\node[draw,rectangle,rounded corners=3pt,minimum height=2cm,minimum width=2cm] (SceneB) at (-2, 0) { } ;
30+
\draw (SceneB.north) node [below] { Credits } ;
31+
32+
\node[draw,rectangle,rounded corners=3pt,minimum height=3cm,minimum width=5cm] (Act2) at (3,0) { } ;
33+
\draw (Act2.north) node [below] { Act \#2: World } ;
34+
35+
\node[draw,rectangle,rounded corners=3pt,minimum height=2cm,minimum width=2cm] (SceneC) at (2, 0) { } ;
36+
\draw (SceneC.north) node [below] { Map } ;
37+
38+
\node[draw,rectangle,rounded corners=3pt,minimum height=2cm,minimum width=2cm] (SceneD) at (4, 0) { } ;
39+
\draw (SceneD.north) node [below] { Options } ;
40+
41+
\end{onepagefig}
42+
43+
44+
\end{document}

docs/tex/crop-images.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ mv "${WORKING_DIR}/grids-31.png" "${OUTPUT_DIR}/hexagonal_x_1_neighbors.png"
6060
mv "${WORKING_DIR}/grids-32.png" "${OUTPUT_DIR}/hexagonal_x_0_neighbors.png"
6161
mv "${WORKING_DIR}/grids-33.png" "${OUTPUT_DIR}/hexagonal_y_1_neighbors.png"
6262
mv "${WORKING_DIR}/grids-34.png" "${OUTPUT_DIR}/hexagonal_y_0_neighbors.png"
63+
64+
# architecture
65+
66+
mv "${WORKING_DIR}/architecture-1.png" "${OUTPUT_DIR}/acts_scenes.png"

0 commit comments

Comments
 (0)