This is the monstrous, ugly, hacked-in behemoth I had to slap together to get two numbers just so I could point the mouse somewhere on the screen, save the current screen mouse position, and apply it to the current position in the world after the client's eye has been moved. Something that should just plain be simple as all get-out wound up eating 4 hours of my time. It's just maddening that something this basic that the engine already needs to calculate just to do view sending and rendering takes this much work to do.
You want to see it? You sure you want to see it?
client
var
view_x
view_y
view_width = 31
view_height = 17
edge_limit_x1
edge_limit_y1
edge_limit_x2
edge_limit_y2
New()
. = ..()
if(.)
__checkView()
proc
setEdgeLimit(x1,y1,x2,y2)
if(x1&&y1&&x2&&y2)
edge_limit_x1 = x1
edge_limit_y1 = y1
edge_limit_x2 = x2
edge_limit_y2 = y2
perspective |= EDGE_PERSPECTIVE
edge_limit = "[x1],[y1] to [x2],[y2]"
else
edge_limit_x1 = null
edge_limit_y1 = null
edge_limit_x2 = null
edge_limit_y2 = null
perspective &= ~EDGE_PERSPECTIVE
edge_limit = null
__checkView()
set waitfor = 0
var/opersp = perspective
var/olimit = edge_limit
var/atom/movable/oeye = virtual_eye
var/cx = null
var/cy = null
if(virtual_eye)
if(ismovable(virtual_eye))
cx = (oeye:x-1)*TILE_WIDTH + oeye:step_x + oeye:bound_x
cy = (oeye:y-1)*TILE_HEIGHT + oeye:step_y + oeye:bound_y
else
cx = (oeye:x-1)*TILE_WIDTH
cy = (oeye:y-1)*TILE_HEIGHT
var/ox = cx
var/oy = cy
var/opx = pixel_x
var/opy = pixel_y
var/oview = view
UpdateViewLoc()
sleep(TICK_LAG)
while(1)
. = 0
if(view!=oview)
oview = view
if(isnum(view))
view_width = view*2+1
view_height = view_width
else
view_width = text2num(view)
view_height = text2num(str_copy_after(view,"x"))
. = 1
if(opx!=pixel_x||opy!=pixel_y)
opx = pixel_x
opy = pixel_y
. = 1
if(perspective!=opersp)
opersp = perspective
. = 1
if(olimit!=edge_limit)
olimit = edge_limit
. = 1
if(virtual_eye!=oeye)
oeye = virtual_eye
if(oeye)
if(ismovable(oeye))
cx = (oeye:x-1)*TILE_WIDTH + oeye:step_x + oeye:bound_x
cy = (oeye:y-1)*TILE_HEIGHT + oeye:step_y + oeye:bound_y
else
cx = (oeye:x-1)*TILE_WIDTH
cy = (oeye:y-1)*TILE_HEIGHT
else
cx = null
cy = null
if(ox!=cx||oy!=cy)
ox = cx
oy = cy
. = 1
if(.)
UpdateViewLoc()
sleep(TICK_LAG)
UpdateViewLoc()
var/oldx = view_x
var/oldy = view_y
if(eye:z)
var/mov = ismovable(eye)
if(view_width>=world.maxx)
view_x = ((world.maxx - view_width)*TILE_WIDTH)/2 + pixel_x
else if(perspective&EDGE_PERSPECTIVE)
var/vx = floor(view_width/2)
if(eye:x<=edge_limit_x1+vx)
view_x = (edge_limit_x1-1)*TILE_WIDTH + pixel_x
else if(eye:x>=world.maxx-vx)
view_x = (edge_limit_x2-view_width+vx-1)*TILE_WIDTH + pixel_x
else
var/ox = 0
var/ow = TILE_WIDTH
if(mov)
ow = eye:bound_width
ox = eye:step_x + eye:bound_x
view_x = (eye:x - 1)*TILE_WIDTH - (view_width*TILE_WIDTH-ow)/2 + pixel_x + ox + 1
else
var/ox = 0
var/ow = TILE_WIDTH
if(mov)
ow = eye:bound_width
ox = eye:step_x + eye:bound_x
view_x = (eye:x - 1)*TILE_WIDTH - (view_width*TILE_WIDTH-ow)/2 + pixel_x + ox + 1
if(view_height>=world.maxy)
view_y = ((world.maxy - view_height)*TILE_HEIGHT)/2 + pixel_y
else if(perspective&EDGE_PERSPECTIVE)
var/vy = floor(view_height/2)
if(eye:y<=edge_limit_y1+vy)
view_y = (edge_limit_y1-1)*TILE_HEIGHT + pixel_y
else if(eye:y>=world.maxy-vy)
view_y = (edge_limit_y2-view_height+vy-1)*TILE_HEIGHT + pixel_y
else
var/oy = 0
var/oh = TILE_HEIGHT
if(mov)
oh = eye:bound_height
oy = eye:step_y + eye:bound_y
view_y = (eye:y - 1)*TILE_HEIGHT - (view_height*TILE_HEIGHT-oh)/2 + pixel_y + oy + 1
else
var/oy = 0
var/oh = TILE_HEIGHT
if(mov)
oh = eye:bound_height
oy = eye:step_y + eye:bound_y
view_y = (eye:y - 1)*TILE_HEIGHT - (view_height*TILE_HEIGHT-oh)/2 + pixel_y + oy + 1
else
view_x = null
view_y = null
if(oldx!=view_x||oldy!=view_y)
ViewMoved(oldx,oldy)
ViewMoved(OldX,OldY)
Lummox Pls.
It doesn't have to be this waaay.