This is an automated email from the git hooks/post-receive script. smcv pushed a commit to branch debian/master in repository openjk.
commit 3761dffdcbc65f01d43c01996e4b1bcc48fc62f6 Author: bibendovsky <[email protected]> Date: Thu Jul 7 23:04:12 2016 +0300 Implement method open --- code/cgame/cg_main.cpp | 2 +- code/game/G_Timer.cpp | 2 +- code/game/Q3_Interface.cpp | 2 +- code/game/g_main.cpp | 2 +- code/game/g_objectives.cpp | 2 +- code/game/g_roff.cpp | 2 +- code/game/g_savegame.cpp | 2 +- code/icarus/IcarusImplementation.cpp | 2 +- code/qcommon/cm_load.cpp | 2 +- code/rd-vanilla/G2_misc.cpp | 2 +- code/server/sv_savegame.cpp | 2 +- codeJK2/cgame/cg_main.cpp | 2 +- codeJK2/game/G_Timer.cpp | 2 +- codeJK2/game/Q3_Registers.cpp | 2 +- codeJK2/game/g_main.cpp | 2 +- codeJK2/game/g_objectives.cpp | 2 +- codeJK2/game/g_roff.cpp | 2 +- codeJK2/game/g_savegame.cpp | 2 +- codeJK2/icarus/Instance.cpp | 2 +- codeJK2/icarus/Sequence.cpp | 2 +- codeJK2/icarus/Sequencer.cpp | 2 +- codeJK2/icarus/TaskManager.cpp | 2 +- shared/qcommon/ojk_saved_game.cpp | 189 +++++++++++++++++++++++++++++------ shared/qcommon/ojk_saved_game_fwd.h | 20 ++-- 24 files changed, 195 insertions(+), 58 deletions(-) diff --git a/code/cgame/cg_main.cpp b/code/cgame/cg_main.cpp index d93d4f7..2ffa679 100644 --- a/code/cgame/cg_main.cpp +++ b/code/cgame/cg_main.cpp @@ -29,7 +29,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "../qcommon/sstring.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" //NOTENOTE: Be sure to change the mirrored code in g_shared.h typedef std::map< sstring_t, unsigned char > namePrecache_m; diff --git a/code/game/G_Timer.cpp b/code/game/G_Timer.cpp index 2e97b40..eb8cf38 100644 --- a/code/game/G_Timer.cpp +++ b/code/game/G_Timer.cpp @@ -23,7 +23,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "g_local.h" #include "../Rufl/hstring.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" #define MAX_GTIMERS 16384 diff --git a/code/game/Q3_Interface.cpp b/code/game/Q3_Interface.cpp index e395e1f..13e9c5d 100644 --- a/code/game/Q3_Interface.cpp +++ b/code/game/Q3_Interface.cpp @@ -41,7 +41,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "g_vehicles.h" #include "g_navigator.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" extern cvar_t *com_buildScript; diff --git a/code/game/g_main.cpp b/code/game/g_main.cpp index e01516c..302d856 100644 --- a/code/game/g_main.cpp +++ b/code/game/g_main.cpp @@ -37,7 +37,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. //rww - RAGDOLL_END #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" extern void WP_SaberLoadParms( void ); extern qboolean G_PlayerSpawned( void ); diff --git a/code/game/g_objectives.cpp b/code/game/g_objectives.cpp index 4f0dd85..e7a87d7 100644 --- a/code/game/g_objectives.cpp +++ b/code/game/g_objectives.cpp @@ -30,7 +30,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "objectives.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" qboolean missionInfo_Updated; diff --git a/code/game/g_roff.cpp b/code/game/g_roff.cpp index 3ed0d3d..8fdecd1 100644 --- a/code/game/g_roff.cpp +++ b/code/game/g_roff.cpp @@ -26,7 +26,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "../cgame/cg_local.h" #include "g_functions.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" // The list of precached ROFFs roff_list_t roffs[MAX_ROFFS]; diff --git a/code/game/g_savegame.cpp b/code/game/g_savegame.cpp index f62c7ff..dcc46aa 100644 --- a/code/game/g_savegame.cpp +++ b/code/game/g_savegame.cpp @@ -31,7 +31,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "../cgame/cg_camera.h" #include "../qcommon/sstring.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" extern void OBJ_LoadTacticalInfo(void); diff --git a/code/icarus/IcarusImplementation.cpp b/code/icarus/IcarusImplementation.cpp index f404f51..bc2ecff 100644 --- a/code/icarus/IcarusImplementation.cpp +++ b/code/icarus/IcarusImplementation.cpp @@ -34,7 +34,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "../qcommon/q_shared.h" #include "../qcommon/qcommon.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" #define STL_ITERATE( a, b ) for ( a = b.begin(); a != b.end(); ++a ) #define STL_INSERT( a, b ) a.insert( a.end(), b ); diff --git a/code/qcommon/cm_load.cpp b/code/qcommon/cm_load.cpp index f2573e9..d809a7e 100644 --- a/code/qcommon/cm_load.cpp +++ b/code/qcommon/cm_load.cpp @@ -25,7 +25,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "cm_local.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" #ifdef BSPC void SetPlaneSignbits (cplane_t *out) { diff --git a/code/rd-vanilla/G2_misc.cpp b/code/rd-vanilla/G2_misc.cpp index 9ce7074..5b51819 100644 --- a/code/rd-vanilla/G2_misc.cpp +++ b/code/rd-vanilla/G2_misc.cpp @@ -51,7 +51,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #ifdef _G2_GORE #include "../ghoul2/ghoul2_gore.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" #define GORE_TAG_UPPER (256) #define GORE_TAG_MASK (~255) diff --git a/code/server/sv_savegame.cpp b/code/server/sv_savegame.cpp index 305a06b..03e6256 100644 --- a/code/server/sv_savegame.cpp +++ b/code/server/sv_savegame.cpp @@ -38,7 +38,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include <map> #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" static char saveGameComment[iSG_COMMENT_SIZE]; diff --git a/codeJK2/cgame/cg_main.cpp b/codeJK2/cgame/cg_main.cpp index 3ff00fb..c4c84fc 100644 --- a/codeJK2/cgame/cg_main.cpp +++ b/codeJK2/cgame/cg_main.cpp @@ -29,7 +29,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "../../code/qcommon/sstring.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" //NOTENOTE: Be sure to change the mirrored code in g_shared.h typedef std::map< sstring_t, unsigned char, std::less<sstring_t>, std::allocator< unsigned char > > namePrecache_m; diff --git a/codeJK2/game/G_Timer.cpp b/codeJK2/game/G_Timer.cpp index 26197b2..80fb4be 100644 --- a/codeJK2/game/G_Timer.cpp +++ b/codeJK2/game/G_Timer.cpp @@ -24,7 +24,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "g_local.h" #include "../../code/Rufl/hstring.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" #define MAX_GTIMERS 16384 diff --git a/codeJK2/game/Q3_Registers.cpp b/codeJK2/game/Q3_Registers.cpp index 87c21a5..269e4f6 100644 --- a/codeJK2/game/Q3_Registers.cpp +++ b/codeJK2/game/Q3_Registers.cpp @@ -25,7 +25,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "g_local.h" #include "Q3_Registers.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" extern void Q3_DebugPrint( int level, const char *format, ... ); diff --git a/codeJK2/game/g_main.cpp b/codeJK2/game/g_main.cpp index 76f6f96..bc09a5d 100644 --- a/codeJK2/game/g_main.cpp +++ b/codeJK2/game/g_main.cpp @@ -36,7 +36,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "../cgame/cg_local.h" // yeah I know this is naughty, but we're shipping soon... #include "time.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" extern CNavigator navigator; diff --git a/codeJK2/game/g_objectives.cpp b/codeJK2/game/g_objectives.cpp index 9fdbc4c..8420d2a 100644 --- a/codeJK2/game/g_objectives.cpp +++ b/codeJK2/game/g_objectives.cpp @@ -32,7 +32,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "objectives.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" qboolean missionInfo_Updated; diff --git a/codeJK2/game/g_roff.cpp b/codeJK2/game/g_roff.cpp index 749c7e0..abdda30 100644 --- a/codeJK2/game/g_roff.cpp +++ b/codeJK2/game/g_roff.cpp @@ -26,7 +26,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "g_roff.h" #include "g_icarus.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" // The list of precached ROFFs roff_list_t roffs[MAX_ROFFS]; diff --git a/codeJK2/game/g_savegame.cpp b/codeJK2/game/g_savegame.cpp index 799c9e9..e0e4333 100644 --- a/codeJK2/game/g_savegame.cpp +++ b/codeJK2/game/g_savegame.cpp @@ -34,7 +34,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "g_icarus.h" #include "../../code/qcommon/sstring.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" extern void OBJ_LoadTacticalInfo(void); diff --git a/codeJK2/icarus/Instance.cpp b/codeJK2/icarus/Instance.cpp index 6a833f5..0d9693b 100644 --- a/codeJK2/icarus/Instance.cpp +++ b/codeJK2/icarus/Instance.cpp @@ -30,7 +30,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include <assert.h> #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" // Instance diff --git a/codeJK2/icarus/Sequence.cpp b/codeJK2/icarus/Sequence.cpp index 7f2cbba..5add77e 100644 --- a/codeJK2/icarus/Sequence.cpp +++ b/codeJK2/icarus/Sequence.cpp @@ -29,7 +29,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include <assert.h> #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" CSequence::CSequence( void ) { diff --git a/codeJK2/icarus/Sequencer.cpp b/codeJK2/icarus/Sequencer.cpp index 8096d3f..bbf7184 100644 --- a/codeJK2/icarus/Sequencer.cpp +++ b/codeJK2/icarus/Sequencer.cpp @@ -31,7 +31,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include "assert.h" #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_sg_archive.h" +#include "qcommon/ojk_saved_game_fwd.h" // Sequencer diff --git a/codeJK2/icarus/TaskManager.cpp b/codeJK2/icarus/TaskManager.cpp index 3b32e53..f17bad7 100644 --- a/codeJK2/icarus/TaskManager.cpp +++ b/codeJK2/icarus/TaskManager.cpp @@ -32,7 +32,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>. #include <assert.h> #include "qcommon/ojk_sg_wrappers.h" -#include "qcommon/ojk_saved_game.h" +#include "qcommon/ojk_saved_game_fwd.h" #define ICARUS_VALIDATE(a) if ( a == false ) return TASK_FAILED; diff --git a/shared/qcommon/ojk_saved_game.cpp b/shared/qcommon/ojk_saved_game.cpp index dd3f384..343d559 100644 --- a/shared/qcommon/ojk_saved_game.cpp +++ b/shared/qcommon/ojk_saved_game.cpp @@ -12,7 +12,7 @@ SavedGame::SavedGame() : io_buffer_(), io_buffer_offset_(), rle_buffer_(), - is_testing_read_chunk_() + is_preview_mode_() { } @@ -121,8 +121,126 @@ void SavedGame::close() bool SavedGame::read_chunk( const SavedGame::ChunkId chunk_id) { - throw SavedGameException( - "Not implemented."); + auto chunk_id_string = get_chunk_id_string( + chunk_id); + + ::Com_DPrintf( + "Attempting read of chunk %s\n", + chunk_id_string.c_str()); + + // Load in chid and length... + // + uint32_t ulLoadedChid = 0; + uint32_t uiLoadedLength = 0; + + auto uiLoaded = ::FS_Read( + &ulLoadedChid, + static_cast<int>(sizeof(ulLoadedChid)), + file_handle_); + + uiLoaded += ::FS_Read( + &uiLoadedLength, + static_cast<int>(sizeof(uiLoadedLength)), + file_handle_); + + auto bBlockIsCompressed = (static_cast<int32_t>(uiLoadedLength) < 0); + + if (bBlockIsCompressed) { + uiLoadedLength = -static_cast<int32_t>(uiLoadedLength); + } + + // Make sure we are loading the correct chunk... + // + if (ulLoadedChid != chunk_id) { + auto loaded_chunk_id_string = get_chunk_id_string(ulLoadedChid); + + if (!is_preview_mode_) { + ::Com_Error( + ERR_DROP, + "Loaded chunk ID (%s) does not match requested chunk ID (%s)", + loaded_chunk_id_string.c_str(), + chunk_id_string.c_str()); + } + + return false; + } + + // Load in data and magic number... + // + uint32_t uiCompressedLength = 0; + + if (bBlockIsCompressed) { + uiLoaded += ::FS_Read( + &uiCompressedLength, + static_cast<int>(uiCompressedLength), + file_handle_); + + rle_buffer_.resize( + uiCompressedLength); + + uiLoaded += ::FS_Read( + rle_buffer_.data(), + uiCompressedLength, + file_handle_); + + decompress( + rle_buffer_, + io_buffer_); + } else { + io_buffer_.resize( + uiLoadedLength); + + uiLoaded += ::FS_Read( + io_buffer_.data(), + uiLoadedLength, + file_handle_); + } + + // Get checksum... + // + uint32_t uiLoadedCksum = 0; + + uiLoaded += ::FS_Read( + &uiLoadedCksum, + static_cast<int>(sizeof(uiLoadedCksum)), + file_handle_); + + // Make sure the checksums match... + // + auto uiCksum = ::Com_BlockChecksum( + io_buffer_.data(), + static_cast<int>(io_buffer_.size())); + + if (uiLoadedCksum != uiCksum) { + if (!is_preview_mode_) { + ::Com_Error( + ERR_DROP, + "Failed checksum check for chunk", + chunk_id_string.c_str()); + } + + return false; + } + + // Make sure we didn't encounter any read errors... + if (uiLoaded != + sizeof(ulLoadedChid) + + sizeof(uiLoadedLength) + + sizeof(uiLoadedCksum) + + (bBlockIsCompressed ? sizeof(uiCompressedLength) : 0) + + (bBlockIsCompressed ? uiCompressedLength : io_buffer_.size())) + { + if (!is_preview_mode_) { + ::Com_Error( + ERR_DROP, + "Error during loading chunk %s", + chunk_id_string.c_str()); + } + + return false; + } + + return true; } bool SavedGame::write_chunk( @@ -169,22 +287,24 @@ SavedGame& SavedGame::get_instance() return result; } -int SavedGame::compress() +void SavedGame::compress( + const Buffer& src_buffer, + Buffer& dst_buffer) { - auto src_size = static_cast<int>(io_buffer_.size()); + auto src_size = static_cast<int>(src_buffer.size()); - rle_buffer_.resize(2 * src_size); + dst_buffer.resize(2 * src_size); int src_count = 0; int dst_index = 0; while (src_count < src_size) { auto src_index = src_count; - auto b = io_buffer_[src_index++]; + auto b = src_buffer[src_index++]; while (src_index < src_size && (src_index - src_count) < 127 && - io_buffer_[src_index] == b) + src_buffer[src_index] == b) { src_index += 1; } @@ -192,73 +312,71 @@ int SavedGame::compress() if ((src_index - src_count) == 1) { while (src_index < src_size && (src_index - src_count) < 127 && ( - io_buffer_[src_index] != io_buffer_[src_index - 1] || ( + src_buffer[src_index] != src_buffer[src_index - 1] || ( src_index > 1 && - io_buffer_[src_index] != io_buffer_[src_index - 2]))) + src_buffer[src_index] != src_buffer[src_index - 2]))) { src_index += 1; } while (src_index < src_size && - io_buffer_[src_index] == io_buffer_[src_index - 1]) + src_buffer[src_index] == src_buffer[src_index - 1]) { src_index -= 1; } - rle_buffer_[dst_index++] = + dst_buffer[dst_index++] = static_cast<uint8_t>(src_count - src_index); for (auto i = src_count; i < src_index; ++i) { - rle_buffer_[dst_index++] = io_buffer_[i]; + dst_buffer[dst_index++] = src_buffer[i]; } } else { - rle_buffer_[dst_index++] = + dst_buffer[dst_index++] = static_cast<uint8_t>(src_index - src_count); - rle_buffer_[dst_index++] = b; + dst_buffer[dst_index++] = b; } src_count = src_index; } - rle_buffer_.resize( + dst_buffer.resize( dst_index); - - return dst_index; } void SavedGame::decompress( - int dst_size) + const Buffer& src_buffer, + Buffer& dst_buffer) { - rle_buffer_.resize( - dst_size); - int src_index = 0; int dst_index = 0; - while (dst_size > 0) { - auto count = static_cast<int8_t>(io_buffer_[src_index++]); + auto remain_size = static_cast<int>(dst_buffer.size()); + + while (remain_size > 0) { + auto count = static_cast<int8_t>(src_buffer[src_index++]); if (count > 0) { std::uninitialized_fill_n( - &rle_buffer_[dst_index], + &dst_buffer[dst_index], count, - io_buffer_[src_index++]); + src_buffer[src_index++]); } else { if (count < 0) { count = -count; std::uninitialized_copy_n( - &io_buffer_[src_index], + &src_buffer[src_index], count, - &rle_buffer_[dst_index]); + &dst_buffer[dst_index]); src_index += count; } } dst_index += count; - dst_size -= count; + remain_size -= count; } } @@ -309,5 +427,18 @@ std::string SavedGame::get_failed_to_open_message( return result; } +std::string SavedGame::get_chunk_id_string( + uint32_t chunk_id) +{ + std::string result(4, '\0'); + + result[0] = static_cast<char>((chunk_id >> 24) & 0xFF); + result[1] = static_cast<char>((chunk_id >> 16) & 0xFF); + result[2] = static_cast<char>((chunk_id >> 8) & 0xFF); + result[3] = static_cast<char>((chunk_id >> 0) & 0xFF); + + return result; +} + } // ojk diff --git a/shared/qcommon/ojk_saved_game_fwd.h b/shared/qcommon/ojk_saved_game_fwd.h index 0c1886c..55f932c 100644 --- a/shared/qcommon/ojk_saved_game_fwd.h +++ b/shared/qcommon/ojk_saved_game_fwd.h @@ -152,16 +152,18 @@ private: Buffer rle_buffer_; // Does not throws an exception on chunk reading if true. - bool is_testing_read_chunk_; + bool is_preview_mode_; - // Compresses I/O buffer into RLE one. - // Returns a size of compressed data. - int compress(); + // Compresses data. + static void compress( + const Buffer& src_buffer, + Buffer& dst_buffer); - // Decompresses I/O buffer into RLE one. - void decompress( - int dst_size); + // Decompresses data. + static void decompress( + const Buffer& src_buffer, + Buffer& dst_buffer); static std::string generate_path( @@ -172,6 +174,10 @@ private: bool is_open); + static std::string get_chunk_id_string( + uint32_t chunk_id); + + // Checks if there is enough data for reading in the I/O buffer. template<typename T> void check_io_buffer( -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/openjk.git _______________________________________________ Pkg-games-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

