Exemple #1
0
 Surface* loadRgbaSurface(const char* filename) override {
   int old_color_conv = _color_conv;
   set_color_conversion(COLORCONV_NONE);
   Surface* sur = loadSurface(filename);
   set_color_conversion(old_color_conv);
   return sur;
 }
Exemple #2
0
/**
 * Load bitmap (this function is aware of truecolor transparency)
 */
static BITMAP *load_bitmap_alpha(const char *filename, bool keep_alpha)
{
    // Allow any color conversions except when loaded file 
    // contains alpha channel
    int cc = get_color_conversion();
    set_color_conversion((COLORCONV_TOTAL | COLORCONV_KEEP_TRANS) & 
        ~(COLORCONV_32A_TO_8 | COLORCONV_32A_TO_15 | COLORCONV_32A_TO_16 | COLORCONV_32A_TO_24));
    BITMAP *bmp_orig = load_bitmap(filename, NULL);
    set_color_conversion(cc);
    return convert_bitmap_alpha(bmp_orig, keep_alpha);
}
Exemple #3
0
Bitmap *ConvertBitmap(Bitmap *src, int dst_color_depth)
{
    int src_col_depth = src->GetColorDepth();
    if (src_col_depth != dst_color_depth)
    {
        int old_conv = get_color_conversion();
        // TODO: find out what is this, and why do we need to call this every time (do we?)
        set_color_conversion(COLORCONV_KEEP_TRANS | COLORCONV_TOTAL);
        Bitmap *dst = BitmapHelper::CreateBitmapCopy(src, dst_color_depth);
        set_color_conversion(old_conv);
        return dst;
    }
    return src;
}
    Image* AllegroImageLoader::load(const std::string& filename, bool convertToDisplayFormat)
    {
#if !(ALLEGRO_VERSION == 4 && ALLEGRO_SUB_VERSION == 0)
        int colconv = get_color_conversion();
#endif

        set_color_conversion(COLORCONV_NONE);

        PALETTE pal;
        BITMAP *bmp = loadBitmap(filename, pal);

        if (bmp == NULL)
        {
            throw FCN_EXCEPTION(std::string("Unable to load: ") + filename);
        }

        BITMAP *bmp2 = create_bitmap_ex(32, bmp->w, bmp->h);

        if (bmp2 == NULL)
        {
            throw FCN_EXCEPTION(std::string("Not enough memory to load: ") + filename);
        }

        set_palette(pal);
        blit(bmp, bmp2, 0, 0, 0, 0, bmp->w, bmp->h);
        destroy_bitmap(bmp);

#if (ALLEGRO_VERSION == 4 && ALLEGRO_SUB_VERSION == 0)
        set_color_conversion(COLORCONV_TOTAL);
#else
        set_color_conversion(colconv);
#endif

        Image *image = new AllegroImage(bmp2, true);

        if (convertToDisplayFormat)
        {
            image->convertToDisplayFormat();
        }

        return image;
    }
Exemple #5
0
Font* load_bitmap_font(const char* filename, int scale)
{
    FONT* allegFont = NULL;
    int old_color_conv = _color_conv;

    set_color_conversion(COLORCONV_NONE);
    PALETTE junk;
    BITMAP* bmp = load_bitmap(filename, junk);
    set_color_conversion(old_color_conv);

    if (bmp) {
        Alleg4Surface sur(bmp, Alleg4Surface::DestroyHandle);
        if (scale > 1)
            sur.applyScale(scale);

        allegFont = bitmap_to_font(reinterpret_cast<BITMAP*>(sur.nativeHandle()));
    }

    if (allegFont)
        return new Alleg4Font(allegFont, Alleg4Font::DeleteAndDestroy);
    else
        return NULL;
}
Exemple #6
0
CPlayer::CPlayer(int x,int y,char *key_bindings_file,int solid)
{	
	set_config_file(key_bindings_file);
	key_left = get_config_int(NULL,"LEFT",0);
	key_right = get_config_int(NULL,"RIGHT",0);
	key_fire  = get_config_int(NULL,"FIRE",0);
	
	this->x = x;
	this->y = y;
	set_config_file(DEFAULT_PLAYER_CONFIG_FILE);
	bonus_frequency = default_bonus_frequency = get_config_int(NULL,"bonus_rate",5);
	more_bonuses_modifier = get_config_int(NULL,"more_bonuses_modifier",1);
	more_bonuses_duration = get_config_int(NULL,"more_bonuses_duration",10);
	
	move_speed = default_move_speed = get_config_int(NULL,"pad_speed",100);
	speed_modifier = get_config_int(NULL,"player_speed_modifier",5);
	
	set_color_conversion(COLORCONV_TOTAL);
	model = load_bitmap("/home/valo/Projects/breakin/graphics/batata.bmp",NULL);
	width = model->w;
	height = model->h;
	
	score = 0;
	last_scored = -30;
	bonus_points = 0;
	
	solid_walls = solid;
	
	immortal_time = get_config_int(NULL,"immortal_time",10);
	
	penetrating = false;
	penetration_time = get_config_int(NULL,"penetration_duration",10);
	
	ball_speed = default_ball_speed = get_config_int(NULL,"ball_speed",5);
	ball_speed_modifier = get_config_int(NULL,"ball_speed_modifier",10);
	
	fast_hit_max_time = get_config_float(NULL,"fast_hit_max_time",0.5);
	
	status_font1 = alfont_load_font(STATUS_FONT1_FILENAME);
	status_font2 = alfont_load_font(STATUS_FONT2_FILENAME);
	alfont_set_font_size(status_font1,50);
	alfont_set_font_size(status_font2,20);
}
Exemple #7
0
int main( int argc, char **argv )
{
    PALETTE pal;
    int i;


    /* init allegro and init palette */
    install_allegro(SYSTEM_NONE, &errno, atexit);
    set_color_depth(8);
    set_color_conversion(COLORCONV_REDUCE_TO_256);
    for( i = 0; i < 256; i++ )
    {
        /* divided by 4 because the colour value ranges from 0-63 */
        pal[i].r = pal[i].g = pal[i].b = i/4;
    }


    srand(time(NULL));

    do_args(argc, argv);

    if( filename == NULL )
    {
        /* +1 for '\0' char */
        filename = malloc(strlen(DEFT_FILENAME)+1);
        if( filename == NULL )
        {
            fprintf(stderr, "error: can't malloc space for map name.\n");
            exit(EXIT_FAILURE);
        }
        strcpy(filename, DEFT_FILENAME);
    }

    lwmapgen(size, grid_size, func_id);

    save_bitmap(filename, map.map, pal);


    return EXIT_SUCCESS;
}
Exemple #8
0
int main(int argc, char *argv[])
{
    BITMAP *bmp;
    PACKFILE *f;

    if (argc != 3) {
        usage();
        return 1;
    }

    if (install_allegro(SYSTEM_NONE, &errno, atexit) != 0)
        return 1;
    set_color_conversion(COLORCONV_NONE);

    bmp = load_bitmap(argv[1], the_pal);
    if (!bmp) {
        printf("Error reading palette from '%s'\n", argv[1]);
        return 1;
    }

    destroy_bitmap(bmp);

    printf("Palette read from '%s'\n", argv[1]);
    printf("Creating RGB map\n");

    create_rgb_table(&the_map, the_pal, NULL);

    f = pack_fopen(argv[2], F_WRITE);
    if (!f) {
        printf("Error writing '%s'\n", argv[2]);
        return 1;
    }

    pack_fwrite(&the_map, sizeof(the_map), f);
    pack_fclose(f);

    printf("RGB mapping table written to '%s'\n", argv[2]);
    return 0;
}
Exemple #9
0
int main(int argc, char *argv[])
{
   int c, w, h;
   char buf[256], buf2[256];
   ANIMATION_TYPE type;

   for (c = 1; c < argc; c++) {
      if (stricmp(argv[c], "-cheat") == 0)
         cheat = TRUE;

      if (stricmp(argv[c], "-jumpstart") == 0)
         jumpstart = TRUE;
   }

   /* The fonts we are using don't contain the full latin1 charset (not to
    * mention Unicode), so in order to display correctly author names in
    * the credits with 8-bit characters, we will convert them down to 7
    * bits with a custom mapping table. Fortunately, Allegro comes with a
    * default custom mapping table which reduces Latin-1 and Extended-A
    * characters to 7 bits. We don't even need to call set_ucodepage()!
    */
   set_uformat(U_ASCII_CP);
   
   srand(time(NULL));
   if (allegro_init() != 0)
      return 1;
   install_keyboard();
   install_timer();
   install_mouse();

   if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
      allegro_message("Error initialising sound\n%s\n", allegro_error);
      install_sound(DIGI_NONE, MIDI_NONE, NULL);
   }

   if (install_joystick(JOY_TYPE_AUTODETECT) != 0) {
      allegro_message("Error initialising joystick\n%s\n", allegro_error);
      install_joystick(JOY_TYPE_NONE);
   }

   if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
      if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
         set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
         allegro_message("Unable to set any graphic mode\n%s\n",
                         allegro_error);
         return 1;
      }
   }

   get_executable_name(buf, sizeof(buf));
   replace_filename(buf2, buf, "demo.dat", sizeof(buf2));
   set_color_conversion(COLORCONV_NONE);
   data = load_datafile(buf2);
   if (!data) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error loading %s\n", buf2);
      exit(1);
   }

   if (!jumpstart) {
      intro_screen();
   }

   clear_bitmap(screen);
   set_gui_colors();
   set_mouse_sprite(NULL);

   if (!gfx_mode_select(&c, &w, &h))
      exit(1);

   if (pick_animation_type(&type) < 0)
      exit(1);

   init_display(c, w, h, type);

   generate_explosions();

   //stop_sample(data[INTRO_SPL].dat);

   clear_bitmap(screen);

   while (title_screen())
      play_game();

   destroy_display();

   destroy_explosions();

   stop_midi();

   set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);

   end_title();

   unload_datafile(data);

   allegro_exit();

   return 0;
}
Exemple #10
0
/* main:
 *  Guess what this function does.
 */
