Use configured resolution for login/outgame/ingame
[ryzomcore.git] / nel / tools / 3d / ig_add / main.cpp
blobf205d7a98981db862e0f74526e40a0827a0e9cc5
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 <iostream>
18 #include <vector>
20 #include "nel/misc/file.h"
22 #include "nel/3d/scene_group.h"
24 using namespace NLMISC;
25 using namespace NL3D;
26 using namespace std;
28 // ***************************************************************************
29 CInstanceGroup* LoadInstanceGroup (const char* sFilename)
31 CIFile file;
32 CInstanceGroup *newIG = new CInstanceGroup;
34 if( file.open( sFilename ) )
36 try
38 newIG->serial (file);
40 catch (const Exception &)
42 delete newIG;
43 return NULL;
46 else
48 delete newIG;
49 return NULL;
51 return newIG;
54 // ***************************************************************************
55 bool SaveInstanceGroup (const char* sFilename, CInstanceGroup *pIG)
57 COFile file;
59 if( file.open( sFilename ) )
61 try
63 pIG->serial (file);
65 catch (const Exception &)
67 return false;
70 else
72 return false;
74 return true;
77 // ***************************************************************************
78 int main(int nNbArg, char**ppArgs)
81 if (nNbArg != 4)
83 // Display help information
84 cout << "USAGE : ig_add out in1 in2" << endl;
85 cout << "Make out = in1 + in2 (out, in1 and in2 are *.IG files" << endl;
86 return 1;
89 // Load in1 and in2
90 // ****************
91 CInstanceGroup *pIG1 = LoadInstanceGroup (ppArgs[2]);
92 if (pIG1 == NULL)
94 cerr << "File " << ppArgs[2] << " not found" << endl;
95 return -1;
97 CInstanceGroup *pIG2 = LoadInstanceGroup (ppArgs[3]);
98 if (pIG2 == NULL)
100 cerr << "File " << ppArgs[3] << " not found" << endl;
101 delete pIG1;
102 return -1;
105 // Add in1 and in2
106 // ***************
107 CInstanceGroup *pIGout = new CInstanceGroup;
109 CVector vGP1, vGP2, vGPout;
110 CInstanceGroup::TInstanceArray IA1, IA2, IAout;
111 vector<CCluster> Clusters1, Clusters2, Clustersout;
112 vector<CPortal> Portals1, Portals2, Portalsout;
113 vector<CPointLightNamed> PLN1, PLN2, PLNout;
115 pIG1->retrieve (vGP1, IA1, Clusters1, Portals1, PLN1);
116 pIG2->retrieve (vGP2, IA2, Clusters2, Portals2, PLN2);
118 uint32 i;
120 // -----------------------------------------------------------------------
121 vGPout = (vGP1+vGP2) / 2.0f;
123 // -----------------------------------------------------------------------
124 for (i = 0; i < IA1.size(); ++i)
126 CInstanceGroup::CInstance iTmp = IA1[i];
127 iTmp.Pos += (vGP1 - vGPout);
128 IAout.push_back(iTmp);
130 for (i = 0; i < IA2.size(); ++i)
132 CInstanceGroup::CInstance iTmp = IA2[i];
133 iTmp.Pos += (vGP2 - vGPout);
134 IAout.push_back(iTmp);
137 // -----------------------------------------------------------------------
138 Clustersout = Clusters1;
139 for (i = 0; i < Clusters2.size(); ++i)
140 Clustersout.push_back(Clusters2[i]);
142 // -----------------------------------------------------------------------
143 Portalsout = Portals1;
144 for (i = 0; i < Portals2.size(); ++i)
145 Portalsout.push_back(Portals2[i]);
147 // -----------------------------------------------------------------------
148 PLNout = PLN1;
149 for (i = 0; i < PLN2.size(); ++i)
150 PLNout.push_back(PLN2[i]);
153 pIGout->build (vGPout, IAout, Clustersout, Portalsout, PLNout);
155 // Save out
156 // ********
157 if (!SaveInstanceGroup (ppArgs[1], pIGout))
159 cerr << "Cannot save to file " << ppArgs[1] << endl;
161 // Delete the ig
162 delete pIG1;
163 delete pIG2;
164 delete pIGout;
166 return -1;
169 // Delete the ig
170 delete pIG1;
171 delete pIG2;
172 delete pIGout;
174 return 1;
177 // NOTES : For the moment the behaviour of the build with cluster system is
178 // strange because the instance of the instance group are not relinked to
179 // all the clusters... But this is not a big deal because we just want to
180 // add group of instances without any cluster system