1 /* DooM2D: Midnight on the Firing Line
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 module xmain_d2d
is aliced
;
25 import std
.concurrency
;
27 import arsd
.simpledisplay
;
29 import iv
.glbinds
: GL_NUM_SHADING_LANGUAGE_VERSIONS
; // please rdmd
31 import iv
.cmdcon
: ConInputChar
;
53 // ////////////////////////////////////////////////////////////////////////// //
58 // ////////////////////////////////////////////////////////////////////////// //
59 void main (string
[] args
) {
60 FuncPool
.dumpCode
= false;
61 FuncPool
.dumpCodeSize
= false;
62 dacsDumpSemantic
= false;
64 //version(rdmd) { dacsOptimize = 0; }
65 bool compileOnly
= false;
68 for (usize idx
= 1; idx
< args
.length
; ++idx
) {
70 if (args
[idx
].length
< 1) continue;
71 if (args
[idx
] == "--dump-code") FuncPool
.dumpCode
= true;
72 else if (args
[idx
] == "--dump-code-size") FuncPool
.dumpCodeSize
= true;
73 else if (args
[idx
] == "--dump-semantic") dacsDumpSemantic
= true;
74 else if (args
[idx
] == "--dump-all") { FuncPool
.dumpCode
= true; FuncPool
.dumpCodeSize
= true; dacsDumpSemantic
= true; }
75 else if (args
[idx
] == "--compile") compileOnly
= true;
76 else if (args
[idx
] == "--compile-only") compileOnly
= true;
77 else if (args
[idx
] == "--messages") ++dacsMessages
;
78 else if (args
[idx
] == "--no-copro") dacsOptimizeNoCoPro
= true;
79 else if (args
[idx
] == "--no-deadass") dacsOptimizeNoDeadAss
= true;
80 else if (args
[idx
] == "--no-purekill") dacsOptimizeNoPureKill
= true;
81 else if (args
[idx
] == "--no-vsync") doVBL
= false;
82 else if (args
[idx
] == "--vsync") doVBL
= true;
83 else if (args
[idx
].length
> 2 && args
[idx
][0..2] == "-O") {
85 ubyte olevel
= to
!ubyte(args
[idx
][2..$]);
86 dacsOptimize
= olevel
;
87 } else if (args
[idx
][0] == '-') {
92 foreach (immutable c
; idx
+1..args
.length
) args
.ptr
[c
-1] = args
.ptr
[c
];
97 if (processCL(args
)) return;
99 addInternalActorFields();
101 static void setDP () {
105 import std
.file
: thisExePath
;
106 import std
.path
: dirName
;
107 setDataPath(thisExePath
.dirName
~"/data");
109 addPak(getDataPath
~"base.pk3"); registerWadScripts();
110 //addWad("/home/ketmar/k8prj/doom2d-tl/data/doom2d.wad"); registerWadScripts();
111 //addWad("/home/ketmar/k8prj/doom2d-tl/data/meat.wad"); registerWadScripts();
112 //addWad("/home/ketmar/k8prj/doom2d-tl/data/megadm.wad"); registerWadScripts();
113 //addWad("/home/ketmar/k8prj/doom2d-tl/data/megadm1.wad"); registerWadScripts();
114 //addWad("/home/ketmar/k8prj/doom2d-tl/data/superdm.wad"); registerWadScripts();
115 //addWad("/home/ketmar/k8prj/doom2d-tl/data/zadoomka.wad"); registerWadScripts();
121 if (compileOnly
) return;
127 setOpenGLContextVersion(3, 2); // up to GLSL 150
128 //openGLContextCompatible = false;
130 curmapname
= "maps/map01.d2m";
131 //conwriteln(genNextMapName());
133 sdwindow
= new SimpleWindow(vlWidth
, vlHeight
, "D2D", OpenGlOptions
.yes
, Resizability
.fixedSize
);
134 //sdwindow.hideCursor();
136 sdwindow
.closeQuery
= delegate () { concmd("quit"); };
138 sdwindow
.visibleForTheFirstTime
= delegate () {
140 sdwindow
.setAsCurrentOpenGlContext(); // make this window active
143 import core.stdc.stdio;
144 printf("GL version: %s\n", glGetString(GL_VERSION));
146 glGetIntegerv(GL_MAJOR_VERSION, &h);
147 glGetIntegerv(GL_MINOR_VERSION, &l);
148 printf("version: %d.%d\n", h, l);
149 printf("shader version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
151 glGetIntegerv(GL_NUM_SHADING_LANGUAGE_VERSIONS, &svcount);
153 printf("%d shader versions supported:\n", svcount);
154 foreach (GLuint n; 0..svcount) printf(" %d: %s\n", n, glGetStringi(GL_SHADING_LANGUAGE_VERSION, n));
158 glGetIntegerv(GL_NUM_EXTENSIONS, &ecount);
160 printf("%d extensions supported:\n", ecount);
161 foreach (GLuint n; 0..ecount) printf(" %d: %s\n", n, glGetStringi(GL_EXTENSIONS, n));
166 // check if we have sufficient shader version here
170 glGetIntegerv(GL_NUM_SHADING_LANGUAGE_VERSIONS
, &svcount
);
172 foreach (GLuint n
; 0..svcount
) {
173 import core
.stdc
.string
: strncmp
;
174 auto v
= glGetStringi(GL_SHADING_LANGUAGE_VERSION
, n
);
175 if (v
is null) continue;
176 if (strncmp(v
, "130", 3) != 0) continue;
177 if (v
[3] > ' ') continue;
182 if (!found
) assert(0, "can't find OpenGL GLSL 120");
184 auto adr
= glGetProcAddress("glTexParameterf");
185 if (adr
is null) assert(0);
188 sdwindow
.vsync
= false;
189 sdwindow
.useGLFinish
= false;
191 if (!sdwindow
.releaseCurrentOpenGlContext()) { import core
.stdc
.stdio
; printf("can't release OpenGL context(1)\n"); }
193 convar("r_vsync", doVBL
);
194 concmd("exec config.rc");
195 concmd("exec autoexec.rc");
196 concmd("map '"~curmapname
~"'");
197 //convar("r_console", true);
200 enum { Left
, Right
, Up
, Down
}
201 bool[4] pressed
= false;
202 bool testLightLocked
= false;
203 bool justConsoled
= false;
205 sdwindow
.eventLoop(5000,
207 if (sdwindow
.closed
) return;
209 delegate (KeyEvent event
) {
210 if (sdwindow
.closed
) return;
211 if (event
.pressed
) justConsoled
= false;
212 if (!conVisible
&& inEditMode
) { postKeyEvent(event
); return; }
213 if (event
.pressed
&& event
.key
== Key
.Escape
) {
214 //if (convar!bool("r_console")) conwriteln("CONSOLE IS HERE"); else conwriteln("NO CONSOLE");
215 if (conVisible
) concmd("r_console toggle"); else concmd("quit");
220 case Key
.Left
: case Key
.Pad4
: plrKeyUpDown(0, PLK_LEFT
, event
.pressed
); break;
221 case Key
.Right
: case Key
.Pad6
: plrKeyUpDown(0, PLK_RIGHT
, event
.pressed
); break;
222 case Key
.Up
: case Key
.Pad8
: plrKeyUpDown(0, PLK_UP
, event
.pressed
); break;
223 case Key
.Down
: case Key
.Pad2
: plrKeyUpDown(0, PLK_DOWN
, event
.pressed
); break;
224 case Key
.Alt
: plrKeyUpDown(0, PLK_JUMP
, event
.pressed
); break;
225 case Key
.Ctrl
: plrKeyUpDown(0, PLK_FIRE
, event
.pressed
); break;
226 case Key
.Shift
: plrKeyUpDown(0, PLK_USE
, event
.pressed
); break;
227 case Key
.Grave
: if (event
.pressed
) { justConsoled
= !conVisible
; concmd("r_console toggle"); } break;
231 plrKeyUpDown(0, PLK_LEFT
, false);
232 plrKeyUpDown(0, PLK_RIGHT
, false);
233 plrKeyUpDown(0, PLK_UP
, false);
234 plrKeyUpDown(0, PLK_DOWN
, false);
235 plrKeyUpDown(0, PLK_JUMP
, false);
236 plrKeyUpDown(0, PLK_FIRE
, false);
237 plrKeyUpDown(0, PLK_USE
, false);
238 if (event
.pressed
&& event
.key
== Key
.Up
) postChar(ConInputChar
.Up
);
239 else if (event
.pressed
&& event
.key
== Key
.Down
) postChar(ConInputChar
.Down
);
240 else if (event
.pressed
&& event
.key
== Key
.PageUp
) postChar(ConInputChar
.PageUp
);
241 else if (event
.pressed
&& event
.key
== Key
.PageDown
) postChar(ConInputChar
.PageDown
);
242 else postKeyEvent(event
);
245 delegate (MouseEvent event
) {
246 if (inEditMode
) { postMouseEvent(event
); return; }
247 if (!testLightLocked
) postTestLightMove(event
.x
, event
.y
);
249 delegate (dchar ch
) {
251 if (justConsoled
&& ch
== '`') ch
= 0;
252 justConsoled
= false;
253 if (ch
&& ch
< 128) postChar(cast(char)ch
);
256 if (inEditMode
) return;
257 if (ch
== 'q') concmd("quit");
258 if (ch
== '1') concmd("r_scale 1");
259 if (ch
== '2') concmd("r_scale 2");
260 if (ch
== 'D') concmd("nodoorclip");
261 if (ch
== 'i') concmd("r_interpolation toggle; hudmsg \"Interpolation: $r_interpolation\"");
262 if (ch
== 'l') concmd("r_lighting toggle");
263 if (ch
== 'W') concmd("nowallclip");
264 if (ch
== 'L') testLightLocked
= !testLightLocked
;
265 if (ch
== 'p') concmd("g_pause toggle");
266 if (ch
== '!') concmd("skiplevel");
267 if (ch
== 'e') concmd("ed_toggle");
270 } catch (Exception e
) {
271 import std
.stdio
: stderr
;
272 stderr
.writeln("FUUUUUUUUUUUU\n", e
.toString
);