Added System.getTimer, moved file I/O into system, removed unused
This commit is contained in:
@@ -267,7 +267,11 @@ class Timer {
|
||||
|
||||
public static function stamp ():Float {
|
||||
|
||||
#if lime_legacy
|
||||
return lime_time_stamp ();
|
||||
#else
|
||||
return System.getTimer () / 1000;
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
@@ -294,6 +298,7 @@ class Timer {
|
||||
}
|
||||
|
||||
|
||||
#if lime_legacy
|
||||
@:noCompletion private function __check (inTime:Float) {
|
||||
|
||||
if (inTime >= mFireAt) {
|
||||
@@ -364,6 +369,7 @@ class Timer {
|
||||
return limit * 0.001;
|
||||
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
|
||||
@@ -373,9 +379,7 @@ class Timer {
|
||||
|
||||
|
||||
|
||||
#if !lime_legacy
|
||||
static var lime_time_stamp = System.load ("lime", "lime_system_get_timestamp", 0);
|
||||
#else
|
||||
#if lime_legacy
|
||||
static var lime_time_stamp = flash.Lib.load ("lime", "lime_time_stamp", 0);
|
||||
#end
|
||||
|
||||
|
||||
@@ -2,6 +2,12 @@ package lime.system;
|
||||
#if !macro
|
||||
|
||||
|
||||
#if flash
|
||||
import flash.Lib;
|
||||
#elseif (html5 || disable_cffi)
|
||||
import haxe.Timer;
|
||||
#end
|
||||
|
||||
#if (js && html5)
|
||||
import js.html.HtmlElement;
|
||||
import js.Browser;
|
||||
@@ -19,6 +25,9 @@ class System {
|
||||
|
||||
|
||||
@:noCompletion private static var __moduleNames:Map<String, String> = null;
|
||||
#if (!flash && (html5 || disable_cffi))
|
||||
@:noCompletion private static var __startTime:Float = Timer.stamp ();
|
||||
#end
|
||||
|
||||
#if neko
|
||||
private static var __loadedNekoAPI:Bool;
|
||||
@@ -134,6 +143,19 @@ class System {
|
||||
}
|
||||
|
||||
|
||||
public static function getTimer ():Int {
|
||||
|
||||
#if flash
|
||||
return flash.Lib.getTimer ();
|
||||
#elseif (html5 || disable_cffi)
|
||||
return Std.int ((System.getTimer () - __startTime) * 1000);
|
||||
#else
|
||||
return lime_system_gettimer ();
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function load (library:String, method:String, args:Int = 0, lazy:Bool = false):Dynamic {
|
||||
|
||||
#if disable_cffi
|
||||
@@ -368,6 +390,18 @@ class System {
|
||||
#end
|
||||
|
||||
|
||||
|
||||
|
||||
// Native Methods
|
||||
|
||||
|
||||
|
||||
|
||||
#if (cpp || neko || nodejs)
|
||||
private static var lime_system_gettimer = System.load ("lime", "lime_system_gettimer", 0);
|
||||
#end
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -133,24 +133,20 @@
|
||||
<file name="src/backend/sdl/SDLWindow.cpp" />
|
||||
<file name="src/backend/sdl/SDLRenderer.cpp" />
|
||||
<file name="src/backend/sdl/SDLMouse.cpp" />
|
||||
<file name="src/backend/sdl/SDLFileIO.cpp" />
|
||||
<file name="src/backend/sdl/SDLSystem.cpp" />
|
||||
|
||||
</section>
|
||||
|
||||
<file name="src/system/ios/System.mm" if="ios" />
|
||||
|
||||
<file name="src/app/UpdateEvent.cpp" />
|
||||
<file name="src/audio/format/WAV.cpp" />
|
||||
<file name="src/audio/AudioBuffer.cpp" />
|
||||
<file name="src/graphics/ImageBuffer.cpp" />
|
||||
<file name="src/graphics/RenderEvent.cpp" />
|
||||
<file name="src/system/System.cpp" />
|
||||
<file name="src/ui/KeyEvent.cpp" />
|
||||
<file name="src/ui/MouseEvent.cpp" />
|
||||
<file name="src/ui/TouchEvent.cpp" />
|
||||
<file name="src/ui/WindowEvent.cpp" />
|
||||
<file name="src/utils/ByteArray.cpp" />
|
||||
<file name="src/utils/FileIO.cpp" unless="LIME_SDL" />
|
||||
|
||||
</files>
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef LIME_SYSTEM_SYSTEM_H
|
||||
#define LIME_SYSTEM_SYSTEM_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
@@ -10,12 +12,35 @@ namespace lime {
|
||||
|
||||
public:
|
||||
|
||||
static double GetTimestamp ();
|
||||
static double GetTimer ();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct FILE_HANDLE {
|
||||
|
||||
void *handle;
|
||||
|
||||
FILE_HANDLE (void* handle) : handle (handle) {}
|
||||
|
||||
FILE* getFile ();
|
||||
int getLength ();
|
||||
bool isFile ();
|
||||
|
||||
};
|
||||
|
||||
|
||||
extern int fclose (FILE_HANDLE *stream);
|
||||
extern FILE_HANDLE *fdopen (int fd, const char *mode);
|
||||
extern FILE_HANDLE *fopen (const char *filename, const char *mode);
|
||||
//extern FILE* freopen (const char *filename, const char *mode, FILE *stream);
|
||||
extern size_t fread (void *ptr, size_t size, size_t count, FILE_HANDLE *stream);
|
||||
extern int fseek (FILE_HANDLE *stream, long int offset, int origin);
|
||||
extern long int ftell (FILE_HANDLE *stream);
|
||||
extern size_t fwrite (const void *ptr, size_t size, size_t count, FILE_HANDLE *stream);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef LIME_UTILS_FILEIO_H
|
||||
#define LIME_UTILS_FILEIO_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
struct FILE_HANDLE {
|
||||
|
||||
void *handle;
|
||||
|
||||
FILE_HANDLE (void* handle) : handle (handle) {}
|
||||
|
||||
FILE* getFile ();
|
||||
int getLength ();
|
||||
bool isFile ();
|
||||
|
||||
};
|
||||
|
||||
extern int fclose (FILE_HANDLE *stream);
|
||||
extern FILE_HANDLE *fdopen (int fd, const char *mode);
|
||||
extern FILE_HANDLE *fopen (const char *filename, const char *mode);
|
||||
//extern FILE* freopen (const char *filename, const char *mode, FILE *stream);
|
||||
extern size_t fread (void *ptr, size_t size, size_t count, FILE_HANDLE *stream);
|
||||
extern int fseek (FILE_HANDLE *stream, long int offset, int origin);
|
||||
extern long int ftell (FILE_HANDLE *stream);
|
||||
extern size_t fwrite (const void *ptr, size_t size, size_t count, FILE_HANDLE *stream);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -398,9 +398,9 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_system_get_timestamp () {
|
||||
value lime_system_gettimer () {
|
||||
|
||||
return alloc_float (System::GetTimestamp ());
|
||||
return alloc_float (System::GetTimer ());
|
||||
|
||||
}
|
||||
|
||||
@@ -542,7 +542,7 @@ namespace lime {
|
||||
DEFINE_PRIM (lime_renderer_create, 1);
|
||||
DEFINE_PRIM (lime_renderer_flip, 1);
|
||||
DEFINE_PRIM (lime_render_event_manager_register, 2);
|
||||
DEFINE_PRIM (lime_system_get_timestamp, 0);
|
||||
DEFINE_PRIM (lime_system_gettimer, 0);
|
||||
DEFINE_PRIM (lime_text_create, 3);
|
||||
DEFINE_PRIM (lime_text_from_string, 4);
|
||||
DEFINE_PRIM (lime_touch_event_manager_register, 2);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <audio/format/OGG.h>
|
||||
#include <utils/FileIO.h>
|
||||
#include <system/System.h>
|
||||
#include <vorbis/vorbisfile.h>
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <audio/format/WAV.h>
|
||||
#include <utils/FileIO.h>
|
||||
#include <system/System.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
#include <utils/FileIO.h>
|
||||
#include <system/System.h>
|
||||
|
||||
#ifdef HX_MACOS
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
#include <SDL_rwops.h>
|
||||
#include <SDL_timer.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
double System::GetTimer () {
|
||||
|
||||
return SDL_GetTicks ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
FILE* FILE_HANDLE::getFile () {
|
||||
|
||||
if (((SDL_RWops*)handle)->type == SDL_RWOPS_STDFILE) {
|
||||
@@ -8,7 +8,7 @@ extern "C" {
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <graphics/format/JPEG.h>
|
||||
#include <utils/FileIO.h>
|
||||
#include <system/System.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
@@ -9,8 +9,8 @@ extern "C" {
|
||||
#include <setjmp.h>
|
||||
#include <graphics/format/PNG.h>
|
||||
#include <graphics/ImageBuffer.h>
|
||||
#include <system/System.h>
|
||||
#include <utils/ByteArray.h>
|
||||
#include <utils/FileIO.h>
|
||||
#include <utils/QuickVec.h>
|
||||
|
||||
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
#ifdef HX_WINDOWS
|
||||
|
||||
#include <windows.h>
|
||||
#include <Shlobj.h>
|
||||
#include <time.h>
|
||||
|
||||
#elif defined (EPPC)
|
||||
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef HX_LINUX
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifndef EMSCRIPTEN
|
||||
typedef uint64_t __int64;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HX_MACOS
|
||||
#include <mach/mach_time.h>
|
||||
#include <mach-o/dyld.h>
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#ifdef TIZEN
|
||||
#include <FSystem.h>
|
||||
#endif
|
||||
|
||||
#ifdef IPHONE
|
||||
#include <QuartzCore/QuartzCore.h>
|
||||
#endif
|
||||
|
||||
#include <system/System.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
double System::GetTimestamp () {
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
static __int64 t0 = 0;
|
||||
static double period = 0;
|
||||
__int64 now;
|
||||
|
||||
if (QueryPerformanceCounter ((LARGE_INTEGER*)&now)) {
|
||||
|
||||
if (t0 == 0) {
|
||||
|
||||
t0 = now;
|
||||
__int64 freq;
|
||||
QueryPerformanceFrequency ((LARGE_INTEGER*)&freq);
|
||||
|
||||
if (freq != 0)
|
||||
period = 1.0 / freq;
|
||||
|
||||
}
|
||||
|
||||
if (period != 0)
|
||||
return (now - t0) * period;
|
||||
|
||||
}
|
||||
|
||||
return (double)clock () / ((double)CLOCKS_PER_SEC);
|
||||
|
||||
#elif defined (HX_MACOS)
|
||||
|
||||
static double time_scale = 0.0;
|
||||
|
||||
if (time_scale == 0.0) {
|
||||
|
||||
mach_timebase_info_data_t info;
|
||||
mach_timebase_info (&info);
|
||||
time_scale = 1e-9 * (double)info.numer / info.denom;
|
||||
|
||||
}
|
||||
|
||||
double r = mach_absolute_time () * time_scale;
|
||||
return mach_absolute_time () * time_scale;
|
||||
|
||||
#else
|
||||
|
||||
static double t0 = 0;
|
||||
|
||||
#if defined (IPHONE)
|
||||
|
||||
double t = CACurrentMediaTime ();
|
||||
|
||||
#elif defined (GPH) || defined (HX_LINUX) || defined (EMSCRIPTEN)
|
||||
|
||||
struct timeval tv;
|
||||
if (gettimeofday (&tv, 0))
|
||||
return 0;
|
||||
double t = (tv.tv_sec + ((double)tv.tv_usec) / 1000000.0);
|
||||
|
||||
#elif defined (EPPC)
|
||||
|
||||
time_t tod;
|
||||
time (&tod);
|
||||
double t = (double)tod;
|
||||
|
||||
#else
|
||||
|
||||
struct timespec ts;
|
||||
clock_gettime (CLOCK_MONOTONIC, &ts);
|
||||
double t = (ts.tv_sec + ((double)ts.tv_nsec) * 1e-9);
|
||||
|
||||
#endif
|
||||
|
||||
if (t0 == 0) t0 = t;
|
||||
return t - t0;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <string>
|
||||
|
||||
namespace lime
|
||||
{
|
||||
|
||||
FILE *OpenRead(const char *inName)
|
||||
{
|
||||
FILE *result = 0;
|
||||
|
||||
if (inName[0]=='/')
|
||||
{
|
||||
result = fopen(inName,"rb");
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *assetPath = [@"assets" stringByAppendingPathComponent:[NSString stringWithFormat:@"%s", inName]];
|
||||
|
||||
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
|
||||
NSString *path = [resourcePath stringByAppendingPathComponent:assetPath];
|
||||
|
||||
// search in documents if not in the resource bundle
|
||||
if ( ! [[NSFileManager defaultManager] fileExistsAtPath:path])
|
||||
{
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *documentDir = [paths objectAtIndex:0];
|
||||
path = [documentDir stringByAppendingPathComponent:assetPath];
|
||||
}
|
||||
|
||||
result = fopen([path UTF8String],"rb");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
FILE *OpenOverwrite(const char *inName)
|
||||
{
|
||||
NSString *str = [@"assets" stringByAppendingPathComponent:[NSString stringWithFormat:@"%s", inName]];
|
||||
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||
NSString *documentDir = [paths objectAtIndex:0];
|
||||
NSString *path = [documentDir stringByAppendingPathComponent:str];
|
||||
|
||||
// create any directories if they don't exist
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:[path stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
|
||||
FILE * result = fopen([path UTF8String],"w");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
|
||||
#include <hx/CFFI.h>
|
||||
|
||||
#include <system/System.h>
|
||||
#include <utils/ByteArray.h>
|
||||
#include <utils/FileIO.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
#include <utils/FileIO.h>
|
||||
|
||||
#ifdef HX_MACOS
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
FILE* FILE_HANDLE::getFile () {
|
||||
|
||||
return (FILE*)handle;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int FILE_HANDLE::getLength () {
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool FILE_HANDLE::isFile () {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int fclose (FILE_HANDLE *stream) {
|
||||
|
||||
if (stream) {
|
||||
|
||||
int value = ::fclose ((FILE*)stream->handle);
|
||||
if (stream) delete stream;
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
FILE_HANDLE *fdopen (int fd, const char *mode) {
|
||||
|
||||
FILE* result = ::fdopen (fd, mode);
|
||||
|
||||
if (result) {
|
||||
|
||||
return new FILE_HANDLE (result);
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
FILE_HANDLE *fopen (const char *filename, const char *mode) {
|
||||
|
||||
FILE* result;
|
||||
#ifdef HX_MACOS
|
||||
result = ::fopen (filename, "rb");
|
||||
if (!result) {
|
||||
CFStringRef str = CFStringCreateWithCString (NULL, filename, kCFStringEncodingUTF8);
|
||||
CFURLRef path = CFBundleCopyResourceURL (CFBundleGetMainBundle (), str, NULL, NULL);
|
||||
CFRelease (str);
|
||||
if (path) {
|
||||
str = CFURLCopyPath (path);
|
||||
CFIndex maxSize = CFStringGetMaximumSizeForEncoding (CFStringGetLength (str), kCFStringEncodingUTF8);
|
||||
char *buffer = (char *)malloc (maxSize);
|
||||
if (CFStringGetCString (str, buffer, maxSize, kCFStringEncodingUTF8)) {
|
||||
result = ::fopen (buffer,"rb");
|
||||
free (buffer);
|
||||
}
|
||||
CFRelease (str);
|
||||
CFRelease (path);
|
||||
}
|
||||
}
|
||||
#else
|
||||
result = ::fopen (filename, mode);
|
||||
#endif
|
||||
|
||||
if (result) {
|
||||
|
||||
return new FILE_HANDLE (result);
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
size_t fread (void *ptr, size_t size, size_t count, FILE_HANDLE *stream) {
|
||||
|
||||
return ::fread (ptr, size, count, stream ? (FILE*)stream->handle : NULL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int fseek (FILE_HANDLE *stream, long int offset, int origin) {
|
||||
|
||||
return ::fseek (stream ? (FILE*)stream->handle : NULL, offset, origin);
|
||||
|
||||
}
|
||||
|
||||
|
||||
long int ftell (FILE_HANDLE *stream) {
|
||||
|
||||
return ::ftell (stream ? (FILE*)stream->handle : NULL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
size_t fwrite (const void *ptr, size_t size, size_t count, FILE_HANDLE *stream) {
|
||||
|
||||
return ::fwrite (ptr, size, count, (FILE*)stream->handle);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user