Skip to content

Commit fa58018

Browse files
committed
up
1 parent be523ea commit fa58018

File tree

6 files changed

+151
-26
lines changed

6 files changed

+151
-26
lines changed

Plugins/kbengine_ue4_plugins/Source/KBEnginePlugins/Engine/KBEMain.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ void UKBEMain::BeginPlay()
6767
pArgs->UDP_SEND_BUFFER_MAX = UDP_SEND_BUFFER_MAX;
6868
pArgs->UDP_RECV_BUFFER_MAX = UDP_RECV_BUFFER_MAX;
6969

70+
KBEngineApp::destroyKBEngineApp();
7071
if (!KBEngineApp::getSingleton().initialize(pArgs))
7172
delete pArgs;
7273

@@ -96,23 +97,7 @@ void UKBEMain::EndPlay(const EEndPlayReason::Type EndPlayReason)
9697
// Called every frame
9798
void UKBEMain::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
9899
{
99-
Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
100-
101-
KBEvent::processOutEvents();
102-
103-
APawn* ue4_player = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
104-
Entity* kbe_player = KBEngineApp::getSingleton().player();
105-
106-
// 每个tick将UE4的玩家坐标写入到KBE插件中的玩家实体坐标,插件会定期同步给服务器
107-
if (kbe_player && ue4_player)
108-
{
109-
UE4Pos2KBPos(kbe_player->position, ue4_player->GetActorLocation());
110-
UE4Dir2KBDir(kbe_player->direction, ue4_player->GetActorRotation());
111-
112-
kbe_player->isOnGround(ue4_player->GetMovementComponent() && ue4_player->GetMovementComponent()->IsMovingOnGround());
113-
}
114-
115-
KBEngineApp::getSingleton().process();
100+
116101
}
117102