int main(int argc, char *argv[])
{
   PACKFILE *f;
   CFURLRef cf_url_ref;
   FSRef fs_ref;
   FSSpec fs_spec;
   IconFamilyHandle icon_family;
   Handle raw_data;
   char datafile[MAX_STRING_SIZE];
   char bundle[MAX_STRING_SIZE];
   char bundle_dir[MAX_STRING_SIZE];
   char bundle_contents_dir[MAX_STRING_SIZE];
   char bundle_contents_resources_dir[MAX_STRING_SIZE];
   char bundle_contents_macos_dir[MAX_STRING_SIZE];
   char bundle_contents_frameworks_dir[MAX_STRING_SIZE];
   char *bundle_exe = NULL;
   char bundle_plist[MAX_STRING_SIZE];
   char bundle_pkginfo[MAX_STRING_SIZE];
   char bundle_icns[MAX_STRING_SIZE];
   char bundle_version[MAX_STRING_SIZE];
   char bundle_long_version[MAX_STRING_SIZE];
   char *buffer = NULL;
   int arg, type = 0, result = 0;
   int i, size, x, y, mask_bit, mask_byte;
   unsigned char *data;
   
   install_allegro(SYSTEM_NONE, &errno, &atexit);
   set_color_depth(32);
   set_color_conversion(COLORCONV_TOTAL | COLORCONV_KEEP_TRANS);
   
   if (argc < 2)
      usage();
   
   datafile[0] = '\0';
   bundle[0] = '\0';
   select_palette(black_palette);
   
   /* Parse command line and load any given resource */
   for (arg = 2; arg < argc; arg++) {
      if (!strcmp(argv[arg], "-m"))
         flags |= F_MOVE;
      else if (!strcmp(argv[arg], "-e"))
         flags |= F_EMBED_FRAMEWORK;
      else if (!strcmp(argv[arg], "-o")) {
         if ((argc < arg + 2) || (bundle[0] != '\0'))
	    usage();
	 strcpy(bundle, argv[++arg]);
      }
      else if (!strcmp(argv[arg], "-v")) {
         if (argc < arg + 2)
	    usage();
	 flags |= F_GOT_VERSION;
	 strcpy(bundle_version, argv[++arg]);
      }
      else if (!strcmp(argv[arg], "-V")) {
         if (argc < arg + 2)
	    usage();
	 flags |= F_GOT_LONG_VERSION;
	 strcpy(bundle_long_version, argv[++arg]);
      }
      else if (!strcmp(argv[arg], "-d")) {
         if (argc < arg + 2)
	    usage();
	 strcpy(datafile, argv[++arg]);
      }
      else if ((!strcmp(argv[arg], "-16")) || (!strcmp(argv[arg], "-32")) ||
               (!strcmp(argv[arg], "-48")) || (!strcmp(argv[arg], "-128"))) {
         if (argc < arg + 2)
	    usage();
	 switch (atoi(&argv[arg][1])) {
	    case 16: type = 0; break;
	    case 32: type = 1; break;
	    case 48: type = 2; break;
	    case 128: type = 3; break;
	 }
	 if (load_resource(datafile, argv[++arg], &icon_data[type])) {
	    result = -1;
	    goto exit_error;
	 }
      }
      else {
         if (load_resource(datafile, argv[arg], NULL)) {
	    result = -1;
	    goto exit_error;
	 }
      }
   }
   
   buffer = malloc(4096);
   if (!buffer) {
      result = -1;
      goto exit_error_bundle;
   }
   
   bundle_exe = argv[1];
   if (!exists(bundle_exe)) {
      fprintf(stderr, "Cannot locate executable file '%s'\n", bundle_exe);
      result = -1;
      goto exit_error;
   }
   if (bundle[0] == '\0')
      strcpy(bundle, bundle_exe);
   replace_extension(bundle_dir, bundle, "app", MAX_STRING_SIZE);
   strcpy(bundle_contents_dir, bundle_dir);
   strcat(bundle_contents_dir, "/Contents");
   strcpy(bundle_contents_resources_dir, bundle_contents_dir);
   strcat(bundle_contents_resources_dir, "/Resources");
   strcpy(bundle_contents_macos_dir, bundle_contents_dir);
   strcat(bundle_contents_macos_dir, "/MacOS");
   strcpy(bundle_contents_frameworks_dir, bundle_contents_dir);
   strcat(bundle_contents_frameworks_dir, "/Frameworks");
   bundle_icns[0] = '\0';
   bundle_plist[0] = '\0';
   bundle_pkginfo[0] = '\0';
   
   /* Create bundle structure */
   if ((mkdir(bundle_dir, 0777) && (errno != EEXIST)) ||
       (mkdir(bundle_contents_dir, 0777) && (errno != EEXIST)) ||
       (mkdir(bundle_contents_resources_dir, 0777) && (errno != EEXIST)) ||
       (mkdir(bundle_contents_macos_dir, 0777) && (errno != EEXIST))) {
      fprintf(stderr, "Cannot create %s\n", bundle_dir);
      result = -1;
      goto exit_error_bundle;
   }
   
   /* Copy/move executable into the bundle */
   if (copy_file(bundle_exe, bundle_contents_macos_dir)) {
      fprintf(stderr, "Cannot create %s\n", bundle_contents_macos_dir);
      result = -1;
      goto exit_error_bundle;
   }
   strcat(bundle_contents_macos_dir, "/");
   strcat(bundle_contents_macos_dir, get_filename(bundle_exe));
   chmod(bundle_contents_macos_dir, 0755);
   if (flags & F_MOVE)
      unlink(bundle_exe);
   
   /* Embed Allegro framework if requested */
   if (flags & F_EMBED_FRAMEWORK) {
      if (!file_exists("/Library/Frameworks/Allegro.framework", FA_RDONLY | FA_DIREC, NULL)) {
         fprintf(stderr, "Cannot find Allegro framework\n");
	 result = -1;
	 goto exit_error_bundle;
      }
      if (!exists("/Library/Frameworks/Allegro.framework/Resources/Embeddable")) {
         fprintf(stderr, "Cannot embed system wide Allegro framework; install embeddable version first!\n");
	 result = -1;
	 goto exit_error_bundle;
      }
      sprintf(buffer, "/Developer/Tools/pbxcp -exclude .DS_Store -exclude CVS -resolve-src-symlinks /Library/Frameworks/Allegro.framework %s", bundle_contents_frameworks_dir);
      if ((mkdir(bundle_contents_frameworks_dir, 0777) && (errno != EEXIST)) ||
	  (system(buffer))) {
         fprintf(stderr, "Cannot create %s\n", bundle_contents_frameworks_dir);
	 result = -1;
	 goto exit_error_bundle;
      }
   }
   
   /* Setup the .icns resource */
   if (flags & F_ICONS_DEFINED) {
      strcat(bundle_contents_resources_dir, "/");
      strcat(bundle_contents_resources_dir, get_filename(bundle));
      replace_extension(bundle_icns, bundle_contents_resources_dir, "icns", MAX_STRING_SIZE);
      
      icon_family = (IconFamilyHandle)NewHandle(0);
      
      for (i = 0; i < 4; i++) {
         if (flags & icon_data[i].defined) {
	    /* Set 32bit RGBA data */
	        raw_data = NewHandle(icon_data[i].size * icon_data[i].size * 4);
	    data = *(unsigned char **)raw_data;
	    for (y = 0; y < icon_data[i].size; y++) {
	       for (x = 0; x < icon_data[i].size; x++) {
	          *data++ = geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
	          *data++ = getr32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
	          *data++ = getg32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
	          *data++ = getb32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
	       }
	    }
	    if (SetIconFamilyData(icon_family, icon_data[i].data, raw_data) != noErr) {
               DisposeHandle(raw_data);
	       fprintf(stderr, "Error setting %dx%d icon resource RGBA data\n", icon_data[i].size, icon_data[i].size);
	       result = -1;
	       goto exit_error_bundle;
	    }
	    DisposeHandle(raw_data);
	    /* Set 8bit mask */
            raw_data = NewHandle(icon_data[i].size * icon_data[i].size);
	    data = *(unsigned char **)raw_data;
	    for (y = 0; y < icon_data[i].size; y++) {
	       for (x = 0; x < icon_data[i].size; x++) {
	          *data++ = geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]);
	       }
	    }
	    if (SetIconFamilyData(icon_family, icon_data[i].mask8, raw_data) != noErr) {
               DisposeHandle(raw_data);
	       fprintf(stderr, "Error setting %dx%d icon resource 8bit mask\n", icon_data[i].size, icon_data[i].size);
	       result = -1;
	       goto exit_error_bundle;
	    }
	    DisposeHandle(raw_data);
	    /* Set 1bit mask */
	    if (icon_data[i].mask1) {
	       size = ((icon_data[i].size * icon_data[i].size) + 7) / 8;
	       raw_data = NewHandle(size * 2);
	       data = *(unsigned char **)raw_data;
	       mask_byte = 0;
	       mask_bit = 7;
	       for (y = 0; y < icon_data[i].size; y++) {
	          for (x = 0; x < icon_data[i].size; x++) {
		     if (geta32(((unsigned int *)(icon_data[i].scaled->line[y]))[x]) >= 0xfd)
		        mask_byte |= (1 << mask_bit);
		     mask_bit--;
		     if (mask_bit < 0) {
		        *data++ = mask_byte;
			mask_byte = 0;
			mask_bit = 7;
		     }
		  }
	       }
	       memcpy(*raw_data + size, *raw_data, size);
               if (SetIconFamilyData(icon_family, icon_data[i].mask1, raw_data) != noErr) {
                  DisposeHandle(raw_data);
	          fprintf(stderr, "Error setting %dx%d icon resource 1bit mask\n", icon_data[i].size, icon_data[i].size);
	          result = -1;
	          goto exit_error_bundle;
	       }
	       DisposeHandle(raw_data);
	    }
	 }
      }

      f = pack_fopen(bundle_icns, F_WRITE);
      if (!f) {
         fprintf(stderr, "Cannot create %s\n", bundle_icns);
	 result = -1;
	 goto exit_error_bundle;
      }
      pack_fclose(f);
      
      cf_url_ref = CFURLCreateWithBytes(kCFAllocatorDefault, (unsigned char *)bundle_icns, strlen(bundle_icns), 0, NULL);
      if (!cf_url_ref) {
         fprintf(stderr, "Cannot create %s\n", bundle_icns);
	 result = -1;
	 goto exit_error_bundle;
      }
      CFURLGetFSRef(cf_url_ref, &fs_ref);
      CFRelease(cf_url_ref);
      if ((FSGetCatalogInfo(&fs_ref, kFSCatInfoNone, NULL, NULL, &fs_spec, NULL)) || 
          (WriteIconFile(icon_family, &fs_spec) != noErr)) {
         fprintf(stderr, "Cannot create %s\n", bundle_icns);
	 result = -1;
	 goto exit_error_bundle;
      }
      DisposeHandle((Handle)icon_family);
   }
   
   /* Setup Info.plist */
   sprintf(bundle_plist, "%s/Info.plist", bundle_contents_dir);
   f = pack_fopen(bundle_plist, F_WRITE);
   if (!f) {
      fprintf(stderr, "Cannot create %s\n", bundle_plist);
      result = -1;
      goto exit_error_bundle;
   }
   sprintf(buffer, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
      "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
      "<plist version=\"1.0\">\n"
      "<dict>\n"
      "\t<key>CFBundleExecutable</key>\n"
      "\t<string>%s</string>\n"
      "\t<key>CFBundleInfoDictionaryVersion</key>\n"
      "\t<string>6.0</string>\n"
      "\t<key>CFBundlePackageType</key>\n"
      "\t<string>APPL</string>\n"
      "\t<key>CFBundleSignature</key>\n"
      "\t<string>%s</string>\n"
      "\t<key>CFBundleVersion</key>\n"
      "\t<string>%s</string>\n"
      "\t<key>CFBundleDocumentTypes</key>\n"
      "\t<array>\n"
      "\t\t<dict>\n"
      "\t\t\t<key>CFBundleTypeExtensions</key>\n"
      "\t\t\t<array>\n"
      "\t\t\t\t<string>*</string>\n"
      "\t\t\t</array>\n"
      "\t\t\t<key>CFBundleTypeName</key>\n"
      "\t\t\t<string>NSStringPboardType</string>\n"
      "\t\t\t<key>CFBundleTypeOSTypes</key>\n"
      "\t\t\t<array>\n"
      "\t\t\t\t<string>****</string>\n"
      "\t\t\t</array>\n"
      "\t\t\t<key>CFBundleTypeRole</key>\n"
      "\t\t\t<string>Viewer</string>\n"
      "\t\t</dict>\n"
      "\t</array>\n",
      get_filename(bundle_exe), "????", (flags & F_GOT_VERSION) ? bundle_version : "1.0");
   pack_fputs(buffer, f);
   if (flags & F_GOT_LONG_VERSION) {
      sprintf(buffer, "\t<key>CFBundleGetInfoString</key>\n"
         "\t<string>%s</string>\n", bundle_long_version);
      pack_fputs(buffer, f);
   }
   if (flags & F_ICONS_DEFINED) {
      sprintf(buffer, "\t<key>CFBundleIconFile</key>\n"
         "\t<string>%s</string>\n", get_filename(bundle_icns));
      pack_fputs(buffer, f);
   }
   pack_fputs("</dict>\n</plist>\n", f);
   pack_fclose(f);
   
   /* Setup PkgInfo */
   sprintf(bundle_pkginfo, "%s/PkgInfo", bundle_contents_dir);
   f = pack_fopen(bundle_pkginfo, F_WRITE);
   if (!f) {
      fprintf(stderr, "Cannot create %s\n", bundle_pkginfo);
      result = -1;
      goto exit_error_bundle;
   }
   pack_fputs("APPL????", f);
   pack_fclose(f);
   
