00001 /* 00002 * groupMgr.cpp 00003 * 00004 * Created on: Jan 28, 2012 00005 * Author: sushil 00006 */ 00007 #include <groupMgr.h> 00008 #include <mgr.h> 00009 #include <engine.h> 00010 #include "DEBUG.h" 00011 00012 void FastEcslent::GroupMgr::reset() { 00013 nGroups = 0; 00014 } 00015 00016 00017 //FastEcslent::GroupMgr::GroupMgr() { 00018 // reset(); 00019 //} 00020 00021 FastEcslent::GroupMgr::GroupMgr(Engine* engine, Options opts): Mgr(engine) { 00022 reset(); 00023 options = opts; 00024 } 00025 00026 void FastEcslent::GroupMgr::init() { 00027 DEBUG(std::cout << "GroupMgr Initialized" << std::endl;) 00028 for (int i = 0; i < nGroups;i++){ 00029 groups[i]->init(); 00030 } 00031 00032 } 00033 00034 void FastEcslent::GroupMgr::tick(double dtime){ 00035 for (int i = 0; i < nGroups; i++){ 00036 groups[i]->tick(dtime); 00037 } 00038 } 00039 00040 FastEcslent::Group* FastEcslent::GroupMgr::findIfExists(FastEcslent::Group* group){ 00041 00042 for (int i = 0; i < nGroups; i++){ 00043 Group *existingGroup = this->groups[i]; 00044 int nMatches = 0; 00045 if (existingGroup->nEntitiesInGroup == group->nEntitiesInGroup) { 00046 for(int j = 0; j < group->nEntitiesInGroup; j++){ 00047 if(existingGroup->isMember(group->members[j])){ 00048 nMatches++; 00049 } 00050 } 00051 } 00052 if(nMatches == existingGroup->nEntitiesInGroup) 00053 return existingGroup; 00054 } 00055 return 0; 00056 } 00057 00058 FastEcslent::Group* FastEcslent::GroupMgr::createGroup(FastEcslent::Entity** ents, int nMembers){ 00059 assert(nMembers < MaxEnts - 1); 00060 00061 Identity id; 00062 id.id = nGroups; 00063 id.instanceId = engine->instanceId; 00064 00065 Group *newGroup = new Group(this->engine, ents, nMembers, id); 00066 Group* foundGroup = findIfExists(newGroup); 00067 00068 if (!foundGroup){ 00069 groups[nGroups++] = newGroup; 00070 return newGroup; 00071 } else { 00072 return foundGroup; 00073 } 00074 // DEBUG(std::cout << "GroupMgr: created group with " << nEntitiesInGroup << " members." << std::endl;) 00075 //return group; 00076 } 00077 /* 00078 FastEcslent::Group* FastEcslent::GroupMgr::createGroup(){ 00079 00080 Identity id; 00081 id.id = nGroups; 00082 id.instanceId = engine->instanceId; 00083 00084 Group *group = new Group(this->engine, id); 00085 groups[nGroups++] = group; 00086 DEBUG(std::cout << "GroupMgr: created an empty group." << std::endl;) 00087 return group; 00088 } 00089 */ 00090 00091 void FastEcslent::GroupMgr::dumpOne(int i){ 00092 assert(i >= 0 && i < nGroups); 00093 groups[i]->print(); 00094 } 00095 void FastEcslent::GroupMgr::dumpAll(){ 00096 for (int i = 0; i < nGroups; i++){ 00097 groups[i]->print(); 00098 } 00099 }