Merge pull request #10901 from pchote/server-maps

Remove Map usage from the server and mission browser.
This commit is contained in:
abcdefg30
2016-03-13 11:24:04 +01:00
8 changed files with 140 additions and 66 deletions

View File

@@ -152,7 +152,7 @@ namespace OpenRA.Mods.Common.Server
client.SpawnPoint = 0;
client.Slot = s;
S.SyncClientToPlayerReference(client, server.MapPlayers.Players[s]);
S.SyncClientToPlayerReference(client, server.Map.Players.Players[s]);
if (!slot.LockColor)
client.PreferredColor = client.Color = SanitizePlayerColor(server, client.Color, client.Index, conn);
@@ -311,7 +311,7 @@ namespace OpenRA.Mods.Common.Server
var tileset = server.Map.Rules.TileSet;
var terrainColors = tileset.TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color);
var playerColors = server.LobbyInfo.Clients.Select(c => c.Color.RGB)
.Concat(server.MapPlayers.Players.Values.Select(p => p.Color.RGB));
.Concat(server.Map.Players.Players.Values.Select(p => p.Color.RGB));
bot.Color = bot.PreferredColor = validator.RandomValidColor(server.Random, terrainColors, playerColors);
server.LobbyInfo.Clients.Add(bot);
@@ -323,7 +323,7 @@ namespace OpenRA.Mods.Common.Server
bot.Bot = botType;
}
S.SyncClientToPlayerReference(bot, server.MapPlayers.Players[parts[0]]);
S.SyncClientToPlayerReference(bot, server.Map.Players.Players[parts[0]]);
server.SyncLobbyClients();
server.SyncLobbySlots();
return true;
@@ -370,9 +370,9 @@ namespace OpenRA.Mods.Common.Server
if (c.Slot != null)
{
// Remove Bot from slot if slot forbids bots
if (c.Bot != null && !server.MapPlayers.Players[c.Slot].AllowBots)
if (c.Bot != null && !server.Map.Players.Players[c.Slot].AllowBots)
server.LobbyInfo.Clients.Remove(c);
S.SyncClientToPlayerReference(c, server.MapPlayers.Players[c.Slot]);
S.SyncClientToPlayerReference(c, server.Map.Players.Players[c.Slot]);
}
else if (c.Bot != null)
server.LobbyInfo.Clients.Remove(c);
@@ -387,12 +387,12 @@ namespace OpenRA.Mods.Common.Server
server.SendMessage("{0} changed the map to {1}.".F(client.Name, server.Map.Title));
if (server.Map.RuleDefinitions != null)
if (server.Map.Rules.Actors != server.ModData.DefaultRules.Actors)
server.SendMessage("This map contains custom rules. Game experience may change.");
if (server.Settings.DisableSinglePlayer)
server.SendMessage("Singleplayer games have been disabled on this server.");
else if (server.MapPlayers.Players.Where(p => p.Value.Playable).All(p => !p.Value.AllowBots))
else if (server.Map.Players.Players.Where(p => p.Value.Playable).All(p => !p.Value.AllowBots))
server.SendMessage("Bots have been disabled on this map.");
return true;
@@ -875,7 +875,7 @@ namespace OpenRA.Mods.Common.Server
int spawnPoint;
if (!Exts.TryParseIntegerInvariant(parts[1], out spawnPoint)
|| spawnPoint < 0 || spawnPoint > server.Map.SpawnPoints.Value.Length)
|| spawnPoint < 0 || spawnPoint > server.Map.SpawnPoints.Length)
{
Log.Write("server", "Invalid spawn point: {0}", parts[1]);
return true;
@@ -1013,28 +1013,28 @@ namespace OpenRA.Mods.Common.Server
};
}
public static void LoadMapSettings(Session.Global gs, Map map)
public static void LoadMapSettings(Session.Global gs, Ruleset rules)
{
var devMode = map.Rules.Actors["player"].TraitInfo<DeveloperModeInfo>();
var devMode = rules.Actors["player"].TraitInfo<DeveloperModeInfo>();
gs.AllowCheats = devMode.Enabled;
var crateSpawner = map.Rules.Actors["world"].TraitInfoOrDefault<CrateSpawnerInfo>();
var crateSpawner = rules.Actors["world"].TraitInfoOrDefault<CrateSpawnerInfo>();
gs.Crates = crateSpawner != null && crateSpawner.Enabled;
var shroud = map.Rules.Actors["player"].TraitInfo<ShroudInfo>();
var shroud = rules.Actors["player"].TraitInfo<ShroudInfo>();
gs.Fog = shroud.FogEnabled;
gs.Shroud = !shroud.ExploredMapEnabled;
var resources = map.Rules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
var resources = rules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
gs.StartingCash = resources.DefaultCash;
var startingUnits = map.Rules.Actors["world"].TraitInfoOrDefault<SpawnMPUnitsInfo>();
var startingUnits = rules.Actors["world"].TraitInfoOrDefault<SpawnMPUnitsInfo>();
gs.StartingUnitsClass = startingUnits == null ? "none" : startingUnits.StartingUnitsClass;
var mapBuildRadius = map.Rules.Actors["world"].TraitInfoOrDefault<MapBuildRadiusInfo>();
var mapBuildRadius = rules.Actors["world"].TraitInfoOrDefault<MapBuildRadiusInfo>();
gs.AllyBuildRadius = mapBuildRadius != null && mapBuildRadius.AllyBuildRadiusEnabled;
var mapOptions = map.Rules.Actors["world"].TraitInfo<MapOptionsInfo>();
var mapOptions = rules.Actors["world"].TraitInfo<MapOptionsInfo>();
gs.ShortGame = mapOptions.ShortGameEnabled;
gs.TechLevel = mapOptions.TechLevel;
gs.Difficulty = mapOptions.Difficulty ?? mapOptions.Difficulties.FirstOrDefault();
@@ -1042,15 +1042,14 @@ namespace OpenRA.Mods.Common.Server
static void LoadMap(S server)
{
server.Map = new Map(server.ModData, server.ModData.MapCache[server.LobbyInfo.GlobalSettings.Map].Package);
server.Map = server.ModData.MapCache[server.LobbyInfo.GlobalSettings.Map];
server.MapPlayers = new MapPlayers(server.Map.PlayerDefinitions);
server.LobbyInfo.Slots = server.MapPlayers.Players
server.LobbyInfo.Slots = server.Map.Players.Players
.Select(p => MakeSlotFromPlayerReference(p.Value))
.Where(s => s != null)
.ToDictionary(s => s.PlayerReference, s => s);
LoadMapSettings(server.LobbyInfo.GlobalSettings, server.Map);
LoadMapSettings(server.LobbyInfo.GlobalSettings, server.Map.Rules);
}
static HSLColor SanitizePlayerColor(S server, HSLColor askedColor, int playerIndex, Connection connectionToEcho = null)
@@ -1067,7 +1066,7 @@ namespace OpenRA.Mods.Common.Server
var tileset = server.Map.Rules.TileSet;
var terrainColors = tileset.TerrainInfo.Where(ti => ti.RestrictPlayerColor).Select(ti => ti.Color).ToList();
var playerColors = server.LobbyInfo.Clients.Where(c => c.Index != playerIndex).Select(c => c.Color.RGB)
.Concat(server.MapPlayers.Players.Values.Select(p => p.Color.RGB)).ToList();
.Concat(server.Map.Players.Players.Values.Select(p => p.Color.RGB)).ToList();
return validator.MakeValid(askColor.RGB, server.Random, terrainColors, playerColors, onError);
}
@@ -1086,7 +1085,7 @@ namespace OpenRA.Mods.Common.Server
if (slot == null)
return null;
return server.MapPlayers.Players[slot.PlayerReference];
return server.Map.Players.Players[slot.PlayerReference];
}
}
}

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Server
return;
var defaults = new Session.Global();
LobbyCommands.LoadMapSettings(defaults, server.Map);
LobbyCommands.LoadMapSettings(defaults, server.Map.Rules);
if (server.LobbyInfo.GlobalSettings.AllowCheats != defaults.AllowCheats)
server.SendOrderTo(conn, "Message", "Allow Cheats: {0}".F(server.LobbyInfo.GlobalSettings.AllowCheats));

