Added epoch to scripts.
This commit is contained in:
@ -12,13 +12,16 @@ bool sandboxSceneInit(sandboxscene_t *game) {
|
||||
scripterInit(&game->scripter, &game->engine);
|
||||
game->scripter.user = game;
|
||||
|
||||
// Add APIs
|
||||
scriptsApiIo(&game->scripter);
|
||||
scriptsApiDisplay(&game->scripter);
|
||||
scriptsApiAsset(&game->scripter);
|
||||
|
||||
scriptsApiEpoch(&game->scripter);
|
||||
|
||||
// Load main script
|
||||
assetScripterAppend(&game->scripter, "scripts/main.js");
|
||||
|
||||
|
||||
// Invoke initialization.
|
||||
scripterInvokeMethodSimple(&game->scripter, "init");
|
||||
|
||||
return true;
|
||||
|
32
src/script/api/epoch.c
Normal file
32
src/script/api/epoch.c
Normal file
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "epoch.h"
|
||||
|
||||
scripterreturn_t _scripterEpochGetDelta(scriptercontext_t *ctx) {
|
||||
scripter_t *scripter = scripterFromContext(ctx);
|
||||
duk_push_number(ctx, scripter->engine->time.delta);
|
||||
return 1;
|
||||
}
|
||||
|
||||
scripterreturn_t _scripterEpochGetCurrent(scriptercontext_t *ctx) {
|
||||
scripter_t *scripter = scripterFromContext(ctx);
|
||||
duk_push_number(ctx, scripter->engine->time.current);
|
||||
return 1;
|
||||
}
|
||||
|
||||
scripterreturn_t _scripterEpochGetLast(scriptercontext_t *ctx) {
|
||||
scripter_t *scripter = scripterFromContext(ctx);
|
||||
duk_push_number(ctx, scripter->engine->time.last);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void scriptsApiEpoch(scripter_t *scripter) {
|
||||
scripterDefineMethod(scripter, "epochGetDelta", 0, &_scripterEpochGetDelta);
|
||||
scripterDefineMethod(scripter, "epochGetCurrent",0,&_scripterEpochGetCurrent);
|
||||
scripterDefineMethod(scripter, "epochGetLast", 0, &_scripterEpochGetLast);
|
||||
}
|
10
src/script/api/epoch.d.ts
vendored
Normal file
10
src/script/api/epoch.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
declare function epochGetDelta():number;
|
||||
|
||||
declare function epochGetCurrent():number;
|
||||
|
||||
declare function epochGetLast():number;
|
13
src/script/api/epoch.h
Normal file
13
src/script/api/epoch.h
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../../libs.h"
|
||||
#include "../scripter.h"
|
||||
#include "../../engine/engine.h"
|
||||
|
||||
void scriptsApiEpoch(scripter_t *scripter);
|
Reference in New Issue
Block a user