|
3 | 3 |
|
4 | 4 | #include ".\soundrender_cache.h" |
5 | 5 |
|
6 | | -CSoundRender_Cache::CSoundRender_Cache () |
| 6 | +CSoundRender_Cache::CSoundRender_Cache () |
7 | 7 | { |
8 | | - data = NULL; |
9 | | - c_storage = NULL; |
10 | | - c_begin = NULL; |
11 | | - c_end = NULL; |
12 | | - _total = 0; |
13 | | - _line = 0; |
14 | | - _count = 0; |
| 8 | + data = NULL; |
| 9 | + c_storage = NULL; |
| 10 | + c_begin = NULL; |
| 11 | + c_end = NULL; |
| 12 | + _total = 0; |
| 13 | + _line = 0; |
| 14 | + _count = 0; |
15 | 15 | } |
16 | 16 |
|
17 | | -CSoundRender_Cache::~CSoundRender_Cache () |
| 17 | +CSoundRender_Cache::~CSoundRender_Cache () |
18 | 18 | { |
19 | 19 | } |
20 | 20 |
|
21 | 21 |
|
22 | | -void CSoundRender_Cache::move2top (cache_line* line) |
| 22 | +void CSoundRender_Cache::move2top (cache_line* line) |
23 | 23 | { |
24 | | - VERIFY (line); |
25 | | - if (line==c_begin) return; // already at top |
| 24 | + VERIFY (line); |
| 25 | + if (line==c_begin) return; // already at top |
26 | 26 |
|
27 | | - // track end |
28 | | - if (line==c_end) c_end = c_end->prev; |
| 27 | + // track end |
| 28 | + if (line==c_end) c_end = c_end->prev; |
29 | 29 |
|
30 | | - // cut |
31 | | - cache_line* prev = line->prev; |
32 | | - cache_line* next = line->next; |
33 | | - if (prev) prev->next = next; |
34 | | - if (next) next->prev = prev; |
| 30 | + // cut |
| 31 | + cache_line* prev = line->prev; |
| 32 | + cache_line* next = line->next; |
| 33 | + if (prev) prev->next = next; |
| 34 | + if (next) next->prev = prev; |
35 | 35 |
|
36 | | - // register at top |
37 | | - line->prev = NULL; |
38 | | - line->next = c_begin; |
| 36 | + // register at top |
| 37 | + line->prev = NULL; |
| 38 | + line->next = c_begin; |
39 | 39 |
|
40 | | - // track begin |
41 | | - c_begin->prev = line; |
42 | | - c_begin = line; |
| 40 | + // track begin |
| 41 | + c_begin->prev = line; |
| 42 | + c_begin = line; |
43 | 43 |
|
44 | | - // internal verify |
45 | | - VERIFY (c_begin->prev == NULL); |
46 | | - VERIFY (c_end->next == NULL); |
| 44 | + // internal verify |
| 45 | + VERIFY (c_begin->prev == NULL); |
| 46 | + VERIFY (c_end->next == NULL); |
47 | 47 | } |
48 | 48 |
|
49 | | -BOOL CSoundRender_Cache::request (cache_cat& cat, u32 id) |
| 49 | +BOOL CSoundRender_Cache::request (cache_cat& cat, u32 id) |
50 | 50 | { |
51 | | - // 1. check if cached version available |
52 | | - id %= cat.size; |
53 | | -//. R_ASSERT (id<cat.size); |
54 | | - u16& cptr = cat.table[id]; |
55 | | - if (CAT_FREE != cptr) { |
56 | | - // cache line exists - change it's priority and return |
57 | | - _stat_hit ++; |
58 | | - cache_line* L = c_storage + cptr; |
59 | | - move2top (L); |
60 | | - return FALSE; |
61 | | - } |
62 | | - |
63 | | - // 2. purge oldest item + move it to top |
64 | | - _stat_miss ++; |
65 | | - move2top (c_end); |
66 | | - if (c_begin->loopback) { |
67 | | - *c_begin->loopback = CAT_FREE; |
68 | | - c_begin->loopback = NULL; |
69 | | - } |
70 | | - |
71 | | - // 3. associate |
72 | | - cptr = c_begin->id; |
73 | | - c_begin->loopback = &cptr; |
74 | | - |
75 | | - // 4. fill with data |
76 | | - return TRUE; |
| 51 | + // 1. check if cached version available |
| 52 | + id %= cat.size; |
| 53 | +//. R_ASSERT (id<cat.size); |
| 54 | + u16& cptr = cat.table[id]; |
| 55 | + if (CAT_FREE != cptr) { |
| 56 | + // cache line exists - change it's priority and return |
| 57 | + _stat_hit ++; |
| 58 | + cache_line* L = c_storage + cptr; |
| 59 | + move2top (L); |
| 60 | + return FALSE; |
| 61 | + } |
| 62 | + |
| 63 | + // 2. purge oldest item + move it to top |
| 64 | + _stat_miss ++; |
| 65 | + move2top (c_end); |
| 66 | + if (c_begin->loopback) { |
| 67 | + *c_begin->loopback = CAT_FREE; |
| 68 | + c_begin->loopback = NULL; |
| 69 | + } |
| 70 | + |
| 71 | + // 3. associate |
| 72 | + cptr = c_begin->id; |
| 73 | + c_begin->loopback = &cptr; |
| 74 | + |
| 75 | + // 4. fill with data |
| 76 | + return TRUE; |
77 | 77 | } |
78 | 78 |
|
79 | | -void CSoundRender_Cache::initialize (u32 _total_kb_approx, u32 bytes_per_line) |
| 79 | +void CSoundRender_Cache::initialize (u32 _total_kb_approx, u32 bytes_per_line) |
80 | 80 | { |
81 | | - // use twice the requisted memory (to avoid bad configs) |
82 | | - _total_kb_approx *= 2; |
83 | | - |
84 | | - // calc |
85 | | - _line = bytes_per_line; |
86 | | - _count = ((_total_kb_approx*1024)/bytes_per_line + 1); |
87 | | - _total = _count*_line; |
88 | | - R_ASSERT (_count<CAT_FREE); |
89 | | - Msg ("* sound : cache: %d kb, %d lines, %d bpl",_total/1024,_count,_line); |
90 | | - |
91 | | - // alloc structs |
92 | | - data = xr_alloc<u8> (_total); |
93 | | - c_storage = xr_alloc<cache_line> (_count); |
94 | | - |
95 | | - // format |
96 | | - format (); |
| 81 | + // use twice the requisted memory (to avoid bad configs) |
| 82 | + _total_kb_approx *= 2; |
| 83 | + |
| 84 | + // calc |
| 85 | + _line = bytes_per_line; |
| 86 | + _count = ((_total_kb_approx*1024)/bytes_per_line + 1); |
| 87 | + _total = _count*_line; |
| 88 | + R_ASSERT (_count<CAT_FREE); |
| 89 | + Msg ("* sound : cache: %d kb, %d lines, %d bpl",_total/1024,_count,_line); |
| 90 | + |
| 91 | + // alloc structs |
| 92 | + data = xr_alloc<u8> (_total); |
| 93 | + c_storage = xr_alloc<cache_line> (_count); |
| 94 | + |
| 95 | + // format |
| 96 | + format (); |
97 | 97 | } |
98 | 98 |
|
99 | | -void CSoundRender_Cache::disconnect () |
| 99 | +void CSoundRender_Cache::disconnect () |
100 | 100 | { |
101 | | - // disconnect from CATs |
102 | | - for (u32 it=0; it<_count; it++) |
103 | | - { |
104 | | - cache_line* L = c_storage+it; |
105 | | - if (L->loopback) { |
106 | | - *L->loopback = CAT_FREE; |
107 | | - L->loopback = NULL; |
108 | | - } |
109 | | - } |
| 101 | + // disconnect from CATs |
| 102 | + for (u32 it=0; it<_count; it++) |
| 103 | + { |
| 104 | + cache_line* L = c_storage+it; |
| 105 | + if (L->loopback) { |
| 106 | + *L->loopback = CAT_FREE; |
| 107 | + L->loopback = NULL; |
| 108 | + } |
| 109 | + } |
110 | 110 | } |
111 | 111 |
|
112 | | -void CSoundRender_Cache::format () |
| 112 | +void CSoundRender_Cache::format () |
113 | 113 | { |
114 | | - // format structs |
115 | | - for (u32 it=0; it<_count; it++) |
116 | | - { |
117 | | - cache_line* L = c_storage+it; |
118 | | - L->prev = (0==it) ? NULL : c_storage+it-1; |
119 | | - L->next = ((_count-1) == it) ? NULL : c_storage+it+1; |
120 | | - L->data = data + it*_line; |
121 | | - L->loopback = NULL; |
122 | | - L->id = u16 (it); |
123 | | - } |
124 | | - |
125 | | - // start-end |
126 | | - c_begin = c_storage + 0; |
127 | | - c_end = c_storage + _count - 1; |
| 114 | + // format structs |
| 115 | + for (u32 it=0; it<_count; it++) |
| 116 | + { |
| 117 | + cache_line* L = c_storage+it; |
| 118 | + L->prev = (0==it) ? NULL : c_storage+it-1; |
| 119 | + L->next = ((_count-1) == it) ? NULL : c_storage+it+1; |
| 120 | + L->data = data + it*_line; |
| 121 | + L->loopback = NULL; |
| 122 | + L->id = u16 (it); |
| 123 | + } |
| 124 | + |
| 125 | + // start-end |
| 126 | + c_begin = c_storage + 0; |
| 127 | + c_end = c_storage + _count - 1; |
128 | 128 | } |
129 | 129 |
|
130 | | -void CSoundRender_Cache::purge () |
| 130 | +void CSoundRender_Cache::purge () |
131 | 131 | { |
132 | | - disconnect (); // disconnect from CATs |
133 | | - format (); // format |
| 132 | + disconnect (); // disconnect from CATs |
| 133 | + format (); // format |
134 | 134 | } |
135 | 135 |
|
136 | | -void CSoundRender_Cache::destroy () |
| 136 | +void CSoundRender_Cache::destroy () |
137 | 137 | { |
138 | | - disconnect (); |
139 | | - xr_free (data); |
140 | | - xr_free (c_storage); |
141 | | - c_begin = NULL; |
142 | | - c_end = NULL; |
143 | | - _total = 0; |
144 | | - _line = 0; |
145 | | - _count = 0; |
| 138 | + disconnect (); |
| 139 | + xr_free (data); |
| 140 | + xr_free (c_storage); |
| 141 | + c_begin = NULL; |
| 142 | + c_end = NULL; |
| 143 | + _total = 0; |
| 144 | + _line = 0; |
| 145 | + _count = 0; |
146 | 146 | } |
147 | 147 |
|
148 | | -void CSoundRender_Cache::cat_create (cache_cat& cat, u32 bytes) |
| 148 | +void CSoundRender_Cache::cat_create (cache_cat& cat, u32 bytes) |
149 | 149 | { |
150 | | - cat.size = bytes / _line; |
151 | | - if (bytes%_line) cat.size += 1; |
152 | | - u32 allocsize = (cat.size&1)?cat.size+1:cat.size; |
153 | | - cat.table = xr_alloc<u16>(allocsize); |
154 | | - memset (cat.table,0xffffffff,allocsize/2); |
| 150 | + cat.size = bytes / _line; |
| 151 | + if (bytes%_line) cat.size += 1; |
| 152 | + u32 allocsize = (cat.size&1)?cat.size+1:cat.size; |
| 153 | + cat.table = xr_alloc<u16>(allocsize); |
| 154 | + MemFill32(cat.table,0xffffffff,allocsize/2); |
155 | 155 | } |
156 | 156 |
|
157 | | -void CSoundRender_Cache::cat_destroy (cache_cat& cat) |
| 157 | +void CSoundRender_Cache::cat_destroy (cache_cat& cat) |
158 | 158 | { |
159 | | - xr_free (cat.table); |
160 | | - cat.size = 0; |
| 159 | + xr_free (cat.table); |
| 160 | + cat.size = 0; |
161 | 161 | } |
0 commit comments