View File

@@ -43,11 +43,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly ScrollPanelWidget missionList;
readonly ScrollItemWidget headerTemplate;
readonly ScrollItemWidget template;
readonly Cache<MapPreview, Map> mapCache;
MapPreview selectedMapPreview;
Map selectedMap;
MapPreview selectedMap;
PlayingVideo playingVideo;
string difficulty;
@@ -56,7 +53,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor]
public MissionBrowserLogic(Widget widget, ModData modData, World world, Action onStart, Action onExit)
{
mapCache = new Cache<MapPreview, Map>(p => new Map(modData, p.Package));
this.modData = modData;
this.onStart = onStart;
@@ -67,12 +63,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var title = widget.GetOrNull<LabelWidget>("MISSIONBROWSER_TITLE");
if (title != null)
title.GetText = () => playingVideo != PlayingVideo.None ? selectedMapPreview.Title : title.Text;
title.GetText = () => playingVideo != PlayingVideo.None ? selectedMap.Title : title.Text;
widget.Get("MISSION_INFO").IsVisible = () => selectedMapPreview != null;
widget.Get("MISSION_INFO").IsVisible = () => selectedMap != null;
var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW");
previewWidget.Preview = () => selectedMapPreview;
previewWidget.Preview = () => selectedMap;
previewWidget.IsVisible = () => playingVideo == PlayingVideo.None;
videoPlayer = widget.Get<VqaPlayerWidget>("MISSION_VIDEO");
@@ -132,11 +128,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (allPreviews.Any())
SelectMap(allPreviews.First());
// Preload map and preview data to reduce jank
// Preload map preview and rules to reduce jank
new Thread(() =>
{
foreach (var p in allPreviews)
modData.MapCache[mapCache[p].Uid].GetMinimap();
{
p.GetMinimap();
var unused = p.Rules;
}
}).Start();
var startButton = widget.Get<ButtonWidget>("STARTGAME_BUTTON");
@@ -163,7 +162,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var preview = p;
var item = ScrollItemWidget.Setup(template,
() => selectedMapPreview != null && selectedMapPreview.Uid == preview.Uid,
() => selectedMap != null && selectedMap.Uid == preview.Uid,
() => SelectMap(preview),
StartMissionClicked);
@@ -174,8 +173,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void SelectMap(MapPreview preview)
{
selectedMap = mapCache[preview];
selectedMapPreview = preview;
selectedMap = preview;
// Cache the rules on a background thread to avoid jank
var difficultyDisabled = true;
@@ -189,17 +187,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var infoVideoVisible = false;
var infoVideoDisabled = true;
var map = selectedMap;
new Thread(() =>
{
map.PreloadRules();
var mapOptions = map.Rules.Actors["world"].TraitInfo<MapOptionsInfo>();
var mapOptions = preview.Rules.Actors["world"].TraitInfo<MapOptionsInfo>();
difficulty = mapOptions.Difficulty ?? mapOptions.Difficulties.FirstOrDefault();
difficulties = mapOptions.Difficulties;
difficultyDisabled = mapOptions.DifficultyLocked || mapOptions.Difficulties.Length <= 1;
var missionData = map.Rules.Actors["world"].TraitInfoOrDefault<MissionDataInfo>();
var missionData = preview.Rules.Actors["world"].TraitInfoOrDefault<MissionDataInfo>();
if (missionData != null)
{
briefingVideo = missionData.BriefingVideo;
@@ -214,7 +210,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var height = descriptionFont.Measure(briefing).Y;
Game.RunAfterTick(() =>
{
if (map == selectedMap)
if (preview == selectedMap)
{
description.Text = briefing;
description.Bounds.Height = height;
@@ -348,11 +344,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
PlayVideo(fsPlayer, missionData.StartVideo, PlayingVideo.GameStart, () =>
{
StopVideo(fsPlayer);
Game.CreateAndStartLocalServer(selectedMapPreview.Uid, orders, onStart);
Game.CreateAndStartLocalServer(selectedMap.Uid, orders, onStart);
});
}
else
Game.CreateAndStartLocalServer(selectedMapPreview.Uid, orders, onStart);
Game.CreateAndStartLocalServer(selectedMap.Uid, orders, onStart);
}
class DropDownOption