diff --git a/Assets/Scripts/Animation List/ListManager.cs b/Assets/Scripts/Animation List/ListManager.cs index 75656df..2ff6f61 100644 --- a/Assets/Scripts/Animation List/ListManager.cs +++ b/Assets/Scripts/Animation List/ListManager.cs @@ -18,10 +18,12 @@ public class ItemData { public class ListManager : MonoBehaviour { + private PlayerManager manager; + public GameObject sampleItemObject; public GameObject sampleLoadingItemObject; - public string[] itemList; + public List itemList; private int index = 0; private const int OFFSET = 20; private int size = 0; @@ -38,10 +40,9 @@ public class ListManager : MonoBehaviour { private float itemHeight = 30F; - TrieST trie; - void Start() { + this.manager = this.gameObject.GetComponent(); this.scrollView.onValueChanged.AddListener(checkScrollPosition); this.input.onValueChanged.AddListener(inputChanged); @@ -61,35 +62,11 @@ public class ListManager : MonoBehaviour { public IEnumerator load() { - WWW www = new WWW("http://150.165.205.9/anims/sinais.txt"); - yield return www; - - string[] lines = new string[0]; - - if (string.IsNullOrEmpty(www.error)) - { - lines = System.Text.Encoding.UTF8.GetString(www.bytes, 0, www.bytes.Length).Split('\n'); - } - else - { - TextAsset file = Resources.Load("sinais") as TextAsset; - lines = System.Text.Encoding.UTF8.GetString(file.bytes, 0, file.bytes.Length).Split('\n'); - // lines = file.text.Split("\n"[0]); - } + while (manager.signs == null) yield return new WaitForEndOfFrame(); - this.trie = new TrieST(); - - foreach (string line in lines) - { - string word = line.Trim(); - - if ( ! String.IsNullOrEmpty(word)) - this.trie.put(word, word); - } - - this.itemList = getNamesByPrefix(""); + this.itemList = this.manager.signs.StartsWith(""); this.index = 0; - this.size = itemList.Length; + this.size = itemList.Count; populateList(); } @@ -102,9 +79,9 @@ public class ListManager : MonoBehaviour { public void inputChanged(string text) { - this.itemList = getNamesByPrefix(text.ToUpper()); + this.itemList = this.manager.signs.StartsWith(text.ToUpper()); this.index = 0; - this.size = itemList.Length; + this.size = itemList.Count; this.contentPanel.DetachChildren(); foreach(GameObject go in GameObject.FindGameObjectsWithTag("clone")) @@ -145,10 +122,4 @@ public class ListManager : MonoBehaviour { this.index = last; } - private string[] getNamesByPrefix(string prefix) - { - Queue names = this.trie.keysWithPrefix(prefix); - return names.ToArray(); - } - } diff --git a/Assets/Scripts/Player Manager/GenericPlayerManager.cs b/Assets/Scripts/Player Manager/GenericPlayerManager.cs index d1b5e2a..a51bb02 100644 --- a/Assets/Scripts/Player Manager/GenericPlayerManager.cs +++ b/Assets/Scripts/Player Manager/GenericPlayerManager.cs @@ -49,8 +49,6 @@ public abstract class GenericPlayerManager : MonoBehaviour { // Guarda os nomes das palavras já carregadas private HashSet loadedAssetBundles = new HashSet(); - // Guarda os nomes das palavras que não tem assetbundle - private HashSet nonexistentAssetBundles = new HashSet(); // Fila de animações para reprodução // Utilizada para alterar velocidade e apresentar a legenda @@ -476,32 +474,17 @@ public abstract class GenericPlayerManager : MonoBehaviour { Queue toPlayQueue = new Queue(); toPlayQueue.Enqueue(new ToPlay(Subtitle.TYPE_NONE, DEFAULT_ANIMATION, "", this)); - - /*WWW checkConnectionRequest = getCheckConnectionRequest(); - bool connected = false; - - while ( ! checkConnectionRequest.isDone) - yield return checkConnectionRequest; - - if (checkConnectionRequest.responseHeaders.Count > 0) - { - PlayerLogger.Log(checkConnectionRequest.responseHeaders["STATUS"]); - connected = checkConnectionRequest.responseHeaders["STATUS"].Contains("404"); - } - else PlayerLogger.Log("No response headers.");*/ - - bool connected = true; + bool playingStarted = false; String[] stringPos = gloss.Split(' '); foreach (string aniName in stringPos) { if (String.IsNullOrEmpty(aniName)) continue; - - bool nonexistent = nonexistentAssetBundles.Contains(aniName); + bool loaded = loadedAssetBundles.Contains(aniName); - if ( ! nonexistent && ! loaded && connected) + if ( ! loaded) { WWW bundleRequest = loadAssetBundle(aniName); @@ -533,8 +516,6 @@ public abstract class GenericPlayerManager : MonoBehaviour { else PlayerLogger.Log("GPM", "L", "Sign \"" + aniName + "\" wasn't loaded successfuly."); } else PlayerLogger.Log("GPM", "L", "Bundle \"" + aniName + "\" wasn't loaded successfuly."); - - if ( ! loaded) nonexistentAssetBundles.Add(aniName); } else { diff --git a/Assets/Scripts/PlayerManager.cs b/Assets/Scripts/PlayerManager.cs index b03ae95..e0de109 100644 --- a/Assets/Scripts/PlayerManager.cs +++ b/Assets/Scripts/PlayerManager.cs @@ -8,6 +8,7 @@ using System.Threading; using LAViD.Utils; using LAViD.Structures; using System.Diagnostics; +using System.Collections.Generic; public class PlayerManager : GenericPlayerManager { @@ -23,8 +24,6 @@ public class PlayerManager : GenericPlayerManager { private const string SERVER_URL = "http://traducao.vlibras.gov.br/translate?text="; private const int VERSION = 1; - private Trie signs; - public enum ERROR_STATUS_MESSAGE { INTERNET_CONNECTION_FAILURE, @@ -46,7 +45,8 @@ public class PlayerManager : GenericPlayerManager { private string regionPath = ""; private int regionHash = 1; - private static string dictionaryJSON; + public Trie signs = null; + public static string get_connection_status_message(ERROR_STATUS_MESSAGE msg) { @@ -67,15 +67,14 @@ public class PlayerManager : GenericPlayerManager { public override void Start() { - base.setRandomAnimations(randomAnimationNames); - base.Start(); - - voiceRecognizer = new VoiceRecognition(); - #if UNITY_EDITOR Caching.CleanCache(); #endif + base.setRandomAnimations(randomAnimationNames); + base.Start(); + + voiceRecognizer = new VoiceRecognition(); Screen.fullScreen = false; StartCoroutine(WaitForResponse( @@ -83,28 +82,39 @@ public class PlayerManager : GenericPlayerManager { // Success delegate(WWW www) { - PlayerManager.dictionaryJSON = www.text; + string response = www.text; - /*new Thread( + new Thread( () => { - Thread.CurrentThread.IsBackground = true;*/ + Thread.CurrentThread.IsBackground = true; Stopwatch watch = new Stopwatch(); watch.Start(); try { - this.signs = Trie.FromJSON(new JSONParser(Regex.Unescape(PlayerManager.dictionaryJSON))); - - PlayerLogger.Log("PM", "S", "Found EU: " + this.signs.Contains("EU")); - PlayerLogger.Log("PM", "S", "Found EUE: " + this.signs.Contains("EUE")); + PlayerLogger.Log("T", "FJ", "Starting trie parsing."); + this.signs = Trie.FromJSON(new JSONParser(Regex.Unescape(response))); + + char[] charactersSigns = new char[] + { + 'A', 'B', 'C', 'Ç', 'D', 'E', 'F', 'G', 'H', 'I', + 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', + 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' + }; + + foreach (char c in charactersSigns) + { + this.signs.Add(c.ToString()); + } } catch (Exception e) { PlayerLogger.Log("PM", "S", "Exception at trie JSON parser: " + e.ToString()); } watch.Stop(); PlayerLogger.Log("T", "FJ", "Parsed in " + watch.ElapsedMilliseconds + " ms."); - /* } - ).Start();*/ + } + ).Start(); }, // Error delegate (WWW www) @@ -166,6 +176,9 @@ public class PlayerManager : GenericPlayerManager { protected override WWW loadAssetBundle(string aniName) { + if (this.regionHash == 1 && !this.signs.Contains(aniName)) + return null; + string address = BASE_URL + this.regionPath + WWW.EscapeURL(aniName); PlayerLogger.Log("PM", "lAB", "Requesting bundle: " + address); diff --git a/Assets/Scripts/Trie/JSONParser.cs b/Assets/Scripts/Trie/JSONParser.cs index bf80d41..e0c40e9 100644 --- a/Assets/Scripts/Trie/JSONParser.cs +++ b/Assets/Scripts/Trie/JSONParser.cs @@ -6,7 +6,7 @@ using System.Text; namespace LAViD.Utils { - class JSONParser + public class JSONParser { private static readonly string True = "true"; private static readonly string False = "false"; @@ -250,7 +250,7 @@ namespace LAViD.Utils } } - class JSONObject + public class JSONObject { public delegate T Creator(); public delegate void Assigner(JSONParser json, T obj); diff --git a/Assets/Scripts/Trie/Trie.cs b/Assets/Scripts/Trie/Trie.cs index 15bea43..cd0a3f9 100644 --- a/Assets/Scripts/Trie/Trie.cs +++ b/Assets/Scripts/Trie/Trie.cs @@ -9,7 +9,7 @@ using System.Text.RegularExpressions; namespace LAViD.Structures { - class Trie + public class Trie { private char[] characters; private Dictionary keys; @@ -32,13 +32,25 @@ namespace LAViD.Structures obj.characters = jsonParser.ParseList(char.Parse).ToArray(); }); - public static Trie FromJSON(JSONParser json) + public static Trie FromJSON(JSONParser json) { + return Trie.Parser.Parse(json); + } + + public void Add(string word) { - PlayerLogger.Log("T", "FJ", "Starting trie parsing."); + Node node = this.root; - Trie trie = Trie.Parser.Parse(json); - - return trie; + foreach (char c in word) + { + int key = this.keys[c]; + + if (node.children[key] == null) + node.children[key] = new Node(this.root.maxChildren); + + node = node.children[key]; + } + + node.end = true; } public bool Contains(string word) @@ -57,6 +69,8 @@ namespace LAViD.Structures public List StartsWith(string word) { + PlayerLogger.Log("T", "SW", "Searching for '" + word + "'."); + List list = new List(); Node node = this.root; @@ -66,7 +80,7 @@ namespace LAViD.Structures if (node == null) break; } - if (node != null) feed(list, "", node); + if (node != null) feed(list, word, node); return list; } @@ -89,6 +103,7 @@ namespace LAViD.Structures public Node(int maxChildren) { this.maxChildren = maxChildren; + this.children = new Node[maxChildren]; } private readonly static JSONObject Parser = new JSONObject() @@ -108,9 +123,7 @@ namespace LAViD.Structures return Node.FromJSON(innerJSONParser, obj.maxChildren); } ); - - obj.children = new Node[obj.maxChildren]; - + foreach (KeyValuePair pair in children) obj.children[pair.Key] = pair.Value; }); -- libgit2 0.21.2