source: abuse/tags/pd/macabuse/inc/cache.hpp

Last change on this file was 49, checked in by Sam Hocevar, 15 years ago
  • Imported original public domain release, for future reference.
File size: 3.3 KB
Line 
1#ifndef __CASHE_HPP_
2#define __CASHE_HPP_
3
4#include <stdlib.h>
5#include "specs.hpp"
6#include "items.hpp"
7#include "sound.hpp"
8#include "lisp.hpp"
9
10class level;
11/* Cache item types :
12
13      foretile,backtile,character,
14      sound,
15      image,trans_image
16
17*/
18
19
20
21struct cache_item
22{
23  void *data;
24  long last_access;   
25  unsigned char type;
26  short file_number;
27  long offset;
28} ;
29
30
31
32class crced_file
33{
34  public :
35  int crc_calculated;
36  ulong crc;
37  char *filename;
38  crced_file(char *name);
39  ~crced_file();
40} ;
41
42class crc_manager  // stores crc for each file open so redundant calculations are not done
43{
44  int total_files;
45  crced_file **files;
46  public :
47  crc_manager();
48  int get_filenumber(char *filename);
49  ulong get_crc(long filenumber, int &failed);
50  void set_crc(long filenumber, ulong crc);
51  char *get_filename(long filenumber);
52  void clean_up();
53  int total_filenames() { return total_files; }
54  int write_crc_file(char *filename);
55  int load_crc_file(char *filename);
56} ;
57
58
59class memory_file;
60
61class cache_list
62{
63  cache_item *list;
64  long total,last_registered,last_access,poll_start_access;
65  short last_file;           // for speed leave the last file accessed open
66
67  bFILE *fp;
68  memory_file *cache_mfile;
69  spec_directory *last_dir;
70  long last_offset;          // store the last offset so we don't have to seek if
71                             // we don't need to
72 
73
74  short lcache_number;
75  long alloc_id();
76  void locate(cache_item *i, int local_only=0);    // set up file and offset for this item
77  void normalize();
78  void unmalloc(cache_item *i);
79  int used,                                 // flag set when disk is accessed
80      ful;                                  // set when stuff has to be thrown out
81  int *prof_data;                           // holds counts for each id
82  void preload_cache_object(int type);
83  void preload_cache(level *lev);
84public :
85  void create_lcache();
86  cache_list();
87  void free_oldest();
88  int in_use() { if (used) { used=0; return 1; } else return 0; }
89  int full() { if (ful) { ful=0; return 1; } else return 0; }
90  long reg_object(char *filename, void *object, int type, int rm_dups);      // lisp object
91  long reg(char *filename, char *name, int type=-1, int rm_dups=0);          // returns id to item
92  long reg_lisp_block(Cell *block);
93  int loaded(int id);
94  void unreg(int id);
95  void note_need(int id);
96
97  void           expire(int id);   // if loaded item will be freed now
98  backtile       *backt(int id);
99  foretile       *foret(int id);
100  figure          *fig(int id);
101  image           *img(int id);
102  sound_effect    *sfx(int id);
103  Cell         *lblock(int id);
104  char_tint     *ctint(int id);
105
106  void prof_init();
107  void prof_write(bFILE *fp);
108  void prof_uninit();
109  int  prof_size();                   // sizeof of spec entry that will be saved
110  void prof_poll_start();
111  void prof_poll_end();
112  int  prof_is_on() { return prof_data!=NULL; }   // so level knows weither to save prof info or not
113  int compare(int a, int b);          // compares the ussage counts of 2 entries (used by qsort)
114  int offset_compare(int a, int b);
115
116  void load_cache_prof_info(char *filename, level *lev);
117  int search(int *sarray, ushort filenum, long offset);  // sarray is a index table sorted by offset/filenum
118
119  void show_accessed();
120  void empty();
121  ~cache_list();
122} ;
123
124extern cache_list cash;
125extern crc_manager crc_man;
126
127
128#endif
129
130
131
132
133
134
Note: See TracBrowser for help on using the repository browser.