source: golgotha/src/maxtool/m1_info.cc

Last change on this file was 80, checked in by Sam Hocevar, 12 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: 3.8 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 "m1_info.hh"
10#include "lisp/li_types.hh"
11#include "file/file.hh"
12#include "make_tlist.hh"
13#include "gui/text_scroll.hh"
14#include "r1_api.hh"
15#include "tmanage.hh"
16#include "max_object.hh"
17#include "tupdate.hh"
18#include "st_edit.hh"
19#include "render.hh"
20
21m1_info_struct m1_info;
22extern i4_text_scroll_window_class *m1_warn_window;
23
24const i4_const_str m1_info_struct::current_filename()
25{
26  if (m1_info.models.size()==0)
27    return i4_const_str("");
28  else
29    return *m1_info.models[m1_info.current_model];
30}
31
32void m1_info_struct::set_current_filename(const i4_const_str &str)
33{
34  if (m1_info.models.size()==0)
35  {
36    m1_info.models.add();
37    m1_info.current_model=0;
38  }
39  else
40    delete m1_info.models[m1_info.current_model];
41
42  m1_info.models[m1_info.current_model]=new i4_str(str);
43}
44
45
46void m1_info_struct::get_texture_list(i4_array<i4_str *> &array, i4_bool for_all)
47{
48  int i;
49
50  if (for_all)
51  {
52    // add any textures from res files
53    if (res_files.size())
54    {
55      i4_file_class *fp[500];
56
57   
58      for (i=0; i<res_files.size(); i++)
59        fp[i]=i4_open(*res_files[i]);
60
61      int tmp_int;
62      i4_array<i4_str *> tmp_array(0,32);
63      g1_get_load_info(fp, res_files.size(), array, tmp_array, tmp_int, i4_T);
64     
65      for (i=0; i<tmp_array.size(); i++)
66        delete tmp_array[i];
67    }
68
69    for (i=0; i<textures.size(); i++)
70      array.add(new i4_str(*textures[i]));
71
72    for (i=0; i<models.size(); i++)
73      g1_make_texture_list_for_model(*models[i], array);
74  }
75  else
76    g1_make_texture_list_for_model(*models[current_model], array);
77}
78
79
80void m1_info_struct::init(int argc, i4_const_str *argv)
81{
82  for (int i=1; i<argc; i++)
83  {
84    if (argv[i]=="-update")
85      update_mode=1;
86    else
87    {
88      i4_filename_struct fn;
89      i4_split_path(argv[i],fn);
90
91      if (fn.extension)
92      {
93        if (strcmp(fn.extension,"scm")==0)
94          res_files.add(new i4_str(argv[i]));
95        else if (strcmp(fn.extension,"tga")==0)
96          textures.add(new i4_str(argv[i]));
97        else if (strcmp(fn.extension, "gmod")==0 || strcmp(fn.extension,"crk")==0)
98          models.add(new i4_str(argv[i]));
99      }
100    }
101  }
102}
103
104void m1_info_struct::uninit()
105{
106  int i;
107  for (i=0; i<res_files.size(); i++) delete res_files[i];
108  res_files.uninit();
109
110  for (i=0; i<textures.size(); i++) delete textures[i];
111  textures.uninit();
112
113  for (i=0; i<models.size(); i++) delete models[i];
114  models.uninit();
115}
116
117
118void m1_info_struct::texture_list_changed()
119{
120  if (update_mode)
121    return ;
122
123  r1_texture_manager_class *tman=r_api->get_tmanager();
124 
125  if (!obj)
126    return;
127
128  if (tman)
129  {
130    int i;
131    tman->reset();
132    textures_loaded=i4_F;
133
134    i4_status_class *stat=i4_create_status("Updating textures");
135
136    int nq=m1_info.obj->num_quad;
137    for (i=0; i<nq; i++)
138      m1_update_texture(*m1_info.obj->texture_names[i], i4_F, stat,
139                        i/(float)nq, (i+1)/(float)nq);
140
141    if (stat) delete stat;
142   
143
144    for (i=0; i<m1_info.obj->num_quad; i++)   
145      m1_info.obj->quad[i].material_ref=tman->register_texture(*m1_info.obj->texture_names[i],
146                                                               m1_info.current_filename());
147
148    m1_st_edit->edit_poly_changed();
149    m1_render_window->request_redraw(i4_F);
150  }
151}
Note: See TracBrowser for help on using the repository browser.