修訂 | 98c546100a61b099940000a22a7db0f1d710e446 (tree) |
---|---|
時間 | 2012-10-28 21:59:03 |
作者 | h2so5 <h2so5@git....> |
Commiter | h2so5 |
起動時にステージモデルをキャッシュする機能を追加
ModelHandle2をModelHandleに改名
@@ -37,3 +37,4 @@ log_*.txt | ||
37 | 37 | /client/bin/log |
38 | 38 | /client/bin/Log.txt |
39 | 39 | /client/bin/user |
40 | +/client/bin/cache |
@@ -211,10 +211,6 @@ void FieldPlayer::SetModel(const ModelHandle& model) | ||
211 | 211 | |
212 | 212 | void FieldPlayer::Update() |
213 | 213 | { |
214 | - if (loading_model_handle_ && loading_model_handle_.CheckLoaded()) { | |
215 | - SetModel(loading_model_handle_); | |
216 | - loading_model_handle_ = ModelHandle(); | |
217 | - } | |
218 | 214 | |
219 | 215 | // 落ちた時に強制復帰 |
220 | 216 | if (prev_stat_.pos.y < (*stage_)->min_height()) { |
@@ -236,7 +236,6 @@ public: | ||
236 | 236 | } |
237 | 237 | |
238 | 238 | // 床へのめり込みを防止 |
239 | - float floor_y; | |
240 | 239 | std::pair<bool, VECTOR> floor_coll; |
241 | 240 | // 足で接地検査 |
242 | 241 | floor_coll = (*stage_)->FloorExists(moved_pos,model_height_,0); |
@@ -9,7 +9,7 @@ | ||
9 | 9 | #include <string> |
10 | 10 | |
11 | 11 | Stage::Stage(const ChannelPtr& channel,const ConfigManagerPtr &config_manager) : |
12 | - map_handle_(ResourceManager::LoadModelFromName2(unicode::ToTString(channel->stage))), | |
12 | + map_handle_(ResourceManager::LoadModelFromName(unicode::ToTString(channel->stage))), | |
13 | 13 | map_scale_(map_handle_.property().get<float>("scale", 20.0)), |
14 | 14 | min_height_(map_handle_.property().get<float>("min_height", -200.0)), |
15 | 15 | host_change_flag_(false), |
@@ -320,7 +320,7 @@ void Stage::UpdateSkymapPosition(const VECTOR& pos) | ||
320 | 320 | MV1SetPosition(skymap_handle_.handle(), VGet(pos.x, 800, pos.z)); |
321 | 321 | } |
322 | 322 | |
323 | -const ModelHandle2& Stage::map_handle() const | |
323 | +const ModelHandle& Stage::map_handle() const | |
324 | 324 | { |
325 | 325 | return map_handle_; |
326 | 326 | } |
@@ -34,7 +34,7 @@ class Stage { | ||
34 | 34 | bool IsVisiblePoint(const VECTOR& point) const; |
35 | 35 | bool IsNearPoint(const VECTOR& point) const; |
36 | 36 | |
37 | - const ModelHandle2& map_handle() const; | |
37 | + const ModelHandle& map_handle() const; | |
38 | 38 | const ModelHandle& skymap_handle() const; |
39 | 39 | float map_scale() const; |
40 | 40 | float min_height() const; |
@@ -50,13 +50,12 @@ class Stage { | ||
50 | 50 | ConfigManagerPtr config_manager() const; |
51 | 51 | |
52 | 52 | private: |
53 | - ModelHandle2 map_handle_; | |
53 | + ModelHandle map_handle_; | |
54 | + ModelHandle skymap_handle_; | |
54 | 55 | float map_scale_; |
55 | 56 | float min_height_; |
56 | 57 | |
57 | 58 | std::unordered_set<int> draw_after_meshes_; |
58 | - | |
59 | - ModelHandle skymap_handle_; | |
60 | 59 | std::vector<ModelHandle> warpobj_handles_; |
61 | 60 | |
62 | 61 | std::vector<VECTOR> start_points_; |
@@ -4,11 +4,23 @@ | ||
4 | 4 | |
5 | 5 | #include <fstream> |
6 | 6 | #include <boost/filesystem.hpp> |
7 | +#include <boost/crc.hpp> | |
7 | 8 | #include "ResourceManager.hpp" |
8 | 9 | #include "../common/Logger.hpp" |
9 | 10 | #include "../common/unicode.hpp" |
10 | 11 | #include "Music.hpp" |
11 | 12 | |
13 | + | |
14 | +// MV1書き出し関数 | |
15 | +namespace DxLib | |
16 | +{ | |
17 | +extern int MV1SaveModelToMV1File( int MHandle, const char *FileName, | |
18 | + int SaveType = ((0x0001) | (0x0002)), int AnimMHandle = -1, | |
19 | + int AnimNameCheck = TRUE, int Normal8BitFlag = 1, | |
20 | + int Position16BitFlag = 1, int Weight8BitFlag = 0, | |
21 | + int Anim16BitFlag = 1 ); | |
22 | +}; | |
23 | + | |
12 | 24 | ResourceManager::MemoryPool ResourceManager::mempool; |
13 | 25 | |
14 | 26 | const static TCHAR* CHAT_FONT_NAME = _T("UmePlus P Gothic"); |
@@ -109,10 +121,10 @@ std::vector<std::string> ResourceManager::model_name_list_; | ||
109 | 121 | ptree ResourceManager::model_name_tree_; |
110 | 122 | void ResourceManager::BuildModelFileTree() |
111 | 123 | { |
112 | - using namespace boost::filesystem; | |
113 | - using namespace std; | |
124 | + using namespace boost::filesystem; | |
125 | + using namespace std; | |
114 | 126 | |
115 | - model_name_tree_.clear(); | |
127 | + model_name_tree_.clear(); | |
116 | 128 | model_name_list_.clear(); |
117 | 129 | |
118 | 130 | std::function<void(const path& p)> search_dir; |
@@ -120,51 +132,55 @@ void ResourceManager::BuildModelFileTree() | ||
120 | 132 | |
121 | 133 | using namespace boost::filesystem; |
122 | 134 | |
123 | - if (exists(p) && is_directory(p)) { | |
124 | - for (auto it_dir = directory_iterator(p); it_dir != directory_iterator(); ++it_dir) { | |
125 | - if (is_directory(*it_dir)) { | |
126 | - path json_path = it_dir->path() / "info.json"; | |
127 | - if (exists(json_path)) { | |
128 | - | |
129 | - path model_path; | |
130 | - for (auto it = directory_iterator(*it_dir); it != directory_iterator(); ++it) { | |
131 | - auto extension = it->path().extension().string(); | |
132 | - | |
133 | - if (extension == ".mv1" || extension == ".x" | |
134 | - || extension == ".pmd" || extension == ".pmx") { | |
135 | - model_path = it->path(); | |
136 | - break; | |
137 | - } | |
138 | - } | |
139 | - | |
140 | - if (!model_path.empty()) { | |
141 | - ptree pt_json; | |
142 | - read_json(json_path.string(), pt_json); | |
135 | + if (exists(p) && is_directory(p)) { | |
136 | + for (auto it_dir = directory_iterator(p); it_dir != directory_iterator(); ++it_dir) { | |
137 | + if (is_directory(*it_dir)) { | |
138 | + path json_path = it_dir->path() / "info.json"; | |
139 | + if (exists(json_path)) { | |
140 | + | |
141 | + path model_path; | |
142 | + for (auto it = directory_iterator(*it_dir); it != directory_iterator(); ++it) { | |
143 | + auto extension = it->path().extension().string(); | |
144 | + | |
145 | + if (extension == ".mv1" || extension == ".x" | |
146 | + || extension == ".pmd" || extension == ".pmx") { | |
147 | + model_path = it->path(); | |
148 | + break; | |
149 | + } | |
150 | + } | |
151 | + | |
152 | + if (!model_path.empty()) { | |
153 | + ptree pt_json; | |
154 | + read_json(json_path.string(), pt_json); | |
143 | 155 | MergePtree(&pt_json, GetDefaultInfoJSON()); |
144 | 156 | |
145 | - std::string name = pt_json.get<std::string>("name", ""); | |
146 | - pt_json.put<std::string>("modelpath", unicode::sjis2utf8(model_path.string())); | |
157 | + std::string name = pt_json.get<std::string>("name", ""); | |
158 | + auto model_path_str = unicode::sjis2utf8(model_path.string()); | |
159 | + | |
160 | + pt_json.put<std::string>("modelpath", model_path_str); | |
147 | 161 | if (!name.empty()) { |
148 | 162 | model_name_list_.push_back(name); |
149 | - } | |
163 | + model_name_tree_.put_child(ptree::path_type(name + ":_info_", ':'), pt_json); | |
150 | 164 | |
151 | - if (name.size() > 0) { | |
152 | - model_name_tree_.put_child(ptree::path_type(name + ":_info_", ':'), pt_json); | |
153 | - } | |
154 | - } | |
155 | - } else { | |
165 | + // ステージデータをキャッシュ | |
166 | + if (name.find("stage:") == 0) { | |
167 | + CreateModelCache(model_path_str, pt_json); | |
168 | + } | |
169 | + } | |
170 | + } | |
171 | + } else { | |
156 | 172 | search_dir(it_dir->path()); |
157 | 173 | } |
158 | - } | |
159 | - } | |
160 | - } | |
174 | + } | |
175 | + } | |
176 | + } | |
161 | 177 | }; |
162 | 178 | |
163 | - try { | |
179 | + try { | |
164 | 180 | search_dir("./models"); |
165 | - } catch (const filesystem_error& ex) { | |
166 | - Logger::Error(_T("%s"), unicode::ToTString(ex.what())); | |
167 | - } | |
181 | + } catch (const filesystem_error& ex) { | |
182 | + Logger::Error(_T("%s"), unicode::ToTString(ex.what())); | |
183 | + } | |
168 | 184 | |
169 | 185 | } |
170 | 186 |
@@ -272,6 +288,49 @@ void SetMotionNames(int handle, const ReadFuncData& funcdata) | ||
272 | 288 | } |
273 | 289 | } |
274 | 290 | |
291 | +std::string ResourceManager::GetCacheFilename(const ptree& info, const std::shared_ptr<char>& fileimage, int filesize) | |
292 | +{ | |
293 | + boost::crc_32_type crc; | |
294 | + crc.process_block(static_cast<void*>(fileimage.get()), | |
295 | + static_cast<void*>(fileimage.get() + filesize)); | |
296 | + | |
297 | + boost::crc_32_type crc_info; | |
298 | + std::stringstream stream; | |
299 | + boost::archive::text_oarchive oa(stream); | |
300 | + oa << info; | |
301 | + while(stream.good()) { | |
302 | + crc_info.process_byte(stream.get()); | |
303 | + } | |
304 | + | |
305 | + auto cache_filename = "./cache/" + | |
306 | + boost::lexical_cast<std::string>(crc.checksum()) + "_" + | |
307 | + boost::lexical_cast<std::string>(crc_info.checksum()) + | |
308 | + ".mv1"; | |
309 | + | |
310 | + return cache_filename; | |
311 | +} | |
312 | + | |
313 | +void ResourceManager::CreateModelCache(std::string filepath, const ptree& info) | |
314 | +{ | |
315 | + auto funcdata = std::make_shared<ReadFuncData>(info); | |
316 | + | |
317 | + std::shared_ptr<char> fileimage; | |
318 | + int filesize; | |
319 | + | |
320 | + LoadFile(unicode::ToTString(filepath).c_str(), &fileimage, &filesize ); | |
321 | + auto cache_filename = GetCacheFilename(info, fileimage, filesize); | |
322 | + | |
323 | + if (!boost::filesystem::exists(cache_filename)) { | |
324 | + int handle = MV1LoadModelFromMem(fileimage.get(), filesize, FileReadFunc, FileReleaseFunc, &(*funcdata)); | |
325 | + | |
326 | + if (!boost::filesystem::exists("./cache")) { | |
327 | + boost::filesystem::create_directory("./cache"); | |
328 | + } | |
329 | + MV1SaveModelToMV1File(handle, cache_filename.c_str()); | |
330 | + MV1DeleteModel(handle); | |
331 | + } | |
332 | +} | |
333 | + | |
275 | 334 | void ResourceManager::RequestModelFromName(const tstring& name) |
276 | 335 | { |
277 | 336 | if (!IsCachedModelName(name)) { |
@@ -293,7 +352,7 @@ ReadFuncData::ReadFuncData(const ptree& info) | ||
293 | 352 | { |
294 | 353 | tstring filepath = unicode::ToTString(info.get<std::string>("modelpath", "")); |
295 | 354 | auto path = boost::filesystem::wpath(unicode::ToWString(filepath)); |
296 | - model_dir = path.parent_path(); | |
355 | + model_dir = path.parent_path(); | |
297 | 356 | |
298 | 357 | if (path.extension() == _T(".pmd") || path.extension() == _T(".pmx")) { |
299 | 358 | auto motions_array = info.get_child("character.motions", ptree()); |
@@ -345,61 +404,13 @@ ReadFuncData::ReadFuncData(const ptree& info) | ||
345 | 404 | } |
346 | 405 | } |
347 | 406 | } |
348 | - motions_it = motions.begin(); | |
407 | + motions_it = motions.begin(); | |
349 | 408 | } |
350 | 409 | |
351 | 410 | std::unordered_map<std::string, std::string> ResourceManager::set_motions_ = std::unordered_map<std::string, std::string>(); |
352 | 411 | float ResourceManager::model_edge_size_ = 1.0f; |
353 | -ModelHandle ResourceManager::LoadModelFromName(const tstring& name) | |
354 | -{ | |
355 | - auto fullpath = ptree::path_type(unicode::ToString(NameToFullPath(name)), ':'); | |
356 | - ptree p = model_name_tree_.get_child(fullpath, ptree()); | |
357 | - | |
358 | - ptree info = p.get_child("_info_", ptree()); | |
359 | - tstring filepath = unicode::ToTString(info.get<std::string>("modelpath", "")); | |
360 | - if(!filepath.size()) | |
361 | - { | |
362 | - fullpath = ptree::path_type(unicode::ToString(NameToFullPath(UNKNOWN_MODEL_NAME)), ':'); | |
363 | - p = model_name_tree_.get_child(fullpath, ptree()); | |
364 | - info = p.get_child("_info_", ptree()); | |
365 | - filepath = unicode::ToTString(info.get<std::string>("modelpath", "")); | |
366 | - } | |
367 | - if (filepath.size() > 0) { | |
368 | - auto it = model_handles_.find(unicode::ToTString(filepath)); | |
369 | - if (it != model_handles_.end()) { | |
370 | - return it->second.Clone(); | |
371 | - }else{ | |
372 | - auto funcdata = std::make_shared<ReadFuncData>(info); | |
373 | - set_motions_ = funcdata->set_motions; | |
374 | - | |
375 | - //void *FileImage ; | |
376 | - std::shared_ptr<char> FileImage; | |
377 | - int FileSize ; | |
378 | - | |
379 | - LoadFile(unicode::ToTString(filepath).c_str(), &FileImage, &FileSize ); | |
380 | - | |
381 | - int handle = MV1LoadModelFromMem( FileImage.get(), FileSize, FileReadFunc, FileReleaseFunc, &(*funcdata)); | |
382 | - | |
383 | - auto material_num = MV1GetMaterialNum(handle); | |
384 | - for(int i = 0; i < material_num; ++i){ | |
385 | - MV1SetMaterialType(handle,i,DX_MATERIAL_TYPE_TOON_2); | |
386 | - } | |
387 | 412 | |
388 | - | |
389 | - SetMotionNames(handle, *funcdata); | |
390 | - | |
391 | - auto model_handle = ModelHandle(handle, funcdata, std::make_shared<ptree>(info)); | |
392 | - model_handles_[unicode::ToTString(filepath)] = model_handle; | |
393 | - | |
394 | - Logger::Debug(_T("Model %d"), handle); | |
395 | - return model_handle.Clone(); | |
396 | - } | |
397 | - } else { | |
398 | - return ModelHandle(); | |
399 | - } | |
400 | -} | |
401 | - | |
402 | -ModelHandle2 ResourceManager::LoadModelFromName2(const tstring& name) | |
413 | +ModelHandle ResourceManager::LoadModelFromName(const tstring& name) | |
403 | 414 | { |
404 | 415 | auto fullpath = ptree::path_type(unicode::ToString(NameToFullPath(name)), ':'); |
405 | 416 | ptree p = model_name_tree_.get_child(fullpath, ptree()); |
@@ -416,16 +427,23 @@ ModelHandle2 ResourceManager::LoadModelFromName2(const tstring& name) | ||
416 | 427 | if (filepath.size() > 0) { |
417 | 428 | auto it = shared_model_data_.find(unicode::ToTString(filepath)); |
418 | 429 | if (it != shared_model_data_.end()) { |
419 | - return ModelHandle2(it->second); | |
430 | + return ModelHandle(it->second); | |
420 | 431 | }else{ |
421 | 432 | auto funcdata = std::make_shared<ReadFuncData>(info); |
422 | 433 | set_motions_ = funcdata->set_motions; |
423 | 434 | |
424 | - //void *FileImage ; | |
425 | 435 | std::shared_ptr<char> FileImage; |
426 | - int FileSize ; | |
436 | + int FileSize; | |
427 | 437 | |
428 | 438 | LoadFile(unicode::ToTString(filepath).c_str(), &FileImage, &FileSize ); |
439 | + | |
440 | + // キャッシュ読み込み | |
441 | + // モーションなしのモデルでないと上手くいかない | |
442 | + auto cache_filename = GetCacheFilename(info, FileImage, FileSize); | |
443 | + if (boost::filesystem::exists(cache_filename)) { | |
444 | + FileImage.reset(); | |
445 | + LoadFile(unicode::ToTString(cache_filename).c_str(), &FileImage, &FileSize); | |
446 | + } | |
429 | 447 | |
430 | 448 | int handle = MV1LoadModelFromMem( FileImage.get(), FileSize, FileReadFunc, FileReleaseFunc, &(*funcdata)); |
431 | 449 |
@@ -436,20 +454,22 @@ ModelHandle2 ResourceManager::LoadModelFromName2(const tstring& name) | ||
436 | 454 | |
437 | 455 | SetMotionNames(handle, *funcdata); |
438 | 456 | |
457 | + // CreateModelCache(handle, info, FileImage, FileSize); | |
458 | + | |
439 | 459 | SharedModelDataPtr shared_data = |
440 | 460 | std::make_shared<SharedModelData>(handle, std::make_shared<ptree>(info)); |
441 | 461 | |
442 | 462 | shared_model_data_[unicode::ToTString(filepath)] = shared_data; |
443 | 463 | |
444 | 464 | Logger::Debug(_T("Model %d"), handle); |
445 | - return ModelHandle2(shared_data); | |
465 | + return ModelHandle(shared_data); | |
446 | 466 | } |
447 | 467 | } else { |
448 | - return ModelHandle2(); | |
468 | + return ModelHandle(); | |
449 | 469 | } |
450 | 470 | } |
451 | 471 | |
452 | -void ResourceManager::ClearModelHandle2() | |
472 | +void ResourceManager::ClearModelHandle() | |
453 | 473 | { |
454 | 474 | std::list<tstring> erase_keys; |
455 | 475 | BOOST_FOREACH(const auto& it, shared_model_data_) { |
@@ -577,71 +597,6 @@ ImageHandle::operator int() const | ||
577 | 597 | return handle_; |
578 | 598 | } |
579 | 599 | |
580 | -ModelHandle::ModelHandle(int handle, const ReadFuncDataPtr& funcdata, const std::shared_ptr<ptree>& property, bool async_load) : | |
581 | - handle_(handle), | |
582 | - funcdata_(funcdata), | |
583 | - property_(property), | |
584 | - name_(property_->get<std::string>("name", "")), | |
585 | - async_load_(async_load) | |
586 | -{ | |
587 | - | |
588 | -} | |
589 | - | |
590 | -ModelHandle ModelHandle::Clone() | |
591 | -{ | |
592 | - if (CheckHandleASyncLoad(handle_) == TRUE) { | |
593 | - return ModelHandle(handle_, funcdata_, property_, true); | |
594 | - } else { | |
595 | - return ModelHandle(MV1DuplicateModel(handle_), funcdata_, property_); | |
596 | - } | |
597 | -} | |
598 | - | |
599 | -bool ModelHandle::CheckLoaded() | |
600 | -{ | |
601 | - if (!async_load_) { | |
602 | - return true; | |
603 | - } else if (async_load_ && CheckHandleASyncLoad(handle_) == FALSE) { | |
604 | - handle_ = MV1DuplicateModel(handle_); | |
605 | - SetMotionNames(handle_, *funcdata_); | |
606 | - async_load_ = false; | |
607 | - return true; | |
608 | - } else { | |
609 | - return false; | |
610 | - } | |
611 | -} | |
612 | - | |
613 | -ModelHandle::operator bool() const | |
614 | -{ | |
615 | - return handle_ != -1; | |
616 | -} | |
617 | - | |
618 | -ModelHandle::ModelHandle() : | |
619 | - handle_(-1), | |
620 | - property_(std::make_shared<ptree>()) | |
621 | -{ | |
622 | - | |
623 | -} | |
624 | - | |
625 | -ModelHandle::~ModelHandle() | |
626 | -{ | |
627 | - | |
628 | -} | |
629 | - | |
630 | -int ModelHandle::handle() const | |
631 | -{ | |
632 | - return handle_; | |
633 | -} | |
634 | - | |
635 | -const ptree& ModelHandle::property() const | |
636 | -{ | |
637 | - return *property_; | |
638 | -} | |
639 | - | |
640 | -std::string ModelHandle::name() const | |
641 | -{ | |
642 | - return name_; | |
643 | -} | |
644 | - | |
645 | 600 | SharedModelData::SharedModelData(int base_handle, const PtreePtr& property) : |
646 | 601 | base_handle_(base_handle), |
647 | 602 | property_(property) |
@@ -670,24 +625,34 @@ SharedModelData::~SharedModelData() | ||
670 | 625 | MV1DeleteModel(base_handle_); |
671 | 626 | } |
672 | 627 | |
673 | -ModelHandle2::ModelHandle2(const SharedModelDataPtr& shared_data) : | |
628 | +ModelHandle::ModelHandle(const SharedModelDataPtr& shared_data) : | |
674 | 629 | shared_data_(shared_data), |
675 | 630 | handle_(shared_data->DuplicateHandle()) |
676 | 631 | { |
677 | 632 | |
678 | 633 | } |
679 | 634 | |
680 | -ModelHandle2::operator bool() const | |
635 | +ModelHandle::ModelHandle() | |
636 | +{ | |
637 | + | |
638 | +} | |
639 | + | |
640 | +ModelHandle::operator bool() const | |
681 | 641 | { |
682 | 642 | return static_cast<bool>(shared_data_); |
683 | 643 | } |
684 | 644 | |
685 | -int ModelHandle2::handle() const | |
645 | +int ModelHandle::handle() const | |
686 | 646 | { |
687 | 647 | return handle_; |
688 | 648 | } |
689 | 649 | |
690 | -const ptree& ModelHandle2::property() const | |
650 | +const ptree& ModelHandle::property() const | |
691 | 651 | { |
692 | 652 | return shared_data_->property(); |
653 | +} | |
654 | + | |
655 | +std::string ModelHandle::name() const | |
656 | +{ | |
657 | + return property().get<std::string>("name", ""); | |
693 | 658 | } |
\ No newline at end of file |
@@ -22,7 +22,7 @@ class ModelHandle; | ||
22 | 22 | class Music; |
23 | 23 | |
24 | 24 | class SharedModelData; |
25 | -class ModelHandle2; | |
25 | +class ModelHandle; | |
26 | 26 | |
27 | 27 | typedef std::shared_ptr<ImageHandle> ImageHandlePtr; |
28 | 28 | typedef std::shared_ptr<ModelHandle> ModelHandlePtr; |
@@ -106,10 +106,12 @@ class ResourceManager { | ||
106 | 106 | // models |
107 | 107 | static void BuildModelFileTree(); |
108 | 108 | static void CacheBakedModel(); |
109 | + | |
109 | 110 | static ModelHandle LoadModelFromName(const tstring&); |
111 | + static void ClearModelHandle(); | |
110 | 112 | |
111 | - static ModelHandle2 LoadModelFromName2(const tstring&); | |
112 | - static void ClearModelHandle2(); | |
113 | + static std::string GetCacheFilename(const ptree& info, const std::shared_ptr<char>& fileimage, int filesize); | |
114 | + static void CreateModelCache(std::string filepath, const ptree& info); | |
113 | 115 | |
114 | 116 | static void RequestModelFromName(const tstring&); |
115 | 117 | static bool IsCachedModelName(const tstring&); |
@@ -171,46 +173,6 @@ class ImageHandle { | ||
171 | 173 | |
172 | 174 | }; |
173 | 175 | |
174 | -class ModelHandle { | |
175 | - friend class ResourceManager; | |
176 | - | |
177 | - private: | |
178 | - ModelHandle(int handle, const ReadFuncDataPtr& funcdata, const std::shared_ptr<ptree>& property, bool async_load = false); | |
179 | - ModelHandle Clone(); | |
180 | - | |
181 | - public: | |
182 | - ModelHandle(); | |
183 | - ~ModelHandle(); | |
184 | - | |
185 | - int handle() const; | |
186 | - const ptree& property() const; | |
187 | - std::string name() const; | |
188 | - | |
189 | - operator bool() const; | |
190 | - | |
191 | - bool CheckLoaded(); | |
192 | - | |
193 | - private: | |
194 | - int handle_; | |
195 | - ReadFuncDataPtr funcdata_; | |
196 | - std::shared_ptr<ptree> property_; | |
197 | - std::string name_; | |
198 | - bool async_load_; | |
199 | - | |
200 | - public: | |
201 | - void *operator new(size_t size) | |
202 | - { | |
203 | - return tlsf_new(ResourceManager::memory_pool(), size); | |
204 | - } | |
205 | - void *operator new(size_t, void *p){return p;} | |
206 | - void operator delete(void *p) | |
207 | - { | |
208 | - tlsf_delete(ResourceManager::memory_pool(), p); | |
209 | - } | |
210 | - void operator delete(void *, void *){}; | |
211 | - | |
212 | -}; | |
213 | - | |
214 | 176 | typedef std::shared_ptr<ptree> PtreePtr; |
215 | 177 | |
216 | 178 | class SharedModelData { |
@@ -227,12 +189,14 @@ class SharedModelData { | ||
227 | 189 | PtreePtr property_; |
228 | 190 | }; |
229 | 191 | |
230 | -class ModelHandle2 { | |
192 | +class ModelHandle { | |
231 | 193 | public: |
232 | - ModelHandle2(const SharedModelDataPtr& shared_data = SharedModelDataPtr()); | |
194 | + ModelHandle(const SharedModelDataPtr& shared_data); | |
195 | + ModelHandle(); | |
233 | 196 | operator bool() const; |
234 | 197 | int handle() const; |
235 | 198 | const ptree& property() const; |
199 | + std::string name() const; | |
236 | 200 | |
237 | 201 | private: |
238 | 202 | SharedModelDataPtr shared_data_; |
@@ -17,7 +17,8 @@ ChannelChange::ChannelChange(unsigned char channel, const ManagerAccessorPtr& ma | ||
17 | 17 | account_manager_(manager_accessor->account_manager().lock()), |
18 | 18 | config_manager_(manager_accessor->config_manager().lock()), |
19 | 19 | player_manager_(manager_accessor->player_manager().lock()), |
20 | - channel_(channel) | |
20 | + channel_(channel), | |
21 | + fade_counter_(0) | |
21 | 22 | { |
22 | 23 | |
23 | 24 | } |
@@ -28,18 +29,7 @@ ChannelChange::~ChannelChange() | ||
28 | 29 | |
29 | 30 | void ChannelChange::Begin() |
30 | 31 | { |
31 | - // 古いステージを削除 | |
32 | - player_manager_->ResetStage(); | |
33 | - manager_accessor_->set_world_manager(WorldManagerPtr()); | |
34 | 32 | |
35 | - ResourceManager::ClearModelHandle2(); | |
36 | - | |
37 | - command_manager_->Write(network::ServerUpdateAccountProperty(CHANNEL, network::Utils::Serialize(channel_))); | |
38 | - | |
39 | - auto channel_ptr = command_manager_->channels().at(channel_); | |
40 | - StagePtr stage = std::make_shared<Stage>(channel_ptr,manager_accessor_->config_manager().lock()); | |
41 | - world_manager_ = std::make_shared<WorldManager>(stage, manager_accessor_); | |
42 | - manager_accessor_->set_world_manager(world_manager_); | |
43 | 33 | } |
44 | 34 | |
45 | 35 | void ChannelChange::End() |
@@ -48,11 +38,22 @@ void ChannelChange::End() | ||
48 | 38 | |
49 | 39 | void ChannelChange::Update() |
50 | 40 | { |
51 | - //if(world_manager_->stage()->host_change_flag()) | |
52 | - //{ | |
53 | - //account_manager_->set_host(world_manager_->stage()->host_change_flag().second); | |
41 | + if (fade_counter_ < 120) { | |
42 | + fade_counter_++; | |
43 | + } else { | |
44 | + // 古いステージを削除 | |
45 | + player_manager_->ResetStage(); | |
46 | + manager_accessor_->set_world_manager(WorldManagerPtr()); | |
47 | + | |
48 | + command_manager_->Write(network::ServerUpdateAccountProperty(CHANNEL, network::Utils::Serialize(channel_))); | |
49 | + | |
50 | + auto channel_ptr = command_manager_->channels().at(channel_); | |
51 | + StagePtr stage = std::make_shared<Stage>(channel_ptr,manager_accessor_->config_manager().lock()); | |
52 | + world_manager_ = std::make_shared<WorldManager>(stage, manager_accessor_); | |
53 | + manager_accessor_->set_world_manager(world_manager_); | |
54 | + | |
54 | 55 | next_scene_ = std::make_shared<scene::MainLoop>(manager_accessor_); |
55 | - //} | |
56 | + } | |
56 | 57 | } |
57 | 58 | |
58 | 59 | void ChannelChange::ProcessInput(InputManager* input) |
@@ -62,6 +63,13 @@ void ChannelChange::ProcessInput(InputManager* input) | ||
62 | 63 | |
63 | 64 | void ChannelChange::Draw() |
64 | 65 | { |
66 | + if (fade_counter_ < 120) { | |
67 | + SetDrawBlendMode(DX_BLENDMODE_ALPHA, 255 * fade_counter_ / 120); | |
68 | + int width, height; | |
69 | + GetScreenState(&width, &height, nullptr); | |
70 | + DrawBox(0, 0, width, height, GetColor(0, 0, 0), TRUE); | |
71 | + SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
72 | + } | |
65 | 73 | } |
66 | 74 | |
67 | 75 | } |
\ No newline at end of file |
@@ -31,6 +31,7 @@ class ChannelChange : public Base{ | ||
31 | 31 | PlayerManagerPtr player_manager_; |
32 | 32 | |
33 | 33 | unsigned char channel_; |
34 | + int fade_counter_; | |
34 | 35 | }; |
35 | 36 | |
36 | 37 | } |
\ No newline at end of file |
@@ -36,7 +36,8 @@ MainLoop::MainLoop(const ManagerAccessorPtr& manager_accessor) : | ||
36 | 36 | inputbox_(std::make_shared<InputBox>(manager_accessor_)), |
37 | 37 | minimap_(std::make_shared<MiniMap>(manager_accessor)), |
38 | 38 | snapshot_number_(0), |
39 | - snapshot_(false) | |
39 | + snapshot_(false), | |
40 | + fade_counter_(0) | |
40 | 41 | { |
41 | 42 | manager_accessor_->set_window_manager(window_manager_); |
42 | 43 |
@@ -55,6 +56,7 @@ MainLoop::MainLoop(const ManagerAccessorPtr& manager_accessor) : | ||
55 | 56 | world_manager_->myself()->Init(unicode::ToTString(account_manager_->model_name())); |
56 | 57 | |
57 | 58 | socket_server_manager_->Start(); |
59 | + | |
58 | 60 | } |
59 | 61 | |
60 | 62 | MainLoop::~MainLoop() |
@@ -79,6 +81,15 @@ void MainLoop::Update() | ||
79 | 81 | world_manager_->Update(); |
80 | 82 | ResourceManager::music()->Update(); |
81 | 83 | |
84 | + static int cleanup_counter = 0; | |
85 | + if (cleanup_counter % (60 * 30) == 0) { | |
86 | + ResourceManager::ClearModelHandle(); | |
87 | + } | |
88 | + cleanup_counter++; | |
89 | + | |
90 | + if (fade_counter_ < 120) { | |
91 | + fade_counter_++; | |
92 | + } | |
82 | 93 | } |
83 | 94 | |
84 | 95 | void MainLoop::ProcessInput(InputManager* input) |
@@ -187,9 +198,18 @@ void MainLoop::Draw() | ||
187 | 198 | SetDrawBlendMode(DX_BLENDMODE_MUL, 120); |
188 | 199 | DrawBox(0,0,config_manager_->screen_width(),config_manager_->screen_height(),GetColor(0,0,0),1); |
189 | 200 | SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); |
190 | - auto str = unicode::ToTString("サーバーとの接続が切断されました"); | |
201 | + auto str = unicode::ToTString(_T("サーバーとの接続が切断されました")); | |
191 | 202 | auto width = GetDrawStringWidthToHandle(str.c_str(),str.length(),ResourceManager::default_font_handle()); |
192 | 203 | DrawStringToHandle(config_manager_->screen_width()/2.0f - width,config_manager_->screen_height()/2.0f - ResourceManager::default_font_size(),str.c_str(),GetColor(255,255,255),ResourceManager::default_font_handle()); |
204 | + SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
205 | + } | |
206 | + | |
207 | + if (fade_counter_ < 120) { | |
208 | + SetDrawBlendMode(DX_BLENDMODE_ALPHA, 255 * (120 - fade_counter_) / 120); | |
209 | + int width, height; | |
210 | + GetScreenState(&width, &height, nullptr); | |
211 | + DrawBox(0, 0, width, height, GetColor(0, 0, 0), TRUE); | |
212 | + SetDrawBlendMode(DX_BLENDMODE_NOBLEND, 0); | |
193 | 213 | } |
194 | 214 | } |
195 | 215 |
@@ -45,6 +45,7 @@ class MainLoop : public Base { | ||
45 | 45 | int snapshot_number_; |
46 | 46 | bool snapshot_; |
47 | 47 | |
48 | + int fade_counter_; | |
48 | 49 | //SocketServer socket_server_; |
49 | 50 | }; |
50 | 51 |