1 //----------------------------------------------------------------------------
2 //  EDGE Basic Types
3 //----------------------------------------------------------------------------
4 //
5 //  Copyright (c) 1999-2008  The EDGE Team.
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //----------------------------------------------------------------------------
18 //
19 //  Based on the DOOM source code, released by Id Software under the
20 //  following copyright:
21 //
22 //    Copyright (C) 1993-1996 by id Software, Inc.
23 //
24 //----------------------------------------------------------------------------
25 
26 #ifndef __DDF_TYPE_H__
27 #define __DDF_TYPE_H__
28 
29 #include "epi/utility.h"
30 
31 class mobjtype_c;
32 
33 
34 // RGB 8:8:8
35 // (FIXME: use epi::colour_c)
36 typedef unsigned int rgbcol_t;
37 
38 #define RGB_NO_VALUE  0x01FEFE  /* bright CYAN */
39 
40 #define RGB_MAKE(r,g,b)  (((r) << 16) | ((g) << 8) | (b))
41 
42 #define RGB_RED(rgbcol)  (((rgbcol) >> 16) & 0xFF)
43 #define RGB_GRN(rgbcol)  (((rgbcol) >>  8) & 0xFF)
44 #define RGB_BLU(rgbcol)  (((rgbcol)      ) & 0xFF)
45 
46 // useful colors
47 #define T_BLACK   RGB_MAKE(  0,  0,  0)
48 #define T_DGREY   RGB_MAKE( 64, 64, 64)
49 #define T_MGREY   RGB_MAKE(128,128,128)
50 #define T_LGREY   RGB_MAKE(208,208,208)
51 #define T_WHITE   RGB_MAKE(255,255,255)
52 
53 #define T_RED     RGB_MAKE(255,0,0)
54 #define T_GREEN   RGB_MAKE(0,255,0)
55 #define T_BLUE    RGB_MAKE(0,0,255)
56 #define T_YELLOW  RGB_MAKE(255,255,24)
57 #define T_PURPLE  RGB_MAKE(255,24,255)
58 #define T_CYAN    RGB_MAKE(24,255,255)
59 #define T_ORANGE  RGB_MAKE(255,72,0)
60 #define T_LTBLUE  RGB_MAKE(128,128,255)
61 
62 
63 // percentage type.  Ranges from 0.0f - 1.0f
64 typedef float percent_t;
65 
66 #define PERCENT_MAKE(val)  ((val) / 100.0f)
67 #define PERCENT_2_FLOAT(perc)  (perc)
68 
69 
70 typedef u32_t angle_t;
71 
72 #define ANGLEBITS  32
73 
74 // Binary Angle Measument, BAM.
75 #define ANG0   0x00000000
76 #define ANG1   0x00B60B61
77 #define ANG45  0x20000000
78 #define ANG90  0x40000000
79 #define ANG135 0x60000000
80 #define ANG180 0x80000000
81 #define ANG225 0xa0000000
82 #define ANG270 0xc0000000
83 #define ANG315 0xe0000000
84 
85 #define ANG_MAX 0xffffffff
86 
87 // Only use this one with float.
88 #define ANG360  (4294967296.0)
89 
90 #define ANG5   (ANG45/9)
91 
92 // Conversion macros:
93 
94 #define F2AX(n)  (((n) < 0) ? (360.0f + (n)) : (n))
95 #define ANG_2_FLOAT(a)  ((float) (a) * 360.0f / 4294967296.0f)
96 #define FLOAT_2_ANG(n)  ((angle_t) (F2AX(n) / 360.0f * 4294967296.0f))
97 
98 
99 // Our lumpname class
100 #define LUMPNAME_SIZE 10
101 
102 class lumpname_c
103 {
104 public:
lumpname_c()105 	lumpname_c() { clear(); }
lumpname_c(lumpname_c & rhs)106 	lumpname_c(lumpname_c &rhs) { Set(rhs.data); }
~lumpname_c()107 	~lumpname_c() {};
108 
109 private:
110 	char data[LUMPNAME_SIZE];
111 
112 public:
clear()113 	void clear() { data[0] = '\0'; }
114 
c_str()115 	const char *c_str() const { return data; }
116 
empty()117 	inline bool empty() const { return data[0] == '\0'; }
118 
Set(const char * s)119 	void Set(const char *s)
120 	{
121 		int i;
122 
123 		for (i=0; i<(LUMPNAME_SIZE-1) && *s; i++, s++)
124 			data[i] = *s;
125 
126 		data[i] = '\0';
127 	}
128 
129 	lumpname_c& operator=(lumpname_c &rhs)
130 	{
131 		if (&rhs != this)
132 			Set(rhs.data);
133 
134 		return *this;
135 	}
136 
137 	char operator[](int idx) const { return data[idx]; }
138 	operator const char* () const { return data; }
139 };
140 
141 
142 class mobj_strref_c
143 {
144 public:
mobj_strref_c()145 	mobj_strref_c() : name(), def(NULL) { }
mobj_strref_c(const char * s)146 	mobj_strref_c(const char *s) : name(s), def(NULL) { }
mobj_strref_c(const mobj_strref_c & rhs)147 	mobj_strref_c(const mobj_strref_c &rhs) : name(rhs.name), def(NULL) { }
~mobj_strref_c()148 	~mobj_strref_c() {};
149 
150 private:
151 	epi::strent_c name;
152 
153 	const mobjtype_c *def;
154 
155 public:
GetName()156 	const char *GetName() const { return name.c_str(); }
157 
158 	const mobjtype_c *GetRef();
159 	// Note: this returns NULL if not found, in which case you should
160 	// produce an error, since future calls will do the search again.
161 
162 	mobj_strref_c& operator= (mobj_strref_c &rhs)
163 	{
164 		if (&rhs != this)
165 		{
166 			name = rhs.name;
167 			def = NULL;
168 		}
169 
170 		return *this;
171 	}
172 };
173 
174 
175 #endif /*__DDF_TYPE_H__*/
176 
177 //--- editor settings ---
178 // vi:ts=4:sw=4:noexpandtab
179