Beispiel #1
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;
}
Beispiel #2
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;
}