Commit 97762aee authored by Libretro-Admin's avatar Libretro-Admin
Browse files

Cleanups

parent 5adbbc5a
......@@ -69,8 +69,7 @@ else ifeq ($(platform), psp1)
AR = psp-ar$(EXE_EXT)
PLATFORM_DEFINES := -DPSP -G0
STATIC_LINKING = 1
else
CC = gcc
else CC = gcc
TARGET := $(TARGET_NAME)_libretro.dll
SHARED := -shared -static-libgcc -static-libstdc++ -Wl,--no-undefined -s
endif
......@@ -92,12 +91,6 @@ CFLAGS +=
LFLAGS :=
LDFLAGS += $(LIBM)
ifeq ($(platform), qnx)
CFLAGS += -Wc,-std=gnu99
else
CFLAGS += -std=gnu99
endif
ifeq ($(platform), osx)
ifndef ($(NOUNIVERSAL))
CFLAGS += $(ARCHFLAGS)
......
......@@ -97,4 +97,4 @@ void render_title(void);
void render_win_or_game_over(void);
void render_paused(void);
#endif // GAME_H
#endif /* GAME_H */
......@@ -22,7 +22,7 @@ static const char* label_lut[13] =
"XXX"
};
// LAME DRAW TEXT and FILLRECT
/* LAME DRAW TEXT and FILLRECT */
static unsigned *frame_buf;
......@@ -75,7 +75,7 @@ void DrawFBoxBmp(char *buffer,int x,int y,int dx,int dy,unsigned color)
void Draw_string(char *surf, signed short int x, signed short int y, const unsigned char *string,unsigned short maxstrlen,unsigned short xscale, unsigned short yscale, unsigned fg, unsigned bg)
{
int strlen;
int strlen, surfw, surfh;
unsigned char *linesurf;
signed int ypixel;
unsigned *yptr;
......@@ -95,8 +95,8 @@ void Draw_string(char *surf, signed short int x, signed short int y, const unsig
for(strlen = 0; strlen<maxstrlen && string[strlen]; strlen++)
{}
int surfw=strlen * 7 * xscale;
int surfh=8 * yscale;
surfw=strlen * 7 * xscale;
surfh=8 * yscale;
#if defined PITCH && PITCH == 4
......@@ -192,6 +192,8 @@ static void draw_tile(int ctx, cell_t *cell)
int font_size = FONT_SIZE;
float *frame_time = game_get_frame_time();
(void)font_size;
if (cell->value && cell->move_time < 1)
{
int x1, y1, x2, y2;
......@@ -213,9 +215,11 @@ static void draw_tile(int ctx, cell_t *cell)
w = h = bump_out(0, TILE_SIZE, cell->appear_time);
font_size = bump_out(0, FONT_SIZE, cell->appear_time);
// w = lerp(0, TILE_SIZE, cell->appear_time);
// h = lerp(0, TILE_SIZE, cell->appear_time);
// font_size = lerp(0, FONT_SIZE, cell->appear_time);
#if 0
w = lerp(0, TILE_SIZE, cell->appear_time);
h = lerp(0, TILE_SIZE, cell->appear_time);
font_size = lerp(0, FONT_SIZE, cell->appear_time);
#endif
x += TILE_SIZE/2 - w/2;
y += TILE_SIZE/2 - h/2;
......@@ -234,11 +238,11 @@ static void draw_tile(int ctx, cell_t *cell)
if (cell->value)
{
if (cell->value < 6) // one or two digits
if (cell->value < 6) /* one or two digits */
nullctx_fontsize(3);
else if (cell->value < 10) // three digits
else if (cell->value < 10) /* three digits */
nullctx_fontsize(2);
else // four digits
else /* four digits */
nullctx_fontsize(1);
set_rgb(ctx, 119, 110, 101);
......@@ -253,22 +257,22 @@ void game_calculate_pitch(void)
static void init_luts(void)
{
color_lut[0] = RGB32(238,228,218,90);//cairo_pattern_create_rgba(238 / 255.0, 228 / 255.0, 218 / 255.0, 0.35);
color_lut[1] = RGB32(238,228,218,255);//cairo_pattern_create_rgb(238 / 255.0, 228 / 255.0, 218 / 255.0);
color_lut[2] = RGB32(237,224,200,255);//cairo_pattern_create_rgb(237 / 255.0, 224 / 255.0, 200 / 255.0);
color_lut[3] = RGB32(242,177,121,255);//cairo_pattern_create_rgb(242 / 255.0, 177 / 255.0, 121 / 255.0);
color_lut[4] = RGB32(245,149,99,255);//cairo_pattern_create_rgb(245 / 255.0, 149 / 255.0, 99 / 255.0);
color_lut[5] = RGB32(246,124,95,255);//cairo_pattern_create_rgb(246 / 255.0, 124 / 255.0, 95 / 255.0);
color_lut[6] = RGB32(246,94,59,255);//cairo_pattern_create_rgb(246 / 255.0, 94 / 255.0, 59 / 255.0);
// TODO: shadow
color_lut[7] = RGB32(237,207,114,255);//cairo_pattern_create_rgb(237 / 255.0, 207 / 255.0, 114 / 255.0);
color_lut[8] = RGB32(237,204,97,255);//cairo_pattern_create_rgb(237 / 255.0, 204 / 255.0, 97 / 255.0);
color_lut[9] = RGB32(237,200,80,255);//cairo_pattern_create_rgb(237 / 255.0, 200 / 255.0, 80 / 255.0);
color_lut[10] = RGB32(237,197,63,255);//cairo_pattern_create_rgb(237 / 255.0, 197 / 255.0, 63 / 255.0);
color_lut[11] = RGB32(237,194,46,255);//cairo_pattern_create_rgb(237 / 255.0, 194 / 255.0, 46 / 255.0);
color_lut[12] = RGB32(60,58,50,255);//cairo_pattern_create_rgb(60 / 255.0, 58 / 255.0, 50 / 255.0);
color_lut[0] = RGB32(238,228,218,90);
color_lut[1] = RGB32(238,228,218,255);
color_lut[2] = RGB32(237,224,200,255);
color_lut[3] = RGB32(242,177,121,255);
color_lut[4] = RGB32(245,149,99,255);
color_lut[5] = RGB32(246,124,95,255);
color_lut[6] = RGB32(246,94,59,255);
/* TODO: shadow */
color_lut[7] = RGB32(237,207,114,255);
color_lut[8] = RGB32(237,204,97,255);
color_lut[9] = RGB32(237,200,80,255);
color_lut[10] = RGB32(237,197,63,255);
color_lut[11] = RGB32(237,194,46,255);
color_lut[12] = RGB32(60,58,50,255);
}
static void init_static_surface(void)
......@@ -278,36 +282,36 @@ static void init_static_surface(void)
cell_t dummy;
static_ctx = 0;
// bg
/* bg */
set_rgb(static_ctx, 250, 248, 239);
fill_rectangle(static_ctx, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
// grid bg
/* grid bg */
set_rgb(static_ctx, 185, 172, 159);
fill_rectangle(static_ctx, SPACING, BOARD_OFFSET_Y, BOARD_WIDTH, BOARD_WIDTH);
// score bg
/* score bg */
set_rgb(static_ctx, 185, 172, 159);
fill_rectangle(static_ctx, SPACING, SPACING, TILE_SIZE*2+SPACING*2, TILE_SIZE);
// best bg
/* best bg */
set_rgb(static_ctx, 185, 172, 159);
fill_rectangle(static_ctx, TILE_SIZE*2+SPACING*4, SPACING, TILE_SIZE*2+SPACING*2, TILE_SIZE);
nullctx.color=color_lut[1];
nullctx_fontsize(1) ;
// score title
/* score title */
draw_text_centered(static_ctx, "SCORE", SPACING*2, SPACING * 2, 0, 0);
// best title
/* best title */
draw_text_centered(static_ctx, "BEST", TILE_SIZE*2+SPACING*5, SPACING*2, 0, 0);
// draw background cells
dummy.move_time = 1;
/* draw background cells */
dummy.move_time = 1;
dummy.appear_time = 1;
dummy.source = NULL;
dummy.value = 0;
dummy.source = NULL;
dummy.value = 0;
for (row = 0; row < 4; row++)
{
......@@ -347,15 +351,15 @@ void render_playing(void)
{
int *delta_score;
float *delta_score_time;
int row, col, ctx=0;
char tmp[10] = {0};
float *frame_time = game_get_frame_time();
// paint static background
/* paint static background */
nullctx_fontsize(2) ;
int ctx=0;
// score and best score value
/* score and best score value */
set_rgb(ctx, 255, 255, 255);
sprintf(tmp, "%i", game_get_score() % 1000000);
draw_text_centered(ctx, tmp, SPACING*2, SPACING * 5, TILE_SIZE*2, 0);
......@@ -365,9 +369,9 @@ void render_playing(void)
draw_text_centered(ctx, tmp, TILE_SIZE*2+SPACING*5, SPACING * 5, TILE_SIZE*2, 0);
for (int row = 0; row < 4; row++)
for (row = 0; row < 4; row++)
{
for (int col = 0; col < 4; col++)
for (col = 0; col < 4; col++)
{
cell_t *grid = game_get_grid();
cell_t *cell = &grid[row * 4 + col];
......@@ -380,14 +384,14 @@ void render_playing(void)
delta_score_time = game_get_delta_score_time();
delta_score = game_get_delta_score();
// draw +score animation
/* draw +score animation */
if (*delta_score_time < 1)
{
int x, y;
nullctx_fontsize(1);
int x = SPACING * 2;
int y = SPACING * 5;
x = SPACING * 2;
y = SPACING * 5;
y = lerp(y, y - TILE_SIZE, *delta_score_time);
set_rgba(ctx, 119, 110, 101, lerp(1, 0, *delta_score_time));
......@@ -402,7 +406,8 @@ void render_playing(void)
void render_title(void)
{
int ctx=0;
// bg
/* bg */
set_rgb(ctx, 250, 248, 239);
fill_rectangle(ctx, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
......@@ -431,7 +436,7 @@ void render_win_or_game_over(void)
if (state == STATE_GAME_OVER)
render_playing();
// bg
/* bg */
set_rgba(ctx, 250, 248, 239, 0.85);
fill_rectangle(ctx, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
......@@ -462,7 +467,7 @@ void render_paused(void)
render_playing();
// bg
/* bg */
set_rgba(ctx, 250, 248, 239, 0.85);
fill_rectangle(ctx, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
......
......@@ -7,25 +7,28 @@
static game_t game;
// score animations
/* Score animations */
static int delta_score;
static float delta_score_time;
static float frame_time = 0.016;
#define PI 3.14159
// out back bicubic
// from http://www.timotheegroleau.com/Flash/experiments/easing_function_generator.htm
/* out back bicubic
* from http://www.timotheegroleau.com/Flash/experiments/easing_function_generator.htm
*/
float bump_out(float v0, float v1, float t)
{
t /= 1;// intensity (d)
float ts, tc;
float ts = t * t;
float tc = ts * t;
t /= 1; /* intensity (d) */
ts = t * t;
tc = ts * t;
return v0 + v1 * (4*tc + -9*ts + 6*t);
}
// interpolation functions
/* interpolation functions */
float lerp(float v0, float v1, float t)
{
return v0 * (1 - t) + v1 * t;
......@@ -48,7 +51,7 @@ void *game_save_data(void)
{
int row, col;
// stop animations
/* stop animations */
for (row = 0; row < 4; row++)
{
for (col = 0; col < 4; col++)
......@@ -60,7 +63,7 @@ void *game_save_data(void)
delta_score_time = 1;
// show title screen when the game gets loaded again.
/* show title screen when the game gets loaded again. */
if (game.state != STATE_PLAYING && game.state != STATE_PAUSED)
{
game.score = 0;
......@@ -144,8 +147,8 @@ void start_game(void)
}
}
// reset +score animation
delta_score = 0;
/* reset +score animation */
delta_score = 0;
delta_score_time = 1;
add_tile();
......@@ -192,7 +195,11 @@ static bool matches_available(void)
static bool move_tiles(void)
{
int row, col;
int vec_x, vec_y;
int col_begin, col_end, col_inc;
int row_begin, row_end, row_inc;
bool moved = false;
switch (game.direction)
{
......@@ -213,12 +220,12 @@ static bool move_tiles(void)
break;
}
int col_begin = 0;
int col_end = 4;
int col_inc = 1;
int row_begin = 0;
int row_end = 4;
int row_inc = 1;
col_begin = 0;
col_end = 4;
col_inc = 1;
row_begin = 0;
row_end = 4;
row_inc = 1;
if (vec_x > 0) {
col_begin = 3;
......@@ -233,14 +240,12 @@ static bool move_tiles(void)
row_inc = -1;
}
bool moved = false;
delta_score = game.score;
// clear source cell and save current position in the grid
for (int row = row_begin; row != row_end; row += row_inc)
/* clear source cell and save current position in the grid */
for (row = row_begin; row != row_end; row += row_inc)
{
for (int col = col_begin; col != col_end; col += col_inc)
for (col = col_begin; col != col_end; col += col_inc)
{
cell_t *cell = &game.grid[row * 4 + col];
cell->old_pos = cell->pos;
......@@ -250,18 +255,20 @@ static bool move_tiles(void)
}
}
for (int row = row_begin; row != row_end; row += row_inc)
for (row = row_begin; row != row_end; row += row_inc)
{
for (int col = col_begin; col != col_end; col += col_inc)
for (col = col_begin; col != col_end; col += col_inc)
{
int new_row, new_col;
cell_t *farthest, *next;
cell_t *cell = &game.grid[row * 4 + col];
if (!cell->value)
continue;
cell_t *farthest;
cell_t *next = cell;
int new_row = row , new_col = col;
next = cell;
new_row = row;
new_col = col;
do
{
......@@ -276,7 +283,7 @@ static bool move_tiles(void)
next = &game.grid[new_row * 4 + new_col];
} while (!next->value);
// only tiles that have not been merged
/* only tiles that have not been merged */
if (next->value && next->value == cell->value && next != cell && !next->source)
{
next->value = cell->value + 1;
......
......@@ -20,8 +20,10 @@ float frame_time = 0;
static void fallback_log(enum retro_log_level level, const char *fmt, ...)
{
(void)level;
va_list va;
(void)level;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
va_end(va);
......@@ -29,15 +31,17 @@ static void fallback_log(enum retro_log_level level, const char *fmt, ...)
void retro_init(void)
{
char *savedir;
game_calculate_pitch();
game_init();
char *savedir;
environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &savedir);
if (savedir)
{
FILE *fp;
#ifdef _WIN32
char slash = '\\';
#else
......@@ -46,7 +50,7 @@ void retro_init(void)
char filename[1024] = {0};
sprintf(filename, "%s%c2048.srm", savedir, slash);
FILE *fp = fopen(filename, "rb");
fp = fopen(filename, "rb");
if (fp)
{
......@@ -73,15 +77,16 @@ void retro_deinit(void)
if (savedir)
{
FILE *fp;
#ifdef _WIN32
char slash = '\\';
#else
char slash = '/';
#endif
char filename[1024] = {0};
sprintf(filename, "%s%c2048.srm", savedir, slash);
FILE *fp = fopen(filename, "wb");
sprintf(filename, "%s%c2048.srm", savedir, slash);
fp = fopen(filename, "wb");
if (fp)
{
......@@ -121,7 +126,7 @@ void retro_get_system_info(struct retro_system_info *info)
info->library_name = "2048";
info->library_version = "v1.0";
info->need_fullpath = false;
info->valid_extensions = NULL; // Anything is fine, we don't care.
info->valid_extensions = NULL; /* Anything is fine, we don't care. */
}
void retro_get_system_av_info(struct retro_system_av_info *info)
......@@ -139,9 +144,10 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
void retro_set_environment(retro_environment_t cb)
{
struct retro_log_callback logging;
bool no_rom = true;
environ_cb = cb;
bool no_rom = true;
cb(RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME, &no_rom);
if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging))
......@@ -204,6 +210,7 @@ void retro_run(void)
bool retro_load_game(const struct retro_game_info *info)
{
struct retro_frame_time_callback frame_cb;
struct retro_input_descriptor desc[] = {
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Up" },
......@@ -219,7 +226,8 @@ bool retro_load_game(const struct retro_game_info *info)
if (!game_init_pixelformat())
return false;
struct retro_frame_time_callback frame_cb = { frame_time_cb, 1000000 / 60 };
frame_cb.callback = frame_time_cb;
frame_cb.reference = 1000000 / 60;
frame_cb.callback(frame_cb.reference);
environ_cb(RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK, &frame_cb);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment