Ejemplo n.º 1
0
TbBool load_slab_datclm_files(void)
{
    struct Column *cols;
    long cols_tot;
    struct SlabSet *slbset;
    long slbset_tot;
    struct SlabSet *sset;
    long i;
    SYNCDBG(5,"Starting");
    // Load Column Set
    cols_tot = COLUMNS_COUNT;
    cols = (struct Column *)LbMemoryAlloc(cols_tot*sizeof(struct Column));
    if (cols == NULL)
    {
      WARNMSG("Can't allocate memory for %d column sets.",cols_tot);
      return false;
    }
    if (!load_slabclm_file(cols, &cols_tot))
    {
      LbMemoryFree(cols);
      return false;
    }
    // Load Slab Set
    slbset_tot = SLABSET_COUNT;
    slbset = (struct SlabSet *)LbMemoryAlloc(slbset_tot*sizeof(struct SlabSet));
    if (slbset == NULL)
    {
      WARNMSG("Can't allocate memory for %d slab sets.",slbset_tot);
      return false;
    }
    if (!load_slabdat_file(slbset, &slbset_tot))
    {
      LbMemoryFree(cols);
      LbMemoryFree(slbset);
      return false;
    }
    // Update the structure
    for (i=0; i < slbset_tot; i++)
    {
        sset = &game.slabset[i];
        LbMemoryCopy(sset, &slbset[i], sizeof(struct SlabSet));
    }
    game.slabset_num = slbset_tot;
    update_columns_use(cols,cols_tot,slbset,slbset_tot);
    LbMemoryFree(slbset);
    create_columns_from_list(cols,cols_tot);
    update_slabset_column_indices(cols,cols_tot);
    LbMemoryFree(cols);
    return true;
}
Ejemplo n.º 2
0
/**
 * Allocates graphics heap.
 */
TbBool setup_heap_memory(void)
{
  long i;
  SYNCDBG(8,"Starting");
  if (heap != NULL)
  {
    SYNCDBG(0,"Freeing old Graphics heap");
    LbMemoryFree(heap);
    heap = NULL;
  }
  i = mem_size;
  heap_size = get_best_sound_heap_size(i);
  while ( 1 )
  {
    heap = LbMemoryAlloc(heap_size);
    if (heap != NULL)
      break;
    i = get_smaller_memory_amount(i);
    if (i > 8)
    {
      heap_size = get_best_sound_heap_size(i);
    } else
    {
      if (heap_size < 524288)
      {
        ERRORLOG("Unable to allocate Graphic Heap");
        heap_size = 0;
        return false;
      }
      heap_size -= 16384;
    }
  }
  SYNCMSG("GraphicsHeap Size %d", heap_size);
  return true;
}
Ejemplo n.º 3
0
/**
 * Loads the language-specific strings data for the current campaign.
 */
