mirror of https://github.com/minetest/minetest.git
CSM: Implement register_globalstep
* Re-use fatal error mechanism from server to disconnect client on CSM error * Little client functions cleanups
This commit is contained in:
parent
22b3e09a97
commit
f0154c7912
|
@ -1,6 +1,6 @@
|
||||||
-- This is an example function to ensure it's working properly, should be removed before merge
|
-- This is an example function to ensure it's working properly, should be removed before merge
|
||||||
core.register_on_shutdown(function()
|
core.register_on_shutdown(function()
|
||||||
print("shutdown client")
|
print("[PREVIEW] shutdown client")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- This is an example function to ensure it's working properly, should be removed before merge
|
-- This is an example function to ensure it's working properly, should be removed before merge
|
||||||
|
@ -15,17 +15,25 @@ core.register_on_sending_chat_messages(function(message)
|
||||||
return false
|
return false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- This is an example function to ensure it's working properly, should be removed before merge
|
||||||
core.register_on_hp_modification(function(hp)
|
core.register_on_hp_modification(function(hp)
|
||||||
print("[PREVIEW] HP modified " .. hp)
|
print("[PREVIEW] HP modified " .. hp)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- This is an example function to ensure it's working properly, should be removed before merge
|
||||||
core.register_on_damage_taken(function(hp)
|
core.register_on_damage_taken(function(hp)
|
||||||
print("[PREVIEW] Damage taken " .. hp)
|
print("[PREVIEW] Damage taken " .. hp)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- This is an example function to ensure it's working properly, should be removed before merge
|
||||||
|
core.register_globalstep(function(dtime)
|
||||||
|
-- print("[PREVIEW] globalstep " .. dtime)
|
||||||
|
end)
|
||||||
|
|
||||||
-- This is an example function to ensure it's working properly, should be removed before merge
|
-- This is an example function to ensure it's working properly, should be removed before merge
|
||||||
core.register_chatcommand("dump", {
|
core.register_chatcommand("dump", {
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
return true, dump(_G)
|
return true, dump(_G)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ local function make_registration()
|
||||||
return t, registerfunc
|
return t, registerfunc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
core.registered_globalsteps, core.register_globalstep = make_registration()
|
||||||
core.registered_on_shutdown, core.register_on_shutdown = make_registration()
|
core.registered_on_shutdown, core.register_on_shutdown = make_registration()
|
||||||
core.registered_on_receiving_chat_messages, core.register_on_receiving_chat_messages = make_registration()
|
core.registered_on_receiving_chat_messages, core.register_on_receiving_chat_messages = make_registration()
|
||||||
core.registered_on_sending_chat_messages, core.register_on_sending_chat_messages = make_registration()
|
core.registered_on_sending_chat_messages, core.register_on_sending_chat_messages = make_registration()
|
||||||
|
|
|
@ -678,6 +678,8 @@ Helper functions
|
||||||
### Global callback registration functions
|
### Global callback registration functions
|
||||||
Call these functions only at load time!
|
Call these functions only at load time!
|
||||||
|
|
||||||
|
* `minetest.register_globalstep(func(dtime))`
|
||||||
|
* Called every client environment step, usually interval of 0.1s
|
||||||
* `minetest.register_on_shutdown(func())`
|
* `minetest.register_on_shutdown(func())`
|
||||||
* Called before client shutdown
|
* Called before client shutdown
|
||||||
* **Warning**: If the client terminates abnormally (i.e. crashes), the registered
|
* **Warning**: If the client terminates abnormally (i.e. crashes), the registered
|
||||||
|
|
|
@ -263,6 +263,7 @@ Client::Client(
|
||||||
g_settings->getBool("enable_parallax_occlusion"));
|
g_settings->getBool("enable_parallax_occlusion"));
|
||||||
|
|
||||||
m_script = new ClientScripting(this);
|
m_script = new ClientScripting(this);
|
||||||
|
m_env.setScript(m_script);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::initMods()
|
void Client::initMods()
|
||||||
|
|
16
src/client.h
16
src/client.h
|
@ -488,13 +488,19 @@ public:
|
||||||
// Get event from queue. CE_NONE is returned if queue is empty.
|
// Get event from queue. CE_NONE is returned if queue is empty.
|
||||||
ClientEvent getClientEvent();
|
ClientEvent getClientEvent();
|
||||||
|
|
||||||
bool accessDenied()
|
bool accessDenied() const { return m_access_denied; }
|
||||||
{ return m_access_denied; }
|
|
||||||
|
|
||||||
bool reconnectRequested() { return m_access_denied_reconnect; }
|
bool reconnectRequested() const { return m_access_denied_reconnect; }
|
||||||
|
|
||||||
std::string accessDeniedReason()
|
void setFatalError(const std::string &reason)
|
||||||
{ return m_access_denied_reason; }
|
{
|
||||||
|
m_access_denied = true;
|
||||||
|
m_access_denied_reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renaming accessDeniedReason to better name could be good as it's used to
|
||||||
|
// disconnect client when CSM failed.
|
||||||
|
const std::string &accessDeniedReason() const { return m_access_denied_reason; }
|
||||||
|
|
||||||
bool itemdefReceived()
|
bool itemdefReceived()
|
||||||
{ return m_itemdef_received; }
|
{ return m_itemdef_received; }
|
||||||
|
|
|
@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "clientenvironment.h"
|
#include "clientenvironment.h"
|
||||||
#include "clientsimpleobject.h"
|
#include "clientsimpleobject.h"
|
||||||
#include "clientmap.h"
|
#include "clientmap.h"
|
||||||
|
#include "clientscripting.h"
|
||||||
#include "mapblock_mesh.h"
|
#include "mapblock_mesh.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "collision.h"
|
#include "collision.h"
|
||||||
|
@ -42,6 +43,7 @@ ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
|
||||||
m_smgr(smgr),
|
m_smgr(smgr),
|
||||||
m_texturesource(texturesource),
|
m_texturesource(texturesource),
|
||||||
m_client(client),
|
m_client(client),
|
||||||
|
m_script(NULL),
|
||||||
m_irr(irr)
|
m_irr(irr)
|
||||||
{
|
{
|
||||||
char zero = 0;
|
char zero = 0;
|
||||||
|
@ -243,6 +245,8 @@ void ClientEnvironment::step(float dtime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_script->environment_step(dtime);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
A quick draft of lava damage
|
A quick draft of lava damage
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
|
||||||
class ClientSimpleObject;
|
class ClientSimpleObject;
|
||||||
class ClientMap;
|
class ClientMap;
|
||||||
|
class ClientScripting;
|
||||||
class ClientActiveObject;
|
class ClientActiveObject;
|
||||||
class GenericCAO;
|
class GenericCAO;
|
||||||
class LocalPlayer;
|
class LocalPlayer;
|
||||||
|
@ -75,6 +76,7 @@ public:
|
||||||
ClientMap & getClientMap();
|
ClientMap & getClientMap();
|
||||||
|
|
||||||
Client *getGameDef() { return m_client; }
|
Client *getGameDef() { return m_client; }
|
||||||
|
void setScript(ClientScripting *script) { m_script = script; }
|
||||||
|
|
||||||
void step(f32 dtime);
|
void step(f32 dtime);
|
||||||
|
|
||||||
|
@ -176,6 +178,7 @@ private:
|
||||||
scene::ISceneManager *m_smgr;
|
scene::ISceneManager *m_smgr;
|
||||||
ITextureSource *m_texturesource;
|
ITextureSource *m_texturesource;
|
||||||
Client *m_client;
|
Client *m_client;
|
||||||
|
ClientScripting *m_script;
|
||||||
IrrlichtDevice *m_irr;
|
IrrlichtDevice *m_irr;
|
||||||
UNORDERED_MAP<u16, ClientActiveObject*> m_active_objects;
|
UNORDERED_MAP<u16, ClientActiveObject*> m_active_objects;
|
||||||
std::vector<ClientSimpleObject*> m_simple_objects;
|
std::vector<ClientSimpleObject*> m_simple_objects;
|
||||||
|
|
|
@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
|
||||||
#include "s_client.h"
|
#include "s_client.h"
|
||||||
#include "s_internal.h"
|
#include "s_internal.h"
|
||||||
|
#include "client.h"
|
||||||
|
|
||||||
void ScriptApiClient::on_shutdown()
|
void ScriptApiClient::on_shutdown()
|
||||||
{
|
{
|
||||||
|
@ -94,3 +95,20 @@ void ScriptApiClient::on_death()
|
||||||
// Call callbacks
|
// Call callbacks
|
||||||
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
|
runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptApiClient::environment_step(float dtime)
|
||||||
|
{
|
||||||
|
SCRIPTAPI_PRECHECKHEADER
|
||||||
|
|
||||||
|
// Get core.registered_globalsteps
|
||||||
|
lua_getglobal(L, "core");
|
||||||
|
lua_getfield(L, -1, "registered_globalsteps");
|
||||||
|
// Call callbacks
|
||||||
|
lua_pushnumber(L, dtime);
|
||||||
|
try {
|
||||||
|
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
|
||||||
|
} catch (LuaError &e) {
|
||||||
|
getClient()->setFatalError(std::string("Client environment_step: ") + e.what() + "\n"
|
||||||
|
+ script_get_backtrace(L));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -36,5 +36,7 @@ public:
|
||||||
void on_damage_taken(int32_t damage_amount);
|
void on_damage_taken(int32_t damage_amount);
|
||||||
void on_hp_modification(int32_t newhp);
|
void on_hp_modification(int32_t newhp);
|
||||||
void on_death();
|
void on_death();
|
||||||
|
|
||||||
|
void environment_step(float dtime);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue