Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/game_pictures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ std::vector<lcf::rpg::SavePicture> Game_Pictures::GetSaveData() const {
// but in multiplayer we don't want to save pictures generated by other players
// because 1) they occupy needless space and 2) they will be immediately out of date
constexpr int min_pic_id = 1;
constexpr int min_player_id = 1;
// the 50 comes from the player image offset used for remote ShowPicture commands
const int multiplayer_pic_ids_begin = data_size + min_pic_id + (min_player_id + 1) * 50;
constexpr int min_player_id = 0;
const int multiplayer_pic_ids_begin = GetPictureIdForPlayer(min_player_id, min_pic_id);
save.reserve(multiplayer_pic_ids_begin);

for (const auto& pic: pictures) {
Expand Down Expand Up @@ -153,6 +152,10 @@ int Game_Pictures::GetDefaultNumberOfPictures() {
return 0;
}

int Game_Pictures::GetPictureIdForPlayer(int player_id, int pic_id) {
return (player_id + 1) * GetDefaultNumberOfPictures() + pic_id;
}

Game_Pictures::Picture& Game_Pictures::GetPicture(int id) {
if (EP_UNLIKELY(id > static_cast<int>(pictures.size()))) {
pictures.reserve(id);
Expand Down Expand Up @@ -366,7 +369,7 @@ void Game_Pictures::EraseAllMultiplayer() {
}

void Game_Pictures::EraseAllMultiplayerForPlayer(int id) {
auto start = (id + 1) * GetDefaultNumberOfPictures() + 1;
auto start = GetPictureIdForPlayer(id, 1);
auto end = start + GetDefaultNumberOfPictures();
for (auto& pic: pictures) {
if (pic.data.ID >= start && pic.data.ID < end) {
Expand Down
1 change: 1 addition & 0 deletions src/game_pictures.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Game_Pictures {
void InitGraphics();

static int GetDefaultNumberOfPictures();
static int GetPictureIdForPlayer(int player_id, int pic_id);

struct Params {
int position_x = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/multiplayer/game_multiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,18 @@ void Game_Multiplayer::InitConnection() {
connection.RegisterHandler<ShowPicturePacket>("ap", [this, modify_args] (ShowPicturePacket& p) {
if (players.find(p.id) == players.end()) return;
modify_args(p);
int pic_id = p.pic_id + (p.id + 1) * 50; //offset to avoid conflicting with others using the same picture
int pic_id = Game_Pictures::GetPictureIdForPlayer(p.id, p.pic_id);
Main_Data::game_pictures->Show(pic_id, p.params);
});
connection.RegisterHandler<MovePicturePacket>("mp", [this, modify_args] (MovePicturePacket& p) {
if (players.find(p.id) == players.end()) return;
int pic_id = p.pic_id + (p.id + 1) * 50; //offset to avoid conflicting with others using the same picture
int pic_id = Game_Pictures::GetPictureIdForPlayer(p.id, p.pic_id);
modify_args(p);
Main_Data::game_pictures->Move(pic_id, p.params);
});
connection.RegisterHandler<ErasePicturePacket>("rp", [this] (ErasePicturePacket& p) {
if (players.find(p.id) == players.end()) return;
int pic_id = p.pic_id + (p.id + 1) * 50; //offset to avoid conflicting with others using the same picture
int pic_id = Game_Pictures::GetPictureIdForPlayer(p.id, p.pic_id);
Main_Data::game_pictures->Erase(pic_id);
});
connection.RegisterHandler<ShowPlayerBattleAnimPacket>("ba", [this] (ShowPlayerBattleAnimPacket& p) {
Expand Down
Loading