Compare commits

...

111 Commits

Author SHA1 Message Date
elasota
567b82eb23 Tag 1.1.0 rc2 2021-05-11 21:36:12 -04:00
elasota
e8565a122d EOL fix 2021-05-11 21:32:00 -04:00
elasota
32ff2f6fe8 Finish clearing out std::vector from PortabilityLayer 2021-05-11 21:27:40 -04:00
elasota
95260f8d8a Zero out structures when creating houses and rooms 2021-05-11 19:47:05 -04:00
elasota
e7b02f37a5 Fix memory corruption when creating a new house 2021-05-11 19:42:05 -04:00
elasota
781c6ce610 Fix missing return value 2021-05-11 19:18:24 -04:00
elasota
98c7a1eea6 Fix MergeGPF missing from simple release 2021-05-11 19:18:15 -04:00
elasota
6858230dde Update copyright 2021-05-11 01:52:56 -04:00
elasota
a6486c137b Change version tag to 1.1.0 rc1 2021-05-11 01:42:06 -04:00
elasota
318a5868d7 Disable loading room editor if the current house is damaged beyond repair, and re-enable loading a different house. 2021-05-11 01:39:17 -04:00
elasota
295db5f064 Fix memory leak 2021-05-11 01:29:40 -04:00
elasota
0def879db1 Fix build 2021-05-11 00:58:26 -04:00
elasota
ac56badffa Add download house option 2021-05-11 00:41:35 -04:00
elasota
75923ad7b0 Fix deleted houses still being in the house list 2021-05-10 23:21:40 -04:00
elasota
32d96798cc Fix file deletion not working in web version 2021-05-10 19:43:52 -04:00
elasota
c354d49e9f Replace beep sound with a simple 80% 440hz + 20% 60hz + fadeout generated tone 2021-05-10 00:10:14 -04:00
elasota
24169507bd Add beep sound to platforms with no beep 2021-05-09 23:45:27 -04:00
elasota
d54ad576bc Add delete option to File browser 2021-05-09 22:48:23 -04:00
elasota
222927d56f Fix double-free when handle is shrunk to zero size 2021-05-09 22:47:57 -04:00
elasota
d74c4b70f3 Remove unused function 2021-05-08 10:55:22 -04:00
elasota
fb7b9b02d9 Web save mechanism 2021-05-07 23:09:35 -04:00
elasota
1ac8032411 Log to stdout 2021-05-07 23:08:29 -04:00
elasota
a012c6d3e7 Fix web build and add export path 2021-05-07 20:12:41 -04:00
elasota
08c6fd5108 EOL fix 2021-05-07 20:12:27 -04:00
elasota
a7cf9d48e3 Fix double GP_RESTRICT definition 2021-05-07 13:29:45 -04:00
elasota
d6ce07685e Clean up vector use 2021-05-07 10:59:31 -04:00
elasota
5e060279af Clean up warnings 2021-05-07 10:59:19 -04:00
elasota
a2ca1725fa Improve export house errors 2021-05-07 03:02:30 -04:00
elasota
f32866510e EOL fix 2021-05-07 02:59:30 -04:00
elasota
ac15c26bef Update installer manufacturer ID 2021-05-07 02:52:28 -04:00
elasota
9510aaee32 Re-enable initial launch disclaimer 2021-05-07 02:30:20 -04:00
elasota
c6aa82db35 Adjust credits 2021-05-07 02:26:10 -04:00
elasota
6d12b6ff1a Add house export to room editor 2021-05-07 02:16:25 -04:00
elasota
c3b2a7e8af EOL fix 2021-05-07 02:14:50 -04:00
elasota
b0d5673d95 Add export dir to Windows 2021-05-07 02:12:58 -04:00
elasota
0de26b5e71 Remove header guards 2021-05-04 18:26:33 -04:00
elasota
65d4784618 Fix desaturation filter not isolating wand star. 2021-05-04 18:26:23 -04:00
elasota
5187ef5dc6 Use upscale filter at 1.5x and 2.5x 2021-05-04 18:25:49 -04:00
elasota
f24b0a0e77 Preprocess audio into S16 for faster mixing. 2021-04-29 20:16:24 -04:00
elasota
7442b92dd3 Make FS use new allocator API 2021-04-28 23:18:24 -04:00
elasota
a2d374f650 Allocator refactor 2021-04-28 01:46:07 -04:00
elasota
472462c535 AerofoilX logging fixes 2021-04-27 10:38:09 -04:00
elasota
80683464af Buildfix AerofoilX 2021-04-27 10:00:23 -04:00
elasota
2cd4e4f178 UTF refactor to eliminate duplicated code outside of PL 2021-04-27 09:54:01 -04:00
elasota
07df94fb00 Use combined files on Android for faster build 2021-04-27 09:52:59 -04:00
elasota
d6b206195d Buildfix Android 2021-04-27 09:51:05 -04:00
elasota
65e68f790a Don't allow empty images. 2021-04-27 03:37:24 -04:00
elasota
56d999f400 Don't allow empty sounds 2021-04-27 03:37:14 -04:00
elasota
2991a7490e Preserve active room on editor resolution change. 2021-04-27 01:33:23 -04:00
elasota
0c43370353 Patch Castle o' the Air start room. Fixes issue #4. 2021-04-27 00:14:59 -04:00
elasota
9ba5b14db6 Add HouseTool 2021-04-27 00:14:16 -04:00
elasota
5e1f5655a0 Fix unpacktool not working 2021-04-27 00:13:51 -04:00
elasota
0385c28002 User house validation 2021-04-25 22:08:15 -04:00
elasota
19b1a307e7 EOL fix 2021-04-25 22:07:04 -04:00
elasota
9341c4c378 EOL fix 2021-04-25 01:59:48 -04:00
elasota
5d9dde6589 Refactor audio buffering API, this should mainly prevent SDL audio driver from allocating memory in the mixer callback. 2021-04-25 00:34:02 -04:00
elasota
f9d3b91f72 Fixed redundant set 2021-04-20 21:02:11 -04:00
elasota
1dc86a703e Fix somewhat incorrect upscale texture handling. Replace InstancedResources reset with something that's less likely to be undefined behavior. 2021-04-20 20:42:30 -04:00
elasota
77e02927c6 Fix web crash when dragging or closing popup windows 2021-04-19 02:44:19 -04:00
elasota
c473271e4e Super-minimal shell 2021-04-19 02:28:34 -04:00
elasota
84a4d16aed Web file system implementation + fixes 2021-04-19 01:02:10 -04:00
elasota
f15a87041a Improve synthetic bold quality and use synthetic bold for most Open Sans uses 2021-04-18 18:11:38 -04:00
elasota
d826a908e9 Remove font cache from web 2021-04-18 18:06:45 -04:00
elasota
3d3f839801 Add synthetic bold hack to better support Geneva CY 2021-04-16 00:26:42 -04:00
elasota
141f840888 Specialize font paths for preinstalled font selection instead 2021-04-15 20:56:31 -04:00
elasota
22ae442f87 Handle preinstalled fonts case 2021-04-15 20:08:16 -04:00
elasota
5dd8bf28f5 Add IsUsingPreinstalledFonts API 2021-04-15 20:03:06 -04:00
elasota
bd422d0eb3 EOL fix 2021-04-15 19:52:50 -04:00
elasota
4e8e76f8fc Re-enable runtime font rendering if a font handler is assigned, clean up some font handler things. 2021-04-15 19:49:43 -04:00
elasota
c49bab04d5 Fix modulation being applied twice 2021-04-11 10:57:33 -04:00
elasota
71f27f0a05 Fix some suboptimal audio constants. 2021-04-11 01:22:48 -04:00
elasota
b9fe553ff8 Improve mixer performance 2021-04-10 23:56:25 -04:00
elasota
7ae31bc7fc Use fixed latency offset in SDL mixer. This should fix score tick sounds having uneven spacing.
Reduce buffer to 512 samples again.
2021-04-10 21:54:41 -04:00
elasota
2234190f24 Remove FreeType from basic release 2021-04-08 02:01:43 -04:00
elasota
d62de80ff1 Flag GenerateFonts as a dependency for the release package installer 2021-04-08 01:43:00 -04:00
elasota
03f07d7c4f Remove resources dir from basic release 2021-04-08 01:40:48 -04:00
elasota
b90d0c303c Fix AerofoilX 2021-04-07 11:42:57 -04:00
elasota
7842e721e5 Remove Resources dir from Windows release 2021-04-07 10:52:18 -04:00
elasota
93195207dc Disable glGetError calls in release config 2021-04-07 00:03:09 -04:00
elasota
59741dd966 Bump Android version to 1.1.0 2021-04-07 00:02:52 -04:00
elasota
1ac69c2c75 Misc tweaks, partially bump version to 1.1 2021-03-30 05:24:37 -04:00
elasota
69f59f769d Fix broken thread events 2021-03-30 05:24:18 -04:00
elasota
bb2af5abb3 Fix bad parameter 2021-03-30 05:23:54 -04:00
elasota
3692a966bf Tweak some values to help with sound choppiness in Chrome slightly, until we port to OpenAL 2021-03-30 05:23:44 -04:00
elasota
7916c72fc4 Fix incorrect fast AA calculations 2021-03-30 05:23:02 -04:00
elasota
7951f579e0 Remove logs 2021-03-30 00:01:37 -04:00
elasota
b64c904558 Remove junk 2021-03-30 00:00:17 -04:00
elasota
a6f6ffcdcc Remove log func 2021-03-30 00:00:07 -04:00
elasota
6fb45f480b Emscripten port 2021-03-29 21:41:11 -04:00
elasota
9ba0e9f13d Remove FreeType from Android build 2021-03-29 11:57:04 -04:00
elasota
0df94405f8 Faster AA table generation 2021-03-27 03:01:43 -04:00
elasota
ae69696cbd Remove unused header 2021-03-27 03:01:30 -04:00
elasota
50f420d2b1 Font system refactor, use pre-rendered fonts 2021-03-27 03:01:19 -04:00
elasota
c87f238563 Display driver loop refactor 2021-03-26 17:05:38 -04:00
elasota
48fe83bb33 EOL fix 2021-03-19 03:45:43 -04:00
elasota
b2b27ef335 Fix some splash screen inconsistencies 2021-03-19 03:16:59 -04:00
elasota
89831f0ff6 Fix Windows SDL build 2021-03-18 19:05:16 -04:00
elasota
99fd71196d Tentative Linux readme 2021-03-18 18:16:18 -04:00
elasota
7060676b73 Cygwin port 2021-03-18 17:08:11 -04:00
elasota
184f867f79 Fix Android symlinks 2021-03-18 17:05:29 -04:00
elasota
cbd759c754 Add README.md 2021-03-16 03:02:18 -04:00
elasota
2ada8029d0 Fixed source code export not working 2021-03-15 19:36:07 -04:00
elasota
8e0d8e261e Bump version to 1.0.17 2021-03-12 18:42:54 -05:00
elasota
20b9eef64d Fix missing FreeType2 PDBs 2021-03-12 18:26:08 -05:00
elasota
c147e1100e Change MiniRez to use WindowsUnicodeToolShim 2021-03-11 22:28:01 -05:00
elasota
0a2e730d26 Change FTagData to use WindowsUnicodeToolShim 2021-03-11 22:22:30 -05:00
elasota
922cd0fd06 Add debug/release props to WindowsUnicodeToolShim 2021-03-11 22:22:14 -05:00
elasota
b8bf6be44f Change hqx2gp to use WindowsUnicodeToolShim 2021-03-11 22:18:07 -05:00
elasota
2897c4ffab Fix saved game deletion not working 2021-03-11 21:40:22 -05:00
elasota
35c174984b Bump version to 1.0.16 2021-03-11 21:36:06 -05:00
elasota
da16edea8d Fix broken AA table preloader, use load bar first time on desktop 2021-03-09 04:15:59 -05:00
367 changed files with 14986 additions and 4451 deletions

13
.gitignore vendored
View File

