Coverage Summary for Class: RenderingManager (com.mygdx.game.Managers)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| RenderingManager | 100% (1/1) | 50% (5/10) | 14.7% (5/34) |
1 package com.mygdx.game.Managers; 2 3 import com.badlogic.gdx.Application; 4 import com.badlogic.gdx.Gdx; 5 import com.badlogic.gdx.graphics.OrthographicCamera; 6 import com.badlogic.gdx.graphics.g2d.SpriteBatch; 7 import com.mygdx.game.Components.Component; 8 import com.mygdx.game.Entitys.Building; 9 10 import java.util.ArrayList; 11 12 import static com.mygdx.utils.Constants.*; 13 14 /** 15 * Responsible for all rending. Renders in layers render item layers can't be changed 16 * holds the primary sprite batch and rendering camera 17 */ 18 public final class RenderingManager { 19 private static boolean initialized = false; 20 private static ArrayList<Component> renderItems; 21 private static ArrayList<ArrayList<Integer>> layers; 22 private static OrthographicCamera camera; 23 private static SpriteBatch batch; 24 25 public static void Initialize() { 26 initialized = true; 27 renderItems = new ArrayList<>(); 28 29 30 batch = new SpriteBatch(); 31 // batch.enableBlending(); 32 camera = new OrthographicCamera(); 33 camera.viewportHeight = VIEWPORT_HEIGHT / ZOOM; 34 camera.viewportWidth = VIEWPORT_WIDTH / ZOOM; 35 camera.update(); 36 37 layers = new ArrayList<>(RenderLayer.values().length); 38 39 for (int i = 0; i < RenderLayer.values().length; i++) { 40 layers.add(new ArrayList<>()); 41 } 42 } 43 44 public static OrthographicCamera getCamera() { 45 return camera; 46 } 47 48 49 public static void setCamera(OrthographicCamera cam) { 50 camera = cam; 51 } 52 53 /** 54 * adds item to the list of renderable and adds to the correct layer 55 * 56 * @param item component that utilises render 57 * @param layer the layer that it will be rendered in 58 */ 59 public static void addItem(Component item, RenderLayer layer) { 60 if(Application.ApplicationType.HeadlessDesktop == Gdx.app.getType()){ 61 return; 62 } 63 tryInit(); 64 renderItems.add(item); 65 layers.get(layer.ordinal()).add(renderItems.size() - 1); 66 } 67 68 private static void tryInit() { 69 70 if (!initialized) { 71 Initialize(); 72 } 73 } 74 75 /** 76 * Renders all items in accordance with their layers on one sprite batch 77 */ 78 public static void render() { 79 tryInit(); 80 81 batch.setProjectionMatrix(camera.combined); 82 batch.begin(); 83 84 for (ArrayList<Integer> layer : layers) { 85 for (Integer itemIndex : layer) { 86 Component item = renderItems.get(itemIndex); 87 if (item.getParent() instanceof Building) { 88 int i = 0; 89 } 90 item.render(); 91 } 92 } 93 94 /*for(int i = 0; i < renderItems.size(); i++){ 95 //renderItems.get(renderItems.size() - (1 + i)).render(); 96 renderItems.get(i).render(); 97 }*/ 98 99 batch.end(); 100 } 101 102 public static void cleanUp() { 103 batch.dispose(); 104 } 105 106 public static SpriteBatch getBatch() { 107 return batch; 108 } 109 }