Skip to content

Commit

Permalink
feat: [クラスラッパー]描画まわりの機能を充実
Browse files Browse the repository at this point in the history
  • Loading branch information
automatic9045 committed Oct 23, 2023
1 parent 81dd0ae commit 1c1b057
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 6 deletions.
1 change: 1 addition & 0 deletions Libs/BveTypes/BveTypes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<Compile Include="ClassWrappers\Public\DoorState.cs" />
<Compile Include="ClassWrappers\Public\DrawDistanceManager.cs" />
<Compile Include="ClassWrappers\Public\Ecb.cs" />
<Compile Include="ClassWrappers\Public\IDrawable.cs" />
<Compile Include="ClassWrappers\Public\StationText.cs" />
<Compile Include="ClassWrappers\Public\SpeedLimitText.cs" />
<Compile Include="ClassWrappers\Public\GraphCurve.cs" />
Expand Down
17 changes: 12 additions & 5 deletions Libs/BveTypes/ClassWrappers/Public/AssistantBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace BveTypes.ClassWrappers
/// <summary>
/// すべての補助表示の基本クラスを表します。
/// </summary>
public class AssistantBase : ClassWrapperBase
public class AssistantBase : ClassWrapperBase, IDrawable
{
[InitializeClassWrapper]
private static void Initialize(BveTypeSet bveTypes)
Expand All @@ -31,6 +31,8 @@ private static void Initialize(BveTypeSet bveTypes)
DisplayAreaGetMethod = members.GetSourcePropertyGetterOf(nameof(DisplayArea));

DrawMethod = members.GetSourceMethodOf(nameof(Draw));
OnDeviceLostMethod = members.GetSourceMethodOf(nameof(OnDeviceLost));
OnDeviceResetMethod = members.GetSourceMethodOf(nameof(OnDeviceReset));
}

/// <summary>
Expand Down Expand Up @@ -68,9 +70,14 @@ public Color BackgroundColor
/// <summary>
/// 補助表示を描画します。
/// </summary>
public void Draw()
{
DrawMethod.Invoke(Src, null);
}
public void Draw() => DrawMethod.Invoke(Src, null);

private static FastMethod OnDeviceLostMethod;
/// <inheritdoc/>
public void OnDeviceLost() => OnDeviceLostMethod.Invoke(Src, null);

private static FastMethod OnDeviceResetMethod;
/// <inheritdoc/>
public void OnDeviceReset() => OnDeviceResetMethod.Invoke(Src, null);
}
}
18 changes: 18 additions & 0 deletions Libs/BveTypes/ClassWrappers/Public/AssistantDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ private static void Initialize(BveTypeSet bveTypes)
ClassMemberSet members = bveTypes.GetClassInfoOf<AssistantDrawer>();

ItemsGetMethod = members.GetSourcePropertyGetterOf(nameof(Items));

DrawMethod = members.GetSourceMethodOf(nameof(Draw));
OnDeviceLostMethod = members.GetSourceMethodOf(nameof(OnDeviceLost));
OnDeviceResetMethod = members.GetSourceMethodOf(nameof(OnDeviceReset));
}

/// <summary>
Expand All @@ -47,5 +51,19 @@ protected AssistantDrawer(object src) : base(src)
/// 補助表示の一覧を取得します。
/// </summary>
public WrappedList<AssistantBase> Items => WrappedList<AssistantBase>.FromSource(ItemsGetMethod.Invoke(Src, null));

private static FastMethod DrawMethod;
/// <summary>
/// 全ての補助表示を描画します。
/// </summary>
public void Draw() => DrawMethod.Invoke(Src, null);

private static FastMethod OnDeviceLostMethod;
/// <inheritdoc/>
public void OnDeviceLost() => OnDeviceLostMethod.Invoke(Src, null);

private static FastMethod OnDeviceResetMethod;
/// <inheritdoc/>
public void OnDeviceReset() => OnDeviceResetMethod.Invoke(Src, null);
}
}
58 changes: 58 additions & 0 deletions Libs/BveTypes/ClassWrappers/Public/CameraLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Threading.Tasks;

using FastMember;
using SlimDX;
using System.Drawing;
using TypeWrapping;

