summaryrefslogtreecommitdiff
path: root/WorldSegment.h
diff options
context:
space:
mode:
authorPetr Mrázek2012-02-27 17:44:09 +0100
committerPetr Mrázek2012-02-27 17:44:09 +0100
commitca35c82579d1e3e0ce227ccdaeb71c2a6dbf1cb9 (patch)
tree04052da84dee32c944dc3d8e9a4167102cc2b8e9 /WorldSegment.h
parent09476326db2b0613e6120fa83146e004b6d92dda (diff)
downloadstonesense-ca35c82579d1e3e0ce227ccdaeb71c2a6dbf1cb9.tar.gz
stonesense-ca35c82579d1e3e0ce227ccdaeb71c2a6dbf1cb9.tar.bz2
stonesense-ca35c82579d1e3e0ce227ccdaeb71c2a6dbf1cb9.tar.xz
Get rid of a bunch of things. Simpler map segment update mechanism.
Diffstat (limited to 'WorldSegment.h')
-rw-r--r--WorldSegment.h46
1 files changed, 40 insertions, 6 deletions
diff --git a/WorldSegment.h b/WorldSegment.h
index 2a9b778..b755a32 100644
--- a/WorldSegment.h
+++ b/WorldSegment.h
@@ -1,5 +1,4 @@
-#ifndef WORLDSEGMENT_H
-#define WORLDSEGMENT_H
+#pragma once
#include "Block.h"
@@ -7,7 +6,6 @@ class WorldSegment{
private:
vector<Block*> blocks;
public:
- ALLEGRO_MUTEX * mutie;
bool loaded;
bool processed;
int x, y, z;
@@ -31,7 +29,6 @@ public:
uint32_t memoryNeeded = sizex * sizey * sizez * sizeof(Block*);
blocksAsPointerVolume = (Block**) malloc( memoryNeeded );
memset(blocksAsPointerVolume, 0, memoryNeeded);
- mutie = al_create_mutex();
}
~WorldSegment(){
@@ -40,7 +37,6 @@ public:
delete(blocks[i]);
}
blocks.clear();
- al_destroy_mutex(mutie);
}
void Dispose(void){
@@ -62,4 +58,42 @@ public:
bool CoordinateInsideSegment(uint32_t x, uint32_t y, uint32_t z);
};
-#endif \ No newline at end of file
+// FIXME: make nicer. one day. maybe.
+class SegmentWrap
+{
+public:
+ SegmentWrap()
+ {
+ segment = NULL;
+ mutex = al_create_mutex();
+ locked = false;
+ }
+ ~SegmentWrap()
+ {
+ al_destroy_mutex(mutex);
+ }
+ void lock()
+ {
+ al_lock_mutex(mutex);
+ locked = true;
+ }
+ void unlock()
+ {
+ al_unlock_mutex(mutex);
+ locked = false;
+ }
+ WorldSegment * swap(WorldSegment * newsegment)
+ {
+ WorldSegment * temp = segment;
+ segment = newsegment;
+ return temp;
+ }
+ WorldSegment * get()
+ {
+ return segment;
+ }
+private:
+ ALLEGRO_MUTEX * mutex;
+ WorldSegment * segment;
+ bool locked;
+};