Jump to content

  • Log In with Google      Sign In   
  • Create Account


tharealjohn

Member Since 12 Nov 2011
Offline Last Active Jan 23 2014 01:49 PM
-----

Topics I've Started

How? - Loading Unity Terrain Async without Pro or Asset Streaming

12 July 2013 - 01:34 PM

Question: How can I offset some of the load of creating Terrain objects procedurally using a separate thread?

Background: I have been trying to get an "infinite" terrain system going using the Terrain objects in unity. I am procedurally creating the TerrainData objects, and then creating a Terrain object like this:

var t = Terrain.CreateTerrainGameObject(terrainData).GetComponent<Terrain>();

 

 

I need to keep track of my t objects so I know how many and which Terrains have been created. I am following a basic Tile grid, where each Terrain object is thought to be a Tile in the grid, located at coordinates like (0,0), (0,1), etc. The TerrainData object has all of its values and height mapping done using Perlin Noise. As I walk around I "cull" unneeded tiles of the Terrain that are "too far" away from the player. This results in a "rolling" set of 9 tiles surrounding the player, which is always at the center tile.

Here is where the question comes in. Creating the Perlin values for the TerrainData, along with the height map is very CPU intensive. I would like to do this on a separate thread, but because the TerrainData and Terrain objects are so closely linked, and they cannot be accessed on another thread, I am not sure how to architect my situation so I can use a separate thread for the Perlin and Height mapping bits.

An example of what I have (simplified):


List<Terrain> terrain = new List<Terrain>();
...

public Terrain CreateTerrain(int x, int y)
{
    // CPU intensive work
    CreateHeightMapValues(heightMap);

    // Fill in TerrainData values (I dont think this has to be done on the main thread)
    var td = new TerrainData();
    ....

    // Create the actual Terrain (Has to be done on the main thread)
    var t = Terrain.CreateTerrainGameObject(terrainData).GetComponent<Terrain>();

    // set position, etc.
    ... (misc work)

    return t;
}

I would like to wrap that CPU intensive work somehow in another thread, but because I need to return that Terrain object so I can add it to my List terrain, I cant just throw it off on another thread, because Ill need to wait anyway to create the actual Terrain object.

 

Can anyone suggest how to break it apart a little better so that I don't rely on the direct creation being linked to when I can add it to the list of terrain objects?

Note* That list is so I know how to destroy/create them when the player moves. It would also be nice to Destroy the Terrain object on a seperate thread so it doesnt lag the UI, but I dont think that is possible do to Unity's non-threadsafe environment.

 

I originally posted on Unity Answers, but thought this might be a good place too, as it is not 100% Unity specific, since it is mainly a architectural problem. Knowledge of Unity and its limitations is probably helpful though.

 

Also note that creating the threads and being able to invoke back on the main thread in Unity are not my problems, I have that code figured out. I just dont know how to use it effectively given the issues I mentioned above about 1 thing being needed for the other.


Xbox One and Indie Dev

24 May 2013 - 10:21 AM

I have been following some of the new Xbox stuff like most of you probably are too. I am surprised to not really see anything M$ is doing to promote indie development. Is there some information I am missing? They killed XNA, closed the game studio, and now DRM the @#$@ out of Xbox? I don't get where they're going with this thing. I can see some obvious points that they want to make the Xbox an "all in one" entertainment piece or something, but what about the gaming part? Isn't that what the Xbox should excel at? I mean, why would I buy a new Xbox as a media device when my PS3 already does most of my media needs? 

 

I am confused as to why they didn't jump on supporting indies better, like other companies are doing...


What happens when your "good idea" has been already made?

12 May 2013 - 05:57 PM

So a friend of mine and myself have been working on a game we came up with for a while, and its been coming along. We have been keeping it quiet because we felt it was a really good idea, and really liked where it was going. However, just yesterday I was on IndieDB, and I saw a game pop up on the banner, and it looked really interesting (meaning it looked a lot like the game we were making). I took a look at it, and it was really awesome, and it was everything we are doing and more. Not only that, but they already have a playable game that is for sale on Desura, and just launched a Kickstarter to "finish it". 

 

As amazing as the game looks, it was like a punch in the heart because it seriously demotivated me from continuing my project. I don't need to have an original concept (if that even exists anymore) but I don't really want to make a game that is basically this other game, only they have some more features that would be everything I wanted this game to become. 

 

What would you do in this situation? Has anyone had this experience? If so, what was the outcome?

 

EDIT: Interestingly, I came across this gamasutra post that was an interesting read on the subject:

 

http://gamasutra.com/blogs/MikoCharbonneau/20130510/192111/Coping_with_Comparison.php


XNA and loops

22 June 2012 - 06:37 PM

Hello,

I am working on a tower defense game using XNA 4.0.

I have gotten to a point where I am questioning if I am doing things the right way, and if there is a better to do some of what im doing. For the most part, most of my logic seems to be countless foreach or for loops going through lists of enemies or towers, etc and apply some calculations or conditionals on properties.

I feel like the more complex my game will get, the more lists and loops Ill have to add to check each enemy and tower for information. As the lists grow, the game starts to slow down. How can I handle this differently?

Basically my level has a List<Enemy> enemies and a List<Tower> towers.

In an public void Update(GameTime gameTIme) function there are a few foreach loops doing some logic on positions, alive, distance, etc.

Suggestions on how to handle this better?

Thanks,

Handling textures with XNA and inheritance

16 November 2011 - 01:47 PM

Hello,

I am having some architecture level problems with my application. I am new to OOP and am seeing some problems with how I have things layered in my code. This is kind of a general OOP problem, but I posted in here so that someone may be able to make specific references to XNA to help me with example fixes.

Here is an example of what I have:

Base class for handling sprites:
public Sprite(Texture2D spriteTexture, Vector2 spritePosition, Rectangle textureSourceRectangle)


This class handles the drawing of the texture I want from a sheet of textures given the parameters.

I want to inherit from this for all other classes that will be drawn to the screen. So I have something similar to:

public class DrawMe : Sprite


public DrawMe(Texture2D drawTextures,  Vector2 position)
            : base(drawTextures, position, drawMeSource)


The problem is with the DrawMe class, I want to be able to define that class as having a drawMeSource that is only for the DrawMe class. This way I can make a new class (DrawYou) that can define a different textureSourceRectangle. I'm not sure how to implement this. The base constructor gets called before the derived so Im not sure how to pass in a special value for drawMeSource without passing it from the constructor of DrawMe. I do not want to define the drawMeSource in the constructor of DrawMe because every time I need a new object of DrawMe I do not want to have to define the same source rectangle.

I feel like it should be a field and/or a property of the DrawMe class but how do I implement this to keep this structure?


If this is completely bad design by some opinion, what do you suggest a better architecture for handling this scenario is?


Thanks for any help,

John

PARTNERS