namespace BveTypes.ClassWrappers
Expand All @@ -18,6 +20,18 @@ public class CameraLocation : ClassWrapperBase
private static void Initialize(BveTypeSet bveTypes)
{
ClassMemberSet members = bveTypes.GetClassInfoOf<CameraLocation>();

TransformFromBlockGetMethod = members.GetSourcePropertyGetterOf(nameof(TransformFromBlock));
TransformFromBlockSetMethod = members.GetSourcePropertySetterOf(nameof(TransformFromBlock));

TransformFromCameraHomePositionGetMethod = members.GetSourcePropertyGetterOf(nameof(TransformFromCameraHomePosition));
TransformFromCameraHomePositionSetMethod = members.GetSourcePropertySetterOf(nameof(TransformFromCameraHomePosition));

PlaneGetMethod = members.GetSourcePropertyGetterOf(nameof(Plane));
PlaneSetMethod = members.GetSourcePropertySetterOf(nameof(Plane));

SpeedGetMethod = members.GetSourcePropertyGetterOf(nameof(Speed));
SpeedSetMethod = members.GetSourcePropertySetterOf(nameof(Speed));
}

/// <summary>
Expand All @@ -35,5 +49,49 @@ protected CameraLocation(object src) : base(src)
/// <returns>オリジナル オブジェクトをラップした <see cref="CameraLocation"/> クラスのインスタンス。</returns>
[CreateClassWrapperFromSource]
public static CameraLocation FromSource(object src) => src is null ? null : new CameraLocation(src);

private static FastMethod TransformFromBlockGetMethod;
private static FastMethod TransformFromBlockSetMethod;
/// <summary>
/// 現在位置のストラクチャーブロックの原点から見たときの、このカメラの相対位置を表すワールド変換行列を取得・設定します。
/// </summary>
public Matrix TransformFromBlock
{
get => TransformFromBlockGetMethod.Invoke(Src, null);
set => TransformFromBlockSetMethod.Invoke(Src, new object[] { value });
}

private static FastMethod TransformFromCameraHomePositionGetMethod;
private static FastMethod TransformFromCameraHomePositionSetMethod;
/// <summary>
/// このカメラのホーム位置から見たときの、現在のカメラの相対位置を表す変換行列を取得・設定します。
/// </summary>
public Matrix TransformFromCameraHomePosition
{
get => TransformFromCameraHomePositionGetMethod.Invoke(Src, null);
set => TransformFromCameraHomePositionSetMethod.Invoke(Src, new object[] { value });
}

private static FastMethod PlaneGetMethod;
private static FastMethod PlaneSetMethod;
/// <summary>
/// このカメラのプレーンを取得・設定します。
/// </summary>
public RectangleF Plane
{
get => PlaneGetMethod.Invoke(Src, null);
set => PlaneSetMethod.Invoke(Src, new object[] { value });
}

private static FastMethod SpeedGetMethod;
private static FastMethod SpeedSetMethod;
/// <summary>
/// このカメラが移動する速度 [m/s] を取得・設定します。
/// </summary>
public Vector3 Speed
{
get => SpeedGetMethod.Invoke(Src, null);
set => SpeedSetMethod.Invoke(Src, new object[] { value });
}
}
}
9 changes: 9 additions & 0 deletions Libs/BveTypes/ClassWrappers/Public/Direct3DProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ private static void Initialize(BveTypeSet bveTypes)
DeviceGetMethod = members.GetSourcePropertyGetterOf(nameof(Device));
PresentParametersGetMethod = members.GetSourcePropertyGetterOf(nameof(PresentParameters));
Direct3DGetMethod = members.GetSourcePropertyGetterOf(nameof(Direct3D));

RenderMethod = members.GetSourceMethodOf(nameof(Render));
}

/// <summary>
Expand Down Expand Up @@ -68,5 +70,12 @@ protected Direct3DProvider(object src) : base(src)
/// <see cref="SlimDX.Direct3D9.Direct3D"/> を取得します。
/// </summary>
public Direct3D Direct3D => (Direct3D)Direct3DGetMethod.Invoke(Src, null);

private static FastMethod RenderMethod;
/// <summary>
/// 指定したオブジェクトへ描画します。
/// </summary>
/// <param name="target">描画のターゲット。</param>
public void Render(IDrawable target) => RenderMethod.Invoke(Src, new object[] { ((ClassWrapperBase)target).Src });
}
}
17 changes: 16 additions & 1 deletion Libs/BveTypes/ClassWrappers/Public/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace BveTypes.ClassWrappers
/// <summary>
/// メインのフォームを表します。
/// </summary>
public class MainForm : ClassWrapperBase
public class MainForm : ClassWrapperBase, IDrawable
{
[InitializeClassWrapper]
private static void Initialize(BveTypeSet bveTypes)
Expand All @@ -40,6 +40,9 @@ private static void Initialize(BveTypeSet bveTypes)
CreateDirectXDevicesMethod = members.GetSourceMethodOf(nameof(CreateDirectXDevices));
LoadScenarioMethod = members.GetSourceMethodOf(nameof(LoadScenario));
UnloadScenarioMethod = members.GetSourceMethodOf(nameof(UnloadScenario));
DrawMethod = members.GetSourceMethodOf(nameof(Draw));
OnDeviceLostMethod = members.GetSourceMethodOf(nameof(OnDeviceLost));
OnDeviceResetMethod = members.GetSourceMethodOf(nameof(OnDeviceReset));
}

/// <summary>
Expand Down Expand Up @@ -172,5 +175,17 @@ public ContextMenuStrip ContextMenu
/// シナリオを閉じます。
/// </summary>
public void UnloadScenario() => UnloadScenarioMethod.Invoke(Src, null);

private static FastMethod DrawMethod;
/// <inheritdoc/>
public void Draw() => DrawMethod.Invoke(Src, null);

private static FastMethod OnDeviceLostMethod;
/// <inheritdoc/>
public void OnDeviceLost() => OnDeviceLostMethod.Invoke(Src, null);

private static FastMethod OnDeviceResetMethod;
/// <inheritdoc/>
public void OnDeviceReset() => OnDeviceResetMethod.Invoke(Src, null);
}
}
29 changes: 29 additions & 0 deletions Libs/BveTypes/ClassWrappers/Public/IDrawable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BveTypes.ClassWrappers
{
/// <summary>
/// Direct3D9 によって描画することが可能であるコンポーネントなどを表します。
/// </summary>
public interface IDrawable
{
/// <summary>
/// このオブジェクトに描画します。
/// </summary>
void Draw();

/// <summary>
/// Direct3D9 デバイスがロストした時に呼び出されます。
/// </summary>
void OnDeviceLost();

/// <summary>
/// Direct3D9 デバイスがリセットされた時に呼び出されます。
/// </summary>
void OnDeviceReset();
}
}
4 changes: 4 additions & 0 deletions Libs/BveTypes/ClassWrappers/Public/ObjectDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private static void Initialize(BveTypeSet bveTypes)
DrawDistanceManagerField = members.GetSourceFieldOf(nameof(DrawDistanceManager));

SetRouteMethod = members.GetSourceMethodOf(nameof(SetRoute));
DrawMethod = members.GetSourceMethodOf(nameof(Draw));
}

/// <summary>
Expand Down Expand Up @@ -57,5 +58,8 @@ protected ObjectDrawer(object src) : base(src)

private static FastMethod SetRouteMethod;
public void SetRoute(Route route) => SetRouteMethod.Invoke(Src, new object[] { route.Src });

private static FastMethod DrawMethod;
public void Draw() => DrawMethod.Invoke(Src, null);
}
}
8 changes: 8 additions & 0 deletions Libs/BveTypes/ClassWrappers/Public/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private static void Initialize(BveTypeSet bveTypes)
DisposeMethod = members.GetSourceMethodOf(nameof(Dispose));
InitializeTimeAndLocationMethod = members.GetSourceMethodOf(nameof(InitializeTimeAndLocation));
InitializeMethod = members.GetSourceMethodOf(nameof(Initialize));
DrawMethod = members.GetSourceMethodOf(nameof(Draw));
}

/// <summary>
Expand Down Expand Up @@ -123,5 +124,12 @@ public WrappedSortedList<string, Train> Trains

private static FastMethod InitializeMethod;
public void Initialize(int stationIndex) => InitializeMethod.Invoke(Src, new object[] { stationIndex });

