• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

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

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


Commit MetaInfo

修訂36070f036c03cd57c4e715532c9f631b875e6975 (tree)
時間2014-03-14 03:02:24
作者MandhelingFreak <mandheling30-freak@yaho...>
CommiterMandhelingFreak

Log Message

航行距離が復元されないバグ修正。
ついでにファイル入出力周りの整理。

Change Summary

差異

--- a/GVONavish/GVONavish/GVOShipRoute.cpp
+++ b/GVONavish/GVONavish/GVOShipRoute.cpp
@@ -4,6 +4,14 @@
44
55
66 namespace {
7+ struct ChunkHeader {
8+ enum : uint32_t {
9+ k_Version1 = 1,
10+ };
11+ const uint32_t version = k_Version1;
12+ uint32_t lineCount = 0;
13+ };
14+
715 const float k_worldLoopThreshold = 0.5f;
816
917 inline POINT s_denormalizedPoint( const GVONormalizedPoint & point )
@@ -14,6 +22,84 @@ namespace {
1422 };
1523 return p;
1624 }
25+
26+ inline double s_calcLineLength( const GVOShipRoute::Line & line )
27+ {
28+ double length = 0.0;
29+
30+ for ( auto it = line.begin(); it != line.end(); ++it ) {
31+ auto p1 = *it;
32+ if ( std::next(it) == line.end() ) {
33+ break;
34+ }
35+ auto p2 = *std::next( it );
36+ auto vector = GVOVector( s_denormalizedPoint( p1 ), s_denormalizedPoint( p2 ) );
37+ length += vector.length();
38+ }
39+ return length;
40+ }
41+}
42+
43+
44+std::ostream & operator << (std::ostream& os, GVOShipRoute& shipRoute)
45+{
46+ _ASSERT( os.good() );
47+ if ( !os.good() ) {
48+ throw std::runtime_error( "output stream error." );
49+ }
50+
51+ ChunkHeader header;
52+ header.lineCount = shipRoute.getLines().size();
53+ os.write( reinterpret_cast<const char *>(&header), sizeof(header) );
54+
55+ for ( const auto & line : shipRoute.getLines() ) {
56+ const size_t count = line.size();
57+ os.write( reinterpret_cast<const char *>(&count), sizeof(count) );
58+ if ( !line.empty() ) {
59+ os.write( reinterpret_cast<const char *>(&line[0]), sizeof(line[0]) * line.size() );
60+ }
61+ }
62+
63+ _ASSERT( os.good() );
64+ return os;
65+}
66+
67+
68+std::istream & operator >> (std::istream& is, GVOShipRoute& shipRoute)
69+{
70+ _ASSERT( is.good() );
71+ if ( !is.good() ) {
72+ throw std::runtime_error( "input stream error." );
73+ }
74+
75+ ChunkHeader header;
76+ is.read( reinterpret_cast<char *>(&header), sizeof(header) );
77+
78+ if ( header.version != ChunkHeader::k_Version1 ) {
79+ throw std::runtime_error( "unknown file version." );
80+ }
81+
82+ shipRoute.setFavorite( true );
83+ shipRoute.setFix( true );
84+
85+ for ( size_t k = 0; k < header.lineCount; ++k ) {
86+ size_t pointCount = 0;
87+ is.read( reinterpret_cast<char *>(&pointCount), sizeof(pointCount) );
88+ if ( 0 < pointCount ) {
89+ GVOShipRoute::Line tmp( pointCount );
90+ is.read( reinterpret_cast<char *>(&tmp[0]), sizeof(tmp[0]) * tmp.size() );
91+ if ( !shipRoute.getLines().empty() && !tmp.empty() ) {
92+ auto p1 = shipRoute.getLines().back().back();
93+ auto p2 = tmp.front();
94+ shipRoute.m_length += GVOVector( s_denormalizedPoint( p1 ), s_denormalizedPoint( p2 ) ).length();
95+ }
96+ shipRoute.m_length += s_calcLineLength( tmp );
97+ shipRoute.addLine( std::move( tmp ) );
98+ }
99+ }
100+
101+ _ASSERT( is.good() );
102+ return is;
17103 }
18104
19105
--- a/GVONavish/GVONavish/GVOShipRoute.h
+++ b/GVONavish/GVONavish/GVOShipRoute.h
@@ -3,8 +3,12 @@
33 #include <ctime>
44 #include "GVONormalizedPoint.h"
55
6+
67 //!@brief q˜H
78 class GVOShipRoute {
9+ friend std::ostream & operator << (std::ostream& os, GVOShipRoute& shipRoute);
10+ friend std::istream & operator >> (std::istream& is, GVOShipRoute& shipRoute);
11+
812 public:
913 typedef std::vector<GVONormalizedPoint> Line;
1014 typedef std::deque<Line> Lines;
--- a/GVONavish/GVONavish/GVOShipRouteList.cpp
+++ b/GVONavish/GVONavish/GVOShipRouteList.cpp
@@ -30,17 +30,7 @@ std::ostream & operator <<(std::ostream & os, const GVOShipRouteList & shipRoute
3030 for ( const auto & shipRoute : shipRouteList.m_shipRouteList ) {
3131 if ( shipRoute->isFavorite() ) {
3232 ++fileHeader.favoritsCount;
33-
34- const size_t lineCount = shipRoute->getLines().size();
35- os.write( reinterpret_cast<const char *>(&lineCount), sizeof(lineCount) );
36-
37- for ( const auto & line : shipRoute->getLines() ) {
38- const size_t count = line.size();
39- os.write( reinterpret_cast<const char *>(&count), sizeof(count) );
40- if ( !line.empty() ) {
41- os.write( reinterpret_cast<const char *>(&line[0]), sizeof(line[0]) * line.size() );
42- }
43- }
33+ os << *shipRoute;
4434 }
4535 }
4636
@@ -73,20 +63,7 @@ std::istream & operator >>(std::istream & is, GVOShipRouteList & shipRouteList)
7363
7464 for ( uint32_t i = 0; i < fileHeader.favoritsCount; ++i ) {
7565 GVOShipRoutePtr shipRoute( new GVOShipRoute() );
76- shipRoute->setFavorite( true );
77-
78- size_t lineCount = 0;
79- is.read( reinterpret_cast<char *>(&lineCount), sizeof(lineCount) );
80-
81- for ( size_t k = 0; k < lineCount; ++k ) {
82- size_t pointCount = 0;
83- is.read( reinterpret_cast<char *>(&pointCount), sizeof(pointCount) );
84- if ( 0 < pointCount ) {
85- GVOShipRoute::Line tmp( pointCount );
86- is.read( reinterpret_cast<char *>(&tmp[0]), sizeof(tmp[0]) * tmp.size() );
87- shipRoute->addLine( std::move( tmp ) );
88- }
89- }
66+ is >> *shipRoute;
9067
9168 workRouteList.push_back( std::move( shipRoute ) );
9269 }