Exemplo n.º 1
0
void ListBox::UpdateVScrollBar()
{
	if ((int32_t)mItems.size() > mNumVisibleItems)
	{
		mVertScrollBar->SetScrollableSize(mItems.size());

		if (mVertScrollBar->IsVisible() == false)
		{
			mVertScrollBar->SetVisible(true);
			mVertScrollBar->SetPosition(int2(mSize.X() - mScrollBarWidth, 1));
			mVertScrollBar->SetSize(int2(mScrollBarWidth-1, mSize.Y()-2));
			mSelectionRegion.Width -= mScrollBarWidth;
		}
		else 
		{
			mSelectionRegion.Width -= mScrollBarWidth;
			mVertScrollBar->SetScrollRange(0, (int)mItems.size() - mNumVisibleItems);	
		}
		
	}
	else
	{
		if (mVertScrollBar->IsVisible())
		{
			mVertScrollBar->SetVisible(false);
			mSelectionRegion.Width += mScrollBarWidth;
		}
	}
}
Exemplo n.º 2
0
int updatedragpos(SDL_TouchFingerEvent &e, Uint32 et, const int2 &screensize)
{
    int numfingers = SDL_GetNumTouchFingers(e.touchId);
    //assert(numfingers && e.fingerId < numfingers);
    for (int i = 0; i < numfingers; i++)
    {
        auto finger = SDL_GetTouchFinger(e.touchId, i);
        if (finger->id == e.fingerId)
        {
            // this is a bit clumsy as SDL has a list of fingers and so do we, but they work a bit differently
            int j = findfinger(e.fingerId, et == SDL_FINGERUP);
            auto &f = fingers[j];
            auto ep = float2(e.x, e.y);
            auto ed = float2(e.dx, e.dy);
            auto xy = ep * float2(screensize);

            // FIXME: converting back to int coords even though touch theoretically may have higher res
            f.mousepos = int2(xy * float(screenscalefactor));
            f.mousedelta += int2(ed * float2(screensize));
            return j;
        }
    }
    //assert(0);
    return 0;
}
Exemplo n.º 3
0
CPathFinder::CPathFinder(): squareStates(int2(gs->mapx, gs->mapy), int2(gs->mapx, gs->mapy))
{
	heatMapping = true;
	InitHeatMap();

	// Precalculated vectors.
	directionVector[PATHOPT_RIGHT].x = -2;
	directionVector[PATHOPT_LEFT ].x =  2;
	directionVector[PATHOPT_UP   ].x =  0;
	directionVector[PATHOPT_DOWN ].x =  0;
	directionVector[(PATHOPT_RIGHT | PATHOPT_UP  )].x = directionVector[PATHOPT_RIGHT].x + directionVector[PATHOPT_UP  ].x;
	directionVector[(PATHOPT_LEFT  | PATHOPT_UP  )].x = directionVector[PATHOPT_LEFT ].x + directionVector[PATHOPT_UP  ].x;
	directionVector[(PATHOPT_RIGHT | PATHOPT_DOWN)].x = directionVector[PATHOPT_RIGHT].x + directionVector[PATHOPT_DOWN].x;
	directionVector[(PATHOPT_LEFT  | PATHOPT_DOWN)].x = directionVector[PATHOPT_LEFT ].x + directionVector[PATHOPT_DOWN].x;

	directionVector[PATHOPT_RIGHT].y =  0;
	directionVector[PATHOPT_LEFT ].y =  0;
	directionVector[PATHOPT_UP   ].y =  2;
	directionVector[PATHOPT_DOWN ].y = -2;
	directionVector[(PATHOPT_RIGHT | PATHOPT_UP  )].y = directionVector[PATHOPT_RIGHT].y + directionVector[PATHOPT_UP  ].y;
	directionVector[(PATHOPT_LEFT  | PATHOPT_UP  )].y = directionVector[PATHOPT_LEFT ].y + directionVector[PATHOPT_UP  ].y;
	directionVector[(PATHOPT_RIGHT | PATHOPT_DOWN)].y = directionVector[PATHOPT_RIGHT].y + directionVector[PATHOPT_DOWN].y;
	directionVector[(PATHOPT_LEFT  | PATHOPT_DOWN)].y = directionVector[PATHOPT_LEFT ].y + directionVector[PATHOPT_DOWN].y;

	moveCost[PATHOPT_RIGHT] = 1;
	moveCost[PATHOPT_LEFT ] = 1;
	moveCost[PATHOPT_UP   ] = 1;
	moveCost[PATHOPT_DOWN ] = 1;
	moveCost[(PATHOPT_RIGHT | PATHOPT_UP  )] = 1.42f;
	moveCost[(PATHOPT_LEFT  | PATHOPT_UP  )] = 1.42f;
	moveCost[(PATHOPT_RIGHT | PATHOPT_DOWN)] = 1.42f;
	moveCost[(PATHOPT_LEFT  | PATHOPT_DOWN)] = 1.42f;
}
Exemplo n.º 4
0
	void HandleSDLMouseEvent (SDL_Event& event)
	{
		switch(event.type) {
		case SDL_MOUSEMOTION:
			mousepos = int2(event.motion.x,event.motion.y);
			if(mouse)
				mouse->MouseMove(mousepos.x,mousepos.y);
			break;
		case SDL_MOUSEBUTTONDOWN:
			mousepos = int2(event.button.x,event.button.y);
			if (mouse) {
				if (event.button.button == SDL_BUTTON_WHEELUP)
					mouse->currentCamController->MouseWheelMove(scrollWheelSpeed);
				else if (event.button.button == SDL_BUTTON_WHEELDOWN)
					mouse->currentCamController->MouseWheelMove(-scrollWheelSpeed);
				else
					mouse->MousePress(event.button.x,event.button.y,event.button.button);
			}
			break;
		case SDL_MOUSEBUTTONUP:
			mousepos = int2(event.button.x,event.button.y);
			if (mouse)
				mouse->MouseRelease(event.button.x,event.button.y,event.button.button);
			break;
		}
	}
Exemplo n.º 5
0
bool BOState::Initialize(float2 p_position, int2 p_size, float2 p_menuPosition, std::string p_name, SDL_Texture* p_sprite)
{
	m_name = p_name;
	m_position = p_position;
	m_screenSize = p_size;
	m_buttonList.empty();

	BOPublisher::AddSubscriber(this);

	// Load background.
	if (!m_background.Initialize(p_position, p_size, p_sprite))
	{
		std::cout << "Failed to load background for " << m_name << "!" << std::endl;
		return false;
	}

	// Load the menu bars first edge.
	BOObject firstEdge;
	if (!firstEdge.Initialize(float2(p_menuPosition.x + 2.5f, p_menuPosition.y + 35), int2(5, 70), BOTextureManager::GetTexture(TEXMENUEDGE)))
	{
		std::cout << "Failed to load first edge of menu" << m_name << "!" << std::endl;
		return false;
	}

	m_menuBar.push_back(firstEdge);

	// Load the menu bar.
	BOObject menuBar;
	if (!menuBar.Initialize(float2(p_menuPosition.x + 125, p_menuPosition.y + 35), int2(240, 70), BOTextureManager::GetTexture(TEXMENUBAR)))
	{
		std::cout << "Failed to load last edge of menu" << m_name << "!" << std::endl;
		return false;
	}

	m_menuBar.push_back(menuBar);

	// Load the last edge of the menu bars.
	BOObject lastEdge;
	if (!lastEdge.Initialize(float2(p_menuPosition.x + 247.5f, p_menuPosition.y + 35), int2(5, 70), BOTextureManager::GetTexture(TEXMENUEDGE)))
	{
		std::cout << "Failed to load last edge of menu" << m_name << "!" << std::endl;
		return false;
	}

	m_menuBar.push_back(lastEdge);

	// Load menu text
	if (!m_menuText.Initialize(float2(0,0), m_name, int3(255, 255, 255), 72, 0))
	{
		std::cout << "Failed to create menu text in " << m_name << "!" << std::endl;
		return false;
	}

	// Calculate menu text position
	int2 tempSize = m_menuText.GetSize();
	float2 tempPos = float2(25.0f + p_menuPosition.x + tempSize.x / 2, 13 + p_menuPosition.y + tempSize.y / 2);
	m_menuText.SetPosition(tempPos);

	return true;
}
Exemplo n.º 6
0
	void View::drawGrid(Renderer2D &out) const {
		if(!m_is_visible)
			return;

		const int2 tile_map_size = m_tile_map.dimensions();

		int2 p[4] = {
			screenToWorld(m_view_pos + int2(0, 0)),
			screenToWorld(m_view_pos + int2(0, m_view_size.y)),
			screenToWorld(m_view_pos + int2(m_view_size.x, m_view_size.y)),
			screenToWorld(m_view_pos + int2(m_view_size.x, 0)) };
		int2 offset = screenToWorld(worldToScreen(int3(0, m_height, 0)));
		for(int n = 0; n < 4; n++)
			p[n] -= offset;

		int2 tmin = min(min(p[0], p[1]), min(p[2], p[3]));
		int2 tmax = max(max(p[0], p[1]), max(p[2], p[3]));
		IRect box(max(tmin, int2(0, 0)), min(tmax, tile_map_size));

		Color color(255, 255, 255, 64);
		for(int x = box.min.x - box.min.x % m_cell_size; x <= box.max.x; x += m_cell_size)
			drawLine(out, int3(x, m_height, box.min.y), int3(x, m_height, box.max.y), color);
		for(int y = box.min.y - box.min.y % m_cell_size; y <= box.max.y; y += m_cell_size)
			drawLine(out, int3(box.min.x, m_height, y), int3(box.max.x, m_height, y), color);
	}
Exemplo n.º 7
0
	void HandleSDLMouseEvent (SDL_Event& event)
	{
		switch (event.type) {
			case SDL_MOUSEMOTION: {
				mousepos = int2(event.motion.x, event.motion.y);
				if (mouse) {
					mouse->MouseMove(mousepos.x, mousepos.y);
				}
				break;
			}
			case SDL_MOUSEBUTTONDOWN: {
				mousepos = int2(event.button.x, event.button.y);
				if (mouse) {
					if (event.button.button == SDL_BUTTON_WHEELUP) {
						mouse->MouseWheel(1.0f);
					} else if (event.button.button == SDL_BUTTON_WHEELDOWN) {
						mouse->MouseWheel(-1.0f);
					} else {
						mouse->MousePress(event.button.x, event.button.y, event.button.button);
					}
				}
				break;
			}
			case SDL_MOUSEBUTTONUP: {
				mousepos = int2(event.button.x, event.button.y);
				if (mouse) {
					mouse->MouseRelease(event.button.x, event.button.y, event.button.button);
				}
				break;
			}
		}
	}
Exemplo n.º 8
0
	void UIScrollBar::MouseOverHandler(UIDialog const & /*sender*/, uint32_t /*buttons*/, int2 const & pt)
	{
		last_mouse_ = pt;
		is_mouse_over_ = true;

		if (drag_)
		{
			thumb_rc_.bottom() += pt.y() - thumb_offset_y_ - thumb_rc_.top();
			thumb_rc_.top() = pt.y() - thumb_offset_y_;
			if (thumb_rc_.top() < track_rc_.top())
			{
				thumb_rc_ += int2(0, track_rc_.top() - thumb_rc_.top());
			}
			else
			{
				if (thumb_rc_.bottom() > track_rc_.bottom())
				{
					thumb_rc_ += int2(0, track_rc_.bottom() - thumb_rc_.bottom());
				}
			}

			// Compute first item index based on thumb position

			size_t nMaxFirstItem = end_ - start_ - page_size_;  // Largest possible index for first item
			size_t nMaxThumb = track_rc_.Height() - thumb_rc_.Height();  // Largest possible thumb position from the top

			position_ = start_ +
				(thumb_rc_.top() - track_rc_.top() +
				nMaxThumb / (nMaxFirstItem * 2)) * // Shift by half a row to avoid last row covered by only one pixel
				nMaxFirstItem  / nMaxThumb;
		}
	}
Exemplo n.º 9
0
bool World::IsBuildTileAccessible(const BuildTile& parBuildTile, const int2& parDimensions) const
{
	assert(parBuildTile.IsValid());

	if (!accessibleTile_[parBuildTile.x()][parBuildTile.y()])
		return false;

	BuildTile dimensionInBuildTile(float2(float(parDimensions.x), float(parDimensions.y))); // force conversion
	const int2& minTile = int2(
		parBuildTile.x() - 1 - dimensionInBuildTile.w() / 2,
		parBuildTile.y() - 1 - dimensionInBuildTile.h() / 2);
	const int2& maxTile = int2(
		parBuildTile.x() + 1 + dimensionInBuildTile.w() / 2,
		parBuildTile.y() + 1 + dimensionInBuildTile.h() / 2);

	for (int x = minTile.x; x <= maxTile.x; ++x)
	{
		for (int y = minTile.y; y <= maxTile.y; ++y)
		{
			BuildTile tile(x, y);
			if (!tile.IsValid() || !accessibleTile_[x][y])
				return false;
		}
	}

	return true;
}
Exemplo n.º 10
0
bool BOTechTreeManager::Initialize(int2 p_windowDimension)
{
    m_windowSize = p_windowDimension;

    m_grid = BOTextureManager::GetTexture(TEXTTHIGHLIGHTED);

    int2 m_Size = int2(100, 100);
    float2 midScreen = float2(m_windowSize.x * 0.5f, m_windowSize.y * 0.5f + 150); // To save computation
    int diameter = 7; // Original is 7
    float xOffset = m_Size.x * 0.85f;
    float yOffset = m_Size.y*0.5f;

    for (unsigned int y = diameter - 3, x = 0; y != 0; y--, x++)
    {
        BOTechTreeNode* newNode = CreateNode(float2(midScreen.x - x * xOffset, midScreen.y - (y + 4) * yOffset), m_Size, " ");
    }
    for (unsigned int y = diameter - 2, x = 0; y != 0; y--, x++)
    {
        BOTechTreeNode* newNode = CreateNode(float2(midScreen.x + xOffset - x * xOffset, midScreen.y + yOffset - (y + 3) * yOffset), m_Size, " ");
    }
    for (unsigned int y = diameter - 1, x = 0; y != 0; y--, x++)
    {
        BOTechTreeNode* newNode = CreateNode(float2(midScreen.x + xOffset * 2 - x * xOffset, midScreen.y + yOffset * 3 - (y + 3) * yOffset), m_Size, " ");
    }
    for (unsigned int y = diameter, x = 0; y != 0; y--, x++)
    {
        BOTechTreeNode* newNode = CreateNode(float2(midScreen.x + xOffset * 3 - x * xOffset, midScreen.y + yOffset * 5 - (y + 3) * yOffset), m_Size, " ");
    }
    for (unsigned int y = diameter - 1, x = 0; y != 0; y--, x++)
    {
        BOTechTreeNode* newNode = CreateNode(float2(midScreen.x + xOffset * 3 - x * xOffset, midScreen.y + yOffset * 6 - (y + 3) * yOffset), m_Size, " ");
    }
    for (unsigned int y = diameter - 2, x = 0; y != 0; y--, x++)
    {
        BOTechTreeNode* newNode = CreateNode(float2(midScreen.x + xOffset * 3 - x * xOffset, midScreen.y + yOffset * 7 - (y + 3) * yOffset), m_Size, " ");
    }
    for (unsigned int y = diameter - 3, x = 0; y != 0; y--, x++)
    {
        BOTechTreeNode* newNode = CreateNode(float2(midScreen.x + xOffset * 3 - x * xOffset, midScreen.y + yOffset * 8 - (y + 3) * yOffset), m_Size, " ");
    }

    MapNodes();
    SetLPE();

    m_resetButton.Initialize(float2(m_windowSize.x-300.0f, m_windowSize.y-125.0f), int2(250, 75), BOTextureManager::GetTexture(TEXMENUBUTTON), "RESET", TECHTREERESET, "");

    // Tech Points
    m_techPointsText.Initialize(float2(0,0), "ERROR", int3(255, 255, 255), 50, 0);
    float2 resetPos = m_resetButton.GetPosition();
    int2 resetSize = m_resetButton.GetSize();
    int2 textSize = m_techPointsText.GetSize();
    m_techPointsText.SetPosition(float2(resetPos.x - textSize.x*0.5f - 50.0f, resetPos.y + resetSize.y*0.5f));
    m_maxTechPoints = 0;
    m_techPointsLeft = 0;

    BOPublisher::AddSubscriber(this);

    return true;
}
Exemplo n.º 11
0
	void EntitiesEditor::findVisible(vector<int> &out, const IRect &rect) const {
		out.clear();

		std::set<int> indices;
		vector<int> temp;
		temp.reserve(100);

		enum { block_size = 64 };

		for(int gy = m_selection.min.y; gy <= m_selection.max.y; gy += block_size)
			for(int gx = m_selection.min.x; gx <= m_selection.max.x; gx += block_size) {
				temp.clear();

				IRect block_rect(int2(gx, gy), min(int2(gx + block_size, gy + block_size), m_selection.max));
				m_entity_map.findAll(temp, block_rect, Flags::all | Flags::visible);
				for(int n = 0; n < (int)temp.size(); n++)
					if(indices.find(temp[n]) != indices.end()) {
						temp[n--] = temp.back();
						temp.pop_back();
					}

				for(int y = gy, endy = min(m_selection.max.y, gy + block_size); y <= endy; y += 2)
					for(int x = m_selection.min.x, endx = min(gx + block_size, m_selection.max.x); x <= endx; x += 2) {
						int2 point(x, y);
						if(point.x + 1 <= m_selection.max.x && (y & 1))
							point.x++;

						bool tile_isected = false;
						int tile_idx = -1;

						for(int i = 0; i < (int)temp.size(); i++) {
							const auto &object = m_entity_map[temp[i]];
							bool is_trigger = object.ptr->typeId() == EntityId::trigger;

							if(!is_trigger && !object.ptr->testPixel(point))
								continue;
							if(is_trigger && !object.ptr->currentScreenRect().isInside(point))
								continue;

							if(!tile_isected) {
								tile_idx = m_tile_map.pixelIntersect(int2(x, y), Flags::walkable_tile | Flags::visible);
								tile_isected = true;
							}
							if(tile_idx != -1) {
								if(drawingOrder(m_tile_map[tile_idx].bbox, m_entity_map[temp[i]].bbox) == 1)
									continue;
							}
						
							indices.insert(temp[i]);
							temp[i--] = temp.back();
							temp.pop_back();
						}
					}
			}

		out.insert(out.begin(), indices.begin(), indices.end());
	}
