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 dengapi
is aliced
;
39 // ////////////////////////////////////////////////////////////////////////// //
40 private extern (C
) void _d_print_throwable (Throwable t
);
43 // ////////////////////////////////////////////////////////////////////////// //
48 // ////////////////////////////////////////////////////////////////////////// //
49 public void addInternalActorFields () {
50 // &0xffff: position in drawlist
51 // (>>16)&0xff: drawlist index
52 //Actor.addField("0drawlistpos", Actor.Field.Type.Uint);
56 // ////////////////////////////////////////////////////////////////////////// //
59 enum PLK_DOWN
= (1<<1);
60 enum PLK_LEFT
= (1<<2);
61 enum PLK_RIGHT
= (1<<3);
62 enum PLK_FIRE
= (1<<4);
63 enum PLK_JUMP
= (1<<5);
64 enum PLK_USE
= (1<<6);
67 __gshared
uint plrKeysLast
;
68 __gshared
uint plrKeyState
;
71 public void plrKeyDown (uint plidx
, uint mask
) {
72 if (mask
== 0 || plidx
> 0) return;
78 public void plrKeyUp (uint plidx
, uint mask
) {
79 if (mask
== 0 || plidx
> 0) return;
84 public void plrKeyUpDown (uint plidx
, uint mask
, bool down
) {
85 if (down
) plrKeyDown(plidx
, mask
); else plrKeyUp(plidx
, mask
);
89 void plrKeysFix (uint plidx
) {
90 if (plidx
> 0) return;
91 //conwritefln!"plrKeyState=0x%02x; plrKeysLast=0x%02x"(plrKeyState, plrKeysLast);
92 foreach (uint n
; 0..12) {
93 if ((plrKeyState
&(1<<n
)) == 0) plrKeysLast
&= ~(1<<n
);
98 // ////////////////////////////////////////////////////////////////////////// //
99 void updateActorClasses (int iteration
) {
100 foreach (string ctype
; dacsClassTypes(iteration
)) {
101 foreach (auto mod
; dacsClassModules(ctype
, iteration
)) {
102 auto adef
= registerActorDef(mod
.rmoduletype
.classtype
, mod
.rmoduletype
.classname
);
103 conwriteln("found info for actor '", mod
.rmoduletype
.classtype
, ":", mod
.rmoduletype
.classname
, "'");
105 auto animInitFn
= FuncPool
.findByFQMG(mod
.name
~".initializeAnim", ":void");
106 if (animInitFn
!is null) adef
.setAnimInitFunc(animInitFn
);
109 auto initFn
= FuncPool
.findByFQMG(mod
.name
~".initialize", ":void:Actor");
110 if (initFn
!is null) adef
.setInitFunc(initFn
);
113 auto thinkFn
= FuncPool
.findByFQMG(mod
.name
~".think", ":void:Actor");
114 if (thinkFn
!is null) adef
.setThinkFunc(thinkFn
);
121 // ////////////////////////////////////////////////////////////////////////// //
122 private string
modLoader (string modname
) {
123 static string
getTextFile (string fname
) {
125 auto res
= loadTextFile(fname
);
126 conwriteln("loading DACS module file '", fname
, "' (", res
.length
, " bytes)");
127 if (res
is null) res
= "";
129 } catch (Exception
) {}
135 //res = getTextFile(modname~".dacs");
136 //if (res !is null) return res;
138 res
= getTextFile("scripts/"~modname
~".dacs");
139 if (res
!is null) return res
;
142 string
[] parts
= ["scripts"];
144 while (mn
.length
> 0) {
146 if (mn
[0] >= 'A' && mn
[0] <= 'Z') ++pos
;
147 while (pos
< mn
.length
&& (mn
[pos
] < 'A' || mn
[pos
] > 'Z')) ++pos
;
148 if (mn
[0] >= 'A' && mn
[0] <= 'Z') {
149 parts
~= cast(char)(mn
[0]+32)~mn
[1..pos
];
156 import std
.array
: join
;
157 string path
= parts
.join("/")~".dacs";
158 res
= getTextFile(path
);
159 if (res
!is null) return res
;
163 throw new Exception("module '"~modname
~"' not found");
167 __gshared
int modIteration
= 0;
169 public void loadWadScripts () {
170 if (moduleLoader
is null) moduleLoader
= (string modname
) => modLoader(modname
);
173 import std
.array
: split
;
174 auto t
= loadTextFile("scripts/dacsmain.txt");
175 foreach (string line
; t
.split('\n')) {
176 while (line
.length
&& line
[0] <= ' ') line
= line
[1..$];
177 if (line
.length
== 0 || line
[0] == ';') continue;
178 while (line
.length
&& line
[$-1] <= ' ') line
= line
[0..$-1];
181 } catch (Exception e
) { return; }
183 //conwriteln("loading main DACS module '", mainmod, "'");
184 auto iter
= modIteration
++;
185 conwriteln("iteration=", iter
);
186 foreach (string mod
; mainmods
) {
187 parseModule(mod
, iter
);
189 conwriteln("calling parseComplete; iteration=", iter
);
191 updateActorClasses(iter
);
192 } catch (CompilerException e
) {
193 _d_print_throwable(e
);
194 conwriteln("PARSE ERROR: ", e
.file
, " at ", e
.line
);
195 conwriteln(e
.toString
);
201 public void scriptLoadingComplete () {
203 dacsFinalizeCompiler();
207 // ////////////////////////////////////////////////////////////////////////// //
208 public __gshared LevelMap map
;
209 //public __gshared DACSVM dvm;
210 public __gshared
uint prngSyncSeed
= 0x29a;
211 public __gshared
uint prngSeed
= 0x29a; // unsynced
212 public __gshared string curmapname
;
213 public __gshared string nextmapname
; // nonempty: go to next level
216 // generate next map name for exit
217 public string
genNextMapName (int lnum
) {
218 import std
.algorithm
: endsWith
;
221 string nn
= curmapname
;
222 if (nn
.endsWith(".d2m")) {
226 if (nn
[$-1] < '0' || nn
[$-1] > '9') return null;
227 uint mapnum
= 0, mmul
= 1;
228 while (nn
.length
> 0 && nn
[$-1] >= '0' && nn
[$-1] <= '9') {
229 mapnum
+= (nn
[$-1]-'0')*mmul
;
234 if (lnum
> 0 && lnum
< 100) mapnum
= lnum
;
235 if (mapnum
> 99) return null; // alas
236 import std
.string
: format
;
237 return "%s%02u%s".format(nn
, mapnum
, ext
);
241 // ////////////////////////////////////////////////////////////////////////// //
242 // Park-Miller-Carta Pseudo-Random Number Generator, based on David G. Carta paper
243 // 31 bit of randomness
244 // seed is previous result, as usual
245 public uint prngR31next (uint seed
) {
246 if (seed
== 0) seed
= 0x29a;
247 uint lo
= 16807*(seed
&0xffff);
248 uint hi
= 16807*(seed
>>16);
249 lo
+= (hi
&0x7fff)<<16;
251 //if (lo > 0x7fffffff) lo -= 0x7fffffff; // should be >=, actually
252 lo
= (lo
&0x7FFFFFFF)+(lo
>>31); // same as previous code, but branch-less
257 // "synced" random, using common seed for all players
258 public uint syncrandu31 () {
259 pragma(inline
, true);
260 return (prngSyncSeed
= prngR31next(prngSyncSeed
));
264 // "unsynced" random, seed isn't saved
265 public uint unsyncrandu31 () {
266 pragma(inline
, true);
267 return (prngSeed
= prngR31next(prngSeed
));
271 // ////////////////////////////////////////////////////////////////////////// //
272 version(dacs_use_vm
) {
273 // this is VAT function, argument order is reversed
274 void doWrite(bool donl
) (FuncPool
.FuncInfo fi
, DACSVM vm
) {
276 auto count
= vm
.popInt();
277 while (count
-- > 0) {
278 auto type
= vm
.popInt();
279 switch (cast(VATArgType
)type
) {
280 case VATArgType
.Int
: write(vm
.popInt()); break;
281 case VATArgType
.Uint
: write(vm
.popUint()); break;
282 case VATArgType
.Float
: write(vm
.popFloat()); break;
283 case VATArgType
.StrId
: write(StrId(vm
.popUint()).get
); break;
284 case VATArgType
.ActorId
: write("<actor>"); vm
.popUint(); break; //TODO
285 default: write("<invalid-type>"); vm
.popUint(); break; //TODO
288 static if (donl
) writeln();
289 // push dummy return value
293 extern(C
) void doWrite(bool donl
) (uint argc
, ...) {
296 mainloop
: while (argc
>= 2) {
298 int tp
= va_arg
!int(_argptr
);
301 auto v
= va_arg
!int(_argptr
);
304 case VATArgType
.Uint
:
305 auto v
= va_arg
!uint(_argptr
);
308 case VATArgType
.Float
:
309 auto v
= va_arg
!float(_argptr
);
312 case VATArgType
.StrId
:
313 auto v
= StrId(va_arg
!uint(_argptr
)).get
;
316 case VATArgType
.ActorId
:
317 auto v
= ActorId(va_arg
!uint(_argptr
));
318 write("<actor:", v
.valid
, ":", v
.id
, ">");
321 default: write("<invalid-type>"); break mainloop
;
324 static if (donl
) writeln();
329 // ////////////////////////////////////////////////////////////////////////// //
330 void animClearFrames (StrId classtype
, StrId classname
, StrId state
) {
331 auto adef
= findActorDef(classtype
.get
, classname
.get
);
332 if (adef
is null) throw new Exception("animClearFrames: actor '"~classtype
.get
~":"~classname
.get
~"' not found!");
333 adef
.clearFrames(state
);
337 void animAddFrame (StrId classtype
, StrId classname
, StrId state
, uint dir
, StrId sprname
) {
338 auto adef
= findActorDef(classtype
.get
, classname
.get
);
339 if (adef
is null) throw new Exception("animAddFrame: actor '"~classtype
.get
~":"~classname
.get
~"' not found!");
340 if (dir
!= 0) dir
= 1; //TODO: process mirror flag here
341 adef
.addFrame(state
, dir
, sprname
);
345 // ////////////////////////////////////////////////////////////////////////// //
347 conwriteln("setting up D API");
349 FuncPool
["write"] = &doWrite
!false;
350 FuncPool
["writeln"] = &doWrite
!true;
352 FuncPool
["syncrandu31"] = &syncrandu31
;
354 FuncPool
["animClearFrames"] = &animClearFrames
;
355 FuncPool
["animAddFrame"] = &animAddFrame
;
357 FuncPool
["actorSetAnimation"] = function void (ActorId me
, StrId state
) {
358 if (!me
.valid
) return;
359 if (auto adef
= findActorDef(me
.classtype
!string
, me
.classname
!string
)) {
360 me
.zAnimstate
= state
;
365 //FuncPool["getPlayer"] = function ActorId () { assert(0); };
366 //FuncPool["isPlayer"] = function int (ActorId me) { return (me == players.ptr[0] ? 1 : 0); };
368 FuncPool
["getPlayerCount"] = function int () => 1;
370 FuncPool
["getPlayerActor"] = function ActorId (uint pnum
) {
371 if (pnum
== 1) return players
.ptr
[0];
375 FuncPool
["getPlayerButtons"] = function uint (uint pidx
) { return (pidx
== 1 ? plrKeysLast
: 0); };
377 FuncPool
["mapGetTypeTile"] = function int (int x
, int y
) {
379 if (map
!is null && x
>= 0 && y
>= 0 && x
< map
.width
&& y
< map
.height
) {
380 res
= map
.tiles
.ptr
[LevelMap
.Type
].ptr
[y
*map
.width
+x
];
381 if (res
!= LevelMap
.TILE_ACTTRAP
) res
&= 0x7f;
386 FuncPool
["mapGetTile"] = function int (uint layer
, int x
, int y
) {
387 return (map
!is null && x
>= 0 && y
>= 0 && x
< map
.width
&& y
< map
.height
&& layer
>= 0 && layer
<= 1 ? map
.tiles
.ptr
[LevelMap
.Front
+layer
].ptr
[y
*map
.width
+x
] : 0);
390 FuncPool
["mapSetTypeTile"] = function void (int x
, int y
, int tid
) {
391 if (map
is null || x
< 0 || y
< 0 || x
>= map
.width || y
>= map
.height || tid
< 0 || tid
> 255) return;
392 auto p
= map
.tiles
.ptr
[LevelMap
.Type
].ptr
+y
*map
.width
+x
;
395 import render
: mapDirty
;
396 mapDirty((1<<LevelMap
.Type
)|
(1<<LevelMap
.LightMask
));
400 FuncPool
["mapSetTile"] = function void (uint layer
, int x
, int y
, int tid
) {
401 if (map
is null || layer
< 0 || layer
> 1 || x
< 0 || y
< 0 || x
>= map
.width || y
>= map
.height || tid
< 0 || tid
> 255) return;
402 auto p
= map
.tiles
.ptr
[LevelMap
.Front
+layer
].ptr
+y
*map
.width
+x
;
405 import render
: mapDirty
;
408 mapDirty((1<<LevelMap
.Front
)|
(1<<LevelMap
.AllLiquids
)|
(1<<LevelMap
.LiquidMask
));
411 mapDirty((1<<LevelMap
.Back
)|
(1<<LevelMap
.AllLiquids
)|
(1<<LevelMap
.LiquidMask
));
416 FuncPool
["mapGetWaterTexture"] = function int (int fg
) {
417 if (fg
< 0 || fg
>= map
.wallnames
.length
) return 0;
418 switch (map
.wallnames
.ptr
[fg
]) {
419 case "_water_0": return 1;
420 case "_water_1": return 2;
421 case "_water_2": return 3;
427 FuncPool
["getMapViewHeight"] = function int () {
428 import render
: vlWidth
, vlHeight
, getScale
;
429 return vlHeight
/getScale
;
432 FuncPool
["setMapViewPos"] = function void (int x
, int y
) {
433 import render
: setMapViewPos
;
437 FuncPool
["actorsOverlap"] = function int (ActorId a
, ActorId b
) { return (actorsOverlap(a
, b
) ?
1 : 0); };
439 FuncPool
["actorRemove"] = function void (ActorId me
) {
441 if ((me
.flags
!uint&AF_NOCOLLISION
) == 0) ugActorModify
!false(me
); // remove from grid
446 FuncPool
["rewindTouchList"] = &rewindTouchList
;
447 FuncPool
["getNextTouchListItem"] = &getNextTouchListItem
;
449 FuncPool
["actorListRewind"] = &xactorListRewind
;
450 FuncPool
["actorListNext"] = &xactorListNext
;
452 FuncPool
["getCheatNoDoors"] = function int () { import render
: cheatNoDoors
; return (cheatNoDoors ?
1 : 0); };
453 FuncPool
["getCheatNoWallClip"] = function int () { import render
: cheatNoWallClip
; return (cheatNoWallClip ?
1 : 0); };
454 FuncPool
["getCheatNoCeilClip"] = function int () { return 0; };
455 FuncPool
["getCheatNoLiftClip"] = function int () { return 0; };
457 FuncPool
["addMessage"] = function void (string text
, int pause
, bool noreplace
) {
458 import render
: postAddMessage
;
459 postAddMessage(text
, pause
, noreplace
);
462 import d2dparts
: dotAddBlood
, dotAddSpark
, dotAddWater
;
464 FuncPool
["dotAddBlood"] = &dotAddBlood
;
465 FuncPool
["dotAddSpark"] = &dotAddSpark
;
466 FuncPool
["dotAddWater"] = &dotAddWater
;
468 function void (int x, int y, int xv, int yv, int n, int color) {
469 conwriteln("dotAddWater: x=", x, "; y=", y, "; xv=", xv, "; yv=", yv, "; n=", n, "; color=", color);
470 dotAddWater(x, y, xv, yv, n, color);
474 FuncPool
["gactLevelExit"] = function void (int lnum
) {
475 if (nextmapname
.length
== 0) {
476 string nmname
= genNextMapName(lnum
);
477 if (nmname
.length
== 0) assert(0, "no level!");
478 nextmapname
= nmname
;
484 public void registerAPI () {
485 //Actor.actorSize += 256;
486 conwriteln("actor size is ", Actor
.actorSize
, " bytes");
488 version(dacs_use_vm
) FuncPool
.vm
= new DACSVM();
489 //dvm = new DACSVM();
491 // initialize actor animation
492 ActorDef
.forEach((adef
) => adef
.callAnimInit());
494 conwriteln("API registered");
498 // ////////////////////////////////////////////////////////////////////////// //
499 mixin(Actor
.FieldGetMixin
!("classtype", StrId
)); // fget_classtype
500 mixin(Actor
.FieldGetMixin
!("classname", StrId
)); // fget_classname
501 mixin(Actor
.FieldGetMixin
!("x", int));
502 mixin(Actor
.FieldGetMixin
!("y", int));
503 mixin(Actor
.FieldGetMixin
!("dir", uint));
504 mixin(Actor
.FieldGetMixin
!("height", int));
505 mixin(Actor
.FieldGetMixin
!("radius", int));
506 mixin(Actor
.FieldGetMixin
!("flags", uint));
507 mixin(Actor
.FieldGetMixin
!("zAnimstate", StrId
));
508 mixin(Actor
.FieldGetMixin
!("zAnimidx", int));
510 mixin(Actor
.FieldSetMixin
!("zAnimidx", int));
513 public bool actorsOverlap (ActorId a
, ActorId b
) {
514 if (!a
.valid ||
!b
.valid
) return false;
515 if (a
.id
== b
.id
) return false; // no self-overlap
519 int ar
= a
.fget_radius
;
520 int br
= b
.fget_radius
;
522 if (ax
-ar
> bx
+br || ax
+ar
< bx
-br
) return false;
526 int ah
= a
.fget_height
;
527 int bh
= b
.fget_height
;
529 //return (ay > by-bh && ay-ah < by);
530 return (by
-bh
<= ay
&& by
>= ay
-ah
);
534 // ////////////////////////////////////////////////////////////////////////// //
535 public __gshared ActorId
[2] players
;
538 public void loadAllMonsterGraphics () {
539 ActorDef
.forEach((adef
) {
540 conwriteln("loading graphics for '", adef
.classtype
.get
, ":", adef
.classname
.get
, "'");
543 //Actor.dumpActors();
544 realiseSpriteAtlases();
548 public void loadMapMonsters () {
549 assert(map
!is null);
551 players
[] = ActorId(0);
552 //conwriteln(players[0].valid, "; ", players[0].id);
553 foreach (ref thing
; map
.things
) {
554 if (thing
.dmonly
) continue;
555 auto did
= (thing
.type
&0x7fff) in d2dactordefsById
;
556 if (did
!is null && did
.classtype
== "playerstart") {
557 if ((thing
.type
&0x7fff) == 1 ||
(thing
.type
&0x7fff) == 2) {
558 int pnum
= thing
.type
-1;
559 if (!players
[pnum
].valid
) {
560 auto aid
= Actor
.alloc
;
561 aid
.classtype
= StrPool
.intern("monster");
562 aid
.classname
= StrPool
.intern("Player");
563 aid
.plrnum
= cast(uint)(pnum
+1);
564 aid
.state
= StrPool
.MNST_SLEEP
;
565 aid
.x
= cast(int)thing
.x
;
566 aid
.y
= cast(int)thing
.y
;
567 aid
.dir
= cast(uint)(thing
.right ?
1 : 0);
568 if (pnum
== 0) aid
.flags
= aid
.flags
!uint|AF_CAMERACHICK
;
569 auto adef
= findD2DActorDef(thing
.type
);
570 if (adef
is null) assert(0);
572 if ((aid
.flags
!uint&AF_NOCOLLISION
) == 0) ugActorModify
!true(aid
);
574 conwriteln("player #", pnum
+1, " aid is ", aid
.id
);
579 auto adef
= findD2DActorDef(thing
.type
&0x7fff);
582 conwriteln("ignoring D2D thing '", did
.classtype
.get
, ":", did
.classname
.get
, "'");
584 conwriteln("ignoring unknown D2D thing with mapid ", thing
.type
);
588 // create actor and initialize it
589 auto aid
= Actor
.alloc
;
590 aid
.classtype
= StrPool
.intern(adef
.classtype
);
591 aid
.classname
= StrPool
.intern(adef
.classname
);
592 //conwriteln("found '", aid.classtype.get, ":", aid.classname.get, "'");
594 assert(did
.classtype
== adef
.classtype
);
595 assert(did
.classname
== adef
.classname
);
596 conwriteln("mapid=", thing
.type
, "; ", adef
.classtype
, ":", adef
.classname
, "; id=", aid
.id
);
597 assert(aid
.classtype
!string
== adef
.classtype
);
598 assert(aid
.classname
!string
== adef
.classname
);
602 aid
.state
= StrPool
.MNST_SLEEP
;
603 aid
.x
= cast(int)thing
.x
;
604 aid
.y
= cast(int)thing
.y
;
605 aid
.dir
= cast(uint)(thing
.right ?
1 : 0);
606 if (thing
.type
&0x8000) aid
.flags
= aid
.flags
!uint|AF_NOGRAVITY
;
607 //if (aid.classtype!string == "item" && aid.x!int < 64) { aid.x = 92; aid.y = aid.y!int-16; conwriteln("!!!"); }
609 if ((aid
.flags
!uint&AF_NOCOLLISION
) == 0) ugActorModify
!true(aid
);
613 foreach (ref sw
; map
.switches
) {
614 if (sw
.type
== 0) continue; // just in case
615 auto swname
= getD2DSwitchClassName(sw
.type
);
616 if (swname
.length
== 0) {
617 conwriteln("unknown switch type ", sw
.type
);
620 if (auto adef
= findActorDef("switch", swname
)) {
621 auto aid
= Actor
.alloc
;
622 aid
.classtype
= StrPool
.intern("switch");
623 aid
.classname
= StrPool
.intern(swname
);
624 // nocollision, 'cause collision checking will be processed in switch thinker, but other actors should not touch switches
625 aid
.flags
= /*AF_NOCOLLISION|*/AF_NOGRAVITY|
/*AF_NOONTOUCH|*/AF_NODRAW|AF_NOLIGHT|AF_NOANIMATE
;
628 aid
.switchabf
= (sw
.a
<<16)|
(sw
.b
<<8)|sw
.flags
;
633 if ((aid
.flags
!uint&AF_NOCOLLISION
) == 0) ugActorModify
!true(aid
); // just in case
635 conwriteln("switch definition 'switch:", swname
, "' not found");
639 conwriteln("initial snapshot size: ", Actor
.snapshotSize
, " bytes");
643 // ////////////////////////////////////////////////////////////////////////// //
644 __gshared ActorId
[65536] xactorList
; // aids
645 __gshared
uint xactorListCount
, xactorListIndex
= uint.max
;
649 void xactorListRewind () {
650 if (!touchListAllowed
) return; // it's ok to reuse it here
651 xactorListCount
= xactorListIndex
= 0;
652 Actor
.forEach((ActorId me
) {
653 if (me
.fget_classtype
!= StrPool
.X_X
) xactorList
.ptr
[xactorListCount
++] = me
;
659 ActorId
xactorListNext () {
660 if (!touchListAllowed
) return ActorId(0); // it's ok to reuse it here
661 if (xactorListIndex
== uint.max
) xactorListRewind();
662 while (xactorListIndex
< xactorListCount
) {
663 auto aid
= xactorList
.ptr
[xactorListIndex
];
665 if (aid
.fget_classtype
== StrPool
.X_X
) continue;
672 // ////////////////////////////////////////////////////////////////////////// //
673 __gshared
uint[65536] touchList
; // aids
674 __gshared
uint[] realTouchList
;
675 __gshared
uint realTouchListIndex
= uint.max
;
676 __gshared ActorId curThinkingActor
;
677 __gshared
bool touchListAllowed
= false;
681 void rewindTouchList () {
682 if (!touchListAllowed
) return;
683 realTouchListIndex
= 0;
684 realTouchList
= ugActorHitList(curThinkingActor
, touchList
[]);
689 ActorId
getNextTouchListItem () {
690 if (!touchListAllowed
) return ActorId(0);
691 if (realTouchListIndex
== uint.max
) rewindTouchList();
692 while (realTouchListIndex
< realTouchList
.length
) {
693 auto aid
= ActorId(realTouchList
.ptr
[realTouchListIndex
]);
694 ++realTouchListIndex
;
695 if (aid
.fget_classtype
== StrPool
.X_X
) continue;
696 if (aid
.valid
&& (aid
.fget_flags
&AF_NOONTOUCH
) == 0) return aid
;
702 public void doActorsThink () {
703 // we have too much memory!
704 __gshared
uint[65536] validActorsList
;
705 __gshared ActorId
[65536] postponedDeath
;
706 __gshared
uint pdcount
;
708 touchListAllowed
= true;
709 scope(exit
) touchListAllowed
= false;
711 foreach (uint xid
; Actor
.getValidList(validActorsList
[])) {
712 auto me
= ActorId(xid
);
714 if (me
.fget_classtype
== StrPool
.X_X
) { postponedDeath
.ptr
[pdcount
++] = me
; continue; }
715 auto flags
= me
.fget_flags
;
716 if ((flags
&AF_NOCOLLISION
) == 0) ugActorModify
!false(me
); // remove from grid
717 if (auto adef
= findActorDef(me
)) {
718 if ((flags
&AF_NOTHINK
) == 0) {
719 realTouchListIndex
= uint.max
;
720 xactorListIndex
= uint.max
;
721 curThinkingActor
= me
;
723 //if (me.x!int < 32) conwriteln("actor: ", me.id, "; attLightRGBX=", me.attLightRGBX!uint);
724 if (!me
.valid
) continue; // we are dead
725 if (me
.fget_classtype
== StrPool
.X_X
) { postponedDeath
.ptr
[pdcount
++] = me
; continue; }
726 flags
= me
.fget_flags
; // in case script updated flags
728 if ((flags
&AF_NOANIMATE
) == 0) {
729 int aidx
= me
.fget_zAnimidx
;
730 int nidx
= adef
.nextAnimIdx(me
.fget_zAnimstate
, me
.fget_dir
, aidx
);
731 //conwriteln("actor ", me.id, " (", me.classtype!string, me.classname!string, "): state=", me.zAnimstate!string, "; aidx=", aidx, "; nidx=", nidx);
732 me
.fset_zAnimidx
= nidx
;
733 //assert(me.fget_zAnimidx == nidx);
736 if ((flags
&AF_NOCOLLISION
) == 0) ugActorModify
!true(me
);
740 // process scheduled death
741 foreach (ActorId aid
; postponedDeath
[0..pdcount
]) {
746 //{ import std.stdio : stdout; stdout.writeln("========================================="); }
747 //Actor.dumpActors();