1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

wyświetlanie obiektów na mapie (wymaga dokończenia), drobne poprawki

This commit is contained in:
mateuszb 2007-07-02 11:23:42 +00:00
parent 30aa7499ef
commit 9ff9557ed2
9 changed files with 63 additions and 41 deletions

View File

@ -391,6 +391,19 @@ void CAmbarCendamo::deh3m()
int defAmount = bufor[i]; // liczba defow
defAmount = readNormalNr(i);
i+=4;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int srmask = 0xff000000;
int sgmask = 0x00ff0000;
int sbmask = 0x0000ff00;
int samask = 0x000000ff;
#else
int srmask = 0x000000ff;
int sgmask = 0x0000ff00;
int sbmask = 0x00ff0000;
int samask = 0xff000000;
#endif
SDL_Surface * alphaTransSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 12, 12, 32, srmask, sgmask, sbmask, samask);
for (int idd = 0 ; idd<defAmount; idd++) // reading defs
{
int nameLength = readNormalNr(i,4);i+=4;
@ -406,16 +419,20 @@ void CAmbarCendamo::deh3m()
map.defy.push_back(vinya); // add this def to the vector
//testing - only fragment//////////////////////////////////////////////////////////////
/*map.defy[idd].handler = new CSemiDefHandler();
map.defy[idd].handler->openDef(map.defy[idd].name.c_str(), "H3sprite.lod");
map.defy[idd].handler = new CDefHandler();
map.defy[idd].handler->openDef( std::string("newH3sprite\\")+map.defy[idd].name);
for(int ff=0; ff<map.defy[idd].handler->ourImages.size(); ++ff) //adding shadows and transparency
{
map.defy[idd].handler->ourImages[ff].bitmap = CSDL_Ext::alphaTransform(map.defy[idd].handler->ourImages[ff].bitmap);
}//*/
SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[idd].handler->ourImages[ff].bitmap, alphaTransSurf);
SDL_FreeSurface(map.defy[idd].handler->ourImages[ff].bitmap);
map.defy[idd].handler->ourImages[ff].bitmap = bufs;
}
//end fo testing - only fragment///////////////////////////////////////////////////////
//teceDef();
}
SDL_FreeSurface(alphaTransSurf);
THC std::cout<<"Wczytywanie defow: "<<th.getDif()<<std::endl;
////loading objects
int howManyObjs = readNormalNr(i, 4); i+=4;

View File

@ -8,6 +8,7 @@
#include "SDL.h"
#include "map.h"
#include "CSemiDefHandler.h"
#include "CDefHandler.h"
#include "CCreatureHandler.h"
enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF, EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF, SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF, BORDERGUARD_DEF};

Binary file not shown.

Binary file not shown.

15
CMT.cpp
View File

@ -274,8 +274,8 @@ int _tmain(int argc, _TCHAR* argv[])
//test->init(std::string("h3abp_bm.lod"));
CDefHandler * tdef = new CDefHandler;
tdef->openDef(std::string("H3sprite.lod\\EDG.DEF"));
tdef->getSprite(0);
tdef->openDef(std::string("newh3sprite\\AVLSPTR3.DEF"));
//tdef->getSprite(0);
//CLodHandler * bitmapLod = new CLodHandler;
//bitmapLod->init(std::string("newH3bitmap.lod"));
@ -285,6 +285,9 @@ int _tmain(int argc, _TCHAR* argv[])
tconv->convert();
tconv->saveBMP(std::string("tesciczekConva.bmp"));
CSemiDefHandler * semek = new CSemiDefHandler;
semek->openDef(std::string("EDG.DEF"), std::string("H3sprite.lod"));
//////////////////////////////////////////////////////////////////////////////// lod testing end
cgi->sspriteh = new CSemiLodHandler();
@ -343,6 +346,7 @@ int _tmain(int argc, _TCHAR* argv[])
bool scrollingUp = false;
bool scrollingDown = false;
bool updateScreen = false;
unsigned char animVal=0; //for animations handling
for(;;) // main loop
{
try
@ -456,7 +460,7 @@ int _tmain(int argc, _TCHAR* argv[])
if(updateScreen)
{
SDL_FillRect(ekran, NULL, SDL_MapRGB(ekran->format, 0, 0, 0));
SDL_Surface * help = mh->terrainRect(xx,yy,25,19,zz);
SDL_Surface * help = mh->terrainRect(xx,yy,25,19,zz,animVal);
SDL_BlitSurface(help,NULL,ekran,NULL);
SDL_FreeSurface(help);
SDL_UpdateRect(ekran, 0, 0, ekran->w, ekran->h);
@ -467,7 +471,10 @@ int _tmain(int argc, _TCHAR* argv[])
catch(...)
{ continue; }
SDL_Delay(25); //give time for other apps
updateScreen = true;
++animVal; //for animations
SDL_Delay(30); //give time for other apps
}
return 0;
}

View File

@ -329,7 +329,7 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
}
SDL_SetColors(src, &shadow, yy, 1);
}
if(cur.g == 255 && cur.b == 255)
if((cur.g == 255 && cur.b == 255) || (cur.r == 255 && cur.g == 0 && cur.b == 0))
{
SDL_Color transp;
transp.b = transp.g = transp.r = 0;
@ -345,7 +345,7 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
SDL_Surface * CSDL_Ext::secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha)
{
Uint32 pompom[192][192];
Uint32 pompom[224][224];
for(int i=0; i<src->w; ++i)
{
for(int j=0; j<src->h; ++j)
@ -353,7 +353,7 @@ SDL_Surface * CSDL_Ext::secondAlphaTransform(SDL_Surface * src, SDL_Surface * al
pompom[i][j] = 0xffffffff - (SDL_GetPixel(src, i, j, true) & 0xff000000);
}
}
Uint32 pompom2[192][192];
Uint32 pompom2[224][224];
for(int i=0; i<src->w; ++i)
{
for(int j=0; j<src->h; ++j)

4
map.h
View File

@ -5,6 +5,7 @@
#include <vector>
#include "global.h"
#include "CSemiDefHandler.h"
#include "CDefHandler.h"
enum ESortBy{name,playerAm,size,format, viccon,loscon};
struct Sresource
@ -56,7 +57,8 @@ struct DefInfo //information from def declaration
{
std::string name;
int bytes [42];
CSemiDefHandler * handler;
//CSemiDefHandler * handler;
CDefHandler * handler;
};
struct Location
{

View File

@ -17,18 +17,18 @@ void CMapHandler::init()
CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap);
}
visibility.resize(reader->map.width+8);
for(int gg=0; gg<reader->map.width+8; ++gg)
visibility.resize(reader->map.width+2*Woff);
for(int gg=0; gg<reader->map.width+2*Woff; ++gg)
{
visibility[gg].resize(reader->map.height+8);
for(int jj=0; jj<reader->map.height+8; ++jj)
visibility[gg].resize(reader->map.height+2*Hoff);
for(int jj=0; jj<reader->map.height+2*Hoff; ++jj)
visibility[gg][jj] = true;
}
undVisibility.resize(reader->map.width+8);
for(int gg=0; gg<reader->map.width+8; ++gg)
undVisibility.resize(reader->map.width+2*Woff);
for(int gg=0; gg<reader->map.width+2*Woff; ++gg)
{
undVisibility[gg].resize(reader->map.height+8);
for(int jj=0; jj<reader->map.height+8; ++jj)
undVisibility[gg].resize(reader->map.height+2*Woff);
for(int jj=0; jj<reader->map.height+2*Woff; ++jj)
undVisibility[gg][jj] = true;
}
@ -44,8 +44,8 @@ void CMapHandler::init()
visibility[6][9] = false;
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
for (int ii=0;ii<reader->map.width+2*Woff;ii++)
terrainBitmap[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory
CSemiDefHandler * bord = CGameInfo::mainObj->sspriteh->giveDef("EDG.DEF");
for (int i=0; i<reader->map.width+8; i++) //jest po szerokoœci
{
@ -241,7 +241,7 @@ void CMapHandler::init()
} //end of if
}
SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level)
SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int rmask = 0xff000000;
@ -280,27 +280,19 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level)
}
}
////terrain printed; printing objects
/*
for (int bx=0; bx<dx; bx++)
for(int gg=0; gg<CGameInfo::mainObj->objh->objInstances.size(); ++gg)
{
for (int by=0; by<dy; by++)
if(CGameInfo::mainObj->objh->objInstances[gg].x >= x-3 && CGameInfo::mainObj->objh->objInstances[gg].x < dx+x-3 && CGameInfo::mainObj->objh->objInstances[gg].y >= y-3 && CGameInfo::mainObj->objh->objInstances[gg].y < dy+y-3 && CGameInfo::mainObj->objh->objInstances[gg].z == level)
{
for(int gg=0; gg<CGameInfo::mainObj->objh->objInstances.size(); ++gg)
{
if(CGameInfo::mainObj->objh->objInstances[gg].x == bx+x-4 && CGameInfo::mainObj->objh->objInstances[gg].y == by+y-4 && CGameInfo::mainObj->objh->objInstances[gg].z == level)
{
SDL_Rect * sr = new SDL_Rect;
sr->h=sr->w=192;
sr->x = (bx)*32 - CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->w + 32;
sr->y = (by)*32 - CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->h + 32;
SDL_Surface * s2 = CSDL_Ext::secondAlphaTransform(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap, su);
SDL_BlitSurface(s2, NULL, su, sr);
SDL_FreeSurface(s2);
delete sr;
}
}
SDL_Rect * sr = new SDL_Rect;
sr->w = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->w;
sr->h = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->h;
sr->x = (CGameInfo::mainObj->objh->objInstances[gg].x-x+4)*32 - CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->w + 32;
sr->y = (CGameInfo::mainObj->objh->objInstances[gg].y-y+4)*32 - CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->h + 32;
SDL_BlitSurface(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap, NULL, su, sr);
delete sr;
}
}//*/
}
////objects printed, printing shadow
for (int bx=0; bx<dx; bx++)
{

View File

@ -5,13 +5,16 @@
#include "CSemiDefHandler.h"
#include "CGameInfo.h"
const unsigned int Woff = 4; //width of map's frame
const unsigned int Hoff = 4;
class CMapHandler
{
public:
CAmbarCendamo * reader;
SDL_Surface *** terrainBitmap;
SDL_Surface *** undTerrainBitmap; // used only if there is underground level
SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0);
SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0);
SDL_Surface * terrBitmap(int x, int y);
SDL_Surface * undTerrBitmap(int x, int y);
CSemiDefHandler * fullHide;