Added JS engine.

This commit is contained in:
2021-09-18 00:39:00 -07:00
parent 9dd9ce7cbd
commit ef9137fabb
52 changed files with 547 additions and 35712 deletions

View File

@ -136,4 +136,19 @@ void assetXmlLoad(xml_t *xml, char *assetName) {
char *data = assetStringLoad(assetName);
xmlLoad(xml, data);
free(data);
}
void assetScripterAppend(scripter_t *scripter, char *fileName) {
assetbuffer_t *asset = assetBufferOpen(fileName);
int32_t read;
char buffer[2048];
duk_push_global_object(scripter->context);
while(read = assetBufferRead(asset, buffer, 2048)) {
duk_push_lstring(scripter->context, buffer, (duk_size_t)read);
}
duk_peval(scripter->context);
assetBufferClose(asset);
}

View File

@ -86,4 +86,8 @@ void assetTextureLoad(texture_t *texture, char *fileName);
* @param assetName Asset name for the TTF font.
* @param size Size of the font.
*/
void assetFontLoad(font_t *font, char *assetName);
void assetFontLoad(font_t *font, char *assetName);
void assetScripterAppend(scripter_t *scripter, char *fileName);

View File

@ -13,11 +13,11 @@ bool gameInit(game_t *game) {
// Send off to the game instance
#if SETTING_GAME == SETTING_GAME_POKER
return pokerGameInit(&game->pokerGame);
return pokerGameInit(&game->pokerGame, &game->engine);
#elif SETTING_GAME == SETTING_GAME_DAWN
return dawnGameInit(game);
#elif SETTING_GAME == SETTING_GAME_SANDBOX
return sandboxSceneInit(&game->sandboxScene);
return sandboxSceneInit(&game->sandboxScene, &game->engine);
#endif
}

View File

