Skip to content

Commit

Permalink
More Android stub-outs and bug fixes. Fix broken SDL fiber sync.
Browse files Browse the repository at this point in the history
  • Loading branch information
elasota committed Oct 10, 2020
1 parent a2f19f5 commit 5c98783
Show file tree
Hide file tree
Showing 63 changed files with 1,445 additions and 635 deletions.
2 changes: 1 addition & 1 deletion Aerofoil/GpFiberStarter_Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace GpFiberStarter_Win32
}
}

IGpFiber *GpFiberStarter::StartFiber(ThreadFunc_t threadFunc, void *context, IGpFiber *creatingFiber)
IGpFiber *GpFiberStarter::StartFiber(PortabilityLayer::HostSystemServices *systemServices, ThreadFunc_t threadFunc, void *context, IGpFiber *creatingFiber)
{
ULONG_PTR lowLimit;
ULONG_PTR highLimit;
Expand Down
4 changes: 2 additions & 2 deletions Aerofoil/GpThreadEvent_Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ void GpThreadEvent_Win32::Wait()
WaitForSingleObject(m_event, INFINITE);
}

void GpThreadEvent_Win32::WaitTimed(uint32_t msec)
bool GpThreadEvent_Win32::WaitTimed(uint32_t msec)
{
WaitForSingleObject(m_event, static_cast<DWORD>(msec));
return WaitForSingleObject(m_event, static_cast<DWORD>(msec)) == WAIT_OBJECT_0;
}

void GpThreadEvent_Win32::Signal()
Expand Down
2 changes: 1 addition & 1 deletion Aerofoil/GpThreadEvent_Win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GpThreadEvent_Win32 final : public PortabilityLayer::HostThreadEvent
{
public:
void Wait() override;
void WaitTimed(uint32_t msec) override;
bool WaitTimed(uint32_t msec) override;
void Signal() override;
void Destroy() override;

Expand Down
12 changes: 12 additions & 0 deletions AerofoilAndroid/app/jni/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
AerofoilSDL
Common
FreeType
GpApp
GpCommon
GpFontHandler_FreeType2
GpShell
MacRomanConversion
PortabilityLayer
rapidjson
SDL2
stb
zlib
2 changes: 1 addition & 1 deletion AerofoilAndroid/app/jni/Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Uncomment this if you're using STL in your project
# You can find more information here:
# https://developer.android.com/ndk/guides/cpp-support
# APP_STL := c++_shared
APP_STL := c++_shared

APP_ABI := armeabi-v7a arm64-v8a x86 x86_64

Expand Down
16 changes: 14 additions & 2 deletions AerofoilAndroid/app/jni/main/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ LOCAL_MODULE := main

SDL_PATH := ../SDL

LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include \
$(LOCAL_PATH)/../GpShell \
$(LOCAL_PATH)/../GpCommon \
$(LOCAL_PATH)/../AerofoilSDL \
$(LOCAL_PATH)/../Common \
$(LOCAL_PATH)/../PortabilityLayer

LOCAL_CFLAGS := -DGP_DEBUG_CONFIG=0

# Add your application source files here...
LOCAL_SRC_FILES := YourSourceHere.c
LOCAL_SRC_FILES := \
GpMain_SDL_Android.cpp \
GpSystemServices_Android.cpp \
GpFileSystem_Android.cpp

LOCAL_SHARED_LIBRARIES := SDL2

LOCAL_STATIC_LIBRARIES := GpShell GpFontHandler_FreeType2 AerofoilSDL GpApp

LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog

include $(BUILD_SHARED_LIBRARY)
5 changes: 5 additions & 0 deletions AerofoilAndroid/app/jni/main/GpAndroid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

struct GpAndroidGlobals
{
};
84 changes: 84 additions & 0 deletions AerofoilAndroid/app/jni/main/GpFileSystem_Android.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include "GpFileSystem_Android.h"

GpFileSystem_Android::GpFileSystem_Android()
{
}

bool GpFileSystem_Android::FileExists(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path)
{
return false;
}

bool GpFileSystem_Android::FileLocked(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool *exists)
{
return false;
}

GpIOStream *GpFileSystem_Android::OpenFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool writeAccess, GpFileCreationDisposition_t createDisposition)
{
return nullptr;
}

bool GpFileSystem_Android::DeleteFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &existed)
{
existed = false;
return false;
}

PortabilityLayer::HostDirectoryCursor *GpFileSystem_Android::ScanDirectory(PortabilityLayer::VirtualDirectory_t virtualDirectory)
{
return nullptr;
}

bool GpFileSystem_Android::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 == '\'')
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_Android::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;
}

GpFileSystem_Android *GpFileSystem_Android::GetInstance()
{
return &ms_instance;
}

GpFileSystem_Android GpFileSystem_Android::ms_instance;
27 changes: 27 additions & 0 deletions AerofoilAndroid/app/jni/main/GpFileSystem_Android.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "HostFileSystem.h"

#include "GpCoreDefs.h"

class GpFileSystem_Android final : public PortabilityLayer::HostFileSystem
{
public:
GpFileSystem_Android();

bool FileExists(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path) override;
bool FileLocked(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool *exists) override;
GpIOStream *OpenFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool writeAccess, GpFileCreationDisposition_t createDisposition) override;
bool DeleteFile(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, bool &existed) override;
PortabilityLayer::HostDirectoryCursor *ScanDirectory(PortabilityLayer::VirtualDirectory_t virtualDirectory) override;

bool ValidateFilePath(const char *path, size_t sz) const override;
bool ValidateFilePathUnicodeChar(uint32_t ch) const override;

static GpFileSystem_Android *GetInstance();

private:
bool ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDirectory, const char *path, wchar_t *outPath);

static GpFileSystem_Android ms_instance;
};
15 changes: 4 additions & 11 deletions AerofoilAndroid/app/jni/main/GpMain_SDL_Android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "GpAudioDriverFactory.h"
#include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h"
#include "GpFiber_Win32.h"
#include "GpFiber_SDL.h"
#include "GpFileSystem_Android.h"
#include "GpFontHandlerFactory.h"
Expand All @@ -19,8 +18,6 @@

#include "GpAndroid.h"

#include "resource.h"

GpAndroidGlobals g_gpAndroidGlobals;

extern "C" IGpFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties);
Expand All @@ -29,17 +26,19 @@ IGpDisplayDriver *GpDriver_CreateDisplayDriver_SDL_GL2(const GpDisplayDriverProp
IGpAudioDriver *GpDriver_CreateAudioDriver_SDL(const GpAudioDriverProperties &properties);


int main(int argc, const char **argv)
int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return -1;

SDL_GL_LoadLibrary("libGLESv2.so");

GpAppInterface_Get()->PL_HostFileSystem_SetInstance(GpFileSystem_Android::GetInstance());
GpAppInterface_Get()->PL_HostSystemServices_SetInstance(GpSystemServices_Android::GetInstance());

g_gpGlobalConfig.m_displayDriverType = EGpDisplayDriverType_SDL_GL2;

g_gpGlobalConfig.m_audioDriverType = EGpAudioDriverType_SDL2;
g_gpGlobalConfig.m_audioDriverType = EGpAudioDriverType_None;

g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_FreeType2;

Expand All @@ -54,13 +53,7 @@ int main(int argc, const char **argv)
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL);
GpFontHandlerFactory::RegisterFontHandlerFactory(EGpFontHandlerType_FreeType2, GpDriver_CreateFontHandler_FreeType2);

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;
}
Loading

0 comments on commit 5c98783

Please sign in to comment.