forked from oerkki/voxelands
add dig animation to player
This commit is contained in:
parent
135d54f31d
commit
bcd316bab0
|
@ -1090,6 +1090,27 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
}
|
||||
} //envlock
|
||||
}
|
||||
else if(command == TOCLIENT_PLAYER_ANIMATION)
|
||||
{
|
||||
u16 peer_id = readU16(&data[2]);
|
||||
u8 anim_id = readU8(&data[4]);
|
||||
|
||||
Player *player = m_env.getPlayer(peer_id);
|
||||
|
||||
// Create a player if it doesn't exist
|
||||
if (player == NULL) {
|
||||
player = new RemotePlayer(
|
||||
m_device->getSceneManager()->getRootSceneNode(),
|
||||
m_device,
|
||||
-1);
|
||||
player->peer_id = peer_id;
|
||||
m_env.addPlayer(player);
|
||||
infostream<<"Client: Adding new player " <<peer_id<<std::endl;
|
||||
}
|
||||
|
||||
player->updateAnim(anim_id);
|
||||
player->updateName(player->getName());
|
||||
}
|
||||
else if(command == TOCLIENT_SECTORMETA)
|
||||
{
|
||||
infostream<<"Client received DEPRECATED TOCLIENT_SECTORMETA"<<std::endl;
|
||||
|
|
|
@ -70,7 +70,12 @@ enum ToClientCommand
|
|||
[N] char[20] name
|
||||
*/
|
||||
|
||||
TOCLIENT_OPT_BLOCK_NOT_FOUND = 0x25, // Obsolete
|
||||
TOCLIENT_PLAYER_ANIMATION = 0x25, // stolen from TOCLIENT_OPT_BLOCK_NOT_FOUND
|
||||
/*
|
||||
[0] u16 command
|
||||
[2] u16 peer_id
|
||||
[4] u8 animation_id
|
||||
*/
|
||||
|
||||
TOCLIENT_SECTORMETA = 0x26, // Obsolete
|
||||
/*
|
||||
|
|
|
@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "mesh.h"
|
||||
#endif
|
||||
#include "settings.h"
|
||||
#include "filesys.h"
|
||||
|
||||
Player::Player():
|
||||
touching_ground(false),
|
||||
|
@ -195,7 +196,8 @@ RemotePlayer::RemotePlayer(
|
|||
s32 id):
|
||||
scene::ISceneNode(parent, (device==NULL)?NULL:device->getSceneManager(), id),
|
||||
m_node(NULL),
|
||||
m_text(NULL)
|
||||
m_text(NULL),
|
||||
m_anim_id(PLAYERANIM_STAND)
|
||||
{
|
||||
m_box = core::aabbox3d<f32>(-BS/2,0,-BS/2,BS/2,BS*2,BS/2);
|
||||
|
||||
|
@ -255,7 +257,7 @@ void RemotePlayer::updateName(const char *name)
|
|||
m_text->setText(wname);
|
||||
}
|
||||
if (m_node != NULL) {
|
||||
std::string tex = std::string("players/player_")+name+".png";
|
||||
std::string tex = std::string("players") + DIR_DELIM + "player_" + name + ".png";
|
||||
std::string ptex = getTexturePath(tex);
|
||||
printf("'%s' '%s'\n",tex.c_str(),ptex.c_str());
|
||||
if (ptex == "")
|
||||
|
@ -293,11 +295,19 @@ void RemotePlayer::move(f32 dtime, Map &map, f32 pos_max_d)
|
|||
&& movevector.Z > -0.001
|
||||
)
|
||||
) {
|
||||
if (m_node->getEndFrame() != 79)
|
||||
if (m_anim_id == PLAYERANIM_DIG) {
|
||||
if (m_node->getEndFrame() != 198)
|
||||
m_node->setFrameLoop(189,198);
|
||||
}else if (m_node->getEndFrame() != 79) {
|
||||
m_node->setFrameLoop(0,79);
|
||||
}
|
||||
}else{
|
||||
if (m_node->getEndFrame() != 187)
|
||||
if (m_anim_id == PLAYERANIM_DIG) {
|
||||
if (m_node->getEndFrame() != 219)
|
||||
m_node->setFrameLoop(200,219);
|
||||
}else if (m_node->getEndFrame() != 187) {
|
||||
m_node->setFrameLoop(168,187);
|
||||
}
|
||||
}
|
||||
|
||||
ISceneNode::setPosition(m_showpos);
|
||||
|
|
12
src/player.h
12
src/player.h
|
@ -31,6 +31,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#define PLAYERNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
|
||||
|
||||
#define PLAYERANIM_STAND 0
|
||||
#define PLAYERANIM_WALK 1
|
||||
#define PLAYERANIM_DIG 2
|
||||
#define PLAYERANIM_WALKDIG 3
|
||||
#define PLAYERANIM_DIE 4
|
||||
|
||||
class Map;
|
||||
|
||||
class Player
|
||||
|
@ -133,6 +139,9 @@ public:
|
|||
light = light_at_pos;
|
||||
}
|
||||
|
||||
virtual void updateAnim(u8 anim_id)
|
||||
{}
|
||||
|
||||
// NOTE: Use peer_id == 0 for disconnected
|
||||
/*virtual bool isClientConnected() { return false; }
|
||||
virtual void setClientConnected(bool) {}*/
|
||||
|
@ -274,6 +283,8 @@ public:
|
|||
|
||||
void updateName(const char *name);
|
||||
|
||||
virtual void updateAnim(u8 anim_id) {m_anim_id = anim_id;}
|
||||
|
||||
virtual void updateLight(u8 light_at_pos)
|
||||
{
|
||||
Player::updateLight(light_at_pos);
|
||||
|
@ -298,6 +309,7 @@ private:
|
|||
f32 m_pos_animation_time;
|
||||
f32 m_pos_animation_time_counter;
|
||||
v3f m_showpos;
|
||||
u8 m_anim_id;
|
||||
};
|
||||
|
||||
#endif // !SERVER
|
||||
|
|
|
@ -2405,6 +2405,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
*/
|
||||
if(action == 0)
|
||||
{
|
||||
SendPlayerAnim(player,PLAYERANIM_DIG);
|
||||
MapNode n = m_env.getMap().getNodeNoEx(p_under);
|
||||
if (n.getContent() >= CONTENT_DOOR_MIN && n.getContent() <= CONTENT_DOOR_MAX) {
|
||||
v3s16 mp(0,1,0);
|
||||
|
@ -2559,6 +2560,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
*/
|
||||
else if(action == 2)
|
||||
{
|
||||
SendPlayerAnim(player,PLAYERANIM_STAND);
|
||||
#if 0
|
||||
RemoteClient *client = getClient(peer_id);
|
||||
JMutexAutoLock digmutex(client->m_dig_mutex);
|
||||
|
@ -3046,7 +3048,6 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
*/
|
||||
else if(action == 1)
|
||||
{
|
||||
|
||||
v3s16 p_dir = p_under - p_over;
|
||||
InventoryList *ilist = player->inventory.getList("main");
|
||||
if(ilist == NULL)
|
||||
|
@ -4299,6 +4300,25 @@ void Server::SendWieldedItem(const Player* player)
|
|||
m_con.SendToAll(0, data, true);
|
||||
}
|
||||
|
||||
void Server::SendPlayerAnim(const Player* player, u8 animation_id)
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
||||
assert(player);
|
||||
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
|
||||
writeU16(os, TOCLIENT_PLAYER_ANIMATION);
|
||||
writeU16(os, player->peer_id);
|
||||
writeU8(os, animation_id);
|
||||
|
||||
// Make data buffer
|
||||
std::string s = os.str();
|
||||
SharedBuffer<u8> data((u8*)s.c_str(), s.size());
|
||||
|
||||
m_con.SendToAll(0, data, true);
|
||||
}
|
||||
|
||||
void Server::SendPlayerItems()
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
|
|
@ -505,6 +505,7 @@ private:
|
|||
void SendInventory(u16 peer_id);
|
||||
// send wielded item info about player to all
|
||||
void SendWieldedItem(const Player *player);
|
||||
void SendPlayerAnim(const Player *player, u8 animation_id);
|
||||
// send wielded item info about all players to all players
|
||||
void SendPlayerItems();
|
||||
void SendChatMessage(u16 peer_id, const std::wstring &message);
|
||||
|
|
Loading…
Reference in New Issue