Creating a Cross Platform Isometric game with terrain generation. Help?

Started by
15 comments, last by chaosvine 9 years ago

Thanks for the replies guys. I'll try to address what people have said here.

So my reasoning was that should I make say 100,000 or more draw calls to create individual sprites for each block then I would get huge performance hits wouldn't I? Rendering the blocks to a texture reduces the number of draw calls required by quite a bit...


The thing is, a GPU is much quicker at drawing pixels than the CPU is, but you're using the CPU to do it thousands of times rather than the GPU. If you use a texture atlas, you can build a single vertex buffer from all the visible cells and draw the whole thing in a single draw call. And it would be much faster than calling image::Copy 100,000 times on the CPU.

As for the pathfinding. In the final version of the terrain I intend on having half blocks which create the face of hilled areas so as to be more smooth, while mountains I thought should remain more difficult to traverse.

I don't particularly understand 3D noise all that well as I've only worked with 2D and 1D noise patterns before. But I suppose I could try it. Any tips in that regard?


I posted some links.

Are you saying that I should be doing this in 3D rather than 2D? I'm not particularly interested in that approach if I can help it.


It doesn't need to have a movable camera or a perspective projection, but doing it 3D (ie, using the hardware as it was designed) is definitely preferable than performing 100,000 image copy calls on the CPU. The GPU hardware is very well suited to moving lots of pixels around, so why not let it do its job?
Advertisement

Ok, you're mentioning a few things I'm not exactly clear on understanding. I'll do some more research on texture atlases vertex buffers before I proceed.

Ok, so I tried it using sprite objects only (I think this is what you were referring to when you said to use the gpu hardware). It renders very well actually... and I should have known this would work based on my experience in rendering alot of instanced objects with small geometry before in 3d applications. And the SFML documentation even says in the tutorial that the best performance will come from modifying the objects as necessary but instancing the textures all from the same atlas. I don't know why I was actually worried about this. However, I now have another question...

So I'm allocating an array of sprites (in this instance 16 * 64 * 64 long) that I'm using to draw the sprites to the screen. However I was under the impression that I'd have to delete this array at shutdown... when I try to delete the array the debug output window says that its an invalid pointer. I'm confused, so do I still need to delete this array of sprite objects or is sfml taking care of that for me somehow? I couldn't find anything on this in the documentation.

Perhaps show how you are allocating it?

So I'm allocating an array of sprites (in this instance 16 * 64 * 64 long) that I'm using to draw the sprites to the screen. However I was under the impression that I'd have to delete this array at shutdown... when I try to delete the array the debug output window says that its an invalid pointer. I'm confused, so do I still need to delete this array of sprite objects or is sfml taking care of that for me somehow? I couldn't find anything on this in the documentation.

A) We need to see code to comment on your crash, but in general SFML does not manually free memory that you manually allocated. But SFML does manually frees memory that you have SFML allocate for you. smile.png

B) Use a std::vector, unless you have a reason to micro-manage your memory (which in this case, it doesn't seem like you do). Raw calls to free/malloc/new/delete are frowned upon in higher level code (becuase it's not needed and doesn't help), and reserved primarily for lower-level code.

C) I'd suggest using a 1-dimensional array(vector), and treat it as 3D when you need 3D. It's just more convenient and (in some cases) more efficient.

D) sf::Sprites are fine, but if you ever need to, you can eek out faster performance by ditching the sprites. No need to ditch the entire API. But for now, I'd just stick with sf::Sprites because it's probably sufficiently fast for your needs.

Yeah sorry, I forgot to show code. I've used vectors extensively in the past, I'm just a bit rusty when it comes to some things. And I forgot about them automatically allocating memory and deallocating it.

As far as dimensions of the array, I'm already using a 1D array like a 3D array. :)

Yeah, I've been told I could get more performance from a vertex array but I'm not sure what that is exactly. I have yet to look it up, was a bit tired last night...

I'm assuming it's something similiar to the Vertex Buffers in OpenGL / DirectX in which case I would have a starting point at least for converting the algorithm.

So I've looked up Vertex arrays, they are basically to my understanding a Vertex Buffer that is already wrapped in a dynamic array for you (very convenient). However, this poses the new Question of how to go about using this for my purposes specifically in that I'm not sure exactly how I would create a new object or mesh from this that would display the textures properly. =/

I'm going to look through the links Jtippets provided in his above post. Perhaps there is a clue there. Otherwise maybe someone could fill me in to help on my search?

This topic is closed to new replies.

Advertisement