slowly teasing the view+controller out of the model classes.
actually doesn't work right now, but that will change. git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@2050 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace OpenRa
|
namespace OpenRa
|
||||||
{
|
{
|
||||||
@@ -18,6 +16,7 @@ namespace OpenRa
|
|||||||
public float2(SizeF p) { X = p.Width; Y = p.Height; }
|
public float2(SizeF p) { X = p.Width; Y = p.Height; }
|
||||||
|
|
||||||
public PointF ToPointF() { return new PointF(X, Y); }
|
public PointF ToPointF() { return new PointF(X, Y); }
|
||||||
|
public SizeF ToSizeF() { return new SizeF(X, Y); }
|
||||||
|
|
||||||
public static implicit operator float2(int2 src) { return new float2(src.X, src.Y); }
|
public static implicit operator float2(int2 src) { return new float2(src.X, src.Y); }
|
||||||
|
|
||||||
|
|||||||
28
OpenRa.Game/Controller.cs
Normal file
28
OpenRa.Game/Controller.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
class Controller
|
||||||
|
{
|
||||||
|
Game game;
|
||||||
|
|
||||||
|
public IOrderGenerator orderGenerator;
|
||||||
|
|
||||||
|
public Controller(Game game)
|
||||||
|
{
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WorldClicked(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
var xy = (1 / 24.0f) * (new float2(e.Location) + game.viewport.Location);
|
||||||
|
if (orderGenerator != null)
|
||||||
|
orderGenerator.Order(game, new int2((int)xy.X, (int)xy.Y)).Apply(game);
|
||||||
|
// todo: route all orders through netcode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
234
OpenRa.Game/Game Code.cd
Normal file
234
OpenRa.Game/Game Code.cd
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ClassDiagram MajorVersion="1" MinorVersion="1">
|
||||||
|
<Class Name="OpenRa.Game.Actor" Collapsed="true">
|
||||||
|
<Position X="4" Y="3.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAgAAAAAAAgAAAAAAAAAAAAAAAAAAIAAAAAIAAQAA=</HashCode>
|
||||||
|
<FileName>Actor.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.World">
|
||||||
|
<Position X="8.75" Y="4.25" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAaAACBBAAAAAiAAAIACBgAAAAAAAAAIAAAAAAgAAAA=</HashCode>
|
||||||
|
<FileName>World.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.Building" Collapsed="true">
|
||||||
|
<Position X="4" Y="6.25" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA=</HashCode>
|
||||||
|
<FileName>Building.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.Game" Collapsed="true">
|
||||||
|
<Position X="11" Y="0.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAEAEAAAAIAAAgAABAAAIAAQAAAAAQAAJAAAAABAQAA=</HashCode>
|
||||||
|
<FileName>Game.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.MainWindow" Collapsed="true">
|
||||||
|
<Position X="12.75" Y="0.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAABAAAAAKIEAACAAAgAI=</HashCode>
|
||||||
|
<FileName>MainWindow.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.MoveOrder" Collapsed="true" BaseTypeListCollapsed="true">
|
||||||
|
<Position X="4" Y="1.75" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAABAAAAAAIAAAAAAAAAAAAAAEAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>MoveOrder.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.DeployMcvOrder" Collapsed="true" BaseTypeListCollapsed="true">
|
||||||
|
<Position X="1.75" Y="1.75" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAABAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>MoveOrder.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.HarvestOrder" Collapsed="true" BaseTypeListCollapsed="true">
|
||||||
|
<Position X="6.25" Y="1.75" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAABAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>MoveOrder.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.PathFinder" Collapsed="true">
|
||||||
|
<Position X="14.5" Y="0.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAEAAAAAAAABAAAAAAAAAAAAAEEAAAMAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>PathFinder.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.Player" Collapsed="true">
|
||||||
|
<Position X="11" Y="1.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAEAAAAAAAAAAAAAAAAAACAAAgAAAAAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>Player.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.PlayerOwned" Collapsed="true">
|
||||||
|
<Position X="2.75" Y="4.75" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAgAAAAAAAIAAAAAAAAIACAAAAAAAAAgAAAIAAAAA=</HashCode>
|
||||||
|
<FileName>PlayerOwned.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.Refinery" Collapsed="true">
|
||||||
|
<Position X="4" Y="7.75" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>Refinery.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.Rules" Collapsed="true">
|
||||||
|
<Position X="12.75" Y="1.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAgAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>Rules.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.Sidebar" Collapsed="true">
|
||||||
|
<Position X="14.5" Y="1.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AACAAAQAgECAAGAAEAgCAEAACABAiIAIAAAAIAC8AAA=</HashCode>
|
||||||
|
<FileName>Sidebar.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.PlaceBuilding" Collapsed="true" BaseTypeListCollapsed="true">
|
||||||
|
<Position X="16.25" Y="0.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAEAAACAAAAAAAAAAAAAAAQAAAAAAAAAAAAAQAAAAAA=</HashCode>
|
||||||
|
<FileName>Sidebar.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
<Lollipop Position="0.2" Collapsed="true" />
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.SidebarItem" Collapsed="true">
|
||||||
|
<Position X="16.25" Y="1.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAAAAAAAAAAAAAAACEBAAACAAAAAAAAAIAAA=</HashCode>
|
||||||
|
<FileName>SidebarItem.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.TerrainCosts" Collapsed="true">
|
||||||
|
<Position X="11" Y="2.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAAAAAAIAAAAAABAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>TerrainCosts.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.Tree" Collapsed="true">
|
||||||
|
<Position X="6.25" Y="4.75" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>gAAAgAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAIAAAAA=</HashCode>
|
||||||
|
<FileName>Tree.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.UiOverlay" Collapsed="true">
|
||||||
|
<Position X="12.75" Y="2.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAIAAAiQAQAAQIABAQAAgAAAYAAAAAAQAAAA=</HashCode>
|
||||||
|
<FileName>UiOverlay.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.Unit" Collapsed="true">
|
||||||
|
<Position X="1.75" Y="6.25" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAEAgDgAAAAAAAAAAAAAAAEAAAEGAAgAAAAERAAAQAA=</HashCode>
|
||||||
|
<FileName>Unit.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
<Lollipop Position="0.2" />
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.UnitInfo" Collapsed="true">
|
||||||
|
<Position X="14.5" Y="2.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AIAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>UnitInfo.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.UnitMissions">
|
||||||
|
<Position X="16.25" Y="2.5" Width="1.5" />
|
||||||
|
<Members>
|
||||||
|
<Method Name="Turn" Hidden="true" />
|
||||||
|
</Members>
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAYAAAAAAAAACAAABAAAAAAAAABAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>UnitMissions.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.Order" Collapsed="true">
|
||||||
|
<Position X="5" Y="0.5" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>MoveOrder.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Class Name="OpenRa.Game.PlaceBuildingOrder" Collapsed="true">
|
||||||
|
<Position X="8.5" Y="1.75" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>EAAAAAAAABAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>Sidebar.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Class>
|
||||||
|
<Struct Name="OpenRa.Game.CellInfo" Collapsed="true">
|
||||||
|
<Position X="11" Y="4.75" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAAAAAAIAAAEAAAAAAAAAAAQAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>PathFinder.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Struct>
|
||||||
|
<Struct Name="OpenRa.Game.PathDistance" Collapsed="true" BaseTypeListCollapsed="true">
|
||||||
|
<Position X="12.75" Y="4.75" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAAAAAAQAAAIAQAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>PathFinder.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
<Lollipop Position="0.2" Collapsed="true" />
|
||||||
|
</Struct>
|
||||||
|
<Interface Name="OpenRa.Game.IOrderGenerator" Collapsed="true">
|
||||||
|
<Position X="11" Y="6" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAA=</HashCode>
|
||||||
|
<FileName>IOrderGenerator.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Interface>
|
||||||
|
<Enum Name="OpenRa.Game.UnitMovementType" Collapsed="true">
|
||||||
|
<Position X="16.25" Y="7" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAQAAAAAAAiAAA=</HashCode>
|
||||||
|
<FileName>TerrainCosts.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Enum>
|
||||||
|
<Enum Name="OpenRa.Game.TerrainMovementType" Collapsed="true">
|
||||||
|
<Position X="14.5" Y="7" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAABAAAAAAAAIEAAAAAAAABgAAQgAAAAAABQAAA=</HashCode>
|
||||||
|
<FileName>TerrainCosts.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Enum>
|
||||||
|
<Enum Name="OpenRa.Game.SupportedMissions" Collapsed="true">
|
||||||
|
<Position X="12.75" Y="7" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAIBAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>UnitMissions.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Enum>
|
||||||
|
<Enum Name="OpenRa.TechTree.Race" Collapsed="true">
|
||||||
|
<Position X="11" Y="7" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAAAAAAEAAAA=</HashCode>
|
||||||
|
<FileName>Race.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Enum>
|
||||||
|
<Delegate Name="OpenRa.Game.UnitMission" Collapsed="true">
|
||||||
|
<Position X="11" Y="8" Width="1.5" />
|
||||||
|
<TypeIdentifier>
|
||||||
|
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAA=</HashCode>
|
||||||
|
<FileName>UnitMissions.cs</FileName>
|
||||||
|
</TypeIdentifier>
|
||||||
|
</Delegate>
|
||||||
|
<Font Name="Segoe UI" Size="9" />
|
||||||
|
</ClassDiagram>
|
||||||
@@ -15,14 +15,18 @@ namespace OpenRa.Game
|
|||||||
public readonly Viewport viewport;
|
public readonly Viewport viewport;
|
||||||
public readonly PathFinder pathFinder;
|
public readonly PathFinder pathFinder;
|
||||||
public readonly Network network;
|
public readonly Network network;
|
||||||
|
public readonly WorldRenderer worldRenderer;
|
||||||
|
public readonly Controller controller;
|
||||||
|
|
||||||
public int localPlayerIndex = 1;
|
int localPlayerIndex = 1;
|
||||||
|
|
||||||
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
|
public readonly Dictionary<int, Player> players = new Dictionary<int, Player>();
|
||||||
|
|
||||||
// temporary, until we remove all the subclasses of Building
|
// temporary, until we remove all the subclasses of Building
|
||||||
public Dictionary<string, Func<int2, Player, Building>> buildingCreation = new Dictionary<string, Func<int2, Player, Building>>();
|
public Dictionary<string, Func<int2, Player, Building>> buildingCreation = new Dictionary<string, Func<int2, Player, Building>>();
|
||||||
|
|
||||||
|
public Player LocalPlayer { get { return players[localPlayerIndex]; } }
|
||||||
|
|
||||||
public Game(string mapName, Renderer renderer, int2 clientSize)
|
public Game(string mapName, Renderer renderer, int2 clientSize)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
@@ -34,7 +38,7 @@ namespace OpenRa.Game
|
|||||||
viewport = new Viewport(clientSize, map.Size, renderer);
|
viewport = new Viewport(clientSize, map.Size, renderer);
|
||||||
|
|
||||||
terrain = new TerrainRenderer(renderer, map, viewport);
|
terrain = new TerrainRenderer(renderer, map, viewport);
|
||||||
world = new World(renderer, this);
|
world = new World(this);
|
||||||
treeCache = new TreeCache(map);
|
treeCache = new TreeCache(map);
|
||||||
|
|
||||||
foreach (TreeReference treeReference in map.Trees)
|
foreach (TreeReference treeReference in map.Trees)
|
||||||
@@ -48,20 +52,18 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
string[] buildings = { "fact", "powr", "apwr", "weap", "barr", "atek", "stek", "dome" };
|
string[] buildings = { "fact", "powr", "apwr", "weap", "barr", "atek", "stek", "dome" };
|
||||||
foreach (string s in buildings)
|
foreach (string s in buildings)
|
||||||
AddBuilding(s);
|
buildingCreation.Add(s, (location, owner) => new Building(s, location, owner, this));
|
||||||
}
|
|
||||||
|
|
||||||
void AddBuilding(string name)
|
controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL
|
||||||
{
|
worldRenderer = new WorldRenderer(renderer, world);
|
||||||
buildingCreation.Add(name, (location, owner) => new Building(name, location, owner, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
viewport.DrawRegions(this);
|
var stuffFromOtherPlayers = network.Tick(); // todo: actually use the orders!
|
||||||
Queue<Packet> stuffFromOtherPlayers = network.Tick(); // todo: actually use the orders!
|
world.Update();
|
||||||
}
|
|
||||||
|
|
||||||
public void Issue(IOrder order) { order.Apply(this); }
|
viewport.DrawRegions(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,8 @@ namespace OpenRa.Game.Graphics
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Region> regions = new List<Region>();
|
List<Region> regions = new List<Region>();
|
||||||
public void AddRegion(Region r)
|
|
||||||
{
|
public void AddRegion(Region r) { regions.Add(r); }
|
||||||
regions.Add(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawRegions(Game game)
|
public void DrawRegions(Game game)
|
||||||
{
|
{
|
||||||
@@ -46,9 +44,6 @@ namespace OpenRa.Game.Graphics
|
|||||||
renderer.EndFrame();
|
renderer.EndFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Region> Regions
|
public IEnumerable<Region> Regions { get { return regions; } }
|
||||||
{
|
|
||||||
get { return regions; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
48
OpenRa.Game/Graphics/WorldRenderer.cs
Normal file
48
OpenRa.Game/Graphics/WorldRenderer.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace OpenRa.Game.Graphics
|
||||||
|
{
|
||||||
|
class WorldRenderer
|
||||||
|
{
|
||||||
|
public readonly SpriteRenderer spriteRenderer;
|
||||||
|
public readonly World world;
|
||||||
|
public readonly Region region;
|
||||||
|
public readonly UiOverlay uiOverlay;
|
||||||
|
|
||||||
|
public WorldRenderer(Renderer renderer, World world)
|
||||||
|
{
|
||||||
|
// TODO: this is layout policy. it belongs at a higher level than this.
|
||||||
|
|
||||||
|
region = Region.Create(world.game.viewport, DockStyle.Left,
|
||||||
|
world.game.viewport.Width - 128, Draw, world.game.controller.WorldClicked); // TODO: world.WorldClicked is part of the CONTROLLER
|
||||||
|
world.game.viewport.AddRegion(region);
|
||||||
|
|
||||||
|
spriteRenderer = new SpriteRenderer(renderer, true);
|
||||||
|
uiOverlay = new UiOverlay(spriteRenderer, world.game);
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Draw()
|
||||||
|
{
|
||||||
|
var rect = new RectangleF(region.Location.ToPointF(), region.Size.ToSizeF());
|
||||||
|
|
||||||
|
foreach (Actor a in world.Actors)
|
||||||
|
{
|
||||||
|
Sprite[] images = a.CurrentImages;
|
||||||
|
float2 loc = a.RenderLocation;
|
||||||
|
|
||||||
|
if (loc.X > rect.Right || loc.X < rect.Left - images[0].bounds.Width)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (loc.Y > rect.Bottom || loc.Y < rect.Top - images[0].bounds.Height)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (Sprite image in images)
|
||||||
|
spriteRenderer.DrawSprite(image, loc, (a.owner != null) ? a.owner.Palette : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
spriteRenderer.Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
interface IOrderGenerator
|
interface IOrderGenerator
|
||||||
{
|
{
|
||||||
IOrder Order( Game game, int2 xy );
|
Order Order( Game game, int2 xy );
|
||||||
void PrepareOverlay( Game game, int2 xy );
|
void PrepareOverlay( Game game, int2 xy );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace OpenRa.Game
|
|||||||
game.world.Add( new Unit( "mcv", new int2( 5, 5 ), game.players[ 3 ], game ) );
|
game.world.Add( new Unit( "mcv", new int2( 5, 5 ), game.players[ 3 ], game ) );
|
||||||
game.world.Add( new Unit( "mcv", new int2( 7, 5 ), game.players[ 2 ], game ) );
|
game.world.Add( new Unit( "mcv", new int2( 7, 5 ), game.players[ 2 ], game ) );
|
||||||
Unit mcv = new Unit( "mcv", new int2( 9, 5 ), game.players[ 1 ], game );
|
Unit mcv = new Unit( "mcv", new int2( 9, 5 ), game.players[ 1 ], game );
|
||||||
game.world.orderGenerator = mcv;
|
game.controller.orderGenerator = mcv;
|
||||||
game.world.Add( mcv );
|
game.world.Add( mcv );
|
||||||
|
|
||||||
sidebar = new Sidebar(Race.Soviet, renderer, game);
|
sidebar = new Sidebar(Race.Soviet, renderer, game);
|
||||||
@@ -72,7 +72,7 @@ namespace OpenRa.Game
|
|||||||
lastPos = new int2(e.Location);
|
lastPos = new int2(e.Location);
|
||||||
|
|
||||||
if (e.Button == MouseButtons.Left)
|
if (e.Button == MouseButtons.Left)
|
||||||
foreach (GRegion region in game.viewport.Regions)
|
foreach (var region in game.viewport.Regions)
|
||||||
if (region.Contains(lastPos))
|
if (region.Contains(lastPos))
|
||||||
region.Clicked(e);
|
region.Clicked(e);
|
||||||
}
|
}
|
||||||
@@ -88,8 +88,8 @@ namespace OpenRa.Game
|
|||||||
lastPos = p;
|
lastPos = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game.world.orderGenerator != null)
|
if (game.controller.orderGenerator != null)
|
||||||
game.world.orderGenerator.PrepareOverlay(game,
|
game.controller.orderGenerator.PrepareOverlay(game,
|
||||||
new int2(e.Location.X / 24, e.Location.Y / 24));
|
new int2(e.Location.X / 24, e.Location.Y / 24));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ using System.Text;
|
|||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
interface IOrder
|
abstract class Order
|
||||||
{
|
{
|
||||||
void Apply( Game game );
|
public abstract void Apply( Game game );
|
||||||
}
|
}
|
||||||
|
|
||||||
class MoveOrder : IOrder
|
class MoveOrder : Order
|
||||||
{
|
{
|
||||||
public readonly Unit Unit;
|
public readonly Unit Unit;
|
||||||
public readonly int2 Destination;
|
public readonly int2 Destination;
|
||||||
@@ -20,13 +20,13 @@ namespace OpenRa.Game
|
|||||||
this.Destination = destination;
|
this.Destination = destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Apply( Game game )
|
public override void Apply( Game game )
|
||||||
{
|
{
|
||||||
Unit.nextOrder = UnitMissions.Move( Unit, Destination );
|
Unit.nextOrder = UnitMissions.Move( Unit, Destination );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeployMcvOrder : IOrder
|
class DeployMcvOrder : Order
|
||||||
{
|
{
|
||||||
Unit unit;
|
Unit unit;
|
||||||
|
|
||||||
@@ -35,13 +35,13 @@ namespace OpenRa.Game
|
|||||||
this.unit = unit;
|
this.unit = unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Apply( Game game )
|
public override void Apply( Game game )
|
||||||
{
|
{
|
||||||
unit.nextOrder = UnitMissions.Deploy( unit );
|
unit.nextOrder = UnitMissions.Deploy( unit );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HarvestOrder : IOrder
|
class HarvestOrder : Order
|
||||||
{
|
{
|
||||||
Unit unit;
|
Unit unit;
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ namespace OpenRa.Game
|
|||||||
this.unit = unit;
|
this.unit = unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Apply( Game game )
|
public override void Apply( Game game )
|
||||||
{
|
{
|
||||||
unit.nextOrder = UnitMissions.Harvest( unit );
|
unit.nextOrder = UnitMissions.Harvest( unit );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,9 +71,11 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Actor.cs" />
|
<Compile Include="Actor.cs" />
|
||||||
|
<Compile Include="Controller.cs" />
|
||||||
<Compile Include="Graphics\Animation.cs" />
|
<Compile Include="Graphics\Animation.cs" />
|
||||||
<Compile Include="Building.cs" />
|
<Compile Include="Building.cs" />
|
||||||
<Compile Include="Game.cs" />
|
<Compile Include="Game.cs" />
|
||||||
|
<Compile Include="Graphics\WorldRenderer.cs" />
|
||||||
<Compile Include="IOrderGenerator.cs" />
|
<Compile Include="IOrderGenerator.cs" />
|
||||||
<Compile Include="TechTree\Item.cs" />
|
<Compile Include="TechTree\Item.cs" />
|
||||||
<Compile Include="Network\Packet.cs" />
|
<Compile Include="Network\Packet.cs" />
|
||||||
@@ -81,7 +83,7 @@
|
|||||||
<Compile Include="PlayerOwned.cs" />
|
<Compile Include="PlayerOwned.cs" />
|
||||||
<Compile Include="Race.cs" />
|
<Compile Include="Race.cs" />
|
||||||
<Compile Include="Rules.cs" />
|
<Compile Include="Rules.cs" />
|
||||||
<Compile Include="SharedResources.cs" />
|
<Compile Include="Support\SharedResources.cs" />
|
||||||
<Compile Include="Graphics\Sheet.cs" />
|
<Compile Include="Graphics\Sheet.cs" />
|
||||||
<Compile Include="Support\Log.cs" />
|
<Compile Include="Support\Log.cs" />
|
||||||
<Compile Include="Network\Network.cs" />
|
<Compile Include="Network\Network.cs" />
|
||||||
@@ -148,6 +150,7 @@
|
|||||||
</BootstrapperPackage>
|
</BootstrapperPackage>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="Game Code.cd" />
|
||||||
<None Include="Graphics\Graphics.cd" />
|
<None Include="Graphics\Graphics.cd" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace OpenRa.Game
|
|||||||
Unit harvester = new Unit( "harv", location + new int2( 1, 2 ), owner, game );
|
Unit harvester = new Unit( "harv", location + new int2( 1, 2 ), owner, game );
|
||||||
harvester.facing = 8;
|
harvester.facing = 8;
|
||||||
game.world.Add(harvester);
|
game.world.Add(harvester);
|
||||||
game.world.orderGenerator = harvester;
|
game.controller.orderGenerator = harvester;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public Sidebar( Race race, Renderer renderer, Game game )
|
public Sidebar( Race race, Renderer renderer, Game game )
|
||||||
{
|
{
|
||||||
this.techTree = game.players[ game.localPlayerIndex ].TechTree;
|
this.techTree = game.LocalPlayer.TechTree;
|
||||||
this.game = game;
|
this.game = game;
|
||||||
region = GRegion.Create(game.viewport, DockStyle.Right, 128, Paint, MouseHandler);
|
region = GRegion.Create(game.viewport, DockStyle.Right, 128, Paint, MouseHandler);
|
||||||
game.viewport.AddRegion( region );
|
game.viewport.AddRegion( region );
|
||||||
@@ -49,7 +49,7 @@ namespace OpenRa.Game
|
|||||||
public void Build(SidebarItem item)
|
public void Build(SidebarItem item)
|
||||||
{
|
{
|
||||||
if (item != null)
|
if (item != null)
|
||||||
game.world.orderGenerator = new PlaceBuilding(game.players[1], item.techTreeItem.tag.ToLowerInvariant());
|
game.controller.orderGenerator = new PlaceBuilding(game.players[1], item.techTreeItem.tag.ToLowerInvariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadSprites(string filename)
|
void LoadSprites(string filename)
|
||||||
@@ -132,16 +132,16 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
class PlaceBuilding : IOrderGenerator
|
class PlaceBuilding : IOrderGenerator
|
||||||
{
|
{
|
||||||
Player owner;
|
public readonly Player Owner;
|
||||||
string buildingName;
|
public readonly string Name;
|
||||||
|
|
||||||
public PlaceBuilding( Player owner, string buildingName )
|
public PlaceBuilding( Player owner, string name )
|
||||||
{
|
{
|
||||||
this.owner = owner;
|
Owner = owner;
|
||||||
this.buildingName = buildingName;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IOrder Order( Game game, int2 xy )
|
public Order Order( Game game, int2 xy )
|
||||||
{
|
{
|
||||||
// todo: check that space is free
|
// todo: check that space is free
|
||||||
return new PlaceBuildingOrder( this, xy );
|
return new PlaceBuildingOrder( this, xy );
|
||||||
@@ -149,34 +149,34 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public void PrepareOverlay(Game game, int2 xy)
|
public void PrepareOverlay(Game game, int2 xy)
|
||||||
{
|
{
|
||||||
game.world.uiOverlay.SetCurrentOverlay(false, xy, 2, 3);
|
game.worldRenderer.uiOverlay.SetCurrentOverlay(false, xy, 2, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PlaceBuildingOrder : Order
|
||||||
|
{
|
||||||
|
PlaceBuilding building;
|
||||||
|
int2 xy;
|
||||||
|
|
||||||
|
public PlaceBuildingOrder(PlaceBuilding building, int2 xy)
|
||||||
|
{
|
||||||
|
this.building = building;
|
||||||
|
this.xy = xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlaceBuildingOrder : IOrder
|
public override void Apply(Game game)
|
||||||
{
|
{
|
||||||
PlaceBuilding building;
|
game.world.AddFrameEndTask(_ =>
|
||||||
int2 xy;
|
|
||||||
|
|
||||||
public PlaceBuildingOrder( PlaceBuilding building, int2 xy )
|
|
||||||
{
|
{
|
||||||
this.building = building;
|
Func<int2, Player, Building> newBuilding;
|
||||||
this.xy = xy;
|
if (game.buildingCreation.TryGetValue(building.Name, out newBuilding))
|
||||||
}
|
|
||||||
|
|
||||||
public void Apply( Game game )
|
|
||||||
{
|
|
||||||
game.world.AddFrameEndTask( _ =>
|
|
||||||
{
|
{
|
||||||
Func<int2, Player, Building> newBuilding;
|
Log.Write("Player \"{0}\" builds {1}", building.Owner.PlayerName, building.Name);
|
||||||
if( game.buildingCreation.TryGetValue( building.buildingName, out newBuilding ) )
|
game.world.Add(newBuilding(xy, building.Owner));
|
||||||
{
|
}
|
||||||
Log.Write( "Player \"{0}\" builds {1}", building.owner.PlayerName, building.buildingName );
|
game.controller.orderGenerator = null;
|
||||||
game.world.Add( newBuilding( xy, building.owner ) );
|
game.worldRenderer.uiOverlay.KillOverlay();
|
||||||
}
|
});
|
||||||
game.world.orderGenerator = null;
|
|
||||||
game.world.uiOverlay.KillOverlay();
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
OpenRa.Game/Support/SharedResources.cs
Normal file
13
OpenRa.Game/Support/SharedResources.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using IjwFramework.Types;
|
||||||
|
using OpenRa.FileFormats;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
class SharedResources
|
||||||
|
{
|
||||||
|
static Lazy<IniFile> rules = new Lazy<IniFile>(
|
||||||
|
() => new IniFile( FileSystem.Open( "rules.ini" )));
|
||||||
|
|
||||||
|
public static IniFile Rules { get { return rules.Value; } }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,6 +39,8 @@ namespace OpenRa.Game
|
|||||||
for (int j = 0; j < height; j++)
|
for (int j = 0; j < height; j++)
|
||||||
spriteRenderer.DrawSprite(blocked ? buildBlocked : buildOk,
|
spriteRenderer.DrawSprite(blocked ? buildBlocked : buildOk,
|
||||||
24 * (position + new int2(i, j)) + game.viewport.Location, 0);
|
24 * (position + new int2(i, j)) + game.viewport.Location, 0);
|
||||||
|
|
||||||
|
spriteRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool blocked, hasOverlay;
|
bool blocked, hasOverlay;
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ namespace OpenRa.Game
|
|||||||
return mission == ( unitInfo.supportedMissions & mission );
|
return mission == ( unitInfo.supportedMissions & mission );
|
||||||
}
|
}
|
||||||
|
|
||||||
public IOrder Order( Game game, int2 xy )
|
public Order Order( Game game, int2 xy )
|
||||||
{
|
{
|
||||||
if( ( fromCell == toCell || moveFraction == 0 ) && fromCell == xy )
|
if( ( fromCell == toCell || moveFraction == 0 ) && fromCell == xy )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Ijw.DirectX;
|
|
||||||
using OpenRa.Game.Graphics;
|
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -10,22 +8,10 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
List<Actor> actors = new List<Actor>();
|
List<Actor> actors = new List<Actor>();
|
||||||
List<Action<World>> frameEndActions = new List<Action<World>>();
|
List<Action<World>> frameEndActions = new List<Action<World>>();
|
||||||
SpriteRenderer spriteRenderer;
|
|
||||||
Game game;
|
|
||||||
Region region;
|
|
||||||
public IOrderGenerator orderGenerator;
|
|
||||||
public UiOverlay uiOverlay;
|
|
||||||
|
|
||||||
public World(Renderer renderer, Game game)
|
public readonly Game game;
|
||||||
{
|
|
||||||
region = Region.Create(game.viewport, DockStyle.Left, game.viewport.Width - 128, Draw, WorldClicked);
|
|
||||||
this.game = game;
|
|
||||||
game.viewport.AddRegion(region);
|
|
||||||
|
|
||||||
spriteRenderer = new SpriteRenderer(renderer, true);
|
|
||||||
|
|
||||||
uiOverlay = new UiOverlay(spriteRenderer, game);
|
public World(Game game) { this.game = game; }
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(Actor a) { actors.Add(a); }
|
public void Add(Actor a) { actors.Add(a); }
|
||||||
public void Remove( Actor a ) { actors.Remove( a ); }
|
public void Remove( Actor a ) { actors.Remove( a ); }
|
||||||
@@ -33,46 +19,21 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
int lastTime = Environment.TickCount;
|
int lastTime = Environment.TickCount;
|
||||||
|
|
||||||
void WorldClicked(object sender, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
float2 xy = (1 / 24.0f) * (new float2(e.Location) + game.viewport.Location);
|
|
||||||
if (orderGenerator != null)
|
|
||||||
{
|
|
||||||
IOrder order = orderGenerator.Order(game, new int2((int)xy.X, (int)xy.Y));
|
|
||||||
game.Issue(order);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Draw()
|
|
||||||
|
public void Update()
|
||||||
{
|
{
|
||||||
int t = Environment.TickCount;
|
int t = Environment.TickCount;
|
||||||
int dt = t - lastTime;
|
int dt = t - lastTime;
|
||||||
lastTime = t;
|
lastTime = t;
|
||||||
|
|
||||||
var range = new Range<float2>(region.Location, region.Location + region.Size);
|
|
||||||
|
|
||||||
foreach (Actor a in actors)
|
foreach (Actor a in actors)
|
||||||
{
|
a.Tick(game, dt);
|
||||||
a.Tick( game, dt );
|
|
||||||
|
|
||||||
Sprite[] images = a.CurrentImages;
|
|
||||||
float2 loc = a.RenderLocation;
|
|
||||||
|
|
||||||
if( loc.X > range.End.X || loc.X < range.Start.X - images[ 0 ].bounds.Width )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( loc.Y > range.End.Y || loc.Y < range.Start.Y - images[ 0 ].bounds.Height )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
foreach( Sprite image in images )
|
|
||||||
spriteRenderer.DrawSprite(image, loc, (a.owner != null) ? a.owner.Palette : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Action<World> a in frameEndActions) a(this);
|
foreach (Action<World> a in frameEndActions) a(this);
|
||||||
frameEndActions.Clear();
|
frameEndActions.Clear();
|
||||||
|
|
||||||
uiOverlay.Draw();
|
|
||||||
spriteRenderer.Flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Actor> Actors { get { return actors; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user