Skip to content

Commit

Permalink
Merge pull request #276 from tzachshabtay/XY_Fixes
Browse files Browse the repository at this point in the history
Fix matching areas didn't use world position
  • Loading branch information
tzachshabtay committed Mar 26, 2018
2 parents c4373ad + bb111aa commit c917728
Show file tree
Hide file tree
Showing 47 changed files with 1,043 additions and 464 deletions.
1 change: 1 addition & 0 deletions Source/AGS.API/AGS.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
<Compile Include="Game\IRepeatedlyExecuteEventArgs.cs" />
<Compile Include="Misc\Events\ClaimEventToken.cs" />
<Compile Include="Graphics\Effects\ISaturationEffectComponent.cs" />
<Compile Include="Objects\IWorldPositionComponent.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup />
Expand Down
4 changes: 2 additions & 2 deletions Source/AGS.API/Audio/ISoundEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public interface ISoundEmitter : ISoundPlayer
IObject Object { set; }

/// <summary>
/// Gets or sets the translate component (for binding to location).
/// Gets or sets the world position component (for binding to location).
/// You can set the Object property instead a short-hand convience.
/// </summary>
/// <value>The translate.</value>
ITranslate Translate { get; set; }
IWorldPositionComponent WorldPosition { get; set; }

/// <summary>
/// Gets or sets the room component, for the emitter to not play the sound if the entity is not in currently rendered room.
Expand Down
5 changes: 5 additions & 0 deletions Source/AGS.API/Graphics/Logic/DisplayList/IDisplayList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ public interface IDisplayList
/// <returns>The display list.</returns>
/// <param name="viewport">Viewport.</param>
List<IObject> GetDisplayList(IViewport viewport);

/// <summary>
/// Update the display list (this is called every tick by the game engine itself).
/// </summary>
void Update();
}
}
24 changes: 12 additions & 12 deletions Source/AGS.API/Input/MousePosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public float GetViewportX(IViewport viewport)
var parentBoundingBoxes = viewport.Parent?.GetBoundingBoxes(_mainViewport);
if (parentBoundingBoxes != null)
{
projectLeft += parentBoundingBoxes.RenderBox.MinX;
projectRight += parentBoundingBoxes.RenderBox.MinX;
projectLeft += parentBoundingBoxes.ViewportBox.MinX;
projectRight += parentBoundingBoxes.ViewportBox.MinX;
}

float x = MathUtils.Lerp(projectLeft, 0f, projectRight, VirtualResolution.Width, XWindow);
Expand All @@ -83,8 +83,8 @@ public float GetViewportY(IViewport viewport)
var parentBoundingBoxes = viewport.Parent?.GetBoundingBoxes(_mainViewport);
if (parentBoundingBoxes != null)
{
projectBottom -= parentBoundingBoxes.RenderBox.MinY;
projectTop -= parentBoundingBoxes.RenderBox.MinY;
projectBottom -= parentBoundingBoxes.ViewportBox.MinY;
projectTop -= parentBoundingBoxes.ViewportBox.MinY;
}

float y = MathUtils.Lerp(projectBottom, 0f, projectTop, VirtualResolution.Height, YWindow);
Expand All @@ -109,10 +109,10 @@ public Vector2 GetProjectedPoint(IViewport viewport, IObject projectedInto)
var parentBoundingBoxes = viewport.Parent?.GetBoundingBoxes(_mainViewport);
if (parentBoundingBoxes != null)
{
projectLeft += parentBoundingBoxes.RenderBox.MinX;
projectRight += parentBoundingBoxes.RenderBox.MinX;
projectBottom -= parentBoundingBoxes.RenderBox.MinY;
projectTop -= parentBoundingBoxes.RenderBox.MinY;
projectLeft += parentBoundingBoxes.ViewportBox.MinX;
projectRight += parentBoundingBoxes.ViewportBox.MinX;
projectBottom -= parentBoundingBoxes.ViewportBox.MinY;
projectTop -= parentBoundingBoxes.ViewportBox.MinY;
}
float y = MathUtils.Lerp(projectTop, VirtualResolution.Height, projectBottom, 0f, YWindow);
float x = MathUtils.Lerp(projectLeft, 0f, projectRight, VirtualResolution.Width, XWindow);
Expand All @@ -124,11 +124,11 @@ public Vector2 GetProjectedPoint(IViewport viewport, IObject projectedInto)
x = xyz.X;
y = xyz.Y;