@@ -20,6 +20,7 @@
*.idb
*.aps
*.res
*.a
.vs/*
Packaged/*
DebugData/*
@@ -30,9 +31,21 @@ InstallerPackages/*
*.wixobj
*.CopyComplete
*.lnk
*.cmake
ReleasePackageInstaller/obj/*
ReleasePackageInstaller/bin/*
ReleasePackageInstaller/AerofoilPackageDefs.wxi
ReleasePackageInstaller/AerofoilPackageVersion.wxi
packages/*
!SDL2-2.0.12/lib/x64/*
CMakeCache.txt
CMakeFiles/*
Makefile
SDL2-2.0.12/CMakeFiles/*
SDL2-2.0.12/build
SDL2-2.0.12/config.status
SDL2-2.0.12/libtool
SDL2-2.0.12/Makefile.rules
SDL2-2.0.12/sdl2.pc
SDL2-2.0.12/sdl2-config
install_manifest.txt

4
.gitmodules vendored Normal file
View File

@@ -0,0 +1,4 @@
[submodule "AerofoilWeb/FileSaverDotJS"]
path = AerofoilWeb/FileSaverDotJS
url = https://github.com/eligrey/FileSaver.js.git
branch = master

View File

@@ -48,6 +48,8 @@ Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "ReleasePackageInstaller", "
{7EFF1E21-C375-45EA-A069-4E2232C8A72B} = {7EFF1E21-C375-45EA-A069-4E2232C8A72B}
{B852D549-4020-4477-8BFB-E199FF78B047} = {B852D549-4020-4477-8BFB-E199FF78B047}
{2FF15659-5C72-48B8-B55B-3C658E4125B5} = {2FF15659-5C72-48B8-B55B-3C658E4125B5}
{3B7FD18D-7A50-4DF5-AC25-543E539BFACE} = {3B7FD18D-7A50-4DF5-AC25-543E539BFACE}
{B31BFF9D-2D14-4B1A-A625-8348CC3D8D67} = {B31BFF9D-2D14-4B1A-A625-8348CC3D8D67}
{36DAF5FA-6ADB-4F20-9810-1610DE0AE653} = {36DAF5FA-6ADB-4F20-9810-1610DE0AE653}
EndProjectSection
EndProject
@@ -63,6 +65,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AerofoilSDL", "AerofoilSDL\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MergeGPF", "MergeGPF\MergeGPF.vcxproj", "{36DAF5FA-6ADB-4F20-9810-1610DE0AE653}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GenerateFonts", "GenerateFonts\GenerateFonts.vcxproj", "{3B7FD18D-7A50-4DF5-AC25-543E539BFACE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bin2h", "bin2h\bin2h.vcxproj", "{D045F28D-F245-44DD-B576-CC91BF3BE6E9}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HouseTool", "HouseTool\HouseTool.vcxproj", "{B31BFF9D-2D14-4B1A-A625-8348CC3D8D67}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -175,6 +183,18 @@ Global
{36DAF5FA-6ADB-4F20-9810-1610DE0AE653}.Debug|x64.Build.0 = Debug|x64
{36DAF5FA-6ADB-4F20-9810-1610DE0AE653}.Release|x64.ActiveCfg = Release|x64
{36DAF5FA-6ADB-4F20-9810-1610DE0AE653}.Release|x64.Build.0 = Release|x64
{3B7FD18D-7A50-4DF5-AC25-543E539BFACE}.Debug|x64.ActiveCfg = Debug|x64
{3B7FD18D-7A50-4DF5-AC25-543E539BFACE}.Debug|x64.Build.0 = Debug|x64
{3B7FD18D-7A50-4DF5-AC25-543E539BFACE}.Release|x64.ActiveCfg = Release|x64
{3B7FD18D-7A50-4DF5-AC25-543E539BFACE}.Release|x64.Build.0 = Release|x64
{D045F28D-F245-44DD-B576-CC91BF3BE6E9}.Debug|x64.ActiveCfg = Debug|x64
{D045F28D-F245-44DD-B576-CC91BF3BE6E9}.Debug|x64.Build.0 = Debug|x64
{D045F28D-F245-44DD-B576-CC91BF3BE6E9}.Release|x64.ActiveCfg = Release|x64
{D045F28D-F245-44DD-B576-CC91BF3BE6E9}.Release|x64.Build.0 = Release|x64
{B31BFF9D-2D14-4B1A-A625-8348CC3D8D67}.Debug|x64.ActiveCfg = Debug|x64
{B31BFF9D-2D14-4B1A-A625-8348CC3D8D67}.Debug|x64.Build.0 = Debug|x64
{B31BFF9D-2D14-4B1A-A625-8348CC3D8D67}.Release|x64.ActiveCfg = Release|x64
{B31BFF9D-2D14-4B1A-A625-8348CC3D8D67}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -43,6 +43,7 @@
<Import Project="..\GpMainApp.props" />
<Import Project="..\GpShell.props" />
<Import Project="..\Debug.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -52,6 +53,7 @@
<Import Project="..\GpMainApp.props" />
<Import Project="..\Release.props" />
<Import Project="..\GpShell.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
@@ -82,16 +84,15 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
<ClCompile Include="GpBWCursor_Win32.cpp" />
<ClCompile Include="GpColorCursor_Win32.cpp" />
<ClCompile Include="GpFiber_Win32.cpp" />
<ClCompile Include="GpFileStream_Win32.cpp" />
<ClCompile Include="GpFileSystem_Win32.cpp" />
<ClCompile Include="GpLogDriver_Win32.cpp" />
<ClCompile Include="GpMain_Win32.cpp" />
<ClCompile Include="GpMutex_Win32.cpp" />
<ClCompile Include="GpSystemServices_Win32.cpp" />
<ClCompile Include="GpFiberStarter_Win32.cpp" />
<ClCompile Include="GpThreadEvent_Win32.cpp" />
</ItemGroup>
<ItemGroup>
@@ -102,13 +103,14 @@
<ClInclude Include="..\GpCommon\GpDisplayDriverTickStatus.h" />
<ClInclude Include="..\GpCommon\GpFileCreationDisposition.h" />
<ClInclude Include="..\GpCommon\GpInputDriverProperties.h" />
<ClInclude Include="..\GpCommon\GpString.h" />
<ClInclude Include="..\GpCommon\GpVector.h" />
<ClInclude Include="..\GpCommon\IGpCursor.h" />
<ClInclude Include="..\GpCommon\IGpAudioChannelCallbacks.h" />
<ClInclude Include="..\GpCommon\IGpDisplayDriverSurface.h" />
<ClInclude Include="..\GpCommon\IGpLogDriver.h" />
<ClInclude Include="..\GpCommon\IGpPrefsHandler.h" />
<ClInclude Include="GpBWCursor_Win32.h" />
<ClInclude Include="GpFiber_Win32.h" />
<ClInclude Include="GpFileStream_Win32.h" />
<ClInclude Include="GpFileSystem_Win32.h" />
<ClInclude Include="GpLogDriver_Win32.h" />
@@ -127,9 +129,6 @@
<ProjectReference Include="..\GpDisplayDriver_D3D11\GpDisplayDriver_D3D11.vcxproj">
<Project>{ffc961ac-55b4-4a38-a83e-06ae98f59acc}</Project>
</ProjectReference>
<ProjectReference Include="..\GpFontHandler_FreeType2\GpFontHandler_FreeType2.vcxproj">
<Project>{4b564030-8985-4975-91e1-e1b2c16ae2a1}</Project>
</ProjectReference>
<ProjectReference Include="..\GpInputDriver_XInput\GpInputDriver_XInput.vcxproj">
<Project>{17b96f07-ef92-47cd-95a5-8e6ee38ab564}</Project>
</ProjectReference>

View File

@@ -4,12 +4,6 @@
<ClCompile Include="GpColorCursor_Win32.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GpFiber_Win32.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GpFiberStarter_Win32.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GpFileStream_Win32.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -34,6 +28,9 @@
<ClCompile Include="GpBWCursor_Win32.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\GpCommon\EGpInputDriverType.h">
@@ -48,9 +45,6 @@
<ClInclude Include="..\GpCommon\GpDisplayDriverTickStatus.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GpFiber_Win32.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\GpCommon\GpFileCreationDisposition.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -99,6 +93,12 @@
<ClInclude Include="GpBWCursor_Win32.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\GpCommon\GpVector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\GpCommon\GpString.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="ConvertedResources\Large128.ico">

View File

@@ -21,6 +21,7 @@
#include "GpBWCursor_Win32.h"
#include "GpWindows.h"
#include "IGpAllocator.h"
#include <stdint.h>
#include <stdlib.h>
@@ -34,19 +35,19 @@ void GpBWCursor_Win32::Destroy()
this->DecRef();
}
IGpCursor_Win32 *GpBWCursor_Win32::Create(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY)
IGpCursor_Win32 *GpBWCursor_Win32::Create(IGpAllocator *alloc, size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY)
{
size_t numBits = width * height;
size_t numBytes = (width * height + 7) / 8;
uint8_t *convertedAndData = static_cast<uint8_t*>(malloc(numBytes));
uint8_t *convertedXorData = static_cast<uint8_t*>(malloc(numBytes));
size_t numBytes = (numBits + 7) / 8;
uint8_t *convertedAndData = static_cast<uint8_t*>(alloc->Alloc(numBytes));
uint8_t *convertedXorData = static_cast<uint8_t*>(alloc->Alloc(numBytes));
if (!convertedAndData || !convertedXorData)
{
if (convertedAndData)
free(convertedAndData);
alloc->Release(convertedAndData);
if (convertedXorData)
free(convertedXorData);
alloc->Release(convertedXorData);
return nullptr;
}
@@ -62,25 +63,26 @@ IGpCursor_Win32 *GpBWCursor_Win32::Create(size_t width, size_t height, const voi
HCURSOR hcursor = CreateCursor(g_gpWindowsGlobals.m_hInstance, static_cast<int>(hotSpotX), static_cast<int>(hotSpotY), static_cast<int>(width), static_cast<int>(height), convertedAndData, convertedXorData);
free(convertedAndData);
free(convertedXorData);
alloc->Release(convertedAndData);
alloc->Release(convertedXorData);
if (!hcursor)
return nullptr;
void *storage = malloc(sizeof(GpBWCursor_Win32));
void *storage = alloc->Alloc(sizeof(GpBWCursor_Win32));
if (!storage)
{
DestroyCursor(hcursor);
return nullptr;
}
return new (storage) GpBWCursor_Win32(hcursor);
return new (storage) GpBWCursor_Win32(hcursor, alloc);
}
GpBWCursor_Win32::GpBWCursor_Win32(HCURSOR cursor)
GpBWCursor_Win32::GpBWCursor_Win32(HCURSOR cursor, IGpAllocator *alloc)
: m_cursor(cursor)
, m_refCount(1)
, m_alloc(alloc)
{
}
@@ -104,7 +106,8 @@ void GpBWCursor_Win32::DecRef()
m_refCount--;
if (m_refCount == 0)
{
IGpAllocator *alloc = m_alloc;
this->~GpBWCursor_Win32();
free(this);
alloc->Release(this);
}
}

View File

@@ -3,6 +3,8 @@
#include "IGpCursor_Win32.h"
#include "GpWindows.h"
struct IGpAllocator;
class GpBWCursor_Win32 final : public IGpCursor_Win32
{
public:
@@ -13,12 +15,13 @@ public:
void IncRef() override;
void DecRef() override;
static IGpCursor_Win32 *Create(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY);
static IGpCursor_Win32 *Create(IGpAllocator *alloc, size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY);
private:
GpBWCursor_Win32(HCURSOR cursor);
GpBWCursor_Win32(HCURSOR cursor, IGpAllocator *alloc);
~GpBWCursor_Win32();
HCURSOR m_cursor;
int m_refCount;
IGpAllocator *m_alloc;
};

View File

@@ -20,6 +20,7 @@
*/
#include "GpColorCursor_Win32.h"
#include "IGpAllocator.h"
#include <stdint.h>
#include <stdlib.h>
@@ -31,7 +32,7 @@ void GpColorCursor_Win32::Destroy()
this->DecRef();
}
IGpCursor_Win32 *GpColorCursor_Win32::Create(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY)
IGpCursor_Win32 *GpColorCursor_Win32::Create(IGpAllocator *alloc, size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY)
{
const size_t paddingBits = (sizeof(void*) * 8);
@@ -52,7 +53,7 @@ IGpCursor_Win32 *GpColorCursor_Win32::Create(size_t width, size_t height, const
size_t maskPitch = width + paddingBits - 1;
maskPitch -= maskPitch % paddingBits;
LPVOID maskBits = malloc(maskPitch * height);
LPVOID maskBits = alloc->Alloc(maskPitch * height);
if (!maskBits)
return nullptr;
@@ -71,6 +72,8 @@ IGpCursor_Win32 *GpColorCursor_Win32::Create(size_t width, size_t height, const
ii.hbmMask = CreateBitmap(width, height, 1, 1, maskBits);
ReleaseDC(NULL, hdc);
alloc->Release(maskBits);
size_t cursorPitch = width * 4;
size_t numPixels = width * height;
@@ -90,19 +93,20 @@ IGpCursor_Win32 *GpColorCursor_Win32::Create(size_t width, size_t height, const
if (!hicon)
return nullptr;
void *storage = malloc(sizeof(GpColorCursor_Win32));
void *storage = alloc->Alloc(sizeof(GpColorCursor_Win32));
if (!storage)
{
DestroyIcon(hicon);
return nullptr;
}
return new (storage) GpColorCursor_Win32(reinterpret_cast<HCURSOR>(hicon));
return new (storage) GpColorCursor_Win32(alloc, reinterpret_cast<HCURSOR>(hicon));
}
GpColorCursor_Win32::GpColorCursor_Win32(HCURSOR cursor)
GpColorCursor_Win32::GpColorCursor_Win32(IGpAllocator *alloc, HCURSOR cursor)
: m_cursor(cursor)
, m_refCount(1)
, m_alloc(alloc)
{
}
@@ -126,7 +130,8 @@ void GpColorCursor_Win32::DecRef()
m_refCount--;
if (m_refCount == 0)
{
IGpAllocator *alloc = m_alloc;
this->~GpColorCursor_Win32();
free(this);
alloc->Release(this);
}
}

View File

@@ -3,6 +3,7 @@
#include "IGpCursor_Win32.h"
#include "GpWindows.h"
struct IGpAllocator;
class GpColorCursor_Win32 final : public IGpCursor_Win32
{
@@ -14,12 +15,13 @@ public:
void IncRef() override;
void DecRef() override;
static IGpCursor_Win32 *Create(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY);
static IGpCursor_Win32 *Create(IGpAllocator *alloc, size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY);
private:
GpColorCursor_Win32(HCURSOR cursor);
GpColorCursor_Win32(IGpAllocator *alloc, HCURSOR cursor);
~GpColorCursor_Win32();
HCURSOR m_cursor;
int m_refCount;
IGpAllocator *m_alloc;
};

View File

@@ -1,56 +0,0 @@
#include "GpFiberStarter.h"
#include "GpFiber_Win32.h"
#include "GpWindows.h"
#include <assert.h>
namespace GpFiberStarter_Win32
{
struct FiberStartState
{
GpFiberStarter::ThreadFunc_t m_threadFunc;
IGpFiber *m_creatingFiber;
void *m_context;
};
static VOID WINAPI FiberStartRoutine(LPVOID lpThreadParameter)
{
const FiberStartState *tss = static_cast<const FiberStartState*>(lpThreadParameter);
GpFiberStarter::ThreadFunc_t threadFunc = tss->m_threadFunc;
IGpFiber *creatingFiber = tss->m_creatingFiber;
void *context = tss->m_context;
SwitchToFiber(static_cast<GpFiber_Win32*>(creatingFiber)->GetFiber());
threadFunc(context);
assert(!"Fiber function exited");
}
}
IGpFiber *GpFiberStarter::StartFiber(IGpSystemServices *systemServices, ThreadFunc_t threadFunc, void *context, IGpFiber *creatingFiber)
{
ULONG_PTR lowLimit;
ULONG_PTR highLimit;
#if 0
GetCurrentThreadStackLimits(&lowLimit, &highLimit);
ULONG_PTR stackSize = highLimit - lowLimit;
#else
ULONG_PTR stackSize = 1024 * 1024;
#endif
GpFiberStarter_Win32::FiberStartState startState;
startState.m_context = context;
startState.m_creatingFiber = creatingFiber;
startState.m_threadFunc = threadFunc;
void *fiber = CreateFiber(static_cast<SIZE_T>(stackSize), GpFiberStarter_Win32::FiberStartRoutine, &startState);
if (!fiber)
return nullptr;
SwitchToFiber(fiber);
return GpFiber_Win32::Create(fiber);
}

View File

@@ -1,37 +0,0 @@
#include "GpFiber_Win32.h"
#include <new>
GpFiber_Win32::GpFiber_Win32(LPVOID fiber)
: m_fiber(fiber)
{
}
void GpFiber_Win32::YieldTo(IGpFiber *toFiber)
{
SwitchToFiber(static_cast<GpFiber_Win32*>(toFiber)->m_fiber);
}
void GpFiber_Win32::YieldToTerminal(IGpFiber *toFiber)
{
YieldTo(toFiber);
}
void GpFiber_Win32::Destroy()
{
this->~GpFiber_Win32();
free(this);
}
GpFiber_Win32::~GpFiber_Win32()
{
DeleteFiber(m_fiber);
}
IGpFiber *GpFiber_Win32::Create(LPVOID fiber)
{
void *storage = malloc(sizeof(GpFiber_Win32));
if (!storage)
return nullptr;
return new (storage) GpFiber_Win32(fiber);
}

View File

@@ -1,26 +0,0 @@
#pragma once
#include "GpWindows.h"
#include "IGpFiber.h"
class GpFiber_Win32 final : public IGpFiber
{
public:
void YieldTo(IGpFiber *toFiber) override;
void YieldToTerminal(IGpFiber *toFiber) override;
void Destroy() override;
static IGpFiber *Create(LPVOID fiber);
LPVOID GetFiber() const;
private:
explicit GpFiber_Win32(LPVOID fiber);
~GpFiber_Win32();
LPVOID m_fiber;
};
inline LPVOID GpFiber_Win32::GetFiber() const
{
return m_fiber;
}

View File

@@ -1,13 +1,32 @@
#include "GpFileStream_Win32.h"
#include "IGpAllocator.h"
GpFileStream_Win32::GpFileStream_Win32(HANDLE handle, bool readable, bool writeable, bool seekable)
: m_handle(handle)
#include <new>
GpFileStream_Win32::GpFileStream_Win32(IGpAllocator *alloc, HANDLE handle, bool readable, bool writeable, bool seekable)
: m_alloc(alloc)
, m_handle(handle)
, m_readable(readable)
, m_writeable(writeable)
, m_seekable(seekable)
{
}
GpFileStream_Win32 *GpFileStream_Win32::Create(IGpAllocator *alloc, HANDLE handle, bool readable, bool writeable, bool seekable)
{
void *storage = alloc->Alloc(sizeof(GpFileStream_Win32));
if (!storage)
return nullptr;
return new (storage) GpFileStream_Win32(alloc, handle, readable, writeable, seekable);
}
GpFileStream_Win32::~GpFileStream_Win32()
{
CloseHandle(m_handle);
}
size_t GpFileStream_Win32::Read(void *bytesOut, size_t size)
{
if (!m_readable)
@@ -122,7 +141,10 @@ GpUFilePos_t GpFileStream_Win32::Tell() const
void GpFileStream_Win32::Close()
{
CloseHandle(m_handle);
IGpAllocator *alloc = m_alloc;
this->~GpFileStream_Win32();
alloc->Release(this);
}
void GpFileStream_Win32::Flush()

View File

@@ -7,7 +7,7 @@
class GpFileStream_Win32 final : public GpIOStream
{
public:
explicit GpFileStream_Win32(HANDLE handle, bool readable, bool writeable, bool seekable);
~GpFileStream_Win32();
size_t Read(void *bytesOut, size_t size) override;
size_t Write(const void *bytes, size_t size) override;
@@ -19,10 +19,19 @@ public:
bool SeekEnd(GpUFilePos_t loc) override;
GpUFilePos_t Size() const override;
GpUFilePos_t Tell() const override;
void Close() override;
void GP_ASYNCIFY_PARANOID_NAMED(Close)() override;
void Flush() override;
#if GP_ASYNCIFY_PARANOID
void Close();
#endif
static GpFileStream_Win32 *Create(IGpAllocator *alloc, HANDLE handle, bool readable, bool writeable, bool seekable);
private:
GpFileStream_Win32(IGpAllocator *alloc, HANDLE handle, bool readable, bool writeable, bool seekable);
IGpAllocator *m_alloc;
HANDLE m_handle;
bool m_readable;
bool m_writeable;

View File

@@ -1,44 +1,49 @@
#include "GpFileSystem_Win32.h"
#include "GpAllocator_C.h"
#include "GpApplicationName.h"
#include "GpFileStream_Win32.h"
#include "GpWindows.h"
#include "IGpAllocator.h"
#include "IGpDirectoryCursor.h"
#include <string>
#include <Shlwapi.h>
#include <ShlObj.h>
#include <commdlg.h>
#include <assert.h>
struct IGpAllocator;
extern GpWindowsGlobals g_gpWindowsGlobals;
class GpDirectoryCursor_Win32 final : public IGpDirectoryCursor
{
public:
static GpDirectoryCursor_Win32 *Create(const HANDLE &handle, const WIN32_FIND_DATAW &findData);
static GpDirectoryCursor_Win32 *Create(IGpAllocator *alloc, const HANDLE &handle, const WIN32_FIND_DATAW &findData);
bool GetNext(const char *&outFileName) override;
void Destroy() override;
private:
GpDirectoryCursor_Win32(const HANDLE &handle, const WIN32_FIND_DATAW &findData);
GpDirectoryCursor_Win32(IGpAllocator *alloc, const HANDLE &handle, const WIN32_FIND_DATAW &findData);
~GpDirectoryCursor_Win32();
IGpAllocator *m_alloc;
HANDLE m_handle;
WIN32_FIND_DATAW m_findData;
char m_chars[MAX_PATH + 1];
bool m_haveNext;
};
GpDirectoryCursor_Win32 *GpDirectoryCursor_Win32::Create(const HANDLE &handle, const WIN32_FIND_DATAW &findData)
GpDirectoryCursor_Win32 *GpDirectoryCursor_Win32::Create(IGpAllocator *alloc, const HANDLE &handle, const WIN32_FIND_DATAW &findData)
{
void *storage = malloc(sizeof(GpDirectoryCursor_Win32));
void *storage = alloc->Alloc(sizeof(GpDirectoryCursor_Win32));
if (!storage)
return nullptr;
return new (storage) GpDirectoryCursor_Win32(handle, findData);
return new (storage) GpDirectoryCursor_Win32(alloc, handle, findData);
}
bool GpDirectoryCursor_Win32::GetNext(const char *&outFileName)
@@ -82,14 +87,16 @@ bool GpDirectoryCursor_Win32::GetNext(const char *&outFileName)
void GpDirectoryCursor_Win32::Destroy()
{
IGpAllocator *alloc = m_alloc;
this->~GpDirectoryCursor_Win32();
free(this);
alloc->Release(this);
}
GpDirectoryCursor_Win32::GpDirectoryCursor_Win32(const HANDLE &handle, const WIN32_FIND_DATAW &findData)
GpDirectoryCursor_Win32::GpDirectoryCursor_Win32(IGpAllocator *alloc, const HANDLE &handle, const WIN32_FIND_DATAW &findData)
: m_handle(handle)
, m_findData(findData)
, m_haveNext(true)
, m_alloc(alloc)
{
}
@@ -98,47 +105,76 @@ GpDirectoryCursor_Win32::~GpDirectoryCursor_Win32()
FindClose(m_handle);
}
GpFileSystem_Win32::GpFileSystem_Win32()
GpFileSystem_Win32::GpFileSystem_Win32(IGpAllocator *alloc)
: m_alloc(alloc)
, m_prefsDir(alloc)
, m_scoresDir(alloc)
, m_packagedDir(alloc)
, m_housesDir(alloc)
, m_logsDir(alloc)
, m_userHousesDir(alloc)
, m_userSavesDir(alloc)
, m_resourcesDir(alloc)
, m_exportDir(alloc)
{
// GP TODO: This shouldn't be static init since it allocates memory
m_executablePath[0] = 0;
}
void GpFileSystem_Win32::Destroy()
{
IGpAllocator *alloc = m_alloc;
this->~GpFileSystem_Win32();
alloc->Release(this);
}
bool GpFileSystem_Win32::Init()
{
PWSTR docsPath;
if (!FAILED(SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &docsPath)))
if (FAILED(SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &docsPath)))
return false;
if (!m_prefsDir.Set(docsPath))
{
try
{
m_prefsDir = docsPath;
}
catch(...)
{
CoTaskMemFree(docsPath);
throw;
}
m_prefsDir.append(L"\\" GP_APPLICATION_NAME_W);
m_userHousesDir = m_prefsDir + L"\\Houses";
m_userSavesDir = m_prefsDir + L"\\SavedGames";
m_scoresDir = m_prefsDir + L"\\Scores";
m_logsDir = m_prefsDir + L"\\Logs";
m_fontCacheDir = m_prefsDir + L"\\FontCache";
CreateDirectoryW(m_prefsDir.c_str(), nullptr);
CreateDirectoryW(m_scoresDir.c_str(), nullptr);
CreateDirectoryW(m_userHousesDir.c_str(), nullptr);
CreateDirectoryW(m_userSavesDir.c_str(), nullptr);
CreateDirectoryW(m_logsDir.c_str(), nullptr);
CreateDirectoryW(m_fontCacheDir.c_str(), nullptr);
m_prefsDir.append(L"\\");
m_scoresDir.append(L"\\");
m_userHousesDir.append(L"\\");
m_userSavesDir.append(L"\\");
m_logsDir.append(L"\\");
m_fontCacheDir.append(L"\\");
CoTaskMemFree(docsPath);
return false;
}
CoTaskMemFree(docsPath);
if (!m_prefsDir.Append(L"\\" GP_APPLICATION_NAME_W))
return false;
if (!m_userHousesDir.Set(m_prefsDir) || !m_userHousesDir.Append(L"\\Houses"))
return false;
if (!m_userSavesDir.Set(m_prefsDir) || !m_userSavesDir.Append(L"\\SavedGames"))
return false;
if (!m_scoresDir.Set(m_prefsDir) || !m_scoresDir.Append(L"\\Scores"))
return false;
if (!m_logsDir.Set(m_prefsDir) || !m_logsDir.Append(L"\\Logs"))
return false;
if (!m_exportDir.Set(m_prefsDir) || !m_exportDir.Append(L"\\Export"))
return false;
CreateDirectoryW(m_prefsDir.Buffer(), nullptr);
CreateDirectoryW(m_scoresDir.Buffer(), nullptr);
CreateDirectoryW(m_userHousesDir.Buffer(), nullptr);
CreateDirectoryW(m_userSavesDir.Buffer(), nullptr);
CreateDirectoryW(m_logsDir.Buffer(), nullptr);
CreateDirectoryW(m_exportDir.Buffer(), nullptr);
if (!m_prefsDir.Append(L"\\") ||
!m_scoresDir.Append(L"\\") ||
!m_userHousesDir.Append(L"\\") ||
!m_userSavesDir.Append(L"\\") ||
!m_logsDir.Append(L"\\") ||
!m_resourcesDir.Append(L"\\") ||
!m_exportDir.Append(L"\\"))
return false;
DWORD modulePathSize = GetModuleFileNameW(nullptr, m_executablePath, MAX_PATH);
if (modulePathSize == MAX_PATH || modulePathSize == 0)
m_executablePath[0] = 0;
@@ -158,7 +194,7 @@ GpFileSystem_Win32::GpFileSystem_Win32()
continue;
}
if (wcscat_s(m_executablePath, L"Resources"))
if (wcscat_s(m_executablePath, L"Packaged"))
{
currentPathLength = 0;
break;
@@ -173,12 +209,19 @@ GpFileSystem_Win32::GpFileSystem_Win32()
currentPathLength--;
}
if (currentPathLength > 0)
{
m_packagedDir = std::wstring(m_executablePath) + L"Packaged\\";
m_housesDir = std::wstring(m_executablePath) + L"Packaged\\Houses\\";
m_resourcesDir = std::wstring(m_executablePath) + L"Resources\\";
}
if (currentPathLength == 0)
return false;
if (!m_packagedDir.Set(m_executablePath) || !m_packagedDir.Append(L"Packaged\\"))
return false;
if (!m_housesDir.Set(m_executablePath) || !m_housesDir.Append(L"Packaged\\Houses\\"))
return false;
if (!m_resourcesDir.Set(m_executablePath) || !m_resourcesDir.Append(L"Resources\\"))
return false;
return true;
}
bool GpFileSystem_Win32::FileExists(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path)
@@ -247,7 +290,7 @@ GpIOStream *GpFileSystem_Win32::OpenFileNested(PortabilityLayer::VirtualDirector
if (h == INVALID_HANDLE_VALUE)
return false;
return new GpFileStream_Win32(h, true, writeAccess, true);
return GpFileStream_Win32::Create(m_alloc, h, true, writeAccess, true);
}
bool GpFileSystem_Win32::DeleteFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &existed)
@@ -276,7 +319,7 @@ IGpDirectoryCursor *GpFileSystem_Win32::ScanDirectoryNested(PortabilityLayer::Vi
{
wchar_t winPath[MAX_PATH + 2];
const char **expandedPaths = static_cast<const char**>(malloc(sizeof(const char*) * (numPaths + 1)));
const char **expandedPaths = static_cast<const char**>(m_alloc->Alloc(sizeof(const char*) * (numPaths + 1)));
if (!expandedPaths)
return nullptr;
@@ -285,7 +328,7 @@ IGpDirectoryCursor *GpFileSystem_Win32::ScanDirectoryNested(PortabilityLayer::Vi
expandedPaths[numPaths] = "*";
const bool isPathResolved = ResolvePath(virtualDirectory, expandedPaths, numPaths + 1, winPath);
free(expandedPaths);
m_alloc->Release(expandedPaths);
if (!isPathResolved)
return nullptr;
@@ -296,7 +339,7 @@ IGpDirectoryCursor *GpFileSystem_Win32::ScanDirectoryNested(PortabilityLayer::Vi
if (ff == INVALID_HANDLE_VALUE)
return nullptr;
return GpDirectoryCursor_Win32::Create(ff, findData);
return GpDirectoryCursor_Win32::Create(m_alloc, ff, findData);
}
bool GpFileSystem_Win32::ValidateFilePathUnicodeChar(uint32_t c) const
@@ -319,11 +362,6 @@ bool GpFileSystem_Win32::ValidateFilePathUnicodeChar(uint32_t c) const
return false;
}
void GpFileSystem_Win32::SetMainThreadRelay(IGpThreadRelay *relay)
{
(void)relay;
}
void GpFileSystem_Win32::SetDelayCallback(GpFileSystem_Win32::DelayCallback_t delayCallback)
{
}
@@ -424,9 +462,27 @@ const wchar_t *GpFileSystem_Win32::GetBasePath() const
return m_executablePath;
}
GpFileSystem_Win32 *GpFileSystem_Win32::CreateInstance(IGpAllocator *alloc)
{
void *storage = alloc->Alloc(sizeof(GpFileSystem_Win32));
if (!storage)
return nullptr;
GpFileSystem_Win32 *fs = new (storage) GpFileSystem_Win32(alloc);
if (!fs->Init())
{
fs->Destroy();
return nullptr;
}
ms_instance = fs;
return fs;
}
GpFileSystem_Win32 *GpFileSystem_Win32::GetInstance()
{
return &ms_instance;
return ms_instance;
}
bool GpFileSystem_Win32::ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths, wchar_t *outPath)
@@ -436,31 +492,31 @@ bool GpFileSystem_Win32::ResolvePath(PortabilityLayer::VirtualDirectory_t virtua
switch (virtualDirectory)
{
case PortabilityLayer::VirtualDirectories::kApplicationData:
baseDir = m_packagedDir.c_str();
baseDir = m_packagedDir.Buffer();
break;
case PortabilityLayer::VirtualDirectories::kGameData:
baseDir = m_housesDir.c_str();
baseDir = m_housesDir.Buffer();
break;
case PortabilityLayer::VirtualDirectories::kUserData:
baseDir = m_userHousesDir.c_str();
baseDir = m_userHousesDir.Buffer();
break;
case PortabilityLayer::VirtualDirectories::kUserSaves:
baseDir = m_userSavesDir.c_str();
baseDir = m_userSavesDir.Buffer();
break;
case PortabilityLayer::VirtualDirectories::kPrefs:
baseDir = m_prefsDir.c_str();
baseDir = m_prefsDir.Buffer();
break;
case PortabilityLayer::VirtualDirectories::kFonts:
baseDir = m_resourcesDir.c_str();
baseDir = m_resourcesDir.Buffer();
break;
case PortabilityLayer::VirtualDirectories::kHighScores:
baseDir = m_scoresDir.c_str();
baseDir = m_scoresDir.Buffer();
break;
case PortabilityLayer::VirtualDirectories::kLogs:
baseDir = m_logsDir.c_str();
baseDir = m_logsDir.Buffer();
break;
case PortabilityLayer::VirtualDirectories::kFontCache:
baseDir = m_fontCacheDir.c_str();
case PortabilityLayer::VirtualDirectories::kSourceExport:
baseDir = m_exportDir.Buffer();
break;
default:
return false;
@@ -506,4 +562,4 @@ bool GpFileSystem_Win32::ResolvePath(PortabilityLayer::VirtualDirectory_t virtua
return true;
}
GpFileSystem_Win32 GpFileSystem_Win32::ms_instance;
GpFileSystem_Win32 *GpFileSystem_Win32::ms_instance;

View File

@@ -4,13 +4,14 @@
#include "GpCoreDefs.h"
#include "GpWindows.h"
#include <string>
#include "GpString.h"
class GpFileSystem_Win32 final : public IGpFileSystem
{
public:
GpFileSystem_Win32();
explicit GpFileSystem_Win32(IGpAllocator *alloc);
void Destroy();
bool FileExists(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path) override;
bool FileLocked(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &exists) override;
@@ -21,26 +22,30 @@ public:
bool ValidateFilePath(const char *path, size_t sz) const override;
bool ValidateFilePathUnicodeChar(uint32_t ch) const override;
void SetMainThreadRelay(IGpThreadRelay *relay) override;
void SetDelayCallback(DelayCallback_t delayCallback) override;
const wchar_t *GetBasePath() const;
static GpFileSystem_Win32 *CreateInstance(IGpAllocator *alloc);
static GpFileSystem_Win32 *GetInstance();
private:
bool Init();
bool ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths, wchar_t *outPath);
std::wstring m_prefsDir;
std::wstring m_scoresDir;
std::wstring m_packagedDir;
std::wstring m_housesDir;
std::wstring m_logsDir;
std::wstring m_userHousesDir;
std::wstring m_userSavesDir;
std::wstring m_resourcesDir;
std::wstring m_fontCacheDir;
GpWString m_prefsDir;
GpWString m_scoresDir;
GpWString m_packagedDir;
GpWString m_housesDir;
GpWString m_logsDir;
GpWString m_userHousesDir;
GpWString m_userSavesDir;
GpWString m_resourcesDir;
GpWString m_exportDir;
wchar_t m_executablePath[MAX_PATH];
static GpFileSystem_Win32 ms_instance;
IGpAllocator *m_alloc;
static GpFileSystem_Win32 *ms_instance;
};

View File

@@ -1,3 +1,4 @@
#include "GpAllocator_C.h"
#include "GpLogDriver_Win32.h"
#include "GpFileSystem_Win32.h"
@@ -7,6 +8,7 @@
GpLogDriver_Win32::GpLogDriver_Win32()
: m_stream(nullptr)
, m_isInitialized(false)
, m_alloc(GpAllocator_C::GetInstance())
{
}
@@ -58,14 +60,14 @@ void GpLogDriver_Win32::VPrintf(Category category, const char *fmt, va_list args
if (formattedSize <= 0)
return;
char *charBuff = static_cast<char*>(malloc(formattedSize + 1));
char *charBuff = static_cast<char*>(m_alloc->Alloc(formattedSize + 1));
if (!charBuff)
return;
vsnprintf(charBuff, formattedSize + 1, fmt, args);
m_stream->Write(charBuff, formattedSize);
free(charBuff);
m_alloc->Release(charBuff);
}
m_stream->Write("\n", 1);

View File

@@ -3,6 +3,7 @@
#include "IGpLogDriver.h"
class GpIOStream;
struct IGpAllocator;
class GpLogDriver_Win32 : public IGpLogDriver
{
@@ -20,6 +21,7 @@ private:
void InitInternal();
GpIOStream *m_stream;
IGpAllocator *m_alloc;
bool m_isInitialized;
static GpLogDriver_Win32 ms_instance;

View File

@@ -1,10 +1,10 @@
#include "GpMain.h"
#include "GpAllocator_C.h"
#include "GpAudioDriverFactory.h"
#include "GpBWCursor_Win32.h"
#include "GpColorCursor_Win32.h"
#include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h"
#include "GpFiber_Win32.h"
#include "GpFileSystem_Win32.h"
#include "GpLogDriver_Win32.h"
#include "GpFontHandlerFactory.h"
@@ -28,7 +28,6 @@ GpWindowsGlobals g_gpWindowsGlobals;
extern "C" __declspec(dllimport) IGpAudioDriver *GpDriver_CreateAudioDriver_XAudio2(const GpAudioDriverProperties &properties);
extern "C" __declspec(dllimport) IGpDisplayDriver *GpDriver_CreateDisplayDriver_D3D11(const GpDisplayDriverProperties &properties);
extern "C" __declspec(dllimport) IGpInputDriver *GpDriver_CreateInputDriver_XInput(const GpInputDriverProperties &properties);
extern "C" __declspec(dllimport) IGpFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties);
static void PostMouseEvent(IGpVOSEventQueue *eventQueue, GpMouseEventType_t eventType, GpMouseButton_t button, int32_t x, int32_t y, float pixelScaleX, float pixelScaleY)
{
@@ -405,6 +404,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
int nArgs;
LPWSTR *cmdLineArgs = CommandLineToArgvW(cmdLine, &nArgs);
IGpAllocator *alloc = GpAllocator_C::GetInstance();
// Init file system first since logging may depend on it
GpFileSystem_Win32 *fs = GpFileSystem_Win32::CreateInstance(alloc);
if (!fs)
return -1;
for (int i = 1; i < nArgs; i++)
{
if (!wcscmp(cmdLineArgs[i], L"-diagnostics"))
@@ -412,12 +418,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
}
IGpLogDriver *logger = GpLogDriver_Win32::GetInstance();
IGpSystemServices *sysServices = GpSystemServices_Win32::GetInstance();
GpDriverCollection *drivers = GpAppInterface_Get()->PL_GetDriverCollection();
drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_Win32::GetInstance());
drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_Win32::GetInstance());
drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_Win32::GetInstance());
drivers->SetDriver<GpDriverIDs::kSystemServices>(sysServices);
drivers->SetDriver<GpDriverIDs::kLog>(logger);
drivers->SetDriver<GpDriverIDs::kAlloc>(alloc);
g_gpWindowsGlobals.m_hInstance = hInstance;
g_gpWindowsGlobals.m_hPrevInstance = hPrevInstance;
@@ -430,7 +438,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
g_gpWindowsGlobals.m_hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_ICON1));
g_gpWindowsGlobals.m_hIconSm = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_ICON2));
g_gpWindowsGlobals.m_createFiberFunc = GpFiber_Win32::Create;
g_gpWindowsGlobals.m_createBWCursorFunc = GpBWCursor_Win32::Create;
g_gpWindowsGlobals.m_createColorCursorFunc = GpColorCursor_Win32::Create;
g_gpWindowsGlobals.m_translateWindowsMessageFunc = TranslateWindowsMessage;
@@ -439,7 +446,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
g_gpGlobalConfig.m_audioDriverType = EGpAudioDriverType_XAudio2;
g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_FreeType2;
g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_None;
EGpInputDriverType inputDrivers[] =
{
@@ -451,12 +458,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
g_gpGlobalConfig.m_osGlobals = &g_gpWindowsGlobals;
g_gpGlobalConfig.m_logger = logger;
g_gpGlobalConfig.m_systemServices = GpSystemServices_Win32::GetInstance();
g_gpGlobalConfig.m_systemServices = sysServices;
g_gpGlobalConfig.m_allocator = alloc;
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_D3D11, GpDriver_CreateDisplayDriver_D3D11);
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_XAudio2, GpDriver_CreateAudioDriver_XAudio2);
GpInputDriverFactory::RegisterInputDriverFactory(EGpInputDriverType_XInput, GpDriver_CreateInputDriver_XInput);
GpFontHandlerFactory::RegisterFontHandlerFactory(EGpFontHandlerType_FreeType2, GpDriver_CreateFontHandler_FreeType2);
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Windows environment configured, starting up");
@@ -468,5 +475,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
LocalFree(cmdLineArgs);
fs->Destroy();
return returnCode;
}

View File

@@ -1,5 +1,6 @@
#include "GpMutex_Win32.h"
#include "IGpAllocator.h"
#include "GpWindows.h"
#include <stdlib.h>
@@ -7,8 +8,9 @@
void GpMutex_Win32::Destroy()
{
IGpAllocator *alloc = m_alloc;
this->~GpMutex_Win32();
free(this);
alloc->Release(this);
}
void GpMutex_Win32::Lock()
@@ -22,16 +24,17 @@ void GpMutex_Win32::Unlock()
}
GpMutex_Win32 *GpMutex_Win32::Create()
GpMutex_Win32 *GpMutex_Win32::Create(IGpAllocator *alloc)
{
void *storage = malloc(sizeof(GpMutex_Win32));
void *storage = alloc->Alloc(sizeof(GpMutex_Win32));
if (!storage)
return nullptr;
return new (storage) GpMutex_Win32();
return new (storage) GpMutex_Win32(alloc);
}
GpMutex_Win32::GpMutex_Win32()
GpMutex_Win32::GpMutex_Win32(IGpAllocator *alloc)
: m_alloc(alloc)
{
InitializeCriticalSection(&m_critSection);
}

View File

@@ -4,6 +4,8 @@
#include "GpWindows.h"
struct IGpAllocator;
class GpMutex_Win32 final : public IGpMutex
{
public:
@@ -11,11 +13,12 @@ public:
void Lock() override;
void Unlock() override;
static GpMutex_Win32 *Create();
static GpMutex_Win32 *Create(IGpAllocator *alloc);
private:
const GpMutex_Win32();
explicit GpMutex_Win32(IGpAllocator *alloc);
~GpMutex_Win32();
CRITICAL_SECTION m_critSection;
IGpAllocator *m_alloc;
};

View File

@@ -2,11 +2,11 @@
#include "GpMutex_Win32.h"
#include "GpThreadEvent_Win32.h"
#include "GpWindows.h"
#include "GpAllocator_C.h"
#include "IGpClipboardContents.h"
#include "UTF16.h"
#include "UTF8.h"
#include "GpUnicode.h"
#include <assert.h>
#include <vector>
@@ -134,6 +134,7 @@ static DWORD WINAPI StaticStartThread(LPVOID lpThreadParameter)
GpSystemServices_Win32::GpSystemServices_Win32()
: m_isTouchscreenSimulation(false)
, m_alloc(GpAllocator_C::GetInstance())
{
}
@@ -181,17 +182,17 @@ void GpSystemServices_Win32::GetLocalDateTime(unsigned int &year, unsigned int &
IGpMutex *GpSystemServices_Win32::CreateMutex()
{
return GpMutex_Win32::Create();
return GpMutex_Win32::Create(m_alloc);
}
IGpMutex *GpSystemServices_Win32::CreateRecursiveMutex()
{
return GpMutex_Win32::Create();
return GpMutex_Win32::Create(m_alloc);
}
IGpThreadEvent *GpSystemServices_Win32::CreateThreadEvent(bool autoReset, bool startSignaled)
{
return GpThreadEvent_Win32::Create(autoReset, startSignaled);
return GpThreadEvent_Win32::Create(m_alloc, autoReset, startSignaled);
}
void *GpSystemServices_Win32::CreateThread(ThreadFunc_t threadFunc, void *context)
@@ -231,9 +232,10 @@ uint64_t GpSystemServices_Win32::GetFreeMemoryCosmetic() const
return memStatus.ullAvailPhys;
}
void GpSystemServices_Win32::Beep() const
bool GpSystemServices_Win32::Beep() const
{
MessageBeep(MB_OK);
return true;
}
bool GpSystemServices_Win32::IsTouchscreen() const
@@ -261,6 +263,21 @@ bool GpSystemServices_Win32::IsFullscreenOnStartup() const
return false;
}
bool GpSystemServices_Win32::HasNativeFileManager() const
{
return true;
}
GpOperatingSystem_t GpSystemServices_Win32::GetOperatingSystem() const
{
return GpOperatingSystems::kWindows;
}
GpOperatingSystemFlavor_t GpSystemServices_Win32::GetOperatingSystemFlavor() const
{
return GpOperatingSystemFlavors::kGeneric;
}
unsigned int GpSystemServices_Win32::GetCPUCount() const
{
SYSTEM_INFO sysInfo;

View File

@@ -28,12 +28,15 @@ public:
void *CreateThread(ThreadFunc_t threadFunc, void *context) override;
IGpThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) override;
uint64_t GetFreeMemoryCosmetic() const override;
void Beep() const override;
bool Beep() const override;
bool IsTouchscreen() const override;
bool IsUsingMouseAsTouch() const override;
bool IsTextInputObstructive() const override;
bool IsFullscreenPreferred() const override;
bool IsFullscreenOnStartup() const override;
bool HasNativeFileManager() const override;
GpOperatingSystem_t GetOperatingSystem() const override;
GpOperatingSystemFlavor_t GetOperatingSystemFlavor() const override;
unsigned int GetCPUCount() const override;
void SetTextInputEnabled(bool isEnabled) override;
bool IsTextInputEnabled() const override;
@@ -48,6 +51,8 @@ public:
private:
bool m_isTouchscreenSimulation;
IGpAllocator *m_alloc;
static GpSystemServices_Win32 ms_instance;
};

View File

@@ -1,4 +1,5 @@
#include "GpThreadEvent_Win32.h"
#include "IGpAllocator.h"
#include <stdlib.h>
#include <new>
@@ -20,28 +21,30 @@ void GpThreadEvent_Win32::Signal()
void GpThreadEvent_Win32::Destroy()
{
IGpAllocator *alloc = m_alloc;
this->~GpThreadEvent_Win32();
free(this);
alloc->Release(this);
}
GpThreadEvent_Win32 *GpThreadEvent_Win32::Create(bool autoReset, bool startSignaled)
GpThreadEvent_Win32 *GpThreadEvent_Win32::Create(IGpAllocator *alloc, bool autoReset, bool startSignaled)
{
HANDLE handle = CreateEventA(nullptr, autoReset ? FALSE : TRUE, startSignaled ? TRUE : FALSE, nullptr);
if (handle == nullptr)
return nullptr;
void *storage = malloc(sizeof(GpThreadEvent_Win32));
void *storage = alloc->Alloc(sizeof(GpThreadEvent_Win32));
if (!storage)
{
CloseHandle(handle);
return nullptr;
}
return new (storage) GpThreadEvent_Win32(handle);
return new (storage) GpThreadEvent_Win32(alloc, handle);
}
GpThreadEvent_Win32::GpThreadEvent_Win32(const HANDLE &handle)
GpThreadEvent_Win32::GpThreadEvent_Win32(IGpAllocator *alloc, const HANDLE &handle)
: m_event(handle)
, m_alloc(alloc)
{
}

