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