TbBool setup_campaign_strings_data(struct GameCampaign *campgn)
{
  char *strings_data_end;
  char *fname;
  short result;
  long filelen;
  SYNCDBG(18,"Starting");
  fname = prepare_file_path(FGrp_Main,campgn->strings_fname);
  filelen = LbFileLengthRnc(fname);
  if (filelen <= 0)
  {
    ERRORLOG("Campaign Strings file does not exist or can't be opened");
    return false;
  }
  campgn->strings_data = (char *)LbMemoryAlloc(filelen + 256);
  if (campgn->strings_data == NULL)
  {
    ERRORLOG("Can't allocate memory for Campaign Strings data");
    return false;
  }
  strings_data_end = campgn->strings_data+filelen+255;
  long loaded_size;
  loaded_size = LbFileLoadAt(fname, campgn->strings_data);
  if (loaded_size < 16)
  {
    ERRORLOG("Campaign Strings file couldn't be loaded or is too small");
    return false;
  }
  // Resetting all values to empty strings
  reset_strings(campgn->strings);
  // Analyzing strings data and filling correct values
  result = create_strings_list(campgn->strings, campgn->strings_data, strings_data_end);
  SYNCDBG(19,"Finished");
  return result;
}
Ejemplo n.º 4
0
TbBool load_trapdoor_config_file(const char *textname, const char *fname, unsigned short flags)
{
    char *buf;
    long len;
    TbBool result;
    SYNCDBG(0,"%s %s file \"%s\".",((flags & CnfLd_ListOnly) == 0)?"Reading":"Parsing",textname,fname);
    len = LbFileLengthRnc(fname);
    if (len < MIN_CONFIG_FILE_SIZE)
    {
        if ((flags & CnfLd_IgnoreErrors) == 0)
            WARNMSG("The %s file \"%s\" doesn't exist or is too small.",textname,fname);
        return false;
    }
    if (len > MAX_CONFIG_FILE_SIZE)
    {
        if ((flags & CnfLd_IgnoreErrors) == 0)
            WARNMSG("The %s file \"%s\" is too large.",textname,fname);
        return false;
    }
    buf = (char *)LbMemoryAlloc(len+256);
    if (buf == NULL)
        return false;
    // Loading file data
    len = LbFileLoadAt(fname, buf);
    result = (len > 0);
    // Parse blocks of the config file
    if (result)
    {
        result = parse_trapdoor_common_blocks(buf, len, textname, flags);
        if ((flags & CnfLd_AcceptPartial) != 0)
            result = true;
        if (!result)
            WARNMSG("Parsing %s file \"%s\" common blocks failed.",textname,fname);
    }
    if (result)
    {
        result = parse_trapdoor_trap_blocks(buf, len, textname, flags);
        if ((flags & CnfLd_AcceptPartial) != 0)
            result = true;
        if (!result)
            WARNMSG("Parsing %s file \"%s\" trap blocks failed.",textname,fname);
    }
    if (result)
    {
        result = parse_trapdoor_door_blocks(buf, len, textname, flags);
        if ((flags & CnfLd_AcceptPartial) != 0)
            result = true;
        if (!result)
            WARNMSG("Parsing %s file \"%s\" door blocks failed.",textname,fname);
    }
    //Freeing and exiting
    LbMemoryFree(buf);
    SYNCDBG(19,"Done");
    return result;
}
Ejemplo n.º 5
0
/**
 * Loads map file with given level number and file extension.
 * @return Returns NULL if the file doesn't exist or is smaller than ldsize;
 * on success, returns a buffer which should be freed after use,
 * and sets ldsize into its size.
 */
unsigned char *load_single_map_file_to_buffer(LevelNumber lvnum,const char *fext,long *ldsize,unsigned short flags)
{
  unsigned char *buf;
  char *fname;
  long fsize;
  short fgroup;
  fgroup = get_level_fgroup(lvnum);
  fname = prepare_file_fmtpath(fgroup,"map%05lu.%s",lvnum,fext);
  wait_for_cd_to_be_available();
  fsize = LbFileLengthRnc(fname);
  if (fsize < *ldsize)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Map file \"map%05lu.%s\" doesn't exist or is too small.",lvnum,fext);
    else
      SYNCMSG("Optional file \"map%05lu.%s\" doesn't exist or is too small.",lvnum,fext);
    return NULL;
  }
  if (fsize > ANY_MAP_FILE_MAX_SIZE)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Map file \"map%05lu.%s\" exceeds max size of %d; loading failed.",lvnum,fext,ANY_MAP_FILE_MAX_SIZE);
    else
      SYNCMSG("Optional file \"map%05lu.%s\" exceeds max size of %d; not loading.",lvnum,fext,ANY_MAP_FILE_MAX_SIZE);
    return NULL;
  }
  buf = LbMemoryAlloc(fsize+16);
  if (buf == NULL)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Can't allocate %ld bytes to load \"map%05lu.%s\".",fsize,lvnum,fext);
    else
      SYNCMSG("Can't allocate %ld bytes to load \"map%05lu.%s\".",fsize,lvnum,fext);
    return NULL;
  }
  fsize = LbFileLoadAt(fname,buf);
  if (fsize < *ldsize)
  {
    if ((flags & LMFF_Optional) == 0)
      WARNMSG("Reading map file \"map%05lu.%s\" failed.",lvnum,fext);
    else
      SYNCMSG("Reading optional file \"map%05lu.%s\" failed.",lvnum,fext);
    LbMemoryFree(buf);
    return NULL;
  }
  *ldsize = fsize;
  SYNCDBG(7,"Map file \"map%05lu.%s\" loaded.",lvnum,fext);
  return buf;
}
Ejemplo n.º 6
0
/**
 * Searches levels folder for LOF files and adds them to campaign levels list.
 */
