30 lines
		
	
	
	
		
			690 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
	
		
			690 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #pragma once
 | |
| #include <vector>
 | |
| #include <unordered_map>
 | |
| #include "map.hpp"
 | |
| #include "dinkyecs.hpp"
 | |
| #include "point.hpp"
 | |
| 
 | |
| typedef std::vector<DinkyECS::Entity> EntityList;
 | |
| 
 | |
| typedef std::unordered_map<Point, DinkyECS::Entity, PointHash> PointEntityMap;
 | |
| 
 | |
| struct FoundEntities {
 | |
|   bool found;
 | |
|   EntityList nearby;
 | |
| };
 | |
| 
 | |
| class spatial_map {
 | |
|   public:
 | |
|     spatial_map() {}
 | |
| 
 | |
|     void insert(Point pos, DinkyECS::Entity obj);
 | |
|     void move(Point from, Point to, DinkyECS::Entity ent);
 | |
|     void remove(Point pos);
 | |
|     bool occupied(Point pos) const;
 | |
|     DinkyECS::Entity get(Point at) const;
 | |
|     FoundEntities neighbors(Point position, bool diag=false) const;
 | |
| 
 | |
|   private:
 | |
|     PointEntityMap table;
 | |
| };
 | 
