diff --git a/Aufgabenblock_2/Fahrzeug.cpp b/Aufgabenblock_2/Fahrzeug.cpp index 7e30020..975af7f 100644 --- a/Aufgabenblock_2/Fahrzeug.cpp +++ b/Aufgabenblock_2/Fahrzeug.cpp @@ -88,7 +88,8 @@ void Fahrzeug::vNeueStrecke(Weg *pWeg, double dStartZeit) { if (p_pVerhalten != NULL) { /* alter Weg vorhanden? */ delete p_pVerhalten; /* Speicherleck vermeiden! */ } - else if (dStartZeit > 0) { + + if (dStartZeit > 0) { p_pVerhalten = new FzgParken(pWeg, dStartZeit); } else { diff --git a/Aufgabenblock_2/FzgFahren.cpp b/Aufgabenblock_2/FzgFahren.cpp index f0c1528..3376d29 100644 --- a/Aufgabenblock_2/FzgFahren.cpp +++ b/Aufgabenblock_2/FzgFahren.cpp @@ -13,7 +13,7 @@ FzgFahren::~FzgFahren() double FzgFahren::dStrecke(Fahrzeug *pFz, double dDelta) { double dStrecke = pFz->dGeschwindigkeit() * dDelta; - if (pFz->getAbschnittStrecke() >= p_pWeg->getLaenge()) { /* bereits zuweit gefahren */ + if (pFz->getAbschnittStrecke() >= p_pWeg->getLaenge() - 1e-5) { /* bereits zuweit gefahren */ throw Streckenende(pFz, p_pWeg); } else if (pFz->getAbschnittStrecke() + dStrecke > p_pWeg->getLaenge()) { /* fahre nur bis zum Streckenende */ diff --git a/Aufgabenblock_2/FzgParken.cpp b/Aufgabenblock_2/FzgParken.cpp index 77dedb0..ed9594d 100644 --- a/Aufgabenblock_2/FzgParken.cpp +++ b/Aufgabenblock_2/FzgParken.cpp @@ -14,7 +14,7 @@ FzgParken::~FzgParken() { } double FzgParken::dStrecke(Fahrzeug *pFz, double dDelta) { - if (p_dStartZeit > dGlobaleZeit) { + if (p_dStartZeit >= dGlobaleZeit - 1e-5) { return 0.0; } else { diff --git a/Aufgabenblock_2/LazyAktion.h b/Aufgabenblock_2/LazyAktion.h index 0f6860b..1bf954f 100644 --- a/Aufgabenblock_2/LazyAktion.h +++ b/Aufgabenblock_2/LazyAktion.h @@ -33,7 +33,7 @@ public: } private: - using LazyAktion::p_ptLazyListe; + //using LazyAktion::p_ptLazyListe; T p_tObjekt; }; @@ -53,7 +53,7 @@ public: } private: - using LazyAktion::p_ptLazyListe; // für gcc notwendig + //using LazyAktion::p_ptLazyListe; // für gcc notwendig T p_tObjekt; }; @@ -66,9 +66,7 @@ public: LazyErase(const iterator &itObjekt, list *eineListe) : LazyAktion (eineListe), p_itObjekt(itObjekt) - { - cout << "reihe " << *itObjekt << " zur löschung ein" << endl; - } + { } virtual ~LazyErase() { } @@ -77,7 +75,7 @@ public: } private: - using LazyAktion::p_ptLazyListe; // für gcc notwendig + //using LazyAktion::p_ptLazyListe; // für gcc notwendig iterator p_itObjekt; // bei erase Iterator speichern }; diff --git a/Aufgabenblock_2/LazyListe.h b/Aufgabenblock_2/LazyListe.h index d6a73c9..90d974d 100644 --- a/Aufgabenblock_2/LazyListe.h +++ b/Aufgabenblock_2/LazyListe.h @@ -71,12 +71,9 @@ public: // ausstehende Aktionen durchfuehren typename list *>::const_iterator it; // TODO warum typename?! for (it = p_ListeAktionen.begin(); it != p_ListeAktionen.end(); it++) { - cout << "führe aktion aus, noch " << p_ListeAktionen.size() << endl; // Aktion ausführen - //LazyAktion *pAktion = *it; - //pAktion->vAusfuehren(); - - (*it)->vAusfuehren(); + LazyAktion *pAktion = *it; + pAktion->vAusfuehren(); // Zeiger auf Action-Element löschen delete *it; diff --git a/Aufgabenblock_2/SimuClient.h b/Aufgabenblock_2/SimuClient.h index cfeadd8..80133d0 100644 --- a/Aufgabenblock_2/SimuClient.h +++ b/Aufgabenblock_2/SimuClient.h @@ -1,74 +1,40 @@ -/* - * SimuClient für MacOS/Linux (Praktikum Informatik 2, WS 2009/10 RWTH Aachen) - * Version 0.5 - * von Robert Uhl, 2009 - 2010 - * Vielen Dank an den Lehrstuhl EECS, RWTH Aachen, für den Zugang zum Quellcode - * des SimuClient für Windows. - * Datei: SimuClient.h - * Inhalt: SimuClient sendet Daten an den (erweiterten) Java-Grafik-Server - */ - -#ifndef SIMUCLIENT_H -#define SIMUCLIENT_H - -#include -using namespace std; - -/** - * Grafik-Server initialisieren - * Standard: bStarteServer = true, sServer = "localhost", iPort = 7654 - */ -bool bInitialisiereGrafik(int sizeX, int sizeY, bool bStarteServer = true, const string& sServer = "localhost", const unsigned short iPort = 7654); - -/** - * Zeichnet eine Kreuzung - */ -bool bZeichneKreuzung(int posX, int posY); - -/** - * Straße zeichnen - */ -bool bZeichneStrasse(const string& way_to_name, const string& way_back_name, int length, int numPoints, int* points_xy); - -/** - * PKW zeichnen - */ -bool bZeichnePKW(const string& carname, const string& streetname, double rel_position, double speed, double tank); - -/** - * Zeichne Fahrrad - */ -bool bZeichneFahrrad(const string& bikename, const string& streetname, double relposition, double speed); - -/** - * Sendet die aktuelle Simulationszeit an den erweiterten SimuServer - */ -void vSetzeZeit(const double dTime); - -/** - * Ersetzt die Sleep()-Funktion von Windows, die mSek übernimmt - */ -void Sleep(const int mSec); - -/** - * Grafikserver beenden - */ -void vBeendeGrafik(void); - -/* - * Zusätzliche Schnittstellen wegen eventueller Konvertierungsprobleme bei string/char* - */ - -bool bZeichneStrasse(const char* way_to_name, const char* way_back_name, int length, int numPoints, int* points_xy); -bool bZeichneStrasse(const string& way_to_name, const char* way_back_name, int length, int numPoints, int* points_xy); -bool bZeichneStrasse(const char* way_to_name, const string& way_back_name, int length, int numPoints, int* points_xy); - -bool bZeichnePKW(const char* carname, const char* streetname, double rel_position, double speed, double tank); -bool bZeichnePKW(const string& carname, const char* streetname, double rel_position, double speed, double tank); -bool bZeichnePKW(const char* carname, const string& streetname, double rel_position, double speed, double tank); - -bool bZeichneFahrrad(const char* bikename, const char* streetname, double rel_position, double speed); -bool bZeichneFahrrad(const string& bikename, const char* streetname, double rel_position, double speed); -bool bZeichneFahrrad(const char* bikename, const string& streetname, double rel_position, double speed); - -#endif // SIMUCLIENT_H +#pragma once +#pragma warning (disable:4786) +#include +using namespace std; + +// Folgender ifdef-Block ist die Standardmethode zum Erstellen von Makros, die das Exportieren +// aus einer DLL vereinfachen. Alle Dateien in dieser DLL werden mit dem SIMUCLIENT_EXPORTS-Symbol +// kompiliert, das in der Befehlszeile definiert wurde. Das Symbol darf nicht für ein Projekt definiert werden, +// das diese DLL verwendet. Alle anderen Projekte, deren Quelldateien diese Datei beinhalten, erkennen +// SIMUCLIENT_API-Funktionen als aus einer DLL importiert, während die DLL +// mit diesem Makro definierte Symbole als exportiert ansieht. +#ifdef SIMUCLIENT_EXPORTS +#define SIMUCLIENT_API __declspec(dllexport) +#else +#define SIMUCLIENT_API __declspec(dllimport) +#endif + +// NUTZBARE FUNKTIONEN (offizielle Schnittstelle) +SIMUCLIENT_API bool bInitialisiereGrafik(int sizeX, int sizeY, char* address = "127.0.0.1"); +SIMUCLIENT_API bool bZeichneKreuzung(int posX, int posY); +SIMUCLIENT_API bool bZeichneStrasse(const string& way_to_name, const string& way_back_name, int length, int numPoints, int* points_xy); +SIMUCLIENT_API bool bZeichnePKW(const string& carname, const string& streetname, double rel_position, double speed, double tank); +SIMUCLIENT_API bool bZeichneFahrrad(const string& bikename, const string& streetname, double relposition, double speed); +SIMUCLIENT_API void vBeendeGrafik(); +SIMUCLIENT_API void vSetzeZeit(const double dTime); + +// Zusätzliche Schnittstellen (wegen Konvertierungsproblemen bei string/char*) + +SIMUCLIENT_API bool bZeichneStrasse(const char* way_to_name, const char* way_back_name, int length, int numPoints, int* points_xy); +SIMUCLIENT_API bool bZeichneStrasse(const string& way_to_name, const char* way_back_name, int length, int numPoints, int* points_xy); +SIMUCLIENT_API bool bZeichneStrasse(const char* way_to_name, const string& way_back_name, int length, int numPoints, int* points_xy); +SIMUCLIENT_API bool bZeichnePKW(const string& carname, const char* streetname, double rel_position, double speed, double tank); +SIMUCLIENT_API bool bZeichneFahrrad(const string& bikename, const char* streetname, double rel_position, double speed); +SIMUCLIENT_API bool bZeichnePKW(const char* carname, const char* streetname, double rel_position, double speed, double tank); +SIMUCLIENT_API bool bZeichneFahrrad(const char* bikename, const char* streetname, double rel_position, double speed); +SIMUCLIENT_API bool bZeichnePKW(const char* carname, const string& streetname, double rel_position, double speed, double tank); +SIMUCLIENT_API bool bZeichneFahrrad(const char* bikename, const string& streetname, double rel_position, double speed); + +// Wrapperfunktion fuer Sleep +SIMUCLIENT_API void vSleep(int mSec); \ No newline at end of file diff --git a/Aufgabenblock_2/SimuServer.jar b/Aufgabenblock_2/SimuServer.jar index 496145c..e8c7e93 100644 Binary files a/Aufgabenblock_2/SimuServer.jar and b/Aufgabenblock_2/SimuServer.jar differ diff --git a/Aufgabenblock_2/Weg.cpp b/Aufgabenblock_2/Weg.cpp index 4ad2eac..2eef6e7 100644 --- a/Aufgabenblock_2/Weg.cpp +++ b/Aufgabenblock_2/Weg.cpp @@ -25,20 +25,28 @@ Weg::~Weg() void Weg::vAbfertigung() { list::iterator it; + p_pFahrzeuge.vAktualisieren(); for (it = p_pFahrzeuge.begin(); it != p_pFahrzeuge.end(); it++) { - try { + try { (*it)->vAbfertigung(); } catch (FahrAusnahme &ausnahme) { ausnahme.vBearbeiten(); } } + p_pFahrzeuge.vAktualisieren(); p_dZeit = dGlobaleZeit; } void Weg::vAnnahme(Fahrzeug *pFz, double dStartZeit) { pFz->vNeueStrecke(this, dStartZeit); - p_pFahrzeuge.push_back(pFz); + + if (dStartZeit > 0) { /* parkende Fahrzeuge werden vorne eingefügt */ + p_pFahrzeuge.push_front(pFz); + } + else { /* fahrende hinten */ + p_pFahrzeuge.push_back(pFz); + } } void Weg::vAbgabe(Fahrzeug *pFz) { @@ -46,7 +54,7 @@ void Weg::vAbgabe(Fahrzeug *pFz) { result = find(p_pFahrzeuge.begin(), p_pFahrzeuge.end(), pFz); - if (result != p_pFahrzeuge.end()) { + if (result != p_pFahrzeuge.end()) { /* gefunden */ p_pFahrzeuge.erase(result); } } diff --git a/Aufgabenblock_2/Weg.h b/Aufgabenblock_2/Weg.h index 1a60da7..e44118c 100644 --- a/Aufgabenblock_2/Weg.h +++ b/Aufgabenblock_2/Weg.h @@ -5,6 +5,7 @@ #include #include "AktivesVO.h" +#include "LazyListe.h" using namespace std; @@ -34,7 +35,7 @@ public: private: double p_dLaenge; Begrenzung p_eLimit; - list p_pFahrzeuge; + LazyListe p_pFahrzeuge; }; #endif /* WEG_H_ */ diff --git a/Aufgabenblock_2/main.cpp b/Aufgabenblock_2/main.cpp index ec8508e..6c0f5e9 100644 --- a/Aufgabenblock_2/main.cpp +++ b/Aufgabenblock_2/main.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include "SimuClient.h" #include "Fahrzeug.h" #include "Fahrrad.h" @@ -12,7 +14,7 @@ using namespace std; -double dGlobaleZeit = 0.0; +double dGlobaleZeit; void vAufgabe1() { /* 3. Initialisieren */ @@ -155,14 +157,14 @@ void vAufgabe3() { void vAufgabe4() { Weg weg("Allee", 150.0, Weg::Landstrasse); - PKW vw("Golf", 110, 6.7, 88); + PKW vw("Golf", 55, 6.7, 88); Fahrrad velo("Haibike", 22); - weg.vAnnahme(&vw); - weg.vAnnahme(&velo, 1.1); + weg.vAnnahme(&vw, 1.2); + weg.vAnnahme(&velo); Fahrzeug::vAusgabeHeader(); - while (dGlobaleZeit < 10) { + while (dGlobaleZeit < 3) { dGlobaleZeit += 0.1; weg.vAbfertigung(); cout << vw << endl << velo << endl << weg << endl; @@ -173,10 +175,10 @@ void vAufgabe5() { Weg hin("Hinweg", 500.0, Weg::Landstrasse); Weg rueck("Rueckweg", 500.0, Weg::Landstrasse); - PKW vw("Golf", 110, 6.7, 88); + PKW vw("Golf", 55, 10, 20); Fahrrad velo("Haibike", 22); - bool bStarted = bInitialisiereGrafik(800, 600, true); + bool bStarted = bInitialisiereGrafik(800, 600); if (!bStarted) { cerr << "Konnte Simulationsserver nicht starten!" << endl; } @@ -184,11 +186,11 @@ void vAufgabe5() { int iKoordinaten[] = {100, 100, 700, 500 }; bZeichneStrasse(hin.getName(), rueck.getName(), hin.getLaenge(), 2, iKoordinaten); - hin.vAnnahme(&vw); - rueck.vAnnahme(&velo); + hin.vAnnahme(&vw, 1.2); + rueck.vAnnahme(&velo); Fahrzeug::vAusgabeHeader(); - while (dGlobaleZeit < 10) { + while (dGlobaleZeit < 15) { dGlobaleZeit += 0.3; hin.vAbfertigung(); rueck.vAbfertigung(); @@ -208,7 +210,7 @@ void vAufgabe5() { void vAufgabe6() { Weg weg("Allee", 300.0, Weg::Landstrasse); - PKW vw("Golf", 110, 6.7, 88); + PKW vw("Golf", 55, 6.7, 88); weg.vAnnahme(&vw); @@ -220,7 +222,7 @@ void vAufgabe6() { } } -void vListeAusgeben(LazyListe tListe) { +void vListeAusgeben(LazyListe &tListe) { LazyListe::iterator it; for (it = tListe.begin(); it != tListe.end(); it++) { cout << *it << ", "; @@ -310,6 +312,7 @@ int main() { goto retry; } + dGlobaleZeit = 0; /* resette globale Uhr */ pAufgaben[iWahl](); /* Funktionspointer aufrufen */ cout << endl << endl << "Nochmal? (0/1): ";