5 # \date 2010-05-24 13:42GMT
6 # \author Jan Boon (Kaetemi)
7 # Python port of game data build pipeline.
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"):
32 log
= open("log.log", "w")
34 from buildsite
import *
37 from directories
import *
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())))
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")
61 printLog(log
, "DETECT UPDATE IG->Elevated")
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")
68 printLog(log
, "DETECT SKIP HeightMap->Elevated")
69 needUpdateLand
= needUpdateFileDirNoSubdir(log
, DatabaseDirectory
+ "/" + LigoBaseSourceDirectory
+ "/" + LigoExportLand
, outputIgDir
)
71 printLog(log
, "DETECT UPDATE Land->Elevated")
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
):
84 printLog(log
, "CONFIG " + configFile
)
85 cf
= open(configFile
, "w")
86 cf
.write("// ig_elevation.cfg\n")
88 cf
.write("InputIGDir = \"" + inputIgDir
+ "\";\n")
89 cf
.write("OutputIGDir = \"" + outputIgDir
+ "\";\n")
91 cf
.write("CellSize = 160.0;")
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")
99 cf
.write("LandFile = \"" + DatabaseDirectory
+ "/" + LigoBaseSourceDirectory
+ "/" + LigoExportLand
+ "\";\n")
102 subprocess
.call([ IgElevation
, configFile
])
103 os
.remove(configFile
)
105 # Copy remaining IG files
106 #BUG:copyFilesLogless(log, inputIgDir, outputIgDir)
108 printLog(log
, "DETECT DECIDE SKIP")
109 printLog(log
, "SKIP *")
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")
136 cf
.write("OutIGDir = \"" + outIgDir
+ "\";\n")
137 cf
.write("ZoneWDir = \"" + zoneWDir
+ "\";\n")
139 cf
.write("SmallBank = \"" + smallBank
+ "\";\n")
140 cf
.write("FarBank = \"" + farBank
+ "\";\n")
141 cf
.write("DisplaceDir = \"" + displaceDir
+ "\";\n")
143 cf
.write("CellSize = 160.0;")
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")
152 cf
.write("FormDir = \"" + formDir
+ "\";\n")
153 cf
.write("WorldEditorFiles = \"" + worldEditorFiles
+ "\";\n")
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")
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
]
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
195 if igFile
in igFilesPrim
:
196 if needUpdate(log
, primIgFile
, outIgFile
):
198 if not needsUpdate
== 1 and igFile
in igFilesLigo
:
199 if needUpdate(log
, ligoIgFile
, outIgFile
):
201 if not needsUpdate
== 1 and igFile
in igFilesStatic
:
202 if needUpdate(log
, staticIgFile
, outIgFile
):
205 if os
.path
.isfile(outIgFile
):
207 if igFile
in igFilesPrim
:
208 sourceTools
+= " [Prim]"
209 activeFile
= primIgFile
210 if igFile
in igFilesLigo
:
212 activeFile
= ligoIgFile
214 sourceTools
+= " [Ligo]"
215 subprocess
.call([ IgAdd
, tempIgFile
, ligoIgFile
, activeFile
])
216 activeFile
= tempIgFile
217 if igFile
in igFilesStatic
:
219 activeFile
= staticIgFile
221 sourceTools
+= " [Static]"
222 subprocess
.call([ IgAdd
, outIgFile
, staticIgFile
, activeFile
])
223 activeFile
= outIgFile
225 shutil
.copy(activeFile
, outIgFile
)
226 printLog(log
, "MERGE " + igFile
+ sourceTools
)
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
)
244 printLog(log
, ">>> Verify land IGs <<<")
245 for igFile
in igFilesAll
:
246 if not igFile
in igFilesOut
:
247 printLog(log
, "MISSING " + igFile
)
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
):
256 igTxt
= open(igTxtFile
, "w")
257 for igFile
in igFilesAll
:
258 igTxt
.write(igFile
+ "\n")
261 printLog(log
, "SKIP *")
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")