TbBool find_and_load_lof_files(void)
{
    struct TbFileFind fileinfo;
    unsigned char *buf;
    char *fname;
    short result;
    int rc;
    long i;
    SYNCDBG(16,"Starting");
    buf = LbMemoryAlloc(MAX_LIF_SIZE);
    if (buf == NULL)
    {
      ERRORLOG("Can't allocate memory for .LOF files parsing.");
      return false;
    }
    result = false;
    fname = prepare_file_path(FGrp_VarLevels,"*.lof");
    rc = LbFileFindFirst(fname, &fileinfo, 0x21u);
    while (rc != -1)
    {
        fname = prepare_file_path(FGrp_VarLevels,fileinfo.Filename);
        i = LbFileLength(fname);
        if ((i < 0) || (i >= MAX_LIF_SIZE))
        {
          WARNMSG("File '%s' too long (Max size %d)", fileinfo.Filename, MAX_LIF_SIZE);

        } else
        if (LbFileLoadAt(fname, buf) != i)
        {
          WARNMSG("Unable to read .LOF file, '%s'", fileinfo.Filename);
        } else
        {
          buf[i] = '\0';
          if (level_lof_file_parse(fileinfo.Filename, (char *)buf, i))
            result = true;
        }
        rc = LbFileFindNext(&fileinfo);
    }
    LbFileFindEnd(&fileinfo);
    LbMemoryFree(buf);
    return result;
}
Ejemplo n.º 7
0
/**
 * Loads the language-specific strings data for game interface.
 */
