Ok guys I've got an idea for aIn my game, while it is only an idea, it doesn't mean I'm going to make it, but its probably a common problem.
I have a plotthere are plots of land with buildings (one of a few in the game) on the land I build a building(1 of a few on the plot) such as a house or ahouses, resource creator (like wood millcenters) a house can. Buildings like houses have a tenant (of a certain social class) a house hastenants, rooms (which are of a certain standard) a house has, add ons like double glazing-ons, et cetera, and other stuff
now the building needs to be maintained. the tenant hasthere are several values which needthat have to be calculatedsimulated based on the plot of land and state of the buildingall these variables.
Now, I'd like to use AndEngine for the front end stuff, and create another thread to do the simulation calculations perhaps(perhaps also later include AI in this thread). ThisThis is so that one whole thread doesn't do all the work and cause problems such as blocking, so using a thread makes sense to me.
So this This introduces the problem of concurrencyconcurrency and dependencydependency.
The thread would need to update the tenant values based on values from the plot of land, the building and the tenants social class expectations. It also also update the object animations if they are currently visible(such as a tenant outside the building = create sprite)
So the currency problemcurrency problem is my main uiUI thread and the calculation thread would both need to access all thesethe simulation objects. So I have to make them thread safe-safe, but I don't know how to store and structure the simulation objects? to enable that.
The dependency problem (I think this is a problem, but I might be getting confused)dependency problem is that in order to calculate values, my calculations depend on other objectsobjects' values. If I wanted to some testing, then wouldn't his be a problem? I may be thinking to hard and creating a problem all in my head.
As for calculations, The general idea is: if room 1 is standard low then increase value x by n
HowWhat would Ibe the best way to link up my tenant object in the building with my calculations? hard codeHard-code it into the tenant class? whatWhat is a good way to do store, if you like,"store" algorithms so they are easily tweaked?
A simple lazy way would be to bung everything into a class which holds all the object, such as plots of lands (who in turn hold the buildings etc etc), itet cetera). This class would also hold game state such as the technology available to the user, object pools for things such as sprites. Oh yeah and make it a singleton!!! butBut this is a lazy and dangerous way (correct?)
So how about do I do I solve this problem. of structure of objects for threading, the concurrency (without using singleton) dependency problem of other objects needing other object values? how to store algorithms (how I want to calculate thingscorrect?)
I'm not too worried about resources as the first step would be to at least get a design that is reliable and is testable, but suggestions are welcome.
editEdit:
I I was looking at Dependency injectionInjection, but how well does that cope with like a class that holds other objects? ie Myi.e, my plot of land, with a building -, which has a tenant and a rafthost of other values. DIDI looks like a pain in the bum with AndEngine as well.