OSDN Git Service

(2.2.0.6) モンスター1種追加。 / Add a monster.
[hengband/hengband.git] / src / h-type.h
1 /*!
2  * @file h-type.h
3  * @brief ゲーム中に用いる変数型定義 /
4  * Basic "types".
5  * @date 2014/08/17
6  * @author
7  * 不明(変愚蛮怒スタッフ?)
8  * @details
9  * <pre>
10  * Note the attempt to make all basic types have 4 letters.
11  * This improves readibility and standardizes the code.
12  * Likewise, all complex types are at least 4 letters.
13  * Thus, almost every three letter word is a legal variable.
14  * But beware of certain reserved words ('for' and 'if' and 'do').
15  * Note that the type used in structures for bit flags should be uint.
16  * As long as these bit flags are sequential, they will be space smart.
17  * Note that on some machines, apparently "signed char" is illegal.
18  * It must be true that char/byte takes exactly 1 byte
19  * It must be true that sind/uind takes exactly 2 bytes
20  * It must be true that sbig/ubig takes exactly 4 bytes
21  * On Sparc's, a sint takes 4 bytes (2 is legal)
22  * On Sparc's, a uint takes 4 bytes (2 is legal)
23  * On Sparc's, a long takes 4 bytes (8 is legal)
24  * On Sparc's, a huge takes 4 bytes (8 is legal)
25  * On Sparc's, a vptr takes 4 bytes (8 is legal)
26  * On Sparc's, a real takes 8 bytes (4 is legal)
27  * Note that some files have already been included by "h-include.h"
28  * These include <stdio.h> and <sys/types>, which define some types
29  * In particular, uint is defined so we do not have to define it
30  * Also, see <limits.h> for min/max values for sind, uind, long, huge
31  * (SHRT_MIN, SHRT_MAX, USHRT_MAX, LONG_MIN, LONG_MAX, ULONG_MAX)
32  * These limits should be verified and coded into "h-constant.h".
33  * </pre>
34  */
35
36 #ifndef INCLUDED_H_TYPE_H
37 #define INCLUDED_H_TYPE_H
38
39 #ifdef HAVE_STDINT_H
40 #include <stdint.h>
41 #endif
42
43 /*** Special 4 letter names for some standard types ***/
44
45 typedef void *vptr;       /*!< void型ポインタ定義 / A standard pointer (to "void" because ANSI C says so) */
46 typedef const char *cptr; /*!< 文字列定数用ポインタ定義 / A simple pointer (to unmodifiable strings) */
47 typedef double real;      /*!< doubleをreal型として定義 / Since float's are silly, hard code real numbers as doubles */
48
49
50 /*!
51  * @brief エラーコードの定義 / Error codes for function return values
52  * @details
53  * 一般に成功時0、失敗時負数、何らかの問題時整数とする。
54  * Success = 0, Failure = -N, Problem = +N 
55  */
56 typedef int errr;
57
58 #undef uint
59 #define uint uint_hack /*!< 非マッキントッシュ環境で重複を避けるためのuint_hack型定義 / Hack -- prevent problems with non-MACINTOSH */
60
61 #undef huge
62 #define huge huge_hack /*!< WINDOWS環境で重複を避けるためのhuge_hack定義 / Hack -- prevent problems with WINDOWS */
63
64 #undef byte
65 #define byte byte_hack /*!< AMIGA環境で重複を避けるためのbyte_hack定義 / Hack -- prevent problems with AMIGA */
66
67 #undef bool
68 #define bool bool_hack /*!< C++環境で重複を避けるためのbool_hack定義 Hack -- prevent problems with C++ */
69
70
71 /* Note that "signed char" is not always "defined" */
72 /* So always use "s16b" to hold small signed values */
73 /* A signed byte of memory */
74 /* typedef signed char syte; */
75
76 typedef unsigned char byte; /*!< byte型をunsighned charとして定義 / Note that unsigned values can cause math problems / An unsigned byte of memory */
77 typedef char bool; /*!< bool型をcharとして定義 / Note that a bool is smaller than a full "int" / Simple True/False type */
78 typedef int sint; /*!< sint型をintとして定義 / A signed, standard integer (at least 2 bytes) */
79 typedef unsigned int uint; /* uint型をintとして定義 /  An unsigned, "standard" integer (often pre-defined) */
80
81 /* The largest possible signed integer (pre-defined) */
82 /* typedef long long; */
83
84 /* The largest possible unsigned integer */
85 typedef unsigned long huge;
86
87 /* Signed/Unsigned 16 bit value */
88 #ifdef HAVE_STDINT_H
89 typedef int16_t s16b;
90 typedef uint16_t u16b;
91 #else
92 typedef signed short s16b;
93 typedef unsigned short u16b;
94 #endif
95
96 /* Signed/Unsigned 32 bit value */
97 #ifdef HAVE_STDINT_H
98 typedef int32_t s32b;
99 typedef uint32_t u32b;
100 #else
101 typedef signed long s32b;
102 typedef unsigned long u32b;
103 #endif
104
105
106
107
108 /*** Pointers to all the basic types defined above ***/
109
110 typedef real *real_ptr;
111 typedef errr *errr_ptr;
112 typedef char *char_ptr;
113 typedef byte *byte_ptr;
114 typedef bool *bool_ptr;
115 typedef sint *sint_ptr;
116 typedef uint *uint_ptr;
117 typedef long *long_ptr;
118 typedef huge *huge_ptr;
119 typedef s16b *s16b_ptr;
120 typedef u16b *u16b_ptr;
121 typedef s32b *s32b_ptr;
122 typedef u32b *u32b_ptr;
123 typedef vptr *vptr_ptr;
124 typedef cptr *cptr_ptr;
125
126
127
128 /*** Pointers to Functions of special types (for various purposes) ***/
129
130 /* A generic function takes a user data and a special data */
131 typedef errr    (*func_gen)(vptr, vptr);
132
133 /* An equality testing function takes two things to compare (bool) */
134 typedef bool    (*func_eql)(vptr, vptr);
135
136 /* A comparison function takes two things and to compare (-1,0,+1) */
137 typedef sint    (*func_cmp)(vptr, vptr);
138
139 /* A hasher takes a thing (and a max hash size) to hash (0 to siz - 1) */
140 typedef uint    (*func_hsh)(vptr, uint);
141
142 /* A key extractor takes a thing and returns (a pointer to) some key */
143 typedef vptr    (*func_key)(vptr);
144
145
146
147 #endif
148