Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
CryENGINE Game Programming with C++, C#, and Lua
CryENGINE Game Programming with C++, C#, and Lua

CryENGINE Game Programming with C++, C#, and Lua: For developers wanting to create 3D games, CryENGINE offers the intuitive route to success and this book is the complete guide to using it. Learn to use sophisticated tools and build super-real, super-addictive games.

NZ$‎57.99 NZ$‎39.99
Book Nov 2013 276 pages 1st Edition
eBook
NZ$‎57.99 NZ$‎39.99
Print
NZ$‎71.99
Subscription
Free Trial
eBook
NZ$‎57.99 NZ$‎39.99
Print
NZ$‎71.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Nov 22, 2013
Length 276 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781849695909
Vendor :
Crytek
Category :
Concepts :

Estimated delivery fee Deliver to New Zealand

Standard 10 - 13 business days

NZ$20.95

Premium 5 - 8 business days

NZ$74.95
(Includes tracking information)
Table of content icon View table of contents Preview book icon Preview Book

CryENGINE Game Programming with C++, C#, and Lua

Chapter 1. Introduction and Setup

CryENGINE is known as one of the most extensible engines available due to its ability to portray a vast variety of impressive visuals and gameplay. This makes it an invaluable tool at the hand of a programmer, where the only limit is one's creativity.

In this chapter, we will cover the following topics:

  • Installing Visual Studio Express 2012 for Windows Desktop

  • Downloading the CryENGINE sample installation or using a custom engine install

  • Registering an account at http://www.crydev.net, the official CryENGINE development portal

  • Compiling a stripped-down CryGame library

  • Attaching and utilizing the debugger

Installing Visual Studio Express 2012


In order to compile the game code, you will need a copy of Visual Studio. For this demonstration, we'll be using Visual Studio Express 2012 for Windows Desktop.

Note

If you already have Visual Studio 2012 installed, you may skip this step.

To install Visual Studio, follow the given steps:

  1. Visit http://www.microsoft.com/visualstudio/ and download Visual Studio Express 2012 for Windows Desktop.

  2. After downloading the executable, install the application and proceed to the next step after restarting your computer.

Choosing your CryENGINE installation type


Now that we have Visual Studio installed, we'll need to download a version of CryENGINE to develop on.

We have created a stripped-down sample installation for the book, which is recommended for users who are just starting out with the engine. To download it, see the following Downloading the book's CryENGINE sample installation section.

If you would rather use another build of CryENGINE, such as the latest Free SDK release, please see the Using a custom or newer CryENGINE installation section later in this chapter. This section will cover integrating CryMono on your own.

Downloading the book's CryENGINE sample installation


