Skip to content
Snippets Groups Projects
Commit f1b9d7a0 authored by Micah Elizabeth Scott's avatar Micah Elizabeth Scott
Browse files

CPU utilization tweaks; default frame rate, no draw when disconnected

parent 9fb077f3
No related branches found
No related tags found
No related merge requests found
......@@ -182,7 +182,8 @@ inline EffectRunner::EffectRunner()
lastTime.tv_sec = 0;
lastTime.tv_usec = 0;
// Default server
// Defaults
setMaxFrameRate(300);
setServer("localhost");
}
......@@ -279,22 +280,26 @@ inline void EffectRunner::doFrame(float timeDelta)
frameInfo.advance(timeDelta);
effect->beginFrame(frameInfo);
uint8_t *dest = OPCClient::Header::view(frameBuffer).data();
// Only calculate the effect if we have a connection
if (opc.tryConnect()) {
uint8_t *dest = OPCClient::Header::view(frameBuffer).data();
for (PixelInfoIter i = frameInfo.pixels.begin(), e = frameInfo.pixels.end(); i != e; ++i) {
Vec3 rgb(0, 0, 0);
const PixelInfo &p = *i;
for (PixelInfoIter i = frameInfo.pixels.begin(), e = frameInfo.pixels.end(); i != e; ++i) {
Vec3 rgb(0, 0, 0);
const PixelInfo &p = *i;
if (p.isMapped()) {
effect->calculatePixel(rgb, p);
}
if (p.isMapped()) {
effect->calculatePixel(rgb, p);
}
for (unsigned i = 0; i < 3; i++) {
*(dest++) = std::min<int>(255, std::max<int>(0, rgb[i] * 255 + 0.5));
for (unsigned i = 0; i < 3; i++) {
*(dest++) = std::min<int>(255, std::max<int>(0, rgb[i] * 255 + 0.5));
}
}
}
opc.write(frameBuffer);
opc.write(frameBuffer);
}
effect->endFrame(frameInfo);
......
......@@ -47,6 +47,8 @@ public:
bool resolve(const char *hostport, int defaultPort = 7890);
bool write(const uint8_t *data, ssize_t length);
bool write(const std::vector<uint8_t> &data);
bool tryConnect();
bool isConnected();
struct Header {
......@@ -139,12 +141,15 @@ inline bool OPCClient::isConnected()
return fd > 0;
}
inline bool OPCClient::tryConnect()
{
return isConnected() || connectSocket();
}
inline bool OPCClient::write(const uint8_t *data, ssize_t length)
{
if (!isConnected()) {
if (!connectSocket()) {
return false;
}
if (!tryConnect()) {
return false;
}
while (length > 0) {
......@@ -170,7 +175,7 @@ inline bool OPCClient::connectSocket()
fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (connect(fd, (struct sockaddr*) &address, sizeof address) < 0) {
close(fd);
closeSocket();
return false;
}
......
......@@ -76,7 +76,6 @@ int main(int argc, char **argv)
EffectRunner r;
r.setEffect(&br);
r.setMaxFrameRate(200);
r.setLayout("../layouts/grid32x16z.json");
return r.main(argc, argv);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment