Skip to content

Commit cd68e54

Browse files
committed
serialization is done
1 parent 9f30b0c commit cd68e54

File tree

8 files changed

+23
-16
lines changed

8 files changed

+23
-16
lines changed

sprint4/problems/leave_game/solution/src/application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ namespace app {
195195
}
196196
}
197197

198-
Application::Application(model::Game& game)
198+
Application::Application(model::Game& game)
199199
: game_(game) {
200200
}
201201

sprint4/problems/leave_game/solution/src/application.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ namespace app_serialization {
324324
void serialize(Archive& ar, [[maybe_unused]] const unsigned version) {
325325
std::cout << "Serializing players, count: " << players_.size() << std::endl;
326326
ar & players_;
327-
ar & players_;
328327
ar & dog_ids_;
329328
}
330329

sprint4/problems/leave_game/solution/src/copy_server_state.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

sprint4/problems/leave_game/solution/src/model.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ using namespace std::literals;
102102
Dog::Dog(State state, std::string name)
103103
: state_(std::move(state))
104104
, name_(std::move(name)) {
105-
general_id_++;
105+
106106
}
107107

108108
Dog::Dog(std::string_view name) : name_(std::string(name)) {
@@ -173,6 +173,15 @@ using namespace std::literals;
173173
return state_;
174174
}
175175

176+
void SessionService::ConfigureSessionData(std::shared_ptr<GameSession> session) {
177+
int index = common_data_->sessions_.size();
178+
179+
common_data_->sessions_.push_back(session);
180+
common_data_->game_sessions_id_to_index_[session->GetSessionId()] = index;
181+
common_data_->mapId_to_session_index_[session->GetMapId()] =
182+
session->GetSessionId();
183+
}
184+
176185
std::shared_ptr<GameSession> SessionService::CreateGameSession(Map::Id map_id) {
177186
auto& map = common_data_->maps_[common_data_->map_id_to_index_[map_id]];
178187

@@ -191,10 +200,7 @@ using namespace std::literals;
191200
// Создаём GameSession с lootId_to_value_
192201
auto result = std::make_shared<GameSession>(map, std::move(type_to_loot_values));
193202

194-
int index = common_data_->sessions_.size();
195-
common_data_->sessions_.push_back(result);
196-
common_data_->game_sessions_id_to_index_[result->GetSessionId()] = index;
197-
common_data_->mapId_to_session_index_[map_id] = result->GetSessionId();
203+
ConfigureSessionData(result);
198204

199205
return result;
200206
}
@@ -204,8 +210,9 @@ using namespace std::literals;
204210
, bag_capacity_(map.GetBagCapacity())
205211
, lootId_to_value_(std::move(loot_values)) {
206212
if (!is_deserialized) {
207-
id_= general_id_++;
213+
id_= general_id_;
208214
}
215+
general_id_++;
209216
InitializeRegions(map_, regions_);
210217
}
211218

sprint4/problems/leave_game/solution/src/model.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ namespace model {
474474
std::shared_ptr<model::GameSession> FindGameSession(model::GameSession::Id session_id) const {
475475
auto it = common_data_->sessions_[common_data_->game_sessions_id_to_index_[session_id]];
476476

477-
return std::make_shared<model::GameSession>(*it);
477+
return it;
478478
}
479479

480480
std::shared_ptr<GameSession>
@@ -483,6 +483,8 @@ namespace model {
483483
void Tick(std::chrono::milliseconds delta_time);
484484

485485
private:
486+
void ConfigureSessionData(std::shared_ptr<GameSession> session);
487+
486488
std::shared_ptr<CommonData> common_data_;
487489
};
488490

sprint4/problems/leave_game/solution/src/model_serialization.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ namespace serialization {
352352

353353
for (const auto& session : data.sessions_) {
354354
auto index = data.map_id_to_index_.at(session->GetMapId());
355-
sessions_.emplace_back(*session, data.maps_[index]);
355+
sessions_.push_back(GameSessionSer(*session, data.maps_[index]));
356356
}
357357

358358
for (const auto& [map_id, loot_ptr] : data.mapId_to_lootTypes_) {

sprint4/problems/leave_game/solution/src/request_handler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "application.h"
66
#include "extra_data.h"
77

8+
#include <boost/json/serialize.hpp>
89
#include <chrono>
910
#include <cstdint>
1011
#include <exception>
@@ -458,6 +459,7 @@ namespace http_handler {
458459
}
459460

460461
auto response_body = app_.GetSerializedGameState(app::Token{token});
462+
461463
return json_response(http::status::ok, std::move(response_body), ContentType::APP_JSON);
462464
}
463465

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
22 serialization::archive 19 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 4 map3 5 Map 3 3 0 0 9 0 0 0 0 0 2 2 2 16 12 7 12 0 20 0 20 14 14 16 14 14 8 7 8 14 2 7 20 7 12 0 20 0 20 14 8 14 2 16 14 16 0 0 5 0 0 0 0 0 4 2 0 0 6 3 14 2 4 3 4 9 2 5 9 9 4 3 14 9 4 3 0 0 1 0 0 0 0 0 2 o1 8 14 0 0 1 -1 3.00000000000000000e+00 0 0 2 13 0 0 0 0 10 1 30 0 0 1 1 0 1 22 1 0
2-
0 3 Dog 0 0 0 0 1.11050000000000093e+01 7.15999999999999837e+00 0 0 0.00000000000000000e+00 0.00000000000000000e+00 3 70 0 0 0 1 0 0 0 3 0 3.00000000000000000e+00 0 0 1 0 0 0 4 1 1.39636870409646825e+01 1.53526592749417876e+01 5 0 0 0 1 13 0 0 0 0 0 0 0 3 13 0 0 0 4 map3 0 0 2 0 107 {"name":"key","file":"assets/key.obj","type":"obj","rotation":90,"color":"#338844","scale":3E-2,"value":10} 112 {"name":"wallet","file":"assets/wallet.obj","type":"obj","rotation":0,"color":"#883344","scale":1E-2,"value":30} 4 town 2 0 107 {"name":"key","file":"assets/key.obj","type":"obj","rotation":90,"color":"#338844","scale":3E-2,"value":10} 107 {"name":"key","file":"assets/key.obj","type":"obj","rotation":90,"color":"#338844","scale":3E-2,"value":10} 4 map1 2 0 107 {"name":"key","file":"assets/key.obj","type":"obj","rotation":90,"color":"#338844","scale":3E-2,"value":10} 112 {"name":"wallet","file":"assets/wallet.obj","type":"obj","rotation":0,"color":"#883344","scale":1E-2,"value":30} 0 0 1 13 0 0 0 4 map3 0 0 0 3 0 4 map1 5 Map 1 3 4 0 0 0 40 0 40 0 40 30 40 30 0 30 0 0 0 30 1 0 5 5 30 20 1 0 2 o0 40 30 5 0 4.00000000000000000e+00 4 town 4 Town 3 22 0 0 0 40 0 40 0 40 30 40 30 0 30 0 15 40 15 20 0 20 30 0 22 17 22 17 18 17 27 10 22 10 30 0 10 10 10 10 10 10 5 10 5 20 5 20 30 20 40 20 40 10 40 20 40 30 40 30 0 30 10 20 25 25 25 30 25 30 30 20 20 25 20 30 15 30 20 35 20 40 20 40 25 35 25 30 30 30 35 20 0 2 2 6 6 12 7 6 6 22 2 6 11 32 2 6 11 22 16 4 3 33 16 4 3 34 21 4 3 22 21 4 3 22 26 5 3 34 26 5 3 28 21 4 3 2 16 5 5 9 16 6 3 12 24 3 4 2 24 6 4 12 1 7 2 11 34 4 4 22 31 6 2 22 35 6 4 17 41 7 4 1 0 2 o0 40 30 5 0 3.00000000000000000e+00 4 map3 5 Map 3 3 9 0 2 2 2 16 12 7 12 0 20 0 20 14 14 16 14 14 8 7 8 14 2 7 20 7 12 0 20 0 20 14 8 14 2 16 14 16 5 0 4 2 6 3 14 2 4 3 4 9 2 5 9 9 4 3 14 9 4 3 1 0 2 o1 8 14 1 -1 3.00000000000000000e+00 3 13 0 4 map1 0 4 town 1 4 map3 2 3.00000000000000000e+00 1.00000000000000000e+01 0 0 0 0 1 0 0 0
3-
1 3 Dog 1.11050000000000093e+01 7.15999999999999837e+00 0.00000000000000000e+00 0.00000000000000000e+00 3 70 0 1 0 3 0 3.00000000000000000e+00 0 1 0 1 0 1 0 0
1+
22 serialization::archive 19 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 4 map3 5 Map 3 3 0 0 9 0 0 0 0 0 2 2 2 16 12 7 12 0 20 0 20 14 14 16 14 14 8 7 8 14 2 7 20 7 12 0 20 0 20 14 8 14 2 16 14 16 0 0 5 0 0 0 0 0 4 2 0 0 6 3 14 2 4 3 4 9 2 5 9 9 4 3 14 9 4 3 0 0 1 0 0 0 0 0 2 o1 8 14 0 0 1 -1 3.00000000000000000e+00 0 0 2 13 0 0 0 1 30 0 10 0 0 1 1 0 1 22 1 0
2+
0 3 Dog 0 0 0 0 1.87059999999999924e+01 -1.72999999999926407e-01 0 0 0.00000000000000000e+00 0.00000000000000000e+00 2 180 0 0 0 1 0 0 0 16 0 3.00000000000000000e+00 0 0 1 0 0 0 17 0 1.42480060931481507e+01 1.42766721016293765e+01 18 0 4 map1 5 Map 1 3 4 0 0 0 40 0 40 0 40 30 40 30 0 30 0 0 0 30 1 0 5 5 30 20 1 0 2 o0 40 30 5 0 4.00000000000000000e+00 2 13 0 1 30 0 10 0 1 1 0 8 1 1.91040078574823333e+01 -2.32130725693235646e-01 18 1 0 0 2 13 0 0 0 1 1 0 0 0 0 3 13 0 0 0 4 map1 0 0 2 0 107 {"name":"key","file":"assets/key.obj","type":"obj","rotation":90,"color":"#338844","scale":3E-2,"value":10} 112 {"name":"wallet","file":"assets/wallet.obj","type":"obj","rotation":0,"color":"#883344","scale":1E-2,"value":30} 4 town 2 0 107 {"name":"key","file":"assets/key.obj","type":"obj","rotation":90,"color":"#338844","scale":3E-2,"value":10} 107 {"name":"key","file":"assets/key.obj","type":"obj","rotation":90,"color":"#338844","scale":3E-2,"value":10} 4 map3 2 0 107 {"name":"key","file":"assets/key.obj","type":"obj","rotation":90,"color":"#338844","scale":3E-2,"value":10} 112 {"name":"wallet","file":"assets/wallet.obj","type":"obj","rotation":0,"color":"#883344","scale":1E-2,"value":30} 0 0 2 13 0 0 0 4 map1 1 4 map3 0 0 0 3 0 4 map1 5 Map 1 3 4 0 0 0 40 0 40 0 40 30 40 30 0 30 0 0 0 30 1 0 5 5 30 20 1 0 2 o0 40 30 5 0 4.00000000000000000e+00 4 town 4 Town 3 22 0 0 0 40 0 40 0 40 30 40 30 0 30 0 15 40 15 20 0 20 30 0 22 17 22 17 18 17 27 10 22 10 30 0 10 10 10 10 10 10 5 10 5 20 5 20 30 20 40 20 40 10 40 20 40 30 40 30 0 30 10 20 25 25 25 30 25 30 30 20 20 25 20 30 15 30 20 35 20 40 20 40 25 35 25 30 30 30 35 20 0 2 2 6 6 12 7 6 6 22 2 6 11 32 2 6 11 22 16 4 3 33 16 4 3 34 21 4 3 22 21 4 3 22 26 5 3 34 26 5 3 28 21 4 3 2 16 5 5 9 16 6 3 12 24 3 4 2 24 6 4 12 1 7 2 11 34 4 4 22 31 6 2 22 35 6 4 17 41 7 4 1 0 2 o0 40 30 5 0 3.00000000000000000e+00 4 map3 5 Map 3 3 9 0 2 2 2 16 12 7 12 0 20 0 20 14 14 16 14 14 8 7 8 14 2 7 20 7 12 0 20 0 20 14 8 14 2 16 14 16 5 0 4 2 6 3 14 2 4 3 4 9 2 5 9 9 4 3 14 9 4 3 1 0 2 o1 8 14 1 -1 3.00000000000000000e+00 3 13 0 4 map3 2 4 town 1 4 map1 0 3.00000000000000000e+00 1.00000000000000000e+01 0 0 0 0 1 0 0 0
3+
1 3 Dog 1.87059999999999924e+01 -1.72999999999926407e-01 0.00000000000000000e+00 0.00000000000000000e+00 2 180 0 1 0 16 0 3.00000000000000000e+00 0 1 0 0

0 commit comments

Comments
 (0)