For this book, we will be using a custom CryENGINE sample as a base for learning the workings of the engine. Most exercises in the book depend on this sample; however, the working knowledge you get from this can be applied to the default CryENGINE Free SDK (available at http://www.crydev.net).

To download the sample installation, follow these steps:

  1. Visit https://github.com/inkdev/CryENGINE-Game-Programming-Sample and click on the Download ZIP button in order to download a compressed archive containing the sample.

  2. Once downloaded, extract the contents of the archive to a folder of your choice. For the sake of the example, we will be extracting it to C:\Crytek\CryENGINE-Programming-Sample.

What just happened?

You should now have a copy of our sample CryENGINE installation. You can now run and view the sample content which we will be using for the most part of this book.

Using a custom or newer CryENGINE installation


This section helps out the readers who choose to use custom or newer builds of the engine. If you are unsure of this process, we recommend reading the Downloading the book's CryENGINE sample installation section in this chapter.

Verifying that the build is functional

Before starting, you should verify that your version of CryENGINE is functional so that you can use it for running and creating code based on this book's chapters.

Note

Note that if you are using an older or newer version of the engine, certain chapters may provide examples and information on changed systems. Keep this in mind, and refer to the sample mentioned previously for the optimal learning experience.

A good way to check this is by starting the Editor and Launcher applications and checking whether the engine behaves as expected.

Integrating CryMono (C# support)

If you're interested in using the sample code and chapter contents written with C# in mind, you'll need to integrate the third-party CryMono plugin into your CryENGINE installation.

Note

Note that CryMono is integrated by default in the sample we created specifically for this book.

To begin integrating CryMono, open the Code folder present in the engine root folder. We'll be placing the source files here, inside a subfolder called CryMono/.

To download the source code, visit https://github.com/inkdev/CryMono and click on Download Zip (or Clone in Desktop if you prefer using your Git revision control client).

Once downloaded, copy the contents into the Code/CryMono folder we mentioned earlier. If the folder does not exist, create it first.

When the files have been successfully moved, your folder structure should look similar to this:

Compiling the CryMono project

Now that we have the CryMono source code, we'll need to compile it.

To start, open Code/CryMono/Solutions/CryMono.sln using Visual Studio.

Note

Make sure to use CryMono.sln and not CryMono Full.sln. The latter is only used when you need to rebuild the entire Mono runtime, which ships precompiled with the CryMono repository.

Before we compile, we'll need to modify the engine's SSystemGlobalEnvironment struct (this is exposed using the global gEnv pointer).

To do so, open ISystem.h in the Code/CryEngine/CryCommon/ folder. Find the struct's definition by searching for the struct SSystemGlobalEnvironment.

Then add the following code to the very end of the struct's members and functions:

struct IMonoScriptSystem*
  pMonoScriptSystem;

Note

Modifying interfaces is not recommended if you do not have full engine source, as other engine modules have been compiled with the default interfaces in mind. However, appending to the end of this struct is mostly harmless.

Once done, open up the instance of Visual Studio where you opened CryMono.sln and start compiling.

Note

The automated post-build step in the project should automatically move the compiled files to your build's Bin32 folder following a successful compilation pass.

To verify that CryMono was compiled successfully, search for CryMono.dll in your Bin32 folder.

Loading and initializing CryMono via the CryGame.dll library

Now that we have the CryMono binaries present in our Bin32 folder, we'll just have to load it during game startup. This is done via the CryGame project, via the CGameStartup class.

To start, open your CryEngine or CryGame solution file (.sln) present in Code/Solutions/.

Including the CryMono interface folder

Before we modify the game startup code, we'll need to tell the compiler where to find the CryMono interfaces.

Start by right-clicking on the CryGame project in Visual Studio's Solution Explorer and select Properties. This should bring up the following CryGame Property Pages window:

Now, click on C/C++ and select General. This will bring up a screen of general compiler settings, which we'll use to add an additional include folder as shown in the following screenshot:

Now all we have to do is add ..\..\CryMono\MonoDll\Headers to the Additional Include Directories menu. This will tell the compiler to search CryMono's Headers folder when the #include macro is used, allowing us to find the CryMono C++ interfaces.

Initializing CryMono at start up

Open GameStartup.h in the CryGame project and add the following to the bottom of the class declaration:

static HMODULE
m_cryMonoDll;

Then open GameStartup.cpp and add the following before the CGameStartup constructor:

HMODULE CGameStartup::m_cryMonoDll = 0;

Now navigate to the CGameStartup destructor and add the following code:

if(m_cryMonoDll)
{
  CryFreeLibrary(m_cryMonoDll);
  m_cryMonoDll = 0;
}

Now navigate to the CGameStartup::Init function declaration, and add the following prior to the REGISTER_COMMAND("g_loadMod", RequestLoadMod,VF_NULL,""); snippet:

m_cryMonoDll = CryLoadLibrary("CryMono.dll");
if(!m_cryMonoDll)
{
  CryFatalError("Could not locate CryMono DLL! %i", GetLastError());
  return false;
}

auto InitMonoFunc = (IMonoScriptSystem::TEntryFunction)CryGetProcAddress(m_cryMonoDll, "InitCryMono");
if(!InitMonoFunc)
{
  CryFatalError("Specified CryMono DLL is not valid!");
  return false;
}

InitMonoFunc(gEnv->pSystem, m_pFramework);

Now all we have to do is compile CryGame in order to have CryMono loaded and initialized at startup.

Registering flow nodes

Due to a recent change in the flow system, flow nodes have to be registered at a certain point during game startup. To make sure that our C# nodes are registered, we'll need to call IMonoScriptSysetm::RegisterFlownodes from IGame::RegisterGameFlowNodes.

To do this, open Game.cpp and add the following inside the CGame::RegisterGameFlowNodes function:

GetMonoScriptSystem()->RegisterFlownodes();

Now, after compiling, all managed flow nodes should appear in the Flowgraph Editor.

Registering your CryDev account


The CryENGINE Free SDK requires a CryDev account in order for the application's to launch. This can be easily retrieved via http://www.crydev.net, by following these steps:

  1. Visit http://www.crydev.net in the browser of your choice.

  2. Click on Register in the upper-right corner.

  3. Read and accept the terms of usage.

  4. Select your username data.

What just happened?

You now have your own CryDev user account. While running the CryENGINE Free SDK applications (see Running the sample application), you will be prompted to log in with the details you have just registered.

Running the sample application


Before we get started with building the game project, we'll go through the basics of the default CryENGINE applications.

Note

All executables are contained inside either the Bin32 or Bin64 folders, depending on the build architecture. However, our sample only includes a Bin32 folder to keep things simple and the build repository small in size.

Editor

This is the main application that developers will use. The Editor serves as the direct interface to the engine, used for all kinds of developer-specific tasks such as level design and character setup.

The Editor supports WYSIWYP (What You See Is What You Play) functionality, which allows developers to preview the game by hitting the shortcut Ctrl + G, or by navigating to the Game menu, and choosing Switch to Game.

Starting the Editor

Open the main sample folder, and navigate to the Bin32 folder. Once there, start Editor.exe.

When the Editor has finished loading, you will be greeted by the Sandbox interface, which can be used to create most visual aspects of the game (excluding models and textures).

To create a new level, open the File menu, and select the New option. This should present you with the New Level message box. Simply specify your level name and click on OK, and the Editor will create and load your empty level.

To load an existing level, open the File menu, and select the Open option. This presents you with the Open Level message box. Select your level and click on Open to have your level loaded.

Launcher

This is the application seen by the end user. Upon startup, the Launcher displays the game's main menu, along with different options allowing users to load levels and configure the game.

The Launcher's game context is commonly referred to as Pure game mode.

Starting the Launcher

Open the main sample folder, and navigate into the Bin32 folder. Once there, start Launcher.exe.

When you've started the application, you'll be greeted with the default main menu. This interface allows the user to load levels and alter game settings such as visuals and controls.

The Launcher is preferable over the Editor when you want to play the game as the end user would. Another benefit is the quick startup time.

Dedicated server

The dedicated server is used to start up a multiplayer server for other clients to connect to. The dedicated server does not initialize a renderer, and instead functions as a console application.

Compiling the CryGame project (C++)


The CryENGINE Free SDK ships with complete source access to the game logic library, CryGame.dll. This dynamic library is responsible for the main part of game features, as well as the initial game startup process.

Note

A library is a collection of existing classes and functions that can be integrated into other projects. In Windows, the most common form of library is a Dynamic Link Library , or DLL , which uses the .dll file extension.

To start off, open the main sample folder, and navigate to Code/Solutions/, in which a Visual Studio solution file named CE Game Programming Sample.sln should be present. Double-click on the file and Visual Studio should start up, displaying the included projects (see the following breakdown).

Note

A solution is a structure for organizing projects in Visual Studio. The solution contains information on projects in a text-based .sln file, as well as a .suo file (user-specific options).

To build the project, simply press F7 or right-click on the CryGame project in the Solution Explorer and select Build.

What just happened?

You just compiled CryGame.dll, which should now be present in the binary folder. (Bin32 for 32-bit compilation, Bin64 for 64-bit). Launching the sample application will now load the .dll file containing the source code you compiled.

The CE Game Programming Sample solution breakdown

The solution includes the following three projects, one of which compiles to a .dll file.

CryGame

The CryGame project includes the underlying game logic used by the engine. This compiles to CryGame.dll.

CryAction

The CryAction project includes partial source to CryAction.dll, which is responsible for a large number of systems, such as actors, UI Graphs, and game objects. This project does not compile to a .dll file, but is instead only used for interface access.

CryCommon

The CryCommon project is a helper containing all shared CryENGINE interfaces. If there is a subsystem you want access to, look for its exposed interface in here.

The CryENGINE folder structure


See the following table for an explanation of the CryENGINE folder structure:

Folder name

Description

Bin32

Contains all 32-bit executables and libraries used by the engine.

Bin64

Contains all 64-bit executables and libraries used by the engine.

Editor

Editor configuration folder, contains common editor helpers, styles, and more.

Engine

Used as a central folder for assets used by the engine itself, not any particular game.

Shaders and configuration files are stored here.

Game

Each game contains a game folder, which includes all its assets, scripts, levels, and so on.

Does not have to be named "Game", but is dependent on the value of the sys_game_folder console variable.

Localization

Contains localization assets such as localized sounds and text for each language.

PAK files

The engine ships with the CryPak module, allowing for the storage of game content files in compressed or uncompressed archives. The archives use the .pak file extension.

When game content is requested, the CryPak system will query through all found .pak files in order to find the file.

File query priority

The PAK system prioritizes the files found in the loose folder structure over those in PAK, except when the engine was compiled in RELEASE mode. When that is the case, the file stored in a PAK system is preferred over the loose one.

If the file exists in multiple .pak archives, the one with the most recent filesystem creation date is used.

Attaching the debugger

Visual Studio allows you to attach the Debugger to your application. This allows you to use functionalities such as breakpoints; letting you stop at a specific line in your C++ source code, and step through the program execution.

To start debugging, open CE Game Programming Sample.sln and press F5, or click on the green play icon on the Visual Studio toolbar. If a No debug symbols could be found for Editor.exe message box appears, simply click on OK.

What just happened?

The CryENGINE Sandbox editor should now have started, with the Visual Studio Debugger attached. We can now place breakpoints in code, and watch program execution pause when that specific line of code is executed.

Summary


In this chapter, we have downloaded and learned how to use a CryENGINE installation. You should now be aware of the process of compiling and debugging the CryGame project.

We now have the basic knowledge needed to move on to learning the ins and outs of the CryENGINE programming API.

If you feel like learning more about CryENGINE itself, besides programming knowledge, feel free to start the Sandbox editor and play around with the level design tools. This will help you prepare for future chapters, where you'll be required to utilize the Editor Viewport and more.

Left arrow icon Right arrow icon

Key benefits

  • Dive into the various CryENGINE subsystems to quickly learn how to master the engine
  • Create your very own game using C++, C#, or Lua in CryENGINE
  • Understand the structure and design of the engine

Description

CryENGINE is a complete 3D game development solution that can run on multiple platforms. It is orientated around giving intuitive tools to the developer. A variety of interactive video games can be created using CryENGINE. CryENGINE is one of the most beginner-friendly engines out there to learn. If you are interested in diving into the various systems and understanding their workings in a way that is easily understood, then this book is for you. This book provides you with the knowledge to tame the powerful but hard-to-master CryENGINE. CryENGINE Game Programming with C++, C#, and Lua dives into the various systems and explains their workings in a way that can be easily understood by developers of all levels. It provides knowledge on the engine along with step-by-step exercises and detailed information on the backend implementation of the subsystems, giving you an excellent foundation to build upon when developing your own CryENGINE games. Written by developers with years of CryENGINE experience, this book breaks down the common confusion that encompasses the CryENGINE engine code, guiding you through a series of chapters aimed towards giving you the ability to create your own games in a rapid yet productive fashion. You will learn everything you need to know in order to create your own CryENGINE-powered games as well as detailed information on how to use the engine to your advantage. By teaching systems such as audio, particle effects, rendering, AI, networking, and more, we'll be exposing the most inner parts of CryENGINE that commonly confuse programmers. If you want to quickly gain the knowledge required to create your own CryENGINE game title, then this book is for you.

What you will learn

Make and modify Flowgraph nodes to give your visual scripting a clear advantage Utilize custom entities, from simple physicalized objects to complex weather simulation managers Control the flow of the game in real-time by creating game rules and modes Create custom actors, in order to create unique elements controllable by human players Use the Artificial Intelligence system to your advantage with custom AI units Design custom User Interfaces to give your player a way to navigate the game s menus and HUDs Implement multiplayer and networking elements for your game, allowing several players to share the experience with each other Master game physics and how to create your own physicalized objects that can interact with the game world Understand the process of using and manipulating the CryENGINE renderer to your advantage, including custom shader authoring Bring your game to life by introducing effects such as particles and sound Debug and profile your game code to get the most out of the computers running your game Implement stock GameDll systems such as vehicles and weapons

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Nov 22, 2013
Length 276 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781849695909
Vendor :
Crytek
Category :
Concepts :

Estimated delivery fee Deliver to New Zealand

Standard 10 - 13 business days

NZ$20.95

Premium 5 - 8 business days

NZ$74.95
(Includes tracking information)

Table of Contents

19 Chapters
CryENGINE Game Programming with C++, C#, and Lua Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Authors Chevron down icon Chevron up icon
About the Reviewers Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
1. Introduction and Setup Chevron down icon Chevron up icon
2. Visual Scripting with Flowgraph Chevron down icon Chevron up icon
3. Creating and Utilizing Custom Entities Chevron down icon Chevron up icon
4. Game Rules Chevron down icon Chevron up icon
5. Creating Custom Actors Chevron down icon Chevron up icon
6. Artificial Intelligence Chevron down icon Chevron up icon
7. The User Interface Chevron down icon Chevron up icon
8. Multiplayer and Networking Chevron down icon Chevron up icon
9. Physics Programming Chevron down icon Chevron up icon
10. Rendering Programming Chevron down icon Chevron up icon
11. Effects and Sound Chevron down icon Chevron up icon
12. Debugging and Profiling Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.