Search in sources :

Example 11 with Vector4f

use of org.joml.Vector4f in project chunkstories by Hugobros3.

the class ConnectionOverlay method render.

@Override
public void render(RenderingInterface renderingContext) {
    parentLayer.getRootLayer().render(renderingContext);
    String color = "#606060";
    Font font = renderingContext.getFontRenderer().getFont("LiberationSans-Regular", 11);
    String connection = "Connecting, please wait";
    renderingContext.getFontRenderer().drawStringWithShadow(font, renderingContext.getWindow().getWidth() / 2 - font.getWidth(connection) * 1.5f, renderingContext.getWindow().getHeight() / 2 + 48 * 3, connection, 3, 3, new Vector4f(1));
    String currentConnectionStep = connectionSequence.getStatus().getStepText();
    renderingContext.getFontRenderer().drawStringWithShadow(font, renderingContext.getWindow().getWidth() / 2 - font.getWidth(currentConnectionStep) * 1.5f, renderingContext.getWindow().getHeight() / 2 + 32 * 3, color + currentConnectionStep, 3, 3, new Vector4f(1));
    exitButton.setPosition(renderingContext.getWindow().getWidth() / 2 - exitButton.getWidth() / 2, renderingContext.getWindow().getHeight() / 2 - 24);
    exitButton.render(renderingContext);
    // Once the connection sequence is done, we hide this overlay
    if (connectionSequence.isDone())
        this.gameWindow.setLayer(parentLayer);
    String fail = connectionSequence.wasAborted();
    if (fail != null)
        Client.getInstance().exitToMainMenu(fail);
}
Also used : Vector4f(org.joml.Vector4f) Font(io.xol.chunkstories.api.rendering.text.FontRenderer.Font)

Example 12 with Vector4f

use of org.joml.Vector4f in project chunkstories by Hugobros3.

the class DeathScreen method render.

@Override
public void render(RenderingInterface renderer) {
    parentLayer.render(renderer);
    renderer.getGuiRenderer().drawBoxWindowsSpace(0, 0, renderer.getWindow().getWidth(), renderer.getWindow().getHeight(), 0, 0, 0, 0, null, false, true, new Vector4f(0.0f, 0.0f, 0.0f, 0.5f));
    String color = "#";
    color += HexTools.intToHex((int) (Math.random() * 255));
    color += HexTools.intToHex((int) (Math.random() * 255));
    color += HexTools.intToHex((int) (Math.random() * 255));
    Font font = renderer.getFontRenderer().getFont("LiberationSans-Regular", 11);
    renderer.getFontRenderer().drawStringWithShadow(font, renderer.getWindow().getWidth() / 2 - font.getWidth("YOU DIEDED") * 3f, renderer.getWindow().getHeight() / 2 + 48 * 3, "#FF0000YOU DIEDED", 6, 6, new Vector4f(1));
    renderer.getFontRenderer().drawStringWithShadow(font, renderer.getWindow().getWidth() / 2 - font.getWidth("git --gud scrub") * 1.5f, renderer.getWindow().getHeight() / 2 + 36 * 3, color + "git --gud scrub", 3, 3, new Vector4f(1));
    respawnButton.setPosition(renderer.getWindow().getWidth() / 2 - respawnButton.getWidth() / 2, renderer.getWindow().getHeight() / 2 + 48);
    exitButton.setPosition(renderer.getWindow().getWidth() / 2 - exitButton.getWidth() / 2, renderer.getWindow().getHeight() / 2 - 24);
    respawnButton.render(renderer);
    exitButton.render(renderer);
    // When the new entity arrives
    if (Client.getInstance().getPlayer().getControlledEntity() != null)
        gameWindow.setLayer(parentLayer);
    // Make sure to ungrab the mouse
    Mouse mouse = gameWindow.getInputsManager().getMouse();
    if (mouse.isGrabbed())
        mouse.setGrabbed(false);
}
Also used : Vector4f(org.joml.Vector4f) Mouse(io.xol.chunkstories.api.input.Mouse) Font(io.xol.chunkstories.api.rendering.text.FontRenderer.Font)

Example 13 with Vector4f

use of org.joml.Vector4f in project chunkstories by Hugobros3.

the class InventoryView method render.

@Override
public void render(RenderingInterface renderer) {
    parentLayer.render(renderer);
    Mouse mouse = renderer.getClient().getInputsManager().getMouse();
    int totalWidth = 0;
    for (Inventory inv : inventories) totalWidth += 2 + inv.getWidth();
    totalWidth -= 2;
    int widthAccumulation = 0;
    for (int i = 0; i < drawers.length; i++) {
        int thisWidth = inventories[i].getWidth();
        drawers[i].drawInventoryCentered(renderer, renderer.getWindow().getWidth() / 2 - totalWidth * 24 + thisWidth * 24 + widthAccumulation * 48, renderer.getWindow().getHeight() / 2, 2, false, 4 - i * 4);
        widthAccumulation += 1 + thisWidth;
        int[] highlightedSlot = drawers[i].getSelectedSlot();
        if (highlightedSlot != null) {
            ItemPile pileHighlighted = inventories[i].getItemPileAt(highlightedSlot[0], highlightedSlot[1]);
            if (pileHighlighted != null) {
                float mx = (float) mouse.getCursorX();
                float my = (float) mouse.getCursorY();
                renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), mx, my, pileHighlighted.getItem().getName(), 2, 2, new Vector4f(1.0f));
            // System.out.println(pileHighlighted);
            }
        }
    }
    if (selectedItem != null) {
        int slotSize = 24 * 2;
        int width = slotSize * selectedItem.getItem().getDefinition().getSlotsWidth();
        int height = slotSize * selectedItem.getItem().getDefinition().getSlotsHeight();
        selectedItem.getItem().getDefinition().getRenderer().renderItemInInventory(renderer, selectedItem, (float) mouse.getCursorX() - width / 2, (float) mouse.getCursorY() - height / 2, 2);
        if (selectedItemAmount != 1)
            renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), (float) mouse.getCursorX() - width / 2 + (selectedItem.getItem().getDefinition().getSlotsWidth() - 1.0f) * slotSize, (float) mouse.getCursorY() - height / 2, selectedItemAmount + "", 2, 2, new Vector4f(1, 1, 1, 1));
    }
}
Also used : Mouse(io.xol.chunkstories.api.input.Mouse) Vector4f(org.joml.Vector4f) PacketInventoryMoveItemPile(io.xol.chunkstories.api.net.packets.PacketInventoryMoveItemPile) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile) Inventory(io.xol.chunkstories.api.item.inventory.Inventory)

Example 14 with Vector4f

use of org.joml.Vector4f in project chunkstories by Hugobros3.

the class DebugInfoRenderer method drawF3debugMenu.

public void drawF3debugMenu(RenderingInterface renderingInterface) {
    CameraInterface camera = renderingInterface.getCamera();
    Entity playerEntity = client.getPlayer().getControlledEntity();
    /*int timeTook = Client.profiler.timeTook();
		String debugInfo = Client.profiler.reset("gui").toString();
		if (timeTook > 400)
			System.out.println("Lengty frame, printing debug information : \n" + debugInfo);*/
    // Memory usage
    long total = Runtime.getRuntime().totalMemory();
    long used = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
    // By default use the camera position
    int bx = ((int) camera.getCameraPosition().x());
    int by = ((int) camera.getCameraPosition().y());
    int bz = ((int) camera.getCameraPosition().z());
    int lx = bx, ly = by, lz = bz;
    // If the player can look use that
    if (playerEntity != null && playerEntity instanceof EntityControllable) {
        Location loc = ((EntityControllable) playerEntity).getBlockLookingAt(true);
        if (loc != null) {
            lx = (int) loc.x();
            ly = (int) loc.y();
            lz = (int) loc.z();
        }
    }
    int raw_data = world.peekRaw(lx, ly, lz);
    CellData cell = world.peekSafely(lx, ly, lz);
    // System.out.println(VoxelFormat.id(raw_data));
    int cx = bx / 32;
    int cy = by / 32;
    int cz = bz / 32;
    int csh = world.getRegionsSummariesHolder().getHeightAtWorldCoordinates(bx, bz);
    // Obtain the angle the player is facing
    VoxelSide side = VoxelSide.TOP;
    float angleX = -1;
    if (playerEntity != null && playerEntity instanceof EntityLiving)
        angleX = Math.round(((EntityLiving) playerEntity).getEntityRotationComponent().getHorizontalRotation());
    double dx = Math.sin(angleX / 360 * 2.0 * Math.PI);
    double dz = Math.cos(angleX / 360 * 2.0 * Math.PI);
    if (Math.abs(dx) > Math.abs(dz)) {
        if (dx > 0)
            side = VoxelSide.RIGHT;
        else
            side = VoxelSide.LEFT;
    } else {
        if (dz > 0)
            side = VoxelSide.FRONT;
        else
            side = VoxelSide.BACK;
    }
    // Count all the entities
    int ec = 0;
    IterableIterator<Entity> i = world.getAllLoadedEntities();
    while (i.hasNext()) {
        i.next();
        ec++;
    }
    Chunk current = world.getChunk(cx, cy, cz);
    int x_top = renderingInterface.getWindow().getHeight() - 16;
    Font font = null;
    font = renderingInterface.getFontRenderer().getFont("LiberationSans-Regular", 12);
    if (font == null)
        font = renderingInterface.getFontRenderer().getFont("LiberationSans-Regular", 12);
    int lineHeight = font.getLineHeight();
    int posx, posy;
    String text;
    posx = 8;
    posy = x_top - posx;
    text = GLCalls.getStatistics() + " Chunks in view : " + world.getWorldRenderer().getChunksRenderer().getChunksVisible() + " Entities " + ec + " Particles :" + ((ClientParticlesRenderer) world.getParticlesManager()).count() + " #FF0000Render FPS: " + Client.getInstance().getGameWindow().getFPS() + " avg: " + Math.floor(10000.0 / Client.getInstance().getGameWindow().getFPS()) / 10.0 + " #00FFFFSimulation FPS: " + world.getWorldRenderer().getWorld().getGameLogic().getSimulationFps();
    renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
    posy -= lineHeight;
    text = "RAM usage : " + used / 1024 / 1024 + " / " + total / 1024 / 1024 + " MB used, chunks loaded in ram: " + world.getRegionsHolder().countChunksWithData() + "/" + world.getRegionsHolder().countChunks() + " " + Math.floor(world.getRegionsHolder().countChunksWithData() * 4 * 32 * 32 * 32 / (1024L * 1024 / 100f)) / 100f + "MB used by chunks";
    renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
    long totalVram = (renderingInterface.getTotalVramUsage()) / 1024 / 1024;
    posy -= lineHeight;
    text = "VRAM usage : " + totalVram + "MB as " + Texture2DGL.getTotalNumberOfTextureObjects() + " textures using " + Texture2DGL.getTotalVramUsage() / 1024 / 1024 + "MB + " + VertexBufferGL.getTotalNumberOfVerticesObjects() + " vbos using " + renderingInterface.getVertexDataVramUsage() / 1024 / 1024 + " MB";
    renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
    posy -= lineHeight;
    text = "Worker threads: " + world.getGameContext().tasks() + " - " + world.ioHandler.toString();
    renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
    posy -= lineHeight;
    text = "Position : x:" + bx + " y:" + by + " z:" + bz + " dir: " + angleX + " side: " + side + " #FF0000Block looking at#FFFFFF : pos: " + lx + ": " + ly + ": " + lz + " data: " + raw_data + " voxel_type: " + cell.getVoxel().getName() + " sl:" + cell.getSunlight() + " bl: " + cell.getBlocklight() + " meta:" + cell.getMetaData() + " csh:" + csh;
    renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
    posy -= lineHeight;
    text = "Current Summary : " + world.getRegionsSummariesHolder().getHeightmapChunkCoordinates(cx, cz);
    renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
    posy -= lineHeight;
    text = "Current Region : " + world.getRegionChunkCoordinates(cx, cy, cz);
    renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
    if (current == null) {
        posy -= lineHeight;
        text = "Current chunk null";
        renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
    } else if (current instanceof ChunkRenderable) {
        ChunkRenderDataHolder chunkRenderData = ((ClientChunk) current).getChunkRenderData();
        if (chunkRenderData != null) {
            posy -= lineHeight;
            text = "Current Chunk : " + current + " - " + chunkRenderData.toString();
            renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
        } else {
            posy -= lineHeight;
            text = "Current Chunk : " + current + " - No rendering data";
            renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
        }
    }
    if (playerEntity != null && playerEntity instanceof Entity) {
        posy -= lineHeight;
        text = "Controlled Entity : " + playerEntity;
        renderingInterface.getFontRenderer().drawStringWithShadow(font, posx, posy, text, 1, 1, new Vector4f(1));
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) VoxelSide(io.xol.chunkstories.api.voxel.VoxelSide) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) ChunkRenderable(io.xol.chunkstories.api.rendering.world.chunk.ChunkRenderable) Chunk(io.xol.chunkstories.api.world.chunk.Chunk) ClientChunk(io.xol.chunkstories.world.chunk.ClientChunk) CellData(io.xol.chunkstories.api.world.cell.CellData) Font(io.xol.chunkstories.api.rendering.text.FontRenderer.Font) ChunkRenderDataHolder(io.xol.chunkstories.renderer.chunks.ChunkRenderDataHolder) Vector4f(org.joml.Vector4f) CameraInterface(io.xol.chunkstories.api.rendering.CameraInterface) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) Location(io.xol.chunkstories.api.Location) ClientParticlesRenderer(io.xol.chunkstories.renderer.particles.ClientParticlesRenderer)

Example 15 with Vector4f

use of org.joml.Vector4f in project chunkstories by Hugobros3.

the class PhysicsWireframeDebugger method render.

public void render(RenderingInterface renderer) {
    Vector3dc cameraPosition = renderer.getCamera().getCameraPosition();
    // int id, data;
    int drawDebugDist = 6;
    // Iterate over nearby voxels
    for (int i = ((int) (double) cameraPosition.x()) - drawDebugDist; i <= ((int) (double) cameraPosition.x()) + drawDebugDist; i++) for (int j = ((int) (double) cameraPosition.y()) - drawDebugDist; j <= ((int) (double) cameraPosition.y()) + drawDebugDist; j++) for (int k = ((int) (double) cameraPosition.z()) - drawDebugDist; k <= ((int) (double) cameraPosition.z()) + drawDebugDist; k++) {
        // data = world.peekSimple(i, j, k);
        // id = VoxelFormat.id(data);
        CellData cell = world.peekSafely(i, j, k);
        // System.out.println(i+":"+j+":"+k);
        // System.out.println(cell.getX() + ":"+cell.getY()+":"+cell.getZ());
        CollisionBox[] tboxes = cell.getTranslatedCollisionBoxes();
        // System.out.println(tboxes.length);
        if (tboxes != null) {
            // Draw all their collision boxes
            for (CollisionBox box : tboxes) {
                if (cell.getVoxel().getDefinition().isSolid())
                    // Red if solid
                    FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(1, 0, 0, 1.0f));
                else
                    // Yellow otherwise
                    FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(1, 1, 0, 0.25f));
            }
        }
    }
    // Iterate over each entity
    Iterator<Entity> ie = world.getAllLoadedEntities();
    while (ie.hasNext()) {
        Entity e = ie.next();
        // Entities with hitboxes see all of those being drawn
        if (e instanceof EntityLiving) {
            EntityLiving eli = (EntityLiving) e;
            for (HitBox hitbox : eli.getHitBoxes()) {
                hitbox.draw(renderer);
            }
        }
        // Get the entity bounding box
        if (e.getTranslatedBoundingBox().lineIntersection(cameraPosition, new Vector3d(renderer.getCamera().getViewDirection())) != null)
            FakeImmediateModeDebugRenderer.renderCollisionBox(e.getTranslatedBoundingBox(), new Vector4f(0, 0, 0.5f, 1.0f));
        else
            FakeImmediateModeDebugRenderer.renderCollisionBox(e.getTranslatedBoundingBox(), new Vector4f(0, 1f, 1f, 1.0f));
        // And the collision box
        for (CollisionBox box : e.getCollisionBoxes()) {
            box.translate(e.getLocation());
            FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(0, 1, 0.5f, 1.0f));
        }
    }
}
Also used : Vector3dc(org.joml.Vector3dc) Entity(io.xol.chunkstories.api.entity.Entity) HitBox(io.xol.chunkstories.api.entity.EntityLiving.HitBox) Vector4f(org.joml.Vector4f) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) Vector3d(org.joml.Vector3d) CellData(io.xol.chunkstories.api.world.cell.CellData) CollisionBox(io.xol.chunkstories.api.physics.CollisionBox)

Aggregations

Vector4f (org.joml.Vector4f)68 Vector3f (org.joml.Vector3f)13 Font (io.xol.chunkstories.api.rendering.text.FontRenderer.Font)12 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)6 Vector3d (org.joml.Vector3d)6 Shader (io.xol.chunkstories.api.rendering.shader.Shader)5 CellData (io.xol.chunkstories.api.world.cell.CellData)5 Vector2f (org.joml.Vector2f)5 Mouse (io.xol.chunkstories.api.input.Mouse)4 Texture2DGL (io.xol.chunkstories.renderer.opengl.texture.Texture2DGL)4 ByteBuffer (java.nio.ByteBuffer)4 Matrix4f (org.joml.Matrix4f)4 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)3 STBEasyFont.stb_easy_font_print (org.lwjgl.stb.STBEasyFont.stb_easy_font_print)3 Location (io.xol.chunkstories.api.Location)2 Entity (io.xol.chunkstories.api.entity.Entity)2 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)2 GuiRenderer (io.xol.chunkstories.api.gui.GuiRenderer)2 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)2 Voxel (io.xol.chunkstories.api.voxel.Voxel)2