From 2e6a6a68a7ec3164519095c449172da1560f4654 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Tue, 29 Mar 2016 16:53:31 +0300 Subject: [PATCH] we can go to level 2 now! --- data/scripts/api/actor.dacs | 5 ++++ data/scripts/d2dswitches.dacs | 2 +- data/scripts/switch/exit.dacs | 28 +++++++++++++++++++++ dengapi.d | 35 ++++++++++++++++++++++++++ render.d | 58 +++++++++++++++++++++++++++++++++++-------- xmain_d2d.d | 6 ++++- 6 files changed, 122 insertions(+), 12 deletions(-) create mode 100644 data/scripts/switch/exit.dacs diff --git a/data/scripts/api/actor.dacs b/data/scripts/api/actor.dacs index 0bf7391..d8f38bc 100644 --- a/data/scripts/api/actor.dacs +++ b/data/scripts/api/actor.dacs @@ -257,3 +257,8 @@ public extern int getCheatNoLiftClip (); public extern void dotAddBlood (int x, int y, int xv, int yv, int n); public extern void dotAddSpark (int x, int y, int xv, int yv, int n); public extern void dotAddWater (int x, int y, int xv, int yv, int n, int color); + + +// ////////////////////////////////////////////////////////////////////////// // +// lnum <= 0: next level +public extern void gactLevelExit (int lnum); diff --git a/data/scripts/d2dswitches.dacs b/data/scripts/d2dswitches.dacs index 2b995f6..3da1765 100644 --- a/data/scripts/d2dswitches.dacs +++ b/data/scripts/d2dswitches.dacs @@ -1,6 +1,6 @@ module d2dswitches; -//import switchExit; // SW_EXIT +import switchExit; // SW_EXIT //import switchExitsecret; // SW_EXITS import switchDooropen; // SW_OPENDOOR //import switchDoorclose; // SW_SHUTDOOR diff --git a/data/scripts/switch/exit.dacs b/data/scripts/switch/exit.dacs new file mode 100644 index 0000000..e57fa5b --- /dev/null +++ b/data/scripts/switch/exit.dacs @@ -0,0 +1,28 @@ +module switchExit is "switch" "Exit"; + +import apiActor; +import apiMap; +import apiSwitch; +import stdlib; + + +// setup actor properties +public void initialize (Actor me) { +} + + +// thinker +public void think (Actor me) { + if (me.atm > 0) { + --me.atm; + return; + } + + me.atm = 0; // just in case + + auto toucher = me.switchWhoTouched(); + if (toucher && toucher.isPlayer) { + me.atm = 9; // cooldown time + gactLevelExit(me.switchGetD()); + } +} diff --git a/dengapi.d b/dengapi.d index aa91475..6b1f7c0 100644 --- a/dengapi.d +++ b/dengapi.d @@ -209,6 +209,33 @@ public __gshared LevelMap map; //public __gshared DACSVM dvm; public __gshared uint prngSyncSeed = 0x29a; public __gshared uint prngSeed = 0x29a; // unsynced +public __gshared string curmapname; +public __gshared string nextmapname; // nonempty: go to next level + + +// generate next map name for exit +public string genNextMapName (int lnum) { + import std.algorithm : endsWith; + import std.path; + string ext; + string nn = curmapname; + if (nn.endsWith(".d2m")) { + ext = ".d2m"; + nn = nn[0..$-4]; + } + if (nn[$-1] < '0' || nn[$-1] > '9') return null; + uint mapnum = 0, mmul = 1; + while (nn.length > 0 && nn[$-1] >= '0' && nn[$-1] <= '9') { + mapnum += (nn[$-1]-'0')*mmul; + mmul *= 10; + nn = nn[0..$-1]; + } + ++mapnum; + if (lnum > 0 && lnum < 100) mapnum = lnum; + if (mapnum > 99) return null; // alas + import std.string : format; + return "%s%02u%s".format(nn, mapnum, ext); +} // ////////////////////////////////////////////////////////////////////////// // @@ -443,6 +470,14 @@ void setupDAPI () { dotAddWater(x, y, xv, yv, n, color); }; */ + + FuncPool["gactLevelExit"] = function void (int lnum) { + if (nextmapname.length == 0) { + string nmname = genNextMapName(lnum); + if (nmname.length == 0) assert(0, "no level!"); + nextmapname = nmname; + } + }; } diff --git a/render.d b/render.d index 3e0846f..d9a5c3e 100644 --- a/render.d +++ b/render.d @@ -200,6 +200,7 @@ public void initOpenGL () { void loadMap (string mapname) { if (map !is null) map.clear(); map = new LevelMap(mapname); + curmapname = mapname; ugInit(map.width*8, map.height*8); @@ -228,7 +229,7 @@ void loadMap (string mapname) { dotInit(); // save first snapshot - prevFrameActorsData = new ubyte[](Actor.actorSize*65536); // ~15-20 megabytes + if (prevFrameActorsData.length == 0) prevFrameActorsData = new ubyte[](Actor.actorSize*65536); // ~15-20 megabytes prevFrameActorOfs[] = uint.max; // just for fun Actor.saveSnapshot(prevFrameActorsData[], prevFrameActorOfs.ptr); mapViewPosX[0] = mapViewPosX[1]; @@ -856,6 +857,28 @@ public void renderThread (Tid starterTid) { bool vframeWasLost = false; + void resetFrameTimers () { + MonoTime curtime = MonoTime.currTime; + lastthink = curtime; // for interpolator + nextthink = curtime+dur!"msecs"(D2DFrameTime); + nextvframe = curtime; + } + + void loadNewLevel (string name) { + /* + if (levelLoaded) { + conwriteln("ERROR: can't load new levels yet"); + return; + } + */ + if (name.length == 0) { + conwriteln("ERROR: can't load empty level!"); + } + conwriteln("loading map '", name, "'"); + loadMap(name); + resetFrameTimers(); + } + void receiveMessages () { for (;;) { import core.time : Duration; @@ -866,16 +889,15 @@ public void renderThread (Tid starterTid) { addMessage(msg.text[0..msg.textlen], msg.pauseMsecs, msg.noreplace); }, (TMsgLoadLevel msg) { - if (levelLoaded) { - conwriteln("ERROR: can't load new levels yet"); - return; - } - auto mn = msg.mapfile[0..msg.textlen].idup; - if (mn.length == 0) { - conwriteln("ERROR: can't load empty level!"); + nextmapname = null; // clear "exit" flag + loadNewLevel(msg.mapfile[0..msg.textlen].idup); + }, + (TMsgSkipLevel msg) { + string mn = genNextMapName(0); + if (mn.length) { + nextmapname = null; // clear "exit" flag + loadNewLevel(mn); } - conwriteln("loading map '", mn, "'"); - loadMap(mn); }, (TMsgIntOption msg) { final switch (msg.type) with (TMsgIntOption.Type) { @@ -950,6 +972,11 @@ public void renderThread (Tid starterTid) { break; } } + if (nextmapname.length) { + string mn = nextmapname; + nextmapname = null; // clear "exit" flag + loadNewLevel(mn); + } } // "D2D frames"; curtime should be set; return `true` if frame was processed; will fix `curtime` @@ -1180,6 +1207,17 @@ public void postLoadLevel (const(char)[] mapfile) { // ////////////////////////////////////////////////////////////////////////// // +struct TMsgSkipLevel { +} + +public void postSkipLevel () { + if (!atomicLoad(renderThreadStarted)) return; + TMsgSkipLevel msg; + send(renderTid, msg); +} + + +// ////////////////////////////////////////////////////////////////////////// // struct TMsgIntOption { enum Type { Scale, diff --git a/xmain_d2d.d b/xmain_d2d.d index 014ff63..14bd2a7 100644 --- a/xmain_d2d.d +++ b/xmain_d2d.d @@ -121,6 +121,9 @@ void main (string[] args) { setOpenGLContextVersion(3, 2); // up to GLSL 150 //openGLContextCompatible = false; + curmapname = "maps/map01.d2m"; + //conwriteln(genNextMapName()); + //map = new LevelMap("maps/map01.d2m"); //ugInit(map.width*8, map.height*8); @@ -212,7 +215,7 @@ void main (string[] args) { } */ startRenderThread(); - postLoadLevel("maps/map01.d2m"); + postLoadLevel(curmapname); //postAddMessage("WRYYYYYYYYYY"); //postAddMessage("wryyyyyyyyyy"); }; @@ -289,6 +292,7 @@ void main (string[] args) { if (ch == 'l') postToggleOption("lighting", showMessage:true); if (ch == 'W') postToggleOption("CheatNoWallClip", showMessage:true); if (ch == 'L') testLightLocked = !testLightLocked; + if (ch == '!') postSkipLevel(); //if (ch == ' ') movement = !movement; }, ); -- 2.11.4.GIT