Replies: 6 comments 6 replies
-
Tagging @JimOfLeisure , @WildWeazel , @maxpetul as having contributed thoughts on this subject in the past. One advantage of GUIDs is they are globally unique - in multiplayer, each computer could generate a GUID for new player units, and it would be very unlikely that they could collide. The disadvantage is GUIDs are probably the worst option for human readability. Human readability influences my next point - if we want the save/mod format to be human modifiable (without special tools like scenario editors), the things that humans might want to modify should be in a format they can read. To that effect, for terrain types, we started using keys. These are not going to be generated in-game, so it isn't a concern there, but a human might want to modify them in the JSON save/scenario file. The keys are human-readable such as "plains", "ocean", and "grassland". You could add new ones such as "taiga", "savannah", etc. (although right now C7 wouldn't know how to use those new ones). For tiles, an obvious key would be a combination of its X and Y coordinates. If a human wants to add a unit to a tile, being able to refer to it by coordinates would be much more convenient than by a GUID. But for other things, such as units or buildings-built-in-cities, there may not be an obvious "key". I think for these, an integer ID or perhaps even a GUID may make more sense. So my vote may be that it depends on the object, whether it will be generated in-game, and how likely it is that a human will be visually cross-referencing references to it. |
Beta Was this translation helpful? Give feedback.
-
An alternative to GUIDs that would address the issue of length and relatively poor comparison performance would be something like twitter snowflake IDs, which (should) ensure that different clients won't generate the same ID. If we stick with GUIDs, we should be using the Guid struct instead of storing them as strings for performance. |
Beta Was this translation helpful? Give feedback.
-
I hadn't heard of snowflake IDs before (Wiki link: https://en.wikipedia.org/wiki/Snowflake_ID), but it might be appropriate. The machine ID part would be useful in multiplayer, and the millisecond-based time component and sequence part should be more than adequate. It looks like they are stored as just a long string of digits, too? So something that could be stored in JSON. I'm curious about the performance difference? How significant is it? I could see 64-bit snowflakes being quicker than 128-bit GUIDs since it would fit in a regular 64-bit int, but I'd be somewhat surprised if GUIDs were noticeably slow. Good to know there's a GUID object in C#. |
Beta Was this translation helpful? Give feedback.
-
In my early coding, I just punted and used I still don't have an image in my head of how GUIDs would be used. I know we don't want limits, but even a signed Would a default 'plains' tile description have a GUID? Would that be different for each mod? Each game? Does each unit in a game really need a GUID? Seems like a player ID and auto-incrementing |
Beta Was this translation helpful? Give feedback.
-
Apologies for letting this sit for so long, but it's time we figure it out. @maxpetul I don't necessarily disagree with you, but could you elaborate on your objections to GUIDs from the CFC thread? Firstly by GUID do you mean the System.Guid struct specifically, or 32-hex strings, or any long random alphanumeric ID? And is the problem with multiplayer sync that each player would have to produce the same GUIDs? Because you can (re)construct them from known values, and we could make the host responsible for initializing all data. I was also unfamiliar with snowflake IDs as a formal thing, though I've seen similar schemes before. That seems to address the performance and sync concerns, though it's not much more user-friendly for defining content. As I'm thinking more about it though, as @QuintillusCFC touched on above I think there's a case for 2 different types of ID:
|
Beta Was this translation helpful? Give feedback.
-
I largely concur with what WildWeazel wrote. Though for the static content one I'll note that it probably isn't necessary or feasible for unit prototypes/technologies to be globally unique, just unique within a ruleset. E.g. You could have two different mods/scenarios with a unit prototype called "galleon" and the stats could be completely different. Hypothetically, if we somehow allow combining multiple sources of unit prototypes into one rule set, and both define a "galleon" unit, that could cause the combination to be rejected on load, but I'm not sure when we'd be drawing that together? I guess the question is does the benefit of "MyAwesomeC7Mod.Unit.Galleon" outweigh the extra overhead versus just plain "galleon"? |
Beta Was this translation helpful? Give feedback.
-
There has been some discussion regarding object IDs and GUIDs which are currently used to identify cities, map units, and players in this CFC thread. This PR also has some relevant discussion.
Let's weigh the pros and cons of some options such as GUID, incrementing ID, etc. and adopt a standard to implement moving forward.
Beta Was this translation helpful? Give feedback.
All reactions