View File

@@ -12,11 +12,12 @@ public:
void Signal() override;
void Destroy() override;
static GpThreadEvent_Win32 *Create(bool autoReset, bool startSignaled);
static GpThreadEvent_Win32 *Create(IGpAllocator *alloc, bool autoReset, bool startSignaled);
private:
explicit GpThreadEvent_Win32(const HANDLE &handle);
explicit GpThreadEvent_Win32(IGpAllocator *alloc, const HANDLE &handle);
~GpThreadEvent_Win32();
HANDLE m_event;
IGpAllocator *m_alloc;
};

View File

@@ -15,8 +15,8 @@ android {
}
minSdkVersion 16
targetSdkVersion 29
versionCode 11
versionName "1.0.15"
versionCode 14
versionName "1.1.0"
externalNativeBuild {
ndkBuild {
arguments "APP_PLATFORM=android-16"

View File

@@ -1,4 +1,5 @@
AerofoilSDL
AerofoilPortable
Common
FreeType
GpApp

View File

@@ -1 +0,0 @@
../../../AerofoilPortable

View File

@@ -24,7 +24,7 @@ LOCAL_SRC_FILES := \
LOCAL_SHARED_LIBRARIES := SDL2
LOCAL_STATIC_LIBRARIES := GpShell GpFontHandler_FreeType2 AerofoilPortable AerofoilSDL GpApp
LOCAL_STATIC_LIBRARIES := GpShell AerofoilPortable AerofoilSDL GpApp
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog

View File

@@ -424,9 +424,6 @@ bool GpFileSystem_Android::ResolvePath(PortabilityLayer::VirtualDirectory_t virt
case PortabilityLayer::VirtualDirectories::kPrefs:
prefsAppend = "Prefs";
break;
case PortabilityLayer::VirtualDirectories::kFontCache:
prefsAppend = "FontCache";
break;
default:
return false;
};
@@ -450,7 +447,6 @@ bool GpFileSystem_Android::ResolvePath(PortabilityLayer::VirtualDirectory_t virt
GpFileSystem_Android::GpFileSystem_Android()
: m_activity(nullptr)
, m_relay(nullptr)
, m_delayCallback(nullptr)
, m_sourceExportMutex(nullptr)
, m_sourceExportFD(0)
@@ -680,25 +676,6 @@ bool GpFileSystem_Android::DeleteFile(PortabilityLayer::VirtualDirectory_t virtu
}
IGpDirectoryCursor *GpFileSystem_Android::ScanDirectoryNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *const *paths, size_t numPaths)
{
ScanDirectoryNestedContext ctx;
ctx.m_this = this;
ctx.m_returnValue = nullptr;
ctx.m_virtualDirectory = virtualDirectory;
ctx.m_paths = paths;
ctx.m_numPaths = numPaths;
m_relay->Invoke(ScanDirectoryNestedThunk, &ctx);
return ctx.m_returnValue;
}
void GpFileSystem_Android::ScanDirectoryNestedThunk(void *context)
{
ScanDirectoryNestedContext *ctx = static_cast<ScanDirectoryNestedContext*>(context);
ctx->m_returnValue = ctx->m_this->ScanDirectoryNestedInternal(ctx->m_virtualDirectory, ctx->m_paths, ctx->m_numPaths);
}
IGpDirectoryCursor *GpFileSystem_Android::ScanDirectoryNestedInternal(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *const *paths, size_t numPaths)
{
if (virtualDirectory == PortabilityLayer::VirtualDirectories::kGameData || virtualDirectory == PortabilityLayer::VirtualDirectories::kApplicationData)
return ScanAssetDirectory(virtualDirectory, paths, numPaths);
@@ -752,11 +729,6 @@ bool GpFileSystem_Android::ValidateFilePathUnicodeChar(uint32_t c) const
return false;
}
void GpFileSystem_Android::SetMainThreadRelay(IGpThreadRelay *relay)
{
m_relay = relay;
}
void GpFileSystem_Android::SetDelayCallback(DelayCallback_t delayCallback)
{
m_delayCallback = delayCallback;

View File

@@ -27,7 +27,6 @@ public:
bool ValidateFilePath(const char *path, size_t pathLen) const override;
bool ValidateFilePathUnicodeChar(uint32_t ch) const override;
void SetMainThreadRelay(IGpThreadRelay *relay) override;
void SetDelayCallback(DelayCallback_t delayCallback) override;
void PostSourceExportRequest(bool cancelled, int fd, jobject pfd);
@@ -36,26 +35,12 @@ public:
static GpFileSystem_Android *GetInstance();
private:
struct ScanDirectoryNestedContext
{
GpFileSystem_Android *m_this;
IGpDirectoryCursor *m_returnValue;
PortabilityLayer::VirtualDirectory_t m_virtualDirectory;
char const *const *m_paths;
size_t m_numPaths;
};
static void ScanDirectoryNestedThunk(void *context);
IGpDirectoryCursor *ScanDirectoryNestedInternal(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths);
IGpDirectoryCursor *ScanAssetDirectory(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths);
IGpDirectoryCursor *ScanStorageDirectory(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths);
bool OpenSourceExportFD(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths, int &fd, jobject &pfd);
bool ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths, std::string &resolution, bool &isAsset);
IGpThreadRelay *m_relay;
DelayCallback_t m_delayCallback;
jobject m_activity;

View File

@@ -4,7 +4,6 @@
#include "GpAudioDriverFactory.h"
#include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h"
#include "GpFiber_SDL.h"
#include "GpFileSystem_Android.h"
#include "GpFontHandlerFactory.h"
#include "GpInputDriverFactory.h"
@@ -24,8 +23,6 @@
GpAndroidGlobals g_gpAndroidGlobals;
extern "C" IGpFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties);
IGpDisplayDriver *GpDriver_CreateDisplayDriver_SDL_GL2(const GpDisplayDriverProperties &properties);
IGpAudioDriver *GpDriver_CreateAudioDriver_SDL(const GpAudioDriverProperties &properties);
@@ -91,7 +88,7 @@ int main(int argc, char* argv[])
g_gpGlobalConfig.m_audioDriverType = EGpAudioDriverType_SDL2;
g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_FreeType2;
g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_None;
g_gpGlobalConfig.m_inputDriverTypes = nullptr;
g_gpGlobalConfig.m_numInputDrivers = 0;
@@ -102,7 +99,6 @@ int main(int argc, char* argv[])
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2);
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL);
GpFontHandlerFactory::RegisterFontHandlerFactory(EGpFontHandlerType_FreeType2, GpDriver_CreateFontHandler_FreeType2);
int returnCode = GpMain::Run();

View File

@@ -55,8 +55,9 @@ void *GpSystemServices_Android::CreateThread(ThreadFunc_t threadFunc, void *cont
return thread;
}
void GpSystemServices_Android::Beep() const
bool GpSystemServices_Android::Beep() const
{
return false;
}
bool GpSystemServices_Android::IsTouchscreen() const
@@ -84,6 +85,21 @@ bool GpSystemServices_Android::IsFullscreenOnStartup() const
return true;
}
bool GpSystemServices_Android::HasNativeFileManager() const
{
return false;
}
GpOperatingSystem_t GpSystemServices_Android::GetOperatingSystem() const
{
return GpOperatingSystems::kAndroid;
}
GpOperatingSystemFlavor_t GpSystemServices_Android::GetOperatingSystemFlavor() const
{
return GpOperatingSystemFlavors::kGeneric;
}
unsigned int GpSystemServices_Android::GetCPUCount() const
{
return SDL_GetCPUCount();

View File

@@ -9,12 +9,15 @@ public:
GpSystemServices_Android();
void *CreateThread(ThreadFunc_t threadFunc, void *context) override;
void Beep() const override;
bool Beep() const override;
bool IsTouchscreen() const override;
bool IsUsingMouseAsTouch() const override;
bool IsTextInputObstructive() const override;
bool IsFullscreenPreferred() const override;
bool IsFullscreenOnStartup() const override;
bool HasNativeFileManager() const override;
GpOperatingSystem_t GetOperatingSystem() const override;
GpOperatingSystemFlavor_t GetOperatingSystemFlavor() const override;
unsigned int GetCPUCount() const override;
void SetTextInputEnabled(bool isEnabled) override;
bool IsTextInputEnabled() const override;

View File

@@ -11,12 +11,9 @@ mklink /D app\jni\SDL2 ..\..\..\SDL2-2.0.12
mklink /D app\jni\GpApp ..\..\..\GpApp
mklink /D app\jni\GpShell ..\..\..\GpShell
mklink /D app\jni\GpCommon ..\..\..\GpCommon
mklink /D app\jni\GpFontHandler_FreeType2 ..\..\..\GpFontHandler_FreeType2
mklink /D app\jni\PortabilityLayer ..\..\..\PortabilityLayer
mklink /D app\jni\FreeType ..\..\..\FreeType
mklink /D app\jni\rapidjson ..\..\..\rapidjson
mklink /D app\jni\MacRomanConversion ..\..\..\MacRomanConversion
mklink /D app\jni\stb ..\..\..\stb
mklink /D app\src\main\assets\Resources ..\..\..\..\..\Resources
pause

View File

@@ -8,11 +8,7 @@ rmdir app\jni\SDL2
rmdir app\jni\GpShell
rmdir app\jni\GpCommon
rmdir app\jni\GpApp
rmdir app\jni\GpFontHandler_FreeType2
rmdir app\jni\PortabilityLayer
rmdir app\jni\FreeType
rmdir app\jni\zlib
rmdir app\jni\rapidjson
rmdir app\jni\MacRomanConversion
rmdir app\jni\stb
rmdir app\src\main\assets\Resources

10
AerofoilPortable.props Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IncludePath>$(SolutionDir)AerofoilPortable;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup />
<ItemGroup />
</Project>

View File

@@ -17,4 +17,5 @@ LOCAL_SRC_FILES := \
GpThreadEvent_Cpp11.cpp \
GpSystemServices_POSIX.cpp
include $(BUILD_STATIC_LIBRARY)

View File

@@ -0,0 +1,115 @@
#include "GpAllocator_C.h"
#include "CoreDefs.h"
#include <string.h>
#include <stdlib.h>
#include <assert.h>
struct GpAllocator_C_MMBlock
{
uint8_t m_offsetFromAllocLocation;
static size_t AlignedSize();
};
size_t GpAllocator_C_MMBlock::AlignedSize()
{
const size_t paddedSize = sizeof(GpAllocator_C_MMBlock) + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
const size_t paddedSizeTruncated = paddedSize - (paddedSize % GP_SYSTEM_MEMORY_ALIGNMENT);
return paddedSizeTruncated;
}
void *GpAllocator_C::Realloc(void *buf, size_t newSize)
{
if (buf == nullptr)
{
if (newSize == 0)
return nullptr;
return this->Alloc(newSize);
}
if (newSize == 0)
{
this->Free(buf);
return nullptr;
}
assert(buf != nullptr);
const size_t mmBlockSize = GpAllocator_C_MMBlock::AlignedSize();
uint8_t *oldBufBytes = static_cast<uint8_t*>(buf);
const GpAllocator_C_MMBlock *oldBufMMBlock = reinterpret_cast<const GpAllocator_C_MMBlock*>(oldBufBytes - GpAllocator_C_MMBlock::AlignedSize());
const size_t oldBufOffsetFromAlignLoc = oldBufMMBlock->m_offsetFromAllocLocation;
uint8_t *oldBufBase = oldBufBytes - GpAllocator_C_MMBlock::AlignedSize() - oldBufOffsetFromAlignLoc;
const size_t mmBlockSizeWithMaxPadding = GpAllocator_C_MMBlock::AlignedSize() + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
if (SIZE_MAX - newSize < mmBlockSizeWithMaxPadding)
return nullptr;
const size_t newBufferSize = newSize + mmBlockSizeWithMaxPadding;
uint8_t *newBuffer = static_cast<uint8_t*>(realloc(oldBufBase, newSize + mmBlockSizeWithMaxPadding));
if (!newBuffer)
return nullptr;
const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(newBuffer) & static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT - 1);
intptr_t alignPadding = 0;
if (offsetFromAlignPoint != 0)
alignPadding = static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint;
// Check if the alignment changed, if so relocate
if (static_cast<size_t>(alignPadding) != oldBufOffsetFromAlignLoc)
memmove(newBuffer + alignPadding, newBuffer + oldBufOffsetFromAlignLoc, GpAllocator_C_MMBlock::AlignedSize() + newSize);
GpAllocator_C_MMBlock *newMMBlock = reinterpret_cast<GpAllocator_C_MMBlock*>(newBuffer + alignPadding);
newMMBlock->m_offsetFromAllocLocation = static_cast<uint8_t>(alignPadding);
return newBuffer + alignPadding + GpAllocator_C_MMBlock::AlignedSize();
}
void *GpAllocator_C::Alloc(size_t size)
{
if (size == 0)
return nullptr;
const size_t mmBlockSizeWithMaxPadding = GpAllocator_C_MMBlock::AlignedSize() + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
if (SIZE_MAX - size < mmBlockSizeWithMaxPadding)
return nullptr;
uint8_t *buffer = static_cast<uint8_t*>(realloc(nullptr, size + mmBlockSizeWithMaxPadding));
if (!buffer)
return nullptr;
const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(buffer) & static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT - 1);
intptr_t alignPadding = 0;
if (offsetFromAlignPoint != 0)
alignPadding = static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint;
GpAllocator_C_MMBlock *mmBlock = reinterpret_cast<GpAllocator_C_MMBlock*>(buffer + alignPadding);
mmBlock->m_offsetFromAllocLocation = static_cast<uint8_t>(alignPadding);
return buffer + alignPadding + GpAllocator_C_MMBlock::AlignedSize();
}
void GpAllocator_C::Free(void *buf)
{
if (!buf)
return;
const size_t mmBlockSize = GpAllocator_C_MMBlock::AlignedSize();
uint8_t *bytes = static_cast<uint8_t*>(buf);
const GpAllocator_C_MMBlock *mmBlock = reinterpret_cast<const GpAllocator_C_MMBlock*>(bytes - GpAllocator_C_MMBlock::AlignedSize());
void *freeLoc = bytes - GpAllocator_C_MMBlock::AlignedSize() - mmBlock->m_offsetFromAllocLocation;
realloc(freeLoc, 0);
}
GpAllocator_C *GpAllocator_C::GetInstance()
{
return &ms_instance;
}
GpAllocator_C GpAllocator_C::ms_instance;

View File

@@ -0,0 +1,17 @@
#pragma once
#include "IGpAllocator.h"
class GpAllocator_C final : public IGpAllocator
{
public:
void *Realloc(void *buf, size_t newSize) override;
static GpAllocator_C *GetInstance();
private:
void *Alloc(size_t size);
void Free(void *ptr);
static GpAllocator_C ms_instance;
};

View File

@@ -3,7 +3,7 @@
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<IncludePath>$(SolutionDir)SDL2-2.0.12\include;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)SDL2-2.0.12\include;$(SolutionDir)AerofoilPortable;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)SDL2-2.0.12\lib\x64;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup>

View File

@@ -84,6 +84,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
<ClCompile Include="..\Aerofoil\GpColorCursor_Win32.cpp" />
<ClCompile Include="..\Aerofoil\GpFileStream_Win32.cpp" />
<ClCompile Include="..\Aerofoil\GpFileSystem_Win32.cpp" />
@@ -93,8 +94,6 @@
<ClCompile Include="..\Aerofoil\GpThreadEvent_Win32.cpp" />
<ClCompile Include="GpAudioDriver_SDL2.cpp" />
<ClCompile Include="GpDisplayDriver_SDL_GL2.cpp" />
<ClCompile Include="GpFiberStarter_SDL.cpp" />
<ClCompile Include="GpFiber_SDL.cpp" />
<ClCompile Include="GpInputDriver_SDL_Gamepad.cpp" />
<ClCompile Include="GpMain_SDL_Win32.cpp" />
<ClCompile Include="ShaderCode\CopyQuadP.cpp" />

View File

@@ -48,12 +48,6 @@
<ClCompile Include="ShaderCode\ScaleQuadP.cpp">
<Filter>Source Files\ShaderCode</Filter>
</ClCompile>
<ClCompile Include="GpFiber_SDL.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GpFiberStarter_SDL.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GpDisplayDriver_SDL_GL2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -72,6 +66,9 @@
<ClCompile Include="GpInputDriver_SDL_Gamepad.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ShaderCode\Functions.h">

View File

@@ -0,0 +1,8 @@
#include "GpAudioDriver_SDL2.cpp"
#include "GpDisplayDriver_SDL_GL2.cpp"
#include "GpInputDriver_SDL_Gamepad.cpp"
#include "ShaderCode/CopyQuadP.cpp"
#include "ShaderCode/DrawQuadPaletteP.cpp"
#include "ShaderCode/DrawQuad32P.cpp"
#include "ShaderCode/DrawQuadV.cpp"
#include "ShaderCode/ScaleQuadP.cpp"

View File

@@ -11,6 +11,7 @@ LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../GpShell \
$(LOCAL_PATH)/../Common \
$(LOCAL_PATH)/../PortabilityLayer \
$(LOCAL_PATH)/../AerofoilPortable \
$(LOCAL_PATH)/$(SDL_PATH)/include
LOCAL_CFLAGS := -DGP_DEBUG_CONFIG=0
@@ -19,8 +20,6 @@ LOCAL_CFLAGS := -DGP_DEBUG_CONFIG=0
LOCAL_SRC_FILES := \
GpAudioDriver_SDL2.cpp \
GpDisplayDriver_SDL_GL2.cpp \
GpFiber_SDL.cpp \
GpFiberStarter_SDL.cpp \
ShaderCode/CopyQuadP.cpp \
ShaderCode/DrawQuadPaletteP.cpp \
ShaderCode/DrawQuad32P.cpp \

View File

