16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 18:39:18 +02:00

merge local branch 'mover_in_c++'

This commit is contained in:
tmj-fstate
2018-10-12 18:02:09 +02:00
368 changed files with 71983 additions and 93895 deletions

176
old/AdvSound.cpp Normal file
View File

@@ -0,0 +1,176 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "AdvSound.h"
#include "Timer.h"
//---------------------------------------------------------------------------
TAdvancedSound::~TAdvancedSound()
{ // Ra: stopowanie się sypie
// SoundStart.Stop();
// SoundCommencing.Stop();
// SoundShut.Stop();
}
void TAdvancedSound::Init( std::string const &NameOn, std::string const &Name, std::string const &NameOff, double DistanceAttenuation, Math3D::vector3 const &pPosition)
{
SoundStart.Init(NameOn, DistanceAttenuation, pPosition.x, pPosition.y, pPosition.z, true);
SoundCommencing.Init(Name, DistanceAttenuation, pPosition.x, pPosition.y, pPosition.z, true);
SoundShut.Init(NameOff, DistanceAttenuation, pPosition.x, pPosition.y, pPosition.z, true);
fStartLength = SoundStart.GetWaveTime();
fShutLength = SoundShut.GetWaveTime();
SoundStart.AM = 1.0;
SoundStart.AA = 0.0;
SoundStart.FM = 1.0;
SoundStart.FA = 0.0;
SoundCommencing.AM = 1.0;
SoundCommencing.AA = 0.0;
SoundCommencing.FM = 1.0;
SoundCommencing.FA = 0.0;
defAM = 1.0;
defFM = 1.0;
SoundShut.AM = 1.0;
SoundShut.AA = 0.0;
SoundShut.FM = 1.0;
SoundShut.FA = 0.0;
}
void TAdvancedSound::Load(cParser &Parser, Math3D::vector3 const &pPosition)
{
std::string nameon, name, nameoff;
double attenuation;
Parser.getTokens( 3, true, "\n\t ;," ); // samples separated with commas
Parser
>> nameon
>> name
>> nameoff;
Parser.getTokens( 1, false );
Parser
>> attenuation;
Init( nameon, name, nameoff, attenuation, pPosition );
}
void TAdvancedSound::TurnOn(bool ListenerInside, Math3D::vector3 NewPosition)
{
// hunter-311211: nie trzeba czekac na ponowne odtworzenie dzwieku, az sie wylaczy
if ((State == ss_Off || State == ss_ShuttingDown) && (SoundStart.AM > 0))
{
SoundStart.ResetPosition();
SoundCommencing.ResetPosition();
SoundStart.Play(1, 0, ListenerInside, NewPosition);
// SoundStart->SetVolume(-10000);
State = ss_Starting;
fTime = 0;
}
}
void TAdvancedSound::TurnOff(bool ListenerInside, Math3D::vector3 NewPosition)
{
if ((State == ss_Commencing || State == ss_Starting) && (SoundShut.AM > 0))
{
SoundStart.Stop();
SoundCommencing.Stop();
SoundShut.ResetPosition();
SoundShut.Play(1, 0, ListenerInside, NewPosition);
State = ss_ShuttingDown;
fTime = fShutLength;
// SoundShut->SetVolume(0);
}
}
void TAdvancedSound::Update(bool ListenerInside, Math3D::vector3 NewPosition)
{
if ((State == ss_Commencing) && (SoundCommencing.AM > 0))
{
// SoundCommencing->SetFrequency();
SoundShut.Stop(); // hunter-311211
SoundCommencing.Play(1, DSBPLAY_LOOPING, ListenerInside, NewPosition);
}
else if (State == ss_Starting)
{
fTime += Timer::GetDeltaTime();
// SoundStart->SetVolume(-1000*(4-fTime)/4);
if (fTime >= fStartLength)
{
State = ss_Commencing;
SoundCommencing.ResetPosition();
SoundCommencing.Play(1, DSBPLAY_LOOPING, ListenerInside, NewPosition);
SoundStart.Stop();
}
else
SoundStart.Play(1, 0, ListenerInside, NewPosition);
}
else if (State == ss_ShuttingDown)
{
fTime -= Timer::GetDeltaTime();
// SoundShut->SetVolume(-1000*(4-fTime)/4);
if (fTime <= 0)
{
State = ss_Off;
SoundShut.Stop();
}
else
SoundShut.Play(1, 0, ListenerInside, NewPosition);
}
}
void TAdvancedSound::UpdateAF(double A, double F, bool ListenerInside, Math3D::vector3 NewPosition)
{ // update, ale z amplituda i czestotliwoscia
if( State == ss_Off ) {
return;
}
if ((State == ss_Commencing) && (SoundCommencing.AM > 0))
{
SoundShut.Stop(); // hunter-311211
SoundCommencing.Play(A, DSBPLAY_LOOPING, ListenerInside, NewPosition);
}
else if (State == ss_Starting)
{
fTime += Timer::GetDeltaTime();
// SoundStart->SetVolume(-1000*(4-fTime)/4);
if (fTime >= fStartLength)
{
State = ss_Commencing;
SoundCommencing.ResetPosition();
SoundCommencing.Play(A, DSBPLAY_LOOPING, ListenerInside, NewPosition);
SoundStart.Stop();
}
else
SoundStart.Play(A, 0, ListenerInside, NewPosition);
}
else if (State == ss_ShuttingDown)
{
fTime -= Timer::GetDeltaTime();
// SoundShut->SetVolume(-1000*(4-fTime)/4);
if (fTime <= 0)
{
State = ss_Off;
SoundShut.Stop();
}
else
SoundShut.Play(A, 0, ListenerInside, NewPosition);
}
SoundCommencing.AdjFreq(F, Timer::GetDeltaTime());
}
void TAdvancedSound::CopyIfEmpty(TAdvancedSound &s)
{ // skopiowanie, gdyby był potrzebny, a nie został wczytany
if ((fStartLength > 0.0) || (fShutLength > 0.0))
return; // coś jest
SoundStart = s.SoundStart;
SoundCommencing = s.SoundCommencing;
SoundShut = s.SoundShut;
State = s.State;
fStartLength = s.fStartLength;
fShutLength = s.fShutLength;
defAM = s.defAM;
defFM = s.defFM;
};

49
old/AdvSound.h Normal file
View File

@@ -0,0 +1,49 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#ifndef AdvSoundH
#define AdvSoundH
#include "RealSound.h"
#include "parser.h"
enum TSoundState {
ss_Off,
ss_Starting,
ss_Commencing,
ss_ShuttingDown
};
class TAdvancedSound
{ // klasa dźwięków mających początek, dowolnie długi środek oraz zakończenie (np. Rp1)
TRealSound SoundStart;
TRealSound SoundCommencing;
TRealSound SoundShut;
TSoundState State = ss_Off;
double fTime = 0.0;
double fStartLength = 0.0;
double fShutLength = 0.0;
double defAM = 0.0;
double defFM = 0.0;
public:
TAdvancedSound() = default;
~TAdvancedSound();
void Init( std::string const &NameOn, std::string const &Name, std::string const &NameOff, double DistanceAttenuation, Math3D::vector3 const &pPosition);
void Load(cParser &Parser, Math3D::vector3 const &pPosition);
void TurnOn(bool ListenerInside, Math3D::vector3 NewPosition);
void TurnOff(bool ListenerInside, Math3D::vector3 NewPosition);
void Update(bool ListenerInside, Math3D::vector3 NewPosition);
void UpdateAF(double A, double F, bool ListenerInside, Math3D::vector3 NewPosition);
void CopyIfEmpty(TAdvancedSound &s);
};
//---------------------------------------------------------------------------
#endif

17
old/Classes.cpp Normal file
View File

@@ -0,0 +1,17 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include <vcl.h>
#pragma hdrstop
#include "Classes.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)

424
old/Data.h Normal file
View File

@@ -0,0 +1,424 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#ifndef DataH
#define DataH
//---------------------------------------------------------------------------
// Moduł z danymi
//---------------------------------------------------------------------------
struct TDist
{
int x, y;
};
const TDist SectorOrder[] = {
// tabela współrzędnych sektorów, posortowana wg odległości
{0, 0}, // 0.00
{1, 0}, // 1.00
{0, 1}, // 1.00
{1, 1}, // 1.41
{2, 0}, // 2.00
{0, 2}, // 2.00
{2, 1}, // 2.24
{1, 2}, // 2.24
{2, 2}, // 2.83 - 9 (566m)
{3, 0}, // 3.00
{0, 3}, // 3.00
{3, 1}, // 3.16
{1, 3}, // 3.16
{3, 2}, // 3.61
{2, 3}, // 3.61
{4, 0}, // 4.00 - 16 (800m)
{0, 4}, // 4.00
{4, 1}, // 4.12
{1, 4}, // 4.12
{3, 3}, // 4.24 - 20
{4, 2}, // 4.47
{2, 4}, // 4.47
{4, 3}, // 5.00
{3, 4}, // 5.00
{5, 0}, // 5.00 - 25
{0, 5}, // 5.00
{5, 1}, // 5.10
{1, 5}, // 5.10 - 28
{5, 2}, // 5.39
{2, 5}, // 5.39
{4, 4}, // 5.66
{5, 3}, // 5.83
{3, 5}, // 5.83
{6, 0}, // 6.00
{0, 6}, // 6.00
{6, 1}, // 6.08 - 36
{1, 6}, // 6.08
{6, 2}, // 6.32
{2, 6}, // 6.32
{5, 4}, // 6.40
{4, 5}, // 6.40
{6, 3}, // 6.71
{3, 6}, // 6.71
{7, 0}, // 7.00
{0, 7}, // 7.00
{5, 5}, // 7.07
{7, 1}, // 7.07
{1, 7}, // 7.07
{6, 4}, // 7.21
{4, 6}, // 7.21
{7, 2}, // 7.28
{2, 7}, // 7.28
{7, 3}, // 7.62
{3, 7}, // 7.62
{6, 5}, // 7.81
{5, 6}, // 7.81
{8, 0}, // 8.00
{0, 8}, // 8.00
{7, 4}, // 8.06
{4, 7}, // 8.06
{8, 1}, // 8.06
{1, 8}, // 8.06
{8, 2}, // 8.25
{2, 8}, // 8.25
{6, 6}, // 8.49
{8, 3}, // 8.54
{3, 8}, // 8.54
{7, 5}, // 8.60
{5, 7}, // 8.60
{8, 4}, // 8.94
{4, 8}, // 8.94
{9, 0}, // 9.00
{0, 9}, // 9.00
{9, 1}, // 9.06
{1, 9}, // 9.06
{7, 6}, // 9.22
{6, 7}, // 9.22
{9, 2}, // 9.22
{2, 9}, // 9.22
{8, 5}, // 9.43
{5, 8}, // 9.43
{9, 3}, // 9.49
{3, 9}, // 9.49
{9, 4}, // 9.85
{4, 9}, // 9.85
{7, 7}, // 9.90
{8, 6}, // 10.00
{6, 8}, // 10.00
{10, 0}, // 10.00
{0, 10}, // 10.00
{10, 1}, // 10.05
{1, 10}, // 10.05
{10, 2}, // 10.20
{2, 10}, // 10.20
{9, 5}, // 10.30
{5, 9}, // 10.30
{10, 3}, // 10.44
{3, 10}, // 10.44
{8, 7}, // 10.63
{7, 8}, // 10.63
{10, 4}, // 10.77
{4, 10}, // 10.77
{9, 6}, // 10.82
{6, 9}, // 10.82
{11, 0}, // 11.00
{0, 11}, // 11.00
{11, 1}, // 11.05
{1, 11}, // 11.05
{10, 5}, // 11.18
{5, 10}, // 11.18
{11, 2}, // 11.18
{2, 11}, // 11.18
{8, 8}, // 11.31
{9, 7}, // 11.40
{7, 9}, // 11.40
{11, 3}, // 11.40
{3, 11}, // 11.40
{10, 6}, // 11.66
{6, 10}, // 11.66
{11, 4}, // 11.70
{4, 11}, // 11.70
{12, 0}, // 12.00
{0, 12}, // 12.00
{9, 8}, // 12.04
{8, 9}, // 12.04
{12, 1}, // 12.04
{1, 12}, // 12.04
{11, 5}, // 12.08
{5, 11}, // 12.08
{12, 2}, // 12.17
{2, 12}, // 12.17
{10, 7}, // 12.21
{7, 10}, // 12.21
{12, 3}, // 12.37
{3, 12}, // 12.37
{11, 6}, // 12.53
{6, 11}, // 12.53
{12, 4}, // 12.65
{4, 12}, // 12.65
{9, 9}, // 12.73
{10, 8}, // 12.81
{8, 10}, // 12.81
{12, 5}, // 13.00
{5, 12}, // 13.00
{13, 0}, // 13.00
{0, 13}, // 13.00
{11, 7}, // 13.04
{7, 11}, // 13.04
{13, 1}, // 13.04
{1, 13}, // 13.04
{13, 2}, // 13.15
{2, 13}, // 13.15
{13, 3}, // 13.34
{3, 13}, // 13.34
{12, 6}, // 13.42
{6, 12}, // 13.42
{10, 9}, // 13.45
{9, 10}, // 13.45
{11, 8}, // 13.60
{8, 11}, // 13.60
{13, 4}, // 13.60
{4, 13}, // 13.60
{12, 7}, // 13.89
{7, 12}, // 13.89
{13, 5}, // 13.93
{5, 13}, // 13.93
{14, 0}, // 14.00
{0, 14}, // 14.00
{14, 1}, // 14.04
{1, 14}, // 14.04
{10, 10}, // 14.14
{14, 2}, // 14.14
{2, 14}, // 14.14
{11, 9}, // 14.21
{9, 11}, // 14.21
{13, 6}, // 14.32
{6, 13}, // 14.32
{14, 3}, // 14.32
{3, 14}, // 14.32
{12, 8}, // 14.42
{8, 12}, // 14.42
{14, 4}, // 14.56
{4, 14}, // 14.56
{13, 7}, // 14.76
{7, 13}, // 14.76
{11, 10}, // 14.87
{10, 11}, // 14.87
{14, 5}, // 14.87
{5, 14}, // 14.87
{12, 9}, // 15.00
{9, 12}, // 15.00
{15, 0}, // 15.00
{0, 15}, // 15.00
{15, 1}, // 15.03
{1, 15}, // 15.03
{15, 2}, // 15.13
{2, 15}, // 15.13
{14, 6}, // 15.23
{6, 14}, // 15.23
{13, 8}, // 15.26
{8, 13}, // 15.26
{15, 3}, // 15.30
{3, 15}, // 15.30
{15, 4}, // 15.52
{4, 15}, // 15.52
{11, 11}, // 15.56
{12, 10}, // 15.62
{10, 12}, // 15.62
{14, 7}, // 15.65
{7, 14}, // 15.65
{13, 9}, // 15.81
{9, 13}, // 15.81
{15, 5}, // 15.81
{5, 15}, // 15.81
{16, 0}, // 16.00
{0, 16}, // 16.00
{16, 1}, // 16.03
{1, 16}, // 16.03
{14, 8}, // 16.12
{8, 14}, // 16.12
{16, 2}, // 16.12
{2, 16}, // 16.12
{15, 6}, // 16.16
{6, 15}, // 16.16
{12, 11}, // 16.28
{11, 12}, // 16.28
{16, 3}, // 16.28
{3, 16}, // 16.28
{13, 10}, // 16.40
{10, 13}, // 16.40
{16, 4}, // 16.49
{4, 16}, // 16.49
{15, 7}, // 16.55
{7, 15}, // 16.55
{14, 9}, // 16.64
{9, 14}, // 16.64
{16, 5}, // 16.76
{5, 16}, // 16.76
{12, 12}, // 16.97
{15, 8}, // 17.00
{8, 15}, // 17.00
{17, 0}, // 17.00
{0, 17}, // 17.00
{13, 11}, // 17.03
{11, 13}, // 17.03
{17, 1}, // 17.03
{1, 17}, // 17.03
{16, 6}, // 17.09
{6, 16}, // 17.09
{17, 2}, // 17.12
{2, 17}, // 17.12
{14, 10}, // 17.20
{10, 14}, // 17.20
{17, 3}, // 17.26
{3, 17}, // 17.26
{16, 7}, // 17.46
{7, 16}, // 17.46
{17, 4}, // 17.46
{4, 17}, // 17.46
{15, 9}, // 17.49
{9, 15}, // 17.49
{13, 12}, // 17.69
{12, 13}, // 17.69
{17, 5}, // 17.72
{5, 17}, // 17.72
{14, 11}, // 17.80
{11, 14}, // 17.80
{16, 8}, // 17.89
{8, 16}, // 17.89
{18, 0}, // 18.00
{0, 18}, // 18.00
{15, 10}, // 18.03
{10, 15}, // 18.03
{17, 6}, // 18.03
{6, 17}, // 18.03
{18, 1}, // 18.03
{1, 18}, // 18.03
{18, 2}, // 18.11
{2, 18}, // 18.11
{18, 3}, // 18.25
{3, 18}, // 18.25
{16, 9}, // 18.36
{9, 16}, // 18.36
{13, 13}, // 18.38
{17, 7}, // 18.38
{7, 17}, // 18.38
{14, 12}, // 18.44
{12, 14}, // 18.44
{18, 4}, // 18.44
{4, 18}, // 18.44
{15, 11}, // 18.60
{11, 15}, // 18.60
{18, 5}, // 18.68
{5, 18}, // 18.68
{17, 8}, // 18.79
{8, 17}, // 18.79
{16, 10}, // 18.87
{10, 16}, // 18.87
{18, 6}, // 18.97
{6, 18}, // 18.97
{19, 0}, // 19.00
{0, 19}, // 19.00
{19, 1}, // 19.03
{1, 19}, // 19.03
{14, 13}, // 19.10
{13, 14}, // 19.10
{19, 2}, // 19.10
{2, 19}, // 19.10
{15, 12}, // 19.21
{12, 15}, // 19.21
{17, 9}, // 19.24
{9, 17}, // 19.24
{19, 3}, // 19.24
{3, 19}, // 19.24
{18, 7}, // 19.31
{7, 18}, // 19.31
{16, 11}, // 19.42
{11, 16}, // 19.42
{19, 4}, // 19.42
{4, 19}, // 19.42
{19, 5}, // 19.65
{5, 19}, // 19.65
{18, 8}, // 19.70
{8, 18}, // 19.70
{17, 10}, // 19.72
{10, 17}, // 19.72
{14, 14}, // 19.80
{15, 13}, // 19.85
{13, 15}, // 19.85
{19, 6}, // 19.92
{6, 19}, // 19.92
{16, 12}, // 20.00
{12, 16}, // 20.00
{18, 9}, // 20.12
{9, 18}, // 20.12
{17, 11}, // 20.25
{11, 17}, // 20.25
{19, 7}, // 20.25
{7, 19}, // 20.25
{15, 14}, // 20.52
{14, 15}, // 20.52
{18, 10}, // 20.59
{10, 18}, // 20.59
{16, 13}, // 20.62
{13, 16}, // 20.62
{19, 8}, // 20.62
{8, 19}, // 20.62
{17, 12}, // 20.81
{12, 17}, // 20.81
{19, 9}, // 21.02
{9, 19}, // 21.02
{18, 11}, // 21.10
{11, 18}, // 21.10
{15, 15}, // 21.21
{16, 14}, // 21.26
{14, 16}, // 21.26
{17, 13}, // 21.40
{13, 17}, // 21.40
{19, 10}, // 21.47
{10, 19}, // 21.47
{18, 12}, // 21.63
{12, 18}, // 21.63
{16, 15}, // 21.93
{15, 16}, // 21.93
{19, 11}, // 21.95
{11, 19}, // 21.95
{17, 14}, // 22.02
{14, 17}, // 22.02
{18, 13}, // 22.20
{13, 18}, // 22.20
{19, 12}, // 22.47
{12, 19}, // 22.47
{16, 16}, // 22.63
{17, 15}, // 22.67
{15, 17}, // 22.67
{18, 14}, // 22.80
{14, 18}, // 22.80
{19, 13}, // 23.02
{13, 19}, // 23.02
{17, 16}, // 23.35
{16, 17}, // 23.35
{18, 15}, // 23.43
{15, 18}, // 23.43
{19, 14}, // 23.60
{14, 19}, // 23.60
{17, 17}, // 24.04
{18, 16}, // 24.08
{16, 18}, // 24.08
{19, 15}, // 24.21
{15, 19}, // 24.21
{18, 17}, // 24.76
{17, 18}, // 24.76
{19, 16}, // 24.84
{16, 19}, // 24.84
{18, 18}, // 25.46
{19, 17}, // 25.50
{17, 19}, // 25.50
{19, 18}, // 26.17
{18, 19}, // 26.17
{19, 19} // 26.87 - 400 (5374m)
};
#endif

92
old/FadeSound.cpp Normal file
View File

@@ -0,0 +1,92 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
/*
MaSzyna EU07 locomotive simulator
Copyright (C) 2001-2004 Marcin Wozniak and others
*/
#include "stdafx.h"
#include "FadeSound.h"
#include "Timer.h"
TFadeSound::~TFadeSound()
{
Free();
}
void TFadeSound::Free()
{
}
void TFadeSound::Init(std::string const &Name, float fNewFade)
{
Sound = TSoundsManager::GetFromName(Name, false);
if (Sound)
Sound->SetVolume(0);
fFade = fNewFade;
fTime = 0;
}
void TFadeSound::TurnOn()
{
State = ss_Starting;
Sound->Play(0, 0, DSBPLAY_LOOPING);
fTime = fFade;
}
void TFadeSound::TurnOff()
{
State = ss_ShuttingDown;
}
void TFadeSound::Update()
{
if (State == ss_Starting)
{
fTime += Timer::GetDeltaTime();
// SoundStart->SetVolume(-1000*(4-fTime)/4);
if (fTime >= fFade)
{
fTime = fFade;
State = ss_Commencing;
Sound->SetVolume(-2000 * (fFade - fTime) / fFade);
Sound->SetFrequency(44100 - 500 + 500 * (fTime) / fFade);
}
else if (Timer::GetSoundTimer())
{
Sound->SetVolume(-2000 * (fFade - fTime) / fFade);
Sound->SetFrequency(44100 - 500 + 500 * (fTime) / fFade);
}
}
else if (State == ss_ShuttingDown)
{
fTime -= Timer::GetDeltaTime();
if (fTime <= 0)
{
State = ss_Off;
fTime = 0;
Sound->Stop();
}
if (Timer::GetSoundTimer())
{ // DSBVOLUME_MIN
Sound->SetVolume(-2000 * (fFade - fTime) / fFade);
Sound->SetFrequency(44100 - 500 + 500 * fTime / fFade);
}
}
}
void TFadeSound::Volume(long vol)
{
float glos = 1;
Sound->SetVolume(vol * glos);
}
//---------------------------------------------------------------------------

40
old/FadeSound.h Normal file
View File

@@ -0,0 +1,40 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#ifndef FadeSoundH
#define FadeSoundH
#include "Sound.h"
#include "AdvSound.h"
class TFadeSound
{
PSound Sound = nullptr;
float fFade = 0.0f;
float dt = 0.0f,
fTime = 0.0f;
TSoundState State = ss_Off;
public:
TFadeSound() = default;
~TFadeSound();
void Init(std::string const &Name, float fNewFade);
void TurnOn();
void TurnOff();
bool Playing()
{
return (State == ss_Commencing || State == ss_Starting);
};
void Free();
void Update();
void Volume(long vol);
};
//---------------------------------------------------------------------------
#endif

52
old/Forth.cpp Normal file
View File

@@ -0,0 +1,52 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include <vcl.h>
#pragma hdrstop
#include "Forth.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
/* Ra: Forth jest prostym językiem programowania, funkcjonującym na dosyć
niskim poziomie. Może być zarówno interpretowany jak i kompilowany, co
pozwala szybko działać skompilowanym programom, jak również wykonywać
polecenia wprowadzane z klawiatury. Za pomocą zdefiniowanych kompilatorów
można definiować nowe funkcje, można również tworzyć nowe struktury jezyka,
np. wykraczające poza dotychczasową składnię. Prostota i wydajność są okupione
nieco specyficzną składnią, wynikającą z użycia stosu do obliczeń (tzw. odwrotna
notacja polska).
Forth ma być używany jako:
1. Alternatywna postać eventów. Dotychczasowe eventy w sceneriach mogą być
traktowane jako funkcje języka Forth. Jednocześnie można uzyskać uelastycznienie
składni, poprzez np. połączenie w jednym wpisie różnych typów eventów wraz z
dodaniem warunków dostępnych tylko dla Multiple. Również można będzie używać
wyrażeń języka Forth, czyli dokonywać obliczeń.
2. Jako docelowa postać schematów obwodów Ladder Diagram. Można zrobić tak, by
program źródłowy w Forth (przy pewnych ograniczeniach) był wyświetlany graficznie
jako Ladder Diagram. Jednocześnie graficzne modyfikacje schematu można by
przełożyć na postać tekstową Forth i skompilować na kod niskiego poziomu.
3. Jako algorytm funkcjonowania AI, możliwy do zaprogramowania na zewnątzr EXE.
Każdy użytkownik będzie mógł swój własny styl jazdy.
4. Jako algorytm sterowania ruchem (zależności na stacji).
5. Jako AI stacji, zarządzające ruchem na stacji zależnie w czasie rzeczywistym.
Względem pierwotnego języka Forth, użyty tutaj będzie miał pewne odstępstwa:
1. Operacje na liczbach czterobajtowych float. Należy we własnym zakresie dbać
o zgodność użytych funkcji z typem argumentu na stosie.
2. Jedynym typem całkowitym jest czterobajtowy int.
3. Do wyszukiwania obiektów w scenerii po nazwie (torów, eventów), używane jest
drzewo zamiast listy.
Wpisy w scenerii, przetwarzane jako komendy Forth, nie mogą używać średnika jako
separatora słów. Uniemożliwia to używanie średnika jako słowa.
*/

17
old/Forth.h Normal file
View File

@@ -0,0 +1,17 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#ifndef ForthH
#define ForthH
//---------------------------------------------------------------------------
class Forth
{ // klasa obsługi języka
};
#endif

127
old/Geom.cpp Normal file
View File

@@ -0,0 +1,127 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "system.hpp"
#include "classes.hpp"
#include <gl/gl.h>
#include <gl/glu.h>
#include "GL/glut.h"
#pragma hdrstop
#include "Texture.h"
#include "usefull.h"
#include "Globals.h"
#include "Geom.h"
TGeometry::TGeometry()
{
}
TGeometry::~TGeometry()
{
}
bool TGeometry::Init()
{
}
vector3 TGeometry::Load(TQueryParserComp *Parser)
{
str = Parser->GetNextSymbol().LowerCase();
tmp->TextureID = TTexturesManager::GetTextureID(str.c_str());
i = 0;
do
{
tf = Parser->GetNextSymbol().ToDouble();
TempVerts[i].Point.x = tf;
tf = Parser->GetNextSymbol().ToDouble();
TempVerts[i].Point.y = tf;
tf = Parser->GetNextSymbol().ToDouble();
TempVerts[i].Point.z = tf;
tf = Parser->GetNextSymbol().ToDouble();
TempVerts[i].Normal.x = tf;
tf = Parser->GetNextSymbol().ToDouble();
TempVerts[i].Normal.y = tf;
tf = Parser->GetNextSymbol().ToDouble();
TempVerts[i].Normal.z = tf;
str = Parser->GetNextSymbol().LowerCase();
if (str == "x")
TempVerts[i].tu = (TempVerts[i].Point.x + Parser->GetNextSymbol().ToDouble()) /
Parser->GetNextSymbol().ToDouble();
else if (str == "y")
TempVerts[i].tu = (TempVerts[i].Point.y + Parser->GetNextSymbol().ToDouble()) /
Parser->GetNextSymbol().ToDouble();
else if (str == "z")
TempVerts[i].tu = (TempVerts[i].Point.z + Parser->GetNextSymbol().ToDouble()) /
Parser->GetNextSymbol().ToDouble();
else
TempVerts[i].tu = str.ToDouble();
;
str = Parser->GetNextSymbol().LowerCase();
if (str == "x")
TempVerts[i].tv = (TempVerts[i].Point.x + Parser->GetNextSymbol().ToDouble()) /
Parser->GetNextSymbol().ToDouble();
else if (str == "y")
TempVerts[i].tv = (TempVerts[i].Point.y + Parser->GetNextSymbol().ToDouble()) /
Parser->GetNextSymbol().ToDouble();
else if (str == "z")
TempVerts[i].tv = (TempVerts[i].Point.z + Parser->GetNextSymbol().ToDouble()) /
Parser->GetNextSymbol().ToDouble();
else
TempVerts[i].tv = str.ToDouble();
;
// tf= Parser->GetNextSymbol().ToDouble();
// TempVerts[i].tu= tf;
// tf= Parser->GetNextSymbol().ToDouble();
// TempVerts[i].tv= tf;
TempVerts[i].Point.RotateZ(aRotate.z / 180 * M_PI);
TempVerts[i].Point.RotateX(aRotate.x / 180 * M_PI);
TempVerts[i].Point.RotateY(aRotate.y / 180 * M_PI);
TempVerts[i].Normal.RotateZ(aRotate.z / 180 * M_PI);
TempVerts[i].Normal.RotateX(aRotate.x / 180 * M_PI);
TempVerts[i].Normal.RotateY(aRotate.y / 180 * M_PI);
TempVerts[i].Point += pOrigin;
tmp->pCenter += TempVerts[i].Point;
i++;
// }
} while (Parser->GetNextSymbol().LowerCase() != "endtri");
nv = i;
tmp->Init(nv);
tmp->pCenter /= (nv > 0 ? nv : 1);
// memcpy(tmp->Vertices,TempVerts,nv*sizeof(TGroundVertex));
r = 0;
for (int i = 0; i < nv; i++)
{
tmp->Vertices[i] = TempVerts[i];
tf = SquareMagnitude(tmp->Vertices[i].Point - tmp->pCenter);
if (tf > r)
r = tf;
}
// tmp->fSquareRadius= 2000*2000+r;
tmp->fSquareRadius += r;
}
bool TGeometry::Render()
{
}
//---------------------------------------------------------------------------
#pragma package(smart_init)

46
old/Geom.h Normal file
View File

@@ -0,0 +1,46 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#ifndef GeomH
#define GeomH
#include <gl/gl.h>
#include "QueryParserComp.hpp"
struct TGeomVertex
{
vector3 Point;
vector3 Normal;
double tu, tv;
};
class TGeometry
{
private:
GLuint iType;
union
{
int iNumVerts;
int iNumPts;
};
GLuint TextureID;
TMaterialColor Ambient;
TMaterialColor Diffuse;
TMaterialColor Specular;
public:
TGeometry();
~TGeometry();
bool Init();
vector3 Load(TQueryParserComp *Parser);
bool Render();
};
//---------------------------------------------------------------------------
#endif

4015
old/Ground.cpp Normal file

File diff suppressed because it is too large Load Diff

315
old/Ground.h Normal file
View File

@@ -0,0 +1,315 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <string>
#include "Classes.h"
#include "material.h"
#include "dumb3d.h"
#include "Names.h"
#include "lightarray.h"
#include "simulation.h"
typedef int TGroundNodeType;
// Ra: zmniejszone liczby, aby zrobić tabelkę i zoptymalizować wyszukiwanie
const int TP_MODEL = 10;
/*
const int TP_MESH = 11; // Ra: specjalny obiekt grupujący siatki dla tekstury
const int TP_DUMMYTRACK = 12; // Ra: zdublowanie obiektu toru dla rozdzielenia tekstur
*/
const int TP_TERRAIN = 13; // Ra: specjalny model dla terenu
const int TP_DYNAMIC = 14;
const int TP_SOUND = 15;
const int TP_TRACK = 16;
/*
const int TP_GEOMETRY=17;
*/
const int TP_MEMCELL = 18;
const int TP_EVLAUNCH = 19; // MC
const int TP_TRACTION = 20;
const int TP_TRACTIONPOWERSOURCE = 21; // MC
/*
const int TP_ISOLATED=22; //Ra
*/
const int TP_SUBMODEL = 22; // Ra: submodele terenu
const int TP_LAST = 25; // rozmiar tablicy
struct TGroundVertex
{
glm::dvec3 position;
glm::vec3 normal;
glm::vec2 texture;
void HalfSet(const TGroundVertex &v1, const TGroundVertex &v2)
{ // wyliczenie współrzędnych i mapowania punktu na środku odcinka v1<->v2
interpolate_( v1, v2, 0.5 );
}
void SetByX(const TGroundVertex &v1, const TGroundVertex &v2, double x)
{ // wyliczenie współrzędnych i mapowania punktu na odcinku v1<->v2
interpolate_( v1, v2, ( x - v1.position.x ) / ( v2.position.x - v1.position.x ) );
}
void SetByZ(const TGroundVertex &v1, const TGroundVertex &v2, double z)
{ // wyliczenie współrzędnych i mapowania punktu na odcinku v1<->v2
interpolate_( v1, v2, ( z - v1.position.z ) / ( v2.position.z - v1.position.z ) );
}
void interpolate_( const TGroundVertex &v1, const TGroundVertex &v2, double factor ) {
position = interpolate( v1.position, v2.position, factor );
normal = interpolate( v1.normal, v2.normal, static_cast<float>( factor ) );
texture = interpolate( v1.texture, v2.texture, static_cast<float>( factor ) );
}
};
// ground node holding single, unique piece of 3d geometry. TBD, TODO: unify this with basic 3d model node
struct piece_node {
std::vector<TGroundVertex> vertices;
geometry_handle geometry { 0, 0 }; // geometry prepared for drawing
};
// obiekt scenerii
class TGroundNode {
friend class opengl_renderer;
public:
TGroundNode *nNext; // lista wszystkich w scenerii, ostatni na początku
TGroundNode *nNext2; // lista obiektów w sektorze
TGroundNode *nNext3; // lista obiektów renderowanych we wspólnym cyklu
std::string asName; // nazwa (nie zawsze ma znaczenie)
TGroundNodeType iType; // typ obiektu
union
{ // Ra: wskażniki zależne od typu - zrobić klasy dziedziczone zamiast
void *Pointer; // do przypisywania NULL
TSubModel *smTerrain; // modele terenu (kwadratow kilometrowych)
TAnimModel *Model; // model z animacjami
TDynamicObject *DynamicObject; // pojazd
piece_node *Piece; // non-instanced piece of geometry
TTrack *pTrack; // trajektoria ruchu
TMemCell *MemCell; // komórka pamięci
TEventLauncher *EvLaunch; // wyzwalacz zdarzeń
TTraction *hvTraction; // drut zasilający
TTractionPowerSource *psTractionPowerSource; // zasilanie drutu (zaniedbane w sceneriach)
TTextSound *tsStaticSound; // dźwięk przestrzenny
TGroundNode *nNode; // obiekt renderujący grupowo ma tu wskaźnik na listę obiektów
};
Math3D::vector3 pCenter; // współrzędne środka do przydzielenia sektora
float m_radius { 0.0f }; // bounding radius of geometry stored in the node. TODO: reuse bounding_area struct for radius and center
glm::dvec3 m_rootposition; // position of the ground (sub)rectangle holding the node, in the 3d world
// visualization-related data
// TODO: wrap these in a struct, when cleaning objects up
double fSquareMinRadius; // kwadrat widoczności od
double fSquareRadius; // kwadrat widoczności do
union
{
int iNumVerts; // dla trójkątów
int iNumPts; // dla linii
int iCount; // dla terenu
};
int iFlags; // tryb przezroczystości: 0x10-nieprz.,0x20-przezroczysty,0x30-mieszany
material_handle m_material; // główna (jedna) tekstura obiektu
glm::vec3
Ambient{ 0.2f },
Diffuse{ 1.0f },
Specular{ 0.0f }; // oświetlenie
double fLineThickness; // McZapkie-120702: grubosc linii
bool bVisible;
TGroundNode();
TGroundNode(TGroundNodeType t);
~TGroundNode();
void InitNormals();
void RenderHidden(); // obsługa dźwięków i wyzwalaczy zdarzeń
};
class TSubRect : public CMesh
{ // sektor składowy kwadratu kilometrowego
public:
scene::bounding_area m_area;
unsigned int m_framestamp { 0 }; // id of last rendered gfx frame
int iTracks = 0; // ilość torów w (tTracks)
TTrack **tTracks = nullptr; // tory do renderowania pojazdów
protected:
TTrack *tTrackAnim = nullptr; // obiekty do przeliczenia animacji
public:
TGroundNode *nRootNode = nullptr; // wszystkie obiekty w sektorze, z wyjątkiem renderujących i pojazdów (nNext2)
TGroundNode *nRenderHidden = nullptr; // lista obiektów niewidocznych, "renderowanych" również z tyłu (nNext3)
TGroundNode *nRenderRect = nullptr; // z poziomu sektora - nieprzezroczyste (nNext3)
TGroundNode *nRenderRectAlpha = nullptr; // z poziomu sektora - przezroczyste (nNext3)
TGroundNode *nRenderWires = nullptr; // z poziomu sektora - druty i inne linie (nNext3)
TGroundNode *nRender = nullptr; // indywidualnie - nieprzezroczyste (nNext3)
TGroundNode *nRenderMixed = nullptr; // indywidualnie - nieprzezroczyste i przezroczyste (nNext3)
TGroundNode *nRenderAlpha = nullptr; // indywidualnie - przezroczyste (nNext3)
#ifdef EU07_SCENERY_EDITOR
std::deque< TGroundNode* > m_memcells; // collection of memcells present in the sector
#endif
int iNodeCount = 0; // licznik obiektów, do pomijania pustych sektorów
public:
void LoadNodes(); // utworzenie VBO sektora
public:
virtual ~TSubRect();
virtual void NodeAdd(TGroundNode *Node); // dodanie obiektu do sektora na etapie rozdzielania na sektory
void Sort(); // optymalizacja obiektów w sektorze (sortowanie wg tekstur)
TTrack * FindTrack(vector3 *Point, int &iConnection, TTrack *Exclude);
TTraction * FindTraction(glm::dvec3 const &Point, int &iConnection, TTraction *Exclude);
#ifdef EU07_USE_OLD_GROUNDCODE
bool RaTrackAnimAdd(TTrack *t); // zgłoszenie toru do animacji
void RaAnimate( unsigned int const Framestamp ); // przeliczenie animacji torów
void RenderSounds(); // dźwięki pojazdów z niewidocznych sektorów
#endif
};
// Ra: trzeba sprawdzić wydajność siatki
const int iNumSubRects = 5; // na ile dzielimy kilometr
const int iNumRects = 500;
const int iTotalNumSubRects = iNumRects * iNumSubRects;
const double fHalfTotalNumSubRects = iTotalNumSubRects / 2.0;
const double fSubRectSize = 1000.0 / iNumSubRects;
const double fRectSize = fSubRectSize * iNumSubRects;
class TGroundRect : public TSubRect
{ // kwadrat kilometrowy
// obiekty o niewielkiej ilości wierzchołków będą renderowane stąd
// Ra: 2012-02 doszły submodele terenu
friend class opengl_renderer;
private:
TSubRect *pSubRects { nullptr };
void Init();
public:
virtual ~TGroundRect();
// pobranie wskaźnika do małego kwadratu, utworzenie jeśli trzeba
inline
TSubRect * SafeGetSubRect(int iCol, int iRow) {
if( !pSubRects ) {
// utworzenie małych kwadratów
Init();
}
return pSubRects + iRow * iNumSubRects + iCol; // zwrócenie właściwego
};
// pobranie wskaźnika do małego kwadratu, bez tworzenia jeśli nie ma
inline
TSubRect *FastGetSubRect(int iCol, int iRow) const {
return (
pSubRects ?
pSubRects + iRow * iNumSubRects + iCol :
nullptr); };
void NodeAdd( TGroundNode *Node ); // dodanie obiektu do sektora na etapie rozdzielania na sektory
// compares two provided nodes, returns true if their content can be merged
bool mergeable( TGroundNode const &Left, TGroundNode const &Right ) const;
// optymalizacja obiektów w sektorach
inline
void Optimize() {
if( pSubRects ) {
for( int i = iNumSubRects * iNumSubRects - 1; i >= 0; --i ) {
// optymalizacja obiektów w sektorach
pSubRects[ i ].Sort(); } } };
TGroundNode *nTerrain { nullptr }; // model terenu z E3D - użyć nRootMesh?
};
class TGround
{
friend class opengl_renderer;
TGroundRect Rects[ iNumRects ][ iNumRects ]; // mapa kwadratów kilometrowych
TSubRect srGlobal; // zawiera obiekty globalne (na razie wyzwalacze czasowe)
TGroundNode *nRootDynamic = nullptr; // lista pojazdów
TGroundNode *nRootOfType[ TP_LAST ]; // tablica grupująca obiekty, przyspiesza szukanie
#ifdef EU07_USE_OLD_GROUNDCODE
TEvent *RootEvent = nullptr; // lista zdarzeń
TEvent *QueryRootEvent = nullptr,
*tmpEvent = nullptr;
typedef std::unordered_map<std::string, TEvent *> event_map;
event_map m_eventmap;
TNames<TGroundNode *> m_nodemap;
#endif
vector3 pOrigin;
vector3 aRotate;
bool bInitDone = false;
private: // metody prywatne
#ifdef EU07_USE_OLD_GROUNDCODE
bool EventConditon(TEvent *e);
#endif
public:
TGround();
~TGround();
void Free();
#ifdef EU07_USE_OLD_GROUNDCODE
bool Init( std::string File );
void FirstInit();
void InitTracks();
void InitTraction();
bool InitEvents();
bool InitLaunchers();
TTrack * FindTrack(vector3 Point, int &iConnection, TGroundNode *Exclude);
TTraction * FindTraction(glm::dvec3 const &Point, int &iConnection, TGroundNode *Exclude);
TTraction * TractionNearestFind(glm::dvec3 &p, int dir, TGroundNode *n);
#endif
TGroundNode * AddGroundNode(cParser *parser);
#ifdef EU07_USE_OLD_GROUNDCODE
void UpdatePhys(double dt, int iter); // aktualizacja fizyki stałym krokiem
bool Update(double dt, int iter); // aktualizacja przesunięć zgodna z FPS
void Update_Hidden(); // updates invisible elements of the scene
bool GetTraction(TDynamicObject *model);
bool AddToQuery( TEvent *Event, TDynamicObject *Node );
bool CheckQuery();
TGroundNode * DynamicFindAny(std::string const &Name);
TGroundNode * DynamicFind(std::string const &Name);
TGroundNode * FindGroundNode(std::string const &asNameToFind, TGroundNodeType const iNodeType);
#endif
TGroundRect * GetRect( double x, double z );
TSubRect * GetSubRect( int iCol, int iRow );
inline
TSubRect * GetSubRect(double x, double z) {
return GetSubRect(GetColFromX(x), GetRowFromZ(z)); };
TSubRect * FastGetSubRect( int iCol, int iRow );
inline
TSubRect * FastGetSubRect( double x, double z ) {
return FastGetSubRect( GetColFromX( x ), GetRowFromZ( z ) ); };
inline
int GetRowFromZ(double z) {
return (int)(z / fSubRectSize + fHalfTotalNumSubRects); };
inline
int GetColFromX(double x) {
return (int)(x / fSubRectSize + fHalfTotalNumSubRects); };
#ifdef EU07_USE_OLD_GROUNDCODE
TEvent * FindEvent(const std::string &asEventName);
void TrackJoin(TGroundNode *Current);
private:
// convert tp_terrain model to a series of triangle nodes
void convert_terrain( TGroundNode const *Terrain );
void convert_terrain( TSubModel const *Submodel );
void RaTriangleDivider(TGroundNode *node);
#endif
public:
#ifdef EU07_USE_OLD_GROUNDCODE
void DynamicList( bool all = false );
void TrackBusyList();
void IsolatedBusyList();
void IsolatedBusy( const std::string t );
void RadioStop(vector3 pPosition);
TDynamicObject * DynamicNearest(vector3 pPosition, double distance = 20.0, bool mech = false);
TDynamicObject * CouplerNearest(vector3 pPosition, double distance = 20.0, bool mech = false);
#endif
void DynamicRemove(TDynamicObject *dyn);
void TerrainRead(std::string const &f);
void TerrainWrite();
#ifdef EU07_USE_OLD_GROUNDCODE
void Silence(vector3 gdzie);
#endif
};
//---------------------------------------------------------------------------

763
old/MWD.cpp Normal file
View File

@@ -0,0 +1,763 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
/*
Program obsługi portu COM i innych na potrzeby sterownika MWDevice
(oraz innych wykorzystujących komunikację przez port COM)
dla Symulatora Pojazdów Szynowych MaSzyna
author: Maciej Witek 2016
Autor nie ponosi odpowiedzialności za niewłaciwe używanie lub działanie programu!
*/
#include "stdafx.h"
#include "MWD.h"
#include "Globals.h"
#include "Logs.h"
#include "World.h"
#include <windows.h>
HANDLE hComm;
TMWDComm::TMWDComm() // konstruktor
{
MWDTime = 0;
bSHPstate = false;
bPrzejazdSHP = false;
bKabina1 = true; // pasuje wyciągnąć dane na temat kabiny
bKabina2 = false; // i ustawiać te dwa parametry!
bHamowanie = false;
bCzuwak = false;
bRysik1H = false;
bRysik1L = false;
bRysik2H = false;
bRysik2L = false;
bocznik = 0;
nastawnik = 0;
kierunek = 0;
bnkMask = 0;
int i = 6;
while (i)
{
i--;
lastStateData[i] = 0;
maskData[i] = 0;
maskSwitch[i] = 0;
bitSwitch[i] = 0;
}
i = 0;
while (i<BYTETOWRITE)
{
if (i<BYTETOREAD)ReadDataBuff[i] = 0;
WriteDataBuff[i] = 0;
i++;
}
i = 0;
while (i<6)
{
lastStateData[i] = 0;
maskSwitch[i] = 0;
bitSwitch[i] = 0;
i++;
}
}
TMWDComm::~TMWDComm() // destruktor
{
Close();
}
bool TMWDComm::Open() // otwieranie portu COM
{
LPCSTR portId = Global.sMWDPortId.c_str();
hComm = CreateFile(portId, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hComm == INVALID_HANDLE_VALUE)
{
if (GetLastError() == ERROR_FILE_NOT_FOUND)
{
WriteLog("PortCOM ERROR: serial port does not exist"); // serial port does not exist.
// Inform user.
}
WriteLog("PortCOM ERROR! not open!");
// some other error occurred. Inform user.
return FALSE;
}
DCB CommDCB;
CommDCB.DCBlength = sizeof(DCB);
GetCommState(hComm, &CommDCB);
CommDCB.BaudRate = Global.iMWDBaudrate;
CommDCB.fBinary = TRUE;
CommDCB.fParity = FALSE;
CommDCB.fOutxCtsFlow = FALSE; // No CTS output flow control
CommDCB.fOutxDsrFlow = FALSE; // No DSR output flow control
CommDCB.fDtrControl = FALSE; // DTR flow control type
CommDCB.fDsrSensitivity = FALSE; // DSR sensitivity
CommDCB.fTXContinueOnXoff = FALSE; // XOFF continues Tx
CommDCB.fOutX = FALSE; // No XON/XOFF out flow control
CommDCB.fInX = FALSE; // No XON/XOFF in flow control
CommDCB.fErrorChar = FALSE; // Disable error replacement
CommDCB.fNull = FALSE; // Disable null stripping
CommDCB.fRtsControl = RTS_CONTROL_DISABLE;
CommDCB.fAbortOnError = FALSE;
CommDCB.ByteSize = 8;
CommDCB.Parity = NOPARITY;
CommDCB.StopBits = ONESTOPBIT;
// konfiguracja portu
if (!SetCommState(hComm, &CommDCB))
{
// dwError = GetLastError ();
WriteLog("Unable to configure the serial port!");
return FALSE;
}
WriteLog("PortCOM OPEN and CONFIG!");
return TRUE;
}
bool TMWDComm::Close() // zamykanie portu COM
{
Global.bMWDmasterEnable = false; // główne włączenie portu!
Global.bMWDInputEnable = false; // włącz wejścia
Global.bMWDBreakEnable = false; // włącz wejścia analogowe
WriteLog("COM Port is closing...");
int i = 0;
while (i < BYTETOWRITE) // zerowanie danych...
{
WriteDataBuff[i] = 0;
i++;
}
Sleep(100);
SendData(); // wysyłanie do pulpitu: zatrzymanie haslera i zgaszenie lampek
Sleep(700);
CloseHandle(hComm);
WriteLog("COM is close!");
return TRUE;
}
bool TMWDComm::GetMWDState() // sprawdzanie otwarcia portu COM
{
if (hComm > 0)
return 1;
else
return 0;
}
bool TMWDComm::ReadData() // odbieranie danych + odczyta danych analogowych i zapis do zmiennych
{
DWORD bytes_read;
ReadFile(hComm, &ReadDataBuff[0], BYTETOREAD, &bytes_read, NULL);
if (Global.bMWDdebugEnable && Global.iMWDDebugMode == 128) WriteLog("Data receive. Checking data...");
if (Global.bMWDBreakEnable)
{
uiAnalog[0] = (ReadDataBuff[9] << 8) + ReadDataBuff[8];
uiAnalog[1] = (ReadDataBuff[11] << 8) + ReadDataBuff[10];
uiAnalog[2] = (ReadDataBuff[13] << 8) + ReadDataBuff[12];
uiAnalog[3] = (ReadDataBuff[15] << 8) + ReadDataBuff[14];
if (Global.bMWDdebugEnable && (Global.iMWDDebugMode & 1))
{
WriteLog("Main Break = " + to_string(uiAnalog[0]));
WriteLog("Locomotiv Break = " + to_string(uiAnalog[1]));
}
if (Global.bMWDdebugEnable && (Global.iMWDDebugMode & 2))
{
WriteLog("Analog input 1 = " + to_string(uiAnalog[2]));
WriteLog("Analog imput 2 = " + to_string(uiAnalog[3]));
}
}
if (Global.bMWDInputEnable) CheckData();
return TRUE;
}
bool TMWDComm::SendData() // wysyłanie danych
{
DWORD bytes_write;
WriteFile(hComm, &WriteDataBuff[0], BYTETOWRITE, &bytes_write, NULL);
return TRUE;
}
bool TMWDComm::Run() // wywoływanie obsługi MWD + generacja większego opóźnienia
{
if (GetMWDState())
{
MWDTime++;
if (!(MWDTime % Global.iMWDdivider))
{
MWDTime = 0;
if (Global.bMWDdebugEnable && Global.iMWDDebugMode == 128) WriteLog("Sending data...");
SendData();
if (Global.bMWDdebugEnable && Global.iMWDDebugMode == 128) WriteLog(" complet!\nReceiving data...");
ReadData();
if (Global.bMWDdebugEnable && Global.iMWDDebugMode == 128) WriteLog(" complet!");
return 1;
}
}
else
{
WriteLog("Port COM: connection ERROR!");
Close();
// może spróbować się połączyć znowu?
return 0;
}
return 1;
}
void TMWDComm::CheckData() // sprawdzanie wejść cyfrowych i odpowiednie sterowanie maszyną
{
int i = 0;
while (i < 6)
{
maskData[i] = ReadDataBuff[i] ^ lastStateData[i];
lastStateData[i] = ReadDataBuff[i];
i++;
}
/*
Rozpiska portów!
Port0: 0 NC odblok. przek. sprężarki i wentyl. oporów
1 M wyłącznik wył. szybkiego
2 Shift+M impuls załączający wył. szybki
3 N odblok. przekaźników nadmiarowych
i różnicowego obwodu głównegoMMm
4 NC rezerwa
5 Ctrl+N odblok. przek. nadmiarowych
przetwornicy, ogrzewania pociągu i różnicowych obw. pomocniczych
6 L wył. styczników liniowych
7 SPACE kasowanie czuwaka
Port1: 0 NC
1 (Shift) X przetwornica
2 (Shift) C sprężarka
3 S piasecznice
4 (Shift) H ogrzewanie składu
5 przel. hamowania Shift+B
pspbpwy Ctrl+B pospieszny B towarowy
6 przel. hamowania
7 (Shift) F rozruch w/n
Port2: 0 (Shift) P pantograf przedni
1 (Shift) O pantograf tylni
2 ENTER przyhamowanie przy poślizgu
3 () przyciemnienie świateł
4 () przyciemnienie świateł
5 NUM6 odluźniacz
6 a syrena lok W
7 A syrena lok N
Port3: 0 Shift+J bateria
1
2
3
4
5
6
7
*/
/* po przełączeniu bistabilnego najpierw wciskamy klawisz i przy następnym
wejściu w pętlę MWD puszczamy bo inaczej nie działa
*/
// wciskanie przycisków klawiatury
/*PORT0*/
if (maskData[0] & 0x02) if (lastStateData[0] & 0x02)
KeyBoard('M', 1); // wyłączenie wyłącznika szybkiego
else KeyBoard('M', 0); // monostabilny
if (maskData[0] & 0x04) if (lastStateData[0] & 0x04) // impuls załączający wyłącznik szybki
{
KeyBoard(0x10, 1); // monostabilny
KeyBoard('M', 1);
}
else
{
KeyBoard('M', 0);
KeyBoard(0x10, 0);
}
if (maskData[0] & 0x08) if (lastStateData[0] & 0x08)
KeyBoard('N', 1); // odblok nadmiarowego silników trakcyjnych
else KeyBoard('N', 0); // monostabilny
if (maskData[0] & 0x20) if (lastStateData[0] & 0x20)
{ // odblok nadmiarowego przetwornicy, ogrzewania poc.
KeyBoard(0x11, 1); // różnicowego obwodów pomocniczych
KeyBoard('N', 1); // monostabilny
}
else
{
KeyBoard('N', 0);
KeyBoard(0x11, 0);
}
if (maskData[0] & 0x40) if (lastStateData[0] & 0x40) KeyBoard('L', 1); // wył. styczników liniowych
else KeyBoard('L', 0); // monostabilny
if (maskData[0] & 0x80) if (lastStateData[0] & 0x80) KeyBoard(0x20, 1); // kasowanie czuwaka/SHP
else KeyBoard(0x20, 0); // kasowanie czuwaka/SHP
/*PORT1*/
// puszczanie przycisku bistabilnego klawiatury
if (maskSwitch[1] & 0x02)
{
if (bitSwitch[1] & 0x02)
{
KeyBoard('X', 0);
KeyBoard(0x10, 0);
}
else KeyBoard('X', 0);
maskSwitch[1] &= ~0x02;
}
if (maskSwitch[1] & 0x04) {
if (bitSwitch[1] & 0x04) {
KeyBoard('C', 0);
KeyBoard(0x10, 0);
}
else KeyBoard('C', 0);
maskSwitch[1] &= ~0x04;
}
if (maskSwitch[1] & 0x10) {
if (bitSwitch[1] & 0x10) {
KeyBoard('H', 0);
KeyBoard(0x10, 0);
}
else KeyBoard('H', 0);
maskSwitch[1] &= ~0x10;
}
if (maskSwitch[1] & 0x20 || maskSwitch[1] & 0x40) {
if (maskSwitch[1] & 0x20) KeyBoard(0x10, 0);
if (maskSwitch[1] & 0x40) KeyBoard(0x11, 0);
KeyBoard('B', 0);
maskSwitch[1] &= ~0x60;
}
if (maskSwitch[1] & 0x80) {
if (bitSwitch[1] & 0x80) {
KeyBoard('F', 0);
KeyBoard(0x10, 0);
}
else KeyBoard('F', 0);
maskSwitch[1] &= ~0x80;
}
// przetwornica
if (maskData[1] & 0x02) if (lastStateData[1] & 0x02)
{
KeyBoard(0x10, 1); // bistabilny
KeyBoard('X', 1);
maskSwitch[1] |= 0x02;
bitSwitch[1] |= 0x02;
}
else
{
maskSwitch[1] |= 0x02;
bitSwitch[1] &= ~0x02;
KeyBoard('X', 1);
}
// sprężarka
if (maskData[1] & 0x04) if (lastStateData[1] & 0x04)
{
KeyBoard(0x10, 1); // bistabilny
KeyBoard('C', 1);
maskSwitch[1] |= 0x04;
bitSwitch[1] |= 0x04;
}
else
{
maskSwitch[1] |= 0x04;
bitSwitch[1] &= ~0x04;
KeyBoard('C', 1);
}
// piasecznica
if (maskData[1] & 0x08) if (lastStateData[1] & 0x08)
KeyBoard('S', 1);
else
KeyBoard('S', 0); // monostabilny
// ogrzewanie składu
if (maskData[1] & 0x10) if (lastStateData[1] & 0x10)
{
KeyBoard(0x11, 1); // bistabilny
KeyBoard('H', 1);
maskSwitch[1] |= 0x10;
bitSwitch[1] |= 0x10;
}
else
{
maskSwitch[1] |= 0x10;
bitSwitch[1] &= ~0x10;
KeyBoard('H', 1);
}
// przełącznik hamowania
if (maskData[1] & 0x20 || maskData[1] & 0x40)
{
if (lastStateData[1] & 0x20)
{ // Shift+B
KeyBoard(0x10, 1);
maskSwitch[1] |= 0x20;
}
else if (lastStateData[1] & 0x40)
{ // Ctrl+B
KeyBoard(0x11, 1);
maskSwitch[1] |= 0x40;
}
KeyBoard('B', 1);
}
// rozruch wysoki/niski
if (maskData[1] & 0x80) if (lastStateData[1] & 0x80)
{
KeyBoard(0x10, 1); // bistabilny
KeyBoard('F', 1);
maskSwitch[1] |= 0x80;
bitSwitch[1] |= 0x80;
}
else
{
maskSwitch[1] |= 0x80;
bitSwitch[1] &= ~0x80;
KeyBoard('F', 1);
}
//PORT2
if (maskSwitch[2] & 0x01)
{
if (bitSwitch[2] & 0x01)
{
KeyBoard('P', 0);
KeyBoard(0x10, 0);
}
else KeyBoard('P', 0);
maskSwitch[2] &= ~0x01;
}
if (maskSwitch[2] & 0x02)
{
if (bitSwitch[2] & 0x02)
{
KeyBoard('O', 0);
KeyBoard(0x10, 0);
}
else KeyBoard('O', 0);
maskSwitch[2] &= ~0x02;
}
// pantograf przedni
if (maskData[2] & 0x01) if (lastStateData[2] & 0x01)
{
KeyBoard(0x10, 1); // bistabilny
KeyBoard('P', 1);
maskSwitch[2] |= 0x01;
bitSwitch[2] |= 0x01;
}
else
{
maskSwitch[2] |= 0x01;
bitSwitch[2] &= ~0x01;
KeyBoard('P', 1);
}
// pantograf tylni
if (maskData[2] & 0x02) if (lastStateData[2] & 0x02)
{
KeyBoard(0x10, 1); // bistabilny
KeyBoard('O', 1);
maskSwitch[2] |= 0x02;
bitSwitch[2] |= 0x02;
}
else
{
maskSwitch[2] |= 0x02;
bitSwitch[2] &= ~0x02;
KeyBoard('O', 1);
}
// przyhamowanie przy poślizgu
if (maskData[2] & 0x04) if (lastStateData[2] & 0x04) {
KeyBoard(0x10, 1); // monostabilny
KeyBoard(0x0D, 1);
}
else
{
KeyBoard(0x0D, 0);
KeyBoard(0x10, 0);
}
/*if(maskData[2] & 0x08) if (lastStateData[2] & 0x08){ // przyciemnienie świateł
KeyBoard(' ',0); // bistabilny
KeyBoard(0x10,1);
KeyBoard(' ',1);
}else{
KeyBoard(' ',0);
KeyBoard(0x10,0);
KeyBoard(' ',1);
}
if(maskData[2] & 0x10) if (lastStateData[2] & 0x10) { // przyciemnienie świateł
KeyBoard(' ',0); // bistabilny
KeyBoard(0x11,1);
KeyBoard(' ',1);
}else{
KeyBoard(' ',0);
KeyBoard(0x11,0);
KeyBoard(' ',1);
}*/
// odluźniacz
if (maskData[2] & 0x20) if (lastStateData[2] & 0x20)
KeyBoard(0x66, 1);
else
KeyBoard(0x66, 0); // monostabilny
// syrena wysoka
if (maskData[2] & 0x40) if (lastStateData[2] & 0x40)
{
KeyBoard(0x10, 1); // monostabilny
KeyBoard('A', 1);
}
else
{
KeyBoard('A', 0);
KeyBoard(0x10, 0);
}
if (maskData[2] & 0x80) if (lastStateData[2] & 0x80)
KeyBoard('A', 1); // syrena niska
else
KeyBoard('A', 0); // monostabilny
//PORT3
if (maskSwitch[3] & 0x01)
{
if (bitSwitch[3] & 0x01)
{
KeyBoard('J', 0);
KeyBoard(0x10, 0);
}
else KeyBoard('J', 0);
maskSwitch[3] &= ~0x01;
}
if (maskSwitch[3] & 0x02)
{
if (bitSwitch[3] & 0x02)
{
KeyBoard('Y', 0);
KeyBoard(0x10, 0);
}
else KeyBoard('Y', 0);
maskSwitch[3] &= ~0x02;
}
if (maskSwitch[3] & 0x04)
{
if (bitSwitch[3] & 0x04)
{
KeyBoard('U', 0);
KeyBoard(0x10, 0);
}
else KeyBoard('U', 0);
maskSwitch[3] &= ~0x04;
}
if (maskSwitch[3] & 0x08)
{
if (bitSwitch[3] & 0x08)
{
KeyBoard('I', 0);
KeyBoard(0x10, 0);
}
else KeyBoard('I', 0);
maskSwitch[3] &= ~0x08;
}
// bateria
if (maskData[3] & 0x01) if (lastStateData[3] & 0x01)
{
KeyBoard(0x10, 1); // bistabilny
KeyBoard('J', 1);
maskSwitch[3] |= 0x01;
bitSwitch[3] |= 0x01;
}
else
{
maskSwitch[3] |= 0x01;
bitSwitch[3] &= ~0x01;
KeyBoard('J', 1);
}
//Światło lewe
if (maskData[3] & 0x02) if (lastStateData[3] & 0x02)
{
KeyBoard(0x10, 1); // bistabilny
KeyBoard('Y', 1);
maskSwitch[3] |= 0x02;
bitSwitch[3] |= 0x02;
}else
{
maskSwitch[3] |= 0x02;
bitSwitch[3] &= ~0x02;
KeyBoard('Y', 1);
}
//światło górne
if (maskData[3] & 0x04) if (lastStateData[3] & 0x04)
{
KeyBoard(0x10, 1); // bistabilny
KeyBoard('U', 1);
maskSwitch[3] |= 0x04;
bitSwitch[3] |= 0x04;
}
else
{
maskSwitch[3] |= 0x04;
bitSwitch[3] &= ~0x04;
KeyBoard('U', 1);
}
//światło prawe
if (maskData[3] & 0x08) if (lastStateData[3] & 0x08)
{
KeyBoard(0x10, 1); // bistabilny
KeyBoard('I', 1);
maskSwitch[3] |= 0x08;
bitSwitch[3] |= 0x08;
}
else
{
maskSwitch[3] |= 0x08;
bitSwitch[3] &= ~0x08;
KeyBoard('I', 1);
}
/* NASTAWNIK, BOCZNIK i KIERUNEK */
if (bnkMask & 1)
{ // puszczanie klawiszy
KeyBoard(0x6B, 0);
bnkMask &= ~1;
}
if (bnkMask & 2)
{
KeyBoard(0x6D, 0);
bnkMask &= ~2;
}
if (bnkMask & 4)
{
KeyBoard(0x6F, 0);
bnkMask &= ~4;
}
if (bnkMask & 8)
{
KeyBoard(0x6A, 0);
bnkMask &= ~8;
}
if (nastawnik < ReadDataBuff[6])
{
bnkMask |= 1;
nastawnik++;
KeyBoard(0x6B, 1); // wciśnij + i dodaj 1 do nastawnika
}
if (nastawnik > ReadDataBuff[6])
{
bnkMask |= 2;
nastawnik--;
KeyBoard(0x6D, 1); // wciśnij - i odejmij 1 do nastawnika
}
if (bocznik < ReadDataBuff[7])
{
bnkMask |= 4;
bocznik++;
KeyBoard(0x6F, 1); // wciśnij / i dodaj 1 do bocznika
}
if (bocznik > ReadDataBuff[7])
{
bnkMask |= 8;
bocznik--;
KeyBoard(0x6A, 1); // wciśnij * i odejmij 1 do bocznika
}
/* Obsługa HASLERA */
if (ReadDataBuff[0] & 0x80)
bCzuwak = true;
if (bKabina1)
{ // logika rysika 1
bRysik1H = true;
bRysik1L = false;
if (bPrzejazdSHP)
bRysik1H = false;
}
else if (bKabina2)
{
bRysik1L = true;
bRysik1H = false;
if (bPrzejazdSHP)
bRysik1L = false;
}
else
{
bRysik1H = false;
bRysik1L = false;
}
if (bHamowanie)
{ // logika rysika 2
bRysik2H = false;
bRysik2L = true;
}
else
{
if (bCzuwak)
bRysik2H = true;
else
bRysik2H = false;
bRysik2L = false;
}
bCzuwak = false;
if (bRysik1H)
WriteDataBuff[6] |= 1 << 0;
else
WriteDataBuff[6] &= ~(1 << 0);
if (bRysik1L)
WriteDataBuff[6] |= 1 << 1;
else
WriteDataBuff[6] &= ~(1 << 1);
if (bRysik2H)
WriteDataBuff[6] |= 1 << 2;
else
WriteDataBuff[6] &= ~(1 << 2);
if (bRysik2L)
WriteDataBuff[6] |= 1 << 3;
else
WriteDataBuff[6] &= ~(1 << 3);
}
void TMWDComm::KeyBoard(int key, bool s) // emulacja klawiatury
{
INPUT ip;
// Set up a generic keyboard event.
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0; // hardware scan code for key
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = key; // virtual-key code for the "a" key
if (s)
{ // Press the "A" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
}
else
{
ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
SendInput(1, &ip, sizeof(INPUT));
}
// return 1;
}

112
old/MWD.h Normal file
View File

@@ -0,0 +1,112 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
/*
Program obsługi portu COM i innych na potrzeby sterownika MWDevice
(oraz innych wykorzystujących komunikację przez port COM)
dla Symulatora Pojazdów Szynowych MaSzyna
author: Maciej Witek 2016
Autor nie ponosi odpowiedzialności za niewłaciwe używanie lub działanie programu!
*/
#ifndef MWDH
#define MWDH
//---------------------------------------------------------------------------
#define BYTETOWRITE 31 // ilość bajtów przesyłanych z MaSzyny
#define BYTETOREAD 16 // ilość bajtów przesyłanych do MaSzyny
typedef unsigned char BYTE;
typedef unsigned long DWORD;
class TMWDComm
{
private:
int MWDTime; //
char lastStateData[6], maskData[6], maskSwitch[6], bitSwitch[6];
int bocznik, nastawnik, kierunek;
char bnkMask;
bool ReadData(); //BYTE *pReadDataBuff);
bool SendData(); //BYTE *pWriteDataBuff);
void CheckData(); //sprawdzanie zmian wejść i kontrola mazaków HASLERA
void KeyBoard(int key, bool s);
//void CheckData2();
bool bRysik1H;
bool bRysik1L;
bool bRysik2H;
bool bRysik2L;
public:
bool Open(); // Otwarcie portu
bool Close(); // Zamknięcie portu
bool Run(); // Obsługa portu
bool GetMWDState(); // sprawdź czy port jest otwarty, 0 zamknięty, 1 otwarty
// zmienne do rysików HASLERA
bool bSHPstate;
bool bPrzejazdSHP;
bool bKabina1;
bool bKabina2;
bool bHamowanie;
bool bCzuwak;
unsigned int uiAnalog[4]; // trzymanie danych z wejść analogowych
BYTE ReadDataBuff[BYTETOREAD]; //17]; // bufory danych
BYTE WriteDataBuff[BYTETOWRITE]; //31];
TMWDComm(); // konstruktor
~TMWDComm(); // destruktor
};
#endif
/*
INFO - zmiany dokonane w innych plikach niezbędne do prawidłowego działania:
Console.cpp:
Console::AnalogCalibrateGet - obsługa kranów hamulców
Console::Update - wywoływanie obsługi MWD
Console::ValueSet - obsługa manometrów, mierników WN (PWM-y)
Console::BitsUpdate - ustawiania lampek
Console::Off - zamykanie portu COM
Console::On - otwieranie portu COM
Console::~Console - usuwanie MWD (jest też w Console OFF)
MWDComm * Console::MWD = NULL; - luzem, obiekt i wskaźnik(?)
dodatkowo zmieniłem int na long int dla BitSet i BitClear oraz iBits
Train.cpp:
if (Global::iFeedbackMode == 5) - pobieranie prędkości, manometrów i mierników WN
if (ggBrakeCtrl.SubModel) - możliwość sterowania hamulcem zespolonym
if (ggLocalBrake.SubModel) - możliwość sterowania hamulcem lokomotywy
Globals.h:
dodano zmienne dla MWD
Globals.cpp:
dodano inicjalizaję zmiennych i odczyt z ini ustawień
Wpisy do pliku eu07.ini
//maciek001 MWD
comportname COM3 // wybór portu COM
mwdbaudrate 500000
mwdbreakenable yes // czy załączyć sterowanie hamulcami? blokuje klawiature
mwdbreak 1 255 0 255 // hamulec zespolony
mwdbreak 2 255 0 255 // hamulec lokomotywy
mwdzbiornikglowny 0.82 255
mwdprzewodglowny 0.7 255
mwdcylinderhamulcowy 0.43 255
mwdwoltomierzwn 4000 255
mwdamperomierzwn 800 255
*/

906
old/Mover.hpp Normal file
View File

@@ -0,0 +1,906 @@
// Borland C++ Builder
// Copyright (c) 1995, 1999 by Borland International
// All rights reserved
// (DO NOT EDIT: machine generated header) '_mover.pas' rev: 5.00
//Ra: eee... tam, sam si<73> generuje b<><62>dnie i trzeba r<>cznie poprawia<69>!
#ifndef _moverHPP
#define _moverHPP
#pragma delphiheader begin
#pragma option push -w-
#pragma option push -Vx
#include "Oerlikon_ESt.h" // Pascal unit
#include "hamulce.h" // Pascal unit
#include <SysUtils.hpp> // Pascal unit
#include <mctools.hpp> // Pascal unit
#include <SysInit.hpp> // Pascal unit
#include <System.hpp> // Pascal unit
//-- user supplied -----------------------------------------------------------
namespace _mover
{
//-- type declarations -------------------------------------------------------
struct TLocation
{
double X;
double Y;
double Z;
} ;
struct TRotation
{
double Rx;
double Ry;
double Rz;
} ;
struct TDimension
{
double W;
double L;
double H;
} ;
struct TCommand
{
AnsiString Command;
double Value1;
double Value2;
TLocation Location;
} ;
struct TTrackShape
{
double R;
double Len;
double dHtrack;
double dHrail;
} ;
struct TTrackParam
{
double Width;
double friction;
Byte CategoryFlag;
Byte QualityFlag;
Byte DamageFlag;
double Velmax;
} ;
struct TTractionParam
{
double TractionVoltage;
double TractionFreq;
double TractionMaxCurrent;
double TractionResistivity;
} ;
#pragma option push -b-
enum TBrakeSystem { Individual, Pneumatic, ElectroPneumatic };
#pragma option pop
#pragma option push -b-
enum TBrakeSubSystem { ss_None, ss_W, ss_K, ss_KK, ss_Hik, ss_ESt, ss_KE, ss_LSt, ss_MT, ss_Dako };
#pragma option pop
#pragma option push -b-
enum TBrakeValve { NoValve, W, W_Lu_VI, W_Lu_L, W_Lu_XR, K, Kg, Kp, Kss, Kkg, Kkp, Kks, Hikg1, Hikss,
Hikp1, KE, SW, EStED, NESt3, ESt3, LSt, ESt4, ESt3AL2, EP1, EP2, M483, CV1_L_TR, CV1, CV1_R, Other
};
#pragma option pop
#pragma option push -b-
enum TBrakeHandle {
NoHandle, West, FV4a, M394, M254, FVel1, FVel6, D2, Knorr, FD1, BS2, testH, St113,
MHZ_P, MHZ_T, MHZ_EN57 };
#pragma option pop
#pragma option push -b-
enum TLocalBrake { NoBrake, ManualBrake, PneumaticBrake, HydraulicBrake };
#pragma option pop
typedef double TBrakeDelayTable[4];
struct TBrakePressure
{
double PipePressureVal;
double BrakePressureVal;
double FlowSpeedVal;
TBrakeSystem BrakeType;
} ;
typedef TBrakePressure TBrakePressureTable[13];
#pragma option push -b-
enum TEngineTypes { None, Dumb, WheelsDriven, ElectricSeriesMotor, ElectricInductionMotor, DieselEngine,
SteamEngine, DieselElectric };
#pragma option pop
#pragma option push -b-
enum TPowerType { NoPower, BioPower, MechPower, ElectricPower, SteamPower };
#pragma option pop
#pragma option push -b-
enum TFuelType { Undefined, Coal, Oil };
#pragma option pop
struct TGrateType
{
TFuelType FuelType;
double GrateSurface;
double FuelTransportSpeed;
double IgnitionTemperature;
double MaxTemperature;
} ;
struct TBoilerType
{
double BoilerVolume;
double BoilerHeatSurface;
double SuperHeaterSurface;
double MaxWaterVolume;
double MinWaterVolume;
double MaxPressure;
} ;
struct TCurrentCollector
{
int CollectorsNo;
double MinH;
double MaxH;
double CSW;
double MinV;
double MaxV;
double OVP;
double InsetV;
double MinPress;
double MaxPress;
} ;
#pragma option push -b-
enum TPowerSource { NotDefined, InternalSource, Transducer, Generator, Accumulator, CurrentCollector,
PowerCable, Heater };
#pragma option pop
struct _mover__1
{
double MaxCapacity;
TPowerSource RechargeSource;
} ;
struct _mover__2
{
TPowerType PowerTrans;
double SteamPressure;
} ;
struct _mover__3
{
TGrateType Grate;
TBoilerType Boiler;
} ;
struct TPowerParameters
{
double MaxVoltage;
double MaxCurrent;
double IntR;
TPowerSource SourceType;
union
{
struct
{
_mover__3 RHeater;
};
struct
{
_mover__2 RPowerCable;
};
struct
{
TCurrentCollector CollectorParameters;
};
struct
{
_mover__1 RAccumulator;
};
struct
{
TEngineTypes GeneratorEngine;
};
struct
{
double InputVoltage;
};
struct
{
TPowerType PowerType;
};
};
} ;
struct TScheme
{
Byte Relay;
double R;
Byte Bn;
Byte Mn;
bool AutoSwitch;
Byte ScndAct;
} ;
typedef TScheme TSchemeTable[65];
struct TDEScheme
{
double RPM;
double GenPower;
double Umax;
double Imax;
} ;
typedef TDEScheme TDESchemeTable[33];
struct TShuntScheme
{
double Umin;
double Umax;
double Pmin;
double Pmax;
} ;
typedef TShuntScheme TShuntSchemeTable[33];
struct TMPTRelay
{
double Iup;
double Idown;
} ;
typedef TMPTRelay TMPTRelayTable[8];
struct TMotorParameters
{
double mfi;
double mIsat;
double mfi0;
double fi;
double Isat;
double fi0;
bool AutoSwitch;
} ;
struct TSecuritySystem
{
Byte SystemType;
double AwareDelay;
double AwareMinSpeed;
double SoundSignalDelay;
double EmergencyBrakeDelay;
Byte Status;
double SystemTimer;
double SystemSoundCATimer;
double SystemSoundSHPTimer;
double SystemBrakeCATimer;
double SystemBrakeSHPTimer;
double SystemBrakeCATestTimer;
int VelocityAllowed;
int NextVelocityAllowed;
bool RadioStop;
} ;
struct TTransmision
{
Byte NToothM;
Byte NToothW;
double Ratio;
} ;
#pragma option push -b-
enum TCouplerType { NoCoupler, Articulated, Bare, Chain, Screw, Automatic };
#pragma option pop
class DELPHICLASS T_MoverParameters;
struct TCoupling
{
double SpringKB;
double SpringKC;
double beta;
double DmaxB;
double FmaxB;
double DmaxC;
double FmaxC;
TCouplerType CouplerType;
Byte CouplingFlag;
int AllowedFlag;
bool Render;
double CoupleDist;
T_MoverParameters* Connected;
Byte ConnectedNr;
double CForce;
double Dist;
bool CheckCollision;
} ;
class PASCALIMPLEMENTATION T_MoverParameters : public System::TObject
{
typedef System::TObject inherited;
public:
double dMoveLen;
AnsiString filename;
Byte CategoryFlag;
AnsiString TypeName;
int TrainType;
TEngineTypes EngineType;
TPowerParameters EnginePowerSource;
TPowerParameters SystemPowerSource;
TPowerParameters HeatingPowerSource;
TPowerParameters AlterHeatPowerSource;
TPowerParameters LightPowerSource;
TPowerParameters AlterLightPowerSource;
double Vmax;
double Mass;
double Power;
double Mred;
double TotalMass;
double HeatingPower;
double LightPower;
double BatteryVoltage;
bool Battery;
bool EpFuse;
bool Signalling;
bool DoorSignalling;
bool Radio;
double NominalBatteryVoltage;
TDimension Dim;
double Cx;
double Floor;
double WheelDiameter;
double WheelDiameterL;
double WheelDiameterT;
double TrackW;
double AxleInertialMoment;
AnsiString AxleArangement;
Byte NPoweredAxles;
Byte NAxles;
Byte BearingType;
double ADist;
double BDist;
Byte NBpA;
int SandCapacity;
TBrakeSystem BrakeSystem;
TBrakeSubSystem BrakeSubsystem;
TBrakeValve BrakeValve;
TBrakeHandle BrakeHandle;
TBrakeHandle BrakeLocHandle;
double MBPM;
Hamulce::TBrake* Hamulec;
Hamulce::THandle* Handle;
Hamulce::THandle* LocHandle;
Hamulce::TReservoir* Pipe;
Hamulce::TReservoir* Pipe2;
TLocalBrake LocalBrake;
TBrakePressure BrakePressureTable[13];
TBrakePressure BrakePressureActual;
Byte ASBType;
Byte TurboTest;
double MaxBrakeForce;
double MaxBrakePress[5];
double P2FTrans;
double TrackBrakeForce;
Byte BrakeMethod;
double HighPipePress;
double LowPipePress;
double DeltaPipePress;
double CntrlPipePress;
double BrakeVolume;
double BrakeVVolume;
double VeselVolume;
int BrakeCylNo;
double BrakeCylRadius;
double BrakeCylDist;
double BrakeCylMult[3];
Byte LoadFlag;
double BrakeCylSpring;
double BrakeSlckAdj;
double BrakeRigEff;
double RapidMult;
int BrakeValveSize;
AnsiString BrakeValveParams;
double Spg;
double MinCompressor;
double MaxCompressor;
double CompressorSpeed;
double BrakeDelay[4];
Byte BrakeCtrlPosNo;
Byte MainCtrlPosNo;
Byte ScndCtrlPosNo;
Byte LightsPosNo;
Byte LightsDefPos;
bool LightsWrap;
Byte Lights[2][16];
bool ScndInMain;
bool MBrake;
double StopBrakeDecc;
TSecuritySystem SecuritySystem;
TScheme RList[65];
int RlistSize;
TMotorParameters MotorParam[11];
TTransmision Transmision;
double NominalVoltage;
double WindingRes;
double u;
double CircuitRes;
int IminLo;
int IminHi;
int ImaxLo;
int ImaxHi;
double nmax;
double InitialCtrlDelay;
double CtrlDelay;
double CtrlDownDelay;
Byte FastSerialCircuit;
Byte AutoRelayType;
bool CoupledCtrl;
bool IsCoupled;
Byte DynamicBrakeType;
Byte RVentType;
double RVentnmax;
double RVentCutOff;
int CompressorPower;
int SmallCompressorPower;
bool Trafo;
double dizel_Mmax;
double dizel_nMmax;
double dizel_Mnmax;
double dizel_nmax;
double dizel_nominalfill;
double dizel_Mstand;
double dizel_nmax_cutoff;
double dizel_nmin;
double dizel_minVelfullengage;
double dizel_AIM;
double dizel_engageDia;
double dizel_engageMaxForce;
double dizel_engagefriction;
double AnPos;
bool AnalogCtrl;
bool AnMainCtrl;
bool ShuntModeAllow;
bool ShuntMode;
bool Flat;
double Vhyp;
TDEScheme DElist[33];
double Vadd;
TMPTRelay MPTRelay[8];
Byte RelayType;
TShuntScheme SST[33];
double PowerCorRatio;
double Ftmax;
double eimc[26];
int MaxLoad;
AnsiString LoadAccepted;
AnsiString LoadQuantity;
double OverLoadFactor;
double LoadSpeed;
double UnLoadSpeed;
Byte DoorOpenCtrl;
Byte DoorCloseCtrl;
double DoorStayOpen;
bool DoorClosureWarning;
double DoorOpenSpeed;
double DoorCloseSpeed;
double DoorMaxShiftL;
double DoorMaxShiftR;
double DoorMaxPlugShift;
Byte DoorOpenMethod;
double PlatformSpeed;
double PlatformMaxShift;
Byte PlatformOpenMethod;
bool ScndS;
TLocation Loc;
TRotation Rot;
AnsiString Name;
TCoupling Couplers[2];
double HVCouplers[2][2];
int ScanCounter;
bool EventFlag;
Byte SoundFlag;
double DistCounter;
double V;
double Vel;
double AccS;
double AccN;
double AccV;
double nrot;
double EnginePower;
double dL;
double Fb;
double Ff;
double FTrain;
double FStand;
double FTotal;
double UnitBrakeForce;
double Ntotal;
bool SlippingWheels;
bool SandDose;
double Sand;
double BrakeSlippingTimer;
double dpBrake;
double dpPipe;
double dpMainValve;
double dpLocalValve;
double ScndPipePress;
double BrakePress;
double LocBrakePress;
double PipeBrakePress;
double PipePress;
double EqvtPipePress;
double Volume;
double CompressedVolume;
double PantVolume;
double Compressor;
bool CompressorFlag;
bool PantCompFlag;
bool CompressorAllow;
bool ConverterFlag;
bool ConverterAllow;
int BrakeCtrlPos;
double BrakeCtrlPosR;
double BrakeCtrlPos2;
Byte LocalBrakePos;
Byte ManualBrakePos;
double LocalBrakePosA;
Byte BrakeStatus;
bool EmergencyBrakeFlag;
Byte BrakeDelayFlag;
Byte BrakeDelays;
Byte BrakeOpModeFlag;
Byte BrakeOpModes;
bool DynamicBrakeFlag;
double LimPipePress;
double ActFlowSpeed;
Byte DamageFlag;
Byte EngDmgFlag;
Byte DerailReason;
TCommand CommandIn;
AnsiString CommandOut;
AnsiString CommandLast;
double ValueOut;
TTrackShape RunningShape;
TTrackParam RunningTrack;
double OffsetTrackH;
double OffsetTrackV;
bool Mains;
Byte MainCtrlPos;
Byte ScndCtrlPos;
Byte LightsPos;
int ActiveDir;
int CabNo;
int DirAbsolute;
int ActiveCab;
double LastSwitchingTime;
bool DepartureSignal;
bool InsideConsist;
TTractionParam RunningTraction;
double enrot;
double Im;
double Itot;
double IHeating;
double ITraction;
double TotalCurrent;
double Mm;
double Mw;
double Fw;
double Ft;
int Imin;
int Imax;
double Voltage;
Byte MainCtrlActualPos;
Byte ScndCtrlActualPos;
bool DelayCtrlFlag;
double LastRelayTime;
bool AutoRelayFlag;
bool FuseFlag;
bool ConvOvldFlag;
bool StLinFlag;
bool ResistorsFlag;
double RventRot;
bool UnBrake;
double PantPress;
bool s_CAtestebrake;
double dizel_fill;
double dizel_engagestate;
double dizel_engage;
double dizel_automaticgearstatus;
bool dizel_enginestart;
double dizel_engagedeltaomega;
double eimv[21];
double PulseForce;
double PulseForceTimer;
int PulseForceCount;
double eAngle;
int Load;
AnsiString LoadType;
Byte LoadStatus;
double LastLoadChangeTime;
bool DoorBlocked;
bool DoorLeftOpened;
bool DoorRightOpened;
bool PantFrontUp;
bool PantRearUp;
bool PantFrontSP;
bool PantRearSP;
int PantFrontStart;
int PantRearStart;
double PantFrontVolt;
double PantRearVolt;
AnsiString PantSwitchType;
AnsiString ConvSwitchType;
bool Heating;
int DoubleTr;
bool PhysicActivation;
double FrictConst1;
double FrictConst2s;
double FrictConst2d;
double TotalMassxg;
double __fastcall GetTrainsetVoltage(void);
bool __fastcall Physic_ReActivation(void);
double __fastcall LocalBrakeRatio(void);
double __fastcall ManualBrakeRatio(void);
double __fastcall PipeRatio(void);
double __fastcall RealPipeRatio(void);
double __fastcall BrakeVP(void);
bool __fastcall DynamicBrakeSwitch(bool Switch);
bool __fastcall SendCtrlBroadcast(AnsiString CtrlCommand, double ctrlvalue);
bool __fastcall SendCtrlToNext(AnsiString CtrlCommand, double ctrlvalue, double dir);
bool __fastcall CabActivisation(void);
bool __fastcall CabDeactivisation(void);
bool __fastcall IncMainCtrl(int CtrlSpeed);
bool __fastcall DecMainCtrl(int CtrlSpeed);
bool __fastcall IncScndCtrl(int CtrlSpeed);
bool __fastcall DecScndCtrl(int CtrlSpeed);
bool __fastcall AddPulseForce(int Multipler);
bool __fastcall SandDoseOn(void);
bool __fastcall SecuritySystemReset(void);
void __fastcall SecuritySystemCheck(double dt);
bool __fastcall BatterySwitch(bool State);
bool __fastcall EpFuseSwitch(bool State);
bool __fastcall IncBrakeLevelOld(void);
bool __fastcall DecBrakeLevelOld(void);
bool __fastcall IncLocalBrakeLevel(Byte CtrlSpeed);
bool __fastcall DecLocalBrakeLevel(Byte CtrlSpeed);
bool __fastcall IncLocalBrakeLevelFAST(void);
bool __fastcall DecLocalBrakeLevelFAST(void);
bool __fastcall IncManualBrakeLevel(Byte CtrlSpeed);
bool __fastcall DecManualBrakeLevel(Byte CtrlSpeed);
bool __fastcall EmergencyBrakeSwitch(bool Switch);
bool __fastcall AntiSlippingBrake(void);
bool __fastcall BrakeReleaser(Byte state);
bool __fastcall SwitchEPBrake(Byte state);
bool __fastcall AntiSlippingButton(void);
bool __fastcall IncBrakePress(double &brake, double PressLimit, double dp);
bool __fastcall DecBrakePress(double &brake, double PressLimit, double dp);
bool __fastcall BrakeDelaySwitch(Byte BDS);
bool __fastcall IncBrakeMult(void);
bool __fastcall DecBrakeMult(void);
void __fastcall UpdateBrakePressure(double dt);
void __fastcall UpdatePipePressure(double dt);
void __fastcall CompressorCheck(double dt);
//void __fastcall UpdatePantVolume(double dt);
void __fastcall UpdateScndPipePressure(double dt);
void __fastcall UpdateBatteryVoltage(double dt);
double __fastcall GetDVc(double dt);
void __fastcall ComputeConstans(void);
double __fastcall ComputeMass(void);
double __fastcall Adhesive(double staticfriction);
double __fastcall TractionForce(double dt);
double __fastcall FrictionForce(double R, Byte TDamage);
double __fastcall BrakeForce(const TTrackParam &Track);
double __fastcall CouplerForce(Byte CouplerN, double dt);
void __fastcall CollisionDetect(Byte CouplerN, double dt);
double __fastcall ComputeRotatingWheel(double WForce, double dt, double n);
bool __fastcall SetInternalCommand(AnsiString NewCommand, double NewValue1, double NewValue2);
double __fastcall GetExternalCommand(AnsiString &Command);
bool __fastcall RunCommand(AnsiString command, double CValue1, double CValue2);
bool __fastcall RunInternalCommand(void);
void __fastcall PutCommand(AnsiString NewCommand, double NewValue1, double NewValue2, const TLocation
&NewLocation);
bool __fastcall DirectionBackward(void);
bool __fastcall MainSwitch(bool State);
bool __fastcall ConverterSwitch(bool State);
bool __fastcall CompressorSwitch(bool State);
bool __fastcall FuseOn(void);
bool __fastcall FuseFlagCheck(void);
void __fastcall FuseOff(void);
int __fastcall ShowCurrent(Byte AmpN);
double __fastcall v2n(void);
double __fastcall current(double n, double U);
double __fastcall Momentum(double I);
double __fastcall MomentumF(double I, double Iw, Byte SCP);
bool __fastcall CutOffEngine(void);
bool __fastcall MaxCurrentSwitch(bool State);
bool __fastcall ResistorsFlagCheck(void);
bool __fastcall MinCurrentSwitch(bool State);
bool __fastcall AutoRelaySwitch(bool State);
bool __fastcall AutoRelayCheck(void);
bool __fastcall dizel_EngageSwitch(double state);
bool __fastcall dizel_EngageChange(double dt);
bool __fastcall dizel_AutoGearCheck(void);
double __fastcall dizel_fillcheck(Byte mcp);
double __fastcall dizel_Momentum(double dizel_fill, double n, double dt);
bool __fastcall dizel_Update(double dt);
bool __fastcall LoadingDone(double LSpeed, AnsiString LoadInit);
void __fastcall ComputeTotalForce(double dt, double dt1, bool FullVer);
double __fastcall ComputeMovement(double dt, double dt1, const TTrackShape &Shape, TTrackParam &Track
, TTractionParam &ElectricTraction, const TLocation &NewLoc, TRotation &NewRot);
double __fastcall FastComputeMovement(double dt, const TTrackShape &Shape, TTrackParam &Track, const
TLocation &NewLoc, TRotation &NewRot);
bool __fastcall ChangeOffsetH(double DeltaOffset);
__fastcall T_MoverParameters(double VelInitial, AnsiString TypeNameInit, AnsiString NameInit, int LoadInitial
, AnsiString LoadTypeInitial, int Cab);
bool __fastcall LoadChkFile(AnsiString chkpath);
bool __fastcall CheckLocomotiveParameters(bool ReadyFlag, int Dir);
AnsiString __fastcall EngineDescription(int what);
bool __fastcall DoorLeft(bool State);
bool __fastcall DoorRight(bool State);
bool __fastcall DoorBlockedFlag(void);
bool __fastcall PantFront(bool State);
bool __fastcall PantRear(bool State);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall T_MoverParameters(void) : System::TObject() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~T_MoverParameters(void) { }
#pragma option pop
};
//-- var, const, procedure ---------------------------------------------------
static const bool Go = true;
static const bool Hold = false;
static const Shortint ResArraySize = 0x40;
static const Shortint MotorParametersArraySize = 0xa;
static const Shortint maxcc = 0x4;
static const Shortint LocalBrakePosNo = 0xa;
static const Shortint MainBrakeMaxPos = 0xa;
static const Shortint ManualBrakePosNo = 0x14;
static const Shortint LightsSwitchPosNo = 0x10;
static const Shortint dtrack_railwear = 0x2;
static const Shortint dtrack_freerail = 0x4;
static const Shortint dtrack_thinrail = 0x8;
static const Shortint dtrack_railbend = 0x10;
static const Shortint dtrack_plants = 0x20;
static const Shortint dtrack_nomove = 0x40;
static const Byte dtrack_norail = 0x80;
static const Shortint dtrain_thinwheel = 0x1;
static const Shortint dtrain_loadshift = 0x1;
static const Shortint dtrain_wheelwear = 0x2;
static const Shortint dtrain_bearing = 0x4;
static const Shortint dtrain_coupling = 0x8;
static const Shortint dtrain_ventilator = 0x10;
static const Shortint dtrain_loaddamage = 0x10;
static const Shortint dtrain_engine = 0x20;
static const Shortint dtrain_loaddestroyed = 0x20;
static const Shortint dtrain_axle = 0x40;
static const Byte dtrain_out = 0x80;
#define p_elengproblem (1.000000E-02)
#define p_elengdamage (1.000000E-01)
#define p_coupldmg (2.000000E-02)
#define p_derail (1.000000E-03)
#define p_accn (1.000000E-01)
#define p_slippdmg (1.000000E-03)
static const Shortint ctrain_virtual = 0x0;
static const Shortint ctrain_coupler = 0x1;
static const Shortint ctrain_pneumatic = 0x2;
static const Shortint ctrain_controll = 0x4;
static const Shortint ctrain_power = 0x8;
static const Shortint ctrain_passenger = 0x10;
static const Shortint ctrain_scndpneumatic = 0x20;
static const Shortint ctrain_heating = 0x40;
static const Byte ctrain_depot = 0x80;
static const Shortint dbrake_none = 0x0;
static const Shortint dbrake_passive = 0x1;
static const Shortint dbrake_switch = 0x2;
static const Shortint dbrake_reversal = 0x4;
static const Shortint dbrake_automatic = 0x8;
static const Shortint s_waiting = 0x1;
static const Shortint s_aware = 0x2;
static const Shortint s_active = 0x4;
static const Shortint s_CAalarm = 0x8;
static const Shortint s_SHPalarm = 0x10;
static const Shortint s_CAebrake = 0x20;
static const Shortint s_SHPebrake = 0x40;
static const Byte s_CAtest = 0x80;
static const Shortint sound_none = 0x0;
static const Shortint sound_loud = 0x1;
static const Shortint sound_couplerstretch = 0x2;
static const Shortint sound_bufferclamp = 0x4;
static const Shortint sound_bufferbump = 0x8;
static const Shortint sound_relay = 0x10;
static const Shortint sound_manyrelay = 0x20;
static const Shortint sound_brakeacc = 0x40;
extern PACKAGE bool PhysicActivationFlag;
static const Shortint dt_Default = 0x0;
static const Shortint dt_EZT = 0x1;
static const Shortint dt_ET41 = 0x2;
static const Shortint dt_ET42 = 0x4;
static const Shortint dt_PseudoDiesel = 0x8;
static const Shortint dt_ET22 = 0x10;
static const Shortint dt_SN61 = 0x20;
static const Shortint dt_EP05 = 0x40;
static const Byte dt_ET40 = 0x80;
static const Word dt_181 = 0x100;
static const Shortint eimc_s_dfic = 0x0;
static const Shortint eimc_s_dfmax = 0x1;
static const Shortint eimc_s_p = 0x2;
static const Shortint eimc_s_cfu = 0x3;
static const Shortint eimc_s_cim = 0x4;
static const Shortint eimc_s_icif = 0x5;
static const Shortint eimc_f_Uzmax = 0x7;
static const Shortint eimc_f_uzh = 0x8;
static const Shortint eimc_f_DU = 0x9;
static const Shortint eimc_f_I0 = 0xa;
static const Shortint eimc_f_cfu = 0xb;
static const Shortint eimc_p_F0 = 0xd;
static const Shortint eimc_p_a1 = 0xe;
static const Shortint eimc_p_Pmax = 0xf;
static const Shortint eimc_p_Fh = 0x10;
static const Shortint eimc_p_Ph = 0x11;
static const Shortint eimc_p_Vh0 = 0x12;
static const Shortint eimc_p_Vh1 = 0x13;
static const Shortint eimc_p_Imax = 0x14;
static const Shortint eimc_p_abed = 0x15;
static const Shortint eimc_p_eped = 0x16;
static const Shortint eimv_FMAXMAX = 0x0;
static const Shortint eimv_Fmax = 0x1;
static const Shortint eimv_ks = 0x2;
static const Shortint eimv_df = 0x3;
static const Shortint eimv_fp = 0x4;
static const Shortint eimv_U = 0x5;
static const Shortint eimv_pole = 0x6;
static const Shortint eimv_Ic = 0x7;
static const Shortint eimv_If = 0x8;
static const Shortint eimv_M = 0x9;
static const Shortint eimv_Fr = 0xa;
static const Shortint eimv_Ipoj = 0xb;
static const Shortint eimv_Pm = 0xc;
static const Shortint eimv_Pe = 0xd;
static const Shortint eimv_eta = 0xe;
static const Shortint eimv_fkr = 0xf;
static const Shortint eimv_Uzsmax = 0x10;
static const Shortint eimv_Pmax = 0x11;
static const Shortint eimv_Fzad = 0x12;
static const Shortint eimv_Imax = 0x13;
static const Shortint eimv_Fful = 0x14;
static const Shortint bom_PS = 0x1;
static const Shortint bom_PN = 0x2;
static const Shortint bom_EP = 0x4;
static const Shortint bom_MED = 0x8;
extern PACKAGE double __fastcall Distance(const TLocation &Loc1, const TLocation &Loc2, const TDimension
&Dim1, const TDimension &Dim2);
} /* namespace _mover */
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace _mover;
#endif
#pragma option pop // -w-
#pragma option pop // -Vx
#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif // _mover

293
old/Oerlikon_ESt.hpp Normal file
View File

@@ -0,0 +1,293 @@
// Borland C++ Builder
// Copyright (c) 1995, 1999 by Borland International
// All rights reserved
// (DO NOT EDIT: machine generated header) 'Oerlikon_ESt.pas' rev: 5.00
#ifndef Oerlikon_EStHPP
#define Oerlikon_EStHPP
#pragma delphiheader begin
#pragma option push -w-
#pragma option push -Vx
#include <hamulce.h> // Pascal unit
#include <friction.h> // Pascal unit
#include <SysUtils.hpp> // Pascal unit
#include <mctools.h> // Pascal unit
#include <SysInit.hpp> // Pascal unit
#include <System.hpp> // Pascal unit
//-- user supplied -----------------------------------------------------------
namespace Oerlikon_est
{
//-- type declarations -------------------------------------------------------
class DELPHICLASS TPrzekladnik;
class PASCALIMPLEMENTATION TPrzekladnik : public TReservoir
{
typedef TReservoir inherited;
public:
TReservoir* *BrakeRes;
TReservoir* *Next;
virtual void __fastcall Update(double dt);
public:
#pragma option push -w-inl
/* TReservoir.Create */ inline __fastcall TPrzekladnik(void) : TReservoir() { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TPrzekladnik(void) { }
#pragma option pop
};
class DELPHICLASS TRura;
class PASCALIMPLEMENTATION TRura : public TPrzekladnik
{
typedef TPrzekladnik inherited;
public:
virtual double __fastcall P(void);
virtual void __fastcall Update(double dt);
public:
#pragma option push -w-inl
/* TReservoir.Create */ inline __fastcall TRura(void) : TPrzekladnik() { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TRura(void) { }
#pragma option pop
};
class DELPHICLASS TPrzeciwposlizg;
class PASCALIMPLEMENTATION TPrzeciwposlizg : public TRura
{
typedef TRura inherited;
private:
bool Poslizg;
public:
void __fastcall SetPoslizg(bool flag);
virtual void __fastcall Update(double dt);
public:
#pragma option push -w-inl
/* TReservoir.Create */ inline __fastcall TPrzeciwposlizg(void) : TRura() { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TPrzeciwposlizg(void) { }
#pragma option pop
};
class DELPHICLASS TRapid;
class PASCALIMPLEMENTATION TRapid : public TPrzekladnik
{
typedef TPrzekladnik inherited;
private:
bool RapidStatus;
double RapidMult;
double DN;
double DL;
public:
void __fastcall SetRapidParams(double mult, double size);
void __fastcall SetRapidStatus(bool rs);
virtual void __fastcall Update(double dt);
public:
#pragma option push -w-inl
/* TReservoir.Create */ inline __fastcall TRapid(void) : TPrzekladnik() { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TRapid(void) { }
#pragma option pop
};
class DELPHICLASS TPrzekCiagly;
class PASCALIMPLEMENTATION TPrzekCiagly : public TPrzekladnik
{
typedef TPrzekladnik inherited;
private:
double Mult;
public:
void __fastcall SetMult(double m);
virtual void __fastcall Update(double dt);
public:
#pragma option push -w-inl
/* TReservoir.Create */ inline __fastcall TPrzekCiagly(void) : TPrzekladnik() { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TPrzekCiagly(void) { }
#pragma option pop
};
class DELPHICLASS TPrzek_PZZ;
class PASCALIMPLEMENTATION TPrzek_PZZ : public TPrzekladnik
{
typedef TPrzekladnik inherited;
private:
double LBP;
public:
void __fastcall SetLBP(double P);
virtual void __fastcall Update(double dt);
public:
#pragma option push -w-inl
/* TReservoir.Create */ inline __fastcall TPrzek_PZZ(void) : TPrzekladnik() { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TPrzek_PZZ(void) { }
#pragma option pop
};
class DELPHICLASS TPrzekZalamany;
class PASCALIMPLEMENTATION TPrzekZalamany : public TPrzekladnik
{
typedef TPrzekladnik inherited;
public:
#pragma option push -w-inl
/* TReservoir.Create */ inline __fastcall TPrzekZalamany(void) : TPrzekladnik() { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TPrzekZalamany(void) { }
#pragma option pop
};
class DELPHICLASS TPrzekED;
class PASCALIMPLEMENTATION TPrzekED : public TRura
{
typedef TRura inherited;
private:
double MaxP;
public:
void __fastcall SetP(double P);
virtual void __fastcall Update(double dt);
public:
#pragma option push -w-inl
/* TReservoir.Create */ inline __fastcall TPrzekED(void) : TRura() { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TPrzekED(void) { }
#pragma option pop
};
class DELPHICLASS TNESt3;
class PASCALIMPLEMENTATION TNESt3 : public Hamulce::TBrake
{
typedef Hamulce::TBrake inherited;
private:
double Nozzles[11];
Hamulce::TReservoir* CntrlRes;
double BVM;
bool Zamykajacy;
bool Przys_blok;
Hamulce::TReservoir* Miedzypoj;
TPrzekladnik* Przekladniki[3];
bool RapidStatus;
bool RapidStaly;
double LoadC;
double TareM;
double LoadM;
double TareBP;
double HBG300;
double Podskok;
bool autom;
double LBP;
public:
virtual double __fastcall GetPF(double PP, double dt, double Vel);
void __fastcall EStParams(double i_crc);
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
virtual double __fastcall GetCRP(void);
void __fastcall CheckState(double BCP, double &dV1);
void __fastcall CheckReleaser(double dt);
double __fastcall CVs(double bp);
double __fastcall BVs(double BCP);
void __fastcall SetSize(int size, AnsiString params);
void __fastcall PLC(double mass);
void __fastcall SetLP(double TM, double LM, double TBP);
virtual void __fastcall ForceEmptiness(void);
void __fastcall SetLBP(double P);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TNESt3(double i_mbp, double i_bcr, double i_bcd, double i_brc
, Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : Hamulce::TBrake(i_mbp, i_bcr, i_bcd
, i_brc, i_bcn, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TNESt3(void) { }
#pragma option pop
};
//-- var, const, procedure ---------------------------------------------------
static const Shortint dMAX = 0xa;
static const Shortint dON = 0x0;
static const Shortint dOO = 0x1;
static const Shortint dTN = 0x2;
static const Shortint dTO = 0x3;
static const Shortint dP = 0x4;
static const Shortint dSd = 0x5;
static const Shortint dSm = 0x6;
static const Shortint dPd = 0x7;
static const Shortint dPm = 0x8;
static const Shortint dPO = 0x9;
static const Shortint dPT = 0xa;
static const Shortint p_none = 0x0;
static const Shortint p_rapid = 0x1;
static const Shortint p_pp = 0x2;
static const Shortint p_al2 = 0x3;
static const Shortint p_ppz = 0x4;
static const Shortint P_ed = 0x5;
extern PACKAGE double __fastcall d2A(double d);
} /* namespace Oerlikon_est */
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Oerlikon_est;
#endif
#pragma option pop // -w-
#pragma option pop // -Vx
#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif // Oerlikon_ESt

805
old/Oerlikon_ESt.pas Normal file
View File

@@ -0,0 +1,805 @@
unit Oerlikon_ESt; {fizyka hamulcow Oerlikon ESt dla symulatora}
(*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*)
(*
MaSzyna EU07 - SPKS
Brakes. Oerlikon ESt.
Copyright (C) 2007-2014 Maciej Cierniak
*)
(*
(C) youBy
Co jest:
- glowny przyrzad rozrzadczy
- napelniacz zbiornika pomocniczego
- napelniacz zbiornika sterujacego
- zawor podskoku
- nibyprzyspieszacz
- tylko 16",14",12",10"
- nieprzekladnik rura
- przekladnik 1:1
- przekladniki AL2
- przeciwposlizgi
- rapid REL2
- HGB300
- inne srednice
Co brakuje:
- dobry przyspieszacz
- mozliwosc zasilania z wysokiego cisnienia ESt4
- ep: EP1 i EP2
- samoczynne ep
- PZZ dla dodatkowego
*)
interface
uses mctools,sysutils,friction,hamulce;//,klasy_ham;
CONST
dMAX=10; //dysze
dON = 0; //osobowy napelnianie (+ZP)
dOO = 1; //osobowy oproznianie
dTN = 2; //towarowy napelnianie (+ZP)
dTO = 3; //towarowy oproznianie
dP = 4; //zbiornik pomocniczy
dSd = 5; //zbiornik sterujacy
dSm = 6; //zbiornik sterujacy
dPd = 7; //duzy przelot zamykajcego
dPm = 8; //maly przelot zamykajacego
dPO = 9; //zasilanie pomocniczego O
dPT =10; //zasilanie pomocniczego T
//przekladniki
p_none = 0;
p_rapid = 1;
p_pp = 2;
p_al2 = 3;
p_ppz = 4;
P_ed = 5;
TYPE
TPrzekladnik= class(TReservoir) //przekladnik (powtarzacz)
private
public
BrakeRes: PReservoir;
Next: PReservoir;
procedure Update(dt:real); virtual;
end;
TRura= class(TPrzekladnik) //nieprzekladnik, rura laczaca
private
public
function P: real; override;
procedure Update(dt:real); override;
end;
TPrzeciwposlizg= class(TRura) //przy napelnianiu - rura, przy poslizgu - upust
private
Poslizg: boolean;
public
procedure SetPoslizg(flag: boolean);
procedure Update(dt:real); override;
end;
TRapid= class(TPrzekladnik) //przekladnik dwustopniowy
private
RapidStatus: boolean; //status rapidu
RapidMult: real; //przelozenie (w dol)
// Komora2: real;
DN,DL: real; //srednice dysz napelniania i luzowania
public
procedure SetRapidParams(mult: real; size: real);
procedure SetRapidStatus(rs: boolean);
procedure Update(dt:real); override;
end;
TPrzekCiagly= class(TPrzekladnik) //AL2
private
Mult: real;
public
procedure SetMult(m: real);
procedure Update(dt:real); override;
end;
TPrzek_PZZ= class(TPrzekladnik) //podwojny zawor zwrotny
private
LBP: real;
public
procedure SetLBP(P: real);
procedure Update(dt:real); override;
end;
TPrzekZalamany= class(TPrzekladnik) //Knicksventil
private
public
end;
TPrzekED= class(TRura) //przy napelnianiu - rura, przy hamowaniu - upust
private
MaxP: real;
public
procedure SetP(P: real);
procedure Update(dt:real); override;
end;
TNESt3= class(TBrake)
private
Nozzles: array[0..dMAX] of real; //dysze
CntrlRes: TReservoir; //zbiornik steruj¹cy
BVM: real; //przelozenie PG-CH
// ValveFlag: byte; //polozenie roznych zaworkow
Zamykajacy: boolean; //pamiec zaworka zamykajacego
// Przys_wlot: boolean; //wlot do komory przyspieszacza
Przys_blok: boolean; //blokada przyspieszacza
Miedzypoj: TReservoir; //pojemnosc posrednia (urojona) do napelniania ZP i ZS
Przekladniki: array[1..3] of TPrzekladnik;
RapidStatus: boolean;
RapidStaly: boolean;
LoadC: real;
TareM, LoadM: real; //masa proznego i pelnego
TareBP: real; //cisnienie dla proznego
HBG300: real; //zawor ograniczajacy cisnienie
Podskok: real; //podskok preznosci poczatkowej
// HPBR: real; //zasilanie ZP z wysokiego cisnienia
autom: boolean; //odluzniacz samoczynny
LBP: real; //cisnienie hamulca pomocniczego
public
function GetPF(PP, dt, Vel: real): real; override; //przeplyw miedzy komora wstepna i PG
procedure EStParams(i_crc: real); //parametry charakterystyczne dla ESt
procedure Init(PP, HPP, LPP, BP: real; BDF: byte); override;
function GetCRP: real; override;
procedure CheckState(BCP: real; var dV1: real); //glowny przyrzad rozrzadczy
procedure CheckReleaser(dt: real); //odluzniacz
function CVs(bp: real): real; //napelniacz sterujacego
function BVs(BCP: real): real; //napelniacz pomocniczego
procedure SetSize(size: integer; params: string); //ustawianie dysz (rozmiaru ZR), przekladniki
procedure PLC(mass: real); //wspolczynnik cisnienia przystawki wazacej
procedure SetLP(TM, LM, TBP: real); //parametry przystawki wazacej
procedure ForceEmptiness(); override; //wymuszenie bycia pustym
procedure SetLBP(P: real); //cisnienie z hamulca pomocniczego
end;
function d2A(d: real):real;
implementation
function d2A(d: real):real;
begin
d2A:=(d*d)*0.7854/1000;
end;
// ------ RURA ------
function TRura.P: real;
begin
P:=Next.P;
end;
procedure TRura.Update(dt: real);
begin
Next.Flow(dVol);
dVol:=0;
end;
// ------ PRZECIWPOSLIG ------
procedure TPrzeciwposlizg.SetPoslizg(flag: boolean);
begin
Poslizg:=flag;
end;
procedure TPrzeciwposlizg.Update(dt: real);
begin
if (Poslizg) then
begin
BrakeRes.Flow(dVol);
Next.Flow(PF(Next.P,0,d2A(10))*dt);
end
else
Next.Flow(dVol);
dVol:=0;
end;
// ------ PRZEKLADNIK ------
procedure TPrzekladnik.Update(dt: real);
var BCP, BVP, dV: real;
begin
BCP:=Next.P;
BVP:=BrakeRes.P;
if(BCP>P)then
dV:=-PFVd(BCP,0,d2A(10),P)*dt
else
if(BCP<P)then
dV:=PFVa(BVP,BCP,d2A(10),P)*dt
else dV:=0;
Next.Flow(dV);
if dV>0 then
BrakeRes.Flow(-dV);
end;
// ------ PRZEKLADNIK RAPID ------
procedure TRapid.SetRapidParams(mult: real; size: real);
begin
RapidMult:=mult;
RapidStatus:=false;
if (size>0.1) then //dopasowywanie srednicy przekladnika
begin
DN:=D2A(size*0.4);
DL:=D2A(size*0.4);
end
else
begin
DN:=D2A(5);
DL:=D2A(5);
end;
end;
procedure TRapid.SetRapidStatus(rs: boolean);
begin
RapidStatus:=rs;
end;
procedure TRapid.Update(dt: real);
var BCP, BVP, dV, ActMult: real;
begin
BVP:=BrakeRes.P;
BCP:=Next.P;
if(RapidStatus)then
begin
ActMult:=RapidMult;
end
else
begin
ActMult:=1;
end;
if(BCP*RapidMult>P*actMult)then
dV:=-PFVd(BCP,0,DL,P*actMult/RapidMult)*dt
else
if(BCP*RapidMult<P*ActMult)then
dV:=PFVa(BVP,BCP,DN,P*actMult/RapidMult)*dt
else dV:=0;
Next.Flow(dV);
if dV>0 then
BrakeRes.Flow(-dV);
end;
// ------ PRZEK£ADNIK CI¥G£Y ------
procedure TPrzekCiagly.SetMult(m:real);
begin
Mult:=m;
end;
procedure TPrzekCiagly.Update(dt: real);
var BCP, BVP, dV: real;
begin
BVP:=BrakeRes.P;
BCP:=Next.P;
if(BCP>P*Mult)then
dV:=-PFVd(BCP,0,d2A(8),P*Mult)*dt
else
if(BCP<P*Mult)then
dV:=PFVa(BVP,BCP,d2A(8),P*Mult)*dt
else dV:=0;
Next.Flow(dV);
if dV>0 then
BrakeRes.Flow(-dV);
end;
// ------ PRZEK£ADNIK CI¥G£Y ------
procedure TPrzek_PZZ.SetLBP(P:real);
begin
LBP:=P;
end;
procedure TPrzek_PZZ.Update(dt: real);
var BCP, BVP, dV, Pgr: real;
begin
BVP:=BrakeRes.P;
BCP:=Next.P;
Pgr:=Max0R(LBP,P);
if(BCP>Pgr)then
dV:=-PFVd(BCP,0,d2A(8),Pgr)*dt
else
if(BCP<Pgr)then
dV:=PFVa(BVP,BCP,d2A(8),Pgr)*dt
else dV:=0;
Next.Flow(dV);
if dV>0 then
BrakeRes.Flow(-dV);
end;
// ------ PRZECIWPOSLIG ------
procedure TPrzekED.SetP(P: real);
begin
MaxP:=P;
end;
procedure TPrzekED.Update(dt: real);
begin
if Next.P>MaxP then
begin
BrakeRes.Flow(dVol);
Next.Flow(PFVd(Next.P,0,d2A(10)*dt,MaxP));
end
else
Next.Flow(dVol);
dVol:=0;
end;
// ------ OERLIKON EST NA BOGATO ------
function TNESt3.GetPF(PP, dt, Vel: real): real; //przeplyw miedzy komora wstepna i PG
var dv, dv1, temp:real;
VVP, BVP, BCP, CVP, MPP, nastG: real;
i: byte;
begin
BVP:=BrakeRes.P;
VVP:=ValveRes.P;
// BCP:=BrakeCyl.P;
BCP:=Przekladniki[1].P;
CVP:=CntrlRes.P-0.0;
MPP:=Miedzypoj.P;
dV1:=0;
nastG:=(BrakeDelayFlag and bdelay_G);
//sprawdzanie stanu
CheckState(BCP, dV1);
CheckReleaser(dt);
//luzowanie
if(BrakeStatus and b_hld)=b_off then
dV:=PF(0,BCP,Nozzles[dTO]*nastG+(1-nastG)*Nozzles[dOO])*dt*(0.1+4.9*Min0R(0.2,BCP-((CVP-0.05-VVP)*BVM+0.1)))
else dV:=0;
// BrakeCyl.Flow(-dV);
Przekladniki[1].Flow(-dV);
if((BrakeStatus and b_on)=b_on)and(Przekladniki[1].P*HBG300<MaxBP)then
dV:=PF(BVP,BCP,Nozzles[dTN]*(nastG+2*Byte(BCP<Podskok))+Nozzles[dON]*(1-nastG))*dt*(0.1+4.9*Min0R(0.2,(CVP-0.05-VVP)*BVM-BCP))
else dV:=0;
// BrakeCyl.Flow(-dV);
Przekladniki[1].Flow(-dV);
BrakeRes.Flow(dV);
for i:=1 to 3 do
begin
Przekladniki[i].Update(dt);
if (Przekladniki[i] is TRapid) then
begin
RapidStatus:=(((BrakeDelayFlag and bdelay_R)=bdelay_R) and ((Abs(Vel)>70) or ((RapidStatus) and (Abs(Vel)>50)) or (RapidStaly)));
(Przekladniki[i] as TRapid).SetRapidStatus(RapidStatus);
end
else
if (Przekladniki[i] is TPrzeciwposlizg) then
(Przekladniki[i] as TPrzeciwposlizg).SetPoslizg((BrakeStatus and b_asb)=b_asb)
else
if (Przekladniki[i] is TPrzekED) then
if (Vel<-15) then
(Przekladniki[i] as TPrzekED).SetP(0)
else (Przekladniki[i] as TPrzekED).SetP(MaxBP*3)
else
if (Przekladniki[i] is TPrzekCiagly) then
(Przekladniki[i] as TPrzekCiagly).SetMult(LoadC)
else
if (Przekladniki[i] is TPrzek_PZZ) then
(Przekladniki[i] as TPrzek_PZZ).SetLBP(LBP);
end;
//przeplyw testowy miedzypojemnosci
dV:=PF(MPP,VVP,BVs(BCP))+PF(MPP,CVP,CVs(BCP));
if(MPP-0.05>BVP)then
dV:=dV+PF(MPP-0.05,BVP,Nozzles[dPT]*nastG+(1-nastG)*Nozzles[dPO]);
if MPP>VVP then dV:=dV+PF(MPP,VVP,d2A(5));
Miedzypoj.Flow(dV*dt*0.15);
//przeplyw ZS <-> PG
temp:=CVs(BCP);
dV:=PF(CVP,MPP,temp)*dt;
CntrlRes.Flow(+dV);
ValveRes.Flow(-0.02*dV);
dV1:=dV1+0.98*dV;
//przeplyw ZP <-> MPJ
if(MPP-0.05>BVP)then
dV:=PF(BVP,MPP-0.05,Nozzles[dPT]*nastG+(1-nastG)*Nozzles[dPO])*dt
else dV:=0;
BrakeRes.Flow(dV);
dV1:=dV1+dV*0.98;
ValveRes.Flow(-0.02*dV);
//przeplyw PG <-> rozdzielacz
dV:=PF(PP,VVP,0.005)*dt; //0.01
ValveRes.Flow(-dV);
ValveRes.Act;
BrakeCyl.Act;
BrakeRes.Act;
CntrlRes.Act;
Miedzypoj.Act;
Przekladniki[1].Act;
Przekladniki[2].Act;
Przekladniki[3].Act;
GetPF:=dV-dV1;
end;
procedure TNESt3.EStParams(i_crc: real); //parametry charakterystyczne dla ESt
begin
end;
procedure TNESt3.Init(PP, HPP, LPP, BP: real; BDF: byte);
begin
ValveRes.CreatePress(1*PP);
BrakeCyl.CreatePress(1*BP);
BrakeRes.CreatePress(1*PP);
CntrlRes:=TReservoir.Create;
CntrlRes.CreateCap(15);
CntrlRes.CreatePress(1*HPP);
BrakeStatus:=Byte(BP>1)*1;
Miedzypoj:=TReservoir.Create;
Miedzypoj.CreateCap(5);
Miedzypoj.CreatePress(PP);
BVM:=1/(HPP-0.05-LPP)*MaxBP;
BrakeDelayFlag:=BDF;
Zamykajacy:=false;
if not ((FM is TDisk1) or (FM is TDisk2)) then //jesli zeliwo to schodz
RapidStaly:=false
else
RapidStaly:=true;
end;
function TNESt3.GetCRP: real;
begin
GetCRP:=CntrlRes.P;
// GetCRP:=Przekladniki[1].P;
// GetCRP:=Miedzypoj.P;
end;
procedure TNESt3.CheckState(BCP: real; var dV1: real); //glowny przyrzad rozrzadczy
var VVP, BVP, CVP, MPP: real;
begin
BVP:=BrakeRes.P; //-> tu ma byc komora rozprezna
VVP:=ValveRes.P;
CVP:=CntrlRes.P;
MPP:=Miedzypoj.P;
if(BCP<0.25)and(VVP+0.08>CVP)then Przys_blok:=false;
//sprawdzanie stanu
// if ((BrakeStatus and 1)=1)and(BCP>0.25)then
if(VVP+0.01+BCP/BVM<CVP-0.05)and(Przys_blok)then
BrakeStatus:=(BrakeStatus or 3) //hamowanie stopniowe
else if(VVP-0.01+(BCP-0.1)/BVM>CVP-0.05) then
BrakeStatus:=(BrakeStatus and 252) //luzowanie
else if(VVP+BCP/BVM>CVP-0.05) then
BrakeStatus:=(BrakeStatus and 253) //zatrzymanie napelaniania
else if(VVP+(BCP-0.1)/BVM<CVP-0.05)and(BCP>0.25)then //zatrzymanie luzowania
BrakeStatus:=(BrakeStatus or 1);
if (BrakeStatus and 1)=0 then
SoundFlag:=SoundFlag or sf_CylU;
if(VVP+0.10<CVP)and(BCP<0.25)then //poczatek hamowania
if (not Przys_blok) then
begin
ValveRes.CreatePress(0.1*VVP);
SoundFlag:=SoundFlag or sf_Acc;
ValveRes.Act;
Przys_blok:=true;
end;
if(BCP>0.5)then
Zamykajacy:=true
else if(VVP-0.6<MPP) then
Zamykajacy:=false;
end;
procedure TNESt3.CheckReleaser(dt: real); //odluzniacz
var
VVP, CVP: real;
begin
VVP:=ValveRes.P;
CVP:=CntrlRes.P;
//odluzniacz automatyczny
if(BrakeStatus and b_rls=b_rls)then
begin
CntrlRes.Flow(+PF(CVP,0,0.02)*dt);
if(CVP<VVP+0.3)or(not autom)then
BrakeStatus:=BrakeStatus and 247;
end;
end;
function TNESt3.CVs(bp: real): real; //napelniacz sterujacego
var CVP, MPP: real;
begin
CVP:=CntrlRes.P;
MPP:=Miedzypoj.P;
//przeplyw ZS <-> PG
if(MPP<CVP-0.17)then
CVS:=0
else
if(MPP>CVP-0.08)then
CVs:=Nozzles[dSD]
else
CVs:=Nozzles[dSm];
end;
function TNESt3.BVs(BCP: real): real; //napelniacz pomocniczego
var CVP, MPP: real;
begin
CVP:=CntrlRes.P;
MPP:=Miedzypoj.P;
//przeplyw ZP <-> rozdzielacz
if(MPP<CVP-0.3)then
BVs:=Nozzles[dP]
else
if(BCP<0.5) then
if(Zamykajacy)then
BVs:=Nozzles[dPm] //1.25
else
BVs:=Nozzles[dPD]
else
BVs:=0;
end;
procedure TNESt3.PLC(mass: real);
begin
LoadC:=1+Byte(Mass<LoadM)*((TareBP+(MaxBP-TareBP)*(mass-TareM)/(LoadM-TareM))/MaxBP-1);
end;
procedure TNESt3.ForceEmptiness();
begin
ValveRes.CreatePress(0);
BrakeRes.CreatePress(0);
Miedzypoj.CreatePress(0);
CntrlRes.CreatePress(0);
BrakeStatus:=0;
ValveRes.Act();
BrakeRes.Act();
Miedzypoj.Act();
CntrlRes.Act();
end;
procedure TNESt3.SetLP(TM, LM, TBP: real);
begin
TareM:=TM;
LoadM:=LM;
TareBP:=TBP;
end;
procedure TNESt3.SetLBP(P: real);
begin
LBP:=P;
end;
procedure TNESt3.SetSize(size: integer; params: string); //ustawianie dysz (rozmiaru ZR)
const
dNO1l = 1.250;
dNT1l = 0.510;
dOO1l = 0.907;
dOT1l = 0.524;
var
i:integer;
begin
if Pos('ESt3',params)>0 then
begin
Podskok:=0.7;
Przekladniki[1]:=TRura.Create;
Przekladniki[3]:=TRura.Create;
end
else
begin
Podskok:=-1;
Przekladniki[1]:=TRapid.Create;
if Pos('-s216',params)>0 then
(Przekladniki[1] as TRapid).SetRapidParams(2,16)
else
(Przekladniki[1] as TRapid).SetRapidParams(2,0);
Przekladniki[3]:=TPrzeciwposlizg.Create;
if Pos('-ED',params)>0 then
begin
Przekladniki[3].Free();
(Przekladniki[1] as TRapid).SetRapidParams(2,18);
Przekladniki[3]:=TPrzekED.Create;
end;
end;
if Pos('AL2',params)>0 then
Przekladniki[2]:=TPrzekCiagly.Create
else
if Pos('PZZ',params)>0 then
Przekladniki[2]:=TPrzek_PZZ.Create
else
Przekladniki[2]:=TRura.Create;
if (Pos('3d',params)+Pos('4d',params)>0) then autom:=false else autom:=true;
if (Pos('HBG300',params)>0) then HBG300:=1 else HBG300:=0;
case size of
16:
begin //dON,dOO,dTN,dTO,dP,dS
Nozzles[dON]:=5.0;//5.0;
Nozzles[dOO]:=3.4;//3.4;
Nozzles[dTN]:=2.0;
Nozzles[dTO]:=1.75;
Nozzles[dP]:=3.8;
Nozzles[dPd]:=2.70;
Nozzles[dPm]:=1.25;
Nozzles[dPO]:=Nozzles[dON];
Nozzles[dPT]:=Nozzles[dTN];
end;
14:
begin //dON,dOO,dTN,dTO,dP,dS
Nozzles[dON]:=4.3;
Nozzles[dOO]:=2.85;
Nozzles[dTN]:=1.83;
Nozzles[dTO]:=1.57;
Nozzles[dP]:=3.4;
Nozzles[dPd]:=2.20;
Nozzles[dPm]:=1.10;
Nozzles[dPO]:=Nozzles[dON];
Nozzles[dPT]:=Nozzles[dTN];
end;
12:
begin //dON,dOO,dTN,dTO,dP,dS
Nozzles[dON]:=3.7;
Nozzles[dOO]:=2.50;
Nozzles[dTN]:=1.65;
Nozzles[dTO]:=1.39;
Nozzles[dP]:=2.65;
Nozzles[dPd]:=1.80;
Nozzles[dPm]:=0.85;
Nozzles[dPO]:=Nozzles[dON];
Nozzles[dPT]:=Nozzles[dTN];
end;
10:
begin //dON,dOO,dTN,dTO,dP,dS
Nozzles[dON]:=3.1;
Nozzles[dOO]:=2.0;
Nozzles[dTN]:=1.35;
Nozzles[dTO]:=1.13;
Nozzles[dP]:=1.6;
Nozzles[dPd]:=1.55;
Nozzles[dPm]:=0.7;
Nozzles[dPO]:=Nozzles[dON];
Nozzles[dPT]:=Nozzles[dTN];
end;
200:
begin //dON,dOO,dTN,dTO,dP,dS
Nozzles[dON]:=dNO1l;
Nozzles[dOO]:=dOO1l/1.15;
Nozzles[dTN]:=dNT1l;
Nozzles[dTO]:=dOT1l;
Nozzles[dP]:=7.4;
Nozzles[dPd]:=5.3;
Nozzles[dPm]:=2.5;
Nozzles[dPO]:=7.28;
Nozzles[dPT]:=2.96;
end;
375:
begin //dON,dOO,dTN,dTO,dP,dS
Nozzles[dON]:=dNO1l;
Nozzles[dOO]:=dOO1l/1.15;
Nozzles[dTN]:=dNT1l;
Nozzles[dTO]:=dOT1l;
Nozzles[dP]:=13.0;
Nozzles[dPd]:=9.6;
Nozzles[dPm]:=4.4;
Nozzles[dPO]:=9.92;
Nozzles[dPT]:=3.99;
end;
150:
begin //dON,dOO,dTN,dTO,dP,dS
Nozzles[dON]:=dNO1l;
Nozzles[dOO]:=dOO1l;
Nozzles[dTN]:=dNT1l;
Nozzles[dTO]:=dOT1l;
Nozzles[dP]:=5.8;
Nozzles[dPd]:=4.1;
Nozzles[dPm]:=1.9;
Nozzles[dPO]:=6.33;
Nozzles[dPT]:=2.58;
end;
100:
begin //dON,dOO,dTN,dTO,dP,dS
Nozzles[dON]:=dNO1l;
Nozzles[dOO]:=dOO1l;
Nozzles[dTN]:=dNT1l;
Nozzles[dTO]:=dOT1l;
Nozzles[dP]:=4.2;
Nozzles[dPd]:=2.9;
Nozzles[dPm]:=1.4;
Nozzles[dPO]:=5.19;
Nozzles[dPT]:=2.14;
end;
else
begin
Nozzles[dON]:=0;
Nozzles[dOO]:=0;
Nozzles[dTN]:=0;
Nozzles[dTO]:=0;
Nozzles[dP]:=0;
Nozzles[dPd]:=0;
Nozzles[dPm]:=0;
end;
end;
Nozzles[dSd]:=1.1;
Nozzles[dSm]:=0.9;
//przeliczanie z mm^2 na l/m
for i:=0 to dMAX do
begin
Nozzles[i]:=d2A(Nozzles[i]); //(/1000^2*pi/4*1000)
end;
for i:=1 to 3 do
begin
Przekladniki[i].BrakeRes:=@BrakeRes;
Przekladniki[i].CreateCap(i);
Przekladniki[i].CreatePress(BrakeCyl.P);
if i<3 then
Przekladniki[i].Next:=@Przekladniki[i+1]
else
Przekladniki[i].Next:=@BrakeCyl;
end
end;
end.

151
old/QueryParserComp.hpp Normal file
View File

@@ -0,0 +1,151 @@
// Borland C++ Builder
// Copyright (c) 1995, 1999 by Borland International
// All rights reserved
// (DO NOT EDIT: machine generated header) 'QueryParserComp.pas' rev: 5.00
#ifndef QueryParserCompHPP
#define QueryParserCompHPP
#pragma delphiheader begin
#pragma option push -w-
#pragma option push -Vx
#include <SysUtils.hpp> // Pascal unit
#include <Classes.hpp> // Pascal unit
#include <SysInit.hpp> // Pascal unit
#include <System.hpp> // Pascal unit
//-- user supplied -----------------------------------------------------------
namespace Queryparsercomp
{
//-- type declarations -------------------------------------------------------
#pragma option push -b-
enum TTokenType { ttString, ttSymbol, ttComment, ttDelimiter, ttSpecialChar, ttStatementDelimiter, ttCommentedSymbol,
ttCommentDelimiter };
#pragma option pop
typedef Set<char, 0, 255> TSetOfChar;
typedef AnsiString TComment[2];
#pragma option push -b-
enum TCharacterType { ctSymbol, ctBeginComment, ctEndComment, ctDelimiter, ctString, ctSpecialChar }
;
#pragma option pop
#pragma option push -b-
enum QueryParserComp__1 { cmt1, cmt2, cmt3 };
#pragma option pop
typedef Set<QueryParserComp__1, cmt1, cmt3> TCommentType;
typedef AnsiString QueryParserComp__2[3][2];
typedef void __fastcall (__closure *TEndOfStatement)(System::TObject* Sender, AnsiString SQLStatement
);
class DELPHICLASS TQueryParserComp;
class PASCALIMPLEMENTATION TQueryParserComp : public Classes::TComponent
{
typedef Classes::TComponent inherited;
private:
Classes::TStringStream* FStream;
bool FEOF;
AnsiString FToken;
TTokenType FTokenType;
bool FComment;
bool FString;
bool FWasString;
TCommentType FCommentType;
AnsiString FStringDelimiters;
AnsiString FLastStringDelimiterFound;
int FSymbolsCount;
AnsiString FSpecialCharacters;
bool FRemoveStrDelimiter;
AnsiString FStringToParse;
int FGoPosition;
TEndOfStatement FOnStatementDelimiter;
bool FCountFromStatement;
Classes::TStringList* FStatementDelimiters;
char FStringDelimiter;
bool FGenerateOnStmtDelimiter;
void __fastcall Init(void);
void __fastcall SetStringToParse(AnsiString AStringToParse);
bool __fastcall StatementDelimiter(void);
bool __fastcall CheckForBeginComment(void);
bool __fastcall CheckForEndComment(char Character);
TCharacterType __fastcall CharacterType(char Character);
bool __fastcall CheckCharcterType(char Character);
bool __fastcall StringDelimiter(char Character);
bool __fastcall SpecialCharacter(char Character);
void __fastcall RemoveStringDelimiter(AnsiString &Source);
void __fastcall SetDelimiterType(AnsiString Source);
void __fastcall SetToken(void);
void __fastcall SetSD(Classes::TStringList* ASD);
void __fastcall SetSpecialCharacters(AnsiString ASpecialCharacters);
void __fastcall SetStringDelimiters(AnsiString AStringDelimiters);
protected:
DYNAMIC void __fastcall DoStatementDelimiter(void);
public:
__fastcall virtual TQueryParserComp(Classes::TComponent* AOwner);
__fastcall virtual ~TQueryParserComp(void);
void __fastcall LoadStringToParse(AnsiString FileName);
void __fastcall First(void);
void __fastcall FirstToken(void);
void __fastcall NextToken(void);
AnsiString __fastcall GetNextSymbol();
__property bool EndOfFile = {read=FEOF, nodefault};
__property bool Comment = {read=FComment, nodefault};
__property AnsiString Token = {read=FToken};
__property TTokenType TokenType = {read=FTokenType, nodefault};
__property char CurrentStringDelimiter = {read=FStringDelimiter, nodefault};
__property int SymbolsCount = {read=FSymbolsCount, default=0};
__property Classes::TStringStream* StringStream = {read=FStream};
__published:
__property bool IsEOFStmtDelimiter = {read=FGenerateOnStmtDelimiter, write=FGenerateOnStmtDelimiter
, nodefault};
__property AnsiString StringDelimiters = {read=FStringDelimiters, write=SetStringDelimiters};
__property AnsiString SpecialCharacters = {read=FSpecialCharacters, write=SetSpecialCharacters};
__property bool RemoveStrDelimiter = {read=FRemoveStrDelimiter, write=FRemoveStrDelimiter, nodefault
};
__property bool CountFromStatement = {read=FCountFromStatement, write=FCountFromStatement, nodefault
};
__property AnsiString TextToParse = {read=FStringToParse, write=SetStringToParse};
__property Classes::TStringList* StatementDelimiters = {read=FStatementDelimiters, write=SetSD};
__property TEndOfStatement OnStatementDelimiter = {read=FOnStatementDelimiter, write=FOnStatementDelimiter
};
};
//-- var, const, procedure ---------------------------------------------------
extern PACKAGE System::ResourceString _sTextNotSet;
#define Queryparsercomp_sTextNotSet System::LoadResourceString(&Queryparsercomp::_sTextNotSet)
extern PACKAGE System::ResourceString _sIllegalSpecialChar;
#define Queryparsercomp_sIllegalSpecialChar System::LoadResourceString(&Queryparsercomp::_sIllegalSpecialChar)
extern PACKAGE System::ResourceString _sIllegalStringChar;
#define Queryparsercomp_sIllegalStringChar System::LoadResourceString(&Queryparsercomp::_sIllegalStringChar)
static const char CR = '\xd';
static const char LF = '\xa';
static const char TAB = '\x9';
#define CRLF "\r\n"
extern PACKAGE TSetOfChar Delimiters;
extern PACKAGE AnsiString Comments[3][2];
extern PACKAGE void __fastcall Register(void);
} /* namespace Queryparsercomp */
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Queryparsercomp;
#endif
#pragma option pop // -w-
#pragma option pop // -Vx
#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif // QueryParserComp

733
old/QueryParserComp.pas Normal file
View File

@@ -0,0 +1,733 @@
unit QueryParserComp;
(*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*)
interface
uses
Classes, Sysutils;
resourcestring
sTextNotSet = 'You must set the TextToParse property first.';
sIllegalSpecialChar = 'Illegal special character.';
sIllegalStringChar = 'Illegal string delimiter.';
type
TTokenType = (ttString, ttSymbol, ttComment, ttDelimiter, ttSpecialChar,
ttStatementDelimiter, ttCommentedSymbol, ttCommentDelimiter);
TSetOfChar = set of Char;
TComment = array[0..1] of string;
TCharacterType = (ctSymbol, ctBeginComment, ctEndComment, ctDelimiter,
ctString, ctSpecialChar);
TCommentType = set of (cmt1, cmt2, cmt3);
const
CR = #13;
LF = #10;
TAB = #9;
CRLF = CR + LF;
Delimiters: TSetOfChar = [' ', ',', ';', CR, LF, TAB];
Comments: array[0..2] of TComment = (('/*', '*/'), ('#', LF), ('//', LF));
type
TEndOfStatement = procedure(Sender: TObject; SQLStatement: String) of object;
TQueryParserComp = class(TComponent)
private
FStream: TStringStream;
FEOF: Boolean;
FToken: String;
FTokenType: TTokenType;
FComment: Boolean;
FString: Boolean;
FWasString: Boolean;
FCommentType: TCommentType;
FStringDelimiters: String;
FLastStringDelimiterFound: String;
FSymbolsCount: Integer;
FSpecialCharacters: String;
FRemoveStrDelimiter: Boolean;
FStringToParse: String;
FGoPosition: Integer;
FOnStatementDelimiter: TEndOfStatement;
FCountFromStatement: Boolean;
FStatementDelimiters: TStringList;
FStringDelimiter: Char;
FGenerateOnStmtDelimiter: Boolean;
procedure Init;
procedure SetStringToParse(AStringToParse: String);
function StatementDelimiter: Boolean;
function CheckForBeginComment: Boolean;
function CheckForEndComment(Character: Char): Boolean;
function CharacterType(Character: Char): TCharacterType;
function CheckCharcterType(Character: Char): Boolean;
function StringDelimiter(Character: Char): Boolean;
function SpecialCharacter(Character: Char): Boolean;
procedure RemoveStringDelimiter(var Source: String);
procedure SetDelimiterType(Source: String);
procedure SetToken;
procedure SetSD(ASD: TStringList);
procedure SetSpecialCharacters(ASpecialCharacters: String);
procedure SetStringDelimiters(AStringDelimiters: String);
protected
procedure DoStatementDelimiter; dynamic;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure LoadStringToParse(FileName: string);
procedure First;
procedure FirstToken;
procedure NextToken;
function GetNextSymbol : string;
property EndOfFile: Boolean read FEOF;
property Comment: Boolean read FComment;
property Token: String read FToken;
property TokenType: TTokenType read FTokenType;
property CurrentStringDelimiter: Char read FStringDelimiter;
property SymbolsCount: Integer read FSymbolsCount default 0;
property StringStream: TStringStream read FStream;
published
property IsEOFStmtDelimiter: Boolean read FGenerateOnStmtDelimiter
write FGenerateOnStmtDelimiter;
property StringDelimiters: String read FStringDelimiters
write SetStringDelimiters;
property SpecialCharacters: String read FSpecialCharacters
write SetSpecialCharacters;
property RemoveStrDelimiter: Boolean read FRemoveStrDelimiter
write FRemoveStrDelimiter;
property CountFromStatement: Boolean read FCountFromStatement
write FCountFromStatement;
property TextToParse: String read FStringToParse
write SetStringToParse;
property StatementDelimiters: TStringList read FStatementDelimiters write SetSD;
property OnStatementDelimiter: TEndOfStatement read FOnStatementDelimiter
write FOnStatementDelimiter;
end;
procedure Register;
implementation
{ TSQLParser }
procedure Register;
begin
RegisterComponents('Samples', [TQueryParserComp]);
end;
constructor TQueryParserComp.Create(AOwner: TComponent);
begin
inherited;
FStatementDelimiters := TStringList.Create;
FStatementDelimiters.Add('GO');
FStatementDelimiters.Add(';');
FCountFromStatement := True;
end;
procedure TQueryParserComp.LoadStringToParse(FileName: string);
var
fs:TFileStream;
size:integer;
begin
fs:= TFileStream.Create(FileName, fmOpenRead);
size:= fs.Size;
if Assigned(FStream) then
FStream.Free;
FStream := TStringStream.Create('');
FStream.CopyFrom(fs,size);
fs.Free;
Init;
First;
end;
procedure TQueryParserComp.FirstToken;
begin
Init;
NextToken;
end;
function TQueryParserComp.CheckForBeginComment: Boolean;
var
Buffer: String;
begin
Result := False;
if not FEOF and not FString then
begin
Buffer := FStream.ReadString(1);
if cmt1 in FCommentType then
if Buffer[1] = '*' then
begin
FCommentType := [cmt1];
Result := True;
end;
if cmt2 in FCommentType then
if Buffer[1] = '/' then
begin
FCommentType := [cmt2];
Result := True;
end;
if cmt3 in FCommentType then
if Buffer[1] = '-' then
begin
FCommentType := [cmt3];
Result := True;
end;
FStream.Seek(-1, soFromCurrent);
end;
end;
procedure TQueryParserComp.SetDelimiterType(Source: String);
begin
FToken := Source[1];
if ((cmt2 in FCommentType) or (cmt3 in FCommentType)) and FComment
and ((Source[1] = CR) or (Source[1] = LF)) then
begin
FComment := False;
FTokenType := ttCommentDelimiter;
end
else
FTokenType := ttDelimiter;
end;
procedure TQueryParserComp.NextToken;
var
Buffer: String;
ETextNotSet: Exception;
begin
if FEOF then
Exit;
if not Assigned(FStream) then
begin
ETextNotSet := Exception.Create(sTextNotSet);
raise ETextNotSet;
end;
if not FString then
FStringDelimiter := ' ';
FToken := '';
if not FEOF then
begin
Buffer := FStream.ReadString(1);
if Length(Buffer) > 0 then
begin
if (Buffer[1] in Delimiters) and not (FString or FComment)then
SetDelimiterType(Buffer)
else
begin
if FStream.Position > 0 then
FStream.Seek(-1, soFromCurrent);
SetToken;
end;
end
else
FEOF := True;
end;
case FTokenType of
ttSymbol: Inc(FSymbolsCount);
ttString:
begin
FStringDelimiter := FToken[1];
if FRemoveStrDelimiter then
RemoveStringDelimiter(FToken);
end;
end;
if StatementDelimiter then
FTokenType := ttStatementDelimiter;
if FEOF then
begin
FLastStringDelimiterFound := '';
FWasString := False;
FString := False;
if FGenerateOnStmtDelimiter then
DoStatementDelimiter;
end;
end;
function TQueryParserComp.GetNextSymbol : string;
begin
GetNextSymbol:= '';
while ( not EndOfFile) do
begin
NextToken;
if (TokenType=ttSymbol) then
begin
GetNextSymbol:= Token;
break;
end
end
end;
function TQueryParserComp.StatementDelimiter: Boolean;
var
i: Integer;
begin
Result := False;
if not FString then
for i := 0 to FStatementDelimiters.Count - 1 do
begin
Result := (UpperCase(FToken) = UpperCase(FStatementDelimiters.Strings[i]));
if Result then
begin
if FCountFromStatement then
FSymbolsCount := 0;
DoStatementDelimiter;
Break;
end;
end;
end;
function TQueryParserComp.CharacterType(Character: Char): TCharacterType;
begin
Result := ctSymbol;
case Character of
'/':
begin
if not FComment then
begin
FCommentType := [cmt1, cmt2];
if CheckForBeginComment then
Result := ctBeginComment;
end;
end;
'-':
begin
if not FComment then
begin
FCommentType := [cmt3];
if CheckForBeginComment then
Result := ctBeginComment;
end;
end;
'*':
begin
if CheckForEndComment(Character) then
Result := ctEndComment;
end;
CR, LF, ' ', ',', TAB:
begin
if CheckForEndComment(Character) then
Result := ctEndComment
else
Result := ctDelimiter;
if FString and ((Character = CR) or (Character = LF)) then
begin
FString := False;
FWasString := False;
Result := ctDelimiter;
end;
end;
end;
if not FString then
if SpecialCharacter(Character) then
begin
if not FComment then
Result := ctSpecialChar;
end;
if not FComment then
if StringDelimiter(Character) then
begin
Result := ctSymbol;
if FString then
begin
FLastStringDelimiterFound := '';
FWasString := True;
FString := False;
end
else
begin
FWasString := False;
FString := True;
end;
end;
end;
function TQueryParserComp.CheckForEndComment(Character: Char): Boolean;
var
Buffer: String;
begin
Result := False;
if not FComment or FString then
Exit;
if not FEOF then
begin
if cmt1 in FCommentType then
begin
Buffer := FStream.ReadString(1);
if Buffer[1] = '/' then
Result := True;
FStream.Seek(-1, soFromCurrent);
end;
if (cmt2 in FCommentType) or (cmt3 in FCommentType) then
begin
if (Character = CR) or (Character = LF) then
Result := True;
end;
end;
end;
function TQueryParserComp.CheckCharcterType(Character: Char): Boolean;
var
Buffer: String;
begin
Result := False;
case CharacterType(Character) of
ctBeginComment:
begin
if not FComment then
begin
if FToken <> '' then
begin
FStream.Seek(-1, soFromCurrent);
FTokenType := ttSymbol;
end
else
begin
FComment := True;
FToken := FToken + Character;
Buffer := FStream.ReadString(1);
FToken := FToken + Buffer;
FTokenType := ttComment;
end;
Result := True;
end;
end;
ctEndComment:
begin
if FComment then
begin
Result := True;
if FToken <> '' then
begin
FStream.Seek(-1, soFromCurrent);
FTokenType := ttCommentedSymbol;
end
else
begin
FComment := False;
FToken := FToken + Character;
if FCommentType = [cmt1] then
begin
Buffer := FStream.ReadString(1);
FToken := FToken + Buffer;
end;
FTokenType := ttComment;
end;
end;
end;
ctSymbol:
begin
FToken := FToken + Character;
if FComment then
FTokenType := ttCommentedSymbol
else
begin
if FString or FWasString then
begin
if FWasString then
begin
FTokenType := ttString;
FWasString := False;
Result := True;
end
else
FTokenType := ttString;
end
else
FTokenType := ttSymbol;
end;
end;
ctSpecialChar:
begin
if FToken <> '' then
begin
FStream.Seek(-1, soFromCurrent);
FTokenType := ttSymbol;
end
else
begin
FToken := FToken + Character;
FTokenType := ttSpecialChar;
end;
Result := True;
end;
ctDelimiter:
begin
FTokenType := ttDelimiter;
Result := True;
end;
end
end;
procedure TQueryParserComp.RemoveStringDelimiter(var Source: String);
var
EndOfString: Integer;
i: Integer;
begin
for i := 1 to Length(FStringDelimiters) do
begin
EndOfString := 1;
while not (EndOfString = 0) do
begin
EndOfString := Pos(FStringDelimiters[i], Source);
if EndOfString <> 0 then
begin
FLastStringDelimiterFound := Copy(FStringDelimiters, i, 1);
Delete(Source, EndOfString, 1);
end;
end;
end;
end;
function TQueryParserComp.StringDelimiter(Character: Char): Boolean;
var
i: Integer;
Buffer: String;
begin
Result := False;
for i := 1 to Length(FStringDelimiters) do
if (Character = FStringDelimiters[i]) then
begin
if (FLastStringDelimiterFound = '') then
FLastStringDelimiterFound := FStringDelimiters[i];
if (FLastStringDelimiterFound = FStringDelimiters[i]) then
begin
if not FEOF then
Buffer := FStream.ReadString(1);
if Length(Buffer) > 0 then
begin
if Buffer[1] <> Character then
begin
FStream.Seek(-1, soFromCurrent);
Result := True;
end
else
FToken := FToken + Buffer;
end
else
Result := True;
end;
end;
end;
function TQueryParserComp.SpecialCharacter(Character: Char): Boolean;
var
i: Integer;
begin
Result := False;
for i := 1 to Length(FSpecialCharacters) do
if Character = FSpecialCharacters[i] then
Result := True;
end;
procedure TQueryParserComp.SetToken;
var
EndToken: Boolean;
Buffer: String;
begin
EndToken := False;
while not (EndToken or FEOF) do
begin
FEOF := FStream.Position >= FStream.Size-1;
Buffer := FStream.ReadString(1);
if not (Buffer[1] in Delimiters) then
EndToken := CheckCharcterType(Buffer[1])
else
begin
if not (FString or FComment) then
begin
EndToken := True;
FStream.Seek(-1, soFromCurrent);
end
else
begin
if FString and ((Buffer[1] = CR) or (Buffer[1] = LF)) then
begin
FString := False;
FWasString := False;
EndToken := True;
end
else
if FComment and ((cmt2 in FCommentType) or
(cmt3 in FCommentType)) and ((Buffer[1] = CR) or
(Buffer[1] = LF)) then
begin
EndToken := True;
FStream.Seek(-1, soFromCurrent);
FComment := False;
FCommentType := [];
end
else
FToken := FToken + Buffer;
end;
end;
end; //while
end;
destructor TQueryParserComp.Destroy;
begin
if Assigned(FStream) then
FStream.Free;
inherited Destroy;
end;
procedure TQueryParserComp.DoStatementDelimiter;
var
Buffer: String;
CurrentPosition: Integer;
begin
if Assigned(FOnStatementDelimiter) then
begin
CurrentPosition := FStream.Position;
FStream.Seek(FGoPosition, soFromBeginning);
Buffer := FStream.ReadString(CurrentPosition-FGoPosition-Length(FToken));
FStream.Seek(Length(FToken), soFromCurrent);
if FStream.Position >= FStream.Size then
FEOF := True;
FGoPosition := FStream.Position;
if FCountFromStatement then
FSymbolsCount := 0;
FOnStatementDelimiter(Self, Trim(Buffer));
end;
end;
procedure TQueryParserComp.SetStringToParse(AStringToParse: String);
begin
if AStringToParse = '' then
Exit;
if Assigned(FStream) then
FStream.Free;
TrimRight(AStringToParse);
FStream := TStringStream.Create(AStringToParse);
FStringToParse := AStringToParse;
Init;
end;
procedure TQueryParserComp.SetSD(ASD: TStringList);
begin
FStatementDelimiters.Assign(ASD);
end;
procedure TQueryParserComp.First;
begin
Init;
end;
procedure TQueryParserComp.Init;
var
ETextNotSet: Exception;
begin
if not Assigned(FStream) then
begin
ETextNotSet := Exception.Create(sTextNotSet);
raise ETextNotSet;
end;
FStream.Seek(0, soFromBeginning);
FToken := '';
FTokenType := ttString;
FComment := False;
FCommentType := [];
FEOF := False;
FSymbolsCount := 0;
FGoPosition := 0;
FLastStringDelimiterFound := '';
FWasString := False;
FString := False;
end;
procedure TQueryParserComp.SetSpecialCharacters(ASpecialCharacters: String);
var
i: Integer;
k: Integer;
IllegalSpecialChar: Exception;
begin
for i := 1 to Length(ASpecialCharacters) do
begin
for k := 0 to FStatementDelimiters.Count - 1 do
begin
if (Pos(ASpecialCharacters[i], FStatementDelimiters.Strings[k]) <> 0) then
begin
IllegalSpecialChar := Exception.Create(sIllegalSpecialChar);
raise IllegalSpecialChar;
end;
end;
if (ASpecialCharacters[i] in Delimiters) or
(Pos(ASpecialCharacters[i], FStringDelimiters) <> 0) then
begin
IllegalSpecialChar := Exception.Create(sIllegalSpecialChar);
raise IllegalSpecialChar;
end;
end;
FSpecialCharacters := ASpecialCharacters;
end;
procedure TQueryParserComp.SetStringDelimiters(AStringDelimiters: String);
var
i: Integer;
k: Integer;
IllegalStringChar: Exception;
begin
for i := 1 to Length(AStringDelimiters) do
begin
for k := 0 to FStatementDelimiters.Count - 1 do
begin
if (Pos(AStringDelimiters[i], FStatementDelimiters.Strings[k]) <> 0) then
begin
IllegalStringChar := Exception.Create(sIllegalStringChar);
raise IllegalStringChar;
end;
end;
if (AStringDelimiters[i] in Delimiters) or
(Pos(AStringDelimiters[i], FSpecialCharacters) <> 0) then
begin
IllegalStringChar := Exception.Create(sIllegalStringChar);
raise IllegalStringChar;
end;
end;
FStringDelimiters := AStringDelimiters;
end;
end.

260
old/RealSound.cpp Normal file
View File

@@ -0,0 +1,260 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
/*
MaSzyna EU07 locomotive simulator
Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others
*/
#include "stdafx.h"
#include "RealSound.h"
#include "Globals.h"
#include "Logs.h"
//#include "math.h"
#include "Timer.h"
#include "mczapkie/mctools.h"
#include "usefull.h"
TRealSound::TRealSound(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod, double rmin)
{
Init(SoundName, SoundAttenuation, X, Y, Z, Dynamic, freqmod, rmin);
}
TRealSound::~TRealSound()
{
// if (this) if (pSound) pSound->Stop();
}
void TRealSound::Init(std::string const &SoundName, double DistanceAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod, double rmin)
{
// Nazwa=SoundName; //to tak raczej nie zadziała, (SoundName) jest tymczasowe
pSound = TSoundsManager::GetFromName(SoundName, Dynamic, &fFrequency);
if (pSound)
{
if (freqmod)
if (fFrequency != 22050.0)
{ // dla modulowanych nie może być zmiany mnożnika, bo częstotliwość w nagłówku byłą
// ignorowana, a mogła być inna niż 22050
fFrequency = 22050.0;
ErrorLog("Bad sound: " + SoundName + ", as modulated, should have 22.05kHz in header");
}
AM = 1.0;
pSound->SetVolume(DSBVOLUME_MIN);
}
else
{ // nie ma dźwięku, to jest wysyp
AM = 0;
ErrorLog("Missed sound: " + SoundName);
}
if (DistanceAttenuation > 0.0)
{
dSoundAtt = DistanceAttenuation * DistanceAttenuation;
vSoundPosition.x = X;
vSoundPosition.y = Y;
vSoundPosition.z = Z;
if (rmin < 0)
iDoppler = 1; // wyłączenie efektu Dopplera, np. dla dźwięku ptaków
}
else
dSoundAtt = -1;
};
double TRealSound::ListenerDistance( Math3D::vector3 ListenerPosition)
{
if (dSoundAtt == -1)
{
return 0.0;
}
else
{
return SquareMagnitude(ListenerPosition - vSoundPosition);
}
}
void TRealSound::Play(double Volume, int Looping, bool ListenerInside, Math3D::vector3 NewPosition)
{
if (!pSound)
return;
long int vol;
double dS = 0.0;
// double Distance;
DWORD stat;
if ((Global::bSoundEnabled) && (AM != 0))
{
if (Volume > 1.0)
Volume = 1.0;
fPreviousDistance = fDistance;
fDistance = 0.0; //??
if (dSoundAtt > 0.0)
{
vSoundPosition = NewPosition;
dS = dSoundAtt; //*dSoundAtt; //bo odleglosc podawana w kwadracie
fDistance = ListenerDistance(Global::pCameraPosition);
if (ListenerInside) // osłabianie dźwięków z odległością
Volume = Volume * dS / (dS + fDistance);
else
Volume = Volume * dS / (dS + 2 * fDistance); // podwójne dla ListenerInside=false
}
if (iDoppler) //
{ // Ra 2014-07: efekt Dopplera nie zawsze jest wskazany
// if (FreeFlyModeFlag) //gdy swobodne latanie - nie sprawdza się to
fPreviousDistance = fDistance; // to efektu Dopplera nie będzie
}
if (Looping) // dźwięk zapętlony można wyłączyć i zostanie włączony w miarę potrzeby
bLoopPlay = true; // dźwięk wyłączony
// McZapkie-010302 - babranie tylko z niezbyt odleglymi dźwiękami
if ((dSoundAtt == -1) || (fDistance < 20.0 * dS))
{
// vol=2*Volume+1;
// if (vol<1) vol=1;
// vol=10000*(log(vol)-1);
// vol=10000*(vol-1);
// int glos=1;
// Volume=Volume*glos; //Ra: whatta hella is this
if (Volume < 0.0)
Volume = 0.0;
vol = -5000.0 + 5000.0 * Volume;
if (vol >= 0)
vol = -1;
if (Timer::GetSoundTimer() || !Looping) // Ra: po co to jest?
pSound->SetVolume(vol); // Attenuation, in hundredths of a decibel (dB).
pSound->GetStatus(&stat);
if (!(stat & DSBSTATUS_PLAYING))
pSound->Play(0, 0, Looping);
}
else // wylacz dzwiek bo daleko
{ // Ra 2014-09: oddalanie się nie może być powodem do wyłączenie dźwięku
/*
// Ra: stara wersja, ale podobno lepsza
pSound->GetStatus(&stat);
if (bLoopPlay) //jeśli zapętlony, to zostanie ponownie włączony, o ile znajdzie się
bliżej
if (stat&DSBSTATUS_PLAYING)
pSound->Stop();
// Ra: wyłączyłem, bo podobno jest gorzej niż wcześniej
//ZiomalCl: dźwięk po wyłączeniu sam się nie włączy, gdy wrócimy w rejon odtwarzania
pSound->SetVolume(DSBVOLUME_MIN); //dlatego lepiej go wyciszyć na czas oddalenia się
pSound->GetStatus(&stat);
if (!(stat&DSBSTATUS_PLAYING))
pSound->Play(0,0,Looping); //ZiomalCl: włączenie odtwarzania rownież i tu, gdyż
jesli uruchamiamy dźwięk poza promieniem, nie uruchomi się on w ogóle
*/
}
}
};
void TRealSound::Stop()
{
DWORD stat;
if (pSound)
if ((Global::bSoundEnabled) && (AM != 0))
{
bLoopPlay = false; // dźwięk wyłączony
pSound->GetStatus(&stat);
if (stat & DSBSTATUS_PLAYING)
pSound->Stop();
}
};
void TRealSound::AdjFreq(double Freq, double dt) // McZapkie TODO: dorobic tu efekt Dopplera
// Freq moze byc liczba dodatnia mniejsza od 1 lub wieksza od 1
{
float df, Vlist;
if ((Global::bSoundEnabled) && (AM != 0) && (pSound != nullptr))
{
if (dt > 0)
// efekt Dopplera
{
Vlist = (sqrt(fPreviousDistance) - sqrt(fDistance)) / dt;
df = Freq * (1 + Vlist / 299.8);
}
else
df = Freq;
if (Timer::GetSoundTimer())
{
df = fFrequency * df; // TODO - brac czestotliwosc probkowania z wav
pSound->SetFrequency( clamp( df, static_cast<float>(DSBFREQUENCY_MIN), static_cast<float>(DSBFREQUENCY_MAX) ) );
}
}
}
double TRealSound::GetWaveTime() // McZapkie: na razie tylko dla 22KHz/8bps
{ // używana do pomiaru czasu dla dźwięków z początkiem i końcem
if (!pSound)
return 0.0;
double WaveTime;
DSBCAPS caps;
caps.dwSize = sizeof(caps);
pSound->GetCaps(&caps);
WaveTime = caps.dwBufferBytes;
return WaveTime /
fFrequency; //(pSound->); // wielkosc w bajtach przez czestotliwosc probkowania
}
void TRealSound::SetPan(int Pan)
{
pSound->SetPan(Pan);
}
int TRealSound::GetStatus()
{
DWORD stat;
if ((Global::bSoundEnabled) && (AM != 0))
{
pSound->GetStatus(&stat);
return stat;
}
else
return 0;
}
void TRealSound::ResetPosition()
{
if (pSound) // Ra: znowu jakiś badziew!
pSound->SetCurrentPosition(0);
}
TTextSound::TTextSound(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod, double rmin) :
TRealSound(SoundName, SoundAttenuation, X, Y, Z, Dynamic, freqmod, rmin)
{
Init(SoundName, SoundAttenuation, X, Y, Z, Dynamic, freqmod, rmin);
}
void TTextSound::Init(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod, double rmin)
{ // dodatkowo doczytuje plik tekstowy
fTime = GetWaveTime();
std::string txt(SoundName);
txt.erase( txt.rfind( '.' ) ); // obcięcie rozszerzenia
for (size_t i = txt.length(); i > 0; --i)
if (txt[i] == '/')
txt[i] = '\\'; // bo nie rozumi
txt += "-" + Global::asLang + ".txt"; // już może być w różnych językach
if (!FileExists(txt))
txt = "sounds\\" + txt; //ścieżka może nie być podana
if (FileExists(txt))
{ // wczytanie
std::ifstream inputfile( txt );
asText.assign( std::istreambuf_iterator<char>( inputfile ), std::istreambuf_iterator<char>() );
}
};
void TTextSound::Play(double Volume, int Looping, bool ListenerInside, Math3D::vector3 NewPosition)
{
if (false == asText.empty())
{ // jeśli ma powiązany tekst
DWORD stat;
pSound->GetStatus(&stat);
if (!(stat & DSBSTATUS_PLAYING)) {
// jeśli nie jest aktualnie odgrywany
Global::tranTexts.Add( asText, fTime, true );
}
}
TRealSound::Play(Volume, Looping, ListenerInside, NewPosition);
};
//---------------------------------------------------------------------------

96
old/RealSound.h Normal file
View File

@@ -0,0 +1,96 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <string>
#include "Sound.h"
#include "dumb3d.h"
#include "names.h"
class TRealSound {
protected:
PSound pSound = nullptr;
double fDistance = 0.0;
double fPreviousDistance = 0.0; // dla liczenia Dopplera
float fFrequency = 22050.0; // częstotliwość samplowania pliku
int iDoppler = 0; // Ra 2014-07: możliwość wyłączenia efektu Dopplera np. dla śpiewu ptaków
public:
std::string m_name;
Math3D::vector3 vSoundPosition; // polozenie zrodla dzwieku
double dSoundAtt = -1.0; // odleglosc polowicznego zaniku dzwieku
double AM = 0.0; // mnoznik amplitudy
double AA = 0.0; // offset amplitudy
double FM = 0.0; // mnoznik czestotliwosci
double FA = 0.0; // offset czestotliwosci
bool bLoopPlay = false; // czy zapętlony dźwięk jest odtwarzany
TRealSound() = default;
TRealSound( std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod = false, double rmin = 0.0 );
~TRealSound();
void Init( std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod = false, double rmin = 0.0 );
double ListenerDistance( Math3D::vector3 ListenerPosition);
void Play(double Volume, int Looping, bool ListenerInside, Math3D::vector3 NewPosition);
void Stop();
void AdjFreq(double Freq, double dt);
void SetPan(int Pan);
double GetWaveTime(); // McZapkie TODO: dorobic dla roznych bps
int GetStatus();
void ResetPosition();
bool Empty() { return ( pSound == nullptr ); }
void
name( std::string Name ) {
m_name = Name; }
std::string const &
name() const {
return m_name; }
glm::dvec3
location() const {
return vSoundPosition; };
};
class TTextSound : public TRealSound {
// dźwięk ze stenogramem
std::string asText;
float fTime; // czas trwania
public:
TTextSound(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod = false, double rmin = 0.0);
void Init(std::string const &SoundName, double SoundAttenuation, double X, double Y, double Z, bool Dynamic, bool freqmod = false, double rmin = 0.0);
void Play(double Volume, int Looping, bool ListenerInside, Math3D::vector3 NewPosition);
};
class TSynthSound
{ // klasa generująca sygnał odjazdu (Rp12, Rp13), potem rozbudować o pracę manewrowego...
int iIndex[44]; // indeksy początkowe, gdy mamy kilka wariantów dźwięków składowych
// 0..9 - cyfry 0..9
// 10..19 - liczby 10..19
// 21..29 - dziesiątki (*21==*10?)
// 31..39 - setki 100,200,...,800,900
// 40 - "tysiąc"
// 41 - "tysiące"
// 42 - indeksy początkowe dla "odjazd"
// 43 - indeksy początkowe dla "gotów"
PSound sSound; // posortowana tablica dźwięków, rozmiar zależny od liczby znalezionych plików
// a może zamiast wielu plików/dźwięków zrobić jeden połączony plik i posługiwać się czasem
// od..do?
};
// collection of generators for power grid present in the scene
class sound_table : public basic_table<TTextSound> {
};
//---------------------------------------------------------------------------

257
old/Sound.cpp Normal file
View File

@@ -0,0 +1,257 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "Sound.h"
#include "Globals.h"
#include "Logs.h"
#include "Usefull.h"
#include "mczapkie/mctools.h"
#include "WavRead.h"
#define SAFE_RELEASE(p) \
{ \
if (p) \
{ \
(p)->Release(); \
(p) = NULL; \
} \
}
LPDIRECTSOUND TSoundsManager::pDS;
LPDIRECTSOUNDNOTIFY TSoundsManager::pDSNotify;
int TSoundsManager::Count = 0;
TSoundContainer *TSoundsManager::First = NULL;
TSoundContainer::TSoundContainer(LPDIRECTSOUND pDS, std::string const &Directory, std::string const &Filename, int NConcurrent)
{ // wczytanie pliku dźwiękowego
int hr = 111;
DSBuffer = nullptr; // na początek, gdyby uruchomić dźwięków się nie udało
Concurrent = NConcurrent;
Oldest = 0;
m_name = Directory + Filename;
// Create a new wave file class
std::shared_ptr<CWaveSoundRead> pWaveSoundRead = std::make_shared<CWaveSoundRead>();
// Load the wave file
if( ( FAILED( pWaveSoundRead->Open( m_name ) ) )
&& ( FAILED( pWaveSoundRead->Open( Filename ) ) ) ) {
ErrorLog( "Missed sound: " + Filename );
return;
}
m_name = ToLower( Filename );
// Set up the direct sound buffer, and only request the flags needed
// since each requires some overhead and limits if the buffer can
// be hardware accelerated
DSBUFFERDESC dsbd;
ZeroMemory(&dsbd, sizeof(DSBUFFERDESC));
dsbd.dwSize = sizeof(DSBUFFERDESC);
dsbd.dwFlags = DSBCAPS_STATIC | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY;
if (!Global::bInactivePause) // jeśli przełączony w tło ma nadal działać
dsbd.dwFlags |= DSBCAPS_GLOBALFOCUS; // to dźwięki mają być również słyszalne
dsbd.dwBufferBytes = pWaveSoundRead->m_ckIn.cksize;
dsbd.lpwfxFormat = pWaveSoundRead->m_pwfx;
fSamplingRate = pWaveSoundRead->m_pwfx->nSamplesPerSec;
iBitsPerSample = pWaveSoundRead->m_pwfx->wBitsPerSample;
// pDSBuffer= (LPDIRECTSOUNDBUFFER*) malloc(Concurrent*sizeof(LPDIRECTSOUNDBUFFER));
// for (int i=0; i<Concurrent; i++)
// pDSBuffer[i]= NULL;
// Create the static DirectSound buffer
if (FAILED(hr = pDS->CreateSoundBuffer(&dsbd, &(DSBuffer), NULL)))
// if (FAILED(pDS->CreateSoundBuffer(&dsbd,&(DSBuffer),NULL)))
return;
// Remember how big the buffer is
DWORD dwBufferBytes;
dwBufferBytes = dsbd.dwBufferBytes;
//----------------------------------------------------------
BYTE *pbWavData; // Pointer to actual wav data
UINT cbWavSize; // Size of data
VOID *pbData = NULL;
VOID *pbData2 = NULL;
DWORD dwLength;
DWORD dwLength2;
// The size of wave data is in pWaveFileSound->m_ckIn
INT nWaveFileSize = pWaveSoundRead->m_ckIn.cksize;
// Allocate that buffer.
pbWavData = new BYTE[nWaveFileSize];
if (NULL == pbWavData)
return; // E_OUTOFMEMORY;
// if (FAILED(hr=pWaveSoundRead->Read( nWaveFileSize,pbWavData,&cbWavSize)))
if( FAILED( hr = pWaveSoundRead->Read( nWaveFileSize, pbWavData, &cbWavSize ) ) ) {
delete[] pbWavData;
return;
}
// Reset the file to the beginning
pWaveSoundRead->Reset();
// Lock the buffer down
// if (FAILED(hr=DSBuffer->Lock(0,dwBufferBytes,&pbData,&dwLength,&pbData2,&dwLength2,0)))
if( FAILED( hr = DSBuffer->Lock( 0, dwBufferBytes, &pbData, &dwLength, &pbData2, &dwLength2, 0L ) ) ) {
delete[] pbWavData;
return;
}
// Copy the memory to it.
memcpy(pbData, pbWavData, dwBufferBytes);
// Unlock the buffer, we don't need it anymore.
DSBuffer->Unlock(pbData, dwBufferBytes, NULL, 0);
pbData = NULL;
// We dont need the wav file data buffer anymore, so delete it
delete[] pbWavData;
DSBuffers.push(DSBuffer);
};
TSoundContainer::~TSoundContainer()
{
while (!DSBuffers.empty())
{
SAFE_RELEASE(DSBuffers.top());
DSBuffers.pop();
}
SafeDelete(Next);
};
LPDIRECTSOUNDBUFFER TSoundContainer::GetUnique(LPDIRECTSOUND pDS)
{
if (!DSBuffer)
return NULL;
// jeśli się dobrze zainicjowało
LPDIRECTSOUNDBUFFER buff = nullptr;
pDS->DuplicateSoundBuffer(DSBuffer, &buff);
if (buff)
DSBuffers.push(buff);
return DSBuffers.top();
};
TSoundsManager::~TSoundsManager()
{
Free();
};
void TSoundsManager::Free()
{
SafeDelete(First);
SAFE_RELEASE(pDS);
};
TSoundContainer * TSoundsManager::LoadFromFile( std::string const &Dir, std::string const &Filename, int Concurrent)
{
TSoundContainer *tmp = First;
First = new TSoundContainer(pDS, Dir, Filename, Concurrent);
First->Next = tmp;
Count++;
return First; // albo NULL, jak nie wyjdzie (na razie zawsze wychodzi)
};
LPDIRECTSOUNDBUFFER TSoundsManager::GetFromName(std::string const &Name, bool Dynamic, float *fSamplingRate)
{ // wyszukanie dźwięku w pamięci albo wczytanie z pliku
std::string name{ ToLower(Name) };
std::string file;
if (Dynamic)
{ // próba wczytania z katalogu pojazdu
file = Global::asCurrentDynamicPath + name;
if (FileExists(file))
name = file; // nowa nazwa
else
Dynamic = false; // wczytanie z "sounds/"
}
TSoundContainer *Next = First;
for (int i = 0; i < Count; i++)
{
if( name == Next->m_name ) {
if (fSamplingRate)
*fSamplingRate = Next->fSamplingRate; // częstotliwość
return (Next->GetUnique(pDS));
}
else
Next = Next->Next;
};
if (Dynamic) // wczytanie z katalogu pojazdu
Next = LoadFromFile("", name, 1);
else
Next = LoadFromFile(szSoundPath, name, 1);
if (Next)
{ //
if (fSamplingRate)
*fSamplingRate = Next->fSamplingRate; // częstotliwość
return Next->GetUnique(pDS);
}
ErrorLog("Missed sound: " + Name );
return (nullptr);
};
void TSoundsManager::RestoreAll()
{
TSoundContainer *Next = First;
HRESULT hr;
DWORD dwStatus = 0;
for (int i = 0; i < Count; i++)
{
if (dwStatus & DSBSTATUS_BUFFERLOST)
{
// Since the app could have just been activated, then
// DirectSound may not be giving us control yet, so
// the restoring the buffer may fail.
// If it does, sleep until DirectSound gives us control.
do
{
hr = Next->DSBuffer->Restore();
if (hr == DSERR_BUFFERLOST)
Sleep(10);
} while ((hr = Next->DSBuffer->Restore()) != 0);
// char *Name= Next->Name;
// int cc= Next->Concurrent;
// delete Next;
// Next= new TSoundContainer(pDS, Directory, Name, cc);
// if( FAILED( hr = FillBuffer() ) );
// return hr;
};
Next = Next->Next;
};
};
bool TSoundsManager::Init(HWND hWnd) {
First = nullptr;
Count = 0;
pDS = nullptr;
pDSNotify = nullptr;
// Create IDirectSound using the primary sound device
auto hr = ::DirectSoundCreate(NULL, &pDS, NULL);
if (hr != DS_OK) {
return false;
};
pDS->SetCooperativeLevel(hWnd, DSSCL_NORMAL);
return true;
};

50
old/Sound.h Normal file
View File

@@ -0,0 +1,50 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <stack>
#include <dsound.h>
typedef LPDIRECTSOUNDBUFFER PSound;
class TSoundContainer
{
public:
int Concurrent;
int Oldest;
std::string m_name;
LPDIRECTSOUNDBUFFER DSBuffer;
float fSamplingRate; // częstotliwość odczytana z pliku
int iBitsPerSample; // ile bitów na próbkę
TSoundContainer *Next;
std::stack<LPDIRECTSOUNDBUFFER> DSBuffers;
TSoundContainer(LPDIRECTSOUND pDS, std::string const &Directory, std::string const &Filename, int NConcurrent);
~TSoundContainer();
LPDIRECTSOUNDBUFFER GetUnique( LPDIRECTSOUND pDS );
};
class TSoundsManager
{
private:
static LPDIRECTSOUND pDS;
static LPDIRECTSOUNDNOTIFY pDSNotify;
static TSoundContainer *First;
static int Count;
static TSoundContainer * LoadFromFile( std::string const &Directory, std::string const &FileName, int Concurrent);
public:
~TSoundsManager();
static bool Init( HWND hWnd );
static void Free();
static LPDIRECTSOUNDBUFFER GetFromName( std::string const &Name, bool Dynamic, float *fSamplingRate = NULL );
static void RestoreAll();
};

493
old/Unit1.pas Normal file
View File

@@ -0,0 +1,493 @@
unit Unit1;
(*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*)
interface
uses
ai_driver,mtable,mover,mctools,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Label2: TLabel;
Label3: TLabel;
Timer1: TTimer;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Button7: TButton;
Button8: TButton;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Button9: TButton;
Button10: TButton;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Button11: TButton;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
Label25: TLabel;
lczas: TLabel;
Label28: TLabel;
Label29: TLabel;
Label30: TLabel;
Label31: TLabel;
Label32: TLabel;
Label33: TLabel;
Label34: TLabel;
Button12: TButton;
BStart: TButton;
Label35: TLabel;
Label36: TLabel;
Label37: TLabel;
Label38: TLabel;
Button13: TButton;
Label39: TLabel;
Label40: TLabel;
Label41: TLabel;
Label42: TLabel;
Label43: TLabel;
Button14: TButton;
Button15: TButton;
Label44: TLabel;
Label45: TLabel;
Label46: TLabel;
Label47: TLabel;
BMains: TButton;
Label48: TLabel;
Label49: TLabel;
Label50: TLabel;
Panel1: TPanel;
Label1: TLabel;
OpenDialog1: TOpenDialog;
Edit1: TEdit;
GroupBox1: TGroupBox;
CheckBox1: TCheckBox;
BSInc: TButton;
BSDec: TButton;
Label51: TLabel;
Label52: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure BStartClick(Sender: TObject);
procedure Button13MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button14Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure BMainsClick(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure BSIncClick(Sender: TObject);
procedure BSDecClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
mtno=30;
tno:integer=0;
var
Form1: TForm1;
loc:TMoverParameters;
wagony:array[1..mtno] of TMoverParameters;
mechanik: TController;
pociag: TTrainParameters;
couplerflag:byte;
l0,l0p:TLocation;
ll:array[1..mtno] of TLocation;
r0:TRotation;
rr:array[1..mtno] of TRotation;
Shape:TTrackShape; Track:TTrackParam;
ExternalVoltage:real;
ActualTime:real;
fout: text;
OK:boolean;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var typename,path:string;slashpos:byte;
begin
couplerflag:=strtoint(Edit1.Text);
if tno>0 then
wagony[tno]:=TMoverParameters.Create;
OpenDialog1.Execute;
path:='';
typename:=OpenDialog1.Filename;
repeat
slashpos:=pos('\',typename);
if slashpos>0 then
typename:=copy(typename,slashpos+1,length(typename));
until slashpos=0;
path:=copy(opendialog1.filename,1,length(opendialog1.filename)-length(typename));
typename:=Copy(typename,1,Pos('.chk',typename)-1);
if tno=0 then
begin
loc.Init(l0,r0,0,typename,'lokomotywa',0,'',1);
OK:=loc.loadchkfile(path) and loc.CheckLocomotiveParameters(Go);
if OK then
begin
Label1.Caption:=loc.TypeName;
case loc.AutoRelayType of
2: CheckBox1.Enabled:=True;
1: CheckBox1.Checked:=True;
end;
end;
end
else
begin
wagony[tno].Init(ll[tno],rr[tno],0,typename,IntToStr(tno),0,'',0);
OK:=OK and (wagony[tno].loadchkfile(path) and wagony[tno].CheckLocomotiveParameters(Go));
if OK then
begin
Label1.Caption:=Label1.Caption+' '+wagony[tno].TypeName;
if tno=1 then
ll[tno].x:=loc.Loc.x-loc.Dim.L/2-wagony[tno].Dim.L/2
else
ll[tno].x:=wagony[tno-1].Loc.x-wagony[tno-1].Dim.L/2-wagony[tno].Dim.L/2;
wagony[tno].loc:=ll[tno];
if tno=1 then
begin
OK:=OK and loc.attach(2,@wagony[1],couplerflag);
OK:=OK and wagony[1].attach(1,@loc,couplerflag);
end
else
begin
OK:=OK and wagony[tno-1].attach(2,@wagony[tno],couplerflag);
OK:=OK and wagony[tno].attach(1,@wagony[tno-1],couplerflag);
end
end;
end;
if OK then
begin
BStart.Enabled:=True;
if tno=mtno then button1.enabled:=false
else inc(tno);
Label49.Caption:='ilosc pojazdow '+inttostr(tno);
end
else
begin
Label1.Caption:=inttostr(conversionerror)+' '+inttostr(linecount);
Button1.Enabled:=False;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var iw:integer;
begin
if Timer1.Enabled then
begin
Timer1.Enabled:=False;
CloseFile(fout);
end;
mechanik.CloseLog;
mechanik.free;
loc.Free;
for iw:=1 to tno do
wagony[iw].Free;
Close;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var dl,dt:real; iw:integer;
begin
dt:=Timer1.Interval/1000;
ActualTime:=ActualTime+dt;
if l0.x>200 then Shape.R:=1000;
if l0.x>1000 then Shape.R:=-500;
if l0.x>1500 then Shape.R:=0;
if l0.x>2000 then Shape.R:=1500;
if l0.x>2200 then Shape.R:=3000;
if l0.x>2400 then Shape.R:=0;
loc.ComputeTotalForce(dt);
for iw:=1 to tno do
wagony[iw].ComputeTotalForce(dt);
dl:=loc.ComputeMovement(dt,Shape,Track,ExternalVoltage,l0,r0);
l0.x:=l0.x+dl;
for iw:=1 to tno do
begin
dl:=wagony[iw].ComputeMovement(dt,Shape,Track,ExternalVoltage,ll[iw],rr[iw]);
ll[iw].x:=ll[iw].x+dl;
end;
mechanik.UpdateSituation(dt);
l0p.x:=500; l0p.y:=2; l0.z:=0;
if (l0.x>-1) and (l0.x<5) then
loc.PutCommand('SetVelocity',60,-1,l0p);
if (l0.x>499) and (l0.x<505) then
loc.PutCommand('SetVelocity',-1,-1,l0);
l0p.x:=3600;
if (l0.x>2985) and (l0.x<3005) then
loc.PutCommand('SetVelocity',-1,0,l0p);
if (l0.x>3600) and (l0.x<3615) then
loc.PutCommand('SetVelocity',0,0,l0);
if (l0.x>3430) and (loc.Vel<0.01) and (mechanik.GetCurrentOrder=Obey_train) then
loc.PutCommand('SetVelocity',0,0,l0);
if (loc.power>0) then
begin
Label2.Caption:='I0='+r2s(Loc.Im,0)+' A';
Label3.Caption:=r2s(Loc.Ft/1000,0)+' kN';
Label13.Caption:=IntToStr(Loc.MainCtrlPos);
Label18.Caption:=IntToStr(Loc.ScndCtrlPos);
Label20.Caption:=IntToStr(Loc.MainCtrlActualPos);
Label21.Caption:=IntToStr(Loc.ScndCtrlActualPos);
end
else
for iw:=1 to tno do
if wagony[iw].power>0 then
begin
Label2.Caption:='I'+IntToStr(iw)+'='+r2s(wagony[iw].Im,0)+' A';
Label3.Caption:=r2s(wagony[iw].Ft/1000,0)+' kN';
Label13.Caption:=IntToStr(wagony[iw].MainCtrlPos);
Label18.Caption:=IntToStr(wagony[iw].ScndCtrlPos);
Label20.Caption:=IntToStr(wagony[iw].MainCtrlActualPos);
Label21.Caption:=IntToStr(wagony[iw].ScndCtrlActualPos);
end;
Label4.Caption:=r2s(l0.x,0)+' m';
Label5.Caption:=r2s(Sign(Loc.V)*Loc.Vel,0)+' km/h';
Label6.Caption:=r2s(Loc.AccS,0)+' m/ss';
Label9.Caption:=r2s(Loc.Fb/1000,0)+' kN';
Label10.Caption:=r2s(Loc.Compressor,0)+' MPa';
Label11.Caption:=r2s(Loc.PipePress,0)+' MPa';
Label12.Caption:=r2s(Loc.BrakePress,0)+' MPa';
Label14.Caption:=IntToStr(Loc.BrakeCtrlPos);
Label15.Caption:=IntToStr(Loc.LocalBrakePos);
Label16.Caption:=IntToStr(Loc.showcurrent(1));
Label17.Caption:=IntToStr(Loc.showcurrent(2));
if loc.SlippingWheels then
Label19.Caption:='Poslizg!'
else Label19.Caption:=' ';
Label22.Caption:=r2s(ll[1].x,0)+' m';
if tno>=1 then
begin
Label23.Caption:=r2s(Sign(wagony[1].V)*wagony[1].Vel,0)+' km/h';
Label24.Caption:=r2s(Distance(loc.loc,wagony[1].loc,loc.dim,wagony[1].dim),0)+' m';
end;
Label25.Caption:=r2s(loc.nrot,0)+' 1/s';
Label28.Caption:=r2s(ll[2].x,0)+' m';
if tno>=2 then
Label29.Caption:=r2s(sign(wagony[2].V)*wagony[2].Vel,0)+' km/h';
Label30.Caption:=r2s(loc.dpLocalValve/dt,0)+' MPa/s';
Label31.Caption:=r2s(loc.dpBrake/dt,0)+' MPa/s';
Label32.Caption:=r2s(loc.dpMainValve/dt,0)+' MPa/s';
Label33.Caption:=r2s(loc.dpPipe/dt,0)+' MPa/s';
if tno>0 then Label34.Caption:=r2s(wagony[tno].PipePress,0)+' MPa';
Label35.Caption:=r2s(ll[3].x,0)+' m';
if tno>0 then Label36.Caption:=r2s(sign(wagony[tno].V)*wagony[tno].Vel,0)+' km/h';
if tno>0 then Label37.Caption:=r2s(wagony[tno].couplers[1].cforce/1000,0)+' kN';
if tno>0 then Label38.Caption:=r2s(wagony[tno].brakepress,0)+' MPa';
Label39.Caption:=r2s(loc.enginePower/1000,0)+' kW';
Label40.Caption:=i2s(trunc(loc.Rventrot*60))+' /min';
Label41.Visible:=loc.SandDose;
Label42.Caption:=r2s(mechanik.accdesired,0)+' m/ss';
Label43.Caption:=r2s(mechanik.veldesired,0)+' km/h';
if tno>0 then Label44.Caption:=r2s(ll[tno].x,0)+' m';
Label45.Caption:=inttostr(loc.activedir);
Label46.Caption:=inttostr(ord(mechanik.orderlist[mechanik.orderpos]));
Label47.Caption:=inttostr(mechanik.orderpos);
Label48.Caption:=inttostr(ord(loc.mains));
{ if tno>0 then Label51.Caption:=wagony[1].CommandIn.Command;
if tno>0 then Label52.Caption:=r2s(wagony[1].CommandIn.Value1,0);
}
Label51.Caption:=loc.CommandIn.Command;
Label52.Caption:=r2s(loc.CommandIn.Value1,0);
Lczas.Caption:=r2s(actualtime,0)+' s';
writeln(fout,Actualtime,' ',{loc.v-wag.v,}loc.UnitBrakeForce,' ',loc.dpMainValve,{' ',loc.dpLocalValve,}' ',loc.accs,' ',loc.couplers[2].cforce,' ',{,l1.x}' '{,Distance(loc.loc,wagony[1].loc,loc.dim,wagony[1].dim)});
end;
procedure TForm1.FormCreate(Sender: TObject);
var iw:integer;
begin
Timer1.Enabled:=False;
tno:=0;
assignfile(fout,'log.dat');
rewrite(fout);
ActualTime:=0;
loc:=TMoverParameters.Create;
Shape.R:=0; Shape.Len:=10000; Shape.dHtrack:=0; Shape.dHrail:=0;
Track.Width:=1435; Track.friction:=0.15; Track.CategoryFlag:=1;
Track.QualityFlag:=25; Track.DamageFlag:=0;
Track.VelMax:=120;
ExternalVoltage:=3000;
l0.x:=0; l0.y:=0; l0.z:=0;
r0.rx:=0; r0.ry:=0; r0.rz:=0;
for iw:=1 to mtno do
begin
rr[iw].rx:=0; rr[iw].ry:=0; rr[iw].rz:=0;
ll[iw].x:=0; ll[iw].y:=0; ll[iw].z:=0;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
loc.incbrakelevel;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
loc.decbrakelevel;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
loc.inclocalbrakelevel(1);
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
loc.declocalbrakelevel(1);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
loc.incmainctrl(1);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
loc.decmainctrl(1);
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
loc.DirectionForward;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
loc.DirectionBackward;
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
loc.FuseOn;
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
Loc.AntiSlippingBrake;
end;
procedure TForm1.BStartClick(Sender: TObject);
begin
tno:=tno-1;
Button1.Enabled:=False;
Edit1.Enabled:=False;
Timer1.Enabled:=True;
mechanik:=TController.Create;
pociag:=TTrainParameters.Create;
pociag.init('Testowy Express',100);
mechanik.init(l0,r0,HumanDriver,@loc,@pociag,Aggressive);
BStart.Enabled:=False;
Button14.enabled:=True;
Button15.enabled:=True;
end;
procedure TForm1.Button13MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
loc.SandDoseOn;
end;
procedure TForm1.Button14Click(Sender: TObject);
begin
mechanik.SetVelocity(30,120);
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
mechanik.AIControllFlag:=not mechanik.AIControllFlag;
if not loc.mains then
begin
mechanik.ChangeOrder(Prepare_Engine);
mechanik.JumpToNextOrder;
mechanik.ChangeOrder(Obey_train);
mechanik.JumpToNextOrder;
mechanik.ChangeOrder(Release_engine);
mechanik.JumpToFirstOrder;
mechanik.SetVelocity(60,120);
end;
end;
procedure TForm1.BMainsClick(Sender: TObject);
begin
loc.MainSwitch;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
loc.autorelayswitch;
end;
procedure TForm1.BSIncClick(Sender: TObject);
begin
loc.incscndctrl(1);
end;
procedure TForm1.BSDecClick(Sender: TObject);
begin
loc.decscndctrl(1);
end;
end.

11
old/VBO.cpp Normal file
View File

@@ -0,0 +1,11 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "VBO.h"

19
old/VBO.h Normal file
View File

@@ -0,0 +1,19 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "openglgeometrybank.h"
class CMesh
{
public:
geometrybank_handle m_geometrybank;
bool m_geometrycreated { false };
};

1379
old/World.cpp Normal file

File diff suppressed because it is too large Load Diff

113
old/World.h Normal file
View File

@@ -0,0 +1,113 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <GLFW/glfw3.h>
#include <string>
#include "classes.h"
#include "Camera.h"
#include "sky.h"
#include "sun.h"
#include "moon.h"
#include "stars.h"
#include "skydome.h"
#include "messaging.h"
// wrapper for environment elements -- sky, sun, stars, clouds etc
class world_environment {
friend opengl_renderer;
public:
void init();
void update();
void time( int const Hour = -1, int const Minute = -1, int const Second = -1 );
private:
CSkyDome m_skydome;
cStars m_stars;
cSun m_sun;
cMoon m_moon;
TSky m_clouds;
};
class TWorld
{
// NOTE: direct access is a shortcut, but world etc needs some restructuring regardless
friend opengl_renderer;
public:
// types
// constructors
TWorld();
// destructor
~TWorld();
// methods
void CreateE3D( std::string const &dir = "", bool dyn = false );
bool Init( GLFWwindow *w );
bool InitPerformed() { return m_init; }
bool Update();
void OnKeyDown( int cKey );
void OnCommandGet( multiplayer::DaneRozkaz *pRozkaz );
// passes specified sound to all vehicles within range as a radio message broadcasted on specified channel
void radio_message( sound_source *Message, int const Channel );
void CabChange( TDynamicObject *old, TDynamicObject *now );
void TrainDelete(TDynamicObject *d = NULL);
TTrain const *
train() const { return Train; }
TDynamicObject const *
controlled() const { return Controlled; }
// switches between static and dynamic daylight calculation
void ToggleDaylight();
// calculates current season of the year based on set simulation date
void compute_season( int const Yearday ) const;
// calculates current weather
void compute_weather() const;
// members
private:
void Update_Environment();
void Update_Camera( const double Deltatime );
// handles vehicle change flag
void ChangeDynamic();
void InOutKey( bool const Near = true );
void FollowView( bool wycisz = true );
void DistantView( bool const Near = false );
TCamera Camera;
TCamera DebugCamera;
world_environment Environment;
TTrain *Train;
TDynamicObject *Controlled { nullptr }; // pojazd, który prowadzimy
TDynamicObject *pDynamicNearest { nullptr };
bool Paused { true };
TEvent *KeyEvents[10]; // eventy wyzwalane z klawiaury
TMoverParameters *mvControlled; // wskaźnik na człon silnikowy, do wyświetlania jego parametrów
double fTime50Hz; // bufor czasu dla komunikacji z PoKeys
double fTimeBuffer; // bufor czasu aktualizacji dla stałego kroku fizyki
double fMaxDt; //[s] krok czasowy fizyki (0.01 dla normalnych warunków)
double const m_primaryupdaterate { 1.0 / 100.0 };
double const m_secondaryupdaterate { 1.0 / 50.0 };
double m_primaryupdateaccumulator { m_secondaryupdaterate }; // keeps track of elapsed simulation time, for core fixed step routines
double m_secondaryupdateaccumulator { m_secondaryupdaterate }; // keeps track of elapsed simulation time, for less important fixed step routines
int iPause; // wykrywanie zmian w zapauzowaniu
bool m_init { false }; // indicates whether initial update of the world was performed
GLFWwindow *window;
};
extern TWorld World;
//---------------------------------------------------------------------------

903
old/_Mover.hpp Normal file
View File

@@ -0,0 +1,903 @@
// Borland C++ Builder
// Copyright (c) 1995, 1999 by Borland International
// All rights reserved
// (DO NOT EDIT: machine generated header) '_mover.pas' rev: 5.00
#ifndef _moverHPP
#define _moverHPP
#pragma delphiheader begin
#pragma option push -w-
#pragma option push -Vx
#include <Oerlikon_ESt.h> // Pascal unit
#include <hamulce.h> // Pascal unit
#include <SysUtils.hpp> // Pascal unit
#include <mctools.hpp> // Pascal unit
#include <SysInit.hpp> // Pascal unit
#include <System.hpp> // Pascal unit
//-- user supplied -----------------------------------------------------------
namespace _mover
{
//-- type declarations -------------------------------------------------------
struct TLocation
{
double X;
double Y;
double Z;
} ;
struct TRotation
{
double Rx;
double Ry;
double Rz;
} ;
struct TDimension
{
double W;
double L;
double H;
} ;
struct TCommand
{
AnsiString Command;
double Value1;
double Value2;
TLocation Location;
} ;
struct TTrackShape
{
double R;
double Len;
double dHtrack;
double dHrail;
} ;
struct TTrackParam
{
double Width;
double friction;
Byte CategoryFlag;
Byte QualityFlag;
Byte DamageFlag;
double Velmax;
} ;
struct TTractionParam
{
double TractionVoltage;
double TractionFreq;
double TractionMaxCurrent;
double TractionResistivity;
} ;
#pragma option push -b-
enum TBrakeSystem { Individual, Pneumatic, ElectroPneumatic };
#pragma option pop
#pragma option push -b-
enum TBrakeSubSystem { ss_None, ss_W, ss_K, ss_KK, ss_Hik, ss_ESt, ss_KE, ss_LSt, ss_MT, ss_Dako };
#pragma option pop
#pragma option push -b-
enum TBrakeValve { NoValve, W, W_Lu_VI, W_Lu_L, W_Lu_XR, K, Kg, Kp, Kss, Kkg, Kkp, Kks, Hikg1, Hikss,
Hikp1, KE, SW, EStED, NESt3, ESt3, LSt, ESt4, ESt3AL2, EP1, EP2, M483, CV1_L_TR, CV1, CV1_R, Other
};
#pragma option pop
#pragma option push -b-
enum TBrakeHandle { NoHandle, West, FV4a, M394, M254, FVel1, FVel6, D2, Knorr, FD1, BS2, testH, St113,
MHZ_P, MHZ_T, MHZ_EN57 };
#pragma option pop
#pragma option push -b-
enum TLocalBrake { NoBrake, ManualBrake, PneumaticBrake, HydraulicBrake };
#pragma option pop
typedef double TBrakeDelayTable[4];
struct TBrakePressure
{
double PipePressureVal;
double BrakePressureVal;
double FlowSpeedVal;
TBrakeSystem BrakeType;
} ;
typedef TBrakePressure TBrakePressureTable[13];
#pragma option push -b-
enum TEngineTypes { None, Dumb, WheelsDriven, ElectricSeriesMotor, ElectricInductionMotor, DieselEngine,
SteamEngine, DieselElectric };
#pragma option pop
#pragma option push -b-
enum TPowerType { NoPower, BioPower, MechPower, ElectricPower, SteamPower };
#pragma option pop
#pragma option push -b-
enum TFuelType { Undefined, Coal, Oil };
#pragma option pop
struct TGrateType
{
TFuelType FuelType;
double GrateSurface;
double FuelTransportSpeed;
double IgnitionTemperature;
double MaxTemperature;
} ;
struct TBoilerType
{
double BoilerVolume;
double BoilerHeatSurface;
double SuperHeaterSurface;
double MaxWaterVolume;
double MinWaterVolume;
double MaxPressure;
} ;
struct TCurrentCollector
{
int CollectorsNo;
double MinH;
double MaxH;
double CSW;
double MinV;
double MaxV;
double OVP;
double InsetV;
double MinPress;
double MaxPress;
} ;
#pragma option push -b-
enum TPowerSource { NotDefined, InternalSource, Transducer, Generator, Accumulator, CurrentCollector,
PowerCable, Heater };
#pragma option pop
struct _mover__1
{
double MaxCapacity;
TPowerSource RechargeSource;
} ;
struct _mover__2
{
TPowerType PowerTrans;
double SteamPressure;
} ;
struct _mover__3
{
TGrateType Grate;
TBoilerType Boiler;
} ;
struct TPowerParameters
{
double MaxVoltage;
double MaxCurrent;
double IntR;
TPowerSource SourceType;
union
{
struct
{
_mover__3 RHeater;
};
struct
{
_mover__2 RPowerCable;
};
struct
{
TCurrentCollector CollectorParameters;
};
struct
{
_mover__1 RAccumulator;
};
struct
{
TEngineTypes GeneratorEngine;
};
struct
{
double InputVoltage;
};
struct
{
TPowerType PowerType;
};
};
} ;
struct TScheme
{
Byte Relay;
double R;
Byte Bn;
Byte Mn;
bool AutoSwitch;
Byte ScndAct;
} ;
typedef TScheme TSchemeTable[65];
struct TDEScheme
{
double RPM;
double GenPower;
double Umax;
double Imax;
} ;
typedef TDEScheme TDESchemeTable[33];
struct TShuntScheme
{
double Umin;
double Umax;
double Pmin;
double Pmax;
} ;
typedef TShuntScheme TShuntSchemeTable[33];
struct TMPTRelay
{
double Iup;
double Idown;
} ;
typedef TMPTRelay TMPTRelayTable[8];
struct TMotorParameters
{
double mfi;
double mIsat;
double mfi0;
double fi;
double Isat;
double fi0;
bool AutoSwitch;
} ;
struct TSecuritySystem
{
Byte SystemType;
double AwareDelay;
double AwareMinSpeed;
double SoundSignalDelay;
double EmergencyBrakeDelay;
Byte Status;
double SystemTimer;
double SystemSoundCATimer;
double SystemSoundSHPTimer;
double SystemBrakeCATimer;
double SystemBrakeSHPTimer;
double SystemBrakeCATestTimer;
int VelocityAllowed;
int NextVelocityAllowed;
bool RadioStop;
} ;
struct TTransmision
{
Byte NToothM;
Byte NToothW;
double Ratio;
} ;
#pragma option push -b-
enum TCouplerType { NoCoupler, Articulated, Bare, Chain, Screw, Automatic };
#pragma option pop
class DELPHICLASS T_MoverParameters;
struct TCoupling;
class PASCALIMPLEMENTATION T_MoverParameters : public System::TObject
{
typedef System::TObject inherited;
public:
double dMoveLen;
AnsiString filename;
Byte CategoryFlag;
AnsiString TypeName;
int TrainType;
TEngineTypes EngineType;
TPowerParameters EnginePowerSource;
TPowerParameters SystemPowerSource;
TPowerParameters HeatingPowerSource;
TPowerParameters AlterHeatPowerSource;
TPowerParameters LightPowerSource;
TPowerParameters AlterLightPowerSource;
double Vmax;
double Mass;
double Power;
double Mred;
double TotalMass;
double HeatingPower;
double LightPower;
double BatteryVoltage;
bool Battery;
bool EpFuse;
bool Signalling;
bool DoorSignalling;
bool Radio;
double NominalBatteryVoltage;
TDimension Dim;
double Cx;
double Floor;
double WheelDiameter;
double WheelDiameterL;
double WheelDiameterT;
double TrackW;
double AxleInertialMoment;
AnsiString AxleArangement;
Byte NPoweredAxles;
Byte NAxles;
Byte BearingType;
double ADist;
double BDist;
Byte NBpA;
int SandCapacity;
TBrakeSystem BrakeSystem;
TBrakeSubSystem BrakeSubsystem;
TBrakeValve BrakeValve;
TBrakeHandle BrakeHandle;
TBrakeHandle BrakeLocHandle;
double MBPM;
Hamulce::TBrake* Hamulec;
Hamulce::THandle* Handle;
Hamulce::THandle* LocHandle;
Hamulce::TReservoir* Pipe;
Hamulce::TReservoir* Pipe2;
TLocalBrake LocalBrake;
TBrakePressure BrakePressureTable[13];
TBrakePressure BrakePressureActual;
Byte ASBType;
Byte TurboTest;
double MaxBrakeForce;
double MaxBrakePress[5];
double P2FTrans;
double TrackBrakeForce;
Byte BrakeMethod;
double HighPipePress;
double LowPipePress;
double DeltaPipePress;
double CntrlPipePress;
double BrakeVolume;
double BrakeVVolume;
double VeselVolume;
int BrakeCylNo;
double BrakeCylRadius;
double BrakeCylDist;
double BrakeCylMult[3];
Byte LoadFlag;
double BrakeCylSpring;
double BrakeSlckAdj;
double BrakeRigEff;
double RapidMult;
int BrakeValveSize;
AnsiString BrakeValveParams;
double Spg;
double MinCompressor;
double MaxCompressor;
double CompressorSpeed;
double BrakeDelay[4];
Byte BrakeCtrlPosNo;
Byte MainCtrlPosNo;
Byte ScndCtrlPosNo;
Byte LightsPosNo;
Byte LightsDefPos;
bool LightsWrap;
Byte Lights[2][16];
bool ScndInMain;
bool MBrake;
double StopBrakeDecc;
TSecuritySystem SecuritySystem;
TScheme RList[65];
int RlistSize;
TMotorParameters MotorParam[11];
TTransmision Transmision;
double NominalVoltage;
double WindingRes;
double u;
double CircuitRes;
int IminLo;
int IminHi;
int ImaxLo;
int ImaxHi;
double nmax;
double InitialCtrlDelay;
double CtrlDelay;
double CtrlDownDelay;
Byte FastSerialCircuit;
Byte AutoRelayType;
bool CoupledCtrl;
bool IsCoupled;
Byte DynamicBrakeType;
Byte RVentType;
double RVentnmax;
double RVentCutOff;
int CompressorPower;
int SmallCompressorPower;
bool Trafo;
double dizel_Mmax;
double dizel_nMmax;
double dizel_Mnmax;
double dizel_nmax;
double dizel_nominalfill;
double dizel_Mstand;
double dizel_nmax_cutoff;
double dizel_nmin;
double dizel_minVelfullengage;
double dizel_AIM;
double dizel_engageDia;
double dizel_engageMaxForce;
double dizel_engagefriction;
double AnPos;
bool AnalogCtrl;
bool AnMainCtrl;
bool ShuntModeAllow;
bool ShuntMode;
bool Flat;
double Vhyp;
TDEScheme DElist[33];
double Vadd;
TMPTRelay MPTRelay[8];
Byte RelayType;
TShuntScheme SST[33];
double PowerCorRatio;
double Ftmax;
double eimc[26];
int MaxLoad;
AnsiString LoadAccepted;
AnsiString LoadQuantity;
double OverLoadFactor;
double LoadSpeed;
double UnLoadSpeed;
Byte DoorOpenCtrl;
Byte DoorCloseCtrl;
double DoorStayOpen;
bool DoorClosureWarning;
double DoorOpenSpeed;
double DoorCloseSpeed;
double DoorMaxShiftL;
double DoorMaxShiftR;
double DoorMaxPlugShift;
Byte DoorOpenMethod;
double PlatformSpeed;
double PlatformMaxShift;
Byte PlatformOpenMethod;
bool ScndS;
TLocation Loc;
TRotation Rot;
AnsiString Name;
TCoupling Couplers[2];
double HVCouplers[2][2];
int ScanCounter;
bool EventFlag;
Byte SoundFlag;
double DistCounter;
double V;
double Vel;
double AccS;
double AccN;
double AccV;
double nrot;
double EnginePower;
double dL;
double Fb;
double Ff;
double FTrain;
double FStand;
double FTotal;
double UnitBrakeForce;
double Ntotal;
bool SlippingWheels;
bool SandDose;
double Sand;
double BrakeSlippingTimer;
double dpBrake;
double dpPipe;
double dpMainValve;
double dpLocalValve;
double ScndPipePress;
double BrakePress;
double LocBrakePress;
double PipeBrakePress;
double PipePress;
double EqvtPipePress;
double Volume;
double CompressedVolume;
double PantVolume;
double Compressor;
bool CompressorFlag;
bool PantCompFlag;
bool CompressorAllow;
bool ConverterFlag;
bool ConverterAllow;
int BrakeCtrlPos;
double BrakeCtrlPosR;
double BrakeCtrlPos2;
Byte LocalBrakePos;
Byte ManualBrakePos;
double LocalBrakePosA;
Byte BrakeStatus;
bool EmergencyBrakeFlag;
Byte BrakeDelayFlag;
Byte BrakeDelays;
Byte BrakeOpModeFlag;
Byte BrakeOpModes;
bool DynamicBrakeFlag;
double LimPipePress;
double ActFlowSpeed;
Byte DamageFlag;
Byte EngDmgFlag;
Byte DerailReason;
TCommand CommandIn;
AnsiString CommandOut;
AnsiString CommandLast;
double ValueOut;
TTrackShape RunningShape;
TTrackParam RunningTrack;
double OffsetTrackH;
double OffsetTrackV;
bool Mains;
Byte MainCtrlPos;
Byte ScndCtrlPos;
Byte LightsPos;
int ActiveDir;
int CabNo;
int DirAbsolute;
int ActiveCab;
double LastSwitchingTime;
bool DepartureSignal;
bool InsideConsist;
TTractionParam RunningTraction;
double enrot;
double Im;
double Itot;
double IHeating;
double ITraction;
double TotalCurrent;
double Mm;
double Mw;
double Fw;
double Ft;
int Imin;
int Imax;
double Voltage;
Byte MainCtrlActualPos;
Byte ScndCtrlActualPos;
bool DelayCtrlFlag;
double LastRelayTime;
bool AutoRelayFlag;
bool FuseFlag;
bool ConvOvldFlag;
bool StLinFlag;
bool ResistorsFlag;
double RventRot;
bool UnBrake;
double PantPress;
bool s_CAtestebrake;
double dizel_fill;
double dizel_engagestate;
double dizel_engage;
double dizel_automaticgearstatus;
bool dizel_enginestart;
double dizel_engagedeltaomega;
double eimv[21];
double PulseForce;
double PulseForceTimer;
int PulseForceCount;
double eAngle;
int Load;
AnsiString LoadType;
Byte LoadStatus;
double LastLoadChangeTime;
bool DoorBlocked;
bool DoorLeftOpened;
bool DoorRightOpened;
bool PantFrontUp;
bool PantRearUp;
bool PantFrontSP;
bool PantRearSP;
int PantFrontStart;
int PantRearStart;
double PantFrontVolt;
double PantRearVolt;
AnsiString PantSwitchType;
AnsiString ConvSwitchType;
bool Heating;
int DoubleTr;
bool PhysicActivation;
double FrictConst1;
double FrictConst2s;
double FrictConst2d;
double TotalMassxg;
double __fastcall GetTrainsetVoltage(void);
bool __fastcall Physic_ReActivation(void);
double __fastcall LocalBrakeRatio(void);
double __fastcall ManualBrakeRatio(void);
double __fastcall PipeRatio(void);
double __fastcall RealPipeRatio(void);
double __fastcall BrakeVP(void);
bool __fastcall DynamicBrakeSwitch(bool Switch);
bool __fastcall SendCtrlBroadcast(AnsiString CtrlCommand, double ctrlvalue);
bool __fastcall SendCtrlToNext(AnsiString CtrlCommand, double ctrlvalue, double dir);
bool __fastcall CabActivisation(void);
bool __fastcall CabDeactivisation(void);
bool __fastcall IncMainCtrl(int CtrlSpeed);
bool __fastcall DecMainCtrl(int CtrlSpeed);
bool __fastcall IncScndCtrl(int CtrlSpeed);
bool __fastcall DecScndCtrl(int CtrlSpeed);
bool __fastcall AddPulseForce(int Multipler);
bool __fastcall SandDoseOn(void);
bool __fastcall SecuritySystemReset(void);
void __fastcall SecuritySystemCheck(double dt);
bool __fastcall BatterySwitch(bool State);
bool __fastcall EpFuseSwitch(bool State);
bool __fastcall IncBrakeLevelOld(void);
bool __fastcall DecBrakeLevelOld(void);
bool __fastcall IncLocalBrakeLevel(Byte CtrlSpeed);
bool __fastcall DecLocalBrakeLevel(Byte CtrlSpeed);
bool __fastcall IncLocalBrakeLevelFAST(void);
bool __fastcall DecLocalBrakeLevelFAST(void);
bool __fastcall IncManualBrakeLevel(Byte CtrlSpeed);
bool __fastcall DecManualBrakeLevel(Byte CtrlSpeed);
bool __fastcall EmergencyBrakeSwitch(bool Switch);
bool __fastcall AntiSlippingBrake(void);
bool __fastcall BrakeReleaser(Byte state);
bool __fastcall SwitchEPBrake(Byte state);
bool __fastcall AntiSlippingButton(void);
bool __fastcall IncBrakePress(double &brake, double PressLimit, double dp);
bool __fastcall DecBrakePress(double &brake, double PressLimit, double dp);
bool __fastcall BrakeDelaySwitch(Byte BDS);
bool __fastcall IncBrakeMult(void);
bool __fastcall DecBrakeMult(void);
void __fastcall UpdateBrakePressure(double dt);
void __fastcall UpdatePipePressure(double dt);
void __fastcall CompressorCheck(double dt);
void __fastcall UpdateScndPipePressure(double dt);
double __fastcall GetDVc(double dt);
void __fastcall ComputeConstans(void);
double __fastcall ComputeMass(void);
double __fastcall Adhesive(double staticfriction);
double __fastcall TractionForce(double dt);
double __fastcall FrictionForce(double R, Byte TDamage);
double __fastcall BrakeForce(const TTrackParam &Track);
double __fastcall CouplerForce(Byte CouplerN, double dt);
void __fastcall CollisionDetect(Byte CouplerN, double dt);
double __fastcall ComputeRotatingWheel(double WForce, double dt, double n);
bool __fastcall SetInternalCommand(AnsiString NewCommand, double NewValue1, double NewValue2);
double __fastcall GetExternalCommand(AnsiString &Command);
bool __fastcall RunCommand(AnsiString command, double CValue1, double CValue2);
bool __fastcall RunInternalCommand(void);
void __fastcall PutCommand(AnsiString NewCommand, double NewValue1, double NewValue2, const TLocation
&NewLocation);
bool __fastcall DirectionBackward(void);
bool __fastcall MainSwitch(bool State);
bool __fastcall ConverterSwitch(bool State);
bool __fastcall CompressorSwitch(bool State);
bool __fastcall FuseOn(void);
bool __fastcall FuseFlagCheck(void);
void __fastcall FuseOff(void);
int __fastcall ShowCurrent(Byte AmpN);
double __fastcall v2n(void);
double __fastcall current(double n, double U);
double __fastcall Momentum(double I);
double __fastcall MomentumF(double I, double Iw, Byte SCP);
bool __fastcall CutOffEngine(void);
bool __fastcall MaxCurrentSwitch(bool State);
bool __fastcall ResistorsFlagCheck(void);
bool __fastcall MinCurrentSwitch(bool State);
bool __fastcall AutoRelaySwitch(bool State);
bool __fastcall AutoRelayCheck(void);
bool __fastcall dizel_EngageSwitch(double state);
bool __fastcall dizel_EngageChange(double dt);
bool __fastcall dizel_AutoGearCheck(void);
double __fastcall dizel_fillcheck(Byte mcp);
double __fastcall dizel_Momentum(double dizel_fill, double n, double dt);
bool __fastcall dizel_Update(double dt);
bool __fastcall LoadingDone(double LSpeed, AnsiString LoadInit);
void __fastcall ComputeTotalForce(double dt, double dt1, bool FullVer);
double __fastcall ComputeMovement(double dt, double dt1, const TTrackShape &Shape, TTrackParam &Track
, TTractionParam &ElectricTraction, const TLocation &NewLoc, TRotation &NewRot);
double __fastcall FastComputeMovement(double dt, const TTrackShape &Shape, TTrackParam &Track, const
TLocation &NewLoc, TRotation &NewRot);
bool __fastcall ChangeOffsetH(double DeltaOffset);
__fastcall T_MoverParameters(double VelInitial, AnsiString TypeNameInit, AnsiString NameInit, int LoadInitial
, AnsiString LoadTypeInitial, int Cab);
bool __fastcall LoadChkFile(AnsiString chkpath);
bool __fastcall CheckLocomotiveParameters(bool ReadyFlag, int Dir);
AnsiString __fastcall EngineDescription(int what);
bool __fastcall DoorLeft(bool State);
bool __fastcall DoorRight(bool State);
bool __fastcall DoorBlockedFlag(void);
bool __fastcall PantFront(bool State);
bool __fastcall PantRear(bool State);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall T_MoverParameters(void) : System::TObject() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~T_MoverParameters(void) { }
#pragma option pop
};
struct TCoupling
{
double SpringKB;
double SpringKC;
double beta;
double DmaxB;
double FmaxB;
double DmaxC;
double FmaxC;
TCouplerType CouplerType;
Byte CouplingFlag;
int AllowedFlag;
bool Render;
double CoupleDist;
T_MoverParameters* Connected;
Byte ConnectedNr;
double CForce;
double Dist;
bool CheckCollision;
} ;
//-- var, const, procedure ---------------------------------------------------
static const bool Go = true;
static const bool Hold = false;
static const Shortint ResArraySize = 0x40;
static const Shortint MotorParametersArraySize = 0xa;
static const Shortint maxcc = 0x4;
static const Shortint LocalBrakePosNo = 0xa;
static const Shortint MainBrakeMaxPos = 0xa;
static const Shortint ManualBrakePosNo = 0x14;
static const Shortint LightsSwitchPosNo = 0x10;
static const Shortint dtrack_railwear = 0x2;
static const Shortint dtrack_freerail = 0x4;
static const Shortint dtrack_thinrail = 0x8;
static const Shortint dtrack_railbend = 0x10;
static const Shortint dtrack_plants = 0x20;
static const Shortint dtrack_nomove = 0x40;
static const Byte dtrack_norail = 0x80;
static const Shortint dtrain_thinwheel = 0x1;
static const Shortint dtrain_loadshift = 0x1;
static const Shortint dtrain_wheelwear = 0x2;
static const Shortint dtrain_bearing = 0x4;
static const Shortint dtrain_coupling = 0x8;
static const Shortint dtrain_ventilator = 0x10;
static const Shortint dtrain_loaddamage = 0x10;
static const Shortint dtrain_engine = 0x20;
static const Shortint dtrain_loaddestroyed = 0x20;
static const Shortint dtrain_axle = 0x40;
static const Byte dtrain_out = 0x80;
#define p_elengproblem (1.000000E-02)
#define p_elengdamage (1.000000E-01)
#define p_coupldmg (2.000000E-02)
#define p_derail (1.000000E-03)
#define p_accn (1.000000E-01)
#define p_slippdmg (1.000000E-03)
static const Shortint ctrain_virtual = 0x0;
static const Shortint ctrain_coupler = 0x1;
static const Shortint ctrain_pneumatic = 0x2;
static const Shortint ctrain_controll = 0x4;
static const Shortint ctrain_power = 0x8;
static const Shortint ctrain_passenger = 0x10;
static const Shortint ctrain_scndpneumatic = 0x20;
static const Shortint ctrain_heating = 0x40;
static const Byte ctrain_depot = 0x80;
static const Shortint dbrake_none = 0x0;
static const Shortint dbrake_passive = 0x1;
static const Shortint dbrake_switch = 0x2;
static const Shortint dbrake_reversal = 0x4;
static const Shortint dbrake_automatic = 0x8;
static const Shortint s_waiting = 0x1;
static const Shortint s_aware = 0x2;
static const Shortint s_active = 0x4;
static const Shortint s_CAalarm = 0x8;
static const Shortint s_SHPalarm = 0x10;
static const Shortint s_CAebrake = 0x20;
static const Shortint s_SHPebrake = 0x40;
static const Byte s_CAtest = 0x80;
static const Shortint sound_none = 0x0;
static const Shortint sound_loud = 0x1;
static const Shortint sound_couplerstretch = 0x2;
static const Shortint sound_bufferclamp = 0x4;
static const Shortint sound_bufferbump = 0x8;
static const Shortint sound_relay = 0x10;
static const Shortint sound_manyrelay = 0x20;
static const Shortint sound_brakeacc = 0x40;
extern PACKAGE bool PhysicActivationFlag;
static const Shortint dt_Default = 0x0;
static const Shortint dt_EZT = 0x1;
static const Shortint dt_ET41 = 0x2;
static const Shortint dt_ET42 = 0x4;
static const Shortint dt_PseudoDiesel = 0x8;
static const Shortint dt_ET22 = 0x10;
static const Shortint dt_SN61 = 0x20;
static const Shortint dt_EP05 = 0x40;
static const Byte dt_ET40 = 0x80;
static const Word dt_181 = 0x100;
static const Shortint eimc_s_dfic = 0x0;
static const Shortint eimc_s_dfmax = 0x1;
static const Shortint eimc_s_p = 0x2;
static const Shortint eimc_s_cfu = 0x3;
static const Shortint eimc_s_cim = 0x4;
static const Shortint eimc_s_icif = 0x5;
static const Shortint eimc_f_Uzmax = 0x7;
static const Shortint eimc_f_Uzh = 0x8;
static const Shortint eimc_f_DU = 0x9;
static const Shortint eimc_f_I0 = 0xa;
static const Shortint eimc_f_cfu = 0xb;
static const Shortint eimc_p_F0 = 0xd;
static const Shortint eimc_p_a1 = 0xe;
static const Shortint eimc_p_Pmax = 0xf;
static const Shortint eimc_p_Fh = 0x10;
static const Shortint eimc_p_Ph = 0x11;
static const Shortint eimc_p_Vh0 = 0x12;
static const Shortint eimc_p_Vh1 = 0x13;
static const Shortint eimc_p_Imax = 0x14;
static const Shortint eimc_p_abed = 0x15;
static const Shortint eimc_p_eped = 0x16;
static const Shortint eimv_FMAXMAX = 0x0;
static const Shortint eimv_Fmax = 0x1;
static const Shortint eimv_ks = 0x2;
static const Shortint eimv_df = 0x3;
static const Shortint eimv_fp = 0x4;
static const Shortint eimv_U = 0x5;
static const Shortint eimv_pole = 0x6;
static const Shortint eimv_Ic = 0x7;
static const Shortint eimv_If = 0x8;
static const Shortint eimv_M = 0x9;
static const Shortint eimv_Fr = 0xa;
static const Shortint eimv_Ipoj = 0xb;
static const Shortint eimv_Pm = 0xc;
static const Shortint eimv_Pe = 0xd;
static const Shortint eimv_eta = 0xe;
static const Shortint eimv_fkr = 0xf;
static const Shortint eimv_Uzsmax = 0x10;
static const Shortint eimv_Pmax = 0x11;
static const Shortint eimv_Fzad = 0x12;
static const Shortint eimv_Imax = 0x13;
static const Shortint eimv_Fful = 0x14;
static const Shortint bom_PS = 0x1;
static const Shortint bom_PN = 0x2;
static const Shortint bom_EP = 0x4;
static const Shortint bom_MED = 0x8;
extern PACKAGE double __fastcall Distance(const TLocation &Loc1, const TLocation &Loc2, const TDimension
&Dim1, const TDimension &Dim2);
} /* namespace _mover */
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace _mover;
#endif
#pragma option pop // -w-
#pragma option pop // -Vx
#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif // _mover

7596
old/_mover.pas Normal file

File diff suppressed because it is too large Load Diff

232
old/friction.hpp Normal file
View File

@@ -0,0 +1,232 @@
// Borland C++ Builder
// Copyright (c) 1995, 1999 by Borland International
// All rights reserved
// (DO NOT EDIT: machine generated header) 'friction.pas' rev: 5.00
#ifndef frictionHPP
#define frictionHPP
#pragma delphiheader begin
#pragma option push -w-
#pragma option push -Vx
#include <SysUtils.hpp> // Pascal unit
#include <mctools.hpp> // Pascal unit
#include <SysInit.hpp> // Pascal unit
#include <System.hpp> // Pascal unit
//-- user supplied -----------------------------------------------------------
namespace Friction
{
//-- type declarations -------------------------------------------------------
class DELPHICLASS TFricMat;
class PASCALIMPLEMENTATION TFricMat : public System::TObject
{
typedef System::TObject inherited;
public:
virtual double __fastcall GetFC(double N, double Vel);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TFricMat(void) : System::TObject() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TFricMat(void) { }
#pragma option pop
};
class DELPHICLASS TP10Bg;
class PASCALIMPLEMENTATION TP10Bg : public TFricMat
{
typedef TFricMat inherited;
public:
virtual double __fastcall GetFC(double N, double Vel);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TP10Bg(void) : TFricMat() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TP10Bg(void) { }
#pragma option pop
};
class DELPHICLASS TP10Bgu;
class PASCALIMPLEMENTATION TP10Bgu : public TFricMat
{
typedef TFricMat inherited;
public:
virtual double __fastcall GetFC(double N, double Vel);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TP10Bgu(void) : TFricMat() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TP10Bgu(void) { }
#pragma option pop
};
class DELPHICLASS TP10yBg;
class PASCALIMPLEMENTATION TP10yBg : public TFricMat
{
typedef TFricMat inherited;
public:
virtual double __fastcall GetFC(double N, double Vel);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TP10yBg(void) : TFricMat() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TP10yBg(void) { }
#pragma option pop
};
class DELPHICLASS TP10yBgu;
class PASCALIMPLEMENTATION TP10yBgu : public TFricMat
{
typedef TFricMat inherited;
public:
virtual double __fastcall GetFC(double N, double Vel);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TP10yBgu(void) : TFricMat() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TP10yBgu(void) { }
#pragma option pop
};
class DELPHICLASS TP10;
class PASCALIMPLEMENTATION TP10 : public TFricMat
{
typedef TFricMat inherited;
public:
virtual double __fastcall GetFC(double N, double Vel);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TP10(void) : TFricMat() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TP10(void) { }
#pragma option pop
};
class DELPHICLASS TFR513;
class PASCALIMPLEMENTATION TFR513 : public TFricMat
{
typedef TFricMat inherited;
public:
virtual double __fastcall GetFC(double N, double Vel);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TFR513(void) : TFricMat() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TFR513(void) { }
#pragma option pop
};
class DELPHICLASS TFR510;
class PASCALIMPLEMENTATION TFR510 : public TFricMat
{
typedef TFricMat inherited;
public:
virtual double __fastcall GetFC(double N, double Vel);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TFR510(void) : TFricMat() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TFR510(void) { }
#pragma option pop
};
class DELPHICLASS TCosid;
class PASCALIMPLEMENTATION TCosid : public TFricMat
{
typedef TFricMat inherited;
public:
virtual double __fastcall GetFC(double N, double Vel);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TCosid(void) : TFricMat() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TCosid(void) { }
#pragma option pop
};
class DELPHICLASS TDisk1;
class PASCALIMPLEMENTATION TDisk1 : public TFricMat
{
typedef TFricMat inherited;
public:
virtual double __fastcall GetFC(double N, double Vel);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TDisk1(void) : TFricMat() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TDisk1(void) { }
#pragma option pop
};
class DELPHICLASS TDisk2;
class PASCALIMPLEMENTATION TDisk2 : public TFricMat
{
typedef TFricMat inherited;
public:
virtual double __fastcall GetFC(double N, double Vel);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TDisk2(void) : TFricMat() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TDisk2(void) { }
#pragma option pop
};
//-- var, const, procedure ---------------------------------------------------
} /* namespace Friction */
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Friction;
#endif
#pragma option pop // -w-
#pragma option pop // -Vx
#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif // friction

182
old/friction.pas Normal file
View File

@@ -0,0 +1,182 @@
unit friction; {wspolczynnik tarcia roznych materialow}
(*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*)
(*
MaSzyna EU07 - SPKS
Friction coefficient.
Copyright (C) 2007-2013 Maciej Cierniak
*)
(*
(C) youBy
Co brakuje:
- hamulce tarczowe
- kompozyty
*)
(*
Zrobione:
1) zadeklarowane niektore typy
2) wzor jubaja na tarcie wstawek Bg i Bgu z zeliwa P10
3) hamulec tarczowy marki 152A ;)
*)
interface
//uses hamulce;
uses mctools,sysutils;
TYPE
TFricMat = class
public
function GetFC(N, Vel: real): real; virtual;
end;
TP10Bg = class(TFricMat)
public
function GetFC(N, Vel: real): real; override;
end;
TP10Bgu = class(TFricMat)
public
function GetFC(N, Vel: real): real; override;
end;
TP10yBg = class(TFricMat)
public
function GetFC(N, Vel: real): real; override;
end;
TP10yBgu = class(TFricMat)
public
function GetFC(N, Vel: real): real; override;
end;
TP10 = class(TFricMat)
public
function GetFC(N, Vel: real): real; override;
end;
TFR513 = class(TFricMat)
public
function GetFC(N, Vel: real): real; override;
end;
TFR510 = class(TFricMat)
public
function GetFC(N, Vel: real): real; override;
end;
TCosid = class(TFricMat)
public
function GetFC(N, Vel: real): real; override;
end;
TDisk1 = class(TFricMat)
public
function GetFC(N, Vel: real): real; override;
end;
TDisk2 = class(TFricMat)
public
function GetFC(N, Vel: real): real; override;
end;
implementation
function TFricMat.GetFC(N, Vel: real): real;
begin
GetFC:=1;
end;
function TP10Bg.GetFC(N, Vel: real): real;
begin
// GetFC:=0.60*((1.6*N+100)/(8.0*N+100))*((Vel+100)/(5*Vel+100))*(1.0032-0.0007*N-0.0001*N*N);
// GetFC:=47/(2*Vel+100)*(2.145-0.0538*N+0.00074*N*N-0.00000536*N*N*N)/2.145;
// GetFC:=46/(2*Vel+100)*(11.33-0.105*N)/(11.33+0.179*N);
// GetFC:=49/(2*Vel+100)*(13.08-0.083*N)/(12.94+0.285*N);
//if Vel<20 then Vel:=20;
// Vel:= Vel-20;
// GetFC:=0.52*((1*Vel+100)/(5.0*Vel+100))*(13.08-0.083*N)/(12.94+0.285*N);
// GetFC:=Min0R(0.67*(1*(277-2.66*Vel)/(100+2.1*Vel)+0.23*(-686+8.27*Vel)/(100+1.16*Vel))*(13.08-0.083*N)/(12.94+0.285*N),0.4);
GetFC:=exp(-0.022*N)*(0.19-0.095*exp(-Vel/25.7))+0.384*exp(-Vel/25.7)-0.028;
end;
function TP10Bgu.GetFC(N, Vel: real): real;
begin
// GetFC:=0.60*((1.6*N+100)/(8.0*N+100))*((Vel+100)/(5*Vel+100));
// GetFC:=47/(2*Vel+100)*(2.137-0.0514*N+0.000832*N*N-0.00000604*N*N*N)/2.137;
// GetFC:=0.49*100/(2*Vel+100)*(11.33-0.013*N)/(11.33+0.280*N);
// GetFC:=0.52*((Vel+100)/(5.0*Vel+100))*(11.33-0.013*N)/(11.33+0.280*N);
//if Vel<20 then Vel:=20;
// Vel:= Vel-20;
// GetFC:=0.52*((0.0*Vel+120)/(5*Vel+100))*(11.33-0.013*N)/(11.33+0.280*N);
// GetFC:=0.49*100/(3*Vel+100)*(11.33-0.013*N)/(11.33+0.280*N);
// GetFC:=Min0R(0.67*(1*(277-2.66*Vel)/(100+2.1*Vel)+0.23*(-686+8.27*Vel)/(100+1.16*Vel))*(11.33-0.013*N)/(11.33+0.280*N),0.4);
GetFC:=exp(-0.017*N)*(0.18-0.09*exp(-Vel/25.7))+0.381*exp(-Vel/25.7)-0.022;//0.05*exp(-0.2*N);
end;
function TP10yBg.GetFC(N, Vel: real): real;
var A,C,u0, V0: real;
begin
A:=2.135*exp(-0.03726*N)-0.5;
C:=0.353-A*0.029;
u0:=0.41-C;
V0:=25.7+20*A;
GetFC:=(u0+C*exp(-Vel/V0));
end;
function TP10yBgu.GetFC(N, Vel: real): real;
var A,C,u0, V0: real;
begin
A:=1.68*exp(-0.02735*N)-0.5;
C:=0.353-A*0.044;
u0:=0.41-C;
V0:=25.7+21*A;
GetFC:=(u0+C*exp(-Vel/V0));
end;
function TP10.GetFC(N, Vel: real): real;
begin
GetFC:=0.60*((1.6*N+100)/(8.0*N+100))*((Vel+100)/(5*Vel+100));
// GetFC:=43/(2*Vel+100)*(2.145-0.0538*N+0.00074*N*N-0.00000536*N*N*N)/2.145
end;
function TFR513.GetFC(N, Vel: real): real;
begin
GetFC:=0.3-Vel*0.00081;
// GetFC:=43/(2*Vel+100)*(2.145-0.0538*N+0.00074*N*N-0.00000536*N*N*N)/2.145
end;
function TCosid.GetFC(N, Vel: real): real;
begin
GetFC:=0.27;
end;
function TDisk1.GetFC(N, Vel: real): real;
begin
GetFC:=0.2375+0.000885*N-0.000345*N*N;
end;
function TDisk2.GetFC(N, Vel: real): real;
begin
GetFC:=0.27;
end;
function TFR510.GetFC(N, Vel: real): real;
begin
GetFC:=0.15;
end;
end.

881
old/hamulce.hpp Normal file
View File

@@ -0,0 +1,881 @@
// Borland C++ Builder
// Copyright (c) 1995, 1999 by Borland International
// All rights reserved
// (DO NOT EDIT: machine generated header) 'hamulce.pas' rev: 5.00
#ifndef hamulceHPP
#define hamulceHPP
#pragma delphiheader begin
#pragma option push -w-
#pragma option push -Vx
#include <friction.h> // Pascal unit
#include <SysUtils.hpp> // Pascal unit
#include <mctools.hpp> // Pascal unit
#include <SysInit.hpp> // Pascal unit
#include <System.hpp> // Pascal unit
//-- user supplied -----------------------------------------------------------
namespace Hamulce
{
//-- type declarations -------------------------------------------------------
class DELPHICLASS TReservoir;
class PASCALIMPLEMENTATION TReservoir : public System::TObject
{
typedef System::TObject inherited;
protected:
double Cap;
double Vol;
double dVol;
public:
__fastcall TReservoir(void);
void __fastcall CreateCap(double Capacity);
void __fastcall CreatePress(double Press);
virtual double __fastcall pa(void);
virtual double __fastcall P(void);
void __fastcall Flow(double dv);
void __fastcall Act(void);
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TReservoir(void) { }
#pragma option pop
};
typedef TReservoir* *PReservoir;
class DELPHICLASS TBrakeCyl;
class PASCALIMPLEMENTATION TBrakeCyl : public TReservoir
{
typedef TReservoir inherited;
public:
virtual double __fastcall pa(void);
virtual double __fastcall P(void);
public:
#pragma option push -w-inl
/* TReservoir.Create */ inline __fastcall TBrakeCyl(void) : TReservoir() { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TBrakeCyl(void) { }
#pragma option pop
};
class DELPHICLASS TBrake;
class PASCALIMPLEMENTATION TBrake : public System::TObject
{
typedef System::TObject inherited;
protected:
TReservoir* BrakeCyl;
TReservoir* BrakeRes;
TReservoir* ValveRes;
Byte BCN;
double BCM;
double BCA;
Byte BrakeDelays;
Byte BrakeDelayFlag;
Friction::TFricMat* FM;
double MaxBP;
Byte BA;
Byte NBpA;
double SizeBR;
double SizeBC;
bool DCV;
double ASBP;
Byte BrakeStatus;
Byte SoundFlag;
public:
__fastcall TBrake(double i_mbp, double i_bcr, double i_bcd, double i_brc, Byte i_bcn, Byte i_BD, Byte
i_mat, Byte i_ba, Byte i_nbpa);
virtual double __fastcall GetFC(double Vel, double N);
virtual double __fastcall GetPF(double PP, double dt, double Vel);
double __fastcall GetBCF(void);
virtual double __fastcall GetHPFlow(double HP, double dt);
virtual double __fastcall GetBCP(void);
double __fastcall GetBRP(void);
double __fastcall GetVRP(void);
virtual double __fastcall GetCRP(void);
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
bool __fastcall SetBDF(Byte nBDF);
void __fastcall Releaser(Byte state);
virtual void __fastcall SetEPS(double nEPS);
void __fastcall ASB(Byte state);
Byte __fastcall GetStatus(void);
void __fastcall SetASBP(double press);
virtual void __fastcall ForceEmptiness(void);
Byte __fastcall GetSoundFlag(void);
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TBrake(void) { }
#pragma option pop
};
class DELPHICLASS TWest;
class PASCALIMPLEMENTATION TWest : public TBrake
{
typedef TBrake inherited;
private:
double LBP;
double dVP;
double EPS;
double TareM;
double LoadM;
double TareBP;
double LoadC;
public:
void __fastcall SetLBP(double P);
virtual double __fastcall GetPF(double PP, double dt, double Vel);
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
virtual double __fastcall GetHPFlow(double HP, double dt);
void __fastcall PLC(double mass);
virtual void __fastcall SetEPS(double nEPS);
void __fastcall SetLP(double TM, double LM, double TBP);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TWest(double i_mbp, double i_bcr, double i_bcd, double i_brc,
Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TBrake(i_mbp, i_bcr, i_bcd, i_brc, i_bcn
, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TWest(void) { }
#pragma option pop
};
class DELPHICLASS TESt;
class PASCALIMPLEMENTATION TESt : public TBrake
{
typedef TBrake inherited;
private:
TReservoir* CntrlRes;
double BVM;
public:
virtual double __fastcall GetPF(double PP, double dt, double Vel);
void __fastcall EStParams(double i_crc);
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
virtual double __fastcall GetCRP(void);
void __fastcall CheckState(double BCP, double &dV1);
void __fastcall CheckReleaser(double dt);
double __fastcall CVs(double bp);
double __fastcall BVs(double BCP);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TESt(double i_mbp, double i_bcr, double i_bcd, double i_brc,
Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TBrake(i_mbp, i_bcr, i_bcd, i_brc, i_bcn
, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TESt(void) { }
#pragma option pop
};
class DELPHICLASS TESt3;
class PASCALIMPLEMENTATION TESt3 : public TESt
{
typedef TESt inherited;
private:
double CylFlowSpeed[2][2];
public:
virtual double __fastcall GetPF(double PP, double dt, double Vel);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TESt3(double i_mbp, double i_bcr, double i_bcd, double i_brc,
Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TESt(i_mbp, i_bcr, i_bcd, i_brc, i_bcn
, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TESt3(void) { }
#pragma option pop
};
class DELPHICLASS TESt3AL2;
class PASCALIMPLEMENTATION TESt3AL2 : public TESt3
{
typedef TESt3 inherited;
private:
double TareM;
double LoadM;
double TareBP;
double LoadC;
public:
TReservoir* ImplsRes;
virtual double __fastcall GetPF(double PP, double dt, double Vel);
void __fastcall PLC(double mass);
void __fastcall SetLP(double TM, double LM, double TBP);
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TESt3AL2(double i_mbp, double i_bcr, double i_bcd, double i_brc
, Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TESt3(i_mbp, i_bcr, i_bcd, i_brc, i_bcn
, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TESt3AL2(void) { }
#pragma option pop
};
class DELPHICLASS TESt4R;
class PASCALIMPLEMENTATION TESt4R : public TESt
{
typedef TESt inherited;
private:
bool RapidStatus;
double RapidTemp;
public:
TReservoir* ImplsRes;
virtual double __fastcall GetPF(double PP, double dt, double Vel);
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TESt4R(double i_mbp, double i_bcr, double i_bcd, double i_brc
, Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TESt(i_mbp, i_bcr, i_bcd, i_brc, i_bcn
, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TESt4R(void) { }
#pragma option pop
};
class DELPHICLASS TLSt;
class PASCALIMPLEMENTATION TLSt : public TESt4R
{
typedef TESt4R inherited;
private:
double CylFlowSpeed[2][2];
double LBP;
double RM;
double EDFlag;
public:
void __fastcall SetLBP(double P);
void __fastcall SetRM(double RMR);
virtual double __fastcall GetPF(double PP, double dt, double Vel);
virtual double __fastcall GetHPFlow(double HP, double dt);
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
virtual double __fastcall GetEDBCP(void);
void __fastcall SetED(double EDstate);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TLSt(double i_mbp, double i_bcr, double i_bcd, double i_brc,
Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TESt4R(i_mbp, i_bcr, i_bcd, i_brc, i_bcn
, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TLSt(void) { }
#pragma option pop
};
class DELPHICLASS TEStED;
class PASCALIMPLEMENTATION TEStED : public TLSt
{
typedef TLSt inherited;
private:
double Nozzles[11];
bool Zamykajacy;
bool Przys_blok;
TReservoir* Miedzypoj;
double TareM;
double LoadM;
double TareBP;
double LoadC;
public:
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
virtual double __fastcall GetPF(double PP, double dt, double Vel);
virtual double __fastcall GetEDBCP(void);
void __fastcall PLC(double mass);
void __fastcall SetLP(double TM, double LM, double TBP);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TEStED(double i_mbp, double i_bcr, double i_bcd, double i_brc
, Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TLSt(i_mbp, i_bcr, i_bcd, i_brc, i_bcn
, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TEStED(void) { }
#pragma option pop
};
class DELPHICLASS TEStEP2;
class PASCALIMPLEMENTATION TEStEP2 : public TLSt
{
typedef TLSt inherited;
private:
double TareM;
double LoadM;
double TareBP;
double LoadC;
double EPS;
public:
virtual double __fastcall GetPF(double PP, double dt, double Vel);
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
void __fastcall PLC(double mass);
virtual void __fastcall SetEPS(double nEPS);
void __fastcall SetLP(double TM, double LM, double TBP);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TEStEP2(double i_mbp, double i_bcr, double i_bcd, double i_brc
, Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TLSt(i_mbp, i_bcr, i_bcd, i_brc, i_bcn
, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TEStEP2(void) { }
#pragma option pop
};
class DELPHICLASS TCV1;
class PASCALIMPLEMENTATION TCV1 : public TBrake
{
typedef TBrake inherited;
private:
TReservoir* CntrlRes;
double BVM;
public:
virtual double __fastcall GetPF(double PP, double dt, double Vel);
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
virtual double __fastcall GetCRP(void);
void __fastcall CheckState(double BCP, double &dV1);
double __fastcall CVs(double bp);
double __fastcall BVs(double BCP);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TCV1(double i_mbp, double i_bcr, double i_bcd, double i_brc,
Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TBrake(i_mbp, i_bcr, i_bcd, i_brc, i_bcn
, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TCV1(void) { }
#pragma option pop
};
class DELPHICLASS TCV1R;
class PASCALIMPLEMENTATION TCV1R : public TCV1
{
typedef TCV1 inherited;
private:
TReservoir* ImplsRes;
bool RapidStatus;
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TCV1R(double i_mbp, double i_bcr, double i_bcd, double i_brc,
Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TCV1(i_mbp, i_bcr, i_bcd, i_brc, i_bcn
, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TCV1R(void) { }
#pragma option pop
};
class DELPHICLASS TCV1L_TR;
class PASCALIMPLEMENTATION TCV1L_TR : public TCV1
{
typedef TCV1 inherited;
private:
TReservoir* ImplsRes;
double LBP;
public:
virtual double __fastcall GetPF(double PP, double dt, double Vel);
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
void __fastcall SetLBP(double P);
virtual double __fastcall GetHPFlow(double HP, double dt);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TCV1L_TR(double i_mbp, double i_bcr, double i_bcd, double i_brc
, Byte i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TCV1(i_mbp, i_bcr, i_bcd, i_brc, i_bcn
, i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TCV1L_TR(void) { }
#pragma option pop
};
class DELPHICLASS TKE;
class PASCALIMPLEMENTATION TKE : public TBrake
{
typedef TBrake inherited;
private:
bool RapidStatus;
TReservoir* ImplsRes;
TReservoir* CntrlRes;
TReservoir* Brak2Res;
double BVM;
double TareM;
double LoadM;
double TareBP;
double LoadC;
double RM;
double LBP;
public:
void __fastcall SetRM(double RMR);
virtual double __fastcall GetPF(double PP, double dt, double Vel);
virtual void __fastcall Init(double PP, double HPP, double LPP, double BP, Byte BDF);
virtual double __fastcall GetHPFlow(double HP, double dt);
virtual double __fastcall GetCRP(void);
void __fastcall CheckState(double BCP, double &dV1);
void __fastcall CheckReleaser(double dt);
double __fastcall CVs(double bp);
double __fastcall BVs(double BCP);
void __fastcall PLC(double mass);
void __fastcall SetLP(double TM, double LM, double TBP);
void __fastcall SetLBP(double P);
public:
#pragma option push -w-inl
/* TBrake.Create */ inline __fastcall TKE(double i_mbp, double i_bcr, double i_bcd, double i_brc, Byte
i_bcn, Byte i_BD, Byte i_mat, Byte i_ba, Byte i_nbpa) : TBrake(i_mbp, i_bcr, i_bcd, i_brc, i_bcn,
i_BD, i_mat, i_ba, i_nbpa) { }
#pragma option pop
public:
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TKE(void) { }
#pragma option pop
};
class DELPHICLASS THandle;
class PASCALIMPLEMENTATION THandle : public System::TObject
{
typedef System::TObject inherited;
public:
bool Time;
bool TimeEP;
double Sounds[5];
virtual double __fastcall GetPF(double i_bcp, double pp, double hp, double dt, double ep);
virtual void __fastcall Init(double press);
virtual double __fastcall GetCP(void);
virtual void __fastcall SetReductor(double nAdj);
virtual double __fastcall GetSound(Byte i);
virtual double __fastcall GetPos(Byte i);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall THandle(void) : System::TObject() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~THandle(void) { }
#pragma option pop
};
class DELPHICLASS TFV4a;
class PASCALIMPLEMENTATION TFV4a : public THandle
{
typedef THandle inherited;
private:
double CP;
double TP;
double RP;
public:
virtual double __fastcall GetPF(double i_bcp, double pp, double hp, double dt, double ep);
virtual void __fastcall Init(double press);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TFV4a(void) : THandle() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TFV4a(void) { }
#pragma option pop
};
class DELPHICLASS TFV4aM;
class PASCALIMPLEMENTATION TFV4aM : public THandle
{
typedef THandle inherited;
private:
double CP;
double TP;
double RP;
double XP;
double RedAdj;
bool Fala;
public:
virtual double __fastcall GetPF(double i_bcp, double pp, double hp, double dt, double ep);
virtual void __fastcall Init(double press);
virtual void __fastcall SetReductor(double nAdj);
virtual double __fastcall GetSound(Byte i);
virtual double __fastcall GetPos(Byte i);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TFV4aM(void) : THandle() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TFV4aM(void) { }
#pragma option pop
};
class DELPHICLASS TMHZ_EN57;
class PASCALIMPLEMENTATION TMHZ_EN57 : public THandle
{
typedef THandle inherited;
private:
double CP;
double TP;
double RP;
double RedAdj;
bool Fala;
public:
virtual double __fastcall GetPF(double i_bcp, double pp, double hp, double dt, double ep);
virtual void __fastcall Init(double press);
virtual void __fastcall SetReductor(double nAdj);
virtual double __fastcall GetSound(Byte i);
virtual double __fastcall GetPos(Byte i);
virtual double __fastcall GetCP(void);
double __fastcall GetEP(double pos);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TMHZ_EN57(void) : THandle() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TMHZ_EN57(void) { }
#pragma option pop
};
class DELPHICLASS TM394;
class PASCALIMPLEMENTATION TM394 : public THandle
{
typedef THandle inherited;
private:
double CP;
double RedAdj;
public:
virtual double __fastcall GetPF(double i_bcp, double pp, double hp, double dt, double ep);
virtual void __fastcall Init(double press);
virtual void __fastcall SetReductor(double nAdj);
virtual double __fastcall GetCP(void);
virtual double __fastcall GetPos(Byte i);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TM394(void) : THandle() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TM394(void) { }
#pragma option pop
};
class DELPHICLASS TH14K1;
class PASCALIMPLEMENTATION TH14K1 : public THandle
{
typedef THandle inherited;
private:
double CP;
double RedAdj;
public:
virtual double __fastcall GetPF(double i_bcp, double pp, double hp, double dt, double ep);
virtual void __fastcall Init(double press);
virtual void __fastcall SetReductor(double nAdj);
virtual double __fastcall GetCP(void);
virtual double __fastcall GetPos(Byte i);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TH14K1(void) : THandle() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TH14K1(void) { }
#pragma option pop
};
class DELPHICLASS TSt113;
class PASCALIMPLEMENTATION TSt113 : public TH14K1
{
typedef TH14K1 inherited;
private:
double EPS;
public:
virtual double __fastcall GetPF(double i_bcp, double pp, double hp, double dt, double ep);
virtual double __fastcall GetCP(void);
virtual double __fastcall GetPos(Byte i);
virtual void __fastcall Init(double press);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TSt113(void) : TH14K1() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TSt113(void) { }
#pragma option pop
};
class DELPHICLASS Ttest;
class PASCALIMPLEMENTATION Ttest : public THandle
{
typedef THandle inherited;
private:
double CP;
public:
virtual double __fastcall GetPF(double i_bcp, double pp, double hp, double dt, double ep);
virtual void __fastcall Init(double press);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall Ttest(void) : THandle() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~Ttest(void) { }
#pragma option pop
};
class DELPHICLASS TFD1;
class PASCALIMPLEMENTATION TFD1 : public THandle
{
typedef THandle inherited;
private:
double MaxBP;
double BP;
public:
double Speed;
virtual double __fastcall GetPF(double i_bcp, double pp, double hp, double dt, double ep);
virtual void __fastcall Init(double press);
virtual double __fastcall GetCP(void);
void __fastcall SetSpeed(double nSpeed);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TFD1(void) : THandle() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TFD1(void) { }
#pragma option pop
};
class DELPHICLASS TH1405;
class PASCALIMPLEMENTATION TH1405 : public THandle
{
typedef THandle inherited;
private:
double MaxBP;
double BP;
public:
virtual double __fastcall GetPF(double i_bcp, double pp, double hp, double dt, double ep);
virtual void __fastcall Init(double press);
virtual double __fastcall GetCP(void);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TH1405(void) : THandle() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TH1405(void) { }
#pragma option pop
};
class DELPHICLASS TFVel6;
class PASCALIMPLEMENTATION TFVel6 : public THandle
{
typedef THandle inherited;
private:
double EPS;
public:
virtual double __fastcall GetPF(double i_bcp, double pp, double hp, double dt, double ep);
virtual double __fastcall GetCP(void);
virtual double __fastcall GetPos(Byte i);
virtual double __fastcall GetSound(Byte i);
virtual void __fastcall Init(double press);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TFVel6(void) : THandle() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TFVel6(void) { }
#pragma option pop
};
//-- var, const, procedure ---------------------------------------------------
static const Shortint LocalBrakePosNo = 0xa;
static const Shortint MainBrakeMaxPos = 0xa;
static const Shortint bdelay_G = 0x1;
static const Shortint bdelay_P = 0x2;
static const Shortint bdelay_R = 0x4;
static const Shortint bdelay_M = 0x8;
static const Byte bdelay_GR = 0x80;
static const Shortint b_off = 0x0;
static const Shortint b_hld = 0x1;
static const Shortint b_on = 0x2;
static const Shortint b_rfl = 0x4;
static const Shortint b_rls = 0x8;
static const Shortint b_ep = 0x10;
static const Shortint b_asb = 0x20;
static const Byte b_dmg = 0x80;
static const Shortint df_on = 0x1;
static const Shortint df_off = 0x2;
static const Shortint df_br = 0x4;
static const Shortint df_vv = 0x8;
static const Shortint df_bc = 0x10;
static const Shortint df_cv = 0x20;
static const Shortint df_PP = 0x40;
static const Byte df_RR = 0x80;
static const Shortint s_fv4a_b = 0x0;
static const Shortint s_fv4a_u = 0x1;
static const Shortint s_fv4a_e = 0x2;
static const Shortint s_fv4a_x = 0x3;
static const Shortint s_fv4a_t = 0x4;
static const Shortint bp_P10 = 0x0;
static const Shortint bp_P10Bg = 0x2;
static const Shortint bp_P10Bgu = 0x1;
static const Shortint bp_LLBg = 0x4;
static const Shortint bp_LLBgu = 0x3;
static const Shortint bp_LBg = 0x6;
static const Shortint bp_LBgu = 0x5;
static const Shortint bp_KBg = 0x8;
static const Shortint bp_KBgu = 0x7;
static const Shortint bp_D1 = 0x9;
static const Shortint bp_D2 = 0xa;
static const Shortint bp_FR513 = 0xb;
static const Shortint bp_Cosid = 0xc;
static const Shortint bp_PKPBg = 0xd;
static const Shortint bp_PKPBgu = 0xe;
static const Byte bp_MHS = 0x80;
static const Shortint bp_P10yBg = 0xf;
static const Shortint bp_P10yBgu = 0x10;
static const Shortint bp_FR510 = 0x11;
static const Shortint sf_Acc = 0x1;
static const Shortint sf_BR = 0x2;
static const Shortint sf_CylB = 0x4;
static const Shortint sf_CylU = 0x8;
static const Shortint sf_rel = 0x10;
static const Shortint sf_ep = 0x20;
static const Shortint bh_MIN = 0x0;
static const Shortint bh_MAX = 0x1;
static const Shortint bh_FS = 0x2;
static const Shortint bh_RP = 0x3;
static const Shortint bh_NP = 0x4;
static const Shortint bh_MB = 0x5;
static const Shortint bh_FB = 0x6;
static const Shortint bh_EB = 0x7;
static const Shortint bh_EPR = 0x8;
static const Shortint bh_EPN = 0x9;
static const Shortint bh_EPB = 0xa;
#define SpgD (7.917000E-01)
#define SpO (5.067000E-01)
extern PACKAGE double BPT[9][2];
extern PACKAGE double BPT_394[7][2];
static const Shortint i_bcpno = 0x6;
extern PACKAGE double __fastcall PF(double P1, double P2, double S, double DP);
extern PACKAGE double __fastcall PF1(double P1, double P2, double S);
extern PACKAGE double __fastcall PFVa(double PH, double PL, double S, double LIM, double DP);
extern PACKAGE double __fastcall PFVd(double PH, double PL, double S, double LIM, double DP);
} /* namespace Hamulce */
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Hamulce;
#endif
#pragma option pop // -w-
#pragma option pop // -Vx
#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif // hamulce

3200
old/hamulce.pas Normal file

File diff suppressed because it is too large Load Diff

69
old/klasy_ham.pas Normal file
View File

@@ -0,0 +1,69 @@
unit klasy_ham; {fizyka hamulcow dla symulatora}
(*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*)
(*
MaSzyna EU07 - SPKS
Brakes. Basic classes.
Copyright (C) 2007-2013 Maciej Cierniak
*)
interface
uses mctools,sysutils;
//CONST;
TYPE
TRurka= class //bezposrednie polaczenie, co wleci to wyleci
private
Vol: real;
Cap: real;
public
function Update(dt: real);
procedure Flow(dV: real);
end;
PRurka= ^TRurka;
TTrojnik= class(TRurka)
private
Wyjscie1: PRurka;
Wyjscie2: PRurka;
Wyjscie3: PRurka;
public
end;
TZbiornik= class(TRurka)
private
Wyjscie_jeden: PRurka;
public
end;
TPowtarzacz= class(TRurka)
private
public
end;
TPrzekladnik= class(TPowtarzacz)
private
public
end;
function PF(P1,P2,S:real):real;
implementation
end.

322
old/mctools.cpp Normal file
View File

@@ -0,0 +1,322 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
/*
MaSzyna EU07 - SPKS
Brakes.
Copyright (C) 2007-2014 Maciej Cierniak
*/
#include "stdafx.h"
#include "mctools.h"
#include <sys/types.h>
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
#endif
#ifdef WIN32
#define stat _stat
#endif
#include "Globals.h"
/*================================================*/
bool DebugModeFlag = false;
bool FreeFlyModeFlag = false;
bool EditorModeFlag = true;
bool DebugCameraFlag = false;
double Max0R(double x1, double x2)
{
if (x1 > x2)
return x1;
else
return x2;
}
double Min0R(double x1, double x2)
{
if (x1 < x2)
return x1;
else
return x2;
}
// shitty replacement for Borland timestamp function
// TODO: replace with something sensible
std::string Now() {
std::time_t timenow = std::time( nullptr );
std::tm tm = *std::localtime( &timenow );
std::stringstream converter;
converter << std::put_time( &tm, "%c" );
return converter.str();
}
bool SetFlag( int &Flag, int const Value ) {
if( Value > 0 ) {
if( false == TestFlag( Flag, Value ) ) {
Flag |= Value;
return true; // true, gdy było wcześniej 0 i zostało ustawione
}
}
else if( Value < 0 ) {
// Value jest ujemne, czyli zerowanie flagi
return ClearFlag( Flag, -Value );
}
return false;
}
bool ClearFlag( int &Flag, int const Value ) {
if( true == TestFlag( Flag, Value ) ) {
Flag &= ~Value;
return true;
}
else {
return false;
}
}
inline double Random(double a, double b)
{
std::uniform_real_distribution<> dis(a, b);
return dis(Global.random_engine);
}
bool FuzzyLogic(double Test, double Threshold, double Probability)
{
if ((Test > Threshold) && (!DebugModeFlag))
return
(Random() < Probability * Threshold * 1.0 / Test) /*im wiekszy Test tym wieksza szansa*/;
else
return false;
}
bool FuzzyLogicAI(double Test, double Threshold, double Probability)
{
if ((Test > Threshold))
return
(Random() < Probability * Threshold * 1.0 / Test) /*im wiekszy Test tym wieksza szansa*/;
else
return false;
}
std::string DUE(std::string s) /*Delete Before Equal sign*/
{
//DUE = Copy(s, Pos("=", s) + 1, length(s));
return s.substr(s.find("=") + 1, s.length());
}
std::string DWE(std::string s) /*Delete After Equal sign*/
{
size_t ep = s.find("=");
if (ep != std::string::npos)
//DWE = Copy(s, 1, ep - 1);
return s.substr(0, ep);
else
return s;
}
std::string ExchangeCharInString( std::string const &Source, char const From, char const To )
{
std::string replacement; replacement.reserve( Source.size() );
std::for_each(
std::begin( Source ), std::end( Source ),
[&](char const idx) {
if( idx != From ) { replacement += idx; }
else { replacement += To; } } );
return replacement;
}
std::vector<std::string> &Split(const std::string &s, char delim, std::vector<std::string> &elems)
{ // dzieli tekst na wektor tekstow
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim))
{
elems.push_back(item);
}
return elems;
}
std::vector<std::string> Split(const std::string &s, char delim)
{ // dzieli tekst na wektor tekstow
std::vector<std::string> elems;
Split(s, delim, elems);
return elems;
}
std::vector<std::string> Split(const std::string &s)
{ // dzieli tekst na wektor tekstow po białych znakach
std::vector<std::string> elems;
std::stringstream ss(s);
std::string item;
while (ss >> item)
{
elems.push_back(item);
}
return elems;
}
std::string to_string(int _Val)
{
std::ostringstream o;
o << _Val;
return o.str();
};
std::string to_string(unsigned int _Val)
{
std::ostringstream o;
o << _Val;
return o.str();
};
std::string to_string(double _Val)
{
std::ostringstream o;
o << _Val;
return o.str();
};
std::string to_string(int _Val, int precision)
{
std::ostringstream o;
o << std::fixed << std::setprecision(precision);
o << _Val;
return o.str();
};
std::string to_string(double _Val, int precision)
{
std::ostringstream o;
o << std::fixed << std::setprecision(precision);
o << _Val;
return o.str();
};
std::string to_string(int _Val, int precision, int width)
{
std::ostringstream o;
o.width(width);
o << std::fixed << std::setprecision(precision);
o << _Val;
return o.str();
};
std::string to_string(double const Value, int const Precision, int const Width)
{
std::ostringstream converter;
converter << std::setw( Width ) << std::fixed << std::setprecision(Precision) << Value;
return converter.str();
};
std::string to_hex_str( int const Value, int const Width )
{
std::ostringstream converter;
converter << "0x" << std::uppercase << std::setfill( '0' ) << std::setw( Width ) << std::hex << Value;
return converter.str();
};
int stol_def(const std::string &str, const int &DefaultValue) {
int result { DefaultValue };
std::stringstream converter;
converter << str;
converter >> result;
return result;
}
std::string ToLower(std::string const &text)
{
std::string lowercase( text );
std::transform(text.begin(), text.end(), lowercase.begin(), ::tolower);
return lowercase;
}
std::string ToUpper(std::string const &text)
{
std::string uppercase( text );
std::transform(text.begin(), text.end(), uppercase.begin(), ::toupper);
return uppercase;
}
// replaces polish letters with basic ascii
void
win1250_to_ascii( std::string &Input ) {
std::unordered_map<char, char> charmap{
{ 165, 'A' }, { 198, 'C' }, { 202, 'E' }, { 163, 'L' }, { 209, 'N' }, { 211, 'O' }, { 140, 'S' }, { 143, 'Z' }, { 175, 'Z' },
{ 185, 'a' }, { 230, 'c' }, { 234, 'e' }, { 179, 'l' }, { 241, 'n' }, { 243, 'o' }, { 156, 's' }, { 159, 'z' }, { 191, 'z' }
};
std::unordered_map<char, char>::const_iterator lookup;
for( auto &input : Input ) {
if( ( lookup = charmap.find( input ) ) != charmap.end() )
input = lookup->second;
}
}
// Ra: tymczasowe rozwiązanie kwestii zagranicznych (czeskich) napisów
char bezogonkowo[] = "E?,?\"_++?%S<STZZ?`'\"\".--??s>stzz"
" ^^L$A|S^CS<--RZo±,l'uP.,as>L\"lz"
"RAAAALCCCEEEEIIDDNNOOOOxRUUUUYTB"
"raaaalccceeeeiiddnnoooo-ruuuuyt?";
std::string Bezogonkow(std::string str, bool _)
{ // wycięcie liter z ogonkami, bo OpenGL nie umie wyświetlić
for (unsigned int i = 1; i < str.length(); ++i)
if (str[i] & 0x80)
str[i] = bezogonkowo[str[i] & 0x7F];
else if (str[i] < ' ') // znaki sterujące nie są obsługiwane
str[i] = ' ';
else if (_)
if (str[i] == '_') // nazwy stacji nie mogą zawierać spacji
str[i] = ' '; // więc trzeba wyświetlać inaczej
return str;
};
template <>
bool
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) {
auto value = extract_value( Key, Input );
if( false == value.empty() ) {
// set the specified variable to retrieved value
Variable = ( ToLower( value ) == "yes" );
return true; // located the variable
}
else {
// set the variable to provided default value
if( false == Default.empty() ) {
Variable = ( ToLower( Default ) == "yes" );
}
return false; // couldn't locate the variable in provided input
}
}
bool
FileExists( std::string const &Filename ) {
std::ifstream file( Filename );
return( true == file.is_open() );
}
// returns time of last modification for specified file
std::time_t
last_modified( std::string const &Filename ) {
struct stat filestat;
if( ::stat( Filename.c_str(), &filestat ) == 0 ) { return filestat.st_mtime; }
else { return 0; }
}

166
old/mctools.h Normal file
View File

@@ -0,0 +1,166 @@
#pragma once
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
/*rozne takie duperele do operacji na stringach w paszczalu, pewnie w delfi sa lepsze*/
/*konwersja zmiennych na stringi, funkcje matematyczne, logiczne, lancuchowe, I/O etc*/
#include <string>
#include <fstream>
#include <ctime>
#include <vector>
#include <sstream>
extern bool DebugModeFlag;
extern bool FreeFlyModeFlag;
extern bool EditorModeFlag;
extern bool DebugCameraFlag;
/*funkcje matematyczne*/
double Max0R(double x1, double x2);
double Min0R(double x1, double x2);
inline double Sign(double x)
{
return x >= 0 ? 1.0 : -1.0;
}
inline long Round(double const f)
{
return (long)(f + 0.5);
//return lround(f);
}
double Random(double a, double b);
inline double Random()
{
return Random(0.0,1.0);
}
inline double Random(double b)
{
return Random(0.0, b);
}
inline double BorlandTime()
{
auto timesinceepoch = std::time( nullptr );
return timesinceepoch / (24.0 * 60 * 60);
/*
// std alternative
auto timesinceepoch = std::chrono::system_clock::now().time_since_epoch();
return std::chrono::duration_cast<std::chrono::seconds>( timesinceepoch ).count() / (24.0 * 60 * 60);
*/
}
std::string Now();
/*funkcje logiczne*/
inline bool TestFlag( int const Flag, int const Value ) { return ( ( Flag & Value ) == Value ); }
bool SetFlag( int &Flag, int const Value);
bool ClearFlag(int &Flag, int const Value);
bool FuzzyLogic(double Test, double Threshold, double Probability);
/*jesli Test>Threshold to losowanie*/
bool FuzzyLogicAI(double Test, double Threshold, double Probability);
/*to samo ale zawsze niezaleznie od DebugFlag*/
/*operacje na stringach*/
std::string DUE(std::string s); /*Delete Until Equal sign*/
std::string DWE(std::string s); /*Delete While Equal sign*/
std::string ExchangeCharInString( std::string const &Source, char const From, char const To ); // zamienia jeden znak na drugi
std::vector<std::string> &Split(const std::string &s, char delim, std::vector<std::string> &elems);
std::vector<std::string> Split(const std::string &s, char delim);
//std::vector<std::string> Split(const std::string &s);
std::string to_string(int _Val);
std::string to_string(unsigned int _Val);
std::string to_string(int _Val, int precision);
std::string to_string(int _Val, int precision, int width);
std::string to_string(double _Val);
std::string to_string(double _Val, int precision);
std::string to_string(double _Val, int precision, int width);
std::string to_hex_str( int const _Val, int const width = 4 );
inline std::string to_string(bool _Val) {
return _Val == true ? "true" : "false";
}
template <typename Type_, glm::precision Precision_ = glm::defaultp>
std::string to_string( glm::tvec3<Type_, Precision_> const &Value ) {
return to_string( Value.x, 2 ) + ", " + to_string( Value.y, 2 ) + ", " + to_string( Value.z, 2 );
}
template <typename Type_, glm::precision Precision_ = glm::defaultp>
std::string to_string( glm::tvec4<Type_, Precision_> const &Value, int const Width = 2 ) {
return to_string( Value.x, Width ) + ", " + to_string( Value.y, Width ) + ", " + to_string( Value.z, Width ) + ", " + to_string( Value.w, Width );
}
int stol_def(const std::string & str, const int & DefaultValue);
std::string ToLower(std::string const &text);
std::string ToUpper(std::string const &text);
// replaces polish letters with basic ascii
void win1250_to_ascii( std::string &Input );
// TODO: unify with win1250_to_ascii()
std::string Bezogonkow( std::string str, bool _ = false );
inline
std::string
extract_value( std::string const &Key, std::string const &Input ) {
// NOTE, HACK: the leading space allows to uniformly look for " variable=" substring
std::string const input { " " + Input };
std::string value;
auto lookup = input.find( " " + Key + "=" );
if( lookup != std::string::npos ) {
value = input.substr( input.find_first_not_of( ' ', lookup + Key.size() + 2 ) );
lookup = value.find( ' ' );
if( lookup != std::string::npos ) {
// trim everything past the value
value.erase( lookup );
}
}
return value;
}
template <typename Type_>
bool
extract_value( Type_ &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) {
auto value = extract_value( Key, Input );
if( false == value.empty() ) {
// set the specified variable to retrieved value
std::stringstream converter;
converter << value;
converter >> Variable;
return true; // located the variable
}
else {
// set the variable to provided default value
if( false == Default.empty() ) {
std::stringstream converter;
converter << Default;
converter >> Variable;
}
return false; // couldn't locate the variable in provided input
}
}
template <>
bool
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default );
bool FileExists( std::string const &Filename );
// returns time of last modification for specified file
std::time_t last_modified( std::string const &Filename );

95
old/mctools.hpp Normal file
View File

@@ -0,0 +1,95 @@
// Borland C++ Builder
// Copyright (c) 1995, 1999 by Borland International
// All rights reserved
// (DO NOT EDIT: machine generated header) 'mctools.pas' rev: 5.00
#ifndef mctoolsHPP
#define mctoolsHPP
#pragma delphiheader begin
#pragma option push -w-
#pragma option push -Vx
#include <SysInit.hpp> // Pascal unit
#include <System.hpp> // Pascal unit
//-- user supplied -----------------------------------------------------------
namespace Mctools
{
//-- type declarations -------------------------------------------------------
typedef Set<char, 0, 255> TableChar;
//-- var, const, procedure ---------------------------------------------------
#define _EOL (System::Set<char, 0, 255> () << '\xa' << '\xd' )
static const char _SPACE = '\x20';
#define _Spacesigns (System::Set<char, 0, 255> () << '\x9' << '\xa' << '\xd' << '\x29' << '\x2a' << '\x2d' \
<< '\x49' << '\x4a' << '\x4d' << '\x69' << '\x6a' << '\x6d' << '\x89' << '\x8a' << '\x8d' << '\xa9' \
<< '\xaa' << '\xad' << '\xc9' << '\xca' << '\xcd' << '\xe9' << '\xea' << '\xed' )
static const Shortint CutLeft = 0xffffffff;
static const Shortint CutRight = 0x1;
static const Shortint CutBoth = 0x0;
extern PACKAGE int ConversionError;
extern PACKAGE int LineCount;
extern PACKAGE bool DebugModeFlag;
extern PACKAGE bool FreeFlyModeFlag;
extern PACKAGE double Xmin;
extern PACKAGE double Ymin;
extern PACKAGE double Xmax;
extern PACKAGE double Ymax;
extern PACKAGE double Xaspect;
extern PACKAGE double Yaspect;
extern PACKAGE double Hstep;
extern PACKAGE double Vstep;
extern PACKAGE int Vsize;
extern PACKAGE int Hsize;
extern PACKAGE AnsiString __fastcall Ups(AnsiString s);
extern PACKAGE AnsiString __fastcall b2s(Byte b);
extern PACKAGE AnsiString __fastcall i2s(int i);
extern PACKAGE AnsiString __fastcall l2s(int l);
extern PACKAGE AnsiString __fastcall r2s(double r, Byte SWidth);
extern PACKAGE Byte __fastcall s2b(AnsiString s);
extern PACKAGE int __fastcall s2i(AnsiString s);
extern PACKAGE int __fastcall s2l(AnsiString s);
extern PACKAGE double __fastcall s2r(AnsiString s);
extern PACKAGE Byte __fastcall s2bE(AnsiString s);
extern PACKAGE int __fastcall s2iE(AnsiString s);
extern PACKAGE int __fastcall s2lE(AnsiString s);
extern PACKAGE double __fastcall s2rE(AnsiString s);
extern PACKAGE Byte __fastcall Max0(Byte x1, Byte x2);
extern PACKAGE Byte __fastcall Min0(Byte x1, Byte x2);
extern PACKAGE double __fastcall Max0R(double x1, double x2);
extern PACKAGE double __fastcall Min0R(double x1, double x2);
extern PACKAGE int __fastcall Sign(double x);
extern PACKAGE bool __fastcall TestFlag(int Flag, int Value);
extern PACKAGE bool __fastcall SetFlag(Byte &Flag, int Value);
extern PACKAGE bool __fastcall iSetFlag(int &Flag, int Value);
extern PACKAGE bool __fastcall FuzzyLogic(double Test, double Threshold, double Probability);
extern PACKAGE bool __fastcall FuzzyLogicAI(double Test, double Threshold, double Probability);
extern PACKAGE AnsiString __fastcall ReadWord(TextFile &infile);
extern PACKAGE AnsiString __fastcall Cut_Space(AnsiString s, int Just);
extern PACKAGE AnsiString __fastcall ExtractKeyWord(AnsiString InS, AnsiString KeyWord);
extern PACKAGE AnsiString __fastcall DUE(AnsiString S);
extern PACKAGE AnsiString __fastcall DWE(AnsiString S);
extern PACKAGE AnsiString __fastcall Ld2Sp(AnsiString S);
extern PACKAGE AnsiString __fastcall Tab2Sp(AnsiString S);
extern PACKAGE void __fastcall ComputeArc(double X0, double Y0, double Xn, double Yn, double R, double
L, double dL, double &phi, double &Xout, double &Yout);
extern PACKAGE void __fastcall ComputeALine(double X0, double Y0, double Xn, double Yn, double L, double
R, double &Xout, double &Yout);
extern PACKAGE double __fastcall Xhor(double h);
extern PACKAGE double __fastcall Yver(double v);
extern PACKAGE int __fastcall Horiz(double X);
extern PACKAGE int __fastcall Vert(double Y);
extern PACKAGE void __fastcall ClearPendingExceptions(void);
} /* namespace Mctools */
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Mctools;
#endif
#pragma option pop // -w-
#pragma option pop // -Vx
#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif // mctools

507
old/mctools.pas Normal file
View File

@@ -0,0 +1,507 @@
unit mctools;
(*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*)
{rozne takie duperele do operacji na stringach w paszczalu, pewnie w delfi sa lepsze}
{konwersja zmiennych na stringi, funkcje matematyczne, logiczne, lancuchowe, I/O etc}
interface
const
{Ra: te sta³e nie s¹ u¿ywane...
_FileName = ['a'..'z','A'..'Z',':','\','.','*','?','0'..'9','_','-'];
_RealNum = ['0'..'9','-','+','.','E','e'];
_Integer = ['0'..'9','-']; //Ra: to siê gryzie z STLport w Builder 6
_Plus_Int = ['0'..'9'];
_All = [' '..'þ'];
_Delimiter= [',',';']+_EOL;
_Delimiter_Space=_Delimiter+[' '];
}
_EOL = [#13,#10];
_SPACE = ' ';
_Spacesigns=[' ']+[#9]+_EOL;
CutLeft=-1; CutRight=1; CutBoth=0; {Cut_Space}
var
ConversionError: integer=0;
LineCount: integer=0;
DebugModeFlag: boolean=False;
FreeFlyModeFlag: boolean=False;
type
TableChar = Set Of Char; {MCTUTIL}
{konwersje}
function b2s(b:byte):string;
function i2s(i:integer):string;
function l2s(l:longint):string;
function r2s(r:real; SWidth:byte):string;
function s2b(s:string):byte;
function s2i(s:string):integer;
function s2l(s:string):longint;
function s2r(s:string):real;
function s2bE(s:string):byte;
function s2iE(s:string):integer;
function s2lE(s:string):longint;
function s2rE(s:string):real;
{funkcje matematyczne}
function Max0(x1,x2:byte) : byte;
function Min0(x1,x2:byte) : byte;
function Max0R(x1,x2:real) : real;
function Min0R(x1,x2:real) : real;
function Sign(x:real) : integer;
{funkcje logiczne}
function TestFlag(Flag:integer; Value:integer):boolean;
function SetFlag(var Flag:byte; Value:integer):boolean;
function iSetFlag(var Flag:integer; Value:integer):boolean;
function FuzzyLogic(Test,Threshold,Probability:real):boolean;
{jesli Test>Threshold to losowanie}
function FuzzyLogicAI(Test,Threshold,Probability:real):boolean;
{to samo ale zawsze niezaleznie od DebugFlag}
{operacje na stringach}
Function ReadWord(var infile:text):string; {czyta slowo z wiersza pliku tekstowego}
Function Ups (s:string ): string ;
Function Cut_Space(s:string; Just:integer) : string;
Function ExtractKeyWord(InS:String; KeyWord:string) : String; {wyciaga slowo kluczowe i lancuch do pierwszej spacji}
Function DUE(S:String) : String; {Delete Until Equal sign}
Function DWE(S:String) : String; {Delete While Equal sign}
Function Ld2Sp(S:String): String; {Low dash to Space sign}
Function Tab2Sp(S:String): String; {Tab to Space sign}
{procedury, zmienne i funkcje graficzne}
procedure ComputeArc(X0,Y0,Xn,Yn,R,L:real;dL:real; var phi,Xout,Yout:real);
{wylicza polozenie Xout Yout i orientacje phi punktu na elemencie dL luku}
procedure ComputeALine(X0,Y0,Xn,Yn,L,R:real; var Xout,Yout:real);
var
Xmin,Ymin,Xmax,Ymax:real;
Xaspect,Yaspect:real;
Hstep,Vstep: real;
Vsize,Hsize:integer;
function Xhor( h:real) :real;
{ Converts horizontal screen coordinate into real X-coordinate. }
function Yver( v:real) :real;
{ Converts vertical screen coordinate into real Y-coordinate. }
function Horiz(X:real):longint;
function Vert(Y:real):longint;
procedure ClearPendingExceptions;
{------------------------------------------------}
Implementation
{================================================}
function Ups (s:string ): string ;
var
jatka : integer; swy:string;
begin
swy:='';
for jatka:=1 to length(s) do swy:=swy+UpCase(s[jatka]);
Ups:=swy;
end; {=Ups=}
function b2s(b:byte):string;
var
s:string;
begin
Str(b:2,s);
b2s:=s;
end; {=b2s=}
function i2s(i:integer):string;
var
s:string;
begin
Str(i:3,s);
i2s:=s;
end; {=i2s=}
function l2s(l:longint):string;
var
s:string;
begin
Str(l:4,s);
l2s:=s;
end; {=l2s=}
function r2s(r:real; SWidth:byte):string;
var
s:string;
absr:real; {rr:integer;}
begin
absr:=Abs(r);
if SWidth<8 then SWidth:=8;
if absr > 0.0001 then
begin {rr:=(Round(ln(1/absr)/ln(10)-1+Swidth/2));}
if absr < 100 then
Str(r:Swidth:(Round(ln(1/absr)/ln(10)-1+Swidth/2)),s)
else Str(r:Swidth:1,s)
end
else Str(r:Swidth,s);
{ if r>0 then s:=insert('+'s,3);}
r2s:=s;
end; {=r2s=}
function s2b(s:string):byte;
var e:integer;
b:byte;
begin
Val(s,b,e);
s2b:=b;
end;
function s2i(s:string):integer;
var e:integer;
i:integer;
begin
Val(s,i,e);
s2i:=i;
end;
function s2l(s:string):longint;
var e:integer;
l:longint;
begin
Val(s,l,e);
s2l:=l;
end;
function s2r(s:string):real;
var e:integer;
r:real;
begin
Val(s,r,e);
s2r:=r;
end;
function s2bE(s:string):byte;
var e:integer;
b:byte;
begin
s2bE:=0;
Val(s,b,e);
if e>0 then
ConversionError:=e
else s2bE:=b;
end;
function s2iE(s:string):integer;
var e:integer;
i:integer;
begin
s2iE:=0;
Val(s,i,e);
if e>0 then
ConversionError:=e
else s2iE:=i;
end;
function s2lE(s:string):longint;
var e:integer;
l:longint;
begin
s2lE:=0;
Val(s,l,e);
if e>0 then
ConversionError:=e
else s2lE:=l;
end;
function s2rE(s:string):real;
var e:integer;
r:real;
begin
s2rE:=0;
Val(s,r,e);
if e>0 then
ConversionError:=e
else s2rE:=r;
end;
function Max0(x1,x2:byte) : byte;
begin
if x1>x2 then
Max0:=x1
else
Max0:=x2;
end;
function Min0(x1,x2:byte) : byte;
begin
if x1<x2 then
Min0:=x1
else
Min0:=x2;
end;
function Max0R(x1,x2:real) : real;
begin
if x1>x2 then
Max0R:=x1
else
Max0R:=x2;
end;
function Min0R(x1,x2:real) : real;
begin
if x1<x2 then
Min0R:=x1
else
Min0R:=x2;
end;
function Sign(x:real) : integer;
begin
Sign:=0;
if x>0 then Sign:=1;
if x<0 then Sign:=-1;
end;
function TestFlag(Flag:integer; Value:integer):boolean;
begin
if (Flag and Value)=Value then
TestFlag:=True
else TestFlag:=False;
end;
function SetFlag(var Flag:byte; Value:integer):boolean;
begin
SetFlag:=False;
if Value>0 then
if (Flag and Value)=0 then
begin
Flag:=Flag+Value;
SetFlag:=True
end;
if Value<0 then
if (Flag and Abs(Value))=Abs(Value) then
begin
Flag:=Flag+Value;
SetFlag:=True
end;
end;
function iSetFlag(var Flag:integer; Value:integer):boolean;
begin
iSetFlag:=False;
if Value>0 then
if (Flag and Value)=0 then
begin
Flag:=Flag+Value;
iSetFlag:=True; //true, gdy by³o wczeœniej 0 i zosta³o ustawione
end;
if Value<0 then
if (Flag and Abs(Value))=Abs(Value) then
begin
Flag:=Flag+Value; //Value jest ujemne, czyli zerowanie flagi
iSetFlag:=True; //true, gdy by³o wczeœniej 1 i zosta³o wyzerowane
end;
end;
function FuzzyLogic(Test,Threshold,Probability:real):boolean;
begin
if (Test>Threshold) and (not DebugModeFlag) then
FuzzyLogic:=(Random<Probability*Threshold/Test) {im wiekszy Test tym wieksza szansa}
else FuzzyLogic:=False;
end;
function FuzzyLogicAI(Test,Threshold,Probability:real):boolean;
begin
if (Test>Threshold) then
FuzzyLogicAI:=(Random<Probability*Threshold/Test) {im wiekszy Test tym wieksza szansa}
else FuzzyLogicAI:=False;
end;
Function ReadWord(var infile:text):string;
var s:string; c:char; nextword:boolean;
begin
s:='';
nextword:=False;
while (not eof(infile)) and (not nextword) do
begin
read(infile,c);
if c in _SpaceSigns then
if s<>'' then
nextword:=True;
if not (c in _Spacesigns) then
s:=s+c;
end;
ReadWord:=s;
end;
Function Cut_Space(s:string; Just:integer) : string;
var ii:byte;
begin
case Just of
CutLeft : begin
ii:=0;
while (ii<length(s)) and (s[ii+1]=_SPACE) do
inc(ii);
S:=Copy(s,ii+1,length(s)-ii);
end;
CutRight: begin
ii:=length(s);
while(ii>0) and (s[ii]=_SPACE) do
dec(ii);
S:=Copy(s,1,ii);
end;
CutBoth : begin
S:=Cut_Space(S,CutLeft);
S:=Cut_Space(S,CutRight);
end;
end;
Cut_Space:=S;
end;
{Cut_Space}
Function ExtractKeyWord(InS:String; KeyWord:string) : String;
var s:string; kwp:byte;
begin
Ins:=Ins+' ';
kwp:=Pos(KeyWord,InS);
if kwp>0 then
begin
s:=Copy(InS,kwp,Length(Ins));
s:=Copy(s,1,Pos(' ',s)-1);
end
else s:='';
ExtractKeyWord:=s;
end;
Function DUE(S:String) : String; {Delete Until Equal sign}
begin
DUE:=Copy(S,Pos('=',S)+1,Length(S));
end;
Function DWE(S:String) : String; {Delete While Equal sign}
var ep:byte;
begin
ep:=Pos('=',S);
if ep>0 then
DWE:=Copy(S,1,ep-1)
else DWE:=S;
end;
Function Ld2Sp(S:String): String; {Low dash to Space sign}
var b:byte; s2:string;
begin
s2:='';
for b:=1 to length(S) do
if S[b]='_' then
s2:=s2+' '
else
s2:=s2+S[b];
Ld2Sp:=s2;
end;
Function Tab2Sp(S:String): String; {Tab to Space sign}
var b:byte; s2:string;
begin
s2:='';
for b:=1 to length(S) do
if S[b]=#9 then
s2:=s2+' '
else
s2:=s2+S[b];
Tab2Sp:=s2;
end;
procedure ComputeArc(X0,Y0,Xn,Yn,R,L:real;dL:real; var phi,Xout,Yout:real);
{wylicza polozenie Xout Yout i orientacje phi punktu na elemencie dL luku}
var dX,dY,Xc,Yc,gamma,alfa,AbsR:real;
begin
if (R<>0) and (L<>0) then
begin
AbsR:=Abs(R);
dX:=Xn-X0;
dY:=Yn-Y0;
if dX<>0 then gamma:=arctan(dY/dX)
else if dY>0 then gamma:=Pi/2
else gamma:=3*Pi/2;
alfa:=L/R;
phi:=gamma-(alfa+Pi*Round(R/AbsR))/2;
Xc:=X0-AbsR*cos(phi);
Yc:=Y0-AbsR*sin(phi);
phi:=phi+alfa*dL/L;
Xout:=AbsR*cos(phi)+Xc;
Yout:=AbsR*sin(phi)+Yc;
end;
end;
procedure ComputeALine(X0,Y0,Xn,Yn,L,R:real; var Xout,Yout:real);
var dX,dY,gamma,alfa:real;
{ pX,pY : real;}
begin
alfa:=0; //ABu: bo nie bylo zainicjowane
dX:=Xn-X0;
dY:=Yn-Y0;
if dX<>0 then gamma:=arctan(dY/dX)
else if dY>0 then gamma:=Pi/2
else gamma:=3*Pi/2;
if R<>0 then alfa:=L/R;
Xout:=X0+L*cos(alfa/2-gamma);
Yout:=Y0+L*sin(alfa/2-gamma);
end;
{graficzne:}
function Xhor( h:real) :real;
begin
Xhor:= h*Hstep + Xmin;
end;
function Yver( v:real) :real;
begin
Yver:= (Vsize-v)*Vstep + Ymin;
end;
function Horiz(X:real):longint;
begin
x:= (x-Xmin) / Hstep;
if x > -MaxInt then
if x < MaxInt then Horiz:=Round(x)
else Horiz:= MaxInt
else Horiz:= -MaxInt;
end;
function Vert(Y:real):longint;
begin
y:= (y-Ymin) / Vstep;
if y > -MaxInt then
if y < MaxInt then Vert:=Vsize-Round(y)
else Vert:= MaxInt
else Vert:= -MaxInt
end;
procedure ClearPendingExceptions;
//resetuje b³êdy FPU, wymagane dla Trunc()
asm
FNCLEX
end;
end.

127
old/mtable.hpp Normal file
View File

@@ -0,0 +1,127 @@
// Borland C++ Builder
// Copyright (c) 1995, 1999 by Borland International
// All rights reserved
// (DO NOT EDIT: machine generated header) 'mtable.pas' rev: 5.00
#ifndef mtableHPP
#define mtableHPP
#pragma delphiheader begin
#pragma option push -w-
#pragma option push -Vx
#include <SysUtils.hpp> // Pascal unit
#include <mctools.hpp> // Pascal unit
#include <SysInit.hpp> // Pascal unit
#include <System.hpp> // Pascal unit
//-- user supplied -----------------------------------------------------------
namespace Mtable
{
//-- type declarations -------------------------------------------------------
struct TMTableLine
{
double km;
double vmax;
AnsiString StationName;
AnsiString StationWare;
Byte TrackNo;
int Ah;
int Am;
int Dh;
int Dm;
double tm;
int WaitTime;
} ;
typedef TMTableLine TMTable[101];
class DELPHICLASS TTrainParameters;
typedef TTrainParameters* *PTrainParameters;
class PASCALIMPLEMENTATION TTrainParameters : public System::TObject
{
typedef System::TObject inherited;
public:
AnsiString TrainName;
double TTVmax;
AnsiString Relation1;
AnsiString Relation2;
double BrakeRatio;
AnsiString LocSeries;
double LocLoad;
TMTableLine TimeTable[101];
int StationCount;
int StationIndex;
AnsiString NextStationName;
double LastStationLatency;
int Direction;
double __fastcall CheckTrainLatency(void);
AnsiString __fastcall ShowRelation();
double __fastcall WatchMTable(double DistCounter);
AnsiString __fastcall NextStop();
bool __fastcall IsStop(void);
bool __fastcall IsTimeToGo(double hh, double mm);
bool __fastcall UpdateMTable(double hh, double mm, AnsiString NewName);
__fastcall TTrainParameters(AnsiString NewTrainName);
void __fastcall NewName(AnsiString NewTrainName);
bool __fastcall LoadTTfile(AnsiString scnpath, int iPlus, double vMax);
bool __fastcall DirectionChange(void);
void __fastcall StationIndexInc(void);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TTrainParameters(void) : System::TObject() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TTrainParameters(void) { }
#pragma option pop
};
class DELPHICLASS TMTableTime;
class PASCALIMPLEMENTATION TMTableTime : public System::TObject
{
typedef System::TObject inherited;
public:
double GameTime;
int dd;
int hh;
int mm;
int srh;
int srm;
int ssh;
int ssm;
double mr;
void __fastcall UpdateMTableTime(double deltaT);
__fastcall TMTableTime(int InitH, int InitM, int InitSRH, int InitSRM, int InitSSH, int InitSSM);
public:
#pragma option push -w-inl
/* TObject.Create */ inline __fastcall TMTableTime(void) : System::TObject() { }
#pragma option pop
#pragma option push -w-inl
/* TObject.Destroy */ inline __fastcall virtual ~TMTableTime(void) { }
#pragma option pop
};
//-- var, const, procedure ---------------------------------------------------
static const Shortint MaxTTableSize = 0x64;
static const char hrsd = '\x2e';
extern PACKAGE TMTableTime* GlobalTime;
} /* namespace Mtable */
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Mtable;
#endif
#pragma option pop // -w-
#pragma option pop // -Vx
#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif // mtable

530
old/mtable.pas Normal file
View File

@@ -0,0 +1,530 @@
unit mtable;
(*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*)
interface uses mctools,sysutils;
const MaxTTableSize=100; //mo¿na by to robiæ dynamicznie
hrsd= '.';
Type
//Ra: pozycja zerowa rozk³adu chyba nie ma sensu
//Ra: numeracja przystanków jest 1..StationCount
TMTableLine=record
km:real; //kilometraz linii
vmax:real; //predkosc rozkladowa przed przystankiem
//StationName:string[32]; //nazwa stacji ('_' zamiast spacji)
//StationWare:string[32]; //typ i wyposazenie stacji, oddz. przecinkami}
StationName:string; //nazwa stacji ('_' zamiast spacji)
StationWare:string; //typ i wyposazenie stacji, oddz. przecinkami}
TrackNo:byte; //ilosc torow szlakowych
Ah,Am:integer; //godz. i min. przyjazdu, -1 gdy bez postoju
Dh,Dm:integer; //godz. i min. odjazdu
tm:real; //czas jazdy do tej stacji w min. (z kolumny)
WaitTime:integer; //czas postoju (liczony plus 6 sekund)
end;
TMTable = array[0..MaxTTableSize] of TMTableLine;
PTrainParameters= ^TTrainParameters;
TTrainParameters = class(TObject)
TrainName:string;
TTVmax:real;
Relation1,Relation2: string; //nazwy stacji danego odcinka
BrakeRatio: real;
LocSeries: string; //seria (typ) pojazdu
LocLoad: real;
TimeTable: TMTable;
StationCount: integer; //iloœæ przystanków (0-techniczny)
StationIndex: integer; //numer najbli¿szego (aktualnego) przystanku
NextStationName: string;
LastStationLatency: real;
Direction: integer; {kierunek jazdy w/g kilometrazu}
function CheckTrainLatency: real;
{todo: str hh:mm to int i z powrotem}
function ShowRelation: string;
function WatchMTable(DistCounter:real): real;
function NextStop:string;
function IsStop:boolean;
function IsTimeToGo(hh,mm:real):boolean;
function UpdateMTable(hh,mm:real; NewName: string): boolean;
constructor Init(NewTrainName:string);
procedure NewName(NewTrainName:string);
function LoadTTfile(scnpath:string;iPlus:Integer;vMax:real):boolean;
function DirectionChange():boolean;
procedure StationIndexInc();
end;
TMTableTime = class(TObject)
GameTime: real;
dd,hh,mm: integer;
srh,srm : integer; {wschod slonca}
ssh,ssm : integer; {zachod slonca}
mr:real;
procedure UpdateMTableTime(deltaT:real);
constructor Init(InitH,InitM,InitSRH,InitSRM,InitSSH,InitSSM:integer);
end;
var GlobalTime: TMTableTime;
implementation
function CompareTime(t1h,t1m,t2h,t2m:real):real; {roznica czasu w minutach}
//zwraca ró¿nicê czasu
//jeœli pierwsza jest aktualna, a druga rozk³adowa, to ujemna oznacza opó¿nienie
//na d³u¿sz¹ metê trzeba uwzglêdniæ datê, jakby opó¿nienia mia³y przekraczaæ 12h (towarowych)
var
t:real;
begin
if (t2h<0) then
CompareTime:=0
else
begin
t:=(t2h-t1h)*60+t2m-t1m; //jeœli t2=00:05, a t1=23:50, to ró¿nica wyjdzie ujemna
if (t<-720) then //jeœli ró¿nica przekracza 12h na minus
t:=t+1440 //to dodanie doby minut
else
if (t>720) then //jeœli przekracza 12h na plus
t:=t-1440; //to odjêcie doby minut
CompareTime:=t;
end;
end;
function TTrainParameters.CheckTrainLatency: real;
begin
if (LastStationLatency>1.0) or (LastStationLatency<0) then
CheckTrainLatency:=LastStationLatency {spoznienie + lub do przodu - z tolerancja 1 min}
else
CheckTrainLatency:=0
end;
function TTrainParameters.WatchMTable(DistCounter:real): real;
{zwraca odlegloϾ do najblizszej stacji z zatrzymaniem}
var dist:real;
begin
if Direction=1 then
dist:=TimeTable[StationIndex].km-TimeTable[0].km-DistCounter
else
dist:=TimeTable[0].km-TimeTable[StationIndex].km-DistCounter;
WatchMTable:=dist;
end;
function TTrainParameters.NextStop:string;
//pobranie nazwy nastêpnego miejsca zatrzymania
begin
if StationIndex<=StationCount
then
NextStop:='PassengerStopPoint:'+NextStationName //nazwa nastêpnego przystanku
else
NextStop:='[End of route]'; //¿e niby koniec
end;
function TTrainParameters.IsStop:boolean;
//zapytanie, czy zatrzymywaæ na nastêpnym punkcie rozk³adu
begin
if (StationIndex<StationCount) then
IsStop:=TimeTable[StationIndex].Ah>=0 //-1 to brak postoju
else
IsStop:=true; //na ostatnim siê zatrzymaæ zawsze
end;
function TTrainParameters.UpdateMTable(hh,mm:real;NewName:string):boolean;
{odfajkowanie dojechania do stacji (NewName) i przeliczenie opóŸnienia}
var OK:boolean;
begin
OK:=false;
if StationIndex<=StationCount then //Ra: "<=", bo ostatni przystanek jest traktowany wyj¹tkowo
begin
if NewName=NextStationName then //jeœli dojechane do nastêpnego
begin //Ra: wywo³anie mo¿e byæ powtarzane, jak stoi na W4
if TimeTable[StationIndex+1].km-TimeTable[StationIndex].km<0 then //to jest bez sensu
Direction:=-1
else
Direction:=1; //prowizorka bo moze byc zmiana kilometrazu
//ustalenie, czy opóŸniony (porównanie z czasem odjazdu)
LastStationLatency:=CompareTime(hh,mm,TimeTable[StationIndex].Dh,TimeTable[StationIndex].Dm);
//inc(StationIndex); //przejœcie do nastêpnej pozycji StationIndex<=StationCount
if StationIndex<StationCount then //Ra: "<", bo dodaje 1 przy przejœciu do nastêpnej stacji
begin //jeœli nie ostatnia stacja
NextStationName:=TimeTable[StationIndex+1].StationName; //zapamiêtanie nazwy
TTVmax:=TimeTable[StationIndex+1].vmax; //Ra: nowa prêdkoœæ rozk³adowa na kolejnym odcinku
end
else //gdy ostatnia stacja
NextStationName:=''; //nie ma nastêpnej stacji
OK:=true;
end;
end;
UpdateMTable:=OK; {czy jest nastepna stacja}
end;
procedure TTrainParameters.StationIndexInc();
begin
Inc(StationIndex); //przejœcie do nastêpnej pozycji StationIndex<=StationCount
end;
function TTrainParameters.IsTimeToGo(hh,mm:real):boolean;
//sprawdzenie, czy mo¿na ju¿ odjechaæ z aktualnego zatrzymania
//StationIndex to numer nastêpnego po dodarciu do aktualnego
begin
if (StationIndex<1) then
IsTimeToGo:=true //przed pierwsz¹ jechaæ
else if (StationIndex<StationCount) then
begin //oprócz ostatniego przystanku
if (TimeTable[StationIndex].Ah<0) then //odjazd z poprzedniego
IsTimeToGo:=true //czas przyjazdu nie by³ podany - przelot
else
IsTimeToGo:=CompareTime(hh,mm,TimeTable[StationIndex].Dh,TimeTable[StationIndex].Dm)<=0;
end
else //gdy rozk³ad siê skoñczy³
IsTimeToGo:=false; //dalej nie jechaæ
end;
function TTrainParameters.ShowRelation:string;
{zwraca informacjê o relacji}
begin
//if (Relation1=TimeTable[1].StationName) and (Relation2=TimeTable[StationCount].StationName)
if (Relation1<>'') and (Relation2<>'')
then ShowRelation:=Relation1+' - '+Relation2
else ShowRelation:='';
end;
constructor TTrainParameters.Init(NewTrainName:string);
{wstêpne ustawienie parametrów rozk³adu jazdy}
begin
NewName(NewTrainName);
end;
procedure TTrainParameters.NewName(NewTrainName:string);
{wstêpne ustawienie parametrów rozk³adu jazdy}
var i:integer;
begin
TrainName:=NewTrainName;
StationCount:=0;
StationIndex:=0;
NextStationName:='nowhere';
LastStationLatency:=0;
Direction:=1;
Relation1:=''; Relation2:='';
for i:=0 to MaxTTableSize do
with timeTable[i] do
begin
km:=0; vmax:=-1; StationName:='nowhere'; StationWare:='';
TrackNo:=1; Ah:=-1; Am:=-1; Dh:=-1; Dm:=-1; tm:=0; WaitTime:=0;
end;
TTVmax:=100; {wykasowac}
end;
function TTrainParameters.LoadTTfile(scnpath:string;iPlus:Integer;vMax:real):boolean;
//wczytanie pliku-tabeli z rozk³adem przesuniêtym o (fPlus); (vMax) nie ma znaczenia
var
lines,s:string;
fin:text;
EndTable:boolean;
vActual:real;
i,time:Integer; //do zwiêkszania czasu
procedure UpdateVelocity(StationCount:integer;vActual:real);
//zapisywanie prêdkoœci maksymalnej do wczeœniejszych odcinków
//wywo³ywane z numerem ostatniego przetworzonego przystanku
var i:integer;
begin
i:=StationCount;
//TTVmax:=vActual; {PROWIZORKA!!!}
while (i>=0) and (TimeTable[i].vmax=-1) do
begin
TimeTable[i].vmax:=vActual; //prêdkoœæ dojazdu do przystanku i
dec(i); //ewentualnie do poprzedniego te¿
end;
end;
begin
ClearPendingExceptions;
ConversionError:=0;
EndTable:=False;
if (TrainName='') then
begin //jeœli pusty rozk³ad
//UpdateVelocity(StationCount,vMax); //ograniczenie do prêdkoœci startowej
end
else
begin
ConversionError:=666;
vActual:=-1;
s:=scnpath+TrainName+'.txt';
//Ra 2014-09: ustaliæ zasady wyznaczenia pierwotnego pliku przy przesuniêtych rozk³adach (kolejny poci¹g dostaje numer +2)
assignfile(fin,s);
s:='';
{$I-}
reset(fin);
{$I+}
if IOresult<>0 then
begin
vMax:=s2r(TrainName); //nie ma pliku ale jest liczba
if (vMax>10)and(vMax<200) then
begin
TTVmax:=vMax; //Ra 2014-07: zamiast rozk³adu mo¿na podaæ Vmax
UpdateVelocity(StationCount,vMax); //ograniczenie do prêdkoœci startowej
ConversionError:=0;
end
else
ConversionError:=-8; {Ra: ten b³¹d jest niepotrzebny}
end
else
begin {analiza rozk³adu jazdy}
ConversionError:=0;
while not (eof(fin) or (ConversionError<>0) or EndTable) do
begin
readln(fin,lines); {wczytanie linii}
if Pos('___________________',lines)>0 then {linia pozioma górna}
if ReadWord(fin)='[' then {lewy pion}
if ReadWord(fin)='Rodzaj' then {"Rodzaj i numer pociagu"}
repeat
until (ReadWord(fin)='|') or (eof(fin)); {œrodkowy pion}
s:=ReadWord(fin); {nazwa poci¹gu}
//if LowerCase(s)<>ExtractFileName(TrainName) then {musi byæ taka sama, jak nazwa pliku}
//ConversionError:=-7 {b³¹d niezgodnoœci}
TrainName:=s; //nadanie nazwy z pliku TXT (bez œcie¿ki do pliku)
//else
begin {czytaj naglowek}
repeat
until (Pos('_______|',ReadWord(fin))>0) or eof(fin);
repeat
until (ReadWord(fin)='[') or (eof(fin)); {pierwsza linia z relacj¹}
repeat
s:=ReadWord(fin);
until (s<>'|') or eof(fin);
if s<>'|' then Relation1:=s
else ConversionError:=-5;
repeat
until (Readword(fin)='Relacja') or (eof(fin)); {druga linia z relacj¹}
repeat
until (ReadWord(fin)='|') or (eof(fin));
Relation2:=ReadWord(fin);
repeat
until Readword(fin)='Wymagany';
repeat
until (ReadWord(fin)='|') or (eoln(fin));
s:=ReadWord(fin);
s:=Copy(s,1,Pos('%',s)-1);
BrakeRatio:=s2rE(s);
repeat
until Readword(fin)='Seria';
repeat
until (ReadWord(fin)='|') or (eof(fin));
LocSeries:=ReadWord(fin);
LocLoad:=s2rE(ReadWord(fin));
repeat
until (Pos('[______________',ReadWord(fin))>0) or (eof(fin));
while not eof(fin) and not EndTable do
begin
inc(StationCount);
repeat
s:=ReadWord(fin);
until (s='[') or (eof(fin));
with TimeTable[StationCount] do
begin
if s='[' then
s:=ReadWord(fin)
else ConversionError:=-4;
if Pos('|',s)=0 then
begin
km:=s2rE(s);
s:=ReadWord(fin);
end;
if Pos('|_____|',s)>0 then {zmiana predkosci szlakowej}
UpdateVelocity(StationCount,vActual)
else
begin
s:=ReadWord(fin);
if Pos('|',s)=0 then
vActual:=s2rE(s);
end;
while Pos('|',s)=0 do
s:=Readword(fin);
StationName:=ReadWord(fin);
repeat
s:=ReadWord(fin);
until (s='1') or (s='2') or eof(fin);
TrackNo:=s2bE(s);
s:=ReadWord(fin);
if s<>'|' then
begin
if Pos(hrsd,s)>0 then
begin
ah:=s2iE(Copy(s,1,Pos(hrsd,s)-1)); //godzina przyjazdu
am:=s2iE(Copy(s,Pos(hrsd,s)+1,Length(s))); //minuta przyjazdu
end
else
begin
ah:=TimeTable[StationCount-1].ah; //godzina z poprzedniej pozycji
am:=s2iE(s); //bo tylko minuty podane
end;
end;
repeat
s:=ReadWord(fin);
until (s<>'|') or (eof(fin));
if s<>']' then
tm:=s2rE(s);
repeat
s:=ReadWord(fin);
until (s='[') or eof(fin);
s:=ReadWord(fin);
if Pos('|',s)=0 then
begin
{tu s moze byc miejscem zmiany predkosci szlakowej}
s:=ReadWord(fin);
end;
if Pos('|_____|',s)>0 then {zmiana predkosci szlakowej}
UpdateVelocity(StationCount,vActual)
else
begin
s:=ReadWord(fin);
if Pos('|',s)=0 then
vActual:=s2rE(s);
end;
while Pos('|',s)=0 do
s:=Readword(fin);
StationWare:=ReadWord(fin);
repeat
s:=ReadWord(fin);
until (s='1') or (s='2') or eof(fin);
TrackNo:=s2bE(s);
s:=ReadWord(fin);
if s<>'|' then
begin
if Pos(hrsd,s)>0 then
begin
dh:=s2iE(Copy(s,1,Pos(hrsd,s)-1)); //godzina odjazdu
dm:=s2iE(Copy(s,Pos(hrsd,s)+1,Length(s))); //minuta odjazdu
end
else
begin
dh:=TimeTable[StationCount-1].dh; //godzina z poprzedniej pozycji
dm:=s2iE(s); //bo tylko minuty podane
end;
end
else
begin
dh:=ah; //odjazd o tej samej, co przyjazd (dla ostatniego te¿)
dm:=am; //bo s¹ u¿ywane do wyliczenia opóŸnienia po dojechaniu
end;
if (ah>=0) then
WaitTime:=Trunc(CompareTime(ah,am,dh,dm)+0.1);
repeat
s:=ReadWord(fin);
until (s<>'|') or (eof(fin));
if s<>']' then
tm:=s2rE(s);
repeat
s:=ReadWord(fin);
until (Pos('[',s)>0) or eof(fin);
if Pos('_|_',s)=0 then
s:=Readword(fin);
if Pos('|',s)=0 then
begin
{tu s moze byc miejscem zmiany predkosci szlakowej}
s:=ReadWord(fin);
end;
if Pos('|_____|',s)>0 then {zmiana predkosci szlakowej}
UpdateVelocity(StationCount,vActual)
else
begin
s:=ReadWord(fin);
if Pos('|',s)=0 then
vActual:=s2rE(s);
end;
while Pos('|',s)=0 do
s:=Readword(fin);
while (Pos(']',s)=0) do
s:=ReadWord(fin);
if Pos('_|_',s)>0 then EndTable:=True;
end; {timetableline}
end;
end;
end; {while eof}
close(fin);
end;
end;
if ConversionError=0 then
begin
if (TimeTable[1].StationName=Relation1) then //jeœli nazwa pierwszego zgodna z relacj¹
if (TimeTable[1].Ah<0) then //a nie podany czas przyjazdu
begin //to mamy zatrzymanie na pierwszym, a nie przelot
TimeTable[1].Ah:=TimeTable[1].Dh;
TimeTable[1].Am:=TimeTable[1].Dm;
end
//NextStationName:=TimeTable[1].StationName;
{ TTVmax:=TimeTable[1].vmax; }
end;
if (iPlus<>0) then //je¿eli jest przesuniêcie rozk³adu
for i:=1 to StationCount do //bez with, bo ciê¿ko siê przenosi na C++
begin
if (TimeTable[i].Ah>=0) then
begin
time:=iPlus+TimeTable[i].Ah*60+TimeTable[i].Am; //nowe minuty
TimeTable[i].Am:=time mod 60;
TimeTable[i].Ah:=(time div 60) mod 60;
end;
if (TimeTable[i].Dh>=0) then
begin
time:=iPlus+TimeTable[i].Dh*60+TimeTable[i].Dm; //nowe minuty
TimeTable[i].Dm:=time mod 60;
TimeTable[i].Dh:=(time div 60) mod 60;
end;
end;
LoadTTfile:=(ConversionError=0);
end;
procedure TMTableTime.UpdateMTableTime(deltaT:real);
//dodanie czasu (deltaT) w sekundach, z przeliczeniem godziny
begin
mr:=mr+deltaT; //dodawanie sekund
while mr>60.0 do //przeliczenie sekund do w³aœciwego przedzia³u
begin
mr:=mr-60.0;
inc(mm);
end;
while mm>59 do //przeliczenie minut do w³aœciwego przedzia³u
begin
mm:=mm-60;
inc(hh);
end;
while hh>23 do //przeliczenie godzin do w³aœciwego przedzia³u
begin
hh:=hh-24;
inc(dd); //zwiêkszenie numeru dnia
end;
GameTime:=GameTime+deltaT;
end;
constructor TMTableTime.Init(InitH,InitM,InitSRH,InitSRM,InitSSH,InitSSM:integer);
begin
GameTime:=0.0;
dd:=0;
hh:=InitH;
mm:=InitM;
srh:=InitSRH;
srm:=InitSRM;
ssh:=InitSSH;
ssm:=InitSSM;
end;
function TTrainParameters.DirectionChange():boolean;
//sprawdzenie, czy po zatrzymaniu wykonaæ kolejne komendy
begin
DirectionChange:=false; //przed pierwsz¹ bez zmiany
if (StationIndex>0) and (StationIndex<StationCount) then //dla ostatniej stacji nie
if (Pos('@',TimeTable[StationIndex].StationWare)>0) then
DirectionChange:=true;
end;
END.

347
old/unit2.pas Normal file
View File

@@ -0,0 +1,347 @@
unit Unit1;
(*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*)
interface
uses
ai_driver,mtable,mover,mctools,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Label2: TLabel;
Label3: TLabel;
Timer1: TTimer;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Button7: TButton;
Button8: TButton;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Button9: TButton;
Button10: TButton;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Button11: TButton;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
Label25: TLabel;
lczas: TLabel;
Label26: TLabel;
Label27: TLabel;
Label28: TLabel;
Label29: TLabel;
Label30: TLabel;
Label31: TLabel;
Label32: TLabel;
Label33: TLabel;
Label34: TLabel;
Button12: TButton;
BStart: TButton;
Label35: TLabel;
Label36: TLabel;
Label37: TLabel;
Label38: TLabel;
Button13: TButton;
Label39: TLabel;
Label40: TLabel;
Label41: TLabel;
Button14: TButton;
Button15: TButton;
Label42: TLabel;
Label43: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure BStartClick(Sender: TObject);
procedure Button13MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button14Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
loc,wag,wag2,wag3:TMoverParameters;
mechanik: TController;
pociag: TTrainParameters;
l0,l1,l2,l3:TLocation;
r0,r1,r2,r3:TRotation;
Shape:TTrackShape; Track:TTrackParam;
ExternalVoltage:real;
ActualTime:real;
fout: text;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
assignfile(fout,'log.dat');
rewrite(fout);
ActualTime:=0;
loc:=TMoverParameters.Create;
wag:=TMoverParameters.Create;
wag2:=TMoverParameters.Create;
wag3:=TMoverParameters.Create;
mechanik:=TController.Create;
pociag:=TTrainParameters.Create;
Shape.R:=0; Shape.Len:=10000; Shape.dHtrack:=0; Shape.dHrail:=0;
Track.Width:=1435; Track.friction:=0.15; Track.CategoryFlag:=1;
Track.QualityFlag:=25; Track.DamageFlag:=0;
Track.VelMax:=120;
ExternalVoltage:=3000;
l0.x:=0; l0.y:=0; l0.z:=0;
l1.x:=-14.0235; l1.y:=0; l1.z:=0;
l2.x:=-27.3634; l2.y:=0; l2.z:=0;
l3.x:=-40.7032; l3.y:=0; l3.z:=0;
r0.rx:=0; r0.ry:=0; r0.rz:=0;
r1.rx:=0; r1.ry:=0; r1.rz:=0;
r2.rx:=0; r2.ry:=0; r2.rz:=0;
r3.rx:=0; r3.ry:=0; r3.rz:=0;
{ loc.Init(l1,r1,0,'en57','456',0,'Human',1); }
loc.Init(l0,r0,60,'eu07','456',0,'',1);
wag.Init(l1,r1,60,'Falns_440v','52-51-342027-2',30,'',0);
wag2.Init(l2,r2,60,'Falns_440v','52-51-322311-5',30,'',0);
wag3.Init(l3,r3,60,'Falns_440v','52-51-410025-3',30,'',0);
pociag.init('Testowy Express',100);
mechanik.init(l1,r1,True,@loc,@pociag,Aggressive);
if (loc.loadchkfile('') and wag.loadchkfile('') and wag2.loadchkfile('') and wag3.loadchkfile(''))
and (loc.CheckLocomotiveParameters(Go) and wag.CheckLocomotiveParameters(Go) and wag2.CheckLocomotiveParameters(Go) and wag3.CheckLocomotiveParameters(Go)) then
begin
Label1.Caption:='OK';
loc.attach(2,@wag,3);
wag.attach(1,@loc,3);
wag.attach(2,@wag2,3);
wag2.attach(1,@wag,3);
wag2.attach(2,@wag3,3);
wag3.attach(1,@wag2,3);
Timer1.Enabled:=True;
end
else Label1.Caption:=inttostr(conversionerror)+' '+inttostr(linecount);
Button1.Visible:=False;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if Timer1.Enabled then
begin
Timer1.Enabled:=False;
CloseFile(fout);
end;
loc.Free;
wag.Free;
wag2.free;
wag3.free;
mechanik.free;
Close;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var dl,dt:real;
begin
dt:=Timer1.Interval/1000;
ActualTime:=ActualTime+dt;
loc.ComputeTotalForce(dt,Shape,Track,ExternalVoltage);
wag.ComputeTotalForce(dt,Shape,Track,ExternalVoltage);
wag2.ComputeTotalForce(dt,Shape,Track,ExternalVoltage);
wag3.ComputeTotalForce(dt,Shape,Track,ExternalVoltage);
dl:=loc.ComputeMovement(dt,Shape,Track,ExternalVoltage,l0,r0);
l0.x:=l0.x+dl;
dl:=wag.ComputeMovement(dt,Shape,Track,ExternalVoltage,l1,r1);
l1.x:=l1.x+dl;
dl:=wag2.ComputeMovement(dt,Shape,Track,ExternalVoltage,l2,r2);
l2.x:=l2.x+dl;
dl:=wag3.ComputeMovement(dt,Shape,Track,ExternalVoltage,l3,r3);
l3.x:=l3.x+dl;
if l0.x<500 then mechanik.UpdateSituation(500-l0.x,dt)
else
if l0.x<2500 then mechanik.UpdateSituation(-1,dt)
else
if l0.x<3500 then mechanik.UpdateSituation(3500-l0.x,dt);
if (l0.x>499) and (l0.x<505) then
mechanik.SetVelocity(-1,-1,0);
if (l0.x>2499) and (l0.x<2510) then
mechanik.SetVelocity(-1,0,0);
Label2.Caption:=r2s(Loc.Im,0)+' A';
Label3.Caption:=r2s(Loc.Ft/1000,0)+' kN';
Label4.Caption:=r2s(l0.x,0)+' m';
Label5.Caption:=r2s(Sign(Loc.V)*Loc.Vel,0)+' km/h';
Label6.Caption:=r2s(Loc.AccS,0)+' m/ss';
Label7.Caption:=r2s(Loc.couplers[1].cforce/1000,0)+' kN';
Label8.Caption:=r2s(Loc.couplers[2].cforce/1000,0)+' kN';
Label9.Caption:=r2s(Loc.Fb/1000,0)+' kN';
Label10.Caption:=r2s(Loc.Compressor,0)+' MPa';
Label11.Caption:=r2s(Loc.PipePress,0)+' MPa';
Label12.Caption:=r2s(Loc.BrakePress,0)+' MPa';
Label13.Caption:=IntToStr(Loc.MainCtrlPos);
Label14.Caption:=IntToStr(Loc.BrakeCtrlPos);
Label15.Caption:=IntToStr(Loc.LocalBrakePos);
Label16.Caption:=IntToStr(Loc.showcurrent(1));
Label17.Caption:=IntToStr(Loc.showcurrent(2));
Label18.Caption:=IntToStr(Loc.ScndCtrlPos);
if loc.SlippingWheels then
Label19.Caption:='Poslizg!'
else Label19.Caption:=' ';
Label20.Caption:=IntToStr(Loc.MainCtrlActualPos);
Label21.Caption:=IntToStr(Loc.ScndCtrlActualPos);
Label22.Caption:=r2s(l1.x,0)+' m';
Label23.Caption:=r2s(Sign(wag.V)*wag.Vel,0)+' km/h';
Label24.Caption:=r2s(Distance(loc.loc,wag.loc,loc.dim,wag.dim),0)+' m';
Label25.Caption:=r2s(loc.nrot,0)+' 1/s';
Label26.Caption:=r2s(wag.couplers[1].cforce/1000,0)+' kN';
Label27.Caption:=r2s(wag.couplers[2].cforce/1000,0)+' kN';
Label28.Caption:=r2s(l2.x,0)+' m';
Label29.Caption:=r2s(sign(wag2.V)*wag2.Vel,0)+' km/h';
Label30.Caption:=r2s(loc.dpLocalValve/dt,0)+' MPa/s';
Label31.Caption:=r2s(loc.dpBrake/dt,0)+' MPa/s';
Label32.Caption:=r2s(loc.dpMainValve/dt,0)+' MPa/s';
Label33.Caption:=r2s(loc.dpPipe/dt,0)+' MPa/s';
Label34.Caption:=r2s(wag2.PipePress,0)+' MPa';
Label35.Caption:=r2s(l3.x,0)+' m';
Label36.Caption:=r2s(sign(wag3.V)*wag3.Vel,0)+' km/h';
Label37.Caption:=r2s(wag3.couplers[1].cforce/1000,0)+' kN';
Label38.Caption:=r2s(wag3.brakepress,0)+' MPa';
Label39.Caption:=r2s(loc.enginePower/1000,0)+' kW';
Label40.Caption:=i2s(trunc(loc.Rventrot*60))+' /min';
Label41.Visible:=loc.SandDose;
Label42.Caption:=r2s(mechanik.accdesired,0)+' m/ss';
Label43.Caption:=r2s(mechanik.veldesired,0)+' km/h';
Lczas.Caption:=r2s(actualtime,0)+' s';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled:=False;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
loc.incbrakelevel(1);
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
loc.decbrakelevel(1);
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
loc.inclocalbrakelevel(1);
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
loc.declocalbrakelevel(1);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
loc.incmainctrl(1);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
loc.decmainctrl(1);
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
loc.DirectionForward;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
loc.DirectionBackward;
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
loc.FuseOn;
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
Loc.AntiSlippingBrake;
end;
procedure TForm1.BStartClick(Sender: TObject);
begin
loc.activedir:=1;
{ if mechanik.OrderDirectionChange(1) then }
mechanik.SetVelocity(60,0,0);
end;
procedure TForm1.Button13MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
loc.SandDoseOn;
end;
procedure TForm1.Button14Click(Sender: TObject);
begin
mechanik.SetVelocity(30,120,0);
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
mechanik.SetVelocity(0,120,0);
end;
end.

264
old/wavread.cpp Normal file
View File

@@ -0,0 +1,264 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
//-----------------------------------------------------------------------------
// File: WavRead.cpp
//
// Desc: Wave file support for loading and playing Wave files using DirectSound
// buffers.
//
// Copyright (c) 1999 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "WavRead.h"
#include "usefull.h"
//-----------------------------------------------------------------------------
// Name: ReadMMIO()
// Desc: Support function for reading from a multimedia I/O stream
//-----------------------------------------------------------------------------
HRESULT ReadMMIO(HMMIO hmmioIn, MMCKINFO *pckInRIFF, WAVEFORMATEX **ppwfxInfo)
{
MMCKINFO ckIn; // chunk info. for general use.
PCMWAVEFORMAT pcmWaveFormat; // Temp PCM structure to load in.
*ppwfxInfo = NULL;
if ((0 != mmioDescend(hmmioIn, pckInRIFF, NULL, 0)))
return E_FAIL;
if ((pckInRIFF->ckid != FOURCC_RIFF) || (pckInRIFF->fccType != mmioFOURCC('W', 'A', 'V', 'E')))
return E_FAIL;
// Search the input file for for the 'fmt ' chunk.
ckIn.ckid = mmioFOURCC('f', 'm', 't', ' ');
if (0 != mmioDescend(hmmioIn, &ckIn, pckInRIFF, MMIO_FINDCHUNK))
return E_FAIL;
// Expect the 'fmt' chunk to be at least as large as <PCMWAVEFORMAT>;
// if there are extra parameters at the end, we'll ignore them
if (ckIn.cksize < (LONG)sizeof(PCMWAVEFORMAT))
return E_FAIL;
// Read the 'fmt ' chunk into <pcmWaveFormat>.
if (mmioRead(hmmioIn, (HPSTR)&pcmWaveFormat, sizeof(pcmWaveFormat)) != sizeof(pcmWaveFormat))
return E_FAIL;
// Allocate the waveformatex, but if its not pcm format, read the next
// word, and thats how many extra bytes to allocate.
if (pcmWaveFormat.wf.wFormatTag == WAVE_FORMAT_PCM)
{
if (NULL == (*ppwfxInfo = new WAVEFORMATEX))
return E_FAIL;
// Copy the bytes from the pcm structure to the waveformatex structure
memcpy(*ppwfxInfo, &pcmWaveFormat, sizeof(pcmWaveFormat));
(*ppwfxInfo)->cbSize = 0;
}
else
{
// Read in length of extra bytes.
WORD cbExtraBytes = 0L;
if (mmioRead(hmmioIn, (CHAR *)&cbExtraBytes, sizeof(WORD)) != sizeof(WORD))
return E_FAIL;
*ppwfxInfo = (WAVEFORMATEX *)new CHAR[sizeof(WAVEFORMATEX) + cbExtraBytes];
if (NULL == *ppwfxInfo)
return E_FAIL;
// Copy the bytes from the pcm structure to the waveformatex structure
memcpy(*ppwfxInfo, &pcmWaveFormat, sizeof(pcmWaveFormat));
(*ppwfxInfo)->cbSize = cbExtraBytes;
// Now, read those extra bytes into the structure, if cbExtraAlloc != 0.
if (mmioRead(hmmioIn, (CHAR *)(((BYTE *)&((*ppwfxInfo)->cbSize)) + sizeof(WORD)),
cbExtraBytes) != cbExtraBytes)
{
delete *ppwfxInfo;
*ppwfxInfo = NULL;
return E_FAIL;
}
}
// Ascend the input file out of the 'fmt ' chunk.
if (0 != mmioAscend(hmmioIn, &ckIn, 0))
{
delete *ppwfxInfo;
*ppwfxInfo = NULL;
return E_FAIL;
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: WaveOpenFile()
// Desc: This function will open a wave input file and prepare it for reading,
// so the data can be easily read with WaveReadFile. Returns 0 if
// successful, the error code if not.
//-----------------------------------------------------------------------------
HRESULT WaveOpenFile( std::string const &Filename, HMMIO *phmmioIn, WAVEFORMATEX **ppwfxInfo,
MMCKINFO *pckInRIFF)
{
HRESULT hr;
HMMIO hmmioIn = NULL;
if (NULL == (hmmioIn = mmioOpen(const_cast<char*>(Filename.c_str()), NULL, MMIO_ALLOCBUF | MMIO_READ)))
return E_FAIL;
if (FAILED(hr = ReadMMIO(hmmioIn, pckInRIFF, ppwfxInfo)))
{
mmioClose(hmmioIn, 0);
return hr;
}
*phmmioIn = hmmioIn;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: WaveStartDataRead()
// Desc: Routine has to be called before WaveReadFile as it searches for the
// chunk to descend into for reading, that is, the 'data' chunk. For
// simplicity, this used to be in the open routine, but was taken out and
// moved to a separate routine so there was more control on the chunks
// that are before the data chunk, such as 'fact', etc...
//-----------------------------------------------------------------------------
HRESULT WaveStartDataRead(HMMIO *phmmioIn, MMCKINFO *pckIn, MMCKINFO *pckInRIFF)
{
// Seek to the data
if (-1 == mmioSeek(*phmmioIn, pckInRIFF->dwDataOffset + sizeof(FOURCC), SEEK_SET))
return E_FAIL;
// Search the input file for for the 'data' chunk.
pckIn->ckid = mmioFOURCC('d', 'a', 't', 'a');
if (0 != mmioDescend(*phmmioIn, pckIn, pckInRIFF, MMIO_FINDCHUNK))
return E_FAIL;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: WaveReadFile()
// Desc: Reads wave data from the wave file. Make sure we're descended into
// the data chunk before calling this function.
// hmmioIn - Handle to mmio.
// cbRead - # of bytes to read.
// pbDest - Destination buffer to put bytes.
// cbActualRead - # of bytes actually read.
//-----------------------------------------------------------------------------
HRESULT WaveReadFile(HMMIO hmmioIn, UINT cbRead, BYTE *pbDest, MMCKINFO *pckIn, UINT *cbActualRead)
{
MMIOINFO mmioinfoIn; // current status of <hmmioIn>
*cbActualRead = 0;
if (0 != mmioGetInfo(hmmioIn, &mmioinfoIn, 0))
return E_FAIL;
UINT cbDataIn = cbRead;
if (cbDataIn > pckIn->cksize)
cbDataIn = pckIn->cksize;
pckIn->cksize -= cbDataIn;
for (DWORD cT = 0; cT < cbDataIn; cT++)
{
// Copy the bytes from the io to the buffer.
if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead)
{
if (0 != mmioAdvance(hmmioIn, &mmioinfoIn, MMIO_READ))
return E_FAIL;
if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead)
return E_FAIL;
}
// Actual copy.
*((BYTE *)pbDest + cT) = *((BYTE *)mmioinfoIn.pchNext);
mmioinfoIn.pchNext++;
}
if (0 != mmioSetInfo(hmmioIn, &mmioinfoIn, 0))
return E_FAIL;
*cbActualRead = cbDataIn;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: CWaveSoundRead()
// Desc: Constructs the class
//-----------------------------------------------------------------------------
CWaveSoundRead::CWaveSoundRead()
{
m_pwfx = NULL;
}
//-----------------------------------------------------------------------------
// Name: ~CWaveSoundRead()
// Desc: Destructs the class
//-----------------------------------------------------------------------------
CWaveSoundRead::~CWaveSoundRead()
{
Close();
SafeDelete(m_pwfx);
}
//-----------------------------------------------------------------------------
// Name: Open()
// Desc: Opens a wave file for reading
//-----------------------------------------------------------------------------
HRESULT CWaveSoundRead::Open(std::string const &Filename)
{
SafeDelete(m_pwfx);
HRESULT hr;
if (FAILED(hr = WaveOpenFile(Filename, &m_hmmioIn, &m_pwfx, &m_ckInRiff)))
return hr;
if (FAILED(hr = Reset()))
return hr;
return hr;
}
//-----------------------------------------------------------------------------
// Name: Reset()
// Desc: Resets the internal m_ckIn pointer so reading starts from the
// beginning of the file again
//-----------------------------------------------------------------------------
HRESULT CWaveSoundRead::Reset()
{
return WaveStartDataRead(&m_hmmioIn, &m_ckIn, &m_ckInRiff);
}
//-----------------------------------------------------------------------------
// Name: Read()
// Desc: Reads a wave file into a pointer and returns how much read
// using m_ckIn to determine where to start reading from
//-----------------------------------------------------------------------------
HRESULT CWaveSoundRead::Read(UINT nSizeToRead, BYTE *pbData, UINT *pnSizeRead)
{
return WaveReadFile(m_hmmioIn, nSizeToRead, pbData, &m_ckIn, pnSizeRead);
}
//-----------------------------------------------------------------------------
// Name: Close()
// Desc: Closes an open wave file
//-----------------------------------------------------------------------------
HRESULT CWaveSoundRead::Close()
{
if( m_hmmioIn != NULL ) {
mmioClose( m_hmmioIn, 0 );
}
return S_OK;
}

48
old/wavread.h Normal file
View File

@@ -0,0 +1,48 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
//-----------------------------------------------------------------------------
// File: WavRead.h
//
// Desc: Support for loading and playing Wave files using DirectSound sound
// buffers.
//
// Copyright (c) 1999 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#pragma once
#include <mmsystem.h>
#include <string>
HRESULT WaveOpenFile(std::string const &Filename, HMMIO *phmmioIn, WAVEFORMATEX **ppwfxInfo,
MMCKINFO *pckInRIFF);
HRESULT WaveStartDataRead(HMMIO *phmmioIn, MMCKINFO *pckIn, MMCKINFO *pckInRIFF);
HRESULT WaveReadFile(HMMIO hmmioIn, UINT cbRead, BYTE *pbDest, MMCKINFO *pckIn, UINT *cbActualRead);
//-----------------------------------------------------------------------------
// Name: class CWaveSoundRead
// Desc: A class to read in sound data from a Wave file
//-----------------------------------------------------------------------------
class CWaveSoundRead
{
public:
WAVEFORMATEX *m_pwfx; // Pointer to WAVEFORMATEX structure
HMMIO m_hmmioIn{ NULL }; // MM I/O handle for the WAVE
MMCKINFO m_ckIn; // Multimedia RIFF chunk
MMCKINFO m_ckInRiff; // Use in opening a WAVE file
public:
CWaveSoundRead();
~CWaveSoundRead();
HRESULT Open(std::string const &Filename);
HRESULT Reset();
HRESULT Read(UINT nSizeToRead, BYTE *pbData, UINT *pnSizeRead);
HRESULT Close();
};