From b056b5c1531261b12dfd2d3abaaa654033e10879 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 12 Sep 2022 11:49:28 +0200 Subject: [PATCH] shapes used, unique_ptrs, resources generated --- rogueviz/ads/control.cpp | 15 +++++++------ rogueviz/ads/display.cpp | 7 +++--- rogueviz/ads/map.cpp | 46 ++++++++++++++++++++++++++++++---------- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/rogueviz/ads/control.cpp b/rogueviz/ads/control.cpp index f9b9e776..9537820c 100644 --- a/rogueviz/ads/control.cpp +++ b/rogueviz/ads/control.cpp @@ -14,8 +14,8 @@ void fire() { ads_matrix S1 = S0 * lorentz(0, 2, 3); // 0.995c auto& ro = ci_at[c].rocks; - ro.emplace_back(ads_object{oMissile, c, S1, 0xC0C0FFFF }); - auto& r = ro.back(); + auto r = std::make_unique (oMissile, c, S1, 0xC0C0FFFF); + r->shape = &shape_missile; ads_matrix Scell(Id, 0); cell *lcell = vctr; @@ -23,7 +23,7 @@ void fire() { int steps = 0; - compute_life(vctr, unshift(r.at), [&] (cell *c1, ld t) { + compute_life(vctr, unshift(r->at), [&] (cell *c1, ld t) { if(true) for(int i=0; itype; i++) { auto lcell1 = lcell->cmove(i); auto wcell1 = hybrid::get_where(lcell1); @@ -51,18 +51,18 @@ void fire() { gen_rocks(c1, ci, 2); }); if(among(ci.type, wtSolid, wtDestructible)) { - r.life_end = t; + r->life_end = t; auto Scell_inv = ads_inverse(Scell); - Scell_inv = Scell_inv * r.at; + Scell_inv = Scell_inv * r->at; Scell_inv = Scell_inv * ads_matrix(Id, t); optimize_shift(Scell_inv); auto X = ads_inverse(Scell); - X = X * (r.at * ads_matrix(Id, t)); + X = X * (r->at * ads_matrix(Id, t)); optimize_shift(X); - ads_matrix prel = ads_inverse(S0) * r.at * ads_matrix(Id, t); + ads_matrix prel = ads_inverse(S0) * r->at * ads_matrix(Id, t); println(hlog, "crashed: proper time = ", t/TAU, " wall time = ", Scell_inv.shift / TAU, " player time = ", (prel.shift+ship_pt) / TAU, " start = ", ship_pt / TAU); if(abs(X.shift - Scell_inv.shift) > .2) { @@ -74,6 +74,7 @@ void fire() { } return false; }); + ro.emplace_back(std::move(r)); } bool handleKey(int sym, int uni) { diff --git a/rogueviz/ads/display.cpp b/rogueviz/ads/display.cpp index 9f1166af..fe7f4d9c 100644 --- a/rogueviz/ads/display.cpp +++ b/rogueviz/ads/display.cpp @@ -90,7 +90,8 @@ void draw_game_cell(cell *cs, ads_matrix V, ld plev) { queuestr(shiftless(rgpushxto0(center.h)), .1, str, 0xFF4040, 8); } - for(auto& rock: ci.rocks) { + for(auto& r: ci.rocks) { + auto& rock = *r; hybrid::in_actual([&]{ dynamicval b(geometry, gRotSpace); @@ -101,8 +102,8 @@ void draw_game_cell(cell *cs, ads_matrix V, ld plev) { if(rock.pt_main.shift < rock.life_start || rock.pt_main.shift > rock.life_end) continue; displayed.push_back(&rock); - rock.pts.clear(); - vector& shape = rock.type ? shape_missile : shape_rock; + rock.pts.clear(); + auto& shape = *rock.shape; for(int i=0; i* rsrc_shape[6] = { nullptr, &shape_heart, &shape_gold, &shape_weapon, &shape_fuel, &shape_airtank }; struct ads_object { eObjType type; + eResourceType resource; cell *owner; ads_matrix at; color_t col; + vector* shape; ld life_start, life_end; cross_result pt_main; @@ -25,7 +34,7 @@ enum eWalltype { wtNone, wtDestructible, wtSolid, wtGate }; struct cellinfo { int mpd_terrain; /* 0 = fully generated terrain */ int rock_dist; /* rocks generated in this radius */ - vector rocks; + vector> rocks; eWalltype type; cellinfo() { mpd_terrain = 4; @@ -119,23 +128,27 @@ void gen_rocks(cell *c, cellinfo& ci, int radius) { hybrid::in_actual([&] { int q = rpoisson(.25); - auto add_rock = [&] (ads_object&& r) { + auto add_rock = [&] (ads_matrix T) { + eResourceType rt = eResourceType(rand() % 6); + auto r = std::make_unique (oRock, c, T, rock_color[rt]); + r->resource = rt; + r->shape = &(rand() % 2 ? shape_rock2 : shape_rock); if(geometry != gRotSpace) { println(hlog, "wrong geometry detected in gen_rocks 2!"); exit(1); } - compute_life(hybrid::get_at(c, 0), unshift(r.at), [&] (cell *c, ld t) { + compute_life(hybrid::get_at(c, 0), unshift(r->at), [&] (cell *c, ld t) { auto& ci = ci_at[c]; hybrid::in_underlying_geometry([&] { gen_terrain(c, ci); }); ci.type = wtNone; return false; }); - ci.rocks.emplace_back(r); + ci.rocks.emplace_back(std::move(r)); }; for(int i=0; i(oParticle, c, from * spin(randd() * TAU) * lorentz(0, 2, 1 + randd()), col ); + r->shape = &shape_particle; + r->life_end = randd() * t; + r->life_start = 0; + ro.emplace_back(std::move(r)); } } +void gen_resource(cell *c, shiftmatrix from, eResourceType rsrc) { + if(!rsrc) return; + auto r = std::make_unique(oResource, c, from, rsrc_color[rsrc]); + r->shape = rsrc_shape[rsrc]; + r->life_end = HUGE_VAL; + r->life_start = 0; + ci_at[c].rocks.emplace_back(std::move(r)); + } + void handle_crashes() { vector missiles; vector rocks; @@ -182,6 +205,7 @@ void handle_crashes() { hybrid::in_actual([&] { gen_particles(8, m->owner, m->at * ads_matrix(Id, m->life_end), missile_color, 0.1); gen_particles(8, r->owner, r->at * ads_matrix(Id, r->life_end), r->col, 0.5); + gen_resource(r->owner, r->at * ads_matrix(Id, r->life_end), r->resource); }); } }