Sign in to follow this  

Level Streaming

Recommended Posts

Elrinth    130

I'm working on a level editor for a 2D game atm, and I'd like to have the file you're editing to stream from/to a file or many files.

I've got Resolution 800x600.
I make sections outta 256x256 pixels. Where there are 16x16 pixels large tiles. Which makes 256 tiles per section.

NrOfSectionsX = ceil(resolutionX / sectionXpixels) + 2
NrOfSectionsY = ceil(resolutionY / sectionYpixels) + 2
i add +2 so I can get sections -1 and +1 outside of the screen so I got that in memory and can display it instantly without having to load anything.
However the problem comes when I wanna load sections outside the screen.
I store each section as it's own file. Where I call them for example: 0,0,0.txt being the upper left screen which can be seen when starting.
Then next is called 1,0,0.txt which is 256 pixels to the right of previous section.

Problem is. There's choppiness when I load these sections which are outside of the screen. It happens because I write sections to disk which aren't important anymore. and I read sections which become important.
So I put the level save/load in separate thread. Sure there is no choppiness any longer.. However, there is delay before they are presented.

So I thought, hmmm what about having one large file containing all the level data with pointer-data in the beginning of the file which says where in the file each section is... Sure that works.. However, what happens when data is changed? Yes that's right, it doesn't work, because you cannot edit stuff you've already written to the file.

I thought about putting it all into a zip file aswell. But there seems to be no libraries which can fix my problems.

Now I'm asking if you guys have any good idea to fix this problem?

If I remove the whole file i/o then my program runs smooth at 1000 fps. But sadly no sections are stored which kinda sucks.

Visual example of what I'm trying to deal with: [url=""][/url] Edited by Elrinth

Share this post

Link to post
Share on other sites
Elrinth    130
Well I figured out why my file i/o was so slow... I rewrote the code to load / save the sections via FILE *fp and use fgetc and fputc.. This was soooo much faster... Before I had to convert strings into values this was probably slowing down my code considerably... Now it's working flawlessly even if I move the camera really fast :)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this