exit_error:
   if (buffer)
      free(buffer);
   for (i = 0; i < 4; i++) {
      if (icon_data[i].original)
         destroy_bitmap(icon_data[i].original);
      if (icon_data[i].workspace)
         destroy_bitmap(icon_data[i].workspace);
      if (icon_data[i].scaled)
         destroy_bitmap(icon_data[i].scaled);
   }
   return result;

exit_error_bundle:
   sprintf(buffer, "%s/%s", bundle_contents_macos_dir, get_filename(bundle_exe));
   unlink(buffer);
   unlink(bundle_plist);
   unlink(bundle_pkginfo);
   unlink(bundle_icns);
   rmdir(bundle_dir);
   rmdir(bundle_contents_dir);
   rmdir(bundle_contents_resources_dir);
   rmdir(bundle_contents_macos_dir);
   goto exit_error;
}
Exemple #11
0
/***
  Function : install()
  Returns  : TRUE on succes, FALSE on failure
  Purpose  : Will install game variables, sets up the entire game.
***/
bool install()
{
    // Each time we run the game, we clear out the logbook
    FILE *fp;
    fp = fopen("log.txt", "wt");

    if (fp)
    {
        fprintf(fp, "Counter-Strike 2D Logbook\n");
        fprintf(fp, "-------------------------\n\n"); // print head of logbook
        fclose(fp);
    }

    logbook("--------------");
    logbook("Initialization");
    logbook("--------------");

    // init game
    map.init();
    game.init();
    steam.init();

    logbook("Creating entity types.");
    game.install_entities();

    // Logbook notification
    logbook("\n-------");
    logbook("Allegro");
    logbook("-------");


    // ALLEGRO - INIT
    if (allegro_init() != 0)
        return false;

    logbook(allegro_id);
    yield_timeslice();
    logbook("yield_timeslice()");

    int r = install_timer();
    if (r > -1) logbook("install_timer()");
    else
    {
        logbook("FAILED");
        return false;
    }

    alfont_init();
    logbook("alfont_init()");
    install_keyboard();
    logbook("install_keyboard()");
    install_mouse();
    logbook("install_mouse()");

    logbook("setting up timer functions / locking functions & memory");
    /* set up the interrupt routines... */
    LOCK_VARIABLE(RUNNING_TIMER_tenth);
    LOCK_VARIABLE(RUNNING_TIMER_fps);
    LOCK_FUNCTION(timer_tenth);
    LOCK_FUNCTION(fps_proc);

    install_int(timer_tenth, 10);
    install_int(fps_proc, 1000);

    logbook("Timers installed");

    frame_count = fps = 0;


    // set window title
    char title[80];
    sprintf(title, "Counter-Strike 2D");

    // Set window title
    set_window_title(title);
    char window_title[256];
    sprintf(window_title, "Window title set: [%s]", title);
    logbook(window_title);

    set_color_depth(16);      // run in 16 bit mode
    if (game.windowed)
    {
        int r = set_gfx_mode(GFX_AUTODETECT_WINDOWED, game.screen_x, game.screen_y, game.screen_x, game.screen_y);
        if (r > -1)
        {
            // Succes
        }
        else
        {
            // GFX_DIRECTX_ACCEL / GFX_AUTODETECT
            r = set_gfx_mode(GFX_DIRECTX_ACCEL, game.screen_x, game.screen_y, game.screen_x, game.screen_y);
            if (r > -1)
            {
                game.windowed = false;
                logbook("Could not enter windowed-mode; settings.d3 adjusted");
            }
            else
            {
                logbook("ERROR - !");
                return false;
            }
        }
    }
    else
    {
        int r = set_gfx_mode(GFX_AUTODETECT, game.screen_x, game.screen_y, game.screen_x, game.screen_y);

        // succes
        if (r > -1)
        {

        }
        else
        {
            logbook("ERROR - !!");
            return false;
        }

    }


    text_mode(0);

    logbook("Loading font data");
    // loading font

    game_font = alfont_load_font("gfx\\font\\tahoma.ttf");

    if (game_font != NULL)
    {
        alfont_set_font_size(game_font, 20); // set size
    }
    else
        allegro_message("Error loading tahoma.ttf!");

    // CS Font
    cs_font = alfont_load_font("gfx\\font\\cs.ttf");

    if (cs_font != NULL)
    {
        alfont_set_font_size(cs_font, 20); // set size
    }
    else
        allegro_message("Error loading cs.ttf");

    alfont_text_mode(-1);

    if (set_display_switch_mode(SWITCH_BACKGROUND) < 0)
    {
        set_display_switch_mode(SWITCH_PAUSE);
        logbook("Display 'switch and pause' mode set");
    }
    else
        logbook("Display 'switch to background' mode set");

    // sound
    logbook("Initializing sound");
    int s = install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);

    /***
     Bitmap Creation
     ***/

    bmp_screen = create_bitmap(game.screen_x, game.screen_y);

    if (bmp_screen == NULL)
    {
        logbook("ERROR: Could not create bitmap: bmp_screen");
        return false;
    }
    else
        logbook("Bitmap created: bmp_screen");

    bmp_collide = create_bitmap(game.screen_x, game.screen_y);

    if (bmp_collide == NULL)
    {
        logbook("ERROR: Could not create bitmap: bmp_collide");
        return false;
    }
    else
        logbook("Bitmap created: bmp_collide");

    /*** End of Bitmap Creation ***/

    // load datafiles
    graphics = load_datafile("graphics.dat");
    if (graphics == NULL)
    {
        logbook("ERROR: Could not load datafile: graphics.dat");
        return false;
    }
    else
        logbook("Datafile loaded: graphics.dat");

    // Shadows
    shadows = load_datafile("shadows.dat");
    if (shadows == NULL)
    {
        logbook("ERROR: Could not load datafile: shadows.dat");
        return false;
    }
    else
        logbook("Datafile loaded: shadows.dat");

    // HUD
    hud = load_datafile("hud.dat");
    if (hud == NULL)
    {
        logbook("ERROR: Could not load datafile: hud.dat");
        return false;
    }
    else
        logbook("Datafile loaded: hud.dat");

    //set_color_conversion(COLORCONV_NONE);
    set_color_conversion(COLORCONV_MOST);
    logbook("Color conversion method set");

    // setup mouse speed
    set_mouse_speed(2,2);

    logbook("Mouse speed set");

    logbook("");
    logbook("----");
    logbook("GAME ");
    logbook("----");

    game.LOAD_TexturesFromDataFile("data//de_aztec.dat");
