Best practices Ashley + box2d

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Best practices Ashley + box2d

Postby bmanmcfly » Thu Jan 02, 2020 5:41 am

I've tried searching for this to no avail.

I'm at a point where I would benefit by converting most of the data to save / load so that I can refine some variables to fine tune things. Where possible am trying to keep within Gdx explicit tools.

The last time I was saving, it wound up being this huge cumbersome process where I made a static class 'descriptor' for each entity type.

The ashley github page got my hopes up with the 'serialization' folder that was not included with what gradle provides with non-snapshot versions.

SO, the ultimate question here is how to go about properly saving the world data?

My setup as is; the game screen creates the engine / systems.
The 'worldSystem' is what controls the map data, loading and unloading entities, swapping maps, etc. It's essentially the core system.

Entities have components, some that would be saved, some just a string or something which can be used to 'decode' and rebuild from the file, others are holders of images or animations that don't need to be saved.

Thanks for any pointers.
bmanmcfly
 
Posts: 47
Joined: Fri Oct 30, 2015 4:09 am

Re: Best practices Ashley + box2d

Postby shatterblast » Thu Jan 02, 2020 6:38 am

You could try a mix of JSON data and ObjectBox for cross-platform compatible storage. If you just need to store data in a save file, then you can still write JSON data to a blank file.
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Re: Best practices Ashley + box2d

Postby bmanmcfly » Mon Jan 06, 2020 12:24 am

shatterblast wrote:You could try a mix of JSON data and ObjectBox for cross-platform compatible storage. If you just need to store data in a save file, then you can still write JSON data to a blank file.


I believe I can make it with only JSON, the last time I had gone through the effort, I just wound up doing everything manually.

I was hoping that there might be a simpler way than to have:

- Player components
- player descriptor (to prototype the save / load file)
Ex: public static class PlayerDescriptor { string map, float x,y, etc }
- a player loader that would repeat the parts of the descriptor
That would actually load the json file.

Now, doing things like that gets real redundant, so I was hoping there's a better approach, and just thought I'd ask before reinventing the wheel for a different project.

I was thinking of making each of the components serializable, and then could just pass the JSON file to all the components that need it.

Thanks for pointing to ObjectBox, that seems useful.
bmanmcfly
 
Posts: 47
Joined: Fri Oct 30, 2015 4:09 am

Re: Best practices Ashley + box2d

Postby shatterblast » Mon Jan 06, 2020 4:17 am

LibGDX has Preferences available, so that you can keep together non-vital settings, like the user's preferred volume level and the current network status. ObjectBox might serve better if you want to keep a large number of designs organized, like level layouts and monster stats. You might use GitHub to find decent examples of LibGDX's Preference class at work. Not all are equal.

Link 3) has one valid example.

1) https://github.com/libgdx/libgdx/wiki/Preferences
2) https://libgdx.badlogicgames.com/ci/nig ... ences.html
3) https://github.com/bornander/nine-levels
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Re: Best practices Ashley + box2d

Postby bmanmcfly » Wed Jan 08, 2020 10:53 pm

shatterblast wrote:LibGDX has Preferences available, so that you can keep together non-vital settings, like the user's preferred volume level and the current network status. ObjectBox might serve better if you want to keep a large number of designs organized, like level layouts and monster stats. You might use GitHub to find decent examples of LibGDX's Preference class at work. Not all are equal.

Link 3) has one valid example.

1) https://github.com/libgdx/libgdx/wiki/Preferences
2) https://libgdx.badlogicgames.com/ci/nig ... ences.html
3) https://github.com/bornander/nine-levels


Thanks for the links; I did have intention to make use of preferences at a later point for sound, music and some options. Looking at those samples, the preferences seems more powerful than I had expected.

Anyway, I hadn't really had the chance to test things thoroughly as I might have liked, but I did find something with promise. It seems that we can cycle through the entities, and cycle through the components of each entity, and serialize each component.

Code: Select all
foreach (Entity entity : entities){
     foreach (Component comp : entity.getComponents(){
            Add component to json
    }
}

Where marking each unneeded variable as 'transient' prevents it from being added.

Will check back if I can add a solved tag for others in the future.
bmanmcfly
 
Posts: 47
Joined: Fri Oct 30, 2015 4:09 am


Return to General Development

Who is online

Users browsing this forum: No registered users and 1 guest