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
;
51 // ////////////////////////////////////////////////////////////////////////// //
56 // ////////////////////////////////////////////////////////////////////////// //
57 void main (string
[] args
) {
58 FuncPool
.dumpCode
= false;
59 FuncPool
.dumpCodeSize
= false;
60 dacsDumpSemantic
= false;
62 //version(rdmd) { dacsOptimize = 0; }
63 bool compileOnly
= false;
66 for (usize idx
= 1; idx
< args
.length
; ++idx
) {
68 if (args
[idx
] == "--dump-code") FuncPool
.dumpCode
= true;
69 else if (args
[idx
] == "--dump-code-size") FuncPool
.dumpCodeSize
= true;
70 else if (args
[idx
] == "--dump-semantic") dacsDumpSemantic
= true;
71 else if (args
[idx
] == "--dump-all") { FuncPool
.dumpCode
= true; FuncPool
.dumpCodeSize
= true; dacsDumpSemantic
= true; }
72 else if (args
[idx
] == "--compile") compileOnly
= true;
73 else if (args
[idx
] == "--compile-only") compileOnly
= true;
74 else if (args
[idx
] == "--messages") ++dacsMessages
;
75 else if (args
[idx
] == "--no-copro") dacsOptimizeNoCoPro
= true;
76 else if (args
[idx
] == "--no-deadass") dacsOptimizeNoDeadAss
= true;
77 else if (args
[idx
] == "--no-purekill") dacsOptimizeNoPureKill
= true;
78 else if (args
[idx
] == "--no-vsync") doVBL
= false;
79 else if (args
[idx
] == "--vsync") doVBL
= true;
80 else if (args
[idx
].length
> 2 && args
[idx
][0..2] == "-O") {
82 ubyte olevel
= to
!ubyte(args
[idx
][2..$]);
83 dacsOptimize
= olevel
;
87 foreach (immutable c
; idx
+1..args
.length
) args
.ptr
[c
-1] = args
.ptr
[c
];
92 if (processCL(args
)) return;
94 addInternalActorFields();
96 static void setDP () {
100 import std
.file
: thisExePath
;
101 import std
.path
: dirName
;
102 setDataPath(thisExePath
.dirName
);
104 addPak(getDataPath
~"base.pk3"); registerWadScripts();
105 //addWad("/home/ketmar/k8prj/doom2d-tl/data/doom2d.wad"); registerWadScripts();
106 //addWad("/home/ketmar/k8prj/doom2d-tl/data/meat.wad"); registerWadScripts();
107 //addWad("/home/ketmar/k8prj/doom2d-tl/data/megadm.wad"); registerWadScripts();
108 //addWad("/home/ketmar/k8prj/doom2d-tl/data/megadm1.wad"); registerWadScripts();
109 //addWad("/home/ketmar/k8prj/doom2d-tl/data/superdm.wad"); registerWadScripts();
110 //addWad("/home/ketmar/k8prj/doom2d-tl/data/zadoomka.wad"); registerWadScripts();
116 if (compileOnly
) return;
122 setOpenGLContextVersion(3, 2); // up to GLSL 150
123 //openGLContextCompatible = false;
125 curmapname
= "maps/map01.d2m";
126 //conwriteln(genNextMapName());
128 //map = new LevelMap("maps/map01.d2m");
129 //ugInit(map.width*TileSize, map.height*TileSize);
134 //mapOfsX = TileSize*26;
135 //mapOfsY = TileSize*56;
136 map.getThingPos(1/*ThingId.Player1*/, &mapOfsX, &mapOfsY);
139 mapOfsX = (mapOfsX*2)-vlWidth/2;
140 if (mapOfsX+vlWidth > map.width*16) mapOfsX = map.width*16-vlWidth;
141 if (mapOfsX < 0) mapOfsX = 0;
142 mapOfsY = (mapOfsY*2)-vlHeight/2;
143 if (mapOfsY+vlHeight > map.height*16) mapOfsY = map.height*16-vlHeight;
144 if (mapOfsY < 0) mapOfsY = 0;
146 setMapViewPos(mapOfsX, mapOfsY);
147 mapOfsX = mapViewPosX[1];
148 mapOfsY = mapViewPosY[1];
151 sdwindow
= new SimpleWindow(vlWidth
, vlHeight
, "D2D", OpenGlOptions
.yes
, Resizablity
.fixedSize
);
153 sdwindow
.visibleForTheFirstTime
= delegate () {
154 sdwindow
.setAsCurrentOpenGlContext(); // make this window active
155 glbindLoadFunctions();
158 import core.stdc.stdio;
159 printf("GL version: %s\n", glGetString(GL_VERSION));
161 glGetIntegerv(GL_MAJOR_VERSION, &h);
162 glGetIntegerv(GL_MINOR_VERSION, &l);
163 printf("version: %d.%d\n", h, l);
164 printf("shader version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
166 glGetIntegerv(GL_NUM_SHADING_LANGUAGE_VERSIONS, &svcount);
168 printf("%d shader versions supported:\n", svcount);
169 foreach (GLuint n; 0..svcount) printf(" %d: %s\n", n, glGetStringi(GL_SHADING_LANGUAGE_VERSION, n));
173 glGetIntegerv(GL_NUM_EXTENSIONS, &ecount);
175 printf("%d extensions supported:\n", ecount);
176 foreach (GLuint n; 0..ecount) printf(" %d: %s\n", n, glGetStringi(GL_EXTENSIONS, n));
181 // check if we have sufficient shader version here
185 glGetIntegerv(GL_NUM_SHADING_LANGUAGE_VERSIONS
, &svcount
);
187 foreach (GLuint n
; 0..svcount
) {
188 import core
.stdc
.string
: strncmp
;
189 auto v
= glGetStringi(GL_SHADING_LANGUAGE_VERSION
, n
);
190 if (v
is null) continue;
191 if (strncmp(v
, "120", 3) != 0) continue;
192 if (v
[3] > ' ') continue;
197 if (!found
) assert(0, "can't find OpenGL GLSL 120");
199 auto adr
= glGetProcAddress("glTexParameterf");
200 if (adr
is null) assert(0);
203 version(dont_use_vsync
) {
204 sdwindow
.vsync
= false;
206 sdwindow
.vsync
= true;
208 //sdwindow.useGLFinish = false;
210 //sdwindow.redrawOpenGlScene();
211 if (!sdwindow
.releaseCurrentOpenGlContext()) { import core
.stdc
.stdio
; printf("can't release OpenGL context(1)\n"); }
214 renderTid = new Thread(&renderThread);
219 postLoadLevel(curmapname
);
220 //postAddMessage("WRYYYYYYYYYY");
221 //postAddMessage("wryyyyyyyyyy");
224 //sdwindow.redrawOpenGlScene = delegate () { renderScene(); };
226 enum MSecsPerFrame
= 1000/30; /* 30 is FPS */
228 enum { Left
, Right
, Up
, Down
}
229 bool[4] pressed
= false;
230 bool testLightLocked
= false;
232 sdwindow
.eventLoop(MSecsPerFrame
,
234 if (sdwindow
.closed
) return;
236 if (pressed[Left]) mapOfsX -= TileSize;
237 if (pressed[Right]) mapOfsX += TileSize;
238 if (pressed[Up]) mapOfsY -= TileSize;
239 if (pressed[Down]) mapOfsY += TileSize;
240 import std.math : cos, sin;
241 __gshared float itime = 0.0;
244 mapOfsX = cast(int)(800.0/2.0+cos(itime)*220.0);
245 mapOfsY = cast(int)(800.0/2.0+120.0+sin(itime)*160.0);
247 if (scale == 1) mapOfsX = mapOfsY = 0;
249 //sdwindow.redrawOpenGlSceneNow();
251 delegate (KeyEvent event
) {
252 if (sdwindow
.closed
) return;
253 if (event
.pressed
&& event
.key
== Key
.Escape
) { closeWindow(); return; }
256 case Key.X: if (event.pressed) altMove = !altMove; break;
257 case Key.Left: if (altMove) pressed[Left] = event.pressed; break;
258 case Key.Right: if (altMove) pressed[Right] = event.pressed; break;
259 case Key.Up: if (altMove) pressed[Up] = event.pressed; break;
260 case Key.Down: if (altMove) pressed[Down] = event.pressed; break;
264 if (true/*!altMove*/) {
266 case Key
.Left
: case Key
.Pad4
: plrKeyUpDown(0, PLK_LEFT
, event
.pressed
); break;
267 case Key
.Right
: case Key
.Pad6
: plrKeyUpDown(0, PLK_RIGHT
, event
.pressed
); break;
268 case Key
.Up
: case Key
.Pad8
: plrKeyUpDown(0, PLK_UP
, event
.pressed
); break;
269 case Key
.Down
: case Key
.Pad2
: plrKeyUpDown(0, PLK_DOWN
, event
.pressed
); break;
270 case Key
.Alt
: plrKeyUpDown(0, PLK_JUMP
, event
.pressed
); break;
271 case Key
.Ctrl
: plrKeyUpDown(0, PLK_FIRE
, event
.pressed
); break;
272 case Key
.Shift
: plrKeyUpDown(0, PLK_USE
, event
.pressed
); break;
277 delegate (MouseEvent event
) {
279 testLightX = event.x/*/scale*/;
280 testLightY = event.y/*/scale*/;
281 //testLightX += mapOfsX/scale;
282 //testLightY += mapOfsY/scale;
284 if (!testLightLocked
) postTestLightMove(event
.x
, event
.y
);
286 delegate (dchar ch
) {
287 if (ch
== 'q') { closeWindow(); return; }
288 //if (ch == 's') scanlines = !scanlines;
289 if (ch
== '1') postSetOption("scale", 1);
290 if (ch
== '2') postSetOption("scale", 2);
291 if (ch
== 'D') postToggleOption("cheatNoDoors", showMessage
:true);
292 if (ch
== 'i') postToggleOption("interpolation", showMessage
:true);
293 if (ch
== 'l') postToggleOption("lighting", showMessage
:false);
294 if (ch
== 'W') postToggleOption("CheatNoWallClip", showMessage
:true);
295 if (ch
== 'L') testLightLocked
= !testLightLocked
;
296 if (ch
== 'p') postToggleOption("pause", showMessage
:false);
297 if (ch
== '!') postSkipLevel();
298 //if (ch == ' ') movement = !movement;
301 } catch (Exception e
) {
302 import std
.stdio
: stderr
;
303 stderr
.writeln("FUUUUUUUUUUUU\n", e
.toString
);