修訂 | 55583373d66028d4627aeee5ed5b41d066963fa9 (tree) |
---|---|
時間 | 2012-10-29 23:25:10 |
作者 | h2so5 <h2so5@git....> |
Commiter | h2so5 |
ワープ先座標の指定機能を追加
同じチャンネルネル内でのワープに対応
@@ -142,19 +142,23 @@ void FieldPlayer::Draw() const | ||
142 | 142 | // DrawLine3D(current_stat_.pos, current_stat_.pos + VGet(0, 0, 2 * (*stage_)->map_scale()), GetColor(0, 0, 255)); |
143 | 143 | } |
144 | 144 | |
145 | -void FieldPlayer::Init(tstring model_name) | |
145 | +void FieldPlayer::Init(tstring model_name, const std::shared_ptr<VECTOR>& init_position) | |
146 | 146 | { |
147 | 147 | LoadModel(model_name); |
148 | - ResetPosition(); | |
148 | + ResetPosition(init_position); | |
149 | 149 | } |
150 | 150 | |
151 | -void FieldPlayer::ResetPosition() | |
151 | +void FieldPlayer::ResetPosition(const std::shared_ptr<VECTOR>& init_position) | |
152 | 152 | { |
153 | - const auto& points = (*stage_)->start_points(); | |
154 | - std::mt19937 engine(time(nullptr)); | |
155 | - std::uniform_int_distribution<int> distribution(0, points.size() - 1); | |
153 | + if (init_position) { | |
154 | + current_stat_.pos = *init_position; | |
155 | + } else { | |
156 | + const auto& points = (*stage_)->start_points(); | |
157 | + std::mt19937 engine(time(nullptr)); | |
158 | + std::uniform_int_distribution<int> distribution(0, points.size() - 1); | |
159 | + current_stat_.pos = points[distribution(engine)]; | |
160 | + } | |
156 | 161 | |
157 | - current_stat_.pos = points[distribution(engine)]; | |
158 | 162 | current_stat_.pos.y = (*stage_)->GetFloorY(current_stat_.pos + VGet(0, 20, 0), current_stat_.pos - VGet(0, 20, 0)); |
159 | 163 | } |
160 | 164 |
@@ -53,8 +53,8 @@ public: | ||
53 | 53 | |
54 | 54 | void Draw() const; |
55 | 55 | void Update(); |
56 | - void Init(tstring model_path); | |
57 | - void ResetPosition(); | |
56 | + void Init(tstring model_path, const std::shared_ptr<VECTOR>& init_position); | |
57 | + void ResetPosition(const std::shared_ptr<VECTOR>& init_position); | |
58 | 58 | void RescuePosition(); |
59 | 59 | |
60 | 60 | void LoadModel(const tstring& name); |
@@ -41,7 +41,7 @@ Stage::Stage(const ChannelPtr& channel,const ConfigManagerPtr &config_manager) : | ||
41 | 41 | BOOST_FOREACH(const auto& warp_point, channel_->warp_points) { |
42 | 42 | auto handle = ResourceManager::LoadModelFromName(_T("warpobj:ワープオブジェクト")); |
43 | 43 | float scale = handle.property().get<float>("scale", 80.0); |
44 | - MV1SetPosition(handle.handle(), VGet(warp_point.x, warp_point.y, warp_point.z)); | |
44 | + MV1SetPosition(handle.handle(), warp_point.position); | |
45 | 45 | MV1SetScale(handle.handle(), VGet(scale, scale, scale)); |
46 | 46 | warpobj_handles_.push_back(handle); |
47 | 47 | } |
@@ -113,7 +113,16 @@ void CommandManager::FetchCommand(const network::Command& command) | ||
113 | 113 | auto x = warp_point.second.get<float>("position.x", 0); |
114 | 114 | auto y = warp_point.second.get<float>("position.y", 0); |
115 | 115 | auto z = warp_point.second.get<float>("position.z", 0); |
116 | - Channel::WarpPoint point = {x, y, z, channel, ""}; | |
116 | + | |
117 | + std::shared_ptr<VECTOR> destination; | |
118 | + if (!warp_point.second.get_child("destination", ptree()).empty()) { | |
119 | + auto dest_x = warp_point.second.get<float>("destination.x", 0); | |
120 | + auto dest_y = warp_point.second.get<float>("destination.y", 0); | |
121 | + auto dest_z = warp_point.second.get<float>("destination.z", 0); | |
122 | + destination = std::make_shared<VECTOR>(VGet(dest_x, dest_y, dest_z)); | |
123 | + } | |
124 | + Channel::WarpPoint point = {VGet(x, y, z), channel, "", destination}; | |
125 | + | |
117 | 126 | ptr->warp_points.push_back(point); |
118 | 127 | } |
119 | 128 | channels_[id] = ptr; |
@@ -15,9 +15,10 @@ namespace network { | ||
15 | 15 | struct Channel { |
16 | 16 | public: |
17 | 17 | struct WarpPoint { |
18 | - float x, y, z; | |
18 | + VECTOR position; | |
19 | 19 | unsigned int channel; |
20 | 20 | std::string name; |
21 | + std::shared_ptr<VECTOR> destination; | |
21 | 22 | }; |
22 | 23 | |
23 | 24 | public: |
@@ -5,12 +5,16 @@ | ||
5 | 5 | #include "MainLoop.hpp" |
6 | 6 | #include "ChannelChange.hpp" |
7 | 7 | #include "../CommandManager.hpp" |
8 | +#include "../AccountManager.hpp" | |
8 | 9 | #include "../../common/Logger.hpp" |
9 | 10 | #include "../../common/network/Utils.hpp" |
10 | 11 | #include "../3d/Stage.hpp" |
11 | 12 | |
12 | 13 | namespace scene { |
13 | -ChannelChange::ChannelChange(unsigned char channel, const ManagerAccessorPtr& manager_accessor) : | |
14 | +ChannelChange::ChannelChange( | |
15 | + unsigned char channel, | |
16 | + const std::shared_ptr<VECTOR>& init_position, | |
17 | + const ManagerAccessorPtr& manager_accessor) : | |
14 | 18 | manager_accessor_(manager_accessor), |
15 | 19 | card_manager_(manager_accessor->card_manager().lock()), |
16 | 20 | command_manager_(manager_accessor->command_manager().lock()), |
@@ -18,7 +22,8 @@ ChannelChange::ChannelChange(unsigned char channel, const ManagerAccessorPtr& ma | ||
18 | 22 | config_manager_(manager_accessor->config_manager().lock()), |
19 | 23 | player_manager_(manager_accessor->player_manager().lock()), |
20 | 24 | channel_(channel), |
21 | - fade_counter_(0) | |
25 | + fade_counter_(0), | |
26 | + init_position_(init_position) | |
22 | 27 | { |
23 | 28 | |
24 | 29 | } |
@@ -54,6 +59,10 @@ void ChannelChange::Update() | ||
54 | 59 | world_manager_ = std::make_shared<WorldManager>(stage, manager_accessor_); |
55 | 60 | manager_accessor_->set_world_manager(world_manager_); |
56 | 61 | |
62 | + player_manager_->Init(); | |
63 | + world_manager_->Init(); | |
64 | + world_manager_->myself()->Init(unicode::ToTString(account_manager_->model_name()), init_position_); | |
65 | + | |
57 | 66 | next_scene_ = std::make_shared<scene::MainLoop>(manager_accessor_); |
58 | 67 | } |
59 | 68 | } |
@@ -13,7 +13,10 @@ namespace scene { | ||
13 | 13 | class ChannelChange : public Base{ |
14 | 14 | |
15 | 15 | public: |
16 | - ChannelChange(unsigned char channel, const ManagerAccessorPtr&); | |
16 | + ChannelChange( | |
17 | + unsigned char channel, | |
18 | + const std::shared_ptr<VECTOR>& destination, | |
19 | + const ManagerAccessorPtr&); | |
17 | 20 | ~ChannelChange(); |
18 | 21 | void Begin(); |
19 | 22 | void Update(); |
@@ -32,6 +35,7 @@ class ChannelChange : public Base{ | ||
32 | 35 | |
33 | 36 | unsigned char channel_; |
34 | 37 | int fade_counter_; |
38 | + std::shared_ptr<VECTOR> init_position_; | |
35 | 39 | }; |
36 | 40 | |
37 | 41 | } |
\ No newline at end of file |
@@ -104,7 +104,7 @@ void Connect::Update() | ||
104 | 104 | message_.Update(); |
105 | 105 | |
106 | 106 | if (command_manager_->status() == CommandManager::STATUS_READY) { |
107 | - next_scene_= std::make_shared<scene::ChannelChange>(0, manager_accessor_); | |
107 | + next_scene_= std::make_shared<scene::ChannelChange>(0, std::shared_ptr<VECTOR>(), manager_accessor_); | |
108 | 108 | } else if (return_flag_) { |
109 | 109 | next_scene_= std::make_shared<scene::Title>(manager_accessor_); |
110 | 110 | } |
@@ -50,11 +50,6 @@ MainLoop::MainLoop(const ManagerAccessorPtr& manager_accessor) : | ||
50 | 50 | |
51 | 51 | window_manager_->RestorePosition(); |
52 | 52 | |
53 | - player_manager_->Init(); | |
54 | - world_manager_->Init(); | |
55 | - | |
56 | - world_manager_->myself()->Init(unicode::ToTString(account_manager_->model_name())); | |
57 | - | |
58 | 53 | socket_server_manager_->Start(); |
59 | 54 | |
60 | 55 | } |
@@ -120,12 +115,24 @@ void MainLoop::ProcessInput(InputManager* input) | ||
120 | 115 | |
121 | 116 | if (const auto& channel = command_manager_->current_channel()) { |
122 | 117 | BOOST_FOREACH(const auto& warp_point, channel->warp_points) { |
123 | - auto point = VGet(warp_point.x, warp_point.y + 30, warp_point.z); | |
118 | + auto point = warp_point.position; | |
119 | + point.y += 30; | |
124 | 120 | const auto& pos = player_manager_->GetMyself()->position(); |
125 | 121 | |
126 | - auto distance = VSize(VGet(warp_point.x - pos.x, warp_point.y - pos.y, warp_point.z - pos.z)); | |
122 | + auto distance = VSize(warp_point.position - VGet(pos.x, pos.y, pos.z)); | |
127 | 123 | if (distance < 50 && input->GetKeyCount(KEY_INPUT_M) == 1) { |
128 | - next_scene_ = std::make_shared<scene::ChannelChange>(warp_point.channel, manager_accessor_); | |
124 | + | |
125 | + // 同一チャンネルの場合は移動するだけ | |
126 | + if (player_manager_->GetMyself()->channel() == warp_point.channel) { | |
127 | + if (warp_point.destination) { | |
128 | + world_manager_->myself()->ResetPosition(warp_point.destination); | |
129 | + } | |
130 | + } else { | |
131 | + next_scene_ = std::make_shared<scene::ChannelChange>( | |
132 | + warp_point.channel, | |
133 | + warp_point.destination, | |
134 | + manager_accessor_); | |
135 | + } | |
129 | 136 | } |
130 | 137 | } |
131 | 138 | } |
@@ -164,10 +171,11 @@ void MainLoop::Draw() | ||
164 | 171 | |
165 | 172 | if (const auto& channel = command_manager_->current_channel()) { |
166 | 173 | BOOST_FOREACH(const auto& warp_point, channel->warp_points) { |
167 | - auto point = VGet(warp_point.x, warp_point.y + 30, warp_point.z); | |
174 | + auto point = warp_point.position; | |
175 | + point.y += 30; | |
168 | 176 | const auto& pos = player_manager_->GetMyself()->position(); |
169 | - | |
170 | - auto distance = VSize(VGet(warp_point.x - pos.x, warp_point.y - pos.y, warp_point.z - pos.z)); | |
177 | + | |
178 | + auto distance = VSize(warp_point.position - VGet(pos.x, pos.y, pos.z)); | |
171 | 179 | |
172 | 180 | if (world_manager_->stage()->IsVisiblePoint(point)) { |
173 | 181 | auto screen_pos = ConvWorldPosToScreenPos(point); |