TbBool setup_gui_strings_data(void)
{
  char *strings_data_end;
  char *fname;
  short result;
  long filelen;
  long loaded_size;
  SYNCDBG(8,"Starting");

  fname = prepare_file_fmtpath(FGrp_FxData,"gtext_%s.dat",get_language_lwrstr(install_info.lang_id));
  filelen = LbFileLengthRnc(fname);
  if (filelen <= 0)
  {
    ERRORLOG("GUI Strings file does not exist or can't be opened");
    SYNCLOG("Strings file name is \"%s\"",fname);
    return false;
  }
  gui_strings_data = (char *)LbMemoryAlloc(filelen + 256);
  if (gui_strings_data == NULL)
  {
    ERRORLOG("Can't allocate memory for GUI Strings data");
    SYNCLOG("Strings file name is \"%s\"",fname);
    return false;
  }
  strings_data_end = gui_strings_data+filelen+255;
  loaded_size = LbFileLoadAt(fname, gui_strings_data);
  if (loaded_size < 16)
  {
    ERRORLOG("GUI Strings file couldn't be loaded or is too small");
    return false;
  }
  // Resetting all values to empty strings
  reset_strings(gui_strings);
  // Analyzing strings data and filling correct values
  result = create_strings_list(gui_strings, gui_strings_data, strings_data_end);
  // Updating strings inside the DLL
  LbMemoryCopy(_DK_strings, gui_strings, DK_STRINGS_MAX*sizeof(char *));
  SYNCDBG(19,"Finished");
  return result;
}
Ejemplo n.º 8
0
TbBool cumulative_screen_shot(void)
{
    //_DK_cumulative_screen_shot();return;
    static long frame_number=0;
    char fname[255];
    const char *fext;
    int w,h;
    switch (screenshot_format)
    {
    case 1:
        fext="raw";
        break;
    case 2:
        fext="bmp";
        break;
    default:
        ERRORLOG("Screenshot format incorrectly set.");
        return false;
    }
    long i;
    unsigned char *buf;
    long ssize;
    for (i=frame_number; i<10000; i++)
    {
        sprintf(fname, "scrshots/scr%05ld.%s", i, fext);
        if (!LbFileExists(fname)) break;
    }
    frame_number = i;
    if (frame_number >= 10000)
    {
        show_onscreen_msg(game.num_fps, "No free filename for screenshot.");
        return false;
    }
    sprintf(fname, "scrshots/scr%05ld.%s", frame_number, fext);

    w=MyScreenWidth/pixel_size;
    h=MyScreenHeight/pixel_size;

    buf = LbMemoryAlloc((w+3)*h+2048);
    if (buf == NULL)
    {
        ERRORLOG("Can't allocate buffer");
        return false;
    }
    LbPaletteGet(cap_palette);
    switch (screenshot_format)
    {
    case 1:
        ssize=prepare_hsi_screenshot(buf,cap_palette);
        break;
    case 2:
        ssize=prepare_bmp_screenshot(buf,cap_palette);
        break;
    default:
        ssize=0;
        break;
    }
    if (ssize>0)
        ssize = LbFileSaveAt(fname, buf, ssize);
    LbMemoryFree(buf);
    if (ssize>0)
        show_onscreen_msg(game.num_fps, "File \"%s\" saved.", fname);
    else
        show_onscreen_msg(game.num_fps, "Cannot save \"%s\".", fname);
    frame_number++;
    return (ssize>0);
}
Ejemplo n.º 9
0
TbBool setup_heaps(void)
{
    TbBool low_memory;
    char snd_fname[2048];
    char *spc_fname;
    long i;
    SYNCDBG(8,"Starting");
    low_memory = false;
    if (!SoundDisabled)
    {
      StopAllSamples();
      close_sound_heap();
      if (sound_heap_memory != NULL)
      {
        LbMemoryFree(sound_heap_memory);
        sound_heap_memory = NULL;
      }
    }
    if (heap != NULL)
    {
      ERRORLOG("Graphics heap already allocated");
      LbMemoryFree(heap);
      heap = NULL;
    }
    // Allocate sound heap
    if (!SoundDisabled)
    {
      i = mem_size;
      while (sound_heap_memory == NULL)
      {
        sound_heap_size = get_best_sound_heap_size(i);
        i = get_smaller_memory_amount(i);
        sound_heap_memory = LbMemoryAlloc(sound_heap_size);
        if ((i <= 8) && (sound_heap_memory == NULL))
        {
          low_memory = true;
          break;
        }
      }
    }
    // Allocate graphics heap
    i = mem_size;
    while (heap == NULL)
    {
      heap_size = get_best_sound_heap_size(i);
      i = get_smaller_memory_amount(i);
      heap = LbMemoryAlloc(heap_size);
      if ((i <= 8) && (heap == NULL))
      {
        low_memory = true;
        break;
      }
    }
    SYNCMSG("GraphicsHeap Size %d", heap_size);

    if (low_memory)
    {
      SYNCDBG(8,"Low memory mode entered on heap allocation.");
      while (heap != NULL)
      {
        if ((!SoundDisabled) && (sound_heap_memory == NULL))
        {
          break;
        }
        if (!SoundDisabled)
        {
          if (sound_heap_size < heap_size)
          {
            heap_size -= 16384;
          } else
          if (sound_heap_size == heap_size)
          {
            heap_size -= 16384;
            sound_heap_size -= 16384;
          } else
          {
            sound_heap_size -= 16384;
          }
          if (sound_heap_size < 524288)
          {
            ERRORLOG("Unable to allocate heaps (small_mem)");
            return false;
          }
        } else
        {
          heap_size -= 16384;
        }
        if (heap_size < 524288)
        {
          if (sound_heap_memory != NULL)
          {
            LbMemoryFree(sound_heap_memory);
            sound_heap_memory = NULL;
          }
          ERRORLOG("Unable to allocate heaps (small_mem)");
          return false;
          }
        }
        if (sound_heap_memory != NULL)
        {
          LbMemoryFree(sound_heap_memory);
          sound_heap_memory = NULL;
        }
        if (heap != NULL)
        {
          LbMemoryFree(heap);
          heap = NULL;
        }
        if (!SoundDisabled)
        {
          sound_heap_memory = LbMemoryAlloc(sound_heap_size);
        }
        heap = LbMemoryAlloc(heap_size);
    }
    if (!SoundDisabled)
    {
      SYNCMSG("SoundHeap Size %d", sound_heap_size);
      // Prepare sound sample bank file names
      prepare_file_path_buf(snd_fname,FGrp_LrgSound,sound_fname);
      // language-specific speech file
      spc_fname = prepare_file_fmtpath(FGrp_LrgSound,"speech_%s.dat",get_language_lwrstr(install_info.lang_id));
      // default speech file
      if (!LbFileExists(spc_fname))
        spc_fname = prepare_file_path(FGrp_LrgSound,speech_fname);
      // speech file for english
      if (!LbFileExists(spc_fname))
        spc_fname = prepare_file_fmtpath(FGrp_LrgSound,"speech_%s.dat",get_language_lwrstr(1));
      // Initialize sample banks
      if (!init_sound_heap_two_banks(sound_heap_memory, sound_heap_size, snd_fname, spc_fname, 1622))
      {
        LbMemoryFree(sound_heap_memory);
        sound_heap_memory = NULL;
        SoundDisabled = true;
        ERRORLOG("Unable to initialize sound heap. Sound disabled.");
      }
    }
    return true;
}
Ejemplo n.º 10
0
/**
 * Loads binary config of cubes.
 * @deprecated Replaced by text config - remove pending.
 */
