Jo Engine 2026.11.6
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
level.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*/
38
39#ifndef __JO_LEVEL_H__
40# define __JO_LEVEL_H__
41
42#ifdef JO_COMPILE_WITH_FS_SUPPORT
43
44# include "level_format.h"
45
47# define JO_LEVEL_MAX_COPIES (16)
48
50typedef struct
51{
52 unsigned char *data; // The file
53 unsigned int size;
55 unsigned int section_count;
56 const char *strings; // STRS section (JO_NULL: none)
57 unsigned int strings_size;
59 unsigned int copy_count;
60} jo_level;
61
67jo_level *jo_level_load(const char * const filename);
68
72void jo_level_free(jo_level * const level);
73
79const jo_level_directory_entry *jo_level_find_section(const jo_level * const level, const unsigned int id);
80
86const void *jo_level_section_data(const jo_level * const level, const unsigned int id);
87
95const void *jo_level_get_header(jo_level * const level, const unsigned int id, const unsigned int size,
96 const void * const defaults);
97
106const void *jo_level_get_records(jo_level * const level, const unsigned int id, const unsigned int size,
107 const void * const defaults, unsigned int * const count);
108
115const void *jo_level_get_array(const jo_level * const level, const unsigned int id, const unsigned int offset);
116
122const char *jo_level_string(const jo_level * const level, const unsigned int offset);
123
125# define JO_LEVEL_HEADER(LEVEL, ID, NAME) ({ static const jo_level_##NAME##_header __defaults = JO_LEVEL_##ID##_HEADER_DEFAULTS; \
126 (const jo_level_##NAME##_header *)jo_level_get_header((LEVEL), JO_LEVEL_SECTION_##ID, \
127 sizeof(jo_level_##NAME##_header), &__defaults); })
128
130# define JO_LEVEL_RECORDS(LEVEL, ID, NAME, COUNT) ({ static const jo_level_##NAME##_record __defaults = JO_LEVEL_##ID##_RECORD_DEFAULTS; \
131 (const jo_level_##NAME##_record *)jo_level_get_records((LEVEL), JO_LEVEL_SECTION_##ID, \
132 sizeof(jo_level_##NAME##_record), &__defaults, (COUNT)); })
133
134/*
135** Textures of 16 colors (section TX16): 4 bits a pixel, 4 times less VRAM than RGB. A level (or a file of textures) gives
136** the palette and the pixels; the game makes its sprites when it starts and frees the file: the textures are not in the
137** program. The fields of the game (TX16.value) and the sizes: JO_LEVEL_RECORDS(level, TX16, tx16, &count)
138*/
139
145bool jo_level_set_textures16_palette(jo_level * const level, const jo_palette * const palette);
146
161bool jo_level_add_textures16(jo_level * const level, const jo_palette * const palette,
162 const int first, const int count, int * const sprite_ids);
163
164/*
165** Textures of 256 colors (section TX08): a byte a pixel, one palette of 255 colors for all of them (photographs, painted
166** textures: more colors than 16 a texture, opaque over a see-through bottom). A texture can bring its smaller copies (half
167** and quarter size, made by the tool: Compiler/COMMON/jo_level/quantize.py), used when it is drawn small (the VDP1 reads all
168** the texels of a texture). The fields of the game (TX08.value) and the sizes: JO_LEVEL_RECORDS(level, TX08, tx08, &count)
169*/
170
176bool jo_level_set_textures8_palette(jo_level * const level, const jo_palette * const palette);
177
188bool jo_level_add_textures8(jo_level * const level, const int first, const int count,
189 int * const sprite_ids);
190
191#endif /* !JO_COMPILE_WITH_FS_SUPPORT */
192
193#endif /* !__JO_LEVEL_H__ */
194
195/*
196** END OF FILE
197*/
const jo_level_directory_entry * jo_level_find_section(const jo_level *const level, const unsigned int id)
Find a section (also a section of the game: identifier with a lowercase letter).
void jo_level_free(jo_level *const level)
Free a level (the pointers given by the functions below are not valid any more).
const void * jo_level_get_array(const jo_level *const level, const unsigned int id, const unsigned int offset)
Array of a section (an offset field of its header).
const char * strings
Definition level.h:56
const void * jo_level_section_data(const jo_level *const level, const unsigned int id)
Start of a section in the file.
bool jo_level_add_textures8(jo_level *const level, const int first, const int count, int *const sprite_ids)
Make the sprites of textures of 256 colors of a level, and of their smaller copies (the sprites after...
bool jo_level_set_textures8_palette(jo_level *const level, const jo_palette *const palette)
Copy the palette of the textures of 256 colors of a level in a palette.
void * copies[(16)]
Definition level.h:58
#define JO_LEVEL_MAX_COPIES
Maximum number of normalized copies of headers and records of a level (older files,...
Definition level.h:47
const void * jo_level_get_header(jo_level *const level, const unsigned int id, const unsigned int size, const void *const defaults)
Header of a section, with the fields of this engine.
bool jo_level_set_textures16_palette(jo_level *const level, const jo_palette *const palette)
Copy the palette of the textures of 16 colors of a level in a palette.
jo_level * jo_level_load(const char *const filename)
Load a level file (in the current directory of the CD, see jo_fs_cd()).
const void * jo_level_get_records(jo_level *const level, const unsigned int id, const unsigned int size, const void *const defaults, unsigned int *const count)
Records of a section, with the fields of this engine.
unsigned int section_count
Definition level.h:55
unsigned int strings_size
Definition level.h:57
unsigned int copy_count
Definition level.h:59
bool jo_level_add_textures16(jo_level *const level, const jo_palette *const palette, const int first, const int count, int *const sprite_ids)
Make the sprites of textures of 16 colors of a level, each one with its color lookup table.
unsigned int size
Definition level.h:53
const char * jo_level_string(const jo_level *const level, const unsigned int offset)
A string of the level (field of type string).
const jo_level_directory_entry * directory
Definition level.h:54
unsigned char * data
Definition level.h:52
A loaded level.
Definition level.h:51
Directory entry (one per section, after the file header) (24 bytes).
Definition level_format.h:37
Palette contents struct.
Definition types.h:268