I’m trying to improve my game’s rendering by bulk rendering the textures of blocks of the same type.
Each block in my game is defined by a class in the format BlockWood, which all extend from the class Block.
I currently have a map between the different block classes/types, and an ArrayList which contains the positions of all the blocks of that type, on the map.
HashMap<Block, ArrayList<Vector2f>> blockMap = new HashMap<Block, ArrayList<Vector2f>>();
Using this, I can loop through the map, bulk rendering each type of block, speeding up my rendering.
This approach however, doesn’t work. I want to be able to access the ArrayList’s using a dummy class as so –
blockMap.get(BlockWood.class);
Is there any efficient way I can map a class type to an ArrayList? Or will I just have to map the class string representations?
You want to use
Classas the key type. Your current implementation is using aBlockinstance as the key. Where as usingClasswill use the type ofBlockas the key.