]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/i18n.qh
Bot AI: don't consider an item reachable just because it overlaps a teleport waypoint...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / i18n.qh
index 3773e16d1d2fdde2c904f6ac37812aab2d5a08a2..3dfac622464a1144ed74096703108d0e9afa8251 100644 (file)
@@ -1,11 +1,16 @@
-#ifndef I18N_H
-#define I18N_H
+#pragma once
 
 #include "log.qh"
+#include "map.qh"
+#include "unsafe.qh"
 
 // translation helpers
 string prvm_language;
 
+/**
+ * @deprecated prefer _("translated")
+ */
+ERASEABLE
 string language_filename(string s)
 {
        string fn = prvm_language;
@@ -20,13 +25,36 @@ string language_filename(string s)
        return s;
 }
 
+#ifndef CTX_CACHE
+       #define CTX_CACHE 1
+#endif
+
+#if CTX_CACHE
+       HashMap CTX_cache;
+       STATIC_INIT(CTX_cache)
+       {
+               HM_NEW(CTX_cache);
+       }
+       SHUTDOWN(CTX_cache)
+       {
+               HM_DELETE(CTX_cache);
+       }
+#endif
+
+ERASEABLE
 string CTX(string s)
 {
+#if CTX_CACHE
+               string c = HM_gets(CTX_cache, s);
+               if (c != "") return c;
+#endif
        int p = strstrofs(s, "^", 0);
-       if (p < 0) return s;
-       return substring(s, p + 1, -1);
+       string ret = (p < 0) ? s : substring(s, p + 1, -1);
+#if CTX_CACHE
+        LOG_DEBUGF("CTX(\"%s\")", s);
+               HM_sets(CTX_cache, s, ret);
+#endif
+       return ret;
 }
 
 #define ZCTX(s) strzone(CTX(s))
-
-#endif