171 lines
3.5 KiB
C++
171 lines
3.5 KiB
C++
#include <azur/azur.h>
|
|
#include <azur/gint/render.h>
|
|
#include <gint/drivers/r61524.h>
|
|
#include <gint/rtc.h>
|
|
|
|
#include <gint/keyboard.h>
|
|
|
|
#include <libprof.h>
|
|
#include <gint/usb.h>
|
|
#include <gint/usb-ff-bulk.h>
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <fxlibc/printf.h>
|
|
#include <cstdint>
|
|
|
|
|
|
#include "utilities.h"
|
|
#include "particles.h"
|
|
#include <vector>
|
|
|
|
bool screenshot = false;
|
|
bool record = false;
|
|
bool exitToOS = false;
|
|
|
|
|
|
std::vector<Particle*> MyParticles;
|
|
|
|
|
|
void Create_Explosion( void )
|
|
{
|
|
uint16_t xexplosion = rand() % 396;
|
|
uint16_t yexplosion = rand() % 224;
|
|
|
|
for(int i=0; i<50; i++)
|
|
{
|
|
Particle *p = new Particle( xexplosion, yexplosion );
|
|
MyParticles.push_back( p );
|
|
}
|
|
}
|
|
|
|
static void get_inputs( void )
|
|
{
|
|
key_event_t ev;
|
|
while((ev = pollevent()).type != KEYEV_NONE)
|
|
{
|
|
|
|
}
|
|
|
|
if(keydown(KEY_SHIFT)) {Create_Explosion();}
|
|
|
|
if(keydown(KEY_EXIT)) {exitToOS = true; };
|
|
|
|
if(keydown(KEY_7)) {screenshot = true; };
|
|
if(keydown(KEY_8)) {record = !record; };
|
|
}
|
|
|
|
|
|
static void update( float dt )
|
|
{
|
|
// all update stuff dependng on time will be done here
|
|
for(int i=0; i<MyParticles.size();i++)
|
|
{
|
|
MyParticles[i]->Update();
|
|
|
|
if(MyParticles[i]->age > MyParticles[i]->maxage)
|
|
MyParticles[i]->size--;
|
|
|
|
if (MyParticles[i]->size==0)
|
|
MyParticles.erase( MyParticles.begin() + i );
|
|
|
|
}
|
|
}
|
|
|
|
|
|
int main(void)
|
|
{
|
|
exitToOS = false;
|
|
float elapsedTime = 0.0f;
|
|
|
|
__printf_enable_fp();
|
|
__printf_enable_fixed();
|
|
|
|
azrp_config_scale(1);
|
|
azrp_shader_clear_configure();
|
|
azrp_shader_image_rgb16_configure();
|
|
azrp_shader_image_p8_configure();
|
|
azrp_shader_image_p4_configure();
|
|
|
|
srand(rtc_ticks());
|
|
|
|
//extern bopti_image_t img_plane;
|
|
|
|
usb_interface_t const *interfaces[] = { &usb_ff_bulk, NULL };
|
|
usb_open(interfaces, GINT_CALL_NULL);
|
|
|
|
prof_init();
|
|
prof_t perf_update, perf_render;
|
|
uint32_t time_update=0, time_render=0;
|
|
|
|
do
|
|
{
|
|
perf_update = prof_make();
|
|
prof_enter(perf_update);
|
|
|
|
{
|
|
// all the stuff to be update should be put here
|
|
|
|
// read inputs from the player
|
|
get_inputs( );
|
|
|
|
// update as per the time spend to do the loop
|
|
update( elapsedTime );
|
|
}
|
|
|
|
prof_leave(perf_update);
|
|
time_update = prof_time(perf_update);
|
|
|
|
perf_render = prof_make();
|
|
prof_enter(perf_render);
|
|
|
|
{
|
|
// all the stuff to be rendered should be put here
|
|
azrp_clear( C_BLACK );
|
|
|
|
Azur_draw_text(1,01, "Update = %.0f microseconds", (float) time_update );
|
|
Azur_draw_text(1,11, "Render = %.0f microseconds", (float) time_render );
|
|
Azur_draw_text(1,21, ">Total = %.3f milliseconds", (float) elapsedTime / 1000.0f );
|
|
|
|
Azur_draw_text(1,41, "FPS = %.3f", (float) (1000000.0f / elapsedTime) );
|
|
|
|
Azur_draw_text(1,61, "Particles = %d", MyParticles.size() );
|
|
|
|
|
|
//azrp_image( 10, 50, &img_plane );
|
|
|
|
for(auto& p : MyParticles)
|
|
p->Render();
|
|
|
|
azrp_update();
|
|
}
|
|
|
|
prof_leave(perf_render);
|
|
time_render = prof_time(perf_render);
|
|
|
|
elapsedTime = ((float) (time_update+time_render));
|
|
|
|
if (screenshot && usb_is_open())
|
|
{
|
|
usb_fxlink_screenshot(false);
|
|
screenshot = false;
|
|
}
|
|
|
|
if(record && usb_is_open())
|
|
{
|
|
usb_fxlink_videocapture(false);
|
|
}
|
|
}
|
|
while (exitToOS==false);
|
|
|
|
|
|
MyParticles.clear();
|
|
|
|
|
|
prof_quit();
|
|
usb_close();
|
|
|
|
return 1;
|
|
}
|