Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / nel / src / pacs / move_cell.cpp
blob436808754de7e06e1144b73ae3520c1e4db6943a
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdpacs.h"
19 #include "nel/pacs/move_cell.h"
20 #include "nel/pacs/move_element.h"
21 #include "nel/pacs/move_primitive.h"
23 namespace NLPACS
26 // ***************************************************************************
28 CMoveCell::CMoveCell()
30 _FirstX=NULL;
31 _LastX=NULL;
32 /*_FirstY=NULL;
33 _LastY=NULL;*/
36 // ***************************************************************************
38 void CMoveCell::unlinkX (CMoveElement *element)
40 // Check first last
41 if (_FirstX==element)
42 _FirstX=element->NextX;
43 if (_LastX==element)
44 _LastX=element->PreviousX;
46 // Relink to others
47 if (element->NextX)
48 element->NextX->PreviousX=element->PreviousX;
49 if (element->PreviousX)
50 element->PreviousX->NextX=element->NextX;
53 // ***************************************************************************
55 /*void CMoveCell::unlinkY (CMoveElement *element)
57 // Linked in list ?
58 // Check first / last
59 if (_FirstY==element)
60 _FirstY=element->NextY;
61 if (_LastY==element)
62 _LastY=element->PreviousY;
64 // Relink to others
65 if (element->NextY)
66 element->NextY->PreviousY=element->PreviousY;
67 if (element->PreviousY)
68 element->PreviousY->NextY=element->NextY;
69 }*/
71 // ***************************************************************************
73 void CMoveCell::linkX (CMoveElement *previous, CMoveElement *element, CMoveElement *next)
75 // Link the element
76 element->NextX=next;
77 element->PreviousX=previous;
79 // Link to others
80 if (previous)
81 previous->NextX=element;
82 if (next)
83 next->PreviousX=element;
85 // Check first / last
86 if (previous==NULL)
87 _FirstX=element;
88 if (next==NULL)
89 _LastX=element;
92 // ***************************************************************************
94 /*void CMoveCell::linkY (CMoveElement *previous, CMoveElement *element, CMoveElement *next)
96 // Link the element
97 element->NextY=next;
98 element->PreviousY=previous;
100 // Link to others
101 if (previous)
102 previous->NextY=element;
103 if (next)
104 next->PreviousY=element;
106 // Check first / last
107 if (previous==NULL)
108 _FirstY=element;
109 if (next==NULL)
110 _LastY=element;
113 // ***************************************************************************
115 void CMoveCell::updateSortedLists (CMoveElement *element, uint8 worldImage)
117 // ** Update sorted list on X
119 // Primitive pointer
120 CMovePrimitive *primitive=element->Primitive;
122 // Get the world image
123 CPrimitiveWorldImage *wI=primitive->getWorldImage (worldImage);
125 // Test if we will go to the right
126 CMoveElement *ptr=element->NextX;
127 if (ptr && (wI->getBBXMin() > ptr->Primitive->getWorldImage (worldImage)->getBBXMin()) )
129 // Unlink
130 unlinkX (element);
132 // Adjust the list localisation
133 while (ptr->NextX && (wI->getBBXMin() > ptr->NextX->Primitive->getWorldImage (worldImage)->getBBXMin()) )
135 // Next ptr
136 ptr=ptr->NextX;
139 // Here we go
140 linkX (ptr, element, ptr->NextX);
142 else
144 // Test if we will go to the left
145 ptr=element->PreviousX;
146 if (ptr && (ptr->Primitive->getWorldImage (worldImage)->getBBXMin() > wI->getBBXMin()) )
148 // Unlink
149 unlinkX (element);
151 // Adjust the list localisation
152 while (ptr->PreviousX && (ptr->PreviousX->Primitive->getWorldImage (worldImage)->getBBXMin() > wI->getBBXMin()) )
154 // Next ptr
155 ptr=ptr->PreviousX;
158 // Here we go
159 linkX (ptr->PreviousX, element, ptr);
163 /* // ** Update sorted list on Y
165 // Test if we will go to the right
166 ptr=element->NextY;
167 if (ptr && (primitive->getBBYMin() > ptr->Primitive->getBBYMin()) )
169 // Unlink
170 unlinkY (element);
172 // Adjust the list localisation
173 while (ptr->NextY && (primitive->getBBYMin() > ptr->NextY->Primitive->getBBYMin()) )
175 // Next ptr
176 ptr=ptr->NextY;
179 // Here we go
180 linkY (ptr, element, ptr->NextY);
182 else
184 // Test if we will go to the left
185 ptr=element->PreviousY;
186 if (ptr && (ptr->Primitive->getBBYMin() > primitive->getBBYMin()) )
188 // Unlink
189 unlinkY (element);
191 // Adjust the list localisation
192 while (ptr->PreviousY && (ptr->PreviousY->Primitive->getBBYMin() > primitive->getBBYMin()) )
194 // Next ptr
195 ptr=ptr->PreviousY;
198 // Here we go
199 linkY (ptr->PreviousY, element, ptr);
204 // ***************************************************************************
206 } // NLPACS