Fix rbank water mapping

develop
kaetemi 4 years ago
parent d9d9c6e1e6
commit a1f1bd888c

@ -55,6 +55,7 @@ printLog(log, "")
# Build rbank bbox # Build rbank bbox
printLog(log, ">>> Build rbank bbox <<<") printLog(log, ">>> Build rbank bbox <<<")
tempBbox = ExportBuildDirectory + "/" + RbankBboxBuildDirectory + "/temp.bbox" tempBbox = ExportBuildDirectory + "/" + RbankBboxBuildDirectory + "/temp.bbox"
rebuiltBbox = False
if BuildIgBoxes == "": if BuildIgBoxes == "":
toolLogFail(log, BuildIgBoxesTool, ToolSuffix) toolLogFail(log, BuildIgBoxesTool, ToolSuffix)
else: else:
@ -70,6 +71,7 @@ else:
else: else:
printLog(log, "DETECT SKIP Shape->Bbox") printLog(log, "DETECT SKIP Shape->Bbox")
if needUpdateIg or needUpdateShape: if needUpdateIg or needUpdateShape:
rebuiltBbox = True
printLog(log, "DETECT DECIDE UPDATE") printLog(log, "DETECT DECIDE UPDATE")
cf = open("build_ig_boxes.cfg", "w") cf = open("build_ig_boxes.cfg", "w")
cf.write("\n") cf.write("\n")
@ -204,23 +206,35 @@ elif ExecTimeout == "":
toolLogFail(log, ExecTimeoutTool, ToolSuffix) toolLogFail(log, ExecTimeoutTool, ToolSuffix)
else: else:
zonefiles = findFiles(log, ExportBuildDirectory + "/" + ZoneWeldBuildDirectory, "", ".zonew") zonefiles = findFiles(log, ExportBuildDirectory + "/" + ZoneWeldBuildDirectory, "", ".zonew")
zonesToBuild = []
for zonefile in zonefiles: for zonefile in zonefiles:
zone = os.path.basename(zonefile)[0:-len(".zonew")] zone = os.path.basename(zonefile)[0:-len(".zonew")]
lr1 = ExportBuildDirectory + "/" + RbankSmoothBuildDirectory + "/" + zone + ".lr" lr1 = ExportBuildDirectory + "/" + RbankSmoothBuildDirectory + "/" + zone + ".lr"
nearzones = subprocess.Popen([ GetNeighbors, zone ], stdout = subprocess.PIPE).communicate()[0].strip().split(" ") nearzones = subprocess.Popen([ GetNeighbors, zone ], stdout = subprocess.PIPE).communicate()[0].strip().split(" ")
printLog(log, "ZONE " + zone + ": " + str(nearzones)) printLog(log, "ZONE " + zone + ": " + str(nearzones))
zone_to_build = 0 zoneToBuild = 0
for nearzone in nearzones: for nearzone in nearzones:
sourcePath = ExportBuildDirectory + "/" + ZoneWeldBuildDirectory + "/" + nearzone + ".zonew" sourcePath = ExportBuildDirectory + "/" + ZoneWeldBuildDirectory + "/" + nearzone + ".zonew"
if (os.path.isfile(sourcePath)): if (os.path.isfile(sourcePath)):
if (needUpdate(log, sourcePath, lr1)): if (rebuiltBbox or needUpdate(log, sourcePath, lr1)):
zone_to_build = 1 zoneToBuild = 1
zonesToBuild.append(os.path.basename(zonefile))
sourcePath = ExportBuildDirectory + "/" + ZoneWeldBuildDirectory + "/" + zone + ".zonew" sourcePath = ExportBuildDirectory + "/" + ZoneWeldBuildDirectory + "/" + zone + ".zonew"
if zone_to_build: if zoneToBuild:
printLog(log, sourcePath + " -> " + lr1) printLog(log, sourcePath + " -> " + lr1)
subprocess.call([ ExecTimeout, str(RbankBuildTesselTimeout), BuildRbank, "-c", "-P", "-g", os.path.basename(zonefile) ]) # subprocess.call([ ExecTimeout, str(RbankBuildTesselTimeout), BuildRbank, "-c", "-P", "-g", os.path.basename(zonefile) ])
else: else:
printLog(log, "SKIP " + lr1) printLog(log, "SKIP " + lr1)
while len(zonesToBuild) > 0:
processCommand = [ ExecTimeout, str(RbankBuildTesselTimeout), BuildRbank, "-c", "-P", "-g" ]
processCommand.extend(zonesToBuild[:min(len(zonesToBuild), 64)])
if len(zonesToBuild) > 64:
zonesToBuild = zonesToBuild[64:]
else:
zonesToBuild = []
print processCommand
print len(processCommand)
subprocess.call(processCommand)
printLog(log, "") printLog(log, "")
printLog(log, ">>> Detect modifications to rebuild lr <<<") printLog(log, ">>> Detect modifications to rebuild lr <<<")
@ -245,7 +259,7 @@ if needUpdateBboxRbank:
else: else:
printLog(log, "DETECT SKIP Lr->Rbank") printLog(log, "DETECT SKIP Lr->Rbank")
if needUpdateCmbLr or needUpdateCmbRbank or needUpdateLrRbank or needUpdateBboxRbank: if rebuiltBbox or needUpdateCmbLr or needUpdateCmbRbank or needUpdateLrRbank or needUpdateBboxRbank:
printLog(log, "DETECT DECIDE UPDATE") printLog(log, "DETECT DECIDE UPDATE")
printLog(log, ">>> Build rbank process global <<<") # This generates temp lr files. TODO: Check if the LR changed? printLog(log, ">>> Build rbank process global <<<") # This generates temp lr files. TODO: Check if the LR changed?
if BuildRbank == "": if BuildRbank == "":

@ -336,13 +336,19 @@ void CPrimChecker::render(CPrimZone *zone, uint8 bits)
*/ */
void CPrimChecker::render(const CPolygon &poly, uint16 value) void CPrimChecker::render(const CPolygon &poly, uint16 value)
{ {
static const sint centerOffset = 20480; // zones are max 40960
CPolygon polyOffset = poly;
for (ptrdiff_t i = 0; i < (ptrdiff_t)polyOffset.Vertices.size(); ++i)
// center to computeBorders range (-32k to 32k)
polyOffset.Vertices[i] += CVector(-centerOffset, centerOffset, 0);
list<CPolygon> convex; list<CPolygon> convex;
// divide poly in convex polys // divide poly in convex polys
if (!poly.toConvexPolygons(convex, CMatrix::Identity)) if (!polyOffset.toConvexPolygons(convex, CMatrix::Identity))
{ {
convex.clear(); convex.clear();
CPolygon reverse = poly; CPolygon reverse = polyOffset;
std::reverse(reverse.Vertices.begin(), reverse.Vertices.end()); std::reverse(reverse.Vertices.begin(), reverse.Vertices.end());
if (!reverse.toConvexPolygons(convex, CMatrix::Identity)) if (!reverse.toConvexPolygons(convex, CMatrix::Identity))
return; return;
@ -357,6 +363,7 @@ void CPrimChecker::render(const CPolygon &poly, uint16 value)
sint ymin; sint ymin;
convex2d.computeBorders(rasterized, ymin); convex2d.computeBorders(rasterized, ymin);
ymin -= centerOffset; // uncenter
sint dy; sint dy;
for (dy=0; dy<(sint)rasterized.size(); ++dy) for (dy=0; dy<(sint)rasterized.size(); ++dy)
@ -365,19 +372,19 @@ void CPrimChecker::render(const CPolygon &poly, uint16 value)
for (x=rasterized[dy].first; x<=rasterized[dy].second; ++x) for (x=rasterized[dy].first; x<=rasterized[dy].second; ++x)
{ {
uint8 prevBits = _Grid.get((uint)x, (uint)(ymin+dy)); uint8 prevBits = _Grid.get((uint)x + centerOffset, (uint)(ymin + dy));
// only set if there was not a water shape there or if previous was lower // only set if there was not a water shape there or if previous was lower
if ((prevBits & Water) != 0) if ((prevBits & Water) != 0)
{ {
uint16 prevWS = _Grid.index((uint)x, (uint)(ymin+dy)); uint16 prevWS = _Grid.index((uint)x + centerOffset, (uint)(ymin + dy));
if (_WaterHeight[value] < _WaterHeight[prevWS]) if (_WaterHeight[value] < _WaterHeight[prevWS])
continue; continue;
} }
_Grid.index((uint)x, (uint)(ymin+dy), value); _Grid.index((uint)x + centerOffset, (uint)(ymin + dy), value);
_Grid.set((uint)x, (uint)(ymin+dy), Water); _Grid.set((uint)x + centerOffset, (uint)(ymin + dy), Water);
} }
} }
} }
@ -389,13 +396,19 @@ void CPrimChecker::render(const CPolygon &poly, uint16 value)
*/ */
void CPrimChecker::renderBits(const CPolygon &poly, uint8 bits) void CPrimChecker::renderBits(const CPolygon &poly, uint8 bits)
{ {
static const sint centerOffset = 20480; // zones are max 40960
CPolygon polyOffset = poly;
for (ptrdiff_t i = 0; i < (ptrdiff_t)polyOffset.Vertices.size(); ++i)
// center to computeBorders range (-32k to 32k)
polyOffset.Vertices[i] += CVector(-centerOffset, centerOffset, 0);
list<CPolygon> convex; list<CPolygon> convex;
// divide poly in convex polys // divide poly in convex polys
if (!poly.toConvexPolygons(convex, CMatrix::Identity)) if (!polyOffset.toConvexPolygons(convex, CMatrix::Identity))
{ {
convex.clear(); convex.clear();
CPolygon reverse = poly; CPolygon reverse = polyOffset;
std::reverse(reverse.Vertices.begin(), reverse.Vertices.end()); std::reverse(reverse.Vertices.begin(), reverse.Vertices.end());
if (!reverse.toConvexPolygons(convex, CMatrix::Identity)) if (!reverse.toConvexPolygons(convex, CMatrix::Identity))
return; return;
@ -410,6 +423,7 @@ void CPrimChecker::renderBits(const CPolygon &poly, uint8 bits)
sint ymin; sint ymin;
convex2d.computeBorders(rasterized, ymin); convex2d.computeBorders(rasterized, ymin);
ymin -= centerOffset; // uncenter
sint dy; sint dy;
for (dy=0; dy<(sint)rasterized.size(); ++dy) for (dy=0; dy<(sint)rasterized.size(); ++dy)
@ -418,7 +432,7 @@ void CPrimChecker::renderBits(const CPolygon &poly, uint8 bits)
for (x=rasterized[dy].first; x<=rasterized[dy].second; ++x) for (x=rasterized[dy].first; x<=rasterized[dy].second; ++x)
{ {
_Grid.set((uint)x, (uint)(ymin+dy), bits); _Grid.set((uint)x + centerOffset, (uint)(ymin + dy), bits);
} }
} }
} }

Loading…
Cancel
Save