Load all textures at once, or as needed?

Started by
6 comments, last by tinkertom 7 years, 2 months ago

Hello,

This is my first post. I'm also teaching myself everything with regards to game development, so I apologise if I seem a little naive.

I'm currently programming a rendering function for my game and I'm trying to work out what is the best way to load textures into the game.

The game world is a voxel grid, where each voxel is a pointer to a predefined block struct.

Said struct contains the SDL_Texture pointer along with other data.

What is rendered to the screen is a small window of blocks, say 21x15 blocks with each block having a resolution of 16x16 pixels.

Not really mega stuff.

So should I set every pointer at startup or should I load everything into the game as the renderer needs it and then delete it.

Like I say I'm not to knowledgable here, so which is more efficient or what have you.

Thank you.

Advertisement

Load your data before you need it, which is usually at the start of the program, or the start of the map/level (not relevant to you, probably). You certainly don't want to be loading data when your renderer needs it - you don't want your graphic speed to be limited by your hard disk speed!

Okay, will do. Thank you very much.

As Kylotan says, you start by just loading everything up at program start. Caveman 3.0 does this. I believe Rome II Toal War does as well. if that starts taking forever, you go to loading a level at a time, like dungeons in Skyrim. If that's too big and will take too long, you switch to loading levels / areas / chunks in the background, like skyrim when out in the wilderness.

demand load paging of assets is another option. can work well with predictive background loading. but occasionally you get a cache (texture memory pool) miss, and your render speed drops to that of your hard drive as Kylotan says. this can mean the difference between playable on a bleeding edge PC, and unplayable on a low end rig.

load at program start. if it gets slow, try optimizing it first. binary fread_nolock() is VERY fast. slow load times are often the result of inefficient file formats. that's why many games use their own custom formats with just what they need and nothing more. some of those custom formats have gone on to become de-facto industry standard formats.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

I believe Rome II Toal War

Do you have any source material for this? (I am an RTS fan and am always interested in code examples/discussions ESPECIALLY for the Total War series)

I'm also teaching myself everything with regards to game development

If you're at a point where you're mostly learning, or it's a game that doesn't have a lot of textures to begin with, then it makes perfect sense to load up all your textures as soon as your app start, so you're ready to use them as soon as you need them. A bigger and more complicated project might delay loading assets until they're needed to save memory, but it's the kind of thing that only makes sense to do if you're trying to solve a specific problem.

Do you have any source material for this?

based on program behavior.

there is a load screen at program start, then a main menu, then a loading game screen, and your in. since its not a level based game, you need more or less all the graphics at once. also, come to think of it, when i would run it on my old PC, it would page assets off the hard drive. so it probably reverts to demand load paging if there's not enough ram to load all the assets upfront. it was so slow on the old PC, i gave up and bought shogun2.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Thank you all for replies, it's much appreciated.

This topic is closed to new replies.

Advertisement