void linux_signal::wait_for(spring_time t) { int m; // cur gen const int g = gen.load(); // our gen sleepers++; struct timespec linux_t; linux_t.tv_sec = 0; linux_t.tv_nsec = t.toNanoSecsi(); const spring_time endTimer = spring_now() + t; while (((g - (m = mtx)) >= 0) && (spring_now() < endTimer)) { syscall(SYS_futex, &mtx, FUTEX_WAIT_PRIVATE, m, &linux_t, NULL, 0); } sleepers--; }
/** * @return return code of activecontroller draw function * * Draw function repeatedly called, it calls all the * other draw functions */ int SpringApp::Update() { if (globalRendering->FSAA) glEnable(GL_MULTISAMPLE_ARB); int ret = 1; if (activeController != NULL) { ret = activeController->Update(); if (ret) { ScopedTimer cputimer("GameController::Draw"); ret = activeController->Draw(); } } ScopedTimer cputimer("SwapBuffers"); spring_time pre = spring_now(); VSync.Delay(); SDL_GL_SwapWindow(window); eventHandler.DbgTimingInfo(TIMING_SWAP, pre, spring_now()); return ret; }
static void DrawThreadBarcode() { const float maxHist_f = 4.0f; const spring_time curTime = spring_now(); const spring_time maxHist = spring_secs(maxHist_f); auto& coreProf = profiler.profileCore; const auto numThreads = coreProf.size(); const float drawArea[4] = {0.01f, 0.30f, (start_x / 2), 0.35f}; // background CVertexArray* va = GetVertexArray(); va->Initialize(); va->AddVertex0(drawArea[0] - 10 * globalRendering->pixelX, drawArea[1] - 10 * globalRendering->pixelY, 0.0f); va->AddVertex0(drawArea[0] - 10 * globalRendering->pixelX, drawArea[3] + 10 * globalRendering->pixelY, 0.0f); va->AddVertex0(drawArea[2] + 10 * globalRendering->pixelX, drawArea[3] + 10 * globalRendering->pixelY, 0.0f); va->AddVertex0(drawArea[2] + 10 * globalRendering->pixelX, drawArea[1] - 10 * globalRendering->pixelY, 0.0f); glColor4f(0.0f,0.0f,0.0f, 0.5f); va->DrawArray0(GL_QUADS); // title font->glFormat(drawArea[0], drawArea[3], 0.7f, FONT_TOP | DBG_FONT_FLAGS, "ThreadPool (%.0fsec)", maxHist_f); // bars glColor4f(1.0f,0.0f,0.0f, 0.6f); int i = 0; for (auto& frames: coreProf) { float drawArea2[4] = {drawArea[0], 0.f, drawArea[2], 0.f}; drawArea2[1] = drawArea[1] + ((drawArea[3] - drawArea[1]) / numThreads) * i++; drawArea2[3] = drawArea[1] + ((drawArea[3] - drawArea[1]) / numThreads) * i - 4 * globalRendering->pixelY; DrawTimeSlice(frames, curTime, maxHist, drawArea2); } // feeder //const float y1 = 0.0f; //const float y2 = 0.1f * numThreads; //CVertexArray* va = GetVertexArray(); va->Initialize(); const float r = (curTime % maxHist).toSecsf() / maxHist_f; const float xf = drawArea[0] + r * (drawArea[2] - drawArea[0]); va->AddVertex0(xf, drawArea[1], 0.0f); va->AddVertex0(xf, drawArea[3], 0.0f); va->AddVertex0(xf + 5 * globalRendering->pixelX, drawArea[3], 0.0f); va->AddVertex0(xf + 5 * globalRendering->pixelX, drawArea[1], 0.0f); glColor3f(1.0f,0.0f,0.0f); va->DrawArray0(GL_QUADS); }
void LineEdit::DrawSelf() { const float opacity = Opacity(); glColor4f(1.0f, 1.0f, 1.0f, opacity); DrawBox(GL_QUADS); glLineWidth(1.49f); if (hasFocus) { glColor4f(0.0f, 0.0f, 0.0f, opacity); DrawBox(GL_LINE_LOOP); } else { glColor4f(0.5f, 0.5f, 0.5f, opacity); DrawBox(GL_LINE_LOOP); } std::string tempText; if (crypt) { tempText.resize(content.size(), '*'); } else { tempText = content; } const float textCenter = pos[1] + size[1]/2; if (hasFocus) { // draw the caret const std::string caretStr = tempText.substr(0, cursorPos); const float caretWidth = font->GetSize() * font->GetTextWidth(caretStr) / float(screensize[0]); char c = tempText[cursorPos]; if (c == 0) { c = ' '; } const float cursorHeight = font->GetSize() * font->GetLineHeight() / float(screensize[1]); const float cw = font->GetSize() * font->GetCharacterWidth(c) /float(screensize[0]); const float csx = pos[0] + 0.01 + caretWidth; const float f = 0.5f * (1.0f + fastmath::sin(spring_now().toMilliSecsf() * 0.015f)); glColor4f(f, f, f, opacity); glRectf(csx, textCenter + cursorHeight/2, csx + cw, textCenter - cursorHeight/2); glColor4f(0.0f, 0.0f, 0.0f, 1.0f); // black } font->SetTextColor(); //default font->glPrint(pos[0] + 0.01, textCenter, 1.0, FONT_VCENTER | FONT_SCALE | FONT_NORM, tempText); }
void CPlayerRosterDrawer::Draw() { if (playerRoster.GetSortType() == PlayerRoster::Disabled) return; const unsigned currentTime = spring_now().toSecsi(); static std::string chart; chart = ""; static std::string prefix; char buf[128]; int count; const std::vector<int>& indices = playerRoster.GetIndices(&count, true); SNPRINTF(buf, sizeof(buf), "\xff%c%c%c \tNu\tm \tUser name \tCPU \tPing", 255, 255, 63); chart += buf; for (int a = 0; a < count; ++a) { const CPlayer* p = playerHandler->Player(indices[a]); unsigned char color[3] = {255, 255, 255}; unsigned char allycolor[3] = {255, 255, 255}; if (p->ping != PATHING_FLAG || !gs->PreSimFrame()) { if (p->spectator) prefix = "S"; else { const unsigned char* bColor = teamHandler->Team(p->team)->color; color[0] = std::max((unsigned char)1, bColor[0]); color[1] = std::max((unsigned char)1, bColor[1]); color[2] = std::max((unsigned char)1, bColor[2]); if (gu->myAllyTeam == teamHandler->AllyTeam(p->team)) { allycolor[0] = allycolor[2] = 1; prefix = "A"; // same AllyTeam } else if (teamHandler->AlliedTeams(gu->myTeam, p->team)) { allycolor[0] = allycolor[1] = 1; prefix = "E+"; // different AllyTeams, but are allied } else { allycolor[1] = allycolor[2] = 1; prefix = "E"; //no alliance at all } } float4 cpucolor(!p->spectator && p->cpuUsage > 0.75f && gs->speedFactor < gs->wantedSpeedFactor * 0.99f && (currentTime & 128) ? 0.5f : std::max(0.01f, std::min(1.0f, p->cpuUsage * 2.0f / 0.75f)), std::min(1.0f, std::max(0.01f, (1.0f - p->cpuUsage / 0.75f) * 2.0f)), 0.01f, 1.0f); float4 pingcolor(!p->spectator && globalConfig->reconnectTimeout > 0 && p->ping > 1000 * globalConfig->reconnectTimeout && (currentTime & 128) ? 0.5f : std::max(0.01f, std::min(1.0f, (p->ping - 250) / 375.0f)), std::min(1.0f, std::max(0.01f, (1000 - p->ping) / 375.0f)), 0.01f, 1.0f); SNPRINTF(buf, sizeof(buf), "\xff%c%c%c%c \t%i \t%s \t\xff%c%c%c%s \t\xff%c%c%c%.0f%% \t\xff%c%c%c%dms", allycolor[0], allycolor[1], allycolor[2], (gu->spectating && !p->spectator && (gu->myTeam == p->team)) ? '-' : ' ', p->team, prefix.c_str(), color[0], color[1], color[2], p->name.c_str(), (unsigned char)(cpucolor[0] * 255.0f), (unsigned char)(cpucolor[1] * 255.0f), (unsigned char)(cpucolor[2] * 255.0f), p->cpuUsage * 100.0f, (unsigned char)(pingcolor[0] * 255.0f), (unsigned char)(pingcolor[1] * 255.0f), (unsigned char)(pingcolor[2] * 255.0f), p->ping); } else { prefix = ""; SNPRINTF(buf, sizeof(buf), "\xff%c%c%c%c \t%i \t%s \t\xff%c%c%c%s \t%s-%d \t%d", allycolor[0], allycolor[1], allycolor[2], (gu->spectating && !p->spectator && (gu->myTeam == p->team)) ? '-' : ' ', p->team, prefix.c_str(), color[0], color[1], color[2], p->name.c_str(), (((int)p->cpuUsage) & 0x1)?"PC":"BO", ((int)p->cpuUsage) & 0xFE, (((int)p->cpuUsage)>>8)*1000); } chart += "\n"; chart += buf; } int font_options = FONT_RIGHT | FONT_BOTTOM | FONT_SCALE | FONT_NORM; if (guihandler->GetOutlineFonts()) font_options |= FONT_OUTLINE; smallFont->SetColors(); smallFont->glPrintTable(1.0f - 5 * globalRendering->pixelX, 0.00f + 5 * globalRendering->pixelY, 1.0f, font_options, chart); }
static void DrawFrameBarcode() { const float maxHist_f = 0.5f; const spring_time curTime = spring_now(); const spring_time maxHist = spring_secs(maxHist_f); float drawArea[4] = {0.01f, 0.2f, start_x - 0.05f, 0.25f}; // background CVertexArray* va = GetVertexArray(); va->Initialize(); va->AddVertex0(drawArea[0] - 10 * globalRendering->pixelX, drawArea[1] - 10 * globalRendering->pixelY, 0.0f); va->AddVertex0(drawArea[0] - 10 * globalRendering->pixelX, drawArea[3] + 20 * globalRendering->pixelY, 0.0f); va->AddVertex0(drawArea[2] + 10 * globalRendering->pixelX, drawArea[3] + 20 * globalRendering->pixelY, 0.0f); va->AddVertex0(drawArea[2] + 10 * globalRendering->pixelX, drawArea[1] - 10 * globalRendering->pixelY, 0.0f); glColor4f(0.0f,0.0f,0.0f, 0.5f); va->DrawArray0(GL_QUADS); // title and legend font->glFormat(drawArea[0], drawArea[3] + 10 * globalRendering->pixelY, 0.7f, FONT_TOP | DBG_FONT_FLAGS, "Frame Grapher (%.2fsec)" "\xff\xff\x80\xff GC" "\xff\xff\xff\x01 Unsynced" "\xff\x01\x01\xff Swap" "\xff\x01\xff\x01 Video" "\xff\xff\x01\x01 Sim" , maxHist_f); // gc frames glColor4f(1.0f,0.5f,1.0f, 0.55f); DrawTimeSlice(lgcFrames, curTime, maxHist, drawArea); // updateunsynced frames glColor4f(1.0f,1.0f,0.0f, 0.9f); DrawTimeSlice(uusFrames, curTime, maxHist, drawArea); // video swap frames glColor4f(0.0f,0.0f,1.0f, 0.55f); DrawTimeSlice(swpFrames, curTime, maxHist, drawArea); // video frames glColor4f(0.0f,1.0f,0.0f, 0.55f); DrawTimeSlice(vidFrames, curTime, maxHist, drawArea); // sim frames glColor4f(1.0f,0.0f,0.0f, 0.55f); DrawTimeSlice(simFrames, curTime, maxHist, drawArea); // draw `feeder` indicating current time pos //CVertexArray* va = GetVertexArray(); va->Initialize(); // draw feeder const float r = (curTime % maxHist).toSecsf() / maxHist_f; const float xf = drawArea[0] + r * (drawArea[2] - drawArea[0]); va->AddVertex0(xf, drawArea[1], 0.0f); va->AddVertex0(xf, drawArea[3], 0.0f); va->AddVertex0(xf + 10 * globalRendering->pixelX, drawArea[3], 0.0f); va->AddVertex0(xf + 10 * globalRendering->pixelX, drawArea[1], 0.0f); // draw scale (horizontal bar that indicates 30FPS timing length) const float xs1 = drawArea[2] - 1.f/(30.f*maxHist_f) * (drawArea[2] - drawArea[0]); const float xs2 = drawArea[2] + 0.0f * (drawArea[2] - drawArea[0]); va->AddVertex0(xs1, drawArea[3] + 2 * globalRendering->pixelY, 0.0f); va->AddVertex0(xs1, drawArea[3] + 10 * globalRendering->pixelY, 0.0f); va->AddVertex0(xs2, drawArea[3] + 10 * globalRendering->pixelY, 0.0f); va->AddVertex0(xs2, drawArea[3] + 2 * globalRendering->pixelY, 0.0f); glColor4f(1.0f,0.0f,0.0f, 1.0f); va->DrawArray0(GL_QUADS); }