@ -24,8 +24,12 @@ void _pokerGameActionBetOnUpdate(
// Handle as an AI
if(isHuman) {
turn.type = POKER_TURN_TYPE_FOLD;
turnMade = true;
if(inputIsPressed(&game->engine->input, INPUT_DOWN)) {
} else if(inputIsPressed(&game->engine->input, INPUT_RIGHT)) {
} else if(inputIsPressed(&game->engine->input, INPUT_UP)) {
}
} else {
turn = pokerTurnGet(&game->poker, game->poker.bet.better);
turnMade = true;
@ -87,6 +91,7 @@ void _pokerGameActionBetOnEnd(
// Are we waiting on any players?
if(game->poker.bet.better != 0xFF) {
pokerGameActionLookAdd(game, game->poker.bet.better);
pokerGameActionBetAdd(game);
return;
}
@ -103,6 +108,7 @@ void _pokerGameActionBetOnEnd(
pokerBetResetBetter(&game->poker);
pokerGameActionRestackAdd(game);
pokerGameActionLookAdd(game, game->poker.bet.better);
pokerGameActionBetAdd(game);
return;
}

View File

@ -7,7 +7,9 @@
#include "pokergame.h"
bool pokerGameInit(pokergame_t *game) {
bool pokerGameInit(pokergame_t *game, engine_t *engine) {
game->engine = engine;
// Load the Assets.
pokerGameAssetsInit(&game->assets);

View File

@ -21,9 +21,10 @@
* Initializes the game state for the poker game.
*
* @param game Game to initialize.
* @param engine Engine to use when initializing.
* @returns True if successful, otherwise false.
*/
bool pokerGameInit(pokergame_t *game);
bool pokerGameInit(pokergame_t *game, engine_t *engine);
/**
* Updates the poker game instance.

View File

@ -20,6 +20,7 @@ bool pokerGameAssetsInit(pokergameassets_t *assets) {
// Load the world textures.
assetTextureLoad(&assets->testTexture, "test_texture.png");
assetTextureLoad(&assets->cardTexture, "cards_normal.png");
assetTextureLoad(&assets->roomTexture, "world/pub/pub_skywall.png");
// Load the character textures.

View File

@ -0,0 +1,23 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "pokercardui.h"
void pokerCardSetImage(image_t *image, texture_t *texture, card_t card) {
uint8_t cardImageIndex = (
cardGetNumber(card) == CARD_ACE ? (
card - CARD_COUNT_PER_SUIT + 1
) : card+0x01
);
imageSetTextureAndCrop(
image, texture,
cardGetNumber(cardImageIndex) * 71,
cardGetSuit(card) * 96,
71, 96
);
}

View File

@ -0,0 +1,14 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../../../ui/image.h"
#include "../../../poker/card.h"
void pokerCardSetImage(image_t *image, texture_t *texture, card_t card);

View File

@ -17,7 +17,14 @@ void pokerPlayerUiInit(pokerplayerui_t *ui) {
0, 0, 0, 1,
POKER_PLAYER_UI_IMAGE_SIZE, POKER_PLAYER_UI_IMAGE_SIZE, 1, 0
);
// Set up the grid
ui->grid.gutterX = POKER_PLAYER_UI_PADDING;
ui->grid.columns = 2;
ui->grid.rows = 2;
ui->grid.columnDefinitions[1] = POKER_PLAYER_UI_IMAGE_SIZE;
ui->grid.rowDefinitions[0] = POKER_PLAYER_UI_IMAGE_SIZE / 2.0f;
ui->grid.rowDefinitions[1] = POKER_PLAYER_UI_IMAGE_SIZE / 2.0f;
}
void pokerPlayerUiUpdate(
@ -72,62 +79,51 @@ void pokerPlayerUiRender(
float scale;
align_t align;
float gx, gy, gw, gh, sCol, sRow;
float gx, gy, gw, gh;
// Font crap.
scale = fontGetScale(FONT_SIZE_DEFAULT);
player = game->poker.players + playerIndex;
// Resize the grid
align = alignmentGet(
ALIGN_POS_END | ALIGN_SIZE_ORIGINAL, ALIGN_POS_START | ALIGN_SIZE_ORIGINAL,
engine->render.width, engine->render.height,
POKER_PLAYER_UI_IMAGE_SIZE*2, POKER_PLAYER_UI_IMAGE_SIZE, -1, -1
// Align the grid itself.
gridResize(&ui->grid, POKER_PLAYER_UI_WIDTH, POKER_PLAYER_UI_HEIGHT);
// Render face
gridGetChild(&ui->grid, 1, 0, 1, 2, &gx, &gy, &gw, &gh);
shaderUseTexture(shader, &ui->frame.texture);
shaderUsePosition(shader, x+gx, y+gy, 0, 0,0,0);
primitiveDraw(&ui->quad, 0, -1);
// Render chips
sprintf(buffer, "$%i", player->chips);
ui->label.maxWidth = -1;
labelSetText(&ui->label, font, buffer);
align = gridGetAndAlignChild(
&ui->grid, 0, 0, 1, 1,
ALIGN_POS_END | ALIGN_SIZE_ORIGINAL, ALIGN_POS_CENTER | ALIGN_SIZE_ORIGINAL,
ui->label.info.width, ui->label.info.height
);
// gridSetSize(
// &ui->grid, engine->render.width, engine->render.height,
// align.width, align.height,
// align.x + x, align.y + y
// );
labelRender(&ui->label, shader, x+align.x, y+align.y);
// // Render face
// gridGetChildSize(&ui->grid, ui->grid.breakpointCurrent, ui->grid.children+0,
// &sCol, &sRow, &gx, &gy, &gw, &gh
// );
// shaderUseTexture(shader, &ui->frame.texture);
// shaderUsePosition(shader, gx, gy, 0, 0,0,0);
// primitiveDraw(&ui->quad, 0, -1);
// // Render chips
// sprintf(buffer, "$%i", player->chips);
// ui->label.maxWidth = -1;
// labelSetText(&ui->label, font, buffer);
// align = gridAlignChild(
// &ui->grid, ui->grid.breakpointCurrent, ui->grid.children + 1, &sCol, &sRow,
// ALIGN_POS_END | ALIGN_SIZE_ORIGINAL, ALIGN_POS_CENTER | ALIGN_SIZE_ORIGINAL,
// ui->label.info.width, ui->label.info.height
// );
// labelRender(&ui->label, shader, align.x, align.y);
// // Render state
// if(player->state & POKER_PLAYER_STATE_OUT) {
// sprintf(buffer, "Out");
// } else if(player->state & POKER_PLAYER_STATE_FOLDED) {
// sprintf(buffer, "Folded");
// } else if(player->state & POKER_PLAYER_STATE_SHOWING) {
// sprintf(buffer, "Showing");
// } else if(game->poker.bet.better == playerIndex) {
// sprintf(buffer, "Thinking");
// } else {
// sprintf(buffer, "Whatever");
// }
// labelSetText(&ui->label, font, buffer);
// align = gridAlignChild(
// &ui->grid, ui->grid.breakpointCurrent, ui->grid.children + 2, &sCol, &sRow,
// ALIGN_POS_END | ALIGN_SIZE_ORIGINAL, ALIGN_POS_CENTER | ALIGN_SIZE_ORIGINAL,
// ui->label.info.width, ui->label.info.height
// );
// labelRender(&ui->label, shader, align.x, align.y);
// Render state
if(player->state & POKER_PLAYER_STATE_OUT) {
sprintf(buffer, "Out");
} else if(player->state & POKER_PLAYER_STATE_FOLDED) {
sprintf(buffer, "Folded");
} else if(player->state & POKER_PLAYER_STATE_SHOWING) {
sprintf(buffer, "Showing");
} else if(game->poker.bet.better == playerIndex) {
sprintf(buffer, "Thinking");
} else {
sprintf(buffer, "Whatever");
}
labelSetText(&ui->label, font, buffer);
align = gridGetAndAlignChild(
&ui->grid, 0, 1, 1, 1,
ALIGN_POS_END | ALIGN_SIZE_ORIGINAL, ALIGN_POS_CENTER | ALIGN_SIZE_ORIGINAL,
ui->label.info.width, ui->label.info.height
);
labelRender(&ui->label, shader, x+align.x, y+align.y);
}
void pokerPlayerUiDispose(pokerplayerui_t *ui) {

View File

@ -10,6 +10,10 @@
void pokerUiInit(pokergame_t *pokerGame) {
uint8_t i, j;
// Initialize card render(s)
imageInit(&pokerGame->ui.card);
// Initialize players
j = 0;
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
if(i == POKER_PLAYER_HUMAN_INDEX) continue;
@ -34,6 +38,29 @@ void pokerUiUpdate(pokergame_t *pokerGame, engine_t *engine) {
void pokerUiRender(pokergame_t *pokerGame, engine_t *engine) {
uint8_t i, j;
pokerplayerui_t *ui;
pokerplayer_t *player;
char message[128];
// cards
if(pokerGame->poker.state >= POKER_STATE_DEALING) {
for(j = 0; j < POKER_PLAYER_COUNT; j++) {
player = pokerGame->poker.players + j;
for(i = 0; i < player->cardCount; i++) {
pokerCardSetImage(&pokerGame->ui.card, &pokerGame->assets.cardTexture, player->cards[i]);
imageRender(&pokerGame->ui.card, &pokerGame->assets.shader, i * 64.0f, j * 100);
}
}
}
// show uh
player = pokerGame->poker.players + POKER_PLAYER_HUMAN_INDEX;
if(pokerGame->poker.bet.better == POKER_PLAYER_HUMAN_INDEX) {
sprintf(message, "Press down to fold, up to bet, right to check/call.");
labelSetText(&pokerGame->ui.player->label, &pokerGame->assets.font, message);
labelRender(&pokerGame->ui.player->label, &pokerGame->assets.shader, 300, 100);
}
j = 0;
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
@ -42,7 +69,7 @@ void pokerUiRender(pokergame_t *pokerGame, engine_t *engine) {
pokerPlayerUiRender(
ui, pokerGame, &pokerGame->assets.shader, &pokerGame->assets.font, engine,
i, 0, j * 75.0f
i, engine->render.width - ui->grid.width, j * 75.0f
);
j++;
}
@ -51,6 +78,8 @@ void pokerUiRender(pokergame_t *pokerGame, engine_t *engine) {
void pokerUiDispose(pokergame_t *pokerGame) {
uint8_t i, j;
imageDispose(&pokerGame->ui.card);
j = 0;
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
if(i == POKER_PLAYER_HUMAN_INDEX) continue;

View File

@ -9,6 +9,7 @@
#include <dawn/dawn.h>
#include "../../../ui/label.h"
#include "pokerplayerui.h"
#include "pokercardui.h"
/**
* Initializes the UI Module.

View File

@ -7,48 +7,48 @@
#include "sandboxscene.h"
framedtextmenu_t ftm;
scripter_t scripter;
bool sandboxSceneInit(sandboxscene_t *game) {
bool sandboxSceneInit(sandboxscene_t *game, engine_t *engine) {
assetFontLoad(&game->font, "fonts/opensans/OpenSans-Regular.ttf");
assetTextureLoad(&game->texture, "test_texture.png");
assetShaderLoad(&game->shader,
"shaders/textured.vert", "shaders/textured.frag"
);
menuitem_t *item;
framedTextMenuInit(&ftm, &game->font, &game->texture);
ftm.menu.grid.rows = 3;
item = textMenuAdd(&ftm.menu, "Option 1");
item->y = 0;
item = textMenuAdd(&ftm.menu, "Option 2");
item->y = 1;
item = textMenuAdd(&ftm.menu, "Option 3");
item->y = 2;
scripterInit(&scripter, engine);
assetScripterAppend(&scripter, "scripts/main.js");
scripterInvokeMethodSimple(&scripter, "init");
return true;
}
void sandboxSceneUpdate(sandboxscene_t *game, engine_t *engine) {
cameraLookAt(&game->camera,
0, 0, 10,
0, 0, 0
);
cameraLookAt(&game->camera, 3,3,3, 0,0,0);
cameraOrtho(&game->camera,
0, engine->render.width,
engine->render.height, 0,
cameraPerspective(&game->camera, 45,
engine->render.width/engine->render.height,
0.01f, 1000.0f
);
// cameraLookAt(&game->camera,
// 0, 0, 10,
// 0, 0, 0
// );
// cameraOrtho(&game->camera,
// 0, engine->render.width,
// engine->render.height, 0,
// 0.01f, 1000.0f
// );
shaderUse(&game->shader);
shaderUseCamera(&game->shader, &game->camera);
framedTextMenuResize(&ftm, 400, 400);
framedTextMenuUpdate(&ftm, engine);
framedTextMenuRender(&ftm, &game->shader, 0, 0);
shaderUsePosition(&game->shader, 0,0,0, 0,0,0);
shaderUseTexture(&game->shader, &game->texture);
scripterInvokeMethodSimple(&scripter, "update");
}
void sandboxSceneDispose(sandboxscene_t *game) {
// scripterInvokeMethodSimple(&scripter, "dispose");
scripterDispose(&scripter);
}

View File

@ -18,7 +18,8 @@
#include "../../file/asset.h"
#include "../../file/xml.h"
#include "../../file/asset.h"
#include "../../script/scripter.h"
#include "../../ui/grid.h"
#include "../../ui/menu.h"
#include "../../ui/textmenu.h"
@ -29,9 +30,10 @@
* Initialize the sandbox scene test game.
*
* @param game Game to initialize.
* @param engine Engine to use during init.
* @return True if successful, otherwise false.
*/
bool sandboxSceneInit(sandboxscene_t *game);
bool sandboxSceneInit(sandboxscene_t *game, engine_t *engine);
/**
* Update a sandbox scene.

View File

@ -11,6 +11,8 @@ void _pokerActionBlindsOnStart(queue_t *queue,queueaction_t *action,uint8_t i) {
poker_t *poker;
poker = (poker_t *)action->data;
poker->state = POKER_STATE_TAKING_BLINDS;
pokerBetTakeBlinds(poker);
printf("Taken Blinds\n");
queueNext(queue);

View File

@ -11,6 +11,8 @@ void _pokerActionDealOnStart(queue_t *queue, queueaction_t *action, uint8_t i) {
poker_t *poker;
poker = (poker_t *)action->data;
poker->state = POKER_STATE_DEALING;
// Shuffle the deck
cardShuffle(poker->dealer.deck, CARD_DECK_SIZE);

View File

@ -11,6 +11,8 @@ void _pokerActionFlopDo(queue_t *queue, queueaction_t *action, uint8_t count) {
poker_t *poker;
poker = (poker_t *)action->data;
poker->state = POKER_STATE_CARDS_FLOPPING;
pokerDealerBurn(&poker->dealer, 1);
pokerDealerTurn(&poker->dealer, count);

View File

@ -13,6 +13,8 @@ void _pokerActionMatchOnStart(queue_t *queue, queueaction_t *action, uint8_t i){
poker = (poker_t *)action->data;
poker->state = POKER_STATE_STARTING_MATCH;
// Reset the main game state. This does not init the round.
pokerBetInit(&poker->bet);
poker->roundDealer = POKER_PLAYER_COUNT-2;

View File

@ -15,6 +15,8 @@ void _pokerActionRoundOnStart(queue_t *queue, queueaction_t *action ,uint8_t i){
poker = (poker_t *)action->data;
poker->state = POKER_STATE_STARTING_ROUND;
// Prepare the initial game state
pokerBetReset(&poker->bet);
pokerDealerInit(&poker->dealer);

13
src/script/api/api.c Normal file
View File

@ -0,0 +1,13 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "api.h"
void scriptApiAdd(scripter_t *scripter) {
scriptsApiIo(scripter);
scriptsApiPrimitive(scripter);
}

13
src/script/api/api.h Normal file
View 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 <dawn/dawn.h>
#include "primitive.h"
#include "io.h"
void scriptApiAdd(scripter_t *scripter);

1
src/script/api/global.d.ts vendored Normal file
View File

@ -0,0 +1 @@
declare type Pointer<T> = { 'POINTER':T };

24
src/script/api/io.c Normal file
View File

@ -0,0 +1,24 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "io.h"
scripterreturn_t _scriptPrint(scriptercontext_t *ctx) {
duk_push_string(ctx, " ");
duk_insert(ctx, 0);
duk_join(ctx, duk_get_top(ctx) - 1);
printf("%s\n", duk_safe_to_string(ctx, -1));
return 0;
}
void scriptsApiIo(scripter_t *scripter) {
scripterDefineMethod(scripter,
SCRIPT_IO_PRINT_NAME,
SCRIPT_IO_PRINT_ARGS,
&_scriptPrint
);
}

1
src/script/api/io.d.ts vendored Normal file
View File

@ -0,0 +1 @@
declare function print(...args:any):void;

13
src/script/api/io.h Normal file
View 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 <dawn/dawn.h>
#include "../scripter.h"
#define SCRIPT_IO_PRINT_NAME "print"
#define SCRIPT_IO_PRINT_ARGS SCRIPTER_VARIABLE_ARGUMENT_COUNT
void scriptsApiIo(scripter_t *scripter);

View File

@ -0,0 +1,36 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "primitive.h"
scripterreturn_t _scriptPrimitiveDraw(scriptercontext_t *context) {
primitive_t *primitive = duk_to_pointer(context, 0);
int32_t start = duk_to_number(context, 1);
int32_t count = duk_to_number(context, 2);
primitiveDraw(primitive, start, count);
return 0;
}
scripterreturn_t _scriptCubeInit(scriptercontext_t *context) {
primitive_t *primitive = malloc(sizeof(primitive_t));
cubeInit(primitive, 1, 1, 1);
duk_push_pointer(context, primitive);
return 1;
}
void scriptsApiPrimitive(scripter_t *scripter) {
scripterDefineMethod(scripter,
SCRIPT_PRIMITIVE_DRAW_NAME,
SCRIPT_PRIMITIVE_DRAW_ARGS,
&_scriptPrimitiveDraw
);
scripterDefineMethod(scripter,
SCRIPT_CUBE_INIT_NAME,
SCRIPT_CUBE_INIT_ARGS,
&_scriptCubeInit
);
}

5
src/script/api/primitive.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
declare type PointerPrimitive = Pointer<'PRIMITIVE'>;
declare function primitiveDraw(primitive:PointerPrimitive, start:number, count:number);
declare function cubeCreate():PointerPrimitive;

View File

@ -0,0 +1,20 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "../scripter.h"
#include "../../display/primitive.h"
#include "../../display/primitives/cube.h"
#define SCRIPT_PRIMITIVE_DRAW_NAME "primitiveDraw"
#define SCRIPT_PRIMITIVE_DRAW_ARGS 3
#define SCRIPT_CUBE_INIT_NAME "cubeCreate"
#define SCRIPT_CUBE_INIT_ARGS 0
void scriptsApiPrimitive(scripter_t *scripter);

73
src/script/scripter.c Normal file
View File

@ -0,0 +1,73 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "scripter.h"
void scripterInit(scripter_t *scripter, engine_t *engine) {
scripter->context = duk_create_heap_default();
scripter->engine = engine;
// Global context is implied here?
// Push the script self reference
duk_push_pointer(scripter->context, scripter);
duk_put_global_string(scripter->context, SCRIPTER_SELF_NAME);
// Inject API
scriptApiAdd(scripter);
}
void scripterDispose(scripter_t *scripter) {
duk_destroy_heap(scripter->context);
}
scripter_t * scripterFromContext(scriptercontext_t *ctx) {
// Switch to global object
duk_push_global_object(ctx);
// Get the string in the object.
duk_get_prop_string(ctx, -1, SCRIPTER_SELF_NAME);
// Get the pointer from that string.
scripter_t *scripter = (scripter_t *)duk_get_pointer(ctx, -1);
// Pop the string.
duk_pop(ctx);
// Pop the global.
duk_pop(ctx);
return scripter;
}
void scripterDefineMethod(scripter_t *scripter,
char *name, int32_t argCount, scriptermethod_t *method
) {
duk_push_c_function(scripter->context, method, argCount);
duk_put_global_string(scripter->context, name);
}
bool scripterInvokeMethodSimple(scripter_t *scripter, char *method) {
// Push global
duk_push_global_object(scripter->context);
// Push method string
duk_get_prop_string(scripter->context, -1, method);
// Invoke string method
if(duk_pcall(scripter->context, 0) != 0) {
printf("Error: %s\n", duk_safe_to_string(scripter->context, -1));
return false;
}
// Pop result
duk_pop(scripter->context);
// Pop global
duk_pop(scripter->context);
return true;
}

54
src/script/scripter.h Normal file
View File

@ -0,0 +1,54 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "api/api.h"
/**
* Initialize the scripter engine.
*
* @param scripter Scripter engine to initialize.
* @param engine Game engine to use.
*/
void scripterInit(scripter_t *scripter, engine_t *engine);
/**
* Dispose a previously created scripter instance.
*
* @param scripter Scripter to dispose.
*/
void scripterDispose(scripter_t *scripter);
/**
* Retreive the scripter instance frm a scripter context.
*
* @param ctx Scripter context.
* @return Pointer to the scripter instance.
*/
scripter_t * scripterFromContext(scriptercontext_t *ctx);
/**
* Define a method onto the global scripter stack.
*
* @param scripter Scripter to define onto.
* @param name Name of the method.
* @param argCount Arguments that the method takes.
* @param method Pointer to the method to receive the callback.
*/
void scripterDefineMethod(scripter_t *scripter,
char *name, int32_t argCount, scriptermethod_t *method
);
/**
* Invoke a method (without arguments) off the global stack.
*
* @param scripter Scripter to invoke frmo
* @param method Method to invoke.
* @return True if successful, otherwise false.
*/
bool scripterInvokeMethodSimple(scripter_t *scripter, char *method);

16
src/scripts/main.ts Normal file
View File

@ -0,0 +1,16 @@
import { Primitive } from "./primitive";
let cube:PointerPrimitive;
let prim = new Primitive();
const init = () => {
cube = cubeCreate();
print("Created cube", cube);
}
const update = () => {
primitiveDraw(cube, 0, -1);
}
const dispose = () => {
}

5
src/scripts/primitive.ts Normal file
View File

@ -0,0 +1,5 @@
export class Primitive {
constructor() {
print('Hello Class!');
}
}

View File

@ -38,6 +38,8 @@ void imageSetTextureAndCrop(image_t *image, texture_t *texture,
v1 = v0 + (height / texture->height);
image->texture = texture;
image->width = width;
image->height = height;
quadInit(&image->quad, 0,
0,0,u0,v0,
1,1,u1,v1