From c87f98ce7faed9ba1d2acc9e0e9c9eb5bfb32bfe Mon Sep 17 00:00:00 2001 From: Karl Kurbjun Date: Mon, 17 Apr 2006 03:09:29 +0000 Subject: Finally add support for unlimited number of addons and demos. Also cleaned up the code and made a general function to handle the addons and demos. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9700 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/doom/rockdoom.c | 97 ++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 57 deletions(-) (limited to 'apps') diff --git a/apps/plugins/doom/rockdoom.c b/apps/plugins/doom/rockdoom.c index b4d2692af4..fab1fb308e 100644 --- a/apps/plugins/doom/rockdoom.c +++ b/apps/plugins/doom/rockdoom.c @@ -240,8 +240,8 @@ const unsigned char wads_builtin[7][30] = }; int namemap[7]; -static struct opt_items addons[10]; -static struct opt_items demolmp[11]; +static struct opt_items *addons; +static struct opt_items *demolmp; char addon[200]; // This sets up the base game and builds up myargv/c bool Dhandle_ver (int dver) @@ -391,67 +391,54 @@ int Dbuild_base (struct opt_items *names) return i; } -int Dbuild_addons(struct opt_items *names, char *firstentry, char *directory, char *stringmatch) +// This is a general function that takes in an opt_items structure and makes a list +// of files within it based on matching the string stringmatch to the files. +int Dbuild_filelist(struct opt_items **names, char *firstentry, char *directory, char *stringmatch) { - int i=1; + int i=0; + DIR *filedir; + struct dirent *dptr; + char *startpt; + struct opt_items *temp; - DIR *addondir; - struct dirent *dptr; - char *startpt; + filedir=opendir(directory); -// startpt=malloc(strlen("No Addon")*sizeof(char)); // Add this on to allow for no addon to be played -// strcpy(startpt,"No Addon"); - names[0].string=firstentry; - names[0].voice_id=0; - - addondir=opendir(directory); - if(addondir==NULL) - return 1; - - while((dptr=rb->readdir(addondir)) && i<10) + if(filedir==NULL) { - if(rb->strcasestr(dptr->d_name, stringmatch)) - { - startpt=malloc(strlen(dptr->d_name)*sizeof(char)); - strcpy(startpt,dptr->d_name); - names[i].string=startpt; - names[i].voice_id=0; - i++; - } + temp=malloc(sizeof(struct opt_items)); + temp[0].string=firstentry; + temp[0].voice_id=0; + *names=temp; + return 1; } - closedir(addondir); - return i; -} -int Dbuild_demos(struct opt_items *names) -{ - int i=1; - - DIR *demos; - struct dirent *dptr; - char *startpt; + // Get the total number of entries + while((dptr=rb->readdir(filedir))) + i++; - startpt=malloc(strlen("No Demo")*sizeof(char)); // Add this on to allow for no demo to be played - strcpy(startpt,"No Demo"); - names[0].string=startpt; - names[0].voice_id=0; + // Reset the directory + closedir(filedir); + filedir=opendir(directory); - demos=opendir(GAMEBASE"demos/"); - if(demos==NULL) - return 1; + i++; + temp=malloc(i*sizeof(struct opt_items)); + temp[0].string=firstentry; + temp[0].voice_id=0; + i=1; - while((dptr=rb->readdir(demos)) && i<11) + while((dptr=rb->readdir(filedir))) { - if(rb->strcasestr(dptr->d_name, ".LMP")) + if(rb->strcasestr(dptr->d_name, stringmatch)) { startpt=malloc(strlen(dptr->d_name)*sizeof(char)); strcpy(startpt,dptr->d_name); - names[i].string=startpt; - names[i].voice_id=0; + temp[i].string=startpt; + temp[i].voice_id=0; i++; } } - closedir(demos); + closedir(filedir); + *names=temp; return i; } @@ -729,11 +716,11 @@ int doom_menu() return -1; } - int numadd=Dbuild_addons(addons, "No Addons", GAMEBASE"addons/", ".WAD" ); + int numadd=Dbuild_filelist(&addons, "No Addons", GAMEBASE"addons/", ".WAD" ); - int numdemos=Dbuild_demos(demolmp); - argvlist.demonum=0; + int numdemos=Dbuild_filelist(&demolmp, "No Demos", GAMEBASE"demos/", ".LMP" ); + argvlist.demonum=0; argvlist.addonnum=0; gamever=status-1; @@ -810,7 +797,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) // We're using doom's memory management since it implements a proper free (and re-uses the memory) // and now with prboom's code: realloc and calloc - printf ("Z_Init: Init zone memory allocation daemon. \n"); + printf ("Z_Init: Init zone memory allocation daemon.\n"); Z_Init (); printf ("M_LoadDefaults: Load system defaults.\n"); @@ -826,10 +813,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) rb->splash(HZ*2, true, "Welcome to RockDoom"); #endif - myargv = malloc(sizeof(char *)*MAXARGVS); - memset(myargv,0,sizeof(char *)*MAXARGVS); - myargv[0]="doom.rock"; - myargc=1; + myargv =0; + myargc=0; int result=doom_menu(); @@ -865,8 +850,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) fpoint--; } -// rb->splash(HZ, true, "Bye"); - #ifdef HAVE_ADJUSTABLE_CPU_FREQ rb->cpu_boost(false); #endif -- cgit v1.2.3