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:
@@ -96,6 +96,7 @@ protected:
|
|||||||
void UpdateMap();
|
void UpdateMap();
|
||||||
|
|
||||||
//character management
|
//character management
|
||||||
|
void hCharacterUpdate(CharacterPacket* const);
|
||||||
void hCharacterCreate(CharacterPacket* const);
|
void hCharacterCreate(CharacterPacket* const);
|
||||||
void hCharacterDelete(CharacterPacket* const);
|
void hCharacterDelete(CharacterPacket* const);
|
||||||
void hQueryCharacterExists(CharacterPacket* const);
|
void hQueryCharacterExists(CharacterPacket* const);
|
||||||
|
|||||||
@@ -35,6 +35,24 @@
|
|||||||
//DOCS: new characters will result in create messages
|
//DOCS: new characters will result in create messages
|
||||||
//DOCS: this client's character will exist in both (skipped)
|
//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) {
|
void World::hCharacterCreate(CharacterPacket* const argPacket) {
|
||||||
//prevent double message
|
//prevent double message
|
||||||
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
|
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
|
||||||
|
|||||||
@@ -335,6 +335,9 @@ void World::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
//character management
|
//character management
|
||||||
|
case SerialPacketType::CHARACTER_UPDATE:
|
||||||
|
hCharacterUpdate(static_cast<CharacterPacket*>(argPacket));
|
||||||
|
break;
|
||||||
case SerialPacketType::CHARACTER_CREATE:
|
case SerialPacketType::CHARACTER_CREATE:
|
||||||
hCharacterCreate(static_cast<CharacterPacket*>(argPacket));
|
hCharacterCreate(static_cast<CharacterPacket*>(argPacket));
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ mapMaker = require("map_maker")
|
|||||||
mapSaver = require("map_saver")
|
mapSaver = require("map_saver")
|
||||||
roomSystem = require("room_system")
|
roomSystem = require("room_system")
|
||||||
characterSystem = require("character_system")
|
characterSystem = require("character_system")
|
||||||
|
networkSystem = require("network")
|
||||||
|
|
||||||
local function dumpTable(t)
|
local function dumpTable(t)
|
||||||
print(t)
|
print(t)
|
||||||
@@ -18,12 +19,19 @@ roomSystem.RoomManager.SetOnCreate(function(room, index)
|
|||||||
|
|
||||||
--called ~60 times per second
|
--called ~60 times per second
|
||||||
roomSystem.Room.SetOnTick(room, function(room)
|
roomSystem.Room.SetOnTick(room, function(room)
|
||||||
|
--[[
|
||||||
local character = characterSystem.CharacterManager.GetCharacter("handle")
|
local character = characterSystem.CharacterManager.GetCharacter("handle")
|
||||||
if character ~= nil then
|
if character ~= nil then
|
||||||
--debugging
|
--debugging
|
||||||
local x, y = characterSystem.Character.GetOrigin(character)
|
local originX, originY = characterSystem.Character.GetOrigin(character)
|
||||||
print("character.Origin(x, y): ", x, y)
|
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)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ static int getOrigin(lua_State* L) {
|
|||||||
|
|
||||||
static int getMotion(lua_State* L) {
|
static int getMotion(lua_State* L) {
|
||||||
Entity* entity = static_cast<Entity*>(lua_touserdata(L, 1));
|
Entity* entity = static_cast<Entity*>(lua_touserdata(L, 1));
|
||||||
lua_pushnumber(L, entity->GetOrigin().x);
|
lua_pushnumber(L, entity->GetMotion().x);
|
||||||
lua_pushnumber(L, entity->GetOrigin().y);
|
lua_pushnumber(L, entity->GetMotion().y);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-1
@@ -21,8 +21,45 @@
|
|||||||
*/
|
*/
|
||||||
#include "network_api.hpp"
|
#include "network_api.hpp"
|
||||||
|
|
||||||
|
#include "character_data.hpp"
|
||||||
|
#include "character_manager.hpp"
|
||||||
|
#include "server_utilities.hpp"
|
||||||
|
|
||||||
static int pumpCharacterUpdate(lua_State* L) {
|
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[] = {
|
static const luaL_Reg networkLib[] = {
|
||||||
|
|||||||
@@ -183,10 +183,15 @@ void ServerApplication::hCharacterUnload(CharacterPacket* const argPacket) {
|
|||||||
void ServerApplication::hCharacterMovement(CharacterPacket* const argPacket) {
|
void ServerApplication::hCharacterMovement(CharacterPacket* const argPacket) {
|
||||||
//get the specified objects
|
//get the specified objects
|
||||||
AccountData* accountData = accountMgr.Get(argPacket->accountIndex);
|
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);
|
CharacterData* characterData = characterMgr.Get(argPacket->characterIndex);
|
||||||
|
|
||||||
if (!accountData || !characterData) {
|
if (!characterData) {
|
||||||
throw(std::runtime_error("Failed to move a character, missing data"));
|
throw(std::runtime_error("Failed to move a character, missing character"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//get this account's client
|
//get this account's client
|
||||||
|
|||||||
Reference in New Issue
Block a user