Skip to content

Commit

Permalink
Merge pull request #122 from ConfettiFX/confetti-dev
Browse files Browse the repository at this point in the history
Release 1.30 - June 28th, 2019 - Ephemeris 2 - New Skydome System | Android Unit Tests | New Entity Component System | SoLoud Audio
  • Loading branch information
wolfgangfengel authored Jun 29, 2019
2 parents efb6c19 + f8a92c9 commit f43a2fe
Show file tree
Hide file tree
Showing 648 changed files with 58,454 additions and 12,849 deletions.
142 changes: 128 additions & 14 deletions Common_3/OS/Android/AndroidBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@

#include "../Input/InputSystem.h"
#include "../Input/InputMappings.h"
#include "../Interfaces/IMemoryManager.h"
#include "AndroidFileSystem.cpp"
#include "../Interfaces/IMemoryManager.h"

#define CONFETTI_WINDOW_CLASS L"confetti"
#define MAX_KEYS 256
Expand Down Expand Up @@ -111,6 +111,19 @@ int64_t getTimerFrequency()

static IApp* pApp = NULL;

struct DisplayMetrics
{
uint32_t widthPixels;
uint32_t heightPixels;
float density;
uint32_t densityDpi;
float scaledDensity;
float xdpi;
float ydpi;
};

DisplayMetrics metrics = {};