Exemplo n.º 12
0
CPathEstimator::CPathEstimator(CPathFinder* pf, unsigned int BSIZE, const std::string& cacheFileName, const std::string& map):
	BLOCK_SIZE(BSIZE),
	BLOCK_PIXEL_SIZE(BSIZE * SQUARE_SIZE),
	BLOCKS_TO_UPDATE(SQUARES_TO_UPDATE / (BLOCK_SIZE * BLOCK_SIZE) + 1),
	pathFinder(pf),
	nbrOfBlocksX(gs->mapx / BLOCK_SIZE),
	nbrOfBlocksZ(gs->mapy / BLOCK_SIZE),
	pathChecksum(0),
	offsetBlockNum(nbrOfBlocksX * nbrOfBlocksZ),
	costBlockNum(nbrOfBlocksX * nbrOfBlocksZ),
	nextOffsetMessage(-1),
	nextCostMessage(-1),
	blockStates(int2(nbrOfBlocksX, nbrOfBlocksZ), int2(gs->mapx, gs->mapy))
{
	// these give the changes in (x, z) coors
	// when moving one step in given direction
	directionVector[PATHDIR_LEFT      ].x =  1;
	directionVector[PATHDIR_LEFT      ].y =  0;
	directionVector[PATHDIR_LEFT_UP   ].x =  1;
	directionVector[PATHDIR_LEFT_UP   ].y =  1;
	directionVector[PATHDIR_UP        ].x =  0;
	directionVector[PATHDIR_UP        ].y =  1;
	directionVector[PATHDIR_RIGHT_UP  ].x = -1;
	directionVector[PATHDIR_RIGHT_UP  ].y =  1;
	directionVector[PATHDIR_RIGHT     ].x = -1;
	directionVector[PATHDIR_RIGHT     ].y =  0;
	directionVector[PATHDIR_RIGHT_DOWN].x = -1;
	directionVector[PATHDIR_RIGHT_DOWN].y = -1;
	directionVector[PATHDIR_DOWN      ].x =  0;
	directionVector[PATHDIR_DOWN      ].y = -1;
	directionVector[PATHDIR_LEFT_DOWN ].x =  1;
	directionVector[PATHDIR_LEFT_DOWN ].y = -1;

	goalSqrOffset.x = BLOCK_SIZE / 2;
	goalSqrOffset.y = BLOCK_SIZE / 2;

	vertices.resize(moveinfo->moveData.size() * blockStates.GetSize() * PATH_DIRECTION_VERTICES, 0.0f);

	// load precalculated data if it exists
	InitEstimator(cacheFileName, map);

	// As all vertexes are bidirectional and have equal values
	// in both directions, only one value needs to be stored.
	// This vector helps getting the right vertex. (Needs to
	// be inited after pre-calculations.)
	directionVertex[PATHDIR_LEFT      ] = PATHDIR_LEFT;
	directionVertex[PATHDIR_LEFT_UP   ] = PATHDIR_LEFT_UP;
	directionVertex[PATHDIR_UP        ] = PATHDIR_UP;
	directionVertex[PATHDIR_RIGHT_UP  ] = PATHDIR_RIGHT_UP;
	directionVertex[PATHDIR_RIGHT     ] = int(PATHDIR_LEFT    ) - PATH_DIRECTION_VERTICES;
	directionVertex[PATHDIR_RIGHT_DOWN] = int(PATHDIR_LEFT_UP ) - (nbrOfBlocksX * PATH_DIRECTION_VERTICES) - PATH_DIRECTION_VERTICES;
	directionVertex[PATHDIR_DOWN      ] = int(PATHDIR_UP      ) - (nbrOfBlocksX * PATH_DIRECTION_VERTICES);
	directionVertex[PATHDIR_LEFT_DOWN ] = int(PATHDIR_RIGHT_UP) - (nbrOfBlocksX * PATH_DIRECTION_VERTICES) + PATH_DIRECTION_VERTICES;

	pathCache = new CPathCache(nbrOfBlocksX, nbrOfBlocksZ);
}
Exemplo n.º 13
0
	void Button::drawContents() const {
		drawWindow(IRect(int2(0, 0), size()), isMouseOver() && m_is_enabled? WindowStyle::gui_light : WindowStyle::gui_dark,
					m_mouse_press? -2 : 2);

		int2 rect_center = size() / 2;
		int2 pos = rect_center - m_text_extents.size() / 2 - m_text_extents.min - int2(1, 1);
		if(m_mouse_press)
			pos += int2(2, 2);
		m_font->draw((float2)pos, {m_is_enabled? Color::white : Color::gray, Color::black}, m_text);
	}
