Anpassungen für VS2010 nach dem 2. Testat

This commit is contained in:
Steffen Vogel 2011-11-06 12:46:23 +01:00
parent 1e8e9f4749
commit a24126cf99
10 changed files with 78 additions and 104 deletions

View file

@ -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 {

View file

@ -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 */

View file

@ -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 {

View file

@ -33,7 +33,7 @@ public:
}
private:
using LazyAktion<T>::p_ptLazyListe;
//using LazyAktion<T>::p_ptLazyListe;
T p_tObjekt;
};
@ -53,7 +53,7 @@ public:
}
private:
using LazyAktion<T>::p_ptLazyListe; // für gcc notwendig
//using LazyAktion<T>::p_ptLazyListe; // für gcc notwendig
T p_tObjekt;
};
@ -66,9 +66,7 @@ public:
LazyErase(const iterator &itObjekt, list<T> *eineListe) :
LazyAktion<T> (eineListe),
p_itObjekt(itObjekt)
{
cout << "reihe " << *itObjekt << " zur löschung ein" << endl;
}
{ }
virtual ~LazyErase() { }
@ -77,7 +75,7 @@ public:
}
private:
using LazyAktion<T>::p_ptLazyListe; // für gcc notwendig
//using LazyAktion<T>::p_ptLazyListe; // für gcc notwendig
iterator p_itObjekt; // bei erase Iterator speichern
};

View file

@ -71,12 +71,9 @@ public:
// ausstehende Aktionen durchfuehren
typename list<LazyAktion<T> *>::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<T> *pAktion = *it;
//pAktion->vAusfuehren();
(*it)->vAusfuehren();
LazyAktion<T> *pAktion = *it;
pAktion->vAusfuehren();
// Zeiger auf Action-Element löschen
delete *it;

View file

@ -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 <string>
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 <string>
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);

Binary file not shown.

View file

@ -25,20 +25,28 @@ Weg::~Weg()
void Weg::vAbfertigung() {
list<Fahrzeug *>::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);
}
}

View file

@ -5,6 +5,7 @@
#include <string>
#include "AktivesVO.h"
#include "LazyListe.h"
using namespace std;
@ -34,7 +35,7 @@ public:
private:
double p_dLaenge;
Begrenzung p_eLimit;
list<Fahrzeug *> p_pFahrzeuge;
LazyListe<Fahrzeug *> p_pFahrzeuge;
};
#endif /* WEG_H_ */

View file

@ -3,6 +3,8 @@
#include <iostream>
#include <stdlib.h>
#include <windows.h>
#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<int> tListe) {
void vListeAusgeben(LazyListe<int> &tListe) {
LazyListe<int>::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): ";