本文整理汇总了C++中PlayerSAO类的典型用法代码示例。如果您正苦于以下问题:C++ PlayerSAO类的具体用法?C++ PlayerSAO怎么用?C++ PlayerSAO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PlayerSAO类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getplayersao
RemotePlayer *ObjectRef::getplayer(ObjectRef *ref)
{
PlayerSAO *playersao = getplayersao(ref);
if (playersao == NULL)
return NULL;
return playersao->getPlayer();
}
示例2: DSTACK
void Server::SendPlayerBreath(u16 peer_id)
{
DSTACK(FUNCTION_NAME);
PlayerSAO *playersao = getPlayerSAO(peer_id);
if (!playersao)
return;
m_script->player_event(playersao, "breath_changed");
SendBreath(peer_id, playersao->getBreath());
}
示例3: checkobject
// get_look_yaw2(self)
int ObjectRef::l_get_look_horizontal(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
PlayerSAO* co = getplayersao(ref);
if (co == NULL) return 0;
// Do it
lua_pushnumber(L, co->getRadRotation().Y);
return 1;
}
示例4: checkobject
// set_look_yaw(self, radians)
int ObjectRef::l_set_look_yaw(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
PlayerSAO* co = getplayersao(ref);
if (co == NULL) return 0;
float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
// Do it
co->setYaw(yaw);
return 1;
}
示例5: checkobject
// get_look_dir(self)
int ObjectRef::l_get_look_dir(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
PlayerSAO* co = getplayersao(ref);
if (co == NULL) return 0;
// Do it
float pitch = co->getRadPitchDep();
float yaw = co->getRadYawDep();
v3f v(cos(pitch)*cos(yaw), sin(pitch), cos(pitch)*sin(yaw));
push_v3f(L, v);
return 1;
}
示例6: log_deprecated
// DEPRECATED
// get_look_yaw(self)
int ObjectRef::l_get_look_yaw(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
log_deprecated(L,
"Deprecated call to get_look_yaw, use get_look_horizontal instead");
ObjectRef *ref = checkobject(L, 1);
PlayerSAO* co = getplayersao(ref);
if (co == NULL) return 0;
// Do it
lua_pushnumber(L, co->getRadYawDep());
return 1;
}
示例7: log_deprecated
// DEPRECATED
// set_look_yaw(self, radians)
int ObjectRef::l_set_look_yaw(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
log_deprecated(L,
"Deprecated call to set_look_yaw, use set_look_horizontal instead.");
ObjectRef *ref = checkobject(L, 1);
PlayerSAO* co = getplayersao(ref);
if (co == NULL) return 0;
float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
// Do it
co->setYawAndSend(yaw);
return 1;
}
示例8: checkobject
// get_nametag_attributes(self)
int ObjectRef::l_get_nametag_attributes(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
PlayerSAO *playersao = getplayersao(ref);
if (playersao == NULL)
return 0;
video::SColor color = playersao->getNametagColor();
lua_newtable(L);
push_ARGB8(L, color);
lua_setfield(L, -2, "color");
return 1;
}
示例9: getClient
void Server::handleCommand_ClientReady(NetworkPacket* pkt) {
const auto peer_id = pkt->getPeerId();
auto & packet = *(pkt->packet);
u16 peer_proto_ver = getClient(peer_id, CS_InitDone)->net_proto_version;
// clients <= protocol version 22 did not send ready message,
// they're already initialized
if (peer_proto_ver <= 22) {
infostream << "Client sent message not expected by a "
<< "client using protocol version <= 22,"
<< "disconnecting peer_id: " << peer_id << std::endl;
m_con.DisconnectPeer(peer_id);
return;
}
PlayerSAO* playersao = StageTwoClientInit(peer_id);
// If failed, cancel
if (playersao == NULL) {
errorstream
<< "TOSERVER_CLIENT_READY stage 2 client init failed for peer_id: "
<< peer_id << std::endl;
m_con.DisconnectPeer(peer_id);
return;
}
int version_patch = 0, version_tweak = 0;
packet.convert_safe(TOSERVER_CLIENT_READY_VERSION_PATCH, version_patch);
packet.convert_safe(TOSERVER_CLIENT_READY_VERSION_TWEAK, version_tweak);
if (version_tweak) {} //no warn todo remove
m_clients.setClientVersion(
peer_id,
packet[TOSERVER_CLIENT_READY_VERSION_MAJOR].as<int>(),
packet[TOSERVER_CLIENT_READY_VERSION_MINOR].as<int>(),
version_patch,
//version_tweak,
packet[TOSERVER_CLIENT_READY_VERSION_STRING].as<std::string>()
);
m_clients.event(peer_id, CSE_SetClientReady);
m_script->on_joinplayer(playersao);
stat.add("join", playersao->getPlayer()->getName());
}
示例10: checkobject
// setvelocity(self, {x=num, y=num, z=num})
int ObjectRef::l_setvelocity(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
v3f pos = checkFloatPos(L, 2);
PlayerSAO* ps = getplayersao(ref);
if (ps) {
ps->addSpeed(pos);
return 0;
}
LuaEntitySAO *co = getluaobject(ref);
if (co == NULL) return 0;
// Do it
co->setVelocity(pos);
return 0;
}
示例11:
void PlayerDatabaseSQLite3::savePlayer(RemotePlayer *player)
{
PlayerSAO* sao = player->getPlayerSAO();
sanity_check(sao);
const v3f &pos = sao->getBasePosition();
// Begin save in brace is mandatory
if (!playerDataExists(player->getName())) {
beginSave();
str_to_sqlite(m_stmt_player_add, 1, player->getName());
double_to_sqlite(m_stmt_player_add, 2, sao->getPitch());
double_to_sqlite(m_stmt_player_add, 3, sao->getYaw());
double_to_sqlite(m_stmt_player_add, 4, pos.X);
double_to_sqlite(m_stmt_player_add, 5, pos.Y);
double_to_sqlite(m_stmt_player_add, 6, pos.Z);
int64_to_sqlite(m_stmt_player_add, 7, sao->getHP());
int64_to_sqlite(m_stmt_player_add, 8, sao->getBreath());
sqlite3_vrfy(sqlite3_step(m_stmt_player_add), SQLITE_DONE);
sqlite3_reset(m_stmt_player_add);
} else {
beginSave();
double_to_sqlite(m_stmt_player_update, 1, sao->getPitch());
double_to_sqlite(m_stmt_player_update, 2, sao->getYaw());
double_to_sqlite(m_stmt_player_update, 3, pos.X);
double_to_sqlite(m_stmt_player_update, 4, pos.Y);
double_to_sqlite(m_stmt_player_update, 5, pos.Z);
int64_to_sqlite(m_stmt_player_update, 6, sao->getHP());
int64_to_sqlite(m_stmt_player_update, 7, sao->getBreath());
str_to_sqlite(m_stmt_player_update, 8, player->getName());
sqlite3_vrfy(sqlite3_step(m_stmt_player_update), SQLITE_DONE);
sqlite3_reset(m_stmt_player_update);
}
// Write player inventories
str_to_sqlite(m_stmt_player_remove_inventory, 1, player->getName());
sqlite3_vrfy(sqlite3_step(m_stmt_player_remove_inventory), SQLITE_DONE);
sqlite3_reset(m_stmt_player_remove_inventory);
str_to_sqlite(m_stmt_player_remove_inventory_items, 1, player->getName());
sqlite3_vrfy(sqlite3_step(m_stmt_player_remove_inventory_items), SQLITE_DONE);
sqlite3_reset(m_stmt_player_remove_inventory_items);
std::vector<const InventoryList*> inventory_lists = sao->getInventory()->getLists();
for (u16 i = 0; i < inventory_lists.size(); i++) {
const InventoryList* list = inventory_lists[i];
str_to_sqlite(m_stmt_player_add_inventory, 1, player->getName());
int_to_sqlite(m_stmt_player_add_inventory, 2, i);
int_to_sqlite(m_stmt_player_add_inventory, 3, list->getWidth());
str_to_sqlite(m_stmt_player_add_inventory, 4, list->getName());
int_to_sqlite(m_stmt_player_add_inventory, 5, list->getSize());
sqlite3_vrfy(sqlite3_step(m_stmt_player_add_inventory), SQLITE_DONE);
sqlite3_reset(m_stmt_player_add_inventory);
for (u32 j = 0; j < list->getSize(); j++) {
std::ostringstream os;
list->getItem(j).serialize(os);
std::string itemStr = os.str();
str_to_sqlite(m_stmt_player_add_inventory_items, 1, player->getName());
int_to_sqlite(m_stmt_player_add_inventory_items, 2, i);
int_to_sqlite(m_stmt_player_add_inventory_items, 3, j);
str_to_sqlite(m_stmt_player_add_inventory_items, 4, itemStr);
sqlite3_vrfy(sqlite3_step(m_stmt_player_add_inventory_items), SQLITE_DONE);
sqlite3_reset(m_stmt_player_add_inventory_items);
}
}
str_to_sqlite(m_stmt_player_metadata_remove, 1, player->getName());
sqlite3_vrfy(sqlite3_step(m_stmt_player_metadata_remove), SQLITE_DONE);
sqlite3_reset(m_stmt_player_metadata_remove);
const PlayerAttributes &attrs = sao->getExtendedAttributes();
for (PlayerAttributes::const_iterator it = attrs.begin(); it != attrs.end(); ++it) {
str_to_sqlite(m_stmt_player_metadata_add, 1, player->getName());
str_to_sqlite(m_stmt_player_metadata_add, 2, it->first);
str_to_sqlite(m_stmt_player_metadata_add, 3, it->second);
sqlite3_vrfy(sqlite3_step(m_stmt_player_metadata_add), SQLITE_DONE);
sqlite3_reset(m_stmt_player_metadata_add);
}
endSave();
}
示例12: DSTACK
void RemoteClient::GetNextBlocks (
ServerEnvironment *env,
EmergeManager * emerge,
float dtime,
std::vector<PrioritySortedBlockTransfer> &dest)
{
DSTACK(FUNCTION_NAME);
// Increment timers
m_nothing_to_send_pause_timer -= dtime;
m_nearest_unsent_reset_timer += dtime;
if(m_nothing_to_send_pause_timer >= 0)
return;
RemotePlayer *player = env->getPlayer(peer_id);
// This can happen sometimes; clients and players are not in perfect sync.
if (!player)
return;
PlayerSAO *sao = player->getPlayerSAO();
if (!sao)
return;
// Won't send anything if already sending
if(m_blocks_sending.size() >= g_settings->getU16
("max_simultaneous_block_sends_per_client"))
{
//infostream<<"Not sending any blocks, Queue full."<<std::endl;
return;
}
v3f playerpos = sao->getBasePosition();
const v3f &playerspeed = player->getSpeed();
v3f playerspeeddir(0,0,0);
if(playerspeed.getLength() > 1.0*BS)
playerspeeddir = playerspeed / playerspeed.getLength();
// Predict to next block
v3f playerpos_predicted = playerpos + playerspeeddir*MAP_BLOCKSIZE*BS;
v3s16 center_nodepos = floatToInt(playerpos_predicted, BS);
v3s16 center = getNodeBlockPos(center_nodepos);
// Camera position and direction
v3f camera_pos = sao->getEyePosition();
v3f camera_dir = v3f(0,0,1);
camera_dir.rotateYZBy(sao->getPitch());
camera_dir.rotateXZBy(sao->getYaw());
/*infostream<<"camera_dir=("<<camera_dir.X<<","<<camera_dir.Y<<","
<<camera_dir.Z<<")"<<std::endl;*/
/*
Get the starting value of the block finder radius.
*/
if(m_last_center != center)
{
m_nearest_unsent_d = 0;
m_last_center = center;
}
/*infostream<<"m_nearest_unsent_reset_timer="
<<m_nearest_unsent_reset_timer<<std::endl;*/
// Reset periodically to workaround for some bugs or stuff
if(m_nearest_unsent_reset_timer > 20.0)
{
m_nearest_unsent_reset_timer = 0;
m_nearest_unsent_d = 0;
//infostream<<"Resetting m_nearest_unsent_d for "
// <<server->getPlayerName(peer_id)<<std::endl;
}
//s16 last_nearest_unsent_d = m_nearest_unsent_d;
s16 d_start = m_nearest_unsent_d;
//infostream<<"d_start="<<d_start<<std::endl;
u16 max_simul_sends_setting = g_settings->getU16
("max_simultaneous_block_sends_per_client");
u16 max_simul_sends_usually = max_simul_sends_setting;
/*
Check the time from last addNode/removeNode.
Decrease send rate if player is building stuff.
*/
m_time_from_building += dtime;
if(m_time_from_building < g_settings->getFloat(
"full_block_send_enable_min_time_from_building"))
{
max_simul_sends_usually
= LIMITED_MAX_SIMULTANEOUS_BLOCK_SENDS;
}
/*
Number of blocks sending + number of blocks selected for sending
//.........这里部分代码省略.........
示例13: DSTACK
//.........这里部分代码省略.........
Answer with a TOCLIENT_INIT
*/
{
MSGPACK_PACKET_INIT(TOCLIENT_INIT, 4);
PACK(TOCLIENT_INIT_DEPLOYED, deployed);
PACK(TOCLIENT_INIT_SEED, m_env->getServerMap().getSeed());
PACK(TOCLIENT_INIT_STEP, g_settings->getFloat("dedicated_server_step"));
//if (player) //todo : remake me
// PACK(TOCLIENT_INIT_POS, player->getPosition());
Settings params;
m_emerge->params.save(params);
PACK(TOCLIENT_INIT_MAP_PARAMS, params);
// Send as reliable
m_clients.send(peer_id, 0, buffer, true);
m_clients.event(peer_id, CSE_Init);
}
return;
}
if(command == TOSERVER_INIT2)
{
verbosestream<<"Server: Got TOSERVER_INIT2 from "
<<peer_id<<std::endl;
m_clients.event(peer_id, CSE_GotInit2);
u16 protocol_version = m_clients.getProtocolVersion(peer_id);
///// begin compatibility code
PlayerSAO* playersao = NULL;
if (protocol_version <= 22) {
playersao = StageTwoClientInit(peer_id);
if (playersao == NULL) {
errorstream
<< "TOSERVER_INIT2 stage 2 client init failed for peer "
<< peer_id << std::endl;
return;
}
}
///// end compatibility code
/*
Send some initialization data
*/
infostream<<"Server: Sending content to "
<<getPlayerName(peer_id)<<std::endl;
// Send player movement settings
SendMovement(peer_id);
// Send item definitions
SendItemDef(peer_id, m_itemdef, protocol_version);
// Send node definitions
SendNodeDef(peer_id, m_nodedef, protocol_version);
m_clients.event(peer_id, CSE_SetDefinitionsSent);
// Send media announcement
sendMediaAnnouncement(peer_id);
示例14: savePlayer
void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
{
PlayerSAO* sao = player->getPlayerSAO();
if (!sao)
return;
verifyDatabase();
v3f pos = sao->getBasePosition();
std::string pitch = ftos(sao->getPitch());
std::string yaw = ftos(sao->getYaw());
std::string posx = ftos(pos.X);
std::string posy = ftos(pos.Y);
std::string posz = ftos(pos.Z);
std::string hp = itos(sao->getHP());
std::string breath = itos(sao->getBreath());
const char *values[] = {
player->getName(),
pitch.c_str(),
yaw.c_str(),
posx.c_str(), posy.c_str(), posz.c_str(),
hp.c_str(),
breath.c_str()
};
const char* rmvalues[] = { player->getName() };
beginSave();
if (getPGVersion() < 90500) {
if (!playerDataExists(player->getName()))
execPrepared("create_player", 8, values, true, false);
else
execPrepared("update_player", 8, values, true, false);
}
else
execPrepared("save_player", 8, values, true, false);
// Write player inventories
execPrepared("remove_player_inventories", 1, rmvalues);
execPrepared("remove_player_inventory_items", 1, rmvalues);
std::vector<const InventoryList*> inventory_lists = sao->getInventory()->getLists();
for (u16 i = 0; i < inventory_lists.size(); i++) {
const InventoryList* list = inventory_lists[i];
const std::string &name = list->getName();
std::string width = itos(list->getWidth()),
inv_id = itos(i), lsize = itos(list->getSize());
const char* inv_values[] = {
player->getName(),
inv_id.c_str(),
width.c_str(),
name.c_str(),
lsize.c_str()
};
execPrepared("add_player_inventory", 5, inv_values);
for (u32 j = 0; j < list->getSize(); j++) {
std::ostringstream os;
list->getItem(j).serialize(os);
std::string itemStr = os.str(), slotId = itos(j);
const char* invitem_values[] = {
player->getName(),
inv_id.c_str(),
slotId.c_str(),
itemStr.c_str()
};
execPrepared("add_player_inventory_item", 4, invitem_values);
}
}
execPrepared("remove_player_metadata", 1, rmvalues);
const StringMap &attrs = sao->getMeta().getStrings();
for (const auto &attr : attrs) {
const char *meta_values[] = {
player->getName(),
attr.first.c_str(),
attr.second.c_str()
};
execPrepared("save_player_metadata", 3, meta_values);
}
sao->getMeta().setModified(false);
endSave();
}