2. Creating & Building a New Project

In this chapter, we will create a new project named hello world and show how to build it.

Note

I will use a terminal window in this example. If you’d like to use CLion on linux or Visual Studio, please refer to Build environment using CLion and Build environment using Visual Studio , respectively.

2.1. Initiating a project

$ funapi_initiator hello_world

If you run the command above, you will get a directory named hello_world-source in the current directory. This is a source directory that you will maintain throughout the project lifecycle. If you want to share the source directory, you can put the directory into your favorite version control systems such as GIT or SVN.

2.2. Generating a build directory

You may want a build directory separate from the source directory for better source tree management. If you have more than one engineers in your development team, they will share the same source tree through SVN/GIT but they will prepare own build directory using either terminal, CLion, or Visual Studio.

As mentioned earlier, this example uses a terminal window. Please type in the following command.

$ hello_world-source/setup_build_environment --type=makefile

The command above creates a build directory named hello_world-build. And it has subdirectories named debug and release in it. The subdirectories are for a debug build and a release build, respectively.

Note

Release build is compiled with -DNDEBUG preprocessor on and -O3 optimization option. Release build and debug build share the rest of compiler options.

Important

Do not put the build directory into an SVN repository or a GIT repository, since build outputs may have dependency on a specific user’s build environment. This will make your colleagues unhappy.

2.3. Building the project

Let’s build the debug version. Move into the hello_world-build/debug directory and type in make.

$ cd hell_world-build/debug
$ make

All is good if you see a message like this:

...
[100%] Building CXX object src/CMakeFiles/hello_world.dir/hello_world_server.cc.o
Linking CXX shared module libhello_world.so
[100%] Built target hello_world

2.4. Running the project

At the end of a build process, iFun Engine generates two launch scripts ending with -local and -launcher, respectively. The former is for development and runs the game server from the current directory. The latter, on the other hand, is used when you package the project, copy it onto a live server, and to run the project on the server as a daemon (i.e., using upstart or systemd)

Please note that we need a separate script for a service daemon, for different paths to executable files and log directories. Packaging a game server as a service daemon is explained in Packaging The Game Server .

So, we should run hello_world-local at this time, since we will run the server from the current working directory.

$ ./hello_world-local

Running? Congratulations! I will describe in the following chapter about the networking part of iFun Engine and explain how to add code to handle client-server messages.