long load_cube_file(void)
{
    char *buf;
    long len;
    TbBool result;
    char *fname;
    static const char textname[] = "binary cubes config";
    fname = prepare_file_path(FGrp_StdData,"cube.dat");
    SYNCDBG(0,"%s %s file \"%s\".","Reading",textname,fname);
    //return _DK_load_cube_file();
    clear_cubes();
    len = LbFileLengthRnc(fname);
    if (len < MIN_CONFIG_FILE_SIZE)
    {
        WARNMSG("The %s file \"%s\" doesn't exist or is too small.",textname,fname);
        return false;
    }
    if (len > MAX_CONFIG_FILE_SIZE)
    {
        WARNMSG("The %s file \"%s\" is too large.",textname,fname);
        return false;
    }
    buf = (char *)LbMemoryAlloc(len+256);
    if (buf == NULL)
        return false;
    // Loading file data
    len = LbFileLoadAt(fname, buf);
    result = (len > 0);
    // Parse the config file
    if (result)
    {
        long i,count;
        count = *(long *)&buf[0];
        if (count > len/sizeof(struct CubeAttribs)) {
            count = len/sizeof(struct CubeAttribs);
            WARNMSG("The %s file \"%s\" seem truncated.",textname,fname);
        }
        if (count > CUBE_ITEMS_MAX-1)
            count = CUBE_ITEMS_MAX-1;
        if (count < 0)
            count = 0;
        struct CubeAttribs * cubuf;
        cubuf = (struct CubeAttribs *)&buf[4];
        for (i=0; i < count; i++)
        {
            struct CubeAttribs * cubed;
            cubed = &game.cubes_data[i];
            int n;
            for (n=0; n < CUBE_TEXTURES; n++) {
                cubed->texture_id[n] = cubuf->texture_id[n];
            }
            for (n=0; n < CUBE_TEXTURES; n++) {
                cubed->field_C[n] = cubuf->field_C[n];
            }
            cubuf++;
        }
        result = true;
    }
    //Freeing and exiting
    LbMemoryFree(buf);
    return result;
}