Compare commits

...

4 Commits

Author SHA1 Message Date
swagtoy
4165e8fb31
Merge b2792e59f735376889de310d844efeac49a7649a into 9a1501ae89ffe79c38dbd6756c9e7ed647dd7dc1 2024-06-28 05:31:41 +00:00
swagtoy
b2792e59f7 Reload graphics & dynamic shadows
You can force reload graphics by showing the verbose debug page (press F5 a few times). It might be better to bind it to a specific keybind, but this was easier to implement and didn't require taking up another keybind.
2024-06-28 01:31:37 -04:00
grorp
9a1501ae89
CIrrDeviceSDL: Fix numpad key events not having correct KeyInput.Char (#14780)
Allows you to change viewing range using numpad +/- again. This fix also works with the current unreleased version of SDL 3.

The keycodes for numpad keys (both SDL keycodes and Irrlicht keycodes) are not the same as the keycodes for the equivalent non-numpad keys and don't correspond to chars, so I mapped them to chars manually.

Since I think the resolution of https://github.com/minetest/minetest/issues/13770 was "just disable numlock", I made sure to only do this for the numpad number keys if numlock is enabled.
2024-06-27 14:44:44 +02:00
Erich Schubert
514e106414
Fix missing newline before Markdown list (#14783)
Renders incorrectly e.g. on https://api.minetest.net/spatial-vectors/
2024-06-26 22:21:18 +02:00
14 changed files with 119 additions and 14 deletions

@ -218,6 +218,7 @@ core.register_on_formspec_input(function(formname, fields)
dialogdata.components = nil
dialogdata.rightscroll = 0
core.show_settings()
core.reload_graphics()
return true
end
end

@ -3902,6 +3902,7 @@ Operators
---------
Operators can be used if all of the involved vectors have metatables:
* `v1 == v2`:
* Returns whether `v1` and `v2` are identical.
* `-v`:

@ -129,9 +129,9 @@ EM_BOOL CIrrDeviceSDL::MouseLeaveCallback(int eventType, const EmscriptenMouseEv
}
#endif
bool CIrrDeviceSDL::keyIsKnownSpecial(EKEY_CODE key)
bool CIrrDeviceSDL::keyIsKnownSpecial(EKEY_CODE irrlichtKey)
{
switch (key) {
switch (irrlichtKey) {
// keys which are known to have safe special character interpretation
// could need changes over time (removals and additions!)
case KEY_RETURN:
@ -189,24 +189,68 @@ bool CIrrDeviceSDL::keyIsKnownSpecial(EKEY_CODE key)
}
}
int CIrrDeviceSDL::findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key)
int CIrrDeviceSDL::findCharToPassToIrrlicht(uint32_t sdlKey, EKEY_CODE irrlichtKey, bool numlock)
{
switch (irrlichtKey) {
// special cases that always return a char regardless of how the SDL keycode
// looks
switch (key) {
case KEY_RETURN:
case KEY_ESCAPE:
return (int)key;
return (int)irrlichtKey;
// This is necessary for keys on the numpad because they don't use the same
// keycodes as their non-numpad versions (whose keycodes correspond to chars),
// but have their own SDL keycodes and their own Irrlicht keycodes (which
// don't correspond to chars).
case KEY_MULTIPLY:
return '*';
case KEY_ADD:
return '+';
case KEY_SUBTRACT:
return '-';
case KEY_DIVIDE:
return '/';
default:
break;
}
if (numlock) {
// Number keys on the numpad are also affected, but we only want them
// to produce number chars when numlock is enabled.
switch (irrlichtKey) {
case KEY_NUMPAD0:
return '0';
case KEY_NUMPAD1:
return '1';
case KEY_NUMPAD2:
return '2';
case KEY_NUMPAD3:
return '3';
case KEY_NUMPAD4:
return '4';
case KEY_NUMPAD5:
return '5';
case KEY_NUMPAD6:
return '6';
case KEY_NUMPAD7:
return '7';
case KEY_NUMPAD8:
return '8';
case KEY_NUMPAD9:
return '9';
default:
break;
}
}
// SDL in-place ORs values with no character representation with 1<<30
// https://wiki.libsdl.org/SDL2/SDLKeycodeLookup
if (assumedChar & (1 << 30))
// This also affects the numpad keys btw.
if (sdlKey & (1 << 30))
return 0;
switch (key) {
switch (irrlichtKey) {
case KEY_PRIOR:
case KEY_NEXT:
case KEY_HOME:
@ -218,7 +262,7 @@ int CIrrDeviceSDL::findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key)
case KEY_NUMLOCK:
return 0;
default:
return assumedChar;
return sdlKey;
}
}
@ -825,7 +869,8 @@ bool CIrrDeviceSDL::run()
irrevent.KeyInput.PressedDown = (SDL_event.type == SDL_KEYDOWN);
irrevent.KeyInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;
irrevent.KeyInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL) != 0;
irrevent.KeyInput.Char = findCharToPassToIrrlicht(mp.SDLKey, key);
irrevent.KeyInput.Char = findCharToPassToIrrlicht(mp.SDLKey, key,
(SDL_event.key.keysym.mod & KMOD_NUM) != 0);
postEventFromUser(irrevent);
} break;

@ -273,10 +273,10 @@ class CIrrDeviceSDL : public CIrrDeviceStub
#endif
// Check if a key is a known special character with no side effects on text boxes.
static bool keyIsKnownSpecial(EKEY_CODE key);
static bool keyIsKnownSpecial(EKEY_CODE irrlichtKey);
// Return the Char that should be sent to Irrlicht for the given key (either the one passed in or 0).
static int findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key);
static int findCharToPassToIrrlicht(uint32_t sdlKey, EKEY_CODE irrlichtKey, bool numlock);
// Check if a text box is in focus. Enable or disable SDL_TEXTINPUT events only if in focus.
void resetReceiveTextInputEvents();

@ -273,6 +273,9 @@ void ClientEnvironment::step(float dtime)
auto cb_state = [this, dtime, update_lighting, day_night_ratio] (ClientActiveObject *cao) {
// Step object
cao->step(dtime, this);
if (m_update_shadows)
cao->updateSceneShadows();
if (update_lighting)
cao->updateLight(day_night_ratio);
@ -296,6 +299,9 @@ void ClientEnvironment::step(float dtime)
++i;
}
}
if (m_update_shadows)
m_update_shadows = false;
}
void ClientEnvironment::addSimpleObject(ClientSimpleObject *simple)

@ -142,13 +142,14 @@ class ClientEnvironment : public Environment
const std::set<std::string> &getPlayerNames() { return m_player_names; }
void addPlayerName(const std::string &name) { m_player_names.insert(name); }
void removePlayerName(const std::string &name) { m_player_names.erase(name); }
void updateCameraOffset(const v3s16 &camera_offset)
{ m_camera_offset = camera_offset; }
void updateCameraOffset(const v3s16 &camera_offset) { m_camera_offset = camera_offset; }
void requestUpdateShadows() { m_update_shadows = true; }
v3s16 getCameraOffset() const { return m_camera_offset; }
void updateFrameTime(bool is_paused);
u64 getFrameTime() const { return m_frame_time; }
u64 getFrameTimeDelta() const { return m_frame_dtime; }
private:
ClientMap *m_map;
@ -162,6 +163,7 @@ class ClientEnvironment : public Environment
IntervalLimiter m_active_object_light_update_interval;
std::set<std::string> m_player_names;
v3s16 m_camera_offset;
bool m_update_shadows = false;
u64 m_frame_time = 0;
u64 m_frame_dtime = 0;
u64 m_frame_time_pause_accumulator = 0;

@ -62,6 +62,7 @@ class ClientActiveObject : public ActiveObject
virtual void updateAttachments() {};
virtual bool doShowSelectionBox() { return true; }
virtual void updateSceneShadows() {}
// Step object in time
virtual void step(float dtime, ClientEnvironment *env) {}

@ -604,6 +604,17 @@ void GenericCAO::removeFromScene(bool permanent)
m_client->getMinimap()->removeMarker(&m_marker);
}
void GenericCAO::updateSceneShadows()
{
if (scene::ISceneNode *node = getSceneNode()) {
if (m_matrixnode)
node->setParent(m_matrixnode);
if (auto shadow = RenderingEngine::get_shadow_renderer())
shadow->addNodeToShadowList(node);
}
}
void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
{
m_smgr = smgr;
@ -833,6 +844,8 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
if (m_reset_textures_timer < 0)
updateTextures(m_current_texture_modifier);
if (scene::ISceneNode *node = getSceneNode()) {
if (m_matrixnode)
node->setParent(m_matrixnode);

@ -249,6 +249,7 @@ class GenericCAO : public ClientActiveObject
}
void updateLight(u32 day_night_ratio) override;
void updateSceneShadows() override;
void setNodeLight(const video::SColor &light);

@ -739,6 +739,7 @@ class Game {
void updateCameraOrientation(CameraOrientation *cam, float dtime);
void updatePlayerControl(const CameraOrientation &cam);
void updatePauseState();
void reloadGraphics();
void step(f32 dtime);
void processClientEvents(CameraOrientation *cam);
void updateCamera(f32 dtime);
@ -1126,6 +1127,12 @@ bool Game::startup(bool *kill,
return true;
}
inline void Game::reloadGraphics()
{
m_rendering_engine->initialize(client, hud);
client->getEnv().requestUpdateShadows();
}
void Game::run()
{
@ -1802,6 +1809,8 @@ bool Game::getServerContent(bool *aborted)
}
/****************************************************************************/
/****************************************************************************
Run
@ -1865,9 +1874,15 @@ inline bool Game::handleCallbacks()
if (g_gamecallback->unpause_requested) {
m_is_paused = false;
m_rendering_engine->initialize(client, hud);
g_gamecallback->unpause_requested = false;
}
if (g_gamecallback->reload_graphics_requested) {
reloadGraphics();
g_gamecallback->reload_graphics_requested = false;
}
if (g_gamecallback->show_settings_requested) {
if (client->modsLoaded())
{
@ -1911,7 +1926,9 @@ void Game::updateDebugState()
m_game_ui->m_flags.show_basic_debug = false;
} else if (m_game_ui->m_flags.show_minimal_debug) {
if (has_basic_debug)
{
m_game_ui->m_flags.show_basic_debug = true;
}
}
if (!has_basic_debug)
hud->disableBlockBounds();
@ -2523,6 +2540,7 @@ void Game::toggleDebug()
} else if (!m_game_ui->m_flags.show_profiler_graph && !draw_control->show_wireframe) {
if (has_basic_debug)
m_game_ui->m_flags.show_basic_debug = true;
reloadGraphics();
m_game_ui->m_flags.show_profiler_graph = true;
m_game_ui->showTranslatedStatusText("Profiler graph shown");
} else if (!draw_control->show_wireframe && client->checkPrivilege("debug")) {

@ -82,4 +82,4 @@ void createPipeline(const std::string &stereo_mode, IrrlichtDevice *device, Clie
// fallback to plain renderer
errorstream << "Invalid rendering mode: " << stereo_mode << std::endl;
populatePlainPipeline(result.pipeline, client);
}
}

@ -35,6 +35,7 @@ class IGameCallback
virtual void changePassword() = 0;
virtual void changeVolume() = 0;
virtual void unpause() = 0;
virtual void reloadGraphics() = 0;
virtual void showSettings() = 0;
virtual void showOpenURLDialog(const std::string &url) = 0;
virtual void signalKeyConfigChange() = 0;
@ -154,6 +155,11 @@ class MainGameCallback : public IGameCallback
unpause_requested = true;
}
void reloadGraphics() override
{
reload_graphics_requested = true;
}
void showSettings() override
{
show_settings_requested = true;
@ -165,6 +171,7 @@ class MainGameCallback : public IGameCallback
bool keyconfig_requested = false;
bool shutdown_requested = false;
bool unpause_requested = false;
bool reload_graphics_requested = false;
bool show_settings_requested = false;
bool keyconfig_changed = false;
std::string show_open_url_dialog = "";

@ -196,6 +196,12 @@ int ModApiClient::l_exit_to_os(lua_State *L)
return 1;
}
int ModApiClient::l_reload_graphics(lua_State *L)
{
g_gamecallback->reloadGraphics();
return 1;
}
int ModApiClient::l_key_config(lua_State *L)
{
g_gamecallback->keyConfig();
@ -392,6 +398,7 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(disconnect);
API_FCT(unpause);
API_FCT(exit_to_os);
API_FCT(reload_graphics);
API_FCT(key_config);
API_FCT(get_meta);
API_FCT(get_server_info);

@ -57,6 +57,9 @@ class ModApiClient : public ModApiBase
// exit_to_os()
static int l_exit_to_os(lua_State *L);
// reload_graphics()
static int l_reload_graphics(lua_State *L);
// key_config()
static int l_key_config(lua_State *L);