Files
Plugin/Source/SenseGloveCoreImpl/Private/SGCoreImpl/SGTimedBuzzCommandImpl.cpp
T

205 lines
6.6 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/SGTimedBuzzCommandImpl.h"
#include "SGBuildHacks/SGInclude_Core_TimedBuzzCommand.h"
#include "SGCoreImpl/SGCoreEnumCast.h"
#include "SGUtils/SGArrayUtils.h"
struct FSGTimedBuzzCommandImpl::FImpl
{
/************************
* Member variables
************************/
/************************
* Owner object
************************/
FSGTimedBuzzCommandImpl* Owner;
/************************
* Constructor / Destructor
************************/
explicit FImpl(FSGTimedBuzzCommandImpl* InOwner);
~FImpl();
/************************
* Default copy constructor & copy assignment operator
************************/
FImpl(const FImpl& Rhs) = default;
FImpl& operator=(const FImpl& Rhs) = default;
};
FSGTimedBuzzCommandImpl::FSGTimedBuzzCommandImpl()
: FSGBuzzCommandImpl(MakeShared<FTimedBuzzCommandType>()),
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
}
FSGTimedBuzzCommandImpl::FSGTimedBuzzCommandImpl(const ESGFinger Finger, const int32 Magnitude,
const float DurationSeconds, const float StartTimeSeconds)
: FSGBuzzCommandImpl(MakeShared<FTimedBuzzCommandType>(FSGCoreEnumCast::ToEFinger(Finger), Magnitude,
DurationSeconds, StartTimeSeconds)),
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
}
FSGTimedBuzzCommandImpl::FSGTimedBuzzCommandImpl(const FSGBuzzCommandImpl& BaseCommand,
const float DurationSeconds, const float StartTimeSeconds)
: FSGBuzzCommandImpl(MakeShared<FTimedBuzzCommandType>(
BaseCommand.ToBuzzCommand(), DurationSeconds, StartTimeSeconds)),
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
}
FSGTimedBuzzCommandImpl::FSGTimedBuzzCommandImpl(const FTimedBuzzCommandType& TimedBuzzCommand)
: FSGBuzzCommandImpl(MakeShared<FTimedBuzzCommandType>(TimedBuzzCommand)),
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
}
FSGTimedBuzzCommandImpl::FSGTimedBuzzCommandImpl(const TSharedRef<FTimedBuzzCommandType> TimedBuzzCommand)
: FSGBuzzCommandImpl(TimedBuzzCommand),
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{
}
FSGTimedBuzzCommandImpl::FSGTimedBuzzCommandImpl(const FSGTimedBuzzCommandImpl& Rhs)
: FSGBuzzCommandImpl(Rhs),
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{*Rhs.Pimpl}, PimplDeleter))
{
Pimpl->Owner = this;
}
FSGTimedBuzzCommandImpl::FSGTimedBuzzCommandImpl(FSGTimedBuzzCommandImpl&& Rhs) SG_NOEXCEPT = default;
FSGTimedBuzzCommandImpl::~FSGTimedBuzzCommandImpl() = default;
FSGTimedBuzzCommandImpl& FSGTimedBuzzCommandImpl::operator=(const FSGTimedBuzzCommandImpl& Rhs)
{
FSGBuzzCommandImpl::operator=(Rhs);
*Pimpl = *Rhs.Pimpl;
Pimpl->Owner = this;
return *this;
}
FSGTimedBuzzCommandImpl& FSGTimedBuzzCommandImpl::operator=(FSGTimedBuzzCommandImpl&& Rhs) SG_NOEXCEPT = default;
const FSGTimedBuzzCommandImpl::FTimedBuzzCommandType& FSGTimedBuzzCommandImpl::ToTimedBuzzCommand() const
{
return *StaticCastSharedRef<FTimedBuzzCommandType>(ToBuzzCommandRef());
}
TSharedRef<FSGTimedBuzzCommandImpl::FTimedBuzzCommandType> FSGTimedBuzzCommandImpl::ToTimedBuzzCommandRef() const
{
return StaticCastSharedRef<FTimedBuzzCommandType>(ToBuzzCommandRef());
}
FSGTimedBuzzCommandImpl::FTimedBuzzCommandType& FSGTimedBuzzCommandImpl::ToTimedBuzzCommand()
{
return *StaticCastSharedRef<FTimedBuzzCommandType>(ToBuzzCommandRef());
}
TSharedRef<FSGTimedBuzzCommandImpl::FTimedBuzzCommandType> FSGTimedBuzzCommandImpl::ToTimedBuzzCommandRef()
{
return StaticCastSharedRef<FTimedBuzzCommandType>(ToBuzzCommandRef());
}
FSGBuzzCommandImpl FSGTimedBuzzCommandImpl::Copy() const
{
return FSGBuzzCommandImpl{ToTimedBuzzCommandRef()->Copy()};
}
FSGBuzzCommandImpl FSGTimedBuzzCommandImpl::Merge(const FSGBuzzCommandImpl& BuzzCommand) const
{
return FSGBuzzCommandImpl{ToTimedBuzzCommandRef()->Merge(BuzzCommand.ToBuzzCommand())};
}
FSGBuzzCommandImpl FSGTimedBuzzCommandImpl::GetBaseCommand() const
{
return FSGBuzzCommandImpl{MakeShared<FBuzzCommandType>(ToTimedBuzzCommandRef()->GetBaseCommand())};
}
float FSGTimedBuzzCommandImpl::GetDuration() const
{
return ToTimedBuzzCommandRef()->GetDuration();
}
float FSGTimedBuzzCommandImpl::GetElapsedTime() const
{
return ToTimedBuzzCommandRef()->GetElapsedTime();
}
bool FSGTimedBuzzCommandImpl::HasTimeElapsed() const
{
return ToTimedBuzzCommandRef()->HasTimeElapsed();
}
float FSGTimedBuzzCommandImpl::NormalizedTime(const bool bClamp01) const
{
return ToTimedBuzzCommandRef()->NormalizedTime(bClamp01);
}
void FSGTimedBuzzCommandImpl::ResetTiming()
{
ToTimedBuzzCommandRef()->ResetTiming();
}
void FSGTimedBuzzCommandImpl::UpdateTiming(const float DeltaSeconds)
{
ToTimedBuzzCommandRef()->UpdateTiming(DeltaSeconds);
}
FString FSGTimedBuzzCommandImpl::ToString() const
{
return UTF8_TO_TCHAR(ToTimedBuzzCommandRef()->ToString().c_str());
}
FSGTimedBuzzCommandImpl::FImpl::FImpl(FSGTimedBuzzCommandImpl* InOwner)
: Owner(InOwner)
{
}
FSGTimedBuzzCommandImpl::FImpl::~FImpl() = default;
void FSGTimedBuzzCommandImpl::FImplDeleter::operator()(const FSGTimedBuzzCommandImpl::FImpl* P) const
{
delete P;
}