package world; import exceptions.ChunkNotLoadedException; import gen.ChunkLoader; import gen.WorldBuilder; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Point; import java.awt.image.BufferedImage; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.concurrent.Phaser; import main.GraphicsMain; public class World implements ScreenComponent{ private volatile ArrayList<Chunk> chunks = new ArrayList<Chunk>(); private volatile int chunksStability = 0; //+'ive = # threads accessing, -'ive = # threads editing private volatile Phaser chunkStabilityPhaser = new Phaser() { protected boolean onAdvance(int phase, int registeredParties) { synchronized(chunkStabilityCountLock) { if (registeredParties == 0) { chunksStability = 0; } else { } } return false; } }; private WorldBuilder worldBuilder; worldBuilder = new WorldBuilder(fileName); } public void load() { worldBuilder.loadWorld(); } public void update() { growVillages(); lockEditChunks(); for (Chunk c : chunks) { c.update(); } unlockEditChunks(); ArrayList<Village> villages = getVillages(); for (Village v : villages) { v.update(); } } public void growVillages() { ArrayList<Village> toGrow = getGrownVillages(); for (Village v : toGrow) { boolean complete = true; int maxDX = (int)(v.getRelativeChunkCenter().getX()); int maxDY = (int)(v.getRelativeChunkCenter().getY()); int oldVillageChunkLength = v.getChunkSideLength(v.getSizeRank()-v.getGrowth()); for (int dX = (int) (-1*v.getRelativeChunkCenter().getX()); dX <= maxDX; ++dX) { for (int dY = (int) (-1*v.getRelativeChunkCenter().getY()); dY <= maxDY; ++dY) { if (dX < oldVillageChunkLength*-1 || dX > oldVillageChunkLength || dY < oldVillageChunkLength*-1 || dY > oldVillageChunkLength) { Chunk cur; try { cur = getChunk(v.getX()+dX, v.getY()+dY); } catch (ChunkNotLoadedException e) { complete = false; continue; } //TODO decide what to do if there is already a village there cur.addVillage(v); } } } v.resetGrowth(); } } @Override public BufferedImage draw() { return draw(GraphicsMain.WIDTH/-2, GraphicsMain.HEIGHT/-2, GraphicsMain.WIDTH, GraphicsMain.HEIGHT); } public BufferedImage draw(int x, int y) { return draw(x, y, GraphicsMain.WIDTH, GraphicsMain.HEIGHT); } { drawChunks(x, y, width, height, gI); drawVillagers(x, y, gI); gI.dispose(); return image; } { for (int x = (int) ((x0-.0)/Chunk.getPixelLength()-0.5); x <= Math.ceil(((double)x0+width)/Chunk.getPixelLength()); ++x) { for (int y = (int) ((y0-.0)/Chunk.getPixelLength()-0.5); y <= Math.ceil(((double)y0+height)/Chunk.getPixelLength()); ++y) { Chunk c; try { c = getChunk(x, y); } catch (ChunkNotLoadedException e) { continue; } int cScreenX = (int)((x-0.5)*Chunk.getPixelLength()-x0), cScreenY = (int)((y-0.5)*Chunk.getPixelLength()-y0); if (!(cScreenX <= width && cScreenX+Chunk.getPixelLength() >= 0 && cScreenY <= width && cScreenY+Chunk.getPixelLength() >= 0)) //Check that shouldn't fail! { } gI.drawImage(cI, cScreenX, cScreenY, Chunk.getPixelLength(), Chunk.getPixelLength(), null); } } } { ArrayList<Village> villages = getVillages(); for (Village v : villages) { for (Villager villager : v.getPopulation()) { double vAbsX = villager.getRelativeX()+(v.getX()-screenX0+0.5)*Chunk.lengthOfChunk-0.5, vAbsY = villager.getRelativeY()+(v.getY()-screenY0+0.5)*Chunk.lengthOfChunk-0.5; //gI.drawImage(villager.draw(), (int)(vAbsX*Building.lengthOfBuilding), (int)(vAbsY*Building.lengthOfBuilding), null); } } } private ArrayList<Village> getGrownVillages() { ArrayList<Village> villages = getVillages(); ArrayList<Village> grownVillages = new ArrayList<Village>(); for (int i = 0; i < villages.size(); ++i) { if (villages.get(i).getGrowth() != 0) { grownVillages.add(villages.get(i)); } } return grownVillages; } private ArrayList<Chunk> getGrownVillageChunks() { ArrayList<Chunk> grownVillageChunks = new ArrayList<Chunk>(); lockEditChunks(); for (Chunk c : chunks) { if (c.hasVillage() && c.getVillage().getGrowth() != 0) { grownVillageChunks.add(c); } } unlockEditChunks(); return grownVillageChunks; } private ArrayList<Village> getVillages() { ArrayList<Village> villages = new ArrayList<Village>(); // Iterator has issues when the ArrayList is modified. // if the draw thread tries to zoom out and load new chunks during the time this loop is iterating, // the thread will crash lockEditChunks(); for (Chunk c : chunks) { if (c.hasVillage() && !villages.contains(c.getVillage())) { villages.add(c.getVillage()); } } unlockEditChunks(); return villages; } private ArrayList<Chunk> getVillageChunks() { ArrayList<Chunk> villageChunks = new ArrayList<Chunk>(); lockEditChunks(); for (Chunk c : chunks) { if (c.hasVillage()) { villageChunks.add(c); } } unlockEditChunks(); return villageChunks; } public Chunk getChunk(int x, int y) throws ChunkNotLoadedException { lockEditChunks(); for (Chunk c : chunks) { if (c.getX() == x && c.getY() == y) { unlockEditChunks(); return c; } } unlockEditChunks(); throw new ChunkNotLoadedException(); } public void addChunk(Chunk C) { destabalizeChunks(); chunks.add(C); stabalizeChunks(); } /** * Prevents other threads from editing <b>World.chunks</b>. * Calling this will freeze the thread if another thread has called <b>World.destabalizeChunks()</b> * without calling <b>World.stabalizeChunks()</b> */ /* * #UnArrivedParties = # threads currently requiring stability level * #ArrivedParties = # threads waiting for opposite stability level * #RegisteredParites == 0 = no one is accessing/modifying */ public void lockEditChunks() { chunkStabilityPhaser.register(); if (this.chunkStabilityPhaser.getUnarrivedParties() > 1 && this.chunksStability < 0) //number threads currently editing > 0 { this.chunkStabilityPhaser.arriveAndAwaitAdvance(); //wait until threads editing finish } //SOLVED I THINK //#registered threads > 0 then happened at momentary blip before decrement of chunk stability by threads waiting to modify chunks //#retistered threads == 0 then no threads waiting //other thread performs above check, but for a chunk stability of > 0 //continues past believing that no threads are waiting for stable access //then begins editing, and we have a problem //not only that but increment operator messes up synchronized(chunkStabilityCountLock) { ++this.chunksStability; } } public void unlockEditChunks() { chunkStabilityPhaser.arriveAndDeregister(); } /** * Prevents other threads requiring stability of <b>World.chunks</b> from continuing * Calling this will freeze the thread if another thread has called <b>World.lockEditChunks()</b> * without calling <b>World.unlockEditChunks()</b> */ public void destabalizeChunks() { chunkStabilityPhaser.register(); if (this.chunkStabilityPhaser.getUnarrivedParties() > 1 && this.chunksStability > 0) //number threads currently editing > 0 { this.chunkStabilityPhaser.arriveAndAwaitAdvance(); //wait until threads editing finish } synchronized(chunkStabilityCountLock) { --this.chunksStability; } } public void stabalizeChunks() { chunkStabilityPhaser.arriveAndDeregister(); } }
Standard input is empty
Main.java:17: error: class World is public, should be declared in a file named World.java public class World implements ScreenComponent{ ^ Main.java:3: error: package exceptions does not exist import exceptions.ChunkNotLoadedException; ^ Main.java:4: error: package gen does not exist import gen.ChunkLoader; ^ Main.java:5: error: package gen does not exist import gen.WorldBuilder; ^ Main.java:15: error: package main does not exist import main.GraphicsMain; ^ Main.java:17: error: cannot find symbol public class World implements ScreenComponent{ ^ symbol: class ScreenComponent Main.java:19: error: cannot find symbol private volatile ArrayList<Chunk> chunks = new ArrayList<Chunk>(); ^ symbol: class Chunk location: class World Main.java:39: error: cannot find symbol private WorldBuilder worldBuilder; ^ symbol: class WorldBuilder location: class World Main.java:148: error: cannot find symbol private ArrayList<Village> getGrownVillages() ^ symbol: class Village location: class World Main.java:162: error: cannot find symbol private ArrayList<Chunk> getGrownVillageChunks() ^ symbol: class Chunk location: class World Main.java:178: error: cannot find symbol private ArrayList<Village> getVillages() ^ symbol: class Village location: class World Main.java:196: error: cannot find symbol private ArrayList<Chunk> getVillageChunks() ^ symbol: class Chunk location: class World Main.java:212: error: cannot find symbol public Chunk getChunk(int x, int y) throws ChunkNotLoadedException ^ symbol: class Chunk location: class World Main.java:212: error: cannot find symbol public Chunk getChunk(int x, int y) throws ChunkNotLoadedException ^ symbol: class ChunkNotLoadedException location: class World Main.java:230: error: cannot find symbol public void addChunk(Chunk C) ^ symbol: class Chunk location: class World Main.java:19: error: cannot find symbol private volatile ArrayList<Chunk> chunks = new ArrayList<Chunk>(); ^ symbol: class Chunk location: class World Main.java:42: error: cannot find symbol worldBuilder = new WorldBuilder(fileName); ^ symbol: class WorldBuilder location: class World Main.java:53: error: cannot find symbol for (Chunk c : chunks) ^ symbol: class Chunk location: class World Main.java:59: error: cannot find symbol ArrayList<Village> villages = getVillages(); ^ symbol: class Village location: class World Main.java:60: error: cannot find symbol for (Village v : villages) ^ symbol: class Village location: class World Main.java:68: error: cannot find symbol ArrayList<Village> toGrow = getGrownVillages(); ^ symbol: class Village location: class World Main.java:69: error: cannot find symbol for (Village v : toGrow) ^ symbol: class Village location: class World Main.java:81: error: cannot find symbol Chunk cur; ^ symbol: class Chunk location: class World Main.java:84: error: cannot find symbol } catch (ChunkNotLoadedException e) { ^ symbol: class ChunkNotLoadedException location: class World Main.java:97: error: method does not override or implement a method from a supertype @Override ^ Main.java:98: error: cannot find symbol public BufferedImage draw() { return draw(GraphicsMain.WIDTH/-2, GraphicsMain.HEIGHT/-2, GraphicsMain.WIDTH, GraphicsMain.HEIGHT); } ^ symbol: variable GraphicsMain location: class World Main.java:98: error: cannot find symbol public BufferedImage draw() { return draw(GraphicsMain.WIDTH/-2, GraphicsMain.HEIGHT/-2, GraphicsMain.WIDTH, GraphicsMain.HEIGHT); } ^ symbol: variable GraphicsMain location: class World Main.java:98: error: cannot find symbol public BufferedImage draw() { return draw(GraphicsMain.WIDTH/-2, GraphicsMain.HEIGHT/-2, GraphicsMain.WIDTH, GraphicsMain.HEIGHT); } ^ symbol: variable GraphicsMain location: class World Main.java:98: error: cannot find symbol public BufferedImage draw() { return draw(GraphicsMain.WIDTH/-2, GraphicsMain.HEIGHT/-2, GraphicsMain.WIDTH, GraphicsMain.HEIGHT); } ^ symbol: variable GraphicsMain location: class World Main.java:99: error: cannot find symbol public BufferedImage draw(int x, int y) { return draw(x, y, GraphicsMain.WIDTH, GraphicsMain.HEIGHT); } ^ symbol: variable GraphicsMain location: class World Main.java:99: error: cannot find symbol public BufferedImage draw(int x, int y) { return draw(x, y, GraphicsMain.WIDTH, GraphicsMain.HEIGHT); } ^ symbol: variable GraphicsMain location: class World Main.java:113: error: cannot find symbol for (int x = (int) ((x0-.0)/Chunk.getPixelLength()-0.5); x <= Math.ceil(((double)x0+width)/Chunk.getPixelLength()); ++x) ^ symbol: variable Chunk location: class World Main.java:113: error: cannot find symbol for (int x = (int) ((x0-.0)/Chunk.getPixelLength()-0.5); x <= Math.ceil(((double)x0+width)/Chunk.getPixelLength()); ++x) ^ symbol: variable Chunk location: class World Main.java:115: error: cannot find symbol for (int y = (int) ((y0-.0)/Chunk.getPixelLength()-0.5); y <= Math.ceil(((double)y0+height)/Chunk.getPixelLength()); ++y) ^ symbol: variable Chunk location: class World Main.java:115: error: cannot find symbol for (int y = (int) ((y0-.0)/Chunk.getPixelLength()-0.5); y <= Math.ceil(((double)y0+height)/Chunk.getPixelLength()); ++y) ^ symbol: variable Chunk location: class World Main.java:117: error: cannot find symbol Chunk c; ^ symbol: class Chunk location: class World Main.java:120: error: cannot find symbol } catch (ChunkNotLoadedException e) { ^ symbol: class ChunkNotLoadedException location: class World Main.java:124: error: cannot find symbol int cScreenX = (int)((x-0.5)*Chunk.getPixelLength()-x0), cScreenY = (int)((y-0.5)*Chunk.getPixelLength()-y0); ^ symbol: variable Chunk location: class World Main.java:124: error: cannot find symbol int cScreenX = (int)((x-0.5)*Chunk.getPixelLength()-x0), cScreenY = (int)((y-0.5)*Chunk.getPixelLength()-y0); ^ symbol: variable Chunk location: class World Main.java:125: error: cannot find symbol if (!(cScreenX <= width && cScreenX+Chunk.getPixelLength() >= 0 && cScreenY <= width && cScreenY+Chunk.getPixelLength() >= 0)) //Check that shouldn't fail! ^ symbol: variable Chunk location: class World Main.java:125: error: cannot find symbol if (!(cScreenX <= width && cScreenX+Chunk.getPixelLength() >= 0 && cScreenY <= width && cScreenY+Chunk.getPixelLength() >= 0)) //Check that shouldn't fail! ^ symbol: variable Chunk location: class World Main.java:130: error: cannot find symbol gI.drawImage(cI, cScreenX, cScreenY, Chunk.getPixelLength(), Chunk.getPixelLength(), null); ^ symbol: variable Chunk location: class World Main.java:130: error: cannot find symbol gI.drawImage(cI, cScreenX, cScreenY, Chunk.getPixelLength(), Chunk.getPixelLength(), null); ^ symbol: variable Chunk location: class World Main.java:137: error: cannot find symbol ArrayList<Village> villages = getVillages(); ^ symbol: class Village location: class World Main.java:138: error: cannot find symbol for (Village v : villages) ^ symbol: class Village location: class World Main.java:140: error: cannot find symbol for (Villager villager : v.getPopulation()) ^ symbol: class Villager location: class World Main.java:142: error: cannot find symbol double vAbsX = villager.getRelativeX()+(v.getX()-screenX0+0.5)*Chunk.lengthOfChunk-0.5, vAbsY = villager.getRelativeY()+(v.getY()-screenY0+0.5)*Chunk.lengthOfChunk-0.5; ^ symbol: variable Chunk location: class World Main.java:142: error: cannot find symbol double vAbsX = villager.getRelativeX()+(v.getX()-screenX0+0.5)*Chunk.lengthOfChunk-0.5, vAbsY = villager.getRelativeY()+(v.getY()-screenY0+0.5)*Chunk.lengthOfChunk-0.5; ^ symbol: variable Chunk location: class World Main.java:150: error: cannot find symbol ArrayList<Village> villages = getVillages(); ^ symbol: class Village location: class World Main.java:151: error: cannot find symbol ArrayList<Village> grownVillages = new ArrayList<Village>(); ^ symbol: class Village location: class World Main.java:151: error: cannot find symbol ArrayList<Village> grownVillages = new ArrayList<Village>(); ^ symbol: class Village location: class World Main.java:164: error: cannot find symbol ArrayList<Chunk> grownVillageChunks = new ArrayList<Chunk>(); ^ symbol: class Chunk location: class World Main.java:164: error: cannot find symbol ArrayList<Chunk> grownVillageChunks = new ArrayList<Chunk>(); ^ symbol: class Chunk location: class World Main.java:167: error: cannot find symbol for (Chunk c : chunks) ^ symbol: class Chunk location: class World Main.java:180: error: cannot find symbol ArrayList<Village> villages = new ArrayList<Village>(); ^ symbol: class Village location: class World Main.java:180: error: cannot find symbol ArrayList<Village> villages = new ArrayList<Village>(); ^ symbol: class Village location: class World Main.java:185: error: cannot find symbol for (Chunk c : chunks) ^ symbol: class Chunk location: class World Main.java:198: error: cannot find symbol ArrayList<Chunk> villageChunks = new ArrayList<Chunk>(); ^ symbol: class Chunk location: class World Main.java:198: error: cannot find symbol ArrayList<Chunk> villageChunks = new ArrayList<Chunk>(); ^ symbol: class Chunk location: class World Main.java:201: error: cannot find symbol for (Chunk c : chunks) ^ symbol: class Chunk location: class World Main.java:215: error: cannot find symbol for (Chunk c : chunks) ^ symbol: class Chunk location: class World Main.java:227: error: cannot find symbol throw new ChunkNotLoadedException(); ^ symbol: class ChunkNotLoadedException location: class World 62 errors
Standard output is empty