LCOV - code coverage report
Current view: top level - blClone/src - Application.cpp (source / functions) Hit Total Coverage
Test: report.info Lines: 53 54 98.1 %
Date: 2014-06-08 Functions: 7 7 100.0 %

          Line data    Source code
       1             : #include "Util.h"
       2             : #include "Config.h"
       3             : 
       4             : #include "Application.h"
       5             : 
       6           1 : Application::Application() {
       7             : 
       8           1 :         width_ = Config::SCREEN_WIDTH;
       9           1 :         height_ = Config::SCREEN_HEIGHT;
      10             : 
      11           1 :         display_ = Display::Instance();
      12           1 : }
      13             : 
      14           1 : Application::~Application() {
      15             : 
      16             :         // Destroy lights.
      17           1 :         std::vector< Light* >::iterator iLight;
      18           6 :         for(iLight = lights_.begin(); iLight != lights_.end(); ++iLight) {
      19           5 :                 delete (*iLight);
      20             :         }
      21             : 
      22           1 :         std::vector< Block* >::iterator iBlock;
      23           1 :         for(iBlock = blocks_.begin(); iBlock != blocks_.end(); ++iBlock) {
      24           0 :                 delete (*iBlock);
      25             :         }
      26             : 
      27           1 :         display_->destroy();
      28           1 : }
      29             : 
      30        1000 : void Application::render() {
      31             : 
      32             :         // Clear screen.
      33        1000 :         display_->clear();
      34             : 
      35        1000 :         std::vector< Light* >::iterator iLight;
      36        6000 :         for (iLight = lights_.begin(); iLight != lights_.end(); ++iLight) {
      37             : 
      38             :                 // Start rendering to stencil buffer.
      39        5000 :                 display_->setStencil();
      40             : 
      41        5000 :                 std::vector< Block* >::iterator iBlock;
      42        5045 :                 for (iBlock = blocks_.begin(); iBlock != blocks_.end(); ++iBlock) {
      43             : 
      44          45 :                         std::vector< Edge* > edges;
      45          45 :                         edges = (*iBlock)->getEdges();
      46          45 :                         std::vector< Edge* >::iterator iEdge;
      47         225 :                         for (iEdge = edges.begin(); iEdge != edges.end(); ++iEdge) {
      48             : 
      49             :                                 EdgeShadow* edge_shadow;
      50         180 :                                 edge_shadow = (*iEdge)->castShadow( *iLight );
      51             : 
      52             :                                 // TODO : display_draw_edge_shadow
      53         180 :                                 display_->drawEdgeShadow( edge_shadow );
      54             :                         }
      55          45 :                 }
      56             : 
      57             :                 // End rendering to stencil buffer.
      58        5000 :                 display_->resetStencil();
      59             : 
      60             :                 // Run shader program for given light.
      61        5000 :                 display_->runShader( *iLight );
      62             :         }
      63             : 
      64             :         // Draw all blocks over the scene.
      65        1000 :         display_->drawBlocks( blocks_ );
      66             : 
      67             :         // Refresh display.
      68        1000 :         display_->refresh();
      69        1000 : }
      70             : 
      71           1 : void Application::setUpObjects() {
      72             : 
      73             :         // Random number of lights in a given range.
      74           1 :         int lightCount = Util::randomInRange(Config::MIN_LIGHTS, Config::MAX_LIGHTS);
      75             : 
      76             :         // Create lights.
      77           6 :         for (int i = 1; i <= lightCount; i++) {
      78             : 
      79           5 :                 Light* new_light = new Light();
      80           5 :                 lights_.push_back( new_light );
      81             :         }
      82             : 
      83             :         // Random number of blocks in a given range.
      84           1 :         int blockCount = Util::randomInRange(Config::MIN_BLOCKS, Config::MAX_BLOCKS);
      85             : 
      86             :         // Create blocks.
      87          10 :         for (int i = 1; i <= blockCount; i++) {
      88             : 
      89           9 :                 Block* new_block = new Block();
      90           9 :                 blocks_.push_back( new_block );
      91             :         }
      92           1 : }
      93             : 
      94           1 : void Application::initialize() {
      95             : 
      96             :         // Open graphics window & mode, etc.
      97           1 :         display_->open();
      98             : 
      99             :         // Initialize fragment shader.
     100           1 :         display_->initShader();
     101             : 
     102             :         // Complete graphics initialization.
     103           1 :         display_->initialize();
     104           1 : }
     105             : 
     106           1 : void Application::cleanup() {
     107             : 
     108             :         // Delete and free shader program.
     109           1 :         display_->deleteShader();
     110             : 
     111             :         // Delete and destroy display.
     112           1 :         display_->destroy();
     113           1 : }
     114             : 
     115        1001 : bool Application::isCloseRequested() {
     116             : 
     117             :         // Return quit request from display object.
     118        1001 :         return display_->quitRequest();
     119             : }
     120             : 
     121             : 

Generated by: LCOV version 1.9