Not logged inOpenClonk Forum
Up Topic Development / Developer's Corner / Save scenario rework: Save to Objects.c instead of Game.txt.
- - By Sven2 [de] Date 2013-12-23 00:16
When you're building scenarios - especially missions - it's very convenient to draw the landscape, place all objects in the editor and then just click "Save scenario". Unfortunately, that method has always had upwards compatibility problems. The serialization in Game.txt cintained all kinds of internal data and when the underlying object definitions were reworked, things often broke.

This got especially bad now with the increasing use of prop lists and arrays. Since they get enumerated, you end up with an unmaintainable mess of cross references where you cannot just add/remove objects and properties in the proper [Object] sections.

I built a patch that reworks the behaviour on "Save scenario" to serialize all objects into an Objects.c script file instead of Game.txt. By default, only a limited number of properties is saved. If an object wants to save more (or less), it may overload a number of callback function to control writing of the Objects.c file.

Objects.c files may also be used in scenario sections.

Also, note that this does not replace Game.txt. Game.txt serialization is still used for savegames, runtime join synchronization, runtime records and runtime scenario section saves.

The patch can be reviewed here: https://crucible.openclonk.org/cru/OC-5

Here's an example for an auto-generated Objects.c file: http://pastebin.com/E3dJuv2b
Parent - By Newton [th] Date 2013-12-23 04:18
Yeah, cool idea! I always disliked the Game.txt for the same reasons.
Parent - - By B_E [de] Date 2013-12-23 15:53
This is more or less Hazards serialize(), I think? What might also be a nice feature, or at least a function would be serializing only a certain rectangle of the map, so for example if you redesign an area you can only grab the changes.
Parent - By Newton [th] Date 2013-12-23 16:18
The idea is similar, but Sven2's solution is more abstract and thus gives much more flexibility while being even less work for the scenario designer.
Parent - - By Sven2 [de] Date 2013-12-23 16:33

> so for example if you redesign an area you can only grab the changes.


I don't understand this use case. If you store an incomplete Objects.c that contains only objects in an area, then how would you merge this with an old existing Objects.c? Objects are ordered roughly by z-Order and object type, so you would have to copy your changes line by line manually into the existing file.

Independent of that, it would be cool if the editor had options to resize the map in any direction, move objects accordingly and issue script callbacks so e.g. MovingBricks can adjust their stored coordinates.
Parent - - By B_E [de] Date 2013-12-23 17:24
AFAIK this was used extensively when designing CMC maps and generating areas by the scenario script, depending on the chosen goal. Since the script would be the same here one could simply port the Objects.c (or newly designed areas) over to the scenarioscript, without having to write an own implementation of a serialize()-function.
I think it simply might help scenario designers in the future if this serialization functionality was exposed.
Parent - - By Sven2 [de] Date 2013-12-23 18:39

> I think it simply might help scenario designers in the future if this serialization functionality was exposed.


It is exposed. It's all in a script function in System.ocg/SaveScenario.c, which you can copy or overload and make your changes e.g. to store only objects in a rectangle. Though I would argue it would be easier to just write a script that removes all objects outside a rectangle and save afterwards.

It might be interesting to have an editor function that e.g. serializes all currently selected objects and puts the script into the clipboard. But I'm not sure if that's a really high priority, since a) we don't have such big maps yet, b) there are a lot more important things to be added to the editor.
Parent - By B_E [de] Date 2013-12-23 19:44

>It is exposed. It's all in a script function in System.ocg/SaveScenario.c, which you can copy or overload and make your changes e.g. to store only objects in a rectangle.


Okay thanks, all is clear then. I guess I'm not completely used to new stuff being outside of the engine nowadays.
Parent - By Newton [th] Date 2013-12-24 05:23
IIRC Hazard's serialize function did write out objects like CreateObject(Crate, x+234, y+12); enabling one to easily add an offset to the creation script.
Parent - - By Sven2 [de] Date 2013-12-27 02:08
I uploaded a new iteration:

* I combined the SaveScenarioObject / SaveScenarioObjectProps / SaveScenarioObjectExtraProps / SaveScenarioObjectIgnoreProps into a single SaveScenarioObject callback with a proplist parameter that has the remaining interface. E.g.:

func SaveScenarioObject(props)
{
  if (!inherited(props, ...)) return false;
  // Waterfall has its own creation procedure
  props->RemoveCreation();
  props->Add(SAVEOBJ_Creation, "CreateWaterfall(%d,%d,%d,%v)",fx_waterfall.X, fx_waterfall.Y, fx_waterfall.Strength, fx_waterfall.Material);
  // Don't save color modultion
  props->Remove("ClrModulation");
  // Save some properties
  props->AddCall("Direction", this, "SetDirection", XDir, YDir);
  return true;
}


* Actions no longer saved by default
* GetScenarioSaveName renamed to MakeScenarioSaveName
* Interface extended on some objects so Set*-functions can be called instead of setting locals directly
Parent - By Sven2 [de] Date 2013-12-27 03:04
I think I'd also push it now if there are no further remarks.
Parent - - By Sven2 [de] Date 2013-12-27 18:14
I pushed the patch. Thanks for the feedback!
Parent - By Newton [eu] Date 2013-12-30 03:12
No, thank you for that great enhancement! I find it great that you always thoroughly document a new feature, the docs sadly have a tendency to outdate quickly.
Have a nice slide into the new year everyone!
Parent - - By Newton [th] Date 2014-01-10 08:24
There are two scenarios left which still use Game.txt, did you forget to convert them?

Missions.ocf\MineRescue.ocs
Missions.ocf\MtBrame.ocs
Parent - By Sven2 Date 2014-01-10 11:13
I converted only the Game.txts I made myself so far because of those I knew I wouldn't forget anything. I'll convert the others when I find time. Opened a bugtracker entry for now.

Btw, anyone can convert those. Just open the scenario in editor mode, save it, check if everything got saved and check if there's any unnecessary cruft in Objects.c.
- - By Maikel Date 2018-06-23 09:26
Is there any way we can store SetObjDrawTransform for scenario saving?
Parent - - By Sven2 [us] Date 2018-06-23 23:00
You mean add DrawTransform to the default whitelist? Why would you want to do that?

You can always put your transform into the custom init script field of the object.
Parent - By Maikel Date 2018-06-24 09:27
I never used the init script, now I see its use!
Up Topic Development / Developer's Corner / Save scenario rework: Save to Objects.c instead of Game.txt.

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill