/** * adds a fat. * * @param value fat's value. * @param big fat's size. */ public void addFat(int value, boolean big) { Entity inFront = getBodyParts().get(getBodyParts().size() - 1); Fat temp = new Fat(value, big); temp.setFrontX(inFront.getRearX()); temp.setY(inFront.getYFromCenterToRear(FAT_DISTANCE + NECK_RADIUS)); addBodyPart(temp); }
@Override public int addValue(int value) { for (Entity e : getBodyParts()) value = e.addValue(value); if (value > 0) { value -= 50; Vector<Entity> fats = getBodyParts(); Entity last = fats.get(fats.size() - 1); if (fats.size() < MAX_FATS) { Fat fat = new Fat(); fat.setAngle(last.getAngle()); fat.setFrontX(last.getRearX()); fat.setY(last.getYFromCenterToRear(FAT_DISTANCE + NECK_RADIUS)); fat.setMaxVelocity(0); addBodyPart(fat); } else for (int i = 0; i < fats.size(); ++i) if (!((Fat) fats.get(i)).getBig()) { ((Fat) fats.get(i)).setBig(true); break; } for (int i = 0; i < fats.size(); ++i) fats.get(i).setValue(((Fat) fats.get(i)).getBig() ? 50 : 0); } if (value > 0) spawnExcrement(value); return 0; }
public FatCache(Fat fat, int cacheSize, int elementSize) { this.fat = fat; this.api = fat.getApi(); this.fatsize = fat.getBootSector().getSectorsPerFat() * fat.getBootSector().getBytesPerSector(); this.nrfats = fat.getBootSector().getNrFats(); this.elementSize = elementSize; // allocate the LinkedHashMap // that do the dirty LRU job this.map = new CacheMap(cacheSize); }
/** Constructor for FatFileSystem in specified readOnly mode */ public FatFileSystem(Device device, boolean readOnly, FatFileSystemType type) throws FileSystemException { super(device, readOnly, type); // false = read/write mode try { bs = new BootSector(512); bs.read(getApi()); // if (!bs.isaValidBootSector()) throw new FileSystemException( // "Can't mount this partition: Invalid BootSector"); // System.out.println(bs); Fat[] fats = new Fat[bs.getNrFats()]; rootDir = new FatLfnDirectory(this, bs.getNrRootDirEntries()); FatType bitSize; if (bs.getMediumDescriptor() == 0xf8) { bitSize = FatType.FAT16; } else { bitSize = FatType.FAT12; } for (int i = 0; i < fats.length; i++) { Fat fat = new Fat( bitSize, bs.getMediumDescriptor(), bs.getSectorsPerFat(), bs.getBytesPerSector()); fats[i] = fat; fat.read(getApi(), FatUtils.getFatOffset(bs, i)); } for (int i = 1; i < fats.length; i++) { if (!fats[0].equals(fats[i])) { System.out.println("FAT " + i + " differs from FAT 0"); } } fat = fats[0]; rootDir.read(getApi(), FatUtils.getRootDirOffset(bs)); rootEntry = new FatRootEntry(rootDir); // files = new FatFile[fat.getNrEntries()]; } catch (IOException ex) { throw new FileSystemException(ex); } catch (Exception e) { // something bad happened in the FAT boot // sector... just ignore this FS throw new FileSystemException(e); } }
/** * Sets the length. * * @param length The length to set */ public synchronized void setLength(long length) throws IOException { if (getFileSystem().isReadOnly()) { throw new ReadOnlyFileSystemException("setLength in readonly filesystem"); } if (this.length == length) { // Do nothing return; } final FatFileSystem fs = getFatFileSystem(); final Fat fat = fs.getFat(); final int nrClusters = (int) ((length + clusterSize - 1) / clusterSize); if (this.length == 0) { final long[] chain = fat.allocNew(nrClusters); this.startCluster = chain[0]; this.myEntry.setStartCluster((int) startCluster); } else { final long[] chain = fs.getFat().getChain(startCluster); if (nrClusters != chain.length) { if (nrClusters > chain.length) { // Grow int count = nrClusters - chain.length; while (count > 0) { fat.allocAppend(getStartCluster()); count--; } } else { // Shrink fat.setEof(chain[nrClusters - 1]); for (int i = nrClusters; i < chain.length; i++) { fat.setFree(chain[i]); } } } } this.length = length; this.myEntry.updateLength(length); }
/** * Flush all changed structures to the device. * * @throws IOException */ public void flush() throws IOException { final BlockDeviceAPI api = getApi(); if (bs.isDirty()) { bs.write(api); } for (FatFile f : files.values()) { f.flush(); } if (fat.isDirty()) { for (int i = 0; i < bs.getNrFats(); i++) { fat.write(api, FatUtils.getFatOffset(bs, i)); } } if (rootDir.isDirty()) { rootDir.flush(); } }
public void setInt32(int index, int element) throws IOException { setInt32(fat.position(0, index), element); }
public long getUInt32(int index) throws IOException { return getUInt32(fat.position(0, index)); }
public void setMovingFast(boolean movingFast) { for (Entity e : getBodyParts()) ((Fat) e).setMovingFast(movingFast); }