Wed, 19 Dec 2012 22:01:42 +0200
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
0 | 1 | /* |
2 | * botc source code | |
3 | * Copyright (C) 2012 Santeri `Dusk` Piippo | |
4 | * All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright notice, | |
10 | * this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
12 | * this list of conditions and the following disclaimer in the documentation | |
13 | * and/or other materials provided with the distribution. | |
3 | 14 | * 3. Neither the name of the developer nor the names of its contributors may |
15 | * be used to endorse or promote products derived from this software without | |
16 | * specific prior written permission. | |
0 | 17 | * 4. Redistributions in any form must be accompanied by information on how to |
18 | * obtain complete source code for the software and any accompanying | |
19 | * software that uses the software. The source code must either be included | |
20 | * in the distribution or be available for no more than the cost of | |
21 | * distribution plus a nominal fee, and must be freely redistributable | |
22 | * under reasonable conditions. For an executable file, complete source | |
23 | * code means the source code for all modules it contains. It does not | |
24 | * include source code for modules or files that typically accompany the | |
25 | * major components of the operating system on which the executable file | |
26 | * runs. | |
27 | * | |
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
38 | * POSSIBILITY OF SUCH DAMAGE. | |
39 | */ | |
40 | ||
41 | #ifndef __COMMON_H__ | |
42 | #define __COMMON_H__ | |
43 | ||
26
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
44 | #include <stdio.h> |
0 | 45 | #include <stdarg.h> |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
46 | #include <stdint.h> |
0 | 47 | #include "bots.h" |
48 | #include "str.h" | |
49 | ||
34
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
50 | // Application name and version |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
51 | #define APPNAME "botc" |
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
52 | #define VERSION_MAJOR 0 |
69
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
53 | #define VERSION_MINOR 999 |
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
54 | |
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
55 | // Use a macro for Write so we can get the function name |
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
56 | // This can be pretty crucial in debugging. |
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
57 | #ifdef __GNUC__ |
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
58 | #define Write(STUFF) DoWrite (__PRETTY_FUNCTION__, STUFF) |
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
59 | #else |
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
60 | #define Write(STUFF) DoWrite (__func__, STUFF) |
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
61 | #endif |
0 | 62 | |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
63 | // On Windows, files are case-insensitive |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
64 | #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) |
33
fd35f6cb5f28
Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
65 | #define FILE_CASEINSENSITIVE |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
66 | #endif |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
67 | |
34
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
68 | // Parser mode: where is the parser at? |
67
0a202714eea4
Some rework on variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
69 | enum parsermode_e { |
26
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
70 | MODE_TOPLEVEL, // at top level |
34
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
71 | MODE_EVENT, // inside event definition |
26
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
72 | MODE_MAINLOOP, // inside mainloop |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
73 | MODE_ONENTER, // inside onenter |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
74 | MODE_ONEXIT, // inside onexit |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
75 | }; |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
76 | |
68
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
77 | enum type_e { |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
78 | TYPE_UNKNOWN = 0, |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
79 | TYPE_VOID, |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
80 | TYPE_INT, |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
81 | TYPE_STRING, |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
82 | TYPE_BOOL, |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
83 | }; |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
84 | |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
85 | #define CHECK_FILE(pointer,path,action) \ |
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
86 | if (!pointer) { \ |
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
87 | error ("couldn't open %s for %s!\n", (char*)path, action); \ |
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
88 | exit (1); \ |
0 | 89 | } |
90 | ||
34
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
91 | // Shortcut for formatting |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
92 | #define PERFORM_FORMAT(in, out) \ |
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
93 | va_list v; \ |
0 | 94 | va_start (v, in); \ |
95 | char* out = vdynformat (in, v, 256); \ | |
96 | va_end (v); | |
97 | ||
34
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
98 | // Plural expression |
22
b48e10ca8832
Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
99 | #define PLURAL(n) (n != 1) ? "s" : "" |
b48e10ca8832
Added rudimentary global var support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
3
diff
changeset
|
100 | |
59
891b9e6ee139
Added support for continue-statements
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
101 | // Shortcut for zeroing something |
891b9e6ee139
Added support for continue-statements
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
102 | #define ZERO(obj) memset (&obj, 0, sizeof (obj)); |
891b9e6ee139
Added support for continue-statements
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
103 | |
0 | 104 | void error (const char* text, ...); |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
105 | char* ObjectFileName (str s); |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
106 | bool fexists (char* path); |
68
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
107 | type_e GetTypeByName (str token); |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
67
diff
changeset
|
108 | str GetTypeName (type_e type); |
0 | 109 | |
34
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
110 | // Make the parser's variables globally available |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
111 | extern int g_NumStates; |
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
112 | extern int g_NumEvents; |
67
0a202714eea4
Some rework on variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
113 | extern parsermode_e g_CurMode; |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
114 | extern str g_CurState; |
66
4fc1ec88aa41
Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
115 | |
4fc1ec88aa41
Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
116 | #define neurosphere if (g_Neurosphere) |
4fc1ec88aa41
Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
117 | #define twice for (int repeat_token = 0; repeat_token < 2; repeat_token++) |
4fc1ec88aa41
Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
118 | |
4fc1ec88aa41
Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
119 | #ifndef __GNUC__ |
4fc1ec88aa41
Good bunch of changes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
120 | #define __attribute__(X) |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
121 | #endif |
67
0a202714eea4
Some rework on variables
Teemu Piippo <crimsondusk64@gmail.com>
parents:
66
diff
changeset
|
122 | #define deprecated __attribute__ ((deprecated)) |
1
f0c61c204bc8
Added support for #include directives, added basic header and statistics printing.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
0
diff
changeset
|
123 | |
26
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
124 | // Power function |
63
0557babc8675
- Fixed error display - peeking was pushing recorded `cursor` position out of sync
Teemu Piippo <crimsondusk64@gmail.com>
parents:
59
diff
changeset
|
125 | template<class T> T pow (T a, unsigned int b) { |
26
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
126 | if (!b) |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
127 | return 1; |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
128 | |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
129 | T r = a; |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
130 | while (b > 1) { |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
131 | b--; |
63
0557babc8675
- Fixed error display - peeking was pushing recorded `cursor` position out of sync
Teemu Piippo <crimsondusk64@gmail.com>
parents:
59
diff
changeset
|
132 | r = r * a; |
26
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
133 | } |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
134 | |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
135 | return r; |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
136 | } |
54eaea6dc27c
Mainloop and onenter definitions are now written into separate buffers first and only written to file after state ends. Why? Zandronum seems to demand that mainloop definitions MUST be written right after any onenter one. This way, mainloop and onenter definitions can be written without this restriction in the script. Also now I have a cool uchar-buffer class :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
137 | |
33
fd35f6cb5f28
Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
138 | // Whitespace check |
fd35f6cb5f28
Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
139 | inline bool IsCharWhitespace (char c) { |
fd35f6cb5f28
Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
140 | return (c <= 32 || c == 127 || c == 255); |
fd35f6cb5f28
Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
141 | } |
fd35f6cb5f28
Added a preprocessor with proper #include support. Macro support via #define is planned too. God, was it a B-I-T-C-H to get working right, though..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
142 | |
34
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
143 | // Byte datatype |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
144 | typedef int32_t word; |
50
2e333a3ca49a
Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents:
47
diff
changeset
|
145 | typedef unsigned char byte; |
36
a8838b5f1213
Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
34
diff
changeset
|
146 | |
a8838b5f1213
Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
34
diff
changeset
|
147 | // Keywords |
a8838b5f1213
Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
34
diff
changeset
|
148 | #ifndef __MAIN_CXX__ |
a8838b5f1213
Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
34
diff
changeset
|
149 | extern const char** g_Keywords; |
a8838b5f1213
Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
34
diff
changeset
|
150 | #endif |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
151 | |
36
a8838b5f1213
Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
34
diff
changeset
|
152 | bool IsKeyword (str s); |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
153 | unsigned int NumKeywords (); |
34
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
154 | |
41
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
155 | // Script mark and reference |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
156 | struct ScriptMark { |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
157 | str name; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
158 | size_t pos; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
159 | }; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
160 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
161 | struct ScriptMarkReference { |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
162 | unsigned int num; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
163 | size_t pos; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
164 | }; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
165 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
166 | // ==================================================================== |
41
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
167 | // Generic union |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
168 | template <class T> union union_t { |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
169 | T val; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
170 | byte b[sizeof (T)]; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
171 | char c[sizeof (T)]; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
172 | double d; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
173 | float f; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
174 | int i; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
175 | word w; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
176 | }; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
177 | |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
178 | // ==================================================================== |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
179 | // Finds a byte in the given value. |
41
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
180 | template <class T> inline unsigned char GetByteIndex (T a, unsigned int b) { |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
181 | union_t<T> uni; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
182 | uni.val = a; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
183 | return uni.b[b]; |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
184 | } |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
185 | |
0 | 186 | #endif // __COMMON_H__ |