Ejemplo n.º 1
0
Vector2i
Playfield::get_pos() const
{
  return Vector2i(static_cast<int>(state.get_pos().x), 
                  static_cast<int>(state.get_pos().y));
}
Ejemplo n.º 2
0
void
Playfield::set_viewpoint(int x, int y)
{
  state.set_pos(Vector2i(x, y));
}
Ejemplo n.º 3
0
Vector2i Window::getPosition() const
{
    return m_impl ? m_impl->getPosition() : Vector2i();
}
Ejemplo n.º 4
0
	void LevelChunk::Draw() const
	{
		Matrix4f mat = Matrix4f::IDENTITY;
		for (int y = 0; y < SIDE; y++)
		{
			for (int x = 0; x < SIDE; x++)
			{
				const auto& cell = GetCell(Vector2i(x, y));
				if (cell._floor < 0)
					continue;

				const Vector3f offset = _position + Vector3f(x, 0, y) * LevelCell::SIZE;

				mat = Matrix4f::createTranslate(offset.x, offset.y, offset.z);
				_level->GetPrefabs()[cell._floor]->Draw(mat);

				for (int i = 0; i < 4; i++)
				{
					if (cell._wall[i] < 0)
						continue;

					const Matrix4f mat2 = LevelCell::WALL_OFFSET[i] * mat;
					_level->GetPrefabs()[cell._wall[i]]->Draw(mat2);
				}

// 				if (cell._wall[DIR_WEST] >= 0)
// 				{
// 					glPushMatrix();
// 					glTranslatef(-0.5f * LevelCell::SIZE, 0, 0);
// 					_level->GetPrefabs()[cell._wall[DIR_WEST]]->Draw();
// 					glPopMatrix();
// 				}
// 
// 				if (cell._wall[DIR_EAST] >= 0)
// 				{
// 					glPushMatrix();
// 					glTranslatef(+0.5f * LevelCell::SIZE, 0, 0);
// 					_level->GetPrefabs()[cell._wall[DIR_EAST]]->Draw();
// 					glPopMatrix();
// 				}
// 
// 				if (cell._wall[DIR_NORTH] >= 0)
// 				{
// 					glPushMatrix();
// 					glRotatef(90, 0, 1, 0);
// 					glTranslatef(+0.5f * LevelCell::SIZE, 0, 0);
// 					_level->GetPrefabs()[cell._wall[DIR_NORTH]]->Draw();
// 					glPopMatrix();
// 				}
// 
// 				if (cell._wall[DIR_SOUTH] >= 0)
// 				{
// 					glPushMatrix();
// 					glRotatef(90, 0, 1, 0);
// 					glTranslatef(-0.5f * LevelCell::SIZE, 0, 0);
// 					_level->GetPrefabs()[cell._wall[DIR_SOUTH]]->Draw();
// 					glPopMatrix();
// 				}
			}
		}
	}
