com.xenoamess.cyan_potion.base.CallbackManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cyan_potion_base Show documentation
Show all versions of cyan_potion_base Show documentation
the low-level part of cyan_potion game engine.
// Generated by delombok at Sat May 02 07:05:56 CST 2020
/*
* MIT License
*
* Copyright (c) 2020 XenoAmess
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.xenoamess.cyan_potion.base;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xenoamess.cyan_potion.base.events.Event;
import com.xenoamess.cyan_potion.base.events.WindowResizeEvent;
import com.xenoamess.cyan_potion.base.io.DropFilesEvent;
import com.xenoamess.cyan_potion.base.io.input.keyboard.CharEvent;
import com.xenoamess.cyan_potion.base.io.input.keyboard.KeyboardEvent;
import com.xenoamess.cyan_potion.base.io.input.mouse.MouseButtonEvent;
import com.xenoamess.cyan_potion.base.io.input.mouse.MouseScrollEvent;
import org.lwjgl.glfw.*;
import org.lwjgl.system.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.lwjgl.glfw.GLFW.*;
/**
* Callbacks class.
*
* @author XenoAmess
* @version 0.162.2
*/
public class CallbackManager extends SubManager {
@JsonIgnore
private static final transient Logger LOGGER = LoggerFactory.getLogger(CallbackManager.class);
/**
* Constructor for Callbacks.
*
* @param gameManager gameManager
*/
public CallbackManager(GameManager gameManager) {
super(gameManager);
}
@SuppressWarnings("unused")
@Override
public void init() {
//do nothing
}
@SuppressWarnings("unused")
@Override
public void update() {
//do nothing
}
@Override
public void close() {
GLFWWindowCloseCallback glfwWindowCloseCallback = glfwSetWindowCloseCallback(this.getGameManager().getGameWindow().getWindow(), null);
if (glfwWindowCloseCallback != null) {
glfwWindowCloseCallback.free();
}
GLFWKeyCallback glfwKeyCallback = glfwSetKeyCallback(this.getGameManager().getGameWindow().getWindow(), null);
if (glfwKeyCallback != null) {
glfwKeyCallback.free();
}
}
private GLFWWindowCloseCallbackI windowCloseCallback = window -> {
LOGGER.debug("Alright I exit.");
getGameManager().shutdown();
};
//-----CallbackIs
private GLFWErrorCallbackI errorCallback = null;
private GLFWKeyCallbackI keyCallback = (long window, int key, int scancode, int action, int mods) -> {
Event event = new KeyboardEvent(window, key, scancode, action, mods);
getGameManager().eventListAdd(event);
};
private GLFWJoystickCallbackI joystickCallback = (int jid, int event) -> LOGGER.debug("jid : {}, event : {}", jid, event);
private GLFWMouseButtonCallbackI mouseButtonCallback = (long window, int button, int action, int mods) -> {
GameWindow gameWindow = getGameManager().getGameWindow();
Event event = new MouseButtonEvent(window, button, action, mods, gameWindow.getMousePosX(), gameWindow.getMousePosY());
getGameManager().eventListAdd(event);
};
private GLFWScrollCallbackI scrollCallback = (long window, double xoffset, double yoffset) -> {
Event event = new MouseScrollEvent(window, xoffset, yoffset);
getGameManager().eventListAdd(event);
};
private GLFWWindowSizeCallbackI windowSizeCallback = (long window, int width, int height) -> {
Event event = new WindowResizeEvent(window, width, height);
getGameManager().eventListAdd(event);
};
private GLFWCharCallbackI charCallback = (long window, int codepoint) -> {
Event event = new CharEvent(window, codepoint);
getGameManager().eventListAdd(event);
};
private GLFWDropCallbackI dropCallback = (long window, int count, long names) -> {
Event event = new DropFilesEvent(window, count, names);
getGameManager().eventListAdd(event);
};
//-----wrap callback functions-----
/**
* wrapErrorCallback.
*
* @return a {@link org.lwjgl.glfw.GLFWErrorCallbackI} object.
*/
public GLFWErrorCallbackI wrapErrorCallback() {
return (error, description) -> CallbackManager.this.getErrorCallback().invoke(error, description);
}
/**
* wrapWindowCloseCallback.
*
* @return a {@link org.lwjgl.glfw.GLFWWindowCloseCallbackI} object.
*/
public GLFWWindowCloseCallbackI wrapWindowCloseCallback() {
return window -> CallbackManager.this.getWindowCloseCallback().invoke(window);
}
/**
* wrapKeyCallback.
*
* @return a {@link org.lwjgl.glfw.GLFWKeyCallbackI} object.
*/
public GLFWKeyCallbackI wrapKeyCallback() {
return (window, key, scancode, action, mods) -> CallbackManager.this.getKeyCallback().invoke(window, key, scancode, action, mods);
}
/**
* wrapJoystickCallback.
*
* @return a {@link org.lwjgl.glfw.GLFWJoystickCallbackI} object.
*/
public GLFWJoystickCallbackI wrapJoystickCallback() {
return (jid, event) -> CallbackManager.this.getJoystickCallback().invoke(jid, event);
}
/**
* wrapMouseButtonCallback.
*
* @return a {@link org.lwjgl.glfw.GLFWMouseButtonCallbackI} object.
*/
public GLFWMouseButtonCallbackI wrapMouseButtonCallback() {
return (window, button, action, mods) -> CallbackManager.this.getMouseButtonCallback().invoke(window, button, action, mods);
}
/**
* wrapScrollCallback.
*
* @return a {@link org.lwjgl.glfw.GLFWScrollCallbackI} object.
*/
public GLFWScrollCallbackI wrapScrollCallback() {
return (window, xoffset, yoffset) -> CallbackManager.this.getScrollCallback().invoke(window, xoffset, yoffset);
}
/**
* wrapWindowSizeCallback.
*
* @return a {@link org.lwjgl.glfw.GLFWWindowSizeCallbackI} object.
*/
public GLFWWindowSizeCallbackI wrapWindowSizeCallback() {
return (window, width, height) -> CallbackManager.this.getWindowSizeCallback().invoke(window, width, height);
}
/**
* wrapCharCallback.
*
* @return a {@link org.lwjgl.glfw.GLFWCharCallbackI} object.
*/
public GLFWCharCallbackI wrapCharCallback() {
return (window, codepoint) -> CallbackManager.this.getCharCallback().invoke(window, codepoint);
}
/**
* wrapDropCallback.
*
* @return a {@link org.lwjgl.glfw.GLFWDropCallbackI} object.
*/
public GLFWDropCallbackI wrapDropCallback() {
return (window, count, names) -> CallbackManager.this.getDropCallback().invoke(window, count, names);
}
public void setWrapperCallbacks(GameWindow gameWindow) {
glfwSetErrorCallback(this.wrapErrorCallback());
glfwSetKeyCallback(gameWindow.getWindow(), this.wrapKeyCallback());
glfwSetCharCallback(gameWindow.getWindow(), this.wrapCharCallback());
glfwSetMouseButtonCallback(gameWindow.getWindow(), this.wrapMouseButtonCallback());
glfwSetScrollCallback(gameWindow.getWindow(), this.wrapScrollCallback());
glfwSetJoystickCallback(this.wrapJoystickCallback());
glfwSetWindowCloseCallback(gameWindow.getWindow(), this.wrapWindowCloseCallback());
glfwSetWindowSizeCallback(gameWindow.getWindow(), this.wrapWindowSizeCallback());
glfwSetDropCallback(gameWindow.getWindow(), this.wrapDropCallback());
}
public void freeWrapperCallbacks(GameWindow gameWindow) {
free(glfwSetErrorCallback(null));
free(glfwSetKeyCallback(gameWindow.getWindow(), null));
free(glfwSetCharCallback(gameWindow.getWindow(), null));
free(glfwSetMouseButtonCallback(gameWindow.getWindow(), null));
free(glfwSetScrollCallback(gameWindow.getWindow(), null));
free(glfwSetJoystickCallback(null));
free(glfwSetWindowCloseCallback(gameWindow.getWindow(), null));
free(glfwSetWindowSizeCallback(gameWindow.getWindow(), null));
free(glfwSetDropCallback(gameWindow.getWindow(), null));
//-----
free(errorCallback);
free(keyCallback);
free(joystickCallback);
free(mouseButtonCallback);
free(scrollCallback);
free(windowSizeCallback);
free(charCallback);
free(dropCallback);
}
public static void free(Callback callback) {
if (callback == null) {
return;
}
callback.free();
}
public static void free(Object callbackI) {
if (callbackI instanceof Callback) {
free((Callback) callbackI);
}
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof CallbackManager)) return false;
final CallbackManager other = (CallbackManager) o;
if (!other.canEqual((java.lang.Object) this)) return false;
if (!super.equals(o)) return false;
final java.lang.Object this$windowCloseCallback = this.getWindowCloseCallback();
final java.lang.Object other$windowCloseCallback = other.getWindowCloseCallback();
if (this$windowCloseCallback == null ? other$windowCloseCallback != null : !this$windowCloseCallback.equals(other$windowCloseCallback)) return false;
final java.lang.Object this$errorCallback = this.getErrorCallback();
final java.lang.Object other$errorCallback = other.getErrorCallback();
if (this$errorCallback == null ? other$errorCallback != null : !this$errorCallback.equals(other$errorCallback)) return false;
final java.lang.Object this$keyCallback = this.getKeyCallback();
final java.lang.Object other$keyCallback = other.getKeyCallback();
if (this$keyCallback == null ? other$keyCallback != null : !this$keyCallback.equals(other$keyCallback)) return false;
final java.lang.Object this$joystickCallback = this.getJoystickCallback();
final java.lang.Object other$joystickCallback = other.getJoystickCallback();
if (this$joystickCallback == null ? other$joystickCallback != null : !this$joystickCallback.equals(other$joystickCallback)) return false;
final java.lang.Object this$mouseButtonCallback = this.getMouseButtonCallback();
final java.lang.Object other$mouseButtonCallback = other.getMouseButtonCallback();
if (this$mouseButtonCallback == null ? other$mouseButtonCallback != null : !this$mouseButtonCallback.equals(other$mouseButtonCallback)) return false;
final java.lang.Object this$scrollCallback = this.getScrollCallback();
final java.lang.Object other$scrollCallback = other.getScrollCallback();
if (this$scrollCallback == null ? other$scrollCallback != null : !this$scrollCallback.equals(other$scrollCallback)) return false;
final java.lang.Object this$windowSizeCallback = this.getWindowSizeCallback();
final java.lang.Object other$windowSizeCallback = other.getWindowSizeCallback();
if (this$windowSizeCallback == null ? other$windowSizeCallback != null : !this$windowSizeCallback.equals(other$windowSizeCallback)) return false;
final java.lang.Object this$charCallback = this.getCharCallback();
final java.lang.Object other$charCallback = other.getCharCallback();
if (this$charCallback == null ? other$charCallback != null : !this$charCallback.equals(other$charCallback)) return false;
final java.lang.Object this$dropCallback = this.getDropCallback();
final java.lang.Object other$dropCallback = other.getDropCallback();
if (this$dropCallback == null ? other$dropCallback != null : !this$dropCallback.equals(other$dropCallback)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
protected boolean canEqual(final java.lang.Object other) {
return other instanceof CallbackManager;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public int hashCode() {
final int PRIME = 59;
int result = super.hashCode();
final java.lang.Object $windowCloseCallback = this.getWindowCloseCallback();
result = result * PRIME + ($windowCloseCallback == null ? 43 : $windowCloseCallback.hashCode());
final java.lang.Object $errorCallback = this.getErrorCallback();
result = result * PRIME + ($errorCallback == null ? 43 : $errorCallback.hashCode());
final java.lang.Object $keyCallback = this.getKeyCallback();
result = result * PRIME + ($keyCallback == null ? 43 : $keyCallback.hashCode());
final java.lang.Object $joystickCallback = this.getJoystickCallback();
result = result * PRIME + ($joystickCallback == null ? 43 : $joystickCallback.hashCode());
final java.lang.Object $mouseButtonCallback = this.getMouseButtonCallback();
result = result * PRIME + ($mouseButtonCallback == null ? 43 : $mouseButtonCallback.hashCode());
final java.lang.Object $scrollCallback = this.getScrollCallback();
result = result * PRIME + ($scrollCallback == null ? 43 : $scrollCallback.hashCode());
final java.lang.Object $windowSizeCallback = this.getWindowSizeCallback();
result = result * PRIME + ($windowSizeCallback == null ? 43 : $windowSizeCallback.hashCode());
final java.lang.Object $charCallback = this.getCharCallback();
result = result * PRIME + ($charCallback == null ? 43 : $charCallback.hashCode());
final java.lang.Object $dropCallback = this.getDropCallback();
result = result * PRIME + ($dropCallback == null ? 43 : $dropCallback.hashCode());
return result;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public java.lang.String toString() {
return "CallbackManager(windowCloseCallback=" + this.getWindowCloseCallback() + ", errorCallback=" + this.getErrorCallback() + ", keyCallback=" + this.getKeyCallback() + ", joystickCallback=" + this.getJoystickCallback() + ", mouseButtonCallback=" + this.getMouseButtonCallback() + ", scrollCallback=" + this.getScrollCallback() + ", windowSizeCallback=" + this.getWindowSizeCallback() + ", charCallback=" + this.getCharCallback() + ", dropCallback=" + this.getDropCallback() + ")";
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public GLFWWindowCloseCallbackI getWindowCloseCallback() {
return this.windowCloseCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setWindowCloseCallback(final GLFWWindowCloseCallbackI windowCloseCallback) {
this.windowCloseCallback = windowCloseCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public GLFWErrorCallbackI getErrorCallback() {
return this.errorCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setErrorCallback(final GLFWErrorCallbackI errorCallback) {
this.errorCallback = errorCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public GLFWKeyCallbackI getKeyCallback() {
return this.keyCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setKeyCallback(final GLFWKeyCallbackI keyCallback) {
this.keyCallback = keyCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public GLFWJoystickCallbackI getJoystickCallback() {
return this.joystickCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setJoystickCallback(final GLFWJoystickCallbackI joystickCallback) {
this.joystickCallback = joystickCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public GLFWMouseButtonCallbackI getMouseButtonCallback() {
return this.mouseButtonCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setMouseButtonCallback(final GLFWMouseButtonCallbackI mouseButtonCallback) {
this.mouseButtonCallback = mouseButtonCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public GLFWScrollCallbackI getScrollCallback() {
return this.scrollCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setScrollCallback(final GLFWScrollCallbackI scrollCallback) {
this.scrollCallback = scrollCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public GLFWWindowSizeCallbackI getWindowSizeCallback() {
return this.windowSizeCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setWindowSizeCallback(final GLFWWindowSizeCallbackI windowSizeCallback) {
this.windowSizeCallback = windowSizeCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public GLFWCharCallbackI getCharCallback() {
return this.charCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setCharCallback(final GLFWCharCallbackI charCallback) {
this.charCallback = charCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public GLFWDropCallbackI getDropCallback() {
return this.dropCallback;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public void setDropCallback(final GLFWDropCallbackI dropCallback) {
this.dropCallback = dropCallback;
}
}