coastline 0.0.4
Loading...
Searching...
No Matches
vehiclecolor.h
Go to the documentation of this file.
1#ifndef COASTLINE_VEHICLECOLOR_H
2#define COASTLINE_VEHICLECOLOR_H
3
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#if TGR_BOSS_RALLY
14void RefreshVehicleMaterialTextures(VehicleModel *model);
15
21static inline void SetVehicleLightPalette(u16 *palette, s32 variant, s32 dark) {
22 if (variant == 0) {
23 palette[15] = dark ? 0x0070 : 0x0190;
24 palette[10] = dark ? 0x8290 : 0x01a0;
25 palette[12] = 0x8179;
26 palette[7] = 0x4192;
27 }
28 palette[11] = variant < 2 ? 0x6bad : 0x38e7;
29 palette[6] = variant < 2 ? 0x31c6 : 0xfeff;
30 palette[14] = variant & 1 ? 0x00c0 : 0x0190;
31 palette[13] = variant & 1 ? 0x00c0 : palette[15];
32 palette[9] = variant & 1 ? 0x04f9 : 0x01a0;
33 palette[8] = variant & 1 ? 0x04f9 : palette[10];
34}
35#endif /* TGR_BOSS_RALLY */
36
38static inline u16 PackMaterialPaletteColor(u16 color) {
39#if TGR_BOSS_RALLY
40 return (color >> 8) | (color << 8);
41#else
42 return color;
43#endif
44}
45
47static inline s32 GetMaterialTextureFormat(const ModelTexture *texture) {
48#if TGR_BOSS_RALLY
49 return (texture->textureFlags >> 24) & 0xf;
50#else
51 return texture->format;
52#endif
53}
54
56static inline void SetMaterialPaletteColors(VehicleModel *model, s32 red, s32 green, s32 blue) {
57 ModelTexture *texture;
58 u16 *palette;
59 s32 i;
60
61 for (i = 0; i < VEHICLE_MATERIALS; i++) {
62 texture = &model->textures[model->materialTextures[i]];
63 palette = texture->palette;
64 if (palette != NULL && GetMaterialTextureFormat(texture) == TEXTURE_FORMAT_CI4) {
65 /* Each store preserves bit 0 from the material's indexed entry in native byte order. */
66 palette[0] = PackMaterialPaletteColor(
67 (u16)((palette[i] & 1) | (red << 11) | (green << 6) | (blue << 1)));
68 /* The second entry is a darker shade. */
69 palette[1] = PackMaterialPaletteColor((u16)((palette[i] & 1) | ((red & 0x1E) << 10) |
70 ((green & 0x1E) << 5) | (blue & 0x1E)));
71 }
72 }
73}
74
75#ifdef __cplusplus
76}
77#endif
78
79#endif /* COASTLINE_VEHICLECOLOR_H */
#define TEXTURE_FORMAT_CI4
Definition render.h:121
A texture of a model and its palette.
Definition render.h:63
unsigned format
Definition render.h:93
u16 * palette
Definition render.h:72
The model of a car as it is loaded from the cartridge.
Definition vehiclemodel.h:55
u8 materialTextures[VEHICLE_MATERIALS]
Definition vehiclemodel.h:129
ModelTexture * textures
Definition vehiclemodel.h:104
#define NULL
Definition ultratypes.h:49
unsigned short u16
Definition ultratypes.h:19
int s32
Definition ultratypes.h:25
static s32 GetMaterialTextureFormat(const ModelTexture *texture)
Definition vehiclecolor.h:47
static u16 PackMaterialPaletteColor(u16 color)
Definition vehiclecolor.h:38
static void SetMaterialPaletteColors(VehicleModel *model, s32 red, s32 green, s32 blue)
Set the material palettes of model to the requested red, green, and blue colour.
Definition vehiclecolor.h:56
#define VEHICLE_MATERIALS
Definition vehiclemodel.h:36