Jo Engine  9
Jo Sega Saturn Engine
sprites.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2017, Johannes Fetz (johannesfetz@gmail.com)
4 ** All rights reserved.
5 **
6 ** Redistribution and use in source and binary forms, with or without
7 ** modification, are permitted provided that the following conditions are met:
8 ** * Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** * Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** * Neither the name of the Johannes Fetz nor the
14 ** names of its contributors may be used to endorse or promote products
15 ** derived from this software without specific prior written permission.
16 **
17 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 ** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
35 #ifndef __JO_SPRITES_H__
36 # define __JO_SPRITES_H__
37 
38 /*
39 ** INCLUDES
40 */
41 #include "types.h"
42 #include "image.h"
43 #include "tga.h"
44 #include "math.h"
45 #include "colors.h"
46 
58 extern jo_texture_definition __jo_sprite_def[JO_MAX_SPRITE];
62 extern jo_picture_definition __jo_sprite_pic[JO_MAX_SPRITE];
66 void jo_sprite_draw(const int sprite_id, const jo_pos3D * const pos, const bool centered_style_coordinates, const bool billboard);
70 void jo_sprite_draw_rotate(const int sprite_id, const jo_pos3D * const pos, const int angle, const bool centered_style_coordinates, const bool billboard);
71 
72 /*
73 ** INTERNAL
74 */
76 static __jo_force_inline void __internal_jo_sprite_set_position3D(const int x, const int y, const int z)
77 {
78  __jo_sprite_pos.x = x;
79  __jo_sprite_pos.y = y;
80  __jo_sprite_pos.z = z;
81 }
82 
86 int jo_get_last_sprite_id(void);
87 
92 int jo_sprite_add(const jo_img * const img);
93 
98 int jo_sprite_add_8bits_image(const jo_img_8bits * const img);
99 
105 int jo_sprite_replace(const jo_img * const img, const int sprite_id);
106 
111 void jo_sprite_free_from(const int sprite_id);
112 
117 {
119 }
120 
126 int jo_sprite_name2id(const char *const filename);
127 
128 /*
129 ** Screen doors filter (old school transparency)
130 */
134 {
135  __jo_sprite_attributes.effect |= 256;
136 }
137 
141 {
142  __jo_sprite_attributes.effect &= ~(256);
143 }
144 
145 
149 {
150  __jo_sprite_attributes.effect |= 1;
151 }
152 
156 {
157  __jo_sprite_attributes.effect &= ~(1);
158 }
159 
160 /*
161 ** Dark filter
162 */
166 {
167  __jo_sprite_attributes.effect |= 2;
168 }
169 
173 {
174  __jo_sprite_attributes.effect &= ~(2);
175 }
176 
177 /*
178 ** Half transparency
179 */
183 {
184  __jo_sprite_attributes.effect |= 3;
185 }
186 
190 {
191  __jo_sprite_attributes.effect &= ~(3);
192 }
193 
194 /*
195 ** Gouraud Shading
196 */
198 # define JO_NO_GOURAUD_COLOR (0xc210)
199 
206 void jo_set_gouraud_shading_colors(const jo_color topleft_color,
207  const jo_color topright_color,
208  const jo_color bottomright_color,
209  const jo_color bottomleft_color);
210 
214 {
215  __jo_sprite_attributes.effect |= 4;
216 }
217 
221 {
222  __jo_sprite_attributes.effect &= ~(4);
223 }
224 
226 # define JO_DEFAULT_BRIGHTNESS (16)
227 
229 # define JO_MAX_BRIGHTNESS (31)
230 
234 void jo_set_gouraud_shading_brightness(const unsigned char brightness);
235 
236 /*
237 ** Vertical flip
238 */
242 {
243  __jo_sprite_attributes.direction |= 32;
244 }
245 
249 {
250  __jo_sprite_attributes.direction &= ~(32);
251 }
252 
253 /*
254 ** Horizontal flip
255 */
258 {
259  __jo_sprite_attributes.direction |= 16;
260 }
261 
265 {
266  __jo_sprite_attributes.direction &= ~(16);
267 }
268 
269 /*
270 ** Change sprite scale
271 */
275 static __jo_force_inline void jo_sprite_change_sprite_scale(const float scale)
276 {
277  __jo_sprite_attributes.fixed_scale = (int)(scale * 65536.f);
278 }
279 
283 {
284  __jo_sprite_attributes.fixed_scale = JO_FIXED_1;
285 }
286 
294 static __jo_force_inline void jo_sprite_draw3D_and_rotate(const int sprite_id, const int x, const int y, const int z, const int angle)
295 {
297  jo_sprite_draw_rotate(sprite_id, &__jo_sprite_pos, angle, true, false);
298 }
299 
306 static __jo_force_inline void jo_sprite_draw3D(const int sprite_id, const int x, const int y, const int z)
307 {
309  jo_sprite_draw(sprite_id, &__jo_sprite_pos, true, false);
310 }
311 
319 static __jo_force_inline void jo_sprite_draw3D_and_rotate2(const int sprite_id, const int x, const int y, const int z, const int angle)
320 {
322  jo_sprite_draw_rotate(sprite_id, &__jo_sprite_pos, angle, false, false);
323 }
324 
331 static __jo_force_inline void jo_sprite_draw3D2(const int sprite_id, const int x, const int y, const int z)
332 {
334  jo_sprite_draw(sprite_id, &__jo_sprite_pos, false, false);
335 }
336 
337 /*
338 ** Some helper to get pixel color in texture
339 */
346 static __jo_force_inline jo_color jo_sprite_get_pixel_color(const jo_color * const data, const unsigned int x, const unsigned int y, const unsigned int image_width)
347 {
348  return data[x + y * image_width];
349 }
350 
358 static __jo_force_inline bool jo_sprite_is_pixel_transparent(const jo_color * const data, const unsigned int x, const unsigned int y, const unsigned int image_width)
359 {
360  return jo_sprite_get_pixel_color(data, x, y, image_width) == JO_COLOR_Transparent;
361 }
362 
367 static __jo_force_inline int jo_sprite_get_width(const int sprite_id)
368 {
369  return (__jo_sprite_def[sprite_id].width);
370 }
371 
376 static __jo_force_inline int jo_sprite_get_height(const int sprite_id)
377 {
378  return (__jo_sprite_def[sprite_id].height);
379 }
380 
385 {
386  return (jo_get_last_sprite_id() + 1);
387 }
388 
393 int jo_sprite_usage_percent(void);
394 
395 #endif /* !__JO_SPRITES_H__ */
396 
397 /*
398 ** END OF FILE
399 */
int jo_sprite_usage_percent(void)
Get sprite memory usage.
Jo Engine Math tools.
static __jo_force_inline void jo_sprite_enable_horizontal_flip(void)
Activate horizontal flip for every sprite displayed after this call.
Definition: sprites.h:257
static __jo_force_inline void jo_sprite_enable_shadow_filter(void)
Activate shadow filter for every sprite displayed after this call.
Definition: sprites.h:148
jo_texture_definition __jo_sprite_def[JO_MAX_SPRITE]
(internal engine usage)
static __jo_force_inline void jo_sprite_enable_screen_doors_filter(void)
Activate screen doors filter for every sprite displayed after this call.
Definition: sprites.h:133
Jo Engine Types.
void jo_set_gouraud_shading_brightness(const unsigned char brightness)
Change Gouraud Shading brightness.
static __jo_force_inline void jo_sprite_disable_half_transparency(void)
Disable half transparency for every sprite displayed after this call.
Definition: sprites.h:189
jo_picture_definition __jo_sprite_pic[JO_MAX_SPRITE]
(internal engine usage)
unsigned short jo_color
15 bits color type
Definition: types.h:39
Texture definition.
Definition: types.h:131
static __jo_force_inline void jo_sprite_draw3D(const int sprite_id, const int x, const int y, const int z)
Display a sprite in 3 dimensional space.
Definition: sprites.h:306
static __jo_force_inline void jo_sprite_enable_dark_filter(void)
Activate dark filter for every sprite displayed after this call.
Definition: sprites.h:165
static __jo_force_inline void jo_sprite_enable_half_transparency(void)
Activate half transparency for every sprite displayed after this call.
Definition: sprites.h:182
int x
Definition: types.h:53
void jo_sprite_draw(const int sprite_id, const jo_pos3D *const pos, const bool centered_style_coordinates, const bool billboard)
(internal engine usage)
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: conf.h:154
int jo_sprite_add(const jo_img *const img)
Add a sprite.
static __jo_force_inline jo_color jo_sprite_get_pixel_color(const jo_color *const data, const unsigned int x, const unsigned int y, const unsigned int image_width)
Get a specific pixel color from image bytes.
Definition: sprites.h:346
15 bits image struct
Definition: image.h:44
static __jo_force_inline void jo_sprite_disable_screen_doors_filter(void)
Disable screen doors filter for every sprite displayed after this call.
Definition: sprites.h:140
int y
Definition: types.h:54
#define JO_COLOR_Transparent
Definition: colors.h:83
static __jo_force_inline void jo_sprite_disable_horizontal_flip(void)
Disable horizontal flip for every sprite displayed after this call.
Definition: sprites.h:264
jo_sprite_attributes __jo_sprite_attributes
Current displayed sprite attribute (internal engine usage)
3D position
Definition: types.h:51
static __jo_force_inline void jo_sprite_disable_vertical_flip(void)
Disable vertical flip for every sprite displayed after this call.
Definition: sprites.h:248
Picture definition.
Definition: types.h:139
static __jo_force_inline void jo_sprite_free_all(void)
Free all sprites.
Definition: sprites.h:116
Jo Engine Image definition and tools.
void jo_sprite_free_from(const int sprite_id)
Free all sprites from the given sprite_id.
Jo Engine Standard colors.
static __jo_force_inline void jo_sprite_disable_shadow_filter(void)
Disable shadow filter for every sprite displayed after this call.
Definition: sprites.h:155
jo_pos3D __jo_sprite_pos
Current displayed sprite position (internal engine usage)
Sprite attributes.
Definition: types.h:147
static __jo_force_inline void jo_sprite_draw3D_and_rotate(const int sprite_id, const int x, const int y, const int z, const int angle)
Display a sprite in 3 dimensional space.
Definition: sprites.h:294
static __jo_force_inline void jo_sprite_disable_dark_filter(void)
Disable dark filter for every sprite displayed after this call.
Definition: sprites.h:172
static __jo_force_inline int jo_sprite_count(void)
Get sprite count.
Definition: sprites.h:384
unsigned short effect
Definition: types.h:149
int jo_sprite_replace(const jo_img *const img, const int sprite_id)
Replace a sprite.
static __jo_force_inline int jo_sprite_get_width(const int sprite_id)
Get sprite width.
Definition: sprites.h:367
int z
Definition: types.h:55
int jo_get_last_sprite_id(void)
Get last Sprite Id.
static __jo_force_inline void jo_sprite_draw3D2(const int sprite_id, const int x, const int y, const int z)
Display a sprite in 3 dimensional space.
Definition: sprites.h:331
Jo Engine Truevision Targa format support.
static __jo_force_inline void jo_sprite_draw3D_and_rotate2(const int sprite_id, const int x, const int y, const int z, const int angle)
Display a sprite in 3 dimensional space.
Definition: sprites.h:319
#define JO_FIXED_1
Fixed floating point value for 1.
Definition: math.h:60
void jo_sprite_draw_rotate(const int sprite_id, const jo_pos3D *const pos, const int angle, const bool centered_style_coordinates, const bool billboard)
(internal engine usage)
static __jo_force_inline void jo_sprite_restore_sprite_scale(void)
Restore default scale for every sprite displayed after this call.
Definition: sprites.h:282
static __jo_force_inline void jo_sprite_enable_vertical_flip(void)
Activate vertical flip for every sprite displayed after this call.
Definition: sprites.h:241
int jo_sprite_add_8bits_image(const jo_img_8bits *const img)
Add a 8 bits sprite.
static __jo_force_inline void jo_sprite_disable_gouraud_shading(void)
Disable Gouraud Shading for every sprite displayed after this call.
Definition: sprites.h:220
8 bits image struct
Definition: image.h:52
static __jo_force_inline bool jo_sprite_is_pixel_transparent(const jo_color *const data, const unsigned int x, const unsigned int y, const unsigned int image_width)
Get if a specific pixel is transparent (JO_COLOR_Transparent) in image bytes.
Definition: sprites.h:358
unsigned short direction
Definition: types.h:150
unsigned int fixed_scale
Definition: types.h:153
int jo_sprite_name2id(const char *const filename)
Retrive the Sprite Id from filename based on the four first character in the filename.
void jo_set_gouraud_shading_colors(const jo_color topleft_color, const jo_color topright_color, const jo_color bottomright_color, const jo_color bottomleft_color)
Change Gouraud Shading colors.
static __jo_force_inline void jo_sprite_enable_gouraud_shading(void)
Activate Gouraud Shading for every sprite displayed after this call.
Definition: sprites.h:213
static __jo_force_inline void __internal_jo_sprite_set_position3D(const int x, const int y, const int z)
Internal usage don't use it.
Definition: sprites.h:76
static __jo_force_inline void jo_sprite_change_sprite_scale(const float scale)
Change scale for every sprite displayed after this call.
Definition: sprites.h:275
static __jo_force_inline int jo_sprite_get_height(const int sprite_id)
Get sprite height.
Definition: sprites.h:376