Game settings in an Zay-ES based server/client

Hey

Just wanted to reach out and see what your thoughts are on how to keep your game settings in a Zay-ES based networking game. I currently have a system that loads settings from files - and im wondering what other people do with them once you have your game settings then. Do you create an entity, and let other systems and the clients watch that specific entity, in case they need to know what setting is “currently in play” or do you have other ways to do this ? I guess now that I think about it, a “settings” entity seems very logical and easy to implement solution - but im keen to get input.

Following that thought, other systems watch this entity, and when needed, they pull the desired setting-component (input welcome on the design here) and put that to use. The setting could have changed since last time the system pulled the info, so a re-poll is always needed in my case.

Can you elaborate what do you mean by “settings”? Give an example, please.

Edit:
It would be an abuse to use ES for saving app settings.
I would suggest using Java Properties API and for user preferences the Java Preferences API.

Game settings. Like the default speed that an entity has, say a bomb has a default speed, physics mass etc. Where do you keep those things that affect game play

Sounds like the Bomb should be an entity. With components like Position, Physics etc. Where Position contains position & rotation. Physics maybe the mass and the speed? Visual maybe the It is up to you find a logical solution how you want your components to spread out for the entities.

Oh that part I got down. Totally agree.

But I’m wondering about the data structure for keeping those default settings somewhere (not asking about the entity itself, but rather, where do you find the data that you instantiate the entity with)

Ah ok, got you now what you mean. Well, maybe you cook your own editor and dataformat with JSON/XML/whatever…

Ah, I see now. What you refer to is called a “Prefab” or “Blueprint”. I am using JSON for creating them. (Using Gson library for loading them)

1 Like

Not sure how json works. Lets say I have prefabs lying in json, I build my entities from those etc. and its all good. How would it work, if I wanted to change those prefabs run-time, say, change the speed of the bomb entities that my ship is firing off.

Is this something that there is a game use-case for or is it “I just want to tweak things as a developer”?

Because the former implies that this is power ups or something and the latter is a ‘game dev’ mode where you can adjust the “loaded from JSON” config directly and potentially save it back out again.

The reason is that I have different “games” in my server. One game requires one set of game settings for the entities, another game requires a different set of game settings. Same prefabs of entities, they just act differently depending on which sub-game the player(s) are currently “in”.

I guess I am wondering how other people keep track of their “current” game settings (no matter how many different ones they need). Are they json-based prefabs (and what does an example of that look like), are they kept in a static class, are they kept in a hashmap/some other lookup, are they kept in an entity

Edit:
Or rather an example: Player can choose a class. Every class has access to the same basic weaponry, but depending on the class, they act differently. So the same prefabs for all classes, just different values going into those prefabs (im guessing how prefabs work)

I try really hard to only keep game objects in my entities. I’ve regretted it nearly 100% of the time that I strayed from this rule.

Thanks, so would you send client(s) information about game settings (if needed) through RMI then ? (say you want to display the stats of the weaponry, or stats of the spaceship you can choose or the car you can drive)

Wait, those could be game objects as well I guess

Yes, game assets. Start speed of a bomb is not much different than some animation on a mesh… in fact, the two may be closely related in some cases if the bomb drops as a result of an animation.

This is an example entity prefab I have. It has 4 components, ObjectType, ModelInfo, Mass, CollisionShape.

{
  "components": [
    {
      "class": "ObjectType",
      "type": "Character-1"
    },
    {
      "class": "ModelInfo",
      "category": "character",
      "modelNumber": 1
    },
    {
      "class": "Mass",
      "mass": 30.0,
      "type": -1
    },
    {
      "class": "CollisionShapeInfo",
      "id": "Character-1"
    }
  ],
  "linkedEntities": []
}
1 Like

That I would beg you to elaborate. Would you send assets through RMI ? In my game (for now) I ship the client with a multitude of different tilesets/graphics and lots of different audio, but may only need a small percentage based on what the server decides to use. Will need to look into some form of streaming at some point I guess

I guess for now I will try with my current approach and have a SettingsSystem on the server that loads the game settings - maybe I’ll consider moving to json based import/export at some point, and then have other systems ask the SettingsSystem when they need to look up values (when setting entity components).

If the client needs to know any about any game settings, I’ll send that through RMI.

I guess what I’m wondering is how do you guys do this part (of what I wrote above):

then have other systems ask the SettingsSystem when they need to look up values (when setting entity components).

Do all the server systems access/use the json prefabs when setting components/creating entities?

I don’t want to be that guy, but what is wrong with hard-coding them?
Unless users/other devs or something should influence the values, I don’t see a reason for making them really dynamic.

Think of it like this: You changed the bomb speed. All Clients probably need to know this change as well and with a new build (and thus probably a connection refuse) you have a clear way. You don’t even need RMI for things that will never change.

Unless every game server has different bomb settings (think: difficulty)

Yes, when a system wants to spawn an entity of a specific entity prefab type it calls
GameEntities.createEntity(ObjectType type, EntityId entityId);

/**
 * A registry of common game entities that can be looked up by ObjectType ID.
 *
 * @author Ali-RS
 */
public interface GameEntities {

    /**
     * Registers the specific prefab for the specified ObjectType such that
     * subsequent calls to loadPrefab(type) will resolve to that prefab. This can
     * be used to bypass any (potentially expensive) entity prefab loading
     * that the GameEntities implementation might be attempting for registry
     * misses.
     */
    public EntityPrefab register(ObjectType type, EntityPrefab prefab);

    /**
     * Returns the entity prefab for the specified type. This will
     * generally reuse EntityPrefabs (without cloning) if they have already
     * been loaded or registered... though ultimately it is up to the specific
     * implementation of GameEntities.
     */
    public EntityPrefab getPrefab(ObjectType type);

    /**
     * Make an EntityPrefab from the specified entity.
     */
    public EntityPrefab makePrefab(EntityId entityId);

    /**
     * Instantiate an entity of the specified type. If the specified entity ID is null
     * a new one will be created else it will be used.
     */
    public EntityId createEntity(ObjectType type, EntityId entityId);
}

No, in modern post-1990s time, you’d have to threaten me with cutting my balls off to use Java’s RMI. It was neat and novel in 1995.

I generally include my assets in my game. And if I weren’t, I’d put them on the web and download them as part of startup.

Edit: I’ve thought about it some more… if forced, I might be willing to give up my left testicle to avoid having to generate skeleton classes and stuff. But not both of them.

If you meant JME’s SpiderMonkey RMI then we get into a frequently repeated argument about all of the already-built-into-Java better things you could be doing instead of writing 1000 lines of code to make spider monkey serve asset binaries.

I second this as someone who went down that track. Now I used Netty.IO for my networking stacks and don’t bother with SpiderMonkey. There are just too many limitations in how it is implemented. But for serving actual assets (such as models and what not) use http, it is clean and easy to implement, and then it is not tied to client specific technology so you can port your client to different platforms and still have a universal way to download the assets.