@@ -1,3 +1,5 @@
#include "CoreDefs.h"
#include "IGpAudioBuffer.h"
#include "IGpAudioDriver.h"
#include "IGpAudioChannel.h"
#include "IGpAudioChannelCallbacks.h"
@@ -5,21 +7,28 @@
#include "IGpPrefsHandler.h"
#include "IGpSystemServices.h"
#include "GpAudioDriverProperties.h"
#include "CoreDefs.h"
#include "GpSDL.h"
#include "SDL_audio.h"
#include "GpRingBuffer.h"
#include "SDL_atomic.h"
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <new>
#include <stdio.h>
#include <chrono>
class GpAudioDriver_SDL2;
typedef std::chrono::high_resolution_clock::duration GpAudioDriver_SDL2_Duration_t;
typedef std::chrono::high_resolution_clock::time_point GpAudioDriver_SDL2_TimePoint_t;
typedef std::chrono::high_resolution_clock::period GpAudioDriver_SDL2_Period_t;
typedef std::chrono::high_resolution_clock::rep GpAudioDriver_SDL2_Rep_t;
static void *AlignedAlloc(size_t size, size_t alignment)
{
void *storage = malloc(size + alignment);
@@ -46,72 +55,150 @@ static void AlignedFree(void *ptr)
free(storageLoc);
}
struct GpAudioChannelBufferChain_SDL2 final
{
GpAudioChannelBufferChain_SDL2();
static GpAudioChannelBufferChain_SDL2 *Alloc();
void Release();
static const size_t kMaxCapacity = 65536;
size_t m_consumed;
size_t m_used;
uint8_t m_data[kMaxCapacity];
GpAudioChannelBufferChain_SDL2 *m_next;
bool m_hasTrigger;
};
class GP_ALIGNED(GP_SYSTEM_MEMORY_ALIGNMENT) GpAudioChannel_SDL2 final : public IGpAudioChannel
class GpAudioBuffer_SDL2 final : public IGpAudioBuffer
{
public:
enum ChannelState
{
ChannelState_Idle,
ChannelState_Playing,
ChannelState_Stopped,
};
typedef int16_t AudioSample_t;
static GpAudioBuffer_SDL2 *Create(const void *data, size_t size);
void AddRef() override;
void Release() override;
const AudioSample_t *GetData() const;
size_t GetSize() const;
private:
GpAudioBuffer_SDL2(const AudioSample_t *data, size_t size);
~GpAudioBuffer_SDL2();
void Destroy();
const AudioSample_t *m_data;
size_t m_size;
SDL_atomic_t m_count;
};
GpAudioBuffer_SDL2 *GpAudioBuffer_SDL2::Create(const void *data, size_t size)
{
size_t baseSize = sizeof(GpAudioBuffer_SDL2) + GP_SYSTEM_MEMORY_ALIGNMENT + 1;
baseSize -= baseSize % GP_SYSTEM_MEMORY_ALIGNMENT;
void *storage = malloc(size * sizeof(AudioSample_t) + baseSize);
if (!storage)
return nullptr;
AudioSample_t *dataPos = reinterpret_cast<AudioSample_t*>(static_cast<uint8_t*>(storage) + baseSize);
// Convert from u8 to s16
const uint8_t *srcData = static_cast<const uint8_t*>(data);
for (size_t i = 0; i < size; i++)
dataPos[i] = srcData[i] - 0x80;
return new (storage) GpAudioBuffer_SDL2(dataPos, size);
}
void GpAudioBuffer_SDL2::AddRef()
{
SDL_AtomicAdd(&m_count, 1);
}
void GpAudioBuffer_SDL2::Release()
{
int prevCount = SDL_AtomicAdd(&m_count, -1);
if (prevCount == 1)
this->Destroy();
}
const int16_t *GpAudioBuffer_SDL2::GetData() const
{
return m_data;
}
size_t GpAudioBuffer_SDL2::GetSize() const
{
return m_size;
}
GpAudioBuffer_SDL2::GpAudioBuffer_SDL2(const int16_t *data, size_t size)
: m_data(data)
, m_size(size)
{
SDL_AtomicSet(&m_count, 1);
}
GpAudioBuffer_SDL2::~GpAudioBuffer_SDL2()
{
}
void GpAudioBuffer_SDL2::Destroy()
{
this->~GpAudioBuffer_SDL2();
free(this);
}
class GpAudioChannel_SDL2 final : public IGpAudioChannel
{
public:
friend class GpAudioDriver_SDL2;
typedef GpAudioBuffer_SDL2::AudioSample_t AudioSample_t;
GpAudioChannel_SDL2();
GpAudioChannel_SDL2(GpAudioDriver_SDL2_Duration_t latency, GpAudioDriver_SDL2_Duration_t bufferTime, size_t bufferSamplesMax, uint16_t sampleRate);
~GpAudioChannel_SDL2();
void AddRef();
void Release();
void SetAudioChannelContext(IGpAudioChannelCallbacks *callbacks) override;
void PostBuffer(const void *buffer, size_t bufferSize) override;
bool PostBuffer(IGpAudioBuffer *buffer) override;
void Stop() override;
void Destroy() override;
void Consume(uint8_t *output, size_t sz);
void Consume(int16_t *output, size_t sz, GpAudioDriver_SDL2_TimePoint_t mixStartTime, GpAudioDriver_SDL2_TimePoint_t mixEndTime);
static GpAudioChannel_SDL2 *Alloc(GpAudioDriver_SDL2 *driver);
static GpAudioChannel_SDL2 *Alloc(GpAudioDriver_SDL2 *driver, GpAudioDriver_SDL2_Duration_t latency, GpAudioDriver_SDL2_Duration_t bufferTime, size_t bufferSamplesMax, uint16_t sampleRate);
private:
bool Init(GpAudioDriver_SDL2 *driver);
static const size_t kMaxBuffers = 16;
IGpAudioChannelCallbacks *m_callbacks;
IGpMutex *m_mutex;
GpAudioDriver_SDL2 *m_owner;
SDL_atomic_t m_refCount;
GpAudioChannelBufferChain_SDL2 *m_firstPendingBuffer;
GpAudioChannelBufferChain_SDL2 *m_lastPendingBuffer;
GpAudioBuffer_SDL2 *m_pendingBuffers[kMaxBuffers];
size_t m_nextPendingBufferConsumePos;
size_t m_nextPendingBufferInsertionPos;
size_t m_numQueuedBuffers;
size_t m_firstBufferSamplesConsumed;
ChannelState m_channelState;
GpAudioDriver_SDL2_TimePoint_t m_timestamp; // Time that audio will be consumed if posted to the channel, if m_hasTimestamp is true.
GpAudioDriver_SDL2_Duration_t m_latency;
GpAudioDriver_SDL2_Duration_t m_bufferTime;
size_t m_bufferSamplesMax;
size_t m_leadingSilence;
uint16_t m_sampleRate;
bool m_isMixing;
bool m_hasTimestamp;
};
class GP_ALIGNED(GP_SYSTEM_MEMORY_ALIGNMENT) GpAudioDriver_SDL2 final : public IGpAudioDriver, public IGpPrefsHandler
class GpAudioDriver_SDL2 final : public IGpAudioDriver, public IGpPrefsHandler
{
public:
friend class GpAudioChannel_SDL2;
typedef GpAudioChannel_SDL2::AudioSample_t AudioSample_t;
explicit GpAudioDriver_SDL2(const GpAudioDriverProperties &properties);
~GpAudioDriver_SDL2();
IGpAudioBuffer *CreateBuffer(const void *data, size_t size) override;
IGpAudioChannel *CreateChannel() override;
void SetMasterVolume(uint32_t vol, uint32_t maxVolume) override;
void Shutdown() override;
@@ -122,63 +209,59 @@ public:
bool Init();
static GpAudioDriver_SDL2_TimePoint_t GetCurrentTime();
private:
void DetachAudioChannel(GpAudioChannel_SDL2 *channel);
static void SDLCALL StaticMixAudio(void *userdata, Uint8 *stream, int len);
void MixAudio(void *stream, size_t len);
void RefillMixChunk(GpAudioChannel_SDL2 *const*channels, size_t numChannels);
void RefillMixChunk(GpAudioChannel_SDL2 *const*channels, size_t numChannels, size_t maxSamplesToFill, GpAudioDriver_SDL2_TimePoint_t mixStartTime, GpAudioDriver_SDL2_TimePoint_t mixEndTime);
static void AddSamples(AudioSample_t *GP_RESTRICT dest, const AudioSample_t *GP_RESTRICT src, size_t nSamples);
GpAudioDriverProperties m_properties;
IGpMutex *m_mutex;
IGpMutex *m_mixState;
static const size_t kMaxChannels = 16;
static const size_t kMixChunkSize = 256;
static const int16_t kMaxAudioVolumeScale = 25;
static const size_t kMixChunkSamples = 512;
static const int16_t kMaxAudioVolumeScale = 64;
GpAudioChannel_SDL2 *m_channels[kMaxChannels];
size_t m_numChannels;
unsigned int m_sampleRate;
GpAudioDriver_SDL2_Duration_t m_latency;
GpAudioDriver_SDL2_Duration_t m_bufferTime;
size_t m_bufferSamples;
bool m_sdlAudioRunning;
GP_ALIGNED(GP_SYSTEM_MEMORY_ALIGNMENT) int16_t m_mixChunk[kMixChunkSize];
GP_ALIGNED(GP_SYSTEM_MEMORY_ALIGNMENT) int16_t m_mixChunk[kMixChunkSamples];
size_t m_mixChunkReadOffset;
int16_t m_audioVolumeScale;
};
GpAudioChannelBufferChain_SDL2::GpAudioChannelBufferChain_SDL2()
: m_used(0)
, m_consumed(0)
, m_next(nullptr)
, m_hasTrigger(false)
{
}
GpAudioChannelBufferChain_SDL2 *GpAudioChannelBufferChain_SDL2::Alloc()
{
void *storage = AlignedAlloc(sizeof(GpAudioChannelBufferChain_SDL2), GP_SYSTEM_MEMORY_ALIGNMENT);
return new (storage) GpAudioChannelBufferChain_SDL2();
}
void GpAudioChannelBufferChain_SDL2::Release()
{
this->~GpAudioChannelBufferChain_SDL2();
AlignedFree(this);
}
/////////////////////////////////////////////////////////////////////////////////////////
// GpAudioChannel
GpAudioChannel_SDL2::GpAudioChannel_SDL2()
GpAudioChannel_SDL2::GpAudioChannel_SDL2(GpAudioDriver_SDL2_Duration_t latency, GpAudioDriver_SDL2_Duration_t bufferTime, size_t bufferSamplesMax, uint16_t sampleRate)
: m_callbacks(nullptr)
, m_mutex(nullptr)
, m_owner(nullptr)
, m_firstPendingBuffer(nullptr)
, m_lastPendingBuffer(nullptr)
, m_latency(latency)
, m_bufferTime(bufferTime)
, m_bufferSamplesMax(bufferSamplesMax)
, m_leadingSilence(0)
, m_sampleRate(sampleRate)
, m_isMixing(false)
, m_hasTimestamp(false)
, m_nextPendingBufferConsumePos(0)
, m_nextPendingBufferInsertionPos(0)
, m_numQueuedBuffers(0)
, m_firstBufferSamplesConsumed(0)
{
SDL_AtomicSet(&m_refCount, 1);
}
@@ -190,12 +273,7 @@ GpAudioChannel_SDL2::~GpAudioChannel_SDL2()
if (m_mutex)
m_mutex->Destroy();
while (m_firstPendingBuffer)
{
GpAudioChannelBufferChain_SDL2 *buffer = m_firstPendingBuffer;
m_firstPendingBuffer = buffer->m_next;
buffer->Release();
}
assert(m_numQueuedBuffers == 0);
}
void GpAudioChannel_SDL2::AddRef()
@@ -218,54 +296,70 @@ void GpAudioChannel_SDL2::SetAudioChannelContext(IGpAudioChannelCallbacks *callb
m_callbacks = callbacks;
}
void GpAudioChannel_SDL2::PostBuffer(const void *buffer, size_t bufferSize)
bool GpAudioChannel_SDL2::PostBuffer(IGpAudioBuffer *buffer)
{
buffer->AddRef();
m_mutex->Lock();
while (bufferSize > 0)
if (m_numQueuedBuffers == kMaxBuffers)
{
GpAudioChannelBufferChain_SDL2 *newBuffer = GpAudioChannelBufferChain_SDL2::Alloc();
if (newBuffer == nullptr)
break;
if (m_lastPendingBuffer == nullptr)
m_firstPendingBuffer = newBuffer;
else
m_lastPendingBuffer->m_next = newBuffer;
m_lastPendingBuffer = newBuffer;
size_t bufferable = newBuffer->kMaxCapacity;
if (bufferSize < bufferable)
bufferable = bufferSize;
memcpy(newBuffer->m_data, buffer, bufferable);
buffer = static_cast<const uint8_t*>(buffer) + bufferable;
bufferSize -= bufferable;
m_lastPendingBuffer->m_used = bufferable;
m_lastPendingBuffer->m_hasTrigger = (bufferSize == 0);
m_mutex->Unlock();
buffer->Release();
return false;
}
size_t leadingSilence = 0;
if (m_numQueuedBuffers == 0 && m_hasTimestamp && !m_isMixing)
{
GpAudioDriver_SDL2_TimePoint_t queueTime = GpAudioDriver_SDL2::GetCurrentTime() + m_latency;
if (queueTime > m_timestamp)
{
const GpAudioDriver_SDL2_Duration_t leadTime = queueTime - m_timestamp;
if (leadTime > m_bufferTime)
leadingSilence = m_bufferSamplesMax;
else
{
const GpAudioDriver_SDL2_Rep_t leadTimeRep = leadTime.count();
leadingSilence = leadTimeRep * static_cast<GpAudioDriver_SDL2_Rep_t>(m_sampleRate) * GpAudioDriver_SDL2_Period_t::num / GpAudioDriver_SDL2_Period_t::den;
}
}
}
m_leadingSilence = leadingSilence;
m_pendingBuffers[m_nextPendingBufferInsertionPos++] = static_cast<GpAudioBuffer_SDL2*>(buffer);
m_numQueuedBuffers++;
m_nextPendingBufferInsertionPos = m_nextPendingBufferInsertionPos % kMaxBuffers;
m_mutex->Unlock();
return true;
}
void GpAudioChannel_SDL2::Stop()
{
m_mutex->Lock();
GpAudioChannelBufferChain_SDL2 *buffer = m_firstPendingBuffer;
m_firstPendingBuffer = nullptr;
m_lastPendingBuffer = nullptr;
m_leadingSilence = 0;
while (buffer)
size_t numBuffersToDischarge = m_numQueuedBuffers;
for (size_t i = 0; i < numBuffersToDischarge; i++)
{
if (buffer->m_hasTrigger && m_callbacks)
GpAudioBuffer_SDL2 *buffer = m_pendingBuffers[m_nextPendingBufferConsumePos];
m_nextPendingBufferConsumePos = (m_nextPendingBufferConsumePos + 1) % kMaxBuffers;
m_numQueuedBuffers--;
m_firstBufferSamplesConsumed = 0;
if (m_callbacks)
m_callbacks->NotifyBufferFinished();
GpAudioChannelBufferChain_SDL2 *nextBuffer = buffer->m_next;
buffer->Release();
buffer = nextBuffer;
}
m_mutex->Unlock();
@@ -289,25 +383,57 @@ bool GpAudioChannel_SDL2::Init(GpAudioDriver_SDL2 *driver)
return true;
}
void GpAudioChannel_SDL2::Consume(uint8_t *output, size_t sz)
void GpAudioChannel_SDL2::Consume(int16_t *output, size_t sz, GpAudioDriver_SDL2_TimePoint_t mixStartTime, GpAudioDriver_SDL2_TimePoint_t mixEndTime)
{
m_mutex->Lock();
while (m_firstPendingBuffer != nullptr)
m_isMixing = true;
m_hasTimestamp = true;
m_timestamp = mixEndTime;
if (sz <= m_leadingSilence)
{
GpAudioChannelBufferChain_SDL2 *buffer = m_firstPendingBuffer;
const size_t available = (buffer->m_used - buffer->m_consumed);
memset(output, 0, sz * sizeof(AudioSample_t));
m_leadingSilence -= sz;
m_isMixing = false;
m_mutex->Unlock();
return;
}
else
{
size_t leadingSilence = m_leadingSilence;
if (leadingSilence > 0)
{
memset(output, 0, leadingSilence * sizeof(AudioSample_t));
output += leadingSilence;
sz -= leadingSilence;
m_leadingSilence = 0;
}
}
while (m_numQueuedBuffers > 0)
{
GpAudioBuffer_SDL2 *buffer = m_pendingBuffers[m_nextPendingBufferConsumePos];
const int16_t *bufferData = buffer->GetData();
const size_t bufferSize = buffer->GetSize();
assert(m_firstBufferSamplesConsumed < bufferSize);
const size_t available = (bufferSize - m_firstBufferSamplesConsumed);
if (available <= sz)
{
memcpy(output, buffer->m_data + buffer->m_consumed, available);
memcpy(output, bufferData + m_firstBufferSamplesConsumed, available * sizeof(AudioSample_t));
sz -= available;
output += available;
m_firstPendingBuffer = buffer->m_next;
if (m_firstPendingBuffer == nullptr)
m_lastPendingBuffer = nullptr;
m_nextPendingBufferConsumePos = (m_nextPendingBufferConsumePos + 1) % kMaxBuffers;
m_numQueuedBuffers--;
if (buffer->m_hasTrigger && m_callbacks)
m_firstBufferSamplesConsumed = 0;
if (m_callbacks)
m_callbacks->NotifyBufferFinished();
buffer->Release();
@@ -317,26 +443,28 @@ void GpAudioChannel_SDL2::Consume(uint8_t *output, size_t sz)
}
else
{
memcpy(output, buffer->m_data + buffer->m_consumed, sz);
buffer->m_consumed += sz;
buffer += sz;
memcpy(output, bufferData + m_firstBufferSamplesConsumed, sz * sizeof(AudioSample_t));
m_firstBufferSamplesConsumed += sz;
output += sz;
sz = 0;
break;
}
}
m_isMixing = false;
m_mutex->Unlock();
memset(output, 0x80, sz);
memset(output, 0, sz * sizeof(AudioSample_t));
}
GpAudioChannel_SDL2 *GpAudioChannel_SDL2::Alloc(GpAudioDriver_SDL2 *driver)
GpAudioChannel_SDL2 *GpAudioChannel_SDL2::Alloc(GpAudioDriver_SDL2 *driver, GpAudioDriver_SDL2_Duration_t latency, GpAudioDriver_SDL2_Duration_t bufferTime, size_t bufferSamplesMax, uint16_t sampleRate)
{
void *storage = AlignedAlloc(sizeof(GpAudioChannel_SDL2), GP_SYSTEM_MEMORY_ALIGNMENT);
if (!storage)
return nullptr;
GpAudioChannel_SDL2 *channel = new (storage) GpAudioChannel_SDL2();
GpAudioChannel_SDL2 *channel = new (storage) GpAudioChannel_SDL2(latency, bufferTime, bufferSamplesMax, sampleRate);
if (!channel->Init(driver))
{
channel->Destroy();
@@ -354,15 +482,18 @@ GpAudioDriver_SDL2::GpAudioDriver_SDL2(const GpAudioDriverProperties &properties
: m_properties(properties)
, m_mutex(nullptr)
, m_numChannels(0)
, m_sampleRate(0)
, m_latency(GpAudioDriver_SDL2_Duration_t::zero())
, m_bufferTime(GpAudioDriver_SDL2_Duration_t::zero())
, m_sdlAudioRunning(false)
, m_mixChunkReadOffset(kMixChunkSize)
, m_mixChunkReadOffset(kMixChunkSamples)
, m_audioVolumeScale(kMaxAudioVolumeScale)
{
for (size_t i = 0; i < kMaxChannels; i++)
m_channels[i] = nullptr;
for (size_t i = 0; i < kMixChunkSize; i++)
for (size_t i = 0; i < kMixChunkSamples; i++)
m_mixChunk[i] = 0;
}
@@ -375,9 +506,14 @@ GpAudioDriver_SDL2::~GpAudioDriver_SDL2()
m_mutex->Destroy();
}
IGpAudioBuffer *GpAudioDriver_SDL2::CreateBuffer(const void *data, size_t size)
{
return GpAudioBuffer_SDL2::Create(data, size);
}
IGpAudioChannel *GpAudioDriver_SDL2::CreateChannel()
{
GpAudioChannel_SDL2 *newChannel = GpAudioChannel_SDL2::Alloc(this);
GpAudioChannel_SDL2 *newChannel = GpAudioChannel_SDL2::Alloc(this, m_latency, m_bufferTime, m_bufferSamples, m_sampleRate);
if (!newChannel)
return nullptr;
@@ -437,7 +573,7 @@ bool GpAudioDriver_SDL2::Init()
requestedSpec.channels = 1;
requestedSpec.format = AUDIO_S16;
requestedSpec.freq = m_properties.m_sampleRate;
requestedSpec.samples = 512;
requestedSpec.samples = kMixChunkSamples;
requestedSpec.userdata = this;
if (SDL_OpenAudio(&requestedSpec, nullptr))
@@ -450,6 +586,10 @@ bool GpAudioDriver_SDL2::Init()
SDL_PauseAudio(0);
m_sdlAudioRunning = true;
m_sampleRate = requestedSpec.freq;
m_latency = GpAudioDriver_SDL2_Duration_t(static_cast<GpAudioDriver_SDL2_Rep_t>(GpAudioDriver_SDL2_Period_t::den * requestedSpec.samples / GpAudioDriver_SDL2_Period_t::num / m_sampleRate));
m_bufferTime = GpAudioDriver_SDL2_Duration_t(static_cast<GpAudioDriver_SDL2_Rep_t>(GpAudioDriver_SDL2_Period_t::den * requestedSpec.samples / GpAudioDriver_SDL2_Period_t::num / m_sampleRate));
m_bufferSamples = requestedSpec.samples;
return true;
}
@@ -492,11 +632,16 @@ void GpAudioDriver_SDL2::MixAudio(void *stream, size_t len)
}
m_mutex->Unlock();
size_t samplesRemaining = len / sizeof(int16_t);
const size_t totalSamples = len / sizeof(int16_t);
size_t samplesRemaining = totalSamples;
GpAudioDriver_SDL2_TimePoint_t audioMixStartTime = GpAudioDriver_SDL2::GetCurrentTime();
GpAudioDriver_SDL2_TimePoint_t audioMixBlockStartTime = audioMixStartTime;
size_t samplesSinceStart = 0;
for (;;)
{
size_t availableInMixChunk = kMixChunkSize - m_mixChunkReadOffset;
size_t availableInMixChunk = kMixChunkSamples - m_mixChunkReadOffset;
if (availableInMixChunk > samplesRemaining)
{
@@ -510,10 +655,17 @@ void GpAudioDriver_SDL2::MixAudio(void *stream, size_t len)
memcpy(stream, m_mixChunk + m_mixChunkReadOffset, availableInMixChunk * sizeof(int16_t));
stream = static_cast<int16_t*>(stream) + availableInMixChunk;
samplesRemaining -= availableInMixChunk;
samplesSinceStart += availableInMixChunk;
GpAudioDriver_SDL2_Duration_t audioMixDurationSinceStart = GpAudioDriver_SDL2_Duration_t(static_cast<GpAudioDriver_SDL2_Rep_t>(GpAudioDriver_SDL2_Period_t::den * samplesSinceStart / GpAudioDriver_SDL2_Period_t::num / m_sampleRate));
GpAudioDriver_SDL2_TimePoint_t audioMixBlockEndTime = audioMixStartTime + audioMixDurationSinceStart;
m_mixChunkReadOffset = 0;
RefillMixChunk(mixingChannels, numChannels);
RefillMixChunk(mixingChannels, numChannels, samplesRemaining, audioMixBlockStartTime, audioMixBlockEndTime);
audioMixBlockStartTime = audioMixBlockEndTime;
samplesRemaining -= availableInMixChunk;
}
}
@@ -521,42 +673,66 @@ void GpAudioDriver_SDL2::MixAudio(void *stream, size_t len)
mixingChannels[i]->Release();
}
void GpAudioDriver_SDL2::RefillMixChunk(GpAudioChannel_SDL2 *const*channels, size_t numChannels)
void GpAudioDriver_SDL2::RefillMixChunk(GpAudioChannel_SDL2 *const*channels, size_t numChannels, size_t maxSamplesToFill, GpAudioDriver_SDL2_TimePoint_t mixStartTime, GpAudioDriver_SDL2_TimePoint_t mixEndTime)
{
uint8_t audioMixBufferUnaligned[kMixChunkSize + GP_SYSTEM_MEMORY_ALIGNMENT];
uint8_t *audioMixBuffer = audioMixBufferUnaligned;
uint8_t audioMixBufferUnaligned[kMixChunkSamples * sizeof(AudioSample_t) + GP_SYSTEM_MEMORY_ALIGNMENT];
uint8_t *audioMixBufferBytes = audioMixBufferUnaligned;
{
uintptr_t bufferPtr = reinterpret_cast<uintptr_t>(audioMixBuffer);
uintptr_t bufferPtr = reinterpret_cast<uintptr_t>(audioMixBufferBytes);
size_t alignPadding = GP_SYSTEM_MEMORY_ALIGNMENT - (bufferPtr % GP_SYSTEM_MEMORY_ALIGNMENT);
audioMixBuffer += alignPadding;
audioMixBufferBytes += alignPadding;
}
AudioSample_t *audioMixBuffer = reinterpret_cast<AudioSample_t*>(audioMixBufferBytes);
bool noAudio = true;
const int16_t audioVolumeScale = m_audioVolumeScale;
size_t samplesToFill = kMixChunkSamples;
if (samplesToFill > maxSamplesToFill)
{
m_mixChunkReadOffset += samplesToFill - maxSamplesToFill;
samplesToFill = maxSamplesToFill;
}
else
m_mixChunkReadOffset = 0;
AudioSample_t *mixChunkStart = m_mixChunk + m_mixChunkReadOffset;
for (size_t i = 0; i < numChannels; i++)
{
channels[i]->Consume(audioMixBuffer, kMixChunkSize);
channels[i]->Consume(audioMixBuffer, samplesToFill, mixStartTime, mixEndTime);
if (i == 0)
{
noAudio = false;
for (size_t j = 0; j < kMixChunkSize; j++)
m_mixChunk[j] = (static_cast<int16_t>(audioMixBuffer[j]) - 0x80) * audioVolumeScale;
memcpy(mixChunkStart, audioMixBuffer, samplesToFill * sizeof(AudioSample_t));
}
else
{
for (size_t j = 0; j < kMixChunkSize; j++)
m_mixChunk[j] += (static_cast<int16_t>(audioMixBuffer[j]) - 0x80) * audioVolumeScale;
}
AddSamples(mixChunkStart, audioMixBuffer, samplesToFill);
}
if (noAudio)
memset(m_mixChunk, 0, kMixChunkSize * sizeof(m_mixChunk[0]));
memset(mixChunkStart, 0, samplesToFill * sizeof(AudioSample_t));
else
{
for (size_t i = 0; i < samplesToFill; i++)
mixChunkStart[i] *= audioVolumeScale;
}
}
void GpAudioDriver_SDL2::AddSamples(AudioSample_t *GP_RESTRICT dest, const AudioSample_t *GP_RESTRICT src, size_t nSamples)
{
for (size_t i = 0; i < nSamples; i++)
dest[i] += src[i];
}
GpAudioDriver_SDL2_TimePoint_t GpAudioDriver_SDL2::GetCurrentTime()
{
return std::chrono::high_resolution_clock::now();
}
IGpAudioDriver *GpDriver_CreateAudioDriver_SDL(const GpAudioDriverProperties &properties)
{

View File

@@ -1,12 +1,14 @@
#include "IGpDisplayDriver.h"
#include "CoreDefs.h"
#include "GpApplicationName.h"
#include "GpComPtr.h"
#include "GpFiber_SDL.h"
#include "GpDisplayDriverProperties.h"
#include "GpVOSEvent.h"
#include "GpRingBuffer.h"
#include "GpInputDriver_SDL_Gamepad.h"
#include "GpSDL.h"
#include "GpUnicode.h"
#include "IGpCursor.h"
#include "IGpDisplayDriverSurface.h"
#include "IGpLogDriver.h"
@@ -28,6 +30,9 @@
#include <vector>
#include <algorithm>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#pragma push_macro("LoadCursor")
#ifdef LoadCursor
@@ -48,68 +53,6 @@ struct GpDisplayDriver_SDL_GL2_Prefs
bool m_isFullScreen;
};
namespace DeleteMe
{
bool DecodeCodePoint(const uint8_t *characters, size_t availableCharacters, size_t &outCharactersDigested, uint32_t &outCodePoint)
{
if (availableCharacters <= 0)
return false;
if ((characters[0] & 0x80) == 0x00)
{
outCharactersDigested = 1;
outCodePoint = characters[0];
return true;
}
size_t sz = 0;
uint32_t codePoint = 0;
uint32_t minCodePoint = 0;
if ((characters[0] & 0xe0) == 0xc0)
{
sz = 2;
minCodePoint = 0x80;
codePoint = (characters[0] & 0x1f);
}
else if ((characters[0] & 0xf0) == 0xe0)
{
sz = 3;
minCodePoint = 0x800;
codePoint = (characters[0] & 0x0f);
}
else if ((characters[0] & 0xf8) == 0xf0)
{
sz = 4;
minCodePoint = 0x10000;
codePoint = (characters[0] & 0x07);
}
else
return false;
if (availableCharacters < sz)
return false;
for (size_t auxByte = 1; auxByte < sz; auxByte++)
{
if ((characters[auxByte] & 0xc0) != 0x80)
return false;
codePoint = (codePoint << 6) | (characters[auxByte] & 0x3f);
}
if (codePoint < minCodePoint || codePoint > 0x10ffff)
return false;
if (codePoint >= 0xd800 && codePoint <= 0xdfff)
return false;
outCodePoint = codePoint;
outCharactersDigested = sz;
return true;
}
}
namespace GpBinarizedShaders
{
extern const char *g_drawQuadV_GL2;
@@ -214,6 +157,7 @@ struct GpGLFunctions
static void CheckGLError(const GpGLFunctions &gl, IGpLogDriver *logger)
{
#if GP_DEBUG_CONFIG
GLenum errorCode = gl.GetError();
if (errorCode != 0)
{
@@ -222,6 +166,7 @@ static void CheckGLError(const GpGLFunctions &gl, IGpLogDriver *logger)
}
assert(errorCode == 0);
#endif
}
class GpGLObject
@@ -729,17 +674,18 @@ public:
explicit GpDisplayDriver_SDL_GL2(const GpDisplayDriverProperties &properties);
~GpDisplayDriver_SDL_GL2();
bool Init();
bool Init() GP_ASYNCIFY_PARANOID_OVERRIDE;
void ServeTicks(int tickCount) GP_ASYNCIFY_PARANOID_OVERRIDE;
void ForceSync() override;
void Shutdown() GP_ASYNCIFY_PARANOID_OVERRIDE;
void TranslateSDLMessage(const SDL_Event *msg, IGpVOSEventQueue *eventQueue, float pixelScaleX, float pixelScaleY, bool obstructiveTextInput);
void Run() override;
void Shutdown() override;
void GetInitialDisplayResolution(unsigned int *width, unsigned int *height) override;
IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext) override;
void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) override;
IGpCursor *CreateBWCursor(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY) override;
IGpCursor *CreateColorCursor(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY) override;
IGpCursor *CreateBWCursor(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY) GP_ASYNCIFY_PARANOID_OVERRIDE;
IGpCursor *CreateColorCursor(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY) GP_ASYNCIFY_PARANOID_OVERRIDE;
void SetCursor(IGpCursor *cursor) override;
void SetStandardCursor(EGpStandardCursor_t standardCursor) override;
void UpdatePalette(const void *paletteData) override;
@@ -797,7 +743,7 @@ private:
void ScaleVirtualScreen();
GpDisplayDriverTickStatus_t PresentFrameAndSync();
bool SyncRender();
GpGLFunctions m_gl;
GpDisplayDriverProperties m_properties;
@@ -839,9 +785,6 @@ private:
GpComPtr<GpGLRenderTargetView> m_upscaleTextureRTV;
GpComPtr<GpGLTexture> m_upscaleTexture;
uint32_t m_upscaleTextureWidth;
uint32_t m_upscaleTextureHeight;
GpComPtr<GpGLVertexArray> m_quadVertexArray;
GpComPtr<GpGLBuffer> m_quadVertexBufferKeepalive;
GpComPtr<GpGLBuffer> m_quadIndexBuffer;
@@ -898,7 +841,10 @@ private:
uint32_t m_initialHeightVirtual;
float m_pixelScaleX;
float m_pixelScaleY;
bool m_useUpscaleFilter;
uint32_t m_upscaleTextureWidth;
uint32_t m_upscaleTextureHeight;
GpCursor_SDL2 *m_activeCursor;
GpCursor_SDL2 *m_pendingCursor;
@@ -906,9 +852,6 @@ private:
EGpStandardCursor_t m_pendingStandardCursor;
bool m_mouseIsInClientArea;
IGpFiber *m_vosFiber;
IGpThreadEvent *m_vosEvent;
float m_bgColor[4];
bool m_bgIsDark;
@@ -1193,8 +1136,8 @@ GpDisplayDriver_SDL_GL2::GpDisplayDriver_SDL_GL2(const GpDisplayDriverProperties
, m_pixelScaleX(1.0f)
, m_pixelScaleY(1.0f)
, m_useUpscaleFilter(false)
, m_vosFiber(nullptr)
, m_vosEvent(nullptr)
, m_upscaleTextureWidth(0)
, m_upscaleTextureHeight(0)
, m_pendingCursor(nullptr)
, m_activeCursor(nullptr)
, m_currentStandardCursor(EGpStandardCursors::kArrow)
@@ -1339,9 +1282,246 @@ GpDisplayDriver_SDL_GL2::~GpDisplayDriver_SDL_GL2()
bool GpDisplayDriver_SDL_GL2::Init()
{
#if GP_GL_IS_OPENGL_4_CONTEXT
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
#endif
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
IGpLogDriver *logger = m_properties.m_logger;
uint32_t windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
if (m_properties.m_systemServices->IsFullscreenOnStartup())
{
windowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
m_isFullScreen = true;
}
else
windowFlags |= SDL_WINDOW_RESIZABLE;
m_window = SDL_CreateWindow(GP_APPLICATION_NAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, m_windowWidthPhysical, m_windowHeightPhysical, windowFlags);
if (m_isFullScreen)
{
m_windowModeRevertWidth = m_windowWidthPhysical;
m_windowModeRevertHeight = m_windowHeightPhysical;
int windowWidth = 0;
int windowHeight = 0;
SDL_GetWindowSize(m_window, &windowWidth, &windowHeight);
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Initialized fullscreen SDL window %i x %i", windowWidth, windowHeight);
m_windowWidthPhysical = windowWidth;
m_windowHeightPhysical = windowHeight;
uint32_t desiredWidth = windowWidth;
uint32_t desiredHeight = windowHeight;
uint32_t virtualWidth = m_windowWidthVirtual;
uint32_t virtualHeight = m_windowHeightVirtual;
float pixelScaleX = m_pixelScaleX;
float pixelScaleY = m_pixelScaleY;
if (m_properties.m_adjustRequestedResolutionFunc(m_properties.m_adjustRequestedResolutionFuncContext, desiredWidth, desiredHeight, virtualWidth, virtualHeight, pixelScaleX, pixelScaleY))
{
m_windowWidthVirtual = virtualWidth;
m_windowHeightVirtual = virtualHeight;
m_pixelScaleX = pixelScaleX;
m_pixelScaleY = pixelScaleY;
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "AdjustedRequestedResolution succeeded. Virtual dimensions %i x %i Pixel scale %f x %f", static_cast<int>(virtualWidth), static_cast<int>(virtualHeight), static_cast<float>(pixelScaleX), static_cast<float>(pixelScaleY));
}
else
{
if (logger)
logger->Printf(IGpLogDriver::Category_Error, "AdjustedRequestedResolution failed!");
}
}
const bool obstructiveTextInput = m_properties.m_systemServices->IsTextInputObstructive();
if (!obstructiveTextInput)
SDL_StartTextInput();
StartOpenGLForWindow(logger);
if (!m_gl.LookUpFunctions())
return false;
m_initialWidthVirtual = m_windowWidthVirtual;
m_initialHeightVirtual = m_windowHeightVirtual;
return true;
}
void GpDisplayDriver_SDL_GL2::ServeTicks(int ticks)
{
IGpLogDriver *logger = m_properties.m_logger;
const bool obstructiveTextInput = m_properties.m_systemServices->IsTextInputObstructive();
for (;;)
{
SDL_Event msg;
if (SDL_PollEvent(&msg) != 0)
{
switch (msg.type)
{
case SDL_MOUSEMOTION:
{
if (!m_mouseIsInClientArea)
m_mouseIsInClientArea = true;
}
break;
//case SDL_MOUSELEAVE: // Does SDL support this??
// m_mouseIsInClientArea = false;
// break;
case SDL_RENDER_DEVICE_RESET:
case SDL_RENDER_TARGETS_RESET:
{
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Triggering GL context reset due to device loss (Type: %i)", static_cast<int>(msg.type));
m_contextLost = true;
}
break;
case SDL_CONTROLLERAXISMOTION:
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
case SDL_CONTROLLERDEVICEREMAPPED:
if (IGpInputDriverSDLGamepad *gamepadDriver = IGpInputDriverSDLGamepad::GetInstance())
gamepadDriver->ProcessSDLEvent(msg);
break;
}
TranslateSDLMessage(&msg, m_properties.m_eventQueue, m_pixelScaleX, m_pixelScaleY, obstructiveTextInput);
}
else
{
if (m_isFullScreen != m_isFullScreenDesired)
{
if (m_isFullScreenDesired)
BecomeFullScreen();
else
BecomeWindowed();
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Triggering GL context reset due to fullscreen state change");
m_contextLost = true;
continue;
}
int clientWidth = 0;
int clientHeight = 0;
SDL_GetWindowSize(m_window, &clientWidth, &clientHeight);
unsigned int desiredWidth = clientWidth;
unsigned int desiredHeight = clientHeight;
if (desiredWidth != m_windowWidthPhysical || desiredHeight != m_windowHeightPhysical || m_isResolutionResetDesired)
{
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Detected window size change");
uint32_t prevWidthPhysical = m_windowWidthPhysical;
uint32_t prevHeightPhysical = m_windowHeightPhysical;
uint32_t prevWidthVirtual = m_windowWidthVirtual;
uint32_t prevHeightVirtual = m_windowHeightVirtual;
uint32_t virtualWidth = m_windowWidthVirtual;
uint32_t virtualHeight = m_windowHeightVirtual;
float pixelScaleX = 1.0f;
float pixelScaleY = 1.0f;
if (m_properties.m_adjustRequestedResolutionFunc(m_properties.m_adjustRequestedResolutionFuncContext, desiredWidth, desiredHeight, virtualWidth, virtualHeight, pixelScaleX, pixelScaleY))
{
bool resizedOK = ResizeOpenGLWindow(m_windowWidthPhysical, m_windowHeightPhysical, desiredWidth, desiredHeight, logger);
if (!resizedOK)
break; // Critical video driver error, exit
m_windowWidthVirtual = virtualWidth;
m_windowHeightVirtual = virtualHeight;
m_pixelScaleX = pixelScaleX;
m_pixelScaleY = pixelScaleY;
m_isResolutionResetDesired = false;
if (GpVOSEvent *resizeEvent = m_properties.m_eventQueue->QueueEvent())
{
resizeEvent->m_eventType = GpVOSEventTypes::kVideoResolutionChanged;
resizeEvent->m_event.m_resolutionChangedEvent.m_prevWidth = prevWidthVirtual;
resizeEvent->m_event.m_resolutionChangedEvent.m_prevHeight = prevHeightVirtual;
resizeEvent->m_event.m_resolutionChangedEvent.m_newWidth = m_windowWidthVirtual;
resizeEvent->m_event.m_resolutionChangedEvent.m_newHeight = m_windowHeightVirtual;
}
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Triggering GL context reset due to window size change");
m_contextLost = true;
continue;
}
}
if (m_contextLost)
{
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Resetting OpenGL context. Physical: %i x %i Virtual %i x %i", static_cast<int>(m_windowWidthPhysical), static_cast<int>(m_windowHeightPhysical), static_cast<int>(m_windowWidthVirtual), static_cast<int>(m_windowHeightVirtual));
// Drop everything and reset
m_res = InstancedResources();
if (m_firstSurface)
m_firstSurface->DestroyAll();
if (!InitResources(m_windowWidthPhysical, m_windowHeightPhysical, m_windowWidthVirtual, m_windowHeightVirtual))
{
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Terminating display driver due to InitResources failing");
break;
}
if (m_firstSurface)
m_firstSurface->RecreateAll();
m_contextLost = false;
continue;
}
bool wantTextInput = m_properties.m_systemServices->IsTextInputEnabled();
if (wantTextInput != m_textInputEnabled)
{
m_textInputEnabled = wantTextInput;
if (m_textInputEnabled)
SDL_StartTextInput();
else
SDL_StopTextInput();
}
// Handle dismissal of on-screen keyboard
const bool isTextInputActuallyActive = SDL_IsTextInputActive();
m_textInputEnabled = isTextInputActuallyActive;
m_properties.m_systemServices->SetTextInputEnabled(isTextInputActuallyActive);
if (SyncRender())
{
ticks--;
if (ticks <= 0)
break;
}
}
}
}
void GpDisplayDriver_SDL_GL2::ForceSync()
{
m_frameTimeAccumulated = std::chrono::nanoseconds::zero();
}
static void PostMouseEvent(IGpVOSEventQueue *eventQueue, GpMouseEventType_t eventType, GpMouseButton_t button, int32_t x, int32_t y, float pixelScaleX, float pixelScaleY)
{
if (GpVOSEvent *evt = eventQueue->QueueEvent())
@@ -1379,7 +1559,7 @@ static void PostTouchEvent(IGpVOSEventQueue *eventQueue, GpTouchEventType_t even
static bool IdentifyVKey(const SDL_KeyboardEvent *keyEvt, GpKeyIDSubset_t &outSubset, GpKeyboardInputEvent::KeyUnion &outKey)
{
SDL_KeyCode keyCode = static_cast<SDL_KeyCode>(keyEvt->keysym.sym);
SDL_Keycode keyCode = static_cast<SDL_Keycode>(keyEvt->keysym.sym);
switch (keyCode)
{
@@ -1800,7 +1980,7 @@ void GpDisplayDriver_SDL_GL2::TranslateSDLMessage(const SDL_Event *msg, IGpVOSEv
{
uint32_t codePoint;
size_t numDigested;
DeleteMe::DecodeCodePoint(reinterpret_cast<const uint8_t*>(teEvt->text) + parseOffset, lenUTF8 - parseOffset, numDigested, codePoint);
GpUnicode::UTF8::Decode(reinterpret_cast<const uint8_t*>(teEvt->text) + parseOffset, lenUTF8 - parseOffset, numDigested, codePoint);
parseOffset += numDigested;
@@ -1835,248 +2015,6 @@ void GpDisplayDriver_SDL_GL2::TranslateSDLMessage(const SDL_Event *msg, IGpVOSEv
}
}
void GpDisplayDriver_SDL_GL2::Run()
{
#if GP_GL_IS_OPENGL_4_CONTEXT
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
#endif
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
IGpLogDriver *logger = m_properties.m_logger;
m_vosEvent = m_properties.m_systemServices->CreateThreadEvent(true, false);
m_vosFiber = new GpFiber_SDL(nullptr, m_vosEvent);
uint32_t windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
if (m_properties.m_systemServices->IsFullscreenOnStartup())
{
windowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
m_isFullScreen = true;
}
else
windowFlags |= SDL_WINDOW_RESIZABLE;
m_window = SDL_CreateWindow(GP_APPLICATION_NAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, m_windowWidthPhysical, m_windowHeightPhysical, windowFlags);
if (m_isFullScreen)
{
m_windowModeRevertWidth = m_windowWidthPhysical;
m_windowModeRevertHeight = m_windowHeightPhysical;
int windowWidth = 0;
int windowHeight = 0;
SDL_GetWindowSize(m_window, &windowWidth, &windowHeight);
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Initialized fullscreen SDL window %i x %i", windowWidth, windowHeight);
m_windowWidthPhysical = windowWidth;
m_windowHeightPhysical = windowHeight;
uint32_t desiredWidth = windowWidth;
uint32_t desiredHeight = windowHeight;
uint32_t virtualWidth = m_windowWidthVirtual;
uint32_t virtualHeight = m_windowHeightVirtual;
float pixelScaleX = m_pixelScaleX;
float pixelScaleY = m_pixelScaleY;
if (m_properties.m_adjustRequestedResolutionFunc(m_properties.m_adjustRequestedResolutionFuncContext, desiredWidth, desiredHeight, virtualWidth, virtualHeight, pixelScaleX, pixelScaleY))
{
m_windowWidthVirtual = virtualWidth;
m_windowHeightVirtual = virtualHeight;
m_pixelScaleX = pixelScaleX;
m_pixelScaleY = pixelScaleY;
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "AdjustedRequestedResolution succeeded. Virtual dimensions %i x %i Pixel scale %f x %f", static_cast<int>(virtualWidth), static_cast<int>(virtualHeight), static_cast<float>(pixelScaleX), static_cast<float>(pixelScaleY));
}
else
{
if (logger)
logger->Printf(IGpLogDriver::Category_Error, "AdjustedRequestedResolution failed!");
}
}
const bool obstructiveTextInput = m_properties.m_systemServices->IsTextInputObstructive();
if (!obstructiveTextInput)
SDL_StartTextInput();
StartOpenGLForWindow(logger);
if (!m_gl.LookUpFunctions())
return;
m_initialWidthVirtual = m_windowWidthVirtual;
m_initialHeightVirtual = m_windowHeightVirtual;
for (;;)
{
SDL_Event msg;
if (SDL_PollEvent(&msg) != 0)
{
switch (msg.type)
{
case SDL_MOUSEMOTION:
{
if (!m_mouseIsInClientArea)
m_mouseIsInClientArea = true;
}
break;
//case SDL_MOUSELEAVE: // Does SDL support this??
// m_mouseIsInClientArea = false;
// break;
case SDL_RENDER_DEVICE_RESET:
case SDL_RENDER_TARGETS_RESET:
{
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Triggering GL context reset due to device loss (Type: %i)", static_cast<int>(msg.type));
m_contextLost = true;
}
break;
case SDL_CONTROLLERAXISMOTION:
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
case SDL_CONTROLLERDEVICEREMAPPED:
if (IGpInputDriverSDLGamepad *gamepadDriver = IGpInputDriverSDLGamepad::GetInstance())
gamepadDriver->ProcessSDLEvent(msg);
break;
}
TranslateSDLMessage(&msg, m_properties.m_eventQueue, m_pixelScaleX, m_pixelScaleY, obstructiveTextInput);
}
else
{
if (m_isFullScreen != m_isFullScreenDesired)
{
if (m_isFullScreenDesired)
BecomeFullScreen();
else
BecomeWindowed();
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Triggering GL context reset due to fullscreen state change");
m_contextLost = true;
continue;
}
int clientWidth = 0;
int clientHeight = 0;
SDL_GetWindowSize(m_window, &clientWidth, &clientHeight);
unsigned int desiredWidth = clientWidth;
unsigned int desiredHeight = clientHeight;
if (desiredWidth != m_windowWidthPhysical || desiredHeight != m_windowHeightPhysical || m_isResolutionResetDesired)
{
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Detected window size change");
uint32_t prevWidthPhysical = m_windowWidthPhysical;
uint32_t prevHeightPhysical = m_windowHeightPhysical;
uint32_t prevWidthVirtual = m_windowWidthVirtual;
uint32_t prevHeightVirtual = m_windowHeightVirtual;
uint32_t virtualWidth = m_windowWidthVirtual;
uint32_t virtualHeight = m_windowHeightVirtual;
float pixelScaleX = 1.0f;
float pixelScaleY = 1.0f;
if (m_properties.m_adjustRequestedResolutionFunc(m_properties.m_adjustRequestedResolutionFuncContext, desiredWidth, desiredHeight, virtualWidth, virtualHeight, pixelScaleX, pixelScaleY))
{
bool resizedOK = ResizeOpenGLWindow(m_windowWidthPhysical, m_windowHeightPhysical, desiredWidth, desiredHeight, logger);
if (!resizedOK)
break; // Critical video driver error, exit
m_windowWidthVirtual = virtualWidth;
m_windowHeightVirtual = virtualHeight;
m_pixelScaleX = pixelScaleX;
m_pixelScaleY = pixelScaleY;
m_isResolutionResetDesired = false;
if (GpVOSEvent *resizeEvent = m_properties.m_eventQueue->QueueEvent())
{
resizeEvent->m_eventType = GpVOSEventTypes::kVideoResolutionChanged;
resizeEvent->m_event.m_resolutionChangedEvent.m_prevWidth = prevWidthVirtual;
resizeEvent->m_event.m_resolutionChangedEvent.m_prevHeight = prevHeightVirtual;
resizeEvent->m_event.m_resolutionChangedEvent.m_newWidth = m_windowWidthVirtual;
resizeEvent->m_event.m_resolutionChangedEvent.m_newHeight = m_windowHeightVirtual;
}
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Triggering GL context reset due to window size change");
m_contextLost = true;
continue;
}
}
if (m_contextLost)
{
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Resetting OpenGL context. Physical: %i x %i Virtual %i x %i", static_cast<int>(m_windowWidthPhysical), static_cast<int>(m_windowHeightPhysical), static_cast<int>(m_windowWidthVirtual), static_cast<int>(m_windowHeightVirtual));
// Drop everything and reset
m_res.~InstancedResources();
new (&m_res) InstancedResources();
if (m_firstSurface)
m_firstSurface->DestroyAll();
if (!InitResources(m_windowWidthPhysical, m_windowHeightPhysical, m_windowWidthVirtual, m_windowHeightVirtual))
{
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Terminating display driver due to InitResources failing");
break;
}
if (m_firstSurface)
m_firstSurface->RecreateAll();
m_contextLost = false;
continue;
}
bool wantTextInput = m_properties.m_systemServices->IsTextInputEnabled();
if (wantTextInput != m_textInputEnabled)
{
m_textInputEnabled = wantTextInput;
if (m_textInputEnabled)
SDL_StartTextInput();
else
SDL_StopTextInput();
}
// Handle dismissal of on-screen keyboard
const bool isTextInputActuallyActive = SDL_IsTextInputActive();
m_textInputEnabled = isTextInputActuallyActive;
m_properties.m_systemServices->SetTextInputEnabled(isTextInputActuallyActive);
GpDisplayDriverTickStatus_t tickStatus = PresentFrameAndSync();
if (tickStatus == GpDisplayDriverTickStatuses::kFatalFault || tickStatus == GpDisplayDriverTickStatuses::kApplicationTerminated)
{
if (logger)
{
if (tickStatus == GpDisplayDriverTickStatuses::kFatalFault)
logger->Printf(IGpLogDriver::Category_Information, "Terminating display driver due to fatal fault");
if (tickStatus == GpDisplayDriverTickStatuses::kApplicationTerminated)
logger->Printf(IGpLogDriver::Category_Information, "Terminating display driver due to application termination");
}
break;
}
}
}
// Exit
}
void GpDisplayDriver_SDL_GL2::Shutdown()
{
this->~GpDisplayDriver_SDL_GL2();
@@ -2460,11 +2398,6 @@ bool GpDisplayDriver_SDL_GL2::InitResources(uint32_t physicalWidth, uint32_t phy
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "GpDisplayDriver_SDL_GL2::InitResources");
if ((m_pixelScaleX < 2.0f && m_pixelScaleX > 1.0f) || (m_pixelScaleY < 2.0f && m_pixelScaleY > 1.0f))
m_useUpscaleFilter = true;
else
m_useUpscaleFilter = false;
CheckGLError(m_gl, logger);
if (!InitBackBuffer(virtualWidth, virtualHeight))
@@ -2780,8 +2713,9 @@ bool GpDisplayDriver_SDL_GL2::InitBackBuffer(uint32_t width, uint32_t height)
m_gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
}
m_useUpscaleFilter = (m_pixelScaleX == 1.5f || m_pixelScaleX == 2.5f || m_pixelScaleY == 1.5f || m_pixelScaleY == 2.5f);
if (m_pixelScaleX != floor(m_pixelScaleX) || m_pixelScaleY != floor(m_pixelScaleY))
if (m_useUpscaleFilter)
{
uint32_t upscaleX = ceil(m_pixelScaleX);
uint32_t upscaleY = ceil(m_pixelScaleY);
@@ -2796,8 +2730,8 @@ bool GpDisplayDriver_SDL_GL2::InitBackBuffer(uint32_t width, uint32_t height)
return false;
}
m_res.m_upscaleTextureWidth = width * upscaleX;
m_res.m_upscaleTextureHeight = height * upscaleY;
m_upscaleTextureWidth = width * upscaleX;
m_upscaleTextureHeight = height * upscaleY;
GLenum internalFormat = SupportsSizedFormats() ? GL_RGBA8 : GL_RGBA;
@@ -2807,7 +2741,7 @@ bool GpDisplayDriver_SDL_GL2::InitBackBuffer(uint32_t width, uint32_t height)
m_gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
m_gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
m_gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
m_gl.TexImage2D(GL_TEXTURE_2D, 0, internalFormat, m_res.m_upscaleTextureWidth, m_res.m_upscaleTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
m_gl.TexImage2D(GL_TEXTURE_2D, 0, internalFormat, m_upscaleTextureWidth, m_upscaleTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
m_gl.BindTexture(GL_TEXTURE_2D, 0);
CheckGLError(m_gl, logger);
@@ -2852,7 +2786,7 @@ void GpDisplayDriver_SDL_GL2::ScaleVirtualScreen()
{
m_gl.BindFramebuffer(GL_FRAMEBUFFER, m_res.m_upscaleTextureRTV->GetID());
m_gl.Viewport(0, 0, m_res.m_upscaleTextureWidth, m_res.m_upscaleTextureHeight);
m_gl.Viewport(0, 0, m_upscaleTextureWidth, m_upscaleTextureHeight);
const BlitQuadProgram &program = m_res.m_scaleQuadProgram;
@@ -3058,8 +2992,15 @@ bool GpDisplayDriver_SDL_GL2::BlitQuadProgram::Link(GpDisplayDriver_SDL_GL2 *dri
return true;
}
GpDisplayDriverTickStatus_t GpDisplayDriver_SDL_GL2::PresentFrameAndSync()
bool GpDisplayDriver_SDL_GL2::SyncRender()
{
if (m_frameTimeAccumulated >= m_frameTimeSliceSize)
{
m_frameTimeAccumulated -= m_frameTimeSliceSize;
return true;
}
SynchronizeCursors();
float bgColor[4];
@@ -3091,6 +3032,10 @@ GpDisplayDriverTickStatus_t GpDisplayDriver_SDL_GL2::PresentFrameAndSync()
SDL_GL_SwapWindow(m_window);
#ifdef __EMSCRIPTEN__
emscripten_sleep(1);
#endif
std::chrono::time_point<std::chrono::high_resolution_clock>::duration syncTime = std::chrono::high_resolution_clock::now().time_since_epoch();
const intmax_t periodNum = std::chrono::high_resolution_clock::period::num;
const intmax_t periodDen = std::chrono::high_resolution_clock::period::den;
@@ -3181,22 +3126,9 @@ GpDisplayDriverTickStatus_t GpDisplayDriver_SDL_GL2::PresentFrameAndSync()
}
m_frameTimeAccumulated += frameTimeStep;
while (m_frameTimeAccumulated >= m_frameTimeSliceSize)
{
GpDisplayDriverTickStatus_t tickStatus = m_properties.m_tickFunc(m_properties.m_tickFuncContext, m_vosFiber);
m_frameTimeAccumulated -= m_frameTimeSliceSize;
if (tickStatus == GpDisplayDriverTickStatuses::kSynchronizing)
{
m_frameTimeAccumulated = std::chrono::high_resolution_clock::duration::zero();
break;
}
else if (tickStatus != GpDisplayDriverTickStatuses::kOK)
return tickStatus;
}
}
return GpDisplayDriverTickStatuses::kOK;
return false;
}
IGpDisplayDriver *GpDriver_CreateDisplayDriver_SDL_GL2(const GpDisplayDriverProperties &properties)
@@ -3205,18 +3137,9 @@ IGpDisplayDriver *GpDriver_CreateDisplayDriver_SDL_GL2(const GpDisplayDriverProp
if (!driver)
return nullptr;
new (driver) GpDisplayDriver_SDL_GL2(properties);
if (!driver->Init())
{
driver->Shutdown();
return nullptr;
}
return driver;
return new (driver) GpDisplayDriver_SDL_GL2(properties);
}
template<class T>
T *GpGLObjectImpl<T>::Create(GpDisplayDriver_SDL_GL2 *driver)
{
@@ -3237,4 +3160,33 @@ T *GpGLObjectImpl<T>::Create(GpDisplayDriver_SDL_GL2 *driver)
return obj;
}
#if GP_ASYNCIFY_PARANOID
bool IGpDisplayDriver::Init()
{
return static_cast<GpDisplayDriver_SDL_GL2*>(this)->Init();
}
void IGpDisplayDriver::ServeTicks(int tickCount)
{
static_cast<GpDisplayDriver_SDL_GL2*>(this)->ServeTicks(tickCount);
}
void IGpDisplayDriver::Shutdown()
{
static_cast<GpDisplayDriver_SDL_GL2*>(this)->Shutdown();
}
IGpCursor *IGpDisplayDriver::CreateBWCursor(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY)
{
return static_cast<GpDisplayDriver_SDL_GL2*>(this)->CreateBWCursor(width, height, pixelData, maskData, hotSpotX, hotSpotY);
}
IGpCursor *IGpDisplayDriver::CreateColorCursor(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY)
{
return static_cast<GpDisplayDriver_SDL_GL2*>(this)->CreateColorCursor(width, height, pixelDataRGBA, hotSpotX, hotSpotY);
}
#endif
#pragma pop_macro("LoadCursor")

View File

@@ -1,70 +0,0 @@
#include "GpFiberStarter.h"
#include "GpFiber_SDL.h"
#include "IGpSystemServices.h"
#include "IGpThreadEvent.h"
#include "SDL_thread.h"
#include <assert.h>
namespace GpFiberStarter_SDL
{
struct FiberStartState
{
GpFiberStarter::ThreadFunc_t m_threadFunc;
IGpThreadEvent *m_creatingReturnEvent;
IGpThreadEvent *m_creatingWakeEvent;
void *m_context;
};
static int SDLCALL FiberStartRoutine(void *lpThreadParameter)
{
const FiberStartState *tss = static_cast<const FiberStartState*>(lpThreadParameter);
GpFiberStarter::ThreadFunc_t threadFunc = tss->m_threadFunc;
IGpThreadEvent *creatingReturnEvent = tss->m_creatingReturnEvent;
IGpThreadEvent *wakeEvent = tss->m_creatingWakeEvent;
void *context = tss->m_context;
creatingReturnEvent->Signal();
wakeEvent->Wait();
threadFunc(context);
return 0;
}
}
IGpFiber *GpFiberStarter::StartFiber(IGpSystemServices *systemServices, ThreadFunc_t threadFunc, void *context, IGpFiber *creatingFiber)
{
IGpThreadEvent *returnEvent = systemServices->CreateThreadEvent(true, false);
if (!returnEvent)
return nullptr;
IGpThreadEvent *wakeEvent = systemServices->CreateThreadEvent(true, false);
if (!wakeEvent)
{
returnEvent->Destroy();
return nullptr;
}
GpFiberStarter_SDL::FiberStartState startState;
startState.m_context = context;
startState.m_creatingReturnEvent = returnEvent;
startState.m_creatingWakeEvent = wakeEvent;
startState.m_threadFunc = threadFunc;
SDL_Thread *thread = SDL_CreateThread(GpFiberStarter_SDL::FiberStartRoutine, "Fiber", &startState);
if (!thread)
{
returnEvent->Destroy();
wakeEvent->Destroy();
return nullptr;
}
returnEvent->Wait();
returnEvent->Destroy();
return new GpFiber_SDL(thread, wakeEvent);
}

View File

@@ -1,29 +0,0 @@
#include "GpFiber_SDL.h"
#include "IGpThreadEvent.h"
GpFiber_SDL::GpFiber_SDL(SDL_Thread *thread, IGpThreadEvent *threadEvent)
: m_event(threadEvent)
, m_thread(thread)
{
}
GpFiber_SDL::~GpFiber_SDL()
{
m_event->Destroy();
}
void GpFiber_SDL::YieldTo(IGpFiber *toFiber)
{
static_cast<GpFiber_SDL*>(toFiber)->m_event->Signal();
m_event->Wait();
}
void GpFiber_SDL::YieldToTerminal(IGpFiber *toFiber)
{
static_cast<GpFiber_SDL*>(toFiber)->m_event->Signal();
}
void GpFiber_SDL::Destroy()
{
delete this;
}

View File

@@ -1,24 +0,0 @@
#pragma once
#include "IGpFiber.h"
#include "SDL_thread.h"
struct IGpThreadEvent;
class GpFiber_SDL final : public IGpFiber
{
public:
explicit GpFiber_SDL(SDL_Thread *thread, IGpThreadEvent *threadEvent);
~GpFiber_SDL();
void YieldTo(IGpFiber *fromFiber) override;
void YieldToTerminal(IGpFiber *fromFiber) override;
void Destroy() override;
private:
static int SDLCALL InternalThreadFunction(void *data);
bool m_isDestroying;
IGpThreadEvent *m_event;
SDL_Thread *m_thread;
};

View File

@@ -1,6 +1,5 @@
#include "GpInputDriver_SDL_Gamepad.h"
#include "GpVOSEvent.h"
#include "GpWindows.h"
#include "IGpVOSEventQueue.h"
#include "SDL_events.h"
@@ -198,7 +197,7 @@ void GpInputDriverSDLGamepad::ProcessSDLEvent(const SDL_Event &msg)
IGpVOSEventQueue *evtQueue = m_properties.m_eventQueue;
switch (msg.type)
{
{
case SDL_CONTROLLERAXISMOTION:
{
const SDL_ControllerAxisEvent &axisMsg = msg.caxis;
@@ -232,8 +231,8 @@ void GpInputDriverSDLGamepad::ProcessSDLEvent(const SDL_Event &msg)
m_pendingEvents.push_back(evt);
}
break;
case SDL_CONTROLLERBUTTONDOWN:
break;
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
{
const bool isDown = (msg.type == SDL_CONTROLLERBUTTONDOWN);
@@ -288,22 +287,22 @@ void GpInputDriverSDLGamepad::ProcessSDLEvent(const SDL_Event &msg)
m_pendingEvents.push_back(evt);
}
break;
break;
case SDL_CONTROLLERDEVICEADDED:
HandleDeviceAdded(msg.cdevice.which);
break;
break;
case SDL_CONTROLLERDEVICEREMOVED:
HandleDeviceRemoved(msg.cdevice.which);
break;
break;
case SDL_CONTROLLERDEVICEREMAPPED:
// Not really sure what to do here, just re-add it
HandleDeviceRemoved(msg.cdevice.which);
HandleDeviceAdded(msg.cdevice.which);
break;
}
break;
}
}
IGpInputDriver *GpDriver_CreateInputDriver_SDL2_Gamepad(const GpInputDriverProperties &properties)
{
return GpInputDriverSDLGamepad::Create(properties);
return GpInputDriverSDLGamepad::Create(properties);
}

View File

@@ -1,11 +1,10 @@
#include "SDL.h"
#include "GpMain.h"
#include "GpAllocator_C.h"
#include "GpAudioDriverFactory.h"
#include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h"
#include "GpFiber_Win32.h"
#include "GpFiber_SDL.h"
#include "GpFileSystem_Win32.h"
#include "GpLogDriver_Win32.h"
#include "GpFontHandlerFactory.h"
@@ -38,6 +37,12 @@ IGpInputDriver *GpDriver_CreateInputDriver_SDL2_Gamepad(const GpInputDriverPrope
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
IGpAllocator *alloc = GpAllocator_C::GetInstance();
GpFileSystem_Win32 *fs = GpFileSystem_Win32::CreateInstance(alloc);
if (!fs)
return -1;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0)
return -1;
@@ -58,9 +63,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
IGpLogDriver *logger = GpLogDriver_Win32::GetInstance();
GpDriverCollection *drivers = GpAppInterface_Get()->PL_GetDriverCollection();
drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_Win32::GetInstance());
drivers->SetDriver<GpDriverIDs::kFileSystem>(fs);
drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_Win32::GetInstance());
drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_Win32::GetInstance());
drivers->SetDriver<GpDriverIDs::kAlloc>(GpAllocator_C::GetInstance());
g_gpWindowsGlobals.m_hInstance = hInstance;
g_gpWindowsGlobals.m_hPrevInstance = hPrevInstance;
@@ -88,6 +94,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
g_gpGlobalConfig.m_osGlobals = &g_gpWindowsGlobals;
g_gpGlobalConfig.m_logger = logger;
g_gpGlobalConfig.m_systemServices = GpSystemServices_Win32::GetInstance();
g_gpGlobalConfig.m_allocator = alloc;
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2);
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL);
@@ -104,5 +111,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
LocalFree(cmdLineArgs);
fs->Destroy();
return returnCode;
}

