コード例 #1
0
ファイル: player.c プロジェクト: FatherFoxxy/BadGame
BOOL Player_AdjustPos(float relativeX, float relativeY)
{
	FloatPoint newPos = { 0 };
	newPos.x = relativeX + player->pos.x;
	newPos.y = relativeY + player->pos.y;

	FloatPoint integerPos = { 0 };
	integerPos.x = roundf(player->pos.x + relativeX);
	integerPos.y = roundf(player->pos.y + relativeY);

	if (integerPos.y > level->levelHeight - SPRITE_HEIGHT)
		return TRUE;

	for (int i = 0; i < 4; i++)
	{
		FloatPoint colPoint = player->collisionPoints[i];
		if (colPoint.y + integerPos.y >= level->levelHeight || colPoint.y + integerPos.y < 0 || integerPos.x  > level->levelWidth - SPRITE_WIDTH || integerPos.x < 0)
			return TRUE;

		for (int j = 0; j < level->entityCount; j++)
		{
			FloatPoint* entityPoints = Entities_GetEntityPoints(level->entities[j].entityId);
			if (!Vector_RectContainsPoints(entityPoints, integerPos))
			{
				free(entityPoints);
				continue;
			}
			if (level->entities[j].is_dangerous)
			{
				free(entityPoints);
				Player_Die(player);
				return FALSE;
			}
			free(entityPoints);
		}

		int adjustedY = roundUpTo(integerPos.y - colPoint.y, SPRITE_HEIGHT);
		int adjustedX = roundUpTo(integerPos.x - colPoint.x, SPRITE_WIDTH);

#if DISPLAY_COLLISION_PROCESS
		Bitmap_WriteToBuffer(details->BackBuffer, details->Width, 20, 20, adjustedX, adjustedY, calloc(20 * 20, sizeof(int)));
		StretchDIBits(details->DC,
			0, 0, details->Width, details->Height,
			0, 0, details->BitMapInfo.bmiHeader.biWidth, Abs(details->BitMapInfo.bmiHeader.biHeight),
			details->BackBuffer, &details->BitMapInfo,
			DIB_RGB_COLORS, SRCCOPY);
		Sleep(50);
#endif

		TileInfo* info = Level_GetTileAtPos(level, adjustedY, adjustedX);
		if (info->is_collidable)
			return TRUE;
	}
	player->pos.x += relativeX;
	player->pos.y += relativeY;
	return FALSE;
}
コード例 #2
0
ファイル: commands.cpp プロジェクト: SamuelStewart/mineserver
void giveItemsName(std::string userIn, int id, int count, int health)
{
  if (isValidItem(id))
  {
    int itemCount = 1, itemStacks = 1;

    if(count != 1)
    {
      itemCount = count;
      if(itemCount>1024) itemCount=1024;
      // If multiple stacks
      itemStacks = roundUpTo(itemCount, 64) / 64;
      itemCount  -= (itemStacks-1) * 64;
    }
    int amount = 64;
    for(int i = 0; i < itemStacks; i++)
    {
      // if last stack
      if(i == itemStacks - 1)
      {
        amount = itemCount;
      }
      mineserver->user.addItem(userIn.c_str(), id, amount, health);
    }
  }
  else
  {
    mineserver->chat.sendmsgTo(userIn.c_str(),  "Not a valid item");
  }
}
コード例 #3
0
ファイル: player.c プロジェクト: FatherFoxxy/BadGame
void Player_CheckColissions()
{
	POINT integerPos = { 0 };
	integerPos.x = (int)roundf(player->pos.x);
	integerPos.y = (int)roundf(player->pos.y);

	int bottomTouchCount = 0;
	for (int i = 0; i < 2; i++) //top
	{
		FloatPoint colPoint = player->collisionPoints[i];
		if (colPoint.y + integerPos.y >= level->levelHeight || colPoint.y + integerPos.y < 0 || integerPos.x  > level->levelWidth - SPRITE_WIDTH || integerPos.x < 0)
			return;

		int adjustedY = roundUpTo(integerPos.y + colPoint.y + 1, SPRITE_HEIGHT);
		int adjustedX = roundUpTo(integerPos.x - colPoint.x, SPRITE_WIDTH);

		TileInfo* tile = Level_GetTileAtPos(level, adjustedY, adjustedX);

		bottomTouchCount += tile->is_collidable;
	}

	/*for (int i = 2; i < 4; i++) //bottom
	{
	FloatPoint colPoint = player->collisionPoints[i];
	if (colPoint.y + integerPos.y >= level->levelHeight || colPoint.y + integerPos.y < 0 || integerPos.x  > level->levelWidth - SPRITE_WIDTH || integerPos.x < 0)
	return TRUE;

	int adjustedY = roundUpTo(integerPos.y + colPoint.y + 1, SPRITE_HEIGHT);
	int adjustedX = roundUpTo(integerPos.x - colPoint.x, SPRITE_WIDTH);

	#if DISPLAY_COLLISION_PROCESS
	Bitmap_WriteToBuffer(details->BackBuffer, details->Width, 20, 20, adjustedX, adjustedY, calloc(20 * 20, sizeof(int)));
	StretchDIBits(details->DC,
	0, 0, details->Width, details->Height,
	0, 0, details->BitMapInfo.bmiHeader.biWidth, Abs(details->BitMapInfo.bmiHeader.biHeight),
	details->BackBuffer, &details->BitMapInfo,
	DIB_RGB_COLORS, SRCCOPY);
	Sleep(10);
	#endif
	}*/

	if (bottomTouchCount > 0)
		player->isOnGround = 1;
	else
		player->isOnGround = 0;
}
コード例 #4
0
ファイル: space.cpp プロジェクト: AdamSpitz/klein
BPRef Space::allocateBytes(int nBytes) {
  Byte* newBytesBottom = ((Byte*) bytesBottom()) - roundUpTo(nBytes, oopSize);
  
  // Check for out of memory: using '<=' to reserve space for the mark following
  // the last word in the space.
  if (newBytesBottom <= ((Byte*) objsTop())) {
    error("space full");
  }
  
  setBytesBottom(newBytesBottom);
  return (BPRef) newBytesBottom;
}
コード例 #5
0
ファイル: CopeOtExtSender.cpp プロジェクト: ladnir/dGarble
    void CopeOtExtSender::send(
        span<ZpNumber> messages,
        Channel& chl)
    {
        auto fieldSize = messages[0].mField->bitCount();

        // round up
        u64 numOtExt = roundUpTo(messages.size() * fieldSize, 128);
        u64 numSuperBlocks = (numOtExt / 128 + copeSuperBlkSize - 1) / copeSuperBlkSize;
        //u64 numBlocks = numSuperBlocks * copeSuperBlkSize;

        // a uNum that will be used to transpose the sender's matrix
        std::array<block, copeSuperBlkSize> t;
        std::vector<std::array<block, copeSuperBlkSize>> u(128 * copeCommStepSize);

        //std::array<block, 128> choiceMask;
        block delta = *(block*)mBaseChoiceBits.data();

        //for (u64 i = 0; i < 128; ++i)
        //{
        //    if (mBaseChoiceBits[i]) choiceMask[i] = AllOneBlock;
        //    else choiceMask[i] = ZeroBlock;
        //}


        auto* mIter = messages.data();

        block * uIter = (block*)u.data() + copeSuperBlkSize * 128 * copeCommStepSize;
        block * uEnd = uIter;

        ZpField field;
        field.setParameters(ZpParam128);

        std::vector<ZpNumber> g;
        //qq.reserve(copeSuperBlkSize * field.bitCount());
        //for (u64 i = 0; i < copeSuperBlkSize * field.bitCount(); ++i)
        //    qq.emplace_back(field);

        std::cout << IoStream::lock;
        g.reserve(field.bitCount());
        for (u64 i = 0; i < field.bitCount(); ++i)
        {
            g.emplace_back(field, 2);
            g[i].powEq(i);
            std::cout << "g[" << i << "] " << g[i] << std::endl;
        }

        std::cout << IoStream::unlock;

        std::array<ZpNumber, copeSuperBlkSize> q
         {
            ZpNumber(field),ZpNumber(field),ZpNumber(field),ZpNumber(field),
            ZpNumber(field), ZpNumber(field), ZpNumber(field), ZpNumber(field)
        };

        ZpNumber uNum(field);

        for (u64 superBlkIdx = 0; superBlkIdx < numSuperBlocks; ++superBlkIdx)
        {

            if (uIter == uEnd)
            {
                u64 step = std::min<u64>(numSuperBlocks - superBlkIdx, (u64)copeCommStepSize);
                chl.recv((u8*)u.data(), step * copeSuperBlkSize * 128 * sizeof(block));
                uIter = (block*)u.data();
            }

            for (u64 j = 0; j < copeSuperBlkSize; ++j)
            {
                //qq[j] = 0;
                mIter[j] = 0;
            }
            std::cout << IoStream::lock;

            // transpose 128 columns at at time. Each column will be 128 * copeSuperBlkSize = 1024 bits long.
            for (u64 colIdx = 0; colIdx < 128; ++colIdx)
            {
                // generate the columns using AES-NI in counter mode.
                mGens[colIdx].mAes.ecbEncCounterMode(mGens[colIdx].mBlockIdx, copeSuperBlkSize, t.data());
                mGens[colIdx].mBlockIdx += copeSuperBlkSize;

                for (u64 i = 0; i < copeSuperBlkSize; ++i)
                {
                    q[i].fromBytes((u8*)&t[i]);
                }

                if (this->mBaseChoiceBits[colIdx])
                {
                    for (u64 i = 0; i < copeSuperBlkSize; ++i)
                    {
                        uNum.fromBytes((u8*)&uIter[i]);
                        q[i] -= uNum;
                    }
                }



                for (u64 i = 0; i < copeSuperBlkSize; ++i)
                {
                    //std::cout <<  (mBaseChoiceBits[colIdx]? "t0x" : "t0 ") <<"[" << i << "][" << colIdx << "] = " << q[i] <<"   " << mBaseChoiceBits[colIdx] << "\n\n"<<std::endl;
                    std::cout << "q[" << colIdx << "][" << i << "] = " << q[i] << std::endl;
                    q[i] *= g[colIdx];

                    mIter[i] += q[i];
                }

                uIter += 8;
            }
            std::cout << IoStream::unlock;

            mIter += 8;

        }


        static_assert(gOtExtBaseOtCount == 128, "expecting 128");
    }
コード例 #6
0
ファイル: commands.cpp プロジェクト: swallen/mineserver
void giveItems(User *user, std::string command, std::deque<std::string> args)
{
  User *tUser = NULL;
  int itemId = 0, itemCount = 1, itemStacks = 1;

  if(args.size() > 1)
  {
    tUser = getUserByNick(args[0]);

    //First check if item is a number
    itemId = atoi(args[1].c_str());

    //If item was not a number, search the name from config
    if(itemId == 0)
      itemId = Conf::get().iValue(args[1]);

    // Check item validity
    if(!isValidItem(itemId))
    {
      reportError(user, "Item " + args[1] + " not found.");
      return;
    }

    if(args.size() > 2)
    {
      itemCount = atoi(args[2].c_str());
      // If multiple stacks
      itemStacks = roundUpTo(itemCount, 64) / 64; 
      itemCount  -= (itemStacks-1) * 64; 
    }
  }
  else
  {
    reportError(user, "Too few parameters.");
	  return;
  }

  if(tUser)
  {
    int amount = 64;
    for(int i = 0; i < itemStacks; i++)
    {
      // if last stack
      if(i == itemStacks - 1)
        amount = itemCount;

      spawnedItem item;
      item.EID     = generateEID();
      item.item    = itemId;
      item.health  = 0;
      item.count   = amount;
      item.pos.x() = static_cast<int>(tUser->pos.x * 32);
      item.pos.y() = static_cast<int>(tUser->pos.y * 32);
      item.pos.z() = static_cast<int>(tUser->pos.z * 32);

      Map::get().sendPickupSpawn(item);
    }

    Chat::get().sendMsg(user, COLOR_RED + user->nick + " spawned " + args[1], Chat::ADMINS);
  }
  else
    reportError(user, "User " + args[0] + " not found (see /players)");
}