Ejemplo n.º 5
0
ref<Bitmap> ConstantFloatTexture::getBitmap(const Vector2i &sizeHint) const {
	ref<Bitmap> result = new Bitmap(Bitmap::ELuminance, Bitmap::EFloat, Vector2i(1, 1));
	*result->getFloatData() = m_value;
	return result;
}
Ejemplo n.º 6
0
void NNUtilities::normalizeContrast(GrayscaledImage& output, const float percent)
{
  normalizeContrast(output[0], Vector2i(output.width, output.height), percent);
}
Ejemplo n.º 7
0
Vector2i Window::getPosition() const {
    return mBase ? mBase->getPosition() : Vector2i();
}
// Attempts to load the texture from the source.
bool TextureResource::Load(RenderInterface* render_interface) const
{
	// Check for special loader tokens.
	if (!source.Empty() &&
		source[0] == '?')
	{
		Vector2i dimensions;

		bool delete_data = false;
		const byte* data = NULL;

		// Find the generation protocol and generate the data accordingly.
		String protocol = source.Substring(1, source.Find("::") - 1);
		if (protocol == "font")
		{
			// The requested texture is a font layer.
			delete_data = true;

			FontFaceHandle* handle;
			FontEffect* layer_id;
			int layout_id;
			int texture_id;

			if (sscanf(source.CString(), "?font::%p/%p/%d/%d", &handle, &layer_id, &layout_id, &texture_id) == 4)
			{
				handle->GenerateLayerTexture(data,
											 dimensions,
											 layer_id,
											 layout_id,
											 texture_id);
			}
		}

		// If texture data was generated, great! Otherwise, fallback to the LoadTexture() code and
		// hope the client knows what the hell to do with the question mark in their file name.
		if (data != NULL)
		{
			TextureHandle handle;
			bool success = render_interface->GenerateTexture(handle, data, dimensions);

			if (delete_data)
				delete[] data;

			if (success)
			{
				texture_data[render_interface] = TextureData(handle, dimensions);
				return true;
			}
			else
			{
				Log::Message(Log::LT_WARNING, "Failed to generate internal texture %s.", source.CString());
				texture_data[render_interface] = TextureData(0, Vector2i(0, 0));

				return false;
			}
		}
	}

	TextureHandle handle;
	Vector2i dimensions;
	if (!render_interface->LoadTexture(handle, dimensions, source))
	{
		Log::Message(Log::LT_WARNING, "Failed to load texture from %s.", source.CString());
		texture_data[render_interface] = TextureData(0, Vector2i(0, 0));

		return false;
	}

	texture_data[render_interface] = TextureData(handle, dimensions);
	return true;
}
Ejemplo n.º 9
0
Vector2i Slider::preferredSize(NVGcontext *) const {
    return Vector2i(70, 12);
}
Ejemplo n.º 10
0
void Pathfinder::GeneratePath()
{
    sLog.Write("Generating new path");

    // Destroy old path
    Path = std::stack<Vector2i>();

    // Zero out status grid
    std::memset(PathfindingStatusGrid.get(), 0, MAX_MAP_HEIGHT * MAX_MAP_WIDTH * sizeof(uint8));

    // Get Node with same position as creature in pathfinding grid
    PathfinderNode* pOriginNode = &(PathfindingGrid[MAX_MAP_HEIGHT * pOrigin->GetY() + pOrigin->GetX()]);

    // Origin node does not have parent node
    pOriginNode->pParent = nullptr;

    // Origin node does not have G cost
    pOriginNode->G = 0;
    pOriginNode->H = 10 * math::GetManhattanDistance(Vector2i(pOriginNode->Position.x, pOriginNode->Position.y), Target);

    // Add origin node to queue
    OpenList.push(pOriginNode);

    do
    {
        // Grab node with highest priority
        PathfinderNode* pCurrent = OpenList.top();
        OpenList.pop();

        // Move it to "closed" list
        PathfindingStatusGrid[MAX_MAP_HEIGHT * pCurrent->Position.y + pCurrent->Position.x] = CLOSED;

        // If current node has same coordinates as target, we found our path
        if(pCurrent->Position == Target)
        {
            // Create path using parents to track down origin
            while(pCurrent->pParent != nullptr)
            {
                Path.push(pCurrent->Position);
                pCurrent = pCurrent->pParent;
            }
            
            // Destroy open list
            OpenList.clear();
            
            return;
        }

        // For each of adjacent nodes
        // if it is not out of bounds
        // and if tile is 'walkable',
        // check its status

        // Upper
        if(pCurrent->Position.y != 0)
        {
            CheckNode(pCurrent, 0, -1, 10);
        }

        // Lower
        if(pCurrent->Position.y != pTileGrid->size()-1)
        {
            CheckNode(pCurrent, 0, 1, 10);
        }

        // Right
        if(pCurrent->Position.x != (*pTileGrid)[0].size()-1)
        {
            CheckNode(pCurrent, 1, 0, 10);
        }

        // Left
        if(pCurrent->Position.x != 0)
        {
            CheckNode(pCurrent, -1, 0, 10);
        }

        // Upper-right
        if(pCurrent->Position.x != (*pTileGrid)[0].size()-1 && pCurrent->Position.y != 0)
        {
            CheckNode(pCurrent, 1, -1, 14);
        }

        // Upper-left
        if(pCurrent->Position.x != 0 && pCurrent->Position.y != 0)
        {
            CheckNode(pCurrent, -1, -1, 14);
        }

        // Lower-right
        if(pCurrent->Position.x != (*pTileGrid)[0].size()-1 && pCurrent->Position.y != pTileGrid->size()-1)
        {
            CheckNode(pCurrent, 1, 1, 14);
        }

        // Lower-left
        if(pCurrent->Position.x != 0 && pCurrent->Position.y != pTileGrid->size()-1)
        {
            CheckNode(pCurrent, -1, 1, 14);
        }

    } while(!OpenList.empty());

    sLog.Write("Could not generate path");
}
Ejemplo n.º 11
0
Vector2i WindowWorld::GetCameraTarget() const
{
    return m_world ? m_world->GetCamera()->GetTarget() : Vector2i();
}
Ejemplo n.º 12
0
void WindowWorld::OnMouseWheel(const InputMouse& args)
{
    Window::OnMouseWheel(args);

    if (!m_world)
    {
        return;
    }

    const Vector2i position = m_world->GetCamera()->Project(GetBounds(), args.position);

    for (ListenerList::iterator iter = m_listeners.begin(); iter != m_listeners.end(); ++iter)
    {
        (*iter)->OnWorldMouseWheel(InputMouse(args.button, args.buttonState, position, Vector2i(0, 0), args.wheel, args.modifier));
    }
}
Ejemplo n.º 13
0
void WindowWorld::OnMouseButtonDown(const InputMouse& args)
{
    Window::OnMouseButtonDown(args);

    if (!m_world)
    {
        return;
    }

    const Vector2i position = m_world->GetCamera()->Project(GetBounds(), args.position);

    for (ListenerList::iterator iter = m_listeners.begin(); iter != m_listeners.end(); ++iter)
    {
        (*iter)->OnWorldMouseButtonDown(InputMouse(args.button, args.buttonState, position, Vector2i(0, 0), args.wheel, args.modifier));
    }

#ifdef DEVELOPER
    if (args.modifier & KMOD_SHIFT && args.button == SDL_BUTTON_LEFT)
    {
        boost::shared_ptr<Actor> actor = PickActor(position).lock();
        if (actor)
        {
            TRACE_INFO(boost::format("Actor:\n\tAlias = %s\n\tId = %d\n\tName = %s\n\tLayer = %d\n\tPosition = (%.1f, %.1f)") %
                       actor->GetAlias() % actor->GetId() % actor->GetName() % actor->GetLayer() % actor->GetPosition().x % actor->GetPosition().y);
        }
    }
#endif
}
Ejemplo n.º 14
0
void
Playfield::scroll (int x, int y)
{
  state.set_pos(state.get_pos() + Vector2i(x, y));
}
Ejemplo n.º 15
0
ref<Bitmap> ConstantSpectrumTexture::getBitmap(const Vector2i &sizeHint) const {
	ref<Bitmap> result = new Bitmap(Bitmap::ESpectrum, Bitmap::EFloat, Vector2i(1, 1));
	*((Spectrum *) result->getFloatData()) = m_value;
	return result;
}
Ejemplo n.º 16
0
	bool render(Scene *scene, RenderQueue *queue, 
		const RenderJob *job, int sceneResID, int cameraResID, int samplerResID) {
		ref<Scheduler> sched = Scheduler::getInstance();
		ref<Camera> camera = scene->getCamera();
		ref<Film> film = camera->getFilm();
		size_t nCores = sched->getCoreCount();
		Sampler *cameraSampler = (Sampler *) sched->getResource(samplerResID, 0);
	
		size_t sampleCount = cameraSampler->getSampleCount();
		Log(EInfo, "Starting render job (%ix%i, " SIZE_T_FMT " %s, " SIZE_T_FMT 
			" %s, " SSE_STR ") ..", film->getCropSize().x, film->getCropSize().y, 
			sampleCount, sampleCount == 1 ? "sample" : "samples", nCores, 
			nCores == 1 ? "core" : "cores");

		Vector2i cropSize = film->getCropSize();
		Point2i cropOffset = film->getCropOffset();

		m_gatherPoints.clear();
		m_running = true;
		for (size_t i=0; i<m_blocks.size(); ++i)
			m_blocks[i]->decRef();
		m_blocks.clear();

		m_totalEmitted = 0;
		bool needsLensSample = camera->needsLensSample();
		bool needsTimeSample = camera->needsTimeSample();
		Log(EInfo, "Creating approximately %i gather points", cropSize.x*cropSize.y*sampleCount);
		Point2 lensSample, sample;
		RayDifferential eyeRay;
		Float timeSample = 0;
		m_filter = camera->getFilm()->getTabulatedFilter();
		Vector2 filterSize = m_filter->getFilterSize();
		int borderSize = (int) std::ceil(std::max(filterSize.x, filterSize.y));

		ref<Sampler> independentSampler = static_cast<Sampler *> (PluginManager::getInstance()->
			createObject(MTS_CLASS(Sampler), Properties("independent")));

		/* Create a sampler instance for every core */
		std::vector<SerializableObject *> samplers(sched->getCoreCount());
		for (size_t i=0; i<sched->getCoreCount(); ++i) {
			ref<Sampler> clonedSampler = independentSampler->clone();
			clonedSampler->incRef();
			samplers[i] = clonedSampler.get();
		}

		int independentSamplerResID = sched->registerManifoldResource(samplers); 
		for (size_t i=0; i<sched->getCoreCount(); ++i)
			samplers[i]->decRef();

#ifdef MTS_DEBUG_FP
		enableFPExceptions();
#endif

		/* Create gather points in blocks so that gathering can be parallelized later on */
		for (int yofs=0; yofs<cropSize.y; yofs += m_blockSize) {
			for (int xofs=0; xofs<cropSize.x; xofs += m_blockSize) {
				ImageBlock *block = new ImageBlock(Vector2i(m_blockSize, m_blockSize), borderSize, 
					true, true, false, false);
				block->setSize(Vector2i(m_blockSize, m_blockSize));
				block->setOffset(Point2i(cropOffset.x + xofs, cropOffset.y + yofs));
				block->incRef();
				std::vector<GatherPoint> gatherPoints;
				gatherPoints.reserve(m_blockSize*m_blockSize*sampleCount);
				for (int yofsInt = 0; yofsInt < m_blockSize; ++yofsInt) {
					if (yofsInt + yofs >= cropSize.y)
						continue;
					for (int xofsInt = 0; xofsInt < m_blockSize; ++xofsInt) {
						if (xofsInt + xofs >= cropSize.x)
							continue;
						int y = cropOffset.y + yofs + yofsInt;
						int x = cropOffset.x + xofs + xofsInt;
						cameraSampler->generate();
						for (size_t j = 0; j<sampleCount; j++) {
							if (needsLensSample)
								lensSample = cameraSampler->next2D();
							if (needsTimeSample)
								timeSample = cameraSampler->next1D();
							sample = cameraSampler->next2D();
							sample.x += x; sample.y += y;
							camera->generateRayDifferential(sample, 
								lensSample, timeSample, eyeRay);
							size_t offset = gatherPoints.size();
							Float count = (Float) createGatherPoints(scene, eyeRay, sample, 
									cameraSampler, Spectrum(1.0f),
								gatherPoints, 1);
							if (count > 1) { // necessary because of filter weight computation
								for (int i = 0; i<count; ++i)
									gatherPoints[offset+i].weight *= count;
							}

							cameraSampler->advance();
						}
					}
				}
				m_blocks.push_back(block);
				m_gatherPoints.push_back(gatherPoints);
			}
		}

		int it=0;
		while (m_running) 
			photonMapPass(++it, queue, job, film, sceneResID, cameraResID, independentSamplerResID);

#ifdef MTS_DEBUG_FP
		disableFPExceptions();
#endif

		sched->unregisterResource(independentSamplerResID);
		return true;
	}
