forked from MagicBane/Server
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.8 KiB
75 lines
2.8 KiB
3 years ago
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||
|
// Magicbane Emulator Project © 2013 - 2022
|
||
|
// www.magicbane.com
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||
|
// Magicbane Emulator Project © 2013 - 2022
|
||
|
// www.magicbane.com
|
||
|
|
||
|
|
||
|
|
||
|
package engine.net;
|
||
|
|
||
|
import engine.objects.PlayerCharacter;
|
||
|
|
||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||
|
|
||
|
import static engine.net.MessageDispatcher.itemPoolSize;
|
||
|
|
||
|
/**
|
||
|
* Data class holds a message and a distribution list
|
||
|
*/
|
||
|
|
||
|
public class Dispatch {
|
||
|
|
||
|
private static final ConcurrentLinkedQueue<Dispatch> dispatchPool = new ConcurrentLinkedQueue<>();
|
||
|
|
||
|
public PlayerCharacter player;
|
||
|
public AbstractNetMsg msg;
|
||
|
|
||
|
public Dispatch(PlayerCharacter player, AbstractNetMsg msg) {
|
||
|
this.player = player;
|
||
|
this.msg = msg;
|
||
|
}
|
||
|
|
||
|
public void reset() {
|
||
|
this.player = null;
|
||
|
this.msg = null;
|
||
|
}
|
||
|
|
||
|
public static Dispatch borrow(PlayerCharacter player, AbstractNetMsg msg) {
|
||
|
|
||
|
Dispatch dispatch;
|
||
|
|
||
|
dispatch = dispatchPool.poll();
|
||
|
|
||
|
if (dispatch == null) {
|
||
|
dispatch = new Dispatch(player, msg);
|
||
|
} else {
|
||
|
dispatch.player = player;
|
||
|
dispatch.msg = msg;
|
||
|
itemPoolSize.decrement();
|
||
|
}
|
||
|
|
||
|
return dispatch;
|
||
|
}
|
||
|
|
||
|
public void release() {
|
||
|
this.reset();
|
||
|
dispatchPool.add(this);
|
||
|
itemPoolSize.increment();
|
||
|
}
|
||
|
}
|