OSDN Git Service

航路保存機能試作。
authorMandhelingFreak <mandheling30-freak@yahoo.co.jp>
Mon, 10 Mar 2014 19:43:01 +0000 (04:43 +0900)
committerMandhelingFreak <mandheling30-freak@yahoo.co.jp>
Mon, 10 Mar 2014 19:43:01 +0000 (04:43 +0900)
GVONavish/GVONavish/GVONavish.cpp
GVONavish/GVONavish/GVONormalizedPoint.h
GVONavish/GVONavish/GVOShipRoute.h
GVONavish/GVONavish/GVOShipRouteList.cpp
GVONavish/GVONavish/GVOShipRouteList.h

index 78cdc6d..ddcc008 100644 (file)
@@ -87,6 +87,7 @@ static GVOConfig s_config( k_configFileName );
 static GVOGameProcess s_gvoGameProcess;
 static GVORenderer s_renderer;
 static GVOWorldMap s_worldMap;
 static GVOGameProcess s_gvoGameProcess;
 static GVORenderer s_renderer;
 static GVOWorldMap s_worldMap;
+const std::wstring && k_routeListFilePath = g_makeFullPath(L"RouteList.dat");
 static std::unique_ptr<GVOShipRouteList> s_shipRouteList;
 static POINT s_latestSurveyCoord;
 static GVOVector s_latestShipVector;
 static std::unique_ptr<GVOShipRouteList> s_shipRouteList;
 static POINT s_latestSurveyCoord;
 static GVOVector s_latestShipVector;
@@ -149,6 +150,7 @@ int APIENTRY _tWinMain( _In_ HINSTANCE hInstance,
        // \83\81\83C\83\93 \83\81\83b\83Z\81[\83\83\8b\81[\83v:
        const LRESULT retVal = s_mainLoop();
 
        // \83\81\83C\83\93 \83\81\83b\83Z\81[\83\83\8b\81[\83v:
        const LRESULT retVal = s_mainLoop();
 
+       s_shipRouteList->saveToFile( k_routeListFilePath );
        s_gvoGameProcess.teardown();
 
        s_config.save();
        s_gvoGameProcess.teardown();
 
        s_config.save();
@@ -216,6 +218,7 @@ static BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
        s_renderer.setup( &s_config, g_hdcMain, &s_worldMap );
 
        s_shipRouteList.reset( new GVOShipRouteList() );
        s_renderer.setup( &s_config, g_hdcMain, &s_worldMap );
 
        s_shipRouteList.reset( new GVOShipRouteList() );
+       s_shipRouteList->loadFromFile( k_routeListFilePath );
        s_pollingInterval = s_config.m_pollingInterval;
        s_gvoGameProcess.setup( s_config );
 
        s_pollingInterval = s_config.m_pollingInterval;
        s_gvoGameProcess.setup( s_config );
 
index 6e68ce0..18af47a 100644 (file)
@@ -31,4 +31,8 @@ public:
        {
                return m_y;
        }
        {
                return m_y;
        }
+
 };
 };
+
+// \83t\83@\83C\83\8b\93ü\8fo\97Í\97p\82É\83A\83\89\83C\83\81\83\93\83g\8am\94F
+static_assert(sizeof(GVONormalizedPoint) == (sizeof(float)*2), "bat size.");
index 3470c6c..954091e 100644 (file)
@@ -1,11 +1,12 @@
 #pragma once
 #include <deque>
 #pragma once
 #include <deque>
+#include <ctime>
 #include "GVONormalizedPoint.h"
 
 //!@brief \8dq\98H
 class GVOShipRoute {
 public:
 #include "GVONormalizedPoint.h"
 
 //!@brief \8dq\98H
 class GVOShipRoute {
 public:
-       typedef std::deque<GVONormalizedPoint> Line;
+       typedef std::vector<GVONormalizedPoint> Line;
        typedef std::deque<Line> Lines;
 private:
        Lines m_lines;
        typedef std::deque<Line> Lines;
 private:
        Lines m_lines;
@@ -14,6 +15,9 @@ private:
        bool m_hilight = false;
        bool m_fixed = false;           //!<@brief \8dq\98H\8cÅ\92è\83t\83\89\83O
 
        bool m_hilight = false;
        bool m_fixed = false;           //!<@brief \8dq\98H\8cÅ\92è\83t\83\89\83O
 
+       std::time_t m_earliestDateTime = std::time_t();
+       std::time_t m_latestDateTime = std::time_t();
+
 public:
        GVOShipRoute() = default;
        ~GVOShipRoute() = default;
 public:
        GVOShipRoute() = default;
        ~GVOShipRoute() = default;
@@ -78,6 +82,39 @@ public:
        {
                return m_length;
        }
        {
                return m_length;
        }
+
+       std::time_t earliestDateTime() const
+       {
+               return m_earliestDateTime;
+       }
+
+       // \82¿\82å\82Á\82Æ\89\98\82¢\82©\82È\81[
+       void setEarliestDateTime( const std::time_t dateTime )
+       {
+               m_earliestDateTime = dateTime;
+       }
+
+       // \82¿\82å\82Á\82Æ\89\98\82¢\82©\82È\81[
+       std::time_t latestDateTime() const
+       {
+               return m_latestDateTime;
+       }
+
+       // \82¿\82å\82Á\82Æ\89\98\82¢\82©\82È\81[
+       void setLatestDateTime( const std::time_t dateTime )
+       {
+               m_latestDateTime = dateTime;
+       }
+
+       // \82¿\82å\82Á\82Æ\89\98\82¢\82©\82È\81[
+       void addLine( Line & line )
+       {
+               m_lines.push_back( line );
+       }
+       void addLine( Line && line )
+       {
+               m_lines.push_back( line );
+       }
 private:
 };
 
 private:
 };
 
index b343545..01e9789 100644 (file)
@@ -2,6 +2,103 @@
 #include "GVOShipRouteList.h"
 
 
 #include "GVOShipRouteList.h"
 
 
+namespace {
+       struct FileHeaderV1 {
+               enum {
+                       k_FileVersion = 1,
+               };
+               const uint32_t version = k_FileVersion;
+               uint32_t favoritsCount = 0;
+       };
+
+       typedef FileHeaderV1 FileHeader;
+}
+
+
+bool GVOShipRouteList::saveToFile( const std::wstring & filePath )
+{
+       std::unique_ptr<FILE, decltype(&::fclose)> file(::_wfopen(filePath.c_str(), L"wb"), &::fclose);
+       if ( !file ) {
+               return false;
+       }
+
+       FileHeader fileHeader;
+
+       ::fseek( file.get(), sizeof(FileHeader), SEEK_SET );
+
+       for ( const auto & shipRoute : m_shipRouteList ) {
+               if ( shipRoute->isFavorite() ) {
+                       ++fileHeader.favoritsCount;
+
+                       std::time_t dateTime = std::time_t();
+                       dateTime = shipRoute->earliestDateTime();
+                       ::fwrite( &dateTime, sizeof(dateTime), 1, file.get() );
+                       dateTime = shipRoute->latestDateTime();
+                       ::fwrite( &dateTime, sizeof(dateTime), 1, file.get() );
+
+                       const size_t lineCount = shipRoute->getLines().size();
+                       ::fwrite( &lineCount, sizeof(lineCount), 1, file.get() );
+
+                       for ( const auto & line : shipRoute->getLines() ) {
+                               const size_t count = line.size();
+                               ::fwrite( &count, sizeof(count), 1, file.get() );
+                               if ( !line.empty() ) {
+                                       ::fwrite( &line[0], sizeof(line[0]), line.size(), file.get() );
+                               }
+                       }
+               }
+       }
+
+       ::fseek( file.get(), 0, SEEK_SET );
+       ::fwrite( &fileHeader, sizeof(fileHeader), 1, file.get() );
+       return true;
+}
+
+
+bool GVOShipRouteList::loadFromFile( const std::wstring & filePath )
+{
+       std::unique_ptr<FILE, decltype(&::fclose)> file( ::_wfopen( filePath.c_str(), L"rb" ), &::fclose );
+       if ( !file ) {
+               return false;
+       }
+
+       FileHeader fileHeader;
+       ::fread( &fileHeader, sizeof( fileHeader ), 1, file.get() );
+
+       if ( fileHeader.version != FileHeader::k_FileVersion ) {
+               return false;
+       }
+
+       m_shipRouteList.clear();
+
+       for ( uint32_t i = 0; i < fileHeader.favoritsCount; ++i ) {
+               GVOShipRoutePtr shipRoute( new GVOShipRoute() );
+               shipRoute->setFavorite( true );
+
+               std::time_t dateTime = std::time_t();
+               ::fread( &dateTime, sizeof(dateTime), 1, file.get() );
+               shipRoute->setEarliestDateTime( dateTime );
+               ::fread( &dateTime, sizeof(dateTime), 1, file.get() );
+               shipRoute->setLatestDateTime( dateTime );
+
+               size_t lineCount = 0;
+               ::fread( &lineCount, sizeof(lineCount), 1, file.get() );
+
+               for ( size_t k = 0; k < lineCount; ++k ) {
+                       size_t pointCount = 0;
+                       ::fread( &pointCount, sizeof(pointCount), 1, file.get() );
+                       if ( 0 < pointCount ) {
+                               GVOShipRoute::Line tmp( pointCount );
+                               ::fread( &tmp[0], sizeof(tmp[0]), tmp.size(), file.get() );
+                               shipRoute->addLine( std::move( tmp ) );
+                       }
+               }
+
+               m_shipRouteList.push_back( std::move( shipRoute ) );
+       }
+
+       return true;
+}
 
 
 void GVOShipRouteList::closeRoute()
 
 
 void GVOShipRouteList::closeRoute()
index 436277d..68dbd0b 100644 (file)
@@ -11,6 +11,8 @@ class IGVOShipRouteListObserver;
 class GVOShipRouteList {
 private:
        typedef std::list<GVOShipRoutePtr> RouteList;
 class GVOShipRouteList {
 private:
        typedef std::list<GVOShipRoutePtr> RouteList;
+
+private:
        RouteList m_shipRouteList;
        IGVOShipRouteListObserver * m_observer = nullptr;
        size_t m_maxRouteCountWithoutFavorits = 30;     //!<@brief \82¨\8bC\82É\93ü\82è\82ð\8f\9c\8aO\82µ\82½\8dq\98H\95Û\91\90\94
        RouteList m_shipRouteList;
        IGVOShipRouteListObserver * m_observer = nullptr;
        size_t m_maxRouteCountWithoutFavorits = 30;     //!<@brief \82¨\8bC\82É\93ü\82è\82ð\8f\9c\8aO\82µ\82½\8dq\98H\95Û\91\90\94
@@ -19,6 +21,13 @@ public:
        GVOShipRouteList() = default;
        ~GVOShipRouteList() = default;
 
        GVOShipRouteList() = default;
        ~GVOShipRouteList() = default;
 
+       //!@note \82 \82ñ\82Ü\82è\8ds\8bV\82ª\97Ç\82¢\8e\96\82\82á\82È\82¢\82¯\82ê\82Ç\81B
+       bool saveToFile( const std::wstring & filePath );
+
+       //!@note \82 \82ñ\82Ü\82è\8ds\8bV\82ª\97Ç\82¢\8e\96\82\82á\82È\82¢\82¯\82ê\82Ç\81B
+       bool loadFromFile( const std::wstring & filePath );
+
+
        void setObserver( IGVOShipRouteListObserver * observer )
        {
                m_observer = observer;
        void setObserver( IGVOShipRouteListObserver * observer )
        {
                m_observer = observer;
@@ -55,8 +64,6 @@ public:
                return reverseIndex;
        }
 
                return reverseIndex;
        }
 
-       //void removeShipRouteAtReverseIndex( int reverseIndex );
-
        void removeShipRoute( GVOShipRoutePtr shipRoute );
 
        void clearAllItems();
        void removeShipRoute( GVOShipRoutePtr shipRoute );
 
        void clearAllItems();