📄 minimap.cpp
字号:
/*************************************************************************** map.h - description ------------------- begin : Thu Jan 29 2004 copyright : (C) 2004 by Daroth-U email : daroth-u@ifrance.com***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include "minimap.h"/* How to enhance it ? (or what will be done soon)- manage differents display mode of the minimap -> only walls and doors, add creatures...- handle mouse click on the minimap- dynamically free memory unused for pos[..][..]- activate the "fog" - put color in the shape to avoid tests during construction of the minimap */#define DEBUG_MINIMAP 0MiniMap :: MiniMap(Scourge *scourge){ this->scourge = scourge; zoomFactor = 1.2f; // default we see the entire minimap effectiveWidth = effectiveHeight = 0; maxX = maxY = -1; minX = minY = 3000; midX = midY = -1.0f; screenHeight = screenHeight = scourge->getSDLHandler()->getScreen()->h; ; showMiniMap = true; win = new Window( scourge->getSDLHandler(), 0, 400, 200, 150, strdup("Minimap"), scourge->getShapePalette()->getGuiTexture() ); canvas = new Canvas( 0, 0, 200, 150, this ); if(DEBUG_MINIMAP) fprintf(stderr, "mini map =( %d x %d )\n", MINI_MAP_WIDTH, MINI_MAP_DEPTH); for (int x = 0 ; x < MINI_MAP_WIDTH ; x++){ for(int y = 0; y < MINI_MAP_DEPTH ; y++){ pos[x][y].r = 0.0; pos[x][y].g = 0.0; pos[x][y].b = 0.0; pos[x][y].visible = true; } } textureSizeH = textureSizeW = 0; textureInMemory = NULL; mustBuildTexture = true;}MiniMap :: ~MiniMap(){ if(textureInMemory != NULL){ free(textureInMemory); textureInMemory = NULL; } }void MiniMap :: computeDrawValues(){ effectiveWidth = int(maxX - minX); effectiveHeight = int(maxY - minY); midX = (effectiveWidth + minX)/2; midY = (effectiveHeight + minY)/2; if(minX >= 2) minX -= 2; if(minY >= 2) minY -= 2; if(DEBUG_MINIMAP) { fprintf(stderr, "effWidth : %d, effHeight : %d\n", effectiveWidth, effectiveHeight); } // Compute dimensions of the texture that will hold the minimap // Each dimension must be a power of 2 int b; b = int(ceil(log(double(effectiveHeight))/log(2.0))); textureSizeH = int(pow(2.0, b)); b = int(ceil(log(double(effectiveWidth))/log(2.0))); textureSizeW = int(pow(2.0, b)); if(DEBUG_MINIMAP){ fprintf(stderr, "textSzW = %d, textSzH : %d\n", textureSizeW, textureSizeH); } }// Create and fill the texture for the minimapvoid MiniMap :: buildTexture(int xCoord, int yCoord){ // Create texture and copy minimap date from backbuffer on it textureInMemory = (unsigned char *) malloc(textureSizeH * textureSizeW * 4); glGenTextures(1, texture); glBindTexture(GL_TEXTURE_2D, texture[0]); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // filtre appliqu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -