Exemple #1
0
/*static*/
int Main::main(void)
{
	init_term();

    printf("\nEDBMS Start");

	pM = &m;

	InitEndian();

	m.execute();

    printf("\nEDBMS Stop");

    return 0;
}
Exemple #2
0
glbsp_ret_e GlbspBuildNodes(const nodebuildinfo_t *info,
    const nodebuildfuncs_t *funcs, volatile nodebuildcomms_t *comms)
{
  char *file_msg;

  glbsp_ret_e ret = GLBSP_E_OK;

  cur_info  = info;
  cur_funcs = funcs;
  cur_comms = comms;

  cur_comms->total_big_warn = 0;
  cur_comms->total_small_warn = 0;

  // clear cancelled flag
  comms->cancelled = FALSE;

  // sanity check
  if (!cur_info->input_file  || cur_info->input_file[0] == 0 ||
      !cur_info->output_file || cur_info->output_file[0] == 0)
  {
    SetErrorMsg("INTERNAL ERROR: Missing in/out filename !");
    return GLBSP_E_BadArgs;
  }

  InitDebug();
  InitEndian();
 
  if (info->missing_output)
    PrintMsg("* No output file specified. Using: %s\n\n", info->output_file);

  if (info->same_filenames)
    PrintMsg("* Output file is same as input file. Using -loadall\n\n");

  // opens and reads directory from the input wad
  ret = ReadWadFile(cur_info->input_file);

  if (ret != GLBSP_E_OK)
  {
    TermDebug();
    return ret;
  }

  if (CountLevels() <= 0)
  {
    CloseWads();
    TermDebug();

    SetErrorMsg("No levels found in wad !");
    return GLBSP_E_Unknown;
  }
   
  PrintMsg("\n");
  PrintVerbose("Creating nodes using tunable factor of %d\n", info->factor);

  DisplayOpen(DIS_BUILDPROGRESS);
  DisplaySetTitle("glBSP Build Progress");

  file_msg = UtilFormat("File: %s", cur_info->input_file);
 
  DisplaySetBarText(2, file_msg);
  DisplaySetBarLimit(2, CountLevels() * 10);
  DisplaySetBar(2, 0);

  UtilFree(file_msg);
  
  cur_comms->file_pos = 0;
  
  // loop over each level in the wad
  while (FindNextLevel())
  {
    ret = HandleLevel();

    if (ret != GLBSP_E_OK)
      break;

    cur_comms->file_pos += 10;
    DisplaySetBar(2, cur_comms->file_pos);
  }

  DisplayClose();

  // writes all the lumps to the output wad
  if (ret == GLBSP_E_OK)
  {
    ret = WriteWadFile(cur_info->output_file);

    // when modifying the original wad, any GWA companion must be deleted
    if (ret == GLBSP_E_OK && cur_info->same_filenames)
      DeleteGwaFile(cur_info->output_file);

    PrintMsg("\n");
    PrintMsg("Total serious warnings: %d\n", cur_comms->total_big_warn);
    PrintMsg("Total minor warnings: %d\n", cur_comms->total_small_warn);

    ReportFailedLevels();
  }

  // close wads and free memory
  CloseWads();

  TermDebug();

  cur_info  = NULL;
  cur_comms = NULL;
  cur_funcs = NULL;

  return ret;
}
Exemple #3
0
int main(int argc, char** argv)
{
	if(argc == 1)
	{
		tr_help();
		return 1;
	}
	
	tr_parseoptions(argc, argv);
	
	if(!quiet)
	{
		tr_version();
	}
	
	if(argc - optind < 2)
	{
		fprintf(stderr, "ERROR: Requires input and response file to be specified. Use -h for help \n");
		return 1;
	}
	
	
	const char* infilename       = argv[optind];
	const char* responsefilename = argv[optind+1];
	
	/* Make a filename from the input and response names */
	if(!outfilename)
	{
		char* innameend = strrchr(infilename, '.');
		int innamelen = innameend ? innameend-infilename : strlen(infilename);
		
		char* responsenameend = strrchr(responsefilename, '.');
		int responsenamelen = responsenameend ? responsenameend-responsefilename : strlen(responsefilename);
		
		outfilename = malloc(innamelen+responsenamelen + 5); /* + '.wav '*/
		strncpy(outfilename, infilename, innamelen);
		strncat(outfilename, responsefilename, responsenamelen);
		strcat(outfilename, ".wav");
	}
	
	
	InitEndian();
	
	/* Setup the input file */
	FILE* infile = fopen(infilename, "rb");
	if(infile == 0)
	{
		fprintf(stderr, "ERROR: Failed opening input file %s\n", infilename);
		return 1;
	}
	
	tr_wavfile inputwav;
	if( !tr_wavopen(infile, &inputwav, 'r') )
	{
		fprintf(stderr, "ERROR: Invalid file type, %s is not a wav file\n", infilename);
		return 1;
	}
	
	if(!quiet)
	{
		fprintf(stdout, "\n");
		fprintf(stdout, "Input file         : %s\n", infilename);
		fprintf(stdout, "  Samples          : %u\n", inputwav.totalsamples);
		fprintf(stdout, "  Channels         : %i\n", inputwav.channels);
		fprintf(stdout, "  Sample rate      : %u\n", inputwav.samplerate);
		fprintf(stdout, "  Bytes per sample : %u\n", inputwav.bytespersample);
		fprintf(stdout, "  Duration seconds : %.2f\n", ((float)inputwav.totalsamples / (float)inputwav.samplerate / (float)inputwav.channels));
	}
	
	/* Now setup the response file */
	FILE* responsefile = fopen(responsefilename, "rb");
	if(responsefile == 0)
	{
		fprintf(stderr, "ERROR: Failed opening response file %s\n", responsefilename);
		return 1;
	}
	
	tr_wavfile responsewav;
	if(!tr_wavopen(responsefile, &responsewav, 'r'))
	{
		fprintf(stderr, "ERROR: Invalid file type, %s is not a wav file\n", responsefilename);
		return 1;
	}
	
	if(!quiet)
	{
		fprintf(stdout, "\n");
		fprintf(stdout, "Response file      : %s\n", responsefilename);
		fprintf(stdout, "  Samples          : %u\n", responsewav.totalsamples);
		fprintf(stdout, "  Channels         : %i\n", responsewav.channels);
		fprintf(stdout, "  Sample rate      : %u\n", responsewav.samplerate);
		fprintf(stdout, "  Bytes per sample : %u\n", responsewav.bytespersample);
		fprintf(stdout, "  Duration seconds : %.2f\n", ((float)responsewav.totalsamples / (float)responsewav.samplerate / (float)responsewav.channels));
		
		fprintf(stdout, "\n");
	}
	
	/* Make sure we can handle processing the two files */
	if(inputwav.channels != responsewav.channels)
	{
		fprintf(stderr, "ERROR: Channels do not match. %s has %i channels, %s has %i\n", 
		   infilename, inputwav.channels, responsefilename, responsewav.channels);
		return 1;
	}
	else if(inputwav.samplerate != responsewav.samplerate)
	{
		fprintf(stderr, "ERROR: Sample rates do not match. %s is at %uHz, %s is at %uHz\n", 
		   infilename, inputwav.samplerate, responsefilename, responsewav.samplerate);
		return 1;
	}
	else if(!quiet)
	{
		fprintf(stdout, "Reading %s and %s into memory\n", infilename, responsefilename);
	}
	
	/* Both are open, now read them into memory */
	float* inputbuffer = malloc(inputwav.totalsamples * sizeof(float));
	if( !tr_wavread(&inputwav, inputbuffer, inputwav.totalsamples) )
	{
		fprintf(stderr, "ERROR: Failed reading input file\n");
		return 1;
	}
	
	float* responsebuffer = malloc(responsewav.totalsamples * sizeof(float));
	if(!tr_wavread(&responsewav, responsebuffer, responsewav.totalsamples))
	{
		fprintf(stderr, "ERROR: Failed reading input file\n");
		return 1;
	}
	
	/* Prepare a buffer to accept the data from our processing */
	unsigned int samplesinput    = inputwav.totalsamples;
	unsigned int samplesresponse = responsewav.totalsamples;
	unsigned int samplestotal    = samplesinput + samplesresponse + 1;
	float* outputbuffer = malloc(samplestotal*sizeof(float));
	
	float* conv = outputbuffer;
	unsigned int inoffset;
	unsigned int reoffset;
	unsigned int n_hi;
	unsigned int n_lo;
	
	if(!quiet)
	{
		fprintf(stdout, "Processing audio, please be patient\n");
	}
	
	/* Do the processing (time domain convolution) */
	unsigned int i;
	for(i = 0; i < samplestotal; i++)
	{
		n_lo = i < samplesresponse ? 0 : i - samplesresponse;
		n_hi = samplesinput < i ? samplesinput : i;
		
		inoffset = n_lo;
		reoffset = i - n_lo;
		
		*conv = 0.0f;
		unsigned int n;
		for(n = n_lo; n < n_hi; n++)
		{
			*conv += *(inputbuffer+inoffset) * *(responsebuffer+reoffset);
			++inoffset;
			--reoffset;
		}
		conv++;
	}
	
	if(!quiet)
	{
		fprintf(stdout, "Normalising audio\n");
	}
	
	/* Normalise the data */
	conv = outputbuffer;
	float maxsample = 0.0f;
	
	for(i = 0; i < samplestotal; i++)
	{
		if(*conv > maxsample)
		{
			maxsample = *conv;
		}
		++conv;
	}
	
	conv = outputbuffer;
	float normalise = 1.0f / maxsample;
	
	for(i = 0; i < samplestotal; i++)
	{
		*conv++ *= normalise;
	}
	
	/* Setup the output file */
	FILE* outfile = fopen(outfilename, "wb");
	if(outfile == 0)
	{
		fprintf(stderr, "ERROR: Failed opening output file %s\n", outfilename);
		return 1;
	}
	
	tr_wavfile outwav;
	tr_wavopen(outfile, &outwav, 'w');
	outwav.channels       = inputwav.channels;
	outwav.samplerate     = inputwav.samplerate;
	outwav.bytespersample = inputwav.bytespersample;
	
	if(!quiet)
	{
		fprintf(stdout, "\n");
		fprintf(stdout, "Output file        : %s\n", outfilename);
		fprintf(stdout, "  Samples          : %u\n", samplestotal);
		fprintf(stdout, "  Channels         : %i\n", outwav.channels);
		fprintf(stdout, "  Sample rate      : %u\n", outwav.samplerate);
		fprintf(stdout, "  Bytes per sample : %u\n", outwav.bytespersample);
		fprintf(stdout, "  Duration seconds : %.2f\n", ((float)samplestotal / (float)outwav.samplerate / (float)outwav.channels));
		
		fprintf(stdout, "\n");
		fprintf(stdout, "Writing data out to %s\n", outfilename);
	}
	
	/* Write out data from the processing to file */
	if(!tr_wavwrite(&outwav, outputbuffer, samplestotal))
	{
		fprintf(stderr, "ERROR: Failed during write of %s.  File may be malformed\n", outfilename);
	}

	/* Clean up */
	free(inputbuffer);
	free(responsebuffer);
	free(outputbuffer);
	
	tr_wavclose(&inputwav);
	tr_wavclose(&responsewav);
	tr_wavclose(&outwav);
	
	fclose(infile);
	fclose(responsefile);
	fclose(outfile);
	
	return 0;
}
Exemple #4
0
int main(int argc, char **argv)
{
	try
	{
		// skip program name
		argv++, argc--;

		ArgvInit(argc, (const char **)argv);
	 
		InitDebug(ArgvFind(0, "debug") >= 0);
		InitEndian();

		if (ArgvFind('?', NULL) >= 0 || ArgvFind('h', "help") >= 0)
		{
			ShowTitle();
			ShowInfo();
			exit(1);
		}

		InitFLTK();

		SetDefaults();
		SetupRandom();

		int W = 40;
		int H = 40;

		GetMapSize(&W, &H);

		PrintDebug("Map size %dx%d\n\n", W, H);

		the_world = new world_c(W, H);

		environ_build::CreateEnv();
		area_build::CreateAreas();
		island_build::CreateIslands();
		island_build::Cleanup();

  		stage_build::CreateStages();
		path_build::CreatePaths();
		room_build::CreateRooms();

		if (ArgvFind('g', "gui") >= 0)
		{
			guix_win = new Guix_MainWin(PROG_NAME);

			// run the GUI until the user quits
			while (! guix_win->want_quit)
				Fl::wait();
		}

		CreateWAD();
	}
	catch (const char * err)
	{
		DisplayError("%s", err);
	}
#if 1
	catch (assert_fail_c err)
	{
		DisplayError("Sorry, an internal error occurred:\n%s", err.GetMessage());
	}
	catch (...)
	{
		DisplayError("An unknown problem occurred (UI code)");
	}
#endif

	delete guix_win;

	TermDebug();

	return main_result;
}