Jump to content

  • Log In with Google      Sign In   
  • Create Account

XNA questions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 burnt_casadilla   Members   -  Reputation: 442

Like
0Likes
Like

Posted 23 June 2013 - 03:51 PM

I have a few simple questions that don't require much thought, so I figured I'd put them in one thread instead of making a bunch of threads. I don't know where else to put them lol.

 

1: If I have one million cubes, is it faster to draw them from one big list, or 20 smaller lists?

2: When I'm drawing a skybox, should I have it drawn relative to the player or to the map?

3: Is there a method that can change how a texture looks depending on player color? For example, if player ones color is red, part of the texture will be red. I don't remember what the exact word for it is...maybe alpha blending or something like that.

4: In a multiplayer game, I'm assuming it's correct to create a camera for each player. Is this easiest to do through the player class?

5: What's the difference between the LoadContent and Initialize method created for you? I use both of them while initializing variables, although I'm not really sure why


Edited by burnt_casadilla, 23 June 2013 - 03:55 PM.

If you see a post from me, you can safely assume its C# and XNA :)


Sponsor:

#2 phil_t   Crossbones+   -  Reputation: 3928

Like
1Likes
Like

Posted 23 June 2013 - 05:34 PM


1: If I have one million cubes, is it faster to draw them from one big list, or 20 smaller lists?

 

Generally the fewer draw calls the better - so, one big list. However, if you can avoid drawing any of your 20 smaller lists (say because you know that none of the cubes in that list will be visible from the current camera), then 20 smaller lists is the better way to go.

 


3: Is there a method that can change how a texture looks depending on player color? For example, if player ones color is red, part of the texture will be red. I don't remember what the exact word for it is...maybe alpha blending or something like that.

 

You could use a second texture that indicates which parts of the first texture get replaced by red. Then write a custom shader that uses these two textures to determine the final output color.

Or, draw the object twice. Once normally, and then again using the "team color" texture that is transparent where you want the original color to show through.



#3 burnt_casadilla   Members   -  Reputation: 442

Like
0Likes
Like

Posted 23 June 2013 - 05:44 PM

Your first answer helped a lot. Since the entire map is huge, I'll end up using smaller lists. And fog too.

 

With the texture I'm using it'll be easy enough to determine which colors to change to the player color. If the pixel is a certain shade of gray and the player places it, that shade of gray will change to the player color


If you see a post from me, you can safely assume its C# and XNA :)


#4 kunos   Crossbones+   -  Reputation: 2207

Like
0Likes
Like

Posted 23 June 2013 - 11:46 PM

1: If I have one million cubes, is it faster to draw them from one big list, or 20 smaller lists?

 

 

 

 

If that million is ON SCREEN, then it should be faster to draw from one list... if for "list" you mean drawcall.

If they are not all visible, then having the possibility to discard cubes might be faster. There's a sweet spot to be found between batch size and ability to cull out blocks and that is very application specific and can only be found through benchmarking your own game.


Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#5 Andy474   Members   -  Reputation: 685

Like
2Likes
Like

Posted 24 June 2013 - 01:51 AM


If I have one million cubes, is it faster to draw them from one big list, or 20 smaller lists?

 

Neither, your still doing 1,000,000 draw calls wither way. what you need to-do is only draw them if they are onscreen and through the use of Culling or instancing.

 

 


Is there a method that can change how a texture looks depending on player color? For example, if player ones color is red, part of the texture will be red. I don't remember what the exact word for it is...maybe alpha blending or something like that.

 

No, Make one smile.png you will need to use RenderTargets to modify the texture. here is a snippet how to use a rendertarget:

 

RenderTarget2D target = new RenderTarger2D(...); 
//I cant remeber the arguments off the top of my head.
//I think its GraphicsDevice, Width, Height, GenerateMipmap, SurfaceFormat, Depthformat

GraphicsDevice.SetRenderTarget(target);
GraphicsDevice.Clear(Color.Black); //any colour will do
using(SpriteBatch b = new SpriteBatch(GraphicsDevice))
{
b.Begin();

//Draw anything here to draw onto a new texture E.g.
//Draw the Basic non-coloured texture
//Draw the players colour where we are supposed too.

b.End();
}

GraphicsDevice.SetRenderTarget(null);

//Then to access your new Texture, just do 
Texture newTexture = target; //Target inherits from Texture2D so no casting needed

 

 


In a multiplayer game, I'm assuming it's correct to create a camera for each player. Is this easiest to do through the player class?

 

Depends, Local multiplayer, E.g. on the same PC? s this the design you want? I would probally have 1 camera class (Singleton maybe?) which contained ALL the informatio

 

 


