diff --git a/programs/games/marblematch3/game/rsgame.c b/programs/games/marblematch3/game/rsgame.c index 5a027219a4..86a8b5ebc8 100644 --- a/programs/games/marblematch3/game/rsgame.c +++ b/programs/games/marblematch3/game/rsgame.c @@ -217,6 +217,8 @@ void game_reg_init() { game.loader_counter = 0; + game.process_timer = 0; + game.need_redraw = 1; game.score = 0; @@ -381,7 +383,7 @@ void game_fall() { }; }; -int process_timer = 0; + void GameProcess() { @@ -400,13 +402,12 @@ void GameProcess() { } else if (game.status == STATUS_PLAYING) { - - process_timer++; + game.process_timer++; - if (process_timer > 3) { + if (game.process_timer > ANIMATION_PROCESS_TIMER_LIMIT) { game_check_and_explode(); game_fall(); - process_timer = 0; + game.process_timer = 0; }; int i; @@ -607,8 +608,16 @@ void GameKeyUp(int key) { }; +typedef struct { + int a; + int b; + unsigned short c; + unsigned short d; +} cc_t; + void GameMouseDown(int x, int y) { + game.need_redraw = 1; game.tx = x; @@ -657,7 +666,7 @@ void GameMouseDown(int x, int y) { } else { // success - process_timer = 0; + game.process_timer = 0; }; } diff --git a/programs/games/marblematch3/game/rsgame.h b/programs/games/marblematch3/game/rsgame.h index a6d7119347..625f4a2109 100644 --- a/programs/games/marblematch3/game/rsgame.h +++ b/programs/games/marblematch3/game/rsgame.h @@ -135,6 +135,8 @@ void soundbuf_stop(rs_soundbuf_t *snd); #define EXPLOSIONS_MAX_COUNT 16 //#define EXPLOSION_PACK(x,y,frame) ( (x) | ( (y)<<8 ) | (frame)<<16 ) +#define ANIMATION_PROCESS_TIMER_LIMIT 3 + typedef struct rs_game_t { rs_texture_t framebuffer; unsigned char *scaled_framebuffer; // 24-bit BGRBGRBGR... for direct drawing @@ -167,6 +169,8 @@ typedef struct rs_game_t { int window_scale; + int process_timer; + int tx; int ty; int tz; diff --git a/programs/games/marblematch3/game/rsgamedraw.c b/programs/games/marblematch3/game/rsgamedraw.c index 4a62a0114d..50a1485f05 100644 --- a/programs/games/marblematch3/game/rsgamedraw.c +++ b/programs/games/marblematch3/game/rsgamedraw.c @@ -17,7 +17,10 @@ void game_draw() { int w = GAME_WIDTH; int h = GAME_HEIGHT; + int continue_need_redraw = 0; + if (game.need_redraw) { +// if (1) { @@ -59,20 +62,25 @@ void game_draw() { texture_draw(&game.framebuffer, &game.tex_bg_gameplay, 0, 0, DRAW_MODE_REPLACE); - int i, j; + int i, j, y_shift; for (i = 0; i < FIELD_HEIGHT; i++) { for (j = 0; j < FIELD_WIDTH; j++) { if ( IS_BIT_SET( game.field[i*FIELD_WIDTH + j], CRYSTAL_VISIBLE_BIT )) { - texture_draw( &game.framebuffer, &game.tex_crystals[ game.field[i*FIELD_WIDTH + j] & CRYSTAL_INDEX_MASK ], FIELD_X0+ j*CRYSTAL_SIZE, FIELD_Y0+ i*CRYSTAL_SIZE, DRAW_MODE_ALPHA ); - if (game.selected) { - if ( (j == game.selected_x) && (i == game.selected_y) ) { - texture_draw( &game.framebuffer, &game.tex_cursor, FIELD_X0+ j*CRYSTAL_SIZE, FIELD_Y0+ i*CRYSTAL_SIZE, DRAW_MODE_ALPHA ); - }; + y_shift = 0; + if ( IS_BIT_SET( game.field[i*FIELD_WIDTH + j], CRYSTAL_MOVING_BIT ) ) { + y_shift = -CRYSTAL_SIZE + CRYSTAL_SIZE*(game.process_timer+1)/(ANIMATION_PROCESS_TIMER_LIMIT+1); + continue_need_redraw = 1; }; + texture_draw( &game.framebuffer, &game.tex_crystals[ game.field[i*FIELD_WIDTH + j] & CRYSTAL_INDEX_MASK ], FIELD_X0+ j*CRYSTAL_SIZE, y_shift + FIELD_Y0+ i*CRYSTAL_SIZE, DRAW_MODE_ALPHA ); }; }; }; + if (game.selected) { + texture_draw( &game.framebuffer, &game.tex_cursor, FIELD_X0+ game.selected_x*CRYSTAL_SIZE, FIELD_Y0+ game.selected_y*CRYSTAL_SIZE, DRAW_MODE_ALPHA ); + }; + + for (i = 0; i < game.explosions_count; i++) { texture_draw( &game.framebuffer, &(game.tex_explosion[ (game.explosions[i]>>16) & 0xFF ]), FIELD_X0 + CRYSTAL_SIZE*( game.explosions[i] & 0xFF) - (EXPLOSION_SIZE-CRYSTAL_SIZE)/2 , @@ -99,10 +107,13 @@ void game_draw() { }; - rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, game.scaled_framebuffer); +// rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, NULL, RSKOS_BGRA); + rskos_draw_area(0, 0, w, h, game.window_scale, game.framebuffer.data, game.scaled_framebuffer, 0); }; - game.need_redraw = 0; + if (!continue_need_redraw) { + game.need_redraw = 0; + }; }; @@ -194,47 +205,51 @@ void game_textures_init_stage1() { float cr_b[CRYSTALS_COUNT] = { 0.0, 0.1, 1.0, 1.0, 0.0, 0.9, 0.9 }; +// rs_gen_init(5, CRYSTAL_SIZE); +// for (i = 0; i < CRYSTALS_COUNT; i++) { +// texture_init(&(game.tex_crystals[i]), CRYSTAL_SIZE, CRYSTAL_SIZE); +// +// rs_gen_func_set(0, 0.0); +// rs_gen_func_radial(0, 0.5, 0.5, 0.5, 0.75, 10.0); +// +// rs_gen_func_set(1, 0.0); +// rs_gen_func_cell(1, 110+100*i, 7+i, NULL, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0); +// rs_gen_func_normalize(1, 0.0, 1.0); +// +// rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0); +// rs_gen_tex_out_rgba(1, 1, 1, 0, cr_b[i], cr_g[i], cr_r[i], 1.0); +// +// memcpy(game.tex_crystals[i].data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 ); +// }; +// rs_gen_term(); + rs_gen_init(5, CRYSTAL_SIZE); for (i = 0; i < CRYSTALS_COUNT; i++) { - texture_init(&(game.tex_crystals[i]), CRYSTAL_SIZE, CRYSTAL_SIZE); rs_gen_func_set(0, 0.0); rs_gen_func_radial(0, 0.5, 0.5, 0.5, 0.75, 10.0); - -// rs_gen_func_perlin(2, 33, 4, 0.5, 350+i); -// rs_gen_func_normalize(2, 0.0, 1.0); -// rs_gen_func_posterize(2, 4); -// -// rs_gen_func_cell(1, 410+i, 50, NULL, -2.0, 1.0, 1.0, 1.0, 0.0, 1.0); -// rs_gen_func_posterize(1, 2); -// rs_gen_func_normalize(1, 0.0, 1.0); -// rs_gen_func_add(1, 1, 2, 1.0, 0.5); -// rs_gen_func_normalize(1, 0.0, 1.0); -// rs_gen_func_posterize(1, 4); -// -// rs_gen_func_add(1, 0, 1, 1.0, 1.0); -// rs_gen_func_normalize(1, 0.0, 1.0); -// rs_gen_func_mult(1, 0, 1); -// rs_gen_func_normalize(1, 0.0, 1.0); -// rs_gen_func_posterize(1, 4); - rs_gen_func_set(1, 0.0); - rs_gen_func_cell(1, 110+100*i, 7+i, NULL, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0); + rs_gen_func_set(1, 1.0); + rs_gen_func_cell(1, 310+100*i, 5, NULL, -0.5, 1.0, 1.0, 0.0, -2.0, 2.0); rs_gen_func_normalize(1, 0.0, 1.0); -// rs_gen_func_mult_add_value(1, 1, 0.9, 0.1); -// rs_gen_func_normalmap(2, 3, 3, 1, 1.0); -// rs_gen_func_mult(1, 1, 2); + rs_gen_func_normalmap(2, 3, 4, 1, 1.0); + rs_gen_func_mult_add_value(3, 3, -1.0, 1.0); - //rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0); - //rs_gen_tex_out_rgba(1, 1, 1, 1, 0.5+ 0.03*(i%2), 0.7+ 0.03*(i%3) , 0.9, 1.0); -// rs_gen_tex_out_rgba_set(0.2 + 0.2*(i/3), 0.2 + 0.1*(i%5), 0.2 + 0.1*(i%7), 0.0); -// rs_gen_tex_out_rgba(1, 1, 1, 1, 0.0, 0.0, 0.0, 1.0); + rs_gen_func_clamp(2, 0.5, 1.0); + rs_gen_func_normalize(2, 0.0, 1.0); + rs_gen_func_clamp(3, 0.5, 1.0); + rs_gen_func_normalize(3, 0.0, 1.0); + + rs_gen_func_add(4, 2, 3, 0.5, 0.5); + rs_gen_func_mult(1, 1, 4); + rs_gen_func_normalize(1, 0.0, 1.0); rs_gen_tex_out_rgba_set(0.0, 0.0, 0.0, 0.0); -// rs_gen_tex_out_rgba_set( cr_b[i], cr_g[i], cr_r[i], 0.0); rs_gen_tex_out_rgba(1, 1, 1, 0, cr_b[i], cr_g[i], cr_r[i], 1.0); +// rs_gen_tex_out_rgba(4, 4, 4, 0, 0.8-0.8*cr_b[i], 0.8-0.8*cr_g[i], 0.8-0.8*cr_r[i], 0.0); +// rs_gen_tex_out_rgba(1, 1, 1, 0, 1.0, 1.0, 1.0, 1.0); memcpy(game.tex_crystals[i].data, rs_gen_reg.tex_out, CRYSTAL_SIZE*CRYSTAL_SIZE*4 ); }; diff --git a/programs/games/marblematch3/game/rskos.c b/programs/games/marblematch3/game/rskos.c index e3c2152cf1..b9212bc07b 100644 --- a/programs/games/marblematch3/game/rskos.c +++ b/programs/games/marblematch3/game/rskos.c @@ -35,18 +35,19 @@ unsigned int rskos_get_time() { }; -void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer) { - - - int i, j; +void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer, int image_format) { - for (i = 0; i < h*k_scale; i++) { - for (j = 0; j < w*k_scale; j++) { - scaled_buffer[ (i*w*k_scale + j)*3 + 0] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 0]; - scaled_buffer[ (i*w*k_scale + j)*3 + 1] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 1]; - scaled_buffer[ (i*w*k_scale + j)*3 + 2] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 2]; - }; - }; + int bpp = image_format == RSKOS_BGR ? 3 : 4; + +// int i, j; +// +// for (i = 0; i < h*k_scale; i++) { +// for (j = 0; j < w*k_scale; j++) { +// scaled_buffer[ (i*w*k_scale + j)*3 + 0] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 0]; +// scaled_buffer[ (i*w*k_scale + j)*3 + 1] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 1]; +// scaled_buffer[ (i*w*k_scale + j)*3 + 2] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 2]; +// }; +// }; @@ -65,7 +66,8 @@ void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *dat - rs_tx_t tex = rs_tx_create_from_data(w*k_scale, h*k_scale, 3, 0, 1, scaled_buffer); + //rs_tx_t tex = rs_tx_create_from_data(w*k_scale, h*k_scale, 3, 0, 1, scaled_buffer); + rs_tx_t tex = rs_tx_create_from_data(w, h, bpp, 0, 1, data); glBindTexture(GL_TEXTURE_2D, tex); @@ -85,10 +87,6 @@ void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *dat rsDoSwapBuffers(); - - // swap buffers (??) - - }; @@ -150,22 +148,33 @@ void rskos_snd_stop(SNDBUF *hbuf) { return 1; }; - void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer) { + void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer, int image_format) { // unsigned char *scaled_buffer = malloc(w*k_scale*h*k_scale*3); - int i, j; - - for (i = 0; i < h*k_scale; i++) { - for (j = 0; j < w*k_scale; j++) { - scaled_buffer[ (i*w*k_scale + j)*3 + 0] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 0]; - scaled_buffer[ (i*w*k_scale + j)*3 + 1] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 1]; - scaled_buffer[ (i*w*k_scale + j)*3 + 2] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 2]; - }; - }; - kol_paint_image(0, 0, w*k_scale, h*k_scale, scaled_buffer); - -// free(image_data); + +// if (scaled_buffer != NULL) { + + int i, j; + + for (i = 0; i < h*k_scale; i++) { + for (j = 0; j < w*k_scale; j++) { + scaled_buffer[ (i*w*k_scale + j)*3 + 0] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 0]; + scaled_buffer[ (i*w*k_scale + j)*3 + 1] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 1]; + scaled_buffer[ (i*w*k_scale + j)*3 + 2] = data[ ( (i/k_scale)*w + (j/k_scale) )*4 + 2]; + }; + }; + + kol_paint_image(0, 0, w*k_scale, h*k_scale, scaled_buffer); +// } +// else { +// //kol_paint_image_pal(0, 0, w, h, data, &image_format) +// h/=4; +// asm volatile ("int $0x40"::"a"(65), "b"(data), "c"(w*65536+h), "d"(0*65536+0), "D"(0), "S"(24) ); +//// asm volatile ("int $0x40"::"a"(7), "c"(w*65536+h), "d"(x*65536+y), "b"(data)); +// }; +// +//// free(image_data); diff --git a/programs/games/marblematch3/game/rskos.h b/programs/games/marblematch3/game/rskos.h index b95250ab56..e0bd6c01d1 100644 --- a/programs/games/marblematch3/game/rskos.h +++ b/programs/games/marblematch3/game/rskos.h @@ -6,7 +6,10 @@ unsigned int rskos_get_time(); -void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer); +#define RSKOS_BGRA 32 +#define RSKOS_BGR 24 + +void rskos_draw_area(int x, int y, int w, int h, int k_scale, unsigned char *data, unsigned char *scaled_buffer, int image_format); void rskos_resize_window(int w, int h); void rskos_get_screen_size(unsigned int *pw, unsigned int *ph);