Java Code Examples for master.flame.danmaku.danmaku.model.BaseDanmaku#isOutside()

The following examples show how to use master.flame.danmaku.danmaku.model.BaseDanmaku#isOutside() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DanmakuFilters.java    From letv with Apache License 2.0 6 votes vote down vote up
public synchronized boolean needFilter(BaseDanmaku danmaku, int index, int totalsizeInScreen, DanmakuTimer timer, boolean fromCachingTask) {
    boolean z = true;
    synchronized (this) {
        removeTimeoutDanmakus(this.blockedDanmakus, 2);
        removeTimeoutDanmakus(this.passedDanmakus, 2);
        removeTimeoutDanmakus(this.currentDanmakus, 3);
        if (!this.blockedDanmakus.contains(danmaku) || danmaku.isOutside()) {
            if (this.passedDanmakus.contains(danmaku)) {
                z = false;
            } else if (this.currentDanmakus.containsKey(danmaku.text)) {
                this.currentDanmakus.put(String.valueOf(danmaku.text), danmaku);
                this.blockedDanmakus.removeItem(danmaku);
                this.blockedDanmakus.addItem(danmaku);
            } else {
                this.currentDanmakus.put(String.valueOf(danmaku.text), danmaku);
                this.passedDanmakus.addItem(danmaku);
                z = false;
            }
        }
    }
    return z;
}
 
Example 2
Source File: DanmakuUtils.java    From letv with Apache License 2.0 6 votes vote down vote up
public static boolean willHitInDuration(IDisplayer disp, BaseDanmaku d1, BaseDanmaku d2, long duration, long currTime) {
    int type1 = d1.getType();
    if (type1 != d2.getType()) {
        return false;
    }
    if (d1.isOutside()) {
        return false;
    }
    long dTime = d2.time - d1.time;
    if (dTime < 0) {
        return true;
    }
    if (Math.abs(dTime) >= duration || d1.isTimeOut() || d2.isTimeOut()) {
        return false;
    }
    if (type1 == 5 || type1 == 4) {
        return true;
    }
    return checkHitAtTime(disp, d1, d2, currTime) || checkHitAtTime(disp, d1, d2, d1.time + d1.getDuration());
}
 
Example 3
Source File: DrawTask.java    From letv with Apache License 2.0 5 votes vote down vote up
public IDanmakus getVisibleDanmakusOnTime(long time) {
    IDanmakus subDanmakus = this.danmakuList.subnew((time - this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION) - 100, time + this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION);
    IDanmakus visibleDanmakus = new Danmakus();
    if (!(subDanmakus == null || subDanmakus.isEmpty())) {
        IDanmakuIterator iterator = subDanmakus.iterator();
        while (iterator.hasNext()) {
            BaseDanmaku danmaku = iterator.next();
            if (danmaku.isShown() && !danmaku.isOutside()) {
                visibleDanmakus.addItem(danmaku);
            }
        }
    }
    return visibleDanmakus;
}
 
Example 4
Source File: DanmakuFilters.java    From letv with Apache License 2.0 5 votes vote down vote up
private synchronized boolean needFilter(BaseDanmaku danmaku, int orderInScreen, int totalsizeInScreen, DanmakuTimer timer, boolean fromCachingTask) {
    boolean z = false;
    synchronized (this) {
        if (timer != null) {
            if (danmaku.isOutside()) {
                if (SystemClock.uptimeMillis() - timer.currMillisecond >= this.mMaxTime) {
                    z = true;
                }
            }
        }
    }
    return z;
}
 
Example 5
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 5 votes vote down vote up
private void evictAllNotInScreen(boolean removeAllReferences) {
    if (this.mCaches != null) {
        IDanmakuIterator it = this.mCaches.iterator();
        while (it.hasNext()) {
            BaseDanmaku danmaku = it.next();
            IDrawingCache<?> cache = danmaku.cache;
            boolean hasReferences;
            if (cache == null || !cache.hasReferences()) {
                hasReferences = false;
            } else {
                hasReferences = true;
            }
            if (removeAllReferences && hasReferences) {
                if (cache.get() != null) {
                    this.mRealSize -= cache.size();
                    cache.destroy();
                }
                entryRemoved(true, danmaku, null);
                it.remove();
            } else if (!danmaku.hasDrawingCache() || danmaku.isOutside()) {
                entryRemoved(true, danmaku, null);
                it.remove();
            }
        }
    }
    this.mRealSize = 0;
}
 
