Moved general purpose stuff into util, renamed utils->util
This commit is contained in:
@@ -4,9 +4,9 @@ package mightypork.gamecore.audio;
|
||||
import java.io.IOException;
|
||||
|
||||
import mightypork.gamecore.loading.DeferredResource;
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.utils.files.FileUtils;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.util.files.FileUtils;
|
||||
import mightypork.util.logging.LogAlias;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
|
||||
import org.newdawn.slick.openal.Audio;
|
||||
import org.newdawn.slick.openal.SoundStore;
|
||||
@@ -17,7 +17,7 @@ import org.newdawn.slick.openal.SoundStore;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@Alias(name = "Audio")
|
||||
@LogAlias(name = "Audio")
|
||||
public class DeferredAudio extends DeferredResource {
|
||||
|
||||
private enum PlayMode
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.gamecore.audio;
|
||||
|
||||
|
||||
import mightypork.utils.math.Calc;
|
||||
import mightypork.util.math.Calc;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@ package mightypork.gamecore.audio;
|
||||
|
||||
|
||||
import mightypork.gamecore.loading.NullResource;
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.util.logging.LogAlias;
|
||||
|
||||
|
||||
/**
|
||||
@@ -11,7 +11,7 @@ import mightypork.utils.annotations.Alias;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@Alias(name = "NullAudio")
|
||||
@LogAlias(name = "NullAudio")
|
||||
public class NullAudio extends DeferredAudio implements NullResource {
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,7 @@ import mightypork.gamecore.audio.players.EffectPlayer;
|
||||
import mightypork.gamecore.audio.players.LoopPlayer;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppAdapter;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.util.logging.Log;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,12 +8,12 @@ import java.util.Set;
|
||||
import mightypork.gamecore.audio.players.EffectPlayer;
|
||||
import mightypork.gamecore.audio.players.LoopPlayer;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.bus.clients.RootBusNode;
|
||||
import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.utils.math.Calc.Buffers;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.utils.math.constraints.vect.mutable.VectVar;
|
||||
import mightypork.gamecore.control.events.ResourceLoadRequest;
|
||||
import mightypork.util.control.eventbus.clients.RootBusNode;
|
||||
import mightypork.util.control.timing.Updateable;
|
||||
import mightypork.util.math.Calc.Buffers;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
import mightypork.util.math.constraints.vect.mutable.VectVar;
|
||||
|
||||
import org.lwjgl.openal.AL;
|
||||
import org.lwjgl.openal.AL10;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package mightypork.gamecore.audio;
|
||||
|
||||
|
||||
import mightypork.utils.math.Calc;
|
||||
import mightypork.utils.objects.Mutable;
|
||||
import mightypork.util.math.Calc;
|
||||
import mightypork.util.objects.Mutable;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ package mightypork.gamecore.audio.players;
|
||||
|
||||
import mightypork.gamecore.audio.DeferredAudio;
|
||||
import mightypork.gamecore.audio.Volume;
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
import mightypork.util.control.Destroyable;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ package mightypork.gamecore.audio.players;
|
||||
|
||||
import mightypork.gamecore.audio.DeferredAudio;
|
||||
import mightypork.gamecore.audio.Volume;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,9 +3,9 @@ package mightypork.gamecore.audio.players;
|
||||
|
||||
import mightypork.gamecore.audio.DeferredAudio;
|
||||
import mightypork.gamecore.audio.Volume;
|
||||
import mightypork.gamecore.control.timing.Pauseable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.utils.math.constraints.num.mutable.NumAnimated;
|
||||
import mightypork.util.control.timing.Pauseable;
|
||||
import mightypork.util.control.timing.Updateable;
|
||||
import mightypork.util.math.constraints.num.mutable.NumAnimated;
|
||||
|
||||
import org.lwjgl.openal.AL10;
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ package mightypork.gamecore.control;
|
||||
|
||||
|
||||
import mightypork.gamecore.audio.SoundSystem;
|
||||
import mightypork.gamecore.control.bus.BusAccess;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.util.control.eventbus.BusAccess;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,9 +2,9 @@ package mightypork.gamecore.control;
|
||||
|
||||
|
||||
import mightypork.gamecore.audio.SoundSystem;
|
||||
import mightypork.gamecore.control.bus.EventBus;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.util.control.eventbus.EventBus;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,9 +2,9 @@ package mightypork.gamecore.control;
|
||||
|
||||
|
||||
import mightypork.gamecore.audio.SoundSystem;
|
||||
import mightypork.gamecore.control.bus.clients.RootBusNode;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.util.control.eventbus.clients.RootBusNode;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,11 +2,11 @@ package mightypork.gamecore.control;
|
||||
|
||||
|
||||
import mightypork.gamecore.audio.SoundSystem;
|
||||
import mightypork.gamecore.control.bus.clients.BusNode;
|
||||
import mightypork.gamecore.control.bus.clients.DelegatingClient;
|
||||
import mightypork.gamecore.control.bus.clients.RootBusNode;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.util.control.eventbus.clients.BusNode;
|
||||
import mightypork.util.control.eventbus.clients.DelegatingClient;
|
||||
import mightypork.util.control.eventbus.clients.RootBusNode;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,18 +8,17 @@ import java.util.logging.Level;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import mightypork.gamecore.audio.SoundSystem;
|
||||
import mightypork.gamecore.control.bus.EventBus;
|
||||
import mightypork.gamecore.control.bus.events.*;
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.gamecore.control.events.*;
|
||||
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.loading.AsyncResourceLoader;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.utils.annotations.DefaultImpl;
|
||||
import mightypork.utils.files.InstanceLock;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.logging.LogWriter;
|
||||
import mightypork.util.annotations.DefaultImpl;
|
||||
import mightypork.util.control.Destroyable;
|
||||
import mightypork.util.control.eventbus.EventBus;
|
||||
import mightypork.util.control.timing.Updateable;
|
||||
import mightypork.util.files.InstanceLock;
|
||||
import mightypork.util.logging.Log;
|
||||
import mightypork.util.logging.writers.LogWriter;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,12 +4,12 @@ package mightypork.gamecore.control;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import mightypork.gamecore.control.bus.events.MainLoopTaskRequest;
|
||||
import mightypork.gamecore.control.bus.events.UpdateEvent;
|
||||
import mightypork.gamecore.control.timing.TimerDelta;
|
||||
import mightypork.gamecore.control.events.MainLoopTaskRequest;
|
||||
import mightypork.gamecore.control.events.UpdateEvent;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.gamecore.gui.screens.ScreenRegistry;
|
||||
import mightypork.utils.annotations.DefaultImpl;
|
||||
import mightypork.util.annotations.DefaultImpl;
|
||||
import mightypork.util.control.timing.TimerDelta;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ package mightypork.gamecore.control;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import mightypork.utils.logging.LogWriter;
|
||||
import mightypork.util.logging.writers.LogWriter;
|
||||
|
||||
import org.newdawn.slick.util.LogSystem;
|
||||
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
package mightypork.gamecore.control.bus;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* HashSet that buffers add and remove calls and performs them all at once when
|
||||
* a flush() method is called.
|
||||
*
|
||||
* @author MightyPork
|
||||
* @param <E> element type
|
||||
*/
|
||||
public class BufferedHashSet<E> extends HashSet<E> {
|
||||
|
||||
private final List<E> toAdd = new LinkedList<>();
|
||||
private final List<Object> toRemove = new LinkedList<>();
|
||||
private boolean buffering = false;
|
||||
|
||||
|
||||
/**
|
||||
* make empty
|
||||
*/
|
||||
public BufferedHashSet() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* make from elements of a collection
|
||||
*
|
||||
* @param c
|
||||
*/
|
||||
public BufferedHashSet(Collection<? extends E> c) {
|
||||
super(c);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* make new
|
||||
*
|
||||
* @param initialCapacity
|
||||
* @param loadFactor
|
||||
*/
|
||||
public BufferedHashSet(int initialCapacity, float loadFactor) {
|
||||
super(initialCapacity, loadFactor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* make new
|
||||
*
|
||||
* @param initialCapacity
|
||||
*/
|
||||
public BufferedHashSet(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean add(E e)
|
||||
{
|
||||
if (buffering) {
|
||||
toAdd.add(e);
|
||||
} else {
|
||||
super.add(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean remove(Object e)
|
||||
{
|
||||
if (buffering) {
|
||||
toRemove.add(e);
|
||||
} else {
|
||||
super.remove(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flush all
|
||||
*/
|
||||
private void flush()
|
||||
{
|
||||
for (final E e : toAdd) {
|
||||
super.add(e);
|
||||
}
|
||||
|
||||
for (final Object e : toRemove) {
|
||||
super.remove(e);
|
||||
}
|
||||
|
||||
toAdd.clear();
|
||||
toRemove.clear();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends E> c)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Toggle buffering
|
||||
*
|
||||
* @param enable enable buffering
|
||||
*/
|
||||
public void setBuffering(boolean enable)
|
||||
{
|
||||
if (this.buffering && !enable) {
|
||||
flush();
|
||||
}
|
||||
|
||||
this.buffering = enable;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package mightypork.gamecore.control.bus;
|
||||
|
||||
|
||||
/**
|
||||
* Access to an {@link EventBus} instance
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface BusAccess {
|
||||
|
||||
/**
|
||||
* @return event bus
|
||||
*/
|
||||
EventBus getEventBus();
|
||||
|
||||
}
|
||||
@@ -1,396 +0,0 @@
|
||||
package mightypork.gamecore.control.bus;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.DelayQueue;
|
||||
import java.util.concurrent.Delayed;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import mightypork.gamecore.control.bus.clients.DelegatingClient;
|
||||
import mightypork.gamecore.control.bus.events.Event;
|
||||
import mightypork.gamecore.control.bus.events.types.DelayedEvent;
|
||||
import mightypork.gamecore.control.bus.events.types.ImmediateEvent;
|
||||
import mightypork.gamecore.control.bus.events.types.SingleReceiverEvent;
|
||||
import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
|
||||
/**
|
||||
* An event bus, accommodating multiple {@link EventChannel}s.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
final public class EventBus implements Destroyable {
|
||||
|
||||
/** Message channels */
|
||||
private final BufferedHashSet<EventChannel<?, ?>> channels = new BufferedHashSet<>();
|
||||
|
||||
/** Registered clients */
|
||||
private final BufferedHashSet<Object> clients = new BufferedHashSet<>();
|
||||
|
||||
/** Messages queued for delivery */
|
||||
private final DelayQueue<DelayQueueEntry> sendQueue = new DelayQueue<>();
|
||||
|
||||
/** Queue polling thread */
|
||||
private final QueuePollingThread busThread;
|
||||
|
||||
/** Whether the bus was destroyed */
|
||||
private boolean dead = false;
|
||||
|
||||
/** Log detailed messages (debug) */
|
||||
public boolean detailedLogging = false;
|
||||
|
||||
|
||||
/**
|
||||
* Make a new bus and start it's queue thread.
|
||||
*/
|
||||
public EventBus() {
|
||||
busThread = new QueuePollingThread();
|
||||
busThread.setDaemon(true);
|
||||
busThread.start();
|
||||
}
|
||||
|
||||
|
||||
private boolean shallLog(Event<?> event)
|
||||
{
|
||||
if (!detailedLogging) return false;
|
||||
if (event.getClass().isAnnotationPresent(UnloggedEvent.class)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a {@link EventChannel} to this bus.<br>
|
||||
* If a channel of matching types is already added, it is returned instead.
|
||||
*
|
||||
* @param channel channel to be added
|
||||
* @return the channel that's now in the bus
|
||||
*/
|
||||
public EventChannel<?, ?> addChannel(EventChannel<?, ?> channel)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
// if the channel already exists, return this instance instead.
|
||||
for (final EventChannel<?, ?> ch : channels) {
|
||||
if (ch.equals(channel)) {
|
||||
Log.w("<bus> Channel of type " + Log.str(channel) + " already registered.");
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
|
||||
channels.add(channel);
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make & connect a channel for given event and client type.
|
||||
*
|
||||
* @param eventClass event type
|
||||
* @param clientClass client type
|
||||
* @return the created channel instance
|
||||
*/
|
||||
@FactoryMethod
|
||||
public <F_EVENT extends Event<F_CLIENT>, F_CLIENT> EventChannel<?, ?> addChannel(Class<F_EVENT> eventClass, Class<F_CLIENT> clientClass)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
final EventChannel<F_EVENT, F_CLIENT> channel = EventChannel.create(eventClass, clientClass);
|
||||
return addChannel(channel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a {@link EventChannel} from this bus
|
||||
*
|
||||
* @param channel true if channel was removed
|
||||
*/
|
||||
public void removeChannel(EventChannel<?, ?> channel)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
channels.remove(channel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send based on annotation.clients
|
||||
*
|
||||
* @param event event
|
||||
*/
|
||||
public void send(Event<?> event)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
final DelayedEvent adelay = event.getClass().getAnnotation(DelayedEvent.class);
|
||||
if (adelay != null) {
|
||||
sendDelayed(event, adelay.delay());
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getClass().isAnnotationPresent(ImmediateEvent.class)) {
|
||||
sendDirect(event);
|
||||
return;
|
||||
}
|
||||
|
||||
sendQueued(event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add event to a queue
|
||||
*
|
||||
* @param event event
|
||||
*/
|
||||
public void sendQueued(Event<?> event)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
sendDelayed(event, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add event to a queue, scheduled for given time.
|
||||
*
|
||||
* @param event event
|
||||
* @param delay delay before event is dispatched
|
||||
*/
|
||||
public void sendDelayed(Event<?> event, double delay)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
final DelayQueueEntry dm = new DelayQueueEntry(delay, event);
|
||||
|
||||
if (shallLog(event)) Log.f3("<bus> Qu " + Log.str(event) + ", t = +" + delay + "s");
|
||||
|
||||
sendQueue.add(dm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send immediately.<br>
|
||||
* Should be used for real-time events that require immediate response, such
|
||||
* as timing events.
|
||||
*
|
||||
* @param event event
|
||||
*/
|
||||
public void sendDirect(Event<?> event)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
if (shallLog(event)) Log.f3("<bus> Di " + Log.str(event));
|
||||
|
||||
dispatch(event);
|
||||
}
|
||||
|
||||
|
||||
public void sendDirectToChildren(DelegatingClient delegatingClient, Event<?> event)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
if (shallLog(event)) Log.f3("<bus> Di sub " + Log.str(event));
|
||||
|
||||
doDispatch(delegatingClient.getChildClients(), event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send immediately.<br>
|
||||
* Should be used for real-time events that require immediate response, such
|
||||
* as timing events.
|
||||
*
|
||||
* @param event event
|
||||
*/
|
||||
private void dispatch(Event<?> event)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
channels.setBuffering(true);
|
||||
clients.setBuffering(true);
|
||||
|
||||
doDispatch(clients, event);
|
||||
|
||||
channels.setBuffering(false);
|
||||
clients.setBuffering(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send to a set of clients
|
||||
*
|
||||
* @param clients clients
|
||||
* @param event event
|
||||
*/
|
||||
private void doDispatch(Collection<Object> clients, Event<?> event)
|
||||
{
|
||||
boolean sent = false;
|
||||
boolean accepted = false;
|
||||
|
||||
final boolean singular = event.getClass().isAnnotationPresent(SingleReceiverEvent.class);
|
||||
|
||||
for (final EventChannel<?, ?> b : channels) {
|
||||
if (b.canBroadcast(event)) {
|
||||
accepted = true;
|
||||
sent |= b.broadcast(event, clients);
|
||||
}
|
||||
|
||||
if (sent && singular) break;
|
||||
}
|
||||
|
||||
if (!accepted) Log.e("<bus> Not accepted by any channel: " + Log.str(event));
|
||||
if (!sent && shallLog(event)) Log.w("<bus> Not delivered: " + Log.str(event));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Connect a client to the bus. The client will be connected to all current
|
||||
* and future channels, until removed from the bus.
|
||||
*
|
||||
* @param client the client
|
||||
*/
|
||||
public void subscribe(Object client)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
if (client == null) return;
|
||||
|
||||
clients.add(client);
|
||||
|
||||
if (detailedLogging) Log.f3("<bus> Client joined: " + Log.str(client));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disconnect a client from the bus.
|
||||
*
|
||||
* @param client the client
|
||||
*/
|
||||
public void unsubscribe(Object client)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
clients.remove(client);
|
||||
|
||||
if (detailedLogging) Log.f3("<bus> Client left: " + Log.str(client));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if client can be accepted by any channel
|
||||
*
|
||||
* @param client tested client
|
||||
* @return would be accepted
|
||||
*/
|
||||
public boolean isClientValid(Object client)
|
||||
{
|
||||
assertLive();
|
||||
|
||||
if (client == null) return false;
|
||||
|
||||
for (final EventChannel<?, ?> ch : channels) {
|
||||
if (ch.isClientValid(client)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private class DelayQueueEntry implements Delayed {
|
||||
|
||||
private final long due;
|
||||
private Event<?> evt = null;
|
||||
|
||||
|
||||
public DelayQueueEntry(double seconds, Event<?> event) {
|
||||
super();
|
||||
this.due = System.currentTimeMillis() + (long) (seconds * 1000);
|
||||
this.evt = event;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(Delayed o)
|
||||
{
|
||||
return Long.valueOf(getDelay(TimeUnit.MILLISECONDS)).compareTo(o.getDelay(TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getDelay(TimeUnit unit)
|
||||
{
|
||||
return unit.convert(due - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
||||
public Event<?> getEvent()
|
||||
{
|
||||
return evt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class QueuePollingThread extends Thread {
|
||||
|
||||
public boolean stopped = false;
|
||||
|
||||
|
||||
public QueuePollingThread() {
|
||||
super("Queue Polling Thread");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
DelayQueueEntry evt;
|
||||
|
||||
while (!stopped) {
|
||||
evt = null;
|
||||
|
||||
try {
|
||||
evt = sendQueue.take();
|
||||
} catch (final InterruptedException ignored) {
|
||||
//
|
||||
}
|
||||
|
||||
if (evt != null) {
|
||||
dispatch(evt.getEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Halt bus thread and reject any future events.
|
||||
*/
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
assertLive();
|
||||
|
||||
busThread.stopped = true;
|
||||
|
||||
dead = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make sure the bus is not destroyed.
|
||||
*
|
||||
* @throws IllegalStateException if the bus is dead.
|
||||
*/
|
||||
private void assertLive() throws IllegalStateException
|
||||
{
|
||||
if (dead) throw new IllegalStateException("EventBus is dead.");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,215 +0,0 @@
|
||||
package mightypork.gamecore.control.bus;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
import mightypork.gamecore.control.bus.clients.DelegatingClient;
|
||||
import mightypork.gamecore.control.bus.clients.ToggleableClient;
|
||||
import mightypork.gamecore.control.bus.events.Event;
|
||||
import mightypork.gamecore.control.bus.events.types.SingleReceiverEvent;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
|
||||
/**
|
||||
* Event delivery channel, module of {@link EventBus}
|
||||
*
|
||||
* @author MightyPork
|
||||
* @param <EVENT> event type
|
||||
* @param <CLIENT> client (subscriber) type
|
||||
*/
|
||||
final public class EventChannel<EVENT extends Event<CLIENT>, CLIENT> {
|
||||
|
||||
private final Class<CLIENT> clientClass;
|
||||
private final Class<EVENT> eventClass;
|
||||
|
||||
|
||||
/**
|
||||
* Create a channel
|
||||
*
|
||||
* @param eventClass event class
|
||||
* @param clientClass client class
|
||||
*/
|
||||
public EventChannel(Class<EVENT> eventClass, Class<CLIENT> clientClass) {
|
||||
|
||||
if (eventClass == null || clientClass == null) {
|
||||
throw new NullPointerException("Null Event or Client class.");
|
||||
}
|
||||
|
||||
this.clientClass = clientClass;
|
||||
this.eventClass = eventClass;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Try to broadcast a event.<br>
|
||||
* If event is of wrong type, <code>false</code> is returned.
|
||||
*
|
||||
* @param event a event to be sent
|
||||
* @param clients collection of clients
|
||||
* @return true if event was sent
|
||||
*/
|
||||
public boolean broadcast(Event<?> event, Collection<Object> clients)
|
||||
{
|
||||
if (!canBroadcast(event)) return false;
|
||||
|
||||
return doBroadcast(eventClass.cast(event), clients, new HashSet<>());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send the event
|
||||
*
|
||||
* @param event sent event
|
||||
* @param clients subscribing clients
|
||||
* @param processed clients already processed
|
||||
* @return success
|
||||
*/
|
||||
private boolean doBroadcast(final EVENT event, final Collection<Object> clients, final Collection<Object> processed)
|
||||
{
|
||||
boolean sent = false;
|
||||
final boolean singular = event.getClass().isAnnotationPresent(SingleReceiverEvent.class);
|
||||
|
||||
for (final Object client : clients) {
|
||||
|
||||
// exclude obvious non-clients
|
||||
if (!isClientValid(client)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// avoid executing more times
|
||||
if (processed.contains(client)) {
|
||||
Log.w("<bus> Client already served: " + Log.str(client));
|
||||
continue;
|
||||
}
|
||||
processed.add(client);
|
||||
|
||||
// opt-out
|
||||
if (client instanceof ToggleableClient) {
|
||||
if (!((ToggleableClient) client).isListening()) continue;
|
||||
}
|
||||
|
||||
sent |= sendTo(client, event);
|
||||
|
||||
// singular event ain't no whore, handled once only.
|
||||
if (sent && singular) return true;
|
||||
|
||||
// pass on to delegated clients
|
||||
if (client instanceof DelegatingClient) {
|
||||
if (((DelegatingClient) client).doesDelegate()) {
|
||||
|
||||
final Collection<Object> children = ((DelegatingClient) client).getChildClients();
|
||||
|
||||
if (children != null && children.size() > 0) {
|
||||
sent |= doBroadcast(event, children, processed);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send an event to a client.
|
||||
*
|
||||
* @param client target client
|
||||
* @param event event to send
|
||||
* @return success
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean sendTo(Object client, EVENT event)
|
||||
{
|
||||
if (isClientOfType(client)) {
|
||||
((Event<CLIENT>) event).handleBy((CLIENT) client);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the given event can be broadcasted by this {@link EventChannel}
|
||||
*
|
||||
* @param event event object
|
||||
* @return can be broadcasted
|
||||
*/
|
||||
public boolean canBroadcast(Event<?> event)
|
||||
{
|
||||
return event != null && eventClass.isInstance(event);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an instance for given types
|
||||
*
|
||||
* @param eventClass event class
|
||||
* @param clientClass client class
|
||||
* @return the broadcaster
|
||||
*/
|
||||
public static <F_EVENT extends Event<F_CLIENT>, F_CLIENT> EventChannel<F_EVENT, F_CLIENT> create(Class<F_EVENT> eventClass, Class<F_CLIENT> clientClass)
|
||||
{
|
||||
return new EventChannel<>(eventClass, clientClass);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if client is of channel type
|
||||
*
|
||||
* @param client client
|
||||
* @return is of type
|
||||
*/
|
||||
private boolean isClientOfType(Object client)
|
||||
{
|
||||
return clientClass.isInstance(client);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the channel is compatible with given
|
||||
*
|
||||
* @param client client
|
||||
* @return is supported
|
||||
*/
|
||||
public boolean isClientValid(Object client)
|
||||
{
|
||||
return isClientOfType(client) || (client instanceof DelegatingClient);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 13;
|
||||
int result = 1;
|
||||
result = prime * result + ((clientClass == null) ? 0 : clientClass.hashCode());
|
||||
result = prime * result + ((eventClass == null) ? 0 : eventClass.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj) return true;
|
||||
if (obj == null) return false;
|
||||
if (!(obj instanceof EventChannel)) return false;
|
||||
final EventChannel<?, ?> other = (EventChannel<?, ?>) obj;
|
||||
if (clientClass == null) {
|
||||
if (other.clientClass != null) return false;
|
||||
} else if (!clientClass.equals(other.clientClass)) return false;
|
||||
if (eventClass == null) {
|
||||
if (other.eventClass != null) return false;
|
||||
} else if (!eventClass.equals(other.eventClass)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "{ " + Log.str(eventClass) + " => " + Log.str(clientClass) + " }";
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
package mightypork.gamecore.control.bus.clients;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mightypork.gamecore.control.bus.BusAccess;
|
||||
import mightypork.gamecore.control.bus.EventBus;
|
||||
|
||||
|
||||
/**
|
||||
* Client that can be attached to the {@link EventBus}, or added as a child
|
||||
* client to another {@link DelegatingClient}
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class BusNode implements BusAccess, ClientHub {
|
||||
|
||||
private final BusAccess busAccess;
|
||||
|
||||
private final Set<Object> clients = new LinkedHashSet<>();
|
||||
private boolean listening = true;
|
||||
private boolean delegating = true;
|
||||
|
||||
|
||||
/**
|
||||
* @param busAccess access to bus
|
||||
*/
|
||||
public BusNode(BusAccess busAccess) {
|
||||
this.busAccess = busAccess;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final Collection<Object> getChildClients()
|
||||
{
|
||||
return clients;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final boolean doesDelegate()
|
||||
{
|
||||
return delegating;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final boolean isListening()
|
||||
{
|
||||
return listening;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a child subscriber to the {@link EventBus}.<br>
|
||||
*
|
||||
* @param client
|
||||
*/
|
||||
@Override
|
||||
public final void addChildClient(Object client)
|
||||
{
|
||||
if (client instanceof RootBusNode) {
|
||||
throw new IllegalArgumentException("Cannot nest RootBusNode.");
|
||||
}
|
||||
|
||||
if (getEventBus().isClientValid(client)) {
|
||||
clients.add(client);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a child subscriber
|
||||
*
|
||||
* @param client subscriber to remove
|
||||
*/
|
||||
@Override
|
||||
public final void removeChildClient(Object client)
|
||||
{
|
||||
if (client != null) {
|
||||
clients.remove(client);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set whether events should be received.
|
||||
*
|
||||
* @param listening receive events
|
||||
*/
|
||||
public final void setListening(boolean listening)
|
||||
{
|
||||
this.listening = listening;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set whether events should be passed on to child nodes
|
||||
*
|
||||
* @param delegating
|
||||
*/
|
||||
public final void setDelegating(boolean delegating)
|
||||
{
|
||||
this.delegating = delegating;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final EventBus getEventBus()
|
||||
{
|
||||
return busAccess.getEventBus();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package mightypork.gamecore.control.bus.clients;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import mightypork.gamecore.control.bus.EventBus;
|
||||
|
||||
|
||||
/**
|
||||
* Common methods for client hubs (ie delegating vlient implementations)
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface ClientHub extends DelegatingClient, ToggleableClient {
|
||||
|
||||
@Override
|
||||
public boolean doesDelegate();
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<Object> getChildClients();
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isListening();
|
||||
|
||||
|
||||
/**
|
||||
* Add a child subscriber to the {@link EventBus}.<br>
|
||||
*
|
||||
* @param client
|
||||
*/
|
||||
public void addChildClient(Object client);
|
||||
|
||||
|
||||
/**
|
||||
* Remove a child subscriber
|
||||
*
|
||||
* @param client subscriber to remove
|
||||
*/
|
||||
void removeChildClient(Object client);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package mightypork.gamecore.control.bus.clients;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
/**
|
||||
* Client containing child clients. According to the contract, if the collection
|
||||
* of clients is ordered, the clients will be served in that order. In any case,
|
||||
* the {@link DelegatingClient} itself will be served beforehand.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface DelegatingClient {
|
||||
|
||||
/**
|
||||
* @return collection of child clients. Can not be null.
|
||||
*/
|
||||
public Collection<Object> getChildClients();
|
||||
|
||||
|
||||
/**
|
||||
* @return true if delegating is active
|
||||
*/
|
||||
public boolean doesDelegate();
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package mightypork.gamecore.control.bus.clients;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.BusAccess;
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
|
||||
|
||||
/**
|
||||
* Bus node that should be directly attached to the bus.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class RootBusNode extends BusNode implements Destroyable {
|
||||
|
||||
/**
|
||||
* @param busAccess access to bus
|
||||
*/
|
||||
public RootBusNode(BusAccess busAccess) {
|
||||
super(busAccess);
|
||||
|
||||
getEventBus().subscribe(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void destroy()
|
||||
{
|
||||
deinit();
|
||||
|
||||
getEventBus().unsubscribe(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deinitialize the subsystem<br>
|
||||
* (called during destruction)
|
||||
*/
|
||||
protected abstract void deinit();
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package mightypork.gamecore.control.bus.clients;
|
||||
|
||||
|
||||
/**
|
||||
* Client that can toggle receiving messages.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface ToggleableClient {
|
||||
|
||||
/**
|
||||
* @return true if the client wants to receive messages
|
||||
*/
|
||||
public boolean isListening();
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.types.DelayedEvent;
|
||||
import mightypork.gamecore.control.bus.events.types.ImmediateEvent;
|
||||
import mightypork.gamecore.control.bus.events.types.SingleReceiverEvent;
|
||||
import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Something that can be handled by HANDLER.
|
||||
* </p>
|
||||
* <p>
|
||||
* Can be annotated as {@link SingleReceiverEvent} to be delivered once only,
|
||||
* and {@link DelayedEvent} or {@link ImmediateEvent} to specify default sending
|
||||
* mode. When marked as {@link UnloggedEvent}, it will not appear in detailed
|
||||
* bus logging (useful for very frequent events, such as UpdateEvent).
|
||||
* </p>
|
||||
* <p>
|
||||
* Default sending mode (if not changed by annotations) is <i>queued</i> with
|
||||
* zero delay.
|
||||
* </p>
|
||||
*
|
||||
* @author MightyPork
|
||||
* @param <HANDLER> handler type
|
||||
*/
|
||||
public interface Event<HANDLER> {
|
||||
|
||||
/**
|
||||
* Ask handler to handle this message.
|
||||
*
|
||||
* @param handler handler instance
|
||||
*/
|
||||
public void handleBy(HANDLER handler);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package mightypork.gamecore.control.bus.events.types;
|
||||
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* Event that should be queued with given delay (default: 0);
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Inherited
|
||||
@Documented
|
||||
public @interface DelayedEvent {
|
||||
|
||||
/**
|
||||
* @return event dispatch delay [seconds]
|
||||
*/
|
||||
double delay() default 0;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package mightypork.gamecore.control.bus.events.types;
|
||||
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* Event that should not be queued.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Inherited
|
||||
@Documented
|
||||
public @interface ImmediateEvent {}
|
||||
@@ -1,16 +0,0 @@
|
||||
package mightypork.gamecore.control.bus.events.types;
|
||||
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* Handled only by the first client, then discarded.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Inherited
|
||||
@Documented
|
||||
public @interface SingleReceiverEvent {}
|
||||
@@ -1,17 +0,0 @@
|
||||
package mightypork.gamecore.control.bus.events.types;
|
||||
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* Event that's not worth logging, unless there was an error with it.<br>
|
||||
* Useful for common events that would otherwise clutter the log.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Inherited
|
||||
@Documented
|
||||
public @interface UnloggedEvent {}
|
||||
+4
-3
@@ -1,8 +1,9 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
package mightypork.gamecore.control.events;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.types.ImmediateEvent;
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
import mightypork.util.control.Destroyable;
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.control.eventbus.events.flags.ImmediateEvent;
|
||||
|
||||
|
||||
/**
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
package mightypork.gamecore.control.events;
|
||||
|
||||
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
|
||||
+4
-2
@@ -1,7 +1,8 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
package mightypork.gamecore.control.events;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.types.ImmediateEvent;
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.control.eventbus.events.flags.ImmediateEvent;
|
||||
|
||||
|
||||
/**
|
||||
@@ -24,6 +25,7 @@ public class LayoutChangeEvent implements Event<LayoutChangeEvent.Listener> {
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
|
||||
public void onLayoutChanged();
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
package mightypork.gamecore.control.events;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.types.SingleReceiverEvent;
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent;
|
||||
|
||||
|
||||
/**
|
||||
+4
-3
@@ -1,8 +1,9 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
package mightypork.gamecore.control.events;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
+5
-4
@@ -1,9 +1,10 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
package mightypork.gamecore.control.events;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.utils.math.constraints.vect.VectConst;
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.control.eventbus.events.flags.UnloggedEvent;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
import mightypork.util.math.constraints.vect.VectConst;
|
||||
|
||||
|
||||
/**
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
package mightypork.gamecore.control.events;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.types.SingleReceiverEvent;
|
||||
import mightypork.gamecore.loading.Deferred;
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent;
|
||||
|
||||
|
||||
/**
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
package mightypork.gamecore.control.events;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
package mightypork.gamecore.control.events;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.types.SingleReceiverEvent;
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.control.eventbus.events.flags.SingleReceiverEvent;
|
||||
|
||||
|
||||
/**
|
||||
+5
-4
@@ -1,9 +1,10 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
package mightypork.gamecore.control.events;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.types.ImmediateEvent;
|
||||
import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
import mightypork.util.control.eventbus.events.flags.ImmediateEvent;
|
||||
import mightypork.util.control.eventbus.events.flags.UnloggedEvent;
|
||||
import mightypork.util.control.timing.Updateable;
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,15 +0,0 @@
|
||||
package mightypork.gamecore.control.interf;
|
||||
|
||||
|
||||
/**
|
||||
* Object that can be destroyed (free resources etc)
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface Destroyable {
|
||||
|
||||
/**
|
||||
* Destroy this object
|
||||
*/
|
||||
public void destroy();
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package mightypork.gamecore.control.interf;
|
||||
|
||||
|
||||
/**
|
||||
* Can be enabled or disabled.<br>
|
||||
* Implementations should take appropriate action (ie. stop listening to events,
|
||||
* updating etc.)
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface Enableable {
|
||||
|
||||
/**
|
||||
* Change enabled state
|
||||
*
|
||||
* @param yes enabled
|
||||
*/
|
||||
public void enable(boolean yes);
|
||||
|
||||
|
||||
/**
|
||||
* @return true if enabled
|
||||
*/
|
||||
public boolean isEnabled();
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package mightypork.gamecore.control.timing;
|
||||
|
||||
|
||||
/**
|
||||
* Class for counting FPS in games.<br>
|
||||
* This class can be used also as a simple frequency meter - output is in Hz.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class FpsMeter {
|
||||
|
||||
private long frames = 0;
|
||||
private long lastTimeMillis = System.currentTimeMillis();
|
||||
private long lastSecFPS = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @return current second's FPS
|
||||
*/
|
||||
public long getFPS()
|
||||
{
|
||||
return lastSecFPS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notification that frame was rendered
|
||||
*/
|
||||
public void frame()
|
||||
{
|
||||
if (System.currentTimeMillis() - lastTimeMillis > 1000) {
|
||||
lastSecFPS = frames;
|
||||
frames = 0;
|
||||
final long over = System.currentTimeMillis() - lastTimeMillis - 1000;
|
||||
lastTimeMillis = System.currentTimeMillis() - over;
|
||||
}
|
||||
frames++;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package mightypork.gamecore.control.timing;
|
||||
|
||||
|
||||
/**
|
||||
* Can be paused & resumed
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface Pauseable {
|
||||
|
||||
/**
|
||||
* Pause operation
|
||||
*/
|
||||
public void pause();
|
||||
|
||||
|
||||
/**
|
||||
* Resume operation
|
||||
*/
|
||||
public void resume();
|
||||
|
||||
|
||||
/**
|
||||
* @return paused state
|
||||
*/
|
||||
public boolean isPaused();
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package mightypork.gamecore.control.timing;
|
||||
|
||||
|
||||
/**
|
||||
* Timer for delta timing
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class TimerDelta {
|
||||
|
||||
private long lastFrame;
|
||||
|
||||
private static final long SECOND = 1000000000; // a million nanoseconds
|
||||
|
||||
|
||||
/**
|
||||
* New delta timer
|
||||
*/
|
||||
public TimerDelta() {
|
||||
lastFrame = System.nanoTime();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get current time in NS
|
||||
*
|
||||
* @return current time NS
|
||||
*/
|
||||
public long getTime()
|
||||
{
|
||||
return System.nanoTime();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get time since the last "getDelta()" call.
|
||||
*
|
||||
* @return delta time (seconds)
|
||||
*/
|
||||
public double getDelta()
|
||||
{
|
||||
final long time = getTime();
|
||||
final double delta = (time - lastFrame) / (double) SECOND;
|
||||
lastFrame = time;
|
||||
return delta;
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
package mightypork.gamecore.control.timing;
|
||||
|
||||
|
||||
/**
|
||||
* Timer for interpolated timing
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class TimerFps {
|
||||
|
||||
private long lastFrame = 0;
|
||||
private long nextFrame = 0;
|
||||
private long skipped = 0;
|
||||
private long lastSkipped = 0;
|
||||
|
||||
private static final long SECOND = 1000000000; // a million nanoseconds
|
||||
private final long FRAME; // a time of one frame in nanoseconds
|
||||
|
||||
|
||||
/**
|
||||
* New interpolated timer
|
||||
*
|
||||
* @param fps target FPS
|
||||
*/
|
||||
public TimerFps(long fps) {
|
||||
FRAME = Math.round(SECOND / (double) fps);
|
||||
|
||||
lastFrame = System.nanoTime();
|
||||
nextFrame = System.nanoTime() + FRAME;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sync and calculate dropped frames etc.
|
||||
*/
|
||||
public void sync()
|
||||
{
|
||||
final long time = getTime();
|
||||
if (time >= nextFrame) {
|
||||
final long skippedNow = (long) Math.floor((time - nextFrame) / (double) FRAME) + 1;
|
||||
skipped += skippedNow;
|
||||
lastFrame = nextFrame + (1 - skippedNow) * FRAME;
|
||||
nextFrame += skippedNow * FRAME;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get nanotime
|
||||
*
|
||||
* @return nanotime
|
||||
*/
|
||||
public long getTime()
|
||||
{
|
||||
return System.nanoTime();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get fraction of next frame
|
||||
*
|
||||
* @return fraction
|
||||
*/
|
||||
public double getFraction()
|
||||
{
|
||||
if (getSkipped() >= 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
final long time = getTime();
|
||||
|
||||
if (time <= nextFrame) {
|
||||
return (double) (time - lastFrame) / (double) FRAME;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get number of elapsed ticks
|
||||
*
|
||||
* @return ticks
|
||||
*/
|
||||
public int getSkipped()
|
||||
{
|
||||
final long change = skipped - lastSkipped;
|
||||
lastSkipped = skipped;
|
||||
return (int) change;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear timer and start counting new tick.
|
||||
*/
|
||||
public void startNewFrame()
|
||||
{
|
||||
final long time = getTime();
|
||||
lastFrame = time;
|
||||
nextFrame = time + FRAME;
|
||||
lastSkipped = skipped;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package mightypork.gamecore.control.timing;
|
||||
|
||||
|
||||
/**
|
||||
* Uses delta timing
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface Updateable {
|
||||
|
||||
/**
|
||||
* Update item state based on elapsed time
|
||||
*
|
||||
* @param delta time elapsed since last update, in seconds
|
||||
*/
|
||||
public void update(double delta);
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package mightypork.gamecore.gui;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.interf.Enableable;
|
||||
|
||||
|
||||
/**
|
||||
* Triggered action
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class Action implements Runnable, Enableable {
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
|
||||
/**
|
||||
* Enable the action
|
||||
*
|
||||
* @param enable true to enable
|
||||
*/
|
||||
@Override
|
||||
public final void enable(boolean enable)
|
||||
{
|
||||
this.enabled = enable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true if this action is enabled.
|
||||
*/
|
||||
@Override
|
||||
public final boolean isEnabled()
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the action, if it's enabled.
|
||||
*/
|
||||
@Override
|
||||
public final void run()
|
||||
{
|
||||
if (enabled) execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do the work.
|
||||
*/
|
||||
protected abstract void execute();
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package mightypork.gamecore.gui;
|
||||
|
||||
|
||||
/**
|
||||
* Element that can be assigned an action (ie. button);
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface ActionTrigger {
|
||||
|
||||
/**
|
||||
* Assign an action
|
||||
*
|
||||
* @param action action
|
||||
*/
|
||||
void setAction(Action action);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.gamecore.gui;
|
||||
|
||||
|
||||
/**
|
||||
* Horizontal align sides
|
||||
*
|
||||
@@ -8,4 +9,4 @@ package mightypork.gamecore.gui;
|
||||
public enum AlignX
|
||||
{
|
||||
LEFT, CENTER, RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.gamecore.gui;
|
||||
|
||||
|
||||
/**
|
||||
* Vertical align sides
|
||||
*
|
||||
@@ -8,4 +9,4 @@ package mightypork.gamecore.gui;
|
||||
public enum AlignY
|
||||
{
|
||||
TOP, CENTER, BOTTOM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.gamecore.gui.components;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.events.MouseButtonEvent;
|
||||
|
||||
|
||||
public abstract class ClickableComponent extends InputComponent {
|
||||
|
||||
@@ -2,8 +2,8 @@ package mightypork.gamecore.gui.components;
|
||||
|
||||
|
||||
import mightypork.gamecore.gui.Hideable;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package mightypork.gamecore.gui.components;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.interf.Enableable;
|
||||
import mightypork.gamecore.gui.Action;
|
||||
import mightypork.gamecore.gui.ActionTrigger;
|
||||
import mightypork.gamecore.control.events.MouseButtonEvent;
|
||||
import mightypork.util.control.Action;
|
||||
import mightypork.util.control.ActionTrigger;
|
||||
import mightypork.util.control.Enableable;
|
||||
|
||||
|
||||
public abstract class InputComponent extends VisualComponent implements Enableable, ActionTrigger, MouseButtonEvent.Listener {
|
||||
@@ -33,7 +33,9 @@ public abstract class InputComponent extends VisualComponent implements Enableab
|
||||
return enabled;
|
||||
}
|
||||
|
||||
protected void triggerAction() {
|
||||
if(action != null) action.run();
|
||||
|
||||
protected void triggerAction()
|
||||
{
|
||||
if (action != null) action.run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ import java.util.LinkedList;
|
||||
import mightypork.gamecore.audio.SoundSystem;
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppSubModule;
|
||||
import mightypork.gamecore.control.bus.EventBus;
|
||||
import mightypork.gamecore.control.bus.clients.ClientHub;
|
||||
import mightypork.gamecore.control.interf.Enableable;
|
||||
import mightypork.gamecore.input.InputSystem;
|
||||
import mightypork.gamecore.render.DisplaySystem;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.util.control.Enableable;
|
||||
import mightypork.util.control.eventbus.EventBus;
|
||||
import mightypork.util.control.eventbus.clients.ClientHub;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
|
||||
|
||||
public abstract class LayoutComponent extends VisualComponent implements Enableable, ClientHub, AppAccess {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package mightypork.gamecore.gui.components;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.rect.proxy.PluggableRectBound;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
import mightypork.util.math.constraints.rect.proxy.PluggableRectBound;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package mightypork.gamecore.gui.components;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.LayoutChangeEvent;
|
||||
import mightypork.utils.annotations.DefaultImpl;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.rect.caching.AbstractRectCache;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBoundAdapter;
|
||||
import mightypork.gamecore.control.events.LayoutChangeEvent;
|
||||
import mightypork.util.annotations.DefaultImpl;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
import mightypork.util.math.constraints.rect.caching.AbstractRectCache;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBoundAdapter;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,10 +2,10 @@ package mightypork.gamecore.gui.components.layout;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||
import mightypork.gamecore.gui.components.Component;
|
||||
import mightypork.utils.math.constraints.rect.builders.TiledRect;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||
import mightypork.util.math.constraints.rect.builders.TiledRect;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,9 +2,9 @@ package mightypork.gamecore.gui.components.layout;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||
import mightypork.gamecore.gui.components.Component;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,11 +3,11 @@ package mightypork.gamecore.gui.components.layout;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.gui.AlignX;
|
||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||
import mightypork.gamecore.gui.components.Component;
|
||||
import mightypork.utils.math.constraints.num.Num;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||
import mightypork.util.math.constraints.num.Num;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,10 +2,10 @@ package mightypork.gamecore.gui.components.layout;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||
import mightypork.gamecore.gui.components.Component;
|
||||
import mightypork.utils.math.constraints.rect.builders.TiledRect;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||
import mightypork.util.math.constraints.rect.builders.TiledRect;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,11 +3,11 @@ package mightypork.gamecore.gui.components.layout;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.gui.AlignY;
|
||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||
import mightypork.gamecore.gui.components.Component;
|
||||
import mightypork.utils.math.constraints.num.Num;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.gamecore.gui.components.LayoutComponent;
|
||||
import mightypork.util.math.constraints.num.Num;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,8 +3,8 @@ package mightypork.gamecore.gui.components.painters;
|
||||
|
||||
import mightypork.gamecore.gui.components.VisualComponent;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.util.annotations.FactoryMethod;
|
||||
import mightypork.util.math.color.Color;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,11 +5,11 @@ import mightypork.gamecore.gui.AlignX;
|
||||
import mightypork.gamecore.gui.components.VisualComponent;
|
||||
import mightypork.gamecore.render.fonts.FontRenderer;
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.utils.string.StringProvider;
|
||||
import mightypork.utils.string.StringProvider.StringWrapper;
|
||||
import mightypork.util.math.color.Color;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
import mightypork.util.string.StringProvider;
|
||||
import mightypork.util.string.StringProvider.StringWrapper;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.Collection;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,17 +3,17 @@ package mightypork.gamecore.gui.screens;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppSubModule;
|
||||
import mightypork.gamecore.control.bus.events.LayoutChangeEvent;
|
||||
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
||||
import mightypork.gamecore.control.events.LayoutChangeEvent;
|
||||
import mightypork.gamecore.control.events.ScreenChangeEvent;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.gamecore.input.KeyBinder;
|
||||
import mightypork.gamecore.input.KeyBindingPool;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.annotations.DefaultImpl;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.util.annotations.DefaultImpl;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,15 +5,15 @@ import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import mightypork.gamecore.control.AppSubModule;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.gamecore.gui.Hideable;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.gamecore.gui.components.layout.ConstraintLayout;
|
||||
import mightypork.gamecore.input.KeyBinder;
|
||||
import mightypork.gamecore.input.KeyBindingPool;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.utils.annotations.DefaultImpl;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.util.annotations.DefaultImpl;
|
||||
import mightypork.util.control.timing.Updateable;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,10 +5,10 @@ import java.util.HashMap;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppModule;
|
||||
import mightypork.gamecore.control.bus.events.ScreenRequestEvent;
|
||||
import mightypork.gamecore.control.events.ScreenRequestEvent;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.utils.annotations.DefaultImpl;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.util.annotations.DefaultImpl;
|
||||
import mightypork.util.logging.Log;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,15 +2,15 @@ package mightypork.gamecore.input;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.bus.clients.RootBusNode;
|
||||
import mightypork.gamecore.control.bus.events.KeyEvent;
|
||||
import mightypork.gamecore.control.bus.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.bus.events.MouseMotionEvent;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.gamecore.control.events.KeyEvent;
|
||||
import mightypork.gamecore.control.events.MouseButtonEvent;
|
||||
import mightypork.gamecore.control.events.MouseMotionEvent;
|
||||
import mightypork.rogue.events.ActionRequest;
|
||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.utils.math.constraints.vect.mutable.VectVar;
|
||||
import mightypork.util.control.eventbus.clients.RootBusNode;
|
||||
import mightypork.util.control.timing.Updateable;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
import mightypork.util.math.constraints.vect.mutable.VectVar;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
@@ -174,7 +174,8 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
|
||||
|
||||
/**
|
||||
* Get absolute mouse position. This vect is final and views at it can safely be made.
|
||||
* Get absolute mouse position. This vect is final and views at it can
|
||||
* safely be made.
|
||||
*
|
||||
* @return mouse position
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.gamecore.input;
|
||||
|
||||
|
||||
import mightypork.gamecore.gui.Action;
|
||||
import mightypork.util.control.Action;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.gamecore.input;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.KeyEvent;
|
||||
import mightypork.gamecore.control.events.KeyEvent;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import mightypork.gamecore.control.bus.events.KeyEvent;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.gamecore.control.events.KeyEvent;
|
||||
import mightypork.util.logging.Log;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,12 +5,12 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import mightypork.gamecore.control.bus.BusAccess;
|
||||
import mightypork.gamecore.control.bus.events.MainLoopTaskRequest;
|
||||
import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.gamecore.control.events.MainLoopTaskRequest;
|
||||
import mightypork.gamecore.control.events.ResourceLoadRequest;
|
||||
import mightypork.util.annotations.FactoryMethod;
|
||||
import mightypork.util.control.Destroyable;
|
||||
import mightypork.util.control.eventbus.BusAccess;
|
||||
import mightypork.util.logging.Log;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package mightypork.gamecore.loading;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.interf.Destroyable;
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.util.control.Destroyable;
|
||||
import mightypork.util.logging.Log;
|
||||
import mightypork.util.logging.LogAlias;
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@ import mightypork.utils.logging.Log;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@Alias(name = "Resource")
|
||||
@LogAlias(name = "Resource")
|
||||
public abstract class DeferredResource implements Deferred, Destroyable {
|
||||
|
||||
private final String resource;
|
||||
|
||||
@@ -7,12 +7,12 @@ import java.nio.ByteBuffer;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppModule;
|
||||
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
||||
import mightypork.gamecore.control.timing.FpsMeter;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.gamecore.control.events.ScreenChangeEvent;
|
||||
import mightypork.util.control.timing.FpsMeter;
|
||||
import mightypork.util.logging.Log;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
import mightypork.util.math.constraints.rect.proxy.RectBound;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
|
||||
@@ -6,13 +6,13 @@ import static org.lwjgl.opengl.GL11.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import mightypork.gamecore.render.textures.TxQuad;
|
||||
import mightypork.utils.files.FileUtils;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.rect.caching.RectDigest;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.utils.math.constraints.vect.VectConst;
|
||||
import mightypork.util.files.FileUtils;
|
||||
import mightypork.util.logging.Log;
|
||||
import mightypork.util.math.color.Color;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
import mightypork.util.math.constraints.rect.caching.RectDigest;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
import mightypork.util.math.constraints.vect.VectConst;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.HashMap;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppAdapter;
|
||||
import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
|
||||
import mightypork.gamecore.control.events.ResourceLoadRequest;
|
||||
import mightypork.gamecore.render.fonts.impl.DeferredFont;
|
||||
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
@@ -16,7 +16,7 @@ import org.newdawn.slick.opengl.Texture;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class FontBank extends AppAdapter {
|
||||
public class FontBank extends AppAdapter {
|
||||
|
||||
/**
|
||||
* @param app app access
|
||||
@@ -53,7 +53,8 @@ public class FontBank extends AppAdapter {
|
||||
{
|
||||
fonts.put(key, font);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add a font alias.
|
||||
*
|
||||
@@ -76,9 +77,9 @@ public class FontBank extends AppAdapter {
|
||||
{
|
||||
GLFont f = fonts.get(key);
|
||||
|
||||
if(f == null) f = fonts.get(aliases.get(key));
|
||||
if (f == null) f = fonts.get(aliases.get(key));
|
||||
|
||||
if (f == null) {
|
||||
if (f == null) {
|
||||
throw new RuntimeException("There's no font called " + key + "!");
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package mightypork.gamecore.render.fonts;
|
||||
|
||||
import mightypork.gamecore.gui.AlignX;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.util.math.color.Color;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package mightypork.gamecore.render.fonts;
|
||||
|
||||
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.util.math.color.Color;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,10 +20,10 @@ import java.util.Map;
|
||||
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.gamecore.render.textures.FilterMode;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.utils.math.constraints.vect.VectConst;
|
||||
import mightypork.util.logging.Log;
|
||||
import mightypork.util.math.color.Color;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
import mightypork.util.math.constraints.vect.VectConst;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
@@ -294,8 +294,7 @@ public class CachedFont implements GLFont {
|
||||
|
||||
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI);
|
||||
} else {
|
||||
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder())
|
||||
.put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
|
||||
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
|
||||
}
|
||||
|
||||
byteBuffer.flip();
|
||||
@@ -413,8 +412,7 @@ public class CachedFont implements GLFont {
|
||||
chtx = chars.get(charCurrent);
|
||||
|
||||
if (chtx != null) {
|
||||
drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY
|
||||
+ chtx.height);
|
||||
drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY + chtx.height);
|
||||
totalwidth += chtx.width;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import mightypork.gamecore.loading.DeferredResource;
|
||||
import mightypork.gamecore.loading.MustLoadInMainThread;
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.gamecore.render.textures.FilterMode;
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.utils.files.FileUtils;
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.util.files.FileUtils;
|
||||
import mightypork.util.logging.LogAlias;
|
||||
import mightypork.util.math.color.Color;
|
||||
import mightypork.util.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
@@ -22,7 +22,7 @@ import mightypork.utils.math.constraints.vect.Vect;
|
||||
* @author MightyPork
|
||||
*/
|
||||
@MustLoadInMainThread
|
||||
@Alias(name = "Font")
|
||||
@LogAlias(name = "Font")
|
||||
public class DeferredFont extends DeferredResource implements GLFont {
|
||||
|
||||
public static enum FontStyle
|
||||
@@ -129,7 +129,7 @@ public class DeferredFont extends DeferredResource implements GLFont {
|
||||
*/
|
||||
protected Font getAwtFont(String resource, float size, int style) throws FontFormatException, IOException
|
||||
{
|
||||
try(InputStream in = FileUtils.getResource(resource)) {
|
||||
try (InputStream in = FileUtils.getResource(resource)) {
|
||||
|
||||
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, in);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.awt.FontFormatException;
|
||||
import java.io.IOException;
|
||||
|
||||
import mightypork.gamecore.render.textures.FilterMode;
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.util.logging.LogAlias;
|
||||
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@ import mightypork.utils.annotations.Alias;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@Alias(name = "FontNative")
|
||||
@LogAlias(name = "FontNative")
|
||||
public class DeferredFontNative extends DeferredFont {
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,8 +4,8 @@ package mightypork.gamecore.render.textures;
|
||||
import mightypork.gamecore.loading.DeferredResource;
|
||||
import mightypork.gamecore.loading.MustLoadInMainThread;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.util.logging.LogAlias;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
@@ -17,7 +17,7 @@ import org.newdawn.slick.opengl.Texture;
|
||||
* @author MightyPork
|
||||
*/
|
||||
@MustLoadInMainThread
|
||||
@Alias(name = "Texture")
|
||||
@LogAlias(name = "Texture")
|
||||
public class DeferredTexture extends DeferredResource implements FilteredTexture {
|
||||
|
||||
private Texture backingTexture;
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.util.HashMap;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppAdapter;
|
||||
import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.gamecore.control.events.ResourceLoadRequest;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.gamecore.render.textures;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.util.math.constraints.rect.Rect;
|
||||
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user