mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
otoczka mapy i drobne poprawki (w tym wydajnościowe)
This commit is contained in:
parent
e060988289
commit
82547d6829
@ -10,6 +10,7 @@
|
||||
#include "CBuildingHandler.h"
|
||||
#include "CObjectHandler.h"
|
||||
#include "CMusicHandler.h"
|
||||
#include "CSemiLodHandler.h"
|
||||
|
||||
/*
|
||||
CGameInfo class
|
||||
@ -28,6 +29,7 @@ public:
|
||||
CBuildingHandler * buildh;
|
||||
CObjectHandler * objh;
|
||||
CMusicHandler * mush;
|
||||
CSemiLodHandler * sspriteh;
|
||||
};
|
||||
|
||||
#endif //CGAMEINFO_H
|
38
CMT.cpp
38
CMT.cpp
@ -24,6 +24,7 @@
|
||||
#include "CObjectHandler.h"
|
||||
#include "CGameInfo.h"
|
||||
#include "CMusicHandler.h"
|
||||
#include "CSemiLodHandler.h"
|
||||
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
|
||||
# include <fcntl.h>
|
||||
# include <io.h>
|
||||
@ -259,6 +260,8 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
CGameInfo * cgi = new CGameInfo;
|
||||
CGameInfo::mainObj = cgi;
|
||||
cgi->mush = mush;
|
||||
cgi->sspriteh = new CSemiLodHandler();
|
||||
cgi->sspriteh->openLod("H3sprite.lod");
|
||||
CArtHandler * arth = new CArtHandler;
|
||||
arth->loadArtifacts();
|
||||
cgi->arth = arth;
|
||||
@ -280,7 +283,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
CObjectHandler * objh = new CObjectHandler;
|
||||
objh->loadObjects();
|
||||
cgi->objh = objh;
|
||||
CAmbarCendamo * ac = new CAmbarCendamo("Cave of Gerfrex"); //4gryf
|
||||
CAmbarCendamo * ac = new CAmbarCendamo("4gryf"); //4gryf
|
||||
CMapHeader * mmhh = new CMapHeader(ac->bufor); //czytanie nag³ówka
|
||||
cgi->ac = ac;
|
||||
THC std::cout<<"Wczytywanie pliku: "<<tmh.getDif()<<std::endl;
|
||||
@ -308,6 +311,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
bool scrollingRight = false;
|
||||
bool scrollingUp = false;
|
||||
bool scrollingDown = false;
|
||||
bool updateScreen = false;
|
||||
for(;;) // main loop
|
||||
{
|
||||
try
|
||||
@ -352,6 +356,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
if (zz)
|
||||
zz--;
|
||||
else zz++;
|
||||
updateScreen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -388,29 +393,44 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
if(scrollingLeft)
|
||||
{
|
||||
if(xx>0)
|
||||
{
|
||||
xx--;
|
||||
updateScreen = true;
|
||||
}
|
||||
}
|
||||
if(scrollingRight)
|
||||
{
|
||||
if(xx<ac->map.width-25)
|
||||
if(xx<ac->map.width-25+8)
|
||||
{
|
||||
xx++;
|
||||
updateScreen = true;
|
||||
}
|
||||
}
|
||||
if(scrollingUp)
|
||||
{
|
||||
if(yy>0)
|
||||
{
|
||||
yy--;
|
||||
updateScreen = true;
|
||||
}
|
||||
}
|
||||
if(scrollingDown)
|
||||
{
|
||||
if(yy<ac->map.height-18)
|
||||
if(yy<ac->map.height-18+8)
|
||||
{
|
||||
yy++;
|
||||
updateScreen = true;
|
||||
}
|
||||
}
|
||||
if(updateScreen)
|
||||
{
|
||||
SDL_FillRect(ekran, NULL, SDL_MapRGB(ekran->format, 0, 0, 0));
|
||||
SDL_Surface * help = mh->terrainRect(xx,yy,25,18,zz);
|
||||
SDL_BlitSurface(help,NULL,ekran,NULL);
|
||||
SDL_FreeSurface(help);
|
||||
SDL_Flip(ekran);
|
||||
updateScreen = false;
|
||||
}
|
||||
|
||||
SDL_FillRect(ekran, NULL, SDL_MapRGB(ekran->format, 0, 0, 0));
|
||||
SDL_Surface * help = mh->terrainRect(xx,yy,25,18,zz);
|
||||
SDL_BlitSurface(help,NULL,ekran,NULL);
|
||||
SDL_FreeSurface(help);
|
||||
SDL_Flip(ekran);
|
||||
/////////
|
||||
}
|
||||
catch(...)
|
||||
|
@ -1,3 +1,6 @@
|
||||
#ifndef CSEMILODHANDLER_H
|
||||
#define CSEMILODHANDLER_H
|
||||
|
||||
#include "CSemiDefHandler.h"
|
||||
class CSemiLodHandler
|
||||
{
|
||||
@ -5,4 +8,6 @@ public:
|
||||
std::string ourName; // name of our lod
|
||||
void openLod(std::string path);
|
||||
CSemiDefHandler * giveDef(std::string name); //loads def from our lod
|
||||
};
|
||||
};
|
||||
|
||||
#endif //CSEMILODHANDLER_H
|
137
mapHandler.cpp
137
mapHandler.cpp
@ -3,18 +3,69 @@
|
||||
#include "CSemiDefHandler.h"
|
||||
#include "SDL_rotozoom.h"
|
||||
#include "SDL_Extensions.h"
|
||||
#include "CGameInfo.h"
|
||||
|
||||
extern SDL_Surface * ekran;
|
||||
void mapHandler::init()
|
||||
{
|
||||
terrainBitmap = new SDL_Surface **[reader->map.width];
|
||||
for (int ii=0;ii<reader->map.width;ii++)
|
||||
terrainBitmap[ii] = new SDL_Surface*[reader->map.height]; // allocate memory
|
||||
for (int i=0; i<reader->map.width; i++)
|
||||
terrainBitmap = new SDL_Surface **[reader->map.width+8];
|
||||
for (int ii=0;ii<reader->map.width+8;ii++)
|
||||
terrainBitmap[ii] = new SDL_Surface*[reader->map.height+8]; // allocate memory
|
||||
CSemiDefHandler * bord = CGameInfo::mainObj->sspriteh->giveDef("EDG.DEF");
|
||||
for (int i=0; i<reader->map.width+8; i++) //jest po szerokoœci
|
||||
{
|
||||
for (int j=0; j<reader->map.height;j++)
|
||||
for (int j=0; j<reader->map.height+8;j++) //po wysokoœci
|
||||
{
|
||||
TerrainTile zz = reader->map.terrain[i][j];
|
||||
std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i][j].tertype);
|
||||
if(i < 4 || i > (reader->map.width+3) || j < 4 || j > (reader->map.height+3))
|
||||
{
|
||||
if(i==3 && j==3)
|
||||
{
|
||||
terrainBitmap[i][j] = bord->ourImages[16].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(i==3 && j==(reader->map.height+4))
|
||||
{
|
||||
terrainBitmap[i][j] = bord->ourImages[19].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(i==(reader->map.width+4) && j==3)
|
||||
{
|
||||
terrainBitmap[i][j] = bord->ourImages[17].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(i==(reader->map.width+4) && j==(reader->map.height+4))
|
||||
{
|
||||
terrainBitmap[i][j] = bord->ourImages[18].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(j == 3 && i > 3 && i < reader->map.height+4)
|
||||
{
|
||||
terrainBitmap[i][j] = bord->ourImages[22+rand()%2].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(i == 3 && j > 3 && j < reader->map.height+4)
|
||||
{
|
||||
terrainBitmap[i][j] = bord->ourImages[33+rand()%2].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(j == reader->map.height+4 && i > 3 && i < reader->map.width+4)
|
||||
{
|
||||
terrainBitmap[i][j] = bord->ourImages[29+rand()%2].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(i == reader->map.width+4 && j > 3 && j < reader->map.height+4)
|
||||
{
|
||||
terrainBitmap[i][j] = bord->ourImages[25+rand()%2].bitmap;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
terrainBitmap[i][j] = bord->ourImages[rand()%16].bitmap;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
TerrainTile zz = reader->map.terrain[i-4][j-4];
|
||||
std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i-4][j-4].tertype);
|
||||
for (unsigned int k=0; k<reader->defs.size(); k++)
|
||||
{
|
||||
try
|
||||
@ -24,10 +75,10 @@ void mapHandler::init()
|
||||
else
|
||||
{
|
||||
SDL_Surface * n;
|
||||
int ktora = reader->map.terrain[i][j].terview;
|
||||
int ktora = reader->map.terrain[i-4][j-4].terview;
|
||||
terrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
|
||||
//TODO: odwracanie
|
||||
switch ((reader->map.terrain[i][j].siodmyTajemniczyBajt)%4)
|
||||
switch ((reader->map.terrain[i-4][j-4].siodmyTajemniczyBajt)%4)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
@ -57,15 +108,63 @@ void mapHandler::init()
|
||||
}
|
||||
if (reader->map.twoLevel)
|
||||
{
|
||||
undTerrainBitmap = new SDL_Surface **[reader->map.width];
|
||||
for (int ii=0;ii<reader->map.width;ii++)
|
||||
undTerrainBitmap[ii] = new SDL_Surface*[reader->map.height]; // allocate memory
|
||||
for (int i=0; i<reader->map.width; i++)
|
||||
undTerrainBitmap = new SDL_Surface **[reader->map.width+8];
|
||||
for (int ii=0;ii<reader->map.width+8;ii++)
|
||||
undTerrainBitmap[ii] = new SDL_Surface*[reader->map.height+8]; // allocate memory
|
||||
for (int i=0; i<reader->map.width+8; i++)
|
||||
{
|
||||
for (int j=0; j<reader->map.height;j++)
|
||||
for (int j=0; j<reader->map.height+8;j++)
|
||||
{
|
||||
TerrainTile zz = reader->map.undergroungTerrain[i][j];
|
||||
std::string name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i][j].tertype);
|
||||
if(i < 4 || i > (reader->map.width+3) || j < 4 || j > (reader->map.height+3))
|
||||
{
|
||||
if(i==3 && j==3)
|
||||
{
|
||||
undTerrainBitmap[i][j] = bord->ourImages[16].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(i==3 && j==(reader->map.height+4))
|
||||
{
|
||||
undTerrainBitmap[i][j] = bord->ourImages[19].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(i==(reader->map.width+4) && j==3)
|
||||
{
|
||||
undTerrainBitmap[i][j] = bord->ourImages[17].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(i==(reader->map.width+4) && j==(reader->map.height+4))
|
||||
{
|
||||
undTerrainBitmap[i][j] = bord->ourImages[18].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(j == 3 && i > 3 && i < reader->map.height+4)
|
||||
{
|
||||
undTerrainBitmap[i][j] = bord->ourImages[22+rand()%2].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(i == 3 && j > 3 && j < reader->map.height+4)
|
||||
{
|
||||
undTerrainBitmap[i][j] = bord->ourImages[33+rand()%2].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(j == reader->map.height+4 && i > 3 && i < reader->map.width+4)
|
||||
{
|
||||
undTerrainBitmap[i][j] = bord->ourImages[29+rand()%2].bitmap;
|
||||
continue;
|
||||
}
|
||||
else if(i == reader->map.width+4 && j > 3 && j < reader->map.height+4)
|
||||
{
|
||||
undTerrainBitmap[i][j] = bord->ourImages[25+rand()%2].bitmap;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
undTerrainBitmap[i][j] = bord->ourImages[rand()%16].bitmap;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
TerrainTile zz = reader->map.undergroungTerrain[i-4][j-4];
|
||||
std::string name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i-4][j-4].tertype);
|
||||
for (unsigned int k=0; k<reader->defs.size(); k++)
|
||||
{
|
||||
try
|
||||
@ -75,10 +174,10 @@ void mapHandler::init()
|
||||
else
|
||||
{
|
||||
SDL_Surface * n;
|
||||
int ktora = reader->map.undergroungTerrain[i][j].terview;
|
||||
int ktora = reader->map.undergroungTerrain[i-4][j-4].terview;
|
||||
undTerrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
|
||||
//TODO: odwracanie
|
||||
switch ((reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt)%4)
|
||||
switch ((reader->map.undergroungTerrain[i-4][j-4].siodmyTajemniczyBajt)%4)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
@ -123,7 +222,7 @@ SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy, int level)
|
||||
#endif
|
||||
SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
|
||||
rmask, gmask, bmask, amask);
|
||||
if (((dx+x)>((reader->map.width)) || (dy+y)>((reader->map.height))) || ((x<0)||(y<0) ) )
|
||||
if (((dx+x)>((reader->map.width+8)) || (dy+y)>((reader->map.height+8))) || ((x<0)||(y<0) ) )
|
||||
throw new std::string("Poza zakresem");
|
||||
for (int bx=0; bx<dx; bx++)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user