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">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetName>ProjectName</TargetName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<LangVersion>8.0</LangVersion>
<StartupObject>ProjectName.Program</StartupObject>
<AssemblyName>ProjectName</AssemblyName>
<RootNamespace>ProjectName</RootNamespace>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ApplicationIcon />
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetName>ProjectName</TargetName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<LangVersion>7.3</LangVersion>
<StartupObject>ProjectName.Program</StartupObject>
<AssemblyName>ProjectName</AssemblyName>
<RootNamespace>ProjectName</RootNamespace>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ApplicationIcon />
</PropertyGroup>
<ItemGroup>
<Content Include="Content\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Content\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);lib\**\*</DefaultItemExcludes>
</PropertyGroup>
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);lib\**\*</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="lib\MoonWorks\MoonWorks.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="lib\MoonWorks\MoonWorks.csproj" />
</ItemGroup>
<Import Project=".\CopyMoonlibs.targets" />
<Import Project=".\CopyMoonlibs.targets" />
</Project>

View File

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

View File

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

View File

@ -5,30 +5,37 @@ using MoonWorks;
namespace ProjectName
{
class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDllDirectory(string lpPathName);
class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDllDirectory(string lpPathName);
static void Main(string[] args)
{
WindowCreateInfo windowCreateInfo = new WindowCreateInfo
{
WindowWidth = 1280,
WindowHeight = 720,
WindowTitle = "ProjectName",
ScreenMode = ScreenMode.Windowed
};
static void Main(string[] args)
{
WindowCreateInfo windowCreateInfo = new WindowCreateInfo
{
WindowWidth = 1280,
WindowHeight = 720,
WindowTitle = "ProjectName",
ScreenMode = ScreenMode.Windowed
};
ProjectNameGame game = new ProjectNameGame(
windowCreateInfo,
MoonWorks.Graphics.PresentMode.FIFORelaxed,
true
);
FramerateSettings framerateSettings = new FramerateSettings
{
Mode = FramerateMode.Uncapped,
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
{
class ProjectNameGame : Game
{
public ProjectNameGame(
WindowCreateInfo windowCreateInfo,
PresentMode presentMode,
bool debugMode
) : base(windowCreateInfo, presentMode, 60, debugMode)
{
// Insert your game initialization logic here.
}
class ProjectNameGame : Game
{
public ProjectNameGame(
WindowCreateInfo windowCreateInfo,
PresentMode presentMode,
FramerateSettings framerateSettings,
bool debugMode
) : base(windowCreateInfo, presentMode, framerateSettings, 60, debugMode)
{
// Insert your game initialization logic here.
}
protected override void Update(System.TimeSpan dt)
{
// Insert your game update logic here.
}
protected override void Update(System.TimeSpan dt)
{
// Insert your game update logic here.
}
protected override void Draw(System.TimeSpan dt, double alpha)
{
// Replace this with your own drawing code.
protected override void Draw(double alpha)
{
// Replace this with your own drawing code.
var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
var swapchainTexture = commandBuffer.AcquireSwapchainTexture(Window);
commandBuffer.BeginRenderPass(
commandBuffer.BeginRenderPass(
new ColorAttachmentInfo(swapchainTexture, Color.CornflowerBlue)
);
);
commandBuffer.EndRenderPass();
GraphicsDevice.Submit(commandBuffer);
}
GraphicsDevice.Submit(commandBuffer);
}
protected override void OnDestroy()
protected override void Destroy()
{
}
}
}
}