static void onResize(const WindowResizeEventData* pData)
{
pApp->mSettings.mWidth = getRectWidth(pData->rect);
Expand All @@ -123,12 +136,111 @@ static void onResize(const WindowResizeEventData* pData)
float2 getDpiScale()
{
float2 ret = {};
ret.x = 1.0f;
ret.y = 1.0f;
ret.x = metrics.scaledDensity;
ret.y = metrics.scaledDensity;

return ret;
}

float getDensity()
{
return metrics.density;
}

void getDisplayMetrics(struct android_app* _android_app, DisplayMetrics& metrics, RectDesc& rect)
{
if (!_android_app || !_android_app->activity || !_android_app->activity->vm )
return;

JNIEnv* jni = 0;
_android_app->activity->vm->AttachCurrentThread(&jni, NULL);
if (!jni )
return;

// get all the classes we want to access from the JVM
jclass classNativeActivity = jni->FindClass("android/app/NativeActivity");
jclass classWindowManager = jni->FindClass("android/view/WindowManager");
jclass classDisplay = jni->FindClass("android/view/Display");
jclass classDisplayMetrics = jni->FindClass("android/util/DisplayMetrics");

if (!classNativeActivity || !classWindowManager || !classDisplay || !classDisplayMetrics)
{
_android_app->activity->vm->DetachCurrentThread();
return;
}

// Get all the methods we want to access from the JVM classes
// Note: You can get the signatures (third parameter of GetMethodID) for all
// functions of a class with the javap tool, like in the following example for class DisplayMetrics:
// javap -s -classpath myandroidpath/adt-bundle-linux-x86_64-20131030/sdk/platforms/android-10/android.jar android/util/DisplayMetrics
jmethodID idNativeActivity_getWindowManager = jni->GetMethodID( classNativeActivity
, "getWindowManager"
, "()Landroid/view/WindowManager;");
jmethodID idWindowManager_getDefaultDisplay = jni->GetMethodID( classWindowManager
, "getDefaultDisplay"
, "()Landroid/view/Display;");
jmethodID idDisplayMetrics_constructor = jni->GetMethodID( classDisplayMetrics
, "<init>"
, "()V");
jmethodID idDisplay_getMetrics = jni->GetMethodID( classDisplay
, "getMetrics"
, "(Landroid/util/DisplayMetrics;)V");

if (!idNativeActivity_getWindowManager || !idWindowManager_getDefaultDisplay || !idDisplayMetrics_constructor
|| !idDisplay_getMetrics)
{
_android_app->activity->vm->DetachCurrentThread();
return;
}

jobject windowManager = jni->CallObjectMethod(_android_app->activity->clazz, idNativeActivity_getWindowManager);

if (!windowManager)
{
_android_app->activity->vm->DetachCurrentThread();
return;
}
jobject display = jni->CallObjectMethod(windowManager, idWindowManager_getDefaultDisplay);
if (!display)
{
_android_app->activity->vm->DetachCurrentThread();
return;
}
jobject displayMetrics = jni->NewObject( classDisplayMetrics, idDisplayMetrics_constructor);
if (!displayMetrics)
{
_android_app->activity->vm->DetachCurrentThread();
return;
}
jni->CallVoidMethod(display, idDisplay_getMetrics, displayMetrics);

// access the fields of DisplayMetrics (we ignore the DENSITY constants)
jfieldID idDisplayMetrics_widthPixels = jni->GetFieldID( classDisplayMetrics, "widthPixels", "I");
jfieldID idDisplayMetrics_heightPixels = jni->GetFieldID( classDisplayMetrics, "heightPixels", "I");
jfieldID idDisplayMetrics_density = jni->GetFieldID( classDisplayMetrics, "density", "F");
jfieldID idDisplayMetrics_densityDpi = jni->GetFieldID( classDisplayMetrics, "densityDpi", "I");
jfieldID idDisplayMetrics_scaledDensity = jni->GetFieldID( classDisplayMetrics, "scaledDensity", "F");
jfieldID idDisplayMetrics_xdpi = jni->GetFieldID(classDisplayMetrics, "xdpi", "F");
jfieldID idDisplayMetrics_ydpi = jni->GetFieldID(classDisplayMetrics, "ydpi", "F");

if ( idDisplayMetrics_widthPixels )
metrics.widthPixels = jni->GetIntField(displayMetrics, idDisplayMetrics_widthPixels);
if ( idDisplayMetrics_heightPixels )
metrics.heightPixels = jni->GetIntField(displayMetrics, idDisplayMetrics_heightPixels);
if (idDisplayMetrics_density )
metrics.density = jni->GetFloatField(displayMetrics, idDisplayMetrics_density);
if (idDisplayMetrics_densityDpi)
metrics.densityDpi = jni->GetIntField(displayMetrics, idDisplayMetrics_densityDpi);
if (idDisplayMetrics_scaledDensity)
metrics.scaledDensity = jni->GetFloatField(displayMetrics, idDisplayMetrics_scaledDensity);
if ( idDisplayMetrics_xdpi )
metrics.xdpi = jni->GetFloatField(displayMetrics, idDisplayMetrics_xdpi);
if ( idDisplayMetrics_ydpi )
metrics.ydpi = jni->GetFloatField(displayMetrics, idDisplayMetrics_ydpi);

_android_app->activity->vm->DetachCurrentThread();
}

void openWindow(const char* app_name, WindowsDesc* winDesc) {}

void handleMessages(WindowsDesc* winDesc) { return; }
Expand Down Expand Up @@ -222,7 +334,7 @@ int AndroidMain(void* param, IApp* app)
struct android_app* android_app = (struct android_app*)param;

// Set the callback to process system events
android_app->onAppCmd = handle_cmd;
android_app->onAppCmd = handle_cmd;

pApp = app;

Expand All @@ -238,25 +350,27 @@ int AndroidMain(void* param, IApp* app)
FileSystem::SetCurrentDir(FileSystem::GetProgramDir());

IApp::Settings* pSettings = &pApp->mSettings;

if (!pApp->Init())
abort();

InputSystem::Init(pSettings->mWidth, pSettings->mHeight);
// Set the callback to process input events
android_app->onInputEvent = handle_input;

InputSystem::SetMouseCapture(true);

Timer deltaTimer;
if (pSettings->mWidth == -1 || pSettings->mHeight == -1)
{
RectDesc rect = {};
getRecommendedResolution(&rect);
pSettings->mWidth = getRectWidth(rect);
pSettings->mHeight = getRectHeight(rect);
getDisplayMetrics(android_app, metrics, rect);
}

InputSystem::Init(pSettings->mWidth, pSettings->mHeight);
InputSystem::SetMouseCapture(true);
InputSystem::SetHideMouseCursorWhileCaptured(false);
// Set the callback to process input events
android_app->onInputEvent = handle_input;

if (!pApp->Init())
abort();

InputSystem::SetMouseCapture(true);

registerWindowResizeEvent(onResize);

bool quit = false;
Expand Down
29 changes: 27 additions & 2 deletions Common_3/OS/Android/AndroidFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#include "../Interfaces/IFileSystem.h"
#include "../Interfaces/ILogManager.h"
#include "../Interfaces/IOperatingSystem.h"
#include "../Interfaces/IMemoryManager.h"
#include <unistd.h>
#include <android/asset_manager.h>
#include "../Interfaces/IMemoryManager.h"
#define MAX_PATH PATH_MAX

#define RESOURCE_DIR "Shaders"
Expand All @@ -41,6 +41,7 @@ const char* pszRoots[FSR_Count] = {
"Fonts/", // FSR_Builtin_Fonts
"GPUCfg/", // FSR_GpuConfig
"Animation/", // FSR_Animation
"Audio/", // FSR_Audio
"", // FSR_OtherFiles
};

Expand All @@ -60,7 +61,8 @@ FileHandle open_file(const char* filename, const char* flags)
AAsset* file = AAssetManager_open(_mgr,
filename, AASSET_MODE_BUFFER);

if(_mgr == NULL) return NULL;
if(file == NULL)
return NULL;

return reinterpret_cast<void*>(file);
}
Expand All @@ -71,6 +73,29 @@ bool close_file(FileHandle handle)
return true;
}

