Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Lord FlatHead

Writing a WAD reader, need help from programmer types

Recommended Posts

Hello. I've been working on a WAD reader in C, and it just doesn't want to work right. I was hoping some of you programmer guys who have (or have not) worked with the format could tell me what I'm doing wrong.

Source code, compiled .exe, test wad and sample output file : http://users.pandora.be/flathead/storage/wadfucker2.zip (25 Kb)

As you'll see from the included text file, everything goes fine until about linedef #36 - at that point the buffer I read the linedef information into seems to be filled with random garbage, or most likely nothing at all.

Strange thing is, it works fine on small maps (handful of linedefs, 3 or 4 sectors) but whenever I try it on a decent-sized map it does this. I know my little wad file isn't at fault either since I checked in a hex editor.

Anyone ? Thanks in advance.

Share this post


Link to post

My original idea was to read, for example, all the linedefs at once into a buffer using fread(), then going through them one one filling up an array with the values I needed. For some odd reason the buffer got filled with NULL values after a certain point though, so now I just read the records one by one. Seems to work, except I still get a few missing lines now and then. Clicky.

Share this post


Link to post

Check to make sure your file is opened in binary mode. Opening a file for reading in text mode will cause automatic CRLF translation, and can also interfere with proper fseek behavior. Last time I had a problem with seemingly arbitrary behavior in an IO program, this was the cause of the problem.

Share this post


Link to post
Fredrik said:

Well, I guess that shows why C++ is crap.


Uh, he said he programmed it in C...

So therefore, C is crap too :)

Share this post


Link to post
Darkhaven said:

New Map editor or just a reader?

Reader. I was thinking of writing a proper renderer and collision code for it too, just as an exercise in C/C++. Fredrik, arguments over which programming language is better than another are the lowest, saddest form of geek discourse :) So let's not.

Share this post


Link to post

Hmm I remember getting those missing lines when I first started playing around with the doom map format. I can't remember what caused it though (reading in text mode caused much bigger errors than that for me).

Share this post


Link to post
Darkhaven said:

Uh, he said he programmed it in C...

So why did he put the code in a .cpp file? Tsk, tsk.

Lord FlatHead said:

Fredrik, arguments over which programming language is better than another are the lowest, saddest form of geek discourse :)

The losing side often employs this argument.

Share this post


Link to post
fraggle said:

Fredrik is right, dont use C.

Lord FlatHead said:

just as an exercise in C/C++.

Share this post


Link to post
Graf Zahl said:

But he is right.

Of course not. The lowest, saddest form of geek discourse is editor flamewar.

Share this post


Link to post
Fredrik said:

Well, I guess that shows why C++ is crap.


I have a wad loader that works perfectly and is written in C++

in fact it's what I use to generate the stats for the Doom wiki :P

Share this post


Link to post

I probably shouldn't have spoken about it anyway, I couldn't download the source / executable before it was removed(?).

Share this post


Link to post

WTF, I thought C++ was the standard. Oh well, whatever. All I know is Basic and Python anyway.

Share this post


Link to post
Darkhaven said:

Uh, he said he programmed it in C...

So therefore, C is crap too :)


Heh C++ is just an advanced C with classes and stuff (OOP). It's an inside joke to programmers as the "++" operater is like saying "x = x + 1". Therefore "C++" is like saying "C = C + 1" or C++ is better (greater) than C :P

However it still wouldnt run. If you wanted a working program it would be:

#pragma once
#include <iostream>
using namespace std;

int C = 1;

int main()
{
    C++;
    cout << "C++ is C plus 1! (" << C << ")" << endl; //C++ is C plus 1! (2)
    return 0;
}

Share this post


Link to post

You fools. Real programmers write in machine code they design, because those damn Intel engineers really bogged down the original version.

DC

Share this post


Link to post

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
×