selectionMgr.cpp

Go to the documentation of this file.
00001 /*
00002  * selectionMgr.cpp
00003  *
00004  *  Created on: Jan 24, 2012
00005  *      Author: sushil
00006  */
00007 
00008 #include <selectionMgr.h>
00009 #include <engine.h>
00010 #include <ent.h>
00011 #include <map>
00012 #include "DEBUG.h"
00013 
00014 void FastEcslent::SelectionMgr::reset() {
00015         for (std::map<Identity, Entity *>::iterator it = selectedEnts.begin(); it != selectedEnts.end(); it++){
00016                 it->second->isSelected = false;
00017         }
00018         this->selectedEnts.clear();
00019         primarySelection = NULL;
00020 }
00021 
00022 void FastEcslent::SelectionMgr::resetAll() {
00023         for (int i = 0; i < this->engine->entityMgr->nEnts; i++){
00024                 this->engine->entityMgr->ents[i]->isSelected = false;
00025         }
00026         this->selectedEnts.clear();
00027         primarySelection = NULL;
00028 }
00029 
00030 //FastEcslent::SelectionMgr::SelectionMgr() {
00031 //      resetAll();
00032 //}
00033 
00034 FastEcslent::SelectionMgr::SelectionMgr(Engine* engine, Options opts): Mgr(engine) {
00035         resetAll();
00036         options = opts;
00037 }
00038 
00039 void FastEcslent::SelectionMgr::init() {
00040         DEBUG(std::cout << "SelectionMgr Initialized" << std::endl;)
00041 
00042         resetAll();
00043 }
00044 
00045 
00046 
00047 void FastEcslent::SelectionMgr::tick(double dtime){
00048 
00049 
00050         return;
00051 }
00052 
00053 void FastEcslent::SelectionMgr::updatePrimarySelection(){
00054         if(!selectedEnts.empty()){
00055                 primarySelection = selectedEnts.begin()->second;
00056         }
00057 }
00058 
00059 //-----------------------------
00060 void FastEcslent::SelectionMgr::select(int i){
00061         Entity *ent;
00062         ent = engine->entityMgr->ents[i];
00063         if (!ent->isSelected) {
00064                 ent->isSelected = true;
00065                 selectedEnts[ent->entityId] = ent;
00066         }
00067         updatePrimarySelection();
00068 }
00069 void FastEcslent::SelectionMgr::select(Entity *ent){
00070         if (!ent->isSelected) {
00071                 ent->isSelected = true;
00072                 selectedEnts[ent->entityId] = ent;
00073         }
00074         updatePrimarySelection();
00075 }
00076 //-----------------------------
00077 void FastEcslent::SelectionMgr::unselect(int i){
00078         Entity *ent;
00079         ent = engine->entityMgr->ents[i];
00080 
00081         if (ent->isSelected){
00082                 ent->isSelected = false;
00083                 selectedEnts.erase(ent->entityId);
00084         }
00085         updatePrimarySelection();
00086 }
00087 
00088 void FastEcslent::SelectionMgr::unselect(Entity *ent){
00089         if (ent->isSelected) {
00090                 ent->isSelected = false;
00091                 selectedEnts.erase(ent->entityId);
00092         }
00093         updatePrimarySelection();
00094 }
00095 
00096 // Management
00097 FastEcslent::Entity** FastEcslent::SelectionMgr::getSelectedEnts(){
00098         nSelectedEnts = selectedEnts.size();
00099         int index = 0;
00100         for (std::map<Identity, Entity*>::iterator it = selectedEnts.begin(); it != selectedEnts.end(); it++){
00101                 selectedEntsArray[index++] = it->second;
00102         }
00103         return selectedEntsArray;
00104 }
00105 
00106 FastEcslent::Entity* FastEcslent::SelectionMgr::getPrimarySelection(){
00107         return this->primarySelection;
00108 }
00109 
00110 int FastEcslent::SelectionMgr::getNSelectedEnts(){
00111         this->nSelectedEnts = this->selectedEnts.size();
00112         return this->nSelectedEnts;
00113 }
00114 
00115 void FastEcslent::SelectionMgr::dump(){
00116         DEBUG(std::cout << "Selected: (";)
00117         for (std::map<Identity, Entity*>::iterator it = selectedEnts.begin(); it != selectedEnts.end(); it++){
00118                 DEBUG(std::cout << it->second->entityId.id << ", ";)
00119         }
00120         DEBUG(std::cout << ")" << std::endl;)
00121 }

Generated on Fri Dec 13 14:54:18 2013 for FastECSLent by  doxygen 1.5.4