Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Bitwise

Loading entities from Q3 .bsp file?

This topic is 5959 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been trying to write some routines to load all the info contained in a Quake3 .bsp file using info from http://graphics.stanford.edu/~kekoa/q3/ My approach has been to create classes containing all the data as described and then using a stream to read them in order in binary mode. The author describes the entity lump like this: "entities string[length] ents Entity descriptions, stored as a string. The length of the entity string is given by the size of the lump itself, as specified in the lump directory. " I took this as just an array of chars. In this case I my entity class contained only 1 pointer to a char which I then allocated enough memory to store all the entities after reading the length of the lump from the header via: entity = new char[numEntities]; Basically this does not work and what I read is not valid data. Any ideas on what I am doing wrong would be great. thanks. Bitwise

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
hm.. could you post some more code? assuming that you seek to the entities lump in the file correctly and that you read the right amount then it should work...

Share this post


Link to post
Share on other sites
Here is how I set up the header object and as 2 example lumps entities, and texture (the first two lumps in the bsp file).

// Used to find the various lumps in the bsp file
class BSPdirentry
{
public:

int offset;
int length;
};

// Header at the beginning of bsp file
class BSPheader
{
public:

char magic[4];
int version;
BSPdirentry directory[17];
};


class BSPentities
{
public:

char* entitites;
};

// Describes textures used in map
class BSPtexture
{
public:

char name[64];
int flags;
int contents;
};


Then to read the data from the bsp file:

fstream file;

file.open("test.bsp",ios::app | ios::out | ios::in | ios::binary );
file.read( reinterpret_cast(&header), sizeof(header) ); // Load the header

numEntities = header.directory[0].length;

// Here I am finding out how much memory to allocate
numEntities = header.directory[0].length;
numTextures = header.directory[1].length / sizeofBSPtexture);

// Allocate memory for BSP data
entity.entitites = new char[numEntities];
texture = new BSPtexture[numTextures];

file.read( reinterpret_cast(&entity), sizeof(entity) );

for ( counter = 0; counter < numTextures; counter++)
{
file.read( reinterpret_cast(&texture[counter]), sizeof(BSPtexture) );
}


This is just a cut and paste of the meat and bones of the routine. I think it gives a pretty good idea of what I''m trying to do. I have a feeling a few of my data structures for the lumps are off and therefore causing all other after to be garbage as well. Unfortunately I think it is the entity and texture lumps that are probably wrong and they are the first two int the file. I know I can do a seek to just load the crucial data for rendering but I want to understand all the lumps structure if possible.

Bitwise

Share this post


Link to post
Share on other sites
Guest Anonymous Poster


<<<< file.read( reinterpret_cast(&entity), sizeof(entity) );


you are reading sizeof(entity) bytes, isnt entity a struct with a singler pointer in it? besides numEntities you will need the size of the data of entities...


hope this could help

Share this post


Link to post
Share on other sites
yes entity is basically a struct with just a pointer to a char. This is how the guy at stanford describes the entity lump:

"entities

string[length] ents Entity descriptions, stored as a string.

The length of the entity string is given by the size of the lump itself, as specified in the lump directory. "

Now i think this is kind of worded poorly. I interpreted "string[length] ents" to mean that the entity lump is just one long array of characters which is header.directory[0].length long. I just figured that this array contained a bunch of null terminated strings one after another to describe all the entities. If I am wrong someone please correct me!

Obviously I think something is either wrong with this assumption of how the entities are describes in the file or I am implementing it incorrectly. As far as I can tell the code listed above would read allocate enough memory for my entity.entities pointer to be length long and then read that much data from the correct part of the file but I get some very strange results. When I tried to ouput the data as one long string that entity points to I get what looks to be like the ascii character set repeated over and over about 4 times. I also now get a bunch of repeated data when I try to output the vertcies positions. Very strange indeed.

Bitwise

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Kind of an old post, but I notice it never got a real answer.

Anyways, you should read in the header of the file, then consult the file directory to find the entities. The lumps aren''t necessarily ordered in the file the same way they are in the direntry file (which you seem to be assuming.)

I read the header then do some _fseek calls with the info in the header.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!