runtime smudge support

This commit is contained in:
Paul Chote
2010-04-08 18:03:22 +12:00
committed by Bob
parent ff7204d79d
commit 916706fa75
10 changed files with 145 additions and 149 deletions

View File

@@ -51,8 +51,14 @@ namespace OpenRA
w => w.Add(new Explosion(w, visualLocation, warhead.Explosion, isWater))); w => w.Add(new Explosion(w, visualLocation, warhead.Explosion, isWater)));
Sound.Play(GetImpactSound(warhead, isWater)); Sound.Play(GetImpactSound(warhead, isWater));
if (!isWater) world.Map.AddSmudge(targetTile, warhead); if (warhead.SmudgeType != SmudgeType.None)
{
var smudgeLayer = world.WorldActor.traits.WithInterface<SmudgeLayer>().FirstOrDefault(x => x.Info.Type == warhead.SmudgeType);
if (!isWater)
smudgeLayer.AddSmudge(targetTile);
}
if (warhead.Ore) if (warhead.Ore)
world.WorldActor.traits.Get<ResourceLayer>().Destroy(targetTile); world.WorldActor.traits.Get<ResourceLayer>().Destroy(targetTile);

View File

@@ -1,70 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Linq;
using OpenRA.FileFormats;
namespace OpenRA.Graphics
{
class SmudgeRenderer
{
static string[] smudgeSpriteNames =
{
"bib3", "bib2", "bib1", "sc1", "sc2", "sc3", "sc4", "sc5", "sc6",
"cr1", "cr2", "cr3", "cr4", "cr5", "cr6",
};
readonly Sprite[] smudgeSprites;
SpriteRenderer spriteRenderer;
Map map;
public SmudgeRenderer( Renderer renderer, Map map )
{
this.spriteRenderer = new SpriteRenderer( renderer, true );
this.map = map;
smudgeSprites = smudgeSpriteNames.SelectMany(f => SpriteSheetBuilder.LoadAllSprites(f)).ToArray();
}
public void Draw()
{
/*
var shroud = Game.world.LocalPlayer.Shroud;
for (int y = map.YOffset; y < map.YOffset + map.Height; y++)
for (int x = map.XOffset; x < map.XOffset + map.Width; x++)
{
if (!shroud.IsExplored(new int2(x,y))) continue;
var tr = map.MapTiles[x,y];
if (tr.smudge != 0 && tr.smudge <= smudgeSprites.Length)
{
var location = new int2(x, y);
spriteRenderer.DrawSprite(smudgeSprites[tr.smudge - 1],
Game.CellSize * (float2)location, "terrain");
}
}
spriteRenderer.Flush();
*/
}
}
}

View File

@@ -33,7 +33,6 @@ namespace OpenRA.Graphics
Renderer renderer; Renderer renderer;
Map map; Map map;
SmudgeRenderer overlayRenderer;
public TerrainRenderer(World world, Renderer renderer, WorldRenderer wr) public TerrainRenderer(World world, Renderer renderer, WorldRenderer wr)
{ {
@@ -68,8 +67,6 @@ namespace OpenRA.Graphics
indexBuffer = renderer.Device.CreateIndexBuffer( indices.Length ); indexBuffer = renderer.Device.CreateIndexBuffer( indices.Length );
indexBuffer.SetData( indices ); indexBuffer.SetData( indices );
overlayRenderer = new SmudgeRenderer( renderer, map );
} }
public void Draw( Viewport viewport ) public void Draw( Viewport viewport )
@@ -109,8 +106,6 @@ namespace OpenRA.Graphics
foreach (var r in Game.world.WorldActor.traits.WithInterface<IRenderOverlay>()) foreach (var r in Game.world.WorldActor.traits.WithInterface<IRenderOverlay>())
r.Render(); r.Render();
overlayRenderer.Draw();
} }
} }
} }

View File

@@ -65,11 +65,11 @@
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Tao.FreeType, Version=2.3.5.0, Culture=neutral, PublicKeyToken=e499629dc69cd531, processorArchitecture=MSIL"> <Reference Include="Tao.FreeType, Version=2.3.5.0, Culture=neutral, PublicKeyToken=e499629dc69cd531">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\thirdparty\Tao\Tao.FreeType.dll</HintPath> <HintPath>..\thirdparty\Tao\Tao.FreeType.dll</HintPath>
</Reference> </Reference>
<Reference Include="Tao.OpenAl, Version=1.1.0.1, Culture=neutral, PublicKeyToken=a7579dda88828311, processorArchitecture=MSIL"> <Reference Include="Tao.OpenAl, Version=1.1.0.1, Culture=neutral, PublicKeyToken=a7579dda88828311">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\thirdparty\Tao\Tao.OpenAl.dll</HintPath> <HintPath>..\thirdparty\Tao\Tao.OpenAl.dll</HintPath>
</Reference> </Reference>
@@ -122,7 +122,6 @@
<Compile Include="Server\Server.cs" /> <Compile Include="Server\Server.cs" />
<Compile Include="Server\ServerOrder.cs" /> <Compile Include="Server\ServerOrder.cs" />
<Compile Include="ShroudRenderer.cs" /> <Compile Include="ShroudRenderer.cs" />
<Compile Include="Smudge.cs" />
<Compile Include="Sound.cs" /> <Compile Include="Sound.cs" />
<Compile Include="Support\PerfHistory.cs" /> <Compile Include="Support\PerfHistory.cs" />
<Compile Include="Sync.cs" /> <Compile Include="Sync.cs" />
@@ -159,7 +158,6 @@
<Compile Include="Graphics\CursorSequence.cs" /> <Compile Include="Graphics\CursorSequence.cs" />
<Compile Include="Graphics\CursorSheetBuilder.cs" /> <Compile Include="Graphics\CursorSheetBuilder.cs" />
<Compile Include="Graphics\LineRenderer.cs" /> <Compile Include="Graphics\LineRenderer.cs" />
<Compile Include="Graphics\SmudgeRenderer.cs" />
<Compile Include="Graphics\WorldRenderer.cs" /> <Compile Include="Graphics\WorldRenderer.cs" />
<Compile Include="Traits\Activities\Idle.cs" /> <Compile Include="Traits\Activities\Idle.cs" />
<Compile Include="Traits\Activities\Land.cs" /> <Compile Include="Traits\Activities\Land.cs" />
@@ -293,6 +291,7 @@
<Compile Include="Traits\World\GlobalDefaults.cs" /> <Compile Include="Traits\World\GlobalDefaults.cs" />
<Compile Include="Traits\RepairsUnits.cs" /> <Compile Include="Traits\RepairsUnits.cs" />
<Compile Include="Traits\World\BibLayer.cs" /> <Compile Include="Traits\World\BibLayer.cs" />
<Compile Include="Traits\World\SmudgeLayer.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -1,67 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.FileFormats;
using OpenRA.GameRules;
namespace OpenRA
{
static class Smudge
{
const int firstScorch = 19;
const int firstCrater = 25;
const int framesPerCrater = 5;
public static void AddSmudge(this Map map, bool isCrater, int x, int y)
{
/*
var smudge = map.MapTiles[x, y].smudge;
if (smudge == 0)
map.MapTiles[x, y].smudge = (byte) (isCrater
? (firstCrater + framesPerCrater * ChooseSmudge())
: (firstScorch + ChooseSmudge()));
if (smudge < firstCrater || !isCrater) return; / * bib or scorch; don't change * /
/ * deepen the crater * /
var amount = (smudge - firstCrater) % framesPerCrater;
if (amount < framesPerCrater - 1)
map.MapTiles[x, y].smudge++;
*/
}
public static void AddSmudge(this Map map, int2 targetTile, WarheadInfo warhead)
{
/*
if (warhead.SmudgeType == SmudgeType.None) return;
if (warhead.Size[0] == 0 && warhead.Size[1] == 0)
map.AddSmudge(warhead.SmudgeType == SmudgeType.Crater, targetTile.X, targetTile.Y);
else
foreach (var t in Game.world.FindTilesInCircle(targetTile, warhead.Size[0]))
if ((t - targetTile).LengthSquared >= warhead.Size[1] * warhead.Size[1])
if (Rules.TerrainTypes[Game.world.GetTerrainType(t)].AcceptSmudge)
map.AddSmudge(warhead.SmudgeType == SmudgeType.Crater, t.X, t.Y);
*/
}
static int lastSmudge = 0;
static int ChooseSmudge() { return 0; /*lastSmudge = (lastSmudge + 1) % 6; return lastSmudge; */}
}
}

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Traits
World world; World world;
BibLayerInfo info; BibLayerInfo info;
TileReference<byte,byte>[,] tiles; TileReference<byte,byte>[,] tiles;
Sprite[][] bibSprites; Sprite[][] bibSprites;
public BibLayer(Actor self, BibLayerInfo info) public BibLayer(Actor self, BibLayerInfo info)

View File

@@ -0,0 +1,99 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using System.Linq;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.FileFormats;
using OpenRA.GameRules;
namespace OpenRA.Traits
{
class SmudgeLayerInfo : ITraitInfo
{
public readonly SmudgeType Type = SmudgeType.Scorch;
public readonly string[] Types = {"sc1", "sc2", "sc3", "sc4", "sc5", "sc6"};
public readonly int[] Depths = {1,1,1,1,1,1};
public object Create(Actor self) { return new SmudgeLayer(self, this); }
}
class SmudgeLayer: IRenderOverlay, ILoadWorldHook
{
public SmudgeLayerInfo Info;
SpriteRenderer spriteRenderer;
World world;
TileReference<byte,byte>[,] tiles;
Sprite[][] smudgeSprites;
string[] smudgeTypes;
public SmudgeLayer(Actor self, SmudgeLayerInfo info)
{
spriteRenderer = new SpriteRenderer( Game.renderer, true );
this.Info = info;
smudgeSprites = Info.Types.Select(x => SpriteSheetBuilder.LoadAllSprites(x)).ToArray();
}
public void WorldLoaded(World w)
{
world = w;
tiles = new TileReference<byte,byte>[w.Map.MapSize.X,w.Map.MapSize.Y];
// TODO: Parse map and add initial smudges
}
public void AddSmudge(int2 loc)
{
// No smudge; create a new one
if (tiles[loc.X, loc.Y].type == 0)
{
byte st = (byte)(1 + world.SharedRandom.Next(Info.Types.Length - 1));
tiles[loc.X,loc.Y] = new TileReference<byte,byte>(st,(byte)0);
return;
}
// Existing smudge; make it deeper
int depth = Info.Depths[tiles[loc.X, loc.Y].type-1];
if (tiles[loc.X, loc.Y].image >= depth - 1) return; /* Smudge is at maximum depth */
tiles[loc.X,loc.Y].image++;
}
public void Render()
{
var shroud = world.LocalPlayer.Shroud;
var tl = world.Map.TopLeft;
var br = world.Map.BottomRight;
for (int x = tl.X; x < br.X; x++)
for (int y = tl.Y; y < br.Y; y++)
{
var t = new int2(x, y);
if (!shroud.IsExplored(t) || tiles[x,y].type == 0) continue;
spriteRenderer.DrawSprite(smudgeSprites[tiles[x,y].type- 1][tiles[x,y].image],
Game.CellSize * (float2)t, "terrain");
}
spriteRenderer.Flush();
}
}
}

View File

@@ -199,6 +199,14 @@ World:
Name: Tiberium Name: Tiberium
GrowthInterval: 2 GrowthInterval: 2
SpreadInterval: 12 SpreadInterval: 12
SmudgeLayer@SCORCH:
Type:Scorch
Types:sc1,sc2,sc3,sc4,sc5,sc6
Depths:1,1,1,1,1,1
SmudgeLayer@CRATER:
Type:Crater
Types:cr1,cr2,cr3,cr4,cr5,cr6
Depths:5,5,5,5,5,5
SpawnMapActors: SpawnMapActors:
SpawnDefaultUnits: SpawnDefaultUnits:
EvaAlerts: EvaAlerts:

View File

