convert line ends
[canaan.git] / prj / cam / src / sim / roompa.h
blob0689b396803fe7f6a5c807bc58bdd7f90564b3a5
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/src/sim/roompa.h,v 1.8 2000/01/31 10:00:36 adurant Exp $
8 //
9 // cRooms header
11 #pragma once
13 #ifndef __ROOMPA_H
14 #define __ROOMPA_H
16 #include <matrixs.h>
17 #include <hashpp.h>
18 #include <dlist.h>
19 #include <dlisttem.h>
21 #include <roombase.h>
23 /////////////////
25 const kMaxDepth = 10;
27 /////////////////
29 enum eEnterResult_
31 kER_Nothing,
32 kER_StartBad,
33 kER_EndBad,
34 kER_Success,
36 typedef int eEnterResult;
38 ////////////////////////////////////////////////////////////////////////////////
40 class cRoomPropResult;
42 typedef cDListNode<cRoomPropResult, 0> cRoomPropResultNode;
43 typedef cDList<cRoomPropResult, 0> cRoomPropResultListBase;
45 class cRoomPropResult : public cRoomPropResultNode
47 public:
48 cRoomPropResult(const cRoom *init_room);
50 const cRoom *room;
53 inline cRoomPropResult::cRoomPropResult(const cRoom *init_room)
54 : room(init_room)
58 ////////////////////////////////////////
60 class cRoomPropResultList : public cRoomPropResultListBase
62 public:
63 ~cRoomPropResultList() { DestroyAll(); }
66 ////////////////////////////////////////
68 // 1024 * 16 = 16k
69 #define MAX_BF_ROOMS 1024
71 // array elements for A* search
72 class cBFRoomInfo
74 public:
75 void Init(mxs_real _dist, int _previous_room, int _previous_portal, short _next_active, short _prev_active)
77 dist = _dist;
78 previous_room = _previous_room + 1;
79 previous_portal = _previous_portal + 1;
80 next_active = _next_active + 1;
81 prev_active = _prev_active + 1;
84 mxs_real GetDist() const { return dist; };
85 void SetDist(mxs_real _dist) { dist = _dist; };
87 int GetPreviousRoom() const { return previous_room - 1; };
88 void SetPreviousRoom(int _previous_room) { previous_room = _previous_room + 1; };
90 int GetPreviousRoom2() const { return previous_room_2 - 1; };
91 void SetPreviousRoom2(int _previous_room_2) { previous_room_2 = _previous_room_2 + 1; };
93 void SwitchPreviousRooms()
95 static short temp;
97 temp = previous_room;
98 previous_room = previous_room_2;
99 previous_room_2 = temp;
101 temp = previous_portal;
102 previous_portal = previous_portal_2;
103 previous_portal_2 = temp;
106 int GetPreviousPortal() const { return previous_portal - 1; };
107 void SetPreviousPortal(int _previous_portal) { previous_portal = _previous_portal + 1; };
109 int GetPreviousPortal2() const { return previous_portal - 1; };
110 void SetPreviousPortal2(int _previous_portal_2) { previous_portal_2 = _previous_portal_2 + 1; };
112 short GetNextActive() const { return next_active - 1; };
113 void SetNextActive(short _next_active) { next_active = _next_active + 1; };
115 short GetPrevActive() const { return prev_active - 1; };
116 void SetPrevActive(short _prev_active) { prev_active = _prev_active + 1; };
118 private:
119 mxs_real dist; // distance to get to this room
120 short previous_room; // how we got to this room
121 short previous_room_2; // secondary previous room
122 short previous_portal; // the portal we used to get here
123 short previous_portal_2; // secondary previous portal
124 short next_active; // the next room id in the active list
125 short prev_active; // the previous room id in the active list
128 ////////////////////////////////////////////////////////////////////////////////
130 class cRoomPropAgent;
132 class cRoomPAFuncs
134 public:
135 cRoomPropAgent *GetPropAgent;
137 virtual int EnterCallback(const cRoom *room, const cRoomPortal *enterPortal, const mxs_vector &enterPt, mxs_real dist) = 0;
138 virtual void ExitCallback(const cRoom *room) = 0;
139 virtual mxs_real PortalsCallback(const cRoomPortal *enterPortal, const cRoomPortal *exitPortal, mxs_real dist) = 0;
141 cRoomPropAgent *m_RoomPropAgent;
144 ////////////////////////////////////////////////////////////////////////////////
146 class cRoomPropAgent
148 public:
150 /////////////////
152 // Constructor / Destructor
154 cRoomPropAgent();
155 ~cRoomPropAgent();
158 /////////////////
160 // Functions
162 void SetFunctions(cRoomPAFuncs *funcs);
164 void PropagateBF(const mxs_vector &startPos, const cRoom *startRoom);
165 void PropagateDF(const mxs_vector &startPos, const cRoom *startRoom);
167 void GetRoomPath(const cRoom *endRoom, cRoomPropResultList *pResultList) const;
168 const cBFRoomInfo *GetRoomBrushInfo() const;
170 private:
172 void PropagateRec(const cRoom *curRoom, const cRoomPortal *enterPortal, const mxs_vector &startPt, mxs_real dist, int depth);
174 cRoomPAFuncs *m_Funcs;
176 cBFRoomInfo m_BFRoomInfo[MAX_BF_ROOMS];
179 ////////////////////////////////////////////////////////////////////////////////
181 inline const cBFRoomInfo *cRoomPropAgent::GetRoomBrushInfo() const
183 return m_BFRoomInfo;
186 ////////////////////////////////////////////////////////////////////////////////
188 inline void cRoomPropAgent::SetFunctions(cRoomPAFuncs *funcs)
190 m_Funcs = funcs;
191 m_Funcs->m_RoomPropAgent = this;
194 ////////////////////////////////////////////////////////////////////////////////
196 #endif