Subversion Repositories eduke32

Rev

Rev 3267 | Rev 3274 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1677 terminx 1
//-------------------------------------------------------------------------
2
/*
3
Copyright (C) 2010 EDuke32 developers and contributors
4
 
5
This file is part of EDuke32.
6
 
7
EDuke32 is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License version 2
9
as published by the Free Software Foundation.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
15
See the GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
*/
21
//-------------------------------------------------------------------------
22
 
23
#ifndef __gamevars_h__
24
#define __gamevars_h__
25
 
1909 terminx 26
#include "gamedef.h"
27
 
3268 terminx 28
#define MAXGAMEVARS 2048 // must be a power of two
29
#define MAXVARLABEL 26
30
 
1677 terminx 31
// store global game definitions
32
enum GamevarFlags_t {
33
    GAMEVAR_PERPLAYER  = 0x00000001, // per-player variable
34
    GAMEVAR_PERACTOR   = 0x00000002, // per-actor variable
1857 terminx 35
    GAMEVAR_USER_MASK  = (GAMEVAR_PERPLAYER|GAMEVAR_PERACTOR),
1677 terminx 36
    GAMEVAR_RESET      = 0x00000008, // marks var for to default
37
    GAMEVAR_DEFAULT    = 0x00000100, // allow override
38
    GAMEVAR_SECRET     = 0x00000200, // don't dump...
39
    GAMEVAR_NODEFAULT  = 0x00000400, // don't reset on actor spawn
40
    GAMEVAR_SYSTEM     = 0x00000800, // cannot change mode flags...(only default value)
41
    GAMEVAR_READONLY   = 0x00001000, // values are read-only (no setvar allowed)
42
    GAMEVAR_INTPTR     = 0x00002000, // plValues is a pointer to an int32_t
43
    GAMEVAR_SHORTPTR   = 0x00008000, // plValues is a pointer to a short
44
    GAMEVAR_CHARPTR    = 0x00010000, // plValues is a pointer to a char
1857 terminx 45
    GAMEVAR_PTR_MASK   = (GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR),
1677 terminx 46
    GAMEVAR_NORESET    = 0x00020000, // var values are not reset when restoring map state
47
    GAMEVAR_SPECIAL    = 0x00040000, // flag for structure member shortcut vars
48
    GAMEVAR_NOMULTI    = 0x00080000, // don't attach to multiplayer packets
49
};
50
 
3268 terminx 51
#define MAXGAMEARRAYS (MAXGAMEVARS>>2) // must be lower than MAXGAMEVARS
52
#define MAXARRAYLABEL MAXVARLABEL
53
 
1677 terminx 54
enum GamearrayFlags_t {
55
    GAMEARRAY_NORMAL   = 0,
56
    GAMEARRAY_NORESET  = 0x00000001,
57
};
58
 
59
#pragma pack(push,1)
60
typedef struct {
61
    union {
62
        intptr_t lValue;
63
        intptr_t *plValues;     // array of values when 'per-player', or 'per-actor'
64
    } val;
65
    intptr_t lDefault;
66
    uintptr_t dwFlags;
67
    char *szLabel;
68
} gamevar_t;
69
 
70
typedef struct {
71
    char *szLabel;
2664 terminx 72
    intptr_t *plValues;     // array of values
1677 terminx 73
    intptr_t size;
74
    intptr_t bReset;
75
} gamearray_t;
76
#pragma pack(pop)
77
 
2689 helixhorne 78
#define GAR_ELTSZ (sizeof(aGameArrays[0].plValues[0]))
79
 
1677 terminx 80
extern gamevar_t aGameVars[MAXGAMEVARS];
81
extern gamearray_t aGameArrays[MAXGAMEARRAYS];
82
extern int32_t g_gameVarCount;
83
extern int32_t g_gameArrayCount;
84
 
85
int32_t __fastcall Gv_GetVar(register int32_t id,register int32_t iActor,register int32_t iPlayer);
86
int32_t __fastcall Gv_GetVarX(register int32_t id);
87
int32_t Gv_GetVarByLabel(const char *szGameLabel,int32_t lDefault,int32_t iActor,int32_t iPlayer);
88
int32_t Gv_NewArray(const char *pszLabel,int32_t asize);
2005 terminx 89
int32_t Gv_NewVar(const char *pszLabel,intptr_t lValue,uint32_t dwFlags);
1677 terminx 90
int32_t Gv_ReadSave(int32_t fil,int32_t newbehav);
91
void __fastcall A_ResetVars(register int32_t iActor);
92
void __fastcall Gv_SetVar(register int32_t id,register int32_t lValue,register int32_t iActor,register int32_t iPlayer);
93
void __fastcall Gv_SetVarX(register int32_t id,register int32_t lValue);
94
void G_FreeMapState(int32_t mapnum);
95
void Gv_DumpValues(void);
96
void Gv_Init(void);
97
void Gv_InitWeaponPointers(void);
98
void Gv_RefreshPointers(void);
99
void Gv_RefreshPointers(void);
100
void Gv_ResetSystemDefaults(void);
101
void Gv_ResetVars(void);
102
void Gv_WriteSave(FILE *fil,int32_t newbehav);
1909 terminx 103
 
3267 terminx 104
#define GV_VAROP(func, operator) static inline void __fastcall func(register int32_t id, register int32_t lValue) \
105
{ \
106
    switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) \
107
    { \
108
    default: \
109
        aGameVars[id].val.lValue operator lValue; \
110
        return; \
111
    case GAMEVAR_PERPLAYER: \
112
        if ((unsigned)vm.g_p > MAXPLAYERS-1) return; \
113
        aGameVars[id].val.plValues[vm.g_p] operator lValue; \
114
        return; \
115
    case GAMEVAR_PERACTOR: \
116
        if ((unsigned)vm.g_i > MAXSPRITES-1) return; \
117
        aGameVars[id].val.plValues[vm.g_i] operator lValue; \
118
        return; \
119
    case GAMEVAR_INTPTR: \
120
        *((int32_t *)aGameVars[id].val.lValue) operator (int32_t)lValue; \
121
        return; \
122
    case GAMEVAR_SHORTPTR: \
123
        *((int16_t *)aGameVars[id].val.lValue) operator (int16_t)lValue; \
124
        return; \
125
    case GAMEVAR_CHARPTR: \
126
        *((uint8_t *)aGameVars[id].val.lValue) operator (uint8_t)lValue; \
127
        return; \
128
    } \
1909 terminx 129
}
130
 
3267 terminx 131
GV_VAROP(Gv_AddVar, +=)
132
GV_VAROP(Gv_SubVar, -=)
133
GV_VAROP(Gv_MulVar, *=)
134
GV_VAROP(Gv_DivVar, /=)
135
GV_VAROP(Gv_ModVar, %=)
136
GV_VAROP(Gv_AndVar, &=)
137
GV_VAROP(Gv_XorVar, ^=)
138
GV_VAROP(Gv_OrVar, |=)
1909 terminx 139
 
1677 terminx 140
#endif