diff options
author | Oren Hurvitz | 2012-07-24 19:48:08 +0300 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-09-14 20:25:03 +0100 |
commit | ce468215d576cc301a261d85bee9baa68a246ce6 (patch) | |
tree | ad2c6d7e3156bf8dab596f2772cc712d4f96c698 /OpenSim/Region/CoreModules/World/Archiver/ArchiveScenesGroup.cs | |
parent | Don't store the unnecessary VERSIONMIN. VERSIONMAX, METHOD or UserID (present... (diff) | |
download | opensim-SC_OLD-ce468215d576cc301a261d85bee9baa68a246ce6.zip opensim-SC_OLD-ce468215d576cc301a261d85bee9baa68a246ce6.tar.gz opensim-SC_OLD-ce468215d576cc301a261d85bee9baa68a246ce6.tar.bz2 opensim-SC_OLD-ce468215d576cc301a261d85bee9baa68a246ce6.tar.xz |
Support multi-region OAR files
Merged ArchiveWriteRequestPreparation.cs and ArchiveWriteRequestExecution.cs. This simplifies the code, and it's faster to write each scene to the archive as it's found rather than all at once at the end.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Archiver/ArchiveScenesGroup.cs | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveScenesGroup.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveScenesGroup.cs new file mode 100644 index 0000000..a66ed88 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveScenesGroup.cs | |||
@@ -0,0 +1,176 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Text; | ||
32 | using OpenSim.Region.Framework.Scenes; | ||
33 | using OpenMetaverse; | ||
34 | using System.Drawing; | ||
35 | |||
36 | namespace OpenSim.Region.CoreModules.World.Archiver | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// A group of regions arranged in a rectangle, possibly with holes. | ||
40 | /// </summary> | ||
41 | /// <remarks> | ||
42 | /// The regions usually (but not necessarily) belong to an archive file, in which case we | ||
43 | /// store additional information used to create the archive (e.g., each region's | ||
44 | /// directory within the archive). | ||
45 | /// </remarks> | ||
46 | public class ArchiveScenesGroup | ||
47 | { | ||
48 | /// <summary> | ||
49 | /// All the regions. The outer dictionary contains rows (key: Y coordinate). | ||
50 | /// The inner dictionaries contain each row's regions (key: X coordinate). | ||
51 | /// </summary> | ||
52 | public SortedDictionary<uint, SortedDictionary<uint, Scene>> Regions { get; set; } | ||
53 | |||
54 | /// <summary> | ||
55 | /// The subdirectory where each region is stored in the archive. | ||
56 | /// </summary> | ||
57 | protected Dictionary<UUID, string> m_regionDirs; | ||
58 | |||
59 | /// <summary> | ||
60 | /// The grid coordinates of the regions' bounding box. | ||
61 | /// </summary> | ||
62 | public Rectangle Rect { get; set; } | ||
63 | |||
64 | |||
65 | public ArchiveScenesGroup() | ||
66 | { | ||
67 | Regions = new SortedDictionary<uint, SortedDictionary<uint, Scene>>(); | ||
68 | m_regionDirs = new Dictionary<UUID, string>(); | ||
69 | Rect = new Rectangle(0, 0, 0, 0); | ||
70 | } | ||
71 | |||
72 | public void AddScene(Scene scene) | ||
73 | { | ||
74 | uint x = scene.RegionInfo.RegionLocX; | ||
75 | uint y = scene.RegionInfo.RegionLocY; | ||
76 | |||
77 | SortedDictionary<uint, Scene> row; | ||
78 | if (!Regions.TryGetValue(y, out row)) | ||
79 | { | ||
80 | row = new SortedDictionary<uint, Scene>(); | ||
81 | Regions[y] = row; | ||
82 | } | ||
83 | |||
84 | row[x] = scene; | ||
85 | } | ||
86 | |||
87 | /// <summary> | ||
88 | /// Called after all the scenes have been added. Performs calculations that require | ||
89 | /// knowledge of all the scenes. | ||
90 | /// </summary> | ||
91 | public void CalcSceneLocations() | ||
92 | { | ||
93 | if (Regions.Count == 0) | ||
94 | return; | ||
95 | |||
96 | // Find the bounding rectangle | ||
97 | |||
98 | uint firstY = Regions.First().Key; | ||
99 | uint lastY = Regions.Last().Key; | ||
100 | |||
101 | uint? firstX = null; | ||
102 | uint? lastX = null; | ||
103 | |||
104 | foreach (SortedDictionary<uint, Scene> row in Regions.Values) | ||
105 | { | ||
106 | uint curFirstX = row.First().Key; | ||
107 | uint curLastX = row.Last().Key; | ||
108 | |||
109 | firstX = (firstX == null) ? curFirstX : (firstX < curFirstX) ? firstX : curFirstX; | ||
110 | lastX = (lastX == null) ? curLastX : (lastX > curLastX) ? lastX : curLastX; | ||
111 | } | ||
112 | |||
113 | Rect = new Rectangle((int)firstX, (int)firstY, (int)(lastY - firstY + 1), (int)(lastX - firstX + 1)); | ||
114 | |||
115 | |||
116 | // Calculate the subdirectory in which each region will be stored in the archive | ||
117 | |||
118 | m_regionDirs.Clear(); | ||
119 | ForEachScene(delegate(Scene scene) | ||
120 | { | ||
121 | // We add the region's coordinates to ensure uniqueness even if multiple regions have the same name | ||
122 | string path = string.Format("{0}_{1}_{2}", | ||
123 | scene.RegionInfo.RegionLocX - Rect.X + 1, | ||
124 | scene.RegionInfo.RegionLocY - Rect.Y + 1, | ||
125 | scene.RegionInfo.RegionName.Replace(' ', '_')); | ||
126 | m_regionDirs[scene.RegionInfo.RegionID] = path; | ||
127 | }); | ||
128 | } | ||
129 | |||
130 | /// <summary> | ||
131 | /// Returns the subdirectory where the region is stored. | ||
132 | /// </summary> | ||
133 | /// <param name="regionID"></param> | ||
134 | /// <returns></returns> | ||
135 | public string GetRegionDir(UUID regionID) | ||
136 | { | ||
137 | return m_regionDirs[regionID]; | ||
138 | } | ||
139 | |||
140 | /// <summary> | ||
141 | /// Performs an action on all the scenes in this order: rows from South to North, | ||
142 | /// and within each row West to East. | ||
143 | /// </summary> | ||
144 | /// <param name="action"></param> | ||
145 | public void ForEachScene(Action<Scene> action) | ||
146 | { | ||
147 | foreach (SortedDictionary<uint, Scene> row in Regions.Values) | ||
148 | { | ||
149 | foreach (Scene scene in row.Values) | ||
150 | { | ||
151 | action(scene); | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | |||
156 | /// <summary> | ||
157 | /// Returns the scene at position 'location'. | ||
158 | /// </summary> | ||
159 | /// <param name="location">A location in the grid</param> | ||
160 | /// <param name="scene">The scene at this location</param> | ||
161 | /// <returns>Whether the scene was found</returns> | ||
162 | public bool TryGetScene(Point location, out Scene scene) | ||
163 | { | ||
164 | SortedDictionary<uint, Scene> row; | ||
165 | if (Regions.TryGetValue((uint)location.Y, out row)) | ||
166 | { | ||
167 | if (row.TryGetValue((uint)location.X, out scene)) | ||
168 | return true; | ||
169 | } | ||
170 | |||
171 | scene = null; | ||
172 | return false; | ||
173 | } | ||
174 | |||
175 | } | ||
176 | } | ||