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

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