@@ -488,13 +488,11 @@ var
488488 region: TRSMapRegion;
489489 i, j, k, plane, regionCount: Integer;
490490 maps, heightmaps, collisionmaps: TImageArray;
491- topLeft, btmRight: TPoint;
491+ topLeft, btmRight, offset : TPoint;
492492 graphs: array of TWebGraph;
493- boxes: TBoxArray;
493+ boxes, oldRegions : TBoxArray;
494494 newMap, newHeightmap, newCollision: TImage;
495- existingBox: TBox;
496- oldRegions: array of TBox;
497- offset: TPoint;
495+ oldMapBox: TBox;
498496begin
499497 if Self.Downscale <> downscale then
500498 raise GetDebugLn('MapLoader', 'Cannot add chunks with different downscale value');
@@ -529,7 +527,6 @@ begin
529527 maps += Self.GetMap(region.Chunks, plane, ERSMap.NORMAL);
530528 maps.Last.Pad(padding);
531529
532- //heightmap are shared accross planes
533530 heightmaps += Self.GetMap(region.Chunks, plane, ERSMap.HEIGHT);
534531 heightmaps.Last.Pad(padding);
535532
@@ -544,18 +541,20 @@ begin
544541 Self.Regions += region;
545542 end;
546543
547- if Length(Self.Regions) = regionCount then Exit;
544+ if Length(Self.Regions) = regionCount then
545+ Exit;
548546
549547 SetLength(oldRegions, regionCount);
550548 for i := 0 to regionCount - 1 do
549+ begin
551550 oldRegions[i] := Self.Regions[i].Region;
552-
553- for i := 0 to regionCount - 1 do
554551 boxes.Insert(Self.Regions[i].Region, i);
552+ end;
555553
556554 boxes := boxes.Pack();
557- existingBox := Self.MapBox;
555+ oldMapBox := Self.MapBox;
558556 Self.MapBox := [];
557+
559558 for i := 0 to High(boxes) do
560559 begin
561560 Self.Regions[i].Region := boxes[i];
@@ -566,97 +565,74 @@ begin
566565 newHeightmap := new TImage(Self.MapBox.Width, Self.MapBox.Height);
567566 newCollision := new TImage(Self.MapBox.Width, Self.MapBox.Height);
568567
569- if (existingBox.Width > 0) and (existingBox.Height > 0) then
568+ for i := 0 to regionCount - 1 do
570569 begin
571- for i := 0 to regionCount - 1 do
572- begin
573- newMap.DrawImage(Self.Map.Copy(oldRegions[i]), Self.Regions[i].Region.TopLeft);
574- if Assigned(Self.Heightmap) then
575- newHeightmap.DrawImage(Self.Heightmap.Copy(oldRegions[i]), Self.Regions[i].Region.TopLeft);
576- newCollision.DrawImage(Self.Collision.Copy(oldRegions[i]), Self.Regions[i].Region.TopLeft);
577- end;
570+ topLeft := Self.Regions[i].Region.TopLeft;
571+ newMap.DrawImage(Self.Map.Copy(oldRegions[i]), topLeft);
572+ newHeightmap.DrawImage(Self.Heightmap.Copy(oldRegions[i]), topLeft);
573+ newCollision.DrawImage(Self.Collision.Copy(oldRegions[i]), topLeft);
578574 end;
579575
580576 for i := regionCount to High(Self.Regions) do
581577 begin
582- newMap.DrawImage(maps[i - regionCount], Self.Regions[i].Region.TopLeft);
583- if i - regionCount < Length(heightmaps) then
584- newHeightmap.DrawImage(heightmaps[i - regionCount], Self.Regions[i].Region.TopLeft);
585- newCollision.DrawImage(collisionmaps[i - regionCount], Self.Regions[i].Region.TopLeft);
578+ j := i - regionCount;
579+ topLeft := Self.Regions[i].Region.TopLeft;
580+ newMap.DrawImage(maps[j], topLeft);
581+ newHeightmap.DrawImage(heightmaps[j], topLeft);
582+ newCollision.DrawImage(collisionmaps[j], topLeft);
586583 end;
587584
588585 Self.Map := newMap;
589- if Length(heightmaps) > 0 then
590- Self.Heightmap := newHeightmap;
586+ Self.Heightmap := newHeightmap;
591587 Self.Collision := newCollision;
592588
593589 Self.HalfMap := Self.Map.Downsample(2);
594590 Self.DownscaledMap := Self.Map.Downsample(Self.Downscale);
595591
596- if not WebGraphGenerator.Disabled then
592+ if WebGraphGenerator.Disabled then Exit;
593+
594+ for i := 0 to regionCount - 1 do
597595 begin
598- for i := 0 to regionCount - 1 do
599- begin
600- offset := Self.Regions[i].Region.TopLeft - oldRegions[i].TopLeft;
601-
602- if offset <> [0, 0] then
603- begin
604- for j := 0 to High(Self.Graph.Nodes) do
605- if Self.Graph.Nodes[j] in oldRegions[i] then
606- Self.Graph.Nodes[j] := Self.Graph.Nodes[j] + offset;
607-
608- for j := 0 to High(Self.Graph.WalkableSpace) do
609- if Self.Graph.WalkableSpace[j] in oldRegions[i] then
610- Self.Graph.WalkableSpace[j] := Self.Graph.WalkableSpace[j] + offset;
611-
612- for j := 0 to High(Self.Graph.WalkableClusters) do
613- for k := 0 to High(Self.Graph.WalkableClusters[j]) do
614- if Self.Graph.WalkableClusters[j][k] in oldRegions[i] then
615- Self.Graph.WalkableClusters[j][k] := Self.Graph.WalkableClusters[j][k] + offset;
616-
617- for j := 0 to High(Self.Graph.ObjectClusters) do
618- for k := 0 to High(Self.Graph.ObjectClusters[j]) do
619- if Self.Graph.ObjectClusters[j][k] in oldRegions[i] then
620- Self.Graph.ObjectClusters[j][k] := Self.Graph.ObjectClusters[j][k] + offset;
621-
622- for j := 0 to High(Self.Graph.Doors) do
623- if Self.Graph.Doors[j].Center in oldRegions[i] then
624- begin
625- Self.Graph.Doors[j].Before := Self.Graph.Doors[j].Before + offset;
626- Self.Graph.Doors[j].After := Self.Graph.Doors[j].After + offset;
627- Self.Graph.Doors[j].Center := Self.Graph.Doors[j].Center + offset;
628- end;
629- end;
630- end;
596+ offset := Self.Regions[i].Region.TopLeft - oldRegions[i].TopLeft;
631597
632- for i := 0 to High(graphs) do
598+ if offset <> [0, 0] then
633599 begin
634- offset := Self.Regions[regionCount + i].Region.TopLeft;
635-
636- graphs[i].Nodes := graphs[i].Nodes.Offset(offset);
637- graphs[i].WalkableSpace := graphs[i].WalkableSpace.Offset(offset);
638-
639- for j := 0 to High(graphs[i].WalkableClusters) do
640- graphs[i].WalkableClusters[j] := graphs[i].WalkableClusters[j].Offset(offset);
641-
642- for j := 0 to High(graphs[i].ObjectClusters) do
643- graphs[i].ObjectClusters[j] := graphs[i].ObjectClusters[j].Offset(offset);
600+ for j := 0 to High(Self.Graph.Nodes) do
601+ if Self.Graph.Nodes[j] in oldRegions[i] then
602+ Self.Graph.Nodes[j] := Self.Graph.Nodes[j] + offset;
603+
604+ for j := 0 to High(Self.Graph.WalkableSpace) do
605+ if Self.Graph.WalkableSpace[j] in oldRegions[i] then
606+ Self.Graph.WalkableSpace[j] := Self.Graph.WalkableSpace[j] + offset;
607+
608+ for j := 0 to High(Self.Graph.WalkableClusters) do
609+ for k := 0 to High(Self.Graph.WalkableClusters[j]) do
610+ if Self.Graph.WalkableClusters[j][k] in oldRegions[i] then
611+ Self.Graph.WalkableClusters[j][k] := Self.Graph.WalkableClusters[j][k] + offset;
612+
613+ for j := 0 to High(Self.Graph.ObjectClusters) do
614+ for k := 0 to High(Self.Graph.ObjectClusters[j]) do
615+ if Self.Graph.ObjectClusters[j][k] in oldRegions[i] then
616+ Self.Graph.ObjectClusters[j][k] := Self.Graph.ObjectClusters[j][k] + offset;
617+
618+ for j := 0 to High(Self.Graph.Doors) do
619+ if Self.Graph.Doors[j].Center in oldRegions[i] then
620+ begin
621+ Self.Graph.Doors[j].Before := Self.Graph.Doors[j].Before + offset;
622+ Self.Graph.Doors[j].After := Self.Graph.Doors[j].After + offset;
623+ Self.Graph.Doors[j].Center := Self.Graph.Doors[j].Center + offset;
624+ end;
625+ end;
644626
645- for j := 0 to High(graphs[i].Doors) do
646- begin
647- graphs[i].Doors[j].Before := graphs[i].Doors[j].Before + offset;
648- graphs[i].Doors[j].After := graphs[i].Doors[j].After + offset;
649- graphs[i].Doors[j].Center := graphs[i].Doors[j].Center + offset;
650- end;
627+ end;
651628
652- Self.Graph.Merge (graphs[i]);
653- end ;
629+ for i := 0 to High (graphs) do
630+ Self.Graph.Merge(graphs[i]) ;
654631
655- for i := 0 to High(Self.Graph.Doors) do
656- begin
657- Self.Graph.Doors[i].Before := RSTranslator.Normalize(Self.Graph.Doors[i].Before);
658- Self.Graph.Doors[i].After := RSTranslator.Normalize(Self.Graph.Doors[i].After);
659- end;
632+ for i := 0 to High(Self.Graph.Doors) do
633+ begin
634+ Self.Graph.Doors[i].Before := RSTranslator.Normalize(Self.Graph.Doors[i].Before);
635+ Self.Graph.Doors[i].After := RSTranslator.Normalize(Self.Graph.Doors[i].After);
660636 end;
661637end;
662638
0 commit comments