CitiesSkylinesMods / PersistencyManager

MIT License
0 stars 0 forks source link

Approach #1

Open kianzarrin opened 2 years ago

kianzarrin commented 2 years ago

I could do this in two ways each of them with advantages/disadvantages: 1- patch NetTool methods so when user adds/removes stuff, I would know. 2- before every simulation step when something is updated, I can check what has changed and then transfer data accordingly.

Approach 1:

Approach 2:

kianzarrin commented 2 years ago

@aubergine10 I have explained what this library aims to achieve in readme: https://github.com/CitiesSkylinesMods/PersistencyManager

I need advice on what approach to follow and what compromises to make.

what do you think about the two approaches above? which one do you prefer?

IMT is taking approach 2 so it can detect changes caused by third party mods even if they don't use nettool. but it is unable to persist segment markups when it is split/merged/moved/upgraded

NS is using approach and therefore it is capable of keeping skins for segments when they move/split/merge/upgrade using nettool but not when this is done by a third party mod.

I think 3rd party mods (i think NMT is the only one that matters to us) can use the MoveItIntegration to copy paste data too and that can also be a solution.

originalfoo commented 2 years ago

What has the least impact on framerate?

Solution 2 sounds like it's eating fps even if nothing changes (which is most frames).

There's suprisingly few mods that alter roads/networks (well, depending on what is considered an "update" to network), and most of them are actively maintained and could thus be updated to use persistency framework.

So, IMO, event driven would be best approach because it avoids bloating simulation step.

kianzarrin commented 2 years ago

@aubergine10

There's surprisingly few mods

here is actually quite a lot:

NC/IMT/NS/TMPE/AN/MoveIT/LaneManager(future)

Solution 2 sounds like it's eating fps even if nothing changes (which is most frames).

No. first of all it checks before every simulation step which takes place in simulation thread which has no influence on FPS. Secondly it only checks nodes/segments that are marked as updated. so it won't even slow down the simulation thread.

What has the least impact on framerate?

Neither approach impact performance.

PS: I think having a unified framework for persistency also makes it easier to add undo/redo operations to it (maybe I need to define an extra API method for this?). This can then be used by Undo it mod or maybe each mod can handle its own undo/redo.

kianzarrin commented 2 years ago

some challenges I need to solve: 1- copy pasting segment ends are challenging since there InstanceID does not support segment end. I managed to shove segment ends into InstanceID though by talking some extreme measures! 2- handling merged segments is easy. the map dictionary<InstanceID, InstanceID> will have two keys mapped into one target. but handling segment split might be a bit more difficult as the same key cannot have 2 different targets (unless if I add some redundancy in InstanceID.RawData or use list instead of dictionary).