Modified to check every pixel

Checking only a few pixels had the tendancy to turn my charcter's head inside out when I was pointing directions other than south. Worse case is 1024 tests per object in the image. This test should be uncommon and the CPU usage is constrained by other factors.
This commit is contained in:
JimTheCactus
2014-07-28 01:46:07 -06:00
committed by ZomgPonies
parent ca458f502a
commit 03b075ffd7
2 changed files with 13 additions and 32 deletions
+11 -24
View File
@@ -682,12 +682,7 @@ proc // Creates a single icon from a given /atom or /image. Only the first argu
var/image/copy
// Add the atom's icon itself, without pixel_x/y offsets.
if(!noIcon)
world.log << "***Rendering Icon [A.type] in state '[curstate]' on layer [A.layer] in direction [curdir]" // #JMO
copy = image(icon=curicon, icon_state=curstate, layer=A.layer, dir=curdir)
if (isnull(copy)) // #JMO
world.log << "****Created a null!" // #JMO
else // #JMO
world.log << "****Created a thing of type [copy.type]" // #JMO
copy.color = A.color
copy.alpha = A.alpha
copy.blend_mode = curblend
@@ -751,30 +746,22 @@ proc // Creates a single icon from a given /atom or /image. Only the first argu
// This checks for a silent failure mode of the icon routine. If the requested dir
// doesn't exist in this icon state it returns a 32x32 icon with 0 alpha.
if (I:dir != SOUTH && add.Width() == 32 && add.Height() == 32)
// Since checking every pixel for blank isn't trivial, we make some assumptions about
// the content of the image to determine if it actually is blank. On a rare occassions
// this will cause the software to return a non-directional icon for when a
// directionalized one would be more appropriate. This is rare enough that this
// will suffice in place of a map rework that properly normalizes directions.
var/blankpixel=1;
// Check the four corners...
blankpixel &= isnull(add.GetPixel(1,1))
blankpixel &= isnull(add.GetPixel(32,1))
blankpixel &= isnull(add.GetPixel(32,32))
blankpixel &= isnull(add.GetPixel(32,1))
// The thirds...
blankpixel &= isnull(add.GetPixel(11,11))
blankpixel &= isnull(add.GetPixel(11,22))
blankpixel &= isnull(add.GetPixel(22,22))
blankpixel &= isnull(add.GetPixel(22,11))
// and the center...
blankpixel &= isnull(add.GetPixel(16,16))
// Check every pixel for blank (computationally expensive, but the process is limited
// by the amount of film on the station, only happens when we hit something that's
// turned, and bails at the very first pixel it sees.
var/blankpixel;
for(var/y;y<=32;y++)
for(var/x;x<32;x++)
blankpixel = isnull(add.GetPixel(x,y))
if(!blankpixel)
break
if(!blankpixel)
break
// If we ALWAYS returned a null (which happens when GetPixel encounters something with alpha 0)
if (blankpixel)
// Pull the default direction.
add = icon(I:icon, I:icon_state)
else // 'I' is an appearance object.
world.log << "***Recursing to render Icon [I:type] in state '[curstate]' in direction [curdir]" // #JMO
add = getFlatIcon(new/image(I), curdir, curicon, curstate, curblend)
// Find the new dimensions of the flat icon to fit the added overlay
+2 -8
View File
@@ -154,16 +154,12 @@
..()
/obj/item/device/camera/proc/get_icon(turf/the_turf as turf,mob/user as mob) //#JMO Added mob/user for debug for debug
/obj/item/device/camera/proc/get_icon(turf/the_turf as turf)
//Bigger icon base to capture those icons that were shifted to the next tile
//i.e. pretty much all wall-mounted machinery
var/icon/res = icon('icons/effects/96x96.dmi', "")
world.log << "***Calling build composite..." //#JMO
//var/icon/turficon = build_composite_icon(the_turf)
res.Blend(getFlatIcon(the_turf), blendMode2iconMode(the_turf.blend_mode),33,33)
world.log << "***Exiting build composite..." //#JMO
//res.Blend(turficon, ICON_OVERLAY, 33, 33)
var/atoms[] = list()
for(var/atom/A in the_turf)
@@ -186,11 +182,9 @@
for(var/i; i <= sorted.len; i++)
var/atom/A = sorted[i]
if(A)
world.log << "**Calling getFlatIcon to render [A]" //#JMO
var/icon/img = getFlatIcon(A)//build_composite_icon(A)
// Check if we're looking at a mob that's lying down
if(istype(A, /mob/living) && A:lying)
world.log << "[A] is lying down. Making it look as such..." // #JMO;
// If they are, apply that effect to their picture.
img.BecomeLying()
@@ -237,7 +231,7 @@
if(user.client) //To make shooting through security cameras possible
viewer = user.client.eye
if(dummy in viewers(world.view, viewer))
temp.Blend(get_icon(T,user), ICON_OVERLAY, 32 * (j-1-1), 32 - 32 * (i-1))
temp.Blend(get_icon(T), ICON_OVERLAY, 32 * (j-1-1), 32 - 32 * (i-1))
else
temp.Blend(black, ICON_OVERLAY, 32 * (j-1), 64 - 32 * (i-1))
mobs += get_mobs(T)