Object orientation & code complexity [Multiplayer 4X]
Posted: Wed Jul 09, 2014 3:32 am
I have a client-server turn-based game that I have been making. I am trying to figure out how much data and tables to leave raw versus turning them into class based objects. I am currently using latest version of MiddleClass.
In general, I under utilize objects and mainly keep them for clientside things like GUI widgets and animations. I do this because I tend to use a lot of class inheritance here. However, there are extremely few on the server side.
Here's an example of something I am thinking of turning into an object:
I have a table for each region of a planet. There is a lot of information in each one of these including things like value, owner, units stationed, terrain type, etc.
Currently, a region is stored like:
It gets sanitized of serverside only information and sent to the client where it essentially just becomes
All the functions related to regions are named things like addArmyToRegion(regionName, armyID). This is starting to become a pain with so many functions. I guess I could do something like region.addArmy(regionName, armyID), but it would be nice to do Region:addArmy(armyID), but then I have to start creating these objects again clientside after serialization and transfer from server (and to a lesser extent again serverside with client information).
It would be a lot of work to convert some of these things to objects and I am hesitant since I've gone so far without them. I'm kind of looking for an excuse not to do it and I have a feeling I'm overlooking something. I've tried the MiddleClass performance tests and it appears I could make an almost unlimited number of objects without performance problems...unless there's a memory use problem or if object creation is going to make garbage collection more difficult somehow? I also have the current code support a listen server where the player is a client and host in the same executable. [I don't know if that really is going to make a difference here].
TLDR: Should I make absolutely everything possible a class object to better group functions, realizing that this will mean more work making objects after accepting serialized data, or should I only use class objects for things that have a lot of inheritance?
In general, I under utilize objects and mainly keep them for clientside things like GUI widgets and animations. I do this because I tend to use a lot of class inheritance here. However, there are extremely few on the server side.
Here's an example of something I am thinking of turning into an object:
I have a table for each region of a planet. There is a lot of information in each one of these including things like value, owner, units stationed, terrain type, etc.
Currently, a region is stored like:
Code: Select all
ServerGalaxy.Planets.Earth.Regions['North America'] = {Tons of values}
Code: Select all
ClientGalaxy.Planets.Earth.Regions['North America'] = {Mostly same values}
It would be a lot of work to convert some of these things to objects and I am hesitant since I've gone so far without them. I'm kind of looking for an excuse not to do it and I have a feeling I'm overlooking something. I've tried the MiddleClass performance tests and it appears I could make an almost unlimited number of objects without performance problems...unless there's a memory use problem or if object creation is going to make garbage collection more difficult somehow? I also have the current code support a listen server where the player is a client and host in the same executable. [I don't know if that really is going to make a difference here].
TLDR: Should I make absolutely everything possible a class object to better group functions, realizing that this will mean more work making objects after accepting serialized data, or should I only use class objects for things that have a lot of inheritance?