C:/DevKitPro/!MDuel/source/main.cpp

Go to the documentation of this file.
00001 /*
00002  * Marshmallow Duel DS v2
00003  * Copyright © 2007 Sam Pospischil http://pospi.spadgos.com
00004  * 
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  */
00019 
00020 // Includes
00021 #include <PA9.h>       // Include for PA_Lib
00022 #include <dswifi9.h>
00023 #include <vector>
00024 #include <string>
00025         using std::vector;
00026         using std::string;
00027 
00028 #include "macros.h"
00029 #include "spriteManager.h"
00030 #include "gameManager.h"
00031 #include "menuTitle.h"
00032 #include "menuBottom.h"
00033 #include "menuGBottom.h"
00034 
00035 //graphics
00036 #ifndef _ALLGRAPHICS_
00037 #define _ALLGRAPHICS_
00038 #include "../data/all_gfx_ed.c"
00039 #endif
00040 //sounds
00041 #ifdef __WITHSOUND
00042 #include "boomflyF.h"
00043 #include "bootsF.h"
00044 #include "BulletReflect.h"
00045 #include "dunceF.h"
00046 #include "HookHit.h"
00047 #include "invisibleF.h"
00048 #include "lazerF.h"
00049 #include "lightningarmedF.h"
00050 #include "lightninghitF.h"
00051 #include "magnetF.h"
00052 #include "mineDrop.h"
00053 #include "mineExp.h"
00054 #include "net.h"
00055 #include "paraCloseF.h"
00056 #include "paraOpenF.h"
00057 #include "gotPickup.h"
00058 #include "skull.h"
00059 #include "skullPickup.h"
00060 #include "splashBig.h"
00061 #include "splashSmall.h"
00062 #include "teleF.h"
00063 #include "thrown.h"
00064 #include "visableF.h"
00065 #include "WeasAttack2.h"
00066 #include "WeasAttackF.h"
00067 #include "WeasRelease1.h"
00068 #include "WeasRelease2.h"
00069 #include "WeasRun1.h"
00070 #include "WeasRun2.h"
00071 #include "WeasRun3.h"
00072 #include "platformExplode.h"
00073 #include "spawnPuff.h"
00074 #include "menuMove.h"
00075 #include "menuOk.h"
00076 #include "menuCancel.h"
00077 /*#ifdef __WITHMENUTRACK
00078         #include "opening.h"
00079 #endif*/
00080 #endif
00081 
00082 //end asset loading
00083 //start actual program
00084 
00085 //==============================================================================================
00086 //==============================================================================================
00087 //HERE IS SOME AWESOME DEBUGGING WHICH IS REALLY NOT MUCH USE TO ME. MAYBE SOME OTHER TIME.
00088 
00089 /*#ifdef __MDDEBUG
00090         
00091         #include <list>
00092         #include <iterator>
00093         
00094         typedef struct {
00095                 int     address;
00096                 int     size;
00097                 char file[64];
00098                 int     line;
00099         } ALLOC_INFO;
00100 
00101         typedef list<ALLOC_INFO*> AllocList;
00102         
00103         AllocList *allocList;
00104         
00105         void AddTrack(int addr,  int asize,  const char *fname, int lnum)
00106         {
00107                 ALLOC_INFO *info;
00108                 
00109                 if(!allocList) {
00110                         allocList = new(AllocList);
00111                 }
00112                 
00113                 info = new(ALLOC_INFO);
00114                 info->address = addr;
00115                 strncpy(info->file, fname, 63);
00116                 info->line = lnum;
00117                 info->size = asize;
00118                 allocList->insert(allocList->begin(), info);
00119         };
00120         
00121         void RemoveTrack(int addr)
00122         {
00123                 AllocList::iterator i;
00124                 
00125                 if(!allocList)
00126                         return;
00127                 for(i = allocList->begin(); i != allocList->end(); i++)
00128                 {
00129                         if((*i)->address == addr)
00130                         {
00131                                 allocList->remove((*i));
00132                                 break;
00133                         }
00134                 }
00135         };
00136         
00137         void DumpUnfreed()
00138         {
00139                 AllocList::iterator i;
00140                 int totalSize = 0;
00141                 string buf;
00142                 
00143                 if(!allocList)
00144                   return;
00145                 
00146                 for(i = allocList->begin(); i != allocList->end(); i++) {
00147                         char temp[256];
00148                         sprintf(temp, "%-50s: LINE %d, ADDRESS %d, %d unfreed\n",
00149                           (*i)->file, (*i)->line, (*i)->address, (*i)->size);
00150                         buf += temp;
00151                         totalSize += (*i)->size;
00152                 }
00153                 //sprintf(buf, "-----------------------------------------------------------\n");
00154                 //PA_OutputText(0, 0, 0, buf);
00155                 //sprintf(buf, "Total Unfreed: %d bytes\n", totalSize);
00156                 
00157                 PA_OutputText(0, 0, 0, const_cast<char *>(buf.c_str()));
00158         };
00159         
00160         inline void * operator new(unsigned int size, const char *file, int line)
00161         {
00162           void *ptr = (void *)malloc(size);
00163           AddTrack((int)ptr, size, file, line);
00164           return(ptr);
00165         };
00166         inline void operator delete(void *p)
00167         {
00168           RemoveTrack((int)p);
00169           free(p);
00170         };
00171         
00172         #define DEBUG_NEW new(__FILE__, __LINE__)
00173         #define new DEBUG_NEW
00174 #endif*/
00175 
00176 //==============================================================================================
00177 //==============================================================================================
00178 
00179 int main(int argc, char ** argv)
00180 {
00181         PA_Init();      // Initializes PA_Lib
00182         PA_InitRand();  // random numbers are go!
00183         #ifdef __WITHSOUND
00184         PA_InitSound(); // sounds!
00185         #endif
00186         PA_InitVBL();   // Initializes a standard VBL
00187 
00188         #ifdef __MDDEBUG
00189         PA_WaitForVBL();  PA_WaitForVBL();  PA_WaitForVBL();  // wait a few VBLs
00190         fatInitDefault();  // FAT driver init
00191         FILE* logFile = fopen(LOGFILE, "a+");
00192         if (logFile)
00193                 fprintf(logFile, "\n\n\n\n=========================================\nNEW GAME!\n\n\n\n");
00194         fclose(logFile);
00195         #endif
00196         
00197         //start timer system. We get roughly 1,100 hours of play before the timer overflows. Should be alright :P
00198         StartTime(true);
00199         
00200         PA_InitCustomText(0, 2, Font);  //initialise text subsystems
00201         PA_InitCustomText(1, 2, Font);
00202         
00203         //sprite managers
00204         gameManager *gm = new gameManager(1);
00205         menuTitle *menuTop = new menuTitle(1);
00206         menuBottom *menuBase = new menuBottom(0);
00207         menuGBottom *gameBase = new menuGBottom(0);
00208         
00209         gm->statTimerID = NewTimer(true);               //timer for stats recording
00210         
00211         gm->loadEnvSpriteSet(envSprites_Pal, envSprites_Sprite);
00212         gm->loadPickupSpriteSet(pickupSprites_Pal, pickupSprites_Sprite);
00213         gm->loadFXSpriteSet(effectSprites_Pal, effectSprites_Sprite);
00214         gm->loadDunceSpriteSet(dunceHatSprite_Pal, dunceHatSprite_Sprite);
00215         gm->loadBootsSpriteSet(bootsSprite_Pal, bootsSprite_Sprite);
00216         
00217         gm->player1000VPalleteData = player1000V_Pal;
00218         
00219         menuBase->loadCursorSpriteSet(menuCursors_Pal, menuCursors_Sprite);
00220         menuBase->loadPickupSpriteSet(pickupSprites_Pal, pickupSprites_Sprite);
00221         menuBase->loadMenuSpriteSet(menuSprites_Pal, menuSprites_Sprite);
00222         menuBase->playerPallete1 = playerSprite1_Pal;
00223         menuBase->playerPallete2 = playerSprite3_Pal;
00224         menuBase->playerPallete3 = playerSprite2_Pal;
00225         menuBase->playerPallete4 = playerSprite4_Pal;
00226         menuBase->playerSprite1 = playerSprite1_Sprite;
00227         menuBase->playerSprite2 = playerSprite2_Sprite;
00228         menuBase->playerSprite3 = playerSprite3_Sprite;
00229         
00230         gameBase->loadMenuSpriteSet(menuSprites_Pal, menuSprites_Sprite);
00231         gameBase->loadSpawnerSpriteSet(spawnerSpriteX_Pal, spawnerSpriteX_Sprite);
00232         gameBase->loadPickupSpriteSet(pickupSprites_Pal, pickupSprites_Sprite);
00233         
00234         #ifdef __WITHSOUND
00235         /*#ifdef __WITHMENUTRACK
00236         menuBase->loadSound(&menuBase->titleMusic, opening, opening_size);
00237         #endif*/
00238         gm->loadSound(&gm->bigSplash, splashBig, splashBig_size);
00239         gm->loadSound(&gm->smallSplash, splashSmall, splashSmall_size);
00240         gm->loadSound(&gm->platformExplode, platformExplode, platformExplode_size);
00241         gm->loadSound(&gm->spawnPuff, spawnPuff, spawnPuff_size);
00242         gm->loadSound(&gm->gotPickup, gotPickup, gotPickup_size);
00243         gm->loadSound(&gm->teleport, teleF, teleF_size);
00244         gm->loadSound(&gm->skullLoop, skull, skull_size);
00245         gm->loadSound(&gm->skullPickup, skullPickup, skullPickup_size);
00246         gm->loadSound(&gm->lightningHit, lightninghitF, lightninghitF_size);
00247         gm->loadSound(&gm->lightningLoop, lightningarmedF, lightningarmedF_size);
00248         gm->loadSound(&gm->invisOn, invisibleF, invisibleF_size);
00249         gm->loadSound(&gm->invisOff, visableF, visableF_size);
00250         gm->loadSound(&gm->mineExp, mineExp, mineExp_size);
00251         gm->loadSound(&gm->mineDrop, mineDrop, mineDrop_size);
00252         gm->loadSound(&gm->gunFire, lazerF, lazerF_size);
00253         gm->loadSound(&gm->bootsJump, bootsF, bootsF_size);
00254         gm->loadSound(&gm->chutClose, paraCloseF, paraCloseF_size);
00255         gm->loadSound(&gm->chutOpen, paraOpenF, paraOpenF_size);
00256         gm->loadSound(&gm->hookHit, HookHit, HookHit_size);
00257         gm->loadSound(&gm->duncePickup, dunceF, dunceF_size);
00258         gm->loadSound(&gm->magnetLoop, magnetF, magnetF_size);
00259         gm->loadSound(&gm->netThrow, net, net_size);
00260         gm->loadSound(&gm->bulletReflect, BulletReflect, BulletReflect_size);
00261         gm->loadSound(&gm->boomerangLoop, boomflyF, boomflyF_size);
00262         gm->loadSound(&gm->throwSound, thrown, thrown_size);
00263         
00264         gm->loadSound(&gm->weaselSounds[0], WeasAttack2, WeasAttack2_size);
00265         gm->loadSound(&gm->weaselSounds[1], WeasAttackF, WeasAttackF_size);
00266         gm->loadSound(&gm->weaselSounds[2], WeasRelease1, WeasRelease1_size);
00267         gm->loadSound(&gm->weaselSounds[3], WeasRelease2, WeasRelease2_size);
00268         gm->loadSound(&gm->weaselSounds[4], WeasRun1, WeasRun1_size);
00269         gm->loadSound(&gm->weaselSounds[5], WeasRun2, WeasRun2_size);
00270         gm->loadSound(&gm->weaselSounds[6], WeasRun3, WeasRun3_size);
00271 
00272         menuBase->loadSound(&menuBase->menuMove, menuMove, menuMove_size);
00273         menuBase->loadSound(&menuBase->menuOk, menuOk, menuOk_size);
00274         menuBase->loadSound(&menuBase->menuCancel, menuCancel, menuCancel_size);
00275         #endif
00276         
00277         //spriteManager associations
00278         menuBase->menuTop = menuTop;
00279         menuBase->gameTop = gm;
00280         menuBase->gameBottom = gameBase;
00281         
00282         gameBase->menuTop = menuTop;
00283         gameBase->menuBase = menuBase;
00284         gameBase->gameTop = gm;
00285         
00286         gm->menuTop = menuTop;
00287         gm->menuBase = menuBase;
00288         gm->gameBottom = gameBase;
00289         
00290         //ok - turn on the spriteManagers we want to use now.
00291         menuTop->activate();
00292         menuBase->activate();
00293         
00294         // Unfortunately try/catch blocks don't seem to work on the DS. Boo!
00295         //try {
00296                 while (1)
00297                 {
00298                         if (menuTop->isActive())
00299                                 menuTop->gameTick();
00300                         if (menuBase->isActive())
00301                                 menuBase->gameTick();
00302                         if (gm->isActive())
00303                                 gm->gameTick();
00304                         if (gameBase->isActive())
00305                                 gameBase->gameTick();
00306                         
00307                         PA_CheckLid();  //check for lid pausing
00308                         PA_WaitForVBL();
00309                 } 
00310         /*} catch (...) {
00311                 DumpUnfreed();
00312         }*/
00313         
00314         return 0;
00315 }
00316 

Generated on Tue Mar 13 23:27:52 2007 for MDuel DS by  doxygen 1.5.1-p1