Преглед изворни кода

* merged CBattleConsole::stackKilled into CBattleInterface::stacksAreAttacked (I hope it'll work even better than before)
* a few optimizations
* maybe something else I've forgotten ;]

mateuszb пре 17 година
родитељ
комит
447e5babda
12 измењених фајлова са 133 додато и 171 уклоњено
  1. 10 10
      CAdvmapInterface.cpp
  2. 75 93
      CBattleInterface.cpp
  3. 5 2
      CBattleInterface.h
  4. 1 1
      CGameState.cpp
  5. 1 1
      CGameState.h
  6. 2 2
      CHeroWindow.cpp
  7. 0 4
      CMessage.cpp
  8. 9 14
      CPlayerInterface.cpp
  9. 0 4
      CPreGame.cpp
  10. 21 35
      SDL_Extensions.cpp
  11. 4 4
      SDL_Extensions.h
  12. 5 1
      mapHandler.h

+ 10 - 10
CAdvmapInterface.cpp

@@ -58,16 +58,16 @@ CMinimap::CMinimap(bool draw)
 	{
 		if (i%4 || (i==0))
 		{
-			SDL_PutPixel(radar,i,0,255,75,125);
-			SDL_PutPixel(radar,i,radar->h-1,255,75,125);
+			SDL_PutPixelWithoutRefresh(radar,i,0,255,75,125);
+			SDL_PutPixelWithoutRefresh(radar,i,radar->h-1,255,75,125);
 		}
 	}
 	for (int i=0; i<radar->h; i++)
 	{
 		if ((i%4) || (i==0))
 		{
-			SDL_PutPixel(radar,0,i,255,75,125);
-			SDL_PutPixel(radar,radar->w-1,i,255,75,125);
+			SDL_PutPixelWithoutRefresh(radar,0,i,255,75,125);
+			SDL_PutPixelWithoutRefresh(radar,radar->w-1,i,255,75,125);
 		}
 	}
 	SDL_SetColorKey(radar,SDL_SRCCOLORKEY,SDL_MapRGB(radar->format,0,255,255));
@@ -124,7 +124,7 @@ void CMinimap::draw()
 		{
 			for (int jj=0; jj<ho; jj++)
 			{
-				SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[hh[i]->getOwner()].r,
+				SDL_PutPixelWithoutRefresh(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[hh[i]->getOwner()].r,
 						graphics->playerColors[hh[i]->getOwner()].g,graphics->playerColors[hh[i]->getOwner()].b);
 			}
 		}
@@ -146,10 +146,10 @@ void CMinimap::draw()
 						for (int jj=0; jj<ho; jj++)
 						{
 							if(oo[v]->tempOwner == 255)
-								SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,graphics->neutralColor->r,
+								SDL_PutPixelWithoutRefresh(temps,maplgp.x+ii,maplgp.y+jj,graphics->neutralColor->r,
 									graphics->neutralColor->g,graphics->neutralColor->b);
 							else
-								SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[oo[v]->getOwner()].r,
+								SDL_PutPixelWithoutRefresh(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[oo[v]->getOwner()].r,
 									graphics->playerColors[oo[v]->getOwner()].g,graphics->playerColors[oo[v]->getOwner()].b);
 						}
 					}
@@ -185,8 +185,8 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels
 				int mx=(mapSizes.x*x)/pos.w;
 				int my=(mapSizes.y*y)/pos.h;
 				if (CGI->mh->ttiles[mx][my][i].tileInfo->blocked && (!CGI->mh->ttiles[mx][my][i].tileInfo->visitable))
-					SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
-				else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
+					SDL_PutPixelWithoutRefresh(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
+				else SDL_PutPixelWithoutRefresh(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
 			}
 		}
 		map.push_back(pom);
@@ -285,7 +285,7 @@ void CMinimap::showTile(const int3 &pos)
 		for (int jj=0; jj<ho; jj++)
 		{
 			if ((pos.x*wo+ii<this->pos.w) && (pos.y*ho+jj<this->pos.h))
-				CSDL_Ext::SDL_PutPixel(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0,0);
+				CSDL_Ext::SDL_PutPixelWithoutRefresh(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0);
 		}
 	}
 }

+ 75 - 93
CBattleInterface.cpp

@@ -41,7 +41,9 @@ public:
 } cmpst2 ;
 
 CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2)
-: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL), attackingInfo(NULL), myTurn(false), resWindow(NULL), showStackQueue(false), animSpeed(2), printStackRange(true), printMouseShadow(true), spellDestSelectMode(false), spellToCast(NULL)
+: printCellBorders(true), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), givenCommand(NULL),
+	attackingInfo(NULL), myTurn(false), resWindow(NULL), showStackQueue(false), animSpeed(2), printStackRange(true),
+	printMouseShadow(true), spellDestSelectMode(false), spellToCast(NULL), previouslyHoveredHex(-1)
 {
 	strongInterest = true;
 	givenCommand = new CondSh<BattleAction *>(NULL);
@@ -323,6 +325,14 @@ void CBattleInterface::show(SDL_Surface * to)
 		{
 			if(bfield[b].strictHovered && bfield[b].hovered)
 			{
+				if(previouslyHoveredHex == -1) previouslyHoveredHex = b; //something to start with
+				if(currentlyHoveredHex == -1) currentlyHoveredHex = b; //something to start with
+				if(currentlyHoveredHex != b) //repair hover info
+				{
+					previouslyHoveredHex = currentlyHoveredHex;
+					currentlyHoveredHex = b;
+				}
+				//print shade
 				int x = 14 + ((b/BFIELD_WIDTH)%2==0 ? 22 : 0) + 44*(b%BFIELD_WIDTH);
 				int y = 86 + 42 * (b/BFIELD_WIDTH);
 				CSDL_Ext::blit8bppAlphaTo24bpp(cellShade, NULL, to, &genRect(cellShade->h, cellShade->w, x, y));
@@ -373,30 +383,22 @@ void CBattleInterface::show(SDL_Surface * to)
 	{
 		for(int v=0; v<stackDeadByHex[b].size(); ++v)
 		{
-			creAnims[stackDeadByHex[b][v]]->nextFrame(to, creAnims[stackDeadByHex[b][v]]->pos.x, creAnims[stackDeadByHex[b][v]]->pos.y, creDir[stackDeadByHex[b][v]], (animCount%(4/animSpeed)==0) && creAnims[stackDeadByHex[b][v]]->getType()!=5, stackDeadByHex[b][v]==activeStack); //increment always when moving, never if stack died
-			//printing amount
-			if(stacks[stackDeadByHex[b][v]].amount > 0) //don't print if stack is not alive
-			{
-				int xAdd = stacks[stackDeadByHex[b][v]].attackerOwned ? 220 : 202;
-
-				CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackDeadByHex[b][v]]->pos.x + xAdd, creAnims[stackDeadByHex[b][v]]->pos.y + 260));
-				std::stringstream ss;
-				ss<<stacks[stackDeadByHex[b][v]].amount;
-				CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackDeadByHex[b][v]]->pos.x + xAdd + 14, creAnims[stackDeadByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
-			}
+			creAnims[stackDeadByHex[b][v]]->nextFrame(to, creAnims[stackDeadByHex[b][v]]->pos.x, creAnims[stackDeadByHex[b][v]]->pos.y, creDir[stackDeadByHex[b][v]], false, stackDeadByHex[b][v]==activeStack); //increment always when moving, never if stack died
 		}
 	}
 	for(int b=0; b<BFIELD_SIZE; ++b) //showing alive stacks
 	{
 		for(int v=0; v<stackAliveByHex[b].size(); ++v)
 		{
-			creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], (animCount%(4/animSpeed)==0) && creAnims[stackAliveByHex[b][v]]->getType()!=0 && creAnims[stackAliveByHex[b][v]]->getType()!=5 && creAnims[stackAliveByHex[b][v]]->getType()!=20 && creAnims[stackAliveByHex[b][v]]->getType()!=21, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died
+			int animType = creAnims[stackAliveByHex[b][v]]->getType();
+			bool incrementFrame = (animCount%(4/animSpeed)==0) && animType!=0 && animType!=5 && animType!=20 && animType!=21 && animType!=3;
+			creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], incrementFrame, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died
 			//printing amount
 			if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive
 			{
 				int xAdd = stacks[stackAliveByHex[b][v]].attackerOwned ? 220 : 202;
 
-				CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + xAdd, creAnims[stackAliveByHex[b][v]]->pos.y + 260));
+				SDL_BlitSurface(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + xAdd, creAnims[stackAliveByHex[b][v]]->pos.y + 260));
 				std::stringstream ss;
 				ss<<stacks[stackAliveByHex[b][v]].amount;
 				CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackAliveByHex[b][v]]->pos.x + xAdd + 14, creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
