-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev: move fn mg_timer_add #170
Changes from all commits
529c119
396619a
3f932fc
3760e25
ecdd723
40616e3
3cc904e
c62c44a
41f5136
9918f1f
27859f0
6395f04
6dacffb
bb90172
179d1fd
b02bbdd
1aae61c
b06d774
e8b0063
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
// | ||
|
||
#include <pystring.h> | ||
#include <utility> | ||
|
||
#include "view/danmaku_core.hpp" | ||
#include "view/mpv_core.hpp" | ||
|
@@ -43,6 +44,42 @@ DanmakuItem::DanmakuItem(std::string content, const char *attributes) | |
} | ||
} | ||
|
||
DanmakuItem::DanmakuItem(std::string &&content, const std::string &attributes){ | ||
msg = std::move(content); | ||
|
||
#ifdef OPENCC | ||
static bool ZH_T = brls::Application::getLocale() == brls::LOCALE_ZH_HANT || | ||
brls::Application::getLocale() == brls::LOCALE_ZH_TW; | ||
if (ZH_T && brls::Label::OPENCC_ON) msg = brls::Label::STConverter(msg); | ||
#endif | ||
std::vector<std::string> attrs; | ||
pystring::split(attributes.c_str(), attrs, ","); | ||
if (attrs.size() < 9) { | ||
brls::Logger::error("error decode danmaku: {} {}", msg, attributes); | ||
type = -1; | ||
return; | ||
} | ||
time = atof(attrs[0].c_str()); | ||
type = atoi(attrs[1].c_str()); | ||
fontSize = atoi(attrs[2].c_str()); | ||
fontColor = atoi(attrs[3].c_str()); | ||
level = atoi(attrs[8].c_str()); | ||
|
||
int r = (fontColor >> 16) & 0xff; | ||
int g = (fontColor >> 8) & 0xff; | ||
int b = fontColor & 0xff; | ||
isDefaultColor = (r & g & b) == 0xff; | ||
color = nvgRGB(r, g, b); | ||
color.a = DanmakuCore::DANMAKU_STYLE_ALPHA * 0.01; | ||
borderColor.a = DanmakuCore::DANMAKU_STYLE_ALPHA * 0.005; | ||
|
||
// 判断是否添加浅色边框 | ||
if ((r * 299 + g * 587 + b * 114) < 60000) { | ||
borderColor = nvgRGB(255, 255, 255); | ||
borderColor.a = DanmakuCore::DANMAKU_STYLE_ALPHA * 0.5; | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里面可以和原本的构造函数复用的部分是不是应该写到一起去,避免相同的代码写两遍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 那传递的时候依旧需要复制一遍,就没有意义了 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果你指的是单独拿出重复的部分,那是没有问题的 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
是的我就是这个意思,这样之后改的话也不需要同时改两个地方 |
||
void DanmakuCore::reset() { | ||
danmakuMutex.lock(); | ||
lineNum = 20; | ||
|
@@ -78,6 +115,16 @@ void DanmakuCore::addSingleDanmaku(const DanmakuItem &item) { | |
MPVCore::instance().getCustomEvent()->fire("DANMAKU_LOADED", nullptr); | ||
} | ||
|
||
void DanmakuCore::addSingleDanmaku(DanmakuItem &&item) { | ||
danmakuMutex.lock(); | ||
this->danmakuData.emplace_back(std::move(item)); | ||
this->danmakuLoaded = true; | ||
danmakuMutex.unlock(); | ||
|
||
// 通过mpv来通知弹幕加载完成 | ||
MPVCore::instance().getCustomEvent()->fire("DANMAKU_LOADED", nullptr); | ||
} | ||
|
||
void DanmakuCore::refresh() { | ||
danmakuMutex.lock(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这一段可以找到更好的方式来实现吗?直接使用 reinterpret_cast 转换两个数字类型会导致 Undefined Behavior,虽然大多数时候都能正常运行,但是还是应该避免这个警告。
https://stackoverflow.com/a/25586060
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我使用的uint32_t应该能在大部分平台保持一致吧,你引用的问题使用了
reinterpret_cast<unsigned long>(int)
,他这个确实可能会有问题要不就换回我之前使用的memcpy。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maye174 你之前就是写的 reinterpret_cast,这里的 memcpy 是我改的,如果不改的话在调试的时候IDE一直报告问题。
我在这里有提及:#164 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xfangfang 那你再改回去吧,我真没注意这个,我比较惯用这个。。