#include "config.h"

#include <inttypes.h>

/*- Doom Structures .. Colin Reed 1994 -------------------------------------*/
/*
 * Modified 2010/08/04 by Christopher Bazley
 */

struct wad_header 					/* Linked wad files list.*/
{
	char type[4];
	uint32_t num_entries;
	uint32_t dir_start;
};

struct directory 						/* The directory entry header*/
{
	uint32_t start;
	uint32_t length;
	char name[8];
};

struct Block
{
	int16_t minx;
	int16_t miny;
	int16_t xblocks;
	int16_t yblocks;
};

struct lumplist {
 struct lumplist *next;
 struct directory dir;
 void *data;
 void (*write_data)(struct lumplist *lump);
 struct lumplist *level;
};

typedef void data_callback(struct lumplist *lump);

/*- The level structures ---------------------------------------------------*/

struct Vertex
{
   int16_t x;         /* X coordinate */
   int16_t y;         /* Y coordinate */
};

struct LineDef
{
   uint16_t start;     /* from this vertex ... */
   uint16_t end;       /* ... to this vertex */
   uint16_t flags;     /* see NAMES.C for more info */
   uint16_t type;      /* see NAMES.C for more info */
   uint16_t tag;       /* crossing this linedef activates the sector with the same tag */
   int16_t sidedef1;  /* sidedef */
   int16_t sidedef2;  /* only if this line adjoins 2 sectors */
};

struct SideDef
{
   int16_t xoff;      /* X offset for texture */
   int16_t yoff;      /* Y offset for texture */
   char tex1[8];  /* texture name for the part above */
   char tex2[8];  /* texture name for the part below */
   char tex3[8];  /* texture name for the regular part */
   int16_t sector;    /* adjacent sector */
};

struct Sector
{
   int16_t floorh;    /* floor height */
   int16_t ceilh;     /* ceiling height */
   char floort[8];/* floor texture */
   char ceilt[8]; /* ceiling texture */
   int16_t light;     /* light level (0-255) */
   int16_t special;   /* special behaviour (0 = normal, 9 = secret, ...) */
   int16_t tag;       /* sector activated by a linedef with the same tag */
};

/*--------------------------------------------------------------------------*/
/* These are the structure used for creating the NODE bsp tree.             */
/*--------------------------------------------------------------------------*/

struct Seg
{
   short int start;     /* from this vertex ... */
   short int end;       /* ... to this vertex */
   unsigned short angle;/* angle (0 = east, 16384 = north, ...) */
   short int linedef;   /* linedef that this seg goes along*/
   short int flip;      /* true if not the same direction as linedef */
   unsigned short dist; /* distance from starting point */
	struct Seg *next;
        short psx,psy,pex,pey;  /* Start, end coordinates */
        long pdx,pdy,ptmp;      /* Used in intersection calculations */
        long len;
        short sector;
};

struct Pseg
{
   int16_t start;     /* from this vertex ... */
   int16_t end;       /* ... to this vertex */
   uint16_t angle;/* angle (0 = east, 16384 = north, ...) */
   int16_t linedef;   /* linedef that this seg goes along*/
   int16_t flip;      /* true if not the same direction as linedef */
   uint16_t dist; /* distance from starting point */
};

/* cph - dedicated type for bounding boxes, as in the Doom source */
typedef int16_t bbox_t[4];
enum { BB_TOP, BB_BOTTOM, BB_LEFT, BB_RIGHT };

struct Node
{
   int16_t x, y;			/* starting point*/
   int16_t dx, dy;			/* offset to ending point*/
   bbox_t rightbox;			/* bounding rectangle 1*/
   bbox_t leftbox;			/* bounding rectangle 2*/
   int16_t chright, chleft;		/* Node or SSector (if high bit is set)*/
	struct Node *nextr,*nextl;
	int16_t node_num;	        		/* starting at 0 (but reversed when done)*/
        long ptmp;
};

struct SSector
{
   uint16_t num;       /* number of Segs in this Sub-Sector */
   uint16_t first;     /* first Seg */
};

/*--------------------------------------------------------------------------*/
