X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_sprit.c;h=c69f6694f90ec36ee276d71c1b85ae433db10063;hb=c97b854807379d39e5cc97c5c8c4f4390302528d;hp=c11ff63895d18dc3d741f1a59a7076aa0c4f17c0;hpb=285987ea5f697bbd8dbd273a39345f892fa0caa9;p=16.git diff --git a/src/lib/16_sprit.c b/src/lib/16_sprit.c index c11ff638..c69f6694 100755 --- a/src/lib/16_sprit.c +++ b/src/lib/16_sprit.c @@ -52,7 +52,6 @@ void init_anim(struct sprite *spri, int anim_index) spri->curr_anim_list = anim_list; } - int set_anim_by_id(struct sprite *spri, int anim_id) { int new_anim_index = 0; @@ -97,44 +96,116 @@ void print_anim_ids(struct sprite *spri) } } - -void animate_spri(struct sprite *spri, global_game_variables_t *gv) +void animate_spri(entity_t *enti, video_t *video) { - int i; - // Events go here +#define INC_PER_FRAME if(enti->q&1) enti->persist_aniframe++; if(enti->persist_aniframe>4) enti->persist_aniframe = 1; - // Draw sprite - i = get_vrl_by_id(spri->spritesheet, spri->curr_spri_id, spri->sprite_vrl_cont); - if(i < 0) - { - Quit (gv, "Error retriving required sprite"); - } - draw_vrl1_vgax_modex( spri->x,// - spri->sprite_vrl_cont->vrl_header->width-28, - spri->y,// - spri->sprite_vrl_cont->vrl_header->height*2 -(gv->video.page[0].sh/2), - spri->sprite_vrl_cont->vrl_header, spri->sprite_vrl_cont->line_offsets, - spri->sprite_vrl_cont->buffer + sizeof(struct vrl1_vgax_header), - spri->sprite_vrl_cont->data_size); + unsigned int i,o,o2; int j; + int x,y,rx,ry,w,h; + + VGA_RAM_PTR omemptr; // Depending on delay, update indices - switch(spri->delay){ +//#define FRAME1 modexDrawSpriteRegion(pip[(pip->video->p)].page, x, y, 48, player[pn].enti.dire, 24, 32, PLAYERBMPDATAPTR); +//#define FRAME2 modexDrawSpriteRegion(pip[(pip->video->p)].page, x, y, 24, player[pn].enti.dire, 24, 32, PLAYERBMPDATAPTR); stand +//#define FRAME3 modexDrawSpriteRegion(pip[(pip->video->p)].page, x, y, 0, player[pn].enti.dire, 24, 32, PLAYERBMPDATAPTR); +//#define FRAME4 modexDrawSpriteRegion(pip[(pip->video->p)].page, x, y, 24, player[pn].enti.dire, 24, 32, PLAYERBMPDATAPTR); stand + switch(enti->spri->delay) + { // Delay = 0 means that sprite should loop. Nothing to change here case 0: - break; + break; // Delay = 1 means that on next time unit sprite should be changed case 1: - spri->curr_anim_spri++; + INC_PER_FRAME + enti->spri->curr_anim_spri++; // If we hit the end of an animation sequence, restart it - if(!(spri->curr_spri_id = spri->curr_anim_list[spri->curr_anim_spri].sprite_id)){ - spri->curr_anim_spri = 0; - spri->curr_spri_id = spri->curr_anim_list[spri->curr_anim_spri].sprite_id; + if(!( enti->spri->curr_spri_id = enti->spri->curr_anim_list[enti->spri->curr_anim_spri].sprite_id)){ + enti->spri->curr_anim_spri = 0; + enti->spri->curr_spri_id = enti->spri->curr_anim_list[enti->spri->curr_anim_spri].sprite_id; } - spri->delay = spri->curr_anim_list[spri->curr_anim_spri].delay; + enti->spri->delay = enti->spri->curr_anim_list[enti->spri->curr_anim_spri].delay; // Delay > 1 means that we should not change sprite yet. Decrease delay default: - spri->delay--; - break; + enti->spri->delay--; + break; + } + + // Events go here + + + omemptr = (VGA_RAM_PTR)video->page[0].data;// save original mem ptr + x=enti->spri->x; + y=enti->spri->y; + + // Draw sprite + j = get_vrl_by_id(enti->spri->spritesheet, enti->spri->curr_spri_id, enti->spri->sprite_vrl_cont); + if(j < 0) + { + //Quit (gv, "Error retriving required sprite"); + return; + } + + // render box bounds. y does not need modification, but x and width must be multiple of 4 + if(!video->rss){ + if (x >= enti->overdraww) rx = (x - enti->overdraww) & (~3); + else rx = -(video->page[0].dx); + if (y >= enti->overdrawh) ry = (y - enti->overdrawh); + else ry = -(video->page[0].dy); + h = enti->spri->sprite_vrl_cont->vrl_header->height + enti->overdrawh + y - ry; + w = (x + enti->spri->sprite_vrl_cont->vrl_header->width + (enti->overdraww*2) + 3 - rx) & (~3) - enti->overdraww;//round up + if ((rx+w) > video->page[0].width) w = video->page[0].width-rx; + if ((ry+h) > video->page[0].height) h = video->page[0].height-ry; + + // block copy pattern to where we will draw the sprite + vga_setup_wm1_block_copy(); + o2 = VMEMPAGESIZE2; + o = ((uint16_t)VMEMPAGEDATA2) + (ry * video->page[0].stridew) + (rx >> 2); // source offscreen 0x10000UL - + for (i=0;i < h;i++,o += video->page[0].stridew,o2 += (w >> 2)) vga_wm1_mem_block_copy(o2,o,w >> 2); + + // must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally + vga_restore_rm0wm0(); + + // replace VGA stride with our own and mem ptr. then sprite rendering at this stage is just (0,0) + vga_state.vga_draw_stride = w >> 2; + vga_state.vga_graphics_ram = omemptr + VMEMPAGESIZE2; + }else{ rx=ry=w=h=0; vga_state.vga_graphics_ram = (VGA_RAM_PTR)video->page[0].data; } + vga_state.vga_draw_stride_limit = (video->page[0].width + 3 - x) >> 2;//round up + + // then the sprite. note modding ram ptr means we just draw to (x&3,0) +#ifndef SPRITE + modexClearRegion(&video->page[0], x, y, 16, 32, 1); +#else + draw_vrl1_vgax_modex( + x-rx, + y-ry, + enti->spri->sprite_vrl_cont->vrl_header, + enti->spri->sprite_vrl_cont->line_offsets, + enti->spri->sprite_vrl_cont->buffer + sizeof(struct vrl1_vgax_header), + enti->spri->sprite_vrl_cont->data_size + ); +#endif + if(!video->rss){ + // restore ptr + vga_state.vga_graphics_ram = omemptr; + + // block copy to visible RAM from offscreen + vga_setup_wm1_block_copy(); + o = VMEMPAGESIZE2; // source offscreen + o2 = (ry * video->page[0].stridew) + (rx >> 2); // dest visible (original stride) + for (i=0;i < h;i++,o += vga_state.vga_draw_stride,o2 += video->page[0].stridew) vga_wm1_mem_block_copy(o2,o,w >> 2); + // must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally + vga_restore_rm0wm0(); } + // restore stride + vga_state.vga_draw_stride_limit = vga_state.vga_draw_stride = video->page[0].stridew; + + vga_state.vga_graphics_ram = video->omemptr; } + + + +