source: abuse/trunk/src/include/cache.hpp @ 18

Last change on this file since 18 was 17, checked in by Sam Hocevar, 17 years ago
  • absolute shitloads of 64 bit fixes.
File size: 3.3 KB
RevLine 
[2]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;
[17]25  int32_t last_access;   
26  uint8_t type;
27  int16_t file_number;
28  int32_t offset;
[2]29} ;
30
31
32
33class crced_file
34{
35  public :
36  int crc_calculated;
[17]37  uint32_t crc;
[2]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);
[17]50  uint32_t get_crc(int32_t filenumber, int &failed);
51  void set_crc(int32_t filenumber, uint32_t crc);
52  char *get_filename(int32_t filenumber);
[2]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;
[17]64  int32_t total,last_registered,last_access,poll_start_access;
65  int16_t last_file;           // for speed leave the last file accessed open
[2]66
67  bFILE *fp,*cache_file,*cache_read_file;
68  spec_directory *last_dir;
[17]69  int32_t last_offset;          // store the last offset so we don't have to seek if
[2]70                             // we don't need to
71 
72
[17]73  int16_t lcache_number;
74  int32_t alloc_id();
[2]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; }
[17]89  int32_t reg_object(char *filename, void *object, int type, int rm_dups);      // lisp object
90  int32_t reg(char *filename, char *name, int type=-1, int rm_dups=0);          // returns id to item
91  int32_t reg_lisp_block(Cell *block);
[2]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);
[17]116  int search(int *sarray, uint16_t filenum, int32_t offset);  // sarray is a index table sorted by offset/filenum
[2]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.