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
];
93 addInternalActorFields();
95 static void setDP () {
99 import std
.file
: thisExePath
;
100 import std
.path
: dirName
;
101 setDataPath(thisExePath
.dirName
);
103 addPK3(getDataPath
~"base.pk3"); loadWadScripts();
104 //addWad("/home/ketmar/k8prj/doom2d-tl/data/doom2d.wad"); loadWadScripts();
105 //addWad("/home/ketmar/k8prj/doom2d-tl/data/meat.wad"); loadWadScripts();
106 //addWad("/home/ketmar/k8prj/doom2d-tl/data/megadm.wad"); loadWadScripts();
107 //addWad("/home/ketmar/k8prj/doom2d-tl/data/megadm1.wad"); loadWadScripts();
108 //addWad("/home/ketmar/k8prj/doom2d-tl/data/superdm.wad"); loadWadScripts();
109 //addWad("/home/ketmar/k8prj/doom2d-tl/data/zadoomka.wad"); loadWadScripts();
110 scriptLoadingComplete();
115 if (compileOnly
) return;
121 setOpenGLContextVersion(3, 2); // up to GLSL 150
122 //openGLContextCompatible = false;
124 //map = new LevelMap("maps/map01.d2m");
125 //ugInit(map.width*8, map.height*8);
132 map.getThingPos(1/*ThingId.Player1*/, &mapOfsX, &mapOfsY);
135 mapOfsX = (mapOfsX*2)-vlWidth/2;
136 if (mapOfsX+vlWidth > map.width*16) mapOfsX = map.width*16-vlWidth;
137 if (mapOfsX < 0) mapOfsX = 0;
138 mapOfsY = (mapOfsY*2)-vlHeight/2;
139 if (mapOfsY+vlHeight > map.height*16) mapOfsY = map.height*16-vlHeight;
140 if (mapOfsY < 0) mapOfsY = 0;
142 setMapViewPos(mapOfsX, mapOfsY);
143 mapOfsX = mapViewPosX[1];
144 mapOfsY = mapViewPosY[1];
147 sdwindow
= new SimpleWindow(vlWidth
, vlHeight
, "D2D", OpenGlOptions
.yes
, Resizablity
.fixedSize
);
149 sdwindow
.visibleForTheFirstTime
= delegate () {
150 sdwindow
.setAsCurrentOpenGlContext(); // make this window active
151 glbindLoadFunctions();
154 import core.stdc.stdio;
155 printf("GL version: %s\n", glGetString(GL_VERSION));
157 glGetIntegerv(GL_MAJOR_VERSION, &h);
158 glGetIntegerv(GL_MINOR_VERSION, &l);
159 printf("version: %d.%d\n", h, l);
160 printf("shader version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
162 glGetIntegerv(GL_NUM_SHADING_LANGUAGE_VERSIONS, &svcount);
164 printf("%d shader versions supported:\n", svcount);
165 foreach (GLuint n; 0..svcount) printf(" %d: %s\n", n, glGetStringi(GL_SHADING_LANGUAGE_VERSION, n));
169 glGetIntegerv(GL_NUM_EXTENSIONS, &ecount);
171 printf("%d extensions supported:\n", ecount);
172 foreach (GLuint n; 0..ecount) printf(" %d: %s\n", n, glGetStringi(GL_EXTENSIONS, n));
177 // check if we have sufficient shader version here
181 glGetIntegerv(GL_NUM_SHADING_LANGUAGE_VERSIONS
, &svcount
);
183 foreach (GLuint n
; 0..svcount
) {
184 import core
.stdc
.string
: strncmp
;
185 auto v
= glGetStringi(GL_SHADING_LANGUAGE_VERSION
, n
);
186 if (v
is null) continue;
187 if (strncmp(v
, "120", 3) != 0) continue;
188 if (v
[3] > ' ') continue;
193 if (!found
) assert(0, "can't find OpenGL GLSL 120");
195 auto adr
= glGetProcAddress("glTexParameterf");
196 if (adr
is null) assert(0);
199 version(dont_use_vsync
) {
200 sdwindow
.vsync
= false;
202 sdwindow
.vsync
= true;
204 //sdwindow.useGLFinish = false;
206 //sdwindow.redrawOpenGlScene();
207 if (!sdwindow
.releaseCurrentOpenGlContext()) { import core
.stdc
.stdio
; printf("can't release OpenGL context(1)\n"); }
210 renderTid = new Thread(&renderThread);
215 postLoadLevel("maps/map01.d2m");
218 //sdwindow.redrawOpenGlScene = delegate () { renderScene(); };
220 enum MSecsPerFrame
= 1000/30; /* 30 is FPS */
222 enum { Left
, Right
, Up
, Down
}
223 bool[4] pressed
= false;
224 bool testLightLocked
= false;
226 sdwindow
.eventLoop(MSecsPerFrame
,
228 if (sdwindow
.closed
) return;
230 if (pressed[Left]) mapOfsX -= 8;
231 if (pressed[Right]) mapOfsX += 8;
232 if (pressed[Up]) mapOfsY -= 8;
233 if (pressed[Down]) mapOfsY += 8;
234 import std.math : cos, sin;
235 __gshared float itime = 0.0;
238 mapOfsX = cast(int)(800.0/2.0+cos(itime)*220.0);
239 mapOfsY = cast(int)(800.0/2.0+120.0+sin(itime)*160.0);
241 if (scale == 1) mapOfsX = mapOfsY = 0;
243 //sdwindow.redrawOpenGlSceneNow();
245 delegate (KeyEvent event
) {
246 if (sdwindow
.closed
) return;
247 if (event
.pressed
&& event
.key
== Key
.Escape
) { closeWindow(); return; }
250 case Key.X: if (event.pressed) altMove = !altMove; break;
251 case Key.Left: if (altMove) pressed[Left] = event.pressed; break;
252 case Key.Right: if (altMove) pressed[Right] = event.pressed; break;
253 case Key.Up: if (altMove) pressed[Up] = event.pressed; break;
254 case Key.Down: if (altMove) pressed[Down] = event.pressed; break;
258 if (true/*!altMove*/) {
260 case Key
.Left
: case Key
.Pad4
: plrKeyUpDown(0, PLK_LEFT
, event
.pressed
); break;
261 case Key
.Right
: case Key
.Pad6
: plrKeyUpDown(0, PLK_RIGHT
, event
.pressed
); break;
262 case Key
.Up
: case Key
.Pad8
: plrKeyUpDown(0, PLK_UP
, event
.pressed
); break;
263 case Key
.Down
: case Key
.Pad2
: plrKeyUpDown(0, PLK_DOWN
, event
.pressed
); break;
264 case Key
.Alt
: plrKeyUpDown(0, PLK_JUMP
, event
.pressed
); break;
265 case Key
.Ctrl
: plrKeyUpDown(0, PLK_FIRE
, event
.pressed
); break;
266 case Key
.Shift
: plrKeyUpDown(0, PLK_USE
, event
.pressed
); break;
271 delegate (MouseEvent event
) {
273 testLightX = event.x/*/scale*/;
274 testLightY = event.y/*/scale*/;
275 //testLightX += mapOfsX/scale;
276 //testLightY += mapOfsY/scale;
278 if (!testLightLocked
) postTestLightMove(event
.x
, event
.y
);
280 delegate (dchar ch
) {
281 if (ch
== 'q') { closeWindow(); return; }
282 //if (ch == 's') scanlines = !scanlines;
283 if (ch
== '1') postSetOption("scale", 1);
284 if (ch
== '2') postSetOption("scale", 2);
285 if (ch
== 'D') postSetOption("cheatNoDoors", true, showMessage
:true, toggle
:true);
286 if (ch
== 'i') postSetOption("interpolation", true, showMessage
:true, toggle
:true);
287 if (ch
== 'l') postSetOption("lighting", true, showMessage
:true, toggle
:true);
288 if (ch
== 'L') testLightLocked
= !testLightLocked
;
289 //if (ch == ' ') movement = !movement;
292 } catch (Exception e
) {
293 import std
.stdio
: stderr
;
294 stderr
.writeln("FUUUUUUUUUUUU\n", e
.toString
);