118103
void UKBEMain::installEvents()
@@ -163,6 +148,7 @@ void UKBEMain::downloadSDKFromServer()
163148
if(pUpdaterObj != nullptr)
164149
{
165150
delete pUpdaterObj;
151+
pUpdaterObj = nullptr;
166152
}
167153
}
168154
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Fill out your copyright notice in the Description page of Project Settings.
2+
3+
#include "KBETicker.h"
4+
#include "Engine.h"
5+
#include "KBDebug.h"
6+
#include "Entity.h"
7+
#include "KBEngine.h"
8+
9+
10+
UKBETicker::UKBETicker()
11+
{
12+
}
13+
14+
UKBETicker::~UKBETicker()
15+
{
16+
}
17+
18+
void UKBETicker::Tick(float DeltaTime)
19+
{
20+
KBEvent::processOutEvents();
21+
22+
APawn* ue4_player = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
23+
Entity* kbe_player = KBEngineApp::getSingleton().player();
24+
25+
// 每个tick将UE4的玩家坐标写入到KBE插件中的玩家实体坐标,插件会定期同步给服务器
26+
if (kbe_player && ue4_player)
27+
{
28+
UE4Pos2KBPos(kbe_player->position, ue4_player->GetActorLocation());
29+
UE4Dir2KBDir(kbe_player->direction, ue4_player->GetActorRotation());
30+
31+
kbe_player->isOnGround(ue4_player->GetMovementComponent() && ue4_player->GetMovementComponent()->IsMovingOnGround());
32+
}
33+
34+
KBEngineApp::getSingleton().process();
35+
}
36+
37+
bool UKBETicker::IsTickable() const
38+
{
39+
return true;
40+
}
41+
42+
TStatId UKBETicker::GetStatId() const
43+
{
44+
return TStatId();
45+
}
46+
47+
UWorld* UKBETicker::GetWorld() const
48+
{
49+
UWorld* World = (GetOuter() != nullptr) ? GetOuter()->GetWorld() : GWorld;
50+
if (World == nullptr)
51+
{
52+
World = GWorld;
53+
}
54+
55+
return World;
56+
}
57+
58+
bool UKBETicker::IsTickableWhenPaused() const
59+
{
60+
return false;
61+
}
62+
63+
bool UKBETicker::IsTickableInEditor() const
64+
{
65+
return false;
66+
}
67+
68+
UWorld* UKBETicker::GetTickableGameObjectWorld() const
69+
{
70+
return GetWorld();
71+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Fill out your copyright notice in the Description page of Project Settings.
2+
3+
#pragma once
4+
5+
#include "CoreMinimal.h"
6+
#include "Object.h"
7+
#include "KBECommon.h"
8+
#include "KBEvent.h"
9+
#include "Tickable.h"
10+
#include "KBETicker.generated.h"
11+
/**
12+
*
13+
*/
14+
UCLASS()
15+
class KBENGINEPLUGINS_API UKBETicker : public UObject, public FTickableGameObject
16+
{
17+
GENERATED_BODY()
18+
public:
19+
UKBETicker();
20+
~UKBETicker();
21+
22+
UWorld* GetWorld() const override;
23+
24+
virtual bool IsTickableWhenPaused() const override;
25+
virtual bool IsTickableInEditor() const override;
26+
virtual UWorld* GetTickableGameObjectWorld() const override;
27+
28+
virtual void Tick(float DeltaTime) override;
29+
virtual bool IsTickable() const override;
30+
virtual TStatId GetStatId() const override;
31+
};

Plugins/kbengine_ue4_plugins/Source/KBEnginePlugins/Engine/KBEngine.cpp

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ KBEngineApp::KBEngineApp() :
5656
spaceResPath_(TEXT("")),
5757
isLoadedGeometry_(false),
5858
component_(TEXT("client")),
59-
pFilter_(NULL)
59+
pFilter_(NULL),
60+
pUKBETicker_(nullptr)
6061
{
6162
INFO_MSG("KBEngineApp::KBEngineApp(): hello!");
63+
installUKBETicker();
6264
}
6365

6466
KBEngineApp::KBEngineApp(KBEngineArgs* pArgs):
@@ -97,10 +99,12 @@ KBEngineApp::KBEngineApp(KBEngineArgs* pArgs):
9799
spaceResPath_(TEXT("")),
98100
isLoadedGeometry_(false),
99101
component_(TEXT("client")),
100-
pFilter_(NULL)
102+
pFilter_(NULL),
103+
pUKBETicker_(nullptr)
101104
{
102105
INFO_MSG("KBEngineApp::KBEngineApp(): hello!");
103106
initialize(pArgs);
107+
installUKBETicker();
104108
}
105109

106110
KBEngineApp::~KBEngineApp()
@@ -109,16 +113,26 @@ KBEngineApp::~KBEngineApp()
109113
INFO_MSG("KBEngineApp::~KBEngineApp(): destructed!");
110114
}
111115

116+
KBEngineApp* pKBEngineApp = nullptr;
117+
112118
KBEngineApp& KBEngineApp::getSingleton()
113119
{
114-
static KBEngineApp* pKBEngineApp = NULL;
115-
116-
if (!pKBEngineApp)
120+
if(!pKBEngineApp)
117121
pKBEngineApp = new KBEngineApp();
118122

119123
return *pKBEngineApp;
120124
}
121125

126+
void KBEngineApp::destroyKBEngineApp()
127+
{
128+
if(pKBEngineApp)
129+
{
130+
delete pKBEngineApp;
131+
pKBEngineApp = nullptr;
132+
KBEvent::clear();
133+
}
134+
}
135+
122136
bool KBEngineApp::initialize(KBEngineArgs* pArgs)
123137
{
124138
if (isInitialized())
@@ -192,6 +206,7 @@ void KBEngineApp::destroy()
192206
KBE_SAFE_RELEASE(pArgs_);
193207
KBE_SAFE_RELEASE(pNetworkInterface_);
194208
KBE_SAFE_RELEASE(pFilter_);
209+
uninstallUKBETicker();
195210
}
196211

