libvwad: updated -- vwadwrite: free file buffers on close (otherwise archive creation...
[k8vavoom.git] / source / psim / p_world.h
blob4897229f8cbc1828ed1122c54b02915f554a002c
1 //**************************************************************************
2 //**
3 //** ## ## ## ## ## #### #### ### ###
4 //** ## ## ## ## ## ## ## ## ## ## #### ####
5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ##
6 //** ## ## ######## ## ## ## ## ## ## ## ### ##
7 //** ### ## ## ### ## ## ## ## ## ##
8 //** # ## ## # #### #### ## ##
9 //**
10 //** Copyright (C) 1999-2006 Jānis Legzdiņš
11 //** Copyright (C) 2018-2023 Ketmar Dark
12 //**
13 //** This program is free software: you can redistribute it and/or modify
14 //** it under the terms of the GNU General Public License as published by
15 //** the Free Software Foundation, version 3 of the License ONLY.
16 //**
17 //** This program is distributed in the hope that it will be useful,
18 //** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 //** GNU General Public License for more details.
21 //**
22 //** You should have received a copy of the GNU General Public License
23 //** along with this program. If not, see <http://www.gnu.org/licenses/>.
24 //**
25 //**************************************************************************
27 // BLOCK MAP ITERATORS
29 // For each line/thing in the given mapblock, call the passed PIT_*
30 // function. If the function returns false, exit with false without checking
31 // anything else.
33 //**************************************************************************
34 #ifndef VAVOOM_PSIM_WORLD_HEADER
35 #define VAVOOM_PSIM_WORLD_HEADER
38 //==========================================================================
40 // VBlockPObjIterator
42 // The validcount flags are used to avoid checking pobjs that are marked in
43 // multiple mapblocks, so increment validcount before creating this object.
45 //==========================================================================
46 class VBlockPObjIterator {
47 private:
48 VLevel *Level;
49 polyobj_t **PolyPtr;
50 polyblock_t *PolyLink;
51 bool returnAll;
53 public:
54 // if `all` is false, return only 3d pobjs
55 VBlockPObjIterator (VLevel *Level, int x, int y, polyobj_t **APolyPtr, bool all=false);
56 bool GetNext ();
60 //==========================================================================
62 // VRadiusThingsIterator
64 //==========================================================================
65 class VRadiusThingsIterator : public VScriptIterator {
66 private:
67 VThinker *Self;
68 VEntity **EntPtr;
69 VEntity *Ent;
70 int x, y;
71 int xl, xh;
72 int yl, yh;
74 public:
75 VRadiusThingsIterator (VThinker *ASelf, VEntity **AEntPtr, TVec Org, float Radius);
76 virtual bool GetNext () override;
80 //==========================================================================
82 // VPathTraverse
84 // Traces a line from x1,y1 to x2,y2, calling the traverser function for
85 // each. Returns true if the traverser function returns true for all lines.
87 //==========================================================================
88 class VPathTraverse : public VScriptIterator {
89 private:
90 VLevel *Level;
91 TPlane trace_plane;
92 TVec trace_org;
93 TVec trace_dest;
94 TVec trace_delta;
95 TVec trace_dir;
96 TVec trace_org3d;
97 TVec trace_dir3d; // normalised
98 float trace_len;
99 float trace_len3d;
100 float max_frac;
101 unsigned scanflags; // PT_xxx
103 int poolStart, poolEnd;
105 intercept_t *InPtr;
106 int Count;
107 int Index;
109 public:
110 VPathTraverse (VThinker *Self, intercept_t *AInPtr, const TVec &p0, const TVec &p1, int flags,
111 vuint32 planeflags=SPF_NOBLOCKING|SPF_NOBLOCKSHOOT, vuint32 lineflags=ML_BLOCKEVERYTHING|ML_BLOCKHITSCAN);
113 virtual ~VPathTraverse ();
115 virtual bool GetNext () override;
117 private:
118 void Init (VThinker *Self, const TVec &p0, const TVec &p1, int flags, vuint32 planeflags, vuint32 lineflags);
119 void AddLineIntercepts (int mapx, int mapy, vuint32 planeflags, vuint32 lineflags);
120 void AddThingIntercepts (int mapx, int mapy);
121 intercept_t &NewIntercept (const float frac);
123 inline int InterceptCount () const noexcept { return Level->CurrentPathInterceptionIndex()-poolStart; }
124 inline intercept_t *GetIntercept (int idx) noexcept { return Level->GetPathIntercept(poolStart+idx); }
126 inline bool NeedCheckBMCell (const int bmx, const int bmy) const noexcept {
127 if (bmx >= 0 && bmy >= 0 && bmx < Level->BlockMapWidth && bmy < Level->BlockMapHeight) {
128 vint32 *pp = Level->processedBMCells+(bmy*Level->BlockMapWidth+bmx);
129 if (*pp == validcount) return false;
130 *pp = validcount;
131 return true;
132 } else {
133 return false;
139 #endif