Skip to content

Commit

Permalink
DanmakuFilters: skip filter-checking if danmaku is already filtered b…
Browse files Browse the repository at this point in the history
…y one filter
  • Loading branch information
ctiao committed Sep 10, 2015
1 parent ee50f9c commit a63a573
Showing 1 changed file with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static interface IDanmakuFilter<T> {
/*
* 是否过滤
*/
public void filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
public boolean filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask);

public void setData(T data);
Expand Down Expand Up @@ -74,12 +74,13 @@ public void disableType(Integer type) {
}

@Override
public void filter(BaseDanmaku danmaku, int orderInScreen, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
public boolean filter(BaseDanmaku danmaku, int orderInScreen, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
boolean filtered = danmaku != null && mFilterTypes.contains(danmaku.getType());
if (filtered) {
danmaku.mFilterParam |= FILTER_TYPE_TYPE;
}
return filtered;
}

@Override
Expand Down Expand Up @@ -131,12 +132,13 @@ private boolean needFilter(BaseDanmaku danmaku, int orderInScreen,
}

@Override
public synchronized void filter(BaseDanmaku danmaku, int orderInScreen,
int totalsizeInScreen, DanmakuTimer timer, boolean fromCachingTask) {
public synchronized boolean filter(BaseDanmaku danmaku, int orderInScreen,
int totalsizeInScreen, DanmakuTimer timer, boolean fromCachingTask) {
boolean filtered = needFilter(danmaku, orderInScreen, totalsizeInScreen, timer, fromCachingTask);
if (filtered) {
danmaku.mFilterParam |= FILYER_TYPE_QUANTITY;
}
return filtered;
}

@Override
Expand Down Expand Up @@ -183,12 +185,13 @@ private synchronized boolean needFilter(BaseDanmaku danmaku, int orderInScreen,
}

@Override
public void filter(BaseDanmaku danmaku, int orderInScreen,
int totalsizeInScreen, DanmakuTimer timer, boolean fromCachingTask) {
public boolean filter(BaseDanmaku danmaku, int orderInScreen,
int totalsizeInScreen, DanmakuTimer timer, boolean fromCachingTask) {
boolean filtered = needFilter(danmaku, orderInScreen, totalsizeInScreen, timer, fromCachingTask);
if (filtered) {
danmaku.mFilterParam |= FILTER_TYPE_ELAPSED_TIME;
}
return filtered;
}

@Override
Expand Down Expand Up @@ -224,12 +227,13 @@ private void addToWhiteList(Integer color) {
}

@Override
public void filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
public boolean filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
boolean filtered = danmaku != null && !mWhiteList.contains(danmaku.textColor);
if (filtered) {
danmaku.mFilterParam |= FILTER_TYPE_TEXTCOLOR;
}
return filtered;
}

@Override
Expand Down Expand Up @@ -265,7 +269,7 @@ private void addToBlackList(T id) {
}

@Override
public abstract void filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
public abstract boolean filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask);

@Override
Expand Down Expand Up @@ -293,12 +297,13 @@ public void reset() {
public static class UserIdFilter extends UserFilter<Integer> {

@Override
public void filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
public boolean filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
boolean filtered = danmaku != null && mBlackList.contains(danmaku.userId);
if (filtered) {
danmaku.mFilterParam |= FILTER_TYPE_USER_ID;
}
return filtered;
}

}
Expand All @@ -311,12 +316,13 @@ public void filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
public static class UserHashFilter extends UserFilter<String> {

@Override
public void filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
public boolean filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
boolean filtered = danmaku != null && mBlackList.contains(danmaku.userHash);
if (filtered) {
danmaku.mFilterParam |= FILTER_TYPE_USER_HASH;
}
return filtered;
}

}
Expand All @@ -331,12 +337,13 @@ public static class GuestFilter extends BaseDanmakuFilter<Boolean> {
private Boolean mBlock = false;

@Override
public void filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
public boolean filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
boolean filtered = mBlock && danmaku.isGuest;
if (filtered) {
danmaku.mFilterParam |= FILTER_TYPE_USER_GUEST;
}
return filtered;
}

@Override
Expand Down Expand Up @@ -424,12 +431,13 @@ public synchronized boolean needFilter(BaseDanmaku danmaku, int index, int total
}

@Override
public void filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
public boolean filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
boolean filtered = needFilter(danmaku, index, totalsizeInScreen, timer, fromCachingTask);
if (filtered) {
danmaku.mFilterParam |= FILTER_TYPE_DUPLICATE_MERGE;
}
return filtered;
}

@Override
Expand Down Expand Up @@ -475,8 +483,11 @@ public void filter(BaseDanmaku danmaku, int index, int totalsizeInScreen,
DanmakuTimer timer, boolean fromCachingTask) {
for (IDanmakuFilter<?> f : mFilterArray) {
if (f != null) {
f.filter(danmaku, index, totalsizeInScreen, timer, fromCachingTask);
boolean filtered = f.filter(danmaku, index, totalsizeInScreen, timer, fromCachingTask);
danmaku.filterResetFlag = GlobalFlagValues.FILTER_RESET_FLAG;
if (filtered) {
break;
}
}
}
}
Expand Down

0 comments on commit a63a573

Please sign in to comment.