5
AerofoilSDL/GpSDL.h Normal file
View File

@@ -0,0 +1,5 @@
#ifdef __CYGWIN__
#define GP_SDL_DIRECTORY_PREFIX "SDL2/"
#else
#define GP_SDL_DIRECTORY_PREFIX
#endif

View File

@@ -17,7 +17,7 @@
" vec4 resultColor = vec4(SamplePixel(texCoord.xy), 1.0);\n"\
" resultColor *= constants_Modulation;\n"\
"#ifdef ENABLE_FLICKER\n"\
" resultColor = ApplyFlicker(constants_FlickerAxis, texCoord.zw, constants_FlickerStartThreshold, constants_FlickerEndThreshold, resultColor * constants_Modulation);\n"\
" resultColor = ApplyFlicker(constants_FlickerAxis, texCoord.zw, constants_FlickerStartThreshold, constants_FlickerEndThreshold, resultColor);\n"\
" if (resultColor.a < 1.0)\n"\
" discard;\n"\
"#endif\n"\

View File

@@ -18,7 +18,7 @@
" vec4 resultColor = vec4(SamplePixel(texCoord.xy), 1.0);\n"\
" resultColor *= constants_Modulation;\n"\
"#ifdef ENABLE_FLICKER\n"\
" resultColor = ApplyFlicker(constants_FlickerAxis, texCoord.zw, constants_FlickerStartThreshold, constants_FlickerEndThreshold, resultColor * constants_Modulation);\n"\
" resultColor = ApplyFlicker(constants_FlickerAxis, texCoord.zw, constants_FlickerStartThreshold, constants_FlickerEndThreshold, resultColor);\n"\
" if (resultColor.a < 1.0)\n"\
" discard;\n"\
"#endif\n"\

View File

@@ -58,7 +58,7 @@
"vec4 ApplyDesaturation(float desaturation, vec4 color)\n"\
"{\n"\
" // This is intentionally done in gamma space\n"\
" if (desaturation == 0.0)\n"\
" if (desaturation == 0.0 || (color.r == 1.0 && color.g == 1.0 && color.b == 0.0))\n"\
" return color;\n"\
"\n"\
" float grayLevel = dot(color.rgb, vec3(3.0, 6.0, 1.0) / 10.0);\n"\

3
AerofoilWeb/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
obj
res
bin

View File

@@ -0,0 +1,4 @@
#include "GpFileSystem_Web.cpp"
#include "GpLogDriver_Web.cpp"
#include "GpMain_SDL_Web.cpp"
#include "GpSystemServices_Web.cpp"

View File

@@ -0,0 +1,15 @@
#include <stdint.h>
#include "GpFileSystem_Web_Resources.h"
namespace GpFileSystem_Web_Resources
{
namespace ApplicationData
{
#include "res/ApplicationData.h"
}
namespace GameData
{
#include "res/GameData.h"
}
}

View File

@@ -0,0 +1,11 @@
set INPUT_DIR=../AerofoilPortable
set OUTPUT_DIR=obj
rem set DEBUG_LEVEL_FLAGS=-g4 -O0
set DEBUG_LEVEL_FLAGS=-O3
set FLAGS=-s USE_SDL=2 -flto -I../GpCommon/ -I../Common/ -s ASYNCIFY %DEBUG_LEVEL_FLAGS% -DGP_DEBUG_CONFIG=0
emcc -c %INPUT_DIR%/GpAllocator_C.cpp -o %OUTPUT_DIR%/AerofoilPortable_Combined.o %FLAGS%
pause

View File

@@ -0,0 +1,7 @@
set INPUT_DIR=../AerofoilSDL
set OUTPUT_DIR=obj
set FLAGS=-s USE_SDL=2 -flto -I../GpCommon/ -I../PortabilityLayer/ -I../Common/ -s ASYNCIFY -O3 -DGP_DEBUG_CONFIG=0
emcc -c %INPUT_DIR%/AerofoilSDL_Combined.cpp -o %OUTPUT_DIR%/AerofoilSDL_Combined.o %FLAGS%
pause

View File

@@ -0,0 +1,11 @@
set INPUT_DIR=.
set OUTPUT_DIR=obj
rem set DEBUG_LEVEL_FLAGS=-g4 -O0
set DEBUG_LEVEL_FLAGS=-O3
set FLAGS=-s USE_SDL=2 -flto -I../GpCommon/ -I../PortabilityLayer/ -I../Common/ -I../AerofoilPortable/ -I../GpShell/ -s ASYNCIFY %DEBUG_LEVEL_FLAGS% -DGP_DEBUG_CONFIG=0
emcc -c %INPUT_DIR%/AerofoilWeb_Combined.cpp -o %OUTPUT_DIR%/AerofoilWeb_Combined.o %FLAGS%
pause

View File

@@ -0,0 +1,7 @@
set INPUT_DIR=../GpApp
set OUTPUT_DIR=obj
set FLAGS=-s USE_SDL=2 -flto -I../GpCommon/ -I../PortabilityLayer/ -I../Common/ -s ASYNCIFY -O3 -DGP_DEBUG_CONFIG=0
emcc -c %INPUT_DIR%/GpApp_Combined.cpp -o %OUTPUT_DIR%/GpApp_Combined.o %FLAGS%
pause

View File

