new lua API: platform
you can get current OS / build information, exe name, restart tpt, open a link in the web browser, and use clipboard copy/paste functions Also remove some older Platform.h file which wasn't really needed or used
This commit is contained in:
parent
282d1fbf0c
commit
9048a3c50e
@ -179,6 +179,15 @@
|
|||||||
#define TH_ENTRY_POINT
|
#define TH_ENTRY_POINT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// old Platform.h stuff, maybe we should have a file for these kinds of things
|
||||||
|
typedef unsigned short Uint16;
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
# define NULL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
#define SDEUT
|
#define SDEUT
|
||||||
//#define REALHEAT
|
//#define REALHEAT
|
||||||
|
|
||||||
|
130
src/Misc.cpp
130
src/Misc.cpp
@ -1,5 +1,4 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sstream>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -7,62 +6,6 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
#include "icondoc.h"
|
#include "icondoc.h"
|
||||||
#ifdef WIN
|
|
||||||
#include <shlobj.h>
|
|
||||||
#include <shlwapi.h>
|
|
||||||
#include <windows.h>
|
|
||||||
#else
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#endif
|
|
||||||
#ifdef MACOSX
|
|
||||||
#include <mach-o/dyld.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *exe_name(void)
|
|
||||||
{
|
|
||||||
#if defined(WIN)
|
|
||||||
char *name= (char *)malloc(64);
|
|
||||||
DWORD max=64, res;
|
|
||||||
while ((res = GetModuleFileName(NULL, name, max)) >= max)
|
|
||||||
{
|
|
||||||
#elif defined MACOSX
|
|
||||||
char *fn=(char*)malloc(64),*name=(char*)malloc(PATH_MAX);
|
|
||||||
uint32_t max=64, res;
|
|
||||||
if (_NSGetExecutablePath(fn, &max) != 0)
|
|
||||||
{
|
|
||||||
fn = (char*)realloc(fn, max);
|
|
||||||
_NSGetExecutablePath(fn, &max);
|
|
||||||
}
|
|
||||||
if (realpath(fn, name) == NULL)
|
|
||||||
{
|
|
||||||
free(fn);
|
|
||||||
free(name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
res = 1;
|
|
||||||
#else
|
|
||||||
char fn[64], *name=(char *)malloc(64);
|
|
||||||
size_t max=64, res;
|
|
||||||
sprintf(fn, "/proc/self/exe");
|
|
||||||
memset(name, 0, max);
|
|
||||||
while ((res = readlink(fn, name, max)) >= max-1)
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
#ifndef MACOSX
|
|
||||||
max *= 2;
|
|
||||||
name = (char *)realloc(name, max);
|
|
||||||
memset(name, 0, max);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (res <= 0)
|
|
||||||
{
|
|
||||||
free(name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Signum function
|
//Signum function
|
||||||
int isign(float i) //TODO: INline or macro
|
int isign(float i) //TODO: INline or macro
|
||||||
@ -217,34 +160,6 @@ void *file_load(char *fn, int *size)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cpu_check(void)
|
|
||||||
{
|
|
||||||
/*#ifdef MACOSX
|
|
||||||
return 0;
|
|
||||||
#else
|
|
||||||
#ifdef X86
|
|
||||||
unsigned af,bf,cf,df;
|
|
||||||
x86_cpuid(0, af, bf, cf, df);
|
|
||||||
//if (bf==0x68747541 && cf==0x444D4163 && df==0x69746E65)
|
|
||||||
// amd = 1;
|
|
||||||
x86_cpuid(1, af, bf, cf, df);
|
|
||||||
#ifdef X86_SSE
|
|
||||||
if (!(df&(1<<25)))
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
#ifdef X86_SSE2
|
|
||||||
if (!(df&(1<<26)))
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
#ifdef X86_SSE3
|
|
||||||
if (!(cf&1))
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif*/
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
matrix2d m2d_multiply_m2d(matrix2d m1, matrix2d m2)
|
matrix2d m2d_multiply_m2d(matrix2d m1, matrix2d m2)
|
||||||
{
|
{
|
||||||
matrix2d result = {
|
matrix2d result = {
|
||||||
@ -352,24 +267,6 @@ void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b)//convert 0-255(0-360 for
|
|||||||
*b += m;
|
*b += m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenURI(std::string uri) {
|
|
||||||
#if defined(WIN)
|
|
||||||
ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0);
|
|
||||||
#elif defined(MACOSX)
|
|
||||||
char *cmd = (char*)malloc(7+uri.length());
|
|
||||||
strcpy(cmd, "open ");
|
|
||||||
strappend(cmd, (char*)uri.c_str());
|
|
||||||
system(cmd);
|
|
||||||
#elif defined(LIN)
|
|
||||||
char *cmd = (char*)malloc(11+uri.length());
|
|
||||||
strcpy(cmd, "xdg-open ");
|
|
||||||
strappend(cmd, (char*)uri.c_str());
|
|
||||||
system(cmd);
|
|
||||||
#else
|
|
||||||
printf("Cannot open browser\n");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 RGB values to 0-255(0-360 for H) HSV
|
void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 RGB values to 0-255(0-360 for H) HSV
|
||||||
{
|
{
|
||||||
float rr, gg, bb, a,x,c,d;
|
float rr, gg, bb, a,x,c,d;
|
||||||
@ -406,32 +303,5 @@ void membwand(void * destv, void * srcv, size_t destsize, size_t srcsize)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void millisleep(long int t)
|
|
||||||
{
|
|
||||||
#ifdef WIN
|
|
||||||
Sleep(t);
|
|
||||||
#else
|
|
||||||
struct timespec s;
|
|
||||||
s.tv_sec = t / 1000;
|
|
||||||
s.tv_nsec = (t % 1000) * 10000000;
|
|
||||||
nanosleep(&s, NULL);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
long unsigned int gettime()
|
|
||||||
{
|
|
||||||
#ifdef WIN
|
|
||||||
return GetTickCount();
|
|
||||||
#elif defined(MACOSX)
|
|
||||||
struct timeval s;
|
|
||||||
gettimeofday(&s, NULL);
|
|
||||||
return (unsigned int)(s.tv_sec * 1000 + s.tv_usec / 1000);
|
|
||||||
#else
|
|
||||||
struct timespec s;
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &s);
|
|
||||||
return s.tv_sec * 1000 + s.tv_nsec / 1000000;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
vector2d v2d_zero = {0,0};
|
vector2d v2d_zero = {0,0};
|
||||||
matrix2d m2d_identity = {1,0,0,1};
|
matrix2d m2d_identity = {1,0,0,1};
|
||||||
|
10
src/Misc.h
10
src/Misc.h
@ -22,8 +22,6 @@ __asm__ __volatile ("cpuid":\
|
|||||||
"=a" (af), "=b" (bf), "=c" (cf), "=d" (df) : "a" (func));
|
"=a" (af), "=b" (bf), "=c" (cf), "=d" (df) : "a" (func));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *exe_name(void);
|
|
||||||
|
|
||||||
//Linear interpolation
|
//Linear interpolation
|
||||||
template <typename T> inline T LinearInterpolate(T val1, T val2, T lowerCoord, T upperCoord, T coord)
|
template <typename T> inline T LinearInterpolate(T val1, T val2, T lowerCoord, T upperCoord, T coord)
|
||||||
{
|
{
|
||||||
@ -68,20 +66,12 @@ void *file_load(char *fn, int *size);
|
|||||||
|
|
||||||
extern char *clipboard_text;
|
extern char *clipboard_text;
|
||||||
|
|
||||||
int cpu_check(void);
|
|
||||||
|
|
||||||
void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b);
|
void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b);
|
||||||
|
|
||||||
void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v);
|
void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v);
|
||||||
|
|
||||||
void OpenURI(std::string uri);
|
|
||||||
|
|
||||||
void membwand(void * dest, void * src, size_t destsize, size_t srcsize);
|
void membwand(void * dest, void * src, size_t destsize, size_t srcsize);
|
||||||
|
|
||||||
void millisleep(long int t);
|
|
||||||
|
|
||||||
long unsigned int gettime();
|
|
||||||
|
|
||||||
// a b
|
// a b
|
||||||
// c d
|
// c d
|
||||||
|
|
||||||
|
127
src/Platform.cpp
Normal file
127
src/Platform.cpp
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cstdio>
|
||||||
|
#ifdef WIN
|
||||||
|
#include <shlobj.h>
|
||||||
|
#include <shlwapi.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
#ifdef MACOSX
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
|
#endif
|
||||||
|
#include "Platform.h"
|
||||||
|
#include "Misc.h"
|
||||||
|
|
||||||
|
namespace Platform
|
||||||
|
{
|
||||||
|
|
||||||
|
char *ExecutableName(void)
|
||||||
|
{
|
||||||
|
#if defined(WIN)
|
||||||
|
char *name = (char *)malloc(64);
|
||||||
|
DWORD max = 64, res;
|
||||||
|
while ((res = GetModuleFileName(NULL, name, max)) >= max)
|
||||||
|
{
|
||||||
|
#elif defined MACOSX
|
||||||
|
char *fn = (char*)malloc(64),*name = (char*)malloc(PATH_MAX);
|
||||||
|
uint32_t max = 64, res;
|
||||||
|
if (_NSGetExecutablePath(fn, &max) != 0)
|
||||||
|
{
|
||||||
|
fn = (char*)realloc(fn, max);
|
||||||
|
_NSGetExecutablePath(fn, &max);
|
||||||
|
}
|
||||||
|
if (realpath(fn, name) == NULL)
|
||||||
|
{
|
||||||
|
free(fn);
|
||||||
|
free(name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
res = 1;
|
||||||
|
#else
|
||||||
|
char fn[64], *name = (char *)malloc(64);
|
||||||
|
size_t max = 64, res;
|
||||||
|
sprintf(fn, "/proc/self/exe");
|
||||||
|
memset(name, 0, max);
|
||||||
|
while ((res = readlink(fn, name, max)) >= max-1)
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
#ifndef MACOSX
|
||||||
|
max *= 2;
|
||||||
|
name = (char *)realloc(name, max);
|
||||||
|
memset(name, 0, max);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (res <= 0)
|
||||||
|
{
|
||||||
|
free(name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoRestart()
|
||||||
|
{
|
||||||
|
char *exename = ExecutableName();
|
||||||
|
if (exename)
|
||||||
|
{
|
||||||
|
#ifdef WIN
|
||||||
|
ShellExecute(NULL, "open", exename, NULL, NULL, SW_SHOWNORMAL);
|
||||||
|
#elif defined(LIN) || defined(MACOSX)
|
||||||
|
execl(exename, "powder", NULL);
|
||||||
|
#endif
|
||||||
|
free(exename);
|
||||||
|
}
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenURI(std::string uri)
|
||||||
|
{
|
||||||
|
#if defined(WIN)
|
||||||
|
ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0);
|
||||||
|
#elif defined(MACOSX)
|
||||||
|
char *cmd = (char*)malloc(7+uri.length());
|
||||||
|
strcpy(cmd, "open ");
|
||||||
|
strappend(cmd, (char*)uri.c_str());
|
||||||
|
system(cmd);
|
||||||
|
#elif defined(LIN)
|
||||||
|
char *cmd = (char*)malloc(11+uri.length());
|
||||||
|
strcpy(cmd, "xdg-open ");
|
||||||
|
strappend(cmd, (char*)uri.c_str());
|
||||||
|
system(cmd);
|
||||||
|
#else
|
||||||
|
printf("Cannot open browser\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void Millisleep(long int t)
|
||||||
|
{
|
||||||
|
#ifdef WIN
|
||||||
|
Sleep(t);
|
||||||
|
#else
|
||||||
|
struct timespec s;
|
||||||
|
s.tv_sec = t / 1000;
|
||||||
|
s.tv_nsec = (t % 1000) * 10000000;
|
||||||
|
nanosleep(&s, NULL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
long unsigned int GetTime()
|
||||||
|
{
|
||||||
|
#ifdef WIN
|
||||||
|
return GetTickCount();
|
||||||
|
#elif defined(MACOSX)
|
||||||
|
struct timeval s;
|
||||||
|
gettimeofday(&s, NULL);
|
||||||
|
return (unsigned int)(s.tv_sec * 1000 + s.tv_usec / 1000);
|
||||||
|
#else
|
||||||
|
struct timespec s;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &s);
|
||||||
|
return s.tv_sec * 1000 + s.tv_nsec / 1000000;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
17
src/Platform.h
Normal file
17
src/Platform.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef PLATFORM_H
|
||||||
|
#define PLATFORM_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Platform
|
||||||
|
{
|
||||||
|
char * ExecutableName();
|
||||||
|
void DoRestart();
|
||||||
|
|
||||||
|
void OpenURI(std::string uri);
|
||||||
|
|
||||||
|
void Millisleep(long int t);
|
||||||
|
long unsigned int GetTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -19,56 +19,12 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Update.h>
|
#include "Update.h"
|
||||||
#include <Misc.h>
|
#include "Platform.h"
|
||||||
|
|
||||||
/*char *exe_name(void)
|
|
||||||
{
|
|
||||||
#if defined(WIN)
|
|
||||||
char *name= (char *)malloc(64);
|
|
||||||
DWORD max=64, res;
|
|
||||||
while ((res = GetModuleFileName(NULL, name, max)) >= max)
|
|
||||||
{
|
|
||||||
#elif defined MACOSX
|
|
||||||
char *fn=malloc(64),*name=malloc(PATH_MAX);
|
|
||||||
uint32_t max=64, res;
|
|
||||||
if (_NSGetExecutablePath(fn, &max) != 0)
|
|
||||||
{
|
|
||||||
fn = realloc(fn, max);
|
|
||||||
_NSGetExecutablePath(fn, &max);
|
|
||||||
}
|
|
||||||
if (realpath(fn, name) == NULL)
|
|
||||||
{
|
|
||||||
free(fn);
|
|
||||||
free(name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
res = 1;
|
|
||||||
#else
|
|
||||||
char fn[64], *name=malloc(64);
|
|
||||||
size_t max=64, res;
|
|
||||||
sprintf(fn, "/proc/self/exe");
|
|
||||||
memset(name, 0, max);
|
|
||||||
while ((res = readlink(fn, name, max)) >= max-1)
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
#ifndef MACOSX
|
|
||||||
max *= 2;
|
|
||||||
name = (char*)realloc(name, max);
|
|
||||||
memset(name, 0, max);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (res <= 0)
|
|
||||||
{
|
|
||||||
free(name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int update_start(char *data, unsigned int len)
|
int update_start(char *data, unsigned int len)
|
||||||
{
|
{
|
||||||
char *self=exe_name(), *temp;
|
char *self = Platform::ExecutableName(), *temp;
|
||||||
#ifdef WIN
|
#ifdef WIN
|
||||||
char *p;
|
char *p;
|
||||||
#endif
|
#endif
|
||||||
@ -147,7 +103,7 @@ fail:
|
|||||||
int update_finish(void)
|
int update_finish(void)
|
||||||
{
|
{
|
||||||
#ifdef WIN
|
#ifdef WIN
|
||||||
char *temp, *self=exe_name(), *p;
|
char *temp, *self = Platform::ExecutableName(), *p;
|
||||||
int timeout = 60, err;
|
int timeout = 60, err;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "MD5.h"
|
#include "MD5.h"
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
|
#include "Platform.h"
|
||||||
#include "Update.h"
|
#include "Update.h"
|
||||||
#include "HTTP.h"
|
#include "HTTP.h"
|
||||||
|
|
||||||
@ -187,7 +188,7 @@ bool Client::DoInstallation()
|
|||||||
int returnval;
|
int returnval;
|
||||||
LONG rresult;
|
LONG rresult;
|
||||||
HKEY newkey;
|
HKEY newkey;
|
||||||
char *currentfilename = exe_name();
|
char *currentfilename = Platform::ExecutableName();
|
||||||
char *iconname = NULL;
|
char *iconname = NULL;
|
||||||
char *opencommand = NULL;
|
char *opencommand = NULL;
|
||||||
char *protocolcommand = NULL;
|
char *protocolcommand = NULL;
|
||||||
@ -352,7 +353,7 @@ bool Client::DoInstallation()
|
|||||||
#elif defined(LIN)
|
#elif defined(LIN)
|
||||||
#include "icondoc.h"
|
#include "icondoc.h"
|
||||||
|
|
||||||
std::string filename = exe_name(), pathname = filename.substr(0, filename.rfind('/'));
|
std::string filename = Platform::ExecutableName(), pathname = filename.substr(0, filename.rfind('/'));
|
||||||
for (size_t i = 0; i < filename.size(); i++)
|
for (size_t i = 0; i < filename.size(); i++)
|
||||||
{
|
{
|
||||||
if (filename[i] == '\'')
|
if (filename[i] == '\'')
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
#include "HTTP.h"
|
#include "HTTP.h"
|
||||||
#include "MD5.h"
|
#include "MD5.h"
|
||||||
#include "Misc.h"
|
#include "Platform.h"
|
||||||
|
|
||||||
#ifdef WIN
|
#ifdef WIN
|
||||||
#define PERROR SOCKET_ERROR
|
#define PERROR SOCKET_ERROR
|
||||||
@ -605,7 +605,7 @@ char *http_async_req_stop(void *ctx, int *ret, int *len)
|
|||||||
|
|
||||||
if (cx->state != HTS_DONE)
|
if (cx->state != HTS_DONE)
|
||||||
while (!http_async_req_status(ctx))
|
while (!http_async_req_status(ctx))
|
||||||
millisleep(1);
|
Platform::Millisleep(1);
|
||||||
|
|
||||||
if (cx->host)
|
if (cx->host)
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "RequestListener.h"
|
#include "RequestListener.h"
|
||||||
#include "ThumbRenderRequest.h"
|
#include "ThumbRenderRequest.h"
|
||||||
#include "ImageRequest.h"
|
#include "ImageRequest.h"
|
||||||
#include "Misc.h"
|
#include "Platform.h"
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
#include "client/GameSave.h"
|
#include "client/GameSave.h"
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
@ -238,7 +238,7 @@ void RequestBroker::thumbnailQueueProcessTH()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&requestQueueMutex);
|
pthread_mutex_unlock(&requestQueueMutex);
|
||||||
millisleep(1);
|
Platform::Millisleep(1);
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&runningMutex);
|
pthread_mutex_lock(&runningMutex);
|
||||||
thumbnailQueueRunning = false;
|
thumbnailQueueRunning = false;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
|
#include "Platform.h"
|
||||||
#include "GameController.h"
|
#include "GameController.h"
|
||||||
#include "GameModel.h"
|
#include "GameModel.h"
|
||||||
#include "client/SaveInfo.h"
|
#include "client/SaveInfo.h"
|
||||||
@ -636,7 +637,7 @@ bool GameController::MouseUp(int x, int y, unsigned button)
|
|||||||
// buff is already confirmed to be a number by sign::splitsign
|
// buff is already confirmed to be a number by sign::splitsign
|
||||||
std::stringstream uri;
|
std::stringstream uri;
|
||||||
uri << "http://powdertoy.co.uk/Discussions/Thread/View.html?Thread=" << buff;
|
uri << "http://powdertoy.co.uk/Discussions/Thread/View.html?Thread=" << buff;
|
||||||
OpenURI(uri.str());
|
Platform::OpenURI(uri.str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 's':
|
case 's':
|
||||||
@ -1525,7 +1526,7 @@ void GameController::NotifyNewNotification(Client * sender, std::pair<std::strin
|
|||||||
|
|
||||||
virtual void Action()
|
virtual void Action()
|
||||||
{
|
{
|
||||||
OpenURI(link);
|
Platform::OpenURI(link);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
gameModel->AddNotification(new LinkNotification(notification.second, notification.first));
|
gameModel->AddNotification(new LinkNotification(notification.second, notification.first));
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Platform.h"
|
|
||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
//#include "Platform.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "gui/interface/Component.h"
|
#include "gui/interface/Component.h"
|
||||||
#include "gui/interface/Engine.h"
|
#include "gui/interface/Engine.h"
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include "Appearance.h"
|
#include "Appearance.h"
|
||||||
#include "Point.h"
|
#include "Point.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "Platform.h"
|
|
||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
|
@ -4,9 +4,8 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Misc.h"
|
#include "Platform.h"
|
||||||
#include "gui/interface/Window.h"
|
#include "gui/interface/Window.h"
|
||||||
#include "gui/interface/Platform.h"
|
|
||||||
#include "gui/interface/Engine.h"
|
#include "gui/interface/Engine.h"
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
|
|
||||||
@ -180,7 +179,7 @@ void Engine::Tick()
|
|||||||
state_->DoTick(dt);
|
state_->DoTick(dt);
|
||||||
|
|
||||||
|
|
||||||
lastTick = gettime();
|
lastTick = Platform::GetTime();
|
||||||
|
|
||||||
/*if(statequeued_ != NULL)
|
/*if(statequeued_ != NULL)
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include "Singleton.h"
|
#include "Singleton.h"
|
||||||
#include "Platform.h"
|
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
//#include "Platform.h"
|
|
||||||
|
|
||||||
#include "gui/interface/Panel.h"
|
#include "gui/interface/Panel.h"
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
//#include "Platform.h"
|
|
||||||
|
|
||||||
#include "gui/interface/Point.h"
|
#include "gui/interface/Point.h"
|
||||||
#include "gui/interface/Window.h"
|
#include "gui/interface/Window.h"
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
typedef unsigned short Uint16;
|
|
||||||
|
|
||||||
/* ***** Primitive Types ***** */
|
|
||||||
|
|
||||||
#ifndef NULL
|
|
||||||
# define NULL 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <climits>
|
|
||||||
namespace sys
|
|
||||||
{
|
|
||||||
|
|
||||||
#if UCHAR_MAX == 0xFF //char
|
|
||||||
typedef signed char s8;
|
|
||||||
typedef unsigned char u8;
|
|
||||||
#else
|
|
||||||
# error No 8-Bit Integer supported.
|
|
||||||
#endif
|
|
||||||
#if USHRT_MAX == 0xFFFF //short
|
|
||||||
typedef signed short s16;
|
|
||||||
typedef unsigned short u16;
|
|
||||||
#elif UINT_MAX == 0xFFFF
|
|
||||||
typedef signed int s16;
|
|
||||||
typedef unsigned int u16;
|
|
||||||
#elif ULONG_MAX == 0xFFFF
|
|
||||||
typedef signed long s16;
|
|
||||||
typedef unsigned long u16;
|
|
||||||
#else
|
|
||||||
# error No 16-Bit Integer supported.
|
|
||||||
#endif
|
|
||||||
#if USHRT_MAX == 0xFFFFFFFF //int
|
|
||||||
typedef signed short s32;
|
|
||||||
typedef unsigned short u32;
|
|
||||||
#elif UINT_MAX == 0xFFFFFFFF
|
|
||||||
typedef signed int s32;
|
|
||||||
typedef unsigned int u32;
|
|
||||||
#elif ULONG_MAX == 0xFFFFFFFF
|
|
||||||
typedef signed long s32;
|
|
||||||
typedef unsigned long u32;
|
|
||||||
#else
|
|
||||||
# error No 32-Bit Integer supported.
|
|
||||||
#endif
|
|
||||||
#if UINT_MAX == 0xFFFFFFFFFFFFFFFF //long
|
|
||||||
typedef signed int s64;
|
|
||||||
typedef unsigned int u64;
|
|
||||||
#elif ULONG_MAX == 0xFFFFFFFFFFFFFFFF
|
|
||||||
typedef signed long s64;
|
|
||||||
typedef unsigned long u64;
|
|
||||||
#elif ULLONG_MAX == 0xFFFFFFFFFFFFFFFF
|
|
||||||
typedef signed long long s64;
|
|
||||||
typedef unsigned long long u64;
|
|
||||||
#else
|
|
||||||
# pragma message("Warning: 64-bit not supported. s64 and u64 defined as 32-bit.")
|
|
||||||
typedef s32 s64;
|
|
||||||
typedef u32 u64;
|
|
||||||
#endif
|
|
||||||
//floating
|
|
||||||
typedef float f32;
|
|
||||||
typedef double f64;
|
|
||||||
//misc
|
|
||||||
typedef u8 byte;
|
|
||||||
typedef u8 ubyte;
|
|
||||||
typedef s8 sbyte;
|
|
||||||
typedef s64 llong;
|
|
||||||
typedef s64 sllong;
|
|
||||||
typedef u64 ullong;
|
|
||||||
typedef char* cstring;
|
|
||||||
|
|
||||||
} //namespace sys
|
|
@ -1,5 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Platform.h"
|
|
||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
#include "RichLabel.h"
|
#include "RichLabel.h"
|
||||||
#include "Misc.h"
|
#include "Platform.h"
|
||||||
#include "gui/interface/Point.h"
|
#include "gui/interface/Point.h"
|
||||||
#include "gui/interface/Component.h"
|
#include "gui/interface/Component.h"
|
||||||
#include "graphics/Graphics.h"
|
#include "graphics/Graphics.h"
|
||||||
@ -190,7 +190,7 @@ void RichLabel::OnMouseClick(int x, int y, unsigned button)
|
|||||||
switch((*iter).action)
|
switch((*iter).action)
|
||||||
{
|
{
|
||||||
case 'a':
|
case 'a':
|
||||||
OpenURI((*iter).actionData);
|
Platform::OpenURI((*iter).actionData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
#include "Platform.h"
|
||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
#include "gui/interface/Point.h"
|
#include "gui/interface/Point.h"
|
||||||
#include "gui/interface/Textbox.h"
|
#include "gui/interface/Textbox.h"
|
||||||
@ -280,10 +281,10 @@ void Textbox::Tick(float dt)
|
|||||||
keyDown = 0;
|
keyDown = 0;
|
||||||
characterDown = 0;
|
characterDown = 0;
|
||||||
}
|
}
|
||||||
if ((keyDown || characterDown) && repeatTime <= gettime())
|
if ((keyDown || characterDown) && repeatTime <= Platform::GetTime())
|
||||||
{
|
{
|
||||||
OnVKeyPress(keyDown, characterDown, false, false, false);
|
OnVKeyPress(keyDown, characterDown, false, false, false);
|
||||||
repeatTime = gettime()+30;
|
repeatTime = Platform::GetTime()+30;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,7 +298,7 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
|||||||
{
|
{
|
||||||
characterDown = character;
|
characterDown = character;
|
||||||
keyDown = key;
|
keyDown = key;
|
||||||
repeatTime = gettime()+300;
|
repeatTime = Platform::GetTime()+300;
|
||||||
OnVKeyPress(key, character, shift, ctrl, alt);
|
OnVKeyPress(key, character, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "gui/dialogues/ErrorMessage.h"
|
#include "gui/dialogues/ErrorMessage.h"
|
||||||
#include "gui/login/LoginController.h"
|
#include "gui/login/LoginController.h"
|
||||||
#include "Controller.h"
|
#include "Controller.h"
|
||||||
|
#include "Platform.h"
|
||||||
|
|
||||||
PreviewController::PreviewController(int saveID, int saveDate, bool instant, ControllerCallback * callback):
|
PreviewController::PreviewController(int saveID, int saveDate, bool instant, ControllerCallback * callback):
|
||||||
saveId(saveID),
|
saveId(saveID),
|
||||||
@ -150,7 +151,7 @@ void PreviewController::OpenInBrowser()
|
|||||||
{
|
{
|
||||||
std::stringstream uriStream;
|
std::stringstream uriStream;
|
||||||
uriStream << "http://" << SERVER << "/Browse/View.html?ID=" << saveId;
|
uriStream << "http://" << SERVER << "/Browse/View.html?ID=" << saveId;
|
||||||
OpenURI(uriStream.str());
|
Platform::OpenURI(uriStream.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PreviewController::NextCommentPage()
|
bool PreviewController::NextCommentPage()
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "client/UserInfo.h"
|
#include "client/UserInfo.h"
|
||||||
#include "client/requestbroker/RequestListener.h"
|
#include "client/requestbroker/RequestListener.h"
|
||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
|
#include "Platform.h"
|
||||||
|
|
||||||
ProfileActivity::ProfileActivity(std::string username) :
|
ProfileActivity::ProfileActivity(std::string username) :
|
||||||
WindowActivity(ui::Point(-1, -1), ui::Point(236, 300)),
|
WindowActivity(ui::Point(-1, -1), ui::Point(236, 300)),
|
||||||
@ -80,7 +81,7 @@ void ProfileActivity::setUserInfo(UserInfo newInfo)
|
|||||||
EditAvatarAction(ProfileActivity * a) : a(a) { }
|
EditAvatarAction(ProfileActivity * a) : a(a) { }
|
||||||
void ActionCallback(ui::Button * sender_)
|
void ActionCallback(ui::Button * sender_)
|
||||||
{
|
{
|
||||||
OpenURI("http://" SERVER "/Profile/Avatar.html");
|
Platform::OpenURI("http://" SERVER "/Profile/Avatar.html");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "gui/dialogues/ErrorMessage.h"
|
#include "gui/dialogues/ErrorMessage.h"
|
||||||
#include "gui/preview/PreviewController.h"
|
#include "gui/preview/PreviewController.h"
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
#include "Misc.h"
|
#include "Platform.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
#include "tasks/TaskWindow.h"
|
#include "tasks/TaskWindow.h"
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ void SearchController::Update()
|
|||||||
doRefresh = false;
|
doRefresh = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!nextQueryDone && nextQueryTime < gettime())
|
else if (!nextQueryDone && nextQueryTime < Platform::GetTime())
|
||||||
{
|
{
|
||||||
if (searchModel->UpdateSaveList(1, nextQuery))
|
if (searchModel->UpdateSaveList(1, nextQuery))
|
||||||
nextQueryDone = true;
|
nextQueryDone = true;
|
||||||
@ -115,7 +115,7 @@ void SearchController::DoSearch(std::string query, bool now)
|
|||||||
nextQuery = query;
|
nextQuery = query;
|
||||||
if (!now)
|
if (!now)
|
||||||
{
|
{
|
||||||
nextQueryTime = gettime()+600;
|
nextQueryTime = Platform::GetTime()+600;
|
||||||
nextQueryDone = false;
|
nextQueryDone = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "client/HTTP.h"
|
#include "client/HTTP.h"
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
#include "Update.h"
|
#include "Update.h"
|
||||||
#include "Misc.h"
|
#include "Platform.h"
|
||||||
|
|
||||||
|
|
||||||
class UpdateDownloadTask : public Task
|
class UpdateDownloadTask : public Task
|
||||||
@ -148,7 +148,7 @@ void UpdateActivity::NotifyError(Task * sender)
|
|||||||
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
|
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
|
||||||
if (result == ConfirmPrompt::ResultOkay)
|
if (result == ConfirmPrompt::ResultOkay)
|
||||||
{
|
{
|
||||||
OpenURI("http://powdertoy.co.uk/Download.html");
|
Platform::OpenURI("http://powdertoy.co.uk/Download.html");
|
||||||
}
|
}
|
||||||
a->Exit();
|
a->Exit();
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "Format.h"
|
#include "Format.h"
|
||||||
#include "LuaScriptInterface.h"
|
#include "LuaScriptInterface.h"
|
||||||
#include "LuaScriptHelper.h"
|
#include "LuaScriptHelper.h"
|
||||||
#include "Misc.h"
|
#include "Platform.h"
|
||||||
#include "PowderToy.h"
|
#include "PowderToy.h"
|
||||||
|
|
||||||
#include "gui/dialogues/ErrorMessage.h"
|
#include "gui/dialogues/ErrorMessage.h"
|
||||||
@ -463,7 +463,7 @@ int luacon_keyevent(int key, int modifier, int event)
|
|||||||
{
|
{
|
||||||
if (!strcmp(luacon_geterror(), "Error: Script not responding"))
|
if (!strcmp(luacon_geterror(), "Error: Script not responding"))
|
||||||
{
|
{
|
||||||
ui::Engine::Ref().LastTick(gettime());
|
ui::Engine::Ref().LastTick(Platform::GetTime());
|
||||||
for (int j = i; j <= len-1; j++)
|
for (int j = i; j <= len-1; j++)
|
||||||
{
|
{
|
||||||
lua_rawgeti(l, -2, j+1);
|
lua_rawgeti(l, -2, j+1);
|
||||||
@ -516,7 +516,7 @@ int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel)
|
|||||||
{
|
{
|
||||||
if (!strcmp(luacon_geterror(), "Error: Script not responding"))
|
if (!strcmp(luacon_geterror(), "Error: Script not responding"))
|
||||||
{
|
{
|
||||||
ui::Engine::Ref().LastTick(gettime());
|
ui::Engine::Ref().LastTick(Platform::GetTime());
|
||||||
for (int j = i; j <= len-1; j++)
|
for (int j = i; j <= len-1; j++)
|
||||||
{
|
{
|
||||||
lua_rawgeti(l, -2, j+1);
|
lua_rawgeti(l, -2, j+1);
|
||||||
@ -567,7 +567,7 @@ int luacon_step(int mx, int my)
|
|||||||
{
|
{
|
||||||
if (!strcmp(luacon_geterror(), "Error: Script not responding"))
|
if (!strcmp(luacon_geterror(), "Error: Script not responding"))
|
||||||
{
|
{
|
||||||
ui::Engine::Ref().LastTick(gettime());
|
ui::Engine::Ref().LastTick(Platform::GetTime());
|
||||||
for (int j = i; j <= len-1; j++)
|
for (int j = i; j <= len-1; j++)
|
||||||
{
|
{
|
||||||
lua_rawgeti(l, -2, j+1);
|
lua_rawgeti(l, -2, j+1);
|
||||||
@ -589,17 +589,17 @@ int luacon_step(int mx, int my)
|
|||||||
|
|
||||||
int luacon_eval(const char *command)
|
int luacon_eval(const char *command)
|
||||||
{
|
{
|
||||||
ui::Engine::Ref().LastTick(gettime());
|
ui::Engine::Ref().LastTick(Platform::GetTime());
|
||||||
return luaL_dostring (luacon_ci->l, command);
|
return luaL_dostring (luacon_ci->l, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void luacon_hook(lua_State * l, lua_Debug * ar)
|
void luacon_hook(lua_State * l, lua_Debug * ar)
|
||||||
{
|
{
|
||||||
if(ar->event == LUA_HOOKCOUNT && gettime()-ui::Engine::Ref().LastTick() > 3000)
|
if(ar->event == LUA_HOOKCOUNT && Platform::GetTime()-ui::Engine::Ref().LastTick() > 3000)
|
||||||
{
|
{
|
||||||
if(ConfirmPrompt::Blocking("Script not responding", "The Lua script may have stopped responding. There might be an infinite loop. Press \"Stop\" to stop it", "Stop"))
|
if(ConfirmPrompt::Blocking("Script not responding", "The Lua script may have stopped responding. There might be an infinite loop. Press \"Stop\" to stop it", "Stop"))
|
||||||
luaL_error(l, "Error: Script not responding");
|
luaL_error(l, "Error: Script not responding");
|
||||||
ui::Engine::Ref().LastTick(gettime());
|
ui::Engine::Ref().LastTick(Platform::GetTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2012,17 +2012,4 @@ int luatpt_screenshot(lua_State* l)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int luatpt_getclip (lua_State* l)
|
|
||||||
{
|
|
||||||
lua_pushstring(l, ClipboardPull().c_str());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int luatpt_setclip (lua_State* l)
|
|
||||||
{
|
|
||||||
luaL_checktype(l, 1, LUA_TSTRING);
|
|
||||||
ClipboardPush(luaL_optstring(l, 1, ""));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -128,8 +128,6 @@ int luatpt_getscript(lua_State* l);
|
|||||||
int luatpt_setwindowsize(lua_State* l);
|
int luatpt_setwindowsize(lua_State* l);
|
||||||
|
|
||||||
int luatpt_screenshot(lua_State* l);
|
int luatpt_screenshot(lua_State* l);
|
||||||
int luatpt_getclip(lua_State* l);
|
|
||||||
int luatpt_setclip(lua_State* l);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* LUASCRIPTHELPER_H_ */
|
#endif /* LUASCRIPTHELPER_H_ */
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "client/HTTP.h"
|
#include "client/HTTP.h"
|
||||||
#include "client/SaveFile.h"
|
#include "client/SaveFile.h"
|
||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
|
#include "Platform.h"
|
||||||
#include "PowderToy.h"
|
#include "PowderToy.h"
|
||||||
|
|
||||||
#include "LuaBit.h"
|
#include "LuaBit.h"
|
||||||
@ -135,6 +136,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
|
|||||||
initElementsAPI();
|
initElementsAPI();
|
||||||
initGraphicsAPI();
|
initGraphicsAPI();
|
||||||
initFileSystemAPI();
|
initFileSystemAPI();
|
||||||
|
initPlatformAPI();
|
||||||
|
|
||||||
//Old TPT API
|
//Old TPT API
|
||||||
char tmpname[12];
|
char tmpname[12];
|
||||||
@ -200,8 +202,8 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
|
|||||||
{"element",&luatpt_getelement},
|
{"element",&luatpt_getelement},
|
||||||
{"element_func",&luatpt_element_func},
|
{"element_func",&luatpt_element_func},
|
||||||
{"graphics_func",&luatpt_graphics_func},
|
{"graphics_func",&luatpt_graphics_func},
|
||||||
{"get_clipboard", &luatpt_getclip},
|
{"get_clipboard", &platform_clipboardCopy},
|
||||||
{"set_clipboard", &luatpt_setclip},
|
{"set_clipboard", &platform_clipboardPaste},
|
||||||
{NULL,NULL}
|
{NULL,NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2948,6 +2950,81 @@ int LuaScriptInterface::fileSystem_copy(lua_State * l)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuaScriptInterface::initPlatformAPI()
|
||||||
|
{
|
||||||
|
//Methods
|
||||||
|
struct luaL_Reg platformAPIMethods [] = {
|
||||||
|
{"platform", platform_platform},
|
||||||
|
{"build", platform_build},
|
||||||
|
{"releaseType", platform_releaseType},
|
||||||
|
{"exeName", platform_exeName},
|
||||||
|
{"restart", platform_restart},
|
||||||
|
{"openLink", platform_openLink},
|
||||||
|
{"clipboardCopy", platform_clipboardCopy},
|
||||||
|
{"clipboardPaste", platform_clipboardPaste},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
luaL_register(l, "platform", platformAPIMethods);
|
||||||
|
|
||||||
|
//elem shortcut
|
||||||
|
lua_getglobal(l, "platform");
|
||||||
|
lua_setglobal(l, "plat");
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::platform_platform(lua_State * l)
|
||||||
|
{
|
||||||
|
lua_pushstring(l, IDENT_PLATFORM);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::platform_build(lua_State * l)
|
||||||
|
{
|
||||||
|
lua_pushstring(l, IDENT_BUILD);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::platform_releaseType(lua_State * l)
|
||||||
|
{
|
||||||
|
lua_pushstring(l, IDENT_RELTYPE);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::platform_exeName(lua_State * l)
|
||||||
|
{
|
||||||
|
char *name = Platform::ExecutableName();
|
||||||
|
if (name)
|
||||||
|
lua_pushstring(l, name);
|
||||||
|
else
|
||||||
|
luaL_error(l, "Error, could not get executable name");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::platform_restart(lua_State * l)
|
||||||
|
{
|
||||||
|
Platform::DoRestart();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::platform_openLink(lua_State * l)
|
||||||
|
{
|
||||||
|
const char * uri = luaL_checkstring(l, 1);
|
||||||
|
Platform::OpenURI(uri);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::platform_clipboardCopy(lua_State * l)
|
||||||
|
{
|
||||||
|
lua_pushstring(l, ClipboardPull().c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaScriptInterface::platform_clipboardPaste(lua_State * l)
|
||||||
|
{
|
||||||
|
luaL_checktype(l, 1, LUA_TSTRING);
|
||||||
|
ClipboardPush(luaL_optstring(l, 1, ""));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LuaScriptInterface::OnBrushChanged(int brushType, int rx, int ry)
|
bool LuaScriptInterface::OnBrushChanged(int brushType, int rx, int ry)
|
||||||
{
|
{
|
||||||
@ -3023,7 +3100,7 @@ bool LuaScriptInterface::OnKeyRelease(int key, Uint16 character, bool shift, boo
|
|||||||
|
|
||||||
bool LuaScriptInterface::OnMouseTick()
|
bool LuaScriptInterface::OnMouseTick()
|
||||||
{
|
{
|
||||||
ui::Engine::Ref().LastTick(gettime());
|
ui::Engine::Ref().LastTick(Platform::GetTime());
|
||||||
if (luacon_mousedown)
|
if (luacon_mousedown)
|
||||||
return luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS, 0);
|
return luacon_mouseevent(luacon_mousex, luacon_mousey, luacon_mousebutton, LUACON_MPRESS, 0);
|
||||||
return true;
|
return true;
|
||||||
@ -3034,7 +3111,7 @@ void LuaScriptInterface::OnTick()
|
|||||||
lua_getglobal(l, "simulation");
|
lua_getglobal(l, "simulation");
|
||||||
lua_pushinteger(l, luacon_sim->NUM_PARTS); lua_setfield(l, -2, "NUM_PARTS");
|
lua_pushinteger(l, luacon_sim->NUM_PARTS); lua_setfield(l, -2, "NUM_PARTS");
|
||||||
lua_pop(l, 1);
|
lua_pop(l, 1);
|
||||||
ui::Engine::Ref().LastTick(gettime());
|
ui::Engine::Ref().LastTick(Platform::GetTime());
|
||||||
luacon_step(luacon_mousex, luacon_mousey);
|
luacon_step(luacon_mousex, luacon_mousey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3057,7 +3134,7 @@ int LuaScriptInterface::Command(std::string command)
|
|||||||
lastCode += "\n";
|
lastCode += "\n";
|
||||||
lastCode += command;
|
lastCode += command;
|
||||||
std::string tmp = "return " + lastCode;
|
std::string tmp = "return " + lastCode;
|
||||||
ui::Engine::Ref().LastTick(gettime());
|
ui::Engine::Ref().LastTick(Platform::GetTime());
|
||||||
luaL_loadbuffer(l, tmp.c_str(), tmp.length(), "@console");
|
luaL_loadbuffer(l, tmp.c_str(), tmp.length(), "@console");
|
||||||
if (lua_type(l, -1) != LUA_TFUNCTION)
|
if (lua_type(l, -1) != LUA_TFUNCTION)
|
||||||
{
|
{
|
||||||
|
@ -148,6 +148,16 @@ class LuaScriptInterface: public CommandInterface
|
|||||||
static int fileSystem_move(lua_State * l);
|
static int fileSystem_move(lua_State * l);
|
||||||
static int fileSystem_copy(lua_State * l);
|
static int fileSystem_copy(lua_State * l);
|
||||||
|
|
||||||
|
void initPlatformAPI();
|
||||||
|
static int platform_platform(lua_State * l);
|
||||||
|
static int platform_build(lua_State * l);
|
||||||
|
static int platform_releaseType(lua_State * l);
|
||||||
|
static int platform_exeName(lua_State * l);
|
||||||
|
static int platform_restart(lua_State * l);
|
||||||
|
static int platform_openLink(lua_State * l);
|
||||||
|
static int platform_clipboardCopy(lua_State * l);
|
||||||
|
static int platform_clipboardPaste(lua_State * l);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int tpt_index(lua_State *l);
|
int tpt_index(lua_State *l);
|
||||||
int tpt_newIndex(lua_State *l);
|
int tpt_newIndex(lua_State *l);
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include "LuaLuna.h"
|
#include "LuaLuna.h"
|
||||||
|
|
||||||
#include "gui/interface/Platform.h"
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
class Window;
|
class Window;
|
||||||
|
Reference in New Issue
Block a user