Clean a bit

This commit is contained in:
Miloslav Ciz 2024-09-29 21:41:06 +02:00
parent beda272f18
commit 3310008a0d
2 changed files with 57 additions and 118 deletions

View file

@ -16,8 +16,6 @@
#include <stdint.h>
#include "map.h"
// TODO: images should be 64x64 indexed, sky will be composed of 2x2 normal images
static const uint8_t map1[] =
{
LCR_MAP_MAGIC_NUMBER,
@ -48,10 +46,13 @@ LCR_MAP_BLOCK(LCR_BLOCK_START,32,1,32,0,LCR_BLOCK_TRANSFORM_ROT_180),
#define LCR_IMAGE_SIZE 64 ///< one-dimension resolution of bitmap image
#define LCR_IMAGE_STORE_SIZE (LCR_IMAGE_SIZE * LCR_IMAGE_SIZE + 256 * 2)
// TODO: put this into struct
uint16_t _LCR_currentImagePalette[256];
const uint8_t *_LCR_currentImagePixel;
const uint8_t *_LCR_currentImage;
struct
{
uint16_t palette[256];
const uint8_t *pixel;
const uint8_t *image;
} LCR_currentImage;
#define LCR_IMAGE_WALL_CONCRETE 0
#define LCR_IMAGE_WALL_WOOD 1
@ -6138,17 +6139,17 @@ static const uint8_t LCR_images[] =
void LCR_loadImage(unsigned int index)
{
_LCR_currentImage = LCR_images + index * LCR_IMAGE_STORE_SIZE;
LCR_currentImage.image = LCR_images + index * LCR_IMAGE_STORE_SIZE;
for (int i = 0; i < 256; ++i)
{
_LCR_currentImagePalette[i] = *_LCR_currentImage;
_LCR_currentImage++;
_LCR_currentImagePalette[i] |= ((uint16_t) (*_LCR_currentImage)) << 8;
_LCR_currentImage++;
LCR_currentImage.palette[i] = *LCR_currentImage.image;
LCR_currentImage.image++;
LCR_currentImage.palette[i] |= ((uint16_t) (*LCR_currentImage.image)) << 8;
LCR_currentImage.image++;
}
_LCR_currentImagePixel = _LCR_currentImage;
LCR_currentImage.pixel = LCR_currentImage.image;
}
/**
@ -6159,11 +6160,11 @@ void LCR_imageChangeBrightness(int up)
{
if (up)
for (int i = 0; i < 256; ++i)
_LCR_currentImagePalette[i] |= 0x18e3;
LCR_currentImage.palette[i] |= 0x18e3;
else
for (int i = 0; i < 256; ++i)
_LCR_currentImagePalette[i] =
((_LCR_currentImagePalette[i] >> 1) & 0x7bef);
LCR_currentImage.palette[i] =
((LCR_currentImage.palette[i] >> 1) & 0x7bef);
}
/**
@ -6175,7 +6176,7 @@ uint16_t LCR_sampleImage(int x, int y)
// TODO: bottleneck, later on optimize here
x = (y % LCR_IMAGE_SIZE) * LCR_IMAGE_SIZE + (x % LCR_IMAGE_SIZE);
x += (x < 0) * (LCR_IMAGE_SIZE * LCR_IMAGE_SIZE);
return _LCR_currentImagePalette[_LCR_currentImage[x]];
return LCR_currentImage.palette[LCR_currentImage.image[x]];
}
/**
@ -6184,8 +6185,8 @@ uint16_t LCR_sampleImage(int x, int y)
*/
uint16_t LCR_getNextImagePixel(void)
{
uint16_t r = _LCR_currentImagePalette[*_LCR_currentImagePixel];
_LCR_currentImagePixel++;
uint16_t r = LCR_currentImage.palette[*LCR_currentImage.pixel];
LCR_currentImage.pixel++;
return r;
}