• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisióne03f8649cd63324e9400af94cedbeb3737d9eeed (tree)
Tiempo2012-10-28 23:30:53
Autorh2so5 <h2so5@git....>
Commiterh2so5

Log Message

開始地点が移動不可能地点だった場合、エスケープしても抜け出せない問題を修正
空のshared_ptrへのアクセスが発生してしまう問題を修正

Cambiar Resumen

Diferencia incremental

--- a/client/3d/FieldPlayer.cpp
+++ b/client/3d/FieldPlayer.cpp
@@ -160,10 +160,11 @@ void FieldPlayer::ResetPosition()
160160
161161 void FieldPlayer::RescuePosition()
162162 {
163- const auto& points = (*stage_)->start_points();
164- const auto& new_pos =
165- std::min_element(points.begin(), points.end(),
166- [this](const VECTOR& a, const VECTOR& b){
163+ static int rotation = 0;
164+
165+ auto points = (*stage_)->start_points();
166+ std::sort(points.begin(), points.end(),
167+ [this](const VECTOR& a, const VECTOR& b){
167168 return ((a.x - current_stat_.pos.x) * (a.x - current_stat_.pos.x) +
168169 (a.y - current_stat_.pos.y) * (a.y - current_stat_.pos.y) +
169170 (a.z - current_stat_.pos.z) * (a.z - current_stat_.pos.z)) <
@@ -172,7 +173,22 @@ void FieldPlayer::RescuePosition()
172173 (b.z - current_stat_.pos.z) * (b.z - current_stat_.pos.z));
173174 });
174175
175- current_stat_.pos = *new_pos;
176+ const auto& nearest_pos = points[0];
177+ float nearest_dist =
178+ ((nearest_pos.x - current_stat_.pos.x) * (nearest_pos.x - current_stat_.pos.x) +
179+ (nearest_pos.z - current_stat_.pos.z) * (nearest_pos.z - current_stat_.pos.z));
180+
181+ // 同じリスポーンポイントで嵌らないようにポイントをずらす
182+ VECTOR new_pos;
183+ if (nearest_dist < 20 && points.size() > 1) {
184+ rotation++;
185+ new_pos = points[rotation % points.size()];
186+ } else {
187+ rotation = 0;
188+ new_pos = points[0];
189+ }
190+
191+ current_stat_.pos = new_pos;
176192 current_stat_.pos.y = (*stage_)->GetFloorY(current_stat_.pos - VGet(0, 100, 0), current_stat_.pos + VGet(0, 100, 0));
177193 current_stat_.acc.y = 0;
178194 current_stat_.vel.y = 0;
--- a/server/Server.cpp
+++ b/server/Server.cpp
@@ -89,8 +89,12 @@ namespace network {
8989 int Server::GetUserCount() const
9090 {
9191 auto count = std::count_if(sessions_.begin(), sessions_.end(),
92- [](const SessionWeakPtr& s){
93- return !s.expired() && s.lock()->online() && s.lock()->id() > 0;
92+ [](const SessionWeakPtr& s) -> bool {
93+ if (auto session = s.lock()) {
94+ return !s.expired() && session->online() && session->id() > 0;
95+ } else {
96+ return false;
97+ }
9498 });
9599
96100 return count;
@@ -124,12 +128,14 @@ namespace network {
124128 ptree player_array;
125129 auto id_list = account_.GetIDList();
126130 BOOST_FOREACH(const auto& s, sessions_) {
127- if (!s.expired() && s.lock()->online() && s.lock()->id() > 0) {
128- auto id = s.lock()->id();
129- ptree player;
130- player.put("name", account_.GetUserName(id));
131- player.put("model_name", account_.GetUserModelName(id));
132- player_array.push_back(std::make_pair("", player));
131+ if (auto session = s.lock()) {
132+ if (!s.expired() && session->online() && session->id() > 0) {
133+ auto id = session->id();
134+ ptree player;
135+ player.put("name", account_.GetUserName(id));
136+ player.put("model_name", account_.GetUserModelName(id));
137+ player_array.push_back(std::make_pair("", player));
138+ }
133139 }
134140 }
135141 xml_ptree.put_child("players", player_array);
@@ -183,9 +189,10 @@ namespace network {
183189
184190 void Server::ReceiveSession(const SessionPtr& session, const boost::system::error_code& error)
185191 {
186-
187192 config_.Reload();
188193
194+ if (!session) return;
195+
189196 const auto address = session->tcp_socket().remote_endpoint().address();
190197
191198 // 拒否IPでないか判定
@@ -253,12 +260,18 @@ namespace network {
253260 void Server::SendTo(const Command& command, uint32_t user_id)
254261 {
255262 auto it = std::find_if(sessions_.begin(), sessions_.end(),
256- [user_id](SessionWeakPtr& ptr){
257- return ptr.lock()->id() == user_id;
263+ [user_id](SessionWeakPtr& ptr) -> bool {
264+ if (auto session = ptr.lock()) {
265+ return session->id() == user_id;
266+ } else {
267+ return false;
268+ }
258269 });
259270
260271 if (it != sessions_.end()) {
261- it->lock()->Send(command);
272+ if (auto session = it->lock()) {
273+ session->Send(command);
274+ }
262275 }
263276 }
264277
@@ -344,7 +357,7 @@ namespace network {
344357 {
345358 uint8_t header;
346359 std::string body;
347- SessionWeakPtr session;
360+ SessionWeakPtr weak_session;
348361
349362 // IPアドレスとポートからセッションを特定
350363 auto it = std::find_if(sessions_.begin(), sessions_.end(),
@@ -363,8 +376,10 @@ namespace network {
363376 });
364377
365378 if (it != sessions_.end()) {
366- session = *it;
367- Logger::Debug("Receive UDP Command: %d", session.lock()->id());
379+ weak_session = *it;
380+ if (auto session = weak_session.lock()) {
381+ Logger::Debug("Receive UDP Command: %d", session->id());
382+ }
368383 } else {
369384 Logger::Debug("Receive anonymous UDP Command");
370385 }
@@ -374,18 +389,20 @@ namespace network {
374389 }
375390
376391 // 復号
377- if (session.lock() && header == header::ENCRYPT_HEADER) {
378- body.erase(0, sizeof(header));
379- body = session.lock()->encrypter().Decrypt(body);
380- Utils::Deserialize(body, &header);
381- body = buffer.substr(sizeof(header));
382- }
392+ if (auto session = weak_session.lock()) {
393+ if (header == header::ENCRYPT_HEADER) {
394+ body.erase(0, sizeof(header));
395+ body = session->encrypter().Decrypt(body);
396+ Utils::Deserialize(body, &header);
397+ body = buffer.substr(sizeof(header));
398+ }
399+ }
383400
384401 if (header == network::header::ServerRequstedStatus) {
385402 SendUDP(GetStatusJSON(), endpoint);
386403 } else {
387404 if (callback_) {
388- (*callback_)(Command(static_cast<network::header::CommandHeader>(header), body, session));
405+ (*callback_)(Command(static_cast<network::header::CommandHeader>(header), body, weak_session));
389406 }
390407 }
391408