core/types, doc/conventions, builtin: NullptrCatch
This commit is contained in:
parent
1c91de2ab1
commit
873213aae9
@ -272,61 +272,66 @@ struct CInstance: public ground_plane_lighting::Instance
|
|||||||
|
|
||||||
void on_node_volume_updated(const voxelworld::NodeVolumeUpdated &event)
|
void on_node_volume_updated(const voxelworld::NodeVolumeUpdated &event)
|
||||||
{
|
{
|
||||||
if(!event.is_static_chunk)
|
try {
|
||||||
return;
|
if(!event.is_static_chunk)
|
||||||
if(event.scene != m_scene_ref)
|
return;
|
||||||
return;
|
if(event.scene != m_scene_ref)
|
||||||
log_v(MODULE, "Checking ground level in chunk " PV3I_FORMAT,
|
return;
|
||||||
PV3I_PARAMS(event.chunk_p));
|
log_v(MODULE, "Checking ground level in chunk " PV3I_FORMAT,
|
||||||
const pv::Vector3DInt32 &chunk_p = event.chunk_p;
|
PV3I_PARAMS(event.chunk_p));
|
||||||
voxelworld::access(m_server, [&](voxelworld::Interface *ivoxelworld)
|
const pv::Vector3DInt32 &chunk_p = event.chunk_p;
|
||||||
{
|
voxelworld::access(m_server, [&](voxelworld::Interface *ivoxelworld)
|
||||||
voxelworld::Instance *world =
|
{
|
||||||
check(ivoxelworld->get_instance(m_scene_ref));
|
voxelworld::Instance *world =
|
||||||
interface::VoxelRegistry *voxel_reg = world->get_voxel_reg();
|
check(ivoxelworld->get_instance(m_scene_ref));
|
||||||
//const auto &chunk_size_voxels = world->get_chunk_size_voxels();
|
interface::VoxelRegistry *voxel_reg = world->get_voxel_reg();
|
||||||
pv::Region chunk_region =
|
//const auto &chunk_size_voxels = world->get_chunk_size_voxels();
|
||||||
world->get_chunk_region_voxels(chunk_p);
|
pv::Region chunk_region =
|
||||||
|
world->get_chunk_region_voxels(chunk_p);
|
||||||
|
|
||||||
auto lc = chunk_region.getLowerCorner();
|
auto lc = chunk_region.getLowerCorner();
|
||||||
auto uc = chunk_region.getUpperCorner();
|
auto uc = chunk_region.getUpperCorner();
|
||||||
//log_nv(MODULE, "yst=[");
|
//log_nv(MODULE, "yst=[");
|
||||||
for(int z = lc.getZ(); z <= uc.getZ(); z++){
|
for(int z = lc.getZ(); z <= uc.getZ(); z++){
|
||||||
for(int x = lc.getX(); x <= uc.getX(); x++){
|
for(int x = lc.getX(); x <= uc.getX(); x++){
|
||||||
int32_t yst0 = get_yst(x, z);
|
int32_t yst0 = get_yst(x, z);
|
||||||
if(yst0 > uc.getY()){
|
if(yst0 > uc.getY()){
|
||||||
// Y-seethrough doesn't reach here
|
// Y-seethrough doesn't reach here
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
int y = uc.getY();
|
|
||||||
for(;; y--){
|
|
||||||
VoxelInstance v = world->get_voxel(
|
|
||||||
pv::Vector3DInt32(x, y, z), true);
|
|
||||||
if(v.get_id() == interface::VOXELTYPEID_UNDEFINED){
|
|
||||||
// NOTE: This leaves the chunks below unhandled;
|
|
||||||
// there would have to be some kind of a dirty
|
|
||||||
// flag based on which this seach would be
|
|
||||||
// continued at a later point when the chunk
|
|
||||||
// gets loaded
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
const auto *def = voxel_reg->get_cached(v);
|
int y = uc.getY();
|
||||||
if(!def)
|
for(;; y--){
|
||||||
throw Exception(ss_()+"Undefined voxel: "+
|
VoxelInstance v = world->get_voxel(
|
||||||
itos(v.get_id()));
|
pv::Vector3DInt32(x, y, z), true);
|
||||||
bool light_passes = (!def || !def->physically_solid);
|
if(v.get_id() == interface::VOXELTYPEID_UNDEFINED){
|
||||||
if(!light_passes)
|
// NOTE: This leaves the chunks below unhandled;
|
||||||
break;
|
// there would have to be some kind of a dirty
|
||||||
|
// flag based on which this seach would be
|
||||||
|
// continued at a later point when the chunk
|
||||||
|
// gets loaded
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const auto *def = voxel_reg->get_cached(v);
|
||||||
|
if(!def)
|
||||||
|
throw Exception(ss_()+"Undefined voxel: "+
|
||||||
|
itos(v.get_id()));
|
||||||
|
bool light_passes = (!def || !def->physically_solid);
|
||||||
|
if(!light_passes)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// The first voxel downwards from the top of the world that
|
||||||
|
// doesn't pass light
|
||||||
|
int32_t yst1 = y;
|
||||||
|
//log_nv(MODULE, "%i -> %i, ", yst0, yst1);
|
||||||
|
set_yst(x, z, yst1);
|
||||||
}
|
}
|
||||||
// The first voxel downwards from the top of the world that
|
|
||||||
// doesn't pass light
|
|
||||||
int32_t yst1 = y;
|
|
||||||
//log_nv(MODULE, "%i -> %i, ", yst0, yst1);
|
|
||||||
set_yst(x, z, yst1);
|
|
||||||
}
|
}
|
||||||
}
|
//log_v(MODULE, "]");
|
||||||
//log_v(MODULE, "]");
|
});
|
||||||
});
|
} catch(NullptrCatch &e){
|
||||||
|
// Something was probably deleted or unloaded
|
||||||
|
log_v(MODULE, "NullptrCatch: %s", e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_initial_sectors(int peer)
|
void send_initial_sectors(int peer)
|
||||||
|
@ -217,7 +217,7 @@ struct Module: public interface::Module, public main_context::Interface
|
|||||||
{
|
{
|
||||||
Scene *scene = find_scene(ref);
|
Scene *scene = find_scene(ref);
|
||||||
if(!scene)
|
if(!scene)
|
||||||
throw Exception("check_scene(): Scene not found");
|
throw NullptrCatch("check_scene(): Scene not found");
|
||||||
return scene;
|
return scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,22 +94,27 @@ struct CInstance: public worldgen::Instance
|
|||||||
// queued but instead sectors get queued in the event queue.
|
// queued but instead sectors get queued in the event queue.
|
||||||
void generate_next_section()
|
void generate_next_section()
|
||||||
{
|
{
|
||||||
if(!m_enabled)
|
try {
|
||||||
throw Exception("generate_next_section(): Not enabled");
|
if(!m_enabled)
|
||||||
if(m_queued_sections.empty())
|
throw Exception("generate_next_section(): Not enabled");
|
||||||
return;
|
if(m_queued_sections.empty())
|
||||||
const pv::Vector3DInt16 section_p = m_queued_sections.front();
|
return;
|
||||||
m_queued_sections.pop_front();
|
const pv::Vector3DInt16 section_p = m_queued_sections.front();
|
||||||
|
m_queued_sections.pop_front();
|
||||||
|
|
||||||
log_v(MODULE, "Generating section (%i, %i, %i); queue size: %zu",
|
log_v(MODULE, "Generating section (%i, %i, %i); queue size: %zu",
|
||||||
section_p.getX(), section_p.getY(), section_p.getZ(),
|
section_p.getX(), section_p.getY(), section_p.getZ(),
|
||||||
m_queued_sections.size());
|
m_queued_sections.size());
|
||||||
|
|
||||||
if(m_generator)
|
if(m_generator)
|
||||||
m_generator->generate_section(m_server, m_scene_ref, section_p);
|
m_generator->generate_section(m_server, m_scene_ref, section_p);
|
||||||
|
|
||||||
m_server->emit_event("worldgen:queue_modified",
|
m_server->emit_event("worldgen:queue_modified",
|
||||||
new QueueModifiedEvent(m_scene_ref, m_queued_sections.size()));
|
new QueueModifiedEvent(m_scene_ref, m_queued_sections.size()));
|
||||||
|
} catch(NullptrCatch &e){
|
||||||
|
// Something was probably deleted or unloaded
|
||||||
|
log_v(MODULE, "NullptrCatch: %s", e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interface
|
// Interface
|
||||||
|
@ -73,7 +73,7 @@ Non-exception throwing and exception-throwing methods
|
|||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
- get_x: Returns nullptr or equivalent if not found
|
- get_x: Returns nullptr or equivalent if not found
|
||||||
- find_x: Returns nullptr or equivalent if not found
|
- find_x: Returns nullptr or equivalent if not found
|
||||||
- check_x: Throws exception if not found
|
- check_x: Throws NullptrCatch if not found
|
||||||
|
|
||||||
To check for nullptr returned by get_x() or find_x(), use the check() function
|
To check for nullptr returned by get_x() or find_x(), use the check() function
|
||||||
in core/types.h.
|
in core/types.h.
|
||||||
|
@ -66,7 +66,9 @@ struct Exception: public std::exception {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
#define DEFINE_EXCEPTION(name, base) struct name: public base \
|
#define DEFINE_EXCEPTION(name, base) struct name: public base \
|
||||||
{name(const ss_ &msg = ""): base(ss_()+#name+msg){}}
|
{name(const ss_ &msg): base(msg){}}
|
||||||
|
|
||||||
|
DEFINE_EXCEPTION(NullptrCatch, Exception);
|
||||||
|
|
||||||
static inline ss_ itos(int64_t i){
|
static inline ss_ itos(int64_t i){
|
||||||
char buf[22];
|
char buf[22];
|
||||||
@ -152,13 +154,13 @@ static inline cc_* cs(const T &v){
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
static inline T* check(T *v){
|
static inline T* check(T *v){
|
||||||
if(v == nullptr)
|
if(v == nullptr)
|
||||||
throw Exception("check(): nullptr");
|
throw NullptrCatch("check(): nullptr");
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline const T* check(const T *v){
|
static inline const T* check(const T *v){
|
||||||
if(v == nullptr)
|
if(v == nullptr)
|
||||||
throw Exception("check(): nullptr");
|
throw NullptrCatch("check(): nullptr");
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ void ModuleThread::handle_direct_cb(
|
|||||||
log_t(MODULE, "M[%s] ~direct_cb(): Executed",
|
log_t(MODULE, "M[%s] ~direct_cb(): Executed",
|
||||||
cs(mc->info.name));
|
cs(mc->info.name));
|
||||||
} catch(...){
|
} catch(...){
|
||||||
log_v(MODULE, "M[%s] ~direct_cb() failed (exception)",
|
log_t(MODULE, "M[%s] ~direct_cb() failed (exception)",
|
||||||
cs(mc->info.name));
|
cs(mc->info.name));
|
||||||
// direct_cb() exception should not directly shutdown the
|
// direct_cb() exception should not directly shutdown the
|
||||||
// server; instead they are passed to the caller. Eventually
|
// server; instead they are passed to the caller. Eventually
|
||||||
|
Loading…
x
Reference in New Issue
Block a user