Debian Codegraph @

src/uk/me/parabola/imgfmt/app/typ/ShapeStacking.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Steve Ratcliffe
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: Dec 15, 2007
16 */
17 package uk.me.parabola.imgfmt.app.typ;
18
19 import java.util.Map;
20 import java.util.SortedMap;
21 import java.util.TreeMap;
22
23 import uk.me.parabola.imgfmt.app.ImgFileWriter;
24
25 /**
26 * Holds the shape stacking section.
27 *
28 * Deals with sorting everything correctly, so no need to sort in the input file.
29 *
30 * @author Steve Ratcliffe
31 */
32 public class ShapeStacking {
33 private final SortedMap<Integer, DrawOrder> bar = new TreeMap<>();
34
35 public void addPolygon(int level, int type, int subtype) {
36 int levelType = (level << 16) + type;
37 bar.computeIfAbsent(levelType, k -> new DrawOrder(type)).addSubtype(subtype);
38 }
39
40 public void write(ImgFileWriter writer) {
41 int lastLevel = 1;
42
43 DrawOrder empty = new DrawOrder(0);
44
45 for (Map.Entry<Integer, DrawOrder> ent : bar.entrySet()) {
46 int level = (ent.getKey() >> 16) & 0xffff;
47 DrawOrder order = ent.getValue();
48
49 if (level != lastLevel) {
50 empty.write(writer);
51 lastLevel = level;
52 }
53
54 order.write(writer);
55 }
56 }
57
58 }