rename OpenRA.Support.Random aka XRandom to MersenneTwister
This commit is contained in:
5
OpenRA.Game/Exts.cs
Executable file → Normal file
5
OpenRA.Game/Exts.cs
Executable file → Normal file
@@ -14,6 +14,7 @@ using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -100,13 +101,13 @@ namespace OpenRA
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static T Random<T>(this IEnumerable<T> ts, Support.Random r)
|
||||
public static T Random<T>(this IEnumerable<T> ts, MersenneTwister r)
|
||||
{
|
||||
var xs = ts.ToArray();
|
||||
return xs[r.Next(xs.Length)];
|
||||
}
|
||||
|
||||
public static T RandomOrDefault<T>(this IEnumerable<T> ts, Support.Random r)
|
||||
public static T RandomOrDefault<T>(this IEnumerable<T> ts, MersenneTwister r)
|
||||
{
|
||||
if (!ts.Any())
|
||||
return default(T);
|
||||
|
||||
@@ -24,8 +24,6 @@ using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
using XRandom = OpenRA.Support.Random;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public static class Game
|
||||
@@ -39,7 +37,7 @@ namespace OpenRA
|
||||
internal static OrderManager orderManager;
|
||||
static Server.Server server;
|
||||
|
||||
public static XRandom CosmeticRandom = new XRandom(); // not synced
|
||||
public static MersenneTwister CosmeticRandom = new MersenneTwister(); // not synced
|
||||
|
||||
public static Renderer Renderer;
|
||||
public static bool HasInputFocus = false;
|
||||
|
||||
@@ -247,6 +247,7 @@
|
||||
<Compile Include="ModMetadata.cs" />
|
||||
<Compile Include="GameRules\Ruleset.cs" />
|
||||
<Compile Include="GameRules\RulesetCache.cs" />
|
||||
<Compile Include="Support\MersenneTwister.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FileSystem\D2kSoundResources.cs" />
|
||||
@@ -321,7 +322,6 @@
|
||||
<Compile Include="WRot.cs" />
|
||||
<Compile Include="WVec.cs" />
|
||||
<Compile Include="Primitives\TypeDictionary.cs" />
|
||||
<Compile Include="Support\Random.cs" />
|
||||
<Compile Include="Map\ActorInitializer.cs" />
|
||||
<Compile Include="Map\ActorReference.cs" />
|
||||
<Compile Include="Support\Evaluator.cs" />
|
||||
|
||||
@@ -21,6 +21,7 @@ using OpenRA.GameRules;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
|
||||
using XTimer = System.Timers.Timer;
|
||||
|
||||
@@ -39,7 +40,7 @@ namespace OpenRA.Server
|
||||
public readonly int Port;
|
||||
|
||||
int randomSeed;
|
||||
public readonly Support.Random Random = new Support.Random();
|
||||
public readonly MersenneTwister Random = new MersenneTwister();
|
||||
|
||||
// Valid player connections
|
||||
public List<Connection> Conns = new List<Connection>();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
@@ -13,8 +13,7 @@ using System;
|
||||
namespace OpenRA.Support
|
||||
{
|
||||
// quick & dirty Mersenne Twister [MT19937] implementation
|
||||
|
||||
public class Random
|
||||
public class MersenneTwister
|
||||
{
|
||||
uint[] mt = new uint[624];
|
||||
int index = 0;
|
||||
@@ -22,9 +21,9 @@ namespace OpenRA.Support
|
||||
public int Last;
|
||||
public int TotalCount = 0;
|
||||
|
||||
public Random() : this(Environment.TickCount) { }
|
||||
public MersenneTwister() : this(Environment.TickCount) { }
|
||||
|
||||
public Random(int seed)
|
||||
public MersenneTwister(int seed)
|
||||
{
|
||||
mt[0] = (uint)seed;
|
||||
for (var i = 1u; i < mt.Length; i++)
|
||||
2
OpenRA.Game/Traits/Util.cs
Executable file → Normal file
2
OpenRA.Game/Traits/Util.cs
Executable file → Normal file
@@ -96,7 +96,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
|
||||
/* pretty crap */
|
||||
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> ts, Support.Random random)
|
||||
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> ts, MersenneTwister random)
|
||||
{
|
||||
var items = ts.ToList();
|
||||
while (items.Count > 0)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -39,7 +40,7 @@ namespace OpenRA
|
||||
// 2 samples produces a triangular probability
|
||||
// ...
|
||||
// N samples approximates a true gaussian
|
||||
public static WRange FromPDF(Support.Random r, int samples)
|
||||
public static WRange FromPDF(MersenneTwister r, int samples)
|
||||
{
|
||||
return new WRange(Exts.MakeArray(samples, _ => r.Next(-1024, 1024))
|
||||
.Sum() / samples);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
@@ -12,6 +12,7 @@ using System;
|
||||
using Eluant;
|
||||
using Eluant.ObjectBinding;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -73,7 +74,7 @@ namespace OpenRA
|
||||
// 2 samples produces a triangular probability
|
||||
// ...
|
||||
// N samples approximates a true gaussian
|
||||
public static WVec FromPDF(Support.Random r, int samples)
|
||||
public static WVec FromPDF(MersenneTwister r, int samples)
|
||||
{
|
||||
return new WVec(WRange.FromPDF(r, samples), WRange.FromPDF(r, samples), WRange.Zero);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ using OpenRA.Orders;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
using XRandom = OpenRA.Support.Random;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -36,7 +35,7 @@ namespace OpenRA
|
||||
internal readonly OrderManager orderManager;
|
||||
public Session LobbyInfo { get { return orderManager.LobbyInfo; } }
|
||||
|
||||
public XRandom SharedRandom;
|
||||
public MersenneTwister SharedRandom;
|
||||
|
||||
public readonly List<Player> Players = new List<Player>();
|
||||
|
||||
@@ -126,7 +125,7 @@ namespace OpenRA
|
||||
Map = map;
|
||||
|
||||
TileSet = map.Rules.TileSets[Map.Tileset];
|
||||
SharedRandom = new XRandom(orderManager.LobbyInfo.GlobalSettings.RandomSeed);
|
||||
SharedRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed);
|
||||
|
||||
WorldActor = CreateActor("World", new TypeDictionary());
|
||||
ActorMap = WorldActor.Trait<ActorMap>();
|
||||
|
||||
2
OpenRA.Game/WorldUtils.cs
Executable file → Normal file
2
OpenRA.Game/WorldUtils.cs
Executable file → Normal file
@@ -118,7 +118,7 @@ namespace OpenRA
|
||||
: (edge ? w.Map.Bounds.Top : w.Map.Bounds.Bottom));
|
||||
}
|
||||
|
||||
public static CPos ChooseRandomCell(this World w, Support.Random r)
|
||||
public static CPos ChooseRandomCell(this World w, MersenneTwister r)
|
||||
{
|
||||
return new CPos(
|
||||
r.Next(w.Map.Bounds.Left, w.Map.Bounds.Right),
|
||||
|
||||
Reference in New Issue
Block a user