Facade Game Not Loading

OpenGL 2D Facade (22): Load and save game state

We still need game content to test the facade, and it's even better if we can load and save that content from a file!

This post is part of the OpenGL 2D Facade series

Objective

The expected result is our current level editor able to load and save all the current game state:

I've been seeing it pop up on a ton of my favourite channels of late, so I just had to try Facade for myself! Watch as a flirt with Grace, throw back booze w. The loading screen certainly took longer than the promised “no more than 60 seconds” (and the computer I used is not usually slow, so I figured it was the game) After restarting the game a few times, I still could not actually get to the game-part of the game, so eventually I moved to another computer – this time with a Windows 7 os. Facade game not loading on Mac First, uninstall the game completely and then shut down your computer. Unplug the cables to your Network Interface Controller (NIC) and then wait for at least 10 seconds. Every Game is Free to Try or Totally Free. Our site is about all kinds of free games to download whether they be time limited shareware, level limited demos or freeware games with absolutely no restrictions at all. We want you to be able to experience high quality game play without having to pay before you play. Jul 05, 2005 Game Walkthroughs. Walkthrough (PC) Added on:. If you know cheat codes, secrets, hints, glitches or other level guides for this game that can help others leveling up, then please Submit your Cheats and share your insights and experience with other gamers. Latest Questions.

Serialization

Design

To load and save data, I propose to use serialization. It is a common approach that reads or writes content sequentially. It is a fast approach, and the only drawback is that we can not read or write a specific item. In our context, we always want to load or save a whole level, so it is not an issue.

We also have to choose the encoding or how we translate data into bytes or characters. Many people like text-based encodings like JSON or XML, but it is relatively slow and leads to large files. In our case, I think that it is better to consider binary encoding to get quick I/O and small files. The only drawback is that binary files are not human-readable.

Here are the classes I propose to create:

The IO class is the main class, and it can read or write primary content like strings or numbers. It holds a binary stream in the stream attribute we use to read or write byte arrays.

For specific objects, like the state of our game, we can create implementations of the ObjectSerializer class. In the read() and write() methods, we explain how to serialize them. They can use primary types (like numbers or strings) and any data type with an ObjectSerializer implementation registered with the registerObjectSerializer() method.

Note: In the diagram above, we only see a few cases. The complete IO class contains most integers (from 8 to 64 bits, signed or not), floats, usual structures, Numpy arrays, etc.

Integer serialization

Let's see an example with the serialization of an unsigned 8-bit integer:

Yahoo Game Not Loading

Line 2 checks that the input number fits the available space; otherwise, we could lose data without knowing it.

Line 3 writes some data that tells that the following content is an unsigned 8-bit integer. This step is not mandatory and increases the size of the file. However, it robustifies the file and helps in the detection of corrupted data. It is worth the cost, especially if we save most of our data in large structures like Numpy arrays.

Facade game not loading windows 10

self.BLOCK_UINT8 is a unique value to identify unsigned 8-bit integers. Its actual value does matter; what matters is to define it and never change it.

Line 4 encodes the number into a Python bytes array.

Line 5 writes the bytes array to the stream.

The writeBlockHeader() method writes a single byte:

Integer deserialization

Facade Game Not Loading Windows 10

The decoding of an integer is as follow:

Line 2 reads the type code in the block header and checks it is as expected.

Line 3 reads a bytes array with a single byte.

Line 4 converts the bytes array into an integer.

The readBlockHeader() also reads a single byte:

Objects serialization

For the serialization of objects, we need to explain how they can be read and written. Let's take an example with a simple class with two attributes:

The serialization of instances of this class can be as follow:

The implementation is straightforward:

  • We write the name and then the age for the serialization;
  • We read the name and then the age for the deserialization.

Note that we could also add a header to tell that the content is a user.

To use this serializer (read or write), we first need to register it:

The implementation of the registerObjectSerializer() is straightforward:

We can write instances of the User class with the writeObject() method:

Here is the implementation of this method:

Line 2 gets the name of the class. Note that it is the relative name; we can have several classes with the same name in various locations.

Lines 3-4 check that we registered the type.

Line 5 writes the block header.

Line 6 writes a string with the name of the class.

Line 7 gets the object serializer.

Line 8 serializes the object.

The deserialization of the object is thanks to the readObject() method:

NB: don't forget to move the stream pointer to the stream's start if you want to test this!

The implementation of the readObject() method is as follow:

Other data types

Please have a look at the complete code below to see all cases.

Game state serialization

Using the IO class, the serialization of all our game content is easy:

Handling versions

Our game data will evolves with time, so we should handle these changes as soon as possible. The approach in this section consists of creating sets of object serializers for each version:

The diagram above shows the state and region serializers in a v1 package. The idea is to create a new package for each version (v2, v3, ...) with all the serializers. As we see below, we will only need to add the new serializers since we can reuse the previous ones if they have not changed.

For each version, we create a static method in the MainIO class that register all the serializers. For instance, for the first version:

Then, we can save our game state in the following way:

Line 2 creates a MainIO with the latest version (here version 1).

Line 3 asks MainIO to create a new empty stream in memory.

Line 4 writes the main file header: a string to identify the file's content (here a game level) and an integer for the version (here version 1).

Line 5 writes the game state.

Line 6 saves all the stream content into a file.

The loading of the file have to deal with the versions:

Facade game not loading gameFacade Game Not Loading

Line 2 creates a new instance of IO.

Line 3 loads the content of a file into the stream of mainIO.

Line 4 reads the file header: it checks that the file is a 'level' file and returns its version.

If the version is the first one, then line 5 creates the corresponding MainIO. It uses the previous stream, so we don't have to decode the file header again. Line 6 reads the game state.

For other versions, we can add elif statements and build corresponding deserializers.

Final progam

In the next post, I'll show how to animate water.

Copyright © 2020-2021 https://www.patternsgameprog.com

Mediumish Theme by WowThemes.net