bool anDirExists(const char* path)
{
AAssetDir* assetDir = AAssetManager_openDir(_mgr, path );
bool exist = AAssetDir_getNextFileName(assetDir) != NULL;
AAssetDir_close( assetDir );
return exist;
}

void get_files_with_extension(const char* dir, const char* ext, eastl::vector<eastl::string>& filesOut)
{
AAssetDir* assetDir = AAssetManager_openDir(_mgr, dir);
const char* fileName = (const char*)NULL;
while ((fileName = AAssetDir_getNextFileName(assetDir)) != NULL) {
const char* p = strstr(fileName, ext);
if(p)
{
filesOut.push_back(dir + eastl::string(fileName));
}
}
AAssetDir_close(assetDir);
}


void flush_file(FileHandle handle)
{
LOGF(LogLevel::eERROR, "FileSystem::Flush not supported on Android!");
Expand Down
2 changes: 1 addition & 1 deletion Common_3/OS/Android/AndroidLogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

// interfaces
#include "../Interfaces/ILogManager.h"
#include "../Interfaces/IMemoryManager.h"
#include <assert.h>
#include "../Interfaces/IMemoryManager.h"

void outputLogString(const char* pszStr)
{
Expand Down
2 changes: 1 addition & 1 deletion Common_3/OS/Android/AndroidThreadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#include "../Interfaces/IThread.h"
#include "../Interfaces/IOperatingSystem.h"
#include "../Interfaces/ILogManager.h"
#include "../Interfaces/IMemoryManager.h"

#include <pthread.h>
#include <unistd.h>
#include "../Interfaces/IMemoryManager.h"

AtomicUint::AtomicUint()
{
Expand Down
38 changes: 26 additions & 12 deletions Common_3/OS/Core/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include "../Interfaces/IFileSystem.h"
#include "../Interfaces/ILogManager.h"
#include "../Interfaces/IMemoryManager.h"

#ifdef __APPLE__
#include <unistd.h>
Expand All @@ -38,14 +37,15 @@
#include <stdio.h>
#include <stdlib.h>
#endif
#ifdef __linux__
#if defined(__linux__)
#include <unistd.h>
#include <limits.h> // for UINT_MAX
#include <sys/stat.h> // for mkdir
#include <sys/errno.h> // for errno
#include <sys/wait.h>
#include <dirent.h>
#endif
#include "../Interfaces/IMemoryManager.h"

void translateFileAccessFlags(FileMode modeFlags, char* fileAccesString, int strLength)
{
Expand Down Expand Up @@ -604,11 +604,23 @@ unsigned MemoryBuffer::Read(void* dest, unsigned size)

unsigned MemoryBuffer::Seek(unsigned position, SeekDir seekDir /* = SeekDir::SEEK_DIR_BEGIN*/)
{
UNREF_PARAM(seekDir);
if (position > mSize)
position = mSize;
position = (mSize - 1);

mPosition = position;
switch (seekDir)
{
case SEEK_DIR_BEGIN:
mPosition = position;
break;
case SEEK_DIR_CUR:
mPosition += position;
break;
case SEEK_DIR_END:
mPosition = mSize - 1 - position;
break;
default:
break;
}
return mPosition;
}

Expand Down Expand Up @@ -683,7 +695,7 @@ bool FileSystem::FileExists(const eastl::string& _fileName, FSRoot _root)
#ifdef _DURANGO
return (fopen(fileName.c_str(), "rb") != NULL);
#else
return ((access(fileName.c_str(), 0)) != -1);
return ((access(fileName.c_str(), 0)) != -1);
#endif
}

Expand Down Expand Up @@ -1007,15 +1019,17 @@ int FileSystem::SystemRun(const eastl::string& fileName, const eastl::vector<eas
int res = system(cmd.c_str());
return res;
#else

// NOTE: do not use eastl in the forked process! It will use unsafe functions (such as malloc) which will hang the whole thing
eastl::vector<const char*> argPtrs;
argPtrs.push_back(fixedFileName.c_str());
for (unsigned i = 0; i < (unsigned)arguments.size(); ++i)
argPtrs.push_back(arguments[i].c_str());
argPtrs.push_back(NULL);

pid_t pid = fork();
if (!pid)
{
eastl::vector<const char*> argPtrs;
argPtrs.push_back(fixedFileName.c_str());
for (unsigned i = 0; i < (unsigned)arguments.size(); ++i)
argPtrs.push_back(arguments[i].c_str());
argPtrs.push_back(NULL);

execvp(argPtrs[0], (char**)&argPtrs[0]);
return -1; // Return -1 if we could not spawn the process
}
Expand Down
5 changes: 4 additions & 1 deletion Common_3/OS/Core/RingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
#include "../../Renderer/IRenderer.h"
#include "../../Renderer/ResourceLoader.h"
#include "../Interfaces/ILogManager.h"
#include "../Interfaces/IMemoryManager.h"

#define MEM_MANAGER_FROM_HEADER
#include "../../OS/Interfaces/IMemoryManager.h"

/************************************************************************/
/* RING BUFFER MANAGEMENT */
/************************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions Common_3/OS/Core/ThreadSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

#include "../Interfaces/IThread.h"
#include "../Interfaces/ILogManager.h"
#include "../Interfaces/IMemoryManager.h"

#include "ThreadSystem.h"
#include "../Interfaces/IMemoryManager.h"

struct ThreadedTask
{
Expand Down Expand Up @@ -92,7 +92,7 @@ static void taskThreadFunc(void* pThreadData)

void initThreadSystem(ThreadSystem** ppThreadSystem)
{
ThreadSystem* pThreadSystem = conf_new<ThreadSystem>();
ThreadSystem* pThreadSystem = conf_new(ThreadSystem);

uint32_t numThreads = max<uint32_t>(Thread::GetNumCPUCores() - 1, 1);
uint32_t numLoaders = min<uint32_t>(numThreads, MAX_LOAD_THREADS);
Expand Down
Loading

0 comments on commit f43a2fe

Please sign in to comment.