OSDN Git Service

Field::GetSight()の速度改善。 / Improve Field::GetSight().
authorDeskull <desull@users.sourceforge.jp>
Sun, 11 Jan 2015 04:32:19 +0000 (13:32 +0900)
committerDeskull <desull@users.sourceforge.jp>
Sun, 11 Jan 2015 04:32:19 +0000 (13:32 +0900)
Deeangband/Creature.cpp
Deeangband/Field.cpp
Deeangband/GameSurfaceSDL.cpp
Deeangband/GameWorld.cpp

index 5fbb767..dee3b32 100644 (file)
@@ -428,29 +428,6 @@ namespace Deeangband
                if(fieldPtr == NULL) return;
 
                fieldPtr->GetSight(this->sightList, 12, this->position.GetX(), this->position.GetY());
-
-               /*
-               for(y = this->position.GetY() - 12; y <= this->position.GetY() + 12; y++)
-               {
-                       for(x = this->position.GetX() - 12; y <= this->position.GetX() + 12; y++)
-                       {
-                               this->lore.PutFieldLore(0, x, y);
-                       }
-               }
-               */
-
-               /*
-               this->sight.clear();
-               this->position.GetRoundRange(rangeVec, 0, 12);
-               for(rangeIt = rangeVec.begin(); rangeIt != rangeVec.end(); rangeIt++)
-               {
-                       if(fieldPtr->HaveSight(this->position.GetX(), this->position.GetY(), rangeIt->GetX(), rangeIt->GetY()))
-                       {
-                               this->lore.PutFieldLore(0, rangeIt->GetX(), rangeIt->GetY());
-                               this->sight[rangeIt->GetY()][rangeIt->GetX()] = true;
-                       }
-               }
-               */
        }
 
        void Creature::XMLSave(std::string filename)
index 784981b..279f0c4 100644 (file)
@@ -191,19 +191,16 @@ namespace Deeangband
        {
                MAP_LENGTH x, y, s;
                int sideWidth = size * 2 + 1;
+               int allocSize = sideWidth * sideWidth;
                std::vector<Coordinates> lineVec;
                std::vector<Coordinates>::iterator lineIt;
                std::vector<Coordinates>::reverse_iterator lineRIt;
 
-               for(y = 0 ; y < size * 2 + 1; y++)
-               {
-                       for(x = 0; x < size * 2 + 1; x++)
-                       {
-                               coordVec[y * sideWidth + x] = false;
-                       }
-               }
+               for(s = 0 ; s < allocSize; s++) coordVec[s] = false;
+               coordVec[size * sideWidth + size] = true;
+               
 
-               for(s = size; s >= 0; s--)
+               for(s = size; s >= 1; s--)
                {
                        for(x = baseX - s; x <= baseX + s; x++)
                        {
@@ -218,7 +215,7 @@ namespace Deeangband
                                                Coordinates::LineOfSight(lineVec, baseX, baseY, tx, ty1);
                                                if(lineVec[0].GetX() == baseX && lineVec[0].GetY() == baseY)
                                                {
-                                                       for(lineIt = lineVec.begin(); lineIt < lineVec.end(); lineIt++)
+                                                       for(lineIt = ++lineVec.begin(); lineIt < lineVec.end(); lineIt++)
                                                        {
                                                                int lsx = lineIt->GetX() - baseX + size;
                                                                int lsy = lineIt->GetY() - baseY + size;
@@ -228,7 +225,7 @@ namespace Deeangband
                                                }
                                                else
                                                {
-                                                       for(lineRIt = lineVec.rbegin(); lineRIt < lineVec.rend(); lineRIt++)
+                                                       for(lineRIt = ++lineVec.rbegin(); lineRIt < lineVec.rend(); lineRIt++)
                                                        {
                                                                int lsx = lineRIt->GetX() - baseX + size;
                                                                int lsy = lineRIt->GetY() - baseY + size;
@@ -248,7 +245,7 @@ namespace Deeangband
                                                Coordinates::LineOfSight(lineVec, baseX, baseY, tx, ty2);
                                                if(lineVec[0].GetX() == baseX && lineVec[0].GetY() == baseY)
                                                {
-                                                       for(lineIt = lineVec.begin(); lineIt < lineVec.end(); lineIt++)
+                                                       for(lineIt = ++lineVec.begin()++; lineIt < lineVec.end(); lineIt++)
                                                        {
                                                                int lsx = lineIt->GetX() - baseX + size;
                                                                int lsy = lineIt->GetY() - baseY + size;
@@ -258,7 +255,7 @@ namespace Deeangband
                                                }
                                                else
                                                {
-                                                       for(lineRIt = lineVec.rbegin(); lineRIt < lineVec.rend(); lineRIt++)
+                                                       for(lineRIt = ++lineVec.rbegin()++; lineRIt < lineVec.rend(); lineRIt++)
                                                        {
                                                                int lsx = lineRIt->GetX() - baseX + size;
                                                                int lsy = lineRIt->GetY() - baseY + size;
@@ -286,7 +283,7 @@ namespace Deeangband
                                                Coordinates::LineOfSight(lineVec, baseX, baseY, tx1, ty);
                                                if(lineVec[0].GetX() == baseX && lineVec[0].GetY() == baseY)
                                                {
-                                                       for(lineIt = lineVec.begin(); lineIt < lineVec.end(); lineIt++)
+                                                       for(lineIt = ++lineVec.begin(); lineIt < lineVec.end(); lineIt++)
                                                        {
                                                                int lsx = lineIt->GetX() - baseX + size;
                                                                int lsy = lineIt->GetY() - baseY + size;
@@ -296,7 +293,7 @@ namespace Deeangband
                                                }
                                                else
                                                {
-                                                       for(lineRIt = lineVec.rbegin(); lineRIt < lineVec.rend(); lineRIt++)
+                                                       for(lineRIt = ++lineVec.rbegin(); lineRIt < lineVec.rend(); lineRIt++)
                                                        {
                                                                int lsx = lineRIt->GetX() - baseX + size;
                                                                int lsy = lineRIt->GetY() - baseY + size;
@@ -316,7 +313,7 @@ namespace Deeangband
                                                Coordinates::LineOfSight(lineVec, baseX, baseY, tx2, ty);
                                                if(lineVec[0].GetX() == baseX && lineVec[0].GetY() == baseY)
                                                {
-                                                       for(lineIt = lineVec.begin(); lineIt < lineVec.end(); lineIt++)
+                                                       for(lineIt = ++lineVec.begin(); lineIt < lineVec.end(); lineIt++)
                                                        {
                                                                int lsx = lineIt->GetX() - baseX + size;
                                                                int lsy = lineIt->GetY() - baseY + size;
@@ -326,7 +323,7 @@ namespace Deeangband
                                                }
                                                else
                                                {
-                                                       for(lineRIt = lineVec.rbegin(); lineRIt < lineVec.rend(); lineRIt++)
+                                                       for(lineRIt = ++lineVec.rbegin(); lineRIt < lineVec.rend(); lineRIt++)
                                                        {
                                                                int lsx = lineRIt->GetX() - baseX + size;
                                                                int lsy = lineRIt->GetY() - baseY + size;
index cb395b2..1d128fc 100644 (file)
@@ -134,7 +134,7 @@ namespace Deeangband
                SDL_Rect floorSerfaceRect = {0, 0, squareGraphicWidth, squareGraphicHeight};
                SDL_Surface *surface, *symbolSurface;
 
-               //! @TTF\83t\83H\83\93\83g\82Ì\93Ç\82Ý\8d\9e\82Ý
+               //! @note TTF\83t\83H\83\93\83g\82Ì\93Ç\82Ý\8d\9e\82Ý
 
                font = TTF_OpenFont("ttf\\ipam.ttf", 14);
                fontSmall = TTF_OpenFont("ttf\\ipag.ttf", 9);
@@ -151,7 +151,7 @@ namespace Deeangband
                color.b = 200;
                color.a = 255;
 
-               if(!font)
+               if(!font || !fontSmall)
                {       
                        OutputDebugString(L"Failed: loading .ttf files.\n");
                        exit(1);
@@ -604,28 +604,29 @@ void GameSurfaceSDL::drawField(const CREATURE_IT &subjectCreatureIt, GameWorld *
                {
                        if(px < fieldPtr->GetWidth() && py < fieldPtr->GetHeight())
                        {
+                               SDL_Rect blitRect = {GameSurfaceSDL::sideBarWidth + (px - x) * squareGraphicWidth, 30 + (py - y) * squareGraphicHeight , squareGraphicWidth, squareGraphicHeight};
+                               /*
                                SDL_Rect checkRect1 = {GameSurfaceSDL::sideBarWidth + (px - x) * squareGraphicWidth - 2 + 12, 30 + (py - y) * squareGraphicHeight - 2 + 12, 4, 4};
                                SDL_Rect checkRect2 = {GameSurfaceSDL::sideBarWidth + (px - x) * squareGraphicWidth - 2, 30 + (py - y) * squareGraphicHeight - 2, 4, 4};
                                SDL_Rect checkRect3 = {GameSurfaceSDL::sideBarWidth + (px - x) * squareGraphicWidth - 6 + 12, 30 + (py - y) * squareGraphicHeight - 1, 12, 2};
                                SDL_Rect checkRect4 = {GameSurfaceSDL::sideBarWidth + (px - x) * squareGraphicWidth - 1, 30 + (py - y) * squareGraphicHeight - 6 + 12, 2, 12};
-                               SDL_Rect blitRect = {GameSurfaceSDL::sideBarWidth + (px - x) * squareGraphicWidth, 30 + (py - y) * squareGraphicHeight , squareGraphicWidth, squareGraphicHeight};
-/*
+
                                if(subJectCreaturePtr->GetLore()->GetFieldLore(0, px, py) > 0)
                                {
                                        TAG tag = fieldPtr->GetSquare(px, py)->GetFloorTag();
                                        SDL_BlitSurface(floorSurfaces[tag], &symbolRect, windowSurface, &blitRect);
                                        if(subJectCreaturePtr->InSight(px, py) == false)
                                        {
-                                               SDL_Rect fieldRect = {blitRect.x % 128, blitRect.y % 128, blitRect.x % 128 + squareGraphicWidth, blitRect.y % 128 + squareGraphicHeight};
+                                               SDL_Rect fieldRect = {blitRect.x % 128, blitRect.y % 128, squareGraphicWidth, squareGraphicHeight};
                                                SDL_BlitSurface(unseenFieldSurface, &fieldRect, windowSurface, &blitRect); 
                                        }
                                }
                                else
                                {
-                                       SDL_Rect fieldRect = {blitRect.x % 128, blitRect.y % 128, blitRect.x % 128 + squareGraphicWidth, blitRect.y % 128 + squareGraphicHeight};
+                                       SDL_Rect fieldRect = {blitRect.x % 128, blitRect.y % 128, squareGraphicWidth, squareGraphicHeight};
                                        SDL_BlitSurface(unknownFieldSurface, &fieldRect, windowSurface, &blitRect); 
                                }
-*/
+                               */
 
                                if(subJectCreaturePtr->InSight(px, py))
                                {
@@ -634,11 +635,13 @@ void GameSurfaceSDL::drawField(const CREATURE_IT &subjectCreatureIt, GameWorld *
                                }
                                else
                                {
-                                       SDL_Rect fieldRect = {blitRect.x % 128, blitRect.y % 128, squareGraphicWidth, squareGraphicHeight};
+                                       //SDL_Rect fieldRect = {blitRect.x % 128, blitRect.y % 128, squareGraphicWidth, squareGraphicHeight};
                                        //SDL_FillRect(windowSurface, &fieldRect, SDL_MapRGBA(windowSurface->format, 255, 0, 0, 255));
-                                       SDL_BlitSurface(unknownFieldSurface, &fieldRect, windowSurface, &blitRect); 
+                                       //SDL_BlitSurface(unknownFieldSurface, &fieldRect, windowSurface, &blitRect); 
                                }
+
 /*
+                       
                                else
                                {
                                        SDL_Rect fieldRect = {blitRect.x % 128, blitRect.y % 128, blitRect.x % 128 + squareGraphicWidth, blitRect.y % 128 + squareGraphicHeight};
index 9c195a4..2ab3876 100644 (file)
@@ -95,9 +95,11 @@ namespace Deeangband
 
        bool GameWorld::GenerateCreature(std::map<TAG, boost::shared_ptr<Species>>::iterator& speciesIt, std::map<ID, boost::shared_ptr<Field>>::iterator& fieldIt, MAP_LENGTH x, MAP_LENGTH y)
        {
+               std::map<ID, boost::shared_ptr<Creature>>::iterator creatureIt; 
                creatureList.emplace(this->creatureID, boost::make_shared<Creature>(speciesIt, fieldIt, x, y));
-               creatureList[this->creatureID]->PlusWait(100, TRUE);
-               creatureList[this->creatureID]->UpdateFieldLore();
+               creatureIt = creatureList.find(this->creatureID);
+               creatureIt->second->PlusWait(100, TRUE);
+               creatureIt->second->UpdateFieldLore();
                do
                {
                        this->creatureID++;