i dont care
This commit is contained in:
@@ -8,6 +8,7 @@ PheromoneMap::PheromoneMap(const char * file_name) {
|
||||
load_map(file_name);
|
||||
sem_init(&map_semaphore, 0, 1);
|
||||
tex_created = false;
|
||||
then = 0;
|
||||
}
|
||||
|
||||
PheromoneMap::~PheromoneMap() {
|
||||
@@ -26,7 +27,7 @@ void PheromoneMap::load_map(const char * file_name) {
|
||||
|
||||
png_init(0, 0);
|
||||
png_open_file_read(&tex, file_name);
|
||||
data = (unsigned char*) malloc(tex.width * tex.height * tex.bpp);
|
||||
data = static_cast<unsigned char *>(malloc(tex.width * tex.height * tex.bpp));
|
||||
png_get_data(&tex, data);
|
||||
|
||||
std::cout << "Loaded map \"" << file_name << "\" :: " << tex.width << "x" << tex.height << "x" << (int)tex.bpp << std::endl;
|
||||
@@ -48,7 +49,7 @@ GLuint PheromoneMap::s_build_texture() {
|
||||
glGenTextures(1, &handle);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, handle);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, m_width, m_height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
@@ -57,3 +58,56 @@ GLuint PheromoneMap::s_build_texture() {
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void PheromoneMap::s_draw_point(float x, float y) {
|
||||
int _x = m_width * x;
|
||||
int _y = m_height - (m_height * y);
|
||||
|
||||
sem_wait(&map_semaphore); {
|
||||
data[(_y * m_height) + _x] = 249;
|
||||
} sem_post(&map_semaphore);
|
||||
}
|
||||
|
||||
void PheromoneMap::s_update() {
|
||||
clock_t now = clock();
|
||||
|
||||
if(static_cast<float>(now - then) / CLOCKS_PER_SEC < 0.005) {
|
||||
return;
|
||||
}
|
||||
|
||||
then = now;
|
||||
|
||||
sem_wait(&map_semaphore); {
|
||||
for(int i = 1; i < m_height - 1; i++) {
|
||||
for(int j = 1; j < m_width - 1; j++) {
|
||||
if(data[(i * m_height) + j] > 10 && data[(i * m_height) + j] < 250){
|
||||
data[(i * m_height) + j] -= 1;
|
||||
|
||||
if(data[((i - 1) * m_height) + (j - 1)] < 250)
|
||||
data[((i - 1) * m_height) + (j - 1)] = data[(i * m_height) + j];
|
||||
|
||||
if(data[((i - 1) * m_height) + j] < 250)
|
||||
data[((i - 1) * m_height) + j] = data[(i * m_height) + j];
|
||||
|
||||
if(data[((i - 1) * m_height) + (j + 1)] < 250)
|
||||
data[((i - 1) * m_height) + (j + 1)] = data[(i * m_height) + j];
|
||||
|
||||
if(data[(i * m_height) + (j - 1)] < 250)
|
||||
data[(i * m_height) + (j - 1)] = data[(i * m_height) + j];
|
||||
|
||||
if(data[(i * m_height) + (j + 1)] < 250)
|
||||
data[(i * m_height) + (j + 1)] = data[(i * m_height) + j];
|
||||
|
||||
if(data[((i + 1) * m_height) + (j - 1)] < 250)
|
||||
data[((i + 1) * m_height) + (j - 1)] = data[(i * m_height) + j];
|
||||
|
||||
if(data[((i + 1) * m_height) + j] < 250)
|
||||
data[((i + 1) * m_height) + j] = data[(i * m_height) + j];
|
||||
|
||||
if(data[((i + 1) * m_height) + (j + 1)] < 250)
|
||||
data[((i + 1) * m_height) + (j + 1)] = data[(i * m_height) + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
} sem_post(&map_semaphore);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user