refactors clickcatchers/parallax/fullsceren (#15460)

* :)

* that

* move those there

* refactor that too

* wew

* stuff

* almost.

* sigh

* just need speed

* stuf

* pain

* hm

* tweaks

* that

* eh

* wack

* a

* done

* that's important

* wacky

* all that

* fixes

* typo

* that

* a

* funny

* that

* that

* woo

* help im losing my fucking mind

* okay

* fix
This commit is contained in:
silicons
2022-02-07 15:17:24 -08:00
committed by GitHub
parent e089be0de9
commit af6e43c595
84 changed files with 1323 additions and 889 deletions
+28
View File
@@ -0,0 +1,28 @@
/**
* Holds parallax information.
*/
/datum/parallax
/// List of parallax objects - these are cloned to a parallax holder using Clone on each.
var/list/atom/movable/screen/parallax_layer/objects
/// Parallax layers
var/layers = 0
/datum/parallax/New(create_objects = TRUE)
if(create_objects)
objects = CreateObjects()
layers = objects.len
/datum/parallax/Destroy()
QDEL_LIST(objects)
return ..()
/**
* Gets a new version of the objects inside - used when applying to a holder.
*/
/datum/parallax/proc/GetObjects()
. = list()
for(var/atom/movable/screen/parallax_layer/layer in objects)
. += layer.Clone()
/datum/parallax/proc/CreateObjects()
. = objects = list()
+311
View File
@@ -0,0 +1,311 @@
/**
* # Parallax holders
*
* Holds all the information about a client's parallax
*
* Not on mob because parallax is area based, not mob based.
*
* How parallax works:
* - Layers - normal layers, scroll with movement to relative position, can scroll
* - Absolute - absolute layers, scroll with movement to absolute position, cannot scroll
* - Vis - vis_contents-like model - things in this are directly applied and get no processing whatsoever. Things like overmap ships can use this.
*/
/datum/parallax_holder
/// Client that owns us
var/client/owner
/// The parallax object we're currently rendering
var/datum/parallax/parallax
/// Eye we were last anchored to - used to detect eye changes
var/atom/cached_eye
/// force this eye as the "real" eye - useful for secondary maps
var/atom/forced_eye
/// last turf loc
var/turf/last
/// last area - for parallax scrolling/loop animations
var/area/last_area
/// Holder object for vis
var/atom/movable/screen/parallax_vis/vis_holder
/// are we not on the main map? if so, put map id here
var/secondary_map
/// all layers
var/list/atom/movable/screen/parallax_layer/layers
/// vis contents
var/list/atom/movable/vis
/// currently scrolling?
var/scrolling = FALSE
/// current scroll speed in DS per scroll
var/scroll_speed
/// current scroll turn - applied after angle. if angle is 0 (picture moving north) and turn is 90, it would be like if you turned your viewport 90 deg clockwise.
var/scroll_turn
/// override planemaster we manipulate for turning and other effects
var/atom/movable/screen/plane_master/parallax/planemaster_override
/datum/parallax_holder/New(client/C, secondary_map, forced_eye, planemaster_override)
owner = C
if(!owner)
CRASH("No client")
src.secondary_map = secondary_map
src.forced_eye = forced_eye
src.planemaster_override = planemaster_override
Reset()
/datum/parallax_holder/Destroy()
if(owner)
if(owner.parallax_holder == src)
owner.parallax_holder = null
Remove()
HardResetAnimations()
QDEL_NULL(vis_holder)
QDEL_NULL(parallax)
layers = null
vis = null
last = null
forced_eye = cached_eye = null
owner = null
return ..()
/datum/parallax_holder/proc/Reset(auto_z_change, force)
if(!(cached_eye = Eye()))
// if no eye, tear down
last = cached_eye = last_area = null
SetParallax(null, null, auto_z_change)
return
// first, check loc
var/turf/T = get_turf(cached_eye)
if(!T)
// if in nullspace, tear down
last = cached_eye = last_area = null
SetParallax(null, null, auto_z_change)
return
// set last loc and eye
last = T
last_area = T.loc
// rebuild parallax
SetParallax(SSparallax.get_parallax_datum(T.z), null, auto_z_change, force)
// hard reset positions to correct positions
for(var/atom/movable/screen/parallax_layer/L in layers)
L.ResetPosition(T.x, T.y)
// better updates via client_mobs_in_contents can be created again when important recursive contents is ported!
/datum/parallax_holder/proc/Update(full)
if(!full && !cached_eye || (get_turf(cached_eye) == last))
return
if(!owner) // why are we here
if(!QDELETED(src))
qdel(src)
return
if(cached_eye != Eye())
// eye mismatch, reset
Reset()
return
var/turf/T = get_turf(cached_eye)
if(!last || T.z != last.z)
// z mismatch, reset
Reset()
return
// get rel offsets
var/rel_x = T.x - last.x
var/rel_y = T.y - last.y
// set last
last = T
// move
for(var/atom/movable/screen/parallax_layer/L in layers)
L.RelativePosition(T.x, T.y, rel_x, rel_y)
// process scrolling/movedir
if(last_area != T.loc)
last_area = T.loc
UpdateMotion()
/**
* Gets the eye we should be centered on
*/
/datum/parallax_holder/proc/Eye()
return forced_eye || owner?.eye
/**
* Gets the base parallax planemaster for things like turning
*/
/datum/parallax_holder/proc/GetPlaneMaster()
return planemaster_override || (owner && (locate(/atom/movable/screen/plane_master/parallax) in owner?.screen))
/**
* Syncs us to our parallax objects. Does NOT check if we should have those objects, that's Reset()'s job.
*
* Doesn't move/update positions/screen locs either.
*
* Also ensures movedirs are correct for the eye's pos.
*/
/datum/parallax_holder/proc/Sync(auto_z_change, force)
layers = list()
for(var/atom/movable/screen/parallax_layer/L in parallax.objects)
layers += L
L.map_id = secondary_map
if(!istype(vis_holder))
vis_holder = new /atom/movable/screen/parallax_vis
var/turf/T = get_turf(cached_eye)
vis_holder.vis_contents = vis = T? SSparallax.get_parallax_vis_contents(T.z) : list()
UpdateMotion(auto_z_change, force)
/**
* Updates motion if needed
*/
/datum/parallax_holder/proc/UpdateMotion(auto_z_change, force)
var/turf/T = get_turf(cached_eye)
if(!T)
if(scroll_speed || scroll_turn)
HardResetAnimations()
return
var/list/ret = SSparallax.get_parallax_motion(T.z)
if(ret)
Animation(ret[1], ret[2], auto_z_change? 0 : ret[3], auto_z_change? 0 : ret[4], force)
else
var/area/A = T.loc
Animation(A.parallax_move_speed, A.parallax_move_angle, auto_z_change? 0 : null, auto_z_change? 0 : null, force)
/datum/parallax_holder/proc/Apply(client/C = owner)
if(QDELETED(C))
return
. = list()
for(var/atom/movable/screen/parallax_layer/L in layers)
if(L.parallax_intensity > owner.prefs.parallax)
continue
if(!L.ShouldSee(C, last))
continue
L.SetView(C.view, TRUE)
. |= L
C.screen |= .
if(!secondary_map)
var/atom/movable/screen/plane_master/parallax_white/PM = locate() in C.screen
if(PM)
PM.color = list(
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 1, 1, 1,
0, 0, 0, 0
)
/datum/parallax_holder/proc/Remove(client/C = owner)
if(QDELETED(C))
return
C.screen -= layers
if(!secondary_map)
var/atom/movable/screen/plane_master/parallax_white/PM = locate() in C.screen
if(PM)
PM.color = initial(PM.color)
/datum/parallax_holder/proc/SetParallaxType(path)
if(!ispath(path, /datum/parallax))
CRASH("Invalid path")
SetParallax(new path)
/datum/parallax_holder/proc/SetParallax(datum/parallax/P, delete_old = TRUE, auto_z_change, force)
if(P == parallax)
return
Remove()
if(delete_old && istype(parallax) && !QDELETED(parallax))
qdel(parallax)
HardResetAnimations()
parallax = P
if(!parallax)
return
Sync(auto_z_change, force)
Apply()
/**
* Runs a modifier to parallax as an animation.
*
* @params
* speed - ds per loop
* turn - angle clockwise from north to turn the motion to
* windup - ds to spend on windups. 0 for immediate.
* turn_speed - ds to spend on turning. 0 for immediate.
*/
/datum/parallax_holder/proc/Animation(speed = 25, turn = 0, windup = speed, turn_speed = speed, force)
// Parallax doesn't currently use this method of rotating.
// #if !PARALLAX_ROTATION_ANIMATIONS
// turn_speed = 0
// #endif
if(speed == 0)
StopScrolling(turn = turn, time = windup)
return
// if(turn != scroll_turn && GetPlaneMaster())
// // first handle turn. we turn the planemaster
// var/matrix/turn_transform = matrix()
// turn_transform.Turn(turn)
// scroll_turn = turn
// animate(GetPlaneMaster(), transform = turn_transform, time = turn_speed, easing = QUAD_EASING | EASE_IN, flags = ANIMATION_END_NOW | ANIMATION_LINEAR_TRANSFORM)
if(scroll_speed == speed && !force)
// we're done
return
// speed diff?
scroll_speed = speed
scrolling = TRUE
// always scroll from north; turn handles everything
for(var/atom/movable/screen/parallax_layer/P in layers)
if(P.absolute)
continue
var/matrix/translate_matrix = matrix()
translate_matrix.Translate(cos(turn) * 480, sin(turn) * 480)
var/matrix/target_matrix = matrix()
var/move_speed = speed * P.speed
// do the first segment by shifting down one screen
P.transform = translate_matrix
animate(P, transform = target_matrix, time = move_speed, easing = QUAD_EASING|EASE_IN, flags = ANIMATION_END_NOW)
// queue up another incase lag makes QueueLoop not fire on time, this time by shifting up
animate(transform = translate_matrix, time = 0)
animate(transform = target_matrix, time = move_speed)
P.QueueLoop(move_speed, speed * P.speed, translate_matrix, target_matrix)
/**
* Smoothly stops the animation, turning to a certain angle as needed.
*/
/datum/parallax_holder/proc/StopScrolling(turn = 0, time = 30)
// reset turn
if(turn != scroll_turn && GetPlaneMaster())
var/matrix/turn_transform = matrix()
turn_transform.Turn(turn)
scroll_turn = turn
animate(GetPlaneMaster(), transform = turn_transform, time = time, easing = QUAD_EASING | EASE_OUT, flags = ANIMATION_END_NOW | ANIMATION_LINEAR_TRANSFORM)
if(scroll_speed == 0)
// we're done
scrolling = FALSE
scroll_speed = 0
return
scrolling = FALSE
scroll_speed = 0
// someone can do the math for "stop after a smooth iteration" later.
for(var/atom/movable/screen/parallax_layer/P in layers)
if(P.absolute)
continue
P.CancelAnimation()
var/matrix/translate_matrix = matrix()
translate_matrix.Translate(cos(turn) * 480, sin(turn) * 480)
P.transform = translate_matrix
animate(P, transform = matrix(), time = time, easing = QUAD_EASING | EASE_OUT)
/**
* fully resets animation state
*/
/datum/parallax_holder/proc/HardResetAnimations()
// reset vars
scroll_turn = 0
scroll_speed = 0
scrolling = FALSE
// reset turn
if(GetPlaneMaster())
animate(GetPlaneMaster(), transform = matrix(), time = 0, flags = ANIMATION_END_NOW)
// reset objects
for(var/atom/movable/screen/parallax_layer/P in layers)
if(P.absolute)
continue
P.CancelAnimation()
animate(P, transform = matrix(), time = 0, flags = ANIMATION_END_NOW)
/client/proc/CreateParallax()
if(!parallax_holder)
parallax_holder = new(src)
/atom/movable/screen/parallax_vis
screen_loc = "CENTER,CENTER"
+137
View File
@@ -0,0 +1,137 @@
/atom/movable/screen/parallax_layer
icon = 'icons/screen/parallax.dmi'
blend_mode = BLEND_ADD
plane = PLANE_SPACE_PARALLAX
screen_loc = "CENTER-7,CENTER-7"
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
appearance_flags = PIXEL_SCALE | KEEP_TOGETHER
// notice - all parallax layers are 15x15 tiles. They roll over every 240 pixels.
/// pixel x/y shift per real x/y
var/speed = 1
/// current cached offset x
var/offset_x = 0
/// current cached offset y
var/offset_y = 0
/// normal centered x
var/center_x = 0
/// normal centered y
var/center_y = 0
/// absolute - always determine shift x/y as a function of real x/y instead of allowing for relative scroll.
var/absolute = FALSE
/// parallax level required to see this
var/parallax_intensity = PARALLAX_INSANE
/// current view we're adapted to
var/view_current
/// dynamic self tile - tile to our view size. set this to false for static parallax layers.
var/dynamic_self_tile = TRUE
/// map id
var/map_id
/// queued animation timerid
var/queued_animation
/atom/movable/screen/parallax_layer/proc/ResetPosition(x, y)
// remember that our offsets/directiosn are relative to the player's viewport
// this means we need to scroll reverse to them.
offset_x = -(center_x + speed * x)
offset_y = -(center_y + speed * y)
if(!absolute)
if(offset_x > 240)
offset_x -= 480
if(offset_x < -240)
offset_x += 480
if(offset_y > 240)
offset_y -= 480
if(offset_y < -240)
offset_y += 480
screen_loc = "[map_id && "[map_id]:"]CENTER-7:[round(offset_x,1)],CENTER-7:[round(offset_y,1)]"
/atom/movable/screen/parallax_layer/proc/RelativePosition(x, y, rel_x, rel_y)
if(absolute)
return ResetPosition(x, y)
offset_x -= rel_x * speed
offset_y -= rel_y * speed
if(offset_x > 240)
offset_x -= 480
if(offset_x < -240)
offset_x += 480
if(offset_y > 240)
offset_y -= 480
if(offset_y < -240)
offset_y += 480
screen_loc = "[map_id && "[map_id]:"]CENTER-7:[round(offset_x,1)],CENTER-7:[round(offset_y,1)]"
/atom/movable/screen/parallax_layer/proc/SetView(client_view = world.view, force_update = FALSE)
if(view_current == client_view && !force_update)
return
view_current = client_view
if(!dynamic_self_tile)
return
var/list/real_view = getviewsize(client_view)
var/count_x = CEILING((real_view[1] / 2) / 15, 1) + 1
var/count_y = CEILING((real_view[2] / 2) / 15, 1) + 1
var/list/new_overlays = GetOverlays()
for(var/x in -count_x to count_x)
for(var/y in -count_y to count_y)
if(!x && !y)
continue
var/mutable_appearance/clone = new
// appearance clone
clone.icon = icon
clone.icon_state = icon_state
clone.overlays = GetOverlays()
// do NOT inherit our overlays! parallax layers should never have overlays,
// because if it inherited us it'll result in exponentially increasing overlays
// due to cut_overlays() above over there being a queue operation and not instant!
// clone.overlays = list()
// currently instantly using overlays =.
// clone.blend_mode = blend_mode
// clone.mouse_opacity = mouse_opacity
// clone.plane = plane
// clone.layer = layer
// shift to position
clone.transform = matrix(1, 0, x * 480, 0, 1, y * 480)
new_overlays += clone
overlays = new_overlays
/atom/movable/screen/parallax_layer/proc/ShouldSee(client/C, atom/location)
return TRUE
/**
* Return "natural" overlays, as we're goin to do some fuckery to overlays above.
*/
/atom/movable/screen/parallax_layer/proc/GetOverlays()
return list()
/atom/movable/screen/parallax_layer/proc/Clone()
var/atom/movable/screen/parallax_layer/layer = new type
layer.speed = speed
layer.offset_x = offset_x
layer.offset_y = offset_y
layer.absolute = absolute
layer.parallax_intensity = parallax_intensity
layer.view_current = view_current
layer.appearance = appearance
/atom/movable/screen/parallax_layer/proc/default_x()
return center_x
/atom/movable/screen/parallax_layer/proc/default_y()
return center_y
/atom/movable/screen/parallax_layer/proc/QueueLoop(delay, speed, matrix/translate_matrix, matrix/target_matrix)
if(queued_animation)
CancelAnimation()
queued_animation = addtimer(CALLBACK(src, .proc/_loop, speed, translate_matrix, target_matrix), delay, TIMER_STOPPABLE)
/atom/movable/screen/parallax_layer/proc/_loop(speed, matrix/translate_matrix = matrix(1, 0, 0, 0, 1, 480), matrix/target_matrix = matrix())
transform = translate_matrix
animate(src, transform = target_matrix, time = speed, loop = -1)
animate(transform = translate_matrix, time = 0)
queued_animation = null
/atom/movable/screen/parallax_layer/proc/CancelAnimation()
if(queued_animation)
deltimer(queued_animation)
queued_animation = null
+66
View File
@@ -0,0 +1,66 @@
/datum/parallax/space
var/static/planet_offset_x = rand(100, 160)
var/static/planet_offset_y = rand(100, 160)
var/static/random_layer = pickweightAllowZero(list(
/atom/movable/screen/parallax_layer/space/random/asteroids = 35,
/atom/movable/screen/parallax_layer/space/random/space_gas = 35,
null = 30
))
var/static/random_gas_color = pick(COLOR_TEAL, COLOR_GREEN, COLOR_YELLOW, COLOR_CYAN, COLOR_ORANGE, COLOR_PURPLE)
/datum/parallax/space/CreateObjects()
. = ..()
. += new /atom/movable/screen/parallax_layer/space/layer_1
. += new /atom/movable/screen/parallax_layer/space/layer_2
. += new /atom/movable/screen/parallax_layer/space/layer_3
var/atom/movable/screen/parallax_layer/space/planet/P = new
P.pixel_x = planet_offset_x
P.pixel_y = planet_offset_y
. += P
if(random_layer)
. += new random_layer
if(ispath(random_layer, /atom/movable/screen/parallax_layer/space/random/space_gas))
var/atom/movable/screen/parallax_layer/space/random/space_gas/SG = locate(random_layer) in objects
SG.add_atom_colour(random_gas_color, ADMIN_COLOUR_PRIORITY)
/atom/movable/screen/parallax_layer/space/layer_1
icon_state = "layer1"
speed = 0.6
layer = 1
parallax_intensity = PARALLAX_LOW
/atom/movable/screen/parallax_layer/space/layer_2
icon_state = "layer2"
speed = 1
layer = 2
parallax_intensity = PARALLAX_MED
/atom/movable/screen/parallax_layer/space/layer_3
icon_state = "layer3"
speed = 1.4
layer = 3
parallax_intensity = PARALLAX_HIGH
/atom/movable/screen/parallax_layer/space/random
blend_mode = BLEND_OVERLAY
speed = 3
layer = 3
parallax_intensity = PARALLAX_INSANE
/atom/movable/screen/parallax_layer/space/random/space_gas
icon_state = "space_gas"
/atom/movable/screen/parallax_layer/space/random/asteroids
icon_state = "asteroids"
/atom/movable/screen/parallax_layer/space/planet
icon_state = "planet"
blend_mode = BLEND_OVERLAY
absolute = TRUE //Status of seperation
speed = 3
layer = 30
dynamic_self_tile = FALSE
/atom/movable/screen/parallax_layer/space/planet/ShouldSee(client/C, atom/location)
var/turf/T = get_turf(location)
return ..() && T && is_station_level(T.z)