예제 #1
0
void Monster::state_Idle() {
	//sightEnemyTime
	self->SetAnimState(ANIMCHANNEL_LEGS,  "Legs_Sight", GUARDIAN_IDLE_TO_SIGHT);
	self->SetWaitState("sight");

	TransitionState(&STATE_IDLE);	
}
예제 #2
0
void Monster::Legs_Walk() {
	if (rightfoot) {
		self->Event_PlayAnim( ANIMCHANNEL_LEGS, "walk_right" );		
	} else {
		self->Event_PlayAnim( ANIMCHANNEL_LEGS, "walk_left" );		
	}

	TransitionState(&STATE_WALK);
}
예제 #3
0
void Monster::state_Killed() {
	self->AI_DEAD = true;
	self->Event_StopMove();
	self->SetAnimState(ANIMCHANNEL_LEGS, "Legs_Death", 0 );
	self->SetWaitState( "dead" );
	self->Event_StopThinking();	
	Legs_Death();

	TransitionState(&STATE_DEATH);
}
예제 #4
0
bool Monster::TickWalk() {
	if (self->AI_PAIN) {
		self->SetAnimState( ANIMCHANNEL_LEGS, "Legs_Pain", GUARDIAN_WALK_TO_PAIN );
	}
	if (!self->AI_FORWARD) {
		self->SetAnimState( ANIMCHANNEL_LEGS, "Legs_Idle", GUARDIAN_WALK_TO_IDLE );
	}

	if (self->Event_AnimDone(ANIMCHANNEL_LEGS, 0)) {
		/*if ( charge ) {
			animState( ANIMCHANNEL_LEGS, "Legs_Charge", GUARDIAN_WALK_TO_CHARGE );
		}*/
		rightfoot = !rightfoot;
		if (rightfoot) {
			self->Event_PlayAnim( ANIMCHANNEL_LEGS, "walk_right" );
		} else {
			self->Event_PlayAnim( ANIMCHANNEL_LEGS, "walk_left" );
		}
	}
	if (GetKeyDown('F'))
	{		
		//state_Killed();
		//self->Event_RealKill();
		//TransitionState(&STATE_DEATH);
		TransitionState(&STATE_PLAYANIM);
	}

	if (GetKeyDown('D'))
	{		
		//state_Killed();
		static int i =0;
		if (i & 2)
			self->Event_EnableWalkIK();
		else 
			self->Event_DisableWalkIK();
		i++;		
	}

	return true;
}
예제 #5
0
/**
 *----------------------------------------------------------------------------
 *
 * CloudInitSetup --
 *
 * Function which does the setup for cloud-init if it is enabled.
 * Essentially it copies
 * - nics.tx
 * - cust.cfg to a predefined location.
 *
 * @param   [IN]  imcDirPath Path where nics.txt and cust.cfg exist
 * @returns DEPLOYPKG_STATUS_CLOUD_INIT_DELEGATED on success
 *          DEPLOYPKG_STATUS_ERROR on error
 *
 *----------------------------------------------------------------------------
 * */
static DeployPkgStatus
CloudInitSetup(const char *imcDirPath)
{
   DeployPkgStatus deployPkgStatus = DEPLOYPKG_STATUS_ERROR;
   static const char *cloudInitTmpDirPath = "/var/run/vmware-imc";
   int forkExecResult;
   char command[1024];
   Bool cloudInitTmpDirCreated = FALSE;
   char* customScriptName = NULL;
   sLog(log_info, "Creating temp directory %s to copy customization files",
        cloudInitTmpDirPath);
   snprintf(command, sizeof(command),
            "/bin/mkdir -p %s", cloudInitTmpDirPath);
   command[sizeof(command) - 1] = '\0';

   forkExecResult = ForkExecAndWaitCommand(command, false);
   if (forkExecResult != 0) {
      SetDeployError("Error creating %s dir: %s",
                     cloudInitTmpDirPath,
                     strerror(errno));
      goto done;
   }

   cloudInitTmpDirCreated = TRUE;

   // Copy required files for cloud-init to a temp name initially and then
   // rename in order to avoid race conditions with partial writes.
   sLog(log_info, "Check if nics.txt exists. Copy if exists, skip otherwise");
   snprintf(command, sizeof(command),
            "/usr/bin/test -f %s/nics.txt", imcDirPath);
   command[sizeof(command) - 1] = '\0';

   forkExecResult = ForkExecAndWaitCommand(command, false);

   /*
    * /usr/bin/test -f returns 0 if the file exists
    * non zero is returned if the file does not exist.
    * We need to copy the nics.txt only if it exists.
    */
   if (forkExecResult == 0) {
      sLog(log_info, "nics.txt file exists. Copying..");
      if (!CopyFileToDirectory(imcDirPath, cloudInitTmpDirPath, "nics.txt")) {
         goto done;
       }
   }

   // Get custom script name.
   customScriptName = GetCustomScript(imcDirPath);
   if (customScriptName != NULL) {
      char scriptPath[1024];

      sLog(log_info, "Custom script present.");
      sLog(log_info, "Copying script to execute post customization.");
      snprintf(scriptPath, sizeof(scriptPath), "%s/scripts", imcDirPath);
      scriptPath[sizeof(scriptPath) - 1] = '\0';
      if (!CopyFileToDirectory(scriptPath, cloudInitTmpDirPath,
                               "post-customize-guest.sh")) {
         goto done;
      }

      sLog(log_info, "Copying user uploaded custom script %s",
           customScriptName);
      if (!CopyFileToDirectory(imcDirPath, cloudInitTmpDirPath,
                               customScriptName)) {
         goto done;
      }
   }

   sLog(log_info, "Copying main configuration file cust.cfg");
   if (!CopyFileToDirectory(imcDirPath, cloudInitTmpDirPath, "cust.cfg")) {
      goto done;
   }

   deployPkgStatus = DEPLOYPKG_STATUS_CLOUD_INIT_DELEGATED;

done:
   free(customScriptName);
   if (DEPLOYPKG_STATUS_CLOUD_INIT_DELEGATED == deployPkgStatus) {
      sLog(log_info, "Deployment for cloud-init succeeded.");
      TransitionState(INPROGRESS, DONE);
   } else {
      sLog(log_error, "Deployment for cloud-init failed.");
      if (cloudInitTmpDirCreated) {
         sLog(log_info, "Removing temporary folder %s", cloudInitTmpDirPath);
         snprintf(command, sizeof(command),
                  "/bin/rm -rf %s",
                  cloudInitTmpDirPath);
         command[sizeof(command) - 1] = '\0';
         ForkExecAndWaitCommand(command, false);
      }
      sLog(log_error, "Setting generic error status in vmx. \n");
      SetCustomizationStatusInVmx(TOOLSDEPLOYPKG_RUNNING,
                                  GUESTCUST_EVENT_CUSTOMIZE_FAILED,
                                  NULL);
      TransitionState(INPROGRESS, ERRORED);
   }

   return deployPkgStatus;
}
예제 #6
0
/**
 *
 * Core function which takes care of deployment in Linux.
 * Essentially it does
 * - uncabing of the cabinet
 * - execution of the command embedded in the cabinet header
 *
 * @param   [IN[  packageName  Package file to be used for deployment
 * @returns DEPLOYPKG_STATUS_SUCCESS on success
 *          DEPLOYPKG_STATUS_CLOUD_INIT_DELEGATED if customization task is
 *          delegated to cloud-init.
 *          DEPLOYPKG_STATUS_ERROR on error
 *
 **/
static DeployPkgStatus
Deploy(const char* packageName)
{
   DeployPkgStatus deployPkgStatus = DEPLOYPKG_STATUS_SUCCESS;
   char* pkgCommand = NULL;
   char* command = NULL;
   int deploymentResult = 0;
   char *nics;
   char* cleanupCommand;
   uint8 archiveType;
   uint8 flags;
   bool forceSkipReboot = false;
   const char *baseDirPath = NULL;
   char *imcDirPath = NULL;
   bool useCloudInitWorkflow = false;

   TransitionState(NULL, INPROGRESS);

   // Notify the vpx of customization in-progress state
   SetCustomizationStatusInVmx(TOOLSDEPLOYPKG_RUNNING,
                               TOOLSDEPLOYPKG_ERROR_SUCCESS,
                               NULL);

   // PR 2127543, Use /var/run or /run but /tmp firstly
   if (File_IsDirectory(VARRUNDIR)) {
      baseDirPath = VARRUNDIR;
   } else if (File_IsDirectory(RUNDIR)) {
      baseDirPath = RUNDIR;
   } else {
      baseDirPath = TMPDIR;
   }

   // Create a random name dir under base dir path
   imcDirPath = malloc(strlen(baseDirPath) + strlen(IMC_DIR_PATH_PATTERN) + 1);
   if (imcDirPath == NULL) {
      SetDeployError("Error allocating memory to create imc dir.");
      return DEPLOYPKG_STATUS_ERROR;
   }
   strcpy(imcDirPath, baseDirPath);
   strcat(imcDirPath, IMC_DIR_PATH_PATTERN);
   if (mkdtemp(imcDirPath) == NULL) {
      free(imcDirPath);
      SetDeployError("Error creating imc dir: %s", strerror(errno));
      return DEPLOYPKG_STATUS_ERROR;
   }

   sLog(log_info,
        "Reading cabinet file %s and will extract it to %s. \n",
         packageName,
         imcDirPath);

   // Get the command to execute
   if (!GetPackageInfo(packageName, &pkgCommand, &archiveType, &flags)) {
      SetDeployError("Error extracting package header information. (%s)",
                     GetDeployError());
      free(imcDirPath);
      return DEPLOYPKG_STATUS_CAB_ERROR;
   }

   sLog(log_info, "Flags in the header: %d\n", (int) flags);

   sLog(log_info, "Original deployment command: %s\n", pkgCommand);
   if (strstr(pkgCommand, IMC_TMP_PATH_VAR) != NULL) {
      command = StrUtil_ReplaceAll(pkgCommand, IMC_TMP_PATH_VAR, imcDirPath);
   } else {
      command = StrUtil_ReplaceAll(pkgCommand, TMP_PATH_VAR, imcDirPath);
   }
   free(pkgCommand);

   sLog(log_info, "Actual deployment command: %s\n", command);

   if (archiveType == VMWAREDEPLOYPKG_PAYLOAD_TYPE_CAB) {
      if (!ExtractCabPackage(packageName, imcDirPath)) {
         free(imcDirPath);
         free(command);
         return DEPLOYPKG_STATUS_CAB_ERROR;
      }
   } else if (archiveType == VMWAREDEPLOYPKG_PAYLOAD_TYPE_ZIP) {
      if (!ExtractZipPackage(packageName, imcDirPath)) {
         free(imcDirPath);
         free(command);
         return DEPLOYPKG_STATUS_CAB_ERROR;
      }
   }

   if (!(flags & VMWAREDEPLOYPKG_HEADER_FLAGS_IGNORE_CLOUD_INIT)) {
      useCloudInitWorkflow = UseCloudInitWorkflow(imcDirPath);
   } else {
      sLog(log_info, "Ignoring cloud-init.");
   }

   if (useCloudInitWorkflow) {
      sLog(log_info, "Executing cloud-init workflow");
      sSkipReboot = TRUE;
      free(command);
      deployPkgStatus = CloudInitSetup(imcDirPath);
   } else {
      sLog(log_info, "Executing traditional GOSC workflow");
      deploymentResult = ForkExecAndWaitCommand(command, false);
      free(command);

      if (deploymentResult != CUST_SUCCESS) {
         sLog(log_error, "Customization process returned with error. \n");
         sLog(log_debug, "Deployment result = %d \n", deploymentResult);

         if (deploymentResult == CUST_NETWORK_ERROR ||
             deploymentResult == CUST_NIC_ERROR ||
             deploymentResult == CUST_DNS_ERROR) {
            sLog(log_info, "Setting network error status in vmx. \n");
            SetCustomizationStatusInVmx(TOOLSDEPLOYPKG_RUNNING,
                                        GUESTCUST_EVENT_NETWORK_SETUP_FAILED,
                                        NULL);
         } else {
            sLog(log_info, "Setting %s error status in vmx. \n",
                 deploymentResult == CUST_GENERIC_ERROR ? "generic" : "unknown");
            SetCustomizationStatusInVmx(TOOLSDEPLOYPKG_RUNNING,
                                        GUESTCUST_EVENT_CUSTOMIZE_FAILED,
                                        NULL);
         }

         TransitionState(INPROGRESS, ERRORED);

         deployPkgStatus = DEPLOYPKG_STATUS_ERROR;
         SetDeployError("Deployment failed. "
                        "The forked off process returned error code.");
         sLog(log_error, "Deployment failed. "
                         "The forked off process returned error code. \n");
      } else {
         nics = GetNicsToEnable(imcDirPath);
         if (nics) {
            // XXX: Sleep before the last SetCustomizationStatusInVmx
            //      This is a temporary-hack for PR 422790
            sleep(5);
            sLog(log_info, "Wait before set enable-nics stats in vmx.\n");

            TryToEnableNics(nics);

            free(nics);
         } else {
            sLog(log_info, "No nics to enable.\n");
         }

         SetCustomizationStatusInVmx(TOOLSDEPLOYPKG_DONE,
                                     TOOLSDEPLOYPKG_ERROR_SUCCESS,
                                     NULL);

         TransitionState(INPROGRESS, DONE);

         deployPkgStatus = DEPLOYPKG_STATUS_SUCCESS;
         sLog(log_info, "Deployment succeeded. \n");
      }
   }

   cleanupCommand = malloc(strlen(CLEANUPCMD) + strlen(imcDirPath) + 1);
   if (!cleanupCommand) {
      SetDeployError("Error allocating memory.");
      free(imcDirPath);
      return DEPLOYPKG_STATUS_ERROR;
   }

   strcpy(cleanupCommand, CLEANUPCMD);
   strcat(cleanupCommand, imcDirPath);

   sLog(log_info, "Launching cleanup. \n");
   if (ForkExecAndWaitCommand(cleanupCommand, false) != 0) {
      sLog(log_warning, "Error while cleaning up imc directory %s: (%s)",
           imcDirPath, strerror (errno));
   }
   free (cleanupCommand);
   free(imcDirPath);

   if (flags & VMWAREDEPLOYPKG_HEADER_FLAGS_SKIP_REBOOT) {
      forceSkipReboot = true;
   }
   sLog(log_info,
        "sSkipReboot: %s, forceSkipReboot %s\n",
        sSkipReboot ? "true" : "false",
        forceSkipReboot ? "true" : "false");
   sSkipReboot |= forceSkipReboot;

   //Reset the guest OS
   if (!sSkipReboot && !deploymentResult) {
      pid_t pid = fork();
      if (pid == -1) {
         sLog(log_error, "Failed to fork: %s", strerror(errno));
      } else if (pid == 0) {
         // We're in the child

         // Repeatedly try to reboot to workaround PR 530641 where
         // telinit 6 is overwritten by a telinit 2
         int rebootComandResult = 0;
         do {
            sLog(log_info, "Rebooting\n");
            rebootComandResult = ForkExecAndWaitCommand("/sbin/telinit 6", false);
            sleep(1);
         } while (rebootComandResult == 0);
         sLog(log_error, "telinit returned error %d\n", rebootComandResult);

         exit (127);
      }
   }

   return deployPkgStatus;
}
예제 #7
0
void State::StartTransitionOut(float duration) {
    mTransitionState = TransitionState(TransitionState::OUT, duration, 0.f);
}
예제 #8
0
void State::StartTransitionIn(float duration) {
    mTransitionState = TransitionState(TransitionState::INTO, duration, 0.f);
}
예제 #9
0
// Call me once a frame!
void GPGMultiplayer::Update() {
  pthread_mutex_lock(&state_mutex_);  // unlocked in two places below
  if (!next_states_.empty()) {
    // Transition at most one state per frame.
    MultiplayerState next_state = next_states_.front();
    next_states_.pop();
    pthread_mutex_unlock(&state_mutex_);
    SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
                 "GPGMultiplayer: Exiting state %d to enter state %d", state(),
                 next_state);
    TransitionState(state(), next_state);
  } else {
    pthread_mutex_unlock(&state_mutex_);
  }

  // Now update based on what state we are in.
  switch (state()) {
    case kDiscovering: {
      pthread_mutex_lock(&instance_mutex_);
      bool has_discovered_instance = !discovered_instances_.empty();
      pthread_mutex_unlock(&instance_mutex_);

      if (has_discovered_instance) {
        QueueNextState(kDiscoveringPromptedUser);
      }
      break;
    }
    case kDiscoveringPromptedUser: {
      DialogResponse response = GetConnectionDialogResponse();
      if (response == kDialogNo) {
        // we decided not to connect to the first discovered instance.
        pthread_mutex_lock(&instance_mutex_);
        discovered_instances_.pop_front();
        pthread_mutex_unlock(&instance_mutex_);

        QueueNextState(kDiscovering);
      } else if (response == kDialogYes) {
        // We decided to try to connect to the first discovered instance.
        pthread_mutex_lock(&instance_mutex_);
        auto instance = discovered_instances_.front();
        discovered_instances_.pop_front();
        pthread_mutex_unlock(&instance_mutex_);

        SendConnectionRequest(instance);
        QueueNextState(kDiscoveringWaitingForHost);
      }
      // Otherwise we haven't gotten a response yet.
      break;
    }
    case kConnectedWithDisconnections: {
      pthread_mutex_lock(&instance_mutex_);
      bool has_disconnected_instance = !disconnected_instances_.empty();
      bool has_pending_instance = !pending_instances_.empty();
      pthread_mutex_unlock(&instance_mutex_);
      if (!has_disconnected_instance) {
        SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,
                     "GPGMultiplayer: No disconnected instances.");
        QueueNextState(kConnected);
      } else if (has_pending_instance) {
        // Check if the pending instance is one of the disconnected ones.
        // If so, and we still have room, connect him.
        // Otherwise, reject.

        pthread_mutex_lock(&instance_mutex_);
        auto i = disconnected_instances_.find(pending_instances_.front());
        bool is_reconnection = (i != disconnected_instances_.end());
        pthread_mutex_unlock(&instance_mutex_);

        if (!is_reconnection) {
          // Not a disconnected instance. Reject.
          RejectConnectionRequest(pending_instances_.front());
        } else if (max_connected_players_allowed() >= 0 &&
                   GetNumConnectedPlayers() >=
                       max_connected_players_allowed()) {
          // Too many players to allow us back. Reject. But we might be
          // allowed back again in the future.
          RejectConnectionRequest(pending_instances_.front());
        } else {
          // A valid reconnecting instance. Allow.
          AcceptConnectionRequest(pending_instances_.front());
        }
      }
      break;
    }
    case kAdvertising: {
      pthread_mutex_lock(&instance_mutex_);
      bool has_pending_instance = !pending_instances_.empty();
      pthread_mutex_unlock(&instance_mutex_);

      if (has_pending_instance) {
        if (max_connected_players_allowed() >= 0 &&
            GetNumConnectedPlayers() >= max_connected_players_allowed()) {
          // Already have a full game, auto-reject any additional players.
          RejectConnectionRequest(pending_instances_.front());
        } else {
          // Prompt the user to allow the connection.
          QueueNextState(kAdvertisingPromptedUser);
        }
      }
      break;
    }
    case kAdvertisingPromptedUser: {
      // check if we allowed connection
      int response = GetConnectionDialogResponse();
      if (response == 0) {
        // Reject removes the instance_id from pending
        pthread_mutex_lock(&instance_mutex_);
        auto instance = pending_instances_.front();
        pthread_mutex_unlock(&instance_mutex_);

        RejectConnectionRequest(instance);
        QueueNextState(kAdvertising);
      } else if (response == 1) {
        // Accept removes the instance_id from pending and adds it to connected
        pthread_mutex_lock(&instance_mutex_);
        auto instance = pending_instances_.front();
        pthread_mutex_unlock(&instance_mutex_);

        AcceptConnectionRequest(instance);
        QueueNextState(kAdvertising);
      }
      // Otherwise we haven't gotten a response yet.
      break;
    }
    default: {
      // no default behavior
      break;
    }
  }
}