This commit is contained in:
aozhiwei 2023-12-12 18:44:58 +08:00
parent c25c30c765
commit 564851eae8
7 changed files with 26 additions and 10 deletions

View File

@ -1,5 +1,8 @@
#include "precompile.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <a8/mutable_xobject.h>
#include <a8/websocketclient.h>
@ -33,7 +36,6 @@ behaviac::EBTStatus AndroidAgent::SearchEnemy(int range)
bool AndroidAgent::NetIsConnected()
{
a8::XPrintf("NetIsConnected\n", {});
return true;
return owner_->GetWebSocket()->Connected() != 0;
}
@ -134,7 +136,6 @@ behaviac::EBTStatus AndroidAgent::CoLogin()
behaviac::EBTStatus AndroidAgent::CoConnectBattleServer()
{
PRE_ENTER_COROUTINE();
a8::XPrintf("CoConnectBattleServer socket_id:%d\n", {owner_->GetSocketId()});
auto context = MAKE_BTCONTEXT
(
std::function<void (a8::WebSocketClient*, int)> old_on_error;
@ -158,7 +159,7 @@ behaviac::EBTStatus AndroidAgent::CoConnectBattleServer()
owner_->GetWebSocket()->on_connect =
[this, context] (a8::WebSocketClient* )
{
a8::XPrintf("id:%d WebSocketClient on_connect\n", {context->socket_id});
//a8::XPrintf("id:%d WebSocketClient on_connect\n", {context->socket_id});
context->pending = false;
context->connect_ok = true;
};
@ -219,6 +220,7 @@ behaviac::EBTStatus AndroidAgent::CoJoin()
if (!owner_->IsJoinOk()) {
return behaviac::BT_RUNNING;
}
++Perf::Instance()->join_ok_times;
return behaviac::BT_SUCCESS;
};
return StartCoroutine(co);
@ -236,11 +238,15 @@ behaviac::EBTStatus AndroidAgent::CoUpdateGame()
#if 1
++Perf::Instance()->update_times;
if (owner_->GetWebSocket()->Connected()) {
std::shared_ptr<glm::vec3> sand_table_target_pos;
if (a8::XGetTickCount() - last_dir_tick_ > 3000) {
curr_dir_ = glm::vec3(0.0f, 0.0f, 1.0f);
GlmHelper::RotateY(curr_dir_, a8::RandAngle());
GlmHelper::RotateY(curr_dir_, glm::radians((float(rand() % 360))));
last_dir_tick_ = a8::XGetTickCount();
++Perf::Instance()->chg_dir_times;
sand_table_target_pos = std::make_shared<glm::vec3>(0.0f, 0.0f, 0.0f);
sand_table_target_pos->x = a8::RandEx(100, 2000);
sand_table_target_pos->z = a8::RandEx(100, 2000);
}
if (a8::XGetTickCount() - last_send_tick_ > 80) {
last_send_tick_ = a8::XGetTickCount();
@ -249,6 +255,9 @@ behaviac::EBTStatus AndroidAgent::CoUpdateGame()
cs::CMMove msg;
ToPb(curr_dir_, msg.mutable_move_dir());
ToPb(curr_dir_, msg.mutable_attack_dir());
if (sand_table_target_pos) {
ToPb(*sand_table_target_pos.get(), msg.mutable_sand_table_target_pos());
}
msg.set_shot_start(1);
msg.set_shot_hold(1);
owner_->SendMsg(msg);
@ -259,7 +268,7 @@ behaviac::EBTStatus AndroidAgent::CoUpdateGame()
}
}
} else {
a8::XPrintf("disconnect\n", {});
//a8::XPrintf("disconnect\n", {});
}
#endif
return behaviac::BT_SUCCESS;

View File

@ -1,6 +1,8 @@
#include "precompile.h"
#include "base_agent.h"
#include "tracemgr.h"
#include "perf.h"
#include <f8/btmgr.h>

View File

@ -25,7 +25,7 @@ void Perf::UnInit()
void Perf::Output()
{
f8::UdpLog::Instance()->Info
("perf login_ok:%d login_fail:%d enter_ok:%d enter_fail:%d connect_ok:%d connect_fail:%d chg_dir:%d send_move:%d update:%d",
("perf login_ok:%d login_fail:%d enter_ok:%d enter_fail:%d connect_ok:%d connect_fail:%d join_ok:%d chg_dir:%d send_move:%d update:%d",
{
login_ok_times,
login_fail_times,
@ -33,6 +33,7 @@ void Perf::Output()
enter_fail_times,
connect_ok_times,
connect_fail_times,
join_ok_times,
chg_dir_times,
send_move_times,
update_times

View File

@ -19,11 +19,11 @@ private:
long long enter_fail_times = 0;
long long connect_ok_times = 0;
long long connect_fail_times = 0;
long long join_ok_times = 0;
long long chg_dir_times = 0;
long long send_move_times = 0;
long long update_times = 0;
private:
void Output();
};

View File

@ -15,8 +15,11 @@
void Player::Update()
{
if (agent_) {
agent_->Exec();
if (a8::XGetTickCount() - last_update_tick_ > 50) {
last_update_tick_ = a8::XGetTickCount();
if (agent_) {
agent_->Exec();
}
}
}

View File

@ -83,6 +83,7 @@ private:
bool is_login_success_ = false;
bool net_connected_ = false;
bool join_ok_ = false;
long long last_update_tick_ = 0;
std::shared_ptr<a8::WebSocketClient> web_socket_;

View File

@ -32,7 +32,7 @@ void PlayerMgr::Init()
account_id_hash_[hum->GetAccountId()] = hum;
socket_id_hash_[hum->GetSocketId()] = hum;
++count;
if (count >= 1) {
if (count >= 2000) {
f8::Timer::Instance()->DeleteCurrentTimer();
}
}