It is currently Tue Dec 12, 2017 10:28 pm

All times are UTC - 5 hours




 Page 1 of 2 [ 26 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Sat May 24, 2014 1:34 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
In this video I add support to the MkoFileReader so that you can open 1 mko file, but then generate multiple objects out of the one file.

Then I present to you Challenge #3. I demonstrate in this video what the winning solution must be able to do, but I have summarized the 5 functions that you must be able to complete:

#1 Add a console key which can add 3 more image mko object into the array.
#2 Add a console key which can list all the image mko objects that you have currently loaded into the array.
#3 Add a console key that can delete 1 image mko object from the array.
#4 Add a console key that displays how many textures are loaded into memory.
#5 Add a console key that can delete 1 image mko object and also delete the texture associated with it. (make sure you test #1 after implementing this to make sure you didn't break anything else!)

Post your solution in the forum thread for me to test and the first person that implements all 5 things correctly will win 200 download credits.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Sat May 24, 2014 8:15 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
I have been working on this and so far this is what I have. All are working correct but the one in which it deletes the image and texture. Here is what I have so far. I added a function in the Image2d to get our infoStructure. I also added the ability to save our file name in that class and added a method to retrieve it. Here is my code inside the Game.cpp's consoleKyeboardInput() function. I also added the keys to be used in the F1 help display menu.

// ----------------------------------------------------------------------------
// consoleKeyboardInput()
void Game::consoleKeyboardInput( unsigned vkCode, bool isPressed ) {
   // Keep Track Of Which Keys Are Pressed And Which Ones Are Released
   static bool keyPressed[256] = { 0 };
   if ( vkCode < 256 ) {
      keyPressed[vkCode] = isPressed;
   }

   // std::cout << "Console Key 0x" << std::hex << vkCode << " was " << ( isPressed ? "Pressed" : "Released" ) << std::endl;
   
   if ( !isPressed ) {
      return;
   }

   switch ( vkCode ) {
      case VK_F1 : {
         std::cout << "Console Commands:" << std::endl
            << "F1  - Shows this help text" << std::endl
            << "ESC - Quit" << std::endl
            << "A   - Add Texture" << std::endl
            << "S   - Query Textures" << std::endl
            << "D   - Delete One Texture Image" << std::endl
            << "T   - Show Texture Info" << std::endl
            << "E   - Delete Image and Texture" << std::endl
            << "M   - Toggle memory debugging" << std::endl;
         break;
      }
      case VK_ESCAPE: {
         PostQuitMessage( 0 );
         break;
      }
      case 'A' : {
         loadImages();
         break;
      }
      case 'S' : {
         for ( unsigned u = 0; u < _vImage2d.size(); ++u ) {
            std::cout << "Loaded Image: mko" << _vImage2d.at(u)->getId() << std::endl;
         }
         std::cout << std::endl;

         break;
      }
      case 'D' : {
         if ( _vImage2d.size() >= 1 ) {
            _vImage2d.pop_back();
         }
         break;
      }
      case 'T' : {
         std::cout << "Loaded texture listed below:" << std::endl;
         for ( unsigned u = 0; u < _vImage2d.size(); ++u ) {
            std::cout << "textureId<" << _vImage2d.at( u )->getId() << "> transparency<"
                 << (_vImage2d.at( u )->getTextureInfo().hasTransparency ? "Y" : "N" ) << "> size<"
                  << _vImage2d.at( u )->getTextureInfo().size.x << ","
                 << _vImage2d.at( u )->getTextureInfo().size.y << "> "
                 << _vImage2d.at( u )->getTextureFilename() << std::endl;
            }
         std::cout << std::endl;

         break;      
      }
      case 'E' : {
         if ( _vImage2d.size() >= 1 ) {
            _vImage2d.back()->clearTextureInfo(); // Not Sure if this is correct
            _vImage2d.pop_back();
         }

         break;
      }
      case 'M' : {         
         unsigned debugLogging = _pSettings->getDebugLogging();
         debugLogging ^= Settings::DEBUG_MEMORY;
         _pSettings->setDebugLogging( debugLogging );

         std::cout << "Debug memory turned " << ( ( ( debugLogging & Settings::DEBUG_MEMORY ) == Settings::DEBUG_MEMORY ) ? "ON" : "OFF" ) << std::endl;
   
         break;
      }
   }

} // consoleKeyboardInput


The case where I am using 'E' to delete and remove the texture is where I am having trouble!


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Sat May 31, 2014 8:24 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
Keep trying everyone, I'm still waiting for someone with the correct solution.

@skilz80, don't forget what the AssetStorage class is for, you need to use it if you want to have the correct solution for the challenge.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Mon Jun 02, 2014 8:59 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
I've worked at this for some time, I think I have it working now. I added in the ability to use the AssetStorage Class. When I Use the "d" key it does a single delete of render image, but the texture stays in memory. When I use the "e" key it removes all loaded textures and removes the mko from memory. No exceptions are thrown and the engine does not crash if you keep pressing "e" or "d" after all textures are gone. Also if all textures are gone and you are trying to query its Id or information there is no exception thrown. I think this is what you are looking for or very close, please let me know all feedback is acceptable. Here is the code

// ----------------------------------------------------------------------------
// consoleKeyboardInput()
void Game::consoleKeyboardInput( unsigned vkCode, bool isPressed ) {
   // Keep Track Of Which Keys Are Pressed And Which Ones Are Released
   static bool keyPressed[256] = { 0 };
   if ( vkCode < 256 ) {
      keyPressed[vkCode] = isPressed;
   }

   // std::cout << "Console Key 0x" << std::hex << vkCode << " was " << ( isPressed ? "Pressed" : "Released" ) << std::endl;
   
   if ( !isPressed ) {
      return;
   }

   switch ( vkCode ) {
      case VK_F1 : {
         std::cout << "Console Commands:" << std::endl
            << "F1  - Shows this help text" << std::endl
            << "ESC - Quit" << std::endl
            << "A   - Add Texture" << std::endl
            << "S   - Query Textures" << std::endl
            << "D   - Delete One Texture Image" << std::endl
            << "T   - Show Texture Info" << std::endl
            << "E   - Delete Image and Texture" << std::endl
            << "M   - Toggle memory debugging" << std::endl;
         break;
      }
      case VK_ESCAPE: {
         PostQuitMessage( 0 );
         break;
      }
      case 'A' : {
         loadImages();
         break;
      }
      case 'S' : {

         if ( !_vImage2d.empty() ) {
            for ( unsigned u = 0; u < _vImage2d.size(); ++u ) {
               std::cout << "Loaded Image: " << _vImage2d.at( u )->getId() << std::endl;
            }
            std::cout << std::endl;
         }

         break;
      }
      case 'D' : {
         if ( _vImage2d.size() >= 1 ) {
            _pAssetStorage->removeMko( _vImage2d.back()->getId(), false );
            _vImage2d.pop_back();
         }
         
         break;
      }
      case 'T' : {
         if ( !_vImage2d.empty() ) {
            std::string strFilename = _vImage2d.front()->getTextureFilename();

            std::cout << "Loaded texture listed below:" << std::endl;
            
            std::cout << "textureId<" << _pAssetStorage->getTextureInfo( strFilename ).uTextureId
               << "> transparency<"
               << (_pAssetStorage->getTextureInfo( strFilename ).hasTransparency ? "Y" : "N" ) << "> size<"
               << _pAssetStorage->getTextureInfo( strFilename ).size.x << ","
               << _pAssetStorage->getTextureInfo( strFilename ).size.y << "> "
               << strFilename << std::endl;
         }
                        
         std::cout << std::endl;

         break;      
      }
      case 'E' : {
         if ( !_vImage2d.empty() ) {
            
            _pAssetStorage->removeMko( _vImage2d.front()->getId(), true );
            //_pAssetStorage->removeTextureInfo( _vImage2d.back()->getId() );
            _vImage2d.clear();
         }
         
         break;
      }
      case 'M' : {         
         unsigned debugLogging = _pSettings->getDebugLogging();
         debugLogging ^= Settings::DEBUG_MEMORY;
         _pSettings->setDebugLogging( debugLogging );

         std::cout << "Debug memory turned " << ( ( ( debugLogging & Settings::DEBUG_MEMORY ) == Settings::DEBUG_MEMORY ) ? "ON" : "OFF" ) << std::endl;
   
         break;
      }
   }

} // consoleKeyboardInput


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Mon Jun 02, 2014 9:20 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
Getting closer skilz80, but I still see bugs in your code and the "Show Texture Info" case can be handled more efficiently.

Try the following with your program:
* Place 12 images on your screen
* Delete one image including the texture associated with it.
( you should not be able to see the remaining 11 images since the texture has been deleted, however these 11 should still exist in memory )
* Add 3 more images
( you should now see 14 images. The 11 original ones, plus the 3 new ones ).

Keep trying.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Mon Jun 02, 2014 11:10 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
For the show texture info case, should I just use the info from the vector itself like I did in my first posting? Or am I to still use the AssetStorage?


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Mon Jun 02, 2014 11:26 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
skilz80 wrote:
For the show texture info case, should I just use the info from the vector itself like I did in my first posting? Or am I to still use the AssetStorage?


You should be using the AssetStorage since in the future we will have many textures, and not all of them are going to be easily accessible via objects i the Game class. The AssetStorage is the place to keep track of everything in memory.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Mon Jun 02, 2014 11:36 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
Okay that is what I was thinking, but I'm trying to see how it can be written more efficiently.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Mon Jun 02, 2014 5:53 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
I've made a few changes to the code. This is working as you have show in your challenge video or at least it appears to be. However, I do not know why but when I am using the "E" key yes the texture images are removed from the render screen and the textures are still loaded in memory, but I am getting a black box where the textures use to be drawn instead of a clean white page. I have looked everywhere for any type of bugs, but do not seem to find any. Any idea where I can start to look?

// ----------------------------------------------------------------------------
// consoleKeyboardInput()
void Game::consoleKeyboardInput( unsigned vkCode, bool isPressed ) {
   // Keep Track Of Which Keys Are Pressed And Which Ones Are Released
   static bool keyPressed[256] = { 0 };
   if ( vkCode < 256 ) {
      keyPressed[vkCode] = isPressed;
   }

   // std::cout << "Console Key 0x" << std::hex << vkCode << " was " << ( isPressed ? "Pressed" : "Released" ) << std::endl;
   
   if ( !isPressed ) {
      return;
   }

   switch ( vkCode ) {
      case VK_F1 : {
         std::cout << "Console Commands:" << std::endl
            << "F1  - Shows this help text" << std::endl
            << "ESC - Quit" << std::endl
            << "A   - Add Texture" << std::endl
            << "S   - Query Textures" << std::endl
            << "D   - Delete One Texture Image" << std::endl
            << "T   - Show Texture Info" << std::endl
            << "E   - Delete Image and Texture" << std::endl
            << "M   - Toggle memory debugging" << std::endl;
         break;
      }
      case VK_ESCAPE: {
         PostQuitMessage( 0 );
         break;
      }
      case 'A' : {
         loadImages();
         break;
      }
      case 'S' : {

         if ( !_vImage2d.empty() ) {
            for ( unsigned u = 0; u < _vImage2d.size(); ++u ) {
               std::cout << "Loaded Image: " << _vImage2d.at( u )->getId() << std::endl;
            }
            std::cout << std::endl;
         }

         break;
      }
      case 'D' : {
         if ( _vImage2d.size() >= 1 ) {
            _pAssetStorage->removeMko( _vImage2d.back()->getId(), false );
            _vImage2d.pop_back();
         }
         
         break;
      }
      case 'T' : {
         if ( !_vImage2d.empty() ) {

            const std::string& strFilename = _vImage2d.front()->getTextureFilename();            

            std::cout << "Loaded texture listed below:" << std::endl
               << "textureId<" << _pAssetStorage->getTextureInfo( strFilename ).uTextureId
               << "> transparency<"
               << (_pAssetStorage->getTextureInfo( strFilename ).hasTransparency ? "Y" : "N" ) << "> size<"
               << _pAssetStorage->getTextureInfo( strFilename ).size.x << ","
               << _pAssetStorage->getTextureInfo( strFilename ).size.y << "> "
               << strFilename << std::endl;
         }
                        
         std::cout << std::endl;

         break;      
      }
      case 'E' : {
         if ( !_vImage2d.empty() ) {            
            _pAssetStorage->removeTextureInfo( _vImage2d.back()->getTextureInfo().uTextureId );
         }
         
         break;
      }
      case 'M' : {         
         unsigned debugLogging = _pSettings->getDebugLogging();
         debugLogging ^= Settings::DEBUG_MEMORY;
         _pSettings->setDebugLogging( debugLogging );

         std::cout << "Debug memory turned " << ( ( ( debugLogging & Settings::DEBUG_MEMORY ) == Settings::DEBUG_MEMORY ) ? "ON" : "OFF" ) << std::endl;
   
         break;
      }
   }

} // consoleKeyboardInput


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Tue Jun 03, 2014 7:42 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
When you press the letter 'S' in your program, print more than just the id for your Image2d object. This should give you an idea of what is going wrong.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Tue Jun 03, 2014 8:10 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
I am not seeing it. When I am using the Image2d vector to display the information. The Size for (x,y) from its info structure match what is stored in the AssetStorage, the getFilename() is retrieving the same file name as the AssetStorage. The transparency information is the same the only difference is the _vImage2d's getId() is returning mko+ for as many images stored in the vector, where as in the Image2d's getTextureInfo().uTextureId = 1 for all 3 images. But isn't this what we are expecting? Since all three images are sharing the same texture ?


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Wed Jun 04, 2014 5:11 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
After some time searching, I have found one apparent bug. This bug was hidden inside the Image2d.cpp file. Inside the constructor where we are creating our Texture Coordinate Buffer for the glBufferData() call one of the variables I was passing in was vVertexPositions instead of vTextureCoordiantes. I changed this however I am still getting the same behavior when I am using my "d" key. The Images or textures are being removed from the render screen they are still in memory but I am getting a black rectangle in their locations. I will keep looking, I'm still not sure where this bug is coming from.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Wed Jun 04, 2014 5:40 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
I added this to my 'T': case

unsigned u = 0;
         for ( ; u < _vImage2d.size(); ++u ) {
            std::cout << "Info from Image2d vector directly:" << std::endl
                 << "TextureId: " << _vImage2d.at(u)->getId() << std::endl
                 << "TextureId: " << _vImage2d.at(u)->getTextureInfo().uTextureId << std::endl
                 << "Transparency: "  << (_vImage2d.at(u)->getTextureInfo().hasTransparency ? "Y" : "N") << std::endl
                 << "Size: " << _vImage2d.at(u)->getTextureInfo().size.x << "," << _vImage2d.front()->getTextureInfo().size.y << std::endl
                 << "Filename: " << _vImage2d.at(u)->getTextureFilename() << std::endl << std::endl;

            std::cout << "Info from AssetStorage: " << std::endl;
            const std::string& strFilename = _vImage2d.at(u)->getTextureFilename();
            std::cout << "TextureId: " << _pAssetStorage->getTextureInfo( strFilename ).uTextureId << std::endl
                 << "Transparency: " << (_pAssetStorage->getTextureInfo( strFilename ).hasTransparency ? "Y" : "N" ) << std::endl
                 << "Size: " << _pAssetStorage->getTextureInfo( strFilename ).size.x << "," << _pAssetStorage->getTextureInfo( strFilename ).size.y << std::endl
                 << "Filename: N/A from AssetStorage" << std::endl << std::endl;
         }


When I first run the program and the 3 original are displayed and I press the T key the info is showed for all 3 in both cases and everything matches. When I use my "d" key, everything is working correctly the two remaining have the same information. The same happens when I press the "d" key until none are left. Then I press my "a" key to add 3 more and three new ones are displayed. I then press the "T" key and the info is displayed for all 3 correctly in both cases. Now at this point I have 3 being displayed but their mko ids are mko4,5,6 respectively. This time instead of pressing "d" to delete one at a time. I am now pressing my "e" key and this is where I get the black shadows. When I press the "T" this is what I am getting: I'll just show the first case and not all three

Info from Image2d vector directly:
TextureId: mko4
TextureId: 1
Transparency: Y
Size: 150, 200
Filename: Assets/images/testImageRLE.tga

Info from AssetStorage:
TextureId: 4294967295
Transparency: N
Size: 0,0
Filename: N/A from AssetStorage.

The TextureId from the AssetStorage should be matching the Second TextureId from the vector<Image2d> pointer calling the getTextureInfo but it isn't. This is telling me that the data is being deleted but it shouldn't be. At this point I'm not sure if I should be using the removeTextureInfo call or using the removeMko call and if using the removeMko call either passing in true or false(default). I have tried all combinations. I know I'm close to getting this though.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Wed Jun 04, 2014 6:26 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
I do have a question, the AssetStorage's removeTextureInfo() function it takes in either an std::string or unsigned id. The overloaded method that takes the std::string as a filename is this the filename for the .mko file or the texture image file that is stored?

I did this as a test, and I can see where there are some problems now.

// This first one is just a reference for comparing strings in the debugger. This is the filename we passed into our Fileloader to create our Image2d object.
const std::string& strFilename = std::string( "Assets/testImageRLE.mko" );

// This one is the filename that I am getting from my getTextureFilename from my Image2d class that I added.
const std::string& strFilename2 = _vImage2d.front()->getTextureFilename();


For the 1st as Expected the string shows "Assets/testImageRLE.mko".
For the 2nd the string in the debugger is "Assets/images/testImageRLE.tga"

So which string is the removeTextureInfo() expecting ?


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Wed Jun 04, 2014 7:33 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
You're getting close to solving this problem. When you ask the asset storage to remove a texture, you need to specify which texture you want to remove, not which object this texture is attached to.

Now as for the black "shadows". This is to be expected. I do not see black squares but you do which is okay, because this result is graphic card hardware dependant. Your graphics card handles this differently than mine, and that is fine.

Once you figure out why this is happening, then you should be able to complete the last part of the challenge.
* add 12 images to the screen
* delete 1 with its texture
* add 3 more and you should now see 14 on the screen.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Wed Jun 04, 2014 11:23 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
Okay here is my revised code for my consoleKeyboardInput function and I optimized it the best way I know how at this point. I am getting the behavior you are showing in the video.
Let me know if you are looking for something else.

// ----------------------------------------------------------------------------
// consoleKeyboardInput()
void Game::consoleKeyboardInput( unsigned vkCode, bool isPressed ) {
   // Keep Track Of Which Keys Are Pressed And Which Ones Are Released
   static bool keyPressed[256] = { 0 };
   if ( vkCode < 256 ) {
      keyPressed[vkCode] = isPressed;
   }

   // std::cout << "Console Key 0x" << std::hex << vkCode << " was " << ( isPressed ? "Pressed" : "Released" ) << std::endl;
   
   if ( !isPressed ) {
      return;
   }

   switch ( vkCode ) {
      case VK_F1 : {
         std::cout << "Console Commands:" << std::endl
            << "F1  - Shows this help text" << std::endl
            << "ESC - Quit" << std::endl
            << "A   - Add Texture" << std::endl
            << "S   - Query Textures" << std::endl
            << "D   - Delete One Texture Image" << std::endl
            << "T   - Show Texture Info" << std::endl
            << "E   - Delete Image and Texture" << std::endl
            << "M   - Toggle memory debugging" << std::endl;
         break;
      }
      case VK_ESCAPE: {
         PostQuitMessage( 0 );
         break;
      }
      case 'A' : {
         loadImages();
         break;
      }
      case 'S' : {

         if ( _vImage2d.empty() ) {
            break;
         } else {         
            unsigned u = 0;
            for ( ; u < _vImage2d.size(); ++u ) {
               std::cout << "Loaded Image: " << _vImage2d[u]->getId() << std::endl;
            }
            std::cout << std::endl;
         }

         break;
      }
      case 'D' : {
         if ( _vImage2d.empty() ) {
            break;
         } else {
            _pAssetStorage->removeMko( _vImage2d.back()->getId(), false );
            _vImage2d.pop_back();
         }
         
         break;
      }
      case 'T' : {
         if ( _vImage2d.empty() ) {
            break;
         } else {
            unsigned u = 0;
            for ( ; u < _vImage2d.size(); ++u ) {
               const std::string& strFilename = _vImage2d[u]->getTextureFilename();            

               std::cout << "Loaded texture listed below:" << std::endl
                  << "textureId<" << _pAssetStorage->getTextureInfo( strFilename ).uTextureId
                  << "> transparency<"
                  << (_pAssetStorage->getTextureInfo( strFilename ).hasTransparency ? "Y" : "N" ) << "> size<"
                  << _pAssetStorage->getTextureInfo( strFilename ).size.x << ","
                  << _pAssetStorage->getTextureInfo( strFilename ).size.y << "> "
                  << strFilename << std::endl;
            }                        
            std::cout << std::endl;
         }
         break;      
      }
      case 'E' : {
         if ( _vImage2d.empty() ) {
            break;
         } else {
            _pAssetStorage->removeTextureInfo( _vImage2d[0]->getTextureFilename() );
         }
         break;
      }
      case 'M' : {         
         unsigned debugLogging = _pSettings->getDebugLogging();
         debugLogging ^= Settings::DEBUG_MEMORY;
         _pSettings->setDebugLogging( debugLogging );

         std::cout << "Debug memory turned " << ( ( ( debugLogging & Settings::DEBUG_MEMORY ) == Settings::DEBUG_MEMORY ) ? "ON" : "OFF" ) << std::endl;
   
         break;
      }
   }

} // consoleKeyboardInput


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Sat Jun 07, 2014 9:36 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
I changed my 'E' case from what I had above to this:

case 'E' : {
         if ( _vImage2d.empty() ) {
            break;
         } else {
            _pAssetStorage->removeMko( _vImage2d.back()->getId(), true );
            _vImage2d.pop_back();
            //_pAssetStorage->removeTextureInfo( _vImage2d[0]->getTextureFilename() );
         }
         break;
      }


you can use the same source that I sent you and change the 'E' case to this.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Mon Jun 09, 2014 5:12 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
I have watched your video again and I am following your steps and I am seeing the same behavior as you have.
This is what I currently have for my source code for the solution.

// ----------------------------------------------------------------------------
// consoleKeyboardInput()
void Game::consoleKeyboardInput( unsigned vkCode, bool isPressed ) {
   // Keep Track Of Which Keys Are Pressed And Which Ones Are Released
   static bool keyPressed[256] = { 0 };
   if ( vkCode < 256 ) {
      keyPressed[vkCode] = isPressed;
   }

   // std::cout << "Console Key 0x" << std::hex << vkCode << " was " << ( isPressed ? "Pressed" : "Released" ) << std::endl;
   
   if ( !isPressed ) {
      return;
   }

   switch ( vkCode ) {
      case VK_F1 : {
         std::cout << "Console Commands:" << std::endl
            << "F1  - Shows this help text" << std::endl
            << "ESC - Quit" << std::endl
            << "A   - Add Texture" << std::endl
            << "S   - Query Textures" << std::endl
            << "D   - Delete One Texture Image" << std::endl
            << "T   - Show Texture Info" << std::endl
            << "E   - Delete Image and Texture" << std::endl
            << "M   - Toggle memory debugging" << std::endl;
         break;
      }
      case VK_ESCAPE: {
         PostQuitMessage( 0 );
         break;
      }
      case 'A' : {
         loadImages();
         break;
      }
      case 'S' : {

         if ( _vImage2d.empty() ) {
            break;
         } else {         
            unsigned u = 0;
            for ( ; u < _vImage2d.size(); ++u ) {
               std::cout << "Loaded Image: " << _vImage2d[u]->getId() << std::endl;
            }
            std::cout << std::endl;
         }

         break;
      }
      case 'D' : {
         if ( _vImage2d.empty() ) {
            break;
         } else {
            _pAssetStorage->removeMko( _vImage2d.back()->getId(), false );
            _vImage2d.pop_back();
         }
         
         break;
      }
      case 'T' : {
         if ( _vImage2d.empty() ) {
            break;
         } else {            

            const std::string& strFilename = _vImage2d[0]->getTextureFilename();               

            std::cout << "Loaded texture listed below:" << std::endl
               << "textureId<" << _pAssetStorage->getTextureInfo( strFilename ).uTextureId
               << "> transparency<"
               << (_pAssetStorage->getTextureInfo( strFilename ).hasTransparency ? "Y" : "N" ) << "> size<"
               << _pAssetStorage->getTextureInfo( strFilename ).size.x << ","
               << _pAssetStorage->getTextureInfo( strFilename ).size.y << "> "
               << strFilename << std::endl;
                        
            std::cout << std::endl;
         }
         break;      
      }
      case 'E' : {
         if ( _vImage2d.empty() ) {
            break;
         } else {
            _pAssetStorage->removeMko( _vImage2d.back()->getId(), true );
            _vImage2d.pop_back();
         }
         break;
      }
      case 'M' : {         
         unsigned debugLogging = _pSettings->getDebugLogging();
         debugLogging ^= Settings::DEBUG_MEMORY;
         _pSettings->setDebugLogging( debugLogging );

         std::cout << "Debug memory turned " << ( ( ( debugLogging & Settings::DEBUG_MEMORY ) == Settings::DEBUG_MEMORY ) ? "ON" : "OFF" ) << std::endl;
   
         break;
      }
   }

} // consoleKeyboardInput


You can copy and replace this with the solution I sent you, nothing else in my solution has changed. If you are getting different behavior then what I am I do not know what is causing it. I am using VS2012 Ultimate on Win7 64bit Home Premium. Using an NVIDA video card.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Mon Jun 09, 2014 4:17 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
Here is the loadImages() function you requested.

// ----------------------------------------------------------------------------
// loadImages
void Game::loadImages() {
   MkoFileReader file( "Assets/testImageRLE.mko" );
   for ( unsigned u = 0; u < 3; ++u ) {
      _vImage2d.push_back( file.getMko<Image2d>() );
   }

} // loadImages


should be exactly the same as in your video.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Tue Jun 10, 2014 7:32 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
@skilz80 loadImages needs to be updated for the correct solution to challenge #3. Here are some questions for you to answer to understand why this function needs updating.

* When you add 3 new Image2d objects, which texture ID do they refer to?
* When you delete an Image2d object and you remove the texture from memory, what happens to the other two Image2d object's texture IDs?
* When you add 3 new image2d objects, which texture ID do they now have?

Use your debugger and take a look at the mko and texture objects stored in the Asset Storage class to answer these questions.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Tue Jun 10, 2014 8:01 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
After stepping through the debugger my loadImages() function is creating the 3 initial and when I press the "A" key it is creating 3 more. The baseMko's stringId for each of the 6 in the vector are mko1 ... mko6 for as many as are in the vector. For the image2d object within the textureInfo structure the id for the texture for all of these objects is set to 1. This also matches what the AssetStorage has. I do not see why this needs to be modified and if so, how to at this point. I will continue to work on it.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Tue Jun 10, 2014 8:22 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
I changed my 'E' key to this:
      case 'E' : {
         if ( _vImage2d.empty() ) {
            break;
         } else {
            _pAssetStorage->removeMko( _vImage2d.back()->getId(), false );
            _vImage2d.pop_back();
            
            _pAssetStorage->removeTextureInfo( _vImage2d.back()->getTextureInfo().uTextureId );
         }
         break;
      }


I did this so it would remove 1 object same as the "D" case except that afterwards it will remove the texture associated with it.
After setting a break point on my "E" case and stepping through for the _vImage2d vector the strId is the same mk1 ... to how many are in the vector. The textureId is still 1. In the AssetStorage the stringId is the same mko1 ... to its size. The textureId for each mko asset is the same "1", however the _textureInfo's size in the Asset Storage is now 0.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Tue Jun 10, 2014 8:29 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
The new code for the 'E' case is incorrect.

Test what happens when you only have one Image2d object inside the _vImage2d vector.


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Tue Jun 10, 2014 8:47 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
I know, I was doing this for testing purposes. It should be what I have above.

      case 'E' : {
         if ( _vImage2d.empty() ) {
            break;
         } else {
            _pAssetStorage->removeMko( _vImage2d.back()->getId(), true );
            _vImage2d.pop_back();            
         }
         break;
      }


Offline
 Profile  
 
 Post subject: Re: Shader VMK 46 - Multi MKO & Challenge 3
PostPosted: Fri Jun 13, 2014 7:15 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 450
I've been looking at this for quite some time, and you said that my loadImage() needs to be changed for the correct solution. I used the implementation you showed in the video and it creates 3 Image2d pointers adds them to the vector stored in the game class, and by doing so. When the Image2d objects are created they are automatically added into the AssetStorage. This is where I am getting a bit lost.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 2 [ 26 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron