Apply const to more local variables

This commit is contained in:
Chris Thrasher 2023-11-14 11:37:59 -07:00
parent 819bdb67e9
commit 0e17f4d320
10 changed files with 56 additions and 58 deletions

View File

@ -406,8 +406,8 @@ bool RenderTarget::setActive(bool active)
const std::uint64_t contextId = Context::getActiveContextId();
using RenderTargetImpl::getContextRenderTargetMap;
auto& contextRenderTargetMap = getContextRenderTargetMap();
auto it = contextRenderTargetMap.find(contextId);
auto& contextRenderTargetMap = getContextRenderTargetMap();
const auto it = contextRenderTargetMap.find(contextId);
if (active)
{

View File

@ -510,7 +510,7 @@ bool RenderTextureImplFBO::activate(bool active)
if (it != m_multisampleFrameBuffers.end())
{
auto frameBuffer = it->second.lock();
const auto frameBuffer = it->second.lock();
if (frameBuffer)
{
@ -526,7 +526,7 @@ bool RenderTextureImplFBO::activate(bool active)
if (it != m_frameBuffers.end())
{
auto frameBuffer = it->second.lock();
const auto frameBuffer = it->second.lock();
if (frameBuffer)
{
@ -568,8 +568,8 @@ void RenderTextureImplFBO::updateTexture(unsigned int)
if ((frameBufferIt != m_frameBuffers.end()) && (multisampleIt != m_multisampleFrameBuffers.end()))
{
auto frameBuffer = frameBufferIt->second.lock();
auto multiSampleFrameBuffer = multisampleIt->second.lock();
const auto frameBuffer = frameBufferIt->second.lock();
const auto multiSampleFrameBuffer = multisampleIt->second.lock();
if (frameBuffer && multiSampleFrameBuffer)
{

View File

@ -93,7 +93,7 @@ ActivityStates* retrieveStates(ANativeActivity* activity)
static void initializeMain(ActivityStates* states)
{
// Protect from concurrent access
std::lock_guard lock(states->mutex);
const std::lock_guard lock(states->mutex);
// Prepare and share the looper to be read later
ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
@ -117,7 +117,7 @@ static void initializeMain(ActivityStates* states)
static void terminateMain(ActivityStates* states)
{
// Protect from concurrent access
std::lock_guard lock(states->mutex);
const std::lock_guard lock(states->mutex);
// The main thread has finished, we must explicitly ask the activity to finish
states->mainOver = true;
@ -138,7 +138,7 @@ void* main(ActivityStates* states)
terminateMain(states);
{
std::lock_guard lock(states->mutex);
const std::lock_guard lock(states->mutex);
states->terminated = true;
}
@ -260,7 +260,7 @@ static void onResume(ANativeActivity* activity)
{
// Retrieve our activity states from the activity instance
sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity);
std::lock_guard lock(states->mutex);
const std::lock_guard lock(states->mutex);
if (states->fullscreen)
goToFullscreenMode(activity);
@ -278,7 +278,7 @@ static void onPause(ANativeActivity* activity)
{
// Retrieve our activity states from the activity instance
sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity);
std::lock_guard lock(states->mutex);
const std::lock_guard lock(states->mutex);
// Send an event to warn people the activity has been paused
sf::Event event;
@ -302,7 +302,7 @@ static void onDestroy(ANativeActivity* activity)
// Send an event to warn people the activity is being destroyed
{
std::lock_guard lock(states->mutex);
const std::lock_guard lock(states->mutex);
// If the main thread hasn't yet finished, send the event and wait for
// it to finish.
@ -344,7 +344,7 @@ static void onDestroy(ANativeActivity* activity)
static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* window)
{
sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity);
std::lock_guard lock(states->mutex);
const std::lock_guard lock(states->mutex);
// Update the activity states
states->window = window;
@ -369,7 +369,7 @@ static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* wind
static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* /* window */)
{
sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity);
std::lock_guard lock(states->mutex);
const std::lock_guard lock(states->mutex);
// Update the activity states
states->window = nullptr;
@ -410,7 +410,7 @@ static void onInputQueueCreated(ANativeActivity* activity, AInputQueue* queue)
// Attach the input queue
{
std::lock_guard lock(states->mutex);
const std::lock_guard lock(states->mutex);
AInputQueue_attachLooper(queue, states->looper, 1, states->processEvent, nullptr);
states->inputQueue = queue;
@ -426,7 +426,7 @@ static void onInputQueueDestroyed(ANativeActivity* activity, AInputQueue* queue)
// Detach the input queue
{
std::lock_guard lock(states->mutex);
const std::lock_guard lock(states->mutex);
AInputQueue_detachLooper(queue);
states->inputQueue = nullptr;
@ -447,7 +447,7 @@ static void onContentRectChanged(ANativeActivity* activity, const ARect* /* rect
{
// Retrieve our activity states from the activity instance
sf::priv::ActivityStates* states = sf::priv::retrieveStates(activity);
std::lock_guard lock(states->mutex);
const std::lock_guard lock(states->mutex);
// Make sure the window still exists before we access the dimensions on it
if (states->window != nullptr)

View File

@ -38,8 +38,8 @@ namespace sf::priv
////////////////////////////////////////////////////////////
ResourceStream::ResourceStream(const std::filesystem::path& filename)
{
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
m_file.reset(AAssetManager_open(states.activity->assetManager, filename.c_str(), AASSET_MODE_UNKNOWN));
}

View File

@ -83,8 +83,8 @@ void setVirtualKeyboardVisible(bool visible)
{
// todo: Check if the window is active
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
// Initializes JNI
jint lFlags = 0;
@ -168,8 +168,8 @@ bool isMouseButtonPressed(Mouse::Button button)
{
ALooper_pollAll(0, nullptr, nullptr, nullptr);
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
return states.isButtonPressed[button];
}
@ -180,8 +180,8 @@ Vector2i getMousePosition()
{
ALooper_pollAll(0, nullptr, nullptr, nullptr);
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
return states.mousePosition;
}
@ -213,8 +213,8 @@ bool isTouchDown(unsigned int finger)
{
ALooper_pollAll(0, nullptr, nullptr, nullptr);
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
return states.touchEvents.find(static_cast<int>(finger)) != states.touchEvents.end();
}
@ -225,8 +225,8 @@ Vector2i getTouchPosition(unsigned int finger)
{
ALooper_pollAll(0, nullptr, nullptr, nullptr);
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
return states.touchEvents.find(static_cast<int>(finger))->second;
}

View File

@ -50,7 +50,7 @@ VideoMode VideoModeImpl::getDesktopMode()
{
// Get the activity states
priv::ActivityStates& states = priv::getActivity();
std::lock_guard lock(states.mutex);
const std::lock_guard lock(states.mutex);
return VideoMode(Vector2u(states.screenSize));
}

View File

@ -63,8 +63,8 @@ WindowImplAndroid::WindowImplAndroid(VideoMode mode,
const ContextSettings& /* settings */) :
m_size(mode.size)
{
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
if (style & Style::Fullscreen)
states.fullscreen = true;
@ -89,8 +89,8 @@ WindowImplAndroid::~WindowImplAndroid()
////////////////////////////////////////////////////////////
WindowHandle WindowImplAndroid::getNativeHandle() const
{
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
return states.window;
}
@ -102,8 +102,8 @@ void WindowImplAndroid::processEvents()
// Process incoming OS events
ALooper_pollAll(0, nullptr, nullptr, nullptr);
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
if (m_windowBeingCreated)
{
@ -254,8 +254,8 @@ void WindowImplAndroid::forwardEvent(const Event& event)
////////////////////////////////////////////////////////////
int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* data */)
{
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
AInputEvent* inputEvent = nullptr;
@ -708,8 +708,8 @@ Keyboard::Key WindowImplAndroid::androidKeyToSF(std::int32_t key)
int WindowImplAndroid::getUnicode(AInputEvent* event)
{
// Retrieve activity states
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
// Initializes JNI
jint lResult;

View File

@ -63,7 +63,7 @@ EGLDisplay getInitializedDisplay()
// On Android, its native activity handles this for us
sf::priv::ActivityStates& states = sf::priv::getActivity();
std::lock_guard lock(states.mutex);
const std::lock_guard lock(states.mutex);
return states.display;
@ -146,8 +146,8 @@ EglContext::EglContext(EglContext* shared,
#ifdef SFML_SYSTEM_ANDROID
// On Android, we must save the created context
ActivityStates& states = getActivity();
std::lock_guard lock(states.mutex);
ActivityStates& states = getActivity();
const std::lock_guard lock(states.mutex);
states.context = this;

View File

@ -479,7 +479,7 @@ std::shared_ptr<void> GlContext::getSharedContext()
void GlContext::registerUnsharedGlObject(std::shared_ptr<void> object)
{
if (const std::lock_guard lock(Impl::getUnsharedGlObjectsMutex());
auto unsharedGlObjects = Impl::getWeakUnsharedGlObjects().lock())
const auto unsharedGlObjects = Impl::getWeakUnsharedGlObjects().lock())
unsharedGlObjects->emplace_back(Impl::UnsharedGlObject{GlContextImpl::CurrentContext::get().id, std::move(object)});
}
@ -488,17 +488,17 @@ void GlContext::registerUnsharedGlObject(std::shared_ptr<void> object)
void GlContext::unregisterUnsharedGlObject(std::shared_ptr<void> object)
{
if (const std::lock_guard lock(Impl::getUnsharedGlObjectsMutex());
auto unsharedGlObjects = Impl::getWeakUnsharedGlObjects().lock())
const auto unsharedGlObjects = Impl::getWeakUnsharedGlObjects().lock())
{
// Find the object in unshared objects and remove it if its associated context is currently active
// This will trigger the destructor of the object since shared_ptr
// in unshared objects should be the only one existing
auto iter = std::find_if(unsharedGlObjects->begin(),
unsharedGlObjects->end(),
[&](const Impl::UnsharedGlObject& obj) {
return (obj.object == object) &&
(obj.contextId == GlContextImpl::CurrentContext::get().id);
});
const auto iter = std::find_if(unsharedGlObjects->begin(),
unsharedGlObjects->end(),
[&](const Impl::UnsharedGlObject& obj) {
return (obj.object == object) &&
(obj.contextId == GlContextImpl::CurrentContext::get().id);
});
if (iter != unsharedGlObjects->end())
unsharedGlObjects->erase(iter);
@ -555,7 +555,7 @@ void GlContext::releaseTransientContext()
std::unique_ptr<GlContext> GlContext::create()
{
// Make sure that there's an active context (context creation may need extensions, and thus a valid context)
auto sharedContext = SharedContext::get();
const auto sharedContext = SharedContext::get();
const std::lock_guard lock(sharedContext->mutex);
@ -581,7 +581,7 @@ std::unique_ptr<GlContext> GlContext::create()
std::unique_ptr<GlContext> GlContext::create(const ContextSettings& settings, const WindowImpl& owner, unsigned int bitsPerPixel)
{
// Make sure that there's an active context (context creation may need extensions, and thus a valid context)
auto sharedContext = SharedContext::get();
const auto sharedContext = SharedContext::get();
const std::lock_guard lock(sharedContext->mutex);
@ -625,7 +625,7 @@ std::unique_ptr<GlContext> GlContext::create(const ContextSettings& settings, co
std::unique_ptr<GlContext> GlContext::create(const ContextSettings& settings, const Vector2u& size)
{
// Make sure that there's an active context (context creation may need extensions, and thus a valid context)
auto sharedContext = SharedContext::get();
const auto sharedContext = SharedContext::get();
const std::lock_guard lock(sharedContext->mutex);
@ -646,15 +646,13 @@ std::unique_ptr<GlContext> GlContext::create(const ContextSettings& settings, co
sharedContext->loadExtensions();
}
std::unique_ptr<GlContext> context;
// We don't use acquireTransientContext here since we have
// to ensure we have exclusive access to the shared context
// in order to make sure it is not active during context creation
sharedContext->context->setActive(true);
// Create the context
context = std::make_unique<ContextType>(&sharedContext->context.value(), settings, size);
auto context = std::make_unique<ContextType>(&sharedContext->context.value(), settings, size);
sharedContext->context->setActive(false);

View File

@ -868,7 +868,7 @@ void HIDInputManager::buildMappings()
UniChar string[maxLength];
UniCharCount length = 0;
std::uint32_t deadKeyState = 0; // unused value
std::uint32_t const modifiers = 0x100; // no modifiers
const std::uint32_t modifiers = 0x100; // no modifiers
// Use current layout for translation
const OSStatus error = UCKeyTranslate(layout,