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
;
50 // ////////////////////////////////////////////////////////////////////////// //
55 // ////////////////////////////////////////////////////////////////////////// //
56 void main (string
[] args
) {
57 FuncPool
.dumpCode
= false;
58 FuncPool
.dumpCodeSize
= false;
59 dacsDumpSemantic
= false;
61 //version(rdmd) { dacsOptimize = 0; }
62 bool compileOnly
= false;
65 for (usize idx
= 1; idx
< args
.length
; ++idx
) {
67 if (args
[idx
] == "--dump-code") FuncPool
.dumpCode
= true;
68 else if (args
[idx
] == "--dump-code-size") FuncPool
.dumpCodeSize
= true;
69 else if (args
[idx
] == "--dump-semantic") dacsDumpSemantic
= true;
70 else if (args
[idx
] == "--dump-all") { FuncPool
.dumpCode
= true; FuncPool
.dumpCodeSize
= true; dacsDumpSemantic
= true; }
71 else if (args
[idx
] == "--compile") compileOnly
= true;
72 else if (args
[idx
] == "--compile-only") compileOnly
= true;
73 else if (args
[idx
] == "--messages") ++dacsMessages
;
74 else if (args
[idx
] == "--no-copro") dacsOptimizeNoCoPro
= true;
75 else if (args
[idx
] == "--no-deadass") dacsOptimizeNoDeadAss
= true;
76 else if (args
[idx
] == "--no-purekill") dacsOptimizeNoPureKill
= true;
77 else if (args
[idx
] == "--no-vsync") doVBL
= false;
78 else if (args
[idx
] == "--vsync") doVBL
= true;
79 else if (args
[idx
].length
> 2 && args
[idx
][0..2] == "-O") {
81 ubyte olevel
= to
!ubyte(args
[idx
][2..$]);
82 dacsOptimize
= olevel
;
86 foreach (immutable c
; idx
+1..args
.length
) args
.ptr
[c
-1] = args
.ptr
[c
];
91 if (processCL(args
)) return;
93 addInternalActorFields();
95 static void setDP () {
99 import std
.file
: thisExePath
;
100 import std
.path
: dirName
;
101 setDataPath(thisExePath
.dirName
);
103 addPak(getDataPath
~"base.pk3"); registerWadScripts();
104 //addWad("/home/ketmar/k8prj/doom2d-tl/data/doom2d.wad"); registerWadScripts();
105 //addWad("/home/ketmar/k8prj/doom2d-tl/data/meat.wad"); registerWadScripts();
106 //addWad("/home/ketmar/k8prj/doom2d-tl/data/megadm.wad"); registerWadScripts();
107 //addWad("/home/ketmar/k8prj/doom2d-tl/data/megadm1.wad"); registerWadScripts();
108 //addWad("/home/ketmar/k8prj/doom2d-tl/data/superdm.wad"); registerWadScripts();
109 //addWad("/home/ketmar/k8prj/doom2d-tl/data/zadoomka.wad"); registerWadScripts();
115 if (compileOnly
) return;
121 setOpenGLContextVersion(3, 2); // up to GLSL 150
122 //openGLContextCompatible = false;
124 curmapname
= "maps/map01.d2m";
125 //conwriteln(genNextMapName());
127 //map = new LevelMap("maps/map01.d2m");
128 //ugInit(map.width*TileSize, map.height*TileSize);
133 //mapOfsX = TileSize*26;
134 //mapOfsY = TileSize*56;
135 map.getThingPos(1/*ThingId.Player1*/, &mapOfsX, &mapOfsY);
138 mapOfsX = (mapOfsX*2)-vlWidth/2;
139 if (mapOfsX+vlWidth > map.width*16) mapOfsX = map.width*16-vlWidth;
140 if (mapOfsX < 0) mapOfsX = 0;
141 mapOfsY = (mapOfsY*2)-vlHeight/2;
142 if (mapOfsY+vlHeight > map.height*16) mapOfsY = map.height*16-vlHeight;
143 if (mapOfsY < 0) mapOfsY = 0;
145 setMapViewPos(mapOfsX, mapOfsY);
146 mapOfsX = mapViewPosX[1];
147 mapOfsY = mapViewPosY[1];
150 sdwindow
= new SimpleWindow(vlWidth
, vlHeight
, "D2D", OpenGlOptions
.yes
, Resizablity
.fixedSize
);
151 //sdwindow.hideCursor();
153 sdwindow
.closeQuery
= delegate () { concmd("quit"); };
155 sdwindow
.visibleForTheFirstTime
= delegate () {
156 sdwindow
.setAsCurrentOpenGlContext(); // make this window active
157 glbindLoadFunctions();
160 import core.stdc.stdio;
161 printf("GL version: %s\n", glGetString(GL_VERSION));
163 glGetIntegerv(GL_MAJOR_VERSION, &h);
164 glGetIntegerv(GL_MINOR_VERSION, &l);
165 printf("version: %d.%d\n", h, l);
166 printf("shader version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
168 glGetIntegerv(GL_NUM_SHADING_LANGUAGE_VERSIONS, &svcount);
170 printf("%d shader versions supported:\n", svcount);
171 foreach (GLuint n; 0..svcount) printf(" %d: %s\n", n, glGetStringi(GL_SHADING_LANGUAGE_VERSION, n));
175 glGetIntegerv(GL_NUM_EXTENSIONS, &ecount);
177 printf("%d extensions supported:\n", ecount);
178 foreach (GLuint n; 0..ecount) printf(" %d: %s\n", n, glGetStringi(GL_EXTENSIONS, n));
183 // check if we have sufficient shader version here
187 glGetIntegerv(GL_NUM_SHADING_LANGUAGE_VERSIONS
, &svcount
);
189 foreach (GLuint n
; 0..svcount
) {
190 import core
.stdc
.string
: strncmp
;
191 auto v
= glGetStringi(GL_SHADING_LANGUAGE_VERSION
, n
);
192 if (v
is null) continue;
193 if (strncmp(v
, "120", 3) != 0) continue;
194 if (v
[3] > ' ') continue;
199 if (!found
) assert(0, "can't find OpenGL GLSL 120");
201 auto adr
= glGetProcAddress("glTexParameterf");
202 if (adr
is null) assert(0);
205 version(dont_use_vsync
) {
206 sdwindow
.vsync
= false;
208 sdwindow
.vsync
= true;
210 //sdwindow.useGLFinish = false;
212 //sdwindow.redrawOpenGlScene();
213 if (!sdwindow
.releaseCurrentOpenGlContext()) { import core
.stdc
.stdio
; printf("can't release OpenGL context(1)\n"); }
216 renderTid = new Thread(&renderThread);
221 //postLoadLevel(curmapname);
222 concmd("map '"~curmapname
~"'");
223 //postAddMessage("WRYYYYYYYYYY");
224 //postAddMessage("wryyyyyyyyyy");
227 //sdwindow.redrawOpenGlScene = delegate () { renderScene(); };
229 enum MSecsPerFrame
= 1000/30; /* 30 is FPS */
231 enum { Left
, Right
, Up
, Down
}
232 bool[4] pressed
= false;
233 bool testLightLocked
= false;
235 sdwindow
.eventLoop(MSecsPerFrame
,
237 if (sdwindow
.closed
) return;
238 if (quitRequested
) { closeWindow(); return; }
240 if (pressed[Left]) mapOfsX -= TileSize;
241 if (pressed[Right]) mapOfsX += TileSize;
242 if (pressed[Up]) mapOfsY -= TileSize;
243 if (pressed[Down]) mapOfsY += TileSize;
244 import std.math : cos, sin;
245 __gshared float itime = 0.0;
248 mapOfsX = cast(int)(800.0/2.0+cos(itime)*220.0);
249 mapOfsY = cast(int)(800.0/2.0+120.0+sin(itime)*160.0);
251 if (scale == 1) mapOfsX = mapOfsY = 0;
253 //sdwindow.redrawOpenGlSceneNow();
255 delegate (KeyEvent event
) {
256 if (sdwindow
.closed
) return;
257 if (inEditMode
) { postKeyEvent(event
); return; }
258 if (event
.pressed
&& event
.key
== Key
.Escape
) {
259 if (conVisible
) concmd("r_console toggle"); else concmd("quit");
264 case Key.X: if (event.pressed) altMove = !altMove; break;
265 case Key.Left: if (altMove) pressed[Left] = event.pressed; break;
266 case Key.Right: if (altMove) pressed[Right] = event.pressed; break;
267 case Key.Up: if (altMove) pressed[Up] = event.pressed; break;
268 case Key.Down: if (altMove) pressed[Down] = event.pressed; break;
272 if (true/*!altMove*/) {
274 case Key
.Left
: case Key
.Pad4
: plrKeyUpDown(0, PLK_LEFT
, event
.pressed
); break;
275 case Key
.Right
: case Key
.Pad6
: plrKeyUpDown(0, PLK_RIGHT
, event
.pressed
); break;
276 case Key
.Up
: case Key
.Pad8
: plrKeyUpDown(0, PLK_UP
, event
.pressed
); break;
277 case Key
.Down
: case Key
.Pad2
: plrKeyUpDown(0, PLK_DOWN
, event
.pressed
); break;
278 case Key
.Alt
: plrKeyUpDown(0, PLK_JUMP
, event
.pressed
); break;
279 case Key
.Ctrl
: plrKeyUpDown(0, PLK_FIRE
, event
.pressed
); break;
280 case Key
.Shift
: plrKeyUpDown(0, PLK_USE
, event
.pressed
); break;
281 case Key
.Grave
: if (event
.pressed
&& !conVisible
) concmd("r_console toggle"); break;
286 delegate (MouseEvent event
) {
287 if (inEditMode
) { postMouseEvent(event
); return; }
289 testLightX = event.x/*/scale*/;
290 testLightY = event.y/*/scale*/;
291 //testLightX += mapOfsX/scale;
292 //testLightY += mapOfsY/scale;
294 if (!testLightLocked
) postTestLightMove(event
.x
, event
.y
);
296 delegate (dchar ch
) {
297 //if (ch == '`') { concmd("r_console toggle"); return; }
299 //{ import core.stdc.stdio; printf("%u\n", cast(uint)ch); }
300 if (ch
< 128) postChar(cast(char)ch
);
303 if (inEditMode
) return;
304 if (ch
== 'q') concmd("quit"); //{ closeWindow(); return; }
305 //if (ch == 's') scanlines = !scanlines;
306 if (ch
== '1') concmd("r_scale 1");
307 if (ch
== '2') concmd("r_scale 2");
308 if (ch
== 'D') concmd("nodoorclip");
309 if (ch
== 'i') concmd("r_interpolation toggle; hudmsg \"Interpolation: $r_interpolation\"");
310 if (ch
== 'l') concmd("r_lighting toggle");
311 if (ch
== 'W') concmd("nowallclip");
312 if (ch
== 'L') testLightLocked
= !testLightLocked
;
313 if (ch
== 'p') concmd("g_pause toggle");
314 if (ch
== '!') concmd("skiplevel");
315 if (ch
== 'e') concmd("ed_toggle");
316 //if (ch == ' ') movement = !movement;
319 } catch (Exception e
) {
320 import std
.stdio
: stderr
;
321 stderr
.writeln("FUUUUUUUUUUUU\n", e
.toString
);