@@ -0,0 +1,7 @@
set INPUT_DIR=../GpShell
set OUTPUT_DIR=obj
set FLAGS=-s USE_SDL=2 -flto -I../GpCommon/ -I../PortabilityLayer/ -I../Common/ -s ASYNCIFY -O3 -DGP_DEBUG_CONFIG=0
emcc -c %INPUT_DIR%/GpShell_Combined.cpp -o %OUTPUT_DIR%/GpShell_Combined.o %FLAGS%
pause

View File

@@ -0,0 +1,7 @@
set INPUT_DIR=../MacRomanConversion
set OUTPUT_DIR=obj
set FLAGS=-flto -I../MacRomanConversion/ -s ASYNCIFY -O3
emcc -c %INPUT_DIR%/MacRomanConversion.cpp -o %OUTPUT_DIR%/MacRomanConversion.o %FLAGS%
pause

View File

@@ -0,0 +1,7 @@
set INPUT_DIR=../PortabilityLayer
set OUTPUT_DIR=obj
set FLAGS=-s USE_ZLIB=1 -flto -I../GpCommon/ -I../Common/ -I../PortabilityLayer/ -I../rapidjson/include/ -I../MacRomanConversion/ -I../stb/ -s ASYNCIFY -O3 -DGP_DEBUG_CONFIG=0 -Wno-tautological-constant-out-of-range-compare
emcc -c %INPUT_DIR%/PortabilityLayer_Combined.cpp -o %OUTPUT_DIR%/PortabilityLayer_Combined.o %FLAGS%
pause

View File

@@ -0,0 +1,10 @@
..\x64\Release\bin2h.exe ..\Packaged res\ApplicationData.h
..\x64\Release\bin2h.exe ..\Packaged\Houses res\GameData.h
set INPUT_DIR=.
set OUTPUT_DIR=obj
set FLAGS=-flto -O3 -DGP_DEBUG_CONFIG=0
emcc -c %INPUT_DIR%/AerofoilWeb_Resources.cpp -o %OUTPUT_DIR%/AerofoilWeb_Resources.o %FLAGS%
pause

View File

@@ -0,0 +1,867 @@
#define _LARGEFILE64_SOURCE
#include "GpFileSystem_Web.h"
#include "GpIOStream.h"
#include "IGpDirectoryCursor.h"
#include "IGpSystemServices.h"
#include "IGpMutex.h"
#include "VirtualDirectory.h"
#include "PLDrivers.h"
#include "SDL2/SDL.h"
#include "SDL2/SDL_rwops.h"
#include <string>
#include <vector>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <dirent.h>
#include <emscripten.h>
#include "UTF8.h"
#if defined(__CYGWIN__) || defined(__EMSCRIPTEN__)
typedef off_t off64_t;
#define fstat64 fstat
#define fseek64 fseek
#define ftruncate64 ftruncate
#define stat64 stat
#endif
EM_JS(void, FlushFileSystem, (), {
Asyncify.handleSleep(wakeUp => {
FS.syncfs(false, function (err) {
assert(!err);
wakeUp();
});
});
});
EM_JS(void, DownloadAndDeleteFile, (const char *fileNamePtr, const char *prettyNamePtr), {
var fileName = UTF8ToString(fileNamePtr);
var prettyName = UTF8ToString(prettyNamePtr);
console.log("Flush download of file " + fileName + " as " + prettyName);
var mimeType = "application/octet-stream";
if (prettyName.endsWith(".bin"))
mimeType = "application/macbinary";
else if (prettyName.endsWith(".gpf"))
mimeType = "application/zip";
var byteArray = FS.readFile(fileName, { encoding: "binary" });
var blob = new Blob([byteArray], { type: mimeType });
saveAs(blob, prettyName);
});
class GpDirectoryCursor_Web final : public IGpDirectoryCursor
{
public:
explicit GpDirectoryCursor_Web(DIR *dir, const std::string &prefix);
~GpDirectoryCursor_Web();
bool GetNext(const char *&outFileName) override;
void Destroy() override;
private:
DIR *m_dir;
std::string m_prefix;
std::string m_decodedFileName;
};
GpDirectoryCursor_Web::GpDirectoryCursor_Web(DIR *dir, const std::string &prefix)
: m_dir(dir)
, m_prefix(prefix)
{
}
GpDirectoryCursor_Web::~GpDirectoryCursor_Web()
{
closedir(m_dir);
}
bool GpDirectoryCursor_Web::GetNext(const char *&outFileName)
{
const size_t prefixLength = m_prefix.size();
for (;;)
{
struct dirent *dir = readdir(m_dir);
if (!dir)
return false;
const char *fname = dir->d_name;
const size_t fnameLen = strlen(fname);
if (fnameLen > prefixLength && (prefixLength == 0 || !memcmp(&m_prefix[0], fname, prefixLength)))
{
const char *encodedResult = fname + prefixLength;
m_decodedFileName.clear();
for (size_t i = 0; encodedResult[i] != 0; i++)
{
char c = encodedResult[i];
if (c == '%')
{
char highNibble = encodedResult[i + 1];
if ((highNibble >= '0' && highNibble <= '9') || (highNibble >= 'a' && highNibble <= 'f') || (highNibble >= 'A' && highNibble <= 'F'))
{
char lowNibble = encodedResult[i + 2];
if ((lowNibble >= '0' && lowNibble <= '9') || (lowNibble >= 'a' && lowNibble <= 'f') || (lowNibble >= 'A' && lowNibble <= 'F'))
{
bool failedNibble = false;
char nibbles[2] = { highNibble, lowNibble };
int decNibbles[2];
for (int ni = 0; ni < 2; ni++)
{
char nc = nibbles[ni];
if (nc >= '0' && nc <= '9')
decNibbles[ni] = nc - '0';
else if (nc >= 'a' && nc <= 'f')
decNibbles[ni] = 0xa + (nc - 'a');
else if (nc >= 'A' && nc <= 'F')
decNibbles[ni] = 0xa + (nc - 'A');
else
failedNibble = true;
}
if (!failedNibble)
{
c = static_cast<char>((decNibbles[0] << 4) + decNibbles[1]);
i += 2;
}
}
}
}
m_decodedFileName += c;
}
outFileName = m_decodedFileName.c_str();
return true;
}
}
return true;
}
void GpDirectoryCursor_Web::Destroy()
{
delete this;
}
class GpFileStream_Web_StaticMemFile final : public GpIOStream
{
public:
GpFileStream_Web_StaticMemFile(const unsigned char *bytes, size_t size);
~GpFileStream_Web_StaticMemFile();
size_t Read(void *bytesOut, size_t size) override;
size_t Write(const void *bytes, size_t size) override;
bool IsSeekable() const override;
bool IsReadOnly() const override;
bool IsWriteOnly() const override;
bool SeekStart(GpUFilePos_t loc) override;
bool SeekCurrent(GpFilePos_t loc) override;
bool SeekEnd(GpUFilePos_t loc) override;
GpUFilePos_t Size() const override;
GpUFilePos_t Tell() const override;
void GP_ASYNCIFY_PARANOID_NAMED(Close)() override;
void Flush() override;
private:
const unsigned char *m_bytes;
size_t m_offset;
size_t m_size;
};
GpFileStream_Web_StaticMemFile::GpFileStream_Web_StaticMemFile(const unsigned char *bytes, size_t size)
: m_bytes(bytes)
, m_size(size)
, m_offset(0)
{
}
GpFileStream_Web_StaticMemFile::~GpFileStream_Web_StaticMemFile()
{
}
size_t GpFileStream_Web_StaticMemFile::Read(void *bytesOut, size_t size)
{
size_t available = m_size - m_offset;
size = std::min(size, available);
memcpy(bytesOut, m_bytes + m_offset, size);
m_offset += size;
return size;
}
size_t GpFileStream_Web_StaticMemFile::Write(const void *bytes, size_t size)
{
return 0;
}
bool GpFileStream_Web_StaticMemFile::IsSeekable() const
{
return true;
}
bool GpFileStream_Web_StaticMemFile::IsReadOnly() const
{
return true;
}
bool GpFileStream_Web_StaticMemFile::IsWriteOnly() const
{
return false;
}
bool GpFileStream_Web_StaticMemFile::SeekStart(GpUFilePos_t loc)
{
if (loc > m_size)
return false;
m_offset = static_cast<size_t>(loc);
return true;
}
bool GpFileStream_Web_StaticMemFile::SeekCurrent(GpFilePos_t loc)
{
GpFilePos_t minOffset = -static_cast<GpFilePos_t>(m_offset);
GpFilePos_t maxOffset = static_cast<GpFilePos_t>(m_size - m_offset);
if (loc < minOffset || loc > maxOffset)
return false;
m_offset = static_cast<size_t>(static_cast<GpFilePos_t>(m_offset) + loc);
return true;
}
bool GpFileStream_Web_StaticMemFile::SeekEnd(GpUFilePos_t loc)
{
if (loc > m_size)
return false;
m_offset = m_size - loc;
return true;
}
GpUFilePos_t GpFileStream_Web_StaticMemFile::Size() const
{
return m_size;
}
GpUFilePos_t GpFileStream_Web_StaticMemFile::Tell() const
{
return m_offset;
}
void GpFileStream_Web_StaticMemFile::GP_ASYNCIFY_PARANOID_NAMED(Close)()
{
delete this;
}
void GpFileStream_Web_StaticMemFile::Flush()
{
}
class GpFileStream_Web_File final : public GpIOStream
{
public:
GpFileStream_Web_File(FILE *f, const std::string &filePath, const std::string &prettyName, bool readOnly, bool writeOnly, bool synchronizeOnClose, bool isIDB);
~GpFileStream_Web_File();
size_t Read(void *bytesOut, size_t size) override;
size_t Write(const void *bytes, size_t size) override;
bool IsSeekable() const override;
bool IsReadOnly() const override;
bool IsWriteOnly() const override;
bool SeekStart(GpUFilePos_t loc) override;
bool SeekCurrent(GpFilePos_t loc) override;
bool SeekEnd(GpUFilePos_t loc) override;
GpUFilePos_t Size() const override;
GpUFilePos_t Tell() const override;
void GP_ASYNCIFY_PARANOID_NAMED(Close)() override;
void Flush() override;
private:
FILE *m_f;
std::string m_filePath;
std::string m_prettyName;
bool m_seekable;
bool m_isReadOnly;
bool m_isWriteOnly;
bool m_synchronizeOnClose;
bool m_isIDB;
};
GpFileStream_Web_File::GpFileStream_Web_File(FILE *f, const std::string &filePath, const std::string &prettyName, bool readOnly, bool writeOnly, bool synchronizeOnClose, bool isIDB)
: m_f(f)
, m_isReadOnly(readOnly)
, m_isWriteOnly(writeOnly)
, m_synchronizeOnClose(synchronizeOnClose)
, m_isIDB(isIDB)
, m_filePath(filePath)
, m_prettyName(prettyName)
{
m_seekable = (fseek(m_f, 0, SEEK_CUR) == 0);
}
GpFileStream_Web_File::~GpFileStream_Web_File()
{
fclose(m_f);
if (m_synchronizeOnClose)
{
if (m_isIDB)
GpFileSystem_Web::MarkFSStateDirty();
else
GpFileSystem_Web::SyncDownloadFile(m_filePath, m_prettyName);
}
}
size_t GpFileStream_Web_File::Read(void *bytesOut, size_t size)
{
if (m_isWriteOnly)
return 0;
return fread(bytesOut, 1, size, m_f);
}
size_t GpFileStream_Web_File::Write(const void *bytes, size_t size)
{
if (m_isReadOnly)
return 0;
return fwrite(bytes, 1, size, m_f);
}
bool GpFileStream_Web_File::IsSeekable() const
{
return m_seekable;
}
bool GpFileStream_Web_File::IsReadOnly() const
{
return m_isReadOnly;
}
bool GpFileStream_Web_File::IsWriteOnly() const
{
return m_isWriteOnly;
}
bool GpFileStream_Web_File::SeekStart(GpUFilePos_t loc)
{
if (!m_seekable)
return false;
fflush(m_f);
return fseek64(m_f, static_cast<off64_t>(loc), SEEK_SET) >= 0;
}
bool GpFileStream_Web_File::SeekCurrent(GpFilePos_t loc)
{
if (!m_seekable)
return false;
fflush(m_f);
return fseek64(m_f, static_cast<off64_t>(loc), SEEK_CUR) >= 0;
}
bool GpFileStream_Web_File::SeekEnd(GpUFilePos_t loc)
{
if (!m_seekable)
return false;
fflush(m_f);
return fseek64(m_f, -static_cast<off64_t>(loc), SEEK_END) >= 0;
}
GpUFilePos_t GpFileStream_Web_File::Size() const
{
fflush(m_f);
struct stat64 s;
if (fstat64(fileno(m_f), &s) < 0)
return 0;
return static_cast<GpUFilePos_t>(s.st_size);
}
GpUFilePos_t GpFileStream_Web_File::Tell() const
{
return static_cast<GpUFilePos_t>(ftell(m_f));
}
void GpFileStream_Web_File::GP_ASYNCIFY_PARANOID_NAMED(Close)()
{
this->~GpFileStream_Web_File();
free(this);
}
void GpFileStream_Web_File::Flush()
{
fflush(m_f);
}
bool GpFileSystem_Web::ms_fsStateDirty;
bool GpFileSystem_Web::ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths, bool trailingSlash, std::string &resolution, bool &outIsIDB)
{
const char *pathAppend = nullptr;
const std::string *rootPath = nullptr;
std::string unsanitized;
bool isIDB = false;
switch (virtualDirectory)
{
case PortabilityLayer::VirtualDirectories::kApplicationData:
unsanitized = std::string("Packaged");
break;
case PortabilityLayer::VirtualDirectories::kGameData:
unsanitized = std::string("Packaged/Houses");
break;
case PortabilityLayer::VirtualDirectories::kFonts:
unsanitized = std::string("Resources");
break;
case PortabilityLayer::VirtualDirectories::kHighScores:
pathAppend = "HighScores";
rootPath = &m_prefsPath;
isIDB = true;
break;
case PortabilityLayer::VirtualDirectories::kUserData:
pathAppend = "Houses";
rootPath = &m_prefsPath;
isIDB = true;
break;
case PortabilityLayer::VirtualDirectories::kUserSaves:
pathAppend = "SavedGames";
rootPath = &m_prefsPath;
isIDB = true;
break;
case PortabilityLayer::VirtualDirectories::kPrefs:
pathAppend = "Prefs";
rootPath = &m_prefsPath;
isIDB = true;
break;
case PortabilityLayer::VirtualDirectories::kSourceExport:
pathAppend = "Export";
rootPath = &m_exportPath;
isIDB = false;
break;
default:
return false;
};
if (pathAppend)
{
unsanitized = pathAppend;
for (size_t i = 0; i < numPaths; i++)
{
unsanitized += "/";
unsanitized += paths[i];
}
if (trailingSlash)
unsanitized += "/";
std::string sanitized;
for (size_t i = 0; i < unsanitized.size(); i++)
{
char c = unsanitized[i];
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_')
sanitized += c;
else
{
const char *nibbles = "0123456789abcdef";
char subPath[4];
subPath[0] = '%';
subPath[1] = nibbles[(c >> 4) & 0xf];
subPath[2] = nibbles[c & 0xf];
subPath[3] = 0;
sanitized += subPath;
}
}
resolution = (*rootPath) + "/" + sanitized;
}
else
{
std::string sanitized = m_basePath + unsanitized;
for (size_t i = 0; i < numPaths; i++)
{
sanitized += "/";
sanitized += paths[i];
}
resolution = sanitized;
}
outIsIDB = isIDB;
return true;
}
GpFileSystem_Web::GpFileSystem_Web()
: m_delayCallback(nullptr)
{
}
GpFileSystem_Web::~GpFileSystem_Web()
{
}
void GpFileSystem_Web::Init()
{
m_prefsPath = "/aerofoil";
m_exportPath = "/aerofoil_memfs";
char *baseDir = SDL_GetBasePath();
m_basePath = baseDir;
SDL_free(baseDir);
char baseDirSeparator = m_basePath[m_basePath.size() - 1];
if (m_basePath.size() >= 4 && m_basePath.substr(m_basePath.size() - 4, 3) == "bin")
m_basePath = m_basePath.substr(0, m_basePath.size() - 4) + "lib" + baseDirSeparator + "aerofoil" + baseDirSeparator;
}
bool GpFileSystem_Web::FileExists(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path)
{
if (const GpFileSystem_Web_Resources::FileCatalog *catalog = GetCatalogForVirtualDirectory(virtualDirectory))
{
for (size_t i = 0; i < catalog->m_numEntries; i++)
{
const GpFileSystem_Web_Resources::FileCatalogEntry &entry = catalog->m_entries[i];
if (!strcmp(path, entry.m_fileName))
return true;
}
return false;
}
std::string resolvedPath;
bool isIDB = false;
if (!ResolvePath(virtualDirectory, &path, 1, false, resolvedPath, isIDB))
return false;
struct stat s;
return stat(resolvedPath.c_str(), &s) == 0;
}
bool GpFileSystem_Web::FileLocked(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &exists)
{
if (const GpFileSystem_Web_Resources::FileCatalog *catalog = GetCatalogForVirtualDirectory(virtualDirectory))
{
for (size_t i = 0; i < catalog->m_numEntries; i++)
{
const GpFileSystem_Web_Resources::FileCatalogEntry &entry = catalog->m_entries[i];
if (!strcmp(path, entry.m_fileName))
{
exists = true;
return true;
}
}
exists = false;
return false;
}
std::string resolvedPath;
bool isIDB = false;
if (!ResolvePath(virtualDirectory, &path, 1, false, resolvedPath, isIDB))
{
if (exists)
exists = false;
return false;
}
int permissions = access(resolvedPath.c_str(), W_OK | F_OK);
exists = ((permissions & F_OK) != 0);
return ((permissions & W_OK) != 0);
}
GpIOStream *GpFileSystem_Web::OpenFileNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* subPaths, size_t numSubPaths, bool writeAccess, GpFileCreationDisposition_t createDisposition)
{
if (numSubPaths == 1)
{
if (const GpFileSystem_Web_Resources::FileCatalog *catalog = GetCatalogForVirtualDirectory(virtualDirectory))
{
for (size_t i = 0; i < catalog->m_numEntries; i++)
{
const GpFileSystem_Web_Resources::FileCatalogEntry &entry = catalog->m_entries[i];
if (!strcmp(subPaths[0], entry.m_fileName))
return new GpFileStream_Web_StaticMemFile(entry.m_data, entry.m_size);
}
return nullptr;
}
}
const char *mode = nullptr;
bool canWrite = false;
bool needResetPosition = false;
switch (createDisposition)
{
case GpFileCreationDispositions::kCreateOrOverwrite:
mode = "wb";
break;
case GpFileCreationDispositions::kCreateNew:
mode = "x+b";
break;
case GpFileCreationDispositions::kCreateOrOpen:
mode = "a+b";
needResetPosition = true;
break;
case GpFileCreationDispositions::kOpenExisting:
mode = writeAccess ? "r+b" : "rb";
break;
case GpFileCreationDispositions::kOverwriteExisting:
mode = "r+b";
break;
default:
return nullptr;
};
std::string resolvedPath;
bool isIDB = false;
if (!ResolvePath(virtualDirectory, subPaths, numSubPaths, false, resolvedPath, isIDB))
return nullptr;
void *objStorage = malloc(sizeof(GpFileStream_Web_File));
if (!objStorage)
return nullptr;
FILE *f = fopen(resolvedPath.c_str(), mode);
if (!f)
{
free(objStorage);
return nullptr;
}
if (needResetPosition)
fseek(f, 0, SEEK_SET);
if (createDisposition == GpFileCreationDispositions::kOverwriteExisting)
{
if (ftruncate64(fileno(f), 0) < 0)
{
free(objStorage);
fclose(f);
return nullptr;
}
}
std::string prettyName;
if (numSubPaths > 0)
prettyName = subPaths[numSubPaths - 1];
return new (objStorage) GpFileStream_Web_File(f, resolvedPath, prettyName, !writeAccess, false, writeAccess, isIDB);
}
bool GpFileSystem_Web::DeleteFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &existed)
{
if (const GpFileSystem_Web_Resources::FileCatalog *catalog = GetCatalogForVirtualDirectory(virtualDirectory))
return false;
std::string resolvedPath;
bool isIDB = false;
if (!ResolvePath(virtualDirectory, &path, 1, false, resolvedPath, isIDB))
{
existed = false;
return false;
}
if (unlink(resolvedPath.c_str()) < 0)
{
existed = (errno != ENOENT);
return false;
}
if (isIDB)
MarkFSStateDirty();
existed = true;
return true;
}
bool GpFileSystem_Web::ValidateFilePath(const char *path, size_t length) const
{
for (size_t i = 0; i < length; i++)
{
const char c = path[i];
if (c >= '0' && c <= '9')
continue;
if (c == '_' || c == '.' || c == '\'' || c == '!')
continue;
if (c == ' ' && i != 0 && i != length - 1)
continue;
if (c >= 'a' && c <= 'z')
continue;
if (c >= 'A' && c <= 'Z')
continue;
return false;
}
return true;
}
bool GpFileSystem_Web::ValidateFilePathUnicodeChar(uint32_t c) const
{
if (c >= '0' && c <= '9')
return true;
if (c == '_' || c == '\'')
return true;
if (c == ' ')
return true;
if (c >= 'a' && c <= 'z')
return true;
if (c >= 'A' && c <= 'Z')
return true;
return false;
}
void GpFileSystem_Web::SetDelayCallback(DelayCallback_t delayCallback)
{
m_delayCallback = delayCallback;
}
GpFileSystem_Web *GpFileSystem_Web::GetInstance()
{
return &ms_instance;
}
class GpDirectoryCursor_StringList final : public IGpDirectoryCursor
{
public:
explicit GpDirectoryCursor_StringList(std::vector<std::string> &paths);
~GpDirectoryCursor_StringList();
bool GetNext(const char *&outFileName) override;
void Destroy() override;
private:
std::vector<std::string> m_paths;
size_t m_index;
};
GpDirectoryCursor_StringList::GpDirectoryCursor_StringList(std::vector<std::string> &paths)
: m_index(0)
{
std::swap(paths, m_paths);
}
GpDirectoryCursor_StringList::~GpDirectoryCursor_StringList()
{
}
bool GpDirectoryCursor_StringList::GetNext(const char *&outFileName)
{
if (m_index == m_paths.size())
return false;
outFileName = m_paths[m_index].c_str();
m_index++;
return true;
}
void GpDirectoryCursor_StringList::Destroy()
{
delete this;
}
IGpDirectoryCursor *GpFileSystem_Web::ScanDirectoryNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths)
{
if (const GpFileSystem_Web_Resources::FileCatalog *catalog = GetCatalogForVirtualDirectory(virtualDirectory))
return ScanCatalog(*catalog);
std::string resolvedPrefix;
bool isIDB = false;
if (!ResolvePath(virtualDirectory, paths, numPaths, true, resolvedPrefix, isIDB))
return nullptr;
std::string trimmedPrefix = resolvedPrefix.substr(m_prefsPath.size() + 1);
DIR *d = opendir(m_prefsPath.c_str());
if (!d)
return nullptr;
return new GpDirectoryCursor_Web(d, trimmedPrefix);
}
const GpFileSystem_Web_Resources::FileCatalog *GpFileSystem_Web::GetCatalogForVirtualDirectory(PortabilityLayer::VirtualDirectory_t virtualDirectory)
{
if (virtualDirectory == PortabilityLayer::VirtualDirectories::kApplicationData)
return &GpFileSystem_Web_Resources::ApplicationData::GetCatalog();
if (virtualDirectory == PortabilityLayer::VirtualDirectories::kGameData)
return &GpFileSystem_Web_Resources::GameData::GetCatalog();
return nullptr;
}
IGpDirectoryCursor *GpFileSystem_Web::ScanCatalog(const GpFileSystem_Web_Resources::FileCatalog &catalog)
{
std::vector<std::string> paths;
for (size_t i = 0; i < catalog.m_numEntries; i++)
paths.push_back(std::string(catalog.m_entries[i].m_fileName));
return new GpDirectoryCursor_StringList(paths);
}
void GpFileSystem_Web::MarkFSStateDirty()
{
ms_fsStateDirty = true;
}
void GpFileSystem_Web::SyncDownloadFile(const std::string &filePath, const std::string &prettyName)
{
DownloadAndDeleteFile(filePath.c_str(), prettyName.c_str());
}
void GpFileSystem_Web::FlushFS()
{
if (ms_fsStateDirty)
{
ms_fsStateDirty = false;
FlushFileSystem();
}
}
#if GP_ASYNCIFY_PARANOID
void GpIOStream::Close()
{
this->GP_ASYNCIFY_PARANOID_NAMED(Close)();
GpFileSystem_Web::FlushFS();
}
bool IGpFileSystem::DeleteFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &existed)
{
bool deleted = static_cast<GpFileSystem_Web*>(this)->DeleteFile(virtualDirectory, path, existed);
if (deleted)
GpFileSystem_Web::FlushFS();
return deleted;
}
#endif
GpFileSystem_Web GpFileSystem_Web::ms_instance;

View File

@@ -0,0 +1,68 @@
#pragma once
#include "IGpFileSystem.h"
#include "GpFileSystem_Web_Resources.h"
#include "GpCoreDefs.h"
#include <string>
#include <stdio.h>
struct IGpMutex;
class GpFileSystem_Web final : public IGpFileSystem
{
public:
GpFileSystem_Web();
~GpFileSystem_Web();
void Init();
bool FileExists(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path) override;
bool FileLocked(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &exists) override;
GpIOStream *OpenFileNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* subPaths, size_t numSubPaths, bool writeAccess, GpFileCreationDisposition_t createDisposition) override;
bool DeleteFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &existed) GP_ASYNCIFY_PARANOID_OVERRIDE;
IGpDirectoryCursor *ScanDirectoryNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths) override;
bool ValidateFilePath(const char *path, size_t pathLen) const override;
bool ValidateFilePathUnicodeChar(uint32_t ch) const override;
void SetDelayCallback(DelayCallback_t delayCallback) override;
static void MarkFSStateDirty();
static void SyncDownloadFile(const std::string &filePath, const std::string &prettyName);
static void FlushFS();
static GpFileSystem_Web *GetInstance();
private:
struct ScanDirectoryNestedContext
{
GpFileSystem_Web *m_this;
IGpDirectoryCursor *m_returnValue;
PortabilityLayer::VirtualDirectory_t m_virtualDirectory;
char const *const *m_paths;
size_t m_numPaths;
};
static void ScanDirectoryNestedThunk(void *context);
IGpDirectoryCursor *ScanDirectoryNestedInternal(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths);
IGpDirectoryCursor *ScanDirectory(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths);
static const GpFileSystem_Web_Resources::FileCatalog *GetCatalogForVirtualDirectory(PortabilityLayer::VirtualDirectory_t virtualDirectory);
static IGpDirectoryCursor *ScanCatalog(const GpFileSystem_Web_Resources::FileCatalog &catalog);
bool ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths, bool trailingSlash, std::string &resolution, bool &outIsIDB);
DelayCallback_t m_delayCallback;
std::string m_prefsPath;
std::string m_basePath;
std::string m_exportPath;
static bool ms_fsStateDirty;
static GpFileSystem_Web ms_instance;
};

View File

@@ -0,0 +1,28 @@
#pragma once
namespace GpFileSystem_Web_Resources
{
struct FileCatalogEntry
{
const char *m_fileName;
const unsigned char *m_data;
const unsigned int m_size;
};
struct FileCatalog
{
const FileCatalogEntry *m_entries;
const unsigned int m_numEntries;
const unsigned int m_size;
const unsigned int m_size0;
};
namespace ApplicationData
{
const FileCatalog &GetCatalog();
}
namespace GameData
{
const FileCatalog &GetCatalog();
}
}

View File

@@ -0,0 +1,89 @@
#include "GpLogDriver_Web.h"
#include "GpFileSystem_Web.h"
#include "GpApplicationName.h"
#include "GpIOStream.h"
#include <time.h>
#include <cstring>
GpLogDriver_Web::GpLogDriver_Web()
{
}
void GpLogDriver_Web::Init()
{
ms_instance.InitInternal();
}
void GpLogDriver_Web::VPrintf(Category category, const char *fmt, va_list args)
{
size_t fmtSize = 0;
bool hasFormatting = false;
for (const char *fmtCheck = fmt; *fmtCheck; fmtCheck++)
{
if (*fmtCheck == '%')
hasFormatting = true;
fmtSize++;
}
time_t t = time(nullptr);
struct tm sysTime = *localtime(&t);
char timestampBuffer[64];
sprintf(timestampBuffer, "[%02d:%02d:%02d] ", sysTime.tm_hour, sysTime.tm_min, sysTime.tm_sec);
const char *debugTag = "";
switch (category)
{
case Category_Warning:
debugTag = "[WARNING] ";
break;
case Category_Error:
debugTag = "[ERROR] ";
break;
default:
break;
};
int formattedSize = vsnprintf(nullptr, 0, fmt, args);
if (formattedSize <= 0)
return;
char *charBuff = static_cast<char*>(malloc(formattedSize + 1));
if (!charBuff)
return;
vsnprintf(charBuff, formattedSize + 1, fmt, args);
fprintf(stdout, "%s%s%s\n", timestampBuffer, debugTag, charBuff);
fflush(stdout);
free(charBuff);
}
void GpLogDriver_Web::Shutdown()
{
}
GpLogDriver_Web *GpLogDriver_Web::GetInstance()
{
return &ms_instance;
}
void GpLogDriver_Web::InitInternal()
{
time_t t = time(nullptr);
struct tm utcTime = *gmtime(&t);
this->Printf(IGpLogDriver::Category_Information, GP_APPLICATION_NAME " build " __TIMESTAMP__);
#if !GP_DEBUG_CONFIG
this->Printf(IGpLogDriver::Category_Information, "Configuration: Release");
#else
this->Printf(IGpLogDriver::Category_Information, "Configuration: Debug");
#endif
}
GpLogDriver_Web GpLogDriver_Web::ms_instance;