What's the difference between the LoadContent and Initialize method created for you? I use both of them while initializing variables, although I'm not really sure why

 

GraphicsDevice ... Initialize() ... is called just after the constructor, that's it. it is never called again until you create another instance of the class.

Whereas LoadContent<T>() ... is called on starup AND whenever the graphics device is Lost or Reset recovering your ingame assets.

 

This means that LoadContent is called when the Game Window is minimized and reopened, or something takes control of the screen (E.g. UAC) and everything run in loaded is run again, this means it is not a good idea to put any data initialization in here, as it will be "reset" when your device is reset / lost.


Edited by Andy474, 24 June 2013 - 01:53 AM.


#6 burnt_casadilla   Members   -  Reputation: 442

Like
0Likes
Like

Posted 24 June 2013 - 02:06 AM

Thanks! I guess when the time comes I'll have to figure out a way to get a certain RGB value of a texture and then change it according to player color. When I was playing around with sprites I recalled that pink was always transparent, so I figured I could take a color and make it transparent, then draw over it with the player color


If you see a post from me, you can safely assume its C# and XNA :)


#7 phil_t   Crossbones+   -  Reputation: 3928

Like
0Likes
Like

Posted 24 June 2013 - 02:15 AM


GraphicsDevice ... Initialize() ... is called just after the constructor, that's it. it is never called again until you create another instance of the class.

Whereas LoadContent() ... is called on starup AND whenever the graphics device is Lost or Reset recovering your ingame assets.



This means that LoadContent is called when the Game Window is minimized and reopened, or something takes control of the screen (E.g. UAC) and everything run in loaded is run again, this means it is not a good idea to put any data initialization in here, as it will be "reset" when your device is reset / lost.

 

That may have been true in older versions of XNA, but not anymore. LoadContent should only be called once.



#8 Andy474   Members   -  Reputation: 685

Like
0Likes
Like

Posted 24 June 2013 - 02:54 AM

 

That may have been true in older versions of XNA, but not anymore. LoadContent should only be called once.

 

 

Not what MSDN Says:

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.loadcontent%28v=xnagamestudio.40%29.aspx

 

 


This method is called by Initialize. Also, it is called any time the game content needs to be reloaded, such as when the DeviceReset event occurs. You should not access the GraphicsDevice until LoadContent is called.

LoadContent is called by Initialize, and before Draw. During the time the code for this method is executing, the user will experience a delay before the initial game screen appears.


Edited by Andy474, 24 June 2013 - 02:56 AM.


#9 phil_t   Crossbones+   -  Reputation: 3928

Like
0Likes
Like

Posted 24 June 2013 - 03:46 AM

As is often the case, MSDN is wrong (see here: http://xboxforums.create.msdn.com/forums/p/27316/150367.aspx#150367). It's pretty easy to verify this yourself by adding a DeviceReset handler, and putting a bp on it and on your game's LoadContent.

 

XNA will recreate most graphics resources automatically. The only resources that "lose" their data on a device reset are render targets, DynamicVertexBuffers, DynamicIndexBuffers and maybe I few more I can't remember.


Edited by phil_t, 24 June 2013 - 03:49 AM.


#10 Andy474   Members   -  Reputation: 685

Like
0Likes
Like

Posted 24 June 2013 - 03:54 AM

As is often the case, MSDN is wrong (see here: http://xboxforums.create.msdn.com/forums/p/27316/150367.aspx#150367). It's pretty easy to verify this yourself by adding a DeviceReset handler, and putting a bp on it and on your game's LoadContent.

 

XNA will recreate most graphics resources automatically. The only resources that "lose" their data on a device reset are render targets, DynamicVertexBuffers, DynamicIndexBuffers and maybe I few more I can't remember.

 

Interesting ... I'll take the word on it, but if i remember correctly a game i made a while ago used to have problem that every time the game was Minimized all the content would reload and score rest etc. (this was in XNA 3.0) and i got around this by moving all Data stuff (scores etc. out of the LoadContent method. )

 

So smile.png


Edited by Andy474, 24 June 2013 - 04:20 AM.


#11 Tom KQT   Members   -  Reputation: 1595

Like
1Likes
Like

Posted 24 June 2013 - 04:16 AM

2: When I'm drawing a skybox, should I have it drawn relative to the player or to the map?

Nobody answered this one yet smile.png

Skybox should move with the player. But only translation; rotation of the skybox must be fixed with the map.

The reason why you want to move skybox with the player is that this way it will appear to be really far away and you don't need an extremely huge skybox model. If the model wasn't incredibly huge and if it didn't move with the player, it would appear to be very close, which would break the immersion.


Edited by Tom KQT, 24 June 2013 - 04:17 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS