bool DeleteMap::HandleAction(QString &action, uint64_t frame, uint64_t played) { bool handled = true; if (action == ACTION_UP) UpdateSeekAmount(1); else if (action == ACTION_DOWN) UpdateSeekAmount(-1); else if (action == ACTION_CLEARMAP) Clear(tr("Clear Cuts")); else if (action == ACTION_INVERTMAP) ReverseAll(); else if (action == "MOVEPREV") MoveRelative(frame, false); else if (action == "MOVENEXT") MoveRelative(frame, true); else if (action == "CUTTOBEGINNING") { Push(tr("Cut to Beginning")); AddMark(frame, MARK_CUT_END); } else if (action == "CUTTOEND") { Push(tr("Cut to End")); AddMark(frame, MARK_CUT_START); // If the recording is still in progress, add an explicit end // mark at the end. if (m_ctx->player && m_ctx->player->IsWatchingInprogress()) AddMark(m_ctx->player->GetTotalFrameCount() - 1, MARK_CUT_END); } else if (action == "NEWCUT") NewCut(frame); else if (action == "DELETE") //: Delete the current cut or preserved region Delete(frame, tr("Delete")); else if (action == "UNDO") Undo(); else if (action == "REDO") Redo(); else handled = false; return handled; }
/// Move an existing mark to a new frame. void DeleteMap::Move(uint64_t frame, uint64_t to) { EDIT_CHECK; Push(tr("Move Mark")); MarkTypes type = Delete(frame); if (MARK_UNSET == type) { if (frame == 0) type = MARK_CUT_START; else if (frame == m_ctx->player->GetTotalFrameCount()) type = MARK_CUT_END; } AddMark(to, type); }
bool bgControlPointsGizmo::Initialize(bgActor* pActor, bgShaderFactory* ShaderFactory,cRenderer* pRenderer) { ASSERT(pActor != 0); bgGizmo::Initialize(pActor, ShaderFactory,pRenderer); pMapper = dynamic_cast<bgSplineMapper*>(pActor->getInput()); if (pMapper == 0) return false; PickingPoints = pMapper->GetControlPoints(); if (PickingPoints.size() <= 0) return false; pGuideLine->getInput()->getInput()->initialize(); pGuideLine->initialize(); bgData* pData = pGuideLine->getInput()->getInput(); bgData::_PositionList& PositionList = pData->GetPositionList(); bgData::_ColorList& ColorList = pData->GetColorList(); bgData::_IndexList& IndexList = pData->GetIndexList(); std::vector<glm::vec3>::iterator iControl = PickingPoints.begin(); for (; iControl != PickingPoints.end(); iControl++) { PositionList.push_back((*iControl).x); PositionList.push_back((*iControl).y); PositionList.push_back((*iControl).z); ColorList.push_back(0.0f); ColorList.push_back(1.0f); ColorList.push_back(0.0f); AddMark(*iControl, pRenderer); } for (int index = 0; index < PositionList.size() / 3-1; index++){ IndexList.push_back(index); IndexList.push_back(index+1); } pGuideLine->build(*pRenderer); return true; }
void PrintMarksComponent::EndImportCustomPrintMark(CamelotRecordHandler *pHandler) { PORTNOTETRACE("print","PrintMarksComponent::EndImportCustomPrintMark - do nothing"); #ifndef EXCLUDE_FROM_XARALX ERROR3IF(CustomCurrentContext == NULL || pNewMark == NULL, "EndImportCustomPrintMark - StartImportCustomMark not called/failed"); // Find the Print mark manager and it's PrintMark cache PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager(); if (pMarksMan == NULL) return; // Restore the previous import context node pHandler->SetInsertContextNode(CustomPreviousContext); // Complete the mark and add it to the PMM cache NodeGroup *Glyph = (NodeGroup *)CustomCurrentContext->FindFirstChild(); ERROR3IF(Glyph == NULL, "Import of custom mark subtree must have failed"); if (Glyph != NULL) { ERROR3IF(!Glyph->IsKindOf(CC_RUNTIME_CLASS(NodeGroup)), "Imported print mark doesn't start with a group"); Glyph->UnlinkNodeFromTree(NULL); UINT32 MarkHandle = pMarksMan->PMMCache.AddNewMark(pNewMark, Glyph); // Add a reference to the mark to ourself, so the mark is enabled AddMark(MarkHandle); } else { // Try not to leak too much! delete pNewMark; } // Tidy up pNewMark = NULL; CustomPreviousContext = NULL; delete CustomCurrentContext; CustomCurrentContext = NULL; #endif }
void PrintMarksComponent::ImportDefaultPrintMark(CXaraFileRecord* Rec) { PORTNOTETRACE("print","PrintMarksComponent::ExportPrintMark - do nothing"); #ifndef EXCLUDE_FROM_XARALX ERROR3IF(Rec == NULL, "Illegal NULL params"); BYTE ID = 0; BOOL ok = Rec->ReadBYTE(&ID); if (!ok) return; // Find the Print mark manager and it's PrintMark cache PrintMarksMan* pMarksMan = GetApplication()->GetMarksManager(); if (pMarksMan == NULL) return; // Search the PMMCache list for a PrintMark with the given ID byte UINT32 Handle = 0; BOOL Found = FALSE; PrintMarkItem *pItem = pMarksMan->PMMCache.GetFirstMark(); while (pItem != NULL) { PrintMark *pMark = pItem->GetPrintMark(); if (pMark != NULL && pMark->GetIDByte() == ID) { Handle = pItem->GetHandle(); Found = TRUE; break; } pItem = pMarksMan->PMMCache.GetNextMark(pItem); } // If we found a mark, then Handle is its PMM handle - Add an entry to our // list of Enabled marks. if (Found) AddMark(Handle); #endif }
void MythUIEditBar::Display(void) { QRect keeparea = QRect(); QRect cutarea = QRect(); MythUIType *position = GetChild("position"); MythUIType *keep = GetChild("keep"); MythUIType *cut = GetChild("cut"); MythUIType *cuttoleft = GetChild("cuttoleft"); MythUIType *cuttoright = GetChild("cuttoright"); MythUIType *keeptoleft = GetChild("keeptoleft"); MythUIType *keeptoright = GetChild("keeptoright"); if (position) position->SetVisible(false); if (keep) { keep->SetVisible(false); keeparea = keep->GetArea(); } if (cut) { cut->SetVisible(false); cutarea = cut->GetArea(); } if (cuttoleft) cuttoleft->SetVisible(false); if (cuttoright) cuttoright->SetVisible(false); if (keeptoleft) keeptoleft->SetVisible(false); if (keeptoright) keeptoright->SetVisible(false); if (position && keeparea.isValid()) { int offset = position->GetArea().width() / 2; int newx = (int)(((float)keeparea.width() * m_editPosition) + 0.5f); int newy = position->GetArea().top(); position->SetPosition(newx - offset, newy); position->SetVisible(true); } ClearImages(); if (!m_regions.size()) { if (keep) keep->SetVisible(true); return; } MythUIShape *barshape = dynamic_cast<MythUIShape *>(cut); MythUIImage *barimage = dynamic_cast<MythUIImage *>(cut); MythUIShape *leftshape = dynamic_cast<MythUIShape *>(cuttoleft); MythUIImage *leftimage = dynamic_cast<MythUIImage *>(cuttoleft); MythUIShape *rightshape = dynamic_cast<MythUIShape *>(cuttoright); MythUIImage *rightimage = dynamic_cast<MythUIImage *>(cuttoright); QListIterator<QPair<float, float> > regions(m_regions); while (regions.hasNext() && cutarea.isValid()) { QPair<float, float> region = regions.next(); int left = (int)((region.first * cutarea.width()) + 0.5f); int right = (int)((region.second * cutarea.width()) + 0.5f); if (left >= right) right = left + 1; if (cut) { AddBar(barshape, barimage, QRect(left, cutarea.top(), right - left, cutarea.height())); } if (cuttoleft && (region.second < 1.0f)) AddMark(leftshape, leftimage, right, true); if (cuttoright && (region.first > 0.0f)) AddMark(rightshape, rightimage, left, false); } CalcInverseRegions(); barshape = dynamic_cast<MythUIShape *>(keep); barimage = dynamic_cast<MythUIImage *>(keep); leftshape = dynamic_cast<MythUIShape *>(keeptoleft); leftimage = dynamic_cast<MythUIImage *>(keeptoleft); rightshape = dynamic_cast<MythUIShape *>(keeptoright); rightimage = dynamic_cast<MythUIImage *>(keeptoright); QListIterator<QPair<float, float> > regions2(m_invregions); while (regions2.hasNext() && keeparea.isValid()) { QPair<float, float> region = regions2.next(); int left = (int)((region.first * keeparea.width()) + 0.5f); int right = (int)((region.second * keeparea.width()) + 0.5f); if (left >= right) right = left + 1; if (keep) { AddBar(barshape, barimage, QRect(left, keeparea.top(), right - left, keeparea.height())); } if (keeptoleft && (region.second < 1.0f)) AddMark(leftshape, leftimage, right, true); if (keeptoright && (region.first > 0.0f)) AddMark(rightshape, rightimage, left, false); } if (position) position->MoveToTop(); }
void nraApplicationModel::MessageDispatcher(nraWeakPointer<CReconItem> ReconItem) { nraSharedPointer<CUIMessage> UIMessage; CUIAddMark* pAddMark; CUIDestroyMark* pDestroyMark; CUIMoveMark* pMoveMark; CUISetLabel* pSetLabel; CUISetSlice* pSetSlice; CUISetSlider* pSetSlider; CUISetStack* pSetStack; CUIDisable* pDisable; //queue< nraSharedPointer<CUIMessage> > MessageQueue; m_boolSemaphore = false; while(!(*ReconItem).MessageQueue.empty()) { UIMessage = (*ReconItem).MessageQueue.front(); (*ReconItem).MessageQueue.pop(); pAddMark = dynamic_cast<CUIAddMark*>(UIMessage.GetPointer()); if(pAddMark) { emit AddMark(pAddMark->GetTag(), pAddMark->GetType(), pAddMark->GetAccLabel(), pAddMark->GetX(), pAddMark->GetY()); continue; } pDestroyMark = dynamic_cast<CUIDestroyMark*>(UIMessage.GetPointer()); if(pDestroyMark) { emit DestroyMark(pDestroyMark->GetTag()); continue; } pMoveMark = dynamic_cast<CUIMoveMark*>(UIMessage.GetPointer()); if(pMoveMark) { emit MoveMark(pMoveMark->GetTag(), pMoveMark->GetX(), pMoveMark->GetY()); continue; } pSetLabel = dynamic_cast<CUISetLabel*>(UIMessage.GetPointer()); if(pSetLabel) { emit SetLabel(pSetLabel->GetTag(), pSetLabel->GetLabel()); continue; } pSetSlice = dynamic_cast<CUISetSlice*>(UIMessage.GetPointer()); if(pSetSlice) { emit SetSlice(pSetSlice->GetSlice()); continue; } pSetSlider = dynamic_cast<CUISetSlider*>(UIMessage.GetPointer()); if(pSetSlider) { emit SetSlider(pSetSlider->GetMin(),pSetSlider->GetMax(),pSetSlider->GetVal()); continue; } pSetStack = dynamic_cast<CUISetStack*>(UIMessage.GetPointer()); if(pSetStack) { emit SetStack(pSetStack->GetStack()); continue; } pDisable = dynamic_cast<CUIDisable*>(UIMessage.GetPointer()); if(pDisable) { emit Disable(); continue; } } m_boolSemaphore = true; }
int main(int argc, char *argv[]) { VERBOSE = 0; GRAPHICS = 0; validate(argc, argv); int avatarID = atoi(argv[1]); FILE *logFile; logFile = fopen(argv[6], "a+"); char *IP = (char*)calloc(strlen(argv[4]) + 1, sizeof(char)); MALLOC_CHECK(stderr, IP); strncpy(IP, argv[4], strlen(argv[4])); myAvatar *avatar; int slobAvatar = 0; // the one who doesn't move in maze solver int mazePort = atoi(argv[5]); int width = atoi(argv[7]); int height = atoi(argv[8]); int shmID = atoi(argv[9]); char *maze = (char*) shmat(shmID, 0, 0); if (maze == (void *)-1 && errno == EACCES) { fprintf(stderr, "shmat failed EACCES\n"); exit(1); } if (maze == (void *)-1 && errno == EINVAL) { fprintf(stderr, "shmat failed EINVAL\n"); exit(1); } if (maze == (void *)-1 && errno == ENOMEM) { fprintf(stderr, "shmat failed ENOMEM\n"); exit(1); } // Server connection stuff int sockfd; struct sockaddr_in servaddr; // Create and check status of server sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { free(IP); fprintf(stderr, "Could not create socket.\n"); return 0; // false } memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = inet_addr(IP); servaddr.sin_port = htons(mazePort); // Connect to server if (connect(sockfd, (struct sockaddr*) &servaddr, \ sizeof(servaddr)) < 0) { fprintf(stderr, "Unable to connect to server. Exiting.\n"); free(IP); return 0; // false } // Fire off initial AM_AVATAR_READY AM_Message *sendmsg = (AM_Message*)calloc(1, sizeof(AM_Message)); MALLOC_CHECK(stderr, sendmsg); sendmsg->type = htonl(AM_AVATAR_READY); sendmsg->avatar_ready.AvatarId = htonl(avatarID); // pack information // Send ready message to server containing avatar ID send(sockfd, sendmsg, sizeof(AM_Message), 0); // Make a message to get back from server AM_Message *receivemsg = (AM_Message*)calloc(1, sizeof(AM_Message)); MALLOC_CHECK(stderr, receivemsg); int firstMove = 1; int turn = -1; // Start while loop that checks all server messages and updates // the avatar's position until either error message or AM_SOLVED received for ( ;; ) { // Zero out the message pointers so they can be re-used memset(receivemsg, 0, sizeof(AM_Message)); memset(sendmsg, 0, sizeof(AM_Message)); // Receive the message and make sure it's not empty if (recv(sockfd, receivemsg, sizeof(AM_Message), 0) == 0) { fprintf(stderr, "Server terminated early.\n"); OUTPUT(logFile, "Empty message type. Exiting...\n"); break; } // Check for server error if (IS_AM_ERROR(receivemsg->type)) { fprintf(stderr, "Error mask detected error.\n"); } // Following if statements will check for all possible server errors // In all cases, print to stderr, log the error to output file // and break to free resources and return if (ntohl(receivemsg->type) == AM_UNKNOWN_MSG_TYPE) { fprintf(stderr, "AM_UNKNOWN_MSG_TYPE\n"); OUTPUT(logFile, "Unknown message type. Exiting...\n"); break; } if (ntohl(receivemsg->type) == AM_NO_SUCH_AVATAR) { fprintf(stderr, "AM_NO_SUCH_AVATAR\n"); OUTPUT(logFile, "No such avatar error. Exiting...\n"); break; } if (ntohl(receivemsg->type) == AM_UNEXPECTED_MSG_TYPE) { fprintf(stderr, "AM_UNEXPECTED_MSG_TYPE\n"); OUTPUT(logFile, "Unexpected message type. Exiting...\n"); break; } if (ntohl(receivemsg->type) == AM_AVATAR_OUT_OF_TURN) { fprintf(stderr, "AM_AVATAR_OUT_OF_TURN\n"); OUTPUT(logFile, "Avatar out of turns message type. Exiting...\n"); break; } if (ntohl(receivemsg->type) == AM_TOO_MANY_MOVES) { fprintf(stderr, "AM_AVATAR_TOO_MANY_MOVES\n"); OUTPUT(logFile, "Avatar too many moves message type. Exiting...\n"); break; } if (ntohl(receivemsg->type) == AM_SERVER_TIMEOUT) { fprintf(stderr, "AM_SERVER_TIMEOUT\n"); OUTPUT(logFile, "Server timeout message type. Exiting...\n"); break; } if (ntohl(receivemsg->type) == AM_SERVER_DISK_QUOTA) { fprintf(stderr, "AM_SERVER_DISK_QUOTA\n"); OUTPUT(logFile, "Server disk quota message type. Exiting...\n"); break; } if (ntohl(receivemsg->type) == AM_SERVER_OUT_OF_MEM) { fprintf(stderr, "AM_SERVER_OUT_OF_MEM\n"); OUTPUT(logFile, "Server out of mem message type. Exiting...\n"); break; } // Huzzah! Output success to log file. if (ntohl(receivemsg->type) == AM_MAZE_SOLVED) { // Only output this stuff once. if (avatarID == slobAvatar) { fprintf(stdout, "SOLVED!!!\n"); fprintf(logFile, "Maze solved with %d avatars on %d" " difficulty in %d moves. The Hash key is: %d.\n", ntohl(receivemsg->maze_solved.nAvatars),\ ntohl(receivemsg->maze_solved.Difficulty), ntohl(receivemsg->maze_solved.\ nMoves), ntohl(receivemsg->maze_solved.Hash)); } break; } if (ntohl(receivemsg->type) == AM_AVATAR_TURN) { // Only look at messages from the relevant reply messages if (ntohl(receivemsg->avatar_turn.TurnId) == avatarID) { if (firstMove) { // Initialize the avatar. avatar = (myAvatar*)calloc(1, sizeof(myAvatar)); MALLOC_CHECK(stderr, avatar); avatar->fd = avatarID; avatar->lastMoveDir = M_NORTH; // everyone goes north initially // Initially, avatar's previous position and current position // are the same. Retrieve these from server. avatar->pos.x = ntohl(receivemsg->avatar_turn.Pos[avatarID].x); avatar->pos.y = ntohl(receivemsg->avatar_turn.Pos[avatarID].y); // No previous initially. // Send the avatar north. sendmsg->type = htonl(AM_AVATAR_MOVE); sendmsg->avatar_move.AvatarId = htonl(avatarID); sendmsg->avatar_move.Direction = htonl(M_NORTH); if (VERBOSE) { fprintf(stdout, "Avatar %d: Initial pos (%d, %d) moved NORTH\n", avatarID,\ avatar->pos.x, avatar->pos.y); } // Send ready message to server containing avatar ID send(sockfd, sendmsg, sizeof(AM_Message), 0); turn = 1; firstMove = 0; if (GRAPHICS) { //initialize graphics AddAvatar(maze,avatar,width); PrintMaze(maze, width, height); } continue; } else { // not first move // If it's the avatar standing still, arbitrarily picked as // avatar with ID = 0, then always stand still. if (avatarID == slobAvatar) { sendmsg->type = htonl(AM_AVATAR_MOVE); sendmsg->avatar_move.AvatarId = htonl(avatarID); // should be 0 sendmsg->avatar_move.Direction = htonl(M_NULL_MOVE); send(sockfd, sendmsg, sizeof(AM_Message), 0); turn++; continue; } // Make the previous the current position avatar->prev.x = avatar->pos.x; avatar->prev.y = avatar->pos.y; turn++; // Make current position the new one from the server int newX = ntohl(receivemsg->avatar_turn.Pos[avatarID].x); int newY = ntohl(receivemsg->avatar_turn.Pos[avatarID].y); avatar->pos.x = newX; avatar->pos.y = newY; // See if the slob and the current avatar are on the same spot. int deltaX = avatar->pos.x - ntohl(receivemsg->avatar_turn.Pos[slobAvatar].x); int deltaY = avatar->pos.y - ntohl(receivemsg->avatar_turn.Pos[slobAvatar].y); int checkSameCell = 0; if ((deltaY == 0) && (deltaX == 0)) { checkSameCell = 1; } // If avatar is on same spot as slob, slob has been found. // Don't move the other avatar. if (checkSameCell) { sendmsg->type = htonl(AM_AVATAR_MOVE); sendmsg->avatar_move.AvatarId = htonl(avatarID); sendmsg->avatar_move.Direction = htonl(M_NULL_MOVE); send(sockfd, sendmsg, sizeof(AM_Message), 0); turn++; continue; } // Avatar is not slob and has not yet met slob. else { // See if the last move was productive int lastMove = checkLastMove(avatar); avatar->lastMoveSuccess = lastMove; //update graphics based on last move if(!lastMove){ AddWall(maze,avatar,width); } else{ //DelAvatar(maze,avatar,width);//comment out to see history if(!AddMark(maze,avatar,width))//blocks square if test passes AddAvatar(maze,avatar,width); } if (GRAPHICS) { PrintMaze(maze,width,height); } //prep next move int nextMove = getMove(avatar); avatar->lastMoveDir = nextMove; while(isKnown(maze, avatar, width)){ avatar->lastMoveSuccess = false; nextMove = getMove(avatar); avatar->lastMoveDir = nextMove; } turn++; sendmsg->type = htonl(AM_AVATAR_MOVE); sendmsg->avatar_move.AvatarId = htonl(avatarID); sendmsg->avatar_move.Direction = htonl(nextMove); if (VERBOSE) { fprintf(stdout, "======== Turn %d ========\n", turn); if (nextMove == M_NORTH) { fprintf(stdout, "Avatar %d: Moved NORTH from (%d, %d).\n", avatarID,\ avatar->pos.x, avatar->pos.y); } if (nextMove == M_SOUTH) { fprintf(stdout, "Avatar %d: Moved SOUTH from (%d, %d).\n", avatarID,\ avatar->pos.x, avatar->pos.y); } if (nextMove == M_WEST) { fprintf(stdout, "Avatar %d: Moved WEST from (%d, %d).\n", avatarID,\ avatar->pos.x, avatar->pos.y); } if (nextMove == M_EAST) { fprintf(stdout, "Avatar %d: Moved EAST from (%d, %d).\n", avatarID,\ avatar->pos.x, avatar->pos.y); } fprintf(stdout, "\n"); } send(sockfd, sendmsg, sizeof(AM_Message), 0); } } } } } shmctl(shmID, IPC_RMID, NULL); free(sendmsg); free(receivemsg); free(IP); free(avatar); fclose(logFile); close(sockfd); return 1; }
bool bgBezierPatchControlPointsGizmo::Initialize(bgActor* pActor, bgShaderFactory* ShaderFactory, cRenderer* pRenderer) { ASSERT(pActor != 0); bgGizmo::Initialize(pActor, ShaderFactory, pRenderer); pMapper = dynamic_cast<bgBezierPatchMapper*>(pActor->getInput()); if (pMapper == 0) return false; pMapper->Reset(); InitializeMarkList(); bgBezierPatchMapper::_ControlPointList& PatchList = pMapper->GetPatchControlPoints(); pGuideLine->getInput()->getInput()->initialize(); pGuideLine->initialize(); bgData* pData = pGuideLine->getInput()->getInput(); pData->initialize(); bgData::_PositionList& PositionList = pData->GetPositionList(); bgData::_ColorList& ColorList = pData->GetColorList(); bgData::_IndexList& IndexList = pData->GetIndexList(); bool bCreatedMode = MarkList.size() <= 0 ? true : false; CString message; int uSize = pMapper->GetUSize(); int vSize = pMapper->GetVSize(); for (int u = 0; u < uSize; u++) { for (int v = 0; v < vSize; v++) { glm::vec3 position = pMapper->FindControlPointPosition(u, v); PositionList.push_back(position.x); PositionList.push_back(position.y); PositionList.push_back(position.z); ColorList.push_back(1.0f); ColorList.push_back(0.0f); ColorList.push_back(0.0f); ControlPointIndex* indexInfo = pMapper->FindControlPointIndex(u, v); ASSERT(indexInfo != NULL); if (u == 0 || v == 0 || u == uSize - 1 || v == vSize - 1) indexInfo->bEdgePoint = true; else indexInfo->bEdgePoint = false; //CString message; //message.Format("position:%f,%f,%f \n", position.x, position.y, position.z); //OutputDebugString(message); if (bCreatedMode) AddMark(indexInfo, position, pRenderer); else ResetMark(indexInfo, position, pRenderer); } } for (int u = 0; u < uSize ; u++) { for (int v = 0; v < vSize-1; v++) { IndexList.push_back( u*vSize + v); IndexList.push_back( u*vSize + v+ 1); // message.Format("U Base Index :%d, %d\n", (u*vSize + v), (u*vSize + v + 1)); // OutputDebugString(message); } } for (int v = 0; v < vSize; v++) { for (int u = 0; u < uSize-1 ; u++) { IndexList.push_back(u*vSize + v); IndexList.push_back((u + 1)*vSize + v); // message.Format("V Base Index :%d, %d\n", (u*vSize + v), ( (u+1)*vSize + v) ); // OutputDebugString(message); } } pGuideLine->build(*pRenderer); return true; }