/
d_api.c
254 lines (223 loc) · 6.97 KB
/
d_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
252
253
254
/**\file d_api.c
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2006-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2013 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
*/
/**
* Doomsday API setup and interaction - Doom64 specific.
*/
#include <assert.h>
#include <string.h>
#include "doomsday.h"
#include "jdoom64.h"
#include "d_netsv.h"
#include "d_net.h"
#include "fi_lib.h"
#include "g_common.h"
#include "g_update.h"
#include "hu_menu.h"
#include "p_mapsetup.h"
#include "r_common.h"
#include "p_map.h"
#include "polyobjs.h"
#define GID(v) (toGameId(v))
// The interface to the Doomsday engine.
game_export_t gx;
// Identifiers given to the games we register during startup.
static gameid_t gameIds[NUM_GAME_MODES];
static __inline gameid_t toGameId(int gamemode)
{
assert(gamemode >= 0 && gamemode < NUM_GAME_MODES);
return gameIds[(gamemode_t) gamemode];
}
/**
* Register the game modes supported by this plugin.
*/
int G_RegisterGames(int hookType, int param, void* data)
{
#define CONFIGDIR "doom64"
#define STARTUPPK3 PLUGIN_NAMETEXT2 ".pk3"
GameDef const doom64Def = {
"doom64", CONFIGDIR,
"Doom 64: Absolution", "Kaiser et al.",
"", "",
"$(App.DataPath)/$(GamePlugin.Name)/doom64.mapinfo"
};
DENG_UNUSED(hookType); DENG_UNUSED(param); DENG_UNUSED(data);
gameIds[doom64] = DD_DefineGame(&doom64Def);
DD_AddGameResource(GID(doom64), RC_PACKAGE, FF_STARTUP, STARTUPPK3, 0);
DD_AddGameResource(GID(doom64), RC_PACKAGE, FF_STARTUP, "doom64.wad", "MAP01;MAP020;MAP38;F_SUCK");
DD_AddGameResource(GID(doom64), RC_DEFINITION, 0, PLUGIN_NAMETEXT ".ded", 0);
return true;
#undef STARTUPPK3
#undef CONFIGDIR
}
/**
* Called right after the game plugin is selected into use.
*/
void DP_Load(void)
{
// We might've been freed from memory, so refresh the game ids.
gameIds[doom64] = DD_GameIdForKey("doom64");
Plug_AddHook(HOOK_VIEWPORT_RESHAPE, R_UpdateViewport);
}
/**
* Called when the game plugin is freed from memory.
*/
void DP_Unload(void)
{
Plug_RemoveHook(HOOK_VIEWPORT_RESHAPE, R_UpdateViewport);
}
void G_PreInit(gameid_t gameId)
{
/// \todo Refactor me away.
{ size_t i;
for(i = 0; i < NUM_GAME_MODES; ++i)
if(gameIds[i] == gameId)
{
gameMode = (gamemode_t) i;
gameModeBits = 1 << gameMode;
break;
}
if(i == NUM_GAME_MODES)
Con_Error("Failed gamemode lookup for id %i.", gameId);
}
D_PreInit();
}
/**
* Called by the engine to initiate a soft-shutdown request.
*/
dd_bool G_TryShutdown(void)
{
G_QuitGame();
return true;
}
/**
* 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(void)
{
// Clear all of our exports.
memset(&gx, 0, sizeof(gx));
// Fill in the data for the exports.
gx.apiSize = sizeof(gx);
gx.PreInit = G_PreInit;
gx.PostInit = D_PostInit;
gx.Shutdown = D_Shutdown;
gx.TryShutdown = G_TryShutdown;
gx.Ticker = G_Ticker;
gx.DrawViewPort = G_DrawViewPort;
gx.DrawWindow = D_DrawWindow;
gx.FinaleResponder = FI_PrivilegedResponder;
gx.PrivilegedResponder = G_PrivilegedResponder;
gx.Responder = G_Responder;
gx.EndFrame = D_EndFrame;
gx.MobjThinker = P_MobjThinker;
gx.MobjFriction = Mobj_Friction;
gx.MobjCheckPositionXYZ = P_CheckPositionXYZ;
gx.MobjTryMoveXYZ = P_TryMoveXYZ;
gx.SectorHeightChangeNotification = P_HandleSectorHeightChange;
gx.UpdateState = G_UpdateState;
gx.GetInteger = D_GetInteger;
gx.GetVariable = D_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;
// Data structure sizes.
gx.mobjSize = sizeof(mobj_t);
gx.polyobjSize = sizeof(Polyobj);
gx.FinalizeMapChange = P_FinalizeMapChange;
// These really need better names. Ideas?
gx.HandleMapDataPropertyValue = P_HandleMapDataPropertyValue;
gx.HandleMapObjectStatusReport = P_HandleMapObjectStatusReport;
return &gx;
}
/**
* This function is called automatically when the plugin is loaded.
* We let the engine know what we'd like to do.
*/
void DP_Initialize()
{
Plug_AddHook(HOOK_STARTUP, G_RegisterGames);
}
/**
* Declares the type of the plugin so the engine knows how to treat it. Called
* automatically when the plugin is loaded.
*/
const char* deng_LibraryType(void)
{
return "deng-plugin/game";
}
DENG_DECLARE_API(Base);
DENG_DECLARE_API(B);
DENG_DECLARE_API(Busy);
DENG_DECLARE_API(Client);
DENG_DECLARE_API(Con);
DENG_DECLARE_API(Def);
DENG_DECLARE_API(F);
DENG_DECLARE_API(FR);
DENG_DECLARE_API(GL);
DENG_DECLARE_API(Infine);
DENG_DECLARE_API(InternalData);
DENG_DECLARE_API(Material);
DENG_DECLARE_API(MaterialArchive);
DENG_DECLARE_API(Map);
DENG_DECLARE_API(MPE);
DENG_DECLARE_API(Player);
DENG_DECLARE_API(Plug);
DENG_DECLARE_API(R);
DENG_DECLARE_API(Rend);
DENG_DECLARE_API(S);
DENG_DECLARE_API(Server);
DENG_DECLARE_API(Svg);
DENG_DECLARE_API(Thinker);
DENG_DECLARE_API(Uri);
DENG_API_EXCHANGE(
DENG_GET_API(DE_API_BASE, Base);
DENG_GET_API(DE_API_BINDING, B);
DENG_GET_API(DE_API_BUSY, Busy);
DENG_GET_API(DE_API_CLIENT, Client);
DENG_GET_API(DE_API_CONSOLE, Con);
DENG_GET_API(DE_API_DEFINITIONS, Def);
DENG_GET_API(DE_API_FILE_SYSTEM, F);
DENG_GET_API(DE_API_FONT_RENDER, FR);
DENG_GET_API(DE_API_GL, GL);
DENG_GET_API(DE_API_INFINE, Infine);
DENG_GET_API(DE_API_INTERNAL_DATA, InternalData);
DENG_GET_API(DE_API_MATERIALS, Material);
DENG_GET_API(DE_API_MATERIAL_ARCHIVE, MaterialArchive);
DENG_GET_API(DE_API_MAP, Map);
DENG_GET_API(DE_API_MAP_EDIT, MPE);
DENG_GET_API(DE_API_PLAYER, Player);
DENG_GET_API(DE_API_PLUGIN, Plug);
DENG_GET_API(DE_API_RESOURCE, R);
DENG_GET_API(DE_API_RENDER, Rend);
DENG_GET_API(DE_API_SOUND, S);
DENG_GET_API(DE_API_SERVER, Server);
DENG_GET_API(DE_API_SVG, Svg);
DENG_GET_API(DE_API_THINKER, Thinker);
DENG_GET_API(DE_API_URI, Uri);
)