Exemplo n.º 14
0
GWinControl::GWinControl()
{
	m_Hwnd			= NULL;
	m_OwnerHwnd		= NULL;
	m_pOwnerControl	= NULL;
	m_ControlID		= 0;
	m_ClientPos		= int2(0,0);
	m_ClientSize	= int2(40,40);
	m_StyleFlags	= 0x0;
}
Exemplo n.º 15
0
/**
 * Recreates the path found by pathfinder.
 * Starting at goalSquare and tracking backwards.
 *
 * Perform adjustment of waypoints so not all turns are 90 or 45 degrees.
 */
void CPathFinder::FinishSearch(const MoveData& moveData, IPath::Path& foundPath) {
	// backtrack
	if (needPath) {
		int2 square;
			square.x = goalSquare % gs->mapx;
			square.y = goalSquare / gs->mapx;

		// for path adjustment (cutting corners)
		std::deque<int2> previous;

		// make sure we don't match anything
		previous.push_back(int2(-100, -100));
		previous.push_back(int2(-100, -100));
		previous.push_back(int2(-100, -100));

		while (true) {
			const int sqrIdx = square.y * gs->mapx + square.x;

			if (squareStates[sqrIdx].nodeMask & PATHOPT_START)
				break;

			float3 cs;
				cs.x = (square.x/2/* + 0.5f*/) * SQUARE_SIZE * 2 + SQUARE_SIZE;
				cs.z = (square.y/2/* + 0.5f*/) * SQUARE_SIZE * 2 + SQUARE_SIZE;
				cs.y = moveData.moveMath->yLevel(square.x, square.y);

			// try to cut corners
			AdjustFoundPath(moveData, foundPath, /* inout */ cs, previous, square);

			foundPath.path.push_back(cs);
			foundPath.squares.push_back(square);

			previous.pop_front();
			previous.push_back(square);

			int2 oldSquare;
				oldSquare.x = square.x;
				oldSquare.y = square.y;

			square.x -= directionVector[squareStates[sqrIdx].nodeMask & PATHOPT_DIRECTION].x;
			square.y -= directionVector[squareStates[sqrIdx].nodeMask & PATHOPT_DIRECTION].y;
		}

		if (!foundPath.path.empty()) {
			foundPath.pathGoal = foundPath.path.front();
		}
	}

	// Adds the cost of the path.
	foundPath.pathCost = squareStates[goalSquare].fCost;
}
Exemplo n.º 16
0
	void UISlider::UpdateRects()
	{
		UIControl::UpdateRects();

		slider_rc_ = IRect(x_, y_, x_ + width_, y_ + height_);

		button_rc_ = slider_rc_;
		button_rc_.right() = button_rc_.left() + button_rc_.Height();
		button_rc_ += int2(-button_rc_.Width() / 2, 0);

		button_x_ = static_cast<int>((value_ - min_) * static_cast<float>(slider_rc_.Width()) / (max_ - min_));
		button_rc_ += int2(button_x_, 0);

		bounding_box_ = button_rc_ | slider_rc_;
	}
int2 CLegacyInfoTextureHandler::GetCurrentInfoTextureSize() const
{
	if (highResInfoTexWanted)
		return (int2(mapDims.pwr2mapx, mapDims.pwr2mapy));

	return (int2(mapDims.pwr2mapx >> 1, mapDims.pwr2mapy >> 1));
}
Exemplo n.º 18
0
    STARTDECL(gl_window) (Value &title, Value &xs, Value &ys)
    {
        if (graphics_initialized)
            g_vm->BuiltinError("cannot call gl_window() twice");

        screensize = int2(xs.ival, ys.ival);
        string err = SDLInit(title.sval->str(), screensize);
        title.DECRT();

        if (err.empty())
        {
            OpenGLInit();

            err = LoadMaterialFile("shaders/default.materials");
        }

        if (!err.empty())
        {
            DebugLog(1, err.c_str());
            return Value(g_vm->NewString(err));
        }

        colorshader = LookupShader("color");
        assert(colorshader);

        meshes   = new IntResourceManagerCompact<Mesh>();

        DebugLog(-1, "graphics fully initialized...");
        graphics_initialized = true;

        return Value(0, V_NIL);
    }
Exemplo n.º 19
0
bool BOTechTreeNode::Initialize(float2 p_pos, int2 p_size, std::string p_tooltip)
{
    m_isActive = false;
    m_isAdjacentActive = false;
    m_hoveringOver = false;
    m_layer = 0;
    m_price = 0;
    m_effect = 0;

    m_icon = BOTextureManager::GetTexture(TEXTTINACTIVE);
    m_active = BOTextureManager::GetTexture(TEXTTCHOSEN);
    m_inactive = BOTextureManager::GetTexture(TEXTTINACTIVE);
    m_adjacentActive = BOTextureManager::GetTexture(TEXTTADJACENTACTIVE);
    m_highlighted = BOTextureManager::GetTexture(TEXTTHIGHLIGHTED);

    // Tooltip
    m_tooltipHeading.Initialize(float2(0, 0), "Heading", int3(255, 255, 255), 40, 0);
    m_tooltipText.Initialize(float2(0,0), " ", int3(255, 255, 255), 30, 0);
    int2 windowBounds = BOGraphicInterface::GetWindowSize();
    m_tooltipFrame.Initialize(float2(0,0), int2(310,210), BOTextureManager::GetTexture(TEXTTTOLTIPFRAME));
    int2 framesSize = m_tooltipFrame.GetSize();
    m_tooltipFrame.SetPosition(float2(windowBounds.x - 50 - framesSize.x*0.5f, framesSize.y*0.5f +50));

    //priceText
    m_priceText.Initialize(float2(0, 0), " ", int3(255, 255, 255), 25, 0);

    return BOObject::Initialize(p_pos, p_size, m_inactive);
}
Exemplo n.º 20
0
int hours_of_observational_data_cutoff_after_reference_time(unsigned char **sec) {
    int p;
    p = GB2_ProdDefTemplateNo(sec);
    if (p <= 15 || p == 1000 || p == 1001 || p == 1002 || p == 1100 || p == 1101)
        return int2(sec[4]+14);
    return -1;
}
Exemplo n.º 21
0
/*
Request a new multipath, store the result and return a handle-id to it.
*/
unsigned int CPathManager::RequestPath(
	CSolidObject* caller,
	const MoveDef* moveDef,
	float3 startPos,
	float3 goalPos,
	float goalRadius,
	bool synced
) {
	if (!IsFinalized())
		return 0;

	// in misc since it is called from many points
	SCOPED_TIMER("Misc::Path::RequestPath");
	startPos.ClampInBounds();
	goalPos.ClampInBounds();

	// Create an estimator definition.
	goalRadius = std::max<float>(goalRadius, PATH_NODE_SPACING * SQUARE_SIZE); //FIXME do on a per PE & PF level?
	assert(moveDef == moveDefHandler->GetMoveDefByPathType(moveDef->pathType));

	MultiPath newPath = MultiPath(moveDef, startPos, goalPos, goalRadius);
	newPath.finalGoal = goalPos;
	newPath.caller = caller;
	newPath.peDef.synced = synced;

	if (caller != nullptr)
		caller->UnBlock();

	const IPath::SearchResult result = ArrangePath(&newPath, moveDef, startPos, goalPos, caller);

	unsigned int pathID = 0;

	if (result != IPath::Error) {
		if (newPath.maxResPath.path.empty()) {
			if (result != IPath::CantGetCloser) {
				LowRes2MedRes(newPath, startPos, caller, synced);
				MedRes2MaxRes(newPath, startPos, caller, synced);
			} else {
				// add one dummy waypoint so that the calling MoveType
				// does not consider this request a failure, which can
				// happen when startPos is very close to goalPos
				//
				// otherwise, code relying on MoveType::progressState
				// (eg. BuilderCAI::MoveInBuildRange) would misbehave
				// (eg. reject build orders)
				newPath.maxResPath.path.push_back(startPos);
				newPath.maxResPath.squares.push_back(int2(startPos.x / SQUARE_SIZE, startPos.z / SQUARE_SIZE));
			}
		}

		FinalizePath(&newPath, startPos, goalPos, result == IPath::CantGetCloser);
		newPath.searchResult = result;
		pathID = Store(newPath);
	}

	if (caller != nullptr)
		caller->Block();

	return pathID;
}
Exemplo n.º 22
0
std::vector<int2> TileMapCollisionHelper::get_next_collided_tile_coords(float x, float y, float velocity, float depth_of_body, float length_of_edge)
// returns the set of tile coordinates that will be collided with after the velocity is applied
{
    std::vector<int2> collided_tiles;

    if (velocity > 0) x += depth_of_body;

    int now = TileMap::world_to_tile(x);
    int next = TileMap::world_to_tile(x + velocity);

    if (now != next)
    {
        // new tiles have been entered
        int start_y = TileMap::world_to_tile(y);
        float inset_y = fmod(y, 16.0);
        int num_tiles_along_edge = std::max(1, (int)ceil((length_of_edge + inset_y) / 16));
        collided_tiles.reserve(num_tiles_along_edge);

        // add a list of tiles to the thing
        for (int i=0; i<num_tiles_along_edge; i++)
            collided_tiles.push_back(int2(next, start_y+i));
    }

    return collided_tiles;
}
Exemplo n.º 23
0
static void TestCatalog(skiatest::Reporter* reporter) {
    SkPDFCatalog catalog((SkPDFDocument::Flags)0);
    SkAutoTUnref<SkPDFInt> int1(new SkPDFInt(1));
    SkAutoTUnref<SkPDFInt> int2(new SkPDFInt(2));
    SkAutoTUnref<SkPDFInt> int3(new SkPDFInt(3));
    int1.get()->ref();
    SkAutoTUnref<SkPDFInt> int1Again(int1.get());

    catalog.addObject(int1.get(), false);
    catalog.addObject(int2.get(), false);
    catalog.addObject(int3.get(), false);

    REPORTER_ASSERT(reporter, catalog.getObjectNumberSize(int1.get()) == 3);
    REPORTER_ASSERT(reporter, catalog.getObjectNumberSize(int2.get()) == 3);
    REPORTER_ASSERT(reporter, catalog.getObjectNumberSize(int3.get()) == 3);

    SkDynamicMemoryWStream buffer;
    catalog.emitObjectNumber(&buffer, int1.get());
    catalog.emitObjectNumber(&buffer, int2.get());
    catalog.emitObjectNumber(&buffer, int3.get());
    catalog.emitObjectNumber(&buffer, int1Again.get());
    char expectedResult[] = "1 02 03 01 0";
    REPORTER_ASSERT(reporter, stream_equals(buffer, 0, expectedResult,
                                            strlen(expectedResult)));
}
void BOStationaryParticle::Draw(SDL_Texture* p_texture)
{
	int4 target = int4((int)m_position.x, (int)m_position.y, m_size.x, m_size.y);
	int4 source = int4(0, 0, m_size.x, m_size.y);

    BOGraphicInterface::DrawEx(p_texture, source, target, m_rotation, int2(source.z / 2, source.w / 2), m_opacity);
}
Exemplo n.º 25
0
void Grid::findAll(vector<int> &out, const IRect &view_rect, int flags) const {
	IRect grid_box(0, 0, m_size.x, m_size.y);

	for(int y = grid_box.min.y; y < grid_box.max.y; y++) {
		const int2 &row_rect = m_row_rects[y];
		if(row_rect.x >= view_rect.max.y || row_rect.y <= view_rect.min.y)
			continue;
		
		for(int x = grid_box.min.x; x < grid_box.max.x; x++) {
			int node_id = nodeAt(int2(x, y));
			const Node &node = m_nodes[node_id];
	
			if(!flagTest(node.obj_flags, flags) || !areOverlapping(view_rect, node.rect))
				continue;

			bool anything_found = false;
			const Object *objects[node.size];
			int count = extractObjects(node_id, objects, -1, flags);

			for(int n = 0; n < count; n++) {
				if(areOverlapping(view_rect, objects[n]->rect())) {
					if(objects[n]->node_id == -1)
						disableOverlap(objects[n]);
					out.push_back(objects[n] - &m_objects[0]);
					anything_found = true;
				}
			}

			if(!anything_found && node.is_dirty)
				updateNode(node_id);	
		}
	}

	clearDisables();
}
Exemplo n.º 26
0
	void HandleSDLMouseEvent (SDL_Event& event)
	{
		if (!mouse)
			return;

		switch (event.type) {
		case SDL_SYSWMEVENT:{
			SDL_SysWMmsg *msg = event.syswm.msg;
			if (msg->msg == 0x020B) { // WM_XBUTTONDOWN, beats me why it isn't defined by default
				if (msg->wParam & 0x20) // MK_XBUTTON1
					mouse->MousePress (mousepos.x, mousepos.y, 4);
				if (msg->wParam & 0x40) // MK_XBUTTON2
					mouse->MousePress (mousepos.x, mousepos.y, 5);
			}
			break;}
		case SDL_MOUSEMOTION: // the normal SDL method works fine in windowed mode 
			if(!fullscreen) {
				mousepos = int2(event.motion.x, event.motion.y);
				mouse->MouseMove(mousepos.x, mousepos.y);
			}
			break;
		case SDL_MOUSEBUTTONDOWN:
			if (event.button.button == SDL_BUTTON_WHEELUP)
				mouse->currentCamController->MouseWheelMove(scrollWheelSpeed);
			else if (event.button.button == SDL_BUTTON_WHEELDOWN)
				mouse->currentCamController->MouseWheelMove(-scrollWheelSpeed);
			else
				mouse->MousePress(mousepos.x, mousepos.y,event.button.button);
			break;
		case SDL_MOUSEBUTTONUP:
			mouse->MouseRelease(mousepos.x, mousepos.y,event.button.button);
			break;
		}
	}
Exemplo n.º 27
0
int Grid::pixelIntersect(const int2 &screen_pos, bool (*pixelTest)(const ObjectDef&, const int2&), int flags) const {
	IRect grid_box(0, 0, m_size.x, m_size.y);
	
	int best = -1;
	FBox best_box;

	for(int y = grid_box.min.y; y < grid_box.max.y; y++) {
		const int2 &row_rect = m_row_rects[y];
		if(row_rect.x >= screen_pos.y || row_rect.y <= screen_pos.y)
			continue;

		for(int x = grid_box.min.x; x < grid_box.max.x; x++) {
			int node_id = nodeAt(int2(x, y));
			const Node &node = m_nodes[node_id];

			if(!flagTest(node.obj_flags, flags) || !node.rect.isInside(screen_pos))
				continue;
			if(node.is_dirty)
				updateNode(node_id);	

			const Object *objects[node.size];
			int count = extractObjects(node_id, objects, -1, flags);

			for(int n = 0; n < count; n++)
				if(objects[n]->rect().isInside(screen_pos) && pixelTest(*objects[n], screen_pos)) {
					if(best == -1 || drawingOrder(objects[n]->bbox, best_box) == 1) {
						best = objects[n] - &m_objects[0];
						best_box = objects[n]->bbox;
					}
				}
		}
	}

	return best;
}
Exemplo n.º 28
0
	void MultiResSILLayer::ExtractVPLs(CameraPtr const & rsm_camera, LightSourcePtr const & light)
	{
		rsm_texs_[0]->BuildMipSubLevels();
		rsm_texs_[1]->BuildMipSubLevels();
		
		rsm_to_depth_derivate_pp_->Apply();
		
		float4x4 ls_to_es = rsm_camera->InverseViewMatrix() * g_buffer_camera_->ViewMatrix();
		float4x4 const & inv_proj = rsm_camera->InverseProjMatrix();
		LightSource::LightType type = light->Type();

		float4 vpl_params(static_cast<float>(VPL_COUNT), 2.0f, 
			              static_cast<float>(MIN_RSM_MIPMAP_SIZE), static_cast<float>(MIN_RSM_MIPMAP_SIZE * MIN_RSM_MIPMAP_SIZE));

		rsm_to_vpls_pps_[type]->SetParam(0, ls_to_es);
		rsm_to_vpls_pps_[type]->SetParam(1, vpl_params);
		rsm_to_vpls_pps_[type]->SetParam(2, light->Color());
		rsm_to_vpls_pps_[type]->SetParam(3, light->CosOuterInner());
		rsm_to_vpls_pps_[type]->SetParam(4, light->Falloff());
		rsm_to_vpls_pps_[type]->SetParam(5, g_buffer_camera_->InverseViewMatrix());
		float3 upper_left = MathLib::transform_coord(float3(-1, +1, 1), inv_proj);
		float3 upper_right = MathLib::transform_coord(float3(+1, +1, 1), inv_proj);
		float3 lower_left = MathLib::transform_coord(float3(-1, -1, 1), inv_proj);
		rsm_to_vpls_pps_[type]->SetParam(6, upper_left);
		rsm_to_vpls_pps_[type]->SetParam(7, upper_right - upper_left);
		rsm_to_vpls_pps_[type]->SetParam(8, lower_left - upper_left);
		rsm_to_vpls_pps_[type]->SetParam(9, int2(1, 0));
		rsm_to_vpls_pps_[type]->SetParam(10, 0.12f * rsm_camera->FarPlane());
		rsm_to_vpls_pps_[type]->SetParam(11, static_cast<float>(rsm_texs_[0]->NumMipMaps() - 1));

		rsm_to_vpls_pps_[type]->Apply();
	}
Exemplo n.º 29
0
void Grid::findAll(vector<int> &out, const FBox &box, int ignored_id, int flags) const {
	IRect grid_box = nodeCoords(box);

	for(int y = grid_box.min.y; y <= grid_box.max.y; y++)
		for(int x = grid_box.min.x; x <= grid_box.max.x; x++) {
			int node_id = nodeAt(int2(x, y));
			const Node &node = m_nodes[node_id];

			if(!flagTest(node.obj_flags, flags) || !areOverlapping(box, node.bbox))
				continue;
			bool anything_found = false;

			const Object *objects[node.size];
			int count = extractObjects(node_id, objects, ignored_id, flags);

			for(int n = 0; n < count; n++)
				if(areOverlapping(box, objects[n]->bbox)) {
					if(objects[n]->node_id == -1)
						disableOverlap(objects[n]);
					out.push_back(objects[n] - &m_objects[0]);
					anything_found = true;
				}

			if(!anything_found && node.is_dirty)
				updateNode(node_id);	
		}

	clearDisables();
}
Exemplo n.º 30
0
void Window::Print(const int2 & coord, const char * format, ...)
{
    char buffer[1024];
    va_list args;
    va_start(args, format);
    vsnprintf(buffer, sizeof(buffer), format, args);
    va_end(args);

    glPushAttrib(GL_ALL_ATTRIB_BITS);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, fontTexture);
    glBegin(GL_QUADS);
    int2 glyphSize = {8,14};
    float2 texScale = float2(glyphSize)/128.0f;
    auto c0 = coord;
    for(auto ch : buffer)
    {
        if(!ch) break;
        if(isprint(ch))
        {
            auto t0 = float2(int2((ch-32)%16, (ch-32)/16)) * texScale, t1 = t0 + texScale;
            auto c1 = c0 + int2{8,14};
            glTexCoord2f(t0.x,t0.y); glVertex2i(c0.x,c0.y);
            glTexCoord2f(t1.x,t0.y); glVertex2i(c1.x,c0.y);
            glTexCoord2f(t1.x,t1.y); glVertex2i(c1.x,c1.y);
            glTexCoord2f(t0.x,t1.y); glVertex2i(c0.x,c1.y);
        }
        c0.x += 8;
    }
    glEnd();
    glPopAttrib();
}