mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
* Enhance Windows build matrix with AVX2 variants * fix(lang): the two Polish lines of the download area written with \n, so they match the tooltip and the hint * fix(files): data named in another case is found on Linux, folders included The parser and the loaders lowercase every name they read, while the data made on Windows has files and folders named in any case (scenery/Braniewo, textures/siec_trakcyjna_ph/.../STS_*.tga, sounds/sip/Gorki.wav). FileCased matched the file name only, so a folder in another case wasn't found. - FileCased walks every part of the path on Linux, the folder listings kept by their lowercase and read again once the folder changed; Windows as it was - FileExists finds the file in any case on Linux, and the variant with names and extensions gives back the name as it's on the disk, so textures, materials, sounds, station announcements and scripts open that name - models, sound captions, timetables and nodebank previews open the file as it's named on the disk; the texture format is told by the extension in any case * fix(files): the banks keep the names asked for, only the opening takes the case of the disk The textures, materials and sounds are kept by the names they're asked for. Given back as named on the disk, a file in another case missed the bank and was loaded again on every request. - FileExists with names and extensions finds the file in any case but gives back the name asked for; FileOnDisk gives the file to open, used where textures, sounds and scripts are opened - FileExists of a single name is a plain check again, the places checking it and opening the same name stay as they were - the texture format is told by the extension asked for again - a folder changed shortly before it was read is read again for a name missing from it, the time of a change being as coarse as the clock of the file system; a listing cut short isn't kept * fix(files): a folder changed in the future isn't read again on every name missing from it * perf(files): a file missing costs a single check, as before Measured in a case sensitive folder (3000 textures, every 20th in mixed case, looked up the way Texture.cpp does), the walk over every part of the path made a texture lookup 4-5 times slower than master: each name tried and missing checked every folder of its path. - the folders found are kept by the name they're given with, the missing ones for a second, so a missing file checks its folder alone - a folder named as it is on the disk is taken without its listing - the time a folder was changed is looked at once a second at most The lookup is now as fast as master's (about 180 us per texture on NTFS in both) while finding the files named in another case too. * fix(files): terrain files named in another case are found on Linux The terrain directive names .txtf/.btf files in lowercase, as the parser gives every token. The name is now taken as it is on disk, from the text file first, so the binary file is made next to the text and the editor's references and layers keep one name. * fix(files): models named in another case are found on Linux The manager of the models looked for the file with FileExists of a single name, a plain check again since the banks keep the names asked for, so a model named in another case (models/przejazdy/plyty3_L, dynamic/pkp/st44_v2/main/2M62-0685-A) was reported missing before TModel3d::LoadFromFile() could open it as it's named on the disk. find_on_disk() finds the file in any case and gives back the name asked for, the key of the bank. * refactor(files): named functions instead of the lambdas of the folder cache (Sonar S2259, S3608, S6004) Sonar took the folder captured by the lambda reading it for a reference to null, failing the quality gate on reliability. The folder is read and the path kept by functions in the anonymous namespace, the age of the listing declared in its if. * fix: the simulator opens more than 512 files at once, and a shader it can't open says why With "physicslog yes" every driver keeps its .dat open, and a large scenery (Tomaszewo: some 500 vehicles, cars of the roads included) took all 512 streams the MSVC runtime gives: the next fopen failed and the simulator stopped at "cannot read shader: shaders/map.vert" on opening the map. The limit is raised to 8192 at the start (the soft limit of open files up to the hard one on Linux), and a shader file that doesn't open is told as such, with the system's reason, rather than as one that can't be read. * feat(blackbox): the black box on its own, writing the tapes of the user's vehicles at the end "blackbox yes" in eu07.ini records the black box with the physics logs on or off, "blackbox no" never; with no entry it goes with "physicslog yes" as before. With the physics logs off, the recorder keeps the line of the physics log of the driver the user is with, every 0.05 s, and writes it to physicslog/<vehicle>.dat when the recording closes: the speed recorder's tape of the vehicles the user was in, without every vehicle keeping a log open and written twenty times a second. The line and the header of the log are made by one function of the driver, which its own log writes too, and the file is opened the same way, so the two are the same to the byte: the readers of these logs (the old Hasler tape viewer, the starter) read them as before. * feat(physicslog): the logs written every two seconds by a thread of their own, no file kept open; the black box's tapes as it goes "physicslog yes" kept the .dat of every vehicle with a driver open for the whole run and flushed it twenty times a second from the simulation's thread: some 580 open files on Tomaszewo. The lines are kept now and a thread of their own writes them every two seconds, each file opened only for the moment it is written to. The files, their lines and their text mode stay as they were. - The black box, with the physics logs off, writes the tapes of the user's vehicles through the same writer as it goes, not at the end. A log begins when the user is first in the vehicle and goes on while the user looks around outside, until another vehicle is taken; back in it, the log goes on after the gap. The vehicle's own driver keeps the log only if it is the primary one, as a passive one's clock stands still; otherwise the driver of its train does. - What is kept is written when the simulator closes, after the black box, at the end of a test run, and when the test watchdog ends a run. A crash loses the last two seconds. - On Tomaszewo with the black box alone, the one tape grows every two seconds. With "physicslog yes", the 581 logs grow and the simulator holds as many handles as without them; writing them takes the thread about 1.9 s, which the closing waits for once. * feat(blackbox): the cab record holds the speed of the wheels, apart from the vehicle's when they slip The speed of the cab record is the vehicle's. The speedometer, and a speed recorder's tape with it, shows the speed of the wheels as they turn, which runs away from it while they slip and drops to 0 while they are locked in a skid. It is added at the end of the record (194 bytes), where the readers skip what they don't know; the .dat tapes have it already, in their second column. * fix(ci): build OpenAL Soft with the PipeWire, PulseAudio and ALSA backends, so the Linux game has sound The Linux job builds OpenAL Soft 1.24.2 from source, but the runner had none of the headers of its audio backends, and OpenAL Soft's CMake leaves out every backend it can't find. The bundled libopenal.so.1 had only OSS, Null, Wave and Loopback. Modern distributions and the Steam Linux Runtime have no /dev/dsp, so the game logged "Failed to obtain audio device" and played nothing, with any Steam Linux Runtime and without one. - install libasound2-dev, libpulse-dev and libpipewire-0.3-dev before building OpenAL Soft - configure it with ALSOFT_REQUIRE_PIPEWIRE/PULSEAUDIO/ALSA, so a missing header fails the build instead of shipping a library without sound The backends are loaded with dlopen at run time (ALSOFT_DLOPEN is on by default), so the bundled library gains no new dependency. Tested by putting an OpenAL Soft 1.24.2 with these backends next to the game from the Steam depot: under Steam Linux Runtime 4.0 the sound works. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(editor): the certificates of https looked for where the distribution keeps them The Linux game bundles the libcurl of Ubuntu, which knows only Ubuntu's /etc/ssl/certs/ca-certificates.crt. Fedora, RHEL and openSUSE keep the certificates elsewhere, so every download of the editor (orthophoto, terrain model, topo map) failed there with a certificate error. The file is taken from SSL_CERT_FILE or CURL_CA_BUNDLE when set, else the first of the files the distributions keep, and passed as CURLOPT_CAINFO. With none found libcurl keeps its own. * fix(editor): an https proxy checked with the same certificates CURLOPT_PROXY_CAINFO gets the file found for CURLOPT_CAINFO, so a download through an https:// proxy on Fedora or RHEL doesn't fail on the proxy's certificate. * fix(ci): the no-AVX2 Windows build has its own concurrency group and its own public download After master was merged the two Windows variants shared one concurrency group with cancel-in-progress, so one cancelled the other, and the publish job looked for an artifact name the matrix no longer produces. Each variant now has its own group, the publish job downloads both, and the release carries maszyna-windows-x64.zip (AVX2, the old name, so the links already handed out still work) and maszyna-windows-x64-noavx2.zip. The AVX2 variant passes -DENABLE_AVX2=ON explicitly instead of an empty flag. * build: a build without AVX2 has _noavx2 at the end of its executable name With ENABLE_AVX2=OFF the executable is eu07-x64_<date>_<hash>_noavx2.exe (eu07-x64_noavx2.exe without ADD_VERSION_SUFFIX), so a starter can tell the two builds apart by the name alone and pick this one on a CPU without AVX2. The AVX2 build keeps its name. * ci: Linux is built without AVX2 too, published as maszyna-linux-x64-noavx2.tar.gz The Linux job becomes the same two-variant matrix as Windows (ENABLE_AVX2=ON/OFF), each variant with a concurrency group of its own. The publish job downloads both Linux artifacts, restores the executable bits in both and releases maszyna-linux-x64.tar.gz (AVX2, the old name) next to maszyna-linux-x64-noavx2.tar.gz. The no-AVX2 executable is eu07_<date>_<hash>_noavx2. * fix(renderer): the legacy renderer clears the arrays the scene left before it draws the ui The legacy renderer drew the ui with the client arrays of the last scene draw still enabled: the texture coordinates of the normal map unit and the normals, pointing into the vertex buffer of whatever was drawn last, 48 bytes a vertex. The ImGui backend sets up the vertex, colour and texture coordinates of the active unit only, so the driver read the stale arrays with the indices of the ui. Once the ui had more vertices than that buffer, the NVIDIA driver read past its end and the game crashed; a crash dump of the editor (an area selected, a track being laid) shows the read of vertex 15113 at a 48-byte stride in ImGui_ImplOpenGL2_RenderDrawData. The arrays are now disabled on every texture unit the geometry uses, with the normal and colour arrays, inside the glPushClientAttrib already there, so the scene gets its state back after the ui. The default and the experimental renderers don't go through this code. * fix(app): a renderer this build doesn't have starts the full one, not the legacy one The starter writes "gfxrenderer vulkan" for the Vulkan renderer of the builds that have it. This exe doesn't know the word, and every word other than default/experimental fell to the legacy renderer: a player who picked Vulkan got the slowest renderer, the one whose ui crashes on NVIDIA (the arrays left by the scene). "experimental" in a build without the NVRHI renderer ended with "no renderer found!" and no game at all. After the settings are read, a gfxrenderer word this build has no renderer for becomes "default", with a line in the log saying so. The words it knows stay as they were: full/default, legacy, simple, null, the older starters' simpleshader and off (legacy as before), and experimental where it is built. * fix(settings): the gfxrenderer word read in any case, as the starter reads it A hand-written "gfxrenderer Legacy" started the legacy renderer only because every unknown word did; with unknown words going to the full renderer it would have changed. The word is lowercased when read, as StarterNG's RenderEngineOf does, so Legacy, Simple or Full mean what they say. * fix(physicslog): a log whose file can't be written keeps its lines and header, and the writer is stopped once on every way out A failed write put its lines back, ahead of those since, so a file held by another program for a while gets its header and every line once it can be written; up to 4 MB kept per log. Stopping is joined once, and not from the writer's own thread. main stops the logs after an error it caught too, and the test watchdog flushes with a time limit, so a disk that doesn't answer doesn't keep the run from ending. * fix(blackbox): the wheels of the powered vehicle, as the speedometer has them, and the logs described as the drivers' they are In a unit driven from an unpowered car, the speed of the wheels was of the car the user is in, whose wheels never slip; now of the motor car, signed as the occupied vehicle's speed. The doc tells of a log per driver, and of the two seconds of real time a crash loses. * fix(physicslog): failed logs kept within 64 MB in all, cut outside the lock, never written twice; the writer knows itself when stopped The lines kept while files can't be written are cut to their share of 64 MB before the lock the simulation waits on. A log written in part is cut back to its length, so the next try doesn't write its start twice. A stop from the writer itself is told by its id even after another thread took it to join, and the watchdog's flush waits at most its time, the writing on a thread of its own. * feat(physicslog): the logs of the trains only, physicslog.trains "physicslog.trains yes" in eu07.ini writes the .dat log of each driver who drives rail vehicles, not of the passengers nor of the road vehicles that make "physicslog yes" hundreds of files on a big scenery: the tape of every train. A driver made primary later begins its log then, and isn't counted while it doesn't log. The black box goes with it when the ini says nothing of its own, and doesn't write a second log of a driver writing its own. The doc tells the doors' sides are the vehicle's, the driver's swapped in the rear cab. * fix(physicslog): a train's log begun at its first line, so passive crews get no file Every crew is primary in the constructor and the drivers but one of a train with crews in more vehicles are made passive only before it starts, so a log begun there left files with only the header. With physicslog on all logs begin at once as before; one of a train waits for update_logs. * fix(editor): the texture pickers let go of the images scrolled past, the memory no longer runs out The picker of the textures of a track offers every texture of the textures folder, and each tile that came into sight read its texture full size, into the graphics card and the memory, and kept it there for good. Scrolling through the list for a trackbed texture took about 2.5 MB a tile: some 900 tiles made 3.5 GB, the whole folder 28 GB, and the game went down once the memory ran out. An image out of sight for 3 seconds is now taken out of both again (texture_manager::unload, Unload_Texture of the renderers) and read anew when it's shown once more, a few a frame as before. Only a texture the scene has never drawn is let go; those of the scene stay to the resource sweep. The texture browser lets go of its images on Refresh too. The picker no longer lists textures/previews: the 4100 previews of the node bank are images of models, not textures of anything. Checked on td.scn by a scripted run: 8000 images of the picker read one batch a few frames after another held the game at 2-3 GB, where it went to 28 GB and fell before; images shown again after they were let go come back; a trackbed texture picked from the folder is drawn on the track after its image was let go. * fix(physicslog): the writer's destructor throws nothing, its wait a plain condition variable woken to stop; a driver of no vehicle controls nothing * fix(editor): the images of the materials let go of with all their textures, the browser's Refresh a frame later An image of a material read the material with all its textures, the normal and specular maps and the variants, and only the first one was let go of: those stayed in the memory for every material scrolled past. They are let go of together now (Unload_Material). texture_manager::unload also takes the textures read and not made yet, waiting for a worker still reading one, and deletes the gl texture itself: release() would read it back from the card with gfx.resource.move only for it to be dropped. The Refresh of the texture browser let go of the images in the middle of the frame, while panels drawn before it could still refer to them; it now marks them, and they go at the start of the next frame. Checked on td.scn by a scripted run: 8040 images of the picker read a batch every few frames end at 2.0 GB, against 2.3-2.6 GB before this and 1.1 GB at the start; a trackbed material picked from the folder is drawn on the track after its image was let go. * fix(physicslog): every stop asked wakes the writer, the one from itself too; no psyche for a driver of no vehicle * fix(editor): the image of a material with no texture in its first slot is let go of too Its normal and specular maps were read with it and stayed in the memory: the trim passed over every image with no texture of its own, the material along with it. * fix(physicslog): nothing that goes wrong in the writing ends the simulator; a name in 1250 makes a path on a Windows set to UTF-8 The writer's thread called flush() with nothing around it, so an exception leaving write() ended the process with std::terminate, with no message. One that happens: the file of a log was made a std::filesystem::path of the vehicle's name, which MSVC converts in the code page of the system and throws for bytes not of it; on a Windows with "Use Unicode UTF-8 for worldwide language support" a vehicle named in 1250, as the sceneries have them (0xB3 for ł), isn't UTF-8. - the file of a log is made of the name with MultiByteToWideChar without MB_ERR_INVALID_CHARS: the same file as before for every name of the code page, U+FFFD for the bytes not of it instead of a throw. Elsewhere the bytes are the name of the file as they were - a log whose writing throws for any other reason (memory) is kept for the next try as one whose file can't be written, and the other logs are written still - the thread, flush_for() and stop() write through flush_safely(), which lets nothing out: what was taken for a writing failing as a whole is lost and told in the log, the next writing goes on - the messages name the file by the bytes of the name, not by path::string(), which converts back Tests: a log which can't be written doesn't keep the others from theirs; a vehicle named in 1250 has its log, read back by physicslog_writer::file(). Reported in the review of #385. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(blackbox): the tapes go on after the editor, with the physics logs off The tapes of the user's vehicles were written by update() after the check for the writer of the recording, which close() drops on entering the editor (F11). With "physicslog no", the speed recorder's tape ended at F11 while the drivers' own logs of "physicslog yes" went on. The tapes are files of their own: they are kept from the moment the recording was to be made, the file made or not, closed or not, until the simulator closes, after the gap of the time in the editor. Only the recording itself stops at F11, as before. Reported in the review of #385. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(physicslog): what no file name may have on Windows is replaced in the name of a log, on every system A spawned vehicle is named <spawn>:<number>, and its log went to physicslog/<spawn>:<number>.dat. On NTFS that isn't even an error: it is the stream <number>.dat of the file <spawn>, which nothing lists, so the log was written and no one could find it. On Linux the file was there, under a name Windows can't open. The name of the file of a log has < > : " / \ | ? * and the control characters replaced by _, on every system, so the logs are named alike everywhere (spawn_ezt:12 is spawn_ezt_12.dat), and a _ before a name Windows keeps for a device (con, nul, com1..., with an extension too). The bytes of 1250 stay. The black box tells the log it begins by the same name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(renderer): a material's textures let go of in one place, for every backend Unload_Material walked the textures of a material and of its variants the same way in both opengl renderers, and Sonar counted its declarations, set into the long run of overrides the two headers share, as duplicated: 5.2% of the new code, 3% allowed. The walk is gfx_renderer's now, over IMaterial::GetAllTextures and the backend's Unload_Texture. Materials that don't tell their textures, the Vulkan renderer's, give none, and are left alone as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * AI: shunting brakes for a stop point again; test mode: no false SPAD for a train set across a signal (#409) * fix(ai): shunting AI brakes for a stop point again, the braking curve doesn't plan from a brake table left at zero The braking curve outside the final approach plans from the consist brake table sincece87aa0e(#187, merged with #264) whenever the brake is pneumatic. That table is worked out only for train running (Obey_train, Bank); in shunting it stays at zero, the planned full braking falls to its floor of 0.01 m/s2, and the demand comes out at a few hundredths of a m/s2, above the shunting brake threshold of -0.2. A shunting engine then rolled on without braking until the final approach, too late, and ran through the signal it was to stop at (seed 480873929 of l053_poranek: ep07p-2003 at sandomierz_g4_sem_info, sm42-1096, et22-654). With no worked out table the curve is again the constant deceleration over the distance left, as it was beforece87aa0eand as #187 meant to keep it for shunting. Train running is unchanged. The curve moves out of TController into vehicle/brakingcurve.{h,cpp} so that it is unit tested: tests/unit/test_braking_curve.cpp checks a shunting engine braking to a stop point with the zeroed table, and that a train with a worked out table gets the same demand as before. * test(ai): pin the train braking-curve demand to the results of the code before the move A brake table that grips harder as the train slows and a gradient, so that a wrong gravity sign, table index or a dropped term in the shaped demand shows; the expected values were worked out with the code removed from TController::adjust_desired_speed_for_braking_curve. * fix(test): a train set across a signal doesn't pass it at danger the moment the AI first looks at it The speed table takes in events up to a train length behind the head, so a signal the train stands across at the start of a scenario is found already behind the head, becomes elapsed on its first update, and the test mode reported it as passed at danger (calkowo_lotos: st43-189 at mac_daleko3_sem_info, manewrowo3: st43-100 at suw_szopa_a02_sem_info, both at 13.6 s with the train at a stand, the signal 20 m behind the head). A point now counts as passed only when the head of the train had it ahead once; the blackbox record of passed signals follows the same rule. * fix(test): a signal found up to 5 m behind the head still counts as seen ahead The distance to an event is found in steps of a metre from the position of its memory cell, so a signal just ahead of the head (a train stopped short of it when the autopilot takes over, or set right at it at the start) could come out slightly behind it, and passing it would not be reported. The trains set across a signal that the previous commit is about stood 20 m past it. Still not reported: a signal crossed while the speed table is being traced anew in motion (a Timetable: command to a running train, the autopilot taking over in motion), as it is found behind the head when the trace is made. * docs(test): say what the seen-ahead tolerance gives up A train set less than 5 m past a signal at stop is still reported to pass it at danger: standing that close it can't be told from a train stopped just short of the signal, which the tolerance is there for. --------- Co-authored-by: maj00r <maj00r@host> * fix(camera): the roll of the cab shake tilts the view about the line of sight again (#414)623c4f82(#97, in 26.05.1) changed the order of the camera rotations from Z, X, Y to X, Y, Z. The order matters only with a roll, which the cab shake gives (Angle.z, set in drivermode.cpp), or a camera entry of the scenery with a roll. Applied last, in the space of the cab, the roll nodded the view up and down when looking out of a side window instead of tilting it. The roll is multiplied in first again, as in 26.05. Co-authored-by: maj00r <maj00r@host> * fix(particles): the smoke of a cold diesel keeps the colour of its template (#413)bcb9e644(#109) turned a comparison into an assignment: the smoke of a vehicle in air at 5 degrees or less, or with its engine under 45 degrees, got the colour 128,128,128. The emitter colour is on a 0-1 scale, so the smoke turned pure white, glowing at night, and stayed so once the engine warmed up. Up to 26.05 the line compared and did nothing; the smoke keeps the colour of its template again, as it did then. Co-authored-by: maj00r <maj00r@host> * Fix stutter with fpslimit on Windows and a texture unit cache race with threaded Python screens (#399) * fix(render): the python upload thread only marks the texture unit cache stale, the drawing thread clears it update_from_memory() runs on the python upload thread with python.threadedupload (the default), and sincee230d7b9it cleared opengl_texture::units there outright. That raced Bind_Material filling the same array for its multi-bind: a unit reset between the fill and glBindTextures() made the bind of that unit fail, and the object was drawn with the texture of the one drawn before it, for a frame, at the rate of the screens. The thread now sets an atomic flag, and the drawing thread clears the cache when it next binds textures (bind() and the multi-bind of Bind_Material), so a screen texture given a new gl name is still rebound. * fix(app): fpslimit asks Windows for the 1 ms timer, the frames no longer come in turns long and short The wait of fpslimit sleeps, and Windows wakes a process which didn't ask for a finer timer in steps of up to ~15.6 ms. A 10 ms slot of fpslimit 100 ended ~15.6 ms later, the pacer made it up with no wait in the next frame, and with vsync on the frames were shown for one or two refreshes in turn: visible stutter at a steady FPS. timeBeginPeriod(1) is held from the settings to the exit, only when fpslimit is set. * fix: the 1 ms timer also for an fpslimit set by the scenery, the stale unit cache checked with a plain load first A config block of the scenery is parsed after the settings and can set fpslimit, so the timer period is asked for at the first wait of the pacer too, once. bind() checks the stale flag of the unit cache with a relaxed load before the exchange, which it does for every texture. * fix(textures): the stale flag of the unit cache uses the default memory order (Sonar S8417) On x86 a sequentially consistent load and exchange cost the same as the relaxed and acq_rel ones; only the store in invalidate_unit_cache() becomes an xchg, and it runs rarely. --------- Co-authored-by: maj00r <maj00r@host> * fix(camera): the cab shake taken at the frame's moment between its fixed steps, it no longer moves in steps (#403) The shake of the cab camera (ShakeState) is stepped by update_shake at a fixed 1/50 s, while the camera read the raw state every frame. At any frame rate other than 50 the shake moved in steps: some frames showed the same state as the one before, others jumped one or two steps at once. Players with 144/165 Hz screens saw the cab jump around the camera. The vehicle now keeps the state from before the last step (ShakeStateBefore), and the camera takes the state between the two at the share of the step the simulation time has reached (shake_between). The offset and the velocity are blended, the angles worked out from the blended velocity. The shake itself is computed as before, with the same fixed step and the same springs; only what the camera shows of it changes. It lags the vehicle by a constant 1/50 s instead of 0 to 1/50 s. Measured with the same build and the blending switched off by a temporary environment variable (not in this commit), the EU07 on td.scn driven by the AI, frames over 30 km/h, two runs of each: - 60 fps: frames with the shake standing still 25% -> 0%, the change in its speed frame to frame 4-5 times smaller for the offset, a third smaller for the angles - ~144 fps: 65% -> 0%, 10-18 times smaller for the offset, 4 times for the angles - no fps limit (~520 fps): 90% -> 0% Co-authored-by: maj00r <maj00r@host> * fix: inverted clamp bounds give the upper bound again, as the old clamp did (#412) * fix: inverted clamp bounds give the upper bound again, as the old clamp did The project's own clamp() of 26.05 applied the lower bound first and the upper one last, so bounds given the wrong way round always gave the upper one. Its calls became std::clamp (undefined for such bounds) and, where the bounds can cross, safe_clamp, which swapped them instead. Neither gives the old result. - safe_clamp is the old clamp again, min(max(value, lo), hi). This restores 26.05 at every place it is used, among them the AI's dynamic brake test (its demand was fAccThreshold x1.21, the swap made it x1.01), the generator voltage, the heavy cargo acceleration of the AI and the EP correction of the brake. - The cab camera is kept inside the cab with safe_clamp. The bounds come from the .mmd as written and some cabs have them reversed (the B cars of SA134 and 21xM, ET40, 754); with std::clamp the camera jumped between the two bounds every frame on MSVC, as its result is fed back. * fix: every call of the old clamp gives what it gave up to 26.05.1d1f16411(#99) made every call of the project's clamp() std::clamp. Where the bounds come from the data or are computed at runtime they can cross, and then std::clamp gives another result (undefined behaviour; MSVC gives the lower bound unless the value is above the upper one) where the old clamp gave the upper bound. These calls use safe_clamp, the old clamp, too: - Mover: the pantograph pressure (MaxPress), the compressor switch (CompressorListPosNo), the coupler distance (DmaxB, DmaxC), the engine revolutions, the eimic ramp (CtrlDelay), the eimic limit (eimic_max), the speed control ramp (PowerUpSpeed, PowerDownSpeed), the load (MaxLoad), the magnet of the security system (Dim.L); - DynObj: the coupler distance of the buffers (DmaxB), the axle distance (Dim.L); - Train: the brake handle positions (BrakeCtrlPosNo, the range of the handle); - the legacy renderer: the mouse pick (the window size). With the bounds in order nothing changes. Calls whose bounds the code keeps in order (constants, SplineFidelity 1-4, the season table, the guarded output calibration) give the same result with std::clamp and stay as they are. The load offset takes its arguments in the 26.05.1 order again;fa2ed089swapped them, which with the old clamp differs only for a negative load. The bump at a rail joint gives the old result again. Up to 26.05.1 its clamps had 0 in place of the value (since96f43e11and4d72d352), and the old clamp made that the headroom Vmax - (Vel + 0.32 Vmax), negative above 68% of the top speed, capped from above only;d464628aand03bfbb13kept it at 0 or above. Only damaged track has the bump: a damage flag in the .scn, a derailer set by an event, a track made on a derailment. The interior light of the cab in the 3.3 renderer is computed in double again, as befored1f16411. The call added since (stepped_uc_value,00955513) keeps what master does: bounds given the other way round are put in order. * fix: the alpha of a particle in the legacy renderer as up to 26.05.1, the NaN cases of the clamp tested Up to 26.05.1 the alpha was clamp<std::uint8_t>( particle.opacity * 255, 0, 255 ): the float was made a byte first, so the clamp did nothing and an opacity over 1 (a smoke max_opacity over 1) wrapped round, 1.2 giving 50. The move to std::clamp made it 255. It's made a byte as then again, through int: the byte the x86-64 compilers gave, without the undefined behaviour of that conversion (MSVC makes the same two instructions of both). openglparticles.cpp goes with feat/gl46-migration; its opengl33 counterpart, std::clamp( opacity, 0, 1 ), already gives what 26.05.1 gave. The tests pin what the old clamp gave with NaN: a NaN value stays NaN, a NaN bound doesn't clamp. The checks named after the AI braking test and the bump at a rail joint say they test the helper with the arguments of those calls, not the calls. * test: the includes of the clamp tests before the project's headers <cmath> and <limits> go up, after the test headers, so the change no longer touches the lines #416 adds its includes after. With both merged <cmath> is included twice, which is harmless. --------- Co-authored-by: maj00r <maj00r@host> * Python screens: the worker's image goes in place only after its fence, not a bare glFlush (#411) * fix(python): a screen uploaded by the worker goes into a texture of its own, put in place after a fence With python.threadedupload (the default) the worker wrote the image into the texture the drawing thread draws from, with glTexImage2D and glGenerateMipmap from its own context, and only a glFlush after. Nothing ordered the two contexts: the drawing one could sample the texture while its storage was being made anew, its level 0 half written or its mipmaps not made yet, and on a change of size the worker deleted the texture and wrote a new name into `id` with no synchronisation. The worker now uploads each image into a new texture, sets a fence after it and flushes. The drawing thread, once per frame in python_taskqueue::update(), waits for that fence on the gpu (glWaitSync, the cpu goes on), deletes the old texture and puts the new one in place. The worker no longer touches the texture drawn from, nor `id`. An image the drawing thread didn't take yet is dropped by the next one. Without sync objects the worker waits for the upload with glFinish. The windows of python.displaywindows with python.sharectx bound the texture once; they now bind the name of the last image put in place, which python_rt keeps for them. Uploads on the drawing thread (python.threadedupload no, the Lua and WebAssembly screens, the editor) are as they were. * fix(python): the image of the worker goes in place once its fence is signalled, the viewer binds it each frame From the review of8811ee5a: - glWaitSync ordered only the context of the main window. The extra viewports and the windows of python.displaywindows draw in contexts of their own and could bind the new texture before the upload was done. commit_thread_upload() now asks the fence without waiting (glClientWaitSync, timeout 0) and puts the image in place only once it is signalled, so every context binding it afterwards has it whole. Until then the task stays in the upload queue and is asked again the next frame. - The drawing thread chose between upload and commit by python.threadedupload, the worker by whether it got a context. With python.threadedupload on and no context made for the worker, the screens were no longer updated. The task now records that a worker uploaded it. - The viewer of python.displaywindows told a new image by its texture name, but a deleted name comes back for a later texture. It binds the name of the last image each frame, read under the lock of the render target, and the name it starts with is read on the drawing thread when it is made. * fix(python): the old texture deleted under the lock the viewers bind under, a fence not made waited for with glFinish From the review of #411: - finish_upload() deleted the old texture before it took the lock of the render target, and the windows of python.displaywindows read the name under that lock but bound it after letting go of it. A window could bind a name already deleted, or already given to the next upload. In a compatibility context (the legacy renderer) that makes a new empty texture: a black frame and a texture never deleted. The commit and the publishing of the new name now go under the lock, and the viewer binds under it too. A name bound before the deletion stays alive in that window's context while bound. - A glFenceSync that returns no fence was taken for a signalled one: the image went in place at once, with nothing ordering the contexts. The worker now waits for its upload with glFinish then, as without sync objects. * fix(python): the worker waits for the lock of the screen without the gil, no flush after a finish From the review of939514ea: - The drawing thread now holds the lock of the render target for a whole upload with python.threadedupload off. The worker, copying the next image under that lock, waited for it holding the gil. It now lets the gil go around the lock and the copy: the bytes it copies stay valid, the object is immutable and held by the reference the worker has. - glFlush after glFinish did nothing; the worker flushes only when it made a fence. --------- Co-authored-by: maj00r <maj00r@host> * fix(models): a scenery light that is off no longer shows lit for a moment the first time it comes into view (#407) * fix(models): a scenery light that is off no longer shows lit for a moment the first time it comes into view Sinced13c27a7(the light blinking rework) the opacity of a light changes step by step from its last value, and the opacities start at 1. RaAnimate runs only for the instances that are drawn, so a model with "lights 0" (a W24 LED indicator, for one) was drawn lit when it first came into range and faded out over 0.45 s. Befored13c27a7the opacity of a plain on/off light was worked out anew from a timer starting at 0, so a light that is off was off from the first frame. Now the first time an instance is animated its lights take their current state at once, whether it came from the definition or from an event since. Every later change fades as before. The light threshold modes (ls_Dark, ls_Home) are untouched. The only other difference from befored13c27a7: a light that is on no longer fades in the first time it is drawn. * fix(models): the light opacity step written without an implicit double to float conversion (Sonar S5276) The sum is still worked out in double and rounded to float once, as the compound assignment did, so the result is the same to the bit. --------- Co-authored-by: maj00r <maj00r@host> * Editor: switch drives with no switch listed and marked; a deleted switch takes its drives and ballast along (#330) * feat(track): the rail code split by concern, the blades of the switches with the key frogs shaped from their templates The rails are laid by code of their own instead of inside Track.cpp: gauge lines (GaugeLine), knot lines (Knots.h), crossings and check rails (RailCrossings), rail materials (RailMaterials), measuring the rail profile (RailProfile), planning the cuts (RailPlan), the carving scan (RailCarve) and laying the geometry (RailLayer). A switch with the key frogs draws its blades from the tip where their planed nose ends to the heel, bent as they're thrown, and the rail behind them from the heel on, where they were laid from the start of the switch before; on a switch of the catalogue they start at the cut tip of the tables, 1.248 m from the joint at R 190, 1.5 m at R 300 (track_features::blades). The frogs cut from the rails, the wing and the check rails are built but switched off (track_features::crossings), the rails laid whole as before. The switches without the key keep the blades they had. A switch path can be a chain of pieces: pieces1 and pieces2 keep the parts of each path after the classic bezier, which stays as the approximation older versions read. A path with its radius given is a curve however gently it bends, a plain track a straight only where both of its control vectors lie along it. A vehicle trailing through a switch with a movable nose set the other way runs off the rails at it (TRAILED_SWITCH). * feat(render): the shared treads of the rails and their cut faces drawn, the cut faces in the matte variants of the rail materials Both renderers draw the treads a track shares with the rails it crosses, in the pick pass too, and a pass of their own for the faces where the rails are cut, the ends of the blades among them, in the matte variants of the rail materials, so the cut faces don't shine like the head the wheels polish. * feat(vehicle): an axle on a switch keeps to the path it came on, and coming from the frog end trails the switch through where the wheels reach the blades The switch thrown under an axle no longer moves it over onto the other path; it runs on along the one it entered. Coming from the frog end, where the blades are shaped or the frog has a movable nose, the switch set the other way is trailed through (rozprucie) only where the wheels get to the blades or to the nose, not as the axle enters the track; the other switches are trailed through as it enters, as before. * fix(track): the tracks drawn straight before, which their second control vector bends now, written to the log The simulator told a straight by the first control vector of a path alone, so a track whose second control vector bent it was drawn straight; now it's a curve. Such a track is named in the log as it loads, so a scenery made counting on the straight can be found: 25 tracks of lk357. Paths with both control vectors along them bend a centimetre or so at most and aren't named. * feat(track): 3D sleepers and switch timbers laid where the simulator makes the ballast, switched off in the build The sleepers of a track running alone are laid square to it, the timbers of the switches and crossings across the tracks running over them, shared by them, of the models set with sleepers3d and sleepers3dplain in eu07.ini; sleepers3dbed tells whether the ballast is laid under them too, lowered so they stick out of it. The layout of a cluster of tracks is worked out once and kept till a track of it changes, in a thread of its own while the simulation runs. timbermodel of a track, read and written back before, takes the place of the model of sleepers3d there. All of it is off whatever eu07.ini sets (track_features::sleepers), the tracks keeping their ballast and their sleeper models. * feat(render): the 3D sleepers and switch timbers drawn in instanced batches Render_Timbers lays the beams of the tracks in range where they're out of date and draws those of a run of tracks of a cell gathered by the model and its part or its level of detail, in as few instanced batches as they fit in; in the shadow pass only those near the camera. A track with them leaves its old sleeper model out. OpenGL 3.3 renderer only. * fix(track): the counts of what's wrong with the sleepers kept safe from the thread laying them, and that thread stopped before what it works with goes The counts of the beams clipped, dropped and off the plane, of the slowest and the biggest cluster, are counted by the thread working out the layouts in the background as well as by the simulation laying a cluster itself, and were plain values written by both; they're atomic now. What the thread keeps the clusters in, their version and the counts were made after the worker, as it first asked for them, and so destroyed before it at the exit while its thread could still be laying a cluster; they're made first now, the worker stopping and joining its thread before they go. The tracks go with the paths of the simulation, made before the worker. * revert(track): a tributary and a track of an unknown type load as before They came in with the rail code from the guards of the editor against crashing, and don't belong with the blades: a track of an unknown type loaded as a normal track of the railway could be joined to it and run on, and a tributary loaded as a river with its first path lost the second one when the editor saved the scenery. Both load as on master again; the place where the editor crashed on them is to be guarded where it is. * fix(track): the tracks drawn straight before named in the log once, as they load, and the paths of the switches with no radius told a straight as before in one term The log of the tracks the second control vector bends now was written each time the segments of a track were made again, as a track with its unevenness loads and as the editor changes or drags a track; it's written only the first time, as the track loads. The paths of a switch or a crossing with no radius keep the rule of master, a straight told by the first control vector alone, its two terms being the same length; they're one term now, with the comment saying so. * fix(track): the thread laying the sleepers stopped as the application exits, and loading no models itself The thread reads the scenery, which the application deletes as it exits well before the statics go: it's stopped and joined first thing in exit() now, the worker destroyed with the statics only where the application exits some other way, and not started again after. The models the beams are made of were loaded by the thread where it didn't find them, through the renderer, out of the thread of the renderer, into a map read by the simulation meanwhile: they're found under a lock now and loaded only by the threads other than it, again for all the tracks whenever a track changed since, before a layout is asked of it. With the 3D sleepers off in the build their settings aren't exported, and a track changed doesn't look for the tracks around to lay their beams again. * feat(track): the 3D sleepers turned on with sleepers3d in eu07.ini, no longer switched off in the build track_features::sleepers is gone: sleepers3d <model> in eu07.ini lays them, none (the default) lays nothing and the tracks keep their ballast, as before. The sleepers3d settings are written back with the others. The editor changes the tracks, so while it's open their sleepers are worked out on the main thread as they're needed, not in the background. * fix(render): only the part of a timber model drawn, not what else the model holds A timber model of parts may hold more than its begin, main and end, as the kits with the fastenings of the rails do. Those were drawn with each part of each timber, in the middle of the track; they aren't laid, so they're skipped now. * fix(track): the 3D sleepers laid only for a renderer which draws them Only the OpenGL 3.3 renderer draws the beams. With another one a track set to them lost its ballast to them, lowered or not laid at all with sleepers3dbed no, and nothing was drawn in its place. Draws_Timbers() of the renderer tells now, and where it's false the tracks keep their ballast, as with sleepers3d none. * fix(render): the submodels of a timber model left as they were after its parts are drawn They were all made visible after a part was drawn, the ones the model hides itself too, like Light_On, while the same model may stand in the scenery. The submodels of the top level besides the parts are listed as the model is loaded, hidden while a part is drawn and given back their own visibility after. The parts have to be at the top level of the model for that; a model with them deeper is logged and drawn whole. Render_Timbers no longer looks the model up under the lock for every run of tracks, the name set is enough there. * fix(render): a vertex whose faces give its texture no direction gets a tangent across its normal, not a NaN one The cut ends of the rails have one spot of the texture on all their corners, so their tangent came out of normalize() as NaN. The normal-mapped shaders then shaded them with a NaN normal: about half of the vertices of the cuts and frogs, and the end faces of the rails. * feat(track): the frogs cut from the rails turned on with frogs in eu07.ini, no longer switched off in the build frogs yes cuts the rails of the plain tracks and of the switches with the key frogs where they cross other rails, into frogs, wing rails and check rails. It's off by default: the rails are laid whole as before, the blades of the switches with the key are shaped still. * refactor(editor): the track mode file split into the files of its tools, the code as it was A pure move, so that the commits after it show what changes in each tool rather than a 4800-line file rewritten. The member functions of editor_mode go to the file the editor of this branch has them in: route, straights, lay, switchplace, switchdrive, switchtool, trackgizmo, and the rest stays in editormodetrack.cpp. The helpers of its anonymous namespace go to editormodetrackshared.h, as they were but inline, in namespace track_mode, which the files use. No line of code changes; the files add only their license, includes and the using line. * feat(editor): the groundwork the tools of the editor share - The tool interface (editortool.h), the gestures of the mouse (editorgestures.h) and what the modes share (editormodeshared.h); the projection, viewport, selection and texture picking taking them up. - Scripted input (scriptedinput): the input of a selftest script fed to the editor as if typed and clicked, the real mouse and keyboard ignored meanwhile; EU07_EDITOR_SELFTEST_HIDDEN draws into a window never shown nor focused. - The ui layers and panels of the editor, its settings, icons and the info of the includes; the layers of the scenery and their saving; the launcher mode. - utilities: user_cache_path (the cache folder of the system for the user) and the helpers of the translations. - stb_image: the gif loader takes the frame two back from the frames it decoded, not from before its buffer. - tools/editor: the scripts making the headers of the drives, the turntables, the editor and its usage. - Unit tests: test_area and the stubs of the editor the tests link. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the tracks laid along an alignment, to the PKP PLK norms, with their grade line and the ground - The alignment of the laying (editorAlignment, editorAlignmentStore): straights, transition curves and arcs with the cant of the norms for the speed, the radius below the minimum for it a warning; the lay, route and straights tools build on it, the route plan reading the curves going on from the tracks adjoining. - The grade line (editorProfile, the profile and gradeline tools): fitted to the terrain model or edited by hand, the tracks fitted marked in the scenery (//$f), the shared grade lines of nearly parallel tracks (//$n). - The ground under the tracks (editorGroundFollow, trackbed): the terrain drawn to the tracks and restored, the tracks put onto the terrain. - Connections between tracks (editorConnections, the connection and connection curve tools), the track presets, the shape of a track (editorTrackShape), digitizing tracks from the orthophoto, the properties sheet of the tracks (trackprops) and the track ux. - Unit tests: alignment, ground fit, heights, with the data of two fits. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the switches placed, slid and designed from their templates - The switch templates (editorSwitchStore, the template tool): the catalogue switches and the user's own, kept with the settings; the designer (editorSwitchDesign) with a drawing of the dimensions, a and b typed in with the shape making up the rest, a switch clicked off the orthophoto. - The curve of a switch laid into a curve (editorSwitchCurve), placement on a straight or into a curve, slide along it, crossovers and double slips (switchplace, switchslide), the drives of the switches (switchdrive) and the records of the switches placed (records). - Unit tests: test_switch_curve. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the tools of the infrastructure beside the tracks The gauge, speed, joints, lineside, parallel tracks, vehicles, signals, turntables, sweep and road tools with headers of their own; the kilometrage of the lines (editorKilometrage, the km tool); the infrastructure, roads and speeds behind them (editorInfra, editorRoad, editorSpeed). Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the terrain model of geoportal.gov.pl and the orthophoto downloaded for the editor - editorNmt: the squares of the terrain model at 1 m (NMT GRID1, the WCS service of geoportal.gov.pl) fetched by two workers, kept in editor/cache/nmt/grid1 of the game folder, the heights of the scenery taken from them; the nmt mode loads it along the tracks or around the camera. - editorHttp: the HTTP client of both, WinHTTP on Windows, libcurl elsewhere where it's built with it; without it the caches only. - The orthophoto: its cache moved to the cache folder of the system for the user, the download area a polygon on the topo map (//$a) filled in the background, the 4K imagery, the tiles waiting outlined on the ground. - editorGeoMap: the topo map of the top view; heightmapterrain and the terrain streamer grow the terrain made from the model around the camera. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(launcher): the scenery wizard picks the place of a new scenery on the topo map the editor shares The wizard drops its own map download and decoding for the topo map widget of the editor (editorGeoMap). The place clicked becomes the geographic reference of the new scenery (//$g PUWG1992), and the scenery starts with the orthophoto of the editor on (//$o), lying under it in place. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the tools wired into the editor mode and the build editor_mode takes the tools of the commits before: its header declares them, editormode.cpp and the track mode drive them, and the renderers draw their overlays (opengl33 and legacy). CMakeLists lists the new sources and adds WITH_EDITOR_SELFTESTS (off by default); the unit tests build the new test files. Not built on its own: the tree builds again with the selftests commit, the one before the translation. * feat(editor): the selftests of the editor split by what they test The scripts of EU07_EDITOR_SELFTEST run the commands of editormodeselftest*.cpp: scene, track, rails, join, switch, signal, sleepers, sweep, terrain, monkey. The code is in every build; only with WITH_EDITOR_SELFTESTS=ON does the editor read the variables and run a script. The selftests of master now need the option too. The tree builds again with this commit. * feat(editor): the Polish texts of the editor, all of them in one update of editor_pl.po * fix(editor): the marks of the editor moved off the letters the starters read, and its lines told by their words The starters read some letters in a scenery file: the Starter the title //$n, the attachments //$f and the old scenery //$a, StarterNG and the launcher of the game the attachments //$f and the title //$n. The editor wrote its download area, shared grade lines and fitted tracks under them, and took every line of those marks as its own: saved, a scenery lost its title and attachments, and the starters showed the lines of the editor as them. - The download area is //$z, the shared grade lines //$w, the fitted tracks //$t. - Their lines and those of //$o are told by their first words, as //$h, //$r and //$k were: //$o only as "on 0" or "on 1", the origin or the settings of older builds after it, so a trainset described as "on ..." isn't taken. - The lines older builds wrote under //$a, //$n and //$f are read only by the words the editor wrote in them, or by its own comment line before them, under the new mark. Each save writes them again with it, also when the editor didn't change them; the lines of the starters stay. * fix(editor): a square of the terrain model cut short isn't read, and the squares are kept in the user's cache The service puts the directory of its GeoTIFF before the pixels, so a file cut short by a write or a fetch broken off was read whole, the pixels missing coming out as heights of 0 m, for good. - The reader (editorGeoTiff.hpp, with unit tests) wants all the strips the rows need, each within the file. - A square is written under a name of its own and renamed. - The squares are kept in the user's cache folder (nmt/grid1), as the orthophoto, since the game folder may not be writable; without one, in the game folder as before. The ones older builds kept there are moved over as each is asked for, a damaged one deleted. - Capabilities that didn't come aren't kept as the fallback name for the session: the next square asks again. * chore(editor): the http client said to serve the terrain model and the topo map too, the gif fix of stb_image marked local - CMake names the orthophoto, the terrain model and the topo map as what goes without libcurl. - The fix of the gif frame two back in stb_image is ours, not upstream's (v2.30 still has the old line): a comment at the line says so, for an update of stb_image to keep it. * fix(editor): the lines moved off the letters of the starters in a merged layer written once, not again with each save A merged layer's text goes into the file of its target on save, and the target is read again; the marked lines of the merged layer were dropped only for the marks the editor had changed. The lines moved to the new letters stayed with their old places, and the next save of the session wrote them into the target once more. - After a save, the marked lines of every merged layer are dropped; those of its target are read again from its file. - The lines of a dead layer aren't written again. - The selftest layermerge merges the layer of one file into another's, as the layers panel does. * feat(editor): the station as the signalling sees it, found from a switch of it, and its schematic editorStation: the switches joined by plain track no longer than 1.5 km, the tracks between them and the lines leading out, 400 m of each beyond the outermost switch; laid out as a schematic along the main track through the station. The track circuits, the signals and their lights, the lengths of the station tracks and the lines to the next stations are worked out from it for the signalling tool. Nothing uses it yet: the signalling tool, wired in the next commit, does. It builds on its own. * feat(editor): the signalling of a station in the Signalling tab, laid out from a switch of it as on the lines of PKP PLK LMB on a switch in the Signalling tab opens its station: the schematic in a window of its own, the name, the code, the line and the km of the station, and the steps of its signalling, each one step of undo: - the switches numbered along the station after its code, bpd_1, the parts of a slip bpd_15a..d; the drives and the objects naming a switch follow it, events written by hand keep the old names; - the tracks cut at the joints of the track circuits, Ie-4, and the circuits named, bpd_iz1, bpd_it1; - the entry, exit and shunting signals placed and named, A, F1, Tm1, from the templates chosen; - the signals of the lines out: the automatic block of three or four aspects, the block sections no shorter than the braking distance, or the semi-automatic one with a warning disc; block boundaries drawn by hand; - the lights each signal needs for its routes, Ie-1 and Ie-4 § 8, its template fitted to them; - the SHP track resonators the signals lack, rezonator.inc; - the lengths of the station tracks as a table, and what the station and its lines still lack, with Repair. The stations described are kept as //$s lines in the files of their layers. * fix(editor): the signals of a station and of its lines not placed with no template for a kind, no track cut for them first - Set the signals and Set the line signals cut the tracks first, and only then found no template for a kind. They stopped there, but the cuts stayed as a step of undo. Now they ask for the templates first, by the lookup signal_batch() uses (signal_template_for(), behind editor_signals::signal_templates_missing()). Without one nothing is cut. - Set the signals and Set the track circuits again under Track lengths had the ids of the buttons of the steps above them. ImGui flagged them when hovered. Each now has an id of its own. * fix(utilities): win1250_to_utf8 turns the polish letters into utf-8, not into themselves utilities.cpp starts with a byte order mark, so the compiler reads it as utf-8. The game's targets don't get /utf-8, though: set_target_properties(... COMPILE_OPTIONS ...) in the MSVC block of CMakeLists.txt replaces the options add_compile_options gave them. So the string literals went into the program in the code page of the system, windows-1250 on a polish one, and the map of win1250_to_utf8 turned each letter into itself. What read windows-1250 through it got no utf-8: the names, descriptions and categories of the sceneries and the names of the textures in the launcher, and the descriptions of the templates in the editor. The editor writes such a description back through utf8_to_win1250, which makes a question mark of each byte that doesn't start a utf-8 sequence, so the letters it had read unchanged didn't come back. The utf-8 sequences are written as bytes now, the way utf8_to_win1250 has them, so they don't depend on the options. The options stay as they are: with /utf-8 other literals of the files with a byte order mark would change, the "±" of the table of Bezogonkow would take two bytes and move the letters after it. The unit tests check the letters and that the text given is valid utf-8. (cherry picked from commit9ffed96ec1) * fix(editor): the switches renamed only after the events by their old names are shown, the station records in windows-1250 and in the file the scenery had Number the switches renames the switches and what the editor writes along with them, but not the events written by hand: a switch event aiming at a switch, or <name>:event0 and the others named after it, would keep the old name and lose its switch. Now the first click lists them in the status, up to six and how many more, and renames nothing. A second click with the same renames goes ahead. The name of a station is written in windows-1250, like the rest of the scenery file. A name read that isn't valid utf-8 is taken for windows-1250; the utf-8 the earlier builds wrote is read as it is. utf8_to_win1250 moves from editorIncludeInfo.cpp to the utilities, beside win1250_to_utf8, and the unit tests check both ways. The record of a station that had none goes beside the records of the other stations, in the file marked with them, so a scenery saved under another name keeps them in one file. output_layer takes, after <scenery>_<part>.scm, an included file of the part of another name, the one of the scenery it was copied from, before it makes a new one. The comments: the joints of the track circuits stand 4.2 m beyond the fouling points, where the axes are 3.5 m apart, as joints() counts them; the regulation of the lengths is cited with its date and title. * fix(editor): a scenery saved under another name keeps one file of the keys by the movable noses, not the old one beside its own The editor writes the keys by the movable noses on each save to <scenery>_dzioby.scm and includes it. A copy of a scenery, saved under another name, still included the file of the scenery it came from, and its save wrote a file of its own and included it too, so each key stood twice. Now the save leaves out of the scenery the other files of such keys it includes, told by the line the editor writes at their start. Their files stay on the disk, for the scenery they were made for. A file made by hand, without that line, stays included. The turntable controls had the same, fixed the same way on their own. * fix(editor): a file of the scenery named like a part of a tool isn't taken for the one the tool made output_layer took, after <scenery>_<part>.scm, any included file named *_<part>.scm, so that a scenery saved under another name goes on with the file of the scenery it was copied from. A file of the scenery named alike, written by hand, such as rejon_teren.scm, got the terrain directive, the hectometre posts or the new signals too. The files output_layer makes start with a line of their own now, "// scenery layer created in the editor for its <part> part", and a file of another name is taken only with that line. A layer gets it through the new parameter of scene::node_layers::create(); the others start with the general line as before. <scenery>_<part>.scm of the scenery itself is taken without the line, as it was. A file made for a part by an earlier build has only the general line, so a copy saved from it gets a file of its own. * feat(editor): a player of GIF clips for the windows of the editor editor_clips::clip plays a GIF in an ImGui window, looped, from the time given. stb_image decodes the whole file on a thread of its own, so the window isn't held up; until then the clip says it's loading. The frames are kept as stb_image decoded them, and the one shown is a texture of the ImGui renderer (Create_Image), made again only when the frame changes. A file that isn't there is told missing at once, with no thread started. Nothing uses it yet; the tutorial of the next commit shows its clips with it. * feat(editor): Help > Tutorial, fifteen short lessons of the editor The lessons: looking around, laying track, curves, the radius of the curves at the bends, correcting a curve, joining tracks, switches, switch templates, signals and posts, selecting and fixing, editing with the gizmo, the grade line, terrain from the terrain model, sceneries made before, saving and driving. Each lesson has: - in eight lessons, a looping clip from lang/editor_tutorial/<lesson>.gif, played from the start on a click; in six others, a moving drawing (the radius at a bend, a switch template clicked, the signals, the grade line, the terrain, a trainset); - the mouse buttons and keys drawn as pictures beside what they do; - ticks that fill in as the user does it, told by the tools through editor_guide::first_step_done(); - a button that turns the tool of the lesson on; - Back / Next and a dot per lesson, green when the lesson is done. The window follows the work: when the tool in use changes, it turns to the first lesson of that tool not done yet, and a page turned by hand stays until then. In a lesson of laying it warns when there's no ground under the cursor. Where it opens: - by itself when an editor session starts, until "Show when the editor opens" is unticked (first_steps in the editor's settings); - from the Help menu; - from a Tutorial button beside Lay a track in the hint of an empty scenery, which isn't drawn while the tutorial is open; - at its lesson, from a "?" by the radius at the bends in the lay panel. A lesson whose clip isn't there is shown without it; the clips aren't in this commit. editor_guide is a new role of the editor, given to the hekto-post and trainset tools. Selftest command tutorial <page>: opens the tutorial at a lesson, from 0; -1 closes it. * fix(editor): the lessons of the tutorial say what the editor does The lesson texts checked one by one against the tools; the ones that told otherwise: - Switches: a connection isn't chosen at the top of the panel, its kind comes from where the drag is let go (a crossover onto the other track, over a crossover the other way a double one, or scissors where they overlap). - Switches: a ladder leads onto the parallel tracks it's dragged across, let go on the farthest, with the straights up to where they start; it lays no missing tracks. - Terrain: there is no step 3. Step 1 is Location, step 2 is Load around the camera while there are no tracks and Tracks and terrain with its three ways once there are. The rows had the step numbers in the keys column, and 1, 2 and 3 switch the edit modes in the Terrain field. Now the steps show the mouse, the terrain under some tracks only is a row of F3 (the line the terrain panel shows), and the rows that only tell what the fit does have no key. - Sceneries made before: a plain include can be changed; the row lists what can't: an include template (.inc), the binary terrain cache, a file included twice or with parameters, a locked or hidden layer. - Laying: the second Esc drops the points only within 3 s. - The radius at the bends: two transition curves from 6000 m down to 2000 m while they're long enough for the speed, then an arc; a label turns orange where the curve breaks the norms, not because it came out smaller; two transitions meeting read 2xL and R; the labels of each transition curve are on laid tracks, close up. - Signals and posts: the W17 markers go by the selected switch, around the camera or the whole scenery, not along a line. - Selecting and fixing: E lengthens the track, the control vectors bend it. - The gizmo: at a point Q moves the point alone, W turns the whole track about it. The tooltip of Help > Tutorial no longer speaks of clips: the tutorial goes without them. lang/editor_pl.po has the new texts. * fix(editor): the lessons of the tutorial in plain words Every row, goal and warning of the tutorial is said again for someone who has never laid a track, in English and in Polish: - the words of the railway and of the editor are said in everyday ones, or explained where they come: the radius (how big the curve is), the transition curve (the easing into it), the cant (the outer rail raised), the gizmo (handles on the track), the control vectors (points that bend it), the grade line (how the line goes up and down), the terrain model (the real ground), the orthophoto (the aerial photo), the hectometre posts (every 100 m), W17 (how far a wagon may stand); - what only a designer needs is left out: the 6000 and 2000 m of the radius ladder, the compound curve, the hump, the kinds of include that can't be changed; - the buttons are named as the panels name them: Apply to the scenery, Template editor..., the tiles of the switch tool; - the Polish names of three lessons say what they are about ("Uchwyty na torze (gizmo)", "Wzniesienia i spadki", "Prawdziwy teren"). Their English titles stay, the lessons are found by them; - the warning of no ground under the cursor tells what happens to the track; - two captions of the drawings say what they show (the tracks inside a box, posts every 100 m), and in Polish the button of the top view is "Widok z góry (O)", without "ortogonalny". What each row tells of is the same as before. The msgid of the length typed while laying stays, the window of the keys (F1) uses it. * feat(editor): the semaphores and the warning discs chosen by what their descriptions say they show The descriptions of the signal templates can now say what a semaphore shows and what a disc repeats, and the editor reads it: - signal: {arms: 2, aspects: {Sr1: ..., Sr2: ..., Sr3: ..., Sz: ...}, repeats: {stop: ..., vmax: ..., "40": ...}} is kept with the template, the events named for each aspect - the palette shows a template with arms as a semaphore of its arms, with 1 arm / 2 arms and Sz picking the template of the same tile that has them - the signals of SRK take a semaphore whose aspects cover what the signal needs (Sr3 where a speed is reduced, Sz on the main signals), the fewest arms that do it, and say which one does when the placed one hasn't them or has more than it needs - the warning disc before a semaphore is one whose repeats cover stop, the highest speed and 40 km/h when the semaphore shows Sr3; SRK writes no events of the routes, so this only chooses and checks the disc - the linked signal (parameter 7) is read for the role link as well as text - signal_headers.py keeps the keys written by hand in a description (arms, aspects, repeats, the description and the parameters from 6 on) when it writes the guessed ones again - signaltemplates of the self test lists what the templates say and the heads made of them * feat(editor): the shaped discs swapped and set by hand, the warning discs checked by what they repeat The shaped shunting and stop discs (mk1, tzm, z1) are known to the signalling, but it doesn't place them by itself: - a shaped disc chosen in the palette for the shunting or the stop signals is placed by hand only; the signalling of a station takes the light template of the kind there, and says so when there is none - the template of a shunting or a stop signal standing can be swapped for a light or a shaped one of another mount as well (dwarf and mast, not gantry) - a signal whose description lists its aspects shows a button for each under its card: it sets the signal to that aspect in the editor, by the animations, the lights and the submodels its event sets off, the time standing still; nothing of it is saved. TAnimContainer::Finish takes an animation to its end at once, giving the submodel its angles, multi_event::branches tells the events set off when the condition isn't met From the review of the descriptions: - a shaped warning disc standing before a semaphore described is checked by the events it repeats: stop, the highest speed and 40 km/h of a second arm told apart; one which doesn't is offered the disc which does, and Fit swaps it - the disc offered is of the mount of the disc chosen, taken from the template even when it isn't described - 1 arm / 2 arms / Sz of the palette pick the template leaning as the chosen one and most like it by its name - a semaphore described with its arms but not its aspects has Sr1, Sr2 and with a second arm Sr3 - Fit leaves a semaphore having what it needs with its arms, for the events written by hand to the aspects of a second one; the messages of the fitting speak of what the signals need, not of their lights - signal_headers.py warns of a signal map written as a block, whose keys it can't keep * fix(editor): an aspect shown by hand doesn't name a vehicle that may be gone The Show button runs the events of the aspect outside the queue. run() writes the vehicle that set the event off last into the log, and nothing clears that pointer, so a train deleted since would have been read after it was freed. The queue sets the activator anew each time, so it is cleared before the run. * fix(editor): a disc not described is only offered the one that tells, a light stand-in of the mount of the shaped one - A shaped warning disc whose template doesn't say what it repeats may tell all its semaphore shows as well. It is no longer marked as not fitting: the disc described is offered as a hint, and Fit leaves it be. A disc whose template isn't among the scanned, its mount not known, is offered nothing rather than discs of any mount. - A shaped disc chosen for shunting or stop is stood in for by a light template of its own mount first, a dwarf for a dwarf. - The tooltip of the aspect buttons says the trains read the signal as its events set it last, in a run started from the editor too. - The Polish texts of the fitting speak of signals, not semaphores, since it takes the discs too. * refactor: the Sonar remarks on the switch blades taken care of - the big functions of the rails split into helpers with one job each: the carving, the laying and the planning of the rails, their crossings, the blades, the lofted spans of a segment, the profile of a rail measured piece by piece, the joining of the switches - the floating-point loop counters are while loops doing the same additions, so the samples come out where they did - C arrays are std::array, the two sides of the paths path_sides; the ends of a cut are two parts of one struct, ending and starting - the rail laid by a course of its own, not eleven parameters - the globals kept in functions, the nested ternaries taken apart, one declaration per statement, explicit captures, ranges algorithms, std::format, std::numbers, emplace_back, structured bindings - the region finds the sections around a point into a list the caller gives, so the search for the rails around a track shares no list with another thread - check_rails and create_track_rail_profile are const, the pool of the reused chunks can't be copied The geometry of every chunk of lk357 and td_fog, with the frogs on and off, comes out the same as before. * refactor: the Sonar remarks on the 3D sleepers taken care of - the big functions of the sleepers split into helpers with one job each: the clusters and the lines of timbers, the gaps under the rails, the models and their parts, the check of the layout, the drawing of the timbers in instanced batches - the tracks near a track found into a list of their own, the region searched into a list the caller keeps, not the one the region shares with the main thread; the callbacks are templates, not std::function - the layout of a cluster takes a span of its tracks - the globals kept in functions, the parts of a beam int constants, beam_overhang no longer hidden by a field of the same name - scoped_lock, jthread, contains, ranges algorithms, std::format, emplace_back, structured bindings, explicit captures, upper-case literal suffixes, one declaration per statement - the uniform buffer takes a span of bytes * fix(editor): the editor core builds with GCC again - kCrossoverStraights is constexpr, so the connection curve can take it into a constant expression; GCC refused a double that was only const there. - the track_hover alias inside editor_mode dropped: declared after hovered_track had already used the name, it changed what the name meant in the class (-Wchanges-meaning); the definitions name the shared track_hover. - <cstring> included where the rail self-test uses std::memcpy, which MSVC reached through other headers. * refactor: the second round of Sonar remarks on the switch blades - the carve of a throwable part takes the cut before it only where there is one, as only that cut makes it throwable - the splitting of a grooved profile by the floor of its groove moved out of the rail layer into a class of its own, which is given the profile, the size of the rail, the texture of the plates and the side - the rail drawing is made by a const function - the triangles of an ear-clipped outline go in as the arrays they are, the search for a corner within an ear is an any_of, the loop pruning thin corners keeps the count it started with, as it stops at the first - the bytes of the blocks of a texture are taken off the file through its buffer, with no cast of their storage - the log of a carved part takes the tracks around it as a span - the joint length of a switch, a constant, isn't captured, and the directions at the ends of a crossroads are tested in one condition each * refactor: the Sonar remarks on the tutorial - the window of the tutorial in smaller pieces: the steps reached, the lesson followed and its clip, the clip or the sketch of a lesson, its keys and steps, the button under it and the buttons of the pages; the lessons are a table of their own, the button of each kind of lesson picked from a switch - a clip whose delays add up to nothing shows no frame instead of dividing by them - the frames of a clip are decoded by a function of their own, on a thread kept with them and joined once it's done, or as the editor closes, instead of a detached one - the sleepers of the signal sketch counted by a whole number, the texts of the sketches made by std::format, their points kept in std::array, the whole numbers turned into floats where it's meant * fix: the bugs and vulnerabilities Sonar found in the editor core - the loops stepping along a track, a curve or the view count their steps by a whole number and take the station as so many steps from the first, instead of adding a fraction up, which drifts - the self-test of the guard rails keeps the plan of the rails of the track against while it goes through them: the range of the loop was in a plan made for it and gone before the loop began - the generators of the self-tests and of a unit test are seeded on purpose, so a run can be repeated: marked for Sonar as such - the tool writing the descriptions of the templates takes the names out of its tables only where they stay in the data folder * fix: the loops of the signalling stepping by a whole number the places of the block signals along a line and the marks of the chainage under the plan of a station are counted by a whole number and taken as so many steps from the first, instead of adding a fraction up, which drifts; Sonar took the counters of floats for bugs * refactor: the checks of the signal heads and the signal sheet in smaller pieces the remarks Sonar made on the signal descriptions: the warning about a disc on the mount of a signal is worked out by a function of its own, the fit and the aspects of a head, the swap of a template and its aspects in the sheet of a signal are drawn by members of their own, the walk over the events of a signal is a free function instead of a std::function held by a lambda, and the description of an include is read a part at a time; the names of the kinds are kept in a std::array and looked up by the algorithms of ranges, a name is taken as a std::string_view where it is only compared, and the locals named event, which hid the enumerator, are renamed * style: a space after a comma in the join self-test * style: a space after the question mark in the terrain sketch * style: a space after the question mark in the status of the fitting * refactor: the last Sonar remarks on the small fixes the opening of a scenario catches the exception the scenery throws when it can't be read, not any runtime error; the vehicle moved between trainsets keeps its source by a reference to const; the messages of a track of an unknown type and of a tributary are raw string literals; the parser opens a file by a std::filesystem::path, and the log of a file it can't open still names its folder and its name * refactor: the crossings of a track found without casting its const away the radius of a node can be read off a const one: radius_() is const across the nodes, the ones of the tracks and the models marked override, and a const radius() gives the radius worked out already, or works it out anew without keeping it; the helpers finding the crossings of a track only read it and take it const, its own run of rails typed apart from the ones of the tracks it crosses, which the crossings found name; the triangles of a filled outline are pushed as named corners * refactor: the paths around a track sampled without casting its const away the sampling of the paths and the clusters of tracks laid together only read the tracks, so they take and keep them const: the path sampled points at a const track, the tracks near one are found from a const one by its const radius, and a cluster holds const tracks; the shared zones of the timbers no longer cast the const of their track away * fix(editor): the Sonar blocker remarks on the stack, no side effects in the operands of && and ||, no local named final (S912, S1669) Counting the leftover signals, the pieces of a station walk, the places with nothing beside a run and the joints and fouling points logged by the self-tests no longer counts inside a condition; the last span of a straight is named tail. The counts and what they log are the same. * revert(vehicle): an axle on a switch follows the switch as it is set, as before the stack The axle kept to the path it came on, so a switch thrown under a moving train no longer sent the rest of it onto the other branch, and coming from the frog end it trailed shaped blades only where the wheels reached them. That changed the running of every switch in every scenery, and the AI still scans its route by the switch as set. TrkFoll is as on master again, and the trailing point of the blades it used is gone. * revert(track): a path is told a straight by its first control vector alone again, as the sceneries are made for A plain track was drawn bent where its second control vector was off the chord though the first lay along it, and a path with a radius given was never straightened. Tracks of existing sceneries drawn straight before would have been drawn bent, with their length, cant and the models along them. TTrack::straightened is the rule of master, for plain tracks and the paths of switches. The editor keeps a bend dragged with the second control vector, or set by joining the tangents, by moving the first one 2.5 cm off the chord to the side of the bend, past the tolerance, so the track is drawn, saved and read back bent, by older builds too; the second one dragged back along the chord takes the first one back onto it. * feat(track): the switches joined directly to other switches at load told in the log A switch right after another one is joined to it as the sceneries load, where its end was left open before and vehicles came off the track there. Each switch joined so is logged with its place and the number of ends, and the whole number once, so a scenery can be checked for places that run differently now. * fix(editor): a bend kept by lengthening the first control vector, not turning it keep_bent moved the first control vector 2.5 cm sideways, which turned the start tangent: a kink of 0.29 deg on a 15 m track, flagged by the joints check, and against the fixed direction at a switch or a locked track. Now the vector keeps its direction and gets 2.5 cm longer than a third of the chord, which the simulator no longer takes for a straight. It is also applied after an end is moved or snapped, since a new chord or a snap onto a neighbour could bring the vector back within the tolerance. With the second vector back on the chord, the first goes back to a third of it. * fix(track): each switch joined directly to another one logged with both names join_switches counted ends, while one join links both switches, and only the first switch of a pair was named. It now returns the switches joined to, and the log names both of each joint and gives the number of joints. * fix(editor): a path drawn bent is kept bent through every edit, one drawn straight is left as it is The first control vector is made longer past the 2 cm tolerance only where the path was drawn bent before the edit, or where the edit itself sets the second vector: the end of the path moved, its first vector, its second one, a neighbour followed or its grade taken, the controls aligned at a joint, an end snapped. A path drawn straight keeps being straight when its ends move, and the paths of a track that the edit doesn't bend aren't changed. Moving the second vector back along the chord takes the first one back to a third of the chord where it was made longer here. * fix(app): a scenery that can't be opened takes the game back to the launcher whatever the file system throws Catches std::runtime_error again, as master did: invalid_scenery_exception is one of them, and so is what the file system throws while the scenery is opened. * fix(track): the beams worked out in the background don't read the ends a switch is set to The ballast a switch trackbed takes is asked of the tracks joined to its main path, as the trackbed is made at the load, not of the ends the switch is set to now, which change as it's thrown while the thread runs. What the thread reads with no lock against the main thread is written down where it runs, with the two things driving can change: a switch thrown and a turntable turned. * perf(render): the cut faces of a track drawn with nothing put on the heap, a track with none passed over at once * chore(track): the switch drawing the cut faces in the unrolled material read only in the builds with the self-tests * docs(track): the blades flag said to be switched on, and what frogs in eu07.ini changes of it * fix(editor): a response over 64 MB is refused, curl kept to http and https, the address read as UTF-8 The body of a map or of a service the user typed is read into memory up to 64 MB and fails above that, with WinHTTP and with curl. curl follows at most 10 redirects and only to http or https. WinHTTP gets the address widened from UTF-8, so a pasted one with letters past ASCII isn't turned into garbage. * fix(editor): only the orthophoto an older editor kept is deleted from the settings folder, not all its cache The geoportal folder of the old cache is removed, and the cache folder itself only where nothing else is left in it. * fix(editor): the square metre of the outlined area written as its UTF-8 bytes, shown right where /utf-8 doesn't reach * docs(track): why the velocity read for a switch is put back after its segments are made * fix(track): the blade tips and the open ends of a track take the dark of the rail, not the colour of a worn tread No wheel runs over them, so their cut faces aren't drawn as worn: the beige the matte material gives a worn face is left to the cut faces of the frogs. * fix(editor): a neighbour followed or given its grade is bent only where its second vector really changed follow() and follow_grade() write the second vector of a track joined at its end back as it was when the joint didn't turn or keep its grade; a track the simulator draws straight with that vector off the chord was made bent then, though the edit never touched it. Its first vector is lengthened now only where the path was drawn bent or the second vector took another direction or grade. * fix(track): the open ends of a track laid with cuts take the dark of the rail too The rails a frog or a crossing cuts are laid piece by piece; the caps of their pieces at the open ends of the track were drawn worn with the cuts of the frogs. They aren't worn now, as the open ends of the other tracks. * fix(editor): a neighbour drawn straight is bent only where the edit took its second vector off the chord follow_grade() sets the height of the second vector anew on every graded joint, a fraction of a millimetre off the height the scenery has, so a change of the vector bent a track whose second vector stood off the chord sideways already, though the simulator draws it straight. follow() and follow_grade() keep a path drawn straight bent now only where its second vector lay along the chord before the edit and stands off it after; a path drawn bent is kept bent as before. How far the vector stands off the chord is measured in one place, keep_bent() uses it too. * docs(editor): the comment of keep_bent above keep_bent again, not above the measure of the chord * Editor: signal reads kept by the signal, level crossing discs, signals out of the gauge, indicators, the signalling tools split (#307) * fix(editor): the read of a signal stays by it as its track is split, on a switch and when it is moved, and a level crossing disc is placed The trains find a signal by its read, a passive event in a list of the track, and measure the way to the cell it reads along three tracks further at most. The editor let the read drift away from the signal, or put it where trains of another path read it. - A track split in two: a read the trains scan for (a passive event) goes to the piece by the point it reads, whatever its list; before, those of the runs towards the end stayed on the first piece. Five splits left the reads of A, B, C and J on the first piece while the signals stood on the sixth, out of the reach of the trains. The reads of signals placed since the scenery was opened, not bound to an event yet, go to the piece by their signal the same way. - A signal moved off its track jumped back to that track's end once the track was changed: the track had taken it up as its object and measured it again along itself. A moved signal is let go by the track it stood by, and an object of a single point moved off the side of its track no longer follows it. - A switch reads its events to the trains of both its paths. A signal past the frog of a path, where the axes are a gauge apart, is passed by the trains of that path only, so its read goes to the track joined to the far end of the path, in the list of the trains running from the switch onto it or the other way. Before the frog it stays on the switch. Moving the signal across the frog takes the read between the two. - A signal by a switch on the side of its other path stood on that path, in the way of its trains (0.45 m from its axis); it is refused there, placed or moved, with the reason. - The kind crossing of the descriptions (tsosp, tsospn) is known: the level crossing disc is listed in the palette and placed with its read. Checked in the editor on a hidden desktop: five splits of a track with bound and fresh reads, a signal moved to another track and the old one raised, signals placed before and past the frog of a switch on both paths, turned and moved across the frog, saved and opened again with the reads bound, the tracks raised, shifted and bent with the signals following. Unit tests pass. * fix(editor): a split keeps reads far off the path and bound objects up to 30 m by their pieces A read the trains scan for moves to the piece by the point it reads only from event1 and event2, only when it isn't ignored and only when that point is within 50 m of one of the pieces; a read at the station building stays in its list. An object bound by hand keeps its binding as its path moves up to 30 m from it, an adopted one up to 12 m as before. * feat(editor): the tracks that read a signal are drawn and can be picked, flipped or dropped The selected signal shows each read of its _sem_info as a thick band over the reading track, arrows in the way the read is scanned, a line from the foot of the signal and a plate with the list and the track; the hovered one shows them thinner and placing or moving a signal shows where it will be read. The panel lists the reads: each can be turned the other way or removed, "Pick the path" takes a click on a track (with Shift one read more or less) and "By the path it stands by" puts back the read the signal gets when it is placed. Each change is one step of the undo. The self-test gets signalread, signalreadflip, signalreaddrop and signalreaddefault, and the probe lists every read of a signal. * fix(editor): a moved or turned signal keeps the reads picked by hand, and a read set again isn't an undo step Moving a signal, taking it across the track or turning it put back only the read by the track it stands by and dropped the others: those stay on their tracks now, on the other list when the signal is turned. Setting the reads the signal has already says so and adds no step to the undo. Picking a reading track disarms the template, so a click after Esc doesn't place a signal, and the signals are listed again after any change of the history, also once it is full. * feat(editor): a signal is placed out of the gauge of the tracks around it As a signal is placed, moved, taken across or turned, its models are measured against the gauge chosen in the Gauge window along every path near it. One that enters it is taken sideways, away from the axis of the track whose gauge it enters, as deep as it went in and 3 cm more, in the same step of the undo; between two tracks too close for it, it stays where it was put and the status tells which gauge it enters and how deep. A gantry is only measured. The panel of the selected signal tells when it stands in the gauge, with a button to move it out, and the view marks the deepest place. The gauge tool measures any models against the paths around them for it. The self-test places a signal at a given offset and its probe tells the gauge. * fix(editor): a moved signal leaves only the read of the track it stood by, and the gauge is checked on its level The reads a moved signal keeps were all but the first one listed, which is the first track of the scenery having it, not the one the signal stood by: a read picked by hand could go and the track it left could keep it. It is the read of the track it stood by that goes with it now, and turned, eventall1 and eventall2 swap as well. A track more than 2 m above or below the foot doesn't push the signal aside, the status tells the real distance it went, the gauge is measured again when the signal follows a dragged track, and the marker in the view shows only what is up to date. * feat(editor): indicators put on a signal from the panel, they move and go with it The indicators of scenery/pkp/wskazniki described as "category: indicator" are offered under the selected signal, grouped by their sign. One is put in as an include named after the signal, on the srk layer: - a lit one (place: head) under the lowest lamp of the signal, 0.73 m below it and 5 cm ahead of the mast, each next one 0.45 m lower; a dwarf signal is refused, it has no mast for one; - a plate (place: foot) at the foot of the signal, its model has its place by the mast built in. The panel lists the indicators standing by the signal with a Remove button. They are found as the includes whose first parameter is the signal's name, within 1 m of it in plan. When the signal is flipped, turned or moved, they keep their place in its frame, in the same undo step; deleting the signal deletes them too. If the signal and the indicator both define an event, the status says so, since the scenery keeps only one of them. The self-test gets signalindicator and signalindicatordrop, and its signalprobe gives each indicator's height and the height of the lowest lamp. * feat(tools): indicator descriptions and the indicators taken out of the signal templates indicator_headers.py writes //$e descriptions into the LED indicators of scenery/pkp/wskazniki (W19, W20, W21, W24, W26) with the events each shows. It also makes the indicators that were so far only built into the signal templates: - W1 of the warning discs, new, old and with the light strip; - W1 and W18 (new and old) of the block signals; - the I, II and III plates of the repeaters. The plates fixed flat to the mast are moved 4 cm ahead. Their back is 5 cm from the mast's axis, while the mast is 6.1 cm thick and its clamp under them 8.3 cm, so the mast went through the plate, in the templates too. * fix(editor): a signal turned or moved by the gizmo is read and kept out of the gauge, its indicators go with it everywhere The gizmo of an include only rewrote the numbers of a signal. Its read stayed on the event it had, even when the signal was turned to the trains of the other direction. Its indicators stayed behind, its height could be dragged off the ground, and the gauge wasn't checked. Now: - the gizmo moves a signal in the plan only, at the height it has; - while it is dragged, its indicators keep their place by it; - once it is let go, the drag is made again as a move of the signal tool, one step of the history: the read goes to the event of the trains it faces on the path it stands by, and it is taken out of the gauge; - dropped away from every track, it goes back where it stood. The indicators of a signal are found in the scenery now, not in the list the signal tool keeps up only while it is open: - deleted from another tab, the signal takes them with it; - a signal renamed in the node properties gives its new name to them in the same step of the history; - in the station and line batches, a renamed signal renames them, and a removed one removes them; - the binding of objects to tracks puts them on the path reading their signal, not on the one nearest to them, and a signal moved by hand lets go of them too. Also: - a signal on a gantry takes no indicator from the list; - an indicator a signal has already isn't put on it twice; - the signals and their indicators are found in one pass over the includes, the indicators by the name of their signal; - a step of the history with tracks is always one of their edit, so they are taken back with the includes. The self-test gets signalgizmo, which turns and moves a signal as the gizmo does. * fix(tools): indicator_headers.py keeps the files it replaces, writes beside the data on request - An indicator it made, found changed, is put into a tar in editor_backup before it's written again. - --sidecar writes the descriptions of the lit indicators into editor/templates, as the other header scripts do, the files of the game left alone. - The indicators it makes are copies: the signal templates keep their own, and the docstring and the files say so. * fix(editor): a signal moved by the gizmo by another track is read by it, the templates known without the signal tool - At the end of a gizmo move the nearest track takes the signal when it is nearer than its own by more than 0.5 m; a track it was dropped onto, within 1.2 m of its axis, doesn't, so a signal only turned between two tracks or dropped onto one in a switch keeps its own. - The signal templates and indicators are looked for when a signal is renamed or its gizmo shown, so its indicators follow without the signal tool opened first. - A drop refused puts the gizmo and the node properties back where the signal stands. - The indicators follow only once the gizmo made its step, and the ones not changed are left alone: grabbed and let go it changes nothing. * fix(editor): a signal dropped by the gizmo onto a track keeps its own, the gizmo doesn't wait for the template scan - When the nearest path to the drop is within 1.2 m of its axis, the signal keeps its own track, instead of only that path being left out: dropped onto a middle track it no longer goes to the track beyond it. - The gizmo starts the signal template scan without waiting for it, so a rescan with a signal selected doesn't stop the editor; renaming a signal still waits. * feat(editor): the signalling split into Signals, Station, Station signals and Line block The one Signalling tool held the signals placed by hand, the whole wizard of a station and its checks; each is now a tool of its own in the toolbar: - Signals (I): the palette, a signal placed by a track, dragged along it, selected; a click on a switch no longer opens a station. - Station: LMB on a switch lays the station out; its name, code, line, km, speed and braking distance, the numbers of the switches, the track circuits, the number of the selected track, the list of the switches. - Station signals: the signals of the whole station placed at once, the template of each of their kinds (main, shunt) chosen in a table, and below what the signalling lacks: the repairs, the SHP resonators, the track lengths, the signal heads. - Line block: the block of each line, the block boundaries drawn by hand, the line signals, the templates of the block signals and warning discs. The station tools share the open station and its schematic; Station signals and Line block show what the Station tool set for it, the line and the km in red where the line block needs them. The template table replaces the palette in the station tools, so choosing a template there no longer arms placing. Two icons drawn for the new tools, in editor_icons.py too; the png is drawn by the same shapes, Pillow wasn't at hand. The tracktab self-test takes a tool by its name, and srkopen shows the Station tool. * feat(editor): a signal shows its distance from the track axis and to the switch ahead, and goes to 50, 100 m... from it - editor/editorTrackTrace: the track followed the way a train runs, shared by the W17 markers and the signals. The fouling point of a switch (where the axes of its tracks are 3.5 m apart) moved here… * fix: a failed start says why and ends with an error code; a small crash dump by default (#425) * fix: a failed start says why in the log and ends with an error code When the window could not be made, the log only said "Bad init: failed to create glfw window", without the reason glfw knows (no OpenGL driver, no pixel format that fits, no EGL). Sometimes it did not even say that: the log thread writes every 50 ms, and main() ended the process with std::_Exit(0) without stopping it, so a start that failed within that time left a log that ends at "// startup". - glfw's errors go to the log and errors.txt through glfwSetErrorCallback, set before glfwInit(); each distinct message once. - after a failed start (or an exception caught in main) the log thread is stopped and waited for, as the test runs already do, so nothing logged last is lost. - a failed start ends with exit code 1 instead of 0, so the starter can tell it from a closing. A start that worked ends as before. * fix: glfw's errors told during the start only, a closed crash dialog is no failed start After review of the previous commit: - the glfw error callback is taken off at the end of init(). Once the simulator runs, glfw would only repeat what the platform can't do (glfwSetCursorPos on Wayland, on every mouse-look) or what a scenery asks for in vain (launcher key codes below GLFW_KEY_SPACE, checked on every update), which would put new lines in errors.txt of existing sceneries and cost a format and a lock per call. - closing the crash-report window ends the simulator as before, but init() now returns 1 for it (above 0: closed by the player), and only a result below 0 gives exit code 1. - a start that throws from init() (bad_alloc, or a runtime_error on Windows) ends with exit code 1 too; an exception after a start that worked ends with 0 as before. * feat: a small crash dump by default, the full one with "crashdump.full yes" The dump written by the crash handler (Windows, WITHDUMPGEN) held all the memory of the simulator (MiniDumpWithFullMemory), so it was as large as the memory the simulator took: gigabytes on a large scenery, written to the game folder at the moment of the crash, on machines with 8 GB of RAM too. By default it now holds the stacks with the memory they point to, the threads, the modules, the handles, the memory map and the modules' data segments (MiniDumpWithDataSegs in place of MiniDumpWithFullMemory, the rest of the flags as before). The globals, Global among them, stay readable. "crashdump.full yes" in eu07.ini writes the full dump as before. Measured on td.scn with a ghostview camera (1.2 GB committed): the small dump 44 MB in 2 s, the full one 1.6 GB in 19 s. The key is new and optional: eu07.ini files without it read as before, and the setting is listed in the log at start. * fix: the small crash dump keeps the process and thread blocks MiniDumpWithProcessThreadData adds the PEB and the TEBs, a few KB: the command line (the scenery and the vehicle), the environment and the last error of each thread, which the small dump otherwise lacks, since the heap behind Global's longer strings is not in it. * fix: an exception that ends the simulator says what it was in the log After review of #425: - the exceptions main() catches are logged ("Critical error: ..."): on Windows the runtime_error that only showed a message box, and on the other systems any std::exception, which used to end the simulator through std::terminate with no word in the log. On Windows the others are still left to CrashHandler, whose dump shows where they were thrown. - every exception caught there ends with exit code 1, in the start or later, as a crash; it used to be 0 when caught, the abort code when not. - closing the crash-report window logs "Crash report window closed, closing" instead of the error "Failed to run crash gui!", which stays for a result below 0. * feat: the stack of a crash on Linux in the log and on the standard error On Linux no dump is written (the crash handler is Windows only, crashpad is off), so a crash left a log that just stopped. A handler of SIGSEGV, SIGBUS, SIGFPE, SIGILL and SIGABRT (installed at the start of main) now writes, with write() only: Crash: signal 11 (SIGSEGV) at address 0x... Version: EU07 (cmake), <hash> (...) Stack (addr2line -f -C -e <the eu07 file of this version> <offset>): <backtrace_symbols_fd> to the end of the log file (its whole path, set when the log opens it) and to the standard error, which StarterNG shows first. The Linux builds carry their symbols (GENERATE_PDB adds -g, nothing strips them), so addr2line on the eu07 file of the same version gives the files and lines. Then the signal ends the process as before (SA_RESETHAND, raise): the same exit status, and a core dump where the system makes one. The handler runs on an alternate stack, so an overflow of the main thread's stack is reported too; backtrace() is warmed up at install so it doesn't allocate in the handler, and alarm(5) ends a handler that hangs (a crash in the allocator or the loader). WAMR is built without its hardware bound checks, so it installs no SIGSEGV handler of its own. Elsewhere crash_signals does nothing. A unit test (Linux only) crashes a child process and checks the report on its standard error and in the log, and that the child still ended by SIGSEGV. * fix: the crash report can't be cut by a second crash signal or end with SIGALRM After review: - the five crash signals are blocked while a report is written, so a second one waits rather than starting a second report in its middle (a fault that comes while blocked still ends the process). - a report that hangs past alarm(5) ends the process by the signal of the crash, not by SIGALRM: a SIGALRM handler, set only in the crash handler, raises the crash signal and unblocks it. - the child of the unit test calls alarm(10) first, so a child stuck before the crash can't hang the build. --------- Co-authored-by: maj00r <maj00r@host> * feat(track): unevenness waves shaped by the track spectra of FRA and ORE B176 (#426) * feat(track): unevenness waves shaped by the track spectra of FRA and ORE B176 The waves were 5-42 m sideways and 8-83 m vertically, with the long ones cut down, so a short wavelength carried a large share and the ride and the rails looked busy. They are now 7-90 m sideways and 8-110 m vertically, about the bands D1-D3 of EN 13848, each wave standing for a band of the spectrum S ~ Wc^2 / (W^2 (W^2 + Wc^2)), Wc = 0.8245 rad/m, the shape the FRA and the ORE B176 (German) spectra share: the longer a wave, the higher it is. The "uneven" value keeps its meaning, the peak deviation of a rail on a 10 m chord as PLK Id-14 measures it, so the values in sceneries stay as they are. Since the chord sees the long waves less, the amplitudes are calibrated again, and apart for the vertical and the sideways waves: stray_per_mm becomes stray_up_per_mm 0.00229 and stray_side_per_mm 0.0031, and cross_share 0.35. A track at "uneven 18" measures 18 mm vertically, 17 sideways, 15 of twist, +-10 of gauge, 21 of cross level and J 5.7 against the Id-14 limits for 80 km/h. A rail now goes up to about 5 cm off its design over the long waves, so the bound of the test goes from 40 to 60 mm; the short waves the cab shakes on are smaller, the sideways bend under the axles about 30% less. Every scenery with unevenness looks and rides differently after this. No release has unevenness yet. The grading tool follows the vertical waves; on Baltyk the pantograph keeps within 0.6 cm of the wire up to the product 1150 of the vertical value and the speed (925 before). * test(track): bound the sideways offset of an uneven track off its design The longer waves move the track about 4.5 cm sideways off its design at "uneven 18" (2 cm before), and nothing checked or stated it. The Id-14 test now bounds the peak sideways offset of the middle of the track below 5 cm, next to the vertical one, so a later change of the shares can't double it unnoticed. The doc gives the figure, and names platform edges and level crossing panels among what a rail moves away from. --------- Co-authored-by: maj00r <maj00r@host> * feat(editor): ~ shows or hides the orthophoto, Ctrl+~ downloads what the camera sees first; the speed of the camera in the View menu (#312) * feat(editor): ~ shows or hides the orthophoto, Ctrl+~ downloads what the camera sees first; the speed of the camera in the View menu ~ (the key left of 1) turns the orthophoto on and off. Ctrl+~ finds what of the ground the camera sees (rays through a grid over the screen down to the level of the ground under the camera, or as far as 2.5 km where they don't come down to it) and puts those tiles at the front of the queue of the downloads, the ones which failed tried again at once; the status line tells how many. Tab is not used, the laying and the switches have it. View > Camera speed: the speed of the free camera of the editor (x0.05 to x10, 1 as it was), how many times faster Ctrl makes it (1 to 30, 30 as it was), and in the top view as fast as the view is zoomed, so the map crosses the screen at the same pace zoomed in or out. Kept in the settings of the editor; the camera of the cab and of the free fly outside the editor unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * fix(editor): Ctrl+~ in the top view, over a scenery with no terrain under the camera and with the orthophoto off; "As it was" without the speed going with the zoom In the top view the box is the view itself, its corners on the ground. The ground under the camera is the terrain, else the scenery, else the rays go as far as the reach. The tile of the camera is taken anew by hurry(), it isn't followed while the layer is off. The top view is as fast zoomed in as out by default, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * fix(editor): the corners of the top view on the ground put where the camera is (the view matrix is camera-relative) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * i18n(editor): Polish for the orthophoto keys and the camera speed, on top of the master's own translations Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ * fix(editor): Ctrl+~ asks only for the tiles update() would ask for; the tooltip of "Track colours" back in its place After the reviews of #312: - hurry() skips the tiles outside the download area set and marks the ones outside the area the service covers as empty, as update() does, so Ctrl+~ no longer queues downloads update() drops at once (and the workers took anyway, into the disk cache, against the area set), nor requests the service can't answer. - A blank tile hurried takes the standard image first, as in update(); first_level() and outside_area() are shared by both loops, and the body of the loop of hurry() is hurry_tile(). - orthophoto_hurry() takes the level of the terrain only when it's below the camera, as the branch of the scenery already did: a camera under the terrain (a tunnel, under the heightmap) no longer flips the box of the view behind it. - The "Camera speed" menu goes after the tooltip of "Track colours", which it had taken. - #include <set> once in editorOrthophoto.hpp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QRgQ1K1Qu7TCsa74zsNURd --------- Co-authored-by: Claude <noreply@anthropic.com> * fix: whole-number bounds of Random() give a real number again (#416) * fix: whole-number bounds of Random() give a real number againee3af0bf(#99, in 26.05.2) renamed RandomInt to an overload, Random(int, int). The calls with whole-number bounds that expect a real number in between took the overload and draw whole numbers since: - wheel flats given with P0 happen to 1 vehicle in 101 (before: none), the random part of a flat is a whole number of millimetres; - the chance of truck hunting is h/101 instead of h/100; - the wind starts with a whole azimuth, speed and rates of change, and its direction changes in whole degrees per second; - the tachometer below 5 km/h jumps to whole numbers. The whole-number draw is RandomInt again, keeping the shared engine and the swap of inverted bounds; the loading screen's trivia use it. Those calls take the real Random() again, as up to 26.05.1. * RandomInt: the comment says what it draws and why it has a name of its own The comment put the bug on the overloading. It was in the calls that pass whole-number bounds and expect a real number; the separate name keeps them on Random(double, double). * fix: RandomInt draws from the local engine, as up to 26.05.1 from one of its own From the review of #416:ee3af0bfmoved RandomInt from an engine of its own (std::mt19937 seeded by std::random_device) to Global.random_engine, the engine of the run's seed, and only the name was taken back here. Its one caller draws the trivia of the loading screen, in init_modes, before a network client gets the seed of the session in server_hello: the server's engine was then one draw ahead of the client's, and with a fixed randomseed the trivia was the same on every start. It is drawn from Global.local_random_engine now, the engine of what one machine shows, seeded from a true random source in init_modes before the loader is made. The test of the same seed checks the shared engine with Random() and the local one with RandomInt(); a new test checks that RandomInt() doesn't move the engine of the run's seed. --------- Co-authored-by: maj00r <maj00r@host> * fix(editor): the orthophoto only on the chunks of the heightmap terrain in memory, and laid onto the ground again once it comes (#417) * fix(editor): the orthophoto only on the chunks of the heightmap terrain in memory, and laid onto the ground again once it comes Right after the editor started, the tiles of the orthophoto came from the disk cache at once and were fitted to the ground before the chunks of the heightmap terrain had come (on IRT the orthophoto was on at 24.5 s, the first chunk came at 24.5 s, the last one at 85 s). A tile with no ground under it, and none beside, stayed flat at the height of the layer (0 m, some 230 m under IRT); one partly over the ground had its holes filled from the points beside. Neither was fitted again when the ground came: only the guessed tiles were, by their middle and corners alone, and a tile with no chunk under it at all never got any. The overlay, drawn over everything, then slid with the camera (WASD, turning) instead of lying on the ground. Turning the orthophoto off and on hid it: by then the terrain was in and the tiles took their heights from it or from the edges of the tiles beside. - With the heightmap terrain (the terrain streamer active), a tile of the orthophoto, of the WMS layers and of Ctrl+~ is asked for and shown only where its chunks are in memory (terrain_streamer::ground_under): it waits while one is still to come, and where no chunk is nor will be there's no imagery at all. A scenery without the heightmap terrain is as before. - A tile remembers the points of its grid the ground didn't answer and is fitted again once the ground comes under any of them (every second point and the edges), not only the guessed tiles. No asset changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(editor): the orthophoto waits only for the chunks that will come at this distance, and lies on the other ground or the guess elsewhere After the reviews of maj00r and jerrrrycho on #417: - A tile is no longer dropped where no chunk of the heightmap terrain is nor will be. There it lies on whatever ground there is (terrain models) or on the NMT guess, as on master; a scenery with a few chunks, or with chunks removed, keeps its imagery around them. - A chunk counts as still to come only while it's being loaded or lies within the circle the streamer walks around the camera. The corners of the imagery in the 3D view, beyond that circle, no longer wait for chunks that won't load there: they lie on the guess and are sampled again when the camera comes near and the chunk loads. - terrain_streamer::ground_under() (true / false / empty) became ground_coming() (bool), the cover source of the orthophoto the coming source, and on_ground() waits_for_ground(), which only holds back a new tile. - In the scene (in_scene), the points a steep triangle leaves without a height but the heightmap terrain answers aren't kept as unanswered, so the tile isn't sampled again on every chunk that comes. The holes are counted from the heights again, as on master. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * fix(editor): the closing doesn't wait for a geoportal service that doesn't answer (#432) * fix(editor): the closing doesn't wait for a geoportal service that doesn't answer When geoportal.gov.pl took the connection and never answered, the editor's closing stood still for tens of seconds and was killed: the WinHTTP client was synchronous and looked at the stop only between the reads of a body, so a request waiting for the answer held the closing for the timeouts (up to 20 s for the answer, a few tries a square), and the map of the place-picker downloaded with no stop at all, its std::async future waited for to the end. On Windows the client now uses WinHTTP asynchronously: each step is waited for while the stop is looked at every 50 ms, and a stop closes the request at once. The timeouts, the user agent, the size limit, the errors and the body of a response with an error status stay as they were. The map of the place-picker is given up when it goes. libcurl looked at the stop during the whole transfer already. The unit tests run the client against a local server that never answers (given up within 0.4 s of the stop), one with a body of 100 kB and one with an error status. * fix(editor): the capabilities of a WMS service being added don't hold the closing either The reading of the layers of a WMS service the user adds ran on a std::async future of the editor with no stop: closing the editor while such a service didn't answer waited for its three tries. The reading is given up when the editor goes, as the other downloads now are, and editor_http_get, left with no callers, goes. The unit test's silent server no longer waits for the client to close its connection, and the requests to the local server are skipped when the environment names a proxy, which couldn't reach it. * fix(editor): the stop of the WMS reading outlives the future waiting for it The flag was declared after the future of the reading, so it was destroyed first while the future's destructor still waited for the task reading it. --------- Co-authored-by: maj00r <maj00r@host> * revert(environment): the turbidity of the sky as it was before #227 (#410) #227 (842b7688) raised the turbidity of the sky dome for most cloud covers (3 -> 4 for a clear sky, 5 -> 6 at 0.41-0.60, one more from 0.61 up to 0.90). In the Preetham model a higher turbidity darkens the sky a lot once the sun is below the horizon: with a cover of 0.47 the zenith is about a third darker 1.4 degrees below it and half as bright 3 degrees below, the stars come out right after the sunset and the ambient light taken from the sky dome drops with it. Players report the dusk as too dark since the update. The values are put back as they were before #227, in the turbidity_of() that #323 made of the old chain of conditionals. A clear sky gets the turbidity 3 again, which #227 said breaks the model at night. Co-authored-by: maj00r <maj00r@host> * Revert "fix(physicslog): no road-vehicle logs, formatting on the writer, a slow disk and the closing kept short (#408)" This reverts commitd6c3593520. --------- Co-authored-by: maj00r <73280030+maj00r@users.noreply.github.com> Co-authored-by: maj00r <maj00r@host> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Hirek193 <polomarket73@gmail.com> Co-authored-by: pol102 <mindak.m@icloud.com>
13036 lines
431 KiB
C++
13036 lines
431 KiB
C++
/*
|
|
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 "vehicle/Train.h"
|
|
#include "vehicle/horn.h"
|
|
#include "vehicle/linebreaker.h"
|
|
#include "vehicle/holdcoillever.h"
|
|
#include "vehicle/compartmentlightsswitch.h"
|
|
#include "vehicle/odometer.h"
|
|
#include "vehicle/mainctrlact.h"
|
|
|
|
#include "utilities/Globals.h"
|
|
#include "simulation/simulation.h"
|
|
#include "simulation/blackboxrecorder.h"
|
|
#include "world/Event.h"
|
|
#include "simulation/simulationtime.h"
|
|
#include "vehicle/Camera.h"
|
|
#include "utilities/Logs.h"
|
|
#include "model/MdlMngr.h"
|
|
#include "model/Model3d.h"
|
|
#include "utilities/Timer.h"
|
|
#include "vehicle/Driver.h"
|
|
#include "vehicle/DynObj.h"
|
|
#include "world/mtable.h"
|
|
#include "Console.h"
|
|
#include "application/application.h"
|
|
#include "rendering/renderer.h"
|
|
#include <future>
|
|
#include <thread>
|
|
#include <cmath>
|
|
#include <algorithm>
|
|
#include <format>
|
|
/*
|
|
namespace input {
|
|
|
|
extern user_command command;
|
|
|
|
}
|
|
*/
|
|
void control_mapper::clear()
|
|
{
|
|
|
|
*this = control_mapper();
|
|
}
|
|
|
|
void control_mapper::insert(TGauge const &Gauge, std::string const &Label)
|
|
{
|
|
|
|
if (Gauge.SubModel != nullptr)
|
|
{
|
|
m_controlnames.try_emplace(Gauge.SubModel, Label);
|
|
}
|
|
if (Gauge.SubModelOn != nullptr)
|
|
{
|
|
m_controlnames.try_emplace(Gauge.SubModelOn, Label);
|
|
}
|
|
// the duplicate submodels of a control (duplicate: yes) work the control as well (eu07/maszyna#527)
|
|
for (auto const &mirror : Gauge.mirrors())
|
|
{
|
|
insert(mirror, Label);
|
|
}
|
|
|
|
m_names.emplace(Label);
|
|
}
|
|
|
|
std::string control_mapper::find(TSubModel const *Control) const
|
|
{
|
|
|
|
auto const lookup = m_controlnames.find(Control);
|
|
if (lookup != m_controlnames.end())
|
|
{
|
|
return lookup->second;
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
bool control_mapper::contains(std::string const &Control) const
|
|
{
|
|
|
|
return m_names.contains(Control);
|
|
}
|
|
|
|
void TTrain::screen_entry::deserialize(cParser &Input)
|
|
{
|
|
|
|
while (true == deserialize_mapping(Input))
|
|
{
|
|
// all work done by while()
|
|
}
|
|
}
|
|
|
|
bool TTrain::screen_entry::deserialize_mapping(cParser &Input)
|
|
{
|
|
// token can be a key or block end
|
|
auto const key{Input.getToken<std::string>(true, "\n\r\t ,;[]")};
|
|
|
|
if (true == key.empty() || key == "}")
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (key == "{")
|
|
{
|
|
script = Input.getToken<std::string>();
|
|
}
|
|
else if (key == "target:")
|
|
{
|
|
target = Input.getToken<std::string>();
|
|
}
|
|
else if (key == "updatetime:")
|
|
{
|
|
updatetime = Input.getToken<int>();
|
|
}
|
|
else if (key == "parameters:")
|
|
{
|
|
parameters = dictionary_source(Input.getToken<std::string>());
|
|
}
|
|
else
|
|
{
|
|
// HACK: we expect this to be true only if the screen entry doesn't start with a { which means legacy configuration format
|
|
target = key;
|
|
script = Input.getToken<std::string>();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void TCab::Load(cParser &Parser)
|
|
{
|
|
// NOTE: clearing control tables here is bit of a crutch, imposed by current scheme of loading compartments anew on each cab change
|
|
ggList.clear();
|
|
btList.clear();
|
|
|
|
std::string token;
|
|
Parser.getTokens();
|
|
Parser >> token;
|
|
if (token == "cablight:")
|
|
{
|
|
Parser.getTokens(9, false);
|
|
/*
|
|
Parser
|
|
>> dimm.r
|
|
>> dimm.g
|
|
>> dimm.b
|
|
>> intlit.r
|
|
>> intlit.g
|
|
>> intlit.b
|
|
>> intlitlow.r
|
|
>> intlitlow.g
|
|
>> intlitlow.b;
|
|
*/
|
|
Parser.getTokens();
|
|
Parser >> token;
|
|
}
|
|
CabPos1.x = static_cast<float>(std::stod(token));
|
|
Parser.getTokens(5, false);
|
|
Parser >> CabPos1.y >> CabPos1.z >> CabPos2.x >> CabPos2.y >> CabPos2.z;
|
|
|
|
bEnabled = true;
|
|
bOccupied = true;
|
|
}
|
|
|
|
TGauge &TCab::Gauge(int n)
|
|
{ // pobranie adresu obiektu aniomowanego ruchem
|
|
/*
|
|
if (n < 0)
|
|
{ // rezerwacja wolnego
|
|
ggList[iGauges].Clear();
|
|
return ggList + iGauges++;
|
|
}
|
|
else if (n < iGauges)
|
|
return ggList + n;
|
|
return NULL;
|
|
*/
|
|
if (n < 0)
|
|
{
|
|
ggList.emplace_back();
|
|
return ggList.back();
|
|
}
|
|
else
|
|
{
|
|
return ggList[n];
|
|
}
|
|
};
|
|
|
|
TButton &TCab::Button(int n)
|
|
{ // pobranie adresu obiektu animowanego wyborem 1 z 2
|
|
/*
|
|
if (n < 0)
|
|
{ // rezerwacja wolnego
|
|
return btList + iButtons++;
|
|
}
|
|
else if (n < iButtons)
|
|
return btList + n;
|
|
return NULL;
|
|
*/
|
|
if (n < 0)
|
|
{
|
|
btList.emplace_back();
|
|
return btList.back();
|
|
}
|
|
else
|
|
{
|
|
return btList[n];
|
|
}
|
|
};
|
|
|
|
void TCab::Update(bool const Power)
|
|
{ // odczyt parametrów i ustawienie animacji submodelom
|
|
for (auto &gauge : ggList)
|
|
{
|
|
// animacje izometryczne
|
|
gauge.UpdateValue(); // odczyt parametru i przeliczenie na kąt
|
|
gauge.Update(); // ustawienie animacji
|
|
}
|
|
|
|
for (auto &button : btList)
|
|
{
|
|
// animacje dwustanowe
|
|
button.Update(Power); // odczyt parametru i wybór submodelu
|
|
}
|
|
};
|
|
|
|
// NOTE: we're currently using universal handlers and static handler map but it may be beneficial to have these implemented on individual class instance basis
|
|
// TBD, TODO: consider this approach if we ever want to have customized consist behaviour to received commands, based on the consist/vehicle type or whatever
|
|
TTrain::commandhandler_map const TTrain::m_commandhandlers = {
|
|
|
|
{user_command::aidriverenable, &TTrain::OnCommand_aidriverenable},
|
|
{user_command::aidriverdisable, &TTrain::OnCommand_aidriverdisable},
|
|
{user_command::jointcontrollerset, &TTrain::OnCommand_jointcontrollerset},
|
|
{user_command::mastercontrollerincrease, &TTrain::OnCommand_mastercontrollerincrease},
|
|
{user_command::mastercontrollerincreasefast, &TTrain::OnCommand_mastercontrollerincreasefast},
|
|
{user_command::mastercontrollerdecrease, &TTrain::OnCommand_mastercontrollerdecrease},
|
|
{user_command::mastercontrollerdecreasefast, &TTrain::OnCommand_mastercontrollerdecreasefast},
|
|
{user_command::mastercontrollerset, &TTrain::OnCommand_mastercontrollerset},
|
|
{user_command::secondcontrollerincrease, &TTrain::OnCommand_secondcontrollerincrease},
|
|
{user_command::secondcontrollerincreasefast, &TTrain::OnCommand_secondcontrollerincreasefast},
|
|
{user_command::secondcontrollerdecrease, &TTrain::OnCommand_secondcontrollerdecrease},
|
|
{user_command::secondcontrollerdecreasefast, &TTrain::OnCommand_secondcontrollerdecreasefast},
|
|
{user_command::secondcontrollerset, &TTrain::OnCommand_secondcontrollerset},
|
|
{user_command::dynamicbrakecontrollerincrease, &TTrain::OnCommand_DynamicBrakeControllerIncrease},
|
|
{user_command::dynamicbrakecontrollerincreasefast, &TTrain::OnCommand_DynamicBrakeControllerIncreaseFast},
|
|
{user_command::dynamicbrakecontrollerdecrease, &TTrain::OnCommand_DynamicBrakeControllerDecrease},
|
|
{user_command::dynamicbrakecontrollerdecreasefast, &TTrain::OnCommand_DynamicBrakeControllerDecreaseFast},
|
|
{user_command::dynamicbrakecontrollerset, &TTrain::OnCommand_DynamicBrakeControllerSet},
|
|
{user_command::notchingrelaytoggle, &TTrain::OnCommand_notchingrelaytoggle},
|
|
{user_command::tempomattoggle, &TTrain::OnCommand_tempomattoggle},
|
|
{user_command::mucurrentindicatorothersourceactivate, &TTrain::OnCommand_mucurrentindicatorothersourceactivate},
|
|
{user_command::independentbrakeincrease, &TTrain::OnCommand_independentbrakeincrease},
|
|
{user_command::independentbrakeincreasefast, &TTrain::OnCommand_independentbrakeincreasefast},
|
|
{user_command::independentbrakedecrease, &TTrain::OnCommand_independentbrakedecrease},
|
|
{user_command::independentbrakedecreasefast, &TTrain::OnCommand_independentbrakedecreasefast},
|
|
{user_command::independentbrakeset, &TTrain::OnCommand_independentbrakeset},
|
|
{user_command::independentbrakebailoff, &TTrain::OnCommand_independentbrakebailoff},
|
|
{user_command::universalbrakebutton1, &TTrain::OnCommand_universalbrakebutton1},
|
|
{user_command::universalbrakebutton2, &TTrain::OnCommand_universalbrakebutton2},
|
|
{user_command::universalbrakebutton3, &TTrain::OnCommand_universalbrakebutton3},
|
|
{user_command::trainbrakeincrease, &TTrain::OnCommand_trainbrakeincrease},
|
|
{user_command::trainbrakedecrease, &TTrain::OnCommand_trainbrakedecrease},
|
|
{user_command::trainbrakeset, &TTrain::OnCommand_trainbrakeset},
|
|
{user_command::trainbrakecharging, &TTrain::OnCommand_trainbrakecharging},
|
|
{user_command::trainbrakerelease, &TTrain::OnCommand_trainbrakerelease},
|
|
{user_command::trainbrakefirstservice, &TTrain::OnCommand_trainbrakefirstservice},
|
|
{user_command::trainbrakeservice, &TTrain::OnCommand_trainbrakeservice},
|
|
{user_command::trainbrakefullservice, &TTrain::OnCommand_trainbrakefullservice},
|
|
{user_command::trainbrakehandleoff, &TTrain::OnCommand_trainbrakehandleoff},
|
|
{user_command::trainbrakeemergency, &TTrain::OnCommand_trainbrakeemergency},
|
|
{user_command::trainbrakebasepressureincrease, &TTrain::OnCommand_trainbrakebasepressureincrease},
|
|
{user_command::trainbrakebasepressuredecrease, &TTrain::OnCommand_trainbrakebasepressuredecrease},
|
|
{user_command::trainbrakebasepressurereset, &TTrain::OnCommand_trainbrakebasepressurereset},
|
|
{user_command::trainbrakeoperationtoggle, &TTrain::OnCommand_trainbrakeoperationtoggle},
|
|
{user_command::manualbrakeincrease, &TTrain::OnCommand_manualbrakeincrease},
|
|
{user_command::manualbrakedecrease, &TTrain::OnCommand_manualbrakedecrease},
|
|
{user_command::alarmchaintoggle, &TTrain::OnCommand_alarmchaintoggle},
|
|
{user_command::alarmchainenable, &TTrain::OnCommand_alarmchainenable},
|
|
{user_command::alarmchaindisable, &TTrain::OnCommand_alarmchaindisable},
|
|
{user_command::wheelspinbrakeactivate, &TTrain::OnCommand_wheelspinbrakeactivate},
|
|
{user_command::sandboxactivate, &TTrain::OnCommand_sandboxactivate},
|
|
{user_command::autosandboxtoggle, &TTrain::OnCommand_autosandboxtoggle},
|
|
{user_command::autosandboxactivate, &TTrain::OnCommand_autosandboxactivate},
|
|
{user_command::autosandboxdeactivate, &TTrain::OnCommand_autosandboxdeactivate},
|
|
{user_command::epbrakecontroltoggle, &TTrain::OnCommand_epbrakecontroltoggle},
|
|
{user_command::epbrakecontrolenable, &TTrain::OnCommand_epbrakecontrolenable},
|
|
{user_command::epbrakecontroldisable, &TTrain::OnCommand_epbrakecontroldisable},
|
|
{user_command::trainbrakeoperationmodeincrease, &TTrain::OnCommand_trainbrakeoperationmodeincrease},
|
|
{user_command::trainbrakeoperationmodedecrease, &TTrain::OnCommand_trainbrakeoperationmodedecrease},
|
|
{user_command::brakeactingspeedincrease, &TTrain::OnCommand_brakeactingspeedincrease},
|
|
{user_command::brakeactingspeeddecrease, &TTrain::OnCommand_brakeactingspeeddecrease},
|
|
{user_command::brakeactingspeedsetcargo, &TTrain::OnCommand_brakeactingspeedsetcargo},
|
|
{user_command::brakeactingspeedsetpassenger, &TTrain::OnCommand_brakeactingspeedsetpassenger},
|
|
{user_command::brakeactingspeedsetrapid, &TTrain::OnCommand_brakeactingspeedsetrapid},
|
|
{user_command::brakeloadcompensationincrease, &TTrain::OnCommand_brakeloadcompensationincrease},
|
|
{user_command::brakeloadcompensationdecrease, &TTrain::OnCommand_brakeloadcompensationdecrease},
|
|
{user_command::mubrakingindicatortoggle, &TTrain::OnCommand_mubrakingindicatortoggle},
|
|
{user_command::reverserincrease, &TTrain::OnCommand_reverserincrease},
|
|
{user_command::reverserdecrease, &TTrain::OnCommand_reverserdecrease},
|
|
{user_command::reverserforwardhigh, &TTrain::OnCommand_reverserforwardhigh},
|
|
{user_command::reverserforward, &TTrain::OnCommand_reverserforward},
|
|
{user_command::reverserneutral, &TTrain::OnCommand_reverserneutral},
|
|
{user_command::reverserbackward, &TTrain::OnCommand_reverserbackward},
|
|
{user_command::alerteracknowledge, &TTrain::OnCommand_alerteracknowledge},
|
|
{user_command::cabsignalacknowledge, &TTrain::OnCommand_cabsignalacknowledge},
|
|
{user_command::batterytoggle, &TTrain::OnCommand_batterytoggle},
|
|
{user_command::batteryenable, &TTrain::OnCommand_batteryenable},
|
|
{user_command::batterydisable, &TTrain::OnCommand_batterydisable},
|
|
{user_command::cabactivationtoggle, &TTrain::OnCommand_cabactivationtoggle},
|
|
{user_command::cabactivationenable, &TTrain::OnCommand_cabactivationenable},
|
|
{user_command::cabactivationdisable, &TTrain::OnCommand_cabactivationdisable},
|
|
{user_command::pantographcompressorvalvetoggle, &TTrain::OnCommand_pantographcompressorvalvetoggle},
|
|
{user_command::pantographcompressorvalveenable, &TTrain::OnCommand_pantographcompressorvalveenable},
|
|
{user_command::pantographcompressorvalvedisable, &TTrain::OnCommand_pantographcompressorvalvedisable},
|
|
{user_command::pantographcompressoractivate, &TTrain::OnCommand_pantographcompressoractivate},
|
|
{user_command::pantographtogglefront, &TTrain::OnCommand_pantographtogglefront},
|
|
{user_command::pantographtogglerear, &TTrain::OnCommand_pantographtogglerear},
|
|
{user_command::pantographraisefront, &TTrain::OnCommand_pantographraisefront},
|
|
{user_command::pantographraiserear, &TTrain::OnCommand_pantographraiserear},
|
|
{user_command::pantographlowerfront, &TTrain::OnCommand_pantographlowerfront},
|
|
{user_command::pantographlowerrear, &TTrain::OnCommand_pantographlowerrear},
|
|
|
|
{user_command::wiperswitchincrease, &TTrain::OnCommand_wiperswitchincrease},
|
|
{user_command::wiperswitchdecrease, &TTrain::OnCommand_wiperswitchdecrease},
|
|
|
|
{user_command::lightsset, &TTrain::OnCommand_lightsset},
|
|
|
|
{user_command::pantographlowerall, &TTrain::OnCommand_pantographlowerall},
|
|
{user_command::pantographselectnext, &TTrain::OnCommand_pantographselectnext},
|
|
{user_command::pantographselectprevious, &TTrain::OnCommand_pantographselectprevious},
|
|
{user_command::pantographtoggleselected, &TTrain::OnCommand_pantographtoggleselected},
|
|
{user_command::pantographraiseselected, &TTrain::OnCommand_pantographraiseselected},
|
|
{user_command::pantographlowerselected, &TTrain::OnCommand_pantographlowerselected},
|
|
{user_command::pantographvalvesupdate, &TTrain::OnCommand_pantographvalvesupdate},
|
|
{user_command::pantographvalvesoff, &TTrain::OnCommand_pantographvalvesoff},
|
|
{user_command::linebreakertoggle, &TTrain::OnCommand_linebreakertoggle},
|
|
{user_command::linebreakeropen, &TTrain::OnCommand_linebreakeropen},
|
|
{user_command::linebreakerclose, &TTrain::OnCommand_linebreakerclose},
|
|
{user_command::linebreakertoggleb, &TTrain::OnCommand_linebreakertoggleremote},
|
|
{user_command::linebreakeropenb, &TTrain::OnCommand_linebreakeropenremote},
|
|
{user_command::linebreakercloseb, &TTrain::OnCommand_linebreakercloseremote},
|
|
{user_command::linebreakertogglec, &TTrain::OnCommand_linebreakertoggleremote},
|
|
{user_command::linebreakeropenc, &TTrain::OnCommand_linebreakeropenremote},
|
|
{user_command::linebreakerclosec, &TTrain::OnCommand_linebreakercloseremote},
|
|
{user_command::fuelpumptoggle, &TTrain::OnCommand_fuelpumptoggle},
|
|
{user_command::fuelpumpenable, &TTrain::OnCommand_fuelpumpenable},
|
|
{user_command::fuelpumpdisable, &TTrain::OnCommand_fuelpumpdisable},
|
|
{user_command::oilpumptoggle, &TTrain::OnCommand_oilpumptoggle},
|
|
{user_command::oilfuelpumptoggle, &TTrain::OnCommand_oilfuelpumptoggle},
|
|
{user_command::oilpumpenable, &TTrain::OnCommand_oilpumpenable},
|
|
{user_command::oilpumpdisable, &TTrain::OnCommand_oilpumpdisable},
|
|
{user_command::waterheaterbreakertoggle, &TTrain::OnCommand_waterheaterbreakertoggle},
|
|
{user_command::waterheaterbreakerclose, &TTrain::OnCommand_waterheaterbreakerclose},
|
|
{user_command::waterheaterbreakeropen, &TTrain::OnCommand_waterheaterbreakeropen},
|
|
{user_command::waterheatertoggle, &TTrain::OnCommand_waterheatertoggle},
|
|
{user_command::waterheaterenable, &TTrain::OnCommand_waterheaterenable},
|
|
{user_command::waterheaterdisable, &TTrain::OnCommand_waterheaterdisable},
|
|
{user_command::waterpumpbreakertoggle, &TTrain::OnCommand_waterpumpbreakertoggle},
|
|
{user_command::waterpumpbreakerclose, &TTrain::OnCommand_waterpumpbreakerclose},
|
|
{user_command::waterpumpbreakeropen, &TTrain::OnCommand_waterpumpbreakeropen},
|
|
{user_command::waterpumptoggle, &TTrain::OnCommand_waterpumptoggle},
|
|
{user_command::waterpumpenable, &TTrain::OnCommand_waterpumpenable},
|
|
{user_command::waterpumpdisable, &TTrain::OnCommand_waterpumpdisable},
|
|
{user_command::watercircuitslinktoggle, &TTrain::OnCommand_watercircuitslinktoggle},
|
|
{user_command::watercircuitslinkenable, &TTrain::OnCommand_watercircuitslinkenable},
|
|
{user_command::watercircuitslinkdisable, &TTrain::OnCommand_watercircuitslinkdisable},
|
|
{user_command::convertertoggle, &TTrain::OnCommand_convertertoggle},
|
|
{user_command::converterenable, &TTrain::OnCommand_converterenable},
|
|
{user_command::converterdisable, &TTrain::OnCommand_converterdisable},
|
|
{user_command::convertertogglelocal, &TTrain::OnCommand_convertertogglelocal},
|
|
{user_command::converteroverloadrelayreset, &TTrain::OnCommand_converteroverloadrelayreset},
|
|
{user_command::compressortoggle, &TTrain::OnCommand_compressortoggle},
|
|
{user_command::compressorenable, &TTrain::OnCommand_compressorenable},
|
|
{user_command::compressordisable, &TTrain::OnCommand_compressordisable},
|
|
{user_command::compressortogglelocal, &TTrain::OnCommand_compressortogglelocal},
|
|
{user_command::compressorpresetactivatenext, &TTrain::OnCommand_compressorpresetactivatenext},
|
|
{user_command::compressorpresetactivateprevious, &TTrain::OnCommand_compressorpresetactivateprevious},
|
|
{user_command::compressorpresetactivatedefault, &TTrain::OnCommand_compressorpresetactivatedefault},
|
|
{user_command::motorblowerstogglefront, &TTrain::OnCommand_motorblowerstogglefront},
|
|
{user_command::motorblowerstogglerear, &TTrain::OnCommand_motorblowerstogglerear},
|
|
{user_command::motorblowersdisableall, &TTrain::OnCommand_motorblowersdisableall},
|
|
{user_command::coolingfanstoggle, &TTrain::OnCommand_coolingfanstoggle},
|
|
{user_command::motorconnectorsopen, &TTrain::OnCommand_motorconnectorsopen},
|
|
{user_command::motorconnectorsclose, &TTrain::OnCommand_motorconnectorsclose},
|
|
{user_command::motordisconnect, &TTrain::OnCommand_motordisconnect},
|
|
{user_command::motoroverloadrelaythresholdtoggle, &TTrain::OnCommand_motoroverloadrelaythresholdtoggle},
|
|
{user_command::motoroverloadrelaythresholdsetlow, &TTrain::OnCommand_motoroverloadrelaythresholdsetlow},
|
|
{user_command::motoroverloadrelaythresholdsethigh, &TTrain::OnCommand_motoroverloadrelaythresholdsethigh},
|
|
{user_command::motoroverloadrelayreset, &TTrain::OnCommand_motoroverloadrelayreset},
|
|
{user_command::universalrelayreset1, &TTrain::OnCommand_universalrelayreset},
|
|
{user_command::universalrelayreset2, &TTrain::OnCommand_universalrelayreset},
|
|
{user_command::universalrelayreset3, &TTrain::OnCommand_universalrelayreset},
|
|
{user_command::heatingtoggle, &TTrain::OnCommand_heatingtoggle},
|
|
{user_command::heatingenable, &TTrain::OnCommand_heatingenable},
|
|
{user_command::heatingdisable, &TTrain::OnCommand_heatingdisable},
|
|
{user_command::lightspresetactivatenext, &TTrain::OnCommand_lightspresetactivatenext},
|
|
{user_command::lightspresetactivateprevious, &TTrain::OnCommand_lightspresetactivateprevious},
|
|
{user_command::headlighttoggleleft, &TTrain::OnCommand_headlighttoggleleft},
|
|
{user_command::headlightenableleft, &TTrain::OnCommand_headlightenableleft},
|
|
{user_command::headlightdisableleft, &TTrain::OnCommand_headlightdisableleft},
|
|
{user_command::headlighttoggleright, &TTrain::OnCommand_headlighttoggleright},
|
|
{user_command::headlightenableright, &TTrain::OnCommand_headlightenableright},
|
|
{user_command::headlightdisableright, &TTrain::OnCommand_headlightdisableright},
|
|
{user_command::headlighttoggleupper, &TTrain::OnCommand_headlighttoggleupper},
|
|
{user_command::headlightenableupper, &TTrain::OnCommand_headlightenableupper},
|
|
{user_command::headlightdisableupper, &TTrain::OnCommand_headlightdisableupper},
|
|
{user_command::redmarkertoggleleft, &TTrain::OnCommand_redmarkertoggleleft},
|
|
{user_command::redmarkerenableleft, &TTrain::OnCommand_redmarkerenableleft},
|
|
{user_command::redmarkerdisableleft, &TTrain::OnCommand_redmarkerdisableleft},
|
|
{user_command::redmarkertoggleright, &TTrain::OnCommand_redmarkertoggleright},
|
|
{user_command::redmarkerenableright, &TTrain::OnCommand_redmarkerenableright},
|
|
{user_command::redmarkerdisableright, &TTrain::OnCommand_redmarkerdisableright},
|
|
{user_command::headlighttogglerearleft, &TTrain::OnCommand_headlighttogglerearleft},
|
|
{user_command::headlightenablerearleft, &TTrain::OnCommand_headlightenablerearleft},
|
|
{user_command::headlightdisablerearleft, &TTrain::OnCommand_headlightdisablerearleft},
|
|
{user_command::headlighttogglerearright, &TTrain::OnCommand_headlighttogglerearright},
|
|
{user_command::headlightenablerearright, &TTrain::OnCommand_headlightenablerearright},
|
|
{user_command::headlightdisablerearright, &TTrain::OnCommand_headlightdisablerearright},
|
|
{user_command::headlighttogglerearupper, &TTrain::OnCommand_headlighttogglerearupper},
|
|
{user_command::headlightenablerearupper, &TTrain::OnCommand_headlightenablerearupper},
|
|
{user_command::headlightdisablerearupper, &TTrain::OnCommand_headlightdisablerearupper},
|
|
{user_command::modernlightdimmerdecrease, &TTrain::OnCommand_modernlightdimmerdecrease},
|
|
{user_command::modernlightdimmerincrease, &TTrain::OnCommand_modernlightdimmerincrease},
|
|
{user_command::redmarkertogglerearleft, &TTrain::OnCommand_redmarkertogglerearleft},
|
|
{user_command::redmarkerenablerearleft, &TTrain::OnCommand_redmarkerenablerearleft},
|
|
{user_command::redmarkerdisablerearleft, &TTrain::OnCommand_redmarkerdisablerearleft},
|
|
{user_command::redmarkertogglerearright, &TTrain::OnCommand_redmarkertogglerearright},
|
|
{user_command::redmarkerenablerearright, &TTrain::OnCommand_redmarkerenablerearright},
|
|
{user_command::redmarkerdisablerearright, &TTrain::OnCommand_redmarkerdisablerearright},
|
|
{user_command::redmarkerstoggle, &TTrain::OnCommand_redmarkerstoggle},
|
|
{user_command::endsignalstoggle, &TTrain::OnCommand_endsignalstoggle},
|
|
{user_command::headlightsdimtoggle, &TTrain::OnCommand_headlightsdimtoggle},
|
|
{user_command::headlightsdimenable, &TTrain::OnCommand_headlightsdimenable},
|
|
{user_command::headlightsdimdisable, &TTrain::OnCommand_headlightsdimdisable},
|
|
{user_command::interiorlighttoggle, &TTrain::OnCommand_interiorlighttoggle},
|
|
{user_command::interiorlightenable, &TTrain::OnCommand_interiorlightenable},
|
|
{user_command::interiorlightdisable, &TTrain::OnCommand_interiorlightdisable},
|
|
{user_command::interiorlightdimtoggle, &TTrain::OnCommand_interiorlightdimtoggle},
|
|
{user_command::interiorlightdimenable, &TTrain::OnCommand_interiorlightdimenable},
|
|
{user_command::interiorlightdimdisable, &TTrain::OnCommand_interiorlightdimdisable},
|
|
{user_command::compartmentlightstoggle, &TTrain::OnCommand_compartmentlightstoggle},
|
|
{user_command::compartmentlightsenable, &TTrain::OnCommand_compartmentlightsenable},
|
|
{user_command::compartmentlightsdisable, &TTrain::OnCommand_compartmentlightsdisable},
|
|
{user_command::instrumentlighttoggle, &TTrain::OnCommand_instrumentlighttoggle},
|
|
{user_command::instrumentlightenable, &TTrain::OnCommand_instrumentlightenable},
|
|
{user_command::instrumentlightdisable, &TTrain::OnCommand_instrumentlightdisable},
|
|
{user_command::dashboardlighttoggle, &TTrain::OnCommand_dashboardlighttoggle},
|
|
{user_command::dashboardlightenable, &TTrain::OnCommand_dashboardlightenable},
|
|
{user_command::dashboardlightdisable, &TTrain::OnCommand_dashboardlightdisable},
|
|
{user_command::timetablelighttoggle, &TTrain::OnCommand_timetablelighttoggle},
|
|
{user_command::timetablelightenable, &TTrain::OnCommand_timetablelightenable},
|
|
{user_command::timetablelightdisable, &TTrain::OnCommand_timetablelightdisable},
|
|
{user_command::doorlocktoggle, &TTrain::OnCommand_doorlocktoggle},
|
|
{user_command::doortoggleleft, &TTrain::OnCommand_doortoggleleft},
|
|
{user_command::doortoggleright, &TTrain::OnCommand_doortoggleright},
|
|
{user_command::doorpermitleft, &TTrain::OnCommand_doorpermitleft},
|
|
{user_command::doorpermitright, &TTrain::OnCommand_doorpermitright},
|
|
{user_command::doorpermitpresetactivatenext, &TTrain::OnCommand_doorpermitpresetactivatenext},
|
|
{user_command::doorpermitpresetactivateprevious, &TTrain::OnCommand_doorpermitpresetactivateprevious},
|
|
{user_command::dooropenleft, &TTrain::OnCommand_dooropenleft},
|
|
{user_command::dooropenright, &TTrain::OnCommand_dooropenright},
|
|
{user_command::doorcloseleft, &TTrain::OnCommand_doorcloseleft},
|
|
{user_command::doorcloseright, &TTrain::OnCommand_doorcloseright},
|
|
{user_command::dooropenall, &TTrain::OnCommand_dooropenall},
|
|
{user_command::doorcloseall, &TTrain::OnCommand_doorcloseall},
|
|
{user_command::doorsteptoggle, &TTrain::OnCommand_doorsteptoggle},
|
|
{user_command::doormodetoggle, &TTrain::OnCommand_doormodetoggle},
|
|
{user_command::mirrorstoggle, &TTrain::OnCommand_mirrorstoggle},
|
|
{user_command::nearestcarcouplingincrease, &TTrain::OnCommand_nearestcarcouplingincrease},
|
|
{user_command::nearestcarcouplingdisconnect, &TTrain::OnCommand_nearestcarcouplingdisconnect},
|
|
{user_command::nearestcarcoupleradapterattach, &TTrain::OnCommand_nearestcarcoupleradapterattach},
|
|
{user_command::nearestcarcoupleradapterremove, &TTrain::OnCommand_nearestcarcoupleradapterremove},
|
|
{user_command::occupiedcarcouplingdisconnect, &TTrain::OnCommand_occupiedcarcouplingdisconnect},
|
|
{user_command::departureannounce, &TTrain::OnCommand_departureannounce},
|
|
{user_command::hornlowactivate, &TTrain::OnCommand_hornlowactivate},
|
|
{user_command::hornhighactivate, &TTrain::OnCommand_hornhighactivate},
|
|
{user_command::whistleactivate, &TTrain::OnCommand_whistleactivate},
|
|
{user_command::radiotoggle, &TTrain::OnCommand_radiotoggle},
|
|
{user_command::radioenable, &TTrain::OnCommand_radioenable},
|
|
{user_command::radiodisable, &TTrain::OnCommand_radiodisable},
|
|
{user_command::radiochannelincrease, &TTrain::OnCommand_radiochannelincrease},
|
|
{user_command::radiochanneldecrease, &TTrain::OnCommand_radiochanneldecrease},
|
|
{user_command::radiochannelset, &TTrain::OnCommand_radiochannelset},
|
|
{user_command::radiostopsend, &TTrain::OnCommand_radiostopsend},
|
|
{user_command::radiostopenable, &TTrain::OnCommand_radiostopenable},
|
|
{user_command::radiostopdisable, &TTrain::OnCommand_radiostopdisable},
|
|
{user_command::radiostoptest, &TTrain::OnCommand_radiostoptest},
|
|
{user_command::radiocall1send, &TTrain::OnCommand_radiocall1send},
|
|
{user_command::radiocall3send, &TTrain::OnCommand_radiocall3send},
|
|
{user_command::radiovolumeincrease, &TTrain::OnCommand_radiovolumeincrease},
|
|
{user_command::radiovolumedecrease, &TTrain::OnCommand_radiovolumedecrease},
|
|
{user_command::radiovolumeset, &TTrain::OnCommand_radiovolumeset},
|
|
{user_command::radiofusetoggle, &TTrain::OnCommand_radiofusetoggle},
|
|
{user_command::radiofuseenable, &TTrain::OnCommand_radiofuseenable},
|
|
{user_command::radiofusedisable, &TTrain::OnCommand_radiofusedisable},
|
|
{user_command::cabchangeforward, &TTrain::OnCommand_cabchangeforward},
|
|
{user_command::cabchangebackward, &TTrain::OnCommand_cabchangebackward},
|
|
{user_command::generictoggle0, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle1, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle2, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle3, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle4, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle5, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle6, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle7, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle8, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle9, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle10, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle11, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle12, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle13, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle14, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle15, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle16, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle17, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle18, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle19, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle20, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle21, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle22, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle23, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle24, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle25, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle26, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle27, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle28, &TTrain::OnCommand_generictoggle},
|
|
{user_command::generictoggle29, &TTrain::OnCommand_generictoggle},
|
|
{user_command::genericset0, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset1, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset2, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset3, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset4, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset5, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset6, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset7, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset8, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset9, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset10, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset11, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset12, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset13, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset14, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset15, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset16, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset17, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset18, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset19, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset20, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset21, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset22, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset23, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset24, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset25, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset26, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset27, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset28, &TTrain::OnCommand_genericset},
|
|
{user_command::genericset29, &TTrain::OnCommand_genericset},
|
|
{user_command::vehiclemoveforwards, &TTrain::OnCommand_vehiclemoveforwards},
|
|
{user_command::vehiclemovebackwards, &TTrain::OnCommand_vehiclemovebackwards},
|
|
{user_command::vehicleboost, &TTrain::OnCommand_vehicleboost},
|
|
{user_command::springbraketoggle, &TTrain::OnCommand_springbraketoggle},
|
|
{user_command::springbrakeenable, &TTrain::OnCommand_springbrakeenable},
|
|
{user_command::springbrakedisable, &TTrain::OnCommand_springbrakedisable},
|
|
{user_command::springbrakeshutofftoggle, &TTrain::OnCommand_springbrakeshutofftoggle},
|
|
{user_command::springbrakeshutoffenable, &TTrain::OnCommand_springbrakeshutoffenable},
|
|
{user_command::springbrakeshutoffdisable, &TTrain::OnCommand_springbrakeshutoffdisable},
|
|
{user_command::springbrakerelease, &TTrain::OnCommand_springbrakerelease},
|
|
{user_command::distancecounteractivate, &TTrain::OnCommand_distancecounteractivate},
|
|
{user_command::speedcontrolincrease, &TTrain::OnCommand_speedcontrolincrease},
|
|
{user_command::speedcontroldecrease, &TTrain::OnCommand_speedcontroldecrease},
|
|
{user_command::speedcontrolpowerincrease, &TTrain::OnCommand_speedcontrolpowerincrease},
|
|
{user_command::speedcontrolpowerdecrease, &TTrain::OnCommand_speedcontrolpowerdecrease},
|
|
{user_command::speedcontrolbutton0, &TTrain::OnCommand_speedcontrolbutton},
|
|
{user_command::speedcontrolbutton1, &TTrain::OnCommand_speedcontrolbutton},
|
|
{user_command::speedcontrolbutton2, &TTrain::OnCommand_speedcontrolbutton},
|
|
{user_command::speedcontrolbutton3, &TTrain::OnCommand_speedcontrolbutton},
|
|
{user_command::speedcontrolbutton4, &TTrain::OnCommand_speedcontrolbutton},
|
|
{user_command::speedcontrolbutton5, &TTrain::OnCommand_speedcontrolbutton},
|
|
{user_command::speedcontrolbutton6, &TTrain::OnCommand_speedcontrolbutton},
|
|
{user_command::speedcontrolbutton7, &TTrain::OnCommand_speedcontrolbutton},
|
|
{user_command::speedcontrolbutton8, &TTrain::OnCommand_speedcontrolbutton},
|
|
{user_command::speedcontrolbutton9, &TTrain::OnCommand_speedcontrolbutton},
|
|
{user_command::inverterenable1, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterenable2, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterenable3, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterenable4, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterenable5, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterenable6, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterenable7, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterenable8, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterenable9, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterenable10, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterenable11, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterenable12, &TTrain::OnCommand_inverterenable},
|
|
{user_command::inverterdisable1, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::inverterdisable2, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::inverterdisable3, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::inverterdisable4, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::inverterdisable5, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::inverterdisable6, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::inverterdisable7, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::inverterdisable8, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::inverterdisable9, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::inverterdisable10, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::inverterdisable11, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::inverterdisable12, &TTrain::OnCommand_inverterdisable},
|
|
{user_command::invertertoggle1, &TTrain::OnCommand_invertertoggle},
|
|
{user_command::invertertoggle2, &TTrain::OnCommand_invertertoggle},
|
|
{user_command::invertertoggle3, &TTrain::OnCommand_invertertoggle},
|
|
{user_command::invertertoggle4, &TTrain::OnCommand_invertertoggle},
|
|
{user_command::invertertoggle5, &TTrain::OnCommand_invertertoggle},
|
|
{user_command::invertertoggle6, &TTrain::OnCommand_invertertoggle},
|
|
{user_command::invertertoggle7, &TTrain::OnCommand_invertertoggle},
|
|
{user_command::invertertoggle8, &TTrain::OnCommand_invertertoggle},
|
|
{user_command::invertertoggle9, &TTrain::OnCommand_invertertoggle},
|
|
{user_command::invertertoggle10, &TTrain::OnCommand_invertertoggle},
|
|
{user_command::invertertoggle11, &TTrain::OnCommand_invertertoggle},
|
|
{user_command::invertertoggle12, &TTrain::OnCommand_invertertoggle},
|
|
};
|
|
|
|
std::vector<std::string> const TTrain::fPress_labels = {
|
|
|
|
"ch1: ", "ch2: ", "ch3: ", "ch4: ", "ch5: ", "ch6: ", "ch7: ", "ch8: ", "ch9: ", "ch0: "};
|
|
|
|
TTrain::TTrain()
|
|
{
|
|
|
|
// McZapkie-240302 - przyda sie do tachometru
|
|
|
|
// asMessage="";
|
|
DynamicSet(nullptr); // ustawia wszystkie mv*
|
|
//-----
|
|
|
|
//
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
bMains[i] = false;
|
|
fCntVol[i] = 0.0f;
|
|
bPants[i][0] = false;
|
|
bPants[i][1] = false;
|
|
bFuse[i] = false;
|
|
bBatt[i] = false;
|
|
bConv[i] = false;
|
|
bComp[i][0] = false;
|
|
bComp[i][1] = false;
|
|
// bComp[ i ][ 2 ] = false;
|
|
// bComp[ i ][ 3 ] = false;
|
|
bHeat[i] = false;
|
|
}
|
|
bCompressors.clear();
|
|
for (int i = 0; i < 9; ++i)
|
|
for (int j = 0; j < 10; ++j)
|
|
{
|
|
fEIMParams[i][j] = 0.0;
|
|
fDieselParams[i][j] = 0.0;
|
|
}
|
|
|
|
for (int i = 0; i < 20; ++i)
|
|
{
|
|
for (auto &press : fPress[i])
|
|
press = 0.0;
|
|
bBrakes[i][0] = false;
|
|
bBrakes[i][1] = false;
|
|
}
|
|
}
|
|
|
|
TTrain::~TTrain() = default;
|
|
|
|
bool TTrain::Init(TDynamicObject *NewDynamicObject, bool e3d)
|
|
{ // powiązanie ręcznego sterowania kabiną z pojazdem
|
|
if (NewDynamicObject->Mechanik == nullptr)
|
|
{
|
|
/*
|
|
ErrorLog( "Bad config: can't take control of inactive vehicle \"" + NewDynamicObject->asName + "\"" );
|
|
return false;
|
|
*/
|
|
auto const activecab{(NewDynamicObject->MoverParameters->CabOccupied > 0 ? "1" : NewDynamicObject->MoverParameters->CabOccupied < 0 ? "2" : "p")};
|
|
NewDynamicObject->create_controller(activecab, NewDynamicObject->ctOwner != nullptr);
|
|
}
|
|
|
|
DynamicSet(NewDynamicObject);
|
|
if (!e3d && DynamicObject->Mechanik == nullptr)
|
|
return false;
|
|
|
|
DynamicObject->MechInside = true;
|
|
|
|
fMainRelayTimer = 0; // Hunter, do k...y nędzy, ustawiaj wartości początkowe zmiennych!
|
|
|
|
iCabn = mvOccupied->CabOccupied > 0 ? 1 : mvOccupied->CabOccupied < 0 ? 2 : 0;
|
|
|
|
{
|
|
Global.CurrentMaxTextureSize = Global.iMaxCabTextureSize;
|
|
|
|
auto const filename{mvOccupied->TypeName + ".mmd"};
|
|
LoadMMediaFile(filename);
|
|
InitializeCab(mvOccupied->CabOccupied, filename);
|
|
|
|
Global.CurrentMaxTextureSize = Global.iMaxTextureSize;
|
|
|
|
if (DynamicObject->Controller == Humandriver)
|
|
{
|
|
// McZapkie-030303: mozliwosc wyswietlania kabiny, w przyszlosci dac opcje w mmd
|
|
DynamicObject->bDisplayCab = true;
|
|
}
|
|
}
|
|
|
|
// Ra: taka proteza - przesłanie kierunku do członów connected
|
|
/*
|
|
if (mvControlled->DirActive > 0)
|
|
{ // było do przodu
|
|
mvControlled->DirectionBackward();
|
|
mvControlled->DirectionForward();
|
|
}
|
|
else if (mvControlled->DirActive < 0)
|
|
{
|
|
mvControlled->DirectionForward();
|
|
mvControlled->DirectionBackward();
|
|
}
|
|
*/
|
|
if (false == DynamicObject->Mechanik->AIControllFlag)
|
|
{
|
|
DynamicObject->Mechanik->sync_consist_reversers();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
std::shared_ptr<dictionary_source> TTrain::GetTrainState(dictionary_source const &Extraparameters)
|
|
{
|
|
|
|
if (mvOccupied == nullptr || mvControlled == nullptr)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
auto dict = std::make_shared<dictionary_source>(Extraparameters);
|
|
if (dict == nullptr)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
dict->insert("name", DynamicObject->asName);
|
|
dict->insert("cab", mvOccupied->CabOccupied);
|
|
dict->insert("cabactive", mvOccupied->CabActive);
|
|
dict->insert("master", mvOccupied->CabMaster);
|
|
// basic systems state data
|
|
dict->insert("battery", mvOccupied->Power24vIsAvailable);
|
|
dict->insert("linebreaker", mvControlled->Mains);
|
|
dict->insert("main_init", mvControlled->MainsInitTimeCountdown < mvControlled->MainsInitTime && mvControlled->MainsInitTimeCountdown > 0.0);
|
|
dict->insert("main_ready", false == mvControlled->Mains && fHVoltage > 0.0 && mvControlled->MainsInitTimeCountdown <= 0.0);
|
|
dict->insert("converter", mvOccupied->Power110vIsAvailable);
|
|
dict->insert("converter_overload", mvControlled->ConvOvldFlag);
|
|
dict->insert("compress", mvControlled->CompressorFlag);
|
|
dict->insert("pant_compressor", mvPantographUnit->PantCompFlag);
|
|
dict->insert("lights_front", mvOccupied->iLights[end::front]);
|
|
dict->insert("lights_rear", mvOccupied->iLights[end::rear]);
|
|
dict->insert("off_from_dimmer", mvOccupied->currentDimPosition().isOff);
|
|
dict->insert("lights_compartments", mvOccupied->CompartmentLights.is_active || mvOccupied->CompartmentLights.is_disabled);
|
|
if (Dynamic()->Mechanik)
|
|
{
|
|
auto const *controller{Dynamic()->Mechanik};
|
|
auto const cabmodifier{cab_to_end() == end::front ? 1 : -1};
|
|
auto const traindirection{controller->Direction() * cabmodifier};
|
|
auto const *frontvehicle{controller->Vehicle(traindirection >= 0 ? end::front : end::rear)};
|
|
auto const *rearvehicle{controller->Vehicle(traindirection >= 0 ? end::rear : end::front)};
|
|
auto const frontvehicledirection{(frontvehicle->DirectionGet() == controller->Vehicle()->DirectionGet() ? 1 : -1)};
|
|
auto const rearvehicledirection{(rearvehicle->DirectionGet() == controller->Vehicle()->DirectionGet() ? 1 : -1)};
|
|
auto const fronttrainlights{frontvehicle->MoverParameters->iLights[frontvehicledirection * cabmodifier >= 0 ? end::front : end::rear]};
|
|
auto const reartrainlights{rearvehicle->MoverParameters->iLights[rearvehicledirection * cabmodifier >= 0 ? end::rear : end::front]};
|
|
dict->insert("lights_train_front", fronttrainlights);
|
|
dict->insert("lights_train_rear", reartrainlights);
|
|
}
|
|
else
|
|
{
|
|
// fallback, in the unlikely case we lose the controller
|
|
dict->insert("lights_train_front", mvOccupied->iLights[end::front]);
|
|
dict->insert("lights_train_rear", mvOccupied->iLights[end::rear]);
|
|
}
|
|
// reverser
|
|
dict->insert("direction", mvOccupied->DirActive);
|
|
// throttle
|
|
dict->insert("mainctrl_pos", mvControlled->MainCtrlPos);
|
|
dict->insert("mainctrl_pos_count", mvControlled->MainCtrlPosNo);
|
|
dict->insert("main_ctrl_actual_pos", mvControlled->MainCtrlActualPos);
|
|
dict->insert("scndctrl_pos", mvControlled->ScndCtrlPos);
|
|
dict->insert("dynamicbrake_pos", mvControlled->DynamicBrakeCtrlPos);
|
|
dict->insert("scnd_ctrl_actual_pos", mvControlled->ScndCtrlActualPos);
|
|
dict->insert("brakectrl_pos", mvControlled->fBrakeCtrlPos);
|
|
dict->insert("localbrake_pos", mvControlled->LocalBrakePosA);
|
|
dict->insert("new_speed", mvOccupied->NewSpeed);
|
|
dict->insert("speedctrl", mvOccupied->SpeedCtrlValue);
|
|
dict->insert("speedctrlpower", mvOccupied->SpeedCtrlUnit.DesiredPower);
|
|
dict->insert("speedctrlactive", mvOccupied->SpeedCtrlUnit.IsActive);
|
|
dict->insert("speedctrlstandby", mvOccupied->SpeedCtrlUnit.Standby);
|
|
// brakes
|
|
dict->insert("manual_brake", mvOccupied->ManualBrakePos > 0);
|
|
bool const bEP = mvControlled->LocHandle->GetCP() > 0.2 || fEIMParams[0][5] > 0.01;
|
|
dict->insert("dir_brake", bEP);
|
|
bool bPN{false};
|
|
auto const &brakevalve{*mvOccupied->Hamulec};
|
|
if (auto const &brakevalvetype{typeid(brakevalve)}; brakevalvetype == typeid(TLSt) || brakevalvetype == typeid(TEStED))
|
|
{
|
|
|
|
TBrake *temp_ham = mvOccupied->Hamulec.get();
|
|
bPN = static_cast<TLSt *>(temp_ham)->GetEDBCP() > 0.2;
|
|
}
|
|
dict->insert("indir_brake", bPN);
|
|
dict->insert("emergency_brake", mvOccupied->AlarmChainFlag);
|
|
dict->insert("brake_delay_flag", mvOccupied->BrakeDelayFlag);
|
|
dict->insert("brake_op_mode_flag", mvOccupied->BrakeOpModeFlag);
|
|
dict->insert("pipelock", mvOccupied->LockPipe);
|
|
// other controls
|
|
dict->insert("ca", mvOccupied->SecuritySystem.is_vigilance_blinking());
|
|
dict->insert("shp", mvOccupied->SecuritySystem.is_cabsignal_blinking());
|
|
dict->insert("distance_counter", m_distancecounter);
|
|
dict->insert("pantpress", std::abs(mvPantographUnit->PantPress));
|
|
dict->insert("universal3", InstrumentLightActive);
|
|
for (auto idx = 0; idx < ggUniversals.size(); idx++)
|
|
{
|
|
if (idx != 3)
|
|
{
|
|
dict->insert("universal" + std::to_string(idx), ggUniversals[idx].GetValue() > 0.5);
|
|
}
|
|
}
|
|
dict->insert("radio", mvOccupied->Radio);
|
|
dict->insert("radio_fuse", mvOccupied->RadioFuse);
|
|
dict->insert("radio_channel", RadioChannel());
|
|
dict->insert("radio_volume", m_radiovolume);
|
|
dict->insert("door_lock", mvOccupied->Doors.lock_enabled);
|
|
dict->insert("door_step", mvOccupied->Doors.step_enabled);
|
|
dict->insert("door_permit_left", mvOccupied->Doors.instances[side::left].open_permit);
|
|
dict->insert("door_permit_right", mvOccupied->Doors.instances[side::right].open_permit);
|
|
// movement data
|
|
dict->insert("velocity", std::abs(mvOccupied->Vel));
|
|
dict->insert("tractionforce", std::abs(mvOccupied->Ft));
|
|
dict->insert("slipping_wheels", mvOccupied->SlippingWheels);
|
|
dict->insert("sanding", mvOccupied->SandDose);
|
|
dict->insert("odometer", mvOccupied->DistCounter); // distance run in the session, km
|
|
dict->insert("odometer_total", mvOccupied->Odometer.km); // the vehicle's odometer, kept between the sessions
|
|
// electric current data
|
|
dict->insert("traction_voltage", std::abs(mvPantographUnit->PantographVoltage));
|
|
dict->insert("voltage", std::abs(mvControlled->EngineVoltage));
|
|
dict->insert("im", std::abs(mvControlled->Im));
|
|
dict->insert("fuse", mvControlled->FuseFlag);
|
|
dict->insert("epfuse", mvOccupied->EpFuse);
|
|
dict->insert("power_drawn", mvOccupied->EnergyMeter.first);
|
|
dict->insert("power_returned", mvOccupied->EnergyMeter.second);
|
|
|
|
// induction motor state data
|
|
std::array<char const *, 10> const TXTT{"fd", "fdt", "fdb", "pd", "pdt", "pdb", "itothv", "1", "2", "3"};
|
|
std::array<char const *, 10> const TXTC{"fr", "frt", "frb", "pr", "prt", "prb", "im", "vm", "ihv", "uhv"};
|
|
std::array<char const *, 10> const TXTD{"enrot", "nrot", "fill_des", "fill_real", "clutch_des", "clutch_real", "water_temp", "oil_press", "engine_temp", "retarder_fill"};
|
|
std::array<char const *, 7> const TXTP{"bc", "bp", "sp", "cp", "rp", "mass", "spring"};
|
|
char const *TXTB[2] = {"spring_active", "spring_shutoff"};
|
|
for (int j = 0; j < 10; ++j)
|
|
dict->insert("eimp_t_" + std::string(TXTT[j]), fEIMParams[0][j]);
|
|
for (int i = 0; i < 8; ++i)
|
|
{
|
|
auto const idx{std::to_string(i + 1)};
|
|
for (int j = 0; j < 10; ++j)
|
|
dict->insert("eimp_c" + idx + "_" + std::string(TXTC[j]), fEIMParams[i + 1][j]);
|
|
|
|
for (int j = 0; j < 10; ++j)
|
|
dict->insert("diesel_param_" + idx + "_" + std::string(TXTD[j]), fDieselParams[i + 1][j]);
|
|
|
|
dict->insert("eimp_c" + idx + "_ms", bMains[i]);
|
|
dict->insert("eimp_c" + idx + "_cv", fCntVol[i]);
|
|
dict->insert("eimp_c" + idx + "_fuse", bFuse[i]);
|
|
dict->insert("eimp_c" + idx + "_batt", bBatt[i]);
|
|
dict->insert("eimp_c" + idx + "_conv", bConv[i]);
|
|
dict->insert("eimp_c" + idx + "_heat", bHeat[i]);
|
|
|
|
dict->insert("eimp_u" + idx + "_pf", bPants[i][0]);
|
|
dict->insert("eimp_u" + idx + "_pr", bPants[i][1]);
|
|
dict->insert("eimp_u" + idx + "_comp_a", bComp[i][0]);
|
|
dict->insert("eimp_u" + idx + "_comp_w", bComp[i][1]);
|
|
}
|
|
|
|
dict->insert("compressors_no", (int)bCompressors.size());
|
|
for (int i = 0; i < bCompressors.size(); i++)
|
|
{
|
|
auto const idx{std::to_string(i + 1)};
|
|
dict->insert("compressors_" + idx + "_allow", std::get<0>(bCompressors[i]));
|
|
dict->insert("compressors_" + idx + "_work", std::get<1>(bCompressors[i]));
|
|
dict->insert("compressors_" + idx + "_car_no", std::get<2>(bCompressors[i]));
|
|
}
|
|
|
|
bool kier = DynamicObject->DirectionGet() * mvOccupied->CabOccupied > 0;
|
|
TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->CabOccupied < 0 ? end::rear : end::front, 4);
|
|
int in = 0;
|
|
while (p && in < 8)
|
|
{
|
|
if (p->MoverParameters->eimc[eimc_p_Pmax] > 1)
|
|
{
|
|
in++;
|
|
dict->insert("eimp_c" + std::to_string(in) + "_invno", p->MoverParameters->InvertersNo);
|
|
for (int j = 0; j < p->MoverParameters->InvertersNo; j++)
|
|
{
|
|
dict->insert("eimp_c" + std::to_string(in) + "_inv" + std::to_string(j + 1) + "_act", p->MoverParameters->Inverters[j].IsActive);
|
|
dict->insert("eimp_c" + std::to_string(in) + "_inv" + std::to_string(j + 1) + "_error", p->MoverParameters->Inverters[j].Error);
|
|
dict->insert("eimp_c" + std::to_string(in) + "_inv" + std::to_string(j + 1) + "_allow", p->MoverParameters->Inverters[j].Activate);
|
|
}
|
|
}
|
|
p = kier ? p->Next(4) : p->Prev(4);
|
|
}
|
|
for (int i = 0; i < 20; ++i)
|
|
{
|
|
for (int j = 0; j < 7; ++j)
|
|
{
|
|
dict->insert("eimp_pn" + std::to_string(i + 1) + "_" + TXTP[j], fPress[i][j]);
|
|
}
|
|
for (int j = 0; j < 2; ++j)
|
|
{
|
|
dict->insert("brakes_" + std::to_string(i + 1) + "_" + TXTB[j], bBrakes[i][j]);
|
|
}
|
|
}
|
|
// multi-unit state data
|
|
dict->insert("car_no", iCarNo);
|
|
dict->insert("power_no", iPowerNo);
|
|
dict->insert("unit_no", iUnitNo);
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
auto const caridx{std::to_string(i + 1)};
|
|
dict->insert("doors_" + caridx, bDoors[i][0]);
|
|
dict->insert("doors_l_" + caridx, bDoors[i][1]);
|
|
dict->insert("doors_r_" + caridx, bDoors[i][2]);
|
|
dict->insert("doorstep_l_" + caridx, bDoors[i][3]);
|
|
dict->insert("doorstep_r_" + caridx, bDoors[i][4]);
|
|
dict->insert("doors_no_" + caridx, iDoorNo[i]);
|
|
dict->insert("code_" + caridx, std::to_string(iUnits[i]) + cCode[i]);
|
|
dict->insert("car_name" + caridx, asCarName[i]);
|
|
dict->insert("slip_" + caridx, bSlip[i]);
|
|
}
|
|
// ai state data
|
|
auto const *vehicledriver{(DynamicObject->ctOwner != nullptr ? DynamicObject->ctOwner : DynamicObject->Mechanik)};
|
|
|
|
dict->insert("velocity_desired", vehicledriver->VelDesired);
|
|
dict->insert("velroad", vehicledriver->VelRoad);
|
|
dict->insert("vellimitlast", vehicledriver->VelLimitLast);
|
|
dict->insert("velsignallast", vehicledriver->VelSignalLast);
|
|
dict->insert("velsignalnext", vehicledriver->VelSignalNext);
|
|
dict->insert("velnext", vehicledriver->VelNext);
|
|
dict->insert("actualproximitydist", vehicledriver->ActualProximityDist);
|
|
// train data
|
|
vehicledriver->TrainTimetable().serialize(dict.get());
|
|
dict->insert("train_atpassengerstop", vehicledriver->IsAtPassengerStop);
|
|
dict->insert("train_length", vehicledriver->fLength);
|
|
// world state data
|
|
dict->insert("scenario", Global.SceneryFile);
|
|
dict->insert("hours", static_cast<int>(simulation::Time.data().wHour));
|
|
dict->insert("minutes", static_cast<int>(simulation::Time.data().wMinute));
|
|
dict->insert("seconds", static_cast<int>(simulation::Time.second()));
|
|
dict->insert("air_temperature", Global.AirTemperature);
|
|
dict->insert("light_level", Global.fLuminance - std::max(0.f, Global.Overcast - 1.f));
|
|
|
|
return dict;
|
|
}
|
|
|
|
TTrain::state_t TTrain::get_state() const
|
|
{
|
|
|
|
return {
|
|
btLampkaSHP.GetValue(),
|
|
btLampkaCzuwaka.GetValue(),
|
|
btLampkaRadioStop.GetValue(),
|
|
btLampkaOpory.GetValue(),
|
|
btLampkaWylSzybki.GetValue(),
|
|
btLampkaPrzekRozn.GetValue(),
|
|
btLampkaNadmSil.GetValue(),
|
|
btLampkaStyczn.GetValue(),
|
|
btLampkaPoslizg.GetValue(),
|
|
btLampkaNadmPrzetw.GetValue(),
|
|
btLampkaPrzetwOff.GetValue(),
|
|
btLampkaNadmSpr.GetValue(),
|
|
btLampkaNadmWent.GetValue(),
|
|
btLampkaWysRozr.GetValue(),
|
|
btLampkaOgrzewanieSkladu.GetValue(),
|
|
static_cast<std::uint8_t>(iCabn),
|
|
btHaslerBrakes.GetValue(),
|
|
btHaslerCurrent.GetValue(),
|
|
mvOccupied->SecuritySystem.is_beeping(),
|
|
btLampkaHVoltageB.GetValue(),
|
|
fTachoVelocity,
|
|
static_cast<float>(mvOccupied->Compressor),
|
|
static_cast<float>(mvOccupied->PipePress),
|
|
static_cast<float>(mvOccupied->BrakePress),
|
|
static_cast<float>(mvPantographUnit->PantPress),
|
|
fHVoltage,
|
|
{fHCurrent[mvControlled->TrainType & dt_EZT ? 0 : 1], fHCurrent[2], fHCurrent[3]},
|
|
ggLVoltage.GetValue(),
|
|
mvOccupied->DistCounter,
|
|
static_cast<std::uint8_t>(RadioChannel()),
|
|
btLampkaSpringBrakeActive.GetValue(),
|
|
btLampkaNapNastHam.GetValue(),
|
|
mvOccupied->DirActive > 0,
|
|
mvOccupied->DirActive < 0,
|
|
mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? side::right : side::left].open_permit,
|
|
mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? side::right : side::left].is_open,
|
|
mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? side::left : side::right].open_permit,
|
|
mvOccupied->Doors.instances[mvOccupied->CabOccupied < 0 ? side::left : side::right].is_open,
|
|
mvOccupied->Doors.step_enabled,
|
|
mvOccupied->Power24vIsAvailable,
|
|
0,
|
|
mvOccupied->LockPipe,
|
|
btLampkaRadioMessage.GetValue(),
|
|
};
|
|
}
|
|
|
|
bool TTrain::is_eztoer() const
|
|
{
|
|
|
|
return mvControlled->TrainType == dt_EZT && mvOccupied->BrakeSubsystem == TBrakeSubSystem::ss_ESt && mvControlled->Power24vIsAvailable == true && mvControlled->EpFuse == true &&
|
|
mvControlled->DirActive != 0; // od yB
|
|
}
|
|
|
|
// mover master controller to specified position
|
|
void TTrain::set_master_controller(double const Position)
|
|
{
|
|
|
|
auto positionchange{std::min<int>(static_cast<int>(Position), mvControlled->CoupledCtrl ? mvControlled->MainCtrlPosNo + mvControlled->ScndCtrlPosNo : mvControlled->MainCtrlPosNo) -
|
|
(mvControlled->CoupledCtrl ? mvControlled->MainCtrlPos + mvControlled->ScndCtrlPos : mvControlled->MainCtrlPos)};
|
|
while (positionchange < 0 && true == mvControlled->DecMainCtrl(1))
|
|
{
|
|
++positionchange;
|
|
}
|
|
while (positionchange > 0 && true == mvControlled->IncMainCtrl(1))
|
|
{
|
|
--positionchange;
|
|
}
|
|
}
|
|
|
|
// moves train brake lever to specified position, potentially emits switch sound if conditions are met
|
|
void TTrain::set_train_brake(double const Position)
|
|
{
|
|
|
|
auto const originalbrakeposition{static_cast<int>(100.0 * mvOccupied->fBrakeCtrlPos)};
|
|
mvOccupied->BrakeLevelSet(Position);
|
|
|
|
if (static_cast<int>(100.0 * mvOccupied->fBrakeCtrlPos) == originalbrakeposition)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// sound feedback if the lever movement activates one of the switches
|
|
if (true == is_eztoer() && false == ((originalbrakeposition / 100 == 0 || originalbrakeposition / 100 >= 5) && (mvOccupied->BrakeCtrlPos == 0 || mvOccupied->BrakeCtrlPos >= 5)) && dsbPneumaticSwitch)
|
|
{
|
|
dsbPneumaticSwitch->play();
|
|
}
|
|
}
|
|
|
|
void TTrain::zero_charging_train_brake()
|
|
{
|
|
using enum TBrakeHandle;
|
|
|
|
if (mvOccupied->BrakeCtrlPos == -1 && DynamicObject->Controller != AIdriver && Global.iFeedbackMode < 3 &&
|
|
(mvOccupied->BrakeHandle == FVel6 || mvOccupied->BrakeHandle == MHZ_EN57 || mvOccupied->BrakeHandle == MHZ_K8P))
|
|
{
|
|
// Odskakiwanie hamulce EP
|
|
set_train_brake(0);
|
|
}
|
|
}
|
|
|
|
void TTrain::set_train_brake_speed(TDynamicObject *Vehicle, int const Speed)
|
|
{
|
|
|
|
// visual feedback
|
|
// TODO: add setting indicator to vehicle class, for external lever/indicator
|
|
if (true == Vehicle->MoverParameters->BrakeDelaySwitch(Speed) && Vehicle == DynamicObject)
|
|
{
|
|
if (ggBrakeProfileCtrl.SubModel != nullptr)
|
|
{
|
|
ggBrakeProfileCtrl.UpdateValue((mvOccupied->BrakeDelayFlag & bdelay_R) != 0 ? 2.0 : static_cast<float>(mvOccupied->BrakeDelayFlag - 1), dsbSwitch);
|
|
}
|
|
if (ggBrakeProfileG.SubModel != nullptr)
|
|
{
|
|
ggBrakeProfileG.UpdateValue(mvOccupied->BrakeDelayFlag == bdelay_G ? 1.0 : 0.0, dsbSwitch);
|
|
}
|
|
if (ggBrakeProfileR.SubModel != nullptr)
|
|
{
|
|
ggBrakeProfileR.UpdateValue((mvOccupied->BrakeDelayFlag & bdelay_R) != 0 ? 1.0 : 0.0, dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::set_paired_open_motor_connectors_button(bool const State)
|
|
{
|
|
|
|
if (mvControlled->TrainType == dt_ET41 || mvControlled->TrainType == dt_ET42)
|
|
{
|
|
// crude implementation of the button affecting entire unit for multi-unit engines
|
|
// TODO: rework it into part of standard command propagation system
|
|
if (mvControlled->Couplers[end::front].Connected != nullptr && true == TestFlag(mvControlled->Couplers[end::front].CouplingFlag, coupling::permanent))
|
|
{
|
|
mvControlled->Couplers[end::front].Connected->StLinSwitchOff = State;
|
|
}
|
|
if (mvControlled->Couplers[end::rear].Connected != nullptr && true == TestFlag(mvControlled->Couplers[end::rear].CouplingFlag, coupling::permanent))
|
|
{
|
|
mvControlled->Couplers[end::rear].Connected->StLinSwitchOff = State;
|
|
}
|
|
}
|
|
}
|
|
|
|
// locates nearest vehicle belonging to the consist
|
|
TDynamicObject *TTrain::find_nearest_consist_vehicle(bool freefly, glm::vec3 pos) const
|
|
{
|
|
if (!freefly)
|
|
return DynamicObject;
|
|
|
|
auto couplerindex{-2}; // scan for vehicle, not any specific coupler
|
|
auto *vehicle{DynamicObject->ABuScanNearestObject(pos, DynamicObject->GetTrack(), 1, 1500, couplerindex)};
|
|
if (vehicle == nullptr)
|
|
vehicle = DynamicObject->ABuScanNearestObject(pos, DynamicObject->GetTrack(), -1, 1500, couplerindex);
|
|
// TBD, TODO: perform owner test for the located vehicle
|
|
return vehicle;
|
|
}
|
|
|
|
// command handlers
|
|
void TTrain::OnCommand_aidriverenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// on press
|
|
if (Train->DynamicObject->Mechanik == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (true == Train->DynamicObject->Mechanik->AIControllFlag)
|
|
{
|
|
// żeby nie trzeba było rozłączać dla zresetowania
|
|
Train->DynamicObject->Mechanik->TakeControl(false);
|
|
}
|
|
Train->DynamicObject->Mechanik->TakeControl(true);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_aidriverdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// on press
|
|
if (Command.action == GLFW_PRESS && Train->DynamicObject->Mechanik)
|
|
Train->DynamicObject->Mechanik->TakeControl(false);
|
|
}
|
|
|
|
auto const EU07_CONTROLLER_BASERETURNDELAY{0.5f};
|
|
auto const EU07_CONTROLLER_KEYBOARDETURNDELAY{1.5f};
|
|
|
|
void TTrain::OnCommand_jointcontrollerset(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// on press or hold
|
|
// value controls brake in range 0-0.5, master controller in range 0.5-1.0
|
|
if (Command.param1 >= 0.5)
|
|
{
|
|
Train->set_master_controller((Command.param1 * 2 - 1) *
|
|
(Train->mvControlled->CoupledCtrl ? Train->mvControlled->MainCtrlPosNo + Train->mvControlled->ScndCtrlPosNo : Train->mvControlled->MainCtrlPosNo));
|
|
Train->m_mastercontrollerinuse = true;
|
|
// when SplitEDPneumaticBrake is active the joint controller's negative range
|
|
// commands the dedicated dynamic-brake lever instead of the local pneumatic brake
|
|
if (Train->mvControlled->SplitEDPneumaticBrake)
|
|
{
|
|
Train->mvControlled->DynamicBrakeLevelSet(0.0);
|
|
}
|
|
else
|
|
{
|
|
Train->mvOccupied->LocalBrakePosA = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
auto const negativeRange{std::clamp(1.0 - Command.param1 * 2, 0.0, 1.0)};
|
|
if (Train->mvControlled->SplitEDPneumaticBrake)
|
|
{
|
|
// negative range of jointctrl drives only ED braking, local pneumatic brake stays untouched.
|
|
// snap to DBPN discrete stops so the lever animates step-by-step
|
|
auto const stepCount{std::max(1, Train->mvControlled->DynamicBrakeCtrlPosNo)};
|
|
auto const snapped{std::round(negativeRange * stepCount) / stepCount};
|
|
Train->mvControlled->DynamicBrakeLevelSet(snapped);
|
|
}
|
|
else
|
|
{
|
|
Train->mvOccupied->LocalBrakePosA = negativeRange;
|
|
}
|
|
if (Train->mvControlled->MainCtrlPowerPos() > 0)
|
|
{
|
|
Train->set_master_controller(Train->mvControlled->MainCtrlNoPowerPos());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// release
|
|
Train->m_mastercontrollerinuse = false;
|
|
Train->m_mastercontrollerreturndelay = EU07_CONTROLLER_BASERETURNDELAY; // NOTE: keyboard return delay is omitted for other input sources
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_mastercontrollerincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// on press or hold
|
|
auto const splitMode{Train->mvControlled->SplitEDPneumaticBrake};
|
|
// when SplitEDPneumaticBrake is true the joint controller's negative range maps
|
|
// to the dedicated dynamic-brake lever (DynamicBrakeCtrl) rather than to LocalBrake
|
|
auto const negativeRangeActive{splitMode ? Train->mvControlled->DynamicBrakeCtrlPos > 0.0 : Train->mvOccupied->LocalBrakePosA > 0.0};
|
|
if (Train->ggJointCtrl.SubModel != nullptr && negativeRangeActive)
|
|
{
|
|
if (splitMode)
|
|
{
|
|
OnCommand_DynamicBrakeControllerDecrease(Train, Command);
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
else
|
|
{
|
|
OnCommand_independentbrakedecrease(Train, Command);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Train->mvControlled->IncMainCtrl(1);
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
Train->m_mastercontrollerinuse = false;
|
|
Train->m_mastercontrollerreturndelay = EU07_CONTROLLER_KEYBOARDETURNDELAY + EU07_CONTROLLER_BASERETURNDELAY;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_mastercontrollerincreasefast(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// on press or hold
|
|
auto const splitMode{Train->mvControlled->SplitEDPneumaticBrake};
|
|
auto const negativeRangeActive{splitMode ? Train->mvControlled->DynamicBrakeCtrlPos > 0.0 : Train->mvOccupied->LocalBrakePosA > 0.0};
|
|
if (Train->ggJointCtrl.SubModel != nullptr && negativeRangeActive)
|
|
{
|
|
if (splitMode)
|
|
{
|
|
OnCommand_DynamicBrakeControllerDecreaseFast(Train, Command);
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
else
|
|
{
|
|
OnCommand_independentbrakedecreasefast(Train, Command);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Train->mvControlled->IncMainCtrl(Train->mvControlled->MainCtrlPosNo);
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// release
|
|
Train->m_mastercontrollerinuse = false;
|
|
Train->m_mastercontrollerreturndelay = EU07_CONTROLLER_KEYBOARDETURNDELAY + EU07_CONTROLLER_BASERETURNDELAY;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_mastercontrollerdecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// on press or hold
|
|
auto const splitMode{Train->mvControlled->SplitEDPneumaticBrake};
|
|
if (Train->ggJointCtrl.SubModel != nullptr && Train->mvControlled->IsMainCtrlNoPowerPos())
|
|
{
|
|
// negative range of jointctrl: ED brake when split, otherwise pneumatic local brake
|
|
if (splitMode)
|
|
{
|
|
OnCommand_DynamicBrakeControllerIncrease(Train, Command);
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
else
|
|
{
|
|
OnCommand_independentbrakeincrease(Train, Command);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Train->mvControlled->DecMainCtrl(1);
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
Train->m_mastercontrollerinuse = false;
|
|
Train->m_mastercontrollerreturndelay = EU07_CONTROLLER_KEYBOARDETURNDELAY + EU07_CONTROLLER_BASERETURNDELAY;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_mastercontrollerdecreasefast(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// on press or hold
|
|
auto const splitMode{Train->mvControlled->SplitEDPneumaticBrake};
|
|
if (Train->ggJointCtrl.SubModel != nullptr && Train->mvControlled->IsMainCtrlNoPowerPos())
|
|
{
|
|
if (splitMode)
|
|
{
|
|
OnCommand_DynamicBrakeControllerIncreaseFast(Train, Command);
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
else
|
|
{
|
|
OnCommand_independentbrakeincreasefast(Train, Command);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Train->mvControlled->DecMainCtrl(Train->mvControlled->MainCtrlPowerPos());
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// release
|
|
Train->m_mastercontrollerinuse = false;
|
|
Train->m_mastercontrollerreturndelay = EU07_CONTROLLER_KEYBOARDETURNDELAY + EU07_CONTROLLER_BASERETURNDELAY;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_mastercontrollerset(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// on press or hold
|
|
Train->set_master_controller(Command.param1);
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
else
|
|
{
|
|
// release
|
|
Train->m_mastercontrollerinuse = false;
|
|
Train->m_mastercontrollerreturndelay = EU07_CONTROLLER_BASERETURNDELAY; // NOTE: keyboard return delay is omitted for other input sources
|
|
}
|
|
}
|
|
void TTrain::OnCommand_DynamicBrakeControllerIncrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
return;
|
|
}
|
|
if (false == Train->mvControlled->SplitEDPneumaticBrake)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// step exactly one stop (1 / DBPN) per command, matching the discrete behaviour of jointctrl
|
|
Train->mvControlled->IncDynamicBrakeLevel(1.0f);
|
|
}
|
|
|
|
void TTrain::OnCommand_DynamicBrakeControllerIncreaseFast(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
if (false == Train->mvControlled->SplitEDPneumaticBrake)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Train->mvControlled->IncDynamicBrakeLevel(static_cast<float>(Train->mvControlled->DynamicBrakeCtrlPosNo));
|
|
}
|
|
|
|
void TTrain::OnCommand_DynamicBrakeControllerDecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
return;
|
|
}
|
|
if (false == Train->mvControlled->SplitEDPneumaticBrake)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// step exactly one stop (1 / DBPN) per command, matching the discrete behaviour of jointctrl
|
|
Train->mvControlled->DecDynamicBrakeLevel(1.0f);
|
|
}
|
|
|
|
void TTrain::OnCommand_DynamicBrakeControllerDecreaseFast(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
if (false == Train->mvControlled->SplitEDPneumaticBrake)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Train->mvControlled->DecDynamicBrakeLevel(static_cast<float>(Train->mvControlled->DynamicBrakeCtrlPosNo));
|
|
}
|
|
|
|
void TTrain::OnCommand_DynamicBrakeControllerSet(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
return;
|
|
}
|
|
if (false == Train->mvControlled->SplitEDPneumaticBrake)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// when input source uses raw 0..1 value, snap to nearest DBPN step
|
|
auto const target{std::clamp(Command.param1, 0.0, 1.0)};
|
|
auto const stepCount{std::max(1, Train->mvControlled->DynamicBrakeCtrlPosNo)};
|
|
auto const snapped{std::round(target * stepCount) / stepCount};
|
|
Train->mvControlled->DynamicBrakeLevelSet(snapped);
|
|
}
|
|
|
|
void TTrain::OnCommand_secondcontrollerincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvControlled->EngineType == TEngineType::DieselElectric && true == Train->mvControlled->ShuntModeAllow && true == Train->mvControlled->ShuntMode)
|
|
{
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
Train->mvControlled->AnPos = std::clamp(Train->mvControlled->AnPos + 0.025, 0.0, 1.0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// regular mode
|
|
// push or pushtoggle control type
|
|
if (Train->ggScndCtrl.is_push())
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// activate on press
|
|
Train->mvControlled->IncScndCtrl(1);
|
|
}
|
|
}
|
|
// toggle control type
|
|
else
|
|
{
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
Train->mvControlled->IncScndCtrl(1);
|
|
}
|
|
}
|
|
// HACK: potentially animate push or pushtoggle control
|
|
if (Train->ggScndCtrl.is_push())
|
|
{
|
|
auto const activeposition{1.f};
|
|
auto const neutralposition{Train->ggScndCtrl.is_toggle() ? 0.5f : 0.f};
|
|
Train->ggScndCtrl.UpdateValue(Command.action == GLFW_RELEASE ? neutralposition : activeposition, Train->dsbSwitch);
|
|
}
|
|
// potentially animate tempomat button, unless the cruise control has its own
|
|
if (Train->ggScndCtrlButton.is_push() && Train->mvControlled->ScndCtrlPos <= 1 && false == Train->mvControlled->IsSpeedCtrlSeparate())
|
|
{
|
|
Train->ggScndCtrlButton.UpdateValue(Command.action == GLFW_RELEASE ? 0.f : 1.f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_secondcontrollerincreasefast(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// on press or hold
|
|
if (Train->mvControlled->EngineType == TEngineType::DieselElectric && true == Train->mvControlled->ShuntMode)
|
|
{
|
|
Train->mvControlled->AnPos = 1.0;
|
|
}
|
|
else
|
|
{
|
|
Train->mvControlled->IncScndCtrl(2);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_notchingrelaytoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvOccupied->AutoRelayFlag)
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->AutoRelaySwitch(true);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
Train->mvOccupied->AutoRelaySwitch(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_tempomattoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggScndCtrlButton.is_push())
|
|
{
|
|
// impulse switch
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// just move the button(s) back to default position
|
|
// visual feedback
|
|
Train->ggScndCtrlButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
Train->ggScndCtrlOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
return;
|
|
}
|
|
// glfw_press
|
|
if (false == Train->mvControlled->IsSpeedCtrlEngaged())
|
|
{
|
|
// turn on if it's not active
|
|
Train->mvControlled->SpeedCtrlSwitch(true);
|
|
// visual feedback
|
|
Train->ggScndCtrlButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// otherwise turn off
|
|
Train->mvControlled->SpeedCtrlSwitch(false);
|
|
// visual feedback
|
|
if (Train->m_controlmapper.contains("tempomatoff_sw:"))
|
|
{
|
|
Train->ggScndCtrlOffButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
Train->ggScndCtrlButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// two-state switch
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (false == Train->mvControlled->IsSpeedCtrlEngaged())
|
|
{
|
|
// turn on
|
|
Train->mvControlled->SpeedCtrlSwitch(true);
|
|
// visual feedback
|
|
Train->ggScndCtrlButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
Train->mvControlled->SpeedCtrlSwitch(false);
|
|
// visual feedback
|
|
Train->ggScndCtrlButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_distancecounteractivate(TTrain *Train, command_data const &Command)
|
|
{
|
|
// NOTE: distance meter activation button is presumed to be of impulse type
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggDistanceCounterButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
// activate or start anew
|
|
if (Train->mvOccupied->isDoubleClickForMeasureNeeded)
|
|
{
|
|
// handler tempomatu dla podwojnego kliku
|
|
if (Train->trainLenghtMeasureTimer >= 0.f) // jesli zdazylismy w czasie sekundy
|
|
Train->m_distancecounter = 0.f; // rozpoczynamy pomiar
|
|
else
|
|
Train->trainLenghtMeasureTimer = Train->mvOccupied->DistanceCounterDoublePressPeriod; // odpalamy zegarek od nowa
|
|
}
|
|
else
|
|
{
|
|
// dla pojedynczego kliku
|
|
Train->m_distancecounter = 0.f;
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggDistanceCounterButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_mucurrentindicatorothersourceactivate(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->ggNextCurrentButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Current Indicator Source switch is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// turn on
|
|
Train->ShowNextCurrent = true;
|
|
// visual feedback
|
|
Train->ggNextCurrentButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// turn off
|
|
Train->ShowNextCurrent = false;
|
|
// visual feedback
|
|
Train->ggNextCurrentButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_secondcontrollerdecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvControlled->EngineType == TEngineType::DieselElectric && true == Train->mvControlled->ShuntMode)
|
|
{
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
Train->mvControlled->AnPos = std::clamp(Train->mvControlled->AnPos - 0.025, 0.0, 1.0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// regular mode
|
|
// push or pushtoggle control type
|
|
if (Train->ggScndCtrl.is_push())
|
|
{
|
|
// basic push control can't decrease state, but pushtoggle can
|
|
if (true == Train->ggScndCtrl.is_toggle() && Command.action == GLFW_PRESS)
|
|
{
|
|
// activate on press
|
|
Train->mvControlled->DecScndCtrl(1);
|
|
}
|
|
}
|
|
// toggle control type
|
|
else
|
|
{
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
Train->mvControlled->DecScndCtrl(1);
|
|
}
|
|
}
|
|
// HACK: potentially animate push or pushtoggle control
|
|
if (Train->ggScndCtrl.is_push())
|
|
{
|
|
auto const activeposition{Train->ggScndCtrl.is_toggle() ? 0.f : 1.f};
|
|
auto const neutralposition{Train->ggScndCtrl.is_toggle() ? 0.5f : 0.f};
|
|
Train->ggScndCtrl.UpdateValue(Command.action == GLFW_RELEASE ? neutralposition : activeposition, Train->dsbSwitch);
|
|
}
|
|
// potentially animate tempomat button, unless the cruise control has its own
|
|
if (Train->ggScndCtrlButton.is_push() && Train->mvControlled->ScndCtrlPos <= 1 && false == Train->mvControlled->IsSpeedCtrlSeparate())
|
|
{
|
|
if (Train->m_controlmapper.contains("tempomatoff_sw:"))
|
|
{
|
|
Train->ggScndCtrlOffButton.UpdateValue(Command.action == GLFW_RELEASE ? 0.f : 1.f, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
Train->ggScndCtrlButton.UpdateValue(Command.action == GLFW_RELEASE ? 0.f : 1.f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_secondcontrollerdecreasefast(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// on press or hold
|
|
if (Train->mvControlled->EngineType == TEngineType::DieselElectric && true == Train->mvControlled->ShuntMode)
|
|
{
|
|
Train->mvControlled->AnPos = 0.0;
|
|
}
|
|
else
|
|
{
|
|
Train->mvControlled->DecScndCtrl(2);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_secondcontrollerset(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
auto const targetposition{std::min<int>(static_cast<int>(Command.param1), Train->mvControlled->ScndCtrlPosNo)};
|
|
// HACK: potentially animate push or pushtoggle control
|
|
if (Train->ggScndCtrl.is_push())
|
|
{
|
|
auto const activeposition{Train->ggScndCtrl.is_toggle() ?
|
|
(targetposition < Train->mvControlled->ScndCtrlPos ? 0.f :
|
|
targetposition > Train->mvControlled->ScndCtrlPos ? 1.f :
|
|
Train->ggScndCtrl.GetDesiredValue()) : // leave the control in its current position if it hits the limit
|
|
targetposition == 0 ? 0.f :
|
|
1.f};
|
|
auto const neutralposition{Train->ggScndCtrl.is_toggle() ? 0.5f : 0.f};
|
|
Train->ggScndCtrl.UpdateValue(Command.action == GLFW_RELEASE ? neutralposition : activeposition, Train->dsbSwitch);
|
|
}
|
|
// update control value
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// on press or hold
|
|
while (targetposition < Train->mvControlled->GetVirtualScndPos() && true == Train->mvControlled->DecScndCtrl(1))
|
|
{
|
|
// all work is done in the header
|
|
}
|
|
while (targetposition > Train->mvControlled->GetVirtualScndPos() && true == Train->mvControlled->IncScndCtrl(1))
|
|
{
|
|
// all work is done in the header
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_independentbrakeincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
|
|
// when SplitEDPneumaticBrake is active the local brake key always operates
|
|
// the pneumatic local brake directly, never piggy-backing on the joint controller
|
|
auto const splitMode{Train->mvControlled->SplitEDPneumaticBrake};
|
|
auto const useStepped{Train->ggJointCtrl.SubModel != nullptr && !splitMode};
|
|
if (Train->mvOccupied->LocalBrake != TLocalBrake::ManualBrake)
|
|
{
|
|
if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->mvOccupied->MainCtrlPos > 0)
|
|
{
|
|
OnCommand_mastercontrollerdecrease(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
Train->mvOccupied->IncLocalBrakeLevel(useStepped ? 1 : static_cast<float>(Global.brake_speed * Command.time_delta * LocalBrakePosNo));
|
|
if (useStepped)
|
|
{
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_independentbrakeincreasefast(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
|
|
auto const splitMode{Train->mvControlled->SplitEDPneumaticBrake};
|
|
auto const useJointAnim{Train->ggJointCtrl.SubModel != nullptr && !splitMode};
|
|
if (Train->mvOccupied->LocalBrake != TLocalBrake::ManualBrake)
|
|
{
|
|
if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->mvOccupied->MainCtrlPos > 0)
|
|
{
|
|
OnCommand_mastercontrollerdecreasefast(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
Train->mvOccupied->IncLocalBrakeLevel(LocalBrakePosNo);
|
|
if (useJointAnim)
|
|
{
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_independentbrakedecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
|
|
auto const splitMode{Train->mvControlled->SplitEDPneumaticBrake};
|
|
auto const useStepped{Train->ggJointCtrl.SubModel != nullptr && !splitMode};
|
|
if (Train->mvOccupied->LocalBrake != TLocalBrake::ManualBrake
|
|
// Ra 1014-06: AI potrafi zahamować pomocniczym mimo jego braku - odhamować jakoś trzeba
|
|
// TODO: sort AI out so it doesn't do things it doesn't have equipment for
|
|
|| Train->mvOccupied->LocalBrakePosA > 0)
|
|
{
|
|
if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->mvOccupied->LocalBrakePosA == 0.0)
|
|
{
|
|
OnCommand_mastercontrollerincrease(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
Train->mvOccupied->DecLocalBrakeLevel(useStepped ? 1 : static_cast<float>(Global.brake_speed * Command.time_delta * LocalBrakePosNo));
|
|
if (useStepped)
|
|
{
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_independentbrakedecreasefast(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
|
|
auto const splitMode{Train->mvControlled->SplitEDPneumaticBrake};
|
|
auto const useJointAnim{Train->ggJointCtrl.SubModel != nullptr && !splitMode};
|
|
if (Train->mvOccupied->LocalBrake != TLocalBrake::ManualBrake
|
|
// Ra 1014-06: AI potrafi zahamować pomocniczym mimo jego braku - odhamować jakoś trzeba
|
|
// TODO: sort AI out so it doesn't do things it doesn't have equipment for
|
|
|| Train->mvOccupied->LocalBrakePosA > 0)
|
|
{
|
|
if (false == splitMode && Train->ggJointCtrl.SubModel != nullptr && Train->mvOccupied->LocalBrakePosA == 0.0)
|
|
{
|
|
OnCommand_mastercontrollerincreasefast(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
Train->mvOccupied->DecLocalBrakeLevel(LocalBrakePosNo);
|
|
if (useJointAnim)
|
|
{
|
|
Train->m_mastercontrollerinuse = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_independentbrakeset(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
|
|
Train->mvOccupied->LocalBrakePosA = std::clamp(Command.param1, 0.0, 1.0);
|
|
}
|
|
/*
|
|
Train->mvControlled->LocalBrakePos = (
|
|
std::round(
|
|
interpolate<double>(
|
|
0.0,
|
|
LocalBrakePosNo,
|
|
clamp(
|
|
Command.param1,
|
|
0.0, 1.0 ) ) ) );
|
|
*/
|
|
}
|
|
|
|
void TTrain::OnCommand_independentbrakebailoff(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (false == Command.freefly)
|
|
{
|
|
// TODO: check if this set of conditions can be simplified.
|
|
// it'd be more flexible to have an attribute indicating whether bail off position is supported
|
|
if (Train->mvControlled->TrainType != dt_EZT &&
|
|
(Train->mvControlled->EngineType == TEngineType::ElectricSeriesMotor || Train->mvControlled->EngineType == TEngineType::DieselElectric ||
|
|
Train->mvControlled->EngineType == TEngineType::ElectricInductionMotor) &&
|
|
Train->mvOccupied->BrakeCtrlPosNo > 0)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// press or hold
|
|
// visual feedback
|
|
Train->ggReleaserButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
Train->mvOccupied->BrakeReleaser(1);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggReleaserButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
|
|
Train->mvOccupied->BrakeReleaser(0);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// car brake handling, while in walk mode
|
|
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
|
|
if (vehicle != nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// press or hold
|
|
vehicle->MoverParameters->BrakeReleaser(1);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
vehicle->MoverParameters->BrakeReleaser(0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_universalbrakebutton1(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// press or hold
|
|
// visual feedback
|
|
Train->ggUniveralBrakeButton1.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
Train->mvOccupied->UniversalBrakeButton(0, 1);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggUniveralBrakeButton1.UpdateValue(0.0, Train->dsbSwitch);
|
|
|
|
Train->mvOccupied->UniversalBrakeButton(0, 0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_universalbrakebutton2(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// press or hold
|
|
// visual feedback
|
|
Train->ggUniveralBrakeButton2.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
Train->mvOccupied->UniversalBrakeButton(1, 1);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggUniveralBrakeButton2.UpdateValue(0.0, Train->dsbSwitch);
|
|
|
|
Train->mvOccupied->UniversalBrakeButton(1, 0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_universalbrakebutton3(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// press or hold
|
|
// visual feedback
|
|
Train->ggUniveralBrakeButton3.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
Train->mvOccupied->UniversalBrakeButton(2, 1);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggUniveralBrakeButton3.UpdateValue(0.0, Train->dsbSwitch);
|
|
|
|
Train->mvOccupied->UniversalBrakeButton(2, 0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakeincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_REPEAT && Train->mvOccupied->BrakeHandle == TBrakeHandle::FV4a)
|
|
Train->mvOccupied->BrakeLevelAdd(Global.brake_speed * Command.time_delta * Train->mvOccupied->BrakeCtrlPosNo);
|
|
else if (Command.action == GLFW_PRESS && Train->mvOccupied->BrakeHandle != TBrakeHandle::FV4a)
|
|
Train->set_train_brake(Train->mvOccupied->fBrakeCtrlPos + Global.fBrakeStep);
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakedecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_REPEAT && Train->mvOccupied->BrakeHandle == TBrakeHandle::FV4a)
|
|
Train->mvOccupied->BrakeLevelAdd(-Global.brake_speed * Command.time_delta * Train->mvOccupied->BrakeCtrlPosNo);
|
|
else if (Command.action == GLFW_PRESS && Train->mvOccupied->BrakeHandle != TBrakeHandle::FV4a)
|
|
Train->set_train_brake(Train->mvOccupied->fBrakeCtrlPos - Global.fBrakeStep);
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
Train->zero_charging_train_brake();
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakeset(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// press or hold
|
|
Train->mvOccupied->BrakeLevelSet(std::lerp(Train->mvOccupied->Handle->GetPos(bh_MIN), Train->mvOccupied->Handle->GetPos(bh_MAX), std::clamp(Command.param1, 0.0, 1.0)));
|
|
}
|
|
else
|
|
{
|
|
// release
|
|
Train->zero_charging_train_brake();
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakecharging(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// press or hold
|
|
Train->set_train_brake(-1);
|
|
}
|
|
else
|
|
{
|
|
// release
|
|
Train->zero_charging_train_brake();
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakerelease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->set_train_brake(0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakefirstservice(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->set_train_brake(1);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakeservice(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->set_train_brake(Train->mvOccupied->BrakeCtrlPosNo / 2 + (Train->mvOccupied->BrakeHandle == TBrakeHandle::FV4a ? 1 : 0));
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakefullservice(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->set_train_brake(Train->mvOccupied->BrakeCtrlPosNo - 1);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakehandleoff(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->set_train_brake(Train->mvOccupied->Handle->GetPos(bh_NP));
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakeemergency(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->set_train_brake(Train->mvOccupied->Handle->GetPos(bh_EB));
|
|
/*
|
|
if( Train->mvOccupied->BrakeCtrlPosNo <= 0.1 ) {
|
|
// hamulec bezpieczeństwa dla wagonów
|
|
Train->mvOccupied->RadioStopFlag = true;
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakebasepressureincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
|
|
if (Train->mvOccupied->BrakeHandle == TBrakeHandle::FV4a)
|
|
{
|
|
Train->mvOccupied->BrakeCtrlPos2 = std::clamp(Train->mvOccupied->BrakeCtrlPos2 - 0.01, -1.5, 2.0);
|
|
}
|
|
else
|
|
{
|
|
Train->mvOccupied->BrakeLevelAdd(0.01);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakebasepressuredecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
|
|
if (Train->mvOccupied->BrakeHandle == TBrakeHandle::FV4a)
|
|
{
|
|
Train->mvOccupied->BrakeCtrlPos2 = std::clamp(Train->mvOccupied->BrakeCtrlPos2 + 0.01, -1.5, 2.0);
|
|
}
|
|
else
|
|
{
|
|
Train->mvOccupied->BrakeLevelAdd(-0.01);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakebasepressurereset(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->mvOccupied->BrakeCtrlPos2 = 0;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakeoperationtoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
auto const *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
vehicle->MoverParameters->Hamulec->SetBrakeStatus(vehicle->MoverParameters->Hamulec->GetBrakeStatus() ^ b_dmg);
|
|
// the brake is the player's now, the wagon inspector won't put it back on its own
|
|
vehicle->MoverParameters->BrakeCutOutByInspector = false;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_manualbrakeincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
|
|
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (vehicle->MoverParameters->LocalBrake == TLocalBrake::ManualBrake || vehicle->MoverParameters->MBrake == true)
|
|
{
|
|
|
|
vehicle->MoverParameters->IncManualBrakeLevel(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_manualbrakedecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
|
|
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (vehicle->MoverParameters->LocalBrake == TLocalBrake::ManualBrake || vehicle->MoverParameters->MBrake == true)
|
|
{
|
|
|
|
vehicle->MoverParameters->DecManualBrakeLevel(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_alarmchaintoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
if (false == Train->mvOccupied->AlarmChainFlag)
|
|
{
|
|
OnCommand_alarmchainenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_alarmchaindisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_alarmchainenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
// pull
|
|
Train->mvOccupied->AlarmChainSwitch(true);
|
|
// visual feedback
|
|
Train->ggAlarmChain.UpdateValue(1.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_alarmchaindisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
// release
|
|
Train->mvOccupied->AlarmChainSwitch(false);
|
|
// visual feedback
|
|
Train->ggAlarmChain.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_wheelspinbrakeactivate(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
if (Train->ggAntiSlipButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Wheelspin Brake button is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Train->mvOccupied->BrakeSystem != TBrakeSystem::ElectroPneumatic)
|
|
{
|
|
// standard behaviour
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggAntiSlipButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
// NOTE: system activation is (repeatedly) done in the train update routine
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggAntiSlipButton.UpdateValue(0.0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// electro-pneumatic, custom case
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggAntiSlipButton.UpdateValue(1.0, Train->dsbPneumaticSwitch);
|
|
|
|
// the EP fuse is the cab car's (Ctrl+Z switches mvOccupied's), checked by SwitchEPBrake with the rest of
|
|
// the control's supply
|
|
if (Train->mvOccupied->BrakeHandle == TBrakeHandle::St113)
|
|
{
|
|
Train->mvOccupied->SwitchEPBrake(1);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggAntiSlipButton.UpdateValue(0.0);
|
|
|
|
Train->mvOccupied->SwitchEPBrake(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_sandboxactivate(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
if (Train->ggSandButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Sandbox activation button is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggSandButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
Train->mvControlled->SandboxManual(true);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggSandButton.UpdateValue(0.0);
|
|
|
|
Train->mvControlled->SandboxManual(false);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_autosandboxtoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvOccupied->SandDoseAutoAllow)
|
|
{
|
|
// turn on
|
|
OnCommand_autosandboxactivate(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_autosandboxdeactivate(Train, Command);
|
|
}
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_autosandboxactivate(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvOccupied->SandboxAutoAllow(true);
|
|
Train->ggAutoSandButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_autosandboxdeactivate(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvOccupied->SandboxAutoAllow(false);
|
|
Train->ggAutoSandButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_epbrakecontrolenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
auto const istoggle{(static_cast<int>(Train->ggEPFuseButton.type()) & static_cast<int>(TGaugeType::toggle)) != 0};
|
|
// command only works for bistable switch
|
|
if (Command.action == GLFW_PRESS && istoggle)
|
|
{
|
|
if (Train->mvOccupied->EpFuseSwitch(true))
|
|
{
|
|
// audio feedback
|
|
if (Train->dsbPneumaticSwitch)
|
|
{
|
|
Train->dsbPneumaticSwitch->play();
|
|
}
|
|
Train->ggEPFuseButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_epbrakecontroldisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
auto const istoggle{(static_cast<int>(Train->ggEPFuseButton.type()) & static_cast<int>(TGaugeType::toggle)) != 0};
|
|
// command only works for bistable switch
|
|
if (Command.action == GLFW_PRESS && istoggle)
|
|
{
|
|
if (Train->mvOccupied->EpFuseSwitch(false))
|
|
{
|
|
Train->ggEPFuseButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_epbrakecontroltoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto const ispush{(static_cast<int>(Train->ggEPFuseButton.type()) & static_cast<int>(TGaugeType::push)) != 0};
|
|
auto const istoggle{(static_cast<int>(Train->ggEPFuseButton.type()) & static_cast<int>(TGaugeType::toggle)) != 0};
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (istoggle)
|
|
{
|
|
// switch state
|
|
if (false == Train->mvOccupied->EpFuse)
|
|
{
|
|
// turn on
|
|
// audio feedback
|
|
if (Train->mvOccupied->EpFuseSwitch(true) && Train->dsbPneumaticSwitch)
|
|
{
|
|
Train->dsbPneumaticSwitch->play();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
Train->mvOccupied->EpFuseSwitch(false);
|
|
}
|
|
}
|
|
else if (ispush)
|
|
{
|
|
// potentially turn on
|
|
// audio feedback
|
|
if (Train->mvOccupied->EpFuseSwitch(true) && Train->dsbPneumaticSwitch)
|
|
{
|
|
Train->dsbPneumaticSwitch->play();
|
|
}
|
|
}
|
|
// visual feedback
|
|
Train->ggEPFuseButton.UpdateValue(ispush ? 1.0f : // push or pushtoggle
|
|
Train->mvOccupied->EpFuse ? 1.0f :
|
|
0.0f, // toggle
|
|
Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE && ispush)
|
|
{
|
|
// return the switch to neutral position
|
|
Train->ggEPFuseButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakeoperationmodeincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Command.action == GLFW_PRESS && (Train->mvOccupied->BrakeOpModeFlag << 1 & Train->mvOccupied->BrakeOpModes) != 0)
|
|
{
|
|
// next mode
|
|
Train->mvOccupied->BrakeOpModeFlag <<= 1;
|
|
// visual feedback
|
|
Train->ggBrakeOperationModeCtrl.UpdateValue(Train->mvOccupied->BrakeOpModeFlag > 0 ? static_cast<float>(std::log2(Train->mvOccupied->BrakeOpModeFlag)) : 0); // audio fallback
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_trainbrakeoperationmodedecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Command.action == GLFW_PRESS && (Train->mvOccupied->BrakeOpModeFlag >> 1 & Train->mvOccupied->BrakeOpModes) != 0)
|
|
{
|
|
// previous mode
|
|
Train->mvOccupied->BrakeOpModeFlag >>= 1;
|
|
// visual feedback
|
|
Train->ggBrakeOperationModeCtrl.UpdateValue(Train->mvOccupied->BrakeOpModeFlag > 0 ? static_cast<float>(std::log2(Train->mvOccupied->BrakeOpModeFlag)) : 0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_brakeactingspeedincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if ((vehicle->MoverParameters->BrakeDelayFlag & bdelay_M) != 0)
|
|
{
|
|
// can't speed it up any more than this
|
|
return;
|
|
}
|
|
auto const fasterbrakesetting = vehicle->MoverParameters->BrakeDelayFlag < bdelay_R ? vehicle->MoverParameters->BrakeDelayFlag << 1 : vehicle->MoverParameters->BrakeDelayFlag | bdelay_M;
|
|
|
|
Train->set_train_brake_speed(vehicle, fasterbrakesetting);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_brakeactingspeeddecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (vehicle->MoverParameters->BrakeDelayFlag == bdelay_G)
|
|
{
|
|
// can't slow it down any more than this
|
|
return;
|
|
}
|
|
auto const slowerbrakesetting = vehicle->MoverParameters->BrakeDelayFlag < bdelay_M ? vehicle->MoverParameters->BrakeDelayFlag >> 1 : vehicle->MoverParameters->BrakeDelayFlag ^ bdelay_M;
|
|
|
|
Train->set_train_brake_speed(vehicle, slowerbrakesetting);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_brakeactingspeedsetcargo(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Train->set_train_brake_speed(vehicle, bdelay_G);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_brakeactingspeedsetpassenger(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Train->set_train_brake_speed(vehicle, bdelay_P);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_brakeactingspeedsetrapid(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Train->set_train_brake_speed(vehicle, bdelay_R);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_brakeloadcompensationincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
|
|
if (vehicle != nullptr)
|
|
{
|
|
vehicle->MoverParameters->IncBrakeMult();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_brakeloadcompensationdecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)};
|
|
if (vehicle != nullptr)
|
|
{
|
|
vehicle->MoverParameters->DecBrakeMult();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_mubrakingindicatortoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->ggSignallingButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Braking Indicator switch is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
if (Train->mvControlled->TrainType != dt_EZT)
|
|
{
|
|
//
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvControlled->Signalling)
|
|
{
|
|
// turn on
|
|
Train->mvControlled->Signalling = true;
|
|
// visual feedback
|
|
Train->ggSignallingButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
Train->mvControlled->Signalling = false;
|
|
// visual feedback
|
|
Train->ggSignallingButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_wiperswitchincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvOccupied->wiperSwitchPos++;
|
|
if (Train->mvOccupied->wiperSwitchPos > Train->mvOccupied->WiperListSize - 1)
|
|
Train->mvOccupied->wiperSwitchPos = Train->mvOccupied->WiperListSize - 1;
|
|
|
|
// Visual feedback
|
|
Train->ggWiperSw.UpdateValue(static_cast<float>(Train->mvOccupied->wiperSwitchPos), Train->dsbSwitch);
|
|
}
|
|
}
|
|
void TTrain::OnCommand_wiperswitchdecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvOccupied->wiperSwitchPos--;
|
|
if (Train->mvOccupied->wiperSwitchPos < 0)
|
|
Train->mvOccupied->wiperSwitchPos = 0;
|
|
|
|
// visual feedback
|
|
Train->ggWiperSw.UpdateValue(static_cast<float>(Train->mvOccupied->wiperSwitchPos), Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_reverserincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
// HACK: master controller position isn't set in occupied vehicle in E(D)MUs
|
|
// so we do a manual check in relevant vehicle here
|
|
if (false == Train->mvControlled->EIMDirectionChangeAllow())
|
|
{
|
|
return;
|
|
}
|
|
|
|
// aktualizacja skrajnych pojazdów w składzie
|
|
if (Train->mvOccupied->DirectionForward() && Train->mvOccupied->DirActive && Train->DynamicObject->Mechanik)
|
|
{
|
|
|
|
Train->DynamicObject->Mechanik->DirectionChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_reverserdecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
// HACK: master controller position isn't set in occupied vehicle in E(D)MUs
|
|
// so we do a manual check in relevant vehicle here
|
|
if (false == Train->mvControlled->EIMDirectionChangeAllow())
|
|
{
|
|
return;
|
|
}
|
|
|
|
// aktualizacja skrajnych pojazdów w składzie
|
|
if (Train->mvOccupied->DirectionBackward() && Train->mvOccupied->DirActive && Train->DynamicObject->Mechanik)
|
|
{
|
|
|
|
Train->DynamicObject->Mechanik->DirectionChange();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_reverserforwardhigh(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
// HACK: master controller position isn't set in occupied vehicle in E(D)MUs
|
|
// so we do a manual check in relevant vehicle here
|
|
if (false == Train->mvControlled->EIMDirectionChangeAllow())
|
|
{
|
|
return;
|
|
}
|
|
|
|
// HACK: try to move the reverser one position back, in case it's set to "high forward"
|
|
OnCommand_reverserdecrease(Train, Command);
|
|
|
|
if (Train->mvOccupied->DirActive < 1)
|
|
{
|
|
|
|
while (Train->mvOccupied->DirActive < 1 && true == Train->mvOccupied->DirectionForward())
|
|
{
|
|
// all work is done in the header
|
|
}
|
|
// aktualizacja skrajnych pojazdów w składzie
|
|
if (Train->mvOccupied->DirActive == 1 && Train->DynamicObject->Mechanik)
|
|
{
|
|
|
|
Train->DynamicObject->Mechanik->DirectionChange();
|
|
}
|
|
}
|
|
OnCommand_reverserincrease(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_reverserforward(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
// HACK: master controller position isn't set in occupied vehicle in E(D)MUs
|
|
// so we do a manual check in relevant vehicle here
|
|
if (false == Train->mvControlled->EIMDirectionChangeAllow())
|
|
{
|
|
return;
|
|
}
|
|
|
|
// HACK: try to move the reverser one position back, in case it's set to "high forward"
|
|
// OnCommand_reverserdecrease( Train, Command );
|
|
// visual feedback
|
|
Train->ggDirForwardButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
if (Train->mvOccupied->DirActive == 0)
|
|
{
|
|
|
|
while (Train->mvOccupied->DirActive < 1 && true == Train->mvOccupied->DirectionForward())
|
|
{
|
|
// all work is done in the header
|
|
}
|
|
// aktualizacja skrajnych pojazdów w składzie
|
|
if (Train->mvOccupied->DirActive == 1 && Train->DynamicObject->Mechanik)
|
|
{
|
|
|
|
Train->DynamicObject->Mechanik->DirectionChange();
|
|
}
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggDirForwardButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_reverserneutral(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
// HACK: master controller position isn't set in occupied vehicle in E(D)MUs
|
|
// so we do a manual check in relevant vehicle here
|
|
if (false == Train->mvControlled->EIMDirectionChangeAllow())
|
|
{
|
|
return;
|
|
}
|
|
// visual feedback
|
|
Train->ggDirNeutralButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
while (Train->mvOccupied->DirActive < 0 && true == Train->mvOccupied->DirectionForward())
|
|
{
|
|
// all work is done in the header
|
|
}
|
|
while (Train->mvOccupied->DirActive > 0 && true == Train->mvOccupied->DirectionBackward())
|
|
{
|
|
// all work is done in the header
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggDirNeutralButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_reverserbackward(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
// HACK: master controller position isn't set in occupied vehicle in E(D)MUs
|
|
// so we do a manual check in relevant vehicle here
|
|
if (false == Train->mvControlled->EIMDirectionChangeAllow())
|
|
{
|
|
return;
|
|
}
|
|
Train->ggDirBackwardButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
if (Train->mvOccupied->DirActive == 0)
|
|
{
|
|
|
|
while (Train->mvOccupied->DirActive > -1 && true == Train->mvOccupied->DirectionBackward())
|
|
{
|
|
// all work is done in the header
|
|
}
|
|
// aktualizacja skrajnych pojazdów w składzie
|
|
if (Train->mvOccupied->DirActive == -1 && Train->DynamicObject->Mechanik)
|
|
{
|
|
|
|
Train->DynamicObject->Mechanik->DirectionChange();
|
|
}
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggDirBackwardButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_alerteracknowledge(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggSecurityResetButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
if (Train->mvOccupied->TrainType == dt_EZT || Train->mvOccupied->DirActive != 0)
|
|
Train->mvOccupied->SecuritySystem.acknowledge_press();
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggSecurityResetButton.UpdateValue(0.0);
|
|
|
|
if (Train->mvOccupied->TrainType == dt_EZT || Train->mvOccupied->DirActive != 0)
|
|
Train->mvOccupied->SecuritySystem.acknowledge_release();
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_cabsignalacknowledge(TTrain *Train, command_data const &Command)
|
|
{
|
|
// TODO: visual feedback
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (Train->mvOccupied->SecuritySystem.has_separate_acknowledge())
|
|
{
|
|
Train->mvOccupied->SecuritySystem.cabsignal_reset();
|
|
Train->ggSHPResetButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
Train->ggSHPResetButton.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_batterytoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Train->allowBatteryToggle || Command.action != GLFW_REPEAT)
|
|
{
|
|
// keep the switch from flipping back and forth if key is held down
|
|
if (false == Train->mvOccupied->Power24vIsAvailable)
|
|
{
|
|
// turn on
|
|
OnCommand_batteryenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_batterydisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_batteryenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (!Train->mvOccupied->isBatteryButtonImpulse)
|
|
{ // regular button behavior
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggBatteryButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
Train->ggBatteryOnButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
|
|
Train->mvOccupied->BatterySwitch(true);
|
|
Train->allowBatteryToggle = false;
|
|
// side-effects
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
Train->Dynamic()->SetLights();
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
if (Train->ggBatteryButton.type() == TGaugeType::push)
|
|
{
|
|
// return the switch to neutral position
|
|
Train->ggBatteryButton.UpdateValue(0.5f);
|
|
}
|
|
Train->ggBatteryOnButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
Train->allowBatteryToggle = true;
|
|
}
|
|
}
|
|
else // impulse button behavior
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (Train->mvOccupied->shouldHoldBatteryButton)
|
|
{
|
|
// jesli przycisk trzeba przytrzymac
|
|
Train->ggBatteryButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
Train->ggBatteryOnButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
Train->fBatteryTimer = Train->mvOccupied->BatteryButtonHoldTime; // start timer
|
|
}
|
|
else
|
|
{
|
|
// jesli przycisk dziala od razu
|
|
Train->mvOccupied->BatterySwitch(true);
|
|
Train->allowBatteryToggle = false;
|
|
// side-effects
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
Train->Dynamic()->SetLights();
|
|
}
|
|
|
|
// visual feedback
|
|
Train->ggBatteryButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
Train->ggBatteryOnButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggBatteryButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
Train->ggBatteryOnButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
Train->fBatteryTimer = -1.f; //
|
|
Train->allowBatteryToggle = true;
|
|
Train->mvOccupied->batterySwAlreadyFired = false;
|
|
}
|
|
else if (Command.action == GLFW_REPEAT && Train->mvOccupied->shouldHoldBatteryButton)
|
|
{
|
|
// trzymamy przycisk
|
|
if (Train->fBatteryTimer <= 0.0 && Train->mvOccupied->Battery == false && !Train->mvOccupied->batterySwAlreadyFired)
|
|
{
|
|
Train->mvOccupied->BatterySwitch(true);
|
|
Train->mvOccupied->batterySwAlreadyFired = true;
|
|
|
|
// side-effects
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
Train->Dynamic()->SetLights();
|
|
}
|
|
Train->allowBatteryToggle = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_batterydisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (!Train->mvOccupied->isBatteryButtonImpulse)
|
|
{ // regular button behavior
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggBatteryButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
Train->ggBatteryOffButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
|
|
Train->mvOccupied->BatterySwitch(false);
|
|
|
|
// side-effects
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
Train->Dynamic()->SetLights();
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
if (Train->ggBatteryButton.type() == TGaugeType::push)
|
|
{
|
|
// return the switch to neutral position
|
|
Train->ggBatteryButton.UpdateValue(0.5f);
|
|
}
|
|
Train->ggBatteryOffButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else // impulse button behavior
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (Train->mvOccupied->shouldHoldBatteryButton)
|
|
{
|
|
// jesli przycisk trzeba przytrzymac
|
|
Train->ggBatteryButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
Train->ggBatteryOffButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
Train->fBatteryTimer = Train->mvOccupied->BatteryButtonHoldTime; // start timer
|
|
}
|
|
else
|
|
{
|
|
// jesli przycisk dziala od razu
|
|
Train->mvOccupied->BatterySwitch(false);
|
|
Train->allowBatteryToggle = false;
|
|
|
|
// side-effects
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
Train->Dynamic()->SetLights();
|
|
}
|
|
// visual feedback
|
|
Train->ggBatteryButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
Train->ggBatteryOffButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggBatteryButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
Train->ggBatteryOffButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
Train->allowBatteryToggle = true;
|
|
Train->mvOccupied->batterySwAlreadyFired = false;
|
|
}
|
|
else if (Command.action == GLFW_REPEAT && Train->mvOccupied->shouldHoldBatteryButton)
|
|
{
|
|
// trzymamy przycisk
|
|
if (Train->fBatteryTimer <= 0.0 && Train->mvOccupied->Battery == true && !Train->mvOccupied->batterySwAlreadyFired)
|
|
{
|
|
Train->mvOccupied->BatterySwitch(false);
|
|
Train->mvOccupied->batterySwAlreadyFired = true;
|
|
|
|
// side-effects
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
Train->Dynamic()->SetLights();
|
|
}
|
|
Train->allowBatteryToggle = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_cabactivationtoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_REPEAT)
|
|
{
|
|
// keep the switch from flipping back and forth if key is held down
|
|
if (0 == Train->mvOccupied->CabActive)
|
|
{
|
|
// turn on
|
|
OnCommand_cabactivationenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_cabactivationdisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_cabactivationenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
if (Train->ggCabActivationButton.type() == TGaugeType::push)
|
|
{
|
|
Train->ggCabActivationButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
}
|
|
|
|
Train->mvOccupied->CabActivisation();
|
|
|
|
// side-effects
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
Train->Dynamic()->SetLights();
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE && Train->ggCabActivationButton.type() == TGaugeType::push)
|
|
{
|
|
// return the switch to neutral position
|
|
Train->ggCabActivationButton.UpdateValue(0.5f);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_cabactivationdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
// TBD, TODO: ewentualnie zablokować z FIZ, np. w samochodach się nie odłącza akumulatora
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
if (Train->ggCabActivationButton.type() == TGaugeType::push)
|
|
{
|
|
Train->ggCabActivationButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
}
|
|
|
|
Train->mvOccupied->CabDeactivisation();
|
|
if (Train->mvOccupied->LightsPosNo > 0 && Train->mvOccupied->InactiveCabFlag & activation::redmarkers)
|
|
{
|
|
Train->Dynamic()->SetLights();
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE && Train->ggCabActivationButton.type() == TGaugeType::push)
|
|
{
|
|
// return the switch to neutral position
|
|
Train->ggCabActivationButton.UpdateValue(0.5f);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographtogglefront(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// HACK: presence of pantograph selector prevents manual operation of the individual valves
|
|
if (Train->m_controlmapper.contains("pantselect_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const &pantograph{Train->mvPantographUnit->Pantographs[end::front]};
|
|
auto const state{pantograph.valve.is_enabled || pantograph.is_active}; // fallback for impulse switches
|
|
if (state)
|
|
{
|
|
OnCommand_pantographlowerfront(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_pantographraisefront(Train, Command);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// impulse switches return automatically to neutral position
|
|
if (Train->mvOccupied->PantSwitchType == "impulse")
|
|
{
|
|
auto const ismanual{Train->iCabn == 0};
|
|
Train->mvOccupied->OperatePantographValve(end::front, operation_t::none, ismanual ? range_t::local : range_t::consist);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographtogglerear(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// HACK: presence of pantograph selector prevents manual operation of the individual valves
|
|
if (Train->m_controlmapper.contains("pantselect_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const &pantograph{Train->mvPantographUnit->Pantographs[end::rear]};
|
|
auto const state{pantograph.valve.is_enabled || pantograph.is_active}; // fallback for impulse switches
|
|
if (state)
|
|
{
|
|
OnCommand_pantographlowerrear(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_pantographraiserear(Train, Command);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// impulse switches return automatically to neutral position
|
|
if (Train->mvOccupied->PantSwitchType == "impulse")
|
|
{
|
|
auto const ismanual{Train->iCabn == 0};
|
|
Train->mvOccupied->OperatePantographValve(end::rear, operation_t::none, ismanual ? range_t::local : range_t::consist);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographraisefront(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// HACK: presence of pantograph selector prevents manual operation of the individual valves
|
|
if (Train->m_controlmapper.contains("pantselect_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
// prevent operation without submodel outside of engine compartment
|
|
if (Train->iCabn != 0 && false == Train->m_controlmapper.contains("pantfront_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
// HACK: don't propagate pantograph commands issued from engine compartment, these are presumed to be manually moved levers
|
|
auto const ismanual{Train->iCabn == 0};
|
|
Train->mvOccupied->OperatePantographValve(end::front, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::enable_on : operation_t::enable,
|
|
ismanual ? range_t::local : range_t::consist);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// NOTE: bit of a hax here, we're reusing button reset routine so we don't need a copy in every branch
|
|
OnCommand_pantographtogglefront(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographraiserear(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// HACK: presence of pantograph selector prevents manual operation of the individual valves
|
|
if (Train->m_controlmapper.contains("pantselect_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
// prevent operation without submodel outside of engine compartment
|
|
if (Train->iCabn != 0 && false == Train->m_controlmapper.contains("pantrear_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
// HACK: don't propagate pantograph commands issued from engine compartment, these are presumed to be manually moved levers
|
|
auto const ismanual{Train->iCabn == 0};
|
|
Train->mvOccupied->OperatePantographValve(end::rear, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::enable_on : operation_t::enable,
|
|
ismanual ? range_t::local : range_t::consist);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// NOTE: bit of a hax here, we're reusing button reset routine so we don't need a copy in every branch
|
|
OnCommand_pantographtogglerear(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographlowerfront(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// HACK: presence of pantograph selector prevents manual operation of the individual valves
|
|
if (Train->m_controlmapper.contains("pantselect_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
// prevent operation without submodel outside of engine compartment
|
|
if (Train->iCabn != 0 && false == Train->m_controlmapper.contains(Train->mvOccupied->PantSwitchType == "impulse" ? "pantfrontoff_sw:" : "pantfront_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
// HACK: don't propagate pantograph commands issued from engine compartment, these are presumed to be manually moved levers
|
|
auto const ismanual{Train->iCabn == 0};
|
|
Train->mvOccupied->OperatePantographValve(end::front, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::disable_on : operation_t::disable,
|
|
ismanual ? range_t::local : range_t::consist);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// NOTE: bit of a hax here, we're reusing button reset routine so we don't need a copy in every branch
|
|
OnCommand_pantographtogglefront(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographlowerrear(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// HACK: presence of pantograph selector prevents manual operation of the individual valves
|
|
if (Train->m_controlmapper.contains("pantselect_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->iCabn != 0 && false == Train->m_controlmapper.contains(Train->mvOccupied->PantSwitchType == "impulse" ? "pantrearoff_sw:" : "pantrear_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
// HACK: don't propagate pantograph commands issued from engine compartment, these are presumed to be manually moved levers
|
|
auto const ismanual{Train->iCabn == 0};
|
|
Train->mvOccupied->OperatePantographValve(end::rear, Train->mvOccupied->PantSwitchType == "impulse" ? operation_t::disable_on : operation_t::disable,
|
|
ismanual ? range_t::local : range_t::consist);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// NOTE: bit of a hax here, we're reusing button reset routine so we don't need a copy in every branch
|
|
OnCommand_pantographtogglerear(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographlowerall(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggPantAllDownButton.SubModel == nullptr)
|
|
{
|
|
// TODO: expand definition of cab controls so we can know if the control is present without testing for presence of 3d switch
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Lower All Pantographs switch is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Train->ggPantAllDownButton.type() == TGaugeType::toggle)
|
|
{
|
|
// two-state switch, only cares about press events
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvPantographUnit->DropAllPantographs(false == Train->mvPantographUnit->PantAllDown);
|
|
// visual feedback
|
|
Train->ggPantAllDownButton.UpdateValue(Train->mvPantographUnit->PantAllDown ? 1.0 : 0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// impulse switch
|
|
Train->mvControlled->DropAllPantographs(Command.action == GLFW_PRESS);
|
|
// visual feedback
|
|
Train->ggPantAllDownButton.UpdateValue(Command.action == GLFW_PRESS ? 1.0 : 0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographselectnext(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (false == Train->m_controlmapper.contains("pantselect_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
Train->change_pantograph_selection(1);
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographselectprevious(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (false == Train->m_controlmapper.contains("pantselect_sw:"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
Train->change_pantograph_selection(-1);
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographtoggleselected(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// recalculate pantograph state (hujhujhuj)
|
|
Train->change_pantograph_selection(1);
|
|
Train->change_pantograph_selection(-1);
|
|
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const state{Train->mvPantographUnit->PantsValve.is_enabled || Train->mvPantographUnit->PantsValve.is_active}; // fallback for impulse switches
|
|
if (state)
|
|
{
|
|
OnCommand_pantographlowerselected(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_pantographraiseselected(Train, Command);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// impulse switches return automatically to neutral position
|
|
if (Train->m_controlmapper.contains("pantselectedoff_sw:"))
|
|
{
|
|
// two buttons setup
|
|
if (Train->ggPantSelectedButton.type() != TGaugeType::toggle)
|
|
{
|
|
Train->mvOccupied->OperatePantographsValve(operation_t::enable_off);
|
|
// visual feedback
|
|
Train->ggPantSelectedButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
if (Train->ggPantSelectedDownButton.type() != TGaugeType::toggle)
|
|
{
|
|
Train->mvOccupied->OperatePantographsValve(operation_t::disable_off);
|
|
// visual feedback
|
|
Train->ggPantSelectedDownButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Train->ggPantSelectedButton.type() != TGaugeType::toggle)
|
|
{
|
|
// special case, just one impulse switch controlling both states
|
|
// with neutral position mid-way
|
|
Train->mvOccupied->OperatePantographsValve(operation_t::none);
|
|
// visual feedback
|
|
Train->ggPantSelectedButton.UpdateValue(0.5, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographraiseselected(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// raise selected
|
|
Train->mvOccupied->OperatePantographsValve(Train->ggPantSelectedButton.type() != TGaugeType::toggle ? operation_t::enable_on : operation_t::enable);
|
|
// visual feedback
|
|
Train->ggPantSelectedButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// NOTE: bit of a hax here, we're reusing button reset routine so we don't need a copy in every branch
|
|
OnCommand_pantographtoggleselected(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographlowerselected(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// lower selected
|
|
Train->mvOccupied->OperatePantographsValve(Train->ggPantSelectedDownButton.type() != TGaugeType::toggle ? operation_t::disable_on : operation_t::disable);
|
|
// visual feedback
|
|
if (Train->m_controlmapper.contains("pantselectedoff_sw:"))
|
|
{
|
|
// two button setup
|
|
Train->ggPantSelectedDownButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// single button
|
|
Train->ggPantSelectedButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// NOTE: bit of a hax here, we're reusing button reset routine so we don't need a copy in every branch
|
|
OnCommand_pantographtoggleselected(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::update_pantograph_valves()
|
|
{
|
|
using enum operation_t;
|
|
|
|
auto const &presets{mvOccupied->PantsPreset.first};
|
|
auto const &selection{mvOccupied->PantsPreset.second[cab_to_end()]};
|
|
|
|
auto const preset{presets[selection] - '0'};
|
|
auto const swapends{cab_to_end() != end::front};
|
|
// check desired states for both pantographs; value: whether the pantograph should be raised
|
|
auto const frontstate{preset & (swapends ? 2 : 1)};
|
|
auto const rearstate{preset & (swapends ? 1 : 2)};
|
|
mvOccupied->OperatePantographValve(end::front, frontstate ? enable : disable);
|
|
mvOccupied->OperatePantographValve(end::rear, rearstate ? enable : disable);
|
|
}
|
|
|
|
void TTrain::change_pantograph_selection(int const Change)
|
|
{
|
|
|
|
auto const &presets{mvOccupied->PantsPreset.first};
|
|
auto &selection{mvOccupied->PantsPreset.second[cab_to_end()]};
|
|
auto const initialstate{selection};
|
|
selection = std::clamp(selection + Change, 0, std::max<int>(static_cast<int>(presets.size() - 1), 0));
|
|
|
|
if (selection == initialstate)
|
|
{
|
|
return;
|
|
} // no change, nothing to do
|
|
|
|
// potentially adjust pantograph valves to match the new state
|
|
if (false == m_controlmapper.contains("pantvalves_sw:"))
|
|
{
|
|
update_pantograph_valves();
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographvalvesupdate(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
bool hasSeparateSwitches = Train->m_controlmapper.contains("pantvalvesupdate_bt:") && Train->m_controlmapper.contains("pantvalvesoff_bt:");
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (hasSeparateSwitches)
|
|
{
|
|
// implement action
|
|
Train->update_pantograph_valves();
|
|
// visual feedback
|
|
Train->ggPantValvesUpdate.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
|
|
// Old logic to maintain compatibility
|
|
else
|
|
{
|
|
Train->update_pantograph_valves();
|
|
Train->ggPantValvesButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
// NOTE: pantvalves_sw: is a specialized button, with no toggle behavior support
|
|
if (hasSeparateSwitches)
|
|
Train->ggPantValvesUpdate.UpdateValue(0.5, Train->dsbSwitch);
|
|
|
|
// Old logic to maintain compatibility
|
|
else
|
|
Train->ggPantValvesButton.UpdateValue(0.5, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographvalvesoff(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
bool hasSeparateSwitches = Train->m_controlmapper.contains("pantvalvesupdate_bt:") && Train->m_controlmapper.contains("pantvalvesoff_bt:");
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// implement action
|
|
Train->mvOccupied->OperatePantographValve(end::front, operation_t::disable);
|
|
Train->mvOccupied->OperatePantographValve(end::rear, operation_t::disable);
|
|
// visual feedback
|
|
if (hasSeparateSwitches)
|
|
Train->ggPantValvesOff.UpdateValue(1.0, Train->dsbSwitch);
|
|
else
|
|
Train->ggPantValvesButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
// NOTE: pantvalves_sw: is a speciali zed button, with no toggle behavior support
|
|
if (hasSeparateSwitches)
|
|
Train->ggPantValvesOff.UpdateValue(0.f, Train->dsbSwitch);
|
|
else
|
|
Train->ggPantValvesButton.UpdateValue(0.5, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographcompressorvalvetoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only react to press
|
|
if (Train->mvControlled->bPantKurek3 == false)
|
|
{
|
|
// connect pantographs with primary tank
|
|
OnCommand_pantographcompressorvalveenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// connect pantograps with pantograph compressor
|
|
OnCommand_pantographcompressorvalvedisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographcompressorvalveenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
|
|
if (auto const valveispresent{Train->ggPantCompressorValve.SubModel != nullptr || (Train->mvOccupied == Train->mvPantographUnit && Train->iCabn == 0)}; false == valveispresent)
|
|
{
|
|
// tylko w maszynowym, unless actual device is present
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only react to press
|
|
// connect pantographs with primary tank
|
|
Train->mvControlled->bPantKurek3 = true;
|
|
// visual feedback:
|
|
Train->ggPantCompressorValve.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographcompressorvalvedisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
|
|
if (auto const valveispresent{Train->ggPantCompressorValve.SubModel != nullptr || (Train->mvOccupied == Train->mvPantographUnit && Train->iCabn == 0)}; false == valveispresent)
|
|
{
|
|
// tylko w maszynowym, unless actual device is present
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only react to press
|
|
// connect pantograps with pantograph compressor
|
|
Train->mvControlled->bPantKurek3 = false;
|
|
// visual feedback:
|
|
Train->ggPantCompressorValve.UpdateValue(1.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_pantographcompressoractivate(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// tylko w maszynowym, unless actual device is present
|
|
if (auto const switchispresent{Train->m_controlmapper.contains("pantcompressor_sw:") || (Train->mvOccupied == Train->mvPantographUnit && Train->iCabn == 0)}; false == switchispresent)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// press or hold to activate
|
|
if (Train->mvPantographUnit->PantPress < 4.8 && true == Train->mvPantographUnit->Power24vIsAvailable)
|
|
{
|
|
// needs live power source and low enough pressure to work
|
|
Train->mvPantographUnit->PantCompFlag = true;
|
|
}
|
|
// visual feedback
|
|
Train->ggPantCompressorButton.UpdateValue(1.0);
|
|
}
|
|
else
|
|
{
|
|
// release to disable
|
|
Train->mvPantographUnit->PantCompFlag = false;
|
|
// visual feedback
|
|
Train->ggPantCompressorButton.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
namespace
|
|
{
|
|
// whether the cab's main_off_bt is the bistable lever of the line breaker's hold coil (eu07/maszyna#364)
|
|
bool is_hold_coil_lever(TGauge const &Button)
|
|
{
|
|
return Button.SubModel != nullptr && hold_coil_lever::is_bistable(Button.type_declared(), Button.type() == TGaugeType::toggle);
|
|
}
|
|
} // namespace
|
|
|
|
void TTrain::OnCommand_linebreakertoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// press or hold...
|
|
// a single two-state lever stays where it was put, also when the line breaker gets knocked out
|
|
auto const latchinglever{Train->ggMainOnButton.SubModel == nullptr && Train->ggMainOffButton.SubModel == nullptr && Train->ggMainButton.SubModel != nullptr &&
|
|
Train->ggMainButton.type() == TGaugeType::toggle};
|
|
switch (linebreaker::pressed(Train->m_linebreakerstate, latchinglever, Train->ggMainButton.GetDesiredValue() > 0.5))
|
|
{
|
|
case linebreaker::toggle::close:
|
|
// ...to close the circuit
|
|
if (is_hold_coil_lever(Train->ggMainOffButton) && hold_coil_lever::cuts_off(Train->ggMainOffButton.GetDesiredValue()))
|
|
{
|
|
// the one key works both controls: the hold coil lever goes back on first, or the line breaker couldn't close
|
|
Train->ggMainOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
// NOTE: bit of a dirty shortcut here
|
|
OnCommand_linebreakerclose(Train, Command);
|
|
break;
|
|
case linebreaker::toggle::open:
|
|
// ...to open the circuit, or to put the lever off if the circuit was already opened
|
|
OnCommand_linebreakeropen(Train, Command);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release...
|
|
if (Train->ggMainOnButton.SubModel != nullptr || Train->ggMainButton.type() != TGaugeType::toggle)
|
|
{
|
|
// only impulse switches react to release events
|
|
// NOTE: we presume dedicated state switch is of impulse type
|
|
if (Train->m_linebreakerstate == 0)
|
|
{
|
|
// ...after opening circuit, or holding for too short time to close it
|
|
OnCommand_linebreakeropen(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// ...after closing the circuit
|
|
// NOTE: bit of a dirty shortcut here
|
|
OnCommand_linebreakerclose(Train, Command);
|
|
}
|
|
}
|
|
// HACK: ignition key ignores lack of submodel, so we can start vehicles without any modeled controls
|
|
Train->ggIgnitionKey.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_linebreakeropen(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
if (is_hold_coil_lever(Train->ggMainOffButton))
|
|
{
|
|
// the bistable lever goes over to its other position and stays there
|
|
auto const position{hold_coil_lever::operated(Train->ggMainOffButton.GetDesiredValue())};
|
|
Train->ggMainOffButton.UpdateValue(position, Train->dsbSwitch);
|
|
if (false == hold_coil_lever::cuts_off(position))
|
|
{
|
|
// the hold coil is fed again, which by itself doesn't close the line breaker
|
|
return;
|
|
}
|
|
}
|
|
else if (Train->ggMainOffButton.SubModel != nullptr)
|
|
{
|
|
Train->ggMainOffButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Train->ggMainButton.SubModel != nullptr)
|
|
{
|
|
Train->ggMainButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
else if (Train->ggMainOnButton.SubModel != nullptr && false == Train->mvControlled->MainCircuitOpensWithStarterOnly())
|
|
{
|
|
// NOTE: legacy behaviour, for vehicles equipped only with impulse close switch
|
|
// it doesn't make any real sense to animate this one, but some people can't get over how there's no visual reaction to their keypress
|
|
Train->ggMainOnButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
return;
|
|
}
|
|
// a diesel with only the starter button gets its engine stopped. the button stays put: held down, it would start the engine again
|
|
// play sound immediately when the switch is hit, not after release
|
|
Train->fMainRelayTimer = 0.0f;
|
|
|
|
if (Train->m_linebreakerstate == 0)
|
|
{
|
|
return;
|
|
} // already in the desired state
|
|
|
|
if (true == Train->mvControlled->MainSwitch(false, Train->mvControlled->MainSwitchRange()))
|
|
{
|
|
Train->m_linebreakerstate = 0;
|
|
if (Train->mvControlled->MainSwitchRange() != range_t::local)
|
|
{
|
|
// the engines of the vehicles in multiple stopped along: their two-state switches go off too, left on
|
|
// they'd start them again after the delay
|
|
for (auto &controls : Train->m_remotelinebreakers)
|
|
{
|
|
if (controls.main_switch.SubModel != nullptr && controls.main_switch.type() == TGaugeType::toggle)
|
|
{
|
|
controls.main_switch.UpdateValue(0.0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
// we don't exactly know which of the two buttons was used, so reset both
|
|
// for setup with two separate swiches
|
|
if (Train->ggMainOnButton.SubModel != nullptr)
|
|
{
|
|
Train->ggMainOnButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
if (Train->ggMainOffButton.SubModel != nullptr && false == is_hold_coil_lever(Train->ggMainOffButton))
|
|
{
|
|
// (the bistable hold coil lever stays where it was put)
|
|
Train->ggMainOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
// and the two-state switch too, for good measure
|
|
if (Train->ggMainButton.SubModel != nullptr)
|
|
{
|
|
Train->ggMainButton.UpdateValue(Train->ggMainButton.type() != TGaugeType::toggle ? 0.5 : 0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_linebreakerclose(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
if (Train->ggMainOnButton.SubModel != nullptr)
|
|
{
|
|
// two separate switches to close and break the circuit
|
|
Train->ggMainOnButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Train->ggMainButton.SubModel != nullptr)
|
|
{
|
|
// single two-state switch
|
|
Train->ggMainButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// no switch capable of doing the job
|
|
// HACK: ignition key ignores lack of submodel, so we can start vehicles without any modeled controls
|
|
Train->ggIgnitionKey.UpdateValue(1.0);
|
|
return;
|
|
}
|
|
// the actual closing of the line breaker is handled in the train update routine
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
if (Train->ggMainOnButton.SubModel != nullptr)
|
|
{
|
|
// setup with two separate switches
|
|
Train->ggMainOnButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
else if (Train->ggMainButton.SubModel != nullptr && Train->ggMainButton.type() != TGaugeType::toggle)
|
|
{
|
|
Train->ggMainButton.UpdateValue(0.5, Train->dsbSwitch);
|
|
}
|
|
|
|
if (Train->m_linebreakerstate == 1)
|
|
{
|
|
return;
|
|
} // already in the desired state
|
|
|
|
// we don't need to start the diesel twice, but the other types (with impulse switch setup) still need to be launched
|
|
// NOTE: this behaviour should depend on MainOnButton presence and type_delayed
|
|
// TODO: change it when/if vehicle definition files get their proper switch types
|
|
if (Train->m_linebreakerstate == 2 && Train->mvControlled->EngineType == TEngineType::ElectricSeriesMotor)
|
|
{
|
|
// try to finalize state change of the line breaker, set the state based on the outcome
|
|
Train->m_linebreakerstate = Train->mvControlled->MainSwitch(true, Train->mvControlled->MainSwitchRange()) ? 1 : 0;
|
|
}
|
|
// on button release reset the closing timer
|
|
Train->fMainRelayTimer = 0.0f;
|
|
}
|
|
}
|
|
|
|
namespace
|
|
{
|
|
|
|
// which of the switches of the other vehicles in multiple a command works: 0 the second vehicle's, 1 the third one's
|
|
std::size_t remote_linebreaker_index(user_command const Command)
|
|
{
|
|
using enum user_command;
|
|
return (Command == linebreakertogglec || Command == linebreakeropenc || Command == linebreakerclosec) ? 1 : 0;
|
|
}
|
|
|
|
// the impulse switches of another vehicle's line breaker spring back when let go, whichever way they were pressed
|
|
void release_remote_linebreaker(TTrain::remote_linebreaker &Controls, std::optional<sound_source> &Sound)
|
|
{
|
|
if (Controls.on_button.SubModel != nullptr)
|
|
{
|
|
Controls.on_button.UpdateValue(0.0, Sound);
|
|
}
|
|
if (Controls.off_button.SubModel != nullptr)
|
|
{
|
|
Controls.off_button.UpdateValue(0.0, Sound);
|
|
}
|
|
if (Controls.main_switch.SubModel != nullptr && Controls.main_switch.type() != TGaugeType::toggle)
|
|
{
|
|
Controls.main_switch.UpdateValue(0.5, Sound);
|
|
}
|
|
Controls.held_without_switch = false;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TMoverParameters *TTrain::remote_engine(std::size_t const Index) const
|
|
{
|
|
return engine_start::engine(*mvOccupied, *mvControlled, static_cast<int>(Index) + 2);
|
|
}
|
|
|
|
void TTrain::OnCommand_linebreakertoggleremote(TTrain *Train, command_data const &Command)
|
|
{
|
|
auto const index{remote_linebreaker_index(Command.command)};
|
|
auto &controls{Train->m_remotelinebreakers[index]};
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// a two-state switch goes the other way than it stands, an impulse one the other way than the engine is
|
|
bool close{false};
|
|
if (controls.main_switch.SubModel != nullptr && controls.main_switch.type() == TGaugeType::toggle)
|
|
{
|
|
close = controls.main_switch.GetDesiredValue() < 0.5;
|
|
}
|
|
else
|
|
{
|
|
auto const *engine{Train->remote_engine(index)};
|
|
close = engine == nullptr || false == engine_start::remote_switch::is_running(*engine);
|
|
}
|
|
if (close)
|
|
{
|
|
OnCommand_linebreakercloseremote(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_linebreakeropenremote(Train, Command);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
if (controls.on_button.SubModel != nullptr || controls.main_switch.type() != TGaugeType::toggle)
|
|
{
|
|
// only impulse switches react to release events
|
|
release_remote_linebreaker(controls, Train->dsbSwitch);
|
|
}
|
|
controls.held_without_switch = false;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_linebreakeropenremote(TTrain *Train, command_data const &Command)
|
|
{
|
|
auto const index{remote_linebreaker_index(Command.command)};
|
|
auto &controls{Train->m_remotelinebreakers[index]};
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
if (controls.off_button.SubModel != nullptr)
|
|
{
|
|
controls.off_button.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (controls.main_switch.SubModel != nullptr)
|
|
{
|
|
controls.main_switch.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
controls.held_without_switch = false;
|
|
if (auto *engine{Train->remote_engine(index)}; engine != nullptr)
|
|
{
|
|
engine_start::remote_switch::open(*engine);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
release_remote_linebreaker(controls, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_linebreakercloseremote(TTrain *Train, command_data const &Command)
|
|
{
|
|
auto const index{remote_linebreaker_index(Command.command)};
|
|
auto &controls{Train->m_remotelinebreakers[index]};
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback; the line breaker closes in the train update, once the switch was held long enough
|
|
if (controls.on_button.SubModel != nullptr)
|
|
{
|
|
controls.on_button.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (controls.main_switch.SubModel != nullptr)
|
|
{
|
|
controls.main_switch.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// no switch in the cab, the command alone holds it
|
|
controls.held_without_switch = true;
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
release_remote_linebreaker(controls, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::update_remote_linebreakers(double const Deltatime)
|
|
{
|
|
for (std::size_t index = 0; index < m_remotelinebreakers.size(); ++index)
|
|
{
|
|
auto &controls{m_remotelinebreakers[index]};
|
|
auto *engine{remote_engine(index)};
|
|
auto const closeheld{controls.held_without_switch || (controls.main_switch.SubModel != nullptr && controls.main_switch.GetDesiredValue() > 0.95) ||
|
|
(controls.on_button.SubModel != nullptr && controls.on_button.GetDesiredValue() > 0.95)};
|
|
auto const openheld{controls.off_button.SubModel != nullptr && controls.off_button.GetDesiredValue() > 0.95};
|
|
// as with the cab's own switch, an electric locomotive's impulse switch closes the line breaker when let go
|
|
auto const closesonrelease{engine != nullptr && controls.on_button.SubModel != nullptr && engine->EngineType == TEngineType::ElectricSeriesMotor};
|
|
controls.state.update(engine, closeheld, openheld, Deltatime, closesonrelease);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_fuelpumptoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggFuelPumpButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// currently there's no off button so we always try to turn it on
|
|
OnCommand_fuelpumpenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// two-state switch
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (false == Train->mvControlled->FuelPump.is_enabled)
|
|
{
|
|
// turn on
|
|
OnCommand_fuelpumpenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_fuelpumpdisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_fuelpumpenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggFuelPumpButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggFuelPumpButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
Train->mvControlled->FuelPumpSwitch(true);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggFuelPumpButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
Train->mvControlled->FuelPumpSwitch(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, only cares about press events
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggFuelPumpButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
Train->mvControlled->FuelPumpSwitch(true);
|
|
Train->mvControlled->FuelPumpSwitchOff(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_fuelpumpdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggFuelPumpButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// currently there's no disable return type switch
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, only cares about press events
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggFuelPumpButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
Train->mvControlled->FuelPumpSwitch(false);
|
|
Train->mvControlled->FuelPumpSwitchOff(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_oilpumptoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggOilPumpButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// currently there's no off button so we always try to turn it on
|
|
OnCommand_oilpumpenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// two-state switch
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (false == Train->mvControlled->OilPump.is_enabled)
|
|
{
|
|
// turn on
|
|
OnCommand_oilpumpenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_oilpumpdisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_oilpumpenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggOilPumpButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggOilPumpButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
Train->mvControlled->OilPumpSwitch(true);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggOilPumpButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
Train->mvControlled->OilPumpSwitch(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, only cares about press events
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggOilPumpButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
Train->mvControlled->OilPumpSwitch(true);
|
|
Train->mvControlled->OilPumpSwitchOff(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_oilpumpdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggOilPumpButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// currently there's no disable return type switch
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, only cares about press events
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggOilPumpButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
Train->mvControlled->OilPumpSwitch(false);
|
|
Train->mvControlled->OilPumpSwitchOff(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_oilfuelpumptoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto *vehicle{Train->mvControlled};
|
|
if (Train->ggOilFuelPumpButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch, as the separate ones: held to start both pumps
|
|
auto const pressed{Command.action == GLFW_PRESS};
|
|
Train->ggOilFuelPumpButton.UpdateValue(pressed ? 1.0 : 0.0, Train->dsbSwitch);
|
|
vehicle->FuelPumpSwitch(pressed);
|
|
vehicle->OilPumpSwitch(pressed);
|
|
return;
|
|
}
|
|
// two-state switch, only cares about press events
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
// both pumps go off if both were on, otherwise both go on; a pump started automatically doesn't take part
|
|
auto const enable{false == vehicle->OilFuelPumpsEnabled()};
|
|
Train->ggOilFuelPumpButton.UpdateValue(enable ? 1.0 : 0.0, Train->dsbSwitch);
|
|
vehicle->FuelPumpSwitch(enable);
|
|
vehicle->FuelPumpSwitchOff(false == enable);
|
|
vehicle->OilPumpSwitch(enable);
|
|
vehicle->OilPumpSwitchOff(false == enable);
|
|
}
|
|
|
|
void TTrain::OnCommand_waterheaterbreakertoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvControlled->WaterHeater.breaker)
|
|
{
|
|
// turn on
|
|
OnCommand_waterheaterbreakerclose(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_waterheaterbreakeropen(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_waterheaterbreakerclose(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterHeaterBreakerButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
if (true == Train->mvControlled->WaterHeater.breaker)
|
|
{
|
|
return;
|
|
} // already enabled
|
|
|
|
Train->mvControlled->WaterHeaterBreakerSwitch(true);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_waterheaterbreakeropen(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterHeaterBreakerButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
|
|
if (false == Train->mvControlled->WaterHeater.breaker)
|
|
{
|
|
return;
|
|
} // already enabled
|
|
|
|
Train->mvControlled->WaterHeaterBreakerSwitch(false);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_waterheatertoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvControlled->WaterHeater.is_enabled)
|
|
{
|
|
// turn on
|
|
OnCommand_waterheaterenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_waterheaterdisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_waterheaterenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterHeaterButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
if (true == Train->mvControlled->WaterHeater.is_enabled)
|
|
{
|
|
return;
|
|
} // already enabled
|
|
|
|
Train->mvControlled->WaterHeaterSwitch(true);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_waterheaterdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterHeaterButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
|
|
if (false == Train->mvControlled->WaterHeater.is_enabled)
|
|
{
|
|
return;
|
|
} // already disabled
|
|
|
|
Train->mvControlled->WaterHeaterSwitch(false);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_waterpumpbreakertoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvControlled->WaterPump.breaker)
|
|
{
|
|
// turn on
|
|
OnCommand_waterpumpbreakerclose(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_waterpumpbreakeropen(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_waterpumpbreakerclose(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterPumpBreakerButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
if (true == Train->mvControlled->WaterPump.breaker)
|
|
{
|
|
return;
|
|
} // already enabled
|
|
|
|
Train->mvControlled->WaterPumpBreakerSwitch(true);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_waterpumpbreakeropen(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterPumpBreakerButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
|
|
if (false == Train->mvControlled->WaterPump.breaker)
|
|
{
|
|
return;
|
|
} // already enabled
|
|
|
|
Train->mvControlled->WaterPumpBreakerSwitch(false);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_waterpumptoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggWaterPumpButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// currently there's no off button so we always try to turn it on
|
|
OnCommand_waterpumpenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// two-state switch
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (false == Train->mvControlled->WaterPump.is_enabled)
|
|
{
|
|
// turn on
|
|
OnCommand_waterpumpenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_waterpumpdisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_waterpumpenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggWaterPumpButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterPumpButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
Train->mvControlled->WaterPumpSwitch(true);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterPumpButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
Train->mvControlled->WaterPumpSwitch(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, only cares about press events
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterPumpButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
Train->mvControlled->WaterPumpSwitch(true);
|
|
Train->mvControlled->WaterPumpSwitchOff(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_waterpumpdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggWaterPumpButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// currently there's no disable return type switch
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, only cares about press events
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterPumpButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
Train->mvControlled->WaterPumpSwitch(false);
|
|
Train->mvControlled->WaterPumpSwitchOff(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_watercircuitslinktoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvControlled->WaterCircuitsLink)
|
|
{
|
|
// turn on
|
|
OnCommand_watercircuitslinkenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_watercircuitslinkdisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_watercircuitslinkenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterCircuitsLinkButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
if (true == Train->mvControlled->WaterCircuitsLink)
|
|
{
|
|
return;
|
|
} // already enabled
|
|
|
|
Train->mvControlled->WaterCircuitsLinkSwitch(true);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_watercircuitslinkdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggWaterCircuitsLinkButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
|
|
if (false == Train->mvControlled->WaterCircuitsLink)
|
|
{
|
|
return;
|
|
} // already disabled
|
|
|
|
Train->mvControlled->WaterCircuitsLinkSwitch(false);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_convertertoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const overloadrelayisopen{(Train->Dynamic()->Mechanik != nullptr ? Train->Dynamic()->Mechanik->IsAnyConverterOverloadRelayOpen : Train->mvOccupied->ConvOvldFlag)};
|
|
|
|
if (Train->mvOccupied->ConvSwitchType != "impulse" ? Train->ggConverterButton.GetValue() < 0.5 : false == Train->mvOccupied->Power110vIsAvailable && false == overloadrelayisopen)
|
|
{
|
|
// turn on
|
|
OnCommand_converterenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_converterdisable(Train, Command);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// on button release...
|
|
if (Train->mvOccupied->ConvSwitchType == "impulse")
|
|
{
|
|
// ...return switches to start position if applicable
|
|
Train->ggConverterButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
Train->ggConverterOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_converterenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggConverterButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
// impulse type switch has no effect if there's no power
|
|
// NOTE: this is most likely setup wrong, but the whole thing is smoke and mirrors anyway
|
|
if (Train->mvOccupied->ConvSwitchType != "impulse" || Train->mvControlled->Mains)
|
|
{
|
|
// won't start if the line breaker button is still held
|
|
Train->mvOccupied->ConverterSwitch(true);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// potentially reset impulse switch position, using shared code branch
|
|
OnCommand_convertertoggle(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_converterdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggConverterButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
if (Train->ggConverterOffButton.SubModel != nullptr)
|
|
{
|
|
Train->ggConverterOffButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
|
|
Train->mvOccupied->ConverterSwitch(false);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// potentially reset impulse switch position, using shared code branch
|
|
OnCommand_convertertoggle(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_convertertogglelocal(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->ConverterStart == start_t::automatic)
|
|
{
|
|
// let the automatic thing do its automatic thing...
|
|
return;
|
|
}
|
|
if (Train->ggConverterLocalButton.SubModel == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvOccupied->ConverterAllowLocal && Train->ggConverterLocalButton.GetValue() < 0.5)
|
|
{
|
|
// turn on
|
|
// visual feedback
|
|
Train->ggConverterLocalButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
// effect
|
|
Train->mvOccupied->ConverterAllowLocal = true;
|
|
/*
|
|
if( true == Train->mvControlled->ConverterSwitch( true, range::local ) ) {
|
|
// side effects
|
|
// control the compressor, if it's paired with the converter
|
|
if( Train->mvControlled->CompressorPower == 2 ) {
|
|
// hunter-091012: tak jest poprawnie
|
|
Train->mvControlled->CompressorSwitch( true, range::local );
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
// visual feedback
|
|
Train->ggConverterLocalButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
// effect
|
|
Train->mvOccupied->ConverterAllowLocal = false;
|
|
/*
|
|
if( true == Train->mvControlled->ConverterSwitch( false, range::local ) ) {
|
|
// side effects
|
|
// control the compressor, if it's paired with the converter
|
|
if( Train->mvControlled->CompressorPower == 2 ) {
|
|
// hunter-091012: tak jest poprawnie
|
|
Train->mvControlled->CompressorSwitch( false, range::local );
|
|
}
|
|
// if there's no (low voltage) power source left, drop pantographs
|
|
if( false == Train->mvControlled->Battery ) {
|
|
Train->mvControlled->PantFront( false, range::local );
|
|
Train->mvControlled->PantRear( false, range::local );
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_converteroverloadrelayreset(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->ggConverterFuseButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Converter Overload Relay Reset button is missing, or wasn't defined");
|
|
}
|
|
// return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggConverterFuseButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
Train->mvControlled->RelayReset(relay_t::primaryconverteroverload);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggConverterFuseButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_compressortoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const compressorisenabled{(Train->Dynamic()->Mechanik ? Train->Dynamic()->Mechanik->IsAnyCompressorEnabled : Train->mvOccupied->CompressorAllow)};
|
|
|
|
if (false == compressorisenabled)
|
|
{
|
|
// turn on
|
|
OnCommand_compressorenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_compressordisable(Train, Command);
|
|
}
|
|
}
|
|
/*
|
|
// disabled because we don't have yet support for compressor switch type definition
|
|
else if( Command.action == GLFW_RELEASE ) {
|
|
// on button release...
|
|
if( Train->mvOccupied->CompSwitchType == "impulse" ) {
|
|
// ...return switches to start position if applicable
|
|
Train->ggCompressorButton.UpdateValue( 0.0, Train->dsbSwitch );
|
|
Train->ggCompressorOffButton.UpdateValue( 0.0, Train->dsbSwitch );
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
|
|
void TTrain::OnCommand_compressorenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggCompressorButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
// impulse type switch has no effect if there's no power
|
|
// NOTE: this is most likely setup wrong, but the whole thing is smoke and mirrors anyway
|
|
// if( ( Train->mvOccupied->CompSwitchType != "impulse" )
|
|
// || ( Train->mvControlled->Mains ) ) {
|
|
|
|
Train->mvOccupied->CompressorSwitch(true);
|
|
// }
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// potentially reset impulse switch position, using shared code branch
|
|
OnCommand_compressortoggle(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_compressordisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvControlled->CompressorPower >= 2)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggCompressorButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
/*
|
|
if( Train->ggCompressorOffButton.SubModel != nullptr ) {
|
|
Train->ggCompressorOffButton.UpdateValue( 1.0, Train->dsbSwitch );
|
|
}
|
|
*/
|
|
Train->mvOccupied->CompressorSwitch(false);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// potentially reset impulse switch position, using shared code branch
|
|
OnCommand_compressortoggle(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_compressortogglelocal(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->CompressorPower >= 2)
|
|
{
|
|
return;
|
|
}
|
|
if (Train->ggCompressorLocalButton.SubModel == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvOccupied->CompressorAllowLocal)
|
|
{
|
|
// turn on
|
|
// visual feedback
|
|
Train->ggCompressorLocalButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
// effect
|
|
Train->mvOccupied->CompressorAllowLocal = true;
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
// visual feedback
|
|
Train->ggCompressorLocalButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
// effect
|
|
Train->mvOccupied->CompressorAllowLocal = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_compressorpresetactivatenext(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->CompressorListPosNo == 0)
|
|
{
|
|
return;
|
|
}
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggCompressorListButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
if (Train->mvOccupied->CompressorListPosNo < Train->mvOccupied->CompressorListDefPos + 1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Train->mvOccupied->ChangeCompressorPreset(Command.action == GLFW_PRESS ? Train->mvOccupied->CompressorListDefPos + 1 : Train->mvOccupied->CompressorListDefPos);
|
|
// visual feedback
|
|
Train->ggCompressorListButton.UpdateValue(static_cast<float>(Train->mvOccupied->CompressorListPos - 1), Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// multi-state switch
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->mvOccupied->CompressorListPos < Train->mvOccupied->CompressorListPosNo || true == Train->mvOccupied->CompressorListWrap)
|
|
{
|
|
// active light preset is stored as value in range 1-LigthPosNo
|
|
Train->mvOccupied->ChangeCompressorPreset(Train->mvOccupied->CompressorListPos < Train->mvOccupied->CompressorListPosNo ? Train->mvOccupied->CompressorListPos + 1 : 1); // wrap mode
|
|
// visual feedback
|
|
Train->ggCompressorListButton.UpdateValue(static_cast<float>(Train->mvOccupied->CompressorListPos - 1), Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_compressorpresetactivateprevious(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->CompressorListPosNo == 0)
|
|
{
|
|
return;
|
|
}
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
} // one change per key press
|
|
|
|
if (Train->ggCompressorListButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch toggles only between positions 'default' and 'default+1'
|
|
return;
|
|
}
|
|
|
|
if (Train->mvOccupied->CompressorListPos > 1 || true == Train->mvOccupied->CompressorListWrap)
|
|
{
|
|
// active light preset is stored as value in range 1-LigthPosNo
|
|
Train->mvOccupied->ChangeCompressorPreset(Train->mvOccupied->CompressorListPos > 1 ? Train->mvOccupied->CompressorListPos - 1 : Train->mvOccupied->CompressorListPosNo); // wrap mode
|
|
|
|
// visual feedback
|
|
if (Train->ggCompressorListButton.SubModel != nullptr)
|
|
{
|
|
Train->ggCompressorListButton.UpdateValue(static_cast<float>(Train->mvOccupied->CompressorListPos - 1), Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_compressorpresetactivatedefault(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->CompressorListPosNo == 0)
|
|
{
|
|
return;
|
|
}
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
} // one change per key press
|
|
|
|
Train->mvOccupied->ChangeCompressorPreset(Train->mvOccupied->CompressorListDefPos);
|
|
|
|
// visual feedback
|
|
if (Train->ggCompressorListButton.SubModel != nullptr)
|
|
{
|
|
Train->ggCompressorListButton.UpdateValue(static_cast<float>(Train->mvOccupied->CompressorListPos - 1), Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motorblowerstogglefront(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggMotorBlowersFrontButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// currently there's no off button so we always try to turn it on
|
|
OnCommand_motorblowersenablefront(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// two-state switch
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (false == Train->mvControlled->MotorBlowers[end::front].is_enabled)
|
|
{
|
|
// turn on
|
|
OnCommand_motorblowersenablefront(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_motorblowersdisablefront(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motorblowersenablefront(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggMotorBlowersFrontButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggMotorBlowersFrontButton.UpdateValue(1.f, Train->dsbSwitch);
|
|
Train->mvControlled->MotorBlowersSwitch(true, end::front);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggMotorBlowersFrontButton.UpdateValue(0.f, Train->dsbSwitch);
|
|
Train->mvControlled->MotorBlowersSwitch(false, end::front);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, only cares about press events
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggMotorBlowersFrontButton.UpdateValue(1.f, Train->dsbSwitch);
|
|
Train->mvControlled->MotorBlowersSwitch(true, end::front);
|
|
Train->mvControlled->MotorBlowersSwitchOff(false, end::front);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motorblowersdisablefront(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggMotorBlowersFrontButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// currently there's no disable return type switch
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, only cares about press events
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggMotorBlowersFrontButton.UpdateValue(0.f, Train->dsbSwitch);
|
|
Train->mvControlled->MotorBlowersSwitch(false, end::front);
|
|
Train->mvControlled->MotorBlowersSwitchOff(true, end::front);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motorblowerstogglerear(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggMotorBlowersRearButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// currently there's no off button so we always try to turn it on
|
|
OnCommand_motorblowersenablerear(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// two-state switch
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (false == Train->mvControlled->MotorBlowers[end::rear].is_enabled)
|
|
{
|
|
// turn on
|
|
OnCommand_motorblowersenablerear(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_motorblowersdisablerear(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motorblowersenablerear(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggMotorBlowersRearButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggMotorBlowersRearButton.UpdateValue(1.f, Train->dsbSwitch);
|
|
Train->mvControlled->MotorBlowersSwitch(true, end::rear);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggMotorBlowersRearButton.UpdateValue(0.f, Train->dsbSwitch);
|
|
Train->mvControlled->MotorBlowersSwitch(false, end::rear);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, only cares about press events
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggMotorBlowersRearButton.UpdateValue(1.f, Train->dsbSwitch);
|
|
Train->mvControlled->MotorBlowersSwitch(true, end::rear);
|
|
Train->mvControlled->MotorBlowersSwitchOff(false, end::rear);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motorblowersdisablerear(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggMotorBlowersRearButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// currently there's no disable return type switch
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, only cares about press events
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggMotorBlowersRearButton.UpdateValue(0.f, Train->dsbSwitch);
|
|
Train->mvControlled->MotorBlowersSwitch(false, end::rear);
|
|
Train->mvControlled->MotorBlowersSwitchOff(true, end::rear);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motorblowersdisableall(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggMotorBlowersAllOffButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggMotorBlowersAllOffButton.UpdateValue(1.f, Train->dsbSwitch);
|
|
Train->mvControlled->MotorBlowersSwitchOff(true, end::front);
|
|
Train->mvControlled->MotorBlowersSwitchOff(true, end::rear);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggMotorBlowersAllOffButton.UpdateValue(0.f, Train->dsbSwitch);
|
|
Train->mvControlled->MotorBlowersSwitchOff(false, end::front);
|
|
Train->mvControlled->MotorBlowersSwitchOff(false, end::rear);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, only cares about press events
|
|
// NOTE: generally this switch doesn't come in two-state form
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (Train->ggMotorBlowersAllOffButton.GetDesiredValue() < 0.5f)
|
|
{
|
|
// switch is off, activate
|
|
Train->mvControlled->MotorBlowersSwitchOff(true, end::front);
|
|
Train->mvControlled->MotorBlowersSwitchOff(true, end::rear);
|
|
// visual feedback
|
|
Train->ggMotorBlowersRearButton.UpdateValue(1.f, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// deactivate
|
|
Train->mvControlled->MotorBlowersSwitchOff(false, end::front);
|
|
Train->mvControlled->MotorBlowersSwitchOff(false, end::rear);
|
|
// visual feedback
|
|
Train->ggMotorBlowersRearButton.UpdateValue(0.f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_coolingfanstoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Train->mvControlled->RVentForceOn = !Train->mvControlled->RVentForceOn;
|
|
}
|
|
|
|
void TTrain::OnCommand_motorconnectorsopen(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// TODO: don't rely on presense of 3d model to determine presence of the switch
|
|
if (Train->ggStLinOffButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Open Motor Power Connectors button is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
// HACK: because we don't have modeled actual circuits this is a simplification of the real mechanics
|
|
// namely, pressing the button will flip it in the entire unit, which isn't exactly physically possible
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// button works while it's held down but we can ignore repeats
|
|
if (false == Train->mvControlled->StLinSwitchOff)
|
|
{
|
|
// open the connectors
|
|
// visual feedback
|
|
Train->ggStLinOffButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
Train->mvControlled->StLinSwitchOff = true;
|
|
Train->set_paired_open_motor_connectors_button(true);
|
|
}
|
|
else
|
|
{
|
|
// potentially close the connectors
|
|
OnCommand_motorconnectorsclose(Train, Command);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// button released
|
|
if (Train->mvControlled->StLinSwitchType != "toggle")
|
|
{
|
|
// default button type (impulse) ceases its work on button release
|
|
// visual feedback
|
|
Train->ggStLinOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
|
|
Train->mvControlled->StLinSwitchOff = false;
|
|
Train->set_paired_open_motor_connectors_button(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motorconnectorsclose(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// TODO: don't rely on presense of 3d model to determine presence of the switch
|
|
if (Train->ggStLinOffButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Open Motor Power Connectors button is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (Train->mvControlled->StLinSwitchType == "toggle")
|
|
{
|
|
// default type of button (impulse) has only one effect on press, but the toggle type can toggle the state
|
|
// visual feedback
|
|
Train->ggStLinOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
|
|
if (false == Train->mvControlled->StLinSwitchOff)
|
|
{
|
|
return;
|
|
} // already closed
|
|
|
|
Train->mvControlled->StLinSwitchOff = false;
|
|
Train->set_paired_open_motor_connectors_button(false);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motordisconnect(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvControlled->TrainType == dt_EZT ? Train->mvControlled != Train->mvOccupied : Train->iCabn != 0)
|
|
{
|
|
// tylko w maszynowym
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvControlled->CutOffEngine();
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motoroverloadrelaythresholdtoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (true == Train->mvControlled->ShuntModeAllow ? false == Train->mvControlled->ShuntMode : false == Train->mvControlled->MotorOverloadRelayHighThreshold)
|
|
{
|
|
// turn on
|
|
OnCommand_motoroverloadrelaythresholdsethigh(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_motoroverloadrelaythresholdsetlow(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motoroverloadrelaythresholdsetlow(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvControlled->CurrentSwitch(false);
|
|
// visual feedback
|
|
Train->ggMaxCurrentCtrl.UpdateValue(Train->mvControlled->MotorOverloadRelayHighThreshold ? 1 : 0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motoroverloadrelaythresholdsethigh(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvControlled->CurrentSwitch(true);
|
|
// visual feedback
|
|
Train->ggMaxCurrentCtrl.UpdateValue(Train->mvControlled->MotorOverloadRelayHighThreshold ? 1 : 0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_motoroverloadrelayreset(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->ggFuseButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Motor Overload Relay Reset button is missing, or wasn't defined");
|
|
}
|
|
// return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggFuseButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
Train->mvControlled->FuseOn();
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggFuseButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_universalrelayreset(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
auto const itemindex = static_cast<int>(Command.command) - static_cast<int>(user_command::universalrelayreset1);
|
|
auto &item = Train->ggRelayResetButtons[itemindex];
|
|
|
|
// NOTE: relay reset switches are impulse-only
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvOccupied->UniversalResetButton(itemindex);
|
|
// visual feedback
|
|
item.UpdateValue(1.0);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
item.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
// the cab interior light set by the light preset just selected, if the preset sets one (eu07/maszyna#529).
|
|
// the cab light switch (cablight_sw:) is bound to the light state and follows it by itself
|
|
void TTrain::set_cab_light_from_lights_preset()
|
|
{
|
|
auto const cablight{mvOccupied->LightsPresetCabLight(mvOccupied->LightsPos)};
|
|
if (false == cablight.has_value())
|
|
{
|
|
return;
|
|
}
|
|
auto const set{[&cablight](TCab &Cab) {
|
|
Cab.bLight = cablight->light;
|
|
Cab.bLightDim = cablight->dim;
|
|
}};
|
|
if (false == DynamicObject->JointCabs)
|
|
{
|
|
// vehicles with separate cabs get separate lighting switch states
|
|
set(Cabine[iCabn]);
|
|
}
|
|
else
|
|
{
|
|
// joint virtual cabs share lighting switch states
|
|
for (auto &cab : Cabine)
|
|
{
|
|
set(cab);
|
|
}
|
|
}
|
|
// the dimmer switch is driven by commands only, move it along
|
|
if (ggCabLightDimButton.SubModel != nullptr)
|
|
{
|
|
ggCabLightDimButton.UpdateValue(cablight->dim ? 1.f : 0.f);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_lightspresetactivatenext(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo == 0)
|
|
{
|
|
// no preset selector
|
|
return;
|
|
}
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
// one change per key press
|
|
return;
|
|
}
|
|
|
|
if (Train->mvOccupied->LightsPos < Train->mvOccupied->LightsPosNo || true == Train->mvOccupied->LightsWrap)
|
|
{
|
|
// active light preset is stored as value in range 1-LigthPosNo
|
|
auto const restartcycle{Train->mvOccupied->LightsPos >= Train->mvOccupied->LightsPosNo};
|
|
Train->mvOccupied->LightsPos = false == restartcycle ? Train->mvOccupied->LightsPos + 1 : 1; // wrap mode
|
|
|
|
Train->Dynamic()->SetLights();
|
|
Train->set_cab_light_from_lights_preset();
|
|
// visual feedback
|
|
if (Train->ggLightsButton.SubModel != nullptr)
|
|
{
|
|
if (false == restartcycle)
|
|
{
|
|
Train->ggLightsButton.UpdateValue(static_cast<float>(Train->mvOccupied->LightsPos - 1), Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// past the last position to the first one: a knob turning all the way round turns on rather than
|
|
// back across all the positions, and the position reached sounds (eu07/maszyna#464)
|
|
Train->ggLightsButton.UpdateValueWrapped(static_cast<float>(Train->mvOccupied->LightsPos - 1), true, Train->mvOccupied->LightsPosNo, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_lightspresetactivateprevious(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo == 0)
|
|
{
|
|
// no preset selector
|
|
return;
|
|
}
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
// one change per key press
|
|
return;
|
|
}
|
|
|
|
if (Train->mvOccupied->LightsPos > 1 || true == Train->mvOccupied->LightsWrap)
|
|
{
|
|
// active light preset is stored as value in range 1-LigthPosNo
|
|
auto const restartcycle{Train->mvOccupied->LightsPos <= 1};
|
|
Train->mvOccupied->LightsPos = false == restartcycle ? Train->mvOccupied->LightsPos - 1 : Train->mvOccupied->LightsPosNo; // wrap mode
|
|
|
|
Train->Dynamic()->SetLights();
|
|
Train->set_cab_light_from_lights_preset();
|
|
// visual feedback
|
|
if (Train->ggLightsButton.SubModel != nullptr)
|
|
{
|
|
if (false == restartcycle)
|
|
{
|
|
Train->ggLightsButton.UpdateValue(static_cast<float>(Train->mvOccupied->LightsPos - 1), Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// back past the first position to the last one, the same way (eu07/maszyna#464)
|
|
Train->ggLightsButton.UpdateValueWrapped(static_cast<float>(Train->mvOccupied->LightsPos - 1), false, Train->mvOccupied->LightsPosNo, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlighttoggleleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
|
|
if (Train->ggLeftEndLightButton.SubModel != nullptr || Train->ggLeftLightButton.SubModel == nullptr)
|
|
{
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_left) == 0)
|
|
{
|
|
// turn on
|
|
OnCommand_headlightenableleft(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_headlightdisableleft(Train, Command);
|
|
}
|
|
} else {
|
|
// if the light is controlled by 3-way switch, handle both headlight and redmarker
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_left) == 0 &&
|
|
(Train->mvOccupied->iLights[vehicleend] & light::redmarker_left) == 0)
|
|
{
|
|
// turn on
|
|
OnCommand_headlightenableleft(Train, Command);
|
|
}
|
|
else if (Train->mvOccupied->iLights[vehicleend] & light::headlight_left)
|
|
{
|
|
// switch to red
|
|
OnCommand_redmarkerenableleft(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// disable
|
|
OnCommand_redmarkerdisableleft(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_lightsset(TTrain *Train, command_data const &Command)
|
|
{
|
|
// set custom item in Lights inventory
|
|
Train->mvOccupied->Lights[end::front][17] = static_cast<int>(Command.param1);
|
|
Train->mvOccupied->Lights[end::rear][17] = static_cast<int>(Command.param2);
|
|
Train->mvOccupied->LightsPos = 18; // nasza custom pozycja
|
|
Train->Dynamic()->SetLights();
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightenableleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggLeftLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
// implementation
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_left) == 0)
|
|
{
|
|
Train->mvOccupied->iLights[vehicleend] ^= light::headlight_left;
|
|
}
|
|
// if the light is controlled by 3-way switch, disable marker light
|
|
if (Train->ggLeftEndLightButton.SubModel == nullptr)
|
|
{
|
|
Train->mvOccupied->iLights[vehicleend] &= ~light::redmarker_left;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightdisableleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
int const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_left) == 0)
|
|
{
|
|
return;
|
|
} // already disabled
|
|
|
|
Train->mvOccupied->iLights[vehicleend] ^= light::headlight_left;
|
|
// visual feedback
|
|
Train->ggLeftLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlighttoggleright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
|
|
if (Train->ggRightEndLightButton.SubModel != nullptr || Train->ggRightLightButton.SubModel == nullptr)
|
|
{
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_right) == 0)
|
|
{
|
|
// turn on
|
|
OnCommand_headlightenableright(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_headlightdisableright(Train, Command);
|
|
}
|
|
} else {
|
|
// if the light is controlled by 3-way switch, handle both headlight and redmarker
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_right) == 0 &&
|
|
(Train->mvOccupied->iLights[vehicleend] & light::redmarker_right) == 0)
|
|
{
|
|
// turn on
|
|
OnCommand_headlightenableright(Train, Command);
|
|
}
|
|
else if (Train->mvOccupied->iLights[vehicleend] & light::headlight_right)
|
|
{
|
|
// switch to red
|
|
OnCommand_redmarkerenableright(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// disable
|
|
OnCommand_redmarkerdisableright(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightenableright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->ggRightLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
// implementation
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_right) == 0)
|
|
{
|
|
Train->mvOccupied->iLights[vehicleend] ^= light::headlight_right;
|
|
}
|
|
// if the light is controlled by 3-way switch, disable marker light
|
|
if (Train->ggRightEndLightButton.SubModel == nullptr)
|
|
{
|
|
Train->mvOccupied->iLights[vehicleend] &= ~light::redmarker_right;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightdisableright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_right) == 0)
|
|
{
|
|
return;
|
|
} // already disabled
|
|
|
|
Train->mvOccupied->iLights[vehicleend] ^= light::headlight_right;
|
|
// visual feedback
|
|
Train->ggRightLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlighttoggleupper(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_upper) == 0)
|
|
{
|
|
// turn on
|
|
OnCommand_headlightenableupper(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_headlightdisableupper(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightenableupper(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_upper) != 0)
|
|
{
|
|
return;
|
|
} // already enabled
|
|
|
|
Train->mvOccupied->iLights[vehicleend] ^= light::headlight_upper;
|
|
// visual feedback
|
|
Train->ggUpperLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightdisableupper(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::headlight_upper) == 0)
|
|
{
|
|
return;
|
|
} // already disabled
|
|
|
|
Train->mvOccupied->iLights[vehicleend] ^= light::headlight_upper;
|
|
// visual feedback
|
|
Train->ggUpperLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkertoggleleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::redmarker_left) == 0)
|
|
{
|
|
// turn on
|
|
OnCommand_redmarkerenableleft(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_redmarkerdisableleft(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkerenableleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::redmarker_left) != 0)
|
|
{
|
|
return;
|
|
} // already enabled
|
|
|
|
Train->mvOccupied->iLights[vehicleend] ^= light::redmarker_left;
|
|
// visual feedback
|
|
if (Train->ggLeftEndLightButton.SubModel != nullptr)
|
|
{
|
|
Train->ggLeftEndLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// we interpret lack of dedicated switch as a sign the light is controlled with 3-way switch
|
|
// this is crude, but for now will do
|
|
Train->ggLeftLightButton.UpdateValue(-1.0, Train->dsbSwitch);
|
|
// if the light is controlled by 3-way switch, disable the headlight
|
|
Train->mvOccupied->iLights[vehicleend] &= ~light::headlight_left;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkerdisableleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::redmarker_left) == 0)
|
|
{
|
|
return;
|
|
} // already disabled
|
|
|
|
Train->mvOccupied->iLights[vehicleend] ^= light::redmarker_left;
|
|
// visual feedback
|
|
if (Train->ggLeftEndLightButton.SubModel != nullptr)
|
|
{
|
|
Train->ggLeftEndLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// we interpret lack of dedicated switch as a sign the light is controlled with 3-way switch
|
|
// this is crude, but for now will do
|
|
Train->ggLeftLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkertoggleright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::redmarker_right) == 0)
|
|
{
|
|
// turn on
|
|
OnCommand_redmarkerenableright(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_redmarkerdisableright(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkerenableright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::redmarker_right) != 0)
|
|
{
|
|
return;
|
|
} // already enabled
|
|
|
|
Train->mvOccupied->iLights[vehicleend] ^= light::redmarker_right;
|
|
// visual feedback
|
|
if (Train->ggRightEndLightButton.SubModel != nullptr)
|
|
{
|
|
Train->ggRightEndLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// we interpret lack of dedicated switch as a sign the light is controlled with 3-way switch
|
|
// this is crude, but for now will do
|
|
Train->ggRightLightButton.UpdateValue(-1.0, Train->dsbSwitch);
|
|
// if the light is controlled by 3-way switch, disable the headlight
|
|
Train->mvOccupied->iLights[vehicleend] &= ~light::headlight_right;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkerdisableright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleend{Train->cab_to_end()};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleend] & light::redmarker_right) == 0)
|
|
{
|
|
return;
|
|
} // already disabled
|
|
|
|
Train->mvOccupied->iLights[vehicleend] ^= light::redmarker_right;
|
|
// visual feedback
|
|
if (Train->ggRightEndLightButton.SubModel != nullptr)
|
|
{
|
|
Train->ggRightEndLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// we interpret lack of dedicated switch as a sign the light is controlled with 3-way switch
|
|
// this is crude, but for now will do
|
|
Train->ggRightLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlighttogglerearleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_right) == 0)
|
|
{
|
|
OnCommand_headlightenablerearleft(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_headlightdisablerearleft(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightenablerearleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
// already enabled
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_right) == 0)
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->iLights[vehicleotherend] ^= light::headlight_right;
|
|
// visual feedback
|
|
Train->ggRearLeftLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightdisablerearleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
// already disabled
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_right) == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// turn off
|
|
Train->mvOccupied->iLights[vehicleotherend] ^= light::headlight_right;
|
|
// visual feedback
|
|
Train->ggRearLeftLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlighttogglerearright(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_left) == 0)
|
|
{
|
|
OnCommand_headlightenablerearright(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_headlightdisablerearright(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightenablerearright(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_left) == 0)
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->iLights[vehicleotherend] ^= light::headlight_left;
|
|
// visual feedback
|
|
Train->ggRearRightLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightdisablerearright(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
// already disabled
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_left) == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// turn off
|
|
Train->mvOccupied->iLights[vehicleotherend] ^= light::headlight_left;
|
|
// visual feedback
|
|
Train->ggRearRightLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlighttogglerearupper(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_upper) == 0)
|
|
{
|
|
OnCommand_headlightenablerearupper(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_headlightdisablerearupper(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightenablerearupper(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_upper) == 0)
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->iLights[vehicleotherend] ^= light::headlight_upper;
|
|
// visual feedback
|
|
Train->ggRearUpperLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightdisablerearupper(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
// already disabled?
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::headlight_upper) == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// turn off
|
|
Train->mvOccupied->iLights[vehicleotherend] ^= light::headlight_upper;
|
|
// visual feedback
|
|
Train->ggRearUpperLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_modernlightdimmerincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (!Train->mvOccupied->enableModernDimmer)
|
|
return; // if modern dimmer is disabled, skip entire command
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// update modern dimmer state
|
|
if (false == Train->mvOccupied->stepDimmerPosition(1))
|
|
return; // już na maksimum i nie można cyklicznie
|
|
auto const dimPos = Train->mvOccupied->modernDimmerPosition;
|
|
// update lightning
|
|
// Train->Dynamic()->SetLights();
|
|
Train->Dynamic()->SetLightDimmings();
|
|
|
|
// visual feedback
|
|
if (Train->ggModernLightDimSw.SubModel != nullptr)
|
|
Train->ggModernLightDimSw.UpdateValue(static_cast<float>(dimPos), Train->dsbSwitch);
|
|
}
|
|
}
|
|
void TTrain::OnCommand_modernlightdimmerdecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (!Train->mvOccupied->enableModernDimmer)
|
|
return; // jeśli dimmer jest wyłączony, olewamy
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (false == Train->mvOccupied->stepDimmerPosition(-1))
|
|
return; // już na minimum i nie można cyklicznie
|
|
auto const dimPos = Train->mvOccupied->modernDimmerPosition;
|
|
|
|
// Train->Dynamic()->SetLights();
|
|
Train->Dynamic()->SetLightDimmings();
|
|
|
|
if (Train->ggModernLightDimSw.SubModel != nullptr)
|
|
Train->ggModernLightDimSw.UpdateValue(static_cast<float>(dimPos), Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkertogglerearleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_right) == 0)
|
|
{
|
|
OnCommand_redmarkerenablerearleft(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_redmarkerdisablerearleft(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkerenablerearleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_right) == 0)
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->iLights[vehicleotherend] ^= light::redmarker_right;
|
|
// visual feedback
|
|
Train->ggRearLeftEndLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkerdisablerearleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_right) == 0)
|
|
{
|
|
return;
|
|
}
|
|
// turn off
|
|
Train->mvOccupied->iLights[vehicleotherend] ^= light::redmarker_right;
|
|
// visual feedback
|
|
Train->ggRearLeftEndLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkertogglerearright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_left) == 0)
|
|
{
|
|
OnCommand_redmarkerenablerearright(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_redmarkerdisablerearright(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkerenablerearright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_left) == 0)
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->iLights[vehicleotherend] ^= light::redmarker_left;
|
|
// visual feedback
|
|
Train->ggRearRightEndLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkerdisablerearright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
// lights are controlled by preset selector
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc
|
|
auto const vehicleotherend{(Train->cab_to_end() == end::front ? end::rear : end::front)};
|
|
if ((Train->mvOccupied->iLights[vehicleotherend] & light::redmarker_left) == 0)
|
|
{
|
|
return;
|
|
}
|
|
// turn off
|
|
Train->mvOccupied->iLights[vehicleotherend] ^= light::redmarker_left;
|
|
// visual feedback
|
|
Train->ggRearRightEndLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_redmarkerstoggle(TTrain * /*Train*/, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
auto *vehicle{std::get<TDynamicObject *>(simulation::Region->find_vehicle(Command.location, 10, false, true))};
|
|
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto locationHead = vehicle->HeadPosition() - glm::dvec3(Command.location); // TODO: Maybe command_data should be dvec3?
|
|
auto locationRear = vehicle->RearPosition() - glm::dvec3(Command.location);
|
|
int const CouplNr{std::clamp(vehicle->DirectionGet() * (glm::dot(locationHead, locationHead) > glm::dot(locationRear, locationRear) ? 1 : -1), 0, 1)}; // z [-1,1] zrobić [0,1]
|
|
|
|
auto const lightset{light::redmarker_left | light::redmarker_right};
|
|
|
|
vehicle->MoverParameters->iLights[CouplNr] =
|
|
false == TestFlag(vehicle->MoverParameters->iLights[CouplNr], lightset) ?
|
|
vehicle->MoverParameters->iLights[CouplNr] |= lightset : // turn signals on
|
|
vehicle->MoverParameters->iLights[CouplNr] ^= lightset; // turn signals off
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_endsignalstoggle(TTrain * /*Train*/, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
auto *vehicle{std::get<TDynamicObject *>(simulation::Region->find_vehicle(Command.location, 10, false, true))};
|
|
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
int const CouplNr{
|
|
std::clamp(vehicle->DirectionGet() * (glm::length2(vehicle->HeadPosition() - glm::dvec3(Command.location)) > glm::length2(vehicle->RearPosition() - glm::dvec3(Command.location)) ? 1 : -1), 0,
|
|
1)}; // z [-1,1] zrobić [0,1]
|
|
|
|
auto const lightset{light::rearendsignals};
|
|
|
|
vehicle->MoverParameters->iLights[CouplNr] =
|
|
false == TestFlag(vehicle->MoverParameters->iLights[CouplNr], lightset) ?
|
|
vehicle->MoverParameters->iLights[CouplNr] |= lightset : // turn signals on
|
|
vehicle->MoverParameters->iLights[CouplNr] ^= lightset; // turn signals off
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightsdimtoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Train->DynamicObject->MoverParameters->enableModernDimmer)
|
|
return;
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Train->DynamicObject->MoverParameters->modernDimmerPosition == 0)
|
|
{
|
|
// turn on
|
|
OnCommand_headlightsdimenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_headlightsdimdisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightsdimenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->DynamicObject->MoverParameters->enableModernDimmer)
|
|
return;
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Train->ggDimHeadlightsButton.SubModel != nullptr)
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
// visual feedback
|
|
Train->ggDimHeadlightsButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
|
|
/* // to jest stara logika
|
|
if (true == Train->DynamicObject->DimHeadlights)
|
|
{
|
|
return;
|
|
} // already enabled
|
|
|
|
Train->DynamicObject->DimHeadlights = true;
|
|
*/
|
|
Train->DynamicObject->MoverParameters->modernDimmerPosition = Train->DynamicObject->MoverParameters->clampDimmerPosition(1); // ustawiamy modern dimmer na flage przyciemnienia
|
|
Train->DynamicObject->SetLightDimmings();
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_headlightsdimdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->DynamicObject->MoverParameters->enableModernDimmer) // nie wiem dlaczego to tak dziala ze jest odwrocona logika
|
|
return;
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Train->ggDimHeadlightsButton.SubModel != nullptr)
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
// visual feedback
|
|
Train->ggDimHeadlightsButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
|
|
/* // stara logika przyciemniania
|
|
if( false == Train->DynamicObject->DimHeadlights ) { return; } // already enabled
|
|
|
|
Train->DynamicObject->DimHeadlights = false;
|
|
|
|
*/
|
|
Train->DynamicObject->MoverParameters->modernDimmerPosition = 0; // ustawiamy modern dimmer na flage rozjasnienia
|
|
Train->DynamicObject->SetLightDimmings();
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_interiorlighttoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->Cabine[Train->iCabn].bLight)
|
|
{
|
|
// turn on
|
|
OnCommand_interiorlightenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_interiorlightdisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_interiorlightenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->m_controlmapper.contains("cablight_sw:"))
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
WriteLog("Interior Light switch is missing, or wasn't defined");
|
|
return;
|
|
}
|
|
// store lighting switch states
|
|
if (false == Train->DynamicObject->JointCabs)
|
|
{
|
|
// vehicles with separate cabs get separate lighting switch states
|
|
Train->Cabine[Train->iCabn].bLight = true;
|
|
}
|
|
else
|
|
{
|
|
// joint virtual cabs share lighting switch states
|
|
for (auto &cab : Train->Cabine)
|
|
{
|
|
cab.bLight = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_interiorlightdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->m_controlmapper.contains("cablight_sw:"))
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
WriteLog("Interior Light switch is missing, or wasn't defined");
|
|
return;
|
|
}
|
|
// store lighting switch states
|
|
if (false == Train->DynamicObject->JointCabs)
|
|
{
|
|
// vehicles with separate cabs get separate lighting switch states
|
|
Train->Cabine[Train->iCabn].bLight = false;
|
|
}
|
|
else
|
|
{
|
|
// joint virtual cabs share lighting switch states
|
|
for (auto &cab : Train->Cabine)
|
|
{
|
|
cab.bLight = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_interiorlightdimtoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->Cabine[Train->iCabn].bLightDim)
|
|
{
|
|
// turn on
|
|
OnCommand_interiorlightdimenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_interiorlightdimdisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_interiorlightdimenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Train->ggCabLightDimButton.SubModel == nullptr)
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
WriteLog("Dim Interior Light switch is missing, or wasn't defined");
|
|
return;
|
|
}
|
|
// visual feedback
|
|
Train->ggCabLightDimButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
// store lighting switch states
|
|
if (false == Train->DynamicObject->JointCabs)
|
|
{
|
|
// vehicles with separate cabs get separate lighting switch states
|
|
Train->Cabine[Train->iCabn].bLightDim = true;
|
|
}
|
|
else
|
|
{
|
|
// joint virtual cabs share lighting switch states
|
|
for (auto &cab : Train->Cabine)
|
|
{
|
|
cab.bLightDim = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_interiorlightdimdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Train->ggCabLightDimButton.SubModel == nullptr)
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
WriteLog("Dim Interior Light switch is missing, or wasn't defined");
|
|
return;
|
|
}
|
|
// visual feedback
|
|
Train->ggCabLightDimButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
// store lighting switch states
|
|
if (false == Train->DynamicObject->JointCabs)
|
|
{
|
|
// vehicles with separate cabs get separate lighting switch states
|
|
Train->Cabine[Train->iCabn].bLightDim = false;
|
|
}
|
|
else
|
|
{
|
|
// joint virtual cabs share lighting switch states
|
|
for (auto &cab : Train->Cabine)
|
|
{
|
|
cab.bLightDim = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_compartmentlightstoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// the press changed the state the command is picked from below, so a release picked from it went to the other
|
|
// command and the push button that was pressed never withdrew its request. The release goes to both commands:
|
|
// each returns its own push type control to the neutral position and withdraws its request
|
|
OnCommand_compartmentlightsenable(Train, Command);
|
|
OnCommand_compartmentlightsdisable(Train, Command);
|
|
return;
|
|
}
|
|
|
|
// keep the switch from flipping back and forth if key is held down
|
|
if (false == Train->mvOccupied->CompartmentLights.is_active && false == Train->mvOccupied->CompartmentLights.is_enabled)
|
|
{
|
|
// turn on
|
|
OnCommand_compartmentlightsenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_compartmentlightsdisable(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_compartmentlightsenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvOccupied->CompartmentLightsSwitch(true);
|
|
// withdraw the off request, unless a push type control in the cab withdraws it when released
|
|
if (compartment_lights_switch::withdraws_other_request(Train->m_controlmapper.contains("compartmentlights_sw:"), Train->ggCompartmentLightsButton.is_toggle(),
|
|
Train->m_controlmapper.contains("compartmentlightsoff_sw:")))
|
|
{
|
|
Train->mvOccupied->CompartmentLightsSwitchOff(false);
|
|
}
|
|
// visual feedback
|
|
if (Train->m_controlmapper.contains("compartmentlights_sw:"))
|
|
{
|
|
Train->ggCompartmentLightsButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
}
|
|
if (Train->m_controlmapper.contains("compartmentlightson_sw:"))
|
|
{
|
|
Train->ggCompartmentLightsOnButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
if (Train->m_controlmapper.contains("compartmentlights_sw:") && Train->ggCompartmentLightsButton.type() == TGaugeType::push)
|
|
{
|
|
// return the switch to neutral position
|
|
Train->mvOccupied->CompartmentLightsSwitch(false);
|
|
Train->mvOccupied->CompartmentLightsSwitchOff(false);
|
|
Train->ggCompartmentLightsButton.UpdateValue(0.5f);
|
|
}
|
|
if (Train->m_controlmapper.contains("compartmentlightson_sw:"))
|
|
{
|
|
Train->mvOccupied->CompartmentLightsSwitch(false);
|
|
Train->ggCompartmentLightsOnButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_compartmentlightsdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvOccupied->CompartmentLightsSwitchOff(true);
|
|
// withdraw the on request, unless a push type control in the cab withdraws it when released
|
|
if (compartment_lights_switch::withdraws_other_request(Train->m_controlmapper.contains("compartmentlights_sw:"), Train->ggCompartmentLightsButton.is_toggle(),
|
|
Train->m_controlmapper.contains("compartmentlightson_sw:")))
|
|
{
|
|
Train->mvOccupied->CompartmentLightsSwitch(false);
|
|
}
|
|
// visual feedback
|
|
if (Train->m_controlmapper.contains("compartmentlights_sw:"))
|
|
{
|
|
Train->ggCompartmentLightsButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
}
|
|
if (Train->m_controlmapper.contains("compartmentlightsoff_sw:"))
|
|
{
|
|
Train->ggCompartmentLightsOffButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
if (Train->m_controlmapper.contains("compartmentlights_sw:") && Train->ggCompartmentLightsButton.type() == TGaugeType::push)
|
|
{
|
|
// return the switch to neutral position
|
|
Train->mvOccupied->CompartmentLightsSwitch(false);
|
|
Train->mvOccupied->CompartmentLightsSwitchOff(false);
|
|
Train->ggCompartmentLightsButton.UpdateValue(0.5f);
|
|
}
|
|
if (Train->m_controlmapper.contains("compartmentlightsoff_sw:"))
|
|
{
|
|
Train->mvOccupied->CompartmentLightsSwitchOff(false);
|
|
Train->ggCompartmentLightsOffButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_instrumentlighttoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->InstrumentLightActive)
|
|
{
|
|
// turn on
|
|
OnCommand_instrumentlightenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_instrumentlightdisable(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_instrumentlightenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Train->ggInstrumentLightButton.SubModel == nullptr)
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
WriteLog("Instrument Light switch is missing, or wasn't defined");
|
|
return;
|
|
}
|
|
// visual feedback
|
|
Train->ggInstrumentLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
|
|
if (true == Train->InstrumentLightActive)
|
|
{
|
|
return;
|
|
} // already enabled
|
|
|
|
Train->InstrumentLightActive = true;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_instrumentlightdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Train->ggInstrumentLightButton.SubModel == nullptr)
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
WriteLog("Instrument Light switch is missing, or wasn't defined");
|
|
return;
|
|
}
|
|
// visual feedback
|
|
Train->ggInstrumentLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
|
|
if (false == Train->InstrumentLightActive)
|
|
{
|
|
return;
|
|
} // already disabled
|
|
|
|
Train->InstrumentLightActive = false;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_dashboardlighttoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (false == Train->DashboardLightActive)
|
|
{
|
|
OnCommand_dashboardlightenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_dashboardlightdisable(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_dashboardlightenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggDashboardLightButton.SubModel == nullptr)
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
WriteLog("Dashboard Light switch is missing, or wasn't defined");
|
|
return;
|
|
}
|
|
|
|
if (false == Train->DashboardLightActive)
|
|
{
|
|
// turn on
|
|
Train->DashboardLightActive = true;
|
|
// visual feedback
|
|
Train->ggDashboardLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_dashboardlightdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggDashboardLightButton.SubModel == nullptr)
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
WriteLog("Dashboard Light switch is missing, or wasn't defined");
|
|
return;
|
|
}
|
|
|
|
if (Train->DashboardLightActive)
|
|
{
|
|
// turn off
|
|
Train->DashboardLightActive = false;
|
|
// visual feedback
|
|
Train->ggDashboardLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_timetablelighttoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (false == Train->TimetableLightActive)
|
|
{
|
|
OnCommand_timetablelightenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
OnCommand_timetablelightdisable(Train, Command);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_timetablelightenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggTimetableLightButton.SubModel == nullptr)
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
WriteLog("Timetable Light switch is missing, or wasn't defined");
|
|
return;
|
|
}
|
|
|
|
if (false == Train->TimetableLightActive)
|
|
{
|
|
// turn on
|
|
Train->TimetableLightActive = true;
|
|
// visual feedback
|
|
Train->ggTimetableLightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_timetablelightdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggTimetableLightButton.SubModel == nullptr)
|
|
{
|
|
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
|
|
WriteLog("Timetable Light switch is missing, or wasn't defined");
|
|
return;
|
|
}
|
|
if (Train->TimetableLightActive)
|
|
{
|
|
// turn off
|
|
Train->TimetableLightActive = false;
|
|
// visual feedback
|
|
Train->ggTimetableLightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_heatingtoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->ggTrainHeatingButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Train Heating switch is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// ignore repeats so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvControlled->HeatingAllow)
|
|
{
|
|
// turn on
|
|
OnCommand_heatingenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_heatingdisable(Train, Command);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE && (Train->ggTrainHeatingButton.type() == TGaugeType::push || Train->mvOccupied->HeatingSwitchImpulse))
|
|
{
|
|
// impulse switch
|
|
// visual feedback
|
|
Train->ggTrainHeatingButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_heatingenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->mvOccupied->HeatingSwitch(true);
|
|
// visual feedback
|
|
Train->ggTrainHeatingButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE && Train->mvOccupied->HeatingSwitchImpulse)
|
|
{
|
|
// the switch springs back to the middle
|
|
Train->ggTrainHeatingButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_heatingdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->mvOccupied->HeatingSwitch(false);
|
|
// visual feedback: an impulse switch is pushed the other way, down
|
|
auto position{0.0};
|
|
if (Train->mvOccupied->HeatingSwitchImpulse)
|
|
{
|
|
position = -1.0;
|
|
}
|
|
else if (Train->ggTrainHeatingButton.type() == TGaugeType::push)
|
|
{
|
|
position = 1.0;
|
|
}
|
|
Train->ggTrainHeatingButton.UpdateValue(position, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE && Train->mvOccupied->HeatingSwitchImpulse)
|
|
{
|
|
Train->ggTrainHeatingButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_generictoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
auto const itemindex = static_cast<int>(Command.command) - static_cast<int>(user_command::generictoggle0);
|
|
auto &item = Train->ggUniversals[itemindex];
|
|
/*
|
|
if( item.SubModel == nullptr ) {
|
|
if( Command.action == GLFW_PRESS ) {
|
|
WriteLog( "Train generic item " + std::to_string( itemindex ) + " is missing, or wasn't defined" );
|
|
}
|
|
return;
|
|
}
|
|
*/
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
if (item.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// turn on
|
|
// visual feedback
|
|
item.UpdateValue(1.0);
|
|
}
|
|
else
|
|
{
|
|
// two-state switch, or one dragged in between its ends with the mouse: to the end farther from it
|
|
// visual feedback
|
|
item.UpdateValue(universal_drag::toggled(item.GetDesiredValue()));
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE && item.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// turn off
|
|
// visual feedback
|
|
item.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
// sets a universal control to the position given in param1, from 0 to 1 (MaSzyna-EU07/maszyna#62): the mouse drags
|
|
// the ones with drag: in their definition, and it can be bound to an axis of a gamepad. it stays where it is set
|
|
void TTrain::OnCommand_genericset(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_RELEASE)
|
|
{
|
|
return;
|
|
}
|
|
auto const itemindex = static_cast<int>(Command.command) - static_cast<int>(user_command::genericset0);
|
|
auto &item = Train->ggUniversals[itemindex];
|
|
if (item.is_push())
|
|
{
|
|
// an impulse switch springs back, it has no position to be left in
|
|
return;
|
|
}
|
|
// visual feedback
|
|
item.UpdateValue(universal_drag::clamp(Command.param1));
|
|
}
|
|
|
|
universal_drag::direction TTrain::universal_drag_direction(int const Index) const
|
|
{
|
|
|
|
if (Index < 0 || Index >= static_cast<int>(ggUniversals.size()) || ggUniversals[Index].SubModel == nullptr)
|
|
{
|
|
return universal_drag::direction::none;
|
|
}
|
|
return ggUniversals[Index].drag();
|
|
}
|
|
|
|
float TTrain::universal_position(int const Index) const
|
|
{
|
|
|
|
if (Index < 0 || Index >= static_cast<int>(ggUniversals.size()))
|
|
{
|
|
return 0.f;
|
|
}
|
|
return ggUniversals[Index].GetDesiredValue();
|
|
}
|
|
|
|
void TTrain::OnCommand_springbraketoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvOccupied->SpringBrake.Activate)
|
|
{
|
|
// turn on
|
|
OnCommand_springbrakeenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_springbrakedisable(Train, Command);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggSpringBrakeOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
Train->ggSpringBrakeOnButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_springbrakeenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvOccupied->SpringBrakeActivate(true);
|
|
// visual feedback
|
|
Train->ggSpringBrakeOnButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
Train->ggSpringBrakeOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggSpringBrakeOnButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_springbrakedisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvOccupied->SpringBrakeActivate(false);
|
|
// visual feedback
|
|
Train->ggSpringBrakeOffButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
Train->ggSpringBrakeOnButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggSpringBrakeOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
void TTrain::OnCommand_springbrakeshutofftoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
if (false == Train->mvOccupied->SpringBrake.ShuttOff)
|
|
{
|
|
// turn on
|
|
OnCommand_springbrakeshutoffenable(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
OnCommand_springbrakeshutoffdisable(Train, Command);
|
|
}
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_springbrakeshutoffenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvOccupied->SpringBrakeShutOff(true);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_springbrakeshutoffdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvOccupied->SpringBrakeShutOff(false);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_springbrakerelease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
|
|
if (auto const *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)}; vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
Train->mvOccupied->SpringBrakeRelease();
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_speedcontrolincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvOccupied->SpeedCtrlInc();
|
|
// visual feedback
|
|
Train->ggSpeedControlIncreaseButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggSpeedControlIncreaseButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_speedcontroldecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvOccupied->SpeedCtrlDec();
|
|
// visual feedback
|
|
Train->ggSpeedControlDecreaseButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggSpeedControlDecreaseButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_speedcontrolpowerincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvOccupied->SpeedCtrlPowerInc();
|
|
// visual feedback
|
|
Train->ggSpeedControlPowerIncreaseButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggSpeedControlPowerIncreaseButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_speedcontrolpowerdecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvOccupied->SpeedCtrlPowerDec();
|
|
// visual feedback
|
|
Train->ggSpeedControlPowerDecreaseButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggSpeedControlPowerDecreaseButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_speedcontrolbutton(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
auto const itemindex = static_cast<int>(Command.command) - static_cast<int>(user_command::speedcontrolbutton0);
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
Train->mvOccupied->SpeedCtrlButton(itemindex);
|
|
// visual feedback
|
|
Train->ggSpeedCtrlButtons[itemindex].UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
Train->ggSpeedCtrlButtons[itemindex].UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_inverterenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
auto itemindex = static_cast<int>(Command.command) - static_cast<int>(user_command::inverterenable1);
|
|
auto &item = Train->ggInverterEnableButtons[itemindex];
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
bool kier = Train->DynamicObject->DirectionGet() * Train->mvOccupied->CabOccupied > 0;
|
|
int flag = Train->DynamicObject->MoverParameters->InverterControlCouplerFlag;
|
|
TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? end::rear : end::front, flag);
|
|
while (p)
|
|
{
|
|
if (p->MoverParameters->eimc[eimc_p_Pmax] > 1)
|
|
{
|
|
if (itemindex < p->MoverParameters->InvertersNo)
|
|
{
|
|
p->MoverParameters->Inverters[itemindex].Activate = true;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
itemindex -= p->MoverParameters->InvertersNo;
|
|
}
|
|
}
|
|
p = kier ? p->Next(flag) : p->Prev(flag);
|
|
}
|
|
// visual feedback
|
|
item.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
item.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_inverterdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
auto itemindex = static_cast<int>(Command.command) - static_cast<int>(user_command::inverterdisable1);
|
|
auto &item = Train->ggInverterDisableButtons[itemindex];
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
bool kier = Train->DynamicObject->DirectionGet() * Train->mvOccupied->CabOccupied > 0;
|
|
int flag = Train->DynamicObject->MoverParameters->InverterControlCouplerFlag;
|
|
TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? end::rear : end::front, flag);
|
|
while (p)
|
|
{
|
|
if (p->MoverParameters->eimc[eimc_p_Pmax] > 1)
|
|
{
|
|
if (itemindex < p->MoverParameters->InvertersNo)
|
|
{
|
|
p->MoverParameters->Inverters[itemindex].Activate = false;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
itemindex -= p->MoverParameters->InvertersNo;
|
|
}
|
|
}
|
|
p = kier ? p->Next(flag) : p->Prev(flag);
|
|
}
|
|
// visual feedback
|
|
item.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// release
|
|
// visual feedback
|
|
item.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_invertertoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
auto itemindex = static_cast<int>(Command.command) - static_cast<int>(user_command::invertertoggle1);
|
|
auto &item = Train->ggInverterToggleButtons[itemindex];
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the switch doesn't flip back and forth if key is held down
|
|
bool kier = Train->DynamicObject->DirectionGet() * Train->mvOccupied->CabOccupied > 0;
|
|
int flag = Train->DynamicObject->MoverParameters->InverterControlCouplerFlag;
|
|
TDynamicObject *p = Train->DynamicObject->GetFirstDynamic(Train->mvOccupied->CabOccupied < 0 ? end::rear : end::front, flag);
|
|
while (p)
|
|
{
|
|
if (p->MoverParameters->eimc[eimc_p_Pmax] > 1)
|
|
{
|
|
if (itemindex < p->MoverParameters->InvertersNo)
|
|
{
|
|
p->MoverParameters->Inverters[itemindex].Activate = !p->MoverParameters->Inverters[itemindex].Activate;
|
|
// visual feedback
|
|
item.UpdateValue(p->MoverParameters->Inverters[itemindex].Activate ? 1.0 : 0.0, Train->dsbSwitch);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
itemindex -= p->MoverParameters->InvertersNo;
|
|
}
|
|
}
|
|
p = kier ? p->Next(flag) : p->Prev(flag);
|
|
}
|
|
}
|
|
};
|
|
|
|
void TTrain::OnCommand_doorlocktoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->ggDoorSignallingButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Door Lock switch is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the sound can loop uninterrupted
|
|
if (false == Train->mvOccupied->Doors.lock_enabled)
|
|
{
|
|
// turn on
|
|
// TODO: door lock command to send through consist
|
|
Train->mvOccupied->LockDoors(true);
|
|
// visual feedback
|
|
Train->ggDoorSignallingButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
// TODO: door lock command to send through consist
|
|
Train->mvOccupied->LockDoors(false);
|
|
// visual feedback
|
|
Train->ggDoorSignallingButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_doortoggleleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: test how the door state check works with consists where the occupied vehicle doesn't have opening doors
|
|
if (false == (Train->ggDoorLeftButton.GetDesiredValue() > 0.5 || Train->ggDoorLeftOnButton.GetDesiredValue() > 0.5))
|
|
{
|
|
// open
|
|
OnCommand_dooropenleft(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// close
|
|
if (Train->ggDoorAllOffButton.SubModel != nullptr && Train->ggDoorLeftOffButton.SubModel == nullptr)
|
|
{
|
|
// OnCommand_doorcloseall( Train, Command );
|
|
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
OnCommand_doorcloseleft(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
|
|
if (true == (Train->ggDoorLeftButton.GetDesiredValue() > 0.5 || Train->ggDoorLeftOnButton.GetDesiredValue() > 0.5))
|
|
{
|
|
// open
|
|
if (Train->mvOccupied->Doors.has_autowarning && Train->mvOccupied->DepartureSignal)
|
|
{
|
|
// complete closing the doors
|
|
if (Train->ggDoorAllOffButton.SubModel != nullptr && Train->ggDoorLeftOffButton.SubModel == nullptr)
|
|
{
|
|
// OnCommand_doorcloseall( Train, Command );
|
|
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
OnCommand_doorcloseleft(Train, Command);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
OnCommand_dooropenleft(Train, Command);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// close
|
|
if (Train->ggDoorAllOffButton.SubModel != nullptr && Train->ggDoorLeftOffButton.SubModel == nullptr)
|
|
{
|
|
// OnCommand_doorcloseall( Train, Command );
|
|
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
OnCommand_doorcloseleft(Train, Command);
|
|
}
|
|
}
|
|
// visual feedback
|
|
// dedicated closing buttons are presumed to be impulse switches and return automatically to neutral position
|
|
// NOTE: temporary arrangement, can be removed when LD system is in place
|
|
if (Train->ggDoorLeftOffButton.SubModel)
|
|
Train->ggDoorLeftOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
if (Train->ggDoorLeftOnButton.SubModel)
|
|
Train->ggDoorLeftOnButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_doorpermitleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
if (false == Train->mvOccupied->Doors.permit_presets.empty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto const side{(Train->cab_to_end() == end::front ? side::left : side::right)};
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
if (Train->ggDoorLeftPermitButton.is_push())
|
|
{
|
|
// impulse switch
|
|
Train->mvOccupied->PermitDoors(side);
|
|
// visual feedback
|
|
Train->ggDoorLeftPermitButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
// start potential timer for remote door control
|
|
Train->m_doorpermittimers[side] = Train->mvOccupied->DoorsOpenWithPermitAfter;
|
|
}
|
|
else
|
|
{
|
|
// two-state switch
|
|
auto const newstate{!(Train->ggDoorLeftPermitButton.GetDesiredValue() > 0.5)};
|
|
|
|
Train->mvOccupied->PermitDoors(side, newstate);
|
|
// visual feedback
|
|
Train->ggDoorLeftPermitButton.UpdateValue(newstate ? 1.0 : 0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE && Train->ggDoorLeftPermitButton.is_push())
|
|
{
|
|
// impulse switch
|
|
// visual feedback
|
|
Train->ggDoorLeftPermitButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
// reset potential remote door control timer
|
|
Train->m_doorpermittimers[side] = -1.f;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_doorpermitright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_REPEAT)
|
|
{
|
|
return;
|
|
}
|
|
if (false == Train->mvOccupied->Doors.permit_presets.empty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto const side{(Train->cab_to_end() == end::front ? side::right : side::left)};
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
if (Train->ggDoorRightPermitButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
Train->mvOccupied->PermitDoors(side);
|
|
// visual feedback
|
|
Train->ggDoorRightPermitButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
// start potential timer for remote door control
|
|
Train->m_doorpermittimers[side] = Train->mvOccupied->DoorsOpenWithPermitAfter;
|
|
}
|
|
else
|
|
{
|
|
// two-state switch
|
|
auto const newstate{!(Train->ggDoorRightPermitButton.GetDesiredValue() > 0.5)};
|
|
|
|
Train->mvOccupied->PermitDoors(side, newstate);
|
|
// visual feedback
|
|
Train->ggDoorRightPermitButton.UpdateValue(newstate ? 1.0 : 0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE && Train->ggDoorRightPermitButton.type() == TGaugeType::push)
|
|
{
|
|
// impulse switch
|
|
// visual feedback
|
|
Train->ggDoorRightPermitButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
// reset potential remote door control timer
|
|
Train->m_doorpermittimers[side] = -1.f;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_doorpermitpresetactivatenext(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->mvOccupied->ChangeDoorPermitPreset(1);
|
|
// visual feedback
|
|
Train->ggDoorPermitPresetButton.UpdateValue(static_cast<float>(Train->mvOccupied->Doors.permit_preset), Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_doorpermitpresetactivateprevious(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->mvOccupied->ChangeDoorPermitPreset(-1);
|
|
// visual feedback
|
|
Train->ggDoorPermitPresetButton.UpdateValue(static_cast<float>(Train->mvOccupied->Doors.permit_preset), Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_dooropenleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
|
|
if (auto const remoteopencontrol{Train->mvOccupied->Doors.open_control == control_t::driver || Train->mvOccupied->Doors.open_control == control_t::mixed}; false == remoteopencontrol)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggDoorLeftOnButton.SubModel == nullptr && Train->ggDoorLeftButton.SubModel == nullptr)
|
|
{
|
|
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::left : side::right, true);
|
|
// visual feedback
|
|
if (Train->ggDoorLeftOnButton.SubModel != nullptr)
|
|
{
|
|
// two separate impulse switches
|
|
Train->ggDoorLeftOnButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// single two-state switch
|
|
Train->ggDoorLeftButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
if (Train->ggDoorLeftOnButton.SubModel != nullptr)
|
|
{
|
|
// two separate impulse switches
|
|
Train->ggDoorLeftOnButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_doorcloseleft(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
|
|
if (auto const remoteclosecontrol{Train->mvOccupied->Doors.close_control == control_t::driver || Train->mvOccupied->Doors.close_control == control_t::mixed}; false == remoteclosecontrol)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggDoorLeftOffButton.SubModel == nullptr && Train->ggDoorLeftButton.SubModel == nullptr)
|
|
{
|
|
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
if (Train->mvOccupied->Doors.has_autowarning)
|
|
{
|
|
// automatic departure signal delays actual door closing until the button is released
|
|
Train->mvOccupied->signal_departure(true);
|
|
}
|
|
else
|
|
{
|
|
// TODO: move door opening/closing to the update, so the switch animation doesn't hinge on door working
|
|
Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::left : side::right, false);
|
|
}
|
|
// visual feedback
|
|
if (Train->ggDoorLeftOffButton.SubModel != nullptr)
|
|
{
|
|
// two separate switches to open and close the door
|
|
Train->ggDoorLeftOffButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// single two-state switch
|
|
Train->ggDoorLeftButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
|
|
if (Train->mvOccupied->Doors.has_autowarning)
|
|
{
|
|
// automatic departure signal delays actual door closing until the button is released
|
|
Train->mvOccupied->signal_departure(false);
|
|
// now we can actually close the door
|
|
Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::left : side::right, false);
|
|
}
|
|
// visual feedback
|
|
// dedicated closing buttons are presumed to be impulse switches and return automatically to neutral position
|
|
if (Train->ggDoorLeftOffButton.SubModel)
|
|
Train->ggDoorLeftOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_doortoggleright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// NOTE: test how the door state check works with consists where the occupied vehicle doesn't have opening doors
|
|
if (false == (Train->ggDoorRightButton.GetDesiredValue() > 0.5 || Train->ggDoorRightOnButton.GetDesiredValue() > 0.5))
|
|
{
|
|
// open
|
|
OnCommand_dooropenright(Train, Command);
|
|
}
|
|
else
|
|
{
|
|
// close
|
|
if (Train->ggDoorAllOffButton.SubModel != nullptr && Train->ggDoorRightOffButton.SubModel == nullptr)
|
|
{
|
|
// OnCommand_doorcloseall( Train, Command );
|
|
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
OnCommand_doorcloseright(Train, Command);
|
|
}
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
|
|
if (true == (Train->ggDoorRightButton.GetDesiredValue() > 0.5 || Train->ggDoorRightOnButton.GetDesiredValue() > 0.5))
|
|
{
|
|
// open
|
|
if (Train->mvOccupied->Doors.has_autowarning && Train->mvOccupied->DepartureSignal)
|
|
{
|
|
// complete closing the doors
|
|
if (Train->ggDoorAllOffButton.SubModel != nullptr && Train->ggDoorRightOffButton.SubModel == nullptr)
|
|
{
|
|
// OnCommand_doorcloseall( Train, Command );
|
|
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
OnCommand_doorcloseright(Train, Command);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
OnCommand_dooropenright(Train, Command);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// close
|
|
if (Train->ggDoorAllOffButton.SubModel != nullptr && Train->ggDoorRightOffButton.SubModel == nullptr)
|
|
{
|
|
// OnCommand_doorcloseall( Train, Command );
|
|
// if two-button setup lacks dedicated closing button require the user to press appropriate button manually
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
OnCommand_doorcloseright(Train, Command);
|
|
}
|
|
}
|
|
// visual feedback
|
|
// dedicated closing buttons are presumed to be impulse switches and return automatically to neutral position
|
|
// NOTE: temporary arrangement, can be removed when LD system is in place
|
|
if (Train->ggDoorRightOffButton.SubModel)
|
|
Train->ggDoorRightOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
if (Train->ggDoorRightOnButton.SubModel)
|
|
Train->ggDoorRightOnButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_dooropenright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
|
|
if (auto const remoteopencontrol{Train->mvOccupied->Doors.open_control == control_t::driver || Train->mvOccupied->Doors.open_control == control_t::mixed}; false == remoteopencontrol)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggDoorRightOnButton.SubModel == nullptr && Train->ggDoorRightButton.SubModel == nullptr)
|
|
{
|
|
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::right : side::left, true);
|
|
// visual feedback
|
|
if (Train->ggDoorRightOnButton.SubModel != nullptr)
|
|
{
|
|
// two separate impulse switches
|
|
Train->ggDoorRightOnButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// single two-state switch
|
|
Train->ggDoorRightButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
if (Train->ggDoorRightOnButton.SubModel != nullptr)
|
|
{
|
|
// two separate impulse switches
|
|
Train->ggDoorRightOnButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_doorcloseright(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
|
|
if (auto const remoteclosecontrol{Train->mvOccupied->Doors.close_control == control_t::driver || Train->mvOccupied->Doors.close_control == control_t::mixed}; false == remoteclosecontrol)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggDoorRightOffButton.SubModel == nullptr && Train->ggDoorRightButton.SubModel == nullptr)
|
|
{
|
|
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
if (Train->mvOccupied->Doors.has_autowarning)
|
|
{
|
|
// automatic departure signal delays actual door closing until the button is released
|
|
Train->mvOccupied->signal_departure(true);
|
|
}
|
|
else
|
|
{
|
|
Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::right : side::left, false);
|
|
}
|
|
// visual feedback
|
|
if (Train->ggDoorRightOffButton.SubModel != nullptr)
|
|
{
|
|
// two separate switches to open and close the door
|
|
Train->ggDoorRightOffButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else
|
|
{
|
|
// single two-state switch
|
|
Train->ggDoorRightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
|
|
if (Train->mvOccupied->Doors.has_autowarning)
|
|
{
|
|
// automatic departure signal delays actual door closing until the button is released
|
|
Train->mvOccupied->signal_departure(false);
|
|
// now we can actually close the door
|
|
Train->mvOccupied->OperateDoors(Train->cab_to_end() == end::front ? side::right : side::left, false);
|
|
}
|
|
// visual feedback
|
|
// dedicated closing buttons are presumed to be impulse switches and return automatically to neutral position
|
|
if (Train->ggDoorRightOffButton.SubModel)
|
|
Train->ggDoorRightOffButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_dooropenall(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
|
|
if (auto const remoteopencontrol{Train->mvOccupied->Doors.open_control == control_t::driver || Train->mvOccupied->Doors.open_control == control_t::mixed}; false == remoteopencontrol)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggDoorAllOnButton.SubModel == nullptr)
|
|
{
|
|
// TODO: expand definition of cab controls so we can know if the control is present without testing for presence of 3d switch
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Open All Doors switch is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
Train->mvOccupied->OperateDoors(side::right, true);
|
|
Train->mvOccupied->OperateDoors(side::left, true);
|
|
// visual feedback
|
|
Train->ggDoorAllOnButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggDoorAllOnButton.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_doorcloseall(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
|
|
if (auto const remoteclosecontrol{Train->mvOccupied->Doors.close_control == control_t::driver || Train->mvOccupied->Doors.close_control == control_t::mixed}; false == remoteclosecontrol)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->ggDoorAllOffButton.SubModel == nullptr)
|
|
{
|
|
// TODO: expand definition of cab controls so we can know if the control is present without testing for presence of 3d switch
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Close All Doors switch is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
|
|
if (Train->mvOccupied->Doors.has_autowarning)
|
|
{
|
|
Train->mvOccupied->signal_departure(true);
|
|
}
|
|
if (Train->ggDoorAllOffButton.type() != TGaugeType::push_delayed)
|
|
{
|
|
// delays the action until the button is released
|
|
Train->mvOccupied->OperateDoors(side::right, false);
|
|
Train->mvOccupied->OperateDoors(side::left, false);
|
|
}
|
|
// visual feedback
|
|
Train->ggDoorLeftButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
Train->ggDoorRightButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
if (Train->ggDoorAllOffButton.SubModel)
|
|
Train->ggDoorAllOffButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
if (Train->mvOccupied->Doors.has_autowarning)
|
|
{
|
|
Train->mvOccupied->signal_departure(false);
|
|
}
|
|
if (Train->ggDoorAllOffButton.type() == TGaugeType::push_delayed)
|
|
{
|
|
// now we can actually close the door
|
|
Train->mvOccupied->OperateDoors(side::right, false);
|
|
Train->mvOccupied->OperateDoors(side::left, false);
|
|
}
|
|
// visual feedback
|
|
if (Train->ggDoorAllOffButton.SubModel)
|
|
Train->ggDoorAllOffButton.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_doorsteptoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
// TODO: move logic/visualization code to the gauge, on_command() should return hint whether it should invoke a reaction
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// effect
|
|
if (false == Train->ggDoorStepButton.is_delayed())
|
|
{
|
|
Train->mvOccupied->PermitDoorStep(false == Train->mvOccupied->Doors.step_enabled);
|
|
}
|
|
// visual feedback
|
|
auto const isactive{(Train->ggDoorStepButton.is_push() // always press push button
|
|
|| Train->mvOccupied->Doors.step_enabled)}; // for toggle buttons indicate item state
|
|
Train->ggDoorStepButton.UpdateValue(isactive ? 1 : 0);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// effect
|
|
if (Train->ggDoorStepButton.is_delayed())
|
|
{
|
|
Train->mvOccupied->PermitDoorStep(false == Train->mvOccupied->Doors.step_enabled);
|
|
}
|
|
// visual feedback
|
|
if (Train->ggDoorStepButton.is_push())
|
|
{
|
|
Train->ggDoorStepButton.UpdateValue(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_doormodetoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvOccupied->ChangeDoorControlMode(false == Train->mvOccupied->Doors.remote_only);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_mirrorstoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// only reacting to press, so the sound can loop uninterrupted
|
|
if (false == Train->mvOccupied->MirrorForbidden)
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->MirrorForbidden = true;
|
|
}
|
|
else
|
|
{
|
|
// turn off
|
|
Train->mvOccupied->MirrorForbidden = false;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_nearestcarcouplingincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
// tryb freefly, press only
|
|
auto couplerindex{-1};
|
|
auto *vehicle{Train->DynamicObject->ABuScanNearestObject(Command.location, Train->DynamicObject->GetTrack(), 1, 1500, couplerindex)};
|
|
if (vehicle == nullptr)
|
|
vehicle = Train->DynamicObject->ABuScanNearestObject(Command.location, Train->DynamicObject->GetTrack(), -1, 1500, couplerindex);
|
|
|
|
if (couplerindex != -1 && vehicle != nullptr)
|
|
{
|
|
|
|
vehicle->couple(couplerindex);
|
|
}
|
|
if (Train->DynamicObject->Mechanik)
|
|
{
|
|
// aktualizacja flag kierunku w składzie
|
|
Train->DynamicObject->Mechanik->CheckVehicles(Connect);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_nearestcarcouplingdisconnect(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
// tryb freefly, press only
|
|
auto couplerindex{-1};
|
|
auto *vehicle{Train->DynamicObject->ABuScanNearestObject(Command.location, Train->DynamicObject->GetTrack(), 1, 1500, couplerindex)};
|
|
if (vehicle == nullptr)
|
|
vehicle = Train->DynamicObject->ABuScanNearestObject(Command.location, Train->DynamicObject->GetTrack(), -1, 1500, couplerindex);
|
|
|
|
if (couplerindex != -1 && vehicle != nullptr)
|
|
{
|
|
|
|
vehicle->uncouple(couplerindex);
|
|
}
|
|
if (Train->DynamicObject->Mechanik)
|
|
{
|
|
// aktualizacja flag kierunku w składzie
|
|
Train->DynamicObject->Mechanik->CheckVehicles(Disconnect);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_nearestcarcoupleradapterattach(TTrain * /*Train*/, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
// tryb freefly, press only
|
|
auto *vehicle{std::get<TDynamicObject *>(simulation::Region->find_vehicle(Command.location, 50, false, true))};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto const couplerindex =
|
|
glm::length2(glm::vec3{vehicle->CouplerPosition(end::front)} - Command.location) < glm::length2(glm::vec3{vehicle->CouplerPosition(end::rear)} - Command.location) ? end::front : end::rear;
|
|
|
|
vehicle->attach_coupler_adapter(couplerindex);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_nearestcarcoupleradapterremove(TTrain * /*Train*/, command_data const &Command)
|
|
{
|
|
|
|
if (true == Command.freefly && Command.action == GLFW_PRESS)
|
|
{
|
|
// tryb freefly, press only
|
|
auto *vehicle{std::get<TDynamicObject *>(simulation::Region->find_vehicle(Command.location, 50, false, true))};
|
|
if (vehicle == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto const couplerindex =
|
|
glm::length2(glm::vec3{vehicle->CouplerPosition(end::front)} - Command.location) < glm::length2(glm::vec3{vehicle->CouplerPosition(end::rear)} - Command.location) ? end::front : end::rear;
|
|
|
|
vehicle->remove_coupler_adapter(couplerindex);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_occupiedcarcouplingdisconnect(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// if( false == Train->m_controlmapper.contains( "couplingdisconnect_sw:" ) ) { return; }
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->m_couplingdisconnect = true;
|
|
|
|
if (Train->iCabn == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->DynamicObject)
|
|
{
|
|
Train->DynamicObject->uncouple(Train->cab_to_end());
|
|
if (Train->DynamicObject->Mechanik)
|
|
{
|
|
// aktualizacja flag kierunku w składzie
|
|
Train->DynamicObject->Mechanik->CheckVehicles(Disconnect);
|
|
}
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->m_couplingdisconnect = false;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_occupiedcarcouplingdisconnectback(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
// if( false == Train->m_controlmapper.contains( "couplingdisconnect_sw:" ) ) { return; }
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// visual feedback
|
|
Train->m_couplingdisconnectback = true;
|
|
|
|
if (Train->iCabn == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Train->DynamicObject)
|
|
{
|
|
Train->DynamicObject->uncouple(1 - Train->cab_to_end());
|
|
if (Train->DynamicObject->Mechanik)
|
|
{
|
|
// aktualizacja flag kierunku w składzie
|
|
Train->DynamicObject->Mechanik->CheckVehicles(Disconnect);
|
|
}
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->m_couplingdisconnectback = false;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_departureannounce(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->ggDepartureSignalButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Departure Signal button is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only reacting to press, so the sound can loop uninterrupted
|
|
if (false == Train->mvOccupied->DepartureSignal)
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->signal_departure(true);
|
|
// visual feedback
|
|
Train->ggDepartureSignalButton.UpdateValue(1.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// turn off
|
|
Train->mvOccupied->signal_departure(false);
|
|
// visual feedback
|
|
Train->ggDepartureSignalButton.UpdateValue(0.0, Train->dsbSwitch);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_hornlowactivate(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->ggHornButton.SubModel == nullptr && Train->ggHornLowButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Horn button is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only need to react to press, sound will continue until stopped
|
|
if (false == TestFlag(Train->mvOccupied->WarningSignal, horn::low))
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->WarningSignal = horn::pressed(Train->mvOccupied->WarningSignal, horn::low, Train->has_single_horn_lever());
|
|
// visual feedback
|
|
Train->ggHornButton.UpdateValue(-1.0);
|
|
Train->ggHornLowButton.UpdateValue(1.0);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// turn off
|
|
Train->mvOccupied->WarningSignal = horn::released(Train->mvOccupied->WarningSignal, horn::low);
|
|
// visual feedback
|
|
if (false == (Train->has_single_horn_lever() && TestFlag(Train->mvOccupied->WarningSignal, horn::high)))
|
|
{
|
|
// leave the single lever alone if it was moved to the other tone in the meantime
|
|
Train->ggHornButton.UpdateValue(0.0);
|
|
}
|
|
Train->ggHornLowButton.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_hornhighactivate(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->ggHornButton.SubModel == nullptr && Train->ggHornHighButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Horn button is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only need to react to press, sound will continue until stopped
|
|
if (false == TestFlag(Train->mvOccupied->WarningSignal, horn::high))
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->WarningSignal = horn::pressed(Train->mvOccupied->WarningSignal, horn::high, Train->has_single_horn_lever());
|
|
// visual feedback
|
|
Train->ggHornButton.UpdateValue(1.0);
|
|
Train->ggHornHighButton.UpdateValue(1.0);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// turn off
|
|
Train->mvOccupied->WarningSignal = horn::released(Train->mvOccupied->WarningSignal, horn::high);
|
|
// visual feedback
|
|
if (false == (Train->has_single_horn_lever() && TestFlag(Train->mvOccupied->WarningSignal, horn::low)))
|
|
{
|
|
// leave the single lever alone if it was moved to the other tone in the meantime
|
|
Train->ggHornButton.UpdateValue(0.0);
|
|
}
|
|
Train->ggHornHighButton.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_whistleactivate(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Train->ggWhistleButton.SubModel == nullptr)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
WriteLog("Whistle button is missing, or wasn't defined");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// only need to react to press, sound will continue until stopped
|
|
if (false == TestFlag(Train->mvOccupied->WarningSignal, 4))
|
|
{
|
|
// turn on
|
|
Train->mvOccupied->WarningSignal |= 4;
|
|
// visual feedback
|
|
Train->ggWhistleButton.UpdateValue(1.0);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// turn off
|
|
Train->mvOccupied->WarningSignal &= ~4;
|
|
// visual feedback
|
|
Train->ggWhistleButton.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiotoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// NOTE: works without the switch in the 3d model too, to allow system reset after receiving radio-stop signal
|
|
// only reacting to press, so the sound can loop uninterrupted
|
|
// NOTE: flips the state directly rather than through radioenable/radiodisable, so it doesn't move the radioon_sw:/radiooff_sw: buttons
|
|
Train->mvOccupied->Radio = (false == Train->mvOccupied->Radio);
|
|
}
|
|
|
|
void TTrain::OnCommand_radioenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvOccupied->Radio = true;
|
|
// visual feedback
|
|
if (Train->m_controlmapper.contains("radioon_sw:"))
|
|
{
|
|
Train->ggRadioOnButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
if (Train->m_controlmapper.contains("radioon_sw:"))
|
|
{
|
|
Train->ggRadioOnButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiodisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvOccupied->Radio = false;
|
|
// visual feedback
|
|
if (Train->m_controlmapper.contains("radiooff_sw:"))
|
|
{
|
|
Train->ggRadioOffButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
if (Train->m_controlmapper.contains("radiooff_sw:"))
|
|
{
|
|
Train->ggRadioOffButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
// the cut-off in the radio's power supply (eu07/maszyna#438); opening it works like switching the radio off, the
|
|
// radio-stop flag included
|
|
void TTrain::OnCommand_radiofusetoggle(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action != GLFW_PRESS)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// NOTE: flips the state directly rather than through radiofuseenable/radiofusedisable, so it doesn't move the
|
|
// radiofuseon_sw:/radiofuseoff_sw: buttons
|
|
Train->mvOccupied->RadioFuse = (false == Train->mvOccupied->RadioFuse);
|
|
}
|
|
|
|
void TTrain::OnCommand_radiofuseenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvOccupied->RadioFuse = true;
|
|
// visual feedback
|
|
if (Train->m_controlmapper.contains("radiofuseon_sw:"))
|
|
{
|
|
Train->ggRadioFuseOnButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
if (Train->m_controlmapper.contains("radiofuseon_sw:"))
|
|
{
|
|
Train->ggRadioFuseOnButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiofusedisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
Train->mvOccupied->RadioFuse = false;
|
|
// visual feedback
|
|
if (Train->m_controlmapper.contains("radiofuseoff_sw:"))
|
|
{
|
|
Train->ggRadioFuseOffButton.UpdateValue(1.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
if (Train->m_controlmapper.contains("radiofuseoff_sw:"))
|
|
{
|
|
Train->ggRadioFuseOffButton.UpdateValue(0.0f, Train->dsbSwitch);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiochannelincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// the channel buttons of a radio switched off or without power do nothing
|
|
if (Train->mvOccupied->RadioPowered())
|
|
{
|
|
command_data newCommand = Command;
|
|
newCommand.param1 = Train->RadioChannel() + 1;
|
|
OnCommand_radiochannelset(Train, newCommand);
|
|
}
|
|
|
|
Train->ggRadioChannelNext.UpdateValue(1.0);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggRadioChannelNext.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiochanneldecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (Train->mvOccupied->RadioPowered())
|
|
{
|
|
command_data newCommand = Command;
|
|
newCommand.param1 = Train->RadioChannel() - 1;
|
|
OnCommand_radiochannelset(Train, newCommand);
|
|
}
|
|
|
|
Train->ggRadioChannelPrevious.UpdateValue(1.0);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggRadioChannelPrevious.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiochannelset(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// on press or hold
|
|
Train->RadioChannel() = std::clamp((int)Command.param1, 1, 10);
|
|
Train->ggRadioChannelSelector.UpdateValue(static_cast<float>(Train->RadioChannel() - 1));
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiostopsend(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (Train->mvOccupied->RadioPowered())
|
|
{
|
|
simulation::Region->RadioStop(Train->Dynamic()->GetPosition());
|
|
}
|
|
// visual feedback
|
|
Train->ggRadioStop.UpdateValue(1.0);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggRadioStop.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiostopenable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS && Train->ggRadioStop.GetValue() == 0)
|
|
{
|
|
if (Train->mvOccupied->RadioPowered())
|
|
{
|
|
simulation::Region->RadioStop(Train->Dynamic()->GetPosition());
|
|
}
|
|
// visual feedback
|
|
Train->ggRadioStop.UpdateValue(1.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiostopdisable(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS && Train->ggRadioStop.GetValue() > 0)
|
|
{
|
|
// visual feedback
|
|
Train->ggRadioStop.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiostoptest(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (Train->RadioChannel() == 10 && Train->mvOccupied->RadioPowered())
|
|
{
|
|
Train->Dynamic()->RadioStop();
|
|
}
|
|
// visual feedback
|
|
Train->ggRadioTest.UpdateValue(1.0);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggRadioTest.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiocall1send(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (Train->RadioChannel() != 10 && Train->mvOccupied->RadioPowered())
|
|
{
|
|
simulation::Events.queue_receivers(radio_message::call1, Train->Dynamic()->GetPosition());
|
|
}
|
|
// visual feedback
|
|
Train->ggRadioCall1.UpdateValue(1.0);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggRadioCall1.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiocall3send(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (Train->RadioChannel() != 10 && Train->mvOccupied->RadioPowered())
|
|
{
|
|
simulation::Events.queue_receivers(radio_message::call3, Train->Dynamic()->GetPosition());
|
|
}
|
|
// visual feedback
|
|
Train->ggRadioCall3.UpdateValue(1.0);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggRadioCall3.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiovolumeincrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
// so do the volume buttons
|
|
if (Train->mvOccupied->RadioPowered())
|
|
{
|
|
command_data newCommand = Command;
|
|
newCommand.param1 = Train->m_radiovolume + 0.125;
|
|
OnCommand_radiovolumeset(Train, newCommand);
|
|
}
|
|
Train->ggRadioVolumeNext.UpdateValue(1.0);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggRadioVolumeNext.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiovolumedecrease(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (Train->mvOccupied->RadioPowered())
|
|
{
|
|
command_data newCommand = Command;
|
|
newCommand.param1 = Train->m_radiovolume - 0.125;
|
|
OnCommand_radiovolumeset(Train, newCommand);
|
|
}
|
|
Train->ggRadioVolumePrevious.UpdateValue(1.0);
|
|
}
|
|
else if (Command.action == GLFW_RELEASE)
|
|
{
|
|
// visual feedback
|
|
Train->ggRadioVolumePrevious.UpdateValue(0.0);
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_radiovolumeset(TTrain *Train, command_data const &Command)
|
|
{
|
|
if (Command.action != GLFW_RELEASE)
|
|
{
|
|
// on press or hold
|
|
Train->m_radiovolume = static_cast<float>(std::clamp(Command.param1, 0.0, 1.0));
|
|
Train->ggRadioVolumeSelector.UpdateValue(Train->m_radiovolume);
|
|
audio::event_volume_change = true;
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_cabchangeforward(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (auto const movedirection{1}; false == Train->CabChange(movedirection))
|
|
{
|
|
auto const exitdirection{(movedirection > 0 ? end::front : end::rear)};
|
|
if (TestFlag(Train->mvOccupied->Couplers[exitdirection].CouplingFlag, coupling::gangway))
|
|
{
|
|
// przejscie do nastepnego pojazdu
|
|
auto *targetvehicle = exitdirection == end::front ? Train->DynamicObject->PrevConnected() : Train->DynamicObject->NextConnected();
|
|
targetvehicle->MoverParameters->CabOccupied = Train->mvOccupied->Neighbours[exitdirection].vehicle_end ? -1 : 1;
|
|
Train->MoveToVehicle(targetvehicle);
|
|
}
|
|
}
|
|
// HACK: match consist door permit state with the preset in the active cab
|
|
if (Train->ggDoorPermitPresetButton.SubModel != nullptr)
|
|
{
|
|
Train->mvOccupied->ChangeDoorPermitPreset(0);
|
|
}
|
|
// HACK: update lights state
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
Train->DynamicObject->SetLights();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_cabchangebackward(TTrain *Train, command_data const &Command)
|
|
{
|
|
|
|
if (Command.action == GLFW_PRESS)
|
|
{
|
|
if (auto const movedirection{-1}; false == Train->CabChange(movedirection))
|
|
{
|
|
// current vehicle doesn't extend any farther in this direction, check if we there's one connected we can move to
|
|
auto const exitdirection{(movedirection > 0 ? end::front : end::rear)};
|
|
if (TestFlag(Train->mvOccupied->Couplers[exitdirection].CouplingFlag, coupling::gangway))
|
|
{
|
|
// przejscie do nastepnego pojazdu
|
|
auto *targetvehicle = exitdirection == end::front ? Train->DynamicObject->PrevConnected() : Train->DynamicObject->NextConnected();
|
|
targetvehicle->MoverParameters->CabOccupied = Train->mvOccupied->Neighbours[exitdirection].vehicle_end ? -1 : 1;
|
|
Train->MoveToVehicle(targetvehicle);
|
|
}
|
|
}
|
|
// HACK: match consist door permit state with the preset in the active cab
|
|
if (Train->ggDoorPermitPresetButton.SubModel != nullptr)
|
|
{
|
|
Train->mvOccupied->ChangeDoorPermitPreset(0);
|
|
}
|
|
// HACK: update lights state
|
|
if (Train->mvOccupied->LightsPosNo > 0)
|
|
{
|
|
Train->DynamicObject->SetLights();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TTrain::OnCommand_vehiclemoveforwards(TTrain *Train, const command_data &Command)
|
|
{
|
|
if (Command.action == GLFW_RELEASE || !DebugModeFlag)
|
|
return;
|
|
|
|
Train->DynamicObject->move_set(100.0);
|
|
}
|
|
|
|
void TTrain::OnCommand_vehiclemovebackwards(TTrain *Train, const command_data &Command)
|
|
{
|
|
if (Command.action == GLFW_RELEASE || !DebugModeFlag)
|
|
return;
|
|
|
|
Train->DynamicObject->move_set(-100.0);
|
|
}
|
|
|
|
void TTrain::OnCommand_vehicleboost(TTrain *Train, const command_data &Command)
|
|
{
|
|
if (Command.action == GLFW_RELEASE || !DebugModeFlag)
|
|
return;
|
|
|
|
double boost = Command.param1 != 0.0 ? Command.param1 : 2.78;
|
|
|
|
if (Train->DynamicObject == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto *vehicle{Train->DynamicObject};
|
|
while (vehicle)
|
|
{
|
|
vehicle->MoverParameters->V += vehicle->DirectionGet() * boost;
|
|
vehicle = vehicle->Next(); // pozostałe też
|
|
}
|
|
vehicle = Train->DynamicObject->Prev();
|
|
while (vehicle)
|
|
{
|
|
vehicle->MoverParameters->V += vehicle->DirectionGet() * boost;
|
|
vehicle = vehicle->Prev(); // w drugą stronę też
|
|
}
|
|
}
|
|
|
|
// cab movement update, fixed step part
|
|
void TTrain::UpdateCab()
|
|
{
|
|
|
|
// Ra: przesiadka, jeśli AI zmieniło kabinę (a człon?)...
|
|
if (DynamicObject->Mechanik // może nie być?
|
|
&& DynamicObject->Mechanik->AIControllFlag && iCabn != ( // numer kabiny (-1: kabina B)
|
|
mvOccupied->CabOccupied == -1 ? 2 : mvOccupied->CabOccupied))
|
|
{
|
|
|
|
InitializeCab(mvOccupied->CabOccupied, mvOccupied->TypeName + ".mmd");
|
|
}
|
|
iCabn = mvOccupied->CabOccupied == -1 ? 2 : mvOccupied->CabOccupied;
|
|
}
|
|
|
|
bool TTrain::Update(double const Deltatime)
|
|
{
|
|
// train state update
|
|
// line breaker:
|
|
if (m_linebreakerstate == 0 && true == mvControlled->Mains)
|
|
{
|
|
// crude way to sync state of the linebreaker with ai-issued commands
|
|
m_linebreakerstate = 1;
|
|
}
|
|
if (m_linebreakerstate == 1 && false == (mvControlled->Mains || mvControlled->dizel_startup))
|
|
{
|
|
// crude way to catch cases where the main was knocked out
|
|
// because the state of the line breaker isn't changed to match, we need to do it here manually
|
|
m_linebreakerstate = 0;
|
|
}
|
|
if (is_hold_coil_lever(ggMainOffButton) && hold_coil_lever::cuts_off(ggMainOffButton.GetDesiredValue()))
|
|
{
|
|
if (true == mvControlled->Mains)
|
|
{
|
|
// the line breaker was closed with the hold coil lever off, by the AI or through the control cable:
|
|
// put the lever back on to match, like the line breaker state above
|
|
ggMainOffButton.UpdateValue(0.0);
|
|
}
|
|
else if (m_linebreakerstate == 2)
|
|
{
|
|
// the hold coil was cut off while the closing button was held, the line breaker won't close on its release
|
|
m_linebreakerstate = 0;
|
|
}
|
|
}
|
|
|
|
if ((ggMainButton.SubModel != nullptr && ggMainButton.GetDesiredValue() > 0.95) ||
|
|
ggMainOnButton.SubModel != nullptr && ggMainOnButton.GetDesiredValue() > 0.95 ||
|
|
ggIgnitionKey.GetDesiredValue() > 0.95)
|
|
{ // HACK: fallback
|
|
// keep track of period the line breaker button is held down, to determine when/if circuit closes
|
|
if (mvControlled->MainSwitchCheck())
|
|
{
|
|
fMainRelayTimer += static_cast<float>(Deltatime);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// button isn't down, reset the timer
|
|
fMainRelayTimer = 0.0f;
|
|
}
|
|
if (ggMainOffButton.GetDesiredValue() > 0.95)
|
|
{
|
|
// if the button disconnecting the line breaker is down prevent the timer from accumulating
|
|
fMainRelayTimer = 0.0f;
|
|
}
|
|
if (m_linebreakerstate == 0 && fMainRelayTimer > mvControlled->InitialCtrlDelay)
|
|
{
|
|
// wlaczanie WSa z opoznieniem
|
|
// mark the line breaker as ready to close; for electric series vehicles with impulse switch the setup is completed on button release
|
|
m_linebreakerstate = 2;
|
|
}
|
|
// for diesels and/or vehicles with toggle switch setup we complete the engine start here
|
|
// TODO: make it a test for main_on_bt of type push_delayed instead
|
|
if (m_linebreakerstate == 2 && (ggMainOnButton.SubModel == nullptr || mvControlled->EngineType != TEngineType::ElectricSeriesMotor))
|
|
{
|
|
// try to finalize state change of the line breaker, set the state based on the outcome
|
|
m_linebreakerstate = mvControlled->MainSwitch(true, mvControlled->MainSwitchRange()) ? 1 : 0;
|
|
}
|
|
// the switches of the other vehicles in multiple
|
|
update_remote_linebreakers(Deltatime);
|
|
// door permits
|
|
for (auto idx = 0; idx < 2; ++idx)
|
|
{
|
|
auto &doorpermittimer{m_doorpermittimers[idx]};
|
|
if (doorpermittimer < 0.f)
|
|
{
|
|
continue;
|
|
}
|
|
doorpermittimer -= static_cast<float>(Deltatime);
|
|
if (doorpermittimer < 0.f)
|
|
{
|
|
mvOccupied->OperateDoors(static_cast<side>(idx), true);
|
|
}
|
|
}
|
|
|
|
// train measurement timer
|
|
if (trainLenghtMeasureTimer >= 0.f)
|
|
{
|
|
trainLenghtMeasureTimer -= static_cast<float>(Deltatime);
|
|
if (trainLenghtMeasureTimer < 0.f)
|
|
trainLenghtMeasureTimer = -1.f;
|
|
}
|
|
|
|
// battery timer
|
|
if (fBatteryTimer >= 0.f)
|
|
{
|
|
fBatteryTimer -= static_cast<float>(Deltatime);
|
|
if (fBatteryTimer < 0.f)
|
|
fBatteryTimer = -1.f;
|
|
}
|
|
|
|
// helper variables
|
|
if (DynamicObject->Mechanik != nullptr)
|
|
{
|
|
m_doors = DynamicObject->Mechanik->IsAnyDoorOpen[side::right] || DynamicObject->Mechanik->IsAnyDoorOpen[side::left];
|
|
m_doorpermits = DynamicObject->Mechanik->IsAnyDoorPermitActive[side::right] || DynamicObject->Mechanik->IsAnyDoorPermitActive[side::left];
|
|
m_doorspermitleft = mvOccupied->Doors.instances[cab_to_end() == end::front ? side::left : side::right].open_permit &&
|
|
(simulation::Time.data().wSecond % 2 < 1 || mvOccupied->DoorsPermitLightBlinking < 1 ||
|
|
mvOccupied->DoorsPermitLightBlinking < 2 && DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == end::front ? side::left : side::right] ||
|
|
(mvOccupied->DoorsPermitLightBlinking < 3 && DynamicObject->Mechanik->IsAnyDoorOnlyOpen[cab_to_end() == end::front ? side::left : side::right]));
|
|
m_doorspermitright = mvOccupied->Doors.instances[cab_to_end() == end::front ? side::right : side::left].open_permit &&
|
|
(simulation::Time.data().wSecond % 2 < 1 || mvOccupied->DoorsPermitLightBlinking < 1 ||
|
|
mvOccupied->DoorsPermitLightBlinking < 2 && DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == end::front ? side::right : side::left] ||
|
|
(mvOccupied->DoorsPermitLightBlinking < 3 && DynamicObject->Mechanik->IsAnyDoorOnlyOpen[cab_to_end() == end::front ? side::right : side::left]));
|
|
}
|
|
m_dirforward = mvControlled->DirActive > 0;
|
|
m_dirneutral = mvControlled->DirActive == 0;
|
|
m_dirbackward = mvControlled->DirActive < 0;
|
|
|
|
// check for received user commands
|
|
// NOTE: this is a temporary arrangement, for the transition period from old command setup to the new one
|
|
// eventually commands are going to be retrieved directly by the vehicle, filtered through active control stand
|
|
// and ultimately executed, provided the stand allows it.
|
|
command_data commanddata;
|
|
while (simulation::Commands.pop(commanddata, static_cast<std::size_t>(command_target::vehicle) | id()))
|
|
{
|
|
simulation::Blackbox.command(DynamicObject, commanddata.command, commanddata.action, commanddata.param1, commanddata.param2);
|
|
|
|
auto lookup = m_commandhandlers.find(commanddata.command);
|
|
if (lookup != m_commandhandlers.end())
|
|
{
|
|
// debug data
|
|
if (commanddata.action == GLFW_PRESS)
|
|
{
|
|
WriteLog(mvOccupied->Name + " received command: [" + simulation::Commands_descriptions[static_cast<std::size_t>(commanddata.command)].name + "]");
|
|
}
|
|
// pass the command to the assigned handler
|
|
lookup->second(this, commanddata);
|
|
}
|
|
}
|
|
|
|
UpdateCab();
|
|
|
|
// nie blokujemy AI
|
|
if (DynamicObject->Mechanik != nullptr && false == DynamicObject->Mechanik->AIControllFlag && (mvOccupied->TrainType == dt_ET40 || mvOccupied->TrainType == dt_EP05 || mvOccupied->HasCamshaft))
|
|
{
|
|
// dla ET40 i EU05 automatyczne cofanie nastawnika - i tak nie będzie to działać dobrze...
|
|
// TODO: use deltatime to stabilize speed
|
|
/*
|
|
if( false == (
|
|
( input::command == user_command::mastercontrollerset )
|
|
|| ( input::command == user_command::mastercontrollerincrease )
|
|
|| ( input::command == user_command::mastercontrollerdecrease ) ) ) {
|
|
*/
|
|
if (false == (m_mastercontrollerinuse || Global.ctrlState))
|
|
{
|
|
m_mastercontrollerreturndelay -= static_cast<float>(Deltatime);
|
|
if (m_mastercontrollerreturndelay < 0.f)
|
|
{
|
|
m_mastercontrollerreturndelay = EU07_CONTROLLER_BASERETURNDELAY;
|
|
if (mvOccupied->MainCtrlPos > mvOccupied->MainCtrlActualPos)
|
|
{
|
|
mvOccupied->DecMainCtrl(1);
|
|
}
|
|
else if (mvOccupied->MainCtrlPos < mvOccupied->MainCtrlActualPos)
|
|
{
|
|
// Ra 15-01: a to nie miało być tylko cofanie?
|
|
mvOccupied->IncMainCtrl(1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// McZapkie: predkosc wyswietlana na tachometrze brana jest z obrotow kol
|
|
auto const maxtacho{3.0};
|
|
|
|
double maxSpeed = mvControlled->Vmax * 1.05; // zachowanie starej logiki jak nie ma definicji max tarczki
|
|
if (mvOccupied->maxTachoSpeed != 0)
|
|
{
|
|
maxSpeed = mvOccupied->maxTachoSpeed;
|
|
}
|
|
fTachoVelocity = static_cast<float>(std::min(std::abs(11.31 * mvControlled->WheelDiameter * mvControlled->nrot), maxSpeed));
|
|
{ // skacze osobna zmienna
|
|
float ff = simulation::Time.data().wSecond; // skacze co sekunde - pol sekundy
|
|
// pomiar, pol sekundy ustawienie
|
|
if (ff != fTachoTimer) // jesli w tej sekundzie nie zmienial
|
|
{
|
|
if (fTachoVelocity >= 5) // jedzie
|
|
fTachoVelocityJump = static_cast<float>(fTachoVelocity + (2.0 - LocalRandom(3) + LocalRandom(3)) * 0.5);
|
|
else if (fTachoVelocity < 5 && fTachoVelocity > 1)
|
|
fTachoVelocityJump = static_cast<float>(Random(0, 4)); // tu ma sie bujac jak wariat i zatrzymac na jakiejs predkosci
|
|
// fTachoVelocityJump = 0; // stoi
|
|
fTachoTimer = ff; // juz zmienil
|
|
}
|
|
}
|
|
if (fTachoVelocity > 1) // McZapkie-270503: podkrecanie tachometru
|
|
{
|
|
// szybciej zacznij stukac
|
|
fTachoCount = static_cast<float>(std::min(maxtacho, fTachoCount + Deltatime * 3));
|
|
}
|
|
else if (fTachoCount > 0)
|
|
{
|
|
// schodz powoli - niektore haslery to ze 4 sekundy potrafia stukac
|
|
fTachoCount = static_cast<float>(std::max(0.0, fTachoCount - Deltatime * 0.66));
|
|
}
|
|
|
|
// Ra 2014-09: napięcia i prądy muszą być ustalone najpierw, bo wysyłane są ewentualnie na PoKeys
|
|
if (mvControlled->EngineType != TEngineType::DieselElectric && mvControlled->EngineType != TEngineType::ElectricInductionMotor)
|
|
{ // Ra 2014-09: czy taki rozdzia? ma sens?
|
|
fHVoltage = static_cast<float>(std::max(mvControlled->PantographVoltage,
|
|
mvControlled->GetTrainsetHighVoltage())); // Winger czy to nie jest zle?
|
|
}
|
|
// *mvControlled->Mains);
|
|
else
|
|
{
|
|
fHVoltage = static_cast<float>(mvControlled->EngineVoltage);
|
|
}
|
|
if (ShowNextCurrent)
|
|
{ // jeśli pokazywać drugi człon
|
|
if (mvSecond)
|
|
{ // o ile jest ten drugi
|
|
fHCurrent[0] = static_cast<float>(mvSecond->ShowCurrent(0) * 1.05);
|
|
fHCurrent[1] = static_cast<float>(mvSecond->ShowCurrent(1) * 1.05);
|
|
fHCurrent[2] = static_cast<float>(mvSecond->ShowCurrent(2) * 1.05);
|
|
fHCurrent[3] = static_cast<float>(mvSecond->ShowCurrent(3) * 1.05);
|
|
}
|
|
else
|
|
{
|
|
fHCurrent[0] = 0.0; // gdy nie ma człona
|
|
fHCurrent[1] = 0.0;
|
|
fHCurrent[2] = 0.0;
|
|
fHCurrent[3] = 0.0;
|
|
}
|
|
}
|
|
else
|
|
{ // normalne pokazywanie
|
|
fHCurrent[0] = static_cast<float>(mvControlled->ShowCurrent(0));
|
|
fHCurrent[1] = static_cast<float>(mvControlled->ShowCurrent(1));
|
|
fHCurrent[2] = static_cast<float>(mvControlled->ShowCurrent(2));
|
|
fHCurrent[3] = static_cast<float>(mvControlled->ShowCurrent(3));
|
|
}
|
|
|
|
bool kier = DynamicObject->DirectionGet() * mvOccupied->CabOccupied > 0;
|
|
TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->CabOccupied < 0 ? end::rear : end::front, 4);
|
|
int in = 0;
|
|
fEIMParams[0][6] = 0;
|
|
iCarNo = 0;
|
|
iPowerNo = 0;
|
|
iUnitNo = 1;
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
bMains[i] = false;
|
|
fCntVol[i] = 0.0f;
|
|
bPants[i][0] = false;
|
|
bPants[i][1] = false;
|
|
bFuse[i] = false;
|
|
bBatt[i] = false;
|
|
bConv[i] = false;
|
|
bComp[i][0] = false;
|
|
bComp[i][1] = false;
|
|
// bComp[i][2] = false;
|
|
// bComp[i][3] = false;
|
|
bHeat[i] = false;
|
|
}
|
|
bCompressors.clear();
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
if (p)
|
|
{
|
|
fPress[i][0] = static_cast<float>(p->MoverParameters->BrakePress);
|
|
fPress[i][1] = static_cast<float>(p->MoverParameters->PipePress);
|
|
fPress[i][2] = static_cast<float>(p->MoverParameters->ScndPipePress);
|
|
fPress[i][3] = static_cast<float>(p->MoverParameters->CntrlPipePress);
|
|
fPress[i][4] = static_cast<float>(p->MoverParameters->Hamulec->GetBRP());
|
|
fPress[i][5] = static_cast<float>((p->MoverParameters->TotalMass - p->MoverParameters->Mred) * 0.001);
|
|
fPress[i][6] = static_cast<float>(p->MoverParameters->SpringBrake.SBP);
|
|
bBrakes[i][0] = p->MoverParameters->SpringBrake.IsActive;
|
|
bBrakes[i][1] = p->MoverParameters->SpringBrake.ShuttOff;
|
|
bDoors[i][1] = p->MoverParameters->Doors.instances[side::left].position > 0.f;
|
|
bDoors[i][2] = p->MoverParameters->Doors.instances[side::right].position > 0.f;
|
|
bDoors[i][3] = p->MoverParameters->Doors.instances[side::left].step_position > 0.f;
|
|
bDoors[i][4] = p->MoverParameters->Doors.instances[side::right].step_position > 0.f;
|
|
bDoors[i][0] = bDoors[i][1] || bDoors[i][2];
|
|
iDoorNo[i] = p->iAnimType[ANIM_DOORS];
|
|
iUnits[i] = iUnitNo;
|
|
cCode[i] = p->MoverParameters->TypeName[p->MoverParameters->TypeName.length() - 1];
|
|
asCarName[i] = p->name();
|
|
if (p->MoverParameters->EnginePowerSource.SourceType == TPowerSource::CurrentCollector)
|
|
{
|
|
bPants[iUnitNo - 1][end::front] = bPants[iUnitNo - 1][end::front] || p->MoverParameters->Pantographs[end::front].is_active;
|
|
bPants[iUnitNo - 1][end::rear] = bPants[iUnitNo - 1][end::rear] || p->MoverParameters->Pantographs[end::rear].is_active;
|
|
}
|
|
// TBD, TODO: clean up compressor data arrangement?
|
|
if (iUnitNo <= 8)
|
|
{
|
|
bComp[iUnitNo - 1][0] = bComp[iUnitNo - 1][0] || p->MoverParameters->CompressorAllow || p->MoverParameters->CompressorStart == start_t::automatic;
|
|
}
|
|
if (p->MoverParameters->CompressorSpeed > 0.00001)
|
|
{
|
|
if (iUnitNo <= 8)
|
|
{
|
|
bComp[iUnitNo - 1][1] = bComp[iUnitNo - 1][1] || p->MoverParameters->CompressorFlag;
|
|
}
|
|
bCompressors.emplace_back(p->MoverParameters->CompressorAllow || p->MoverParameters->CompressorStart == start_t::automatic, p->MoverParameters->CompressorFlag, i);
|
|
}
|
|
bSlip[i] = p->MoverParameters->SlippingWheels;
|
|
if (in < 8 && p->MoverParameters->eimc[eimc_p_Pmax] > 1)
|
|
{
|
|
fEIMParams[1 + in][0] = static_cast<float>(p->MoverParameters->eimv[eimv_Fmax]);
|
|
fEIMParams[1 + in][1] = std::max(fEIMParams[1 + in][0], 0.f);
|
|
fEIMParams[1 + in][2] = -std::min(fEIMParams[1 + in][0], 0.f);
|
|
fEIMParams[1 + in][3] = static_cast<float>(p->MoverParameters->eimv[eimv_Fmax] / std::max(p->MoverParameters->eimv[eimv_Fful], 1.));
|
|
fEIMParams[1 + in][4] = std::max(fEIMParams[1 + in][3], 0.f);
|
|
fEIMParams[1 + in][5] = -std::min(fEIMParams[1 + in][3], 0.f);
|
|
fEIMParams[1 + in][6] = static_cast<float>(p->MoverParameters->eimv[eimv_If]);
|
|
fEIMParams[1 + in][7] = static_cast<float>(p->MoverParameters->eimv[eimv_U]);
|
|
fEIMParams[1 + in][8] = static_cast<float>(p->MoverParameters->Itot); // p->MoverParameters->eimv[eimv_Ipoj];
|
|
fEIMParams[1 + in][9] = static_cast<float>(p->MoverParameters->EngineVoltage);
|
|
fEIMParams[0][6] += fEIMParams[1 + in][8];
|
|
bMains[in] = p->MoverParameters->Mains;
|
|
fCntVol[in] = static_cast<float>(p->MoverParameters->BatteryVoltage);
|
|
bFuse[in] = p->MoverParameters->FuseFlag;
|
|
bBatt[in] = p->MoverParameters->Battery;
|
|
bConv[in] = p->MoverParameters->ConverterFlag;
|
|
bHeat[in] = p->MoverParameters->Heating;
|
|
// bComp[in][2] = (p->MoverParameters->CompressorAllow || (p->MoverParameters->CompressorStart == start_t::automatic));
|
|
// bComp[in][3] = (p->MoverParameters->CompressorFlag);
|
|
in++;
|
|
iPowerNo = in;
|
|
}
|
|
if (in < 8 && (p->MoverParameters->EngineType == TEngineType::DieselEngine || p->MoverParameters->EngineType == TEngineType::DieselElectric))
|
|
{
|
|
fDieselParams[1 + in][0] = static_cast<float>(p->MoverParameters->enrot * 60);
|
|
fDieselParams[1 + in][1] = static_cast<float>(p->MoverParameters->nrot);
|
|
fDieselParams[1 + in][2] = static_cast<float>(p->MoverParameters->RList[p->MoverParameters->MainCtrlPos].R);
|
|
fDieselParams[1 + in][3] = static_cast<float>(p->MoverParameters->dizel_fill);
|
|
fDieselParams[1 + in][4] = static_cast<float>(p->MoverParameters->RList[p->MoverParameters->MainCtrlPos].Mn);
|
|
fDieselParams[1 + in][5] = static_cast<float>(p->MoverParameters->dizel_engage);
|
|
fDieselParams[1 + in][6] = p->MoverParameters->dizel_heat.Twy;
|
|
fDieselParams[1 + in][7] = p->MoverParameters->OilPump.pressure;
|
|
fDieselParams[1 + in][8] = p->MoverParameters->dizel_heat.Ts;
|
|
fDieselParams[1 + in][9] = static_cast<float>(p->MoverParameters->hydro_R_Fill);
|
|
bMains[in] = p->MoverParameters->Mains;
|
|
fCntVol[in] = static_cast<float>(p->MoverParameters->BatteryVoltage);
|
|
bFuse[in] = p->MoverParameters->FuseFlag;
|
|
bBatt[in] = p->MoverParameters->Battery;
|
|
bConv[in] = p->MoverParameters->ConverterFlag;
|
|
bHeat[in] = p->MoverParameters->Heating;
|
|
in++;
|
|
iPowerNo = in;
|
|
}
|
|
if ((kier ? p->Next(coupling::permanent) : p->Prev(coupling::permanent)) != (kier ? p->Next(coupling::control) : p->Prev(coupling::control)))
|
|
iUnitNo++;
|
|
p = kier ? p->Next(coupling::control) : p->Prev(coupling::control);
|
|
iCarNo = i + 1;
|
|
}
|
|
else
|
|
{
|
|
fPress[i][0] = 0;
|
|
fPress[i][1] = 0;
|
|
fPress[i][2] = 0;
|
|
fPress[i][3] = 0;
|
|
fPress[i][4] = 0;
|
|
fPress[i][5] = 0;
|
|
bDoors[i][0] = false;
|
|
bDoors[i][1] = false;
|
|
bDoors[i][2] = false;
|
|
bDoors[i][3] = false;
|
|
bDoors[i][4] = false;
|
|
bBrakes[i][0] = false;
|
|
bBrakes[i][1] = false;
|
|
bSlip[i] = false;
|
|
iUnits[i] = 0;
|
|
cCode[i] = 0; //'0';
|
|
asCarName[i] = "";
|
|
}
|
|
}
|
|
|
|
// if (mvControlled == mvOccupied)
|
|
// fEIMParams[0][3] = mvControlled->eimv[eimv_Fzad]; // procent zadany
|
|
// else
|
|
// fEIMParams[0][3] =
|
|
// mvControlled->eimv[eimv_Fzad] - mvOccupied->LocalBrakeRatio(); // procent zadany
|
|
fEIMParams[0][3] = static_cast<float>(mvOccupied->eimic_real);
|
|
fEIMParams[0][4] = std::max(fEIMParams[0][3], 0.f);
|
|
fEIMParams[0][5] = -std::min(fEIMParams[0][3], 0.f);
|
|
fEIMParams[0][1] = static_cast<float>(fEIMParams[0][4] * mvControlled->eimv[eimv_Fful]);
|
|
fEIMParams[0][2] = static_cast<float>(fEIMParams[0][5] * mvControlled->eimv[eimv_Fful]);
|
|
fEIMParams[0][0] = fEIMParams[0][1] - fEIMParams[0][2];
|
|
fEIMParams[0][7] = 0;
|
|
fEIMParams[0][8] = 0;
|
|
fEIMParams[0][9] = 0;
|
|
|
|
for (int i = in; i < 8; i++)
|
|
{
|
|
for (int j = 0; j <= 9; j++)
|
|
{
|
|
fEIMParams[1 + i][j] = 0;
|
|
fDieselParams[1 + i][j] = 0;
|
|
}
|
|
}
|
|
#ifdef _WIN32
|
|
if (Global.iFeedbackMode == 4)
|
|
{
|
|
// wykonywać tylko gdy wyprowadzone na pulpit
|
|
// Ra: sterowanie miernikiem: zbiornik główny
|
|
Console::ValueSet(0, mvOccupied->Compressor);
|
|
// Ra: sterowanie miernikiem: przewód główny
|
|
Console::ValueSet(1, mvOccupied->PipePress);
|
|
// Ra: sterowanie miernikiem: cylinder hamulcowy
|
|
Console::ValueSet(2, mvOccupied->BrakePress);
|
|
// woltomierz wysokiego napięcia
|
|
Console::ValueSet(3, fHVoltage);
|
|
// Ra: sterowanie miernikiem: drugi amperomierz
|
|
Console::ValueSet(4, fHCurrent[2]);
|
|
// pierwszy amperomierz; dla EZT prąd całkowity
|
|
Console::ValueSet(5, fHCurrent[mvControlled->TrainType & dt_EZT ? 0 : 1]);
|
|
// Ra: prędkość na pin 43 - wyjście analogowe (to nie jest PWM); skakanie zapewnia mechanika napędu
|
|
Console::ValueSet(6, fTachoVelocity);
|
|
}
|
|
#endif
|
|
//------------------
|
|
// hunter-261211: nadmiarowy przetwornicy i ogrzewania
|
|
// Ra 15-01: to musi stąd wylecieć - zależności nie mogą być w kabinie
|
|
if (mvControlled->ConverterFlag == true)
|
|
{
|
|
fConverterTimer += static_cast<float>(Deltatime);
|
|
if (mvControlled->CompressorFlag == true && mvControlled->CompressorPower == 1 && (mvControlled->EngineType == TEngineType::ElectricSeriesMotor || mvControlled->TrainType == dt_EZT) &&
|
|
DynamicObject->Controller == Humandriver // hunter-110212: poprawka dla EZT
|
|
&& false == DynamicObject->Mechanik->AIControllFlag)
|
|
{ // hunter-091012: poprawka (zmiana warunku z CompressorPower /rozne od 0/ na /rowne 1/)
|
|
if (fConverterTimer < fConverterPrzekaznik)
|
|
{
|
|
mvControlled->ConvOvldFlag = true;
|
|
if (mvControlled->TrainType != dt_EZT)
|
|
mvControlled->MainSwitch(false, mvControlled->TrainType == dt_EZT ? range_t::unit : range_t::local);
|
|
}
|
|
else if (fConverterTimer >= fConverterPrzekaznik)
|
|
{
|
|
// changed switch from always true to take into account state of the compressor switch
|
|
mvControlled->CompressorSwitch(mvControlled->CompressorAllow);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
fConverterTimer = 0;
|
|
//------------------
|
|
auto const lowvoltagepower{mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable};
|
|
|
|
// youBy - prad w drugim czlonie: galaz lub calosc
|
|
{
|
|
TDynamicObject const *tmp{nullptr};
|
|
if (DynamicObject->NextConnected() && TestFlag(mvControlled->Couplers[end::rear].CouplingFlag, coupling::control) && mvOccupied->CabOccupied == 1)
|
|
tmp = DynamicObject->NextConnected();
|
|
if (DynamicObject->PrevConnected() && TestFlag(mvControlled->Couplers[end::front].CouplingFlag, coupling::control) && mvOccupied->CabOccupied == -1)
|
|
tmp = DynamicObject->PrevConnected();
|
|
if (tmp && tmp->MoverParameters->Power > 0)
|
|
{
|
|
if (ggI1B.SubModel)
|
|
{
|
|
ggI1B.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(1)));
|
|
ggI1B.Update();
|
|
}
|
|
if (ggI2B.SubModel)
|
|
{
|
|
ggI2B.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(2)));
|
|
ggI2B.Update();
|
|
}
|
|
if (ggI3B.SubModel)
|
|
{
|
|
ggI3B.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(3)));
|
|
ggI3B.Update();
|
|
}
|
|
if (ggItotalB.SubModel)
|
|
{
|
|
ggItotalB.UpdateValue(static_cast<float>(tmp->MoverParameters->ShowCurrent(0)));
|
|
ggItotalB.Update();
|
|
}
|
|
if (ggWater1TempB.SubModel)
|
|
{
|
|
ggWater1TempB.UpdateValue(tmp->MoverParameters->dizel_heat.temperatura1);
|
|
ggWater1TempB.Update();
|
|
}
|
|
if (ggOilPressB.SubModel)
|
|
{
|
|
ggOilPressB.UpdateValue(tmp->MoverParameters->OilPump.pressure);
|
|
ggOilPressB.Update();
|
|
}
|
|
}
|
|
}
|
|
// McZapkie-300302: zegarek
|
|
if (ggClockMInd.SubModel)
|
|
{
|
|
ggClockSInd.UpdateValue(simulation::Time.data().wSecond);
|
|
ggClockSInd.Update();
|
|
ggClockMInd.UpdateValue(simulation::Time.data().wMinute);
|
|
ggClockMInd.Update();
|
|
ggClockHInd.UpdateValue(static_cast<float>(simulation::Time.data().wHour + simulation::Time.data().wMinute / 60.0));
|
|
ggClockHInd.Update();
|
|
}
|
|
|
|
Cabine[iCabn].Update(lowvoltagepower); // nowy sposób ustawienia animacji
|
|
/*
|
|
if (ggZbS.SubModel)
|
|
{
|
|
ggZbS.UpdateValue(mvOccupied->Handle->GetCP());
|
|
ggZbS.Update();
|
|
}
|
|
*/
|
|
// replacement for the above. TODO: move it to a more suitable place
|
|
m_brakehandlecp = mvOccupied->Handle->GetCP();
|
|
|
|
// youBy - napiecie na silnikach
|
|
if (ggEngineVoltage.SubModel)
|
|
{
|
|
if (mvControlled->DynamicBrakeFlag)
|
|
{
|
|
ggEngineVoltage.UpdateValue(static_cast<float>(std::abs(mvControlled->Im * 5)));
|
|
}
|
|
else
|
|
{
|
|
int x;
|
|
if (mvControlled->TrainType == dt_ET42 && mvControlled->Imax == mvControlled->ImaxHi)
|
|
x = 1;
|
|
else
|
|
x = 2;
|
|
if (mvControlled->RList[mvControlled->MainCtrlActualPos].Mn > 0 && std::abs(mvControlled->Im) > 0)
|
|
{
|
|
ggEngineVoltage.UpdateValue(static_cast<float>(x * (std::abs(mvControlled->EngineVoltage) - mvControlled->RList[mvControlled->MainCtrlActualPos].R * std::abs(mvControlled->Im)) /
|
|
mvControlled->RList[mvControlled->MainCtrlActualPos].Mn));
|
|
}
|
|
else
|
|
{
|
|
ggEngineVoltage.UpdateValue(0);
|
|
}
|
|
}
|
|
ggEngineVoltage.Update();
|
|
}
|
|
|
|
// Winger 140404 - woltomierz NN
|
|
if (ggLVoltage.SubModel)
|
|
{
|
|
// NOTE: since we don't have functional converter object, we're faking it here by simple check whether converter is on
|
|
// TODO: implement object-based circuits and power systems model so we can have this working more properly
|
|
ggLVoltage.UpdateValue(static_cast<float>(std::max(mvOccupied->Power110vIsAvailable ? mvOccupied->NominalBatteryVoltage : 0.0, mvOccupied->Power24vIsAvailable ? mvOccupied->BatteryVoltage : 0.0)));
|
|
ggLVoltage.Update();
|
|
}
|
|
|
|
if (mvControlled->EngineType == TEngineType::DieselElectric)
|
|
{ // ustawienie zmiennych dla silnika spalinowego
|
|
fEngine[1] = static_cast<float>(mvControlled->ShowEngineRotation(1));
|
|
fEngine[2] = static_cast<float>(mvControlled->ShowEngineRotation(2));
|
|
}
|
|
|
|
else if (mvControlled->EngineType == TEngineType::DieselEngine)
|
|
{ // albo dla innego spalinowego
|
|
fEngine[1] = static_cast<float>(mvControlled->ShowEngineRotation(1));
|
|
fEngine[2] = static_cast<float>(mvControlled->ShowEngineRotation(2));
|
|
fEngine[3] = static_cast<float>(mvControlled->ShowEngineRotation(3));
|
|
if (ggMainGearStatus.SubModel)
|
|
{
|
|
if (mvControlled->Mains)
|
|
ggMainGearStatus.UpdateValue(static_cast<float>(1.1 - std::abs(mvControlled->dizel_automaticgearstatus)));
|
|
else
|
|
ggMainGearStatus.UpdateValue(0.0);
|
|
ggMainGearStatus.Update();
|
|
}
|
|
if (ggIgnitionKey.SubModel && ggIgnitionKey.GetDesiredValue() == 0.0)
|
|
{
|
|
ggIgnitionKey.UpdateValue(mvControlled->Mains || mvControlled->dizel_startup || fMainRelayTimer > 0.f ||
|
|
(ggMainButton.SubModel != nullptr && ggMainButton.GetDesiredValue() > 0.95) ||
|
|
(ggMainOnButton.SubModel != nullptr && ggMainOnButton.GetDesiredValue() > 0.95));
|
|
}
|
|
ggIgnitionKey.Update();
|
|
}
|
|
|
|
if (mvControlled->SlippingWheels)
|
|
{
|
|
// Ra 2014-12: lokomotywy 181/182 dostają SlippingWheels po zahamowaniu powyżej 2.85 bara i buczały
|
|
double veldiff = (DynamicObject->GetVelocity() - fTachoVelocity) / mvControlled->Vmax;
|
|
// 1% Vmax rezerwy, żeby 181/182 nie buczały po zahamowaniu, ale to proteza
|
|
if (veldiff < -0.01 && std::abs(mvControlled->Im) > 10.0)
|
|
{
|
|
btLampkaPoslizg.Turn(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
btLampkaPoslizg.Turn(false);
|
|
}
|
|
|
|
// Lampka pracujacej sprezacki
|
|
if (mvControlled->CompressorFlag || mvOccupied->CompressorFlag)
|
|
btCompressors.Turn(true);
|
|
else
|
|
btCompressors.Turn(false);
|
|
|
|
// Lampka zezwolenia na hamowanie ED
|
|
if (mvControlled->EpFuse)
|
|
btEDenabled.Turn(true);
|
|
else
|
|
btEDenabled.Turn(false);
|
|
|
|
// Lampka aktywowanej kabiny
|
|
if (mvControlled->CabActive != 0)
|
|
{
|
|
btCabActived.Turn(true);
|
|
}
|
|
else
|
|
{
|
|
btCabActived.Turn(false);
|
|
}
|
|
|
|
if (mvControlled->Battery && mvControlled->CabActive != 0)
|
|
btAKLVents.Turn(true);
|
|
else
|
|
btAKLVents.Turn(false);
|
|
|
|
if (true == lowvoltagepower)
|
|
{
|
|
// McZapkie-141102: SHP i czuwak, TODO: sygnalizacja kabinowa
|
|
if (mvOccupied->SecuritySystem.is_vigilance_blinking())
|
|
{
|
|
if (fBlinkTimer > fCzuwakBlink)
|
|
fBlinkTimer = -fCzuwakBlink;
|
|
else
|
|
fBlinkTimer += Deltatime;
|
|
|
|
btLampkaCzuwaka.Turn(fBlinkTimer > 0);
|
|
}
|
|
else
|
|
{
|
|
fBlinkTimer = 0.0;
|
|
btLampkaCzuwaka.Turn(false);
|
|
}
|
|
|
|
btLampkaSHP.Turn(mvOccupied->SecuritySystem.is_cabsignal_blinking());
|
|
btLampkaCzuwakaSHP.Turn(btLampkaSHP.GetValue() || btLampkaCzuwaka.GetValue());
|
|
|
|
btLampkaWylSzybki.Turn(m_linebreakerstate == 2 || mvControlled->Mains);
|
|
btLampkaWylSzybkiOff.Turn(m_linebreakerstate != 2 && !mvControlled->Mains);
|
|
btLampkaMainBreakerReady.Turn(mvControlled->MainsInitTimeCountdown <= 0.0 && m_linebreakerstate != 2 && !mvControlled->Mains);
|
|
btLampkaMainBreakerBlinkingIfReady.Turn(m_linebreakerstate == 2 || mvControlled->Mains || mvControlled->MainsInitTimeCountdown < 0.0 && simulation::Time.data().wMilliseconds > 500);
|
|
|
|
btLampkaPrzetw.Turn(mvOccupied->Power110vIsAvailable);
|
|
btLampkaPrzetwOff.Turn(!mvOccupied->Power110vIsAvailable);
|
|
btLampkaPrzetwAOff.Turn(!mvControlled->ConverterFlag);
|
|
btLampkaNadmPrzetw.Turn(Dynamic()->Mechanik ? Dynamic()->Mechanik->IsAnyConverterOverloadRelayOpen : mvControlled->ConvOvldFlag);
|
|
|
|
btLampkaOpory.Turn(mvControlled->StLinFlag && mvControlled->ResistorsFlagCheck());
|
|
btLampkaBezoporowa.Turn(mvControlled->ResistorsFlagCheck() || mvControlled->MainCtrlActualPos == 0); // do EU04
|
|
btLampkaStyczn.Turn(mvControlled->LineContactorsLampLit()); // mozna prowadzic rozruch
|
|
btLampkaPrzekRozn.Turn(!mvControlled->GroundRelay && mvControlled->MainCircuitLampsEnabled()); // relay is off and needs a reset
|
|
btLampkaNadmSil.Turn(mvControlled->FuseFlagCheck() && mvControlled->MainCircuitLampsEnabled()); // relay is off and needs a reset
|
|
btLampkaUkrotnienie.Turn(TestFlag(mvControlled->Couplers[mvControlled->CabOccupied == 1 ? rear : front].CouplingFlag, control));
|
|
btLampkaHamPosp.Turn(TestFlag(mvOccupied->Hamulec->GetBrakeStatus(), 1)); // lampka drugiego stopnia hamowania
|
|
// TODO: youBy wyciągnąć flagę wysokiego stopnia
|
|
btLampkaNadmWent.Turn(mvControlled->RventRot < 5.0 && mvControlled->ResistorsFlagCheck()); // hunter-121211: lampka zanikowo-pradowego wentylatorow
|
|
btLampkaWysRozr.Turn(mvControlled->Imax >= mvControlled->ImaxHi);
|
|
|
|
btLampkaNapNastHam.Turn(mvControlled->DirActive != 0); // napiecie na nastawniku hamulcowym
|
|
btLampkaSprezarka.Turn(mvControlled->CompressorFlag); // mutopsitka dziala
|
|
btLampkaSprezarkaOff.Turn(!mvControlled->CompressorFlag);
|
|
btLampkaFuelPumpOff.Turn(!mvControlled->FuelPump.is_active);
|
|
btLampkaOilPump.Turn(mvControlled->OilPump.is_active); // pre-lubrication pump, goes off once the engine is started
|
|
|
|
// boczniki
|
|
// Ra: w SU45 boczniki wchodzą na ScndCtrlPos, a nie na ScndCtrlActualPos
|
|
// - pokićkał ktoś?
|
|
int scp = mvControlled->RList[mvControlled->MainCtrlPos].ScndAct;
|
|
scp = scp == 255 ? 0 : scp; // Ra: whatta hella is this?
|
|
btLampkaBoczniki.Turn(!mvControlled->DelayCtrlFlag && mvControlled->ScndCtrlActualPos > 0 || scp > 0);
|
|
btLampkaBocznik1.Turn(!mvControlled->DelayCtrlFlag && mvControlled->ScndCtrlPos > 0 || mvControlled->ScndCtrlActualPos > 0 || scp > 0);
|
|
btLampkaBocznik2.Turn(!mvControlled->DelayCtrlFlag && mvControlled->ScndCtrlPos > 1 || mvControlled->ScndCtrlActualPos > 1 || scp > 1);
|
|
btLampkaBocznik3.Turn(!mvControlled->DelayCtrlFlag && mvControlled->ScndCtrlPos > 2 || mvControlled->ScndCtrlActualPos > 2 || scp > 2);
|
|
btLampkaBocznik4.Turn(!mvControlled->DelayCtrlFlag && mvControlled->ScndCtrlPos > 3 || mvControlled->ScndCtrlActualPos > 3 || scp > 3);
|
|
|
|
// biegi dla motoraka
|
|
btLampkaGear1.Turn(mvControlled->ScndCtrlActualPos == 1 && mvControlled->dizel_engagestate > 0); // bieg 1
|
|
btLampkaGear2.Turn(mvControlled->ScndCtrlActualPos == 2 && mvControlled->dizel_engagestate > 0); // bieg 2
|
|
btLampkaHydroLockup.Turn(mvControlled->hydro_TC_Lockup); // zblokowanie skrzyni z silnikiem
|
|
|
|
if (mvControlled->Signalling == true)
|
|
{
|
|
if (mvOccupied->BrakePress >= 1.45f)
|
|
{
|
|
btLampkaHamowanie1zes.Turn(true);
|
|
}
|
|
if (mvControlled->BrakePress < 0.75f)
|
|
{
|
|
btLampkaHamowanie1zes.Turn(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
btLampkaHamowanie1zes.Turn(false);
|
|
}
|
|
|
|
switch (mvControlled->TrainType)
|
|
{
|
|
// zależnie od typu lokomotywy
|
|
case dt_EZT:
|
|
{
|
|
btLampkaHamienie.Turn(mvControlled->BrakePress >= 0.2 && mvControlled->Signalling);
|
|
break;
|
|
}
|
|
case dt_ET41:
|
|
{
|
|
// odhamowanie drugiego członu
|
|
if (mvSecond)
|
|
{
|
|
// bo może komuś przyjść do głowy jeżdżenie jednym członem
|
|
btLampkaHamienie.Turn(mvSecond->BrakePress < 0.4);
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
btLampkaHamienie.Turn(mvOccupied->BrakePress >= 0.1 || mvControlled->DynamicBrakeFlag);
|
|
btLampkaBrakingOff.Turn(mvOccupied->BrakePress < 0.1 && !mvControlled->DynamicBrakeFlag);
|
|
break;
|
|
}
|
|
}
|
|
// KURS90
|
|
btLampkaMaxSila.Turn(abs(mvControlled->Im) >= 350);
|
|
btLampkaPrzekrMaxSila.Turn(abs(mvControlled->Im) >= 450);
|
|
btLampkaRadio.Turn(mvOccupied->Radio && mvOccupied->RadioFuse);
|
|
btLampkaRadioMessage.Turn(radio_message_played);
|
|
btLampkaRadioStop.Turn(mvOccupied->Radio && mvOccupied->RadioFuse && mvOccupied->RadioStopFlag);
|
|
btLampkaHamulecReczny.Turn(mvOccupied->ManualBrakePos > 0);
|
|
// NBMX wrzesien 2003 - drzwi oraz sygnał odjazdu
|
|
if (DynamicObject->Mechanik != nullptr)
|
|
{
|
|
btLampkaDoorLeft.Turn(DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == end::front ? side::left : side::right]);
|
|
btLampkaDoorRight.Turn(DynamicObject->Mechanik->IsAnyDoorOpen[cab_to_end() == end::front ? side::right : side::left]);
|
|
}
|
|
if (DynamicObject->Mechanik != nullptr)
|
|
{
|
|
// with DoorClosureSignal in the definition of the cab's vehicle, the door closure signalling (SOD) of the whole
|
|
// consist: lit with all doors closed and locked, blinking with them closed but released, dark with a door open.
|
|
// without it, the lock of the vehicle's own doors, as before
|
|
btLampkaBlokadaDrzwi.Turn(mvOccupied->door_closure_lamp_lit(DynamicObject->Mechanik->DoorClosure, simulation::Time.data().wSecond % 2 < 1));
|
|
}
|
|
else
|
|
{
|
|
btLampkaBlokadaDrzwi.Turn(mvOccupied->Doors.is_locked);
|
|
}
|
|
btLampkaDoorLockOff.Turn(false == mvOccupied->Doors.lock_enabled);
|
|
btLampkaDepartureSignal.Turn(mvControlled->DepartureSignal);
|
|
btLampkaNapNastHam.Turn(mvControlled->DirActive != 0 && mvOccupied->EpFuse); // napiecie na nastawniku hamulcowym
|
|
|
|
// Wylaczanie lampek kierunku gdy jedziemy
|
|
// Feature uruchamiany z fiz z sekcji Ctrl. wpisem HideDirStatusWhenMoving=Yes (domyslnie No)
|
|
if (mvOccupied->HideDirStatusWhenMoving && // Czy ta funkcja jest w ogole wlaczona
|
|
mvOccupied->Vel > mvOccupied->HideDirStatusSpeed) // Uzaleznienie od predkosci
|
|
{
|
|
btLampkaForward.Turn(false);
|
|
btLampkaBackward.Turn(false);
|
|
btLampkaNeutral.Turn(false);
|
|
}
|
|
else
|
|
{
|
|
btLampkaForward.Turn(mvControlled->DirActive > 0); // jazda do przodu
|
|
btLampkaBackward.Turn(mvControlled->DirActive < 0); // jazda do tyłu
|
|
btLampkaNeutral.Turn(mvControlled->DirActive == 0); // kierunek neutral
|
|
}
|
|
|
|
btLampkaED.Turn(mvControlled->DynamicBrakeFlag); // hamulec ED
|
|
btLampkaBrakeProfileG.Turn(TestFlag(mvOccupied->BrakeDelayFlag, bdelay_G));
|
|
btLampkaBrakeProfileP.Turn(TestFlag(mvOccupied->BrakeDelayFlag, bdelay_P));
|
|
btLampkaBrakeProfileR.Turn(TestFlag(mvOccupied->BrakeDelayFlag, bdelay_R));
|
|
btLampkaSpringBrakeActive.Turn(mvOccupied->SpringBrake.IsActive);
|
|
btLampkaSpringBrakeInactive.Turn(!mvOccupied->SpringBrake.IsActive);
|
|
// light indicators
|
|
// NOTE: sides are hardcoded to deal with setups where single cab is equipped with all indicators
|
|
btLampkaUpperLight.Turn((mvOccupied->iLights[end::front] & light::headlight_upper) != 0);
|
|
btLampkaLeftLight.Turn((mvOccupied->iLights[end::front] & light::headlight_left) != 0);
|
|
btLampkaRightLight.Turn((mvOccupied->iLights[end::front] & light::headlight_right) != 0);
|
|
btLampkaLeftEndLight.Turn((mvOccupied->iLights[end::front] & light::redmarker_left) != 0);
|
|
btLampkaRightEndLight.Turn((mvOccupied->iLights[end::front] & light::redmarker_right) != 0);
|
|
btLampkaRearUpperLight.Turn((mvOccupied->iLights[end::rear] & light::headlight_upper) != 0);
|
|
btLampkaRearLeftLight.Turn((mvOccupied->iLights[end::rear] & light::headlight_left) != 0);
|
|
btLampkaRearRightLight.Turn((mvOccupied->iLights[end::rear] & light::headlight_right) != 0);
|
|
btLampkaRearLeftEndLight.Turn((mvOccupied->iLights[end::rear] & light::redmarker_left) != 0);
|
|
btLampkaRearRightEndLight.Turn((mvOccupied->iLights[end::rear] & light::redmarker_right) != 0);
|
|
// others
|
|
btLampkaMalfunction.Turn(mvControlled->dizel_heat.PA);
|
|
// overheat indicator lamps
|
|
btLampkaOilOverheat.Turn(mvControlled->dizel_heat.oil.is_hot);
|
|
btLampkaWaterOverheat.Turn(mvControlled->dizel_heat.water.is_hot);
|
|
btLampkaWaterAuxOverheat.Turn(mvControlled->dizel_heat.water_aux.is_hot);
|
|
btLampkaEngineOverheat.Turn(mvControlled->dizel_heat.engine_is_hot);
|
|
btLampkaMotorBlowers.Turn(mvControlled->MotorBlowers[end::front].is_active && mvControlled->MotorBlowers[end::rear].is_active);
|
|
btLampkaCoolingFans.Turn(mvControlled->RventRot > 1.0);
|
|
btLampkaLouvresClosed.Turn(mvControlled->LouvresClosed());
|
|
btLampkaTempomat.Turn(mvOccupied->SpeedCtrlUnit.IsActive);
|
|
btLampkaDistanceCounter.Turn(m_distancecounter >= 0.f);
|
|
// universal devices state indicators
|
|
for (auto idx = 0; idx < btUniversals.size(); ++idx)
|
|
{
|
|
btUniversals[idx].Turn(ggUniversals[idx].GetValue() > 0.5);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// wylaczone
|
|
btLampkaCzuwaka.Turn(false);
|
|
btLampkaSHP.Turn(false);
|
|
btLampkaCzuwakaSHP.Turn(false);
|
|
btLampkaWylSzybki.Turn(false);
|
|
btLampkaWylSzybkiOff.Turn(false);
|
|
btLampkaMainBreakerReady.Turn(false);
|
|
btLampkaMainBreakerBlinkingIfReady.Turn(false);
|
|
btLampkaWysRozr.Turn(false);
|
|
btLampkaOpory.Turn(false);
|
|
btLampkaStyczn.Turn(false);
|
|
btLampkaPrzekRozn.Turn(false);
|
|
btLampkaNadmSil.Turn(false);
|
|
btLampkaUkrotnienie.Turn(false);
|
|
btLampkaHamPosp.Turn(false);
|
|
btLampkaBoczniki.Turn(false);
|
|
btLampkaBocznik1.Turn(false);
|
|
btLampkaBocznik2.Turn(false);
|
|
btLampkaBocznik3.Turn(false);
|
|
btLampkaBocznik4.Turn(false);
|
|
btLampkaGear1.Turn(false);
|
|
btLampkaGear2.Turn(false);
|
|
btLampkaHydroLockup.Turn(false);
|
|
btLampkaNapNastHam.Turn(false);
|
|
btLampkaPrzetw.Turn(false);
|
|
btLampkaPrzetwOff.Turn(false);
|
|
btLampkaPrzetwAOff.Turn(false);
|
|
btLampkaNadmPrzetw.Turn(false);
|
|
btLampkaSprezarka.Turn(false);
|
|
btLampkaSprezarkaOff.Turn(false);
|
|
btLampkaFuelPumpOff.Turn(false);
|
|
btLampkaOilPump.Turn(false);
|
|
btLampkaBezoporowa.Turn(false);
|
|
btLampkaHamowanie1zes.Turn(false);
|
|
btLampkaHamienie.Turn(false);
|
|
btLampkaBrakingOff.Turn(false);
|
|
btLampkaBrakeProfileG.Turn(false);
|
|
btLampkaBrakeProfileP.Turn(false);
|
|
btLampkaBrakeProfileR.Turn(false);
|
|
btLampkaSpringBrakeActive.Turn(false);
|
|
btLampkaSpringBrakeInactive.Turn(false);
|
|
// overheat indicator lamps off
|
|
btLampkaOilOverheat.Turn(false);
|
|
btLampkaWaterOverheat.Turn(false);
|
|
btLampkaWaterAuxOverheat.Turn(false);
|
|
btLampkaEngineOverheat.Turn(false);
|
|
btLampkaMaxSila.Turn(false);
|
|
btLampkaPrzekrMaxSila.Turn(false);
|
|
btLampkaRadio.Turn(false);
|
|
btLampkaRadioMessage.Turn(false);
|
|
btLampkaRadioStop.Turn(false);
|
|
btLampkaHamulecReczny.Turn(false);
|
|
btLampkaDoorLeft.Turn(false);
|
|
btLampkaDoorRight.Turn(false);
|
|
btLampkaBlokadaDrzwi.Turn(false);
|
|
btLampkaDoorLockOff.Turn(false);
|
|
btLampkaDepartureSignal.Turn(false);
|
|
btLampkaNapNastHam.Turn(false);
|
|
btLampkaForward.Turn(false);
|
|
btLampkaBackward.Turn(false);
|
|
btLampkaNeutral.Turn(false);
|
|
btLampkaED.Turn(false);
|
|
// light indicators
|
|
btLampkaUpperLight.Turn(false);
|
|
btLampkaLeftLight.Turn(false);
|
|
btLampkaRightLight.Turn(false);
|
|
btLampkaLeftEndLight.Turn(false);
|
|
btLampkaRightEndLight.Turn(false);
|
|
btLampkaRearUpperLight.Turn(false);
|
|
btLampkaRearLeftLight.Turn(false);
|
|
btLampkaRearRightLight.Turn(false);
|
|
btLampkaRearLeftEndLight.Turn(false);
|
|
btLampkaRearRightEndLight.Turn(false);
|
|
// others
|
|
btLampkaMalfunction.Turn(false);
|
|
btLampkaMotorBlowers.Turn(false);
|
|
btLampkaCoolingFans.Turn(false);
|
|
btLampkaLouvresClosed.Turn(false);
|
|
btLampkaTempomat.Turn(false);
|
|
btLampkaDistanceCounter.Turn(false);
|
|
// universal devices state indicators
|
|
for (auto &universal : btUniversals)
|
|
{
|
|
universal.Turn(false);
|
|
}
|
|
}
|
|
|
|
{ // yB - wskazniki drugiego czlonu
|
|
TDynamicObject const *tmp{nullptr}; //=mvControlled->mvSecond; //Ra 2014-07: trzeba to jeszcze wyjąć z kabiny...
|
|
// Ra 2014-07: no nie ma potrzeby szukać tego w każdej klatce
|
|
if (TestFlag(mvControlled->Couplers[1].CouplingFlag, coupling::control) && mvOccupied->CabOccupied > 0)
|
|
tmp = DynamicObject->NextConnected();
|
|
if (TestFlag(mvControlled->Couplers[0].CouplingFlag, coupling::control) && mvOccupied->CabOccupied < 0)
|
|
tmp = DynamicObject->PrevConnected();
|
|
|
|
if (tmp)
|
|
{
|
|
if (lowvoltagepower)
|
|
{
|
|
|
|
auto const *mover{tmp->MoverParameters};
|
|
|
|
btLampkaWylSzybkiB.Turn(mover->Mains);
|
|
btLampkaWylSzybkiBOff.Turn(false == mover->Mains
|
|
/*&& ( mover->MainsInitTimeCountdown <= 0.0 )*/
|
|
/*&& ( fHVoltage != 0.0 )*/);
|
|
|
|
btLampkaOporyB.Turn(mover->ResistorsFlagCheck());
|
|
btLampkaBezoporowaB.Turn(true == mover->ResistorsFlagCheck() || mover->MainCtrlActualPos == 0); // do EU04
|
|
|
|
btLampkaStycznB.Turn(mover->LineContactorsLampLit()); // mozna prowadzic rozruch
|
|
// hunter-271211: sygnalizacja poslizgu w pierwszym pojezdzie, gdy wystapi w drugim
|
|
if (mover->SlippingWheels)
|
|
{
|
|
// Ra 2014-12: lokomotywy 181/182 dostają SlippingWheels po zahamowaniu powyżej 2.85 bara i buczały
|
|
auto const veldiff{(DynamicObject->GetVelocity() - fTachoVelocity) / mvControlled->Vmax};
|
|
if (veldiff < -0.01)
|
|
{
|
|
// 1% Vmax rezerwy, żeby 181/182 nie buczały po zahamowaniu, ale to proteza
|
|
auto const lightstate{std::abs(mover->Im) > 10.0};
|
|
btLampkaPoslizg.Turn(btLampkaPoslizg.GetValue() || lightstate);
|
|
}
|
|
}
|
|
|
|
btLampkaSprezarkaB.Turn(mover->CompressorFlag); // mutopsitka dziala
|
|
btLampkaSprezarkaBOff.Turn(false == mover->CompressorFlag);
|
|
if (mvControlled->Signalling == true)
|
|
{
|
|
if (mover->BrakePress >= 1.45f)
|
|
{
|
|
btLampkaHamowanie2zes.Turn(true);
|
|
}
|
|
if (mover->BrakePress < 0.75f)
|
|
{
|
|
btLampkaHamowanie2zes.Turn(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
btLampkaHamowanie2zes.Turn(false);
|
|
}
|
|
btLampkaNadmPrzetwB.Turn(mover->ConvOvldFlag); // nadmiarowy przetwornicy?
|
|
btLampkaPrzetwB.Turn(mover->ConverterFlag); // zalaczenie przetwornicy
|
|
btLampkaPrzetwBOff.Turn(false == mover->ConverterFlag);
|
|
btLampkaHVoltageB.Turn(mover->NoVoltRelay && mover->OvervoltageRelay);
|
|
btLampkaMalfunctionB.Turn(mover->dizel_heat.PA);
|
|
// motor fuse indicator turns on if the fuse was blown in any unit under control
|
|
if (mover->Mains)
|
|
{
|
|
btLampkaNadmSil.Turn(btLampkaNadmSil.GetValue() || mover->FuseFlagCheck());
|
|
}
|
|
}
|
|
else // wylaczone
|
|
{
|
|
btLampkaWylSzybkiB.Turn(false);
|
|
btLampkaWylSzybkiBOff.Turn(false);
|
|
btLampkaOporyB.Turn(false);
|
|
btLampkaStycznB.Turn(false);
|
|
btLampkaSprezarkaB.Turn(false);
|
|
btLampkaSprezarkaBOff.Turn(false);
|
|
btLampkaBezoporowaB.Turn(false);
|
|
btLampkaHamowanie2zes.Turn(false);
|
|
btLampkaNadmPrzetwB.Turn(false);
|
|
btLampkaPrzetwB.Turn(false);
|
|
btLampkaPrzetwBOff.Turn(false);
|
|
btLampkaHVoltageB.Turn(false);
|
|
btLampkaMalfunctionB.Turn(false);
|
|
}
|
|
}
|
|
}
|
|
// McZapkie-080602: obroty (albo translacje) regulatorow
|
|
if (ggJointCtrl.SubModel != nullptr)
|
|
{
|
|
// joint master controller moves forward to adjust power and backward to adjust brakes
|
|
auto const brakerangemultiplier{/* NOTE: scaling disabled as it was conflicting with associating sounds with control positions
|
|
( mvControlled->CoupledCtrl ?
|
|
mvControlled->MainCtrlPosNo + mvControlled->ScndCtrlPosNo :
|
|
mvControlled->MainCtrlPosNo )
|
|
/ static_cast<double>(LocalBrakePosNo)
|
|
*/
|
|
1};
|
|
// when SplitEDPneumaticBrake is active the negative range of the joint controller
|
|
// represents the dedicated dynamic-brake lever (DBPN steps), not the pneumatic local brake
|
|
auto const negativePart{mvControlled->SplitEDPneumaticBrake ?
|
|
(mvControlled->DynamicBrakeCtrlPos > 0.0 ? mvControlled->DynamicBrakeCtrlPos * mvControlled->DynamicBrakeCtrlPosNo * -1 * brakerangemultiplier : 0.0) :
|
|
mvOccupied->LocalBrakePosA > 0.0 ? mvOccupied->LocalBrakePosA * LocalBrakePosNo * -1 * brakerangemultiplier :
|
|
0.0};
|
|
ggJointCtrl.UpdateValue(negativePart < 0.0 ? static_cast<float>(negativePart) :
|
|
mvControlled->CoupledCtrl ? static_cast<float>(double(mvControlled->MainCtrlPos + mvControlled->ScndCtrlPos)) :
|
|
static_cast<float>(double(mvControlled->MainCtrlPos)),
|
|
dsbNastawnikJazdy);
|
|
ggJointCtrl.Update();
|
|
}
|
|
if (ggMainCtrl.SubModel != nullptr)
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
if (DynamicObject->Mechanik != nullptr && false == DynamicObject->Mechanik->AIControllFlag // nie blokujemy AI
|
|
&& Global.iFeedbackMode == 4 && Global.fCalibrateIn[2][1] != 0.0)
|
|
{
|
|
|
|
set_master_controller(Console::AnalogCalibrateGet(2) * mvOccupied->MainCtrlPosNo);
|
|
mvOccupied->eimic_analog = Console::AnalogCalibrateGet(2);
|
|
}
|
|
#endif
|
|
|
|
if (mvControlled->CoupledCtrl)
|
|
{
|
|
ggMainCtrl.UpdateValue(static_cast<float>(double(mvControlled->MainCtrlPos + mvControlled->ScndCtrlPos)), dsbNastawnikJazdy);
|
|
}
|
|
else
|
|
{
|
|
ggMainCtrl.UpdateValue(static_cast<float>(double(mvControlled->MainCtrlPos)), dsbNastawnikJazdy);
|
|
}
|
|
ggMainCtrl.Update();
|
|
}
|
|
if (ggMainCtrlAct.SubModel != nullptr)
|
|
{
|
|
ggMainCtrlAct.UpdateValue(main_ctrl_act::position(*mvControlled, ggMainCtrlAct.has_scaletable()));
|
|
ggMainCtrlAct.Update();
|
|
}
|
|
if (ggScndCtrl.SubModel != nullptr)
|
|
{
|
|
// Ra: od byte odejmowane boolean i konwertowane potem na double?
|
|
if (false == ggScndCtrl.is_push())
|
|
{
|
|
ggScndCtrl.UpdateValue(static_cast<float>(double(mvControlled->ScndCtrlPos - (mvControlled->TrainType == dt_ET42 && mvControlled->DynamicBrakeFlag))), dsbNastawnikBocz);
|
|
}
|
|
ggScndCtrl.Update();
|
|
}
|
|
if (ggScndCtrlButton.SubModel != nullptr)
|
|
{
|
|
if (ggScndCtrlButton.is_toggle())
|
|
{
|
|
ggScndCtrlButton.UpdateValue(mvControlled->IsSpeedCtrlEngaged() ? 1.f : 0.f, dsbSwitch);
|
|
}
|
|
ggScndCtrlButton.Update(lowvoltagepower);
|
|
}
|
|
if (ggScndCtrlOffButton.SubModel != nullptr)
|
|
{
|
|
ggScndCtrlOffButton.Update(lowvoltagepower);
|
|
}
|
|
if (ggDistanceCounterButton.SubModel != nullptr)
|
|
{
|
|
ggDistanceCounterButton.Update();
|
|
}
|
|
if (ggDirKey.SubModel != nullptr)
|
|
{
|
|
if (mvControlled->TrainType != dt_EZT)
|
|
{
|
|
ggDirKey.UpdateValue(static_cast<float>(double(mvControlled->DirActive)), dsbReverserKey);
|
|
}
|
|
else
|
|
{
|
|
ggDirKey.UpdateValue(static_cast<float>(double(mvControlled->DirActive) + double(mvControlled->Imin == mvControlled->IminHi)), dsbReverserKey);
|
|
}
|
|
ggDirKey.Update();
|
|
}
|
|
if (ggBrakeCtrl.SubModel != nullptr)
|
|
{
|
|
#ifdef _WIN32
|
|
if (DynamicObject->Mechanik ? (DynamicObject->Mechanik->AIControllFlag ? false : Global.iFeedbackMode == 4 /*|| (Global.bMWDmasterEnable && Global.bMWDBreakEnable)*/) :
|
|
false && Global.fCalibrateIn[0][1] != 0.0) // nie blokujemy AI
|
|
{ // Ra: nie najlepsze miejsce, ale na początek gdzieś to dać trzeba
|
|
// Firleju: dlatego kasujemy i zastepujemy funkcją w Console
|
|
if (mvOccupied->BrakeHandle == TBrakeHandle::FV4a)
|
|
{
|
|
double b = Console::AnalogCalibrateGet(0);
|
|
b = b * 8.0 - 2.0;
|
|
b = safe_clamp(b, -2.0, (double)mvOccupied->BrakeCtrlPosNo); // przycięcie zmiennej do granic
|
|
ggBrakeCtrl.UpdateValue(b); // przesów bez zaokrąglenia
|
|
mvOccupied->BrakeLevelSet(b);
|
|
}
|
|
else if (mvOccupied->BrakeHandle == TBrakeHandle::FVel6) // może można usunąć ograniczenie do FV4a i FVel6?
|
|
{
|
|
double b = Console::AnalogCalibrateGet(0);
|
|
b = b * 7.0 - 1.0;
|
|
b = safe_clamp(b, -1.0, (double)mvOccupied->BrakeCtrlPosNo); // przycięcie zmiennej do granic
|
|
ggBrakeCtrl.UpdateValue(b); // przesów bez zaokrąglenia
|
|
mvOccupied->BrakeLevelSet(b);
|
|
}
|
|
else
|
|
{
|
|
double b = Console::AnalogCalibrateGet(0);
|
|
b = b * (mvOccupied->Handle->GetPos(bh_MAX) - mvOccupied->Handle->GetPos(bh_MIN)) + mvOccupied->Handle->GetPos(bh_MIN);
|
|
b = safe_clamp(b, mvOccupied->Handle->GetPos(bh_MIN), mvOccupied->Handle->GetPos(bh_MAX)); // przycięcie zmiennej do granic
|
|
ggBrakeCtrl.UpdateValue(b); // przesów bez zaokrąglenia
|
|
mvOccupied->BrakeLevelSet(b);
|
|
}
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
// else //standardowa prodedura z kranem powiązanym z klawiaturą
|
|
// ggBrakeCtrl.UpdateValue(double(mvOccupied->BrakeCtrlPos));
|
|
ggBrakeCtrl.UpdateValue(static_cast<float>(mvOccupied->fBrakeCtrlPos));
|
|
ggBrakeCtrl.Update();
|
|
}
|
|
}
|
|
|
|
if (ggLocalBrake.SubModel != nullptr)
|
|
{
|
|
#ifdef _WIN32
|
|
if (DynamicObject->Mechanik != nullptr && false == DynamicObject->Mechanik->AIControllFlag // nie blokujemy AI
|
|
&& mvOccupied->BrakeLocHandle == TBrakeHandle::FD1 && Global.iFeedbackMode == 4 && Global.fCalibrateIn[0][1] != 0.0)
|
|
{
|
|
// Ra: nie najlepsze miejsce, ale na początek gdzieś to dać trzeba
|
|
// Firleju: dlatego kasujemy i zastepujemy funkcją w Console
|
|
auto const b = std::clamp(Console::AnalogCalibrateGet(1), 0.f, 1.f);
|
|
mvOccupied->LocalBrakePosA = b;
|
|
ggLocalBrake.UpdateValue(b * LocalBrakePosNo);
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
// standardowa prodedura z kranem powiązanym z klawiaturą
|
|
ggLocalBrake.UpdateValue(static_cast<float>(mvOccupied->LocalBrakePosA * LocalBrakePosNo));
|
|
}
|
|
ggLocalBrake.Update();
|
|
}
|
|
ggDirForwardButton.Update(lowvoltagepower);
|
|
ggDirNeutralButton.Update(lowvoltagepower);
|
|
ggDirBackwardButton.Update(lowvoltagepower);
|
|
ggAlarmChain.Update();
|
|
ggBrakeProfileCtrl.Update();
|
|
ggBrakeProfileG.Update();
|
|
ggBrakeProfileR.Update();
|
|
ggBrakeOperationModeCtrl.Update();
|
|
ggWiperSw.Update();
|
|
ggMaxCurrentCtrl.UpdateValue(true == mvControlled->ShuntModeAllow ? (true == mvControlled->ShuntMode ? 1.f : 0.f) : mvControlled->MotorOverloadRelayHighThreshold ? 1.f : 0.f);
|
|
ggMaxCurrentCtrl.Update();
|
|
// NBMX wrzesien 2003 - drzwi
|
|
ggDoorLeftPermitButton.Update(lowvoltagepower);
|
|
ggDoorRightPermitButton.Update(lowvoltagepower);
|
|
ggDoorPermitPresetButton.Update(lowvoltagepower);
|
|
ggDoorLeftButton.Update(lowvoltagepower);
|
|
ggDoorRightButton.Update(lowvoltagepower);
|
|
ggDoorLeftOnButton.Update(lowvoltagepower);
|
|
ggDoorRightOnButton.Update(lowvoltagepower);
|
|
ggDoorLeftOffButton.Update(lowvoltagepower);
|
|
ggDoorRightOffButton.Update(lowvoltagepower);
|
|
ggDoorAllOnButton.Update(lowvoltagepower);
|
|
ggDoorAllOffButton.Update(lowvoltagepower);
|
|
ggDoorSignallingButton.Update(lowvoltagepower);
|
|
ggDoorStepButton.Update(lowvoltagepower);
|
|
// NBMX dzwignia sprezarki
|
|
ggCompressorButton.Update();
|
|
ggCompressorLocalButton.Update();
|
|
ggCompressorListButton.Update();
|
|
|
|
//---------
|
|
// hunter-080812: poprawka na ogrzewanie w elektrykach - usuniete uzaleznienie od przetwornicy
|
|
if (mvControlled->Heating == true && mvControlled->ConvOvldFlag == false)
|
|
btLampkaOgrzewanieSkladu.Turn(true);
|
|
else
|
|
btLampkaOgrzewanieSkladu.Turn(false);
|
|
|
|
//----------
|
|
|
|
// lights
|
|
auto const lightpower{(InstrumentLightType == 0 ? mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable :
|
|
InstrumentLightType == 1 ? mvControlled->Mains :
|
|
InstrumentLightType == 2 ? mvOccupied->Power110vIsAvailable :
|
|
InstrumentLightType == 3 ? mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable :
|
|
InstrumentLightType == 4 ? mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable :
|
|
false)};
|
|
InstrumentLightActive = InstrumentLightType == 3 ? true : // TODO: link the light state with the state of the master key
|
|
InstrumentLightType == 4 ? mvOccupied->iLights[end::front] != 0 || mvOccupied->iLights[end::rear] != 0 :
|
|
InstrumentLightActive;
|
|
btInstrumentLight.Turn(InstrumentLightActive && lightpower);
|
|
btDashboardLight.Turn(DashboardLightActive && lightpower);
|
|
btTimetableLight.Turn(TimetableLightActive && lightpower);
|
|
|
|
// guziki:
|
|
ggMainOffButton.Update();
|
|
ggMainOnButton.Update();
|
|
ggMainButton.Update();
|
|
for (auto &remotelinebreaker : m_remotelinebreakers)
|
|
{
|
|
remotelinebreaker.main_switch.Update();
|
|
remotelinebreaker.on_button.Update();
|
|
remotelinebreaker.off_button.Update();
|
|
}
|
|
ggSecurityResetButton.Update();
|
|
ggSHPResetButton.Update();
|
|
ggReleaserButton.Update();
|
|
ggSpringBrakeOnButton.Update();
|
|
ggSpringBrakeOffButton.Update();
|
|
ggUniveralBrakeButton1.Update();
|
|
ggUniveralBrakeButton2.Update();
|
|
ggUniveralBrakeButton3.Update();
|
|
ggEPFuseButton.Update();
|
|
ggAntiSlipButton.Update();
|
|
ggSandButton.Update();
|
|
ggAutoSandButton.Update();
|
|
ggFuseButton.Update();
|
|
ggConverterFuseButton.Update();
|
|
ggStLinOffButton.Update();
|
|
ggRadioChannelSelector.Update();
|
|
ggRadioChannelPrevious.Update();
|
|
ggRadioChannelNext.Update();
|
|
ggRadioStop.Update();
|
|
ggRadioTest.Update();
|
|
ggRadioCall1.Update();
|
|
ggRadioCall3.Update();
|
|
ggRadioVolumeSelector.Update();
|
|
ggRadioVolumePrevious.Update();
|
|
ggRadioVolumeNext.Update();
|
|
ggRadioOnButton.Update();
|
|
ggRadioOffButton.Update();
|
|
ggRadioFuseOnButton.Update();
|
|
ggRadioFuseOffButton.Update();
|
|
ggDepartureSignalButton.Update();
|
|
/*
|
|
ggPantFrontButton.Update();
|
|
ggPantRearButton.Update();
|
|
ggPantFrontButtonOff.Update();
|
|
ggPantRearButtonOff.Update();
|
|
*/
|
|
ggPantAllDownButton.Update();
|
|
ggPantSelectedDownButton.Update();
|
|
ggPantSelectedButton.Update();
|
|
ggPantValvesButton.Update();
|
|
ggPantCompressorButton.Update();
|
|
ggPantCompressorValve.Update();
|
|
|
|
ggPantValvesOff.Update();
|
|
ggPantValvesUpdate.Update();
|
|
|
|
ggLightsButton.Update();
|
|
ggUpperLightButton.Update();
|
|
ggLeftLightButton.Update();
|
|
ggRightLightButton.Update();
|
|
ggLeftEndLightButton.Update();
|
|
ggRightEndLightButton.Update();
|
|
ggModernLightDimSw.Update();
|
|
// hunter-230112
|
|
ggRearUpperLightButton.Update();
|
|
ggRearLeftLightButton.Update();
|
|
ggRearRightLightButton.Update();
|
|
ggRearLeftEndLightButton.Update();
|
|
ggRearRightEndLightButton.Update();
|
|
ggDimHeadlightsButton.Update();
|
|
ggDimHeadlightsButton.Update();
|
|
//------------
|
|
ggConverterButton.Update();
|
|
ggConverterLocalButton.Update();
|
|
ggConverterOffButton.Update();
|
|
ggTrainHeatingButton.Update();
|
|
ggSignallingButton.Update();
|
|
ggNextCurrentButton.Update();
|
|
ggHornButton.Update();
|
|
ggHornLowButton.Update();
|
|
ggHornHighButton.Update();
|
|
ggWhistleButton.Update();
|
|
if (DynamicObject->Mechanik != nullptr)
|
|
{
|
|
ggHelperButton.UpdateValue(static_cast<float>(DynamicObject->Mechanik->HelperState));
|
|
}
|
|
ggHelperButton.Update();
|
|
|
|
ggSpeedControlIncreaseButton.Update(lowvoltagepower);
|
|
ggSpeedControlDecreaseButton.Update(lowvoltagepower);
|
|
ggSpeedControlPowerIncreaseButton.Update(lowvoltagepower);
|
|
ggSpeedControlPowerDecreaseButton.Update(lowvoltagepower);
|
|
for (auto &speedctrlbutton : ggSpeedCtrlButtons)
|
|
{
|
|
speedctrlbutton.Update(lowvoltagepower);
|
|
}
|
|
for (auto &universal : ggUniversals)
|
|
{
|
|
universal.Update();
|
|
}
|
|
for (auto &item : ggInverterEnableButtons)
|
|
{
|
|
item.Update();
|
|
}
|
|
for (auto &item : ggInverterDisableButtons)
|
|
{
|
|
item.Update();
|
|
}
|
|
for (auto &item : ggInverterToggleButtons)
|
|
{
|
|
item.Update();
|
|
}
|
|
for (auto &relayresetbutton : ggRelayResetButtons)
|
|
{
|
|
relayresetbutton.Update();
|
|
}
|
|
// hunter-091012
|
|
ggInstrumentLightButton.Update();
|
|
ggDashboardLightButton.Update();
|
|
ggTimetableLightButton.Update();
|
|
ggCabLightDimButton.Update();
|
|
ggCompartmentLightsButton.Update();
|
|
ggCompartmentLightsOnButton.Update();
|
|
ggCompartmentLightsOffButton.Update();
|
|
ggBatteryButton.Update();
|
|
ggBatteryOnButton.Update();
|
|
ggBatteryOffButton.Update();
|
|
if (ggCabActivationButton.SubModel != nullptr && ggCabActivationButton.type() != TGaugeType::push)
|
|
{
|
|
ggCabActivationButton.UpdateValue(mvOccupied->IsCabMaster() ? 1.0 : 0.0);
|
|
}
|
|
ggCabActivationButton.Update();
|
|
|
|
ggWaterPumpBreakerButton.Update();
|
|
ggWaterPumpButton.Update();
|
|
ggWaterHeaterBreakerButton.Update();
|
|
ggWaterHeaterButton.Update();
|
|
ggWaterCircuitsLinkButton.Update();
|
|
ggFuelPumpButton.Update();
|
|
ggOilPumpButton.Update();
|
|
ggOilFuelPumpButton.Update();
|
|
ggMotorBlowersFrontButton.Update();
|
|
ggMotorBlowersRearButton.Update();
|
|
ggMotorBlowersAllOffButton.Update();
|
|
|
|
// wyprowadzenie sygnałów dla haslera na PoKeys (zaznaczanie na taśmie)
|
|
btHaslerBrakes.Turn(mvOccupied->BrakePress > 0.4); // ciśnienie w cylindrach
|
|
btHaslerCurrent.Turn(mvOccupied->Im != 0.0); // prąd na silnikach
|
|
|
|
// calculate current level of interior illumination
|
|
{
|
|
// TODO: organize it along with rest of train update in a more sensible arrangement
|
|
// Ra: uzeleżnic od napięcia w obwodzie sterowania
|
|
// hunter-091012: uzaleznienie jasnosci od przetwornicy
|
|
int cabidx{0};
|
|
for (auto &cab : Cabine)
|
|
{
|
|
|
|
auto const cablightlevel = (cab.bLight == false ? 0.f : cab.bLightDim == true ? 0.4f : 1.f) * (mvOccupied->Power110vIsAvailable ? 1.f : 0.5f);
|
|
|
|
if (cab.LightLevel != cablightlevel)
|
|
{
|
|
cab.LightLevel = cablightlevel;
|
|
DynamicObject->set_cab_lights(cabidx, cab.LightLevel);
|
|
}
|
|
if (cabidx == iCabn)
|
|
{
|
|
DynamicObject->InteriorLightLevel = cablightlevel;
|
|
}
|
|
|
|
++cabidx;
|
|
}
|
|
}
|
|
|
|
// anti slip system activation, maintained while the control button is down
|
|
if (mvOccupied->BrakeSystem != TBrakeSystem::ElectroPneumatic && ggAntiSlipButton.GetDesiredValue() > 0.95)
|
|
{
|
|
mvControlled->AntiSlippingBrake();
|
|
}
|
|
// screens
|
|
|
|
if (!FreeFlyModeFlag && simulation::Train == this) // don't bother if we're outside
|
|
{
|
|
update_screens(Deltatime);
|
|
update_script_screens();
|
|
}
|
|
|
|
// update direction relay
|
|
if (prevBatState != mvOccupied->Power24vIsAvailable)
|
|
SetupDirectionRelays();
|
|
if (prevDirection != mvOccupied->DirActive)
|
|
UpdateDirectionRelays();
|
|
|
|
prevBatState = mvOccupied->Power24vIsAvailable;
|
|
prevDirection = mvOccupied->DirActive;
|
|
|
|
// sounds
|
|
update_sounds(Deltatime);
|
|
|
|
return true; //(DynamicObject->Update(dt));
|
|
} // koniec update
|
|
|
|
void TTrain::UpdateDirectionRelays()
|
|
{
|
|
if (mvOccupied->DirActive < 0 && mvOccupied->Power24vIsAvailable) // wstecz
|
|
Dynamic()->sDirectionRelayR.play();
|
|
if (mvOccupied->DirActive == 0 && mvOccupied->Power24vIsAvailable) // neutral
|
|
Dynamic()->sDirectionRelayN.play();
|
|
if (mvOccupied->DirActive > 0 && mvOccupied->Power24vIsAvailable) // przod
|
|
Dynamic()->sDirectionRelayD.play();
|
|
}
|
|
|
|
void TTrain::SetupDirectionRelays()
|
|
{
|
|
if (mvOccupied->Power24vIsAvailable)
|
|
{
|
|
if (mvOccupied->DirActive < 0 && mvOccupied->Power24vIsAvailable) // wstecz
|
|
Dynamic()->sDirectionRelayR.play();
|
|
if (mvOccupied->DirActive > 0 && mvOccupied->Power24vIsAvailable) // przod
|
|
Dynamic()->sDirectionRelayD.play();
|
|
}
|
|
else if (mvOccupied->DirActive != 0) // neutral
|
|
Dynamic()->sDirectionRelayN.play();
|
|
}
|
|
|
|
void TTrain::update_sounds(double const Deltatime)
|
|
{
|
|
|
|
double volume{0.0};
|
|
double const brakevolumescale{0.5};
|
|
|
|
// Winger-160404 - syczenie pomocniczego (luzowanie)
|
|
if (m_lastlocalbrakepressure != -1.f)
|
|
{
|
|
// calculate rate of pressure drop in local brake cylinder, once it's been initialized
|
|
auto const brakepressuredifference{mvOccupied->LocBrakePress - m_lastlocalbrakepressure};
|
|
m_localbrakepressurechange = static_cast<float>(std::lerp(m_localbrakepressurechange, 10 * (brakepressuredifference / Deltatime), 0.1f));
|
|
}
|
|
m_lastlocalbrakepressure = static_cast<float>(mvOccupied->LocBrakePress);
|
|
// local brake, release
|
|
if (rsSBHiss)
|
|
{
|
|
if (m_localbrakepressurechange < -0.05f && mvOccupied->LocBrakePress > mvOccupied->BrakePress - 0.05)
|
|
{
|
|
rsSBHiss->gain(static_cast<float>(std::clamp(rsSBHiss->m_amplitudeoffset + rsSBHiss->m_amplitudefactor * -m_localbrakepressurechange * 0.05, 0.0, 1.5)));
|
|
rsSBHiss->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
// don't stop the sound too abruptly
|
|
volume = std::max(0.0, rsSBHiss->gain() - 0.1 * Deltatime);
|
|
rsSBHiss->gain(static_cast<float>(volume));
|
|
if (volume < 0.05)
|
|
{
|
|
rsSBHiss->stop();
|
|
}
|
|
}
|
|
}
|
|
// local brake, engage
|
|
if (rsSBHissU)
|
|
{
|
|
if (m_localbrakepressurechange > 0.05f)
|
|
{
|
|
rsSBHissU->gain(static_cast<float>(std::clamp(rsSBHissU->m_amplitudeoffset + rsSBHissU->m_amplitudefactor * m_localbrakepressurechange * 0.05, 0.0, 1.5)));
|
|
rsSBHissU->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
// don't stop the sound too abruptly
|
|
volume = std::max(0.0, rsSBHissU->gain() - 0.1 * Deltatime);
|
|
rsSBHissU->gain(static_cast<float>(volume));
|
|
if (volume < 0.05)
|
|
{
|
|
rsSBHissU->stop();
|
|
}
|
|
}
|
|
}
|
|
|
|
// McZapkie-280302 - syczenie
|
|
// TODO: softer volume reduction than plain abrupt stop, perhaps as reusable wrapper?
|
|
if (mvOccupied->BrakeHandle == TBrakeHandle::FV4a || mvOccupied->BrakeHandle == TBrakeHandle::FVel6)
|
|
{
|
|
// upuszczanie z PG
|
|
if (rsHiss)
|
|
{
|
|
fPPress = std::lerp(fPPress, static_cast<float>(mvOccupied->Handle->GetSound(s_fv4a_b)), 0.05f);
|
|
volume = fPPress > 0 ? rsHiss->m_amplitudefactor * fPPress * 0.25 + rsHiss->m_amplitudeoffset : 0;
|
|
if (volume * brakevolumescale > 0.05)
|
|
{
|
|
rsHiss->gain(static_cast<float>(volume * brakevolumescale));
|
|
rsHiss->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
rsHiss->stop();
|
|
}
|
|
}
|
|
// napelnianie PG
|
|
if (rsHissU)
|
|
{
|
|
fNPress = std::lerp(fNPress, static_cast<float>(mvOccupied->Handle->GetSound(s_fv4a_u)), 0.25f);
|
|
volume = fNPress > 0 ? rsHissU->m_amplitudefactor * fNPress + rsHissU->m_amplitudeoffset : 0;
|
|
if (volume * brakevolumescale > 0.05)
|
|
{
|
|
rsHissU->gain(static_cast<float>(volume * brakevolumescale));
|
|
rsHissU->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
rsHissU->stop();
|
|
}
|
|
}
|
|
// upuszczanie przy naglym
|
|
if (rsHissE)
|
|
{
|
|
volume = mvOccupied->Handle->GetSound(s_fv4a_e) * rsHissE->m_amplitudefactor + rsHissE->m_amplitudeoffset;
|
|
if (volume * brakevolumescale > 0.05)
|
|
{
|
|
rsHissE->gain(static_cast<float>(volume * brakevolumescale));
|
|
rsHissE->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
rsHissE->stop();
|
|
}
|
|
}
|
|
// upuszczanie sterujacego fala
|
|
if (rsHissX)
|
|
{
|
|
volume = mvOccupied->Handle->GetSound(s_fv4a_x) * rsHissX->m_amplitudefactor + rsHissX->m_amplitudeoffset;
|
|
if (volume * brakevolumescale > 0.05)
|
|
{
|
|
rsHissX->gain(static_cast<float>(volume * brakevolumescale));
|
|
rsHissX->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
rsHissX->stop();
|
|
}
|
|
}
|
|
// upuszczanie z czasowego
|
|
if (rsHissT)
|
|
{
|
|
volume = mvOccupied->Handle->GetSound(s_fv4a_t) * rsHissT->m_amplitudefactor + +rsHissT->m_amplitudeoffset;
|
|
if (volume * brakevolumescale > 0.05)
|
|
{
|
|
rsHissT->gain(static_cast<float>(volume * brakevolumescale));
|
|
rsHissT->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
rsHissT->stop();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// jesli nie FV4a
|
|
// upuszczanie z PG
|
|
if (rsHiss)
|
|
{
|
|
fPPress = static_cast<float>((4.0f * fPPress + std::max(0.0, mvOccupied->dpMainValve)) / (4.0f + 1.0f));
|
|
volume = fPPress > 0.0f ? 2.0 * rsHiss->m_amplitudefactor * fPPress + rsHiss->m_amplitudeoffset : 0.0;
|
|
if (volume > 0.05)
|
|
{
|
|
rsHiss->gain(static_cast<float>(volume));
|
|
rsHiss->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
rsHiss->stop();
|
|
}
|
|
}
|
|
// napelnianie PG
|
|
if (rsHissU)
|
|
{
|
|
fNPress = static_cast<float>((4.0f * fNPress + std::min(0.0, mvOccupied->dpMainValve)) / (4.0f + 1.0f));
|
|
volume = fNPress < 0.0f ? -1.0 * rsHissU->m_amplitudefactor * fNPress + rsHissU->m_amplitudeoffset : 0.0;
|
|
if (volume > 0.01)
|
|
{
|
|
rsHissU->gain(static_cast<float>(volume));
|
|
rsHissU->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
rsHissU->stop();
|
|
}
|
|
}
|
|
} // koniec nie FV4a
|
|
|
|
// brakes
|
|
if (rsBrake)
|
|
{
|
|
if (mvOccupied->UnitBrakeForce > 10.0 && mvOccupied->Vel > 0.05)
|
|
{
|
|
|
|
auto const brakeforceratio{
|
|
std::clamp(mvOccupied->UnitBrakeForce / std::max(1.0, mvOccupied->BrakeForceR(1.0, mvOccupied->Vel) / (mvOccupied->NAxles * std::max(1, mvOccupied->NBpA))), 0.0, 1.0)};
|
|
// HACK: in external view mute the sound rather than stop it, in case there's an opening bookend it'd (re)play on sound restart after returning inside
|
|
volume = FreeFlyModeFlag ? 0.0 : rsBrake->m_amplitudeoffset + std::sqrt(brakeforceratio * std::lerp(0.4, 1.0, mvOccupied->Vel / (1 + mvOccupied->Vmax))) * rsBrake->m_amplitudefactor;
|
|
rsBrake->pitch(static_cast<float>(rsBrake->m_frequencyoffset + mvOccupied->Vel * rsBrake->m_frequencyfactor));
|
|
rsBrake->gain(static_cast<float>(volume));
|
|
rsBrake->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
rsBrake->stop();
|
|
}
|
|
}
|
|
|
|
// ambient sound
|
|
// since it's typically ticking of the clock we can center it on tachometer or on middle of compartment bounding area
|
|
if (rsFadeSound)
|
|
{
|
|
rsFadeSound->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
|
|
if (dsbSlipAlarm)
|
|
{
|
|
// alarm przy poslizgu dla 181/182 - BOMBARDIER
|
|
if (mvControlled->SlippingWheels && DynamicObject->GetVelocity() > 1.0)
|
|
{
|
|
dsbSlipAlarm->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
dsbSlipAlarm->stop();
|
|
}
|
|
}
|
|
|
|
// dzwiek wiatru rozbijajacego sie o szyby w kabinie
|
|
if (rsWindSound)
|
|
{
|
|
if (!FreeFlyModeFlag && !Global.CabWindowOpen && DynamicObject->GetVelocity() > 0.5)
|
|
update_sounds_resonancenoise(*rsWindSound);
|
|
else
|
|
rsWindSound->stop(FreeFlyModeFlag);
|
|
}
|
|
|
|
// dzwiek rezonansu (taki drugi runningnoise w sumie)
|
|
if (rsResonanceNoise)
|
|
{
|
|
if (!FreeFlyModeFlag && !Global.CabWindowOpen && DynamicObject->GetVelocity() > 0.5)
|
|
{
|
|
|
|
update_sounds_resonancenoise(*rsResonanceNoise);
|
|
}
|
|
else
|
|
rsResonanceNoise->stop(FreeFlyModeFlag);
|
|
}
|
|
|
|
// szum w czasie jazdy
|
|
if (rsRunningNoise)
|
|
{
|
|
if (false == FreeFlyModeFlag && false == Global.CabWindowOpen && DynamicObject->GetVelocity() > 0.5)
|
|
{
|
|
|
|
update_sounds_runningnoise(*rsRunningNoise);
|
|
}
|
|
else
|
|
{
|
|
// don't play the optional ending sound if the listener switches views
|
|
rsRunningNoise->stop(true == FreeFlyModeFlag);
|
|
}
|
|
}
|
|
// hunting oscillation noise
|
|
if (rsHuntingNoise)
|
|
{
|
|
if (false == FreeFlyModeFlag && false == Global.CabWindowOpen && DynamicObject->GetVelocity() > 0.5 && DynamicObject->IsHunting)
|
|
{
|
|
|
|
update_sounds_runningnoise(*rsHuntingNoise);
|
|
// modify calculated sound volume by hunting amount
|
|
auto const huntingamount = std::lerp(
|
|
0.0, 1.0, std::clamp((mvOccupied->Vel - DynamicObject->HuntingShake.fadein_begin) / (DynamicObject->HuntingShake.fadein_end - DynamicObject->HuntingShake.fadein_begin), 0.0, 1.0));
|
|
|
|
rsHuntingNoise->gain(static_cast<float>(rsHuntingNoise->gain() * huntingamount));
|
|
}
|
|
else
|
|
{
|
|
// don't play the optional ending sound if the listener switches views
|
|
rsHuntingNoise->stop(true == FreeFlyModeFlag);
|
|
}
|
|
}
|
|
// rain sound
|
|
if (m_rainsound)
|
|
{
|
|
if (false == FreeFlyModeFlag && false == Global.CabWindowOpen && Global.Weather == "rain:")
|
|
{
|
|
if (m_rainsound->is_combined())
|
|
{
|
|
m_rainsound->pitch(static_cast<float>(Global.Overcast - 1.0));
|
|
}
|
|
m_rainsound->gain(m_rainsound->m_amplitudeoffset + m_rainsound->m_amplitudefactor * 1.f);
|
|
m_rainsound->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
m_rainsound->stop();
|
|
}
|
|
}
|
|
|
|
if (dsbHasler)
|
|
{
|
|
if (fTachoCount >= 3.f)
|
|
{
|
|
auto const soundfrequency{(true == dsbHasler->is_combined() ? fTachoVelocity * 0.01 : dsbHasler->m_frequencyoffset + dsbHasler->m_frequencyfactor)};
|
|
dsbHasler->pitch(static_cast<float>(soundfrequency));
|
|
dsbHasler->gain(dsbHasler->m_amplitudeoffset + dsbHasler->m_amplitudefactor);
|
|
dsbHasler->play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else if (fTachoCount < 1.f)
|
|
{
|
|
dsbHasler->stop();
|
|
}
|
|
}
|
|
|
|
// power-reliant sounds
|
|
if (mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable)
|
|
{
|
|
|
|
// buzzer shp
|
|
if (mvOccupied->SecuritySystem.is_cabsignal_beeping())
|
|
{
|
|
if (dsbBuzzerShp && false == dsbBuzzerShp->is_playing())
|
|
{
|
|
dsbBuzzerShp->pitch(dsbBuzzerShp->m_frequencyoffset + dsbBuzzerShp->m_frequencyfactor);
|
|
dsbBuzzerShp->gain(dsbBuzzerShp->m_amplitudeoffset + dsbBuzzerShp->m_amplitudefactor);
|
|
dsbBuzzerShp->play(sound_flags::looping);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (dsbBuzzerShp && true == dsbBuzzerShp->is_playing())
|
|
{
|
|
dsbBuzzerShp->stop();
|
|
}
|
|
}
|
|
|
|
// McZapkie-141102: SHP i czuwak, TODO: sygnalizacja kabinowa
|
|
// hunter-091012: rozdzielenie alarmow
|
|
if (mvOccupied->SecuritySystem.is_beeping())
|
|
{
|
|
if (dsbBuzzer && false == dsbBuzzer->is_playing())
|
|
{
|
|
dsbBuzzer->pitch(dsbBuzzer->m_frequencyoffset + dsbBuzzer->m_frequencyfactor);
|
|
dsbBuzzer->gain(dsbBuzzer->m_amplitudeoffset + dsbBuzzer->m_amplitudefactor);
|
|
dsbBuzzer->play(sound_flags::looping);
|
|
#ifdef _WIN32
|
|
Console::BitsSet(1 << 14); // ustawienie bitu 16 na PoKeys
|
|
#endif
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (dsbBuzzer && true == dsbBuzzer->is_playing())
|
|
{
|
|
dsbBuzzer->stop();
|
|
#ifdef _WIN32
|
|
Console::BitsClear(1 << 14); // ustawienie bitu 16 na PoKeys
|
|
#endif
|
|
}
|
|
}
|
|
// distance meter alert
|
|
if (m_distancecounterclear)
|
|
{
|
|
auto const *owner{(DynamicObject->ctOwner != nullptr ? DynamicObject->ctOwner : DynamicObject->Mechanik)};
|
|
if (m_distancecounter > owner->fLength)
|
|
{
|
|
// play assigned sound if the train travelled its full length since meter activation
|
|
// TBD: check all combinations of directions and active cab
|
|
m_distancecounter = -1.f; // turn off the meter after its task is done
|
|
m_distancecounterclear->pitch(m_distancecounterclear->m_frequencyoffset + m_distancecounterclear->m_frequencyfactor);
|
|
m_distancecounterclear->gain(m_distancecounterclear->m_amplitudeoffset + m_distancecounterclear->m_amplitudefactor);
|
|
m_distancecounterclear->play(sound_flags::exclusive);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// stop power-reliant sounds if power is cut
|
|
if (dsbBuzzer && true == dsbBuzzer->is_playing())
|
|
{
|
|
dsbBuzzer->stop();
|
|
#ifdef _WIN32
|
|
Console::BitsClear(1 << 14); // ustawienie bitu 16 na PoKeys
|
|
#endif
|
|
}
|
|
|
|
if (dsbBuzzerShp && dsbBuzzerShp->is_playing())
|
|
{
|
|
dsbBuzzerShp->stop();
|
|
}
|
|
|
|
if (m_distancecounterclear)
|
|
{
|
|
m_distancecounterclear->stop();
|
|
}
|
|
}
|
|
|
|
update_sounds_radio();
|
|
}
|
|
|
|
void TTrain::update_sounds_resonancenoise(sound_source &Sound) const
|
|
{
|
|
// frequency calculation
|
|
auto const normalizer{mvOccupied->Vmax * 0.01f};
|
|
auto const soundfrequency{Sound.m_frequencyoffset + Sound.m_frequencyfactor * mvOccupied->Vel * normalizer};
|
|
|
|
// volume calculation
|
|
auto volume = Sound.m_amplitudeoffset + Sound.m_amplitudefactor * std::lerp(mvOccupied->Vel / (1 + mvOccupied->Vmax), 1.0, 0.5); // scale base volume between 0.5-1.0
|
|
|
|
if (volume > 0.05)
|
|
{
|
|
Sound.pitch(static_cast<float>(soundfrequency)).gain(static_cast<float>(volume)).play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
Sound.stop();
|
|
}
|
|
}
|
|
|
|
void TTrain::update_sounds_runningnoise(sound_source &Sound)
|
|
{
|
|
// frequency calculation
|
|
auto const normalizer{(true == Sound.is_combined() ? mvOccupied->Vmax * 0.01f : 1.f)};
|
|
auto const soundfrequency{Sound.m_frequencyoffset + Sound.m_frequencyfactor * mvOccupied->Vel * normalizer};
|
|
|
|
// volume calculation
|
|
auto volume = Sound.m_amplitudeoffset + Sound.m_amplitudefactor * std::lerp(mvOccupied->Vel / (1 + mvOccupied->Vmax), 1.0,
|
|
0.5); // scale base volume between 0.5-1.0
|
|
if (std::abs(mvOccupied->nrot) > 0.01)
|
|
{
|
|
// hamulce wzmagaja halas
|
|
auto const brakeforceratio{(std::clamp(mvOccupied->UnitBrakeForce / std::max(1.0, mvOccupied->BrakeForceR(1.0, mvOccupied->Vel) / (mvOccupied->NAxles * std::max(1, mvOccupied->NBpA))), 0.0, 1.0))};
|
|
|
|
volume *= 1 + 0.125 * brakeforceratio;
|
|
}
|
|
// scale volume by track quality
|
|
// TODO: track quality and/or environment factors as separate subroutine
|
|
volume *= std::lerp(0.8, 1.2, std::clamp(DynamicObject->MyTrack->iQualityFlag / 20.0, 0.0, 1.0));
|
|
// for single sample sounds muffle the playback at low speeds
|
|
if (false == Sound.is_combined())
|
|
{
|
|
volume *= std::lerp(0.0, 1.0, std::clamp(mvOccupied->Vel / 25.0, 0.0, 1.0));
|
|
}
|
|
|
|
if (volume > 0.05)
|
|
{
|
|
Sound.pitch(static_cast<float>(soundfrequency)).gain(static_cast<float>(volume)).play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
Sound.stop();
|
|
}
|
|
}
|
|
|
|
void TTrain::update_sounds_radio()
|
|
{
|
|
|
|
radio_message_played = false;
|
|
if (false == m_radiomessages.empty())
|
|
{
|
|
// erase completed radio messages from the list
|
|
std::erase_if(m_radiomessages, [](auto const &source) { return false == source.second->is_playing(); });
|
|
}
|
|
// adjust audibility of remaining messages based on current radio conditions
|
|
auto const radioenabled{mvOccupied->RadioPowered()};
|
|
for (auto const &[messagechannel, messagesound] : m_radiomessages)
|
|
{
|
|
auto const volume{true == radioenabled && Dynamic()->Mechanik != nullptr && messagechannel == RadioChannel() ? m_radiovolume : 0.0};
|
|
messagesound->gain(static_cast<float>(volume));
|
|
radio_message_played |= true == radioenabled && Dynamic()->Mechanik != nullptr && messagechannel == RadioChannel();
|
|
}
|
|
// radiostop
|
|
if (m_radiostop)
|
|
{
|
|
if (true == radioenabled && true == mvOccupied->RadioStopFlag)
|
|
{
|
|
m_radiostop->play(sound_flags::exclusive | sound_flags::looping);
|
|
radio_message_played |= true;
|
|
}
|
|
else
|
|
{
|
|
m_radiostop->stop();
|
|
}
|
|
}
|
|
if (radio_message_played)
|
|
{
|
|
btLampkaRadioMessage.gain(m_radiovolume);
|
|
}
|
|
}
|
|
|
|
void TTrain::update_screens(double dt)
|
|
{
|
|
for (auto &screen : m_screens)
|
|
{
|
|
if (screen.updatetimecounter >= 0)
|
|
screen.updatetimecounter += dt;
|
|
|
|
if (screen.updatetimecounter <= screen.updatetime)
|
|
continue;
|
|
|
|
screen.updatetimecounter = screen.updatetime > 0 ? 0 : -1;
|
|
|
|
auto state_dict = GetTrainState(screen.parameters);
|
|
|
|
state_dict->insert("touches", *screen.touch_list);
|
|
screen.touch_list->clear();
|
|
|
|
Application.request({screen.script, state_dict, screen.rt});
|
|
}
|
|
}
|
|
|
|
void TTrain::update_script_screens()
|
|
{
|
|
auto &queue{Application.screens()};
|
|
for (auto &entry : m_scriptscreens)
|
|
{
|
|
if (false == queue.due(*entry.screen))
|
|
{
|
|
continue;
|
|
}
|
|
auto input{GetTrainState(entry.parameters)};
|
|
input->insert("touches", *entry.touch_list);
|
|
entry.touch_list->clear();
|
|
queue.submit(entry.screen, std::move(input), id());
|
|
}
|
|
}
|
|
|
|
bool TTrain::find_screen_surface(std::string const &Target, std::string_view const Kind, TSubModel *&Submodel, ITexture *&Texture) const
|
|
{
|
|
Submodel = DynamicObject->mdKabina ? DynamicObject->mdKabina->GetFromName(Target) :
|
|
DynamicObject->mdLowPolyInt ? DynamicObject->mdLowPolyInt->GetFromName(Target) :
|
|
nullptr;
|
|
if (Submodel == nullptr)
|
|
{
|
|
WriteLog(std::format("{}: submodel {} not found - Ignoring screen", Kind, Target));
|
|
return false;
|
|
}
|
|
auto const material{Submodel->GetMaterial()};
|
|
if (material <= 0)
|
|
{
|
|
// sub model nie posiada tekstury lub tekstura wymienna - nie obslugiwana
|
|
WriteLog(std::format("{}: invalid texture id {} - Ignoring screen", Kind, material));
|
|
return false;
|
|
}
|
|
|
|
Texture = &GfxRenderer->Texture(GfxRenderer->Material(material)->GetTexture(0));
|
|
return true;
|
|
}
|
|
|
|
void TTrain::load_script_screen(cParser &Parser, script_language const Language)
|
|
{
|
|
script_screen_entry entry;
|
|
// the block is read whole even when the script screens are off
|
|
entry.config.deserialize(Parser);
|
|
if (entry.config.script.empty())
|
|
{
|
|
return;
|
|
}
|
|
if (auto path{script_screens::screen_script_path(DynamicObject->asBaseDir, entry.config.script)}; path.has_value())
|
|
{
|
|
entry.config.script = std::move(*path);
|
|
}
|
|
else
|
|
{
|
|
ErrorLog(std::format("Bad script screen: \"{}\" leads outside the game's folder", entry.config.script));
|
|
return;
|
|
}
|
|
|
|
TSubModel *submodel{nullptr};
|
|
ITexture *texture{nullptr};
|
|
auto &queue{Application.screens()};
|
|
if (false == queue.runs(Language))
|
|
{
|
|
// the screens of the language are off
|
|
return;
|
|
}
|
|
if (entry.config.target != "none" &&
|
|
false == find_screen_surface(entry.config.target, Language == script_language::lua ? "Lua Screen" : "WASM Screen", submodel, texture))
|
|
{
|
|
return;
|
|
}
|
|
|
|
entry.screen = queue.acquire({.kind = script_screen_kind::cab,
|
|
.language = Language,
|
|
.script = entry.config.script,
|
|
.key = std::format("cab:{}:{}:{}", DynamicObject->name(), entry.config.target, entry.config.script),
|
|
.texture = texture,
|
|
.frames = entry.config.frames});
|
|
if (entry.screen == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
if (texture != nullptr)
|
|
{
|
|
// make the surface static so it doesn't get destroyed by garbage collector if the user spends long time outside cab
|
|
texture->create(true);
|
|
}
|
|
if (false == entry.config.parameters.empty())
|
|
{
|
|
entry.parameters = dictionary_source(entry.config.parameters);
|
|
}
|
|
entry.touch_list = std::make_shared<std::vector<glm::vec2>>();
|
|
if (submodel != nullptr)
|
|
{
|
|
submodel->screen_touch_list = entry.touch_list;
|
|
}
|
|
m_scriptscreens.emplace_back(std::move(entry));
|
|
}
|
|
|
|
void TTrain::add_distance(double const Distance)
|
|
{
|
|
|
|
auto const meterenabled{m_distancecounter >= 0 && (mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable)};
|
|
|
|
if (true == meterenabled)
|
|
{
|
|
m_distancecounter += static_cast<float>(Distance * Occupied()->CabOccupied);
|
|
}
|
|
else
|
|
{
|
|
m_distancecounter = -1.f;
|
|
}
|
|
}
|
|
|
|
bool TTrain::CabChange(int iDirection)
|
|
{ // McZapkie-090902: zmiana kabiny 1->0->2 i z powrotem
|
|
if (DynamicObject->Mechanik == nullptr || true == DynamicObject->Mechanik->AIControllFlag)
|
|
{
|
|
// jeśli prowadzi AI albo jest w innym członie
|
|
// jak AI prowadzi, to nie można mu mieszać
|
|
if (std::abs(mvOccupied->CabOccupied + iDirection) > 1)
|
|
return false; // ewentualna zmiana pojazdu
|
|
mvOccupied->CabOccupied += iDirection;
|
|
}
|
|
else
|
|
{ // jeśli pojazd prowadzony ręcznie albo wcale (wagon)
|
|
mvOccupied->CabDeactivisationAuto();
|
|
if (mvOccupied->ChangeCab(iDirection) && InitializeCab(mvOccupied->CabOccupied, mvOccupied->TypeName + ".mmd"))
|
|
{
|
|
// zmiana kabiny w ramach tego samego pojazdu
|
|
mvOccupied->CabActivisationAuto(); // załączenie rozrządu (wirtualne kabiny)
|
|
DynamicObject->Mechanik->DirectionChange();
|
|
return true; // udało się zmienić kabinę
|
|
}
|
|
// aktywizacja poprzedniej, bo jeszcze nie wiadomo, czy jakiś pojazd jest
|
|
mvOccupied->CabActivisationAuto();
|
|
}
|
|
return false; // ewentualna zmiana pojazdu
|
|
}
|
|
|
|
// McZapkie-310302
|
|
// wczytywanie pliku z danymi multimedialnymi (dzwieki, kontrolki, kabiny)
|
|
bool TTrain::LoadMMediaFile(std::string const &asFileName)
|
|
{
|
|
using enum sound_placement;
|
|
using enum sound_type;
|
|
// initialize sounds so potential entries from previous vehicle don't stick around
|
|
std::unordered_map<std::string, std::tuple<std::optional<sound_source> &, sound_placement, float, sound_type, int, double>> internalsounds = {
|
|
{"ctrl:", {dsbNastawnikJazdy, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"ctrlscnd:", {dsbNastawnikBocz, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"reverserkey:", {dsbReverserKey, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"buzzer:", {dsbBuzzer, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"buzzershp:", {dsbBuzzerShp, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"radiostop:", {m_radiostop, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"slipalarm:", {dsbSlipAlarm, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"distancecounter:", {m_distancecounterclear, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"tachoclock:", {dsbHasler, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"switch:", {dsbSwitch, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"pneumaticswitch:", {dsbPneumaticSwitch, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"airsound:", {rsHiss, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, sound_parameters::amplitude, 100.0}},
|
|
{"airsound2:", {rsHissU, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, sound_parameters::amplitude, 100.0}},
|
|
{"airsound3:", {rsHissE, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, sound_parameters::amplitude, 100.0}},
|
|
{"airsound4:", {rsHissX, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, sound_parameters::amplitude, 100.0}},
|
|
{"airsound5:", {rsHissT, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, sound_parameters::amplitude, 100.0}},
|
|
{"localbrakesound:", {rsSBHiss, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, sound_parameters::amplitude, 100.0}},
|
|
{"localbrakesound2:", {rsSBHissU, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, sound_parameters::amplitude, 100.0}},
|
|
{"brakesound:", {rsBrake, internal, -1, single, sound_parameters::amplitude | sound_parameters::frequency, 100.0}},
|
|
{"fadesound:", {rsFadeSound, internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE, single, 0, 100.0}},
|
|
{"runningnoise:", {rsRunningNoise, internal, EU07_SOUND_GLOBALRANGE, single, sound_parameters::amplitude | sound_parameters::frequency, mvOccupied->Vmax}},
|
|
{"resonancenoise:", {rsResonanceNoise, internal, EU07_SOUND_GLOBALRANGE, single, sound_parameters::amplitude | sound_parameters::frequency, mvOccupied->Vmax}},
|
|
{"windsound:", {rsWindSound, internal, EU07_SOUND_GLOBALRANGE, single, sound_parameters::amplitude | sound_parameters::frequency, mvOccupied->Vmax}},
|
|
{"huntingnoise:", {rsHuntingNoise, internal, EU07_SOUND_GLOBALRANGE, single, sound_parameters::amplitude | sound_parameters::frequency, mvOccupied->Vmax}},
|
|
{"rainsound:", {m_rainsound, internal, -1, single, 0, 100.0}},
|
|
};
|
|
for (auto &[soundname, soundsource] : internalsounds)
|
|
{
|
|
std::get<std::optional<sound_source> &>(soundsource).reset();
|
|
}
|
|
// NOTE: since radiosound is an incomplete template not using std::optional it gets a special treatment
|
|
m_radiosound.owner(DynamicObject);
|
|
CabSoundLocations.clear();
|
|
|
|
cParser parser(asFileName, cParser::buffer_FILE, DynamicObject->asBaseDir, true, std::vector<std::string>(), true);
|
|
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
|
// parser.addCommentStyle( "#", "\n" );
|
|
std::string token;
|
|
do
|
|
{
|
|
token = "";
|
|
parser.getTokens();
|
|
parser >> token;
|
|
} while (token != "" && token != "internaldata:");
|
|
|
|
if (token == "internaldata:")
|
|
{
|
|
|
|
do
|
|
{
|
|
token = "";
|
|
parser.getTokens();
|
|
parser >> token;
|
|
|
|
auto lookup{internalsounds.find(token)};
|
|
if (lookup == internalsounds.end())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
auto const soundconfig{lookup->second};
|
|
sound_source sound{std::get<sound_placement>(soundconfig), std::get<float>(soundconfig)};
|
|
sound.deserialize(parser, std::get<sound_type>(soundconfig), std::get<int>(soundconfig), static_cast<int>(std::get<double>(soundconfig)));
|
|
sound.owner(DynamicObject);
|
|
std::get<std::optional<sound_source> &>(soundconfig) = sound;
|
|
} while (token != "");
|
|
|
|
// assign default samples to sound emitters which weren't included in the config file
|
|
if (!m_rainsound)
|
|
{
|
|
sound_source rainsound;
|
|
rainsound.deserialize("rainsound_default", single);
|
|
rainsound.owner(DynamicObject);
|
|
m_rainsound = rainsound;
|
|
}
|
|
if (!rsSBHiss)
|
|
{
|
|
// fallback for vehicles without defined local brake hiss sound
|
|
rsSBHiss = rsHiss;
|
|
}
|
|
if (!rsSBHissU)
|
|
{
|
|
// fallback for vehicles without defined local brake hiss sound
|
|
rsSBHissU = rsHissU;
|
|
}
|
|
if (rsBrake)
|
|
{
|
|
rsBrake->m_frequencyfactor /= static_cast<float>(1 + mvOccupied->Vmax);
|
|
}
|
|
if (rsResonanceNoise)
|
|
{
|
|
rsResonanceNoise->m_frequencyfactor /= static_cast<float>(1 + mvOccupied->Vmax);
|
|
}
|
|
if (rsWindSound)
|
|
{
|
|
rsWindSound->m_frequencyfactor /= static_cast<float>(1 + mvOccupied->Vmax);
|
|
}
|
|
if (rsRunningNoise)
|
|
{
|
|
rsRunningNoise->m_frequencyfactor /= static_cast<float>(1 + mvOccupied->Vmax);
|
|
}
|
|
if (rsHuntingNoise)
|
|
{
|
|
rsHuntingNoise->m_frequencyfactor /= static_cast<float>(1 + mvOccupied->Vmax);
|
|
}
|
|
}
|
|
std::vector<std::reference_wrapper<std::optional<sound_source>>> sounds = {
|
|
dsbReverserKey, dsbNastawnikJazdy, dsbNastawnikBocz, dsbSwitch, dsbPneumaticSwitch, rsHiss, rsHissU, rsHissE, rsHissX, rsHissT, rsSBHiss,
|
|
rsSBHissU, rsFadeSound, rsRunningNoise, rsResonanceNoise, rsWindSound, rsHuntingNoise, dsbHasler, dsbBuzzer, dsbBuzzerShp, dsbSlipAlarm, m_distancecounterclear,
|
|
m_rainsound, m_radiostop};
|
|
for (auto &sound : sounds)
|
|
{
|
|
if (sound.get())
|
|
{
|
|
CabSoundLocations.emplace_back(sound, sound.get()->offset());
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
|
|
{
|
|
m_controlmapper.clear();
|
|
// clear python screens
|
|
m_screens.clear();
|
|
m_scriptscreens.clear();
|
|
// reset sound positions
|
|
auto const nullvector{glm::vec3()};
|
|
std::vector<std::reference_wrapper<std::optional<sound_source>>> sounds = {
|
|
dsbReverserKey, dsbNastawnikJazdy, dsbNastawnikBocz, dsbSwitch, dsbPneumaticSwitch, rsHiss, rsHissU, rsHissE, rsHissX, rsHissT, rsSBHiss,
|
|
rsSBHissU, rsFadeSound, rsRunningNoise, rsResonanceNoise, rsWindSound, rsHuntingNoise, dsbHasler, dsbBuzzer, dsbBuzzerShp, dsbSlipAlarm, m_distancecounterclear,
|
|
m_rainsound, m_radiostop};
|
|
for (auto const &sound : sounds)
|
|
{
|
|
if (sound.get())
|
|
{
|
|
sound.get()->offset(nullvector);
|
|
}
|
|
}
|
|
m_radiosound.offset(nullvector);
|
|
for (auto const &[soundsource, soundoffset] : CabSoundLocations)
|
|
{
|
|
if (soundsource.get() && soundsource.get()->offset() == nullvector)
|
|
{
|
|
soundsource.get()->offset(soundoffset);
|
|
}
|
|
}
|
|
// reset view angles
|
|
pMechViewAngle = {0.0, 0.0};
|
|
|
|
is_cab_initialized = true; // the attempt may fail, but it's the attempt that counts
|
|
|
|
bool parse = false;
|
|
int cabindex = 0;
|
|
DynamicObject->mdKabina = nullptr; // likwidacja wskaźnika na dotychczasową kabinę
|
|
switch (NewCabNo)
|
|
{ // ustalenie numeru kabiny do wczytania
|
|
case -1:
|
|
cabindex = 2;
|
|
break;
|
|
case 1:
|
|
cabindex = 1;
|
|
break;
|
|
case 0:
|
|
cabindex = 0;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
iCabn = cabindex;
|
|
|
|
std::string cabstr("cab" + std::to_string(cabindex) + "definition:");
|
|
|
|
cParser parser(asFileName, cParser::buffer_FILE, DynamicObject->asBaseDir, true, std::vector<std::string>(), true);
|
|
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
|
// parser.addCommentStyle( "#", "\n" );
|
|
std::string token;
|
|
do
|
|
{
|
|
// szukanie kabiny
|
|
token = "";
|
|
parser.getTokens();
|
|
parser >> token;
|
|
} while (token != "" && token != cabstr);
|
|
|
|
if (token == cabstr)
|
|
{
|
|
// jeśli znaleziony wpis kabiny
|
|
Cabine[cabindex].Load(parser);
|
|
// NOTE: the position and angle definitions depend on strict entry order
|
|
// TODO: refactor into more flexible arrangement
|
|
parser.getTokens();
|
|
parser >> token;
|
|
if (token == std::string("driver" + std::to_string(cabindex) + "angle:"))
|
|
{
|
|
// camera view angle
|
|
parser.getTokens(2, false);
|
|
// angle is specified in degrees but internally stored in radians
|
|
glm::vec2 viewangle;
|
|
parser >> viewangle.y // yaw first, then pitch
|
|
>> viewangle.x;
|
|
pMechViewAngle = glm::radians(viewangle);
|
|
|
|
Global.pCamera.Angle.x = pMechViewAngle.x;
|
|
Global.pCamera.Angle.y = pMechViewAngle.y;
|
|
|
|
parser.getTokens();
|
|
parser >> token;
|
|
}
|
|
if (token == std::string("driver" + std::to_string(cabindex) + "pos:"))
|
|
{
|
|
// pozycja poczatkowa maszynisty
|
|
parser.getTokens(3, false);
|
|
parser >> pMechOffset.x >> pMechOffset.y >> pMechOffset.z;
|
|
pMechSittingPosition = pMechOffset;
|
|
|
|
parser.getTokens();
|
|
parser >> token;
|
|
}
|
|
// ABu: pozycja siedzaca mechanika
|
|
if (token == std::string("driver" + std::to_string(cabindex) + "sitpos:"))
|
|
{
|
|
// ABu 180404 pozycja siedzaca maszynisty
|
|
parser.getTokens(3, false);
|
|
parser >> pMechSittingPosition.x >> pMechSittingPosition.y >> pMechSittingPosition.z;
|
|
|
|
parser.getTokens();
|
|
parser >> token;
|
|
}
|
|
// else parse=false;
|
|
do
|
|
{
|
|
if (parse == true)
|
|
{
|
|
token = "";
|
|
parser.getTokens();
|
|
parser >> token;
|
|
}
|
|
else
|
|
{
|
|
parse = true;
|
|
}
|
|
// inicjacja kabiny
|
|
// Ra 2014-08: zmieniamy zasady - zamiast przypisywać submodel do
|
|
// istniejących obiektów animujących
|
|
// będziemy teraz uaktywniać obiekty animujące z tablicy i podawać im
|
|
// submodel oraz wskaźnik na parametr
|
|
if (token == std::string("cab" + std::to_string(cabindex) + "model:"))
|
|
{
|
|
// model kabiny
|
|
parser.getTokens();
|
|
parser >> token;
|
|
std::ranges::replace(token, '\\', '/');
|
|
if (token != "none")
|
|
{
|
|
// bieżąca sciezka do tekstur to dynamic/...
|
|
Global.asCurrentTexturePath = DynamicObject->asBaseDir;
|
|
// szukaj kabinę jako oddzielny model
|
|
// name can contain leading slash, erase it to avoid creation of double slashes when the name is combined with current directory
|
|
replace_slashes(token);
|
|
erase_leading_slashes(token);
|
|
if (token[0] == '/')
|
|
{
|
|
token.erase(0, 1);
|
|
}
|
|
TModel3d *kabina = TModelsManager::GetModel(DynamicObject->asBaseDir + token, true, true, Global.network_servers.empty() && !Global.network_client ? 0 : id());
|
|
// z powrotem defaultowa sciezka do tekstur
|
|
Global.asCurrentTexturePath = paths::textures;
|
|
// if (DynamicObject->mdKabina!=k)
|
|
if (kabina != nullptr)
|
|
{
|
|
DynamicObject->mdKabina = kabina; // nowa kabina
|
|
}
|
|
//(mdKabina) może zostać to samo po przejściu do innego członu bez
|
|
// zmiany kabiny, przy powrocie musi być wiązanie ponowne
|
|
// else
|
|
// break; //wyjście z pętli, bo model zostaje bez zmian
|
|
}
|
|
else if (cabindex == 1)
|
|
{
|
|
// model tylko, gdy nie ma kabiny 1
|
|
// McZapkie-170103: szukaj elementy kabiny w glownym modelu
|
|
DynamicObject->mdKabina = DynamicObject->mdModel;
|
|
}
|
|
clear_cab_controls();
|
|
}
|
|
/*
|
|
if (nullptr == DynamicObject->mdKabina)
|
|
{
|
|
// don't bother with other parts until the cab is initialised
|
|
continue;
|
|
}
|
|
*/
|
|
else if (true == initialize_gauge(parser, token, cabindex))
|
|
{
|
|
// matched the token, grab the next one
|
|
continue;
|
|
}
|
|
else if (true == initialize_button(parser, token, cabindex))
|
|
{
|
|
// matched the token, grab the next one
|
|
continue;
|
|
}
|
|
// TODO: add "pydestination:"
|
|
else if (token == "pyscreen:")
|
|
{
|
|
screen_entry screen;
|
|
screen.deserialize(parser);
|
|
if (false == screen.script.empty() && substr_path(screen.script).empty())
|
|
{
|
|
screen.script = DynamicObject->asBaseDir + screen.script;
|
|
}
|
|
|
|
ITexture *tex = nullptr;
|
|
TSubModel *submodel = nullptr;
|
|
if (screen.target != "none")
|
|
{
|
|
if (false == find_screen_surface(screen.target, "Python Screen", submodel, tex))
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// TODO: fix leak
|
|
tex = ITexture::null_texture();
|
|
tex->make_stub();
|
|
}
|
|
|
|
tex->create(true); // make the surface static so it doesn't get destroyed by garbage
|
|
// collector if the user spends long time outside cab
|
|
// TBD, TODO: keep texture handles around, so we can undo the static switch when the
|
|
// user changes cabs?
|
|
auto rt = std::make_shared<python_rt>();
|
|
rt->shared_tex = tex;
|
|
|
|
// record renderer and material binding for future update requests
|
|
m_screens.emplace_back(screen);
|
|
m_screens.back().rt = rt;
|
|
|
|
m_screens.back().touch_list = std::make_shared<std::vector<glm::vec2>>();
|
|
if (submodel)
|
|
submodel->screen_touch_list = m_screens.back().touch_list;
|
|
|
|
if (Global.python_displaywindows)
|
|
m_screens.back().viewer = std::make_unique<python_screen_viewer>(rt, m_screens.back().touch_list, m_screens.back().script);
|
|
}
|
|
else if (token == "luascreen:")
|
|
{
|
|
load_script_screen(parser, script_language::lua);
|
|
}
|
|
else if (token == "wasmscreen:")
|
|
{
|
|
load_script_screen(parser, script_language::wasm);
|
|
}
|
|
else if (token == "pyscreenupdatetime:")
|
|
{
|
|
parser.getTokens();
|
|
parser >> ScreenUpdateRate;
|
|
}
|
|
// btLampkaUnknown`"unknown",mdKabina,false);
|
|
} while (token != ""
|
|
// TODO: enable full per-cab deserialization when/if .mmd files get proper per-cab switch configuration
|
|
// && ( token != "cab1definition:" )
|
|
// && ( token != "cab2definition:" )
|
|
&& token != "cab0definition:");
|
|
for (auto &screen : m_screens)
|
|
{
|
|
if (screen.updatetime > 0)
|
|
{
|
|
screen.updatetime = std::max((int)screen.updatetime, Global.PythonScreenUpdateRate) * 0.001;
|
|
}
|
|
if (screen.updatetime == 0)
|
|
{
|
|
screen.updatetime = std::max(Global.PythonScreenUpdateRate, ScreenUpdateRate) * 0.001;
|
|
}
|
|
if (screen.updatetime < -1)
|
|
{
|
|
screen.updatetime = -screen.updatetime * 0.001;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
/*
|
|
if (DynamicObject->mdKabina)
|
|
{
|
|
*/
|
|
// configure placement of sound emitters which aren't bound with any device model, and weren't placed manually
|
|
auto const caboffset{glm::dvec3{(Cabine[cabindex].CabPos1 + Cabine[cabindex].CabPos2) * 0.5f} + glm::dvec3{0, 1, 0}};
|
|
// NOTE: since radiosound is an incomplete template not using std::optional it gets a special treatment
|
|
if (m_radiosound.offset() == nullvector)
|
|
{
|
|
m_radiosound.offset(btLampkaRadio.model_offset());
|
|
}
|
|
if (m_radiosound.offset() == nullvector)
|
|
{
|
|
m_radiosound.offset(caboffset);
|
|
}
|
|
std::vector<std::pair<std::reference_wrapper<std::optional<sound_source>>, glm::vec3>> soundlocations = {
|
|
{dsbReverserKey, ggDirKey.model_offset()},
|
|
{dsbNastawnikJazdy, ggJointCtrl.model_offset()},
|
|
{dsbNastawnikJazdy, ggMainCtrl.model_offset()}, // NOTE: fallback for vehicles without universal controller
|
|
{dsbNastawnikBocz, ggScndCtrl.model_offset()},
|
|
{dsbSwitch, caboffset},
|
|
{dsbPneumaticSwitch, caboffset},
|
|
{rsHiss, ggBrakeCtrl.model_offset()},
|
|
{rsHissU, ggBrakeCtrl.model_offset()},
|
|
{rsHissE, ggBrakeCtrl.model_offset()},
|
|
{rsHissX, ggBrakeCtrl.model_offset()},
|
|
{rsHissT, ggBrakeCtrl.model_offset()},
|
|
{rsSBHiss, ggLocalBrake.model_offset()},
|
|
{rsSBHiss, ggBrakeCtrl.model_offset()}, // NOTE: fallback if the local brake model can't be located
|
|
{rsSBHissU, ggLocalBrake.model_offset()},
|
|
{rsSBHissU, ggBrakeCtrl.model_offset()}, // NOTE: fallback if the local brake model can't be located
|
|
{rsFadeSound, caboffset},
|
|
{rsRunningNoise, caboffset},
|
|
{rsResonanceNoise, caboffset},
|
|
{rsWindSound, caboffset},
|
|
{rsHuntingNoise, caboffset},
|
|
{dsbHasler, caboffset},
|
|
{dsbBuzzer, btLampkaCzuwaka.model_offset()},
|
|
{dsbBuzzerShp, btLampkaCzuwaka.model_offset()},
|
|
{dsbSlipAlarm, caboffset},
|
|
{m_distancecounterclear, btLampkaCzuwaka.model_offset()},
|
|
{m_rainsound, caboffset},
|
|
{m_radiostop, m_radiosound.offset()},
|
|
};
|
|
for (auto const &[soundsource, soundoffset] : soundlocations)
|
|
{
|
|
if (soundsource.get() && soundsource.get()->offset() == nullvector)
|
|
{
|
|
soundsource.get()->offset(soundoffset);
|
|
}
|
|
}
|
|
// second pass, in case some items received no positioning due to missing submodels etc
|
|
for (auto const &[soundsource, soundoffset] : soundlocations)
|
|
{
|
|
if (soundsource.get() && soundsource.get()->offset() == nullvector)
|
|
{
|
|
soundsource.get()->offset(caboffset);
|
|
}
|
|
}
|
|
|
|
if (DynamicObject->mdKabina)
|
|
{
|
|
DynamicObject->mdKabina->Init(); // obrócenie modelu oraz optymalizacja, również zapisanie binarnego
|
|
// the vehicle has a cab, a player is in it: the odometer store keeps the vehicle also when its type has no
|
|
// driver's brake valve (eu07/maszyna#72)
|
|
DynamicObject->MoverParameters->Odometer.shown = true;
|
|
}
|
|
|
|
set_cab_controls(NewCabNo < 0 ? 2 : NewCabNo);
|
|
|
|
// set pantograpths (hujhujhuj)
|
|
change_pantograph_selection(0);
|
|
|
|
/*
|
|
return true;
|
|
}
|
|
return (token == "none");
|
|
*/
|
|
return true;
|
|
}
|
|
|
|
glm::dvec3 TTrain::MirrorPosition(bool lewe)
|
|
{ // zwraca współrzędne widoku kamery z lusterka
|
|
auto const shiftdirection{(lewe ? -1 : 1) * (iCabn == 2 ? 1 : -1)};
|
|
|
|
return DynamicObject->mMatrix *
|
|
glm::dvec4(mvOccupied->Dim.W * (0.5 * shiftdirection) + 0.2 * shiftdirection, 1.5 + Cabine[iCabn].CabPos1.y, std::lerp(Cabine[iCabn].CabPos1.z, Cabine[iCabn].CabPos2.z, 0.5), 1.0);
|
|
};
|
|
|
|
void TTrain::DynamicSet(TDynamicObject *d)
|
|
{ // taka proteza: chcę podłączyć
|
|
// kabinę EN57 bezpośrednio z
|
|
// silnikowym, aby nie robić tego
|
|
// przez ukrotnienie
|
|
// drugi silnikowy i tak musi być ukrotniony, podobnie jak kolejna jednostka
|
|
// problem się robi ze światłami, które będą zapalane w silnikowym, ale muszą
|
|
// świecić się w rozrządczych
|
|
// dla EZT światła czołowe będą "zapalane w silnikowym", ale widziane z
|
|
// rozrządczych
|
|
// również wczytywanie MMD powinno dotyczyć aktualnego członu
|
|
// problematyczna może być kwestia wybranej kabiny (w silnikowym...)
|
|
// jeśli silnikowy będzie zapięty odwrotnie (tzn. -1), to i tak powinno
|
|
// jeździć dobrze
|
|
// również hamowanie wykonuje się zaworem w członie, a nie w silnikowym...
|
|
DynamicObject = d; // jedyne miejsce zmiany
|
|
mvControlled = d ? DynamicObject->MoverParameters : nullptr; // albo silnikowy w EZT
|
|
mvOccupied = mvControlled;
|
|
|
|
if (DynamicObject == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
mvControlled = DynamicObject->FindPowered()->MoverParameters;
|
|
mvSecond = nullptr; // gdyby się nic nie znalazło
|
|
if (mvOccupied->Power > 1.0) // dwuczłonowe lub ukrotnienia, żeby nie szukać każdorazowo
|
|
{
|
|
if (mvOccupied->Couplers[1].Connected ? mvOccupied->Couplers[1].AllowedFlag & coupling::control : false)
|
|
{ // gdy jest człon od sprzęgu 1, a sprzęg łączony
|
|
// warsztatowo (powiedzmy)
|
|
if (mvOccupied->Couplers[1].Connected->Power > 1.0) // ten drugi ma moc
|
|
mvSecond = mvOccupied->Couplers[1].Connected; // wskaźnik na drugiego
|
|
}
|
|
else if (mvOccupied->Couplers[0].Connected ? mvOccupied->Couplers[0].AllowedFlag & coupling::control : false)
|
|
{ // gdy jest człon od sprzęgu 0, a sprzęg łączony
|
|
// warsztatowo (powiedzmy)
|
|
if (mvOccupied->Couplers[0].Connected->Power > 1.0) // ale ten drugi ma moc
|
|
mvSecond = mvOccupied->Couplers[0].Connected; // wskaźnik na drugiego
|
|
}
|
|
}
|
|
// cache nearest unit equipped with pantographs
|
|
{
|
|
auto *lookup{DynamicObject->FindPantographCarrier()};
|
|
// HACK: set pointer to existing vehicle to avoid error checking all over the place
|
|
mvPantographUnit = lookup != nullptr ? lookup->MoverParameters : mvControlled;
|
|
}
|
|
};
|
|
|
|
void TTrain::MoveToVehicle(TDynamicObject *target)
|
|
{
|
|
// > Ra: to nie może być tak robione, to zbytnia proteza jest
|
|
// indeed, too much hacks...
|
|
// TODO: cleanup
|
|
TTrain *target_train = simulation::Trains.find(target->name());
|
|
if (target_train)
|
|
{
|
|
// let's try to destroy this TTrain and move to already existing one
|
|
|
|
if (!Dynamic()->Mechanik || !Dynamic()->Mechanik->AIControllFlag)
|
|
{
|
|
// tylko jeśli ręcznie prowadzony
|
|
// jeśli prowadzi AI, to mu nie robimy dywersji!
|
|
Occupied()->CabDeactivisation();
|
|
Occupied()->CabOccupied = 0;
|
|
Occupied()->BrakeLevelSet(Occupied()->Handle->GetPos(bh_NP)); // rozwala sterowanie hamulcem GF 04-2016
|
|
Occupied()->MainCtrlPos = Occupied()->MainCtrlNoPowerPos();
|
|
Occupied()->ScndCtrlPos = 0;
|
|
Dynamic()->MechInside = false;
|
|
Dynamic()->Controller = AIdriver;
|
|
|
|
Dynamic()->bDisplayCab = false;
|
|
Dynamic()->ABuSetModelShake({});
|
|
|
|
if (Dynamic()->Mechanik)
|
|
Dynamic()->Mechanik->MoveTo(target);
|
|
|
|
target_train->Occupied()->LimPipePress = target_train->Occupied()->PipePress;
|
|
target_train->Occupied()->CabActivisationAuto(true); // załączenie rozrządu (wirtualne kabiny)
|
|
target_train->Dynamic()->MechInside = true;
|
|
if (target_train->Dynamic()->Mechanik)
|
|
{
|
|
target_train->Dynamic()->Controller = target_train->Dynamic()->Mechanik->AIControllFlag;
|
|
target_train->Dynamic()->Mechanik->DirectionChange();
|
|
}
|
|
else
|
|
{
|
|
target_train->Dynamic()->Controller = Humandriver;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
target_train->Dynamic()->bDisplayCab = false;
|
|
target_train->Dynamic()->ABuSetModelShake({});
|
|
}
|
|
|
|
target_train->Dynamic()->ABuSetModelShake({}); // zerowanie przesunięcia przed powrotem?
|
|
|
|
// potentially move player
|
|
if (simulation::Train == this)
|
|
{
|
|
simulation::Train = target_train;
|
|
// our local driver may potentially be in external view mode, in which case we shouldn't activate cab visualization
|
|
target_train->Dynamic()->bDisplayCab |= !FreeFlyModeFlag;
|
|
}
|
|
|
|
// delete this TTrain
|
|
pending_delete = true;
|
|
}
|
|
else
|
|
{
|
|
// move this TTrain to other dynamic
|
|
|
|
// remove TTrain from global list, we're going to change dynamic anyway
|
|
simulation::Trains.detach(Dynamic()->name());
|
|
|
|
if (!Dynamic()->Mechanik || !Dynamic()->Mechanik->AIControllFlag)
|
|
{
|
|
// tylko jeśli ręcznie prowadzony
|
|
// jeśli prowadzi AI, to mu nie robimy dywersji!
|
|
|
|
Occupied()->CabDeactivisation();
|
|
Occupied()->CabOccupied = 0;
|
|
Occupied()->BrakeLevelSet(Occupied()->Handle->GetPos(bh_NP)); // rozwala sterowanie hamulcem GF 04-2016
|
|
Occupied()->MainCtrlPos = Occupied()->MainCtrlNoPowerPos();
|
|
Occupied()->ScndCtrlPos = 0;
|
|
Dynamic()->MechInside = false;
|
|
Dynamic()->Controller = AIdriver;
|
|
|
|
Dynamic()->bDisplayCab = false;
|
|
Dynamic()->ABuSetModelShake({});
|
|
|
|
if (Dynamic()->Mechanik)
|
|
Dynamic()->Mechanik->MoveTo(target);
|
|
|
|
DynamicSet(target);
|
|
|
|
Dynamic()->MechInside = true;
|
|
if (Dynamic()->Mechanik)
|
|
{
|
|
Dynamic()->Controller = Dynamic()->Mechanik->AIControllFlag;
|
|
Dynamic()->Mechanik->DirectionChange();
|
|
}
|
|
else
|
|
{
|
|
Dynamic()->Controller = Humandriver;
|
|
}
|
|
|
|
Occupied()->LimPipePress = Occupied()->PipePress;
|
|
Occupied()->CabActivisationAuto(true); // załączenie rozrządu (wirtualne kabiny)
|
|
}
|
|
else
|
|
{
|
|
Dynamic()->bDisplayCab = false;
|
|
Dynamic()->ABuSetModelShake({});
|
|
|
|
DynamicSet(target);
|
|
}
|
|
|
|
{
|
|
auto const filename{Occupied()->TypeName + ".mmd"};
|
|
LoadMMediaFile(filename);
|
|
InitializeCab(Occupied()->CabActive, filename);
|
|
}
|
|
|
|
Dynamic()->ABuSetModelShake({}); // zerowanie przesunięcia przed powrotem?
|
|
|
|
if (simulation::Train == this)
|
|
{
|
|
// our local driver may potentially be in external view mode, in which case we shouldn't activate cab visualization
|
|
Dynamic()->bDisplayCab |= !FreeFlyModeFlag;
|
|
}
|
|
|
|
// add it back with updated dynamic name
|
|
simulation::Trains.insert(this);
|
|
}
|
|
}
|
|
|
|
// checks whether specified point is within boundaries of the active cab
|
|
bool TTrain::point_inside(glm::dvec3 const Point) const
|
|
{
|
|
|
|
return Point.x >= Cabine[iCabn].CabPos1.x && Point.x <= Cabine[iCabn].CabPos2.x && Point.y >= Cabine[iCabn].CabPos1.y + 0.5 && Point.y <= Cabine[iCabn].CabPos2.y + 1.8 &&
|
|
Point.z >= Cabine[iCabn].CabPos1.z && Point.z <= Cabine[iCabn].CabPos2.z;
|
|
}
|
|
|
|
glm::dvec3 TTrain::clamp_inside(glm::dvec3 const &Point) const
|
|
{
|
|
|
|
if (DebugModeFlag)
|
|
{
|
|
return Point;
|
|
}
|
|
|
|
// the bounds come from the .mmd as written, and some cabs have them reversed (the B cars of SA134 and 21xM,
|
|
// ET40, 754...); std::clamp is undefined for those and on MSVC makes the camera jump between the two bounds
|
|
// every frame, as its result is fed back here. safe_clamp keeps the camera on the upper bound, as 26.05 did
|
|
return {safe_clamp(Point.x, (double)Cabine[iCabn].CabPos1.x, (double)Cabine[iCabn].CabPos2.x), safe_clamp(Point.y, (double)Cabine[iCabn].CabPos1.y + 0.5, (double)Cabine[iCabn].CabPos2.y + 1.8),
|
|
safe_clamp(Point.z, (double)Cabine[iCabn].CabPos1.z, (double)Cabine[iCabn].CabPos2.z)};
|
|
}
|
|
|
|
const TTrain::screenentry_sequence &TTrain::get_screens()
|
|
{
|
|
update_screens(Timer::GetDeltaTime());
|
|
return m_screens;
|
|
}
|
|
|
|
void TTrain::radio_message(sound_source *Message, int const Channel)
|
|
{
|
|
|
|
if (auto const soundrange{Message->range()}; soundrange > 0 && glm::length2(Message->location() - glm::dvec3{DynamicObject->GetPosition()}) > sq(soundrange))
|
|
{
|
|
// skip message playback if the receiver is outside of the emitter's range
|
|
return;
|
|
}
|
|
// NOTE: we initiate playback of all sounds in range, in case the user switches on the radio or tunes to the right channel mid-play
|
|
m_radiomessages.emplace_back(Channel, std::make_shared<sound_source>(m_radiosound));
|
|
// assign sound to the template and play it
|
|
auto &message = *m_radiomessages.back().second.get();
|
|
auto const radioenabled{mvOccupied->RadioPowered()};
|
|
auto const volume{true == radioenabled && Dynamic()->Mechanik != nullptr && Channel == RadioChannel() ? 1.0 : 0.0};
|
|
message.copy_sounds(*Message).gain(static_cast<float>(volume)).play();
|
|
}
|
|
|
|
// clears state of all cabin controls
|
|
void TTrain::clear_cab_controls()
|
|
{
|
|
// indicators exposed to custom control devices
|
|
btLampkaSHP.Clear(0);
|
|
btLampkaCzuwaka.Clear(1);
|
|
btLampkaOpory.Clear(2);
|
|
btLampkaWylSzybki.Clear(3);
|
|
btLampkaNadmSil.Clear(4);
|
|
btLampkaStyczn.Clear(5);
|
|
btLampkaPoslizg.Clear(6);
|
|
btLampkaNadmPrzetw.Clear((mvControlled->TrainType & dt_EZT) != 0 ? -1 : 7); // EN57 nie ma tej lampki
|
|
btLampkaPrzetwOff.Clear((mvControlled->TrainType & dt_EZT) != 0 ? 7 : -1); // za to ma tę
|
|
btLampkaNadmSpr.Clear(8);
|
|
btLampkaNadmWent.Clear(9);
|
|
btLampkaWysRozr.Clear((mvControlled->TrainType & dt_ET22) != 0 ? -1 : 10); // ET22 nie ma tej lampki
|
|
btLampkaOgrzewanieSkladu.Clear(11);
|
|
// overheat indicator lamps
|
|
btLampkaOilOverheat.Clear(-1);
|
|
btLampkaWaterOverheat.Clear(-1);
|
|
btLampkaWaterAuxOverheat.Clear(-1);
|
|
btLampkaEngineOverheat.Clear(-1);
|
|
btHaslerBrakes.Clear(12); // ciśnienie w cylindrach do odbijania na haslerze
|
|
btHaslerCurrent.Clear(13); // prąd na silnikach do odbijania na haslerze
|
|
// Numer 14 jest używany dla buczka SHP w update_sounds()
|
|
// Jeśli ustawiamy nową wartość dla PoKeys wolna jest 15
|
|
|
|
// other cab controls
|
|
// TODO: arrange in more readable manner, and eventually refactor
|
|
ggJointCtrl.Clear();
|
|
ggMainCtrl.Clear();
|
|
ggMainCtrlAct.Clear();
|
|
ggScndCtrl.Clear();
|
|
ggScndCtrlButton.Clear();
|
|
ggScndCtrlOffButton.Clear();
|
|
ggDistanceCounterButton.Clear();
|
|
ggDirKey.Clear();
|
|
ggDirForwardButton.Clear();
|
|
ggDirNeutralButton.Clear();
|
|
ggDirBackwardButton.Clear();
|
|
ggBrakeCtrl.Clear();
|
|
ggLocalBrake.Clear();
|
|
ggAlarmChain.Clear();
|
|
ggBrakeProfileCtrl.Clear();
|
|
ggBrakeProfileG.Clear();
|
|
ggBrakeProfileR.Clear();
|
|
ggBrakeOperationModeCtrl.Clear();
|
|
ggWiperSw.Clear();
|
|
ggMaxCurrentCtrl.Clear();
|
|
ggMainOffButton.Clear();
|
|
ggMainOnButton.Clear();
|
|
for (auto &remotelinebreaker : m_remotelinebreakers)
|
|
{
|
|
remotelinebreaker.main_switch.Clear();
|
|
remotelinebreaker.on_button.Clear();
|
|
remotelinebreaker.off_button.Clear();
|
|
remotelinebreaker.held_without_switch = false;
|
|
}
|
|
ggSecurityResetButton.Clear();
|
|
ggSHPResetButton.Clear();
|
|
ggReleaserButton.Clear();
|
|
ggSpringBrakeOnButton.Clear();
|
|
ggSpringBrakeOffButton.Clear();
|
|
ggUniveralBrakeButton1.Clear();
|
|
ggUniveralBrakeButton2.Clear();
|
|
ggUniveralBrakeButton3.Clear();
|
|
ggEPFuseButton.Clear();
|
|
ggSandButton.Clear();
|
|
ggAutoSandButton.Clear();
|
|
ggAntiSlipButton.Clear();
|
|
ggHornButton.Clear();
|
|
ggHornLowButton.Clear();
|
|
ggHornHighButton.Clear();
|
|
ggWhistleButton.Clear();
|
|
ggHelperButton.Clear();
|
|
ggNextCurrentButton.Clear();
|
|
ggSpeedControlIncreaseButton.Clear();
|
|
ggSpeedControlDecreaseButton.Clear();
|
|
ggSpeedControlPowerIncreaseButton.Clear();
|
|
ggSpeedControlPowerDecreaseButton.Clear();
|
|
for (auto &speedctrlbutton : ggSpeedCtrlButtons)
|
|
{
|
|
speedctrlbutton.Clear();
|
|
}
|
|
for (auto &universal : ggUniversals)
|
|
{
|
|
universal.Clear();
|
|
}
|
|
for (auto &item : ggInverterEnableButtons)
|
|
{
|
|
item.Clear();
|
|
}
|
|
for (auto &item : ggInverterDisableButtons)
|
|
{
|
|
item.Clear();
|
|
}
|
|
for (auto &item : ggInverterToggleButtons)
|
|
{
|
|
item.Clear();
|
|
}
|
|
for (auto &relayresetbutton : ggRelayResetButtons)
|
|
{
|
|
relayresetbutton.Clear();
|
|
}
|
|
ggInstrumentLightButton.Clear();
|
|
ggDashboardLightButton.Clear();
|
|
ggTimetableLightButton.Clear();
|
|
// hunter-091012
|
|
ggCabLightDimButton.Clear();
|
|
ggCompartmentLightsButton.Clear();
|
|
ggCompartmentLightsOnButton.Clear();
|
|
ggCompartmentLightsOffButton.Clear();
|
|
ggBatteryButton.Clear();
|
|
ggBatteryOnButton.Clear();
|
|
ggBatteryOffButton.Clear();
|
|
ggCabActivationButton.Clear();
|
|
//-------
|
|
ggFuseButton.Clear();
|
|
ggConverterFuseButton.Clear();
|
|
ggStLinOffButton.Clear();
|
|
ggRadioChannelSelector.Clear();
|
|
ggRadioChannelPrevious.Clear();
|
|
ggRadioChannelNext.Clear();
|
|
ggRadioStop.Clear();
|
|
ggRadioTest.Clear();
|
|
ggRadioCall1.Clear();
|
|
ggRadioCall3.Clear();
|
|
ggRadioVolumeSelector.Clear();
|
|
ggRadioVolumePrevious.Clear();
|
|
ggRadioVolumeNext.Clear();
|
|
ggRadioOnButton.Clear();
|
|
ggRadioOffButton.Clear();
|
|
ggRadioFuseOnButton.Clear();
|
|
ggRadioFuseOffButton.Clear();
|
|
ggDoorLeftPermitButton.Clear();
|
|
ggDoorRightPermitButton.Clear();
|
|
ggDoorPermitPresetButton.Clear();
|
|
ggDoorLeftButton.Clear();
|
|
ggDoorRightButton.Clear();
|
|
ggDoorLeftOnButton.Clear();
|
|
ggDoorRightOnButton.Clear();
|
|
ggDoorLeftOffButton.Clear();
|
|
ggDoorRightOffButton.Clear();
|
|
ggDoorAllOnButton.Clear();
|
|
ggDoorAllOffButton.Clear();
|
|
ggTrainHeatingButton.Clear();
|
|
ggSignallingButton.Clear();
|
|
ggDoorSignallingButton.Clear();
|
|
ggDoorStepButton.Clear();
|
|
ggDepartureSignalButton.Clear();
|
|
ggCompressorButton.Clear();
|
|
ggCompressorLocalButton.Clear();
|
|
ggConverterButton.Clear();
|
|
ggConverterOffButton.Clear();
|
|
ggConverterLocalButton.Clear();
|
|
ggMainButton.Clear();
|
|
/*
|
|
ggPantFrontButton.Clear();
|
|
ggPantRearButton.Clear();
|
|
ggPantFrontButtonOff.Clear();
|
|
ggPantRearButtonOff.Clear();
|
|
*/
|
|
ggPantAllDownButton.Clear();
|
|
ggPantSelectedButton.Clear();
|
|
ggPantSelectedDownButton.Clear();
|
|
ggPantValvesButton.Clear();
|
|
ggPantCompressorButton.Clear();
|
|
ggPantCompressorValve.Clear();
|
|
|
|
ggPantValvesOff.Clear();
|
|
ggPantValvesUpdate.Clear();
|
|
|
|
ggI1B.Clear();
|
|
ggI2B.Clear();
|
|
ggI3B.Clear();
|
|
ggItotalB.Clear();
|
|
ggOilPressB.Clear();
|
|
ggWater1TempB.Clear();
|
|
|
|
ggClockSInd.Clear();
|
|
ggClockMInd.Clear();
|
|
ggClockHInd.Clear();
|
|
ggEngineVoltage.Clear();
|
|
ggLVoltage.Clear();
|
|
ggMainGearStatus.Clear();
|
|
ggIgnitionKey.Clear();
|
|
|
|
ggWaterPumpBreakerButton.Clear();
|
|
ggWaterPumpButton.Clear();
|
|
ggWaterHeaterBreakerButton.Clear();
|
|
ggWaterHeaterButton.Clear();
|
|
ggWaterCircuitsLinkButton.Clear();
|
|
ggFuelPumpButton.Clear();
|
|
ggOilPumpButton.Clear();
|
|
ggOilFuelPumpButton.Clear();
|
|
ggMotorBlowersFrontButton.Clear();
|
|
ggMotorBlowersRearButton.Clear();
|
|
ggMotorBlowersAllOffButton.Clear();
|
|
|
|
btLampkaPrzetw.Clear();
|
|
btLampkaPrzetwB.Clear();
|
|
btLampkaPrzetwBOff.Clear();
|
|
btLampkaPrzetwAOff.Clear();
|
|
btLampkaPrzekRozn.Clear();
|
|
btLampkaPrzekRoznPom.Clear();
|
|
btLampkaUkrotnienie.Clear();
|
|
btLampkaHamPosp.Clear();
|
|
btLampkaWylSzybkiOff.Clear();
|
|
btLampkaWylSzybkiB.Clear();
|
|
btLampkaWylSzybkiBOff.Clear();
|
|
btLampkaMainBreakerReady.Clear();
|
|
btLampkaMainBreakerBlinkingIfReady.Clear();
|
|
btLampkaBezoporowa.Clear();
|
|
btLampkaBezoporowaB.Clear();
|
|
btLampkaMaxSila.Clear();
|
|
btLampkaPrzekrMaxSila.Clear();
|
|
btLampkaRadio.Clear();
|
|
btLampkaRadioMessage.Clear();
|
|
btLampkaRadioStop.Clear();
|
|
btLampkaHamulecReczny.Clear();
|
|
btLampkaBlokadaDrzwi.Clear();
|
|
btLampkaDoorLockOff.Clear();
|
|
for (auto &universal : btUniversals)
|
|
{
|
|
universal.Clear();
|
|
}
|
|
btInstrumentLight.Clear();
|
|
btDashboardLight.Clear();
|
|
btTimetableLight.Clear();
|
|
btLampkaWentZaluzje.Clear();
|
|
btLampkaDoorLeft.Clear();
|
|
btLampkaDoorRight.Clear();
|
|
btLampkaDepartureSignal.Clear();
|
|
btLampkaRezerwa.Clear();
|
|
btLampkaBoczniki.Clear();
|
|
btLampkaBocznik1.Clear();
|
|
btLampkaBocznik2.Clear();
|
|
btLampkaBocznik3.Clear();
|
|
btLampkaBocznik4.Clear();
|
|
btLampkaGear1.Clear();
|
|
btLampkaGear2.Clear();
|
|
btLampkaHydroLockup.Clear();
|
|
btLampkaRadiotelefon.Clear();
|
|
btLampkaHamienie.Clear();
|
|
btLampkaBrakingOff.Clear();
|
|
btLampkaED.Clear();
|
|
btLampkaBrakeProfileG.Clear();
|
|
btLampkaBrakeProfileP.Clear();
|
|
btLampkaBrakeProfileR.Clear();
|
|
btLampkaSpringBrakeActive.Clear();
|
|
btLampkaSpringBrakeInactive.Clear();
|
|
btLampkaSprezarka.Clear();
|
|
btLampkaSprezarkaB.Clear();
|
|
btLampkaSprezarkaOff.Clear();
|
|
btLampkaSprezarkaBOff.Clear();
|
|
btLampkaFuelPumpOff.Clear();
|
|
btLampkaOilPump.Clear();
|
|
btLampkaNapNastHam.Clear();
|
|
btLampkaOporyB.Clear();
|
|
btLampkaStycznB.Clear();
|
|
btLampkaHamowanie1zes.Clear();
|
|
btLampkaHamowanie2zes.Clear();
|
|
btLampkaNadmPrzetwB.Clear();
|
|
btLampkaHVoltageB.Clear();
|
|
btLampkaForward.Clear();
|
|
btLampkaBackward.Clear();
|
|
btLampkaNeutral.Clear();
|
|
// light indicators
|
|
btLampkaUpperLight.Clear();
|
|
btLampkaLeftLight.Clear();
|
|
btLampkaRightLight.Clear();
|
|
btLampkaLeftEndLight.Clear();
|
|
btLampkaRightEndLight.Clear();
|
|
btLampkaRearUpperLight.Clear();
|
|
btLampkaRearLeftLight.Clear();
|
|
btLampkaRearRightLight.Clear();
|
|
btLampkaRearLeftEndLight.Clear();
|
|
btLampkaRearRightEndLight.Clear();
|
|
// others
|
|
btLampkaMalfunction.Clear();
|
|
btLampkaMalfunctionB.Clear();
|
|
btLampkaMotorBlowers.Clear();
|
|
btLampkaCoolingFans.Clear();
|
|
btLampkaLouvresClosed.Clear();
|
|
btLampkaTempomat.Clear();
|
|
btLampkaDistanceCounter.Clear();
|
|
|
|
ggLeftLightButton.Clear();
|
|
ggRightLightButton.Clear();
|
|
ggUpperLightButton.Clear();
|
|
ggDimHeadlightsButton.Clear();
|
|
ggModernLightDimSw.Clear();
|
|
ggLeftEndLightButton.Clear();
|
|
ggRightEndLightButton.Clear();
|
|
ggLightsButton.Clear();
|
|
ggCompressorListButton.Clear();
|
|
// hunter-230112
|
|
ggRearLeftLightButton.Clear();
|
|
ggRearRightLightButton.Clear();
|
|
ggRearUpperLightButton.Clear();
|
|
ggRearLeftEndLightButton.Clear();
|
|
ggRearRightEndLightButton.Clear();
|
|
}
|
|
|
|
// NOTE: we can get rid of this function once we have per-cab persistent state
|
|
void TTrain::set_cab_controls(int const Cab)
|
|
{
|
|
// switches
|
|
// battery
|
|
ggBatteryButton.PutValue(ggBatteryButton.type() == TGaugeType::push ? 0.5f : mvOccupied->Power24vIsAvailable ? 1.f : 0.f);
|
|
// activation
|
|
ggCabActivationButton.PutValue(ggCabActivationButton.type() == TGaugeType::push ? 0.5f : mvOccupied->IsCabMaster() ? 1.f : 0.f);
|
|
// line breaker
|
|
if (ggMainButton.SubModel != nullptr)
|
|
{ // instead of single main button there can be on/off pair
|
|
ggMainButton.PutValue(ggMainButton.type() == TGaugeType::push ? 0.5f : m_linebreakerstate > 0 ? 1.f : 0.f);
|
|
}
|
|
// line breakers of the other vehicles in multiple
|
|
for (std::size_t index = 0; index < m_remotelinebreakers.size(); ++index)
|
|
{
|
|
auto &mainswitch{m_remotelinebreakers[index].main_switch};
|
|
if (mainswitch.SubModel == nullptr)
|
|
{
|
|
continue;
|
|
}
|
|
if (mainswitch.type() == TGaugeType::push)
|
|
{
|
|
mainswitch.PutValue(0.5f);
|
|
continue;
|
|
}
|
|
auto const *engine{remote_engine(index)};
|
|
mainswitch.PutValue(engine != nullptr && engine_start::remote_switch::is_running(*engine) ? 1.f : 0.f);
|
|
}
|
|
|
|
if (ggModernLightDimSw.SubModel != nullptr)
|
|
{
|
|
mvOccupied->modernDimmerPosition = mvOccupied->modernDimmerDefaultPosition;
|
|
ggModernLightDimSw.PutValue(static_cast<float>(mvOccupied->modernDimmerDefaultPosition));
|
|
}
|
|
|
|
// Init separate buttons
|
|
if (ggPantValvesUpdate.SubModel != nullptr)
|
|
{
|
|
ggPantValvesUpdate.PutValue(0.f);
|
|
}
|
|
if (ggPantValvesOff.SubModel != nullptr)
|
|
{
|
|
ggPantValvesOff.PutValue(0.f);
|
|
}
|
|
|
|
// motor connectors
|
|
ggStLinOffButton.PutValue(mvControlled->StLinSwitchOff ? 1.f : 0.f);
|
|
// radio
|
|
ggRadioChannelSelector.PutValue(static_cast<float>((Dynamic()->Mechanik ? Dynamic()->Mechanik->iRadioChannel : 1) - 1));
|
|
// pantographs
|
|
/*
|
|
if( mvOccupied->PantSwitchType != "impulse" ) {
|
|
if( ggPantFrontButton.SubModel ) {
|
|
ggPantFrontButton.PutValue(
|
|
( mvControlled->Pantographs[end::front].valve.is_enabled ?
|
|
1.f :
|
|
0.f ) );
|
|
}
|
|
if( ggPantFrontButtonOff.SubModel ) {
|
|
ggPantFrontButtonOff.PutValue(
|
|
( mvControlled->Pantographs[end::front].valve.is_disabled ?
|
|
1.f :
|
|
0.f ) );
|
|
}
|
|
}
|
|
if( mvOccupied->PantSwitchType != "impulse" ) {
|
|
if( ggPantRearButton.SubModel ) {
|
|
ggPantRearButton.PutValue(
|
|
( mvControlled->Pantographs[end::rear].valve.is_enabled ?
|
|
1.f :
|
|
0.f ) );
|
|
}
|
|
if( ggPantRearButtonOff.SubModel ) {
|
|
ggPantRearButtonOff.PutValue(
|
|
( mvControlled->Pantographs[end::rear].valve.is_disabled ?
|
|
1.f :
|
|
0.f ) );
|
|
}
|
|
}
|
|
*/
|
|
// front/end pantograph selection is relative to occupied cab
|
|
if (ggPantSelectedButton.type() == TGaugeType::toggle)
|
|
{
|
|
ggPantSelectedButton.PutValue(mvPantographUnit->PantsValve.is_enabled ? 1.f : 0.f);
|
|
}
|
|
else
|
|
{
|
|
if (false == m_controlmapper.contains("pantselectedoff_sw:"))
|
|
{
|
|
// single impulse switch arrangement, with neutral position mid-way
|
|
ggPantSelectedButton.PutValue(0.5f);
|
|
}
|
|
}
|
|
if (ggPantSelectedDownButton.type() == TGaugeType::toggle)
|
|
{
|
|
ggPantSelectedDownButton.PutValue(mvPantographUnit->PantsValve.is_disabled ? 1.f : 0.f);
|
|
}
|
|
|
|
ggPantValvesButton.PutValue(0.5f);
|
|
|
|
// auxiliary compressor
|
|
ggPantCompressorValve.PutValue(mvControlled->bPantKurek3 ? 0.f : // default setting is pantographs connected with primary tank
|
|
1.f);
|
|
ggPantCompressorButton.PutValue(mvPantographUnit->PantCompFlag ? 1.f : 0.f);
|
|
// converter
|
|
if (mvOccupied->ConvSwitchType != "impulse")
|
|
{
|
|
ggConverterButton.PutValue(mvControlled->ConverterAllow ? 1.f : 0.f);
|
|
}
|
|
ggConverterLocalButton.PutValue(mvControlled->ConverterAllowLocal ? 1.f : 0.f);
|
|
// compressor
|
|
ggCompressorButton.PutValue(mvControlled->CompressorAllow ? 1.f : 0.f);
|
|
ggCompressorLocalButton.PutValue(mvControlled->CompressorAllowLocal ? 1.f : 0.f);
|
|
ggCompressorListButton.PutValue(static_cast<float>(mvOccupied->CompressorListPos - 1));
|
|
// motor overload relay threshold / shunt mode
|
|
ggMaxCurrentCtrl.PutValue(true == mvControlled->ShuntModeAllow ? (true == mvControlled->ShuntMode ? 1.f : 0.f) : mvControlled->MotorOverloadRelayHighThreshold ? 1.f : 0.f);
|
|
// lights
|
|
ggLightsButton.PutValue(static_cast<float>(mvOccupied->LightsPos - 1));
|
|
|
|
auto const vehicleend{cab_to_end(Cab)};
|
|
|
|
if ((mvOccupied->iLights[vehicleend] & light::headlight_left) != 0)
|
|
{
|
|
ggLeftLightButton.PutValue(1.f);
|
|
}
|
|
if ((mvOccupied->iLights[vehicleend] & light::headlight_right) != 0)
|
|
{
|
|
ggRightLightButton.PutValue(1.f);
|
|
}
|
|
if ((mvOccupied->iLights[vehicleend] & light::headlight_upper) != 0)
|
|
{
|
|
ggUpperLightButton.PutValue(1.f);
|
|
}
|
|
if ((mvOccupied->iLights[vehicleend] & light::redmarker_left) != 0)
|
|
{
|
|
if (ggLeftEndLightButton.SubModel != nullptr)
|
|
{
|
|
ggLeftEndLightButton.PutValue(1.f);
|
|
}
|
|
else
|
|
{
|
|
ggLeftLightButton.PutValue(-1.f);
|
|
}
|
|
}
|
|
if ((mvOccupied->iLights[vehicleend] & light::redmarker_right) != 0)
|
|
{
|
|
if (ggRightEndLightButton.SubModel != nullptr)
|
|
{
|
|
ggRightEndLightButton.PutValue(1.f);
|
|
}
|
|
else
|
|
{
|
|
ggRightLightButton.PutValue(-1.f);
|
|
}
|
|
}
|
|
if (1 == DynamicObject->MoverParameters->modernDimmerPosition)
|
|
{
|
|
ggDimHeadlightsButton.PutValue(static_cast<float>(DynamicObject->MoverParameters->modernDimmerPosition));
|
|
}
|
|
// cab lights
|
|
if (true == Cabine[Cab].bLightDim)
|
|
{
|
|
ggCabLightDimButton.PutValue(1.f);
|
|
}
|
|
// compartment lights
|
|
ggCompartmentLightsButton.PutValue(ggCompartmentLightsButton.type() == TGaugeType::push ? 0.5f : mvOccupied->CompartmentLights.is_enabled ? 1.f : 0.f);
|
|
// instrument lights
|
|
ggInstrumentLightButton.PutValue(InstrumentLightActive ? 1.f : 0.f);
|
|
ggDashboardLightButton.PutValue(DashboardLightActive ? 1.f : 0.f);
|
|
ggTimetableLightButton.PutValue(TimetableLightActive ? 1.f : 0.f);
|
|
// doors permits
|
|
if (false == ggDoorLeftPermitButton.is_push())
|
|
{
|
|
ggDoorLeftPermitButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == end::front ? side::left : side::right].open_permit ? 1.f : 0.f);
|
|
}
|
|
if (false == ggDoorRightPermitButton.is_push())
|
|
{
|
|
ggDoorRightPermitButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == end::front ? side::right : side::left].open_permit ? 1.f : 0.f);
|
|
}
|
|
ggDoorPermitPresetButton.PutValue(static_cast<float>(mvOccupied->Doors.permit_preset));
|
|
// door controls
|
|
ggDoorLeftButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == end::front ? side::left : side::right].is_closed ? 0.f : 1.f);
|
|
ggDoorRightButton.PutValue(mvOccupied->Doors.instances[cab_to_end() == end::front ? side::right : side::left].is_closed ? 0.f : 1.f);
|
|
// door lock
|
|
ggDoorSignallingButton.PutValue(mvOccupied->Doors.lock_enabled ? 1.f : 0.f);
|
|
// door step
|
|
if (false == ggDoorStepButton.is_push())
|
|
{
|
|
ggDoorStepButton.PutValue(mvOccupied->Doors.step_enabled ? 1.f : 0.f);
|
|
}
|
|
// heating
|
|
if (false == ggTrainHeatingButton.is_push() && false == mvOccupied->HeatingSwitchImpulse)
|
|
{
|
|
ggTrainHeatingButton.PutValue(mvControlled->Heating ? 1.f : 0.f);
|
|
}
|
|
// brake acting time
|
|
if (ggBrakeProfileCtrl.SubModel != nullptr)
|
|
{
|
|
ggBrakeProfileCtrl.PutValue((mvOccupied->BrakeDelayFlag & bdelay_R) != 0 ? 2.f : static_cast<float>(mvOccupied->BrakeDelayFlag - 1));
|
|
}
|
|
if (ggBrakeProfileG.SubModel != nullptr)
|
|
{
|
|
ggBrakeProfileG.PutValue(mvOccupied->BrakeDelayFlag == bdelay_G ? 1.f : 0.f);
|
|
}
|
|
if (ggBrakeProfileR.SubModel != nullptr)
|
|
{
|
|
ggBrakeProfileR.PutValue((mvOccupied->BrakeDelayFlag & bdelay_R) != 0 ? 1.f : 0.f);
|
|
}
|
|
|
|
if (ggWiperSw.SubModel != nullptr)
|
|
{
|
|
ggWiperSw.PutValue(static_cast<float>(mvOccupied->wiperSwitchPos));
|
|
}
|
|
|
|
if (ggBrakeOperationModeCtrl.SubModel != nullptr)
|
|
{
|
|
ggBrakeOperationModeCtrl.PutValue(mvOccupied->BrakeOpModeFlag > 0 ? static_cast<float>(std::log2(mvOccupied->BrakeOpModeFlag)) : 0);
|
|
}
|
|
// alarm chain
|
|
ggAlarmChain.PutValue(mvControlled->AlarmChainFlag ? 1.f : 0.f);
|
|
// brake signalling
|
|
ggSignallingButton.PutValue(mvControlled->Signalling ? 1.f : 0.f);
|
|
// multiple-unit current indicator source
|
|
ggNextCurrentButton.PutValue(ShowNextCurrent ? 1.f : 0.f);
|
|
// water pump
|
|
ggWaterPumpBreakerButton.PutValue(mvControlled->WaterPump.breaker ? 1.f : 0.f);
|
|
if (ggWaterPumpButton.type() != TGaugeType::push)
|
|
{
|
|
ggWaterPumpButton.PutValue(mvControlled->WaterPump.is_enabled ? 1.f : 0.f);
|
|
}
|
|
// water heater
|
|
ggWaterHeaterBreakerButton.PutValue(mvControlled->WaterHeater.breaker ? 1.f : 0.f);
|
|
ggWaterHeaterButton.PutValue(mvControlled->WaterHeater.is_enabled ? 1.f : 0.f);
|
|
ggWaterCircuitsLinkButton.PutValue(mvControlled->WaterCircuitsLink ? 1.f : 0.f);
|
|
// fuel pump
|
|
if (ggFuelPumpButton.type() != TGaugeType::push)
|
|
{
|
|
ggFuelPumpButton.PutValue(mvControlled->FuelPump.is_enabled ? 1.f : 0.f);
|
|
}
|
|
// oil pump
|
|
if (ggOilPumpButton.type() != TGaugeType::push)
|
|
{
|
|
ggOilPumpButton.PutValue(mvControlled->OilPump.is_enabled ? 1.f : 0.f);
|
|
}
|
|
// joint oil and fuel pump
|
|
if (ggOilFuelPumpButton.type() != TGaugeType::push)
|
|
{
|
|
ggOilFuelPumpButton.PutValue(mvControlled->OilFuelPumpsEnabled() ? 1.f : 0.f);
|
|
}
|
|
// traction motor fans
|
|
if (ggMotorBlowersFrontButton.type() != TGaugeType::push)
|
|
{
|
|
ggMotorBlowersFrontButton.PutValue(mvControlled->MotorBlowers[end::front].is_enabled ? 1.f : 0.f);
|
|
}
|
|
if (ggMotorBlowersRearButton.type() != TGaugeType::push)
|
|
{
|
|
ggMotorBlowersRearButton.PutValue(mvControlled->MotorBlowers[end::rear].is_enabled ? 1.f : 0.f);
|
|
}
|
|
if (ggMotorBlowersAllOffButton.type() != TGaugeType::push)
|
|
{
|
|
ggMotorBlowersAllOffButton.PutValue(mvControlled->MotorBlowers[end::front].is_disabled || mvControlled->MotorBlowers[end::rear].is_disabled ? 1.f : 0.f);
|
|
}
|
|
// second controller
|
|
if (ggScndCtrl.is_push())
|
|
{
|
|
ggScndCtrl.PutValue(ggScndCtrl.is_toggle() ? 0.5f : // pushtoggle is two-way control with neutral position in the middle
|
|
0.f); // push is on/off control, active while held down, due to legacy use
|
|
}
|
|
// tempomat
|
|
if (false == ggScndCtrlButton.is_push())
|
|
{
|
|
ggScndCtrlButton.PutValue(mvControlled->IsSpeedCtrlEngaged() ? 1.f : 0.f);
|
|
}
|
|
// sandbox
|
|
if (ggAutoSandButton.type() != TGaugeType::push)
|
|
{
|
|
ggAutoSandButton.PutValue(mvControlled->SandDoseAutoAllow ? 1.f : 0.f);
|
|
}
|
|
// radio
|
|
ggRadioVolumeSelector.PutValue(m_radiovolume);
|
|
|
|
// finding each inverter - not so optimal, but action ins performed only during changing cabin
|
|
bool kier = DynamicObject->DirectionGet() * mvOccupied->CabOccupied > 0;
|
|
int flag = DynamicObject->MoverParameters->InverterControlCouplerFlag;
|
|
int itemstart = 0;
|
|
for ([[maybe_unused]] auto const &item : ggInverterToggleButtons) // for each button
|
|
{
|
|
int itemindex = itemstart;
|
|
itemstart++;
|
|
TDynamicObject *p = DynamicObject->GetFirstDynamic(mvOccupied->CabOccupied < 0 ? end::rear : end::front, flag);
|
|
while (p)
|
|
{
|
|
if (p->MoverParameters->eimc[eimc_p_Pmax] > 1)
|
|
{
|
|
if (itemindex < p->MoverParameters->InvertersNo)
|
|
{
|
|
// visual feedback
|
|
ggInverterToggleButtons[itemstart - 1].PutValue(p->MoverParameters->Inverters[itemindex].Activate ? 1.0 : 0.0);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
itemindex -= p->MoverParameters->InvertersNo;
|
|
}
|
|
}
|
|
p = kier ? p->Next(flag) : p->Prev(flag);
|
|
}
|
|
}
|
|
|
|
// we reset all indicators, as they're set during the update pass
|
|
// TODO: when cleaning up break setting indicator state into a separate function, so we can reuse it
|
|
}
|
|
|
|
// initializes a button matching provided label. returns: true if the label was found, false otherwise
|
|
// TODO: refactor the cabin controls into some sensible structure
|
|
bool TTrain::initialize_button(cParser &Parser, std::string const &Label, int const Cabindex)
|
|
{
|
|
|
|
std::unordered_map<std::string, TButton &> const lights = {
|
|
{"i-maxft:", btLampkaMaxSila},
|
|
{"i-maxftt:", btLampkaPrzekrMaxSila},
|
|
{"i-radio:", btLampkaRadio},
|
|
{"i-radiomessage:", btLampkaRadioMessage},
|
|
{"i-radiostop:", btLampkaRadioStop},
|
|
{"i-manual_brake:", btLampkaHamulecReczny},
|
|
{"i-door_blocked:", btLampkaBlokadaDrzwi},
|
|
{"i-door_blockedoff:", btLampkaDoorLockOff},
|
|
{"i-slippery:", btLampkaPoslizg},
|
|
{"i-contactors:", btLampkaStyczn},
|
|
{"i-conv_ovld:", btLampkaNadmPrzetw},
|
|
{"i-converter:", btLampkaPrzetw},
|
|
{"i-converteroff:", btLampkaPrzetwOff},
|
|
{"i-converteraoff:", btLampkaPrzetwAOff},
|
|
{"i-converterb:", btLampkaPrzetwB},
|
|
{"i-converterboff:", btLampkaPrzetwBOff},
|
|
{"i-diff_relay:", btLampkaPrzekRozn},
|
|
{"i-diff_relay2:", btLampkaPrzekRoznPom},
|
|
{"i-motor_ovld:", btLampkaNadmSil},
|
|
{"i-train_controll:", btLampkaUkrotnienie},
|
|
{"i-brake_delay_r:", btLampkaHamPosp},
|
|
{"i-mainbreaker:", btLampkaWylSzybki},
|
|
{"i-mainbreakerb:", btLampkaWylSzybkiB},
|
|
{"i-mainbreakeroff:", btLampkaWylSzybkiOff},
|
|
{"i-mainbreakerboff:", btLampkaWylSzybkiBOff},
|
|
{"i-mainbreakerready:", btLampkaMainBreakerReady},
|
|
{"i-mainbreakerblinking:", btLampkaMainBreakerBlinkingIfReady},
|
|
{"i-vent_ovld:", btLampkaNadmWent},
|
|
{"i-comp_ovld:", btLampkaNadmSpr},
|
|
// overheat indicator lamps
|
|
{"i-oil_overheat:", btLampkaOilOverheat},
|
|
{"i-water_overheat:", btLampkaWaterOverheat},
|
|
{"i-wateraux_overheat:", btLampkaWaterAuxOverheat},
|
|
{"i-engine_overheat:", btLampkaEngineOverheat},
|
|
{"i-resistors:", btLampkaOpory},
|
|
{"i-no_resistors:", btLampkaBezoporowa},
|
|
{"i-no_resistors_b:", btLampkaBezoporowaB},
|
|
{"i-highcurrent:", btLampkaWysRozr},
|
|
{"i-vent_trim:", btLampkaWentZaluzje},
|
|
{"i-motorblowers:", btLampkaMotorBlowers},
|
|
{"i-coolingfans:", btLampkaCoolingFans},
|
|
{"i-louvresclosed:", btLampkaLouvresClosed},
|
|
{"i-tempomat:", btLampkaTempomat},
|
|
{"i-distancecounter:", btLampkaDistanceCounter},
|
|
{"i-trainheating:", btLampkaOgrzewanieSkladu},
|
|
{"i-security_aware:", btLampkaCzuwaka},
|
|
{"i-security_cabsignal:", btLampkaSHP},
|
|
{"i-security_aware_cabsignal:", btLampkaCzuwakaSHP},
|
|
{"i-door_left:", btLampkaDoorLeft},
|
|
{"i-door_right:", btLampkaDoorRight},
|
|
{"i-departure_signal:", btLampkaDepartureSignal},
|
|
{"i-reserve:", btLampkaRezerwa},
|
|
{"i-scnd:", btLampkaBoczniki},
|
|
{"i-scnd1:", btLampkaBocznik1},
|
|
{"i-scnd2:", btLampkaBocznik2},
|
|
{"i-scnd3:", btLampkaBocznik3},
|
|
{"i-scnd4:", btLampkaBocznik4},
|
|
{"i-gear1:", btLampkaGear1},
|
|
{"i-gear2:", btLampkaGear2},
|
|
{"i-hydrolockup:", btLampkaHydroLockup},
|
|
{"i-braking:", btLampkaHamienie},
|
|
{"i-brakingoff:", btLampkaBrakingOff},
|
|
{"i-dynamicbrake:", btLampkaED},
|
|
{"i-brakeprofileg:", btLampkaBrakeProfileG},
|
|
{"i-brakeprofilep:", btLampkaBrakeProfileP},
|
|
{"i-brakeprofiler:", btLampkaBrakeProfileR},
|
|
{"i-springbrakeactive:", btLampkaSpringBrakeActive},
|
|
{"i-springbrakeinactive:", btLampkaSpringBrakeInactive},
|
|
{"i-braking-ezt:", btLampkaHamowanie1zes},
|
|
{"i-braking-ezt2:", btLampkaHamowanie2zes},
|
|
{"i-compressor:", btLampkaSprezarka},
|
|
{"i-compressorb:", btLampkaSprezarkaB},
|
|
{"i-compressoroff:", btLampkaSprezarkaOff},
|
|
{"i-compressorboff:", btLampkaSprezarkaBOff},
|
|
{"i-fuelpumpoff:", btLampkaFuelPumpOff},
|
|
{"i-oilpump:", btLampkaOilPump},
|
|
{"i-voltbrake:", btLampkaNapNastHam},
|
|
{"i-resistorsb:", btLampkaOporyB},
|
|
{"i-contactorsb:", btLampkaStycznB},
|
|
{"i-conv_ovldb:", btLampkaNadmPrzetwB},
|
|
{"i-hvoltageb:", btLampkaHVoltageB},
|
|
{"i-malfunction:", btLampkaMalfunction},
|
|
{"i-malfunctionb:", btLampkaMalfunctionB},
|
|
{"i-forward:", btLampkaForward},
|
|
{"i-backward:", btLampkaBackward},
|
|
{"i-neutral:", btLampkaNeutral},
|
|
{"i-upperlight:", btLampkaUpperLight},
|
|
{"i-leftlight:", btLampkaLeftLight},
|
|
{"i-rightlight:", btLampkaRightLight},
|
|
{"i-leftend:", btLampkaLeftEndLight},
|
|
{"i-rightend:", btLampkaRightEndLight},
|
|
{"i-rearupperlight:", btLampkaRearUpperLight},
|
|
{"i-rearleftlight:", btLampkaRearLeftLight},
|
|
{"i-rearrightlight:", btLampkaRearRightLight},
|
|
{"i-rearleftend:", btLampkaRearLeftEndLight},
|
|
{"i-rearrightend:", btLampkaRearRightEndLight},
|
|
{"i-dashboardlight:", btDashboardLight},
|
|
{"i-timetablelight:", btTimetableLight},
|
|
{"i-universal0:", btUniversals[0]},
|
|
{"i-universal1:", btUniversals[1]},
|
|
{"i-universal2:", btUniversals[2]},
|
|
{"i-universal3:", btUniversals[3]},
|
|
{"i-universal4:", btUniversals[4]},
|
|
{"i-universal5:", btUniversals[5]},
|
|
{"i-universal6:", btUniversals[6]},
|
|
{"i-universal7:", btUniversals[7]},
|
|
{"i-universal8:", btUniversals[8]},
|
|
{"i-universal9:", btUniversals[9]},
|
|
{"i-cabactived:", btCabActived},
|
|
{"i-aklvents:", btAKLVents},
|
|
{"i-compressorany:", btCompressors},
|
|
{"i-edenabled", btEDenabled},
|
|
};
|
|
{
|
|
auto lookup = lights.find(Label);
|
|
if (lookup != lights.end())
|
|
{
|
|
lookup->second.Load(Parser, DynamicObject);
|
|
return true;
|
|
}
|
|
}
|
|
// TODO: move viable dedicated lights to the automatic light array
|
|
std::unordered_map<std::string, bool const *> const autolights = {
|
|
{"i-doors:", &m_doors},
|
|
{"i-doorpermit_left:", &m_doorspermitleft},
|
|
{"i-doorpermit_right:", &m_doorspermitright},
|
|
{"i-doorpermit_any:", &m_doorpermits},
|
|
{"i-doorstep:", &mvOccupied->Doors.step_enabled},
|
|
{"i-mainpipelock:", &mvOccupied->LockPipe},
|
|
{"i-battery:", &mvOccupied->Power24vIsAvailable},
|
|
{"i-cablight:", &Cabine[iCabn].bLight},
|
|
{"i-compartmentlights:", &mvOccupied->CompartmentLights.is_active},
|
|
};
|
|
{
|
|
auto lookup = autolights.find(Label);
|
|
if (lookup != autolights.end())
|
|
{
|
|
auto &button = Cabine[Cabindex].Button(-1); // pierwsza wolna lampka
|
|
button.Load(Parser, DynamicObject);
|
|
button.AssignBool(lookup->second);
|
|
return true;
|
|
}
|
|
}
|
|
// custom lights
|
|
if (Label == "i-instrumentlight:")
|
|
{
|
|
btInstrumentLight.Load(Parser, DynamicObject);
|
|
InstrumentLightType = 0;
|
|
}
|
|
else if (Label == "i-instrumentlight_m:")
|
|
{
|
|
btInstrumentLight.Load(Parser, DynamicObject);
|
|
InstrumentLightType = 1;
|
|
}
|
|
else if (Label == "i-instrumentlight_c:")
|
|
{
|
|
btInstrumentLight.Load(Parser, DynamicObject);
|
|
InstrumentLightType = 2;
|
|
}
|
|
else if (Label == "i-instrumentlight_a:")
|
|
{
|
|
btInstrumentLight.Load(Parser, DynamicObject);
|
|
InstrumentLightType = 3;
|
|
}
|
|
else if (Label == "i-instrumentlight_l:")
|
|
{
|
|
btInstrumentLight.Load(Parser, DynamicObject);
|
|
InstrumentLightType = 4;
|
|
}
|
|
else if (Label == "i-doors:")
|
|
{
|
|
int i = Parser.getToken<int>() - 1;
|
|
auto &button = Cabine[Cabindex].Button(-1); // pierwsza wolna lampka
|
|
button.Load(Parser, DynamicObject);
|
|
button.AssignBool(bDoors[0] + 3 * i);
|
|
}
|
|
else
|
|
{
|
|
// failed to match the label
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// initializes a gauge matching provided label. returns: true if the label was found, false otherwise
|
|
// TODO: refactor the cabin controls into some sensible structure
|
|
bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int const Cabindex)
|
|
{
|
|
|
|
std::unordered_map<std::string, TGauge &> const gauges = {{"jointctrl:", ggJointCtrl},
|
|
{"mainctrl:", ggMainCtrl},
|
|
{"scndctrl:", ggScndCtrl},
|
|
{"dirkey:", ggDirKey},
|
|
{"brakectrl:", ggBrakeCtrl},
|
|
{"localbrake:", ggLocalBrake},
|
|
{"alarmchain:", ggAlarmChain},
|
|
{"brakeprofile_sw:", ggBrakeProfileCtrl},
|
|
{"brakeprofileg_sw:", ggBrakeProfileG},
|
|
{"brakeprofiler_sw:", ggBrakeProfileR},
|
|
{"brakeopmode_sw:", ggBrakeOperationModeCtrl},
|
|
{"maxcurrent_sw:", ggMaxCurrentCtrl},
|
|
{"main_off_bt:", ggMainOffButton},
|
|
{"main_on_bt:", ggMainOnButton},
|
|
{"mainb_sw:", m_remotelinebreakers[0].main_switch},
|
|
{"mainb_off_bt:", m_remotelinebreakers[0].off_button},
|
|
{"mainb_on_bt:", m_remotelinebreakers[0].on_button},
|
|
{"mainc_sw:", m_remotelinebreakers[1].main_switch},
|
|
{"mainc_off_bt:", m_remotelinebreakers[1].off_button},
|
|
{"mainc_on_bt:", m_remotelinebreakers[1].on_button},
|
|
{"security_reset_bt:", ggSecurityResetButton},
|
|
{"shp_reset_bt:", ggSHPResetButton},
|
|
{"releaser_bt:", ggReleaserButton},
|
|
{"springbrakeon_bt:", ggSpringBrakeOnButton},
|
|
{"springbrakeoff_bt:", ggSpringBrakeOffButton},
|
|
{"universalbrake1_bt:", ggUniveralBrakeButton1},
|
|
{"universalbrake2_bt:", ggUniveralBrakeButton2},
|
|
{"universalbrake3_bt:", ggUniveralBrakeButton3},
|
|
{"epbrake_bt:", ggEPFuseButton},
|
|
{"sand_bt:", ggSandButton},
|
|
{"autosandallow_sw:", ggAutoSandButton},
|
|
{"antislip_bt:", ggAntiSlipButton},
|
|
{"horn_bt:", ggHornButton},
|
|
{"hornlow_bt:", ggHornLowButton},
|
|
{"hornhigh_bt:", ggHornHighButton},
|
|
{"whistle_bt:", ggWhistleButton},
|
|
{"helper_bt:", ggHelperButton},
|
|
{"fuse_bt:", ggFuseButton},
|
|
{"converterfuse_bt:", ggConverterFuseButton},
|
|
{"stlinoff_bt:", ggStLinOffButton},
|
|
{"doorpermitpreset_sw:", ggDoorPermitPresetButton},
|
|
{"door_left_sw:", ggDoorLeftButton},
|
|
{"door_right_sw:", ggDoorRightButton},
|
|
{"doorlefton_sw:", ggDoorLeftOnButton},
|
|
{"doorrighton_sw:", ggDoorRightOnButton},
|
|
{"doorleftoff_sw:", ggDoorLeftOffButton},
|
|
{"doorrightoff_sw:", ggDoorRightOffButton},
|
|
{"doorallon_sw:", ggDoorAllOnButton},
|
|
{"departure_signal_bt:", ggDepartureSignalButton},
|
|
{"upperlight_sw:", ggUpperLightButton},
|
|
{"leftlight_sw:", ggLeftLightButton},
|
|
{"rightlight_sw:", ggRightLightButton},
|
|
{"dimheadlights_sw:", ggDimHeadlightsButton},
|
|
{"leftend_sw:", ggLeftEndLightButton},
|
|
{"rightend_sw:", ggRightEndLightButton},
|
|
{"lights_sw:", ggLightsButton},
|
|
{"moderndimmer_sw:", ggModernLightDimSw},
|
|
{"rearupperlight_sw:", ggRearUpperLightButton},
|
|
{"rearleftlight_sw:", ggRearLeftLightButton},
|
|
{"rearrightlight_sw:", ggRearRightLightButton},
|
|
{"rearleftend_sw:", ggRearLeftEndLightButton},
|
|
{"rearrightend_sw:", ggRearRightEndLightButton},
|
|
{"compressor_sw:", ggCompressorButton},
|
|
{"compressorlocal_sw:", ggCompressorLocalButton},
|
|
{"compressorlist_sw:", ggCompressorListButton},
|
|
{"converter_sw:", ggConverterButton},
|
|
{"converterlocal_sw:", ggConverterLocalButton},
|
|
{"converteroff_sw:", ggConverterOffButton},
|
|
{"main_sw:", ggMainButton},
|
|
{"waterpumpbreaker_sw:", ggWaterPumpBreakerButton},
|
|
{"waterpump_sw:", ggWaterPumpButton},
|
|
{"waterheaterbreaker_sw:", ggWaterHeaterBreakerButton},
|
|
{"waterheater_sw:", ggWaterHeaterButton},
|
|
{"water1tempb:", ggWater1TempB},
|
|
{"watercircuitslink_sw:", ggWaterCircuitsLinkButton},
|
|
{"fuelpump_sw:", ggFuelPumpButton},
|
|
{"oilpump_sw:", ggOilPumpButton},
|
|
{"oilfuelpump_sw:", ggOilFuelPumpButton},
|
|
{"oilpressb:", ggOilPressB},
|
|
{"motorblowersfront_sw:", ggMotorBlowersFrontButton},
|
|
{"motorblowersrear_sw:", ggMotorBlowersRearButton},
|
|
{"motorblowersalloff_sw:", ggMotorBlowersAllOffButton},
|
|
{"radiochannel_sw:", ggRadioChannelSelector},
|
|
{"radiochannelprev_sw:", ggRadioChannelPrevious},
|
|
{"radiochannelnext_sw:", ggRadioChannelNext},
|
|
{"radiostop_sw:", ggRadioStop},
|
|
{"radiotest_sw:", ggRadioTest},
|
|
{"radiocall1_sw:", ggRadioCall1},
|
|
{"radiocall3_sw:", ggRadioCall3},
|
|
{"radiovolume_sw:", ggRadioVolumeSelector},
|
|
{"radiovolumeprev_sw:", ggRadioVolumePrevious},
|
|
{"radiovolumenext_sw:", ggRadioVolumeNext},
|
|
{"radioon_sw:", ggRadioOnButton},
|
|
{"radiooff_sw:", ggRadioOffButton},
|
|
{"radiofuseon_sw:", ggRadioFuseOnButton},
|
|
{"radiofuseoff_sw:", ggRadioFuseOffButton},
|
|
/*
|
|
{ "pantfront_sw:", ggPantFrontButton },
|
|
{ "pantrear_sw:", ggPantRearButton },
|
|
{ "pantfrontoff_sw:", ggPantFrontButtonOff },
|
|
{ "pantrearoff_sw:", ggPantRearButtonOff },
|
|
*/
|
|
{"pantalloff_sw:", ggPantAllDownButton},
|
|
{"pantselected_sw:", ggPantSelectedButton},
|
|
{"pantselectedoff_sw:", ggPantSelectedDownButton},
|
|
{"pantvalves_sw:", ggPantValvesButton},
|
|
{"pantcompressor_sw:", ggPantCompressorButton},
|
|
{"pantcompressorvalve_sw:", ggPantCompressorValve},
|
|
{"trainheating_sw:", ggTrainHeatingButton},
|
|
{"signalling_sw:", ggSignallingButton},
|
|
{"door_signalling_sw:", ggDoorSignallingButton},
|
|
{"nextcurrent_sw:", ggNextCurrentButton},
|
|
{"instrumentlight_sw:", ggInstrumentLightButton},
|
|
{"dashboardlight_sw:", ggDashboardLightButton},
|
|
{"timetablelight_sw:", ggTimetableLightButton},
|
|
{"cablightdim_sw:", ggCabLightDimButton},
|
|
{"compartmentlights_sw:", ggCompartmentLightsButton},
|
|
{"compartmentlightson_sw:", ggCompartmentLightsOnButton},
|
|
{"compartmentlightsoff_sw:", ggCompartmentLightsOffButton},
|
|
{"battery_sw:", ggBatteryButton},
|
|
{"batteryon_sw:", ggBatteryOnButton},
|
|
{"batteryoff_sw:", ggBatteryOffButton},
|
|
{"cabactivation_sw:", ggCabActivationButton},
|
|
{"distancecounter_sw:", ggDistanceCounterButton},
|
|
{"relayreset1_bt:", ggRelayResetButtons[0]},
|
|
{"relayreset2_bt:", ggRelayResetButtons[1]},
|
|
{"relayreset3_bt:", ggRelayResetButtons[2]},
|
|
{"universal0:", ggUniversals[0]},
|
|
{"universal1:", ggUniversals[1]},
|
|
{"universal2:", ggUniversals[2]},
|
|
{"universal3:", ggUniversals[3]},
|
|
{"universal4:", ggUniversals[4]},
|
|
{"universal5:", ggUniversals[5]},
|
|
{"universal6:", ggUniversals[6]},
|
|
{"universal7:", ggUniversals[7]},
|
|
{"universal8:", ggUniversals[8]},
|
|
{"universal9:", ggUniversals[9]},
|
|
{"universal10:", ggUniversals[10]},
|
|
{"universal11:", ggUniversals[11]},
|
|
{"universal12:", ggUniversals[12]},
|
|
{"universal13:", ggUniversals[13]},
|
|
{"universal14:", ggUniversals[14]},
|
|
{"universal15:", ggUniversals[15]},
|
|
{"universal16:", ggUniversals[16]},
|
|
{"universal17:", ggUniversals[17]},
|
|
{"universal18:", ggUniversals[18]},
|
|
{"universal19:", ggUniversals[19]},
|
|
{"universal20:", ggUniversals[20]},
|
|
{"universal21:", ggUniversals[21]},
|
|
{"universal22:", ggUniversals[22]},
|
|
{"universal23:", ggUniversals[23]},
|
|
{"universal24:", ggUniversals[24]},
|
|
{"universal25:", ggUniversals[25]},
|
|
{"universal26:", ggUniversals[26]},
|
|
{"universal27:", ggUniversals[27]},
|
|
{"universal28:", ggUniversals[28]},
|
|
{"universal29:", ggUniversals[29]},
|
|
{"inverterenable1_bt:", ggInverterEnableButtons[0]},
|
|
{"inverterenable2_bt:", ggInverterEnableButtons[1]},
|
|
{"inverterenable3_bt:", ggInverterEnableButtons[2]},
|
|
{"inverterenable4_bt:", ggInverterEnableButtons[3]},
|
|
{"inverterenable5_bt:", ggInverterEnableButtons[4]},
|
|
{"inverterenable6_bt:", ggInverterEnableButtons[5]},
|
|
{"inverterenable7_bt:", ggInverterEnableButtons[6]},
|
|
{"inverterenable8_bt:", ggInverterEnableButtons[7]},
|
|
{"inverterenable9_bt:", ggInverterEnableButtons[8]},
|
|
{"inverterenable10_bt:", ggInverterEnableButtons[9]},
|
|
{"inverterenable11_bt:", ggInverterEnableButtons[10]},
|
|
{"inverterenable12_bt:", ggInverterEnableButtons[11]},
|
|
{"inverterdisable1_bt:", ggInverterDisableButtons[0]},
|
|
{"inverterdisable2_bt:", ggInverterDisableButtons[1]},
|
|
{"inverterdisable3_bt:", ggInverterDisableButtons[2]},
|
|
{"inverterdisable4_bt:", ggInverterDisableButtons[3]},
|
|
{"inverterdisable5_bt:", ggInverterDisableButtons[4]},
|
|
{"inverterdisable6_bt:", ggInverterDisableButtons[5]},
|
|
{"inverterdisable7_bt:", ggInverterDisableButtons[6]},
|
|
{"inverterdisable8_bt:", ggInverterDisableButtons[7]},
|
|
{"inverterdisable9_bt:", ggInverterDisableButtons[8]},
|
|
{"inverterdisable10_bt:", ggInverterDisableButtons[9]},
|
|
{"inverterdisable11_bt:", ggInverterDisableButtons[10]},
|
|
{"inverterdisable12_bt:", ggInverterDisableButtons[11]},
|
|
{"invertertoggle1_bt:", ggInverterToggleButtons[0]},
|
|
{"invertertoggle2_bt:", ggInverterToggleButtons[1]},
|
|
{"invertertoggle3_bt:", ggInverterToggleButtons[2]},
|
|
{"invertertoggle4_bt:", ggInverterToggleButtons[3]},
|
|
{"invertertoggle5_bt:", ggInverterToggleButtons[4]},
|
|
{"invertertoggle6_bt:", ggInverterToggleButtons[5]},
|
|
{"invertertoggle7_bt:", ggInverterToggleButtons[6]},
|
|
{"invertertoggle8_bt:", ggInverterToggleButtons[7]},
|
|
{"invertertoggle9_bt:", ggInverterToggleButtons[8]},
|
|
{"invertertoggle10_bt:", ggInverterToggleButtons[9]},
|
|
{"invertertoggle11_bt:", ggInverterToggleButtons[10]},
|
|
{"invertertoggle12_bt:", ggInverterToggleButtons[11]},
|
|
{"pantvalvesupdate_bt:", ggPantValvesUpdate},
|
|
{"pantvalvesoff_bt:", ggPantValvesOff},
|
|
{"wipers_sw:", ggWiperSw}};
|
|
{
|
|
auto const lookup{gauges.find(Label)};
|
|
if (lookup != gauges.end())
|
|
{
|
|
lookup->second.Load(Parser, DynamicObject);
|
|
m_controlmapper.insert(lookup->second, lookup->first);
|
|
return true;
|
|
}
|
|
}
|
|
// dedicated gauges with state-driven optional submodel
|
|
// TODO: move viable gauges here
|
|
// TODO: convert dedicated gauges to auto-allocated ones, replace dedicated references in command handlers to mapper lookups
|
|
std::unordered_map<std::string, std::tuple<TGauge &, bool const *>> const stategauges = {
|
|
{"tempomat_sw:", {ggScndCtrlButton, &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"tempomatoff_sw:", {ggScndCtrlOffButton, &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedinc_bt:", {ggSpeedControlIncreaseButton, &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speeddec_bt:", {ggSpeedControlDecreaseButton, &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedctrlpowerinc_bt:", {ggSpeedControlPowerIncreaseButton, &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedctrlpowerdec_bt:", {ggSpeedControlPowerDecreaseButton, &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedbutton0:", {ggSpeedCtrlButtons[0], &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedbutton1:", {ggSpeedCtrlButtons[1], &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedbutton2:", {ggSpeedCtrlButtons[2], &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedbutton3:", {ggSpeedCtrlButtons[3], &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedbutton4:", {ggSpeedCtrlButtons[4], &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedbutton5:", {ggSpeedCtrlButtons[5], &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedbutton6:", {ggSpeedCtrlButtons[6], &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedbutton7:", {ggSpeedCtrlButtons[7], &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedbutton8:", {ggSpeedCtrlButtons[8], &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"speedbutton9:", {ggSpeedCtrlButtons[9], &mvOccupied->SpeedCtrlUnit.IsActive}},
|
|
{"doorleftpermit_sw:", {ggDoorLeftPermitButton, &m_doorspermitleft}},
|
|
{"doorrightpermit_sw:", {ggDoorRightPermitButton, &m_doorspermitright}},
|
|
{"dooralloff_sw:", {ggDoorAllOffButton, &m_doors}},
|
|
{"doorstep_sw:", {ggDoorStepButton, &mvOccupied->Doors.step_enabled}},
|
|
{"dirforward_bt:", {ggDirForwardButton, &m_dirforward}},
|
|
{"dirneutral_bt:", {ggDirNeutralButton, &m_dirneutral}},
|
|
{"dirbackward_bt:", {ggDirBackwardButton, &m_dirbackward}},
|
|
};
|
|
{
|
|
auto const lookup{stategauges.find(Label)};
|
|
if (lookup != stategauges.end())
|
|
{
|
|
auto &gauge{std::get<TGauge &>(lookup->second)};
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignState(std::get<bool const *>(lookup->second));
|
|
m_controlmapper.insert(gauge, lookup->first);
|
|
return true;
|
|
}
|
|
}
|
|
// TODO: move viable dedicated gauges to the automatic array
|
|
std::unordered_map<std::string, bool *> const autoboolgauges = {
|
|
{"doormode_sw:", &mvOccupied->Doors.remote_only},
|
|
{"coolingfans_sw:", &mvControlled->RVentForceOn},
|
|
{"pantfront_sw:", &mvPantographUnit->Pantographs[end::front].valve.is_enabled},
|
|
{"pantrear_sw:", &mvPantographUnit->Pantographs[end::rear].valve.is_enabled},
|
|
{"pantfrontoff_sw:", &mvPantographUnit->Pantographs[end::front].valve.is_disabled},
|
|
{"pantrearoff_sw:", &mvPantographUnit->Pantographs[end::rear].valve.is_disabled},
|
|
{"radio_sw:", &mvOccupied->Radio},
|
|
{"radiofuse_sw:", &mvOccupied->RadioFuse},
|
|
{"cablight_sw:", &Cabine[iCabn].bLight},
|
|
{"springbraketoggle_bt:", &mvOccupied->SpringBrake.Activate},
|
|
{"couplingdisconnect_sw:", &m_couplingdisconnect},
|
|
{"couplingdisconnectback_sw:", &m_couplingdisconnectback},
|
|
{"mirrors_sw:", &mvOccupied->MirrorForbidden},
|
|
};
|
|
{
|
|
auto lookup = autoboolgauges.find(Label);
|
|
if (lookup != autoboolgauges.end())
|
|
{
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna lampka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignBool(lookup->second);
|
|
m_controlmapper.insert(gauge, lookup->first);
|
|
return true;
|
|
}
|
|
}
|
|
// TODO: move viable dedicated gauges to the automatic array
|
|
std::unordered_map<std::string, int *> const autointgauges = {
|
|
{"manualbrake:", &mvOccupied->ManualBrakePos},
|
|
{"pantselect_sw:", &mvOccupied->PantsPreset.second[cab_to_end()]},
|
|
};
|
|
{
|
|
auto lookup = autointgauges.find(Label);
|
|
if (lookup != autointgauges.end())
|
|
{
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna lampka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignInt(lookup->second);
|
|
m_controlmapper.insert(gauge, lookup->first);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// ABu 090305: uniwersalne przyciski lub inne rzeczy
|
|
if (Label == "mainctrlact:")
|
|
{
|
|
ggMainCtrlAct.Load(Parser, DynamicObject);
|
|
}
|
|
// SEKCJA WSKAZNIKOW
|
|
else if (Label == "tachometer:" || Label == "tachometerb:")
|
|
{
|
|
// predkosciomierz wskaźnikowy z szarpaniem
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(&fTachoVelocityJump);
|
|
// bind tachometer sound location to the meter
|
|
if (dsbHasler && dsbHasler->offset() == glm::vec3())
|
|
{
|
|
dsbHasler->offset(gauge.model_offset());
|
|
}
|
|
}
|
|
else if (Label == "tachometern:")
|
|
{
|
|
// predkosciomierz wskaźnikowy bez szarpania
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(&fTachoVelocity);
|
|
// bind tachometer sound location to the meter
|
|
if (dsbHasler && dsbHasler->offset() == glm::vec3())
|
|
{
|
|
dsbHasler->offset(gauge.model_offset());
|
|
}
|
|
}
|
|
else if (Label == "tachometerd:")
|
|
{
|
|
// predkosciomierz cyfrowy
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(&fTachoVelocity);
|
|
// bind tachometer sound location to the meter
|
|
if (dsbHasler && dsbHasler->offset() == glm::vec3())
|
|
{
|
|
dsbHasler->offset(gauge.model_offset());
|
|
}
|
|
}
|
|
else if (Label == "hvcurrent1:" || Label == "hvcurrent1b:")
|
|
{
|
|
// 1szy amperomierz
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(fHCurrent + 1);
|
|
}
|
|
else if (Label == "hvcurrent2:" || Label == "hvcurrent2b:")
|
|
{
|
|
// 2gi amperomierz
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(fHCurrent + 2);
|
|
}
|
|
else if (Label == "hvcurrent3:" || Label == "hvcurrent3b:")
|
|
{
|
|
// 3ci amperomierz
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałska
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(fHCurrent + 3);
|
|
}
|
|
else if (Label == "hvcurrent:" || Label == "hvcurrentb:")
|
|
{
|
|
// amperomierz calkowitego pradu
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(fHCurrent);
|
|
}
|
|
else if (Label == "eimscreen:")
|
|
{
|
|
// amperomierz calkowitego pradu
|
|
int i;
|
|
int j;
|
|
Parser.getTokens(2, false);
|
|
Parser >> i >> j;
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(&fEIMParams[i][j]);
|
|
}
|
|
else if (Label == "brakes:")
|
|
{
|
|
// specified pipe pressure of specified consist vehicle
|
|
int i;
|
|
int j;
|
|
Parser.getTokens(2, false);
|
|
Parser >> i >> j;
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject, 0.1);
|
|
gauge.AssignFloat(&fPress[std::clamp(i, 1, 20) - 1][std::clamp(j, 0, 3)]);
|
|
}
|
|
else if (Label == "brakepress:" || Label == "brakepressb:")
|
|
{
|
|
// manometr cylindrow hamulcowych
|
|
// Ra 2014-08: przeniesione do TCab
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject, 0.1);
|
|
gauge.AssignDouble(&mvOccupied->BrakePress);
|
|
}
|
|
else if (Label == "pipepress:" || Label == "pipepressb:")
|
|
{
|
|
// manometr przewodu hamulcowego
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject, 0.1);
|
|
gauge.AssignDouble(&mvOccupied->PipePress);
|
|
}
|
|
else if (Label == "scndpress:")
|
|
{
|
|
// manometr przewodu hamulcowego
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject, 0.1);
|
|
gauge.AssignDouble(&mvOccupied->ScndPipePress);
|
|
}
|
|
else if (Label == "limpipepress:")
|
|
{
|
|
// manometr zbiornika sterujacego zaworu maszynisty
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject, 0.1);
|
|
gauge.AssignDouble(&m_brakehandlecp);
|
|
}
|
|
else if (Label == "cntrlpress:")
|
|
{
|
|
// manometr zbiornika kontrolnego/rorz�du
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject, 0.1);
|
|
gauge.AssignDouble(&mvPantographUnit->PantPress);
|
|
}
|
|
else if (Label == "springbrakepress:")
|
|
{
|
|
// manometr cylindra hamulca sprężynowego
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject, 0.1);
|
|
gauge.AssignDouble(&mvOccupied->SpringBrake.SBP);
|
|
}
|
|
else if (Label == "epctrlvalue:")
|
|
{
|
|
// wskazowka sterowania sila hamulca ep
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject, 0.1);
|
|
gauge.AssignDouble(&mvOccupied->EpForce);
|
|
}
|
|
else if (Label == "compressor:" || Label == "compressorb:")
|
|
{
|
|
// manometr sprezarki/zbiornika glownego
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject, 0.1);
|
|
gauge.AssignDouble(&mvOccupied->Compressor);
|
|
}
|
|
else if (Label == "oilpress:")
|
|
{
|
|
// oil pressure
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(&mvControlled->OilPump.pressure);
|
|
}
|
|
else if (Label == "oiltemp:")
|
|
{
|
|
// oil temperature
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(&mvControlled->dizel_heat.To);
|
|
}
|
|
else if (Label == "water1temp:")
|
|
{
|
|
// main circuit water temperature
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(&mvControlled->dizel_heat.temperatura1);
|
|
}
|
|
else if (Label == "water2temp:")
|
|
{
|
|
// auxiliary circuit water temperature
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(&mvControlled->dizel_heat.temperatura2);
|
|
}
|
|
else if (Label == "pantpress:")
|
|
{
|
|
// pantograph tank pressure
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject, 0.1);
|
|
gauge.AssignDouble(&mvPantographUnit->PantPress);
|
|
}
|
|
// yB - dla drugiej sekcji
|
|
else if (Label == "hvbcurrent1:")
|
|
{
|
|
// 1szy amperomierz
|
|
ggI1B.Load(Parser, DynamicObject);
|
|
}
|
|
else if (Label == "hvbcurrent2:")
|
|
{
|
|
// 2gi amperomierz
|
|
ggI2B.Load(Parser, DynamicObject);
|
|
}
|
|
else if (Label == "hvbcurrent3:")
|
|
{
|
|
// 3ci amperomierz
|
|
ggI3B.Load(Parser, DynamicObject);
|
|
}
|
|
else if (Label == "hvbcurrent:")
|
|
{
|
|
// amperomierz calkowitego pradu
|
|
ggItotalB.Load(Parser, DynamicObject);
|
|
}
|
|
//*************************************************************
|
|
else if (Label == "clock:")
|
|
{
|
|
// zegar analogowy
|
|
if (Parser.getToken<std::string>() == "analog" && DynamicObject->mdKabina)
|
|
{
|
|
// McZapkie-300302: zegarek
|
|
ggClockSInd.Init(DynamicObject->mdKabina->GetFromName("ClockShand"), nullptr, TGaugeAnimation::gt_Rotate, static_cast<float>(1.0 / 60.0));
|
|
ggClockMInd.Init(DynamicObject->mdKabina->GetFromName("ClockMhand"), nullptr, TGaugeAnimation::gt_Rotate, static_cast<float>(1.0 / 60.0));
|
|
ggClockHInd.Init(DynamicObject->mdKabina->GetFromName("ClockHhand"), nullptr, TGaugeAnimation::gt_Rotate, static_cast<float>(1.0 / 12.0));
|
|
}
|
|
}
|
|
else if (Label == "clock_seconds:")
|
|
{
|
|
ggClockSInd.Load(Parser, DynamicObject);
|
|
}
|
|
else if (Label == "evoltage:")
|
|
{
|
|
// woltomierz napiecia silnikow
|
|
ggEngineVoltage.Load(Parser, DynamicObject);
|
|
}
|
|
else if (Label == "hvoltage:")
|
|
{
|
|
// woltomierz wysokiego napiecia
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(&fHVoltage);
|
|
}
|
|
else if (Label == "lvoltage:")
|
|
{
|
|
// woltomierz niskiego napiecia
|
|
ggLVoltage.Load(Parser, DynamicObject);
|
|
}
|
|
else if (Label == "enrot1m:")
|
|
{
|
|
// obrotomierz
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(fEngine + 1);
|
|
} // ggEnrot1m.Load(Parser,DynamicObject->mdKabina);
|
|
else if (Label == "enrot2m:")
|
|
{
|
|
// obrotomierz
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(fEngine + 2);
|
|
} // ggEnrot2m.Load(Parser,DynamicObject->mdKabina);
|
|
else if (Label == "enrot3m:")
|
|
{ // obrotomierz
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignFloat(fEngine + 3);
|
|
} // ggEnrot3m.Load(Parser,DynamicObject->mdKabina);
|
|
else if (Label == "engageratio:")
|
|
{
|
|
// np. ciśnienie sterownika sprzęgła
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignDouble(&mvControlled->dizel_engage);
|
|
} // ggEngageRatio.Load(Parser,DynamicObject->mdKabina);
|
|
else if (Label == "maingearstatus:")
|
|
{
|
|
// np. ciśnienie sterownika skrzyni biegów
|
|
ggMainGearStatus.Load(Parser, DynamicObject);
|
|
}
|
|
else if (Label == "ignitionkey:")
|
|
{
|
|
ggIgnitionKey.Load(Parser, DynamicObject);
|
|
}
|
|
else if (Label == "distcounter:")
|
|
{
|
|
// Ra 2014-07: licznik kilometrów
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
// the counter shows the odometer of the vehicle, kept between the sessions (eu07/maszyna#72). its offset
|
|
// was the state it started each session with, now it is that only for a vehicle with no known state
|
|
if (auto const seed{odometer::counter_seed(gauge.offset(), gauge.scale())}; seed.has_value())
|
|
mvControlled->Odometer.seed(*seed);
|
|
gauge.offset(0.f);
|
|
gauge.AssignDouble(&mvControlled->Odometer.km);
|
|
// the vehicle the counter counts for is one the odometer store keeps, also in the sessions the counter seeds
|
|
// nothing (its state is a saved one by then) and when it's the motor car of the unit the cab is in
|
|
mvControlled->Odometer.shown = true;
|
|
}
|
|
else if (Label == "shuntmodepower:")
|
|
{
|
|
// shunt mode power slider
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignDouble(&mvControlled->AnPos);
|
|
m_controlmapper.insert(gauge, "shuntmodepower:");
|
|
}
|
|
else if (Label == "heatingvoltage:")
|
|
{
|
|
if (mvControlled->HeatingPowerSource.SourceType == TPowerSource::Generator)
|
|
{
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignDouble(&mvControlled->HeatingPowerSource.EngineGenerator.voltage);
|
|
}
|
|
}
|
|
else if (Label == "heatingcurrent:")
|
|
{
|
|
auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka
|
|
gauge.Load(Parser, DynamicObject);
|
|
gauge.AssignDouble(&mvControlled->TotalCurrent);
|
|
}
|
|
else
|
|
{
|
|
// failed to match the label
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
uint16_t TTrain::id()
|
|
{
|
|
if (vid == 0)
|
|
{
|
|
vid = ++simulation::prev_train_id;
|
|
WriteLog("net: assigning id " + std::to_string(vid) + " to vehicle " + Dynamic()->name(), logtype::net);
|
|
}
|
|
return vid;
|
|
}
|
|
|
|
namespace
|
|
{
|
|
// updates trains in range [Start, End)
|
|
void update_trains(std::deque<TTrain *> const &Trains, std::size_t const Start, std::size_t const End, double const Dt)
|
|
{
|
|
for (std::size_t j = Start; j < End; ++j)
|
|
{
|
|
if (Trains[j])
|
|
Trains[j]->Update(Dt);
|
|
}
|
|
}
|
|
} // namespace
|
|
|
|
void train_table::updateAsync(double dt)
|
|
{
|
|
const int threads = std::max(1, Global.trainThreads);
|
|
const size_t total = m_items.size();
|
|
const size_t chunkSize = (total + threads - 1) / threads;
|
|
|
|
std::vector<std::jthread> workers;
|
|
std::vector<std::future<void>> results; // przekazują wyjątki z wątków do głównego wątku
|
|
workers.reserve(threads);
|
|
results.reserve(threads);
|
|
|
|
for (int i = 0; i < threads; ++i)
|
|
{
|
|
const size_t start = i * chunkSize;
|
|
const size_t end = std::min(start + chunkSize, total);
|
|
|
|
if (start >= end)
|
|
break; // brak więcej danych
|
|
|
|
std::packaged_task<void()> task([this, start, end, dt]() { update_trains(m_items, start, end, dt); });
|
|
results.emplace_back(task.get_future());
|
|
workers.emplace_back(std::move(task));
|
|
}
|
|
|
|
// Poczekaj aż wszystkie wątki skończą
|
|
for (auto &worker : workers)
|
|
worker.join();
|
|
|
|
for (auto &result : results)
|
|
result.get();
|
|
|
|
// Teraz kasowanie (tylko w głównym wątku)
|
|
for (TTrain *train : m_items)
|
|
{
|
|
if (!train)
|
|
continue;
|
|
|
|
if (train->pending_delete)
|
|
{
|
|
purge(train->Dynamic()->name());
|
|
if (simulation::Train == train)
|
|
simulation::Train = nullptr;
|
|
}
|
|
else if (simulation::Train != train && Global.network_servers.empty() && !Global.network_client)
|
|
{
|
|
purge(train->Dynamic()->name());
|
|
}
|
|
}
|
|
}
|
|
|
|
void train_table::update(double dt)
|
|
{
|
|
for (TTrain *train : m_items)
|
|
{
|
|
if (!train)
|
|
continue;
|
|
|
|
train->Update(dt);
|
|
|
|
if (train->pending_delete)
|
|
{
|
|
purge(train->Dynamic()->name());
|
|
if (simulation::Train == train)
|
|
simulation::Train = nullptr;
|
|
}
|
|
// for single-player destroy non-player trains
|
|
else if (simulation::Train != train && Global.network_servers.empty() && !Global.network_client)
|
|
{
|
|
purge(train->Dynamic()->name());
|
|
}
|
|
}
|
|
}
|
|
|
|
TTrain *train_table::find_id(std::uint16_t const Id) const
|
|
{
|
|
|
|
if (Id == 0)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
for (TTrain *train : m_items)
|
|
{
|
|
if (!train)
|
|
{
|
|
continue;
|
|
}
|
|
if (train->id() == Id)
|
|
{
|
|
return train;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|