Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion browser/src/CrossPlatform/AI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,27 @@ let getNextState canSeePlayer game enemy =
else
enemy
| _ -> enemy

// This conversion required because FSharp do not play
// along with NativeAOT inside interpolated strings + enums.
// Be explicit about how to display strings.
let getStateString state =
match state with
| EnemyStateType.Standing -> "Standing"
| EnemyStateType.Ambushing -> "Ambushing"
| EnemyStateType.Attack -> "Attack"
| EnemyStateType.Path -> "Path"
| EnemyStateType.Pain -> "Pain"
| EnemyStateType.Shoot -> "Shoot"
| (EnemyStateType.Chase (x,y)) -> $"Chase ({x},{y})"
| EnemyStateType.Die -> "Die"
| EnemyStateType.Dead -> "Dead"

let preProcess canSeePlayer (enemy,game) =
// preprocess looks for state changes based on the current game world state
let newEnemy = enemy |> getNextState canSeePlayer game
//if newEnemy.State <> enemy.State then
// Utils.log $"Enemy at {enemy.BasicGameObject.Position.vX}, {enemy.BasicGameObject.Position.vY} moving from {enemy.State} to {newEnemy.State}"
// Utils.log $"Enemy at {enemy.BasicGameObject.Position.vX}, {enemy.BasicGameObject.Position.vY} moving from {getStateString enemy.State} to {getStateString newEnemy.State}"
(newEnemy,game)

// this is loosely based on T_Shoot in WL_ACT2.C
Expand Down
71 changes: 71 additions & 0 deletions desktop/FSharp.Core.rd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8" ?>
<Directives>
<!--
This file is part of RdXmlLibrary project.
Visit https://github.com/kant2002/rdxmllibrary for latest version.
If you have modifications specific to this Nuget package,
please contribute back.
-->
<Application>
<Assembly Name="FSharp.Core">
<!--
This is less developed version then other RD.xml files.
Depending on the sprint usages, these commands would have slight variance.
I think more examples mapped to existing printf commands should be added here.
-->
<Type Name="Microsoft.FSharp.Core.PrintfImpl+Specializations`3[[System.IO.TextWriter,System.Private.CoreLib],[Microsoft.FSharp.Core.Unit,FSharp.Core],[Microsoft.FSharp.Core.Unit,FSharp.Core]]" Dynamic="Required All">
<!-- Pattern for printfn "%f" 1.0 -->
<Method Name="CaptureFinal1" Dynamic="Required">
<GenericArgument Name="System.Double, System.Private.CoreLib" />
</Method>
<Method Name="OneStepWithArg" Dynamic="Required">
<GenericArgument Name="System.Double, System.Private.CoreLib" />
</Method>

<!-- Pattern for printfn "%s %f" "" 3.0 -->
<Method Name="CaptureFinal2" Dynamic="Required">
<GenericArgument Name="System.String, System.Private.CoreLib" />
<GenericArgument Name="System.Double, System.Private.CoreLib" />
</Method>
<Method Name="TwoStepWithArg" Dynamic="Required">
<GenericArgument Name="System.String, System.Private.CoreLib" />
<GenericArgument Name="System.Double, System.Private.CoreLib" />
</Method>

<Method Name="CaptureFinal3" Dynamic="Required">
<GenericArgument Name="System.String, System.Private.CoreLib" />
<GenericArgument Name="System.String, System.Private.CoreLib" />
<GenericArgument Name="System.Double, System.Private.CoreLib" />
</Method>

<!-- Pattern for printfn "%d %s" 3 "" -->
<Method Name="CaptureFinal2" Dynamic="Required">
<GenericArgument Name="System.Int32, System.Private.CoreLib" />
<GenericArgument Name="System.String, System.Private.CoreLib" />
</Method>
<Method Name="TwoStepWithArg" Dynamic="Required">
<GenericArgument Name="System.Int32, System.Private.CoreLib" />
<GenericArgument Name="System.String, System.Private.CoreLib" />
</Method>

<!-- Pattern for printfn "%d" 1 -->
<Method Name="CaptureFinal1" Dynamic="Required">
<GenericArgument Name="System.Int32, System.Private.CoreLib" />
</Method>
<Method Name="OneStepWithArg" Dynamic="Required">
<GenericArgument Name="System.Int32, System.Private.CoreLib" />
</Method>

<!-- Pattern for printfn "%f %d" 3.0 2 -->
<Method Name="CaptureFinal2" Dynamic="Required">
<GenericArgument Name="System.Double, System.Private.CoreLib" />
<GenericArgument Name="System.Int32, System.Private.CoreLib" />
</Method>
<Method Name="TwoStepWithArg" Dynamic="Required">
<GenericArgument Name="System.Double, System.Private.CoreLib" />
<GenericArgument Name="System.Int32, System.Private.CoreLib" />
</Method>
</Type>
</Assembly>
</Application>
</Directives>
8 changes: 8 additions & 0 deletions desktop/FSharpWolfenstein.Desktop.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<!-- Set target framework to .NET 7 to publish with NativeAOT -->
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PublishAot Condition="'$(TargetFramework)' == 'net7.0'">true</PublishAot>
<IlcTrimMetadata>true</IlcTrimMetadata>
<TrimmerDefaultAction>link</TrimmerDefaultAction>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
</PropertyGroup>

Expand Down Expand Up @@ -368,5 +372,9 @@
<PackageReference Include="Silk.NET.Windowing" Version="2.15.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta13" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="6.0.0" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be not needed once dotnet/Silk.NET#959 lands in Silk.Net and they release new version.

</ItemGroup>
<ItemGroup>
<RdXmlFile Include="*.rd.xml" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions desktop/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ let main _ =
let mutable options = WindowOptions.Default
options.Size <- Vector2D<int>(int(float screenWidth * zoom),int (float screenHeight * zoom))
options.Title <- "F# Wolfenstein"
Silk.NET.Input.Sdl.SdlInput.RegisterPlatform()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's manual registration of platforms. By default Silk.Net uses dynamic platform registration, and this is not working well with NativeAOT, so registering platforms manually.

Silk.NET.Input.Glfw.GlfwInput.RegisterPlatform()
let window = Window.Create(options)
window.add_Load (load window)
window.add_Render render
Expand Down