use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class BlockArea method iterator.
// -- ITERABLE ---------------------------------------------------------------------------------------------------//
/**
* Iterates over each position in the BlockArea, in x-first order.
* For example: (0, 0), (1, 0), (2, 0), (0, 1), (1, 1), ...
*/
@Override
public Iterator<Vector2ic> iterator() {
return new Iterator<Vector2ic>() {
private Vector2i current = null;
private final Vector2i next = getMin(new Vector2i());
public boolean findNext() {
if (current.equals(next)) {
next.x++;
if (next.x > maxX) {
next.x = minX;
next.y++;
}
return contains(next);
}
return true;
}
@Override
public boolean hasNext() {
if (!isValid()) {
return false;
}
if (current == null) {
return true;
}
if (current.equals(next)) {
return findNext();
}
return contains(next);
}
@Override
public Vector2ic next() {
if (current == null) {
current = new Vector2i(next);
return next;
}
if (current.equals(next)) {
if (findNext()) {
current.set(next);
return next;
}
return null;
}
current.set(next);
return next;
}
};
}
use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class LayeredZoneRegionFunction method getLayerRange.
private LayerRange getLayerRange(int x, int z, Region region) {
Vector2i pos = new Vector2i(x, z);
if (!layerRangeMap.containsKey(pos)) {
int surfaceHeight = (int) Math.floor(region.getFacet(ElevationFacet.class).getWorld(pos));
boolean aboveground = ordering > 0;
int cumulativeDistanceSmall = 0;
int cumulativeDistanceLarge = 0;
LayerRange layerRange = null;
List<LayeredZoneRegionFunction> layers = aboveground ? abovegroundLayers : undergroundLayers;
int layerIndex;
for (layerIndex = 0; layerIndex < layers.size(); layerIndex++) {
LayeredZoneRegionFunction currentLayer = layers.get(layerIndex);
int thickness = currentLayer.layerThickness.get(x, z);
cumulativeDistanceLarge += thickness;
if (this.equals(currentLayer)) {
if (aboveground) {
layerRange = new LayerRange().setMin(surfaceHeight + cumulativeDistanceSmall).setMax(surfaceHeight + cumulativeDistanceLarge);
break;
} else {
layerRange = new LayerRange().setMin(surfaceHeight - cumulativeDistanceLarge).setMax(surfaceHeight - cumulativeDistanceSmall);
break;
}
}
cumulativeDistanceSmall += thickness;
}
if (layers.size() <= 0 || layerRange == null) {
throw new IllegalStateException("Layer for zone '" + parent + "' not found in list of " + (aboveground ? "aboveground" : "underground") + " layers.");
}
if (layerIndex == layers.size() - 1) {
// At one of the edge layers
if (aboveground) {
layerRange.unsetMax();
} else {
layerRange.unsetMin();
}
}
layerRangeMap.put(pos, layerRange);
}
return layerRangeMap.get(pos);
}
use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class BlockSelectionRenderSystem method renderOverlay.
@Override
public void renderOverlay() {
for (EntityRef entity : entityManager.getEntitiesWith(BlockSelectionComponent.class)) {
BlockSelectionComponent blockSelectionComponent = entity.getComponent(BlockSelectionComponent.class);
if (blockSelectionComponent.shouldRender) {
Texture texture = blockSelectionComponent.texture;
if (null == texture) {
texture = Assets.getTexture("engine:selection").get();
}
Vector2i textureDimensions = new Vector2i(texture.getWidth(), texture.getHeight());
BlockSelectionRenderer selectionRenderer = cachedBlockSelectionRendererByTextureDimensionsMap.get(textureDimensions);
if (null == selectionRenderer) {
selectionRenderer = new BlockSelectionRenderer(texture);
cachedBlockSelectionRendererByTextureDimensionsMap.put(textureDimensions, selectionRenderer);
} else {
selectionRenderer.setEffectsTexture(texture);
}
renderOverlayForOneBlockSelection(blockSelectionComponent, selectionRenderer);
}
}
}
use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class BehaviorEditor method drawConnection.
private void drawConnection(Canvas canvas, Vector2f from, Vector2f to, Color color) {
Vector2i s = worldToScreen(from);
Vector2i e = worldToScreen(to);
canvas.drawLine(s.x, s.y, e.x, e.y, color);
}
use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class LwjglCanvasRenderer method drawText.
@Override
public void drawText(String text, Font font, HorizontalAlign hAlign, VerticalAlign vAlign, Rectanglei absoluteRegionRectangle, Colorc color, Colorc shadowColor, float alpha, boolean underlined) {
Rectanglei absoluteRegion = new Rectanglei(absoluteRegionRectangle);
TextCacheKey key = new TextCacheKey(text, font, absoluteRegion.getSizeX(), hAlign, color, shadowColor, underlined);
usedText.add(key);
Map<Material, Mesh> fontMesh = cachedText.get(key);
List<String> lines = TextLineBuilder.getLines(font, text, absoluteRegion.getSizeX());
if (fontMesh != null) {
for (Mesh mesh : fontMesh.values()) {
if (mesh.isDisposed()) {
fontMesh = null;
break;
}
}
}
if (fontMesh == null) {
fontMesh = fontMeshBuilder.createTextMesh((org.terasology.engine.rendering.assets.font.Font) font, lines, absoluteRegion.getSizeX(), hAlign, color, shadowColor, underlined);
cachedText.put(key, fontMesh);
}
Vector2i offset = new Vector2i(absoluteRegion.minX, absoluteRegion.minY);
offset.y += vAlign.getOffset(lines.size() * font.getLineHeight(), absoluteRegion.lengthY());
fontMesh.entrySet().stream().filter(entry -> entry.getKey().isRenderable()).forEach(entry -> {
entry.getKey().bindTextures();
entry.getKey().setMatrix4("projectionMatrix", projMatrix);
entry.getKey().setMatrix4("modelViewMatrix", modelMatrixStack);
entry.getKey().setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX, requestedCropRegion.maxX, requestedCropRegion.minY, requestedCropRegion.maxY);
entry.getKey().setFloat2("offset", offset.x, offset.y);
entry.getKey().setFloat("alpha", alpha);
entry.getValue().render();
});
}
Aggregations