Saving and Loading the Entire State of a Simulation
<< previous | Chapter 11. Archiving, Dearchiving and Networking Objects and Simulations | next >>

## Saving and Loading the Entire State of a Simulation

This technique allows you to save a simulation, and resume it later. In this case, all objects are archived and their states are archived entirely (except for objects containing variables of type pointer, which should apply only to those developing their own breve plug-ins). You must have the original simulation source file in order to restart a saved simulation.

As with the archiving discussed in the previous section (the section called “Saving and Loading Individual Objects”, dependencies can also be used when archiving entire simulations. In this case, the dependencies effect only the order in which objects are dearchived, an issue that should not effect most users.

When an object is to be archived using this technique, the method "archive" is executed for the object. In your archive method, you should include code that might be needed to prepare the object for archiving such as updating variables which will be required when the object is dearchived. Your archive method must, on success, return 1. Any other return value is considered failure and will abort the archive.

When an object is to be dearchived using this method, the method "dearchive" is executed for the object. In your dearchive method, you should include code that might be needed to restore the state of the object, or to inform the rest of the simulation of its presence if necessary. Your dearchive method must, on success, return 1. Any other return value is considered failure and will abort the archive.

To initiate a "whole simulation archive", use the Control method save-as-xml.

An archived world cannot be loaded into a running simulation—to dearchive a simulation saved with this technique, you have to start the simulation with the archive. In the OS X version of breve, this is done from the "File" menu. In command-line versions of the software, this is done by using the "-l" flag, along with the name of the saved simulation file, for example:

            breve -l "myWorld.xml" myWorld.tz

<< previous | Up | next >>
Saving and Loading Individual Objects | Table of Contents | Chapter 12. Networking