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);
|
@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user