code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
private static Charset getCharset(String charset)
{
try
{
return Charset.forName(charset);
}
catch (final UnsupportedCharsetException exception)
{
Verbose.exception(exception);
return Charset.defaultCharset();
}
} | java |
public final ByteArrayOutputStream encode() throws IOException
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
buffer.write(type);
buffer.write(clientId);
buffer.write(clientDestId);
encode(buffer);
return buffer;
} | java |
public final void decode(byte type, byte from, byte dest, DataInputStream buffer) throws IOException
{
this.type = type;
clientId = from;
clientDestId = dest;
decode(buffer);
} | java |
void robotMove(int nx, int ny)
{
oldX = x;
oldY = y;
x = nx;
y = ny;
wx = nx;
wy = ny;
mx = x - oldX;
my = y - oldY;
moved = true;
} | java |
void robotTeleport(int nx, int ny)
{
oldX = nx;
oldY = ny;
x = nx;
y = ny;
wx = nx;
wy = ny;
mx = 0;
my = 0;
moved = false;
} | java |
void update()
{
mx = x - oldX;
my = y - oldY;
oldX = x;
oldY = y;
} | java |
public static List<ActionRef> imports(Configurer configurer)
{
Check.notNull(configurer);
return imports(configurer.getRoot());
} | java |
public static List<ActionRef> imports(Xml root)
{
Check.notNull(root);
if (!root.hasChild(NODE_ACTIONS))
{
return Collections.emptyList();
}
final Xml node = root.getChild(NODE_ACTIONS);
return getRefs(node);
} | java |
public static Xml exports(Collection<ActionRef> actions)
{
Check.notNull(actions);
final Xml node = new Xml(NODE_ACTIONS);
for (final ActionRef action : actions)
{
final Xml nodeAction = node.createChild(NODE_ACTION);
nodeAction.writeString(ATT_PATH... | java |
private static List<ActionRef> getRefs(Xml node)
{
final Collection<Xml> children = node.getChildren(NODE_ACTION);
final List<ActionRef> actions = new ArrayList<>(children.size());
for (final Xml action : children)
{
final String path = action.readString(ATT_PATH)... | java |
private static void exports(Xml node, ActionRef action)
{
final Xml nodeAction = node.createChild(NODE_ACTION);
nodeAction.writeString(ATT_PATH, action.getPath());
for (final ActionRef ref : action.getRefs())
{
exports(nodeAction, ref);
}
} | java |
public void keyPressed(KeyEvent event)
{
lastKeyName = event.getName();
lastCode = Integer.valueOf(event.getCode());
if (!keys.contains(lastCode))
{
keys.add(lastCode);
}
} | java |
public void keyReleased(KeyEvent event)
{
lastKeyName = EMPTY_KEY_NAME;
lastCode = NO_KEY_CODE;
final Integer key = Integer.valueOf(event.getCode());
keys.remove(key);
pressed.remove(key);
} | java |
protected void addMessage(String message)
{
messages.add(message);
messageCount++;
if (messageCount > messagesQueueMax)
{
messages.remove();
messageCount--;
}
} | java |
private void sendValidatedMessage()
{
final String msg = message.toString();
if (canSendMessage(msg))
{
addNetworkMessage(new NetworkMessageChat(type, getClientId().byteValue(), msg));
}
message.delete(0, message.length());
} | java |
public boolean includes(double value)
{
return Double.compare(value, min) >= 0 && Double.compare(value, max) <= 0;
} | java |
public static Xml exports(SizeConfig config)
{
Check.notNull(config);
final Xml node = new Xml(NODE_SIZE);
node.writeInteger(ATT_WIDTH, config.getWidth());
node.writeInteger(ATT_HEIGHT, config.getHeight());
return node;
} | java |
private void addPoint(Point point, Collidable collidable)
{
final Integer group = collidable.getGroup();
if (!collidables.containsKey(group))
{
collidables.put(group, new HashMap<Point, Set<Collidable>>());
}
final Map<Point, Set<Collidable>> elements = collidable... | java |
private void checkGroup(Entry<Point, Set<Collidable>> current)
{
final Set<Collidable> elements = current.getValue();
for (final Collidable objectA : elements)
{
checkOthers(objectA, current);
}
} | java |
private void checkPoint(Collidable objectA, Map<Point, Set<Collidable>> acceptedElements, Point point)
{
final Set<Collidable> others = acceptedElements.get(point);
for (final Collidable objectB : others)
{
if (objectA != objectB)
{
final List<Collisio... | java |
private void addPoints(int minX, int minY, int maxX, int maxY, Collidable collidable)
{
addPoint(new Point(minX, minY), collidable);
if (minX != maxX && minY == maxY)
{
addPoint(new Point(maxX, minY), collidable);
}
else if (minX == maxX && minY != maxY)
... | java |
protected void actionGoingToResources()
{
if (checker.canExtract())
{
for (final ExtractorListener listener : listeners)
{
listener.notifyStartExtraction(resourceType, resourceLocation);
}
state = ExtractorState.EXTRACTING;
}
... | java |
protected void actionExtracting(double extrp)
{
if (extractable == null || extractable.getResourceQuantity() > 0)
{
if (extractable != null)
{
progress += Math.min(extractable.getResourceQuantity(), speed * extrp);
}
else
{
... | java |
protected void actionGoingToWarehouse()
{
if (checker.canCarry())
{
for (final ExtractorListener listener : listeners)
{
listener.notifyStartDropOff(resourceType, lastProgress);
}
speed = dropOffPerSecond / rate.getAsInt();
... | java |
protected void actionDropingOff(double extrp)
{
progress -= speed * extrp;
final int curProgress = (int) Math.floor(progress);
// Check ended
if (curProgress <= 0)
{
for (final ExtractorListener listener : listeners)
{
listener.notifyD... | java |
private void extract(int curProgress)
{
if (extractable != null)
{
extractable.extractResource(curProgress - lastProgress);
}
for (final ExtractorListener listener : listeners)
{
listener.notifyExtracted(resourceType, curProgress);
}
la... | java |
public GeneratorParameter add(Preference preference)
{
preferences.add(preference);
Collections.sort(preferences);
return this;
} | java |
void setFilter(Filter filter)
{
this.filter = Optional.ofNullable(filter).orElse(FilterNone.INSTANCE);
transform = getTransform();
} | java |
void initResolution(Resolution source)
{
Check.notNull(source);
setSystemCursorVisible(cursorVisibility.booleanValue());
this.source = source;
screen.onSourceChanged(source);
final int width = source.getWidth();
final int height = source.getHeight();
// Stan... | java |
void setSystemCursorVisible(boolean visible)
{
if (screen == null)
{
cursorVisibility = Boolean.valueOf(visible);
}
else
{
if (visible)
{
screen.showCursor();
}
else
{
scre... | java |
private Transform getTransform()
{
final Resolution output = config.getOutput();
final double scaleX = output.getWidth() / (double) source.getWidth();
final double scaleY = output.getHeight() / (double) source.getHeight();
return filter.getTransform(scaleX, scaleY);
} | java |
void render()
{
if (screen.isReady())
{
final Graphic g = screen.getGraphic();
if (buf == null)
{
// Direct rendering
target.render(g);
}
else
{
target.render(graphic);
... | java |
private static String formatResolution(Resolution resolution, int depth)
{
return new StringBuilder(MIN_LENGTH).append(String.valueOf(resolution.getWidth()))
.append(Constant.STAR)
.append(String.valueOf(resolution.getHe... | java |
private void initFullscreen(Resolution output, int depth)
{
final java.awt.Window window = new java.awt.Window(frame, conf);
window.setBackground(Color.BLACK);
window.setIgnoreRepaint(true);
window.setPreferredSize(new Dimension(output.getWidth(), output.getHeight()));
dev.se... | java |
private String getSupportedResolutions()
{
final StringBuilder builder = new StringBuilder(Constant.HUNDRED);
int i = 0;
for (final DisplayMode display : dev.getDisplayModes())
{
final StringBuilder widthSpace = new StringBuilder();
final int width = display.g... | java |
private DisplayMode isSupported(DisplayMode display)
{
final DisplayMode[] supported = dev.getDisplayModes();
for (final DisplayMode current : supported)
{
final boolean multiDepth = current.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI && display.equals(current);
if (... | java |
private static String getTempDir(Class<?> loader)
{
final File temp = new File(TEMP, loader.getSimpleName());
final String path = temp.getAbsolutePath();
if (!temp.isDirectory() && !temp.mkdir())
{
Verbose.warning(ERROR_CREATE_TEMP_DIR, path);
}
re... | java |
private String getPrefix()
{
final String prefix;
if (loader.isPresent())
{
prefix = loader.get().getPackage().getName().replace(Constant.DOT, File.separator);
}
else
{
prefix = resourcesDir;
}
return prefix;
} | java |
private Media create(String prefix, int prefixLength, File file)
{
final String currentPath = file.getPath();
final String[] systemPath = SLASH.split(currentPath.substring(currentPath.indexOf(prefix) + prefixLength)
.replace(File.separat... | java |
private InputStream getInputFromJarOrTemp() throws FileNotFoundException
{
final InputStream input = loader.get().getResourceAsStream(UtilFolder.getPathSeparator(separator, getPath()));
if (input == null)
{
return new FileInputStream(getPathTemp());
}
retur... | java |
private String getPathTemp()
{
return UtilFolder.getPathSeparator(File.separator,
getTempDir(loader.get()),
path.replace(separator, File.separator));
} | java |
public static synchronized void addFormat(AudioFormat format)
{
Check.notNull(format);
for (final String current : format.getFormats())
{
if (FACTORIES.put(current, format) != null)
{
throw new LionEngineException(ERROR_EXISTS + current);
... | java |
public static void copy(InputStream source, OutputStream destination) throws IOException
{
Check.notNull(source);
Check.notNull(destination);
final byte[] buffer = new byte[BUFFER_COPY];
while (true)
{
final int read = source.read(buffer);
if (read ==... | java |
public static File getCopy(String name, InputStream input)
{
Check.notNull(name);
Check.notNull(input);
final String prefix;
final String suffix;
final int minimumPrefix = 3;
final int i = name.lastIndexOf(Constant.DOT);
if (i > minimumPrefix)
{
... | java |
void robotPress(int click)
{
lastClick = click;
if (lastClick < clicks.length)
{
clicks[lastClick] = true;
}
} | java |
void robotRelease(int click)
{
lastClick = 0;
final int button = click;
if (button < clicks.length)
{
clicks[button] = false;
clicked[button] = false;
}
} | java |
void addActionReleased(int click, EventAction action)
{
final Integer key = Integer.valueOf(click);
final List<EventAction> list;
if (actionsReleased.get(key) == null)
{
list = new ArrayList<>();
actionsReleased.put(key, list);
}
else
{... | java |
boolean hasClickedOnce(int click)
{
if (click < clicks.length && clicks[click] && !clicked[click])
{
clicked[click] = true;
return true;
}
return false;
} | java |
private static Transition getTransitionSingleGroup(Collection<String> groups)
{
final Iterator<String> iterator = groups.iterator();
final String group = iterator.next();
return new Transition(TransitionType.CENTER, group, group);
} | java |
private static Transition getTransitionTwoGroups(Collection<String> neighborGroups)
{
final Iterator<String> iterator = new HashSet<>(neighborGroups).iterator();
final String groupIn = iterator.next();
final String groupOut = iterator.next();
final TransitionType type = getTrans... | java |
private static TransitionType getTransitionType(String groupIn, Collection<String> neighborGroups)
{
final boolean[] bits = new boolean[TransitionType.BITS];
int i = 0;
for (final String neighborGroup : neighborGroups)
{
bits[i] = !groupIn.equals(neighborGroup);
... | java |
public Transition getTransition(Tile tile)
{
final Collection<String> neighborGroups = getNeighborGroups(tile);
final Collection<String> groups = new HashSet<>(neighborGroups);
final Transition transition;
if (groups.size() == 1 && mapGroup.getGroup(tile).equals(groups.iterato... | java |
private Collection<String> getNeighborGroups(Tile tile)
{
final Collection<String> neighborGroups = new ArrayList<>(TransitionType.BITS);
addNeighborGroup(neighborGroups, tile, 1, -1);
addNeighborGroup(neighborGroups, tile, -1, -1);
addNeighborGroup(neighborGroups, tile, 1, 1)... | java |
private void addNeighborGroup(Collection<String> neighborGroups, Tile tile, int ox, int oy)
{
final Tile neighbor = map.getTile(tile.getInTileX() + ox, tile.getInTileY() + oy);
if (neighbor != null)
{
final String neighborGroup = getNeighborGroup(tile, neighbor);
... | java |
private String getNeighborGroup(Tile tile, Tile neighbor)
{
final String neighborGroup;
if (isTransition(neighbor))
{
if (isTransition(tile))
{
neighborGroup = getOtherGroup(tile, neighbor);
}
else
{
... | java |
private String getOtherGroup(Tile tile, Tile neighbor)
{
final String group = mapGroup.getGroup(tile);
for (final Tile shared : getSharedNeigbors(tile, neighbor))
{
final String sharedNeighborGroup = mapGroup.getGroup(shared);
if (!group.equals(sharedNeighborGro... | java |
private Collection<Tile> getSharedNeigbors(Tile tile1, Tile tile2)
{
final Collection<Tile> neighbors1 = map.getNeighbors(tile1);
final Collection<Tile> neighbors2 = map.getNeighbors(tile2);
final Collection<Tile> sharedNeighbors = new HashSet<>(2);
for (final Tile neighbor : ne... | java |
private static Robot createRobot()
{
try
{
return new Robot();
}
catch (final AWTException exception)
{
Verbose.exception(exception, ERROR_ROBOT);
return null;
}
} | java |
public void setResolution(Resolution output, Resolution source)
{
Check.notNull(output);
Check.notNull(source);
xRatio = output.getWidth() / (double) source.getWidth();
yRatio = output.getHeight() / (double) source.getHeight();
} | java |
public Sprite getRaster(int id)
{
return rasters.get(UtilMath.clamp(id, 0, rasters.size() - 1));
} | java |
private void updateAdd()
{
if (willAdd)
{
for (final Featurable featurable : toAdd)
{
featurables.add(featurable);
for (final HandlerListener listener : listeners)
{
listener.notifyHandlableAdded(fea... | java |
private void updateRemove()
{
if (willDelete)
{
for (final Integer id : toDelete)
{
final Featurable featurable = featurables.get(id);
for (final HandlerListener listener : listeners)
{
listener.noti... | java |
private static Integer getFreeId()
{
if (!RECYCLE.isEmpty())
{
final Integer id = RECYCLE.poll();
IDS.add(id);
return id;
}
if (IDS.size() == Integer.MAX_VALUE)
{
throw new LionEngineException(ERROR_FREE_ID);
... | java |
public void addMessage(String message, int x, int y, long time)
{
messages.add(new MessageData(message, x, y, time));
hasMessage = true;
} | java |
private static String extractFromJar(Media media)
{
try (InputStream input = media.getInputStream())
{
final File file = UtilStream.getCopy(media.getFile().getName(), input);
return file.getAbsolutePath();
}
catch (final IOException exception)
{
... | java |
private void play(String track, String name)
{
Verbose.info(INFO_PLAYING, name);
play(track);
} | java |
private void updateAttackCheck()
{
attacking = false;
attacked = false;
// Check if target is valid; exit if invalid
if (target == null)
{
state = AttackState.NONE;
}
else
{
final double dist = UtilMath.getDistance(tr... | java |
private void checkTargetDistance(double dist)
{
if (distAttack.includes(dist))
{
if (checker.canAttack())
{
state = AttackState.ATTACKING;
}
}
else if (tick.elapsed(attackPause))
{
for (final AttackerL... | java |
private void updateAttacking()
{
if (tick.elapsed(attackPause))
{
updateAttackHit();
}
else if (attacked)
{
if (AnimState.FINISHED == animator.getAnimState())
{
for (final AttackerListener listener : listeners)
... | java |
private void updateAttackHit()
{
if (!attacking)
{
for (final AttackerListener listener : listeners)
{
listener.notifyAttackStarted(target);
}
attacking = true;
attacked = false;
}
// Hit when fram... | java |
public static int getRandomInteger(Range range)
{
Check.notNull(range);
return getRandomInteger(range.getMin(), range.getMax());
} | java |
public static int getRandomInteger(int min, int max)
{
Check.inferiorOrEqual(min, max);
return min + RANDOM.nextInt(max + 1 - min);
} | java |
public static ImageBuffer createFunctionDraw(CollisionFormula collision, int tw, int th)
{
final ImageBuffer buffer = Graphics.createImageBuffer(tw, th, ColorRgba.TRANSPARENT);
final Graphic g = buffer.createGraphic();
g.setColor(ColorRgba.PURPLE);
createFunctionDraw(g, collis... | java |
private static void createFunctionDraw(Graphic g, CollisionFormula formula, int tw, int th)
{
for (int x = 0; x < tw; x++)
{
for (int y = 0; y < th; y++)
{
renderCollision(g, formula, th, x, y);
}
}
} | java |
private static void renderCollision(Graphic g, CollisionFormula formula, int th, int x, int y)
{
final CollisionFunction function = formula.getFunction();
final CollisionRange range = formula.getRange();
switch (range.getOutput())
{
case X:
renderX(... | java |
private static void renderX(Graphic g, CollisionFunction function, CollisionRange range, int th, int y)
{
if (UtilMath.isBetween(y, range.getMinY(), range.getMaxY()))
{
g.drawRect(function.getRenderX(y), th - y - 1, 0, 0, false);
}
} | java |
private static void renderY(Graphic g, CollisionFunction function, CollisionRange range, int th, int x)
{
if (UtilMath.isBetween(x, range.getMinX(), range.getMaxX()))
{
g.drawRect(x, th - function.getRenderY(x) - 1, 0, 0, false);
}
} | java |
private void renderCollision(Graphic g, TileCollision tile, int x, int y)
{
for (final CollisionFormula collision : tile.getCollisionFormulas())
{
final ImageBuffer buffer = collisionCache.get(collision);
if (buffer != null)
{
g.drawImage(bu... | java |
public final void setScreenSize(int width, int height)
{
screenWidth = width;
screenHeight = height;
final double scaleH = width / (double) Scene.NATIVE.getWidth();
final double scaleV = height / (double) Scene.NATIVE.getHeight();
this.scaleH = scaleH;
this.scaleV = s... | java |
public static List<LauncherConfig> imports(Configurer configurer)
{
Check.notNull(configurer);
final Collection<Xml> children = configurer.getRoot().getChildren(NODE_LAUNCHER);
final List<LauncherConfig> launchers = new ArrayList<>(children.size());
for (final Xml launcher :... | java |
public static LauncherConfig imports(Xml node)
{
Check.notNull(node);
final Collection<Xml> children = node.getChildren(LaunchableConfig.NODE_LAUNCHABLE);
final Collection<LaunchableConfig> launchables = new ArrayList<>(children.size());
for (final Xml launchable : children)... | java |
public static Xml exports(LauncherConfig config)
{
Check.notNull(config);
final Xml node = new Xml(NODE_LAUNCHER);
node.writeInteger(ATT_RATE, config.getRate());
for (final LaunchableConfig launchable : config.getLaunchables())
{
node.add(LaunchableConf... | java |
public static CollisionRange imports(XmlReader node)
{
Check.notNull(node);
final String axisName = node.readString(ATT_AXIS);
try
{
final Axis axis = Axis.valueOf(axisName);
final int minX = node.readInteger(ATT_MIN_X);
final int maxX = ... | java |
public static void exports(Xml root, CollisionRange range)
{
Check.notNull(root);
Check.notNull(range);
final Xml node = root.createChild(NODE_RANGE);
node.writeString(ATT_AXIS, range.getOutput().name());
node.writeInteger(ATT_MIN_X, range.getMinX());
node.wr... | java |
private void computeFrameRate(Timing updateFpsTimer, long lastTime, long currentTime)
{
if (updateFpsTimer.elapsed(Constant.ONE_SECOND_IN_MILLI))
{
currentFrameRate = (int) Math.round(Constant.ONE_SECOND_IN_NANO / (double) (currentTime - lastTime));
updateFpsTimer.restart();
... | java |
protected final void render(Graphic g, int x, int y, int w, int h, int ox, int oy)
{
if (Mirror.HORIZONTAL == mirror)
{
g.drawImage(surface, x, y, x + w, y + h, ox * w + w, oy * h, ox * w, oy * h + h);
}
else if (Mirror.VERTICAL == mirror)
{
g.drawImag... | java |
protected void stretch(int newWidth, int newHeight)
{
width = newWidth;
height = newHeight;
surface = Graphics.resize(surfaceOriginal, newWidth, newHeight);
} | java |
private boolean isTileNotAvailable(Pathfindable mover, int ctx, int cty, Integer ignoreObjectId)
{
final Collection<Integer> ids = getObjectsId(ctx, cty);
final Tile tile = map.getTile(ctx, cty);
if (tile != null)
{
final TilePath tilePath = tile.getFeature(TilePath.class... | java |
private boolean isBlocked(Pathfindable mover, int tx, int ty)
{
final Collection<Integer> ids = getObjectsId(tx, ty);
int ignoredCount = 0;
for (final Integer id : ids)
{
if (mover.isIgnoredId(id))
{
ignoredCount++;
}
}
... | java |
private boolean isTileBlocked(Pathfindable mover, int tx, int ty)
{
final Tile tile = map.getTile(tx, ty);
if (tile != null)
{
final TilePath tilePath = tile.getFeature(TilePath.class);
return mover.isBlocking(tilePath.getCategory());
}
return false;
... | java |
private CoordTile getClosestAvailableTile(Pathfindable mover,
int stx,
int sty,
int stw,
int sth,
... | java |
private CoordTile getFreeTileAround(Pathfindable mover, int tx, int ty, int tw, int th, int radius, Integer id)
{
for (int ctx = tx - radius; ctx <= tx + radius; ctx++)
{
for (int cty = ty - radius; cty <= ty + radius; cty++)
{
if (isAreaAvailable(mover, ctx, ... | java |
private String getCategory(String group)
{
for (final PathCategory category : categories.values())
{
if (category.getGroups().contains(group))
{
return category.getName();
}
}
return null;
} | java |
public void setLocation(int x, int y)
{
screenX = UtilMath.clamp(x, minX, maxX);
screenY = UtilMath.clamp(y, minY, maxY);
} | java |
public void setArea(int minX, int minY, int maxX, int maxY)
{
this.minX = Math.min(minX, maxX);
this.minY = Math.min(minY, maxY);
this.maxX = Math.max(maxX, minX);
this.maxY = Math.max(maxY, minY);
} | java |
public void setGrid(int width, int height)
{
Check.superiorStrict(width, 0);
Check.superiorStrict(height, 0);
gridWidth = width;
gridHeight = height;
} | java |
private static double getRasterFactor(int i, RasterData data)
{
Check.notNull(data);
final double force = data.getForce();
final double amplitude = data.getAmplitude();
final int offset = data.getOffset();
if (0 == data.getType())
{
return forc... | java |
public void loadRasters(int imageHeight, boolean save, String prefix)
{
Check.notNull(prefix);
final Raster raster = Raster.load(rasterFile);
final int max = UtilConversion.boolToInt(rasterSmooth) + 1;
for (int m = 0; m < max; m++)
{
for (int i = 0; i <... | java |
public ImageBuffer getRaster(int id)
{
return rasters.get(UtilMath.clamp(id, 0, rasters.size() - 1));
} | java |
private ImageBuffer createRaster(Media rasterMedia, Raster raster, int i, boolean save)
{
final ImageBuffer rasterBuffer;
if (rasterMedia.exists())
{
rasterBuffer = Graphics.getImageBuffer(rasterMedia);
rasterBuffer.prepare();
}
else
{... | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.