mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-23 21:07:17 +00:00
Rationalize some std::exception stuff.
This commit is contained in:
parent
4c10b17b7e
commit
1761b02b90
@ -267,7 +267,7 @@ EX namespace bt {
|
|||||||
return path(h, d, bd_up_left, {bd_right, bd_down});
|
return path(h, d, bd_up_left, {bd_right, bd_down});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw hr_wrong_dir();
|
throw hr_exception("wrong dir");
|
||||||
}
|
}
|
||||||
case gBinary4: {
|
case gBinary4: {
|
||||||
switch(d) {
|
switch(d) {
|
||||||
@ -286,7 +286,7 @@ EX namespace bt {
|
|||||||
else
|
else
|
||||||
return path(h, 4, 2, {3, 4, 1});
|
return path(h, 4, 2, {3, 4, 1});
|
||||||
default:
|
default:
|
||||||
throw hr_wrong_dir();
|
throw hr_exception("wrong dir");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case gTernary: {
|
case gTernary: {
|
||||||
@ -306,7 +306,7 @@ EX namespace bt {
|
|||||||
else
|
else
|
||||||
return path(h, 5, 3, {4, 5, 2});
|
return path(h, 5, 3, {4, 5, 2});
|
||||||
default:
|
default:
|
||||||
throw hr_wrong_dir();
|
throw hr_exception("wrong dir");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if MAXMDIM >= 4
|
#if MAXMDIM >= 4
|
||||||
@ -342,7 +342,7 @@ EX namespace bt {
|
|||||||
else
|
else
|
||||||
return path(h, 7, 6, {8, 7, parent->c.spin(8) ^ 2});
|
return path(h, 7, 6, {8, 7, parent->c.spin(8) ^ 2});
|
||||||
default:
|
default:
|
||||||
throw hr_wrong_dir();
|
throw hr_exception("wrong dir");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case gHoroRec: {
|
case gHoroRec: {
|
||||||
@ -370,7 +370,7 @@ EX namespace bt {
|
|||||||
parent->cmove(6);
|
parent->cmove(6);
|
||||||
return path(h, 5, 3, {6, 2, parent->c.spin(6)});
|
return path(h, 5, 3, {6, 2, parent->c.spin(6)});
|
||||||
default:
|
default:
|
||||||
throw hr_wrong_dir();
|
throw hr_exception("wrong dir");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case gHoroTris: {
|
case gHoroTris: {
|
||||||
@ -387,7 +387,7 @@ EX namespace bt {
|
|||||||
else return path(h, d, d, {7, d, 9-d-s});
|
else return path(h, d, d, {7, d, 9-d-s});
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw hr_wrong_dir();
|
throw hr_exception("wrong dir");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case gHoroHex: {
|
case gHoroHex: {
|
||||||
@ -422,12 +422,12 @@ EX namespace bt {
|
|||||||
return path(h, 12, (z+1)%3+3, {13, z+6});
|
return path(h, 12, (z+1)%3+3, {13, z+6});
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw hr_wrong_dir();
|
throw hr_exception("wrong dir");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
throw hr_wrong_geometry();
|
throw hr_exception("wrong geometry");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,7 +436,7 @@ EX namespace bt {
|
|||||||
else if(type_of(h) == 6) return bd_down;
|
else if(type_of(h) == 6) return bd_down;
|
||||||
else if(mapside(h) == 1) return bd_left;
|
else if(mapside(h) == 1) return bd_left;
|
||||||
else if(mapside(h) == -1) return bd_right;
|
else if(mapside(h) == -1) return bd_right;
|
||||||
else throw hr_wrong_dir();
|
else throw hr_exception("wrong dir");
|
||||||
}
|
}
|
||||||
|
|
||||||
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {
|
||||||
|
@ -786,7 +786,7 @@ EX namespace dialog {
|
|||||||
#endif
|
#endif
|
||||||
if(reaction) reaction();
|
if(reaction) reaction();
|
||||||
}
|
}
|
||||||
catch(hr_parse_exception&) {
|
catch(const hr_parse_exception&) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ EX namespace history {
|
|||||||
auto p = build_shortest_path(start, target);
|
auto p = build_shortest_path(start, target);
|
||||||
path_for_lineanimation = p;
|
path_for_lineanimation = p;
|
||||||
}
|
}
|
||||||
catch(hr_shortest_path_exception&) {
|
catch(const hr_shortest_path_exception&) {
|
||||||
addMessage("Could not build a path");
|
addMessage("Could not build a path");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
12
hyper.h
12
hyper.h
@ -98,14 +98,12 @@ using std::asinh;
|
|||||||
using std::acosh;
|
using std::acosh;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct hr_exception: std::exception { hr_exception() {} };
|
struct hr_exception : std::runtime_error {
|
||||||
struct hr_shortest_path_exception: hr_exception { };
|
explicit hr_exception() : std::runtime_error("hr_exception") {}
|
||||||
|
explicit hr_exception(const std::string& s) : std::runtime_error(s.c_str()) {}
|
||||||
|
};
|
||||||
|
|
||||||
struct hr_wrong_dir: hr_exception { };
|
struct hr_shortest_path_exception { };
|
||||||
|
|
||||||
struct hr_wrong_geometry: hr_exception { };
|
|
||||||
|
|
||||||
struct hr_exception_str: std::exception { string s; hr_exception_str(const string& s) : s(s) {} const char* what() { return s.c_str(); }};
|
|
||||||
|
|
||||||
// genus (in grammar)
|
// genus (in grammar)
|
||||||
#define GEN_M 0
|
#define GEN_M 0
|
||||||
|
@ -427,11 +427,11 @@ EX namespace sn {
|
|||||||
case 8:
|
case 8:
|
||||||
return xpush(bw*(4.5-j)) * zpush(-1) * ypush(bw*(i-7));
|
return xpush(bw*(4.5-j)) * zpush(-1) * ypush(bw*(i-7));
|
||||||
default:
|
default:
|
||||||
throw hr_wrong_dir();
|
throw hr_exception("wrong dir");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default: throw hr_wrong_geometry();
|
default: throw hr_exception("wrong geometry");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -503,12 +503,12 @@ EX void generate_track() {
|
|||||||
}
|
}
|
||||||
else find_track(s, 0, length);
|
else find_track(s, 0, length);
|
||||||
}
|
}
|
||||||
catch(hr_track_failure&) {
|
catch(const hr_track_failure&) {
|
||||||
race_try++;
|
race_try++;
|
||||||
gamegen_failure = true;
|
gamegen_failure = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch(hr_shortest_path_exception&) {
|
catch(const hr_shortest_path_exception&) {
|
||||||
addMessage("error: could not build path");
|
addMessage("error: could not build path");
|
||||||
gamegen_failure = true;
|
gamegen_failure = true;
|
||||||
racing::on = false;
|
racing::on = false;
|
||||||
|
@ -402,7 +402,7 @@ struct hrmap_notknot : hrmap {
|
|||||||
auto d1 = u->where->c.spin(d);
|
auto d1 = u->where->c.spin(d);
|
||||||
auto z = x->zebraval;
|
auto z = x->zebraval;
|
||||||
if(z & 6) {
|
if(z & 6) {
|
||||||
throw hr_exception_str("zebraval failure!");
|
throw hr_exception("zebraval failure!");
|
||||||
exit(3);
|
exit(3);
|
||||||
x->zebraval = 0;
|
x->zebraval = 0;
|
||||||
}
|
}
|
||||||
@ -418,7 +418,7 @@ struct hrmap_notknot : hrmap {
|
|||||||
|
|
||||||
void add_to_unify(ucover *a, ucover *b) {
|
void add_to_unify(ucover *a, ucover *b) {
|
||||||
if(a->where != b->where)
|
if(a->where != b->where)
|
||||||
throw hr_exception_str("unification error");
|
throw hr_exception("unification error");
|
||||||
unify.emplace_back(a, b);
|
unify.emplace_back(a, b);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -641,7 +641,7 @@ struct hrmap_notknot : hrmap {
|
|||||||
if(u->where == all[0]->where)
|
if(u->where == all[0]->where)
|
||||||
for(auto& lo: to_unloop)
|
for(auto& lo: to_unloop)
|
||||||
if(!make_loop(u, 1, lo))
|
if(!make_loop(u, 1, lo))
|
||||||
throw hr_exception_str("given loop goes through a wall");
|
throw hr_exception("given loop goes through a wall");
|
||||||
|
|
||||||
if(loop_any && u->where == all[0]->where) {
|
if(loop_any && u->where == all[0]->where) {
|
||||||
auto us = all[0];
|
auto us = all[0];
|
||||||
@ -685,7 +685,7 @@ struct hrmap_notknot : hrmap {
|
|||||||
all[0]->parentdir = -1;
|
all[0]->parentdir = -1;
|
||||||
|
|
||||||
if(all[0]->where->zebraval & 1)
|
if(all[0]->where->zebraval & 1)
|
||||||
throw hr_exception_str("error: starting inside a wall");
|
throw hr_exception("error: starting inside a wall");
|
||||||
|
|
||||||
remove_marked_walls = false;
|
remove_marked_walls = false;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
@ -712,7 +712,7 @@ struct hrmap_notknot : hrmap {
|
|||||||
|
|
||||||
uf->state |= 2; uf->merged_into = ut;
|
uf->state |= 2; uf->merged_into = ut;
|
||||||
if(uf->where != ut->where)
|
if(uf->where != ut->where)
|
||||||
throw hr_exception_str("where confusion");
|
throw hr_exception("where confusion");
|
||||||
for(int d=0; d<uf->where->type; d++) {
|
for(int d=0; d<uf->where->type; d++) {
|
||||||
cmov(uf->where, d);
|
cmov(uf->where, d);
|
||||||
auto d1 = uf->where->c.spin(d);
|
auto d1 = uf->where->c.spin(d);
|
||||||
@ -881,9 +881,9 @@ struct hrmap_notknot : hrmap {
|
|||||||
cmov(u->where, d);
|
cmov(u->where, d);
|
||||||
auto d1 = u->where->c.spin(d);
|
auto d1 = u->where->c.spin(d);
|
||||||
if(u->ptr[d] && u->ptr[d]->result == nullptr)
|
if(u->ptr[d] && u->ptr[d]->result == nullptr)
|
||||||
throw hr_exception_str(lalign(0, "connection to null in state ", u->ptr[d]->state, " from state ", u->state, " i=", i, " .. ", u->ptr[d]->index));
|
throw hr_exception(lalign(0, "connection to null in state ", u->ptr[d]->state, " from state ", u->state, " i=", i, " .. ", u->ptr[d]->index));
|
||||||
if(u->ptr[d] && u->ptr[d]->ptr[d1] != u)
|
if(u->ptr[d] && u->ptr[d]->ptr[d1] != u)
|
||||||
throw hr_exception_str("wrong connection");
|
throw hr_exception("wrong connection");
|
||||||
if(u->ptr[d])
|
if(u->ptr[d])
|
||||||
u->result->c.connect(d, u->ptr[d]->result, d1, false);
|
u->result->c.connect(d, u->ptr[d]->result, d1, false);
|
||||||
else
|
else
|
||||||
@ -973,8 +973,8 @@ struct hrmap_notknot : hrmap {
|
|||||||
ray::volumetric::vmap[c] = 0x00000001;
|
ray::volumetric::vmap[c] = 0x00000001;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch(hr_exception_str& s) {
|
} catch(const hr_exception& s) {
|
||||||
println(hlog, "exception: ", s.s);
|
println(hlog, "exception: ", s.what());
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
rug.cpp
6
rug.cpp
@ -600,7 +600,7 @@ EX void buildRug() {
|
|||||||
else if(v > w && v > w2)
|
else if(v > w && v > w2)
|
||||||
addTriangle(v, w, w2);
|
addTriangle(v, w, w2);
|
||||||
}
|
}
|
||||||
catch(out_of_range&) {}
|
catch(const std::out_of_range&) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
println(hlog, "vertices = ", isize(points), " triangles= ", isize(triangles));
|
println(hlog, "vertices = ", isize(points), " triangles= ", isize(triangles));
|
||||||
@ -1218,7 +1218,7 @@ EX void init_model() {
|
|||||||
"Use a different projection to fix this."
|
"Use a different projection to fix this."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch(rug_exception) {
|
catch(const rug_exception&) {
|
||||||
close();
|
close();
|
||||||
clear_model();
|
clear_model();
|
||||||
}
|
}
|
||||||
@ -1353,7 +1353,7 @@ EX void actDraw() {
|
|||||||
perform_finger();
|
perform_finger();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
catch(rug_exception) {
|
catch(const rug_exception&) {
|
||||||
rug::close();
|
rug::close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user