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.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using Ijw.DirectX;
|
||||
using OpenRa.Game.Graphics;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
@@ -10,22 +8,10 @@ namespace OpenRa.Game
|
||||
{
|
||||
List<Actor> actors = new List<Actor>();
|
||||
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)
|
||||
{
|
||||
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);
|
||||
public readonly Game game;
|
||||
|
||||
uiOverlay = new UiOverlay(spriteRenderer, game);
|
||||
}
|
||||
public World(Game game) { this.game = game; }
|
||||
|
||||
public void Add(Actor a) { actors.Add(a); }
|
||||
public void Remove( Actor a ) { actors.Remove( a ); }
|
||||
@@ -33,46 +19,21 @@ namespace OpenRa.Game
|
||||
|
||||
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 dt = t - lastTime;
|
||||
lastTime = t;
|
||||
|
||||
var range = new Range<float2>(region.Location, region.Location + region.Size);
|
||||
|
||||
foreach (Actor a in actors)
|
||||
{
|
||||
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);
|
||||
}
|
||||
a.Tick(game, dt);
|
||||
|
||||
foreach (Action<World> a in frameEndActions) a(this);
|
||||
frameEndActions.Clear();
|
||||
|
||||
uiOverlay.Draw();
|
||||
spriteRenderer.Flush();
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> Actors { get { return actors; } }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user