[ADD] timing and coredump
This commit is contained in:
@@ -52,6 +52,7 @@ link_directories(
|
|||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
src/main.c
|
src/main.c
|
||||||
src/sprites/sprites.c
|
src/sprites/sprites.c
|
||||||
|
src/timing/timing.c
|
||||||
../common/debugScreen.c
|
../common/debugScreen.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
30
Makefile
30
Makefile
@@ -230,6 +230,33 @@ src/sprites/sprites.c.s:
|
|||||||
$(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/sprites/sprites.c.s
|
$(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/sprites/sprites.c.s
|
||||||
.PHONY : src/sprites/sprites.c.s
|
.PHONY : src/sprites/sprites.c.s
|
||||||
|
|
||||||
|
src/timing/timing.obj: src/timing/timing.c.obj
|
||||||
|
|
||||||
|
.PHONY : src/timing/timing.obj
|
||||||
|
|
||||||
|
# target to build an object file
|
||||||
|
src/timing/timing.c.obj:
|
||||||
|
$(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/timing/timing.c.obj
|
||||||
|
.PHONY : src/timing/timing.c.obj
|
||||||
|
|
||||||
|
src/timing/timing.i: src/timing/timing.c.i
|
||||||
|
|
||||||
|
.PHONY : src/timing/timing.i
|
||||||
|
|
||||||
|
# target to preprocess a source file
|
||||||
|
src/timing/timing.c.i:
|
||||||
|
$(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/timing/timing.c.i
|
||||||
|
.PHONY : src/timing/timing.c.i
|
||||||
|
|
||||||
|
src/timing/timing.s: src/timing/timing.c.s
|
||||||
|
|
||||||
|
.PHONY : src/timing/timing.s
|
||||||
|
|
||||||
|
# target to generate assembly for a file
|
||||||
|
src/timing/timing.c.s:
|
||||||
|
$(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/timing/timing.c.s
|
||||||
|
.PHONY : src/timing/timing.c.s
|
||||||
|
|
||||||
# Help Target
|
# Help Target
|
||||||
help:
|
help:
|
||||||
@echo "The following are some of the valid targets for this Makefile:"
|
@echo "The following are some of the valid targets for this Makefile:"
|
||||||
@@ -250,6 +277,9 @@ help:
|
|||||||
@echo "... src/sprites/sprites.obj"
|
@echo "... src/sprites/sprites.obj"
|
||||||
@echo "... src/sprites/sprites.i"
|
@echo "... src/sprites/sprites.i"
|
||||||
@echo "... src/sprites/sprites.s"
|
@echo "... src/sprites/sprites.s"
|
||||||
|
@echo "... src/timing/timing.obj"
|
||||||
|
@echo "... src/timing/timing.i"
|
||||||
|
@echo "... src/timing/timing.s"
|
||||||
.PHONY : help
|
.PHONY : help
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
0
sce_sys/livearea/contents/bg.png
Executable file → Normal file
0
sce_sys/livearea/contents/bg.png
Executable file → Normal file
|
Before Width: | Height: | Size: 324 B After Width: | Height: | Size: 324 B |
0
sce_sys/livearea/contents/startup.png
Executable file → Normal file
0
sce_sys/livearea/contents/startup.png
Executable file → Normal file
|
Before Width: | Height: | Size: 928 B After Width: | Height: | Size: 928 B |
29
src/main.c
29
src/main.c
@@ -9,6 +9,7 @@
|
|||||||
#include <vita2d.h>
|
#include <vita2d.h>
|
||||||
|
|
||||||
#include "sprites/sprites.h"
|
#include "sprites/sprites.h"
|
||||||
|
#include "timing/timing.h"
|
||||||
|
|
||||||
// 14 april 2021: 11:00-15:00
|
// 14 april 2021: 11:00-15:00
|
||||||
|
|
||||||
@@ -16,6 +17,17 @@
|
|||||||
|
|
||||||
// extern unsigned char _binary_image_png_start;
|
// 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[])
|
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)};
|
BULLET b1 = {1,200,200,RGBA8(255,0,255,255)};
|
||||||
|
|
||||||
|
SceUInt64 deltaTime = 0; // delta time in ms
|
||||||
|
SceKernelSysClock sysclock;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
deltaTime = timing_get_deltatime(&sysclock);
|
||||||
|
if (deltaTime < 0)
|
||||||
|
shit_yourself();
|
||||||
|
|
||||||
sceCtrlPeekBufferPositive(0, &pad, 1);
|
sceCtrlPeekBufferPositive(0, &pad, 1);
|
||||||
|
|
||||||
if (pad.buttons & SCE_CTRL_START)
|
if (pad.buttons & SCE_CTRL_START)
|
||||||
@@ -51,9 +70,15 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// vita2d_draw_texture(image, 100, 100);
|
// 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);
|
sprites_draw_bullet(&b1);
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ typedef struct bullet_sprite_t
|
|||||||
unsigned int color; // color of the bullet
|
unsigned int color; // color of the bullet
|
||||||
} BULLET;
|
} BULLET;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief function that draws the given bullet, if it is active
|
* @brief function that draws the given bullet, if it is active
|
||||||
*
|
*
|
||||||
|
|||||||
19
src/timing/timing.c
Normal file
19
src/timing/timing.c
Normal 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
21
src/timing/timing.h
Normal 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
|
||||||
Reference in New Issue
Block a user