View File

@@ -0,0 +1,25 @@
#pragma once
#include "IGpLogDriver.h"
#include <stdio.h>
class GpIOStream;
class GpLogDriver_Web : public IGpLogDriver
{
public:
GpLogDriver_Web();
static void Init();
void VPrintf(Category category, const char *fmt, va_list args) override;
void Shutdown() override;
static GpLogDriver_Web *GetInstance();
private:
void InitInternal();
static GpLogDriver_Web ms_instance;
};

View File

@@ -0,0 +1,109 @@
#include <SDL.h>
#include "SDL_main.h"
#include "GpMain.h"
#include "GpAllocator_C.h"
#include "GpAudioDriverFactory.h"
#include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h"
#include "GpFileSystem_Web.h"
#include "GpLogDriver_Web.h"
#include "GpFontHandlerFactory.h"
#include "GpInputDriverFactory.h"
#include "GpAppInterface.h"
#include "GpSystemServices_Web.h"
#include "GpVOSEvent.h"
#include "GpX.h"
#include "IGpFileSystem.h"
#include "IGpThreadEvent.h"
#include "IGpVOSEventQueue.h"
#include <string>
#include <emscripten.h>
GpXGlobals g_gpXGlobals;
IGpDisplayDriver *GpDriver_CreateDisplayDriver_SDL_GL2(const GpDisplayDriverProperties &properties);
IGpAudioDriver *GpDriver_CreateAudioDriver_SDL(const GpAudioDriverProperties &properties);
IGpInputDriver *GpDriver_CreateInputDriver_SDL2_Gamepad(const GpInputDriverProperties &properties);
EM_JS(void, InitFileSystem, (), {
Asyncify.handleSleep(wakeUp => {
FS.mkdir('/aerofoil');
FS.mkdir('/aerofoil_memfs');
FS.mount(IDBFS, {}, '/aerofoil');
FS.mount(MEMFS, {}, '/aerofoil_memfs');
FS.syncfs(true, function (err) {
assert(!err);
wakeUp();
});
});
});
int main(int argc, char* argv[])
{
IGpAllocator *alloc = GpAllocator_C::GetInstance();
InitFileSystem();
GpLogDriver_Web::Init();
IGpLogDriver *logger = GpLogDriver_Web::GetInstance();
#if GP_ASYNCIFY_PARANOID
SDL_SetHint(SDL_HINT_EMSCRIPTEN_ASYNCIFY, "0");
#endif
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0)
return -1;
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Starting filesystem...");
GpFileSystem_Web::GetInstance()->Init();
GpDriverCollection *drivers = GpAppInterface_Get()->PL_GetDriverCollection();
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "Setting up drivers...");
drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_Web::GetInstance());
drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_Web::GetInstance());
drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_Web::GetInstance());
drivers->SetDriver<GpDriverIDs::kAlloc>(alloc);
g_gpGlobalConfig.m_displayDriverType = EGpDisplayDriverType_SDL_GL2;
g_gpGlobalConfig.m_audioDriverType = EGpAudioDriverType_SDL2;
g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_None;
EGpInputDriverType inputDrivers[] =
{
EGpInputDriverType_SDL2_Gamepad
};
g_gpGlobalConfig.m_inputDriverTypes = inputDrivers;
g_gpGlobalConfig.m_numInputDrivers = sizeof(inputDrivers) / sizeof(inputDrivers[0]);
g_gpGlobalConfig.m_osGlobals = &g_gpXGlobals;
g_gpGlobalConfig.m_logger = logger;
g_gpGlobalConfig.m_systemServices = GpSystemServices_Web::GetInstance();
g_gpGlobalConfig.m_allocator = alloc;
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2);
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL);
GpInputDriverFactory::RegisterInputDriverFactory(EGpInputDriverType_SDL2_Gamepad, GpDriver_CreateInputDriver_SDL2_Gamepad);
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "SDL environment configured, starting up");
int returnCode = GpMain::Run();
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "SDL environment exited with code %i, cleaning up", returnCode);
SDL_Quit();
return returnCode;
}

View File

@@ -0,0 +1,225 @@
#include "GpSystemServices_Web.h"
#include "IGpClipboardContents.h"
#include "IGpThreadEvent.h"
#include "SDL2/SDL.h"
#include <time.h>
#include <unistd.h>
#include <string>
class GpMutex_Web_Null final : public IGpMutex
{
public:
void Destroy() override;
void Lock() override;
void Unlock() override;
static IGpMutex *GetInstance();
private:
static GpMutex_Web_Null ms_instance;
};
void GpMutex_Web_Null::Destroy()
{
}
void GpMutex_Web_Null::Lock()
{
}
void GpMutex_Web_Null::Unlock()
{
}
IGpMutex *GpMutex_Web_Null::GetInstance()
{
return &ms_instance;
}
GpMutex_Web_Null GpMutex_Web_Null::ms_instance;
class GpThreadEvent_Web_Null final : public IGpThreadEvent
{
public:
void Wait() override;
bool WaitTimed(uint32_t msec) override;
void Signal() override;
void Destroy() override;
static IGpThreadEvent *GetInstance();
private:
static GpThreadEvent_Web_Null ms_instance;
};
GpThreadEvent_Web_Null GpThreadEvent_Web_Null::ms_instance;
void GpThreadEvent_Web_Null::Wait()
{
}
bool GpThreadEvent_Web_Null::WaitTimed(uint32_t msec)
{
return true;
}
void GpThreadEvent_Web_Null::Signal()
{
}
void GpThreadEvent_Web_Null::Destroy()
{
}
IGpThreadEvent *GpThreadEvent_Web_Null::GetInstance()
{
return &ms_instance;
}
GpSystemServices_Web::GpSystemServices_Web()
: m_textInputEnabled(false)
, m_clipboardContents(nullptr)
{
}
int64_t GpSystemServices_Web::GetTime() const
{
time_t t = time(nullptr);
return static_cast<int64_t>(t) - 2082844800;
}
void GpSystemServices_Web::GetLocalDateTime(unsigned int &year, unsigned int &month, unsigned int &day, unsigned int &hour, unsigned int &minute, unsigned int &second) const
{
time_t t = time(nullptr);
tm *tmObject = localtime(&t);
year = static_cast<unsigned int>(tmObject->tm_year);
month = static_cast<unsigned int>(tmObject->tm_mon + 1);
hour = static_cast<unsigned int>(tmObject->tm_hour);
minute = static_cast<unsigned int>(tmObject->tm_min);
second = static_cast<unsigned int>(tmObject->tm_sec);
}
IGpMutex *GpSystemServices_Web::CreateMutex()
{
return GpMutex_Web_Null::GetInstance();
}
IGpMutex *GpSystemServices_Web::CreateRecursiveMutex()
{
return GpMutex_Web_Null::GetInstance();
}
IGpThreadEvent *GpSystemServices_Web::CreateThreadEvent(bool autoReset, bool startSignaled)
{
return GpThreadEvent_Web_Null::GetInstance();
}
uint64_t GpSystemServices_Web::GetFreeMemoryCosmetic() const
{
return 0;
}
GpSystemServices_Web::~GpSystemServices_Web()
{
if (m_clipboardContents)
m_clipboardContents->Destroy();
}
void *GpSystemServices_Web::CreateThread(ThreadFunc_t threadFunc, void *context)
{
return nullptr;
}
bool GpSystemServices_Web::Beep() const
{
return false;
}
bool GpSystemServices_Web::IsTouchscreen() const
{
return false;
}
bool GpSystemServices_Web::IsUsingMouseAsTouch() const
{
return false;
}
bool GpSystemServices_Web::IsTextInputObstructive() const
{
return false;
}
bool GpSystemServices_Web::IsFullscreenPreferred() const
{
return false;
}
bool GpSystemServices_Web::IsFullscreenOnStartup() const
{
return false;
}
bool GpSystemServices_Web::HasNativeFileManager() const
{
return false;
}
GpOperatingSystem_t GpSystemServices_Web::GetOperatingSystem() const
{
return GpOperatingSystems::kWeb;
}
GpOperatingSystemFlavor_t GpSystemServices_Web::GetOperatingSystemFlavor() const
{
return GpOperatingSystemFlavors::kGeneric;
}
unsigned int GpSystemServices_Web::GetCPUCount() const
{
return SDL_GetCPUCount();
}
void GpSystemServices_Web::SetTextInputEnabled(bool isEnabled)
{
m_textInputEnabled = isEnabled;
}
bool GpSystemServices_Web::IsTextInputEnabled() const
{
return m_textInputEnabled;
}
bool GpSystemServices_Web::AreFontResourcesSeekable() const
{
return true;
}
IGpClipboardContents *GpSystemServices_Web::GetClipboardContents() const
{
return m_clipboardContents;
}
void GpSystemServices_Web::SetClipboardContents(IGpClipboardContents *contents)
{
if (contents != m_clipboardContents)
{
if (m_clipboardContents)
m_clipboardContents->Destroy();
m_clipboardContents = contents;
}
}
GpSystemServices_Web *GpSystemServices_Web::GetInstance()
{
return &ms_instance;
}
GpSystemServices_Web GpSystemServices_Web::ms_instance;

View File

@@ -0,0 +1,44 @@
#pragma once
#include "IGpSystemServices.h"
#include "GpCoreDefs.h"
struct IGpClipboardContents;
class GpSystemServices_Web final : public IGpSystemServices
{
public:
GpSystemServices_Web();
~GpSystemServices_Web();
void *CreateThread(ThreadFunc_t threadFunc, void *context) override;
bool Beep() const override;
bool IsTouchscreen() const override;
bool IsUsingMouseAsTouch() const override;
bool IsTextInputObstructive() const override;
bool IsFullscreenPreferred() const override;
bool IsFullscreenOnStartup() const override;
bool HasNativeFileManager() const override;
GpOperatingSystem_t GetOperatingSystem() const override;
GpOperatingSystemFlavor_t GetOperatingSystemFlavor() const override;
unsigned int GetCPUCount() const override;
void SetTextInputEnabled(bool isEnabled) override;
bool IsTextInputEnabled() const override;
bool AreFontResourcesSeekable() const override;
IGpClipboardContents *GetClipboardContents() const override;
void SetClipboardContents(IGpClipboardContents *contents) override;
int64_t GetTime() const override;
void GetLocalDateTime(unsigned int &year, unsigned int &month, unsigned int &day, unsigned int &hour, unsigned int &minute, unsigned int &second) const override;
IGpMutex *CreateMutex() override;
IGpMutex *CreateRecursiveMutex() override;
IGpThreadEvent *CreateThreadEvent(bool autoReset, bool startSignaled) override;
uint64_t GetFreeMemoryCosmetic() const override;
static GpSystemServices_Web *GetInstance();
private:
static GpSystemServices_Web ms_instance;
IGpClipboardContents *m_clipboardContents;
bool m_textInputEnabled;
};

10
AerofoilWeb/Link.bat Normal file
View File

@@ -0,0 +1,10 @@
set INPUT_DIR=.
set OUTPUT_DIR=bin
rem set DEBUG_LEVEL_FLAGS=-g4 -O0
set DEBUG_LEVEL_FLAGS=-O3
copy /Y FileSaverDotJS\dist\FileSaver.js bin\FileSaver.js
set FLAGS=-flto %DEBUG_LEVEL_FLAGS% -s USE_SDL=2 -s USE_ZLIB=1 -s ASYNCIFY -s ASYNCIFY_IGNORE_INDIRECT -s INITIAL_MEMORY=33554432 -s ASYNCIFY_ADVISE -lidbfs.js -s ASYNCIFY_IMPORTS=['InitFileSystem','FlushFileSystem'] --shell-file shell_minimal.html
emcc obj/AerofoilWeb_Combined.o obj/AerofoilWeb_Resources.o obj/GpShell_Combined.o obj/AerofoilSDL_Combined.o obj/AerofoilPortable_Combined.o obj/GpApp_Combined.o obj/PortabilityLayer_Combined.o obj/MacRomanConversion.o -o %OUTPUT_DIR%/aerofoil.html %FLAGS%

View File

@@ -0,0 +1,3 @@
mkdir obj
mkdir bin
mkdir res

9
AerofoilWeb/Rebuild.bat Normal file
View File

@@ -0,0 +1,9 @@
call MakeBuildDirs.bat
call BuildAerofoilSDL.bat
call BuildAerofoilWeb.bat
call BuildGpApp.bat
call BuildGpShell.bat
call BuildMacRomanConversion.bat
call BuildPortabilityLayer.bat
call BuildResources.bat
call Link.bat

1
AerofoilWeb/Run.bat Normal file
View File

@@ -0,0 +1 @@
emrun bin/aerofoil.html

View File

@@ -0,0 +1,141 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Aerofoil</title>
<style>
.emscripten { padding-right: 0; padding-top: 0; margin-left: auto; margin-right: auto; margin-top: 0; display: block; }
textarea.emscripten { font-family: monospace; width: 80%; }
div.emscripten { text-align: center; }
div.emscripten_border { border: 1px solid black; }
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten { border: 0px none; background-color: black; }
.spinner {
height: 50px;
width: 50px;
margin: 0px auto;
-webkit-animation: rotation .8s linear infinite;
-moz-animation: rotation .8s linear infinite;
-o-animation: rotation .8s linear infinite;
animation: rotation 0.8s linear infinite;
border-left: 10px solid rgb(0,150,240);
border-right: 10px solid rgb(0,150,240);
border-bottom: 10px solid rgb(0,150,240);
border-top: 10px solid rgb(100,0,200);
border-radius: 100%;
background-color: rgb(200,100,250);
}
@-webkit-keyframes rotation {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(360deg);}
}
@-moz-keyframes rotation {
from {-moz-transform: rotate(0deg);}
to {-moz-transform: rotate(360deg);}
}
@-o-keyframes rotation {
from {-o-transform: rotate(0deg);}
to {-o-transform: rotate(360deg);}
}
@keyframes rotation {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
</style>
</head>
<body class="emscripten">
<div class="emscripten" id="preload">
<figure style="overflow:visible;" id="spinner"><div class="spinner"></div><center style="margin-top:0.5em"><strong>emscripten</strong></center></figure>
<div class="emscripten" id="status">Downloading...</div>
<div class="emscripten">
<progress value="0" max="100" id="progress" hidden=1></progress>
</div>
<div class="emscripten_border">
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
</div>
</div>
<script type='text/javascript'>
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
var spinnerElement = document.getElementById('spinner');
var preloadElement = document.getElementById('preload');
var Module = {
preRun: [],
postRun: [],
print: (function() {
var element = document.getElementById('output');
if (element) element.value = ''; // clear browser cache
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
// These replacements are necessary if you render to raw HTML
//text = text.replace(/&/g, "&amp;");
//text = text.replace(/</g, "&lt;");
//text = text.replace(/>/g, "&gt;");
//text = text.replace('\n', '<br>', 'g');
console.log(text);
if (element) {
element.value += text + "\n";
element.scrollTop = element.scrollHeight; // focus on bottom
}
};
})(),
printErr: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
},
canvas: (function() {
var canvas = document.getElementById('canvas');
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
// application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
return canvas;
})(),
setStatus: function(text) {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.last.text) return;
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
var now = Date.now();
if (m && now - Module.setStatus.last.time < 30) return; // if this is a progress update, skip it if too soon
Module.setStatus.last.time = now;
Module.setStatus.last.text = text;
if (m) {
text = m[1];
progressElement.value = parseInt(m[2])*100;
progressElement.max = parseInt(m[4])*100;
progressElement.hidden = false;
spinnerElement.hidden = false;
} else {
progressElement.value = null;
progressElement.max = null;
progressElement.hidden = true;
if (!text) spinnerElement.hidden = true;
preloadElement.hidden = true;
}
statusElement.innerHTML = text;
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
}
};
Module.setStatus('Downloading...');
window.onerror = function() {
Module.setStatus('Exception thrown, see JavaScript console');
spinnerElement.style.display = 'none';
Module.setStatus = function(text) {
if (text) Module.printErr('[post-exception status] ' + text);
};
};
</script>
<script type="text/javascript" src="FileSaver.js"></script>
{{{ SCRIPT }}}
</body>
</html>

12
AerofoilWin.props Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(SolutionDir)Aerofoil;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup />
</Project>

View File

@@ -0,0 +1,488 @@
#define _LARGEFILE64_SOURCE
#include "GpFileSystem_X.h"
#include "GpIOStream.h"
#include "IGpDirectoryCursor.h"
#include "IGpSystemServices.h"
#include "IGpMutex.h"
#include "IGpThreadRelay.h"
#include "VirtualDirectory.h"
#include "PLDrivers.h"
#include "SDL2/SDL.h"
#include "SDL2/SDL_rwops.h"
#include <string>
#include <vector>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <dirent.h>
#include "UTF8.h"
#ifdef __CYGWIN__
typedef off_t off64_t;
#define fstat64 fstat
#define fseek64 fseek
#define ftruncate64 ftruncate
#define stat64 stat
#endif
class GpFileStream_X_File final : public GpIOStream
{
public:
GpFileStream_X_File(FILE *f, bool readOnly, bool writeOnly);
~GpFileStream_X_File();
size_t Read(void *bytesOut, size_t size) override;
size_t Write(const void *bytes, size_t size) override;
bool IsSeekable() const override;
bool IsReadOnly() const override;
bool IsWriteOnly() const override;
bool SeekStart(GpUFilePos_t loc) override;
bool SeekCurrent(GpFilePos_t loc) override;
bool SeekEnd(GpUFilePos_t loc) override;
GpUFilePos_t Size() const override;
GpUFilePos_t Tell() const override;
void Close() override;
void Flush() override;
private:
FILE *m_f;
bool m_seekable;
bool m_isReadOnly;
bool m_isWriteOnly;
};
GpFileStream_X_File::GpFileStream_X_File(FILE *f, bool readOnly, bool writeOnly)
: m_f(f)
, m_isReadOnly(readOnly)
, m_isWriteOnly(writeOnly)
{
m_seekable = (fseek(m_f, 0, SEEK_CUR) == 0);
}
GpFileStream_X_File::~GpFileStream_X_File()
{
fclose(m_f);
}
size_t GpFileStream_X_File::Read(void *bytesOut, size_t size)
{
if (m_isWriteOnly)
return 0;
return fread(bytesOut, 1, size, m_f);
}
size_t GpFileStream_X_File::Write(const void *bytes, size_t size)
{
if (m_isReadOnly)
return 0;
return fwrite(bytes, 1, size, m_f);
}
bool GpFileStream_X_File::IsSeekable() const
{
return m_seekable;
}
bool GpFileStream_X_File::IsReadOnly() const
{
return m_isReadOnly;
}
bool GpFileStream_X_File::IsWriteOnly() const
{
return m_isWriteOnly;
}
bool GpFileStream_X_File::SeekStart(GpUFilePos_t loc)
{
if (!m_seekable)
return false;
fflush(m_f);
return fseek64(m_f, static_cast<off64_t>(loc), SEEK_SET) >= 0;
}
bool GpFileStream_X_File::SeekCurrent(GpFilePos_t loc)
{
if (!m_seekable)
return false;
fflush(m_f);
return fseek64(m_f, static_cast<off64_t>(loc), SEEK_CUR) >= 0;
}
bool GpFileStream_X_File::SeekEnd(GpUFilePos_t loc)
{
if (!m_seekable)
return false;
fflush(m_f);
return fseek64(m_f, -static_cast<off64_t>(loc), SEEK_END) >= 0;
}
GpUFilePos_t GpFileStream_X_File::Size() const
{
fflush(m_f);
struct stat64 s;
if (fstat64(fileno(m_f), &s) < 0)
return 0;
return static_cast<GpUFilePos_t>(s.st_size);
}
GpUFilePos_t GpFileStream_X_File::Tell() const
{
return static_cast<GpUFilePos_t>(ftell(m_f));
}
void GpFileStream_X_File::Close()
{
this->~GpFileStream_X_File();
free(this);
}
void GpFileStream_X_File::Flush()
{
fflush(m_f);
}
bool GpFileSystem_X::ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths, std::string &resolution)
{
const char *prefsAppend = nullptr;
switch (virtualDirectory)
{
case PortabilityLayer::VirtualDirectories::kApplicationData:
resolution = std::string("Packaged");
break;
case PortabilityLayer::VirtualDirectories::kGameData:
resolution = std::string("Packaged/Houses");
break;
case PortabilityLayer::VirtualDirectories::kFonts:
resolution = std::string("Resources");
break;
case PortabilityLayer::VirtualDirectories::kHighScores:
prefsAppend = "HighScores";
break;
case PortabilityLayer::VirtualDirectories::kUserData:
prefsAppend = "Houses";
break;
case PortabilityLayer::VirtualDirectories::kUserSaves:
prefsAppend = "SavedGames";
break;
case PortabilityLayer::VirtualDirectories::kPrefs:
prefsAppend = "Prefs";
break;
case PortabilityLayer::VirtualDirectories::kLogs:
prefsAppend = "Logs";
break;
default:
return false;
};
if (prefsAppend)
resolution = m_prefsPath + prefsAppend;
else
resolution = m_basePath + resolution;
for (size_t i = 0; i < numPaths; i++)
{
resolution += "/";
resolution += paths[i];
}
return true;
}
GpFileSystem_X::GpFileSystem_X()
: m_delayCallback(nullptr)
{
}
GpFileSystem_X::~GpFileSystem_X()
{
}
void GpFileSystem_X::Init()
{
char *prefsDir = SDL_GetPrefPath("aerofoil", "aerofoil");
m_prefsPath = prefsDir;
char *baseDir = SDL_GetBasePath();
m_basePath = baseDir;
SDL_free(baseDir);
char baseDirSeparator = m_basePath[m_basePath.size() - 1];
if (m_basePath.size() >= 4 && m_basePath.substr(m_basePath.size() - 4, 3) == "bin")
m_basePath = m_basePath.substr(0, m_basePath.size() - 4) + "lib" + baseDirSeparator + "aerofoil" + baseDirSeparator;
const char *extensions[] = { "HighScores", "Houses", "SavedGames", "Prefs", "Logs" };
for (size_t i = 0; i < sizeof(extensions) / sizeof(extensions[0]); i++)
{
std::string prefsPath = std::string(prefsDir) + extensions[i];
int created = mkdir(prefsPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
}
SDL_free(prefsDir);
}
bool GpFileSystem_X::FileExists(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path)
{
std::string resolvedPath;
if (!ResolvePath(virtualDirectory, &path, 1, resolvedPath))
return false;
struct stat s;
return stat(resolvedPath.c_str(), &s) == 0;
}
bool GpFileSystem_X::FileLocked(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &exists)
{
std::string resolvedPath;
if (!ResolvePath(virtualDirectory, &path, 1, resolvedPath))
{
if (exists)
exists = false;
return false;
}
int permissions = access(resolvedPath.c_str(), W_OK | F_OK);
exists = ((permissions & F_OK) != 0);
return ((permissions & W_OK) != 0);
}
GpIOStream *GpFileSystem_X::OpenFileNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* subPaths, size_t numSubPaths, bool writeAccess, GpFileCreationDisposition_t createDisposition)
{
const char *mode = nullptr;
bool canWrite = false;
bool needResetPosition = false;
switch (createDisposition)
{
case GpFileCreationDispositions::kCreateOrOverwrite:
mode = "wb";
break;
case GpFileCreationDispositions::kCreateNew:
mode = "x+b";
break;
case GpFileCreationDispositions::kCreateOrOpen:
mode = "a+b";
needResetPosition = true;
break;
case GpFileCreationDispositions::kOpenExisting:
mode = writeAccess ? "r+b" : "rb";
break;
case GpFileCreationDispositions::kOverwriteExisting:
mode = "r+b";
break;
default:
return nullptr;
};
if (virtualDirectory == PortabilityLayer::VirtualDirectories::kSourceExport)
return nullptr;
std::string resolvedPath;
if (!ResolvePath(virtualDirectory, subPaths, numSubPaths, resolvedPath))
return nullptr;
void *objStorage = malloc(sizeof(GpFileStream_X_File));
if (!objStorage)
return nullptr;
FILE *f = fopen(resolvedPath.c_str(), mode);
if (!f)
{
free(objStorage);
return nullptr;
}
if (needResetPosition)
fseek(f, 0, SEEK_SET);
if (createDisposition == GpFileCreationDispositions::kOverwriteExisting)
{
if (ftruncate64(fileno(f), 0) < 0)
{
free(objStorage);
fclose(f);
return nullptr;
}
}
return new (objStorage) GpFileStream_X_File(f, !writeAccess, false);
}
bool GpFileSystem_X::DeleteFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &existed)
{
std::string resolvedPath;
if (!ResolvePath(virtualDirectory, &path, 1, resolvedPath))
{
existed = false;
return false;
}
if (unlink(resolvedPath.c_str()) < 0)
{
existed = (errno != ENOENT);
return false;
}
existed = true;
return true;
}
bool GpFileSystem_X::ValidateFilePath(const char *path, size_t length) const
{
for (size_t i = 0; i < length; i++)
{
const char c = path[i];
if (c >= '0' && c <= '9')
continue;
if (c == '_' || c == '.' || c == '\'' || c == '!')
continue;
if (c == ' ' && i != 0 && i != length - 1)
continue;
if (c >= 'a' && c <= 'z')
continue;
if (c >= 'A' && c <= 'Z')
continue;
return false;
}
return true;
}
bool GpFileSystem_X::ValidateFilePathUnicodeChar(uint32_t c) const
{
if (c >= '0' && c <= '9')
return true;
if (c == '_' || c == '\'')
return true;
if (c == ' ')
return true;
if (c >= 'a' && c <= 'z')
return true;
if (c >= 'A' && c <= 'Z')
return true;
return false;
}
void GpFileSystem_X::SetDelayCallback(DelayCallback_t delayCallback)
{
m_delayCallback = delayCallback;
}
GpFileSystem_X *GpFileSystem_X::GetInstance()
{
return &ms_instance;
}
class GpDirectoryCursor_StringList final : public IGpDirectoryCursor
{
public:
explicit GpDirectoryCursor_StringList(std::vector<std::string> &paths);
~GpDirectoryCursor_StringList();
bool GetNext(const char *&outFileName) override;
void Destroy() override;
private:
std::vector<std::string> m_paths;
size_t m_index;
};
GpDirectoryCursor_StringList::GpDirectoryCursor_StringList(std::vector<std::string> &paths)
: m_index(0)
{
std::swap(paths, m_paths);
}
GpDirectoryCursor_StringList::~GpDirectoryCursor_StringList()
{
}
bool GpDirectoryCursor_StringList::GetNext(const char *&outFileName)
{
if (m_index == m_paths.size())
return false;
outFileName = m_paths[m_index].c_str();
m_index++;
return true;
}
void GpDirectoryCursor_StringList::Destroy()
{
delete this;
}
class GpDirectoryCursor_POSIX final : public IGpDirectoryCursor
{
public:
explicit GpDirectoryCursor_POSIX(DIR *dir);
~GpDirectoryCursor_POSIX();
bool GetNext(const char *&outFileName) override;
void Destroy() override;
private:
DIR *m_dir;
};
GpDirectoryCursor_POSIX::GpDirectoryCursor_POSIX(DIR *dir)
: m_dir(dir)
{
}
GpDirectoryCursor_POSIX::~GpDirectoryCursor_POSIX()
{
closedir(m_dir);
}
bool GpDirectoryCursor_POSIX::GetNext(const char *&outFileName)
{
struct dirent *dir = readdir(m_dir);
if (!dir)
return false;
outFileName = dir->d_name;
return true;
}
void GpDirectoryCursor_POSIX::Destroy()
{
delete this;
}
IGpDirectoryCursor *GpFileSystem_X::ScanDirectoryNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths)
{
std::string resolvedPath;
std::vector<std::string> subPaths;
if (!ResolvePath(virtualDirectory, paths, numPaths, resolvedPath))
return nullptr;
DIR *d = opendir(resolvedPath.c_str());
if (!d)
return nullptr;
return new GpDirectoryCursor_POSIX(d);
}
GpFileSystem_X GpFileSystem_X::ms_instance;

View File

@@ -0,0 +1,42 @@
#pragma once
#include "IGpFileSystem.h"
#include "GpCoreDefs.h"
#include <string>
#include <stdio.h>
struct IGpMutex;
class GpFileSystem_X final : public IGpFileSystem
{
public:
GpFileSystem_X();
~GpFileSystem_X();
void Init();
bool FileExists(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path) override;
bool FileLocked(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &exists) override;
GpIOStream *OpenFileNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* subPaths, size_t numSubPaths, bool writeAccess, GpFileCreationDisposition_t createDisposition) override;
bool DeleteFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &existed) override;
IGpDirectoryCursor *ScanDirectoryNested(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths) override;
bool ValidateFilePath(const char *path, size_t pathLen) const override;
bool ValidateFilePathUnicodeChar(uint32_t ch) const override;
void SetDelayCallback(DelayCallback_t delayCallback) override;
static GpFileSystem_X *GetInstance();
private:
bool ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths, std::string &resolution);
DelayCallback_t m_delayCallback;
std::string m_prefsPath;
std::string m_basePath;
static GpFileSystem_X ms_instance;
};

127
AerofoilX/GpLogDriver_X.cpp Normal file
View File

