258 lines
8.1 KiB
C++
258 lines
8.1 KiB
C++
/**
|
|
* @file
|
|
*
|
|
* @author Mamadou Babaei <mamadou@senseglove.com>
|
|
*
|
|
* @section LICENSE
|
|
*
|
|
* (The MIT License)
|
|
*
|
|
* Copyright (c) 2020 - 2023 SenseGlove
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
* @section DESCRIPTION
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
#include "SGCoreImpl/SGFingerCommandImpl.h"
|
|
|
|
#include "Containers/StringConv.h"
|
|
#include "Runtime/Launch/Resources/Version.h"
|
|
|
|
#include "SGBuildHacks/SGInclude_Core_BuzzCommand.h"
|
|
#include "SGBuildHacks/SGInclude_Core_FingerCommand.h"
|
|
#include "SGBuildHacks/SGInclude_Core_ForceFeedbackCommand.h"
|
|
#include "SGBuildHacks/SGInclude_Core_TimedBuzzCommand.h"
|
|
#include "SGCoreImpl/SGForceFeedbackCommandImpl.h"
|
|
#include "SGCoreImpl/SGTimedBuzzCommandImpl.h"
|
|
#include "SGUtils/SGArrayUtils.h"
|
|
#include "Templates/Casts.h"
|
|
|
|
struct FSGFingerCommandImpl::FImpl
|
|
{
|
|
/************************
|
|
* Static methods
|
|
************************/
|
|
|
|
static TSharedPtr<FFingerCommandType> MakeNewFingerCommand(TSharedPtr<FFingerCommandType> Ptr);
|
|
|
|
/************************
|
|
* Member variables
|
|
************************/
|
|
|
|
TSharedPtr<FFingerCommandType> FingerCommand;
|
|
|
|
/************************
|
|
* Owner object
|
|
************************/
|
|
|
|
FSGFingerCommandImpl* Owner;
|
|
|
|
/************************
|
|
* Constructor / Destructor
|
|
************************/
|
|
|
|
explicit FImpl(FSGFingerCommandImpl* InOwner);
|
|
~FImpl();
|
|
|
|
/************************
|
|
* The copy constructor & copy assignment operator
|
|
************************/
|
|
|
|
FImpl(const FImpl& Rhs);
|
|
FImpl& operator=(const FImpl& Rhs);
|
|
};
|
|
|
|
FSGFingerCommandImpl::FSGFingerCommandImpl()
|
|
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
}
|
|
|
|
FSGFingerCommandImpl::FSGFingerCommandImpl(const TArray<int32>& Levels)
|
|
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
std::vector<int32> LevelsVector{
|
|
FSGArrayUtils::ToStdVector<int32>(Levels)
|
|
};
|
|
Pimpl->FingerCommand = MakeShared<FFingerCommandType>(MoveTemp(LevelsVector));
|
|
}
|
|
|
|
FSGFingerCommandImpl::FSGFingerCommandImpl(const FFingerCommandType& FingerCommand)
|
|
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
Pimpl->FingerCommand = MakeShared<FFingerCommandType>(FingerCommand);
|
|
}
|
|
|
|
FSGFingerCommandImpl::FSGFingerCommandImpl(const TSharedRef<FFingerCommandType> FingerCommand)
|
|
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
|
|
{
|
|
Pimpl->FingerCommand = FImpl::MakeNewFingerCommand(FingerCommand);
|
|
}
|
|
|
|
FSGFingerCommandImpl::FSGFingerCommandImpl(const FSGFingerCommandImpl& Rhs)
|
|
: Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
|
|
{
|
|
Pimpl->Owner = this;
|
|
Pimpl->FingerCommand = FImpl::MakeNewFingerCommand(Rhs.Pimpl->FingerCommand);
|
|
}
|
|
|
|
FSGFingerCommandImpl::FSGFingerCommandImpl(FSGFingerCommandImpl&& Rhs) SG_NOEXCEPT = default;
|
|
|
|
FSGFingerCommandImpl::~FSGFingerCommandImpl() = default;
|
|
|
|
FSGFingerCommandImpl& FSGFingerCommandImpl::operator=(const FSGFingerCommandImpl& Rhs)
|
|
{
|
|
*Pimpl = *Rhs.Pimpl;
|
|
Pimpl->Owner = this;
|
|
return *this;
|
|
}
|
|
|
|
FSGFingerCommandImpl& FSGFingerCommandImpl::operator=(FSGFingerCommandImpl&& Rhs) SG_NOEXCEPT = default;
|
|
|
|
const FSGFingerCommandImpl::FFingerCommandType& FSGFingerCommandImpl::ToFingerCommand() const
|
|
{
|
|
return *Pimpl->FingerCommand;
|
|
}
|
|
|
|
TSharedRef<FSGFingerCommandImpl::FFingerCommandType> FSGFingerCommandImpl::ToFingerCommandRef() const
|
|
{
|
|
return Pimpl->FingerCommand.ToSharedRef();
|
|
}
|
|
|
|
FSGFingerCommandImpl::FFingerCommandType& FSGFingerCommandImpl::ToFingerCommand()
|
|
{
|
|
return *Pimpl->FingerCommand;
|
|
}
|
|
|
|
TSharedRef<FSGFingerCommandImpl::FFingerCommandType> FSGFingerCommandImpl::ToFingerCommandRef()
|
|
{
|
|
return Pimpl->FingerCommand.ToSharedRef();
|
|
}
|
|
|
|
TSharedRef<FSGFingerCommandImpl> FSGFingerCommandImpl::ToFingerCommandImplRef()
|
|
{
|
|
return SharedThis(this);
|
|
}
|
|
|
|
TSharedRef<FSGBuzzCommandImpl> FSGFingerCommandImpl::ToBuzzCommandImplRef()
|
|
{
|
|
FSGBuzzCommandImpl* BuzzCommandImpl{dynamic_cast<FSGBuzzCommandImpl*>(this)};
|
|
ensureAlwaysMsgf(BuzzCommandImpl, TEXT("Invalid BuzzCommandImpl!"));
|
|
return SharedThis(BuzzCommandImpl);
|
|
}
|
|
|
|
TSharedRef<FSGForceFeedbackCommandImpl> FSGFingerCommandImpl::ToForceFeedbackCommandImplRef()
|
|
{
|
|
FSGForceFeedbackCommandImpl* ForceFeedbackCommandImpl{
|
|
dynamic_cast<FSGForceFeedbackCommandImpl*>(this)};
|
|
ensureAlwaysMsgf(ForceFeedbackCommandImpl, TEXT("Invalid ForceFeedbackCommandImpl!"));
|
|
return SharedThis(ForceFeedbackCommandImpl);
|
|
}
|
|
|
|
TSharedRef<FSGTimedBuzzCommandImpl> FSGFingerCommandImpl::ToTimedBuzzCommandImplRef()
|
|
{
|
|
FSGTimedBuzzCommandImpl* TimedBuzzCommandImpl{dynamic_cast<FSGTimedBuzzCommandImpl*>(this)};
|
|
ensureAlwaysMsgf(TimedBuzzCommandImpl, TEXT("Invalid TimedBuzzCommandImpl!"));
|
|
return SharedThis(TimedBuzzCommandImpl);
|
|
}
|
|
|
|
TArray<int32> FSGFingerCommandImpl::GetLevels() const
|
|
{
|
|
return FSGArrayUtils::FromStdVector<int32>(Pimpl->FingerCommand->GetLevels());
|
|
}
|
|
|
|
int32 FSGFingerCommandImpl::GetLevel(const int32 Finger) const
|
|
{
|
|
return Pimpl->FingerCommand->GetLevel(Finger);
|
|
}
|
|
|
|
void FSGFingerCommandImpl::SetLevel(const int32 Finger, const int32 Value)
|
|
{
|
|
return Pimpl->FingerCommand->SetLevel(Finger, Value);
|
|
}
|
|
|
|
bool FSGFingerCommandImpl::Equals(const FSGFingerCommandImpl& FingerCommandImpl) const
|
|
{
|
|
return Pimpl->FingerCommand->Equals(FingerCommandImpl.ToFingerCommand());
|
|
}
|
|
|
|
FString FSGFingerCommandImpl::ToString() const
|
|
{
|
|
return UTF8_TO_TCHAR(Pimpl->FingerCommand->ToString().c_str());
|
|
}
|
|
|
|
TSharedPtr<FSGFingerCommandImpl::FFingerCommandType> FSGFingerCommandImpl::FImpl::MakeNewFingerCommand(
|
|
const TSharedPtr<FFingerCommandType> Ptr)
|
|
{
|
|
{
|
|
FSGTimedBuzzCommandImpl::FTimedBuzzCommandType* TimedBuzzCommand{dynamic_cast<
|
|
FSGTimedBuzzCommandImpl::FTimedBuzzCommandType*>(Ptr.Get())};
|
|
if (TimedBuzzCommand)
|
|
{
|
|
return MakeShared<FSGTimedBuzzCommandImpl::FTimedBuzzCommandType>(*TimedBuzzCommand);
|
|
}
|
|
}
|
|
|
|
{
|
|
FSGBuzzCommandImpl::FBuzzCommandType* BuzzCommand{dynamic_cast<
|
|
FSGBuzzCommandImpl::FBuzzCommandType*>(Ptr.Get())};
|
|
if (BuzzCommand)
|
|
{
|
|
return MakeShared<FSGBuzzCommandImpl::FBuzzCommandType>(*BuzzCommand);
|
|
}
|
|
}
|
|
|
|
{
|
|
FSGForceFeedbackCommandImpl::FForceFeedbackCommandType* ForceFeedbackCommand{dynamic_cast<
|
|
FSGForceFeedbackCommandImpl::FForceFeedbackCommandType*>(Ptr.Get())};
|
|
if (ForceFeedbackCommand)
|
|
{
|
|
return MakeShared<FSGForceFeedbackCommandImpl::FForceFeedbackCommandType>(*ForceFeedbackCommand);
|
|
}
|
|
}
|
|
|
|
return MakeShared<FFingerCommandType>(*Ptr);
|
|
}
|
|
|
|
FSGFingerCommandImpl::FImpl::FImpl(FSGFingerCommandImpl* InOwner)
|
|
: FingerCommand(MakeShared<FFingerCommandType>()),
|
|
Owner(InOwner)
|
|
{
|
|
}
|
|
|
|
FSGFingerCommandImpl::FImpl::~FImpl() = default;
|
|
|
|
FSGFingerCommandImpl::FImpl::FImpl(const FImpl& Rhs)
|
|
: FingerCommand(MakeNewFingerCommand(Rhs.FingerCommand))
|
|
{
|
|
}
|
|
|
|
FSGFingerCommandImpl::FImpl& FSGFingerCommandImpl::FImpl::operator=(const FImpl& Rhs)
|
|
{
|
|
FingerCommand = MakeNewFingerCommand(Rhs.FingerCommand);
|
|
return *this;
|
|
}
|
|
|
|
void FSGFingerCommandImpl::FImplDeleter::operator()(const FSGFingerCommandImpl::FImpl* P) const
|
|
{
|
|
delete P;
|
|
} |