Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
risolvipro committed Aug 1, 2024
1 parent 6de2d5d commit bc644e5
Show file tree
Hide file tree
Showing 10 changed files with 439 additions and 272 deletions.
4 changes: 2 additions & 2 deletions Source/pdxinfo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name=PlayGB
author=Risolvi Productions
description=A Game Boy emulator based on Peanut-GB
bundleID=com.risolvipro.playgb
version=0.7.6
buildNumber=6
version=0.7.7
buildNumber=7
imagePath=launcher
13 changes: 8 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,26 @@

static int update(void* userdata);

DllExport int eventHandler(PlaydateAPI *pd, PDSystemEvent event, uint32_t arg) {

if(event == kEventInit){
DllExport int eventHandler(PlaydateAPI *pd, PDSystemEvent event, uint32_t arg)
{
if(event == kEventInit)
{
playdate = pd;

PGB_init();

pd->system->setUpdateCallback(update, pd);
}
else if (event == kEventTerminate){
else if (event == kEventTerminate)
{
PGB_quit();
}

return 0;
}

int update(void* userdata) {
int update(void* userdata)
{
PlaydateAPI *pd = userdata;

float dt = pd->system->getElapsedTime();
Expand Down
34 changes: 20 additions & 14 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

PGB_Application *PGB_App;

void PGB_init(void) {
void PGB_init(void)
{
PGB_App = pgb_malloc(sizeof(PGB_Application));

PGB_App->scene = NULL;
Expand Down Expand Up @@ -43,20 +43,23 @@ void PGB_init(void) {
PGB_present(libraryScene->scene);
}

void PGB_update(float dt) {
void PGB_update(float dt)
{
PGB_App->dt = dt;
PGB_App->crankChange = playdate->system->getCrankChange();

if(PGB_App->scene){
if(PGB_App->scene)
{
void *managedObject = PGB_App->scene->managedObject;
PGB_App->scene->update(managedObject);
}

if(PGB_App->pendingScene){
if(PGB_App->pendingScene)
{
// present pending scene

if(PGB_App->scene){
if(PGB_App->scene)
{
prefereces_save_to_disk();

void *managedObject = PGB_App->scene->managedObject;
Expand All @@ -77,29 +80,32 @@ void PGB_update(float dt) {
float refreshRate = 30;
float compensation = 0;

if(PGB_App->scene){
if(PGB_App->scene)
{
refreshRate = PGB_App->scene->preferredRefreshRate;
compensation = PGB_App->scene->refreshRateCompensation;
}

if(refreshRate > 0){
if(refreshRate > 0)
{
float refreshInterval = 1.0f / refreshRate + compensation;
while(playdate->system->getElapsedTime() < refreshInterval);
}

#endif
}

void PGB_present(PGB_Scene *scene) {
void PGB_present(PGB_Scene *scene)
{
PGB_App->pendingScene = scene;
}

void PGB_quit(void) {
void PGB_quit(void)
{
prefereces_save_to_disk();

if(PGB_App->scene){
if(PGB_App->scene)
{
void *managedObject = PGB_App->scene->managedObject;
PGB_App->scene->free(managedObject);
}
Expand Down
18 changes: 11 additions & 7 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@

#include "array.h"

PGB_Array* array_new(void) {
PGB_Array* array_new(void)
{
PGB_Array *array = pgb_malloc(sizeof(PGB_Array));
array->length = 0;
array->items = pgb_malloc(0);
array->items = NULL;

return array;
}

void array_push(PGB_Array *array, void *item) {
void array_push(PGB_Array *array, void *item)
{
array->length++;
array->items = pgb_realloc(array->items, array->length * sizeof(item));
array->items[array->length - 1] = item;
}

void array_clear(PGB_Array *array) {
void array_clear(PGB_Array *array)
{
array->length = 0;
array->items = pgb_realloc(array->items, 0);
pgb_free(array->items);
array->items = NULL;
}

void array_free(PGB_Array *array) {
void array_free(PGB_Array *array)
{
pgb_free(array->items);
pgb_free(array);
}
Loading

0 comments on commit bc644e5

Please sign in to comment.