libvwad: updated -- vwadwrite: free file buffers on close (otherwise archive creation...
[k8vavoom.git] / source / psim / p_trace_internal.h
blob44d33242dc99c4c6aa637e29d86336966aa7328c
1 //**************************************************************************
2 //**
3 //** ## ## ## ## ## #### #### ### ###
4 //** ## ## ## ## ## ## ## ## ## ## #### ####
5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ##
6 //** ## ## ######## ## ## ## ## ## ## ## ### ##
7 //** ### ## ## ### ## ## ## ## ## ##
8 //** # ## ## # #### #### ## ##
9 //**
10 //** Copyright (C) 1999-2006 Jānis Legzdiņš
11 //** Copyright (C) 2018-2023 Ketmar Dark
12 //**
13 //** This program is free software: you can redistribute it and/or modify
14 //** it under the terms of the GNU General Public License as published by
15 //** the Free Software Foundation, version 3 of the License ONLY.
16 //**
17 //** This program is distributed in the hope that it will be useful,
18 //** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 //** GNU General Public License for more details.
21 //**
22 //** You should have received a copy of the GNU General Public License
23 //** along with this program. If not, see <http://www.gnu.org/licenses/>.
24 //**
25 //**************************************************************************
26 #ifndef VAVOOM_PSIM_TRACE_INTERNAL_HEADER
27 #define VAVOOM_PSIM_TRACE_INTERNAL_HEADER
30 // ////////////////////////////////////////////////////////////////////////// //
31 struct InterceptionList {
32 VV_DISABLE_COPY(InterceptionList)
34 intercept_t *list;
35 unsigned alloted;
36 unsigned used;
38 inline InterceptionList () noexcept : list(nullptr), alloted(0), used(0) {}
39 inline ~InterceptionList () noexcept { clear(); }
41 inline void clear () noexcept {
42 if (list) Z_Free(list);
43 list = nullptr;
44 alloted = used = 0;
47 inline void reset () noexcept { used = 0; }
49 VVA_CHECKRESULT inline bool isEmpty () const noexcept { return (used == 0); }
51 VVA_CHECKRESULT inline unsigned count () const noexcept { return used; }
53 VVA_CHECKRESULT inline intercept_t *insert (const float frac) noexcept {
54 if (used == alloted) {
55 alloted += 1024;
56 list = (intercept_t *)Z_Realloc(list, sizeof(list[0])*alloted);
59 intercept_t *res;
60 unsigned ipos = used;
61 if (ipos > 0) {
62 while (ipos > 0 && frac < list[ipos-1].frac) --ipos;
63 // here we should insert at `ipos` position
64 if (ipos == used) {
65 // as last
66 res = &list[used++];
67 } else {
68 // make room
69 memmove((void *)(list+ipos+1), (void *)(list+ipos), (used-ipos)*sizeof(list[0]));
70 ++used;
71 res = &list[ipos];
73 } else {
74 res = &list[used++];
76 res->frac = frac;
77 res->Flags = 0u;
78 return res;
83 #endif