Ejemplo n.º 17
0
/*!***********************************************************************
 @Function		OnForeground
 @Access		public 
 @Returns		void
 @Description	
*************************************************************************/
void ViewGameFinished::OnForeground()
	{
	// Screen coordinates for Menu are in Retina iPhone (i.e 960 x 640)
	Sint32 ViewW = GetScreenDimensions(false).x;
	Sint32 ViewH = GetScreenDimensions(false).y;
	Sint32 ViewHW = ViewW / 2;

	//GraphicsSystem* pGfx = GetApp()->GetGraphicsSystem();
	TXChar szBuffer[256];
	m_Messages.resize(5);

	m_Messages[0].Set(GWSTR(enumSTRING_GameOver), false, false, 0.001f);
	m_Messages[0].Layout(m_FontTitle, Vector2i(ViewHW, ViewH-60), enumTEXTJUSTIFY_Centre);

	sprintf(szBuffer, GWSTR(enumSTRING_XWins), m_pWinner->GetName());
	m_Messages[1].Set(szBuffer, false, false, 0.001f);
	m_Messages[1].Layout(m_FontMenu, Vector2i(ViewHW, ViewH-200), enumTEXTJUSTIFY_Centre);

	if(m_GameData.m_uiNumPlayers == 1)
		{
		sprintf(szBuffer, GWSTR(enumSTRING_ScoreX), m_GameData.m_pPlayers[enumPLAYER_1]->GetScore());
		m_Messages[2].Set(szBuffer, false, false, 0.001f);
		m_Messages[2].Layout(m_FontMenu, Vector2i(100, ViewH-280), enumTEXTJUSTIFY_Left);

		sprintf(szBuffer, GWSTR(enumSTRING_BestScoreX), m_GameData.m_pPlayers[enumPLAYER_1]->GetScore());
		m_Messages[3].Set(szBuffer, false, false, 0.001f);
		m_Messages[3].Layout(m_FontMenu, Vector2i(100, ViewH-320), enumTEXTJUSTIFY_Left);
		}
	else
		{
		char szSprintfBuf[256];
		if(m_GameData.m_eGameType == enumGWGAMETYPE_Rounds)		// Print Rounds Won for each player
			{
			sprintf(szSprintfBuf, "%s %s", GWSTR(enumSTRING_Player1), GWSTR(enumSTRING_RoundsWonX));
			sprintf(szBuffer, szSprintfBuf, m_GameData.m_pPlayers[enumPLAYER_1]->GetRoundsWon());
			m_Messages[2].Set(szBuffer, false, false, 0.001f);
			m_Messages[2].Layout(m_FontMenu, Vector2i(100, ViewH-280), enumTEXTJUSTIFY_Left);

			sprintf(szSprintfBuf, "%s %s", GWSTR(enumSTRING_Player2), GWSTR(enumSTRING_RoundsWonX));
			sprintf(szBuffer, szSprintfBuf, m_GameData.m_pPlayers[enumPLAYER_2]->GetRoundsWon());
			m_Messages[3].Set(szBuffer, false, false, 0.001f);
			m_Messages[3].Layout(m_FontMenu, Vector2i(100, ViewH-320), enumTEXTJUSTIFY_Left);
			}
		else														// Print Score for each player
			{
			sprintf(szSprintfBuf, "%s %s", GWSTR(enumSTRING_Player1), GWSTR(enumSTRING_ScoreX));
			sprintf(szBuffer, szSprintfBuf, m_GameData.m_pPlayers[enumPLAYER_1]->GetScore());
			m_Messages[2].Set(szBuffer, false, false, 0.001f);
			m_Messages[2].Layout(m_FontMenu, Vector2i(100, ViewH-280), enumTEXTJUSTIFY_Left);

			sprintf(szSprintfBuf, "%s %s", GWSTR(enumSTRING_Player2), GWSTR(enumSTRING_ScoreX));
			sprintf(szBuffer, szSprintfBuf, m_GameData.m_pPlayers[enumPLAYER_2]->GetScore());
			m_Messages[3].Set(szBuffer, false, false, 0.001f);
			m_Messages[3].Layout(m_FontMenu, Vector2i(100, ViewH-320), enumTEXTJUSTIFY_Left);
			}
		}

	m_Messages[4].Set(GWSTR(enumSTRING_MainMenu), true, false, 0.01f);
	m_Messages[4].Layout(m_FontMenu, Vector2i(100, 100), enumTEXTJUSTIFY_Left);

	m_Messages[0].pNext = &m_Messages[1];
	m_Messages[1].pNext = &m_Messages[2];
	m_Messages[2].pNext = &m_Messages[3];
	m_Messages[3].pNext = &m_Messages[4];

	m_MsgRoot = &m_Messages[0];

	// --- Set Main Menu button rect
	m_RectMainMenu.m_fX = 100.0f;		m_RectMainMenu.m_fW = m_RectMainMenu.m_fX + 250.0f;
	m_RectMainMenu.m_fY = 94.0f;		m_RectMainMenu.m_fH = m_RectMainMenu.m_fY + 36.0f;
	}