var boundingBoxes = projectedInto.TreeNode.Parent?.GetBoundingBoxes(viewport);
if (boundingBoxes != null && boundingBoxes.RenderBox.IsValid)
var hitTestBox = projectedInto.TreeNode.Parent?.WorldBoundingBox;
if (hitTestBox?.IsValid ?? false)
{
x -= boundingBoxes.HitTestBox.MinX;
y -= boundingBoxes.HitTestBox.MinY;
x -= hitTestBox.Value.MinX;
y -= hitTestBox.Value.MinY;
}
var renderLayer = projectedInto.RenderLayer;
if (renderLayer?.IndependentResolution != null)
Expand Down
24 changes: 12 additions & 12 deletions Source/AGS.API/Misc/Geometry/AGSBoundingBoxes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ public class AGSBoundingBoxes
#region AGSBoundingBoxes implementation

/// <summary>
/// Gets or sets the render box used for rendering the entity.
/// Gets or sets the bounding box in viewport coordinages (used for rendering the entity).
/// This should be only set from the engine.
/// </summary>
/// <value>The render box.</value>
public AGSBoundingBox RenderBox { get; set; }
public AGSBoundingBox ViewportBox { get; set; }

/// <summary>
/// Gets or sets the hit-test box used for collision checks.
/// Gets or sets the bounding box in world coordinates (used for collision checks).
/// This should be only set from the engine.
/// </summary>
/// <value>The hit-test box.</value>
public AGSBoundingBox HitTestBox { get; set; }
public AGSBoundingBox WorldBox { get; set; }

/// <summary>
/// Gets or sets the texture box which specifies which part of the texture is used on the render box.
Expand All @@ -32,12 +32,12 @@ public class AGSBoundingBoxes
public FourCorners<Vector2> TextureBox { get; set; }

/// <summary>
/// Gets or sets the render box before the object was cropped.
/// This will usually be the same as the render box unless the object was actually cropped (i.e if
/// Gets or sets the viewport bounding box before the object was cropped.
/// This will usually be the same as the viewport box unless the object was actually cropped (i.e if
/// it had the <see cref="ICropSelfComponent"/> attached, maybe inside a scrolling panel, for example).
/// </summary>
/// <value>The pre crop render box.</value>
public AGSBoundingBox PreCropRenderBox { get; set; }
public AGSBoundingBox PreCropViewportBox { get; set; }

#endregion

Expand All @@ -48,15 +48,15 @@ public bool Equals(AGSBoundingBoxes boxes)
if (TextureBox == null && boxes.TextureBox != null) return false;
if (TextureBox != null && boxes.TextureBox == null) return false;
if (TextureBox != null && !TextureBox.Equals(boxes.TextureBox)) return false;
return RenderBox.Equals(boxes.RenderBox) && HitTestBox.Equals(boxes.HitTestBox)
&& PreCropRenderBox.Equals(boxes.PreCropRenderBox);
return ViewportBox.Equals(boxes.ViewportBox) && WorldBox.Equals(boxes.WorldBox)
&& PreCropViewportBox.Equals(boxes.PreCropViewportBox);
}

public void CopyFrom(AGSBoundingBoxes boxes)
{
RenderBox = boxes.RenderBox;
HitTestBox = boxes.HitTestBox;
PreCropRenderBox = boxes.PreCropRenderBox;
ViewportBox = boxes.ViewportBox;
WorldBox = boxes.WorldBox;
PreCropViewportBox = boxes.PreCropViewportBox;
TextureBox = boxes.TextureBox;
}
}
Expand Down
9 changes: 7 additions & 2 deletions Source/AGS.API/Objects/Collisions/IBoundingBoxComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
public interface IBoundingBoxComponent : IComponent
{
/// <summary>
/// Gets or sets the bounding box which surrounds the entity.
/// The bounding box is set by the engine, and should not be set by the user.
/// Gets the bounding boxes which surrounds the entity.
/// </summary>
/// <value>The bounding boxes.</value>
AGSBoundingBoxes GetBoundingBoxes(IViewport viewport);

/// <summary>
/// Gets the entity's bounding box in world co-ordinates (can be used for hit-tests).
/// </summary>
/// <value>The world bounding box.</value>
AGSBoundingBox WorldBoundingBox { get; }

/// <summary>
/// An event which fires whenever the bounding boxes for the entity change.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Source/AGS.API/Objects/IModelMatrixComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public struct ModelMatrices
[RequiredComponent(typeof(IHasRoomComponent))]
[RequiredComponent(typeof(IDrawableInfoComponent))]
[RequiredComponent(typeof(IInObjectTreeComponent))]
[RequiredComponent(typeof(IWorldPositionComponent))]
public interface IModelMatrixComponent : IComponent
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/AGS.API/Objects/IObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public interface IObject : IEntity, IHasRoomComponent, IAnimationComponent, IInObjectTreeComponent, IColliderComponent,
IVisibleComponent, IEnabledComponent, ICustomPropertiesComponent, IDrawableInfoComponent,
IShaderComponent, ITranslateComponent, IImageComponent, IScaleComponent, IRotateComponent,
IPixelPerfectComponent, IHasModelMatrix, IModelMatrixComponent, IBoundingBoxComponent
IPixelPerfectComponent, IHasModelMatrix, IModelMatrixComponent, IBoundingBoxComponent, IWorldPositionComponent
{
}
}
Expand Down
16 changes: 13 additions & 3 deletions Source/AGS.API/Objects/ITranslateComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,34 @@ public interface ITranslate : INotifyPropertyChanged
{
/// <summary>
/// Gets or sets the location.
/// (X,Y) are used to place the entity/sprite in 2D space (in room coordinates).
/// (X,Y) are used to place the entity/sprite in 2D space (in local coordinates).
/// The local coordinates are the world coordinates if the entity has no parent, otherwise its
/// the coordinates relative to the parent.
///
/// Z is used for deciding how the entities/sprites are ordered in 2D space (higher Z in front).
/// If Z and Y are the same when setting the location, then Z will be bound to Y: whenever Y moves,
/// Z moves, which will make entities closer to the bottom appear in front, which is the desired behavior
/// in most scenarios. You can change this behavior by explicitly setting Z to a different value.
/// </summary>
/// <seealso cref="IWorldPositionComponent"/>
/// <value>The location.</value>
ILocation Location { get; set; }

/// <summary>
/// Gets or sets the x coordinate (in room coordinates).
/// Gets or sets the x coordinate (in local coordinates).
/// The local coordinates are the world coordinates if the entity has no parent, otherwise its
/// the coordinates relative to the parent.
/// </summary>
/// <seealso cref="IWorldPositionComponent.WorldX"/>
/// <value>The x.</value>
float X { get; set; }

/// <summary>
/// Gets or sets the y coordinate (in room coordinates).
/// Gets or sets the y coordinate (in local coordinates).
/// The local coordinates are the world coordinates if the entity has no parent, otherwise its
/// the coordinates relative to the parent.
/// </summary>
/// <seealso cref="IWorldPositionComponent.WorldY"/>
/// <value>The y.</value>
float Y { get; set; }

Expand Down
33 changes: 33 additions & 0 deletions Source/AGS.API/Objects/IWorldPositionComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
namespace AGS.API
{
/// <summary>
/// Allows getting the world position for entities.
/// </summary>
public interface IWorldPositionComponent : IComponent
{
/// <summary>
/// Get the X of an entity in world coordinates.
/// In case the entity has no parents, the value will be the same as <see cref="ITranslate.X"/>,
/// but if the entity has a parent, then WorldX will give you the absolute world value (as opposed to relative to the parent).
/// </summary>
/// <value>The world x.</value>
float WorldX { get; }

/// <summary>
/// Get the Y of an entity in world coordinates.
/// In case the entity has no parents, the value will be the same as <see cref="ITranslate.Y"/>,
/// but if the entity has a parent, then WorldY will give you the absolute world value (as opposed to relative to the parent).
/// </summary>
/// <value>The world y.</value>
float WorldY { get; }

/// <summary>
/// Get the (X,Y) of an entity in world coordinates.
/// In case the entity has no parents, the value will be the same as <see cref="ITranslate.Location"/>,
/// but if the entity has a parent, then WorldXY will give you the absolute world value (as opposed to relative to the parent).
/// </summary>
/// <value>The world y.</value>
PointF WorldXY { get; }
}
}
97 changes: 97 additions & 0 deletions Source/Engine/AGS.Engine/AGS.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,101 @@
<HintPath>..\..\..\DLLs\protobuf-net.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Update="ComponentsFramework\Templates\AGSButton.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AGSButton.generated.cs</LastGenOutput>
</None>
<None Update="ComponentsFramework\Templates\AGSCharacter.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AGSCharacter.generated.cs</LastGenOutput>
</None>
<None Update="ComponentsFramework\Templates\AGSCheckbox.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AGSCheckbox.generated.cs</LastGenOutput>
</None>
<None Update="ComponentsFramework\Templates\AGSComboBox.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AGSComboBox.generated.cs</LastGenOutput>
</None>
<None Update="ComponentsFramework\Templates\AGSInventoryWindow.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AGSInventoryWindow.generated.cs</LastGenOutput>
</None>
<None Update="ComponentsFramework\Templates\AGSLabel.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AGSLabel.generated.cs</LastGenOutput>
</None>
<None Update="ComponentsFramework\Templates\AGSObject.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AGSObject.generated.cs</LastGenOutput>
</None>
<None Update="ComponentsFramework\Templates\AGSPanel.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AGSPanel.generated.cs</LastGenOutput>
</None>
<None Update="ComponentsFramework\Templates\AGSSlider.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AGSSlider.generated.cs</LastGenOutput>
</None>
<None Update="ComponentsFramework\Templates\AGSTextbox.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AGSTextbox.generated.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Compile Update="ComponentsFramework\Templates\AGSButton.generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AGSButton.tt</DependentUpon>
</Compile>
<Compile Update="ComponentsFramework\Templates\AGSCharacter.generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AGSCharacter.tt</DependentUpon>
</Compile>
<Compile Update="ComponentsFramework\Templates\AGSCheckbox.generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AGSCheckbox.tt</DependentUpon>
</Compile>
<Compile Update="ComponentsFramework\Templates\AGSComboBox.generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AGSComboBox.tt</DependentUpon>
</Compile>
<Compile Update="ComponentsFramework\Templates\AGSInventoryWindow.generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AGSInventoryWindow.tt</DependentUpon>
</Compile>
<Compile Update="ComponentsFramework\Templates\AGSLabel.generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AGSLabel.tt</DependentUpon>
</Compile>
<Compile Update="ComponentsFramework\Templates\AGSObject.generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AGSObject.tt</DependentUpon>
</Compile>
<Compile Update="ComponentsFramework\Templates\AGSPanel.generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AGSPanel.tt</DependentUpon>
</Compile>
<Compile Update="ComponentsFramework\Templates\AGSSlider.generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AGSSlider.tt</DependentUpon>
</Compile>
<Compile Update="ComponentsFramework\Templates\AGSTextbox.generated.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AGSTextbox.tt</DependentUpon>
</Compile>
</ItemGroup>
</Project>

0 comments on commit c917728

Please sign in to comment.