Xonotic
map.qh File Reference
#include "int.qh"
+ Include dependency graph for map.qh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define db_remove(db, key)   db_put(db, key, "")
 
#define HM_DELETE(this)   db_close(this)
 
#define HM_gets(this, k)   db_get(this, k)
 
#define HM_NEW(this)   (this = db_create())
 
#define HM_sets(this, key, val)   db_put(this, key, val)
 

Typedefs

using HashMap = int
 

Functions

ERASEABLE void db_close (int db)
 
ERASEABLE int db_create ()
 
ERASEABLE void db_dump (int db, string filename)
 
ERASEABLE string db_get (int db, string key)
 
ERASEABLE int db_load (string filename)
 
ERASEABLE void db_put (int db, string key, string value)
 
ERASEABLE void db_save (int db, string filename)
 

Variables

const int DB_BUCKETS = 8192
 

Macro Definition Documentation

◆ db_remove

#define db_remove (   db,
  key 
)    db_put(db, key, "")

Definition at line 98 of file map.qh.

Referenced by race_deleteTime(), and uid2name().

◆ HM_DELETE

#define HM_DELETE (   this)    db_close(this)

Definition at line 88 of file map.qh.

Referenced by SHUTDOWN().

◆ HM_gets

#define HM_gets (   this,
 
)    db_get(this, k)

Definition at line 96 of file map.qh.

Referenced by CTX().

◆ HM_NEW

#define HM_NEW (   this)    (this = db_create())

Definition at line 29 of file map.qh.

Referenced by STATIC_INIT().

◆ HM_sets

#define HM_sets (   this,
  key,
  val 
)    db_put(this, key, val)

Definition at line 106 of file map.qh.

Referenced by CTX().

Typedef Documentation

◆ HashMap

using HashMap = int

Definition at line 22 of file map.qh.

Function Documentation

◆ db_close()

ERASEABLE void db_close ( int  db)

Definition at line 84 of file map.qh.

Referenced by CSQC_UpdateView(), GameCommand_database(), GameCommand_effectindexdump(), GenericCommand_rpn(), MapInfo_Cache_Destroy(), SHUTDOWN(), and Shutdown().

85 {
86  buf_del(db);
87 }
+ Here is the caller graph for this function:

◆ db_create()

ERASEABLE int db_create ( )

Definition at line 25 of file map.qh.

References buf_create.

Referenced by CSQC_Init(), CSQC_UpdateView(), GameCommand_effectindexdump(), GenericCommand_rpn(), MapInfo_Cache_Create(), and spawnfunc().

26 {
27  return buf_create();
28 }
#define buf_create
Definition: dpextensions.qh:63
+ Here is the caller graph for this function:

◆ db_dump()

ERASEABLE void db_dump ( int  db,
string  filename 
)

Definition at line 69 of file map.qh.

References argv(), ERASEABLE, fclose(), FILE_WRITE, fopen(), fputs(), LOG_FATALF, strcat(), and tokenizebyseparator.

Referenced by GameCommand_database(), and Shutdown().

70 {
71  int fh = fopen(filename, FILE_WRITE);
72  if (fh < 0) LOG_FATALF("Can't dump DB to %s", filename);
73  fputs(fh, "0\n");
74  for (int i = 0, n = buf_getsize(db); i < n; ++i)
75  {
76  int m = tokenizebyseparator(bufstr_get(db, i), "\\");
77  for (int j = 2; j < m; j += 2)
78  fputs(fh, strcat("\\", argv(j - 1), "\\", argv(j), "\n"));
79  }
80  fclose(fh);
81 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
const float FILE_WRITE
Definition: csprogsdefs.qc:233
#define LOG_FATALF(...)
Definition: log.qh:59
#define tokenizebyseparator
Definition: dpextensions.qh:21
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ db_get()

ERASEABLE string db_get ( int  db,
string  key 
)

Definition at line 91 of file map.qh.

References DB_BUCKETS.

Referenced by _getcommandkey(), ctf_CaptureRecord(), ctf_Initialize(), GameCommand_effectindexdump(), GenericCommand_rpn(), getladder(), HUD_Mod_Race(), MapInfo_Cache_Retrieve(), MapInfo_Cache_Store(), MUTATOR_HOOKFUNCTION(), race_readName(), race_readTime(), race_readUID(), race_SendAll(), uid2name(), and XonoticStatsList_getStats().

92 {
93  int h = crc16(false, key) % DB_BUCKETS;
94  return uri_unescape(infoget(bufstr_get(db, h), key));
95 }
const int DB_BUCKETS
Definition: map.qh:6
+ Here is the caller graph for this function:

◆ db_load()

ERASEABLE int db_load ( string  filename)

Definition at line 35 of file map.qh.

References argv(), buf_create, DB_BUCKETS, db_put(), ERASEABLE, fclose(), fgets(), FILE_READ, fopen(), stoi, and tokenizebyseparator.

Referenced by CSQC_Init(), GameCommand_database(), GenericCommand_rpn(), RestoreGame(), and spawnfunc().

36 {
37  int db = buf_create();
38  if (db < 0) return -1;
39  int fh = fopen(filename, FILE_READ);
40  if (fh < 0) return db;
41  string l = fgets(fh);
42  if (stoi(l) == DB_BUCKETS)
43  {
44  for (int i = 0; (l = fgets(fh)); ++i)
45  {
46  if (l != "") bufstr_set(db, i, l);
47  }
48  }
49  else
50  {
51  // different count of buckets, or a dump?
52  // need to reorganize the database then (SLOW)
53  //
54  // note: we also parse the first line (l) in case the DB file is
55  // missing the bucket count
56  do
57  {
58  int n = tokenizebyseparator(l, "\\");
59  for (int j = 2; j < n; j += 2)
60  db_put(db, argv(j - 1), uri_unescape(argv(j)));
61  }
62  while ((l = fgets(fh)));
63  }
64  fclose(fh);
65  return db;
66 }
ERASEABLE void db_put(int db, string key, string value)
Definition: map.qh:101
const float FILE_READ
Definition: csprogsdefs.qc:231
#define stoi(s)
Definition: int.qh:4
#define buf_create
Definition: dpextensions.qh:63
const int DB_BUCKETS
Definition: map.qh:6
#define tokenizebyseparator
Definition: dpextensions.qh:21
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ db_put()

ERASEABLE void db_put ( int  db,
string  key,
string  value 
)

Definition at line 101 of file map.qh.

References DB_BUCKETS.

Referenced by _getcommandkey(), ctf_CaptureRecord(), db_load(), GameCommand_effectindexdump(), GenericCommand_rpn(), getladder(), HUD_Mod_Race(), MapInfo_Cache_Store(), print_Effect_Index(), race_checkAndWriteName(), race_deleteTime(), race_SpeedAwardFrame(), race_writeTime(), and uid2name().

102 {
103  int h = crc16(false, key) % DB_BUCKETS;
104  bufstr_set(db, h, infoadd(bufstr_get(db, h), key, uri_escape(value)));
105 }
const int DB_BUCKETS
Definition: map.qh:6
+ Here is the caller graph for this function:

◆ db_save()

ERASEABLE void db_save ( int  db,
string  filename 
)

Definition at line 8 of file map.qh.

References DB_BUCKETS, fclose(), FILE_WRITE, fopen(), fputs(), ftos(), LOG_WARNF, and strcat().

Referenced by GameCommand_database(), GenericCommand_rpn(), and Shutdown().

9 {
10  int fh = fopen(filename, FILE_WRITE);
11  if (fh < 0)
12  {
13  LOG_WARNF("^1Can't write DB to %s", filename);
14  return;
15  }
16  fputs(fh, strcat(ftos(DB_BUCKETS), "\n"));
17  for (int i = 0, n = buf_getsize(db); i < n; ++i)
18  fputs(fh, strcat(bufstr_get(db, i), "\n"));
19  fclose(fh);
20 }
#define LOG_WARNF(...)
Definition: log.qh:67
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
const int DB_BUCKETS
Definition: map.qh:6
const float FILE_WRITE
Definition: csprogsdefs.qc:233
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ DB_BUCKETS

const int DB_BUCKETS = 8192

Definition at line 6 of file map.qh.

Referenced by db_get(), db_load(), db_put(), and db_save().