source: abuse/trunk/src/cache.hpp @ 57

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