/
h_api.c
251 lines (197 loc) · 7.2 KB
/
h_api.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/**\file
*\section License
* License: GPL + jHeretic/jHexen Exception
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2006-2007 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2007 Daniel Swanson <danij@dengine.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* In addition, as a special exception, we, the authors of deng
* give permission to link the code of our release of deng with
* the libjhexen and/or the libjheretic libraries (or with modified
* versions of it that use the same license as the libjhexen or
* libjheretic libraries), and distribute the linked executables.
* You must obey the GNU General Public License in all respects for
* all of the code used other than “libjhexen or libjheretic”. If
* you modify this file, you may extend this exception to your
* version of the file, but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your version.
*/
/**
* h_api.c: Doomsday API setup and interaction - jHeretic specific
*/
// HEADER FILES ------------------------------------------------------------
#include "jheretic.h"
#include "hu_menu.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
/**
* jHeretic's entry points
*/
// Initialization
void H_PreInit(void);
void H_PostInit(void);
// Timeing loop
void H_Ticker(timespan_t ticLength);
// Drawing
void D_Display(void);
void D_Display2(void);
void H_EndFrame(void);
// Input responders
int G_PrivilegedResponder(event_t *event);
boolean G_Responder(event_t *ev);
int D_PrivilegedResponder(event_t *event);
// Map Data
void P_SetupForMapData(int type, uint num);
// Map Objects
float P_GetMobjFriction(struct mobj_s *mo);
void P_MobjThinker(mobj_t *mobj);
void P_BlasterMobjThinker(mobj_t *mobj);
// Misc
void H_ConsoleBg(int *width, int *height);
// Game state changes
void G_UpdateState(int step);
// Network
int D_NetServerStarted(int before);
int D_NetServerClose(int before);
int D_NetConnect(int before);
int D_NetDisconnect(int before);
long int D_NetPlayerEvent(int plrNumber, int peType, void *data);
int D_NetWorldEvent(int type, int parm, void *data);
// Handlers
void D_HandlePacket(int fromplayer, int type, void *data, int length);
int P_HandleMapDataProperty(uint id, int dtype, int prop, int type, void *data);
int P_HandleMapDataPropertyValue(uint id, int dtype, int prop, int type, void *data);
int P_HandleMapObjectStatusReport(int code, uint id, int dtype, void *data);
// Shutdown
void H_Shutdown(void);
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern char gameModeString[];
extern char gameConfigString[];
extern struct xgclass_s xgClasses[];
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// The interface to the Doomsday engine.
game_import_t gi;
game_export_t gx;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
// CODE --------------------------------------------------------------------
/**
* Get a 32-bit integer value.
*/
int G_GetInteger(int id)
{
switch(id)
{
case DD_GAME_DMUAPI_VER:
return DMUAPI_VER;
default:
break;
}
// ID not recognized, return NULL.
return 0;
}
/**
* Get a pointer to the value of a variable. Added for 64-bit support.
*/
void *G_GetVariable(int id)
{
static float bob[2];
switch(id)
{
case DD_GAME_NAME:
return GAMENAMETEXT;
case DD_GAME_ID:
return GAMENAMETEXT " " VERSION_TEXT;
case DD_GAME_MODE:
return gameModeString;
case DD_GAME_CONFIG:
return gameConfigString;
case DD_VERSION_SHORT:
return VERSION_TEXT;
case DD_VERSION_LONG:
return VERSIONTEXT
"\n"GAMENAMETEXT" is based on Heretic v1.3 by Raven Software.";
case DD_ACTION_LINK:
return actionlinks;
case DD_ALT_MOBJ_THINKER:
return P_BlasterMobjThinker;
case DD_XGFUNC_LINK:
return xgClasses;
case DD_PSPRITE_BOB_X:
bob[VX] = 1 + (cfg.bobWeapon * players[consoleplayer].bob) *
FIX2FLT(finecosine[(128 * leveltime) & FINEMASK]);
return &bob[VX];
case DD_PSPRITE_BOB_Y:
bob[VY] = 32 + (cfg.bobWeapon * players[consoleplayer].bob) *
FIX2FLT(finesine[(128 * leveltime) & FINEMASK & (FINEANGLES / 2 - 1)]);
return &bob[VY];
default:
break;
}
// ID not recognized, return NULL.
return 0;
}
/**
* Takes a copy of the engine's entry points and exported data. Returns
* a pointer to the structure that contains our entry points and exports.
*/
game_export_t *GetGameAPI(game_import_t *imports)
{
// Take a copy of the imports, but only copy as much data as is
// allowed and legal.
memset(&gi, 0, sizeof(gi));
memcpy(&gi, imports, MIN_OF(sizeof(game_import_t), imports->apiSize));
// Clear all of our exports.
memset(&gx, 0, sizeof(gx));
// Fill in the data for the exports.
gx.apiSize = sizeof(gx);
gx.PreInit = H_PreInit;
gx.PostInit = H_PostInit;
gx.Shutdown = H_Shutdown;
gx.G_Drawer = D_Display;
gx.Ticker = H_Ticker;
gx.G_Drawer2 = D_Display2;
gx.PrivilegedResponder = (boolean (*)(event_t *)) G_PrivilegedResponder;
gx.FallbackResponder = Hu_MenuResponder;
gx.G_Responder = G_Responder;
gx.MobjThinker = P_MobjThinker;
gx.MobjFriction = (float (*)(void *)) P_GetMobjFriction;
gx.EndFrame = H_EndFrame;
gx.ConsoleBackground = H_ConsoleBg;
gx.UpdateState = G_UpdateState;
#undef Get
gx.GetInteger = G_GetInteger;
gx.GetVariable = G_GetVariable;
gx.NetServerStart = D_NetServerStarted;
gx.NetServerStop = D_NetServerClose;
gx.NetConnect = D_NetConnect;
gx.NetDisconnect = D_NetDisconnect;
gx.NetPlayerEvent = D_NetPlayerEvent;
gx.NetWorldEvent = D_NetWorldEvent;
gx.HandlePacket = D_HandlePacket;
// The structure sizes.
gx.ticcmd_size = sizeof(ticcmd_t);
gx.SetupForMapData = P_SetupForMapData;
gx.HandleMapDataProperty = P_HandleMapDataProperty;
gx.HandleMapDataPropertyValue = P_HandleMapDataPropertyValue;
gx.HandleMapObjectStatusReport = P_HandleMapObjectStatusReport;
return &gx;
}