@@ -0,0 +1,127 @@
#include "GpLogDriver_X.h"
#include "GpFileSystem_X.h"
#include "GpApplicationName.h"
#include "GpIOStream.h"
#include <time.h>
#include <cstring>
GpLogDriver_X::GpLogDriver_X()
: m_stream(nullptr)
, m_isInitialized(false)
{
}
void GpLogDriver_X::Init()
{
ms_instance.InitInternal();
}
void GpLogDriver_X::VPrintf(Category category, const char *fmt, va_list args)
{
size_t fmtSize = 0;
bool hasFormatting = false;
for (const char *fmtCheck = fmt; *fmtCheck; fmtCheck++)
{
if (*fmtCheck == '%')
hasFormatting = true;
fmtSize++;
}
time_t t = time(nullptr);
struct tm sysTime = *localtime(&t);
char timestampBuffer[64];
sprintf(timestampBuffer, "[%02d:%02d:%02d] ", sysTime.tm_hour, sysTime.tm_min, sysTime.tm_sec);
if (m_stream)
m_stream->Write(timestampBuffer, strlen(timestampBuffer));
const char *debugTag = "";
switch (category)
{
case Category_Warning:
debugTag = "[WARNING] ";
break;
case Category_Error:
debugTag = "[ERROR] ";
break;
};
if (debugTag[0])
{
if (m_stream)
m_stream->Write(debugTag, strlen(debugTag));
}
if (!hasFormatting)
{
if (m_stream)
m_stream->Write(fmt, fmtSize);
}
else
{
int formattedSize = vsnprintf(nullptr, 0, fmt, args);
if (formattedSize <= 0)
return;
char *charBuff = static_cast<char*>(malloc(formattedSize + 1));
if (!charBuff)
return;
vsnprintf(charBuff, formattedSize + 1, fmt, args);
if (m_stream)
m_stream->Write(charBuff, formattedSize);
free(charBuff);
}
if (m_stream)
{
m_stream->Write("\n", 1);
m_stream->Flush();
}
}
void GpLogDriver_X::Shutdown()
{
if (m_stream)
m_stream->Close();
}
GpLogDriver_X *GpLogDriver_X::GetInstance()
{
if (ms_instance.m_isInitialized)
return &ms_instance;
else
return nullptr;
}
void GpLogDriver_X::InitInternal()
{
time_t t = time(nullptr);
struct tm utcTime = *gmtime(&t);
char logFileName[256];
sprintf(logFileName, GP_APPLICATION_NAME "-%04d-%02d-%02d_%02d-%02d_%02d.txt", utcTime.tm_year, utcTime.tm_mon, utcTime.tm_mday, utcTime.tm_hour, utcTime.tm_min, utcTime.tm_sec);
m_stream = GpFileSystem_X::GetInstance()->OpenFile(PortabilityLayer::VirtualDirectories::kLogs, logFileName, true, GpFileCreationDispositions::kCreateOrOverwrite);
if (m_stream)
{
this->Printf(IGpLogDriver::Category_Information, GP_APPLICATION_NAME " build " __TIMESTAMP__);
#if !GP_DEBUG_CONFIG
this->Printf(IGpLogDriver::Category_Information, "Configuration: Release");
#else
this->Printf(IGpLogDriver::Category_Information, "Configuration: Debug");
#endif
m_isInitialized = true;
}
}
GpLogDriver_X GpLogDriver_X::ms_instance;

28
AerofoilX/GpLogDriver_X.h Normal file
View File

@@ -0,0 +1,28 @@
#pragma once
#include "IGpLogDriver.h"
#include <stdio.h>
class GpIOStream;
class GpLogDriver_X : public IGpLogDriver
{
public:
GpLogDriver_X();
static void Init();
void VPrintf(Category category, const char *fmt, va_list args) override;
void Shutdown() override;
static GpLogDriver_X *GetInstance();
private:
void InitInternal();
GpIOStream *m_stream;
bool m_isInitialized;
static GpLogDriver_X ms_instance;
};

View File

@@ -0,0 +1,89 @@
#include "SDL.h"
#include "SDL_main.h"
#include "GpMain.h"
#include "GpAudioDriverFactory.h"
#include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h"
#include "GpFileSystem_X.h"
#include "GpLogDriver_X.h"
#include "GpFontHandlerFactory.h"
#include "GpInputDriverFactory.h"
#include "GpAppInterface.h"
#include "GpSystemServices_X.h"
#include "GpVOSEvent.h"
#include "GpX.h"
#include "IGpFileSystem.h"
#include "IGpThreadEvent.h"
#include "IGpVOSEventQueue.h"
#include <string>
GpXGlobals g_gpXGlobals;
IGpDisplayDriver *GpDriver_CreateDisplayDriver_SDL_GL2(const GpDisplayDriverProperties &properties);
IGpAudioDriver *GpDriver_CreateAudioDriver_SDL(const GpAudioDriverProperties &properties);
IGpInputDriver *GpDriver_CreateInputDriver_SDL2_Gamepad(const GpInputDriverProperties &properties);
SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[])
{
bool enableLogging = false;
for (int i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "-diagnostics"))
enableLogging = true;
}
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0)
return -1;
GpFileSystem_X::GetInstance()->Init();
IGpLogDriver *logger = nullptr;
if (enableLogging)
{
GpLogDriver_X::Init();
logger = GpLogDriver_X::GetInstance();
}
GpDriverCollection *drivers = GpAppInterface_Get()->PL_GetDriverCollection();
drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_X::GetInstance());
drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_X::GetInstance());
drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_X::GetInstance());
g_gpGlobalConfig.m_displayDriverType = EGpDisplayDriverType_SDL_GL2;
g_gpGlobalConfig.m_audioDriverType = EGpAudioDriverType_SDL2;
g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_None;
EGpInputDriverType inputDrivers[] =
{
EGpInputDriverType_SDL2_Gamepad
};
g_gpGlobalConfig.m_inputDriverTypes = inputDrivers;
g_gpGlobalConfig.m_numInputDrivers = sizeof(inputDrivers) / sizeof(inputDrivers[0]);
g_gpGlobalConfig.m_osGlobals = &g_gpXGlobals;
g_gpGlobalConfig.m_logger = logger;
g_gpGlobalConfig.m_systemServices = GpSystemServices_X::GetInstance();
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2);
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL);
GpInputDriverFactory::RegisterInputDriverFactory(EGpInputDriverType_SDL2_Gamepad, GpDriver_CreateInputDriver_SDL2_Gamepad);
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "SDL environment configured, starting up");
int returnCode = GpMain::Run();
if (logger)
logger->Printf(IGpLogDriver::Category_Information, "SDL environment exited with code %i, cleaning up", returnCode);
return returnCode;
}

View File

@@ -0,0 +1,153 @@
#include "GpSystemServices_X.h"
#include "IGpClipboardContents.h"
#include "IGpThreadEvent.h"
#include "SDL2/SDL.h"
#include <time.h>
#include <unistd.h>
#include <string>
struct GpSystemServices_X_ThreadStartParams
{
GpSystemServices_X::ThreadFunc_t m_threadFunc;
void *m_threadContext;
IGpThreadEvent *m_threadStartEvent;
};
static void *StaticStartThread(void *lpThreadParameter)
{
const GpSystemServices_X_ThreadStartParams *threadParams = static_cast<const GpSystemServices_X_ThreadStartParams*>(lpThreadParameter);
GpSystemServices_X::ThreadFunc_t threadFunc = threadParams->m_threadFunc;
void *threadContext = threadParams->m_threadContext;
IGpThreadEvent *threadStartEvent = threadParams->m_threadStartEvent;
threadStartEvent->Signal();
return reinterpret_cast<void*>(static_cast<intptr_t>(threadFunc(threadContext)));
}
GpSystemServices_X::GpSystemServices_X()
: m_textInputEnabled(false)
, m_clipboardContents(nullptr)
{
}
GpSystemServices_X::~GpSystemServices_X()
{
if (m_clipboardContents)
m_clipboardContents->Destroy();
}
void *GpSystemServices_X::CreateThread(ThreadFunc_t threadFunc, void *context)
{
IGpThreadEvent *evt = CreateThreadEvent(true, false);
if (!evt)
return nullptr;
GpSystemServices_X_ThreadStartParams startParams;
startParams.m_threadContext = context;
startParams.m_threadFunc = threadFunc;
startParams.m_threadStartEvent = evt;
pthread_t thread = nullptr;
if (pthread_create(&thread, nullptr, StaticStartThread, &startParams) != 0)
{
evt->Destroy();
return nullptr;
}
evt->Wait();
evt->Destroy();
return thread;
}
bool GpSystemServices_X::Beep() const
{
return false;
}
bool GpSystemServices_X::IsTouchscreen() const
{
return false;
}
bool GpSystemServices_X::IsUsingMouseAsTouch() const
{
return false;
}
bool GpSystemServices_X::IsTextInputObstructive() const
{
return false;
}
bool GpSystemServices_X::IsFullscreenPreferred() const
{
return true;
}
bool GpSystemServices_X::IsFullscreenOnStartup() const
{
return false;
}
bool GpSystemServices_X::HasNativeFileManager() const
{
return true;
}
GpOperatingSystem_t GpSystemServices_X::GetOperatingSystem() const
{
return GpOperatingSystems::kLinux;
}
GpOperatingSystemFlavor_t GpSystemServices_X::GetOperatingSystemFlavor() const
{
return GpOperatingSystemFlavors::kGeneric;
}
unsigned int GpSystemServices_X::GetCPUCount() const
{
return SDL_GetCPUCount();
}
void GpSystemServices_X::SetTextInputEnabled(bool isEnabled)
{
m_textInputEnabled = isEnabled;
}
bool GpSystemServices_X::IsTextInputEnabled() const
{
return m_textInputEnabled;
}
bool GpSystemServices_X::AreFontResourcesSeekable() const
{
return true;
}
IGpClipboardContents *GpSystemServices_X::GetClipboardContents() const
{
return m_clipboardContents;
}
void GpSystemServices_X::SetClipboardContents(IGpClipboardContents *contents)
{
if (contents != m_clipboardContents)
{
if (m_clipboardContents)
m_clipboardContents->Destroy();
m_clipboardContents = contents;
}
}
GpSystemServices_X *GpSystemServices_X::GetInstance()
{
return &ms_instance;
}
GpSystemServices_X GpSystemServices_X::ms_instance;

View File

@@ -0,0 +1,38 @@
#pragma once
#include "GpSystemServices_POSIX.h"
#include "GpCoreDefs.h"
struct IGpClipboardContents;
class GpSystemServices_X final : public GpSystemServices_POSIX
{
public:
GpSystemServices_X();
~GpSystemServices_X();
void *CreateThread(ThreadFunc_t threadFunc, void *context) override;
bool Beep() const override;
bool IsTouchscreen() const override;
bool IsUsingMouseAsTouch() const override;
bool IsTextInputObstructive() const override;
bool IsFullscreenPreferred() const override;
bool IsFullscreenOnStartup() const override;
bool HasNativeFileManager() const override;
GpOperatingSystem_t GetOperatingSystem() const override;
GpOperatingSystemFlavor_t GetOperatingSystemFlavor() const override;
unsigned int GetCPUCount() const override;
void SetTextInputEnabled(bool isEnabled) override;
bool IsTextInputEnabled() const override;
bool AreFontResourcesSeekable() const override;
IGpClipboardContents *GetClipboardContents() const override;
void SetClipboardContents(IGpClipboardContents *contents) override;
static GpSystemServices_X *GetInstance();
private:
static GpSystemServices_X ms_instance;
IGpClipboardContents *m_clipboardContents;
bool m_textInputEnabled;
};

View File

@@ -4,7 +4,7 @@
{
"name" : "Okay",
"itemType" : "Button",
"pos" : [ 376, 240 ],
"pos" : [ 376, 288 ],
"size" : [ 58, 20 ],
"id" : 1,
"enabled" : true
@@ -12,7 +12,7 @@
{
"name" : "Third Party/Licensing Info...",
"itemType" : "Button",
"pos" : [ 176, 240 ],
"pos" : [ 176, 288 ],
"size" : [ 190, 20 ],
"id" : 1,
"enabled" : true

View File

@@ -18,7 +18,7 @@
"enabled" : false
},
{
"name" : "Aerofoil ©2019-2021 Eric Lasota",
"name" : "Aerofoil ©2019-2021 Gale Force Games LLC",
"itemType" : "Label",
"pos" : [ 16, 21 ],
"size" : [ 406, 20 ],

View File

@@ -0,0 +1,61 @@
{
"items" :
[
{
"name" : "Okay",
"itemType" : "Button",
"pos" : [ 376, 240 ],
"size" : [ 58, 20 ],
"id" : 1,
"enabled" : true
},
{
"name" : "Cancel",
"itemType" : "Button",
"pos" : [ 302, 240 ],
"size" : [ 58, 20 ],
"id" : 2,
"enabled" : true
},
{
"name" : "",
"itemType" : "CustomControl",
"pos" : [ 17, 33 ],
"size" : [ 401, 186 ],
"id" : 2,
"enabled" : true
},
{
"name" : "",
"itemType" : "CustomControl",
"pos" : [ 418, 32 ],
"size" : [ 16, 188 ],
"id" : 3,
"enabled" : true
},
{
"name" : "",
"itemType" : "EditBox",
"pos" : [ 16, 240 ],
"size" : [ 196, 16 ],
"id" : 4,
"enabled" : true
},
{
"name" : "^0",
"itemType" : "Label",
"pos" : [ 16, 16 ],
"size" : [ 418, 16 ],
"id" : 10,
"enabled" : true
},
{
"name" : "Delete",
"itemType" : "Button",
"pos" : [ 228, 240 ],
"size" : [ 58, 20 ],
"id" : 2,
"enabled" : false
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

View File

@@ -0,0 +1,26 @@
A never-before-seen error has arisen. Proceed with caution! (Save and Quit immediately.)
I failed to open the house's resource fork. Any unique room backgrounds are not accessible.
I failed to add a resource to the house's resource fork. See error number.
I failed to create a new resource fork for the house. See error number for problem.
There are no houses on this drive! About your only option is to create your own new house with the Editor.
This house is incompatible with us! You'll need to upgrade Glider PRO to use this house. Do not attempt to play/edit this house!
The background specified by this room was not found! Try re-selecting a new background (the Room Info menu).
The room number is out of bounds. I suspect the house file is corrupt. Try deleting this "illegal" room though.
The data is missing that specifies where the openings in this room are. The house may be damaged. Try selecting a new background though.
There was a problem with the clipboard (Cut, Copy and Paste commands). I couldn't guess why.
I think we just ran out of memory. Quit now and give Glider PRO<52> more memory.
We failed to write the house to disk. (That shouldn't have happened.)
Well, the music didn't load. Glider PRO<52> will still run, you'll just be musically challenged.
Wow, there was a problem bringing sounds up. You might try giving Glider PRO<52> more memory - otherwise ... silence.
Some kind of strange Apple Event error. I think I would just ignore it. Or call Casady & Greene with the error number.
Did you save the house on the same volume Glider PRO is on? I saved the house but had to re-open the old house because I couldn't find the new one.
Wow, I couldn't find the old or new house. Go to the Select House menu item and see if it's there. If not, make sure they're on the same volume as Glider PRO.
Couldn't create a saved game structure. Memory is probably too low.
The saved game doesn't match the house. Either this game was saved for a different house or the house was modified recently.
This saved game is an old version. We cannot use this game with this house.
The number of rooms saved doesn't match the number of house rooms. We cannot use this game with this house.
The QuickTime<6D> movie that goes with this house will not be used. Glider PRO<52> must have enough memory to easily load the entire movie into RAM.
This house has no rooms! Do not attempt to play this house! Select a new house to play.
There was an error generating or parsing a links list. Memory may be tight.
This house contains invalid data that couldn't be repaired. Select a new house to play.
This house contained invalid data, which was repaired. Some things may be missing or not work correctly.

View File

@@ -12,10 +12,9 @@
"DITL/2006.json" : "ApplicationResourcePatches/DITL/2006.json",
"DITL/2007.json" : "ApplicationResourcePatches/DITL/2007.json",
"DITL/2008.json" : "ApplicationResourcePatches/DITL/2008.json",
"DITL/2009.json" : "ApplicationResourcePatches/DITL/2009.json",
"PICT/1300.bmp" : "ApplicationResourcePatches/PICT/1300.bmp",
"PICT/1301.bmp" : "ApplicationResourcePatches/PICT/1301.bmp",
"PICT/1302.bmp" : "ApplicationResourcePatches/PICT/1302.bmp",
"PICT/1303.bmp" : "ApplicationResourcePatches/PICT/1303.bmp",
"PICT/1971.bmp" : "ApplicationResourcePatches/PICT/1971.bmp",
"PICT/1972.bmp" : "ApplicationResourcePatches/PICT/1972.bmp",
"PICT/1973.bmp" : "ApplicationResourcePatches/PICT/1973.bmp",
@@ -39,7 +38,9 @@
"LICS/1003.txt" : "ApplicationResourcePatches/LICS/1003.txt",
"LICS/1004.txt" : "ApplicationResourcePatches/LICS/1004.txt",
"LICS/1005.txt" : "ApplicationResourcePatches/LICS/1005.txt",
"LICS/1006.txt" : "ApplicationResourcePatches/LICS/1006.txt"
"LICS/1006.txt" : "ApplicationResourcePatches/LICS/1006.txt",
"STR$23/1006.txt" : "ApplicationResourcePatches/STR/1006.txt",
"snd$20/1063.wav" : "ApplicationResourcePatches/SND/1063.wav"
},
"delete" :
[

263
CMakeLists.txt Normal file
View File

@@ -0,0 +1,263 @@
cmake_minimum_required(VERSION 3.10)
project (Aerofoil)
message(${CMAKE_BINARY_DIR})
find_package(SDL2 REQUIRED)
add_definitions(-DGP_DEBUG_CONFIG=0)
add_library(stb STATIC
stb/stb_image_write.c
)
add_library(zlib STATIC
zlib/adler32.c
zlib/crc32.c
zlib/deflate.c
zlib/inffast.c
zlib/inflate.c
zlib/inftrees.c
zlib/trees.c
zlib/zutil.c
)
add_library(MacRomanConversion STATIC
MacRomanConversion/MacRomanConversion.cpp
)
add_library(PortabilityLayer STATIC
PortabilityLayer/AntiAliasTable.cpp
PortabilityLayer/AppEventHandler.cpp
PortabilityLayer/BinHex4.cpp
PortabilityLayer/BitmapImage.cpp
PortabilityLayer/ByteSwap.cpp
PortabilityLayer/CFileStream.cpp
PortabilityLayer/DeflateCodec.cpp
PortabilityLayer/DialogManager.cpp
PortabilityLayer/DisplayDeviceManager.cpp
PortabilityLayer/EllipsePlotter.cpp
PortabilityLayer/FileBrowserUI.cpp
PortabilityLayer/FileManager.cpp
PortabilityLayer/FileSectionStream.cpp
PortabilityLayer/FontFamily.cpp
PortabilityLayer/FontManager.cpp
PortabilityLayer/FontRenderer.cpp
PortabilityLayer/GPArchive.cpp
PortabilityLayer/HostSuspendHook.cpp
PortabilityLayer/IconLoader.cpp
PortabilityLayer/InflateStream.cpp
PortabilityLayer/InputManager.cpp
PortabilityLayer/LinePlotter.cpp
PortabilityLayer/MacBinary2.cpp
PortabilityLayer/MacFileInfo.cpp
PortabilityLayer/MacFileMem.cpp
PortabilityLayer/MemoryManager.cpp
PortabilityLayer/MemReaderStream.cpp
PortabilityLayer/MenuManager.cpp
PortabilityLayer/MMHandleBlock.cpp
PortabilityLayer/PLApplication.cpp
PortabilityLayer/PLButtonWidget.cpp
PortabilityLayer/PLControlDefinitions.cpp
PortabilityLayer/PLCore.cpp
PortabilityLayer/PLCTabReducer.cpp
PortabilityLayer/PLDialogs.cpp
PortabilityLayer/PLDrivers.cpp
PortabilityLayer/PLEditboxWidget.cpp
PortabilityLayer/PLEventQueue.cpp
PortabilityLayer/PLHacks.cpp
PortabilityLayer/PLHandle.cpp
PortabilityLayer/PLIconWidget.cpp
PortabilityLayer/PLImageWidget.cpp
PortabilityLayer/PLInvisibleWidget.cpp
PortabilityLayer/PLKeyEncoding.cpp
PortabilityLayer/PLLabelWidget.cpp
PortabilityLayer/PLMenus.cpp
PortabilityLayer/PLMovies.cpp
PortabilityLayer/PLNumberFormatting.cpp
PortabilityLayer/PLPopupMenuWidget.cpp
PortabilityLayer/PLQDOffscreen.cpp
PortabilityLayer/PLQDraw.cpp
PortabilityLayer/PLResourceManager.cpp
PortabilityLayer/PLResources.cpp
PortabilityLayer/PLScrollBarWidget.cpp
PortabilityLayer/PLSound.cpp
PortabilityLayer/PLStandardColors.cpp
PortabilityLayer/PLStringCompare.cpp
PortabilityLayer/PLSysCalls.cpp
PortabilityLayer/PLTimeTaggedVOSEvent.cpp
PortabilityLayer/PLWidgets.cpp
PortabilityLayer/QDGraf.cpp
PortabilityLayer/QDManager.cpp
PortabilityLayer/QDPictDecoder.cpp
PortabilityLayer/QDPictEmitContext.cpp
PortabilityLayer/QDPictHeader.cpp
PortabilityLayer/QDPixMap.cpp
PortabilityLayer/QDPort.cpp
PortabilityLayer/QDStandardPalette.cpp
PortabilityLayer/RandomNumberGenerator.cpp
PortabilityLayer/ResolveCachingColor.cpp
PortabilityLayer/ResourceCompiledRef.cpp
PortabilityLayer/ResourceFile.cpp
PortabilityLayer/ScanlineMask.cpp
PortabilityLayer/ScanlineMaskBuilder.cpp
PortabilityLayer/ScanlineMaskConverter.cpp
PortabilityLayer/ScanlineMaskIterator.cpp
PortabilityLayer/SimpleGraphic.cpp
PortabilityLayer/TextPlacer.cpp
PortabilityLayer/UTF8.cpp
PortabilityLayer/WindowDef.cpp
PortabilityLayer/WindowManager.cpp
PortabilityLayer/WorkerThread.cpp
PortabilityLayer/XModemCRC.cpp
PortabilityLayer/ZipFileProxy.cpp
)
target_include_directories(PortabilityLayer PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Common>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/GpCommon>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/PortabilityLayer>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/zlib>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rapidjson/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/MacRomanConversion>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/stb>
)
target_compile_options(PortabilityLayer PRIVATE -Wno-multichar)
target_link_libraries(PortabilityLayer zlib MacRomanConversion stb)
add_library(GpShell STATIC
GpShell/GpAppEnvironment.cpp
GpShell/GpAudioDriverFactory.cpp
GpShell/GpDisplayDriverFactory.cpp
GpShell/GpFontHandlerFactory.cpp
GpShell/GpGlobalConfig.cpp
GpShell/GpInputDriverFactory.cpp
GpShell/GpMain.cpp
GpShell/GpVOSEventQueue.cpp
)
target_include_directories(GpShell PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Common>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/GpCommon>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/PortabilityLayer>
)
add_library(GpApp STATIC
GpApp/About.cpp
GpApp/AnimCursor.cpp
GpApp/AppleEvents.cpp
GpApp/Banner.cpp
GpApp/ColorUtils.cpp
GpApp/Coordinates.cpp
GpApp/DialogUtils.cpp
GpApp/DynamicMaps.cpp
GpApp/Dynamics.cpp
GpApp/Dynamics2.cpp
GpApp/Dynamics3.cpp
GpApp/Environ.cpp
GpApp/Events.cpp
GpApp/FileError.cpp
GpApp/GameOver.cpp
GpApp/GpAppInterface.cpp
GpApp/Grease.cpp
GpApp/HighScores.cpp
GpApp/House.cpp
GpApp/HouseInfo.cpp
GpApp/HouseIO.cpp
GpApp/HouseLegal.cpp
GpApp/Input.cpp
GpApp/Interactions.cpp
GpApp/InterfaceInit.cpp
GpApp/Link.cpp
GpApp/Main.cpp
GpApp/MainMenuUI.cpp
GpApp/MainWindow.cpp
GpApp/Map.cpp
GpApp/Marquee.cpp
GpApp/Menu.cpp
GpApp/Modes.cpp
GpApp/Music.cpp
GpApp/ObjectAdd.cpp
GpApp/ObjectDraw.cpp
GpApp/ObjectDraw2.cpp
GpApp/ObjectDrawAll.cpp
GpApp/ObjectEdit.cpp
GpApp/ObjectInfo.cpp
GpApp/ObjectRects.cpp
GpApp/Objects.cpp
GpApp/Play.cpp
GpApp/Player.cpp
GpApp/Prefs.cpp
GpApp/RectUtils.cpp
GpApp/Render.cpp
GpApp/Room.cpp
GpApp/RoomGraphics.cpp
GpApp/RoomInfo.cpp
GpApp/RubberBands.cpp
GpApp/SavedGames.cpp
GpApp/Scoreboard.cpp
GpApp/Scrap.cpp
GpApp/SelectHouse.cpp
GpApp/Settings.cpp
GpApp/Sound.cpp
GpApp/SoundSync_Cpp11.cpp
GpApp/SourceExport.cpp
GpApp/StringUtils.cpp
GpApp/StructuresInit.cpp
GpApp/StructuresInit2.cpp
GpApp/Tools.cpp
GpApp/Transit.cpp
GpApp/Transitions.cpp
GpApp/Triggers.cpp
GpApp/Trip.cpp
GpApp/Utilities.cpp
GpApp/WindowUtils.cpp
)
target_compile_options(GpApp PRIVATE -Wno-multichar)
target_include_directories(GpApp PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Common>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/GpCommon>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/PortabilityLayer>
)
target_link_libraries(GpApp PortabilityLayer)
if(CMAKE_HOST_UNIX)
add_executable(AerofoilX
AerofoilPortable/GpSystemServices_POSIX.cpp
AerofoilPortable/GpThreadEvent_Cpp11.cpp
AerofoilSDL/GpAudioDriver_SDL2.cpp
AerofoilSDL/GpDisplayDriver_SDL_GL2.cpp
AerofoilSDL/GpInputDriver_SDL_Gamepad.cpp
AerofoilSDL/ShaderCode/CopyQuadP.cpp
AerofoilSDL/ShaderCode/DrawQuad32P.cpp
AerofoilSDL/ShaderCode/DrawQuadPaletteP.cpp
AerofoilSDL/ShaderCode/DrawQuadV.cpp
AerofoilSDL/ShaderCode/ScaleQuadP.cpp
AerofoilX/GpMain_SDL_X.cpp
AerofoilX/GpLogDriver_X.cpp
AerofoilX/GpSystemServices_X.cpp
AerofoilX/GpFileSystem_X.cpp
)
target_include_directories(AerofoilX PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Common>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/GpCommon>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/GpShell>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/AerofoilSDL>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/AerofoilPortable>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/PortabilityLayer>
${SDL2_INCLUDE_DIRS}
)
target_link_libraries(AerofoilX ${SDL2_LIBRARIES} GpApp GpShell)
endif()
install (TARGETS AerofoilX)

View File

@@ -1,6 +1,7 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
#if __cplusplus >= 199711L
#define GP_IS_CPP11 1
@@ -17,6 +18,7 @@
#if GP_IS_CPP11
#define GP_DELETED = delete
#define GP_STATIC_ASSERT(n) static_assert((n), "Static assert failed: " #n)
#define GP_RESTRICT __restrict
#else
#ifndef nullptr
#define nullptr 0
@@ -31,6 +33,7 @@
#endif
#define GP_DELETED
#define GP_RESTRICT
template<bool TCondition>
struct __GpStaticAssertHelper
@@ -52,3 +55,23 @@ static const size_t GP_SYSTEM_MEMORY_ALIGNMENT = 16;
#if !defined(GP_DEBUG_CONFIG)
#error "GP_DEBUG_CONFIG was not set"
#endif
#ifdef __EMSCRIPTEN__
#define GP_ASYNCIFY_PARANOID 1
#else
#define GP_ASYNCIFY_PARANOID 0
#endif
#define GP_ASYNCIFY_PARANOID_VALIDATION 0
#if GP_ASYNCIFY_PARANOID
#define GP_ASYNCIFY_PARANOID_VIRTUAL
#define GP_ASYNCIFY_PARANOID_PURE
#define GP_ASYNCIFY_PARANOID_OVERRIDE
#define GP_ASYNCIFY_PARANOID_NAMED(n) GpAsyncifyParanoid##n
#else
#define GP_ASYNCIFY_PARANOID_VIRTUAL virtual
#define GP_ASYNCIFY_PARANOID_PURE = 0
#define GP_ASYNCIFY_PARANOID_OVERRIDE override
#define GP_ASYNCIFY_PARANOID_NAMED(n) n
#endif

View File

@@ -1,11 +1,13 @@
#include "CFileStream.h"
#include "BMPFormat.h"
#include "GpAllocator_C.h"
#include "MMHandleBlock.h"
#include "ResourceCompiledTypeList.h"
#include "ResourceFile.h"
#include "SharedTypes.h"
#include "QDStandardPalette.h"
#include "PLBigEndian.h"
#include "PLDrivers.h"
#include <assert.h>
#include <string>
@@ -141,6 +143,9 @@ int main(int argc, const char **argv)
PortabilityLayer::CFileStream stream(f);
GpDriverCollection *drivers = PLDrivers::GetDriverCollection();
drivers->SetDriver<GpDriverIDs::kAlloc>(GpAllocator_C::GetInstance());
PortabilityLayer::ResourceFile *resFile = PortabilityLayer::ResourceFile::Create();
if (!resFile->Load(&stream))
return -1;

Some files were not shown because too many files have changed in this diff Show More