Use C++11 / C++14 in Particle example

This is the only C++ code in the project and it will require at least devkitPPC release 28.
This commit is contained in:
Crayon2000 2017-02-03 23:21:35 -05:00
parent 41ba167a30
commit 145f8e439d

View file

@ -26,7 +26,6 @@
// Random Number (0 - 1) in float // Random Number (0 - 1) in float
#define RANDOM ((((float)(rand() % 12))/12)-0.5) #define RANDOM ((((float)(rand() % 12))/12)-0.5)
using std::vector;
Mtx GXmodelView2D; Mtx GXmodelView2D;
// Basic structure to hold particle data // Basic structure to hold particle data
@ -44,9 +43,9 @@ typedef struct Particle {
} Particle; } Particle;
// Vector used as a container to iterate through all members of GRRLIB_texImg // Vector used as a container to iterate through all members of GRRLIB_texImg
static vector<GRRLIB_texImg *> TextureList; static std::vector<GRRLIB_texImg *> TextureList;
static vector<Particle *> ParticleList; static std::vector<Particle *> ParticleList;
static vector<Particle *> ParticleListTmp; static std::vector<Particle *> ParticleListTmp;
// Declare static functions // Declare static functions
static void ExitGame(); static void ExitGame();
@ -58,10 +57,6 @@ static u8 ClampVar8 (f32 Value);
// Initialize general variables // Initialize general variables
extern GXRModeObj *rmode; extern GXRModeObj *rmode;
ir_t P1Mote;
short WinW;
short WinH;
int P1MX, P1MY;
// Prepare Graphics // Prepare Graphics
GRRLIB_texImg *GFX_Background; GRRLIB_texImg *GFX_Background;
@ -71,15 +66,14 @@ GRRLIB_texImg *GFX_Font;
int main() { int main() {
u32 WPADKeyDown; ir_t P1Mote;
u8 FPS = 0; u8 FPS = 0;
u32 ParticleCnt = 0;
// Init GRRLIB & WiiUse // Init GRRLIB & WiiUse
GRRLIB_Init(); GRRLIB_Init();
WinW = rmode->fbWidth; short WinW = rmode->fbWidth;
WinH = rmode->efbHeight; short WinH = rmode->efbHeight;
WPAD_Init(); WPAD_Init();
WPAD_SetIdleTimeout( 60*10 ); WPAD_SetIdleTimeout( 60*10 );
WPAD_SetDataFormat( WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR ); WPAD_SetDataFormat( WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR );
@ -96,38 +90,31 @@ int main() {
GRRLIB_SetMidHandle( GFX_Smoke, true ); GRRLIB_SetMidHandle( GFX_Smoke, true );
// Feed the vector with the textures // Feed the vector with the textures
TextureList.push_back( GFX_Background ); TextureList = { GFX_Background, GFX_Crosshair, GFX_Smoke, GFX_Font };
TextureList.push_back( GFX_Crosshair );
TextureList.push_back( GFX_Smoke );
TextureList.push_back( GFX_Font );
while (true) { while (true) {
WPAD_ScanPads(); WPAD_ScanPads();
WPADKeyDown = WPAD_ButtonsDown(WPAD_CHAN_0); u32 WPADKeyDown = WPAD_ButtonsDown(WPAD_CHAN_0);
WPAD_SetVRes(WPAD_CHAN_0, WinW, WinH); WPAD_SetVRes(WPAD_CHAN_0, WinW, WinH);
WPAD_IR(WPAD_CHAN_0, &P1Mote); WPAD_IR(WPAD_CHAN_0, &P1Mote);
// Resetting Vars // Resetting Vars
GRRLIB_SetBlend( GRRLIB_BLEND_ALPHA ); GRRLIB_SetBlend( GRRLIB_BLEND_ALPHA );
ParticleCnt = 0; u32 ParticleCnt = 0;
// WiiMote IR Viewport correction // WiiMote IR Viewport correction
P1MX = P1Mote.sx - 150; int P1MX = P1Mote.sx - 150;
P1MY = P1Mote.sy - 150; int P1MY = P1Mote.sy - 150;
// Drawing Background // Drawing Background
GRRLIB_DrawImg( 0, 0, GFX_Background, 0, 1, 1, RGBA(255, 255, 255, 255) ); GRRLIB_DrawImg( 0, 0, GFX_Background, 0, 1, 1, RGBA(255, 255, 255, 255) );
// Add any pending objects into the main container // Add any pending objects into the main container
if (ParticleListTmp.size()) { ParticleList.insert(ParticleList.end(), ParticleListTmp.begin(), ParticleListTmp.end());
for(u32 i = 0; i<ParticleListTmp.size();i++) { ParticleListTmp.clear();
ParticleList.push_back(ParticleListTmp[i]);
}
ParticleListTmp.clear();
}
// Update and draw all particles // Update and draw all particles
for (vector<Particle *>::iterator PartIter = ParticleList.begin(); PartIter != ParticleList.end();) { for (auto PartIter = ParticleList.begin(); PartIter != ParticleList.end();) {
if (updateParticle((*PartIter)) == true) { if (updateParticle((*PartIter)) == true) {
GRRLIB_DrawImg( (*PartIter)->x, (*PartIter)->y, (*PartIter)->tex, (*PartIter)->rot, (*PartIter)->scale, (*PartIter)->scale, RGBA( (*PartIter)->red, (*PartIter)->green, (*PartIter)->blue, ClampVar8((*PartIter)->alpha*255) ) ); GRRLIB_DrawImg( (*PartIter)->x, (*PartIter)->y, (*PartIter)->tex, (*PartIter)->rot, (*PartIter)->scale, (*PartIter)->scale, RGBA( (*PartIter)->red, (*PartIter)->green, (*PartIter)->blue, ClampVar8((*PartIter)->alpha*255) ) );
} else { } else {
@ -135,7 +122,7 @@ int main() {
ParticleList.erase(PartIter); ParticleList.erase(PartIter);
continue; continue;
} }
ParticleCnt += 1; ParticleCnt++;
PartIter++; PartIter++;
} }
@ -255,9 +242,8 @@ static bool updateParticle( Particle *part ) {
static void ExitGame() { static void ExitGame() {
// Free all memory used by textures. // Free all memory used by textures.
for (vector<GRRLIB_texImg *>::iterator TexIter = TextureList.begin(); TexIter != TextureList.end(); TexIter++) { for (auto &TexIter : TextureList) {
free((*TexIter)->data); GRRLIB_FreeTexture(TexIter);
free((*TexIter));
} }
TextureList.clear(); TextureList.clear();