source: golgotha/src/maxtool/max_load.cc @ 80

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