Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #92 from CityScope/buildings-debug
Browse files Browse the repository at this point in the history
fixes bug where building locations were not being properly updated fr…
  • Loading branch information
yasushisakai committed Nov 20, 2018
2 parents 3ee0cab + ba86368 commit 3b023ba
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 52 deletions.
1 change: 0 additions & 1 deletion ABMobility/Agent.pde
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ public class Agent {
PVector currDestBlockLocation = universe.grid.getBuildingLocationById(destBlockId);
if (currDestBlockLocation != destBlockLocation) {
// The destination block has been moved! Update the route.
println("updating route");
destBlockLocation = currDestBlockLocation;
destNode = getNodeByBlockId(destBlockId);
calcRoute();
Expand Down
2 changes: 1 addition & 1 deletion ABMobility/Building.pde
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Building {
capacityA = _capacityA;
}

public void draw (PGraphics p){
public void draw (PGraphics p) {
//p.rectMode(CORNER);
p.fill(universe.grid.gridQRcolorMap.get(loc));
p.stroke(#000000);
Expand Down
122 changes: 72 additions & 50 deletions ABMobility/Grid.pde
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

// There are set locations on the grid where buildings
// can be placed.
public final int BUILDING_LOCATIONS = 18;

public final int PHYSICAL_BUILDINGS_COUNT = 24;
// There are 'virtual buildings' in 'zombie land'.
// These buildings do not have physical representations and can
Expand All @@ -8,8 +12,9 @@ public final int PHYSICAL_BUILDINGS_COUNT = 24;
public final int VIRTUAL_ZOMBIE_BUILDING_ID = PHYSICAL_BUILDINGS_COUNT + 1;

public class Grid {
private ArrayList<Building> buildings; // all the building (24)
private ArrayList<Building> buildingsOnGrid; // Building present on the grid
// The buildings array is indexed by the ids of the buildings it holds.
// i.e. it maps Building.id --> Building for buildings 0...24
private ArrayList<Building> buildings;
private ArrayList<GridInteractionAnimation> gridAnimation;
public HashMap<Integer, PVector> gridMap;
HashMap<PVector,Integer> gridQRcolorMap;
Expand Down Expand Up @@ -45,15 +50,12 @@ public class Grid {
Building b = new Building(gridMap.get(loc), id, capacityR, capacityO, capacityA);
buildings.add(b);
}

// initialize buildings on grid as the first 18 buildings
buildingsOnGrid = new ArrayList<Building>();

gridAnimation = new ArrayList<GridInteractionAnimation>();

// is there a reason not using a simple for loop?
int i = 0;
for (Building b: buildings) {
buildingsOnGrid.add(b);
gridAnimation.add(new GridInteractionAnimation(b.loc));
i += 1;
if (i >= 18) {
Expand All @@ -62,58 +64,80 @@ public class Grid {
}
}

public void draw(PGraphics p){
for (Building b: buildingsOnGrid){
if(b.loc.x!=-1){
b.draw(p);
}
}
public void draw(PGraphics p) {
// Draw building block locations
drawBuildingBlocks(p);
// Draw buildings
for (Building b: buildings) {
if (b.loc != zombieLandLocation) {
b.draw(p);
}
}
// Draw grid animations (if they occured)
for (GridInteractionAnimation ga: gridAnimation){
ga.draw(p);
}
}

for (GridInteractionAnimation ga: gridAnimation){
ga.draw(p);
}
}
public void drawBuildingBlocks(PGraphics p) {
/* Lights up location where building block goes.
This is important to provide the scanner enough light to scan
whether or not a building is in the location.
*/
for (int i=0; i<BUILDING_LOCATIONS; i++) {
PVector loc = gridMap.get(i);
p.fill(255);
p.stroke(#000000);
p.rect(loc.x*GRID_CELL_SIZE+BUILDING_SIZE/2, loc.y*GRID_CELL_SIZE+BUILDING_SIZE/2, BUILDING_SIZE*0.9, BUILDING_SIZE*0.9);
}
}

public void updateGridFromUDP(String message){
//println("message" + message);
public void updateGridFromUDP(String message) {
// Take account of which buildings we have not seen in
// the incoming message.
int[] buildingIdsFromData = new int[PHYSICAL_BUILDINGS_COUNT];
for (int i=0; i<PHYSICAL_BUILDINGS_COUNT; i++) {
buildingIdsFromData[i] = 0;
}

JSONObject json = parseJSONObject(message);
JSONArray grids = json.getJSONArray("grid");
JSONArray grids = json.getJSONArray("grid"); // maps building location --> Building
for(int i=0; i < grids.size(); i++) {
Building b = buildingsOnGrid.get(i);
if(grids.getJSONArray(i).getInt(0) != -1){

// something was put onto the table
if(b.id == -1){
//update the id of the buildign to send the information of which special building has been sent to the grid Animation
b.id = grids.getJSONArray(i).getInt(0);
gridAnimation.get(i).put(b.id);
}
int buildingId = grids.getJSONArray(i).getInt(0);

if((buildingId >= 0) && (buildingId < PHYSICAL_BUILDINGS_COUNT)) {
Building building = buildings.get(buildingId);

b.capacityR = buildings.get(grids.getJSONArray(i).getInt(0)).capacityR;
b.capacityO = buildings.get(grids.getJSONArray(i).getInt(0)).capacityO;
b.capacityA = buildings.get(grids.getJSONArray(i).getInt(0)).capacityA;
}
else {

// the building was taken from the table
if(b.id != -1){
gridAnimation.get(i).take(b.id);
// building with buildingId is on the table
if (building.loc == zombieLandLocation) {
// building was previously not on table - it has just been put on table.
gridAnimation.get(i).put(buildingId);
}
building.loc = gridMap.get(i);
// Record that the building is on the grid
buildingIdsFromData[buildingId] = 1;
} else {
if (!gridAnimation.get(i).isPut) {
gridAnimation.get(i).take(buildingId);
}
}
}

b.id = -1;
b.capacityR = -1;
b.capacityO = -1;
b.capacityA = -1;
for (int buildingId=0; buildingId<PHYSICAL_BUILDINGS_COUNT; buildingId++) {
if (buildingIdsFromData[buildingId] == 0) {
Building building = buildings.get(buildingId);
building.loc = zombieLandLocation;
}
}

if(dynamicSlider) {
JSONArray sliders = json.getJSONArray("slider");
state.slider = 1.0 - sliders.getFloat(0);

}

//FIXME: Keep this for now in case we want to keep the permanent special effect see issue #86
/*if(isBuildingInCurrentGrid(20)){
if(isBuildingInCurrentGrid(20)){
showGlyphs = false;
}else{
showGlyphs =true;
Expand All @@ -127,15 +151,13 @@ public class Grid {
showCollisionPotential = true;
}else{
showCollisionPotential = false;
}*/


}

}
}

public boolean isBuildingInCurrentGrid(int id){
for (Building b: buildingsOnGrid){
if (b.id == id){
return true;
for (Building b: buildings){
if (b.id == id) {
return (b.loc != zombieLandLocation);
}
}
return false;
Expand Down

3 comments on commit 3b023ba

@agrignard
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I said this merge shouldn't be merge

I just tested the last master and this has broken the special building itnteraction that I just pushed this morning...!

Please be careful when merging something that was not suppose to be merge

@yasushisakai
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, are we talking about line 117-129?

I'm confused about the

I just tested that last master and this has broken the special building iteraction that I just pushed this
morning...?

This was there for a while? Or is this about the GridAnimation?

@agrignard
Copy link
Collaborator

@agrignard agrignard commented on 3b023ba Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 117-129 of which file?

The special effect were here for a while but not the temporary feature (that it disappear after 10 sec see issue #86)

I will reiterate

  1. This morning (in France) I pushed this commit 3ee0cab that introduces the temporay special effect (when you put the empire state building you see the network only for 10 sec)

  2. Then you merged the PR92 which was dealing issue Agents should update their destinations when buildings change #84 but but was not ready to be merged for the reason I explained (basically being sure to take care of id =-1 and id >18 even if they have no effect and the behavior of the agent

  3. They I rerun the simulation this afternoon (in France) and I saw that the spatial effect was not temporary any more for different reason (one of the reason is that I implemented the temporal spatial effect starting from the current master and that the PR92 overwrote some stuff)

  4. Then I tried to fix it in 7c854d9 but I realize it was not just about this

  5. so I revert what I did in 4 in 8de84a7 so that you can be strating from the PR92

Please sign in to comment.