197212
void KBEngineApp::resetMessages()
@@ -217,7 +232,7 @@ void KBEngineApp::reset()
217232
serverdatas_.Empty();
218233

219234
serverVersion_ = TEXT("");
220-
clientVersion_ = TEXT("2.4.3");
235+
clientVersion_ = TEXT("2.4.4");
221236
serverScriptVersion_ = TEXT("");
222237
clientScriptVersion_ = TEXT("0.1.0");
223238

@@ -243,6 +258,24 @@ void KBEngineApp::reset()
243258
initNetwork();
244259
}
245260

261+
void KBEngineApp::installUKBETicker()
262+
{
263+
if (pUKBETicker_ == nullptr)
264+
{
265+
pUKBETicker_ = NewObject<UKBETicker>();
266+
pUKBETicker_->AddToRoot();
267+
}
268+
}
269+
270+
void KBEngineApp::uninstallUKBETicker()
271+
{
272+
if (pUKBETicker_)
273+
{
274+
pUKBETicker_->RemoveFromRoot();
275+
pUKBETicker_ = nullptr;
276+
}
277+
}
278+
246279
bool KBEngineApp::initNetwork()
247280
{
248281
KBE_SAFE_RELEASE(pFilter_);
@@ -456,7 +489,7 @@ void KBEngineApp::hello()
456489

457490
KBE_SAFE_RELEASE(pFilter_);
458491

459-
if (pArgs_->networkEncryptType == NETWORK_ENCRYPT_TYPE::ENCRYPT_TYPE_BLOWFISH)
492+
if (pArgs_->networkEncryptType == NETWORK_ENCRYPT_TYPE::ENCRYPT_TYPE_BLOWFISH)
460493
{
461494
pFilter_ = new BlowfishFilter();
462495
encryptedKey_ = ((BlowfishFilter*)pFilter_)->key();

Plugins/kbengine_ue4_plugins/Source/KBEnginePlugins/Engine/KBEngine.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "KBECommon.h"
66
#include "ServerErrorDescrs.h"
77
#include "Interfaces.h"
8+
#include "KBETicker.h"
89

910
class KBEngineArgs;
1011
class Entity;
@@ -29,7 +30,7 @@ class KBENGINEPLUGINS_API KBEngineApp : public InterfaceConnect
2930

3031
public:
3132
static KBEngineApp& getSingleton();
32-
33+
static void destroyKBEngineApp();
3334
public:
3435
bool isInitialized() const {
3536
return pArgs_ != NULL;
@@ -38,6 +39,9 @@ class KBENGINEPLUGINS_API KBEngineApp : public InterfaceConnect
3839
bool initialize(KBEngineArgs* pArgs);
3940
void destroy();
4041
void reset();
42+
43+
void installUKBETicker();
44+
void uninstallUKBETicker();
4145

4246
NetworkInterfaceBase* pNetworkInterface() const {
4347
return pNetworkInterface_;
@@ -510,6 +514,7 @@ class KBENGINEPLUGINS_API KBEngineApp : public InterfaceConnect
510514
FString component_;
511515

512516
EncryptionFilter *pFilter_;
517+
UKBETicker *pUKBETicker_;
513518

514519
};
515520

Plugins/kbengine_ue4_plugins/Source/KBEnginePlugins/Engine/KBEventTypes.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const FString KBEventTypes::onDelSpaceData = "onDelSpaceData";
3838
const FString KBEventTypes::onControlled = "onControlled";
3939
const FString KBEventTypes::onLoseControlledEntity = "onLoseControlledEntity";
4040

41-
4241
// ------------------------------------数据下载相关------------------------------------
4342
const FString KBEventTypes::onStreamDataStarted = "onStreamDataStarted";
4443
const FString KBEventTypes::onStreamDataRecv = "onStreamDataRecv";

0 commit comments

Comments
 (0)