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
|
/*
* Copyright � 2006-2016 SplinterGU (Fenix/Bennugd)
* Copyright � 2002-2006 Fenix Team (Fenix)
* Copyright � 1999-2002 Jos� Luis Cebri�n Pag�e (Fenix)
*
* This file is part of Bennu - Game Development
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* --------------------------------------------------------------------------- */
#ifdef __GNUC__
#define _inline inline
#endif
/* --------------------------------------------------------------------------- */
#include "librender.h"
#include "resolution.h"
#include "sysprocs_st.h"
/* --------------------------------------------------------------------------- */
/*
* FUNCTION : instance_graph
*
* Returns the instance graphic or NULL if there is none
*
* PARAMS :
* i Pointer to the instance
*
* RETURN VALUE :
* Pointer to the graphic or NULL if none
*/
GRAPH * instance_graph( INSTANCE * i )
{
int * xgraph, c, a ;
if (( xgraph = ( int * ) LOCDWORD( librender, i, XGRAPH ) ) ) // Get offset of XGRAPH table
{
c = *xgraph++; // Get number of graphs ids in XGRAPH table
if ( c )
{
// Normalize ANGLE
a = LOCINT32( librender, i, ANGLE ) % 360000 ;
if ( a < 0 ) a += 360000 ;
// Get graph id in XGRAPH table to draw
c = xgraph[a * c / 360000] ;
// If graph id value is negative, then graphic must be mirrored
if ( c < 0 )
{
c = -c;
LOCDWORD( librender, i, XGRAPH_FLAGS ) = B_HMIRROR;
}
else
{
LOCDWORD( librender, i, XGRAPH_FLAGS ) = 0;
}
// Get GRAPH * to draw
return bitmap_get( LOCDWORD( librender, i, FILEID ), c ) ;
}
}
// Get GRAPH * to draw
if (( c = LOCDWORD( librender, i, GRAPHID ) ) )
{
return bitmap_get( LOCDWORD( librender, i, FILEID ), c ) ;
}
return 0 ; // No graph to draw
}
void instance_get_bbox( INSTANCE * i, GRAPH * gr, REGION * dest )
{
REGION *region;
int x, y, r ;
int scalex, scaley ;
r = LOCINT32( librender, i, REGIONID ) ;
if ( r > 0 && r < 32 )
region = ®ions[ r ] ;
else
region = ®ions[ 0 ];
x = LOCINT32( librender, i, COORDX ) ;
y = LOCINT32( librender, i, COORDY ) ;
RESOLXY( librender, i, x, y );
scalex = LOCINT32( librender, i, GRAPHSIZEX );
scaley = LOCINT32( librender, i, GRAPHSIZEY );
if ( scalex == 100 && scaley == 100 ) scalex = scaley = LOCINT32( librender, i, GRAPHSIZE );
gr_get_bbox( dest,
region,
x,
y,
LOCDWORD( librender, i, FLAGS ) ^ LOCDWORD( librender, i, XGRAPH_FLAGS ),
LOCDWORD( librender, i, XGRAPH ) ? 0 : LOCINT32( librender, i, ANGLE ),
scalex,
scaley,
gr
) ;
}
/* ---------------------------------------------------------------------- */
void draw_instance_at( INSTANCE * i, REGION * region, int x, int y, GRAPH * dest )
{
GRAPH * map ;
int16_t * blend_table = NULL ;
int flags ;
int scalex, scaley ;
int alpha ;
int blendop;
PALETTE * palette = NULL;
int paletteid;
map = instance_graph( i ) ;
if ( !map ) return ;
flags = ( LOCDWORD( librender, i, FLAGS ) ^ LOCDWORD( librender, i, XGRAPH_FLAGS ) );
if (( alpha = LOCDWORD( librender, i, ALPHA ) ) != 255 )
{
if ( alpha <= 0 ) return ;
else if ( alpha < 255 )
flags |= B_ALPHA | ( alpha << B_ALPHA_SHIFT );
}
scalex = LOCINT32( librender, i, GRAPHSIZEX );
scaley = LOCINT32( librender, i, GRAPHSIZEY );
if ( scalex == 100 && scaley == 100 ) scalex = scaley = LOCINT32( librender, i, GRAPHSIZE );
if (( blendop = LOCDWORD( librender, i, BLENDOP ) ) )
{
blend_table = map->blend_table;
map->blend_table = ( int16_t * ) blendop;
}
if (( paletteid = LOCDWORD( librender, i, PALETTEID ) ) )
{
palette = map->format->palette ;
map->format->palette = ( PALETTE * ) paletteid;
}
/* XGRAPH does not rotate destination graphic.
WARNING: don't remove "scalex != 100 || scaley != 100 ||" from begin the next condition */
if ( scalex != 100 || scaley != 100 || ( LOCINT32( librender, i, ANGLE ) && !LOCDWORD( librender, i, XGRAPH ) ) )
gr_rotated_blit( dest, region, x, y, flags, LOCDWORD( librender, i, XGRAPH ) ? 0 : LOCINT32( librender, i, ANGLE ), scalex, scaley, map ) ;
else
gr_blit( dest, region, x, y, flags, map ) ;
if ( paletteid ) map->format->palette = palette;
if ( blendop ) map->blend_table = blend_table;
}
/* --------------------------------------------------------------------------- */
/* Rutinas gr�ficas de alto nivel */
void draw_instance( INSTANCE * i, REGION * clip )
{
GRAPH * map ;
int16_t * blend_table = NULL ;
int flags;
int scalex, scaley;
REGION region;
int alpha ;
int blendop = 0 ;
PALETTE * palette = NULL ;
int paletteid;
/* Difference with draw_instance_at from here */
int x, y, r ;
/* Difference with draw_instance_at to here */
// map = instance_graph( i ) ;
map = ( GRAPH * ) LOCDWORD( librender, i, GRAPHPTR );
if ( !map ) return ;
flags = ( LOCDWORD( librender, i, FLAGS ) ^ LOCDWORD( librender, i, XGRAPH_FLAGS ) );
if (( alpha = LOCDWORD( librender, i, ALPHA ) ) != 255 )
{
if ( alpha <= 0 ) return ;
else if ( alpha < 255 )
flags |= B_ALPHA | ( alpha << B_ALPHA_SHIFT );
}
scalex = LOCINT32( librender, i, GRAPHSIZEX );
scaley = LOCINT32( librender, i, GRAPHSIZEY );
if ( scalex == 100 && scaley == 100 ) scalex = scaley = LOCINT32( librender, i, GRAPHSIZE );
if (( blendop = LOCDWORD( librender, i, BLENDOP ) ) )
{
blend_table = map->blend_table;
map->blend_table = ( int16_t * ) blendop;
}
if (( paletteid = LOCDWORD( librender, i, PALETTEID ) ) )
{
palette = map->format->palette ;
map->format->palette = ( PALETTE * ) paletteid;
}
/* Difference with draw_instance_at from here */
x = LOCINT32( librender, i, COORDX ) ;
y = LOCINT32( librender, i, COORDY ) ;
RESOLXY( librender, i, x, y );
r = LOCINT32( librender, i, REGIONID ) ;
if ( r > 0 && r < 32 )
region = regions[ r ] ;
else
region = regions[ 0 ];
if ( clip ) region_union( ®ion, clip );
/* Difference with draw_instance_at to here */
/* XGRAPH does not rotate destination graphic.
WARNING: don't remove "scalex != 100 || scaley != 100 ||" from begin the next condition */
if ( scalex != 100 || scaley != 100 || ( LOCINT32( librender, i, ANGLE ) && !LOCDWORD( librender, i, XGRAPH ) ) )
gr_rotated_blit( 0, ®ion, x, y, flags, LOCDWORD( librender, i, XGRAPH ) ? 0 : LOCINT32( librender, i, ANGLE ), scalex, scaley, map ) ;
else
gr_blit( 0, ®ion, x, y, flags, map ) ;
if ( paletteid ) map->format->palette = palette;
if ( blendop ) map->blend_table = blend_table;
if ( map->modified ) map->modified = 0;
}
/* --------------------------------------------------------------------------- */
/*
* FUNCTION : draw_instance_info
*
* Compares the internal position variables of the instance with its
* currents values, and returns 1 if there is any difference. Used
* to detect changes in a visible process's aspect or position.
*
* PARAMS :
* i Pointer to the instance
*
* RETURN VALUE :
* 1 if there is any change, 0 otherwise
*/
int draw_instance_info( INSTANCE * i, REGION * region, int * z, int * drawme )
{
GRAPH * graph;
* drawme = 0;
LOCDWORD( librender, i, GRAPHPTR ) = ( int )( graph = instance_graph( i ) );
if ( !graph )
{
/*
region->x = -2; region->y = -2;
region->x2 = -2; region->y2 = -2;
*/
return 0;
}
int changed;
int status;
int coordz, coordx, coordy;
status = ( LOCDWORD( librender, i, STATUS ) & ~STATUS_WAITING_MASK ) ;
coordz = LOCINT32( librender, i, COORDZ );
/* Si tiene grafico o xgraph o (ctype == 0 y esta corriendo o congelado) */
if ( LOCDWORD( librender, i, CTYPE ) == C_SCREEN && ( status == STATUS_RUNNING || status == STATUS_FROZEN ) )
* drawme = 1;
coordx = LOCINT32( librender, i, COORDX );
coordy = LOCINT32( librender, i, COORDY );
RESOLXY( librender, i, coordx, coordy );
changed =
graph->modified ||
LOCINT32( librender, i, SAVED_COORDX ) != coordx ||
LOCINT32( librender, i, SAVED_COORDY ) != coordy ||
LOCINT32( librender, i, SAVED_COORDZ ) != coordz ||
LOCDWORD( librender, i, SAVED_GRAPHID ) != LOCDWORD( librender, i, GRAPHID ) ||
LOCINT32( librender, i, SAVED_ANGLE ) != LOCINT32( librender, i, ANGLE ) ||
LOCDWORD( librender, i, SAVED_ALPHA ) != LOCDWORD( librender, i, ALPHA ) ||
LOCDWORD( librender, i, SAVED_BLENDOP ) != LOCDWORD( librender, i, BLENDOP ) ||
LOCINT32( librender, i, SAVED_GRAPHSIZE ) != LOCINT32( librender, i, GRAPHSIZE ) ||
LOCINT32( librender, i, SAVED_GRAPHSIZEX ) != LOCINT32( librender, i, GRAPHSIZEX ) ||
LOCINT32( librender, i, SAVED_GRAPHSIZEY ) != LOCINT32( librender, i, GRAPHSIZEY ) ||
LOCDWORD( librender, i, SAVED_FLAGS ) != LOCDWORD( librender, i, FLAGS ) ||
LOCDWORD( librender, i, SAVED_FILEID ) != LOCDWORD( librender, i, FILEID ) ||
LOCDWORD( librender, i, SAVED_XGRAPH ) != LOCDWORD( librender, i, XGRAPH ) ||
(
graph->ncpoints &&
(
LOCDWORD( librender, i, SAVED_CENTERX ) != graph->cpoints[0].x ||
LOCDWORD( librender, i, SAVED_CENTERY ) != graph->cpoints[0].y
)
)
;
if ( changed )
{
/* Update key */
* z = coordz;
LOCINT32( librender, i, SAVED_COORDX ) = coordx;
LOCINT32( librender, i, SAVED_COORDY ) = coordy;
LOCINT32( librender, i, SAVED_COORDZ ) = coordz;
LOCDWORD( librender, i, SAVED_GRAPHID ) = LOCDWORD( librender, i, GRAPHID );
LOCINT32( librender, i, SAVED_ANGLE ) = LOCINT32( librender, i, ANGLE );
LOCDWORD( librender, i, SAVED_ALPHA ) = LOCDWORD( librender, i, ALPHA );
LOCDWORD( librender, i, SAVED_BLENDOP ) = LOCDWORD( librender, i, BLENDOP );
LOCINT32( librender, i, SAVED_GRAPHSIZE ) = LOCINT32( librender, i, GRAPHSIZE );
LOCINT32( librender, i, SAVED_GRAPHSIZEX ) = LOCINT32( librender, i, GRAPHSIZEX );
LOCINT32( librender, i, SAVED_GRAPHSIZEY ) = LOCINT32( librender, i, GRAPHSIZEY );
LOCDWORD( librender, i, SAVED_FLAGS ) = LOCDWORD( librender, i, FLAGS );
LOCDWORD( librender, i, SAVED_FILEID ) = LOCDWORD( librender, i, FILEID );
LOCDWORD( librender, i, SAVED_XGRAPH ) = LOCDWORD( librender, i, XGRAPH );
if ( graph->ncpoints )
{
LOCDWORD( librender, i, SAVED_CENTERX ) = graph->cpoints[0].x;
LOCDWORD( librender, i, SAVED_CENTERY ) = graph->cpoints[0].y;
}
else
{
LOCDWORD( librender, i, SAVED_CENTERX ) = CPOINT_UNDEFINED;
LOCDWORD( librender, i, SAVED_CENTERY ) = CPOINT_UNDEFINED;
}
instance_get_bbox( i, graph, region );
return 1;
}
return changed;
}
/* ----------------------------------------------------------------------
Dlls Hooks
---------------------------------------------------------------------- */
/*
* FUNCTION : instance_create_hook
*
* PARAMS :
* r Pointer to the instance
*
* RETURN VALUE :
* None
*/
void __bgdexport( librender, instance_create_hook )( INSTANCE * r )
{
/* COORZ is 0 when a new instance is created */
LOCDWORD( librender, r, OBJECTID ) = gr_new_object( /* LOCINT32( librender, r, COORDZ ) */ 0, draw_instance_info, draw_instance, r );
}
/*
* FUNCTION : instance_destroy_hook
*
* PARAMS :
* r Pointer to the instance
*
* RETURN VALUE :
* None
*/
void __bgdexport( librender, instance_destroy_hook )( INSTANCE * r )
{
if ( LOCDWORD( librender, r, OBJECTID ) ) gr_destroy_object( LOCDWORD( librender, r, OBJECTID ) );
}
|