Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The only important requirement here is to provide a deep copy constructor that stores all necessary information (or if that's not possible, a method to get all the required info). Then use that ctor/method to create a second vector. Something like:</p> <pre><code>class Object { RenderObject * m_Renderable; int m_Health; float3 m_Position; Object(const Object * other) : m_Renderable(nullptr), m_Health(other-&gt;m_Health), m_Position(other-&gt;m_Position) { }; Object * GetStorable() { return new Object(*this); } }; </code></pre> <p>then to store "checkpoints", you simply do:</p> <pre><code>vector&lt;vector&lt;shared_ptr&lt;Object&gt;&gt;&gt; gCheckpoints; vector&lt;shared_ptr&lt;Object&gt;&gt; gLevelObjects; vector&lt;shared_ptr&lt;Object&gt;&gt; checkpoint; std::for_each( gLevelObjects.begin(), gLevelObjects.end(), [&amp;](shared_ptr&lt;Object&gt; obj) { checkpoint.push_back(obj-&gt;GetStorable()); }); gCheckpoints.push_back(checkpoint); // creates a new checkpoint </code></pre> <p>You will need to recreate the render information for the objects when the checkpoint is restored; this is a requirement for most save systems in most graphics contexts, however.</p> <p>Depending on how your <code>Object</code> class is set up, you can also inherit from another class that consists <em>only</em> of the stored data, and simply store that and create the renderables from it when necessary (<code>class RenderObject : StoredObject { ... };</code>).</p> <p>You can alternatively serialize the objects in some fashion (binary save, xml, json) and store that to a file (autosave/quicksave/checkpoint) or in-memory, and then use your regular loading mechanism to load that specific file.</p> <p>The best method depends on what your plans are and how your system is set up, but this concept should provide the basics or give you a starting point.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload