Search in sources :

Example 1 with Layer

use of io.xol.chunkstories.api.gui.Layer in project chunkstories by Hugobros3.

the class Lwjgl3ClientInputsManager method onInputPressed.

public boolean onInputPressed(Input input) {
    if (input.equals("fullscreen")) {
        gameWindow.toggleFullscreen();
        return true;
    }
    // System.out.println("Input pressed "+input.getName());
    // Try the client-side event press
    ClientInputPressedEvent event = new ClientInputPressedEvent(gameWindow.getClient(), input);
    ClientPluginManager cpm = gameWindow.getClient().getPluginManager();
    if (cpm != null) {
        cpm.fireEvent(event);
        if (event.isCancelled())
            return false;
    }
    // Try the GUI handling
    Layer layer = gameWindow.getLayer();
    if (layer.handleInput(input))
        return true;
    // System.out.println("wasn't handled");
    final LocalPlayer player = Client.getInstance().getPlayer();
    if (player == null)
        return false;
    final EntityControllable entityControlled = player.getControlledEntity();
    // There has to be a controlled entity for sending inputs to make sense.
    if (entityControlled == null)
        return false;
    // Send input to server
    World world = entityControlled.getWorld();
    if (world instanceof WorldClientRemote) {
        // MouseScroll inputs are strictly client-side
        if (!(input instanceof MouseScroll)) {
            ServerConnection connection = ((WorldClientRemote) entityControlled.getWorld()).getConnection();
            PacketInput packet = new PacketInput(world);
            packet.input = input;
            packet.isPressed = true;
            connection.pushPacket(packet);
        }
        return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
    } else {
        PlayerInputPressedEvent event2 = new PlayerInputPressedEvent(Client.getInstance().getPlayer(), input);
        cpm.fireEvent(event2);
        if (event2.isCancelled())
            return false;
    // entity.handleInteraction(input, entity.getControllerComponent().getController());
    }
    // Handle interaction locally
    return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
}
Also used : ClientPluginManager(io.xol.chunkstories.api.plugin.ClientPluginManager) PacketInput(io.xol.chunkstories.net.packets.PacketInput) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) ServerConnection(io.xol.chunkstories.client.net.ServerConnection) ClientInputPressedEvent(io.xol.chunkstories.api.events.client.ClientInputPressedEvent) World(io.xol.chunkstories.api.world.World) Layer(io.xol.chunkstories.api.gui.Layer) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) MouseScroll(io.xol.chunkstories.api.input.Mouse.MouseScroll) PlayerInputPressedEvent(io.xol.chunkstories.api.events.player.PlayerInputPressedEvent)

Example 2 with Layer

use of io.xol.chunkstories.api.gui.Layer in project chunkstories by Hugobros3.

the class GLFWGameWindow method run.

public void run() {
    try {
        // Client.onStart();
        new IconLoader(this);
        // Resize window logic
        glfwSetFramebufferSizeCallback(glfwWindowHandle, (framebufferSizeCallback = new GLFWFramebufferSizeCallback() {

            @Override
            public void invoke(long window, int width, int height) {
                windowWidth = width;
                windowHeight = height;
                glViewport(0, 0, width, height);
                Layer layer = GLFWGameWindow.this.layer;
                while (layer != null) {
                    layer.onResize(width, height);
                    layer = layer.getParentLayer();
                }
            }
        }));
        while (glfwWindowShouldClose(glfwWindowHandle) == false && !closeRequest) {
            // Update pending actions
            vramUsageVerticesObjects = VertexBufferGL.updateVerticesObjects();
            Texture2DGL.updateTextureObjects();
            FrameBufferObjectGL.updateFrameBufferObjects();
            // Clear windows
            renderingContext.getRenderTargetManager().clearBoundRenderTargetAll();
            // Do scene changes etc
            Iterator<SynchronousTask> is = mainThreadQueue.iterator();
            while (is.hasNext()) {
                SynchronousTask st = is.next();
                st.run.run();
                st.signal();
                is.remove();
            }
            /*for (Runnable r : mainThreadQueue)
					r.run();
				mainThreadQueue.clear();*/
            // Update audio
            soundManager.update();
            // update inputs first
            client.getInputsManager().pollLWJGLInputs();
            // Run scene content
            if (layer != null) {
                // then do the game logic
                try {
                    layer.render(renderingContext);
                }// Fucking tired of handling npes everywhere
                 catch (NullPointerException npe) {
                    npe.printStackTrace();
                }
            }
            renderingContext.getGuiRenderer().drawBuffer();
            tick();
            // Clamp fps
            int targetFPS = this.client.getConfiguration().getIntOption("client.video.framerateCap");
            if (targetFPS != -1) {
                // long time = System.currentTimeMillis();
                sync(targetFPS);
            // glFinish();
            // long timeTook = System.currentTimeMillis() - time;
            // timeTookLastTime = timeTook;
            }
            // Draw graph
            if (client.getConfiguration().getBooleanOption("client.debug.frametimeGraph")) {
                FrametimeRenderer.draw(renderingContext);
                MemUsageRenderer.draw(renderingContext);
                WorldLogicTimeRenderer.draw(renderingContext);
            }
            // Update the screen
            // Display.update();
            glfwSwapBuffers(glfwWindowHandle);
            // Reset counters
            GLCalls.nextFrame();
        }
        // Sane way of ending the game.
        client.logger().info("Game exitting cleanly.");
        soundManager.destroy();
        client.onClose();
        glfwDestroyWindow(glfwWindowHandle);
        System.exit(0);
    } catch (Throwable e) {
        logger().error("A fatal error occured ! If you see the dev, show him this message !", e);
    // e.printStackTrace();
    // e.printStackTrace(logger().getPrintWriter());
    }
}
Also used : GLFWFramebufferSizeCallback(org.lwjgl.glfw.GLFWFramebufferSizeCallback) Layer(io.xol.chunkstories.api.gui.Layer) IconLoader(io.xol.chunkstories.client.util.IconLoader) GLFW.glfwWindowHint(org.lwjgl.glfw.GLFW.glfwWindowHint)

Example 3 with Layer

use of io.xol.chunkstories.api.gui.Layer in project chunkstories-core by Hugobros3.

the class PostProcessPass method render.

@Override
public void render(RenderingInterface renderer) {
    if (shadedBuffer != null) {
        renderer.getRenderTargetManager().setConfiguration(fbo);
        // renderer.getRenderTargetManager().clearBoundRenderTargetAll();
        // TODO mix in the reflections earlier ?
        // Texture2D bloomRendered = RenderingConfig.doBloom ? bloomRenderer.renderBloom(renderingContext) : null;
        Layer layer = renderer.getWindow().getLayer();
        // (layer instanceof Ingame) ? ((Ingame)layer).getPauseOverlayFade() : 0;
        float pauseFade = 0.0f;
        pauseFade = layer.getClass().getName().contains("Ingame") ? 0 : 1;
        // We render to the screen.
        // renderer.getRenderTargetManager().setConfiguration(null);
        renderer.setDepthTestMode(DepthTestMode.DISABLED);
        renderer.setBlendMode(BlendMode.DISABLED);
        Shader postProcess = renderer.useShader("postprocess");
        renderer.bindTexture2D("shadedBuffer", shadedBuffer);
        renderer.bindTexture2D("zBuffer", zBuffer);
        renderer.bindTexture2D("pauseOverlayTexture", renderer.textures().getTexture("./textures/gui/darker.png"));
        // TODO make an underwater pass
        // Voxel vox = world.peekSafely(renderingContext.getCamera().getCameraPosition()).getVoxel();
        // postProcess.setUniform1f("underwater", vox.getDefinition().isLiquid() ? 1 : 0);
        postProcess.setUniform1f("underwater", 0.0f);
        // TODO
        postProcess.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
        postProcess.setUniform1f("pauseOverlayFade", pauseFade);
        if (shadowPass != null && renderer.getClient().getConfiguration().getBooleanOption("client.rendering.shadows")) {
            renderer.bindTexture2D("shadowMap", (Texture2D) shadowPass.resolvedOutputs.get("shadowMap"));
            // System.out.println((Texture2D) shadowPass.resolvedOutputs.get("shadowMap"));
            postProcess.setUniform1f("shadowMapResolution", ((Texture2D) shadowPass.resolvedOutputs.get("shadowMap")).getWidth());
            postProcess.setUniform1f("shadowVisiblity", shadowPass.getShadowVisibility());
            postProcess.setUniformMatrix4f("shadowMatrix", shadowPass.getShadowMatrix());
        }
        renderer.getCamera().setupShader(postProcess);
        worldRenderer.getSkyRenderer().setupShader(postProcess);
        renderer.drawFSQuad();
    }
}
Also used : Shader(io.xol.chunkstories.api.rendering.shader.Shader) Layer(io.xol.chunkstories.api.gui.Layer)

Aggregations

Layer (io.xol.chunkstories.api.gui.Layer)3 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)1 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)1 ClientInputPressedEvent (io.xol.chunkstories.api.events.client.ClientInputPressedEvent)1 PlayerInputPressedEvent (io.xol.chunkstories.api.events.player.PlayerInputPressedEvent)1 MouseScroll (io.xol.chunkstories.api.input.Mouse.MouseScroll)1 ClientPluginManager (io.xol.chunkstories.api.plugin.ClientPluginManager)1 Shader (io.xol.chunkstories.api.rendering.shader.Shader)1 World (io.xol.chunkstories.api.world.World)1 ServerConnection (io.xol.chunkstories.client.net.ServerConnection)1 IconLoader (io.xol.chunkstories.client.util.IconLoader)1 PacketInput (io.xol.chunkstories.net.packets.PacketInput)1 WorldClientRemote (io.xol.chunkstories.world.WorldClientRemote)1 GLFW.glfwWindowHint (org.lwjgl.glfw.GLFW.glfwWindowHint)1 GLFWFramebufferSizeCallback (org.lwjgl.glfw.GLFWFramebufferSizeCallback)1