private static FastMethod DrawMethod;
/// <summary>
/// ストラクチャーと運転台パネルを描画します。
/// </summary>
/// <param name="direct3DProvider">描画に使用する <see cref="Direct3DProvider"/>。</param>
public void Draw(Direct3DProvider direct3DProvider) => DrawMethod.Invoke(Src, new object[] { direct3DProvider.Src });
}
}
32 changes: 32 additions & 0 deletions Libs/BveTypes/WrapTypes/5.8.7554.391.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<Method Wrapper="CreateDirectXDevices" WrapperParams="void" Original="e"/>
<Method Wrapper="LoadScenario" WrapperParams="atsex:ScenarioInfo; System.Boolean" Original="a" IsOriginalNonPublic="true"/>
<Method Wrapper="UnloadScenario" WrapperParams="void" Original="b" IsOriginalNonPublic="true"/>
<Method Wrapper="Draw" WrapperParams="void" Original="o"/>
<Method Wrapper="OnDeviceLost" WrapperParams="void" Original="s"/>
<Method Wrapper="OnDeviceReset" WrapperParams="void" Original="t"/>
</Class>

<Class Wrapper="ScenarioSelectionForm" Original="da">
Expand Down Expand Up @@ -90,12 +93,18 @@
</Property>

<Method Wrapper="Draw" WrapperParams="void" Original="o"/>
<Method Wrapper="OnDeviceLost" WrapperParams="void" Original="s"/>
<Method Wrapper="OnDeviceReset" WrapperParams="void" Original="t"/>
</Class>

<Class Wrapper="AssistantDrawer" Original="ar">
<Property Wrapper="Items">
<Getter Original="a"/>
</Property>

<Method Wrapper="Draw" WrapperParams="void" Original="o"/>
<Method Wrapper="OnDeviceLost" WrapperParams="void" Original="s"/>
<Method Wrapper="OnDeviceReset" WrapperParams="void" Original="t"/>
</Class>

<Class Wrapper="Background" Original="ch">
Expand Down Expand Up @@ -187,6 +196,22 @@
</Class>

<Class Wrapper="CameraLocation" Original="bi">
<Property Wrapper="TransformFromBlock">
<Getter Original="b"/>
<Setter Original="a"/>
</Property>
<Property Wrapper="TransformFromCameraHomePosition">
<Getter Original="c"/>
<Setter Original="b"/>
</Property>
<Property Wrapper="Plane">
<Getter Original="d"/>
<Setter Original="a"/>
</Property>
<Property Wrapper="Speed">
<Getter Original="a"/>
<Setter Original="a"/>
</Property>
</Class>

<Class Wrapper="Cant" Original="c9">
Expand Down Expand Up @@ -311,6 +336,8 @@
<Property Wrapper="Direct3D">
<Getter Original="f"/>
</Property>

<Method Wrapper="Render" WrapperParams="atsex:IDrawable" Original="a"/>
</Class>

<Class Wrapper="DetailText" Original="de">
Expand Down Expand Up @@ -408,6 +435,9 @@
</Property>
</Class>

<Class Wrapper="IDrawable" Original="c0">
</Class>

<Class Wrapper="InstructionText" Original="fy">
</Class>

Expand Down Expand Up @@ -589,6 +619,7 @@
<Field WrapperProperty="DrawDistanceManager" Original="g" IsOriginalNonPublic="true"/>

<Method Wrapper="SetRoute" WrapperParams="atsex:Route" Original="a"/>
<Method Wrapper="Draw" WrapperParams="void" Original="o"/>
</Class>

<Class Wrapper="ObjectPassedEventArgs" Original="e5">
Expand Down Expand Up @@ -755,6 +786,7 @@
<Method Wrapper="Dispose" WrapperParams="void" Original="Dispose"/>
<Method Wrapper="InitializeTimeAndLocation" WrapperParams="System.Double; System.Int32" Original="a" IsOriginalNonPublic="true"/>
<Method Wrapper="Initialize" WrapperParams="System.Int32" Original="a"/>
<Method Wrapper="Draw" WrapperParams="atsex:Direct3DProvider" Original="a"/>
</Class>

<Class Wrapper="ScenarioInfo" Original="ek">
Expand Down
Loading

0 comments on commit 1c1b057

Please sign in to comment.