Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the redundant HTTPRequest ticker #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 3 additions & 38 deletions Source/JavascriptHttp/JavascriptHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,6 @@
#include "JavascriptHttpRequest.h"
#include "JavascriptContext.h"

#if WITH_EDITOR
#include "TickableEditorObject.h"
typedef FTickableEditorObject FTickableRequest;
#else
#include "Tickable.h"
typedef FTickableGameObject FTickableRequest;
#endif

struct FHttpProcessor : public FTickableRequest
{
public:
FHttpProcessor(TSharedPtr<IHttpRequest> InRef)
: Ref(InRef)
{}

TSharedPtr<IHttpRequest> Ref;

virtual void Tick(float DeltaTime) override
{
Ref->Tick(DeltaTime);
}

virtual bool IsTickable() const override
{
return true;
}

virtual TStatId GetStatId() const override
{
RETURN_QUICK_DECLARE_CYCLE_STAT(JavascriptHttpRequest, STATGROUP_Tickables);
}
};

UJavascriptHttpRequest::UJavascriptHttpRequest(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
Expand All @@ -48,7 +16,7 @@ void UJavascriptHttpRequest::BeginDestroy()
{
Super::BeginDestroy();

if (IsProcessing())
if (GetIsProcessing())
{
EndProcessing();
}
Expand All @@ -58,14 +26,11 @@ void UJavascriptHttpRequest::BeginDestroy()

void UJavascriptHttpRequest::BeginProcessing()
{
Processor = new FHttpProcessor(Request);
IsProcessing = true;
}

void UJavascriptHttpRequest::EndProcessing()
{
delete Processor;
Processor = nullptr;

Request->OnProcessRequestComplete().Unbind();
Request->OnRequestProgress().Unbind();
}
Expand Down Expand Up @@ -104,7 +69,7 @@ void UJavascriptHttpRequest::SetHeader(const FString& HeaderName, const FString&

bool UJavascriptHttpRequest::ProcessRequest()
{
if (IsProcessing()) return false;
if (GetIsProcessing()) return false;

Request->OnProcessRequestComplete().BindLambda([&](FHttpRequestPtr, FHttpResponsePtr, bool status){
OnComplete.ExecuteIfBound(status);
Expand Down
12 changes: 6 additions & 6 deletions Source/JavascriptHttp/JavascriptHttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ namespace EJavascriptHttpRequestStatus
};
}

struct FHttpProcessor;

/**
*
*/
Expand All @@ -31,6 +29,10 @@ class JAVASCRIPTHTTP_API UJavascriptHttpRequest : public UObject
{
GENERATED_UCLASS_BODY()

private:

bool IsProcessing;

public:
TSharedPtr<IHttpRequest> Request;

Expand Down Expand Up @@ -169,10 +171,8 @@ class JAVASCRIPTHTTP_API UJavascriptHttpRequest : public UObject
float GetElapsedTime();

virtual void BeginDestroy() override;

FHttpProcessor* Processor{nullptr};

bool IsProcessing() { return Processor != nullptr; }

bool GetIsProcessing() const { return IsProcessing; }

void BeginProcessing();
void EndProcessing();
Expand Down