Skip to content

Commit

Permalink
[HaCreator] optimisation -- from the last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lastbattle committed Jan 11, 2021
1 parent 34199ac commit 355a80a
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions HaCreator/MapSimulator/MapSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class MapSimulator : Microsoft.Xna.Framework.Game
// Boundary, borders
private Rectangle vr_fieldBoundary;
private const int VR_BORDER_WIDTHHEIGHT = 600; // the height or width of the VR border
private bool bDrawVRBorderLeftRight = false;
private Texture2D texture_vrBoundaryRectLeft, texture_vrBoundaryRectRight, texture_vrBoundaryRectTop, texture_vrBoundaryRectBottom;

// Minimap
Expand Down Expand Up @@ -416,11 +417,33 @@ protected override void LoadContent()
SetCameraMoveY(true, true, 0);

///////////// Border
// Left
texture_vrBoundaryRectLeft = CreateVRBorder(VR_BORDER_WIDTHHEIGHT, vr_fieldBoundary.Height, _DxDeviceManager.GraphicsDevice);
texture_vrBoundaryRectRight = CreateVRBorder(VR_BORDER_WIDTHHEIGHT, vr_fieldBoundary.Height, _DxDeviceManager.GraphicsDevice);
texture_vrBoundaryRectTop = CreateVRBorder(vr_fieldBoundary.Width * 2, VR_BORDER_WIDTHHEIGHT, _DxDeviceManager.GraphicsDevice);
texture_vrBoundaryRectBottom = CreateVRBorder(vr_fieldBoundary.Width * 2, VR_BORDER_WIDTHHEIGHT, _DxDeviceManager.GraphicsDevice);
int leftRightVRDifference = (int)((vr_fieldBoundary.Right - vr_fieldBoundary.Left) * RenderObjectScaling);
if (leftRightVRDifference < RenderWidth) // viewing range is smaller than the render width..
{
this.bDrawVRBorderLeftRight = true; // flag

this.texture_vrBoundaryRectLeft = CreateVRBorder(VR_BORDER_WIDTHHEIGHT, vr_fieldBoundary.Height, _DxDeviceManager.GraphicsDevice);
this.texture_vrBoundaryRectRight = CreateVRBorder(VR_BORDER_WIDTHHEIGHT, vr_fieldBoundary.Height, _DxDeviceManager.GraphicsDevice);
this.texture_vrBoundaryRectTop = CreateVRBorder(vr_fieldBoundary.Width * 2, VR_BORDER_WIDTHHEIGHT, _DxDeviceManager.GraphicsDevice);
this.texture_vrBoundaryRectBottom = CreateVRBorder(vr_fieldBoundary.Width * 2, VR_BORDER_WIDTHHEIGHT, _DxDeviceManager.GraphicsDevice);
}

/*
DXObject leftDXVRObject = new DXObject(
vr_fieldBoundary.Left - VR_BORDER_WIDTHHEIGHT,
vr_fieldBoundary.Top,
texture_vrBoundaryRectLeft);
this.leftVRBorderDrawableItem = new BaseDXDrawableItem(leftDXVRObject, false);
//new BackgroundItem(int cx, int cy, int rx, int ry, BackgroundType.Regular, 255, true, leftDXVRObject, false, (int) RenderResolution.Res_All);
// Right VR
DXObject rightDXVRObject = new DXObject(
vr_fieldBoundary.Right,
vr_fieldBoundary.Top,
texture_vrBoundaryRectRight);
this.rightVRBorderDrawableItem = new BaseDXDrawableItem(rightDXVRObject, false);
*/
///////////// End Border

// Debug items
System.Drawing.Bitmap bitmap_debug = new System.Drawing.Bitmap(1, 1);
Expand Down Expand Up @@ -757,12 +780,11 @@ protected override void Draw(GameTime gameTime)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DrawVRFieldBorder(SpriteBatch sprite)
{
if (vr_fieldBoundary.X == 0 && vr_fieldBoundary.Y == 0)
if ((vr_fieldBoundary.X == 0 && vr_fieldBoundary.Y == 0) || !bDrawVRBorderLeftRight)
return;

Color borderColor = Color.Black;


// Draw top line
/* sprite.Draw(texture_vrBoundaryRectTop,
new Rectangle(
Expand Down Expand Up @@ -798,6 +820,7 @@ private void DrawVRFieldBorder(SpriteBatch sprite)
VR_BORDER_WIDTHHEIGHT,
vr_fieldBoundary.Height),
borderColor);

}

/// <summary>
Expand Down Expand Up @@ -951,7 +974,7 @@ private void SetCameraMoveX(bool bIsLeftKeyPressed, bool bIsRightKeyPressed, int
* Viewing Width = 1024
* Relative viewing center = vr.Center - (Viewing Width / 2)
*/
mapShiftX = ((leftRightVRDifference / 2) + (int)(vr_fieldBoundary.Left * RenderObjectScaling)) - (RenderWidth / 2);
this.mapShiftX = ((leftRightVRDifference / 2) + (int)(vr_fieldBoundary.Left * RenderObjectScaling)) - (RenderWidth / 2);
}
else
{
Expand All @@ -961,12 +984,12 @@ private void SetCameraMoveX(bool bIsLeftKeyPressed, bool bIsRightKeyPressed, int

if (bIsLeftKeyPressed)
{
mapShiftX = Math.Max((int)(vr_fieldBoundary.Left * RenderObjectScaling), mapShiftX - moveOffset);
this.mapShiftX = Math.Max((int)(vr_fieldBoundary.Left * RenderObjectScaling), mapShiftX - moveOffset);

}
else if (bIsRightKeyPressed)
{
mapShiftX = Math.Min((int)((vr_fieldBoundary.Right - (RenderWidth / RenderObjectScaling))), mapShiftX + moveOffset);
this.mapShiftX = Math.Min((int)((vr_fieldBoundary.Right - (RenderWidth / RenderObjectScaling))), mapShiftX + moveOffset);
}
}
}
Expand All @@ -983,7 +1006,7 @@ private void SetCameraMoveY(bool bIsUpKeyPressed, bool bIsDownKeyPressed, int mo
int topDownVRDifference = (int)((vr_fieldBoundary.Bottom - vr_fieldBoundary.Top) * RenderObjectScaling);
if (topDownVRDifference < RenderHeight)
{
mapShiftY = ((topDownVRDifference / 2) + (int)(vr_fieldBoundary.Top * RenderObjectScaling)) - (RenderHeight / 2);
this.mapShiftY = ((topDownVRDifference / 2) + (int)(vr_fieldBoundary.Top * RenderObjectScaling)) - (RenderHeight / 2);
}
else
{
Expand All @@ -995,11 +1018,11 @@ private void SetCameraMoveY(bool bIsUpKeyPressed, bool bIsDownKeyPressed, int mo

if (bIsUpKeyPressed)
{
mapShiftY = Math.Max((int)(vr_fieldBoundary.Top), mapShiftY - moveOffset);
this.mapShiftY = Math.Max((int)(vr_fieldBoundary.Top), mapShiftY - moveOffset);
}
else if (bIsDownKeyPressed)
{
mapShiftY = Math.Min((int)((vr_fieldBoundary.Bottom - (RenderHeight / RenderObjectScaling))), mapShiftY + moveOffset);
this.mapShiftY = Math.Min((int)((vr_fieldBoundary.Bottom - (RenderHeight / RenderObjectScaling))), mapShiftY + moveOffset);
}
}
}
Expand Down

0 comments on commit 355a80a

Please sign in to comment.