Happy fun memory usage optimization

git-svn-id: https://svn.eduke32.com/eduke32@385 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2006-12-05 21:22:19 +00:00
parent ccb93c19d8
commit c8abb8384d
2 changed files with 50 additions and 23 deletions

View file

@ -2370,14 +2370,18 @@ char parsecommand(void)
if (*textptr == 0) break; if (*textptr == 0) break;
} }
j = 0; j = 0;
if (music_fn[k][i] == NULL)
music_fn[k][i] = Bcalloc(BMAX_PATH,sizeof(char));
while (isaltok(*(textptr+j))) while (isaltok(*(textptr+j)))
{ {
music_fn[k][i][j] = textptr[j]; tempbuf[j] = textptr[j];
j++; j++;
} }
music_fn[k][i][j] = '\0'; tempbuf[j] = '\0';
if (music_fn[k][i] == NULL)
music_fn[k][i] = Bcalloc(Bstrlen(tempbuf)+1,sizeof(char));
Bstrcpy(music_fn[k][i],tempbuf);
textptr += j; textptr += j;
if (i > MAXLEVELS-1) break; if (i > MAXLEVELS-1) break;
i++; i++;
@ -4519,12 +4523,9 @@ repeatcase:
i = 0; i = 0;
if (level_file_names[j*MAXLEVELS+k] == NULL)
level_file_names[j*MAXLEVELS+k] = Bcalloc(BMAX_PATH,sizeof(char));
while (*textptr != ' ' && *textptr != '\t' && *textptr != 0x0a) while (*textptr != ' ' && *textptr != '\t' && *textptr != 0x0a)
{ {
level_file_names[j*MAXLEVELS+k][i] = *textptr; tempbuf[i] = *textptr;
textptr++,i++; textptr++,i++;
if (i >= BMAX_PATH) if (i >= BMAX_PATH)
{ {
@ -4534,7 +4535,14 @@ repeatcase:
break; break;
} }
} }
level_file_names[j*MAXLEVELS+k][i] = '\0'; tempbuf[i] = '\0';
if (level_file_names[j*MAXLEVELS+k] == NULL)
level_file_names[j*MAXLEVELS+k] = Bcalloc(Bstrlen(tempbuf)+1,sizeof(char));
/* initprintf("level file name string len: %ld\n",Bstrlen(tempbuf)); */
Bstrcpy(level_file_names[j*MAXLEVELS+k],tempbuf);
while (*textptr == ' ' || *textptr == '\t') textptr++; while (*textptr == ' ' || *textptr == '\t') textptr++;
@ -4554,22 +4562,28 @@ repeatcase:
i = 0; i = 0;
if (level_names[j*MAXLEVELS+k] == NULL)
level_names[j*MAXLEVELS+k] = Bcalloc(32,sizeof(char));
while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0) while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0)
{ {
level_names[j*MAXLEVELS+k][i] = toupper(*textptr); tempbuf[i] = Btoupper(*textptr);
textptr++,i++; textptr++,i++;
if (i >= 32) if (i >= 32)
{ {
initprintf("%s:%ld: error: level name exceeds limit of %ld characters.\n",compilefile,line_number,sizeof(level_names[j*MAXLEVELS+k])-1); initprintf("%s:%ld: error: level name exceeds limit of %ld characters.\n",compilefile,line_number,32);
error++; error++;
while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0) textptr++; while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0) textptr++;
break; break;
} }
} }
level_names[j*MAXLEVELS+k][i] = '\0';
tempbuf[i] = '\0';
if (level_names[j*MAXLEVELS+k] == NULL)
level_names[j*MAXLEVELS+k] = Bcalloc(Bstrlen(tempbuf)+1,sizeof(char));
/* initprintf("level name string len: %ld\n",Bstrlen(tempbuf)); */
Bstrcpy(level_names[j*MAXLEVELS+k],tempbuf);
return 0; return 0;
case CON_DEFINEQUOTE: case CON_DEFINEQUOTE:

View file

@ -1609,21 +1609,28 @@ int enterlevel(char g)
if ((g&MODE_DEMO) == 0 && ud.recstat == 2) if ((g&MODE_DEMO) == 0 && ud.recstat == 2)
ud.recstat = 0; ud.recstat = 0;
if (VOLUMEALL) Bsprintf(tempbuf,HEAD2);
else Bsprintf(tempbuf,HEAD);
Bstrcat(tempbuf,apptitle);
wm_setapptitle(tempbuf);
FX_StopAllSounds(); FX_StopAllSounds();
clearsoundlocks(); clearsoundlocks();
FX_SetReverb(0); FX_SetReverb(0);
if (level_names[(ud.volume_number*MAXLEVELS)+ud.level_number] == NULL || level_file_names[(ud.volume_number*MAXLEVELS)+ud.level_number] == NULL) if (level_names[(ud.volume_number*MAXLEVELS)+ud.level_number] == NULL || level_file_names[(ud.volume_number*MAXLEVELS)+ud.level_number] == NULL)
{
if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)
{
if (level_file_names[(ud.volume_number*MAXLEVELS)+ud.level_number] == NULL)
level_file_names[(ud.volume_number*MAXLEVELS)+ud.level_number] = Bcalloc(BMAX_PATH,sizeof(char));
if (level_names[(ud.volume_number*MAXLEVELS)+ud.level_number] == NULL)
{
level_names[(ud.volume_number*MAXLEVELS)+ud.level_number] = Bcalloc(8,sizeof(char));
Bsprintf(level_names[(ud.volume_number*MAXLEVELS)+ud.level_number],"USER MAP");
}
}
else
{ {
initprintf("Map E%ldL%ld not defined!\n",ud.volume_number+1,ud.level_number+1); initprintf("Map E%ldL%ld not defined!\n",ud.volume_number+1,ud.level_number+1);
return 1; return 1;
} }
}
i = ud.screen_size; i = ud.screen_size;
ud.screen_size = 0; ud.screen_size = 0;
@ -1638,6 +1645,12 @@ int enterlevel(char g)
} }
else Bsprintf(apptitle," - %s",level_names[(ud.volume_number*MAXLEVELS)+ud.level_number]); else Bsprintf(apptitle," - %s",level_names[(ud.volume_number*MAXLEVELS)+ud.level_number]);
if (VOLUMEALL) Bsprintf(tempbuf,HEAD2);
else Bsprintf(tempbuf,HEAD);
Bstrcat(tempbuf,apptitle);
wm_setapptitle(tempbuf);
if (!VOLUMEONE) if (!VOLUMEONE)
{ {
if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0) if (boardfilename[0] != 0 && ud.m_level_number == 7 && ud.m_volume_number == 0)