[ADD] timing and coredump

This commit is contained in:
Sem van der Hoeven
2021-05-19 23:33:19 +02:00
parent 28d29b75f3
commit f3241423a1
8 changed files with 100 additions and 2 deletions

View File

@@ -9,6 +9,7 @@
#include <vita2d.h>
#include "sprites/sprites.h"
#include "timing/timing.h"
// 14 april 2021: 11:00-15:00
@@ -16,6 +17,17 @@
// extern unsigned char _binary_image_png_start;
/**
* @brief should be called when an unhandlable exception or error occurs. Triggers coredump.
*
*/
__attribute__((__noreturn__))
void shit_yourself(void){
while(1){
*(int *)(0xAA) = 0x55; // trigger coredump
}
}
int main(int argc, char *argv[])
{
@@ -39,8 +51,15 @@ int main(int argc, char *argv[])
BULLET b1 = {1,200,200,RGBA8(255,0,255,255)};
SceUInt64 deltaTime = 0; // delta time in ms
SceKernelSysClock sysclock;
while (1)
{
deltaTime = timing_get_deltatime(&sysclock);
if (deltaTime < 0)
shit_yourself();
sceCtrlPeekBufferPositive(0, &pad, 1);
if (pad.buttons & SCE_CTRL_START)
@@ -51,9 +70,15 @@ int main(int argc, char *argv[])
// vita2d_draw_texture(image, 100, 100);
vita2d_pgf_draw_text(pgf, 700, 30, RGBA8(0,255,0,255), 1.0f, "PGF Font sample!");
char text[80] = "process time: ";
sprintf(text, "%lld ms", deltaTime);
vita2d_pvf_draw_text(pvf, 700, 80, RGBA8(0,255,0,255), 1.0f, "PVF Font sample!");
char fps[15] = "fps: ";
sprintf(fps, "%d", timing_get_fps(deltaTime));
vita2d_pgf_draw_text(pgf, 700, 30, RGBA8(0, 255, 0, 255), 1.0f, text);
vita2d_pvf_draw_text(pvf, 700, 80, RGBA8(0,255,0,255), 1.0f, fps);
sprites_draw_bullet(&b1);

View File

@@ -23,6 +23,8 @@ typedef struct bullet_sprite_t
unsigned int color; // color of the bullet
} BULLET;
/**
* @brief function that draws the given bullet, if it is active
*

19
src/timing/timing.c Normal file
View File

@@ -0,0 +1,19 @@
#include <psp2/kernel/processmgr.h>
#include "timing.h"
static SceUInt64 lastFrameTime = 0;
SceUInt64 timing_get_deltatime(SceKernelSysClock *sysclock)
{
lastFrameTime = *sysclock; // put the last measured process time in lastFrameTime
uint8_t ret = sceKernelGetProcessTime(sysclock); // sysclock now holds the current process time
if (ret < 0)
return -1;
return (*sysclock - lastFrameTime) / 1000.0; // delta is the new time - the last time
}
uint8_t timing_get_fps(SceUInt64 dt)
{
return (1 / (dt / 1000.0));
}

21
src/timing/timing.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef TIMING_H
#define TIMING_H
#include <psp2/kernel/processmgr.h>
/**
* @brief gets the delta time in ms. (the duration since this function was last called)
*
* @param sysclock the system kernel clock pointer to use
* @return SceUInt64 the delta time in ms
*/
SceUInt64 timing_get_deltatime(SceKernelSysClock *sysclock);
/**
* @brief calculates the fps based on the given delta time
*
* @param dt the delta time in ms
* @return uint8_t the fps
*/
uint8_t timing_get_fps(SceUInt64 dt);
#endif