max_load.cc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 "max_load.hh"
  9. #include "load3d.hh"
  10. #include "loaders/dir_load.hh"
  11. #include "tupdate.hh"
  12. #include "m1_info.hh"
  13. #include "saver_id.hh"
  14. #include "error/alert.hh"
  15. class m1_poly_object_loader_class : public g1_quad_object_loader_class
  16. {
  17. public:
  18. m1_poly_object_class *mobj() const { return (m1_poly_object_class*)obj; }
  19. virtual void set_num_animations(w16 anims)
  20. //{{{
  21. {
  22. mobj()->anim_store.add_many(anims);
  23. mobj()->animation_names.add_many(anims);
  24. mobj()->num_animations = mobj()->anim_store.size();
  25. mobj()->animation = &mobj()->anim_store[0];
  26. }
  27. //}}}
  28. virtual void create_animation(w16 anim, const i4_const_str &name, w16 frames)
  29. //{{{
  30. {
  31. mobj()->animation[anim].num_frames=frames;
  32. mobj()->animation[anim].vertex=mobj()->vert_store.add_many(frames*mobj()->num_vertex);
  33. mobj()->animation_names[anim]=new i4_str(name);
  34. }
  35. //}}}
  36. virtual void set_num_quads(w16 num_quads)
  37. //{{{
  38. {
  39. mobj()->quad_store.add_many(num_quads);
  40. mobj()->texture_names.add_many(num_quads);
  41. mobj()->num_quad = mobj()->quad_store.size();
  42. mobj()->quad = &mobj()->quad_store[0];
  43. }
  44. //}}}
  45. virtual void create_quad(w16 quad, int verts, w16 *ref, w32 flags)
  46. //{{{
  47. {
  48. g1_quad_object_loader_class::create_quad(quad,verts,ref,flags);
  49. for (int i=1; i<verts; i++)
  50. if (ref[i]==0xffff)
  51. ref[i] = ref[i-1];
  52. }
  53. //}}}
  54. virtual void store_texture_name(w32 quad, const i4_const_str &name)
  55. //{{{
  56. {
  57. char buf[512], *p=buf;
  58. i4_os_string(name, buf, sizeof(buf));
  59. while (*p) p++;
  60. --p;
  61. if (p>buf && *p!='.') --p;
  62. if (p>buf && *p!='.') --p;
  63. if (p>buf && *p!='.') --p;
  64. if (*p=='.')
  65. {
  66. ++p;
  67. while (*p)
  68. {
  69. if (*p>='A' && *p<='Z')
  70. *p = *p - 'A' + 'a';
  71. p++;
  72. }
  73. }
  74. g1_quad_object_loader_class::store_texture_name(quad, buf);
  75. mobj()->texture_names[quad]=new i4_str(buf);
  76. }
  77. //}}}
  78. virtual void set_num_mount_points(w16 num_mounts)
  79. //{{{
  80. {
  81. mobj()->mount_store.add_many(num_mounts);
  82. mobj()->mount_id_store.add_many(num_mounts);
  83. mobj()->mount_names.add_many(num_mounts);
  84. mobj()->num_mounts = mobj()->mount_store.size();
  85. if (mobj()->num_mounts>0)
  86. {
  87. mobj()->mount_id = &mobj()->mount_id_store[0];
  88. mobj()->mount = &mobj()->mount_store[0];
  89. }
  90. }
  91. //}}}
  92. virtual void create_mount_point(w32 index, const i4_const_str &name, const i4_3d_vector &off)
  93. //{{{
  94. {
  95. g1_quad_object_loader_class::create_mount_point(index, name, off);
  96. mobj()->mount_names[index]=new i4_str(name);
  97. }
  98. //}}}
  99. virtual void set_num_texture_animations(w16 num_textures)
  100. //{{{
  101. {
  102. mobj()->special_store.add_many(num_textures);
  103. mobj()->num_special = mobj()->special_store.size();
  104. if (mobj()->num_special>0)
  105. mobj()->special = &mobj()->special_store[0];
  106. }
  107. //}}}
  108. virtual g1_quad_object_class *allocate_object()
  109. //{{{
  110. {
  111. m1_poly_object_class *o = new m1_poly_object_class;
  112. if (o) o->init();
  113. return o;
  114. }
  115. //}}}
  116. m1_poly_object_class *load(i4_loader_class *fp, const i4_const_str &_error_name,
  117. r1_texture_manager_class *_tman)
  118. //{{{
  119. {
  120. error_name = &_error_name;
  121. tman = _tman;
  122. heap = 0;
  123. return (m1_poly_object_class *)g1_base_object_loader_class::load(fp);
  124. }
  125. //}}}
  126. };
  127. void m1_load_model_dir(const i4_const_str &object_filename,
  128. r1_texture_manager_class *tman)
  129. {
  130. tman->reset();
  131. m1_info.textures_loaded=i4_F;
  132. i4_array<i4_str *> tname_a(128,16);
  133. i4_file_class *fp=i4_open(object_filename);
  134. if (fp)
  135. {
  136. i4_loader_class *gfp=i4_open_save_file(fp);
  137. if (gfp)
  138. {
  139. if (gfp->goto_section(G1_SECTION_MODEL_TEXTURE_NAMES))
  140. {
  141. w16 quads=gfp->read_16();
  142. for (int i=0; i<quads; i++)
  143. {
  144. i4_str *s=gfp->read_counted_str();
  145. if (!s->null())
  146. tname_a.add(s);
  147. else
  148. delete s;
  149. }
  150. }
  151. delete gfp;
  152. }
  153. }
  154. else i4_alert(i4gets("obj_missing"),100,&object_filename);
  155. for (int i=0; i<tname_a.size(); i++)
  156. delete tname_a[i];
  157. }
  158. m1_poly_object_class *m1_load_model(const i4_const_str &name,
  159. r1_texture_manager_class *tman)
  160. //{{{
  161. {
  162. m1_info.recalcing_textures=i4_T;
  163. m1_update_object_textures(name);
  164. tman->reset();
  165. m1_info.textures_loaded=i4_F;
  166. m1_load_model_dir(name, tman);
  167. m1_info.recalcing_textures=i4_F;
  168. i4_file_class *fp=i4_open(name);
  169. if (fp)
  170. {
  171. i4_loader_class *gfp=i4_open_save_file(fp);
  172. if (gfp)
  173. {
  174. m1_poly_object_class *o;
  175. m1_poly_object_loader_class mo_loader;
  176. o = mo_loader.load(gfp, name, tman);
  177. delete gfp;
  178. return o;
  179. }
  180. }
  181. return 0;
  182. }
  183. //}}}
  184. //{{{ Emacs Locals
  185. // Local Variables:
  186. // folded-file: t
  187. // End:
  188. //}}}