From f2eeb11d0f7bea2fcb7b8495b030afd1d5584a9d Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 6 Oct 2009 20:39:40 +1300 Subject: [PATCH 1/3] added TurretedUnit 3tnk works; jeep's turret is off-center (and possibly hard-coded?) --- OpenRa.Game/Actor.cs | 4 +-- OpenRa.Game/Game.cs | 5 +-- OpenRa.Game/Graphics/Animation.cs | 2 +- OpenRa.Game/Graphics/WorldRenderer.cs | 18 +++++----- OpenRa.Game/MainWindow.cs | 17 ++++++---- OpenRa.Game/PlayerOwned.cs | 10 +++--- OpenRa.Game/Sidebar.cs | 2 +- OpenRa.Game/Tree.cs | 12 +++++-- OpenRa.Game/Unit.cs | 47 ++++++++++++++++++++++++--- sequences.xml | 14 ++++++++ 10 files changed, 96 insertions(+), 35 deletions(-) diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index c1479e0dd0..1c1a673329 100644 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -6,6 +6,7 @@ using OpenRa.FileFormats; using System.Windows.Forms; using OpenRa.Game.Graphics; +using IjwFramework.Types; namespace OpenRa.Game { @@ -13,9 +14,8 @@ namespace OpenRa.Game { public readonly Game game; - public abstract float2 RenderLocation { get; } public Player owner; - public abstract Sprite[] CurrentImages { get; } + public abstract IEnumerable> CurrentImages { get; } public virtual void Tick(Game game, int t) { } protected Actor(Game game) diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 043be2a03f..fb91c4947c 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -52,10 +52,7 @@ namespace OpenRa.Game string[] buildings = { "fact", "powr", "apwr", "weap", "barr", "atek", "stek", "dome" }; foreach (string s in buildings) - { - var t = s; - buildingCreation.Add(t, (location, owner) => new Building(t, location, owner, this)); - } + buildingCreation.Add(s, (location, owner) => new Building(s, location, owner, this)); controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL worldRenderer = new WorldRenderer(renderer, world); diff --git a/OpenRa.Game/Graphics/Animation.cs b/OpenRa.Game/Graphics/Animation.cs index d1debfef51..b3be057d05 100644 --- a/OpenRa.Game/Graphics/Animation.cs +++ b/OpenRa.Game/Graphics/Animation.cs @@ -15,7 +15,7 @@ namespace OpenRa.Game.Graphics Play( "idle" ); } - public Sprite[] Images { get { return new Sprite[] { currentSequence.GetSprite( frame ) }; } } + public Sprite Image { get { return currentSequence.GetSprite( frame ); } } public float2 Center { get { return 0.25f * new float2(currentSequence.GetSprite(0).bounds.Size); } } public void Play( string sequenceName ) diff --git a/OpenRa.Game/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs index d060b4bbae..92dc5f3248 100644 --- a/OpenRa.Game/Graphics/WorldRenderer.cs +++ b/OpenRa.Game/Graphics/WorldRenderer.cs @@ -29,17 +29,19 @@ namespace OpenRa.Game.Graphics foreach (Actor a in world.Actors) { - Sprite[] images = a.CurrentImages; - float2 loc = a.RenderLocation; + var images = a.CurrentImages; - if (loc.X > rect.Right || loc.X < rect.Left - images[0].bounds.Width) - continue; + foreach( var image in images ) + { + var loc = image.Second; - if (loc.Y > rect.Bottom || loc.Y < rect.Top - images[0].bounds.Height) - continue; + if( loc.X > rect.Right || loc.X < rect.Left - image.First.bounds.Width ) + continue; + if( loc.Y > rect.Bottom || loc.Y < rect.Top - image.First.bounds.Height ) + continue; - foreach (Sprite image in images) - spriteRenderer.DrawSprite(image, loc, (a.owner != null) ? a.owner.Palette : 0); + spriteRenderer.DrawSprite( image.First, loc, ( a.owner != null ) ? a.owner.Palette : 0 ); + } } spriteRenderer.Flush(); diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 8b3c163eb0..c35226a0f2 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -36,19 +36,24 @@ namespace OpenRa.Game Location = Point.Empty; Visible = true; - bool windowed = !settings.GetValue("fullscreen", false); - renderer = new Renderer(this, GetResolution(settings), windowed); + //bool windowed = !settings.GetValue("fullscreen", false); + //renderer = new Renderer(this, GetResolution(settings), windowed); + renderer = new Renderer( this, new Size( 800, 600 ), true ); SheetBuilder.Initialize( renderer ); - game = new Game( settings.GetValue( "map", "scm12ea.ini" ), renderer, new int2( ClientSize ) ); + game = new Game( settings.GetValue( "map", "scg11eb.ini" ), renderer, new int2( ClientSize ) ); SequenceProvider.ForcePrecache(); + Unit controlled; + 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 ) ); - Unit mcv = new Unit( "mcv", new int2( 9, 5 ), game.players[ 1 ], game ); - game.controller.orderGenerator = mcv; - game.world.Add( mcv ); + game.world.Add( controlled = new Unit( "mcv", new int2( 9, 5 ), game.players[ 1 ], game ) ); + + game.world.Add( controlled = new TurretedUnit( "jeep", new int2( 9, 7 ), game.players[ 1 ], game ) ); + + game.controller.orderGenerator = controlled; sidebar = new Sidebar(Race.Soviet, renderer, game); diff --git a/OpenRa.Game/PlayerOwned.cs b/OpenRa.Game/PlayerOwned.cs index 06e969abaf..8c65b3866f 100644 --- a/OpenRa.Game/PlayerOwned.cs +++ b/OpenRa.Game/PlayerOwned.cs @@ -1,4 +1,6 @@ +using System.Collections.Generic; using OpenRa.Game.Graphics; +using IjwFramework.Types; namespace OpenRa.Game { @@ -17,11 +19,7 @@ namespace OpenRa.Game this.location = location; } - public override float2 RenderLocation - { - get { return 24.0f * (float2)location; } - } - - public override Sprite[] CurrentImages { get { return animation.Images; } } + public override IEnumerable> CurrentImages { get { yield return Pair.New( animation.Image, 24 * (float2)location ); } } } } + \ No newline at end of file diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index 465776a8e2..8c8768e958 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -108,7 +108,7 @@ namespace OpenRa.Game spriteRenderer.Flush(); - clockRenderer.DrawSprite( clockAnimation.Images[0], region.Location, 0 ); + clockRenderer.DrawSprite( clockAnimation.Image, region.Location, 0 ); clockAnimation.Tick(1); clockRenderer.Flush(); diff --git a/OpenRa.Game/Tree.cs b/OpenRa.Game/Tree.cs index 14b82f361d..e295eea0e5 100644 --- a/OpenRa.Game/Tree.cs +++ b/OpenRa.Game/Tree.cs @@ -4,6 +4,7 @@ using System.Text; using OpenRa.FileFormats; using System.Drawing; using OpenRa.Game.Graphics; +using IjwFramework.Types; namespace OpenRa.Game { @@ -19,8 +20,13 @@ namespace OpenRa.Game } Sprite[] currentImages; - public override Sprite[] CurrentImages { get { return currentImages; } } - - public override float2 RenderLocation { get { return 24 * location; } } + public override IEnumerable> CurrentImages + { + get + { + foreach( var x in currentImages ) + yield return Pair.New( x, 24 * (float2)location ); + } + } } } diff --git a/OpenRa.Game/Unit.cs b/OpenRa.Game/Unit.cs index 4b9bd67528..994429d0ec 100644 --- a/OpenRa.Game/Unit.cs +++ b/OpenRa.Game/Unit.cs @@ -1,5 +1,9 @@ using System; +using System.Collections.Generic; +using System.Linq; + using OpenRa.Game.Graphics; +using IjwFramework.Types; namespace OpenRa.Game { @@ -67,14 +71,20 @@ namespace OpenRa.Game currentOrder( t ); } - public override float2 RenderLocation + public override IEnumerable> CurrentImages + { + get + { + yield return Centered( animation.Image, CenterLocation ); + } + } + + public float2 CenterLocation { get { float fraction = ( moveFraction > 0 ) ? (float)moveFraction / moveFractionTotal : 0f; - - float2 location = 24 * float2.Lerp( fromCell, toCell, fraction ); - return ( location - renderOffset ).Round(); + return new float2( 12, 12 ) + 24 * float2.Lerp( fromCell, toCell, fraction ); } } @@ -97,5 +107,34 @@ namespace OpenRa.Game } public void PrepareOverlay(Game game, int2 xy) { } + + protected static Pair Centered( Sprite s, float2 location ) + { + var loc = location - 0.5f * s.size; + return Pair.New( s, loc.Round() ); + } + } + + class TurretedUnit : Unit + { + Animation turretAnim; + int turretFacing { get { return facing; } } + + public TurretedUnit( string name, int2 cell, Player owner, Game game ) + : base( name, cell, owner, game ) + { + turretAnim = new Animation( name ); + turretAnim.PlayFetchIndex( "turret", () => turretFacing ); + } + + public override IEnumerable> CurrentImages + { + get + { + foreach( var x in base.CurrentImages ) + yield return x; + yield return Centered( turretAnim.Image, CenterLocation ); + } + } } } diff --git a/sequences.xml b/sequences.xml index 3856828cae..7fd1819920 100644 --- a/sequences.xml +++ b/sequences.xml @@ -130,6 +130,20 @@ + + + + + + + + + + + + + + From 88a2fb50b4af1d214975a36c87772888e6a356b1 Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 6 Oct 2009 20:49:21 +1300 Subject: [PATCH 2/3] Project file works with VC# Express, and changes to Game.cs that should have happened last commit :S --- OpenRa.FileFormats/OpenRa.FileFormats.csproj | 8 ++++---- OpenRa.Game/Game.cs | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/OpenRa.FileFormats/OpenRa.FileFormats.csproj b/OpenRa.FileFormats/OpenRa.FileFormats.csproj index 7979afdc1a..d0a40fbc3f 100644 --- a/OpenRa.FileFormats/OpenRa.FileFormats.csproj +++ b/OpenRa.FileFormats/OpenRa.FileFormats.csproj @@ -35,6 +35,10 @@ prompt + + False + ..\Release\MixDecrypt.dll + @@ -62,10 +66,6 @@ - - {6F5D4280-3D23-41FF-AE2A-511B5553E377} - MixDecrypt - {2F9E7A23-56C0-4286-9C8E-1060A9B2F073} OpenRa.DataStructures diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index fb91c4947c..ea46ada831 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using OpenRa.FileFormats; using OpenRa.Game.Graphics; @@ -48,11 +49,9 @@ namespace OpenRa.Game network = new Network(); - buildingCreation.Add("proc", (location, owner) => new Refinery(location, owner, this)); - string[] buildings = { "fact", "powr", "apwr", "weap", "barr", "atek", "stek", "dome" }; - foreach (string s in buildings) - buildingCreation.Add(s, (location, owner) => new Building(s, location, owner, this)); + buildingCreation = buildings.ToDictionary( s => s, s => (Func)( ( l, o ) => new Building( s, l, o, this ) ) ); + buildingCreation.Add( "proc", ( location, owner ) => new Refinery( location, owner, this ) ); controller = new Controller(this); // CAREFUL THERES AN UGLY HIDDEN DEPENDENCY HERE STILL worldRenderer = new WorldRenderer(renderer, world); From 382ff42397b7584a81d196bb19830f4c2e471096 Mon Sep 17 00:00:00 2001 From: Bob Date: Fri, 9 Oct 2009 18:09:30 +1300 Subject: [PATCH 3/3] updated sequences, and some small fixes --- OpenRa.Game/Controller.cs | 12 ++++-- OpenRa.Game/Graphics/Sequence.cs | 2 +- sequences.xml | 73 +++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index 7a3a8b31f4..d47b69949a 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -17,12 +17,16 @@ namespace OpenRa.Game this.game = game; } - public void WorldClicked(object sender, MouseEventArgs e) + 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 + var xy = ( 1 / 24.0f ) * ( new float2( e.Location ) + game.viewport.Location ); + if( orderGenerator != null ) + { + var order = orderGenerator.Order( game, new int2( (int)xy.X, (int)xy.Y ) ); + if( order != null ) + order.Apply( game ); + } } } } diff --git a/OpenRa.Game/Graphics/Sequence.cs b/OpenRa.Game/Graphics/Sequence.cs index c9fe749d10..ecce1b57b5 100644 --- a/OpenRa.Game/Graphics/Sequence.cs +++ b/OpenRa.Game/Graphics/Sequence.cs @@ -32,7 +32,7 @@ namespace OpenRa.Game.Graphics public Sprite GetSprite(int frame) { - return UnitSheetBuilder.sprites[frame + start]; + return UnitSheetBuilder.sprites[ ( frame % length ) + start ]; } } } diff --git a/sequences.xml b/sequences.xml index 7fd1819920..d424f04aa7 100644 --- a/sequences.xml +++ b/sequences.xml @@ -13,7 +13,7 @@ also, creates a sequence that includes all frames after `start`. - + one day, we might support inheritance here too. standard sequence names: @@ -104,6 +104,14 @@ + + + + + + + + @@ -128,8 +136,23 @@ + + + + + + + + + + + + + + + @@ -137,6 +160,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -144,6 +188,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +