| 116 | // last bits of redundancy. Both passes contribute greatly to the miniscule map sizes. |
| 117 | |
| 118 | void rlencodecubes(vector<uchar> &f, sqr *s, int len, bool preservesolids) // run-length encoding and serialisation of a series of cubes |
| 119 | { |
| 120 | sqr *t = NULL; |
| 121 | int sc = 0; |
| 122 | #define spurge while(sc) { f.add(255); if(sc>255) { f.add(255); sc -= 255; } else { f.add(sc); sc = 0; } } |
| 123 | #define c(f) (s->f==t->f) |
| 124 | while(len-- > 0) |
| 125 | { |
| 126 | // 4 types of blocks, to compress a bit: |
| 127 | // 255 (2): same as previous block + count |
| 128 | // 254 (3): same as previous, except light // deprecated |
| 129 | // SOLID (5) |
| 130 | // anything else (9) |
| 131 | |
| 132 | if(SOLID(s) && !preservesolids) |
| 133 | { |
| 134 | if(t && c(type) && c(wtex) && c(vdelta)) |
| 135 | { |
| 136 | sc++; |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | spurge; |
| 141 | f.add(s->type); |
| 142 | f.add(s->wtex); |
| 143 | f.add(s->vdelta); |
| 144 | } |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | if(t && c(type) && c(floor) && c(ceil) && c(ctex) && c(ftex) && c(utex) && c(wtex) && c(vdelta) && c(tag)) |
| 149 | { |
| 150 | sc++; |
| 151 | } |
| 152 | else |
| 153 | { |
| 154 | spurge; |
| 155 | f.add(s->type == SOLID ? 253 : s->type); |
| 156 | f.add(s->floor); |
| 157 | f.add(s->ceil); |
| 158 | f.add(s->wtex); |
| 159 | f.add(s->ftex); |
| 160 | f.add(s->ctex); |
| 161 | f.add(s->vdelta); |
| 162 | f.add(s->utex); |
| 163 | f.add(s->tag); |
| 164 | } |
| 165 | } |
| 166 | t = s; |
| 167 | s++; |
| 168 | } |
| 169 | spurge; |
| 170 | } |
| 171 | |
| 172 | bool rldecodecubes(ucharbuf &f, sqr *s, int len, int version, bool silent) // run-length decoding of a series of cubes (version is only relevant, if < 6) |
| 173 | { |
no test coverage detected