Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 29a09cf71f | |||
| e4d7ece99c | |||
| b2452fb6fe | |||
| 4579f9f388 | |||
| b4b7c0d877 | |||
| ebd8e54725 |
@@ -36,4 +36,12 @@ function mapMaker.debugIsland(region)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mapMaker.dirtLand(region)
|
||||||
|
for i = 1, mapSystem.Region.GetWidth(region) do
|
||||||
|
for j = 1, mapSystem.Region.GetHeight(region) do
|
||||||
|
mapSystem.Region.SetTile(region, i, j, 1, mapMaker.dirt)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return mapMaker
|
return mapMaker
|
||||||
@@ -22,6 +22,10 @@ mapSystem.RegionPager.SetOnSave(roomSystem.Room.GetPager(overworld), mapSaver.Sa
|
|||||||
mapSystem.RegionPager.SetOnCreate(roomSystem.Room.GetPager(overworld), mapMaker.debugIsland)
|
mapSystem.RegionPager.SetOnCreate(roomSystem.Room.GetPager(overworld), mapMaker.debugIsland)
|
||||||
mapSystem.RegionPager.SetOnUnload(roomSystem.Room.GetPager(overworld), mapSaver.Save)
|
mapSystem.RegionPager.SetOnUnload(roomSystem.Room.GetPager(overworld), mapSaver.Save)
|
||||||
|
|
||||||
|
--Dirt Land
|
||||||
|
local dirtLand = roomSystem.RoomManager.CreateRoom("dirt land", "overworld.bmp")
|
||||||
|
roomSystem.Room.Initialize(dirtLand, mapSaver.Load, mapSaver.Save, mapMaker.dirtLand, mapSaver.Save)
|
||||||
|
|
||||||
print("Finished the lua script")
|
print("Finished the lua script")
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
|||||||
@@ -30,9 +30,33 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
class CharacterData: public Entity {
|
class CharacterData: public Entity {
|
||||||
public:
|
public:
|
||||||
CharacterData() = default;
|
CharacterData() = default;
|
||||||
|
CharacterData(CharacterData const& rhs) {
|
||||||
|
std::cerr << "Character copy detected" << std::endl;
|
||||||
|
owner = rhs.owner;
|
||||||
|
handle = rhs.handle;
|
||||||
|
avatar = rhs.avatar;
|
||||||
|
|
||||||
|
//entity stuff
|
||||||
|
roomIndex = rhs.roomIndex;
|
||||||
|
origin = rhs.origin;
|
||||||
|
motion = rhs.motion;
|
||||||
|
}
|
||||||
|
CharacterData(CharacterData&& rhs) {
|
||||||
|
std::cerr << "Character move detected" << std::endl;
|
||||||
|
owner = rhs.owner;
|
||||||
|
handle = rhs.handle;
|
||||||
|
avatar = rhs.avatar;
|
||||||
|
|
||||||
|
//entity stuff
|
||||||
|
roomIndex = rhs.roomIndex;
|
||||||
|
origin = rhs.origin;
|
||||||
|
motion = rhs.motion;
|
||||||
|
}
|
||||||
~CharacterData() = default;
|
~CharacterData() = default;
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ CharacterData* CharacterManager::Get(int uid) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return &it->second;
|
return &(it->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CharacterManager::GetLoadedCount() {
|
int CharacterManager::GetLoadedCount() {
|
||||||
|
|||||||
@@ -56,8 +56,6 @@ static int getPager(lua_State* L) {
|
|||||||
static int initialize(lua_State* L) {
|
static int initialize(lua_State* L) {
|
||||||
//set the members of the given room
|
//set the members of the given room
|
||||||
RoomData* room = static_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = static_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
room->SetName(lua_tostring(L, 2));
|
|
||||||
room->SetTileset(lua_tostring(L, 3));
|
|
||||||
|
|
||||||
//set the refs of these parameters (backwards, since it pops from the top of the stack)
|
//set the refs of these parameters (backwards, since it pops from the top of the stack)
|
||||||
room->GetPager()->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
room->GetPager()->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
||||||
|
|||||||
@@ -24,6 +24,10 @@
|
|||||||
#include "room_api.hpp"
|
#include "room_api.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
//debug
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//public access methods
|
//public access methods
|
||||||
@@ -41,6 +45,47 @@ int RoomManager::Create(std::string roomName, std::string tileset) {
|
|||||||
return counter++;
|
return counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RoomManager::PushEntity(Entity const* entity) {
|
||||||
|
if (!entity) {
|
||||||
|
throw(std::runtime_error("Failed to push null entity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<int, RoomData>::iterator it = elementMap.find(entity->GetRoomIndex());
|
||||||
|
|
||||||
|
if (it == elementMap.end()) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
// msg << "Failed to push entity; Room index not found: " << entity->GetRoomIndex() << std::endl;
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
it->second.entityList.push_back(const_cast<Entity*>(entity));
|
||||||
|
|
||||||
|
std::cout << "\troom[" << it->first << "].entityList.size(): " << it->second.entityList.size() << std::endl;
|
||||||
|
std::cout << "\tEntity: " << int(entity) << "," << int(it->second.entityList.front()) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoomManager::PopEntity(Entity const* entity) {
|
||||||
|
if (!entity) {
|
||||||
|
throw(std::runtime_error("Failed to pop null entity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<int, RoomData>::iterator it = elementMap.find(entity->GetRoomIndex());
|
||||||
|
|
||||||
|
if (it == elementMap.end()) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to pop entity; Room index not found: " << entity->GetRoomIndex() << std::endl;
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
it->second.entityList.remove_if([entity](Entity* ptr) -> bool {
|
||||||
|
bool b = (entity == ptr);
|
||||||
|
std::cout << "\tmatch(" << int(ptr) << "," << int(entity) << "): " << b << std::endl;
|
||||||
|
return b;
|
||||||
|
});
|
||||||
|
|
||||||
|
std::cout << "\troom[" << it->first << "].entityList.size(): " << it->second.entityList.size() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
void RoomManager::UnloadAll() {
|
void RoomManager::UnloadAll() {
|
||||||
elementMap.clear();
|
elementMap.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#ifndef ROOMMANAGER_HPP_
|
#ifndef ROOMMANAGER_HPP_
|
||||||
#define ROOMMANAGER_HPP_
|
#define ROOMMANAGER_HPP_
|
||||||
|
|
||||||
|
#include "entity.hpp"
|
||||||
#include "room_data.hpp"
|
#include "room_data.hpp"
|
||||||
#include "singleton.hpp"
|
#include "singleton.hpp"
|
||||||
|
|
||||||
@@ -39,6 +40,9 @@ public:
|
|||||||
//common public methods
|
//common public methods
|
||||||
int Create(std::string name, std::string tileset);
|
int Create(std::string name, std::string tileset);
|
||||||
|
|
||||||
|
void PushEntity(Entity const* entity);
|
||||||
|
void PopEntity(Entity const* entity);
|
||||||
|
|
||||||
void UnloadAll();
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, RoomData const&>)> fn);
|
void UnloadIf(std::function<bool(std::pair<const int, RoomData const&>)> fn);
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//push this character to the rooms
|
||||||
|
// roomMgr.PushEntity(static_cast<Entity*>(characterMgr.Get(characterIndex)));
|
||||||
|
|
||||||
//pump this character to all clients
|
//pump this character to all clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
CopyCharacterToPacket(&newPacket, characterIndex);
|
CopyCharacterToPacket(&newPacket, characterIndex);
|
||||||
@@ -87,6 +90,7 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//delete the character
|
//delete the character
|
||||||
|
// roomMgr.PopEntity(static_cast<Entity*>(characterMgr.Get(characterIndex)));
|
||||||
characterMgr.Delete(characterIndex);
|
characterMgr.Delete(characterIndex);
|
||||||
|
|
||||||
//pump character delete
|
//pump character delete
|
||||||
@@ -119,6 +123,10 @@ void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//push this character to the rooms
|
||||||
|
std::cout << "pushing index " << characterIndex << std::endl;
|
||||||
|
roomMgr.PushEntity(static_cast<Entity*>(characterMgr.Get(characterIndex)));
|
||||||
|
|
||||||
//pump this character to all clients
|
//pump this character to all clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
CopyCharacterToPacket(&newPacket, characterIndex);
|
CopyCharacterToPacket(&newPacket, characterIndex);
|
||||||
@@ -150,6 +158,8 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//unload the character
|
//unload the character
|
||||||
|
std::cout << "poping index " << argPacket->characterIndex << std::endl;
|
||||||
|
roomMgr.PopEntity(static_cast<Entity*>(characterData));
|
||||||
characterMgr.Unload(argPacket->characterIndex);
|
characterMgr.Unload(argPacket->characterIndex);
|
||||||
|
|
||||||
//pump character delete
|
//pump character delete
|
||||||
@@ -190,11 +200,17 @@ void ServerApplication::HandleCharacterSetRoom(CharacterPacket* const argPacket)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pop from the rooms
|
||||||
|
roomMgr.PopEntity(static_cast<Entity*>(characterData));
|
||||||
|
|
||||||
//set the character's room, zero it's origin, zero it's motion
|
//set the character's room, zero it's origin, zero it's motion
|
||||||
characterData->SetRoomIndex(argPacket->roomIndex);
|
characterData->SetRoomIndex(argPacket->roomIndex);
|
||||||
characterData->SetOrigin({0, 0});
|
characterData->SetOrigin({0, 0});
|
||||||
characterData->SetMotion({0, 0});
|
characterData->SetMotion({0, 0});
|
||||||
|
|
||||||
|
//push to the rooms
|
||||||
|
roomMgr.PushEntity(static_cast<Entity*>(characterData));
|
||||||
|
|
||||||
//update the clients
|
//update the clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
CopyCharacterToPacket(&newPacket, argPacket->characterIndex);
|
CopyCharacterToPacket(&newPacket, argPacket->characterIndex);
|
||||||
|
|||||||
@@ -143,12 +143,17 @@ void ServerApplication::FullAccountUnload(int index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServerApplication::FullCharacterUnload(int index) {
|
void ServerApplication::FullCharacterUnload(int index) {
|
||||||
|
//BUG: #38 UnloadIf() lambas are taking COPIES of data structures, rather than the structures themselves
|
||||||
characterMgr.UnloadIf([&](std::pair<const int, CharacterData const&> character) -> bool {
|
characterMgr.UnloadIf([&](std::pair<const int, CharacterData const&> character) -> bool {
|
||||||
//skip the wrong characters
|
//skip the wrong characters
|
||||||
if (character.first != index) {
|
if (character.first != index) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pop from the rooms
|
||||||
|
std::cout << "popping index " << index << std::endl;
|
||||||
|
roomMgr.PopEntity(reinterpret_cast<Entity const*>(&character.second));
|
||||||
|
|
||||||
//pump character unload
|
//pump character unload
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
newPacket.type = SerialPacketType::CHARACTER_DELETE;
|
newPacket.type = SerialPacketType::CHARACTER_DELETE;
|
||||||
|
|||||||
Reference in New Issue
Block a user