Skip to content

Commit

Permalink
Implemented SpriteRenderComponent, sprite-based rendering of an entity
Browse files Browse the repository at this point in the history
This adds ISpriteRenderComponent interface and its AGSSpriteRenderComponent implementation. SpriteRenderer is supposed to become a rendering "contractor" for 2D sprite-based components, such as ImageComponent or AnimationComponent.
SpriteRenderComponent stores a reference to ISpriteProvider, from which it receives "current sprite" to draw.
AGSAnimationComponent implements ISpriteProvider.

Moved Border and DebugDrawPivot properties from Animation to SpriteRender component.
Made GLImageRenderer refer to SpriteRenderComponent for drawing (instead of AnimationComponent). It is assumed, that parts of GLImageRenderer rendering function will be merged into SpriteRenderComponent on later stages.
  • Loading branch information
ivan-mogilko committed Jan 25, 2018
1 parent 1f4ff23 commit 95b565a
Show file tree
Hide file tree
Showing 27 changed files with 527 additions and 206 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 @@ -36,6 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Graphics\IImageComponent.cs" />
<Compile Include="Graphics\ISpriteRenderComponent.cs" />
<Compile Include="Objects\Collisions\IPixelPerfectCollidable.cs" />
<Compile Include="Objects\IDraggableComponent.cs" />
<Compile Include="Objects\IRotateComponent.cs" />
Expand Down
13 changes: 0 additions & 13 deletions Source/AGS.API/Graphics/Animations/IAnimationComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,12 @@ public interface IAnimationComponent : IComponent
/// <value>The animation.</value>
IAnimation Animation { get; }

/// <summary>
/// Gets or sets a value indicating whether the pivot (the pivot point for position/rotate/scale) will
/// be drawn on the screen as a cross. This can be used for debugging the game.
/// </summary>
/// <value><c>true</c> if debug draw pivot; otherwise, <c>false</c>.</value>
bool DebugDrawPivot { get; set; }

/// <summary>
/// An event when fires whenever an animation is started on this container.
/// </summary>
/// <value>The event.</value>
IBlockingEvent OnAnimationStarted { get; }

/// <summary>
/// Gets or sets a border that will (optionally) surround the animation.
/// </summary>
/// <value>The border.</value>
IBorderStyle Border { get; set; }

/// <summary>
/// Starts a new animation (this does not wait for the animation to complete).
/// </summary>
Expand Down
48 changes: 48 additions & 0 deletions Source/AGS.API/Graphics/ISpriteRenderComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.ComponentModel;

namespace AGS.API
{
/// <summary>
/// Interface of a single sprite source.
/// </summary>
public interface ISpriteProvider : INotifyPropertyChanged
{
/// <summary>
/// Gets a sprite to work with.
/// </summary>
/// <value>The sprite.</value>
ISprite Sprite { get; }
}

/// <summary>
/// A component that renders an entity using 2D sprites.
/// A sprite and other properties may be set either by user or by other components.
/// </summary>
public interface ISpriteRenderComponent : IComponent
{
/// <summary>
/// Gets sprite to render.
/// </summary>
/// <value>The sprite.</value>
ISprite CurrentSprite { get; }

/// <summary>
/// Gets or sets sprite provider.
/// </summary>
/// <value>The sprite provider implementation.</value>
ISpriteProvider SpriteProvider { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the pivot (the pivot point for position/rotate/scale) will
/// be drawn on the screen as a cross. This can be used for debugging the game.
/// </summary>
/// <value><c>true</c> if debug draw pivot; otherwise, <c>false</c>.</value>
bool DebugDrawPivot { get; set; }

/// <summary>
/// Gets or sets a border that will (optionally) surround the sprite.
/// </summary>
/// <value>The border.</value>
IBorderStyle Border { get; set; }
}
}
2 changes: 1 addition & 1 deletion Source/AGS.API/Objects/IObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// An object is an entity with pre-set components (like location, scale, rotation, animation, etc) which is useful
/// to depict all adventure game objects. Both characters and UI controls are also objects (with additional components).
/// </summary>
public interface IObject : IEntity, IHasRoomComponent, IAnimationComponent, IInObjectTreeComponent, IColliderComponent,
public interface IObject : IEntity, IHasRoomComponent, ISpriteRenderComponent, IAnimationComponent, IInObjectTreeComponent, IColliderComponent,
IVisibleComponent, IEnabledComponent, ICustomPropertiesComponent, IDrawableInfoComponent, IHotspotComponent,
IShaderComponent, ITranslateComponent, IImageComponent, IScaleComponent, IRotateComponent,
IPixelPerfectComponent, IHasModelMatrix, IModelMatrixComponent, IBoundingBoxComponent
Expand Down
2 changes: 2 additions & 0 deletions Source/Engine/AGS.Engine/AGS.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Graphics\Drawing\AGSSpriteRenderComponent.cs" />
<Compile Include="Graphics\Image\AGSHasImage.cs" />
<Compile Include="Graphics\Image\AGSImageComponent.cs" />
<Compile Include="Graphics\Logic\Interfaces\IGLUtils.cs" />
Expand Down Expand Up @@ -213,6 +214,7 @@
<Compile Include="Serialization\AGSSerializationContext.cs" />
<Compile Include="Serialization\Contract.cs" />
<Compile Include="Serialization\Contracts\ContractAnimation.cs" />
<Compile Include="Serialization\Contracts\ContractSpriteRenderComponent.cs" />
<Compile Include="Serialization\Contracts\ContractAnimationConfiguration.cs" />
<Compile Include="Serialization\Contracts\ContractAnimationComponent.cs" />
<Compile Include="Serialization\Contracts\ContractAnimationFrame.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class AGSButton : AGSEntity, IButton
private IUIEvents _uIEvents;
private ISkinComponent _skinComponent;
private IHasRoomComponent _hasRoom;
private ISpriteRenderComponent _spriteRender;
private IAnimationComponent _animationContainer;
private IInObjectTreeComponent _inObjectTree;
private IColliderComponent _collider;
Expand All @@ -44,7 +45,9 @@ public AGSButton(string id, Resolver resolver) : base(id, resolver)
_skinComponent = AddComponent<ISkinComponent>();
Bind<ISkinComponent>(c => _skinComponent = c, _ => {});
_hasRoom = AddComponent<IHasRoomComponent>();
Bind<IHasRoomComponent>(c => _hasRoom = c, _ => {});
Bind<IHasRoomComponent>(c => _hasRoom = c, _ => {});
_spriteRender = AddComponent<ISpriteRenderComponent>();
Bind<ISpriteRenderComponent>(c => _spriteRender = c, _ => { });
_animationContainer = AddComponent<IAnimationComponent>();
Bind<IAnimationComponent>(c => _animationContainer = c, _ => {});
_inObjectTree = AddComponent<IInObjectTreeComponent>();
Expand Down Expand Up @@ -186,30 +189,45 @@ public Task ChangeRoomAsync(IRoom room, Nullable<Single> x, Nullable<Single> y)

#endregion

#region ISpriteRender implementation

public ISprite CurrentSprite
{
get { return _spriteRender.CurrentSprite; }
}

public ISpriteProvider SpriteProvider
{
get { return _spriteRender.SpriteProvider; }
set { _spriteRender.SpriteProvider = value; }
}

public Boolean DebugDrawPivot
{
get { return _spriteRender.DebugDrawPivot; }
set { _spriteRender.DebugDrawPivot = value; }
}

public IBorderStyle Border
{
get { return _spriteRender.Border; }
set { _spriteRender.Border = value; }
}

#endregion

#region IAnimationContainer implementation

public IAnimation Animation
{
get { return _animationContainer.Animation; }
}

public Boolean DebugDrawPivot
{
get { return _animationContainer.DebugDrawPivot; }
set { _animationContainer.DebugDrawPivot = value; }
}

public IBlockingEvent OnAnimationStarted
{
get { return _animationContainer.OnAnimationStarted; }
}

public IBorderStyle Border
{
get { return _animationContainer.Border; }
set { _animationContainer.Border = value; }
}

public void StartAnimation(IAnimation animation)
{
_animationContainer.StartAnimation(animation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace AGS.Engine
public partial class AGSCharacter : AGSEntity, ICharacter
{
private IHasRoomComponent _hasRoom;
private ISpriteRenderComponent _spriteRender;
private IAnimationComponent _animationContainer;
private IInObjectTreeComponent _inObjectTree;
private IColliderComponent _collider;
Expand All @@ -43,7 +44,9 @@ public partial class AGSCharacter : AGSEntity, ICharacter
public AGSCharacter(string id, Resolver resolver, IOutfit outfit) : base(id, resolver)
{
_hasRoom = AddComponent<IHasRoomComponent>();
Bind<IHasRoomComponent>(c => _hasRoom = c, _ => {});
Bind<IHasRoomComponent>(c => _hasRoom = c, _ => {});
_spriteRender = AddComponent<ISpriteRenderComponent>();
Bind<ISpriteRenderComponent>(c => _spriteRender = c, _ => { });
_animationContainer = AddComponent<IAnimationComponent>();
Bind<IAnimationComponent>(c => _animationContainer = c, _ => {});
_inObjectTree = AddComponent<IInObjectTreeComponent>();
Expand Down Expand Up @@ -120,30 +123,45 @@ public IBlockingEvent OnRoomChanged

#endregion

#region ISpriteRender implementation

public ISprite CurrentSprite
{
get { return _spriteRender.CurrentSprite; }
}

public ISpriteProvider SpriteProvider
{
get { return _spriteRender.SpriteProvider; }
set { _spriteRender.SpriteProvider = value; }
}

public Boolean DebugDrawPivot
{
get { return _spriteRender.DebugDrawPivot; }
set { _spriteRender.DebugDrawPivot = value; }
}

public IBorderStyle Border
{
get { return _spriteRender.Border; }
set { _spriteRender.Border = value; }
}

#endregion

#region IAnimationContainer implementation

public IAnimation Animation
{
get { return _animationContainer.Animation; }
}

public Boolean DebugDrawPivot
{
get { return _animationContainer.DebugDrawPivot; }
set { _animationContainer.DebugDrawPivot = value; }
}

public IBlockingEvent OnAnimationStarted
{
get { return _animationContainer.OnAnimationStarted; }
}

public IBorderStyle Border
{
get { return _animationContainer.Border; }
set { _animationContainer.Border = value; }
}

public void StartAnimation(IAnimation animation)
{
_animationContainer.StartAnimation(animation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class AGSCheckBox : AGSEntity, ICheckBox
private IUIEvents _uIEvents;
private ISkinComponent _skinComponent;
private IHasRoomComponent _hasRoom;
private ISpriteRenderComponent _spriteRender;
private IAnimationComponent _animationContainer;
private IInObjectTreeComponent _inObjectTree;
private IColliderComponent _collider;
Expand Down Expand Up @@ -45,6 +46,8 @@ public AGSCheckBox(string id, Resolver resolver) : base(id, resolver)
_hasRoom = AddComponent<IHasRoomComponent>();
Bind<IHasRoomComponent>(c => _hasRoom = c, _ => {});
_animationContainer = AddComponent<IAnimationComponent>();
_spriteRender = AddComponent<ISpriteRenderComponent>();
Bind<ISpriteRenderComponent>(c => _spriteRender = c, _ => { });
Bind<IAnimationComponent>(c => _animationContainer = c, _ => {});
_inObjectTree = AddComponent<IInObjectTreeComponent>();
Bind<IInObjectTreeComponent>(c => _inObjectTree = c, _ => {});
Expand Down Expand Up @@ -183,30 +186,45 @@ public Task ChangeRoomAsync(IRoom room, Nullable<Single> x, Nullable<Single> y)

#endregion

#region ISpriteRender implementation

public ISprite CurrentSprite
{
get { return _spriteRender.CurrentSprite; }
}

public ISpriteProvider SpriteProvider
{
get { return _spriteRender.SpriteProvider; }
set { _spriteRender.SpriteProvider = value; }
}

public Boolean DebugDrawPivot
{
get { return _spriteRender.DebugDrawPivot; }
set { _spriteRender.DebugDrawPivot = value; }
}

public IBorderStyle Border
{
get { return _spriteRender.Border; }
set { _spriteRender.Border = value; }
}

#endregion

#region IAnimationContainer implementation

public IAnimation Animation
{
get { return _animationContainer.Animation; }
}

public Boolean DebugDrawPivot
{
get { return _animationContainer.DebugDrawPivot; }
set { _animationContainer.DebugDrawPivot = value; }
}

public IBlockingEvent OnAnimationStarted
{
get { return _animationContainer.OnAnimationStarted; }
}

public IBorderStyle Border
{
get { return _animationContainer.Border; }
set { _animationContainer.Border = value; }
}

public void StartAnimation(IAnimation animation)
{
_animationContainer.StartAnimation(animation);
Expand Down
Loading

0 comments on commit 95b565a

Please sign in to comment.