Fries
fc7ca18fd7
i added deltatime so the bird should hopefully have the same speed if the framerate drops or if you play in PAL 50hz mode.
74 lines
1.9 KiB
C
74 lines
1.9 KiB
C
#include <grrlib.h>
|
|
#include <duktape.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <ogc/lwp_watchdog.h>
|
|
|
|
#include "data.h"
|
|
#include "wii_duk.h"
|
|
|
|
const float MICROSECOND = 0.000001f;
|
|
|
|
extern const char * program;
|
|
static bool running = true;
|
|
static GRRLIB_ttfFont * font;
|
|
static unsigned int green = RGBA(0, 255, 0, 255);
|
|
static float deltatime = 1.0f/60;
|
|
|
|
static void duk_fatal_error(void *udata, const char *msg) {
|
|
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();
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
GRRLIB_Init();
|
|
PAD_Init();
|
|
|
|
// 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);
|
|
|
|
duk_context * ctx = duk_create_heap(NULL, NULL, NULL, NULL, duk_fatal_error);
|
|
|
|
// create a wii object on the global object (globalThis)
|
|
define_wii_object(ctx, font, &running, &deltatime);
|
|
duk_put_global_string(ctx, "wii");
|
|
|
|
// evaluate functions from game.js
|
|
duk_eval_string_noresult(ctx, program);
|
|
|
|
// call start function
|
|
duk_get_global_string(ctx, "start");
|
|
duk_call(ctx, 0);
|
|
duk_pop(ctx);
|
|
|
|
while (running) {
|
|
const unsigned int beginningOfFrame = ticks_to_microsecs(gettime());
|
|
|
|
PAD_ScanPads();
|
|
|
|
// call update function
|
|
duk_get_global_string(ctx, "update");
|
|
duk_call(ctx, 0);
|
|
duk_pop(ctx);
|
|
|
|
GRRLIB_Render();
|
|
|
|
const unsigned int endOfFrame = ticks_to_microsecs(gettime());
|
|
deltatime = (endOfFrame - beginningOfFrame) * MICROSECOND;
|
|
}
|
|
|
|
duk_destroy_heap(ctx);
|
|
GRRLIB_Exit();
|
|
|
|
return 0;
|
|
}
|