Files
Plugin/Source/SenseGloveCore/Public/SGCore/SGHapticGloveCommandBuffer.h
T

222 lines
7.0 KiB
C++

/**
* @file
*
* @author Mamadou Babaei <mamadou@senseglove.com>
*
* @section LICENSE
*
* (The MIT License)
*
* Copyright (c) 2020 - 2022 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
*
*
*/
#pragma once
#include "Containers/Array.h"
#include "Containers/UnrealString.h"
#include "Templates/UniquePtr.h"
#include "UObject/Object.h"
#include "UObject/ObjectMacros.h"
#include "SGCore/SGTimedThumpCommand.h"
#include "SGHapticGloveCommandBuffer.generated.h"
class FSGHapticGloveCommandBufferImpl;
class USGBuzzCommand;
class USGForceFeedbackCommand;
class USGTimedBuzzCommand;
/**
*
*/
UCLASS(BlueprintType)
class SENSEGLOVECORE_API USGHapticGloveCommandBuffer final : public UObject
{
GENERATED_BODY()
public:
static USGHapticGloveCommandBuffer* NewHapticGloveCommandBuffer(
UObject* Outer, const FSGHapticGloveCommandBufferImpl& HapticGloveCommandBufferImpl);
public:
/**
* Create a new HapticsStream for a Haptic Glove.
*/
static USGHapticGloveCommandBuffer* NewHapticGloveCommandBuffer(UObject* Outer);
public:
/**
* The base maximum amount of Force-Feedback Commands that can be in a queue.
*/
static int32 GetMaxForceFeedbackCommands();
/**
* The base maximum amount of Vibrotactile Commands that can be in a queue.
*/
static int32 GetMaxBuzzCommands();
/**
* The base maximum amount of Thumper Commands that can be in a queue.
*/
static int32 GetMaxThumpCommands();
private:
struct FImpl;
struct FImplDeleter
{
void operator()(const FImpl* P) const;
};
TUniquePtr<FImpl, FImplDeleter> Pimpl;
FImplDeleter PimplDeleter;
public:
/**
*
*/
USGHapticGloveCommandBuffer();
public:
/**
* The cast from underlying type constructor.
*/
explicit USGHapticGloveCommandBuffer(const FSGHapticGloveCommandBufferImpl& HapticGloveCommandBufferImpl);
public:
/**
* The destructor.
*/
virtual ~USGHapticGloveCommandBuffer() override;
protected:
/**
* Allows to set the underlying object after construction.
*/
void SetHapticGloveCommandBufferImpl(const FSGHapticGloveCommandBufferImpl& HapticGloveCommandBufferImpl);
public:
/**
* The cast to underlying type method.
*/
const FSGHapticGloveCommandBufferImpl& ToHapticGloveCommandBufferImpl() const;
public:
/**
* All Force Feedback Commands that have been received this 'frame'. Will be flattened into a single command during FlushHapitcs.
*/
TArray<USGForceFeedbackCommand*> GetForceFeedbackCommandsQueue(UObject* Outer) const;
/**
* All Timed Buzz Commands that have been received this 'frame'. Will be flattened into a single command during FlushHapitcs.
*/
TArray<USGTimedBuzzCommand*> GetBuzzCommandsQueue(UObject* Outer) const;
/**
* All Timed Thump Commands that have been received this 'frame'. Will be flattened into a single command during FlushHapitcs.
*/
TArray<USGTimedThumpCommand*> GetThumperCommandsQueue(UObject* Outer) const;
public:
/**
* Clears only the Force-Feedback Queue.
*/
void ClearForceFeedbackCommandsQueue();
/**
* Clears all vibrations in the queue(s).
*/
void ClearVibrations();
/**
* Clear all ongoing effects to this stream.
*/
void Clear();
/**
* Add a new Force-Feedback command to the queue. Does not actually send it.
*/
void AddCommand(const USGForceFeedbackCommand* ForceFeedbackCommand);
/**
* Add a new vibrotactile command to the queue. Does not actually send it.
*/
void AddCommand(const USGTimedBuzzCommand* BuzzCommand);
/**
* Add a new Thumper command to the queue. Does not actually send it. Does not work with SenseGlove, only for Nova's
*/
void AddCommand(const USGTimedThumpCommand* ThumpCommand);
/**
* Update the active commands, using a deltaSeconds since last update, in seconds. Any timedCommands that are elapsed will be removed from the list.
*/
void UpdateTimedCommands(float DeltaSeconds);
public:
/**
* Compiles all ForceFeedback Levels in the queue into a single one. Does not clear the queue. Returns lastForceFeedbackCommand if no ForceFeedback commands are given.
*/
USGForceFeedbackCommand* GetTotalForceFeedbackLevels(
UObject* Outer, const USGForceFeedbackCommand* LastForceFeedbackCommand) const;
/**
* Compiles all ForceFeedback Levels in the queue into a single one. Does not clear the queue.
*/
USGForceFeedbackCommand* GetTotalForceFeedbackLevels(UObject* Outer) const;
/**
* Compiles all active vibrotactile in the queue into a single list of levels. Does not clear the queue.
*/
USGBuzzCommand* GetTotalBuzzLevels(UObject* Outer) const;
/**
* Compiles all active vibrotactile in the queue into a single list of levels. Does not clear the queue.
*/
USGThumperCommand* GetTotalThumperLevels(UObject* Outer) const;
public:
/**
* Compile all commands in the queue(s) into a single set of commands that can be sent to the glove. Only clears the ForceFeedback queue, and only if you want it to.
*/
void FlushHaptics(UObject* Outer,
const USGForceFeedbackCommand* LastBrakeLevel,
USGForceFeedbackCommand*& OutForceFeedbackCommand,
USGBuzzCommand*& OutBuzzCommand,
USGThumperCommand*& OutThumperCommand,
bool bClearForceFeedbackQueue = true);
/**
* Compile all commands in the queue(s) into a single set of commands that can be sent to the glove. Also updates & clears all queues.
*/
void FlushHaptics(UObject* Outer,
float DeltaSeconds,
const USGForceFeedbackCommand* LastBrakeLevel,
USGForceFeedbackCommand*& OutForceFeedbackCommand, USGBuzzCommand*& OutBuzzCommand,
USGThumperCommand*& OutThumperCommand);
};