2024-06-20 04:08:16 +00:00
|
|
|
#include <grrlib.h>
|
2024-06-19 04:51:50 +00:00
|
|
|
#include <duktape.h>
|
2024-06-21 07:45:28 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2024-06-22 05:57:08 +00:00
|
|
|
#include <ogc/lwp_watchdog.h>
|
2024-06-21 07:45:28 +00:00
|
|
|
|
2024-06-21 01:41:49 +00:00
|
|
|
#include "data.h"
|
2024-06-21 07:45:28 +00:00
|
|
|
#include "wii_duk.h"
|
2024-06-19 04:51:50 +00:00
|
|
|
|
2024-06-22 05:57:08 +00:00
|
|
|
const float MICROSECOND = 0.000001f;
|
|
|
|
|
2024-06-21 07:45:28 +00:00
|
|
|
extern const char * program;
|
2024-06-20 04:08:16 +00:00
|
|
|
static bool running = true;
|
2024-06-21 07:45:28 +00:00
|
|
|
static GRRLIB_ttfFont * font;
|
|
|
|
static unsigned int green = RGBA(0, 255, 0, 255);
|
2024-06-22 05:57:08 +00:00
|
|
|
static float deltatime = 1.0f/60;
|
2024-06-19 07:39:01 +00:00
|
|
|
|
|
|
|
static void duk_fatal_error(void *udata, const char *msg) {
|
2024-06-21 07:45:28 +00:00
|
|
|
const char * err_message_format = "an error has occured: %s";
|
|
|
|
size_t message_size = strlen(err_message_format) + strlen(msg) * sizeof(char *);
|
|
|
|
char * message = malloc(message_size);
|
|
|
|
snprintf(message, message_size, err_message_format, msg);
|
|
|
|
while (1) {
|
|
|
|
GRRLIB_PrintfTTF(0, 0, font, message, 12, green);
|
|
|
|
GRRLIB_Render();
|
2024-06-21 01:41:49 +00:00
|
|
|
}
|
2024-06-19 07:39:01 +00:00
|
|
|
}
|
|
|
|
|
2024-06-19 04:51:50 +00:00
|
|
|
int main(int argc, char **argv) {
|
2024-06-20 04:08:16 +00:00
|
|
|
GRRLIB_Init();
|
2024-06-19 07:39:01 +00:00
|
|
|
PAD_Init();
|
2024-06-19 04:51:50 +00:00
|
|
|
|
2024-06-21 07:45:28 +00:00
|
|
|
// get the pixel operator font's data pointer and size
|
|
|
|
void * pixel_operator_font;
|
|
|
|
size_t pixel_operator_font_size;
|
|
|
|
get_file_pointer("PixelOperator.ttf", &pixel_operator_font, &pixel_operator_font_size);
|
|
|
|
|
|
|
|
font = GRRLIB_LoadTTF(pixel_operator_font, pixel_operator_font_size);
|
2024-06-19 04:51:50 +00:00
|
|
|
|
2024-06-21 07:45:28 +00:00
|
|
|
duk_context * ctx = duk_create_heap(NULL, NULL, NULL, NULL, duk_fatal_error);
|
|
|
|
|
|
|
|
// create a wii object on the global object (globalThis)
|
2024-06-22 05:57:08 +00:00
|
|
|
define_wii_object(ctx, font, &running, &deltatime);
|
2024-06-19 07:39:01 +00:00
|
|
|
duk_put_global_string(ctx, "wii");
|
2024-06-19 04:51:50 +00:00
|
|
|
|
2024-06-20 04:08:16 +00:00
|
|
|
// evaluate functions from game.js
|
2024-06-19 07:39:01 +00:00
|
|
|
duk_eval_string_noresult(ctx, program);
|
2024-06-19 04:51:50 +00:00
|
|
|
|
2024-06-20 04:08:16 +00:00
|
|
|
// call start function
|
|
|
|
duk_get_global_string(ctx, "start");
|
|
|
|
duk_call(ctx, 0);
|
|
|
|
duk_pop(ctx);
|
|
|
|
|
|
|
|
while (running) {
|
2024-06-22 05:57:08 +00:00
|
|
|
const unsigned int beginningOfFrame = ticks_to_microsecs(gettime());
|
|
|
|
|
2024-06-20 04:08:16 +00:00
|
|
|
PAD_ScanPads();
|
|
|
|
|
2024-06-21 07:45:28 +00:00
|
|
|
// call update function
|
2024-06-20 04:08:16 +00:00
|
|
|
duk_get_global_string(ctx, "update");
|
|
|
|
duk_call(ctx, 0);
|
|
|
|
duk_pop(ctx);
|
|
|
|
|
|
|
|
GRRLIB_Render();
|
2024-06-22 05:57:08 +00:00
|
|
|
|
|
|
|
const unsigned int endOfFrame = ticks_to_microsecs(gettime());
|
|
|
|
deltatime = (endOfFrame - beginningOfFrame) * MICROSECOND;
|
2024-06-20 04:08:16 +00:00
|
|
|
}
|
|
|
|
|
2024-06-19 07:39:01 +00:00
|
|
|
duk_destroy_heap(ctx);
|
2024-06-20 04:08:16 +00:00
|
|
|
GRRLIB_Exit();
|
2024-06-19 04:51:50 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|