[virtualcommons-svn] commit/foraging: alllee: fixing clipping range bug in rendering and working on
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2011-11-15 20:02:02
|
1 new commit in foraging: https://bitbucket.org/virtualcommons/foraging/changeset/f467c3bd858c/ changeset: f467c3bd858c user: alllee date: 2011-11-15 21:01:47 summary: fixing clipping range bug in rendering and working on some improvements to instructions building affected #: 6 files diff -r ed8ed0f247fd90e1da4716fadeaff361802defc5 -r f467c3bd858c5af915cd4d11d9c6274cfb0f269f src/main/java/edu/asu/commons/foraging/client/ForagingClient.java --- a/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java +++ b/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java @@ -237,6 +237,7 @@ private void initialize2DEventProcessors() { addEventProcessor(new EventTypeProcessor<BeginChatRoundRequest>(BeginChatRoundRequest.class) { public void handle(BeginChatRoundRequest request) { + System.err.println("Starting chat round"); dataModel.initialize(request.getGroupDataModel()); getGameWindow2D().initializeChatPanel(); } diff -r ed8ed0f247fd90e1da4716fadeaff361802defc5 -r f467c3bd858c5af915cd4d11d9c6274cfb0f269f src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java --- a/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java +++ b/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java @@ -426,9 +426,8 @@ return getBooleanProperty("chat-enabled"); } - // Should always return true for 3d experiments public boolean isChatEnabled() { - return isChatRoundEnabled() || isInRoundChatEnabled(); + return isChatRoundEnabled() || isInRoundChatEnabled() || isCensoredChat(); } public int getMaximumResourceAge() { @@ -603,25 +602,25 @@ return instructionsBuilder; } - public StringBuilder addAllSpecialInstructions(StringBuilder builder) { + public StringBuilder addAllSpecialInstructions(StringBuilder instructionsBuilder) { + // FIXME: refactor this convoluted conditional logic if possible + StringBuilder builder = new StringBuilder(); if (isFieldOfVisionEnabled()) { addSpecialInstructions(builder, getFieldOfVisionInstructions()); } if (isSanctioningEnabled()) { addSpecialInstructions(builder, getSanctionInstructions()); } - if (isCensoredChat()) { - addSpecialInstructions(builder, getCensoredChatInstructions()); - } - else if (isInRoundChatEnabled()) { + if (isInRoundChatEnabled()) { addSpecialInstructions(builder, getInRoundChatInstructions()); } else if (isChatEnabled()) { - // FIXME: hard-coded, need to make instructions template-able, perhaps - // via FreeMarker or Velocity. addSpecialInstructions(builder, "Before the beginning of this round you will be able to chat with the other members of your group for " + getChatDuration() + " seconds."); } + if (isCensoredChat()) { + addSpecialInstructions(builder, getCensoredChatInstructions()); + } String resourceGeneratorType = getResourceGeneratorType(); if (resourceGeneratorType.equals("mobile")) { addSpecialInstructions(builder, getMobileResourceInstructions()); @@ -629,11 +628,16 @@ else if (resourceGeneratorType.equals("top-bottom-patchy")) { addSpecialInstructions(builder, getPatchyResourceInstructions()); } - return builder; + if (builder.toString().isEmpty()) { + return instructionsBuilder; + } + else { + return instructionsBuilder.append("<h1>Additional instructions</h1><hr><ul>").append(builder).append("</ul>"); + } } private void addSpecialInstructions(StringBuilder builder, String instructions) { - builder.append("<p>").append(instructions).append("</p>"); + builder.append("<li>").append(instructions).append("</li>"); } private String getMobileResourceInstructions() { diff -r ed8ed0f247fd90e1da4716fadeaff361802defc5 -r f467c3bd858c5af915cd4d11d9c6274cfb0f269f src/main/java/edu/asu/commons/foraging/server/ForagingServer.java --- a/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java +++ b/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java @@ -69,7 +69,6 @@ import edu.asu.commons.foraging.model.EnforcementMechanism; import edu.asu.commons.foraging.model.GroupDataModel; import edu.asu.commons.foraging.model.ResourceDispenser; -import edu.asu.commons.foraging.model.SanctionMechanism; import edu.asu.commons.foraging.model.ServerDataModel; import edu.asu.commons.foraging.rules.ForagingRule; import edu.asu.commons.foraging.ui.Circle; @@ -157,6 +156,7 @@ } else if (input.equals("skip-quiz")) { System.out.println("skipping quiz"); + numberOfSubmittedQuizzes = clients.size(); Utils.notify(quizSignal); } else if (input.equals("start-round")) { @@ -202,6 +202,7 @@ private ResourceDispenser resourceDispenser; private ServerState serverState; private final Duration secondTick = Duration.create(1000L); + private volatile boolean groupsInitialized; /** * Initializes the state machine before the experiment ever begins. @@ -682,30 +683,12 @@ // another way to handle this is to have the clients added // to groups when the show instructions request is handled.. initializeGroups(); - /* - if (getCurrentRoundConfiguration().isFirstRound()) { - shuffleParticipants(); - } - + sendFacilitatorMessage("Sending begin chat round request to all participants"); for (Map.Entry<Identifier, ClientData> entry : clients.entrySet()) { Identifier id = entry.getKey(); ClientData clientData = entry.getValue(); - // FIXME: hacky, get rid of this. - if (clientData.getGroupDataModel() == null) { - // we haven't added this client to the server data model yet. Add them now.. - // FIXME: will this cause problems if we invoke shuffleParticipants() later? I.e., - // the clients get added to the server data model for the purposes of the chat - // and then when they start the actual round they get reshuffled? Need to - // rethink clearly/carefully how clients and when clients get added to the server - // data model...! - serverDataModel.addClient(clientData); - } transmit(new BeginChatRoundRequest(id, clientData.getGroupDataModel())); - // FIXME: should we initialize the persister now? - // just store communication traffic in a separate text file. - } - */ } } }); @@ -887,8 +870,6 @@ private void stopRound() { serverState = ServerState.WAITING; - // FIXME: not needed, persister.persist() automatically adds this. - // persister.store(new RoundEndedMarkerEvent()); sendEndRoundEvents(); if (getCurrentRoundConfiguration().isPostRoundSanctioningEnabled()) { // stop most of the round but don't persist/cleanup yet. @@ -926,6 +907,7 @@ private void cleanupRound() { numberOfSubmittedQuizzes = 0; + groupsInitialized = false; serverDataModel.cleanupRound(); for (ClientData clientData : clients.values()) { clientData.reset(); @@ -950,12 +932,14 @@ } private boolean shouldShuffleParticipants() { + // guard to ensure that we don't shuffle participants twice in a round (in the event there was a chat round preceding the normal game round) + if (groupsInitialized) return false; RoundConfiguration currentRoundConfiguration = getCurrentRoundConfiguration(); RoundConfiguration previousRoundConfiguration = getConfiguration().getPreviousRoundConfiguration(); - // when do we _have_ to shuffle participants? + // we shuffle participants: // 1. when randomize-groups is set for the next round // 2. when we move from a private property round to a open access round - // 3. in general, when the clients per group in the current round is different from the + // 3. when the clients per group in the current round is different from the // clients per group in the next round (FIXME: is this too broad or can #2 just be a special case of this?) return currentRoundConfiguration.shouldRandomizeGroup() || (previousRoundConfiguration.getClientsPerGroup() != currentRoundConfiguration.getClientsPerGroup()); @@ -996,6 +980,7 @@ // set up the resource dispenser, generates the initial resource distributions for the // groups, must be done after creating the client group relationships. resourceDispenser.initialize(); + groupsInitialized = true; } private void startRound() { diff -r ed8ed0f247fd90e1da4716fadeaff361802defc5 -r f467c3bd858c5af915cd4d11d9c6274cfb0f269f src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java --- a/src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java +++ b/src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java @@ -471,11 +471,16 @@ switch (keyCode) { // token request handling case KeyEvent.VK_SPACE: - if (dataModel.isHarvestingAllowed()) { - event = new CollectTokenRequest(client.getId()); + try { + if (dataModel.isHarvestingAllowed()) { + event = new CollectTokenRequest(client.getId()); + } + else { + displayErrorMessage("You cannot harvest at this time."); + } } - else { - displayErrorMessage("You cannot harvest at this time."); + catch (RuntimeException exception) { + displayErrorMessage("You cannot harvest at this time"); } break; // real-time sanctioning keycode handling @@ -709,6 +714,7 @@ private ChatPanel getChatPanel() { if (chatPanel == null) { chatPanel = new ChatPanel(client); + chatPanel.setName(CHAT_PANEL_NAME); } return chatPanel; } @@ -881,7 +887,7 @@ SwingUtilities.invokeLater(new Runnable() { public void run() { ChatPanel chatPanel = getChatPanel(); - chatPanel.initialize(client.getDataModel()); + chatPanel.initialize(dataModel); showPanel(CHAT_PANEL_NAME); startChatTimer(); } diff -r ed8ed0f247fd90e1da4716fadeaff361802defc5 -r f467c3bd858c5af915cd4d11d9c6274cfb0f269f src/main/java/edu/asu/commons/foraging/ui/GridView.java --- a/src/main/java/edu/asu/commons/foraging/ui/GridView.java +++ b/src/main/java/edu/asu/commons/foraging/ui/GridView.java @@ -73,8 +73,8 @@ dw = (availableWidth / boardSize.getWidth()); dh = (availableHeight / boardSize.getHeight()); // ensure square proportions - dh = dw = Math.min(dw, dh); -// dh = dw; + dw = dh = Math.min(dw, dh); +// availableWidth = availableHeight = Math.min(availableWidth, availableHeight); xoffset = (int) Math.floor((availableWidth - (dw * boardSize.getWidth())) / 2); yoffset = (int) Math.floor((availableHeight - (dh * boardSize.getHeight())) / 2); diff -r ed8ed0f247fd90e1da4716fadeaff361802defc5 -r f467c3bd858c5af915cd4d11d9c6274cfb0f269f src/main/java/edu/asu/commons/foraging/ui/SubjectView.java --- a/src/main/java/edu/asu/commons/foraging/ui/SubjectView.java +++ b/src/main/java/edu/asu/commons/foraging/ui/SubjectView.java @@ -6,6 +6,7 @@ import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Point; +import java.awt.Rectangle; import java.awt.geom.Ellipse2D; import java.util.HashMap; import java.util.Iterator; @@ -164,6 +165,9 @@ Ellipse2D.Double circle = new Ellipse2D.Double(x, y, diameter, diameter); // clip the rendered part of the Field of vision circle that crosses the playing boundary graphics2D.setClip(circle); + // this is actually a bit too tall, fine-tune & investigate later + Rectangle bounds = new Rectangle(getPreferredSize()); + graphics2D.clip(bounds); Paint originalPaint = graphics2D.getPaint(); graphics2D.setPaint(FIELD_OF_VISION_COLOR); graphics2D.fill(circle); Repository URL: https://bitbucket.org/virtualcommons/foraging/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |