source: golgotha/src/render/r1_res.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: 2.5 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 <stdio.h>
10#include "r1_res.hh"
11#include "string/string.hh"
12#include "file/file.hh"
13#include "app/registry.hh"
14
15int r1_max_texture_size=256;
16
17static char compressed[60], decompressed[60], cache_file[80];
18static i4_const_str comp(""), decomp(""), cache("");
19
20
21static void get(char *var, char *buffer, int max_buffer, char *def)
22{
23  if (i4_get_registry(I4_REGISTRY_USER,
24                      "SOFTWARE\\Crack dot Com\\render\\1.0",
25                      var, buffer, max_buffer))
26    return ;
27 
28  char *c=getenv(var);
29  if (c)
30  {
31    strncpy(buffer, c, max_buffer);
32    return ;
33  }
34 
35  strcpy(buffer, def);
36
37}
38
39class r1_resource_manager_class : public i4_init_class
40{
41public:
42  i4_string_manager_class r1_strings;
43
44
45
46  void init()
47  {
48    get("G_DECOMPRESSED", decompressed, 60, "g_decompressed");
49    get("G_COMPRESSED", compressed, 60, "g_compressed");
50
51    i4_mkdir(compressed);
52    i4_mkdir(decompressed);
53
54    sprintf(cache_file, "%s/tex_cache.dat", decompressed);
55
56    comp=compressed;
57    decomp=decompressed;
58    cache=cache_file;
59   
60    r1_strings.load("render.res");
61
62    i4_const_str::iterator tmax=r1_gets("max_texture_size").begin();
63    r1_max_texture_size = tmax.read_number();
64   
65    char max_size[40];
66    get("MAX_TEXTURE_SIZE", max_size, 40, "256");
67
68    sscanf(max_size, "%d", &r1_max_texture_size);
69    if (r1_max_texture_size<16) r1_max_texture_size=16;
70
71//    i4_warning("Setting max texture size to %d", r1_max_texture_size); 
72  }
73
74} r1_resource_man;
75
76
77const i4_const_str &r1_gets(char *str, i4_bool barf_on_error)
78{
79  const i4_const_str *s=&r1_resource_man.r1_strings.get(str);
80
81  if (barf_on_error && s->null())
82    i4_error("Render (render.res) resource missing %s", str);
83
84  return *s;
85}
86
87
88const i4_const_str &r1_get_decompressed_dir()
89{
90  return decomp;
91}
92
93
94const i4_const_str &r1_get_compressed_dir()
95{
96  return comp;
97}
98
99
100const i4_const_str &r1_get_cache_file()
101{
102  return cache;
103}
104
Note: See TracBrowser for help on using the repository browser.