//  DATA_Init();

    // randomize timer
    srand( (unsigned)time( NULL ) );

    //srand(time(NULL));

    // normal sounds are loud, the music is lower (its background music, so it should not be disturbing)
    set_volume(255, 200);

    set_trans_blender(128, 128, 128, 128);

    logbook("");
    logbook("--------------");
    logbook("BATTLE CONTROL");
    logbook("--------------");
    logbook("\n3...2...1... GO!\n");
    return true;
}
Exemple #12
0
int main(void)
{
   BITMAP *dbuf;
   BITMAP *b;
   BITMAP *b2;
   int mode = NORMAL;
   float fangle = 0;
   float fscale = 1;
   float inc = 0.002;
   int dir = -1;

   if (allegro_init() != 0) {
      return 1;
   }
   set_color_depth(32);
   install_keyboard();
   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) {
      allegro_message("Could not set graphics mode\n");
      return 1;
   }

   dbuf = create_bitmap(SCREEN_W, SCREEN_H);
   if (!dbuf) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Could not create double buffer\n");
      return 1;
   }

   /* Load the alpha bitmap. This is used for alpha and normal modes */
   set_color_conversion(COLORCONV_KEEP_ALPHA);
   b = load_bitmap("inkblot.tga", NULL);
   if (!b) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Could not load inkblot.tga\n");
      return 1;
   }

   /* Make a non-alpha copy for drawing lit */
   b2 = create_bitmap(b->w, b->h);
   if (!b2) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error creating bitmap\n");
      return 1;
   }
   clear_to_color(b2, makeacol(255, 255, 255, 255));
   set_alpha_blender();
   draw_trans_sprite(b2, b, 0, 0);

   while (!key[KEY_ESC]) {
      fixed angle = ftofix(fangle);
      fixed scale = ftofix(fscale);
      float x = (SCREEN_W-(b->w*fscale))/2;
      float y = (SCREEN_H-(b->h*fscale))/2;

      /* XXX flickers badly due to no buffering */
      clear_to_color(dbuf, makecol(255, 255, 255));
      textout_centre_ex(dbuf, font, "Press 'n' for next mode", SCREEN_W/2, SCREEN_H-30, makecol(0, 0, 0), -1);
      switch (mode) {
         case NORMAL:
            rotate_scaled_sprite(dbuf, b, x, y, angle, scale);
            textout_centre_ex(dbuf, font, "Normal", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1);
            break;
         case ALPHA:
            set_alpha_blender();
            rotate_scaled_sprite_trans(dbuf, b, x, y, angle, scale);
            textout_centre_ex(dbuf, font, "Alpha", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1);
            break;
         case LIT:
            set_trans_blender(255, 0, 0, 0);
            rotate_scaled_sprite_lit(dbuf, b2, x, y, angle, scale, 128);
            textout_centre_ex(dbuf, font, "Lit", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1);
            break;
      }
      blit(dbuf, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

      fangle += 1;
      fscale += dir*inc;
      if (fscale < 0.5) {
         dir = -dir;
         fscale = 0.5;
      }
      else if (fscale > 1) {
         dir = -dir;
         fscale = 1;
      }

      rest(5);

      if (keypressed()) {
         int k = readkey();
         switch (k >> 8) {
            case KEY_N:
               mode++;
               mode %= 3;
               break;
         }
      }
   }

   destroy_bitmap(b);
   destroy_bitmap(b2);
   destroy_bitmap(dbuf);
   return 0;
}
int
main(int argc, char **argv)
{
	BITMAP *bmp;
	PACKFILE *f;
	char *file = NULL, *times = NULL, *memory = NULL;
	int arg, i, n, start, end, size;

	allegro_init();
	install_keyboard();
	install_timer();
	
	jpgalleg_init();
	
	set_color_conversion(COLORCONV_NONE);
	
	for (arg = 1; arg < argc; arg++) {
		if (!strcmp(argv[arg], "-nommx"))
			cpu_capabilities &= ~CPU_MMX;
		else if (!strcmp(argv[arg], "-f"))
			file = argv[++arg];
		else if (!times)
			times = argv[arg];
		else
			about();
	}
	if (times)
		n = atoi(times);
	else
		n = 30;
	if (!file)
		file = "jpgalleg.jpg";
	bmp = load_jpg(file, NULL);
	if (!bmp) {
		printf("Cannot find %s!\n", file);
		return -1;
	}
	size = file_size(file);
	memory = (char *)malloc(size);
	if (!memory) {
		printf("Not enough memory!\n");
		return -1;
	}
	f = pack_fopen(file, F_READ);
	pack_fread(memory, size, f);
	pack_fclose(f);
	
	LOCK_FUNCTION(timer_handler);
	LOCK_VARIABLE(timer);
	
	install_int(timer_handler, 10);
	
	printf("Average timing for %d function calls:\n", n);
	start = timer;
	for (i = 0; i < n; i++)
		bmp = load_jpg(file, NULL);
	end = timer;
	printf("load_jpg: %f seconds\n", ((float)end - (float)start) / 1000.0 / (float)n);

	start = timer;
	for (i = 0; i < n; i++)
		bmp = load_memory_jpg(memory, size, NULL);
	end = timer;
	printf("load_memory_jpg: %f seconds\n", ((float)end - (float)start) / 1000.0 / (float)n);
	
	free(memory);
	return 0;
}
Exemple #14
0
/* See README for details.
 */
void
abitmap_init (char const *path, DATAFILE *datafile)
{
	int i;
	int prev[10];
	int cv;
	char str[1024];
	DATAFILE *dat;

	cv = get_color_conversion ();
	set_color_conversion (COLORCONV_TOTAL | COLORCONV_KEEP_TRANS);

	used_bitmaps_cleanup ();

	push_config_state ();
	dat = set_theme_config (path, datafile);
	if (dat != datafile)
		used_dat = dat;

	theme->fg_color = get_color_string ("fg", "0x000000");
	theme->bg_color = get_color_string ("bg", "0xffffff");
	theme->mg_color = get_color_string ("mg", "0x808080");

	theme->textpushx = get_config_int ("agup.cfg", "px", 0);
	theme->textpushy = get_config_int ("agup.cfg", "py", 0);

	for (i = 0; bload[i].name; i++) {
		int j;
		int s;

		char const *suffix[] = { "", "_hl", "_dis" };

		for (s = 0; bload[i].name[s] == ' '; s++);

		for (j = 0; j < 3; j++) {
			char **argv = NULL;
			int argc = 0;
			BITMAP *bmp = NULL;
			int got_color = 0;

			theme->bitmaps[bload[i].elem][j].bmp = NULL;
			theme->bitmaps[bload[i].elem][j].flags = 0;
			theme->bitmaps[bload[i].elem][j].bl = 0;
			theme->bitmaps[bload[i].elem][j].br = 0;
			theme->bitmaps[bload[i].elem][j].bt = 0;
			theme->bitmaps[bload[i].elem][j].bb = 0;

			sprintf (str, "%s%s", bload[i].name + s, suffix[j]);
			argv = get_config_argv ("agup.cfg", str, &argc);

			TRACE ("%s: ", str);

			if (argc) {
				bmp = find_theme_bitmap (dat, argv[0]);
			}

			if (bmp) {
				int a;

				theme->bitmaps[bload[i].elem][j].bmp = bmp;

				for (a = 1; a < argc; a++) {
					if (!strcmp (argv[a], "stretch"))
						theme->bitmaps[bload[i].elem][j].flags |=
							ABMAP_STRETCH_H | ABMAP_STRETCH_V;
					else if (!strcmp (argv[a], "center"))
						theme->bitmaps[bload[i].elem][j].flags |=
								ABMAP_CENTER_H | ABMAP_CENTER_V;
					else if (!strcmp (argv[a], "stretchh"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_STRETCH_H;
					else if (!strcmp (argv[a], "centerh"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_CENTER_H;
					else if (!strcmp (argv[a], "alignh"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_ALIGN_H;
					else if (!strcmp (argv[a], "stretchv"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_STRETCH_V;
					else if (!strcmp (argv[a], "centerv"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_CENTER_V;
					else if (!strcmp (argv[a], "alignv"))
						theme->bitmaps[bload[i].elem][j].flags |= ABMAP_ALIGN_V;
					else if (!strcmp (argv[a], "cut")) {
						int cx, cy, cw, ch;
						a++;
						if (a < argc) {
							cx = strtol (argv[a], NULL, 10);
							a++;
							if (a < argc) {
								cy = strtol (argv[a], NULL, 10);
								a++;
								if (a < argc) {
									cw = strtol (argv[a], NULL, 10);
									a++;
									if (a < argc) {
										BITMAP *sub;
										ch = strtol (argv[a], NULL, 10);
										if (cw <= 0)
											cw += bmp->w;
										if (ch <= 0)
											ch += bmp->h;
										sub = create_sub_bitmap (bmp, cx, cy, cw, ch);
										used_bitmap (sub, NULL);
										theme->bitmaps[bload[i].elem][j].bmp = sub;
									}
								}
							}
						}
					}
					else if (!strcmp (argv[a], "border")) {
						a++;
						if (a < argc) {
							theme->bitmaps[bload[i].elem][j].bl = strtol (argv[a], NULL, 10);
							a++;
							if (a < argc) {
								theme->bitmaps[bload[i].elem][j].br =
									strtol (argv[a], NULL, 10);
								a++;
								if (a < argc) {
									theme->bitmaps[bload[i].elem][j].bt =
										strtol (argv[a], NULL, 10);
									a++;
									if (a < argc) {
										theme->bitmaps[bload[i].elem][j].bb =
											strtol (argv[a], NULL, 10);
									}
								}
							}
						}
					}
					else if (!strcmp (argv[a], "color")) {
						a++;
						if (a < argc) {
							int rgb32 = strtol (argv[a], NULL, 0);

							theme->bitmaps[bload[i].elem][j].color =
								makecol (rgb32 >> 16, (rgb32 >> 8) & 255,
								rgb32 & 255);
							got_color = 1;
							TRACE ("color %06x ", rgb32);
						}
					}
				}
				TRACE ("loaded successfully.\n");
			} else {
				/* If everything fails, try to inherit from another bitmap. */
				if (j) {
Exemple #15
0
int main(int argc, char *argv[])
{
    BITMAP *fg;
    int depth = 16;
    const char *file;

    allegro_init();
    install_keyboard();

    switch (argc) {
	case 1:
	    file = "alpha.png";
	    break;
	case 2:
	    file = argv[1];
	    break;
	default:
	    file = argv[1];
	    depth = atoi(argv[2]);
	    break;
    }

    if (depth == 8) {
	allegro_message("Truecolour modes only.\n");
	return 1;
    }

    set_color_depth(depth);
    if ((set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) < 0) &&
        (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) < 0)) {
	allegro_message("Unable to set video mode (640x480x%d).\n", depth);
	return 1;
    }

    /* We can't lose the alpha channel when we load the image. */
    set_color_conversion(COLORCONV_NONE);

    fg = load_png(file, NULL);
    if (!fg) {
	set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
	allegro_message("Unable to load alpha.png\n");
	return 1;
    }

    acquire_screen();

    toilet(screen);

    /* Enable alpha transparency, then draw onto the screen. */
    set_alpha_blender();
    draw_trans_sprite(screen, fg, (SCREEN_W - fg->w) / 2, (SCREEN_H - fg->h) / 2);

    release_screen();

    /* Ooh, ahh. */
    readkey();

    destroy_bitmap(fg);

    return 0;
}
Exemple #16
0
int main(int argc, char *argv[])
{
   char buf[256];
   PALETTE pal;
   BITMAP *image1;
   BITMAP *image2;
   BITMAP *buffer;
   int r, g, b, a;
   int x, y, w, h;
   int x1, y1, x2, y2;
   int prevx1, prevy1, prevx2, prevy2;
   int timer;
   int bpp = -1;
   int ret = -1;

   if (allegro_init() != 0)
      return 1;
   install_keyboard(); 
   install_timer();

   /* what color depth should we use? */
   if (argc > 1) {
      if ((argv[1][0] == '-') || (argv[1][0] == '/'))
	 argv[1]++;
      bpp = atoi(argv[1]);
      if ((bpp != 15) && (bpp != 16) && (bpp != 24) && (bpp != 32)) {
	 allegro_message("Invalid color depth '%s'\n", argv[1]);
	 return 1;
      }
   }

   if (bpp > 0) {
      /* set a user-requested color depth */
      set_color_depth(bpp);
      ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
   }
   else {
      /* autodetect what color depths are available */
      static int color_depths[] = { 16, 15, 32, 24, 0 };
      for (a=0; color_depths[a]; a++) {
	 bpp = color_depths[a];
	 set_color_depth(bpp);
	 ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
	 if (ret == 0)
	    break;
      }
   }

   /* did the video mode set properly? */
   if (ret != 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error setting %d bit graphics mode\n%s\n", bpp,
		      allegro_error);
      return 1;
   }

   /* specify that images should be loaded in a truecolor pixel format */
   set_color_conversion(COLORCONV_TOTAL);

   /* load the first picture */
   replace_filename(buf, argv[0], "allegro.pcx", sizeof(buf));
   image1 = load_bitmap(buf, pal);
   if (!image1) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error reading %s!\n", buf);
      return 1;
   }

   /* load the second picture */
   replace_filename(buf, argv[0], "mysha.pcx", sizeof(buf));
   image2 = load_bitmap(buf, pal);
   if (!image2) {
      destroy_bitmap(image1);
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error reading %s!\n", buf);
      return 1;
   }

   /* create a double buffer bitmap */
   buffer = create_bitmap(SCREEN_W, SCREEN_H);

   /* Note that because we loaded the images as truecolor bitmaps, we don't
    * need to bother setting the palette, and we can display both on screen
    * at the same time even though the source files use two different 256
    * color palettes...
    */

   prevx1 = prevy1 = prevx2 = prevy2 = 0;

   textprintf_ex(screen, font, 0, SCREEN_H-8, makecol(255, 255, 255), 0,
		 "%d bpp", bpp);

   while (!keypressed()) {
      timer = retrace_count;
      clear_bitmap(buffer);

      /* the first image moves in a slow circle while being tinted to 
       * different colors...
       */
      x1= 160+fixtoi(fixsin(itofix(timer)/16)*160);
      y1= 140-fixtoi(fixcos(itofix(timer)/16)*140);
      r = 127-fixtoi(fixcos(itofix(timer)/6)*127);
      g = 127-fixtoi(fixcos(itofix(timer)/7)*127);
      b = 127-fixtoi(fixcos(itofix(timer)/8)*127);
      a = 127-fixtoi(fixcos(itofix(timer)/9)*127);
      set_trans_blender(r, g, b, 0);
      draw_lit_sprite(buffer, image1, x1, y1, a);
      textprintf_ex(screen, font, 0, 0, makecol(r, g, b), 0, "light: %d ", a);

      /* the second image moves in a faster circle while the alpha value
       * fades in and out...
       */
      x2= 160+fixtoi(fixsin(itofix(timer)/10)*160);
      y2= 140-fixtoi(fixcos(itofix(timer)/10)*140);
      a = 127-fixtoi(fixcos(itofix(timer)/4)*127);
      set_trans_blender(0, 0, 0, a);
      draw_trans_sprite(buffer, image2, x2, y2);
      textprintf_ex(screen, font, 0, 8, makecol(a, a, a), 0, "alpha: %d ", a);

      /* copy the double buffer across to the screen */
      vsync();

      x = MIN(x1, prevx1);
      y = MIN(y1, prevy1);
      w = MAX(x1, prevx1) + 320 - x;
      h = MAX(y1, prevy1) + 200 - y;
      blit(buffer, screen, x, y, x, y, w, h);

      x = MIN(x2, prevx2);
      y = MIN(y2, prevy2);
      w = MAX(x2, prevx2) + 320 - x;
      h = MAX(y2, prevy2) + 200 - y;
      blit(buffer, screen, x, y, x, y, w, h);

      prevx1 = x1;
      prevy1 = y1;
      prevx2 = x2;
      prevy2 = y2;
   }

   clear_keybuf();

   destroy_bitmap(image1);
   destroy_bitmap(image2);
   destroy_bitmap(buffer);

   return 0;
}
Exemple #17
0
void initialize()
{
    char buf[1024];
    int i;

    // Do the libxml binary compatibility check
    initXML();

    // Initialise Allegro
    allegro_init();
    install_keyboard();
    install_mouse();
    install_timer();

    set_config_file("rpgedit.cfg");
    int grph_drv = (get_config_int("video", "fullscreen", 1)) ?
        GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED;
    int screen_w = get_config_int("video", "width", 800);
    int screen_h = get_config_int("video", "height", 600);

    if (get_config_int("tile_zoom", "grid", 1)) {
        showTileGrid = true;
    }

    set_color_conversion(
            (COLORCONV_TOTAL &
             ~(
                 COLORCONV_32A_TO_8  |
                 COLORCONV_32A_TO_15 |
                 COLORCONV_32A_TO_16 |
                 COLORCONV_32A_TO_24
              ))
            );

    int colordepth = 0;
    if (grph_drv == GFX_AUTODETECT_WINDOWED) {
        colordepth = desktop_color_depth();
    }
    if (colordepth == 0) {
        colordepth = 16;
    }
    set_color_depth(colordepth);

    if (set_gfx_mode(grph_drv, screen_w, screen_h, 0, 0) != 0) {
        set_color_depth(15);
        if (set_gfx_mode(grph_drv, screen_w, screen_h, 0, 0) != 0) {
            set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
            allegro_message("Unable to set graphic mode\n%s\n", allegro_error);
            exit(1);
        }
    }

    buffer = create_bitmap(SCREEN_W, SCREEN_H);


    // Initialize GUI look and feel stuff
    agup_init(aphoton_theme);
    gui_fg_color = agup_fg_color;
    gui_bg_color = agup_bg_color;
    gui_shadow_box_proc = d_agup_shadow_box_proc;
    gui_button_proc = d_agup_button_proc;
    gui_edit_proc = d_agup_edit_proc;
    gui_text_list_proc = d_agup_text_list_proc;

    engine_data = load_datafile("gui.dat");

    DATAFILE* font_data = find_datafile_object(engine_data, "SmallFont");
    if (font_data) font = (FONT*)font_data->dat;

    engine_font = font;

    DATAFILE* mouse_pointer = find_datafile_object(engine_data, "_MS_STD_BMP");
    if (mouse_pointer) set_mouse_sprite((BITMAP*)mouse_pointer->dat);

    DATAFILE* logo = find_datafile_object(engine_data, "MoonlightLogo");
    if (logo) about_dlg[1].dp = (BITMAP*)logo->dat;
    else console.log(CON_QUIT, CON_ALWAYS, "Error loading MoonlightLogo");

    console.log(CON_LOG, CON_ALWAYS, "Loading module \"data\"...");
    module = new Module("data");

    // Lua initialisation
    console.log(CON_LOG, CON_ALWAYS, "Initialising scripting environment...");
    initScripting();

    D_AUTOTEXT_STATUS.dp2 = status_message;
    D_AUTOTEXT_MAPINFO.dp2 = status_mapinfo;

    set_dialog_color(main_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(newmap_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(import_tileset_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(export_tileset_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(resizemap_dlg, agup_fg_color, agup_bg_color);
    set_dialog_color(about_dlg, agup_fg_color, agup_bg_color);


    // Position the dialogs on the screen
    int margin = 6;
    int zoom_w = get_config_int("tile_zoom", "zoom_width", 120) - 1;
    int zoom_h = get_config_int("tile_zoom", "zoom_height", 120) - 1;
    int x, y, w, h;

    // Main (back + menu)
    set_dialog_size(&main_dlg[0],          -2,                -2,              SCREEN_W + 4,          SCREEN_H + 4);
    set_dialog_size(&main_dlg[1],          0,                 0,               SCREEN_W,              15);

    // Status bars
    set_dialog_size(&main_dlg[6],          0,                 SCREEN_H - 17,   SCREEN_W - 256,        17);
    set_dialog_size(&main_dlg[7],          SCREEN_W - 256,    SCREEN_H - 17,   256,                   17);
    set_dialog_size(&main_dlg[8],          3,                 SCREEN_H - 14,   SCREEN_W - 262,        11);
    set_dialog_size(&main_dlg[9],          SCREEN_W - 253,    SCREEN_H - 14,   250,                   11);

    // Edit tile area
    w = zoom_w + 4;
    h = zoom_h + 4;
    x = margin;
    y = main_dlg[6].y - margin - h;
    set_dialog_size(&edit_tile_layer[0],   x,                 y,               w,                     h);
    set_dialog_size(&edit_tile_layer[1],   x + 2,             y + 2,           w - 4,                 h - 4);
    set_dialog_size(&edit_tile_layer[2],   x + margin + w,    y + h - 14,      50,                    14);

    // Color sliders
    x += w + margin;
    w = 128;
    set_dialog_size(&edit_tile_layer[8],   x,                 y,               16,                    8);
    set_dialog_size(&edit_tile_layer[9],   x,                 y + 16,          16,                    8);
    set_dialog_size(&edit_tile_layer[10],  x,                 y + 32,          16,                    8);
    set_dialog_size(&edit_tile_layer[11],  x,                 y + 48 + 8,      16,                    8);
    set_dialog_size(&edit_tile_layer[12],  x,                 y + 64 + 8,      16,                    8);
    set_dialog_size(&edit_tile_layer[3],   x + 16,            y,               w,                     8);
    set_dialog_size(&edit_tile_layer[4],   x + 16,            y + 16,          w,                     8);
    set_dialog_size(&edit_tile_layer[5],   x + 16,            y + 32,          w,                     8);
    set_dialog_size(&edit_tile_layer[6],   x + 16,            y + 48 + 8,      w,                     8);
    set_dialog_size(&edit_tile_layer[7],   x + 16,            y + 64 + 8,      w,                     8);
    set_dialog_size(&edit_tile_layer[13],  x + 16 + w + 4,    y - 1,           11,                    10);
    set_dialog_size(&edit_tile_layer[14],  x + 16 + w + 4,    y + 16 - 1,      11,                    10);
    set_dialog_size(&edit_tile_layer[15],  x + 16 + w + 4,    y + 32 - 1,      11,                    10);
    set_dialog_size(&edit_tile_layer[20],  x + 16 + w + 18,   y + 4,           18,                    32);

    // Select tile area
    x = edit_tile_layer[20].x + edit_tile_layer[20].w + margin;
    w = SCREEN_W - x - margin;
    set_dialog_size(&edit_tile_layer[16],  x,                 y,               104,                   h);
    set_dialog_size(&edit_tile_layer[17],  x + 104,           y,               w - 104,               h);
    set_dialog_size(&edit_tile_layer[18],  x + 104 + 2,       y + 2,           w - 104 - 4 - 11,      h - 4);
    set_dialog_size(&edit_tile_layer[19],  x + w - 14,        y,               14,                    h);

    // Obstacle edit stuff
    w = 24;
    h = 24;
    x = margin;
    y = main_dlg[6].y - margin - h;
    for (i = 0; i < 5; i++) {
        set_dialog_size(&edit_obstacle_layer[i],   x + i*(w+margin),     y,     w,     h);
        set_dialog_size(&edit_obstacle_layer[i+5], x + i*(w+margin) + 2, y + 2, w - 4, h - 4);
    }

    // Edit map area
    x = margin;
    y = 16 + margin;
    w = SCREEN_W - 2 * margin;
    h = edit_obstacle_layer[0].y - margin - y;
    set_dialog_size(&main_dlg[2],          x,                 y,               w,                     h);
    set_dialog_size(&main_dlg[3],          x + 2,             y + 2,           w - 15,                h - 15);
    set_dialog_size(&main_dlg[4],          x + w - 14,        y,               14,                    h - 11);
    set_dialog_size(&main_dlg[5],          x,                 y + h - 14,      w - 11,                14);
    set_dialog_size(&main_dlg[10],         x + w - 12,        y + h - 12,      10,                    10);

    // Edit objects area
    w = 160;
    h = 120;
    x = margin;
    y = main_dlg[6].y - margin - h;
    set_dialog_size(&edit_objects_layer[0], x,                y,               w,                     h);
    set_dialog_size(&edit_objects_layer[1], w + margin * 2, main_dlg[6].y - margin - 14,  97,                    14);


    // Initialize map and tile stuff
    tileRepository = new TileRepository();

    // Import tilesets specified in rpgedit.cfg
    i = 1;
    while (i > 0) 
    {
        uszprintf(buf, sizeof buf, "tileset%d", i);

        const char* filename = get_config_string(buf, "filename", NULL);
        int tile_w = get_config_int(buf, "tile_w", 16);
        int tile_h = get_config_int(buf, "tile_h", 16);
        int tile_spacing = get_config_int(buf, "tile_spacing", 0);

        if (filename) {
            if (tile_w > 0 && tile_h > 0 && tile_spacing >= 0) {
                import_tile_bitmap(filename, tile_w, tile_h, tile_spacing);
            } else {
                allegro_message("Error, incorrect parameters for automatic tile import (%s)!", filename);
                // Print warning in log file
            }
            i++;
        } else  {
            i = -1;
        }
    }

    currentMap = new SquareMap(TILES_W, TILES_H);
    ustrcpy(map_filename, "untitled.tmx");

    // Load map specified in rpgedit.cfg
    const char* filename = get_config_string("startup", "load_map", NULL);
    if (filename) {
        if (!currentMap->loadMap(filename)) {
            ustrcpy(map_filename, filename);
            object_message(&D_MAP, MSG_NEW_MAP, 0);
            set_map_changed(false);
        } else {
            console.log(CON_LOG, CON_ALWAYS,
                    "Error while loading default map (%s)!\n", filename);
        }
    }

    update_window_title();

    map_edit_mode = EM_TILE;
    menu_item_edit_objects();
    //activate_mode(edit_objects_layer);
}