Skip to content

Commit

Permalink
Add some extra build options
Browse files Browse the repository at this point in the history
  • Loading branch information
Speak2Erase committed May 3, 2022
1 parent ed12ab7 commit c3d8ac9
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 38 deletions.
43 changes: 43 additions & 0 deletions binding-mri/binding-mri-win32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef BINDING_MRI_WIN32_H
#define BINDING_MRI_WIN32_H


#include <windows.h>
#include "win-consoleutils.h"

// Attempts to set $stdout and $stdin accordingly on Windows. Only
// called when debug mode is on, since that's when the console
// should be active.
void configureWindowsStreams() {
const int stdoutFD = getStdFD(STD_OUTPUT_HANDLE);

// Configure $stdout
if (stdoutFD >= 0) {
VALUE winStdout = rb_funcall(rb_cIO, rb_intern("new"), 2,
INT2NUM(stdoutFD), rb_str_new_cstr("w+"));

rb_gv_set("stdout", winStdout);
}

const int stdinFD = getStdFD(STD_INPUT_HANDLE);

// Configure $stdin
if (stdinFD >= 0) {
VALUE winStdin = rb_funcall(rb_cIO, rb_intern("new"), 2,
INT2NUM(stdinFD), rb_str_new_cstr("r"));

rb_gv_set("stdin", winStdin);
}

const int stderrFD = getStdFD(STD_ERROR_HANDLE);

// Configure $stderr
if (stderrFD >= 0) {
VALUE winStderr = rb_funcall(rb_cIO, rb_intern("new"), 2,
INT2NUM(stderrFD), rb_str_new_cstr("w+"));

rb_gv_set("stderr", winStderr);
}
}

#endif
62 changes: 57 additions & 5 deletions binding-mri/binding-mri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

#include "otherview-message.h"

#ifdef __WIN32
#include "binding-mri-win32.h"
#endif

#include <ruby.h>
#include <ruby/encoding.h>
#undef inline
Expand Down Expand Up @@ -175,6 +179,12 @@ static void mriBindingInit()
" ENV['SSL_CERT_FILE'] = './lib/cacert.pem'\n"
"end\n"
);

#ifdef __WIN32
if (shState->config().winConsole)
configureWindowsStreams();
#endif

}

static void
Expand Down Expand Up @@ -604,6 +614,8 @@ static void showExc(VALUE exc, const BacktraceData &btData)

static void mriBindingExecute()
{
Config &conf = shState->rtData().config;

/* Normally only a ruby executable would do a sysinit,
* but not doing it will lead to crashes due to closed
* stdio streams on some platforms (eg. Windows) */
Expand All @@ -626,13 +638,53 @@ static void mriBindingExecute()
// the three arguments are the executable name, and the '-e ""' is to tell ruby to run an empty file
// otherwise (since this parses options for the ruby executable) it's gonna wait on stdin for code
// --jit enables the jit i think
char options_argv1[] = "oneshot", options_argv2[] = "-e", options_argv3[] = "";
char* options_argv[] = {options_argv1, options_argv2, options_argv3, NULL};
ruby_options(3, options_argv);
std::vector<const char*> rubyArgsC{"oneshot"};
rubyArgsC.push_back("-e ");
void *node;
if (conf.mjitEnabled) {
std::string verboseLevel("--mjit-verbose="); verboseLevel += std::to_string(conf.mjitVerbosity);
std::string maxCache("--mjit-max-cache="); maxCache += std::to_string(conf.mjitMaxCache);
std::string minCalls("--mjit-min-calls="); minCalls += std::to_string(conf.mjitMinCalls);
rubyArgsC.push_back("--mjit");
rubyArgsC.push_back(verboseLevel.c_str());
rubyArgsC.push_back(maxCache.c_str());
rubyArgsC.push_back(minCalls.c_str());
}

rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));
if (conf.yjitEnabled) {
std::string callThreshold("--yjit-call-threshold="); callThreshold += std::to_string(conf.yjitCallThreshold);
std::string maxVersions("--yjit-max-versions="); maxVersions += std::to_string(conf.yjitMaxVersions);
std::string greedyVersioning("--yjit-greedy-versioning"); greedyVersioning += std::to_string(conf.yjitGreedyVersioning);
rubyArgsC.push_back("--yjit");
rubyArgsC.push_back(callThreshold.c_str());
rubyArgsC.push_back(maxVersions.c_str());
rubyArgsC.push_back(greedyVersioning.c_str());
}

