Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualDrakken255

Posted 12 August 2012 - 06:23 PM

By the Gods... How did they manage such lighting!?!? The main problem I am running into now is gathering all the instances into one array for drawing. It is taking too much time just to get it all sorted out. Here's my current array builder:

public void Update(GameTime gameTime, BoundingFrustum viewFrustum)
		{
			int count = 0;
			for (int i = 0; i < world.LandscapeSizeX; i++)
			{
				for (int j = 0; j < world.LandscapeSizeY; j++)
				{
					if (world.Landscape[i, j] != null)
					{
						if (viewFrustum.Intersects(world.Landscape[i, j].Bounds) && world.Landscape[i, j].IsDrawing)
						{
							count += world.Landscape[i, j].Instances.Count;
						}
					}
				}
			}
			Instances = new InstanceInfo[count];
			count = 0;
			for (int i = 0; i < world.LandscapeSizeX; i++)
			{
				for (int j = 0; j < world.LandscapeSizeY; j++)
				{
					if (world.Landscape[i, j] != null)
					{
						if (viewFrustum.Intersects(world.Landscape[i, j].Bounds) && world.Landscape[i, j].IsDrawing)
						{
							world.Landscape[i, j].Instances.ToArray().CopyTo(Instances, count);
							count += world.Landscape[i, j].Instances.Count;
						}
					}
				}
			}
		}

You may ask why I perform two of the same loop. I do this because I found it is cheaper to add to arrays than it is to lists, so I need an initial count to have an array of the correct size ready.

EDIT: New question: Why is it that when I start a new thread to reinitialize the chunks coming into range, the main thread is slowed? Admittedly there are likely about 20 chunks at the most going through this in any given frame when I am moving around. Should I make a load queue for the thread to work on instead of starting individual threads?

#2Drakken255

Posted 12 August 2012 - 06:18 PM

By the Gods... How did they manage such lighting!?!? The main problem I am running into now is gathering all the instances into one array for drawing. It is taking too much time just to get it all sorted out. Here's my current array builder:

public void Update(GameTime gameTime, BoundingFrustum viewFrustum)
		{
			int count = 0;
			for (int i = 0; i < world.LandscapeSizeX; i++)
			{
				for (int j = 0; j < world.LandscapeSizeY; j++)
				{
					if (world.Landscape[i, j] != null)
					{
						if (viewFrustum.Intersects(world.Landscape[i, j].Bounds) && world.Landscape[i, j].IsDrawing)
						{
							count += world.Landscape[i, j].Instances.Count;
						}
					}
				}
			}
			Instances = new InstanceInfo[count];
			count = 0;
			for (int i = 0; i < world.LandscapeSizeX; i++)
			{
				for (int j = 0; j < world.LandscapeSizeY; j++)
				{
					if (world.Landscape[i, j] != null)
					{
						if (viewFrustum.Intersects(world.Landscape[i, j].Bounds) && world.Landscape[i, j].IsDrawing)
						{
							world.Landscape[i, j].Instances.ToArray().CopyTo(Instances, count);
							count += world.Landscape[i, j].Instances.Count;
						}
					}
				}
			}
		}

You may ask why I perform two of the same loop. I do this because I found it is cheaper to add to arrays than it is to lists, so I need an initial count to have an array of the correct size ready.

EDIT: New question: Why is it that when I start a new thread to reinitialize the chunks coming into range, the main thread is slowed? Admittedly there are likely about 20 chunks at the most going through this in any given frame when I am moving around.

#1Drakken255

Posted 12 August 2012 - 06:00 PM

By the Gods... How did they manage such lighting!?!? The main problem I am running into now is gathering all the instances into one array for drawing. It is taking too much time just to get it all sorted out. Here's my current array builder:

public void Update(GameTime gameTime, BoundingFrustum viewFrustum)
	    {
		    int count = 0;
		    for (int i = 0; i < world.LandscapeSizeX; i++)
		    {
			    for (int j = 0; j < world.LandscapeSizeY; j++)
			    {
				    if (world.Landscape[i, j] != null)
				    {
					    if (viewFrustum.Intersects(world.Landscape[i, j].Bounds) && world.Landscape[i, j].IsDrawing)
					    {
						    count += world.Landscape[i, j].Instances.Count;
					    }
				    }
			    }
		    }
		    Instances = new InstanceInfo[count];
		    count = 0;
		    for (int i = 0; i < world.LandscapeSizeX; i++)
		    {
			    for (int j = 0; j < world.LandscapeSizeY; j++)
			    {
				    if (world.Landscape[i, j] != null)
				    {
					    if (viewFrustum.Intersects(world.Landscape[i, j].Bounds) && world.Landscape[i, j].IsDrawing)
					    {
						    world.Landscape[i, j].Instances.ToArray().CopyTo(Instances, count);
						    count += world.Landscape[i, j].Instances.Count;
					    }
				    }
			    }
		    }
	    }

You may ask why I perform two of the same loop. I do this because I found it is cheaper to add to arrays than it is to lists, so I need an initial count to have an array of the correct size ready.

PARTNERS