Engine restructure part 1 - Added plutocore

This commit is contained in:
Tefek 2020-08-20 19:10:11 +02:00
parent 0386288949
commit 5ee3ecbd65
18 changed files with 578 additions and 81 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
/*/.project
/*/.classpath
/.project
*.log

50
plutocore/pom.xml Normal file
View File

@ -0,0 +1,50 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cz.tefek</groupId>
<artifactId>plutocore</artifactId>
<version>0.1</version>
<name>plutocore</name>
<description>The foundation module for games and apps built on top of PlutoEngine.</description>
<properties>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>cz.tefek</groupId>
<artifactId>plutotexturing</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>cz.tefek</groupId>
<artifactId>plutoshader</artifactId>
<version>0.3</version>
</dependency>
<dependency>
<groupId>cz.tefek</groupId>
<artifactId>plutogui</artifactId>
<version>0.2</version>
</dependency>
<dependency>
<groupId>cz.tefek</groupId>
<artifactId>plutomesher</artifactId>
<version>0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,90 @@
package cz.tefek.pluto;
import java.util.Locale;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL33;
import cz.tefek.io.modloader.ModLoaderCore;
import cz.tefek.io.pluto.debug.Logger;
import cz.tefek.io.pluto.debug.SmartSeverity;
import cz.tefek.l10n.PlutoL10n;
import cz.tefek.pluto.engine.buffer.GLFWImageUtil;
import cz.tefek.pluto.engine.display.Display;
import cz.tefek.pluto.engine.display.DisplayBuilder;
import cz.tefek.pluto.engine.input.InputBus;
public abstract class PlutoApplication
{
public static final boolean DEBUG_MODE = Boolean.valueOf(System.getProperty("cz.tefek.pluto.debug"));
protected Display display;
protected abstract Class<?> getMainModule();
protected abstract void loop();
public final void run(String[] args)
{
Logger.setup();
Logger.log(SmartSeverity.INFO, "Debug mode: " + (DEBUG_MODE ? "enabled" : "disabled"));
PlutoL10n.init(Locale.UK);
DisplayBuilder.initGLFW();
this.display = new DisplayBuilder().hintOpenGLVersion(3, 3).hintDebugContext(DEBUG_MODE).hintMSAA(4).hintVisible(true).hintResizeable(true).setInitialSize(1280, 720).export();
this.display.create("Stardust Miner");
this.display.setWindowSizeLimits(1000, 600, GLFW.GLFW_DONT_CARE, GLFW.GLFW_DONT_CARE);
this.display.lockSwapInterval(0);
this.display.show();
var icons = GLFWImageUtil.loadIconSet("data/icon16.png", "data/icon32.png", "data/icon64.png", "data/icon128.png");
this.display.setIcons(icons);
this.display.createOpenGLCapabilities();
InputBus.init(this.display);
ModLoaderCore.registerMod(this.getMainModule());
ModLoaderCore.loadProcedure();
while (!this.display.isClosing())
{
GL33.glViewport(0, 0, this.display.getWidth(), this.display.getHeight());
GL33.glClearColor(0f, 0.7f, 1f, 0f);
GL33.glClear(GL33.GL_COLOR_BUFFER_BIT | GL33.GL_DEPTH_BUFFER_BIT);
this.loop();
this.display.swapBuffers();
InputBus.resetStates();
this.display.pollEvents();
}
InputBus.destroy();
ModLoaderCore.unloadProcedure();
GL.destroy();
this.display.destroy();
DisplayBuilder.destroyGLFW();
}
public Display getDisplayInstance()
{
return this.display;
}
}

View File

@ -0,0 +1,55 @@
package cz.tefek.pluto.engine.input;
import org.lwjgl.glfw.GLFWCursorPosCallback;
public class CursorPositionCallback extends GLFWCursorPosCallback
{
private double posX;
private double posY;
private double deltaX;
private double deltaY;
@Override
public void invoke(long window, double xpos, double ypos)
{
this.deltaX = this.posX - xpos;
this.deltaY = this.posY - ypos;
this.posX = xpos;
this.posY = ypos;
}
public void reset()
{
this.deltaX = 0;
this.deltaY = 0;
}
public double getX()
{
return this.posX;
}
public double getY()
{
return this.posY;
}
public double getDeltaX()
{
return this.deltaX;
}
public double getDeltaY()
{
return this.deltaY;
}
public boolean isInside(int x, int y, int x2, int y2)
{
boolean inside = this.getX() > x && this.getX() < x2 && this.getY() > y && this.getY() < y2;
return inside;
}
}

View File

@ -0,0 +1,138 @@
package cz.tefek.pluto.engine.input;
import org.lwjgl.glfw.GLFW;
import cz.tefek.pluto.engine.display.Display;
public class InputBus
{
private static ThreadLocal<KeyboardInputCallback> keyboard = new ThreadLocal<>();
private static ThreadLocal<MouseButtonCallback> mouseButton = new ThreadLocal<>();
private static ThreadLocal<CursorPositionCallback> cursorPosition = new ThreadLocal<>();
private static ThreadLocal<ScrollInputCallback> scroll = new ThreadLocal<>();
public static void init(Display display)
{
keyboard.set(new KeyboardInputCallback());
GLFW.glfwSetKeyCallback(display.getWindowPointer(), keyboard.get());
mouseButton.set(new MouseButtonCallback());
GLFW.glfwSetMouseButtonCallback(display.getWindowPointer(), mouseButton.get());
cursorPosition.set(new CursorPositionCallback());
GLFW.glfwSetCursorPosCallback(display.getWindowPointer(), cursorPosition.get());
scroll.set(new ScrollInputCallback());
GLFW.glfwSetScrollCallback(display.getWindowPointer(), scroll.get());
}
public static void destroy()
{
scroll.get().free();
scroll.remove();
mouseButton.get().free();
mouseButton.remove();
keyboard.get().free();
keyboard.remove();
cursorPosition.get().free();
cursorPosition.remove();
}
public static KeyboardInputCallback keyboard()
{
return keyboard.get();
}
public static MouseButtonCallback mouseButtons()
{
return mouseButton.get();
}
public static ScrollInputCallback scroll()
{
return scroll.get();
}
public static CursorPositionCallback cursorPosition()
{
return cursorPosition.get();
}
public static void resetStates()
{
keyboard.get().resetPressed();
mouseButton.get().reset();
scroll.get().reset();
cursorPosition.get().reset();
}
public static class Mouse
{
public static boolean clicked(int button)
{
var mb = mouseButton.get();
return mb.buttonClicked[button];
}
public static boolean released(int button)
{
var mb = mouseButton.get();
return mb.buttonReleased[button];
}
public static boolean isButtonDown(int button)
{
var mb = mouseButton.get();
return mb.buttonDown[button];
}
public static double getX()
{
return cursorPosition.get().getX();
}
public static double getY()
{
return cursorPosition.get().getY();
}
public static double getDX()
{
return cursorPosition.get().getDeltaX();
}
public static double getDY()
{
return cursorPosition.get().getDeltaY();
}
public static double getScrollX()
{
return scroll.get().getXScroll();
}
public static double getScrollY()
{
return scroll.get().getYScroll();
}
}
public static class Keyboard
{
public static boolean pressed(int key)
{
return keyboard.get().hasBeenPressed(key);
}
public static boolean released(int key)
{
return keyboard.get().hasBeenReleased(key);
}
public static boolean isKeyDown(int key)
{
return keyboard.get().isKeyDown(key);
}
}
}

View File

@ -0,0 +1,58 @@
package cz.tefek.pluto.engine.input;
import static org.lwjgl.glfw.GLFW.GLFW_PRESS;
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
import java.util.HashSet;
import java.util.Set;
import org.lwjgl.glfw.GLFWKeyCallback;
public class KeyboardInputCallback extends GLFWKeyCallback
{
private Set<Integer> keyPressed = new HashSet<>();
private Set<Integer> keyDown = new HashSet<>();
private Set<Integer> keyReleased = new HashSet<>();
@Override
public void invoke(long window, int key, int scancode, int action, int mods)
{
if (key < 0)
{
return;
}
if (action == GLFW_PRESS)
{
this.keyDown.add(key);
this.keyPressed.add(key);
}
if (action == GLFW_RELEASE)
{
this.keyDown.remove(key);
this.keyReleased.add(key);
}
}
public void resetPressed()
{
this.keyPressed.clear();
this.keyReleased.clear();
}
public boolean hasBeenPressed(int key)
{
return this.keyPressed.contains(key);
}
public boolean hasBeenReleased(int key)
{
return this.keyReleased.contains(key);
}
public boolean isKeyDown(int key)
{
return this.keyDown.contains(key);
}
}

View File

@ -0,0 +1,33 @@
package cz.tefek.pluto.engine.input;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWMouseButtonCallback;
public class MouseButtonCallback extends GLFWMouseButtonCallback
{
public boolean[] buttonClicked = new boolean[32];
public boolean[] buttonDown = new boolean[32];
public boolean[] buttonReleased = new boolean[32];
@Override
public void invoke(long window, int button, int action, int mods)
{
this.buttonClicked[button] = action == GLFW.GLFW_PRESS;
this.buttonDown[button] = action != GLFW.GLFW_RELEASE;
this.buttonReleased[button] = action == GLFW.GLFW_RELEASE;
}
public void reset()
{
for (int i = 0; i < this.buttonClicked.length; i++)
{
this.buttonClicked[i] = false;
}
for (int i = 0; i < this.buttonClicked.length; i++)
{
this.buttonReleased[i] = false;
}
}
}

View File

@ -0,0 +1,46 @@
package cz.tefek.pluto.engine.input;
import org.lwjgl.glfw.GLFWScrollCallback;
/**
* @author 493msi
*
*/
public class ScrollInputCallback extends GLFWScrollCallback
{
private double xScroll;
private double yScroll;
@Override
public void invoke(long window, double xoffset, double yoffset)
{
xScroll = xoffset;
yScroll = yoffset;
}
public void reset()
{
xScroll = 0;
yScroll = 0;
}
public double getYScroll()
{
return yScroll;
}
public void setYScroll(double yScroll)
{
this.yScroll = yScroll;
}
public double getXScroll()
{
return xScroll;
}
public void setXScroll(double xScroll)
{
this.xScroll = xScroll;
}
}

View File

