From a7087199d26372ef67f568e9ca422982ca92d6fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 14 Mar 2016 16:31:56 +0100 Subject: add util/TurnRecord --- core/src/ch/asynk/rustanddust/util/TurnRecord.java | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 core/src/ch/asynk/rustanddust/util/TurnRecord.java diff --git a/core/src/ch/asynk/rustanddust/util/TurnRecord.java b/core/src/ch/asynk/rustanddust/util/TurnRecord.java new file mode 100644 index 0000000..e7ed117 --- /dev/null +++ b/core/src/ch/asynk/rustanddust/util/TurnRecord.java @@ -0,0 +1,72 @@ +package ch.asynk.rustanddust.util; + +import com.badlogic.gdx.utils.Pool; +import com.badlogic.gdx.utils.Disposable; + +import ch.asynk.rustanddust.ui.List; +import ch.asynk.rustanddust.engine.util.Collection; +import ch.asynk.rustanddust.engine.util.IterableArray; + +public class TurnRecord implements List.ListElement, Disposable, Pool.Poolable +{ + public int id; + public int game; + public int turn; + public int player; + public String hash; + public String payload; + + public static Collection list = new IterableArray(10); + + private static final Pool turnRecordPool = new Pool() + { + @Override + protected TurnRecord newObject() { + return new TurnRecord(); + } + }; + + public static void clearPool() + { + turnRecordPool.clear(); + } + + public static TurnRecord get() + { + TurnRecord r = turnRecordPool.obtain(); + return r; + } + + public static TurnRecord get(int idx) + { + return (TurnRecord) list.get(idx); + } + + public static void clearList() + { + for(List.ListElement r : list) + ((TurnRecord) r).dispose(); + list.clear(); + } + + public TurnRecord() + { + } + + @Override + public void reset() + { + } + + @Override + public void dispose() + { + turnRecordPool.free(this); + } + + @Override + public String s() + { + return String.format("turn(id): g:%d t:%d p:%d", id, game, turn, player); + } +} -- cgit v1.1-2-g2b99