• R/O
  • HTTP
  • SSH
  • HTTPS

GVONavish: Commit

大航海時代Onlineのプレイを少しだけ助けてくれるツール。


Commit MetaInfo

Revisiond26cb3a47bdd65aa62b5c516f081664532a3fe91 (tree)
Time2014-03-11 04:43:01
AuthorMandhelingFreak <mandheling30-freak@yaho...>
CommiterMandhelingFreak

Log Message

航路保存機能試作。

Change Summary

Incremental Difference

--- a/GVONavish/GVONavish/GVONavish.cpp
+++ b/GVONavish/GVONavish/GVONavish.cpp
@@ -87,6 +87,7 @@ static GVOConfig s_config( k_configFileName );
8787 static GVOGameProcess s_gvoGameProcess;
8888 static GVORenderer s_renderer;
8989 static GVOWorldMap s_worldMap;
90+const std::wstring && k_routeListFilePath = g_makeFullPath(L"RouteList.dat");
9091 static std::unique_ptr<GVOShipRouteList> s_shipRouteList;
9192 static POINT s_latestSurveyCoord;
9293 static GVOVector s_latestShipVector;
@@ -149,6 +150,7 @@ int APIENTRY _tWinMain( _In_ HINSTANCE hInstance,
149150 // メイン メッセージ ループ:
150151 const LRESULT retVal = s_mainLoop();
151152
153+ s_shipRouteList->saveToFile( k_routeListFilePath );
152154 s_gvoGameProcess.teardown();
153155
154156 s_config.save();
@@ -216,6 +218,7 @@ static BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
216218 s_renderer.setup( &s_config, g_hdcMain, &s_worldMap );
217219
218220 s_shipRouteList.reset( new GVOShipRouteList() );
221+ s_shipRouteList->loadFromFile( k_routeListFilePath );
219222 s_pollingInterval = s_config.m_pollingInterval;
220223 s_gvoGameProcess.setup( s_config );
221224
--- a/GVONavish/GVONavish/GVONormalizedPoint.h
+++ b/GVONavish/GVONavish/GVONormalizedPoint.h
@@ -31,4 +31,8 @@ public:
3131 {
3232 return m_y;
3333 }
34+
3435 };
36+
37+// ファイル入出力用にアライメント確認
38+static_assert(sizeof(GVONormalizedPoint) == (sizeof(float)*2), "bat size.");
--- a/GVONavish/GVONavish/GVOShipRoute.h
+++ b/GVONavish/GVONavish/GVOShipRoute.h
@@ -1,11 +1,12 @@
11 #pragma once
22 #include <deque>
3+#include <ctime>
34 #include "GVONormalizedPoint.h"
45
56 //!@brief 航路
67 class GVOShipRoute {
78 public:
8- typedef std::deque<GVONormalizedPoint> Line;
9+ typedef std::vector<GVONormalizedPoint> Line;
910 typedef std::deque<Line> Lines;
1011 private:
1112 Lines m_lines;
@@ -14,6 +15,9 @@ private:
1415 bool m_hilight = false;
1516 bool m_fixed = false; //!<@brief 航路固定フラグ
1617
18+ std::time_t m_earliestDateTime = std::time_t();
19+ std::time_t m_latestDateTime = std::time_t();
20+
1721 public:
1822 GVOShipRoute() = default;
1923 ~GVOShipRoute() = default;
@@ -78,6 +82,39 @@ public:
7882 {
7983 return m_length;
8084 }
85+
86+ std::time_t earliestDateTime() const
87+ {
88+ return m_earliestDateTime;
89+ }
90+
91+ // ちょっと汚いかなー
92+ void setEarliestDateTime( const std::time_t dateTime )
93+ {
94+ m_earliestDateTime = dateTime;
95+ }
96+
97+ // ちょっと汚いかなー
98+ std::time_t latestDateTime() const
99+ {
100+ return m_latestDateTime;
101+ }
102+
103+ // ちょっと汚いかなー
104+ void setLatestDateTime( const std::time_t dateTime )
105+ {
106+ m_latestDateTime = dateTime;
107+ }
108+
109+ // ちょっと汚いかなー
110+ void addLine( Line & line )
111+ {
112+ m_lines.push_back( line );
113+ }
114+ void addLine( Line && line )
115+ {
116+ m_lines.push_back( line );
117+ }
81118 private:
82119 };
83120
--- a/GVONavish/GVONavish/GVOShipRouteList.cpp
+++ b/GVONavish/GVONavish/GVOShipRouteList.cpp
@@ -2,6 +2,103 @@
22 #include "GVOShipRouteList.h"
33
44
5+namespace {
6+ struct FileHeaderV1 {
7+ enum {
8+ k_FileVersion = 1,
9+ };
10+ const uint32_t version = k_FileVersion;
11+ uint32_t favoritsCount = 0;
12+ };
13+
14+ typedef FileHeaderV1 FileHeader;
15+}
16+
17+
18+bool GVOShipRouteList::saveToFile( const std::wstring & filePath )
19+{
20+ std::unique_ptr<FILE, decltype(&::fclose)> file(::_wfopen(filePath.c_str(), L"wb"), &::fclose);
21+ if ( !file ) {
22+ return false;
23+ }
24+
25+ FileHeader fileHeader;
26+
27+ ::fseek( file.get(), sizeof(FileHeader), SEEK_SET );
28+
29+ for ( const auto & shipRoute : m_shipRouteList ) {
30+ if ( shipRoute->isFavorite() ) {
31+ ++fileHeader.favoritsCount;
32+
33+ std::time_t dateTime = std::time_t();
34+ dateTime = shipRoute->earliestDateTime();
35+ ::fwrite( &dateTime, sizeof(dateTime), 1, file.get() );
36+ dateTime = shipRoute->latestDateTime();
37+ ::fwrite( &dateTime, sizeof(dateTime), 1, file.get() );
38+
39+ const size_t lineCount = shipRoute->getLines().size();
40+ ::fwrite( &lineCount, sizeof(lineCount), 1, file.get() );
41+
42+ for ( const auto & line : shipRoute->getLines() ) {
43+ const size_t count = line.size();
44+ ::fwrite( &count, sizeof(count), 1, file.get() );
45+ if ( !line.empty() ) {
46+ ::fwrite( &line[0], sizeof(line[0]), line.size(), file.get() );
47+ }
48+ }
49+ }
50+ }
51+
52+ ::fseek( file.get(), 0, SEEK_SET );
53+ ::fwrite( &fileHeader, sizeof(fileHeader), 1, file.get() );
54+ return true;
55+}
56+
57+
58+bool GVOShipRouteList::loadFromFile( const std::wstring & filePath )
59+{
60+ std::unique_ptr<FILE, decltype(&::fclose)> file( ::_wfopen( filePath.c_str(), L"rb" ), &::fclose );
61+ if ( !file ) {
62+ return false;
63+ }
64+
65+ FileHeader fileHeader;
66+ ::fread( &fileHeader, sizeof( fileHeader ), 1, file.get() );
67+
68+ if ( fileHeader.version != FileHeader::k_FileVersion ) {
69+ return false;
70+ }
71+
72+ m_shipRouteList.clear();
73+
74+ for ( uint32_t i = 0; i < fileHeader.favoritsCount; ++i ) {
75+ GVOShipRoutePtr shipRoute( new GVOShipRoute() );
76+ shipRoute->setFavorite( true );
77+
78+ std::time_t dateTime = std::time_t();
79+ ::fread( &dateTime, sizeof(dateTime), 1, file.get() );
80+ shipRoute->setEarliestDateTime( dateTime );
81+ ::fread( &dateTime, sizeof(dateTime), 1, file.get() );
82+ shipRoute->setLatestDateTime( dateTime );
83+
84+ size_t lineCount = 0;
85+ ::fread( &lineCount, sizeof(lineCount), 1, file.get() );
86+
87+ for ( size_t k = 0; k < lineCount; ++k ) {
88+ size_t pointCount = 0;
89+ ::fread( &pointCount, sizeof(pointCount), 1, file.get() );
90+ if ( 0 < pointCount ) {
91+ GVOShipRoute::Line tmp( pointCount );
92+ ::fread( &tmp[0], sizeof(tmp[0]), tmp.size(), file.get() );
93+ shipRoute->addLine( std::move( tmp ) );
94+ }
95+ }
96+
97+ m_shipRouteList.push_back( std::move( shipRoute ) );
98+ }
99+
100+ return true;
101+}
5102
6103
7104 void GVOShipRouteList::closeRoute()
--- a/GVONavish/GVONavish/GVOShipRouteList.h
+++ b/GVONavish/GVONavish/GVOShipRouteList.h
@@ -11,6 +11,8 @@ class IGVOShipRouteListObserver;
1111 class GVOShipRouteList {
1212 private:
1313 typedef std::list<GVOShipRoutePtr> RouteList;
14+
15+private:
1416 RouteList m_shipRouteList;
1517 IGVOShipRouteListObserver * m_observer = nullptr;
1618 size_t m_maxRouteCountWithoutFavorits = 30; //!<@brief お気に入りを除外した航路保存数
@@ -19,6 +21,13 @@ public:
1921 GVOShipRouteList() = default;
2022 ~GVOShipRouteList() = default;
2123
24+ //!@note あんまり行儀が良い事じゃないけれど。
25+ bool saveToFile( const std::wstring & filePath );
26+
27+ //!@note あんまり行儀が良い事じゃないけれど。
28+ bool loadFromFile( const std::wstring & filePath );
29+
30+
2231 void setObserver( IGVOShipRouteListObserver * observer )
2332 {
2433 m_observer = observer;
@@ -55,8 +64,6 @@ public:
5564 return reverseIndex;
5665 }
5766
58- //void removeShipRouteAtReverseIndex( int reverseIndex );
59-
6067 void removeShipRoute( GVOShipRoutePtr shipRoute );
6168
6269 void clearAllItems();
Show on old repository browser