update to latest MoonWorks API

main
cosmonaut 2022-08-29 22:11:51 -07:00
parent a7da12630c
commit 4b1a9feda1
5 changed files with 124 additions and 118 deletions

View File

@ -1,32 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<TargetName>ProjectName</TargetName> <TargetName>ProjectName</TargetName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<LangVersion>8.0</LangVersion> <LangVersion>7.3</LangVersion>
<StartupObject>ProjectName.Program</StartupObject> <StartupObject>ProjectName.Program</StartupObject>
<AssemblyName>ProjectName</AssemblyName> <AssemblyName>ProjectName</AssemblyName>
<RootNamespace>ProjectName</RootNamespace> <RootNamespace>ProjectName</RootNamespace>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ApplicationIcon /> <ApplicationIcon />
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Content Include="Content\**\*.*"> <Content Include="Content\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);lib\**\*</DefaultItemExcludes> <DefaultItemExcludes>$(DefaultItemExcludes);lib\**\*</DefaultItemExcludes>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="lib\MoonWorks\MoonWorks.csproj" /> <ProjectReference Include="lib\MoonWorks\MoonWorks.csproj" />
</ItemGroup> </ItemGroup>
<Import Project=".\CopyMoonlibs.targets" /> <Import Project=".\CopyMoonlibs.targets" />
</Project> </Project>

View File

