Hey guys, in my project i have updating dynamic texture every tick, but it ‘eats’ my fps.
So i wanted to do it async, but i have no idea how to do it.
I checked Rama`s tutorials but still didnt understand anything.
Can u provide me an example how to run async function, for example print string?
I’m Sorry for my bad English.My engine vision is 4.13.2
first create header file:
#include "Runtime/SQLiteSupport/Public/SQLiteDatabaseConnection.h"
DEFINE_LOG_CATEGORY_STATIC(TestLog, Log, All);
class FSQLiteTask
{
public:
FSQLiteTask(int16 _Index) :Index(_Index) {}
static const TCHAR* GetTaskName()
{
return TEXT("FSQLiteTask");
}
FORCEINLINE static TStatId GetStatId()
{
RETURN_QUICK_DECLARE_CYCLE_STAT(FShowcaseTask, STATGROUP_TaskGraphTasks);
}
static ENamedThreads::Type GetDesiredThread()
{
return ENamedThreads::AnyThread;
}
static ESubsequentsMode::Type GetSubsequentsMode()
{
return ESubsequentsMode::TrackSubsequents;
}
void ExecuteSQL()
{
FSQLiteDatabase Datebase;
Datebase.Open(TEXT("D:\\date.db"), nullptr, nullptr);
Datebase.Execute(*(FString::Printf(TEXT("insert into test (id,name) values (1,123)"), *(FDateTime::Now().ToString()), *(FApp::GetSessionId().ToString()))));
Datebase.Close();
UE_LOG(TestLog, Log, TEXT("SQLite Execute"));
}
void DoTask(ENamedThreads::Type CurrentThread, const FGraphEventRef& MyCompletionGraphEvent)
{
UE_LOG(TestLog, Log, TEXT("TaskThread %d Run:1"), Index);
ExecuteSQL();
}
private:
int16 Index;
};
at your game cpp file:
TGraphTask<FSQLiteTask>::CreateTask(NULL, ENamedThreads::GameThread).ConstructAndDispatchWhenReady(0);
Do not forget add #include your header file;
And you can use new Async function:
TFunction<void()> Task = []()
{
FSQLiteDatabase Datebase;
Datebase.Open(TEXT("D:\\date.db"), nullptr, nullptr);
Datebase.Execute(*(FString::Printf(TEXT("insert into test (id,name) values (1,123)"), *(FDateTime::Now().ToString()), *(FApp::GetSessionId().ToString()))));
Datebase.Close();
UE_LOG(TestLog, Log, TEXT("SQLite Execute"));
};
auto result = Async(EAsyncExecution::TaskGraph, Task);
just enjoy this time;
估计你是中国人,不懂QQ+378100977