245 lines
6.1 KiB
C++
245 lines
6.1 KiB
C++
#include <azur/azur.h>
|
|
#include <azur/gint/render.h>
|
|
#include <gint/drivers/r61524.h>
|
|
#include <gint/rtc.h>
|
|
|
|
#include <gint/clock.h>
|
|
#include <gint/kmalloc.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 <num/num.h>
|
|
|
|
#include "utilities.h"
|
|
#include "particles.h"
|
|
#include "starfield.h"
|
|
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
#include "MyAzurShaders.h"
|
|
|
|
|
|
bool screenshot = false;
|
|
bool record = false;
|
|
bool exitToOS = false;
|
|
|
|
#define SCALE_PIXEL 1
|
|
#define X_RESOL (DWIDTH / SCALE_PIXEL)
|
|
#define Y_RESOL (DHEIGHT / SCALE_PIXEL)
|
|
|
|
#define BIAS 1
|
|
#define NOBIAS (1-BIAS)
|
|
|
|
std::vector<Particle*> MyParticles;
|
|
std::vector<Star*> MyStars;
|
|
uint8_t texttodraw=1;
|
|
|
|
|
|
|
|
void Create_Starfield( void )
|
|
{
|
|
srand(rtc_ticks());
|
|
|
|
for(int i=0; i<100; i++)
|
|
{
|
|
Star *s = new Star( );
|
|
MyStars.push_back( s );
|
|
}
|
|
}
|
|
|
|
void Create_Explosion( void )
|
|
{
|
|
if(MyParticles.size()>=300) return;
|
|
|
|
srand(rtc_ticks());
|
|
|
|
uint16_t xexplosion = rand() % X_RESOL;
|
|
uint16_t yexplosion = rand() % Y_RESOL;
|
|
|
|
for(int i=0; i<50; i++)
|
|
{
|
|
Particle *p = new Particle( xexplosion, yexplosion );
|
|
MyParticles.push_back( p );
|
|
}
|
|
}
|
|
|
|
|
|
static void update( float dt )
|
|
{
|
|
// all update stuff depending on time will be done here
|
|
for(int i=0; i<MyParticles.size(); i++)
|
|
{
|
|
MyParticles[i]->Update( dt );
|
|
|
|
// Check if the property toberemoved has been set to "true" for particle deletion
|
|
if (MyParticles[i]->toberemoved == true)
|
|
{
|
|
delete( MyParticles[i] );
|
|
MyParticles.erase( MyParticles.begin() + i );
|
|
}
|
|
}
|
|
|
|
for(auto&s : MyStars)
|
|
s->Update( dt );
|
|
}
|
|
|
|
|
|
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; };
|
|
if(keydown(KEY_F1)) {texttodraw=0;}
|
|
if(keydown(KEY_F2)) {texttodraw=1;}
|
|
if(keydown(KEY_F3)) {texttodraw=2;}
|
|
if(keydown(KEY_F4)) {texttodraw=3;}
|
|
|
|
}
|
|
|
|
|
|
int main(void)
|
|
{
|
|
exitToOS = false;
|
|
float elapsedTime = 0.0f;
|
|
|
|
kmalloc_arena_t *_uram = kmalloc_get_arena("_uram");
|
|
kmalloc_gint_stats_t *_uram_stats;
|
|
|
|
__printf_enable_fp();
|
|
__printf_enable_fixed();
|
|
|
|
azrp_config_scale(SCALE_PIXEL);
|
|
azrp_shader_clear_configure();
|
|
azrp_shader_image_rgb16_configure();
|
|
azrp_shader_image_p8_configure();
|
|
azrp_shader_image_p4_configure();
|
|
|
|
|
|
Create_Starfield();
|
|
|
|
|
|
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 );
|
|
|
|
// update the RAM consumption status
|
|
_uram_stats = kmalloc_get_gint_stats(_uram);
|
|
}
|
|
|
|
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 );
|
|
|
|
#if(BIAS)
|
|
if (texttodraw>=1) Azur_draw_text(1,01, " FPS = %.0f", (float) (1000000.0f / elapsedTime) );
|
|
if (texttodraw>=1) Azur_draw_text(1,11, "Parts = %d", MyParticles.size() );
|
|
|
|
if (texttodraw>=2) Azur_draw_text(1,31, "Update = %.0f mc secs", (float) time_update );
|
|
if (texttodraw>=2) Azur_draw_text(1,41, "Render = %.0f mc secs", (float) time_render );
|
|
if (texttodraw>=2) Azur_draw_text(1,51, ">Total = %.3f ml secs", (float) elapsedTime / 1000.0f );
|
|
if (texttodraw>=2) Azur_draw_text(1,61, ">Total = %.0f seconds", (float) elapsedTime );
|
|
|
|
if (texttodraw>=3) Azur_draw_text(1,81, "Mem Used : %d", _uram_stats->used_memory );
|
|
if (texttodraw>=3) Azur_draw_text(1,91, "Mem Free : %d", _uram_stats->free_memory );
|
|
if (texttodraw>=3) Azur_draw_text(1,101, "Mem Peak Used : %d", _uram_stats->peak_used_memory );
|
|
|
|
if (texttodraw>=3) Azur_draw_text(1,121, "Size of Particles : %d bytes", sizeof(Particle) );
|
|
|
|
|
|
#endif
|
|
|
|
for(auto& p : MyParticles)
|
|
p->Render();
|
|
|
|
for(auto& s : MyStars)
|
|
s->Render();
|
|
|
|
azrp_update();
|
|
}
|
|
|
|
prof_leave(perf_render);
|
|
time_render = prof_time(perf_render);
|
|
|
|
#if(NOBIAS)
|
|
dclear(C_BLACK);
|
|
dprint(1,01, C_WHITE, "Update = %.0f mc secs", (float) time_update );
|
|
dprint(1,11, C_WHITE, "Render = %.0f mc secs", (float) time_render );
|
|
dprint(1,21, C_WHITE, ">Total = %.3f ml secs", (float) elapsedTime / 1000.0f );
|
|
dprint(1,31, C_WHITE, ">Total = %.0f", (float) elapsedTime );
|
|
dprint(1,41, C_WHITE, " FPS = %.0f", (float) (1000000.0f / elapsedTime) );
|
|
dprint(1,51, C_WHITE, "Parts = %d", MyParticles.size() );
|
|
dupdate();
|
|
#endif
|
|
|
|
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);
|
|
|
|
|
|
for(auto& p : MyParticles) delete(p);
|
|
MyParticles.clear();
|
|
|
|
for(auto& s : MyStars) delete(s);
|
|
MyStars.clear();
|
|
|
|
|
|
prof_quit();
|
|
usb_close();
|
|
|
|
return 1;
|
|
}
|