@ -10,7 +10,7 @@ NOTE: OSX is broken right now because I need to set up MoltenVK.
- Project boilerplate code - Project boilerplate code
- VSCode build tasks - VSCode build tasks
- VSCode debugger integration - VSCode step debugger integration
## Requirements ## Requirements
@ -19,6 +19,7 @@ NOTE: OSX is broken right now because I need to set up MoltenVK.
- [Build Tools for Visual Studio 2019](https://visualstudio.microsoft.com/downloads/) on Windows - [Build Tools for Visual Studio 2019](https://visualstudio.microsoft.com/downloads/) on Windows
- [Visual Studio Code](https://code.visualstudio.com/) - [Visual Studio Code](https://code.visualstudio.com/)
- [VSCode C# Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp) - [VSCode C# Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp)
- [VSCode Omnisharp Extension](https://github.com/OmniSharp/omnisharp-vscode)
## Installation ## Installation
@ -33,7 +34,7 @@ NOTE: OSX is broken right now because I need to set up MoltenVK.
- Open the project directory in VSCode - Open the project directory in VSCode
- Press Ctrl-Shift-B to open the build tasks menu - Press Ctrl-Shift-B to open the build tasks menu
- Tasks use .NET 6.0 to build and run - Tasks use .NET 6.0 to build and run
- Press F5 to build and debug - Press F5 to build and run step debugger
## Acknowledgments ## Acknowledgments

View File

@ -12,22 +12,21 @@ readlinkf(){ perl -MCwd -e 'print Cwd::abs_path shift' "$1";}
# Checks if git is installed # Checks if git is installed
function checkGit() function checkGit()
{ {
git --version > /dev/null 2>&1 git --version > /dev/null 2>&1
if [ ! $? -eq 0 ]; then if [ ! $? -eq 0 ]; then
echo >&2 "ERROR: Git is not installed. Please install git to download MoonWorks." echo >&2 "ERROR: Git is not installed. Please install git to download MoonWorks."
exit 1 exit 1
fi fi
} }
# Pulls MoonWorks from github # Pulls MoonWorks from github
function pullMoonWorks() function pullMoonWorks()
{ {
checkGit checkGit
cd lib cd lib
git submodule add https://gitea.moonside.games/MoonsideGames/MoonWorks.git git submodule add https://gitea.moonside.games/MoonsideGames/MoonWorks.git
git checkout main cd ..
cd .. echo "Updating to the latest release of MoonWorks..."
echo "Updating to the latest release of MoonWorks..."
git submodule update --init --recursive git submodule update --init --recursive
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Finished updating!" echo "Finished updating!"
@ -40,54 +39,54 @@ function pullMoonWorks()
# Downloads and extracts prepackaged archive of native libraries ("moonlibs") # Downloads and extracts prepackaged archive of native libraries ("moonlibs")
function getLibs() function getLibs()
{ {
# Downloading # Downloading
echo "Downloading latest moonlibs..." echo "Downloading latest moonlibs..."
curl http://moonside.games/files/moonlibs.tar.bz2 > "$MY_DIR/moonlibs.tar.bz2" curl https://moonside.games/files/moonlibs.tar.bz2 > "$MY_DIR/moonlibs.tar.bz2"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Finished downloading!" echo "Finished downloading!"
else else
>&2 echo "ERROR: Unable to download successfully." >&2 echo "ERROR: Unable to download successfully."
exit 1 exit 1
fi fi
# Decompressing # Decompressing
echo "Decompressing moonlibs..." echo "Decompressing moonlibs..."
mkdir -p "$MY_DIR" mkdir -p "$MY_DIR"
tar xjC "$MY_DIR" -f "$MY_DIR"/moonlibs.tar.bz2 tar -xvC "$MY_DIR"/moonlibs -f "$MY_DIR"/moonlibs.tar.bz2
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Finished decompressing!" echo "Finished decompressing!"
echo "" echo ""
rm "$MY_DIR"/moonlibs.tar.bz2 rm "$MY_DIR"/moonlibs.tar.bz2
else else
>&2 echo "ERROR: Unable to decompress successfully." >&2 echo "ERROR: Unable to decompress successfully."
exit 1 exit 1
fi fi
} }
getLibs
read -p "Enter your project name or 'exit' to quit: " newProjectName read -p "Enter your project name or 'exit' to quit: " newProjectName
if [[ $newProjectName = 'exit' || -z "$newProjectName" ]]; then if [[ $newProjectName = 'exit' || -z "$newProjectName" ]]; then
exit 1 exit 1
fi fi
NEW_PROJECT_DIR="$MY_DIR/../$newProjectName" NEW_PROJECT_DIR="$MY_DIR/../$newProjectName"
if [ -d "$NEW_PROJECT_DIR" ]; then if [ -d "$NEW_PROJECT_DIR" ]; then
>&2 echo "ERROR: Directory already exists." >&2 echo "ERROR: Project directory already exists."
exit 1 exit 1
fi fi
getLibs
# copy everything into new dir # copy everything into new dir
cp -R "$MY_DIR" "$NEW_PROJECT_DIR" cp -R "$MY_DIR" "$NEW_PROJECT_DIR"
cd "$NEW_PROJECT_DIR" cd "$NEW_PROJECT_DIR"
files=(ProjectName.sln .gitignore ProjectName.csproj src/ProjectNameGame.cs src/Program.cs .vscode/tasks.json .vscode/launch.json) files=(ProjectName.sln .gitignore ProjectName.csproj src/ProjectNameGame.cs src/Program.cs .vscode/tasks.json .vscode/launch.json)
for file in "${files[@]}"; do for file in "${files[@]}"; do
sed -i -e "s/ProjectName/$newProjectName/g" "./$file" sed -i -e "s/ProjectName/$newProjectName/g" "./$file"
if [ "$(uname)" == "Darwin" ]; then if [ "$(uname)" == "Darwin" ]; then
rm ./${file}-e rm ./${file}-e
fi fi
done done
mv ./ProjectName.sln "./$newProjectName.sln" mv ./ProjectName.sln "./$newProjectName.sln"
@ -98,8 +97,6 @@ rm ./LICENSE
rm -rf .git rm -rf .git
git init git init
git checkout -b main
git branch -D master
mkdir lib mkdir lib
pullMoonWorks pullMoonWorks
@ -109,7 +106,7 @@ dotnet sln ${newProjectName}.sln add lib/MoonWorks/MoonWorks.csproj
echo "Project $newProjectName created at: " echo "Project $newProjectName created at: "
if [ "$(uname)" == "Darwin" ]; then if [ "$(uname)" == "Darwin" ]; then
echo $(readlinkf $NEW_PROJECT_DIR) echo $(readlinkf $NEW_PROJECT_DIR)
else else
echo $(readlink -f $NEW_PROJECT_DIR) echo $(readlink -f $NEW_PROJECT_DIR)
fi fi

View File

@ -5,30 +5,37 @@ using MoonWorks;
namespace ProjectName namespace ProjectName
{ {
class Program class Program
{ {
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDllDirectory(string lpPathName); static extern bool SetDllDirectory(string lpPathName);
static void Main(string[] args) static void Main(string[] args)
{ {
WindowCreateInfo windowCreateInfo = new WindowCreateInfo WindowCreateInfo windowCreateInfo = new WindowCreateInfo
{ {
WindowWidth = 1280, WindowWidth = 1280,
WindowHeight = 720, WindowHeight = 720,
WindowTitle = "ProjectName", WindowTitle = "ProjectName",
ScreenMode = ScreenMode.Windowed ScreenMode = ScreenMode.Windowed
}; };
ProjectNameGame game = new ProjectNameGame( FramerateSettings framerateSettings = new FramerateSettings
windowCreateInfo, {
MoonWorks.Graphics.PresentMode.FIFORelaxed, Mode = FramerateMode.Uncapped,
true Cap = 60
); };
game.Run(); ProjectNameGame game = new ProjectNameGame(
} windowCreateInfo,
} MoonWorks.Graphics.PresentMode.FIFORelaxed,
framerateSettings,
true
);
game.Run();
}
}
} }

View File

@ -3,41 +3,42 @@ using MoonWorks;
namespace ProjectName namespace ProjectName
{ {
class ProjectNameGame : Game class ProjectNameGame : Game
{ {
public ProjectNameGame( public ProjectNameGame(
WindowCreateInfo windowCreateInfo, WindowCreateInfo windowCreateInfo,
PresentMode presentMode, PresentMode presentMode,
bool debugMode FramerateSettings framerateSettings,
) : base(windowCreateInfo, presentMode, 60, debugMode) bool debugMode
{ ) : base(windowCreateInfo, presentMode, framerateSettings, 60, debugMode)
// Insert your game initialization logic here. {
} // Insert your game initialization logic here.
}
protected override void Update(System.TimeSpan dt) protected override void Update(System.TimeSpan dt)
{ {
// Insert your game update logic here. // Insert your game update logic here.
} }
protected override void Draw(System.TimeSpan dt, double alpha) protected override void Draw(double alpha)
{ {
// Replace this with your own drawing code. // Replace this with your own drawing code.
var commandBuffer = GraphicsDevice.AcquireCommandBuffer(); var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
var swapchainTexture = commandBuffer.AcquireSwapchainTexture(Window); var swapchainTexture = commandBuffer.AcquireSwapchainTexture(Window);
commandBuffer.BeginRenderPass( commandBuffer.BeginRenderPass(
new ColorAttachmentInfo(swapchainTexture, Color.CornflowerBlue) new ColorAttachmentInfo(swapchainTexture, Color.CornflowerBlue)
); );
commandBuffer.EndRenderPass(); commandBuffer.EndRenderPass();
GraphicsDevice.Submit(commandBuffer); GraphicsDevice.Submit(commandBuffer);
} }
protected override void OnDestroy() protected override void Destroy()
{ {
} }
} }
} }