/
example.c
227 lines (181 loc) · 5.59 KB
/
example.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
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2010 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2009-2010 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
*/
/**
* example.c: Example of Doomsday plugin which is called at startup.
*/
// HEADER FILES ------------------------------------------------------------
#ifdef WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "doomsday.h"
#include "dd_api.h"
#include "version.h"
// MACROS ------------------------------------------------------------------
#define DLLEXPORT __declspec( dllexport )
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
DLLEXPORT game_export_t* GetGameAPI(game_import_t* imports);
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// The interface to the Doomsday engine.
game_import_t gi;
game_export_t gx;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
// CODE --------------------------------------------------------------------
void ExampleTicker(timespan_t ticLength)
{
}
void ExampleDrawer(int layer)
{
}
boolean ExampleResponder(event_t* ev)
{
return false;
}
/**
* Get a 32-bit integer value.
*/
int G_GetInteger(int id)
{
switch(id)
{
case DD_DMU_VERSION:
return DMUAPI_VER;
default:
break;
}
return 0;
}
/**
* Get a pointer to the value of a named variable/constant.
*/
void* G_GetVariable(int id)
{
static float bob[2];
switch(id)
{
case DD_PLUGIN_NAME:
return PLUGIN_NAMETEXT;
case DD_PLUGIN_NICENAME:
return PLUGIN_NICENAME;
case DD_PLUGIN_VERSION_SHORT:
return PLUGIN_VERSION_TEXT;
case DD_PLUGIN_VERSION_LONG:
return PLUGIN_VERSION_TEXTLONG "\n" PLUGIN_DETAILS;
case DD_PLUGIN_HOMEURL:
return PLUGIN_HOMEURL;
case DD_PLUGIN_DOCSURL:
return PLUGIN_DOCSURL;
default:
break;
}
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.Ticker = ExampleTicker;
gx.G_Drawer = ExampleDrawer;
//gx.G_Drawer2 = D_Display2;
//gx.PrivilegedResponder = (boolean (*)(event_t*)) G_PrivilegedResponder;
gx.G_Responder = ExampleResponder;
gx.GetInteger = G_GetInteger;
gx.GetVariable = G_GetVariable;
#if 0
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;
gx.NetWriteCommands = D_NetWriteCommands;
gx.NetReadCommands = D_NetReadCommands;
#endif
// Data structure sizes.
/*gx.ticcmdSize = sizeof(ticcmd_t);
gx.mobjSize = sizeof(mobj_t);
gx.polyobjSize = sizeof(polyobj_t);
gx.SetupForMapData = P_SetupForMapData;
// These really need better names. Ideas?
gx.HandleMapDataPropertyValue = P_HandleMapDataPropertyValue;
gx.HandleMapObjectStatusReport = P_HandleMapObjectStatusReport;*/
return &gx;
}
/**
* This function will be called ASAP after Doomsday has completed startup.
*
* @param parm
* @param data
*
* @return Non-zero if successful.
*/
int ExampleHook(int hookType, int parm, void *data)
{
DD_AddGame(PLUGIN_NAMETEXT, DD_BASEPATH_DATA PLUGIN_NAMETEXT "\\", DD_BASEPATH_DEFS PLUGIN_NAMETEXT "\\", PLUGIN_NAMETEXT ".cfg", PLUGIN_NICENAME, PLUGIN_NICEAUTHOR, PLUGIN_NAMETEXT, 0);
return true;
}
/**
* This function is called automatically when the plugin is loaded.
* We let the engine know what we'd like to do.
*/
void DP_Initialize(void)
{
Plug_AddHook(HOOK_STARTUP, ExampleHook);
}
#ifdef WIN32
/**
* Windows calls this when the DLL is loaded.
*/
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
// Register our hooks.
DP_Initialize();
break;
default:
break;
}
return TRUE;
}
#endif