Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generic utilities for working with imageData
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "ImageUtil.h" | ||
|
||
namespace sc2util { | ||
|
||
bool isSet(const sc2::GameInfo & info, const sc2::ImageData & grid, const sc2::Point2D & point) | ||
{ | ||
sc2::Point2DI pointI((int)point.x, (int)point.y); | ||
return isSet(info, grid, pointI); | ||
} | ||
|
||
bool isSet(const sc2::GameInfo & info, const sc2::ImageData & grid, const sc2::Point2DI & pointI) | ||
{ | ||
if (pointI.x < 0 || pointI.x >= info.width || pointI.y < 0 || pointI.y >= info.width) | ||
{ | ||
return false; | ||
} | ||
unsigned char encodedPlacement = grid.data[pointI.x + ((info.height - 1) - pointI.y) * info.width]; | ||
bool decodedPlacement = encodedPlacement == 255 ? false : true; | ||
return decodedPlacement; | ||
} | ||
|
||
bool set(sc2::GameInfo & info, sc2::ImageData & grid, const sc2::Point2D & point, bool b) | ||
{ | ||
sc2::Point2DI pointI((int)point.x, (int)point.y); | ||
return set(info, grid, pointI, b); | ||
} | ||
|
||
bool set(sc2::GameInfo & info, sc2::ImageData & grid, const sc2::Point2DI & pointI, bool b) | ||
{ | ||
if (pointI.x < 0 || pointI.x >= info.width || pointI.y < 0 || pointI.y >= info.width) | ||
{ | ||
return false; | ||
} | ||
unsigned char encodedPlacement = b ? 0 : 255; | ||
auto index = pointI.x + ((info.height - 1) - pointI.y) * info.width; | ||
grid.data[index] = encodedPlacement; | ||
return true; | ||
} | ||
|
||
bool setBuildingAt(sc2::GameInfo & info, sc2::ImageData & grid, const sc2::Point2D & pos, int footprint, bool b) | ||
{ | ||
using namespace sc2; | ||
float fx = pos.x - (float)footprint / 2.0f; | ||
float fy = pos.y - (float)footprint / 2.0f; | ||
|
||
Point2D point(fx, fy); | ||
auto inzone = sc2::Point2DI((int)point.x, (int)point.y); | ||
for (int y = 0; y < footprint; y++) { | ||
for (int x = 0; x < footprint; x++) { | ||
set(info, grid, Point2DI(inzone.x + x, inzone.y + y), !b); | ||
} | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include "sc2api/sc2_map_info.h" | ||
|
||
// API for manipulation of grid data as a matrix of bool indexed by Position | ||
namespace sc2util { | ||
|
||
// query pathing grid at given point | ||
bool isSet(const sc2::GameInfo & info, const sc2::ImageData & grid, const sc2::Point2D & point); | ||
bool isSet(const sc2::GameInfo & info, const sc2::ImageData & grid, const sc2::Point2DI & point); | ||
// updates | ||
bool set(sc2::GameInfo & info, sc2::ImageData & grid, const sc2::Point2D & point, bool b); | ||
bool set(sc2::GameInfo & info, sc2::ImageData & grid, const sc2::Point2DI & point, bool b); | ||
|
||
bool setBuildingAt(sc2::GameInfo & info, sc2::ImageData & grid, const sc2::Point2D & pos, int footprint, bool b); | ||
} |