PumpCharacterUpdate() works from lua to client, read more

There was a bug in the entity API, where getMotion() was pushing the
origin instead of the motion. This has been corrected. Since this is an
important bug, and because the features for this leg is finished, I'll
merge this to master.
This commit is contained in:
Kayne Ruse
2015-02-27 02:39:27 +11:00
parent 067bf40be7
commit 4630b7e403
7 changed files with 79 additions and 7 deletions
+1
View File
@@ -96,6 +96,7 @@ protected:
void UpdateMap();
//character management
void hCharacterUpdate(CharacterPacket* const);
void hCharacterCreate(CharacterPacket* const);
void hCharacterDelete(CharacterPacket* const);
void hQueryCharacterExists(CharacterPacket* const);
@@ -35,6 +35,24 @@
//DOCS: new characters will result in create messages
//DOCS: this client's character will exist in both (skipped)
void World::hCharacterUpdate(CharacterPacket* const argPacket) {
//TODO: (1) Authentication
//NOTE: applies to the local character too
//check that this character exists
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt != characterMap.end()) {
//update the origin and motion, if there's a difference
if (characterIt->second.GetOrigin() != argPacket->origin) {
characterIt->second.SetOrigin(argPacket->origin);
}
if (characterIt->second.GetMotion() != argPacket->motion) {
characterIt->second.SetMotion(argPacket->motion);
characterIt->second.CorrectSprite(); //only correct the sprite if the motion changes
}
}
}
void World::hCharacterCreate(CharacterPacket* const argPacket) {
//prevent double message
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
+3
View File
@@ -335,6 +335,9 @@ void World::HandlePacket(SerialPacket* const argPacket) {
break;
//character management
case SerialPacketType::CHARACTER_UPDATE:
hCharacterUpdate(static_cast<CharacterPacket*>(argPacket));
break;
case SerialPacketType::CHARACTER_CREATE:
hCharacterCreate(static_cast<CharacterPacket*>(argPacket));
break;
+10 -2
View File
@@ -4,6 +4,7 @@ mapMaker = require("map_maker")
mapSaver = require("map_saver")
roomSystem = require("room_system")
characterSystem = require("character_system")
networkSystem = require("network")
local function dumpTable(t)
print(t)
@@ -18,12 +19,19 @@ roomSystem.RoomManager.SetOnCreate(function(room, index)
--called ~60 times per second
roomSystem.Room.SetOnTick(room, function(room)
--[[
local character = characterSystem.CharacterManager.GetCharacter("handle")
if character ~= nil then
--debugging
local x, y = characterSystem.Character.GetOrigin(character)
print("character.Origin(x, y): ", x, y)
local originX, originY = characterSystem.Character.GetOrigin(character)
local motionX, motionY = characterSystem.Character.GetMotion(character)
if motionY < 0 then
characterSystem.Character.SetMotion(character, motionX, 0)
networkSystem.PumpCharacterUpdate(character)
print("Sending: ", motionX, motionY)
end
end
--]]
end)
end)
+2 -2
View File
@@ -56,8 +56,8 @@ static int getOrigin(lua_State* L) {
static int getMotion(lua_State* L) {
Entity* entity = static_cast<Entity*>(lua_touserdata(L, 1));
lua_pushnumber(L, entity->GetOrigin().x);
lua_pushnumber(L, entity->GetOrigin().y);
lua_pushnumber(L, entity->GetMotion().x);
lua_pushnumber(L, entity->GetMotion().y);
return 2;
}
+38 -1
View File
@@ -21,8 +21,45 @@
*/
#include "network_api.hpp"
#include "character_data.hpp"
#include "character_manager.hpp"
#include "server_utilities.hpp"
static int pumpCharacterUpdate(lua_State* L) {
return 0;
CharacterData* characterData = static_cast<CharacterData*>(lua_touserdata(L, 1));
//determine the character's index
int index = -1;
for (auto const& it : *CharacterManager::GetSingleton().GetContainer()) {
if(characterData == &it.second) {
index = it.first;
break;
}
}
//signal an error
if (index == -1) {
lua_pushboolean(L, false);
return 1;
}
//fill the packet with all of this character's data
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
newPacket.characterIndex = index;
strncpy(newPacket.handle, characterData->GetHandle().c_str(), PACKET_STRING_SIZE);
strncpy(newPacket.avatar, characterData->GetAvatar().c_str(), PACKET_STRING_SIZE);
newPacket.accountIndex = characterData->GetOwner();
newPacket.roomIndex = characterData->GetRoomIndex();
newPacket.origin = characterData->GetOrigin();
newPacket.motion = characterData->GetMotion();
//pump to the room
pumpPacketProximity(&newPacket, characterData->GetRoomIndex());
//signal success
lua_pushboolean(L, true);
return 1;
}
static const luaL_Reg networkLib[] = {
+7 -2
View File
@@ -183,10 +183,15 @@ void ServerApplication::hCharacterUnload(CharacterPacket* const argPacket) {
void ServerApplication::hCharacterMovement(CharacterPacket* const argPacket) {
//get the specified objects
AccountData* accountData = accountMgr.Get(argPacket->accountIndex);
if (!accountData) {
throw(std::runtime_error("Failed to move a character, missing account"));
}
CharacterData* characterData = characterMgr.Get(argPacket->characterIndex);
if (!accountData || !characterData) {
throw(std::runtime_error("Failed to move a character, missing data"));
if (!characterData) {
throw(std::runtime_error("Failed to move a character, missing character"));
}
//get this account's client