Jo Engine 2026.11.6
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
cell.h
Go to the documentation of this file.
1/*
2** Jo Sega Saturn Engine
3** Copyright (c) 2012-2026, 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*/
41
42#ifndef __JO_CELL_H__
43# define __JO_CELL_H__
44
45#if defined(JO_COMPILE_WITH_FS_SUPPORT) && defined(JO_COMPILE_WITH_3D_SUPPORT)
46
48# define JO_CELL_MAX (48)
50# define JO_CELL_MAX_PORTALS (96)
52# define JO_CELL_MAX_DRAWN (12)
53
55typedef struct
56{
57 jo_3d_mesh *mesh; // Model of the cell (world coordinates), JO_NULL: none
58 jo_3d_mesh *reflection; // Simpler model drawn in its mirrors (a polished floor), JO_NULL: its model
59 jo_pos3D_fixed center; // Bounding sphere of the model
60 int radius;
61 int x0; // Box where the player can walk (world units)
62 int z0;
63 int x1;
64 int z1;
65 int floor0; // Floor (Saturn Y): see JO_LEVEL_CELL_SLOPE_xxx
66 int floor1;
67 unsigned short slope;
68 unsigned short first_portal;
69 unsigned short portal_count;
70 short yaw; // The box is turned around its center (degrees)
71 jo_fixed cos; // Of the yaw (0 and 1: not turned)
73} jo_cell;
74
76typedef struct
77{
78 jo_pos3D_fixed points[4]; // Corners (world space)
79 unsigned short cell; // Cell seen through it
80 unsigned short kind; // JO_LEVEL_PORTAL_xxx
82
87int jo_cells_load(jo_level * const level);
88
92void jo_cells_free(void);
93
96
101
105const jo_cell *jo_cells_get(const int index);
106
114
121int jo_cell_floor(const jo_cell * const cell, const int x, const int z);
122
130int jo_cells_find(const jo_fixed x, const jo_fixed y, const jo_fixed z, const int step);
131
140bool jo_cells_floor(const jo_fixed x, const jo_fixed y, const jo_fixed z, const int step, int * const floor);
141
150bool jo_cells_is_walkable(const jo_fixed x, const jo_fixed y, const jo_fixed z, const int radius, const int step);
151
157int jo_cells_draw(const jo_pos3D_fixed * const camera);
158
164int jo_cells_prepare(const jo_pos3D_fixed * const camera);
165
172void jo_cells_draw_prepared(const bool slave);
173
180void jo_cells_draw_prepared_part(const bool slave, const int part, const int handicap);
181
189void jo_cells_draw_prepared_share(const bool slave, const int part, const int share);
190
192# define JO_CELLS_DEFAULT_SHARE (400)
194# define JO_CELLS_DEFAULT_MAX_SHARE (1024)
195
201
214void jo_cells_draw_prepared_on_both_cpus(void (* const slave_before)(void), const int slave_polygons);
215
222
227void jo_cells_set_share_limits(const int min, const int max);
228
231
243bool jo_cells_draw_mirror(void (*draw_more)(void));
244
250
256void jo_cells_set_window_distance(const int distance);
257
265bool jo_cells_view_rect_at(const jo_pos3D_fixed * const position, jo_3d_rect * const rect);
266
274bool jo_cells_seen_through(const int index, jo_3d_rect * const rect);
275
281bool jo_cells_seen_through_window(const int index);
282
287bool jo_cells_is_drawn(const int index);
288
297int jo_cells_close_portals(const jo_fixed x, const jo_fixed z, const int radius, const bool closed);
298
306int jo_cells_depth_bias_at(const jo_fixed x, const jo_fixed y, const jo_fixed z);
307
316int jo_cells_object_cell(const jo_fixed x, const jo_fixed y, const jo_fixed z);
317
324void jo_cells_set_portal_clipping(const bool enabled);
325
333void jo_cells_set_occluders(const bool enabled);
334
341int jo_cells_window_of(const int bias);
342
347int jo_cells_depth_bias_of(const int cell);
348
352unsigned short jo_cells_generation(void);
353
362bool jo_cells_ray_hit(const jo_pos3D_fixed * const origin, const jo_pos3D_fixed * const dir, const jo_fixed max_t,
363 jo_fixed * const t, jo_pos3D_fixed * const normal);
364
370int jo_cells_add_point_light_meshes(const bool shadows);
371
372#endif /* !JO_COMPILE_WITH_FS_SUPPORT && JO_COMPILE_WITH_3D_SUPPORT */
373
374#endif /* !__JO_CELL_H__ */
375
376/*
377** END OF FILE
378*/
Mesh structure.
Definition 3d.h:248
A rectangle of the screen (pixels, the edges are in it).
Definition 3d.h:1624
int radius
Definition cell.h:60
jo_pos3D_fixed points[4]
Definition cell.h:78
bool jo_cells_is_drawn(const int index)
Check if a cell was drawn in the last call of jo_cells_draw() or jo_cells_prepare() (the objects in t...
jo_3d_mesh * reflection
Definition cell.h:58
int floor1
Definition cell.h:66
bool jo_cells_floor(const jo_fixed x, const jo_fixed y, const jo_fixed z, const int step, int *const floor)
Floor under a position.
int jo_cells_draw(const jo_pos3D_fixed *const camera)
Draw the cells seen from the camera (the camera matrix is the current matrix, see jo_3d_set_depth_bia...
void jo_cells_draw_prepared_on_both_cpus(void(*const slave_before)(void), const int slave_polygons)
Draw the cells found by jo_cells_prepare() on the 2 CPUs: the slave CPU draws its part (a job,...
int jo_cells_object_cell(const jo_fixed x, const jo_fixed y, const jo_fixed z)
Cell of an object (see jo_cells_depth_bias_at()).
void jo_cells_balance_share(void)
Balance the share of the CPUs for the next frame (see jo_cells_draw_prepared_on_both_cpus()): more po...
bool jo_cells_have_exits(void)
Check if a cell has a door or a window to the outside (the level is not an inside level: there is a w...
bool jo_cells_draw_mirror(void(*draw_more)(void))
Draw the mirror seen by the camera (in the cell of the camera or in a cell seen through a door),...
jo_3d_mesh * mesh
Definition cell.h:57
int jo_cells_prepare(const jo_pos3D_fixed *const camera)
Find the cells seen from the camera (the camera matrix is the current matrix): jo_cells_draw() in 2 p...
jo_pos3D_fixed center
Definition cell.h:59
void jo_cells_set_share_limits(const int min, const int max)
Limits of the share of the master CPU (see jo_cells_draw_prepared_on_both_cpus()).
void jo_cells_free(void)
Free the cells (and their models).
int jo_cells_window_of(const int bias)
The window of an object drawn with a depth bias of the cells (see jo_cells_depth_bias_at(),...
int floor0
Definition cell.h:65
bool jo_cells_seen_through_window(const int index)
Check if a cell is seen from the outside through one of its windows in this frame (see jo_cells_set_w...
short yaw
Definition cell.h:70
unsigned short cell
Definition cell.h:79
int jo_cells_load(jo_level *const level)
Create the cells of a level (sections CELL and PRTL): the previous ones are freed.
int jo_cells_depth_bias_of(const int cell)
Depth bias of an object in a cell (see jo_cells_depth_bias_at()).
void jo_cells_draw_prepared_part(const bool slave, const int part, const int handicap)
Draw a part of the cells found by jo_cells_prepare(): the 2 CPUs draw them together (the meshes split...
void jo_cells_set_occluders(const bool enabled)
A polygon of the cell of the camera that covers the whole screen (the camera near a wall,...
int x1
Definition cell.h:63
int jo_cells_depth_bias_at(const jo_fixed x, const jo_fixed y, const jo_fixed z)
Depth bias of an object in the cells (see jo_cells_draw()): the cells seen through more portals are d...
unsigned short first_portal
Definition cell.h:68
int jo_cells_outside_view(jo_3d_rect *const rect)
Rectangle of the screen where the outside is seen (after jo_cells_prepare()): the portals of the cell...
bool jo_cells_seen_through(const int index, jo_3d_rect *const rect)
The rectangle of the screen where a cell is seen from the outside (through its doors and its near win...
unsigned short slope
Definition cell.h:67
void jo_cells_set_portal_clipping(const bool enabled)
The cells seen through the portals are drawn in the far window (JO_3D_FAR_WINDOW),...
unsigned short jo_cells_generation(void)
Generation of the cells: it changes when cells are loaded or freed (the cells found before are then s...
void jo_cells_draw_prepared(const bool slave)
Draw the cells found by jo_cells_prepare().
jo_fixed cos
Definition cell.h:71
int jo_cells_close_portals(const jo_fixed x, const jo_fixed z, const int radius, const bool closed)
Close the portals of a door (JO_LEVEL_PORTAL_DOOR) whose middle is near a point: the cells behind the...
int jo_cells_count(void)
Number of cells.
const jo_cell * jo_cells_get(const int index)
A cell.
int x0
Definition cell.h:61
bool jo_cells_view_rect_at(const jo_pos3D_fixed *const position, jo_3d_rect *const rect)
The rectangle of the screen where a point is seen (the cell of the point seen through the doors,...
int z0
Definition cell.h:62
int jo_cells_find(const jo_fixed x, const jo_fixed y, const jo_fixed z, const int step)
Cell of a position: its box has the position, its floor is under it (the highest one).
int jo_cells_get_share(void)
Share of the polygons of the cells drawn by the master CPU in the next frame (0 to 1024).
int jo_cells_prepared_polygon_count(void)
Polygons of the cells found by jo_cells_prepare() (the polygons of the chunks seen of the meshes seen...
int jo_cells_add_point_light_meshes(const bool shadows)
The models of the cells are lit by the point lights (see jo/light.h): their meshes are added,...
int jo_cell_floor(const jo_cell *const cell, const int x, const int z)
Floor of a cell at a position (its slope).
int z1
Definition cell.h:64
bool jo_cells_ray_hit(const jo_pos3D_fixed *const origin, const jo_pos3D_fixed *const dir, const jo_fixed max_t, jo_fixed *const t, jo_pos3D_fixed *const normal)
First wall (polygon of a cell) hit by a ray (the bullets).
unsigned short kind
Definition cell.h:80
bool jo_cells_mirror_is_floor(void)
The mirror drawn now (in draw_more of jo_cells_draw_mirror()) is a polished floor (a horizontal porta...
bool jo_cells_is_walkable(const jo_fixed x, const jo_fixed y, const jo_fixed z, const int radius, const int step)
Check if the player can stand at a position: a circle around it is in the box of a cell,...
void jo_cells_set_window_distance(const int distance)
Distance from the outside under which a cell is seen through its windows (portals JO_LEVEL_PORTAL_WIN...
void jo_cells_draw_prepared_share(const bool slave, const int part, const int share)
Draw a part of the cells found by jo_cells_prepare(): the 2 CPUs draw them together,...
unsigned short portal_count
Definition cell.h:69
jo_fixed sin
Definition cell.h:72
A cell.
Definition cell.h:56
A portal: an opening of a cell toward another cell.
Definition cell.h:77
int radius
Definition entity.h:3
jo_pos3D_fixed position
Definition entity.h:2
A loaded level.
Definition level.h:51
int jo_fixed
Fixed point Q16.16 number.
Definition types.h:59
3D position using fixed numbers
Definition types.h:103