Skip to content

Commit

Permalink
Create Oneshot::crc32 Ruby function
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
queengooborg committed Feb 28, 2018
1 parent cd6b77a commit 332fc3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion binding-mri/oneshot-binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "eventthread.h"

#include <SDL.h>
#include <boost/crc.hpp>

RB_METHOD(oneshotSetYesNo)
{
Expand Down Expand Up @@ -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");
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion scripts/i18n_Language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def set(lc)
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
Expand Down

0 comments on commit 332fc3d

Please sign in to comment.