Serialization and data transfer from CRunObject to CEditObj

This forum is currently in read-only mode.
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • There are several problems I'd like to clarify ^^. Working in C++ is really painful for me so tests would take hours ><'. You Devs probably know answer ^^.

    1. Serialization order

    Let's say I've fields: myVal1, myVal2 in EditObj, and fields: myFirst, mySecond in RuntimeObj. How should I do serialization stuff in code (serialization.cpp). Is this solution correct (treating 'ar' as stack):

    /////////////////////////////
    // RUNTIME serialization
    void ExtObject::Serialize(bin& ar)
    {
    	if (ar.loading) 
    	{
    		ar >> mySecond;
    		ar >> myFirst;
    	}
    	else 
    	{
    		ar << myFirst;
    		ar << mySecond;
    	}
    }[/code:cwqirkhd]
    [code:cwqirkhd]/////////////////////////////
    // EDITTIME serialization
    void EditExt::Serialize(bin& ar)
    {
    	int Version = 1;
    	SerializeVersion(ar, Version);
    
    	if (ar.loading) 
    	{
    		ar >> myVal2;
    		ar >> myVal1;
    	}
    	else 
    	{
    		ar << myVal1;
    		ar << myVal2;
    	}
    }[/code:cwqirkhd]
    
    2. Passing values from EditObj to RuntimeObj
    Created RuntimeObj stores handle to EditObj to have access to its data and stuff. Let's say I've two values in EditObj: myVal1 and myVal2. I want to make use of them during Runtime as well (by ACE Methods). Do I need to make fields "myVal1, myVal2" in RuntimeObj as well and duplicate data from EditObj in method "void ExtObject::OnCreate()", or maybe I can access EditObj fields from ACE Methods and not worry about making fields at RunTime Object?
    
    3. Serialization in runtime
    This question is somehow related to #2. Surely serializing object in Runtime is used for QuickSave/QuickLoad its state. When making QuickSave in runtime, does corresponding EditObj data serialize as well?
  • 1. Serialization order

    Let's say I've fields: myVal1, myVal2 in EditObj, and fields: myFirst, mySecond in RuntimeObj. How should I do serialization stuff in code (serialization.cpp). Is this solution correct (treating 'ar' as stack):

    /////////////////////////////
    // RUNTIME serialization
    void ExtObject::Serialize(bin& ar)
    {
    	if (ar.loading) 
    	{
    		ar >> mySecond;
    		ar >> myFirst;
    	}
    	else 
    	{
    		ar << myFirst;
    		ar << mySecond;
    	}
    }[/code:1xb4pd11]
    [code:1xb4pd11]/////////////////////////////
    // EDITTIME serialization
    void EditExt::Serialize(bin& ar)
    {
    	int Version = 1;
    	SerializeVersion(ar, Version);
    
    	if (ar.loading) 
    	{
    		ar >> myVal2;
    		ar >> myVal1;
    	}
    	else 
    	{
    		ar << myVal1;
    		ar << myVal2;
    	}
    }[/code:1xb4pd11]
    

    If you save myVal1 first, then you should load it first, instead of loading myVal2 first. That'd mix up the data.

    2. Passing values from EditObj to RuntimeObj

    Created RuntimeObj stores handle to EditObj to have access to its data and stuff. Let's say I've two values in EditObj: myVal1 and myVal2. I want to make use of them during Runtime as well (by ACE Methods). Do I need to make fields "myVal1, myVal2" in RuntimeObj as well and duplicate data from EditObj in method "void ExtObject::OnCreate()", or maybe I can access EditObj fields from ACE Methods and not worry about making fields at RunTime Object?

    Data which is serialized at edittime can then be loaded similarly in OnCreate, like this:

    void ExtObject::OnCreate()
    {
    	// Load settings
    	bin ar;
    	ar.attach(info.editObject->eData, info.editObject->eSize);
    
    	int Version = 0;
    	ar >> Version;
    
    	ar >> tile_width >> tile_height >> speed >> play_if_stopped;
    	ar.detach();
    [/code:1xb4pd11]
    
    Two important things to note:  you must load a blank version number (as the edittime saves one), and you must call ar.detach() after you've loaded your data.  It's up to you whether you store the loaded variables (as above) or just define them locally in the function for using when creating the object.
    
    

    3. Serialization in runtime

    This question is somehow related to #2. Surely serializing object in Runtime is used for QuickSave/QuickLoad its state. When making QuickSave in runtime, does corresponding EditObj data serialize as well?

    The runtime serializing is used for quicksave/load, yes. The edittime data is gone by this point, so if you need it, get it in OnCreate and keep it in your run object.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks. That explains everything ^^.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)