Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / mesh_camera_col_manager.cpp
blobbf5994583000dfecad678e29e80ed4f436d47ca5
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
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 "stdpch.h"
18 #include "mesh_camera_col_manager.h"
19 #include "precipitation_clip_grid.h"
20 #include "nel/3d/u_visual_collision_manager.h"
21 #include "nel/3d/u_shape_bank.h"
22 #include "nel/misc/hierarchical_timer.h"
23 #include "nel/misc/system_info.h"
24 #include "nel/3d/u_visual_collision_mesh.h"
26 using namespace NL3D;
27 using namespace NLMISC;
28 using namespace std;
31 // ***************************************************************************
32 CMeshCameraColManager MeshCameraColManager;
35 // ***************************************************************************
36 extern UVisualCollisionManager *CollisionManager;
37 extern UDriver *Driver;
40 // ***************************************************************************
41 CMeshCameraColManager::CMeshCameraColManager()
45 // ***************************************************************************
46 CMeshCameraColManager::~CMeshCameraColManager()
48 if(!CollisionManager)
49 return;
51 // reset any remaining mesh
52 TIgMap::iterator it;
53 for(it= _IgMap.begin();it!=_IgMap.end();it++)
55 CMeshGroup &mg= it->second;
56 for(uint i=0;i<mg.Meshs.size();i++)
58 CollisionManager->removeMeshCollision(mg.Meshs[i]);
61 _IgMap.clear();
64 // ***************************************************************************
65 void CMeshCameraColManager::instanceGroupLoaded(NL3D::UInstanceGroup * /* ig */)
67 // no op
70 // ***************************************************************************
71 void CMeshCameraColManager::instanceGroupAdded(NL3D::UInstanceGroup *ig)
73 if(!ig)
74 return;
76 // TestYoyo
77 /*CSimpleClock clock;
78 clock.start();*/
80 // Build a list of Mesh to add to the collision manager
81 CMeshGroup mg;
83 // for all instance of the ig
84 for(uint i=0;i<ig->getNumInstance();i++)
86 string shapeName= ig->getShapeName(i);
87 if (!shapeName.empty())
89 // well... get the actual name (not transformed)
90 if (shapeName.find('.') == std::string::npos)
91 shapeName += ".shape";
93 // try to get the shape
94 UShape shape= Driver->getShapeBank()->getShape(shapeName);
95 // if found
96 if(!shape.empty())
98 UVisualCollisionMesh colMesh;
99 shape.getVisualCollisionMesh(colMesh);
100 // if this mesh has a collision
101 if(!colMesh.empty())
103 // get the instance matrix
104 CMatrix mat;
105 ig->getInstanceMatrix(i, mat);
107 // special code for matis serre. Use the same flags as for shadows
108 bool avoidCollisionInside= ig->dontCastShadowForInterior(i);
109 bool avoidCollisionOutside= ig->dontCastShadowForExterior(i);
110 // very special patch for the matis serre (grrrrrrrrrrrrr)
111 avoidCollisionOutside= avoidCollisionOutside || toLowerAscii(shapeName)== "ma_serre_interieur.shape";
113 // then send the result to the collision manager, and keep the mesh col id if succeed
114 uint32 meshId= CollisionManager->addMeshInstanceCollision(colMesh, mat, avoidCollisionInside, avoidCollisionOutside);
115 if(meshId)
116 mg.Meshs.push_back(meshId);
122 // if mesh group not empty, append to the map (for future remove)
123 if(!mg.Meshs.empty())
125 // should not be present
126 nlassert(_IgMap.find(ig)==_IgMap.end());
127 // insert
128 _IgMap[ig]= mg;
131 // TestYoyo
132 /*clock.stop();
133 double freq = (double) CSystemInfo::getProcessorFrequency(false);
134 double msPerTick = 1000 / (double) freq;
135 nlinfo("IG Camera Added: {%x, %d}: %.3f ms", (uint32)ig, ig->getNumInstance(), msPerTick * clock.getNumTicks());*/
138 // ***************************************************************************
139 void CMeshCameraColManager::instanceGroupRemoved(NL3D::UInstanceGroup *ig)
141 // find the ig in the map
142 TIgMap::iterator it= _IgMap.find(ig);
143 if(it!=_IgMap.end())
145 // TestYoyo
146 /*CSimpleClock clock;
147 clock.start();*/
149 // remove the mesh collision from the manager
150 CMeshGroup &mg= it->second;
151 for(uint i=0;i<mg.Meshs.size();i++)
153 CollisionManager->removeMeshCollision(mg.Meshs[i]);
154 //HeightGrid.removeCollisionMesh(mg.Meshs[i]);
156 // remove
157 _IgMap.erase(it);
159 // TestYoyo
160 /*clock.stop();
161 double freq = (double) CSystemInfo::getProcessorFrequency(false);
162 double msPerTick = 1000 / (double) freq;
163 nlinfo("IG Camera Removed: %.3f ms", msPerTick * clock.getNumTicks());*/