mirror of
https://github.com/libretro/retroluxury.git
synced 2024-11-23 07:39:47 +00:00
added git commit hash version; added wip map support
This commit is contained in:
parent
6843dbf09a
commit
41d64ef562
17
src/Makefile
Normal file
17
src/Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
INCLUDES=-I.
|
||||
DEFINES=-DGITHASH=\"`git rev-parse HEAD`\"
|
||||
|
||||
CFLAGS=-O3 --std=c99 $(INCLUDES) $(DEFINES)
|
||||
|
||||
OBJS=rl_backgrnd.o rl_image.o rl_map.o rl_sound.o rl_sprite.o rl_tile.o rl_version.o
|
||||
|
||||
%.o: %.c
|
||||
gcc $(CFLAGS) -c $< -o $@
|
||||
|
||||
all: libretroluxury.a
|
||||
|
||||
libretroluxury.a: $(OBJS)
|
||||
ar rcs $@ $+
|
||||
|
||||
clean:
|
||||
rm -f libretroluxury.a $(OBJS)
|
108
src/rl_map.c
Normal file
108
src/rl_map.c
Normal file
@ -0,0 +1,108 @@
|
||||
#include <rl_map.h>
|
||||
#include <rl_memory.h>
|
||||
#include <rl_backgrnd.h>
|
||||
|
||||
#include <rl_endian.c>
|
||||
|
||||
static rl_map_t* destroy( rl_map_t* map )
|
||||
{
|
||||
if ( map )
|
||||
{
|
||||
if ( map->tileset )
|
||||
{
|
||||
rl_tileset_destroy( map->tileset );
|
||||
}
|
||||
|
||||
if ( map->layer0 )
|
||||
{
|
||||
rl_free( map->layer0 );
|
||||
}
|
||||
|
||||
rl_free( map );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rl_map_t* rl_map_create( const void* data, size_t size )
|
||||
{
|
||||
union
|
||||
{
|
||||
const void* restrict v;
|
||||
const uint8_t* restrict u8;
|
||||
const uint16_t* restrict u16;
|
||||
const uint32_t* restrict u32;
|
||||
}
|
||||
ptr;
|
||||
|
||||
ptr.v = data;
|
||||
|
||||
int width = ne16( *ptr.u16++ );
|
||||
int height = ne16( *ptr.u16++ );
|
||||
int num_layers = ne16( *ptr.u16++ );
|
||||
ptr.u16++; /* padding */
|
||||
|
||||
rl_map_t* map = (rl_map_t*)rl_malloc( sizeof( rl_map_t ) );
|
||||
|
||||
if ( map )
|
||||
{
|
||||
map->width = width;
|
||||
map->height = height;
|
||||
map->num_layers = num_layers;
|
||||
|
||||
size_t tileset_size = ne32( *ptr.u32++ );
|
||||
map->tileset = rl_tileset_create( ptr.v, tileset_size );
|
||||
|
||||
if ( map->tileset )
|
||||
{
|
||||
ptr.u8 += tileset_size;
|
||||
map->layer0 = (rl_layer0_t*)rl_malloc( width * height * sizeof( uint16_t ) );
|
||||
|
||||
if ( map->layer0 )
|
||||
{
|
||||
uint16_t* restrict ndx = map->layer0->indices;
|
||||
const uint16_t* restrict end = ndx + width * height;
|
||||
|
||||
while ( ndx < end )
|
||||
{
|
||||
*ndx++ = ne16( *ptr.u16++ );
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return destroy( map );
|
||||
}
|
||||
|
||||
void rl_map_destroy( rl_map_t* map )
|
||||
{
|
||||
destroy( map );
|
||||
}
|
||||
|
||||
void rl_map_render_layer( rl_map_t* map, int ndx, int x, int y )
|
||||
{
|
||||
int width, height;
|
||||
rl_backgrnd_fb( &width, &height );
|
||||
|
||||
if ( ndx == 0 )
|
||||
{
|
||||
int wt = ( width + map->tileset->width - 1 ) / map->tileset->width + 1;
|
||||
int ht = ( width + map->tileset->height - 1 ) / map->tileset->height;
|
||||
|
||||
int dx = -( x % map->tileset->width );
|
||||
int dy = -( y % map->tileset->height );
|
||||
|
||||
x /= map->tileset->width;
|
||||
y /= map->tileset->height;
|
||||
|
||||
for ( int yy = 0; yy < ht; yy++ )
|
||||
{
|
||||
for ( int xx = 0; xx < wt; xx++ )
|
||||
{
|
||||
rl_tileset_blit_nobg( map->tileset, map->layer0->indices[ ( y + yy ) * map->width + ( x + xx ) ], dx + xx * map->tileset->width, dy + yy * map->tileset->height );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
src/rl_map.h
Normal file
36
src/rl_map.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef RL_MAP_H
|
||||
#define RL_MAP_H
|
||||
|
||||
#include <rl_userdata.h>
|
||||
#include <rl_tile.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t indices[ 0 ]; /* width * height *tile* indices */
|
||||
}
|
||||
rl_layer0_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
rl_userdata_t ud;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
int num_layers;
|
||||
|
||||
rl_tileset_t* tileset;
|
||||
rl_layer0_t* layer0;
|
||||
|
||||
//rl_layern_t* layers[ 0 ];
|
||||
}
|
||||
rl_map_t;
|
||||
|
||||
rl_map_t* rl_map_create( const void* data, size_t size );
|
||||
void rl_map_destroy( rl_map_t* map );
|
||||
|
||||
void rl_map_render_layer( rl_map_t* map, int ndx, int x, int y );
|
||||
|
||||
#endif /* RL_MAP_H */
|
@ -23,7 +23,7 @@ rl_tileset_t* rl_tileset_create( const void* data, size_t size )
|
||||
|
||||
size -= 3 * sizeof( uint16_t );
|
||||
|
||||
rl_tileset_t* tileset = (rl_tileset_t*)rl_malloc( size );
|
||||
rl_tileset_t* tileset = (rl_tileset_t*)rl_malloc( sizeof( rl_tileset_t ) + size );
|
||||
|
||||
if ( tileset )
|
||||
{
|
||||
@ -32,9 +32,9 @@ rl_tileset_t* rl_tileset_create( const void* data, size_t size )
|
||||
tileset->size = width * height;
|
||||
tileset->num_tiles = num_tiles;
|
||||
|
||||
uint16_t* restrict pixel = (uint16_t*)( (uint8_t*)tileset + sizeof( *tileset ) );
|
||||
uint16_t* restrict pixel = (uint16_t*)( (uint8_t*)tileset + sizeof( rl_tileset_t ) );
|
||||
|
||||
const uint16_t* restrict end = pixel + size;
|
||||
const uint16_t* restrict end = pixel + size / 2;
|
||||
|
||||
while ( pixel < end )
|
||||
{
|
||||
|
13
src/rl_version.c
Normal file
13
src/rl_version.c
Normal file
@ -0,0 +1,13 @@
|
||||
const char* rl_gitstamp =
|
||||
"+------------------------------------------+\n"
|
||||
"| RETROLUXURY |\n"
|
||||
"| ____ _ _ ___ _ ____ |\n"
|
||||
"| | __ ) | | | | |_ _| | | | _ \\ |\n"
|
||||
"| | _ \\ | | | | | | | | | | | | |\n"
|
||||
"| | |_) | | |_| | | | | |__ | |_| | |\n"
|
||||
"| |____/ \\___/ |___| |____| |____/ |\n"
|
||||
"| |\n"
|
||||
"| " GITHASH " |\n"
|
||||
"+------------------------------------------+\n";
|
||||
|
||||
const char* rl_githash = GITHASH;
|
7
src/rl_version.h
Normal file
7
src/rl_version.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef RL_VERSION_H
|
||||
#define RL_VERSION_H
|
||||
|
||||
extern const char* rl_gitstamp;
|
||||
extern const char* rl_githash;
|
||||
|
||||
#endif /* RL_VERSION_H */
|
Loading…
Reference in New Issue
Block a user