Overlay rendering
- also, sequences for HBOX and PBOX
This commit is contained in:
@@ -124,7 +124,6 @@ namespace OpenRa.FileFormats
|
||||
for( int i = 0 ; i < 128 ; i++ )
|
||||
for( int j = 0 ; j < 128 ; j++ )
|
||||
MapTiles[ j, i ].overlay = ReadByte( ms );
|
||||
|
||||
}
|
||||
|
||||
void ReadTrees( IniFile file )
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace OpenRa.Game
|
||||
public Actor( string name, int2 location, Player owner )
|
||||
{
|
||||
unitInfo = Rules.UnitInfo.Get( name );
|
||||
Location = location;
|
||||
Location = location;
|
||||
CenterLocation = new float2( 12, 12 ) + 24 * (float2)Location;
|
||||
Owner = owner;
|
||||
|
||||
@@ -90,11 +90,11 @@ namespace OpenRa.Game
|
||||
case "ftur":
|
||||
traits.Add( new Traits.Building( this ) );
|
||||
traits.Add( new Traits.RenderBuilding( this ) );
|
||||
break;
|
||||
case "weap":
|
||||
traits.Add( new Traits.Building( this ) );
|
||||
traits.Add( new Traits.RenderWarFactory( this ) );
|
||||
break;
|
||||
break;
|
||||
case "weap":
|
||||
traits.Add( new Traits.Building( this ) );
|
||||
traits.Add( new Traits.RenderWarFactory( this ) );
|
||||
break;
|
||||
case "gun":
|
||||
case "agun":
|
||||
case "sam":
|
||||
@@ -117,8 +117,8 @@ namespace OpenRa.Game
|
||||
{
|
||||
foreach( var tick in traits.WithInterface<Traits.ITick>() )
|
||||
tick.Tick( this, game, dt );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public float2 CenterLocation;
|
||||
public float2 SelectedSize { get { return Render().FirstOrDefault().First.size; } }
|
||||
|
||||
@@ -191,45 +191,45 @@ namespace OpenRa.Game
|
||||
{
|
||||
anim.PlayThen( "make", () => anim.PlayFetchIndex( "idle", () => self.traits.Get<Turreted>().turretFacing ) );
|
||||
}
|
||||
}
|
||||
|
||||
class RenderWarFactory : RenderBuilding
|
||||
{
|
||||
public Animation roof;
|
||||
bool doneBuilding;
|
||||
|
||||
public RenderWarFactory( Actor self )
|
||||
: base( self )
|
||||
{
|
||||
roof = new Animation( self.unitInfo.Name );
|
||||
anim.PlayThen( "make", () =>
|
||||
{
|
||||
doneBuilding = true;
|
||||
anim.Play( "idle" );
|
||||
roof.Play( "idle-top" );
|
||||
} );
|
||||
}
|
||||
|
||||
public override IEnumerable<Pair<Sprite, float2>> Render( Actor self )
|
||||
{
|
||||
yield return Pair.New( anim.Image, 24f * (float2)self.Location );
|
||||
if( doneBuilding )
|
||||
yield return Pair.New( roof.Image, 24f * (float2)self.Location );
|
||||
}
|
||||
|
||||
public override void Tick( Actor self, Game game, int dt )
|
||||
{
|
||||
base.Tick( self, game, dt );
|
||||
roof.Tick( dt );
|
||||
}
|
||||
}
|
||||
|
||||
class RenderWarFactory : RenderBuilding
|
||||
{
|
||||
public Animation roof;
|
||||
bool doneBuilding;
|
||||
|
||||
public RenderWarFactory( Actor self )
|
||||
: base( self )
|
||||
{
|
||||
roof = new Animation( self.unitInfo.Name );
|
||||
anim.PlayThen( "make", () =>
|
||||
{
|
||||
doneBuilding = true;
|
||||
anim.Play( "idle" );
|
||||
roof.Play( "idle-top" );
|
||||
} );
|
||||
}
|
||||
|
||||
public override IEnumerable<Pair<Sprite, float2>> Render( Actor self )
|
||||
{
|
||||
yield return Pair.New( anim.Image, 24f * (float2)self.Location );
|
||||
if( doneBuilding )
|
||||
yield return Pair.New( roof.Image, 24f * (float2)self.Location );
|
||||
}
|
||||
|
||||
public override void Tick( Actor self, Game game, int dt )
|
||||
{
|
||||
base.Tick( self, game, dt );
|
||||
roof.Tick( dt );
|
||||
}
|
||||
}
|
||||
|
||||
class RenderUnit : RenderSimple
|
||||
{
|
||||
public RenderUnit( Actor self )
|
||||
: base( self )
|
||||
{
|
||||
anim.PlayFetchIndex( "idle", () => self.traits.Get<Mobile>().facing );
|
||||
{
|
||||
public RenderUnit( Actor self )
|
||||
: base( self )
|
||||
{
|
||||
anim.PlayFetchIndex( "idle", () => self.traits.Get<Mobile>().facing );
|
||||
}
|
||||
|
||||
protected static Pair<Sprite, float2> Centered( Sprite s, float2 location )
|
||||
@@ -319,20 +319,20 @@ namespace OpenRa.Game
|
||||
}
|
||||
|
||||
return highest;
|
||||
}
|
||||
|
||||
void UpdateCenterLocation()
|
||||
{
|
||||
float fraction = ( moveFraction > 0 ) ? (float)moveFraction / moveFractionTotal : 0f;
|
||||
self.CenterLocation = new float2( 12, 12 ) + 24 * float2.Lerp( fromCell, toCell, fraction );
|
||||
}
|
||||
|
||||
void UpdateCenterLocation()
|
||||
{
|
||||
float fraction = ( moveFraction > 0 ) ? (float)moveFraction / moveFractionTotal : 0f;
|
||||
self.CenterLocation = new float2( 12, 12 ) + 24 * float2.Lerp( fromCell, toCell, fraction );
|
||||
}
|
||||
|
||||
public void Tick( Actor self, Game game, int dt )
|
||||
{
|
||||
Move( self, game, dt );
|
||||
{
|
||||
Move( self, game, dt );
|
||||
UpdateCenterLocation();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Move( Actor self, Game game, int dt )
|
||||
{
|
||||
if( fromCell != toCell )
|
||||
@@ -424,16 +424,16 @@ namespace OpenRa.Game
|
||||
class Building : ITick
|
||||
{
|
||||
public Building( Actor self )
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
public void Tick( Actor self, Game game, int dt )
|
||||
{
|
||||
if( first && self.Owner == game.LocalPlayer )
|
||||
{
|
||||
self.Owner.TechTree.Build( self.unitInfo.Name, true );
|
||||
self.CenterLocation = 24 * (float2)self.Location + 0.5f * self.SelectedSize;
|
||||
{
|
||||
if( first && self.Owner == game.LocalPlayer )
|
||||
{
|
||||
self.Owner.TechTree.Build( self.unitInfo.Name, true );
|
||||
self.CenterLocation = 24 * (float2)self.Location + 0.5f * self.SelectedSize;
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRa.Game
|
||||
Rules.LoadRules();
|
||||
|
||||
for( int i = 0 ; i < 8 ; i++ )
|
||||
players.Add(i, new Player(i, string.Format("Multi{0}", i), OpenRa.TechTree.Race.Soviet));
|
||||
players.Add(i, new Player(i, string.Format("Multi{0}", i), OpenRa.TechTree.Race.Allies));
|
||||
|
||||
map = new Map(new IniFile(FileSystem.Open(mapName)));
|
||||
FileSystem.Mount(new Package(map.Theater + ".mix"));
|
||||
|
||||
52
OpenRa.Game/Graphics/OverlayRenderer.cs
Executable file
52
OpenRa.Game/Graphics/OverlayRenderer.cs
Executable file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.FileFormats;
|
||||
|
||||
namespace OpenRa.Game.Graphics
|
||||
{
|
||||
class OverlayRenderer
|
||||
{
|
||||
static string[] overlaySpriteNames = new string[]
|
||||
{
|
||||
"sbag", "cycl", "brik", "fenc", "wood",
|
||||
"gold01", "gold02", "gold03", "gold04",
|
||||
"gem01", "gem02", "gem03", "gem04",
|
||||
"v12", "v13", "v14", "v15", "v16", "v17", "v18",
|
||||
"fpls", "wcrate", "scrate", "barb", "sbag"
|
||||
};
|
||||
Sprite[][] overlaySprites;
|
||||
|
||||
SpriteRenderer spriteRenderer;
|
||||
Map map;
|
||||
|
||||
public OverlayRenderer( Renderer renderer, Map map )
|
||||
{
|
||||
this.spriteRenderer = new SpriteRenderer( renderer, true );
|
||||
this.map = map;
|
||||
|
||||
overlaySprites = new Sprite[ overlaySpriteNames.Length ][];
|
||||
for( int i = 0 ; i < overlaySpriteNames.Length ; i++ )
|
||||
overlaySprites[ i ] = SpriteSheetBuilder.LoadAllSprites( overlaySpriteNames[ i ], ".shp", ".tem", ".sno" );
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
for( int y = 0 ; y < 128 ; y++ )
|
||||
{
|
||||
for( int x = 0 ; x < 128 ; x++ )
|
||||
{
|
||||
if( map.MapTiles[ x, y ].overlay < overlaySprites.Length )
|
||||
{
|
||||
var location = new int2( x, y );
|
||||
var sprites = overlaySprites[ map.MapTiles[ x, y ].overlay ];
|
||||
spriteRenderer.DrawSprite( sprites[ sprites.Length / 2-1 ], 24 * (float2)( location - map.Offset ), 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spriteRenderer.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,24 @@ namespace OpenRa.Game.Graphics
|
||||
{
|
||||
static class SpriteSheetBuilder
|
||||
{
|
||||
static Dictionary<string, Sprite> sprites =
|
||||
new Dictionary<string, Sprite>();
|
||||
static Dictionary<string, Sprite[]> sprites =
|
||||
new Dictionary<string, Sprite[]>();
|
||||
|
||||
public static Sprite LoadSprite(string filename)
|
||||
public static Sprite LoadSprite(string filename, params string[] exts )
|
||||
{
|
||||
Sprite value;
|
||||
if (!sprites.TryGetValue(filename, out value))
|
||||
return LoadAllSprites( filename, exts )[ 0 ];
|
||||
}
|
||||
|
||||
public static Sprite[] LoadAllSprites( string filename, params string[] exts )
|
||||
{
|
||||
Sprite[] value;
|
||||
if( !sprites.TryGetValue( filename, out value ) )
|
||||
{
|
||||
ShpReader shp = new ShpReader(FileSystem.Open(filename));
|
||||
sprites.Add(filename, value = SheetBuilder.Add(shp[0].Image, shp.Size));
|
||||
ShpReader shp = new ShpReader( FileSystem.OpenWithExts( filename, exts ) );
|
||||
value = new Sprite[ shp.ImageCount ];
|
||||
for( int i = 0 ; i < shp.ImageCount ; i++ )
|
||||
value[ i ] = SheetBuilder.Add( shp[ i ].Image, shp.Size );
|
||||
sprites.Add( filename, value );
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace OpenRa.Game.Graphics
|
||||
Renderer renderer;
|
||||
Map map;
|
||||
Viewport viewport;
|
||||
OverlayRenderer overlayRenderer;
|
||||
|
||||
public TerrainRenderer(Renderer renderer, Map map, Viewport viewport)
|
||||
{
|
||||
@@ -25,6 +26,7 @@ namespace OpenRa.Game.Graphics
|
||||
region = Region.Create(viewport, DockStyle.Left, viewport.Width - 128, Draw, null );
|
||||
viewport.AddRegion(region);
|
||||
this.map = map;
|
||||
overlayRenderer = new OverlayRenderer( renderer, map );
|
||||
|
||||
tileSet = new TileSet( map.TileSuffix );
|
||||
|
||||
@@ -78,6 +80,8 @@ namespace OpenRa.Game.Graphics
|
||||
new Range<int>(verticesPerRow * firstRow, verticesPerRow * lastRow),
|
||||
new Range<int>(indicesPerRow * firstRow, indicesPerRow * lastRow),
|
||||
terrainSheet.Texture, PrimitiveType.TriangleList));
|
||||
|
||||
overlayRenderer.Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@
|
||||
<Compile Include="Graphics\Animation.cs" />
|
||||
<Compile Include="Game.cs" />
|
||||
<Compile Include="Graphics\LineRenderer.cs" />
|
||||
<Compile Include="Graphics\OverlayRenderer.cs" />
|
||||
<Compile Include="Graphics\WorldRenderer.cs" />
|
||||
<Compile Include="IOrderGenerator.cs" />
|
||||
<Compile Include="TechTree\Item.cs" />
|
||||
|
||||
@@ -70,8 +70,8 @@ namespace OpenRa.Game
|
||||
{
|
||||
string key = line.Substring(0, line.IndexOf(','));
|
||||
int secondComma = line.IndexOf(',', line.IndexOf(',') + 1);
|
||||
string group = line.Substring(secondComma + 1, line.Length - secondComma - 1);
|
||||
sprites.Add(key, SpriteSheetBuilder.LoadSprite(key + "icon.shp"));
|
||||
string group = line.Substring(secondComma + 1, line.Length - secondComma - 1);
|
||||
sprites.Add( key, SpriteSheetBuilder.LoadSprite( key + "icon", ".shp" ) );
|
||||
itemGroups.Add(key, group);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Windows.Forms;
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
class World
|
||||
{
|
||||
{
|
||||
List<Actor> actors = new List<Actor>();
|
||||
List<Action<World>> frameEndActions = new List<Action<World>>();
|
||||
|
||||
@@ -19,8 +19,6 @@ namespace OpenRa.Game
|
||||
|
||||
int lastTime = Environment.TickCount + 2000;
|
||||
|
||||
|
||||
|
||||
public void Update()
|
||||
{
|
||||
int t = Environment.TickCount;
|
||||
@@ -35,8 +33,8 @@ namespace OpenRa.Game
|
||||
|
||||
foreach (Action<World> a in frameEndActions) a(this);
|
||||
frameEndActions.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> Actors { get { return actors; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +183,20 @@
|
||||
<sequence name="make" start="0" length="*" src="tslamake" />
|
||||
</unit>
|
||||
|
||||
<!-- pillbox -->
|
||||
<unit name="pbox">
|
||||
<sequence name="idle" start="0"/>
|
||||
<sequence name="damaged-idle" start="1"/>
|
||||
<sequence name="make" start="0" length="*" src="pboxmake" />
|
||||
</unit>
|
||||
|
||||
<!-- camo pillbox -->
|
||||
<unit name="hbox">
|
||||
<sequence name="idle" start="0"/>
|
||||
<sequence name="damaged-idle" start="1"/>
|
||||
<sequence name="make" start="0" length="*" src="hboxmake" />
|
||||
</unit>
|
||||
|
||||
<!-- iron curtain -->
|
||||
<unit name="iron">
|
||||
<sequence name="idle" start="0" length="11"/>
|
||||
|
||||
Reference in New Issue
Block a user