Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / build_gamedata / processes / map / 2_build.py
blob4a9477b8abc01d4c4ca7e30977339677a712425e
1 #!/usr/bin/python
2 #
3 # \file 2_build.py
4 # \brief Build map
5 # \date 2009-03-10 13:13GMT
6 # \author Jan Boon (Kaetemi)
7 # Python port of game data build pipeline.
8 # Build map
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 map")
42 printLog(log, "-------")
43 printLog(log, time.strftime("%Y-%m-%d %H:%MGMT", time.gmtime(time.time())))
44 printLog(log, "")
46 # Find tools
47 TgaToDds = findTool(log, ToolDirectories, TgaToDdsTool, ToolSuffix)
48 ExecTimeout = findTool(log, ToolDirectories, ExecTimeoutTool, ToolSuffix)
49 PanoplyMaker = findTool(log, ToolDirectories, PanoplyMakerTool, ToolSuffix)
50 HlsBankMaker = findTool(log, ToolDirectories, HlsBankMakerTool, ToolSuffix)
51 printLog(log, "")
53 buildPanoplyTagPath = ExportBuildDirectory + "/" + MapTagBuildDirectory + "/build_panoply.tag"
54 buildCompressTagPath = ExportBuildDirectory + "/" + MapTagBuildDirectory + "/build_compress.tag"
56 if MapPanoplyFileList != None:
57 printLog(log, ">>> Panoply build <<<")
58 mkPath(log, ExportBuildDirectory + "/" + MapTagBuildDirectory)
59 directoriesCheck = [ ]
60 for panoplyCfg in MapPanoplySourceDirectories:
61 directoriesCheck += [ panoplyCfg[2] ]
62 directoriesCheck += [ panoplyCfg[3] ]
63 if (needUpdateMultiDirNoSubdirFile(log, DatabaseDirectory, directoriesCheck, buildPanoplyTagPath)):
64 mkPath(log, ActiveProjectDirectory + "/generated")
65 mkPath(log, ExportBuildDirectory + "/" + MapPanoplyBuildDirectory)
66 mkPath(log, ExportBuildDirectory + "/" + MapPanoplyHlsInfoBuildDirectory)
67 mkPath(log, ExportBuildDirectory + "/" + MapPanoplyCacheBuildDirectory)
68 printLog(log, "")
69 printLog(log, ">>> Move panoply and hls to cache <<<")
70 removeFilesDirsRecursive(log, ExportBuildDirectory + "/" + MapPanoplyCacheBuildDirectory)
71 moveDir(log, ExportBuildDirectory + "/" + MapPanoplyBuildDirectory, ExportBuildDirectory + "/" + MapPanoplyCacheBuildDirectory)
72 mkPath(log, ExportBuildDirectory + "/" + MapPanoplyBuildDirectory)
73 moveFilesNoSubdir(log, ExportBuildDirectory + "/" + MapPanoplyHlsInfoBuildDirectory, ExportBuildDirectory + "/" + MapPanoplyCacheBuildDirectory)
74 printLog(log, "")
75 for panoplyCfg in MapPanoplySourceDirectories:
76 printLog(log, ">>> Panoply " + panoplyCfg[1] + " <<<")
77 mkPath(log, DatabaseDirectory + "/" + panoplyCfg[2])
78 mkPath(log, DatabaseDirectory + "/" + panoplyCfg[3])
79 cfg = open(ActiveProjectDirectory + "/generated/current_panoply.cfg", "w")
80 cfgCommon = open(ActiveProjectDirectory + "/" + panoplyCfg[0], "r")
81 cfgRace = open(ActiveProjectDirectory + "/" + panoplyCfg[1], "r")
82 cfg.write("\n")
83 cfg.write("// CURRENT PANOPLY CONFIGURATION\n")
84 cfg.write("\n")
85 cfg.write("input_path = \"" + DatabaseDirectory + "/" + panoplyCfg[2] + "\";\n")
86 cfg.write("additionnal_paths = \"" + DatabaseDirectory + "/" + panoplyCfg[3] + "\";\n")
87 cfg.write("output_path = \"" + ExportBuildDirectory + "/" + MapPanoplyBuildDirectory + "\";\n")
88 cfg.write("hls_info_path = \"" + ExportBuildDirectory + "/" + MapPanoplyHlsInfoBuildDirectory + "\";\n")
89 cfg.write("cache_path = \"" + ExportBuildDirectory + "/" + MapPanoplyCacheBuildDirectory + "\";\n")
90 cfg.write("\n")
91 cfg.write("/////////////////////////////////////////////\n")
92 cfg.write("\n")
93 for line in cfgCommon:
94 cfg.write(line)
95 for line in cfgRace:
96 cfg.write(line)
97 cfg.close()
98 cfgCommon.close()
99 cfgRace.close()
100 subprocess.call([ PanoplyMaker, ActiveProjectDirectory + "/generated/current_panoply.cfg" ])
101 printLog(log, "")
102 tagFile = open(buildPanoplyTagPath, "w")
103 tagFile.write(time.strftime("%Y-%m-%d %H:%MGMT", time.gmtime(time.time())) + "\n")
104 tagFile.close()
105 else:
106 printLog(log, "SKIP *.*")
107 printLog(log, "")
109 printLog(log, ">>> Compress TGA and PNG maps to DDS <<<")
110 if TgaToDds == "":
111 toolLogFail(log, TgaToDdsTool, ToolSuffix)
112 elif ExecTimeout == "":
113 toolLogFail(log, ExecTimeoutTool, ToolSuffix)
114 else:
115 destPath = ExportBuildDirectory + "/" + MapBuildDirectory
116 mkPath(log, destPath)
117 sourcePaths = [ ExportBuildDirectory + "/" + MapExportDirectory ]
118 writeTag = 0
119 if MapPanoplyFileList != None:
120 if needUpdate(log, buildPanoplyTagPath, buildCompressTagPath):
121 sourcePaths += [ ExportBuildDirectory + "/" + MapPanoplyBuildDirectory ]
122 else:
123 printLog(log, "SKIP " + ExportBuildDirectory + "/" + MapPanoplyBuildDirectory + "/*.*")
124 for sourcePath in sourcePaths:
125 mkPath(log, sourcePath)
126 files = os.listdir(sourcePath)
127 len_tga_png = len(".tga")
128 len_dds = len(".dds")
129 for fileName in files:
130 if isLegalFileName(fileName):
131 sourceFile = sourcePath + "/" + fileName
132 if os.path.isfile(sourceFile):
133 if (fileName[-len_tga_png:].lower() == ".tga") or (fileName[-len_tga_png:].lower() == ".png"):
134 destFile = destPath + "/" + os.path.basename(fileName)[0:-len_tga_png] + ".dds"
135 if needUpdateLogRemoveDest(log, sourceFile, destFile):
136 subprocess.call([ ExecTimeout, str(MapsBuildTimeout), TgaToDds, sourceFile, "-o", destFile, "-m", "-r" + str(ReduceBitmapFactor) ])
137 writeTag = 1
138 elif fileName[-len_dds:].lower() == ".dds":
139 copyFileIfNeeded(log, sourceFile, destPath + "/" + os.path.basename(fileName))
140 writeTag = 1
141 elif not os.path.isdir(sourceFile):
142 printLog(log, "FAIL ?! file not dir or file ?! " + sourceFile)
143 if writeTag:
144 tagFile = open(buildCompressTagPath, "w")
145 tagFile.write(time.strftime("%Y-%m-%d %H:%MGMT", time.gmtime(time.time())) + "\n")
146 tagFile.close()
147 printLog(log, "")
149 if MapHlsBankFileName != None:
150 printLog(log, ">>> Build the HLSBank <<<")
151 if HlsBankMaker == "":
152 toolLogFail(log, HlsBankMakerTool, ToolSuffix)
153 else:
154 mkPath(log, ExportBuildDirectory + "/" + MapPanoplyHlsInfoBuildDirectory)
155 mkPath(log, ExportBuildDirectory + "/" + MapPanoplyHlsBankBuildDirectory)
156 hlsBankPath = ExportBuildDirectory + "/" + MapPanoplyHlsBankBuildDirectory + "/" + MapHlsBankFileName
157 if (needUpdate(log, buildPanoplyTagPath, hlsBankPath) or needUpdate(log, buildCompressTagPath, hlsBankPath)):
158 if os.path.isfile(hlsBankPath):
159 os.remove(hlsBankPath)
160 subprocess.call([ HlsBankMaker, ExportBuildDirectory + "/" + MapPanoplyHlsInfoBuildDirectory, hlsBankPath ])
161 else:
162 printLog(log,"SKIP " + hlsBankPath)
163 printLog(log, "")
165 log.close()
168 # end of file