Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ KBEngineApp::KBEngineApp() :
serverScriptVersion_(TEXT("")),
clientScriptVersion_(TEXT("")),
serverProtocolMD5_(TEXT("13AF19B0A958067AEB2BC4ED1CD3B46F")),
serverEntitydefMD5_(TEXT("2B445B443EFC9427000733CD39EB2700")),
serverEntitydefMD5_(TEXT("D9BE27DA40153A58EFB4835189190B5D")),
entity_uuid_(0),
entity_id_(0),
entity_type_(TEXT("")),
Expand Down Expand Up @@ -81,7 +81,7 @@ KBEngineApp::KBEngineApp(KBEngineArgs* pArgs):
serverScriptVersion_(TEXT("")),
clientScriptVersion_(TEXT("")),
serverProtocolMD5_(TEXT("13AF19B0A958067AEB2BC4ED1CD3B46F")),
serverEntitydefMD5_(TEXT("2B445B443EFC9427000733CD39EB2700")),
serverEntitydefMD5_(TEXT("D9BE27DA40153A58EFB4835189190B5D")),
entity_uuid_(0),
entity_id_(0),
entity_type_(TEXT("")),
Expand Down Expand Up @@ -2321,19 +2321,19 @@ void KBEngineApp::_updateVolatileData(ENTITY_ID entityID, float x, float y, floa
if (roll != KBE_FLT_MAX)
{
changeDirection = true;
entity.direction.X = int82angle((int8)roll, false);
entity.direction.X = isOptimized ? int82angle((int8)roll, false) : roll;
}

if (pitch != KBE_FLT_MAX)
{
changeDirection = true;
entity.direction.Y = int82angle((int8)pitch, false);
entity.direction.Y = isOptimized ? int82angle((int8)pitch, false) : pitch;
}

if (yaw != KBE_FLT_MAX)
{
changeDirection = true;
entity.direction.Z = int82angle((int8)yaw, false);
entity.direction.Z = isOptimized ? int82angle((int8)yaw, false) : yaw;
}

bool done = false;
Expand All @@ -2347,10 +2347,10 @@ void KBEngineApp::_updateVolatileData(ENTITY_ID entityID, float x, float y, floa
done = true;
}

bool positionChanged = x != KBE_FLT_MAX || y != KBE_FLT_MAX || z != KBE_FLT_MAX;
if (x == KBE_FLT_MAX) x = 0.0f;
if (y == KBE_FLT_MAX) y = 0.0f;
if (z == KBE_FLT_MAX) z = 0.0f;
bool positionChanged = x != KBE_FLT_MAX || y != KBE_FLT_MAX || z != KBE_FLT_MAX;
if (x == KBE_FLT_MAX) x = isOptimized ? 0.0f : entity.position.X;
if (y == KBE_FLT_MAX) y = isOptimized ? 0.0f : entity.position.Y;
if (z == KBE_FLT_MAX) z = isOptimized ? 0.0f : entity.position.Z;

if (positionChanged)
{
Expand Down
13 changes: 8 additions & 5 deletions Source/kbengine_ue4_demo/GameModeWorld.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Fill out your copyright notice in the Description page of Project Settings.
// Fill out your copyright notice in the Description page of Project Settings.

#include "GameModeWorld.h"
#include "kbengine_ue4_demo.h"
Expand All @@ -19,7 +19,7 @@ void AGameModeWorld::installEvents()
Super::installEvents();

// in world
// 这个事件触发时我们需要切换地图到游戏世界地图
// ����¼�����ʱ������Ҫ�л���ͼ����Ϸ�����ͼ
KBENGINE_REGISTER_EVENT(KBEngine::KBEventTypes::addSpaceGeometryMapping, addSpaceGeometryMapping);
KBENGINE_REGISTER_EVENT(KBEngine::KBEventTypes::onEnterWorld, onEnterWorld);
KBENGINE_REGISTER_EVENT(KBEngine::KBEventTypes::onLeaveWorld, onLeaveWorld);
Expand Down Expand Up @@ -57,8 +57,8 @@ void AGameModeWorld::BeginPlay()

check(KBEngine::KBEngineApp::getSingleton().isInitialized());

// 如果已经有被创建的实体,说明他们在上一个场景未来得及跳转之前已经通知创建了,但由于我们的world场景并没有来得及创建,这部分实体进入世界事件已经漏掉
// 此时我们需要再次触发一次onEnterWorld,让表现层能够在游戏场景中创建出所有的实体
// ����Ѿ��б�������ʵ�壬˵����������һ������δ���ü���ת֮ǰ�Ѿ�֪ͨ�����ˣ����������ǵ�world������û�����ü��������ⲿ��ʵ����������¼��Ѿ�©��
// ��ʱ������Ҫ�ٴδ���һ��onEnterWorld���ñ��ֲ��ܹ�����Ϸ�����д��������е�ʵ��
KBEngine::KBEngineApp::ENTITIES_MAP& entities = KBEngine::KBEngineApp::getSingleton().entities();
for (auto& item : entities)
{
Expand All @@ -80,7 +80,7 @@ void AGameModeWorld::BeginPlay()

void AGameModeWorld::reqRelive(int reliveType)
{
// 由于玩家的Avatar实体注册了该事件, 如果此时Avatar实体存在那么必然会执行到该事件
// ������ҵ�Avatarʵ��ע���˸��¼��� �����ʱAvatarʵ�������ô��Ȼ��ִ�е����¼�
UKBEventData_reqRelive* pEventData = NewObject<UKBEventData_reqRelive>();
pEventData->reliveType = reliveType;
KBENGINE_EVENT_FIRE("relive", pEventData);
Expand Down Expand Up @@ -115,6 +115,7 @@ void AGameModeWorld::onEnterWorld_Implementation(const UKBEventData* pEventData)
const UKBEventData_onEnterWorld* pData = Cast<UKBEventData_onEnterWorld>(pEventData);

FRotator Rot(0.f, 0.f, 0.f);
KBDir2UE4Dir(Rot, pData->direction);
FTransform SpawnTransform(Rot, pData->position);

if (pData->isPlayer)
Expand Down Expand Up @@ -157,6 +158,7 @@ void AGameModeWorld::onEnterSpace_Implementation(const UKBEventData* pEventData)
const UKBEventData_onEnterSpace* pData = Cast<UKBEventData_onEnterSpace>(pEventData);

FRotator Rot(0.f, 0.f, 0.f);
KBDir2UE4Dir(Rot, pData->direction);
FTransform SpawnTransform(Rot, pData->position);

if (pData->isPlayer)
Expand Down Expand Up @@ -280,6 +282,7 @@ void AGameModeWorld::set_modelID_Implementation(const UKBEventData* pEventData)
{
const UKBEventData_set_modelID* pData = Cast<UKBEventData_set_modelID>(pEventData);
AGameEntity* pAGameEntity = findGameEntity(pData->entityID);

if (pAGameEntity)
pAGameEntity->setModelID(pData->modelID);
}
Expand Down