Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / client / src / mesh_camera_col_manager.cpp
blob96cedbf7e9f423fc4667f63a3dfe7f6cf85a2a76
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdpch.h"
21 #include "mesh_camera_col_manager.h"
22 #include "precipitation_clip_grid.h"
23 #include "nel/3d/u_visual_collision_manager.h"
24 #include "nel/3d/u_shape_bank.h"
25 #include "nel/misc/hierarchical_timer.h"
26 #include "nel/misc/system_info.h"
27 #include "nel/3d/u_visual_collision_mesh.h"
29 using namespace NL3D;
30 using namespace NLMISC;
31 using namespace std;
34 // ***************************************************************************
35 CMeshCameraColManager MeshCameraColManager;
38 // ***************************************************************************
39 extern UVisualCollisionManager *CollisionManager;
40 extern UDriver *Driver;
43 // ***************************************************************************
44 CMeshCameraColManager::CMeshCameraColManager()
48 // ***************************************************************************
49 CMeshCameraColManager::~CMeshCameraColManager()
51 if(!CollisionManager)
52 return;
54 // reset any remaining mesh
55 TIgMap::iterator it;
56 for(it= _IgMap.begin();it!=_IgMap.end();it++)
58 CMeshGroup &mg= it->second;
59 for(uint i=0;i<mg.Meshs.size();i++)
61 CollisionManager->removeMeshCollision(mg.Meshs[i]);
64 _IgMap.clear();
67 // ***************************************************************************
68 void CMeshCameraColManager::instanceGroupLoaded(NL3D::UInstanceGroup * /* ig */)
70 // no op
73 // ***************************************************************************
74 void CMeshCameraColManager::instanceGroupAdded(NL3D::UInstanceGroup *ig)
76 if(!ig)
77 return;
79 // TestYoyo
80 /*CSimpleClock clock;
81 clock.start();*/
83 // Build a list of Mesh to add to the collision manager
84 CMeshGroup mg;
86 // for all instance of the ig
87 for(uint i=0;i<ig->getNumInstance();i++)
89 string shapeName= ig->getShapeName(i);
90 if (!shapeName.empty())
92 // well... get the actual name (not transformed)
93 if (shapeName.find('.') == std::string::npos)
94 shapeName += ".shape";
96 // try to get the shape
97 UShape shape= Driver->getShapeBank()->getShape(shapeName);
98 // if found
99 if(!shape.empty())
101 UVisualCollisionMesh colMesh;
102 shape.getVisualCollisionMesh(colMesh);
103 // if this mesh has a collision
104 if(!colMesh.empty())
106 // get the instance matrix
107 CMatrix mat;
108 ig->getInstanceMatrix(i, mat);
110 // special code for matis serre. Use the same flags as for shadows
111 bool avoidCollisionInside= ig->dontCastShadowForInterior(i);
112 bool avoidCollisionOutside= ig->dontCastShadowForExterior(i);
113 // very special patch for the matis serre (grrrrrrrrrrrrr)
114 avoidCollisionOutside= avoidCollisionOutside || toLowerAscii(shapeName)== "ma_serre_interieur.shape";
116 // then send the result to the collision manager, and keep the mesh col id if succeed
117 uint32 meshId= CollisionManager->addMeshInstanceCollision(colMesh, mat, avoidCollisionInside, avoidCollisionOutside);
118 if(meshId)
119 mg.Meshs.push_back(meshId);
125 // if mesh group not empty, append to the map (for future remove)
126 if(!mg.Meshs.empty())
128 // should not be present
129 nlassert(_IgMap.find(ig)==_IgMap.end());
130 // insert
131 _IgMap[ig]= mg;
134 // TestYoyo
135 /*clock.stop();
136 double freq = (double) CSystemInfo::getProcessorFrequency(false);
137 double msPerTick = 1000 / (double) freq;
138 nlinfo("IG Camera Added: {%x, %d}: %.3f ms", (uint32)ig, ig->getNumInstance(), msPerTick * clock.getNumTicks());*/
141 // ***************************************************************************
142 void CMeshCameraColManager::instanceGroupRemoved(NL3D::UInstanceGroup *ig)
144 // find the ig in the map
145 TIgMap::iterator it= _IgMap.find(ig);
146 if(it!=_IgMap.end())
148 // TestYoyo
149 /*CSimpleClock clock;
150 clock.start();*/
152 // remove the mesh collision from the manager
153 CMeshGroup &mg= it->second;
154 for(uint i=0;i<mg.Meshs.size();i++)
156 CollisionManager->removeMeshCollision(mg.Meshs[i]);
157 //HeightGrid.removeCollisionMesh(mg.Meshs[i]);
159 // remove
160 _IgMap.erase(it);
162 // TestYoyo
163 /*clock.stop();
164 double freq = (double) CSystemInfo::getProcessorFrequency(false);
165 double msPerTick = 1000 / (double) freq;
166 nlinfo("IG Camera Removed: %.3f ms", msPerTick * clock.getNumTicks());*/