Earlier today, I thought: “Man, Terraria sure is a great game. I should make a clone.”
Then later today, I thought: “Wait, somebody probably already did that.”
And, lo! An open source Terraria clone: Terrarium!
But man, I have to install so many dependencies. This kind of thing is a drag. I just want to try it out.
Fortunately, the instructions were pretty good.
Following the instructions in BUILDING.md, first I installed MinGW and Allegro. MinGW is a C++ compiler, and Allegro is a game programming library for C++.
The Allegro installation instructions had a handy wiki containing the commands for adding the Allegro PPA. Thanks Allegro team!
1
2
3
4
5
6
7
8
|
sudo apt-get install mingw-w64
# ...
sudo add-apt-repository ppa:allegro/5.2
# ...
sudo apt-get update
# ...
sudo apt-get install liballegro5-dev
# ...
|
Next, I copied linux-gcc-allegro5.0-release
from build
to the project root, then ran configure.sh
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
cp -r build/linux-gcc-allegro5.0-release .
cd linux-gcc-allegro5.0-release
./configure.sh
# Searching C++ compiler # ... yes
# Searching libraries in
# library allegro # ... yes
# library allegro_image # ... no
# library allegro_font # ... no
# library allegro_ttf # ... no
# library allegro_primitives # ... yes
# library allegro_audio # ... no
# library allegro_acodec # ... no
# Some libraries are missing. allegro, allegro_image, allegro_font, allegro_ttf, allegro_primitives, allegro_audio and
allegro_acodec (development versions) are required to build.
|
But I was missing many allegro dependencies.
The output didn’t specify actual package names, so I did some apt-cache
searching:
1
2
3
4
5
6
7
|
apt-cache search allegro | grep audio
# liballegro-acodec5-dev - header files for the Allegro 5 audio codec addon
# liballegro-audio5-dev - header files for the Allegro 5 audio addon
# liballegro-acodec5.2 - audio codec addon for the Allegro 5 library
# liballegro-audio5.2 - audio addon for the Allegro 5 library
# liballegro-acodec5.0 - audio codec addon for the Allegro 5 library
# liballegro-audio5.0 - audio addon for the Allegro 5 library
|
Here the match to what I want above is:
So off we go:
1
|
sudo apt-get install liballegro-audio5-dev
|
Repeated until all of the ‘no’ turned to ‘yes’:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
./configure.sh
# Searching C++ compiler # ... yes
# Searching libraries in
# library allegro # ... yes
# library allegro_image # ... yes
# library allegro_font # ... yes
# library allegro_ttf # ... yes
# library allegro_primitives # ... yes
# library allegro_audio # ... yes
# library allegro_acodec # ... yes
# Ready to touch .mk files within the current folder (and subfolders, recursively).
# Replace BUILD_PATH tokens with /home/matt/projects/cplusplus/terrarium # ...
# ...
# Touched /home/matt/projects/cplusplus/terrarium/linux-gcc-allegro5.0-release/sources.mk
# Touched /home/matt/projects/cplusplus/terrarium/linux-gcc-allegro5.0-release/objects.mk
# Ready. Now you can run 'make'
|
Running make:
1
2
|
make
# make: *** No rule to make target 'src_libs/futil/chrono.o', needed by 'terrarium'. Stop.
|
Whoops, git submodules needed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
cd ..
git submodule init
# Submodule 'src_libs/fgeal' (https://github.com/hydren/fgeal) registered for path 'src_libs/fgeal'
# Submodule 'src_libs/futil' (https://github.com/hydren/futil.git) registered for path 'src_libs/futil'
# Submodule 'src_libs/rapidxml' (https://github.com/hydren/rapidxml) registered for path 'src_libs/rapidxml'
git submodule update
# Cloning into 'src_libs/fgeal'# ...
# remote: Counting objects: 4860, done.
# remote: Compressing objects: 100% (42/42), done.
# remote: Total 4860 (delta 31), reused 45 (delta 17), pack-reused 4801
# Receiving objects: 100% (4860/4860), 1.07 MiB | 0 bytes/s, done.
# Resolving deltas: 100% (3545/3545), done.
# Checking connectivity# ... done.
# Submodule path 'src_libs/fgeal': checked out 'fe4442ab80eb87bc326bca19ddea3a8d82fae02a'
# Cloning into 'src_libs/futil'# ...
# remote: Counting objects: 790, done.
# remote: Total 790 (delta 0), reused 0 (delta 0), pack-reused 790
# Receiving objects: 100% (790/790), 162.54 KiB | 0 bytes/s, done.
# Resolving deltas: 100% (544/544), done.
# Checking connectivity# ... done.
# Submodule path 'src_libs/futil': checked out '365586fe5a381863ca7aceb664f0bebfe24e2cf9'
# Cloning into 'src_libs/rapidxml'# ...
# remote: Counting objects: 15, done.
# remote: Total 15 (delta 0), reused 0 (delta 0), pack-reused 15
# Unpacking objects: 100% (15/15), done.
# Checking connectivity# ... done.
# Submodule path 'src_libs/rapidxml': checked out '1c749642e89602a74470593c7d9cb7d35449ebba'
|
Note: git stores the submodule config info in .gitmodules
at the project root.
1
2
3
4
5
6
7
8
9
10
|
cat .gitmodules
[submodule "src_libs/futil"]
path = src_libs/futil
url = ../futil.git
[submodule "src_libs/fgeal"]
path = src_libs/fgeal
url = https://github.com/hydren/fgeal
[submodule "src_libs/rapidxml"]
path = src_libs/rapidxml
url = https://github.com/hydren/rapidxml
|
And now make
is doing things:
1
2
3
4
5
6
7
|
make
# Building file: ../src_libs/futil/chrono.c
# Invoking: GCC C Compiler
# gcc -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src_libs/futil/chrono.d" -MT"src_libs/futil/chrono.o" -o "src_libs/f
# util/chrono.o" "../src_libs/futil/chrono.c"
# Finished building: ../src_libs/futil/chrono.c
# ...
|
But there’s a missing dependency that causes a fatal error in physics.cpp
: Box2D.h
.
1
2
3
4
5
6
7
8
9
10
|
Building file: ../src/physics.cpp
Invoking: GCC C++ Compiler
g++ -I"/home/matt/projects/cplusplus/terrarium/src" -I"/home/matt/projects/cplusplus/terrarium/src_libs" -O3 -Wall -c
-fmessage-length=0 -MMD -MP -MF"src/physics.d" -MT"src/physics.o" -o "src/physics.o" "../src/physics.cpp"
../src/physics.cpp:13:25: fatal error: Box2D/Box2D.h: No such file or directory
#include <Box2D/Box2D.h>
^
compilation terminated.
src/subdir.mk:51: recipe for target 'src/physics.o' failed
make: *** [src/physics.o] Error 1
|
So let’s find Box2D, which is an open source C++ engine for simulating rigid bodies in 2D.
1
2
3
4
5
6
7
8
9
10
|
~/projects/cplusplus/terrarium/linux-gcc-allegro5.0-release $ apt-cache search box2d
# libbox2d-dev - 2D physics engine - development files
# libbox2d-doc - 2D physics engine - documentation
# libbox2d2.3.0 - 2D physics engine
# libbox2d2.3.0-dbg - 2D physics engine - debugging symbols
# numptyphysics - crayon based physics puzzle game
# python-box2d - Python Bindings for the 2D Physics Engine Box2D
# python-box2d-doc - Python Bindings for the 2D Physics Engine Box2D - documentation
# python-elements - A 2D Physics API for Python
# qtdeclarative5-box2d1.1 - QML Bindings for the Box2d physics engine
|
The first one seems reasonable.
After installing, I get a cryptic message when running make
again; it seems some run files were cached:
1
|
# make: 'src_libs/futil/exception.o' is up to date.
|
So I deleted exception.*
from src_libs/futil/properties
, then got this cryptic error:
1
|
# make: 'src_libs/futil/properties.o' is up to date.
|
And so on with:
1
2
3
|
# make: 'src_libs/futil/stox.o' is up to date.
# ...
# etc
|
So I just deleted linux-gcc-allegro5.0-release
and re-copied it from /build/
, re-ran configure.sh
and make
, and bam:
1
2
3
4
5
6
|
./configure.sh
# ...
# Ready. Now you can run 'make'
make
# ...
Finished building target: terrarium
|
So now what?
There’s an executable: terrarium
. So let’s run it:
1
2
|
./terrarium
runtime error File could not be opened: config.properties
|
Whoops, missing config. Reading the BUILDING.md
again, it seems the terrarium
executable needs to get moved up a level, next to the resources
dir:
1
2
3
4
5
|
cp terrarium ../
ls
build BUILDING.md DEV_NOTES linux-gcc-allegro5.0-release resources src terrarium
BUILDING_FGEAL.md config.properties LICENSE README.md scripts src_libs
./terrarium
|
O-ho!
All was not in vain. Though since we get that ‘up to date’ message whenever we re-run make, we’ll have to remove linux-gcc-allegro5.0-release
every time, which is annoying. Script time!
1
2
3
4
5
6
7
|
vim compile
# add these contents; the () commands cause a subshell to be spun up, which is necessary to avoid make weirdness when referencing sub directories)
rm -rf linux-gcc-allegro5.0-release
cp -r build/linux-gcc-allegro5.0-release .
(cd linux-gcc-allegro5.0-release && ./configure.sh)
(cd linux-gcc-allegro5.0-release && make && cp terrarium ../)
./terrarium
|
Hold my pickaxe, I’m going in!