FoW is now moved into lighting so light determines what's seen not player's last position. Not sure if I like that though.
This commit is contained in:
		
							parent
							
								
									d264760405
								
							
						
					
					
						commit
						2997dc363b
					
				
					 7 changed files with 19 additions and 30 deletions
				
			
		|  | @ -24,8 +24,7 @@ namespace gui { | |||
|     $level(level), | ||||
|     $map_render(std::make_shared<sf::RenderTexture>()), | ||||
|     $map_sprite($map_render->getTexture()), | ||||
|     $map_tiles(matrix::make(MAP_WIDTH, MAP_HEIGHT)), | ||||
|     $fow(matrix::make($level.map->width(), $level.map->height())) | ||||
|     $map_tiles(matrix::make(MAP_WIDTH, MAP_HEIGHT)) | ||||
|   { | ||||
|     auto player = $level.world->get_the<Player>(); | ||||
|     $player_display = $level.world->get<Tile>(player.entity).display; | ||||
|  | @ -33,7 +32,6 @@ namespace gui { | |||
| 
 | ||||
|   void MapViewUI::update_level(GameLevel &level) { | ||||
|     $level = level; | ||||
|     $fow = matrix::make($level.map->width(), $level.map->height()); | ||||
|   } | ||||
| 
 | ||||
|   void MapViewUI::init() { | ||||
|  | @ -62,19 +60,8 @@ namespace gui { | |||
| 
 | ||||
|   void MapViewUI::render(sf::RenderWindow &window, int compass_dir) { | ||||
|     $gui.render(window); | ||||
| 
 | ||||
|     auto player = $level.world->get_the<components::Player>(); | ||||
|     auto player_pos = $level.world->get<components::Position>(player.entity).location; | ||||
| 
 | ||||
|     // NOTE: FoW is probably better done in the lighting system, because it illuminates where you've been.  The light calcs could then simply set the light the player touches to 1 when it's run.
 | ||||
|     for(matrix::circle it{$fow, player_pos, 2.5}; it.next();) { | ||||
|       for(int x = it.left; x < it.right; x++) { | ||||
|         $fow[it.y][x] = 1; | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     System::draw_map($level, $map_tiles, $fow, $entity_map); | ||||
|     System::render_map($map_tiles, $entity_map, *$map_render, compass_dir, $player_display); | ||||
|     System::draw_map($level, $map_tiles, $entity_map); | ||||
|     System::render_map($level, $map_tiles, $entity_map, *$map_render, compass_dir, $player_display); | ||||
|     $map_sprite.setTexture($map_render->getTexture(), true); | ||||
|     window.draw($map_sprite); | ||||
|     // $gui.debug_layout(window);
 | ||||
|  |  | |||
|  | @ -17,7 +17,6 @@ namespace gui { | |||
|       std::shared_ptr<sf::RenderTexture> $map_render; | ||||
|       sf::Sprite $map_sprite; | ||||
|       matrix::Matrix $map_tiles; | ||||
|       matrix::Matrix $fow; | ||||
| 
 | ||||
|       MapViewUI(GameLevel &level); | ||||
|       void init(); | ||||
|  |  | |||
|  | @ -12,7 +12,8 @@ namespace lighting { | |||
|     $height(matrix::height(tiles)), | ||||
|     $lightmap(matrix::make($width, $height)), | ||||
|     $ambient(matrix::make($width, $height)), | ||||
|     $paths($width, $height) | ||||
|     $paths($width, $height), | ||||
|     $fow(matrix::make($width, $height)) | ||||
|   { | ||||
|     auto& tile_ambient = textures::get_ambient_light(); | ||||
| 
 | ||||
|  | @ -47,8 +48,9 @@ namespace lighting { | |||
|     for(auto point : has_light) { | ||||
|       for(matrix::compass it{$lightmap, point.x, point.y}; it.next();) { | ||||
|         if($paths.$paths[it.y][it.x] == WALL_PATH_LIMIT) { | ||||
|             $lightmap[it.y][it.x] = light_level(source.strength, 1.5f, point.x, point.y); | ||||
|           $lightmap[it.y][it.x] = light_level(source.strength, 1.5f, point.x, point.y); | ||||
|         } | ||||
|         $fow[it.y][it.x] = $lightmap[it.y][it.x]; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  |  | |||
|  | @ -21,6 +21,7 @@ namespace lighting { | |||
|     Matrix $lightmap; | ||||
|     Matrix $ambient; | ||||
|     Pathing $paths; | ||||
|     matrix::Matrix $fow; | ||||
| 
 | ||||
|     LightRender(Matrix& walls); | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										10
									
								
								systems.cpp
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								systems.cpp
									
										
									
									
									
								
							|  | @ -526,9 +526,10 @@ bool System::inventory_occupied(GameLevel& level, Entity container_id, const std | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| void System::draw_map(GameLevel& level, Matrix& grid, Matrix& fow, EntityGrid& entity_map) { | ||||
| void System::draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map) { | ||||
|   World &world = *level.world; | ||||
|   Map &map = *level.map; | ||||
|   Matrix &fow = level.lights->$fow; | ||||
|   size_t view_x = matrix::width(grid) - 1; | ||||
|   size_t view_y = matrix::height(grid) - 1; | ||||
| 
 | ||||
|  | @ -571,13 +572,15 @@ void System::draw_map(GameLevel& level, Matrix& grid, Matrix& fow, EntityGrid& e | |||
|   }); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display) { | ||||
| void System::render_map(GameLevel& level, Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display) { | ||||
|   sf::Vector2i tile_sprite_dim{MAP_TILE_DIM,MAP_TILE_DIM}; | ||||
|   unsigned int width = matrix::width(tiles); | ||||
|   unsigned int height = matrix::height(tiles); | ||||
|   sf::Vector2u dim{width * tile_sprite_dim.x, height * tile_sprite_dim.y}; | ||||
|   auto render_size = render.getSize(); | ||||
|   Matrix &fow = level.lights->$fow; | ||||
|   (void)level; | ||||
|   (void)fow; | ||||
| 
 | ||||
|   if(render_size.x != width || render_size.y != height) { | ||||
|     bool worked = render.resize(dim); | ||||
|  | @ -608,6 +611,7 @@ void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture | |||
|       sprite.setPosition({float(point.x * tile_sprite_dim.x), float(point.y * tile_sprite_dim.y)}); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     render.draw(sprite); | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -39,6 +39,6 @@ namespace System { | |||
|   void inventory_swap(GameLevel &level, Entity container_id, const std::string& a_name, const std::string &b_name); | ||||
|   bool inventory_occupied(GameLevel& level, Entity container_id, const std::string& name); | ||||
| 
 | ||||
|   void draw_map(GameLevel& level, Matrix& grid, Matrix& fow, EntityGrid& entity_map); | ||||
|   void render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display); | ||||
|   void draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map); | ||||
|   void render_map(GameLevel& level, Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display); | ||||
| } | ||||
|  |  | |||
|  | @ -100,12 +100,8 @@ TEST_CASE("map image test", "[map-sprite]") { | |||
|   for(matrix::each_row it{level.map->walls()}; it.next();) { | ||||
|     player_pos.location.x = it.x; | ||||
|     player_pos.location.y = it.y; | ||||
|     size_t width = level.map->width(); | ||||
|     size_t height = level.map->height(); | ||||
| 
 | ||||
|     Matrix fow = matrix::make(width, height); | ||||
|     System::draw_map(level, map_tiles, fow, entity_map); | ||||
|     System::render_map(map_tiles, entity_map, *render, 2, player_display); | ||||
|     System::draw_map(level, map_tiles, entity_map); | ||||
|     System::render_map(level, map_tiles, entity_map, *render, 2, player_display); | ||||
| 
 | ||||
| #ifdef TEST_RENDER | ||||
|     // confirm we get two different maps
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Zed A. Shaw
						Zed A. Shaw