// Stop this app container from running on these nodes (1+N redundancy)
void acRetract(const char* appCnt, const char* nodeNames[], int numNodes,const char* nameModifier)
{
  ClRcT rc;
  ClAmsEntityConfigT su;
  ClAmsEntityConfigT comp;
  char eName[SA_MAX_NAME_LENGTH];

  if (ccbHandle==CL_HANDLE_INVALID_VALUE) initHandles();

  strncpy(eName,appCnt,SA_MAX_NAME_LENGTH-1);
  eName[SA_MAX_NAME_LENGTH-1] = 0;
  if (nameModifier != NULL)
    {
      strncat(eName,nameModifier,SA_MAX_NAME_LENGTH-1);
      eName[SA_MAX_NAME_LENGTH-1] = 0;
    }

  
  for (int i=0;i<numNodes;i++)
    {
      initEntity(&su,eName,CL_AMS_ENTITY_TYPE_SU,nodeNames[i]);
      entityStop(su);
      initEntity(&comp,eName,CL_AMS_ENTITY_TYPE_COMP,nodeNames[i]);
      // comps are implicitly started/stopped when SU is
      //entityStop(comp);

      if ((rc = clAmsMgmtCCBEntityDelete(ccbHandle,&comp))  != CL_OK) checkError("Delete COMP",rc);
      if ((rc = clAmsMgmtCCBEntityDelete(ccbHandle,&su))  != CL_OK) checkError("Delete SU",rc);      
    }

  if ((rc = clAmsMgmtCCBCommit(ccbHandle) ) != CL_OK) checkError("Committing deletion of COMP/SU", rc);
}
예제 #2
0
 /**
  * @brief Relation::Relation
  * @param relation
  * @param from
  * @param to
  * @param parent
  */
 Relation::Relation(const relationship::SharedRelation &relation, const EntityPtr &from,
                    const EntityPtr &to, QGraphicsItem *parent)
     : QGraphicsLineItem(parent)
     , m_Relation(relation)
     , m_From(from)
     , m_To(to)
 {
     initEntity(m_From);
     initEntity(m_To);
 }
예제 #3
0
void
resurrectPlayer(PlayState *playState, GameContext *gameContext, Entity *entity) {
    initEntity(entity);
    --playState->currentLives;
    entity->position = entity->initialPosition + gameContext->cameraPosition;
    entity->invulnerableCounter = entity->invulnerableTime;
}
void removeNode(const char* safName)
{
  ClRcT rc;
  ClAmsEntityConfigT entity;

  if (ccbHandle==CL_HANDLE_INVALID_VALUE) initHandles();
  initEntity(&entity,safName,CL_AMS_ENTITY_TYPE_NODE);

  entityStop(entity);

  ClCpmSlotInfoT slotInfo;  
  saNameSet(&slotInfo.nodeName,safName);
  if ((rc = clCpmSlotGet(CL_CPM_NODENAME, &slotInfo))  != CL_OK) checkError("Get node address",rc);
  
  if ((rc = clCpmNodeShutDown(slotInfo.nodeIocAddress))  != CL_OK) checkError("shutdown ASP on node",rc);

  ClAmsNodeStatusT* ns;

  bool done = false;
  do
    {
      ns = clAmsMgmtNodeGetStatus( mgmtHandle ,safName);
      sleep(1);
      if (!ns) done = true;
      else
        {
          if (ns->isClusterMember == CL_AMS_NODE_IS_NOT_CLUSTER_MEMBER) done=true;
          clHeapFree(ns);
        }
    } while (!done);

  if ((rc = clAmsMgmtCCBEntityDelete(ccbHandle,&entity))  != CL_OK) checkError("Delete node",rc);      
  if ((rc = clAmsMgmtCCBCommit(ccbHandle) ) != CL_OK) checkError("Committing deletion of node", rc);
}
예제 #5
0
void
addEnemyBullet(PlayState *playState, GameMemory *gameMemory, V2D position, V2D velocity) {

    EntityNode *bullet = playState->freeEntities;

    if (bullet) {
        playState->freeEntities = bullet->next;
    } else {
        bullet = RESERVE_MEMORY(&gameMemory->permanentMemory, EntityNode);
    }

    bullet->next = playState->entityList;

    playState->entityList = bullet;

    bullet->entity = {ENEMY_BULLET_TYPE,
                      position,
    {playState->bullet2Texture, 16, 16, 1},
    velocity
                     };

    initEntity(&bullet->entity);

    assert(bullet != bullet->next);
}
void nodeStop(const char* nodeName)
{
  ClAmsEntityConfigT n;

  initEntity(&n,nodeName,CL_AMS_ENTITY_TYPE_NODE);  
  entityStop(n);  
}
void acStop(const char* name)
{
  ClAmsEntityConfigT n;

  initEntity(&n,name,CL_AMS_ENTITY_TYPE_SG);  
  entityStop(n);  
}
예제 #8
0
파일: Test.cpp 프로젝트: prodongi/Bread
bool cTest::initialize()
{
	if (!initEntity())
		return false;

	return true;
}
예제 #9
0
파일: Ennemi.cpp 프로젝트: dwarfman78/tanks
//int cpt2=1;
Ennemi::Ennemi(se::Application& application, Plateau& p) :
    unregistered(false),
    myPlateau(p),
    myApplication(application),
    gen(time(NULL)),
    dis(10,30)
{
    initEntity(application);
}
예제 #10
0
파일: init.c 프로젝트: Gigaraptor/LD33
entity *loadMachineGun(unitData *mGData, int side, baseEntity *mGTex, int *success, options *opt)
{
	entity *temp = initEntity(mGData->ID, side, *mGTex, *mGTex, success, opt);
	temp->cost = mGData->cost;
	temp->isAnimated = SUCCESS;
	temp->speed = mGData->speed;
	temp->frame.x = INVALID_RECT;
	temp->angle = 90;
	return temp;
}
예제 #11
0
파일: init.c 프로젝트: Gigaraptor/LD33
entity *initTitle(baseEntity animation, int *success, options *opt)
{
	entity *temp;
	temp = initEntity(TITLE, NO_SIDE, animation, animation, success, opt);
	temp->posAndHitbox.y = (opt->SCREEN_HEIGHT / 5);
	temp->posAndHitbox.x = (opt->SCREEN_WIDTH / 3);
	

	return temp;
}
예제 #12
0
    void Relation::setEntity(EntityPtr &e, const EntityPtr &newEntity)
    {
        if (e) {
            G_DISCONNECT(e.data(), &Entity::positionChanged, this, &Relation::recalculateLine);
            G_DISCONNECT(e.data(), &Entity::sizeChanged, this, &Relation::recalculateLine);
        }

        e = newEntity;
        initEntity(e);
    }
예제 #13
0
/**
 * @brief modifyEntityInUse Définie l'emplacement de l'entité comme libre:
 * en cas d'ajout d'une nouvelle entité cette dernière pourra être placé dans cet emplacement.
 * mBitSetComponent est remis à 0.
 * @param bInUse La nouvelle valeur à associé à mbEntityInUse
 */
void Entity::modifyEntityInUse( bool bInUse ){
    if( ! bInUse ){
        reinitComponentBitSet();
        mbEntityInUse = bInUse;
        mbActive = false;
    }
    else {
        initEntity();
    }
}
    // Remove an application from this container.
    // The effect of this is to delete the SAF Service Instance that represents this
    // application
void acRemoveApp(const char* appCnt, const char* appName)
{
  ClRcT rc;
  //ClAmsEntityConfigT sg;
  ClAmsEntityConfigT si;
  ClAmsEntityConfigT csi;
  
  if (ccbHandle==CL_HANDLE_INVALID_VALUE) initHandles();
  //initEntity(&sg,appCnt,CL_AMS_ENTITY_TYPE_SG);
  initEntity(&si,appName,CL_AMS_ENTITY_TYPE_SI);
  initEntity(&csi,appName,CL_AMS_ENTITY_TYPE_CSI);

  entityStop(si);
  entityStop(csi);
  
  if ((rc = clAmsMgmtCCBEntityDelete(ccbHandle,&csi))  != CL_OK) checkError("Delete CSI",rc);
  if ((rc = clAmsMgmtCCBEntityDelete(ccbHandle,&si))  != CL_OK) checkError("Delete SI",rc);      
  if ((rc = clAmsMgmtCCBCommit(ccbHandle) ) != CL_OK) checkError("Committing deletion of SI/CSI", rc);
}
예제 #15
0
void ChunkBase::activateEntity()
{
	if (mSceneAttached) return;

	if (mChunkScene == 0) initEntity();

	if (isEmpty) return;

	Ogre::SceneNode& parentScene = mLevel.getChunkScene();
	parentScene.addChild(mChunkScene);
	mSceneAttached = true;
}
    // Stop this app container from running on these nodes (1+N redundancy)
void acRetract(const char* appCnt, const char* nodeName,const char* compName)
{
  ClRcT rc;
  ClAmsEntityConfigT su;
  ClAmsEntityConfigT comp;

  if (ccbHandle==CL_HANDLE_INVALID_VALUE) initHandles();
  
  if (1)
    {
      initEntity(&su,compName,CL_AMS_ENTITY_TYPE_SU);
      entityStop(su);
      initEntity(&comp,compName,CL_AMS_ENTITY_TYPE_COMP);
      // Comps are implicitly stopped when SU is stopped
      //entityStop(comp);

      if ((rc = clAmsMgmtCCBEntityDelete(ccbHandle,&comp))  != CL_OK) checkError("Delete COMP",rc);
      if ((rc = clAmsMgmtCCBEntityDelete(ccbHandle,&su))  != CL_OK) checkError("Delete SU",rc);      
    }

  if ((rc = clAmsMgmtCCBCommit(ccbHandle) ) != CL_OK) checkError("Committing deletion of COMP/SU", rc);
}
void removeAppCnt(const char* name)
{
  ClRcT rc;
  ClAmsEntityConfigT sg;

  // Create the SG object
  if (ccbHandle==CL_HANDLE_INVALID_VALUE) initHandles();
  initEntity(&sg,name,CL_AMS_ENTITY_TYPE_SG);
  entityStop(sg);
    
  if ((rc = clAmsMgmtCCBEntityDelete(ccbHandle,&sg))  != CL_OK) checkError("Delete SG",rc);
  if ((rc = clAmsMgmtCCBCommit(ccbHandle) ) != CL_OK) checkError("Committing deletion of SG", rc);
}
예제 #18
0
void ChunkBase::update(bool force)
{
	if (force) {
		mIsModified = true;
	}

	if (mIsModified) {
		initEntity();

		if (isEmpty) return;

		initPhysicsBody();
		activateEntity();
		activatePhysicsBody();
	}
}
예제 #19
0
파일: init.c 프로젝트: Gigaraptor/LD33
void newShells(soldiers *army, options *opt, entity *unitType,int *success, Mix_Chunk **sound, int partOfScreen)
{
	army->men = realloc(army->men, (opt->ARTILLERY_BARRAGE + army->no_men) * sizeof(entity *));
	int looper, new_size, start, yCoord, xCoord;
	baseEntity temp;
	temp.tex = unitType->liveAnimation;
	temp.dimensions = unitType->posAndHitbox;
	start = army->no_men; //end of the array
	new_size = army->no_men + opt->ARTILLERY_BARRAGE;
	for(looper = start; looper < new_size; looper++)
	{	if(partOfScreen == BRITISH)
		{
			xCoord = rand() % opt->SCREEN_WIDTH / 2;
			yCoord = rand() % opt->SCREEN_HEIGHT;
		}
		if(partOfScreen == GERMAN)
		{
			xCoord = rand() % opt->SCREEN_WIDTH / 2 + (opt->SCREEN_WIDTH / 2);
			yCoord = rand() % opt->SCREEN_HEIGHT;
		}
		army->men[looper] = initEntity(unitType->type, unitType->side, temp, temp, success, opt);
		army->men[looper]->posAndHitbox.y = yCoord;
		army->men[looper]->posAndHitbox.x = xCoord;
		army->men[looper]->posAndHitbox.w *= (opt->ARTILLERY_SCALE_FACTOR / opt->SCALE_FACTOR);
		army->men[looper]->posAndHitbox.h *= (opt->ARTILLERY_SCALE_FACTOR / opt->SCALE_FACTOR);
		army->men[looper]->frame.x = 0;
		army->men[looper]->frame.w = 64;
		army->men[looper]->frame.h = 64;
		army->men[looper]->entranceSound = unitType->entranceSound;
		army->men[looper]->deathSound = unitType->entranceSound;
		army->men[looper]->isAnimated = SUCCESS;
		army->men[looper]->speed = unitType->speed;
		army->men[looper]->side = unitType->side;
		army->men[looper]->angle = 0;
		
	
		
	}
	
	Mix_PlayChannel(1,army->men[looper -1]->entranceSound,0);

	army->no_men = new_size;

}
// Create a new Node in the AMF
void addNode(const char* safName)
{
  ClRcT rc;
  ClAmsEntityConfigT entity;

  if (ccbHandle==CL_HANDLE_INVALID_VALUE) initHandles();
  initEntity(&entity,safName,CL_AMS_ENTITY_TYPE_NODE);
  

  if ((rc = clAmsMgmtCCBEntityCreate(ccbHandle,&entity)) != CL_OK)
    {
      checkError("Create node",rc);
    }
  
  
  if ((rc = clAmsMgmtCCBCommit(ccbHandle)) != CL_OK)
    {
      checkError("Commit create node",rc);
    }

  entityStart(entity);  
}
예제 #21
0
void
addEnemy(PlayState *playState, GameContext *gameContext, GameMemory *gameMemory) {

    EntityNode* enemy = playState->freeEntities;

    if (enemy) {
        playState->freeEntities = enemy->next;
    } else {
        enemy = RESERVE_MEMORY(&gameMemory->permanentMemory, EntityNode);
    }

    enemy->next = playState->enemies;

    playState->enemies = enemy;

    int yPos = rand() % (gameContext->gameHeight / 2);
    playState->enemies->entity = {GLIDER_TYPE, {600, (float) yPos},
        {playState->gliderTexture, 38, 34, 1}
    };

    initEntity(&enemy->entity);

    assert(enemy != enemy->next);
}
예제 #22
0
bool
startGame(PlayState *playState, GameContext *gameContext, SDL_Renderer *renderer, GameMemory *gameMemory) {

    gameContext->cameraPosition = {-gameContext->scrollSpeed, 0};

    if (playState->scrollingBackground) {
        freeMemory(&gameMemory->longTimeMemory, playState->scrollingBackground);
        playState->scrollingBackground = 0;
    }

    for (EntityNode **entityNode = &playState->entityList; *entityNode;) {

        EntityNode *freeEntity = *entityNode;

        // NOTE: must modify the pointer itself
        *entityNode = (*entityNode)->next;

        freeEntity->next = playState->freeEntities;
        playState->freeEntities = freeEntity;
        assert((*entityNode == 0) || (*entityNode != (*entityNode)->next));
    }

    TileMap *tileMap = RESERVE_MEMORY(&gameMemory->shortTimeMemory, TileMap);
    *tileMap = {};

    if (!loadTileMap(tileMap, "map1.tmx", gameContext, renderer, gameMemory, &playState->freeEntities)) {
        return false;
    }
    playState->tileMapWidth = tileMap->width * tileMap->tileWidth;
    playState->scrollingBackground = tileMap->scrollingBackground;
    playState->entityList = tileMap->entityList;
    playState->player = 0;
    for (EntityNode *entityNode = playState->entityList; entityNode; entityNode = entityNode->next) {
        if (entityNode->entity.type == PLAYER_TYPE) {
            playState->player = &entityNode->entity;
            break;
        }
    }
    if (!playState->player) {
        return false;
    }

    playState->liveTexture = getTexture("LIVES", gameContext);
    if (!playState->liveTexture) {
        return false;
    }
    playState->bullet1Texture = getTexture("BULLET1", gameContext);
    if (!playState->bullet1Texture) {
        return false;
    }
    playState->bullet2Texture = getTexture("BULLET2", gameContext);
    if (!playState->bullet2Texture) {
        return false;
    }
    playState->smallExplosionTexture = getTexture("SMALL_EXPLOSION", gameContext);
    if (!playState->smallExplosionTexture) {
        return false;
    }
    playState->explosionTexture = getTexture("EXPLOSION", gameContext);
    if (!playState->explosionTexture) {
        return false;
    }
    playState->largeExplosionTexture = getTexture("LARGE_EXPLOSION", gameContext);
    if (!playState->largeExplosionTexture) {
        return false;
    }
    playState->bossExplosionTexture = getTexture("BOSS_EXPLOSION", gameContext);
    if (!playState->bossExplosionTexture) {
        return false;
    }

    for (EntityNode *node = playState->entityList; node; node = node->next) {
        initEntity(&node->entity);
    }

    playState->currentLives = 3;

    return true;
}
예제 #23
0
/**
 * @brief Entity::Entity
 * @param uiIdEntity L'identifiant à attribuer à la nouvelle entité.
 */
Entity::Entity( unsigned int uiIdEntity ):mBitSetComponent(std::vector< bool >( ComponentManager::getNumberComponent() ) ),
	mUiIDEntity( uiIdEntity )
{
    initEntity();
}
예제 #24
0
/**
 * @brief Entity::Entity Constructeur de la classe Engine.
 */
Entity::Entity():mBitSetComponent(std::vector< bool >( ComponentManager::getNumberComponent() ) )
{
    initEntity();
}
예제 #25
0
파일: init.c 프로젝트: Gigaraptor/LD33
void newSquad(soldiers *army, options *opt, entity *unitType, baseEntity **corpses, int *success, Mix_Chunk **deathsounds)
{
	
	int looper, new_size, start, corpse, yCoord, deathSound,noWithoutRealloc;
	baseEntity temp;
	temp.tex = unitType->liveAnimation;
	temp.dimensions = unitType->posAndHitbox;
	start = army->no_men; //end of the array
	new_size = army->no_men + opt->SQUAD_SIZE;
	noWithoutRealloc = 0;
	for(looper = 0; looper < army->no_men ; looper++)
	{
		if(army->men[looper]->posAndHitbox.x < 0 - opt->QUIT_OFFSET || army->men[looper]->posAndHitbox.x > opt->SCREEN_WIDTH + opt->QUIT_OFFSET  || army->men[looper]->posAndHitbox.y < 0 - opt->QUIT_OFFSET  || army->men[looper]->posAndHitbox.y > opt->SCREEN_HEIGHT  + opt->QUIT_OFFSET )
		{
			army->men[looper]->isAnimated = FAIL;
		
		}
		if(army->men[looper]->isAnimated == FAIL && noWithoutRealloc < opt->SQUAD_SIZE && army->men[looper]->type < 6 && opt->MAX_ARMY_SIZE < new_size)
		{
			corpse = rand() % opt->NO_CORPSES;
			yCoord = rand () % opt->SCREEN_HEIGHT;
			deathSound = rand() % 6;
			army->men[looper] = initEntity(unitType->type, unitType->side, temp, *(corpses[corpse]), success, opt);
			if(unitType->side == GERMAN)
			{
				army->men[looper]->angle = 90;
				army->men[looper]->posAndHitbox.x = opt->OTHER_OFFSET;
			}
			else
			{
				army->men[looper]->angle = 270;
				army->men[looper]->posAndHitbox.x = opt->SCREEN_WIDTH - opt->OTHER_OFFSET;
			}
			army->men[looper]->posAndHitbox.y = yCoord;
			army->men[looper]->entranceSound = unitType->entranceSound;
			army->men[looper]->frame.w = 64;
			army->men[looper]->frame.h = 64;
			army->men[looper]->frame.x = 0;
			army->men[looper]->frame.y = 0;
			army->men[looper]->deathSound = deathsounds[deathSound];
			army->men[looper]->isAnimated = SUCCESS;
			army->men[looper]->speed = unitType->speed;
			army->men[looper]->side = unitType->side;
			army->men[looper]->anim = 0;
			army->men[looper]->scored = FAIL;
			noWithoutRealloc++;
		
		}
	
	}
	Mix_PlayChannel(-1,army->men[looper -1]->entranceSound,0);
	if(noWithoutRealloc >= opt->SQUAD_SIZE)//cancels if there are enough dead to make new squads
	{
			return;
	}
	if(opt->MAX_ARMY_SIZE < new_size)//stops bodies + soldiers > 1000
	{
			return;
	}
	
	army->men = realloc(army->men, (opt->SQUAD_SIZE + army->no_men - noWithoutRealloc) * sizeof(entity *));
	new_size = army->no_men + opt->SQUAD_SIZE - noWithoutRealloc;
	for(looper = start; looper < new_size; looper++)
	{

		corpse = rand() % opt->NO_CORPSES;
		yCoord = rand () % opt->SCREEN_HEIGHT;
		deathSound = rand() % 6;
		army->men[looper] = initEntity(unitType->type, unitType->side, temp, *(corpses[corpse]), success, opt);
		if(unitType->side == GERMAN)
		{
			army->men[looper]->angle = 90;
			army->men[looper]->posAndHitbox.x = opt->OTHER_OFFSET;
		}
		else
		{
			army->men[looper]->angle = 270;
			army->men[looper]->posAndHitbox.x = opt->SCREEN_WIDTH - opt->OTHER_OFFSET;
		}
		army->men[looper]->posAndHitbox.y = yCoord;
		army->men[looper]->entranceSound = unitType->entranceSound;
		army->men[looper]->frame.w = 64;
		army->men[looper]->frame.h = 64;
		army->men[looper]->frame.x = 0;
		army->men[looper]->frame.y = 0;
		army->men[looper]->deathSound = deathsounds[deathSound];
		army->men[looper]->isAnimated = SUCCESS;
		army->men[looper]->speed = unitType->speed;
		army->men[looper]->side = unitType->side;
		army->men[looper]->anim = 0;
		army->men[looper]->scored = FAIL;
		
	
		
	}
	
	
	
	army->no_men = new_size;

}
// Start this app container running on these nodes (1+N redundancy).  This will
// start a SAF-aware process on each node specified.
// Create SU and Comp
void acExtend(const char* appCnt, const char* nodeName, const char* compName,SafConfig* cfg)
{
  ClRcT rc;
  ClAmsEntityConfigT  sg;
  ClAmsEntityConfigT  comp;
  ClAmsEntityConfigT su;
  ClUint64T           changeMask = 0;
  
  ClAmsSGConfigT      sgConfig;
  ClAmsEntityConfigT* pEntityConfig = NULL;

  if (ccbHandle==CL_HANDLE_INVALID_VALUE) initHandles();
  initEntity(&sg,appCnt,CL_AMS_ENTITY_TYPE_SG);
  
    
  if ((rc = clAmsMgmtEntityGetConfig(mgmtHandle,&sg,&pEntityConfig)) != CL_OK)
    {
      checkError("Get SG configuration", rc);
    }

  memcpy(&sgConfig, pEntityConfig, sizeof(sgConfig));
  clHeapFree(pEntityConfig);

  //Fix bug: recovery policy
  if (cfg && cfg->compRestartCountMax > 0 && cfg->compRestartDuration > 0)
    {
      sgConfig.compRestartCountMax = cfg->compRestartCountMax;
      sgConfig.compRestartDuration = cfg->compRestartDuration;
      changeMask |= SG_CONFIG_COMP_RESTART_DURATION | SG_CONFIG_COMP_RESTART_COUNT_MAX;
      if ((rc = clAmsMgmtCCBEntitySetConfig(ccbHandle,&sgConfig.entity,changeMask) ) != CL_OK)
        {
          checkError("Set SG config", rc);
        }
    }
  
  // Create SU and component per node
  if (1)
    {
      initEntity(&su,compName,CL_AMS_ENTITY_TYPE_SU);
      if ((rc = clAmsMgmtCCBEntityCreate(ccbHandle,&su)) != CL_OK)
        {
          checkError("Create SU", rc);
        }
      
      initEntity(&comp,compName,CL_AMS_ENTITY_TYPE_COMP);
      if ((rc = clAmsMgmtCCBEntityCreate(ccbHandle,&comp)) != CL_OK)
        {
          checkError("Create Comp", rc);
        }     
      
    }
  
  if ((rc = clAmsMgmtCCBCommit(ccbHandle)) != CL_OK)
    {
      checkError("Commit creation of SU and Component", rc);
    }

  SaNameT            supportedCSIType;

  saNameSet(&supportedCSIType, CSI_TYPE_APP);
  supportedCSIType.length += 1;

  // Configure components
  if (1)
    {
      ClAmsCompConfigT   compConfig;
      ClUint64T          bitMask = 0;
      
      if ((rc = clAmsMgmtEntityGetConfig(mgmtHandle,&comp,&pEntityConfig)) != CL_OK)
        {
          checkError("Retrieve component config", rc);
        }
      memcpy(&compConfig, pEntityConfig, sizeof(compConfig));
      clHeapFree(pEntityConfig);

      bitMask |= COMP_CONFIG_CAPABILITY_MODEL | COMP_CONFIG_TIMEOUTS;

      compConfig.capabilityModel = CL_AMS_COMP_CAP_X_ACTIVE_OR_Y_STANDBY;
      compConfig.timeouts.instantiate = 30000;
      compConfig.timeouts.terminate = 30000;
      compConfig.timeouts.cleanup = 30000;
      compConfig.timeouts.quiescingComplete = 30000;
      compConfig.timeouts.csiSet = 30000;
      compConfig.timeouts.csiRemove = 30000;
      compConfig.timeouts.instantiateDelay = 1000;
      if (!strncmp(nodeName, "sc", 2))
        {    	  
      	  if (cfg && cfg->compRestartCountMax == 0)
      	  {
      		  bitMask |= COMP_CONFIG_IS_RESTARTABLE | COMP_CONFIG_RECOVERY_ON_TIMEOUT;
      		  compConfig.isRestartable = false;
      		  compConfig.recoveryOnTimeout = CL_AMS_RECOVERY_NODE_FAILOVER;	     
      	  }    		
      	  else
      	  {    			      	 
      		  bitMask  |= COMP_CONFIG_RECOVERY_ON_TIMEOUT;
      		  compConfig.recoveryOnTimeout = CL_AMS_RECOVERY_NO_RECOMMENDATION;	      	 
      	  }
        }
        else
        {
      	  if (cfg && cfg->compRestartCountMax == 0)
      	  {
      		  bitMask |= COMP_CONFIG_IS_RESTARTABLE | COMP_CONFIG_RECOVERY_ON_TIMEOUT;
      		  compConfig.isRestartable = false;
      		  compConfig.recoveryOnTimeout = CL_AMS_RECOVERY_COMP_FAILOVER;	     
      	  }    		
      	  else
      	  {    			      	 
      		  bitMask  |= COMP_CONFIG_RECOVERY_ON_TIMEOUT;
      		  compConfig.recoveryOnTimeout = CL_AMS_RECOVERY_NO_RECOMMENDATION;	      	 
      	  }
        }

      if ((rc = clAmsMgmtCCBEntitySetConfig(ccbHandle,&compConfig.entity,bitMask) ) != CL_OK)
        {
        checkError("Set component config", rc);
        }
      
      bitMask = COMP_CONFIG_INSTANTIATE_COMMAND;
      if (cfg&&cfg->binName)
        {
        snprintf(compConfig.instantiateCommand, sizeof(compConfig.instantiateCommand), cfg->binName);
        }
      else
        {
        snprintf(compConfig.instantiateCommand, sizeof(compConfig.instantiateCommand), APP_CNT_CMD);
        }
            
      if ((rc = clAmsMgmtCCBEntitySetConfig(ccbHandle,&compConfig.entity,bitMask) ) != CL_OK)
        {
        checkError("Set component instantiate command", rc);          
        }      
    }  

  if ((rc = clAmsMgmtCCBCommit(ccbHandle)) != CL_OK)
    {
      checkError("Commit configure of components", rc);
    }

    // Configure components
  if (1)
    {
      ClAmsCompConfigT   compConfig;
      ClUint64T          bitMask = 0;
      

      if ((rc = clAmsMgmtEntityGetConfig(mgmtHandle,&comp,&pEntityConfig)) != CL_OK)
        {
          checkError("Retrieve component config", rc);
        }
      memcpy(&compConfig, pEntityConfig, sizeof(compConfig));
      clHeapFree(pEntityConfig);

      bitMask |= COMP_CONFIG_SUPPORTED_CSI_TYPE | COMP_CONFIG_NUM_MAX_ACTIVE_CSIS | COMP_CONFIG_NUM_MAX_STANDBY_CSIS;

      if(compConfig.pSupportedCSITypes)
        clHeapFree(compConfig.pSupportedCSITypes);
            
      compConfig.numSupportedCSITypes = 1;
      compConfig.pSupportedCSITypes   = &supportedCSIType;
      compConfig.numMaxActiveCSIs     = 10000;
      compConfig.numMaxStandbyCSIs    = 10000;
      
      if ((rc = clAmsMgmtCCBEntitySetConfig(ccbHandle,&compConfig.entity,bitMask) ) != CL_OK)
        {
          checkError("Setting supported CSI types", rc);
        }            
    }  

  if ((rc = clAmsMgmtCCBCommit(ccbHandle)) != CL_OK)
    {
      checkError("Configuring components supported CSI type", rc);
    }

  
  // Configure SUs
  if (1)
    {
      ClUint64T bitMask = 0;
      ClAmsSUConfigT suConfig;

      if ((rc = clAmsMgmtEntityGetConfig(mgmtHandle,&su,&pEntityConfig)) != CL_OK)
        {
          checkError("Get SU", rc);
        }
      
      memcpy(&suConfig, pEntityConfig, sizeof(suConfig));
      clHeapFree(pEntityConfig);

      bitMask |= SU_CONFIG_NUM_COMPONENTS |  SU_CONFIG_ADMIN_STATE;
      // set number of components (processes) per SU to 1
      suConfig.numComponents = 1;
      //suConfig.adminState = CL_AMS_ADMIN_STATE_UNLOCKED;
      suConfig.adminState = CL_AMS_ADMIN_STATE_LOCKED_I;      

      if ((rc = clAmsMgmtCCBEntitySetConfig(ccbHandle,&suConfig.entity,bitMask)) != CL_OK)
        {
           checkError("Configure SU", rc);
         
        }
      // attach the comp to the su
      if ((rc = clAmsMgmtCCBSetSUCompList(ccbHandle,&su,&comp)) != CL_OK)
        {
          checkError("Link COMP to SU", rc);          
        }      
    }

  if ((rc = clAmsMgmtCCBCommit(ccbHandle)) != CL_OK)
    {
      checkError("Commit SU configuration", rc);          
    }

  
  // Add the SU to SG's and Node's list
  if (1)
    {
      ClAmsEntityConfigT node;
      initEntity(&node,nodeName,CL_AMS_ENTITY_TYPE_NODE);

      if ((rc = clAmsMgmtCCBSetSGSUList(ccbHandle,&sg,&su)) != CL_OK)
        {
          checkError("Add SU to SG", rc);
        }

      if ((rc = clAmsMgmtCCBSetNodeSUList(ccbHandle,&node,&su)) != CL_OK)
        {
          checkError("Add SU to Node", rc);
        }

      /*
      if ((rc = clAmsMgmtCCBCommit(ccbHandle) ) != CL_OK)
        {
          checkError("Committing addition of SU to node and SG", rc);
        }
      */

      if ((rc = clAmsMgmtCCBCommit(ccbHandle) ) != CL_OK)
        {
          checkError("Committing addition of SU to node and SG", rc);
        }  
    }

  // Now that all is configured, start them up
  entityStart(su);
}
예제 #27
0
파일: init.c 프로젝트: Gigaraptor/LD33
void newBullets(soldiers *army, options *opt, entity *unitType,int *success, Mix_Chunk **sounds, int number, entity *mg, int op, int adj)
{
	
	
	
	
	int looper, new_size, start, corpse, yCoord, deathSound, holdTime, noWithoutRealloc;
	mg->startTime = SDL_GetTicks();
	mg->shotTime = mg->startTime - mg->endTime;
	noWithoutRealloc = 0;
	baseEntity temp;
	temp.tex = unitType->liveAnimation;
	temp.dimensions = unitType->posAndHitbox;
	start = army->no_men; //end of the array
	new_size = army->no_men + number;
	if(mg->shotTime < opt->ROF )
	{
		
		return;
	}
	for(looper = 0; looper < army->no_men; looper++)//MUCH MUCH FASTER NOW
	{
		if(army->men[looper]->posAndHitbox.x < 0 || army->men[looper]->posAndHitbox.x > opt->SCREEN_WIDTH || army->men[looper]->posAndHitbox.y < 0 || army->men[looper]->posAndHitbox.y > opt->SCREEN_HEIGHT)
		{
			army->men[looper]->isAnimated = FAIL;
		
		}
		if(army->men[looper]->isAnimated == FAIL && noWithoutRealloc < number)
		{
			noWithoutRealloc++;
			army->men[looper] = initEntity(unitType->type, unitType->side, temp, temp, success, opt);
			army->men[looper]->posAndHitbox.y = mg->posAndHitbox.y;
			army->men[looper]->posAndHitbox.x = mg->posAndHitbox.x;
			army->men[looper]->frame.x = INVALID_RECT;
			army->men[looper]->entranceSound = unitType->entranceSound;
			army->men[looper]->deathSound = unitType->entranceSound;
			army->men[looper]->isAnimated = SUCCESS;
			army->men[looper]->speed = unitType->speed;
			army->men[looper]->side = unitType->side;
			army->men[looper]->adj = adj;
			army->men[looper]->op = op;
			army->men[looper]->angle = 0;
		
		}
	
	
	}
	if(mg->side == BRITISH)
	{
		Mix_PlayChannel(1,sounds[1],0);
	}
	if(mg->side == GERMAN)
	{
		Mix_PlayChannel(1,sounds[2],0);
	}
	if( noWithoutRealloc >= number)//means that unneccessary memory isn't alloced
	{	
		return;
	}
	army->men = realloc(army->men, (number + army->no_men - noWithoutRealloc) * sizeof(entity *));//should limit bullets
	

	for(looper = start; looper < new_size; looper++)
	{

		army->men[looper] = initEntity(unitType->type, unitType->side, temp, temp, success, opt);
		army->men[looper]->posAndHitbox.y = mg->posAndHitbox.y;
		army->men[looper]->posAndHitbox.x = mg->posAndHitbox.x;
		army->men[looper]->frame.x = INVALID_RECT;
		army->men[looper]->entranceSound = unitType->entranceSound;
		army->men[looper]->deathSound = unitType->entranceSound;
		army->men[looper]->isAnimated = SUCCESS;
		army->men[looper]->speed = unitType->speed;
		army->men[looper]->side = unitType->side;
		army->men[looper]->adj = adj;
		army->men[looper]->op = op;
		army->men[looper]->angle = 0;
			
	
		
	}

	mg->endTime = SDL_GetTicks();
	army->no_men = new_size;

}
    // Add an application to this app container.
    // The effect of this is to create a new SAF Service Instance (SI) and CSI
    // This SI will be assigned to the SG and therefore a process running on the cluster
    // This process shall use the information in the SI to start the appropriate
    // application running.
void acAddApp(const char* appCnt,const char* appName, const char* activeXml, const char* standbyXml)
{
  ClRcT rc;
  ClAmsEntityConfigT sg;
  ClAmsEntityConfigT si;
  ClAmsEntityConfigT csi;
  
  if (ccbHandle==CL_HANDLE_INVALID_VALUE) initHandles();
  initEntity(&sg,appCnt,CL_AMS_ENTITY_TYPE_SG);
  initEntity(&si,appName,CL_AMS_ENTITY_TYPE_SI);
  initEntity(&csi,appName,CL_AMS_ENTITY_TYPE_CSI);

  // Create the new entities
  if ((rc = clAmsMgmtCCBEntityCreate(ccbHandle,&si)) != CL_OK)
    {
      checkError("Create SI",rc);
    }
  if ((rc = clAmsMgmtCCBCommit(ccbHandle)) != CL_OK)
    {
      checkError("Commit SI creation", rc);
    }
  
  if ((rc = clAmsMgmtCCBEntityCreate(ccbHandle,&csi)) != CL_OK)
    {
      checkError("Create CSI",rc);
    }

  if ((rc = clAmsMgmtCCBCommit(ccbHandle)) != CL_OK)
    {
      checkError("Commit CSI creation", rc);
    }


  // Configure the new entities
  if (1) // configure the SI
    {
      ClUint64T changeMask = 0;
      ClAmsEntityConfigT *pEntityConfig = NULL;
      ClAmsSIConfigT siConfig;

      // Grab the SI object
      if ((rc = clAmsMgmtEntityGetConfig(mgmtHandle,&si,&pEntityConfig)) != CL_OK)
        {
           checkError("Get SI config", rc);
        }

      memcpy(&siConfig, pEntityConfig, sizeof(siConfig));
      clHeapFree(pEntityConfig);

      // Configure SI state
      siConfig.numCSIs = 1;
      siConfig.numStandbyAssignments = 1; 
      changeMask |= SI_CONFIG_NUM_CSIS | SI_CONFIG_NUM_STANDBY_ASSIGNMENTS;

      if ((rc = clAmsMgmtCCBEntitySetConfig(ccbHandle,&siConfig.entity,changeMask)) != CL_OK)
        {
          checkError("Set SI config", rc);
        }

      // Link SI to the CSI
      if ((rc = clAmsMgmtCCBSetSICSIList(ccbHandle,&si,&csi)) != CL_OK)
        {
           checkError("Change SI config", rc);
        }

      // Commit SI
      if ((rc = clAmsMgmtCCBCommit(ccbHandle)) != CL_OK)
        {
           checkError("Commit SI configuration", rc);
        }      
    }

  if (1) // configure the CSI
    {
      ClAmsEntityConfigT *pEntityConfig = NULL;
      ClUint64T changeMask = 0;
      ClAmsCSIConfigT csiConfig;
      ClAmsCSINVPT nvp;

      // Grab the CSI object
      if ((rc = clAmsMgmtEntityGetConfig(mgmtHandle,&csi,&pEntityConfig)) != CL_OK)
        {
          checkError("Get CSI configuration", rc);
        }
      
      memcpy(&csiConfig, pEntityConfig, sizeof(csiConfig));
      clHeapFree(pEntityConfig);

      // Specify a unique CSI type
      changeMask |= CSI_CONFIG_TYPE;
      saNameSet(&csiConfig.type, CSI_TYPE_APP);
      csiConfig.type.length += 1;

      if ((rc = clAmsMgmtCCBEntitySetConfig(ccbHandle,&csiConfig.entity,changeMask)) != CL_OK)
        {
          checkError("Set CSI type", rc);
        }
      
      // Set the name/value pairs
      saNameSet(&nvp.paramName,"activexml");
      saNameSet(&nvp.paramValue,activeXml);
      if ((rc = clAmsMgmtCCBCSISetNVP(ccbHandle,&csi,&nvp)) != CL_OK)
        {
          checkError("Set CSI NVP", rc);
        }
      // Set the name/value pairs
      saNameSet(&nvp.paramName,"standbyxml");
      saNameSet(&nvp.paramValue,standbyXml);
      if ((rc = clAmsMgmtCCBCSISetNVP(ccbHandle,&csi,&nvp)) != CL_OK)
        {
          checkError("Set CSI NVP", rc);
        }

      // Commit CSI
      if ((rc = clAmsMgmtCCBCommit(ccbHandle)) != CL_OK)
        {
          checkError("Commit CSI",rc);
        }      
      
    }

    if (1) // Link the SI to the SG
    {
      if ((rc = clAmsMgmtCCBSetSGSIList(ccbHandle,&sg,&si)) != CL_OK)
        {
          checkError("Add SI to SG", rc);
        }
      
      if ((rc = clAmsMgmtCCBCommit(ccbHandle) ) != CL_OK)
        {
          checkError("Commit adding SI to SG", rc);
        }
    }
    /*
     * Unlock or start the SI
     */
    if((rc = clAmsMgmtEntityUnlock(mgmtHandle, &si)) != CL_OK 
       &&
       CL_GET_ERROR_CODE(rc) != CL_ERR_NO_OP)
    {
        checkError("SI unlock failed", rc);
    }
}
void suStop(const char* name)
{
  ClAmsEntityConfigT entity;
  initEntity(&entity,name,CL_AMS_ENTITY_TYPE_SU);    
  entityStop(entity);  
}
// Create a new application container in the AMF
void addAppCnt(const char* safName,SafConfig* cfg)
{
  ClRcT rc;
  ClAmsEntityConfigT sg;

  // Create the SG object
  if (ccbHandle==CL_HANDLE_INVALID_VALUE) initHandles();
  initEntity(&sg,safName,CL_AMS_ENTITY_TYPE_SG);

  if ((rc = clAmsMgmtCCBEntityCreate(ccbHandle,&sg)) != CL_OK)
    {
      checkError("Create SG",rc);      
    }

  if ((rc = clAmsMgmtCCBCommit(ccbHandle)) != CL_OK)
    {
      checkError("Commit create SG",rc);      
    }

  // Now configure it -- for now just use the defaults
  if (1)
    {
      ClAmsSGConfigT      sgConfig;
      ClAmsEntityConfigT* pEntityConfig = NULL;
      ClUint64T           changeMask = 0;
      
      if ((rc = clAmsMgmtEntityGetConfig(mgmtHandle,&sg,&pEntityConfig)) != CL_OK)
        {
        checkError("Get SG config",rc);      
        }

      memcpy(&sgConfig, pEntityConfig, sizeof(sgConfig));
      clHeapFree(pEntityConfig);

      changeMask |= SG_CONFIG_REDUNDANCY_MODEL | SG_CONFIG_NUM_PREF_ACTIVE_SUS
        | SG_CONFIG_NUM_PREF_STANDBY_SUS | SG_CONFIG_NUM_PREF_INSERVICE_SUS
        | SG_CONFIG_MAX_ACTIVE_SIS_PER_SU | SG_CONFIG_MAX_STANDBY_SIS_PER_SU
        | SG_CONFIG_INSTANTIATE_DURATION;

      sgConfig.redundancyModel     = CL_AMS_SG_REDUNDANCY_MODEL_TWO_N;
      sgConfig.numPrefActiveSUs    = 1;  // Just a very large number, so the check does not occur in the custom model
      sgConfig.numPrefStandbySUs   = 1;  
      sgConfig.numPrefInserviceSUs = 2;
      sgConfig.maxActiveSIsPerSU   = 1;
      sgConfig.maxStandbySIsPerSU  = 1;
      sgConfig.instantiateDuration = 1000;
      
      //Recovery policy
      if (cfg && cfg->compRestartCountMax > 0 && cfg->compRestartDuration > 0)
        {
          sgConfig.compRestartCountMax = cfg->compRestartCountMax;
          sgConfig.compRestartDuration = cfg->compRestartDuration;	  
          changeMask |= SG_CONFIG_COMP_RESTART_DURATION | SG_CONFIG_COMP_RESTART_COUNT_MAX;
        }
      
      if ((rc = clAmsMgmtCCBEntitySetConfig(ccbHandle,&sgConfig.entity,changeMask) ) != CL_OK)
        {
        checkError("Set SG config", rc);
        }
      
      
      if ((rc = clAmsMgmtCCBCommit(ccbHandle) ) != CL_OK)
        {
        checkError("Commit change SG config",rc);
        }
    }

  // Add the scheduler application in.
  // In particular this defines the CSI TYPE in the SG so it will work when used during component addition.
  //acAddApp(safName,"scheduler","");
 
}