0 Members and 1 Guest are viewing this topic.
;NOTE: these are comments in the main source;setup: dx = 2*(x2 - x1) , dy= 2*(y2 - y1). Use (camera_pos) for x1y1 dir.;do:;if (acc >= dy) && (y1 <= y2):; y++; acc = acc - dy; if acc < 0:; acc = acc + dx;elseif (acc >= dx) && (y1 <= y2):; x++; acc = acc - dx; if acc < 0:; acc = acc + dy
ld (camera_pos_goto),hl scf rl L scf rl H ;shift in 1's for each to extend to new mapping ld (_end_yx),hl ex de,hl ;DE=dest ld hl,(camera_pos) ld a,(camera_subxy) rrca ;shift out x rl L ;put X into low rrca ;shift out Y rl H ;put Y into low ld (_cam_yx),hl ;CURRENT POSITION push hl push de ld h,0 ;x1 = L ld d,h ;x2 = E. High bytes zero. or a ex de,hl sbc hl,de add hl,hl ;dx=2*(x2-x1) ld a,1 jr nc,{+} call _negHL ld a,-1 ;if carry, moving in negative direction+: ld (_cam_mover+0),a ld (_cam_dx),hl pop de pop hl ld e,H ld l,D ;quick exchange instead of having to do ex de,hl. set high to low. ld H,0 ld d,H or a sbc hl,de add hl,hl ;dy=2*(y2-y1) ld a,1 jr nc,{+} call _negHL ld a,-1+: ld (_cam_mover+1),a ld (_cam_dy),hl ld hl,0 ld (_cam_acc),hl-: call _iterateBresenham call key_input_mapper._test_variable_delay ld hl,(_cam_yx) push hl xor a rr h rla rr L rla ld (camera_pos),hl ld (camera_subxy),a call showMapFrameRoutine pop hl ld de,(_end_yx) or a sbc hl,de jr nz,{-} ret
_iterateBresenham: ld hl,(_cam_acc) ld de,(_cam_dx) ;handle (acc >=dy) condition push hl or a sbc hl,de ;carry if condition doesn't hold up pop hl jr c,_iBr_skip_to_elseif push hl ld hl,(_cam_yx) ld a,(_end_yx+1) sub H ;handle (y2 >= y1). Carry if condition doesn't hold. pop hl jr c,_iBr_skip_to_elseif push hl ld hl,_cam_yx+1 ld a,(_cam_mover+1) add a,(hl) ld (hl),a ;y++ (or y-- if running negative y) pop hl ld de,(_cam_dy) or a sbc hl,de ;acc = acc-dy jr nc,_iBr_collect;if made it here, run if acc < 0 ld de,(_cam_dx) add hl,de jr _iBr_collect_iBr_skip_to_elseif: push hl ld hl,(_cam_yx) ld a,(_end_yx+0) sub L ;handle (x2 >= x1). Carry if condition doesn't hold. pop hl jr c,_iBr_collect push hl ld hl,_cam_yx+0 ld a,(_cam_mover+0) add a,(hl) ld (hl),a ;x++ (or x-- if running negative x) pop hl ld de,(_cam_dx) or a sbc hl,de ;acc = acc-dx jr nc,_iBr_collect;if made it here, run if acc < 0 ld de,(_cam_dy) add hl,de_iBr_collect: ld (_cam_acc),hl ret
-snip-
If A>=0 and X!=RThenX+E->X ;X coord, E is 1 or -1 (or possibly 0, but we don't actually need that)A-V->AEndIf A<0 and Z!=SThenZ+F->Z ;F is like EA+U->AEnd
;;Input a list as any {X1,Y1,X2,Y2}, just make sure they are in bounds as my code doesn't checkAns->L1Ans(1->XL1(2->ZL1(3->R ;x2L1(4->S ;y2R-X->U ;deltaxS-Z->V ;deltay(U>0)-(U<0->E ;sign(deltax)->xinc(V>0)-(V<0->F ;sign(deltay)->yincabs(U->A2Ans->U2abs(V->VPxl-On(X,ZRepeat getKeyprgmLINESUBPxl-On(X,ZEnd
res did_it_bresenhamming,(iy+stateflags) ld hl,(_cam_acc) bit 7,h ;sign check jr nz,_br_xfail ;skip if acc less than zero ld a,(_cam_yx+0) ;xpos ld c,a ld a,(_end_yx+0) cp c jr z,_br_xfail ;skip if x1==x2 ld a,(_cam_mover+0) add a,c ld (_cam_yx+0),a ld de,(_cam_dy) or a sbc hl,de ;acc-dy set did_it_bresenhamming,(iy+stateflags)_br_xfail: bit 7,h ;sign check jr z,_br_yfail ;skip if acc is non-negative. ld a,(_cam_yx+1) ;ypos ld c,a ld a,(_end_yx+1) cp c jr z,_br_yfail ;skip if y1==y2 ld a,(_cam_mover+1) add a,c ld (_cam_yx+1),a ld de,(_cam_dx) add hl,de ;acc+dx set did_it_bresenhamming,(iy+stateflags)_br_yfail: bit did_it_bresenhamming,(iy+stateflags) jr nz,_br_nofail ld a,h xor $80 ;flip sign bit to force next iter to do something ld h,a ld (_cam_acc),hl; call _cmp_cur_to_end_pos jr nz,_iterateBresenham ;reiterate bresenhammer._br_nofail: ld (_cam_acc),hl ret
ld b,1 ;use this to check if we bresenhammed ld hl,(_cam_acc) bit 7,h ;sign check jr nz,_br_xfail ;skip if acc less than zero ld a,(_cam_yx+0) ;xpos ld c,a ld a,(_end_yx+0) cp c jr z,_br_xfail ;skip if x1==x2 ld a,(_cam_mover+0) add a,c ld (_cam_yx+0),a ld de,(_cam_dy) ;negate this in the setup code inc b add hl,de inc b jr c,_br_yfail ;skip if acc is non-negative._br_xfail: ld a,(_cam_yx+1) ;ypos ld c,a ld a,(_end_yx+1) cp c jr z,_br_yfail ;skip if y1==y2 ld a,(_cam_mover+1) add a,c ld (_cam_yx+1),a ld de,(_cam_dx) add hl,de ;acc+dx inc b_br_yfail: ld (_cam_acc),hl dec b ret
br_setup:;;(b,c) = (y1,x1);;(d,e) = (y2,x2) ld (_cam_yx),bc ld (_end_yx),de ld hl,0 ld a,d sub b add a,a jr nc,$+5 dec h ;yinc neg ld (_cam_dy),a ld a,e sub c jr nc,$+5 dec l ;xinc neg ld (_cam_mover),hl ld h,0 ld l,a ld (_cam_acc),hl add a,a ld (_cam_dx),a retbr_iter:;;return nc if br is finished;;x1y1=x2y2 66;;x1+ 211 or 220, save 24~33cc;;y1+ 206 or 207, save 22~23cc;;x1+, y1+ 265 or 266, save 83~84cc ld hl,(_cam_end) ld de,(_cam_yx) or a sbc hl,de ret z ld hl,(_cam_acc) ld bc,(_cam_mover) bit 7,h ;sign check jr nz,_br_doy ld a,c add a,e ld e,a ld a,(_cam_dx) ld c,a ld a,l sub c ld l,a jr nc,_br_done dec h jp p,_br_done_br_doy: ld a,b add a,d ld d,a ld a,(_cam_dy) add a,l ld l,a jr nc,$+3 inc h_br_done: ld (_cam_acc),hl ld (_cam_yx),de scf ret
Code: [Select] ld b,1 ;use this to check if we bresenhammed ld hl,(_cam_acc) bit 7,h ;sign check jr nz,_br_xfail ;skip if acc less than zero ld a,(_cam_yx+0) ;xpos ld c,a ld a,(_end_yx+0) cp c jr z,_br_xfail ;skip if x1==x2 ld a,(_cam_mover+0) add a,c ld (_cam_yx+0),a ld de,(_cam_dy) ;negate this in the setup code inc b add hl,de inc b jr c,_br_yfail ;skip if acc is non-negative._br_xfail: ld a,(_cam_yx+1) ;ypos ld c,a ld a,(_end_yx+1) cp c jr z,_br_yfail ;skip if y1==y2 ld a,(_cam_mover+1) add a,c ld (_cam_yx+1),a ld de,(_cam_dx) add hl,de ;acc+dx inc b_br_yfail: ld (_cam_acc),hl dec b ret
It's moving so fast the water looks gray xDAnyhow, looking awesome as usual ^^
So what was the point with trying the bresenham technique versus the original one? The original one seems to pan much more smoothly than the new one.