1
System / Passing arguments to sf::Thread
« on: December 30, 2013, 05:17:48 am »
I need some help passing an argument to a thread. I'm trying to update a map of snow, and I need to pass a class containing the section of the map that the thread needs to process to the thread. This is all done inside an object. I can't for the life of me figure it out. As it stands, my code returns a [Called object type 'void (Map::*)(Vector4i)' is not a function or function pointer] error upon build.
Any help would be appreciated.
The class containing the data:
The snow updator functions:
Any help would be appreciated.
The class containing the data:
class Vector4i {
public:
int x,y,z,a;
Vector4i() {}
Vector4i(int x_, int y_, int z_, int a_) {
x = x_;
y = y_;
z = z_;
a = a_;
}
};
public:
int x,y,z,a;
Vector4i() {}
Vector4i(int x_, int y_, int z_, int a_) {
x = x_;
y = y_;
z = z_;
a = a_;
}
};
The snow updator functions:
void tickSnowHelper(Vector4i vec) { //launched in thread (hopefully)
for (int y = vec.x; y < vec.y; y++) {
for (int x = vec.z; x < vec.a; x++) {
if (read(x, y) == 1 /* || read(x, y) == 2 */) {
if (read(x, y + 1) == 0) {
write(x, y, 0);
write(x, y + 1, -2);
} else if (read(x + 1, y + 1) == 0 || read(x - 1, y + 1) == 0) {
if (read(x - 1, y + 1) == 0 && read(x + 1, y + 1) == 0) {
if (rand()%2) {
write(x, y, 0);
write(x + 1, y + 1, -2);
} else {
write(x, y, 0);
write(x + 1, y + 1, -2);
}
} else if (read(x - 1, y + 1)) {
write(x, y, 0);
write(x + 1, y + 1, -2);
} else if (read(x + 1, y + 1)) {
write(x, y, 0);
write(x + 1, y + 1, -2);
}
}
}
}
}
}
void tickSnow() {
Vector4i sector1(0,MAP_HEIGHT/2,0,MAP_WIDTH/2);
// x-
// --
Vector4i sector2(0,MAP_HEIGHT/2,MAP_WIDTH/2,MAP_WIDTH);
// -x
// --
Vector4i sector3(MAP_HEIGHT/2,MAP_HEIGHT,0,MAP_WIDTH/2);
// --
// x-
Vector4i sector4(MAP_HEIGHT/2,MAP_HEIGHT,MAP_WIDTH/2,MAP_WIDTH);
// --
// -x
sf::Thread helper1(&Map::tickSnowHelper,this);
sf::Thread helper2(&Map::tickSnowHelper,this);
sf::Thread helper3(&Map::tickSnowHelper,this);
sf::Thread helper4(&Map::tickSnowHelper,this);
helper1.launch();
helper2.launch();
helper3.launch();
helper4.launch();
// finalizes snow map
for (int y = 0; y < MAP_HEIGHT; y++) {
for (int x = 0; x < MAP_WIDTH; x++) {
if (read(x, y) == -2) {
write(x, y, 1);
}
if (read(x, y) == -3) {
write(x, y, 2);
}
}
}
}
for (int y = vec.x; y < vec.y; y++) {
for (int x = vec.z; x < vec.a; x++) {
if (read(x, y) == 1 /* || read(x, y) == 2 */) {
if (read(x, y + 1) == 0) {
write(x, y, 0);
write(x, y + 1, -2);
} else if (read(x + 1, y + 1) == 0 || read(x - 1, y + 1) == 0) {
if (read(x - 1, y + 1) == 0 && read(x + 1, y + 1) == 0) {
if (rand()%2) {
write(x, y, 0);
write(x + 1, y + 1, -2);
} else {
write(x, y, 0);
write(x + 1, y + 1, -2);
}
} else if (read(x - 1, y + 1)) {
write(x, y, 0);
write(x + 1, y + 1, -2);
} else if (read(x + 1, y + 1)) {
write(x, y, 0);
write(x + 1, y + 1, -2);
}
}
}
}
}
}
void tickSnow() {
Vector4i sector1(0,MAP_HEIGHT/2,0,MAP_WIDTH/2);
// x-
// --
Vector4i sector2(0,MAP_HEIGHT/2,MAP_WIDTH/2,MAP_WIDTH);
// -x
// --
Vector4i sector3(MAP_HEIGHT/2,MAP_HEIGHT,0,MAP_WIDTH/2);
// --
// x-
Vector4i sector4(MAP_HEIGHT/2,MAP_HEIGHT,MAP_WIDTH/2,MAP_WIDTH);
// --
// -x
sf::Thread helper1(&Map::tickSnowHelper,this);
sf::Thread helper2(&Map::tickSnowHelper,this);
sf::Thread helper3(&Map::tickSnowHelper,this);
sf::Thread helper4(&Map::tickSnowHelper,this);
helper1.launch();
helper2.launch();
helper3.launch();
helper4.launch();
// finalizes snow map
for (int y = 0; y < MAP_HEIGHT; y++) {
for (int x = 0; x < MAP_WIDTH; x++) {
if (read(x, y) == -2) {
write(x, y, 1);
}
if (read(x, y) == -3) {
write(x, y, 2);
}
}
}
}