Adding mutex to level.
This commit is contained in:
parent
fc2ce96771
commit
127ee7a6ca
130
game/level.cc
130
game/level.cc
@ -10,6 +10,136 @@ Level::Level(std::string xmlFilePath) {
|
|||||||
this->xmlFilePath = xmlFilePath;
|
this->xmlFilePath = xmlFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Level::Level(const Level &&other) {
|
||||||
|
std::lock_guard<std::mutex> lock(other.light_mutex);
|
||||||
|
luaState = std::move(other.luaState);
|
||||||
|
crossChunkObjects = std::move(other.crossChunkObjects);
|
||||||
|
sortedCrossChunkObjects = std::move(other.sortedCrossChunkObjects);
|
||||||
|
allObjects = std::move(other.allObjects);
|
||||||
|
physicsObjects = std::move(other.physicsObjects);
|
||||||
|
chunks = std::move(other.chunks);
|
||||||
|
lights = std::move(other.lights);
|
||||||
|
closestLights = std::move(other.closestLights);
|
||||||
|
triggers = std::move(other.triggers);
|
||||||
|
waterPlane = std::move(other.waterPlane);
|
||||||
|
ambientLight = std::move(other.ambientLight);
|
||||||
|
fogColourDay = std::move(other.fogColourDay);
|
||||||
|
fogColourRise = std::move(other.fogColourRise);
|
||||||
|
fogColourNight = std::move(other.fogColourNight);
|
||||||
|
directionalLight = std::move(other.directionalLight);
|
||||||
|
cameraCenter = std::move(other.cameraCenter);
|
||||||
|
playerIndex = std::move(other.playerIndex);
|
||||||
|
skydome = std::move(other.skydome);
|
||||||
|
physics = std::move(other.physics);
|
||||||
|
camera = std::move(other.camera);
|
||||||
|
terrain = std::move(other.terrain);
|
||||||
|
skydomeSize = std::move(other.skydomeSize);
|
||||||
|
strength = std::move(other.strength);
|
||||||
|
xmlFilePath = std::move(other.xmlFilePath);
|
||||||
|
nextLightPosition = std::move(other.nextLightPosition);
|
||||||
|
chunkSize = std::move(other.chunkSize);
|
||||||
|
farPlane = std::move(other.farPlane);
|
||||||
|
}
|
||||||
|
|
||||||
|
Level::Level(const Level &other) {
|
||||||
|
std::lock_guard<std::mutex> lock(other.light_mutex);
|
||||||
|
luaState = other.luaState;
|
||||||
|
crossChunkObjects = other.crossChunkObjects;
|
||||||
|
sortedCrossChunkObjects = other.sortedCrossChunkObjects;
|
||||||
|
allObjects = other.allObjects;
|
||||||
|
physicsObjects = other.physicsObjects;
|
||||||
|
chunks = other.chunks;
|
||||||
|
lights = other.lights;
|
||||||
|
closestLights = other.closestLights;
|
||||||
|
triggers = other.triggers;
|
||||||
|
waterPlane = other.waterPlane;
|
||||||
|
ambientLight = other.ambientLight;
|
||||||
|
fogColourDay = other.fogColourDay;
|
||||||
|
fogColourRise = other.fogColourRise;
|
||||||
|
fogColourNight = other.fogColourNight;
|
||||||
|
directionalLight = other.directionalLight;
|
||||||
|
cameraCenter = other.cameraCenter;
|
||||||
|
playerIndex = other.playerIndex;
|
||||||
|
skydome = other.skydome;
|
||||||
|
physics = other.physics;
|
||||||
|
camera = other.camera;
|
||||||
|
terrain = other.terrain;
|
||||||
|
skydomeSize = other.skydomeSize;
|
||||||
|
strength = other.strength;
|
||||||
|
xmlFilePath = other.xmlFilePath;
|
||||||
|
nextLightPosition = other.nextLightPosition;
|
||||||
|
chunkSize = other.chunkSize;
|
||||||
|
farPlane = other.farPlane;
|
||||||
|
}
|
||||||
|
|
||||||
|
Level& Level::operator= (const Level &other) {
|
||||||
|
std::lock(light_mutex, other.light_mutex);
|
||||||
|
std::lock_guard<std::mutex> self_lock(light_mutex, std::adopt_lock);
|
||||||
|
std::lock_guard<std::mutex> other_lock(other.light_mutex, std::adopt_lock);
|
||||||
|
luaState = other.luaState;
|
||||||
|
crossChunkObjects = other.crossChunkObjects;
|
||||||
|
sortedCrossChunkObjects = other.sortedCrossChunkObjects;
|
||||||
|
allObjects = other.allObjects;
|
||||||
|
physicsObjects = other.physicsObjects;
|
||||||
|
chunks = other.chunks;
|
||||||
|
lights = other.lights;
|
||||||
|
closestLights = other.closestLights;
|
||||||
|
triggers = other.triggers;
|
||||||
|
waterPlane = other.waterPlane;
|
||||||
|
ambientLight = other.ambientLight;
|
||||||
|
fogColourDay = other.fogColourDay;
|
||||||
|
fogColourRise = other.fogColourRise;
|
||||||
|
fogColourNight = other.fogColourNight;
|
||||||
|
directionalLight = other.directionalLight;
|
||||||
|
cameraCenter = other.cameraCenter;
|
||||||
|
playerIndex = other.playerIndex;
|
||||||
|
skydome = other.skydome;
|
||||||
|
physics = other.physics;
|
||||||
|
camera = other.camera;
|
||||||
|
terrain = other.terrain;
|
||||||
|
skydomeSize = other.skydomeSize;
|
||||||
|
strength = other.strength;
|
||||||
|
xmlFilePath = other.xmlFilePath;
|
||||||
|
nextLightPosition = other.nextLightPosition;
|
||||||
|
chunkSize = other.chunkSize;
|
||||||
|
farPlane = other.farPlane;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Level& Level::operator= (const Level &&other) {
|
||||||
|
std::lock(light_mutex, other.light_mutex);
|
||||||
|
std::lock_guard<std::mutex> self_lock(light_mutex, std::adopt_lock);
|
||||||
|
std::lock_guard<std::mutex> other_lock(other.light_mutex, std::adopt_lock);
|
||||||
|
luaState = std::move(other.luaState);
|
||||||
|
crossChunkObjects = std::move(other.crossChunkObjects);
|
||||||
|
sortedCrossChunkObjects = std::move(other.sortedCrossChunkObjects);
|
||||||
|
allObjects = std::move(other.allObjects);
|
||||||
|
physicsObjects = std::move(other.physicsObjects);
|
||||||
|
chunks = std::move(other.chunks);
|
||||||
|
lights = std::move(other.lights);
|
||||||
|
closestLights = std::move(other.closestLights);
|
||||||
|
triggers = std::move(other.triggers);
|
||||||
|
waterPlane = std::move(other.waterPlane);
|
||||||
|
ambientLight = std::move(other.ambientLight);
|
||||||
|
fogColourDay = std::move(other.fogColourDay);
|
||||||
|
fogColourRise = std::move(other.fogColourRise);
|
||||||
|
fogColourNight = std::move(other.fogColourNight);
|
||||||
|
directionalLight = std::move(other.directionalLight);
|
||||||
|
cameraCenter = std::move(other.cameraCenter);
|
||||||
|
playerIndex = std::move(other.playerIndex);
|
||||||
|
skydome = std::move(other.skydome);
|
||||||
|
physics = std::move(other.physics);
|
||||||
|
camera = std::move(other.camera);
|
||||||
|
terrain = std::move(other.terrain);
|
||||||
|
skydomeSize = std::move(other.skydomeSize);
|
||||||
|
strength = std::move(other.strength);
|
||||||
|
xmlFilePath = std::move(other.xmlFilePath);
|
||||||
|
nextLightPosition = std::move(other.nextLightPosition);
|
||||||
|
chunkSize = std::move(other.chunkSize);
|
||||||
|
farPlane = std::move(other.farPlane);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Level::Level() {
|
Level::Level() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,10 @@ class Graphics;
|
|||||||
class Level {
|
class Level {
|
||||||
public:
|
public:
|
||||||
Level(std::string xmlFilePath);
|
Level(std::string xmlFilePath);
|
||||||
|
Level(const Level &other);
|
||||||
|
Level(const Level &&other);
|
||||||
|
Level& operator=(const Level &other);
|
||||||
|
Level& operator=(const Level &&other);
|
||||||
Level();
|
Level();
|
||||||
~Level();
|
~Level();
|
||||||
void load();
|
void load();
|
||||||
@ -114,6 +118,7 @@ class Level {
|
|||||||
int chunkSize;
|
int chunkSize;
|
||||||
float farPlane;
|
float farPlane;
|
||||||
bool compareLightDistances(Light* a, Light* b);
|
bool compareLightDistances(Light* a, Light* b);
|
||||||
|
mutable std::mutex light_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user