unit movement debug overlay + working blocking. still needs repath in some cases.

This commit is contained in:
Chris Forbes
2009-10-26 14:06:06 +13:00
parent b0cf14b3eb
commit 6d1826245f
4 changed files with 53 additions and 21 deletions

View File

@@ -48,7 +48,9 @@ namespace OpenRa.Game
bool windowed = !settings.GetValue("fullscreen", false);
renderer = new Renderer(this, GetResolution(settings), windowed);
SheetBuilder.Initialize(renderer);
SheetBuilder.Initialize(renderer);
UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false);
Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize),
settings.GetValue("player", 1));

View File

@@ -125,7 +125,7 @@ namespace OpenRa.Game.Traits
float2 from, to;
int fromFacing, toFacing;
Action<Actor, Mobile> OnComplete;
Func<Actor, Mobile, bool> OnComplete;
public MoveTo( int2 destination )
{
@@ -185,19 +185,28 @@ namespace OpenRa.Game.Traits
}
void TickMove( Actor self, Mobile mobile )
{
{
var oldFraction = moveFraction;
var oldTotal = moveFractionTotal;
moveFraction += ( self.unitInfo as UnitInfo.MobileInfo ).Speed;
UpdateCenterLocation( self, mobile, (float)moveFraction / moveFractionTotal );
UpdateCenterLocation( self, mobile );
if( moveFraction >= moveFractionTotal )
{
moveFraction -= moveFractionTotal;
OnComplete( self, mobile );
moveFraction -= moveFractionTotal;
if (!OnComplete(self, mobile))
{
moveFraction = oldFraction;
moveFractionTotal = oldTotal;
UpdateCenterLocation(self, mobile );
}
}
return;
}
void UpdateCenterLocation( Actor self, Mobile mobile, float frac )
{
void UpdateCenterLocation( Actor self, Mobile mobile )
{
var frac = (float)moveFraction / moveFractionTotal;
self.CenterLocation = float2.Lerp( from, to, frac );
if( moveFraction >= moveFractionTotal )
mobile.facing = toFacing & 0xFF;
@@ -221,13 +230,16 @@ namespace OpenRa.Game.Traits
return 0.5f * ( CenterOfCell( from ) + CenterOfCell( to ) );
}
void OnCompleteFirstHalf( Actor self, Mobile mobile )
bool OnCompleteFirstHalf( Actor self, Mobile mobile )
{
if( path.Count > 0 )
{
var nextCell = path[ path.Count - 1 ];
if( ( nextCell - mobile.toCell ) != ( mobile.toCell - mobile.fromCell ) )
{
{
if (!CanEnterCell(nextCell, self))
return false;
path.RemoveAt( path.Count - 1 );
from = BetweenCells( mobile.fromCell, mobile.toCell );
to = BetweenCells( mobile.toCell, nextCell );
@@ -237,8 +249,9 @@ namespace OpenRa.Game.Traits
fromFacing = mobile.facing;
toFacing = Util.GetNearestFacing( fromFacing,
Util.GetFacing( mobile.toCell-mobile.fromCell, fromFacing ) );
OnComplete = OnCompleteFirstHalf;
return;
OnComplete = OnCompleteFirstHalf;
Game.UnitInfluence.Update(mobile);
return true;
}
}
from = BetweenCells( mobile.fromCell, mobile.toCell );
@@ -246,15 +259,17 @@ namespace OpenRa.Game.Traits
CalculateMoveFraction();
fromFacing = toFacing = mobile.facing;
OnComplete = OnCompleteSecondHalf;
mobile.fromCell = mobile.toCell;
mobile.fromCell = mobile.toCell;
return true;
}
void OnCompleteSecondHalf( Actor self, Mobile mobile )
bool OnCompleteSecondHalf( Actor self, Mobile mobile )
{
moveFractionTotal = 0;
self.CenterLocation = CenterOfCell( mobile.toCell );
OnComplete = null;
mobile.fromCell = mobile.toCell;
mobile.fromCell = mobile.toCell;
return true;
}
public void Cancel( Actor self, Mobile mobile )

View File

@@ -9,15 +9,17 @@ namespace OpenRa.Game
class UiOverlay
{
SpriteRenderer spriteRenderer;
Sprite buildOk;
Sprite buildBlocked;
Sprite buildOk, buildBlocked, unitDebug;
public static bool ShowUnitDebug = false;
public UiOverlay(SpriteRenderer spriteRenderer)
{
this.spriteRenderer = spriteRenderer;
buildOk = SynthesizeTile(0x80);
buildBlocked = SynthesizeTile(0xe6);
buildBlocked = SynthesizeTile(0xe6);
unitDebug = SynthesizeTile(0x7c);
}
static Sprite SynthesizeTile(byte paletteIndex)
@@ -32,7 +34,13 @@ namespace OpenRa.Game
}
public void Draw()
{
{
if (ShowUnitDebug)
for (var j = 0; j < 128; j++)
for (var i = 0; i < 128; i++)
if (Game.UnitInfluence.GetUnitAt(new int2(i, j)) != null)
spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0);
if (!hasOverlay) return;
var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo[name];

View File

@@ -9,7 +9,12 @@ namespace OpenRa.Game
class UnitInfluenceMap
{
Actor[,] influence = new Actor[128, 128];
readonly int2 searchDistance = new int2(1, 1);
readonly int2 searchDistance = new int2(2,2);
public UnitInfluenceMap()
{
Game.world.ActorRemoved += a => Remove(a.traits.GetOrDefault<Mobile>());
}
public void Tick()
{
@@ -30,6 +35,8 @@ namespace OpenRa.Game
public void Remove(Mobile a)
{
if (a == null) return;
var min = int2.Max(new int2(0, 0), a.self.Location - searchDistance);
var max = int2.Min(new int2(128, 128), a.self.Location + searchDistance);