Level Loading strategy

Hello Guys,
Im working on a Game and I want to ask you if somebody know a good technique for loading Levels which is fast and is good for Levels like Archive used it in his 3D Engine with BSP trees :slight_smile:

If you’re going for something simple, an old technique I used in my level editor seemed very versatile.

Basically, for every texture I create 1 mesh. This mesh contains every single vertex from every model in my level that uses that texture. So if there are 12 textures in the level, I create 12 meshes.

I also have “nodes” which contain a name, position, and rotation. When I parse the model to load it into my engine, I check the names of each node. If it is a barrel, I place a barrel entity at that specific position and rotation. ect.

Not very “professional”, and not optimized at all, but it’s easy to get working.
My game first recon (in the WIP forum) uses basically this technique.

At the moment I just load an image read every pixel and I have defined RGB colors in the image and when I have some defined color I put the defined Mesh at the place for it.Just so:


public boolean loadLevel(String path)
	{
		BufferedImage img = null;
		
		try {
			img = ImageIO.read(Level.class.getResourceAsStream(path));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		this.w = img.getWidth();
		this.d = img.getHeight();
		
		for(int i = 0; i < img.getWidth(); i++) {
			for(int j = 0; j < img.getHeight(); j++) {
				Color c = new Color(img.getRGB(i, j));
				
				if(c.getRed() == 255 && c.getGreen() == 255 && c.getBlue() == 255)
				{
					entities.add(new Entity(texturedModel, new Vector3f(i, -2, -j), 0, 0, 0, 1));
					entities.add(new Entity(texturedModel, new Vector3f(i, 2, -j), 0, 0, 0, 1));
				}
				
				if(c.getRed() == 85 && c.getGreen() == 85 && c.getBlue() == 85)
				{
					entities.add(new Entity(texturedModel, new Vector3f(i, -2, -j), 0, 0, 0, 1));
					entities.add(new Entity(texturedModel, new Vector3f(i, -1, -j), 0, 0, 0, 1));
					entities.add(new Entity(texturedModel, new Vector3f(i, 0, -j), 0, 0, 0, 1));
					entities.add(new Entity(texturedModel, new Vector3f(i, 1, -j), 0, 0, 0, 1));
					entities.add(new Entity(texturedModel, new Vector3f(i, 2, -j), 0, 0, 0, 1));
				}
				
				if(c.getRed() == 255 && c.getGreen() == 0 && c.getBlue() == 0)
				{
					entities.add(new Entity(texturedModel, new Vector3f(i, -2, -j), 0, 0, 0, 1));
					entities.add(new Entity(texturedModel, new Vector3f(i, 2, -j), 0, 0, 0, 1));
				}
			}
		}
		
		return true;
	}

I don’t understand your method that much but I want to build Levels like you in your FPS Engine for example :slight_smile:

You could use some simplified xml/json-esque hierarchial format to define meshes, entities, map structures and world settings all in one file.
The format valve uses for their map editor is a good example of this:

-> *.vmf format

That wiki page contains a lot of examples and explanations.

All you do is represent all ingame objects as structured text/binary(->serialization) data.

//text
model {
    id 13
    file "unit/soldier.md5"
    pos {
       0.0, 1.2, 1.992
    }
}

How you do it is up to you, but using a single bitmap is not feasible for a true 3d game (gameplay in 3d, not only 3d graphics).

What if I use the BSP format and edit it with something like Blender and write everything into a XML-File ? :slight_smile:

BSP is only effective when created out of convex brushes. The models need to specify these brushes or else you’re going to have a mess of polygons.

Okay I read the Document from Valve but I don’t understand it that much.Are there Entries like these for every model in the Level with its path and position ?


//text
model {
    id 13
    file "unit/soldier.md5"
    pos {
       0.0, 1.2, 1.992
    }
}

EDIT: And are there any Level editors for this format or should I just use Notepad++ ? :slight_smile:

Yes
http://www.aegidian.org/gqt/jqt/features.html

So I can use this map Editor to Design a map then save it as a VMF-File and read it in my Engine and render the designed Level ? :slight_smile:

No lol. This is for Quake. Remember that valve’s goldsrc and source engines are derivatives of the Quake engine

something something no free lunch

Valves vmf format is meant for valve source engine games.

Unless your engine has the same basic structure of the source engine, there’s no point in 1:1 copying that stuff, but it’s always nice to have some inspiration so that you can get an idea of what it is you might need to implement.

Do you actually have BSP rendering working?
If no, then you might be better off just keeping it down to a list of model-names with position and rotation to keep it simple and get something crackin at all.

I agree with this, setting up your engine to work with BSPs is no small task

Yeah I want to keep it simple as possible because I want to understand my Code too.So I want to write some simple code for Levels specially for FPS Games or Racing Games but Racing are another thing :slight_smile: So Should I start with the VMF Page from Valve or where should I start and implementing in my code ? :slight_smile: