From 04e6bf198d0af98590a4c411a71ba3fa2d772cc2 Mon Sep 17 00:00:00 2001 From: XProger Date: Sun, 13 Jan 2019 03:46:21 +0300 Subject: [PATCH] #15 NX custom directory support, relative time from game starts --- src/platform/nx/Makefile | 6 +++--- src/platform/nx/main.cpp | 41 +++++++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/platform/nx/Makefile b/src/platform/nx/Makefile index 56c6cb6..55d09eb 100644 --- a/src/platform/nx/Makefile +++ b/src/platform/nx/Makefile @@ -46,15 +46,15 @@ APP_VERSION := 1.0 #--------------------------------------------------------------------------------- ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -mcpu=cortex-a57+crc+fp+simd -CFLAGS := -g -O -ffast-math -fno-strict-aliasing -fomit-frame-pointer -ffunction-sections \ +CFLAGS := -O3 -ffast-math -fno-strict-aliasing -fomit-frame-pointer -ffunction-sections \ $(ARCH) $(DEFINES) CFLAGS += $(INCLUDE) -D__SWITCH__ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 -ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) +ASFLAGS := $(ARCH) +LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs $(ARCH) -Wl,-Map,$(notdir $*.map) LIBS := -lEGL -lGLESv2 -lglapi -ldrm_nouveau -lnx -lm diff --git a/src/platform/nx/main.cpp b/src/platform/nx/main.cpp index 9552811..f5ad484 100644 --- a/src/platform/nx/main.cpp +++ b/src/platform/nx/main.cpp @@ -25,11 +25,11 @@ void osMutexUnlock(void *obj) { } // timing -unsigned int startTime; +u64 startTick; int osGetTime() { u64 tick = armGetSystemTick(); - return (tick * 625 / 12) / 1000000; + return int(((tick - startTick) * 625 / 12) / 1000000); } // sound @@ -286,6 +286,34 @@ void touchUpdate() { } } +void makeCacheDir(char *elfPath) { + char buf[255]; + int len = strlen(elfPath); + int start = 0; + strcpy(buf, elfPath); + + // skip volume id + for (int i = 0; i < len; i++) { + if (buf[i] == ':') { + start = i + 1; + break; + } + } + + // skip executable name + for (int i = len - 1; i >= 0; i--) { + if (buf[i] == '/') { + buf[i] = 0; + break; + } + } + + // make directory by full path + strcpy(cacheDir, buf + start); + strcat(cacheDir, "/cache/"); + fsFsCreateDirectory(fsdevGetDefaultFileSystem(), cacheDir); +} + int main(int argc, char* argv[]) { Core::width = 1280; Core::height = 720; @@ -296,14 +324,9 @@ int main(int argc, char* argv[]) { } cacheDir[0] = saveDir[0] = contentDir[0] = 0; + makeCacheDir(argv[0]); - strcat(contentDir, "/switch/OpenLara/"); - strcat(cacheDir, "/switch/OpenLara/cache/"); - strcat(saveDir, "/switch/OpenLara/"); - - fsFsCreateDirectory(fsdevGetDefaultFileSystem(), cacheDir); - - startTime = osGetTime(); + startTick = armGetSystemTick(); sndInit(); joyInit();