April 5, 2015

Handling Quake 1 .map Files (Part 1)

Now, let's say you want to handle Quake 1 .map files.  Perhaps you want to do the project I'm doing: porting Quake to other engines.  Perhaps you want to use Quake 1-compatible level editors for your MonoGame or three.js projects.  Who knows?  Code for this series will be provided in C# for easy integration into tools and content pipelines.

First, let's look at what an entry in a .map file looks like.

{
 {
  ( x1 y1 z1 ) ( x2 y2 z2 ) ( x3 y3 z3 ) TEXTURENAME xofs yofs rotation xscale yscale
  ...
 }
 "key" "value" // Optional comment
}

Each entry in a .map file is enclosed in curly braces to encompass an entity.

Each entity can contain zero to many brushes.  Each brush is enclosed in curly braces.

Each brush must be convex can contain four to many faces.  (Why four?  Think of a three-sided pyramid and the base.)

Each face includes three vertices to define the plane, shown above as (x1,y1,z1) through (x3,y3,z3), a texture name, and all the information needed to calculate the texture coordinates for each final vertex.  Vertices are in clockwise order.  Most of the time, these vertices are the first three vertices of that face, but not always.  They're just there to define the plane.

Each entity can also contain one to many key/value pairs.  Each entity will have one key named "classname" which tells you what other key/value pairs you should expect.

If you find a classname of "worldspawn" in the entity, this will be all of your static geometry.  You can use this information to heavily optimize this information for rendering or other work: do texture batching, visibility calculations, collision calculations, etc.

While you can have comments in your .map files, you probably won't see them.

If you think about it, this gives you a good way to handle save game separation as well.  When you are saving your game, iterate through your world and serialize out the information for any entity that isn't worldspawn.  When you are loading the saved game, you can load only the worldspawn entity, then overlay your other entity information from your save game.

Now that we have that information, we know what we need to parse the .map file.  Here's a functioning map parser.  It fills a Map object with Entities that can contain key/value pairs and Brush objects containing Faces.

http://www.romsteady.net/quake1/Quake1Map-ParserOnly.zip

Next time, we'll turn this information to a polygon soup.

7 comments:

TheCraftKox YouTuberowca said...

Hey, you work in Ritual Entertainment, right? Do you have files from alpha SiN Episode 2?

Michael Russell said...

TheCraftKox,

I don't work at Ritual Entertainment anymore.

No, I don't have any of the Episode 2 alpha files. I've got the script in my head, and that's it.

TheCraftKox YouTuberowca said...

And remember what was going to happen in the second episode? Or what stage was the second episode? There were only concept art and maps were already in the process of creating? Sorry to whine but I'm a big fan of the two parts of SiN.
So how do you remember that you could write what Blade and Jessica did after killing Radek in the second episode.

Michael Russell said...

Episode 2 was supposed to start immediately following Episode 1.

You needed to get to Radek's crashed chopper to try to find out what he had injected Jessica with, since she was injected with something different from Blade.

That said, you assume too much. Radek isn't dead. Remember the bit after the credits?

TheCraftKox YouTuberowca said...

I thought it was "Save me a sit to the sequel Blade!" so the jokes xD, so it was in Episode 2 of finding a cure for Jessica, probably also about finding a cure for mutants that besieged the Freeport City, walking around the city possessed by mutants and killing them one by one, that would be great. Because from what I know it will blow helicopter fell into the parking lot of the building, it would be hard to survive such a fall + explosion, probably fell Radek was barely alive, I have one last question: is the mutants could infect the civilians his illness? How I wrote out xD

Howabout No said...

Hello, sorry for offtopic, but i'm looking for SE1 alpha/beta/demo whaever build which freatured early desings for mutants and mercs, valve's wiki still have screenshots of them https://developer.valvesoftware.com/wiki/Sin_Episodes

Can you assist me?

Michael Russell said...

I did not take any "SiN Episode 2" files with me when I left Ritual.

I know the plot, etc., but I have nothing I can release.