@@ -127,6 +127,7 @@ Rockets:
InfDeath: 3 InfDeath: 3
Explosion: 4 Explosion: 4
ImpactSound: xplos ImpactSound: xplos
SmudgeType: Crater
Damage: 30 Damage: 30
Flamethrower: Flamethrower:
@@ -142,6 +143,7 @@ Flamethrower:
InfDeath: 4 InfDeath: 4
Explosion: 3 Explosion: 3
ImpactSound: flamer2 ImpactSound: flamer2
SmudgeType: Scorch
Damage: 35 Damage: 35
BigFlamer: BigFlamer:
@@ -157,6 +159,7 @@ BigFlamer:
InfDeath: 4 InfDeath: 4
Explosion: 3 Explosion: 3
ImpactSound: flamer2 ImpactSound: flamer2
SmudgeType: Scorch
Damage: 50 Damage: 50
Chemspray: Chemspray:
@@ -173,6 +176,7 @@ Chemspray:
Verses: 90%,75%,60%,25%,100% Verses: 90%,75%,60%,25%,100%
InfDeath: 2 InfDeath: 2
Explosion: 5 Explosion: 5
SmudgeType: Scorch
ImpactSound: xplos ImpactSound: xplos
Grenade: Grenade:
@@ -192,6 +196,7 @@ Grenade:
InfDeath: 2 InfDeath: 2
Explosion: 5 Explosion: 5
ImpactSound: xplos ImpactSound: xplos
SmudgeType: Crater
Damage: 50 Damage: 50
70mm: 70mm:
@@ -209,6 +214,7 @@ Grenade:
InfDeath: 3 InfDeath: 3
Explosion: 4 Explosion: 4
ImpactSound: xplos ImpactSound: xplos
SmudgeType: Crater
Damage: 25 Damage: 25
105mm: 105mm:
@@ -226,6 +232,7 @@ Grenade:
InfDeath: 3 InfDeath: 3
Explosion: 4 Explosion: 4
ImpactSound: xplos ImpactSound: xplos
SmudgeType: Crater
Damage: 30 Damage: 30
120mm: 120mm:
@@ -243,6 +250,7 @@ Grenade:
InfDeath: 3 InfDeath: 3
Explosion: 4 Explosion: 4
ImpactSound: xplos ImpactSound: xplos
SmudgeType: Crater
Damage: 40 Damage: 40
TurretGun: TurretGun:
@@ -260,6 +268,7 @@ TurretGun:
InfDeath: 3 InfDeath: 3
Explosion: 4 Explosion: 4
ImpactSound: xplos ImpactSound: xplos
SmudgeType: Crater
Damage: 40 Damage: 40
MissilePack: MissilePack:
@@ -285,6 +294,7 @@ MissilePack:
InfDeath: 3 InfDeath: 3
Explosion: 4 Explosion: 4
ImpactSound: xplos ImpactSound: xplos
SmudgeType: Crater
Damage: 75 Damage: 75
227mm: 227mm:
@@ -310,6 +320,7 @@ MissilePack:
InfDeath: 3 InfDeath: 3
Explosion: 4 Explosion: 4
ImpactSound: xplos ImpactSound: xplos
SmudgeType: Crater
Damage: 75 Damage: 75
Ballistic: Ballistic:
@@ -330,6 +341,7 @@ Ballistic:
Verses: 90%,75%,60%,25%,100% Verses: 90%,75%,60%,25%,100%
InfDeath: 2 InfDeath: 2
Explosion: 5 Explosion: 5
SmudgeType: Crater
ImpactSound: xplos ImpactSound: xplos
MachineGun: MachineGun:
@@ -367,6 +379,7 @@ BoatMissile:
InfDeath: 2 InfDeath: 2
Explosion: 5 Explosion: 5
ImpactSound: xplos ImpactSound: xplos
SmudgeType: Crater
Damage: 60 Damage: 60
Tomahawk: Tomahawk:
@@ -391,6 +404,7 @@ Tomahawk:
InfDeath: 2 InfDeath: 2
Explosion: 5 Explosion: 5
ImpactSound: xplos ImpactSound: xplos
SmudgeType: Crater
Damage: 60 Damage: 60
Napalm: Napalm:
@@ -409,6 +423,7 @@ Napalm:
InfDeath: 4 InfDeath: 4
Explosion: 3 Explosion: 3
ImpactSound: flamer2 ImpactSound: flamer2
SmudgeType: Scorch
Damage: 100 Damage: 100
Laser: Laser:
@@ -423,6 +438,7 @@ Laser:
Spread: 1 Spread: 1
Verses: 100%,100%,100%,100%,100% Verses: 100%,100%,100%,100%,100%
InfDeath: 4 InfDeath: 4
SmudgeType: Scorch
Damage: 200 Damage: 200
Nike: Nike:
@@ -446,6 +462,7 @@ Nike:
InfDeath: 3 InfDeath: 3
Explosion: 4 Explosion: 4
ImpactSound: xplos ImpactSound: xplos
SmudgeType: Crater
Damage: 50 Damage: 50
HonestJohn: HonestJohn:
@@ -467,4 +484,5 @@ HonestJohn:
InfDeath: 4 InfDeath: 4
Explosion: 3 Explosion: 3
ImpactSound: flamer2 ImpactSound: flamer2
SmudgeType: Scorch
Damage: 100 Damage: 100

View File

@@ -249,6 +249,14 @@ World:
Templates:templates.ini Templates:templates.ini
Tileset:tileSet.til Tileset:tileSet.til
MapColors:temperat.col MapColors:temperat.col
SmudgeLayer@SCORCH:
Type:Scorch
Types:sc1,sc2,sc3,sc4,sc5,sc6
Depths:1,1,1,1,1,1
SmudgeLayer@CRATER:
Type:Crater
Types:cr1,cr2,cr3,cr4,cr5,cr6
Depths:5,5,5,5,5,5
SpawnMapActors: SpawnMapActors:
SpawnDefaultUnits: SpawnDefaultUnits:
EvaAlerts: EvaAlerts: