src/main.h

changeset 72
03e4d9db3fd9
child 73
1ee9b312dc18
equal deleted inserted replaced
71:11f23fabf8a6 72:03e4d9db3fd9
1 #ifndef BOTC_COMMON_H
2 #define BOTC_COMMON_H
3
4 #if !defined (__cplusplus) || __cplusplus < 201103L
5 # error botc requires a C++11-compliant compiler to be built
6 #endif
7
8 #include <cstdio>
9 #include <cstdarg>
10 #include <cstdint>
11 #include "types.h"
12 #include "bots.h"
13 #include "str.h"
14 #include "containers.h"
15 #include "format.h"
16
17 // Application name and version
18 #define APPNAME "botc"
19 #define VERSION_MAJOR 0
20 #define VERSION_MINOR 999
21
22 // On Windows, files are case-insensitive
23 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)
24 #define FILE_CASEINSENSITIVE
25 #endif
26
27 // Parser mode: where is the parser at?
28 enum parsermode_e {
29 MODE_TOPLEVEL, // at top level
30 MODE_EVENT, // inside event definition
31 MODE_MAINLOOP, // inside mainloop
32 MODE_ONENTER, // inside onenter
33 MODE_ONEXIT, // inside onexit
34 };
35
36 enum type_e {
37 TYPE_UNKNOWN = 0,
38 TYPE_VOID,
39 TYPE_INT,
40 TYPE_STRING,
41 TYPE_BOOL,
42 };
43
44 #define elif else if
45
46 #define CHECK_FILE(pointer,path,action) \
47 if (!pointer) { \
48 error ("couldn't open %s for %s!\n", path.chars(), action); \
49 exit (1); \
50 }
51
52 // Plural expression
53 #define PLURAL(n) (n != 1) ? "s" : ""
54
55 // Shortcut for zeroing something
56 #define ZERO(obj) memset (&obj, 0, sizeof (obj));
57
58 void error (const char* text, ...);
59 string ObjectFileName (string s);
60 bool fexists (string path);
61 type_e GetTypeByName (string token);
62 string GetTypeName (type_e type);
63
64 // Make the parser's variables globally available
65 extern int g_NumStates;
66 extern int g_NumEvents;
67 extern parsermode_e g_CurMode;
68 extern string g_CurState;
69
70 #define neurosphere if (g_Neurosphere)
71 #define twice for (int repeat_token = 0; repeat_token < 2; repeat_token++)
72
73 #ifndef __GNUC__
74 #define __attribute__(X)
75 #endif
76 #define deprecated __attribute__ ((deprecated))
77
78 // Power function
79 template<class T> T pow (T a, unsigned int b) {
80 if (!b)
81 return 1;
82
83 T r = a;
84 while (b > 1) {
85 b--;
86 r = r * a;
87 }
88
89 return r;
90 }
91
92 // Byte datatype
93 typedef int32_t word;
94 typedef unsigned char byte;
95
96 // Keywords
97 extern const char** g_Keywords;
98
99 bool IsKeyword (string s);
100 unsigned int NumKeywords ();
101
102 // Script mark and reference
103 struct ScriptMark {
104 string name;
105 size_t pos;
106 };
107
108 struct ScriptMarkReference {
109 unsigned int num;
110 size_t pos;
111 };
112
113 // ====================================================================
114 // Generic union
115 template <class T> union union_t {
116 T val;
117 byte b[sizeof (T)];
118 char c[sizeof (T)];
119 double d;
120 float f;
121 int i;
122 word w;
123 };
124
125 // ====================================================================
126 // Finds a byte in the given value.
127 template <class T> inline unsigned char GetByteIndex (T a, unsigned int b) {
128 union_t<T> uni;
129 uni.val = a;
130 return uni.b[b];
131 }
132
133 #endif // BOTC_COMMON_H

mercurial