summaryrefslogtreecommitdiff
path: root/Constructions.cpp
diff options
context:
space:
mode:
authorJonas Ask2009-11-20 01:52:29 +0000
committerJonas Ask2009-11-20 01:52:29 +0000
commit8f7a0fe698253075f9044d145d25c3ea5b82cf87 (patch)
tree58ca0cd1f2c7702460696226fe899fb844a2be84 /Constructions.cpp
parent4dcc68877180fdbe31a96a7b1e8f709ff9ac4d29 (diff)
downloadstonesense-8f7a0fe698253075f9044d145d25c3ea5b82cf87.tar.gz
stonesense-8f7a0fe698253075f9044d145d25c3ea5b82cf87.tar.bz2
stonesense-8f7a0fe698253075f9044d145d25c3ea5b82cf87.tar.xz
Moved the changeConstructionMaterials function, reducing it's runtime to O(n). very niiiice.
Slight improvements to UserInput.cpp.
Diffstat (limited to 'Constructions.cpp')
-rw-r--r--Constructions.cpp117
1 files changed, 54 insertions, 63 deletions
diff --git a/Constructions.cpp b/Constructions.cpp
index 18ba31e..13846fe 100644
--- a/Constructions.cpp
+++ b/Constructions.cpp
@@ -3,82 +3,73 @@
#include "Constructions.h"
#include "WorldSegment.h"
-
-void changeConstructionMaterials(WorldSegment* segment, Block* b, vector<t_construction>* allConstructions){
+void changeConstructionMaterials(WorldSegment* segment, vector<t_construction>* allConstructions){
//find construction
int32_t i;
- t_construction* c;
+ Block* b;
t_construction* construct = 0;
i = (uint32_t) allConstructions->size();
if(i <= 0) return;
while(--i >= 0){
- c = &(*allConstructions)[i];
- if(c->x == b->x && c->y == b->y && c->z == b->z ){
- construct = c;
- break;
- }
- }
- if(!construct) return;
-
- //replace floor, wall and ramp types
- if(b->floorType > 0){
- switch(c->material.type){
- case Mat_Wood:
- if(b->floorType == ID_CNSTFLOOR){
- //set to wooden floor
- b->floorType = ID_WOODFLOOR;
- //if tile beneth has a wooden wall, dont display a floor. hackish. buggish. whatever
- Block* under = segment->getBlockRelativeTo( b->x, b->y, b->z, eBelow );
- if(under && under->wallType == ID_WOODWALL)
- b->floorType = 0;
- }
- break;
- case Mat_Stone:
- //case Trey_Parker:
- break;
+ construct = &(*allConstructions)[i];
+ b = segment->getBlock(construct->x, construct->y, construct->z);
+ //replace floor, wall and ramp types
+ if(b->floorType > 0){
+ switch(construct->material.type){
+ case Mat_Wood:
+ if(b->floorType == ID_CNSTFLOOR){
+ //set to wooden floor
+ b->floorType = ID_WOODFLOOR;
+ //if tile beneth has a wooden wall, dont display a floor. hackish. buggish. whatever
+ Block* under = segment->getBlockRelativeTo( b->x, b->y, b->z, eBelow );
+ if(under && under->wallType == ID_WOODWALL)
+ b->floorType = 0;
+ }
+ break;
+ case Mat_Stone:
+ //case Trey_Parker:
+ break;
- case Mat_Metal:
- b->floorType = ID_METALFLOOR;
- }
+ case Mat_Metal:
+ b->floorType = ID_METALFLOOR;
+ }
- }
- if(b->wallType > 0){
- switch(c->material.type){
- case Mat_Wood:
- if(b->wallType == ID_CNSTFORTIFICATION)
- b->wallType = ID_WOODFORTIFICATION;
- else
- b->wallType = ID_WOODWALL;
- break;
- case Mat_Stone:
- //stones are the default constructed object, so dont change them
- break;
- case Mat_Metal:
- b->wallType = ID_METALWALL;
- break;
- }
- }
- if(b->stairType > 0){
- switch(c->material.type){
- case Mat_Wood:
- if(b->stairType == ID_CNSTR_STAIR_UP)
- b->stairType = ID_WOODFLOOR_STAIR_UP;
- if(b->stairType == ID_CNSTR_STAIR_UPDOWN)
- b->stairType = ID_WOODFLOOR_STAIR_UPDOWN;
- if(b->stairType == ID_CNSTR_STAIR_DOWN)
- b->stairType = ID_WOODFLOOR_STAIR_DOWN;
- break;
- case Mat_Stone:
- //case Trey_Parker:
- break;
}
+ if(b->wallType > 0){
+ switch(construct->material.type){
+ case Mat_Wood:
+ if(b->wallType == ID_CNSTFORTIFICATION)
+ b->wallType = ID_WOODFORTIFICATION;
+ else
+ b->wallType = ID_WOODWALL;
+ break;
+ case Mat_Stone:
+ //stones are the default constructed object, so dont change them
+ break;
+ case Mat_Metal:
+ b->wallType = ID_METALWALL;
+ break;
+ }
+ }
+ if(b->stairType > 0){
+ switch(construct->material.type){
+ case Mat_Wood:
+ if(b->stairType == ID_CNSTR_STAIR_UP)
+ b->stairType = ID_WOODFLOOR_STAIR_UP;
+ if(b->stairType == ID_CNSTR_STAIR_UPDOWN)
+ b->stairType = ID_WOODFLOOR_STAIR_UPDOWN;
+ if(b->stairType == ID_CNSTR_STAIR_DOWN)
+ b->stairType = ID_WOODFLOOR_STAIR_DOWN;
+ break;
+ case Mat_Stone:
+ //case Trey_Parker:
+ break;
+ }
+ }
}
-
}
-
-
bool IDisConstruction(int in){
switch(in){
case 495: //constructed pillar