Property based pattern for a game.

I’m developing a game using Property Pattern.

My idea is to use Map<String, Object> (Actually ImmutableIntToObject maps using gs collections) for storing any type of property except classes. I would like to know if anyone had done this in the pass and how does it perform.

My current code is https://github.com/Argentum-Online/Argentum-Online/tree/master/world-model/src/main/java/com/ghrum/argentum/model and an example would be https://github.com/Argentum-Online/Argentum-Online/blob/master/world-example/src/main/java/Example.java

I’m using a functional and data driven pattern for conditions and actions of each stuff.

Thanks!.

You’ve pretty much described what the Properties class already does. Why not just use that?

Recommended reading:

https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html

https://docs.oracle.com/javase/tutorial/essential/environment/properties.html

Wouldn’t be better to use an ImmutableIntObjectMap (GS Collection) that rather using Properties which fallsback to Java’s collection?

For some perceived definition of better, it probably is.

Why?

Really the only way to answer this is to do some profiling. But I would be pretty surprised if you notice any huge differences in performance for something like this. Just go with whatever fits in your head the best, without reinventing the wheel too much.

So i took your advice and did some profiling.

All test has been made using https://github.com/msteindorfer/memory-measurer with 60.000 items in it.

Map<String, Object>: 7868368 bytes
Properties: 6615232 bytes
IntObjectMap (GS-Collection): 3128664 bytes
(MutableIntFloatMap and MutableIntObjectMap<byte[]>) -> Since i only need Strings and numbers: 1768744 bytes

Not really sure what you are trying to achieve here? Do you want low memory usage?

Also can you post the code for all your tests? I’m surprised the best and worst times have a 4x difference so would be interested in what you actually compared against.

And those numbers aren’t really all that high. Are they different? Absolutely, and they’re going to be. But 6 MB is nothing, especially if it’s easier to use, maintain, etc.

If you want to create something just for the fun of it, go for it. But it seems like you’re over-engineering a pretty solved problem, imho.

But like I said: if it sounds fun to program, then program the heck out of it!