mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 14:02:59 +00:00 
			
		
		
		
	nilrider:: refactored mapchar and get_xy
This commit is contained in:
		| @@ -244,6 +244,23 @@ void level::init() { | |||||||
|   init_plan(); |   init_plan(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | xy_float level::get_xy_f(hyperpoint h) { | ||||||
|  |   int tY = isize(map_tiles); | ||||||
|  |   int tX = isize(map_tiles[0]); | ||||||
|  |   ld rtx = ilerp(minx, maxx, h[0]) * tX; | ||||||
|  |   ld rty = ilerp(miny, maxy, h[1]) * tY; | ||||||
|  |   return {rtx, rty}; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | char level::mapchar(xy_int p) { | ||||||
|  |   auto x = p.first; | ||||||
|  |   auto y = p.second; | ||||||
|  |   int tY = isize(map_tiles); | ||||||
|  |   int tX = isize(map_tiles[0]); | ||||||
|  |   if(x < 0 || y < 0 || x >= tX || y >= tY) return '!'; | ||||||
|  |   return map_tiles[y][x]; | ||||||
|  |   } | ||||||
|  |  | ||||||
| /* convert ASCII map coordinates to Heisenberg coordinates */ | /* convert ASCII map coordinates to Heisenberg coordinates */ | ||||||
| hyperpoint level::mappt(ld x, ld y, int s) { | hyperpoint level::mappt(ld x, ld y, int s) { | ||||||
|   int tY = isize(map_tiles); |   int tY = isize(map_tiles); | ||||||
|   | |||||||
| @@ -59,6 +59,10 @@ struct plan_replay { | |||||||
|   plan_t plan; |   plan_t plan; | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  | using xy_float = pair<ld, ld>; | ||||||
|  | using xy_int = pair<int, int>; | ||||||
|  | inline xy_float pfloor(xy_int p) { return {floor(p.first), floor(p.second)}; } | ||||||
|  |  | ||||||
| struct level { | struct level { | ||||||
|   string name; |   string name; | ||||||
|   char hotkey; |   char hotkey; | ||||||
| @@ -123,6 +127,12 @@ struct level { | |||||||
|   void compute_plan_transform(); |   void compute_plan_transform(); | ||||||
|   bool handle_planning(int sym, int uni); |   bool handle_planning(int sym, int uni); | ||||||
|   void solve(); |   void solve(); | ||||||
|  |  | ||||||
|  |   xy_float get_xy_f(hyperpoint h); | ||||||
|  |   xy_int get_xy_i(hyperpoint h) { return pfloor(get_xy_f(h)); } | ||||||
|  |   char mapchar(xy_int p); | ||||||
|  |   char mapchar(xy_float p) { return mapchar(pfloor(p)); } | ||||||
|  |   char mapchar(hyperpoint h) { return mapchar(pfloor(get_xy_f(h))); } | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
| /** ticks per second */ | /** ticks per second */ | ||||||
|   | |||||||
| @@ -47,8 +47,6 @@ void level::solve() { | |||||||
|    |    | ||||||
|   get_id(0, 0); |   get_id(0, 0); | ||||||
|   transmatrix Rstart = gpushxto0(vertices[0].where); |   transmatrix Rstart = gpushxto0(vertices[0].where); | ||||||
|   int tY = isize(map_tiles); |  | ||||||
|   int tX = isize(map_tiles[0]);   |  | ||||||
|    |    | ||||||
|   for(int id=0; id<isize(vertices); id++) { |   for(int id=0; id<isize(vertices); id++) { | ||||||
|     auto& v = vertices[id]; |     auto& v = vertices[id]; | ||||||
| @@ -58,13 +56,9 @@ void level::solve() { | |||||||
|     auto y0 = v.y; |     auto y0 = v.y; | ||||||
|     auto point0 = v.where; |     auto point0 = v.where; | ||||||
|  |  | ||||||
|     ld rtx0 = ilerp(minx, maxx, point0[0]) * tX; |     xy_float f0 = get_xy_f(point0); | ||||||
|     ld rty0 = ilerp(miny, maxy, point0[1]) * tY; |  | ||||||
|  |  | ||||||
|     int tx = floor(rtx0); |     char ch = mapchar(f0); | ||||||
|     int ty = floor(rty0); |  | ||||||
|  |  | ||||||
|     char ch = map_tiles[ty][tx]; |  | ||||||
|     v.goal = ch == '*'; |     v.goal = ch == '*'; | ||||||
|     v.zval = (Rstart * point0)[2]; |     v.zval = (Rstart * point0)[2]; | ||||||
|  |  | ||||||
| @@ -78,18 +72,16 @@ void level::solve() { | |||||||
|       hyperpoint point1 = getpt(x1, y1); |       hyperpoint point1 = getpt(x1, y1); | ||||||
|       e.zval1 = (Rstart * point1)[2]; |       e.zval1 = (Rstart * point1)[2]; | ||||||
|        |        | ||||||
|       ld rtx1 = ilerp(minx, maxx, point1[0]) * tX; |       xy_float f1 = get_xy_f(point1); | ||||||
|       ld rty1 = ilerp(miny, maxy, point1[1]) * tY; |  | ||||||
|        |        | ||||||
|       int txmin = floor(min(rtx0, rtx1) - 1e-3); |       int txmin = floor(min(f0.first, f1.first) - 1e-3); | ||||||
|       int txmax = floor(max(rtx0, rtx1) + 1e-3); |       int txmax = floor(max(f0.first, f1.first) + 1e-3); | ||||||
|       int tymin = floor(min(rty0, rty1) - 1e-3); |       int tymin = floor(min(f0.second, f1.second) - 1e-3); | ||||||
|       int tymax = floor(max(rty0, rty1) + 1e-3); |       int tymax = floor(max(f0.second, f1.second) + 1e-3); | ||||||
|       if(txmin < 0 || tymin < 0 || txmax >= tX || tymax >= tY) continue; |  | ||||||
|       bool bad = false; |       bool bad = false; | ||||||
|       for(int tyi=tymin; tyi<=tymax; tyi++) |       for(int tyi=tymin; tyi<=tymax; tyi++) | ||||||
|       for(int txi=txmin; txi<=txmax; txi++) |       for(int txi=txmin; txi<=txmax; txi++) | ||||||
|         if(among(map_tiles[tyi][txi], '!', 'r')) bad = true; |         if(among(mapchar(xy_int{txi, tyi}), '!', 'r')) bad = true; | ||||||
|       if(bad) continue; |       if(bad) continue; | ||||||
|  |  | ||||||
|       hyperpoint rpoint = gpushxto0(point1) * point0; |       hyperpoint rpoint = gpushxto0(point1) * point0; | ||||||
|   | |||||||
| @@ -71,19 +71,13 @@ void timestamp::draw_unilcycle(const shiftmatrix& V) { | |||||||
| bool tick_debug = false; | bool tick_debug = false; | ||||||
|  |  | ||||||
| bool timestamp::collect(level *lev) { | bool timestamp::collect(level *lev) { | ||||||
|   int tY = isize(lev->map_tiles); |   auto xy = lev->get_xy_i(where); | ||||||
|   int tX = isize(lev->map_tiles[0]); |   char ch = lev->mapchar(xy); | ||||||
|   // println(hlog, where, tie(lev->minx, lev->miny), tie(lev->maxx, lev->maxy)); |  | ||||||
|   int x = floor(ilerp(lev->minx, lev->maxx, where[0]) * tX); |  | ||||||
|   int y = floor(ilerp(lev->miny, lev->maxy, where[1]) * tY); |  | ||||||
|   if(x < 0 || y < 0 || x >= tX || y >= tY) |  | ||||||
|     return false; |  | ||||||
|   char ch = lev->map_tiles[y][x]; |  | ||||||
|   if(ch == 'r' || ch == '!') return false; |   if(ch == 'r' || ch == '!') return false; | ||||||
|   if(ch == '*') { |   if(ch == '*') { | ||||||
|     for(int i=0; i<isize(lev->triangles); i++) { |     for(int i=0; i<isize(lev->triangles); i++) { | ||||||
|       auto& t = lev->triangles[i]; |       auto& t = lev->triangles[i]; | ||||||
|       if(t.x == x && t.y == y) collected_triangles |= (1<<i); |       if(t.x == xy.first && t.y == xy.second) collected_triangles |= (1<<i); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   return true; |   return true; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue