diff --git a/src/game/sandbox/sandboxscene.c b/src/game/sandbox/sandboxscene.c index 28933564..9c05b34f 100644 --- a/src/game/sandbox/sandboxscene.c +++ b/src/game/sandbox/sandboxscene.c @@ -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; diff --git a/src/script/api/epoch.c b/src/script/api/epoch.c new file mode 100644 index 00000000..b6574d5d --- /dev/null +++ b/src/script/api/epoch.c @@ -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); +} \ No newline at end of file diff --git a/src/script/api/epoch.d.ts b/src/script/api/epoch.d.ts new file mode 100644 index 00000000..a9947e7c --- /dev/null +++ b/src/script/api/epoch.d.ts @@ -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; \ No newline at end of file diff --git a/src/script/api/epoch.h b/src/script/api/epoch.h new file mode 100644 index 00000000..f5f99531 --- /dev/null +++ b/src/script/api/epoch.h @@ -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); \ No newline at end of file diff --git a/ts/main.ts b/ts/main.ts index 47e1cf1d..6aea9d8b 100644 --- a/ts/main.ts +++ b/ts/main.ts @@ -2,10 +2,13 @@ let cube:Primitive; let shader:Shader; let camera:Camera; let texture:Texture; +let n:number; const init = () => { print('Main invoked'); + n = 0; + // Create Quad cube = primitiveCreate(); quadInit(cube, 0, -1, -1, 0, 0, 1, 1, 1, 1); @@ -25,12 +28,16 @@ const init = () => { const update = () => { shaderUse(shader); shaderUseTexture(shader, texture); + + n += epochGetDelta(); + cameraLookAt(camera, 3,3,3, 0,0,0); cameraPerspective(camera, 45, 16/9, 0.01, 100); + shaderUseCamera(shader, camera); - shaderUsePosition(shader, 0,0,0, 0,0,0); + shaderUsePosition(shader, 0,0,0, 0,n,0); primitiveDraw(cube, 0, -1); }