|
17 | 17 | <input required |
18 | 18 | type=number |
19 | 19 | min=1 max=65536 |
20 | | - step=1 value=16 |
| 20 | + step=1 value=1024 |
21 | 21 | name="palette-entropy" |
22 | 22 | style="text-align:end;width:9em" |
23 | 23 | /><br/> |
|
38 | 38 | </select><br/> |
39 | 39 | <small>Backing Storage Type</small> |
40 | 40 | </label> |
| 41 | + <label> |
| 42 | + <input required |
| 43 | + type="checkbox" |
| 44 | + checked |
| 45 | + name="recurring-entropy-skip" |
| 46 | + /> |
| 47 | + <span>Skip Recurring</span> |
| 48 | + </label> |
41 | 49 | </div> |
42 | 50 | <blockquote style="display:flex;justify-content:center;align-items:center;padding:0.5rem"> |
43 | 51 | Palette Memory = Palette Entry Size * Entropy<br/> |
|
80 | 88 | } |
81 | 89 |
|
82 | 90 | var calculator = document.getElementById('{{id}}'); |
83 | | - var calc_input_es = calculator.querySelector('input[name=palette-entry-size]'); |
84 | | - var calc_input_me = calculator.querySelector('input[name=palette-entropy]'); |
85 | | - var calc_input_cs = calculator.querySelector('select[name=cell-size]'); |
86 | | - var calc_thead = calculator.querySelector('thead'); |
87 | | - var calc_tbody = calculator.querySelector('tbody'); |
| 91 | + var calc_input_es = calculator.querySelector('input[name=palette-entry-size]'); |
| 92 | + var calc_input_me = calculator.querySelector('input[name=palette-entropy]'); |
| 93 | + var calc_input_cs = calculator.querySelector('select[name=cell-size]'); |
| 94 | + var calc_input_rs = calculator.querySelector('input[name=recurring-entropy-skip]'); |
| 95 | + var calc_thead = calculator.querySelector('thead'); |
| 96 | + var calc_tbody = calculator.querySelector('tbody'); |
88 | 97 |
|
89 | 98 | function update() { |
90 | | - var EntrySize = null, MaxEntropy = null, CellSize = 64; |
91 | | - try { |
92 | | - EntrySize = Number.parseInt(calc_input_es.value || "1"); |
93 | | - MaxEntropy = Number.parseInt(calc_input_me.value || "1"); |
| 99 | + var EntrySize = null, MaxEntropy = null, CellSize = 64, SkipRecurring = true; |
| 100 | + try { |
| 101 | + EntrySize = Math.abs(Number.parseInt(calc_input_es.value || "1")); |
| 102 | + MaxEntropy = Math.abs(Number.parseInt(calc_input_me.value || "1")); |
94 | 103 | CellSize = calc_input_cs.value; |
95 | | - if (!EntrySize) throw "invalid"; |
96 | | - if (!MaxEntropy) throw "invalid"; |
97 | | - } catch(e) { |
98 | | - calc_tbody.innerHTML = ''; |
99 | | - return; |
100 | | - } |
| 104 | + if(MaxEntropy >= 512) calc_input_rs.checked = true; |
| 105 | + SkipRecurring = calc_input_rs.checked; |
| 106 | + if (!EntrySize) throw "invalid"; |
| 107 | + if (!MaxEntropy) throw "invalid"; |
| 108 | + } catch(e) { |
| 109 | + calc_tbody.innerHTML = ''; |
| 110 | + return; |
| 111 | + } |
101 | 112 |
|
102 | 113 | var sizes = [4, 8, 16, 32, 64]; |
103 | 114 | var scols = sizes.map((size) => { |
|
137 | 148 | } |
138 | 149 | calc_thead.innerHTML = thead + "</tr>"; |
139 | 150 |
|
| 151 | + var prev_entropy_bits = -1; |
| 152 | + var prev_skipped_count = 0; |
140 | 153 | var tbody = ""; |
141 | 154 | for(var entropy = 1; entropy <= MaxEntropy; entropy++) { |
142 | 155 | var entropy_bits = Math.ceil(Math.log2(entropy)); |
| 156 | + |
| 157 | + if(SkipRecurring) { |
| 158 | + if(prev_entropy_bits == entropy_bits) { |
| 159 | + prev_skipped_count++; |
| 160 | + continue; |
| 161 | + } else if(prev_skipped_count > 0) { |
| 162 | + tbody += `<tr>`; |
| 163 | + tbody += `<td colspan=${5} style="text-align:center;font-size:0.65em">`; |
| 164 | + tbody += `<span style="opacity:0.5">Skipped ${prev_skipped_count} row/s.</span>`; |
| 165 | + tbody += `</td>`; |
| 166 | + tbody += `<td colspan=${scols.length} style="border-left:1px solid lightgray">`; |
| 167 | + tbody += `</td>`; |
| 168 | + tbody += `</tr>`; |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + prev_entropy_bits = entropy_bits; |
| 173 | + prev_skipped_count = 0; |
| 174 | + |
143 | 175 | var entries = EntrySize * entropy; |
144 | 176 | var voxels_per_cell = Math.floor(entropy_bits != 0 ? CellSize / entropy_bits : 0); |
145 | 177 | var wasted_per_cell = entropy_bits != 0 ? CellSize % entropy_bits : 0; |
|
190 | 222 | calc_input_es.oninput = update; |
191 | 223 | calc_input_me.oninput = update; |
192 | 224 | calc_input_cs.onchange = update; |
| 225 | + calc_input_rs.onchange = update; |
193 | 226 | update(); |
194 | 227 | calculator.style = ''; |
195 | 228 | }) (); |
|
0 commit comments