@@ -407,21 +409,24 @@ void CBattleInterface::show(SDL_Surface * to)
 	projectileShowHelper(to);//showing projectiles
 
 	//showing spell effects
-	std::vector< std::list<SBattleEffect>::iterator > toErase;
-	for(std::list<SBattleEffect>::iterator it = battleEffects.begin(); it!=battleEffects.end(); ++it)
+	if(battleEffects.size())
 	{
-		blitAt(it->anim->ourImages[(it->frame)%it->anim->ourImages.size()].bitmap, it->x, it->y, to);
-		++(it->frame);
+		std::vector< std::list<SBattleEffect>::iterator > toErase;
+		for(std::list<SBattleEffect>::iterator it = battleEffects.begin(); it!=battleEffects.end(); ++it)
+		{
+			blitAt(it->anim->ourImages[(it->frame)%it->anim->ourImages.size()].bitmap, it->x, it->y, to);
+			++(it->frame);
 
-		if(it->frame == it->maxFrame)
-			toErase.push_back(it);
+			if(it->frame == it->maxFrame)
+				toErase.push_back(it);
+		}
+		for(int b=0; b<toErase.size(); ++b)
+		{
+			delete toErase[b]->anim;
+			battleEffects.erase(toErase[b]);
+		}
 	}
 	
-	for(int b=0; b<toErase.size(); ++b)
-	{
-		delete toErase[b]->anim;
-		battleEffects.erase(toErase[b]);
-	}
 
 	//showing queue of stacks
 	if(showStackQueue)
@@ -466,7 +471,7 @@ void CBattleInterface::show(SDL_Surface * to)
 							{
 								pc = *graphics->neutralColor;
 							}
-							CSDL_Ext::SDL_PutPixel(to, xFrom, yFrom, pc.r, pc.g, pc.b);
+							CSDL_Ext::SDL_PutPixelWithoutRefresh(to, xFrom, yFrom, pc.r, pc.g, pc.b);
 						}
 					}
 				}
