source: abuse/branches/pd/abuse/inc/cache.hpp @ 636

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