source: golgotha/src/golg/level_load.cc @ 80

Last change on this file since 80 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.9 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 "lisp/lisp.hh"
10#include "file/file.hh"
11#include "memory/array.hh"
12#include "tile.hh"
13#include "load3d.hh"
14#include "g1_render.hh"
15#include "r1_api.hh"
16#include "tmanage.hh"
17#include "map_man.hh"
18#include "map.hh"
19#include "cwin_man.hh"
20#include "make_tlist.hh"
21#include "saver.hh"
22#include "border_frame.hh"
23#include "file/sub_section.hh"
24#include <stdlib.h>
25
26li_object *g1_add_textures(li_object *o, li_environment *env)
27{
28  for (o=li_cdr(o,0); o; o=li_cdr(o,0))
29    g1_tile_man.add(li_car(o,0), env);
30
31  return 0;
32}
33
34
35static li_object *g1_ignore(li_object *o, li_environment *env) {  return 0;}
36
37i4_str *g1_get_res_filnename(const i4_const_str &map_filename)
38{
39  i4_filename_struct fn;
40  i4_split_path(map_filename, fn);
41
42  char res_name[256];
43
44  int len=strlen(fn.filename);
45  while (len && (fn.filename[len-1]>='0' && fn.filename[len-1]<='9'))
46    len--;
47  res_name[len]=0;
48
49  if (fn.path[0])
50    sprintf(res_name, "%s/%s.scm", fn.path, fn.filename);
51  else
52    sprintf(res_name, "%s.scm", fn.filename);
53
54  return new i4_str(res_name);
55}
56
57void g1_load_res_info(i4_file_class *fp)
58{
59  li_environment *local_env=new li_environment(0,i4_T);
60
61  i4_array<i4_str *> tlist(512,512), mlist(512,512);
62
63  li_list *scheme_list;
64  int t_tiles;
65
66  r1_texture_manager_class *tman=g1_render.r_api->get_tmanager();
67  tman->reset();
68
69  i4_file_class *fp_list[1];
70  fp_list[0]=fp;
71
72  // get a list of models and textures we need to load for this level
73  g1_get_load_info(fp_list,1,  tlist,  mlist, t_tiles, 0);
74
75  if (g1_strategy_screen.get())
76    g1_strategy_screen->create_build_buttons();
77
78  g1_tile_man.reset(t_tiles);
79
80  g1_model_list_man.reset( mlist, tman);
81
82  int i;
83  for (i=0; i<tlist.size(); i++)
84    delete   tlist[i];
85
86  for (i=0; i<mlist.size(); i++)
87    delete mlist[i];
88
89  li_add_function("models", g1_ignore, local_env);
90  li_add_function("textures", g1_add_textures, local_env);
91
92  li_load("scheme/models.scm", local_env);
93  fp->seek(0);
94  li_load(fp, local_env);
95
96
97  g1_tile_man.finished_load();
98  tman->load_textures();
99  g1_render.install_font();
100
101  tman->keep_resident("lod_vehicles1", 256);
102}
103
104i4_bool g1_load_level(const i4_const_str &filename, int reload_textures_and_models,
105                      w32 exclude_flags)
106{
107  int i;
108  i4_file_class *fp=i4_open(filename);
109
110  if (!fp)
111    return 0;
112
113  g1_loader_class *load=g1_open_save_file(fp);
114  if (!load)
115    return 0;
116
117  if (reload_textures_and_models)
118  {
119    if (g1_map_is_loaded())
120      g1_destroy_map();
121
122    w32 off,size;
123    i4_file_class *res_file=0;
124    if (load->get_section_info("resources", off, size))
125      res_file=new i4_sub_section_file(i4_open(filename),off,size);
126
127    if (!res_file)
128    {
129      i4_str *res_name=g1_get_res_filnename(filename);
130      res_file=i4_open(*res_name);
131      delete res_name;
132    }
133
134    if (res_file)
135    {
136      g1_load_res_info(res_file);
137      delete res_file;
138    }
139  }
140   
141  g1_initialize_loaded_objects();
142
143  g1_map_class *map;
144  if (g1_map_is_loaded())
145    map=g1_get_map();
146  else
147    map=new g1_map_class(filename);
148
149
150  w32 ret=map->load(load, G1_MAP_ALL & (~exclude_flags));
151  delete load;
152
153  if ((ret & (G1_MAP_CELLS | G1_MAP_VERTS))==0)
154  {
155    delete map;
156    return i4_F;
157  }
158
159  g1_set_map(map);
160
161  //(OLI) hack for jc to only calculate LOD textures once
162  if (reload_textures_and_models)
163    map->init_lod();
164
165  g1_cwin_man->map_changed();
166
167  return i4_T;
168}
169
170
171
172
Note: See TracBrowser for help on using the repository browser.