forked from 3dyne/3dyne_legacy_engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
l_wrap.cpp
454 lines (358 loc) · 9.68 KB
/
l_wrap.cpp
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/*
* 3dyne Legacy Engine GPL Source Code
*
* Copyright (C) 1996-2012 Matthias C. Berger & Simon Berger.
*
* This file is part of the 3dyne Legacy Engine GPL Source Code ("3dyne Legacy
* Engine Source Code").
*
* 3dyne Legacy Engine Source Code 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 3 of the License,
* or (at your option) any later version.
*
* 3dyne Legacy Engine Source Code 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
* 3dyne Legacy Engine Source Code. If not, see
* <http://www.gnu.org/licenses/>.
*
* In addition, the 3dyne Legacy Engine Source Code is also subject to certain
* additional terms. You should have received a copy of these additional terms
* immediately following the terms and conditions of the GNU General Public
* License which accompanied the 3dyne Legacy Engine Source Code.
*
* Contributors:
* Matthias C. Berger ([email protected]) - initial API and implementation
* Simon Berger ([email protected]) - initial API and implementation
*/
// l_wrap.c
#include "interfaces.h"
#include "r_fake/r_interface.h"
#include "r_fake/g_trace.h"
#include "defs.h"
#include "db_shape.h"
#include "db_lightmap.h"
#include "layer_defs.h"
#include "shape_defs.h"
extern g_resources_t *g_rs; // fixme
extern g_state_t *g_st;
extern int gc_localworldframe;
g_resource_t * GI_ResourceSearch( const char *name )
{
return G_ResourceSearch( g_rs, name );
}
g_resource_t * GI_ResourceAttach( char *name, char *user_name,
int (*user_callback_func)(g_resource_t *r, int reason) )
{
return G_ResourceAttach( g_rs, name, user_name, user_callback_func );
}
void GI_ResourceDetach( char *name, char *user_name )
{
G_ResourceDetach( g_rs, name, user_name );
}
hobj_t * GI_ReadClass( char *path )
{
hobj_t *root;
tokenstream_t *ts;
ts = BeginTokenStream( path );
if ( !ts )
__error( "can't open file '%s'\n", path );
root = ReadClass( ts );
EndTokenStream( ts );
return root;
}
/*
==============================
GI_RegisterWFInfo
==============================
*/
void GI_RegisterWFInfo( wfInfoType type, void *wfinfo )
{
__chkptr( g_st );
#if 0
switch( type )
{
case WFInfoType_model:
{
if ( gc_state->cl.wf_model_num >= G_CLIENT_MAX_MODELS )
__error( "reached G_CLIENT_MAX_MODELS\n" );
gc_state->cl.wf_models[gc_state->cl.wf_model_num++] = (wf_model_info_t *) wfinfo;
}
break;
case WFInfoType_dlight:
{
if ( gc_state->cl.wf_dlight_num >= G_CLIENT_MAX_DLIGHTS )
__error( "reached G_CLIENT_MAX_DLIGHTS\n" );
gc_state->cl.wf_dlights[gc_state->cl.wf_dlight_num++] = (wf_dlight_info_t *) wfinfo;
}
break;
case WFInfoType_sprite:
{
if ( gc_state->cl.wf_sprite_num >= G_CLIENT_MAX_SPRITES )
__error( "reached G_CLIENT_MAX_SPRITES\n" );
gc_state->cl.wf_sprites[gc_state->cl.wf_sprite_num++] = (wf_sprite_info_t *) wfinfo;
}
break;
case WFInfoType_fpsys:
{
if ( gc_state->cl.wf_fpsys_num >= G_CLIENT_MAX_FPSYSS )
__error( "reached G_CLIENT_MAX_FPSYSS\n" );
gc_state->cl.wf_fpsyss[gc_state->cl.wf_fpsys_num++] = (wf_fpsys_info_t *) wfinfo;
}
break;
case WFInfoType_light:
{
#if 0
//
// hack
//
wf_light_info_t *light;
light = (wf_light_info_t *) wfinfo;
LightmapDBU_ApplyLightInfo( g_st->map->lightmap_db, light );
#else
if ( gc_state->cl.wf_light_num >= G_CLIENT_MAX_LIGHTS )
__error( "reached G_CLIENT_MAX_LIGHTS\n" );
gc_state->cl.wf_lights[gc_state->cl.wf_light_num++] = (wf_light_info_t *) wfinfo;
#endif
}
break;
case WFInfoType_shape:
{
if ( gc_state->cl.wf_shape_num >= G_CLIENT_MAX_SHAPES )
__error( "reached G_CLIENT_MAX_SHAPES\n" );
gc_state->cl.wf_shapes[gc_state->cl.wf_shape_num++] = (wf_shape_info_t *) wfinfo;
}
break;
default:
__error( "unknown type\n" );
}
#endif
}
/*
==============================
GI_TraceBB
==============================
*/
g_trace_t * GI_TraceBB( vec3d_t min, vec3d_t max, vec3d_t trymin, vec3d_t trymax )
{
return G_TraceBoundBox( gc_state->map.blockmap, min, max, trymin, trymax );
}
void GI_MapTraceBB( g_trace_t *tr, vec3d_t min, vec3d_t max, vec3d_t trymin, vec3d_t trymax )
{
g_trace_t *tmp;
tmp = G_TraceBoundBox( gc_state->map.blockmap, min, max, trymin, trymax );
memcpy( tr, tmp, sizeof( g_trace_t ) );
// printf( "wrap: scale %f\n", tr->scale );
}
void GI_MapTraceLine( g_trace_t *tr, vec3d_t from, vec3d_t to )
{
G_TraceLine( gc_state->map.blockmap, tr, from, to );
}
/*
==============================
GI_SelectShapesInBoundBox
==============================
*/
void GI_SelectShapesInBoundBox( vec3d_t min, vec3d_t max, void (*action_func)(unique_t shape_id ) )
{
if ( g_st ) {
R_SelectShapesInBoundBox( min, max, action_func );
}
}
/*
==============================
GI_SelectLightSource
==============================
*/
lightsource_t * GI_SelectLightSourceWhereAnyLightID( unique_t id_any_light )
{
return gc_state->map.lightmap_db->SelectLightsourceWhereAnyLightID( id_any_light );
}
/*
==============================
GI_LightSourceUpdate
==============================
*/
void GI_LightSourceUpdate( lightsource_t *lsrc )
{
lightmap_t *lmap;
int num;
__chkptr( lsrc );
num = 0;
//
// visit all lightmaps of this source
//
for ( lmap = lsrc->head; lmap ; lmap=lmap->source_link )
{
if ( !lmap->layer_ref )
{
// __warning( "source got a lightmap that ain't got a layer_ref\n" );
continue;
}
//
// force layer to recombine lightmaps
//
lmap->layer_ref->flags &= ~LAYER_FLAGS_VALID_LIGHTMAP_COMBINE;
lmap->layer_ref->shape->flags |= SHAPE_FLAGS_LAYERS_NEED_CHECK;
num++;
}
// __named_message( " %d lightmaps changed\n", num );
}
/*
==============================
GI_GetUniqueID
==============================
*/
unique_t GI_GetUniqueID( void )
{
return GC_GetUniqueID( gc_state );
}
/*
==============================
GI_MapShapeIDSetFlatColor
==============================
*/
void GI_MapShapeIDSetFlatColor( unique_t id_shape, vec3d_t flat_color )
{
shape_t *shape;
layer_t *layer;
u_list_iter_t iter;
shape = ShapeDB_SelectShapeWhere_selfid( gc_state->map.shape_db, id_shape );
if ( shape )
{
U_ListIterInit( &iter, shape->layer_list );
for ( ; ( layer = (layer_t *)U_ListIterNext( &iter ) ) ; )
{
if ( layer->ordinal == 1 ) // the primary texture layer
{
layer->ambient_color[C_R] = (unsigned char)(flat_color[0] * 255.0);
layer->ambient_color[C_G] = (unsigned char)(flat_color[1] * 255.0);
layer->ambient_color[C_B] = (unsigned char)(flat_color[2] * 255.0);
layer->ambient_color[C_A] = 255;
break;
}
}
}
}
/*
==============================
GI_RenderAddSprite
==============================
*/
void GI_RenderAddSprite( ri_sprite_t *ri )
{
if ( gc_state->cl.ri_sprite_num >= G_CLIENT_MAX_RI_SPRITES )
{
__error( "reached G_CLIENT_MAX_RI_SPRITES\n" );
}
gc_state->cl.ri_sprites[gc_state->cl.ri_sprite_num++] = ri;
}
/*
==============================
GI_RenderAddPsys
==============================
*/
void GI_RenderAddPsys( ri_psys_t *ri )
{
if ( gc_state->cl.ri_psys_num >= G_CLIENT_MAX_RI_PSYSS )
{
__error( "reached G_CLIENT_MAX_RI_PSYSS\n" );
}
gc_state->cl.ri_psyss[gc_state->cl.ri_psys_num++] = ri;
}
/*
==============================
GI_RenderAddHalo
==============================
*/
void GI_RenderAddHalo( ri_halo_t *ri )
{
if ( gc_state->cl.ri_halo_num >= G_CLIENT_MAX_RI_HALOS )
{
__error( "reached G_CLIENT_MAX_RI_HALOS\n" );
}
gc_state->cl.ri_halos[gc_state->cl.ri_halo_num++] = ri;
}
/*
==============================
GI_RenderAddLocalLight
==============================
*/
void GI_RenderAddLocalLight( ri_local_light_t *ri )
{
if ( gc_state->cl.ri_local_light_num >= G_CLIENT_MAX_RI_LOCAL_LIGHTS )
{
__error( "reached G_CLIENT_MAX_RI_LOCAL_LIGHTS\n" );
}
gc_state->cl.ri_local_lights[gc_state->cl.ri_local_light_num++] = ri;
}
/*
==============================
GI_RenderAddModel
==============================
*/
void GI_RenderAddModel( ri_model_t *ri )
{
if ( gc_state->cl.ri_model_num >= G_CLIENT_MAX_RI_MODELS )
{
__error( "reached G_CLIENT_MAX_RI_MODELS\n" );
}
gc_state->cl.ri_models[gc_state->cl.ri_model_num++] = ri;
}
/*
==============================
GI_RenderAddView
==============================
*/
void GI_RenderAddView( ri_view_t *ri )
{
sh_var_t *tmp;
if ( ri->style == viewStyle_player )
{
tmp = SHP_GetVar( "gc_id_bind_view" );
if ( ri->id == tmp->ivalue && ri->id != UNIQUE_INVALIDE )
{
// that's a hack that tells the object not to draw models and sprites
ri->take_view = true; // tell client that this view was rendered
gc_state->cl.ri_view_player = ri;
}
}
if ( ri->style == viewStyle_spectator )
{
gc_state->cl.ri_view_spectator = ri;
}
if ( ri->style == viewStyle_sky )
{
gc_state->cl.ri_view_sky = ri;
}
}
/*
==============================
GI_DrawRect
==============================
*/
void GI_DrawRect( di_rect_t *di )
{
if ( gc_state->cl.di_rect_num >= G_CLIENT_MAX_DI_RECTS )
{
__error( "reached G_CLIENT_MAX_DI_RECTS\n" );
}
gc_state->cl.di_rects[gc_state->cl.di_rect_num++] = di;
}
/*
==============================
GI_DrawText
==============================
*/
void GI_DrawText( di_text_t *di )
{
if ( gc_state->cl.di_text_num >= G_CLIENT_MAX_DI_TEXTS )
{
__error( "reached G_CLIENT_MAX_DI_TEXTS\n" );
}
gc_state->cl.di_texts[gc_state->cl.di_text_num++] = di;
}