Skip to main content
Tweeted twitter.com/#!/StackGameDev/status/122024097612967936
trimmed the question down to reduce "wall of text" factor
Source Link
user1430
user1430

Structure of How should I structure my classes - dependency and threading - calculationsto allow for multithreaded simulation?

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.

Structure of classes - dependency and threading - calculations

Ok guys I've got an idea for a 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 plot of land (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 a resource creator (like wood mill) a house can have a tenant (of a certain social class) a house has rooms (which are of a certain standard) a house has add ons like double glazing and other stuff

now the building needs to be maintained. the tenant has values which need to be calculated based on the plot of land and state of the building.

Now I'd like to use AndEngine for the front end stuff, create another thread to do the calculations perhaps also later include AI in this thread. This 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 introduces the problem of concurrency and dependency.

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 problem is my main ui thread and calculation thread would need to access all these objects. So I have to make them thread safe, but how to store and structure objects?

The dependency problem (I think this is a problem, but I might be getting confused) is in order to calculate values, my calculations depend on other objects 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

How would I best link up my tenant object in the building with my calculations? hard code into the tenant class? what is a good way to do store, if you like, 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), it 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!!! but 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 things?)

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.

edit

I was looking at Dependency injection, but how well does that cope with like a class that holds other objects? ie My plot of land, with a building - which has a tenant and a raft of other values. DI looks like a pain in the bum with AndEngine as well.

How should I structure my classes to allow for multithreaded simulation?

In my game, there are plots of land with buildings (houses, resource centers). Buildings like houses have tenants, rooms, add-ons, et cetera, and there are several values that have to be simulated based on all these variables.

Now, I'd like to use AndEngine for the front end stuff, and create another thread to do the simulation calculations (perhaps also later include AI in this thread). This is so that one whole thread doesn't do all the work and cause problems such as blocking. This introduces the problem of concurrency and dependency.

The currency problem is my main UI thread and the calculation thread would both need to access all the simulation objects. So I have to make them thread-safe, but I don't know how to store and structure the simulation objects to enable that.

The dependency problem is that in order to calculate values, my calculations depend on other objects' values.

What would be the best way to link up my tenant object in the building with my calculations? Hard-code it into the tenant class? What is a good way to do "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, et cetera). This class would also hold game state such as the technology available to the user, object pools for things such as sprites. But this is a lazy and dangerous way, correct?

Edit: I was looking at Dependency Injection, but how well does that cope with like a class that holds other objects? i.e, my plot of land, with a building, which has a tenant and a host of other values. DI looks like a pain in the bum with AndEngine as well.

Source Link

Structure of classes - dependency and threading - calculations

Ok guys I've got an idea for a 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 plot of land (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 a resource creator (like wood mill) a house can have a tenant (of a certain social class) a house has rooms (which are of a certain standard) a house has add ons like double glazing and other stuff

now the building needs to be maintained. the tenant has values which need to be calculated based on the plot of land and state of the building.

Now I'd like to use AndEngine for the front end stuff, create another thread to do the calculations perhaps also later include AI in this thread. This 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 introduces the problem of concurrency and dependency.

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 problem is my main ui thread and calculation thread would need to access all these objects. So I have to make them thread safe, but how to store and structure objects?

The dependency problem (I think this is a problem, but I might be getting confused) is in order to calculate values, my calculations depend on other objects 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

How would I best link up my tenant object in the building with my calculations? hard code into the tenant class? what is a good way to do store, if you like, 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), it 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!!! but 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 things?)

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.

edit

I was looking at Dependency injection, but how well does that cope with like a class that holds other objects? ie My plot of land, with a building - which has a tenant and a raft of other values. DI looks like a pain in the bum with AndEngine as well.