Create Oneshot::crc32 Ruby function

Due to issues in loading Zlib directly within Ruby, I decided to create a C++ binding.  Boost also has a much faster and smarter CRC32 implementation, so I decided to just use it instead of working with Zlib.

This also means that translations are fixed!
This commit is contained in:
Vinyl Darkscratch 2018-02-28 00:55:07 -08:00
parent cd6b77ac8f
commit 332fc3d9e0
2 changed files with 15 additions and 2 deletions

View file

@ -6,6 +6,7 @@
#include "eventthread.h"
#include <SDL.h>
#include <boost/crc.hpp>
RB_METHOD(oneshotSetYesNo)
{
@ -88,6 +89,17 @@ RB_METHOD(oneshotShake)
return Qnil;
}
RB_METHOD(oneshotCRC32)
{
RB_UNUSED_PARAM;
VALUE string;
boost::crc_32_type result;
rb_get_args(argc, argv, "S", &string RB_ARG_END);
std::string str = std::string(RSTRING_PTR(string), RSTRING_LEN(string));
result.process_bytes(str.data(), str.length());
return UINT2NUM(result.checksum());
}
void oneshotBindingInit()
{
VALUE module = rb_define_module("Oneshot");
@ -113,5 +125,6 @@ void oneshotBindingInit()
_rb_define_module_function(module, "obscured_cleared?", oneshotObscuredCleared);
_rb_define_module_function(module, "allow_exit", oneshotAllowExit);
_rb_define_module_function(module, "exiting", oneshotExiting);
_rb_define_module_function(module, "shake", oneshotShake);
_rb_define_module_function(module, "shake", oneshotShake);
_rb_define_module_function(module, "crc32", oneshotCRC32);
}

View file

@ -52,7 +52,7 @@ class Language
def tr(string)
#dbg_print(caller_locations(1, 1).first.tap{|loc| puts "#{loc.path}:#{loc.lineno}"})
if @data
rv = @data[Zlib::crc32(string)] || string
rv = @data[Oneshot::crc32(string)] || string
else
rv = string
end