How do we realize progress-tasks in an ecs ? Lets say we want to chop a tree... player moves to the tree and once he collides with that tree we wanna trigger that task... chopping for example takes 15 seconds and once its finished the player receives 1 log... the task stops if the player moves...
With my current knowledge i would simply make that task a entity with a simple condition that destroys the task once the player moves, a callback or event entity every task tick and one callback/event entity once the task was finished.
Would you do it the same way ? Is this considered clean ? :p
Damn... this is a hard one... my update system runs after the saving system in another thread. But sometimes it may happen that theres nothing to save but to update... it collects all objects to update and creates a query... the mainthread modifies a object enlisted for being updated... this results in a broken query which can not get executed, because one of the objects is now referencing another object which is not in the database yet.
user92578
If your save system doesn't immediately snapshot, you've introduce a data race anyways?
user92578
Update system moves an object -> Save system writes updated X and Y coordinates but previous Z?
@Tyyppi_77 Im using a framework to save those classes to the database... as far as i know hibernate only supports "Snapshots" for database acess, not for the objects we wanna save :/
user92578
5:08 PM
If there's no way to make a copy of the state, I don't think you can avoid a lock
Soo... it really looks like we only have three valid options... either the lock @Tyyppi_77 mentioned... or that the object that causes this issue simply dont get inserted into its parent till it was saved ( Which causes other gameplay related issues )... or the last one : No constraints... but that could cause database incosistence... thats awfull :/
@Pikalek It does not... probably i missed this. It only saves entities marked as "saved"... when theres none, it sleeps :) the problem here is that due to the multithreading the update system contains a object that references another object which has not been safed yet... (Updating all chunks -> Trees spawned and getting inserted into chunks -> During construction of the updating query -> Database error )
That was point - if something can't happen with a direct conflict, then that would be the first place I would start with in order to prevent a situation involving an indirect conflict. Since you've solved it though, carry on.
@Pikalek The issue with updating a entity referencing an other (not saved) entity is still here ^^ i mean i solved the other issue, that the update system only updates entities which already have been saved
Is this referenced entity meant to be saved, and it just hasn't had its turn yet because it's new? Or is it fundamentally not part of the serialized state?
@DMGregory Pretty much the first part... pastebin.com/BD1cmXKX heres a little example of how the data-structure looks like... it happens when we update a chunk and a new tree spawned recently but was not saved yet
Actually its part of the terrain generation ^^ the terrain gets once generated and stored to the database... once a player visits the same place, it loads the same state as before
some players want to plant trees... or other stuff, so i thought its a good way to realise it this way
Usually you wouldn't save it until it's modified. If it hasn't been modified yet, you can just re-run the generator with the same seed and get the same result as loading the saved, unmodified version.
@DMGregory Thats new... i guess im doing this totally wrong. I never used anything like seeds. I simply randomly place trees, store them all to the database and once a player visits the area they are getting loaded back in :/ thats why i save them instant, without waiting for being modified ^^
It's also surprising to me that you're querying your database in the middle of your update loop. I'd expect you'd query the DB when moving to a new area that needs to be loaded, but that everything being iterated in your update loop exists in memory.
@DMGregory Oh thats what im doing ^^ Once a player enters a new chunk, we gonna load that chunk and all its objects into the memory... the saving/updating meanwhile occurs during the player loop async... thats why its so much trouble :/
I could probably try a different approach... reflection, simply checking each field and if we detect a referenced object that hasnt been saved yet we simply ignore that entity from being updated... it would work for every object, but could get kinda slow... probably not that important because its not the mainthread at all