@@ -518,14 +523,8 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
 						CGI->curh->changeGraphic(1,3);
 					else if(isTileAttackable(myNumber)) //available enemy (melee attackable)
 					{
-						int fromHex = -1;
-						for(int b=0; b<BFIELD_SIZE; ++b)
-							if(bfield[b].hovered && !bfield[b].strictHovered)
-							{
-								fromHex = b;
-								break;
-							}
-							if(fromHex!=-1 && fromHex%17!=0 && fromHex%17!=16 && vstd::contains(shadedHexes, fromHex))
+						int fromHex = previouslyHoveredHex;
+						if(fromHex!=-1 && fromHex%17!=0 && fromHex%17!=16 && vstd::contains(shadedHexes, fromHex))
 						{
 							switch(BattleInfo::mutualPosition(fromHex, myNumber))
 							{
@@ -738,55 +737,6 @@ void CBattleInterface::stackRemoved(CStack stack)
 	creAnims.erase(stack.ID);
 }
 
-void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting)
-{
-	if(creAnims[ID]->getType() != 2)
-	{
-		return; //something went wrong
-	}
-	if(byShooting) //delay hit animation
-	{
-		CStack attacker = *LOCPLINT->cb->battleGetStackByID(IDby);
-		while(true)
-		{
-			bool found = false;
-			for(std::list<SProjectileInfo>::const_iterator it = projectiles.begin(); it!=projectiles.end(); ++it)
-			{
-				if(it->creID == attacker.creature->idNumber)
-				{
-					found = true;
-					break;
-				}
-			}
-			if(!found)
-				break;
-			else
-			{
-				show();
-				CSDL_Ext::update();
-				SDL_framerateDelay(LOCPLINT->mainFPSmng);
-			}
-		}
-	}
-	creAnims[ID]->setType(5); //death
-	//int firstFrame = creAnims[ID]->getFrame();
-	int increments = 0;
-	while(increments < creAnims[ID]->framesInGroup(5)-1)
-	{
-		if((animCount%(4/animSpeed))==0)
-		{
-			creAnims[ID]->incrementFrame();
-			++increments;
-		}
-		show();
-		CSDL_Ext::update();
-		SDL_framerateDelay(LOCPLINT->mainFPSmng);
-	}
-
-	if(IDby!=-1)
-		printConsoleAttacked(ID, dmg, killed, IDby);
-}
-
 void CBattleInterface::stackActivated(int number)
 {
 	//givenCommand = NULL;
@@ -913,6 +863,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool endMoving)
 
 void CBattleInterface::stacksAreAttacked(std::vector<CBattleInterface::SStackAttackedInfo> attackedInfos)
 {
+	//restoring default state of battleWindow by calling show func
 	while(true)
 	{
 		show();
@@ -954,40 +905,71 @@ void CBattleInterface::stacksAreAttacked(std::vector<CBattleInterface::SStackAtt
 			}
 		}
 	}
-	std::vector<int> animLengths;
+	//initializing
+	std::map<int, int> animLengths;
+	std::map<int, int> increments;
 	int maxLen = 0;
 	for(int g=0; g<attackedInfos.size(); ++g)
 	{
-		creAnims[attackedInfos[g].ID]->setType(3); //getting hit
-		animLengths.push_back( creAnims[attackedInfos[g].ID]->framesInGroup(3) );
-		if(creAnims[attackedInfos[g].ID]->framesInGroup(3) > maxLen)
+		int animLen;
+		if(attackedInfos[g].killed)
+		{
+			creAnims[attackedInfos[g].ID]->setType(5); //death
+			animLen = creAnims[attackedInfos[g].ID]->framesInGroup(5);
+		}
+		else
+		{
+			creAnims[attackedInfos[g].ID]->setType(3); //getting hit
+			animLen = creAnims[attackedInfos[g].ID]->framesInGroup(3);
+		}
+		animLengths.insert(std::make_pair(attackedInfos[g].ID, animLen));
+		increments.insert(std::make_pair(attackedInfos[g].ID, 0));
+		if(animLen > maxLen)
 		{
-			maxLen = creAnims[attackedInfos[g].ID]->framesInGroup(3);
+			maxLen = animLen;
 		}
 	}
-	for(int i=0; i<maxLen; ++i)
+	//main showing loop
+	bool continueLoop = true;
+	while(continueLoop)
 	{
 		show();
 		CSDL_Ext::update();
 		SDL_framerateDelay(LOCPLINT->mainFPSmng);
-		/*if((animCount+1)%(4/animSpeed)==0)
-			creAnims[ID]->incrementFrame();*/
 		for(int g=0; g<attackedInfos.size(); ++g)
 		{
-			if(i>=animLengths[g] && creAnims[attackedInfos[g].ID]->getType() == 3)
+			if((animCount+1)%(4/animSpeed)==0 && increments[attackedInfos[g].ID]<animLengths[attackedInfos[g].ID])
+			{
+				creAnims[attackedInfos[g].ID]->incrementFrame();
+				++(increments[attackedInfos[g].ID]);
+			}
+			if(increments[attackedInfos[g].ID]>=animLengths[attackedInfos[g].ID] && creAnims[attackedInfos[g].ID]->getType() == 3)
 				creAnims[attackedInfos[g].ID]->setType(2);
 		}
+		bool isAnotherOne = false; //if true, there is a stack whose hit/death anim must be continued
+		for(int g=0; g<attackedInfos.size(); ++g)
+		{
+			if(increments[attackedInfos[g].ID] < animLengths[attackedInfos[g].ID]-1)
+			{
+				isAnotherOne = true;
+				break;
+			}
+		}
+		if(!isAnotherOne)
+			continueLoop = false;
 	}
+	//restoring animType
 	for(int g=0; g<attackedInfos.size(); ++g)
 	{
 		if(creAnims[attackedInfos[g].ID]->getType() == 3)
 			creAnims[attackedInfos[g].ID]->setType(2);
 	}
 
+	//printing info to console
 	for(int g=0; g<attackedInfos.size(); ++g)
 	{
 		if(attackedInfos[g].IDby!=-1)
-			printConsoleAttacked(attackedInfos[g].ID, attackedInfos[g].dmg, attackedInfos[g].killed, attackedInfos[g].IDby);
+			printConsoleAttacked(attackedInfos[g].ID, attackedInfos[g].dmg, attackedInfos[g].amountKilled, attackedInfos[g].IDby);
 	}
 }
 

+ 5 - 2
CBattleInterface.h

@@ -131,6 +131,8 @@ private:
 	unsigned char animCount;
 	int activeStack; //number of active stack; -1 - no one
 	std::vector<int> shadedHexes; //hexes available for active stack
+	int previouslyHoveredHex; //number of hex that was hovered by the cursor a while ago
+	int currentlyHoveredHex; //number of hex that is supposed to be hovered (for a while it may be inappropriately set, but will be renewed soon)
 	int animSpeed; //speed of animation; 1 - slowest, 2 - medium, 4 - fastest
 	float getAnimSpeedMultiplier() const; //returns multiplier for number of frames in a group
 
@@ -223,15 +225,16 @@ public:
 	{
 		int ID; //id of attacked stack
 		int dmg; //damage dealt
-		int killed; //how many creatures in stack has been killed
+		int amountKilled; //how many creatures in stack has been killed
 		int IDby; //ID of attacking stack
 		bool byShooting; //if true, stack has been attacked by shooting
+		bool killed; //if true, stack has been killed
 	};
 
 	//call-ins
 	void newStack(CStack stack); //new stack appeared on battlefield
 	void stackRemoved(CStack stack); //stack disappeared from batlefiled
-	void stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting); //stack has been killed (but corpses remain)
+	//void stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting); //stack has been killed (but corpses remain)
 	void stackActivated(int number); //active stack has been changed
 	void stackMoved(int number, int destHex, bool endMoving); //stack with id number moved to destHex
 	void stacksAreAttacked(std::vector<SStackAttackedInfo> attackedInfos); //called when a certain amount of stacks has been attacked

+ 1 - 1
CGameState.cpp

@@ -250,7 +250,7 @@ std::vector<int> BattleInfo::getPath(int start, int dest, bool*accessibility)
 }
 
 CStack::CStack(CCreature * C, int A, int O, int I, bool AO, int S)
-	:creature(C),amount(A), baseAmount(A), owner(O), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints), slot(S), counterAttacks(1)
+	:creature(C),amount(A), baseAmount(A), owner(O), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints), slot(S), counterAttacks(1), effects(), state()
 {
 	abilities = C->abilities;
 	state.insert(ALIVE);

+ 1 - 1
CGameState.h

@@ -115,7 +115,7 @@ public:
 	std::vector<StackEffect> effects;
 
 	CStack(CCreature * C, int A, int O, int I, bool AO, int S);
-	CStack() : creature(NULL),amount(-1),owner(255), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1), slot(255), baseAmount(-1), counterAttacks(1){};
+	CStack() : creature(NULL),amount(-1),owner(255), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1), slot(255), baseAmount(-1), counterAttacks(1), effects(), state(), abilities(){}
 	const StackEffect * getEffect(ui16 id) const; //effect id (SP)
 	ui32 speed() const;
 	template <typename Handler> void save(Handler &h, const int version)

+ 2 - 2
CHeroWindow.cpp

@@ -595,7 +595,7 @@ void CHeroWindow::redrawCurBack()
 				for(int h=0; h<graphics->portraitSmall[cur->portrait]->h; ++h)
 					if(f==0 || h==0 || f==graphics->portraitSmall[cur->portrait]->w-1 || h==graphics->portraitSmall[cur->portrait]->h-1)
 					{
-						CSDL_Ext::SDL_PutPixel(curBack, 611+f, 87+g*54+h, 240, 220, 120);
+						CSDL_Ext::SDL_PutPixelWithoutRefresh(curBack, 611+f, 87+g*54+h, 240, 220, 120);
 					}
 			}
 		}
@@ -787,7 +787,7 @@ void CArtPlace::show(SDL_Surface *to)
 			{
 				if(i==0 || j==0 || i==pos.h-1 || j==pos.w-1)
 				{
-					CSDL_Ext::SDL_PutPixel(to, pos.x+j, pos.y+i, 240, 220, 120);
+					CSDL_Ext::SDL_PutPixelWithoutRefresh(to, pos.x+j, pos.y+i, 240, 220, 120);
 				}
 			}
 		}

+ 0 - 4
CMessage.cpp

@@ -16,13 +16,9 @@
 #include "client/Graphics.h"
 #include "CAdvmapInterface.h"
 SDL_Color tytulowy, tlo, zwykly ;
-SDL_Rect genRect(int hh, int ww, int xx, int yy);
 
 extern SDL_Surface * screen;
 extern TTF_Font * TNRB16, *TNR, *GEOR13;
-SDL_Color genRGB(int r, int g, int b, int a=0);
-//void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);
-bool isItIn(const SDL_Rect * rect, int x, int y);
 
 using namespace NMessage;
 template <typename T, typename U> std::pair<T,U> max(const std::pair<T,U> &x, const std::pair<T,U> &y)

+ 9 - 14
CPlayerInterface.cpp

@@ -55,7 +55,7 @@ extern boost::mutex eventsM;
 class OCM_HLP_CGIN
 {
 public:
-	bool operator ()(const std::pair<const CGObjectInstance*,SDL_Rect>  & a, const std::pair<const CGObjectInstance*,SDL_Rect> & b) const
+	bool inline operator ()(const std::pair<const CGObjectInstance*,SDL_Rect>  & a, const std::pair<const CGObjectInstance*,SDL_Rect> & b) const
 	{
 		return (*a.first)<(*b.first);
 	}
@@ -750,13 +750,13 @@ void CSelectableComponent::init(SDL_Surface * Border)
 		SDL_FillRect(border,NULL,0x00FFFF);
 		for (int i=0;i<border->w;i++)
 		{
-			SDL_PutPixel(border,i,0,239,215,123);
-			SDL_PutPixel(border,i,(border->h)-1,239,215,123);
+			SDL_PutPixelWithoutRefresh(border,i,0,239,215,123);
+			SDL_PutPixelWithoutRefresh(border,i,(border->h)-1,239,215,123);
 		}
 		for (int i=0;i<border->h;i++)
 		{
-			SDL_PutPixel(border,0,i,239,215,123);
-			SDL_PutPixel(border,(border->w)-1,i,239,215,123);
+			SDL_PutPixelWithoutRefresh(border,0,i,239,215,123);
+			SDL_PutPixelWithoutRefresh(border,(border->w)-1,i,239,215,123);
 		}
 		SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
 	}
@@ -2116,15 +2116,10 @@ void CPlayerInterface::battleStackAttacked(BattleStackAttacked * bsa)
 	{
 		battleInt->displayEffect(bsa->effect, cb->battleGetStackByID(bsa->stackAttacked)->position);
 	}
-	if(bsa->killed())
-		battleInt->stackKilled(bsa->stackAttacked, bsa->damageAmount, bsa->killedAmount, LOCPLINT->curAction->stackNumber, LOCPLINT->curAction->actionType==7 );
-	else
-	{
-		std::vector<CBattleInterface::SStackAttackedInfo> arg;
-		CBattleInterface::SStackAttackedInfo to_put = {bsa->stackAttacked, bsa->damageAmount, bsa->killedAmount, LOCPLINT->curAction->stackNumber, LOCPLINT->curAction->actionType==7};
-		arg.push_back(to_put);
-		battleInt->stacksAreAttacked(arg);
-	}
+	std::vector<CBattleInterface::SStackAttackedInfo> arg;
+	CBattleInterface::SStackAttackedInfo to_put = {bsa->stackAttacked, bsa->damageAmount, bsa->killedAmount, LOCPLINT->curAction->stackNumber, LOCPLINT->curAction->actionType==7, bsa->killed()};
+	arg.push_back(to_put);
+	battleInt->stacksAreAttacked(arg);
 }
 void CPlayerInterface::battleAttack(BattleAttack *ba)
 {

+ 0 - 4
CPreGame.cpp

@@ -28,11 +28,7 @@ extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
 #ifdef max
 #undef max
 #endif
-SDL_Rect genRect(int hh, int ww, int xx, int yy);
-SDL_Color genRGB(int r, int g, int b, int a=0);
-//void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
 CPreGame * CPG;
-bool isItIn(const SDL_Rect * rect, int x, int y);
 
 namespace fs = boost::filesystem;
 namespace s = CSDL_Ext;

+ 21 - 35
SDL_Extensions.cpp

@@ -27,7 +27,7 @@ bool isItIn(const SDL_Rect * rect, int x, int y)
 		return true;
 	else return false;
 }
-inline SDL_Rect genRect(int hh, int ww, int xx, int yy)
+inline SDL_Rect genRect(const int & hh, const int & ww, const int & xx, const int & yy)
 {
 	SDL_Rect ret;
 	ret.h=hh;
@@ -233,47 +233,34 @@ void CSDL_Ext::printToWR(const std::string & text, int x, int y, TTF_Font * font
 	SDL_FreeSurface(temp);
 }
 
-void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A)
+inline void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, const int & x, const int & y, const Uint8 & R, const Uint8 & G, const Uint8 & B, Uint8 A)
 {
-	Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC;
-/*
-#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
-	p[0] = R;
-	p[1] = G;
-	p[2] = B;
-#else
-*/
+	Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel;
+
 	p[0] = B;
 	p[1] = G;
 	p[2] = R;
 	if(ekran->format->BytesPerPixel==4)
 		p[3] = A;
-//#endif
+
 	SDL_UpdateRect(ekran, x, y, 1, 1);
 }
 
-void CSDL_Ext::SDL_PutPixelWithoutRefresh(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A)
+inline void CSDL_Ext::SDL_PutPixelWithoutRefresh(SDL_Surface *ekran, const int & x, const int & y, const Uint8 & R, const Uint8 & G, const Uint8 & B, Uint8 A)
 {
-     Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC;
-/*
-#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+	Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel;
+
 	p[0] = B;
 	p[1] = G;
 	p[2] = R;
-#else
-*/
-	p[0] = R;
-	p[1] = G;
-	p[2] = B;
 	if(ekran->format->BytesPerPixel==4)
 		p[3] = A;
-//#endif
 }
 
 ///**************/
 ///Reverses the toRot surface by the vertical axis
 ///**************/
-SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot, int myC)
+SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot)
 {
 	SDL_Surface * ret = SDL_ConvertSurface(toRot, toRot->format, toRot->flags);
 	//SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey);
@@ -288,10 +275,10 @@ SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot, int myC)
 /*
 
 #if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
-						CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2], myC);
+						CSDL_Ext::SDL_PutPixelWithoutRefresh(ret, i, j, p[0], p[1], p[2]);
 #else
 */
-						CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0], myC);
+						CSDL_Ext::SDL_PutPixelWithoutRefresh(ret, i, j, p[2], p[1], p[0]);
 //#endif
 				}
 			}
@@ -327,10 +314,10 @@ SDL_Surface * CSDL_Ext::hFlip(SDL_Surface * toRot)
 					//int k=2;
 /*
 #if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
-						CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2]);
+						CSDL_Ext::SDL_PutPixelWithoutRefresh(ret, i, j, p[0], p[1], p[2]);
 #else
 */
-						CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0]);
+						CSDL_Ext::SDL_PutPixelWithoutRefresh(ret, i, j, p[2], p[1], p[0]);
 //#endif
 				}
 			}
@@ -367,10 +354,10 @@ SDL_Surface * CSDL_Ext::rotate02(SDL_Surface * toRot)
 				Uint8 *p = (Uint8 *)toRot->pixels + i * toRot->pitch + j * toRot->format->BytesPerPixel;
 /*
 #if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
-					SDL_PutPixel(ret, i, j, p[0], p[1], p[2]);
+					SDL_PutPixelWithoutRefresh(ret, i, j, p[0], p[1], p[2]);
 #else
 */
-					SDL_PutPixel(ret, i, j, p[2], p[1], p[0]);
+					SDL_PutPixelWithoutRefresh(ret, i, j, p[2], p[1], p[0]);
 //#endif
 			}
 		}
@@ -395,10 +382,10 @@ SDL_Surface * CSDL_Ext::rotate03(SDL_Surface * toRot)
 					Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j - 1) * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel+2;
 /*
 #if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
-						SDL_PutPixel(ret, i, j, p[0], p[1], p[2], 2);
+						SDL_PutPixelWithoutRefresh(ret, i, j, p[0], p[1], p[2], 0);
 #else
 */
-						SDL_PutPixel(ret, i, j, p[2], p[1], p[0], 2);
+						SDL_PutPixelWithoutRefresh(ret, i, j, p[2], p[1], p[0], 0);
 //#endif
 				}
 			}
@@ -509,7 +496,6 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
 
 int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)
 {
-	static std::map<Uint8, int> st;
 	if(src && src->format->BytesPerPixel==1 && dst && (dst->format->BytesPerPixel==3 || dst->format->BytesPerPixel==4)) //everything's ok
 	{
 		SDL_Rect fulldst;
@@ -712,13 +698,13 @@ void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 co
 {
 	for(int i=0;i<w;i++)
 	{
-		SDL_PutPixel(sur,x+i,y,color.x,color.y,color.z);
-		SDL_PutPixel(sur,x+i,y+h-1,color.x,color.y,color.z);
+		SDL_PutPixelWithoutRefresh(sur,x+i,y,color.x,color.y,color.z);
+		SDL_PutPixelWithoutRefresh(sur,x+i,y+h-1,color.x,color.y,color.z);
 	}
 	for(int i=0; i<h;i++)
 	{
-		SDL_PutPixel(sur,x,y+i,color.x,color.y,color.z);
-		SDL_PutPixel(sur,x+w-1,y+i,color.x,color.y,color.z);
+		SDL_PutPixelWithoutRefresh(sur,x,y+i,color.x,color.y,color.z);
+		SDL_PutPixelWithoutRefresh(sur,x+w-1,y+i,color.x,color.y,color.z);
 	}
 }
 void CSDL_Ext::setPlayerColor(SDL_Surface * sur, unsigned char player)

+ 4 - 4
SDL_Extensions.h

@@ -20,13 +20,13 @@ template <typename T> int getIndexOf(const std::vector<T> & v, const T & val)
 			return i;
 	return -1;
 }
-SDL_Rect genRect(int hh, int ww, int xx, int yy);
+inline SDL_Rect genRect(const int & hh, const int & ww, const int & xx, const int & yy);
 namespace CSDL_Ext
 {
 	extern SDL_Surface * std32bppSurface;
-	void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC=0, Uint8 A = 255); //myC influences the start of reading pixels
-	void SDL_PutPixelWithoutRefresh(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC=0, Uint8 A = 255); //myC influences the start of reading pixels ; without refreshing
-	SDL_Surface * rotate01(SDL_Surface * toRot, int myC = 2); //vertical flip
+	inline void SDL_PutPixel(SDL_Surface *ekran, const int & x, const int & y, const Uint8 & R, const Uint8 & G, const Uint8 & B, Uint8 A = 255); //myC influences the start of reading pixels
+	inline void SDL_PutPixelWithoutRefresh(SDL_Surface *ekran, const int & x, const int & y, const Uint8 & R, const Uint8 & G, const Uint8 & B, Uint8 A = 255); //myC influences the start of reading pixels ; without refreshing
+	SDL_Surface * rotate01(SDL_Surface * toRot); //vertical flip
 	SDL_Surface * hFlip(SDL_Surface * toRot); //horizontal flip
 	SDL_Surface * rotate02(SDL_Surface * toRot); //rotate 90 degrees left
 	SDL_Surface * rotate03(SDL_Surface * toRot); //rotate 180 degrees

+ 5 - 1
mapHandler.h

@@ -47,7 +47,11 @@ public:
 		for(int i=src.size(); i<src.size()+offset;i++)
 			inver[offset+i] = fill;
 	}
-	inline T & operator[](int n)
+	inline T & operator[](const int & n)
+	{
+		return inver[n+offset];
+	}
+	inline const T & operator[](const int & n) const
 	{
 		return inver[n+offset];
 	}