diff --git a/OverlayDDU.h b/OverlayDDU.h index dae941f..34c6dec 100644 --- a/OverlayDDU.h +++ b/OverlayDDU.h @@ -524,7 +524,7 @@ class OverlayDDU : public Overlay float val = avgPerLap; if( imperial ) val *= 0.264172f; - swprintf( s, _countof(s), imperial ? L"%.1f gl" : L"%.2f lt", val ); + swprintf( s, _countof(s), imperial ? L"%.1f gl" : L"%.1f lt", val ); m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), m_boxFuel.x0, m_boxFuel.x1-xoff, m_boxFuel.y0+m_boxFuel.h*6.9f/12.0f, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING ); } @@ -641,7 +641,7 @@ class OverlayDDU : public Overlay // Incidents { - const int inc = ir_PlayerCarTeamIncidentCount.getInt(); + const int inc = ir_PlayerCarMyIncidentCount.getInt(); swprintf( s, _countof(s), L"%dx", inc ); m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), m_boxInc.x0, m_boxInc.x1, m_boxInc.y0+m_boxInc.h*0.5f, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_CENTER ); } diff --git a/OverlayRelative.h b/OverlayRelative.h index 75e3e1f..81a3fb7 100644 --- a/OverlayRelative.h +++ b/OverlayRelative.h @@ -42,7 +42,7 @@ class OverlayRelative : public Overlay protected: - enum class Columns { POSITION, CAR_NUMBER, NAME, DELTA, LICENSE, SAFETY_RATING, IRATING, PIT, LAST }; + enum class Columns { POSITION, CAR_NUMBER, NAME, DELTA, LICENSE, SAFETY_RATING, IRATING, PIT }; virtual void onEnable() { @@ -74,6 +74,7 @@ class OverlayRelative : public Overlay m_columns.add( (int)Columns::POSITION, computeTextExtent( L"P99", m_dwriteFactory.Get(), m_textFormat.Get() ).x, fontSize/2 ); m_columns.add( (int)Columns::CAR_NUMBER, computeTextExtent( L"#999", m_dwriteFactory.Get(), m_textFormat.Get() ).x, fontSize/2 ); m_columns.add( (int)Columns::NAME, 0, fontSize/2 ); + m_columns.add( (int)Columns::DELTA, computeTextExtent( L"+99L -99.9", m_dwriteFactory.Get(), m_textFormat.Get() ).x, 1, fontSize/2 ); if( g_cfg.getBool(m_name,"show_pit_age",true) ) m_columns.add( (int)Columns::PIT, computeTextExtent( L"999", m_dwriteFactory.Get(), m_textFormatSmall.Get() ).x, fontSize/4 ); @@ -83,10 +84,6 @@ class OverlayRelative : public Overlay m_columns.add( (int)Columns::SAFETY_RATING, computeTextExtent( L"A 4.44", m_dwriteFactory.Get(), m_textFormatSmall.Get() ).x, fontSize/8 ); if( g_cfg.getBool(m_name,"show_irating",true) ) m_columns.add( (int)Columns::IRATING, computeTextExtent( L"999.9k", m_dwriteFactory.Get(), m_textFormatSmall.Get() ).x, fontSize/8 ); - - m_columns.add((int)Columns::LAST, computeTextExtent(L"999.99.999", m_dwriteFactory.Get(), m_textFormat.Get()).x, fontSize / 2); - - m_columns.add((int)Columns::DELTA, computeTextExtent(L"+99L -99.9", m_dwriteFactory.Get(), m_textFormat.Get()).x, 1, fontSize / 2); } virtual void onUpdate() @@ -96,7 +93,6 @@ class OverlayRelative : public Overlay float delta = 0; int lapDelta = 0; int pitAge = 0; - float last = 0; }; std::vector relatives; relatives.reserve( IR_MAX_CARS ); @@ -151,7 +147,6 @@ class OverlayRelative : public Overlay ci.delta = delta; ci.lapDelta = lapDelta; ci.pitAge = ir_CarIdxLap.getInt(i) - car.lastLapInPits; - ci.last = ir_CarIdxLastLapTime.getFloat(i); relatives.push_back( ci ); } } @@ -237,7 +232,6 @@ class OverlayRelative : public Overlay col.a *= 0.5f; wchar_t s[512]; - std::string str; D2D1_RECT_F r = {}; D2D1_ROUNDED_RECT rr = {}; const ColumnLayout::Column* clm = nullptr; @@ -260,9 +254,7 @@ class OverlayRelative : public Overlay rr.rect = { r.left-2, r.top+1, r.right+2, r.bottom-1 }; rr.radiusX = 3; rr.radiusY = 3; - float4 color = car.classCol; - color.a = licenseBgAlpha; - m_brush->SetColor( car.isSelf ? color : (car.isBuddy ? buddyCol : (car.isFlagged?flaggedCol: color)) ); + m_brush->SetColor( car.isSelf ? selfCol : (car.isBuddy ? buddyCol : (car.isFlagged?flaggedCol:carNumberBgCol)) ); m_renderTarget->FillRoundedRectangle( &rr, m_brush.Get() ); m_brush->SetColor( carNumberTextCol ); m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_CENTER ); @@ -276,6 +268,17 @@ class OverlayRelative : public Overlay m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_LEADING ); } + // Delta + { + clm = m_columns.get( (int)Columns::DELTA ); + if( ci.lapDelta ) + swprintf( s, _countof(s), L"%+dL %.1f", ci.lapDelta, ci.delta ); + else + swprintf( s, _countof(s), L"%.1f", ci.delta ); + m_brush->SetColor( col ); + m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING ); + } + // Pit age if( (clm = m_columns.get((int)Columns::PIT)) && !ir_isPreStart() && (ci.pitAge>=0||ir_CarIdxOnPitRoad.getBool(ci.carIdx)) ) { @@ -339,50 +342,8 @@ class OverlayRelative : public Overlay m_brush->SetColor( iratingTextCol ); m_text.render( m_renderTarget.Get(), s, m_textFormatSmall.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_CENTER ); } - - // Last - { - clm = m_columns.get((int)Columns::LAST); - str.clear(); - if (ci.last > 0) - str = formatLaptime(ci.last); - m_brush->SetColor(col); - m_text.render(m_renderTarget.Get(), toWide(str).c_str(), m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - } - - // Delta - { - clm = m_columns.get((int)Columns::DELTA); - swprintf(s, _countof(s), L"%.1f", ci.delta); - m_brush->SetColor(col); - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - } } - /* // Footer - { - float trackTemp = ir_TrackTempCrew.getFloat(); - char tempUnit = 'C'; - - double sessionTime = ir_SessionTimeRemain.getDouble(); - int laps = std::max(ir_CarIdxLap.getInt(ir_session.driverCarIdx), ir_CarIdxLapCompleted.getInt(ir_session.driverCarIdx)); - - const bool sessionIsTimeLimited = ir_SessionLapsTotal.getInt() == 32767 && ir_SessionTimeRemain.getDouble() < 48.0 * 3600.0; // most robust way I could find to figure out whether this is a time-limited session (info in session string is often misleading) - const int remainingLaps = sessionIsTimeLimited ? int(0.5 + sessionTime / ir_estimateLaptime()) : (ir_SessionLapsRemainEx.getInt() != 32767 ? ir_SessionLapsRemainEx.getInt() : -1); - - const int hours = int(sessionTime / 3600.0); - const int mins = int(sessionTime / 60.0) % 60; - const int secs = (int)fmod(sessionTime, 60.0); - - m_brush->SetColor(float4(1, 1, 1, 0.4f)); - m_renderTarget->DrawLine(float2(0, ybottom), float2((float)m_width, ybottom), m_brush.Get()); - swprintf(s, _countof(s), L"SoF: %d Track Temp: %.1f°%c Session end: %d:%02d:%02d Laps: %d/%d", ir_session.sof, trackTemp, tempUnit, hours, mins, secs, laps, remainingLaps); - y = m_height - (m_height - ybottom) / 2; - m_brush->SetColor(headerCol); - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff, (float)m_width - 2 * xoff, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_CENTER); - } - */ - // Minimap if( minimapEnabled ) { @@ -456,12 +417,6 @@ class OverlayRelative : public Overlay m_renderTarget->EndDraw(); } - - virtual bool canEnableWhileNotDriving() const - { - return true; - } - protected: Microsoft::WRL::ComPtr m_textFormat; diff --git a/OverlayStandings.h b/OverlayStandings.h index e23b603..ae02341 100644 --- a/OverlayStandings.h +++ b/OverlayStandings.h @@ -1,4 +1,4 @@ -/* +/* MIT License Copyright (c) 2021-2022 L. E. Spalt @@ -29,35 +29,17 @@ SOFTWARE. #include "Config.h" #include "OverlayDebug.h" -using namespace std; - class OverlayStandings : public Overlay { public: const float DefaultFontSize = 15; - const int defaultNumTopDrivers = 3; - const int defaultNumAheadDrivers = 5; - const int defaultNumBehindDrivers = 5; - enum class Columns { POSITION, CAR_NUMBER, NAME, GAP, BEST, LAST, LICENSE, IRATING, CAR_BRAND, PIT, DELTA, L5, POSITIONS_GAINED }; + enum class Columns { POSITION, CAR_NUMBER, NAME, DELTA, BEST, LAST, LICENSE, IRATING, PIT }; - OverlayStandings(map mapa) + OverlayStandings() : Overlay("OverlayStandings") - { - avgL5Times.reserve(IR_MAX_CARS); - - for (int i = 0; i < IR_MAX_CARS; ++i) { - avgL5Times.emplace_back(); - avgL5Times[i].reserve(5); - - for (int j = 0; j < 5; ++j) { - avgL5Times[i].push_back(0.0); - } - } - - this->mapa = mapa; - } + {} protected: @@ -75,7 +57,7 @@ class OverlayStandings : public Overlay { m_text.reset( m_dwriteFactory.Get() ); - const string font = g_cfg.getString( m_name, "font", "Microsoft YaHei UI" ); + const std::string font = g_cfg.getString( m_name, "font", "Microsoft YaHei UI" ); const float fontSize = g_cfg.getFloat( m_name, "font_size", DefaultFontSize ); const int fontWeight = g_cfg.getInt( m_name, "font_weight", 500 ); HRCHECK(m_dwriteFactory->CreateTextFormat( toWide(font).c_str(), NULL, (DWRITE_FONT_WEIGHT)fontWeight, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, fontSize, L"en-us", &m_textFormat )); @@ -94,167 +76,76 @@ class OverlayStandings : public Overlay m_columns.add( (int)Columns::PIT, computeTextExtent( L"P.Age", m_dwriteFactory.Get(), m_textFormat.Get() ).x, fontSize/2 ); m_columns.add( (int)Columns::LICENSE, computeTextExtent( L"A 4.44", m_dwriteFactory.Get(), m_textFormatSmall.Get() ).x, fontSize/6 ); m_columns.add( (int)Columns::IRATING, computeTextExtent( L"999.9k", m_dwriteFactory.Get(), m_textFormatSmall.Get() ).x, fontSize/6 ); - - if (g_cfg.getBool(m_name, "show_car_brand", true)) - m_columns.add( (int)Columns::CAR_BRAND, 30, fontSize / 2); - - m_columns.add( (int)Columns::POSITIONS_GAINED, computeTextExtent(L"↑6", m_dwriteFactory.Get(), m_textFormat.Get()).x, fontSize / 2); - m_columns.add( (int)Columns::GAP, computeTextExtent(L"9999.9", m_dwriteFactory.Get(), m_textFormat.Get()).x, fontSize / 2 ); m_columns.add( (int)Columns::BEST, computeTextExtent( L"999.99.999", m_dwriteFactory.Get(), m_textFormat.Get() ).x, fontSize/2 ); - - if (g_cfg.getBool(m_name, "show_lap_time", true)) - m_columns.add( (int)Columns::LAST, computeTextExtent( L"999.99.999", m_dwriteFactory.Get(), m_textFormat.Get() ).x, fontSize/2 ); - - if (g_cfg.getBool(m_name, "show_delta", true)) - m_columns.add( (int)Columns::DELTA, computeTextExtent( L"99.99", m_dwriteFactory.Get(), m_textFormat.Get() ).x, fontSize/2 ); - - if (g_cfg.getBool(m_name, "show_L5", false)) - m_columns.add( (int)Columns::L5, computeTextExtent(L"999.99.999", m_dwriteFactory.Get(), m_textFormat.Get()).x, fontSize / 2 ); + m_columns.add( (int)Columns::LAST, computeTextExtent( L"999.99.999", m_dwriteFactory.Get(), m_textFormat.Get() ).x, fontSize/2 ); + m_columns.add( (int)Columns::DELTA, computeTextExtent( L"9999.9999", m_dwriteFactory.Get(), m_textFormat.Get() ).x, fontSize/2 ); } virtual void onUpdate() { struct CarInfo { int carIdx = 0; - int classIdx = 0; int lapCount = 0; float pctAroundLap = 0; - int lapGap = 0; - float gap = 0; + int lapDelta = 0; float delta = 0; int position = 0; float best = 0; float last = 0; - float l5 = 0; bool hasFastestLap = false; int pitAge = 0; - int positionsChanged = 0; - }; - - struct classBestLap { - int carIdx = -1; - float best = FLT_MAX; }; - - vector carInfo; + std::vector carInfo; carInfo.reserve( IR_MAX_CARS ); // Init array - map bestLapClass; - int selfPosition = ir_getPosition(ir_session.driverCarIdx); - boolean hasPacecar = false; - + float fastestLapTime = FLT_MAX; + int fastestLapIdx = -1; for( int i=0; i 0 && ci.best < bestLapClass[ci.classIdx].best) { - bestLapClass[ci.classIdx].best = ci.best; - bestLapClass[ci.classIdx].carIdx = hasPacecar ? ci.carIdx - 1 : ci.carIdx; + if( ci.best > 0 && ci.best < fastestLapTime ) { + fastestLapTime = ci.best; + fastestLapIdx = (int)carInfo.size()-1; } - - if(ci.lapCount > 0) - avgL5Times[ci.carIdx][ci.lapCount % 5] = ci.last; - - float total = 0; - int conteo = 0; - for (float time : avgL5Times[ci.carIdx]) { - if (time > 0.0) { - total += time; - conteo++; - } - } - - ci.l5 = conteo ? total / conteo : 0.0F; - - carInfo.push_back(ci); } - for (const auto& pair : bestLapClass) - { - if (pair.second.best > 0 && pair.second.carIdx >= 0) - carInfo[pair.second.carIdx].hasFastestLap = true; - string str = formatLaptime(pair.second.best); - } + if( fastestLapIdx >= 0 ) + carInfo[fastestLapIdx].hasFastestLap = true; - const CarInfo ciSelf = carInfo[ir_PlayerCarIdx.getInt() > 0 ? hasPacecar ? ir_PlayerCarIdx.getInt() - 1 : ir_PlayerCarIdx.getInt() : 0]; - // Sort by position - sort( carInfo.begin(), carInfo.end(), + std::sort( carInfo.begin(), carInfo.end(), []( const CarInfo& a, const CarInfo& b ) { const int ap = a.position<=0 ? INT_MAX : a.position; const int bp = b.position<=0 ? INT_MAX : b.position; return ap < bp; } ); - map classLider; - - for (const CarInfo& car : carInfo) { - if (car.position > 1) break; - classLider.insert_or_assign(car.classIdx, car.carIdx); - } - - // Compute lap gap to leader and compute delta + // Compute lap deltas to leader for( int i=0; i<(int)carInfo.size(); ++i ) { + const CarInfo& ciLeader = carInfo[0]; CarInfo& ci = carInfo[i]; - ci.lapGap = ir_getLapDeltaToLeader( ci.carIdx, classLider[ci.classIdx]); - ci.delta = ir_getDeltaTime( ci.carIdx, ir_session.driverCarIdx ); - - if (ir_session.sessionType != SessionType::RACE) { - ci.gap = ir_CarIdxF2Time.getFloat(ci.carIdx) - ir_CarIdxF2Time.getFloat(classLider[ci.classIdx]); - ci.gap = ci.gap < 0 ? 0 : ci.gap; - } + ci.lapDelta = ir_getLapDeltaToLeader( ci.carIdx, ciLeader.carIdx ); } const float fontSize = g_cfg.getFloat( m_name, "font_size", DefaultFontSize ); @@ -272,12 +163,7 @@ class OverlayStandings : public Overlay const float4 licenseTextCol = g_cfg.getFloat4( m_name, "license_text_col", float4(1,1,1,0.9f) ); const float4 fastestLapCol = g_cfg.getFloat4( m_name, "fastest_lap_col", float4(1,0,1,1) ); const float4 pitCol = g_cfg.getFloat4( m_name, "pit_col", float4(0.94f,0.8f,0.13f,1) ); - const float4 deltaPosCol = g_cfg.getFloat4( m_name, "delta_positive_col", float4(0.0f, 1.0f, 0.0f, 1.0f)); - const float4 deltaNegCol = g_cfg.getFloat4( m_name, "delta_negative_col", float4(1.0f, 0.0f, 0.0f, 1.0f)); const float licenseBgAlpha = g_cfg.getFloat( m_name, "license_background_alpha", 0.8f ); - const int numTopDrivers = g_cfg.getInt(m_name, "num_top_drivers", defaultNumTopDrivers); - const int numAheadDrivers = g_cfg.getInt(m_name, "num_ahead_drivers", defaultNumAheadDrivers); - const int numBehindDrivers = g_cfg.getInt(m_name, "num_behind_drivers", defaultNumBehindDrivers); const bool imperial = ir_DisplayUnits.getInt() == 0; const float xoff = 10.0f; @@ -288,7 +174,7 @@ class OverlayStandings : public Overlay const ColumnLayout::Column* clm = nullptr; wchar_t s[512]; - string str; + std::string str; D2D1_RECT_F r = {}; D2D1_ROUNDED_RECT rr = {}; @@ -320,65 +206,28 @@ class OverlayStandings : public Overlay swprintf( s, _countof(s), L"IR" ); m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_CENTER ); - if (clm = m_columns.get((int)Columns::CAR_BRAND)) { - swprintf(s, _countof(s), L" "); - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - } - - clm = m_columns.get((int)Columns::POSITIONS_GAINED); - swprintf(s, _countof(s), L" "); - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_CENTER); - - clm = m_columns.get((int)Columns::GAP); - swprintf(s, _countof(s), L"Gap"); - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - clm = m_columns.get( (int)Columns::BEST ); swprintf( s, _countof(s), L"Best" ); m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING ); - if (clm = m_columns.get( (int)Columns::LAST ) ) { - swprintf(s, _countof(s), L"Last"); - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - } - - if (clm = m_columns.get((int)Columns::DELTA)) { - swprintf(s, _countof(s), L"Delta"); - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - } + clm = m_columns.get( (int)Columns::LAST ); + swprintf( s, _countof(s), L"Last" ); + m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING ); - if (clm = m_columns.get((int)Columns::L5)) { - swprintf(s, _countof(s), L"Last 5 avg"); - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - } + clm = m_columns.get( (int)Columns::DELTA ); + swprintf( s, _countof(s), L"Delta" ); + m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING ); // Content - int drawnCars = 0; - int selfClassDrivers = 0; for( int i=0; i<(int)carInfo.size(); ++i ) { - y = 2*yoff + lineHeight/2 + (drawnCars+1)*lineHeight; - - if (ir_CarIdxClass.getInt(carInfo[i].carIdx) != ir_PlayerCarClass.getInt()) { - continue; - } - - selfClassDrivers++; + y = 2*yoff + lineHeight/2 + (i+1)*lineHeight; if( y+lineHeight/2 > ybottom ) break; - // Focus on the driver - if (selfClassDrivers == selfPosition - numAheadDrivers - 2) - drawnCars++; - - if (selfPosition > 0 && selfClassDrivers >= numTopDrivers && (selfClassDrivers < selfPosition - numAheadDrivers - 1 || selfClassDrivers > selfPosition + numBehindDrivers - 1)) - continue; - - drawnCars++; - // Alternating line backgrounds - if(selfClassDrivers & 1 && alternateLineBgCol.a > 0 ) + if( i & 1 && alternateLineBgCol.a > 0 ) { D2D1_RECT_F r = { 0, y-lineHeight/2, (float)m_width, y+lineHeight/2 }; m_brush->SetColor( alternateLineBgCol ); @@ -423,7 +272,7 @@ class OverlayStandings : public Overlay { clm = m_columns.get( (int)Columns::NAME ); m_brush->SetColor( textCol ); - swprintf( s, _countof(s), L"%S", car.teamName.c_str() ); + swprintf( s, _countof(s), L"%S", car.userName.c_str() ); m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_LEADING ); } @@ -476,140 +325,54 @@ class OverlayStandings : public Overlay m_text.render( m_renderTarget.Get(), s, m_textFormatSmall.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_CENTER ); } - // Car brand - if (clm = m_columns.get((int)Columns::CAR_BRAND)) - { - string carNameLowerCase = toLowerCase(car.carName); - - IWICFormatConverter* valor = findAndDrawCar(carNameLowerCase, mapa); //Valor por defecto si no se encuentra el coche en el mapa - - if (valor != nullptr) { - ID2D1Bitmap* pBitmap = NULL; - m_renderTarget->CreateBitmapFromWicBitmap(valor, nullptr, &pBitmap); - D2D1_RECT_F r = { xoff + clm->textL, y - lineHeight / 2, xoff + clm->textR, y + lineHeight / 2 }; - m_renderTarget->DrawBitmap(pBitmap, r); - pBitmap->Release(); - } - else { - std::cout << "No se encontró el coche '" << car.carName << "' en el mapa." << std::endl; - } - - } - - // Positions gained - { - clm = m_columns.get((int)Columns::POSITIONS_GAINED); - - if (ci.positionsChanged == 0) { - swprintf(s, _countof(s), L"-"); - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - } - else { - if (ci.positionsChanged > 0) { - swprintf(s, _countof(s), L"â–²"); - m_brush->SetColor(deltaPosCol); - } - else { - swprintf(s, _countof(s), L"â–¼"); - m_brush->SetColor(deltaNegCol); - } - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - - m_brush->SetColor(textCol); - swprintf(s, _countof(s), L"%d", abs(ci.positionsChanged)); - - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, 17 + xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - } - - } - - // Gap - if (ci.lapGap || ci.gap) - { - clm = m_columns.get((int)Columns::GAP); - if (ci.lapGap < 0) - swprintf(s, _countof(s), L"%d L", ci.lapGap); - else - swprintf(s, _countof(s), L"%.01f", ci.gap); - m_brush->SetColor(textCol); - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - } - // Best { clm = m_columns.get( (int)Columns::BEST ); str.clear(); if( ci.best > 0 ) str = formatLaptime( ci.best ); - m_brush->SetColor( ci.hasFastestLap ? fastestLapCol : textCol); + m_brush->SetColor( ci.hasFastestLap ? fastestLapCol : otherCarCol ); m_text.render( m_renderTarget.Get(), toWide(str).c_str(), m_textFormat.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING ); } // Last - if (clm = m_columns.get((int)Columns::LAST)) { + clm = m_columns.get( (int)Columns::LAST ); str.clear(); if( ci.last > 0 ) str = formatLaptime( ci.last ); - m_brush->SetColor(textCol); + m_brush->SetColor( otherCarCol ); m_text.render( m_renderTarget.Get(), toWide(str).c_str(), m_textFormat.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING ); } // Delta - if (clm = m_columns.get((int)Columns::DELTA)) - { - if (ci.delta) - { - swprintf(s, _countof(s), L"%.01f", abs(ci.delta)); - if (ci.delta > 0) - m_brush->SetColor(deltaPosCol); - else - m_brush->SetColor(deltaNegCol); - m_text.render(m_renderTarget.Get(), s, m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); - } - } - - // Average 5 laps - if (clm = m_columns.get((int)Columns::L5)) + if( ci.lapDelta || ci.delta ) { - str.clear(); - if (ci.l5 > 0 && selfPosition > 0) { - str = formatLaptime(ci.l5); - if (ci.l5 >= ciSelf.l5) - m_brush->SetColor(deltaPosCol); - else - m_brush->SetColor(deltaNegCol); - } + clm = m_columns.get( (int)Columns::DELTA ); + if( ci.lapDelta < 0 ) + swprintf( s, _countof(s), L"%d L", ci.lapDelta ); else - m_brush->SetColor(textCol); - - m_text.render(m_renderTarget.Get(), toWide(str).c_str(), m_textFormat.Get(), xoff + clm->textL, xoff + clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING); + swprintf( s, _countof(s), L"%.03f", ci.delta ); + m_brush->SetColor( otherCarCol ); + m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), xoff+clm->textL, xoff+clm->textR, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_TRAILING ); } } // Footer { float trackTemp = ir_TrackTempCrew.getFloat(); + float airTemp = ir_AirTemp.getFloat(); char tempUnit = 'C'; if( imperial ) { trackTemp = celsiusToFahrenheit( trackTemp ); + airTemp = celsiusToFahrenheit( airTemp ); tempUnit = 'F'; } - int hours, mins, secs; - - ir_getSessionTimeRemaining(hours, mins, secs); - const int laps = max(ir_CarIdxLap.getInt(ir_session.driverCarIdx), ir_CarIdxLapCompleted.getInt(ir_session.driverCarIdx)); - const int remainingLaps = ir_getLapsRemaining(); - int totalLaps = remainingLaps; - - if (ir_SessionLapsTotal.getInt() == 32767) - totalLaps = laps + remainingLaps; - m_brush->SetColor(float4(1,1,1,0.4f)); m_renderTarget->DrawLine( float2(0,ybottom),float2((float)m_width,ybottom),m_brush.Get() ); - swprintf( s, _countof(s), L"SoF: %d Track Temp: %.1f°%c Session end: %d:%02d:%02d Laps: %d/~%d", ir_session.sof, trackTemp, tempUnit, hours, mins, secs, laps, totalLaps); + swprintf( s, _countof(s), L"SoF: %d Track Temp: %.1f°%c Air Temp: %.1f°%c Setup: %s Subsession: %d", ir_session.sof, trackTemp, tempUnit, airTemp, tempUnit, ir_session.isFixedSetup?L"fixed":L"open", ir_session.subsessionId ); y = m_height - (m_height-ybottom)/2; m_brush->SetColor( headerCol ); m_text.render( m_renderTarget.Get(), s, m_textFormat.Get(), xoff, (float)m_width-2*xoff, y, m_brush.Get(), DWRITE_TEXT_ALIGNMENT_CENTER ); @@ -630,6 +393,4 @@ class OverlayStandings : public Overlay ColumnLayout m_columns; TextCache m_text; - vector> avgL5Times; - map mapa; }; diff --git a/README.md b/README.md index 185fffd..26a12a9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# iRon - lightweight overlays for iRacing (OUTDATED) +# iRon - lightweight overlays for iRacing This project provides a few lightweight overlays for iRacing. Included are: a relative display with optional minimap, a dashboard with fuel calculator, a throttle/brake input graph, and a standings display. diff --git a/carIcons/Alpha_Romeo.png b/carIcons/Alpha_Romeo.png deleted file mode 100644 index 21db7be..0000000 Binary files a/carIcons/Alpha_Romeo.png and /dev/null differ diff --git a/carIcons/Alpine_modern.png b/carIcons/Alpine_modern.png deleted file mode 100644 index 55f35c2..0000000 Binary files a/carIcons/Alpine_modern.png and /dev/null differ diff --git a/carIcons/Aston_Martin.png b/carIcons/Aston_Martin.png deleted file mode 100644 index 40e89b0..0000000 Binary files a/carIcons/Aston_Martin.png and /dev/null differ diff --git a/carIcons/Audi.png b/carIcons/Audi.png deleted file mode 100644 index f962e4f..0000000 Binary files a/carIcons/Audi.png and /dev/null differ diff --git a/carIcons/BMW.png b/carIcons/BMW.png deleted file mode 100644 index 6747286..0000000 Binary files a/carIcons/BMW.png and /dev/null differ diff --git a/carIcons/Bugatti.png b/carIcons/Bugatti.png deleted file mode 100644 index 4088aa3..0000000 Binary files a/carIcons/Bugatti.png and /dev/null differ diff --git a/carIcons/Cadillac.png b/carIcons/Cadillac.png deleted file mode 100644 index 74b920a..0000000 Binary files a/carIcons/Cadillac.png and /dev/null differ diff --git a/carIcons/Chevrolet.png b/carIcons/Chevrolet.png deleted file mode 100644 index cba9bf7..0000000 Binary files a/carIcons/Chevrolet.png and /dev/null differ diff --git a/carIcons/Citroen.png b/carIcons/Citroen.png deleted file mode 100644 index e5e5d94..0000000 Binary files a/carIcons/Citroen.png and /dev/null differ diff --git a/carIcons/Corvette.png b/carIcons/Corvette.png deleted file mode 100644 index 1bf2182..0000000 Binary files a/carIcons/Corvette.png and /dev/null differ diff --git a/carIcons/Crysler.png b/carIcons/Crysler.png deleted file mode 100644 index d140d3b..0000000 Binary files a/carIcons/Crysler.png and /dev/null differ diff --git a/carIcons/DS.png b/carIcons/DS.png deleted file mode 100644 index 48096f7..0000000 Binary files a/carIcons/DS.png and /dev/null differ diff --git a/carIcons/Dacia.png b/carIcons/Dacia.png deleted file mode 100644 index c7c10a1..0000000 Binary files a/carIcons/Dacia.png and /dev/null differ diff --git a/carIcons/Dallara.png b/carIcons/Dallara.png deleted file mode 100644 index 9253cdb..0000000 Binary files a/carIcons/Dallara.png and /dev/null differ diff --git a/carIcons/FIAT.png b/carIcons/FIAT.png deleted file mode 100644 index 1ae26ce..0000000 Binary files a/carIcons/FIAT.png and /dev/null differ diff --git a/carIcons/Ferrari.png b/carIcons/Ferrari.png deleted file mode 100644 index 3633f5d..0000000 Binary files a/carIcons/Ferrari.png and /dev/null differ diff --git a/carIcons/Ford.png b/carIcons/Ford.png deleted file mode 100644 index b01291f..0000000 Binary files a/carIcons/Ford.png and /dev/null differ diff --git a/carIcons/Hudson.png b/carIcons/Hudson.png deleted file mode 100644 index e02e4a4..0000000 Binary files a/carIcons/Hudson.png and /dev/null differ diff --git a/carIcons/Hyundai.png b/carIcons/Hyundai.png deleted file mode 100644 index 613e1a7..0000000 Binary files a/carIcons/Hyundai.png and /dev/null differ diff --git a/carIcons/Infiniti.png b/carIcons/Infiniti.png deleted file mode 100644 index d77c27a..0000000 Binary files a/carIcons/Infiniti.png and /dev/null differ diff --git a/carIcons/Jaguar.png b/carIcons/Jaguar.png deleted file mode 100644 index 9ccb0ed..0000000 Binary files a/carIcons/Jaguar.png and /dev/null differ diff --git a/carIcons/Jeep.png b/carIcons/Jeep.png deleted file mode 100644 index b4c05db..0000000 Binary files a/carIcons/Jeep.png and /dev/null differ diff --git a/carIcons/Kia.png b/carIcons/Kia.png deleted file mode 100644 index 825da6e..0000000 Binary files a/carIcons/Kia.png and /dev/null differ diff --git a/carIcons/Lamborghini.png b/carIcons/Lamborghini.png deleted file mode 100644 index e501a20..0000000 Binary files a/carIcons/Lamborghini.png and /dev/null differ diff --git a/carIcons/Land_Rover.png b/carIcons/Land_Rover.png deleted file mode 100644 index 3768e9a..0000000 Binary files a/carIcons/Land_Rover.png and /dev/null differ diff --git a/carIcons/Lexus.png b/carIcons/Lexus.png deleted file mode 100644 index 3f279cf..0000000 Binary files a/carIcons/Lexus.png and /dev/null differ diff --git a/carIcons/Ligier.png b/carIcons/Ligier.png deleted file mode 100644 index ce0baf5..0000000 Binary files a/carIcons/Ligier.png and /dev/null differ diff --git a/carIcons/Lotus.png b/carIcons/Lotus.png deleted file mode 100644 index 65f169c..0000000 Binary files a/carIcons/Lotus.png and /dev/null differ diff --git a/carIcons/Maserati.png b/carIcons/Maserati.png deleted file mode 100644 index bdef994..0000000 Binary files a/carIcons/Maserati.png and /dev/null differ diff --git a/carIcons/Mazda.png b/carIcons/Mazda.png deleted file mode 100644 index 098ce97..0000000 Binary files a/carIcons/Mazda.png and /dev/null differ diff --git a/carIcons/McLaren.png b/carIcons/McLaren.png deleted file mode 100644 index 0c35675..0000000 Binary files a/carIcons/McLaren.png and /dev/null differ diff --git a/carIcons/Mercedes.png b/carIcons/Mercedes.png deleted file mode 100644 index 51a2c34..0000000 Binary files a/carIcons/Mercedes.png and /dev/null differ diff --git a/carIcons/Mini.png b/carIcons/Mini.png deleted file mode 100644 index 870cb02..0000000 Binary files a/carIcons/Mini.png and /dev/null differ diff --git a/carIcons/Mitsubishi.png b/carIcons/Mitsubishi.png deleted file mode 100644 index d466727..0000000 Binary files a/carIcons/Mitsubishi.png and /dev/null differ diff --git a/carIcons/Mustang.png b/carIcons/Mustang.png deleted file mode 100644 index dd09ce1..0000000 Binary files a/carIcons/Mustang.png and /dev/null differ diff --git a/carIcons/Nismo-1.png b/carIcons/Nismo-1.png deleted file mode 100644 index a7639c4..0000000 Binary files a/carIcons/Nismo-1.png and /dev/null differ diff --git a/carIcons/Opel.png b/carIcons/Opel.png deleted file mode 100644 index 396a5d2..0000000 Binary files a/carIcons/Opel.png and /dev/null differ diff --git a/carIcons/Peugeot.png b/carIcons/Peugeot.png deleted file mode 100644 index 6cee284..0000000 Binary files a/carIcons/Peugeot.png and /dev/null differ diff --git a/carIcons/Pontiac.png b/carIcons/Pontiac.png deleted file mode 100644 index 755b179..0000000 Binary files a/carIcons/Pontiac.png and /dev/null differ diff --git a/carIcons/Porsche.png b/carIcons/Porsche.png deleted file mode 100644 index 334eb08..0000000 Binary files a/carIcons/Porsche.png and /dev/null differ diff --git a/carIcons/Radical.png b/carIcons/Radical.png deleted file mode 100644 index 02b6a30..0000000 Binary files a/carIcons/Radical.png and /dev/null differ diff --git a/carIcons/Renault.png b/carIcons/Renault.png deleted file mode 100644 index febc1f4..0000000 Binary files a/carIcons/Renault.png and /dev/null differ diff --git a/carIcons/Rolce_Royce.png b/carIcons/Rolce_Royce.png deleted file mode 100644 index 2bf63ed..0000000 Binary files a/carIcons/Rolce_Royce.png and /dev/null differ diff --git a/carIcons/Sauber.png b/carIcons/Sauber.png deleted file mode 100644 index 155afaa..0000000 Binary files a/carIcons/Sauber.png and /dev/null differ diff --git a/carIcons/Scoda.png b/carIcons/Scoda.png deleted file mode 100644 index f88089b..0000000 Binary files a/carIcons/Scoda.png and /dev/null differ diff --git a/carIcons/Seat.png b/carIcons/Seat.png deleted file mode 100644 index 44369ed..0000000 Binary files a/carIcons/Seat.png and /dev/null differ diff --git a/carIcons/Subaru.png b/carIcons/Subaru.png deleted file mode 100644 index 4daa308..0000000 Binary files a/carIcons/Subaru.png and /dev/null differ diff --git a/carIcons/Suzuki.png b/carIcons/Suzuki.png deleted file mode 100644 index 77fad8c..0000000 Binary files a/carIcons/Suzuki.png and /dev/null differ diff --git a/carIcons/Tesla.png b/carIcons/Tesla.png deleted file mode 100644 index 55b941f..0000000 Binary files a/carIcons/Tesla.png and /dev/null differ diff --git a/carIcons/Toyota.png b/carIcons/Toyota.png deleted file mode 100644 index bea5b5d..0000000 Binary files a/carIcons/Toyota.png and /dev/null differ diff --git a/carIcons/VW.png b/carIcons/VW.png deleted file mode 100644 index 91d1301..0000000 Binary files a/carIcons/VW.png and /dev/null differ diff --git a/carIcons/Volvo.png b/carIcons/Volvo.png deleted file mode 100644 index 3f78167..0000000 Binary files a/carIcons/Volvo.png and /dev/null differ diff --git a/iracing.cpp b/iracing.cpp index 8c34379..114c5c1 100644 --- a/iracing.cpp +++ b/iracing.cpp @@ -400,9 +400,6 @@ ConnectionStatus ir_tick() sprintf( path, "WeekendInfo:WeekendOptions:IsFixedSetup:" ); parseYamlInt( sessionYaml, path, &ir_session.isFixedSetup ); - sprintf(path, "WeekendInfo:WeekendOptions:NumCarClasses:"); - parseYamlInt(sessionYaml, path, &ir_session.numCarClasses); - // Current session type std::string sessionNameStr; sprintf( path, "SessionInfo:Sessions:SessionNum:{%d}SessionName:", ir_SessionNum.getInt() ); @@ -438,41 +435,9 @@ ConnectionStatus ir_tick() continue; } - sprintf(path, "DriverInfo:Drivers:CarIdx:{%d}TeamName:", carIdx); - if (!parseYamlStr(sessionYaml, path, car.teamName)) - { - car = Car(); - continue; - } - - // Remove line breaks in user names if we find any and special characters - for (char& c : car.userName) { - switch (c) { - case '\n': - c = ' '; - break; - case '\r': - c = ' '; - break; - case 'í': - c = 'i'; - break; - case 'ó': - c = 'o'; - break; - case 'ú': - c = 'u'; - break; - case 'á': - c = 'a'; - break; - case 'é': - c = 'e'; - break; - default: - c = c; - } - } + // Remove line breaks in user names if we find any (saw this happen once) + for( char& c : car.userName ) + c = (c=='\n'||c=='\r') ? ' ' : c; sprintf( path, "DriverInfo:Drivers:CarIdx:{%d}CarNumber:", carIdx ); parseYamlStr( sessionYaml, path, car.carNumberStr ); @@ -492,21 +457,9 @@ ConnectionStatus ir_tick() sscanf( car.licenseColStr.c_str(), "0x%x", &licColHex ); car.licenseCol.r = float((licColHex >> 16) & 0xff) / 255.f; car.licenseCol.g = float((licColHex >> 8) & 0xff) / 255.f; - car.licenseCol.b = float((licColHex >> 0) & 0xff) / 255.f; + car.licenseCol.b = float((licColHex >> 0) & 0xff) / 255.f; car.licenseCol.a = 1; - sprintf(path, "DriverInfo:Drivers:CarIdx:{%d}CarClassColor:", carIdx); - parseYamlStr(sessionYaml, path, car.classColStr); - unsigned classColHex = 0; - sscanf(car.classColStr.c_str(), "0x%x", &classColHex); - car.classCol.r = float((classColHex >> 16) & 0xff) / 255.f; - car.classCol.g = float((classColHex >> 8) & 0xff) / 255.f; - car.classCol.b = float((classColHex >> 0) & 0xff) / 255.f; - car.classCol.a = 1; - - sprintf(path, "DriverInfo:Drivers:CarIdx:{%d}CarClassID:", carIdx); - parseYamlInt(sessionYaml, path, &car.classId); - sprintf( path, "DriverInfo:Drivers:CarIdx:{%d}IRating:", carIdx ); parseYamlInt( sessionYaml, path, &car.irating ); @@ -520,14 +473,11 @@ ConnectionStatus ir_tick() parseYamlInt( sessionYaml, path, &car.incidentCount ); sprintf( path, "DriverInfo:Drivers:CarIdx:{%d}CarClassEstLapTime:", carIdx ); - parseYamlFloat( sessionYaml, path, &car.carClassEstLapTime ); - - sprintf(path, "DriverInfo:Drivers:CarIdx:{%d}CarScreenName:", carIdx); - parseYamlStr(sessionYaml, path, car.carName); - - car.qualy.position = 0; - car.practice.position = 0; - car.race.position = 0; + parseYamlFloat( sessionYaml, path, &car.carClassEstLapTime ); + + car.practicePosition = 0; + car.qualPosition = 0; + car.racePosition = 0; } // Qualifying results info @@ -536,15 +486,10 @@ ConnectionStatus ir_tick() sprintf( path, "QualifyResultsInfo:Results:Position:{%d}CarIdx:", pos ); int carIdx = -1; if( parseYamlInt( sessionYaml, path, &carIdx ) ) { - - sprintf(path, "QualifyResultsInfo:Results:Position:{%d}ClassPosition:", pos); - - int realPos = -1; - parseYamlInt(sessionYaml, path, &realPos); - ir_session.cars[carIdx].qualy.position = realPos + 1; + ir_session.cars[carIdx].qualPosition = pos + 1; sprintf( path, "QualifyResultsInfo:Results:Position:{%d}FastestTime:", pos ); - parseYamlFloat( sessionYaml, path, &ir_session.cars[carIdx].qualy.fastestTime ); + parseYamlFloat( sessionYaml, path, &ir_session.cars[carIdx].qualTime ); } } @@ -571,45 +516,12 @@ ConnectionStatus ir_tick() sprintf( path, "SessionInfo:Sessions:SessionNum:{%d}ResultsPositions:Position:{%d}CarIdx:", session, pos ); if( parseYamlInt( sessionYaml, path, &carIdx ) ) { - if (sessionNameStr == "PRACTICE") { - sprintf(path, "SessionInfo:Sessions:SessionNum:{%d}ResultsPositions:Position:{%d}ClassPosition:", session, pos); - - int realPos = -1; - parseYamlInt(sessionYaml, path, &realPos); - ir_session.cars[carIdx].practice.position = realPos + 1; - - sprintf(path, "SessionInfo:Sessions:SessionNum:{%d}ResultsPositions:Position:{%d}LastTime:", session, pos); - parseYamlFloat(sessionYaml, path, &ir_session.cars[carIdx].practice.lastTime); - - sprintf(path, "SessionInfo:Sessions:SessionNum:{%d}ResultsPositions:Position:{%d}FastestTime:", session, pos); - parseYamlFloat(sessionYaml, path, &ir_session.cars[carIdx].practice.fastestTime); - } - else if (sessionNameStr == "QUALIFY") { - sprintf(path, "SessionInfo:Sessions:SessionNum:{%d}ResultsPositions:Position:{%d}ClassPosition:", session, pos); - - int realPos = -1; - parseYamlInt(sessionYaml, path, &realPos); - ir_session.cars[carIdx].qualy.position = realPos + 1; - - sprintf(path, "SessionInfo:Sessions:SessionNum:{%d}ResultsPositions:Position:{%d}LastTime:", session, pos); - parseYamlFloat(sessionYaml, path, &ir_session.cars[carIdx].qualy.lastTime); - - sprintf(path, "SessionInfo:Sessions:SessionNum:{%d}ResultsPositions:Position:{%d}FastestTime:", session, pos); - parseYamlFloat(sessionYaml, path, &ir_session.cars[carIdx].qualy.fastestTime); - } - else if (sessionNameStr == "RACE") { - sprintf(path, "SessionInfo:Sessions:SessionNum:{%d}ResultsPositions:Position:{%d}ClassPosition:", session, pos); - - int realPos = -1; - parseYamlInt(sessionYaml, path, &realPos); - ir_session.cars[carIdx].race.position = realPos + 1; - - sprintf(path, "SessionInfo:Sessions:SessionNum:{%d}ResultsPositions:Position:{%d}LastTime:", session, pos); - parseYamlFloat(sessionYaml, path, &ir_session.cars[carIdx].race.lastTime); - - sprintf(path, "SessionInfo:Sessions:SessionNum:{%d}ResultsPositions:Position:{%d}FastestTime:", session, pos); - parseYamlFloat(sessionYaml, path, &ir_session.cars[carIdx].race.fastestTime); - } + if( sessionNameStr == "PRACTICE" ) + ir_session.cars[carIdx].practicePosition = pos; + else if( sessionNameStr == "QUALIFY" ) + ir_session.cars[carIdx].qualPosition = pos; + else if( sessionNameStr == "RACE" ) + ir_session.cars[carIdx].racePosition = pos; } } } @@ -693,37 +605,25 @@ float ir_estimateLaptime() int ir_getPosition( int carIdx ) { // Try the different sources we have for position data, in descending order of importance - int pos = ir_CarIdxClassPosition.getInt(carIdx); + int pos = ir_CarIdxPosition.getInt(carIdx); if( pos > 0 ) return pos; - pos = ir_session.cars[carIdx].race.position; + pos = ir_session.cars[carIdx].racePosition; if( pos > 0 ) return pos; - pos = ir_session.cars[carIdx].qualy.position; + pos = ir_session.cars[carIdx].qualPosition; if( pos > 0 ) return pos; - pos = ir_session.cars[carIdx].practice.position; + pos = ir_session.cars[carIdx].practicePosition; if( pos > 0 ) return pos; return 0; } -int ir_getPositionsChanged(int carIdx) -{ - - int posAct = ir_CarIdxClassPosition.getInt(carIdx); - int posQualy = ir_session.cars[carIdx].qualy.position; - - if (posQualy > 0 && posAct > 0) - return posQualy - posAct; - - return 0; -} - int ir_getLapDeltaToLeader( int carIdx, int ldrIdx ) { if( ir_session.sessionType!=SessionType::RACE || ir_isPreStart() || carIdx < 0 || ldrIdx < 0 ) @@ -749,52 +649,6 @@ int ir_getLapDeltaToLeader( int carIdx, int ldrIdx ) return lapDelta; } -float ir_getDeltaTime(int carIdx, int selfIdx) -{ - if (ir_isPreStart() || carIdx < 0 || selfIdx < 0) - return 0; - - const float carTimeLap = ir_CarIdxLastLapTime.getFloat(carIdx); - const float selfTimeLap = ir_CarIdxLastLapTime.getFloat(selfIdx); - - if (carTimeLap <= 0 || selfTimeLap <= 0) - return 0; - - float lapDelta = carTimeLap - selfTimeLap; - - return lapDelta; -} - -int ir_getLapsRemaining() { - double sessionTime = ir_SessionTimeRemain.getDouble(); - - const bool sessionIsTimeLimited = ir_SessionLapsTotal.getInt() == 32767 && ir_SessionTimeRemain.getDouble() < 48.0 * 3600.0; // most robust way I could find to figure out whether this is a time-limited session (info in session string is often misleading) - const int remainingLaps = sessionIsTimeLimited ? int(0.5 + sessionTime / ir_estimateLaptime()) : (ir_SessionLapsRemainEx.getInt() != 32767 ? ir_SessionLapsRemainEx.getInt() : -1); - - return remainingLaps; -} - -void ir_getSessionTimeRemaining(int& hours, int& mins, int& secs) { - double sessionTime = ir_SessionTimeRemain.getDouble(); - - hours = int(sessionTime / 3600.0); - mins = int(sessionTime / 60.0) % 60; - secs = (int)fmod(sessionTime, 60.0); -} - -int ir_getClassId(int carIdx) -{ - int id = ir_CarIdxClass.getInt(carIdx); - if (id > 0) - return id; - - id = ir_session.cars[carIdx].classId; - if (id > 0) - return id; - - return 0; -} - void ir_printVariables() { if( !irsdk_isConnected() ) diff --git a/iracing.h b/iracing.h index 568ce35..fba4ee7 100644 --- a/iracing.h +++ b/iracing.h @@ -32,8 +32,6 @@ SOFTWARE. #define IR_MAX_CARS 64 -using namespace std; - enum class ConnectionStatus { UNKNOWN = 0, @@ -52,28 +50,16 @@ enum class SessionType }; static const char* const SessionTypeStr[] = {"UNKNOWN","PRACTICE","QUALIFY","RACE"}; -struct SessionPosTimes -{ - float lastTime = 0; - float fastestTime = 0; - int position = 0; -}; - struct Car { - string userName; - string teamName; + std::string userName; int carNumber = 0; - string carNumberStr; - string carName; - string licenseStr; + std::string carNumberStr; + std::string licenseStr; char licenseChar = 'R'; float licenseSR = 0; - string licenseColStr; + std::string licenseColStr; float4 licenseCol = float4(0,0,0,1); - string classColStr; - float4 classCol = float4(0, 0, 0, 1); - int classId = 0; int irating = 0; int isSelf = 0; int isPaceCar = 0; @@ -82,17 +68,17 @@ struct Car int isFlagged = 0; int incidentCount = 0; float carClassEstLapTime = 0; + int practicePosition = 0; + int qualPosition = 0; + float qualTime = 0; + int racePosition = 0; int lastLapInPits = 0; - SessionPosTimes practice; - SessionPosTimes qualy; - SessionPosTimes race; }; struct Session { SessionType sessionType = SessionType::UNKNOWN; Car cars[IR_MAX_CARS]; - int numCarClasses = -1; int driverCarIdx = -1; int sof = 0; int subsessionId = 0; @@ -418,23 +404,8 @@ float ir_estimateLaptime(); // Get the best known position, from the latest session we can find. int ir_getPosition( int carIdx ); -// Get gained positions. -int ir_getPositionsChanged(int carIdx); - -// Get lap gap to P0 car if available. +// Get lap delta to P0 car if available. int ir_getLapDeltaToLeader( int carIdx, int ldrIdx ); -// Get lap delta if available. -float ir_getDeltaTime(int carIdx, int selfIdx); - -// Get laps remaining for sesion -int ir_getLapsRemaining(); - -// Get session time remaining -void ir_getSessionTimeRemaining(int& hours, int& mins, int& secs); - -// Get car class id -int ir_getClassId(int carIdx); - // Print all the variables the sim supports. void ir_printVariables(); diff --git a/iron.vcxproj b/iron.vcxproj index 0662332..64556da 100644 --- a/iron.vcxproj +++ b/iron.vcxproj @@ -120,7 +120,6 @@ PICOJSON_USE_RVALUE_REFERENCE=0;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true MultiThreadedDebug - stdcpp20 Console @@ -137,7 +136,6 @@ PICOJSON_USE_RVALUE_REFERENCE=0;NOMINMAX;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true MultiThreaded - stdcpp20 Console diff --git a/irsdk/irsdk_client.cpp b/irsdk/irsdk_client.cpp index 4d5b273..97277e1 100644 --- a/irsdk/irsdk_client.cpp +++ b/irsdk/irsdk_client.cpp @@ -294,7 +294,7 @@ float irsdkClient::getVarFloat(int idx, int entry) else { //invalid variable index - //assert(false); + assert(false); } } diff --git a/main.cpp b/main.cpp index a892ec5..9d5a618 100644 --- a/main.cpp +++ b/main.cpp @@ -33,11 +33,7 @@ SOFTWARE. #include #include #include -#include -#include #include -#include -#include #include "iracing.h" #include "Config.h" #include "OverlayCover.h" @@ -47,9 +43,6 @@ SOFTWARE. #include "OverlayDebug.h" #include "OverlayDDU.h" -using namespace Microsoft::WRL; -using namespace std; - enum class Hotkey { UiEdit, @@ -90,7 +83,7 @@ static void registerHotkeys() RegisterHotKey( NULL, (int)Hotkey::Cover, mod, vk ); } -static void handleConfigChange( vector overlays, ConnectionStatus status ) +static void handleConfigChange( std::vector overlays, ConnectionStatus status ) { registerHotkeys(); @@ -114,60 +107,6 @@ static void giveFocusToIracing() SetForegroundWindow( hwnd ); } -// Cargar una imagen .png utilizando WIC -void LoadPNGImage(const wchar_t* filePath, ComPtr& wicFactory, ComPtr& decoder, ComPtr& frame, ComPtr& formatConverter) { - - // Carga el archivo PNG utilizando el decodificador de mapas de bits WIC - wicFactory->CreateDecoderFromFilename(filePath, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, decoder.GetAddressOf()); - - // Obtiene el primer fotograma del archivo PNG - decoder->GetFrame(0, frame.GetAddressOf()); - - // Convierte el formato del fotograma a 32 bpp ARGB - wicFactory->CreateFormatConverter(formatConverter.GetAddressOf()); - formatConverter->Initialize(frame.Get(), GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nullptr, 0.0f, WICBitmapPaletteTypeCustom); - - /*if (FAILED(hr)) - { - // Error al crear el decodificador - return hr; - }*/ - -} - -static void LoadCarIcons(map& mapa) { - const wchar_t* directory = L"./carIcons"; - - CoInitialize(nullptr); - - ComPtr wicFactory; - ComPtr decoder; - ComPtr frame; - ComPtr formatConverter; - - CoCreateInstance(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(wicFactory.GetAddressOf())); - - if (filesystem::exists(directory) && filesystem::is_directory(directory)) { - for (const auto& archivo : filesystem::directory_iterator(directory)) { - if (filesystem::is_regular_file(archivo)) { - std::string ruta = archivo.path().string(); - - int length = MultiByteToWideChar(CP_UTF8, 0, ruta.c_str(), -1, NULL, 0); - wchar_t* ruta_wchar = new wchar_t[length]; - MultiByteToWideChar(CP_UTF8, 0, ruta.c_str(), -1, ruta_wchar, length); - - LoadPNGImage(ruta_wchar, wicFactory, decoder, frame, formatConverter); - string name = archivo.path().filename().string(); - std::regex pattern("\\.\\w+$"); - mapa[regex_replace(name, pattern, "")] = formatConverter.Get(); - } - } - } - else { - cout << "Cars icons doesnt found" << endl; - } -} - int main() { // Bump priority up so we get time from the sim @@ -177,9 +116,6 @@ int main() g_cfg.load(); g_cfg.watchForChanges(); - map mapa; - LoadCarIcons(mapa); - // Register global hotkeys registerHotkeys(); @@ -202,11 +138,11 @@ int main() printf("====================================================================================\n\n"); // Create overlays - vector overlays; + std::vector overlays; overlays.push_back( new OverlayCover() ); overlays.push_back( new OverlayRelative() ); overlays.push_back( new OverlayInputs() ); - overlays.push_back( new OverlayStandings( mapa ) ); + overlays.push_back( new OverlayStandings() ); overlays.push_back( new OverlayDDU() ); #ifdef _DEBUG overlays.push_back( new OverlayDebug() ); @@ -325,7 +261,4 @@ int main() for( Overlay* o : overlays ) delete o; - - // Libera los recursos de COM - CoUninitialize(); } diff --git a/util.h b/util.h index 578999a..3093194 100644 --- a/util.h +++ b/util.h @@ -27,16 +27,13 @@ SOFTWARE. #include #include +#include #include -#include -#include -#include #include #include #include #include #include -#include #define HRCHECK( x_ ) do{ \ HRESULT hr_ = x_; \ @@ -438,34 +435,3 @@ inline bool parseHotkey( const std::string& desc, UINT* mod, UINT* vk ) return false; } - - -inline std::string toLowerCase(std::string str) { - std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c) { - return std::tolower(c); - }); - return str; -}; - - -inline IWICFormatConverter* findAndDrawCar(const std::string& carName, std::map& mapa) -{ - std::string cocheLowerCase = toLowerCase(carName); - - IWICFormatConverter* valor = nullptr; // Valor por defecto si no se encuentra el coche en el mapa - - // Buscar el coche en el mapa - for (const auto& pair : mapa) - { - std::string keyLowerCase = toLowerCase(pair.first); - if (cocheLowerCase.find(keyLowerCase) != std::string::npos) - { - valor = pair.second; - break; - } - } - - return valor; -} - -