1 /*
2  *	yadex.h
3  *	The header that all modules include.
4  *	BW & RQ sometime in 1993 or 1994.
5  */
6 
7 
8 /*
9 This file is part of Yadex.
10 
11 Yadex incorporates code from DEU 5.21 that was put in the public domain in
12 1994 by Rapha�l Quinet and Brendon Wyber.
13 
14 The rest of Yadex is Copyright � 1997-2003 Andr� Majorel and others.
15 
16 This program is free software; you can redistribute it and/or modify it under
17 the terms of the GNU General Public License as published by the Free Software
18 Foundation; either version 2 of the License, or (at your option) any later
19 version.
20 
21 This program is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
23 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
24 
25 You should have received a copy of the GNU General Public License along with
26 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
27 Place, Suite 330, Boston, MA 02111-1307, USA.
28 */
29 
30 
31 #ifndef YH_YADEX  /* DO NOT INSERT ANYTHING BEFORE THIS LINE */
32 #define YH_YADEX
33 
34 
35 #include "config.h"
36 
37 
38 // Sanity checks
39 #if ! (defined Y_BGI ^ defined Y_X11)
40 #error "You must #define either Y_BGI or Y_X11"
41 #endif
42 
43 #if ! (defined Y_DOS ^ defined Y_UNIX)
44 #error "You must #define either Y_DOS or Y_UNIX"
45 #endif
46 
47 
48 /*
49  *	Standard headers
50  */
51 #include <stddef.h>
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #include <stdarg.h>
56 #include <ctype.h>
57 #include <limits.h>
58 #include <errno.h>
59 #ifdef Y_DOS
60 #include <alloc.h>
61 #include <dos.h>
62 #include <bios.h>
63 #elif defined Y_UNIX
64 #include <unistd.h>
65 #define far
66 #define huge
67 #define farmalloc  malloc
68 #define farrealloc realloc
69 #define farfree    free
70 #endif
71 
72 
73 /*
74  *	Additional libraries
75  */
76 #ifdef Y_BGI
77 #include <graphics.h>
78 #endif
79 #include <atclib.h>
80 #include "bitvec.h"  /* bv_set, bv_clear, bv_toggle */
81 #include "yerror.h"
82 #include "aym.h"     /* Needs yerror.h */
83 #include "windim.h"
84 #include "ymemory.h"
85 
86 
87 /*
88  *	Platform-independant types and formats.
89  */
90 typedef unsigned char  u8;
91 typedef signed   char  i8;
92 
93 typedef unsigned short u16;
94 #define F_U16_D "hu"
95 #define F_U16_H "hX"
96 
97 typedef signed   short i16;
98 #define F_I16_D "hd"
99 #define F_I16_H "hX"
100 
101 typedef unsigned int  u32;
102 #define F_U32_D "u"
103 #define F_U32_H "X"
104 
105 typedef signed   int  i32;
106 #define F_I32_D "d"
107 #define F_I32_H "X"
108 
109 
110 /*
111  *	Platform definitions
112  */
113 #if defined Y_DOS
114 const int Y_PATH      = 64;	// Maximum length of a path
115 const int Y_FILE_NAME = 255;	// Maximum length of file name, including path
116 #elif defined Y_UNIX
117 const int Y_PATH      = 255;
118 const int Y_FILE_NAME = 255;
119 #endif
120 typedef char y_file_name_t[Y_FILE_NAME + 1];
121 
122 
123 /*
124  *	Constants of the universe.
125  */
126 const double HALFPI = 1.5707963;
127 const double ONEPI  = 3.1415926;
128 const double TWOPI  = 6.2831852;
129 const double ANSWER = 42;
130 
131 
132 /*
133  *	Syntactic sugar
134  */
135 #define y_min(a,b) ((a) < (b) ? (a) : (b))
136 #define y_max(a,b) ((a) > (b) ? (a) : (b))
137 const char *const Y_NULL = 0;  // NULL (const char *)
138 
139 
140 /*
141  *	To avoid including certain headers.
142  */
143 class rgb_c;
144 
145 
146 #include "wstructs.h"
147 
148 
149 /*
150  *	Doom definitions
151  *	Things about the Doom engine
152  *	FIXME should move as much of this as possible to the ygd file...
153  *	FIXME Hexen has a different value for MIN_DEATHMATH_STARTS
154  */
155 const int DOOM_PLAYER_HEIGHT         = 56;
156 const int DOOM_FLAT_WIDTH            = 64;
157 const int DOOM_FLAT_HEIGHT           = 64;
158 const size_t DOOM_MIN_DEATHMATCH_STARTS = 4;
159 const size_t DOOM_MAX_DEATHMATCH_STARTS = 10;
160 const size_t DOOM_COLOURS               = 256;
161 typedef enum { YGPF_NORMAL, YGPF_ALPHA, YGPF_PR } ygpf_t;
162 typedef enum { YGTF_NORMAL, YGTF_NAMELESS, YGTF_STRIFE11 } ygtf_t;
163 typedef enum { YGTL_NORMAL, YGTL_TEXTURES, YGTL_NONE } ygtl_t;
164 
165 
166 /*
167  *	Directory
168  */
169 /* The wad file pointer structure is used for holding the information
170    on the wad files in a linked list.
171    The first wad file is the main wad file. The rest are patches. */
172 class Wad_file;
173 
174 /* The master directory structure is used to build a complete directory
175    of all the data blocks from all the various wad files. */
176 typedef struct MasterDirectory huge *MDirPtr;
177 struct MasterDirectory
178    {
179    MDirPtr next;		// Next in list
180    const Wad_file *wadfile;	// File of origin
181    struct Directory dir;	// Directory data
182    };
183 
184 /* Lump location : enough information to load a lump without
185    having to do a directory lookup. */
186 struct Lump_loc
187    {
Lump_locLump_loc188    Lump_loc () { wad = 0; }
Lump_locLump_loc189    Lump_loc (const Wad_file *w, i32 o, i32 l) { wad = w; ofs = o; len = l; }
190    bool operator == (const Lump_loc& other) const
191      { return wad == other.wad && ofs == other.ofs && len == other.len; }
192    const Wad_file *wad;
193    i32 ofs;
194    i32 len;
195    };
196 #include "wstructs.h"
197 
198 
199 /*
200  *	The colour system.
201  *	FIXME: only the logical side of the colour system
202  *	should be declared here. The physical side should
203  *	be moved to a less used header as very few modules
204  *	need to know about it.
205  */
206 /* acolour_t -- an application colour number.
207    Several different application colours may refer to the same
208    physical colour. */
209 typedef u8 acolour_t;
210 #define ACOLOUR_NONE 0xff  // The out-of-band value
211 
212 #ifndef Y_BGI
213 /* The 16 VGA colours that DEU used to use.
214    For the BGI version, those macros are defined in graphics.h
215    FIXME: all references to these in the code should be removed. */
216 const acolour_t BLACK           = 0;
217 const acolour_t BLUE            = 1;
218 const acolour_t GREEN           = 2;
219 const acolour_t CYAN            = 3;
220 const acolour_t RED             = 4;
221 const acolour_t MAGENTA         = 5;
222 const acolour_t BROWN           = 6;
223 const acolour_t LIGHTGREY       = 7;
224 const acolour_t DARKGREY        = 8;
225 const acolour_t LIGHTBLUE       = 9;
226 const acolour_t LIGHTGREEN      = 10;
227 const acolour_t LIGHTCYAN       = 11;
228 const acolour_t LIGHTRED        = 12;
229 const acolour_t LIGHTMAGENTA    = 13;
230 const acolour_t YELLOW          = 14;
231 const acolour_t WHITE           = 15;
232 #endif
233 
234 // True logical colours
235 const acolour_t WINBG           = 16;
236 const acolour_t WINBG_LIGHT     = 17;
237 const acolour_t WINBG_DARK      = 18;
238 const acolour_t WINBG_HL        = 19;
239 
240 const acolour_t WINFG           = 20;
241 const acolour_t WINFG_HL        = 21;
242 const acolour_t WINFG_DIM       = 22;
243 const acolour_t WINFG_DIM_HL    = 23;
244 
245 const acolour_t WINLABEL        = 24;
246 const acolour_t WINLABEL_HL     = 25;
247 const acolour_t WINLABEL_DIM    = 26;
248 const acolour_t WINLABEL_DIM_HL = 27;
249 
250 const acolour_t GRID1           = 28;
251 const acolour_t GRID2H          = 29;
252 const acolour_t GRID2V          = 30;
253 const acolour_t GRID3H          = 31;
254 const acolour_t GRID3V          = 32;
255 const acolour_t GRID4H          = 33;
256 const acolour_t GRID4V          = 34;
257 const acolour_t LINEDEF_NO      = 35;
258 const acolour_t SECTOR_NO       = 36;
259 const acolour_t THING_NO        = 37;
260 const acolour_t VERTEX_NO       = 38;
261 const acolour_t CLR_ERROR       = 39;
262 const acolour_t THING_REM       = 40;	// Things when not in things mode
263 
264 const acolour_t SECTOR_TAG      = 41;
265 const acolour_t SECTOR_TAGTYPE  = 42;
266 const acolour_t SECTOR_TYPE     = 43;
267 
268 const acolour_t WINTITLE        = 44;
269 
270 const acolour_t NCOLOURS        = 45;
271 
272 
273 /*
274  *	More stuff
275  */
276 // The actual definition is in selectn.h
277 typedef struct SelectionList *SelPtr;
278 // Operations on the selection :
279 typedef enum
280 {
281   YS_ADD    = BV_SET,	// Add to selection
282   YS_REMOVE = BV_CLEAR,	// Remove from selection
283   YS_TOGGLE = BV_TOGGLE	// If not in selection, add; else, remove
284 } sel_op_t;
285 
286 // Confirmation options are stored internally this way :
287 typedef enum
288    {
289    YC_YES      = 'y',
290    YC_NO       = 'n',
291    YC_ASK      = 'a',
292    YC_ASK_ONCE = 'o'
293    } confirm_t;
294 
295 // Bit bashing operations
296 const int YO_AND    = 'a';  // Argument = mask
297 const int YO_CLEAR  = 'c';  // Argument = bit#
298 const int YO_COPY   = 'd';  // Argument = source_bit# dest_bit#
299 const int YO_OR     = 'o';  // Argument = mask
300 const int YO_SET    = 's';  // Argument = bit#
301 const int YO_TOGGLE = 't';  // Argument = bit#
302 const int YO_XOR    = 'x';  // Argument = mask
303 
304 
305 /*
306  *	Even more stuff ("the macros and constants")
307  */
308 
309 extern const char *const log_file;        // "yadex.log"
310 extern const char *const msg_unexpected;  // "unexpected error"
311 extern const char *const msg_nomem;       // "Not enough memory"
312 
313 // Convert screen/window coordinates to map coordinates
314 #define MAPX(x)		(OrigX + (int) (((int) (x) - ScrCenterX) / Scale))
315 #define MAPY(y)		(OrigY + (int) ((ScrCenterY - (int) (y)) / Scale))
316 
317 // Convert map coordinates to screen/window coordinates
318 #define SCREENX(x)	(ScrCenterX + (int) (((x) - OrigX) * Scale))
319 #define SCREENY(y)	(ScrCenterY + (int) ((OrigY - (y)) * Scale))
320 
321 // AYM 19980213: InputIntegerValue() uses this to mean that Esc was pressed
322 #define IIV_CANCEL  INT_MIN
323 
324 
325 /*
326  *	Not real variables -- just a way for functions
327  *	that return pointers to report errors in a better
328  *	fashion than by just returning NULL and setting
329  *	a global variable.
330  */
331 extern char error_non_unique[1];  // Found more than one
332 extern char error_none[1];        // Found none
333 extern char error_invalid[1];     // Invalid parameter
334 
335 
336 /*
337  *	Interfile global variables
338  */
339 
340 // Defined in yadex.cc
341 extern const char *install_dir; 	// Where yadex is installed
342 extern FILE *logfile;			// Filepointer to the error log
343 extern bool  Registered;		// Registered or shareware iwad ?
344 extern int screen_lines;		// Lines that our TTY can display
345 extern int remind_to_build_nodes;	// Remind the user to build nodes
346 
347 // Defined in yadex.c and set from
348 // command line and/or config file
349 extern bool  autoscroll;	// Autoscrolling enabled.
350 extern unsigned long autoscroll_amp;// Amplitude in percents of screen/window size.
351 extern unsigned long autoscroll_edge; // Max. dist. in pixels to edge.
352 extern const char *config_file;	// Name of the configuration file
353 extern int   copy_linedef_reuse_sidedefs;
354 extern int   cpu_big_endian;	// Am I running on a big-endian CPU ?
355 extern bool  Debug;			// Are we debugging?
356 extern int   default_ceiling_height;			// For new sectors
357 extern char  default_ceiling_texture[WAD_FLAT_NAME + 1];// For new sectors
358 extern int   default_floor_height;			// For new sectors
359 extern char  default_floor_texture[WAD_FLAT_NAME + 1];	// For new sectors
360 extern int   default_light_level;			// For new sectors
361 extern char  default_lower_texture[WAD_TEX_NAME + 1];	// For new linedefs
362 extern char  default_middle_texture[WAD_TEX_NAME + 1];	// For new linedefs
363 extern int   default_thing;				// For new THINGS
364 extern char  default_upper_texture[WAD_TEX_NAME + 1];	// For new linedefs
365 extern int   double_click_timeout;// Max ms between clicks of double click.
366 extern bool  Expert;		// Don't ask for confirmation for some ops.
367 extern const char *Game;	// Name of game "doom", "doom2", "heretic", ...
368 extern int   grid_pixels_min;   // Minimum grid step in pixels when not locked
369 extern int   GridMin;	 	// Minimum grid step in map units
370 extern int   GridMax;		// Maximum grid step in map units
371 extern int   idle_sleep_ms;	// Time to sleep after empty XPending()
372 extern int   zoom_default;	// Initial zoom factor for map
373 extern int   zoom_step;		// Step between zoom factors in percent
374 extern int   digit_zoom_base;	// Zoom factor of `1' key, in percent
375 extern int   digit_zoom_step;	// Step between digit keys, in percent
376 extern confirm_t insert_vertex_merge_vertices;
377 extern confirm_t insert_vertex_split_linedef;
378 extern bool  blindly_swap_sidedefs;
379 extern const char *Iwad1;	// Name of the Doom iwad
380 extern const char *Iwad2;	// Name of the Doom II iwad
381 extern const char *Iwad3;	// Name of the Heretic iwad
382 extern const char *Iwad4;	// Name of the Hexen iwad
383 extern const char *Iwad5;	// Name of the Strife iwad
384 extern const char *Iwad6;	// Name of the Doom alpha 0.2 iwad
385 extern const char *Iwad7;	// Name of the Doom alpha 0.4 iwad
386 extern const char *Iwad8;	// Name of the Doom alpha 0.5 iwad
387 extern const char *Iwad9;	// Name of the Doom press release iwad
388 extern const char *Iwad10;	// Name of the Strife 1.0 iwad
389 extern const char *MainWad;	// Name of the main wad file
390 #ifdef AYM_MOUSE_HACKS
391 extern int   MouseMickeysH;
392 extern int   MouseMickeysV;
393 #endif
394 extern char **PatchWads;	// List of pwad files
395 extern bool  Quiet;		// Don't beep when an object is selected
396 extern bool  Quieter;		// Don't beep, even on error
397 extern unsigned long scroll_less;// %s of screenful to scroll by
398 extern unsigned long scroll_more;// %s of screenful to scroll by
399 extern bool  Select0;		// Autom. select obj. 0 when switching modes
400 extern int   show_help;		// Print usage message and exit.
401 extern int   sprite_scale;	// Relative scale used to display sprites
402 extern bool  SwapButtons;	// Swap right and middle mouse buttons
403 extern int   verbose;		// Verbose mode
404 extern int   welcome_message;	// Print the welcome message on startup.
405 extern const char *bench;	// Benchmark to run
406 
407 // Defined in gfx.cc
408 extern int   ScrMaxX;		// Maximum display X-coord of screen/window
409 extern int   ScrMaxY;		// Maximum display Y-coord of screen/window
410 extern float Scale;		// Scale to draw map 20 to 1
411 
412 // Defined in wads.cc
413 extern MDirPtr   MasterDir;	// The master directory
414 class Serial_num;
415 extern Serial_num master_dir_serial;	// The revision# thereof
416 
417 // Defined in edit.cc
418 extern bool InfoShown;          // Is the bottom line displayed?
419 
420 // Defined in mouse.cc
421 #if defined Y_BGI
422 extern bool UseMouse;		// Is there a mouse driver?
423 #elif defined Y_X11
424 #define UseMouse 1
425 #endif
426 
427 
428 /*
429  *	Prototypes
430  *	AYM 1998-10-16: DEU used to have _all_ prototypes here. Thus
431  *	I had to recompile _all_ the modules every time I changed
432  *	a single prototype. To avoid this, my theory is to put all
433  *	the prototypes I can in individual headers. There is still
434  *	room for improvement on that matter...
435  */
436 
437 // checks.cc (previously in editobj.cc)
438 void CheckLevel (int, int, int pulldown); /* SWAP! */
439 bool CheckStartingPos (void); /* SWAP! */
440 
441 // colour1.cc
442 int getcolour (const char *s, rgb_c *rgb);
443 
444 // colour2.cc
445 int rgb2irgb (int r, int g, int b);
446 
447 // colour3.cc
448 void irgb2rgb (int c, rgb_c *rgb);
449 
450 // editobj.cc
451 int InputObjectNumber (int, int, int, int);
452 int InputObjectXRef (int, int, int, bool, int);
453 bool Input2VertexNumbers (int, int, const char *, int *, int *);
454 void EditObjectsInfo (int, int, int, SelPtr);
455 void InsertStandardObject (int, int, int choice); /* SWAP! */
456 void MiscOperations (int, SelPtr *, int choice); /* SWAP! */
457 
458 // game.cc
459 void InitGameDefs (void);
460 void LoadGameDefs (const char *game);
461 void FreeGameDefs (void);
462 
463 // geom.cc
464 unsigned ComputeAngle (int, int);
465 unsigned ComputeDist (int, int);
466 
467 // input.cc
468 #include "input.h"
469 
470 // l_align.cc (previously in objects.cc)
471 void AlignTexturesY (SelPtr *); /* SWAP! */
472 void AlignTexturesX (SelPtr *); /* SWAP! */
473 
474 // l_misc.cc (previously in objects.cc)
475 void FlipLineDefs (SelPtr, bool); /* SWAP! */
476 void SplitLineDefs (SelPtr); /* SWAP! */
477 void MakeRectangularNook (SelPtr obj, int width, int depth, int convex); /* SWAP! */
478 void SetLinedefLength (SelPtr obj, int length, int move_2nd_vertex);
479 
480 // l_prop.cc (previously in editobj.cc)
481 void LinedefProperties (int x0, int y0, SelPtr obj);
482 
483 // l_unlink.cc
484 void unlink_sidedef (SelPtr linedefs, int side1, int side2);
485 
486 // levels.cc
487 int ReadLevelData (const char *); /* SWAP! */
488 void ForgetLevelData (void); /* SWAP! */
489 int SaveLevelData (const char *, const char *level_name); /* SWAP! */
490 void ReadWTextureNames (void);
491 void ForgetFTextureNames (void);
492 int is_flat_name_in_list (const char *name);
493 void ReadFTextureNames (void);
494 void ForgetWTextureNames (void);
495 
496 // mouse.cc (this module is entirely DOS-specific)
497 #if defined Y_BGI
498 void CheckMouseDriver (void);
499 void ShowMousePointer (void);
500 void HideMousePointer (void);
501 void GetMouseCoords (int *, int *, int *);
502 void SetMouseCoords (int, int);
503 void SetMouseLimits (int, int, int, int);
504 void ResetMouseLimits (void);
505 void MouseCallBackFunction (void);
506 #elif defined Y_X11
507 #define CheckMouseDriver nop
508 #define ShowMousePointer nop
509 #define HideMousePointer nop
510 #define GetMouseCoords   nop
511 #define SetMouseCoords   nop
512 #define SetMouseLimits   nop
513 #define ResetMouseLimits nop
514 #endif
515 
516 // names.cc
517 const char *GetObjectTypeName (int);
518 const char *GetEditModeName (int);
519 const char *GetLineDefTypeName (int);
520 const char *GetLineDefTypeLongName (int);
521 const char *GetLineDefFlagsName (int);
522 const char *GetLineDefFlagsLongName (int);
523 const char *GetSectorTypeName (int);
524 const char *GetSectorTypeLongName (int);
525 
526 // nop.cc
527 void nop (...);
528 
529 // s_door.cc (previously in objects.cc)
530 void MakeDoorFromSector (int); /* SWAP! */
531 
532 // s_lift.cc (previously in objects.cc)
533 void MakeLiftFromSector (int); /* SWAP! */
534 
535 // s_merge.cc (previously in objects.cc)
536 void MergeSectors (SelPtr *); /* SWAP! */
537 void DeleteLineDefsJoinSectors (SelPtr *); /* SWAP! */
538 
539 // s_misc.cc (previously in objects.cc)
540 void DistributeSectorFloors (SelPtr); /* SWAP! */
541 void DistributeSectorCeilings (SelPtr); /* SWAP! */
542 void RaiseOrLowerSectors (SelPtr obj);
543 void BrightenOrDarkenSectors (SelPtr obj);
544 
545 // s_prop.cc (previously in editobj.cc)
546 void SectorProperties (int x0, int y0, SelPtr obj);
547 
548 // s_split.cc (previously in objects.cc)
549 void SplitSector (int, int); /* SWAP! */
550 void SplitLineDefsAndSector (int, int); /* SWAP! */
551 
552 // swapmem.cc
553 void InitSwap (void);
554 void FreeSomeMemory (void);
555 void ObjectsNeeded (int, ...);
556 
557 // scrnshot.cc
558 void ScreenShot (void);
559 
560 // selrect.cc
561 // t_prop.c (previously in editobj.c)
562 void ThingProperties (int x0, int y0, SelPtr obj);
563 
564 // v_merge.cc
565 void DeleteVerticesJoinLineDefs (SelPtr ); /* SWAP! */
566 void MergeVertices (SelPtr *); /* SWAP! */
567 bool AutoMergeVertices (SelPtr *, int obj_type, char operation); /* SWAP! */
568 
569 // v_polyg.cc
570 void InsertPolygonVertices (int, int, int, int);
571 
572 // verbmsg.cc
573 void verbmsg (const char *fmt, ...);
574 
575 // version.cc
576 extern const char *const yadex_version;
577 extern const char *const yadex_source_date;
578 
579 // prefix.cc
580 extern const char *const yadex_etc_version;
581 extern const char *const yadex_etc_common;
582 extern const char *const yadex_ygd_version;
583 extern const char *const yadex_ygd_common;
584 
585 // wads.cc
586 MDirPtr FindMasterDir (MDirPtr, const char *);
587 MDirPtr FindMasterDir (MDirPtr, const char *, const char *);
588 int entryname_cmp (const char *entry1, const char *entry2);
589 
590 // warning.cc
591 void warn (const char *fmt, ...);
592 
593 // yadex.cc
594 void Beep (void);
595 void PlaySound (int, int);
596 void LogMessage (const char *, ...);
597 
598 
599 #endif  /* DO NOT ADD ANYTHING AFTER THIS LINE */
600