Changeset - 532e5f429c0f
[Not reviewed]
default
0 1 0
Tess Snider (Malkyne) - 6 years ago 2018-04-26 04:48:53
this@malkyne.org
DPL should no longer scan entire screenshot, when the Pigment Lab dialog
has already been found, unless it has been moved.
1 file changed with 35 insertions and 5 deletions:
0 comments (0 inline, 0 general)
ReactionRecorder.cs
Show inline comments
...
 
@@ -45,12 +45,16 @@ namespace DesertPaintLab
 
        int colorBarWidth = DEFAULT_COLOR_BAR_WIDTH;
 
        int redBarSpacing = DEFAULT_RED_BAR_SPACING;
 
        int greenBarSpacing = DEFAULT_GREEN_BAR_SPACING;
 
        int blueBarSpacing = DEFAULT_BLUE_BAR_SPACING;
 
        int pixelMultiplier = 1;
 

	
 
        bool firstRun = true;
 
        int lastSwatchX = -1;
 
        int lastSwatchY = -1;
 

	
 
        private static ReactionRecorder _instance;
 
        public static ReactionRecorder Instance
 
        {
 
            get {
 
                if (_instance == null)
 
                {
...
 
@@ -248,21 +252,18 @@ namespace DesertPaintLab
 
                }
 
            }
 

	
 
            return result;
 
        }
 

	
 
        unsafe public bool CaptureReaction(byte* pixBytes, int screenshotWidth, int screenshotHeight, int stride, ref PaintColor reactedColor, ref int redPixelStart)
 
        unsafe private bool TestPosition(int x, int y, byte* pixBytes, int screenshotWidth, int screenshotHeight, int stride, ref PaintColor reactedColor, ref int redPixelStart)
 
        {
 
            byte pixel_r, pixel_g, pixel_b;
 
            int pixelStart, otherPixelStart;
 
            bool colorMatch = true;
 
            for (int x = 0; x < screenshotWidth - colorBarWidth; ++x)
 
            {
 
                for (int y = 0; y < (screenshotHeight - (blueBarSpacing + 1)  /*53*/); ++y)
 
                {
 

 
                    // Look for the color swatch.
 
                    pixelStart = (y * stride) + (x * 3);
 
                    pixel_r = pixBytes[pixelStart];
 
                    pixel_g = pixBytes[pixelStart + 1];
 
                    pixel_b = pixBytes[pixelStart + 2];
 
                    
...
 
@@ -342,12 +343,41 @@ namespace DesertPaintLab
 

	
 
                            reactedColor.Blue = (byte)Math.Round((float)bluePixelCount * 255f / (float)colorBarWidth);
 
                            WriteLog("Found the color swatch at {0}, {1}. Color={2}", x, y, reactedColor);
 
                            return true;
 
                        }
 
                    }
 
            return false;
 
        }
 

	
 
        unsafe public bool CaptureReaction(byte* pixBytes, int screenshotWidth, int screenshotHeight, int stride, ref PaintColor reactedColor, ref int redPixelStart)
 
        {
 
            if (!firstRun)
 
            {
 
                // If this is not the first run, let's check the last location, to see if the UI is still there.
 
                if (TestPosition(lastSwatchX, lastSwatchY, pixBytes, screenshotWidth, screenshotHeight, stride, ref reactedColor, ref redPixelStart))
 
                {
 
                    return true;
 
                }
 
                else
 
                {
 
                    firstRun = true;
 
                }
 
            }
 

	
 
            for (int x = 0; x < screenshotWidth - colorBarWidth; ++x)
 
            {
 
                for (int y = 0; y < (screenshotHeight - (blueBarSpacing + 1)  /*53*/); ++y)
 
                {
 
                    if (TestPosition(x, y, pixBytes, screenshotWidth, screenshotHeight, stride, ref reactedColor, ref redPixelStart))
 
                    {
 
                        lastSwatchX = x;
 
                        lastSwatchY = y;
 
                        firstRun = false;
 
                        return true;
 
                    }
 
                }
 
            }
 
            return false;
 
        }
 

	
 
        public bool RecordReaction(PlayerProfile profile, PaintColor expectedColor, PaintColor reactedColor, Reagent[] reagents)
0 comments (0 inline, 0 general)