[Bastion-cvs] bastion/src/interface/world UnitsView.cpp,1.20,1.21 UnitsView.h,1.12,1.13 WorldView.cp
Brought to you by:
jacek_kolodziej
|
From: Jacek K. <jac...@us...> - 2004-06-30 18:49:40
|
Update of /cvsroot/bastion/bastion/src/interface/world In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24235/src/interface/world Modified Files: UnitsView.cpp UnitsView.h WorldView.cpp Log Message: - Zwyciestwo! Model gry jest oddzielony od jej wizualizacji. Dzieki temu moze istniec caly model swiata bez istnienia wizualizacji (nie testowalem czy mozna tick'ac swiat zanim zacznie sie go ogladac, ale nie powinno byc z tym problemow). W szczegolnosci nie da sie juz przejsc wskaznikami od klas swiata do klas widoku. Teraz metoda void* LoadingScreen::loadLevel(void *levelName) wyglada nader prosto: new World, new GameView(world). Pawel: masz czysty teren jesli chodzi o zapisywanie stanu gry. Sa dwa miejsca gdzie obiekty swiata posiadaja wskaznik do obiektow wizualizacji: UnitHandler oraz EventUnitSpotted (klasa przechowujaca informacje o jednostce w InformationCollectorze). Klasy te posiadaja wskazniki do figurek ("figure"). Przy zapisywaniu stanu gry, nalezy te wskazniki zapisac jako NULL - sa bowiem one poprawiane przy podpinaniu swiata do GameView. Mozna przyjac ze klasa MissileView ktora zajmuje sie renderingiem strzal tez powinna byc zapisywana w pliku. Alternatywnie, mozna odpowiedni wskaznik z klasy Missile zapisac jako NULL - tez powinno dzialac ok. A tak pozatym to gra dziala tak samo jak do tej pory. Index: UnitsView.cpp =================================================================== RCS file: /cvsroot/bastion/bastion/src/interface/world/UnitsView.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** UnitsView.cpp 29 May 2004 11:41:15 -0000 1.20 --- UnitsView.cpp 30 Jun 2004 18:49:30 -0000 1.21 *************** *** 25,28 **** --- 25,31 ---- #include "order/InformationCollector.h" #include "map/UnitHandler.h" + #include "unit/Unit.h" + #include "util/EventDispatcher.h" + #include "map/UnitHandler.h" #include <stdlib.h> *************** *** 36,39 **** --- 39,43 ---- worldv = w; + EventDispatcher::get()->registerListener(EventDispatcher::ENeedAFigure,this); // TODO: finish this code // TextureManager::get()->createTexture( *************** *** 57,60 **** --- 61,67 ---- // addFigure(); + + + } *************** *** 65,68 **** --- 72,76 ---- { // delete fig; + EventDispatcher::get()->unregisterListener(this); delete[] figures; delete[] figuresReal; *************** *** 237,239 **** --- 245,314 ---- } + void UnitsView::attachToWorld( ) + { + vector<EventUnitSpotted*> *unitVector; + std::vector<EventUnitSpotted *>::iterator it; + + // podpinanie sie do InformationCollectora + unitVector = worldv->getWorld()->getArmy(0)->getGeneralTeam()-> + getInformationCollector()->giveUnitsSpotted(); + + for (it = unitVector->begin(); it !=unitVector->end(); it++) { + (*it)->setFigure(createFigureFor(*it)); + } + + // podpinanie sie pod UnitHandlery + for(int army=0; army<=1; army++) { + for(int team=0; + team < worldv->getWorld()->getArmy(army)->getTeamsNum(); + team++) + { + std::vector<Unit*> vec = + worldv->getWorld()->getArmy(army)-> + getTeam(team)->getUnits(); + for(int unit=0; unit < vec.size(); unit++) { + vec[unit]->getHandler()->setFigure( + createFigureFor( vec[unit]->getHandler())); + } + + } + } + } + + Figure * UnitsView::createFigureFor( EventUnitSpotted * unitSpot ) + { + Figure *figure = Figure::createFigure( + unitSpot->unitType, + worldv, + 0, 0, unitSpot->isWilhelm); + figure->beRendered(true); + if (unitSpot->side != worldv->getWorld()->getArmy(0)) + figure->setSide(true); + return figure; + } + + + Figure * UnitsView::createFigureFor( UnitHandler * uhandler ) + { + Figure *figure = Figure::createFigure( + uhandler->getOwner()->getType(), + worldv, + 0, 0, uhandler->getOwner()->isWilhelm, false); + figure->beRendered(false); + if (uhandler->getOwner()->getArmy() != worldv->getWorld()->getArmy(0)) + figure->setSide(true); + return figure; + } + + + void UnitsView::eventNeedAFigure( EventUnitSpotted * eus ) + { + eus->setFigure(createFigureFor(eus)); + } + + void UnitsView::eventNeedAFigure( UnitHandler * uhandler ) + { + uhandler->setFigure(createFigureFor(uhandler)); + } + Index: UnitsView.h =================================================================== RCS file: /cvsroot/bastion/bastion/src/interface/world/UnitsView.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** UnitsView.h 29 May 2004 08:29:13 -0000 1.12 --- UnitsView.h 30 Jun 2004 18:49:30 -0000 1.13 *************** *** 14,21 **** --- 14,24 ---- #include "interface/world/Figure.h" + #include "util/EventListener.h" // Deklaracja klasy jest tu niezbedna z powodu cyklu w grafie zaleznosci klas. class WorldView; class Figure; + class EventUnitSpotted; + class UnitHandler; //template class std::Vector<>; *************** *** 30,36 **** */ ! class UnitsView{ public: UnitsView(WorldView *w); void render(); --- 33,41 ---- */ ! class UnitsView : public EventListener{ public: UnitsView(WorldView *w); + + void attachToWorld(); void render(); *************** *** 63,66 **** --- 68,74 ---- void setRealFiguresRender(bool doRender) { renderFiguresReal = doRender; } + + void eventNeedAFigure(EventUnitSpotted *eus); + void eventNeedAFigure(UnitHandler *uhandler); protected: *************** *** 87,90 **** --- 95,102 ---- } + Figure * createFigureFor(EventUnitSpotted * unit); + Figure * createFigureFor(UnitHandler * uh); + + private: Index: WorldView.cpp =================================================================== RCS file: /cvsroot/bastion/bastion/src/interface/world/WorldView.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** WorldView.cpp 28 Apr 2004 08:55:53 -0000 1.19 --- WorldView.cpp 30 Jun 2004 18:49:30 -0000 1.20 *************** *** 45,48 **** --- 45,49 ---- castleView = new CastleView(this); + unitsView->attachToWorld(); } |