Fix text prop caching and an exception in Server.cs

This commit is contained in:
excitedneon 2017-05-11 20:30:15 +03:00
parent d634e862ea
commit 9f307d7632
2 changed files with 14 additions and 4 deletions

View File

@ -139,7 +139,7 @@ namespace Cyber.Networking.Serverside {
SendToAll(PktType.TextMessage, new TextMessagePkt("Server: " + args[0]));
});
gameObject.AddComponent<Syncer>();
Syncer = gameObject.AddComponent<Syncer>();
return true;
}

View File

@ -63,10 +63,20 @@ namespace Cyber.Util {
/// <param name="forceRender">Whether the texture should be rendered
/// again even if it's cached.</param>
public static Texture2D GetText(TextTextureProperties text, bool forceRender = false) {
if (forceRender || !Cache.ContainsKey(text.Text)) {
Cache[text.Text] = Singleton.RenderText(text);
string Hash = CreateHash(text);
if (forceRender || !Cache.ContainsKey(Hash)) {
Cache[Hash] = Singleton.RenderText(text);
Term.Println("Created a new texture for:");
Term.Println(Hash);
Term.Println("====");
}
return Cache[text.Text];
return Cache[Hash];
}
private static string CreateHash(TextTextureProperties text) {
return text.Text + "," + text.Width + "," + text.Height + "," +
text.FontSize + "," + text.Background.r + "," +
text.Background.g + "," + text.Background.b;
}
}
}