level_load.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "lisp/lisp.hh"
  9. #include "file/file.hh"
  10. #include "memory/array.hh"
  11. #include "tile.hh"
  12. #include "load3d.hh"
  13. #include "g1_render.hh"
  14. #include "r1_api.hh"
  15. #include "tmanage.hh"
  16. #include "map_man.hh"
  17. #include "map.hh"
  18. #include "cwin_man.hh"
  19. #include "make_tlist.hh"
  20. #include "saver.hh"
  21. #include "border_frame.hh"
  22. #include "file/sub_section.hh"
  23. #include <stdlib.h>
  24. li_object *g1_add_textures(li_object *o, li_environment *env)
  25. {
  26. for (o=li_cdr(o,0); o; o=li_cdr(o,0))
  27. g1_tile_man.add(li_car(o,0), env);
  28. return 0;
  29. }
  30. static li_object *g1_ignore(li_object *o, li_environment *env) { return 0;}
  31. i4_str *g1_get_res_filnename(const i4_const_str &map_filename)
  32. {
  33. i4_filename_struct fn;
  34. i4_split_path(map_filename, fn);
  35. char res_name[256];
  36. int len=strlen(fn.filename);
  37. while (len && (fn.filename[len-1]>='0' && fn.filename[len-1]<='9'))
  38. len--;
  39. res_name[len]=0;
  40. if (fn.path[0])
  41. sprintf(res_name, "%s/%s.scm", fn.path, fn.filename);
  42. else
  43. sprintf(res_name, "%s.scm", fn.filename);
  44. return new i4_str(res_name);
  45. }
  46. void g1_load_res_info(i4_file_class *fp)
  47. {
  48. li_environment *local_env=new li_environment(0,i4_T);
  49. i4_array<i4_str *> tlist(512,512), mlist(512,512);
  50. li_list *scheme_list;
  51. int t_tiles;
  52. r1_texture_manager_class *tman=g1_render.r_api->get_tmanager();
  53. tman->reset();
  54. i4_file_class *fp_list[1];
  55. fp_list[0]=fp;
  56. // get a list of models and textures we need to load for this level
  57. g1_get_load_info(fp_list,1, tlist, mlist, t_tiles, 0);
  58. if (g1_strategy_screen.get())
  59. g1_strategy_screen->create_build_buttons();
  60. g1_tile_man.reset(t_tiles);
  61. g1_model_list_man.reset( mlist, tman);
  62. int i;
  63. for (i=0; i<tlist.size(); i++)
  64. delete tlist[i];
  65. for (i=0; i<mlist.size(); i++)
  66. delete mlist[i];
  67. li_add_function("models", g1_ignore, local_env);
  68. li_add_function("textures", g1_add_textures, local_env);
  69. li_load("scheme/models.scm", local_env);
  70. fp->seek(0);
  71. li_load(fp, local_env);
  72. g1_tile_man.finished_load();
  73. tman->load_textures();
  74. g1_render.install_font();
  75. tman->keep_resident("lod_vehicles1", 256);
  76. }
  77. i4_bool g1_load_level(const i4_const_str &filename, int reload_textures_and_models,
  78. w32 exclude_flags)
  79. {
  80. int i;
  81. i4_file_class *fp=i4_open(filename);
  82. if (!fp)
  83. return 0;
  84. g1_loader_class *load=g1_open_save_file(fp);
  85. if (!load)
  86. return 0;
  87. if (reload_textures_and_models)
  88. {
  89. if (g1_map_is_loaded())
  90. g1_destroy_map();
  91. w32 off,size;
  92. i4_file_class *res_file=0;
  93. if (load->get_section_info("resources", off, size))
  94. res_file=new i4_sub_section_file(i4_open(filename),off,size);
  95. if (!res_file)
  96. {
  97. i4_str *res_name=g1_get_res_filnename(filename);
  98. res_file=i4_open(*res_name);
  99. delete res_name;
  100. }
  101. if (res_file)
  102. {
  103. g1_load_res_info(res_file);
  104. delete res_file;
  105. }
  106. }
  107. g1_initialize_loaded_objects();
  108. g1_map_class *map;
  109. if (g1_map_is_loaded())
  110. map=g1_get_map();
  111. else
  112. map=new g1_map_class(filename);
  113. w32 ret=map->load(load, G1_MAP_ALL & (~exclude_flags));
  114. delete load;
  115. if ((ret & (G1_MAP_CELLS | G1_MAP_VERTS))==0)
  116. {
  117. delete map;
  118. return i4_F;
  119. }
  120. g1_set_map(map);
  121. //(OLI) hack for jc to only calculate LOD textures once
  122. if (reload_textures_and_models)
  123. map->init_lod();
  124. g1_cwin_man->map_changed();
  125. return i4_T;
  126. }