Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Question about handling large data.  (Read 1429 times)

0 Members and 1 Guest are viewing this topic.

Vect0rZ

  • Newbie
  • *
  • Posts: 5
    • View Profile
Question about handling large data.
« on: July 29, 2014, 11:22:59 am »
Hey,

I'm new around theese forums and lately been using SFML(C++).

I did some stuff, but now I'm wondering something:

Let's say I got a class Levels{}; with some properties like: name, background sprite, number of objects, height, width... .
And class Objects with allmost the same properties wich i will use in the level.

So,

Now let's say my game have like 200 levels (only example), how should I store properly the info?

1. Should i load all those levels before game start?
2. If i have to load them one by one, should i store them somehow in a class or functions and call them on certain conditions?

Thanks in advance! =]
« Last Edit: July 29, 2014, 12:34:27 pm by Laurent »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Question about handling large data.
« Reply #1 on: July 29, 2014, 12:45:28 pm »
Store your levels in files.
Unless you have a reason to load every level at once, only load the level you need when you need it.

Vect0rZ

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Question about handling large data.
« Reply #2 on: July 29, 2014, 01:09:02 pm »
Thanks for the fast reply.

Excuse me, but you mean like using ostreams, and reading the data from there?

Like
Name["Level1"];
Background [Resources/level1.png];


Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Question about handling large data.
« Reply #3 on: July 29, 2014, 06:37:33 pm »
What I do, for most of my projects, is to create my maps with the Tiled map editor and save as JSON. Then I use picojson to parse the map files and read various properties.
And at the start of each level I destroy any data related to the previous level and load the current one - keeps mem usage down and it only takes a few ms to load and parse a new level.
Regarding how to load the data from file to memory; use std::ifstream, fread or what ever else suits you - that's a detail.
« Last Edit: July 29, 2014, 07:10:15 pm by Jesper Juhl »