Ejemplo n.º 1
0
void draw_text(Alignment align, float x, float y, const char *text, TTF_Font *font) {
	char *nl;
	char *buf = malloc(strlen(text)+1);
	strcpy(buf, text);
	
	if((nl = strchr(buf, '\n')) != NULL && strlen(nl) > 1) {
		draw_text(align, x, y + 20, nl+1, font);
		*nl = '\0';
	}
		
	Texture *tex = load_text(buf, font);
	
	switch(align) {
	case AL_Center:
		draw_texture_p(x, y, tex);
		break;
	case AL_Left:
		draw_texture_p(x + tex->w/2.0, y, tex);
		break;
	case AL_Right:
		draw_texture_p(x - tex->w/2.0, y, tex);
		break;
	}
		
	free_texture(tex);
	free(buf);
}
Ejemplo n.º 2
0
t_length gzhandle::load_text(const char * p_dir, const char * p_file, char * p_mem, t_length max_lenght, t_length start_address, bool safe)
{  
  if(open(p_dir, p_file, "rb", safe))
    return(load_text(p_mem, max_lenght, start_address));
  else
    return(0);
}
Ejemplo n.º 3
0
static void init(void) {
    reward = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_REWARD);
    star = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_STAR);

    load_text(KEY_BALANCE, false);
    load_text(KEY_REWARDS, false);
    load_text(KEY_STARS, false);
    load_text(KEY_STATUS, false);

    window = window_create();
    window_set_fullscreen(window, true);
    window_set_background_color(window, GColorBlack);
    window_set_click_config_provider(window, click_config_provider);
    window_set_window_handlers(window, (WindowHandlers) {
        .load = window_load,
        .unload = window_unload,
    });
Ejemplo n.º 4
0
static void display_scores( RW_Battle *b ) {
    SDL_Surface *text;
    RW_Active_Robot *bot;
    RW_Robot_Iter ri;
    SDL_Rect r = {300, 0, 100, 300};
    SDL_FillRect(screen, &r, 0x88888888);
    RW_Reset_Robot_Iter(b, &ri, NULL);
    while( (bot = RW_Robot_Next(&ri)) ) {
        text = load_name(RW_Get_Robot_Name(bot));
        draw_text(text, 303, 3 + (bot->id * 28));
        text = load_text(bot->damage);
        draw_text(text, 303, 3 + 14 + (bot->id * 28));
        text = load_text(bot->energy);
        draw_text(text, 338, 3 + 14 + (bot->id * 28));
        text = load_text(bot->shield);
        draw_text(text, 373, 3 + 14 + (bot->id * 28));
    }
}
Ejemplo n.º 5
0
static int try_load(struct pattern* pattern)
{
  if (extract_filename(&pattern->pattern)) {
    if (is_cdb(&filename))
      return (pattern->cdb = open_cdb(&filename)) != 0;
    else 
      return (pattern->file = load_text(&filename)) != 0;
  }
  return 1;
}
Ejemplo n.º 6
0
static char *
load_page_text(const char *application, const char *lang, const char *page)
{
    char *filename;
    if (!asprintf(&filename, DATADIR "/help/%s/%s/%s.help",
                  application, lang, page))
        err(1, "asprintf");

    char *text = load_text(filename);
    free(filename);
    return text;
}
Ejemplo n.º 7
0
ProfileDataInfoDialog::ProfileDataInfoDialog(const QStringList& text, const QString& pattern, const QString& suffix, QWidget *parent) : QDialog(parent) {

  Q_UNUSED(parent);

  this->text = text;
  this->pattern = pattern;
  this->suffix = suffix;

  setWindowTitle(i18n("Info Settings"));

  QVBoxLayout *mainLayout = new QVBoxLayout;
  setLayout(mainLayout);

  QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply);
  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
  okButton->setDefault(true);
  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
  applyButton = buttonBox->button(QDialogButtonBox::Apply);
  connect(buttonBox, &QDialogButtonBox::accepted, this, &ProfileDataInfoDialog::slotAccepted);
  connect(buttonBox, &QDialogButtonBox::rejected, this, &ProfileDataInfoDialog::reject);
  connect(applyButton, &QPushButton::clicked, this, &ProfileDataInfoDialog::slotApplied);

  QWidget *widget = new QWidget(this);
  mainLayout->addWidget(widget);
  mainLayout->addWidget(buttonBox);
  ui.setupUi(widget);

  connect(ui.kpushbutton_pattern, SIGNAL(clicked()), this, SLOT(pattern_wizard()));
  ui.kpushbutton_pattern->setIcon(QIcon::fromTheme("tools-wizard"));

  ui.ktextedit_text->setPlainText(text.join("\n"));
  connect(ui.ktextedit_text, SIGNAL(textChanged()), this, SLOT(trigger_changed()));

  ui.qlineedit_pattern->setText(pattern);
  connect(ui.qlineedit_pattern, SIGNAL(textEdited(const QString&)), this, SLOT(trigger_changed()));

  ui.qlineedit_suffix->setText(suffix);
  connect(ui.qlineedit_suffix, SIGNAL(textEdited(const QString&)), this, SLOT(trigger_changed()));

  ui.kpushbutton_load->setIcon(QIcon::fromTheme("document-open"));
  ui.kpushbutton_save->setIcon(QIcon::fromTheme("document-save"));

  connect(ui.kurllabel_aboutvariables, SIGNAL(leftClickedUrl()), this, SLOT(about_variables()));

  connect(ui.kpushbutton_load, SIGNAL(clicked()), this, SLOT(load_text()));
  connect(ui.kpushbutton_save, SIGNAL(clicked()), this, SLOT(save_text()));

  applyButton->setEnabled(false);

}
Ejemplo n.º 8
0
void vsx_widget_note::command_process_back_queue(vsx_command_s *t) {
  if (t->cmd == "close") {
    command_q_b.add_raw("note_delete "+name);
    parent->vsx_command_queue_b(this);
    _delete();
  } else
  if (t->cmd == "save") {
    save();
  } else
  if (t->cmd == "pg64_ok") {
    // pg64_ok [comp] [param] [val] [id]
    load_text( vsx_string_helper::base64_decode(t->parts[3]));
    a_focus = this;
    k_focus = this;
  }
}
Ejemplo n.º 9
0
bool vsx_widget_note::init_from_command(vsx_command_s* c)
{
  set_render_type(render_3d);
  vsx_vector3<> np;
  np = vsx_vector3_helper::from_string<float>(c->parts[2]);
  set_pos(np);
  np = vsx_vector3_helper::from_string<float>(c->parts[3]);
  set_size(np);
  set_font_size(vsx_string_helper::s2f(c->parts[5]));
  set_border(font_size*0.15f);
  size_min.x = font_size*3.0f;
  size_min.y = font_size*4.0f;

  //new_note->target_size = new_note->size;
  load_text( vsx_string_helper::base64_decode(c->parts[4]));
  return true;
}
main(int argc,char * argv[])
{

  FILE *in;
  char * filename;
  char str[100];
  int  proceed =0;
  if(argc != 2) 
    {
      printf("ERROR!:No input file\n");
      exit(0);
    }
  filename=argv[1];
  in=fopen(filename,"r");
  if(in==NULL)
    {
      printf("ERROR!:No input file\n");
      exit(0);
    }
  while(fgets(str,100,in))
    {
      if(!proceed)
	{
	  if(str[0]=='H')
	    {
	      header(str);
	      proceed=1;
	    }
	}
      else
	{
	  if(str[0]=='E')
	    {
	      end();
	      break;
	    }
	  if(str[0]=='T') load_text(str);
	}
    }
  fclose(in);

}
//------------------------------------------------------------------------------
int main(int argc, char** argv) {
    if(argc < 6) {
        std::cerr << "usage: " << argv[0]
                  << " <platform name> <device type = default | cpu | gpu "
                     "| acc | all>  <device num> <OpenCL source file path>"
                     " <kernel name>"
                  << std::endl;
        exit(EXIT_FAILURE);  
    }
    std::string platformName = argv[ 1 ];
    std::string deviceType = argv[2]; 
    int deviceNum = atoi(argv[3]);

    log_thread_count("\n\nstart");
#ifdef _OPENMP    
    {
        // const int CHUNKSIZE = 100;
        // const int N = 1000;    
        // int i, chunk;
        // float a[N], b[N], c[N];
        // for (i=0; i < N; i++)
        //     a[i] = b[i] = i * 1.0;
        // chunk = CHUNKSIZE;
        // printf("%d", omp_get_max_threads());
        #pragma omp parallel //shared(a,b,c,chunk) private(i)
        {
            if(omp_get_thread_num() == 0) {
                log_thread_count("OMP PARALLEL");
            }
        // printf("%d", omp_get_max_threads());
        // #pragma omp for schedule(dynamic,chunk) nowait
        // for (i=0; i < N; i++) {
        //     c[i] = a[i] + b[i];
        // }
        }  
        #pragma omp barrier
    }
#endif    

    //1)create context
    cl_context ctx = create_cl_context(platformName, deviceType, deviceNum);
    std::cout << "OpenCL context created" << std::endl;
    
    log_thread_count("CL context created");


    //2)load kernel source
    const std::string programSource = load_text(argv[4]);
    std::cout << "OpenCL source code loaded" << std::endl;
    const char* src = programSource.c_str();
    const size_t sourceLength = programSource.length();

    //3)build program and create kernel
    cl_int status;
    cl_program program = clCreateProgramWithSource(ctx, //context
                                                   1,   //number of strings
                                                   &src, //source
                                                   &sourceLength, // size 
                                                   &status);  // status 
    check_cl_error(status, "clCreateProgramWithSource");
    cl_device_id deviceID; //only a single device was selected
    // retrieve actual device id from context
    status = clGetContextInfo(ctx,
                              CL_CONTEXT_DEVICES,
                              sizeof(cl_device_id),
                              &deviceID, 0);
    check_cl_error(status, "clGetContextInfo");
    cl_int buildStatus = clBuildProgram(program, //program
                                        1, //number of devices
                                        &deviceID, //array of device ids
                                        0, //program options as passed on
                                           //the command line to regualar
                                           //compilers e.g. -DUSE_DOUBLE
                                        0, 0);
    //log output if any
    char buffer[0x10000] = "";
    size_t len = 0;
    status = clGetProgramBuildInfo(program,
                                   deviceID,
                                   CL_PROGRAM_BUILD_LOG,
                                   sizeof(buffer),
                                   buffer,
                                   &len);
    check_cl_error(status, "clBuildProgramInfo");
    if(len > 1) std::cout << "Build output: " << buffer << std::endl;
    check_cl_error(buildStatus, "clBuildProgram");

    std::cout << "Built OpenCL program" << std::endl;
    const char* kernelName = argv[5];
    cl_kernel kernel = clCreateKernel(program, kernelName, &status);
    check_cl_error(status, "clCreateKernel"); 
   
    //4)allocate output buffer on OpenCL device
    typedef float real_t;
    const size_t ARRAY_LENGTH = 16;
    const size_t ARRAY_BYTE_LENGTH = ARRAY_LENGTH * sizeof(real_t);
    cl_mem outputCLBuffer = clCreateBuffer(ctx,
                                           CL_MEM_WRITE_ONLY,
                                           ARRAY_BYTE_LENGTH,
                                           0,
                                           &status);
    check_cl_error(status, "clCreateBuffer");

    //5)create command queue
    cl_command_queue commands = clCreateCommandQueue(ctx, deviceID, 0, &status);
    check_cl_error(status, "clCreateCommandQueue");
   
    //6)set kernel parameters
    const real_t value = real_t(3.14);
    //first parameter: output array
    status = clSetKernelArg(kernel, //kernel
                            0,      //parameter id
                            sizeof(cl_mem), //size of parameter
                            &outputCLBuffer); //pointer to parameter
    check_cl_error(status, "clSetKernelArg(0)");
    //second parameter: value to assign to each array element
    status = clSetKernelArg(kernel, //kernel
                            1,      //parameter id
                            sizeof(real_t), //size of parameter
                            &value); //pointer to parameter
    check_cl_error(status, "clSetKernelArg(1)");

    //7)setup kernel launch configuration
    //total number of threads == number of array elements
    const size_t globalWorkSize[1] = {ARRAY_LENGTH};
    //number of per-workgroup local threads
    const size_t localWorkSize[1] = {1}; 

    //8)launch kernel
    status = clEnqueueNDRangeKernel(commands, //queue
                                    kernel, //kernel                                   
                                    1, //number of dimensions for work-items
                                    0, //global work offset
                                    globalWorkSize, //total number of threads
                                    localWorkSize, //threads per workgroup
                                    0, //number of events that need to
                                       //complete before kernel executed
                                    0, //list of events that need to complete
                                       //before kernel executed
                                    0); //event object identifying this
                                        //particular kernel execution instance

    check_cl_error(status, "clEnqueueNDRangeKernel");
    log_thread_count("kernel launched");
    std::cout << "Lunched OpenCL kernel - setting all array elements to "
              << value << std::endl;

    //9)read back and print results
    std::vector< real_t > hostArray(ARRAY_LENGTH, real_t(0));
    status = clEnqueueReadBuffer(commands,
                                 outputCLBuffer,
                                 CL_TRUE, //blocking read
                                 0, //offset
                                 ARRAY_BYTE_LENGTH, //byte size of data
                                 &hostArray[0], //destination buffer in host
                                                // memory
                                 0, //number of events that need to
                                    //complete before transfer executed
                                 0, //list of events that need to complete
                                    //before transfer executed
                                 0); //event identifying this specific operation
    check_cl_error(status, "clEnqueueReadBuffer");
    log_thread_count("device -> host transfer");
    std::cout << "Output array: " << std::endl;
    std::ostream_iterator<real_t> out_it(std::cout, " ");
    std::copy(hostArray.begin(), hostArray.end(), out_it);
    std::cout << std::endl;

    //10)release resources
    check_cl_error(clReleaseMemObject(outputCLBuffer), "clReleaseMemObject");
    check_cl_error(clReleaseCommandQueue(commands),"clReleaseCommandQueue");
    check_cl_error(clReleaseKernel(kernel), "clReleaseKernel");
    check_cl_error(clReleaseProgram(program), "clReleaseProgram");
    check_cl_error(clReleaseContext(ctx), "clReleaseContext");
    std::cout << "Released OpenCL resources" << std::endl;
    log_thread_count("released resources");

    print_thread_count(threadlog.begin(), threadlog.end());
    std::cout << std::endl;
    return 0;
}
Ejemplo n.º 12
0
//------------------------------------------------------------------------------
CLEnv create_clenv(const std::string& platformName,
                   const std::string& deviceType,
                   int deviceNum,
                   bool enableProfiling,
                   const char* clSourcePath,
                   const char* kernelName, 
                   const std::string& clSourcePrefix, 
                   const std::string& buildOptions) {

    CLEnv rt;
    cl_int status;
    cl_device_id deviceID;

    //1)create context
    rt.context = create_cl_context(platformName, deviceType, deviceNum);
    //only a single device was selected
    //retrieve actual device id from context
    status = clGetContextInfo(rt.context,
                              CL_CONTEXT_DEVICES,
                              sizeof(cl_device_id),
                              &deviceID, 0);
    check_cl_error(status, "clGetContextInfo");
    
    //2)load kernel source
    if(clSourcePath != 0) {
        const std::string programSource = clSourcePrefix 
                                          + "\n" 
                                          + load_text(clSourcePath);
        const char* src = programSource.c_str();
        const size_t sourceLength = programSource.length();

        //3)build program and create kernel
        
        rt.program = clCreateProgramWithSource(rt.context, //context
                                               1,   //number of strings
                                               &src, //lines
                                               &sourceLength, // size 
                                               &status);  // status 
        check_cl_error(status, "clCreateProgramWithSource");
        
        cl_int buildStatus = buildOptions.size() ?
                             clBuildProgram(rt.program, 1, &deviceID,
                                buildOptions.c_str(), 0, 0)
                             : clBuildProgram(rt.program, 1, &deviceID,
                                0, 0, 0);
        //log output if any
        char buffer[0x10000] = "";
        size_t len = 0;
        status = clGetProgramBuildInfo(rt.program,
                                       deviceID,
                                       CL_PROGRAM_BUILD_LOG,
                                       sizeof(buffer),
                                       buffer,
                                       &len);
        check_cl_error(status, "clBuildProgramInfo");
        if(len > 1) std::cout << "Build output: " << buffer << std::endl;
        check_cl_error(buildStatus, "clBuildProgram");
        if(kernelName != 0) {
            rt.kernel = clCreateKernel(rt.program, kernelName, &status);
            check_cl_error(status, "clCreateKernel"); 
        }
    }

    rt.commandQueue = enableProfiling ?
                      clCreateCommandQueue(rt.context, deviceID,
                                           CL_QUEUE_PROFILING_ENABLE, &status)
                      : clCreateCommandQueue(rt.context, deviceID, 0, &status);
    check_cl_error(status, "clCreateCommandQueue");

    return rt;
}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{
	mem_init();
#ifdef __LINUX__
	error_init(NULL, NULL);
#else
	error_init(msgbox_error, NULL);
	set_warn_func(msgbox_warning);
#endif
	PHYSFSX_init(argc, argv);
	con_init();  // Initialise the console

	setbuf(stdout, NULL); // unbuffered output via printf
#ifdef _WIN32
	freopen( "CON", "w", stdout );
	freopen( "CON", "w", stderr );
#endif

	if (GameArg.SysShowCmdHelp) {
		print_commandline_help();
		set_exit_message("");

		return(0);
	}

	printf("\nType %s -help' for a list of command-line options.\n\n", PROGNAME);

	PHYSFSX_listSearchPathContent();
	
	if (!PHYSFSX_checkSupportedArchiveTypes())
		return(0);

	if (! PHYSFSX_contfile_init("descent.hog", 1))
		Error("Could not find a valid hog file (descent.hog)\nPossible locations are:\n"
#if defined(__unix__) && !defined(__APPLE__)
			  "\t$HOME/.d1x-rebirth\n"
			  "\t" SHAREPATH "\n"
#else
			  "\tDirectory containing D1X\n"
#endif
			  "\tIn a subdirectory called 'Data'\n"
#if (defined(__APPLE__) && defined(__MACH__)) || defined(macintosh)
			  "\tIn 'Resources' inside the application bundle\n"
#endif
			  "Or use the -hogdir option to specify an alternate location.");
	
	switch (PHYSFSX_fsize("descent.hog"))
	{
		case D1_MAC_SHARE_MISSION_HOGSIZE:
		case D1_MAC_MISSION_HOGSIZE:
			MacHog = 1;	// used for fonts and the Automap
			break;
	}

	load_text();

	//print out the banner title
	con_printf(CON_NORMAL, "%s", DESCENT_VERSION); // D1X version
	con_printf(CON_NORMAL, "  %s %s\n", __DATE__,__TIME__);
	con_printf(CON_NORMAL, "This is a MODIFIED version of Descent, based on %s.\n", BASED_VERSION);
	con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
	con_printf(CON_NORMAL, "Copyright (C) 2005-2011 Christian Beckhaeuser\n\n");

	if (GameArg.DbgVerbose)
		con_printf(CON_VERBOSE,"%s%s", TXT_VERBOSE_1, "\n");
	
	ReadConfigFile();

	PHYSFSX_addArchiveContent();

	arch_init();

	select_tmap(GameArg.DbgTexMap);

	con_printf(CON_VERBOSE, "Going into graphics mode...\n");
	gr_set_mode(Game_screen_mode);

	// Load the palette stuff. Returns non-zero if error.
	con_printf(CON_DEBUG, "Initializing palette system...\n" );
	gr_use_palette_table( "PALETTE.256" );

	con_printf(CON_DEBUG, "Initializing font system...\n" );
	gamefont_init();	// must load after palette data loaded.

	set_default_handler(standard_handler);

	show_titles();

	set_screen_mode(SCREEN_MENU);

	con_printf( CON_DEBUG, "\nDoing gamedata_init..." );
	gamedata_init();

	if (GameArg.DbgNoRun)
		return(0);

	con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
	texmerge_init( 10 );		// 10 cache bitmaps

	con_printf( CON_DEBUG, "\nRunning game...\n" );
	init_game();

	Players[Player_num].callsign[0] = '\0';

	key_flush();

	if(GameArg.SysPilot)
	{
		char filename[32] = "";
		int j;

		if (GameArg.SysUsePlayersDir)
			strcpy(filename, "Players/");
		strncat(filename, GameArg.SysPilot, 12);
		filename[8 + 12] = '\0';	// unfortunately strncat doesn't put the terminating 0 on the end if it reaches 'n'
		for (j = GameArg.SysUsePlayersDir? 8 : 0; filename[j] != '\0'; j++) {
			switch (filename[j]) {
				case ' ':
					filename[j] = '\0';
			}
		}
		if(!strstr(filename,".plr")) // if player hasn't specified .plr extension in argument, add it
			strcat(filename,".plr");
		if(PHYSFSX_exists(filename,0))
		{
			strcpy(strstr(filename,".plr"),"\0");
			strcpy(Players[Player_num].callsign, GameArg.SysUsePlayersDir? &filename[8] : filename);
			read_player_file();
			WriteConfigFile();
		}
	}


	Game_mode = GM_GAME_OVER;
	DoMenu();

	setjmp(LeaveEvents);
	while (window_get_front())
		// Send events to windows and the default handler
		event_process();
	
	// Tidy up - avoids a crash on exit
	{
		window *wind;

		show_menus();
		while ((wind = window_get_front()))
			window_close(wind);
	}

	WriteConfigFile();
	show_order_form();

	con_printf( CON_DEBUG, "\nCleanup...\n" );
	close_game();
	texmerge_close();
	gamedata_close();
	gamefont_close();
	free_text();
	args_exit();
	newmenu_free_background();
	free_mission();
	PHYSFSX_removeArchiveContent();

	return(0);		//presumably successful exit
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
	mem_init();
#ifdef __LINUX__
	error_init(NULL);
#else
	error_init(msgbox_error);
	set_warn_func(msgbox_warning);
#endif
	PHYSFSX_init(argc, argv);
	con_init();  // Initialise the console

	setbuf(stdout, NULL); // unbuffered output via printf
#ifdef _WIN32
	freopen( "CON", "w", stdout );
	freopen( "CON", "w", stderr );
#endif

	if (GameArg.SysShowCmdHelp) {
		print_commandline_help();

		return(0);
	}

	printf("\nType %s -help' for a list of command-line options.\n\n", PROGNAME);

	PHYSFSX_listSearchPathContent();
	
	if (!PHYSFSX_checkSupportedArchiveTypes())
		return(0);

	if (! PHYSFSX_contfile_init("descent2.hog", 1)) {
		if (! PHYSFSX_contfile_init("d2demo.hog", 1))
#define DXX_NAME_NUMBER	"2"
#define DXX_HOGFILE_NAMES	"descent2.hog or d2demo.hog"
#if defined(__unix__) && !defined(__APPLE__)
#define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY	\
			      "\t$HOME/.d" DXX_NAME_NUMBER "x-rebirth\n"	\
			      "\t" SHAREPATH "\n"
#else
#define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY	\
				  "\tDirectory containing D" DXX_NAME_NUMBER "X\n"
#endif
#if (defined(__APPLE__) && defined(__MACH__)) || defined(macintosh)
#define DXX_HOGFILE_APPLICATION_BUNDLE	\
				  "\tIn 'Resources' inside the application bundle\n"
#else
#define DXX_HOGFILE_APPLICATION_BUNDLE	""
#endif
#define DXX_MISSING_HOGFILE_ERROR_TEXT	\
		"Could not find a valid hog file (" DXX_HOGFILE_NAMES ")\nPossible locations are:\n"	\
		DXX_HOGFILE_PROGRAM_DATA_DIRECTORY	\
		"\tIn a subdirectory called 'Data'\n"	\
		DXX_HOGFILE_APPLICATION_BUNDLE	\
		"Or use the -hogdir option to specify an alternate location."
		Error(DXX_MISSING_HOGFILE_ERROR_TEXT);
	}

	load_text();

	//print out the banner title
	con_printf(CON_NORMAL, "%s%s  %s\n", DESCENT_VERSION, PHYSFSX_exists(MISSION_DIR "d2x.hog",1) ? "  Vertigo Enhanced" : "", g_descent_build_datetime); // D2X version
	con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2, based on %s.\n", BASED_VERSION);
	con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
	con_printf(CON_NORMAL, "Copyright (C) 1999 Peter Hawkins, 2002 Bradley Bell, 2005-2011 Christian Beckhaeuser\n\n");

	if (GameArg.DbgVerbose)
		con_printf(CON_VERBOSE,"%s%s", TXT_VERBOSE_1, "\n");
	
	ReadConfigFile();

	PHYSFSX_addArchiveContent();

	arch_init();

	select_tmap(GameArg.DbgTexMap);

	Lighting_on = 1;

	con_printf(CON_VERBOSE, "Going into graphics mode...\n");
	gr_set_mode(Game_screen_mode);

	// Load the palette stuff. Returns non-zero if error.
	con_printf(CON_DEBUG, "Initializing palette system...\n" );
	gr_use_palette_table(D2_DEFAULT_PALETTE );

	con_printf(CON_DEBUG, "Initializing font system...\n" );
	gamefont_init();	// must load after palette data loaded.

	set_default_handler(standard_handler);

	con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
	init_movies();		//init movie libraries

	show_titles();

	set_screen_mode(SCREEN_MENU);

	con_printf( CON_DEBUG, "\nDoing gamedata_init..." );
	gamedata_init();

	#ifdef EDITOR
	if (GameArg.EdiSaveHoardData) {
		save_hoard_data();
		exit(1);
	}
	#endif

	if (GameArg.DbgNoRun)
		return(0);

	con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
	texmerge_init( 10 );		// 10 cache bitmaps

	piggy_init_pigfile("groupa.pig");	//get correct pigfile

	con_printf( CON_DEBUG, "\nRunning game...\n" );
	init_game();

	Players[Player_num].callsign[0] = '\0';

	//	If built with editor, option to auto-load a level and quit game
	//	to write certain data.
	#ifdef	EDITOR
	if (GameArg.EdiAutoLoad) {
		strcpy(Auto_file, GameArg.EdiAutoLoad);
		strcpy(Players[0].callsign, "dummy");
	} else
	#endif
	{
		if(GameArg.SysPilot)
		{
			char filename[32] = "";
			int j;

			if (GameArg.SysUsePlayersDir)
				strcpy(filename, "Players/");
			strncat(filename, GameArg.SysPilot, 12);
			filename[8 + 12] = '\0';	// unfortunately strncat doesn't put the terminating 0 on the end if it reaches 'n'
			for (j = GameArg.SysUsePlayersDir? 8 : 0; filename[j] != '\0'; j++) {
				switch (filename[j]) {
					case ' ':
						filename[j] = '\0';
				}
			}
			if(!strstr(filename,".plr")) // if player hasn't specified .plr extension in argument, add it
				strcat(filename,".plr");
			if(PHYSFSX_exists(filename,0))
			{
				strcpy(strstr(filename,".plr"),"\0");
				strcpy(Players[Player_num].callsign, GameArg.SysUsePlayersDir? &filename[8] : filename);
				read_player_file();
				WriteConfigFile();
			}
		}
	}

#ifdef EDITOR
	if (GameArg.EdiAutoLoad) {
		strcpy((char *)&Level_names[0], Auto_file);
		LoadLevel(1, 1);
	}
	else
#endif
	{
		Game_mode = GM_GAME_OVER;
		DoMenu();
	}

	setjmp(LeaveEvents);
	while (window_get_front())
		// Send events to windows and the default handler
		event_process();
	
	// Tidy up - avoids a crash on exit
	{
		window *wind;

		show_menus();
		while ((wind = window_get_front()))
			window_close(wind);
	}

	WriteConfigFile();
	show_order_form();

	con_printf( CON_DEBUG, "\nCleanup...\n" );
	close_game();
	texmerge_close();
	gamedata_close();
	gamefont_close();
	free_text();
	args_exit();
	newmenu_free_background();
	free_mission();
	PHYSFSX_removeArchiveContent();

	return(0);		//presumably successful exit
}
Ejemplo n.º 15
0
static int main(int argc, char *argv[])
{
	if (!PHYSFSX_init(argc, argv))
		return 1;
	con_init();  // Initialise the console

	setbuf(stdout, NULL); // unbuffered output via printf
#ifdef _WIN32
	freopen( "CON", "w", stdout );
	freopen( "CON", "w", stderr );
#endif

	if (CGameArg.SysShowCmdHelp) {
		print_commandline_help();

		return(0);
	}

	printf("\nType '%s -help' for a list of command-line options.\n\n", PROGNAME);

	PHYSFSX_listSearchPathContent();
	
	if (!PHYSFSX_checkSupportedArchiveTypes())
		return(0);

#if defined(DXX_BUILD_DESCENT_I)
	if (! PHYSFSX_contfile_init("descent.hog", 1))
#define DXX_NAME_NUMBER	"1"
#define DXX_HOGFILE_NAMES	"descent.hog"
#elif defined(DXX_BUILD_DESCENT_II)
	if (! PHYSFSX_contfile_init("descent2.hog", 1) && ! PHYSFSX_contfile_init("d2demo.hog", 1))
#define DXX_NAME_NUMBER	"2"
#define DXX_HOGFILE_NAMES	"descent2.hog or d2demo.hog"
#endif
	{
#if defined(__unix__) && !defined(__APPLE__)
#define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY	\
			      "\t$HOME/.d" DXX_NAME_NUMBER "x-rebirth\n"	\
			      "\t" SHAREPATH "\n"
#else
#define DXX_HOGFILE_PROGRAM_DATA_DIRECTORY	\
				  "\tDirectory containing D" DXX_NAME_NUMBER "X\n"
#endif
#if (defined(__APPLE__) && defined(__MACH__)) || defined(macintosh)
#define DXX_HOGFILE_APPLICATION_BUNDLE	\
				  "\tIn 'Resources' inside the application bundle\n"
#else
#define DXX_HOGFILE_APPLICATION_BUNDLE	""
#endif
#define DXX_MISSING_HOGFILE_ERROR_TEXT	\
		"Could not find a valid hog file (" DXX_HOGFILE_NAMES ")\nPossible locations are:\n"	\
		DXX_HOGFILE_PROGRAM_DATA_DIRECTORY	\
		"\tIn a subdirectory called 'Data'\n"	\
		DXX_HOGFILE_APPLICATION_BUNDLE	\
		"Or use the -hogdir option to specify an alternate location."
		UserError(DXX_MISSING_HOGFILE_ERROR_TEXT);
	}

#if defined(DXX_BUILD_DESCENT_I)
	switch (PHYSFSX_fsize("descent.hog"))
	{
		case D1_MAC_SHARE_MISSION_HOGSIZE:
		case D1_MAC_MISSION_HOGSIZE:
			MacHog = 1;	// used for fonts and the Automap
			break;
	}
#endif

	load_text();

	//print out the banner title
#if defined(DXX_BUILD_DESCENT_I)
	con_printf(CON_NORMAL, "%s  %s", DESCENT_VERSION, g_descent_build_datetime); // D1X version
	con_printf(CON_NORMAL, "This is a MODIFIED version of Descent, based on %s.", BASED_VERSION);
	con_printf(CON_NORMAL, "%s\n%s",TXT_COPYRIGHT,TXT_TRADEMARK);
	con_printf(CON_NORMAL, "Copyright (C) 2005-2013 Christian Beckhaeuser");
#elif defined(DXX_BUILD_DESCENT_II)
	con_printf(CON_NORMAL, "%s%s  %s", DESCENT_VERSION, PHYSFSX_exists(MISSION_DIR "d2x.hog",1) ? "  Vertigo Enhanced" : "", g_descent_build_datetime); // D2X version
	con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2, based on %s.", BASED_VERSION);
	con_printf(CON_NORMAL, "%s\n%s",TXT_COPYRIGHT,TXT_TRADEMARK);
	con_printf(CON_NORMAL, "Copyright (C) 1999 Peter Hawkins, 2002 Bradley Bell, 2005-2013 Christian Beckhaeuser");
#endif

	if (CGameArg.DbgVerbose)
		con_puts(CON_VERBOSE, TXT_VERBOSE_1);
	
	ReadConfigFile();

	PHYSFSX_addArchiveContent();

	arch_init();

	select_tmap(CGameArg.DbgTexMap);

#if defined(DXX_BUILD_DESCENT_II)
	Lighting_on = 1;
#endif

	con_printf(CON_VERBOSE, "Going into graphics mode...");
	gr_set_mode(Game_screen_mode);

	// Load the palette stuff. Returns non-zero if error.
	con_printf(CON_DEBUG, "Initializing palette system..." );
#if defined(DXX_BUILD_DESCENT_I)
	gr_use_palette_table( "PALETTE.256" );
#elif defined(DXX_BUILD_DESCENT_II)
	gr_use_palette_table(D2_DEFAULT_PALETTE );
#endif

	con_printf(CON_DEBUG, "Initializing font system..." );
	gamefont_init();	// must load after palette data loaded.

#if defined(DXX_BUILD_DESCENT_II)
	con_printf( CON_DEBUG, "Initializing movie libraries..." );
	init_movies();		//init movie libraries
#endif

	show_titles();

	set_screen_mode(SCREEN_MENU);
#ifdef DEBUG_MEMORY_ALLOCATIONS
	/* Memdebug runs before global destructors, so it incorrectly
	 * reports as leaked any allocations that would be freed by a global
	 * destructor.  This local will force the newmenu globals to be
	 * reset before memdebug scans, which prevents memdebug falsely
	 * reporting them as leaked.
	 *
	 * External tools, such as Valgrind, know to run global destructors
	 * before checking for leaks, so this hack is only necessary when
	 * memdebug is used.
	 */
	struct hack_free_global_backgrounds
	{
		~hack_free_global_backgrounds()
		{
			newmenu_free_background();
		}
	};
	hack_free_global_backgrounds hack_free_global_background;
#endif

	con_printf( CON_DEBUG, "\nDoing gamedata_init..." );
	gamedata_init();

#if defined(DXX_BUILD_DESCENT_II)
#if DXX_USE_EDITOR
	if (GameArg.EdiSaveHoardData) {
		save_hoard_data();
		exit(1);
	}
	#endif
#endif

	if (CGameArg.DbgNoRun)
		return(0);

	con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
	texmerge_init();		// 10 cache bitmaps

#if defined(DXX_BUILD_DESCENT_II)
	piggy_init_pigfile("groupa.pig");	//get correct pigfile
#endif

	con_printf( CON_DEBUG, "\nRunning game..." );
	init_game();

	get_local_player().callsign = {};

#if defined(DXX_BUILD_DESCENT_I)
	key_flush();
#elif defined(DXX_BUILD_DESCENT_II)
	//	If built with editor, option to auto-load a level and quit game
	//	to write certain data.
	#ifdef	EDITOR
	if (!GameArg.EdiAutoLoad.empty()) {
		Players[0].callsign = "dummy";
	} else
	#endif
#endif
	{
		if (!CGameArg.SysPilot.empty())
		{
			char filename[sizeof(PLAYER_DIRECTORY_TEXT) + CALLSIGN_LEN + 4];

			/* Step over the literal PLAYER_DIRECTORY_TEXT when it is
			 * present.  Point at &filename[0] when
			 * PLAYER_DIRECTORY_TEXT is absent.
			 */
			const auto b = &filename[-CGameArg.SysUsePlayersDir];
			snprintf(filename, sizeof(filename), PLAYER_DIRECTORY_STRING("%.12s"), CGameArg.SysPilot.c_str());
			/* The pilot name is never used after this.  Clear it to
			 * free the allocated memory, if any.
			 */
			CGameArg.SysPilot.clear();
			auto p = b;
			for (const auto &facet = std::use_facet<std::ctype<char>>(std::locale::classic()); char &c = *p; ++p)
			{
				c = facet.tolower(static_cast<uint8_t>(c));
			}
			auto j = p - filename;
			if (j < sizeof(filename) - 4 && (j <= 4 || strcmp(&filename[j - 4], ".plr"))) // if player hasn't specified .plr extension in argument, add it
			{
				strcpy(&filename[j], ".plr");
				j += 4;
			}
			if(PHYSFSX_exists(filename,0))
			{
				get_local_player().callsign.copy(b, std::distance(b, &filename[j - 4]));
				read_player_file();
				WriteConfigFile();
			}
		}
	}

#if defined(DXX_BUILD_DESCENT_II)
#if DXX_USE_EDITOR
	if (!GameArg.EdiAutoLoad.empty()) {
		/* Any number >= FILENAME_LEN works */
		Level_names[0].copy_if(GameArg.EdiAutoLoad.c_str(), GameArg.EdiAutoLoad.size());
		LoadLevel(1, 1);
	}
	else
#endif
#endif
	{
		Game_mode = GM_GAME_OVER;
		DoMenu();
	}

	while (window_get_front())
		// Send events to windows and the default handler
		event_process();
	
	// Tidy up - avoids a crash on exit
	{
		window *wind;

		show_menus();
		while ((wind = window_get_front()))
			window_close(wind);
	}

	WriteConfigFile();
	show_order_form();

	con_printf( CON_DEBUG, "\nCleanup..." );
	close_game();
	texmerge_close();
	gamedata_close();
	gamefont_close();
	Current_mission.reset();
	PHYSFSX_removeArchiveContent();

	return(0);		//presumably successful exit
}
Ejemplo n.º 16
0
MergeDialog::MergeDialog(const ustring & text)
{
  event_textbuffer = 0;

  extern Settings *settings;

  mergedialog = gtk_dialog_new();
  gtk_window_set_title(GTK_WINDOW(mergedialog), _("Merge"));
  gtk_window_set_position(GTK_WINDOW(mergedialog), GTK_WIN_POS_CENTER_ON_PARENT);
  gtk_window_set_modal(GTK_WINDOW(mergedialog), TRUE);
  gtk_window_set_default_size(GTK_WINDOW(mergedialog), (int)(settings->genconfig.screen_width_get() * 0.8), (int)(settings->genconfig.screen_height_get() * 0.9));

  dialog_vbox1 = gtk_dialog_get_content_area (GTK_DIALOG (mergedialog));
  gtk_widget_show(dialog_vbox1);

  label = gtk_label_new(_("The merge operation needs manual intervention. Each place that needs intervention shows two buttons with the two alternatives. Please press the buttons with the correct text."));
  gtk_label_set_line_wrap(GTK_LABEL(label), true);
  gtk_widget_show(label);
  gtk_box_pack_start(GTK_BOX(dialog_vbox1), label, FALSE, FALSE, 0);
  gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);

  scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
  gtk_widget_show(scrolledwindow);
  gtk_box_pack_start(GTK_BOX(dialog_vbox1), scrolledwindow, TRUE, TRUE, 0);
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow), GTK_SHADOW_IN);

  textview = gtk_text_view_new();
  gtk_widget_show(textview);
  gtk_container_add(GTK_CONTAINER(scrolledwindow), textview);
  gtk_text_view_set_accepts_tab(GTK_TEXT_VIEW(textview), FALSE);
  gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_WORD);

  textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));

  dialog_action_area1 = gtk_dialog_get_action_area (GTK_DIALOG(mergedialog));
  gtk_widget_show(dialog_action_area1);
  gtk_button_box_set_layout(GTK_BUTTON_BOX(dialog_action_area1), GTK_BUTTONBOX_END);

  new InDialogHelp(mergedialog, NULL, NULL, NULL);

  cancelbutton = gtk_button_new_from_stock("gtk-cancel");
  gtk_widget_show(cancelbutton);
  gtk_dialog_add_action_widget(GTK_DIALOG(mergedialog), cancelbutton, GTK_RESPONSE_CANCEL);
  gtk_widget_set_can_default (GTK_WIDGET (cancelbutton), true);

  okbutton = gtk_button_new_from_stock("gtk-ok");
  gtk_widget_show(okbutton);
  gtk_dialog_add_action_widget(GTK_DIALOG(mergedialog), okbutton, GTK_RESPONSE_OK);
  gtk_widget_set_can_default (GTK_WIDGET (okbutton), true);

  gtk_widget_set_sensitive(okbutton, false);

  g_signal_connect((gpointer) okbutton, "clicked", G_CALLBACK(on_okbutton_clicked), gpointer(this));
  g_signal_connect_after((gpointer) textbuffer, "changed", G_CALLBACK(on_textbuffer_changed), gpointer(this));

  gtk_widget_grab_focus(textview);
  gtk_widget_grab_default(okbutton);

  load_text(text);
}
Ejemplo n.º 17
0
int main(int argc, char *argv[])
{
    int ret = 0;


    if (argc < 2)
    {
        fprintf(stderr, "Usage: transalign_killer [--cldev=x.y] <input file>\n");
        fprintf(stderr, "  --cldev=x.y: x specifies the platform index, y the device index.\n");
        return 1;
    }


    long seq_length;
    char *sequence = load_text(argv[argc - 1], &seq_length);
    if (!sequence)
        return 1;

    seq_length--; // Cut final 0 byte

    // FIXME: All the following code relies on seq_length being a multiple of BASE.

    long round_seq_length = round_up_to_power_of_two(seq_length, BASE_EXP);

    long res_length = 0;
    for (long len = round_seq_length / BASE; len; len /= BASE)
        res_length += len;


    // Use some random index to be searched for here
    unsigned letter_index = seq_length / 2;


    // Select an OpenCL device
    cl_device_id dev = select_device(argc - 1, argv);
    if (!dev)
        return 1;

    // Initialize the OpenCL st...ack
    cl_context ctx = clCreateContext(NULL, 1, &dev, NULL, NULL, NULL);
    cl_command_queue queue = clCreateCommandQueue(ctx, dev, 0, NULL);

    // Load the OpenCL kernesl
    char *prog_src = load_text("trans.cl", NULL);
    if (!prog_src)
        return 1;
    cl_program prog = clCreateProgramWithSource(ctx, 1, (const char **)&prog_src, NULL, NULL);
    free(prog_src);

    // Build them
    clBuildProgram(prog, 0, NULL, NULL, NULL, NULL);
    cl_kernel k_iadd = clCreateKernel(prog, "k_iadd", NULL); // initial addition
    cl_kernel k_cadd = clCreateKernel(prog, "k_cadd", NULL); // consecutive addition
    assert(k_iadd);
    assert(k_cadd);


    // Create the result buffer
    unsigned *result = malloc(res_length * sizeof(unsigned));
    cl_mem result_gpu = clCreateBuffer(ctx, CL_MEM_READ_WRITE | HOST_PTR_POLICY, res_length * sizeof(unsigned), result, NULL);


    clock_start();

    /*** START OF ROCKET SCIENCE LEVEL RUNTIME-TIME INTENSIVE STUFF ***/

    // Bandwidth intensive stuff goes here

    // Copy the sequence to the video memory (or, generally speaking, the OpenCL device)
    cl_mem seq_gpu = clCreateBuffer(ctx, CL_MEM_READ_WRITE | HOST_PTR_POLICY, seq_length * sizeof(char), sequence, NULL);

    long bw1_time = clock_delta();


    // GPU intensive stuff goes here

    /**
     * First, transform every - and \0 into a 0 and every other character into a
     * 1. Then, add consecutive fields (BASE fields) together and store them at
     * the beginning of the result buffer.
     */
    clSetKernelArg(k_iadd, 0, sizeof(result_gpu), &result_gpu);
    clSetKernelArg(k_iadd, 1, sizeof(seq_gpu), &seq_gpu);
    clSetKernelArg(k_iadd, 2, sizeof(unsigned), &(unsigned){seq_length});