Beispiel #1
0
void Engine::Render(const std::vector<uint>& list) {
    CDEBUG("render");
    const Point res = video->GetResolution();

    if (!_isMapLoaded) {
        return;
    }

    tiles->UpdateAnimation(GetTime());

    if (cameraTarget) {
        const Map::Layer* layer = map.GetLayer(cameraTarget->layerIndex);

        SetCamera(Point(
            cameraTarget->x + cameraTarget->sprite->nHotw / 2 - res.x / 2 + layer->x,
            cameraTarget->y + cameraTarget->sprite->nHoth / 2 - res.y / 2 + layer->y));
    }

    // Note that we do not clear the screen here.  This is intentional.

    for (uint i = 0; i < list.size(); i++) {
        uint j = list[i];
        if (j < map.NumLayers()) {
            RenderLayer(j);
            RenderEntities(j);
        }
    }

    DoHook(_hookRetrace);
}
Beispiel #2
0
void CMapView::Render(const RECT& r)
{
    char *s;
    char renderstring[50];
    int  laycount=0;
    
    strcpy(renderstring,pMap->GetRString().c_str());
    
    s=renderstring;
    
    pGraph->Clear();
    
    if (xwin<0) xwin=0;
    if (ywin<0) ywin=0;
    
    while (*s!='\0')
    {
        switch (*s)
        {
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6': 
            RenderLayer(*s-'1',laycount!=0?true:false,r);
            laycount++;
            break;
        }
        s++;
    }
    
    DrawObstructions(r);
    DrawZones(r);
    DrawEntities(r);
    DrawSelection(r);
}
Beispiel #3
0
// Renders the map
void _Map::Render(_Camera *Camera, _Stats *Stats, _Object *ClientPlayer, double BlendFactor, int RenderFlags) {

	// Set lights for editor
	if(!ClientPlayer) {
		glm::vec4 AmbientLightEditor(1.0f, 1.0f, 1.0f, 1.0f);
		Assets.Programs["pos_uv"]->AmbientLight = AmbientLightEditor;
		Assets.Programs["pos_uv"]->LightPosition = glm::vec3(0, 0, 0);
		Assets.Programs["pos_uv_static"]->AmbientLight = AmbientLightEditor;
	}
	else {

		// Setup day night cycle
		SetAmbientLightByClock();

		// Setup lights
		glm::vec3 LightPosition(glm::vec3(ClientPlayer->Position, 1) + glm::vec3(0.5f, 0.5f, 0));
		glm::vec3 LightAttenuation(0.0f, 1.0f, 0.0f);

		Assets.Programs["pos_uv"]->LightAttenuation = LightAttenuation;
		Assets.Programs["pos_uv"]->LightPosition = LightPosition;
		Assets.Programs["pos_uv"]->AmbientLight = AmbientLight;
	}

	// Draw background map
	if(BackgroundMap) {
		BackgroundMap->Clock = Clock;
		BackgroundMap->SetAmbientLightByClock();
		if(!ClientPlayer)
			BackgroundMap->AmbientLight = glm::vec4(1.0f);
		Assets.Programs["pos_uv_static"]->AmbientLight = BackgroundMap->AmbientLight;

		// Get camera position
		glm::vec3 DrawPosition;
		Camera->GetDrawPosition(BlendFactor, DrawPosition);
		DrawPosition -= BackgroundOffset;

		//BackgroundOffset.z = -10.0f;
		float Width = DrawPosition.z * Graphics.AspectRatio;
		float Height = DrawPosition.z;

		// Get render bounds of background tiles
		glm::vec4 BackgroundBounds;
		BackgroundBounds[0] = glm::clamp(-Width + DrawPosition.x, 0.0f, (float)BackgroundMap->Size.x);
		BackgroundBounds[1] = glm::clamp(-Height + DrawPosition.y, 0.0f, (float)BackgroundMap->Size.y);
		BackgroundBounds[2] = glm::clamp(Width + DrawPosition.x, 0.0f, (float)BackgroundMap->Size.x);
		BackgroundBounds[3] = glm::clamp(Height + DrawPosition.y, 0.0f, (float)BackgroundMap->Size.y);

		BackgroundMap->RenderLayer("pos_uv_static", BackgroundBounds, BackgroundOffset, 0, true);
		BackgroundMap->RenderLayer("pos_uv_static", BackgroundBounds, BackgroundOffset, 1, true);
	}

	// Get render bounds
	glm::vec4 Bounds = Camera->GetAABB();
	Bounds[0] = glm::clamp(Bounds[0], 0.0f, (float)Size.x);
	Bounds[1] = glm::clamp(Bounds[1], 0.0f, (float)Size.y);
	Bounds[2] = glm::clamp(Bounds[2], 0.0f, (float)Size.x);
	Bounds[3] = glm::clamp(Bounds[3], 0.0f, (float)Size.y);

	// Draw layers
	RenderLayer("pos_uv", Bounds, glm::vec3(0.0f), 0);
	RenderLayer("pos_uv", Bounds, glm::vec3(0.0f), 1);

	// Render objects
	for(const auto &Object : Objects) {
		Object->Render(ClientPlayer);
	}

	// Check for flags
	if(!RenderFlags)
		return;

	// Draw map boundaries
	if(RenderFlags & FILTER_BOUNDARY) {
		Graphics.SetProgram(Assets.Programs["pos"]);
		Graphics.SetVBO(VBO_NONE);
		Graphics.SetColor(COLOR_RED);
		Graphics.DrawRectangle(glm::vec2(-0.51f, -0.51f), glm::vec2(Size.x - 0.49f, Size.y - 0.49f));
	}

	// Draw zone overlays
	if((RenderFlags & FILTER_ZONE)) {
		Graphics.SetProgram(Assets.Programs["pos"]);
		Graphics.SetVBO(VBO_NONE);
		for(int j = (int)Bounds[1]; j < Bounds[3]; j++) {
			for(int i = (int)Bounds[0]; i < Bounds[2]; i++) {
				_Tile *Tile = &Tiles[i][j];

				// Draw zone color
				if(!Tile->Wall && Tile->Zone > 0) {
					Graphics.SetColor(ZoneColors[Tile->Zone % 6]);
					Graphics.DrawRectangle(glm::vec2(i, j), glm::vec2(i, j), true);
				}
			}
		}
	}

	// Draw text overlay
	for(int j = (int)Bounds[1]; j < Bounds[3]; j++) {
		for(int i = (int)Bounds[0]; i < Bounds[2]; i++) {
			_Tile *Tile = &Tiles[i][j];
			glm::vec3 DrawPosition = glm::vec3(i, j, 0) + glm::vec3(0.5f, 0.5f, 0);

			// Draw wall
			if(Tile->Wall) {
				if(RenderFlags & FILTER_WALL)
					Assets.Fonts["hud_medium"]->DrawText("W", glm::vec2(DrawPosition), COLOR_WHITE, CENTER_MIDDLE, 1.0f / 64.0f);
			}
			else {

				// Draw zone number
				if((RenderFlags & FILTER_ZONE) && Tile->Zone > 0)
					Assets.Fonts["hud_medium"]->DrawText(std::to_string(Tile->Zone).c_str(), glm::vec2(DrawPosition), COLOR_WHITE, CENTER_MIDDLE, 1.0f / 64.0f);

				// Draw PVP
				if((RenderFlags & FILTER_PVP) && Tile->PVP)
					Assets.Fonts["hud_medium"]->DrawText("PVP", glm::vec2(DrawPosition), COLOR_RED, CENTER_MIDDLE, 1.0f / 64.0f);
			}

			// Draw event info
			if(Tile->Event.Type > 0) {
				std::string EventText = Stats->EventNames[Tile->Event.Type].ShortName + std::string(" ") + std::to_string(Tile->Event.Data);
				Assets.Fonts["hud_medium"]->DrawText(EventText, glm::vec2(DrawPosition), COLOR_CYAN, CENTER_MIDDLE, 1.0f / 64.0f);
			}
		}
	}
}