Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / tools / build_gamedata / processes / ig / 2_build.py
blobd5e989bfc57501136fa9e4c8ed94dca4d4747833
1 #!/usr/bin/python
2 #
3 # \file 2_build.py
4 # \brief Build ig
5 # \date 2010-05-24 13:42GMT
6 # \author Jan Boon (Kaetemi)
7 # Python port of game data build pipeline.
8 # Build ig
9 #
10 # NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
11 # Copyright (C) 2009-2014 by authors
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Affero General Public License as
15 # published by the Free Software Foundation, either version 3 of the
16 # License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Affero General Public License for more details.
23 # You should have received a copy of the GNU Affero General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 import time, sys, os, shutil, subprocess, distutils.dir_util
28 sys.path.append("../../configuration")
30 if os.path.isfile("log.log"):
31 os.remove("log.log")
32 log = open("log.log", "w")
33 from scripts import *
34 from buildsite import *
35 from process import *
36 from tools import *
37 from directories import *
39 printLog(log, "")
40 printLog(log, "-------")
41 printLog(log, "--- Build ig")
42 printLog(log, "-------")
43 printLog(log, time.strftime("%Y-%m-%d %H:%MGMT", time.gmtime(time.time())))
44 printLog(log, "")
46 # Find tools
47 ExecTimeout = findTool(log, ToolDirectories, ExecTimeoutTool, ToolSuffix)
48 PrimExport = findTool(log, ToolDirectories, PrimExportTool , ToolSuffix)
49 IgElevation = findTool(log, ToolDirectories, IgElevationTool, ToolSuffix)
50 IgAdd = findTool(log, ToolDirectories, IgAddTool, ToolSuffix)
52 configDir = ActiveProjectDirectory + "/generated"
53 mkPath(log, configDir)
55 def igElevation(inputIgDir, outputIgDir):
56 printLog(log, ">>> IG Elevation <<<")
57 mkPath(log, inputIgDir)
58 mkPath(log, outputIgDir)
59 needUpdateIg = needUpdateDirByTagLog(log, inputIgDir, ".ig", outputIgDir, ".ig")
60 if needUpdateIg:
61 printLog(log, "DETECT UPDATE IG->Elevated")
62 else:
63 printLog(log, "DETECT SKIP IG->Elevated")
64 needUpdateHeightMap = needUpdateFileDirNoSubdir(log, DatabaseDirectory + "/" + LigoBaseSourceDirectory + "/" + LigoExportHeightmap1, outputIgDir) or needUpdateFileDirNoSubdir(log, DatabaseDirectory + "/" + LigoBaseSourceDirectory + "/" + LigoExportHeightmap2, outputIgDir)
65 if needUpdateHeightMap:
66 printLog(log, "DETECT UPDATE HeightMap->Elevated")
67 else:
68 printLog(log, "DETECT SKIP HeightMap->Elevated")
69 needUpdateLand = needUpdateFileDirNoSubdir(log, DatabaseDirectory + "/" + LigoBaseSourceDirectory + "/" + LigoExportLand, outputIgDir)
70 if needUpdateLand:
71 printLog(log, "DETECT UPDATE Land->Elevated")
72 else:
73 printLog(log, "DETECT SKIP Land->Elevated")
74 if needUpdateIg or needUpdateHeightMap or needUpdateLand:
75 printLog(log, "DETECT DECIDE UPDATE")
76 mkPath(log, inputIgDir)
77 mkPath(log, outputIgDir)
78 mkPath(log, DatabaseDirectory + "/" + LigoBaseSourceDirectory)
80 configFile = configDir + "/ig_elevation.cfg"
81 if os.path.isfile(configFile):
82 os.remove(configFile)
84 printLog(log, "CONFIG " + configFile)
85 cf = open(configFile, "w")
86 cf.write("// ig_elevation.cfg\n")
87 cf.write("\n")
88 cf.write("InputIGDir = \"" + inputIgDir + "\";\n")
89 cf.write("OutputIGDir = \"" + outputIgDir + "\";\n")
90 cf.write("\n")
91 cf.write("CellSize = 160.0;")
92 cf.write("\n")
93 cf.write("HeightMapFile1 = \"" + DatabaseDirectory + "/" + LigoBaseSourceDirectory + "/" + LigoExportHeightmap1 + "\";\n")
94 cf.write("ZFactor1 = " + LigoExportZFactor1 + ";\n")
95 cf.write("HeightMapFile2 = \"" + DatabaseDirectory + "/" + LigoBaseSourceDirectory + "/" + LigoExportHeightmap2 + "\";\n")
96 cf.write("ZFactor2 = " + LigoExportZFactor2 + ";\n")
97 cf.write("ExtendCoords = " + str(LigoExportExtendCoords) + ";\n")
98 cf.write("\n")
99 cf.write("LandFile = \"" + DatabaseDirectory + "/" + LigoBaseSourceDirectory + "/" + LigoExportLand + "\";\n")
100 cf.write("\n")
101 cf.close()
102 subprocess.call([ IgElevation, configFile ])
103 os.remove(configFile)
105 # Copy remaining IG files
106 #BUG:copyFilesLogless(log, inputIgDir, outputIgDir)
107 else:
108 printLog(log, "DETECT DECIDE SKIP")
109 printLog(log, "SKIP *")
111 # Build process
112 if (ContinentLeveldesignWorldDirectory != "") or (len(IgOtherSourceDirectories) > 0):
113 printLog(log, ">>> Prim IG: ON <<<")
114 configFile = configDir + "/prim_export.cfg"
115 if os.path.isfile(configFile):
116 os.remove(configFile)
118 outIgDir = ExportBuildDirectory + "/" + IgElevLandPrimBuildDirectory
119 mkPath(log, outIgDir)
120 zoneWDir = ExportBuildDirectory + "/" + ZoneWeldBuildDirectory
121 mkPath(log, zoneWDir)
122 smallBank = DatabaseDirectory + "/" + TileRootSourceDirectory + "/" + BankTileBankName + ".bank"
123 farBank = ExportBuildDirectory + "/" + FarbankBuildDirectory + "/" + BankTileBankName + MultipleTilesPostfix[0] + ".farbank"
124 displaceDir = DatabaseDirectory + "/" + DisplaceSourceDirectory
125 continentDir = LeveldesignWorldDirectory + "/" + ContinentLeveldesignWorldDirectory
126 mkPath(log, continentDir)
127 formDir = LeveldesignDirectory
128 mkPath(log, LeveldesignDirectory)
129 worldEditorFiles = WorldEditorFilesDirectory
130 mkPath(log, WorldEditorFilesDirectory)
132 printLog(log, "CONFIG " + configFile)
133 cf = open(configFile, "w")
134 cf.write("// prim_export.cfg\n")
135 cf.write("\n")
136 cf.write("OutIGDir = \"" + outIgDir + "\";\n")
137 cf.write("ZoneWDir = \"" + zoneWDir + "\";\n")
138 cf.write("\n")
139 cf.write("SmallBank = \"" + smallBank + "\";\n")
140 cf.write("FarBank = \"" + farBank + "\";\n")
141 cf.write("DisplaceDir = \"" + displaceDir + "\";\n")
142 cf.write("\n")
143 cf.write("CellSize = 160.0;")
144 cf.write("\n")
145 cf.write("PrimDirs = {\n")
146 cf.write("\t\"" + continentDir + "\", \n")
147 for dir in IgPrimitiveSourceDirectories:
148 mkPath(log, DatabaseDirectory + "/" + dir)
149 cf.write("\t\"" + DatabaseDirectory + "/" + dir + "\", \n")
150 cf.write("};\n")
151 cf.write("\n")
152 cf.write("FormDir = \"" + formDir + "\";\n")
153 cf.write("WorldEditorFiles = \"" + worldEditorFiles + "\";\n")
154 cf.write("\n")
155 cf.close()
156 subprocess.call([ PrimExport, configFile ])
157 os.remove(configFile)
159 igElevation(ExportBuildDirectory + "/" + LigoIgLandBuildDirectory, ExportBuildDirectory + "/" + IgElevLandLigoBuildDirectory)
161 igElevation(ExportBuildDirectory + "/" + IgStaticLandExportDirectory, ExportBuildDirectory + "/" + IgElevLandStaticBuildDirectory)
163 printLog(log, ">>> Merge land IGs <<<")
164 mkPath(log, ExportBuildDirectory + "/" + IgTempLandMergeBuildDirectory)
165 removeFilesRecursive(log, ExportBuildDirectory + "/" + IgTempLandMergeBuildDirectory)
167 mkPath(log, ExportBuildDirectory + "/" + IgLandBuildDirectory)
169 mkPath(log, ExportBuildDirectory + "/" + IgElevLandPrimBuildDirectory)
170 mkPath(log, ExportBuildDirectory + "/" + IgElevLandLigoBuildDirectory)
171 mkPath(log, ExportBuildDirectory + "/" + IgElevLandStaticBuildDirectory)
172 igFilesPrim = findFiles(log, ExportBuildDirectory + "/" + IgElevLandPrimBuildDirectory, "", ".ig")
173 igFilesLigo = findFiles(log, ExportBuildDirectory + "/" + IgElevLandLigoBuildDirectory, "", ".ig")
174 igFilesStatic = findFiles(log, ExportBuildDirectory + "/" + IgElevLandStaticBuildDirectory, "", ".ig")
175 igFilesAll = [ ]
176 for igFile in igFilesPrim:
177 if not igFile in igFilesAll:
178 igFilesAll += [ igFile ]
179 for igFile in igFilesLigo:
180 if not igFile in igFilesAll:
181 igFilesAll += [ igFile ]
182 for igFile in igFilesStatic:
183 if not igFile in igFilesAll:
184 igFilesAll += [ igFile ]
185 igFilesAll.sort()
186 for igFile in igFilesAll:
187 primIgFile = ExportBuildDirectory + "/" + IgElevLandPrimBuildDirectory + "/" + igFile
188 ligoIgFile = ExportBuildDirectory + "/" + IgElevLandLigoBuildDirectory + "/" + igFile
189 staticIgFile = ExportBuildDirectory + "/" + IgElevLandStaticBuildDirectory + "/" + igFile
190 tempIgFile = ExportBuildDirectory + "/" + IgTempLandMergeBuildDirectory + "/" + igFile
191 outIgFile = ExportBuildDirectory + "/" + IgLandBuildDirectory + "/" + igFile
192 activeFile = ""
193 needsUpdate = 0
194 sourceTools = ""
195 if igFile in igFilesPrim:
196 if needUpdate(log, primIgFile, outIgFile):
197 needsUpdate = 1
198 if not needsUpdate == 1 and igFile in igFilesLigo:
199 if needUpdate(log, ligoIgFile, outIgFile):
200 needsUpdate = 1
201 if not needsUpdate == 1 and igFile in igFilesStatic:
202 if needUpdate(log, staticIgFile, outIgFile):
203 needsUpdate = 1
204 if needsUpdate == 1:
205 if os.path.isfile(outIgFile):
206 os.remove(outIgFile)
207 if igFile in igFilesPrim:
208 sourceTools += " [Prim]"
209 activeFile = primIgFile
210 if igFile in igFilesLigo:
211 if activeFile == "":
212 activeFile = ligoIgFile
213 else:
214 sourceTools += " [Ligo]"
215 subprocess.call([ IgAdd, tempIgFile, ligoIgFile, activeFile ])
216 activeFile = tempIgFile
217 if igFile in igFilesStatic:
218 if activeFile == "":
219 activeFile = staticIgFile
220 else:
221 sourceTools += " [Static]"
222 subprocess.call([ IgAdd, outIgFile, staticIgFile, activeFile ])
223 activeFile = outIgFile
224 else:
225 shutil.copy(activeFile, outIgFile)
226 printLog(log, "MERGE " + igFile + sourceTools)
227 else:
228 printLog(log, "SKIP " + igFile)
230 # Remove temporary land IGs
231 printLog(log, ">>> Remove temporary land IGs <<<")
232 mkPath(log, ExportBuildDirectory + "/" + IgTempLandMergeBuildDirectory)
233 removeFilesRecursive(log, ExportBuildDirectory + "/" + IgTempLandMergeBuildDirectory)
235 # Remove outdated land IGs
236 printLog(log, ">>> Remove outdated land IGs <<<")
237 igFilesOut = findFiles(log, ExportBuildDirectory + "/" + IgLandBuildDirectory, "", ".ig")
238 for igFile in igFilesOut:
239 if not igFile in igFilesAll:
240 printLog(log, "RM " + ExportBuildDirectory + "/" + IgLandBuildDirectory + "/" + igFile)
241 os.remove(ExportBuildDirectory + "/" + IgLandBuildDirectory + "/" + igFile)
243 # Verify land IGs
244 printLog(log, ">>> Verify land IGs <<<")
245 for igFile in igFilesAll:
246 if not igFile in igFilesOut:
247 printLog(log, "MISSING " + igFile)
249 # Write land IGs TXT
250 printLog(log, ">>> Write land IGs TXT <<<")
251 igTxtFile = ExportBuildDirectory + "/" + IgLandBuildDirectory + "/" + LandscapeName + "_ig.txt"
252 if needUpdateDirNoSubdirFile(log, ExportBuildDirectory + "/" + IgLandBuildDirectory, igTxtFile):
253 printLog(log, "WRITE " + ExportBuildDirectory + "/" + IgLandBuildDirectory + "/" + LandscapeName + "_ig.txt")
254 if os.path.isfile(igTxtFile):
255 os.remove(igTxtFile)
256 igTxt = open(igTxtFile, "w")
257 for igFile in igFilesAll:
258 igTxt.write(igFile + "\n")
259 igTxt.close()
260 else:
261 printLog(log, "SKIP *")
263 # Merge other IGs
264 printLog(log, ">>> Merge other IGs <<<") # (not true merge, since not necesserary)
265 mkPath(log, ExportBuildDirectory + "/" + IgStaticOtherExportDirectory)
266 mkPath(log, ExportBuildDirectory + "/" + LigoIgOtherBuildDirectory)
267 mkPath(log, ExportBuildDirectory + "/" + IgOtherBuildDirectory)
268 # copyFilesExtNoTreeIfNeeded(log, ExportBuildDirectory + "/" + IgStaticOtherExportDirectory, ExportBuildDirectory + "/" + IgOtherBuildDirectory, ".ig")
269 igElevation(ExportBuildDirectory + "/" + IgStaticOtherExportDirectory, ExportBuildDirectory + "/" + IgOtherBuildDirectory)
270 copyFilesExtNoTreeIfNeeded(log, ExportBuildDirectory + "/" + LigoIgOtherBuildDirectory, ExportBuildDirectory + "/" + IgOtherBuildDirectory, ".ig")
272 log.close()
275 # end of file