Sound and scripts are opt-in, to speed up loading and closing
This commit is contained in:
parent
064579c9e4
commit
383eaff5b2
177
src/main.c
177
src/main.c
@ -169,7 +169,8 @@ int FPSB = 0;
|
||||
int MSIGN =-1;
|
||||
//int CGOL = 0;
|
||||
//int GSPEED = 1;//causes my .exe to crash..
|
||||
int sound_enable;
|
||||
int sound_enable = 0;
|
||||
int file_script = 0;
|
||||
|
||||
sign signs[MAXSIGNS];
|
||||
|
||||
@ -1214,16 +1215,7 @@ int main(int argc, char *argv[])
|
||||
fmt.samples = 512;
|
||||
fmt.callback = mixaudio;
|
||||
fmt.userdata = NULL;
|
||||
/* Open the audio device and start playing sound! */
|
||||
if ( SDL_OpenAudio(&fmt, NULL) < 0 )
|
||||
{
|
||||
fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
sound_enable = 1;
|
||||
SDL_PauseAudio(0);
|
||||
}
|
||||
|
||||
#ifdef MT
|
||||
numCores = core_count();
|
||||
#endif
|
||||
@ -1276,6 +1268,24 @@ int main(int argc, char *argv[])
|
||||
//sdl_scale = 2; //Removed because some displays cannot handle the resolution
|
||||
hud_enable = 0;
|
||||
}
|
||||
else if (!strncmp(argv[i], "sound", 5))
|
||||
{
|
||||
/* Open the audio device and start playing sound! */
|
||||
if ( SDL_OpenAudio(&fmt, NULL) < 0 )
|
||||
{
|
||||
fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
sound_enable = 1;
|
||||
SDL_PauseAudio(0);
|
||||
}
|
||||
}
|
||||
else if (!strncmp(argv[i], "scripts", 5))
|
||||
{
|
||||
file_script = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
save_presets(0);
|
||||
@ -2767,84 +2777,93 @@ int process_command(pixel *vid_buf,char *console,char *console_error) {
|
||||
}
|
||||
else if(strcmp(console2, "file")==0 && console3)
|
||||
{
|
||||
FILE *f=fopen(console3, "r");
|
||||
if(f)
|
||||
{
|
||||
char fileread[5000];//TODO: make this change with file size
|
||||
char pch[5000];
|
||||
char tokens[10];
|
||||
int tokensize;
|
||||
nx = 0;
|
||||
ny = 0;
|
||||
j = 0;
|
||||
m = 0;
|
||||
if(console4)
|
||||
console_parse_coords(console4, &nx , &ny, console_error);
|
||||
memset(pch,0,sizeof(pch));
|
||||
memset(fileread,0,sizeof(fileread));
|
||||
fread(fileread,1,5000,f);
|
||||
for(i=0; i<strlen(fileread); i++)
|
||||
if(file_script){
|
||||
FILE *f=fopen(console3, "r");
|
||||
if(f)
|
||||
{
|
||||
if(fileread[i] != '\n')
|
||||
char fileread[5000];//TODO: make this change with file size
|
||||
char pch[5000];
|
||||
char tokens[10];
|
||||
int tokensize;
|
||||
nx = 0;
|
||||
ny = 0;
|
||||
j = 0;
|
||||
m = 0;
|
||||
if(console4)
|
||||
console_parse_coords(console4, &nx , &ny, console_error);
|
||||
memset(pch,0,sizeof(pch));
|
||||
memset(fileread,0,sizeof(fileread));
|
||||
fread(fileread,1,5000,f);
|
||||
for(i=0; i<strlen(fileread); i++)
|
||||
{
|
||||
pch[i-j] = fileread[i];
|
||||
if(fileread[i] != ' ')
|
||||
tokens[i-m] = fileread[i];
|
||||
}
|
||||
if(fileread[i] == ' ' || fileread[i] == '\n')
|
||||
{
|
||||
if(sregexp(tokens,"^x.[0-9],y.[0-9]")==0)//TODO: fix regex matching to work with x,y ect, right now it has to have a +0 or -0
|
||||
if(fileread[i] != '\n')
|
||||
{
|
||||
char temp[5];
|
||||
int starty = 0;
|
||||
tokensize = strlen(tokens);
|
||||
x = 0;
|
||||
y = 0;
|
||||
sscanf(tokens,"x%d,y%d",&x,&y);
|
||||
sscanf(tokens,"%9s,%9s",xcoord,ycoord);
|
||||
x += nx;
|
||||
y += ny;
|
||||
sprintf(xcoord,"%d",x);
|
||||
sprintf(ycoord,"%d",y);
|
||||
for(k = 0; k<strlen(xcoord);k++)//rewrite pch with numbers
|
||||
{
|
||||
pch[i-j-tokensize+k] = xcoord[k];
|
||||
starty = k+1;
|
||||
}
|
||||
pch[i-j-tokensize+starty] = ',';
|
||||
starty++;
|
||||
for(k=0;k<strlen(ycoord);k++)
|
||||
{
|
||||
pch[i-j-tokensize+starty+k] = ycoord[k];
|
||||
|
||||
}
|
||||
pch[i-j-tokensize +strlen(xcoord) +1 +strlen(ycoord)] = ' ';
|
||||
j = j -tokensize +strlen(xcoord) +1 +strlen(ycoord);
|
||||
pch[i-j] = fileread[i];
|
||||
if(fileread[i] != ' ')
|
||||
tokens[i-m] = fileread[i];
|
||||
}
|
||||
memset(tokens,0,sizeof(tokens));
|
||||
m = i+1;
|
||||
}
|
||||
if(fileread[i] == '\n')
|
||||
{
|
||||
|
||||
if(do_next)
|
||||
if(fileread[i] == ' ' || fileread[i] == '\n')
|
||||
{
|
||||
if(strcmp(pch,"else")==0)
|
||||
do_next = 0;
|
||||
else
|
||||
do_next = process_command(vid_buf, pch, console_error);
|
||||
if(sregexp(tokens,"^x.[0-9],y.[0-9]")==0)//TODO: fix regex matching to work with x,y ect, right now it has to have a +0 or -0
|
||||
{
|
||||
char temp[5];
|
||||
int starty = 0;
|
||||
tokensize = strlen(tokens);
|
||||
x = 0;
|
||||
y = 0;
|
||||
sscanf(tokens,"x%d,y%d",&x,&y);
|
||||
sscanf(tokens,"%9s,%9s",xcoord,ycoord);
|
||||
x += nx;
|
||||
y += ny;
|
||||
sprintf(xcoord,"%d",x);
|
||||
sprintf(ycoord,"%d",y);
|
||||
for(k = 0; k<strlen(xcoord);k++)//rewrite pch with numbers
|
||||
{
|
||||
pch[i-j-tokensize+k] = xcoord[k];
|
||||
starty = k+1;
|
||||
}
|
||||
pch[i-j-tokensize+starty] = ',';
|
||||
starty++;
|
||||
for(k=0;k<strlen(ycoord);k++)
|
||||
{
|
||||
pch[i-j-tokensize+starty+k] = ycoord[k];
|
||||
|
||||
}
|
||||
pch[i-j-tokensize +strlen(xcoord) +1 +strlen(ycoord)] = ' ';
|
||||
j = j -tokensize +strlen(xcoord) +1 +strlen(ycoord);
|
||||
}
|
||||
memset(tokens,0,sizeof(tokens));
|
||||
m = i+1;
|
||||
}
|
||||
if(fileread[i] == '\n')
|
||||
{
|
||||
|
||||
if(do_next)
|
||||
{
|
||||
if(strcmp(pch,"else")==0)
|
||||
do_next = 0;
|
||||
else
|
||||
do_next = process_command(vid_buf, pch, console_error);
|
||||
}
|
||||
else if(strcmp(pch,"endif")==0 || strcmp(pch,"else")==0)
|
||||
do_next = 1;
|
||||
memset(pch,0,sizeof(pch));
|
||||
j = i+1;
|
||||
}
|
||||
else if(strcmp(pch,"endif")==0 || strcmp(pch,"else")==0)
|
||||
do_next = 1;
|
||||
memset(pch,0,sizeof(pch));
|
||||
j = i+1;
|
||||
}
|
||||
//sprintf(console_error, "%s exists", console3);
|
||||
fclose(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(console_error, "%s does not exist", console3);
|
||||
}
|
||||
//sprintf(console_error, "%s exists", console3);
|
||||
fclose(f);
|
||||
}
|
||||
else
|
||||
sprintf(console_error, "%s does not exist", console3);
|
||||
{
|
||||
sprintf(console_error, "Scripts are not enabled");
|
||||
}
|
||||
|
||||
}
|
||||
else if(strcmp(console2, "sound")==0 && console3)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user