Search in sources :

Example 21 with Vector2i

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;
        }
    };
}
Also used : Iterator(java.util.Iterator) Vector2i(org.joml.Vector2i)

Example 22 with Vector2i

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);
}
Also used : Vector2i(org.joml.Vector2i) ElevationFacet(org.terasology.engine.world.generation.facets.ElevationFacet)

Example 23 with Vector2i

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);
        }
    }
}
Also used : BlockSelectionComponent(org.terasology.engine.world.selection.BlockSelectionComponent) Vector2i(org.joml.Vector2i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Texture(org.terasology.engine.rendering.assets.texture.Texture)

Example 24 with Vector2i

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);
}
Also used : Vector2i(org.joml.Vector2i)

Example 25 with Vector2i

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();
    });
}
Also used : Quaternionf(org.joml.Quaternionf) GL11.glDisable(org.lwjgl.opengl.GL11.glDisable) GL11.glViewport(org.lwjgl.opengl.GL11.glViewport) Vector2ic(org.joml.Vector2ic) DisplayDevice(org.terasology.engine.core.subsystem.DisplayDevice) UITextureRegion(org.terasology.nui.UITextureRegion) Map(java.util.Map) Vector3f(org.joml.Vector3f) GL11(org.lwjgl.opengl.GL11) TeraMath(org.terasology.math.TeraMath) VerticalAlign(org.terasology.nui.VerticalAlign) Quaternionfc(org.joml.Quaternionfc) FrameBufferObject(org.terasology.engine.rendering.opengl.FrameBufferObject) GL_SRC_ALPHA(org.lwjgl.opengl.GL11.GL_SRC_ALPHA) RenderingConfig(org.terasology.engine.config.RenderingConfig) GL_DEPTH_TEST(org.lwjgl.opengl.GL11.GL_DEPTH_TEST) TextLineBuilder(org.terasology.nui.TextLineBuilder) Set(java.util.Set) ScaleMode(org.terasology.nui.ScaleMode) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) MeshBuilder(org.terasology.engine.rendering.assets.mesh.MeshBuilder) List(java.util.List) Context(org.terasology.engine.context.Context) TextureRegion(org.terasology.engine.rendering.assets.texture.TextureRegion) Vector2i(org.joml.Vector2i) Border(org.terasology.nui.Border) PropertyChangeListener(java.beans.PropertyChangeListener) Vector2f(org.joml.Vector2f) Matrix3f(org.joml.Matrix3f) LwjglFrameBufferObject(org.terasology.engine.rendering.opengl.LwjglFrameBufferObject) Matrix4fStack(org.joml.Matrix4fStack) Rectanglef(org.terasology.joml.geom.Rectanglef) Rectanglei(org.terasology.joml.geom.Rectanglei) Colorc(org.terasology.nui.Colorc) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) AABBfc(org.terasology.joml.geom.AABBfc) GL11.glClear(org.lwjgl.opengl.GL11.glClear) Font(org.terasology.nui.asset.font.Font) Matrix4f(org.joml.Matrix4f) FontMeshBuilder(org.terasology.engine.rendering.assets.font.FontMeshBuilder) PropertyChangeEvent(java.beans.PropertyChangeEvent) AssetManager(org.terasology.gestalt.assets.management.AssetManager) GL11.glEnable(org.lwjgl.opengl.GL11.glEnable) Assets(org.terasology.engine.utilities.Assets) Iterator(java.util.Iterator) Maps(com.google.common.collect.Maps) GL11.glBlendFunc(org.lwjgl.opengl.GL11.glBlendFunc) GL_ONE_MINUS_SRC_ALPHA(org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA) Vector3fc(org.joml.Vector3fc) Config(org.terasology.engine.config.Config) Material(org.terasology.engine.rendering.assets.material.Material) GL_BLEND(org.lwjgl.opengl.GL11.GL_BLEND) Mesh(org.terasology.engine.rendering.assets.mesh.Mesh) HorizontalAlign(org.terasology.nui.HorizontalAlign) Mesh(org.terasology.engine.rendering.assets.mesh.Mesh) Material(org.terasology.engine.rendering.assets.material.Material) Rectanglei(org.terasology.joml.geom.Rectanglei) Font(org.terasology.nui.asset.font.Font) Vector2i(org.joml.Vector2i)

Aggregations

Vector2i (org.joml.Vector2i)41 Test (org.junit.jupiter.api.Test)12 Rectanglei (org.terasology.joml.geom.Rectanglei)9 Canvas (org.terasology.nui.Canvas)9 UILabel (org.terasology.nui.widgets.UILabel)6 List (java.util.List)5 Objects (java.util.Objects)5 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)5 Vector2f (org.joml.Vector2f)4 Vector2ic (org.joml.Vector2ic)4 Module (org.terasology.gestalt.module.Module)4 Name (org.terasology.gestalt.naming.Name)4 UIButton (org.terasology.nui.widgets.UIButton)4 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Collection (java.util.Collection)3 Comparator (java.util.Comparator)3 Iterator (java.util.Iterator)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3