mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 22:44:59 +01:00
* 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 from the lineside tool, and danger_ahead finds where a train first comes to a switch: the start of one it runs onto from its start, or the fouling point of one it runs onto from behind, which may lie behind the point (a signal in the fouling zone). - The card of the selected signal: its distance from the axis of its track, and along it to the start or the fouling point of the switch ahead, in red when it stands inside the fouling zone. The overlay draws the same as a dimension line beside the track on the side of the signal, with the distance at the place. - Placed, dragged along or moved with the gizmo, a signal goes to a round distance to the switch ahead (50 m steps) when within 2.5 m of one; Alt keeps it where it is. The drag of a new one is measured from where it was pressed. - The fixes of the review of the split: the click label of the station tools in their own branch and a plain select in Signals, the card of a signal picked from the check lists shown in Station signals, and the help texts naming the Templates table and the Signals tool. - Self-tests: signalprobe logs the distance from the axis and to the switch ahead, signal snap=1 snaps as placing does. * feat(editor): the fouling point widened in the curves under 250 m, as the standard of the gauge says Standardy techniczne PKP PLK, tom II (from 2025-07-17), 6.5-6.6: the W17 marker stands where the axes of the tracks are nominally 3.50 m apart; where one of the tracks lies there in a curve under 250 m that spacing grows by the widening of the gauge from its radius (annex 1, table 1), the widenings of both summed when both lie in curves. - editor/editorFouling: the fouling point found along the axes of the main track and the branch, standing on its own: at each point of the branch the spacing wanted is the nominal one plus, for each track, the widening on the side of the other track from its radius there (taken over 5 m each way): 50000/R - 185 mm towards the centre of the curve, 60000/R - 225 mm away from it, none from 250 m up. - gauge::curve_widening gives table 1 of the gauge the editor checks already. - The W17 tool and the distance of a signal to the switch ahead both use it; the card of a signal shows how far apart the axes are at the fouling point, the help of the W17 tool says where the figures come from. - Unit tests: a straight branch at 1:9, a branch in a curve of 300 m (no widening) and of 200 m (outer widening), both tracks in curves (both widenings summed) and a straight branch off a curving track. * feat(editor): the cant leans the cars into the fouling point, and the fixes of the review of the metre - The fouling point takes the cant in, as Ie-1 wants it placed "with the gauge, the cant and the widening in the curves": the cars of a track on a cant lean towards the inside of its curve by D Hi / 1500 (bD of table 1 of the standard of the gauge), so when the other track lies on that side the spacing wanted grows by it, taken at 3.05 m over the rail top, the top of the widest part of GPL-1. The cant of each point comes from the roll of its path as the gauge tool takes it. At any radius, as the table has it; the track leaning away adds nothing. - Below 150 m, where table 1 ends, the widening from the radius is that of 150 m rather than the formula run on. - A switch run onto from behind has its fouling point looked for once its own path is walked too, so one lying on that path is found rather than skipped for a farther switch. - A point behind a signal lies on the track of the farther end of its segment, so a signal snapped back over a joint lands at the round distance rather than at the joint. - Alt keeping a signal off the round distances reads the key from ImGui, which Global.altState misses while ImGui holds the keyboard. The gizmo doesn't snap a signal:a1d10bb0says it does, it's placing and dragging with the tool only. - The help of the distance on the card stays on the distance, the spacing of the axes under it. The unused track_trace::nearest_on is gone. - Unit tests: the cant leaning towards the other track in a curve and at 300 m, nothing when leaning away, and the table ending at 150 m. * fix(editor): the cars lean the way the cant of their track tips them, taken 3.25 m up - The cant along the trace keeps its sign: a roll above 0 lowers the left rail of the path (as the editor lifts its terrain by it), turned to the way the track is walked. A track adds the leaning of its cars to the spacing wanted at the fouling point when the other track lies on the side its lower rail is, whichever way it curves: a branch on a cant against its own curve leans towards the main track on its outer side, whichd70f189cmissed, and a cant on the straight counts too. - The leaning is taken 3.25 m over the rail top, the top of the widest part of the cars, rather than 3.05 m of GPL-1. - Unit tests: a cant against the curve, a cant on the straight, and the leaning away still adding nothing. * fix(editor): the station tools tell by the mouse what a button came to, and the fields of a station read as empty What a button of the Station, Station signals and Line block tools came to was written at the foot of the panel, under the lists, scrolled away: a click which refused for want of the code of the station looked as if nothing happened. It's told now by the mouse which clicked, a refusal in red as the other tools do, and in the status bar. The fields of a station still empty show their examples as such, "e.g. BPd", not as values typed in; the Station tool says above its steps that the code is to be typed first, Station signals that the code and the track circuits are wanted, the code marked there as needed. The check of a warning disc and of a block section went by the braking distance of the station, while Set the line signals places them by the one of their line: on lk357 a disc placed 700 m before Z, the line run at 100 km/h, was marked as standing nearer than the 1000 m of the station. A signal of a line out is checked by the braking distance of its line now. * feat(editor): the joints of the track circuits put, moved and taken away by hand, kept by the station The Station tool gets Edit the joints by hand: LMB on a plain track of the station puts a joint there, LMB on a joint takes it, then on a track moves it, on it again takes it away. The circuits are set again at once, one step of undo each. The joints so changed are kept in the //$s record of the station (joints +x/y/z for one put, -x/y/z for a planned one taken away), so Set the track circuits keeps them; As planned forgets them. The undo step carries the hand joints of the station with the tracks. srkjoint drives it in the self-tests. * feat(editor): the indicators under the lights reordered, a signal set from the axis and raised, standing on the ground by default The indicators under the lights of the selected signal get arrows up and down: one changes places with the indicator above or below it, a plate at the foot keeps its own. One step of undo each. The distance of the selected signal from the axis of its track is typed in the panel, it moves across as far along the track as it stands, the gauge pushing it out again where it comes too near. Its height is set the same way, raised over where it stands by default, over the rail heads on a gantry. A signal is put on the ground by default, the zero of its model 0.38 m under the rail heads: the ground lies 0.35 m under them as Ie-102 draws it (Lx), the foot of the mast stands on the foundation 3 cm over it in the models of pctga, and the sceneries made by hand (Wrzosy, Baltyk) stand their signals 0.20 m under the rail foot so. It stood on the rail heads. signalindicatorswap and signalacross drive it in the self-tests. * fix(editor): the hand joints of a station without a record, of its ends and of another station; a dragged signal keeps its place across and its height - Edit the joints by hand on a station not described yet read the record of index -1: the hand joints are shown only for a station with one. - The joint between the station and a line out of it can't be taken: taken away, the circuit of the switch ran on over the tracks of the line. - A joint held is let go when another station opens, a move by less than half a metre lets it go, and a change no step of the history takes is undone, so the undo knows every change of the joints. - A signal dragged or snapped along its track keeps its distance from the axis and its height over the default, set by hand or standing so before. * fix(editor): a dragged signal carries what it had by its own track; As planned forgets the hand joints that change nothing The distance from the axis and the height of a dragged signal were taken against the track it was dropped onto: dropped on the next piece of its line, on a grade or by a parallel track it came out too far, in the gauge or off the ground. They are taken as it stood by its own track at the start of the drag. As planned clears the hand joints even where the circuits come out the same. * fix(editor): a signal stands as high over the rail heads as its include gives, lowered only where its bottom would hang over the ground The default height of a signal was 0.38 m under the rail heads for every model. It is now read from the description of its include, `//$e signal: {..., height: <m>, depth: <m>}`: height is where the zero of the model stands over the rail heads (by Ie-117 § 15 the top of the foundation of a mast 0.10 m under them, of a dwarf 0.20 m), depth how far the model reaches under its zero. With a depth, a signal whose bottom would hang over the ground, down an embankment, goes down onto it, by at most 3 m (more is taken for a bridge). Without a height the zero stands at the rail heads. "Raised" in the panel, a signal moved across or dragged, all count from that default height. * fix(editor): a signal flipped, given another template or its variant for the other side stays as raised as it was The default height now depends on the template and on the ground under the signal, so keeping the height as it was no longer keeps the raise. Flipped to the other side of the track, the signal is raised over the default there as it was over the default on its own side. Given another template (Swap), or the variant of its template for the other side when moved or placed, it goes up or down by how much the default height of the new template differs from the old one. * fix(editor): As planned forgetting hand joints that change nothing is a step of undo of its own With nothing in the circuits to change no step of the history took the forgotten joints, so they went with no undo for it: Ctrl+Z took back the step before. The anchor of the station as it is now carries them in a step of their own. The signalmove selftest gets its carry indented with the block it is in. * feat(editor): an indicator under the lights goes in its place by Ie-117, from the top W21, W24, W20, W19, W26 Put on a signal, an indicator under its lights was put below the ones there. It now goes in its place by Ie-117 section 12.1 among them, under the last one it doesn't go above, the others (W18 and the rest) below these; the ones under it move a place down, in the same step of undo. * fix(editor): the signal card and the move of a signal keep no pointer across a refresh of the signals - The card of the selected signal went on after "To the other side" or "Turn around" with found pointing into the list of the signals standing, which their refresh had just replaced: the indicators and the gauge of the card read freed memory. It now ends that frame there. - signal_move_to read the mount of the template after the refresh, which may scan the templates again; it is taken before it. signal_place takes a copy of the template given for the same reason. - The fouling test counts its metres with an int, and the search of the middle point of the radius is a while loop (no floating loop counter). * fix(editor): the dimension line to the danger point counts its metres with an int (Sonar S2193) The line drawn by the track from a signal to the switch or fouling point ahead stepped a double by 1 m. It now counts the whole metres with an int from the same first one: the points are the same, since adding 1 to a whole double and adding a whole int to it give the same values. --------- Co-authored-by: maj00r <maj00r@host> * feat(editor): ride the camera along the tracks, and a minimap with stations by their W4 (#317) * feat(editor): the camera rides along the tracks, over the joints and switches and over to the tracks alongside Y puts the camera onto the track under the cursor (or the nearest one), looking along it 3 m over the rails. W/S drive it ahead and back the way the camera looks, Shift and Ctrl faster (20, 60, 250 m/s); A/D take it over to the track alongside, a click to any track; E/Q and the wheel raise and lower it; the mouse looks around as when flying. At a switch entered from its blades it goes straight on, Z picks the turnout for the camera alone: no switch is thrown, no track learns of the ride. The bar over the view shows the track, the km, the speed, the height and the switch ahead. Y or Esc ends it. Self-test commands ride, ridewalk, ridejump, rideahead, rideprobe and rideleave. * feat(editor): a minimap of the tracks with the camera on them, and the stations found by the names of their W4 View / Minimap and stations (W4), Ctrl+M: a window with the rail tracks seen from above, the camera as a triangle the way it looks, the track ridden along in orange and the stops of passenger trains as dots with the names of their stations. It follows the camera, or is dragged and zoomed apart from it; a click takes the camera there, riding along the track onto the track there. Above it the stations the PassengerStopPoint memory cells and events name, searched by a part of the name with or without the polish letters; a click (or Enter for the first found) flies the camera over to the stop looking along the track, riding it rides on from there, each click to the next W4 of the station. Self-test commands minimap, stations, station and minimapclick. * fix(editor): the ride and the minimap after the review, with fewer words on the screen - Ctrl+S, Ctrl+Z and the other shortcuts reach the editor while riding; Esc closes an open popup first - no key stays held when a window takes the keyboard, the place is kept within a path that got shorter, a release of the mouse goes where its press went - the minimap keeps under the vertex limit of a draw list, Enter in the search goes round the stops of the station, the marked station stays marked - the bar of the ride is one line: the track, km, speed and height; the switch ahead under it, the keys only while standing - the minimap in the Map menu, opening over the view, with short texts; the context menu of a track rides along it * feat(editor): the ride drives with the right button held, as the camera flies, and the editor works on along it - W/S, A/D and Q/E drive the ride only with the right button held; without it they're the editor's keys again (Q/W/E the gizmo) - the left button and Esc go to the tools while riding: tracks and objects are laid and selected from where the ride took the camera; Y leaves, a flight of the camera to a framing leaves too - after the review: the help names Ctrl+W/Ctrl+Down as the much faster drive, the stops of the minimap stay within the vertex limit, the search field lets the keys go after Enter * fix(editor): the tools keep their wheel and the menu of a track its click while riding, a pan or the view from above ends the ride --------- Co-authored-by: maj00r <maj00r@host> * feat(editor): signals placed by the editor get a name plate drawn by python (#316) * feat: Elf emergency brake position in the master controller (eu07/maszyna#413) The Elf's master controller (EIMCtrlType 2) gets an optional emergency brake position below its position 0, turned on by the new .fiz key EIMCtrlMainEmergency=Yes in Cntrl (default No, no change without it). With it the old positions move up by one (MCPN 5, neutral at 4): the emergency position brakes fully at once and vents the brake pipe, like the alarm chain or the Impuls's EIMCtrlEmergency. The loader raises a too small MCPN to 5 and logs it. The Elf code with hard-coded positions (CheckEIMIC, the MED full braking, the AI) takes the shift into account. SVN data to change afterwards (dynamic/pkp/elf_v1, needs this exe): - every .fiz with EIMCtrlType=2: EIMCtrlMainEmergency=Yes, MCPN=5, DirChangeMaxPos=4 where present; - the cab .mmd mainctrl entries: offset one notch lower (-0.06 -> -0.09), sounds shifted one index up, new sound0 with 26284_elf_nastawnik_nagle_*.wav. Issue: (eu07/maszyna#413) * fix: Elf emergency brake position vents the pipe only from the driven vehicle, coupled units agree on the controller position The emergency position of the master controller vented the brake pipe from every vehicle whose controller stood there, and "MainCtrl" reached the coupled vehicles raw, so an Elf with EIMCtrlMainEmergency and one without it disagreed by one notch (the full braking of one was the emergency brake of the other, neutral of one a power position of the other). The pipe is now vented only from the vehicle driven from (IsCabMaster()), and the position goes to the coupled vehicles in the positions without the key (MainCtrlPosForCoupled(), the emergency one as the full braking), each adding its own shift on receiving it (MainCtrlPosFromCoupled()). The loader's fix-up for the old MCPN=4 raises DirChangeMaxPos by the same shift, so the reverser keeps working at the new neutral. * feat(editor): the signals the editor places get a plate with their name, drawn by python A signal placed with the signal tool used to get the plate texture of textures/tabl named like it, or none at all. Now, unless a texture is picked, its plate is made by python/local/signal_plate.py: "make:signal_plate?name=<name>", a light plate with a dark edge, four screws and the name in black, the way the plates of textures/tabl look. Renaming the signal in its properties renames a drawn plate with it; a picked texture stays. The templates put the plate after a folder, "tabl/(p6)", so material_data::assign() takes the folder off a skin which names a texture made by a script. * fix(editor): a drawn signal plate keeps following a cleared name, and isn't made for a name it can't carry Clearing the name of a signal in its properties made its plate the drawn plate of no name, which then never followed the name again. A drawn plate now follows any rename to a name, and keeps the last one while the name is cleared. A name with '|', '&' or '?', or one longer than 64 characters, gets no plate (0_nothing) instead of a broken one: '|' splits the skin, '&' and '?' the query of the script, and a very long name made a path too long for the file system when the skin was looked for on the disk. * fix(editor): a signal plate keeps its last name through a name it can't carry, and a plate named by hand stays Renaming a signal to a name its plate can't carry turned the drawn plate into 0_nothing, and it stopped following the name for good. Such a name now leaves the plate with the last usable one, like a cleared name does, and the plate follows again once a usable name is typed. A drawn plate whose name was given by hand, different from the name of the signal, is no longer replaced on a rename: only the drawn plate of the signal's own name follows it. * feat(editor): the drawn signal plates come in three looks, plain, toned and aged The plate drawn by python/local/signal_plate.py looked too clean. It now takes a look in its query, "make:signal_plate?look=toned&name=Tm12": plain is the bright plate it was, toned a greyish field with a little grain and dust towards the bottom and the sides, a thinner edge, smaller screws and graphite letters, aged a darker, grainier and dustier one. Toned is drawn when no look is given. The signal tool picks the look under the plate, kept in the settings of the editor. A rename of the signal in its properties keeps the look of its plate. * perf(editor): the grain and the dust of a drawn signal plate are made on whole images The toned and aged plates shaded their field a pixel at a time in python, about 34 ms a plate with the interpreter held, so a station of a hundred signals in view kept the python queue, and the screens of the cabs, waiting for seconds. The dust is now made once per look, and the grain from random bytes of the name, both put on the field with ImageChops: about 2 ms a plate. The mean colour of the plates stays the same; only the grain falls differently. * fix(editor): the station signalling draws the plates of its signals as their schematic names them The plates the station signalling places and renames say what its schematic shows (Tm3, F1, ToA, a block signal without the stem), and a template swapped in for a signal without a plate draws that text too rather than the small letters of the name. A signal left for removal gets a plate of no text again, not one saying "_old". No plate, 0_nothing, or the texture named like the signal, what the editor gave before the plates were drawn, become the drawn plate when the signal is renamed, in the properties panel as by the station signalling, in the look set in the editor. * fix(editor): a plate of a scenery named like the end of the name of its signal stays through a rename in the properties A texture pzs_a was given by its scenery as a, its real plate: a rename in the properties panel keeps it. Only the station signalling, which looked its plates up that way, takes such a one for its own. * feat(editor): the drawn signal plates are 256 pixels across, sharp up close The edge, the screws and the blur are drawn bigger by as much as the plate is, and the grain is as coarse as before, so the three looks stay as they were. The smallest letters tried grow with the plate too. * feat(editor): a drawn signal plate takes a speed index and the m of shunting signals, typed in the signal tool signal_plate.py draws the speed index after the name, one digit up at its right or two as a fraction across the height of the letters (index=4, index=12 for 1/2), and with m=1 an "m" on a strip of its own under the name, as Ie-1 marks a semaphore giving shunting signals and as the textures/tabl a-12m plates show it. The signal tool has a field for the index and a box for the m under the look of the plate; the hint of the plate names them (B 1/2 m). The style of a drawn plate, its look with the index and the m, stays with it through a rename, in the properties panel and by the station signalling, which sets neither. The signal selftest takes index= and m=. * fix(editor): the speed index of a plate takes only digits as they are typed The decimal field let in signs and dots, which stayed shown while the index held only the digits, and filled the two places before a second digit could go in. * fix(sonar): the remarks on the drawn signal plates, to pass the quality gate The new code of the plates was 5.2% technical debt against the 5% of the gate. Fixed the small remarks; the big functions stay as they are: - the speed index field and the plate looks are std::arrays, the index is copied without snprintf, the combo of the looks has a function of its own - ranges algorithms, a string_view for signal_plate_drawn, emplace_back - signal_plate.py: dict literals, a cache of fonts not named like FONTS, no unused local, the name and the m drawn by methods of their own; the plates drawn are byte for byte the same as before --------- Co-authored-by: jerrrrycho <jurek.pakula@gmail.com> Co-authored-by: maj00r <maj00r@host> * fix(editor): the tutorial and the hints tell of the kilometrage, and the first lesson takes O either way The kilometrage (X) was in no hint, no shortcut list and no lesson, though the hectometre posts and the block signals are numbered after it. The row of the track tools now reads L T G N U I X B P V J, the turntable with it, and F1 lists I / X / B. The lesson of the signals and the posts says what X does and where the posts take their numbers from, the km of the line or the km typed in their panel for the place clicked, and it opens with the kilometrage tool too. The first lesson asked to switch to the view from above, which a scenery made in the wizard opens in already: O either way does it now. * fix(editor): master's road lifting texts translated, and the panning by the wheel told of in 3D too The merge of master left the status and the label of the lifting of the road points in English: both go through the translations now. Master pans the 3D view by the wheel as well, so the lesson, the hint row and its line say it works in both views. <cstring>, dropped from the road tool before, came back in the merge and is gone again. * fix(editor): the tools of a plain line in sight, the km of a line set once, a lesson of a whole line and of the ride along a track What a layman building a line with signals and posts couldn't find: - The Signals, Kilometrage and Posts tools are in the main row of Tracks, after the tools of laying; the stations, their signals, the line block, the turntable, the trainset and the checks stay behind More. - "Objects" was where the hectometre posts are: the tool is Posts now (Słupki), its hints say the line the posts go along. - The km of a line could be typed in three places that didn't lead to each other. The panel of the posts and the one of a station, where the line has no km set, say the typed km is theirs alone and have Set the km of the line (X), opening the Kilometrage tool; that tool says first that one known point serves the posts, the stations and the block signals. - The hint of the Signals tool says to pick a signal in the list, then click beside a track; with no templates the panel says so in plain words. - A new lesson, A whole line, step by step: the tracks and switches, the km, the station, its signals, the line block, the posts and the drive, with a button to the station tool, and opened with the station tools. - The first lesson shows the ride of the camera along a track (Y, then W S A D and Z) and has it as a step to try. - lang/editor_pl.po: "Restore the terrain" and "Drag an end" were there twice, the second copies are gone. Checked: MSVC build, unit tests 459/459; editor run on a small scenery, screenshots of the toolbar, the new lesson, the first lesson with the ride ticked after Y, the panels of the posts, the kilometrage and the signals. The station panel with no km of the line wasn't seen, the scenery had no station. * fix(editor): the posts open expanded from the trainset, and the Polish of the whole-line lesson reads right B or the Posts button pressed while the trainset tab is shown opens the hectometre posts with their panel expanded. The Tracks area tooltip names the kilometrage and the posts. The station step names the shunting signals, the station button says Narzędzie Stacja, and the ride rows and the lesson list read smoother in Polish. * fix(editor): a bent model is lengthened along the tracks joined to its own, laid along another track after the bending, and set by fewer settings The ends of a bent model have handles in the view: dragged, the model goes on along the tracks joined there, at a switch the way it's dragged to. Its length, a drag of the whole model and a drag of an end all follow the joined tracks; before, they went on straight past the end of the track under the model. The panel of a bent model picks its track: another one picked, the model stays where it stands, a platform turns its edge to the new track and keeps its length. On top stay the track, the length, the offset and the height, bent or repeated, and the platform edge; the reference point, the position along, turned, mirrored, the cant and the gauge widening went under More settings. The buttons of the model's own length and of the whole track are gone: the length field and the handles do it. The links of a model to its tracks are counted anew when its pieces change, undo and redo included. * fix(editor): the bends of straights laid from the end of a curve begin with a straight, not a compound curve In the mode of straights the curve of a plain track's free end no longer goes on into the curve of the first bend as a compound curve. The line comes out of the end's curve by a transition onto a straight, and each bend gets a curve of its own. Only a curve traced in the mode of a curve goes on from the curve of the end, as it already did at a switch. * fix(editor): the bent model keeps its links and its line to what it reaches, and drags without rebuilding at each track - the links of a bent model are matched anew whenever any of its pieces change, not only the first - the line is lengthened by the plan lengths of the joined tracks and built once a round; a drag reuses the line made at its start while it doesn't grow - the tracks of one name are told apart in the track lists, and a deleted track leaves them - the tracks at the ends the copies no longer reach are left out of the line after an edit or a drag * fix(editor): a click on a bent model's handles changes nothing, and the track picked stays picked - the line is trimmed on a drag's release only when the drag changed the model, and an edit that trimming undoes makes no undo step - the track picked for the bending is kept by the track, not its place in the list, when the list is gathered anew * fix(lang): a stray line taken out of editor_pl.po A single "r" between two entries, left by an edit of the switch texts: msgfmt refuses the file with it. * feat(launcher): the range of the aerial photos of a new real scenery given on the map, changed later in the editor (#328) * feat(launcher): the new real scenery gets the range of its aerial photos on the map, changed later in the editor The wizard of a new scenery asked only for the centre; the editor then downloaded the photos around the camera wherever it went, and a scenery had no range of them until one was drawn in the orthophoto settings. The realistic scenery is made in three steps: the name, the place (a click on the map or the place typed, degrees or PUWG 1992), and the range of the aerial photos: a square of 1, 2, 5 or 10 km around the centre, or an area of the user's, its corners clicked on the map. The range is drawn on the map with its size and the number of the tiles, and it's written to the scenery as the download area (//$z), so the editor downloads the photos and the terrain model inside it only. What a beginner gets wrong is told before the scenery is made: the button stays off with the reason under it (no name, the name taken, no centre, the centre outside Poland, an area being drawn or crossing itself), and a warning comes with the centre outside the area, a large area and a centre clicked on the map of the whole country (the map zooms to the place after the first click). In the editor the download area says in plain words what it does, a square around the camera replaces it in one click, and with the camera outside it a note at the bottom of the view says there are no photos there, with the way to the range. * fix(launcher): the range of the photos asked for after the centre, the drawing given up as with Cancel, the square named by its sides The review of the range of the aerial photos found: - with My own area chosen before the centre, the clicks meant for the centre went to the corners of the area: step 3 waits for the centre; - switching to Fictional while drawing dropped the area there was before, and an unfinished one of three corners counted as done: it's given up as with Cancel now, also with Esc; Enter ends it, Backspace takes the last corner back, as in the editor; - the error of a place mistyped stayed after a click on the map; - the largest square was told to be large or not by the rounding: the warning comes from 50 sq km on; - "2 km" read as a radius: the squares say "2 x 2 km", the tooltip how far each edge is; - a place typed with an area of the user's fitted the map to the area, not to the place. In the editor the note of the camera outside the range says the terrain model isn't there either, its button says it opens the settings, it stands above the strip of the profile and the keys of the tools, and it can be closed until the camera is back inside. The squares around the camera want the place of the scenery on the map, and replace an area there is, or start one of 10 x 10 km, only with a yes. * fix(editor): one note of the empty scenery in the middle of the view, the warnings of an area told once it's drawn A new scenery opened in the editor showed two notes of the same over each other in the middle of the view: the panel of the track tools ("The scenery has no tracks yet") and the line of the terrain ("This scenery is still empty"). The line gives way to the panel now. In the wizard the centre outside the area and the crossing edges were told while the area was still being drawn; they're told once it's done. * fix(editor): the note of the camera outside the range of the photos hidden while the camera rides a track Its lines at the bottom of the view are where the camera riding a track writes the next switch and its keys. --------- Co-authored-by: maj00r <maj00r@host> --------- Co-authored-by: maj00r <maj00r@host> Co-authored-by: Hirek193 <polomarket73@gmail.com> Co-authored-by: jerrrrycho <jurek.pakula@gmail.com>
9241 lines
406 KiB
C++
9241 lines
406 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/DynObj.h"
|
|
|
|
#include "vehicle/lightsprogrammer.h"
|
|
|
|
#include "simulation/simulation.h"
|
|
#include "simulation/blackboxrecorder.h"
|
|
#include "rendering/lightarray.h"
|
|
#include "vehicle/Camera.h"
|
|
#include "vehicle/Train.h"
|
|
#include "vehicle/odometer.h"
|
|
#include "vehicle/Driver.h"
|
|
|
|
#include <algorithm>
|
|
#include <iterator>
|
|
#include <unordered_set>
|
|
#include "utilities/Globals.h"
|
|
#include "utilities/Timer.h"
|
|
#include "utilities/Logs.h"
|
|
#include "utilities/glmHelpers.h"
|
|
#include "Console.h"
|
|
#include "world/Traction.h"
|
|
#include "audio/sound.h"
|
|
#include "model/MdlMngr.h"
|
|
#include "model/Model3d.h"
|
|
#include "vehicle/doorwings.h"
|
|
#include "rendering/renderer.h"
|
|
#include "application/uitranscripts.h"
|
|
#include "input/messaging.h"
|
|
#include "application/application.h"
|
|
#include "vehicle/Driver.h"
|
|
|
|
// Ra: taki zapis funkcjonuje lepiej, ale może nie jest optymalny
|
|
#define vWorldFront glm::vec3(0, 0, 1)
|
|
#define vWorldUp glm::vec3(0, 1, 0)
|
|
#define vWorldLeft glm::cross(vWorldUp, vWorldFront)
|
|
|
|
#define M_2PI 6.283185307179586476925286766559;
|
|
const float maxrot = (float)(M_PI / 3.0); // 60°
|
|
|
|
std::string const TDynamicObject::MED_labels[] = {
|
|
"masa: ", "amax: ", "Fzad: ", "FmPN: ", "FmED: ", "FrED: ", "FzPN: ", "nPrF: "
|
|
};
|
|
|
|
bool TDynamicObject::bDynamicRemove { false };
|
|
|
|
// helper, locates submodel with specified name in specified 3d model; returns: pointer to the submodel, or null
|
|
TSubModel *
|
|
GetSubmodelFromName( TModel3d * const Model, std::string const Name ) {
|
|
|
|
return Model ? Model->GetFromName(Name) : nullptr;
|
|
}
|
|
|
|
// Ra 2015-01: sprawdzenie dostępności tekstury o podanej nazwie
|
|
std::string
|
|
TextureTest( std::string const &Name ) {
|
|
|
|
auto const lookup {
|
|
FileExists(
|
|
{ Global.asCurrentTexturePath + Name, Name, paths::textures + Name },
|
|
{ ".mat", ".dds", ".tga", ".ktx", ".png", ".bmp", ".jpg", ".tex" } ) };
|
|
|
|
return lookup.first + lookup.second;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
void TAnimPant::common_pantograph_settings()
|
|
{ // wspólne ustawienia, liczone po przypisaniu wymiarów ramion
|
|
vPos = glm::dvec3(0, 0, 0);
|
|
fAngleL0 = glm::radians(2.8547285515689267247882521833308);
|
|
fAngleL = fAngleL0; // początkowy kąt dolnego ramienia
|
|
fAngleU0 = acos((fLenL1 * cos(fAngleL) + fHoriz) / fLenU1); // górne ramię
|
|
fAngleU = fAngleU0; // początkowy kąt
|
|
PantWys = fLenL1 * sin(fAngleL) + fLenU1 * sin(fAngleU) + fHeight; // wysokość początkowa
|
|
PantTraction = PantWys;
|
|
hvPowerWire = nullptr;
|
|
fWidthExtra = 0.381f; //(2.032m-1.027)/2
|
|
// poza obszarem roboczym jest aproksymacja łamaną o 5 odcinkach
|
|
fHeightExtra[0] = 0.0f; //+0.0762
|
|
fHeightExtra[1] = -0.01f; //+0.1524
|
|
fHeightExtra[2] = -0.03f; //+0.2286
|
|
fHeightExtra[3] = -0.07f; //+0.3048
|
|
fHeightExtra[4] = -0.15f; //+0.3810
|
|
}
|
|
|
|
void TAnimPant::AKP_4E()
|
|
{ // ustawienie wymiarów dla pantografu AKP-4E
|
|
fLenL1 = 1.22; // 1.176289 w modelach
|
|
fLenU1 = 1.755; // 1.724482197 w modelach
|
|
fHoriz = 0.535; // 0.54555075 przesunięcie ślizgu w długości pojazdu względem
|
|
// osi obrotu dolnego
|
|
// ramienia
|
|
fHeight = 0.07; // wysokość ślizgu ponad oś obrotu
|
|
fWidth = 0.635; // połowa szerokości ślizgu, 0.635 dla AKP-1 i AKP-4E
|
|
common_pantograph_settings();
|
|
};
|
|
void TAnimPant::WBL85()
|
|
{ // ustawienie wymiarów dla pantografu WBL88
|
|
// mnozniki animacji ramion dla pantografu WBL88
|
|
rd1rf = 1.f;
|
|
rd2rf = 1.2;
|
|
rg1rf = 0.875;
|
|
rg2rf = 1.0;
|
|
slizgrf = 1.f;
|
|
|
|
fLenL1 = 1.98374;
|
|
fLenU1 = 2.14199;
|
|
fHoriz = 0.142; // 0.54555075 przesunięcie ślizgu w długości pojazdu względem
|
|
// osi obrotu dolnego ramienia
|
|
fHeight = 0.09353; // wysokość ślizgu ponad oś obrotu
|
|
fWidth = 0.4969; // połowa szerokości ślizgu
|
|
common_pantograph_settings();
|
|
};
|
|
void TAnimPant::EC160_200()
|
|
{ // ustawienie wymiarów dla pantografow EC160 lub EC200
|
|
// mnozniki animacji ramion dla pantografow EC160 lub EC200
|
|
rd1rf = 1.f;
|
|
rd2rf = 0.85;
|
|
rg1rf = 1.f;
|
|
rg2rf = 1.f; // 0.833
|
|
slizgrf = 1.f;
|
|
|
|
fLenL1 = 1.98374;
|
|
fLenU1 = 2.14199;
|
|
fHoriz = 0.142; // 0.54555075 przesunięcie ślizgu w długości pojazdu względem
|
|
// osi obrotu dolnego ramienia
|
|
fHeight = 0.09353; // wysokość ślizgu ponad oś obrotu
|
|
fWidth = 0.4969; // połowa szerokości ślizgu
|
|
common_pantograph_settings();
|
|
};
|
|
void TAnimPant::DSAx()
|
|
{ // ustawienie wymiarów dla pantografow z rodziny DSA
|
|
// mnozniki animacji ramion dla pantografow z rodziny DSA
|
|
rd1rf = 1.f;
|
|
rd2rf = 1.025;
|
|
rg1rf = 0.875;
|
|
rg2rf = 1.f;
|
|
slizgrf = 1.f;
|
|
|
|
fLenL1 = 1.98374;
|
|
fLenU1 = 2.14199;
|
|
fHoriz = 0.142; // 0.54555075 przesunięcie ślizgu w długości pojazdu względem
|
|
// osi obrotu dolnego ramienia
|
|
fHeight = 0.09353; // wysokość ślizgu ponad oś obrotu
|
|
fWidth = 0.4969; // połowa szerokości ślizgu
|
|
common_pantograph_settings();
|
|
};
|
|
//---------------------------------------------------------------------------
|
|
int TAnim::TypeSet(int i, TMoverParameters currentMover, int fl)
|
|
{ // ustawienie typu animacji i zależnej od niego ilości animowanych submodeli
|
|
fMaxDist = -1.0; // normalnie nie pokazywać
|
|
switch (i)
|
|
{ // maska 0x000F: ile używa wskaźników na submodele (0 gdy jeden,
|
|
// wtedy bez tablicy)
|
|
// maska 0x00F0:
|
|
// 0-osie,1-drzwi,2-obracane,3-zderzaki,4-wózki,5-pantografy,6-tłoki
|
|
// maska 0xFF00: ile używa liczb float dla współczynników i stanu
|
|
case 0:
|
|
iFlags = 0x000;
|
|
break; // 0-oś
|
|
case 1:
|
|
iFlags = 0x010;
|
|
break; // 1-drzwi
|
|
case 2:
|
|
iFlags = 0x020;
|
|
fParam = fl ? new float[fl] : nullptr;
|
|
iFlags += fl << 8;
|
|
break; // 2-wahacz, dźwignia itp.
|
|
case 3:
|
|
iFlags = 0x030;
|
|
break; // 3-zderzak
|
|
case 4:
|
|
iFlags = 0x040;
|
|
break; // 4-wózek
|
|
case 5: // 5-pantograf - 5 submodeli
|
|
iFlags = 0x055;
|
|
fParamPants = new TAnimPant();
|
|
switch (currentMover.EnginePowerSource.CollectorParameters.PantographType) {
|
|
case TPantType::AKP_4E:
|
|
fParamPants->AKP_4E();
|
|
break;
|
|
case TPantType::DSAx:
|
|
fParamPants->DSAx();
|
|
break;
|
|
case TPantType::EC160_200:
|
|
fParamPants->EC160_200();
|
|
break;
|
|
case TPantType::WBL85:
|
|
fParamPants->WBL85();
|
|
break;
|
|
}
|
|
|
|
break;
|
|
case 6:
|
|
iFlags = 0x068;
|
|
break; // 6-tłok i rozrząd - 8 submodeli
|
|
case 7:
|
|
iFlags = 0x070;
|
|
break; // doorstep
|
|
case 8:
|
|
iFlags = 0x080;
|
|
break; // mirror
|
|
case 9:
|
|
iFlags = 0x023; // 2: Rotating/Motion-based, 8: Uses 3 submodels
|
|
break;
|
|
default:
|
|
iFlags = 0;
|
|
}
|
|
yUpdate = nullptr;
|
|
return iFlags & 15; // ile wskaźników rezerwować dla danego typu animacji
|
|
};
|
|
|
|
TAnim::~TAnim()
|
|
{ // usuwanie animacji
|
|
switch (iFlags & 0xF0)
|
|
{ // usuwanie struktur, zależnie ile zostało stworzonych
|
|
case 0x20: // 2-wahacz, dźwignia itp.
|
|
delete fParam;
|
|
break;
|
|
case 0x50: // 5-pantograf
|
|
delete fParamPants;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
};
|
|
/*
|
|
void TAnim::Parovoz(){
|
|
// animowanie tłoka i rozrządu parowozu
|
|
};
|
|
*/
|
|
|
|
|
|
// assigns specified texture or a group of textures to replacable texture slots
|
|
void
|
|
material_data::assign( std::string const &Replacableskin ) {
|
|
|
|
// a template puts its parameter after a folder ("tabl/(p6)"): a texture made by a script given there keeps its scheme
|
|
if( auto const scheme { Replacableskin.find( "/make:" ) };
|
|
scheme != std::string::npos
|
|
&& false == contains( Replacableskin, '|' ) ) {
|
|
assign( Replacableskin.substr( scheme + 1 ) );
|
|
return;
|
|
}
|
|
// check for the pipe method first
|
|
if( contains( Replacableskin, '|' ) ) {
|
|
cParser nameparser( Replacableskin );
|
|
nameparser.getTokens( 4, false, "|" );
|
|
int skinindex = 0;
|
|
std::string texturename; nameparser >> texturename;
|
|
while( texturename != "" && skinindex < 4 ) {
|
|
replacable_skins[ skinindex + 1 ] = GfxRenderer->Fetch_Material( texturename );
|
|
++skinindex;
|
|
texturename = ""; nameparser >> texturename;
|
|
}
|
|
multi_textures = skinindex;
|
|
}
|
|
else {
|
|
// otherwise try the basic approach
|
|
int skinindex = 0;
|
|
do {
|
|
// test quietly for file existence so we don't generate tons of false errors in the log
|
|
// NOTE: this means actual missing files won't get reported which is hardly ideal, but still somewhat better
|
|
auto const material { TextureTest( ToLower( Replacableskin + "," + std::to_string( skinindex + 1 ) ) ) };
|
|
if( true == material.empty() ) { break; }
|
|
|
|
replacable_skins[ skinindex + 1 ] = GfxRenderer->Fetch_Material( material );
|
|
++skinindex;
|
|
} while( skinindex < 4 );
|
|
multi_textures = skinindex;
|
|
if( multi_textures == 0 ) {
|
|
// zestaw nie zadziałał, próbujemy normanie
|
|
replacable_skins[ 1 ] = GfxRenderer->Fetch_Material( Replacableskin );
|
|
}
|
|
}
|
|
if( replacable_skins[ 1 ] == null_handle ) {
|
|
// last ditch attempt, check for single replacable skin texture
|
|
replacable_skins[ 1 ] = GfxRenderer->Fetch_Material( Replacableskin );
|
|
}
|
|
|
|
// BUGS! it's not entierly designed whether opacity is property of material or submodel,
|
|
// and code does confusing things with this in various places
|
|
textures_alpha = GfxRenderer->Material(replacable_skins[1])->is_translucent() ? 0x31310031 : // tekstura -1 z kanałem alfa - nie renderować w cyklu nieprzezroczystych
|
|
0x30300030; // wszystkie tekstury nieprzezroczyste - nie renderować w cyklu przezroczystych
|
|
if( GfxRenderer->Material( replacable_skins[ 2 ] )->is_translucent() ) {
|
|
// tekstura -2 z kanałem alfa - nie renderować w cyklu nieprzezroczystych
|
|
textures_alpha |= 0x02020002;
|
|
}
|
|
if( GfxRenderer->Material( replacable_skins[ 3 ] )->is_translucent() ) {
|
|
// tekstura -3 z kanałem alfa - nie renderować w cyklu nieprzezroczystych
|
|
textures_alpha |= 0x04040004;
|
|
}
|
|
if( GfxRenderer->Material( replacable_skins[ 4 ] )->is_translucent() ) {
|
|
// tekstura -4 z kanałem alfa - nie renderować w cyklu nieprzezroczystych
|
|
textures_alpha |= 0x08080008;
|
|
}
|
|
}
|
|
|
|
|
|
namespace {
|
|
|
|
// a luadestinationsign: or wasmdestinationsign: block, its script in the vehicle folder when it has no path of its own
|
|
void deserialize_script_sign( cParser &Parser, script_screens::screen_config &Sign, std::string const &Folder ) {
|
|
|
|
Sign.deserialize( Parser );
|
|
if( false == Sign.script.empty()
|
|
&& substr_path( Sign.script ).empty() ) {
|
|
Sign.script = Folder + Sign.script;
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void TDynamicObject::destination_data::deserialize( cParser &Input ) {
|
|
|
|
while( true == deserialize_mapping( Input ) ) {
|
|
; // all work done by while()
|
|
}
|
|
}
|
|
|
|
bool TDynamicObject::destination_data::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 == "update:" ) {
|
|
auto const value { Input.getToken<std::string>() };
|
|
// TODO: implement
|
|
}
|
|
else if( key == "instance:" ) {
|
|
instancing = Input.getToken<std::string>();
|
|
}
|
|
else if( key == "parameters:" ) {
|
|
parameters = Input.getToken<std::string>();
|
|
}
|
|
else if( key == "background:" ) {
|
|
background = Input.getToken<std::string>();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
TDynamicObject * TDynamicObject::FirstFind(int &coupler_nr, int cf)
|
|
{ // szukanie skrajnego połączonego pojazdu w pociagu
|
|
// od strony sprzegu (coupler_nr) obiektu (start)
|
|
TDynamicObject *temp = this;
|
|
for (int i = 0; i < 300; i++) // ograniczenie do 300 na wypadek zapętlenia składu
|
|
{
|
|
if (!temp)
|
|
return nullptr; // Ra: zabezpieczenie przed ewentaulnymi błędami sprzęgów
|
|
if ((temp->MoverParameters->Couplers[coupler_nr].CouplingFlag & cf) != cf)
|
|
return temp; // nic nie ma już dalej podłączone sprzęgiem cf
|
|
if (coupler_nr == end::front)
|
|
{ // jeżeli szukamy od sprzęgu 0
|
|
if (temp->PrevConnected()) // jeśli mamy coś z przodu
|
|
{
|
|
if (temp->PrevConnectedNo() == end::front) // jeśli pojazd od strony sprzęgu 0 jest odwrócony
|
|
coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu
|
|
temp = temp->PrevConnected(); // ten jest od strony 0
|
|
}
|
|
else
|
|
return temp; // jeśli jednak z przodu nic nie ma
|
|
}
|
|
else
|
|
{
|
|
if (temp->NextConnected())
|
|
{
|
|
if (temp->NextConnectedNo() == end::rear) // jeśli pojazd od strony sprzęgu 1 jest odwrócony
|
|
coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu
|
|
temp = temp->NextConnected(); // ten pojazd jest od strony 1
|
|
}
|
|
else
|
|
return temp; // jeśli jednak z tyłu nic nie ma
|
|
}
|
|
}
|
|
return nullptr; // to tylko po wyczerpaniu pętli
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|
|
float TDynamicObject::GetEPP()
|
|
{ // szukanie skrajnego połączonego pojazdu w pociagu
|
|
// od strony sprzegu (coupler_nr) obiektu (start)
|
|
TDynamicObject *temp = this;
|
|
int coupler_nr = 0;
|
|
double eq = 0.0;
|
|
double am = 0.0;
|
|
|
|
for (int i = 0; i < 300; ++i) // ograniczenie do 300 na wypadek zapętlenia składu
|
|
{
|
|
if (!temp)
|
|
break; // Ra: zabezpieczenie przed ewentaulnymi błędami sprzęgów
|
|
eq += temp->MoverParameters->PipePress * temp->MoverParameters->Dim.L;
|
|
am += temp->MoverParameters->Dim.L;
|
|
if ((temp->MoverParameters->Couplers[coupler_nr].CouplingFlag & coupling::brakehose) != coupling::brakehose)
|
|
break; // nic nie ma już dalej podłączone
|
|
if (coupler_nr == 0)
|
|
{ // jeżeli szukamy od sprzęgu 0
|
|
if (temp->PrevConnected()) // jeśli mamy coś z przodu
|
|
{
|
|
if (temp->PrevConnectedNo() == end::front) // jeśli pojazd od strony sprzęgu 0 jest odwrócony
|
|
coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu
|
|
temp = temp->PrevConnected(); // ten jest od strony 0
|
|
}
|
|
else
|
|
break; // jeśli jednak z przodu nic nie ma
|
|
}
|
|
else
|
|
{
|
|
if (temp->NextConnected())
|
|
{
|
|
if (temp->NextConnectedNo() == end::rear) // jeśli pojazd od strony sprzęgu 1 jest odwrócony
|
|
coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu
|
|
temp = temp->NextConnected(); // ten pojazd jest od strony 1
|
|
}
|
|
else
|
|
break; // jeśli jednak z tyłu nic nie ma
|
|
}
|
|
}
|
|
|
|
temp = this;
|
|
coupler_nr = 1;
|
|
for (int i = 0; i < 300; i++) // ograniczenie do 300 na wypadek zapętlenia składu
|
|
{
|
|
if (!temp)
|
|
break; // Ra: zabezpieczenie przed ewentaulnymi błędami sprzęgów
|
|
eq += temp->MoverParameters->PipePress * temp->MoverParameters->Dim.L;
|
|
am += temp->MoverParameters->Dim.L;
|
|
if ((temp->MoverParameters->Couplers[coupler_nr].CouplingFlag & coupling::brakehose) != coupling::brakehose)
|
|
break; // nic nie ma już dalej podłączone
|
|
if (coupler_nr == 0)
|
|
{ // jeżeli szukamy od sprzęgu 0
|
|
if (temp->PrevConnected()) // jeśli mamy coś z przodu
|
|
{
|
|
if (temp->PrevConnectedNo() == end::front) // jeśli pojazd od strony sprzęgu 0 jest odwrócony
|
|
coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu
|
|
temp = temp->PrevConnected(); // ten jest od strony 0
|
|
}
|
|
else
|
|
break; // jeśli jednak z przodu nic nie ma
|
|
}
|
|
else
|
|
{
|
|
if (temp->NextConnected())
|
|
{
|
|
if (temp->NextConnectedNo() == end::rear) // jeśli pojazd od strony sprzęgu 1 jest odwrócony
|
|
coupler_nr = 1 - coupler_nr; // to zmieniamy kierunek sprzęgu
|
|
temp = temp->NextConnected(); // ten pojazd jest od strony 1
|
|
}
|
|
else
|
|
break; // jeśli jednak z tyłu nic nie ma
|
|
}
|
|
}
|
|
eq -= MoverParameters->PipePress * MoverParameters->Dim.L;
|
|
am -= MoverParameters->Dim.L;
|
|
return eq / am;
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|
|
TDynamicObject * TDynamicObject::GetFirstDynamic(int cpl_type, int cf)
|
|
{ // Szukanie skrajnego połączonego pojazdu w pociagu
|
|
// od strony sprzegu (cpl_type) obiektu szukajacego
|
|
// Ra: wystarczy jedna funkcja do szukania w obu kierunkach
|
|
return FirstFind(cpl_type, cf); // używa referencji
|
|
};
|
|
|
|
void TDynamicObject::ABuSetModelShake(glm::dvec3 mShake)
|
|
{
|
|
modelShake = mShake;
|
|
};
|
|
|
|
int TDynamicObject::GetPneumatic(bool front, bool red)
|
|
{
|
|
int x, y, z; // 1=prosty, 2=skośny
|
|
if (red)
|
|
{
|
|
if (front)
|
|
{
|
|
x = btCPneumatic1.GetStatus();
|
|
y = btCPneumatic1r.GetStatus();
|
|
}
|
|
else
|
|
{
|
|
x = btCPneumatic2.GetStatus();
|
|
y = btCPneumatic2r.GetStatus();
|
|
}
|
|
}
|
|
else if (front)
|
|
{
|
|
x = btPneumatic1.GetStatus();
|
|
y = btPneumatic1r.GetStatus();
|
|
}
|
|
else
|
|
{
|
|
x = btPneumatic2.GetStatus();
|
|
y = btPneumatic2r.GetStatus();
|
|
}
|
|
z = 0; // brak węży?
|
|
if (x > 0 && y > 0)
|
|
z = 3; // dwa
|
|
if (x > 0 && y == 0)
|
|
z = 1; // lewy, brak prawego
|
|
if (x == 0 && y > 0)
|
|
z = 2; // brak lewego, prawy
|
|
|
|
return z;
|
|
}
|
|
|
|
void TDynamicObject::SetPneumatic(bool front, bool red)
|
|
{
|
|
int x = 0,
|
|
ten = 0,
|
|
tamten = 0;
|
|
ten = GetPneumatic(front, red); // 1=lewy skos,2=prawy skos,3=dwa proste
|
|
if (front)
|
|
if (PrevConnected()) // pojazd od strony sprzęgu 0
|
|
tamten = PrevConnected()->GetPneumatic(PrevConnectedNo() == end::front ? true : false, red);
|
|
if (!front)
|
|
if (NextConnected()) // pojazd od strony sprzęgu 1
|
|
tamten = NextConnected()->GetPneumatic(NextConnectedNo() == end::front ? true : false, red);
|
|
if (ten == tamten) // jeśli układ jest symetryczny
|
|
switch (ten)
|
|
{
|
|
case 1:
|
|
x = 2;
|
|
break; // mamy lewy skos, dać lewe skosy
|
|
case 2:
|
|
x = 3;
|
|
break; // mamy prawy skos, dać prawe skosy
|
|
case 3: // wszystkie cztery na prosto
|
|
if (MoverParameters->Couplers[front ? end::front : end::rear].Render)
|
|
x = 1;
|
|
else
|
|
x = 4;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
if (ten == 2)
|
|
x = 4;
|
|
if (ten == 1)
|
|
x = 1;
|
|
if (ten == 3)
|
|
if (tamten == 1)
|
|
x = 4;
|
|
else
|
|
x = 1;
|
|
}
|
|
if (front)
|
|
{
|
|
if (red)
|
|
cp1 = x;
|
|
else
|
|
sp1 = x;
|
|
} // który pokazywać z przodu
|
|
else
|
|
{
|
|
if (red)
|
|
cp2 = x;
|
|
else
|
|
sp2 = x;
|
|
} // który pokazywać z tyłu
|
|
}
|
|
|
|
void TDynamicObject::UpdateAxle(TAnim *pAnim)
|
|
{ // animacja osi
|
|
size_t wheel_id = pAnim->dWheelAngle;
|
|
pAnim->smAnimated->SetRotate(float3(1, 0, 0), dWheelAngle[wheel_id]);
|
|
pAnim->smAnimated->future_transform = glm::rotate((float)glm::radians(m_future_wheels_angle[wheel_id]), glm::vec3(1.0f, 0.0f, 0.0f));
|
|
};
|
|
|
|
// angle of a slotted lever for given angle of the wheel, which drives the coupling rod with the pin
|
|
// all points of the coupling rod move along circles of crank radius, the lever follows the pin sliding in its slot
|
|
double TDynamicObject::slottedlever_angle( slottedlever_data const &Lever, double const Wheelangle ) {
|
|
// crank turned around X axis, the same way as the wheel
|
|
auto const wheelangle { glm::radians( Wheelangle ) };
|
|
auto const crank { glm::dvec2(
|
|
Lever.crank.x * std::cos( wheelangle ) - Lever.crank.y * std::sin( wheelangle ),
|
|
Lever.crank.x * std::sin( wheelangle ) + Lever.crank.y * std::cos( wheelangle ) ) };
|
|
auto const pin { Lever.pin - Lever.crank + crank };
|
|
// angle relative to the pose of the lever in the model, which matches wheel angle 0
|
|
return glm::degrees( std::atan2( pin.y, pin.x ) - std::atan2( Lever.pin.y, Lever.pin.x ) );
|
|
}
|
|
|
|
void TDynamicObject::update_slottedlevers() {
|
|
|
|
for( auto const &lever : m_slottedlevers ) {
|
|
auto const wheelid { (
|
|
( lever.axle < iAnimType[ ANIM_WHEELS ] ) && ( lever.axle < static_cast<int>( pAnimations.size() ) ) ?
|
|
pAnimations[ lever.axle ].dWheelAngle :
|
|
1 ) }; // driving wheels and coupling rods by default
|
|
auto const angle { slottedlever_angle( lever, dWheelAngle[ wheelid ] ) };
|
|
auto const futureangle { slottedlever_angle( lever, dWheelAngle[ wheelid ] + m_future_wheels_angle[ wheelid ] ) };
|
|
lever.submodel->SetRotate( float3( 1, 0, 0 ), angle );
|
|
lever.submodel->future_transform = glm::rotate( (float)glm::radians( std::remainder( futureangle - angle, 360.0 ) ), glm::vec3( 1.0f, 0.0f, 0.0f ) );
|
|
}
|
|
}
|
|
|
|
namespace {
|
|
|
|
// the position of the door the animated wing belongs to: its shift or angle from closed
|
|
float door_position( TMoverParameters const &Mover, TAnim const *Animation ) {
|
|
|
|
return Mover.Doors.instances[ (
|
|
door_wings::on_right_side( Animation->iNumber ) ?
|
|
side::right :
|
|
side::left ) ].position;
|
|
}
|
|
|
|
// the wing in the main model, and its namesake in the low poly interior; either can be missing
|
|
std::array<TSubModel *, 2> wing_parts( TAnim const *Animation ) {
|
|
|
|
return { Animation->smAnimated, Animation->smInterior };
|
|
}
|
|
|
|
// folding door: the smaller wing turns, the larger wing (its child) the other way, the step (child of that) under it
|
|
void fold_wing( TSubModel *Wing, door_wings::fold_angles const &Angles ) {
|
|
|
|
if( Wing == nullptr ) { return; }
|
|
// skrzydło mniejsze
|
|
Wing->SetRotate( float3( 0, 0, 1 ), Angles.smaller );
|
|
// skrzydło większe
|
|
auto *larger { Wing->ChildGet() };
|
|
if( larger == nullptr ) { return; }
|
|
larger->SetRotate( float3( 0, 0, 1 ), Angles.larger );
|
|
// podnóżek?
|
|
auto *step { larger->ChildGet() };
|
|
if( step == nullptr ) { return; }
|
|
step->SetRotate( float3( 0, 1, 0 ), Angles.step );
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// animacja drzwi - przesuw
|
|
void TDynamicObject::UpdateDoorTranslate(TAnim *pAnim) {
|
|
|
|
if( pAnim->smAnimated == nullptr ) { return; }
|
|
|
|
auto const shift { door_wings::slide( door_position( *MoverParameters, pAnim ) ) };
|
|
for( auto *wing : wing_parts( pAnim ) ) {
|
|
if( wing != nullptr ) {
|
|
wing->SetTranslate( shift );
|
|
}
|
|
}
|
|
};
|
|
|
|
// animacja drzwi - obrót
|
|
void TDynamicObject::UpdateDoorRotate(TAnim *pAnim) {
|
|
|
|
if( pAnim->smAnimated == nullptr ) { return; }
|
|
|
|
auto const angle { door_position( *MoverParameters, pAnim ) };
|
|
for( auto *wing : wing_parts( pAnim ) ) {
|
|
if( wing != nullptr ) {
|
|
wing->SetRotate( float3( 1, 0, 0 ), angle );
|
|
}
|
|
}
|
|
};
|
|
|
|
// animacja drzwi - obrót
|
|
void TDynamicObject::UpdateDoorFold(TAnim *pAnim) {
|
|
|
|
if( pAnim->smAnimated == nullptr ) { return; }
|
|
|
|
auto const angles { door_wings::fold( door_position( *MoverParameters, pAnim ) ) };
|
|
for( auto *wing : wing_parts( pAnim ) ) {
|
|
fold_wing( wing, angles );
|
|
}
|
|
};
|
|
|
|
// animacja drzwi - odskokprzesuw
|
|
void TDynamicObject::UpdateDoorPlug(TAnim *pAnim) {
|
|
|
|
if( pAnim->smAnimated == nullptr ) { return; }
|
|
|
|
auto const shift { door_wings::plug( door_position( *MoverParameters, pAnim ), MoverParameters->Doors.range_out ) };
|
|
for( auto *wing : wing_parts( pAnim ) ) {
|
|
if( wing != nullptr ) {
|
|
wing->SetTranslate( shift );
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDynamicObject::UpdatePant(TAnim *pAnim)
|
|
{ // animacja pantografu - 4 obracane ramiona, ślizg piąty
|
|
float a, b, c;
|
|
a = glm::degrees(pAnim->fParamPants->fAngleL - pAnim->fParamPants->fAngleL0);
|
|
b = glm::degrees(pAnim->fParamPants->fAngleU - pAnim->fParamPants->fAngleU0);
|
|
c = a + b;
|
|
if (pAnim->smElement[0])
|
|
pAnim->smElement[0]->SetRotate(float3(-1, 0, 0), a); // dolne ramie 1
|
|
if (pAnim->smElement[1])
|
|
pAnim->smElement[1]->SetRotate(float3(1, 0, 0), a * pAnim->fParamPants->rd2rf); // dolne ramie 2
|
|
if (pAnim->smElement[2])
|
|
pAnim->smElement[2]->SetRotate(float3(1, 0, 0), c); // górne ramie 1
|
|
if (pAnim->smElement[3])
|
|
pAnim->smElement[3]->SetRotate(float3(-1, 0, 0), c * pAnim->fParamPants->rg2rf); // gorne ramie 2
|
|
if (pAnim->smElement[4])
|
|
pAnim->smElement[4]->SetRotate(float3(-1, 0, 0), b * pAnim->fParamPants->slizgrf); // ślizg
|
|
}
|
|
|
|
// doorstep animation, shift
|
|
void TDynamicObject::UpdatePlatformTranslate( TAnim *pAnim ) {
|
|
|
|
if( pAnim->smAnimated == nullptr ) { return; }
|
|
|
|
auto const &door { MoverParameters->Doors.instances[ (
|
|
( pAnim->iNumber & 1 ) == 0 ?
|
|
side::right :
|
|
side::left ) ] };
|
|
|
|
pAnim->smAnimated->SetTranslate(
|
|
glm::vec3{
|
|
std::lerp( 0.f, MoverParameters->Doors.step_range, door.step_position ),
|
|
0.0,
|
|
0.0 } );
|
|
}
|
|
|
|
// doorstep animation, rotate
|
|
void TDynamicObject::UpdatePlatformRotate( TAnim *pAnim ) {
|
|
|
|
if( pAnim->smAnimated == nullptr ) { return; }
|
|
|
|
auto const &door { MoverParameters->Doors.instances[ (
|
|
( pAnim->iNumber & 1 ) == 0 ?
|
|
side::right :
|
|
side::left ) ] };
|
|
|
|
pAnim->smAnimated->SetRotate(
|
|
float3( 0, 1, 0 ),
|
|
std::lerp( 0.f, MoverParameters->Doors.step_range, door.step_position ) );
|
|
}
|
|
|
|
// mirror animation, rotate
|
|
void TDynamicObject::UpdateMirror( TAnim *pAnim ) {
|
|
|
|
if( pAnim->smAnimated == nullptr ) { return; }
|
|
|
|
// only animate the mirror if it's located on the same end of the vehicle as the active cab
|
|
auto const isactive { (
|
|
MoverParameters->CabOccupied > 0 ? ( pAnim->iNumber >> 4 == end::front ? 1.0 : 0.0 ) :
|
|
MoverParameters->CabOccupied < 0 ? ( pAnim->iNumber >> 4 == end::rear ? 1.0 : 0.0 ) :
|
|
0.0 ) };
|
|
|
|
if( pAnim->iNumber & 1 )
|
|
pAnim->smAnimated->SetRotate(
|
|
float3( 0, 1, 0 ),
|
|
std::lerp( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveR * isactive ) );
|
|
else
|
|
pAnim->smAnimated->SetRotate(
|
|
float3( 0, 1, 0 ),
|
|
std::lerp( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveL * isactive ) );
|
|
}
|
|
|
|
// wipers
|
|
void TDynamicObject::UpdateWiper(TAnim* pAnim)
|
|
{
|
|
if (!pAnim || !pAnim->smElement)
|
|
return;
|
|
|
|
int i = pAnim->iNumber;
|
|
// odwaramy animacje dla parzystych indexow
|
|
const double rotateAngle = (i + 1) % 2 == 0 ? -MoverParameters->WiperAngle : MoverParameters->WiperAngle;
|
|
|
|
if (pAnim->smElement[0]) // ramie 1
|
|
pAnim->smElement[0]->SetRotate(float3(0, 1, 0), smoothInterpolate(0.0, rotateAngle, dWiperPos[i]));
|
|
if (pAnim->smElement[1]) // ramie 2
|
|
pAnim->smElement[1]->SetRotate(float3(0, 1, 0), smoothInterpolate(0.0, rotateAngle, dWiperPos[i]));
|
|
if (pAnim->smElement[2]) // pioro
|
|
pAnim->smElement[2]->SetRotate(float3(0, 1, 0), smoothInterpolate(0.0, -rotateAngle, dWiperPos[i]));
|
|
}
|
|
|
|
/*
|
|
void TDynamicObject::UpdateLeverDouble(TAnim *pAnim)
|
|
{ // animacja gałki zależna od double
|
|
pAnim->smAnimated->SetRotate(float3(1, 0, 0), pAnim->fSpeed * *pAnim->fDoubleBase);
|
|
};
|
|
void TDynamicObject::UpdateLeverFloat(TAnim *pAnim)
|
|
{ // animacja gałki zależna od float
|
|
pAnim->smAnimated->SetRotate(float3(1, 0, 0), pAnim->fSpeed * *pAnim->fFloatBase);
|
|
};
|
|
void TDynamicObject::UpdateLeverInt(TAnim *pAnim)
|
|
{ // animacja gałki zależna od int
|
|
pAnim->smAnimated->SetRotate(float3(1, 0, 0), pAnim->fSpeed * *pAnim->iIntBase);
|
|
};
|
|
void TDynamicObject::UpdateLeverEnum(TAnim *pAnim)
|
|
{ // ustawienie kąta na
|
|
// wartość wskazaną przez
|
|
// int z tablicy fParam
|
|
// pAnim->fParam[0]; - dodać lepkość
|
|
pAnim->smAnimated->SetRotate(float3(1, 0, 0), pAnim->fParam[*pAnim->iIntBase]);
|
|
};
|
|
*/
|
|
// sets light levels for registered interior sections
|
|
void
|
|
TDynamicObject::toggle_lights() {
|
|
|
|
if( true == SectionLightsActive ) {
|
|
// switch all lights off...
|
|
for( auto §ion : Sections ) {
|
|
auto const sectionname { section.compartment->pName };
|
|
if( sectionname.rfind( "cab", 0 ) != 0 ) {
|
|
section.light_level = 0.0;
|
|
}
|
|
}
|
|
SectionLightsActive = false;
|
|
}
|
|
else {
|
|
// set lights with probability depending on the compartment type. TODO: expose this in .mmd file
|
|
for( auto §ion : Sections ) {
|
|
|
|
auto const sectionname { section.compartment->pName };
|
|
if( sectionname.find("corridor") == 0
|
|
|| sectionname.find("korytarz") == 0 ) {
|
|
// corridors are lit 100% of time
|
|
section.light_level = 0.75f;
|
|
}
|
|
else if(
|
|
sectionname.find("compartment") == 0
|
|
|| sectionname.find("przedzial") == 0 ) {
|
|
// compartments are lit with 75% probability
|
|
section.light_level = Random() < 0.75 ? 0.75f : 0.10f;
|
|
}
|
|
}
|
|
SectionLightsActive = true;
|
|
}
|
|
}
|
|
|
|
void
|
|
TDynamicObject::set_cab_lights( int const Cab, float const Level ) {
|
|
|
|
for( auto §ion : Sections ) {
|
|
// cab compartments are placed at the beginning of the list, so we can bail out as soon as we find different compartment type
|
|
auto const sectionname { section.compartment->pName };
|
|
if( sectionname.size() < 4 ) { return; }
|
|
if( sectionname.find( "cab" ) != 0 ) { return; }
|
|
if( sectionname[ 3 ] != Cab + '0' ) { continue; } // match the cab with correct index
|
|
|
|
section.light_level = Level;
|
|
}
|
|
}
|
|
|
|
// aktualizujemy submodele w zaleznosci od aktualnej pory roku
|
|
void TDynamicObject::on_season_update()
|
|
{
|
|
if (sm_winter_variant != nullptr) // pokazujemy wariant zimowy
|
|
sm_winter_variant->SetVisibilityLevel(Global.Season == "winter:" ? 1 : 0, true, false);
|
|
if (sm_spring_variant != nullptr) // pokazujemy wariant wiosenny
|
|
sm_spring_variant->SetVisibilityLevel(Global.Season == "spring:" ? 1 : 0, true, false);
|
|
if (sm_summer_variant != nullptr) // pokazujemy wariant letni
|
|
sm_summer_variant->SetVisibilityLevel(Global.Season == "summer:" ? 1 : 0, true, false);
|
|
if (sm_autumn_variant != nullptr) // pokazujemy wariant jesienny
|
|
sm_autumn_variant->SetVisibilityLevel(Global.Season == "autumn:" ? 1 : 0, true, false);
|
|
}
|
|
|
|
// ABu 29.01.05 przeklejone z render i renderalpha: *********************
|
|
void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
|
|
{ // ABu290105: pozbierane i uporzadkowane powtarzajace
|
|
// sie rzeczy z Render i RenderAlpha
|
|
// dodatkowy warunek, if (ObjSqrDist<...) zeby niepotrzebnie nie zmianiec w
|
|
// obiektach,
|
|
// ktorych i tak nie widac
|
|
// NBMX wrzesien, MC listopad: zuniwersalnione
|
|
btnOn = false; // czy przywrócić stan domyślny po renderowaniu
|
|
|
|
if (mdLoad) // tymczasowo ładunek na poziom podłogi
|
|
if (vFloor.z > 0.0)
|
|
mdLoad->GetSMRoot()->SetTranslate(modelShake + vFloor);
|
|
|
|
// model jest współdzielony przez pojazdy, a pora roku może się zmienić w trakcie symulacji
|
|
if (Global.UpdateMaterials)
|
|
on_season_update();
|
|
|
|
if (ObjSqrDist < 400 * 400 ) // gdy bliżej niż 400m
|
|
{
|
|
for( auto &animation : pAnimations ) {
|
|
// wykonanie kolejnych animacji
|
|
if( ObjSqrDist < animation.fMaxDist
|
|
&& animation.yUpdate ) {
|
|
// jeśli zdefiniowana funkcja aktualizacja animacji (położenia submodeli
|
|
animation.yUpdate( &animation );
|
|
}
|
|
}
|
|
update_slottedlevers();
|
|
|
|
if( mdModel != nullptr
|
|
&& ObjSqrDist < 50 * 50 ) {
|
|
// gdy bliżej niż 50m
|
|
// ABu290105: rzucanie pudlem
|
|
// te animacje wymagają bananów w modelach!
|
|
mdModel->GetSMRoot()->SetTranslate(modelShake);
|
|
if (mdKabina)
|
|
mdKabina->GetSMRoot()->SetTranslate(modelShake);
|
|
if (mdLoad)
|
|
mdLoad->GetSMRoot()->SetTranslate(modelShake + vFloor);
|
|
if (mdLowPolyInt)
|
|
mdLowPolyInt->GetSMRoot()->SetTranslate(modelShake);
|
|
// ABu: koniec rzucania
|
|
// ABu011104: liczenie obrotow wozkow
|
|
ABuBogies();
|
|
// Mczapkie-100402: rysowanie lub nie - sprzegow
|
|
// ABu-240105: Dodatkowy warunek: if (...).Render, zeby rysowal tylko jeden z polaczonych sprzegow
|
|
// display _on if connected with another vehicle and the coupling owner (render flag)
|
|
// display _xon if connected with another vehicle and not the coupling owner
|
|
// display _xon if not connected, but equipped with coupling adapter
|
|
// display _off if not connected, not equipped with coupling adapter or if _xon model is missing
|
|
if( TestFlag( MoverParameters->Couplers[ end::front ].CouplingFlag, coupling::coupler ) ) {
|
|
if( MoverParameters->Couplers[ end::front ].Render ) {
|
|
btCoupler1.TurnOn();
|
|
}
|
|
else {
|
|
btCoupler1.TurnxOnWithOffAsFallback();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
else {
|
|
if( true == MoverParameters->Couplers[ end::front ].has_adapter() ) {
|
|
btCoupler1.TurnxOnWithOffAsFallback();
|
|
btnOn = true;
|
|
}
|
|
}
|
|
if( TestFlag( MoverParameters->Couplers[ end::rear ].CouplingFlag, coupling::coupler ) ) {
|
|
if( MoverParameters->Couplers[ end::rear ].Render ) {
|
|
btCoupler2.TurnOn();
|
|
}
|
|
else {
|
|
btCoupler2.TurnxOnWithOffAsFallback();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
else {
|
|
if( true == MoverParameters->Couplers[ end::rear ].has_adapter() ) {
|
|
btCoupler2.TurnxOnWithOffAsFallback();
|
|
btnOn = true;
|
|
}
|
|
}
|
|
//********************************************************************************
|
|
// przewody powietrzne j.w., ABu: decyzja czy rysowac tylko na podstawie
|
|
// 'render' - juz
|
|
// nie
|
|
// przewody powietrzne, yB: decyzja na podstawie polaczen w t3d
|
|
if (Global.bnewAirCouplers)
|
|
{
|
|
SetPneumatic(false, false); // wczytywanie z t3d ulozenia wezykow
|
|
SetPneumatic(true, false); // i zapisywanie do zmiennej
|
|
SetPneumatic(true, true); // ktore z nich nalezy
|
|
SetPneumatic(false, true); // wyswietlic w tej klatce
|
|
|
|
if (TestFlag(MoverParameters->Couplers[end::front].CouplingFlag, ctrain_pneumatic))
|
|
{
|
|
switch (cp1)
|
|
{
|
|
case 1:
|
|
btCPneumatic1.TurnOn();
|
|
break;
|
|
case 2:
|
|
btCPneumatic1.TurnxOn();
|
|
break;
|
|
case 3:
|
|
btCPneumatic1r.TurnxOn();
|
|
break;
|
|
case 4:
|
|
btCPneumatic1r.TurnOn();
|
|
break;
|
|
}
|
|
btnOn = true;
|
|
}
|
|
|
|
if (TestFlag(MoverParameters->Couplers[end::rear].CouplingFlag, ctrain_pneumatic))
|
|
{
|
|
switch (cp2)
|
|
{
|
|
case 1:
|
|
btCPneumatic2.TurnOn();
|
|
break;
|
|
case 2:
|
|
btCPneumatic2.TurnxOn();
|
|
break;
|
|
case 3:
|
|
btCPneumatic2r.TurnxOn();
|
|
break;
|
|
case 4:
|
|
btCPneumatic2r.TurnOn();
|
|
break;
|
|
}
|
|
btnOn = true;
|
|
}
|
|
|
|
// przewody zasilajace, j.w. (yB)
|
|
if (TestFlag(MoverParameters->Couplers[end::front].CouplingFlag, ctrain_scndpneumatic))
|
|
{
|
|
switch (sp1)
|
|
{
|
|
case 1:
|
|
btPneumatic1.TurnOn();
|
|
break;
|
|
case 2:
|
|
btPneumatic1.TurnxOn();
|
|
break;
|
|
case 3:
|
|
btPneumatic1r.TurnxOn();
|
|
break;
|
|
case 4:
|
|
btPneumatic1r.TurnOn();
|
|
break;
|
|
}
|
|
btnOn = true;
|
|
}
|
|
|
|
if (TestFlag(MoverParameters->Couplers[end::rear].CouplingFlag, ctrain_scndpneumatic))
|
|
{
|
|
switch (sp2)
|
|
{
|
|
case 1:
|
|
btPneumatic2.TurnOn();
|
|
break;
|
|
case 2:
|
|
btPneumatic2.TurnxOn();
|
|
break;
|
|
case 3:
|
|
btPneumatic2r.TurnxOn();
|
|
break;
|
|
case 4:
|
|
btPneumatic2r.TurnOn();
|
|
break;
|
|
}
|
|
btnOn = true;
|
|
}
|
|
}
|
|
//*********************************************************************************/
|
|
else // po staremu ABu'oewmu
|
|
{
|
|
// przewody powietrzne j.w., ABu: decyzja czy rysowac tylko na podstawie
|
|
// 'render'
|
|
if (TestFlag(MoverParameters->Couplers[end::front].CouplingFlag, ctrain_pneumatic))
|
|
{
|
|
if (MoverParameters->Couplers[end::front].Render)
|
|
btCPneumatic1.TurnOn();
|
|
else
|
|
btCPneumatic1r.TurnOn();
|
|
btnOn = true;
|
|
}
|
|
|
|
if (TestFlag(MoverParameters->Couplers[end::rear].CouplingFlag, ctrain_pneumatic))
|
|
{
|
|
if (MoverParameters->Couplers[end::rear].Render)
|
|
btCPneumatic2.TurnOn();
|
|
else
|
|
btCPneumatic2r.TurnOn();
|
|
btnOn = true;
|
|
}
|
|
|
|
// przewody powietrzne j.w., ABu: decyzja czy rysowac tylko na podstawie
|
|
// 'render'
|
|
// //yB - zasilajace
|
|
if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_scndpneumatic))
|
|
{
|
|
if (MoverParameters->Couplers[0].Render)
|
|
btPneumatic1.TurnOn();
|
|
else
|
|
btPneumatic1r.TurnOn();
|
|
btnOn = true;
|
|
}
|
|
|
|
if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_scndpneumatic))
|
|
{
|
|
if (MoverParameters->Couplers[1].Render)
|
|
btPneumatic2.TurnOn();
|
|
else
|
|
btPneumatic2r.TurnOn();
|
|
btnOn = true;
|
|
}
|
|
}
|
|
//*************************************************************/// koniec
|
|
// wezykow
|
|
// uginanie zderzakow
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
if( MoverParameters->Couplers[ i ].has_adapter() ) {
|
|
// HACK: if there's coupler adapter on this side, we presume there's additional distance put between vehicles
|
|
// which prevents buffers from clashing against each other (or the other vehicle doesn't have buffers to begin with)
|
|
continue;
|
|
}
|
|
|
|
auto const dist { std::clamp( MoverParameters->Couplers[ i ].Dist / 2.0, -MoverParameters->Couplers[ i ].DmaxB, 0.0 ) };
|
|
|
|
if( dist >= 0.0 ) { continue; }
|
|
|
|
if( smBuforLewy[ i ] ) {
|
|
smBuforLewy[ i ]->SetTranslate( glm::vec3( dist, 0, 0 ) );
|
|
}
|
|
if( smBuforPrawy[ i ] ) {
|
|
smBuforPrawy[ i ]->SetTranslate( glm::vec3( dist, 0, 0 ) );
|
|
}
|
|
}
|
|
} // vehicle within 50m
|
|
|
|
// Winger 160204 - podnoszenie pantografow
|
|
|
|
// przewody sterowania ukrotnionego
|
|
if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, coupling::control))
|
|
{
|
|
btCCtrl1.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
// else btCCtrl1.TurnOff();
|
|
if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, coupling::control))
|
|
{
|
|
btCCtrl2.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
// else btCCtrl2.TurnOff();
|
|
// McZapkie-181103: mostki przejsciowe
|
|
if (TestFlag(MoverParameters->Couplers[0].CouplingFlag, ctrain_passenger))
|
|
{
|
|
btCPass1.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
// else btCPass1.TurnOff();
|
|
if (TestFlag(MoverParameters->Couplers[1].CouplingFlag, ctrain_passenger))
|
|
{
|
|
btCPass2.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
// else btCPass2.TurnOff();
|
|
if (MoverParameters->Power24vIsAvailable || MoverParameters->Power110vIsAvailable)
|
|
{ // sygnaly konca pociagu
|
|
if (m_endsignals1.Active()) {
|
|
if (TestFlag(MoverParameters->iLights[end::front], light::redmarker_left | light::redmarker_right ) ) {
|
|
m_endsignals1.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
}
|
|
else {
|
|
if (TestFlag(MoverParameters->iLights[end::front], light::redmarker_left) && !HeadlightsAoff)
|
|
{
|
|
m_endsignal13.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
if (TestFlag(MoverParameters->iLights[end::front], light::redmarker_right) && !HeadlightsAoff)
|
|
{
|
|
m_endsignal12.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
}
|
|
if (m_endsignals2.Active()) {
|
|
if (TestFlag(MoverParameters->iLights[end::rear], light::redmarker_left | light::redmarker_right ) ) {
|
|
m_endsignals2.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
}
|
|
else {
|
|
if (TestFlag(MoverParameters->iLights[end::rear], light::redmarker_left) && !HeadlightsBoff)
|
|
{
|
|
m_endsignal23.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
if (TestFlag(MoverParameters->iLights[end::rear], light::redmarker_right) && !HeadlightsBoff)
|
|
{
|
|
m_endsignal22.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
}
|
|
}
|
|
// tablice blaszane:
|
|
if (TestFlag(MoverParameters->iLights[end::front], light::rearendsignals)) {
|
|
m_endtab1.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
// else btEndSignalsTab1.TurnOff();
|
|
if (TestFlag(MoverParameters->iLights[end::rear], light::rearendsignals)) {
|
|
m_endtab2.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
// destination signs
|
|
update_destinations();
|
|
// else btEndSignalsTab2.TurnOff();
|
|
// McZapkie-181002: krecenie wahaczem (korzysta z kata obrotu silnika)
|
|
if (iAnimType[ANIM_LEVERS])
|
|
for (int i = 0; i < 4; ++i)
|
|
if (smWahacze[i])
|
|
smWahacze[i]->SetRotate(float3(1, 0, 0),
|
|
fWahaczeAmp * cos(MoverParameters->eAngle));
|
|
|
|
// cooling shutters
|
|
// NOTE: shutters display _on state when they're closed, _off otherwise
|
|
if( true == MoverParameters->dizel_heat.water.config.shutters
|
|
&& false == MoverParameters->dizel_heat.zaluzje1 ) {
|
|
btShutters1.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
if( true == MoverParameters->dizel_heat.water_aux.config.shutters
|
|
&& false == MoverParameters->dizel_heat.zaluzje2 ) {
|
|
btShutters2.Turn( true );
|
|
btnOn = true;
|
|
}
|
|
|
|
// only external models ( external_only_on / external_only_off )
|
|
btExteriorOnly.Turn(!bDisplayCab); // display only when cab is not rendered
|
|
|
|
if( false == bDisplayCab // edge case, lowpoly may act as a stand-in for the hi-fi cab, so make sure not to show the driver when inside
|
|
&& Mechanik != nullptr
|
|
&& Mechanik->action() != TAction::actSleep ) {
|
|
// rysowanie figurki mechanika
|
|
btMechanik1.Turn(MoverParameters->CabOccupied > 0);
|
|
btMechanik2.Turn( MoverParameters->CabOccupied < 0 );
|
|
if( MoverParameters->CabOccupied != 0 ) {
|
|
btnOn = true;
|
|
}
|
|
}
|
|
|
|
} // vehicle within 400m
|
|
|
|
if( MoverParameters->Power24vIsAvailable || MoverParameters->Power110vIsAvailable )
|
|
{ // sygnały czoła pociagu //Ra: wyświetlamy bez
|
|
// ograniczeń odległości, by były widoczne z
|
|
// daleka
|
|
|
|
if (TestFlag(MoverParameters->iLights[end::front], light::headlight_left)
|
|
&& !HeadlightsAoff && !HighBeamLights)
|
|
{
|
|
if( DimHeadlights ) {
|
|
m_headlamp13.TurnxOnWithOnAsFallback();
|
|
}
|
|
else {
|
|
m_headlamp13.TurnOn();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
if (TestFlag(MoverParameters->iLights[end::front], light::headlight_upper)
|
|
&& !HeadlightsAoff)
|
|
{
|
|
if( DimHeadlights ) {
|
|
m_headlamp11.TurnxOnWithOnAsFallback();
|
|
}
|
|
else {
|
|
m_headlamp11.TurnOn();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
if (TestFlag(MoverParameters->iLights[end::front], light::headlight_right)
|
|
&& !HeadlightsAoff && !HighBeamLights)
|
|
{
|
|
if( DimHeadlights ) {
|
|
m_headlamp12.TurnxOnWithOnAsFallback();
|
|
}
|
|
else {
|
|
m_headlamp12.TurnOn();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
// else btHeadSignals13.TurnOff();
|
|
if (TestFlag(MoverParameters->iLights[end::rear], light::headlight_left)
|
|
&& !HeadlightsBoff && !HighBeamLights)
|
|
{
|
|
if( DimHeadlights ) {
|
|
m_headlamp23.TurnxOnWithOnAsFallback();
|
|
}
|
|
else {
|
|
m_headlamp23.TurnOn();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
if (TestFlag(MoverParameters->iLights[end::rear], light::headlight_upper)
|
|
&& !HeadlightsBoff)
|
|
{
|
|
if( DimHeadlights ) {
|
|
m_headlamp21.TurnxOnWithOnAsFallback();
|
|
}
|
|
else {
|
|
m_headlamp21.TurnOn();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
if (TestFlag(MoverParameters->iLights[end::rear], light::headlight_right)
|
|
&& !HeadlightsBoff && !HighBeamLights)
|
|
{
|
|
if( DimHeadlights ) {
|
|
m_headlamp22.TurnxOnWithOnAsFallback();
|
|
}
|
|
else {
|
|
m_headlamp22.TurnOn();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
// auxiliary lights
|
|
if (TestFlag(MoverParameters->iLights[end::front], light::auxiliary_left) && !HeadlightsAoff)
|
|
{
|
|
if( DimHeadlights ) {
|
|
m_headsignal13.TurnxOnWithOnAsFallback();
|
|
}
|
|
else {
|
|
m_headsignal13.TurnOn();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
if (TestFlag(MoverParameters->iLights[end::front], light::auxiliary_right) && !HeadlightsAoff)
|
|
{
|
|
if( DimHeadlights ) {
|
|
m_headsignal12.TurnxOnWithOnAsFallback();
|
|
}
|
|
else {
|
|
m_headsignal12.TurnOn();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
if (TestFlag(MoverParameters->iLights[end::rear], light::auxiliary_left) && !HeadlightsBoff)
|
|
{
|
|
if( DimHeadlights ) {
|
|
m_headsignal23.TurnxOnWithOnAsFallback();
|
|
}
|
|
else {
|
|
m_headsignal23.TurnOn();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
if (TestFlag(MoverParameters->iLights[end::rear], light::auxiliary_right) && !HeadlightsBoff)
|
|
{
|
|
if( DimHeadlights ) {
|
|
m_headsignal22.TurnxOnWithOnAsFallback();
|
|
}
|
|
else {
|
|
m_headsignal22.TurnOn();
|
|
}
|
|
btnOn = true;
|
|
}
|
|
|
|
// logika dlugich
|
|
if (TestFlag(MoverParameters->iLights[end::front], light::headlight_left)
|
|
&& !HeadlightsAoff && HighBeamLights)
|
|
m_highbeam13.TurnxOnWithOnAsFallback();
|
|
else
|
|
m_highbeam13.TurnOff();
|
|
|
|
if (TestFlag(MoverParameters->iLights[end::front], light::headlight_right)
|
|
&& !HeadlightsAoff && HighBeamLights)
|
|
m_highbeam12.TurnxOnWithOnAsFallback();
|
|
else
|
|
m_highbeam12.TurnOff();
|
|
|
|
// i to samo od dupy strony
|
|
if (TestFlag(MoverParameters->iLights[end::rear], light::headlight_left)
|
|
&& !HeadlightsBoff && HighBeamLights)
|
|
m_highbeam23.TurnxOnWithOnAsFallback();
|
|
else
|
|
m_highbeam23.TurnOff();
|
|
|
|
if (TestFlag(MoverParameters->iLights[end::rear], light::headlight_right)
|
|
&& !HeadlightsBoff && HighBeamLights)
|
|
m_highbeam22.TurnxOnWithOnAsFallback();
|
|
else
|
|
m_highbeam22.TurnOff();
|
|
}
|
|
// interior light levels
|
|
auto sectionlightcolor { glm::vec4( 1.f ) };
|
|
bool cabsection{ true };
|
|
for( auto const §ion : Sections ) {
|
|
if( cabsection ) {
|
|
// check whether we're still processing cab sections
|
|
auto const §ionname { section.compartment->pName };
|
|
cabsection &= sectionname.size() >= 4 && sectionname.starts_with("cab");
|
|
}
|
|
// TODO: add cablight devices
|
|
auto const sectionlightlevel { section.light_level * ( cabsection ? 1.0f : MoverParameters->CompartmentLights.intensity ) };
|
|
sectionlightcolor = glm::vec4(
|
|
sectionlightlevel == 0.f || Global.fLuminance > section.compartment->fLight ?
|
|
glm::vec3(240.f / 255.f) : // TBD: save and restore initial submodel diffuse instead of enforcing one?
|
|
InteriorLight, // TODO: per-compartment (type) light color
|
|
sectionlightlevel );
|
|
section.compartment->SetLightLevel( sectionlightcolor, true );
|
|
if( section.load != nullptr ) {
|
|
section.load->SetLightLevel( sectionlightcolor, true );
|
|
}
|
|
}
|
|
// load chunks visibility
|
|
for( auto const §ion : Sections ) {
|
|
// section isn't guaranteed to have load model, so check that first
|
|
if( section.load == nullptr ) { continue; }
|
|
section.load->iVisible = section.load_chunks_visible > 0;
|
|
// if the section root isn't visible we can skip meddling with its children
|
|
if( false == section.load->iVisible ) { continue; }
|
|
// if the section root is visible set the state of section chunks
|
|
auto *sectionchunk { section.load->ChildGet() };
|
|
auto visiblechunkcount { section.load_chunks_visible };
|
|
while( sectionchunk != nullptr ) {
|
|
sectionchunk->iVisible = visiblechunkcount > 0;
|
|
--visiblechunkcount;
|
|
sectionchunk = sectionchunk->NextGet();
|
|
}
|
|
}
|
|
|
|
// driver cabs visibility
|
|
for( int cabidx = 0; cabidx < LowPolyIntCabs.size(); ++cabidx ) {
|
|
if( LowPolyIntCabs[ cabidx ] == nullptr ) { continue; }
|
|
LowPolyIntCabs[ cabidx ]->iVisible = mdKabina == nullptr ? true : // there's no hi-fi cab
|
|
bDisplayCab == false ? true : // we're in external view
|
|
simulation::Train == nullptr ? true : // not a player-driven vehicle, implies external view
|
|
simulation::Train->Dynamic() != this ? true : // not a player-driven vehicle, implies external view
|
|
JointCabs ? false : // internal view, all cabs share the model so hide them 'all'
|
|
simulation::Train->iCabn != cabidx; // internal view, hide occupied cab and show others
|
|
}
|
|
}
|
|
// ABu 29.01.05 koniec przeklejenia *************************************
|
|
|
|
TDynamicObject * TDynamicObject::ABuFindNearestObject(glm::vec3 pos, TTrack *Track, TDynamicObject *MyPointer, int &CouplNr)
|
|
{
|
|
// zwraca wskaznik do obiektu znajdujacego sie na torze (Track), którego sprzęg jest najblizszy punktowi
|
|
// służy np. do łączenia i rozpinania sprzęgów
|
|
// WE: Track - tor, na ktorym odbywa sie poszukiwanie
|
|
// MyPointer - wskaznik do obiektu szukajacego
|
|
// WY: CouplNr - który sprzęg znalezionego obiektu jest bliższy kamerze
|
|
|
|
// Uwaga! Jesli CouplNr==-2 to szukamy njblizszego obiektu, a nie sprzegu!!!
|
|
for( auto dynamic : Track->Dynamics ) {
|
|
|
|
if( CouplNr == -2 ) {
|
|
// wektor [kamera-obiekt] - poszukiwanie obiektu
|
|
// length2 is better than length for comparing because it does not require sqrt function
|
|
if (glm::length2(glm::dvec3(pos) - dynamic->vPosition) < sq(10.0))
|
|
{
|
|
// 10 metrów
|
|
return dynamic;
|
|
}
|
|
}
|
|
else {
|
|
// jeśli (CouplNr) inne niz -2, szukamy sprzęgu
|
|
// length2 is better than length for comparing because it does not require sqrt function
|
|
if (glm::length2(glm::dvec3(pos) - dynamic->vCoulpler[0]) < sq(5.0)) {
|
|
// 5 metrów
|
|
CouplNr = 0;
|
|
return dynamic;
|
|
}
|
|
// length2 is better than length for comparing because it does not require sqrt function
|
|
if (glm::length2(glm::dvec3(pos) - dynamic->vCoulpler[1]) < sq(5.0)) {
|
|
// 5 metrów
|
|
CouplNr = 1;
|
|
return dynamic;
|
|
}
|
|
}
|
|
}
|
|
// empty track or nothing found
|
|
return nullptr;
|
|
}
|
|
|
|
TDynamicObject * TDynamicObject::ABuScanNearestObject(glm::vec3 pos, TTrack *Track, double ScanDir, double ScanDist, int &CouplNr)
|
|
{ // skanowanie toru w poszukiwaniu obiektu najblizszego punktowi
|
|
if (ABuGetDirection() < 0)
|
|
ScanDir = -ScanDir;
|
|
TDynamicObject *FoundedObj;
|
|
FoundedObj =
|
|
ABuFindNearestObject(pos, Track, this, CouplNr); // zwraca numer sprzęgu znalezionego pojazdu
|
|
if (FoundedObj == nullptr && Track != nullptr)
|
|
{
|
|
double ActDist; // Przeskanowana odleglosc.
|
|
double CurrDist = 0; // Aktualna dlugosc toru.
|
|
if (ScanDir >= 0)
|
|
ActDist =
|
|
Track->Length() - RaTranslationGet(); //???-przesunięcie wózka względem Point1 toru
|
|
else
|
|
ActDist = RaTranslationGet(); // przesunięcie wózka względem Point1 toru
|
|
while (ActDist < ScanDist)
|
|
{
|
|
ActDist += CurrDist;
|
|
if (ScanDir > 0) // do przodu
|
|
{
|
|
if (Track->iNextDirection) // NOSONAR
|
|
{
|
|
Track = Track->CurrentNext();
|
|
ScanDir = -ScanDir;
|
|
}
|
|
else
|
|
Track = Track->CurrentNext();
|
|
}
|
|
else // do tyłu
|
|
{
|
|
if (Track->iPrevDirection) // NOSONAR
|
|
Track = Track->CurrentPrev();
|
|
else
|
|
{
|
|
Track = Track->CurrentPrev();
|
|
ScanDir = -ScanDir;
|
|
}
|
|
}
|
|
if (Track != nullptr)
|
|
{ // jesli jest kolejny odcinek toru
|
|
CurrDist = Track->Length();
|
|
FoundedObj = ABuFindNearestObject(pos, Track, this, CouplNr);
|
|
if (FoundedObj != nullptr)
|
|
ActDist = ScanDist;
|
|
}
|
|
else // Jesli nie ma, to wychodzimy.
|
|
break;
|
|
}
|
|
} // Koniec szukania najblizszego toru z jakims obiektem.
|
|
return FoundedObj;
|
|
}
|
|
|
|
// ABu 01.11.04 poczatek wyliczania przechylow pudla **********************
|
|
void TDynamicObject::ABuModelRoll()
|
|
{ // ustawienie przechyłki pojazdu i jego
|
|
// zawartości
|
|
// Ra: przechyłkę załatwiamy na etapie przesuwania modelu
|
|
}
|
|
|
|
// ABu 06.05.04 poczatek wyliczania obrotow wozkow **********************
|
|
|
|
void TDynamicObject::ABuBogies()
|
|
{ // Obracanie wozkow na zakretach. Na razie
|
|
// uwzględnia tylko zakręty,
|
|
// bez zadnych gorek i innych przeszkod.
|
|
if (smBogie[0] != nullptr && smBogie[1] != nullptr)
|
|
{
|
|
// modelRot.z=ABuAcos(Axle0.pPosition-Axle1.pPosition); //kąt obrotu pojazdu
|
|
// [rad]
|
|
// bogieRot[0].z=ABuAcos(Axle0.pPosition-Axle3.pPosition);
|
|
bogieRot[0].z = Axle0.vAngles.z;
|
|
bogieRot[0] = glm::degrees(modelRot - bogieRot[0]); // mnożenie wektora przez stałą
|
|
smBogie[0]->SetRotateXYZ(bogieRot[0]);
|
|
// bogieRot[1].z=ABuAcos(Axle2.pPosition-Axle1.pPosition);
|
|
bogieRot[1].z = Axle1.vAngles.z;
|
|
bogieRot[1] = glm::degrees(modelRot - bogieRot[1]);
|
|
smBogie[1]->SetRotateXYZ(bogieRot[1]);
|
|
}
|
|
};
|
|
// ABu 06.05.04 koniec wyliczania obrotow wozkow ************************
|
|
|
|
// ABu 16.03.03 sledzenie toru przed obiektem: **************************
|
|
void TDynamicObject::ABuCheckMyTrack()
|
|
{ // Funkcja przypisujaca obiekt
|
|
// prawidlowej tablicy Dynamics,
|
|
// bo gdzies jest jakis blad i wszystkie obiekty z danego
|
|
// pociagu na poczatku stawiane sa na jednym torze i wpisywane
|
|
// do jednej tablicy. Wykonuje sie tylko raz - po to 'ABuChecked'
|
|
TTrack *OldTrack = MyTrack;
|
|
TTrack *NewTrack = Axle0.GetTrack();
|
|
if( NewTrack != OldTrack ) {
|
|
if( OldTrack ) {
|
|
OldTrack->RemoveDynamicObject( this );
|
|
}
|
|
NewTrack->AddDynamicObject(this);
|
|
}
|
|
iAxleFirst = 0; // pojazd powiązany z przednią osią - Axle0
|
|
}
|
|
|
|
// Ra: w poniższej funkcji jest problem ze sprzęgami
|
|
TDynamicObject *
|
|
TDynamicObject::ABuFindObject( int &Foundcoupler, double &Distance, TTrack const *Track, int const Direction, int const Mycoupler ) const
|
|
{ // Zwraca wskaźnik najbliższego obiektu znajdującego się
|
|
// na torze w określonym kierunku, ale tylko wtedy, kiedy
|
|
// obiekty mogą się zderzyć, tzn. nie mijają się.
|
|
// WE:
|
|
// Track - tor, na ktorym odbywa sie poszukiwanie,
|
|
// Direction - kierunek szukania na torze (+1:w stronę Point2, -1:w stronę Point1)
|
|
// Mycoupler - nr sprzegu obiektu szukajacego;
|
|
// WY:
|
|
// wskaznik do znalezionego obiektu.
|
|
// Foundcoupler - nr sprzegu znalezionego obiektu
|
|
// Distance - distance to found object
|
|
|
|
if( true == Track->Dynamics.empty() ) {
|
|
// sens szukania na tym torze jest tylko, gdy są na nim pojazdy
|
|
Distance += Track->Length(); // doliczenie długości odcinka do przeskanowanej odległości
|
|
return nullptr; // nie ma pojazdów na torze, to jest NULL
|
|
}
|
|
|
|
double distance = Track->Length(); // najmniejsza znaleziona odleglość (zaczynamy od długości toru)
|
|
double myposition; // pozycja szukającego na torze
|
|
TDynamicObject *foundobject = nullptr;
|
|
if( MyTrack == Track ) {
|
|
// gdy szukanie na tym samym torze
|
|
myposition = RaTranslationGet(); // położenie wózka względem Point1 toru
|
|
}
|
|
else {
|
|
// gdy szukanie na innym torze
|
|
if( Direction > 0 ) {
|
|
// szukanie w kierunku Point2 (od zera) - jesteśmy w Point1
|
|
myposition = 0;
|
|
}
|
|
else {
|
|
// szukanie w kierunku Point1 (do zera) - jesteśmy w Point2
|
|
myposition = distance;
|
|
}
|
|
}
|
|
|
|
double objectposition; // robocza odległość od kolejnych pojazdów na danym odcinku
|
|
for( auto dynamic : Track->Dynamics ) {
|
|
|
|
if( dynamic == this ) { continue; } // szukający się nie liczy
|
|
/*
|
|
if( ( ( dynamic == PrevConnected ) && ( MoverParameters->Couplers[ TMoverParameters::side::front ].CouplingFlag != coupling::faux ) )
|
|
|| ( ( dynamic == NextConnected ) && ( MoverParameters->Couplers[ TMoverParameters::side::rear ].CouplingFlag != coupling::faux ) ) ){
|
|
// stop-gap check to prevent 'detection' of attached vehicles
|
|
// which seems to be a side-effect of inaccurate location calculation in 'simple' mode?
|
|
// TODO: investigate actual cause
|
|
continue;
|
|
}
|
|
*/
|
|
if( Direction > 0 ) {
|
|
// jeśli szukanie w kierunku Point2
|
|
objectposition = dynamic->RaTranslationGet() - myposition; // odległogłość tamtego od szukającego
|
|
if( objectposition > 0
|
|
&& objectposition < distance ) {
|
|
// gdy jest po właściwej stronie i bliżej niż jakiś wcześniejszy
|
|
Foundcoupler = dynamic->RaDirectionGet() > 0 ? 1 : 0; // to, bo (ScanDir>=0)
|
|
}
|
|
else { continue; }
|
|
}
|
|
else {
|
|
objectposition = myposition - dynamic->RaTranslationGet(); //???-przesunięcie wózka względem Point1 toru
|
|
if( objectposition > 0
|
|
&& objectposition < distance ) {
|
|
Foundcoupler = dynamic->RaDirectionGet() > 0 ? 0 : 1; // odwrotnie, bo (ScanDir<0)
|
|
}
|
|
else { continue; }
|
|
}
|
|
|
|
if( Track->iCategoryFlag & 254 ) {
|
|
// trajektoria innego typu niż tor kolejowy
|
|
// dla torów nie ma sensu tego sprawdzać, rzadko co jedzie po jednej szynie i się mija
|
|
// Ra: mijanie samochodów wcale nie jest proste
|
|
// Przesuniecie wzgledne pojazdow. Wyznaczane, zeby sprawdzic,
|
|
// czy pojazdy faktycznie sie zderzaja (moga byc przesuniete
|
|
// w/m siebie tak, ze nie zachodza na siebie i wtedy sie mijaja).
|
|
double relativeoffset; // wzajemna odległość poprzeczna
|
|
if( Foundcoupler != Mycoupler ) {
|
|
// facing the same direction
|
|
relativeoffset = std::abs( MoverParameters->OffsetTrackH - dynamic->MoverParameters->OffsetTrackH );
|
|
}
|
|
else {
|
|
relativeoffset = std::abs( MoverParameters->OffsetTrackH + dynamic->MoverParameters->OffsetTrackH );
|
|
}
|
|
if( relativeoffset + relativeoffset > MoverParameters->Dim.W + dynamic->MoverParameters->Dim.W ) {
|
|
// odległość większa od połowy sumy szerokości - kolizji nie będzie
|
|
continue;
|
|
}
|
|
// jeśli zahaczenie jest niewielkie, a jest miejsce na poboczu, to zjechać na pobocze
|
|
}
|
|
foundobject = dynamic; // potencjalna kolizja
|
|
distance = objectposition; // odleglość pomiędzy aktywnymi osiami pojazdów
|
|
}
|
|
|
|
Distance += distance; // doliczenie odległości przeszkody albo długości odcinka do przeskanowanej odległości
|
|
return foundobject;
|
|
}
|
|
|
|
int TDynamicObject::DettachStatus(int dir)
|
|
{ // sprawdzenie odległości sprzęgów
|
|
// rzeczywistych od strony (dir):
|
|
// 0=przód,1=tył
|
|
// Ra: dziwne, że ta funkcja nie jest używana
|
|
if( MoverParameters->Couplers[ dir ].CouplingFlag == coupling::faux ) {
|
|
return 0; // jeśli nic nie podłączone, to jest OK
|
|
}
|
|
return MoverParameters->DettachStatus(dir); // czy jest w odpowiedniej odległości?
|
|
}
|
|
|
|
int TDynamicObject::Dettach(int dir)
|
|
{ // rozłączenie sprzęgów rzeczywistych od
|
|
// strony (dir): 0=przód,1=tył
|
|
// zwraca maskę bitową aktualnych sprzegów (0 jeśli rozłączony)
|
|
if (ctOwner)
|
|
{ // jeśli pojazd ma przypisany obiekt nadzorujący skład, to póki
|
|
// są wskaźniki
|
|
TDynamicObject *d = this;
|
|
while (d)
|
|
{
|
|
d->ctOwner = nullptr; // usuwanie właściciela
|
|
d = d->Prev();
|
|
}
|
|
d = Next();
|
|
while (d)
|
|
{
|
|
d->ctOwner = nullptr; // usuwanie właściciela
|
|
d = d->Next(); // i w drugą stronę
|
|
}
|
|
}
|
|
if( MoverParameters->Couplers[ dir ].CouplingFlag ) {
|
|
// odczepianie, o ile coś podłączone
|
|
MoverParameters->Dettach( dir );
|
|
/*
|
|
if( true == MoverParameters->Dettach( dir ) ) {
|
|
auto *othervehicle { dir ? NextConnected : PrevConnected };
|
|
auto const othercoupler { dir ? NextConnectedNo() : PrevConnectedNo() };
|
|
( othercoupler ? othervehicle->NextConnected : othervehicle->PrevConnected ) = nullptr;
|
|
( dir ? NextConnected : PrevConnected ) = nullptr;
|
|
};
|
|
*/
|
|
}
|
|
// sprzęg po rozłączaniu (czego się nie da odpiąć
|
|
return MoverParameters->Couplers[dir].CouplingFlag;
|
|
}
|
|
|
|
void
|
|
TDynamicObject::couple( int const Side ) {
|
|
|
|
auto const &neighbour { MoverParameters->Neighbours[ Side ] };
|
|
|
|
if( neighbour.vehicle == nullptr ) { return; }
|
|
|
|
auto const &coupler { MoverParameters->Couplers[ Side ] };
|
|
auto *othervehicle { neighbour.vehicle };
|
|
auto *othervehicleparams{ othervehicle->MoverParameters };
|
|
auto const &othercoupler { othervehicleparams->Couplers[ neighbour.vehicle_end ] };
|
|
|
|
if( coupler.CouplingFlag == coupling::faux ) {
|
|
// najpierw hak
|
|
if( ( coupler.AllowedFlag
|
|
& othercoupler.AllowedFlag
|
|
& coupling::coupler ) == coupling::coupler ) {
|
|
if( MoverParameters->Attach(
|
|
Side, neighbour.vehicle_end,
|
|
othervehicleparams,
|
|
coupling::coupler ) ) {
|
|
// one coupling type per key press
|
|
return;
|
|
}
|
|
else {
|
|
WriteLog( "Mechanical coupling failed." );
|
|
}
|
|
}
|
|
}
|
|
if( false == TestFlag( MoverParameters->Couplers[ Side ].CouplingFlag, coupling::brakehose ) ) {
|
|
// pneumatyka
|
|
if( ( coupler.AllowedFlag
|
|
& othercoupler.AllowedFlag
|
|
& coupling::brakehose ) == coupling::brakehose ) {
|
|
if( MoverParameters->Attach(
|
|
Side, neighbour.vehicle_end,
|
|
othervehicleparams,
|
|
coupler.CouplingFlag | coupling::brakehose ) ) {
|
|
SetPneumatic( Side != 0, true );
|
|
othervehicle->SetPneumatic( Side != 0, true );
|
|
// one coupling type per key press
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if( false == TestFlag( MoverParameters->Couplers[ Side ].CouplingFlag, coupling::mainhose ) ) {
|
|
// zasilajacy
|
|
if( ( coupler.AllowedFlag
|
|
& othercoupler.AllowedFlag
|
|
& coupling::mainhose ) == coupling::mainhose ) {
|
|
if( MoverParameters->Attach(
|
|
Side, neighbour.vehicle_end,
|
|
othervehicleparams,
|
|
coupler.CouplingFlag | coupling::mainhose ) ) {
|
|
SetPneumatic( Side != 0, false );
|
|
othervehicle->SetPneumatic( Side != 0, false );
|
|
// one coupling type per key press
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if( false == TestFlag( MoverParameters->Couplers[ Side ].CouplingFlag, coupling::control ) ) {
|
|
// ukrotnionko
|
|
if( (coupler.AllowedFlag & othercoupler.AllowedFlag & coupling::control) == coupling::control
|
|
&& coupler.control_type == othercoupler.control_type
|
|
&& ( MoverParameters->CompatibleCoupling( Side, *othervehicleparams, neighbour.vehicle_end, coupler.CouplingFlag | coupling::control ) & coupling::control ) != 0 ) {
|
|
if( MoverParameters->Attach(
|
|
Side, neighbour.vehicle_end,
|
|
othervehicleparams,
|
|
coupler.CouplingFlag | coupling::control ) ) {
|
|
// one coupling type per key press
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if( false == TestFlag( MoverParameters->Couplers[ Side ].CouplingFlag, coupling::gangway ) ) {
|
|
// mostek
|
|
if( ( coupler.AllowedFlag
|
|
& othercoupler.AllowedFlag
|
|
& coupling::gangway ) == coupling::gangway ) {
|
|
if( MoverParameters->Attach(
|
|
Side, neighbour.vehicle_end,
|
|
othervehicleparams,
|
|
coupler.CouplingFlag | coupling::gangway ) ) {
|
|
// one coupling type per key press
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if( false == TestFlag( MoverParameters->Couplers[ Side ].CouplingFlag, coupling::heating ) ) {
|
|
// heating
|
|
if( ( coupler.AllowedFlag
|
|
& othercoupler.AllowedFlag
|
|
& coupling::heating ) == coupling::heating ) {
|
|
if( MoverParameters->Attach(
|
|
Side, neighbour.vehicle_end,
|
|
othervehicleparams,
|
|
coupler.CouplingFlag | coupling::heating ) ) {
|
|
// one coupling type per key press
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
int
|
|
TDynamicObject::uncouple( int const Side ) {
|
|
|
|
if( DettachStatus(Side) >= 0
|
|
|| true == TestFlag(MoverParameters->Couplers[Side].CouplingFlag, coupling::permanent) ) {
|
|
// can't uncouple, return existing coupling state
|
|
return MoverParameters->Couplers[ Side ].CouplingFlag;
|
|
}
|
|
// jeżeli sprzęg niezablokowany, jest co odczepić i się da
|
|
auto const couplingflag { Dettach( Side ) };
|
|
return couplingflag;
|
|
}
|
|
|
|
bool
|
|
TDynamicObject::attach_coupler_adapter( int const Side, bool const Enforce ) {
|
|
|
|
auto &coupler { MoverParameters->Couplers[ Side ] };
|
|
// sanity check(s)
|
|
if( coupler.type() == TCouplerType::Automatic ) { return false; }
|
|
auto const *neighbour { MoverParameters->Neighbours[ Side ].vehicle };
|
|
if( neighbour == nullptr
|
|
|| MoverParameters->Neighbours[Side].distance > 25.0 ) {
|
|
// can only acquire the adapter from a nearby enough vehicle
|
|
return false;
|
|
}
|
|
// TBD: empty struct instead of fallback defaults, to allow vehicles without adapter?
|
|
auto adapterdata {
|
|
coupleradapter_data {
|
|
{ 0.085f, 0.95f },
|
|
"tabor/polsprzeg" } };
|
|
if( false == neighbour->m_coupleradapter.model.empty() ) {
|
|
// explicit coupler adapter definition overrides default parameters
|
|
adapterdata = neighbour->m_coupleradapter;
|
|
}
|
|
if( MoverParameters->Neighbours[Side].distance - adapterdata.position.x < 0.5
|
|
&& false == Enforce ) {
|
|
// arbitrary amount of free room required to install the adapter
|
|
// NOTE: this also covers cases with established physical connection
|
|
return false;
|
|
}
|
|
|
|
coupler.adapter_type = TCouplerType::Automatic;
|
|
coupler.adapter_length = adapterdata.position.x;
|
|
coupler.adapter_height = adapterdata.position.y;
|
|
// audio flag, visuals update
|
|
coupler.sounds |= sound::attachadapter;
|
|
m_coupleradapters[ Side ] = TModelsManager::GetModel( adapterdata.model );
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
TDynamicObject::remove_coupler_adapter( int const Side ) {
|
|
|
|
auto &coupler{ MoverParameters->Couplers[ Side ] };
|
|
|
|
if( coupler.adapter_type == TCouplerType::NoCoupler ) { return false; }
|
|
// TODO: sanity check(s)
|
|
if( coupler.Connected != nullptr ) {
|
|
// TBD: disallow instead adapter removal if it's coupled with another vehicle?
|
|
uncouple( Side );
|
|
}
|
|
coupler.adapter_type = TCouplerType::NoCoupler;
|
|
coupler.adapter_length = 0.0;
|
|
coupler.adapter_height = 0.0;
|
|
// audio flag, visuals update
|
|
coupler.sounds |= sound::removeadapter;
|
|
m_coupleradapters[ Side ] = nullptr;
|
|
|
|
return true;
|
|
}
|
|
|
|
TDynamicObject::TDynamicObject() {
|
|
modelShake = glm::dvec3(0, 0, 0);
|
|
// fTrackBlock = 10000.0; // brak przeszkody na drodze
|
|
btnOn = false;
|
|
vUp = vWorldUp;
|
|
vFront = vWorldFront;
|
|
vLeft = vWorldLeft;
|
|
iNumAxles = 0;
|
|
MoverParameters = nullptr;
|
|
Mechanik = nullptr;
|
|
MechInside = false;
|
|
// McZapkie-270202
|
|
Controller = AIdriver;
|
|
bDisplayCab = false; // 030303
|
|
// NextConnected = PrevConnected = NULL;
|
|
// NextConnectedNo = PrevConnectedNo = 2; // ABu: Numery sprzegow. 2=nie podłączony
|
|
bEnabled = true;
|
|
MyTrack = nullptr;
|
|
// McZapkie-260202
|
|
dWheelAngle[0] = 0.0;
|
|
dWheelAngle[1] = 0.0;
|
|
dWheelAngle[2] = 0.0;
|
|
// Winger 160204 - pantografy
|
|
// PantVolume = 3.5;
|
|
NoVoltTime = 0;
|
|
mdModel = nullptr;
|
|
mdKabina = nullptr;
|
|
// smWiazary[0]=smWiazary[1]=NULL;
|
|
smWahacze[0] = smWahacze[1] = smWahacze[2] = smWahacze[3] = nullptr;
|
|
fWahaczeAmp = 0;
|
|
smBrakeMode = nullptr;
|
|
smLoadMode = nullptr;
|
|
mdLoad = nullptr;
|
|
mdLowPolyInt = nullptr;
|
|
//smMechanik0 = smMechanik1 = NULL;
|
|
smBuforLewy[0] = smBuforLewy[1] = nullptr;
|
|
smBuforPrawy[0] = smBuforPrawy[1] = nullptr;
|
|
smBogie[0] = smBogie[1] = nullptr;
|
|
bogieRot[0] = bogieRot[1] = glm::dvec3(0, 0, 0);
|
|
modelRot = glm::dvec3(0, 0, 0);
|
|
cp1 = cp2 = sp1 = sp2 = 0;
|
|
iDirection = 1; // stoi w kierunku tradycyjnym (0, gdy jest odwrócony)
|
|
iAxleFirst = 0; // numer pierwszej osi w kierunku ruchu (przełączenie
|
|
// następuje, gdy osie sa na
|
|
// tym samym torze)
|
|
RaLightsSet(0, 0); // początkowe zerowanie stanu świateł
|
|
// Ra: domyślne ilości animacji dla zgodności wstecz (gdy brak ilości podanych
|
|
// w MMD)
|
|
// ustawienie liczby modeli animowanych podczas konstruowania obiektu a nie na 0
|
|
// prowadzi prosto do wysypów jeśli źle zdefiniowane mmd
|
|
iAnimations = 0; // na razie nie ma żadnego
|
|
pAnimated = nullptr;
|
|
fShade = 0.0; // standardowe oświetlenie na starcie
|
|
iHornWarning = 1; // numer syreny do użycia po otrzymaniu sygnału do jazdy
|
|
asDestination = "none"; // stojący nigdzie nie jedzie
|
|
pValveGear = nullptr; // Ra: tymczasowo
|
|
iCabs = 0; // maski bitowe modeli kabin
|
|
smBrakeSet = nullptr; // nastawa hamulca (wajcha)
|
|
smLoadSet = nullptr; // nastawa ładunku (wajcha)
|
|
smWiper = nullptr; // wycieraczka (poniekąd też wajcha)
|
|
ctOwner = nullptr; // na początek niczyj
|
|
iOverheadMask = 0; // maska przydzielana przez AI pojazdom posiadającym
|
|
// pantograf, aby wymuszały
|
|
// jazdę bezprądową
|
|
tmpTraction.TractionVoltage = 0; // Ra 2F1H: prowizorka, trzeba przechować
|
|
// napięcie, żeby nie wywalało WS pod
|
|
// izolatorem
|
|
fAdjustment = 0.0; // korekcja odległości pomiędzy wózkami (np. na łukach)
|
|
}
|
|
|
|
TDynamicObject::~TDynamicObject() {
|
|
SafeDelete( Mechanik );
|
|
SafeDelete( MoverParameters );
|
|
SafeDeleteArray( pAnimated ); // lista animowanych submodeli
|
|
}
|
|
|
|
void TDynamicObject::place_on_track(TTrack *Track, double fDist, bool Reversed)
|
|
{
|
|
for( auto &axle : m_axlesounds ) {
|
|
// wyszukiwanie osi (0 jest na końcu, dlatego dodajemy długość?)
|
|
axle.distance = (
|
|
Reversed ?
|
|
-axle.offset :
|
|
axle.offset + MoverParameters->Dim.L ) + fDist;
|
|
}
|
|
double fAxleDistHalf = fAxleDist * 0.5;
|
|
// przesuwanie pojazdu tak, aby jego początek był we wskazanym miejcu
|
|
fDist -= 0.5 * MoverParameters->Dim.L; // dodajemy pół długości pojazdu, bo ustawiamy jego środek (zliczanie na minus)
|
|
switch (iNumAxles) {
|
|
// Ra: pojazdy wstawiane są na tor początkowy, a potem przesuwane
|
|
case 2: // ustawianie osi na torze
|
|
Axle0.Reset();
|
|
Axle0.Init(Track, this, iDirection ? 1 : -1);
|
|
Axle0.Move((iDirection ? fDist : -fDist) + fAxleDistHalf, false);
|
|
Axle1.Reset();
|
|
Axle1.Init(Track, this, iDirection ? 1 : -1);
|
|
Axle1.Move((iDirection ? fDist : -fDist) - fAxleDistHalf, false); // false, żeby nie generować eventów
|
|
break;
|
|
}
|
|
// potrzebne do wyliczenia aktualnej pozycji; nie może być zero, bo nie przeliczy pozycji
|
|
// teraz jeszcze trzeba przypisać pojazdy do nowego toru, bo przesuwanie początkowe osi nie
|
|
// zrobiło tego
|
|
Move( 0.0001 );
|
|
ABuCheckMyTrack(); // zmiana toru na ten, co oś Axle0 (oś z przodu)
|
|
}
|
|
|
|
double
|
|
TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
|
|
std::string BaseDir, // z którego katalogu wczytany, np. "PKP/EU07"
|
|
std::string asReplacableSkin, // nazwa wymiennej tekstury
|
|
std::string Type_Name, // nazwa CHK/MMD, np. "303E"
|
|
TTrack *Track, // tor początkowy wstwawienia (początek składu)
|
|
double fDist, // dystans względem punktu 1
|
|
std::string DriverType, // typ obsady
|
|
double fVel, // prędkość początkowa
|
|
std::string TrainName, // nazwa składu, np. "PE2307" albo Vmax, jeśli pliku nie ma a są cyfry
|
|
float Load, // ilość ładunku
|
|
std::string LoadType, // nazwa ładunku
|
|
bool Reversed, // true, jeśli ma stać odwrotnie w składzie
|
|
std::string MoreParams // dodatkowe parametry wczytywane w postaci tekstowej
|
|
)
|
|
{ // Ustawienie początkowe pojazdu
|
|
iDirection = Reversed ? 0 : 1; // Ra: 0, jeśli ma być wstawiony jako obrócony tyłem
|
|
asBaseDir = paths::dynamic + BaseDir + "/"; // McZapkie-310302
|
|
asName = Name;
|
|
// derived from the name and the seed of the simulation rather than drawn at random, so that the vehicle
|
|
// keeps the same look for the whole session and looks the same for everyone in a multiplayer game, while
|
|
// another run of the same scenario, with another seed, dresses it differently
|
|
m_variantseed = hash_string( asName, Global.random_seed );
|
|
std::string asAnimName; // zmienna robocza do wyszukiwania osi i wózków
|
|
// Ra: zmieniamy znaczenie obsady na jednoliterowe, żeby dosadzić kierownika
|
|
if (DriverType == "headdriver")
|
|
DriverType = "1"; // sterujący kabiną +1
|
|
else if (DriverType == "reardriver")
|
|
DriverType = "2"; // sterujący kabiną -1
|
|
else if (DriverType == "passenger")
|
|
DriverType = ""; // legacy type, no longer needed
|
|
else if (DriverType == "nobody")
|
|
DriverType = ""; // nikt nie siedzi
|
|
|
|
int Cab = 0; // numer kabiny z obsadą (nie można zająć obu)
|
|
if (DriverType == "1") // od przodu składu
|
|
Cab = 1; // iDirection?1:-1; //iDirection=1 gdy normalnie, =0 odwrotnie
|
|
else if (DriverType == "2") // od tyłu składu
|
|
Cab = -1; // iDirection?-1:1;
|
|
/*
|
|
// NOTE: leave passenger in the middle section, this is most likely to be 'passenger' section in MU trains
|
|
else if (DriverType == "p")
|
|
{
|
|
if (Random(6) < 3)
|
|
Cab = 1;
|
|
else
|
|
Cab = -1; // losowy przydział kabiny
|
|
}
|
|
*/
|
|
// utworzenie parametrów fizyki
|
|
MoverParameters = new TMoverParameters(iDirection ? fVel : -fVel, Type_Name, asName, Cab);
|
|
// the vehicle carries on with the odometer state of its earlier sessions (eu07/maszyna#72)
|
|
MoverParameters->Odometer = odometer::starting_state( odometer::states(), asName, asBaseDir );
|
|
// McZapkie: TypeName musi byc nazwą CHK/MMD pojazdu
|
|
if (!MoverParameters->LoadFIZ(asBaseDir))
|
|
{ // jak wczytanie CHK się nie uda, to błąd
|
|
if (ConversionError == 666)
|
|
ErrorLog( "Bad vehicle: failed to locate definition file \"" + BaseDir + "/" + Type_Name + ".fiz" + "\"" );
|
|
else {
|
|
ErrorLog( "Bad vehicle: failed to load definition from file \"" + BaseDir + "/" + Type_Name + ".fiz\" (error " + std::to_string( ConversionError ) + ")" );
|
|
}
|
|
return 0.0; // zerowa długość to brak pojazdu
|
|
}
|
|
// load the cargo now that we know whether the vehicle will allow it
|
|
MoverParameters->AssignLoad( LoadType, Load );
|
|
MoverParameters->ComputeMass();
|
|
|
|
bool driveractive = fVel != 0.0; // jeśli prędkość niezerowa, to aktywujemy ruch
|
|
if (!MoverParameters->CheckLocomotiveParameters(
|
|
driveractive,
|
|
(fVel > 0 ? 1 : -1) * Cab *
|
|
(iDirection ? 1 : -1))) // jak jedzie lub obsadzony to gotowy do drogi
|
|
{
|
|
Error("Parameters mismatch: dynamic object " + asName + " from \"" + BaseDir + "/" + Type_Name + "\"" );
|
|
return 0.0; // zerowa długość to brak pojazdu
|
|
}
|
|
// controller position
|
|
MoverParameters->MainCtrlPos = MoverParameters->MainCtrlNoPowerPos();
|
|
// ustawienie pozycji hamulca
|
|
MoverParameters->LocalBrakePosA = 0.0;
|
|
if (driveractive)
|
|
{
|
|
if (Cab == 0)
|
|
MoverParameters->BrakeCtrlPos =
|
|
static_cast<int>( std::floor(MoverParameters->Handle->GetPos(bh_NP)) );
|
|
else
|
|
MoverParameters->BrakeCtrlPos = static_cast<int>( std::floor(MoverParameters->Handle->GetPos(bh_RP)) );
|
|
|
|
// engage independent brake if applicable, if the vehicle is to be on standby
|
|
// NOTE: with more than one driver in the consist this is likely to go awery, since all but one will be sent to sleep
|
|
// TBD, TODO: have the virtual helper release independent brakes during consist check?
|
|
if( DriverType != "" ) {
|
|
if( MoverParameters->LocalBrake != TLocalBrake::ManualBrake ) {
|
|
if( fVel < 1.0 ) {
|
|
MoverParameters->IncLocalBrakeLevel( LocalBrakePosNo );
|
|
if ( MoverParameters->EIMCtrlEmergency ) {
|
|
MoverParameters->DecLocalBrakeLevel(1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
MoverParameters->BrakeCtrlPos =
|
|
static_cast<int>( std::floor(MoverParameters->Handle->GetPos(bh_NP)) );
|
|
|
|
// poprawienie hamulca po ewentualnym przestawieniu przez Pascal
|
|
// TODO: check if needed, we're not in Pascal anymore, Toto
|
|
MoverParameters->BrakeLevelSet(MoverParameters->BrakeCtrlPos);
|
|
|
|
// dodatkowe parametry yB
|
|
MoreParams += "."; // wykonuje o jedną iterację za mało, więc trzeba mu dodać
|
|
// kropkę na koniec
|
|
size_t kropka = MoreParams.find("."); // znajdź kropke
|
|
std::string ActPar; // na parametry
|
|
while (kropka != std::string::npos) // jesli sa kropki jeszcze
|
|
{
|
|
size_t dlugosc = MoreParams.length();
|
|
ActPar = ToUpper(MoreParams.substr(0, kropka)); // pierwszy parametr;
|
|
MoreParams = MoreParams.substr(kropka + 1, dlugosc - kropka); // reszta do dalszej obrobki
|
|
kropka = MoreParams.find(".");
|
|
|
|
if (ActPar.substr(0, 1) == "B") // jesli hamulce
|
|
{ // sprawdzanie kolejno nastaw
|
|
WriteLog("Wpis hamulca: " + ActPar);
|
|
if ( contains( ActPar, 'G') )
|
|
{
|
|
MoverParameters->BrakeDelaySwitch(bdelay_G);
|
|
}
|
|
if( contains( ActPar, 'P' ) )
|
|
{
|
|
MoverParameters->BrakeDelaySwitch(bdelay_P);
|
|
}
|
|
if( contains( ActPar, 'R' ) )
|
|
{
|
|
MoverParameters->BrakeDelaySwitch(bdelay_R);
|
|
}
|
|
if( contains( ActPar, 'M' ) )
|
|
{
|
|
MoverParameters->BrakeDelaySwitch(bdelay_R);
|
|
MoverParameters->BrakeDelaySwitch(bdelay_R + bdelay_M);
|
|
}
|
|
// wylaczanie hamulca
|
|
if ( contains( ActPar, "<>") ) // wylaczanie na probe hamowania naglego
|
|
{
|
|
MoverParameters->Hamulec->SetBrakeStatus( MoverParameters->Hamulec->GetBrakeStatus() | b_dmg ); // wylacz
|
|
}
|
|
if ( contains( ActPar, '0' ) ) // wylaczanie na sztywno
|
|
{
|
|
MoverParameters->Hamulec->ForceEmptiness();
|
|
MoverParameters->Hamulec->SetBrakeStatus( MoverParameters->Hamulec->GetBrakeStatus() | b_dmg ); // wylacz
|
|
}
|
|
if ( contains( ActPar, 'E' ) ) // oprozniony
|
|
{
|
|
MoverParameters->Hamulec->ForceEmptiness();
|
|
MoverParameters->Pipe->CreatePress(0);
|
|
MoverParameters->Pipe2->CreatePress(0);
|
|
}
|
|
if ( contains( ActPar, 'Q' ) ) // oprozniony
|
|
{
|
|
MoverParameters->Hamulec->ForceEmptiness();
|
|
MoverParameters->Pipe->CreatePress(0.0);
|
|
MoverParameters->PipePress = 0.0;
|
|
MoverParameters->Pipe2->CreatePress(0.0);
|
|
MoverParameters->ScndPipePress = 0.0;
|
|
MoverParameters->PantVolume = 0.1;
|
|
MoverParameters->PantPress = 0.0;
|
|
MoverParameters->CompressedVolume = 0.0;
|
|
}
|
|
|
|
if ( contains( ActPar, '1' ) ) // wylaczanie 10%
|
|
{
|
|
if (Random(10) < 1) // losowanie 1/10
|
|
{
|
|
MoverParameters->Hamulec->ForceEmptiness();
|
|
MoverParameters->Hamulec->SetBrakeStatus( MoverParameters->Hamulec->GetBrakeStatus() | b_dmg ); // wylacz
|
|
}
|
|
}
|
|
if ( contains( ActPar, 'X') ) // agonalny wylaczanie 20%, usrednienie przekladni
|
|
{
|
|
if (Random(100) < 20) // losowanie 20/100
|
|
{
|
|
MoverParameters->Hamulec->ForceEmptiness();
|
|
MoverParameters->Hamulec->SetBrakeStatus( MoverParameters->Hamulec->GetBrakeStatus() | b_dmg ); // wylacz
|
|
}
|
|
if (MoverParameters->BrakeCylMult[2] * MoverParameters->BrakeCylMult[1] >
|
|
0.01) // jesli jest nastawiacz mechaniczny PL
|
|
{
|
|
float rnd = Random(100);
|
|
if (rnd < 20) // losowanie 20/100 usrednienie
|
|
{
|
|
MoverParameters->BrakeCylMult[2] = MoverParameters->BrakeCylMult[1] =
|
|
(MoverParameters->BrakeCylMult[2] + MoverParameters->BrakeCylMult[1]) /
|
|
2;
|
|
}
|
|
else if (rnd < 70) // losowanie 70/100-20/100 oslabienie
|
|
{
|
|
MoverParameters->BrakeCylMult[1] = MoverParameters->BrakeCylMult[1] * 0.50;
|
|
MoverParameters->BrakeCylMult[2] = MoverParameters->BrakeCylMult[2] * 0.75;
|
|
}
|
|
else if (rnd < 80) // losowanie 80/100-70/100 tylko prozny
|
|
{
|
|
MoverParameters->BrakeCylMult[2] = MoverParameters->BrakeCylMult[1];
|
|
}
|
|
else // tylko ladowny
|
|
{
|
|
MoverParameters->BrakeCylMult[1] = MoverParameters->BrakeCylMult[2];
|
|
}
|
|
}
|
|
}
|
|
// nastawianie ladunku
|
|
if ( contains( ActPar, 'T' ) ) // prozny
|
|
{
|
|
MoverParameters->DecBrakeMult();
|
|
MoverParameters->DecBrakeMult();
|
|
} // dwa razy w dol
|
|
if ( contains( ActPar, 'H' ) ) // ladowny I (dla P-Ł dalej prozny)
|
|
{
|
|
MoverParameters->IncBrakeMult();
|
|
MoverParameters->IncBrakeMult();
|
|
MoverParameters->DecBrakeMult();
|
|
} // dwa razy w gore i obniz
|
|
if ( contains( ActPar, 'F' ) ) // ladowny II
|
|
{
|
|
MoverParameters->IncBrakeMult();
|
|
MoverParameters->IncBrakeMult();
|
|
} // dwa razy w gore
|
|
if ( contains( ActPar, 'N' ) ) // parametr neutralny
|
|
{
|
|
}
|
|
} // koniec hamulce
|
|
else if( ActPar.size() >= 3
|
|
&& ActPar.front() == 'W' ) {
|
|
// wheel
|
|
ActPar.erase( 0, 1 );
|
|
|
|
auto fixedflatsize { 0 };
|
|
auto randomflatsize { 0 };
|
|
auto flatchance { 100 };
|
|
|
|
while( false == ActPar.empty() ) {
|
|
// TODO: convert this whole copy and paste mess to something more elegant one day
|
|
switch( ActPar.front() ) {
|
|
case 'F': {
|
|
// fixed flat size
|
|
auto const indexstart { 1 };
|
|
auto const indexend { ActPar.find_first_not_of( "1234567890", indexstart ) };
|
|
fixedflatsize = std::atoi( ActPar.substr( indexstart, indexend ).c_str() );
|
|
ActPar.erase( 0, indexend );
|
|
break;
|
|
}
|
|
case 'R': {
|
|
// random flat size
|
|
auto const indexstart { 1 };
|
|
auto const indexend { ActPar.find_first_not_of( "1234567890", indexstart ) };
|
|
randomflatsize = std::atoi( ActPar.substr( indexstart, indexend ).c_str() );
|
|
ActPar.erase( 0, indexend );
|
|
break;
|
|
}
|
|
case 'P': {
|
|
// random flat probability
|
|
auto const indexstart { 1 };
|
|
auto const indexend { ActPar.find_first_not_of( "1234567890", indexstart ) };
|
|
flatchance = std::atoi( ActPar.substr( indexstart, indexend ).c_str() );
|
|
ActPar.erase( 0, indexend );
|
|
break;
|
|
}
|
|
case 'H': {
|
|
// truck hunting
|
|
auto const indexstart { 1 };
|
|
auto const indexend { ActPar.find_first_not_of( "1234567890", indexstart ) };
|
|
auto const huntingchance { std::atoi( ActPar.substr( indexstart, indexend ).c_str() ) };
|
|
MoverParameters->TruckHunting = Random(0, 100) < huntingchance;
|
|
ActPar.erase( 0, indexend );
|
|
break;
|
|
}
|
|
default: {
|
|
// unrecognized key
|
|
ActPar.erase( 0, 1 );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if( Random( 0, 100 ) <= flatchance ) {
|
|
MoverParameters->WheelFlat += fixedflatsize + Random( 0, randomflatsize );
|
|
}
|
|
} // wheel
|
|
else if( ActPar.size() >= 2
|
|
&& ActPar.front() == 'T' ) {
|
|
// temperature
|
|
ActPar.erase( 0, 1 );
|
|
|
|
auto setambient { false };
|
|
|
|
while( false == ActPar.empty() ) {
|
|
switch( ActPar.front() ) {
|
|
case 'A': {
|
|
// cold start, set all temperatures to ambient level
|
|
setambient = true;
|
|
ActPar.erase( 0, 1 );
|
|
break;
|
|
}
|
|
default: {
|
|
// unrecognized key
|
|
ActPar.erase( 0, 1 );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if( true == setambient ) {
|
|
// TODO: pull ambient temperature from environment data
|
|
MoverParameters->dizel_HeatSet( Global.AirTemperature );
|
|
}
|
|
} // temperature
|
|
else if( ActPar.size() >= 2
|
|
&& ActPar.front() == 'L' ) {
|
|
// load
|
|
ActPar.erase( 0, 1 );
|
|
// immediately followed by max load override
|
|
// TBD: make it instead an optional sub-parameter?
|
|
{
|
|
auto const indexstart { 0 };
|
|
auto const indexend { ActPar.find_first_not_of( "1234567890", indexstart ) };
|
|
MoverParameters->MaxLoad = std::atoi( ActPar.substr( indexstart, indexend ).c_str() );
|
|
ActPar.erase( 0, indexend );
|
|
}
|
|
while( false == ActPar.empty() ) {
|
|
switch( ActPar.front() ) {
|
|
default: {
|
|
// unrecognized key
|
|
ActPar.erase( 0, 1 );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} // load
|
|
/* else if (ActPar.substr(0, 1) == "") // tu mozna wpisac inny prefiks i inne rzeczy
|
|
{
|
|
// jakies inne prefiksy
|
|
}
|
|
*/
|
|
} // koniec while kropka
|
|
|
|
if (MoverParameters->CategoryFlag & 2) // jeśli samochód
|
|
{ // ustawianie samochodow na poboczu albo na środku drogi
|
|
if( Track->fTrackWidth < 3.5 // jeśli droga wąska
|
|
|| Track->m_road != nullptr ) // a lane of a road node is one-way, the vehicle keeps to its middle
|
|
MoverParameters->OffsetTrackH = 0.0; // to stawiamy na środku, niezależnie od stanu
|
|
// ruchu
|
|
else if( driveractive ) {// od 3.5m do 8.0m jedzie po środku pasa, dla
|
|
// szerszych w odległości
|
|
// 1.5m
|
|
auto const lanefreespace = 0.5 * Track->fTrackWidth - MoverParameters->Dim.W;
|
|
MoverParameters->OffsetTrackH = lanefreespace > 1.5 ?
|
|
-0.5 * MoverParameters->Dim.W - 0.75 : // wide road, keep near centre with safe margin
|
|
lanefreespace > 0.1 ?
|
|
-0.25 * Track->fTrackWidth : // narrow fit, stay on the middle
|
|
-0.5 * MoverParameters->Dim.W - 0.075; // too narrow, just keep some minimal clearance
|
|
}
|
|
else // jak stoi, to kołem na poboczu i pobieramy szerokość razem z
|
|
// poboczem, ale nie z
|
|
// chodnikiem
|
|
MoverParameters->OffsetTrackH =
|
|
-0.5 * (Track->WidthTotal() - MoverParameters->Dim.W) + 0.05;
|
|
iHornWarning = 0; // nie będzie trąbienia po podaniu zezwolenia na jazdę
|
|
if (fDist < 0.0) //-0.5*MoverParameters->Dim.L) //jeśli jest przesunięcie do tyłu
|
|
if (!Track->CurrentPrev()) // a nie ma tam odcinka i trzeba by coś
|
|
// wygenerować
|
|
fDist = -fDist; // to traktujemy, jakby przesunięcie było w drugą stronę
|
|
}
|
|
|
|
create_controller( DriverType, !TrainName.empty() );
|
|
|
|
ShakeSpring.Init( 125.0 );
|
|
BaseShake = baseshake_config {};
|
|
ShakeState = shake_state {};
|
|
|
|
// McZapkie-250202
|
|
/*
|
|
iAxles = std::min( MoverParameters->NAxles, MaxAxles ); // ilość osi
|
|
*/
|
|
// wczytywanie z pliku nazwatypu.mmd, w tym model
|
|
erase_extension( asReplacableSkin );
|
|
LoadMMediaFile(Type_Name, asReplacableSkin);
|
|
// McZapkie-100402: wyszukiwanie submodeli sprzegów
|
|
btCoupler1.Init( "coupler1", mdModel ); // false - ma być wyłączony
|
|
btCoupler2.Init( "coupler2", mdModel );
|
|
// brake hoses
|
|
btCPneumatic1.Init("cpneumatic1", mdModel);
|
|
btCPneumatic2.Init("cpneumatic2", mdModel);
|
|
btCPneumatic1r.Init("cpneumatic1r", mdModel);
|
|
btCPneumatic2r.Init("cpneumatic2r", mdModel);
|
|
// main hoses
|
|
btPneumatic1.Init("pneumatic1", mdModel);
|
|
btPneumatic2.Init("pneumatic2", mdModel);
|
|
btPneumatic1r.Init("pneumatic1r", mdModel);
|
|
btPneumatic2r.Init("pneumatic2r", mdModel);
|
|
// control cables
|
|
btCCtrl1.Init( "cctrl1", mdModel, false);
|
|
btCCtrl2.Init( "cctrl2", mdModel, false);
|
|
// gangways
|
|
btCPass1.Init( "cpass1", mdModel, false);
|
|
btCPass2.Init( "cpass2", mdModel, false);
|
|
// sygnaly
|
|
m_endsignal12.Init( "endsignal12", mdModel, false );
|
|
m_endsignal13.Init( "endsignal13", mdModel, false );
|
|
m_endsignal22.Init( "endsignal22", mdModel, false );
|
|
m_endsignal23.Init( "endsignal23", mdModel, false );
|
|
m_endsignals1.Init( "endsignals1", mdModel, false );
|
|
m_endsignals2.Init( "endsignals2", mdModel, false );
|
|
m_endtab1.Init( "endtab1", mdModel, false );
|
|
m_endtab2.Init( "endtab2", mdModel, false );
|
|
m_headlamp11.Init( "headlamp11", mdModel ); // górne
|
|
m_headlamp12.Init( "headlamp12", mdModel ); // prawe
|
|
m_headlamp13.Init( "headlamp13", mdModel ); // lewe
|
|
m_highbeam12.Init("highbeam12", mdModel); // prawe dlugie
|
|
m_highbeam13.Init("highbeam13", mdModel); // lewe dlugie
|
|
m_headlamp21.Init( "headlamp21", mdModel );
|
|
m_headlamp22.Init( "headlamp22", mdModel );
|
|
m_headlamp23.Init( "headlamp23", mdModel );
|
|
m_highbeam22.Init("highbeam22", mdModel);
|
|
m_highbeam23.Init("highbeam23", mdModel);
|
|
m_headsignal12.Init( "headsignal12", mdModel );
|
|
m_headsignal13.Init( "headsignal13", mdModel );
|
|
m_headsignal22.Init( "headsignal22", mdModel );
|
|
m_headsignal23.Init( "headsignal23", mdModel );
|
|
// informacja, czy ma poszczególne światła
|
|
iInventory[ end::front ] |= m_endsignal12.Active() ? light::redmarker_right : 0;
|
|
iInventory[ end::front ] |= m_endsignal13.Active() ? light::redmarker_left : 0;
|
|
iInventory[ end::rear ] |= m_endsignal22.Active() ? light::redmarker_right : 0;
|
|
iInventory[ end::rear ] |= m_endsignal23.Active() ? light::redmarker_left : 0;
|
|
iInventory[ end::front ] |= m_endsignals1.Active() ? light::redmarker_left | light::redmarker_right : 0;
|
|
iInventory[ end::rear ] |= m_endsignals2.Active() ? light::redmarker_left | light::redmarker_right : 0;
|
|
iInventory[ end::front ] |= m_endtab1.Active() ? light::rearendsignals : 0; // tabliczki blaszane
|
|
iInventory[ end::rear ] |= m_endtab2.Active() ? light::rearendsignals : 0;
|
|
iInventory[ end::front ] |= m_headlamp11.Active() ? light::headlight_upper : 0;
|
|
iInventory[ end::front ] |= m_headlamp12.Active() ? light::headlight_right : 0;
|
|
iInventory[ end::front ] |= m_headlamp13.Active() ? light::headlight_left : 0;
|
|
|
|
iInventory[end::front] |= m_highbeam12.Active() ? light::highbeamlight_right : 0;
|
|
iInventory[end::front] |= m_highbeam13.Active() ? light::highbeamlight_left : 0;
|
|
|
|
iInventory[ end::rear ] |= m_headlamp21.Active() ? light::headlight_upper : 0;
|
|
iInventory[ end::rear ] |= m_headlamp22.Active() ? light::headlight_right : 0;
|
|
iInventory[ end::rear ] |= m_headlamp23.Active() ? light::headlight_left : 0;
|
|
iInventory[ end::front ] |= m_headsignal12.Active() ? light::auxiliary_right : 0;
|
|
iInventory[ end::front ] |= m_headsignal13.Active() ? light::auxiliary_left : 0;
|
|
iInventory[ end::rear ] |= m_headsignal22.Active() ? light::auxiliary_right : 0;
|
|
iInventory[ end::rear ] |= m_headsignal23.Active() ? light::auxiliary_left : 0;
|
|
|
|
iInventory[end::rear] |= m_highbeam22.Active() ? light::highbeamlight_right : 0;
|
|
iInventory[end::rear] |= m_highbeam23.Active() ? light::highbeamlight_left : 0;
|
|
|
|
btExteriorOnly.Init("external_only", mdModel, false);
|
|
|
|
btMechanik1.Init( "mechanik1", mdLowPolyInt, false);
|
|
btMechanik2.Init( "mechanik2", mdLowPolyInt, false);
|
|
|
|
if( MoverParameters->dizel_heat.water.config.shutters ) {
|
|
btShutters1.Init( "shutters1", mdModel, false );
|
|
}
|
|
if( MoverParameters->dizel_heat.water_aux.config.shutters ) {
|
|
btShutters2.Init( "shutters2", mdModel, false );
|
|
}
|
|
TurnOff(); // resetowanie zmiennych submodeli
|
|
|
|
if( mdLowPolyInt != nullptr ) {
|
|
// check the low poly interior for potential compartments of interest, ie ones which can be individually lit
|
|
// TODO: definition of relevant compartments in the .mmd file
|
|
TSubModel *submodel { nullptr };
|
|
if( ( submodel = mdLowPolyInt->GetFromName( "cab0" ) ) != nullptr ) {
|
|
Sections.push_back( { submodel, nullptr, 0, 0.0f } );
|
|
LowPolyIntCabs[ 0 ] = submodel;
|
|
}
|
|
if( ( submodel = mdLowPolyInt->GetFromName( "cab1" ) ) != nullptr ) {
|
|
Sections.push_back( { submodel, nullptr, 0, 0.0f } );
|
|
LowPolyIntCabs[ 1 ] = submodel;
|
|
}
|
|
if( ( submodel = mdLowPolyInt->GetFromName( "cab2" ) ) != nullptr ) {
|
|
Sections.push_back( { submodel, nullptr, 0, 0.0f } );
|
|
LowPolyIntCabs[ 2 ] = submodel;
|
|
}
|
|
// passenger car compartments
|
|
std::vector<std::string> nameprefixes = { "corridor", "korytarz", "compartment", "przedzial" };
|
|
for( auto const &nameprefix : nameprefixes ) {
|
|
init_sections( mdLowPolyInt, nameprefix, MoverParameters->CompartmentLights.start_type == start_t::manual );
|
|
}
|
|
// the inside of the door wings, if the interior has them
|
|
init_interior_doors();
|
|
}
|
|
// destination sign
|
|
if( mdModel ) {
|
|
init_destination( mdModel );
|
|
}
|
|
// 'external_load' is an optional special section in the main model, pointing to submodel of external load
|
|
if( mdModel ) {
|
|
init_sections( mdModel, "external_load", false );
|
|
}
|
|
update_load_sections();
|
|
update_load_visibility();
|
|
// wyszukiwanie zderzakow
|
|
if( mdModel ) {
|
|
// jeśli ma w czym szukać
|
|
for( int i = 0; i < 2; i++ ) {
|
|
asAnimName = std::string( "buffer_left0" ) + std::to_string( i + 1 );
|
|
smBuforLewy[ i ] = mdModel->GetFromName( asAnimName );
|
|
if( smBuforLewy[ i ] )
|
|
smBuforLewy[ i ]->WillBeAnimated(); // ustawienie flagi animacji
|
|
asAnimName = std::string( "buffer_right0" ) + std::to_string( i + 1 );
|
|
smBuforPrawy[ i ] = mdModel->GetFromName( asAnimName );
|
|
if( smBuforPrawy[ i ] )
|
|
smBuforPrawy[ i ]->WillBeAnimated();
|
|
}
|
|
}
|
|
if( Track->fSoundDistance > 0.f ) {
|
|
for( auto &axle : m_axlesounds ) {
|
|
// wyszukiwanie osi (0 jest na końcu, dlatego dodajemy długość?)
|
|
axle.distance =
|
|
clamp_circular<double>(
|
|
( Reversed ?
|
|
-axle.offset :
|
|
axle.offset )
|
|
- 0.5 * MoverParameters->Dim.L
|
|
+ fDist,
|
|
Track->fSoundDistance );
|
|
}
|
|
}
|
|
// McZapkie-250202 end.
|
|
Track->AddDynamicObject(this); // wstawiamy do toru na pozycję 0, a potem przesuniemy
|
|
// McZapkie: zmieniono na ilosc osi brane z chk
|
|
// iNumAxles=(MoverParameters->NAxles>3 ? 4 : 2 );
|
|
initial_track = MyTrack;
|
|
iNumAxles = 2;
|
|
// McZapkie-090402: odleglosc miedzy czopami skretu lub osiami
|
|
fAxleDist = std::clamp(
|
|
std::max( MoverParameters->BDist, MoverParameters->ADist ),
|
|
0.2, //żeby się dało wektory policzyć
|
|
MoverParameters->Dim.L - 0.2 ); // nie mogą być za daleko bo będzie "walenie w mur"
|
|
double fAxleDistHalf = fAxleDist * 0.5;
|
|
// przesuwanie pojazdu tak, aby jego początek był we wskazanym miejcu
|
|
fDist -= 0.5 * MoverParameters->Dim.L; // dodajemy pół długości pojazdu, bo ustawiamy jego środek (zliczanie na minus)
|
|
switch (iNumAxles) {
|
|
// Ra: pojazdy wstawiane są na tor początkowy, a potem przesuwane
|
|
case 2: // ustawianie osi na torze
|
|
Axle0.Init(Track, this, iDirection ? 1 : -1);
|
|
Axle0.Move((iDirection ? fDist : -fDist) + fAxleDistHalf, false);
|
|
Axle1.Init(Track, this, iDirection ? 1 : -1);
|
|
Axle1.Move((iDirection ? fDist : -fDist) - fAxleDistHalf, false); // false, żeby nie generować eventów
|
|
break;
|
|
case 4:
|
|
Axle0.Init(Track, this, iDirection ? 1 : -1);
|
|
Axle0.Move((iDirection ? fDist : -fDist) + (fAxleDistHalf + MoverParameters->ADist * 0.5), false);
|
|
Axle1.Init(Track, this, iDirection ? 1 : -1);
|
|
Axle1.Move((iDirection ? fDist : -fDist) - (fAxleDistHalf + MoverParameters->ADist * 0.5), false);
|
|
// Axle2.Init(Track,this,iDirection?1:-1);
|
|
// Axle2.Move((iDirection?fDist:-fDist)-(fAxleDistHalf-MoverParameters->ADist*0.5),false);
|
|
// Axle3.Init(Track,this,iDirection?1:-1);
|
|
// Axle3.Move((iDirection?fDist:-fDist)+(fAxleDistHalf-MoverParameters->ADist*0.5),false);
|
|
break;
|
|
}
|
|
// potrzebne do wyliczenia aktualnej pozycji; nie może być zero, bo nie przeliczy pozycji
|
|
// teraz jeszcze trzeba przypisać pojazdy do nowego toru, bo przesuwanie początkowe osi nie
|
|
// zrobiło tego
|
|
Move( 0.0001 );
|
|
ABuCheckMyTrack(); // zmiana toru na ten, co oś Axle0 (oś z przodu)
|
|
// Ra: ustawienie pozycji do obliczania sprzęgów
|
|
MoverParameters->Loc = {
|
|
-vPosition.x,
|
|
vPosition.z,
|
|
vPosition.y }; // normalnie przesuwa ComputeMovement() w Update()
|
|
// ABuWozki 060504
|
|
if (mdModel) // jeśli ma w czym szukać
|
|
{
|
|
smBogie[0] = mdModel->GetFromName("bogie1"); // Ra: bo nazwy są małymi
|
|
smBogie[1] = mdModel->GetFromName("bogie2");
|
|
if (!smBogie[0])
|
|
smBogie[0] = mdModel->GetFromName("boogie01"); // Ra: alternatywna nazwa
|
|
if (!smBogie[1])
|
|
smBogie[1] = mdModel->GetFromName("boogie02"); // Ra: alternatywna nazwa
|
|
if (smBogie[0])
|
|
smBogie[0]->WillBeAnimated();
|
|
if (smBogie[1])
|
|
smBogie[1]->WillBeAnimated();
|
|
sm_winter_variant = mdModel->GetFromName("winter_variant");
|
|
sm_spring_variant = mdModel->GetFromName("spring_variant");
|
|
sm_summer_variant = mdModel->GetFromName("summer_variant");
|
|
sm_autumn_variant = mdModel->GetFromName("autumn_variant");
|
|
}
|
|
// ABu: zainicjowanie zmiennej, zeby nic sie nie ruszylo w pierwszej klatce,
|
|
// potem juz liczona prawidlowa wartosc masy
|
|
MoverParameters->ComputeConstans();
|
|
// wektor podłogi dla wagonów, przesuwa ładunek
|
|
vFloor = glm::dvec3(0, 0, MoverParameters->Floor);
|
|
|
|
// długość większa od zera oznacza OK; 2mm docisku?
|
|
return MoverParameters->Dim.L;
|
|
}
|
|
|
|
int
|
|
TDynamicObject::init_sections( TModel3d const *Model, std::string const &Nameprefix, bool const Overrideselfillum ) {
|
|
|
|
auto sectioncount = 0;
|
|
auto sectionindex = 0;
|
|
TSubModel *sectionsubmodel { nullptr };
|
|
|
|
do {
|
|
// section names for index < 10 match either prefix0X or prefixX
|
|
// section names above 10 match prefixX
|
|
auto const sectionindexname { std::to_string( sectionindex ) };
|
|
sectionsubmodel = Model->GetFromName( Nameprefix + sectionindexname );
|
|
if( sectionsubmodel == nullptr
|
|
&& sectionindex < 10 ) {
|
|
sectionsubmodel = Model->GetFromName( Nameprefix + "0" + sectionindexname );
|
|
}
|
|
if( sectionsubmodel != nullptr ) {
|
|
// HACK: disable automatic self-illumination threshold, at least until 3d model update
|
|
if( Overrideselfillum ) {
|
|
sectionsubmodel->SetSelfIllum( 2.0f, true, false );
|
|
}
|
|
Sections.push_back( {
|
|
sectionsubmodel,
|
|
nullptr, // pointers to load sections are generated afterwards
|
|
0,
|
|
0.0f } );
|
|
++sectioncount;
|
|
}
|
|
++sectionindex;
|
|
} while( sectionsubmodel != nullptr
|
|
|| sectionindex < 2 ); // chain can start from prefix00 or prefix01
|
|
|
|
return sectioncount;
|
|
}
|
|
|
|
// a door wing of the main model is seen from the outside, lit as the exterior. its namesake in the low poly interior,
|
|
// if the model has one, follows its moves and is lit with the interior, by its compartment section if it's in one
|
|
void
|
|
TDynamicObject::init_interior_doors() {
|
|
|
|
if( mdLowPolyInt == nullptr ) { return; }
|
|
|
|
for( auto &animation : pAnimations ) {
|
|
// the door animation is only set up for a wing found in the main model
|
|
if( false == door_wings::is_wing( animation.iFlags ) ) { continue; }
|
|
if( ( animation.yUpdate == nullptr ) || ( animation.smAnimated == nullptr ) ) { continue; }
|
|
|
|
auto *interiorwing { mdLowPolyInt->GetFromName( animation.smAnimated->pName ) };
|
|
if( ( interiorwing == nullptr ) || ( interiorwing == animation.smAnimated ) ) { continue; }
|
|
|
|
interiorwing->WillBeAnimated();
|
|
animation.smInterior = interiorwing;
|
|
}
|
|
}
|
|
|
|
bool
|
|
TDynamicObject::init_destination( TModel3d *Model ) {
|
|
|
|
if( Model->GetSMRoot() == nullptr ) { return false; }
|
|
|
|
std::tie( DestinationSign.sign, DestinationSign.has_light ) = Model->GetSMRoot()->find_replacable4();
|
|
|
|
return DestinationSign.sign != nullptr;
|
|
}
|
|
|
|
void
|
|
TDynamicObject::create_controller( std::string const Type, bool const Trainset ) {
|
|
|
|
if( Type == "" ) { return; }
|
|
|
|
// McZapkie-151102: rozkład jazdy czytany z pliku *.txt z katalogu w którym jest sceneria
|
|
if( Type == "1"
|
|
|| Type == "2" ) {
|
|
// McZapkie-110303: mechanik i rozklad tylko gdy jest obsada
|
|
Mechanik = new TController( Controller, this, Aggressive );
|
|
|
|
if( false == Trainset ) {
|
|
// jeśli nie w składzie
|
|
// załączenie rozrządu (wirtualne kabiny) itd.
|
|
Mechanik->DirectionInitial();
|
|
// tryb pociągowy z ustaloną prędkością (względem sprzęgów)
|
|
Mechanik->PutCommand(
|
|
"Timetable:",
|
|
MoverParameters->V * 3.6 * ( iDirection ? -1.0 : 1.0 ),
|
|
0,
|
|
nullptr );
|
|
}
|
|
}
|
|
else if( Type == "p" ) {
|
|
// obserwator w charakterze pasażera
|
|
// Ra: to jest niebezpieczne, bo w razie co będzie pomagał hamulcem bezpieczeństwa
|
|
Mechanik = new TController( Controller, this, Easyman, false );
|
|
}
|
|
}
|
|
|
|
void TDynamicObject::FastMove(double fDistance)
|
|
{
|
|
MoverParameters->dMoveLen = MoverParameters->dMoveLen + fDistance;
|
|
}
|
|
|
|
void TDynamicObject::Move(double fDistance)
|
|
{ // przesuwanie pojazdu po
|
|
// trajektorii polega na
|
|
// przesuwaniu poszczególnych osi
|
|
// Ra: wartość prędkości 2km/h ma ograniczyć aktywację eventów w przypadku
|
|
// drgań
|
|
if (Axle0.GetTrack() == Axle1.GetTrack()) // przed przesunięciem
|
|
{ // powiązanie pojazdu z osią można zmienić tylko wtedy, gdy skrajne osie są
|
|
// na tym samym torze
|
|
if (MoverParameters->Vel >
|
|
2) //|[km/h]| nie ma sensu zmiana osi, jesli pojazd drga na postoju
|
|
iAxleFirst = MoverParameters->V >= 0.0 ?
|
|
1 :
|
|
0; //[m/s] ?1:0 - aktywna druga oś w kierunku jazdy
|
|
// aktualnie eventy aktywuje druga oś, żeby AI nie wyłączało sobie semafora
|
|
// za szybko
|
|
}
|
|
if (fDistance > 0.0)
|
|
{ // gdy ruch w stronę sprzęgu 0, doliczyć korektę do osi 1
|
|
bEnabled &= Axle0.Move(fDistance, iAxleFirst == 0); // oś z przodu pojazdu
|
|
bEnabled &= Axle1.Move(fDistance /*-fAdjustment*/, iAxleFirst != 0); // oś z tyłu pojazdu
|
|
}
|
|
else if (fDistance < 0.0)
|
|
{ // gdy ruch w stronę sprzęgu 1, doliczyć korektę do osi 0
|
|
bEnabled &= Axle1.Move(fDistance, iAxleFirst != 0); // oś z tyłu pojazdu prusza się pierwsza
|
|
bEnabled &= Axle0.Move(fDistance /*-fAdjustment*/, iAxleFirst == 0); // oś z przodu pojazdu
|
|
}
|
|
else // gf: bez wywolania Move na postoju nie ma event0
|
|
{
|
|
bEnabled &= Axle1.Move(fDistance, iAxleFirst != 0); // oś z tyłu pojazdu prusza się pierwsza
|
|
bEnabled &= Axle0.Move(fDistance, iAxleFirst == 0); // oś z przodu pojazdu
|
|
}
|
|
if (fDistance != 0.0) // nie liczyć ponownie, jeśli stoi
|
|
{ // liczenie pozycji pojazdu tutaj, bo jest używane w wielu miejscach
|
|
vPosition = 0.5 * (Axle1.pPosition + Axle0.pPosition); //środek między skrajnymi osiami
|
|
vFront = Axle0.pPosition - Axle1.pPosition; // wektor pomiędzy skrajnymi osiami
|
|
// Ra 2F1J: to nie jest stabilne (powoduje rzucanie taborem) i wymaga
|
|
// dopracowania
|
|
fAdjustment = glm::length(vFront) - fAxleDist; // na łuku będzie ujemny
|
|
// if (fabs(fAdjustment)>0.02) //jeśli jest zbyt dużo, to rozłożyć na kilka przeliczeń (wygasza drgania?)
|
|
//{//parę centymetrów trzeba by już skorygować; te błędy mogą się też
|
|
// generować na ostrych łukach
|
|
// fAdjustment*=0.5; //w jednym kroku korygowany jest ułamek błędu
|
|
//}
|
|
// else
|
|
// fAdjustment=0.0;
|
|
vFront = glm::normalize(vFront); // kierunek ustawienia pojazdu (wektor jednostkowy)
|
|
vLeft = glm::normalize(glm::cross(glm::dvec3(vWorldUp), vFront)); // wektor poziomy w lewo,
|
|
// normalizacja potrzebna z powodu pochylenia (vFront)
|
|
vUp = glm::cross(vFront, vLeft); // wektor w górę, będzie jednostkowy
|
|
modelRot.z = atan2(-vFront.x, vFront.z); // kąt obrotu pojazdu [rad]; z ABuBogies()
|
|
auto const roll { Roll() }; // suma przechyłek
|
|
if (roll != 0.0)
|
|
{ // wyznaczanie przechylenia tylko jeśli jest przechyłka
|
|
// można by pobrać wektory normalne z toru...
|
|
mMatrix = glm::rotate(glm::dmat4(1.0), roll * 0.5, vFront); // ta macierz jest potrzebna głównie do wyświetlania // obrót wzdłuż osi o przechyłkę
|
|
vUp = glm::dvec3(mMatrix * glm::dvec4(vUp, 0.0)); // wektor w górę pojazdu (przekręcenie na przechyłce)
|
|
// vLeft=mMatrix*DynamicObject->vLeft;
|
|
// vUp=CrossProduct(vFront,vLeft); //wektor w górę
|
|
// vLeft=Normalize(CrossProduct(vWorldUp,vFront)); //wektor w lewo
|
|
vLeft = glm::normalize(glm::cross(vUp, vFront)); // wektor w lewo
|
|
// vUp=CrossProduct(vFront,vLeft); //wektor w górę
|
|
}
|
|
mMatrix = BasisChange(vLeft, vUp, vFront); // to też można by od razu policzyć, ale potrzebne jest do wyświetlania // przesuwanie jest jednak rzadziej niż renderowanie
|
|
mMatrix = glm::inverse(mMatrix); // wyliczenie macierzy dla pojazdu (potrzebna tylko do wyświetlania?)
|
|
// if (MoverParameters->CategoryFlag&2)
|
|
{ // przesunięcia są używane po wyrzuceniu pociągu z toru
|
|
vPosition.x += MoverParameters->OffsetTrackH * vLeft.x; // dodanie przesunięcia w bok
|
|
vPosition.z += MoverParameters->OffsetTrackH * vLeft.z; // vLeft jest wektorem poprzecznym
|
|
// if () na przechyłce będzie dodatkowo zmiana wysokości samochodu
|
|
vPosition.y += MoverParameters->OffsetTrackV; // te offsety są liczone przez moverparam
|
|
}
|
|
// obliczanie pozycji sprzęgów do liczenia zderzeń
|
|
auto dir = 0.5 * MoverParameters->Dim.L * vFront; // wektor sprzęgu
|
|
vCoulpler[end::front] = vPosition + dir; // współrzędne sprzęgu na początku
|
|
vCoulpler[end::rear] = vPosition - dir; // współrzędne sprzęgu na końcu
|
|
// bCameraNear=
|
|
// if (bCameraNear) //jeśli istotne są szczegóły (blisko kamery)
|
|
{ // przeliczenie cienia
|
|
TTrack *t0 = Axle0.GetTrack(); // już po przesunięciu
|
|
TTrack *t1 = Axle1.GetTrack();
|
|
if (t0->eEnvironment == e_flat && t1->eEnvironment == e_flat) // może być e_bridge...
|
|
fShade = 0.0; // standardowe oświetlenie
|
|
else
|
|
{ // jeżeli te tory mają niestandardowy stopień zacienienia
|
|
// (e_canyon, e_tunnel)
|
|
if (t0->eEnvironment == t1->eEnvironment)
|
|
{
|
|
switch (t0->eEnvironment)
|
|
{ // typ zmiany oświetlenia
|
|
case e_canyon:
|
|
fShade = 0.65f;
|
|
break; // zacienienie w kanionie
|
|
case e_tunnel:
|
|
fShade = 0.20f;
|
|
break; // zacienienie w tunelu
|
|
}
|
|
}
|
|
else // dwa różne
|
|
{ // liczymy proporcję
|
|
double d = Axle0.GetTranslation(); // aktualne położenie na torze
|
|
if (Axle0.GetDirection() < 0)
|
|
d = t0->Length() - d; // od drugiej strony liczona długość
|
|
d /= fAxleDist; // rozsataw osi procentowe znajdowanie się na torze
|
|
|
|
float shadefrom = 1.0f, shadeto = 1.0f;
|
|
// NOTE, TODO: calculating brightness level is used enough times to warrant encapsulation into a function
|
|
switch( t0->eEnvironment ) {
|
|
case e_canyon: { shadeto = 0.65f; break; }
|
|
case e_tunnel: { shadeto = 0.2f; break; }
|
|
default: {break; }
|
|
}
|
|
switch( t1->eEnvironment ) {
|
|
case e_canyon: { shadefrom = 0.65f; break; }
|
|
case e_tunnel: { shadefrom = 0.2f; break; }
|
|
default: {break; }
|
|
}
|
|
fShade = std::lerp( shadefrom, shadeto, static_cast<float>( d ) );
|
|
/*
|
|
switch (t0->eEnvironment)
|
|
{ // typ zmiany oświetlenia - zakładam, że
|
|
// drugi tor ma e_flat
|
|
case e_canyon:
|
|
fShade = (d * 0.65) + (1.0 - d);
|
|
break; // zacienienie w kanionie
|
|
case e_tunnel:
|
|
fShade = (d * 0.20) + (1.0 - d);
|
|
break; // zacienienie w tunelu
|
|
}
|
|
switch (t1->eEnvironment)
|
|
{ // typ zmiany oświetlenia - zakładam, że
|
|
// pierwszy tor ma e_flat
|
|
case e_canyon:
|
|
fShade = d + (1.0 - d) * 0.65;
|
|
break; // zacienienie w kanionie
|
|
case e_tunnel:
|
|
fShade = d + (1.0 - d) * 0.20;
|
|
break; // zacienienie w tunelu
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
void TDynamicObject::AttachNext(TDynamicObject *Object, int iType)
|
|
{ // Ra: doczepia Object na końcu składu (nazwa funkcji może być myląca)
|
|
// Ra: używane tylko przy wczytywaniu scenerii
|
|
auto const vehicleend { iDirection };
|
|
auto const othervehicleend { Object->iDirection ^ 1 };
|
|
|
|
MoverParameters->Attach( vehicleend, othervehicleend, Object->MoverParameters, iType, true, false );
|
|
// update neighbour data for both affected vehicles
|
|
update_neighbours();
|
|
Object->update_neighbours();
|
|
|
|
// potentially attach automatic coupler adapter to allow the connection
|
|
// HACK: we're doing it after establishin actual connection, as the method needs valid neighbour data
|
|
auto &coupler { MoverParameters->Couplers[ vehicleend ] };
|
|
auto &othercoupler { Object->MoverParameters->Couplers[ ( othervehicleend != 2 ? othervehicleend : coupler.ConnectedNr ) ] };
|
|
|
|
if( coupler.type() != othercoupler.type() ) {
|
|
if( othercoupler.type() == TCouplerType::Automatic ) {
|
|
// try to attach adapter to the vehicle
|
|
attach_coupler_adapter(
|
|
vehicleend,
|
|
true );
|
|
}
|
|
else if( coupler.type() == TCouplerType::Automatic ) {
|
|
// try to attach adapter to the other vehicle
|
|
Object->attach_coupler_adapter(
|
|
othervehicleend != 2 ? othervehicleend : coupler.ConnectedNr,
|
|
true );
|
|
}
|
|
// update distance to neighbours on account of potentially attached adapter
|
|
update_neighbours();
|
|
Object->update_neighbours();
|
|
}
|
|
// potentially adjust vehicle position to avoid collision at the simulation start
|
|
if( MoverParameters->Neighbours[ vehicleend ].distance > -0.001 ) { return; }
|
|
|
|
Object->Move( MoverParameters->Neighbours[ vehicleend ].distance * Object->DirectionGet() );
|
|
// HACK: manually update vehicle position as it's used by neighbour distance update we do next
|
|
Object->MoverParameters->Loc = {
|
|
-Object->vPosition.x,
|
|
Object->vPosition.z,
|
|
Object->vPosition.y };
|
|
// update neighbour distance data after moving our vehicle
|
|
update_neighbours();
|
|
Object->update_neighbours();
|
|
}
|
|
|
|
bool TDynamicObject::UpdateForce(double dt)
|
|
{
|
|
if (!bEnabled)
|
|
return false;
|
|
if( dt > 0 ) {
|
|
// wywalenie WS zależy od ustawienia kierunku
|
|
MoverParameters->ComputeTotalForce( dt );
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// initiates load change by specified amounts, with a platform on specified side
|
|
void TDynamicObject::LoadExchange( int const Disembark, int const Embark, int const Platforms ) {
|
|
/*
|
|
if( ( MoverParameters->Doors.open_control == control_t::passenger )
|
|
|| ( MoverParameters->Doors.open_control == control_t::mixed ) ) {
|
|
// jeśli jedzie do tyłu, to drzwi otwiera odwrotnie
|
|
auto const lewe = ( DirectionGet() > 0 ) ? 1 : 2;
|
|
auto const prawe = 3 - lewe;
|
|
if( Platform & lewe ) {
|
|
MoverParameters->OperateDoors( side::left, true, range_t::local );
|
|
}
|
|
if( Platform & prawe ) {
|
|
MoverParameters->OperateDoors( side::right, true, range_t::local );
|
|
}
|
|
}
|
|
*/
|
|
if( Platforms == 0 ) { return; } // edge case, if there's no accessible platforms discard the request
|
|
|
|
m_exchange.unload_count += Disembark;
|
|
m_exchange.load_count += Embark;
|
|
m_exchange.platforms = Platforms;
|
|
m_exchange.time = 0.0;
|
|
}
|
|
|
|
// calculates time needed to complete current load change
|
|
float TDynamicObject::LoadExchangeTime( int const Platforms ) {
|
|
|
|
m_exchange.platforms = Platforms;
|
|
return LoadExchangeTime();
|
|
}
|
|
|
|
float TDynamicObject::LoadExchangeTime() const {
|
|
|
|
if( m_exchange.unload_count < 0.01 && m_exchange.load_count < 0.01 ) { return 0.f; }
|
|
|
|
auto const baseexchangetime { m_exchange.unload_count / MoverParameters->UnLoadSpeed + m_exchange.load_count / MoverParameters->LoadSpeed };
|
|
auto const nominalexchangespeedfactor { ( m_exchange.platforms == 3 ? 2.f : 1.f ) };
|
|
auto const actualexchangespeedfactor { LoadExchangeSpeed() };
|
|
|
|
return baseexchangetime / ( actualexchangespeedfactor > 0.f ? actualexchangespeedfactor : nominalexchangespeedfactor );
|
|
}
|
|
|
|
// calculates current load exchange rate
|
|
float TDynamicObject::LoadExchangeSpeed() const {
|
|
// platforms (1:left, 2:right, 3:both)
|
|
// with exchange performed on both sides waiting times are halved
|
|
auto exchangespeedfactor { 0.f };
|
|
auto const lewe { DirectionGet() > 0 ? 1 : 2 };
|
|
auto const prawe { 3 - lewe };
|
|
if( m_exchange.platforms & lewe ) {
|
|
exchangespeedfactor += MoverParameters->Doors.instances[side::left].is_open ? 1.f : 0.f;
|
|
}
|
|
if( m_exchange.platforms & prawe ) {
|
|
exchangespeedfactor += MoverParameters->Doors.instances[side::right].is_open ? 1.f : 0.f;
|
|
}
|
|
|
|
return exchangespeedfactor;
|
|
}
|
|
|
|
// update state of load exchange operation
|
|
void TDynamicObject::update_exchange( double const Deltatime ) {
|
|
|
|
// TODO: move offset calculation after initial check, when the loading system is all unified
|
|
update_load_offset();
|
|
|
|
if( m_exchange.unload_count < 0.01 && m_exchange.load_count < 0.01 ) { return; }
|
|
|
|
if( MoverParameters->Vel < 2.0 ) {
|
|
|
|
auto const exchangespeed { LoadExchangeSpeed() };
|
|
|
|
if( exchangespeed < ( m_exchange.platforms == 3 ? 2.f : 1.f ) ) {
|
|
// the exchange isn't performed at optimal rate, or at all. try to open viable vehicle doors to speed it up
|
|
auto const lewe { DirectionGet() > 0 ? 1 : 2 };
|
|
auto const prawe { 3 - lewe };
|
|
if( m_exchange.platforms & lewe
|
|
&& false == (MoverParameters->Doors.instances[side::left].is_open || MoverParameters->Doors.instances[side::left].is_opening) ) {
|
|
// try to open left door
|
|
MoverParameters->OperateDoors( side::left, true, range_t::local );
|
|
}
|
|
if( m_exchange.platforms & prawe
|
|
&& false == (MoverParameters->Doors.instances[side::right].is_open || MoverParameters->Doors.instances[side::right].is_opening) ) {
|
|
// try to open right door
|
|
MoverParameters->OperateDoors( side::right, true, range_t::local );
|
|
}
|
|
}
|
|
|
|
if( exchangespeed > 0.f ) {
|
|
|
|
m_exchange.time += Deltatime;
|
|
while( m_exchange.unload_count > 0.01
|
|
&& m_exchange.time >= 1.0 ) {
|
|
|
|
m_exchange.time -= 1.0;
|
|
auto const exchangesize = std::min( m_exchange.unload_count, MoverParameters->UnLoadSpeed * exchangespeed );
|
|
m_exchange.unload_count -= exchangesize;
|
|
MoverParameters->LoadStatus = 1;
|
|
MoverParameters->LoadAmount = std::max( 0.f, MoverParameters->LoadAmount - exchangesize );
|
|
MoverParameters->ComputeMass();
|
|
update_load_visibility();
|
|
}
|
|
if( m_exchange.unload_count < 0.01 ) {
|
|
// finish any potential unloading operation before adding new load
|
|
// don't load more than can fit
|
|
m_exchange.load_count = std::min( m_exchange.load_count, MoverParameters->MaxLoad - MoverParameters->LoadAmount );
|
|
while( m_exchange.load_count > 0.01
|
|
&& m_exchange.time >= 1.0 ) {
|
|
|
|
m_exchange.time -= 1.0;
|
|
auto const exchangesize = std::min( m_exchange.load_count, MoverParameters->LoadSpeed * exchangespeed );
|
|
m_exchange.load_count -= exchangesize;
|
|
MoverParameters->LoadStatus = 2;
|
|
MoverParameters->LoadAmount = std::min( MoverParameters->MaxLoad, MoverParameters->LoadAmount + exchangesize ); // std::max not strictly needed but, eh
|
|
MoverParameters->ComputeMass();
|
|
update_load_visibility();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if( MoverParameters->Vel > 2.0 ) {
|
|
// if the vehicle moves too fast cancel the exchange
|
|
m_exchange.unload_count = 0;
|
|
m_exchange.load_count = 0;
|
|
}
|
|
|
|
if( m_exchange.unload_count < 0.01
|
|
&& m_exchange.load_count < 0.01 ) {
|
|
|
|
MoverParameters->LoadStatus = 4;
|
|
// if the exchange is completed (or canceled) close the door, if applicable
|
|
if( MoverParameters->Doors.close_control == control_t::passenger
|
|
|| MoverParameters->Doors.close_control == control_t::mixed ) {
|
|
|
|
if( MoverParameters->Vel > 2.0
|
|
|| Random() < (
|
|
// remotely controlled door are more likely to be left open
|
|
MoverParameters->Doors.close_control == control_t::passenger ? 0.75 : 0.50) ) {
|
|
|
|
MoverParameters->OperateDoors( side::left, false, range_t::local );
|
|
MoverParameters->OperateDoors( side::right, false, range_t::local );
|
|
}
|
|
}
|
|
// if the vehicle was emptied potentially switch load visualization model
|
|
if( MoverParameters->LoadAmount == 0 ) {
|
|
MoverParameters->AssignLoad( "" );
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDynamicObject::LoadUpdate() {
|
|
|
|
MoverParameters->LoadStatus &= 1 | 2; // po zakończeniu będzie równe zero
|
|
// przeładowanie modelu ładunku
|
|
if( MoverParameters->LoadTypeChange ) {
|
|
// whether we succeed or not don't try more than once
|
|
MoverParameters->LoadTypeChange = false;
|
|
// bieżąca ścieżka do tekstur to dynamic/...
|
|
Global.asCurrentTexturePath = asBaseDir;
|
|
mdLoad = LoadMMediaFile_mdload( MoverParameters->LoadType.name );
|
|
// TODO: discern from vehicle component which merely uses vehicle directory and has no animations, so it can be initialized outright
|
|
// and actual vehicles which get their initialization after their animations are set up
|
|
if( mdLoad != nullptr ) {
|
|
mdLoad->Init();
|
|
}
|
|
// update bindings between lowpoly sections and potential load chunks placed inside them
|
|
update_load_sections();
|
|
// z powrotem defaultowa sciezka do tekstur
|
|
Global.asCurrentTexturePath = std::string( paths::textures );
|
|
}
|
|
}
|
|
|
|
void
|
|
TDynamicObject::update_load_sections() {
|
|
|
|
SectionLoadOrder.clear();
|
|
|
|
for( auto §ion : Sections ) {
|
|
|
|
section.load = GetSubmodelFromName( mdLoad, section.compartment->pName );
|
|
|
|
if( section.load != nullptr ) {
|
|
// create entry for each load model chunk assigned to the section
|
|
// TBD, TODO: store also pointer to chunk submodel and control its visibility more directly, instead of per-section visibility flag?
|
|
auto loadchunkcount { section.load->count_children() };
|
|
while( loadchunkcount-- ) {
|
|
SectionLoadOrder.push_back( §ion );
|
|
}
|
|
// HACK: disable automatic self-illumination threshold, at least until 3d model update
|
|
if( MoverParameters->CompartmentLights.start_type == start_t::manual ) {
|
|
section.load->SetSelfIllum( 2.0f, true, false );
|
|
}
|
|
}
|
|
}
|
|
shuffle_load_order();
|
|
}
|
|
|
|
void
|
|
TDynamicObject::update_load_visibility() {
|
|
// start with clean load chunk visibility slate
|
|
for( auto §ion : Sections ) {
|
|
section.load_chunks_visible = 0;
|
|
}
|
|
// each entry in load order sequence matches a single chunk of the section it points to
|
|
// the length of load order sequence matches total number of load chunks
|
|
auto const loadpercentage { (
|
|
MoverParameters->MaxLoad == 0.f ?
|
|
0.0 :
|
|
MoverParameters->LoadAmount / MoverParameters->MaxLoad ) };
|
|
auto visiblechunkcount { (
|
|
SectionLoadOrder.empty() ?
|
|
0 :
|
|
static_cast<int>( std::ceil( loadpercentage * SectionLoadOrder.size() - 0.001f ) ) ) };
|
|
for( auto *section : SectionLoadOrder ) {
|
|
if( visiblechunkcount == 0 ) { break; }
|
|
section->load_chunks_visible++;
|
|
--visiblechunkcount;
|
|
}
|
|
}
|
|
|
|
void
|
|
TDynamicObject::update_load_offset() {
|
|
|
|
if( MoverParameters->LoadType.offset_min == 0.f ) { return; }
|
|
|
|
auto const loadpercentage { (
|
|
MoverParameters->MaxLoad == 0.f ?
|
|
0.0 :
|
|
100.0 * MoverParameters->LoadAmount / MoverParameters->MaxLoad ) };
|
|
|
|
LoadOffset = std::lerp( MoverParameters->LoadType.offset_min, 0.f, safe_clamp( 0.0, loadpercentage * 0.01, 1.0 ) );
|
|
}
|
|
|
|
void
|
|
TDynamicObject::shuffle_load_order() {
|
|
|
|
// order of visible load chunks, nothing security related -- see the engines in Globals.h
|
|
std::shuffle( std::begin( SectionLoadOrder ), std::end( SectionLoadOrder ), Global.random_engine ); // NOSONAR
|
|
// shift chunks assigned to corridors to the end of the list, so they show up last
|
|
std::stable_partition(
|
|
std::begin( SectionLoadOrder ), std::end( SectionLoadOrder ),
|
|
[]( vehicle_section const *section ) {
|
|
return section->compartment->pName.find("compartment") == 0 || section->compartment->pName.find("przedzial") == 0; } );
|
|
// NOTE: potentially we're left with a mix of corridor and external section loads
|
|
// but that's not necessarily a wrong outcome, so we leave it this way for the time being
|
|
}
|
|
|
|
/*
|
|
Ra:
|
|
Powinny być dwie funkcje wykonujące aktualizację fizyki. Jedna wykonująca
|
|
krok obliczeń, powtarzana odpowiednią liczbę razy, a druga wykonująca zbiorczą
|
|
aktualzację mniej istotnych elementów.
|
|
Ponadto należało by ustalić odległość składów od kamery i jeśli przekracza
|
|
ona np. 10km, to traktować składy jako uproszczone, np. bez wnikania w siły
|
|
na sprzęgach, opóźnienie działania hamulca itp. Oczywiście musi mieć to pewną
|
|
histerezę czasową, aby te tryby pracy nie przełączały się zbyt szybko.
|
|
*/
|
|
|
|
void TDynamicObject::update_destinations() {
|
|
|
|
if( DestinationSign.sign == nullptr ) { return; }
|
|
|
|
auto const lowvoltagepower { ( MoverParameters->Power24vIsAvailable || MoverParameters->Power110vIsAvailable ) };
|
|
|
|
DestinationSign.sign->fLight = DestinationSign.has_light && lowvoltagepower ? 2.0 : -1.0;
|
|
|
|
// jak są 4 tekstury wymienne, to nie zmieniać rozkładem
|
|
if( std::abs( m_materialdata.multi_textures ) >= 4 ) { return; }
|
|
// TODO: dedicated setting to discern electronic signs, instead of fallback on light presence
|
|
m_materialdata.replacable_skins[ 4 ] = DestinationSign.destination != null_handle && (false == DestinationSign.has_light // physical destination signs remain up until manually changed
|
|
|| (lowvoltagepower // lcd signs are off without power
|
|
&& ctOwner != nullptr)) ? // lcd signs are off for carriages without engine, potentially left on a siding
|
|
DestinationSign.destination :
|
|
DestinationSign.destination_off;
|
|
|
|
update_script_destination();
|
|
}
|
|
|
|
void TDynamicObject::update_script_destination() {
|
|
|
|
if( DestinationSign.script_sign == nullptr ) { return; }
|
|
// only while the sign shows the destination it draws
|
|
if( m_materialdata.replacable_skins[ 4 ] != DestinationSign.destination ) { return; }
|
|
|
|
auto &queue { Application.screens() };
|
|
if( false == queue.due( *DestinationSign.script_sign ) ) { return; }
|
|
// read anew on every refresh, so the sign follows the timetable
|
|
queue.submit( DestinationSign.script_sign, std::make_shared<dictionary_source>( DestinationSign.script_request ), 0 );
|
|
}
|
|
|
|
bool TDynamicObject::Update(double dt, double dt1)
|
|
{
|
|
if (dt1 == 0.0)
|
|
return true; // Ra: pauza
|
|
if (!MoverParameters->PhysicActivation &&
|
|
!MechInside) // to drugie, bo będąc w maszynowym blokuje się fizyka
|
|
return true; // McZapkie: wylaczanie fizyki gdy nie potrzeba
|
|
if (!MyTrack)
|
|
return false; // pojazdy postawione na torach portalowych mają MyTrack==NULL
|
|
if (!bEnabled)
|
|
return false; // a normalnie powinny mieć bEnabled==false
|
|
|
|
double dDOMoveLen;
|
|
// McZapkie: parametry powinny byc pobierane z toru
|
|
if (Axle0.vAngles.z != Axle1.vAngles.z)
|
|
{ // wyliczenie promienia z obrotów osi - modyfikację zgłosił youBy
|
|
ts.R = Axle0.vAngles.z - Axle1.vAngles.z; // różnica może dawać stałą ±M_2PI
|
|
if( ts.R > 15000.0 || ts.R < -15000.0 ) {
|
|
// szkoda czasu na zbyt duże promienie, 4km to promień nie wymagający przechyłki
|
|
ts.R = 0.0;
|
|
}
|
|
else {
|
|
// normalizacja
|
|
if( ts.R > M_PI ) { ts.R -= M_2PI; }
|
|
else if( ts.R < -M_PI ) { ts.R += M_2PI; }
|
|
|
|
if( ts.R != 0.0 ) {
|
|
// sin(0) results in division by zero
|
|
ts.R = -0.5 * MoverParameters->BDist / sin( ts.R * 0.5 );
|
|
}
|
|
}
|
|
}
|
|
else
|
|
ts.R = 0.0;
|
|
// ts.R=ComputeRadius(Axle1.pPosition,Axle2.pPosition,Axle3.pPosition,Axle0.pPosition);
|
|
// Ra: składową pochylenia wzdłużnego mamy policzoną w jednostkowym wektorze
|
|
// vFront
|
|
ts.Len = 1.0; // std::max(MoverParameters->BDist,MoverParameters->ADist);
|
|
ts.dHtrack = -vFront.y; // Axle1.pPosition.y-Axle0.pPosition.y; //wektor
|
|
// między skrajnymi osiami
|
|
// (!!!odwrotny)
|
|
ts.dHrail = (Axle1.GetRoll() + Axle0.GetRoll()) * 0.5; //średnia przechyłka pudła
|
|
// TTrackParam tp;
|
|
tp.Width = MyTrack->fTrackWidth;
|
|
// McZapkie-250202
|
|
tp.friction = MyTrack->Friction() * Global.fFriction * Global.FrictionWeatherFactor;
|
|
tp.CategoryFlag = MyTrack->iCategoryFlag & 15;
|
|
tp.DamageFlag = MyTrack->iDamageFlag;
|
|
tp.QualityFlag = MyTrack->iQualityFlag;
|
|
|
|
// couplers
|
|
if( MoverParameters->Couplers[0].CouplingFlag != coupling::faux
|
|
&& MoverParameters->Couplers[1].CouplingFlag != coupling::faux ) {
|
|
MoverParameters->InsideConsist = true;
|
|
}
|
|
else {
|
|
MoverParameters->InsideConsist = false;
|
|
}
|
|
if( TestFlag( MoverParameters->AIFlag, sound::attachcoupler ) ) {
|
|
auto *driver{ ctOwner ? ctOwner : Mechanik };
|
|
if( driver != nullptr ) {
|
|
driver->CheckVehicles( Connect );
|
|
}
|
|
ClearFlag( MoverParameters->AIFlag, sound::attachcoupler );
|
|
}
|
|
|
|
// napiecie sieci trakcyjnej
|
|
if (MoverParameters->EnginePowerSource.SourceType == TPowerSource::CurrentCollector) { // dla EZT tylko silnikowy
|
|
|
|
tmpTraction.TractionVoltage = std::max( std::abs( MoverParameters->PantRearVolt ), std::abs( MoverParameters->PantFrontVolt ) );
|
|
// jeśli brak zasilania dłużej niż 0.2 sekundy (25km/h pod izolatorem daje 0.15s)
|
|
// Ra 2F1H: prowizorka, trzeba przechować napięcie, żeby nie wywalało WS pod izolatorem
|
|
if( tmpTraction.TractionVoltage > 0.0) {
|
|
NoVoltTime = 0;
|
|
}
|
|
else {
|
|
NoVoltTime += dt1;
|
|
if( NoVoltTime <= 0.2 ) {
|
|
tmpTraction.TractionVoltage = MoverParameters->PantographVoltage;
|
|
}
|
|
else {
|
|
// jeśli jedzie
|
|
if( MoverParameters->Vel > 0.5 ) {
|
|
// Ra 2014-07: doraźna blokada logowania zimnych lokomotyw - zrobić to trzeba inaczej
|
|
if( MoverParameters->Pantographs[end::front].is_active
|
|
|| MoverParameters->Pantographs[end::rear].is_active ) {
|
|
if( MoverParameters->Mains // Ra 15-01: logować tylko, jeśli WS załączony
|
|
&& MoverParameters->GetTrainsetHighVoltage() < 0.1f ) { // yB 16-03: i nie jest to asynchron zasilany z daleka
|
|
// Ra 15-01: bezwzględne współrzędne pantografu nie są dostępne więc lepiej się tego nie zaloguje
|
|
ErrorLog(
|
|
"Bad traction: " + MoverParameters->Name
|
|
+ " lost power for " + to_string( NoVoltTime, 2 ) + " sec. at "
|
|
+ to_string(vPosition) );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
tmpTraction.TractionVoltage = 0.95 * MoverParameters->EnginePowerSource.MaxVoltage;
|
|
}
|
|
tmpTraction.TractionFreq = 0;
|
|
tmpTraction.TractionMaxCurrent = 7500; // Ra: chyba za dużo? powinno wywalać przy 1500
|
|
tmpTraction.TractionResistivity = 0.3;
|
|
|
|
MoverParameters->PantographVoltage = tmpTraction.TractionVoltage;
|
|
// McZapkie: predkosc w torze przekazac do TrackParam
|
|
// McZapkie: Vel ma wymiar [km/h] (absolutny), V ma wymiar [m/s], taka przyjalem notacje
|
|
tp.Velmax = MyTrack->VelocityGet();
|
|
|
|
if (Mechanik)
|
|
{ // Ra 2F3F: do Driver.cpp to przenieść?
|
|
if( Mechanik->primary() ) {
|
|
MoverParameters->EqvtPipePress = GetEPP(); // srednie cisnienie w PG
|
|
}
|
|
if (Mechanik->primary() &&
|
|
(MoverParameters->EngineType == TEngineType::DieselEngine ||
|
|
MoverParameters->EngineType == TEngineType::DieselElectric)
|
|
&& MoverParameters->EIMCtrlType > 0) {
|
|
MoverParameters->CheckEIMIC(dt1);
|
|
if (MoverParameters->SpeedCtrl)
|
|
MoverParameters->CheckSpeedCtrl(dt1);
|
|
MoverParameters->eimic_real = std::min(MoverParameters->eimic,MoverParameters->eimicSpeedCtrl);
|
|
MoverParameters->SendCtrlToNext("EIMIC", MoverParameters->eimic_real, MoverParameters->CabActive);
|
|
}
|
|
if( Mechanik->primary()
|
|
&& MoverParameters->EngineType == TEngineType::ElectricInductionMotor ) {
|
|
// jesli glowny i z asynchronami, to niech steruje hamulcem i napedem lacznie dla calego pociagu/ezt
|
|
auto const kier = DirectionGet() * MoverParameters->CabOccupied > 0;
|
|
auto FED { 0.0 };
|
|
auto np { 0 };
|
|
auto masa { 0.0 };
|
|
auto FrED { 0.0 };
|
|
auto masamax { 0.0 };
|
|
auto FmaxPN { 0.0 };
|
|
auto FfulED { 0.0 };
|
|
auto FmaxED { 0.0 };
|
|
auto Frj { 0.0 };
|
|
auto osie { 0 };
|
|
// 0a. ustal aktualna nastawe zadania sily napedowej i hamowania
|
|
if( MoverParameters->Power < 1
|
|
&& ctOwner != nullptr ) {
|
|
MoverParameters->MainCtrlPos = ctOwner->Controlling()->MainCtrlPos*MoverParameters->MainCtrlPosNo / std::max(1, ctOwner->Controlling()->MainCtrlPosNo);
|
|
MoverParameters->SpeedCtrlValue = ctOwner->Controlling()->SpeedCtrlValue;
|
|
MoverParameters->SpeedCtrlUnit.IsActive = ctOwner->Controlling()->SpeedCtrlUnit.IsActive;
|
|
}
|
|
MoverParameters->CheckEIMIC(dt1);
|
|
MoverParameters->CheckSpeedCtrl(dt1);
|
|
|
|
auto eimic = std::min(MoverParameters->eimic, MoverParameters->eimicSpeedCtrl);
|
|
MoverParameters->eimic_real = eimic;
|
|
// Elf: full braking at once in the lowest position, and in the emergency brake position below it
|
|
if (MoverParameters->EIMCtrlType == 2 && MoverParameters->MainCtrlPos <= MoverParameters->EIMCtrlEmergencyPositions())
|
|
eimic = -1.0;
|
|
MoverParameters->SendCtrlToNext("EIMIC", std::max(0., eimic), MoverParameters->CabActive);
|
|
auto LBR = std::max(-eimic, 0.);
|
|
auto eim_lb = Mechanik->AIControllFlag || !MoverParameters->LocHandleTimeTraxx ? 0 : MoverParameters->eim_localbrake;
|
|
|
|
// 1. ustal wymagana sile hamowania calego pociagu
|
|
// - opoznienie moze byc ustalane na podstawie charakterystyki
|
|
// - opoznienie moze byc ustalane na podstawie mas i cisnien granicznych
|
|
//
|
|
|
|
// 2. ustal mozliwa do realizacji sile hamowania ED
|
|
// - w szczegolnosci powinien brac pod uwage rozne sily hamowania
|
|
for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p;
|
|
kier ? p = p->Next(4) : p = p->Prev(4))
|
|
{
|
|
++np;
|
|
masamax +=
|
|
p->MoverParameters->MBPM
|
|
+ ( p->MoverParameters->MBPM > 1.0 ?
|
|
0.0 :
|
|
p->MoverParameters->Mass )
|
|
+ p->MoverParameters->Mred;
|
|
auto const Nmax = ((p->MoverParameters->P2FTrans * p->MoverParameters->MaxBrakePress[0] -
|
|
p->MoverParameters->BrakeCylSpring) *
|
|
p->MoverParameters->BrakeCylMult[0] -
|
|
p->MoverParameters->BrakeSlckAdj) *
|
|
p->MoverParameters->BrakeCylNo * p->MoverParameters->BrakeRigEff;
|
|
FmaxPN += Nmax * p->MoverParameters->Hamulec->GetFC(
|
|
Nmax / (p->MoverParameters->NAxles * p->MoverParameters->NBpA),
|
|
p->MoverParameters->MED_Vref) *
|
|
1000; // sila hamowania pn
|
|
FmaxED += p->MoverParameters->Mains && p->MoverParameters->DirActive != 0 && p->MoverParameters->InvertersRatio == 1.0 &&
|
|
p->MoverParameters->eimc[eimc_p_Fh] * p->MoverParameters->NPoweredAxles > 0 ?
|
|
p->MoverParameters->eimc[eimc_p_Fh] * 1000 :
|
|
0; // chwilowy max ED -> do rozdzialu sil
|
|
FED -= std::min(p->MoverParameters->eimv[eimv_Fmax], 0.0) *
|
|
1000; // chwilowy max ED -> do rozdzialu sil
|
|
FfulED = std::min(p->MoverParameters->eimv[eimv_Fful], 0.0) *
|
|
1000; // chwilowy max ED -> do rozdzialu sil
|
|
FrED -= std::min(p->MoverParameters->eimv[eimv_Fmax], 0.0) *
|
|
1000; // chwilowo realizowane ED -> do pneumatyki
|
|
Frj += std::max(p->MoverParameters->eimv[eimv_Fmax], 0.0) *
|
|
1000;// chwilowo realizowany napęd -> do utrzymującego
|
|
masa += p->MoverParameters->TotalMass;
|
|
osie += p->MoverParameters->NAxles;
|
|
}
|
|
double RapidMult = 1.0;
|
|
if ((MoverParameters->BrakeDelays & bdelay_P + bdelay_R) == bdelay_P + bdelay_R
|
|
&& MoverParameters->BrakeDelayFlag & bdelay_P)
|
|
RapidMult = MoverParameters->RapidMult;
|
|
|
|
auto const amax = RapidMult * std::min(FmaxPN / masamax, MoverParameters->MED_amax);
|
|
|
|
Mechanik->fMedAmax = amax;
|
|
auto doorisopen {
|
|
false == MoverParameters->Doors.instances[side::left].is_closed
|
|
|| false == MoverParameters->Doors.instances[side::right].is_closed
|
|
|| ( MoverParameters->Doors.permit_needed
|
|
&& ( MoverParameters->Doors.instances[ side::left ].open_permit
|
|
|| MoverParameters->Doors.instances[ side::right ].open_permit ) ) };
|
|
doorisopen &= !(MoverParameters->ReleaseParkingBySpringBrakeWhenDoorIsOpen && MoverParameters->SpringBrake.IsActive);
|
|
|
|
if (MoverParameters->Vel < 0.5 && (eimic < 0 || doorisopen || MoverParameters->Hamulec->GetEDBCP()))
|
|
{
|
|
MoverParameters->ShuntMode = true;
|
|
}
|
|
if (MoverParameters->ShuntMode)
|
|
{
|
|
MoverParameters->ShuntModeAllow = false == doorisopen &&
|
|
LBR < 0.01;
|
|
}
|
|
if( MoverParameters->Vel > 1 && false == doorisopen )
|
|
{
|
|
MoverParameters->ShuntMode = false;
|
|
MoverParameters->ShuntModeAllow = MoverParameters->BrakePress > 0.2 &&
|
|
LBR < 0.01;
|
|
}
|
|
auto Fzad = amax * LBR * masa;
|
|
if ((MoverParameters->BrakeCtrlPos == MoverParameters->Handle->GetPos(bh_EB)
|
|
&& MoverParameters->eimc[eimc_p_abed] < 0.001) ||
|
|
MoverParameters->EmergencyValveFlow > 0)
|
|
Fzad = amax * masa; //pętla bezpieczeństwa - pełne służbowe
|
|
if (MoverParameters->ScndS &&
|
|
MoverParameters->Vel > MoverParameters->eimc[eimc_p_Vh1] && FmaxED > 0)
|
|
{
|
|
Fzad = std::min(LBR * FmaxED, FfulED);
|
|
}
|
|
if (MoverParameters->ShuntMode && eimic <= 0 || doorisopen /*||
|
|
(MoverParameters->V * MoverParameters->DirAbsolute < -0.2)*/)
|
|
{
|
|
auto const sbd { ( MoverParameters->SpringBrake.IsActive && MoverParameters->ReleaseParkingBySpringBrake ? 0.0 : MoverParameters->StopBrakeDecc ) };
|
|
Fzad = std::max( Fzad, sbd * masa );
|
|
}
|
|
if (Fzad > 1 && !MEDLogFile.is_open() && MoverParameters->Vel > 1)
|
|
{
|
|
MEDLogFile.open(
|
|
"MEDLOGS/" + MoverParameters->Name + "_" + std::to_string( ++MEDLogCount ) + ".csv",
|
|
std::ios::in | std::ios::out | std::ios::trunc );
|
|
MEDLogFile << "t\tVel\tMasa\tOsie\tFmaxPN\tFmaxED\tFfulED\tFrED\tFzad\tFzadED\tFzadPN";
|
|
for(int k=1;k<=np;k++)
|
|
{
|
|
MEDLogFile << "\tBP" << k;
|
|
}
|
|
MEDLogFile << "\n";
|
|
MEDLogFile.flush();
|
|
MEDLogInactiveTime = 0;
|
|
MEDLogTime = 0;
|
|
}
|
|
auto FzadED { 0.0 };
|
|
if( LBR > MoverParameters->MED_MinBrakeReqED
|
|
&& ( MoverParameters->BrakeHandle == TBrakeHandle::MHZ_EN57 ?
|
|
(MoverParameters->BrakeOpModeFlag & bom_MED) != 0 :
|
|
MoverParameters->EpFuse ) ) {
|
|
FzadED = std::min( Fzad, FmaxED );
|
|
}
|
|
/*/ELF - wdrazanie ED po powrocie na utrzymanie hamowania - do usuniecia
|
|
if (MoverParameters->EIMCtrlType == 2 && MoverParameters->MainCtrlPos < 2 && MoverParameters->eimic > -0.999)
|
|
{
|
|
FzadED = std::min(FzadED, MED_oldFED);
|
|
} //*/
|
|
//opoznienie wdrazania ED
|
|
if (FzadED > MED_oldFED)
|
|
{
|
|
if (MoverParameters->MED_ED_DelayTimer <= 0) {
|
|
MoverParameters->MED_ED_DelayTimer += dt1;
|
|
if (MoverParameters->MED_ED_DelayTimer > 0) {
|
|
|
|
}
|
|
else {
|
|
FzadED = std::min(FzadED, MED_oldFED);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
FzadED = std::min(FzadED, MED_oldFED);
|
|
MoverParameters->MED_ED_DelayTimer = FrED > 0 ? -MoverParameters->MED_ED_Delay2 : -MoverParameters->MED_ED_Delay1;
|
|
}
|
|
}
|
|
if (MoverParameters->BrakeCtrlPos == MoverParameters->Handle->GetPos(bh_EB)
|
|
&& MoverParameters->eimc[eimc_p_abed] < 0.001)
|
|
FzadED = 0; //pętla bezpieczeństwa - bez ED
|
|
auto const FzadPN = Fzad - FrED * MoverParameters->MED_FrED_factor;
|
|
std::vector<bool> PrzekrF( np );
|
|
float nPrzekrF = 0;
|
|
bool test = true;
|
|
std::vector<float> FzED( np );
|
|
std::vector<float> FzEP( np );
|
|
std::vector<float> FmaxEP( np );
|
|
// 3. ustaw pojazdom sile hamowania ED
|
|
// - proporcjonalnie do mozliwosci
|
|
|
|
// 4. ustal potrzebne dohamowanie pneumatyczne
|
|
// - od sily zadanej trzeba odjac realizowana przez ED
|
|
// 5. w razie potrzeby wlacz hamulec utrzymujacy
|
|
// - gdy zahamowany ma ponizej 2 km/h
|
|
// 6. ustaw pojazdom sile hamowania ep
|
|
// - proporcjonalnie do masy, do liczby osi, rowne cisnienia - jak
|
|
// bedzie, tak bedzie dobrze
|
|
float Fpoj = 0; // MoverParameters->CabOccupied < 0
|
|
////ALGORYTM 2 - KAZDEMU PO ROWNO, ale nie wiecej niz eped * masa
|
|
// 1. najpierw daj kazdemu tyle samo
|
|
int i = 0;
|
|
for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p;
|
|
p = kier == true ? p->Next(4) : p->Prev(4) )
|
|
{
|
|
auto const Nmax = ((p->MoverParameters->P2FTrans * p->MoverParameters->MaxBrakePress[0] -
|
|
p->MoverParameters->BrakeCylSpring) *
|
|
p->MoverParameters->BrakeCylMult[0] -
|
|
p->MoverParameters->BrakeSlckAdj) *
|
|
p->MoverParameters->BrakeCylNo * p->MoverParameters->BrakeRigEff;
|
|
FmaxEP[i] = Nmax *
|
|
p->MoverParameters->Hamulec->GetFC(
|
|
Nmax / (p->MoverParameters->NAxles * p->MoverParameters->NBpA),
|
|
p->MoverParameters->MED_Vref) *
|
|
1000; // sila hamowania pn
|
|
|
|
PrzekrF[i] = false;
|
|
FzED[i] = FmaxED > 0 ? FzadED / FmaxED : 0;
|
|
p->MoverParameters->AnPos =
|
|
MoverParameters->ScndS ? LBR : FzED[i];
|
|
FzEP[ i ] = static_cast<float>( FzadPN * p->MoverParameters->NAxles ) / static_cast<float>( osie );
|
|
++i;
|
|
p->MoverParameters->ShuntMode = MoverParameters->ShuntMode;
|
|
p->MoverParameters->ShuntModeAllow = MoverParameters->ShuntModeAllow;
|
|
}
|
|
while (test)
|
|
{
|
|
test = false;
|
|
i = 0;
|
|
float przek = 0;
|
|
for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p;
|
|
p = kier == true ? p->Next(4) : p->Prev(4) )
|
|
{
|
|
if (FzEP[i] > 0.01 &&
|
|
FzEP[i] > p->MoverParameters->TotalMass * p->MoverParameters->eimc[eimc_p_eped] + std::min(p->MoverParameters->eimv[eimv_Fmax], 0.) * 1000 &&
|
|
!PrzekrF[i])
|
|
{
|
|
float przek1 = -std::min(p->MoverParameters->eimv[eimv_Fmax], 0.) * 1000 +
|
|
FzEP[i] -
|
|
p->MoverParameters->TotalMass *
|
|
p->MoverParameters->eimc[eimc_p_eped] * 0.999;
|
|
PrzekrF[i] = true;
|
|
test = true;
|
|
nPrzekrF++;
|
|
przek1 = std::min(przek1, FzEP[i]);
|
|
FzEP[i] -= przek1;
|
|
if (FzEP[i] < 0)
|
|
FzEP[i] = 0;
|
|
przek += przek1;
|
|
}
|
|
++i;
|
|
}
|
|
i = 0;
|
|
przek = przek / (np - nPrzekrF);
|
|
for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p;
|
|
true == kier ? p = p->Next(4) : p = p->Prev(4))
|
|
{
|
|
if (!PrzekrF[i])
|
|
{
|
|
FzEP[i] += przek;
|
|
}
|
|
++i;
|
|
}
|
|
}
|
|
i = 0;
|
|
for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p;
|
|
true == kier ? p = p->Next(4) : p = p->Prev(4))
|
|
{
|
|
float Nmax = ((p->MoverParameters->P2FTrans * p->MoverParameters->MaxBrakePress[0] -
|
|
p->MoverParameters->BrakeCylSpring) *
|
|
p->MoverParameters->BrakeCylMult[0] -
|
|
p->MoverParameters->BrakeSlckAdj) *
|
|
p->MoverParameters->BrakeCylNo * p->MoverParameters->BrakeRigEff;
|
|
if (FrED > 0.1)
|
|
p->MoverParameters->MED_EPVC_CurrentTime = 0;
|
|
else
|
|
p->MoverParameters->MED_EPVC_CurrentTime += dt1;
|
|
bool EPVC = p->MoverParameters->MED_EPVC && (p->MoverParameters->MED_EPVC_Time < 0 || p->MoverParameters->MED_EPVC_CurrentTime < p->MoverParameters->MED_EPVC_Time);
|
|
float VelC = EPVC ? safe_clamp(p->MoverParameters->Vel, p->MoverParameters->MED_Vmin, p->MoverParameters->MED_Vmax) : p->MoverParameters->MED_Vref;//korekcja EP po prędkości
|
|
float FmaxPoj = Nmax *
|
|
p->MoverParameters->Hamulec->GetFC(
|
|
Nmax / (p->MoverParameters->NAxles * p->MoverParameters->NBpA), VelC) *
|
|
1000; // sila hamowania pn
|
|
p->MoverParameters->LocalBrakePosAEIM = FzEP[i] / FmaxPoj;
|
|
if (p->MoverParameters->LocalBrakePosAEIM>0.009)
|
|
if (p->MoverParameters->P2FTrans * p->MoverParameters->BrakeCylMult[0] *
|
|
p->MoverParameters->MaxBrakePress[0] != 0)
|
|
{
|
|
float x = (p->MoverParameters->BrakeSlckAdj / p->MoverParameters->BrakeCylMult[0] +
|
|
p->MoverParameters->BrakeCylSpring) / (p->MoverParameters->P2FTrans *
|
|
p->MoverParameters->MaxBrakePress[0]);
|
|
p->MoverParameters->LocalBrakePosAEIM = x + (1 - x) * p->MoverParameters->LocalBrakePosAEIM;
|
|
}
|
|
else
|
|
p->MoverParameters->LocalBrakePosAEIM = p->MoverParameters->LocalBrakePosAEIM;
|
|
else
|
|
p->MoverParameters->LocalBrakePosAEIM = 0;
|
|
if (p->MoverParameters->LocHandleTimeTraxx)
|
|
{
|
|
p->MoverParameters->eim_localbrake = eim_lb;
|
|
p->MoverParameters->LocalBrakePosAEIM = std::max(p->MoverParameters->LocalBrakePosAEIM, eim_lb);
|
|
}
|
|
++i;
|
|
}
|
|
|
|
MED[0][0] = masa*0.001;
|
|
MED[0][1] = amax;
|
|
MED[0][2] = Fzad*0.001;
|
|
MED[0][3] = FmaxPN*0.001;
|
|
MED[0][4] = FmaxED*0.001;
|
|
MED[0][5] = FrED*0.001;
|
|
MED[0][6] = FzadPN*0.001;
|
|
MED[0][7] = nPrzekrF;
|
|
|
|
if (MEDLogFile.is_open())
|
|
{
|
|
MEDLogFile << MEDLogTime << "\t" << MoverParameters->Vel << "\t" << masa*0.001 << "\t" << osie << "\t" << FmaxPN*0.001 << "\t" << FmaxED*0.001 << "\t"
|
|
<< FfulED*0.001 << "\t" << FrED*0.001 << "\t" << Fzad*0.001 << "\t" << FzadED*0.001 << "\t" << FzadPN*0.001;
|
|
for (TDynamicObject *p = GetFirstDynamic(MoverParameters->CabOccupied < 0 ? 1 : 0, 4); p;
|
|
true == kier ? p = p->Next(4) : p = p->Prev(4))
|
|
{
|
|
MEDLogFile << "\t" << p->MoverParameters->BrakePress;
|
|
}
|
|
MEDLogFile << "\n";
|
|
if (floor(MEDLogTime + dt1) > floor(MEDLogTime))
|
|
{
|
|
MEDLogFile.flush();
|
|
}
|
|
MEDLogTime += dt1;
|
|
|
|
if (MoverParameters->Vel < 0.1 || MoverParameters->MainCtrlPowerPos() > 0)
|
|
{
|
|
MEDLogInactiveTime += dt1;
|
|
}
|
|
else
|
|
{
|
|
MEDLogInactiveTime = 0;
|
|
}
|
|
if (MEDLogInactiveTime > 5)
|
|
{
|
|
MEDLogFile.flush();
|
|
MEDLogFile.close();
|
|
}
|
|
|
|
}
|
|
|
|
MED_oldFED = FzadED;
|
|
}
|
|
|
|
Mechanik->Update(dt1); // przebłyski świadomości AI
|
|
}
|
|
|
|
// fragment "z EXE Kursa"
|
|
if( MoverParameters->Mains ) { // nie wchodzić w funkcję bez potrzeby
|
|
if( false == (MoverParameters->Power24vIsAvailable || MoverParameters->Power110vIsAvailable)
|
|
/*
|
|
// NOTE: disabled on account of multi-unit setups, where the unmanned unit wouldn't be affected
|
|
&& ( Controller == Humandriver )
|
|
*/
|
|
&& MoverParameters->EngineType != TEngineType::DieselEngine
|
|
&& MoverParameters->EngineType != TEngineType::WheelsDriven ) { // jeśli bateria wyłączona, a nie diesel ani drezyna reczna
|
|
if( MoverParameters->MainSwitch( false, MoverParameters->TrainType == dt_EZT ? range_t::unit : range_t::local ) ) {
|
|
// wyłączyć zasilanie
|
|
// NOTE: we turn off entire EMU, but only the affected unit for other multi-unit consists
|
|
MoverParameters->EventFlag = true;
|
|
// drop pantographs
|
|
// NOTE: this isn't universal behaviour
|
|
// TODO: have this dependant on .fiz-driven flag
|
|
// NOTE: moved to pantspeed calculation part a little later in the function. all remarks and todo still apply
|
|
/*
|
|
MoverParameters->PantFront( false, ( MoverParameters->TrainType == dt_EZT ? range::unit : range::local ) );
|
|
MoverParameters->PantRear( false, ( MoverParameters->TrainType == dt_EZT ? range::unit : range::local ) );
|
|
*/
|
|
}
|
|
}
|
|
}
|
|
|
|
// przekazanie pozycji do fizyki
|
|
// NOTE: coordinate system swap
|
|
// TODO: replace with regular glm vectors
|
|
TLocation const l {
|
|
-vPosition.x,
|
|
vPosition.z,
|
|
vPosition.y };
|
|
TRotation const r {
|
|
0.0,
|
|
0.0,
|
|
modelRot.z };
|
|
// McZapkie-260202 - dMoveLen przyda sie przy stukocie kol
|
|
dDOMoveLen = GetdMoveLen() + MoverParameters->ComputeMovement(dt, dt1, ts, tp, tmpTraction, l, r);
|
|
if( Mechanik ) {
|
|
// dodanie aktualnego przemieszczenia
|
|
Mechanik->MoveDistanceAdd( dDOMoveLen );
|
|
}
|
|
if( simulation::Train != nullptr
|
|
&& simulation::Train->Dynamic() == this ) {
|
|
// update distance meter in user-controlled cab
|
|
// TBD: place the meter on mover logic level?
|
|
simulation::Train->add_distance( dDOMoveLen );
|
|
}
|
|
glm::dvec3 old_pos = vPosition;
|
|
Move(dDOMoveLen);
|
|
|
|
m_future_movement = (vPosition - old_pos) / dt1 * Timer::GetDeltaRenderTime();
|
|
|
|
if (!bEnabled) // usuwane pojazdy nie mają toru
|
|
{ // pojazd do usunięcia
|
|
bDynamicRemove = true; // sprawdzić
|
|
return false;
|
|
}
|
|
ResetdMoveLen();
|
|
|
|
// McZapkie-260202
|
|
// tupot mew, tfu, stukot kol:
|
|
if( MyTrack->fSoundDistance != -1 ) {
|
|
|
|
if( MyTrack->fSoundDistance != dRailLength ) {
|
|
if( dRailLength > 0.0 ) {
|
|
for( auto &axle : m_axlesounds ) {
|
|
axle.distance = axle.offset;
|
|
axle.atjoints = false;
|
|
}
|
|
}
|
|
dRailLength = MyTrack->fSoundDistance;
|
|
}
|
|
if( dRailLength > 0.0 ) {
|
|
if( MoverParameters->Vel > 0 ) {
|
|
// TODO: track quality and/or environment factors as separate subroutine
|
|
auto volume =
|
|
std::lerp(
|
|
0.8, 1.2,
|
|
std::clamp(
|
|
MyTrack->iQualityFlag / 10.0,
|
|
0.0, 1.5 ) );
|
|
switch( MyTrack->eEnvironment ) {
|
|
case e_tunnel: {
|
|
volume *= 1.3;
|
|
break;
|
|
}
|
|
case e_bridge: {
|
|
volume *= 1.5;
|
|
break;
|
|
}
|
|
default: {
|
|
break;
|
|
}
|
|
}
|
|
if( dRailLength > 0.0 ) {
|
|
auto axleindex { 0 };
|
|
auto const directioninconsist { (
|
|
ctOwner == nullptr ?
|
|
1 :
|
|
ctOwner->Vehicle()->DirectionGet() == DirectionGet() ? 1 : -1 ) };
|
|
for( auto &axle : m_axlesounds ) {
|
|
if( axle_passed_joint( axle, dDOMoveLen, directioninconsist )
|
|
&& MoverParameters->Vel > 0.1 ) {
|
|
// NOTE: for combined clatter sound we supply 1/100th of actual value, as the sound module converts does the opposite, converting received (typically) 0-1 values to 0-100 range
|
|
auto const frequency = true == axle.clatter.is_combined() ? MoverParameters->Vel * 0.01 : 1.0;
|
|
axle.clatter
|
|
.pitch( frequency )
|
|
.gain( volume )
|
|
.play();
|
|
// crude bump simulation, drop down on even axles, move back up on
|
|
// the odd ones
|
|
// MoverParameters->AccVert += (MoverParameters->Vel*0.1f) *
|
|
double const headroom = std::clamp(
|
|
MoverParameters->Vmax - ( MoverParameters->Vel + MoverParameters->Vmax * 0.32f ),
|
|
0.0, MoverParameters->Vmax );
|
|
double const jolt = headroom * .05f * ( MyTrack->iDamageFlag * 0.25f );
|
|
if (MyTrack->eType == tt_Normal)
|
|
{
|
|
MoverParameters->AccVert += std::clamp( jolt, 0.0, 4.0 );
|
|
}
|
|
else if (MyTrack->eType == tt_Switch)
|
|
{
|
|
double const accHorizontal = std::clamp( jolt, 0.0, 1.0 ) * ((axleindex % 2) != 0 ? 1 : -1);
|
|
MoverParameters->AccS += accHorizontal;
|
|
MoverParameters->AccN += accHorizontal;
|
|
MoverParameters->AccVert += std::clamp( jolt, 0.0, 2.0 );
|
|
}
|
|
}
|
|
++axleindex;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// McZapkie-260202 end
|
|
|
|
// fragment z EXE Kursa
|
|
/* if (MoverParameters->TrainType==dt_ET42)
|
|
{
|
|
if ((MoverParameters->DynamicBrakeType=dbrake_switch) &&
|
|
((MoverParameters->BrakePress >
|
|
0.2) || ( MoverParameters->PipePress < 0.36 )))
|
|
{
|
|
MoverParameters->StLinFlag=true;
|
|
}
|
|
else
|
|
if ((MoverParameters->DynamicBrakeType=dbrake_switch) &&
|
|
(MoverParameters->BrakePress <
|
|
0.1))
|
|
{
|
|
MoverParameters->StLinFlag=false;
|
|
|
|
}
|
|
} */
|
|
|
|
if (MoverParameters->Vel != 0)
|
|
{ // McZapkie-050402: krecenie kolami:
|
|
glm::dvec3 old_wheels = glm::dvec3(dWheelAngle[0], dWheelAngle[1], dWheelAngle[2]);
|
|
|
|
dWheelAngle[0] += 114.59155902616464175359630962821 * MoverParameters->V * dt1 /
|
|
MoverParameters->WheelDiameterL; // przednie toczne
|
|
dWheelAngle[1] += MoverParameters->nrot * dt1 * 360.0; // napędne
|
|
dWheelAngle[2] += 114.59155902616464175359630962821 * MoverParameters->V * dt1 /
|
|
MoverParameters->WheelDiameterT; // tylne toczne
|
|
|
|
|
|
m_future_wheels_angle = (glm::dvec3(dWheelAngle[0], dWheelAngle[1], dWheelAngle[2]) - old_wheels) / dt1 * Timer::GetDeltaRenderTime();
|
|
|
|
dWheelAngle[0] = clamp_circular( dWheelAngle[0] );
|
|
dWheelAngle[1] = clamp_circular( dWheelAngle[1] );
|
|
dWheelAngle[2] = clamp_circular( dWheelAngle[2] );
|
|
}
|
|
if (pants) // pantograf może być w wagonie kuchennym albo pojeździe rewizyjnym (np. SR61)
|
|
{ // przeliczanie kątów dla pantografów
|
|
double k; // tymczasowy kąt
|
|
double PantDiff;
|
|
TAnimPant *p; // wskaźnik do obiektu danych pantografu
|
|
double fCurrent = (
|
|
MoverParameters->DynamicBrakeFlag && MoverParameters->ResistorsFlag ?
|
|
0 :
|
|
std::abs( MoverParameters->Itot ) * MoverParameters->IsVehicleEIMBrakingFactor() )
|
|
+ MoverParameters->TotalCurrent; // prąd pobierany przez pojazd - bez sensu z tym (TotalCurrent)
|
|
// TotalCurrent to bedzie prad nietrakcyjny (niezwiazany z napedem)
|
|
// fCurrent+=fabs(MoverParameters->Voltage)*1e-6; //prąd płynący przez woltomierz, rozładowuje kondensator orgromowy 4µF
|
|
/*
|
|
double fPantCurrent = fCurrent; // normalnie cały prąd przez jeden pantograf
|
|
if (iAnimType[ANIM_PANTS] > 1) { // a jeśli są dwa pantografy //Ra 1014-11: proteza, trzeba zrobić sensowniej
|
|
if (pants[0].fParamPants->hvPowerWire && pants[1].fParamPants->hvPowerWire) { // i oba podłączone do drutów
|
|
fPantCurrent = fCurrent * 0.5; // to dzielimy prąd równo na oba (trochę bez sensu, ale lepiej tak niż podwoić prąd)
|
|
}
|
|
}
|
|
*/
|
|
// test whether more than one pantograph touches the wire
|
|
// NOTE: we're duplicating lot of code from below
|
|
// TODO: clean this up
|
|
auto activepantographs { 0 };
|
|
for( int idx = 0; idx < iAnimType[ ANIM_PANTS ]; ++idx ) {
|
|
auto const *pantograph { pants[ idx ].fParamPants };
|
|
if( Global.bLiveTraction == false ) {
|
|
if( pantograph->PantWys >= 1.2 ) {
|
|
++activepantographs;
|
|
}
|
|
}
|
|
else {
|
|
if( pantograph->hvPowerWire != nullptr
|
|
&& true == MoverParameters->Pantographs[end::front].is_active
|
|
&& pantograph->PantTraction - pantograph->PantWys < 0.01 ) { // tolerancja niedolegania
|
|
++activepantographs;
|
|
}
|
|
}
|
|
}
|
|
auto const fPantCurrent { fCurrent / std::max( 1, activepantographs ) };
|
|
|
|
for (int i = 0; i < iAnimType[ANIM_PANTS]; ++i)
|
|
{ // pętla po wszystkich pantografach
|
|
p = pants[i].fParamPants;
|
|
if (p->PantWys < 0)
|
|
{ // patograf został połamany, liczony nie będzie
|
|
if (p->fAngleL > p->fAngleL0)
|
|
p->fAngleL -= 0.2 * dt1; // nieco szybciej niż jak dla opuszczania
|
|
if (p->fAngleL < p->fAngleL0)
|
|
p->fAngleL = p->fAngleL0; // kąt graniczny
|
|
if (p->fAngleU < M_PI)
|
|
p->fAngleU += 0.5 * dt1; // górne się musi ruszać szybciej.
|
|
if (p->fAngleU > M_PI)
|
|
p->fAngleU = M_PI;
|
|
if (i & 1) // zgłoszono, że po połamaniu potrafi zostać zasilanie
|
|
MoverParameters->PantRearVolt = 0.0;
|
|
else
|
|
MoverParameters->PantFrontVolt = 0.0;
|
|
continue; // reszta wtedy nie jest wykonywana
|
|
}
|
|
PantDiff = p->PantTraction - p->PantWys; // docelowy-aktualny
|
|
switch (i) // numer pantografu
|
|
{ // trzeba usunąć to rozróżnienie
|
|
case 0:
|
|
if (Global.bLiveTraction == false
|
|
&& p->hvPowerWire == nullptr ) {
|
|
// jeśli nie ma drutu, może pooszukiwać
|
|
MoverParameters->PantFrontVolt =
|
|
p->PantWys >= 1.2 ?
|
|
0.95 * MoverParameters->EnginePowerSource.MaxVoltage :
|
|
0.0;
|
|
}
|
|
else if( true == MoverParameters->Pantographs[end::front].is_active
|
|
&& PantDiff < 0.01 ) // tolerancja niedolegania
|
|
{
|
|
if (p->hvPowerWire) {
|
|
auto const lastvoltage { MoverParameters->PantFrontVolt };
|
|
// TODO: wyliczyć trzeba prąd przypadający na pantograf i wstawić do GetVoltage()
|
|
if( lastvoltage == 0.0 ) {
|
|
// HACK: retrieve the wire voltage for calculations down the road without blowing up the supply
|
|
MoverParameters->PantFrontVolt = p->hvPowerWire->VoltageGet( MoverParameters->PantographVoltage, 0.0 );
|
|
}
|
|
else {
|
|
MoverParameters->PantFrontVolt = p->hvPowerWire->VoltageGet( MoverParameters->PantographVoltage, fPantCurrent );
|
|
if( MoverParameters->PantFrontVolt > 0.0 ) {
|
|
fCurrent -= fPantCurrent; // taki prąd płynie przez powyższy pantograf (unless it doesn't)
|
|
}
|
|
}
|
|
// TODO: refactor reaction to voltage change to mover as sound event for specific pantograph
|
|
if( lastvoltage == 0.0
|
|
&& MoverParameters->PantFrontVolt > 0.0 ) {
|
|
for( auto &pantograph : m_pantographsounds ) {
|
|
if( pantograph.sPantUp.offset().z > 0 ) {
|
|
// limit to pantographs located in the front half of the vehicle
|
|
pantograph.sPantUp.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
MoverParameters->PantFrontVolt = 0.0;
|
|
}
|
|
else
|
|
MoverParameters->PantFrontVolt = 0.0;
|
|
( fPantCurrent > 0.0 ? MoverParameters->EnergyMeter.first : MoverParameters->EnergyMeter.second ) += MoverParameters->PantRearVolt * fPantCurrent * dt1 / 3600000.0;
|
|
break;
|
|
case 1:
|
|
if( false == Global.bLiveTraction
|
|
&& nullptr == p->hvPowerWire ) {
|
|
// jeśli nie ma drutu, może pooszukiwać
|
|
MoverParameters->PantRearVolt =
|
|
p->PantWys >= 1.2 ?
|
|
0.95 * MoverParameters->EnginePowerSource.MaxVoltage :
|
|
0.0;
|
|
}
|
|
else if ( true == MoverParameters->Pantographs[end::rear].is_active
|
|
&& PantDiff < 0.01 )
|
|
{
|
|
if (p->hvPowerWire) {
|
|
auto const lastvoltage { MoverParameters->PantRearVolt };
|
|
// TODO: wyliczyć trzeba prąd przypadający na pantograf i wstawić do GetVoltage()
|
|
if( lastvoltage == 0.0 ) {
|
|
// HACK: retrieve the wire voltage for calculations down the road without blowing up the supply
|
|
MoverParameters->PantRearVolt = p->hvPowerWire->VoltageGet( MoverParameters->PantographVoltage, 0.0 );
|
|
}
|
|
else {
|
|
MoverParameters->PantRearVolt = p->hvPowerWire->VoltageGet( MoverParameters->PantographVoltage, fPantCurrent );
|
|
if( MoverParameters->PantRearVolt > 0.0 ) {
|
|
fCurrent -= fPantCurrent; // taki prąd płynie przez powyższy pantograf (unless it doesn't)
|
|
}
|
|
}
|
|
// TODO: refactor reaction to voltage change to mover as sound event for specific pantograph
|
|
if( lastvoltage == 0.0
|
|
&& MoverParameters->PantRearVolt > 0.0 ) {
|
|
for( auto &pantograph : m_pantographsounds ) {
|
|
if( pantograph.sPantUp.offset().z < 0 ) {
|
|
// limit to pantographs located in the rear half of the vehicle
|
|
pantograph.sPantUp.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
MoverParameters->PantRearVolt = 0.0;
|
|
}
|
|
else {
|
|
// Global.iPause ^= 2;
|
|
MoverParameters->PantRearVolt = 0.0;
|
|
}
|
|
( fPantCurrent > 0.0 ? MoverParameters->EnergyMeter.first : MoverParameters->EnergyMeter.second ) += MoverParameters->PantFrontVolt * fPantCurrent * dt1 / 3600000.0;
|
|
break;
|
|
} // pozostałe na razie nie obsługiwane
|
|
if( MoverParameters->PantPress > (
|
|
MoverParameters->TrainType == dt_EZT ?
|
|
2.45 : // Ra 2013-12: Niebugocław mówi, że w EZT podnoszą się przy 2.5
|
|
3.45 ) ) {
|
|
// z EXE Kursa
|
|
// Ra: wysokość zależy od ciśnienia !!!
|
|
pantspeedfactor = 0.015 * MoverParameters->PantPress * dt1;
|
|
}
|
|
else {
|
|
pantspeedfactor = 0.0;
|
|
}
|
|
if( false == ( MoverParameters->Power24vIsAvailable || MoverParameters->Power110vIsAvailable ) ) {
|
|
pantspeedfactor = 0.0;
|
|
}
|
|
pantspeedfactor = std::max( 0.0, pantspeedfactor );
|
|
k = p->fAngleL;
|
|
if( pantspeedfactor > 0.0
|
|
&& MoverParameters->Pantographs[i].is_active )// jeśli ma być podniesiony
|
|
{
|
|
if (PantDiff > 0.001) // jeśli nie dolega do drutu
|
|
{ // jeśli poprzednia wysokość jest mniejsza niż pożądana, zwiększyć kąt dolnego
|
|
// ramienia zgodnie z ciśnieniem
|
|
if (pantspeedfactor >
|
|
0.55 * PantDiff) // 0.55 to około pochodna kąta po wysokości
|
|
k += 0.55 * PantDiff; // ograniczenie "skoku" w danej klatce
|
|
else
|
|
k += pantspeedfactor; // dolne ramię
|
|
// jeśli przekroczono kąt graniczny, zablokować pantograf
|
|
// (wymaga interwencji pociągu sieciowego)
|
|
}
|
|
else if (PantDiff < -0.001) {
|
|
// drut się obniżył albo pantograf podniesiony za wysoko
|
|
// jeśli wysokość jest zbyt duża, wyznaczyć zmniejszenie kąta
|
|
// jeśli zmniejszenie kąta jest zbyt duże, przejść do trybu łamania pantografu
|
|
// if (PantFrontDiff<-0.05) //skok w dół o 5cm daje złąmanie pantografu
|
|
k += 0.4 * PantDiff; // mniej niż pochodna kąta po wysokości
|
|
} // jeśli wysokość jest dobra, nic więcej nie liczyć
|
|
}
|
|
else
|
|
{ // jeśli ma być na dole
|
|
if (k > p->fAngleL0) // jeśli wyżej niż położenie wyjściowe
|
|
k -= 0.15 * dt1; // ruch w dół
|
|
if (k < p->fAngleL0)
|
|
k = p->fAngleL0; // położenie minimalne
|
|
}
|
|
if (k != p->fAngleL)
|
|
{ //żeby nie liczyć w kilku miejscach ani gdy nie potrzeba
|
|
if (k + p->fAngleU < M_PI)
|
|
{ // o ile nie został osiągnięty kąt maksymalny
|
|
p->fAngleL = k; // zmieniony kąt
|
|
// wyliczyć kąt górnego ramienia z wzoru (a)cosinusowego
|
|
//=acos((b*cos()+c)/a)
|
|
// p->dPantAngleT=acos((1.22*cos(k)+0.535)/1.755); //górne ramię
|
|
p->fAngleU = acos((p->fLenL1 * cos(k) + p->fHoriz) / p->fLenU1); // górne ramię
|
|
// wyliczyć aktualną wysokość z wzoru sinusowego
|
|
// h=a*sin()+b*sin()
|
|
// wysokość całości
|
|
p->PantWys = p->fLenL1 * sin(k) + p->fLenU1 * sin(p->fAngleU) + p->fHeight;
|
|
}
|
|
}
|
|
} // koniec pętli po pantografach
|
|
// TBD, TODO: generate sound event during mover update instead?
|
|
if( MoverParameters->Pantographs[end::front].sound_event != MoverParameters->Pantographs[ end::front ].is_active ) {
|
|
if( MoverParameters->Pantographs[ end::front ].is_active ) {
|
|
// pantograph moving up
|
|
// TBD: add a sound?
|
|
}
|
|
else {
|
|
// pantograph dropping
|
|
for( auto &pantograph : m_pantographsounds ) {
|
|
if( pantograph.sPantDown.offset().z > 0 ) {
|
|
// limit to pantographs located in the front half of the vehicle
|
|
pantograph.sPantDown.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
}
|
|
MoverParameters->Pantographs[ end::front ].sound_event = MoverParameters->Pantographs[ end::front ].is_active;
|
|
}
|
|
if( MoverParameters->Pantographs[ end::rear ].sound_event != MoverParameters->Pantographs[ end::rear ].is_active ) {
|
|
if( MoverParameters->Pantographs[ end::rear ].is_active ) {
|
|
// pantograph moving up
|
|
// TBD: add a sound?
|
|
}
|
|
else {
|
|
// pantograph dropping
|
|
for( auto &pantograph : m_pantographsounds ) {
|
|
if( pantograph.sPantDown.offset().z < 0 ) {
|
|
// limit to pantographs located in the front half of the vehicle
|
|
pantograph.sPantDown.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
}
|
|
MoverParameters->Pantographs[ end::rear ].sound_event = MoverParameters->Pantographs[ end::rear ].is_active;
|
|
}
|
|
}
|
|
else if (MoverParameters->EnginePowerSource.SourceType == TPowerSource::InternalSource)
|
|
if (MoverParameters->EnginePowerSource.PowerType == TPowerType::SteamPower)
|
|
// if (smPatykird1[0])
|
|
{ // Ra: animacja rozrządu parowozu, na razie nieoptymalizowane
|
|
/* //Ra: tymczasowo wyłączone ze względu na porządkowanie animacji
|
|
pantografów
|
|
double fi,dx,c2,ka,kc;
|
|
double sin_fi,cos_fi;
|
|
double L1=1.6688888888888889;
|
|
double L2=5.6666666666666667; //2550/450
|
|
double Lc=0.4;
|
|
double L=5.686422222; //2558.89/450
|
|
double G1,G2,G3,ksi,sin_ksi,gam;
|
|
double G1_2,G2_2,G3_2; //kwadraty
|
|
//ruch tłoków oraz korbowodów
|
|
for (int i=0;i<=1;++i)
|
|
{//obie strony w ten sam sposób
|
|
fi=DegToRad(dWheelAngle[1]+(i?pant2x:pant1x)); //kąt obrotu koła dla
|
|
tłoka 1
|
|
sin_fi=sin(fi);
|
|
cos_fi=cos(fi);
|
|
dx=panty*cos_fi+sqrt(panth*panth-panty*panty*sin_fi*sin_fi)-panth;
|
|
//nieoptymalne
|
|
if (smPatykird1[i]) //na razie zabezpieczenie
|
|
smPatykird1[i]->SetTranslate(float3(dx,0,0));
|
|
ka=-asin(panty/panth)*sin_fi;
|
|
if (smPatykirg1[i]) //na razie zabezpieczenie
|
|
smPatykirg1[i]->SetRotateXYZ(vector3(RadToDeg(ka),0,0));
|
|
//smPatykirg1[0]->SetRotate(float3(0,1,0),RadToDeg(fi)); //obracamy
|
|
//ruch drążka mimośrodkowego oraz jarzma
|
|
//korzystałem z pliku PDF "mm.pdf" (opis czworoboku
|
|
korbowo-wahaczowego):
|
|
//"MECHANIKA MASZYN. Szkic wykładu i laboratorium komputerowego."
|
|
//Prof. dr hab. inż. Jerzy Zajączkowski, 2007, Politechnika Łódzka
|
|
//L1 - wysokość (w pionie) osi jarzma ponad osią koła
|
|
//L2 - odległość w poziomie osi jarzma od osi koła
|
|
//Lc - długość korby mimośrodu na kole
|
|
//Lr - promień jarzma =1.0 (pozostałe przeliczone proporcjonalnie)
|
|
//L - długość drążka mimośrodowego
|
|
//fi - kąt obrotu koła
|
|
//ksi - kąt obrotu jarzma (od pionu)
|
|
//gam - odchylenie drążka mimośrodowego od poziomu
|
|
//G1=(Lr*Lr+L1*L1+L2*L2+Kc*Lc-L*L-2.0*Lc*L2*cos(fi)+2.0*Lc*L1*sin(fi))/(Lr*Lr);
|
|
//G2=2.0*(L2-Lc*cos(fi))/Lr;
|
|
//G3=2.0*(L1-Lc*sin(fi))/Lr;
|
|
fi=DegToRad(dWheelAngle[1]+(i?pant2x:pant1x)-96.77416667); //kąt
|
|
obrotu koła dla
|
|
tłoka 1
|
|
//1) dla dWheelAngle[1]=0° korba jest w dół, a mimośród w stronę
|
|
jarzma, czyli
|
|
fi=-7°
|
|
//2) dla dWheelAngle[1]=90° korba jest do tyłu, a mimośród w dół,
|
|
czyli fi=83°
|
|
sin_fi=sin(fi);
|
|
cos_fi=cos(fi);
|
|
G1=(1.0+L1*L1+L2*L2+Lc*Lc-L*L-2.0*Lc*L2*cos_fi+2.0*Lc*L1*sin_fi);
|
|
G1_2=G1*G1;
|
|
G2=2.0*(L2-Lc*cos_fi);
|
|
G2_2=G2*G2;
|
|
G3=2.0*(L1-Lc*sin_fi);
|
|
G3_2=G3*G3;
|
|
sin_ksi=(G1*G2-G3*_fm_sqrt(G2_2+G3_2-G1_2))/(G2_2+G3_2); //x1 (minus
|
|
delta)
|
|
ksi=asin(sin_ksi); //kąt jarzma
|
|
if (smPatykirg2[i])
|
|
smPatykirg2[i]->SetRotateXYZ(vector3(RadToDeg(ksi),0,0)); //obrócenie
|
|
jarzma
|
|
//1) ksi=-23°, gam=
|
|
//2) ksi=10°, gam=
|
|
//gam=acos((L2-sin_ksi-Lc*cos_fi)/L); //kąt od poziomu, liczony
|
|
względem poziomu
|
|
//gam=asin((L1-cos_ksi-Lc*sin_fi)/L); //kąt od poziomu, liczony
|
|
względem pionu
|
|
gam=atan2((L1-cos(ksi)+Lc*sin_fi),(L2-sin_ksi+Lc*cos_fi)); //kąt od
|
|
poziomu
|
|
if (smPatykird2[i]) //na razie zabezpieczenie
|
|
smPatykird2[i]->SetRotateXYZ(vector3(RadToDeg(-gam-ksi),0,0));
|
|
//obrócenie drążka
|
|
mimośrodowego
|
|
}
|
|
*/
|
|
}
|
|
|
|
if (MoverParameters->EnginePowerSource.SourceType == TPowerSource::CurrentCollector
|
|
&& MoverParameters->EnginePowerSource.CollectorParameters.FakePower) {
|
|
MoverParameters->PantRearVolt = 0.95 * MoverParameters->EnginePowerSource.MaxVoltage;
|
|
MoverParameters->PantFrontVolt = 0.95 * MoverParameters->EnginePowerSource.MaxVoltage;
|
|
}
|
|
|
|
// wipers
|
|
if (dWiperPos.size() > 0) // tylko dla wozow ze zdefiniowanymi wycierakami
|
|
{
|
|
for (int i = 0; i < dWiperPos.size(); i++) // iteracja po kazdej wycieraczce
|
|
{
|
|
bool wipersActive;
|
|
auto const bytesum = MoverParameters->WiperList[MoverParameters->wiperSwitchPos].byteSum;
|
|
// rozroznienie kabinowe
|
|
if (MoverParameters->CabActive == 1)
|
|
{
|
|
wipersActive = (bytesum & 1 << i) != 0 && MoverParameters->Battery;
|
|
}
|
|
else if (MoverParameters->CabActive == -1)
|
|
{
|
|
// odwroconie indexow wycieraczek
|
|
wipersActive = (bytesum & 1 << dWiperPos.size() - 1 - i) != 0 && MoverParameters->Battery;
|
|
}
|
|
else {
|
|
wipersActive = false;
|
|
}
|
|
|
|
auto const currentWiperParams = MoverParameters->WiperList[workingSwitchPos[i]];
|
|
|
|
wiperOutTimer[i] += dt1; // aktualizujemy zegarek
|
|
wiperParkTimer[i] += dt1; // aktualizujemy zegarek
|
|
|
|
if (wipersActive || dWiperPos[i] > 0.0) // zeby wrocily do trybu park
|
|
{
|
|
if (dWiperPos[i] > 0.0 && !wipersActive) // bezwzgledny powrot do zera
|
|
{
|
|
dWiperPos[i] = std::max(0.0, dWiperPos[i] - 1.f / currentWiperParams.WiperSpeed * dt1);
|
|
}
|
|
else {
|
|
|
|
if (dWiperPos[i] < 1.0 && !wiperDirection[i] && wiperParkTimer[i] > currentWiperParams.interval)
|
|
// go out
|
|
{
|
|
if (!sWiperFromParkPlayed)
|
|
{
|
|
sWiperFromPark.play(sound_flags::exclusive);
|
|
sWiperFromParkPlayed = true;
|
|
}
|
|
dWiperPos[i] = std::min(1.0, dWiperPos[i] + 1.f / currentWiperParams.WiperSpeed * dt1);
|
|
}
|
|
if (dWiperPos[i] > 0.0 && wiperDirection[i] && wiperOutTimer[i] > currentWiperParams.outBackDelay)
|
|
// return back
|
|
{
|
|
if (!sWiperToParkPlayed)
|
|
{
|
|
sWiperToPark.play(sound_flags::exclusive);
|
|
sWiperToParkPlayed = true;
|
|
}
|
|
dWiperPos[i] = std::max(0.0, dWiperPos[i] - 1.f / currentWiperParams.WiperSpeed * dt1);
|
|
}
|
|
if (dWiperPos[i] >= 1.0) // we reached end
|
|
{
|
|
sWiperFromPark.stop();
|
|
sWiperFromParkPlayed = false;
|
|
wiperParkTimer[i] = 0.0;
|
|
wiperDirection[i] = true; // switch direction
|
|
}
|
|
if (dWiperPos[i] <= 0.0)
|
|
{
|
|
// when in park position
|
|
sWiperToPark.stop();
|
|
sWiperToParkPlayed = false;
|
|
wiperOutTimer[i] = 0.0;
|
|
wiperDirection[i] = false;
|
|
workingSwitchPos[i] = MoverParameters->wiperSwitchPos; // update configuration
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// mirrors
|
|
auto const mirrorleft { dMirrorMoveL };
|
|
auto const mirrorright { dMirrorMoveR };
|
|
if( MoverParameters->Vel > MoverParameters->MirrorVelClose
|
|
|| MoverParameters->CabActive == 0 && activation::mirrors
|
|
|| MoverParameters->MirrorForbidden ) {
|
|
// automatically fold mirrors when above velocity threshold
|
|
if( dMirrorMoveL > 0.0 ) {
|
|
dMirrorMoveL = std::max(
|
|
0.0,
|
|
dMirrorMoveL - 1.0 * dt1 );
|
|
}
|
|
if( dMirrorMoveR > 0.0 ) {
|
|
dMirrorMoveR = std::max(
|
|
0.0,
|
|
dMirrorMoveR - 1.0 * dt1 );
|
|
}
|
|
}
|
|
else {
|
|
// unfold mirror on the side with open doors, if not moving too fast
|
|
if( dMirrorMoveL < 1.0
|
|
&& true == MoverParameters->Doors.instances[side::left].open_permit ) {
|
|
dMirrorMoveL = std::min(
|
|
1.0,
|
|
dMirrorMoveL + 1.0 * dt1 );
|
|
}
|
|
if( dMirrorMoveR < 1.0
|
|
&& true == MoverParameters->Doors.instances[side::right].open_permit ) {
|
|
dMirrorMoveR = std::min(
|
|
1.0,
|
|
dMirrorMoveR + 1.0 * dt1 );
|
|
}
|
|
}
|
|
play_mirror_sounds( side::left, m_mirrormotion[ side::left ].update( dMirrorMoveL - mirrorleft ) );
|
|
play_mirror_sounds( side::right, m_mirrormotion[ side::right ].update( dMirrorMoveR - mirrorright ) );
|
|
|
|
// compartment lights
|
|
// if the vehicle has a controller, we base the light state on state of the controller otherwise we check the vehicle itself
|
|
if( ctOwner != nullptr ? SectionLightsActive != MoverParameters->CompartmentLights.is_active :
|
|
Mechanik != nullptr ? SectionLightsActive != MoverParameters->CompartmentLights.is_active :
|
|
SectionLightsActive ) { // without controller switch the lights off
|
|
toggle_lights();
|
|
}
|
|
|
|
if (MoverParameters->InactiveCabPantsCheck)
|
|
{
|
|
pants_up();
|
|
MoverParameters->InactiveCabPantsCheck = false;
|
|
}
|
|
|
|
if( MoverParameters->LoadStatus ) {
|
|
LoadUpdate(); // zmiana modelu ładunku
|
|
}
|
|
update_exchange( dt );
|
|
|
|
return true; // Ra: chyba tak?
|
|
}
|
|
|
|
void TDynamicObject::pants_up()
|
|
{
|
|
TDynamicObject *d = this;
|
|
bool isAnyPantUp = false;
|
|
while (d) {
|
|
for (auto &item : d->MoverParameters->Pantographs)
|
|
{
|
|
isAnyPantUp |= item.is_active;
|
|
}
|
|
d = d->Next(4); // pozostałe też
|
|
}
|
|
d = Prev(4);
|
|
while (d) {
|
|
for (auto &item : d->MoverParameters->Pantographs)
|
|
{
|
|
isAnyPantUp |= item.is_active;
|
|
}
|
|
d = d->Prev(4); // w drugą stronę też
|
|
}
|
|
if (isAnyPantUp)
|
|
{
|
|
d = this;
|
|
while (d) {
|
|
d->MoverParameters->OperatePantographValve(end::front, operation_t::enable, range_t::local);
|
|
d->MoverParameters->OperatePantographValve(end::rear, operation_t::enable, range_t::local);
|
|
d = d->Next(4); // pozostałe też
|
|
}
|
|
d = Prev(4);
|
|
while (d) {
|
|
d->MoverParameters->OperatePantographValve(end::front, operation_t::enable, range_t::local);
|
|
d->MoverParameters->OperatePantographValve(end::rear, operation_t::enable, range_t::local);
|
|
d = d->Prev(4); // w drugą stronę też
|
|
}
|
|
}
|
|
}
|
|
|
|
glm::dvec3 TDynamicObject::get_future_movement() const
|
|
{
|
|
return m_future_movement;
|
|
}
|
|
|
|
void TDynamicObject::move_set(double distance)
|
|
{
|
|
TDynamicObject *d = this;
|
|
while( d ) {
|
|
d->Move( distance * d->DirectionGet() );
|
|
d = d->Next(); // pozostałe też
|
|
}
|
|
d = Prev();
|
|
while( d ) {
|
|
d->Move( distance * d->DirectionGet() );
|
|
d = d->Prev(); // w drugą stronę też
|
|
}
|
|
}
|
|
|
|
bool TDynamicObject::FastUpdate(double dt)
|
|
{
|
|
if (dt == 0.0)
|
|
return true; // Ra: pauza
|
|
double dDOMoveLen;
|
|
if (!MoverParameters->PhysicActivation)
|
|
return true; // McZapkie: wylaczanie fizyki gdy nie potrzeba
|
|
|
|
if (!bEnabled)
|
|
return false;
|
|
|
|
// NOTE: coordinate system swap
|
|
// TODO: replace with regular glm vectors
|
|
TLocation const l {
|
|
-vPosition.x,
|
|
vPosition.z,
|
|
vPosition.y };
|
|
TRotation const r {
|
|
0.0,
|
|
0.0,
|
|
modelRot.z };
|
|
// McZapkie: parametry powinny byc pobierane z toru
|
|
// ts.R=MyTrack->fRadius;
|
|
// ts.Len= std::max(MoverParameters->BDist,MoverParameters->ADist);
|
|
// ts.dHtrack=Axle1.pPosition.y-Axle0.pPosition.y;
|
|
// ts.dHrail=((Axle1.GetRoll())+(Axle0.GetRoll()))*0.5f;
|
|
// tp.Width=MyTrack->fTrackWidth;
|
|
// McZapkie-250202
|
|
// tp.friction= MyTrack->fFriction;
|
|
// tp.CategoryFlag= MyTrack->iCategoryFlag&15;
|
|
// tp.DamageFlag=MyTrack->iDamageFlag;
|
|
// tp.QualityFlag=MyTrack->iQualityFlag;
|
|
dDOMoveLen = MoverParameters->FastComputeMovement(dt, ts, tp, l, r); // ,ts,tp,tmpTraction);
|
|
// Move(dDOMoveLen);
|
|
// ResetdMoveLen();
|
|
FastMove(dDOMoveLen);
|
|
|
|
if( MoverParameters->LoadStatus ) {
|
|
LoadUpdate(); // zmiana modelu ładunku
|
|
}
|
|
update_exchange( dt );
|
|
|
|
return true; // Ra: chyba tak?
|
|
}
|
|
|
|
// McZapkie-040402: liczenie pozycji uwzgledniajac wysokosc szyn itp.
|
|
// vector3 TDynamicObject::GetPosition()
|
|
//{//Ra: pozycja pojazdu jest liczona zaraz po przesunięciu
|
|
// return vPosition;
|
|
//};
|
|
|
|
void TDynamicObject::TurnOff()
|
|
{ // wyłączenie rysowania submodeli zmiennych dla
|
|
// egemplarza pojazdu
|
|
btnOn = false;
|
|
btCoupler1.TurnOff();
|
|
btCoupler2.TurnOff();
|
|
btCPneumatic1.TurnOff();
|
|
btCPneumatic1r.TurnOff();
|
|
btCPneumatic2.TurnOff();
|
|
btCPneumatic2r.TurnOff();
|
|
btPneumatic1.TurnOff();
|
|
btPneumatic1r.TurnOff();
|
|
btPneumatic2.TurnOff();
|
|
btPneumatic2r.TurnOff();
|
|
btCCtrl1.Turn( false );
|
|
btCCtrl2.Turn( false );
|
|
btCPass1.Turn( false );
|
|
btCPass2.Turn( false );
|
|
m_endsignal12.Turn( false );
|
|
m_endsignal13.Turn( false );
|
|
m_endsignal22.Turn( false );
|
|
m_endsignal23.Turn( false );
|
|
m_endsignals1.Turn( false );
|
|
m_endsignals2.Turn( false );
|
|
m_endtab1.Turn( false );
|
|
m_endtab2.Turn( false );
|
|
m_headlamp11.TurnOff();
|
|
m_headlamp12.TurnOff();
|
|
m_headlamp13.TurnOff();
|
|
m_headlamp21.TurnOff();
|
|
m_headlamp22.TurnOff();
|
|
m_headlamp23.TurnOff();
|
|
m_highbeam12.TurnOff();
|
|
m_highbeam13.TurnOff();
|
|
m_highbeam22.TurnOff();
|
|
m_highbeam23.TurnOff();
|
|
m_headsignal12.TurnOff();
|
|
m_headsignal13.TurnOff();
|
|
m_headsignal22.TurnOff();
|
|
m_headsignal23.TurnOff();
|
|
btMechanik1.Turn( false );
|
|
btMechanik2.Turn( false );
|
|
btShutters1.Turn( false );
|
|
btShutters2.Turn( false );
|
|
};
|
|
|
|
// przeliczanie dźwięków, bo będzie słychać bez wyświetlania sektora z pojazdem
|
|
void TDynamicObject::RenderSounds() {
|
|
|
|
if( false == simulation::is_ready ) { return; }
|
|
if( Global.iPause != 0 ) { return; }
|
|
|
|
if( m_startjoltplayed
|
|
&& ( std::abs(MoverParameters->AccSVBased) < 0.01
|
|
|| GetVelocity() < 0.01 ) ) {
|
|
// if the vehicle comes to a stop set the movement jolt to play when it starts moving again
|
|
m_startjoltplayed = false;
|
|
}
|
|
|
|
auto const dt{ Timer::GetDeltaRenderTime() };
|
|
m_powertrainsounds.render( *MoverParameters, dt );
|
|
|
|
auto volume{ 0.0 };
|
|
auto frequency{ 1.0 };
|
|
|
|
// NBMX dzwiek przetwornicy
|
|
if( MoverParameters->ConverterFlag ) {
|
|
if( MoverParameters->EngineType == TEngineType::ElectricSeriesMotor ) {
|
|
auto const voltage { std::max( MoverParameters->GetTrainsetHighVoltage(), MoverParameters->PantographVoltage ) };
|
|
if( voltage > 0.0 ) {
|
|
// NOTE: we do sound modulation here to avoid sudden jump on voltage loss
|
|
frequency = voltage / (MoverParameters->NominalVoltage * MoverParameters->RList[MoverParameters->RlistSize].Mn);
|
|
frequency *= sConverter.m_frequencyfactor + sConverter.m_frequencyoffset;
|
|
sConverter.pitch( std::clamp( frequency, 0.75, 1.25 ) ); // arbitrary limits )
|
|
}
|
|
}
|
|
else {
|
|
frequency = sConverter.m_frequencyoffset + sConverter.m_frequencyfactor * frequency;
|
|
sConverter.pitch( std::clamp( frequency, 0.75, 1.25 ) ); // arbitrary limits )
|
|
}
|
|
sConverter.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
sConverter.stop();
|
|
}
|
|
|
|
// Odtworzenie dzwieku wentylatora rezystora hamowania
|
|
|
|
if (MoverParameters->BRVentilators)
|
|
{
|
|
sBRVent.play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else
|
|
{
|
|
sBRVent.stop();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( MoverParameters->CompressorSpeed > 0.0 ) {
|
|
// McZapkie! - dzwiek compressor.wav tylko gdy dziala sprezarka
|
|
if( MoverParameters->CompressorFlag ) {
|
|
// for compressor coupled with the diesel engine sound pitch is driven by engine revolutions
|
|
if( MoverParameters->CompressorPower == 3 ) {
|
|
// presume the compressor sound is recorded for idle revolutions
|
|
// increase the pitch according to increase of engine revolutions
|
|
auto const enginefactor {
|
|
std::clamp( // try to keep the sound pitch in semi-reasonable range
|
|
MoverParameters->EngineMaxRPM() / MoverParameters->EngineIdleRPM() * MoverParameters->EngineRPMRatio(),
|
|
0.5, 2.5 ) };
|
|
sCompressor.pitch( enginefactor );
|
|
sCompressorIdle.pitch( enginefactor );
|
|
}
|
|
if( sCompressorIdle.empty() ) {
|
|
// legacy sound path, if there's no dedicated idle sound
|
|
sCompressor.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
// enhanced sound path, with dedicated sound for idling compressor
|
|
if( MoverParameters->CompressorGovernorLock ) {
|
|
sCompressor.stop();
|
|
sCompressorIdle.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
sCompressor.play( sound_flags::exclusive | sound_flags::looping );
|
|
sCompressorIdle.stop();
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
sCompressor.stop();
|
|
sCompressorIdle.stop();
|
|
}
|
|
}
|
|
|
|
// Winger 160404 - dzwiek malej sprezarki
|
|
if( MoverParameters->PantCompFlag ) {
|
|
sSmallCompressor.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
sSmallCompressor.stop();
|
|
}
|
|
|
|
// heater sound
|
|
{
|
|
auto const isdieselenginepowered { MoverParameters->EngineType == TEngineType::DieselElectric || MoverParameters->EngineType == TEngineType::DieselEngine };
|
|
if( true == MoverParameters->Heating
|
|
&& ( false == isdieselenginepowered
|
|
|| std::abs(MoverParameters->enrot) > 0.01 ) ) {
|
|
sHeater
|
|
.pitch( true == sHeater.is_combined() ?
|
|
std::abs( MoverParameters->enrot ) * 60.f * 0.01f :
|
|
1.f )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
sHeater.stop();
|
|
}
|
|
}
|
|
|
|
// battery sound
|
|
if( MoverParameters->Battery ) {
|
|
m_batterysound.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
m_batterysound.stop();
|
|
}
|
|
|
|
// brake system and braking sounds:
|
|
|
|
// brake cylinder piston
|
|
auto const brakepressureratio { std::max( 0.0, MoverParameters->BrakePress ) / std::max( 1.0, MoverParameters->MaxBrakePress[ 3 ] ) };
|
|
if( m_lastbrakepressure != -1.f ) {
|
|
// HACK: potentially reset playback of opening bookend sounds
|
|
if( false == m_brakecylinderpistonadvance.is_playing() ) {
|
|
m_brakecylinderpistonadvance.stop();
|
|
}
|
|
if( false == m_brakecylinderpistonrecede.is_playing() ) {
|
|
m_brakecylinderpistonrecede.stop();
|
|
}
|
|
// actual sound playback
|
|
auto const quantizedratio { static_cast<int>( 15 * brakepressureratio ) };
|
|
auto const lastbrakepressureratio { std::max( 0.f, m_lastbrakepressure ) / std::max( 1.0, MoverParameters->MaxBrakePress[ 3 ] ) };
|
|
auto const quantizedratiochange { quantizedratio - static_cast<int>( 15 * lastbrakepressureratio ) };
|
|
if( quantizedratiochange > 0 ) {
|
|
m_brakecylinderpistonadvance
|
|
.pitch(
|
|
true == m_brakecylinderpistonadvance.is_combined() ?
|
|
quantizedratio * 0.01f :
|
|
m_brakecylinderpistonadvance.m_frequencyoffset + m_brakecylinderpistonadvance.m_frequencyfactor * 1.f )
|
|
.play();
|
|
}
|
|
else if( quantizedratiochange < 0 ) {
|
|
m_brakecylinderpistonrecede
|
|
.pitch( true == m_brakecylinderpistonrecede.is_combined() ?
|
|
quantizedratio * 0.01f :
|
|
m_brakecylinderpistonrecede.m_frequencyoffset + m_brakecylinderpistonrecede.m_frequencyfactor * 1.f )
|
|
.play();
|
|
}
|
|
}
|
|
|
|
// epbrake - epcompact
|
|
if (MoverParameters->BrakeSystem == TBrakeSystem::ElectroPneumatic && MoverParameters->LocHandle) {
|
|
auto const epbrakepressureratio{ std::min( std::max( 0.0, MoverParameters->LocHandle->GetCP() ) / std::max( 1.0, MoverParameters->MaxBrakePress[0] ),
|
|
m_epbrakepressurechangedectimer > -1.0f ?
|
|
std::max( MoverParameters->LocalBrakePosAEIM, MoverParameters->Hamulec->GetEDBCP() / MoverParameters->MaxBrakePress[3]) :
|
|
1.0 ) };
|
|
if ( m_lastepbrakepressure != -1.f ) {
|
|
// HACK: potentially reset playback of opening bookend sounds
|
|
if ( false == m_epbrakepressureincrease.is_playing() ) {
|
|
m_epbrakepressureincrease.stop();
|
|
}
|
|
if ( false == m_epbrakepressuredecrease.is_playing() ) {
|
|
m_epbrakepressuredecrease.stop();
|
|
}
|
|
m_epbrakepressurechangeinctimer += dt;
|
|
m_epbrakepressurechangedectimer += dt;
|
|
// actual sound playback
|
|
auto const epquantizedratio{ static_cast<int>( 50 * epbrakepressureratio) };
|
|
auto const lastepbrakepressureratio { std::max( 0.f, m_lastepbrakepressure ) / std::max( 1.0, MoverParameters->MaxBrakePress[0] ) };
|
|
auto const epquantizedratiochange { epquantizedratio - static_cast<int>( 50 * lastepbrakepressureratio ) };
|
|
if ( epquantizedratiochange > 0 && m_epbrakepressurechangeinctimer > 0.05f) {
|
|
m_epbrakepressureincrease
|
|
.pitch(
|
|
true == m_epbrakepressureincrease.is_combined() ?
|
|
epquantizedratio * 0.01f :
|
|
m_epbrakepressureincrease.m_frequencyoffset + m_epbrakepressureincrease.m_frequencyfactor * 1.f )
|
|
.play();
|
|
m_epbrakepressurechangeinctimer = 0;
|
|
}
|
|
else if ( epquantizedratiochange < 0 && m_epbrakepressurechangedectimer > 0.3f) {
|
|
m_epbrakepressuredecrease
|
|
.pitch(true == m_epbrakepressuredecrease.is_combined() ?
|
|
-epquantizedratiochange * 0.01f :
|
|
m_epbrakepressuredecrease.m_frequencyoffset + m_epbrakepressuredecrease.m_frequencyfactor * 1.f )
|
|
.play();
|
|
m_epbrakepressurechangedectimer = 0;
|
|
}
|
|
}
|
|
if ( m_epbrakepressurechangeinctimer == 0 || m_epbrakepressurechangedectimer == 0 )
|
|
m_lastepbrakepressure = std::min( MoverParameters->LocHandle->GetCP(),
|
|
MoverParameters->LocalBrakePosAEIM * std::max( 1.0, MoverParameters->MaxBrakePress[0] ) );
|
|
}
|
|
|
|
// emergency brake
|
|
if( MoverParameters->EmergencyValveFlow > 0.025 ) {
|
|
// smooth out air flow rate
|
|
m_emergencybrakeflow = m_emergencybrakeflow == 0.0 ? MoverParameters->EmergencyValveFlow : std::lerp(m_emergencybrakeflow, MoverParameters->EmergencyValveFlow, 0.1);
|
|
// scale volume based on the flow rate and on the pressure in the main pipe
|
|
auto const flowpressure { std::clamp( m_emergencybrakeflow, 0.0, 1.0 ) + std::clamp( 0.1 * MoverParameters->PipePress, 0.0, 0.5 ) };
|
|
m_emergencybrake
|
|
.pitch( m_emergencybrake.m_frequencyoffset + 1.0 * m_emergencybrake.m_frequencyfactor )
|
|
.gain( m_emergencybrake.m_amplitudeoffset + std::clamp( flowpressure, 0.0, 1.0 ) * m_emergencybrake.m_amplitudefactor )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else if( MoverParameters->EmergencyValveFlow < 0.015 ) {
|
|
m_emergencybrakeflow = 0.0;
|
|
m_emergencybrake.stop();
|
|
}
|
|
|
|
// air release
|
|
if( m_lastbrakepressure != -1.f ) {
|
|
// calculate rate of pressure drop in brake cylinder, once it's been initialized
|
|
auto const brakepressuredifference{ m_lastbrakepressure - MoverParameters->BrakePress };
|
|
m_brakepressurechange = std::lerp( m_brakepressurechange, brakepressuredifference / dt, 0.05f );
|
|
}
|
|
m_lastbrakepressure = MoverParameters->BrakePress;
|
|
// ensure some basic level of volume and scale it up depending on pressure in the cylinder; scale this by the air release rate
|
|
volume = rsUnbrake.m_amplitudefactor * m_brakepressurechange * ( 0.25 + 0.75 * brakepressureratio );
|
|
if( m_brakepressurechange > 0.05 && brakepressureratio > 0.05 ) {
|
|
rsUnbrake
|
|
.gain( volume )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
// don't stop the sound too abruptly
|
|
volume = std::max( 0.0, rsUnbrake.gain() - 0.5 * dt );
|
|
rsUnbrake.gain( volume );
|
|
if( volume < 0.05 ) {
|
|
rsUnbrake.stop();
|
|
}
|
|
}
|
|
|
|
// Dzwiek odluzniacza
|
|
if( MoverParameters->Hamulec->Releaser() ) {
|
|
sReleaser
|
|
.gain(
|
|
std::clamp(
|
|
MoverParameters->BrakePress * 1.25, // arbitrary multiplier
|
|
0., 1. ) )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
sReleaser.stop();
|
|
}
|
|
|
|
// slipping wheels
|
|
if( MoverParameters->SlippingWheels ) {
|
|
|
|
if( MoverParameters->UnitBrakeForce > 100.0
|
|
&& GetVelocity() > 1.0 ) {
|
|
|
|
auto const velocitydifference{ GetVelocity() / MoverParameters->Vmax };
|
|
rsSlippery
|
|
.gain( rsSlippery.m_amplitudeoffset + rsSlippery.m_amplitudefactor * velocitydifference )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
}
|
|
else {
|
|
rsSlippery.stop();
|
|
}
|
|
|
|
// Dzwiek piasecznicy
|
|
if( MoverParameters->SandDose ) {
|
|
sSand.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
sSand.stop();
|
|
}
|
|
|
|
// brakes
|
|
auto brakeforceratio{ 0.0 };
|
|
if( //( false == mvOccupied->SlippingWheels ) &&
|
|
MoverParameters->UnitBrakeForce > 10.0
|
|
&& MoverParameters->Vel > 0.05 ) {
|
|
|
|
brakeforceratio =
|
|
std::clamp(
|
|
MoverParameters->UnitBrakeForce / std::max( 1.0, MoverParameters->BrakeForceR( 1.0, MoverParameters->Vel ) / ( MoverParameters->NAxles * std::max( 1, MoverParameters->NBpA ) ) ),
|
|
0.0, 1.0 );
|
|
rsBrake
|
|
.pitch( rsBrake.m_frequencyoffset + MoverParameters->Vel * rsBrake.m_frequencyfactor )
|
|
.gain( rsBrake.m_amplitudeoffset + std::sqrt( brakeforceratio * std::lerp( 0.4, 1.0, MoverParameters->Vel / (1 + MoverParameters->Vmax) ) ) * rsBrake.m_amplitudefactor )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
rsBrake.stop();
|
|
}
|
|
|
|
// yB: przyspieszacz (moze zadziala, ale dzwiek juz jest)
|
|
if( true == bBrakeAcc ) {
|
|
if( true == TestFlag( MoverParameters->Hamulec->GetSoundFlag(), sf_Acc ) ) {
|
|
sBrakeAcc.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
|
|
// McZapkie-280302 - pisk mocno zacisnietych hamulcow
|
|
if( MoverParameters->Vel > 2.5 ) {
|
|
|
|
volume = rsPisk.m_amplitudeoffset + std::lerp( -1.0, 1.0, brakeforceratio ) * rsPisk.m_amplitudefactor;
|
|
if( volume > 0.075 ) {
|
|
rsPisk
|
|
.pitch(
|
|
true == rsPisk.is_combined() ?
|
|
MoverParameters->Vel * 0.01f :
|
|
rsPisk.m_frequencyoffset + rsPisk.m_frequencyfactor * 1.f )
|
|
.gain( volume )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
}
|
|
else {
|
|
// don't stop the sound too abruptly
|
|
volume = std::max( 0.0, rsPisk.gain() - rsPisk.gain() * 2.5 * dt );
|
|
rsPisk.gain( volume );
|
|
}
|
|
if( volume < 0.05 ) {
|
|
rsPisk.stop();
|
|
}
|
|
|
|
// spring brake
|
|
if( m_springbrakesounds.state != MoverParameters->SpringBrake.Activate ) {
|
|
m_springbrakesounds.state = MoverParameters->SpringBrake.Activate;
|
|
if( m_springbrakesounds.state ) {
|
|
m_springbrakesounds.activate.play( sound_flags::exclusive );
|
|
m_springbrakesounds.release.stop();
|
|
}
|
|
else {
|
|
m_springbrakesounds.activate.stop();
|
|
m_springbrakesounds.release.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
|
|
// other sounds
|
|
// load exchange
|
|
if( MoverParameters->LoadStatus & 1 ) {
|
|
m_exchangesounds.unloading.play( sound_flags::exclusive );
|
|
}
|
|
else {
|
|
m_exchangesounds.unloading.stop();
|
|
}
|
|
if( MoverParameters->LoadStatus & 2 ) {
|
|
m_exchangesounds.loading.play( sound_flags::exclusive );
|
|
}
|
|
else {
|
|
m_exchangesounds.loading.stop();
|
|
}
|
|
// NBMX sygnal odjazdu
|
|
if( MoverParameters->Doors.has_warning ) {
|
|
auto const lowvoltagepower { MoverParameters->Power24vIsAvailable || MoverParameters->Power110vIsAvailable };
|
|
for( auto &doorspeaker : m_doorspeakers ) {
|
|
// TBD, TODO: per-location door state triggers?
|
|
if( MoverParameters->DepartureSignal
|
|
&& lowvoltagepower
|
|
/*
|
|
|| ( ( MoverParameters->DoorCloseCtrl = control::autonomous )
|
|
&& ( ( ( false == MoverParameters->DoorLeftOpened ) && ( dDoorMoveL > 0.0 ) )
|
|
|| ( ( false == MoverParameters->DoorRightOpened ) && ( dDoorMoveR > 0.0 ) ) ) )
|
|
*/
|
|
) {
|
|
// for the autonomous doors play the warning automatically whenever a door is closing
|
|
// MC: pod warunkiem ze jest zdefiniowane w chk
|
|
doorspeaker.departure_signal.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
doorspeaker.departure_signal.stop();
|
|
}
|
|
}
|
|
}
|
|
// announcements
|
|
{
|
|
auto const lowvoltagepower { MoverParameters->Power24vIsAvailable || MoverParameters->Power110vIsAvailable };
|
|
if( lowvoltagepower ) {
|
|
// system is powered up, can play queued announcements
|
|
if( false == m_pasystem.announcement_queue.empty()
|
|
&& false == m_pasystem.announcement.is_playing() ) {
|
|
// pull first sound from the queue
|
|
m_pasystem.announcement = m_pasystem.announcement_queue.front();
|
|
m_pasystem.announcement.owner( this );
|
|
m_pasystem.announcement.range( 0.5 * MoverParameters->Dim.L * -1 );
|
|
if( m_pasystem.soundproofing ) {
|
|
if( !m_pasystem.announcement.soundproofing() ) {
|
|
m_pasystem.announcement.soundproofing() = m_pasystem.soundproofing;
|
|
}
|
|
}
|
|
m_pasystem.announcement.play();
|
|
m_pasystem.announcement_queue.pop_front();
|
|
}
|
|
}
|
|
else {
|
|
m_pasystem.announcement.stop();
|
|
m_pasystem.announcement_queue.clear();
|
|
}
|
|
}
|
|
// NBMX Obsluga drzwi, MC: zuniwersalnione
|
|
std::array<side, 2> const sides { side::right, side::left };
|
|
for( auto const side : sides ) {
|
|
|
|
auto const &door { MoverParameters->Doors.instances[ side ] };
|
|
|
|
if( true == door.is_opening ) {
|
|
// door sounds
|
|
if( false == door.step_unfolding // no wait if no doorstep
|
|
|| MoverParameters->Doors.step_type == 2 ) { // no wait for rotating doorstep
|
|
if( door.position < 0.5f ) { // safety measure, to keep slightly too short sounds from repeating
|
|
for( auto &doorsounds : m_doorsounds ) {
|
|
if( doorsounds.placement == side ) {
|
|
// determine left side doors from their offset
|
|
doorsounds.rsDoorOpen.play( sound_flags::exclusive );
|
|
doorsounds.rsDoorClose.stop();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if( true == door.is_closing ) {
|
|
// door sounds can start playing before the door begins moving but shouldn't cease once the door closes
|
|
if( door.position > 0.f ) {
|
|
for( auto &doorsounds : m_doorsounds ) {
|
|
if( doorsounds.placement == side ) {
|
|
// determine left side doors from their offset
|
|
doorsounds.rsDoorClose.play( sound_flags::exclusive );
|
|
doorsounds.rsDoorOpen.stop();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// doorstep sounds
|
|
if( door.step_unfolding ) {
|
|
for( auto &doorsounds : m_doorsounds ) {
|
|
if( doorsounds.placement == side ) {
|
|
doorsounds.step_open.play( sound_flags::exclusive );
|
|
doorsounds.step_close.stop();
|
|
}
|
|
}
|
|
}
|
|
if( door.step_folding ) {
|
|
if( door.step_position < 1.0f ) { // sanity check, the vehicles may keep the doorstep unfolded until the door close
|
|
for( auto &doorsounds : m_doorsounds ) {
|
|
if( doorsounds.placement == side ) {
|
|
// determine left side doors from their offset
|
|
doorsounds.step_close.play( sound_flags::exclusive );
|
|
doorsounds.step_open.stop();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// door locks
|
|
if( MoverParameters->Doors.is_locked != m_doorlocks ) {
|
|
// toggle state of the locks...
|
|
m_doorlocks = !m_doorlocks;
|
|
// ...and play relevant sounds
|
|
for( auto &door : m_doorsounds ) {
|
|
if( m_doorlocks ) {
|
|
door.lock.play( sound_flags::exclusive );
|
|
}
|
|
else {
|
|
door.unlock.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
}
|
|
|
|
// horns
|
|
{
|
|
// for moving vehicle combine regular horn activation flag with emergency brake horn activation flag, if the brake is active;
|
|
// the horns without the air or the voltage they need stay silent
|
|
auto const warningsignal { MoverParameters->SoundingHorns(
|
|
( MoverParameters->Vel > 0.5 && MoverParameters->AlarmChainFlag ?
|
|
MoverParameters->EmergencyBrakeWarningSignal :
|
|
0 )
|
|
| MoverParameters->WarningSignal ) };
|
|
|
|
if( TestFlag( warningsignal, 1 ) ) {
|
|
sHorn1.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
sHorn1.stop();
|
|
}
|
|
if( TestFlag( warningsignal, 2 ) ) {
|
|
sHorn2.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
sHorn2.stop();
|
|
}
|
|
if( TestFlag( warningsignal, 4 ) ) {
|
|
sHorn3.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
sHorn3.stop();
|
|
}
|
|
}
|
|
// szum w czasie jazdy
|
|
if( GetVelocity() > 0.5
|
|
#ifdef EU07_SOUND_BOGIESOUNDS
|
|
&& false == m_bogiesounds.empty()
|
|
#endif
|
|
&& ( // compound test whether the vehicle belongs to user-driven consist (as these don't emit outer noise in cab view)
|
|
FreeFlyModeFlag ? true : // in external view all vehicles emit outer noise
|
|
simulation::Train == nullptr ? true : // no player train, e.g. it went through a portal and the view isn't switched yet
|
|
ctOwner == nullptr ? true : // standalone vehicle, can't be part of user-driven train
|
|
ctOwner != simulation::Train->Dynamic()->ctOwner ? true : // confirmed isn't a part of the user-driven train
|
|
Global.CabWindowOpen ? true : // sticking head out we get to hear outer noise
|
|
false ) ) {
|
|
#ifdef EU07_SOUND_BOGIESOUNDS
|
|
auto const &bogiesound { m_bogiesounds.front() };
|
|
#else
|
|
auto const &bogiesound { m_outernoise };
|
|
#endif
|
|
// frequency calculation
|
|
auto const normalizer { (
|
|
true == bogiesound.is_combined() ?
|
|
MoverParameters->Vmax * 0.01f :
|
|
1.f ) };
|
|
frequency =
|
|
bogiesound.m_frequencyoffset
|
|
+ bogiesound.m_frequencyfactor * MoverParameters->Vel * normalizer;
|
|
|
|
// volume calculation
|
|
volume =
|
|
bogiesound.m_amplitudeoffset
|
|
+ bogiesound.m_amplitudefactor * MoverParameters->Vel;
|
|
if( brakeforceratio > 0.0 ) {
|
|
// hamulce wzmagaja halas
|
|
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(
|
|
MyTrack->iQualityFlag / 20.0,
|
|
0.0, 1.0 ) );
|
|
// for single sample sounds muffle the playback at low speeds
|
|
if( false == bogiesound.is_combined() ) {
|
|
volume *=
|
|
std::lerp(
|
|
0.0, 1.0,
|
|
std::clamp(
|
|
MoverParameters->Vel / 40.0,
|
|
0.0, 1.0 ) );
|
|
}
|
|
switch( MyTrack->eEnvironment ) {
|
|
case e_tunnel: {
|
|
volume *= 1.3;
|
|
break;
|
|
}
|
|
case e_bridge: {
|
|
volume *= 1.5;
|
|
break;
|
|
}
|
|
default: {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if( volume > 0.05 ) {
|
|
// apply calculated parameters to all motor instances
|
|
#ifdef EU07_SOUND_BOGIESOUNDS
|
|
for( auto &bogiesound : m_bogiesounds ) {
|
|
bogiesound
|
|
.pitch( frequency ) // arbitrary limits to prevent the pitch going out of whack
|
|
.gain( volume )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
#else
|
|
m_outernoise
|
|
.pitch( frequency ) // arbitrary limits to prevent the pitch going out of whack
|
|
.gain( volume )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
#endif
|
|
}
|
|
else {
|
|
// stop all noise instances
|
|
#ifdef EU07_SOUND_BOGIESOUNDS
|
|
for( auto &bogiesound : m_bogiesounds ) {
|
|
bogiesound.stop();
|
|
}
|
|
#else
|
|
m_outernoise.stop();
|
|
#endif
|
|
}
|
|
}
|
|
else {
|
|
// don't play the optional ending sound if the listener switches views
|
|
#ifdef EU07_SOUND_BOGIESOUNDS
|
|
for( auto &bogiesound : m_bogiesounds ) {
|
|
bogiesound.stop( false == FreeFlyModeFlag );
|
|
}
|
|
#else
|
|
m_outernoise.stop( false == FreeFlyModeFlag );
|
|
#endif
|
|
}
|
|
// flat spot sound
|
|
if( MoverParameters->CategoryFlag == 1 ) {
|
|
// trains only
|
|
if( GetVelocity() > 1.0
|
|
&& MoverParameters->WheelFlat > 5.0 ) {
|
|
m_wheelflat
|
|
.pitch( m_wheelflat.m_frequencyoffset + std::abs( MoverParameters->nrot ) * m_wheelflat.m_frequencyfactor )
|
|
.gain( m_wheelflat.m_amplitudeoffset + m_wheelflat.m_amplitudefactor * ( ( 1.0 + MoverParameters->Vel / MoverParameters->Vmax + std::clamp( MoverParameters->WheelFlat / 60.0, 0.0, 1.0 ) ) / 3.0 ) )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
m_wheelflat.stop();
|
|
}
|
|
}
|
|
|
|
// youBy: dzwiek ostrych lukow i ciasnych zwrotek
|
|
if( MoverParameters->Vel > 5.0
|
|
&& ts.R * ts.R > 1.0
|
|
&& std::abs(ts.R) < 15000.0 ) {
|
|
// scale volume with curve radius and vehicle speed
|
|
volume =
|
|
std::abs( MoverParameters->AccN ) // * MoverParameters->AccN
|
|
* std::lerp(
|
|
0.5, 1.0,
|
|
std::clamp(
|
|
MoverParameters->Vel / 40.0,
|
|
0.0, 1.0 ) )
|
|
* ( MyTrack->eType == tt_Switch && std::abs(ts.R) < 1500.0 ? 100.0 : 1.0 );
|
|
}
|
|
else {
|
|
volume = 0;
|
|
}
|
|
if( volume > 0.05 ) {
|
|
rscurve
|
|
.pitch(
|
|
true == rscurve.is_combined() ?
|
|
MoverParameters->Vel * 0.01f :
|
|
rscurve.m_frequencyoffset + rscurve.m_frequencyfactor * 1.f )
|
|
.gain( 2.5 * volume )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
rscurve.stop();
|
|
}
|
|
|
|
// movement start jolt
|
|
if( false == m_startjoltplayed ) {
|
|
auto const velocity { GetVelocity() };
|
|
if( ( MoverParameters->V > 0.0 ? MoverParameters->AccSVBased > 0.1 : MoverParameters->AccSVBased < 0.1 )
|
|
&& velocity > 1.0
|
|
&& velocity < 15.0 ) {
|
|
m_startjolt.play( sound_flags::exclusive );
|
|
m_startjoltplayed = true;
|
|
}
|
|
}
|
|
|
|
// McZapkie! - to wazne - SoundFlag wystawiane jest przez moje moduly gdy zachodza pewne wydarzenia komentowane dzwiekiem.
|
|
// pneumatic relay
|
|
if( TestFlag( MoverParameters->SoundFlag, sound::pneumatic ) ) {
|
|
dsbPneumaticRelay
|
|
.gain(
|
|
true == TestFlag( MoverParameters->SoundFlag, sound::loud ) ?
|
|
1.0f :
|
|
0.8f )
|
|
.play();
|
|
}
|
|
// door permit
|
|
if( TestFlag( MoverParameters->SoundFlag, sound::doorpermit ) ) {
|
|
// NOTE: current implementation doesn't discern between permit for left/right side,
|
|
// which may be undesired in weird setups with doors only on one side
|
|
// TBD, TODO: rework into dedicated sound event flag for each door location instance?
|
|
for( auto &door : m_doorsounds ) {
|
|
door.permit_granted.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
|
|
// couplers
|
|
int couplerindex { 0 };
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
|
|
auto &coupler { MoverParameters->Couplers[ couplerindex ] };
|
|
|
|
if( coupler.sounds == sound::none ) {
|
|
++couplerindex;
|
|
continue;
|
|
}
|
|
|
|
if( true == TestFlag( coupler.sounds, sound::bufferclash ) ) {
|
|
// zderzaki uderzaja o siebie
|
|
if( true == TestFlag( coupler.sounds, sound::loud ) ) {
|
|
// loud clash
|
|
if( false == couplersounds.dsbBufferClamp_loud.empty() ) {
|
|
// dedicated sound for loud clash
|
|
couplersounds.dsbBufferClamp_loud
|
|
.gain( 1.f )
|
|
.play( sound_flags::exclusive );
|
|
}
|
|
else {
|
|
// fallback on the standard sound
|
|
couplersounds.dsbBufferClamp
|
|
.gain( 1.f )
|
|
.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
else {
|
|
// basic clash
|
|
couplersounds.dsbBufferClamp
|
|
.gain( 1.f )
|
|
.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
|
|
if( true == TestFlag( coupler.sounds, sound::couplerstretch ) ) {
|
|
// sprzegi sie rozciagaja
|
|
if( true == TestFlag( coupler.sounds, sound::loud ) ) {
|
|
// loud stretch
|
|
if( false == couplersounds.dsbCouplerStretch_loud.empty() ) {
|
|
// dedicated sound for loud stretch
|
|
couplersounds.dsbCouplerStretch_loud
|
|
.gain( 1.f )
|
|
.play( sound_flags::exclusive );
|
|
}
|
|
else {
|
|
// fallback on the standard sound
|
|
couplersounds.dsbCouplerStretch
|
|
.gain( 1.f )
|
|
.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
else {
|
|
// basic clash
|
|
couplersounds.dsbCouplerStretch
|
|
.gain( 1.f )
|
|
.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
// attach/detach sounds
|
|
if( ( coupler.sounds & sound::detach ) == 0 ) {
|
|
// potentially added some couplings
|
|
if( ( coupler.sounds & sound::attachcoupler ) != 0 ) {
|
|
couplersounds.attach_coupler.play();
|
|
}
|
|
if( ( coupler.sounds & sound::attachbrakehose ) != 0 ) {
|
|
couplersounds.attach_brakehose.play();
|
|
}
|
|
if( ( coupler.sounds & sound::attachmainhose ) != 0 ) {
|
|
couplersounds.attach_mainhose.play();
|
|
}
|
|
if( ( coupler.sounds & sound::attachcontrol ) != 0 ) {
|
|
couplersounds.attach_control.play();
|
|
}
|
|
if( ( coupler.sounds & sound::attachgangway ) != 0 ) {
|
|
couplersounds.attach_gangway.play();
|
|
}
|
|
if( ( coupler.sounds & sound::attachheating ) != 0 ) {
|
|
couplersounds.attach_heating.play();
|
|
}
|
|
}
|
|
else {
|
|
// potentially removed some couplings
|
|
if( ( coupler.sounds & sound::attachcoupler ) != 0 ) {
|
|
couplersounds.detach_coupler.play();
|
|
}
|
|
if( ( coupler.sounds & sound::attachbrakehose ) != 0 ) {
|
|
couplersounds.detach_brakehose.play();
|
|
}
|
|
if( ( coupler.sounds & sound::attachmainhose ) != 0 ) {
|
|
couplersounds.detach_mainhose.play();
|
|
}
|
|
if( ( coupler.sounds & sound::attachcontrol ) != 0 ) {
|
|
couplersounds.detach_control.play();
|
|
}
|
|
if( ( coupler.sounds & sound::attachgangway ) != 0 ) {
|
|
couplersounds.detach_gangway.play();
|
|
}
|
|
if( ( coupler.sounds & sound::attachheating ) != 0 ) {
|
|
couplersounds.detach_heating.play();
|
|
}
|
|
}
|
|
if( true == TestFlag( coupler.sounds, sound::attachadapter ) ) {
|
|
couplersounds.dsbAdapterAttach.play();
|
|
}
|
|
if( true == TestFlag( coupler.sounds, sound::removeadapter ) ) {
|
|
couplersounds.dsbAdapterRemove.play();
|
|
}
|
|
|
|
++couplerindex;
|
|
coupler.sounds = 0;
|
|
}
|
|
|
|
MoverParameters->SoundFlag = 0;
|
|
// McZapkie! - koniec obslugi dzwiekow z mover.pas
|
|
|
|
// special events
|
|
if( MoverParameters->EventFlag ) {
|
|
// McZapkie: w razie wykolejenia
|
|
if( true == TestFlag( MoverParameters->DamageFlag, dtrain_out ) ) {
|
|
rsDerailment.play( sound_flags::exclusive );
|
|
}
|
|
|
|
MoverParameters->EventFlag = false;
|
|
}
|
|
}
|
|
|
|
// calculates distance between event-starting axle and front of the vehicle
|
|
double
|
|
TDynamicObject::tracing_offset() const {
|
|
|
|
auto const axletoend{ ( GetLength() - fAxleDist ) * 0.5 };
|
|
return iAxleFirst ? axletoend : axletoend + iDirection * fAxleDist;
|
|
}
|
|
|
|
// TODO: compute and cache radius during vehicle initialization
|
|
double
|
|
TDynamicObject::radius() const {
|
|
|
|
glm::vec3 diagonal(
|
|
static_cast<float>( MoverParameters->Dim.L ),
|
|
static_cast<float>( MoverParameters->Dim.H ),
|
|
static_cast<float>( MoverParameters->Dim.W ) );
|
|
return glm::length( diagonal ) * 0.5f;
|
|
}
|
|
|
|
// McZapkie-250202
|
|
// wczytywanie pliku z danymi multimedialnymi (dzwieki)
|
|
void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string const &ReplacableSkin ) {
|
|
rTypeName = TypeName;
|
|
rReplacableSkin = ReplacableSkin;
|
|
Global.asCurrentDynamicPath = asBaseDir;
|
|
std::string asFileName = asBaseDir + TypeName + ".mmd";
|
|
std::string asAnimName;
|
|
bool Stop_InternalData = false;
|
|
pants = nullptr; // wskaźnik pierwszego obiektu animującego dla pantografów
|
|
wipers = nullptr; // wskaznik pierwszego obiektu animujacego dla wycieraczek
|
|
{
|
|
// preliminary check whether the file exists
|
|
cParser parser( TypeName + ".mmd", cParser::buffer_FILE, asBaseDir );
|
|
if( false == parser.ok() ) {
|
|
ErrorLog( "Failed to load appearance data for vehicle " + MoverParameters->Name );
|
|
return;
|
|
}
|
|
}
|
|
// use #include wrapper to access the appearance data file
|
|
// this allows us to provide the file content with user-defined parameters
|
|
cParser parser(
|
|
"include " + TypeName + ".mmd"
|
|
+ " " + asName // (p1)
|
|
+ " " + TypeName // (p2)
|
|
+ " " + ReplacableSkin // (p3)
|
|
+ " end",
|
|
cParser::buffer_TEXT,
|
|
asBaseDir, true, std::vector<std::string>(), true );
|
|
std::string token;
|
|
do {
|
|
token = "";
|
|
parser.getTokens(); parser >> token;
|
|
|
|
if( token == "models:" ) {
|
|
// modele i podmodele
|
|
m_materialdata.multi_textures = 0; // czy jest wiele tekstur wymiennych?
|
|
parser.getTokens();
|
|
parser >> asModel;
|
|
replace_slashes( asModel );
|
|
if( asModel.back() == '#' ) // Ra 2015-01: nie podoba mi siê to
|
|
{ // model wymaga wielu tekstur wymiennych
|
|
m_materialdata.multi_textures = 1;
|
|
asModel.erase( asModel.length() - 1 );
|
|
}
|
|
// name can contain leading slash, erase it to avoid creation of double slashes when the name is combined with current directory
|
|
erase_leading_slashes( asModel );
|
|
/*
|
|
// never really used, may as well get rid of it
|
|
std::size_t i = asModel.find( ',' );
|
|
if ( i != std::string::npos )
|
|
{ // Ra 2015-01: może szukać przecinka w nazwie modelu, a po przecinku była by liczba tekstur?
|
|
if( i < asModel.length() ) {
|
|
m_materialdata.multi_textures = asModel[ i + 1 ] - '0';
|
|
}
|
|
m_materialdata.multi_textures = std::clamp( m_materialdata.multi_textures, 0, 1 ); // na razie ustawiamy na 1
|
|
}
|
|
*/
|
|
asModel = asBaseDir + asModel; // McZapkie 2002-07-20: dynamics maja swoje modele w dynamics/basedir
|
|
Global.asCurrentTexturePath = asBaseDir; // biezaca sciezka do tekstur to dynamic/...
|
|
mdModel = TModelsManager::GetModel(asModel, true);
|
|
if (ReplacableSkin != "none") {
|
|
m_materialdata.assign( ReplacableSkin );
|
|
}
|
|
Global.asCurrentTexturePath = paths::textures; // z powrotem defaultowa sciezka do tekstur
|
|
do {
|
|
token = "";
|
|
parser.getTokens(); parser >> token;
|
|
|
|
if( token == "animations:" ) {
|
|
// Ra: ustawienie ilości poszczególnych animacji - musi być jako pierwsze, inaczej ilości będą domyślne
|
|
/*
|
|
if( nullptr == pAnimations )
|
|
*/
|
|
if( true == pAnimations.empty() )
|
|
{ // jeśli nie ma jeszcze tabeli animacji, można odczytać nowe ilości
|
|
int co = 0;
|
|
iAnimations = 0;
|
|
int ile;
|
|
do
|
|
{ // kolejne liczby to ilość animacj, -1 to znacznik końca
|
|
ile = -1;
|
|
parser.getTokens( 1, false );
|
|
parser >> ile; // ilość danego typu animacji
|
|
if (ile >= 0)
|
|
{
|
|
iAnimType[co] = ile; // zapamiętanie
|
|
iAnimations += ile; // ogólna ilość animacji
|
|
}
|
|
else {
|
|
iAnimType[co] = 0;
|
|
}
|
|
++co;
|
|
} while ( ile >= 0 && co < ANIM_TYPES ); //-1 to znacznik końca
|
|
|
|
pAnimations.resize( iAnimations );
|
|
int i, j, k = 0, sm = 0;
|
|
for (j = 0; j < ANIM_TYPES; ++j) // petla po wszystkich wpisach w animations
|
|
for (i = 0; i < iAnimType[j]; ++i) // petla iteruje sie tyle razy ile mamy wpisane w animations
|
|
{
|
|
if (j == ANIM_PANTS) // zliczamy poprzednie animacje
|
|
if (!pants)
|
|
if (iAnimType[ANIM_PANTS]) // o ile jakieś pantografy są (a domyślnie są)
|
|
pants = &pAnimations[k]; // zapamiętanie na potrzeby wyszukania submodeli
|
|
if (j == ANIM_WIPERS)
|
|
if (!wipers)
|
|
if (iAnimType[ANIM_WIPERS])
|
|
wipers = &pAnimations[k];
|
|
pAnimations[k].iShift = sm; // przesunięcie do przydzielenia wskaźnika
|
|
sm += pAnimations[k++].TypeSet(j, *MoverParameters); // ustawienie typu animacji i zliczanie tablicowanych submodeli
|
|
}
|
|
if (sm) // o ile są bardziej złożone animacje
|
|
{
|
|
pAnimated = new TSubModel *[sm]; // tabela na animowane submodele
|
|
for (k = 0; k < iAnimations; ++k)
|
|
pAnimations[k].smElement = pAnimated + pAnimations[k].iShift; // przydzielenie wskaźnika do tabelki
|
|
}
|
|
}
|
|
}
|
|
|
|
else if(token == "lowpolyinterior:") {
|
|
// ABu: wnetrze lowpoly
|
|
parser.getTokens();
|
|
parser >> asModel;
|
|
|
|
replace_slashes( asModel );
|
|
erase_leading_slashes( asModel );
|
|
asModel = asBaseDir + asModel; // McZapkie-200702 - dynamics maja swoje modele w dynamic/basedir
|
|
Global.asCurrentTexturePath = asBaseDir; // biezaca sciezka do tekstur to dynamic/...
|
|
mdLowPolyInt = TModelsManager::GetModel(asModel, true);
|
|
}
|
|
|
|
else if(token == "coupleradapter:") {
|
|
// coupling adapter data
|
|
parser.getTokens( 3 );
|
|
parser
|
|
>> m_coupleradapter.model
|
|
>> m_coupleradapter.position.x
|
|
>> m_coupleradapter.position.y;
|
|
replace_slashes( m_coupleradapter.model );
|
|
erase_leading_slashes( m_coupleradapter.model );
|
|
}
|
|
|
|
else if(token == "attachments:") {
|
|
// additional 3d models attached to main body
|
|
// content provided as a series of values together enclosed in "{}"
|
|
// each value is a name of additional 3d model
|
|
// value can be optionally set of values enclosed in "[]" in which case one value will be picked randomly
|
|
// TBD: reconsider something more yaml-compliant and/or ability to define offset and rotation
|
|
while( (token = deserialize_random_set(parser)) != ""
|
|
&& token != "}" ) {
|
|
if( token == "{" ) { continue; }
|
|
replace_slashes( token );
|
|
Global.asCurrentTexturePath = asBaseDir; // biezaca sciezka do tekstur to dynamic/...
|
|
auto *attachmentmodel { TModelsManager::GetModel( asBaseDir + token, true ) };
|
|
if( attachmentmodel != nullptr ) {
|
|
mdAttachments.emplace_back( attachmentmodel );
|
|
}
|
|
}
|
|
}
|
|
|
|
else if(token == "loads:") {
|
|
// default load visualization models overrides
|
|
// content provided as "key: value" pairs together enclosed in "{}"
|
|
// value can be optionally set of values enclosed in "[]" in which case one value will be picked randomly
|
|
while( (token = parser.getToken<std::string>()) != ""
|
|
&& token != "}" ) {
|
|
if( token.back() == ':' ) {
|
|
auto loadmodel { deserialize_random_set( parser ) };
|
|
replace_slashes( loadmodel );
|
|
LoadModelOverrides.emplace( token.erase( token.size() - 1 ), loadmodel );
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "brakemode:" ) {
|
|
// Ra 15-01: gałka nastawy hamulca
|
|
parser.getTokens();
|
|
parser >> asAnimName;
|
|
smBrakeMode = GetSubmodelFromName( mdModel, asAnimName );
|
|
// jeszcze wczytać kąty obrotu dla poszczególnych ustawień
|
|
}
|
|
|
|
else if( token == "loadmode:" ) {
|
|
// Ra 15-01: gałka nastawy hamulca
|
|
parser.getTokens();
|
|
parser >> asAnimName;
|
|
smLoadMode = GetSubmodelFromName( mdModel, asAnimName );
|
|
// jeszcze wczytać kąty obrotu dla poszczególnych ustawień
|
|
}
|
|
|
|
else if (token == "animwheelprefix:") {
|
|
// prefiks kręcących się kół
|
|
int i, k, m;
|
|
unsigned int j;
|
|
parser.getTokens( 1, false ); parser >> token;
|
|
for (i = 0; i < iAnimType[ANIM_WHEELS]; ++i) // liczba osi
|
|
{ // McZapkie-050402: wyszukiwanie kol o nazwie str*
|
|
asAnimName = token + std::to_string(i + 1);
|
|
pAnimations[i].smAnimated = GetSubmodelFromName( mdModel, asAnimName );
|
|
if (pAnimations[i].smAnimated)
|
|
{ //++iAnimatedAxles;
|
|
pAnimations[i].smAnimated->WillBeAnimated(); // wyłączenie optymalizacji transformu
|
|
pAnimations[i].yUpdate = std::bind( &TDynamicObject::UpdateAxle, this, std::placeholders::_1 );
|
|
pAnimations[i].fMaxDist = Global.fDistanceFactor * MoverParameters->WheelDiameter * 200;
|
|
pAnimations[i].fMaxDist *= pAnimations[i].fMaxDist;
|
|
}
|
|
}
|
|
// Ra: ustawianie indeksów osi
|
|
for (i = 0; i < iAnimType[ANIM_WHEELS]; ++i) // ilość osi (zabezpieczenie przed błędami w CHK)
|
|
pAnimations[i].dWheelAngle = 1; // domyślnie wskaźnik na napędzające
|
|
i = 0;
|
|
j = 1;
|
|
k = 0;
|
|
m = 0; // numer osi; kolejny znak; ile osi danego typu; która średnica
|
|
if (MoverParameters->WheelDiameterL != MoverParameters->WheelDiameter ||
|
|
MoverParameters->WheelDiameterT != MoverParameters->WheelDiameter)
|
|
{ // obsługa różnych średnic, o ile występują
|
|
while (i < iAnimType[ANIM_WHEELS] &&
|
|
j <= MoverParameters->AxleArangement.length())
|
|
{ // wersja ze wskaźnikami jest bardziej elastyczna na nietypowe układy
|
|
if (k >= 'A' && k <= 'J') // 10 chyba maksimum?
|
|
{
|
|
pAnimations[i++].dWheelAngle = 1; // obrót osi napędzających
|
|
--k; // następna będzie albo taka sama, albo bierzemy kolejny znak
|
|
m = 2; // następujące toczne będą miały inną średnicę
|
|
}
|
|
else if (k >= '1' && k <= '9')
|
|
{
|
|
pAnimations[i++].dWheelAngle = m; // obrót osi tocznych
|
|
--k; // następna będzie albo taka sama, albo bierzemy kolejny znak
|
|
}
|
|
else
|
|
k = MoverParameters->AxleArangement[j++]; // pobranie kolejnego znaku
|
|
}
|
|
}
|
|
}
|
|
// else if (str==AnsiString("animrodprefix:")) //prefiks wiazarow dwoch
|
|
// {
|
|
// str= Parser->GetNextSymbol();
|
|
// for (int i=1; i<=2; i++)
|
|
// {//McZapkie-050402: wyszukiwanie max 2 wiazarow o nazwie str*
|
|
// asAnimName=str+i;
|
|
// smWiazary[i-1]=mdModel->GetFromName(asAnimName.c_str());
|
|
// smWiazary[i-1]->WillBeAnimated();
|
|
// }
|
|
// }
|
|
|
|
else if( token == "animpantprefix:" ) {
|
|
// Ra: pantografy po nowemu mają literki i numerki
|
|
}
|
|
// Pantografy - Winger 160204
|
|
else if( token == "animpantrd1prefix:" ) {
|
|
// prefiks ramion dolnych 1
|
|
parser.getTokens(); parser >> token;
|
|
float4x4 m; // macierz do wyliczenia pozycji i wektora ruchu pantografu
|
|
TSubModel *sm;
|
|
if (pants)
|
|
for (int i = 0; i < iAnimType[ANIM_PANTS]; i++)
|
|
{ // Winger 160204: wyszukiwanie max 2 patykow o nazwie str*
|
|
asAnimName = token + std::to_string(i + 1);
|
|
sm = GetSubmodelFromName( mdModel, asAnimName );
|
|
pants[i].smElement[0] = sm; // jak NULL, to nie będzie animowany
|
|
if (sm)
|
|
{ // w EP09 wywalało się tu z powodu NULL
|
|
sm->WillBeAnimated();
|
|
sm->ParentMatrix(&m); // pobranie macierzy transformacji
|
|
// m(3)[1]=m[3][1]+0.054; //w górę o wysokość ślizgu (na razie tak)
|
|
pants[i].fParamPants->vPos.z = m[3][0]; // przesunięcie w bok (asymetria)
|
|
pants[i].fParamPants->vPos.y = m[3][1]; // przesunięcie w górę odczytane z modelu
|
|
if ((sm = pants[i].smElement[0]->ChildGet()) != nullptr)
|
|
{ // jeśli ma potomny, można policzyć długość (odległość potomnego od osi obrotu)
|
|
m = float4x4(*sm->GetMatrix()); // wystarczyłby wskaźnik, nie trzeba kopiować
|
|
// może trzeba: pobrać macierz dolnego ramienia, wyzerować przesunięcie, przemnożyć przez macierz górnego
|
|
pants[i].fParamPants->fHoriz = -fabs(m[3][1]);
|
|
pants[i].fParamPants->fLenL1 = hypot(m[3][1], m[3][2]); // po osi OX nie potrzeba
|
|
pants[i].fParamPants->fAngleL0 = atan2(fabs(m[3][2]), fabs(m[3][1]));
|
|
// if (pants[i].fParamPants->fAngleL0<M_PI_2)
|
|
// pants[i].fParamPants->fAngleL0+=M_PI; //gdyby w odwrotną stronę wyszło
|
|
// if
|
|
// ((pants[i].fParamPants->fAngleL0<0.03)||(pants[i].fParamPants->fAngleL0>0.09))
|
|
// //normalnie ok. 0.05
|
|
// pants[i].fParamPants->fAngleL0=pants[i].fParamPants->fAngleL;
|
|
pants[i].fParamPants->fAngleL = pants[i].fParamPants->fAngleL0; // początkowy kąt dolnego ramienia
|
|
if ((sm = sm->ChildGet()) != nullptr)
|
|
{ // jeśli dalej jest ślizg, można policzyć długość górnego ramienia
|
|
m = float4x4(*sm->GetMatrix()); // wystarczyłby wskaźnik,
|
|
// nie trzeba kopiować trzeba by uwzględnić macierz dolnego ramienia, żeby uzyskać kąt do poziomu...
|
|
pants[i].fParamPants->fHoriz += fabs(m(3)[1]); // różnica długości rzutów ramion na
|
|
// płaszczyznę podstawy (jedna dodatnia, druga ujemna)
|
|
pants[i].fParamPants->fLenU1 = hypot( m[3][1], m[3][2] ); // po osi OX nie potrzeba
|
|
// pants[i].fParamPants->pantu=acos((1.22*cos(pants[i].fParamPants->fAngleL)+0.535)/1.755); //górne ramię
|
|
// pants[i].fParamPants->fAngleU0=acos((1.176289*cos(pants[i].fParamPants->fAngleL)+0.54555075)/1.724482197); //górne ramię
|
|
pants[i].fParamPants->fAngleU0 = atan2( fabs(m[3][2]), fabs(m[3][1]) ); // początkowy kąt górnego ramienia, odczytany z modelu
|
|
// if (pants[i].fParamPants->fAngleU0<M_PI_2)
|
|
// pants[i].fParamPants->fAngleU0+=M_PI; //gdyby w odwrotną stronę wyszło
|
|
// if (pants[i].fParamPants->fAngleU0<0)
|
|
// pants[i].fParamPants->fAngleU0=-pants[i].fParamPants->fAngleU0;
|
|
// if
|
|
// ((pants[i].fParamPants->fAngleU0<0.00)||(pants[i].fParamPants->fAngleU0>0.09)) //normalnie ok. 0.07
|
|
// pants[i].fParamPants->fAngleU0=acos((pants[i].fParamPants->fLenL1*cos(pants[i].fParamPants->fAngleL)+pants[i].fParamPants->fHoriz)/pants[i].fParamPants->fLenU1);
|
|
pants[i].fParamPants->fAngleU = pants[i].fParamPants->fAngleU0; // początkowy kąt
|
|
// Ra: ze względu na to, że niektóre modele pantografów są zrąbane, ich mierzenie ma obecnie ograniczony sens
|
|
sm->ParentMatrix(&m); // pobranie macierzy transformacji pivota ślizgu względem wstawienia pojazdu
|
|
float det = Det(m);
|
|
if (std::fabs(det - 1.0) < 0.001) // dopuszczamy 1 promil błędu na skalowaniu ślizgu
|
|
{ // skalowanie jest w normie, można pobrać wymiary z modelu
|
|
pants[i].fParamPants->fHeight = sm->MaxY(m); // przeliczenie maksimum wysokości wierzchołków względem macierzy
|
|
pants[i].fParamPants->fHeight -= m[3][1]; // odjęcie wysokości pivota ślizgu
|
|
pants[i].fParamPants->vPos.x = m[3][2]; // przy okazji odczytać z modelu pozycję w długości
|
|
// ErrorLog("Model OK: "+asModel+",
|
|
// height="+pants[i].fParamPants->fHeight);
|
|
// ErrorLog("Model OK: "+asModel+",
|
|
// pos.x="+pants[i].fParamPants->vPos.x);
|
|
}
|
|
else
|
|
{ // gdy ktoś przesadził ze skalowaniem
|
|
pants[i].fParamPants->fHeight = 0.0; // niech będzie odczyt z pantfactors:
|
|
ErrorLog(
|
|
"Bad model: " + asModel + ", scale of " + sm->pName + " is " + std::to_string(100.0 * det) + "%",
|
|
logtype::model );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
// brak ramienia
|
|
pants[ i ].fParamPants->fHeight = 0.0; // niech będzie odczyt z pantfactors:
|
|
ErrorLog( "Bad model: " + asFileName + " - missed submodel " + asAnimName, logtype::model );
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "animpantrd2prefix:" ) {
|
|
// prefiks ramion dolnych 2
|
|
parser.getTokens(); parser >> token;
|
|
float4x4 m; // macierz do wyliczenia pozycji i wektora ruchu pantografu
|
|
TSubModel *sm;
|
|
if( pants ) {
|
|
for( int i = 0; i < iAnimType[ ANIM_PANTS ]; i++ ) {
|
|
// Winger 160204: wyszukiwanie max 2 patykow o nazwie str*
|
|
asAnimName = token + std::to_string( i + 1 );
|
|
sm = GetSubmodelFromName( mdModel, asAnimName );
|
|
pants[ i ].smElement[ 1 ] = sm; // jak NULL, to nie będzie animowany
|
|
if( sm ) { // w EP09 wywalało się tu z powodu NULL
|
|
sm->WillBeAnimated();
|
|
if( pants[ i ].fParamPants->vPos.y == 0.0 ) {
|
|
// jeśli pierwsze ramię nie ustawiło tej wartości, próbować drugim
|
|
//!!!! docelowo zrobić niezależną animację ramion z każdej strony
|
|
m = float4x4(
|
|
*sm->GetMatrix()); // skopiowanie, bo będziemy mnożyć
|
|
m( 3 )[ 1 ] =
|
|
m[ 3 ][ 1 ] + 0.054; // w górę o wysokość ślizgu (na razie tak)
|
|
while( sm->Parent ) {
|
|
if( sm->Parent->GetMatrix() )
|
|
m = *sm->Parent->GetMatrix() * m;
|
|
sm = sm->Parent;
|
|
}
|
|
pants[ i ].fParamPants->vPos.z = m[3][0]; // przesunięcie w bok (asymetria)
|
|
pants[ i ].fParamPants->vPos.y = m[3][1]; // przesunięcie w górę odczytane z modelu
|
|
}
|
|
}
|
|
else
|
|
ErrorLog( "Bad model: " + asFileName + " - missed submodel " + asAnimName, logtype::model ); // brak ramienia
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "animpantrg1prefix:" ) {
|
|
// prefiks ramion górnych 1
|
|
parser.getTokens(); parser >> token;
|
|
if( pants ) {
|
|
for( int i = 0; i < iAnimType[ ANIM_PANTS ]; i++ ) {
|
|
// Winger 160204: wyszukiwanie max 2 patykow o nazwie str*
|
|
asAnimName = token + std::to_string( i + 1 );
|
|
pants[ i ].smElement[ 2 ] = GetSubmodelFromName( mdModel, asAnimName );
|
|
if( pants[ i ].smElement[ 2 ] ) {
|
|
pants[ i ].smElement[ 2 ]->WillBeAnimated();
|
|
}
|
|
else {
|
|
ErrorLog( "Bad model: " + asFileName + " - missed submodel " + asAnimName, logtype::model ); // brak ramienia
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "animpantrg2prefix:" ) {
|
|
// prefiks ramion górnych 2
|
|
parser.getTokens(); parser >> token;
|
|
if( pants ) {
|
|
for( int i = 0; i < iAnimType[ ANIM_PANTS ]; i++ ) {
|
|
// Winger 160204: wyszukiwanie max 2 patykow o nazwie str*
|
|
asAnimName = token + std::to_string( i + 1 );
|
|
pants[ i ].smElement[ 3 ] = GetSubmodelFromName( mdModel, asAnimName );
|
|
if( pants[ i ].smElement[ 3 ] ) {
|
|
pants[ i ].smElement[ 3 ]->WillBeAnimated();
|
|
}
|
|
else {
|
|
ErrorLog( "Bad model: " + asFileName + " - missed submodel " + asAnimName, logtype::model ); // brak ramienia
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "animpantslprefix:" ) {
|
|
// prefiks ślizgaczy
|
|
parser.getTokens(); parser >> token;
|
|
if( pants ) {
|
|
for( int i = 0; i < iAnimType[ ANIM_PANTS ]; i++ ) {
|
|
// Winger 160204: wyszukiwanie max 2 patykow o nazwie str*
|
|
asAnimName = token + std::to_string( i + 1 );
|
|
pants[ i ].smElement[ 4 ] = GetSubmodelFromName( mdModel, asAnimName );
|
|
if( pants[ i ].smElement[ 4 ] ) {
|
|
pants[ i ].smElement[ 4 ]->WillBeAnimated();
|
|
pants[ i ].yUpdate = std::bind( &TDynamicObject::UpdatePant, this, std::placeholders::_1 );
|
|
pants[ i ].fMaxDist = 300 * 300; // nie podnosić w większej odległości
|
|
pants[ i ].iNumber = i;
|
|
}
|
|
else {
|
|
ErrorLog( "Bad model: " + asFileName + " - missed submodel " + asAnimName, logtype::model ); // brak ramienia
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "pantfactors:" ) {
|
|
// Winger 010304:
|
|
// parametry pantografow
|
|
double pant1x, pant2x, pant1h, pant2h;
|
|
parser.getTokens( 4, false );
|
|
parser
|
|
>> pant1x
|
|
>> pant2x
|
|
>> pant1h // wysokość pierwszego ślizgu
|
|
>> pant2h;// wysokość drugiego ślizgu
|
|
if( pant1h > 0.5 ) {
|
|
pant1h = pant2h; // tu może być zbyt duża wartość
|
|
}
|
|
if (pant1x < 0 &&
|
|
pant2x > 0) // pierwsza powinna być dodatnia, a druga ujemna
|
|
{
|
|
pant1x = -pant1x;
|
|
pant2x = -pant2x;
|
|
}
|
|
if( pants ) {
|
|
for( int i = 0; i < iAnimType[ ANIM_PANTS ]; ++i ) {
|
|
// przepisanie współczynników do pantografów (na razie nie będzie lepiej)
|
|
auto &pantograph { *pants[i].fParamPants };
|
|
|
|
pantograph.fAngleL = pantograph.fAngleL0; // początkowy kąt dolnego ramienia
|
|
pantograph.fAngleU = pantograph.fAngleU0; // początkowy kąt
|
|
// pants[i].fParamPants->PantWys=1.22*sin(pants[i].fParamPants->fAngleL)+1.755*sin(pants[i].fParamPants->fAngleU);
|
|
// //wysokość początkowa
|
|
// pants[i].fParamPants->PantWys=1.176289*sin(pants[i].fParamPants->fAngleL)+1.724482197*sin(pants[i].fParamPants->fAngleU);
|
|
// //wysokość początkowa
|
|
if( pantograph.fHeight == 0.0 ) // gdy jest nieprawdopodobna wartość (np. nie znaleziony ślizg)
|
|
{ // gdy pomiary modelu nie udały się, odczyt podanych parametrów z MMD
|
|
pantograph.vPos.x =
|
|
i & 1 ?
|
|
pant2x :
|
|
pant1x;
|
|
pantograph.fHeight =
|
|
i & 1 ?
|
|
pant2h :
|
|
pant1h; // wysokość ślizgu jest zapisana w MMD
|
|
}
|
|
pantograph.PantWys =
|
|
pantograph.fLenL1 * sin( pantograph.fAngleL ) +
|
|
pantograph.fLenU1 * sin( pantograph.fAngleU ) +
|
|
pantograph.fHeight; // wysokość początkowa
|
|
// pants[i].fParamPants->vPos.y=panty-panth-pants[i].fParamPants->PantWys; //np. 4.429-0.097=4.332=~4.335
|
|
if( pantograph.vPos.y == 0.0 ) {
|
|
// crude fallback, place the pantograph(s) atop of the vehicle-sized box
|
|
pantograph.vPos.y = MoverParameters->Dim.H - pantograph.fHeight - pantograph.PantWys;
|
|
}
|
|
// pants[i].fParamPants->vPos.z=0; //niezerowe dla pantografów asymetrycznych
|
|
pantograph.PantTraction = pantograph.PantWys;
|
|
// połowa szerokości ślizgu; jest w "Power: CSW="
|
|
pantograph.fWidth = 0.5 * MoverParameters->EnginePowerSource.CollectorParameters.CSW;
|
|
|
|
// create sound emitters for the pantograph
|
|
m_pantographsounds.emplace_back();
|
|
}
|
|
}
|
|
}
|
|
|
|
else if (token == "animpistonprefix:") {
|
|
// prefiks tłoczysk - na razie uzywamy modeli pantografów
|
|
parser.getTokens(1, false); parser >> token;
|
|
for( int i = 1; i <= 2; ++i )
|
|
{
|
|
// asAnimName=str+i;
|
|
// smPatykird1[i-1]=mdModel->GetFromName(asAnimName.c_str());
|
|
// smPatykird1[i-1]->WillBeAnimated();
|
|
}
|
|
}
|
|
|
|
else if( token == "animconrodprefix:" ) {
|
|
// prefiks korbowodów - na razie używamy modeli pantografów
|
|
parser.getTokens(); parser >> token;
|
|
for( int i = 1; i <= 2; i++ )
|
|
{
|
|
// asAnimName=str+i;
|
|
// smPatykirg1[i-1]=mdModel->GetFromName(asAnimName.c_str());
|
|
// smPatykirg1[i-1]->WillBeAnimated();
|
|
}
|
|
}
|
|
|
|
else if( token == "pistonfactors:" ) {
|
|
// Ra: parametry
|
|
// silnika parowego
|
|
// (tłoka)
|
|
/* //Ra: tymczasowo wyłączone ze względu na porządkowanie animacji
|
|
pantografów
|
|
pant1x=Parser->GetNextSymbol().ToDouble(); //kąt przesunięcia
|
|
dla
|
|
pierwszego tłoka
|
|
pant2x=Parser->GetNextSymbol().ToDouble(); //kąt przesunięcia
|
|
dla
|
|
drugiego tłoka
|
|
panty=Parser->GetNextSymbol().ToDouble(); //długość korby (r)
|
|
panth=Parser->GetNextSymbol().ToDouble(); //długoś korbowodu
|
|
(k)
|
|
*/
|
|
MoverParameters->EnginePowerSource.PowerType =
|
|
TPowerType::SteamPower; // Ra: po chamsku, ale z CHK nie działa
|
|
}
|
|
|
|
else if( token == "animreturnprefix:" ) {
|
|
// prefiks drążka mimośrodowego - na razie używamy modeli pantografów
|
|
parser.getTokens(1, false); parser >> token;
|
|
for( int i = 1; i <= 2; i++ )
|
|
{
|
|
// asAnimName=str+i;
|
|
// smPatykird2[i-1]=mdModel->GetFromName(asAnimName.c_str());
|
|
// smPatykird2[i-1]->WillBeAnimated();
|
|
}
|
|
}
|
|
|
|
else if (token == "animexplinkprefix:"){ // animreturnprefix:
|
|
// prefiks jarzma - na razie używamy modeli pantografów
|
|
parser.getTokens(1, false); parser >> token;
|
|
for( int i = 1; i <= 2; i++ )
|
|
{
|
|
// asAnimName=str+i;
|
|
// smPatykirg2[i-1]=mdModel->GetFromName(asAnimName.c_str());
|
|
// smPatykirg2[i-1]->WillBeAnimated();
|
|
}
|
|
}
|
|
|
|
else if( token == "animpendulumprefix:" ) {
|
|
// prefiks wahaczy
|
|
parser.getTokens(); parser >> token;
|
|
asAnimName = "";
|
|
for( int i = 1; i <= 4; ++i ) {
|
|
// McZapkie-050402: wyszukiwanie max 4 wahaczy o nazwie str*
|
|
asAnimName = token + std::to_string( i );
|
|
smWahacze[ i - 1 ] = GetSubmodelFromName( mdModel, asAnimName );
|
|
if( smWahacze[ i - 1 ] ) {
|
|
smWahacze[ i - 1 ]->WillBeAnimated();
|
|
}
|
|
}
|
|
parser.getTokens(); parser >> token;
|
|
if( token == "pendulumamplitude:" ) {
|
|
parser.getTokens( 1, false );
|
|
parser >> fWahaczeAmp;
|
|
}
|
|
}
|
|
|
|
else if( token == "animslottedlever:" ) {
|
|
// lever with a slot, turned by a pin on the coupling rod (e.g. speedometer drive)
|
|
// parameters: submodel name, number of axle (from animwheelprefix) driving the coupling rod, crank radius [m],
|
|
// pin position relative to the lever axis [m] and crank angle [deg] for wheel angle 0, in local (Y, Z) plane of the lever
|
|
// angle is measured from Y axis towards Z axis, i.e. in the direction of rotation around X axis
|
|
slottedlever_data lever;
|
|
int axle { 1 };
|
|
double crankradius { 0.0 };
|
|
double crankangle { 0.0 };
|
|
parser.getTokens( 6, false );
|
|
parser
|
|
>> asAnimName
|
|
>> axle
|
|
>> crankradius
|
|
>> lever.pin.x
|
|
>> lever.pin.y
|
|
>> crankangle;
|
|
lever.submodel = GetSubmodelFromName( mdModel, asAnimName );
|
|
if( lever.submodel != nullptr ) {
|
|
lever.submodel->WillBeAnimated();
|
|
lever.axle = std::max( 0, axle - 1 );
|
|
lever.crank = crankradius * glm::dvec2( std::cos( glm::radians( crankangle ) ), std::sin( glm::radians( crankangle ) ) );
|
|
m_slottedlevers.emplace_back( lever );
|
|
}
|
|
else {
|
|
ErrorLog( "Bad model: " + asFileName + " - missed submodel " + asAnimName, logtype::model );
|
|
}
|
|
}
|
|
|
|
else if( token == "animdoorprefix:" ) {
|
|
// nazwa animowanych drzwi
|
|
int i, j;
|
|
parser.getTokens(1, false); parser >> token;
|
|
for (i = 0, j = 0; i < ANIM_DOORS; ++i)
|
|
j += iAnimType[i]; // zliczanie wcześniejszych animacji
|
|
for (i = 0; i < iAnimType[ANIM_DOORS]; ++i) // liczba drzwi
|
|
{ // NBMX wrzesien 2003: wyszukiwanie drzwi o nazwie str*
|
|
// ustalenie submodelu
|
|
asAnimName = token + std::to_string(i + 1);
|
|
pAnimations[ i + j ].smAnimated = GetSubmodelFromName( mdModel, asAnimName );
|
|
if (pAnimations[i + j].smAnimated)
|
|
{ //++iAnimatedDoors;
|
|
pAnimations[i + j].smAnimated->WillBeAnimated(); // wyłączenie optymalizacji transformu
|
|
switch( MoverParameters->Doors.type )
|
|
{ // od razu zapinamy potrzebny typ animacji
|
|
case 1:
|
|
pAnimations[ i + j ].yUpdate = std::bind( &TDynamicObject::UpdateDoorTranslate, this, std::placeholders::_1 );
|
|
break;
|
|
case 2:
|
|
pAnimations[ i + j ].yUpdate = std::bind( &TDynamicObject::UpdateDoorRotate, this, std::placeholders::_1 );
|
|
break;
|
|
case 3:
|
|
pAnimations[ i + j ].yUpdate = std::bind( &TDynamicObject::UpdateDoorFold, this, std::placeholders::_1 );
|
|
break; // obrót 3 kolejnych submodeli
|
|
case 4:
|
|
pAnimations[ i + j ].yUpdate = std::bind( &TDynamicObject::UpdateDoorPlug, this, std::placeholders::_1 );
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
pAnimations[i + j].iNumber = i + 1; // parzyste działają inaczej niż nieparzyste
|
|
pAnimations[i + j].fMaxDist = 300 * 300; // drzwi to z daleka widać
|
|
/*
|
|
// NOTE: no longer used
|
|
pAnimations[i + j].fSpeed = Random(150); // oryginalny koncept z DoorSpeedFactor
|
|
pAnimations[i + j].fSpeed = (pAnimations[i + j].fSpeed + 100) / 100;
|
|
*/
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "animstepprefix:" ) {
|
|
// animated doorstep submodel name prefix
|
|
int i, j;
|
|
parser.getTokens(1, false); parser >> token;
|
|
for (i = 0, j = 0; i < ANIM_DOORSTEPS; ++i)
|
|
j += iAnimType[i]; // zliczanie wcześniejszych animacji
|
|
for (i = 0; i < iAnimType[ANIM_DOORSTEPS]; ++i) // liczba drzwi
|
|
{ // NBMX wrzesien 2003: wyszukiwanie drzwi o nazwie str*
|
|
// ustalenie submodelu
|
|
asAnimName = token + std::to_string(i + 1);
|
|
pAnimations[i + j].smAnimated = GetSubmodelFromName( mdModel, asAnimName );
|
|
if (pAnimations[i + j].smAnimated)
|
|
{ //++iAnimatedDoors;
|
|
pAnimations[i + j].smAnimated->WillBeAnimated(); // wyłączenie optymalizacji transformu
|
|
switch( MoverParameters->Doors.step_type )
|
|
{ // od razu zapinamy potrzebny typ animacji
|
|
case 1: // shift
|
|
pAnimations[ i + j ].yUpdate = std::bind( &TDynamicObject::UpdatePlatformTranslate, this, std::placeholders::_1 );
|
|
break;
|
|
case 2: // rotate
|
|
pAnimations[ i + j ].yUpdate = std::bind( &TDynamicObject::UpdatePlatformRotate, this, std::placeholders::_1 );
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
pAnimations[i + j].iNumber = i + 1; // parzyste działają inaczej niż nieparzyste
|
|
pAnimations[i + j].fMaxDist = 150 * 150; // drzwi to z daleka widać
|
|
/*
|
|
// NOTE: no longer used
|
|
pAnimations[i + j].fSpeed = Random(150); // oryginalny koncept z DoorSpeedFactor
|
|
pAnimations[i + j].fSpeed = (pAnimations[i + j].fSpeed + 100) / 100;
|
|
*/
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "animmirrorprefix:" ) {
|
|
// animated mirror submodel name prefix
|
|
int i, j;
|
|
parser.getTokens( 1, false ); parser >> token;
|
|
for( i = 0, j = 0; i < ANIM_MIRRORS; ++i )
|
|
j += iAnimType[ i ]; // zliczanie wcześniejszych animacji
|
|
for( i = 0; i < iAnimType[ ANIM_MIRRORS ]; ++i ) // liczba drzwi
|
|
{ // NBMX wrzesien 2003: wyszukiwanie drzwi o nazwie str*
|
|
// ustalenie submodelu
|
|
asAnimName = token + std::to_string( i + 1 );
|
|
pAnimations[ i + j ].smAnimated = GetSubmodelFromName( mdModel, asAnimName );
|
|
if( pAnimations[ i + j ].smAnimated ) {
|
|
pAnimations[ i + j ].smAnimated->WillBeAnimated(); // wyłączenie optymalizacji transformu
|
|
// od razu zapinamy potrzebny typ animacji
|
|
auto const offset { pAnimations[ i + j ].smAnimated->offset() };
|
|
pAnimations[ i + j ].yUpdate = std::bind( &TDynamicObject::UpdateMirror, this, std::placeholders::_1 );
|
|
// we don't expect more than 2-4 mirrors, so it should be safe to store submodel location (front/rear) in the higher bits
|
|
// parzyste działają inaczej niż nieparzyste
|
|
pAnimations[ i + j ].iNumber =
|
|
( ( pAnimations[ i + j ].smAnimated->offset().z > 0 ?
|
|
end::front :
|
|
end::rear ) << 4 )
|
|
+ i;
|
|
pAnimations[ i + j ].fMaxDist = 150 * 150; // drzwi to z daleka widać
|
|
/*
|
|
// NOTE: no longer used
|
|
pAnimations[i + j].fSpeed = Random(150); // oryginalny koncept z DoorSpeedFactor
|
|
pAnimations[i + j].fSpeed = (pAnimations[i + j].fSpeed + 100) / 100;
|
|
*/
|
|
}
|
|
}
|
|
}
|
|
|
|
else if (token == "animwiperprefix:")
|
|
{
|
|
parser.getTokens(1, false);
|
|
parser >> token;
|
|
TSubModel *sm;
|
|
if (wipers)
|
|
{
|
|
|
|
for (int i = 0; i < iAnimType[ANIM_WIPERS]; i++) // zebranie wszystkich submodeli wycieraczek
|
|
{
|
|
dWiperPos.emplace_back(0.0); // dodajemy na koniec zeby sie miejsce tam zrobilo i nie bylo invalid addressow potem
|
|
|
|
asAnimName = token + std::to_string(i + 1);
|
|
// element wycieraczki nr 1
|
|
sm = GetSubmodelFromName(mdModel, asAnimName + "_p1");
|
|
wipers[i].smElement[0] = sm;
|
|
if (sm)
|
|
{
|
|
wipers[i].smElement[0]->WillBeAnimated();
|
|
// auto const offset{wipers[i].smElement[0]->offset()};
|
|
}
|
|
|
|
// element wycieraczki nr 2
|
|
sm = GetSubmodelFromName(mdModel, asAnimName + "_p2");
|
|
wipers[i].smElement[1] = sm;
|
|
if (sm)
|
|
{
|
|
wipers[i].smElement[1]->WillBeAnimated();
|
|
// auto const offset{wipers[i].smElement[0]->offset()};
|
|
}
|
|
|
|
// element wycieraczki nr 3
|
|
sm = GetSubmodelFromName(mdModel, asAnimName + "_p3");
|
|
wipers[i].smElement[2] = sm;
|
|
if (sm)
|
|
{
|
|
wipers[i].smElement[2]->WillBeAnimated();
|
|
// auto const offset{wipers[i].smElement[0]->offset()};
|
|
}
|
|
wipers[i].yUpdate = std::bind(&TDynamicObject::UpdateWiper, this, std::placeholders::_1);
|
|
wipers[i].fMaxDist = 150 * 150;
|
|
wipers[i].iNumber = i;
|
|
}
|
|
}
|
|
}
|
|
|
|
} while( token != ""
|
|
&& token != "endmodels" );
|
|
|
|
if( false == MoverParameters->LoadAttributes.empty() ) {
|
|
// Ra: tu wczytywanie modelu ładunku jest w porządku
|
|
|
|
// bieżąca ścieżka do tekstur to dynamic/...
|
|
Global.asCurrentTexturePath = asBaseDir;
|
|
|
|
mdLoad = LoadMMediaFile_mdload( MoverParameters->LoadType.name );
|
|
|
|
// z powrotem defaultowa sciezka do tekstur
|
|
Global.asCurrentTexturePath = std::string( paths::textures );
|
|
}
|
|
|
|
} // models
|
|
|
|
else if( token == "sounds:" ) {
|
|
// dzwieki
|
|
do {
|
|
token = "";
|
|
parser.getTokens(); parser >> token;
|
|
if( token == "wheel_clatter:" ){
|
|
// polozenia osi w/m srodka pojazdu
|
|
double dSDist;
|
|
parser.getTokens( 1, false );
|
|
parser >> dSDist;
|
|
while( (token = parser.getToken<std::string>()) != ""
|
|
&& token != "end" ) {
|
|
// add another axle entry to the list
|
|
axle_sounds axle {
|
|
0,
|
|
std::atof( token.c_str() ) * -1.0, // for axle locations negative value means ahead of centre but vehicle faces +Z in 'its' space
|
|
{ sound_placement::external, static_cast<float>( dSDist ) } };
|
|
axle.clatter.deserialize( parser, sound_type::single );
|
|
axle.clatter.owner( this );
|
|
axle.clatter.offset( { 0, 0, axle.offset } );
|
|
m_axlesounds.emplace_back( axle );
|
|
}
|
|
// arrange the axles in case they're listed out of order
|
|
std::sort(
|
|
std::begin( m_axlesounds ), std::end( m_axlesounds ),
|
|
[]( axle_sounds const &Left, axle_sounds const &Right ) {
|
|
return Left.offset > Right.offset; } );
|
|
}
|
|
|
|
else if( token == "engine:"
|
|
&& MoverParameters->Power > 0 ) {
|
|
// plik z dzwiekiem silnika, mnozniki i ofsety amp. i czest.
|
|
m_powertrainsounds.engine.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
|
|
m_powertrainsounds.engine.owner( this );
|
|
|
|
auto const amplitudedivisor = static_cast<float>( MoverParameters->EngineType == TEngineType::DieselEngine ? 1 :
|
|
MoverParameters->EngineType == TEngineType::DieselElectric ? 1 :
|
|
MoverParameters->nmax * 60 + MoverParameters->Power * 3 );
|
|
m_powertrainsounds.engine.m_amplitudefactor /= amplitudedivisor;
|
|
|
|
} else if (token == "fakeengine:") {
|
|
m_powertrainsounds.fake_engine.deserialize(parser, sound_type::single);
|
|
m_powertrainsounds.fake_engine.owner(this);
|
|
}
|
|
|
|
else if( token == "dieselinc:" ) {
|
|
// dzwiek przy wlazeniu na obroty woodwarda
|
|
m_powertrainsounds.engine_revving.deserialize( parser, sound_type::single, sound_parameters::range );
|
|
m_powertrainsounds.engine_revving.owner( this );
|
|
}
|
|
|
|
else if( token == "oilpump:" ) {
|
|
m_powertrainsounds.oil_pump.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.oil_pump.owner( this );
|
|
}
|
|
|
|
else if( token == "fuelpump:" ) {
|
|
m_powertrainsounds.fuel_pump.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.fuel_pump.owner( this );
|
|
}
|
|
|
|
else if( token == "waterpump:" ) {
|
|
m_powertrainsounds.water_pump.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.water_pump.owner( this );
|
|
}
|
|
|
|
else if( token == "waterheater:" ) {
|
|
m_powertrainsounds.water_heater.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.water_heater.owner( this );
|
|
}
|
|
|
|
else if( token == "tractionmotor:" && MoverParameters->Power > 0 ) {
|
|
// plik z dzwiekiem silnika, mnozniki i ofsety amp. i czest.
|
|
sound_source motortemplate { sound_placement::external };
|
|
motortemplate.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
|
|
auto const amplitudedivisor { static_cast<float>( MoverParameters->nmax * 60 + MoverParameters->Power * 3 ) };
|
|
motortemplate.m_amplitudefactor /= amplitudedivisor;
|
|
motortemplate.owner( this );
|
|
|
|
auto &motors { m_powertrainsounds.motors };
|
|
|
|
if( true == motors.empty() ) {
|
|
// fallback for cases without specified motor locations, convert sound template to a single sound source
|
|
motors.emplace_back( motortemplate );
|
|
}
|
|
else {
|
|
// apply configuration to all defined motors
|
|
for( auto &motor : motors ) {
|
|
// combine potential x- and y-axis offsets of the sound template with z-axis offsets of individual motors
|
|
auto motoroffset { motortemplate.offset() };
|
|
motoroffset.z = motor.offset().z;
|
|
motor = motortemplate;
|
|
motor.offset( motoroffset );
|
|
// apply randomized playback start offset for each instance, to reduce potential reverb with identical nearby sources
|
|
motor.start( LocalRandom( 0.0, 1.0 ) );
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "tractionacmotor:" && MoverParameters->Power > 0 ) {
|
|
// plik z dzwiekiem silnika, mnozniki i ofsety amp. i czest.
|
|
sound_source motortemplate { sound_placement::external };
|
|
motortemplate.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
|
|
motortemplate.owner( this );
|
|
|
|
auto &motors { m_powertrainsounds.acmotors };
|
|
|
|
if( true == motors.empty() ) {
|
|
// fallback for cases without specified motor locations, convert sound template to a single sound source
|
|
motors.emplace_back( motortemplate );
|
|
}
|
|
else {
|
|
// apply configuration to all defined motors
|
|
for( auto &motor : motors ) {
|
|
// combine potential x- and y-axis offsets of the sound template with z-axis offsets of individual motors
|
|
auto motoroffset { motortemplate.offset() };
|
|
motoroffset.z = motor.offset().z;
|
|
motor = motortemplate;
|
|
motor.offset( motoroffset );
|
|
// apply randomized playback start offset for each instance, to reduce potential reverb with identical nearby sources
|
|
motor.start( LocalRandom( 0.0, 1.0 ) );
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "motorblower:" ) {
|
|
|
|
sound_source blowertemplate { sound_placement::engine };
|
|
blowertemplate.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
|
|
blowertemplate.owner( this );
|
|
|
|
auto const amplitudedivisor { static_cast<float>(
|
|
MoverParameters->MotorBlowers[ end::front ].speed > 0 ? MoverParameters->MotorBlowers[ end::front ].speed * MoverParameters->nmax * 60 + MoverParameters->Power * 3 :
|
|
blowertemplate.has_bookends() ? 1 : // NOTE: for motorblowers with fixed speed if the sound has defined bookends we skip revolutions-based part of frequency/volume adjustments
|
|
MoverParameters->MotorBlowers[ end::front ].speed * -1 ) };
|
|
blowertemplate.m_amplitudefactor /= amplitudedivisor;
|
|
blowertemplate.m_frequencyfactor /= amplitudedivisor;
|
|
|
|
if( true == m_powertrainsounds.motors.empty() ) {
|
|
// fallback for cases without specified motor locations, convert sound template to a single sound source
|
|
m_powertrainsounds.motorblowers.emplace_back( blowertemplate );
|
|
}
|
|
else {
|
|
// apply configuration to all defined motor blowers
|
|
for( auto &blower : m_powertrainsounds.motorblowers ) {
|
|
// combine potential x- and y-axis offsets of the sound template with z-axis offsets of individual blowers
|
|
auto bloweroffset { blowertemplate.offset() };
|
|
bloweroffset.z = blower.offset().z;
|
|
blower = blowertemplate;
|
|
blower.offset( bloweroffset );
|
|
// apply randomized playback start offset for each instance, to reduce potential reverb with identical nearby sources
|
|
blower.start( LocalRandom( 0.0, 1.0 ) );
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "inverter:" ) {
|
|
// plik z dzwiekiem wentylatora, mnozniki i ofsety amp. i czest.
|
|
m_powertrainsounds.inverter.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
|
|
m_powertrainsounds.inverter.owner( this );
|
|
}
|
|
|
|
else if( token == "ventilator:" ) {
|
|
// plik z dzwiekiem wentylatora, mnozniki i ofsety amp. i czest.
|
|
m_powertrainsounds.rsWentylator.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude | sound_parameters::frequency );
|
|
m_powertrainsounds.rsWentylator.owner( this );
|
|
|
|
m_powertrainsounds.rsWentylator.m_amplitudefactor /= MoverParameters->RVentnmax;
|
|
m_powertrainsounds.rsWentylator.m_frequencyfactor /= MoverParameters->RVentnmax;
|
|
}
|
|
|
|
else if( token == "radiatorfan1:" ) {
|
|
// primary circuit radiator fan
|
|
m_powertrainsounds.radiator_fan.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.radiator_fan.owner( this );
|
|
}
|
|
|
|
else if( token == "radiatorfan2" ) {
|
|
// auxiliary circuit radiator fan
|
|
m_powertrainsounds.radiator_fan_aux.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.radiator_fan_aux.owner( this );
|
|
}
|
|
|
|
else if( token == "transmission:" ) {
|
|
// plik z dzwiekiem, mnozniki i ofsety amp. i czest.
|
|
// NOTE, fixed default parameters, legacy system leftover
|
|
auto &sound { m_powertrainsounds.transmission };
|
|
sound.m_amplitudefactor = 0.029;
|
|
sound.m_amplitudeoffset = 0.1;
|
|
sound.m_frequencyfactor = 0.005;
|
|
sound.m_frequencyoffset = 1.0;
|
|
|
|
sound.deserialize( parser, sound_type::single, sound_parameters::range );
|
|
sound.owner( this );
|
|
}
|
|
|
|
else if( token == "brakesound:" ) {
|
|
// hamowanie zwykle:
|
|
rsBrake.deserialize( parser, sound_type::single, sound_parameters::amplitude | sound_parameters::frequency );
|
|
rsBrake.owner( this );
|
|
// NOTE: can't pre-calculate amplitude normalization based on max brake force, as this varies depending on vehicle speed
|
|
rsBrake.m_frequencyfactor /= 1 + MoverParameters->Vmax;
|
|
}
|
|
|
|
else if( token == "brake:" ) {
|
|
// plik z piskiem hamulca, mnozniki i ofsety amplitudy.
|
|
rsPisk.deserialize( parser, sound_type::single, sound_parameters::range | sound_parameters::amplitude );
|
|
rsPisk.owner( this );
|
|
|
|
if( rsPisk.m_amplitudefactor > 10.f ) {
|
|
// HACK: convert old style activation point threshold to the new, regular amplitude adjustment system
|
|
rsPisk.m_amplitudefactor = 1.f;
|
|
rsPisk.m_amplitudeoffset = 0.f;
|
|
}
|
|
rsPisk.m_amplitudeoffset *= ( 105.f - Random( 10.f ) ) / 100.f;
|
|
}
|
|
|
|
else if( token == "brakecylinderinc:" ) {
|
|
// brake cylinder pressure increase sounds
|
|
m_brakecylinderpistonadvance.deserialize( parser, sound_type::single );
|
|
m_brakecylinderpistonadvance.owner( this );
|
|
}
|
|
|
|
else if( token == "brakecylinderdec:" ) {
|
|
// brake cylinder pressure decrease sounds
|
|
m_brakecylinderpistonrecede.deserialize( parser, sound_type::single );
|
|
m_brakecylinderpistonrecede.owner( this );
|
|
}
|
|
|
|
else if (token == "epbrakeinc:") {
|
|
// brake cylinder pressure increase sounds
|
|
m_epbrakepressureincrease.deserialize(parser, sound_type::single);
|
|
m_epbrakepressureincrease.owner(this);
|
|
}
|
|
|
|
else if (token == "epbrakedec:") {
|
|
// brake cylinder pressure decrease sounds
|
|
m_epbrakepressuredecrease.deserialize(parser, sound_type::single);
|
|
m_epbrakepressuredecrease.owner(this);
|
|
}
|
|
|
|
else if( token == "emergencybrake:" ) {
|
|
// emergency brake sound
|
|
m_emergencybrake.deserialize( parser, sound_type::single );
|
|
m_emergencybrake.owner( this );
|
|
}
|
|
|
|
else if( token == "brakeacc:" ) {
|
|
// plik z przyspieszaczem (upust po zlapaniu hamowania)
|
|
sBrakeAcc.deserialize( parser, sound_type::single );
|
|
sBrakeAcc.owner( this );
|
|
|
|
bBrakeAcc = true;
|
|
}
|
|
|
|
else if( token == "unbrake:" ) {
|
|
// plik z piskiem hamulca, mnozniki i ofsety amplitudy.
|
|
rsUnbrake.m_amplitudefactor = 20.0f;
|
|
rsUnbrake.deserialize( parser, sound_type::single, sound_parameters::range );
|
|
rsUnbrake.owner( this );
|
|
}
|
|
// spring brake sounds
|
|
else if( token == "springbrake:" ) {
|
|
m_springbrakesounds.activate.deserialize( parser, sound_type::single );
|
|
m_springbrakesounds.activate.owner( this );
|
|
}
|
|
else if( token == "springbrakeoff:" ) {
|
|
m_springbrakesounds.release.deserialize( parser, sound_type::single );
|
|
m_springbrakesounds.release.owner( this );
|
|
}
|
|
|
|
else if( token == "derail:" ) {
|
|
// dzwiek przy wykolejeniu
|
|
rsDerailment.deserialize( parser, sound_type::single, sound_parameters::range );
|
|
rsDerailment.owner( this );
|
|
}
|
|
|
|
else if( token == "curve:" ) {
|
|
rscurve.deserialize( parser, sound_type::single, sound_parameters::range );
|
|
rscurve.owner( this );
|
|
}
|
|
|
|
else if( token == "horn1:" ) {
|
|
// pliki z trabieniem
|
|
sHorn1.deserialize( parser, sound_type::multipart, sound_parameters::range );
|
|
sHorn1.owner( this );
|
|
}
|
|
|
|
else if( token == "horn2:" ) {
|
|
// pliki z trabieniem wysokoton.
|
|
sHorn2.deserialize( parser, sound_type::multipart, sound_parameters::range );
|
|
sHorn2.owner( this );
|
|
// TBD, TODO: move horn selection to ai config file
|
|
if( iHornWarning ) {
|
|
iHornWarning = 2; // numer syreny do użycia po otrzymaniu sygnału do jazdy
|
|
}
|
|
}
|
|
|
|
else if( token == "horn3:" ) {
|
|
sHorn3.deserialize( parser, sound_type::multipart, sound_parameters::range );
|
|
sHorn3.owner( this );
|
|
}
|
|
|
|
else if( token == "pantographup:" ) {
|
|
// pliki dzwiekow pantografow
|
|
sound_source pantographup { sound_placement::external };
|
|
pantographup.deserialize( parser, sound_type::single );
|
|
pantographup.owner( this );
|
|
for( auto &pantograph : m_pantographsounds ) {
|
|
pantograph.sPantUp = pantographup;
|
|
}
|
|
}
|
|
|
|
else if( token == "pantographdown:" ) {
|
|
// pliki dzwiekow pantografow
|
|
sound_source pantographdown { sound_placement::external };
|
|
pantographdown.deserialize( parser, sound_type::single );
|
|
pantographdown.owner( this );
|
|
for( auto &pantograph : m_pantographsounds ) {
|
|
pantograph.sPantDown = pantographdown;
|
|
}
|
|
}
|
|
|
|
else if( token == "compressor:" ) {
|
|
// pliki ze sprezarka
|
|
sCompressor.deserialize( parser, sound_type::multipart, sound_parameters::range );
|
|
sCompressor.owner( this );
|
|
}
|
|
|
|
else if( token == "compressoridle:" ) {
|
|
// pliki ze sprezarka
|
|
sCompressorIdle.deserialize( parser, sound_type::multipart, sound_parameters::range );
|
|
sCompressorIdle.owner( this );
|
|
}
|
|
|
|
else if( token == "converter:" ) {
|
|
// pliki z przetwornica
|
|
sConverter.deserialize( parser, sound_type::multipart, sound_parameters::range );
|
|
sConverter.owner( this );
|
|
}
|
|
|
|
// Dzwiek wentylatora rezystora hamowania
|
|
else if (token == "brakingresistorventilator:")
|
|
{
|
|
sBRVent.deserialize(parser, sound_type::multipart, sound_parameters::range);
|
|
sBRVent.owner(this);
|
|
}
|
|
|
|
else if( token == "heater:" ) {
|
|
// train heating device
|
|
sHeater.deserialize( parser, sound_type::single );
|
|
sHeater.owner( this );
|
|
}
|
|
|
|
else if( token == "battery:" ) {
|
|
// train heating device
|
|
m_batterysound.deserialize( parser, sound_type::single );
|
|
m_batterysound.owner( this );
|
|
}
|
|
|
|
else if( token == "turbo:" ) {
|
|
// pliki z turbogeneratorem
|
|
m_powertrainsounds.engine_turbo.deserialize( parser, sound_type::multipart, sound_parameters::range );
|
|
m_powertrainsounds.engine_turbo.owner( this );
|
|
m_powertrainsounds.engine_turbo.gain( 0 );
|
|
}
|
|
|
|
else if( token == "small-compressor:" ) {
|
|
// pliki z przetwornica
|
|
sSmallCompressor.deserialize( parser, sound_type::multipart, sound_parameters::range );
|
|
sSmallCompressor.owner( this );
|
|
}
|
|
|
|
else if( token == "departuresignal:" ) {
|
|
// pliki z sygnalem odjazdu
|
|
sound_source soundtemplate { sound_placement::general, 25.f };
|
|
soundtemplate.deserialize( parser, sound_type::multipart, sound_parameters::range );
|
|
soundtemplate.owner( this );
|
|
for( auto &speaker : m_doorspeakers ) {
|
|
speaker.departure_signal = soundtemplate;
|
|
speaker.departure_signal.offset( speaker.offset );
|
|
}
|
|
}
|
|
|
|
else if( token == "dooropen:" ) {
|
|
sound_source soundtemplate { sound_placement::general };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &door : m_doorsounds ) {
|
|
// apply configuration to all defined doors, but preserve their individual offsets
|
|
auto const dooroffset { door.rsDoorOpen.offset() };
|
|
door.rsDoorOpen = soundtemplate;
|
|
door.rsDoorOpen.offset( dooroffset );
|
|
}
|
|
}
|
|
|
|
else if( token == "doorclose:" ) {
|
|
sound_source soundtemplate { sound_placement::general };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &door : m_doorsounds ) {
|
|
// apply configuration to all defined doors, but preserve their individual offsets
|
|
auto const dooroffset { door.rsDoorClose.offset() };
|
|
door.rsDoorClose = soundtemplate;
|
|
door.rsDoorClose.offset( dooroffset );
|
|
}
|
|
}
|
|
|
|
else if( token == "doorlock:" ) {
|
|
sound_source soundtemplate { sound_placement::general };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &door : m_doorsounds ) {
|
|
// apply configuration to all defined doors, but preserve their individual offsets
|
|
auto const dooroffset { door.lock.offset() };
|
|
door.lock = soundtemplate;
|
|
door.lock.offset( dooroffset );
|
|
}
|
|
}
|
|
|
|
else if( token == "doorunlock:" ) {
|
|
sound_source soundtemplate { sound_placement::general };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &door : m_doorsounds ) {
|
|
// apply configuration to all defined doors, but preserve their individual offsets
|
|
auto const dooroffset { door.unlock.offset() };
|
|
door.unlock = soundtemplate;
|
|
door.unlock.offset( dooroffset );
|
|
}
|
|
}
|
|
|
|
else if( token == "doorstepopen:" ) {
|
|
sound_source soundtemplate { sound_placement::general };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &door : m_doorsounds ) {
|
|
// apply configuration to all defined doors, but preserve their individual offsets
|
|
auto const dooroffset { door.step_open.offset() };
|
|
door.step_open = soundtemplate;
|
|
door.step_open.offset( dooroffset );
|
|
}
|
|
}
|
|
|
|
else if( token == "mirroropen:" || token == "mirrorclose:" ) {
|
|
sound_source soundtemplate { sound_placement::general };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &mirror : m_mirrorsounds ) {
|
|
// apply configuration to all defined mirrors, but preserve their individual offsets
|
|
auto &sound { token == "mirroropen:" ? mirror.unfold : mirror.fold };
|
|
auto const mirroroffset { sound.offset() };
|
|
sound = soundtemplate;
|
|
sound.offset( mirroroffset );
|
|
}
|
|
}
|
|
|
|
else if( token == "doorstepclose:" ) {
|
|
sound_source soundtemplate { sound_placement::general };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &door : m_doorsounds ) {
|
|
// apply configuration to all defined doors, but preserve their individual offsets
|
|
auto const dooroffset { door.step_close.offset() };
|
|
door.step_close = soundtemplate;
|
|
door.step_close.offset( dooroffset );
|
|
}
|
|
}
|
|
|
|
else if( token == "doorpermit:" ) {
|
|
sound_source soundtemplate { sound_placement::general };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &door : m_doorsounds ) {
|
|
// apply configuration to all defined doors, but preserve their individual offsets
|
|
auto const dooroffset { door.permit_granted.offset() };
|
|
door.permit_granted = soundtemplate;
|
|
door.permit_granted.offset( dooroffset );
|
|
}
|
|
}
|
|
|
|
else if( token == "unloading:" ) {
|
|
m_exchangesounds.unloading.range( MoverParameters->Dim.L * 0.5f * -1 );
|
|
m_exchangesounds.unloading.deserialize( parser, sound_type::single );
|
|
m_exchangesounds.unloading.owner( this );
|
|
}
|
|
|
|
else if( token == "loading:" ) {
|
|
m_exchangesounds.loading.range( MoverParameters->Dim.L * 0.5f * -1 );
|
|
m_exchangesounds.loading.deserialize( parser, sound_type::single );
|
|
m_exchangesounds.loading.owner( this );
|
|
}
|
|
|
|
else if( token == "sand:" ) {
|
|
sSand.deserialize( parser, sound_type::multipart, sound_parameters::range );
|
|
sSand.owner( this );
|
|
}
|
|
|
|
else if( token == "releaser:" ) {
|
|
// pliki z odluzniaczem
|
|
sReleaser.deserialize( parser, sound_type::multipart, sound_parameters::range );
|
|
sReleaser.owner( this );
|
|
}
|
|
|
|
else if( token == "outernoise:" ) {
|
|
// szum podczas jazdy:
|
|
sound_source noisetemplate{ sound_placement::external, EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
|
|
noisetemplate.deserialize( parser, sound_type::single, sound_parameters::amplitude | sound_parameters::frequency, MoverParameters->Vmax );
|
|
noisetemplate.owner( this );
|
|
|
|
noisetemplate.m_amplitudefactor /= 1 + MoverParameters->Vmax;
|
|
noisetemplate.m_frequencyfactor /= 1 + MoverParameters->Vmax;
|
|
#ifdef EU07_SOUND_BOGIESOUNDS
|
|
if( true == m_bogiesounds.empty() ) {
|
|
// fallback for cases without specified noise locations, convert sound template to a single sound source
|
|
m_bogiesounds.emplace_back( noisetemplate );
|
|
}
|
|
else {
|
|
// apply configuration to all defined bogies
|
|
for( auto &bogie : m_bogiesounds ) {
|
|
// combine potential x- and y-axis offsets of the sound template with z-axis offsets of individual motors
|
|
auto bogieoffset{ noisetemplate.offset() };
|
|
bogieoffset.z = bogie.offset().z;
|
|
bogie = noisetemplate;
|
|
bogie.offset( bogieoffset );
|
|
}
|
|
}
|
|
// apply randomized playback start offset for each bogie, to reduce potential reverb with identical nearby sources
|
|
auto bogieidx( 0 );
|
|
for( auto &bogie : m_bogiesounds ) {
|
|
bogie.start( (
|
|
bogieidx % 2 ?
|
|
LocalRandom( 0.0, 30.0 ) :
|
|
LocalRandom( 50.0, 80.0 ) )
|
|
* 0.01 );
|
|
++bogieidx;
|
|
}
|
|
#else
|
|
m_outernoise = noisetemplate;
|
|
// apply randomized playback start offset, to reduce potential reverb with identical nearby sources
|
|
m_outernoise.start( Random( 0.0, 80.0 ) * 0.01 );
|
|
#endif
|
|
}
|
|
|
|
else if( token == "wheelflat:" ) {
|
|
// szum podczas jazdy:
|
|
m_wheelflat.deserialize( parser, sound_type::single, sound_parameters::frequency );
|
|
m_wheelflat.owner( this );
|
|
}
|
|
|
|
else if(token == "announcements:") {
|
|
// announcement sounds
|
|
// content provided as "key: value" pairs together enclosed in "{}"
|
|
// value can be optionally set of values enclosed in "[]" in which case one value will be picked randomly
|
|
std::unordered_map<std::string, announcement_t> const announcements = {
|
|
{ "near_stop:", announcement_t::approaching },
|
|
{ "stop:", announcement_t::current },
|
|
{ "next_stop:", announcement_t::next },
|
|
{ "destination:", announcement_t::destination },
|
|
{ "chime:", announcement_t::chime } };
|
|
while( (token = parser.getToken<std::string>()) != ""
|
|
&& token != "}" ) {
|
|
if( token.back() == ':' ) {
|
|
|
|
if( token == "soundproofing:" ) {
|
|
// custom soundproofing in format [ p1, p2, p3, p4, p5, p6 ]
|
|
parser.getTokens( 6, false, "\n\r\t ,;[]" );
|
|
std::array<float, 6> soundproofing;
|
|
parser
|
|
>> soundproofing[ 0 ]
|
|
>> soundproofing[ 1 ]
|
|
>> soundproofing[ 2 ]
|
|
>> soundproofing[ 3 ]
|
|
>> soundproofing[ 4 ]
|
|
>> soundproofing[ 5 ];
|
|
for( auto & soundproofingelement : soundproofing ) {
|
|
if( soundproofingelement != -1.f ) {
|
|
soundproofingelement = std::sqrt( std::clamp( soundproofingelement, 0.f, 1.f ) );
|
|
}
|
|
}
|
|
m_pasystem.soundproofing = soundproofing;
|
|
continue;
|
|
}
|
|
|
|
auto const lookup { announcements.find( token ) };
|
|
auto const announcementtype { (
|
|
lookup != announcements.end() ?
|
|
lookup->second :
|
|
announcement_t::idle ) };
|
|
// NOTE: we retrieve key value for all keys, not just recognized ones
|
|
if( announcementtype == announcement_t::idle ) {
|
|
token = parser.getToken<std::string>();
|
|
continue;
|
|
}
|
|
/*
|
|
auto announcementsound { deserialize_random_set( parser ) };
|
|
replace_slashes( announcementsound );
|
|
*/
|
|
sound_source soundtemplate { sound_placement::engine }; // NOTE: sound range gets filled by pa system
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
m_pasystem.announcements[ static_cast<int>( announcementtype ) ] = soundtemplate;
|
|
}
|
|
}
|
|
// set provided custom soundproofing to assigned sounds (for sounds without their own custom soundproofing)
|
|
if( m_pasystem.soundproofing ) {
|
|
for( auto &announcement : m_pasystem.announcements ) {
|
|
if( !announcement.soundproofing() ) {
|
|
announcement.soundproofing() = m_pasystem.soundproofing;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} while( token != ""
|
|
&& token != "endsounds" );
|
|
|
|
} // sounds:
|
|
|
|
else if( token == "locations:" ) {
|
|
do {
|
|
token = "";
|
|
parser.getTokens(); parser >> token;
|
|
|
|
if( token == "doors:" ) {
|
|
// a list of pairs: offset along vehicle's z-axis and sides on which the door is present; followed with "end"
|
|
while( (token = parser.getToken<std::string>()) != ""
|
|
&& token != "end" ) {
|
|
// vehicle faces +Z in 'its' space, for door locations negative value means ahead of centre
|
|
auto const offset { std::atof( token.c_str() ) * -1.f };
|
|
// recognized side specifications are "right", "left" and "both"
|
|
auto const sides { parser.getToken<std::string>() };
|
|
// NOTE: we skip setting owner of the sounds, it'll be done during individual sound deserialization
|
|
door_sounds door;
|
|
// add entries to the list:
|
|
if( sides == "both"
|
|
|| sides == "left" ) {
|
|
// left...
|
|
auto const location { glm::vec3 { MoverParameters->Dim.W * 0.5f, MoverParameters->Dim.H * 0.5f, offset } };
|
|
door.placement = side::left;
|
|
door.rsDoorClose.offset( location );
|
|
door.rsDoorOpen.offset( location );
|
|
door.lock.offset( location );
|
|
door.unlock.offset( location );
|
|
door.step_close.offset( location );
|
|
door.step_open.offset( location );
|
|
door.permit_granted.offset( location );
|
|
m_doorsounds.emplace_back( door );
|
|
}
|
|
if( sides == "both"
|
|
|| sides == "right" ) {
|
|
// ...and right
|
|
auto const location { glm::vec3 { MoverParameters->Dim.W * -0.5f, 2.f, offset } };
|
|
door.placement = side::right;
|
|
door.rsDoorClose.offset( location );
|
|
door.rsDoorOpen.offset( location );
|
|
door.lock.offset( location );
|
|
door.unlock.offset( location );
|
|
door.step_close.offset( location );
|
|
door.step_open.offset( location );
|
|
door.permit_granted.offset( location );
|
|
m_doorsounds.emplace_back( door );
|
|
}
|
|
m_doorspeakers.emplace_back(
|
|
doorspeaker_sounds {
|
|
{ 0.f, 3.f, offset },
|
|
{} } );
|
|
}
|
|
}
|
|
|
|
else if( token == "mirrors:" ) {
|
|
// a list of offsets along vehicle's z-axis of the mirror pairs, one at each cab; followed with "end"
|
|
while( (token = parser.getToken<std::string>()) != ""
|
|
&& token != "end" ) {
|
|
// vehicle faces +Z in 'its' space, as for the doors negative value means ahead of centre
|
|
auto const offset { std::atof( token.c_str() ) * -1.f };
|
|
mirror_sounds mirror;
|
|
mirror.end = offset >= 0.f ? end::front : end::rear;
|
|
for( auto const mirrorside : { side::left, side::right } ) {
|
|
auto const location { glm::vec3 {
|
|
MoverParameters->Dim.W * ( mirrorside == side::left ? 0.5f : -0.5f ),
|
|
MoverParameters->Dim.H * 0.5f,
|
|
offset } };
|
|
mirror.placement = mirrorside;
|
|
mirror.unfold.offset( location );
|
|
mirror.fold.offset( location );
|
|
m_mirrorsounds.emplace_back( mirror );
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "tractionmotors:" ) {
|
|
// a list of offsets along vehicle's z-axis; followed with "end"
|
|
while( (token = parser.getToken<std::string>()) != ""
|
|
&& token != "end" ) {
|
|
// vehicle faces +Z in 'its' space, for motor locations negative value means ahead of centre
|
|
auto const offset { std::atof( token.c_str() ) * -1.f };
|
|
// NOTE: we skip setting owner of the sounds, it'll be done during individual sound deserialization
|
|
sound_source motor { sound_placement::external }; // generic traction motor sounds
|
|
sound_source acmotor { sound_placement::external }; // inverter-specific traction motor sounds
|
|
sound_source motorblower { sound_placement::engine }; // associated motor blowers
|
|
// add entry to the list
|
|
auto const location { glm::vec3 { 0.f, 0.f, offset } };
|
|
motor.offset( location );
|
|
m_powertrainsounds.motors.emplace_back( motor );
|
|
acmotor.offset( location );
|
|
m_powertrainsounds.acmotors.emplace_back( acmotor );
|
|
motorblower.offset( location );
|
|
m_powertrainsounds.motorblowers.emplace_back( motorblower );
|
|
}
|
|
}
|
|
|
|
else if( token == "bogies:" ) {
|
|
// a list of offsets along vehicle's z-axis; followed with "end"
|
|
while( (token = parser.getToken<std::string>()) != ""
|
|
&& token != "end" ) {
|
|
// vehicle faces +Z in 'its' space, for bogie locations negative value means ahead of centre
|
|
auto const offset { std::atof( token.c_str() ) * -1.f };
|
|
// NOTE: we skip setting owner of the sounds, it'll be done during individual sound deserialization
|
|
sound_source bogienoise { sound_placement::external, EU07_SOUND_RUNNINGNOISECUTOFFRANGE };
|
|
// add entry to the list
|
|
auto const location { glm::vec3 { 0.f, 0.f, offset } };
|
|
bogienoise.offset( location );
|
|
#ifdef EU07_SOUND_BOGIESOUNDS
|
|
m_bogiesounds.emplace_back( bogienoise );
|
|
#endif
|
|
}
|
|
}
|
|
|
|
} while( token != ""
|
|
&& token != "endlocations" );
|
|
|
|
} // locations:
|
|
|
|
else if( token == "internaldata:" ) {
|
|
// dalej nie czytaj
|
|
do {
|
|
// zbieranie informacji o kabinach
|
|
token = "";
|
|
parser.getTokens(); parser >> token;
|
|
if( token == "cab0model:" ) {
|
|
parser.getTokens(); parser >> token;
|
|
if( token != "none" ) { iCabs |= 0x2; }
|
|
}
|
|
else if( token == "cab1model:" ) {
|
|
parser.getTokens(); parser >> token;
|
|
if( token != "none" ) { iCabs |= 0x1; }
|
|
}
|
|
else if( token == "cab2model:" ) {
|
|
parser.getTokens(); parser >> token;
|
|
if( token != "none" ) { iCabs |= 0x4; }
|
|
}
|
|
// engine sounds
|
|
else if( token == "ignition:" ) {
|
|
// odpalanie silnika
|
|
m_powertrainsounds.engine_ignition.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.engine_ignition.owner( this );
|
|
} else if (token == "shutdown:") {
|
|
m_powertrainsounds.engine_shutdown.deserialize(parser, sound_type::single);
|
|
m_powertrainsounds.engine_shutdown.owner(this);
|
|
} else if( token == "engageslippery:" ) {
|
|
// tarcie tarcz sprzegla:
|
|
m_powertrainsounds.rsEngageSlippery.deserialize( parser, sound_type::single, sound_parameters::amplitude | sound_parameters::frequency );
|
|
m_powertrainsounds.rsEngageSlippery.owner( this );
|
|
|
|
m_powertrainsounds.rsEngageSlippery.m_frequencyfactor /= 1 + MoverParameters->nmax;
|
|
}
|
|
|
|
// dzwieki wycieraczkuf
|
|
else if (token == "wiperfrompark:")
|
|
{
|
|
sWiperFromPark.deserialize(parser, sound_type::single);
|
|
sWiperFromPark.owner(this);
|
|
}
|
|
else if (token == "wipertopark:")
|
|
{
|
|
sWiperToPark.deserialize(parser, sound_type::single);
|
|
sWiperToPark.owner(this);
|
|
}
|
|
|
|
else if (token == "retarder:") {
|
|
m_powertrainsounds.retarder.deserialize(parser, sound_type::single, sound_parameters::amplitude | sound_parameters::frequency);
|
|
m_powertrainsounds.retarder.owner(this);
|
|
}
|
|
else if( token == "linebreakerclose:" ) {
|
|
m_powertrainsounds.linebreaker_close.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.linebreaker_close.owner( this );
|
|
}
|
|
else if( token == "linebreakeropen:" ) {
|
|
m_powertrainsounds.linebreaker_open.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.linebreaker_open.owner( this );
|
|
}
|
|
else if( token == "relay:" ) {
|
|
// styczniki itp:
|
|
m_powertrainsounds.motor_relay.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.motor_relay.owner( this );
|
|
}
|
|
else if( token == "shuntfield:" ) {
|
|
// styczniki itp:
|
|
m_powertrainsounds.motor_shuntfield.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.motor_shuntfield.owner( this );
|
|
}
|
|
else if( token == "wejscie_na_bezoporow:" ) {
|
|
// hunter-111211: wydzielenie wejscia na bezoporowa i na drugi uklad do pliku
|
|
m_powertrainsounds.dsbWejscie_na_bezoporow.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.dsbWejscie_na_bezoporow.owner( this );
|
|
}
|
|
// przekazniki od kierunku jazdy
|
|
else if (token == "directionrelay_d:") {
|
|
// przekaznik od kierunku jazdy do przodu
|
|
sDirectionRelayD.deserialize(parser, sound_type::single);
|
|
sDirectionRelayD.owner(this);
|
|
}
|
|
else if (token == "directionrelay_r:") {
|
|
// przekaznik od kierunku jazdy do tylu
|
|
sDirectionRelayR.deserialize(parser, sound_type::single);
|
|
sDirectionRelayR.owner(this);
|
|
}
|
|
else if (token == "directionrelay_n:")
|
|
{
|
|
// przekaznik od kierunku jazdy do tylu
|
|
sDirectionRelayN.deserialize(parser, sound_type::single);
|
|
sDirectionRelayN.owner(this);
|
|
}
|
|
else if( token == "wejscie_na_drugi_uklad:" ) {
|
|
m_powertrainsounds.motor_parallel.deserialize( parser, sound_type::single );
|
|
m_powertrainsounds.motor_parallel.owner( this );
|
|
}
|
|
else if( token == "pneumaticrelay:" ) {
|
|
// wylaczniki pneumatyczne:
|
|
dsbPneumaticRelay.deserialize( parser, sound_type::single );
|
|
dsbPneumaticRelay.owner( this );
|
|
}
|
|
else if( token == "slipperysound:" ) {
|
|
// sanie:
|
|
rsSlippery.deserialize( parser, sound_type::single, sound_parameters::amplitude );
|
|
rsSlippery.owner( this );
|
|
|
|
rsSlippery.m_amplitudefactor /= 1 + MoverParameters->Vmax;
|
|
}
|
|
// coupler sounds
|
|
else if( token == "couplerattach:" ) {
|
|
sound_source soundtemplate { sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.attach_coupler = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "brakehoseattach:" ) {
|
|
// laczenie:
|
|
sound_source soundtemplate { sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.attach_brakehose = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "mainhoseattach:" ) {
|
|
// laczenie:
|
|
sound_source soundtemplate{ sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.attach_mainhose = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "controlattach:" ) {
|
|
// laczenie:
|
|
sound_source soundtemplate{ sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.attach_control = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "gangwayattach:" ) {
|
|
// laczenie:
|
|
sound_source soundtemplate{ sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.attach_gangway = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "heatingattach:" ) {
|
|
// laczenie:
|
|
sound_source soundtemplate{ sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.attach_heating = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "couplerdetach:" ) {
|
|
// rozlaczanie:
|
|
sound_source soundtemplate { sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.detach_coupler = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "brakehosedetach:" ) {
|
|
// rozlaczanie:
|
|
sound_source soundtemplate { sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.detach_brakehose = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "mainhosedetach:" ) {
|
|
// rozlaczanie:
|
|
sound_source soundtemplate{ sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.detach_mainhose = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "controldetach:" ) {
|
|
// rozlaczanie:
|
|
sound_source soundtemplate{ sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.detach_control = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "gangwaydetach:" ) {
|
|
// rozlaczanie:
|
|
sound_source soundtemplate{ sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.detach_gangway = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "heatingdetach:" ) {
|
|
// rozlaczanie:
|
|
sound_source soundtemplate{ sound_placement::external };
|
|
soundtemplate.deserialize( parser, sound_type::single );
|
|
soundtemplate.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.detach_heating = soundtemplate;
|
|
}
|
|
}
|
|
else if( token == "couplerstretch:" ) {
|
|
// coupler stretching
|
|
sound_source couplerstretch { sound_placement::external };
|
|
couplerstretch.deserialize( parser, sound_type::single );
|
|
couplerstretch.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.dsbCouplerStretch = couplerstretch;
|
|
}
|
|
}
|
|
else if( token == "couplerstretch_loud:" ) {
|
|
// coupler stretching
|
|
sound_source couplerstretch { sound_placement::external };
|
|
couplerstretch.deserialize( parser, sound_type::single );
|
|
couplerstretch.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.dsbCouplerStretch_loud = couplerstretch;
|
|
}
|
|
}
|
|
else if( token == "bufferclamp:" ) {
|
|
// buffers hitting one another
|
|
sound_source bufferclash { sound_placement::external };
|
|
bufferclash.deserialize( parser, sound_type::single );
|
|
bufferclash.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.dsbBufferClamp = bufferclash;
|
|
}
|
|
}
|
|
else if( token == "bufferclamp_loud:" ) {
|
|
// buffers hitting one another
|
|
sound_source bufferclash { sound_placement::external };
|
|
bufferclash.deserialize( parser, sound_type::single );
|
|
bufferclash.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.dsbBufferClamp_loud = bufferclash;
|
|
}
|
|
}
|
|
else if( token == "coupleradapterattach:" ) {
|
|
// laczenie:
|
|
sound_source adapterattach { sound_placement::external };
|
|
adapterattach.deserialize( parser, sound_type::single );
|
|
adapterattach.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.dsbAdapterAttach = adapterattach;
|
|
}
|
|
}
|
|
else if( token == "coupleradapterremove:" ) {
|
|
// rozlaczanie:
|
|
sound_source adapterremove { sound_placement::external };
|
|
adapterremove.deserialize( parser, sound_type::single );
|
|
adapterremove.owner( this );
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
couplersounds.dsbAdapterRemove = adapterremove;
|
|
}
|
|
}
|
|
else if( token == "startjolt:" ) {
|
|
// movement start jolt
|
|
m_startjolt.deserialize( parser, sound_type::single );
|
|
m_startjolt.owner( this );
|
|
}
|
|
|
|
else if (token == "mechspring:")
|
|
{
|
|
// parametry bujania kamery:
|
|
double ks, kd;
|
|
parser.getTokens(2, false);
|
|
parser
|
|
>> ks
|
|
>> kd;
|
|
ShakeSpring.Init(ks, kd);
|
|
parser.getTokens(6, false);
|
|
parser
|
|
>> BaseShake.jolt_scale.x
|
|
>> BaseShake.jolt_scale.y
|
|
>> BaseShake.jolt_scale.z
|
|
>> BaseShake.jolt_limit
|
|
>> BaseShake.angle_scale.x
|
|
>> BaseShake.angle_scale.z;
|
|
}
|
|
else if( token == "enginespring:" ) {
|
|
parser.getTokens( 5, false );
|
|
parser
|
|
>> EngineShake.scale
|
|
>> EngineShake.fadein_offset
|
|
>> EngineShake.fadein_factor
|
|
>> EngineShake.fadeout_offset
|
|
>> EngineShake.fadeout_factor;
|
|
// offsets values are provided as rpm for convenience
|
|
EngineShake.fadein_offset /= 60.f;
|
|
EngineShake.fadeout_offset /= 60.f;
|
|
}
|
|
else if( token == "huntingspring:" ) {
|
|
parser.getTokens( 4, false );
|
|
parser
|
|
>> HuntingShake.scale
|
|
>> HuntingShake.frequency
|
|
>> HuntingShake.fadein_begin
|
|
>> HuntingShake.fadein_end;
|
|
}
|
|
|
|
else if( token == "soundproofing:" ) {
|
|
for( auto &soundproofingtable : m_soundproofing ) {
|
|
for( auto &soundproofingelement : soundproofingtable ) {
|
|
auto const value { parser.getToken<float>( false ) };
|
|
if( value != -1.f ) {
|
|
soundproofingelement = std::sqrt( std::clamp( value, 0.f, 1.f ) );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
else if( token == "jointcabs:" ) {
|
|
parser.getTokens();
|
|
parser >> JointCabs;
|
|
}
|
|
|
|
else if( token == "cablight:" ) {
|
|
parser.getTokens( 3, false ); // low power light, ignore
|
|
parser.getTokens( 3, false ); // base light
|
|
parser
|
|
>> InteriorLight.r
|
|
>> InteriorLight.g
|
|
>> InteriorLight.b;
|
|
InteriorLight = glm::clamp( InteriorLight / 255.f, glm::vec3( 0.f ), glm::vec3( 1.f ) );
|
|
parser.getTokens( 3, false ); // dimmed light, ignore
|
|
}
|
|
|
|
else if( token == "pydestinationsign:" ) {
|
|
DestinationSign.deserialize( parser );
|
|
// supply vehicle folder as script path if none is provided
|
|
if( false == DestinationSign.script.empty()
|
|
&& substr_path(DestinationSign.script).empty() ) {
|
|
DestinationSign.script = asBaseDir + DestinationSign.script;
|
|
}
|
|
}
|
|
else if( token == "luadestinationsign:" ) {
|
|
deserialize_script_sign( parser, DestinationSign.lua, asBaseDir );
|
|
}
|
|
else if( token == "wasmdestinationsign:" ) {
|
|
deserialize_script_sign( parser, DestinationSign.wasm, asBaseDir );
|
|
}
|
|
// NOTE: legacy key, now expected as optional "background:" parameter in pydestinationsign: { parameter block }
|
|
else if( token == "destinationsignbackground:" ) {
|
|
parser.getTokens();
|
|
parser >> DestinationSign.background;
|
|
}
|
|
|
|
} while( token != "" );
|
|
|
|
} // internaldata:
|
|
|
|
} while( token != "" );
|
|
|
|
if( !iAnimations ) {
|
|
// if the animations weren't defined the model is likely to be non-functional. warrants a warning.
|
|
ErrorLog( "Animations tag is missing from the .mmd file \"" + asFileName + "\"" );
|
|
}
|
|
|
|
if( ReplacableSkin != "none" ) {
|
|
// potentially set blank destination texture
|
|
auto language { script_language::lua };
|
|
auto const *scriptsign { script_destination( language ) };
|
|
auto const &background { ( scriptsign != nullptr && false == scriptsign->background.empty() ) ? scriptsign->background : DestinationSign.background };
|
|
DestinationSign.destination_off = DestinationFind( background.empty() ? "nowhere" : background );
|
|
// a blank sign a script draws, drawn once
|
|
DestinationSign.background_sign = draw_script_texture( background, DestinationSign.destination_off );
|
|
}
|
|
|
|
// assign default samples to sound emitters which weren't included in the config file
|
|
if( TestFlag( MoverParameters->CategoryFlag, 1 ) ) {
|
|
// rail vehicles:
|
|
// engine
|
|
if( MoverParameters->Power > 0 ) {
|
|
if( true == m_powertrainsounds.dsbWejscie_na_bezoporow.empty() ) {
|
|
// hunter-111211: domyslne, gdy brak
|
|
m_powertrainsounds.dsbWejscie_na_bezoporow.deserialize( "wejscie_na_bezoporow", sound_type::single );
|
|
m_powertrainsounds.dsbWejscie_na_bezoporow.owner( this );
|
|
}
|
|
if( true == m_powertrainsounds.motor_parallel.empty() ) {
|
|
m_powertrainsounds.motor_parallel.deserialize( "wescie_na_drugi_uklad", sound_type::single );
|
|
m_powertrainsounds.motor_parallel.owner( this );
|
|
}
|
|
}
|
|
// braking sounds
|
|
if( true == rsUnbrake.empty() ) {
|
|
rsUnbrake.deserialize( "[1007]estluz", sound_type::single );
|
|
rsUnbrake.owner( this );
|
|
}
|
|
// couplers
|
|
for( auto &couplersounds : m_couplersounds ) {
|
|
if( true == couplersounds.attach_coupler.empty() ) {
|
|
couplersounds.attach_coupler.deserialize( "couplerattach_default", sound_type::single );
|
|
couplersounds.attach_coupler.owner( this );
|
|
}
|
|
if( true == couplersounds.detach_coupler.empty() ) {
|
|
couplersounds.detach_coupler.deserialize( "couplerdetach_default", sound_type::single );
|
|
couplersounds.detach_coupler.owner( this );
|
|
}
|
|
if( true == couplersounds.dsbCouplerStretch.empty() ) {
|
|
couplersounds.dsbCouplerStretch.deserialize( "couplerstretch_default", sound_type::single );
|
|
couplersounds.dsbCouplerStretch.owner( this );
|
|
}
|
|
if( true == couplersounds.dsbBufferClamp.empty() ) {
|
|
couplersounds.dsbBufferClamp.deserialize( "bufferclamp_default", sound_type::single );
|
|
couplersounds.dsbBufferClamp.owner( this );
|
|
}
|
|
}
|
|
// other sounds
|
|
if( true == m_wheelflat.empty() ) {
|
|
m_wheelflat.deserialize( "lomotpodkucia 0.23 0.0", sound_type::single, sound_parameters::frequency );
|
|
m_wheelflat.owner( this );
|
|
}
|
|
if( true == rscurve.empty() ) {
|
|
// hunter-111211: domyslne, gdy brak
|
|
rscurve.deserialize( "curve", sound_type::single );
|
|
rscurve.owner( this );
|
|
}
|
|
}
|
|
|
|
if (mdModel)
|
|
mdModel->Init(); // obrócenie modelu oraz optymalizacja, również zapisanie binarnego
|
|
if (mdLoad)
|
|
mdLoad->Init();
|
|
if (mdLowPolyInt)
|
|
mdLowPolyInt->Init();
|
|
for( auto *attachment : mdAttachments ) {
|
|
attachment->Init();
|
|
}
|
|
|
|
Global.asCurrentTexturePath = paths::textures; // kiedyś uproszczone wnętrze mieszało tekstury nieba
|
|
Global.asCurrentDynamicPath = "";
|
|
|
|
// position sound emitters which weren't defined in the config file
|
|
// engine sounds, centre of the vehicle
|
|
auto const enginelocation { glm::vec3 {0.f, MoverParameters->Dim.H * 0.5f, 0.f } };
|
|
m_powertrainsounds.position( enginelocation );
|
|
// other engine compartment sounds
|
|
auto const nullvector { glm::vec3() };
|
|
std::vector<sound_source *> enginesounds = {
|
|
&sConverter, &sBRVent, &sCompressor, &sCompressorIdle, &sSmallCompressor, &sHeater, &m_batterysound
|
|
};
|
|
for( auto sound : enginesounds ) {
|
|
if( sound->offset() == nullvector ) {
|
|
sound->offset( enginelocation );
|
|
}
|
|
}
|
|
|
|
// pantographs
|
|
if( pants != nullptr ) {
|
|
std::size_t pantographindex { 0 };
|
|
for( auto &pantographsounds : m_pantographsounds ) {
|
|
auto const pantographoffset {
|
|
glm::vec3(
|
|
0.f,
|
|
pants[ pantographindex ].fParamPants->vPos.y,
|
|
-pants[ pantographindex ].fParamPants->vPos.x ) };
|
|
pantographsounds.sPantUp.offset( pantographoffset );
|
|
pantographsounds.sPantDown.offset( pantographoffset );
|
|
++pantographindex;
|
|
}
|
|
}
|
|
// doors
|
|
std::size_t dooranimationfirstindex { 0 };
|
|
for( std::size_t i = 0; i < ANIM_DOORS; ++i ) {
|
|
// zliczanie wcześniejszych animacji
|
|
dooranimationfirstindex += iAnimType[ i ];
|
|
}
|
|
// couplers
|
|
auto const frontcoupleroffset { glm::vec3{ 0.f, 1.f, MoverParameters->Dim.L * 0.5f } };
|
|
m_couplersounds[ end::front ].attach_coupler.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].attach_brakehose.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].attach_mainhose.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].attach_control.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].attach_gangway.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].attach_heating.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].detach_coupler.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].detach_brakehose.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].detach_mainhose.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].detach_control.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].detach_gangway.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].detach_heating.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].dsbCouplerStretch.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].dsbCouplerStretch_loud.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].dsbBufferClamp.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].dsbBufferClamp_loud.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].dsbAdapterAttach.offset( frontcoupleroffset );
|
|
m_couplersounds[ end::front ].dsbAdapterRemove.offset( frontcoupleroffset );
|
|
auto const rearcoupleroffset { glm::vec3{ 0.f, 1.f, MoverParameters->Dim.L * -0.5f } };
|
|
m_couplersounds[ end::rear ].attach_coupler.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].attach_brakehose.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].attach_mainhose.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].attach_control.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].attach_gangway.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].attach_heating.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].detach_coupler.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].detach_brakehose.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].detach_mainhose.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].detach_control.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].detach_gangway.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].detach_heating.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].dsbCouplerStretch.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].dsbCouplerStretch_loud.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].dsbBufferClamp.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].dsbBufferClamp_loud.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].dsbAdapterAttach.offset( rearcoupleroffset );
|
|
m_couplersounds[ end::rear ].dsbAdapterRemove.offset( rearcoupleroffset );
|
|
}
|
|
|
|
TModel3d *
|
|
TDynamicObject::LoadMMediaFile_mdload( std::string const &Name ) const {
|
|
|
|
auto const loadname { ( Name.empty() ? "none" : Name ) };
|
|
TModel3d *loadmodel { nullptr };
|
|
|
|
// check if we don't have model override for this load type
|
|
if ( loadmodel == nullptr )
|
|
{
|
|
auto const lookup { LoadModelOverrides.find( loadname ) };
|
|
if( lookup != LoadModelOverrides.end() ) {
|
|
loadmodel = TModelsManager::GetModel( asBaseDir + lookup->second, true );
|
|
}
|
|
}
|
|
// regular routine if there's no override or it couldn't be loaded
|
|
// try first specialized version of the load model, vehiclename_loadname
|
|
if ( loadmodel == nullptr )
|
|
{
|
|
auto const specializedloadfilename { asBaseDir + MoverParameters->TypeName + "_" + loadname };
|
|
loadmodel = TModelsManager::GetModel( specializedloadfilename, true, false );
|
|
}
|
|
// try generic version of the load model next, loadname
|
|
if ( loadmodel == nullptr )
|
|
{
|
|
auto const genericloadfilename { asBaseDir + loadname };
|
|
loadmodel = TModelsManager::GetModel( genericloadfilename, true, false );
|
|
}
|
|
|
|
if ( loadmodel != nullptr )
|
|
loadmodel->GetSMRoot()->WillBeAnimated();
|
|
|
|
return loadmodel;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
void TDynamicObject::RadioStop()
|
|
{ // zatrzymanie pojazdu
|
|
if( Mechanik ) {
|
|
// o ile ktoś go prowadzi
|
|
if( MoverParameters->SecuritySystem.radiostop_available()
|
|
&& MoverParameters->Radio
|
|
&& MoverParameters->RadioFuse ) {
|
|
// jeśli pojazd ma RadioStop i jest on aktywny
|
|
// HACK cast until math types unification
|
|
glm::dvec3 pos = static_cast<glm::dvec3>(vPosition);
|
|
Mechanik->PutCommand( "Emergency_brake", 1.0, 1.0, &pos, stopRadio );
|
|
// add onscreen notification for human driver
|
|
// TODO: do it selectively for the 'local' driver once the multiplayer is in
|
|
if( false == Mechanik->AIControllFlag ) {
|
|
ui::Transcripts.AddLine( "!! RADIO-STOP !!", 0.0, 10.0, false );
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|
|
void TDynamicObject::Damage(char flag)
|
|
{
|
|
if (flag & 1) //różnicówka nie robi nic
|
|
{
|
|
MoverParameters->MainSwitch(false);
|
|
MoverParameters->FuseOff();
|
|
}
|
|
else
|
|
{
|
|
}
|
|
|
|
if (flag & 2) //usterka sterowania
|
|
{
|
|
MoverParameters->StLinFlag = false;
|
|
if (MoverParameters->InitialCtrlDelay<100000000)
|
|
MoverParameters->InitialCtrlDelay += 100000001;
|
|
}
|
|
else
|
|
{
|
|
if (MoverParameters->InitialCtrlDelay>100000000)
|
|
MoverParameters->InitialCtrlDelay -= 100000001;
|
|
}
|
|
|
|
if (flag & 4) //blokada przetwornicy
|
|
{
|
|
if( MoverParameters->ConverterStart != start_t::disabled ) {
|
|
MoverParameters->ConvOvldFlag = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
}
|
|
|
|
if (flag & 8) //blokada sprezarki
|
|
{
|
|
if (MoverParameters->MinCompressor>0)
|
|
MoverParameters->MinCompressor -= 100000001;
|
|
if (MoverParameters->MaxCompressor>0)
|
|
MoverParameters->MaxCompressor -= 100000001;
|
|
}
|
|
else
|
|
{
|
|
if (MoverParameters->MinCompressor<0)
|
|
MoverParameters->MinCompressor += 100000001;
|
|
if (MoverParameters->MaxCompressor<0)
|
|
MoverParameters->MaxCompressor += 100000001;
|
|
}
|
|
|
|
if (flag & 16) //blokada wału
|
|
{
|
|
if (MoverParameters->CtrlDelay<100000000)
|
|
MoverParameters->CtrlDelay += 100000001;
|
|
if (MoverParameters->CtrlDownDelay<100000000)
|
|
MoverParameters->CtrlDownDelay += 100000001;
|
|
}
|
|
else
|
|
{
|
|
if (MoverParameters->CtrlDelay>100000000)
|
|
MoverParameters->CtrlDelay -= 100000001;
|
|
if (MoverParameters->CtrlDownDelay>100000000)
|
|
MoverParameters->CtrlDownDelay -= 100000001;
|
|
}
|
|
|
|
if (flag & 32) //hamowanie nagŁe
|
|
{
|
|
}
|
|
else
|
|
{
|
|
}
|
|
|
|
MoverParameters->EngDmgFlag = flag;
|
|
};
|
|
|
|
void TDynamicObject::SetLights() {
|
|
auto const isfrontcaboccupied { MoverParameters->CabOccupied * DirectionGet() >= 0 };
|
|
int const automaticmarkers { MoverParameters->CabActive == 0 && MoverParameters->InactiveCabFlag & activation::redmarkers
|
|
? light::redmarker_left + light::redmarker_right : 0 };
|
|
auto const lightpos { MoverParameters->LightsPos - 1 };
|
|
std::array<int, 2> const cablights {
|
|
automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ end::front ][ lightpos ],
|
|
automaticmarkers > 0 ? automaticmarkers : MoverParameters->Lights[ end::rear ][ lightpos ] };
|
|
// the custom position keeps the lights lit at coupled ends as well
|
|
auto const ignorecouplings { MoverParameters->LightsPos == 18 };
|
|
auto *vehicle { GetFirstDynamic( MoverParameters->CabOccupied >= 0 ? end::front : end::rear, coupling::control ) };
|
|
while( vehicle != nullptr ) {
|
|
// set lights on given side if there's no coupling with another vehicle, turn them off otherwise
|
|
auto const iscoupled { [ vehicle, ignorecouplings ]( end const Side ) {
|
|
return false == ignorecouplings
|
|
&& ( vehicle->MoverParameters->Couplers[ Side ].CouplingFlag & coupling::coupler ) != 0
|
|
&& vehicle->MoverParameters->Neighbours[ Side ].vehicle != nullptr; } };
|
|
auto const lights { lights_programmer::vehicle_lights(
|
|
cablights, isfrontcaboccupied, vehicle->iDirection, { iscoupled( end::front ), iscoupled( end::rear ) } ) };
|
|
vehicle->RaLightsSet( lights.head, lights.rear );
|
|
vehicle = isfrontcaboccupied ? vehicle->Next(coupling::control) : vehicle->Prev(coupling::control);
|
|
}
|
|
};
|
|
|
|
void TDynamicObject::RaLightsSet(int head, int rear)
|
|
{ // zapalenie świateł z przodu i z
|
|
// tyłu, zależne od kierunku
|
|
// pojazdu
|
|
if (!MoverParameters)
|
|
return; // może tego nie być na początku
|
|
if (rear == ( light::redmarker_left | light::redmarker_right | light::rearendsignals ) )
|
|
{ // jeśli koniec pociągu, to trzeba ustalić, czy
|
|
// jest tam czynna lokomotywa
|
|
// EN57 może nie mieć końcówek od środka członu
|
|
if (MoverParameters->Power > 1.0) // jeśli ma moc napędową
|
|
if (!MoverParameters->DirActive) // jeśli nie ma ustawionego kierunku
|
|
{ // jeśli ma zarówno światła jak i końcówki, ustalić, czy jest w stanie aktywnym
|
|
// np. lokomotywa na zimno będzie mieć końcówki a nie światła
|
|
rear = light::rearendsignals; // tablice blaszane
|
|
// trzeba to uzależnić od "załączenia baterii" w pojeździe
|
|
}
|
|
if( rear == ( light::redmarker_left | light::redmarker_right | light::rearendsignals ) ) // jeśli nadal obydwie możliwości
|
|
if( iInventory[
|
|
( iDirection ?
|
|
end::rear :
|
|
end::front ) ] & ( light::redmarker_left | light::redmarker_right ) ) {
|
|
// czy ma jakieś światła czerowone od danej strony
|
|
rear = light::redmarker_left | light::redmarker_right; // dwa światła czerwone
|
|
}
|
|
else {
|
|
rear = light::rearendsignals; // tablice blaszane
|
|
}
|
|
}
|
|
// w zależności od kierunku pojazdu w składzie
|
|
if( head >= 0 ) {
|
|
auto const vehicleend { iDirection > 0 ? end::front : end::rear };
|
|
MoverParameters->iLights[ vehicleend ] = head & iInventory[vehicleend];
|
|
bool tLeft = MoverParameters->iLights[vehicleend] & (light::auxiliary_left | light::headlight_left); // roboczo czy jakiekolwiek swiatlo z lewej jest zapalone
|
|
bool tRight = MoverParameters->iLights[vehicleend] & (light::auxiliary_right | light::headlight_right); // a tu z prawej
|
|
if (Controller == Humandriver) {
|
|
|
|
auto const dps{MoverParameters->currentDimPosition()};
|
|
|
|
// domyślnie
|
|
HighBeamLights = false;
|
|
DimHeadlights = false;
|
|
|
|
// obsługa OFF
|
|
if (dps.isOff)
|
|
{
|
|
//MoverParameters->iLights[vehicleend] &= 0 | light::rearendsignals; // zostawiamy tylko tabliczki jesli sa
|
|
HighBeamLights = false;
|
|
DimHeadlights = false;
|
|
switch (MoverParameters->CabActive)
|
|
{
|
|
case end::front:
|
|
HeadlightsAoff = true;
|
|
break;
|
|
case end::rear:
|
|
HeadlightsBoff = true;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch (MoverParameters->CabActive)
|
|
{
|
|
case end::front:
|
|
HeadlightsAoff = false;
|
|
break;
|
|
case end::rear:
|
|
HeadlightsBoff = false;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// obsługa przyciemnionych
|
|
DimHeadlights = dps.isDimmed;
|
|
|
|
// obsługa długich
|
|
if (dps.isHighBeam)
|
|
{
|
|
HighBeamLights = true;
|
|
}
|
|
}
|
|
|
|
}
|
|
if( rear >= 0 ) {
|
|
auto const vehicleend{ iDirection > 0 ? end::rear : end::front };
|
|
MoverParameters->iLights[ vehicleend ] = rear & iInventory[vehicleend];
|
|
}
|
|
};
|
|
|
|
void TDynamicObject::SetLightDimmings()
|
|
{
|
|
auto const vehicleend{iDirection > 0 ? end::front : end::rear};
|
|
if (Controller == Humandriver)
|
|
{
|
|
|
|
auto const dps{MoverParameters->currentDimPosition()};
|
|
|
|
// domyślnie
|
|
HighBeamLights = false;
|
|
DimHeadlights = false;
|
|
|
|
// obsługa OFF
|
|
if (dps.isOff)
|
|
{
|
|
// MoverParameters->iLights[vehicleend] &= 0 | light::rearendsignals; // zostawiamy tylko tabliczki jesli sa
|
|
HighBeamLights = false;
|
|
DimHeadlights = false;
|
|
switch (vehicleend)
|
|
{
|
|
case end::front:
|
|
HeadlightsAoff = true;
|
|
break;
|
|
case end::rear:
|
|
HeadlightsBoff = true;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch (vehicleend)
|
|
{
|
|
case end::front:
|
|
HeadlightsAoff = false;
|
|
break;
|
|
case end::rear:
|
|
HeadlightsBoff = false;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// obsługa przyciemnionych
|
|
DimHeadlights = dps.isDimmed;
|
|
|
|
// obsługa długich
|
|
if (dps.isHighBeam)
|
|
{
|
|
// obsługa długich
|
|
if (dps.isHighBeam)
|
|
{
|
|
HighBeamLights = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool TDynamicObject::has_signal_pc1_on() const {
|
|
|
|
auto const vehicleend { iDirection > 0 ? end::front : end::rear };
|
|
auto const equippedlights { iInventory[ vehicleend ] };
|
|
auto const pattern { equippedlights & ( light::headlight_left | light::headlight_right | light::headlight_upper ) };
|
|
auto const patternfallback { equippedlights & ( light::auxiliary_left | light::auxiliary_right | light::headlight_upper ) };
|
|
auto const hasauxiliarylights { ( equippedlights & ( light::auxiliary_left | light::auxiliary_right ) ) != 0 };
|
|
auto const activelights { MoverParameters->iLights[ vehicleend ] };
|
|
|
|
return (pattern != 0 && activelights == pattern) || (hasauxiliarylights && activelights == patternfallback) ||
|
|
(pattern == 0 && patternfallback == 0 && activelights == light::rearendsignals); // pc4
|
|
}
|
|
|
|
bool TDynamicObject::has_signal_pc2_on() const {
|
|
|
|
auto const vehicleend { iDirection > 0 ? end::front : end::rear };
|
|
auto const equippedlights { iInventory[ vehicleend ] };
|
|
auto const pattern { equippedlights & ( light::redmarker_left | light::headlight_right | light::headlight_upper ) };
|
|
auto const patternfallback { equippedlights & ( light::redmarker_left | light::auxiliary_right | light::headlight_upper ) };
|
|
auto const hasauxiliarylights { ( equippedlights & ( light::auxiliary_left | light::auxiliary_right ) ) != 0 };
|
|
auto const activelights { MoverParameters->iLights[ vehicleend ] };
|
|
|
|
return activelights == pattern || (hasauxiliarylights && activelights == patternfallback);
|
|
}
|
|
|
|
bool TDynamicObject::has_signal_pc5_on() const {
|
|
|
|
auto const vehicleend { iDirection > 0 ? end::rear : end::front };
|
|
auto const equippedlights { iInventory[ vehicleend ] };
|
|
auto const pattern { equippedlights & ( light::redmarker_left | light::redmarker_right ) };
|
|
auto const patternfallback { equippedlights & light::rearendsignals };
|
|
auto const activelights { MoverParameters->iLights[ vehicleend ] };
|
|
|
|
return (pattern != 0 && activelights == pattern) || (patternfallback != 0 && activelights == patternfallback);
|
|
}
|
|
|
|
bool TDynamicObject::has_signal_on( int const Side, int const Pattern ) const {
|
|
/*
|
|
auto const vehicleend { iDirection > 0 ? Side : 1 - Side };
|
|
auto const pattern { iInventory[ vehicleend ] & Pattern };
|
|
|
|
return ( MoverParameters->iLights[ vehicleend ] == pattern );
|
|
*/
|
|
return MoverParameters->iLights[Side] == (Pattern & iInventory[Side]);
|
|
}
|
|
|
|
int TDynamicObject::DirectionSet(int d)
|
|
{ // ustawienie kierunku w składzie (wykonuje AI)
|
|
auto const lastdirection { iDirection };
|
|
iDirection = d > 0 ? 1 : 0; // d:1=zgodny,-1=przeciwny; iDirection:1=zgodny,0=przeciwny;
|
|
|
|
if( iDirection != lastdirection ) {
|
|
// direction was flipped, switch recorded servicable platform sides for potentially ongoing load exchange
|
|
auto const left { lastdirection > 0 ? 1 : 2 };
|
|
auto const right { 3 - left };
|
|
m_exchange.platforms =
|
|
( ( m_exchange.platforms & left ) != 0 ? right : 0 )
|
|
+ ( ( m_exchange.platforms & right ) != 0 ? left : 0 );
|
|
}
|
|
|
|
if (MyTrack)
|
|
{ // podczas wczytywania wstawiane jest AI, ale może jeszcze nie być toru
|
|
// AI ustawi kierunek ponownie po uruchomieniu silnika
|
|
update_neighbours();
|
|
}
|
|
// informacja o położeniu następnego
|
|
return 1 - ( iDirection > 0 ? NextConnectedNo() : PrevConnectedNo() );
|
|
};
|
|
|
|
// wskaźnik na poprzedni, nawet wirtualny
|
|
TDynamicObject * TDynamicObject::PrevAny() const {
|
|
return MoverParameters->Neighbours[ iDirection ^ 1 ].vehicle;
|
|
}
|
|
TDynamicObject * TDynamicObject::Prev(int C) const {
|
|
return MoverParameters->Couplers[iDirection ^ 1].CouplingFlag & C ? MoverParameters->Neighbours[iDirection ^ 1].vehicle : nullptr;// gdy sprzęg wirtualny, to jakby nic nie było
|
|
}
|
|
TDynamicObject * TDynamicObject::Next(int C) const {
|
|
return MoverParameters->Couplers[iDirection].CouplingFlag & C ? MoverParameters->Neighbours[iDirection].vehicle : nullptr;// gdy sprzęg wirtualny, to jakby nic nie było
|
|
}
|
|
|
|
// checks whether there's unbroken connection of specified type to specified vehicle
|
|
bool
|
|
TDynamicObject::is_connected( TDynamicObject const *Vehicle, coupling const Coupling ) const {
|
|
|
|
auto *vehicle { this };
|
|
if( vehicle == Vehicle ) {
|
|
// edge case, vehicle is always "connected" with itself
|
|
return true;
|
|
}
|
|
// check ahead, it's more likely the "owner" using this method is located there
|
|
while( ( vehicle = vehicle->Prev( Coupling ) ) != nullptr ) {
|
|
if( vehicle == Vehicle ) {
|
|
return true;
|
|
}
|
|
if( vehicle == this ) {
|
|
// edge case, looping consist
|
|
return false;
|
|
}
|
|
}
|
|
// start anew in the other direction
|
|
vehicle = this;
|
|
while( ( vehicle = vehicle->Next( Coupling ) ) != nullptr ) {
|
|
if( vehicle == Vehicle ) {
|
|
return true;
|
|
}
|
|
}
|
|
// no luck in either direction, give up
|
|
return false;
|
|
}
|
|
|
|
// ustalenie następnego (1) albo poprzedniego (0) w składzie bez względu na prawidłowość iDirection
|
|
TDynamicObject *
|
|
TDynamicObject::Neighbour(int &dir) {
|
|
|
|
auto *neighbour { (
|
|
MoverParameters->Couplers[ dir ].CouplingFlag != coupling::faux ?
|
|
MoverParameters->Neighbours[ dir ].vehicle :
|
|
nullptr ) };
|
|
// nowa wartość
|
|
dir = 1 - MoverParameters->Neighbours[ dir ].vehicle_end;
|
|
|
|
return neighbour;
|
|
};
|
|
|
|
// updates potential collision sources
|
|
void
|
|
TDynamicObject::update_neighbours() {
|
|
|
|
for( int end = end::front; end <= end::rear; ++end ) {
|
|
|
|
auto &neighbour { MoverParameters->Neighbours[ end ] };
|
|
auto const &coupler { MoverParameters->Couplers[ end ] };
|
|
|
|
if( coupler.Connected != nullptr
|
|
&& neighbour.vehicle != nullptr ) {
|
|
// physical connection with another vehicle locks down collision source on this end
|
|
// neighbour.vehicle = coupler.Connected;
|
|
// neighbour.vehicle_end = coupler.ConnectedNr;
|
|
neighbour.distance = TMoverParameters::CouplerDist( MoverParameters, coupler.Connected );
|
|
// take into account potential adapters attached to the couplers
|
|
auto const &othercoupler { neighbour.vehicle->MoverParameters->Couplers[ neighbour.vehicle_end ] };
|
|
neighbour.distance -= coupler.adapter_length;
|
|
neighbour.distance -= othercoupler.adapter_length;
|
|
}
|
|
else {
|
|
// if there's no connected vehicle check for potential collision sources in the vicinity
|
|
// NOTE: we perform a new scan on each update to ensure we always locate the nearest potential source
|
|
neighbour = neighbour_data();
|
|
// 10m ~= 140 km/h at 4 fps + safety margin, potential distance between outer axles of involved vehicles
|
|
auto const scanrange { std::max( 10.0, std::abs( MoverParameters->V ) ) + 40.0 };
|
|
auto const lookup { find_vehicle( end, scanrange ) };
|
|
|
|
if( false == std::get<bool>( lookup ) ) { continue; }
|
|
|
|
neighbour.vehicle = std::get<TDynamicObject *>( lookup );
|
|
neighbour.vehicle_end = std::get<int>( lookup );
|
|
neighbour.distance = std::get<double>( lookup );
|
|
|
|
if( neighbour.vehicle
|
|
&& neighbour.distance < (neighbour.vehicle->MoverParameters->CategoryFlag == 2 ? 50 : 100) ) {
|
|
// at short distances (re)calculate range between couplers directly
|
|
neighbour.distance = TMoverParameters::CouplerDist( MoverParameters, neighbour.vehicle->MoverParameters );
|
|
// take into account potential adapters attached to the couplers
|
|
auto const &othercoupler { neighbour.vehicle->MoverParameters->Couplers[ neighbour.vehicle_end ] };
|
|
neighbour.distance -= coupler.adapter_length;
|
|
neighbour.distance -= othercoupler.adapter_length;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// locates potential collision source within specified range, scanning track in specified direction. returns: true if neighbour was located, false otherwise
|
|
// NOTE: reuses legacy code. TBD, TODO: review, refactor?
|
|
std::tuple<TDynamicObject *, int, double, bool>
|
|
TDynamicObject::find_vehicle( int const Direction, double const Distance ) const {
|
|
|
|
auto direction { ( Direction == end::front ? 1 : -1 ) };
|
|
auto const initialdirection { direction }; // zapamiętanie kierunku poszukiwań na torze początkowym, względem sprzęgów
|
|
|
|
auto const *track { RaTrackGet() };
|
|
if( RaDirectionGet() < 0 ) {
|
|
// czy oś jest ustawiona w stronę Point1?
|
|
direction = -direction;
|
|
}
|
|
|
|
// (teraz względem toru)
|
|
auto const mycoupler { ( initialdirection < 0 ? end::rear : end::front ) }; // numer sprzęgu do podłączenia w obiekcie szukajacym
|
|
auto foundcoupler { -1 }; // numer sprzęgu w znalezionym obiekcie (znaleziony wypełni)
|
|
auto distance { 0.0 }; // przeskanowana odleglość; odległość do zawalidrogi
|
|
auto *foundobject { ABuFindObject( foundcoupler, distance, track, direction, mycoupler ) }; // zaczynamy szukać na tym samym torze
|
|
|
|
if( foundobject == nullptr ) {
|
|
// jeśli nie ma na tym samym, szukamy po okolicy szukanie najblizszego toru z jakims obiektem
|
|
// praktycznie przeklejone z TraceRoute()...
|
|
if (direction >= 0) // uwzględniamy kawalek przeanalizowanego wcześniej toru
|
|
distance = track->Length() - RaTranslationGet(); // odległość osi od Point2 toru
|
|
else
|
|
distance = RaTranslationGet(); // odległość osi od Point1 toru
|
|
|
|
while (distance < Distance) {
|
|
if (direction > 0) {
|
|
// w kierunku Point2 toru
|
|
if( track ?
|
|
track->iNextDirection :
|
|
false ) {
|
|
// jeśli następny tor jest podpięty od Point2
|
|
direction = -direction; // to zmieniamy kierunek szukania na tym torze
|
|
}
|
|
if( track ) {
|
|
track = track->CurrentNext(); // potem dopiero zmieniamy wskaźnik
|
|
}
|
|
}
|
|
else {
|
|
// w kierunku Point1
|
|
if( track ?
|
|
!track->iPrevDirection :
|
|
true ) {
|
|
// jeśli poprzedni tor nie jest podpięty od Point2
|
|
direction = -direction; // to zmieniamy kierunek szukania na tym torze
|
|
}
|
|
if( track ) {
|
|
track = track->CurrentPrev(); // potem dopiero zmieniamy wskaźnik
|
|
}
|
|
}
|
|
if (track) {
|
|
// jesli jest kolejny odcinek toru
|
|
foundobject = ABuFindObject(foundcoupler, distance, track, direction, mycoupler); // przejrzenie pojazdów tego toru
|
|
if (foundobject) {
|
|
break;
|
|
}
|
|
}
|
|
else {
|
|
// jeśli toru nie ma, to wychodzimy
|
|
distance = Distance + 1.0; // koniec przeglądania torów
|
|
break;
|
|
}
|
|
}
|
|
} // Koniec szukania najbliższego toru z jakimś obiektem.
|
|
|
|
if( foundobject == nullptr ) { return {}; }
|
|
/*
|
|
auto const *vehicle { MoverParameters };
|
|
auto const *foundvehicle { foundobject->MoverParameters };
|
|
if( ( false == TestFlag( track->iCategoryFlag, 1 ) )
|
|
&& ( distance > 50.0 ) ) {
|
|
// Ra: jeśli dwa samochody się mijają na odcinku przed zawrotką, to odległość między nimi nie może być liczona w linii prostej!
|
|
// NOTE: the distance is approximated, and additionally less accurate for cars heading in opposite direction
|
|
distance -= ( 0.5 * ( vehicle->Dim.L + foundvehicle->Dim.L ) );
|
|
}
|
|
else if( distance < 100.0 ) {
|
|
// at short distances start to calculate range between couplers directly
|
|
// odległość do najbliższego pojazdu w linii prostej
|
|
distance = TMoverParameters::CouplerDist( vehicle, foundvehicle );
|
|
}
|
|
*/
|
|
return { foundobject, foundcoupler, distance, true };
|
|
}
|
|
|
|
TDynamicObject * TDynamicObject::FindPowered()
|
|
{ // 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
|
|
// lepiej by było przesyłać komendy sterowania, co jednak wymaga przebudowy transmisji komend (LD)
|
|
// problem się robi ze światłami, które będą zapalane w silnikowym, ale muszą świecić się w rozrządczych
|
|
// dla EZT światłą 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...
|
|
auto const coupling { MoverParameters->TrainType == dt_EZT || MoverParameters->TrainType == dt_DMU ?
|
|
coupling::permanent :
|
|
coupling::control };
|
|
|
|
auto *lookup {
|
|
find_vehicle(
|
|
coupling,
|
|
[]( TDynamicObject * vehicle ) {
|
|
return vehicle->MoverParameters->Power > 1.0; } ) };
|
|
|
|
return lookup != nullptr ? lookup : this; // always return valid vehicle for backward compatibility
|
|
}
|
|
|
|
TDynamicObject *
|
|
TDynamicObject::FindPantographCarrier() {
|
|
|
|
// try first within a single unit, broaden to all vehicles under our control if first attempt fails
|
|
std::array<coupling, 2> const couplings = { coupling::permanent, coupling::control };
|
|
|
|
for( auto const coupling : couplings ) {
|
|
auto *result =
|
|
find_vehicle(
|
|
coupling,
|
|
[]( TDynamicObject * vehicle ) {
|
|
return vehicle->MoverParameters->EnginePowerSource.SourceType == TPowerSource::CurrentCollector && vehicle->MoverParameters->EnginePowerSource.CollectorParameters.CollectorsNo > 0; } );
|
|
if( result != nullptr ) {
|
|
return result;
|
|
}
|
|
}
|
|
// if we're still here, admit failure
|
|
return nullptr;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
void TDynamicObject::ParamSet(int what, int into)
|
|
{ // ustawienie lokalnego parametru (what) na stan (into)
|
|
switch (what & 0xFF00)
|
|
{
|
|
case 0x0100: // to np. są drzwi, bity 0..7 określają numer 1..254 albo maskę
|
|
// dla 8 różnych
|
|
if (what & 1) // na razie mamy lewe oraz prawe, czyli używamy maskę 1=lewe,
|
|
// 2=prawe, 3=wszystkie
|
|
if( MoverParameters->Doors.instances[side::left].is_open )
|
|
{ // są otwarte
|
|
if (!into) // jeśli zamykanie
|
|
{
|
|
// dźwięk zamykania
|
|
}
|
|
}
|
|
else
|
|
{ // są zamknięte
|
|
if (into) // jeśli otwieranie
|
|
{
|
|
// dźwięk otwierania
|
|
}
|
|
}
|
|
if (what & 2) // prawe działają niezależnie od lewych
|
|
if( MoverParameters->Doors.instances[side::right].is_open )
|
|
{ // są otwarte
|
|
if (!into) // jeśli zamykanie
|
|
{
|
|
// dźwięk zamykania
|
|
}
|
|
}
|
|
else
|
|
{ // są zamknięte
|
|
if (into) // jeśli otwieranie
|
|
{
|
|
// dźwięk otwierania
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
};
|
|
|
|
int TDynamicObject::RouteWish(TTrack *tr)
|
|
{ // zapytanie do AI, po którym
|
|
// segmencie (-6..6) jechać na
|
|
// skrzyżowaniu (tr)
|
|
return Mechanik ? Mechanik->CrossRoute(tr) : 0; // wg AI albo prosto
|
|
};
|
|
|
|
void TDynamicObject::play_mirror_sounds( side const Side, mirror_moves::event const Event ) {
|
|
|
|
if( Event == mirror_moves::event::none ) { return; }
|
|
// as UpdateMirror(), only the mirrors of the occupied cab move
|
|
if( MoverParameters->CabOccupied == 0 ) { return; }
|
|
auto const cabend { MoverParameters->CabOccupied > 0 ? end::front : end::rear };
|
|
for( auto &mirror : m_mirrorsounds ) {
|
|
if( mirror.placement != Side || mirror.end != cabend ) { continue; }
|
|
auto &sound { Event == mirror_moves::event::unfolding ? mirror.unfold : mirror.fold };
|
|
auto &other { Event == mirror_moves::event::unfolding ? mirror.fold : mirror.unfold };
|
|
other.stop();
|
|
sound.play( sound_flags::exclusive );
|
|
}
|
|
}
|
|
|
|
void TDynamicObject::DestinationClear() {
|
|
|
|
if( false == DestinationSign.has_light ) { return; } // physical destination signs remain up until manually changed
|
|
// update_destinations() shows the blank sign in place of the missing destination
|
|
DestinationSign.destination = null_handle;
|
|
DestinationSign.script_sign.reset();
|
|
}
|
|
|
|
void TDynamicObject::DestinationSet(std::string const &to, std::string const &numer) {
|
|
// ustawienie stacji docelowej oraz wymiennej tekstury 4, jeśli istnieje plik
|
|
// w zasadzie, to każdy wagon mógłby mieć inną stację docelową
|
|
// zwłaszcza w towarowych, pod kątem zautomatyzowania maewrów albo pracy górki
|
|
// ale to jeszcze potrwa, zanim będzie możliwe, na razie można wpisać stację z
|
|
// rozkładu
|
|
|
|
asDestination = to;
|
|
|
|
if( std::abs( m_materialdata.multi_textures ) >= 4 ) { return; } // jak są 4 tekstury wymienne, to nie zmieniać rozkładem
|
|
if( DestinationSign.sign == nullptr ) { return; } // no sign submodel, no problem
|
|
// a sign drawn for the previous destination
|
|
DestinationSign.script_sign.reset();
|
|
|
|
// now see if we can find any version of the destination texture
|
|
std::vector<std::string> const destinations = {
|
|
numer, // try dedicated timetable sign first...
|
|
to }; // ...then generic destination sign
|
|
|
|
for( auto const &destination : destinations ) {
|
|
|
|
DestinationSign.destination = DestinationFind( destination );
|
|
if( DestinationSign.destination != null_handle ) {
|
|
// got what we wanted, we're done here
|
|
return;
|
|
}
|
|
}
|
|
// if we didn't get static texture we might be able to make one
|
|
if( true == destination_set_script( numer ) ) { return; }
|
|
if( DestinationSign.script.empty() ) { return; } // no script so no way to make the texture
|
|
if( numer == "none" ) { return; } // blank or incomplete/malformed timetable, don't bother
|
|
|
|
DestinationSign.destination = GfxRenderer->Fetch_Material( destination_request( DestinationSign.script, DestinationSign.instancing, DestinationSign.parameters ) );
|
|
}
|
|
|
|
std::string TDynamicObject::destination_request( std::string const &Script, std::string const &Instancing, std::string const &Parameters ) const {
|
|
|
|
auto const trainname { [this]() -> std::string {
|
|
if( ctOwner != nullptr ) { return ctOwner->TrainName(); }
|
|
if( Mechanik != nullptr ) { return Mechanik->TrainName(); }
|
|
return "none"; } }; // shouldn't get here but, eh
|
|
auto const instance { [this, &Instancing]() -> std::string {
|
|
if( Instancing == "name" ) { return MoverParameters->Name; }
|
|
if( Instancing == "type" ) { return MoverParameters->TypeName; }
|
|
return "none"; } };
|
|
|
|
std::string signrequest {
|
|
"make:"
|
|
+ Script
|
|
+ "?"
|
|
// timetable include
|
|
+ "$timetable=" + (
|
|
ctOwner == nullptr ?
|
|
MoverParameters->Name : // leading vehicle, can point to it directly
|
|
ctOwner->Vehicle()->MoverParameters->Name ) // owned vehicle, safer to point to owner as carriages can have identical names
|
|
// basic instancing string
|
|
// NOTE: underscore doesn't have any magic meaning for the time being, it's just less likely to conflict with regular dictionary keys
|
|
+ "&_id1=" + trainname() };
|
|
// TBD, TODO: replace instancing with support for variables in extra parameters string?
|
|
if( false == Instancing.empty() ) {
|
|
signrequest += "&_id2=" + instance();
|
|
}
|
|
// optionl extra parameters
|
|
if( false == Parameters.empty() ) {
|
|
signrequest += "&" + Parameters;
|
|
}
|
|
return signrequest;
|
|
}
|
|
|
|
script_screens::screen_config const *TDynamicObject::script_destination( script_language &Language ) const {
|
|
|
|
auto const &screens { Application.screens() };
|
|
if( false == DestinationSign.lua.script.empty() && screens.runs( script_language::lua ) ) {
|
|
Language = script_language::lua;
|
|
return &DestinationSign.lua;
|
|
}
|
|
if( false == DestinationSign.wasm.script.empty() && screens.runs( script_language::wasm ) ) {
|
|
Language = script_language::wasm;
|
|
return &DestinationSign.wasm;
|
|
}
|
|
return nullptr; // no script sign, maybe a python one
|
|
}
|
|
|
|
bool TDynamicObject::destination_set_script( std::string const &Numer ) {
|
|
|
|
if( Numer == "none" ) { return false; } // blank or incomplete/malformed timetable, don't bother
|
|
auto language { script_language::lua };
|
|
auto const *scriptsign { script_destination( language ) };
|
|
if( scriptsign == nullptr ) { return false; }
|
|
|
|
auto const signrequest { destination_request( scriptsign->script, scriptsign->instancing, scriptsign->parameters ) };
|
|
auto const signmaterial { GfxRenderer->Fetch_Material( signrequest ) };
|
|
if( signmaterial == null_handle ) { return false; }
|
|
auto &signtexture { GfxRenderer->Texture( GfxRenderer->Material( signmaterial )->GetTexture( 0 ) ) };
|
|
|
|
// vehicles showing the same request (one train, one instance) share the screen, as they share the texture
|
|
auto sign { Application.screens().acquire( {
|
|
.kind = script_screen_kind::external,
|
|
.language = language,
|
|
.script = scriptsign->script,
|
|
.key = signrequest,
|
|
.texture = &signtexture,
|
|
.frames = scriptsign->frames } ) };
|
|
if( sign == nullptr ) { return false; }
|
|
|
|
DestinationSign.destination = signmaterial;
|
|
DestinationSign.script_sign = std::move( sign );
|
|
DestinationSign.script_request = signrequest.substr( signrequest.find( '?' ) + 1 );
|
|
return true;
|
|
}
|
|
|
|
std::shared_ptr<script_screen> TDynamicObject::draw_script_texture( std::string const &Name, material_handle const Material ) {
|
|
|
|
if( false == Name.starts_with( "make:" ) || Material == null_handle ) { return nullptr; }
|
|
auto const query { Name.find( '?' ) };
|
|
auto const script { Name.substr( 5, query == std::string::npos ? std::string::npos : query - 5 ) };
|
|
auto const language { script_language_of( script ) };
|
|
if( false == language.has_value() ) { return nullptr; } // a python texture, made by the texture itself
|
|
|
|
auto &queue { Application.screens() };
|
|
auto &texture { GfxRenderer->Texture( GfxRenderer->Material( Material )->GetTexture( 0 ) ) };
|
|
auto screen { queue.acquire( {
|
|
.kind = script_screen_kind::external,
|
|
.language = *language,
|
|
.script = script,
|
|
.key = Name,
|
|
.texture = &texture,
|
|
.frames = 0 } ) };
|
|
if( screen == nullptr ) { return nullptr; }
|
|
queue.submit(
|
|
screen,
|
|
query == std::string::npos ?
|
|
std::make_shared<dictionary_source>() :
|
|
std::make_shared<dictionary_source>( Name.substr( query + 1 ) ),
|
|
0 );
|
|
return screen;
|
|
}
|
|
|
|
material_handle TDynamicObject::DestinationFind( std::string Destination ) {
|
|
|
|
if( Destination.empty() ) { return null_handle; }
|
|
|
|
// destination textures are kept in the vehicle's directory so we point the current texture path there
|
|
auto const currenttexturepath { Global.asCurrentTexturePath };
|
|
Global.asCurrentTexturePath = asBaseDir;
|
|
|
|
auto destinationhandle { null_handle };
|
|
|
|
if( Destination.starts_with("make:") ) {
|
|
// autogenerated texture
|
|
destinationhandle = GfxRenderer->Fetch_Material( Destination );
|
|
}
|
|
else {
|
|
// regular texture
|
|
Destination = Bezogonkow( Destination ); // do szukania pliku obcinamy ogonki
|
|
// now see if we can find any version of the texture
|
|
std::vector<std::string> const destinations {
|
|
Destination + '@' + MoverParameters->TypeName,
|
|
Destination };
|
|
|
|
for( auto const &destination : destinations ) {
|
|
auto material = TextureTest( ToLower( destination ) );
|
|
if( false == material.empty() ) {
|
|
destinationhandle = GfxRenderer->Fetch_Material( material );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
// whether we got anything, restore previous texture path
|
|
Global.asCurrentTexturePath = currenttexturepath;
|
|
|
|
return destinationhandle;
|
|
}
|
|
|
|
void TDynamicObject::announce( announcement_t const Announcement, bool const Chime ) {
|
|
|
|
if( m_doorspeakers.empty() ) { return; }
|
|
|
|
auto const *driver { (
|
|
ctOwner != nullptr ?
|
|
ctOwner :
|
|
Mechanik ) };
|
|
if( driver == nullptr ) { return; }
|
|
|
|
auto const &timetable { driver->TrainTimetable() };
|
|
auto const &announcements { m_pasystem.announcements };
|
|
auto playchime { Chime };
|
|
|
|
if( announcements[ static_cast<int>( Announcement ) ].empty() ) {
|
|
goto followup;
|
|
}
|
|
// if the announcement sound was defined queue playback
|
|
{
|
|
sound_source stopnamesound;
|
|
switch( Announcement ) {
|
|
case announcement_t::approaching:
|
|
case announcement_t::next: {
|
|
stopnamesound = timetable.next_stop_sound();
|
|
break;
|
|
}
|
|
case announcement_t::current: {
|
|
stopnamesound = timetable.current_stop_sound();
|
|
break;
|
|
}
|
|
case announcement_t::destination: {
|
|
stopnamesound = timetable.last_stop_sound();
|
|
break;
|
|
}
|
|
default: {
|
|
break;
|
|
}
|
|
}
|
|
if( stopnamesound.empty() ) {
|
|
goto followup;
|
|
}
|
|
// potentially precede the announcement with a chime...
|
|
if( true == playchime
|
|
&& false == announcements[static_cast<int>(announcement_t::chime)].empty() ) {
|
|
m_pasystem.announcement_queue.emplace_back( announcements[ static_cast<int>( announcement_t::chime ) ] );
|
|
playchime = false;
|
|
}
|
|
// ...then play the announcement itself
|
|
m_pasystem.announcement_queue.emplace_back( announcements[ static_cast<int>( Announcement ) ] );
|
|
m_pasystem.announcement_queue.emplace_back( stopnamesound );
|
|
}
|
|
followup:
|
|
// potentially follow up with another announcement
|
|
if( Announcement == announcement_t::next ) {
|
|
announce( announcement_t::destination, playchime );
|
|
}
|
|
}
|
|
|
|
void TDynamicObject::OverheadTrack(float o)
|
|
{ // ewentualne wymuszanie jazdy
|
|
// bezprądowej z powodu informacji
|
|
// w torze
|
|
if (ctOwner) // jeśli ma obiekt nadzorujący
|
|
{ // trzeba zaktualizować mapę flag bitowych jazdy bezprądowej
|
|
if (o < 0.0)
|
|
{ // normalna jazda po tym torze
|
|
ctOwner->iOverheadZero &= ~iOverheadMask; // zerowanie bitu - może pobierać prąd
|
|
ctOwner->iOverheadDown &= ~iOverheadMask; // zerowanie bitu - może podnieść pantograf
|
|
}
|
|
else if (o > 0.0)
|
|
{ // opuszczenie pantografów
|
|
ctOwner->iOverheadZero |= iOverheadMask; // ustawienie bitu - ma jechać bez pobierania prądu
|
|
ctOwner->iOverheadDown |= iOverheadMask; // ustawienie bitu - ma opuścić pantograf
|
|
}
|
|
else
|
|
{ // jazda bezprądowa z podniesionym pantografem
|
|
ctOwner->iOverheadZero |= iOverheadMask; // ustawienie bitu - ma jechać bez pobierania prądu
|
|
ctOwner->iOverheadDown &= ~iOverheadMask; // zerowanie bitu - może podnieść pantograf
|
|
}
|
|
}
|
|
};
|
|
|
|
void
|
|
TDynamicObject::update_shake( double const Timedelta ) {
|
|
// Ra: mechanik powinien być telepany niezależnie od pozycji pojazdu
|
|
// Ra: trzeba zrobić model bujania głową i wczepić go do pojazdu
|
|
|
|
// Ra: tu by się przydało uwzględnić rozkład sił:
|
|
// - na postoju horyzont prosto, kabina skosem
|
|
// - przy szybkiej jeździe kabina prosto, horyzont pochylony
|
|
|
|
// McZapkie: najpierw policzę pozycję w/m kabiny
|
|
|
|
// ABu: rzucamy kabina tylko przy duzym FPS!
|
|
// Mala histereza, zeby bez przerwy nie przelaczalo przy FPS~17
|
|
// Granice mozna ustalic doswiadczalnie. Ja proponuje 14:20
|
|
if( Global.iSlowMotion == 0 ) { // musi być pełna prędkość
|
|
|
|
glm::dvec3 shakevector;
|
|
if( MoverParameters->EngineType == TEngineType::DieselElectric
|
|
|| MoverParameters->EngineType == TEngineType::DieselEngine ) {
|
|
if( std::abs( MoverParameters->enrot ) > 0.0 ) {
|
|
// engine vibration
|
|
shakevector.x +=
|
|
std::sin(MoverParameters->eAngle * 4.0) * Timedelta *
|
|
EngineShake.scale
|
|
// fade in with rpm above threshold
|
|
* std::clamp(
|
|
( MoverParameters->enrot - EngineShake.fadein_offset ) * EngineShake.fadein_factor,
|
|
0.0, 1.0 )
|
|
// fade out with rpm above threshold
|
|
* std::lerp(
|
|
1.0, 0.0,
|
|
std::clamp(
|
|
( MoverParameters->enrot - EngineShake.fadeout_offset ) * EngineShake.fadeout_factor,
|
|
0.0, 1.0 ) );
|
|
}
|
|
}
|
|
|
|
if( HuntingShake.fadein_begin > 0.f
|
|
&& true == MoverParameters->TruckHunting ) {
|
|
// hunting oscillation
|
|
HuntingAngle = clamp_circular( HuntingAngle + 4.0 * HuntingShake.frequency * Timedelta * MoverParameters->Vel, 360.0 );
|
|
auto const huntingamount =
|
|
std::lerp(
|
|
0.0, 1.0,
|
|
std::clamp(
|
|
( MoverParameters->Vel - HuntingShake.fadein_begin ) / ( HuntingShake.fadein_end - HuntingShake.fadein_begin ),
|
|
0.0, 1.0 ) );
|
|
shakevector.x +=
|
|
std::sin(glm::radians(HuntingAngle)) * Timedelta * HuntingShake.scale
|
|
* huntingamount;
|
|
IsHunting = huntingamount > 0.025;
|
|
}
|
|
|
|
if (FreeFlyModeFlag)
|
|
shakevector *= 0;
|
|
|
|
auto const iVel { std::min( GetVelocity(), 150.0 ) };
|
|
// an uneven track shakes the cab by itself, in place of the sway drawn from the curve and the jolts drawn at random, as far as it does
|
|
auto const replaced { track_uneven::replaced_shake( MyTrack != nullptr ? MyTrack->uneven_underway() : track_uneven::amounts {} ) };
|
|
if( iVel > 0.5 ) {
|
|
// acceleration-driven base shake
|
|
shakevector += glm::dvec3(
|
|
replaced.sway ? 0.0 : -MoverParameters->AccN * Timedelta * 5.0 * Global.ShakingMultiplierRL, // highlight side sway
|
|
-MoverParameters->AccVert * Timedelta * Global.ShakingMultiplierUD,
|
|
-MoverParameters->AccSVBased * Timedelta * 1.5 * Global.ShakingMultiplierBF); // accent acceleration/deceleration
|
|
// unevenness of the track under the outer axles
|
|
auto const ride { 0.5 * ( Axle0.UnevenBend() + Axle1.UnevenBend() ) * ( MoverParameters->V * MoverParameters->V ) };
|
|
shakevector += glm::dvec3(
|
|
-glm::dot( ride, vLeft ) * Timedelta * 5.0 * Global.ShakingMultiplierRL,
|
|
-ride.y * Timedelta * Global.ShakingMultiplierUD,
|
|
0.0 );
|
|
}
|
|
|
|
auto shake { 1.25 * ShakeSpring.ComputateForces( shakevector, ShakeState.offset ) };
|
|
|
|
if( false == replaced.jolts && LocalRandom( iVel ) > 25.0 ) {
|
|
// extra shake at increased velocity
|
|
shake += ShakeSpring.ComputateForces(
|
|
glm::dvec3(
|
|
( LocalRandom( iVel * 2 ) - iVel ) / ( iVel * 2 * 4 ) * BaseShake.jolt_scale.x,
|
|
( LocalRandom( iVel * 2 ) - iVel ) / ( iVel * 2 * 4 ) * BaseShake.jolt_scale.y,
|
|
( LocalRandom( iVel * 2 ) - iVel ) / ( iVel * 2 * 4 ) * BaseShake.jolt_scale.z )
|
|
// * (( 200 - DynamicObject->MyTrack->iQualityFlag ) * 0.0075 ) // scale to 75-150% based on track quality
|
|
* 1.25,
|
|
ShakeState.offset );
|
|
}
|
|
shake *= 0.85;
|
|
|
|
ShakeState.velocity -= ( shake + ShakeState.velocity * 100.0 ) * (double)( BaseShake.jolt_scale.x + BaseShake.jolt_scale.y + BaseShake.jolt_scale.z ) / 200.0;
|
|
|
|
// McZapkie:
|
|
ShakeState.offset += ShakeState.velocity * Timedelta;
|
|
if( std::abs( ShakeState.offset.y ) > std::abs( BaseShake.jolt_limit ) ) {
|
|
ShakeState.velocity.y = -ShakeState.velocity.y;
|
|
}
|
|
}
|
|
else { // hamowanie rzucania przy spadku FPS
|
|
ShakeState.offset -= ShakeState.offset * std::min( Timedelta, 1.0 ); // po tym chyba potrafią zostać jakieś ułamki, które powodują zjazd
|
|
}
|
|
}
|
|
|
|
bool
|
|
TDynamicObject::axle_passed_joint( axle_sounds &Axle, double const Move, int const Direction ) const {
|
|
|
|
// from the follower on its side of the vehicle, as the two can be on different tracks. They stand fAxleDist apart, at the bogie pivots, and
|
|
// the offset of the axle is the place of its wheel set, so the two of a bogie come out half of ADist to either side of the pivot
|
|
auto const &follower { Axle.offset >= 0.0 ? Axle0 : Axle1 };
|
|
if( auto const railphase { follower.RailPhase( Axle.offset - std::copysign( 0.5 * fAxleDist, Axle.offset ) ) }; railphase >= 0.0 ) {
|
|
// the rails under the axle, which aren't always those under the track the vehicle is on
|
|
auto const passed { Axle.atjoints && std::abs( railphase - Axle.distance ) > 0.5 * follower.GetTrack()->fSoundDistance };
|
|
Axle.distance = railphase;
|
|
Axle.atjoints = true;
|
|
return passed;
|
|
}
|
|
Axle.atjoints = false;
|
|
Axle.distance += Move * Direction;
|
|
if( Axle.distance >= 0 && Axle.distance <= dRailLength ) {
|
|
return false;
|
|
}
|
|
Axle.distance = clamp_circular( Axle.distance, dRailLength );
|
|
return true;
|
|
}
|
|
|
|
std::pair<double, double>
|
|
TDynamicObject::shake_angles() const {
|
|
|
|
return {
|
|
std::atan( ShakeState.velocity.x * BaseShake.angle_scale.x ),
|
|
std::atan( ShakeState.velocity.z * BaseShake.angle_scale.z ) };
|
|
}
|
|
|
|
void
|
|
TDynamicObject::powertrain_sounds::position( glm::vec3 const Location ) {
|
|
|
|
auto const nullvector { glm::vec3() };
|
|
std::vector<sound_source *> enginesounds = {
|
|
&inverter,
|
|
&motor_relay, &dsbWejscie_na_bezoporow, &motor_parallel, &motor_shuntfield, &rsWentylator,
|
|
&engine, &engine_ignition, &engine_shutdown, &engine_revving, &engine_turbo, &oil_pump, &fuel_pump, &water_pump, &water_heater, &radiator_fan, &radiator_fan_aux,
|
|
&transmission, &rsEngageSlippery, &retarder
|
|
};
|
|
for( auto sound : enginesounds ) {
|
|
if( sound->offset() == nullvector ) {
|
|
sound->offset( Location );
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, double const Deltatime ) {
|
|
|
|
if( Vehicle.Power == 0 ) { return; }
|
|
|
|
double frequency { 1.0 };
|
|
double volume { 0.0 };
|
|
|
|
// oil pump
|
|
if( true == Vehicle.OilPump.is_active ) {
|
|
oil_pump
|
|
.pitch( oil_pump.m_frequencyoffset + oil_pump.m_frequencyfactor * 1.f )
|
|
.gain( oil_pump.m_amplitudeoffset + oil_pump.m_amplitudefactor * 1.f )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
oil_pump.stop();
|
|
}
|
|
// fuel pump
|
|
if( true == Vehicle.FuelPump.is_active ) {
|
|
fuel_pump
|
|
.pitch( fuel_pump.m_frequencyoffset + fuel_pump.m_frequencyfactor * 1.f )
|
|
.gain( fuel_pump.m_amplitudeoffset + fuel_pump.m_amplitudefactor * 1.f )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
fuel_pump.stop();
|
|
}
|
|
// water pump
|
|
if( true == Vehicle.WaterPump.is_active ) {
|
|
water_pump
|
|
.pitch( water_pump.m_frequencyoffset + water_pump.m_frequencyfactor * 1.f )
|
|
.gain( water_pump.m_amplitudeoffset + water_pump.m_amplitudefactor * 1.f )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
water_pump.stop();
|
|
}
|
|
// water heater
|
|
if( true == Vehicle.WaterHeater.is_active ) {
|
|
water_heater
|
|
.pitch( water_heater.m_frequencyoffset + water_heater.m_frequencyfactor * 1.f )
|
|
.gain( water_heater.m_amplitudeoffset + water_heater.m_amplitudefactor * 1.f )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
water_heater.stop();
|
|
}
|
|
// engine sounds
|
|
// ignition
|
|
if( engine_state_last != Vehicle.Mains ) {
|
|
|
|
if( true == Vehicle.Mains ) {
|
|
// TODO: separate engine and main circuit
|
|
// engine activation
|
|
engine_shutdown.stop();
|
|
engine_ignition
|
|
.pitch( engine_ignition.m_frequencyoffset + engine_ignition.m_frequencyfactor * 1.f )
|
|
.gain( engine_ignition.m_amplitudeoffset + engine_ignition.m_amplitudefactor * 1.f )
|
|
.play( sound_flags::exclusive );
|
|
// main circuit activation
|
|
linebreaker_close
|
|
.pitch( linebreaker_close.m_frequencyoffset + linebreaker_close.m_frequencyfactor * 1.f )
|
|
.gain( linebreaker_close.m_amplitudeoffset + linebreaker_close.m_amplitudefactor * 1.f )
|
|
.play();
|
|
}
|
|
else {
|
|
// engine deactivation
|
|
engine_ignition.stop();
|
|
engine_shutdown.pitch( engine_shutdown.m_frequencyoffset + engine_shutdown.m_frequencyfactor * 1.f )
|
|
.gain( engine_shutdown.m_amplitudeoffset + engine_shutdown.m_amplitudefactor * 1.f )
|
|
.play( sound_flags::exclusive );
|
|
// main circuit deactivation
|
|
linebreaker_open
|
|
.pitch( linebreaker_open.m_frequencyoffset + linebreaker_open.m_frequencyfactor * 1.f )
|
|
.gain( linebreaker_open.m_amplitudeoffset + linebreaker_open.m_amplitudefactor * 1.f )
|
|
.play();
|
|
}
|
|
engine_state_last = Vehicle.Mains;
|
|
}
|
|
// main engine sound
|
|
if( true == Vehicle.Mains ) {
|
|
|
|
if( std::abs(Vehicle.enrot) > 0.01
|
|
// McZapkie-280503: zeby dla dumb dzialal silnik na jalowych obrotach
|
|
|| Vehicle.EngineType == TEngineType::Dumb ) {
|
|
|
|
// frequency calculation
|
|
auto const normalizer { (
|
|
true == engine.is_combined() ?
|
|
// for combined engine sound we calculate sound point in rpm, to make .mmd files setup easier
|
|
// NOTE: we supply 1/100th of actual value, as the sound module converts does the opposite, converting received (typically) 0-1 values to 0-100 range
|
|
60.f * 0.01f :
|
|
// for legacy single-piece sounds the standard frequency calculation is left untouched
|
|
1.f ) };
|
|
frequency =
|
|
engine.m_frequencyoffset
|
|
+ engine.m_frequencyfactor * std::abs( Vehicle.enrot ) * normalizer;
|
|
|
|
if( Vehicle.EngineType == TEngineType::Dumb ) {
|
|
frequency -= 0.2 * Vehicle.EnginePower / ( 1 + Vehicle.Power * 1000 );
|
|
}
|
|
|
|
// base volume calculation
|
|
switch( Vehicle.EngineType ) {
|
|
// TODO: check calculated values
|
|
case TEngineType::DieselElectric: {
|
|
|
|
volume =
|
|
engine.m_amplitudeoffset
|
|
+ engine.m_amplitudefactor * (
|
|
0.25 * ( Vehicle.EnginePower / Vehicle.Power )
|
|
+ 0.75 * Vehicle.EngineRPMRatio() );
|
|
break;
|
|
}
|
|
case TEngineType::DieselEngine: {
|
|
if( Vehicle.enrot > 0.0 ) {
|
|
volume = Vehicle.EnginePower > 0 ? engine.m_amplitudeoffset + engine.m_amplitudefactor * Vehicle.dizel_fill :
|
|
engine.m_amplitudeoffset + engine.m_amplitudefactor * std::fabs(Vehicle.enrot / Vehicle.dizel_nmax);
|
|
}
|
|
break;
|
|
}
|
|
default: {
|
|
volume =
|
|
engine.m_amplitudeoffset
|
|
+ engine.m_amplitudefactor * ( Vehicle.EnginePower + std::fabs( Vehicle.enrot ) * 60.0 );
|
|
break;
|
|
}
|
|
}
|
|
|
|
if( engine_volume >= 0.05 ) {
|
|
|
|
auto enginerevvolume { 0.f };
|
|
if( Vehicle.EngineType == TEngineType::DieselElectric
|
|
|| Vehicle.EngineType == TEngineType::DieselEngine ) {
|
|
// diesel engine revolutions increase; it can potentially decrease volume of base engine sound
|
|
if( engine_revs_last != -1.f ) {
|
|
// calculate potential recent increase of engine revolutions
|
|
auto const revolutionsperminute { Vehicle.enrot * 60 };
|
|
auto const revolutionsdifference { revolutionsperminute - engine_revs_last };
|
|
auto const idlerevolutionsthreshold { 1.01 * Vehicle.EngineIdleRPM() };
|
|
engine_revs_change = std::max( 0.0, engine_revs_change - 2.5 * Deltatime );
|
|
if( revolutionsperminute > idlerevolutionsthreshold
|
|
&& revolutionsdifference > 1.0 * Deltatime ) {
|
|
engine_revs_change = std::clamp( engine_revs_change + 5.0 * Deltatime, 0.0, 1.25 );
|
|
}
|
|
enginerevvolume = 0.8 * engine_revs_change;
|
|
}
|
|
engine_revs_last = Vehicle.enrot * 60;
|
|
|
|
auto const enginerevfrequency { (
|
|
true == engine_revving.is_combined() ?
|
|
// if the sound contains multiple samples we reuse rpm-based calculation from the engine
|
|
frequency :
|
|
engine_revving.m_frequencyoffset + 1.f * engine_revving.m_frequencyfactor ) };
|
|
|
|
if( enginerevvolume > 0.02 ) {
|
|
engine_revving
|
|
.pitch( enginerevfrequency )
|
|
.gain( enginerevvolume )
|
|
.play( sound_flags::exclusive );
|
|
}
|
|
else {
|
|
engine_revving.stop();
|
|
}
|
|
} // diesel engines
|
|
|
|
// multi-part revving sound pieces replace base engine sound, single revving simply gets mixed with the base
|
|
auto const enginevolume { (
|
|
enginerevvolume > 0.02 && true == engine_revving.is_combined() ?
|
|
std::max( 0.0, engine_volume - enginerevvolume ) :
|
|
engine_volume ) };
|
|
engine
|
|
.pitch( frequency )
|
|
.gain( enginevolume )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
} // enginevolume > 0.05
|
|
}
|
|
else {
|
|
engine.stop();
|
|
}
|
|
}
|
|
|
|
if (Vehicle.Mains) {
|
|
float power = std::clamp(Vehicle.eimv_pr, 0.0, 1.0);
|
|
|
|
fake_engine
|
|
.pitch(fake_engine.m_frequencyoffset + power * fake_engine.m_frequencyfactor)
|
|
.gain(fake_engine.m_amplitudeoffset + power * fake_engine.m_amplitudefactor)
|
|
.play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else {
|
|
fake_engine.stop();
|
|
}
|
|
|
|
engine_volume = std::lerp( engine_volume, volume, 0.25 );
|
|
if( engine_volume < 0.05 ) {
|
|
engine.stop();
|
|
}
|
|
|
|
// youBy - przenioslem, bo diesel tez moze miec turbo
|
|
if( Vehicle.TurboTest > 0 ) {
|
|
// udawanie turbo:
|
|
auto const pitch_diesel{Vehicle.EngineType == TEngineType::DieselEngine || Vehicle.EngineType == TEngineType::DieselElectric ? Vehicle.enrot / Vehicle.dizel_nmax * Vehicle.dizel_fill : 1};
|
|
auto const goalpitch { std::max( 0.025, ( /*engine_volume **/ pitch_diesel + engine_turbo.m_frequencyoffset ) * engine_turbo.m_frequencyfactor ) };
|
|
auto const goalvolume { (
|
|
Vehicle.MainCtrlPos >= Vehicle.TurboTest && Vehicle.enrot > 0.1 ?
|
|
std::max( 0.0, ( engine_turbo_pitch + engine_turbo.m_amplitudeoffset ) * engine_turbo.m_amplitudefactor ) :
|
|
0.0 ) };
|
|
auto const currentvolume { engine_turbo.gain() };
|
|
auto const changerate { 0.4 * Deltatime };
|
|
|
|
engine_turbo_pitch = engine_turbo_pitch > goalpitch ? std::max(goalpitch, engine_turbo_pitch - changerate * 0.5) : std::min(goalpitch, engine_turbo_pitch + changerate);
|
|
|
|
volume = currentvolume > goalvolume ? std::max(goalvolume, currentvolume - changerate) : std::min(goalvolume, currentvolume + changerate);
|
|
|
|
engine_turbo
|
|
.pitch( 0.4 + engine_turbo_pitch * 0.4 )
|
|
.gain( volume );
|
|
|
|
if( volume > 0.05 ) {
|
|
engine_turbo.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
engine_turbo.stop();
|
|
}
|
|
}
|
|
|
|
if( Vehicle.dizel_engage > 0.1 ) {
|
|
if( std::abs( Vehicle.dizel_engagedeltaomega ) > 0.2 ) {
|
|
frequency = rsEngageSlippery.m_frequencyoffset + rsEngageSlippery.m_frequencyfactor * std::fabs( Vehicle.dizel_engagedeltaomega );
|
|
volume = rsEngageSlippery.m_amplitudeoffset + rsEngageSlippery.m_amplitudefactor * Vehicle.dizel_engage;
|
|
}
|
|
else {
|
|
frequency = 1.f; // rsEngageSlippery.FA+0.7*rsEngageSlippery.FM*(fabs(mvControlled->enrot)+mvControlled->nmax);
|
|
volume = Vehicle.dizel_engage > 0.2 ? rsEngageSlippery.m_amplitudeoffset + 0.2 * rsEngageSlippery.m_amplitudefactor * (Vehicle.enrot / Vehicle.nmax) : 0.f;
|
|
}
|
|
|
|
rsEngageSlippery
|
|
.pitch( frequency )
|
|
.gain( volume )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
rsEngageSlippery.stop();
|
|
}
|
|
|
|
if (Vehicle.hydro_R) {
|
|
float speed = std::abs(Vehicle.hydro_R_n);
|
|
|
|
retarder
|
|
.pitch(retarder.m_frequencyoffset + speed * retarder.m_frequencyfactor)
|
|
.gain(retarder.m_amplitudeoffset + Vehicle.hydro_R_Fill * retarder.m_amplitudefactor);
|
|
|
|
if (retarder.gain() > 0.01 && speed > 1 && Vehicle.hydro_R_ClutchActive) {
|
|
retarder.play(sound_flags::exclusive | sound_flags::looping);
|
|
}
|
|
else {
|
|
retarder.stop();
|
|
}
|
|
}
|
|
|
|
// motor sounds
|
|
volume = 0.0;
|
|
// generic traction motor sounds
|
|
if( false == motors.empty() ) {
|
|
|
|
if( std::abs( Vehicle.nrot ) > 0.01 ) {
|
|
|
|
auto const &motor { motors.front() };
|
|
// frequency calculation
|
|
auto normalizer { 1.f };
|
|
if( true == motor.is_combined() ) {
|
|
// for combined motor sound we calculate sound point in rpm, to make .mmd files setup easier
|
|
// NOTE: we supply 1/100th of actual value, as the sound module converts does the opposite, converting received (typically) 0-1 values to 0-100 range
|
|
normalizer = 60.f * 0.01f;
|
|
}
|
|
auto const motorrevolutions { std::abs( Vehicle.nrot ) * Vehicle.Transmision.Ratio };
|
|
frequency =
|
|
motor.m_frequencyoffset
|
|
+ motor.m_frequencyfactor * motorrevolutions * normalizer;
|
|
|
|
// base volume calculation
|
|
switch( Vehicle.EngineType ) {
|
|
case TEngineType::ElectricInductionMotor: {
|
|
volume =
|
|
motor.m_amplitudeoffset
|
|
+ motor.m_amplitudefactor * ( Vehicle.EnginePower + motorrevolutions * 2 );
|
|
break;
|
|
}
|
|
case TEngineType::ElectricSeriesMotor: {
|
|
volume =
|
|
motor.m_amplitudeoffset
|
|
+ motor.m_amplitudefactor * ( Vehicle.EnginePower + motorrevolutions * 60.0 );
|
|
break;
|
|
}
|
|
default: {
|
|
volume =
|
|
motor.m_amplitudeoffset
|
|
+ motor.m_amplitudefactor * motorrevolutions * 60.0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if( Vehicle.EngineType == TEngineType::ElectricSeriesMotor ) {
|
|
// volume variation
|
|
if( volume < 1.0
|
|
&& Vehicle.EnginePower < 100 ) {
|
|
|
|
auto const volumevariation { LocalRandom( 100 ) * Vehicle.enrot / ( 1 + Vehicle.nmax ) };
|
|
if( volumevariation < 2 ) {
|
|
volume += volumevariation / 200;
|
|
}
|
|
}
|
|
|
|
if( Vehicle.DynamicBrakeFlag
|
|
&& Vehicle.EnginePower > 0.1 ) {
|
|
// Szociu - 29012012 - jeżeli uruchomiony jest hamulec elektrodynamiczny, odtwarzany jest dźwięk silnika
|
|
volume += 0.8;
|
|
}
|
|
}
|
|
// scale motor volume based on whether they're active
|
|
motor_momentum =
|
|
std::clamp(
|
|
motor_momentum
|
|
- 1.0 * Deltatime // smooth out decay
|
|
+ std::abs( Vehicle.Mm ) / 60.0 * Deltatime,
|
|
0.0, 1.25 );
|
|
volume *= std::max( 0.25f, motor_momentum );
|
|
motor_volume = std::lerp( motor_volume, volume, 0.25 );
|
|
if( motor_volume >= 0.05 ) {
|
|
// apply calculated parameters to all motor instances
|
|
for( auto &motor : motors ) {
|
|
motor
|
|
.pitch( frequency )
|
|
.gain( motor_volume )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
}
|
|
else {
|
|
// stop all motor instances
|
|
for( auto &motor : motors ) {
|
|
motor.stop();
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
// stop all motor instances
|
|
motor_volume = 0.0;
|
|
for( auto &motor : motors ) {
|
|
motor.stop();
|
|
}
|
|
}
|
|
}
|
|
// inverter-specific traction motor sounds
|
|
if( false == acmotors.empty() ) {
|
|
|
|
if( Vehicle.EngineType == TEngineType::ElectricInductionMotor ) {
|
|
if( Vehicle.InverterFrequency > 0.001 ) {
|
|
|
|
for( auto &motor : acmotors ) {
|
|
motor
|
|
.pitch( motor.m_frequencyoffset + motor.m_frequencyfactor * Vehicle.InverterFrequency )
|
|
.gain( motor.m_amplitudeoffset + motor.m_amplitudefactor * std::sqrt( std::abs( Vehicle.eimv_pr ) ) )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
}
|
|
else {
|
|
for( auto &motor : acmotors ) {
|
|
motor.stop();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// motor blowers
|
|
if( false == motorblowers.empty() ) {
|
|
for( auto &blowersound : motorblowers ) {
|
|
// match the motor blower and the sound source based on whether they're located in the front or the back of the vehicle
|
|
auto const &blower { Vehicle.MotorBlowers[ ( blowersound.offset().z > 0 ? end::front : end::rear ) ] };
|
|
// TODO: for the sounds with provided bookends invoke stop() when the stop is triggered and revolutions start dropping, instead of after full stop
|
|
if( blower.revolutions > 1 ) {
|
|
// NOTE: for motorblowers with fixed speed if the sound has defined bookends we skip revolutions-based part of frequency/volume adjustments
|
|
auto const revolutionmodifier { Vehicle.MotorBlowers[end::front].speed < 0.f && blowersound.has_bookends() ? 1.f : blower.revolutions };
|
|
blowersound
|
|
.pitch(
|
|
true == blowersound.is_combined() ?
|
|
blower.revolutions * 0.01f :
|
|
blowersound.m_frequencyoffset + blowersound.m_frequencyfactor * revolutionmodifier )
|
|
.gain( blowersound.m_amplitudeoffset + blowersound.m_amplitudefactor * revolutionmodifier )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
blowersound.stop();
|
|
}
|
|
}
|
|
}
|
|
// inverter sounds
|
|
if( Vehicle.EngineType == TEngineType::ElectricInductionMotor ) {
|
|
if( Vehicle.InverterFrequency > 0.001 ) {
|
|
|
|
volume = inverter.m_amplitudeoffset + inverter.m_amplitudefactor * std::sqrt( std::abs( Vehicle.eimv_pr) );
|
|
|
|
inverter
|
|
.pitch( inverter.m_frequencyoffset + inverter.m_frequencyfactor * Vehicle.InverterFrequency )
|
|
.gain( volume )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
inverter.stop();
|
|
}
|
|
}
|
|
// ventillator sounds
|
|
if( Vehicle.RventRot > 0.1 ) {
|
|
|
|
rsWentylator
|
|
.pitch( rsWentylator.m_frequencyoffset + rsWentylator.m_frequencyfactor * Vehicle.RventRot )
|
|
.gain( rsWentylator.m_amplitudeoffset + rsWentylator.m_amplitudefactor * Vehicle.RventRot )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
// ...otherwise shut down the sound
|
|
rsWentylator.stop();
|
|
}
|
|
// radiator fan sounds
|
|
if( Vehicle.EngineType == TEngineType::DieselEngine
|
|
|| Vehicle.EngineType == TEngineType::DieselElectric ) {
|
|
|
|
if( Vehicle.dizel_heat.rpmw > 0.1 ) {
|
|
// NOTE: fan speed tends to max out at ~100 rpm; by default we try to get pitch range of 0.5-1.5 and volume range of 0.5-1.0
|
|
radiator_fan
|
|
.pitch( 0.5 + radiator_fan.m_frequencyoffset + radiator_fan.m_frequencyfactor * Vehicle.dizel_heat.rpmw * 0.01 )
|
|
.gain( 0.5 + radiator_fan.m_amplitudeoffset + 0.5 * radiator_fan.m_amplitudefactor * Vehicle.dizel_heat.rpmw * 0.01 )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
// ...otherwise shut down the sound
|
|
radiator_fan.stop();
|
|
}
|
|
|
|
if( Vehicle.dizel_heat.rpmw2 > 0.1 ) {
|
|
// NOTE: fan speed tends to max out at ~100 rpm; by default we try to get pitch range of 0.5-1.5 and volume range of 0.5-1.0
|
|
radiator_fan_aux
|
|
.pitch( 0.5 + radiator_fan_aux.m_frequencyoffset + radiator_fan_aux.m_frequencyfactor * Vehicle.dizel_heat.rpmw2 * 0.01 )
|
|
.gain( 0.5 + radiator_fan_aux.m_amplitudeoffset + 0.5 * radiator_fan_aux.m_amplitudefactor * Vehicle.dizel_heat.rpmw2 * 0.01 )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
// ...otherwise shut down the sound
|
|
radiator_fan_aux.stop();
|
|
}
|
|
}
|
|
|
|
// relay sounds
|
|
auto const soundflags { Vehicle.SoundFlag };
|
|
if( TestFlag( soundflags, sound::relay ) ) {
|
|
// przekaznik - gdy bezpiecznik, automatyczny rozruch itp
|
|
if( true == TestFlag( soundflags, sound::shuntfield ) ) {
|
|
// shunt field
|
|
motor_shuntfield
|
|
.pitch(
|
|
true == motor_shuntfield.is_combined() ?
|
|
Vehicle.ScndCtrlActualPos * 0.01f :
|
|
motor_shuntfield.m_frequencyoffset + motor_shuntfield.m_frequencyfactor * 1.f )
|
|
.gain(
|
|
motor_shuntfield.m_amplitudeoffset + (
|
|
true == TestFlag( soundflags, sound::loud ) ?
|
|
1.0f :
|
|
0.8f )
|
|
* motor_shuntfield.m_amplitudefactor )
|
|
.play();
|
|
}
|
|
else if( true == TestFlag( soundflags, sound::parallel ) ) {
|
|
// parallel mode
|
|
if( TestFlag( soundflags, sound::loud ) ) {
|
|
dsbWejscie_na_bezoporow.play();
|
|
}
|
|
else {
|
|
motor_parallel.play();
|
|
}
|
|
}
|
|
else {
|
|
// series mode
|
|
motor_relay
|
|
.pitch(
|
|
true == motor_relay.is_combined() ?
|
|
Vehicle.MainCtrlActualPos * 0.01f :
|
|
motor_relay.m_frequencyoffset + motor_relay.m_frequencyfactor * 1.f )
|
|
.gain(
|
|
motor_relay.m_amplitudeoffset + (
|
|
true == TestFlag( soundflags, sound::loud ) ?
|
|
1.0f :
|
|
0.8f )
|
|
* motor_relay.m_amplitudefactor )
|
|
.play();
|
|
}
|
|
}
|
|
|
|
if( Vehicle.Vel > 0.1 ) {
|
|
transmission
|
|
.pitch( transmission.m_frequencyoffset + transmission.m_frequencyfactor * Vehicle.Vel )
|
|
.gain( transmission.m_amplitudeoffset + transmission.m_amplitudefactor * Vehicle.Vel )
|
|
.play( sound_flags::exclusive | sound_flags::looping );
|
|
}
|
|
else {
|
|
transmission.stop();
|
|
}
|
|
}
|
|
|
|
|
|
namespace {
|
|
|
|
// a train on the same track this close to the end of the player's train is taken into the physical coupler model [m]
|
|
constexpr double coupler_physics_reach { 200.0 };
|
|
// and let go of once none of its vehicles is this close to the player's train [m]; farther than the reach, so that
|
|
// the trains don't switch to and fro between the models
|
|
constexpr double coupler_physics_release { 500.0 };
|
|
|
|
// the vehicle and those coupled with it, one after the other
|
|
std::vector<TDynamicObject *>
|
|
coupled_train( TDynamicObject *Vehicle ) {
|
|
|
|
std::vector<TDynamicObject *> train { Vehicle };
|
|
for( int direction = end::front; direction <= end::rear; ++direction ) {
|
|
auto *vehicle { Vehicle };
|
|
auto side { direction };
|
|
// a train of more vehicles than are on the tracks would be one coupled into a ring
|
|
while( train.size() < 10000 ) {
|
|
auto const &mover { *vehicle->MoverParameters };
|
|
auto *next { mover.Neighbours[ side ].vehicle };
|
|
if( next == nullptr
|
|
|| ( mover.Couplers[ side ].CouplingFlag & coupling::coupler ) == 0
|
|
|| std::ranges::find( train, next ) != train.end() ) {
|
|
break;
|
|
}
|
|
train.emplace_back( next );
|
|
// onwards from the end of the next vehicle away from this one
|
|
side = 1 - mover.Neighbours[ side ].vehicle_end;
|
|
vehicle = next;
|
|
}
|
|
}
|
|
return train;
|
|
}
|
|
|
|
// the trains on the same track the player's train is closing in on: those found at its free ends, near enough
|
|
std::vector<TDynamicObject *>
|
|
trains_closing_in( std::vector<TDynamicObject *> const &Train ) {
|
|
|
|
std::vector<TDynamicObject *> trains;
|
|
for( auto *vehicle : Train ) {
|
|
for( int side = end::front; side <= end::rear; ++side ) {
|
|
auto const &mover { *vehicle->MoverParameters };
|
|
auto const &neighbour { mover.Neighbours[ side ] };
|
|
if( neighbour.vehicle == nullptr
|
|
|| ( mover.Couplers[ side ].CouplingFlag & coupling::coupler ) != 0
|
|
|| neighbour.distance > coupler_physics_reach
|
|
|| std::ranges::find( Train, neighbour.vehicle ) != Train.end() ) {
|
|
continue;
|
|
}
|
|
std::ranges::copy( coupled_train( neighbour.vehicle ), std::back_inserter( trains ) );
|
|
}
|
|
}
|
|
return trains;
|
|
}
|
|
|
|
// whether any vehicle of the train is within the distance of any vehicle of the other one
|
|
bool
|
|
trains_within( std::vector<TDynamicObject *> const &Train, std::vector<TDynamicObject *> const &Other, double const Distance ) {
|
|
|
|
return std::ranges::any_of( Train, [&]( TDynamicObject const *Vehicle ) {
|
|
return std::ranges::any_of( Other, [&]( TDynamicObject const *Othervehicle ) {
|
|
return glm::distance( Vehicle->GetPosition(), Othervehicle->GetPosition() ) <= Distance; } ); } );
|
|
}
|
|
|
|
} // namespace
|
|
|
|
// the physical coupler model covers the player's train and the trains it closes in on, on the same track; the others
|
|
// keep the legacy model, as the AI drives them in it
|
|
void
|
|
vehicle_table::update_coupler_physics() const {
|
|
|
|
if( false == Global.coupler_physics
|
|
|| true == Global.coupler_physics_all ) {
|
|
return;
|
|
}
|
|
auto *player { simulation::Train != nullptr ? simulation::Train->Dynamic() : nullptr };
|
|
std::vector<TDynamicObject *> train;
|
|
if( player != nullptr ) {
|
|
train = coupled_train( player );
|
|
}
|
|
std::unordered_set<TDynamicObject *> covered { train.begin(), train.end() };
|
|
for( auto *vehicle : trains_closing_in( train ) ) {
|
|
covered.insert( vehicle );
|
|
}
|
|
|
|
std::unordered_set<TDynamicObject *> checked;
|
|
for( auto *vehicle : m_items ) {
|
|
if( covered.contains( vehicle ) ) {
|
|
vehicle->MoverParameters->CouplerPhysics = true;
|
|
continue;
|
|
}
|
|
if( false == vehicle->MoverParameters->CouplerPhysics
|
|
|| checked.contains( vehicle ) ) {
|
|
continue;
|
|
}
|
|
// a train taken in before stays in the model until it's far from the player's one, all of it alike
|
|
auto const other { coupled_train( vehicle ) };
|
|
checked.insert( other.begin(), other.end() );
|
|
if( false == trains_within( other, train, coupler_physics_release ) ) {
|
|
for( auto *othervehicle : other ) {
|
|
othervehicle->MoverParameters->CouplerPhysics = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// legacy method, calculates changes in simulation state over specified time
|
|
void
|
|
vehicle_table::update( double Deltatime, int Iterationcount ) {
|
|
// Ra: w zasadzie to trzeba by utworzyć oddzielną listę taboru do liczenia fizyki
|
|
// na którą by się zapisywały wszystkie pojazdy będące w ruchu
|
|
// pojazdy stojące nie potrzebują aktualizacji, chyba że np. ktoś im zmieni nastawę hamulca
|
|
// oddzielną listę można by zrobić na pojazdy z napędem, najlepiej posortowaną wg typu napędu
|
|
for( auto *vehicle : m_items ) {
|
|
if( false == vehicle->bEnabled ) { continue; }
|
|
// Ra: zmienić warunek na sprawdzanie pantografów w jednej zmiennej: czy pantografy i czy podniesione
|
|
if( vehicle->MoverParameters->EnginePowerSource.SourceType == TPowerSource::CurrentCollector ) {
|
|
update_traction( vehicle );
|
|
}
|
|
vehicle->MoverParameters->ComputeConstans();
|
|
vehicle->update_neighbours();
|
|
}
|
|
update_coupler_physics();
|
|
if( Iterationcount > 1 ) {
|
|
// ABu: ponizsze wykonujemy tylko jesli wiecej niz jedna iteracja
|
|
for( int iteration = 0; iteration < Iterationcount - 1; ++iteration ) {
|
|
for( auto *vehicle : m_items ) {
|
|
vehicle->UpdateForce( Deltatime );
|
|
}
|
|
for( auto *vehicle : m_items ) {
|
|
vehicle->FastUpdate( Deltatime );
|
|
}
|
|
}
|
|
}
|
|
for( auto *vehicle : m_items ) {
|
|
vehicle->UpdateForce( Deltatime );
|
|
}
|
|
|
|
auto const totaltime { Deltatime * Iterationcount }; // całkowity czas
|
|
|
|
for( auto *vehicle : m_items ) {
|
|
// Ra 2015-01: tylko tu przelicza sieć trakcyjną
|
|
vehicle->Update( Deltatime, totaltime );
|
|
}
|
|
|
|
// jeśli jest coś do usunięcia z listy, to trzeba na końcu
|
|
erase_disabled();
|
|
|
|
// the odometers are saved now and then, a crash doesn't lose more than the last minute
|
|
m_odometersavetimer += totaltime;
|
|
if( m_odometersavetimer >= 60.0 ) {
|
|
save_odometers();
|
|
}
|
|
}
|
|
|
|
// records the odometer states of the vehicles and saves them for the next sessions (eu07/maszyna#72)
|
|
void
|
|
vehicle_table::save_odometers() {
|
|
|
|
m_odometersavetimer = 0.0;
|
|
auto &odometers { odometer::states() };
|
|
for( auto const *vehicle : m_items ) {
|
|
if( vehicle->MoverParameters != nullptr ) {
|
|
odometer::record( odometers, vehicle->name(), vehicle->MoverParameters->HasDriverCab(), vehicle->MoverParameters->Odometer );
|
|
}
|
|
}
|
|
odometer::save();
|
|
}
|
|
|
|
// legacy method, checks for presence and height of traction wire for specified vehicle
|
|
void
|
|
vehicle_table::update_traction( TDynamicObject *Vehicle ) {
|
|
auto const vFront = Vehicle->VectorFront(); // wektor normalny dla płaszczyzny ruchu pantografu
|
|
auto const vUp = Vehicle->VectorUp(); // wektor pionu pudła (pochylony od pionu na przechyłce)
|
|
auto const vLeft = Vehicle->VectorLeft(); // wektor odległości w bok (odchylony od poziomu na przechyłce)
|
|
auto const position = Vehicle->GetPosition(); // współrzędne środka pojazdu
|
|
|
|
for( int pantographindex = 0; pantographindex < Vehicle->iAnimType[ ANIM_PANTS ]; ++pantographindex ) {
|
|
// pętla po pantografach
|
|
auto *pantograph { Vehicle->pants[ pantographindex ].fParamPants };
|
|
if( true == Vehicle->MoverParameters->Pantographs[ pantographindex ].is_active ) {
|
|
// jeśli pantograf podniesiony
|
|
auto const pant0 { position + vLeft * pantograph->vPos.z + vUp * pantograph->vPos.y + vFront * pantograph->vPos.x };
|
|
if( pantograph->hvPowerWire != nullptr ) {
|
|
// jeżeli znamy drut z poprzedniego przebiegu
|
|
for( int attempts = 0; attempts < 30; ++attempts ) {
|
|
// sanity check. shouldn't happen in theory, but did happen in practice
|
|
if( pantograph->hvPowerWire == nullptr ) { break; }
|
|
|
|
// powtarzane aż do znalezienia odpowiedniego odcinka na liście dwukierunkowej
|
|
if( pantograph->hvPowerWire->iLast & 0x3 ) {
|
|
// dla ostatniego i przedostatniego przęsła wymuszamy szukanie innego
|
|
// nie to, że nie ma, ale trzeba sprawdzić inne
|
|
pantograph->hvPowerWire = nullptr;
|
|
break;
|
|
}
|
|
if( pantograph->hvPowerWire->hvParallel ) {
|
|
// jeśli przęsło tworzy bieżnię wspólną, to trzeba sprawdzić pozostałe
|
|
// nie to, że nie ma, ale trzeba sprawdzić inne
|
|
pantograph->hvPowerWire = nullptr;
|
|
break;
|
|
}
|
|
// obliczamy wyraz wolny równania płaszczyzny (to miejsce nie jest odpowienie)
|
|
// podstawiamy równanie parametryczne drutu do równania płaszczyzny pantografu
|
|
// TODO: investigate this routine with reardriver/negative speed, does it picks the right wire?
|
|
auto const fRaParam =
|
|
-( glm::dot( pantograph->hvPowerWire->pPoint1, vFront ) - glm::dot( pant0, vFront ) )
|
|
/ glm::dot( pantograph->hvPowerWire->vParametric, vFront );
|
|
|
|
if( fRaParam < -0.001 ) {
|
|
// histereza rzędu 7cm na 70m typowego przęsła daje 1 promil
|
|
pantograph->hvPowerWire = pantograph->hvPowerWire->hvNext[ 0 ];
|
|
continue;
|
|
}
|
|
if( fRaParam > 1.001 ) {
|
|
pantograph->hvPowerWire = pantograph->hvPowerWire->hvNext[ 1 ];
|
|
continue;
|
|
}
|
|
// jeśli t jest w przedziale, wyznaczyć odległość wzdłuż wektorów vUp i vLeft
|
|
// punkt styku płaszczyzny z drutem (dla generatora łuku el.)
|
|
auto const vStyk { pantograph->hvPowerWire->pPoint1 + fRaParam * pantograph->hvPowerWire->vParametric };
|
|
auto const vGdzie { vStyk - pant0 }; // wektor
|
|
// odległość w pionie musi być w zasięgu ruchu "pionowego" pantografu
|
|
// musi się mieścić w przedziale ruchu pantografu
|
|
auto const fVertical { glm::dot( vGdzie, vUp ) };
|
|
// odległość w bok powinna być mniejsza niż pół szerokości pantografu
|
|
// to się musi mieścić w przedziale zależnym od szerokości pantografu
|
|
auto const fHorizontal { std::abs( glm::dot( vGdzie, vLeft ) ) - pantograph->fWidth };
|
|
// jeśli w pionie albo w bok jest za daleko, to dany drut jest nieużyteczny
|
|
if( fHorizontal <= 0.0 ) {
|
|
// koniec pętli, aktualny drut pasuje
|
|
pantograph->PantTraction = fVertical;
|
|
break;
|
|
}
|
|
else {
|
|
// the wire is outside contact area and as of now we don't have good detection of parallel sections
|
|
// as such there's no guaratee there isn't parallel section present.
|
|
// therefore we don't bother checking if the wire is still within range of guide horns
|
|
// but simply force area search for potential better option
|
|
pantograph->hvPowerWire = nullptr;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if( pantograph->hvPowerWire == nullptr ) {
|
|
// look in the region for a suitable traction piece if we don't already have any
|
|
simulation::Region->update_traction( Vehicle, pantographindex );
|
|
}
|
|
|
|
if( pantograph->hvPowerWire == nullptr
|
|
&& false == Global.bLiveTraction ) {
|
|
// jeśli drut nie znaleziony ale można oszukiwać to dajemy coś tam dla picu
|
|
Vehicle->pants[ pantographindex ].fParamPants->PantTraction = 1.4;
|
|
}
|
|
}
|
|
else {
|
|
// pantograph is down
|
|
pantograph->hvPowerWire = nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
// legacy method, sends list of vehicles over network
|
|
void
|
|
vehicle_table::DynamicList( bool const Onlycontrolled ) const {
|
|
// odesłanie nazw pojazdów dostępnych na scenerii (nazwy, szczególnie wagonów, mogą się powtarzać!)
|
|
for( auto const *vehicle : m_items ) {
|
|
if( false == Onlycontrolled
|
|
|| vehicle->Mechanik != nullptr ) {
|
|
// same nazwy pojazdów
|
|
multiplayer::WyslijString( vehicle->asName, 6 );
|
|
}
|
|
}
|
|
// informacja o końcu listy
|
|
multiplayer::WyslijString( "none", 6 );
|
|
}
|
|
|
|
// maintenance; removes from tracks consists with vehicles marked as disabled
|
|
bool
|
|
vehicle_table::erase_disabled() {
|
|
|
|
if( false == TDynamicObject::bDynamicRemove ) { return false; }
|
|
|
|
// go through the list and retrieve vehicles scheduled for removal...
|
|
type_sequence disabledvehicles;
|
|
for( auto *vehicle : m_items ) {
|
|
if( false == vehicle->bEnabled ) {
|
|
disabledvehicles.emplace_back( vehicle );
|
|
}
|
|
}
|
|
// ...now propagate removal flag through affected consists...
|
|
for( auto *vehicle : disabledvehicles ) {
|
|
TDynamicObject *coupledvehicle { vehicle };
|
|
while( ( coupledvehicle = coupledvehicle->Next() ) != nullptr ) {
|
|
coupledvehicle->bEnabled = false;
|
|
}
|
|
// (try to) run propagation in both directions, it's simpler than branching based on direction etc
|
|
coupledvehicle = vehicle;
|
|
while( ( coupledvehicle = coupledvehicle->Prev() ) != nullptr ) {
|
|
coupledvehicle->bEnabled = false;
|
|
}
|
|
}
|
|
// ...then actually remove all disabled vehicles...
|
|
auto vehicleiter = std::begin( m_items );
|
|
while( vehicleiter != std::end( m_items ) ) {
|
|
|
|
auto *vehicle { *vehicleiter };
|
|
|
|
if( true == vehicle->bEnabled ) {
|
|
++vehicleiter;
|
|
}
|
|
else {
|
|
// the distance the vehicle ran goes in the odometer store now, it doesn't depend on the vehicle being
|
|
// kept on the list until the next save (eu07/maszyna#72)
|
|
if( vehicle->MoverParameters != nullptr ) {
|
|
odometer::record( odometer::states(), vehicle->name(), vehicle->MoverParameters->HasDriverCab(), vehicle->MoverParameters->Odometer );
|
|
}
|
|
if( vehicle->MyTrack != nullptr
|
|
&& true == vehicle->MyTrack->RemoveDynamicObject(vehicle) ) {
|
|
vehicle->MyTrack = nullptr;
|
|
}
|
|
if( simulation::Train != nullptr
|
|
&& simulation::Train->Dynamic() == vehicle ) {
|
|
// clear potential train binding
|
|
// TBD, TODO: kill vehicle sounds
|
|
simulation::Train = nullptr;
|
|
}
|
|
simulation::Trains.purge(vehicle->name());
|
|
// remove potential entries in the light array
|
|
simulation::Lights.remove( vehicle );
|
|
simulation::Blackbox.vehicle_removed( vehicle );
|
|
/*
|
|
// finally get rid of the vehicle and its record themselves
|
|
// BUG: deleting the vehicle leaves dangling pointers in event->Activator and potentially elsewhere
|
|
// TBD, TODO: either mark 'dead' vehicles with additional flag, or delete the references as well
|
|
SafeDelete( vehicle );
|
|
vehicleiter = m_items.erase( vehicleiter );
|
|
*/
|
|
++vehicleiter; // NOTE: instead of the erase in the disabled section
|
|
}
|
|
}
|
|
// ...and call it a day
|
|
TDynamicObject::bDynamicRemove = false;
|
|
|
|
return true;
|
|
}
|