Config &conf = shState->rtData().config;
if (conf.jitEnabled) {
std::string verboseLevel("-jit-verbose="); verboseLevel += std::to_string(conf.jitVerbosity);
std::string maxCache("--jit-max-cache="); maxCache += std::to_string(conf.jitMaxCache);
std::string minCalls("--jit-min-calls="); minCalls += std::to_string(conf.jitMinCalls);
rubyArgsC.push_back("--jit");
rubyArgsC.push_back(verboseLevel.c_str());
rubyArgsC.push_back(maxCache.c_str());
rubyArgsC.push_back(minCalls.c_str());
}

node = ruby_options(rubyArgsC.size(), const_cast<char**>(rubyArgsC.data()));

int state;
bool valid = ruby_executable_node(node, &state);
if (valid)
state = ruby_exec_node(node);
if (state || !valid) {
showMsg("An error occurred while initializing Ruby. (Invalid JIT settings?)");
ruby_cleanup(state);
shState->rtData().rqTermAck.set();
return;
}

rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));

if (!conf.rubyLoadpaths.empty())
{
Expand Down
31 changes: 0 additions & 31 deletions oneshot.conf.sample → modshot.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,56 @@
# relative to gameFolder and ignoring both RTPs and
# encrypted archives.


# Start the game in debug/developer mode
# (default: disabled)
#
# debugMode=false


# Continuously print average FPS to console.
# This setting does not affect the window title
# FPS display toggled via F2
# (default: disabled)
#
# printFPS=false


# Start game in fullscreen mode,
# i.e. Big Picture/console mode.
# (default: disabled)
#
# fullscreen=false


# Preserve game screen aspect ratio,
# as opposed to stretch-to-fill
# (default: enabled)
#
# fixedAspectRatio=true


# Apply linear interpolation when game screen
# is upscaled
# (default: disabled)
#
# smoothScaling=false


# Sync screen redraws to the monitor refresh rate
# (default: enabled)
#
# vsync=true


# Override the game window title
# (default: none)
#
# windowTitle=Custom Title


# Enforce a static frame rate
# (0 = disabled)
#
# fixedFramerate=0


# Skip (don't draw) frames when behind
# (default: enabled)
#
# frameSkip=true


# Use a fixed framerate that is approx. equal to the
# native screen refresh rate. This is different from
# "fixedFramerate" because the actual frame rate is
Expand All @@ -79,13 +69,11 @@
#
# syncToRefreshrate=false


# Don't use alpha blending when rendering text
# (default: disabled)
#
# solidFonts=false


# Work around buggy graphics drivers which don't
# properly synchronize texture access, most
# apparent when text doesn't show up or the map
Expand All @@ -94,7 +82,6 @@
#
# subImageFix=false


# Enable framebuffer blitting if the driver is
# capable of it. Some drivers carry buggy
# implementations of this functionality, so
Expand All @@ -103,7 +90,6 @@
#
# enableBlitting=true


# Limit the maximum size (width, height) of
# most textures mkxp will create (exceptions are
# rendering backbuffers and similar).
Expand All @@ -114,49 +100,34 @@
#
# maxTextureSize=0


# Set the base path of the game to '/path/to/game'
# (default: executable directory)
#
# gameFolder=/path/to/game


# Allow symlinks for game assets to be followed
# (default: disabled)
#
# allowSymlinks=false


# Set the game window icon to 'path/to/icon.png'
# (default: none)
#
# iconPath=/path/to/icon.png


# Define raw scripts to be executed before the
# actual Scripts.rxdata execution starts
# (default: none)
#
# preloadScript=my_win32_wrapper.rb
# preloadScript=ruby18_fixes.rb


# Index all accesible assets via their lower case path
# (emulates windows case insensitivity)
# (default: enabled)
#
# pathCache=true


# Add 'rtp1', 'rtp2.zip' and 'game.rgssad' to the
# asset search path (multiple allowed)
# (default: none)
#
# RTP=/path/to/rtp1
# RTP=/path/to/rtp2.zip
# RTP=/path/to/game.rgssad


# Font substitutions allow drop-in replacements of fonts
# to be used without changing the RGSS scripts,
# eg. providing 'Open Sans' when the game thinkgs it's
Expand All @@ -171,7 +142,6 @@
# fontSub=Arial>Open Sans
# fontSub=Times New Roman>Liberation Serif


# Because mkxp is usually distributed as a stand alone
# build, no predefined load paths are initialized
# ($:, $LOAD_PATH) in the MRI backend. With this option,
Expand All @@ -183,7 +153,6 @@
# rubyLoadpath=/usr/lib64/ruby/
# rubyLoadpath=/usr/local/share/ruby/site_ruby


# Number of OpenAL sources to allocate for SE playback.
# If there are a lot of sounds playing at the same time
# and audibly cutting each other off, try increasing
Expand Down
19 changes: 19 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
#include "gamecontrollerdb.txt.xxd"
#endif

#ifdef __WIN32
#include "win-consoleutils.h"
#endif

static void
rgssThreadError(RGSSThreadData *rtData, const std::string &msg)
{
Expand Down Expand Up @@ -297,6 +301,21 @@ int main(int argc, char *argv[]) {
showInitError(std::string("Unable to switch into gameFolder ") + conf.gameFolder);
return 0;
}

#ifdef __WIN32
// Create a debug console in debug mode
if (conf.winConsole) {
if (setupWindowsConsole()) {
reopenWindowsStreams();
} else {
char buf[200];
snprintf(buf, sizeof(buf), "Error allocating console: %lu",
GetLastError());
showInitError(std::string(buf));
}
}
#endif


extern int screenMain(Config &conf);
if (conf.screenMode)
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ main_source = files(
'thread/source/eventthread.cpp',
'thread/source/sharedstate.cpp',
'util/source/config.cpp',
'util/source/win-consoleutils.cpp',
'main.cpp'
)

Expand Down
43 changes: 43 additions & 0 deletions src/util/headers/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,49 @@ struct Config
bool allowSymlinks;
bool pathCache;

/*
MJIT options (experimental):
--mjit-warnings Enable printing JIT warnings
--mjit-debug Enable JIT debugging (very slow), or add cflags if specified
--mjit-wait Wait until JIT compilation finishes every time (for testing)
--mjit-save-temps
Save JIT temporary files in $TMP or /tmp (for testing)
--mjit-verbose=num
Print JIT logs of level num or less to stderr (default: 0)
--mjit-max-cache=num
Max number of methods to be JIT-ed in a cache (default: 10000)
--mjit-min-calls=num
Number of calls to trigger JIT (for testing, default: 10000)
YJIT options (experimental):
--yjit-exec-mem-size=num
Size of executable memory block in MiB (default: 256)
--yjit-call-threshold
Number of calls to trigger JIT (default: 10)
--yjit-max-versions
Maximum number of versions per basic block (default: 4)
--yjit-greedy-versioning
Greedy versioning mode (default: disabled)
*/

bool mjitEnabled;
int mjitVerbosity;
int mjitMaxCache;
int mjitMinCalls;

bool yjitEnabled;
int yjitCallThreshold;
int yjitMaxVersions;
bool yjitGreedyVersioning;

// This is for older versions of Ruby (3.0.* and below)
bool jitEnabled;
int jitVerbosity;
int jitMaxCache;
int jitMinCalls;

bool winConsole;

std::string iconPath;

struct
Expand Down
Loading

0 comments on commit c3d8ac9

Please sign in to comment.