@ -1,16 +1,18 @@
package cz.tefek.io.modloader;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import cz.tefek.io.asl.resource.ResourceHelper;
import cz.tefek.io.pluto.debug.Logger;
import cz.tefek.io.pluto.debug.SmartSeverity;
/**
* Class-loads all valid mods. The only requirement for the mod is to have a
@ -25,7 +27,7 @@ public class ModClassLoader
public static void loadJars()
{
Logger.log("[Pluto Mod Loader] Looking for installed mods.");
Logger.log(SmartSeverity.MODULE, "Looking for installed mods.");
File modDir = new File(ResourceHelper.GLOBAL_ROOT + "mods/");
@ -33,7 +35,7 @@ public class ModClassLoader
{
modDir.mkdir();
Logger.log("[Pluto Mod Loader] No mod found.");
Logger.log(SmartSeverity.MODULE, " No mod found.");
return;
}
@ -42,11 +44,11 @@ public class ModClassLoader
if (mods.size() == 0)
{
Logger.log("[Pluto Mod Loader] No mod found.");
Logger.log(SmartSeverity.MODULE, "No mod found.");
}
else
{
Logger.log("[Pluto Mod Loader] Found " + mods.size() + " mod(s) to load.");
Logger.log(SmartSeverity.MODULE, "Found " + mods.size() + " mod(s) to load.");
try
{
@ -67,11 +69,11 @@ public class ModClassLoader
{
if (mods.size() == 1)
{
Logger.log("[Pluto Mod Loader] There is one mod to load.");
Logger.log(SmartSeverity.MODULE, "There is one mod to load.");
}
else
{
Logger.log("[Pluto Mod Loader] There are " + mods.size() + " mods to load.");
Logger.log(SmartSeverity.MODULE, "There are " + mods.size() + " mods to load.");
}
for (String modname : mods)
@ -125,28 +127,28 @@ public class ModClassLoader
jarFile.close();
Logger.log("[Pluto Mod Loader] Loaded mod jar file: " + modname + "/mod.jar");
Logger.log(SmartSeverity.MODULE_PLUS, "Loaded mod jar file: " + modname + "/mod.jar");
i++;
}
else
{
Logger.log("[Pluto Mod Loader] Failed to load mod jar file: " + modname + ".");
Logger.log("[Pluto Mod Loader] Reason: Missing mod.jar file.");
Logger.log(SmartSeverity.MODULE_WARNING, "Failed to load mod jar file: " + modname + ".");
Logger.log(SmartSeverity.MODULE_WARNING, "Reason: Missing mod.jar file.");
}
}
if (i < 1 || i == 0)
{
System.out.println("[Pluto Mod Loader] Loading mods complete, loaded " + i + " mods.");
Logger.log(SmartSeverity.MODULE, "Loading mods complete, loaded " + i + " mods.");
}
else
{
System.out.println("[Pluto Mod Loader] Loading mods complete, loaded " + i + " mod.");
Logger.log(SmartSeverity.MODULE, "Loading mods complete, loaded " + i + " mod.");
}
}
else
{
Logger.log("[Pluto Mod Loader] There aren't any mods, skipping initialising phase.");
Logger.log(SmartSeverity.MODULE, "There aren't any mods, skipping initialising phase.");
}
}
}

View File

@ -13,25 +13,27 @@ import java.io.InputStream;
import cz.tefek.io.asl.resource.ResourceHelper;
import cz.tefek.io.pluto.debug.Logger;
import cz.tefek.io.pluto.debug.Severity;
import cz.tefek.io.pluto.debug.SmartSeverity;
/**
* Unzips mod packages from the packages folder into the mods folder. WIP
*
* 2020 Update: Still WIP
*
* @author 493msi
*/
public class ModInstaller
{
public static void unpackNewMods()
{
Logger.log("[Pluto Mod Loader] Looking for new mod packages to install.");
Logger.log(SmartSeverity.MODULE, "Looking for new mod packages to install.");
File f = new File(ResourceHelper.GLOBAL_ROOT + "packages/");
if (!f.exists())
{
f.mkdir();
Logger.log("[Pluto Mod Loader] Package folder does not exist, creating it and aborting unpacking.");
Logger.log(SmartSeverity.MODULE, "Package folder does not exist, creating it and aborting unpacking.");
return;
}
@ -40,15 +42,15 @@ public class ModInstaller
if (files.size() == 0)
{
Logger.log("[Pluto Mod Loader] No mod package found.");
Logger.log(SmartSeverity.MODULE, "No mod package found.");
}
else
{
Logger.log("[Pluto Mod Loader] Found " + files.size() + " mod packages.");
Logger.log(SmartSeverity.MODULE_PLUS, "Found " + files.size() + " mod packages.");
for (String file : files)
{
Logger.log("[Pluto Mod Loader] Mod package found: " + file + ", installing it.");
Logger.log(SmartSeverity.MODULE_PLUS, "Mod package found: " + file + ", installing it.");
try
{
@ -56,7 +58,7 @@ public class ModInstaller
}
catch (IOException e)
{
Logger.log(Severity.ERROR, "Unpacking of " + file + " failed!");
Logger.log(SmartSeverity.MODULE_ERROR, "Unpacking of " + file + " failed!");
Logger.logException(e);
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import cz.tefek.io.asl.resource.ResourceHelper;
import cz.tefek.io.modloader.event.ModLoad;
@ -20,26 +21,26 @@ import cz.tefek.pluto.eventsystem.staticmode.StaticPlutoEventManager;
public class ModLoaderCore
{
public static final String MOD_ID_STRING_PATTERN = "[a-z0-9_]+";
public static final String MOD_ID_STRING_PATTERN = "[a-z0-9]+[a-z0-9_]*";
public static final String FULL_MOD_ID_STRING_PATTERN = "^" + MOD_ID_STRING_PATTERN + "$";
static ModLoadingPhase loadingPhase = ModLoadingPhase.WAITING;
private static final List<Mod> modArchive = new ArrayList<>();
private static final LinkedList<Mod> loadBuffer = new LinkedList<>();
private static final Queue<Mod> loadBuffer = new LinkedList<>();
public static void registerMod(Class<?> modClass, String modDataRoot)
{
if (loadingPhase != ModLoadingPhase.WAITING && loadingPhase != ModLoadingPhase.CLASSLOADING)
{
Logger.log(SmartSeverity.ERROR, "Cannot register mod during loading phase " + loadingPhase.name() + "!");
Logger.log(SmartSeverity.MODULE_ERROR, "Cannot register mod during loading phase " + loadingPhase.name() + "!");
return;
}
if (getModByMainClass(modClass) != null)
{
Logger.log(SmartSeverity.WARNING, "[Pluto Mod Loader] Mod class " + modClass.getCanonicalName() + " is already registered, skipping it.");
Logger.log(SmartSeverity.MODULE_WARNING, "Mod class " + modClass.getCanonicalName() + " is already registered, skipping it.");
return;
}
@ -66,8 +67,8 @@ public class ModLoaderCore
if (!mod.getModID().matches(FULL_MOD_ID_STRING_PATTERN))
{
Logger.log(SmartSeverity.WARNING, "[Pluto Mod Loader] Modid " + mod.getModID() + " contains invalid characters (or none at all), mod will not be loaded.");
Logger.log(SmartSeverity.WARNING, "[Pluto Mod Loader] Only lowercase letters (a to z) and numbers (0 to 9) are allowed characters.");
Logger.log(SmartSeverity.MODULE_WARNING, "Mod id " + mod.getModID() + " contains invalid characters (or none at all), mod will not be loaded.");
Logger.log(SmartSeverity.MODULE_WARNING, "Only lowercase letters (a to z) and numbers (0 to 9) are allowed characters.");
return;
}
@ -142,23 +143,23 @@ public class ModLoaderCore
while (loadBuffer.peek() != null)
{
var mod = loadBuffer.removeFirst();
var mod = loadBuffer.remove();
StaticPlutoEventManager.registerEventHandler(mod.getMainClass());
modArchive.add(mod);
}
if (!modArchive.isEmpty())
{
Logger.log("[Pluto Mod Loader] Initializing mod(s)...");
Logger.log(SmartSeverity.MODULE, "Initializing mod(s)...");
initMods();
if (loadingPhase == ModLoadingPhase.FINISHING)
{
Logger.log("[Pluto Mod Loader] Initializing mod(s) finished.");
Logger.log(SmartSeverity.MODULE, "Initializing mod(s) finished.");
}
else
{
Logger.log("[Pluto Mod Loader] Initializing mod(s) was canceled due to error(s).");
Logger.log(SmartSeverity.MODULE_ERROR, "Initializing mod(s) was canceled due to error(s).");
}
}
}
@ -189,7 +190,7 @@ public class ModLoaderCore
public static void unloadProcedure()
{
Logger.log("[Pluto Mod Loader] Unloading all mods.");
Logger.log(SmartSeverity.MODULE_MINUS, "Unloading all mods.");
StaticPlutoEventManager.fireEvent(ModUnload.class, new ModUnloadEvent());
modArchive.clear();
}
@ -207,8 +208,8 @@ public class ModLoaderCore
}
catch (Exception e)
{
Logger.log("[Pluto Mod Loader] Problem encountered while preloading mods.");
Logger.log("[Pluto Mod Loader] Mod loading stopped.");
Logger.log(SmartSeverity.MODULE_ERROR, "Problem encountered while pre-loading mods.");
Logger.log(SmartSeverity.MODULE_ERROR, "Mod loading stopped.");
Logger.logException(e);
@ -228,8 +229,8 @@ public class ModLoaderCore
}
catch (Exception e)
{
Logger.log("[Pluto Mod Loader] Problem encountered while loading mods.");
Logger.log("[Pluto Mod Loader] Mod loading stopped.");
Logger.log(SmartSeverity.MODULE_ERROR, "Problem encountered while loading mods.");
Logger.log(SmartSeverity.MODULE_ERROR, "Mod loading stopped.");
Logger.logException(e);
@ -249,8 +250,8 @@ public class ModLoaderCore
}
catch (Exception e)
{
Logger.log("[Pluto Mod Loader] Problem encountered while loading mods.");
Logger.log("[Pluto Mod Loader] Mod loading stopped.");
Logger.log(SmartSeverity.MODULE_ERROR, "Problem encountered while post-loading mods.");
Logger.log(SmartSeverity.MODULE_ERROR, "Mod loading stopped.");
Logger.logException(e);

View File

@ -61,37 +61,37 @@ public class Logger
System.out.close();
}
public static void log(Object string)
public static synchronized void log(Object string)
{
log(Severity.NONE, string);
}
public static void logf(String string, Object... o)
public static synchronized void logf(String string, Object... o)
{
System.out.printf(string, o);
}
public static void logNoLine(Object string)
public static synchronized void logNoLine(Object string)
{
System.out.print(string);
}
public static void logException(Exception e)
public static synchronized void logException(Exception e)
{
e.printStackTrace();
}
public static void log(ISeverity s, Object string)
public static synchronized void log(ISeverity s, Object string)
{
(s.isStdErr() ? System.err : System.out).println(s.getDisplayName() + string);
}
public static void logf(ISeverity s, String string, Object... o)
public static synchronized void logf(ISeverity s, String string, Object... o)
{
(s.isStdErr() ? System.err : System.out).printf(s.getDisplayName() + string, o);
}
public static void logNoLine(ISeverity s, Object string)
public static synchronized void logNoLine(ISeverity s, Object string)
{
(s.isStdErr() ? System.err : System.out).print(s.getDisplayName() + string);
}

View File

@ -9,10 +9,26 @@ public enum SmartSeverity implements ISeverity
{
ADDED("[+] ", false),
REMOVED("[-] ", false),
ZERO("[0] ", false),
INFO("[i] ", false),
WARNING("[!] ", true),
ERROR("[X] ", true);
ERROR("[X] ", true),
AUDIO("[♪] ", false),
MODULE("[i] [M] ", false),
MODULE_PLUS("[+] [M] ", false),
MODULE_MINUS("[-] [M] ", false),
MODULE_WARNING("[!] [M] ", true),
MODULE_ERROR("[X] [M] ", true),
EVENT("[i] [E] ", false),
EVENT_PLUS("[+] [E] ", false),
EVENT_MINUS("[-] [E] ", false),
EVENT_WARNING("[!] [E] ", true),
EVENT_ERROR("[X] [E] ", true);
private String displayName;
private boolean usesStdErr;

View File

@ -11,7 +11,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import cz.tefek.io.pluto.debug.Logger;
import cz.tefek.io.pluto.debug.Severity;
import cz.tefek.io.pluto.debug.SmartSeverity;
import cz.tefek.pluto.eventsystem.EventData;
/**
@ -68,7 +68,7 @@ public class StaticPlutoEventManager
}
}
Logger.log(Severity.INFO, "Event handler " + clazz.getCanonicalName() + " scan found " + methodsFound + " method callback(s).");
Logger.log(SmartSeverity.EVENT_PLUS, "Event handler " + clazz.getCanonicalName() + " scan found " + methodsFound + " method callback(s).");
}
public static void registerEvent(Class<? extends Annotation> annotation)
@ -78,14 +78,14 @@ public class StaticPlutoEventManager
{
if (eventRegistry.containsKey(annotation))
{
Logger.log(Severity.ERROR, "Annotation " + annotation.getCanonicalName() + " is already registered!");
Logger.log(SmartSeverity.EVENT_ERROR, "Annotation " + annotation.getCanonicalName() + " is already registered!");
return;
}
else
{
eventRegistry.put(annotation, new ArrayList<Method>());
Logger.log(Severity.INFO, "Event " + annotation.getCanonicalName() + " successfully registered!");
Logger.log(SmartSeverity.EVENT_PLUS, "Event " + annotation.getCanonicalName() + " successfully registered!");
short retroactivelyFound = 0;
@ -110,7 +110,7 @@ public class StaticPlutoEventManager
}
}
Logger.log(Severity.INFO, "Retroactive method checking found " + retroactivelyFound + " item(s).");
Logger.log(SmartSeverity.EVENT_PLUS, "Retroactive method checking found " + retroactivelyFound + " item(s).");
// Let's check the Method orphanage for some potential
// candidates.
@ -138,12 +138,12 @@ public class StaticPlutoEventManager
orphans.removeAll(foundParents);
Logger.log(Severity.INFO, orphansFound + " orphan method(s) was/were bound and " + (orphansBefore - orphans.size()) + " removed from the storage!");
Logger.log(SmartSeverity.EVENT_PLUS, orphansFound + " orphan method(s) was/were bound and " + (orphansBefore - orphans.size()) + " removed from the storage!");
}
}
else
{
Logger.log(Severity.ERROR, "Annotation " + annotation.getCanonicalName() + " is not annotated with @Event, can't register it.");
Logger.log(SmartSeverity.EVENT_ERROR, "Annotation " + annotation.getCanonicalName() + " is not annotated with @Event, can't register it.");
}
}
@ -168,7 +168,7 @@ public class StaticPlutoEventManager
if (params.length == 0)
{
Logger.log(Severity.WARNING, "Method " + m.toGenericString() + " has no parameters, will not be invoked by event!");
Logger.log(SmartSeverity.EVENT_WARNING, "Method " + m.toGenericString() + " has no parameters, will not be invoked by event!");
}
for (int i = 0; i < params.length; i++)
@ -177,7 +177,7 @@ public class StaticPlutoEventManager
if (!EventData.class.isAssignableFrom(parameter))
{
Logger.log(Severity.ERROR, "Method " + m.toGenericString() + " contains invalid parameters. Only EventData instances are permitted.");
Logger.log(SmartSeverity.EVENT_ERROR, "Method " + m.toGenericString() + " contains invalid parameters. Only EventData instances are permitted.");
mostSuitableParam = null;
break;
}
@ -211,12 +211,12 @@ public class StaticPlutoEventManager
}
else
{
Logger.log(Severity.ERROR, "There is no event like " + event.getCanonicalName() + " registered.");
Logger.log(SmartSeverity.EVENT_ERROR, "There is no event like " + event.getCanonicalName() + " registered.");
}
}
else
{
Logger.log(Severity.ERROR, event.getCanonicalName() + " is not an event!");
Logger.log(SmartSeverity.EVENT_ERROR, event.getCanonicalName() + " is not an event!");
}
}

View File

@ -24,7 +24,7 @@ import cz.tefek.io.pluto.debug.SmartSeverity;
public class TPL
{
private static final int PLACEHOLDER_SIZE = 16;
private static final int PLACEHOLDER_CHECKEDBOARD = 16;
private static final int PLACEHOLDER_CHECKEDBOARD = 8;
private static final int PLACEHOLDER_CHECKEDBOARD_SQUARE_SIZE = PLACEHOLDER_SIZE / PLACEHOLDER_CHECKEDBOARD;
public static TPNImage load(ResourceAddress file)

View File

@ -100,7 +100,9 @@ public abstract class TiledSpriteSheet<T> extends SpriteSheet<T>
public abstract void copyToNewImage();
public TileSprite<TiledSpriteSheet<T>> addSprite(Sprite<T> sprite, int index)
public TileSprite<TiledSpriteSheet<T>> addSpriteSpecial(Sprite<T> sprite, int index, boolean allowSpriteDownscaling)
{
if (!allowSpriteDownscaling)
{
if (!this.aspectRatiosMatch(sprite))
{
@ -116,6 +118,7 @@ public abstract class TiledSpriteSheet<T> extends SpriteSheet<T>
{
this.upscale(sprite.getWidth() / this.tileWidth);
}
}
while (this.requiresExpanding(index))
{
@ -143,6 +146,11 @@ public abstract class TiledSpriteSheet<T> extends SpriteSheet<T>
return copySprite;
}
public TileSprite<TiledSpriteSheet<T>> addSprite(Sprite<T> sprite, int index)
{
return this.addSpriteSpecial(sprite, index, false);
}
private boolean aspectRatiosMatch(Sprite<?> sprite)
{
final var epsilon = 0.001f;

View File

@ -11,7 +11,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<lwjgl.version>3.2.3</lwjgl.version>
<joml.version>1.9.17</joml.version>
<joml.version>1.9.25</joml.version>
<steamworks4j.version>1.8.0</steamworks4j.version>
<steamworks4j-server.version>1.8.0</steamworks4j-server.version>
</properties>
@ -119,8 +119,6 @@
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-stb</artifactId>
</dependency>
<!-- <dependency> <groupId>org.lwjgl</groupId> <artifactId>lwjgl-jemalloc</artifactId>
</dependency> -->
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
@ -171,13 +169,6 @@
<artifactId>lwjgl-stb</artifactId>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<!-- <dependency> <groupId>org.lwjgl</groupId> <artifactId>lwjgl-jemalloc</artifactId>
<classifier>${lwjgl.natives}</classifier> </dependency> -->
<dependency>
<groupId>org.joml</groupId>
<artifactId>joml</artifactId>
<version>${joml.version}</version>
</dependency>
<dependency>
<groupId>com.code-disaster.steamworks4j</groupId>
<artifactId>steamworks4j</artifactId>

View File

@ -21,4 +21,10 @@ public class CollisionClass
{
return this.selfCollision;
}
@Override
public int hashCode()
{
return this.id;
}
}