X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Farraylist.qh;h=18305177bf8a266261e1be9ad143dfde695fcace;hb=5453f53da1df88742c11c71e4dc5b9c3e3d24c62;hp=c2aae2b7b5476f529eaa977840852bdb5fa55045;hpb=bda4e58210275f23266f9a1231de949b6bc64893;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/arraylist.qh b/qcsrc/lib/arraylist.qh index c2aae2b7b..18305177b 100644 --- a/qcsrc/lib/arraylist.qh +++ b/qcsrc/lib/arraylist.qh @@ -1,45 +1,70 @@ -#ifndef ARRAYLIST_H -#define ARRAYLIST_H +#pragma once -typedef int ArrayList; +USING(ArrayList, entity); +.int al_buf; +.int al_len; -#define AL_declare(this) ArrayList this; int this##_len = (0) -#define AL_init(this, n, default, T) \ - do \ +#define AL_NEW(this, n, default, T) \ + MACRO_BEGIN \ { \ - this = buf_create(); \ - this##_len = n; \ - for (int i = 0; i < this##_len; ++i) \ + ArrayList _al = this = new_pure(ArrayList); \ + _al.al_buf = buf_create(); \ + for (int i = 0, _n = _al.al_len = n; i < _n; ++i) \ { \ const _AL_type__##T() it = default; \ AL_set##T(this, i, it); \ } \ - } \ - while (0) -#define AL_delete(this) buf_del(this) + } MACRO_END + +#define AL_DELETE(this) \ + MACRO_BEGIN \ + { \ + buf_del(this.al_buf); \ + delete(this); \ + this = NULL; \ + } MACRO_END #define _AL_type__s() string -#define AL_gets(this, idx) bufstr_get(this, idx) -#define AL_sets(this, idx, val) bufstr_set(this, idx, val) +#define AL_gets(this, idx) bufstr_get(this.al_buf, idx) +#define AL_sets(this, idx, val) bufstr_set(this.al_buf, idx, val) + +#if defined(CSQC) +string al_ftos(float f) = #26; +float al_stof(string s) = #81; +#elif defined(SVQC) +string al_ftos(float f) = #26; +float al_stof(string s) = #81; +#elif defined(MENUQC) +string al_ftos(float f) = #17; +float al_stof(string s) = #21; +#endif #define _AL_type__f() float -#define AL_getf(this, idx) stof(AL_gets(this, idx)) -#define AL_setf(this, idx, val) AL_sets(this, idx, ftos(val)) +#define AL_getf(this, idx) al_stof(AL_gets(this, idx)) +#define AL_setf(this, idx, val) AL_sets(this, idx, al_ftos(val)) + +#if defined(CSQC) +int al_etof(entity e) = #512; +entity al_ftoe(int i) = #459; +#elif defined(SVQC) +int al_etof(entity e) = #512; +entity al_ftoe(int i) = #459; +#elif defined(MENUQC) +int al_etof(entity e) = #79; +entity al_ftoe(int i) = #80; +#endif #define _AL_type__e() entity -#define AL_gete(this, idx) ftoe(AL_getf(this, idx)) -#define AL_sete(this, idx, val) AL_setf(this, idx, etof(val)) +#define AL_gete(this, idx) al_ftoe(AL_getf(this, idx)) +#define AL_sete(this, idx, val) AL_setf(this, idx, al_etof(val)) #define AL_EACH(this, T, cond, body) \ - do \ + MACRO_BEGIN \ { \ const noref ArrayList _al = this; \ - for (int i = 0, n = this##_len; i < n; ++i) \ + for (int i = 0, n = _al.al_len; i < n; ++i) \ { \ const noref _AL_type__##T() it = AL_get##T(_al, i); \ if (cond) { body } \ } \ - } \ - while (0) - -#endif + } MACRO_END