Skip to content

Commit

Permalink
Minor code-style changes:
Browse files Browse the repository at this point in the history
- The color transformation list now retains order.
- The output vector of the corsair SDK is now reserved with the highest led count available. (possible minor performance boost)
  • Loading branch information
MartB committed Sep 5, 2018
1 parent c146da3 commit ed1126a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 9 additions & 1 deletion server-exe/CorsairSDK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ bool CorsairSDK::initialize() {
}
}

size_t maxLeds = 0;
for (auto i = 0; i < devCount; i++) {
const CorsairDeviceInfo* devInfo = CorsairGetDeviceInfo(i);

Expand Down Expand Up @@ -122,9 +123,16 @@ bool CorsairSDK::initialize() {
continue;
}

// Get the max number of leds so we can later reserve the output color vector.
const auto ledCount = ledVector.size();
if (ledCount > maxLeds) {
maxLeds = ledCount;
}

enableSupportFor(devType);
}

m_outputColorVector.reserve(maxLeds);
return true;
}

Expand Down Expand Up @@ -170,7 +178,7 @@ RZRESULT CorsairSDK::playEffect(RETCDeviceType deviceType, int effectType, const
}

CorsairSetLedsColors(static_cast<int>(m_outputColorVector.size()), m_outputColorVector.data());
m_outputColorVector.resize(0);
m_outputColorVector.clear(); // resize(0) not needed anymore standard states capacity remains unchanged.

if (const auto error = CorsairGetLastError()) {
LOG_D("{0}", errToString(error));
Expand Down
8 changes: 5 additions & 3 deletions server-exe/LightingSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com

#pragma once
#include <set>
#include <algorithm>

#include "../rpc-midl/rpc_retc.h"
#include "SDKLoader.h"
#include "commonData.h"
#include "RzErrors.h"
#include "RzChromaSDKDefines.h"
#include "RzChromaSDKTypes.h"
#include <algorithm>
#include "colorTransformation.h"
#include "gammaTransformation.h"

Expand Down Expand Up @@ -70,7 +72,7 @@ class LightingSDK {
// Gamma adjustment
auto gammaTransformationValues = CONFIG->GetVec3D(SDK_CONFIG_SECTION, L"gamma_adjustment", Vec3D());
if (!gammaTransformationValues.isZero()) { // Skip the transformation if we got the default vector.
m_activeColorTransformations.push_back(std::make_unique<GammaTransformation>(gammaTransformationValues));
m_activeColorTransformations.insert(std::make_unique<GammaTransformation>(gammaTransformationValues));
}

return true;
Expand Down Expand Up @@ -138,7 +140,7 @@ class LightingSDK {
supportArray_t m_supportedDevices;

// Color transformation
std::vector<std::unique_ptr<ColorTransformation>> m_activeColorTransformations;
std::set<std::unique_ptr<ColorTransformation>> m_activeColorTransformations;

private:
SDKLoader* m_sdkLoader;
Expand Down
2 changes: 1 addition & 1 deletion server-exe/SDKManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void SDKManager::checkAvailability() {
}

// Force enable the mousepad support if a headset_stand is connected, this does not assign a sdk!
if (m_clientConfig->supportedDeviceTypes[MOUSEPAD] == FALSE && m_clientConfig->supportedDeviceTypes[HEADSET_STAND] == TRUE) {
if (m_clientConfig->supportedDeviceTypes[MOUSEPAD] == FALSE && m_clientConfig->supportedDeviceTypes[HEADSET_STAND] != FALSE) {
m_clientConfig->supportedDeviceTypes[MOUSEPAD] = TRUE;
}

Expand Down

0 comments on commit ed1126a

Please sign in to comment.