Example 6
Source File: Danmakus.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean removeItem(BaseDanmaku item) {
    if (item == null) {
        return false;
    }
    if (item.isOutside()) {
        item.setVisibility(false);
    }
    if (!this.items.remove(item)) {
        return false;
    }
    this.mSize--;
    return true;
}
 
Example 7
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 4 votes vote down vote up
private long prepareCaches(boolean repositioned) {
    long curr = CacheManagingDrawTask.this.mCacheTimer.currMillisecond;
    long end = curr + (CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION * ((long) CacheManager.this.mScreenSize));
    if (end < CacheManagingDrawTask.this.mTimer.currMillisecond) {
        return 0;
    }
    long startTime = SystemClock.uptimeMillis();
    IDanmakus danmakus = null;
    int tryCount = 0;
    boolean hasException = false;
    do {
        BaseDanmaku first;
        try {
            danmakus = CacheManagingDrawTask.this.danmakuList.subnew(curr, end);
        } catch (Exception e) {
            hasException = true;
            SystemClock.sleep(10);
        }
        tryCount++;
        if (tryCount >= 3 || danmakus != null) {
            if (danmakus != null) {
                CacheManagingDrawTask.this.mCacheTimer.update(end);
                return 0;
            }
            first = danmakus.first();
            BaseDanmaku last = danmakus.last();
            if (first != null || last == null) {
                CacheManagingDrawTask.this.mCacheTimer.update(end);
                return 0;
            }
            long sleepTime = Math.min(100, 30 + ((10 * (first.time - CacheManagingDrawTask.this.mTimer.currMillisecond)) / CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION));
            if (repositioned) {
                sleepTime = 0;
            }
            IDanmakuIterator itr = danmakus.iterator();
            BaseDanmaku item = null;
            int orderInScreen = 0;
            int currScreenIndex = 0;
            int sizeInScreen = danmakus.size();
            while (!this.mPause && !this.mCancelFlag && itr.hasNext()) {
                item = itr.next();
                if (last.time >= CacheManagingDrawTask.this.mTimer.currMillisecond) {
                    if (!item.hasDrawingCache() && (repositioned || (!item.isTimeOut() && item.isOutside()))) {
                        if (!item.hasPassedFilter()) {
                            CacheManagingDrawTask.this.mContext.mDanmakuFilters.filter(item, orderInScreen, sizeInScreen, null, true, CacheManagingDrawTask.this.mContext);
                        }
                        if (!((item.priority == (byte) 0 && item.isFiltered()) || (item.isDanmakuTypeFiltered && item.isFiltered()))) {
                            int screenIndex = (int) ((item.time - curr) / CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION);
                            if (currScreenIndex == screenIndex) {
                                orderInScreen++;
                            } else {
                                orderInScreen = 0;
                                currScreenIndex = screenIndex;
                            }
                            if (!repositioned) {
                                try {
                                    synchronized (CacheManagingDrawTask.this.mDrawingNotify) {
                                        CacheManagingDrawTask.this.mDrawingNotify.wait(sleepTime);
                                    }
                                } catch (InterruptedException e2) {
                                    e2.printStackTrace();
                                }
                            }
                            if (buildCache(item, false) != (byte) 1) {
                                if (!repositioned && SystemClock.uptimeMillis() - startTime >= DanmakuFactory.COMMON_DANMAKU_DURATION * ((long) CacheManager.this.mScreenSize)) {
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
                break;
            }
            long consumingTime = SystemClock.uptimeMillis() - startTime;
            if (item != null) {
                CacheManagingDrawTask.this.mCacheTimer.update(item.time);
                return consumingTime;
            }
            CacheManagingDrawTask.this.mCacheTimer.update(end);
            return consumingTime;
        }
    } while (hasException);
    if (danmakus != null) {
        first = danmakus.first();
        BaseDanmaku last2 = danmakus.last();
        if (first != null) {
        }
        CacheManagingDrawTask.this.mCacheTimer.update(end);
        return 0;
    }
    CacheManagingDrawTask.this.mCacheTimer.update(end);
    return 0;
}
 
Example 8
Source File: DanmakuRenderer.java    From letv with Apache License 2.0 4 votes vote down vote up
public RenderingState draw(IDisplayer disp, IDanmakus danmakus, long startRenderTime) {
    int lastTotalDanmakuCount = this.mRenderingState.totalDanmakuCount;
    this.mRenderingState.reset();
    IDanmakuIterator itr = danmakus.iterator();
    int orderInScreen = 0;
    this.mStartTimer.update(SystemClock.uptimeMillis());
    int sizeInScreen = danmakus.size();
    BaseDanmaku drawItem = null;
    while (itr.hasNext()) {
        drawItem = itr.next();
        if (!drawItem.hasPassedFilter()) {
            this.mContext.mDanmakuFilters.filter(drawItem, orderInScreen, sizeInScreen, this.mStartTimer, false, this.mContext);
        }
        if (drawItem.time >= startRenderTime && (!(drawItem.priority == (byte) 0 && drawItem.isFiltered()) && drawItem.time >= startRenderTime)) {
            if (!drawItem.isDanmakuTypeFiltered || !drawItem.isFiltered()) {
                if (drawItem.isLate()) {
                    if (this.mCacheManager == null || drawItem.hasDrawingCache()) {
                        break;
                    }
                    this.mCacheManager.addDanmaku(drawItem);
                } else {
                    orderInScreen++;
                    if (!drawItem.isMeasured()) {
                        drawItem.measure(disp, false);
                    }
                    this.mDanmakusRetainer.fix(drawItem, disp, this.mVerifier);
                    if (!drawItem.isOutside() && drawItem.isShown()) {
                        if (drawItem.lines != null || drawItem.getBottom() <= ((float) disp.getHeight())) {
                            int renderingType = drawItem.draw(disp);
                            RenderingState renderingState;
                            if (renderingType == 1) {
                                renderingState = this.mRenderingState;
                                renderingState.cacheHitCount++;
                            } else if (renderingType == 2) {
                                renderingState = this.mRenderingState;
                                renderingState.cacheMissCount++;
                                if (this.mCacheManager != null) {
                                    this.mCacheManager.addDanmaku(drawItem);
                                }
                            }
                            this.mRenderingState.addCount(drawItem.getType(), 1);
                            this.mRenderingState.addTotalCount(1);
                            if (!(this.mOnDanmakuShownListener == null || drawItem.firstShownFlag == this.mContext.mGlobalFlagValues.FIRST_SHOWN_RESET_FLAG)) {
                                drawItem.firstShownFlag = this.mContext.mGlobalFlagValues.FIRST_SHOWN_RESET_FLAG;
                                this.mOnDanmakuShownListener.onDanmakuShown(drawItem);
                            }
                        }
                    }
                }
            }
        }
    }
    this.mRenderingState.nothingRendered = this.mRenderingState.totalDanmakuCount == 0;
    this.mRenderingState.endTime = drawItem != null ? drawItem.time : -1;
    if (this.mRenderingState.nothingRendered) {
        this.mRenderingState.beginTime = -1;
    }
    this.mRenderingState.incrementCount = this.mRenderingState.totalDanmakuCount - lastTotalDanmakuCount;
    this.mRenderingState.consumingTime = this.mStartTimer.update(SystemClock.uptimeMillis());
    return this.mRenderingState;
}
 
Example 9
Source File: DanmakusRetainer.java    From letv with Apache License 2.0 4 votes vote down vote up
public void fix(BaseDanmaku drawItem, IDisplayer disp, Verifier verifier) {
    if (!drawItem.isOutside()) {
        float topPos = 0.0f;
        int lines = 0;
        boolean willHit = (drawItem.isShown() || this.mVisibleDanmakus.isEmpty()) ? false : true;
        boolean isOutOfVertialEdge = false;
        boolean shown = drawItem.isShown();
        if (!shown) {
            boolean overwriteInsert;
            this.mCancelFixingFlag = false;
            IDanmakuIterator it = this.mVisibleDanmakus.iterator();
            BaseDanmaku insertItem = null;
            BaseDanmaku firstItem = null;
            BaseDanmaku lastItem = null;
            BaseDanmaku minRightRow = null;
            while (!this.mCancelFixingFlag && it.hasNext()) {
                lines++;
                BaseDanmaku item = it.next();
                if (item == drawItem) {
                    insertItem = item;
                    lastItem = null;
                    shown = true;
                    willHit = false;
                    overwriteInsert = false;
                    break;
                }
                if (firstItem == null) {
                    firstItem = item;
                }
                if (drawItem.paintHeight + item.getTop() > ((float) disp.getHeight())) {
                    overwriteInsert = true;
                    break;
                }
                if (minRightRow == null) {
                    minRightRow = item;
                } else if (minRightRow.getRight() >= item.getRight()) {
                    minRightRow = item;
                }
                willHit = DanmakuUtils.willHitInDuration(disp, item, drawItem, drawItem.getDuration(), drawItem.getTimer().currMillisecond);
                if (!willHit) {
                    insertItem = item;
                    overwriteInsert = false;
                    break;
                }
                lastItem = item;
            }
            overwriteInsert = false;
            boolean checkEdge = true;
            if (insertItem != null) {
                if (lastItem != null) {
                    topPos = lastItem.getBottom();
                } else {
                    topPos = insertItem.getTop();
                }
                if (insertItem != drawItem) {
                    this.mVisibleDanmakus.removeItem(insertItem);
                    shown = false;
                }
            } else if (overwriteInsert && minRightRow != null) {
                topPos = minRightRow.getTop();
                checkEdge = false;
                shown = false;
            } else if (lastItem != null) {
                topPos = lastItem.getBottom();
                willHit = false;
            } else if (firstItem != null) {
                topPos = firstItem.getTop();
                this.mVisibleDanmakus.removeItem(firstItem);
                shown = false;
            } else {
                topPos = 0.0f;
            }
            if (checkEdge) {
                isOutOfVertialEdge = isOutVerticalEdge(overwriteInsert, drawItem, disp, topPos, firstItem, lastItem);
            }
            if (isOutOfVertialEdge) {
                topPos = 0.0f;
                willHit = true;
            }
            if (topPos == 0.0f) {
                shown = false;
            }
        }
        if (verifier == null || !verifier.skipLayout(drawItem, topPos, lines, willHit)) {
            if (isOutOfVertialEdge) {
                clear();
            }
            drawItem.layout(disp, drawItem.getLeft(), topPos);
            if (!shown) {
                this.mVisibleDanmakus.addItem(drawItem);
            }
        }
    }
}
 
Example 10
Source File: DanmakusRetainer.java    From letv with Apache License 2.0 4 votes vote down vote up
public void fix(BaseDanmaku drawItem, IDisplayer disp, Verifier verifier) {
    if (!drawItem.isOutside()) {
        boolean shown = drawItem.isShown();
        float topPos = drawItem.getTop();
        int lines = 0;
        boolean willHit = (drawItem.isShown() || this.mVisibleDanmakus.isEmpty()) ? false : true;
        boolean isOutOfVerticalEdge = false;
        if (topPos < 0.0f) {
            topPos = ((float) disp.getHeight()) - drawItem.paintHeight;
        }
        BaseDanmaku removeItem = null;
        BaseDanmaku firstItem = null;
        if (!shown) {
            this.mCancelFixingFlag = false;
            IDanmakuIterator it = this.mVisibleDanmakus.iterator();
            while (!this.mCancelFixingFlag && it.hasNext()) {
                lines++;
                BaseDanmaku item = it.next();
                if (item == drawItem) {
                    removeItem = null;
                    willHit = false;
                    break;
                }
                if (firstItem == null) {
                    firstItem = item;
                    if (firstItem.getBottom() != ((float) disp.getHeight())) {
                        break;
                    }
                }
                if (topPos < 0.0f) {
                    removeItem = null;
                    break;
                }
                willHit = DanmakuUtils.willHitInDuration(disp, item, drawItem, drawItem.getDuration(), drawItem.getTimer().currMillisecond);
                if (!willHit) {
                    removeItem = item;
                    break;
                }
                topPos = item.getTop() - drawItem.paintHeight;
            }
            isOutOfVerticalEdge = isOutVerticalEdge(false, drawItem, disp, topPos, firstItem, null);
            if (isOutOfVerticalEdge) {
                topPos = ((float) disp.getHeight()) - drawItem.paintHeight;
                willHit = true;
            } else if (topPos >= 0.0f) {
                willHit = false;
            }
        }
        if (verifier == null || !verifier.skipLayout(drawItem, topPos, lines, willHit)) {
            if (isOutOfVerticalEdge) {
                clear();
            }
            drawItem.layout(disp, drawItem.getLeft(), topPos);
            if (!shown) {
                this.mVisibleDanmakus.removeItem(removeItem);
                this.mVisibleDanmakus.addItem(drawItem);
            }
        }
    }
}