Fix threading issues.
This commit is contained in:
		
							parent
							
								
									6b64e29689
								
							
						
					
					
						commit
						9642d25c34
					
				| @ -33,8 +33,8 @@ public class Panel extends JPanel implements Runnable { | |||||||
|     private MemoryImageSource mImageProducer;    |     private MemoryImageSource mImageProducer;    | ||||||
|     private ColorModel cm;     |     private ColorModel cm;     | ||||||
|     private Thread thread; |     private Thread thread; | ||||||
|     Thread[] workerThread = new Thread[8]; |     Thread[] workerThread = new Thread[9]; | ||||||
|     String[][] keySets = new String[8][]; |     String[][] keySets = new String[9][]; | ||||||
|     ConcurrentLinkedQueue<Triangle> newTris = new ConcurrentLinkedQueue<>(); |     ConcurrentLinkedQueue<Triangle> newTris = new ConcurrentLinkedQueue<>(); | ||||||
|     List<Triangle> accumulatedTris = new ArrayList<Triangle>(); |     List<Triangle> accumulatedTris = new ArrayList<Triangle>(); | ||||||
|     public static ConcurrentLinkedQueue<Triangle> accumulatedTris1 = new ConcurrentLinkedQueue<>(); |     public static ConcurrentLinkedQueue<Triangle> accumulatedTris1 = new ConcurrentLinkedQueue<>(); | ||||||
| @ -134,15 +134,7 @@ public class Panel extends JPanel implements Runnable { | |||||||
|         int currentSet=0; |         int currentSet=0; | ||||||
|         for (String key : SigRenderer.blockGrid.keySet()) { |         for (String key : SigRenderer.blockGrid.keySet()) { | ||||||
|             if (currentPiece==0) { |             if (currentPiece==0) { | ||||||
|                 if (currentSet==7) { |  | ||||||
|                     if (SigRenderer.blockGrid.size()%8==0) { |  | ||||||
|                 keySets[currentSet] = new String[pieces]; |                 keySets[currentSet] = new String[pieces]; | ||||||
|                     } else { |  | ||||||
|                         keySets[currentSet] = new String[SigRenderer.blockGrid.size()%8]; |  | ||||||
|                     } |  | ||||||
|                 } else { |  | ||||||
|                     keySets[currentSet] = new String[pieces]; |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|             keySets[currentSet][currentPiece]=key; |             keySets[currentSet][currentPiece]=key; | ||||||
|             currentPiece++; |             currentPiece++; | ||||||
| @ -167,18 +159,24 @@ public class Panel extends JPanel implements Runnable { | |||||||
|                 accumulatedTris1.clear(); |                 accumulatedTris1.clear(); | ||||||
|             } |             } | ||||||
|             final Matrix matWorld2 = matWorld; |             final Matrix matWorld2 = matWorld; | ||||||
|             for (int i=0;i<8;i++) { |             for (int i=0;i<9;i++) { | ||||||
|                 final int id=i; |                 final int id=i; | ||||||
|                 workerThread[i] = new Thread(){ |                 workerThread[i] = new Thread(){ | ||||||
|                     @Override |                     @Override | ||||||
|                     public void run() { |                     public void run() { | ||||||
|                         ConcurrentLinkedQueue<Triangle> newTris = new ConcurrentLinkedQueue<>(); |                         ConcurrentLinkedQueue<Triangle> newTris = new ConcurrentLinkedQueue<>(); | ||||||
|  |                         if (keySets[id]!=null) { | ||||||
|                             for (String key : keySets[id]) { |                             for (String key : keySets[id]) { | ||||||
|  |                                 if (key!=null) { | ||||||
|                                     Block b = SigRenderer.blockGrid.get(key); |                                     Block b = SigRenderer.blockGrid.get(key); | ||||||
|  |                                     if (b!=null) { | ||||||
|                                         for (Triangle t : b.block.prepareRender(b)) { |                                         for (Triangle t : b.block.prepareRender(b)) { | ||||||
|                                             prepareTriForRender(matWorld2, matView, t, newTris); |                                             prepareTriForRender(matWorld2, matView, t, newTris); | ||||||
|                                         } |                                         } | ||||||
|                                     } |                                     } | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|                         if (renderFirst) { |                         if (renderFirst) { | ||||||
|                             accumulatedTris2.addAll(newTris); |                             accumulatedTris2.addAll(newTris); | ||||||
|                         } else { |                         } else { | ||||||
|  | |||||||
| @ -36,7 +36,7 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene | |||||||
| 
 | 
 | ||||||
|     public static boolean windowActive=true; |     public static boolean windowActive=true; | ||||||
|     public static boolean WIREFRAME = false; |     public static boolean WIREFRAME = false; | ||||||
|     public static boolean PROFILING = true; |     public static boolean PROFILING = false; | ||||||
|     public static boolean FLYING_MODE = false; |     public static boolean FLYING_MODE = false; | ||||||
|     public static int SCREEN_WIDTH=1280; |     public static int SCREEN_WIDTH=1280; | ||||||
|     public static int SCREEN_HEIGHT=720; |     public static int SCREEN_HEIGHT=720; | ||||||
| @ -402,8 +402,6 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene | |||||||
|         for (int x=0;x<64;x++) { |         for (int x=0;x<64;x++) { | ||||||
|             for (int z=0;z<64;z++) { |             for (int z=0;z<64;z++) { | ||||||
|                 addBlock(new Vector(x,0,z),Cube.class,BlockType.SOIL_WET,FacingDirection.SOUTH); |                 addBlock(new Vector(x,0,z),Cube.class,BlockType.SOIL_WET,FacingDirection.SOUTH); | ||||||
|                 addBlock(new Vector(x,1,z),Plant.class,BlockType.valueOf("WHEAT_"+(r.nextInt(7))),FacingDirection.SOUTH); |  | ||||||
| 
 |  | ||||||
|                 //addBlock(new Vector(x,1,z),Staircase.class,BlockType.JUNGLE_PLANK,FacingDirection.SOUTH); |                 //addBlock(new Vector(x,1,z),Staircase.class,BlockType.JUNGLE_PLANK,FacingDirection.SOUTH); | ||||||
|                 //addBlock(new Vector(x,2,z),Staircase.class,BlockType.SPRUCE_PLANK,FacingDirection.SOUTH); |                 //addBlock(new Vector(x,2,z),Staircase.class,BlockType.SPRUCE_PLANK,FacingDirection.SOUTH); | ||||||
|                 /*for (int y=1;y<r.nextInt(5);y++) { |                 /*for (int y=1;y<r.nextInt(5);y++) { | ||||||
| @ -430,6 +428,7 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene | |||||||
|                 }*/ |                 }*/ | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         addBlock(new Vector(31,1,31),Plant.class,BlockType.valueOf("WHEAT_"+(r.nextInt(7))),FacingDirection.SOUTH); | ||||||
|         /*addBlock(new Vector(31,2,32),Staircase.class,BlockType.PLANKS,FacingDirection.EAST); |         /*addBlock(new Vector(31,2,32),Staircase.class,BlockType.PLANKS,FacingDirection.EAST); | ||||||
|         addBlock(new Vector(31,3,33),Staircase.class,BlockType.PLANKS,FacingDirection.WEST); |         addBlock(new Vector(31,3,33),Staircase.class,BlockType.PLANKS,FacingDirection.WEST); | ||||||
|         addBlock(new Vector(31,4,34),Staircase.class,BlockType.PLANKS,FacingDirection.SOUTH); |         addBlock(new Vector(31,4,34),Staircase.class,BlockType.PLANKS,FacingDirection.SOUTH); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user